Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp971742imm; Wed, 8 Aug 2018 08:39:38 -0700 (PDT) X-Google-Smtp-Source: AA+uWPzhAgurmnKqYJuQX9DbmHB63uo5lc+f9uNT6NXbX0Y96oC6GF8hc/NXHHu61vFiD9HgbwCE X-Received: by 2002:a62:d8c:: with SMTP id 12-v6mr3546372pfn.202.1533742778448; Wed, 08 Aug 2018 08:39:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533742778; cv=none; d=google.com; s=arc-20160816; b=zmtSiNG+ewUKFrTWoWrUPkZBOJjUi2EodQZsuKVrcVjUrbxguYcIxe6TQiFer/DlWm N89nqMExp8YYJ/hiSzkhCWefQhq+swV1cKVq5XCkfUC/kXHJXXFNhp7y9yc6Exh/OBdt 2ia2/OwXgODn1IjekzR7dyNNU+N94V0mY8f4kjtX/uobdgZu4iU6cSPiydUK2fImc9fW 3tDhRkR2YtbunskgrxhdFqUo/jQ92e4xekukCgNuVqZizm7AYUa8bvwB8Q6It8511ftk ZG4wlRMkhsYTiwwHg1V6R2xhfOVheXt8xxDSq/6zIlm1Dl3RXqPcRkVGfB33JY6sOAKT Fhdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=0/AcFQWG5GWA8z8qElGqK0mK/sub6hcCVMsKNMHf7yU=; b=P4mXsetV9aKnpS4bTwz2YlKynaoTEtUJ2yxeG2pnQiQ+9NvtWVG/PXUZG5gQc6rA0g c2FUIYBllAVmF2RJSbZPwaxBP0K/g+BQ1mMnYELbYgyfeKrUBpMt73aVCXLiLBHlymjS 3450hskCqVH3kEFr6NdE6pYPDrKcwfcjkrX5E5k+gudlV0XXW4LGbYl1O9A4oi5eLLc1 aKefM+UqklbA7G1+envEMf6WuYvz4IAs4jwahXoJ0pr/6zm0eh4oXluDk/rsmHptMI4u pt6YSeur838bixPLPHVtWzsy8YjpnFrqA5ry1qxjZKItzZ/NUljjIaqUDFE7OschETf0 I+1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=e77HNEXQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g12-v6si3480788pla.403.2018.08.08.08.39.23; Wed, 08 Aug 2018 08:39:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=e77HNEXQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727979AbeHHRxq (ORCPT + 99 others); Wed, 8 Aug 2018 13:53:46 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:42742 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727534AbeHHRxn (ORCPT ); Wed, 8 Aug 2018 13:53:43 -0400 Received: by mail-wr1-f68.google.com with SMTP id e7-v6so2389075wrs.9 for ; Wed, 08 Aug 2018 08:33:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=0/AcFQWG5GWA8z8qElGqK0mK/sub6hcCVMsKNMHf7yU=; b=e77HNEXQK7pu4RBRZeCmNPrKeduXRuP9S9cTxoYQ3X+TxcPsLBof2AMUE0NxymJprz aSLozu5Jg/24ZnLaT7WNNLjUfTHXGAedexjwjMe1wVI4m9+SEruVZc0IY4c+44KPWLMw N7LsTQ/H39KweZ99N/07jtuj3+IlYRuGMjFuDMHDmu115wheS5SrCmYOFrCVbLhBIvrS jNM/6Mj281twAPkZvxS8Fb+Tzq815NdY+ScQKrRVooXrSmWto1y4CbrvU2t+rGzouMF9 nScHpKlfurLk468ZkktF3JWjS8MjJGTzcJ/A5CfGeTTOVauyWnKRr1nksHOZ3swBB1bQ G/dA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=0/AcFQWG5GWA8z8qElGqK0mK/sub6hcCVMsKNMHf7yU=; b=IYlgAoDNv/7/l/0jKYYb+PkD+xSJZwxX7T4tFdDBswUBxOjTlRXSgvbY4mrTHidxqn lfN0M6EQYh5ME0vOn6o8d1Nssry9YBZgkDt+Pu/+UTi7/xVvqux2Sw0SRemaPKB2HF3H 1Tg4eCoyxyv9Nd7j/4eCyEPNEoUUN/x1M+o4vOl8DD58T+1xvSXhdlw6H2vqcMDYzJRk DlAJm/Kso/acSz6WOqSRuJ8pD/KC+C2iwqEg9y/6pQi5+HvH8/3azwHuI0qNok1LeVOV mrz1NnMkkWPCC6ufTg9ppvgtVgHWziDLbxbtjOempu4RbCI8kKqS1MNi5LbQGmUzI0Hy +RnQ== X-Gm-Message-State: AOUpUlG2K1WACTnx6XR7jeuVGp2TEwwFC+XqZGX8R1eGyuBR9E/onLQ6 dCzZ6vXPpq033TjYeAfFV+lA4g== X-Received: by 2002:adf:d842:: with SMTP id k2-v6mr2256361wrl.26.1533742411481; Wed, 08 Aug 2018 08:33:31 -0700 (PDT) Received: from brgl-bgdev.lan (LFbn-MAR-1-609-89.w90-118.abo.wanadoo.fr. [90.118.185.89]) by smtp.gmail.com with ESMTPSA id s2-v6sm5240915wrw.52.2018.08.08.08.33.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 08:33:30 -0700 (PDT) From: Bartosz Golaszewski To: Jonathan Corbet , Sekhar Nori , Kevin Hilman , Russell King , Arnd Bergmann , Greg Kroah-Hartman , David Woodhouse , Brian Norris , Boris Brezillon , Marek Vasut , Richard Weinberger , Grygorii Strashko , "David S . Miller" , Srinivas Kandagatla , Naren , Mauro Carvalho Chehab , Andrew Morton , Lukas Wunner , Dan Carpenter , Florian Fainelli , Ivan Khoronzhuk , Sven Van Asbroeck , Paolo Abeni , Alban Bedel , Rob Herring , David Lechner , Andrew Lunn Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-i2c@vger.kernel.org, linux-mtd@lists.infradead.org, linux-omap@vger.kernel.org, netdev@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 03/28] nvmem: add a notifier chain Date: Wed, 8 Aug 2018 17:31:25 +0200 Message-Id: <20180808153150.23444-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180808153150.23444-1-brgl@bgdev.pl> References: <20180808153150.23444-1-brgl@bgdev.pl> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bartosz Golaszewski Add a blocking notifier chain with two events (add and remove) so that users can get notified about the addition of nvmem devices they're waiting for. We'll use this instead of the at24 setup callback in the mityomapl138 board file. Signed-off-by: Bartosz Golaszewski --- drivers/nvmem/core.c | 20 ++++++++++++++++++++ include/linux/nvmem-consumer.h | 18 ++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 329ea5b8f809..128c8e51bff2 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -65,6 +65,8 @@ static DEFINE_MUTEX(nvmem_cells_mutex); static LIST_HEAD(nvmem_cell_lookups); static DEFINE_MUTEX(nvmem_lookup_mutex); +static BLOCKING_NOTIFIER_HEAD(nvmem_notifier); + #ifdef CONFIG_DEBUG_LOCK_ALLOC static struct lock_class_key eeprom_lock_key; #endif @@ -479,6 +481,18 @@ static int nvmem_setup_compat(struct nvmem_device *nvmem, return 0; } +int nvmem_register_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_register(&nvmem_notifier, nb); +} +EXPORT_SYMBOL_GPL(nvmem_register_notifier); + +int nvmem_unregister_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_unregister(&nvmem_notifier, nb); +} +EXPORT_SYMBOL_GPL(nvmem_unregister_notifier); + /** * nvmem_register() - Register a nvmem device for given nvmem_config. * Also creates an binary entry in /sys/bus/nvmem/devices/dev-name/nvmem @@ -559,6 +573,10 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) if (config->cells) nvmem_add_cells(nvmem, config->cells, config->ncells); + rval = blocking_notifier_call_chain(&nvmem_notifier, NVMEM_ADD, nvmem); + if (rval) + goto err_device_del; + return nvmem; err_device_del: @@ -586,6 +604,8 @@ int nvmem_unregister(struct nvmem_device *nvmem) } mutex_unlock(&nvmem_mutex); + blocking_notifier_call_chain(&nvmem_notifier, NVMEM_REMOVE, nvmem); + if (nvmem->flags & FLAG_COMPAT) device_remove_bin_file(nvmem->base_dev, &nvmem->eeprom); diff --git a/include/linux/nvmem-consumer.h b/include/linux/nvmem-consumer.h index f4b5d3186e94..ae4d30347602 100644 --- a/include/linux/nvmem-consumer.h +++ b/include/linux/nvmem-consumer.h @@ -14,6 +14,7 @@ #include #include +#include struct device; struct device_node; @@ -35,6 +36,11 @@ struct nvmem_cell_lookup { const char *nvmem_name; }; +enum { + NVMEM_ADD = 1, + NVMEM_REMOVE, +}; + #if IS_ENABLED(CONFIG_NVMEM) /* Cell based interface */ @@ -61,6 +67,8 @@ ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem, int nvmem_device_cell_write(struct nvmem_device *nvmem, struct nvmem_cell_info *info, void *buf); +int nvmem_register_notifier(struct notifier_block *nb); +int nvmem_unregister_notifier(struct notifier_block *nb); #else static inline struct nvmem_cell *nvmem_cell_get(struct device *dev, @@ -149,6 +157,16 @@ static inline int nvmem_device_write(struct nvmem_device *nvmem, { return -ENOSYS; } + +static inline int nvmem_register_notifier(struct notifier_block *nb) +{ + return -ENOSYS; +} + +static inline int int nvmem_unregister_notifier(struct notifier_block *nb) +{ + return -ENOSYS; +} #endif /* CONFIG_NVMEM */ #if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF) -- 2.18.0