linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/6] nvmem: patches for 5.3 set 2
@ 2019-06-26 10:27 Srinivas Kandagatla
  2019-06-26 10:27 ` [PATCH 1/6] nvmem: imx-ocotp: Elongate OCOTP_CTRL ADDR field to eight bits Srinivas Kandagatla
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Srinivas Kandagatla @ 2019-06-26 10:27 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Srinivas Kandagatla

Hi Greg,

Here are imx-ocotp patches which I missed in last set.
Can you please pick them up if its not too late.

Thanks,
srini

Bryan O'Donoghue (5):
  nvmem: imx-ocotp: Elongate OCOTP_CTRL ADDR field to eight bits
  nvmem: imx-ocotp: Ensure WAIT bits are preserved when setting timing
  nvmem: imx-ocotp: Change TIMING calculation to u-boot algorithm
  nvmem: imx-ocotp: Add i.MX8MM support
  dt-bindings: imx-ocotp: Add i.MX8MM compatible

Leonard Crestez (1):
  nvmem: imx-ocotp: imx8mq is compatible with imx6 not imx7

 .../devicetree/bindings/nvmem/imx-ocotp.txt   |  1 +
 drivers/nvmem/imx-ocotp.c                     | 52 ++++++++++++++++---
 2 files changed, 45 insertions(+), 8 deletions(-)

-- 
2.21.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/6] nvmem: imx-ocotp: Elongate OCOTP_CTRL ADDR field to eight bits
  2019-06-26 10:27 [PATCH 0/6] nvmem: patches for 5.3 set 2 Srinivas Kandagatla
@ 2019-06-26 10:27 ` Srinivas Kandagatla
  2019-06-26 10:27 ` [PATCH 2/6] nvmem: imx-ocotp: Ensure WAIT bits are preserved when setting timing Srinivas Kandagatla
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Srinivas Kandagatla @ 2019-06-26 10:27 UTC (permalink / raw)
  To: gregkh
  Cc: linux-kernel, Bryan O'Donoghue, Leonard Crestez, Srinivas Kandagatla

From: Bryan O'Donoghue <pure.logic@nexus-software.ie>

i.MX6 defines OCOTP_CTRLn:ADDR as seven bit address-field with a one bit
RSVD0 field, i.MX7 defines OCOTP_CTRLn:ADDR as a four bit address-field
with a four bit RSVD0 field.

i.MX8 defines the OCOTP_CTRLn:ADDR bit-field as a full range eight bits.

i.MX6 and i.MX7 should return zero for their respective RSVD0 bits and
ignore a write-back of zero where i.MX8 will make use of the full range.

This patch expands the bit-field definition for all users to eight bits,
which is safe due to RSVD0 being a no-op for the i.MX6 and i.MX7.

Signed-off-by: Bryan O'Donoghue <pure.logic@nexus-software.ie>
Reviewed-by: Leonard Crestez <leonard.crestez@nxp.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/nvmem/imx-ocotp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c
index bd016b928589..14c2bff2cd96 100644
--- a/drivers/nvmem/imx-ocotp.c
+++ b/drivers/nvmem/imx-ocotp.c
@@ -39,7 +39,7 @@
 #define IMX_OCOTP_ADDR_DATA2		0x0040
 #define IMX_OCOTP_ADDR_DATA3		0x0050
 
-#define IMX_OCOTP_BM_CTRL_ADDR		0x0000007F
+#define IMX_OCOTP_BM_CTRL_ADDR		0x000000FF
 #define IMX_OCOTP_BM_CTRL_BUSY		0x00000100
 #define IMX_OCOTP_BM_CTRL_ERROR		0x00000200
 #define IMX_OCOTP_BM_CTRL_REL_SHADOWS	0x00000400
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/6] nvmem: imx-ocotp: Ensure WAIT bits are preserved when setting timing
  2019-06-26 10:27 [PATCH 0/6] nvmem: patches for 5.3 set 2 Srinivas Kandagatla
  2019-06-26 10:27 ` [PATCH 1/6] nvmem: imx-ocotp: Elongate OCOTP_CTRL ADDR field to eight bits Srinivas Kandagatla
@ 2019-06-26 10:27 ` Srinivas Kandagatla
  2019-06-26 10:27 ` [PATCH 3/6] nvmem: imx-ocotp: Change TIMING calculation to u-boot algorithm Srinivas Kandagatla
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Srinivas Kandagatla @ 2019-06-26 10:27 UTC (permalink / raw)
  To: gregkh
  Cc: linux-kernel, Bryan O'Donoghue, Leonard Crestez, Srinivas Kandagatla

From: Bryan O'Donoghue <pure.logic@nexus-software.ie>

The i.MX6 and i.MX8 both have a bit-field spanning bits 27:22 called the
WAIT field.

The WAIT field according to the documentation for both parts "specifies
time interval between auto read and write access in one time program. It is
given in number of ipg_clk periods."

This patch ensures that the relevant field is read and written back to the
timing register.

Fixes: 0642bac7da42 ("nvmem: imx-ocotp: add write support")

Signed-off-by: Bryan O'Donoghue <pure.logic@nexus-software.ie>
Reviewed-by: Leonard Crestez <leonard.crestez@nxp.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/nvmem/imx-ocotp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c
index 14c2bff2cd96..f4e117bbf2c3 100644
--- a/drivers/nvmem/imx-ocotp.c
+++ b/drivers/nvmem/imx-ocotp.c
@@ -183,7 +183,8 @@ static void imx_ocotp_set_imx6_timing(struct ocotp_priv *priv)
 	strobe_prog = clk_rate / (1000000000 / 10000) + 2 * (DEF_RELAX + 1) - 1;
 	strobe_read = clk_rate / (1000000000 / 40) + 2 * (DEF_RELAX + 1) - 1;
 
-	timing = strobe_prog & 0x00000FFF;
+	timing = readl(priv->base + IMX_OCOTP_ADDR_TIMING) & 0x0FC00000;
+	timing |= strobe_prog & 0x00000FFF;
 	timing |= (relax       << 12) & 0x0000F000;
 	timing |= (strobe_read << 16) & 0x003F0000;
 
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/6] nvmem: imx-ocotp: Change TIMING calculation to u-boot algorithm
  2019-06-26 10:27 [PATCH 0/6] nvmem: patches for 5.3 set 2 Srinivas Kandagatla
  2019-06-26 10:27 ` [PATCH 1/6] nvmem: imx-ocotp: Elongate OCOTP_CTRL ADDR field to eight bits Srinivas Kandagatla
  2019-06-26 10:27 ` [PATCH 2/6] nvmem: imx-ocotp: Ensure WAIT bits are preserved when setting timing Srinivas Kandagatla
@ 2019-06-26 10:27 ` Srinivas Kandagatla
  2019-06-26 10:27 ` [PATCH 4/6] nvmem: imx-ocotp: Add i.MX8MM support Srinivas Kandagatla
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Srinivas Kandagatla @ 2019-06-26 10:27 UTC (permalink / raw)
  To: gregkh
  Cc: linux-kernel, Bryan O'Donoghue, Leonard Crestez, Srinivas Kandagatla

From: Bryan O'Donoghue <pure.logic@nexus-software.ie>

The RELAX field of the OCOTP block is turning out as a zero on i.MX8MM.
This messes up the subsequent re-load of the fuse shadow registers.

After some discussion with people @ NXP its clear we have missed a trick
here in Linux.

The OCOTP fuse programming time has a physical minimum 'burn time' that is
not related to the ipg_clk.

We need to define the RELAX, STROBE_READ and STROBE_PROG fields in terms of
desired timings to allow for the burn-in to safely complete. Right now only
the RELAX field is calculated in terms of an absolute time and we are
ending up with a value of zero.

This patch inherits the u-boot timings for the OCOTP_TIMING calculation on
the i.MX6 and i.MX8. Those timings are known to work and critically specify
values such as STROBE_PROG as a minimum timing.

Fixes: 0642bac7da42 ("nvmem: imx-ocotp: add write support")

