mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Lucas Stach <l.stach@pengutronix.de>
To: Oleksij Rempel <o.rempel@pengutronix.de>, barebox@lists.infradead.org
Cc: Oleksij Rempel <linux@rempel-privat.de>
Subject: Re: [PATCH v1 1/3] MIPS: ath79: provide driver for Atheros ART partition
Date: Wed, 06 Jun 2018 11:14:25 +0200	[thread overview]
Message-ID: <1528276465.26063.10.camel@pengutronix.de> (raw)
In-Reply-To: <20180605181021.10467-1-o.rempel@pengutronix.de>

Am Dienstag, den 05.06.2018, 20:10 +0200 schrieb 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.

I think you mentioned that this partition has some kind of CRC. Would
be nice to handle this, as it would add a bit more robustness.

> 
> > Signed-off-by: Oleksij Rempel <linux@rempel-privat.de>
> ---
>  arch/mips/mach-ath79/Makefile |   1 +
>  arch/mips/mach-ath79/art.c    | 110 ++++++++++++++++++++++++++++++++++
>  2 files changed, 111 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..cf482f8fb
> --- /dev/null
> +++ b/arch/mips/mach-ath79/art.c
> @@ -0,0 +1,110 @@
> +// SPDX-License-Identifier: GPL-2.

Incomplete SPDX tag.

> +/*
> > + * 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>
> +
> +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, 0x1000);
> > +	if (fd < 0) {
> > +		dev_err(dev, "Failed to open eeprom path %s %d\n",
> > +		       file, -errno);
> > +		return -errno;
> > +	}
> +
> > +	rbytes = read_full(fd, &eeprom, sizeof(eeprom));
> > +	close(fd);
> > +	if (rbytes <= 0 || rbytes < sizeof(eeprom)) {
> > +		dev_err(dev, "Failed to read %s\n", file);
> > +		return -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);

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

      parent reply	other threads:[~2018-06-06  9:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-05 18:10 Oleksij Rempel
2018-06-05 18:10 ` [PATCH v1 2/3] MIPS: dts: tl_wdr4300: add " Oleksij Rempel
2018-06-05 18:10 ` [PATCH v1 3/3] MIPS: dts: dpt-module: " Oleksij Rempel
2018-06-06  7:35   ` Sascha Hauer
2018-06-05 19:03 ` [PATCH v1 1/3] MIPS: ath79: provide driver for " Sam Ravnborg
2018-06-06  9:14 ` Lucas Stach [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1528276465.26063.10.camel@pengutronix.de \
    --to=l.stach@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=linux@rempel-privat.de \
    --cc=o.rempel@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox