Skip to contentSkip to conversation

arm: imx6: ocotp: Added support for the i.MX6UL

PATCH In review Daniel Schultz 2 participants 5 messages Nov 30, 2016 – Dec 8, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 arm: imx6: ocotp: Added support for the i.MX6UL

This patch adds support for the i.MX6UL SoC. Also, the driver was extended to handle two MAC addresses.

---
 arch/arm/mach-imx/ocotp.c        | 82 +++++++++++++++++++++++++++++++++-------
 dts/Bindings/nvmem/imx-ocotp.txt |  7 ++--
 2 files changed, 73 insertions(+), 16 deletions(-)
arch/arm/mach-imx/ocotp.c +69 -13
index e1d0c25..9efa46a 100644
@@ -70,11 +70,13 @@
 #define FUSE_REGS_COUNT			(16 * 8)
 #define IMX6_OTP_DATA_ERROR_VAL		0xBADABADA
 #define DEF_RELAX			20
-#define MAC_OFFSET			(0x22 * 4)
+#define MAC0_OFFSET			(0x22 * 4)
+#define MAC1_OFFSET			(0x23 * 4)
 #define MAC_BYTES			8
 
 struct imx_ocotp_data {
 	int num_regs;
+	bool scnd_mac_addr;
 };
 
 struct ocotp_priv {
@@ -84,7 +86,7 @@ struct ocotp_priv {
 	struct device_d dev;
 	int permanent_write_enable;
 	int sense_enable;
-	char ethaddr[6];
+	char ethaddr[2][6];
 	struct regmap_config map_config;
 };
 
@@ -394,38 +396,79 @@ static void imx_ocotp_init_dt(struct device_d *dev, void __iomem *base)
 	}
 }
 
-static int imx_ocotp_get_mac(struct param_d *param, void *priv)
+static int imx_ocotp_get_mac(unsigned int mac_no, struct param_d *param,
+			     void *priv)
 {
 	struct ocotp_priv *ocotp_priv = priv;
 	char buf[8];
 	int i, ret;
+	int offset;
 
-	ret = regmap_bulk_read(ocotp_priv->map, MAC_OFFSET, buf, MAC_BYTES);
+	if (mac_no > 1)
+		return -EINVAL;
+
+	ret = regmap_bulk_read(ocotp_priv->map,
+			       (mac_no == 0) ? MAC0_OFFSET : MAC1_OFFSET, buf,
+			       MAC_BYTES);
 	if (ret < 0)
 		return ret;
 
+	offset = mac_no << 1;
 	for (i = 0; i < 6; i++)
-		ocotp_priv->ethaddr[i] = buf[5 - i];
+		ocotp_priv->ethaddr[mac_no][i] = buf[5 - i + offset];
 
 	return 0;
 }
 
-static int imx_ocotp_set_mac(struct param_d *param, void *priv)
+static inline int imx_ocotp_get_mac0(struct param_d *param, void *priv)
+{
+	return imx_ocotp_get_mac(0, param, priv);
+}
+static inline int imx_ocotp_get_mac1(struct param_d *param, void *priv)
+{
+	return imx_ocotp_get_mac(1, param, priv);
+}
+
+static int imx_ocotp_set_mac(unsigned int mac_no, struct param_d *param,
+			     void *priv)
 {
 	struct ocotp_priv *ocotp_priv = priv;
 	char buf[8];
 	int i, ret;
+	int offset;
+
+	if (mac_no > 1)
+		return -EINVAL;
+
+	offset = mac_no << 1;
+	if (mac_no == 0) {
+		buf[6] = ocotp_priv->ethaddr[1][5];
+		buf[7] = ocotp_priv->ethaddr[1][4];
+	} else {
+		buf[0] = ocotp_priv->ethaddr[0][1];
+		buf[1] = ocotp_priv->ethaddr[0][0];
+	}
 
 	for (i = 0; i < 6; i++)
-		buf[5 - i] = ocotp_priv->ethaddr[i];
-	buf[6] = 0; buf[7] = 0;
+		buf[5 - i + offset] = ocotp_priv->ethaddr[mac_no][i];
 
-	ret = regmap_bulk_write(ocotp_priv->map, MAC_OFFSET, buf, MAC_BYTES);
+	ret = regmap_bulk_write(ocotp_priv->map,
+				(mac_no == 0) ? MAC0_OFFSET : MAC1_OFFSET, buf,
+				MAC_BYTES);
 	if (ret < 0)
 		return ret;
 
 	return 0;
 }
