2019-01-30 16:40:29

by Fabrice Gasnier

[permalink] [raw]
Subject: [PATCH 0/4] Add nvmem support on STM32

Non volatile memory area is available on STM32. It contains various
factory programmed information such as unique device ID, analog calibration...
This patchset adds NVMEM support to access these data.

Fabrice Gasnier (4):
dt-bindings: nvmem: Add STM32 factory-programmed romem
nvmem: Add driver for STM32 factory-programmed read only mem
nvmem: stm32: add support for STM32MP15 BSEC to control OTP data
ARM: dts: stm32: Add romem and temperature calibration on stm32mp157c

.../devicetree/bindings/nvmem/st,stm32-romem.txt | 31 ++++
arch/arm/boot/dts/stm32mp157c.dtsi | 13 ++
drivers/nvmem/Kconfig | 10 +
drivers/nvmem/Makefile | 2 +
drivers/nvmem/stm32-romem.c | 202 +++++++++++++++++++++
5 files changed, 258 insertions(+)
create mode 100644 Documentation/devicetree/bindings/nvmem/st,stm32-romem.txt
create mode 100644 drivers/nvmem/stm32-romem.c

--
1.9.1



2019-01-30 16:39:49

by Fabrice Gasnier

[permalink] [raw]
Subject: [PATCH 4/4] ARM: dts: stm32: Add romem and temperature calibration on stm32mp157c

Add & enable stm32 factory-programmed memory. Describe temperature sensor
calibration cells. Non-volatile calibration data is made available by
stm32mp157c bootrom in bsec_dataX registers.

Signed-off-by: Fabrice Gasnier <[email protected]>
---
arch/arm/boot/dts/stm32mp157c.dtsi | 13 +++++++++++++
1 file changed, 13 insertions(+)

diff --git a/arch/arm/boot/dts/stm32mp157c.dtsi b/arch/arm/boot/dts/stm32mp157c.dtsi
index 8bf1c17..9a7ac80 100644
--- a/arch/arm/boot/dts/stm32mp157c.dtsi
+++ b/arch/arm/boot/dts/stm32mp157c.dtsi
@@ -1106,6 +1106,19 @@
status = "disabled";
};