Signed-off-by: Bryan O'Donoghue <pure.logic@nexus-software.ie>
Suggested-by: Leonard Crestez <leonard.crestez@nxp.com>
Reviewed-by: Leonard Crestez <leonard.crestez@nxp.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/nvmem/imx-ocotp.c | 36 ++++++++++++++++++++++++++++++++----
 1 file changed, 32 insertions(+), 4 deletions(-)

diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c
index f4e117bbf2c3..b7dacf53c715 100644
--- a/drivers/nvmem/imx-ocotp.c
+++ b/drivers/nvmem/imx-ocotp.c
@@ -44,7 +44,9 @@
 #define IMX_OCOTP_BM_CTRL_ERROR		0x00000200
 #define IMX_OCOTP_BM_CTRL_REL_SHADOWS	0x00000400
 
-#define DEF_RELAX			20	/* > 16.5ns */
+#define TIMING_STROBE_PROG_US		10	/* Min time to blow a fuse */
+#define TIMING_STROBE_READ_NS		37	/* Min time before read */
+#define TIMING_RELAX_NS			17
 #define DEF_FSOURCE			1001	/* > 1000 ns */
 #define DEF_STROBE_PROG			10000	/* IPG clocks */
 #define IMX_OCOTP_WR_UNLOCK		0x3E770000
@@ -176,12 +178,38 @@ static void imx_ocotp_set_imx6_timing(struct ocotp_priv *priv)
 	 * fields with timing values to match the current frequency of the
 	 * ipg_clk. OTP writes will work at maximum bus frequencies as long
 	 * as the HW_OCOTP_TIMING parameters are set correctly.
+	 *
+	 * Note: there are minimum timings required to ensure an OTP fuse burns
+	 * correctly that are independent of the ipg_clk. Those values are not
+	 * formally documented anywhere however, working from the minimum
+	 * timings given in u-boot we can say:
+	 *
+	 * - Minimum STROBE_PROG time is 10 microseconds. Intuitively 10
+	 *   microseconds feels about right as representative of a minimum time
+	 *   to physically burn out a fuse.
+	 *
+	 * - Minimum STROBE_READ i.e. the time to wait post OTP fuse burn before
+	 *   performing another read is 37 nanoseconds
+	 *
+	 * - Minimum RELAX timing is 17 nanoseconds. This final RELAX minimum
+	 *   timing is not entirely clear the documentation says "This
+	 *   count value specifies the time to add to all default timing
+	 *   parameters other than the Tpgm and Trd. It is given in number
+	 *   of ipg_clk periods." where Tpgm and Trd refer to STROBE_PROG
+	 *   and STROBE_READ respectively. What the other timing parameters
+	 *   are though, is not specified. Experience shows a zero RELAX
+	 *   value will mess up a re-load of the shadow registers post OTP
+	 *   burn.
 	 */
 	clk_rate = clk_get_rate(priv->clk);
 
-	relax = clk_rate / (1000000000 / DEF_RELAX) - 1;
-	strobe_prog = clk_rate / (1000000000 / 10000) + 2 * (DEF_RELAX + 1) - 1;
-	strobe_read = clk_rate / (1000000000 / 40) + 2 * (DEF_RELAX + 1) - 1;
+	relax = DIV_ROUND_UP(clk_rate * TIMING_RELAX_NS, 1000000000) - 1;
+	strobe_read = DIV_ROUND_UP(clk_rate * TIMING_STROBE_READ_NS,
+				   1000000000);
+	strobe_read += 2 * (relax + 1) - 1;
+	strobe_prog = DIV_ROUND_CLOSEST(clk_rate * TIMING_STROBE_PROG_US,
+					1000000);
+	strobe_prog += 2 * (relax + 1) - 1;
 
 	timing = readl(priv->base + IMX_OCOTP_ADDR_TIMING) & 0x0FC00000;
 	timing |= strobe_prog & 0x00000FFF;
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 4/6] nvmem: imx-ocotp: Add i.MX8MM support
  2019-06-26 10:27 [PATCH 0/6] nvmem: patches for 5.3 set 2 Srinivas Kandagatla
                   ` (2 preceding siblings ...)
  2019-06-26 10:27 ` [PATCH 3/6] nvmem: imx-ocotp: Change TIMING calculation to u-boot algorithm Srinivas Kandagatla