+static inline int imx_ocotp_set_mac0(struct param_d *param, void *priv)
+{
+	return imx_ocotp_set_mac(0, param, priv);
+}
+
+static inline int imx_ocotp_set_mac1(struct param_d *param, void *priv)
+{
+	return imx_ocotp_set_mac(1, param, priv);
+}
 
 static struct regmap_bus imx_ocotp_regmap_bus = {
 	.reg_write = imx_ocotp_reg_write,
@@ -482,9 +525,15 @@ static int imx_ocotp_probe(struct device_d *dev)
 				NULL, NULL, &priv->permanent_write_enable, NULL);
 	}
 
-	if (IS_ENABLED(CONFIG_NET))
-		dev_add_param_mac(&(priv->dev), "mac_addr", imx_ocotp_set_mac,
-				imx_ocotp_get_mac, priv->ethaddr, priv);
+	if (IS_ENABLED(CONFIG_NET)) {
+		dev_add_param_mac(&(priv->dev), "mac_addr", imx_ocotp_set_mac0,
+				imx_ocotp_get_mac0, priv->ethaddr[0], priv);
+
+		if (data->scnd_mac_addr)
+			dev_add_param_mac(&(priv->dev), "mac_addr1",
+					 imx_ocotp_set_mac1, imx_ocotp_get_mac1,
+					 priv->ethaddr[1], priv);
+	}
 
 	dev_add_param_bool(&(priv->dev), "sense_enable", NULL, NULL, &priv->sense_enable, priv);
 
