From: Alexander Dahl <ada@thorsis.com>
To: Claudiu Beznea <claudiu.beznea@tuxon.dev>
Cc: Nicolas Ferre <nicolas.ferre@microchip.com>,
Ryan Wanner <ryan.wanner@microchip.com>,
linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org,
linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org,
Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Subject: [PATCH v2 16/16] nvmem: microchip-otpc: Expose UID registers as 2nd nvmem device
Date: Tue, 11 Feb 2025 07:53:04 +0100 [thread overview]
Message-ID: <20250211065304.5019-4-ada@thorsis.com> (raw)
In-Reply-To: <20250211065304.5019-1-ada@thorsis.com>
For SAM9X60 the Product UID x Register containing the Unique Product ID
is part of the OTPC registers. We have everything at hand here to just
create a trivial nvmem device for those.
Signed-off-by: Alexander Dahl <ada@thorsis.com>
---
Notes:
v2:
- Use dev_err_probe() for error reporting (thanks Claudiu)
- Move required register definition over here from removed patch
drivers/nvmem/microchip-otpc.c | 38 +++++++++++++++++++++++++++++++++-
1 file changed, 37 insertions(+), 1 deletion(-)
diff --git a/drivers/nvmem/microchip-otpc.c b/drivers/nvmem/microchip-otpc.c
index 2c524c163b7e2..8353a117769a8 100644
--- a/drivers/nvmem/microchip-otpc.c
+++ b/drivers/nvmem/microchip-otpc.c
@@ -25,10 +25,14 @@
#define MCHP_OTPC_HR (0x20)
#define MCHP_OTPC_HR_SIZE GENMASK(15, 8)
#define MCHP_OTPC_DR (0x24)
+#define MCHP_OTPC_UID0R (0x60)
#define MCHP_OTPC_NAME "mchp-otpc"
#define MCHP_OTPC_SIZE (11 * 1024)
+#define MCHP_OTPC_UID_NAME "mchp-uid"
+#define MCHP_OTPC_UID_SIZE 16
+
/**
* struct mchp_otpc - OTPC private data structure
* @base: base address
@@ -230,6 +234,16 @@ static int mchp_otpc_init_packets_list(struct mchp_otpc *otpc, u32 *size)
return 0;
}
+static int mchp_otpc_uid_read(void *priv, unsigned int offset,
+ void *val, size_t bytes)
+{
+ struct mchp_otpc *otpc = priv;
+
+ memcpy_fromio(val, otpc->base + MCHP_OTPC_UID0R + offset, bytes);
+
+ return 0;
+}
+
static struct nvmem_config mchp_nvmem_config = {
.name = MCHP_OTPC_NAME,
.type = NVMEM_TYPE_OTP,
@@ -239,6 +253,15 @@ static struct nvmem_config mchp_nvmem_config = {
.reg_read = mchp_otpc_read,
};
+static struct nvmem_config mchp_otpc_uid_nvmem_config = {
+ .name = MCHP_OTPC_UID_NAME,
+ .read_only = true,
+ .word_size = 4,
+ .stride = 4,
+ .size = MCHP_OTPC_UID_SIZE,
+ .reg_read = mchp_otpc_uid_read,
+};
+
static int mchp_otpc_probe(struct platform_device *pdev)
{
struct nvmem_device *nvmem;
@@ -270,8 +293,21 @@ static int mchp_otpc_probe(struct platform_device *pdev)
mchp_nvmem_config.size = size;
mchp_nvmem_config.priv = otpc;
nvmem = devm_nvmem_register(&pdev->dev, &mchp_nvmem_config);
+ if (IS_ERR(nvmem)) {
+ return dev_err_probe(&pdev->dev, PTR_ERR(nvmem),
+ "Error registering OTP as nvmem device\n");
+ }
- return PTR_ERR_OR_ZERO(nvmem);
+ mchp_otpc_uid_nvmem_config.dev = otpc->dev;
+ mchp_otpc_uid_nvmem_config.priv = otpc;
+
+ nvmem = devm_nvmem_register(&pdev->dev, &mchp_otpc_uid_nvmem_config);
+ if (IS_ERR(nvmem)) {
+ return dev_err_probe(&pdev->dev, PTR_ERR(nvmem),
+ "Error registering UIDxR as nvmem device\n");
+ }
+
+ return 0;
}
static const struct of_device_id __maybe_unused mchp_otpc_ids[] = {
--
2.39.5
next prev parent reply other threads:[~2025-02-11 6:53 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-10 16:44 [PATCH v2 00/16] Microchip OTPC driver on SAM9X60 exposing UIDxR as additional nvmem device Alexander Dahl
2025-02-10 16:44 ` [PATCH v2 01/16] dt-bindings: clock: at91: Split up per SoC partially Alexander Dahl
2025-02-10 17:05 ` Krzysztof Kozlowski
2025-02-11 7:16 ` Alexander Dahl
2025-02-11 7:47 ` Krzysztof Kozlowski
2025-02-17 9:11 ` Claudiu Beznea
2025-02-17 9:47 ` Alexander Dahl
2025-02-19 8:51 ` Claudiu Beznea
2025-02-19 9:08 ` Alexander Dahl
2025-02-10 16:44 ` [PATCH v2 02/16] ARM: dts: microchip: Use new PMC bindings Alexander Dahl
2025-02-10 16:44 ` [PATCH v2 03/16] clk: at91: " Alexander Dahl
2025-02-10 16:44 ` [PATCH v2 04/16] dt-bindings: clock: at91: Allow referencing main rc oscillator in DT Alexander Dahl
2025-02-10 17:07 ` Krzysztof Kozlowski
2025-02-11 7:26 ` Alexander Dahl
2025-02-11 8:01 ` Krzysztof Kozlowski
2025-02-10 16:44 ` [PATCH v2 05/16] clk: at91: Allow enabling main_rc_osc through DT Alexander Dahl
2025-02-10 16:44 ` [PATCH v2 06/16] clk: at91: Add peripheral id for OTPC Alexander Dahl
2025-02-10 16:44 ` [PATCH v2 07/16] dt-bindings: nvmem: microchip-otpc: Add compatible for SAM9X60 Alexander Dahl
2025-02-12 9:13 ` Krzysztof Kozlowski
2025-02-10 16:44 ` [PATCH v2 08/16] dt-bindings: nvmem: microchip-otpc: Add required clocks Alexander Dahl
2025-02-10 16:59 ` Krzysztof Kozlowski
2025-02-11 7:05 ` Alexander Dahl
2025-02-11 7:50 ` Krzysztof Kozlowski
2025-02-10 16:50 ` [PATCH v2 09/16] nvmem: microchip-otpc: Avoid reading a write-only register Alexander Dahl
2025-02-11 6:47 ` Greg Kroah-Hartman
2025-02-17 9:10 ` Claudiu Beznea
2025-02-11 6:52 ` [PATCH v2 10/16] nvmem: microchip-otpc: Fix swapped 'sleep' and 'timeout' parameters Alexander Dahl
2025-02-11 6:52 ` [PATCH v2 11/16] nvmem: microchip-otpc: Add SAM9X60 support Alexander Dahl
2025-02-11 6:52 ` [PATCH v2 12/16] ARM: dts: microchip: sama7g5: Add OTPC clocks Alexander Dahl
2025-02-17 9:10 ` [PATCH v2 10/16] nvmem: microchip-otpc: Fix swapped 'sleep' and 'timeout' parameters Claudiu Beznea
2025-02-11 6:53 ` [PATCH v2 13/16] ARM: dts: microchip: sam9x60: Add OTPC node Alexander Dahl
2025-02-11 6:53 ` [PATCH v2 14/16] ARM: dts: microchip: sam9x60_curiosity: Enable OTP Controller Alexander Dahl
2025-02-11 6:53 ` [PATCH v2 15/16] nvmem: microchip-otpc: Enable necessary clocks Alexander Dahl
2025-02-17 9:10 ` Claudiu Beznea
2025-02-11 6:53 ` Alexander Dahl [this message]
2025-02-17 9:10 ` [PATCH v2 13/16] ARM: dts: microchip: sam9x60: Add OTPC node Claudiu Beznea
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250211065304.5019-4-ada@thorsis.com \
--to=ada@thorsis.com \
--cc=claudiu.beznea@tuxon.dev \
--cc=devicetree@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nicolas.ferre@microchip.com \
--cc=ryan.wanner@microchip.com \
--cc=srinivas.kandagatla@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).