From patchwork Fri Sep 7 10:07:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 10592005 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7FFBE13AC for ; Fri, 7 Sep 2018 10:20:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C2142AA3A for ; Fri, 7 Sep 2018 10:20:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 604422AA46; Fri, 7 Sep 2018 10:20:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AE0DA2AA3A for ; Fri, 7 Sep 2018 10:20:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=8hpceEtdjAfB2LSstTYfpBpPtw/lgxlyrDO9CAbuhHg=; b=FPvsUHn0QmZcbvJeMBcfc8XZ4M kwZaO9+tDWXC3m16kNfqlrWesDi7ZWP/rV17u1lRIQz/DFu524jxB5vLMlvfNrkCnUFxBwntngyFy gPTrcmqvLYSzeDt4v9HEOQgjmkEb3YtVIfEMjtEwVvg3sS/gSh7OjJHc8+qrBIiRvUwfZ6tkkiVmI SaWLG22dy2MidIiYzPGL1JKqSIB0P9Di5M//03U/Ojw4La/eTAJ2CSj3fEuf1X1Y6R6ZnEDWjZMcn W/XHbnTJAN9XHwUPrx0UNgly2W5bTV1emMXnmR/kOz5T73oNSfAXiSsDj4hini3+2/dI7RmfZGWjo qWLfhhXQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fyDs8-0006hD-VM; Fri, 07 Sep 2018 10:20:17 +0000 Received: from mail-wm0-f66.google.com ([74.125.82.66]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fyDjt-0000BH-Js for linux-arm-kernel@lists.infradead.org; Fri, 07 Sep 2018 10:11:47 +0000 Received: by mail-wm0-f66.google.com with SMTP id 207-v6so13972286wme.5 for ; Fri, 07 Sep 2018 03:09: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=J1XTyB4mx+/CzlqafJmwB/GS7AoL7xfVrlZaU0QgY8A=; b=GrZI/lVtMW02eiYUBbfrGywbxzO8c4MM1aHazk7T6gSADUS3HfbfE/r3QB8/Lw3Q+T 3yVl73YfRU5VOashRo9bLWu3c0hOY4VW1D1IZQ+gNCa34H2mqxSo5UXKeXAKSDrk9c7m dhNkrnfH/5I4YnTtqCxjtsotaRkc6/9T94tq3UGvKEWAKC81CuYol/4PzcjHkjXdq2ds gN+CIlNql+wA2ZcQU+qSMn6INLZv+kF0e/X+wo6F0H3ACDG/rWhy83RzuuM8uqrIhPpi ibtKqaV6r8bzjtiFEGZ2u/dexd53Oy6+D8QKSnqSS/TMqPEqmef41P5+uxWPCqxbkzY9 9pIg== 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=J1XTyB4mx+/CzlqafJmwB/GS7AoL7xfVrlZaU0QgY8A=; b=TsiwOMD72YRV6yr2MkkFv5X3pARPncmZJu1vPremp3PZ5A5pj+u1z8huPui+XMtkXh AigynqDyrren28e7u39RUkeEOonEJHbO5uzB+ryK5YDSGHFMWauUtRJNPLhXS2JzHyN8 9bNNLqfb4Nnh/wK8PYNVKjtg6641+E1UoSfpAS/kk3cm/hI0Xm2WtQXszSs6GNmb9sLi VNNvO9bt0qBUAj9GA4MxM16XM9stFfYEIZc10xCaKg6Ugna9ipmgl+WyftLdAUpLMtji A1tSn0iT8eAvzI0YVq5J0+Bk2pa0azEPXxohQY9TJfyxCshbW598BqX5RxPzDkqgTxxt ynlw== X-Gm-Message-State: APzg51By6Q56kOteKzAPeXh6Btg70SOfgrsUIaLmBOpC0mIAvLoXAo/u KSeMyQKBD9UbtNEW1BrUi5UiWw== X-Google-Smtp-Source: ANB0VdbtkBV1ML2Rf2ViBQMMF/MNN2SlVbE8BidphRJt9UAiGftA9I9Wd6/RYYdOhgAETyZT/CkWmg== X-Received: by 2002:a1c:c64c:: with SMTP id w73-v6mr4316925wmf.98.1536314911633; Fri, 07 Sep 2018 03:08:31 -0700 (PDT) Received: from brgl-bgdev.baylibre.local (AStLambert-681-1-83-232.w90-86.abo.wanadoo.fr. [90.86.25.232]) by smtp.gmail.com with ESMTPSA id 72-v6sm6631619wrb.48.2018.09.07.03.08.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 03:08:30 -0700 (PDT) From: Bartosz Golaszewski To: Srinivas Kandagatla , "David S . Miller" , Mauro Carvalho Chehab , Greg Kroah-Hartman , Andrew Morton , Arnd Bergmann , Jonathan Corbet , Sekhar Nori , Kevin Hilman , David Lechner , Boris Brezillon , Andrew Lunn , Alban Bedel , Maxime Ripard , Chen-Yu Tsai Subject: [PATCH v2 10/16] nvmem: add a notifier chain Date: Fri, 7 Sep 2018 12:07:44 +0200 Message-Id: <20180907100750.14564-11-brgl@bgdev.pl> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180907100750.14564-1-brgl@bgdev.pl> References: <20180907100750.14564-1-brgl@bgdev.pl> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180907_031145_715687_4BEC930C X-CRM114-Status: GOOD ( 15.90 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Bartosz Golaszewski , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 | 36 ++++++++++++++++++++++++++++++++++ include/linux/nvmem-consumer.h | 19 ++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index e456aaa6184a..17307015905a 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -58,6 +58,8 @@ struct nvmem_cell { static DEFINE_MUTEX(nvmem_mutex); static DEFINE_IDA(nvmem_ida); +static BLOCKING_NOTIFIER_HEAD(nvmem_notifier); + #ifdef CONFIG_DEBUG_LOCK_ALLOC static struct lock_class_key eeprom_lock_key; #endif @@ -339,6 +341,32 @@ static int nvmem_setup_compat(struct nvmem_device *nvmem, return 0; } +/** + * nvmem_register_notifier() - Register a notifier block for nvmem events. + * + * @nb: notifier block to be called on nvmem events. + * + * Return: 0 on success, negative error number on failure. + */ +int nvmem_register_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_register(&nvmem_notifier, nb); +} +EXPORT_SYMBOL_GPL(nvmem_register_notifier); + +/** + * nvmem_unregister_notifier() - Unregister a notifier block for nvmem events. + * + * @nb: notifier block to be unregistered. + * + * Return: 0 on success, negative error number on failure. + */ +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 @@ -420,8 +448,15 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) INIT_LIST_HEAD(&nvmem->cells); + rval = blocking_notifier_call_chain(&nvmem_notifier, NVMEM_ADD, nvmem); + if (rval) + goto err_teardown_compat; + return nvmem; +err_teardown_compat: + if (config->compat) + device_remove_bin_file(nvmem->base_dev, &nvmem->eeprom); err_device_del: device_del(&nvmem->dev); err_put_device: @@ -436,6 +471,7 @@ static void nvmem_device_release(struct kref *kref) struct nvmem_device *nvmem; nvmem = container_of(kref, struct nvmem_device, refcnt); + 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 1313da6731ff..be583c4eb2d0 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; @@ -21,6 +22,11 @@ struct device_node; struct nvmem_cell; struct nvmem_device; +enum { + NVMEM_ADD = 1, + NVMEM_REMOVE, +}; + #if IS_ENABLED(CONFIG_NVMEM) /* Cell based interface */ @@ -45,6 +51,9 @@ int nvmem_device_write(struct nvmem_device *nvmem, unsigned int offset, const char *nvmem_dev_name(struct nvmem_device *nvmem); +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, @@ -125,6 +134,16 @@ static inline const char *nvmem_dev_name(struct nvmem_device *nvmem) return NULL; } +static inline int nvmem_register_notifier(struct notifier_block *nb) +{ + return -ENOSYS; +} + +static inline int nvmem_unregister_notifier(struct notifier_block *nb) +{ + return -ENOSYS; +} + #endif /* CONFIG_NVMEM */ #if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF)