rockchip,otp: Support for RK3528, RK3562 and RK3568
Subsystems (3)
Heiko Stuebner
maintainerv4 cover rockchip,otp: Support for RK3528, RK3562 and RK3568
This is a continuation of Kever's from april 2025 [0] - hence the v4 The original patches seem to have fallen through the cracks.
Additionally this directly inclues the interal word-size patch [1], that was previously listed as an external dependency.
And finally meanwhile patches for the RK3528 SoC from Jonas have appeared, so I've included those too, to get the support for all not-yet supported SoCs done
Changes in v4:
- rebase onto 6.18-rc8 - the rockchip-otp driver did no receive additional comments in the meantime
- include the dependency patch about word-sizes
- add support for RK3528
Changes in v3:
- update the clock name from "usr" to "otp" and re-order to sync with other soc.
- rebase on rk3576 and rk3528, changes suggest by Jonas
- Use rk3568 data structure for rk3562
Changes in v2:
- Update the commit message and add maxItems in schema.
[0] https://patch.msgid.link/[email protected]
[1] https://patch.msgid.link/[email protected]
Finley Xiao (2):
nvmem: rockchip-otp: Add support for RK3568
nvmem: rockchip-otp: Add support for RK3562
Jonas Karlman (3):
dt-bindings: nvmem: rockchip,otp: Add compatible for RK3528
nvmem: rockchip-otp: Handle internal word_size in main reg_read op
nvmem: rockchip-otp: Add support for RK3528
Kever Yang (1):
dt-bindings: nvmem: rockchip,otp: Add support for RK3562 and RK3568
.../bindings/nvmem/rockchip,otp.yaml | 83 +++++++-- drivers/nvmem/rockchip-otp.c | 161 ++++++++++++++---- 2 files changed, 202 insertions(+), 42 deletions(-)
Signature · 1 line
2.47.2
Heiko Stuebner
maintainerPATCH v4 1/6 dt-bindings: nvmem: rockchip,otp: Add support for RK3562 and RK3568
From: Kever Yang <[email protected]>
Add compatible entry for the otp controller in RK3562 and RK3568, add schema for different clock names for new entry.
--- .../bindings/nvmem/rockchip,otp.yaml | 58 +++++++++++++++---- 1 file changed, 48 insertions(+), 10 deletions(-)
Documentation/devicetree/bindings/nvmem/rockchip,otp.yaml +48 -10
@@ -14,6 +14,8 @@ properties: enum: - rockchip,px30-otp - rockchip,rk3308-otp + - rockchip,rk3562-otp + - rockchip,rk3568-otp - rockchip,rk3576-otp - rockchip,rk3588-otp
@@ -26,19 +28,15 @@ properties: clock-names: minItems: 3 - items: - - const: otp - - const: apb_pclk - - const: phy - - const: arb + maxItems: 4 resets: minItems: 1 - maxItems: 3 + maxItems: 4 reset-names: minItems: 1 - maxItems: 3 + maxItems: 4 required: - compatible
@@ -64,13 +62,44 @@ allOf: clocks: maxItems: 3 clock-names: - maxItems: 3 + items: + - const: otp + - const: apb_pclk + - const: phy resets: maxItems: 1 reset-names: items: - const: phy + - if: + properties: + compatible: + contains: + enum: + - rockchip,rk3562-otp + - rockchip,rk3568-otp + then: + properties: + clocks: + minItems: 4 + maxItems: 4 + clock-names: + items: + - const: otp + - const: apb_pclk + - const: phy + - const: sbpi + resets: + minItems: 4 + maxItems: 4 + reset-names: + items: + - const: otp + - const: apb + - const: phy + - const: sbpi + - if: properties: compatible:
@@ -82,7 +111,10 @@ allOf: clocks: maxItems: 3 clock-names: - maxItems: 3 + items: + - const: otp + - const: apb_pclk + - const: phy resets: minItems: 2 maxItems: 2
@@ -101,10 +133,16 @@ allOf: properties: clocks: minItems: 4 + maxItems: 4 clock-names: - minItems: 4 + items: + - const: otp + - const: apb_pclk + - const: phy + - const: arb resets: minItems: 3 + maxItems: 3 reset-names: items: - const: otp
Signature · 1 line
2.47.2
Heiko Stuebner
maintainerPATCH v4 2/6 dt-bindings: nvmem: rockchip,otp: Add compatible for RK3528
In reply to Heiko StuebnerFrom: Jonas Karlman <[email protected]>
Add compatible string for the OTP controller in RK3528. Compared to the RK3562 and RK3568 the OTP in RK3528 does not have a phy clock or reset.
--- .../bindings/nvmem/rockchip,otp.yaml | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+)
Documentation/devicetree/bindings/nvmem/rockchip,otp.yaml +25 -0
@@ -14,6 +14,7 @@ properties: enum: - rockchip,px30-otp - rockchip,rk3308-otp + - rockchip,rk3528-otp - rockchip,rk3562-otp - rockchip,rk3568-otp - rockchip,rk3576-otp
@@ -72,6 +73,30 @@ allOf: items: - const: phy + - if: + properties: + compatible: + contains: + enum: + - rockchip,rk3528-otp + then: + properties: + clocks: + maxItems: 3 + clock-names: + items: + - const: otp + - const: apb_pclk + - const: sbpi + resets: + minItems: 3 + maxItems: 3 + reset-names: + items: + - const: otp + - const: apb + - const: sbpi + - if: properties: compatible:
Signature · 1 line
2.47.2
Re: [PATCH v4 2/6] dt-bindings: nvmem: rockchip,otp: Add compatible for RK3528
Quoted 11 lines · Heiko Stuebner
From: Jonas Karlman <[email protected]>
Add compatible string for the OTP controller in RK3528. Compared to the RK3562 and RK3568 the OTP in RK3528 does not have a phy clock or reset.
Signed-off-by Jonas Karlman <[email protected]>Signed-off-by Heiko Stuebner <[email protected]>--- .../bindings/nvmem/rockchip,otp.yaml | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+)
Heiko Stuebner
maintainerPATCH v4 3/6 nvmem: rockchip-otp: Handle internal word_size in main reg_read op
In reply to Heiko StuebnerFrom: Jonas Karlman <[email protected]>
Rockchip SoCs RK3576 and RK3588 read data from the OTP using 32-bit words instead of normal 8-bit bytes. Similar RK3506, RK3528, RK3562 and RK3568 will read data from OTP using 16-bit words.
The nvmem core stride and word_size cannot fully be used as cells is not always aligned. Continue to report a stride=1 and word_size=1 in nvmem_config and instead handle use of SoC specific word_size internally in the driver.
Move current SoC specific word_size handling from the RK3588 read_reg operation to the main read_reg operation to help simplify the SoC specific read_reg operation and allow code reuse in a future RK3568 reg_read operation.
--- drivers/nvmem/rockchip-otp.c | 72 ++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 32 deletions(-)
drivers/nvmem/rockchip-otp.c +40 -32
@@ -59,7 +59,6 @@#define RK3588_OTPC_AUTO_EN 0x08#define RK3588_OTPC_INT_ST 0x84#define RK3588_OTPC_DOUT0 0x20 -#define RK3588_NBYTES 4#define RK3588_BURST_NUM 1#define RK3588_BURST_SHIFT 8#define RK3588_ADDR_SHIFT 16
@@ -69,6 +68,7 @@struct rockchip_data {int size;int read_offset; +int word_size;const char *const *clks;int num_clks;nvmem_reg_read_t reg_read;
@@ -185,48 +185,28 @@ static int px30_otp_read(void *context, unsigned int offset, }static int rk3588_otp_read (void *context,unsigned int offset, -void *val,size_t bytes) +void *val,size_t count) {struct rockchip_otp *otp = context; -unsigned int addr_start, addr_end, addr_len; -int ret, i =0 ; -u32 data; -u8 *buf; - - addr_start =round_down (offset,RK3588_NBYTES ) /RK3588_NBYTES ; - addr_end =round_up (offset + bytes,RK3588_NBYTES ) /RK3588_NBYTES ; - addr_len = addr_end - addr_start; - addr_start += otp->data->read_offset /RK3588_NBYTES ; - - buf =kzalloc (array_size (addr_len,RK3588_NBYTES ),GFP_KERNEL ); -if (!buf) -return -ENOMEM ; +u32 *buf = val; +int ret; -while (addr_len--) { -writel ((addr_start <<RK3588_ADDR_SHIFT ) | +while (count--) { +writel ((offset++ <<RK3588_ADDR_SHIFT ) | (RK3588_BURST_NUM <<RK3588_BURST_SHIFT ), otp->base +RK3588_OTPC_AUTO_CTRL );writel (RK3588_AUTO_EN , otp->base +RK3588_OTPC_AUTO_EN ); ret =rockchip_otp_wait_status (otp,RK3588_OTPC_INT_ST ,RK3588_RD_DONE ); -if (ret <0 ) { +if (ret) {dev_err (otp->dev,"timeout during read setup\n" ); - goto read_end; +return ret; } - data =readl (otp->base +RK3588_OTPC_DOUT0 ); -memcpy (&buf[i], &data,RK3588_NBYTES ); - - i +=RK3588_NBYTES ; - addr_start++; + *buf++ =readl (otp->base +RK3588_OTPC_DOUT0 ); } -memcpy (val, buf + offset %RK3588_NBYTES , bytes); - -read_end: -kfree (buf); -return ret; }
@@ -234,7 +214,7 @@ static int rockchip_otp_read(void *context, unsigned int offset, void *val, size_t bytes) {struct rockchip_otp *otp = context; -int ret; +int ret, word_size;if (!otp->data || !otp->data->reg_read)return -EINVAL ;
@@ -245,8 +225,34 @@ static int rockchip_otp_read(void *context, unsigned int offset,return ret; } - ret = otp->data->reg_read (context, offset, val, bytes); + offset += otp->data->read_offset; + word_size = otp->data->word_size; + +if (word_size >1 ) { +unsigned int addr_start, addr_end; +size_t count; +u8 *buf; + + addr_start = offset / word_size; + addr_end =DIV_ROUND_UP (offset + bytes, word_size); + count = addr_end - addr_start; + + buf =kzalloc (array_size (count, word_size),GFP_KERNEL ); +if (!buf) { + ret = -ENOMEM ; + goto err; + } + + ret = otp->data->reg_read (context, addr_start, buf, count); +if (!ret) +memcpy (val, buf + (offset % word_size), bytes); + +kfree (buf); + }else { + ret = otp->data->reg_read (context, offset, val, bytes); + } +err:clk_bulk_disable_unprepare (otp->data->num_clks, otp->clks);return ret;
@@ -259,7 +265,7 @@ static struct nvmem_config otp_config = { .type = NVMEM_TYPE_OTP, .read_only = true, .stride = 1, - .word_size = 1, + .word_size = sizeof(u8), .reg_read = rockchip_otp_read, };
@@ -277,6 +283,7 @@ static const struct rockchip_data px30_data = {static const struct rockchip_data rk3576_data = { .size =0x100 , .read_offset =0x700 , + .word_size =sizeof (u32), .clks = px30_otp_clocks, .num_clks =ARRAY_SIZE (px30_otp_clocks), .reg_read = rk3588_otp_read,
@@ -289,6 +296,7 @@ static const char * const rk3588_otp_clocks[] = {static const struct rockchip_data rk3588_data = { .size =0x400 , .read_offset =0xc00 , + .word_size =sizeof (u32), .clks = rk3588_otp_clocks, .num_clks =ARRAY_SIZE (rk3588_otp_clocks), .reg_read = rk3588_otp_read,
Signature · 1 line
2.47.2
Heiko Stuebner
maintainerPATCH v4 4/6 nvmem: rockchip-otp: Add support for RK3568
In reply to Heiko StuebnerFrom: Finley Xiao <[email protected]>
This adds the necessary data for handling otp the rk3568.
--- drivers/nvmem/rockchip-otp.c | 69 ++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+)
drivers/nvmem/rockchip-otp.c +69 -0
@@ -27,6 +27,7 @@#define OTPC_USER_CTRL 0x0100#define OTPC_USER_ADDR 0x0104#define OTPC_USER_ENABLE 0x0108 +#define OTPC_USER_QP 0x0120#define OTPC_USER_Q 0x0124#define OTPC_INT_STATUS 0x0304#define OTPC_SBPI_CMD0_OFFSET 0x1000
@@ -184,6 +185,58 @@ static int px30_otp_read(void *context, unsigned int offset,return ret; } +static int rk3568_otp_read (void *context,unsigned int offset,void *val, +size_t count) +{ +struct rockchip_otp *otp = context; +u16 *buf = val; +u32 otp_qp; +int ret; + + ret =rockchip_otp_reset (otp); +if (ret) { +dev_err (otp->dev,"failed to reset otp phy\n" ); +return ret; + } + + ret =rockchip_otp_ecc_enable (otp, true); +if (ret) { +dev_err (otp->dev,"rockchip_otp_ecc_enable err\n" ); +return ret; + } + +writel (OTPC_USE_USER |OTPC_USE_USER_MASK , otp->base +OTPC_USER_CTRL ); +udelay (5 ); + +while (count--) { +writel (offset++ |OTPC_USER_ADDR_MASK , + otp->base +OTPC_USER_ADDR ); +writel (OTPC_USER_FSM_ENABLE |OTPC_USER_FSM_ENABLE_MASK , + otp->base +OTPC_USER_ENABLE ); + + ret =rockchip_otp_wait_status (otp,OTPC_INT_STATUS , +OTPC_USER_DONE ); +if (ret) { +dev_err (otp->dev,"timeout during read setup\n" ); + goto read_end; + } + + otp_qp =readl (otp->base +OTPC_USER_QP ); +if (((otp_qp &0xc0 ) ==0xc0 ) || (otp_qp &0x20 )) { + ret = -EIO ; +dev_err (otp->dev,"ecc check error during read setup\n" ); + goto read_end; + } + + *buf++ =readl (otp->base +OTPC_USER_Q ); + } + +read_end: +writel (0x0 |OTPC_USE_USER_MASK , otp->base +OTPC_USER_CTRL ); + +return ret; +} +static int rk3588_otp_read (void *context,unsigned int offset,void *val,size_t count) {
@@ -280,6 +333,18 @@ static const struct rockchip_data px30_data = { .reg_read = px30_otp_read, }; +static const char *const rk3568_otp_clocks[] = { +"otp" ,"apb_pclk" ,"phy" ,"sbpi" , +}; + +static const struct rockchip_data rk3568_data = { + .size =0x80 , + .word_size =sizeof (u16), + .clks = rk3568_otp_clocks, + .num_clks =ARRAY_SIZE (rk3568_otp_clocks), + .reg_read = rk3568_otp_read, +}; +static const struct rockchip_data rk3576_data = { .size =0x100 , .read_offset =0x700 ,
@@ -311,6 +376,10 @@ static const struct of_device_id rockchip_otp_match[] = { .compatible = "rockchip,rk3308-otp", .data = &px30_data, }, + { + .compatible = "rockchip,rk3568-otp", + .data = &rk3568_data, + }, { .compatible = "rockchip,rk3576-otp", .data = &rk3576_data,
Signature · 1 line
2.47.2
Heiko Stuebner
maintainerPATCH v4 5/6 nvmem: rockchip-otp: Add support for RK3562
In reply to Heiko StuebnerFrom: Finley Xiao <[email protected]>
This adds the necessary data for handling otp on the rk3562.
--- drivers/nvmem/rockchip-otp.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/nvmem/rockchip-otp.c +4 -0
@@ -376,6 +376,10 @@ static const struct of_device_id rockchip_otp_match[] = { .compatible = "rockchip,rk3308-otp", .data = &px30_data, }, + { + .compatible = "rockchip,rk3562-otp", + .data = &rk3568_data, + }, { .compatible = "rockchip,rk3568-otp", .data = &rk3568_data,
Signature · 1 line
2.47.2
Heiko Stuebner
maintainerPATCH v4 6/6 nvmem: rockchip-otp: Add support for RK3528
In reply to Heiko StuebnerFrom: Jonas Karlman <[email protected]>
Add support for the OTP controller in RK3528. The OTPC is similar to the OTPC in RK3562 and RK3568, exept for a missing phy clock and reset.
--- drivers/nvmem/rockchip-otp.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
drivers/nvmem/rockchip-otp.c +16 -0
@@ -333,6 +333,18 @@ static const struct rockchip_data px30_data = { .reg_read = px30_otp_read, }; +static const char *const rk3528_otp_clocks[] = { +"otp" ,"apb_pclk" ,"sbpi" , +}; + +static const struct rockchip_data rk3528_data = { + .size =0x80 , + .word_size =sizeof (u16), + .clks = rk3528_otp_clocks, + .num_clks =ARRAY_SIZE (rk3528_otp_clocks), + .reg_read = rk3568_otp_read, +}; +static const char *const rk3568_otp_clocks[] = {"otp" ,"apb_pclk" ,"phy" ,"sbpi" , };
@@ -376,6 +388,10 @@ static const struct of_device_id rockchip_otp_match[] = { .compatible = "rockchip,rk3308-otp", .data = &px30_data, }, + { + .compatible = "rockchip,rk3528-otp", + .data = &rk3528_data, + }, { .compatible = "rockchip,rk3562-otp", .data = &rk3568_data,
Signature · 1 line
2.47.2
Re: [PATCH v4 6/6] nvmem: rockchip-otp: Add support for RK3528
Hi Heiko,
Quoted 7 lines · Heiko Stuebner
From: Jonas Karlman <[email protected]>
Add support for the OTP controller in RK3528. The OTPC is similar to the OTPC in RK3562 and RK3568, exept for a missing phy clock and reset.
Signed-off-by Jonas Karlman <[email protected]>Signed-off-by Heiko Stuebner <[email protected]>
This time I'm making sure to respond to the right patch :-)
I applied your series on top of latest master and booted it on my E20C (rk3528-based). It provides me with entries in which I can read values, like when I applied Jonas' patch on 6.17, so I guess that it's OK:
# for i in /sys/devices/platform/soc/*/rockchip-otp0/cells/*; do echo ${i##*/}:;hexdump $i;done
cpu-code@2,0:
0000000 2835
0000002
cpu-leakage@1a,0:
0000000 000e
0000001
cpu-version@8,3:
0000000 0001
0000001
gpu-leakage@1c,0:
0000000 0003
0000001
id@a,0:
0000000 4e54 5532 3433 0000 0000 0000 0800 112d
0000010
logic-leakage@1b,0:
0000000 0017
0000001
tsadc-trim@44,0:
0000000 0200
0000002So feel free to add this if you want:
Willy
Quoted 11 lines · Heiko Stuebner
This is a continuation of Kever's from april 2025 [0] - hence the v4 The original patches seem to have fallen through the cracks.
Additionally this directly inclues the interal word-size patch [1], that was previously listed as an external dependency.
And finally meanwhile patches for the RK3528 SoC from Jonas have appeared, so I've included those too, to get the support for all not-yet supported SoCs done
[...]
Applied, thanks!
[1/6] dt-bindings: nvmem: rockchip,otp: Add support for RK3562 and RK3568
commit: 9438f599e77795f59571e57c438b28da59e1e5df
[2/6] dt-bindings: nvmem: rockchip,otp: Add compatible for RK3528
commit: c3c46b2a5bdbe254c6d7546d693a6b3886fd2993
[3/6] nvmem: rockchip-otp: Handle internal word_size in main reg_read op
commit: 9e7aba140eba2aeb72e65ea778c89a245fa235a4
[4/6] nvmem: rockchip-otp: Add support for RK3568
commit: 11e01bcb827d369344f7f0e960698d33db9ced5a
[5/6] nvmem: rockchip-otp: Add support for RK3562
commit: e482a8d8a0b4fef407084da1d6a00ad86993e7df
[6/6] nvmem: rockchip-otp: Add support for RK3528
commit: 85e2134182e21dc9550a1e316d690b1dda52d8cfBest regards,
Signature · 1 line
Srinivas Kandagatla <[email protected]>