@@ -493,10 +542,17 @@ static int imx_ocotp_probe(struct device_d *dev)
 
 static struct imx_ocotp_data imx6q_ocotp_data = {
 	.num_regs = 512,
+	.scnd_mac_addr = false,
+};
+
+static struct imx_ocotp_data imx6ul_ocotp_data = {
+	.num_regs = 512,
+	.scnd_mac_addr = true,
 };
 
 static struct imx_ocotp_data imx6sl_ocotp_data = {
 	.num_regs = 256,
+	.scnd_mac_addr = false,
 };
 
 static __maybe_unused struct of_device_id imx_ocotp_dt_ids[] = {
@@ -511,7 +567,7 @@ static __maybe_unused struct of_device_id imx_ocotp_dt_ids[] = {
 		.data = &imx6sl_ocotp_data,
 	}, {
 		.compatible = "fsl,imx6ul-ocotp",
-		.data = &imx6q_ocotp_data,
+		.data = &imx6ul_ocotp_data,
 	}, {
 		/* sentinel */
 	}
dts/Bindings/nvmem/imx-ocotp.txt +4 -3
index 383d588..5314b88 100644
@@ -1,13 +1,14 @@
 Freescale i.MX6 On-Chip OTP Controller (OCOTP) device tree bindings
 
 This binding represents the on-chip eFuse OTP controller found on
-i.MX6Q/D, i.MX6DL/S, i.MX6SL, and i.MX6SX SoCs.
+i.MX6Q/D, i.MX6DL/S, i.MX6SL, i.MX6SX and i.MX6UL SoCs.
 
 Required properties:
 - compatible: should be one of
 	"fsl,imx6q-ocotp" (i.MX6Q/D/DL/S),
-	"fsl,imx6sl-ocotp" (i.MX6SL), or
-	"fsl,imx6sx-ocotp" (i.MX6SX), followed by "syscon".
+	"fsl,imx6sl-ocotp" (i.MX6SL),
+	"fls,imx6ul-ocotp" (i.MX6UL) or
+	"fls,imx6sx-ocotp" (i.MX6SX), followed by "syscon".
 - reg: Should contain the register base and length.
 - clocks: Should contain a phandle pointing to the gated peripheral clock.
 
Signature · 7 lines
1.9.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

PATCH 2/3 arm: imx6: ocotp: Added write check

Since it's forbidden to use a multicast address as ethernet address, the driver should check the addresses before they got written.

---
 arch/arm/mach-imx/ocotp.c | 6 ++++++
 1 file changed, 6 insertions(+)
arch/arm/mach-imx/ocotp.c +6 -0
index 9efa46a..f8978c0 100644
@@ -452,6 +452,12 @@ static int imx_ocotp_set_mac(unsigned int mac_no, struct param_d *param,
 	for (i = 0; i < 6; i++)
 		buf[5 - i + offset] = ocotp_priv->ethaddr[mac_no][i];
 
+	if (0x01 & buf[5 + offset]) {
+		dev_err(&ocotp_priv->dev,
+			"this MAC address is a broadcast/multicast\n");
+		return -EINVAL;
+	}
+
 	ret = regmap_bulk_write(ocotp_priv->map,
 				(mac_no == 0) ? MAC0_OFFSET : MAC1_OFFSET, buf,
 				MAC_BYTES);
Signature · 7 lines
1.9.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

PATCH 3/3 arm: dts: Added ocotp support for i.MX6UL

In reply to Daniel Schultz

Ocotp is available for the iMX6(q|sx|sl) SoCs. This patch will extend the iMX6ul DT from the mainline kernel to support the ocotp driver on the iMX6ul SoC.

---
 arch/arm/dts/imx6ul-phytec-phycore-som.dts |  1 +
 arch/arm/dts/imx6ul.dtsi                   | 20 ++++++++++++++++++++
 2 files changed, 21 insertions(+)
 create mode 100644 arch/arm/dts/imx6ul.dtsi
arch/arm/dts/imx6ul-phytec-phycore-som.dts +1 -0
index be4556a..285ea62 100644
@@ -13,6 +13,7 @@
 /dts-v1/;
 
 #include <arm/imx6ul.dtsi>
+#include "imx6ul.dtsi"
 
 / {
 	model = "Phytec phyCORE-i.MX6 Ultra Lite SOM";
arch/arm/dts/imx6ul.dtsi new file +20 -0
new file mode 100644
index 0000000..2e02d27
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2016 PHYTEC Messtechnik GmbH
+ * Author: Daniel Schultz <[email protected]>
+ *
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+&aips2 {
+	ocotp: ocotp-ctrl@21bc000 {
+		compatible = "fsl,imx6ul-ocotp";
+		reg = <0x021bc000 0x4000>;
+		clocks = <&clks IMX6UL_CLK_OCOTP>;
+		barebox,provide-mac-address = <&fec1 0x620 &fec2 0x632>;
+	};
+};
Signature · 7 lines
1.9.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

Re: [PATCH 3/3] arm: dts: Added ocotp support for i.MX6UL

Quoted 36 lines · Daniel Schultz

Ocotp is available for the iMX6(q|sx|sl) SoCs. This patch will extend the iMX6ul DT from the mainline kernel to support the ocotp driver on the iMX6ul SoC.

---
 arch/arm/dts/imx6ul-phytec-phycore-som.dts |  1 +
 arch/arm/dts/imx6ul.dtsi                   | 20 ++++++++++++++++++++
 2 files changed, 21 insertions(+)
 create mode 100644 arch/arm/dts/imx6ul.dtsi
arch/arm/dts/imx6ul-phytec-phycore-som.dts +1 -0
index be4556a..285ea62 100644
@@ -13,6 +13,7 @@
 /dts-v1/;
 
 #include <arm/imx6ul.dtsi>
+#include "imx6ul.dtsi"
 
 / {
        model = "Phytec phyCORE-i.MX6 Ultra Lite SOM";
arch/arm/dts/imx6ul.dtsi new file +7 -0
new file mode 100644
index 0000000..2e02d27
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2016 PHYTEC Messtechnik GmbH
+ * Author: Daniel Schultz <[email protected]>
+ *
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:

arch/arm/dts/imx6ul.dtsi line 17

Quoted 10 lines
arch/arm/dts/imx6ul.dtsi new file +10 -0
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+&aips2 {
+       ocotp: ocotp-ctrl@21bc000 {
+               compatible = "fsl,imx6ul-ocotp";
+               reg = <0x021bc000 0x4000>;
+               clocks = <&clks IMX6UL_CLK_OCOTP>;

Just as my two cents, I'd say that all of the above (that is instantiation of OCOT on AIPS2) should go via Linux kernel and trickle down via syncing with its .dts tree (<arm/imx6ul.dtsi> in particular). At least that's what I had to do for OCOTP in Vybrid. Although your case might be more complicated since there are no bindings for "fsl,imx6ul-ocotp" upstream, so take this with a grain of salt

Cheers,
Andrey

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#4 lore raw

Re: [PATCH 3/3] arm: dts: Added ocotp support for i.MX6UL

Am 30.11.2016 um 17:38 schrieb Andrey Smirnov:

Quoted 46 lines · Daniel Schultz
Quoted 45 lines

Ocotp is available for the iMX6(q|sx|sl) SoCs. This patch will extend the iMX6ul DT from the mainline kernel to support the ocotp driver on the iMX6ul SoC.

---
  arch/arm/dts/imx6ul-phytec-phycore-som.dts |  1 +
  arch/arm/dts/imx6ul.dtsi                   | 20 ++++++++++++++++++++
  2 files changed, 21 insertions(+)

create mode 100644 arch/arm/dts/imx6ul.dtsi

arch/arm/dts/imx6ul-phytec-phycore-som.dts +1 -0
index be4556a..285ea62 100644
@@ -13,6 +13,7 @@
  /dts-v1/;
 
  #include <arm/imx6ul.dtsi>
+#include "imx6ul.dtsi"
 
  / {
         model = "Phytec phyCORE-i.MX6 Ultra Lite SOM";
arch/arm/dts/imx6ul.dtsi new file +16 -0
new file mode 100644
index 0000000..2e02d27
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2016 PHYTEC Messtechnik GmbH
+ * Author: Daniel Schultz <[email protected]>
+ *
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+&aips2 {
+       ocotp: ocotp-ctrl@21bc000 {
+               compatible = "fsl,imx6ul-ocotp";
+               reg = <0x021bc000 0x4000>;
Quoted 9 lines

arch/arm/dts/imx6ul.dtsi line 17

Quoted 1 line
arch/arm/dts/imx6ul.dtsi new file +1 -0
+               clocks = <&clks IMX6UL_CLK_OCOTP>;

Just as my two cents, I'd say that all of the above (that is instantiation of OCOT on AIPS2) should go via Linux kernel and trickle down via syncing with its .dts tree (<arm/imx6ul.dtsi> in particular). At least that's what I had to do for OCOTP in Vybrid. Although your case might be more complicated since there are no bindings for "fsl,imx6ul-ocotp" upstream, so take this with a grain of salt

Hi Andrey,

thanks, that's way better. I have sent a patch to the mainline kernel with this change. Sascha Hauer got a notification, so when it apply he can remove the patch.

Signature · 3 lines
Mit freundlichen Grüßen,
With best regards,
  Daniel Schultz
Quoted 3 lines

Cheers,
Andrey

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox