From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on archive.lwn.net X-Spam-Level: X-Spam-Status: No, score=-5.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, T_DKIMWL_WL_MED autolearn=unavailable autolearn_force=no version=3.4.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by archive.lwn.net (Postfix) with ESMTP id 101BE7D57F for ; Wed, 5 Sep 2018 09:58:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728365AbeIEO1o (ORCPT ); Wed, 5 Sep 2018 10:27:44 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:40917 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728267AbeIEO1n (ORCPT ); Wed, 5 Sep 2018 10:27:43 -0400 Received: by mail-wr1-f65.google.com with SMTP id n2-v6so6977040wrw.7 for ; Wed, 05 Sep 2018 02:58:14 -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=UeYhe+JnD0uNBDQp6/YhRrQIb2W6vfY9+P4DJthK/8s=; b=0W2pCf5DleBd0FBNJN1bcIBvpb5BVTXYOuZD1tnQKhxp1fq1x4fvCbM//mBkesLVso a/LfdFucoiT9Vn5GwBGCu17zGlnV1tEU9Aa5x1olFv9f1rrksOcorGAy0GvXck3x+KfZ yPhGZBviERIZNMkMSg2I5CM7/RDEGnmiP/A1eL6qptwOW9RCPIuXPK2nn0ArxsN9Z6bs xwnnuwPZpiFh49ZJZxKX8yMiAVefgSGV0vNIwfz4EzjmJSzjCA91aigLQbSTApy4xMy9 HeEDxN0bZm9BWauq76BXwcfMuja3WACTRUC6TPsQi3BuKsCnO64wwqdXZlJPzKNm7hae Y22Q== 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=UeYhe+JnD0uNBDQp6/YhRrQIb2W6vfY9+P4DJthK/8s=; b=Bx+SbgzY2xjF84Unj3ay8MNLer1YRQlkp/dXkCNuzJpTSP1kNN7ihoPCJuXqKN8Ilb i6fPaRnbkFuBKxAvRZHWdBjP3t7uKT486Ttka7m2vhOS1JKdLdj6OzmmG13JEtWntu5/ lIiY/MLDcpZBYch6LiNBRKBT+EPpv/Wbmi9ArYE+z9TEqjy9PBRrxXdN4zimBj+rwtpN Ctv6XiG1vCd97OZMWib6vQvA7OFDYNmOEkjAOQirOzrgMWMguA0ppOlK60hz8i5xHGOQ 3PF8NQZTYlXIVsyjzunVHV+ZIDYcDZm6rhq5ZryHS584ifG8dATkrFlTqQ4LK/+DX4Hb QExQ== X-Gm-Message-State: APzg51B5Y21BmuwwH7chzpqopBMTlMh93WoyvN/DxrYNIsVUNYJdTHcR HNXYeqYiQRDw7OoUotm3x1jSRw== X-Google-Smtp-Source: ANB0VdY61BW1wrNMkewSn0ibOSkerGRxAaBqd57uZ4bcBDs84qAbw86gBhQEYiFL7OmR3+QiQaJQkw== X-Received: by 2002:adf:e792:: with SMTP id n18-v6mr14381388wrm.136.1536141494220; Wed, 05 Sep 2018 02:58:14 -0700 (PDT) Received: from brgl-bgdev.baylibre.local (AStLambert-681-1-33-235.w90-86.abo.wanadoo.fr. [90.86.152.235]) by smtp.gmail.com with ESMTPSA id l12-v6sm2127815wrv.29.2018.09.05.02.58.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Sep 2018 02:58:13 -0700 (PDT) From: Bartosz Golaszewski To: Srinivas Kandagatla , Joachim Eastwood , "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 Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Bartosz Golaszewski Subject: [PATCH 08/13] nvmem: add a notifier chain Date: Wed, 5 Sep 2018 11:57:33 +0200 Message-Id: <20180905095738.26406-9-brgl@bgdev.pl> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180905095738.26406-1-brgl@bgdev.pl> References: <20180905095738.26406-1-brgl@bgdev.pl> Sender: linux-doc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-doc@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..8a6405febc32 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 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 From mboxrd@z Thu Jan 1 00:00:00 1970 From: brgl@bgdev.pl (Bartosz Golaszewski) Date: Wed, 5 Sep 2018 11:57:33 +0200 Subject: [PATCH 08/13] nvmem: add a notifier chain In-Reply-To: <20180905095738.26406-1-brgl@bgdev.pl> References: <20180905095738.26406-1-brgl@bgdev.pl> Message-ID: <20180905095738.26406-9-brgl@bgdev.pl> To: linux-arm-kernel@lists.infradead.org List-Id: linux-arm-kernel.lists.infradead.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..8a6405febc32 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 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