@ 2019-06-26 10:27 ` Srinivas Kandagatla
  2019-06-26 10:27 ` [PATCH 5/6] dt-bindings: imx-ocotp: Add i.MX8MM compatible Srinivas Kandagatla
  2019-06-26 10:27 ` [PATCH 6/6] nvmem: imx-ocotp: imx8mq is compatible with imx6 not imx7 Srinivas Kandagatla
  5 siblings, 0 replies; 7+ messages in thread
From: Srinivas Kandagatla @ 2019-06-26 10:27 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Bryan O'Donoghue, Srinivas Kandagatla

From: Bryan O'Donoghue <pure.logic@nexus-software.ie>

This patch adds support to burn the fuses on the i.MX8MM.
https://www.nxp.com/webapp/Download?colCode=IMX8MMRM

The i.MX8MM is similar to i.MX6 processors in terms of addressing and clock
setup.

The documentation specifies 60 discreet OTP registers but, the fusemap
address space encompasses up to 256 registers. We map the entire putative
256 OTP registers.

Signed-off-by: Bryan O'Donoghue <pure.logic@nexus-software.ie>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/nvmem/imx-ocotp.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c
index b7dacf53c715..340ab336f987 100644
--- a/drivers/nvmem/imx-ocotp.c
+++ b/drivers/nvmem/imx-ocotp.c
@@ -473,6 +473,12 @@ static const struct ocotp_params imx8mq_params = {
 	.set_timing = imx_ocotp_set_imx7_timing,
 };
 
+static const struct ocotp_params imx8mm_params = {
+	.nregs = 256,
+	.bank_address_words = 0,
+	.set_timing = imx_ocotp_set_imx6_timing,
+};
+
 static const struct of_device_id imx_ocotp_dt_ids[] = {
 	{ .compatible = "fsl,imx6q-ocotp",  .data = &imx6q_params },
 	{ .compatible = "fsl,imx6sl-ocotp", .data = &imx6sl_params },
@@ -483,6 +489,7 @@ static const struct of_device_id imx_ocotp_dt_ids[] = {
 	{ .compatible = "fsl,imx6sll-ocotp", .data = &imx6sll_params },
 	{ .compatible = "fsl,imx7ulp-ocotp", .data = &imx7ulp_params },
 	{ .compatible = "fsl,imx8mq-ocotp", .data = &imx8mq_params },
+	{ .compatible = "fsl,imx8mm-ocotp", .data = &imx8mm_params },
 	{ },
 };
 MODULE_DEVICE_TABLE(of, imx_ocotp_dt_ids);
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 5/6] dt-bindings: imx-ocotp: Add i.MX8MM compatible
  2019-06-26 10:27 [PATCH 0/6] nvmem: patches for 5.3 set 2 Srinivas Kandagatla
                   ` (3 preceding siblings ...)
  2019-06-26 10:27 ` [PATCH 4/6] nvmem: imx-ocotp: Add i.MX8MM support Srinivas Kandagatla
@ 2019-06-26 10:27 ` Srinivas Kandagatla
  2019-06-26 10:27 ` [PATCH 6/6] nvmem: imx-ocotp: imx8mq is compatible with imx6 not imx7 Srinivas Kandagatla
  5 siblings, 0 replies; 7+ messages in thread
From: Srinivas Kandagatla @ 2019-06-26 10:27 UTC (permalink / raw)
  To: gregkh
  Cc: linux-kernel, Bryan O'Donoghue, Rob Herring, Leonard Crestez,
	Srinivas Kandagatla

From: Bryan O'Donoghue <pure.logic@nexus-software.ie>

Add compatible for i.MX8MM as per arch/arm64/boot/dts/freescale/imx8mm.dtsi

Signed-off-by: Bryan O'Donoghue <pure.logic@nexus-software.ie>
Cc: Rob Herring <robh@kernel.org>
Reviewed-by: Leonard Crestez <leonard.crestez@nxp.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 Documentation/devicetree/bindings/nvmem/imx-ocotp.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/nvmem/imx-ocotp.txt b/Documentation/devicetree/bindings/nvmem/imx-ocotp.txt
index 68f7d6fdd140..96ffd06d2ca8 100644
--- a/Documentation/devicetree/bindings/nvmem/imx-ocotp.txt
+++ b/Documentation/devicetree/bindings/nvmem/imx-ocotp.txt
@@ -15,6 +15,7 @@ Required properties:
 	"fsl,imx6sll-ocotp" (i.MX6SLL),
 	"fsl,imx7ulp-ocotp" (i.MX7ULP),
 	"fsl,imx8mq-ocotp" (i.MX8MQ),
+	"fsl,imx8mm-ocotp" (i.MX8MM),
 	followed by "syscon".
 - #address-cells : Should be 1
 - #size-cells : Should be 1
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 6/6] nvmem: imx-ocotp: imx8mq is compatible with imx6 not imx7
  2019-06-26 10:27 [PATCH 0/6] nvmem: patches for 5.3 set 2 Srinivas Kandagatla
                   ` (4 preceding siblings ...)
  2019-06-26 10:27 ` [PATCH 5/6] dt-bindings: imx-ocotp: Add i.MX8MM compatible Srinivas Kandagatla
@ 2019-06-26 10:27 ` Srinivas Kandagatla
  5 siblings, 0 replies; 7+ messages in thread