+ bsec: nvmem@5c005000 {
+ compatible = "st,stm32mp15-bsec";
+ reg = <0x5c005000 0x400>;
+ #address-cells = <1>;
+ #size-cells = <1>;
+ ts_cal1: calib@5c {
+ reg = <0x5c 0x2>;
+ };
+ ts_cal2: calib@5e {
+ reg = <0x5e 0x2>;
+ };
+ };
+
i2c6: i2c@5c009000 {
compatible = "st,stm32f7-i2c";
reg = <0x5c009000 0x400>;
--
1.9.1


2019-01-30 16:39:55

by Fabrice Gasnier

[permalink] [raw]
Subject: [PATCH 2/4] nvmem: Add driver for STM32 factory-programmed read only mem

Add a read only nvmem driver for STM32 factory-programmed memory area
(on-chip non-volatile storage).

Signed-off-by: Fabrice Gasnier <[email protected]>
---
drivers/nvmem/Kconfig | 10 ++++++
drivers/nvmem/Makefile | 2 ++
drivers/nvmem/stm32-romem.c | 78 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 90 insertions(+)
create mode 100644 drivers/nvmem/stm32-romem.c

diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
index 0a7a470e..f398b18 100644
--- a/drivers/nvmem/Kconfig
+++ b/drivers/nvmem/Kconfig
@@ -113,6 +113,16 @@ config NVMEM_BCM_OCOTP
This driver can also be built as a module. If so, the module
will be called nvmem-bcm-ocotp.

+config NVMEM_STM32_ROMEM
+ tristate "STMicroelectronics STM32 factory-programmed memory support"
+ depends on ARCH_STM32 || COMPILE_TEST
+ help
+ Say y here to enable read-only access for STMicroelectronics STM32
+ factory-programmed memory area.
+
+ This driver can also be built as a module. If so, the module
+ will be called nvmem-stm32-romem.
+
config NVMEM_SUNXI_SID
tristate "Allwinner SoCs SID support"
depends on ARCH_SUNXI
diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile
index 4e8c616..e85c946 100644
--- a/drivers/nvmem/Makefile
+++ b/drivers/nvmem/Makefile
@@ -26,6 +26,8 @@ nvmem_qfprom-y := qfprom.o
obj-$(CONFIG_ROCKCHIP_EFUSE) += nvmem_rockchip_efuse.o
nvmem_rockchip_efuse-y := rockchip-efuse.o
obj-$(CONFIG_NVMEM_SUNXI_SID) += nvmem_sunxi_sid.o
+nvmem_stm32_romem-y := stm32-romem.o
+obj-$(CONFIG_NVMEM_STM32_ROMEM) += nvmem_stm32_romem.o
nvmem_sunxi_sid-y := sunxi_sid.o
obj-$(CONFIG_UNIPHIER_EFUSE) += nvmem-uniphier-efuse.o
nvmem-uniphier-efuse-y := uniphier-efuse.o
diff --git a/drivers/nvmem/stm32-romem.c b/drivers/nvmem/stm32-romem.c
new file mode 100644
index 0000000..dadbcc2
--- /dev/null
+++ b/drivers/nvmem/stm32-romem.c
@@ -0,0 +1,78 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * STM32 Factory-programmed memory read access driver
+ *
+ * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
+ * Author: Fabrice Gasnier <[email protected]> for STMicroelectronics.
+ */
+
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/nvmem-provider.h>
+#include <linux/of_device.h>
+
+struct stm32_romem_priv {
+ void __iomem *base;
+ struct nvmem_config cfg;
+};
+
+static int stm32_romem_read(void *context, unsigned int offset, void *buf,
+ size_t bytes)
+{
+ struct stm32_romem_priv *priv = context;
+ u8 *buf8 = buf;
+ int i;
+
+ for (i = offset; i < offset + bytes; i++)
+ *buf8++ = readb_relaxed(priv->base + i);
+
+ return 0;
+}
+
+static int stm32_romem_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct stm32_romem_priv *priv;
+ struct resource *res;
+
+ priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+ if (!priv)
+ return -ENOMEM;
+
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ priv->base = devm_ioremap_resource(dev, res);
+ if (IS_ERR(priv->base))
+ return PTR_ERR(priv->base);
+
+ priv->cfg.name = "stm32-romem";
+ priv->cfg.read_only = true;
+ priv->cfg.word_size = 1;
+ priv->cfg.stride = 1;
+ priv->cfg.size = resource_size(res);
+ priv->cfg.reg_read = stm32_romem_read;
+ priv->cfg.dev = dev;
+ priv->cfg.priv = priv;
+ priv->cfg.owner = THIS_MODULE;
+
+ return PTR_ERR_OR_ZERO(devm_nvmem_register(dev, &priv->cfg));
+}
+
+static const struct of_device_id stm32_romem_of_match[] = {
+ { .compatible = "st,stm32-romem", },
+ {},
+};
+MODULE_DEVICE_TABLE(of, stm32_romem_of_match);
+
+static struct platform_driver stm32_romem_driver = {
+ .probe = stm32_romem_probe,
+ .driver = {
+ .name = "stm32-romem",
+ .of_match_table = of_match_ptr(stm32_romem_of_match),
+ },
+};
+module_platform_driver(stm32_romem_driver);
+
+MODULE_AUTHOR("Fabrice Gasnier <[email protected]>");
+MODULE_DESCRIPTION("STMicroelectronics STM32 RO-MEM");
+MODULE_ALIAS("platform:nvmem-stm32-romem");
+MODULE_LICENSE("GPL v2");
--
1.9.1


2019-01-30 16:40:40

by Fabrice Gasnier

[permalink] [raw]
Subject: [PATCH 1/4] dt-bindings: nvmem: Add STM32 factory-programmed romem

Add documentation for STMicroelectronics STM32 Factory-programmed
read only memory area.

Signed-off-by: Fabrice Gasnier <[email protected]>
---
.../devicetree/bindings/nvmem/st,stm32-romem.txt | 31 ++++++++++++++++++++++
1 file changed, 31 insertions(+)
create mode 100644 Documentation/devicetree/bindings/nvmem/st,stm32-romem.txt

