Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1605071imm; Fri, 7 Sep 2018 03:11:59 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdbb4H3YBPtB5RnhDWoIgrZfvTq5rQtW2aqdBsXXz2lUhQgAVp71iYdx9/xKOVKLt3eMPc+h X-Received: by 2002:a63:6c89:: with SMTP id h131-v6mr7336998pgc.237.1536315119805; Fri, 07 Sep 2018 03:11:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536315119; cv=none; d=google.com; s=arc-20160816; b=0V/DRK9ktGXdqeK1qtItnVhE0ohPOe51WvvmEZnKaZWH00iAPwY1kg6hdnVAiP0Khy F/X5apIo6YPyAb3I3wwmqNQH+LduphDResxV6J/hEiEmnM7aYkfOd/Rj6VRaVcClFU2k UFSbuxd/PJC9qKRg21ZuqMyDPCY7J4/w97FVcvHhBaN2R8J8qaWjIi+ye6qoJiCNnIPf psyiMPflxJ5zSUEVBIslooI2Bbz9jtZ6RsKdBvOX/FXfmJU+gGHivVc9aX/+f0jwFdxH cIQM1lQ5BW20aB7d9gLajmVbljPRFYC7NnGUzZQ5GWfBHcMUjpddA6WKboX63slyYUYK bHOg== 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; bh=J1XTyB4mx+/CzlqafJmwB/GS7AoL7xfVrlZaU0QgY8A=; b=JDrkPD6VZVGiFk/LVhWuGZKYRkwtD37BMhDpeWp7a2yemJ201q5oN2MwcRqQsBFoyK OkwMj2CPSgeT1GtJGeNU7AgI1vWtmcWdLHEPmpDUNe24fAOs7oyhtGgFDU7+rCmzbPGb 42VNOpy83jP/1bKLt+oD+i77ZfXR7/a/NlorQSsJl8B9mp1ZfZ3zeRy33OWx17pot5uW 5LSdgPP8JwY0jwcyjHjfX2U19E2BPxJIUsP+PoupLlol/73ghODx3sH4mmjFtKK5rbUd MtfCranOScdvMnpajBenWZMOJAWXxLk4NTqy+dK8Sb0uOJD9Ut6zB6c+dcEMbRTSx6KM VMcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b="GrZI/lVt"; 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 i3-v6si7401549plb.44.2018.09.07.03.11.44; Fri, 07 Sep 2018 03:11:59 -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="GrZI/lVt"; 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 S1728764AbeIGOsr (ORCPT + 99 others); Fri, 7 Sep 2018 10:48:47 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:50702 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728739AbeIGOsq (ORCPT ); Fri, 7 Sep 2018 10:48:46 -0400 Received: by mail-wm0-f66.google.com with SMTP id s12-v6so14204706wmc.0 for ; Fri, 07 Sep 2018 03:08: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=I431mbuYjwrBiD9TZceCoYewHDmX7FwBHZvCJKzD9zuwb2h0qjY6loXmBgGPftTuno H+qwyclIHjVdRTK8pCkwtWSIt8Y9I0oouJrE16VXdXkRT/JN4tKbwxosQlyWw7FoT7Ie GG/5kPbuGTiT1BJfsPlEqUYdOFPQ0MKbeEKQsZ46ozVlpGc3hTYTVpofXgoVbDwTrxKh 2DRCXt9f3Sk5XNU8VT7hbnsQoQcwvnOuDB04qyr1PQXYZaS6UpYHf0j80zoZBxpsFDRm tYqAkLR+KlXoSvMoT0cCelTHLtqqts3Jw9pDkr/wfHfmvQXBOCAFSfwz2dLwMecVFR+2 onOw== X-Gm-Message-State: APzg51Adb+gXn4Etuutw18d8yUdnh2nIy24f1BGaw6lBtAdA9xKIeIPm h3G4do88nMCM/WrT+5caqJlw3A== 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 Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Bartosz Golaszewski 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> 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 | 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) -- 2.18.0