From nobody Fri Dec 19 00:21:39 2025 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3BEC249EF for ; Fri, 15 Dec 2023 11:15:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="YcPhxab1" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-3332efd75c9so380053f8f.2 for ; Fri, 15 Dec 2023 03:15:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1702638947; x=1703243747; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1kRMoHIJRTtXNIICxC1qtJW1lyGXSE9y4s5yX7QFSi0=; b=YcPhxab1bY3rO8GOQWW52qWcvhcLimuPehgVGkYn6myjAXkHNRwhLVCMyaUfa4MMV3 /U05CRLTQKO8TJ7ED3dKKJ5cgckzQ5CSSOZJysQhB36n4UhjoHn6Q1tzKkQ1G3MOI0ab +V+DLsJoaLXmumI3BYO8asM1OQTWmxbswlfRTiaXufcPEC0ZB2C3PFfx1L8/2nbhaQwg nayqLYXxfjcj6xXRNrNrlwraCRhlyRP9I1Gf3cVtUUFRBMvHhX3wwrwvycP8sDcnXMaj lj6IPtuU2ZbFyu7Q4f1uBD+gRTNthHL/wLD5Wy7XfWq1bAOk03EtS5W37HbcvayobsC8 mCqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702638947; x=1703243747; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1kRMoHIJRTtXNIICxC1qtJW1lyGXSE9y4s5yX7QFSi0=; b=AQCXiQXmkFueHIRLyWQkwtkirJo1QEDoGejhKPlRbTYsPgpU8Xq50MYVzjg/5VTvFA oGtsov1g6UpjNFVhNGtS2cM43fXZ9rwvOOb4EWwK0W7GAGm23+TvwAJb3/DQDgAt2SiD CpMUCxY4WB+t71KwBC+pLCugrqVPhE+F8hQKxwNFS1n9ETkVEbbgIVj9D6lOm7MKPb4N SXvhaB/qq92Jbo8NS1qaLblQF15VYK7HSd91NoXOB57pXfz4r1PXZjQEYKbu+2HTSh2p okQVSy0oNZ4BgSpd3DDIjpt3fMXVHdxWrDPS9Gf2alldfpMD2I7XAYIlwSNsC+wG8TzK uL6g== X-Gm-Message-State: AOJu0YwzYsc1BwsRuWGdJ6KqIleJ7oFjJO7QbtvuDPi7DDDWSNvswqGw wQjUGbvulfz/9A+bcFTJRaq3Tw== X-Google-Smtp-Source: AGHT+IGvp0sgifCyz+Hk70iMVxwgYchRh/UKLVec3MnA6QDQyZVlTj1XYAr/LfKEjMiD225qOJAerQ== X-Received: by 2002:a05:6000:4c8:b0:333:3a38:d568 with SMTP id h8-20020a05600004c800b003333a38d568mr3207085wri.184.1702638946946; Fri, 15 Dec 2023 03:15:46 -0800 (PST) Received: from localhost.localdomain ([5.133.47.210]) by smtp.gmail.com with ESMTPSA id g13-20020a056000118d00b003333d46a9e8sm18511497wrx.56.2023.12.15.03.15.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 03:15:46 -0800 (PST) From: srinivas.kandagatla@linaro.org To: gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, Miquel Raynal , Rob Herring , Srinivas Kandagatla Subject: [PATCH 01/10] of: device: Export of_device_make_bus_id() Date: Fri, 15 Dec 2023 11:15:27 +0000 Message-Id: <20231215111536.316972-2-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231215111536.316972-1-srinivas.kandagatla@linaro.org> References: <20231215111536.316972-1-srinivas.kandagatla@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=5096; i=srinivas.kandagatla@linaro.org; h=from:subject; bh=U8/4jDIV+uERRA2Pjp9VTOhw2zC2Bzr+MXKEeB2u73A=; b=owEBbQGS/pANAwAKAXqh/VnHNFU3AcsmYgBlfDVXCF2GhBRHA5Vqce6mlIYurB1cC08KtWvIy qgDLK160HSJATMEAAEKAB0WIQQi509axvzi9vce3Y16of1ZxzRVNwUCZXw1VwAKCRB6of1ZxzRV NwFlB/4j/xNoIXxFotBnVor1mDKYmPu9ZiJrnJ0RNKm+RBA+xURJXA9vgzS21EL1fYWuB4MzujX ibsBD2oFXTiZKymnxtat33khQAXKms86nme5vMKpFkMxpu/Yk7LUMoLa9Ax+Pf9jOsMwv0iwPfA /B99P8W4UcQ41xVO0JZSja6zbM+zc57rTMV3Pt8EXNpGo6mdugPXraHZWzOyiCD5mfDeOoUntq7 c5s6Tk4UhPD1BEno2Cbi7tfQimWvwGSdpSHkrOBt/rj1rpgwfhYNE+Y624IgKS3L+cDS8b3CCau L1Gw2JvRWm7Gdf7NxC93q04rS+Wdj73O72w7sJIIBEBmtl4R X-Developer-Key: i=srinivas.kandagatla@linaro.org; a=openpgp; fpr=ED6472765AB36EC43B3EF97AD77E3FC0562560D6 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Miquel Raynal This helper is really handy to create unique device names based on their device tree path, we may need it outside of the OF core (in the NVMEM subsystem) so let's export it. As this helper has nothing patform specific, let's move it to of/device.c instead of of/platform.c so we can add its prototype to of_device.h. Signed-off-by: Miquel Raynal Acked-by: Rob Herring Signed-off-by: Srinivas Kandagatla --- drivers/of/device.c | 41 +++++++++++++++++++++++++++++++++++++++ drivers/of/platform.c | 40 -------------------------------------- include/linux/of_device.h | 6 ++++++ 3 files changed, 47 insertions(+), 40 deletions(-) diff --git a/drivers/of/device.c b/drivers/of/device.c index 1ca42ad9dd15..6e9572c4af83 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -304,3 +304,44 @@ int of_device_uevent_modalias(const struct device *dev= , struct kobj_uevent_env * return 0; } EXPORT_SYMBOL_GPL(of_device_uevent_modalias); + +/** + * of_device_make_bus_id - Use the device node data to assign a unique name + * @dev: pointer to device structure that is linked to a device tree node + * + * This routine will first try using the translated bus address to + * derive a unique name. If it cannot, then it will prepend names from + * parent nodes until a unique name can be derived. + */ +void of_device_make_bus_id(struct device *dev) +{ + struct device_node *node =3D dev->of_node; + const __be32 *reg; + u64 addr; + u32 mask; + + /* Construct the name, using parent nodes if necessary to ensure uniquene= ss */ + while (node->parent) { + /* + * If the address can be translated, then that is as much + * uniqueness as we need. Make it the first component and return + */ + reg =3D of_get_property(node, "reg", NULL); + if (reg && (addr =3D of_translate_address(node, reg)) !=3D OF_BAD_ADDR) { + if (!of_property_read_u32(node, "mask", &mask)) + dev_set_name(dev, dev_name(dev) ? "%llx.%x.%pOFn:%s" : "%llx.%x.%pOFn", + addr, ffs(mask) - 1, node, dev_name(dev)); + + else + dev_set_name(dev, dev_name(dev) ? "%llx.%pOFn:%s" : "%llx.%pOFn", + addr, node, dev_name(dev)); + return; + } + + /* format arguments only used if dev_name() resolves to NULL */ + dev_set_name(dev, dev_name(dev) ? "%s:%s" : "%s", + kbasename(node->full_name), dev_name(dev)); + node =3D node->parent; + } +} +EXPORT_SYMBOL_GPL(of_device_make_bus_id); diff --git a/drivers/of/platform.c b/drivers/of/platform.c index 126d265aa7d8..c39e49a1eba0 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -97,46 +97,6 @@ static const struct of_device_id of_skipped_node_table[]= =3D { * mechanism for creating devices from device tree nodes. */ =20 -/** - * of_device_make_bus_id - Use the device node data to assign a unique name - * @dev: pointer to device structure that is linked to a device tree node - * - * This routine will first try using the translated bus address to - * derive a unique name. If it cannot, then it will prepend names from - * parent nodes until a unique name can be derived. - */ -static void of_device_make_bus_id(struct device *dev) -{ - struct device_node *node =3D dev->of_node; - const __be32 *reg; - u64 addr; - u32 mask; - - /* Construct the name, using parent nodes if necessary to ensure uniquene= ss */ - while (node->parent) { - /* - * If the address can be translated, then that is as much - * uniqueness as we need. Make it the first component and return - */ - reg =3D of_get_property(node, "reg", NULL); - if (reg && (addr =3D of_translate_address(node, reg)) !=3D OF_BAD_ADDR) { - if (!of_property_read_u32(node, "mask", &mask)) - dev_set_name(dev, dev_name(dev) ? "%llx.%x.%pOFn:%s" : "%llx.%x.%pOFn", - addr, ffs(mask) - 1, node, dev_name(dev)); - - else - dev_set_name(dev, dev_name(dev) ? "%llx.%pOFn:%s" : "%llx.%pOFn", - addr, node, dev_name(dev)); - return; - } - - /* format arguments only used if dev_name() resolves to NULL */ - dev_set_name(dev, dev_name(dev) ? "%s:%s" : "%s", - kbasename(node->full_name), dev_name(dev)); - node =3D node->parent; - } -} - /** * of_device_alloc - Allocate and initialize an of_device * @np: device node to assign to device diff --git a/include/linux/of_device.h b/include/linux/of_device.h index 2c7a3d4bc775..a72661e47faa 100644 --- a/include/linux/of_device.h +++ b/include/linux/of_device.h @@ -40,6 +40,9 @@ static inline int of_dma_configure(struct device *dev, { return of_dma_configure_id(dev, np, force_dma, NULL); } + +void of_device_make_bus_id(struct device *dev); + #else /* CONFIG_OF */ =20 static inline int of_driver_match_device(struct device *dev, @@ -82,6 +85,9 @@ static inline int of_dma_configure(struct device *dev, { return 0; } + +static inline void of_device_make_bus_id(struct device *dev) {} + #endif /* CONFIG_OF */ =20 #endif /* _LINUX_OF_DEVICE_H */ --=20 2.25.1 From nobody Fri Dec 19 00:21:39 2025 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 72A7224A08 for ; Fri, 15 Dec 2023 11:15:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="daznrApv" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-336420a244dso384273f8f.0 for ; Fri, 15 Dec 2023 03:15:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1702638948; x=1703243748; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=H3wqcftJe3oQSGEVWIPzNX4f98nIVyBhsOjYp0bmWsA=; b=daznrApvU/99RFpf2BiLBAbAY+AREMvYVXsktTBaO84wEaOK42OiLb/2lyHVwDrwNE H16KXtMhZqf7didgKUSiZJIXREeFgZU1Wd20czDA1I9vf0zHXC+Ais+2zs+W5DPksvAm eVMRPyJMin8fNPyaAGJE8mwPQ92gkEewyjl3he4BKjrBixVCiS2PSH6dsQv7+DTnUWgP tnpDvrp6WODP7mU7SlvIuEr5FD2HY2+gz8j6J/Er4Kd+d2PQgtM9y2qOAt5knHEuKBiF HmT8LPJPJfkMxmx2wn5Oydx1oi3e3ngMYompm1F54uCoCSkm4OEo71g02Q0D0nnrW69N 1fcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702638948; x=1703243748; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=H3wqcftJe3oQSGEVWIPzNX4f98nIVyBhsOjYp0bmWsA=; b=lv5j1ahWdIbWJ8y9xJcNr2ehLqfORU2rnrzJ6BG2s/fX8zSzPGZ0/7KGGDWTFR16Nv wUgEHsO+z7lvl7JCWyNhELuuWXRT2bovpGeyTA0Ce+AlTy/AQ05YvbwJ4FMKd0dVnNf7 ma0XOFun3QGIslfjG/eMJRTN+1FL9myQ2+QGq9uqtrddfi2de9C5Im0uRKrdTS2l9J8K tyDfPwGMgR9EUH/JNeRJD1VIu+YAN7vg31FHMMA4xYFTlFKV1udmwHAGwDKNs2cUQRpt m/mgSkwGZzWAF/6YR0s3pkhxq24qiSYEIjHL49oq6fJFukcJjVwp1IFLhM3MF2xgCFfW A3jw== X-Gm-Message-State: AOJu0YzXdYGHE6W3D7L4xAnwZOCNlDAdPEiOgyEYvsRgMz6EmmVSmaoY Tj2t7h7WnciKGg7/mpE7dLaH/Q== X-Google-Smtp-Source: AGHT+IGO+5ZWVSXtpxtnkDfhkW8kSqeviOSB4kYHDAVdjTUAkU4tSDDj5CrrkiNq2+026yJf9XVyIw== X-Received: by 2002:adf:fc46:0:b0:336:4c4b:d702 with SMTP id e6-20020adffc46000000b003364c4bd702mr1000761wrs.117.1702638947761; Fri, 15 Dec 2023 03:15:47 -0800 (PST) Received: from localhost.localdomain ([5.133.47.210]) by smtp.gmail.com with ESMTPSA id g13-20020a056000118d00b003333d46a9e8sm18511497wrx.56.2023.12.15.03.15.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 03:15:47 -0800 (PST) From: srinivas.kandagatla@linaro.org To: gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, Miquel Raynal , Srinivas Kandagatla Subject: [PATCH 02/10] nvmem: Move of_nvmem_layout_get_container() in another header Date: Fri, 15 Dec 2023 11:15:28 +0000 Message-Id: <20231215111536.316972-3-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231215111536.316972-1-srinivas.kandagatla@linaro.org> References: <20231215111536.316972-1-srinivas.kandagatla@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3451; i=srinivas.kandagatla@linaro.org; h=from:subject; bh=IeHRu31C5pTVzTrxF1sImdme6q++k9V3VWhgQK6Fu00=; b=owEBbQGS/pANAwAKAXqh/VnHNFU3AcsmYgBlfDVX4w/9/C2iAEwJzuHX73JYOK4isekL678re sVRq8ZfhYKJATMEAAEKAB0WIQQi509axvzi9vce3Y16of1ZxzRVNwUCZXw1VwAKCRB6of1ZxzRV N4HNB/0Q044LJGF6ZBJnoPZ2mzx2v03HbI2RALPuBjoWSsfGXwDzBIbIiuIlp10N9HyRMM/ITEU gmSkpPXY3V9EMvPuMK2NPKv0IMU5qChaPyMAPxxTE06WjkCDvgTjPEdMSGEjz1P83pSQD1iJgh2 ybu8PaLl/XURNMiiWJMBEbyvEHxuurq7XnDQkLHHEAWR2wEVBpegAxBGboNZ+O1C8kiPbay4/ee Oz3nuteNRfRRLalE1rbQM0UqOV7psMGPb8RqdVDhPEwgJY4ukwgBXbG8yLZivdsChZ4QfMqsnxL gczRh/EfIf/w4Z2R5LOTb1FR40EI/fc1kVlnRmQlj8eiBuee X-Developer-Key: i=srinivas.kandagatla@linaro.org; a=openpgp; fpr=ED6472765AB36EC43B3EF97AD77E3FC0562560D6 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Miquel Raynal nvmem-consumer.h is included by consumer devices, extracting data from NVMEM devices whereas nvmem-provider.h is included by devices providing NVMEM content. The only users of of_nvmem_layout_get_container() outside of the core are layout drivers, so better move its prototype to nvmem-provider.h. While we do so, we also move the kdoc associated with the function to the header rather than the .c file. Signed-off-by: Miquel Raynal Signed-off-by: Srinivas Kandagatla --- drivers/nvmem/core.c | 8 -------- include/linux/nvmem-consumer.h | 7 ------- include/linux/nvmem-provider.h | 21 +++++++++++++++++++++ 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 608b352a7d91..b5b6ec8e04bb 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -847,14 +847,6 @@ static int nvmem_add_cells_from_layout(struct nvmem_de= vice *nvmem) } =20 #if IS_ENABLED(CONFIG_OF) -/** - * of_nvmem_layout_get_container() - Get OF node to layout container. - * - * @nvmem: nvmem device. - * - * Return: a node pointer with refcount incremented or NULL if no - * container exists. Use of_node_put() on it when done. - */ struct device_node *of_nvmem_layout_get_container(struct nvmem_device *nvm= em) { return of_get_child_by_name(nvmem->dev.of_node, "nvmem-layout"); diff --git a/include/linux/nvmem-consumer.h b/include/linux/nvmem-consumer.h index 6ec4b9743e25..2d306fa13b1a 100644 --- a/include/linux/nvmem-consumer.h +++ b/include/linux/nvmem-consumer.h @@ -247,7 +247,6 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node= *np, const char *id); struct nvmem_device *of_nvmem_device_get(struct device_node *np, const char *name); -struct device_node *of_nvmem_layout_get_container(struct nvmem_device *nvm= em); #else static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id) @@ -260,12 +259,6 @@ static inline struct nvmem_device *of_nvmem_device_get= (struct device_node *np, { return ERR_PTR(-EOPNOTSUPP); } - -static inline struct device_node * -of_nvmem_layout_get_container(struct nvmem_device *nvmem) -{ - return NULL; -} #endif /* CONFIG_NVMEM && CONFIG_OF */ =20 #endif /* ifndef _LINUX_NVMEM_CONSUMER_H */ diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index e3930835235b..e5de21516387 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -244,6 +244,27 @@ nvmem_layout_get_match_data(struct nvmem_device *nvmem, =20 #endif /* CONFIG_NVMEM */ =20 +#if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF) + +/** + * of_nvmem_layout_get_container() - Get OF node of layout container + * + * @nvmem: nvmem device + * + * Return: a node pointer with refcount incremented or NULL if no + * container exists. Use of_node_put() on it when done. + */ +struct device_node *of_nvmem_layout_get_container(struct nvmem_device *nvm= em); + +#else /* CONFIG_NVMEM && CONFIG_OF */ + +static inline struct device_node *of_nvmem_layout_get_container(struct nvm= em_device *nvmem) +{ + return NULL; +} + +#endif /* CONFIG_NVMEM && CONFIG_OF */ + #define module_nvmem_layout_driver(__layout_driver) \ module_driver(__layout_driver, nvmem_layout_register, \ nvmem_layout_unregister) --=20 2.25.1 From nobody Fri Dec 19 00:21:39 2025 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C1CD324B39 for ; Fri, 15 Dec 2023 11:15:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="P1t1c6rg" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-33644eeb305so365369f8f.1 for ; Fri, 15 Dec 2023 03:15:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1702638949; x=1703243749; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dS63jOQC9GkVvD/V3gnNGxfqDZcjIOnsJFZBb/UDQUo=; b=P1t1c6rgB8ALJs3XZXs6iwW0BTMBRA9CMnUPbYHVsZf5e6djiH91MnvXk0vL5rSRjn a4oyTWWn0dJhy6uoyoQwkjcLCX8fwYJN1zb2HPtasdc1SPBoJ9nLV8K8q28VSfwlSZtL lNApQZ/JrfGDmRSmNYI7KdS72K2sp73U7TWty1/KbMdwY7ZyclA6hqg+m0zQqyHQyb5o 8Y35Hxom/S+sBPbMD60aKzGWgYu7wynEcOaVaPKtrnevG8qxpA8+hGOGJg2f4alJW7W6 N+6krhlLr42wQX3xKYqZgIGNu+LlnYHk4uhtzkbcCVFb1ojSPnpPkk5J8AJMO0/rKLZN Bmtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702638949; x=1703243749; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dS63jOQC9GkVvD/V3gnNGxfqDZcjIOnsJFZBb/UDQUo=; b=hiCWE8Ci+BN3hbjHAXCvkjh4VyEhd3DDs9jJ9SnEpswMagZsP/Bls5J7HMsk5UQgu6 WtTvr9bXOVcPfs5sYGWal3lgZ1BLVFC5rJy6UR3n0DrUym7Lxwa94sRy4ZqPKVj43Ve8 w9FLifWMB1IZssHhxlk2AmHSgxAvBa1XL/jOcxTc4U8J0IvCDPc99ayIwUN7JXSnrBUc r3H7RuSOeH3ItBF0rf95AkXFbeY/IyZYf71ZLjJeUrltjbUzEniSBsMZAqKsETWcF/L3 gEr9n1iRWgyumfgCQNTFKEWEQey7be4RhqEciIrxWTRTOxgCA5uWz+ogNpgii18ZlmhU MtSQ== X-Gm-Message-State: AOJu0YyzpxXPOi/X14HlsVAG0Hp3yyp8RyZqXXvfQqc/HTicRshN66M0 sShIYenky7QA+ZywOED4vuf1pKvJJ4la4HEFqRc= X-Google-Smtp-Source: AGHT+IGpRCwfcPMbXdRNr3VTZUkVRoaZGPsWBzZK7CSfIDETmvrPl+Iw6W3aY+6bXLrJCucVp/kbmQ== X-Received: by 2002:adf:f70b:0:b0:336:4bfe:5ab2 with SMTP id r11-20020adff70b000000b003364bfe5ab2mr985429wrp.8.1702638949128; Fri, 15 Dec 2023 03:15:49 -0800 (PST) Received: from localhost.localdomain ([5.133.47.210]) by smtp.gmail.com with ESMTPSA id g13-20020a056000118d00b003333d46a9e8sm18511497wrx.56.2023.12.15.03.15.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 03:15:48 -0800 (PST) From: srinivas.kandagatla@linaro.org To: gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, Miquel Raynal , Srinivas Kandagatla Subject: [PATCH 03/10] nvmem: Create a header for internal sharing Date: Fri, 15 Dec 2023 11:15:29 +0000 Message-Id: <20231215111536.316972-4-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231215111536.316972-1-srinivas.kandagatla@linaro.org> References: <20231215111536.316972-1-srinivas.kandagatla@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2565; i=srinivas.kandagatla@linaro.org; h=from:subject; bh=d1EHrgw6/UsDnp63wQlkSGInigR3iNX9QLiyg3bQooY=; b=owEBbQGS/pANAwAKAXqh/VnHNFU3AcsmYgBlfDVXpdB0V9fnBQLtQID2BdPAhCafnEKO73j8W jQhMlQ0uRyJATMEAAEKAB0WIQQi509axvzi9vce3Y16of1ZxzRVNwUCZXw1VwAKCRB6of1ZxzRV N4tQB/0Qpo/abKZeansCugSOlN79NtCIjjJQ9Rv26Kiaty+3AwNSasbjC5KbCMgeLtU6EOC8/Yr 1gVO7ChnZ3lVT9UeCxMaQ4igZsEHNZX2tkhwCyzazIvVe3kj9bdjkr/tXVqE8rIAbl2eV0H02Ai h3ZkZVSqX9v6RXmfdE2USB9NdKHa1ZlQoerUjg9knQu6VdkHa0OK62/uFcl4Nhd+fFlJ++eWGek vxFkkBTKouVfk8UP757RMA9y6xh1I7p6d2I+cDz26Eej2HrgER61e5lFBXiTvNc8E6QzQ1t6a55 /rHTjmD2R4GT2vGWcZtWlhyKvHT+2qe/VTZ3vZT8Ioi4seg4 X-Developer-Key: i=srinivas.kandagatla@linaro.org; a=openpgp; fpr=ED6472765AB36EC43B3EF97AD77E3FC0562560D6 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Miquel Raynal Before adding all the NVMEM layout bus infrastructure to the core, let's move the main nvmem_device structure in an internal header, only available to the core. This way all the additional code can be added in a dedicated file in order to keep the current core file tidy. Signed-off-by: Miquel Raynal Signed-off-by: Srinivas Kandagatla --- drivers/nvmem/core.c | 24 +----------------------- drivers/nvmem/internals.h | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 23 deletions(-) create mode 100644 drivers/nvmem/internals.h diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index b5b6ec8e04bb..b5e5ce67398f 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -19,29 +19,7 @@ #include #include =20 -struct nvmem_device { - struct module *owner; - struct device dev; - int stride; - int word_size; - int id; - struct kref refcnt; - size_t size; - bool read_only; - bool root_only; - int flags; - enum nvmem_type type; - struct bin_attribute eeprom; - struct device *base_dev; - struct list_head cells; - const struct nvmem_keepout *keepout; - unsigned int nkeepout; - nvmem_reg_read_t reg_read; - nvmem_reg_write_t reg_write; - struct gpio_desc *wp_gpio; - struct nvmem_layout *layout; - void *priv; -}; +#include "internals.h" =20 #define to_nvmem_device(d) container_of(d, struct nvmem_device, dev) =20 diff --git a/drivers/nvmem/internals.h b/drivers/nvmem/internals.h new file mode 100644 index 000000000000..ce353831cd65 --- /dev/null +++ b/drivers/nvmem/internals.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _LINUX_NVMEM_INTERNALS_H +#define _LINUX_NVMEM_INTERNALS_H + +#include +#include +#include + +struct nvmem_device { + struct module *owner; + struct device dev; + struct list_head node; + int stride; + int word_size; + int id; + struct kref refcnt; + size_t size; + bool read_only; + bool root_only; + int flags; + enum nvmem_type type; + struct bin_attribute eeprom; + struct device *base_dev; + struct list_head cells; + const struct nvmem_keepout *keepout; + unsigned int nkeepout; + nvmem_reg_read_t reg_read; + nvmem_reg_write_t reg_write; + struct gpio_desc *wp_gpio; + struct nvmem_layout *layout; + void *priv; +}; + +#endif /* ifndef _LINUX_NVMEM_INTERNALS_H */ --=20 2.25.1 From nobody Fri Dec 19 00:21:39 2025 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B315250E2 for ; Fri, 15 Dec 2023 11:15:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="NMwvKkwj" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-3333074512bso933664f8f.1 for ; Fri, 15 Dec 2023 03:15:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1702638950; x=1703243750; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Tv1+SAp30QuqxkV8Rm8OeVD8ARUBR+gXbTPrU19ZNuA=; b=NMwvKkwjJWMF1euohSkTRUjh2IpaFVybLhPuGfWozFStcvGmAd5yAXLJM6TCD5xchh bsyGI60sbfL1iiqHPxLHI5ym68a9uk0syeNxQFWO7wkewos+DN1azF+GZ3siByC+5bSb XPF01rEIb9KMG+mV93pUVql8kjjZE2sFEojK4wgnqUO8C01ykxXnbhNX157X/8HNAW8l K/X0t5lwA5/8VY8j7lj//yJPQtS87erfPIQyLL7rVPx4Oxhofcn7KN8RzV4UWWC99DRz QjHOUWrsJAQfNhF9XJb9wsWjMoZK2RAybQuFCme0auOksUdryaGVUEqKtZHeZoEofko0 KRIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702638950; x=1703243750; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Tv1+SAp30QuqxkV8Rm8OeVD8ARUBR+gXbTPrU19ZNuA=; b=kBTSsRrxnUseR5EANKeynJgkefRdIvpQlwPT5/jsb1eYPHY/Oa776+dYGyv+VXmS4T ZYJfnQYHyaLdB9GNLjR0oF6YQ9gmqzxSrvDbOt3i3/IHT0qBT62TWX1gy56jfyMPYrQx 2VN3GkTzVWq+TfmJj7H4UB2l7ftRi1AVIyJPKxCqO/DhjY8jm9PyLY26QdGc0w2pbWub bGDxgd2bTbvv5UykwWK99vWDkSMDP/t4k179X1imsKKRAy0Dz3s7LSHJm3jbhfr6R2w4 oK12eqvrKKdAMhGUdPfl5ZKhZE6j4wZpimYx1f/qHbfIE3bzWhMIrFatwo1O8nAN7FT2 lp/g== X-Gm-Message-State: AOJu0YwJLL1lTQTkJGNZkgELwd8nAEXfVjF4BoR6gXkWeWlq9Hm5XRNy 1wApBy/4/83YHNJPlpEZFsM6qZVJqfRpzY1zOVs= X-Google-Smtp-Source: AGHT+IFbkO7aUALJvcXI1HkyZSixbD3n8NGQAJWtXa/JjL1LZH066Li1MTHmYcLKO8i0Ikaicf2Atw== X-Received: by 2002:a5d:58cf:0:b0:336:3dd1:e39b with SMTP id o15-20020a5d58cf000000b003363dd1e39bmr2141093wrf.31.1702638949945; Fri, 15 Dec 2023 03:15:49 -0800 (PST) Received: from localhost.localdomain ([5.133.47.210]) by smtp.gmail.com with ESMTPSA id g13-20020a056000118d00b003333d46a9e8sm18511497wrx.56.2023.12.15.03.15.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 03:15:49 -0800 (PST) From: srinivas.kandagatla@linaro.org To: gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, Miquel Raynal , Srinivas Kandagatla Subject: [PATCH 04/10] nvmem: Simplify the ->add_cells() hook Date: Fri, 15 Dec 2023 11:15:30 +0000 Message-Id: <20231215111536.316972-5-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231215111536.316972-1-srinivas.kandagatla@linaro.org> References: <20231215111536.316972-1-srinivas.kandagatla@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3336; i=srinivas.kandagatla@linaro.org; h=from:subject; bh=qT+nEn+r7xwI19VeUnEAbro3PIHpWLZfcTXcGh7CnWk=; b=owGbwMvMwMVYtfBv5HGTUHPG02pJDKk1puGFn9/q+On/ZLgvrZXkK7eT9Tyr4dsT6ZOm3tC0O GN/tzu6k9GYhYGRi0FWTJFF6bl/1LE/j759l7vbCzOIlQlkCgMXpwBMZOpK9n8mRbYn/nCkrdgU P39HtBl3UcZX9aLp86ef5My2eG6QVzpfyKDvUr/6wTW5wpHv1G/YNGQ+Kr8sVfTn0sUUzn65LaE G77rlrXj0/mhH1ulP9PufqxZqEVp2qvpV8Kun828/0rJKtmG5tqazVXurz9HDy0zFL01aEth6TG zmXm/lVBXRYkOBBaev/IwJT7BYH3pJpHAb74lPHBdUdR/JJvV2bxGXnZpiF1MiO5FdhldcYZWre bLMhLrTXnY6e6Tb/r6LfSE4bU3H59wgiapjvJVywu8FdvHzXMmfVtbRGa37MM3Vt27GfUa3vwFf DJuXPHu2OvpYgqjdutdZGneSOx/8/XMxWeL23UNyLN/cAQ== X-Developer-Key: i=srinivas.kandagatla@linaro.org; a=openpgp; fpr=ED6472765AB36EC43B3EF97AD77E3FC0562560D6 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Miquel Raynal The layout entry is not used and will anyway be made useless by the new layout bus infrastructure coming next, so drop it. While at it, clarify the kdoc entry. Signed-off-by: Miquel Raynal Signed-off-by: Srinivas Kandagatla --- drivers/nvmem/core.c | 2 +- drivers/nvmem/layouts/onie-tlv.c | 3 +-- drivers/nvmem/layouts/sl28vpd.c | 3 +-- include/linux/nvmem-provider.h | 8 +++----- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index b5e5ce67398f..f63db5e01fca 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -816,7 +816,7 @@ static int nvmem_add_cells_from_layout(struct nvmem_dev= ice *nvmem) int ret; =20 if (layout && layout->add_cells) { - ret =3D layout->add_cells(&nvmem->dev, nvmem, layout); + ret =3D layout->add_cells(&nvmem->dev, nvmem); if (ret) return ret; } diff --git a/drivers/nvmem/layouts/onie-tlv.c b/drivers/nvmem/layouts/onie-= tlv.c index 59fc87ccfcff..defd42d4375c 100644 --- a/drivers/nvmem/layouts/onie-tlv.c +++ b/drivers/nvmem/layouts/onie-tlv.c @@ -182,8 +182,7 @@ static bool onie_tlv_crc_is_valid(struct device *dev, s= ize_t table_len, u8 *tabl return true; } =20 -static int onie_tlv_parse_table(struct device *dev, struct nvmem_device *n= vmem, - struct nvmem_layout *layout) +static int onie_tlv_parse_table(struct device *dev, struct nvmem_device *n= vmem) { struct onie_tlv_hdr hdr; size_t table_len, data_len, hdr_len; diff --git a/drivers/nvmem/layouts/sl28vpd.c b/drivers/nvmem/layouts/sl28vp= d.c index 05671371f631..26c7cf21b523 100644 --- a/drivers/nvmem/layouts/sl28vpd.c +++ b/drivers/nvmem/layouts/sl28vpd.c @@ -80,8 +80,7 @@ static int sl28vpd_v1_check_crc(struct device *dev, struc= t nvmem_device *nvmem) return 0; } =20 -static int sl28vpd_add_cells(struct device *dev, struct nvmem_device *nvme= m, - struct nvmem_layout *layout) +static int sl28vpd_add_cells(struct device *dev, struct nvmem_device *nvme= m) { const struct nvmem_cell_info *pinfo; struct nvmem_cell_info info =3D {0}; diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index e5de21516387..3939991b3c5f 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -156,9 +156,8 @@ struct nvmem_cell_table { * * @name: Layout name. * @of_match_table: Open firmware match table. - * @add_cells: Will be called if a nvmem device is found which - * has this layout. The function will add layout - * specific cells with nvmem_add_one_cell(). + * @add_cells: Called to populate the layout using + * nvmem_add_one_cell(). * @fixup_cell_info: Will be called before a cell is added. Can be * used to modify the nvmem_cell_info. * @owner: Pointer to struct module. @@ -172,8 +171,7 @@ struct nvmem_cell_table { struct nvmem_layout { const char *name; const struct of_device_id *of_match_table; - int (*add_cells)(struct device *dev, struct nvmem_device *nvmem, - struct nvmem_layout *layout); + int (*add_cells)(struct device *dev, struct nvmem_device *nvmem); void (*fixup_cell_info)(struct nvmem_device *nvmem, struct nvmem_layout *layout, struct nvmem_cell_info *cell); --=20 2.25.1 From nobody Fri Dec 19 00:21:39 2025 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A583625561 for ; Fri, 15 Dec 2023 11:15:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Vf8ZE4q0" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-40c1e3ea2f2so5157085e9.2 for ; Fri, 15 Dec 2023 03:15:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1702638951; x=1703243751; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vf01rCZNs+PJUcph0LJ9xDFnWBedH3iX5y7d50fBsIk=; b=Vf8ZE4q0PS+WjT6xWQSiY0E7IOlIHy8FFW2O2TdM4gJm06bhGcgQmK0a2yVv/ZZ8zC 8pQZ3Kvh00y6FY/DSzrgvNp6QltdeXZrxaX9JR8jvkskGQFW5x7AiJcLI0qIEtUt1HBy ja6QLH6mkH4N9zR98RyixXf8cZ9bDuTeVUo+cHdYBMchGSChTP25gUhSzPukFVkb7v11 zaUqCa6IDz/ETnlJJGHm0umsrtBLD4SW8lSngDeKTBKT+4UGDUFk+qH1TDLl+X0P7hQj U3kTFo7Bm+XFRvZie9o6x1gWGMsRDWRmWPYiq2qUZBZlbWB9CkBFPvN1Kr7753d+cmBU IVHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702638951; x=1703243751; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vf01rCZNs+PJUcph0LJ9xDFnWBedH3iX5y7d50fBsIk=; b=taej9xh1s8b3ZodxGZxcOQceQPzUYnQzMUH3gibkuLLB/vrLQMqYxpSez1LF/sW2ON gTSiLkBRDT6ThpC21oK6zF4C8VPcsS/P76vTwhC7L3Inj5sSEgRABPi2q6nYSLfsQnoR OQ98H5WDHkK9Xxjzhgl4g9VgDGD7Y/MVQzeZdKfKvOmmokeengqxJBOtKzFwtZzJlhtq TMCIN8Xl9Fna2fDW9/B5uzU58jYjFIkw4Gesv0YH2xxNwoj8HmaXSq6wgyZzMf0bhhT1 7n9XI9r074LXSA82OYgyjrmERUpRaPKvgvHUUKa8iNiZMvaQzyu4NOmoDOz7VxaO/YLG 4g9g== X-Gm-Message-State: AOJu0YzP+miQJO8bb0zNnRktPB1mjczMQu0fMyBBBA+32IgAXl1o1Di8 cURbv92e4/CfsyrlL+VJHTLv4lcGRipAgfejqqI= X-Google-Smtp-Source: AGHT+IHc5BnjKeKbvk3KxtuAx1J6qEDt6m00OlC4Vt97548PUCJpJEODPb7x9n8NUVtWwxGsNIOPig== X-Received: by 2002:a05:6000:184f:b0:336:492c:78ff with SMTP id c15-20020a056000184f00b00336492c78ffmr1648229wri.105.1702638950956; Fri, 15 Dec 2023 03:15:50 -0800 (PST) Received: from localhost.localdomain ([5.133.47.210]) by smtp.gmail.com with ESMTPSA id g13-20020a056000118d00b003333d46a9e8sm18511497wrx.56.2023.12.15.03.15.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 03:15:50 -0800 (PST) From: srinivas.kandagatla@linaro.org To: gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, Miquel Raynal , Srinivas Kandagatla Subject: [PATCH 05/10] nvmem: Move and rename ->fixup_cell_info() Date: Fri, 15 Dec 2023 11:15:31 +0000 Message-Id: <20231215111536.316972-6-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231215111536.316972-1-srinivas.kandagatla@linaro.org> References: <20231215111536.316972-1-srinivas.kandagatla@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=6682; i=srinivas.kandagatla@linaro.org; h=from:subject; bh=XG5KX8SfWmX9pvjWJZAJ+CNIBRWVO3JTz3rW0C54F/U=; b=owEBbQGS/pANAwAKAXqh/VnHNFU3AcsmYgBlfDVXuIMnLmTFPbZQCNEgbcPPtySg7god6A1sC AcH33AuMbKJATMEAAEKAB0WIQQi509axvzi9vce3Y16of1ZxzRVNwUCZXw1VwAKCRB6of1ZxzRV NzRAB/0eYNEcKULKdiIDWHFT2wKV+RqSFs+yfjycokpsmF8MnEQTqFBQfWKe9HRMhId05H6BHKL Aa5/UzuOU8RHeF2CEPvWTYI/aqjZVX1IFBX3at6mWMOjVJH+MQi8cvQFnRMxSlvaIAozFqSdL84 2nZf0TJCCj9y3q3gC0fuIfOhkCWudgg0imfiuipkPZH4TDKpFYGkdvMpnQOwHr0FhWeKJ52q77/ QCeDwgdbSiK+RnM3kzuqk28/yrNS9tWxvDiShCh4jo9CBm+oqQ/0vL6w7aRCW1BadZJAThphWcr I9CaPEVU/zoG5XBb69Ca6Ji6iATlVK1tcn+9zMFc9Rf0q466 X-Developer-Key: i=srinivas.kandagatla@linaro.org; a=openpgp; fpr=ED6472765AB36EC43B3EF97AD77E3FC0562560D6 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Miquel Raynal This hook is meant to be used by any provider and instantiating a layout just for this is useless. Let's instead move this hook to the nvmem device and add it to the config structure to be easily shared by the providers. While at moving this hook, rename it ->fixup_dt_cell_info() to clarify its main intended purpose. Signed-off-by: Miquel Raynal Signed-off-by: Srinivas Kandagatla --- drivers/nvmem/core.c | 6 +++--- drivers/nvmem/imx-ocotp.c | 11 +++-------- drivers/nvmem/internals.h | 2 ++ drivers/nvmem/mtk-efuse.c | 11 +++-------- include/linux/nvmem-provider.h | 9 ++++----- 5 files changed, 15 insertions(+), 24 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index f63db5e01fca..a885713d6b4b 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -675,7 +675,6 @@ static int nvmem_validate_keepouts(struct nvmem_device = *nvmem) =20 static int nvmem_add_cells_from_dt(struct nvmem_device *nvmem, struct devi= ce_node *np) { - struct nvmem_layout *layout =3D nvmem->layout; struct device *dev =3D &nvmem->dev; struct device_node *child; const __be32 *addr; @@ -705,8 +704,8 @@ static int nvmem_add_cells_from_dt(struct nvmem_device = *nvmem, struct device_nod =20 info.np =3D of_node_get(child); =20 - if (layout && layout->fixup_cell_info) - layout->fixup_cell_info(nvmem, layout, &info); + if (nvmem->fixup_dt_cell_info) + nvmem->fixup_dt_cell_info(nvmem, &info); =20 ret =3D nvmem_add_one_cell(nvmem, &info); kfree(info.name); @@ -895,6 +894,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_= config *config) =20 kref_init(&nvmem->refcnt); INIT_LIST_HEAD(&nvmem->cells); + nvmem->fixup_dt_cell_info =3D config->fixup_dt_cell_info; =20 nvmem->owner =3D config->owner; if (!nvmem->owner && config->dev->driver) diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c index f1e202efaa49..79dd4fda0329 100644 --- a/drivers/nvmem/imx-ocotp.c +++ b/drivers/nvmem/imx-ocotp.c @@ -583,17 +583,12 @@ static const struct of_device_id imx_ocotp_dt_ids[] = =3D { }; MODULE_DEVICE_TABLE(of, imx_ocotp_dt_ids); =20 -static void imx_ocotp_fixup_cell_info(struct nvmem_device *nvmem, - struct nvmem_layout *layout, - struct nvmem_cell_info *cell) +static void imx_ocotp_fixup_dt_cell_info(struct nvmem_device *nvmem, + struct nvmem_cell_info *cell) { cell->read_post_process =3D imx_ocotp_cell_pp; } =20 -static struct nvmem_layout imx_ocotp_layout =3D { - .fixup_cell_info =3D imx_ocotp_fixup_cell_info, -}; - static int imx_ocotp_probe(struct platform_device *pdev) { struct device *dev =3D &pdev->dev; @@ -619,7 +614,7 @@ static int imx_ocotp_probe(struct platform_device *pdev) imx_ocotp_nvmem_config.size =3D 4 * priv->params->nregs; imx_ocotp_nvmem_config.dev =3D dev; imx_ocotp_nvmem_config.priv =3D priv; - imx_ocotp_nvmem_config.layout =3D &imx_ocotp_layout; + imx_ocotp_nvmem_config.fixup_dt_cell_info =3D &imx_ocotp_fixup_dt_cell_in= fo; =20 priv->config =3D &imx_ocotp_nvmem_config; =20 diff --git a/drivers/nvmem/internals.h b/drivers/nvmem/internals.h index ce353831cd65..893553fbdf51 100644 --- a/drivers/nvmem/internals.h +++ b/drivers/nvmem/internals.h @@ -23,6 +23,8 @@ struct nvmem_device { struct bin_attribute eeprom; struct device *base_dev; struct list_head cells; + void (*fixup_dt_cell_info)(struct nvmem_device *nvmem, + struct nvmem_cell_info *cell); const struct nvmem_keepout *keepout; unsigned int nkeepout; nvmem_reg_read_t reg_read; diff --git a/drivers/nvmem/mtk-efuse.c b/drivers/nvmem/mtk-efuse.c index 87c94686cfd2..84f05b40a411 100644 --- a/drivers/nvmem/mtk-efuse.c +++ b/drivers/nvmem/mtk-efuse.c @@ -45,9 +45,8 @@ static int mtk_efuse_gpu_speedbin_pp(void *context, const= char *id, int index, return 0; } =20 -static void mtk_efuse_fixup_cell_info(struct nvmem_device *nvmem, - struct nvmem_layout *layout, - struct nvmem_cell_info *cell) +static void mtk_efuse_fixup_dt_cell_info(struct nvmem_device *nvmem, + struct nvmem_cell_info *cell) { size_t sz =3D strlen(cell->name); =20 @@ -61,10 +60,6 @@ static void mtk_efuse_fixup_cell_info(struct nvmem_devic= e *nvmem, cell->read_post_process =3D mtk_efuse_gpu_speedbin_pp; } =20 -static struct nvmem_layout mtk_efuse_layout =3D { - .fixup_cell_info =3D mtk_efuse_fixup_cell_info, -}; - static int mtk_efuse_probe(struct platform_device *pdev) { struct device *dev =3D &pdev->dev; @@ -91,7 +86,7 @@ static int mtk_efuse_probe(struct platform_device *pdev) econfig.priv =3D priv; econfig.dev =3D dev; if (pdata->uses_post_processing) - econfig.layout =3D &mtk_efuse_layout; + econfig.fixup_dt_cell_info =3D &mtk_efuse_fixup_dt_cell_info; nvmem =3D devm_nvmem_register(dev, &econfig); =20 return PTR_ERR_OR_ZERO(nvmem); diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index 3939991b3c5f..36415a602d9e 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -83,6 +83,8 @@ struct nvmem_cell_info { * @cells: Optional array of pre-defined NVMEM cells. * @ncells: Number of elements in cells. * @add_legacy_fixed_of_cells: Read fixed NVMEM cells from old OF syntax. + * @fixup_dt_cell_info: Will be called before a cell is added. Can be + * used to modify the nvmem_cell_info. * @keepout: Optional array of keepout ranges (sorted ascending by start). * @nkeepout: Number of elements in the keepout array. * @type: Type of the nvmem storage @@ -113,6 +115,8 @@ struct nvmem_config { const struct nvmem_cell_info *cells; int ncells; bool add_legacy_fixed_of_cells; + void (*fixup_dt_cell_info)(struct nvmem_device *nvmem, + struct nvmem_cell_info *cell); const struct nvmem_keepout *keepout; unsigned int nkeepout; enum nvmem_type type; @@ -158,8 +162,6 @@ struct nvmem_cell_table { * @of_match_table: Open firmware match table. * @add_cells: Called to populate the layout using * nvmem_add_one_cell(). - * @fixup_cell_info: Will be called before a cell is added. Can be - * used to modify the nvmem_cell_info. * @owner: Pointer to struct module. * @node: List node. * @@ -172,9 +174,6 @@ struct nvmem_layout { const char *name; const struct of_device_id *of_match_table; int (*add_cells)(struct device *dev, struct nvmem_device *nvmem); - void (*fixup_cell_info)(struct nvmem_device *nvmem, - struct nvmem_layout *layout, - struct nvmem_cell_info *cell); =20 /* private */ struct module *owner; --=20 2.25.1 From nobody Fri Dec 19 00:21:39 2025 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5BD72288B0 for ; Fri, 15 Dec 2023 11:15:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="pkSaAkRS" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-33638e7f71aso268174f8f.1 for ; Fri, 15 Dec 2023 03:15:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1702638952; x=1703243752; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jmK/5nuUWtg26bIJFH0hmWM12krrxgYPI0mvhBQxbPw=; b=pkSaAkRS468gg7MmxYF2SS/UBFcjkJYFsuz9m3UGBSEP0DPAYyyUPt3uJEjWi+oSYK SLZ9dnrH2EjZ3cY9EoPvGLIIxN7iPjfMfdCQLnmMyYt6OBWqoskcYcQGSSwLpjnfaZib Nwaror9+2YtBjjndpzCOjc2XvLOGckG60YpdHUEpsd+jvd7NNMKUUKFnANCg7So68w+a XwqL3qlkIgqwNICzcghixeyMXOnze+PAwHZYlIKPOPbAolNaVl0NDOL2u+JHfx5uDtlD /mIgw588GgYeif1tkGWvEiaxz0RAlLTIoa572dGpzcLhaD2qDkGOmXrBxLxgk386+MEk +YVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702638952; x=1703243752; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jmK/5nuUWtg26bIJFH0hmWM12krrxgYPI0mvhBQxbPw=; b=tpZMHE3FjtaIQxNlfMkNk32x0cipBzRxETF0LX0bSHT9Iz7fnpXIly7sMEhrACVgDE 2+yOuD45j4oTsvtAHIs74kw/E8gWSoeR/+FJAtj0BomkxPsgq6SWDIfKIX5+KEX6uJr0 Q8Jpkld+nRPpOZhBP/dK8E9xZViRW2IFL2lG7r8GkaV4DRNpFjpBtAbT/GIk1PvNsIEC 8UkBHt/09qMwMI39SGcwtJ1xX6qVn1q/yV/rdsFt7E/O1XpzJhA+o42fdO3mqOsXm6ZK VqzcdFFp3Lz31QNch59Q66AKeAMRDxsySmEr9rusL5JCp3Tfkm+2TaLzYmcEfFTjN3YK pIMA== X-Gm-Message-State: AOJu0YwBSn9Drw6r+CeqEp2ZgO/VQwdk7EBXFiBs/1V0qr7er3tAnEJv wgxRfD0UTeCT0WRlgSbqHjwJnA== X-Google-Smtp-Source: AGHT+IEVwBKmKafiW/au5HaFWbxp8yXc6riJyPyhAmYsbZPI6nT1nci51m498qID6TEp+LrKlYqEOw== X-Received: by 2002:a5d:5148:0:b0:336:42d2:97f3 with SMTP id u8-20020a5d5148000000b0033642d297f3mr1791890wrt.70.1702638951760; Fri, 15 Dec 2023 03:15:51 -0800 (PST) Received: from localhost.localdomain ([5.133.47.210]) by smtp.gmail.com with ESMTPSA id g13-20020a056000118d00b003333d46a9e8sm18511497wrx.56.2023.12.15.03.15.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 03:15:51 -0800 (PST) From: srinivas.kandagatla@linaro.org To: gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, Miquel Raynal , =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= , Srinivas Kandagatla Subject: [PATCH 06/10] nvmem: core: Rework layouts to become regular devices Date: Fri, 15 Dec 2023 11:15:32 +0000 Message-Id: <20231215111536.316972-7-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231215111536.316972-1-srinivas.kandagatla@linaro.org> References: <20231215111536.316972-1-srinivas.kandagatla@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Developer-Signature: v=1; a=openpgp-sha256; l=23023; i=srinivas.kandagatla@linaro.org; h=from:subject; bh=tPvJLoCIlEgWCe6a8N4xtAXSZXfLBGril3r8Injwa24=; b=owEBbQGS/pANAwAKAXqh/VnHNFU3AcsmYgBlfDVXm0HoQFMLYvdkXWZo8W/kK/7S0jR5f+0B0 p6zzgsh1pCJATMEAAEKAB0WIQQi509axvzi9vce3Y16of1ZxzRVNwUCZXw1VwAKCRB6of1ZxzRV N/prCACZZM02UA4UgsdNZh0E8CFFbxigOp5dhGpAkqRS8i+QNlwocKiPd5sYcNVuDg7gOavlRy7 esXRPa5nTT5SzJ0PoUXO7y5kXWxekEeqG6SueStyJTZX5z0oBcOj8VpgeYVyv5z3A8suaxf3uoK tYLHoEAoHP10KP5wJfigesaEtVY8rqpIWVOHAgIQoZlBv2l/nMPIHs4aiBpK8QLpfx+uJKIy70K 6yZbztBOHbd5+pPxSiyPZ3MiXc7ZcXM32P6XvwCcThDnS0QhJy8w8hcmHZGCcP/qj7GerxL5+o1 kV4llB5bM1t5V/tvCDOBZfQXWzT8WP1dWX8qDvis9TmPRyzJ X-Developer-Key: i=srinivas.kandagatla@linaro.org; a=openpgp; fpr=ED6472765AB36EC43B3EF97AD77E3FC0562560D6 Content-Transfer-Encoding: quoted-printable From: Miquel Raynal Current layout support was initially written without modules support in mind. When the requirement for module support rose, the existing base was improved to adopt modularization support, but kind of a design flaw was introduced. With the existing implementation, when a storage device registers into NVMEM, the core tries to hook a layout (if any) and populates its cells immediately. This means, if the hardware description expects a layout to be hooked up, but no driver was provided for that, the storage medium will fail to probe and try later from scratch. Even if we consider that the hardware description shall be correct, we could still probe the storage device (especially if it contains the rootfs). One way to overcome this situation is to consider the layouts as devices, and leverage the native notifier mechanism. When a new NVMEM device is registered, we can populate its nvmem-layout child, if any, and wait for the matching to be done in order to get the cells (the waiting can be easily done with the NVMEM notifiers). If the layout driver is compiled as a module, it should automatically be loaded. This way, there is no strong order to enforce, any NVMEM device creation or NVMEM layout driver insertion will be observed as a new event which may lead to the creation of additional cells, without disturbing the probes with costly (and sometimes endless) deferrals. In order to achieve that goal we create a new bus for the nvmem-layouts with minimal logic to match nvmem-layout devices with nvmem-layout drivers. All this infrastructure code is created in the layouts.c file. Signed-off-by: Miquel Raynal Tested-by: Rafa=C5=82 Mi=C5=82ecki Signed-off-by: Srinivas Kandagatla --- drivers/nvmem/Kconfig | 1 + drivers/nvmem/Makefile | 2 + drivers/nvmem/core.c | 170 ++++++++++---------------- drivers/nvmem/internals.h | 21 ++++ drivers/nvmem/layouts.c | 201 +++++++++++++++++++++++++++++++ drivers/nvmem/layouts/Kconfig | 8 ++ drivers/nvmem/layouts/onie-tlv.c | 24 +++- drivers/nvmem/layouts/sl28vpd.c | 24 +++- include/linux/nvmem-provider.h | 38 +++--- 9 files changed, 354 insertions(+), 135 deletions(-) create mode 100644 drivers/nvmem/layouts.c diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig index 5bc9c4874fe3..283134498fbc 100644 --- a/drivers/nvmem/Kconfig +++ b/drivers/nvmem/Kconfig @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only menuconfig NVMEM bool "NVMEM Support" + imply NVMEM_LAYOUTS help Support for NVMEM(Non Volatile Memory) devices like EEPROM, EFUSES... =20 diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile index 423baf089515..cdd01fbf1313 100644 --- a/drivers/nvmem/Makefile +++ b/drivers/nvmem/Makefile @@ -5,6 +5,8 @@ =20 obj-$(CONFIG_NVMEM) +=3D nvmem_core.o nvmem_core-y :=3D core.o +obj-$(CONFIG_NVMEM_LAYOUTS) +=3D nvmem_layouts.o +nvmem_layouts-y :=3D layouts.o obj-y +=3D layouts/ =20 # Devices diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index a885713d6b4b..4c2154ddf8a7 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -55,9 +55,6 @@ static LIST_HEAD(nvmem_lookup_list); =20 static BLOCKING_NOTIFIER_HEAD(nvmem_notifier); =20 -static DEFINE_SPINLOCK(nvmem_layout_lock); -static LIST_HEAD(nvmem_layouts); - static int __nvmem_reg_read(struct nvmem_device *nvmem, unsigned int offse= t, void *val, size_t bytes) { @@ -740,97 +737,22 @@ static int nvmem_add_cells_from_fixed_layout(struct n= vmem_device *nvmem) return err; } =20 -int __nvmem_layout_register(struct nvmem_layout *layout, struct module *ow= ner) +int nvmem_layout_register(struct nvmem_layout *layout) { - layout->owner =3D owner; - - spin_lock(&nvmem_layout_lock); - list_add(&layout->node, &nvmem_layouts); - spin_unlock(&nvmem_layout_lock); - - blocking_notifier_call_chain(&nvmem_notifier, NVMEM_LAYOUT_ADD, layout); + if (!layout->add_cells) + return -EINVAL; =20 - return 0; + /* Populate the cells */ + return layout->add_cells(&layout->nvmem->dev, layout->nvmem); } -EXPORT_SYMBOL_GPL(__nvmem_layout_register); +EXPORT_SYMBOL_GPL(nvmem_layout_register); =20 void nvmem_layout_unregister(struct nvmem_layout *layout) { - blocking_notifier_call_chain(&nvmem_notifier, NVMEM_LAYOUT_REMOVE, layout= ); - - spin_lock(&nvmem_layout_lock); - list_del(&layout->node); - spin_unlock(&nvmem_layout_lock); + /* Keep the API even with an empty stub in case we need it later */ } EXPORT_SYMBOL_GPL(nvmem_layout_unregister); =20 -static struct nvmem_layout *nvmem_layout_get(struct nvmem_device *nvmem) -{ - struct device_node *layout_np; - struct nvmem_layout *l, *layout =3D ERR_PTR(-EPROBE_DEFER); - - layout_np =3D of_nvmem_layout_get_container(nvmem); - if (!layout_np) - return NULL; - - /* Fixed layouts don't have a matching driver */ - if (of_device_is_compatible(layout_np, "fixed-layout")) { - of_node_put(layout_np); - return NULL; - } - - /* - * In case the nvmem device was built-in while the layout was built as a - * module, we shall manually request the layout driver loading otherwise - * we'll never have any match. - */ - of_request_module(layout_np); - - spin_lock(&nvmem_layout_lock); - - list_for_each_entry(l, &nvmem_layouts, node) { - if (of_match_node(l->of_match_table, layout_np)) { - if (try_module_get(l->owner)) - layout =3D l; - - break; - } - } - - spin_unlock(&nvmem_layout_lock); - of_node_put(layout_np); - - return layout; -} - -static void nvmem_layout_put(struct nvmem_layout *layout) -{ - if (layout) - module_put(layout->owner); -} - -static int nvmem_add_cells_from_layout(struct nvmem_device *nvmem) -{ - struct nvmem_layout *layout =3D nvmem->layout; - int ret; - - if (layout && layout->add_cells) { - ret =3D layout->add_cells(&nvmem->dev, nvmem); - if (ret) - return ret; - } - - return 0; -} - -#if IS_ENABLED(CONFIG_OF) -struct device_node *of_nvmem_layout_get_container(struct nvmem_device *nvm= em) -{ - return of_get_child_by_name(nvmem->dev.of_node, "nvmem-layout"); -} -EXPORT_SYMBOL_GPL(of_nvmem_layout_get_container); -#endif - const void *nvmem_layout_get_match_data(struct nvmem_device *nvmem, struct nvmem_layout *layout) { @@ -838,7 +760,7 @@ const void *nvmem_layout_get_match_data(struct nvmem_de= vice *nvmem, const struct of_device_id *match; =20 layout_np =3D of_nvmem_layout_get_container(nvmem); - match =3D of_match_node(layout->of_match_table, layout_np); + match =3D of_match_node(layout->dev.driver->of_match_table, layout_np); =20 return match ? match->data : NULL; } @@ -950,19 +872,6 @@ struct nvmem_device *nvmem_register(const struct nvmem= _config *config) goto err_put_device; } =20 - /* - * If the driver supplied a layout by config->layout, the module - * pointer will be NULL and nvmem_layout_put() will be a noop. - */ - nvmem->layout =3D config->layout ?: nvmem_layout_get(nvmem); - if (IS_ERR(nvmem->layout)) { - rval =3D PTR_ERR(nvmem->layout); - nvmem->layout =3D NULL; - - if (rval =3D=3D -EPROBE_DEFER) - goto err_teardown_compat; - } - if (config->cells) { rval =3D nvmem_add_cells(nvmem, config->cells, config->ncells); if (rval) @@ -983,24 +892,24 @@ struct nvmem_device *nvmem_register(const struct nvme= m_config *config) if (rval) goto err_remove_cells; =20 - rval =3D nvmem_add_cells_from_layout(nvmem); - if (rval) - goto err_remove_cells; - dev_dbg(&nvmem->dev, "Registering nvmem device %s\n", config->name); =20 rval =3D device_add(&nvmem->dev); if (rval) goto err_remove_cells; =20 + rval =3D nvmem_populate_layout(nvmem); + if (rval) + goto err_remove_dev; + blocking_notifier_call_chain(&nvmem_notifier, NVMEM_ADD, nvmem); =20 return nvmem; =20 +err_remove_dev: + device_del(&nvmem->dev); err_remove_cells: nvmem_device_remove_all_cells(nvmem); - nvmem_layout_put(nvmem->layout); -err_teardown_compat: if (config->compat) nvmem_sysfs_remove_compat(nvmem, config); err_put_device: @@ -1022,7 +931,7 @@ static void nvmem_device_release(struct kref *kref) device_remove_bin_file(nvmem->base_dev, &nvmem->eeprom); =20 nvmem_device_remove_all_cells(nvmem); - nvmem_layout_put(nvmem->layout); + nvmem_destroy_layout(nvmem); device_unregister(&nvmem->dev); } =20 @@ -1324,6 +1233,12 @@ nvmem_cell_get_from_lookup(struct device *dev, const= char *con_id) return cell; } =20 +static void nvmem_layout_module_put(struct nvmem_device *nvmem) +{ + if (nvmem->layout && nvmem->layout->dev.driver) + module_put(nvmem->layout->dev.driver->owner); +} + #if IS_ENABLED(CONFIG_OF) static struct nvmem_cell_entry * nvmem_find_cell_entry_by_node(struct nvmem_device *nvmem, struct device_no= de *np) @@ -1342,6 +1257,18 @@ nvmem_find_cell_entry_by_node(struct nvmem_device *n= vmem, struct device_node *np return cell; } =20 +static int nvmem_layout_module_get_optional(struct nvmem_device *nvmem) +{ + if (!nvmem->layout) + return 0; + + if (!nvmem->layout->dev.driver || + !try_module_get(nvmem->layout->dev.driver->owner)) + return -EPROBE_DEFER; + + return 0; +} + /** * of_nvmem_cell_get() - Get a nvmem cell from given device node and cell = id * @@ -1404,16 +1331,29 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_= node *np, const char *id) return ERR_CAST(nvmem); } =20 + ret =3D nvmem_layout_module_get_optional(nvmem); + if (ret) { + of_node_put(cell_np); + __nvmem_device_put(nvmem); + return ERR_PTR(ret); + } + cell_entry =3D nvmem_find_cell_entry_by_node(nvmem, cell_np); of_node_put(cell_np); if (!cell_entry) { __nvmem_device_put(nvmem); - return ERR_PTR(-ENOENT); + nvmem_layout_module_put(nvmem); + if (nvmem->layout) + return ERR_PTR(-EPROBE_DEFER); + else + return ERR_PTR(-ENOENT); } =20 cell =3D nvmem_create_cell(cell_entry, id, cell_index); - if (IS_ERR(cell)) + if (IS_ERR(cell)) { __nvmem_device_put(nvmem); + nvmem_layout_module_put(nvmem); + } =20 return cell; } @@ -1527,6 +1467,7 @@ void nvmem_cell_put(struct nvmem_cell *cell) =20 kfree(cell); __nvmem_device_put(nvmem); + nvmem_layout_module_put(nvmem); } EXPORT_SYMBOL_GPL(nvmem_cell_put); =20 @@ -2104,11 +2045,22 @@ EXPORT_SYMBOL_GPL(nvmem_dev_name); =20 static int __init nvmem_init(void) { - return bus_register(&nvmem_bus_type); + int ret; + + ret =3D bus_register(&nvmem_bus_type); + if (ret) + return ret; + + ret =3D nvmem_layout_bus_register(); + if (ret) + bus_unregister(&nvmem_bus_type); + + return ret; } =20 static void __exit nvmem_exit(void) { + nvmem_layout_bus_unregister(); bus_unregister(&nvmem_bus_type); } =20 diff --git a/drivers/nvmem/internals.h b/drivers/nvmem/internals.h index 893553fbdf51..4946456c76c7 100644 --- a/drivers/nvmem/internals.h +++ b/drivers/nvmem/internals.h @@ -34,4 +34,25 @@ struct nvmem_device { void *priv; }; =20 +#if IS_ENABLED(CONFIG_OF) +int nvmem_layout_bus_register(void); +void nvmem_layout_bus_unregister(void); +int nvmem_populate_layout(struct nvmem_device *nvmem); +void nvmem_destroy_layout(struct nvmem_device *nvmem); +#else /* CONFIG_OF */ +static inline int nvmem_layout_bus_register(void) +{ + return 0; +} + +static inline void nvmem_layout_bus_unregister(void) {} + +static inline int nvmem_populate_layout(struct nvmem_device *nvmem) +{ + return 0; +} + +static inline void nvmem_destroy_layout(struct nvmem_device *nvmem) { } +#endif /* CONFIG_OF */ + #endif /* ifndef _LINUX_NVMEM_INTERNALS_H */ diff --git a/drivers/nvmem/layouts.c b/drivers/nvmem/layouts.c new file mode 100644 index 000000000000..6a6aa58369ff --- /dev/null +++ b/drivers/nvmem/layouts.c @@ -0,0 +1,201 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * NVMEM layout bus handling + * + * Copyright (C) 2023 Bootlin + * Author: Miquel Raynal +#include +#include +#include +#include +#include +#include + +#include "internals.h" + +#define to_nvmem_layout_driver(drv) \ + (container_of((drv), struct nvmem_layout_driver, driver)) +#define to_nvmem_layout_device(_dev) \ + container_of((_dev), struct nvmem_layout, dev) + +static int nvmem_layout_bus_match(struct device *dev, struct device_driver= *drv) +{ + return of_driver_match_device(dev, drv); +} + +static int nvmem_layout_bus_probe(struct device *dev) +{ + struct nvmem_layout_driver *drv =3D to_nvmem_layout_driver(dev->driver); + struct nvmem_layout *layout =3D to_nvmem_layout_device(dev); + + if (!drv->probe || !drv->remove) + return -EINVAL; + + return drv->probe(layout); +} + +static void nvmem_layout_bus_remove(struct device *dev) +{ + struct nvmem_layout_driver *drv =3D to_nvmem_layout_driver(dev->driver); + struct nvmem_layout *layout =3D to_nvmem_layout_device(dev); + + return drv->remove(layout); +} + +static struct bus_type nvmem_layout_bus_type =3D { + .name =3D "nvmem-layout", + .match =3D nvmem_layout_bus_match, + .probe =3D nvmem_layout_bus_probe, + .remove =3D nvmem_layout_bus_remove, +}; + +int nvmem_layout_driver_register(struct nvmem_layout_driver *drv) +{ + drv->driver.bus =3D &nvmem_layout_bus_type; + + return driver_register(&drv->driver); +} +EXPORT_SYMBOL_GPL(nvmem_layout_driver_register); + +void nvmem_layout_driver_unregister(struct nvmem_layout_driver *drv) +{ + driver_unregister(&drv->driver); +} +EXPORT_SYMBOL_GPL(nvmem_layout_driver_unregister); + +static void nvmem_layout_release_device(struct device *dev) +{ + struct nvmem_layout *layout =3D to_nvmem_layout_device(dev); + + of_node_put(layout->dev.of_node); + kfree(layout); +} + +static int nvmem_layout_create_device(struct nvmem_device *nvmem, + struct device_node *np) +{ + struct nvmem_layout *layout; + struct device *dev; + int ret; + + layout =3D kzalloc(sizeof(*layout), GFP_KERNEL); + if (!layout) + return -ENOMEM; + + /* Create a bidirectional link */ + layout->nvmem =3D nvmem; + nvmem->layout =3D layout; + + /* Device model registration */ + dev =3D &layout->dev; + device_initialize(dev); + dev->parent =3D &nvmem->dev; + dev->bus =3D &nvmem_layout_bus_type; + dev->release =3D nvmem_layout_release_device; + dev->coherent_dma_mask =3D DMA_BIT_MASK(32); + dev->dma_mask =3D &dev->coherent_dma_mask; + device_set_node(dev, of_fwnode_handle(of_node_get(np))); + of_device_make_bus_id(dev); + of_msi_configure(dev, dev->of_node); + + ret =3D device_add(dev); + if (ret) { + put_device(dev); + return ret; + } + + return 0; +} + +static const struct of_device_id of_nvmem_layout_skip_table[] =3D { + { .compatible =3D "fixed-layout", }, + {} +}; + +static int nvmem_layout_bus_populate(struct nvmem_device *nvmem, + struct device_node *layout_dn) +{ + int ret; + + /* Make sure it has a compatible property */ + if (!of_get_property(layout_dn, "compatible", NULL)) { + pr_debug("%s() - skipping %pOF, no compatible prop\n", + __func__, layout_dn); + return 0; + } + + /* Fixed layouts are parsed manually somewhere else for now */ + if (of_match_node(of_nvmem_layout_skip_table, layout_dn)) { + pr_debug("%s() - skipping %pOF node\n", __func__, layout_dn); + return 0; + } + + if (of_node_check_flag(layout_dn, OF_POPULATED_BUS)) { + pr_debug("%s() - skipping %pOF, already populated\n", + __func__, layout_dn); + + return 0; + } + + /* NVMEM layout buses expect only a single device representing the layout= */ + ret =3D nvmem_layout_create_device(nvmem, layout_dn); + if (ret) + return ret; + + of_node_set_flag(layout_dn, OF_POPULATED_BUS); + + return 0; +} + +struct device_node *of_nvmem_layout_get_container(struct nvmem_device *nvm= em) +{ + return of_get_child_by_name(nvmem->dev.of_node, "nvmem-layout"); +} +EXPORT_SYMBOL_GPL(of_nvmem_layout_get_container); + +/* + * Returns the number of devices populated, 0 if the operation was not rel= evant + * for this nvmem device, an error code otherwise. + */ +int nvmem_populate_layout(struct nvmem_device *nvmem) +{ + struct device_node *layout_dn; + int ret; + + layout_dn =3D of_nvmem_layout_get_container(nvmem); + if (!layout_dn) + return 0; + + /* Populate the layout device */ + device_links_supplier_sync_state_pause(); + ret =3D nvmem_layout_bus_populate(nvmem, layout_dn); + device_links_supplier_sync_state_resume(); + + of_node_put(layout_dn); + return ret; +} + +void nvmem_destroy_layout(struct nvmem_device *nvmem) +{ + struct device *dev; + + if (!nvmem->layout) + return; + + dev =3D &nvmem->layout->dev; + of_node_clear_flag(dev->of_node, OF_POPULATED_BUS); + device_unregister(dev); +} + +int nvmem_layout_bus_register(void) +{ + return bus_register(&nvmem_layout_bus_type); +} + +void nvmem_layout_bus_unregister(void) +{ + bus_unregister(&nvmem_layout_bus_type); +} diff --git a/drivers/nvmem/layouts/Kconfig b/drivers/nvmem/layouts/Kconfig index 7ff1ee1c1f05..9c6e672fc350 100644 --- a/drivers/nvmem/layouts/Kconfig +++ b/drivers/nvmem/layouts/Kconfig @@ -1,5 +1,11 @@ # SPDX-License-Identifier: GPL-2.0 =20 +config NVMEM_LAYOUTS + bool + depends on OF + +if NVMEM_LAYOUTS + menu "Layout Types" =20 config NVMEM_LAYOUT_SL28_VPD @@ -21,3 +27,5 @@ config NVMEM_LAYOUT_ONIE_TLV If unsure, say N. =20 endmenu + +endif diff --git a/drivers/nvmem/layouts/onie-tlv.c b/drivers/nvmem/layouts/onie-= tlv.c index defd42d4375c..b24cc5dcc6ee 100644 --- a/drivers/nvmem/layouts/onie-tlv.c +++ b/drivers/nvmem/layouts/onie-tlv.c @@ -225,16 +225,32 @@ static int onie_tlv_parse_table(struct device *dev, s= truct nvmem_device *nvmem) return 0; } =20 +static int onie_tlv_probe(struct nvmem_layout *layout) +{ + layout->add_cells =3D onie_tlv_parse_table; + + return nvmem_layout_register(layout); +} + +static void onie_tlv_remove(struct nvmem_layout *layout) +{ + nvmem_layout_unregister(layout); +} + static const struct of_device_id onie_tlv_of_match_table[] =3D { { .compatible =3D "onie,tlv-layout", }, {}, }; MODULE_DEVICE_TABLE(of, onie_tlv_of_match_table); =20 -static struct nvmem_layout onie_tlv_layout =3D { - .name =3D "ONIE tlv layout", - .of_match_table =3D onie_tlv_of_match_table, - .add_cells =3D onie_tlv_parse_table, +static struct nvmem_layout_driver onie_tlv_layout =3D { + .driver =3D { + .owner =3D THIS_MODULE, + .name =3D "onie-tlv-layout", + .of_match_table =3D onie_tlv_of_match_table, + }, + .probe =3D onie_tlv_probe, + .remove =3D onie_tlv_remove, }; module_nvmem_layout_driver(onie_tlv_layout); =20 diff --git a/drivers/nvmem/layouts/sl28vpd.c b/drivers/nvmem/layouts/sl28vp= d.c index 26c7cf21b523..b8ffae646cc2 100644 --- a/drivers/nvmem/layouts/sl28vpd.c +++ b/drivers/nvmem/layouts/sl28vpd.c @@ -134,16 +134,32 @@ static int sl28vpd_add_cells(struct device *dev, stru= ct nvmem_device *nvmem) return 0; } =20 +static int sl28vpd_probe(struct nvmem_layout *layout) +{ + layout->add_cells =3D sl28vpd_add_cells; + + return nvmem_layout_register(layout); +} + +static void sl28vpd_remove(struct nvmem_layout *layout) +{ + nvmem_layout_unregister(layout); +} + static const struct of_device_id sl28vpd_of_match_table[] =3D { { .compatible =3D "kontron,sl28-vpd" }, {}, }; MODULE_DEVICE_TABLE(of, sl28vpd_of_match_table); =20 -static struct nvmem_layout sl28vpd_layout =3D { - .name =3D "sl28-vpd", - .of_match_table =3D sl28vpd_of_match_table, - .add_cells =3D sl28vpd_add_cells, +static struct nvmem_layout_driver sl28vpd_layout =3D { + .driver =3D { + .owner =3D THIS_MODULE, + .name =3D "kontron-sl28vpd-layout", + .of_match_table =3D sl28vpd_of_match_table, + }, + .probe =3D sl28vpd_probe, + .remove =3D sl28vpd_remove, }; module_nvmem_layout_driver(sl28vpd_layout); =20 diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index 36415a602d9e..6fe65b35ea97 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -9,6 +9,7 @@ #ifndef _LINUX_NVMEM_PROVIDER_H #define _LINUX_NVMEM_PROVIDER_H =20 +#include #include #include #include @@ -158,12 +159,11 @@ struct nvmem_cell_table { /** * struct nvmem_layout - NVMEM layout definitions * - * @name: Layout name. - * @of_match_table: Open firmware match table. - * @add_cells: Called to populate the layout using - * nvmem_add_one_cell(). - * @owner: Pointer to struct module. - * @node: List node. + * @dev: Device-model layout device. + * @nvmem: The underlying NVMEM device + * @add_cells: Will be called if a nvmem device is found which + * has this layout. The function will add layout + * specific cells with nvmem_add_one_cell(). * * A nvmem device can hold a well defined structure which can just be * evaluated during runtime. For example a TLV list, or a list of "name=3D= val" @@ -171,13 +171,15 @@ struct nvmem_cell_table { * cells. */ struct nvmem_layout { - const char *name; - const struct of_device_id *of_match_table; + struct device dev; + struct nvmem_device *nvmem; int (*add_cells)(struct device *dev, struct nvmem_device *nvmem); +}; =20 - /* private */ - struct module *owner; - struct list_head node; +struct nvmem_layout_driver { + struct device_driver driver; + int (*probe)(struct nvmem_layout *layout); + void (*remove)(struct nvmem_layout *layout); }; =20 #if IS_ENABLED(CONFIG_NVMEM) @@ -194,11 +196,15 @@ void nvmem_del_cell_table(struct nvmem_cell_table *ta= ble); int nvmem_add_one_cell(struct nvmem_device *nvmem, const struct nvmem_cell_info *info); =20 -int __nvmem_layout_register(struct nvmem_layout *layout, struct module *ow= ner); -#define nvmem_layout_register(layout) \ - __nvmem_layout_register(layout, THIS_MODULE) +int nvmem_layout_register(struct nvmem_layout *layout); void nvmem_layout_unregister(struct nvmem_layout *layout); =20 +int nvmem_layout_driver_register(struct nvmem_layout_driver *drv); +void nvmem_layout_driver_unregister(struct nvmem_layout_driver *drv); +#define module_nvmem_layout_driver(__nvmem_layout_driver) \ + module_driver(__nvmem_layout_driver, nvmem_layout_driver_register, \ + nvmem_layout_driver_unregister) + const void *nvmem_layout_get_match_data(struct nvmem_device *nvmem, struct nvmem_layout *layout); =20 @@ -262,8 +268,4 @@ static inline struct device_node *of_nvmem_layout_get_c= ontainer(struct nvmem_dev =20 #endif /* CONFIG_NVMEM && CONFIG_OF */ =20 -#define module_nvmem_layout_driver(__layout_driver) \ - module_driver(__layout_driver, nvmem_layout_register, \ - nvmem_layout_unregister) - #endif /* ifndef _LINUX_NVMEM_PROVIDER_H */ --=20 2.25.1 From nobody Fri Dec 19 00:21:39 2025 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 52C072C691 for ; Fri, 15 Dec 2023 11:15:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="ybQP8bvN" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-33638e7f71aso268181f8f.1 for ; Fri, 15 Dec 2023 03:15:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1702638952; x=1703243752; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=E+ooKEqmsF7QvtbpeG1r1pA2WmE89GFiP0WEgLh36AY=; b=ybQP8bvN29AWzEJO0TrF5/Nsva+piSZZrCfBTa6liAUPisaYe0JGDAm7W/qSTRqw3F 4iaCK62Y5tpEKH0ka9goIbC4l8E05h2O9JfhBZb+55RkknJRCehD87gYSN5gOeO/6mo+ zgKUwaGUQqUC/8NloLH9rA227lb7pekSz3LwHzOFd20FWWV6e5hyUhDsuhab1IzgA8uM HpsM/AXb1bz/ptqFTK/Pg8CE2psV88U8hOwY704FGZF1XXFvZji1e4lSphmMbkDfQE/d /8DzRbhpcZ4sOZB7gaonJn106GF1+Uv4KgbkIoyt/bw7LcpA+ALr6gza3Gbetv/XuSbR EtJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702638952; x=1703243752; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=E+ooKEqmsF7QvtbpeG1r1pA2WmE89GFiP0WEgLh36AY=; b=wnkrir86GFy3EFaJ9mEMFR7zMvqM7e7fh1Y5MFYpNOtv3LDoYuFQ0xSeDkRdktGDj+ ktzeFCkjigwJFG8hQHjSKahOKbGUnZTcdkNviPy7yU/J60kO3RTbj3qGEysGmVmsAF5I 6NrgZYi3c0cwZqlkaUhzz+uYZBkIV1fTq9/gZD6YCLao8HdDVStiGbt14WXGUArhgNk3 1lNpJE6ebF8LobB39BAzHhfUD0G0LJwz7Mry/VP2AbHJuNeBUu0f5Edj8Qbmj6+qg+RB UmR5xpn2Z+Qk+/EhizNtof63eIcG+EjyvQh7YTY7EY8CZ9VB9dcVOnCMtgFsDgxUI7YW hmRA== X-Gm-Message-State: AOJu0YyZtKYjKxse7VMnf6Wqu+dwCtY8uIcOSeN1HtD1e6GUTKTXsprl 6SpvXY+bnlwUWQGEupBNcHQXIFCOSu5eEg4mFMg= X-Google-Smtp-Source: AGHT+IGz1rv62aik6ABY9CfctpgNJd229+a0US4HYze0O5k6sTCpndWCcrZ/P+HXsLlki6N6RPh9zA== X-Received: by 2002:a5d:6ac2:0:b0:333:38eb:8949 with SMTP id u2-20020a5d6ac2000000b0033338eb8949mr5985493wrw.25.1702638952500; Fri, 15 Dec 2023 03:15:52 -0800 (PST) Received: from localhost.localdomain ([5.133.47.210]) by smtp.gmail.com with ESMTPSA id g13-20020a056000118d00b003333d46a9e8sm18511497wrx.56.2023.12.15.03.15.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 03:15:52 -0800 (PST) From: srinivas.kandagatla@linaro.org To: gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, Miquel Raynal , Srinivas Kandagatla Subject: [PATCH 07/10] ABI: sysfs-nvmem-cells: Expose cells through sysfs Date: Fri, 15 Dec 2023 11:15:33 +0000 Message-Id: <20231215111536.316972-8-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231215111536.316972-1-srinivas.kandagatla@linaro.org> References: <20231215111536.316972-1-srinivas.kandagatla@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2442; i=srinivas.kandagatla@linaro.org; h=from:subject; bh=rDw2aRqd4VB4KQrERUdheIoqHQ7dZxBi1jfzVJE5aW0=; b=owEBbQGS/pANAwAKAXqh/VnHNFU3AcsmYgBlfDVYlpIsMnIDm7GHut/qUakpchD85wEJ03JP8 hLvUbzLP1eJATMEAAEKAB0WIQQi509axvzi9vce3Y16of1ZxzRVNwUCZXw1WAAKCRB6of1ZxzRV N279CACRaGwuqabts3hC8cLlJ9C+ljtD6Usa4/RGBkwhV5+yE4PP0TZfa2+EfOsxDFQ3Io5UK8B /WlfduyfDSb2fwIgNU0udTpy7a1wSvq0o0rmRVrK4ujU77+aOzPwy8coo/S4ykYkiUIISYrIq+z KGtH0MW9ym9uQeTxxxuDcnjcwkJmBoGXXJTDTpA1KwfYcVWAA1FZCh9qG7NXZ9WCuo8DgmI4/b3 FDfudF10K5GA31KPPJLG6BheyKENdeVE5pC1D696OyhVuiSXF1RScSdJAHGSXyt4wsNFUVXjVqE 8moMwpZ6pvQAU5aiB79J3iK5zcSVX4U5rW4LXqXKrgrthc3U X-Developer-Key: i=srinivas.kandagatla@linaro.org; a=openpgp; fpr=ED6472765AB36EC43B3EF97AD77E3FC0562560D6 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Miquel Raynal The binary content of nvmem devices is available to the user so in the easiest cases, finding the content of a cell is rather easy as it is just a matter of looking at a known and fixed offset. However, nvmem layouts have been recently introduced to cope with more advanced situations, where the offset and size of the cells is not known in advance or is dynamic. When using layouts, more advanced parsers are used by the kernel in order to give direct access to the content of each cell regardless of their position/size in the underlying device, but these information were not accessible to the user. By exposing the nvmem cells to the user through a dedicated cell/ folder containing one file per cell, we provide a straightforward access to useful user information without the need for re-writing a userland parser. Content of nvmem cells is usually: product names, manufacturing date, MAC addresses, etc, Signed-off-by: Miquel Raynal Reviewed-by: Greg Kroah-Hartman Signed-off-by: Srinivas Kandagatla --- Documentation/ABI/testing/sysfs-nvmem-cells | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-nvmem-cells diff --git a/Documentation/ABI/testing/sysfs-nvmem-cells b/Documentation/AB= I/testing/sysfs-nvmem-cells new file mode 100644 index 000000000000..7af70adf3690 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-nvmem-cells @@ -0,0 +1,21 @@ +What: /sys/bus/nvmem/devices/.../cells/ +Date: May 2023 +KernelVersion: 6.5 +Contact: Miquel Raynal +Description: + The "cells" folder contains one file per cell exposed by the + NVMEM device. The name of the file is: @, with + being the cell name and its location in the NVMEM + device, in hexadecimal (without the '0x' prefix, to mimic device + tree node names). The length of the file is the size of the cell + (when known). The content of the file is the binary content of + the cell (may sometimes be ASCII, likely without trailing + character). + Note: This file is only present if CONFIG_NVMEM_SYSFS + is enabled. + + Example:: + + hexdump -C /sys/bus/nvmem/devices/1-00563/cells/product-name@d + 00000000 54 4e 34 38 4d 2d 50 2d 44 4e |TN48M-P-DN| + 0000000a --=20 2.25.1 From nobody Fri Dec 19 00:21:39 2025 Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5FFD02D7AF for ; Fri, 15 Dec 2023 11:15:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="nSjxN4sf" Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-50bfa7f7093so595325e87.0 for ; Fri, 15 Dec 2023 03:15:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1702638954; x=1703243754; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LGq6oPhsUVdTqLZzaZ7S1PrPM+s1Pa6z7b1UfXTkK90=; b=nSjxN4sfn+nnxIexIqM3DXjXcNGNerTSz1L++TDvqt6gv5h5OT+IXJjXFiEy3xVcKG BRsx99I/GAWgf2FvTu9UW5x9PUA1ozz5C4ovx651G6F6RUYbD1+2zYKdgOE8cNZXaBj/ weeDt9hM9yGZT3AiEcfr5CDQRaC4ZR0Q8Rz+FTji8vFP8y5nsEhsMqW8cmVruq5ckeih 7rJYQlfpaPsNfAv1axSJM3zVbVSQhU9ifo8DfJr5dGOihMYWYuQ5I1I7JDBCQ5PP5XXi kIXAScLsBpWWFYpR47fW0Hrry4nTBiGGZRmu6y22rQUjm3W4yigrykbQ9W/vw6OM639x 4yFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702638954; x=1703243754; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LGq6oPhsUVdTqLZzaZ7S1PrPM+s1Pa6z7b1UfXTkK90=; b=F3xegViPVb4rXl8UsawgYwez7x5xymLuq9YA1aoIunSudcFYlMmibLQYyd6kfNmn8x JctxC/6hcBHWgs23c20Q9270dKXDd0XMEGWA9lnJWE51+qWQteXghPBw7MCqwkaiFIyi b3FBGVwo49F6pXDtjvdQlkFSsquO1b/WzvB7LhnbCvzb/P5vKR6GAXDk8IohHBGaqeZ1 M2uZAWX1Jg8XgAAHdxEGdppvZER83W6ZyCVccazo/fbP6+WFtpAff8sVvWOF6SJnkCWt 5vcS1qywnLwNWmYavdYTRd1FJgRzI/hRbqLUNA6e6pKHMzaNTMjvzP7JZT9W8BmP1Nzf +A7w== X-Gm-Message-State: AOJu0YzGKZg656qu0azq3bcgYInenB3jex5qGLDrloMAqdgX91MAwNFt 6ZrLC97K3YrdVqyq+ltu9HXw2A== X-Google-Smtp-Source: AGHT+IHJNyhfre9Ub5s9kt/QZ8VLj3RUMseHeajGQRiN/+J9AdgpX9JKxHmR9vKdVijcRmM5HFGBBg== X-Received: by 2002:a05:6512:1294:b0:50e:1393:c0e2 with SMTP id u20-20020a056512129400b0050e1393c0e2mr2903488lfs.103.1702638954390; Fri, 15 Dec 2023 03:15:54 -0800 (PST) Received: from localhost.localdomain ([5.133.47.210]) by smtp.gmail.com with ESMTPSA id g13-20020a056000118d00b003333d46a9e8sm18511497wrx.56.2023.12.15.03.15.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 03:15:52 -0800 (PST) From: srinivas.kandagatla@linaro.org To: gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, Miquel Raynal , =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= , Chen-Yu Tsai , Srinivas Kandagatla Subject: [PATCH 08/10] nvmem: core: Expose cells through sysfs Date: Fri, 15 Dec 2023 11:15:34 +0000 Message-Id: <20231215111536.316972-9-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231215111536.316972-1-srinivas.kandagatla@linaro.org> References: <20231215111536.316972-1-srinivas.kandagatla@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Developer-Signature: v=1; a=openpgp-sha256; l=7200; i=srinivas.kandagatla@linaro.org; h=from:subject; bh=wFPl5M4upZFBWsXan//pUuNPPb+WjnuRh9SgwcAYUGs=; b=owEBbQGS/pANAwAKAXqh/VnHNFU3AcsmYgBlfDVYrl0n9Azrn6XrOdQtTAkulRaZNZRWlb8AB 1VasyA+7ICJATMEAAEKAB0WIQQi509axvzi9vce3Y16of1ZxzRVNwUCZXw1WAAKCRB6of1ZxzRV N7pjCAC2ETBT3/zy/Z8mUX+CsRQTdjJ+QdhqHM+GwBL2VHUMc1Td4uyvwN1LBFWxNuo5h5DP9EL NPZs4CcQQ56I/4Qh18RspwlhfLRVrT5BAeOHKB1mkUdUr6MRxLJVPEdyr9mDXISfJ9YGLmdnzbA zrTldma50xfHMTj2tvwbNuxqYkBktP9NHCEebY7QHEhrt6bhnfWCHPRmT8872z8M/xY2iGbQ87M xE2kg/uH4GbQM6omL2o+Uthp7/Xs0xRqyf0cExP+/MEJUG3GL0W8k/w/7SUD29I7Eokbk80K8Ut IEx1Rn7jwrBPZxzIonFzsCxAJDZjxuI9AJeI09nZll8gL2R9 X-Developer-Key: i=srinivas.kandagatla@linaro.org; a=openpgp; fpr=ED6472765AB36EC43B3EF97AD77E3FC0562560D6 Content-Transfer-Encoding: quoted-printable From: Miquel Raynal The binary content of nvmem devices is available to the user so in the easiest cases, finding the content of a cell is rather easy as it is just a matter of looking at a known and fixed offset. However, nvmem layouts have been recently introduced to cope with more advanced situations, where the offset and size of the cells is not known in advance or is dynamic. When using layouts, more advanced parsers are used by the kernel in order to give direct access to the content of each cell, regardless of its position/size in the underlying device. Unfortunately, these information are not accessible by users, unless by fully re-implementing the parser logic in userland. Let's expose the cells and their content through sysfs to avoid these situations. Of course the relevant NVMEM sysfs Kconfig option must be enabled for this support to be available. Not all nvmem devices expose cells. Indeed, the .bin_attrs attribute group member will be filled at runtime only when relevant and will remain empty otherwise. In this case, as the cells attribute group will be empty, it will not lead to any additional folder/file creation. Exposed cells are read-only. There is, in practice, everything in the core to support a write path, but as I don't see any need for that, I prefer to keep the interface simple (and probably safer). The interface is documented as being in the "testing" state which means we can later add a write attribute if though relevant. Signed-off-by: Miquel Raynal Tested-by: Rafa=C5=82 Mi=C5=82ecki Tested-by: Chen-Yu Tsai Signed-off-by: Srinivas Kandagatla --- drivers/nvmem/core.c | 135 +++++++++++++++++++++++++++++++++++++- drivers/nvmem/internals.h | 1 + 2 files changed, 135 insertions(+), 1 deletion(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 4c2154ddf8a7..ba559e81f77f 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -299,6 +299,43 @@ static umode_t nvmem_bin_attr_is_visible(struct kobjec= t *kobj, return nvmem_bin_attr_get_umode(nvmem); } =20 +static struct nvmem_cell *nvmem_create_cell(struct nvmem_cell_entry *entry, + const char *id, int index); + +static ssize_t nvmem_cell_attr_read(struct file *filp, struct kobject *kob= j, + struct bin_attribute *attr, char *buf, + loff_t pos, size_t count) +{ + struct nvmem_cell_entry *entry; + struct nvmem_cell *cell =3D NULL; + size_t cell_sz, read_len; + void *content; + + entry =3D attr->private; + cell =3D nvmem_create_cell(entry, entry->name, 0); + if (IS_ERR(cell)) + return PTR_ERR(cell); + + if (!cell) + return -EINVAL; + + content =3D nvmem_cell_read(cell, &cell_sz); + if (IS_ERR(content)) { + read_len =3D PTR_ERR(content); + goto destroy_cell; + } + + read_len =3D min_t(unsigned int, cell_sz - pos, count); + memcpy(buf, content + pos, read_len); + kfree(content); + +destroy_cell: + kfree_const(cell->id); + kfree(cell); + + return read_len; +} + /* default read/write permissions */ static struct bin_attribute bin_attr_rw_nvmem =3D { .attr =3D { @@ -320,11 +357,21 @@ static const struct attribute_group nvmem_bin_group = =3D { .is_bin_visible =3D nvmem_bin_attr_is_visible, }; =20 +/* Cell attributes will be dynamically allocated */ +static struct attribute_group nvmem_cells_group =3D { + .name =3D "cells", +}; + static const struct attribute_group *nvmem_dev_groups[] =3D { &nvmem_bin_group, NULL, }; =20 +static const struct attribute_group *nvmem_cells_groups[] =3D { + &nvmem_cells_group, + NULL, +}; + static struct bin_attribute bin_attr_nvmem_eeprom_compat =3D { .attr =3D { .name =3D "eeprom", @@ -380,6 +427,68 @@ static void nvmem_sysfs_remove_compat(struct nvmem_dev= ice *nvmem, device_remove_bin_file(nvmem->base_dev, &nvmem->eeprom); } =20 +static int nvmem_populate_sysfs_cells(struct nvmem_device *nvmem) +{ + struct bin_attribute **cells_attrs, *attrs; + struct nvmem_cell_entry *entry; + unsigned int ncells =3D 0, i =3D 0; + int ret =3D 0; + + mutex_lock(&nvmem_mutex); + + if (list_empty(&nvmem->cells) || nvmem->sysfs_cells_populated) { + nvmem_cells_group.bin_attrs =3D NULL; + goto unlock_mutex; + } + + /* Allocate an array of attributes with a sentinel */ + ncells =3D list_count_nodes(&nvmem->cells); + cells_attrs =3D devm_kcalloc(&nvmem->dev, ncells + 1, + sizeof(struct bin_attribute *), GFP_KERNEL); + if (!cells_attrs) { + ret =3D -ENOMEM; + goto unlock_mutex; + } + + attrs =3D devm_kcalloc(&nvmem->dev, ncells, sizeof(struct bin_attribute),= GFP_KERNEL); + if (!attrs) { + ret =3D -ENOMEM; + goto unlock_mutex; + } + + /* Initialize each attribute to take the name and size of the cell */ + list_for_each_entry(entry, &nvmem->cells, node) { + sysfs_bin_attr_init(&attrs[i]); + attrs[i].attr.name =3D devm_kasprintf(&nvmem->dev, GFP_KERNEL, + "%s@%x", entry->name, + entry->offset); + attrs[i].attr.mode =3D 0444; + attrs[i].size =3D entry->bytes; + attrs[i].read =3D &nvmem_cell_attr_read; + attrs[i].private =3D entry; + if (!attrs[i].attr.name) { + ret =3D -ENOMEM; + goto unlock_mutex; + } + + cells_attrs[i] =3D &attrs[i]; + i++; + } + + nvmem_cells_group.bin_attrs =3D cells_attrs; + + ret =3D devm_device_add_groups(&nvmem->dev, nvmem_cells_groups); + if (ret) + goto unlock_mutex; + + nvmem->sysfs_cells_populated =3D true; + +unlock_mutex: + mutex_unlock(&nvmem_mutex); + + return ret; +} + #else /* CONFIG_NVMEM_SYSFS */ =20 static int nvmem_sysfs_setup_compat(struct nvmem_device *nvmem, @@ -739,11 +848,25 @@ static int nvmem_add_cells_from_fixed_layout(struct n= vmem_device *nvmem) =20 int nvmem_layout_register(struct nvmem_layout *layout) { + int ret; + if (!layout->add_cells) return -EINVAL; =20 /* Populate the cells */ - return layout->add_cells(&layout->nvmem->dev, layout->nvmem); + ret =3D layout->add_cells(&layout->nvmem->dev, layout->nvmem); + if (ret) + return ret; + +#ifdef CONFIG_NVMEM_SYSFS + ret =3D nvmem_populate_sysfs_cells(layout->nvmem); + if (ret) { + nvmem_device_remove_all_cells(layout->nvmem); + return ret; + } +#endif + + return 0; } EXPORT_SYMBOL_GPL(nvmem_layout_register); =20 @@ -902,10 +1025,20 @@ struct nvmem_device *nvmem_register(const struct nvm= em_config *config) if (rval) goto err_remove_dev; =20 +#ifdef CONFIG_NVMEM_SYSFS + rval =3D nvmem_populate_sysfs_cells(nvmem); + if (rval) + goto err_destroy_layout; +#endif + blocking_notifier_call_chain(&nvmem_notifier, NVMEM_ADD, nvmem); =20 return nvmem; =20 +#ifdef CONFIG_NVMEM_SYSFS +err_destroy_layout: + nvmem_destroy_layout(nvmem); +#endif err_remove_dev: device_del(&nvmem->dev); err_remove_cells: diff --git a/drivers/nvmem/internals.h b/drivers/nvmem/internals.h index 4946456c76c7..18fed57270e5 100644 --- a/drivers/nvmem/internals.h +++ b/drivers/nvmem/internals.h @@ -32,6 +32,7 @@ struct nvmem_device { struct gpio_desc *wp_gpio; struct nvmem_layout *layout; void *priv; + bool sysfs_cells_populated; }; =20 #if IS_ENABLED(CONFIG_OF) --=20 2.25.1 From nobody Fri Dec 19 00:21:39 2025 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 942AC2C6A9 for ; Fri, 15 Dec 2023 11:15:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="cxyGxn9b" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-3360ae2392eso377311f8f.2 for ; Fri, 15 Dec 2023 03:15:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1702638956; x=1703243756; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wj6vTmlRSd1bu8+W9TkZBmaTAnAxkW+/q7AbzNoNfA0=; b=cxyGxn9bm8dIS3ozXtUZTyrGNpqbCZkWlhFDEmqAjugAa3Q3BacwRCYRLfkTsdlWmG Tz7EzpifCioAqQqEWuStKijgTec1X85WAgi2Igccwco3nux1Znk3iCL9HmVGDD10hZP0 7jXwgEgAmlUJ8O1S8E+9KXFhXICm7bUjwWL8zUCOUcSWyTgrAU9eedBGRpHH/l54V4dl n9kpZ3IsqzzEWijFhNFVn1MPvCdQQT8Qi9+0Wuad/Nq5hls+z9zIFJqK2GAwneKZLeiA 9bCmhrNtVQm4JqIRMiADw3moiHtUq/eura0Bvk5hM+CnOHsZENHe+rSVf2GnJw44Exd+ ZhAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702638956; x=1703243756; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wj6vTmlRSd1bu8+W9TkZBmaTAnAxkW+/q7AbzNoNfA0=; b=XJ6pmwY0ymm/c21lkrxVCOQ0F/Zgwmq2ky97YYNzJcKuaJxrCKwr2w9H4sfnz62gXm EgDjK1O7DsHnvRa/YKCiIHgTwkWcaal80fRTpXuz7CiEb7yX5kC6firRVPCxLbaA16YK yvNgLD463hP/PKnWwF5M1lWcM7s9mPOuzOMYECL5KxnEQEMNxqmkpMCMSB5jgfwdkt3c 0IQwxsX58jCtFnVraBLHfapTyMooib0Ny1KWttmCtxxLJqB6ztH1I+erA6CAWZ5dl5Lx km58GoztgxVIXgCHq4fzI+F31dZEt+VVnG4YWw6//M9fspsR49v9Cw9JCH/ZFXCk4X2w ZMlQ== X-Gm-Message-State: AOJu0YyHagEPJfK3NiBHm9iNVDkd0i5J2Z7V1x4LeK+lZczDwdfB2lam Ft4t7ynimTgIJlVJxa19YFFn3A== X-Google-Smtp-Source: AGHT+IHka+ZRTmAvdw2RUKECCNVsM86VMh14Z2k+zoWvpI2YMUk++gbe6RFNRCCOFsPLwxCbXybJvQ== X-Received: by 2002:a05:6000:147:b0:333:38bb:f8bc with SMTP id r7-20020a056000014700b0033338bbf8bcmr5884686wrx.102.1702638955879; Fri, 15 Dec 2023 03:15:55 -0800 (PST) Received: from localhost.localdomain ([5.133.47.210]) by smtp.gmail.com with ESMTPSA id g13-20020a056000118d00b003333d46a9e8sm18511497wrx.56.2023.12.15.03.15.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 03:15:54 -0800 (PST) From: srinivas.kandagatla@linaro.org To: gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, Patrick Delaunay , Conor Dooley , Srinivas Kandagatla Subject: [PATCH 09/10] dt-bindings: nvmem: add new stm32mp25 compatible for stm32-romem Date: Fri, 15 Dec 2023 11:15:35 +0000 Message-Id: <20231215111536.316972-10-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231215111536.316972-1-srinivas.kandagatla@linaro.org> References: <20231215111536.316972-1-srinivas.kandagatla@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=835; i=srinivas.kandagatla@linaro.org; h=from:subject; bh=uFrn3U3yuiQtXighYC3u5r+C5PUPeLGELEDLZIYljOg=; b=owEBbQGS/pANAwAKAXqh/VnHNFU3AcsmYgBlfDVYDLx9/HVM7ZtbN6hbLYzrrMgdVZXw67uHK BjRvp4c0OmJATMEAAEKAB0WIQQi509axvzi9vce3Y16of1ZxzRVNwUCZXw1WAAKCRB6of1ZxzRV N9N4CACOa471I/UZVFYooW+x2TUmGjdN4GFFlg2kWlHgriCC+GbriAX/PqQ3JjZQ2wlJxwngoZT mdhri2sxg7D4UmLFxhAwolvJz0wC4Pty9DyQDo4ceekju8djqZLMuN59H0FDdaP7Lz1ltNOWDSh EUaXsEisVCKI53qA/MFTJZh0r3AViZmY9avxtyqAZRfNpmf86tdrtc6kHMbGYeIHW6zUxcHW+v9 IMfPG1hTAICG4GDpRR3uC3Wnq/W1C5RBNEO/K3GO59C09gXlpDtOnZUIrDruBy+gXboco1ECIEf +wIktzKEv6LAHEtaR/XiyoV1caYw9wpCbCB8MKG6tjJTMvnN X-Developer-Key: i=srinivas.kandagatla@linaro.org; a=openpgp; fpr=ED6472765AB36EC43B3EF97AD77E3FC0562560D6 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Patrick Delaunay Add a new compatible for stm32mp25 support. Signed-off-by: Patrick Delaunay Acked-by: Conor Dooley Signed-off-by: Srinivas Kandagatla --- Documentation/devicetree/bindings/nvmem/st,stm32-romem.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/nvmem/st,stm32-romem.yaml b/= Documentation/devicetree/bindings/nvmem/st,stm32-romem.yaml index a69de3e92282..92bfe25f0571 100644 --- a/Documentation/devicetree/bindings/nvmem/st,stm32-romem.yaml +++ b/Documentation/devicetree/bindings/nvmem/st,stm32-romem.yaml @@ -24,6 +24,7 @@ properties: - st,stm32f4-otp - st,stm32mp13-bsec - st,stm32mp15-bsec + - st,stm32mp25-bsec =20 reg: maxItems: 1 --=20 2.25.1 From nobody Fri Dec 19 00:21:39 2025 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E3D52DB87 for ; Fri, 15 Dec 2023 11:15:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="UF8HDZ0/" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-336417c565eso399108f8f.3 for ; Fri, 15 Dec 2023 03:15:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1702638957; x=1703243757; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oz5guiKfUu5OkDBbdm/LWYtpQOKOV0guWSD3BkGnL4M=; b=UF8HDZ0/2AoYrajwOFa0iAZwufNoL+V7QaYLRPM4det4QnOqDbSUTXGB4jV6gG4Diw e5etBRCEjJm74WHK6+Uv8f4AvFsvy/616WFgb/gPiZpdv7zD9L4rT+JkpG0Q3lBesjuw J1XgIziXIj2Mq5aamNAjKFNnll+oErWyfj6pS9OiIwd38Gy8rwBYJQx/3ZobermqJxdq +cITS361gYPi0H3zTC9PsOmLPMsudB9GbY7QKhqqxwdLgXAxHo5+ZV39qoTA1S0JZdGk C3WsRAVZUMM2D0rpqgxIj+3Htett5m7d0Ch/z3uCWNe+OzySxg+AB3xrWEUL2ZRyDgOu LoLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702638957; x=1703243757; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oz5guiKfUu5OkDBbdm/LWYtpQOKOV0guWSD3BkGnL4M=; b=LqMgsGdPyEECUGq81J5/E03Sy5H+d6ner8gqH2rvcE5lZWaG91oAJgKc3GcjWJ248i v2+EYIQETgt/ZM1/lwUfGHFu/K8VXaHTR/C6w5x8TsISCZQa1xr+ghHpRrZecT1/FzFw HC5GrjfHtJ942gu39jfLxIpruwBJgxp0AG0C/hl3Bk9cuZjOgas710ihzQf95e4OcbEr VpU89yZFllfxXFznGWfonEujJ69+suRcn7GU0lvPTBjpUzdOuJoI1NGm3XkRoxgXm/ZG vRhZSehPCwzo2xzKaeSKYMvoBRN51AHC8pKWPZMLLapFoZUpDbaIZiT4vbJTKCjEkDCW SCug== X-Gm-Message-State: AOJu0YylUkcohLyBIOhtqu4XS0+P/c7EhJgjla1vjIqcw34FwU4suDWb /vhfNXed9QqgNkuG3lzjmxBiKg== X-Google-Smtp-Source: AGHT+IE0eyG/kZrxQ07tUJgniLeOXWkHI7YVXgUUzf5+6aPrP0/Lv6ASYjILCNUOFz/kURIq2ZjZfQ== X-Received: by 2002:adf:fec4:0:b0:334:b2ba:7244 with SMTP id q4-20020adffec4000000b00334b2ba7244mr3997319wrs.174.1702638956919; Fri, 15 Dec 2023 03:15:56 -0800 (PST) Received: from localhost.localdomain ([5.133.47.210]) by smtp.gmail.com with ESMTPSA id g13-20020a056000118d00b003333d46a9e8sm18511497wrx.56.2023.12.15.03.15.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 03:15:56 -0800 (PST) From: srinivas.kandagatla@linaro.org To: gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, Patrick Delaunay , Srinivas Kandagatla Subject: [PATCH 10/10] nvmem: stm32: add support for STM32MP25 BSEC to control OTP data Date: Fri, 15 Dec 2023 11:15:36 +0000 Message-Id: <20231215111536.316972-11-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231215111536.316972-1-srinivas.kandagatla@linaro.org> References: <20231215111536.316972-1-srinivas.kandagatla@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2231; i=srinivas.kandagatla@linaro.org; h=from:subject; bh=4O4WBaJhnw+j/8i/dvSP/B2/3NEdWuXi4KfR7fhrYm0=; b=owEBbQGS/pANAwAKAXqh/VnHNFU3AcsmYgBlfDVYlyX1V5fA3OGAmnHqciQ/gqZpouklcrtwJ uWQX60PZ+OJATMEAAEKAB0WIQQi509axvzi9vce3Y16of1ZxzRVNwUCZXw1WAAKCRB6of1ZxzRV NwCBB/0SEYgVT+0cRSdc9Epo1PpmIEag/pDdzgwIBM7Y49/eIwUxUHZN1AHyQqaW3is6i2iO4FN ChjUjrnd1gIkmbfDobB6DuY+9QW00GNjg4kcDixxYmO1+Rk646SJrnacW2vSmtQtQzU+82rOGKm GVto3RE5tbDUcMqTQVyOlX2DLkPtKGJs6QeEFFOdn6CSV8nTTfndNuZZuxdo2VFCMIkTGnKZcFP kygxBPd3YSzbSaT0BiyHAhnPdjipqhNbOLJo2ExboZ3m2bakxdOjRs/XfobPC6dSfUtpcS8/lvl mgxkX8TUosjv+bi43X6jmqA8iR0pXJ23u4G+Tnm09iel+NYb X-Developer-Key: i=srinivas.kandagatla@linaro.org; a=openpgp; fpr=ED6472765AB36EC43B3EF97AD77E3FC0562560D6 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Patrick Delaunay On STM32MP25, OTP area may be read/written by using BSEC (boot, security and OTP control). The BSEC internal peripheral is only managed by the secure world. The 12 Kbits of OTP (effective) are organized into the following regions: - lower OTP (OTP0 to OTP127) =3D 4096 lower OTP bits, bitwise (1-bit) programmable - mid OTP (OTP128 to OTP255) =3D 4096 middle OTP bits, bulk (32-bit) programmable - upper OTP (OTP256 to OTP383) =3D 4096 upper OTP bits, bulk (32-bit) programmable, only accessible when BSEC is in closed state. As HWKEY and ECIES key are only accessible by ROM code; only 368 OTP words are managed in this driver (OTP0 to OTP267). This patch adds the STM32MP25 configuration for reading and writing the OTP data using the OP-TEE BSEC TA services. Signed-off-by: Patrick Delaunay Signed-off-by: Srinivas Kandagatla --- drivers/nvmem/stm32-romem.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/nvmem/stm32-romem.c b/drivers/nvmem/stm32-romem.c index 8a553b1799a8..82879b1c9eb9 100644 --- a/drivers/nvmem/stm32-romem.c +++ b/drivers/nvmem/stm32-romem.c @@ -269,6 +269,19 @@ static const struct stm32_romem_cfg stm32mp13_bsec_cfg= =3D { .ta =3D true, }; =20 +/* + * STM32MP25 BSEC OTP: 3 regions of 32-bits data words + * lower OTP (OTP0 to OTP127), bitwise (1-bit) programmable + * mid OTP (OTP128 to OTP255), bulk (32-bit) programmable + * upper OTP (OTP256 to OTP383), bulk (32-bit) programmable + * but no access to HWKEY and ECIES key: limited at OTP367 + */ +static const struct stm32_romem_cfg stm32mp25_bsec_cfg =3D { + .size =3D 368 * 4, + .lower =3D 127, + .ta =3D true, +}; + static const struct of_device_id stm32_romem_of_match[] __maybe_unused =3D= { { .compatible =3D "st,stm32f4-otp", }, { .compatible =3D "st,stm32mp15-bsec", @@ -276,6 +289,9 @@ static const struct of_device_id stm32_romem_of_match[]= __maybe_unused =3D { }, { .compatible =3D "st,stm32mp13-bsec", .data =3D (void *)&stm32mp13_bsec_cfg, + }, { + .compatible =3D "st,stm32mp25-bsec", + .data =3D (void *)&stm32mp25_bsec_cfg, }, { /* sentinel */ }, }; --=20 2.25.1