Hei hei,
on a custom sam9x60 based board we want to access a unique ID of the
SoC. Microchip sam-ba has a command 'readuniqueid' which returns the
content of the OTPC Product UID x Register in that case.
(On a different board with a SAMA5D2 we use the Serial Number x Register
exposed through the atmel soc driver, which is not present in the
SAM9X60 series.)
There is a driver for the OTPC of the SAMA7G5 and after comparing
register layouts it seems that one is almost identical to the one used
by SAM9X60. So I thought just adapting the driver for SAM9X60 should be
easy. (At least as a start, the driver has no support for that UID
register, but I suppose it would be the right place to implement it.)
However it does not work. I used the patch attached with
additional debug messages on a SAM9X60-Curiosity board. (That patch is
not meant for inclusion, just for showing what I've tried.)
On probe the function mchp_otpc_init_packets_list() returns with
ETIMEDOUT, which it can only do if mchp_otpc_prepare_read() returns with
timeout and that can only happen if read_poll_timeout() times out on
reading the Status Register. Poking that register with `devmem
0xeff0000c 32` gives 0x00000040 which means "A packet read is on-going".
Kinda stuck here. Any ideas?
Greets and have a nice weekend everyone
Alex
Alexander Dahl (1):
nvmem: microchip-otpc: Add support for SAM9X60
.../dts/microchip/at91-sam9x60_curiosity.dts | 4 ++++
arch/arm/boot/dts/microchip/sam9x60.dtsi | 7 +++++++
drivers/nvmem/microchip-otpc.c | 16 +++++++++++++---
3 files changed, 24 insertions(+), 3 deletions(-)
base-commit: fec50db7033ea478773b159e0e2efb135270e3b7
--
2.39.2
---
.../dts/microchip/at91-sam9x60_curiosity.dts | 4 ++++
arch/arm/boot/dts/microchip/sam9x60.dtsi | 7 +++++++
drivers/nvmem/microchip-otpc.c | 16 +++++++++++++---
3 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/arch/arm/boot/dts/microchip/at91-sam9x60_curiosity.dts b/arch/arm/boot/dts/microchip/at91-sam9x60_curiosity.dts
index c6fbdd29019f..754ce8134f73 100644
--- a/arch/arm/boot/dts/microchip/at91-sam9x60_curiosity.dts
+++ b/arch/arm/boot/dts/microchip/at91-sam9x60_curiosity.dts
@@ -254,6 +254,10 @@ ethernet-phy@0 {
};
};
+&otpc {
+ status = "okay";
+};
+
&pinctrl {
adc {
pinctrl_adc_default: adc-default {
diff --git a/arch/arm/boot/dts/microchip/sam9x60.dtsi b/arch/arm/boot/dts/microchip/sam9x60.dtsi
index 291540e5d81e..010c45f533fe 100644
--- a/arch/arm/boot/dts/microchip/sam9x60.dtsi
+++ b/arch/arm/boot/dts/microchip/sam9x60.dtsi
@@ -156,6 +156,13 @@ sdmmc1: sdio-host@90000000 {
status = "disabled";
};
+ otpc: efuse@eff00000 {
+ compatible = "microchip,sam9x60-otpc", "syscon";
+ reg = <0xeff00000 0xec>;
+ #address-cells = <1>;
+ #size-cells = <1>;
+ };
+
apb {
compatible = "simple-bus";
#address-cells = <1>;
diff --git a/drivers/nvmem/microchip-otpc.c b/drivers/nvmem/microchip-otpc.c
index 7cf81738a3e0..af9ab1158a2b 100644
--- a/drivers/nvmem/microchip-otpc.c
+++ b/drivers/nvmem/microchip-otpc.c
@@ -8,6 +8,7 @@
*/
#include <linux/bitfield.h>
+#include <linux/dev_printk.h>
#include <linux/iopoll.h>
#include <linux/module.h>
#include <linux/nvmem-provider.h>
@@ -248,29 +249,38 @@ static int mchp_otpc_probe(struct platform_device *pdev)
int ret;
otpc = devm_kzalloc(&pdev->dev, sizeof(*otpc), GFP_KERNEL);
- if (!otpc)
+ if (!otpc) {
+ dev_err(&pdev->dev, "devm_kzalloc() error\n");
return -ENOMEM;
+ }
otpc->base = devm_platform_ioremap_resource(pdev, 0);
- if (IS_ERR(otpc->base))
+ if (IS_ERR(otpc->base)) {
+ dev_err(&pdev->dev, "devm_platform_ioremap_resource() error\n");
return PTR_ERR(otpc->base);
+ }
otpc->dev = &pdev->dev;
ret = mchp_otpc_init_packets_list(otpc, &size);
- if (ret)
+ if (ret) {
+ dev_err(&pdev->dev, "mchp_otpc_init_packets_list() error (%d)\n", ret);
return ret;
+ }
mchp_nvmem_config.dev = otpc->dev;
mchp_nvmem_config.add_legacy_fixed_of_cells = true;
mchp_nvmem_config.size = size;
mchp_nvmem_config.priv = otpc;
nvmem = devm_nvmem_register(&pdev->dev, &mchp_nvmem_config);
+ if (!nvmem)
+ dev_err(&pdev->dev, "devm_nvmem_register() error\n");
return PTR_ERR_OR_ZERO(nvmem);
}
static const struct of_device_id __maybe_unused mchp_otpc_ids[] = {
{ .compatible = "microchip,sama7g5-otpc", },
+ { .compatible = "microchip,sam9x60-otpc", },
{ },
};
MODULE_DEVICE_TABLE(of, mchp_otpc_ids);
--
2.39.2
Hi, Alexander,
On 12.04.2024 17:08, Alexander Dahl wrote:
> Hei hei,
>
> on a custom sam9x60 based board we want to access a unique ID of the
> SoC. Microchip sam-ba has a command 'readuniqueid' which returns the
> content of the OTPC Product UID x Register in that case.
>
> (On a different board with a SAMA5D2 we use the Serial Number x Register
> exposed through the atmel soc driver, which is not present in the
> SAM9X60 series.)
>
> There is a driver for the OTPC of the SAMA7G5 and after comparing
> register layouts it seems that one is almost identical to the one used
> by SAM9X60. So I thought just adapting the driver for SAM9X60 should be
> easy. (At least as a start, the driver has no support for that UID
> register, but I suppose it would be the right place to implement it.)
>
> However it does not work. I used the patch attached with
> additional debug messages on a SAM9X60-Curiosity board. (That patch is
> not meant for inclusion, just for showing what I've tried.)
>
> On probe the function mchp_otpc_init_packets_list() returns with
> ETIMEDOUT, which it can only do if mchp_otpc_prepare_read() returns with
> timeout and that can only happen if read_poll_timeout() times out on
> reading the Status Register. Poking that register with `devmem
> 0xeff0000c 32` gives 0x00000040 which means "A packet read is on-going".
Would it be possible that the OTP memory is not properly initialized and
the algorithm to initialized the packet list to confuse the hardware?
I see in the datasheet the following: "The initial value of the OTP memory
is ‘0’ but the memory may contain some “defective” bits already set to the
value ‘1’."
Otherwise, from the top of my mind I don't have any idea on what might happen.
Thank you,
Claudiu Beznea
>
> Kinda stuck here. Any ideas?
>
> Greets and have a nice weekend everyone
> Alex
>
> Alexander Dahl (1):
> nvmem: microchip-otpc: Add support for SAM9X60
>
> .../dts/microchip/at91-sam9x60_curiosity.dts | 4 ++++
> arch/arm/boot/dts/microchip/sam9x60.dtsi | 7 +++++++
> drivers/nvmem/microchip-otpc.c | 16 +++++++++++++---
> 3 files changed, 24 insertions(+), 3 deletions(-)
>
>
> base-commit: fec50db7033ea478773b159e0e2efb135270e3b7