diff --git a/Documentation/devicetree/bindings/nvmem/st,stm32-romem.txt b/Documentation/devicetree/bindings/nvmem/st,stm32-romem.txt
new file mode 100644
index 0000000..fbff52e
--- /dev/null
+++ b/Documentation/devicetree/bindings/nvmem/st,stm32-romem.txt
@@ -0,0 +1,31 @@
+STMicroelectronics STM32 Factory-programmed data device tree bindings
+
+This represents STM32 Factory-programmed read only non-volatile area: locked
+flash, OTP, read-only HW regs... This contains various information such as:
+analog calibration data for temperature sensor (e.g. TS_CAL1, TS_CAL2),
+internal vref (VREFIN_CAL), unique device ID...
+
+Required properties:
+- compatible: Should be one of:
+ "st,stm32-romem"
+ "st,stm32mp15-bsec"
+- reg: Offset and length of factory-programmed area.
+- #address-cells: Should be '<1>'.
+- #size-cells: Should be '<1>'.
+
+Optional Data cells:
+- Must be child nodes as described in nvmem.txt.
+
+Example on stm32f4:
+ romem: nvmem@1fff7800 {
+ compatible = "st,stm32-romem";
+ reg = <0x1fff7800 0x400>;
+ #address-cells = <1>;
+ #size-cells = <1>;
+
+ /* Data cells: ts_cal1 at 0x1fff7a2c */
+ ts_cal1: calib@22c {
+ reg = <0x22c 0x2>;
+ };
+ ...
+ };
--
1.9.1


2019-01-30 16:41:23

by Fabrice Gasnier

[permalink] [raw]
Subject: [PATCH 3/4] nvmem: stm32: add support for STM32MP15 BSEC to control OTP data

On STM32MP15, OTP area may be read/written by using BSEC (boot, security
and OTP control). BSEC registers set is composed of various regions, among
which control registers and OTP shadow registers.
Secure monitor calls are involved in this process to allow (or deny)
access to the full range of OTP data.
This adds support for reading and writing OTP data using SMC services.
Data content can be aligned on 16-bits or 8-bits. Then take care of it,
since BSEC data is 32-bits wide.

Signed-off-by: Fabrice Gasnier <[email protected]>
---
drivers/nvmem/stm32-romem.c | 134 ++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 129 insertions(+), 5 deletions(-)

diff --git a/drivers/nvmem/stm32-romem.c b/drivers/nvmem/stm32-romem.c
index dadbcc2..efb9f38 100644
--- a/drivers/nvmem/stm32-romem.c
+++ b/drivers/nvmem/stm32-romem.c
@@ -6,11 +6,29 @@
* Author: Fabrice Gasnier <[email protected]> for STMicroelectronics.
*/

+#include <linux/arm-smccc.h>
#include <linux/io.h>
#include <linux/module.h>
#include <linux/nvmem-provider.h>
#include <linux/of_device.h>

+/* BSEC secure service access from non-secure */
+#define STM32_SMC_BSEC 0x82001003
+#define STM32_SMC_READ_SHADOW 0x01
+#define STM32_SMC_PROG_OTP 0x02
+#define STM32_SMC_WRITE_SHADOW 0x03
+#define STM32_SMC_READ_OTP 0x04
+
+/* shadow registers offest */
+#define STM32MP15_BSEC_DATA0 0x200
+
+/* 32 (x 32-bits) lower shadow registers */
+#define STM32MP15_BSEC_NUM_LOWER 32
+
+struct stm32_romem_cfg {
+ int size;
+};
+
struct stm32_romem_priv {
void __iomem *base;
struct nvmem_config cfg;
@@ -29,8 +47,98 @@ static int stm32_romem_read(void *context, unsigned int offset, void *buf,
return 0;
}

+static int stm32_bsec_smc(u8 op, u32 otp, u32 data, u32 *result)
+{
+#if IS_ENABLED(CONFIG_HAVE_ARM_SMCCC)
+ struct arm_smccc_res res;
+
+ arm_smccc_smc(STM32_SMC_BSEC, op, otp, data, 0, 0, 0, 0, &res);
+ if (res.a0)
+ return -EIO;
+
+ if (result)
+ *result = (u32)res.a1;
+
+ return 0;
+#else
+ return -ENXIO;
+#endif
+}
+
+static int stm32_bsec_read(void *context, unsigned int offset, void *buf,
+ size_t bytes)
+{
+ struct stm32_romem_priv *priv = context;
+ struct device *dev = priv->cfg.dev;
+ u32 roffset, rbytes, val;
+ u8 *buf8 = buf, *val8 = (u8 *)&val;
+ int i, j = 0, ret, skip_bytes, size;
+
+ /* Round unaligned access to 32-bits */
+ roffset = rounddown(offset, 4);
+ skip_bytes = offset & 0x3;
+ rbytes = roundup(bytes + skip_bytes, 4);
+
+ if (roffset + rbytes > priv->cfg.size)
+ return -EINVAL;
+
+ for (i = roffset; (i < roffset + rbytes); i += 4) {
+ u32 otp = i >> 2;
+
+ if (otp < STM32MP15_BSEC_NUM_LOWER) {
+ /* read lower data from shadow registers */
+ val = readl_relaxed(
+ priv->base + STM32MP15_BSEC_DATA0 + i);
+ } else {
+ ret = stm32_bsec_smc(STM32_SMC_READ_SHADOW, otp, 0,
+ &val);
+ if (ret) {
+ dev_err(dev, "Can't read data%d (%d)\n", otp,
+ ret);
+ return ret;
+ }
+ }
+ /* skip first bytes in case of unaligned read */
+ if (skip_bytes)
+ size = min(bytes, (size_t)(4 - skip_bytes));
+ else
+ size = min(bytes, (size_t)4);
+ memcpy(&buf8[j], &val8[skip_bytes], size);
+ bytes -= size;
+ j += size;
+ skip_bytes = 0;
+ }
+
+ return 0;
+}
+
+static int stm32_bsec_write(void *context, unsigned int offset, void *buf,
+ size_t bytes)
+{
+ struct stm32_romem_priv *priv = context;
+ struct device *dev = priv->cfg.dev;
+ u32 *buf32 = buf;
+ int ret, i;
+
+ /* Allow only writing complete 32-bits aligned words */
+ if ((bytes % 4) || (offset % 4))
+ return -EINVAL;
+
+ for (i = offset; i < offset + bytes; i += 4) {
+ ret = stm32_bsec_smc(STM32_SMC_PROG_OTP, i >> 2, *buf32++,
+ NULL);
+ if (ret) {
+ dev_err(dev, "Can't write data%d (%d)\n", i >> 2, ret);
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
static int stm32_romem_probe(struct platform_device *pdev)
{
+ const struct stm32_romem_cfg *cfg;
struct device *dev = &pdev->dev;
struct stm32_romem_priv *priv;
struct resource *res;
@@ -45,21 +153,37 @@ static int stm32_romem_probe(struct platform_device *pdev)
return PTR_ERR(priv->base);

priv->cfg.name = "stm32-romem";
- priv->cfg.read_only = true;
priv->cfg.word_size = 1;
priv->cfg.stride = 1;
- priv->cfg.size = resource_size(res);
- priv->cfg.reg_read = stm32_romem_read;
priv->cfg.dev = dev;
priv->cfg.priv = priv;
priv->cfg.owner = THIS_MODULE;

+ cfg = (const struct stm32_romem_cfg *)
+ of_match_device(dev->driver->of_match_table, dev)->data;
+ if (!cfg) {
+ priv->cfg.read_only = true;
+ priv->cfg.size = resource_size(res);
+ priv->cfg.reg_read = stm32_romem_read;
+ } else {
+ priv->cfg.size = cfg->size;
+ priv->cfg.reg_read = stm32_bsec_read;
+ priv->cfg.reg_write = stm32_bsec_write;
+ }
+
return PTR_ERR_OR_ZERO(devm_nvmem_register(dev, &priv->cfg));
}

+static const struct stm32_romem_cfg stm32mp15_bsec_cfg = {
+ .size = 384, /* 96 x 32-bits data words */
+};
+
static const struct of_device_id stm32_romem_of_match[] = {
- { .compatible = "st,stm32-romem", },
- {},
+ { .compatible = "st,stm32-romem", }, {
+ .compatible = "st,stm32mp15-bsec",
+ .data = (void *)&stm32mp15_bsec_cfg,
+ }, {
+ },
};
MODULE_DEVICE_TABLE(of, stm32_romem_of_match);

--
1.9.1


2019-02-13 13:44:48

by Fabrice Gasnier

[permalink] [raw]
Subject: Re: [PATCH 0/4] Add nvmem support on STM32

On 1/30/19 5:38 PM, Fabrice Gasnier wrote:
> Non volatile memory area is available on STM32. It contains various
> factory programmed information such as unique device ID, analog calibration...
> This patchset adds NVMEM support to access these data.

Hello,

Gentle reminder for this new driver review

Best Regards,
Fabrice

>
> Fabrice Gasnier (4):
> dt-bindings: nvmem: Add STM32 factory-programmed romem
> nvmem: Add driver for STM32 factory-programmed read only mem
> nvmem: stm32: add support for STM32MP15 BSEC to control OTP data
> ARM: dts: stm32: Add romem and temperature calibration on stm32mp157c
>
> .../devicetree/bindings/nvmem/st,stm32-romem.txt | 31 ++++
> arch/arm/boot/dts/stm32mp157c.dtsi | 13 ++
> drivers/nvmem/Kconfig | 10 +
> drivers/nvmem/Makefile | 2 +
> drivers/nvmem/stm32-romem.c | 202 +++++++++++++++++++++
> 5 files changed, 258 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/nvmem/st,stm32-romem.txt
> create mode 100644 drivers/nvmem/stm32-romem.c
>

2019-02-13 13:45:20

by Srinivas Kandagatla

[permalink] [raw]
Subject: Re: [PATCH 0/4] Add nvmem support on STM32



On 13/02/2019 10:15, Fabrice Gasnier wrote:
> On 1/30/19 5:38 PM, Fabrice Gasnier wrote:
>> Non volatile memory area is available on STM32. It contains various
>> factory programmed information such as unique device ID, analog calibration...
>> This patchset adds NVMEM support to access these data.
>
> Hello,
>
> Gentle reminder for this new driver review
Nvmem provider driver itself looks fine for me, but I am unable to take
this as 5.1 material, as I normally take nvmem patches which are
reviewed and ready before rc5.

dt bindings patch needs an ack from DT maintainers.

Thanks,
srini
>
> Best Regards,
> Fabrice
>
>>
>> Fabrice Gasnier (4):
>> dt-bindings: nvmem: Add STM32 factory-programmed romem
>> nvmem: Add driver for STM32 factory-programmed read only mem
>> nvmem: stm32: add support for STM32MP15 BSEC to control OTP data
>> ARM: dts: stm32: Add romem and temperature calibration on stm32mp157c
>>
>> .../devicetree/bindings/nvmem/st,stm32-romem.txt | 31 ++++
>> arch/arm/boot/dts/stm32mp157c.dtsi | 13 ++
>> drivers/nvmem/Kconfig | 10 +
>> drivers/nvmem/Makefile | 2 +
>> drivers/nvmem/stm32-romem.c | 202 +++++++++++++++++++++
>> 5 files changed, 258 insertions(+)
>> create mode 100644 Documentation/devicetree/bindings/nvmem/st,stm32-romem.txt
>> create mode 100644 drivers/nvmem/stm32-romem.c
>>

2019-02-14 18:03:35

by Fabrice Gasnier

[permalink] [raw]
Subject: Re: [PATCH 0/4] Add nvmem support on STM32

On 2/13/19 11:34 AM, Srinivas Kandagatla wrote:
>
>
> On 13/02/2019 10:15, Fabrice Gasnier wrote:
>> On 1/30/19 5:38 PM, Fabrice Gasnier wrote:
>>> Non volatile memory area is available on STM32. It contains various
>>> factory programmed information such as unique device ID, analog
>>> calibration...
>>> This patchset adds NVMEM support to access these data.
>>
>> Hello,
>>
>> Gentle reminder for this new driver review
> Nvmem provider driver itself looks fine for me, but I am unable to take
> this as 5.1 material, as I normally take nvmem patches which are
> reviewed and ready before rc5.
>

Hi Srini,
Thanks for the feedback.

> dt bindings patch needs an ack from DT maintainers.

I hope Rob cant take a look at it.

Best Regards,
Fabrice

>
> Thanks,
> srini
>>
>> Best Regards,
>> Fabrice
>>
>>>
>>> Fabrice Gasnier (4):
>>>    dt-bindings: nvmem: Add STM32 factory-programmed romem
>>>    nvmem: Add driver for STM32 factory-programmed read only mem
>>>    nvmem: stm32: add support for STM32MP15 BSEC to control OTP data
>>>    ARM: dts: stm32: Add romem and temperature calibration on stm32mp157c
>>>
>>>   .../devicetree/bindings/nvmem/st,stm32-romem.txt   |  31 ++++
>>>   arch/arm/boot/dts/stm32mp157c.dtsi                 |  13 ++
>>>   drivers/nvmem/Kconfig                              |  10 +
>>>   drivers/nvmem/Makefile                             |   2 +
>>>   drivers/nvmem/stm32-romem.c                        | 202
>>> +++++++++++++++++++++
>>>   5 files changed, 258 insertions(+)
>>>   create mode 100644
>>> Documentation/devicetree/bindings/nvmem/st,stm32-romem.txt
>>>   create mode 100644 drivers/nvmem/stm32-romem.c
>>>

2019-02-18 13:46:20

by Fabrice Gasnier

[permalink] [raw]
Subject: Re: [PATCH 1/4] dt-bindings: nvmem: Add STM32 factory-programmed romem

On 1/30/19 5:38 PM, Fabrice Gasnier wrote:
> Add documentation for STMicroelectronics STM32 Factory-programmed
> read only memory area.

Hello Rob, DT Maintainers,

Gentlemen reminder for new DT bindings review.

Best Regards,
Fabrice
>
> Signed-off-by: Fabrice Gasnier <[email protected]>
> ---
> .../devicetree/bindings/nvmem/st,stm32-romem.txt | 31 ++++++++++++++++++++++
> 1 file changed, 31 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/nvmem/st,stm32-romem.txt
>
> diff --git a/Documentation/devicetree/bindings/nvmem/st,stm32-romem.txt b/Documentation/devicetree/bindings/nvmem/st,stm32-romem.txt
> new file mode 100644
> index 0000000..fbff52e
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/nvmem/st,stm32-romem.txt
> @@ -0,0 +1,31 @@
> +STMicroelectronics STM32 Factory-programmed data device tree bindings
> +
> +This represents STM32 Factory-programmed read only non-volatile area: locked
> +flash, OTP, read-only HW regs... This contains various information such as:
> +analog calibration data for temperature sensor (e.g. TS_CAL1, TS_CAL2),
> +internal vref (VREFIN_CAL), unique device ID...
> +
> +Required properties:
> +- compatible: Should be one of:
> + "st,stm32-romem"
> + "st,stm32mp15-bsec"
> +- reg: Offset and length of factory-programmed area.
> +- #address-cells: Should be '<1>'.
> +- #size-cells: Should be '<1>'.
> +
> +Optional Data cells:
> +- Must be child nodes as described in nvmem.txt.
> +
> +Example on stm32f4:
> + romem: nvmem@1fff7800 {
> + compatible = "st,stm32-romem";
> + reg = <0x1fff7800 0x400>;
> + #address-cells = <1>;
> + #size-cells = <1>;
> +
> + /* Data cells: ts_cal1 at 0x1fff7a2c */
> + ts_cal1: calib@22c {
> + reg = <0x22c 0x2>;
> + };
> + ...
> + };
>

2019-02-25 16:54:10

by Rob Herring (Arm)

[permalink] [raw]
Subject: Re: [PATCH 1/4] dt-bindings: nvmem: Add STM32 factory-programmed romem

On Wed, Jan 30, 2019 at 05:38:53PM +0100, Fabrice Gasnier wrote:
> Add documentation for STMicroelectronics STM32 Factory-programmed
> read only memory area.
>
> Signed-off-by: Fabrice Gasnier <[email protected]>
> ---
> .../devicetree/bindings/nvmem/st,stm32-romem.txt | 31 ++++++++++++++++++++++
> 1 file changed, 31 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/nvmem/st,stm32-romem.txt
>
> diff --git a/Documentation/devicetree/bindings/nvmem/st,stm32-romem.txt b/Documentation/devicetree/bindings/nvmem/st,stm32-romem.txt
> new file mode 100644
> index 0000000..fbff52e
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/nvmem/st,stm32-romem.txt
> @@ -0,0 +1,31 @@
> +STMicroelectronics STM32 Factory-programmed data device tree bindings
> +
> +This represents STM32 Factory-programmed read only non-volatile area: locked
> +flash, OTP, read-only HW regs... This contains various information such as:

Several distinct types here. Does s/w need to know the difference
rather than just one generic-ish compatible? Access size restrictions
maybe? Ability to unlock and program?

If not, then why even make this stm32 specific?

> +analog calibration data for temperature sensor (e.g. TS_CAL1, TS_CAL2),
> +internal vref (VREFIN_CAL), unique device ID...
> +
> +Required properties:
> +- compatible: Should be one of:
> + "st,stm32-romem"
> + "st,stm32mp15-bsec"
> +- reg: Offset and length of factory-programmed area.
> +- #address-cells: Should be '<1>'.
> +- #size-cells: Should be '<1>'.
> +
> +Optional Data cells:
> +- Must be child nodes as described in nvmem.txt.
> +
> +Example on stm32f4:
> + romem: nvmem@1fff7800 {
> + compatible = "st,stm32-romem";
> + reg = <0x1fff7800 0x400>;
> + #address-cells = <1>;
> + #size-cells = <1>;
> +
> + /* Data cells: ts_cal1 at 0x1fff7a2c */
> + ts_cal1: calib@22c {
> + reg = <0x22c 0x2>;
> + };
> + ...
> + };
> --
> 1.9.1
>

2019-02-26 09:16:16

by Fabrice Gasnier

[permalink] [raw]
Subject: Re: [PATCH 1/4] dt-bindings: nvmem: Add STM32 factory-programmed romem

On 2/25/19 5:53 PM, Rob Herring wrote:
> On Wed, Jan 30, 2019 at 05:38:53PM +0100, Fabrice Gasnier wrote:
>> Add documentation for STMicroelectronics STM32 Factory-programmed
>> read only memory area.
>>
>> Signed-off-by: Fabrice Gasnier <[email protected]>
>> ---
>> .../devicetree/bindings/nvmem/st,stm32-romem.txt | 31 ++++++++++++++++++++++
>> 1 file changed, 31 insertions(+)
>> create mode 100644 Documentation/devicetree/bindings/nvmem/st,stm32-romem.txt
>>
>> diff --git a/Documentation/devicetree/bindings/nvmem/st,stm32-romem.txt b/Documentation/devicetree/bindings/nvmem/st,stm32-romem.txt
>> new file mode 100644
>> index 0000000..fbff52e
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/nvmem/st,stm32-romem.txt
>> @@ -0,0 +1,31 @@
>> +STMicroelectronics STM32 Factory-programmed data device tree bindings
>> +
>> +This represents STM32 Factory-programmed read only non-volatile area: locked
>> +flash, OTP, read-only HW regs... This contains various information such as:
>
> Several distinct types here. Does s/w need to know the difference
> rather than just one generic-ish compatible? Access size restrictions
> maybe? Ability to unlock and program?

Hi Rob,

The reading part is represented here as "st,stm32-romem" compatible, to
simply handle read only access. I agree this could be a generic-ish.

BUT the specifics are regarding the ability to unlock/lock and program.
Access size can vary from one part to another (e.g. on stm32f4,
reference manual sates: OTP area is divided into 16 OTP data blocks of
32 bytes. on stm32f7, OTP area is divided into 16 OTP data blocks of 64
bytes.)

In STM32MP15, both the read & write access through the BSEC are
specific, represented by dedicated compatible.

Do you wish I update the compatible to something like:
"st,stm32f4-otp"
"st,stm32mp15-bsec"
?

Thanks for reviewing,
Best regards,
Fabrice

>
> If not, then why even make this stm32 specific?
>
>> +analog calibration data for temperature sensor (e.g. TS_CAL1, TS_CAL2),
>> +internal vref (VREFIN_CAL), unique device ID...
>> +
>> +Required properties:
>> +- compatible: Should be one of:
>> + "st,stm32-romem"
>> + "st,stm32mp15-bsec"
>> +- reg: Offset and length of factory-programmed area.
>> +- #address-cells: Should be '<1>'.
>> +- #size-cells: Should be '<1>'.
>> +
>> +Optional Data cells:
>> +- Must be child nodes as described in nvmem.txt.
>> +
>> +Example on stm32f4:
>> + romem: nvmem@1fff7800 {
>> + compatible = "st,stm32-romem";
>> + reg = <0x1fff7800 0x400>;
>> + #address-cells = <1>;
>> + #size-cells = <1>;
>> +
>> + /* Data cells: ts_cal1 at 0x1fff7a2c */
>> + ts_cal1: calib@22c {
>> + reg = <0x22c 0x2>;
>> + };
>> + ...
>> + };
>> --
>> 1.9.1
>>

2019-02-26 17:59:05

by Rob Herring (Arm)

[permalink] [raw]
Subject: Re: [PATCH 1/4] dt-bindings: nvmem: Add STM32 factory-programmed romem

On Tue, Feb 26, 2019 at 3:14 AM Fabrice Gasnier <[email protected]> wrote:
>
> On 2/25/19 5:53 PM, Rob Herring wrote:
> > On Wed, Jan 30, 2019 at 05:38:53PM +0100, Fabrice Gasnier wrote:
> >> Add documentation for STMicroelectronics STM32 Factory-programmed
> >> read only memory area.
> >>
> >> Signed-off-by: Fabrice Gasnier <[email protected]>
> >> ---
> >> .../devicetree/bindings/nvmem/st,stm32-romem.txt | 31 ++++++++++++++++++++++
> >> 1 file changed, 31 insertions(+)
> >> create mode 100644 Documentation/devicetree/bindings/nvmem/st,stm32-romem.txt
> >>
> >> diff --git a/Documentation/devicetree/bindings/nvmem/st,stm32-romem.txt b/Documentation/devicetree/bindings/nvmem/st,stm32-romem.txt
> >> new file mode 100644
> >> index 0000000..fbff52e
> >> --- /dev/null
> >> +++ b/Documentation/devicetree/bindings/nvmem/st,stm32-romem.txt
> >> @@ -0,0 +1,31 @@
> >> +STMicroelectronics STM32 Factory-programmed data device tree bindings
> >> +
> >> +This represents STM32 Factory-programmed read only non-volatile area: locked
> >> +flash, OTP, read-only HW regs... This contains various information such as:
> >
> > Several distinct types here. Does s/w need to know the difference
> > rather than just one generic-ish compatible? Access size restrictions
> > maybe? Ability to unlock and program?
>
> Hi Rob,
>
> The reading part is represented here as "st,stm32-romem" compatible, to
> simply handle read only access. I agree this could be a generic-ish.
>
> BUT the specifics are regarding the ability to unlock/lock and program.
> Access size can vary from one part to another (e.g. on stm32f4,
> reference manual sates: OTP area is divided into 16 OTP data blocks of
> 32 bytes. on stm32f7, OTP area is divided into 16 OTP data blocks of 64
> bytes.)
>
> In STM32MP15, both the read & write access through the BSEC are
> specific, represented by dedicated compatible.
>
> Do you wish I update the compatible to something like:
> "st,stm32f4-otp"
> "st,stm32mp15-bsec"
> ?

Yes, I think given the above that makes sense. We can always map
specific bindings to generic drivers, but not the reverse.

Rob