From: Srinivas Kandagatla @ 2019-06-26 10:27 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Leonard Crestez, Peng Fan, Srinivas Kandagatla

From: Leonard Crestez <leonard.crestez@nxp.com>

According to NXP Reference Manuals and uboot/atf sources the OCOTP block
on imx8m behaves more like imx6 than imx7.

- Fuses can be read/written 32bits at a time (no imx7-like banking)
- The OCOTP_HW_OCOTP_TIMING register is like imx6 not imx7

Since nvmem doesn't support uboot-style "sense" and "override" this
issue only affected "write" which is very rarely used.

Fixes: 163c0dbd0cb1 ("nvmem: imx-ocotp: add support for imx8mq")
Signed-off-by: Leonard Crestez <leonard.crestez@nxp.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/nvmem/imx-ocotp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c
index 340ab336f987..42d4451e7d67 100644
--- a/drivers/nvmem/imx-ocotp.c
+++ b/drivers/nvmem/imx-ocotp.c
@@ -469,8 +469,8 @@ static const struct ocotp_params imx7ulp_params = {
 
 static const struct ocotp_params imx8mq_params = {
 	.nregs = 256,
-	.bank_address_words = 4,
-	.set_timing = imx_ocotp_set_imx7_timing,
+	.bank_address_words = 0,
+	.set_timing = imx_ocotp_set_imx6_timing,
 };
 
 static const struct ocotp_params imx8mm_params = {
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-06-26 10:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-26 10:27 [PATCH 0/6] nvmem: patches for 5.3 set 2 Srinivas Kandagatla
2019-06-26 10:27 ` [PATCH 1/6] nvmem: imx-ocotp: Elongate OCOTP_CTRL ADDR field to eight bits Srinivas Kandagatla
2019-06-26 10:27 ` [PATCH 2/6] nvmem: imx-ocotp: Ensure WAIT bits are preserved when setting timing Srinivas Kandagatla
2019-06-26 10:27 ` [PATCH 3/6] nvmem: imx-ocotp: Change TIMING calculation to u-boot algorithm Srinivas Kandagatla
2019-06-26 10:27 ` [PATCH 4/6] nvmem: imx-ocotp: Add i.MX8MM support Srinivas Kandagatla
2019-06-26 10:27 ` [PATCH 5/6] dt-bindings: imx-ocotp: Add i.MX8MM compatible Srinivas Kandagatla
2019-06-26 10:27 ` [PATCH 6/6] nvmem: imx-ocotp: imx8mq is compatible with imx6 not imx7 Srinivas Kandagatla

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).