Skip to contentSkip to conversation

Add efuse driver for Ingenic JZ4780 SoC

PATCH Superseded Mathieu Malaterre 4 participants 8 messages Dec 27, 2017 – Jan 6, 2018

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Add efuse driver for Ingenic JZ4780 SoC

This patchset bring support for read-only access to the JZ4780 efuse as found on MIPS Creator CI20.

To keep the driver as simple as possible, it was not possible to re-use most of the nvmem core functionalities. This driver is not compatible with the original efuse driver as found in the custom linux kernel from upstream (1), in particular it does not expose to the users neither:
/sys/devices/platform/*/chip_id nor /sys/devices/platform/*/user_id.

The goal of this driver is to provide access to the MAC address to the dm9000 driver.

(1) https://github.com/ZubairLK/CI20_linux/commit/6efd4ffca7dcfaff0794ab60cd6922ce96c60419

Mathieu Malaterre (1):
dts: Probe efuse for CI20

PrasannaKumar Muralidharan (1):
nvmem: add driver for JZ4780 efuse

 .../ABI/testing/sysfs-driver-jz4780-efuse          |  16 ++
 .../bindings/nvmem/ingenic,jz4780-efuse.txt        |  17 ++
 MAINTAINERS                                        |   5 +
 arch/mips/boot/dts/ingenic/jz4780.dtsi             |  40 ++-
 arch/mips/configs/ci20_defconfig                   |   2 +
 drivers/nvmem/Kconfig                              |  10 +
 drivers/nvmem/Makefile                             |   2 +
 drivers/nvmem/jz4780-efuse.c                       | 274 +++++++++++++++++++++
 8 files changed, 354 insertions(+), 12 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-driver-jz4780-efuse
 create mode 100644 Documentation/devicetree/bindings/nvmem/ingenic,jz4780-efuse.txt
 create mode 100644 drivers/nvmem/jz4780-efuse.c
Signature · 6 lines
2.11.0

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#1 lore raw

PATCH 1/2 nvmem: add driver for JZ4780 efuse

From: PrasannaKumar Muralidharan <[email protected]>

This patch brings support for the JZ4780 efuse. Currently it only expose a read only access to the entire 8K bits efuse memory.

---
 .../ABI/testing/sysfs-driver-jz4780-efuse          |  16 ++
 .../bindings/nvmem/ingenic,jz4780-efuse.txt        |  17 ++
 MAINTAINERS                                        |   5 +
 arch/mips/boot/dts/ingenic/jz4780.dtsi             |  40 ++-
 drivers/nvmem/Kconfig                              |  10 +
 drivers/nvmem/Makefile                             |   2 +
 drivers/nvmem/jz4780-efuse.c                       | 274 +++++++++++++++++++++
 7 files changed, 352 insertions(+), 12 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-driver-jz4780-efuse
 create mode 100644 Documentation/devicetree/bindings/nvmem/ingenic,jz4780-efuse.txt
 create mode 100644 drivers/nvmem/jz4780-efuse.c
Documentation/ABI/testing/sysfs-driver-jz4780-efuse new file +16 -0
new file mode 100644
index 000000000000..bb6f5d6ceea0
@@ -0,0 +1,16 @@
+What:		/sys/devices/*/<our-device>/nvmem
+Date:		December 2017
+Contact:	PrasannaKumar Muralidharan <[email protected]>
+Description:	read-only access to the efuse on the Ingenic JZ4780 SoC
+		The SoC has a one time programmable 8K efuse that is
+		split into segments. The driver supports read only.
+		The segments are
+		0x000   64 bit Random Number
+		0x008  128 bit Ingenic Chip ID
+		0x018  128 bit Customer ID
+		0x028 3520 bit Reserved
+		0x1E0    8 bit Protect Segment
+		0x1E1 2296 bit HDMI Key
+		0x300 2048 bit Security boot key
+Users:		any user space application which wants to read the Chip
+		and Customer ID
Documentation/devicetree/bindings/nvmem/ingenic,jz4780-efuse.txt new file +17 -0
new file mode 100644
index 000000000000..cd6d67ec22fc
@@ -0,0 +1,17 @@
+Ingenic JZ EFUSE driver bindings
+
+Required properties:
+- "compatible"		Must be set to "ingenic,jz4780-efuse"
+- "reg"			Register location and length
+- "clocks"		Handle for the ahb clock for the efuse.
+- "clock-names"		Must be "bus_clk"
+
+Example:
+
+efuse: efuse@134100d0 {
+	compatible = "ingenic,jz4780-efuse";
+	reg = <0x134100D0 0xFF>;
+
+	clocks = <&cgu JZ4780_CLK_AHB2>;
+	clock-names = "bus_clk";
+};
MAINTAINERS +5 -0
index a6e86e20761e..7a050c20c533 100644
@@ -6902,6 +6902,11 @@ M:	Zubair Lutfullah Kakakhel <[email protected]>
 S:	Maintained
 F:	drivers/dma/dma-jz4780.c
 
+INGENIC JZ4780 EFUSE Driver
+M:	PrasannaKumar Muralidharan <[email protected]>
+S:	Maintained
+F:	drivers/nvmem/jz4780-efuse.c
+
 INGENIC JZ4780 NAND DRIVER
 M:	Harvey Hunt <[email protected]>
 L:	[email protected]
arch/mips/boot/dts/ingenic/jz4780.dtsi +28 -12
index 9b5794667aee..3fb9d916a2ea 100644
@@ -224,21 +224,37 @@
 		reg = <0x10002000 0x100>;
 	};
 
-	nemc: nemc@13410000 {
-		compatible = "ingenic,jz4780-nemc";
-		reg = <0x13410000 0x10000>;
-		#address-cells = <2>;
+
+	ahb2: ahb2 {
+		compatible = "simple-bus";
+		#address-cells = <1>;
 		#size-cells = <1>;
-		ranges = <1 0 0x1b000000 0x1000000
-			  2 0 0x1a000000 0x1000000
-			  3 0 0x19000000 0x1000000
-			  4 0 0x18000000 0x1000000
-			  5 0 0x17000000 0x1000000
-			  6 0 0x16000000 0x1000000>;
+		ranges = <>;
+
+		nemc: nemc@13410000 {
+			compatible = "ingenic,jz4780-nemc";
+			reg = <0x13410000 0x10000>;
+			#address-cells = <2>;
+			#size-cells = <1>;
+			ranges = <1 0 0x1b000000 0x1000000
+				  2 0 0x1a000000 0x1000000
+				  3 0 0x19000000 0x1000000
+				  4 0 0x18000000 0x1000000
+				  5 0 0x17000000 0x1000000
+				  6 0 0x16000000 0x1000000>;
+
+			clocks = <&cgu JZ4780_CLK_NEMC>;
+
+			status = "disabled";
+		};
 
-		clocks = <&cgu JZ4780_CLK_NEMC>;
+		efuse: efuse@134100d0 {
+			compatible = "ingenic,jz4780-efuse";
+			reg = <0x134100d0 0xff>;
 
-		status = "disabled";
+			clocks = <&cgu JZ4780_CLK_AHB2>;
+			clock-names = "bus_clk";
+		};
 	};
 
 	bch: bch@134d0000 {
drivers/nvmem/Kconfig +10 -0
index ff505af064ba..75400982abac 100644
@@ -36,6 +36,16 @@ config NVMEM_IMX_OCOTP
 	  This driver can also be built as a module. If so, the module
 	  will be called nvmem-imx-ocotp.
 
+config JZ4780_EFUSE
+	tristate "JZ4780 EFUSE Memory Support"
+	depends on MACH_JZ4780 || COMPILE_TEST
+	depends on HAS_IOMEM
+	help
+	  Say Y here to include support for JZ4780 efuse memory found on
+	  all JZ4780 SoC based devices.
+	  To compile this driver as a module, choose M here: the module
+	  will be called nvmem_jz4780_efuse.
+
 config NVMEM_LPC18XX_EEPROM
 	tristate "NXP LPC18XX EEPROM Memory Support"
 	depends on ARCH_LPC18XX || COMPILE_TEST
drivers/nvmem/Makefile +2 -0
index e54dcfa6565a..3b7c18df6771 100644
@@ -13,6 +13,8 @@ obj-$(CONFIG_NVMEM_IMX_IIM)	+= nvmem-imx-iim.o
 nvmem-imx-iim-y			:= imx-iim.o
 obj-$(CONFIG_NVMEM_IMX_OCOTP)	+= nvmem-imx-ocotp.o
 nvmem-imx-ocotp-y		:= imx-ocotp.o
+obj-$(CONFIG_JZ4780_EFUSE)		+= nvmem_jz4780_efuse.o
+nvmem_jz4780_efuse-y		:= jz4780-efuse.o
 obj-$(CONFIG_NVMEM_LPC18XX_EEPROM)	+= nvmem_lpc18xx_eeprom.o
 nvmem_lpc18xx_eeprom-y	:= lpc18xx_eeprom.o
 obj-$(CONFIG_NVMEM_LPC18XX_OTP)	+= nvmem_lpc18xx_otp.o
drivers/nvmem/jz4780-efuse.c new file +274 -0

274 lines not on this page · raw message

Signature · 6 lines
2.11.0

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#6 lore raw

PATCH 2/2 dts: Probe efuse for CI20

In reply to Mathieu Malaterre
---
 arch/mips/configs/ci20_defconfig | 2 ++
 1 file changed, 2 insertions(+)
arch/mips/configs/ci20_defconfig +2 -0
index b5f4ad8f2c45..62c63617e97a 100644
@@ -171,3 +171,5 @@ CONFIG_STACKTRACE=y
 # CONFIG_FTRACE is not set
 CONFIG_CMDLINE_BOOL=y
 CONFIG_CMDLINE="earlycon console=ttyS4,115200 clk_ignore_unused"
+CONFIG_NVMEM=y
+CONFIG_JZ4780_EFUSE=y
Signature · 6 lines
2.11.0

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw

Re: [PATCH 1/2] nvmem: add driver for JZ4780 efuse

In reply to Mathieu Malaterre

Hi Mathieu, PrasannaKumar,

Quoted 17 lines · Mathieu Malaterre

From: PrasannaKumar Muralidharan <[email protected]>

This patch brings support for the JZ4780 efuse. Currently it only expose a read only access to the entire 8K bits efuse memory.

---

drivers/nvmem/jz4780-efuse.c new file +8 -0
+
+/* main entry point */
+static int jz4780_efuse_read(void *context, unsigned int offset,
+					void *val, size_t bytes)
+{
+	static const int nsegments = sizeof(segments) / sizeof(*segments);
+	struct jz4780_efuse *efuse = context;
+	char buf[32];

drivers/nvmem/jz4780-efuse.c line 172

Quoted 10 lines
drivers/nvmem/jz4780-efuse.c new file +10 -0
+	char *cur = val;
+	int i;
+	/* PM recommends read/write each segment separately */
+	for (i = 0; i < nsegments; ++i) {
+		unsigned int *segment = segments[i];
+		unsigned int lpos = segment[0];
+		unsigned int buflen = segment[1] / 8;
+		unsigned int ncount = buflen / 32;
+		unsigned int remain = buflen % 32;
+		int j;

This doesn't look right, as offset & bytes are completely ignored. This means it will return data from an offset other than requested and may also overrun the provided output buffer?

Quoted 6 lines
drivers/nvmem/jz4780-efuse.c new file +6 -0
+		/* EFUSE can read or write maximum 256bit in each time */
+		for (j = 0; j < ncount ; ++j) {
+			jz4780_efuse_read_32bytes(efuse, buf, lpos);
+			memcpy(cur, buf, sizeof(buf));
+			cur += sizeof(buf);
+			lpos += sizeof(buf);

drivers/nvmem/jz4780-efuse.c line 188

Quoted 10 lines
drivers/nvmem/jz4780-efuse.c new file +10 -0
+			}
+		if (remain) {
+			jz4780_efuse_read_32bytes(efuse, buf, lpos);
+			memcpy(cur, buf, remain);
+			cur += remain;
+			}
+		}
+
+	return 0;
+}

Marcin

#3 lore raw

Re: [PATCH 1/2] nvmem: add driver for JZ4780 efuse

Hi Marcin,

Quoted 14 lines · Marcin Nowakowski

Hi Mathieu, PrasannaKumar,

Quoted 9 lines · Mathieu Malaterre

From: PrasannaKumar Muralidharan <[email protected]>

This patch brings support for the JZ4780 efuse. Currently it only expose a read only access to the entire 8K bits efuse memory.

---

Quoted 6 lines

Review

Quoted 6 lines
(quoted diff) +6 -0
+
+/* main entry point */
+static int jz4780_efuse_read(void *context, unsigned int offset,
+                                       void *val, size_t bytes)
+{
+       static const int nsegments = sizeof(segments) /

sizeof(*segments);

Quoted 14 lines

Review

Quoted 12 lines
(quoted diff) +12 -0
+       struct jz4780_efuse *efuse = context;
+       char buf[32];
+       char *cur = val;
+       int i;
+       /* PM recommends read/write each segment separately */
+       for (i = 0; i < nsegments; ++i) {
+               unsigned int *segment = segments[i];
+               unsigned int lpos = segment[0];
+               unsigned int buflen = segment[1] / 8;
+               unsigned int ncount = buflen / 32;
+               unsigned int remain = buflen % 32;
+               int j;
Quoted 3 lines

This doesn't look right, as offset & bytes are completely ignored. This means it will return data from an offset other than requested and may also overrun the provided output buffer?

Thanks for the review ! That was the part of nvmem framework I was not totally clear. Let say I want to expose only a portion of efuse space, eg:

(quoted diff) +0 -0

b/arch/mips/boot/dts/ingenic/jz4780.dtsi
index 2f26922718559..44d97c06a6d15 100644

arch/mips/boot/dts/ingenic/jz4780.dtsi +9 -0
@@ -299,6 +299,15 @@
 
  clocks = <&cgu JZ4780_CLK_AHB2>;
  clock-names = "bus_clk";
+
+ #address-cells = <1>;
+ #size-cells = <1>;
+
+ eth_mac: eth_mac@12 {
+ /* six byte/48bit MAC address stored as 8-bit integers */
+ reg = <0x12 0x6>;
+ };
+
  };
  };
 

What should I do to expose that chunk only in the user space ?

Quoted 13 lines
Quoted 13 lines
(quoted diff) +12 -0
+               /* EFUSE can read or write maximum 256bit in each time */
+               for (j = 0; j < ncount ; ++j) {
+                       jz4780_efuse_read_32bytes(efuse, buf, lpos);
+                       memcpy(cur, buf, sizeof(buf));
+                       cur += sizeof(buf);
+                       lpos += sizeof(buf);
+                       }
+               if (remain) {
+                       jz4780_efuse_read_32bytes(efuse, buf, lpos);
+                       memcpy(cur, buf, remain);
+                       cur += remain;
+                       }
Quoted 9 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+               }
+
+       return 0;
+}

Marcin

-M

#4 lore raw

Re: [PATCH 1/2] nvmem: add driver for JZ4780 efuse

Hi Mathieu,

Quoted 41 lines · Mathieu Malaterre

Hi Marcin,

Quoted 5 lines · On Thu, Dec 28, 2017 at 8:13 AM, Marcin Nowakowski…

Hi Mathieu, PrasannaKumar,

Quoted 2 lines · Mathieu Malaterre

From: PrasannaKumar Muralidharan <[email protected]

<mailto:[email protected]>>

Quoted 5 lines
Quoted 5 lines

This patch brings support for the JZ4780 efuse. Currently it only expose a read only access to the entire 8K bits efuse memory.

<mailto:[email protected]>>

Quoted 1 line
Quoted 1 line
Signed-off-by PrasannaKumar Muralidharan

<[email protected] <mailto:[email protected]>>

Quoted 9 lines

Review

Quoted 9 lines

---

(quoted diff) +6 -0
+
+/* main entry point */
+static int jz4780_efuse_read(void *context, unsigned int offset,
+                                       void *val, size_t bytes)
+{
+       static const int nsegments = sizeof(segments) / 

sizeof(*segments);

Quoted 14 lines
Quoted 12 lines

+       struct jz4780_efuse *efuse = context;
+       char buf[32];
+       char *cur = val;
+       int i;
+       /* PM recommends read/write each segment separately */
+       for (i = 0; i < nsegments; ++i) {
+               unsigned int *segment = segments[i];
+               unsigned int lpos = segment[0];
+               unsigned int buflen = segment[1] / 8;
+               unsigned int ncount = buflen / 32;
+               unsigned int remain = buflen % 32;
+               int j;

Quoted 7 lines
Quoted 2 lines

This doesn't look right, as offset & bytes are completely ignored. This means it will return data from an offset other than requested and may

also

Quoted 1 line

overrun the provided output buffer?

Thanks for the review ! That was the part of nvmem framework I was not totally clear. Let say I want to expose only a portion of efuse space, eg:

Do you need to expose this to the userspace or to other drivers only? For the second case have a look at the description of nvmem cell interface.

Quoted 18 lines
arch/mips/boot/dts/ingenic/jz4780.dtsi +9 -0
index 2f26922718559..44d97c06a6d15 100644
@@ -299,6 +299,15 @@
 clocks = <&cgu JZ4780_CLK_AHB2>;
 clock-names = "bus_clk";
+
+#address-cells = <1>;
+#size-cells = <1>;
+
+eth_mac: eth_mac@12 {
+/* six byte/48bit MAC address stored as 8-bit integers */
+reg = <0x12 0x6>;
+};
+
 };
 };
Quoted 1 line

What should I do to expose that chunk only in the user space ?

The nvmem interface's userspace interface (via /sys/.../nvmem) provides access to the complete device raw memory so the only way to achieve that would be to parse the devicetree description in your driver and only register part of the memory with the nvmem driver - but that would be a slight abuse of the interface. The nvmem devicetree binding document shows clearly how to define the cell interface that can later be used by any consumer - that way you could have the ethernet driver access the cell directly. However, as the dm9000 driver isn't designed to do that and this is a SoC-specific extention, I don't know how it fits with the general eth driver design ...

Potentially a good and useful compromise would be to have all of the cell regs exposed via /sys/.../nvmem-cellname file (or something similar), but this is not currently supported and I don't know what the view of nvmem maintainers on adding such extension would be.

Quoted 18 lines
Quoted 2 lines
Quoted 2 lines

+               /* EFUSE can read or write maximum 256bit in each

time */

Quoted 7 lines
Quoted 7 lines

+               for (j = 0; j < ncount ; ++j) {
+                       jz4780_efuse_read_32bytes(efuse, buf, lpos);
+                       memcpy(cur, buf, sizeof(buf));
+                       cur += sizeof(buf);
+                       lpos += sizeof(buf);
+                       }
+               if (remain) {

Quoted 8 lines

Review

Quoted 8 lines

+                       jz4780_efuse_read_32bytes(efuse, buf, lpos);
+                       memcpy(cur, buf, remain);
+                       cur += remain;
+                       }
+               }

(quoted diff) +3 -0
+
+       return 0;
+}

Regardless of the choices above, you still always have to make sure in your reg_read method that you only read from the offset specified in method arguments and never return more than 'bytes' of data requested.

Marcin
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw

Re: [PATCH 1/2] nvmem: add driver for JZ4780 efuse

Hi Marcin,

Quoted 94 lines · Marcin Nowakowski

Hi Mathieu,

Quoted 44 lines · Mathieu Malaterre

Hi Marcin,

Quoted 5 lines · On Thu, Dec 28, 2017 at 8:13 AM, Marcin Nowakowski…

Hi Mathieu, PrasannaKumar,

Quoted 2 lines · Mathieu Malaterre

From: PrasannaKumar Muralidharan <[email protected]

<mailto:[email protected]>>

Quoted 2 lines
Quoted 2 lines

This patch brings support for the JZ4780 efuse. Currently it only

expose

Quoted 3 lines
Quoted 3 lines

a read only access to the entire 8K bits efuse memory.

<mailto:[email protected]>>

Quoted 1 line
Quoted 1 line

<mailto:[email protected]>>

Quoted 9 lines

Review

Quoted 9 lines

---

(quoted diff) +6 -0
+
+/* main entry point */
+static int jz4780_efuse_read(void *context, unsigned int offset,
+                                       void *val, size_t bytes)
+{
+       static const int nsegments = sizeof(segments) /

sizeof(*segments);

Quoted 14 lines
Quoted 12 lines
(quoted diff) +12 -0
+       struct jz4780_efuse *efuse = context;
+       char buf[32];
+       char *cur = val;
+       int i;
+       /* PM recommends read/write each segment separately */
+       for (i = 0; i < nsegments; ++i) {
+               unsigned int *segment = segments[i];
+               unsigned int lpos = segment[0];
+               unsigned int buflen = segment[1] / 8;
+               unsigned int ncount = buflen / 32;
+               unsigned int remain = buflen % 32;
+               int j;
Quoted 8 lines
Quoted 2 lines

This doesn't look right, as offset & bytes are completely ignored. This means it will return data from an offset other than requested and may

also

Quoted 1 line

overrun the provided output buffer?

Thanks for the review ! That was the part of nvmem framework I was not totally clear. Let say I want to expose only a portion of efuse space, eg:

Do you need to expose this to the userspace or to other drivers only? For the second case have a look at the description of nvmem cell interface.

Quoted 19 lines
arch/mips/boot/dts/ingenic/jz4780.dtsi +9 -0
index 2f26922718559..44d97c06a6d15 100644
@@ -299,6 +299,15 @@
 clocks = <&cgu JZ4780_CLK_AHB2>;
 clock-names = "bus_clk";
+
+#address-cells = <1>;
+#size-cells = <1>;
+
+eth_mac: eth_mac@12 {
+/* six byte/48bit MAC address stored as 8-bit integers */
+reg = <0x12 0x6>;
+};
+
 };
 };
Quoted 1 line

What should I do to expose that chunk only in the user space ?

The nvmem interface's userspace interface (via /sys/.../nvmem) provides access to the complete device raw memory so the only way to achieve that would be to parse the devicetree description in your driver and only register part of the memory with the nvmem driver - but that would be a slight abuse of the interface.
The nvmem devicetree binding document shows clearly how to define the cell interface that can later be used by any consumer - that way you could have the ethernet driver access the cell directly. However, as the dm9000 driver isn't designed to do that and this is a SoC-specific extention, I don't know how it fits with the general eth driver design ...

Quoted 4 lines

Potentially a good and useful compromise would be to have all of the cell regs exposed via /sys/.../nvmem-cellname file (or something similar), but this is not currently supported and I don't know what the view of nvmem maintainers on adding such extension would be.

Currently exposing MAC address is necessary. No need to worry about user space stuff for now.

Quoted 20 lines
Quoted 18 lines
Quoted 2 lines
Quoted 2 lines

+ /* EFUSE can read or write maximum 256bit in each time

*/

Quoted 7 lines
Quoted 7 lines
(quoted diff) +7 -0
+               for (j = 0; j < ncount ; ++j) {
+                       jz4780_efuse_read_32bytes(efuse, buf, lpos);
+                       memcpy(cur, buf, sizeof(buf));
+                       cur += sizeof(buf);
+                       lpos += sizeof(buf);
+                       }
+               if (remain) {
Quoted 8 lines

Review

Quoted 8 lines
(quoted diff) +8 -0
+                       jz4780_efuse_read_32bytes(efuse, buf, lpos);
+                       memcpy(cur, buf, remain);
+                       cur += remain;
+                       }
+               }
+
+       return 0;
+}
Quoted 3 lines

Regardless of the choices above, you still always have to make sure in your reg_read method that you only read from the offset specified in method arguments and never return more than 'bytes' of data requested.

Sure, will do that.

Regards,
PrasannaKumar
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html