mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/3] arm: imx6: ocotp: Added support for the i.MX6UL
@ 2016-11-30 11:10 Daniel Schultz
  2016-11-30 11:10 ` [PATCH 2/3] arm: imx6: ocotp: Added write check Daniel Schultz
  2016-11-30 11:10 ` [PATCH 3/3] arm: dts: Added ocotp support for i.MX6UL Daniel Schultz
  0 siblings, 2 replies; 5+ messages in thread
From: Daniel Schultz @ 2016-11-30 11:10 UTC (permalink / raw)
  To: barebox

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

Signed-off-by: Daniel Schultz <d.schultz@phytec.de>
---
 arch/arm/mach-imx/ocotp.c        | 82 +++++++++++++++++++++++++++++++++-------
 dts/Bindings/nvmem/imx-ocotp.txt |  7 ++--
 2 files changed, 73 insertions(+), 16 deletions(-)

diff --git a/arch/arm/mach-imx/ocotp.c b/arch/arm/mach-imx/ocotp.c
index e1d0c25..9efa46a 100644
--- a/arch/arm/mach-imx/ocotp.c
+++ b/arch/arm/mach-imx/ocotp.c
@@ -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 */
 	}
diff --git a/dts/Bindings/nvmem/imx-ocotp.txt b/dts/Bindings/nvmem/imx-ocotp.txt
index 383d588..5314b88 100644
--- a/dts/Bindings/nvmem/imx-ocotp.txt
+++ b/dts/Bindings/nvmem/imx-ocotp.txt
@@ -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.
 
-- 
1.9.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 2/3] arm: imx6: ocotp: Added write check
  2016-11-30 11:10 [PATCH 1/3] arm: imx6: ocotp: Added support for the i.MX6UL Daniel Schultz
@ 2016-11-30 11:10 ` Daniel Schultz
  2016-11-30 11:10 ` [PATCH 3/3] arm: dts: Added ocotp support for i.MX6UL Daniel Schultz
  1 sibling, 0 replies; 5+ messages in thread
From: Daniel Schultz @ 2016-11-30 11:10 UTC (permalink / raw)
  To: barebox

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

Signed-off-by: Daniel Schultz <d.schultz@phytec.de>
---
 arch/arm/mach-imx/ocotp.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/arm/mach-imx/ocotp.c b/arch/arm/mach-imx/ocotp.c
index 9efa46a..f8978c0 100644
--- a/arch/arm/mach-imx/ocotp.c
+++ b/arch/arm/mach-imx/ocotp.c
@@ -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);
-- 
1.9.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 3/3] arm: dts: Added ocotp support for i.MX6UL
  2016-11-30 11:10 [PATCH 1/3] arm: imx6: ocotp: Added support for the i.MX6UL Daniel Schultz
  2016-11-30 11:10 ` [PATCH 2/3] arm: imx6: ocotp: Added write check Daniel Schultz
@ 2016-11-30 11:10 ` Daniel Schultz
  2016-11-30 16:38   ` Andrey Smirnov
  1 sibling, 1 reply; 5+ messages in thread
From: Daniel Schultz @ 2016-11-30 11:10 UTC (permalink / raw)
  To: barebox

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.

Signed-off-by: Daniel Schultz <d.schultz@phytec.de>
---
 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

diff --git a/arch/arm/dts/imx6ul-phytec-phycore-som.dts b/arch/arm/dts/imx6ul-phytec-phycore-som.dts
index be4556a..285ea62 100644
--- a/arch/arm/dts/imx6ul-phytec-phycore-som.dts
+++ b/arch/arm/dts/imx6ul-phytec-phycore-som.dts
@@ -13,6 +13,7 @@
 /dts-v1/;
 
 #include <arm/imx6ul.dtsi>
+#include "imx6ul.dtsi"
 
 / {
 	model = "Phytec phyCORE-i.MX6 Ultra Lite SOM";
diff --git a/arch/arm/dts/imx6ul.dtsi b/arch/arm/dts/imx6ul.dtsi
new file mode 100644
index 0000000..2e02d27
--- /dev/null
+++ b/arch/arm/dts/imx6ul.dtsi
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2016 PHYTEC Messtechnik GmbH
+ * Author: Daniel Schultz <d.schultz@phytec.de>
+ *
+ * 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>;
+	};
+};
-- 
1.9.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 3/3] arm: dts: Added ocotp support for i.MX6UL
  2016-11-30 11:10 ` [PATCH 3/3] arm: dts: Added ocotp support for i.MX6UL Daniel Schultz
@ 2016-11-30 16:38   ` Andrey Smirnov
  2016-12-08  9:32     ` Daniel Schultz
  0 siblings, 1 reply; 5+ messages in thread
From: Andrey Smirnov @ 2016-11-30 16:38 UTC (permalink / raw)
  To: Daniel Schultz; +Cc: barebox

On Wed, Nov 30, 2016 at 3:10 AM, Daniel Schultz <d.schultz@phytec.de> wrote:
> 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.
>
> Signed-off-by: Daniel Schultz <d.schultz@phytec.de>
> ---
>  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
>
> diff --git a/arch/arm/dts/imx6ul-phytec-phycore-som.dts b/arch/arm/dts/imx6ul-phytec-phycore-som.dts
> index be4556a..285ea62 100644
> --- a/arch/arm/dts/imx6ul-phytec-phycore-som.dts
> +++ b/arch/arm/dts/imx6ul-phytec-phycore-som.dts
> @@ -13,6 +13,7 @@
>  /dts-v1/;
>
>  #include <arm/imx6ul.dtsi>
> +#include "imx6ul.dtsi"
>
>  / {
>         model = "Phytec phyCORE-i.MX6 Ultra Lite SOM";
> diff --git a/arch/arm/dts/imx6ul.dtsi b/arch/arm/dts/imx6ul.dtsi
> new file mode 100644
> index 0000000..2e02d27
> --- /dev/null
> +++ b/arch/arm/dts/imx6ul.dtsi
> @@ -0,0 +1,20 @@
> +/*
> + * Copyright (C) 2016 PHYTEC Messtechnik GmbH
> + * Author: Daniel Schultz <d.schultz@phytec.de>
> + *
> + * 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>;

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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 3/3] arm: dts: Added ocotp support for i.MX6UL
  2016-11-30 16:38   ` Andrey Smirnov
@ 2016-12-08  9:32     ` Daniel Schultz
  0 siblings, 0 replies; 5+ messages in thread
From: Daniel Schultz @ 2016-12-08  9:32 UTC (permalink / raw)
  To: Andrey Smirnov; +Cc: barebox



Am 30.11.2016 um 17:38 schrieb Andrey Smirnov:
> On Wed, Nov 30, 2016 at 3:10 AM, Daniel Schultz <d.schultz@phytec.de> wrote:
>> 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.
>>
>> Signed-off-by: Daniel Schultz <d.schultz@phytec.de>
>> ---
>>   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
>>
>> diff --git a/arch/arm/dts/imx6ul-phytec-phycore-som.dts b/arch/arm/dts/imx6ul-phytec-phycore-som.dts
>> index be4556a..285ea62 100644
>> --- a/arch/arm/dts/imx6ul-phytec-phycore-som.dts
>> +++ b/arch/arm/dts/imx6ul-phytec-phycore-som.dts
>> @@ -13,6 +13,7 @@
>>   /dts-v1/;
>>
>>   #include <arm/imx6ul.dtsi>
>> +#include "imx6ul.dtsi"
>>
>>   / {
>>          model = "Phytec phyCORE-i.MX6 Ultra Lite SOM";
>> diff --git a/arch/arm/dts/imx6ul.dtsi b/arch/arm/dts/imx6ul.dtsi
>> new file mode 100644
>> index 0000000..2e02d27
>> --- /dev/null
>> +++ b/arch/arm/dts/imx6ul.dtsi
>> @@ -0,0 +1,20 @@
>> +/*
>> + * Copyright (C) 2016 PHYTEC Messtechnik GmbH
>> + * Author: Daniel Schultz <d.schultz@phytec.de>
>> + *
>> + * 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>;
>
> 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.

-- 
Mit freundlichen Grüßen,
With best regards,
   Daniel Schultz

> Cheers,
> Andrey
>

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2016-12-08  9:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-30 11:10 [PATCH 1/3] arm: imx6: ocotp: Added support for the i.MX6UL Daniel Schultz
2016-11-30 11:10 ` [PATCH 2/3] arm: imx6: ocotp: Added write check Daniel Schultz
2016-11-30 11:10 ` [PATCH 3/3] arm: dts: Added ocotp support for i.MX6UL Daniel Schultz
2016-11-30 16:38   ` Andrey Smirnov
2016-12-08  9:32     ` Daniel Schultz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox