mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2 1/3] MIPS: ath79: provide driver for Atheros ART partition
@ 2018-06-07 19:55 Oleksij Rempel
  2018-06-07 19:55 ` [PATCH v2 2/3] MIPS: dts: tl_wdr4300: add " Oleksij Rempel
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Oleksij Rempel @ 2018-06-07 19:55 UTC (permalink / raw)
  To: barebox; +Cc: Oleksij Rempel

From: Oleksij Rempel <linux@rempel-privat.de>

this partition contains calibration data for WiFi and
some board specific data, like MAC address.

For now we care only about MAC.

Signed-off-by: Oleksij Rempel <linux@rempel-privat.de>
---
 arch/mips/mach-ath79/Makefile |   1 +
 arch/mips/mach-ath79/art.c    | 112 ++++++++++++++++++++++++++++++++++
 2 files changed, 113 insertions(+)
 create mode 100644 arch/mips/mach-ath79/art.c

diff --git a/arch/mips/mach-ath79/Makefile b/arch/mips/mach-ath79/Makefile
index 3772daeba..b827b363c 100644
--- a/arch/mips/mach-ath79/Makefile
+++ b/arch/mips/mach-ath79/Makefile
@@ -1,2 +1,3 @@
 obj-y += reset.o
 obj-y += bbu.o
+obj-y += art.o
diff --git a/arch/mips/mach-ath79/art.c b/arch/mips/mach-ath79/art.c
new file mode 100644
index 000000000..984d08736
--- /dev/null
+++ b/arch/mips/mach-ath79/art.c
@@ -0,0 +1,112 @@
+// SPDX-License-Identifier: GPL-2.
+/*
+ * Copyright (c) 2018 Oleksij Rempel <linux@rempel-privat.de>
+ */
+
+#include <common.h>
+#include <fcntl.h>
+#include <init.h>
+#include <libfile.h>
+#include <net.h>
+#include <unistd.h>
+
+#define AR93000_EPPROM_OFFSET	0x1000
+
+struct ar9300_eeprom {
+	u8 eeprom_version;
+	u8 template_version;
+	u8 mac_addr[6];
+};
+
+static int art_set_mac(struct device_d *dev, struct ar9300_eeprom *eeprom)
+{
+	struct device_node *node = dev->device_node;
+	struct device_node *rnode;
+
+	if (!node)
+		return -ENOENT;
+
+	rnode = of_parse_phandle_from(node, NULL,
+				     "barebox,provide-mac-address", 0);
+	if (!rnode)
+		return -ENOENT;
+
+	of_eth_register_ethaddr(rnode, &eeprom->mac_addr[0]);
+
+	return 0;
+}
+
+static int art_read_mac(struct device_d *dev, const char *file)
+{
+	int fd, rbytes;
+	struct ar9300_eeprom eeprom;
+
+	fd = open_and_lseek(file, O_RDONLY, AR93000_EPPROM_OFFSET);
+	if (fd < 0) {
+		dev_err(dev, "Failed to open eeprom path %s %d\n",
+		       file, fd);
+		return fd;
+	}
+
+	rbytes = read_full(fd, &eeprom, sizeof(eeprom));
+	close(fd);
+	if (rbytes < sizeof(eeprom)) {
+		dev_err(dev, "Failed to read %s\n", file);
+		return rbytes < 0 ? rbytes : -EIO;
+	}
+
+	dev_dbg(dev, "ART version: %x.%x\n",
+		 eeprom.eeprom_version, eeprom.template_version);
+	dev_dbg(dev, "mac: %02x:%02x:%02x:%02x:%02x:%02x\n",
+	       eeprom.mac_addr[0],
+	       eeprom.mac_addr[1],
+	       eeprom.mac_addr[2],
+	       eeprom.mac_addr[3],
+	       eeprom.mac_addr[4],
+	       eeprom.mac_addr[5]);
+
+	if (!is_valid_ether_addr(&eeprom.mac_addr[0])) {
+		dev_err(dev, "bad MAC addr\n");
+		return -EILSEQ;
+	}
+
+	return art_set_mac(dev, &eeprom);
+}
+
+static int art_probe(struct device_d *dev)
+{
+	char *path;
+	int ret;
+
+	dev_dbg(dev, "found ART partition\n");
+
+	ret = of_find_path(dev->device_node, "device-path", &path, 0);
+	if (ret) {
+		dev_err(dev, "can't find path\n");
+		return ret;
+	}
+
+	return art_read_mac(dev, path);
+}
+
+static struct of_device_id art_dt_ids[] = {
+	{
+		.compatible = "qca,art",
+	}, {
+		/* sentinel */
+	}
+};
+
+static struct driver_d art_driver = {
+	.name		= "qca-art",
+	.probe		= art_probe,
+	.of_compatible	= art_dt_ids,
+};
+
+static int art_of_driver_init(void)
+{
+	platform_driver_register(&art_driver);
+
+	return 0;
+}
+late_initcall(art_of_driver_init);
-- 
2.17.1


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

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

* [PATCH v2 2/3] MIPS: dts: tl_wdr4300: add Atheros ART partition
  2018-06-07 19:55 [PATCH v2 1/3] MIPS: ath79: provide driver for Atheros ART partition Oleksij Rempel
@ 2018-06-07 19:55 ` Oleksij Rempel
  2018-06-07 19:55 ` [PATCH v2 3/3] MIPS: dts: dpt-module: " Oleksij Rempel
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Oleksij Rempel @ 2018-06-07 19:55 UTC (permalink / raw)
  To: barebox; +Cc: Oleksij Rempel

From: Oleksij Rempel <linux@rempel-privat.de>

and define it as source of MAC address for ag71xx driver

Signed-off-by: Oleksij Rempel <linux@rempel-privat.de>
---
 arch/mips/dts/ar9344-tl-wdr4300-v1.7.dts | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/arch/mips/dts/ar9344-tl-wdr4300-v1.7.dts b/arch/mips/dts/ar9344-tl-wdr4300-v1.7.dts
index 5216cdc1e..c9ce12058 100644
--- a/arch/mips/dts/ar9344-tl-wdr4300-v1.7.dts
+++ b/arch/mips/dts/ar9344-tl-wdr4300-v1.7.dts
@@ -26,6 +26,12 @@
 			compatible = "barebox,environment";
 			device-path = &spiflash, "partname:barebox-environment";
 		};
+
+		art@0 {
+			compatible = "qca,art-ar9344", "qca,art";
+			device-path = &spiflash_art;
+			barebox,provide-mac-address = <&mac0>;
+		};
 	};
 };
 
@@ -63,6 +69,11 @@
 			label = "barebox-environment";
 			reg = <0x80000 0x10000>;
 		};
+
+		spiflash_art: partition@7f0000 {
+			label = "art";
+			reg = <0x7f0000 0x10000>;
+		};
 	};
 };
 
-- 
2.17.1


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

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

* [PATCH v2 3/3] MIPS: dts: dpt-module: add Atheros ART partition
  2018-06-07 19:55 [PATCH v2 1/3] MIPS: ath79: provide driver for Atheros ART partition Oleksij Rempel
  2018-06-07 19:55 ` [PATCH v2 2/3] MIPS: dts: tl_wdr4300: add " Oleksij Rempel
@ 2018-06-07 19:55 ` Oleksij Rempel
  2018-06-08  7:08 ` [PATCH v2 1/3] MIPS: ath79: provide driver for " Sascha Hauer
  2018-06-14  6:06 ` Sascha Hauer
  3 siblings, 0 replies; 6+ messages in thread
From: Oleksij Rempel @ 2018-06-07 19:55 UTC (permalink / raw)
  To: barebox; +Cc: Oleksij Rempel

and define it as source of MAC address for ag71xx driver

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 arch/mips/dts/ar9331-dptechnics-dpt-module.dts | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/arch/mips/dts/ar9331-dptechnics-dpt-module.dts b/arch/mips/dts/ar9331-dptechnics-dpt-module.dts
index 2c38bbc09..59bb0dd40 100644
--- a/arch/mips/dts/ar9331-dptechnics-dpt-module.dts
+++ b/arch/mips/dts/ar9331-dptechnics-dpt-module.dts
@@ -11,6 +11,12 @@
 			compatible = "barebox,environment";
 			device-path = &spiflash, "partname:barebox-environment";
 		};
+
+		art@0 {
+			compatible = "qca,art-ar9331", "qca,art";
+			device-path = &spiflash_art;
+			barebox,provide-mac-address = <&mac0>;
+		};
 	};
 
 	leds {
@@ -30,6 +36,11 @@
 		label = "barebox-environment";
 		reg = <0x80000 0x10000>;
 	};
+
+	spiflash_art: partition@7f0000 {
+		label = "art";
+		reg = <0x7f0000 0x10000>;
+	};
 };
 
 &mac0 {
-- 
2.17.1


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

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

* Re: [PATCH v2 1/3] MIPS: ath79: provide driver for Atheros ART partition
  2018-06-07 19:55 [PATCH v2 1/3] MIPS: ath79: provide driver for Atheros ART partition Oleksij Rempel
  2018-06-07 19:55 ` [PATCH v2 2/3] MIPS: dts: tl_wdr4300: add " Oleksij Rempel
  2018-06-07 19:55 ` [PATCH v2 3/3] MIPS: dts: dpt-module: " Oleksij Rempel
@ 2018-06-08  7:08 ` Sascha Hauer
  2018-06-08  7:23   ` Oleksij Rempel
  2018-06-14  6:06 ` Sascha Hauer
  3 siblings, 1 reply; 6+ messages in thread
From: Sascha Hauer @ 2018-06-08  7:08 UTC (permalink / raw)
  To: Oleksij Rempel; +Cc: barebox, Oleksij Rempel

On Thu, Jun 07, 2018 at 09:55:50PM +0200, Oleksij Rempel wrote:
> From: Oleksij Rempel <linux@rempel-privat.de>
> 
> this partition contains calibration data for WiFi and
> some board specific data, like MAC address.
> 
> For now we care only about MAC.
> 
> Signed-off-by: Oleksij Rempel <linux@rempel-privat.de>
> ---

Have you missed Lucas' answer to this patch?

Sascha

>  arch/mips/mach-ath79/Makefile |   1 +
>  arch/mips/mach-ath79/art.c    | 112 ++++++++++++++++++++++++++++++++++
>  2 files changed, 113 insertions(+)
>  create mode 100644 arch/mips/mach-ath79/art.c
> 
> diff --git a/arch/mips/mach-ath79/Makefile b/arch/mips/mach-ath79/Makefile
> index 3772daeba..b827b363c 100644
> --- a/arch/mips/mach-ath79/Makefile
> +++ b/arch/mips/mach-ath79/Makefile
> @@ -1,2 +1,3 @@
>  obj-y += reset.o
>  obj-y += bbu.o
> +obj-y += art.o
> diff --git a/arch/mips/mach-ath79/art.c b/arch/mips/mach-ath79/art.c
> new file mode 100644
> index 000000000..984d08736
> --- /dev/null
> +++ b/arch/mips/mach-ath79/art.c
> @@ -0,0 +1,112 @@
> +// SPDX-License-Identifier: GPL-2.
> +/*
> + * Copyright (c) 2018 Oleksij Rempel <linux@rempel-privat.de>
> + */
> +
> +#include <common.h>
> +#include <fcntl.h>
> +#include <init.h>
> +#include <libfile.h>
> +#include <net.h>
> +#include <unistd.h>
> +
> +#define AR93000_EPPROM_OFFSET	0x1000
> +
> +struct ar9300_eeprom {
> +	u8 eeprom_version;
> +	u8 template_version;
> +	u8 mac_addr[6];
> +};
> +
> +static int art_set_mac(struct device_d *dev, struct ar9300_eeprom *eeprom)
> +{
> +	struct device_node *node = dev->device_node;
> +	struct device_node *rnode;
> +
> +	if (!node)
> +		return -ENOENT;
> +
> +	rnode = of_parse_phandle_from(node, NULL,
> +				     "barebox,provide-mac-address", 0);
> +	if (!rnode)
> +		return -ENOENT;
> +
> +	of_eth_register_ethaddr(rnode, &eeprom->mac_addr[0]);
> +
> +	return 0;
> +}
> +
> +static int art_read_mac(struct device_d *dev, const char *file)
> +{
> +	int fd, rbytes;
> +	struct ar9300_eeprom eeprom;
> +
> +	fd = open_and_lseek(file, O_RDONLY, AR93000_EPPROM_OFFSET);
> +	if (fd < 0) {
> +		dev_err(dev, "Failed to open eeprom path %s %d\n",
> +		       file, fd);
> +		return fd;
> +	}
> +
> +	rbytes = read_full(fd, &eeprom, sizeof(eeprom));
> +	close(fd);
> +	if (rbytes < sizeof(eeprom)) {
> +		dev_err(dev, "Failed to read %s\n", file);
> +		return rbytes < 0 ? rbytes : -EIO;
> +	}
> +
> +	dev_dbg(dev, "ART version: %x.%x\n",
> +		 eeprom.eeprom_version, eeprom.template_version);
> +	dev_dbg(dev, "mac: %02x:%02x:%02x:%02x:%02x:%02x\n",
> +	       eeprom.mac_addr[0],
> +	       eeprom.mac_addr[1],
> +	       eeprom.mac_addr[2],
> +	       eeprom.mac_addr[3],
> +	       eeprom.mac_addr[4],
> +	       eeprom.mac_addr[5]);
> +
> +	if (!is_valid_ether_addr(&eeprom.mac_addr[0])) {
> +		dev_err(dev, "bad MAC addr\n");
> +		return -EILSEQ;
> +	}
> +
> +	return art_set_mac(dev, &eeprom);
> +}
> +
> +static int art_probe(struct device_d *dev)
> +{
> +	char *path;
> +	int ret;
> +
> +	dev_dbg(dev, "found ART partition\n");
> +
> +	ret = of_find_path(dev->device_node, "device-path", &path, 0);
> +	if (ret) {
> +		dev_err(dev, "can't find path\n");
> +		return ret;
> +	}
> +
> +	return art_read_mac(dev, path);
> +}
> +
> +static struct of_device_id art_dt_ids[] = {
> +	{
> +		.compatible = "qca,art",
> +	}, {
> +		/* sentinel */
> +	}
> +};
> +
> +static struct driver_d art_driver = {
> +	.name		= "qca-art",
> +	.probe		= art_probe,
> +	.of_compatible	= art_dt_ids,
> +};
> +
> +static int art_of_driver_init(void)
> +{
> +	platform_driver_register(&art_driver);
> +
> +	return 0;
> +}
> +late_initcall(art_of_driver_init);
> -- 
> 2.17.1
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

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

* Re: [PATCH v2 1/3] MIPS: ath79: provide driver for Atheros ART partition
  2018-06-08  7:08 ` [PATCH v2 1/3] MIPS: ath79: provide driver for " Sascha Hauer
@ 2018-06-08  7:23   ` Oleksij Rempel
  0 siblings, 0 replies; 6+ messages in thread
From: Oleksij Rempel @ 2018-06-08  7:23 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox, Oleksij Rempel


[-- Attachment #1.1: Type: text/plain, Size: 5597 bytes --]

On Fri, Jun 08, 2018 at 09:08:04AM +0200, Sascha Hauer wrote:
> On Thu, Jun 07, 2018 at 09:55:50PM +0200, Oleksij Rempel wrote:
> > From: Oleksij Rempel <linux@rempel-privat.de>
> > 
> > this partition contains calibration data for WiFi and
> > some board specific data, like MAC address.
> > 
> > For now we care only about MAC.
> > 
> > Signed-off-by: Oleksij Rempel <linux@rempel-privat.de>
> > ---
> 
> Have you missed Lucas' answer to this patch?

Sorry forgot reflect it here:
there are different Atheros EEPROM formats. Some of them cover with CRC
complete image. Some of them only part of this image.
The EEPROM used on ar9331 (at least on my board) is covered only partially with CRC -
compressed baseband information, see http://web.mit.edu/freebsd/head/sys/contrib/dev/ath/ath_hal/ar9300/ar9300_eeprom.c
ar9300_compression_checksum()
the CRC check in ar9300_check_eeprom() is not enabled.

> Sascha
> 
> >  arch/mips/mach-ath79/Makefile |   1 +
> >  arch/mips/mach-ath79/art.c    | 112 ++++++++++++++++++++++++++++++++++
> >  2 files changed, 113 insertions(+)
> >  create mode 100644 arch/mips/mach-ath79/art.c
> > 
> > diff --git a/arch/mips/mach-ath79/Makefile b/arch/mips/mach-ath79/Makefile
> > index 3772daeba..b827b363c 100644
> > --- a/arch/mips/mach-ath79/Makefile
> > +++ b/arch/mips/mach-ath79/Makefile
> > @@ -1,2 +1,3 @@
> >  obj-y += reset.o
> >  obj-y += bbu.o
> > +obj-y += art.o
> > diff --git a/arch/mips/mach-ath79/art.c b/arch/mips/mach-ath79/art.c
> > new file mode 100644
> > index 000000000..984d08736
> > --- /dev/null
> > +++ b/arch/mips/mach-ath79/art.c
> > @@ -0,0 +1,112 @@
> > +// SPDX-License-Identifier: GPL-2.
> > +/*
> > + * Copyright (c) 2018 Oleksij Rempel <linux@rempel-privat.de>
> > + */
> > +
> > +#include <common.h>
> > +#include <fcntl.h>
> > +#include <init.h>
> > +#include <libfile.h>
> > +#include <net.h>
> > +#include <unistd.h>
> > +
> > +#define AR93000_EPPROM_OFFSET	0x1000
> > +
> > +struct ar9300_eeprom {
> > +	u8 eeprom_version;
> > +	u8 template_version;
> > +	u8 mac_addr[6];
> > +};
> > +
> > +static int art_set_mac(struct device_d *dev, struct ar9300_eeprom *eeprom)
> > +{
> > +	struct device_node *node = dev->device_node;
> > +	struct device_node *rnode;
> > +
> > +	if (!node)
> > +		return -ENOENT;
> > +
> > +	rnode = of_parse_phandle_from(node, NULL,
> > +				     "barebox,provide-mac-address", 0);
> > +	if (!rnode)
> > +		return -ENOENT;
> > +
> > +	of_eth_register_ethaddr(rnode, &eeprom->mac_addr[0]);
> > +
> > +	return 0;
> > +}
> > +
> > +static int art_read_mac(struct device_d *dev, const char *file)
> > +{
> > +	int fd, rbytes;
> > +	struct ar9300_eeprom eeprom;
> > +
> > +	fd = open_and_lseek(file, O_RDONLY, AR93000_EPPROM_OFFSET);
> > +	if (fd < 0) {
> > +		dev_err(dev, "Failed to open eeprom path %s %d\n",
> > +		       file, fd);
> > +		return fd;
> > +	}
> > +
> > +	rbytes = read_full(fd, &eeprom, sizeof(eeprom));
> > +	close(fd);
> > +	if (rbytes < sizeof(eeprom)) {
> > +		dev_err(dev, "Failed to read %s\n", file);
> > +		return rbytes < 0 ? rbytes : -EIO;
> > +	}
> > +
> > +	dev_dbg(dev, "ART version: %x.%x\n",
> > +		 eeprom.eeprom_version, eeprom.template_version);
> > +	dev_dbg(dev, "mac: %02x:%02x:%02x:%02x:%02x:%02x\n",
> > +	       eeprom.mac_addr[0],
> > +	       eeprom.mac_addr[1],
> > +	       eeprom.mac_addr[2],
> > +	       eeprom.mac_addr[3],
> > +	       eeprom.mac_addr[4],
> > +	       eeprom.mac_addr[5]);
> > +
> > +	if (!is_valid_ether_addr(&eeprom.mac_addr[0])) {
> > +		dev_err(dev, "bad MAC addr\n");
> > +		return -EILSEQ;
> > +	}
> > +
> > +	return art_set_mac(dev, &eeprom);
> > +}
> > +
> > +static int art_probe(struct device_d *dev)
> > +{
> > +	char *path;
> > +	int ret;
> > +
> > +	dev_dbg(dev, "found ART partition\n");
> > +
> > +	ret = of_find_path(dev->device_node, "device-path", &path, 0);
> > +	if (ret) {
> > +		dev_err(dev, "can't find path\n");
> > +		return ret;
> > +	}
> > +
> > +	return art_read_mac(dev, path);
> > +}
> > +
> > +static struct of_device_id art_dt_ids[] = {
> > +	{
> > +		.compatible = "qca,art",
> > +	}, {
> > +		/* sentinel */
> > +	}
> > +};
> > +
> > +static struct driver_d art_driver = {
> > +	.name		= "qca-art",
> > +	.probe		= art_probe,
> > +	.of_compatible	= art_dt_ids,
> > +};
> > +
> > +static int art_of_driver_init(void)
> > +{
> > +	platform_driver_register(&art_driver);
> > +
> > +	return 0;
> > +}
> > +late_initcall(art_of_driver_init);
> > -- 
> > 2.17.1
> > 
> > 
> > _______________________________________________
> > barebox mailing list
> > barebox@lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/barebox
> > 
> 
> -- 
> Pengutronix e.K.                           |                             |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 149 bytes --]

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

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

* Re: [PATCH v2 1/3] MIPS: ath79: provide driver for Atheros ART partition
  2018-06-07 19:55 [PATCH v2 1/3] MIPS: ath79: provide driver for Atheros ART partition Oleksij Rempel
                   ` (2 preceding siblings ...)
  2018-06-08  7:08 ` [PATCH v2 1/3] MIPS: ath79: provide driver for " Sascha Hauer
@ 2018-06-14  6:06 ` Sascha Hauer
  3 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2018-06-14  6:06 UTC (permalink / raw)
  To: Oleksij Rempel; +Cc: barebox, Oleksij Rempel

On Thu, Jun 07, 2018 at 09:55:50PM +0200, Oleksij Rempel wrote:
> From: Oleksij Rempel <linux@rempel-privat.de>
> 
> this partition contains calibration data for WiFi and
> some board specific data, like MAC address.
> 
> For now we care only about MAC.
> 
> Signed-off-by: Oleksij Rempel <linux@rempel-privat.de>
> ---

Applied, thanks

Sascha

>  arch/mips/mach-ath79/Makefile |   1 +
>  arch/mips/mach-ath79/art.c    | 112 ++++++++++++++++++++++++++++++++++
>  2 files changed, 113 insertions(+)
>  create mode 100644 arch/mips/mach-ath79/art.c
> 
> diff --git a/arch/mips/mach-ath79/Makefile b/arch/mips/mach-ath79/Makefile
> index 3772daeba..b827b363c 100644
> --- a/arch/mips/mach-ath79/Makefile
> +++ b/arch/mips/mach-ath79/Makefile
> @@ -1,2 +1,3 @@
>  obj-y += reset.o
>  obj-y += bbu.o
> +obj-y += art.o
> diff --git a/arch/mips/mach-ath79/art.c b/arch/mips/mach-ath79/art.c
> new file mode 100644
> index 000000000..984d08736
> --- /dev/null
> +++ b/arch/mips/mach-ath79/art.c
> @@ -0,0 +1,112 @@
> +// SPDX-License-Identifier: GPL-2.
> +/*
> + * Copyright (c) 2018 Oleksij Rempel <linux@rempel-privat.de>
> + */
> +
> +#include <common.h>
> +#include <fcntl.h>
> +#include <init.h>
> +#include <libfile.h>
> +#include <net.h>
> +#include <unistd.h>
> +
> +#define AR93000_EPPROM_OFFSET	0x1000
> +
> +struct ar9300_eeprom {
> +	u8 eeprom_version;
> +	u8 template_version;
> +	u8 mac_addr[6];
> +};
> +
> +static int art_set_mac(struct device_d *dev, struct ar9300_eeprom *eeprom)
> +{
> +	struct device_node *node = dev->device_node;
> +	struct device_node *rnode;
> +
> +	if (!node)
> +		return -ENOENT;
> +
> +	rnode = of_parse_phandle_from(node, NULL,
> +				     "barebox,provide-mac-address", 0);
> +	if (!rnode)
> +		return -ENOENT;
> +
> +	of_eth_register_ethaddr(rnode, &eeprom->mac_addr[0]);
> +
> +	return 0;
> +}
> +
> +static int art_read_mac(struct device_d *dev, const char *file)
> +{
> +	int fd, rbytes;
> +	struct ar9300_eeprom eeprom;
> +
> +	fd = open_and_lseek(file, O_RDONLY, AR93000_EPPROM_OFFSET);
> +	if (fd < 0) {
> +		dev_err(dev, "Failed to open eeprom path %s %d\n",
> +		       file, fd);
> +		return fd;
> +	}
> +
> +	rbytes = read_full(fd, &eeprom, sizeof(eeprom));
> +	close(fd);
> +	if (rbytes < sizeof(eeprom)) {
> +		dev_err(dev, "Failed to read %s\n", file);
> +		return rbytes < 0 ? rbytes : -EIO;
> +	}
> +
> +	dev_dbg(dev, "ART version: %x.%x\n",
> +		 eeprom.eeprom_version, eeprom.template_version);
> +	dev_dbg(dev, "mac: %02x:%02x:%02x:%02x:%02x:%02x\n",
> +	       eeprom.mac_addr[0],
> +	       eeprom.mac_addr[1],
> +	       eeprom.mac_addr[2],
> +	       eeprom.mac_addr[3],
> +	       eeprom.mac_addr[4],
> +	       eeprom.mac_addr[5]);
> +
> +	if (!is_valid_ether_addr(&eeprom.mac_addr[0])) {
> +		dev_err(dev, "bad MAC addr\n");
> +		return -EILSEQ;
> +	}
> +
> +	return art_set_mac(dev, &eeprom);
> +}
> +
> +static int art_probe(struct device_d *dev)
> +{
> +	char *path;
> +	int ret;
> +
> +	dev_dbg(dev, "found ART partition\n");
> +
> +	ret = of_find_path(dev->device_node, "device-path", &path, 0);
> +	if (ret) {
> +		dev_err(dev, "can't find path\n");
> +		return ret;
> +	}
> +
> +	return art_read_mac(dev, path);
> +}
> +
> +static struct of_device_id art_dt_ids[] = {
> +	{
> +		.compatible = "qca,art",
> +	}, {
> +		/* sentinel */
> +	}
> +};
> +
> +static struct driver_d art_driver = {
> +	.name		= "qca-art",
> +	.probe		= art_probe,
> +	.of_compatible	= art_dt_ids,
> +};
> +
> +static int art_of_driver_init(void)
> +{
> +	platform_driver_register(&art_driver);
> +
> +	return 0;
> +}
> +late_initcall(art_of_driver_init);
> -- 
> 2.17.1
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

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

end of thread, other threads:[~2018-06-14  6:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-07 19:55 [PATCH v2 1/3] MIPS: ath79: provide driver for Atheros ART partition Oleksij Rempel
2018-06-07 19:55 ` [PATCH v2 2/3] MIPS: dts: tl_wdr4300: add " Oleksij Rempel
2018-06-07 19:55 ` [PATCH v2 3/3] MIPS: dts: dpt-module: " Oleksij Rempel
2018-06-08  7:08 ` [PATCH v2 1/3] MIPS: ath79: provide driver for " Sascha Hauer
2018-06-08  7:23   ` Oleksij Rempel
2018-06-14  6:06 ` Sascha Hauer

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