mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2 1/2] nvmem: Introduce nvmem_cell_get_and_read()
@ 2018-06-28  4:42 Andrey Smirnov
  2018-06-28  4:42 ` [PATCH v2 2/2] ARM: rdu2: Fetch MAC address info from RAVE SP EEPROM Andrey Smirnov
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Andrey Smirnov @ 2018-06-28  4:42 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Introduce nvmem_cell_get_and_read() that combines getting a NVMEM cell
by name and reading its contents.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---

Changes since [v1]:

    - Added missing newline to core.c

[v1] http://lists.infradead.org/pipermail/barebox/2018-June/033857.html

 drivers/nvmem/core.c           | 23 +++++++++++++++++++++++
 include/linux/nvmem-consumer.h | 10 ++++++++++
 2 files changed, 33 insertions(+)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 53b934bb3..c0f61f453 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -750,3 +750,26 @@ int nvmem_device_write(struct nvmem_device *nvmem,
 	return bytes;
 }
 EXPORT_SYMBOL_GPL(nvmem_device_write);
+
+void *nvmem_cell_get_and_read(struct device_node *np, const char *cell_name,
+			      size_t bytes)
+{
+	struct nvmem_cell *cell;
+	void *value;
+	size_t len;
+
+	cell = of_nvmem_cell_get(np, cell_name);
+	if (IS_ERR(cell))
+		return cell;
+
+	value = nvmem_cell_read(cell, &len);
+	if (!IS_ERR(value) && len != bytes) {
+		kfree(value);
+		value = ERR_PTR(-EINVAL);
+	}
+
+	nvmem_cell_put(cell);
+
+	return value;
+}
+EXPORT_SYMBOL_GPL(nvmem_cell_get_and_read);
diff --git a/include/linux/nvmem-consumer.h b/include/linux/nvmem-consumer.h
index 606cadb49..0ec2f05b9 100644
--- a/include/linux/nvmem-consumer.h
+++ b/include/linux/nvmem-consumer.h
@@ -32,6 +32,9 @@ struct nvmem_cell_info {
 struct nvmem_cell *nvmem_cell_get(struct device_d *dev, const char *name);
 void nvmem_cell_put(struct nvmem_cell *cell);
 void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len);
+void *nvmem_cell_get_and_read(struct device_node *np, const char *cell_name,
+			      size_t bytes);
+
 int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len);
 
 /* direct nvmem device read/write interface */
@@ -55,6 +58,13 @@ static inline char *nvmem_cell_read(struct nvmem_cell *cell, size_t *len)
 	return ERR_PTR(-ENOSYS);
 }
 
+static inline void *nvmem_cell_get_and_read(struct device_node *np,
+					    const char *cell_name,
+					    size_t bytes)
+{
+	return ERR_PTR(-ENOSYS);
+}
+
 static inline int nvmem_cell_write(struct nvmem_cell *cell,
 				    const char *buf, size_t len)
 {
-- 
2.17.1


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

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

* [PATCH v2 2/2] ARM: rdu2: Fetch MAC address info from RAVE SP EEPROM
  2018-06-28  4:42 [PATCH v2 1/2] nvmem: Introduce nvmem_cell_get_and_read() Andrey Smirnov
@ 2018-06-28  4:42 ` Andrey Smirnov
  2018-06-28  9:46 ` [PATCH v2 1/2] nvmem: Introduce nvmem_cell_get_and_read() Lucas Stach
  2018-06-29  5:05 ` Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Andrey Smirnov @ 2018-06-28  4:42 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

RDU2 stores MAC addresses for its Ethernet interfaces in main RAVE SP
EEPROM. Add code to properly integrate it.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 arch/arm/boards/zii-imx6q-rdu2/board.c | 57 ++++++++++++++++++++++++++
 arch/arm/dts/imx6qdl-zii-rdu2.dtsi     | 15 +++++++
 2 files changed, 72 insertions(+)

diff --git a/arch/arm/boards/zii-imx6q-rdu2/board.c b/arch/arm/boards/zii-imx6q-rdu2/board.c
index 265f97e2f..f6c908c9f 100644
--- a/arch/arm/boards/zii-imx6q-rdu2/board.c
+++ b/arch/arm/boards/zii-imx6q-rdu2/board.c
@@ -19,6 +19,8 @@
 #include <init.h>
 #include <mach/bbu.h>
 #include <mach/imx6.h>
+#include <net.h>
+#include <linux/nvmem-consumer.h>
 
 #define RDU2_DAC1_RESET	IMX_GPIO_NR(1, 0)
 #define RDU2_DAC2_RESET	IMX_GPIO_NR(1, 2)
@@ -151,3 +153,58 @@ static int rdu2_devices_init(void)
 	return 0;
 }
 device_initcall(rdu2_devices_init);
+
+static int rdu2_eth_register_ethaddr(struct device_node *np)
+{
+	u8 mac[ETH_ALEN];
+	u8 *data;
+	int i;
+
+	data = nvmem_cell_get_and_read(np, "mac-address", ETH_ALEN);
+	if (IS_ERR(data))
+		return PTR_ERR(data);
+	/*
+	 * EEPROM stores MAC address in reverse (to what we expect it
+	 * to be) byte order.
+	 */
+	for (i = 0; i < ETH_ALEN; i++)
+		mac[i] = data[ETH_ALEN - i - 1];
+
+	free(data);
+
+	of_eth_register_ethaddr(np, mac);
+
+	return 0;
+}
+
+static int rdu2_ethernet_init(void)
+{
+	const char *aliases[] = { "ethernet0", "ethernet1" };
+	struct device_node *np, *root;
+	int i, ret;
+
+	if (!of_machine_is_compatible("zii,imx6q-zii-rdu2") &&
+	    !of_machine_is_compatible("zii,imx6qp-zii-rdu2"))
+		return 0;
+
+	root = of_get_root_node();
+
+	for (i = 0; i < ARRAY_SIZE(aliases); i++) {
+		const char *alias = aliases[i];
+
+		np = of_find_node_by_alias(root, alias);
+		if (!np) {
+			pr_warn("Failed to find %s\n", alias);
+			continue;
+		}
+
+		ret = rdu2_eth_register_ethaddr(np);
+		if (ret) {
+			pr_warn("Failed to register MAC for %s\n", alias);
+			continue;
+		}
+	}
+
+	return 0;
+}
+late_initcall(rdu2_ethernet_init);
diff --git a/arch/arm/dts/imx6qdl-zii-rdu2.dtsi b/arch/arm/dts/imx6qdl-zii-rdu2.dtsi
index bb5321e62..68ee78002 100644
--- a/arch/arm/dts/imx6qdl-zii-rdu2.dtsi
+++ b/arch/arm/dts/imx6qdl-zii-rdu2.dtsi
@@ -85,6 +85,14 @@
 			boot_source: boot-source@83 {
 				reg = <0x83 1>;
 			};
+
+			mac_address_0: mac-address@180 {
+				reg = <0x180 6>;
+			};
+
+			mac_address_1: mac-address@190 {
+				reg = <0x190 6>;
+			};
 		};
 
 		backlight {
@@ -181,6 +189,11 @@
 	};
 };
 
+&fec {
+	nvmem-cells = <&mac_address_0>;
+	nvmem-cell-names = "mac-address";
+};
+
 &i2c2 {
 	temp-sense@48 {
 		barebox,sensor-name = "Temp Sensor 1";
@@ -196,6 +209,8 @@
 
 		i210: i210@0 {
 			reg = <0 0 0 0 0>;
+			nvmem-cells = <&mac_address_1>;
+			nvmem-cell-names = "mac-address";
 		};
 	};
 };
-- 
2.17.1


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

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

* Re: [PATCH v2 1/2] nvmem: Introduce nvmem_cell_get_and_read()
  2018-06-28  4:42 [PATCH v2 1/2] nvmem: Introduce nvmem_cell_get_and_read() Andrey Smirnov
  2018-06-28  4:42 ` [PATCH v2 2/2] ARM: rdu2: Fetch MAC address info from RAVE SP EEPROM Andrey Smirnov
@ 2018-06-28  9:46 ` Lucas Stach
  2018-06-29  5:05 ` Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Lucas Stach @ 2018-06-28  9:46 UTC (permalink / raw)
  To: Andrey Smirnov, barebox

Am Mittwoch, den 27.06.2018, 21:42 -0700 schrieb Andrey Smirnov:
> Introduce nvmem_cell_get_and_read() that combines getting a NVMEM cell
> by name and reading its contents.
> 
> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>

For the series:
Reviewed-by: Lucas Stach <l.stach@pengutronix.de>

> ---
> 
> Changes since [v1]:
> 
>     - Added missing newline to core.c
> 
> [v1] http://lists.infradead.org/pipermail/barebox/2018-June/033857.html
> 
>  drivers/nvmem/core.c           | 23 +++++++++++++++++++++++
>  include/linux/nvmem-consumer.h | 10 ++++++++++
>  2 files changed, 33 insertions(+)
> 
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index 53b934bb3..c0f61f453 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
> @@ -750,3 +750,26 @@ int nvmem_device_write(struct nvmem_device *nvmem,
> >  	return bytes;
>  }
>  EXPORT_SYMBOL_GPL(nvmem_device_write);
> +
> +void *nvmem_cell_get_and_read(struct device_node *np, const char *cell_name,
> > +			      size_t bytes)
> +{
> > +	struct nvmem_cell *cell;
> > +	void *value;
> > +	size_t len;
> +
> > +	cell = of_nvmem_cell_get(np, cell_name);
> > +	if (IS_ERR(cell))
> > +		return cell;
> +
> > +	value = nvmem_cell_read(cell, &len);
> > +	if (!IS_ERR(value) && len != bytes) {
> > +		kfree(value);
> > +		value = ERR_PTR(-EINVAL);
> > +	}
> +
> > +	nvmem_cell_put(cell);
> +
> > +	return value;
> +}
> +EXPORT_SYMBOL_GPL(nvmem_cell_get_and_read);
> diff --git a/include/linux/nvmem-consumer.h b/include/linux/nvmem-consumer.h
> index 606cadb49..0ec2f05b9 100644
> --- a/include/linux/nvmem-consumer.h
> +++ b/include/linux/nvmem-consumer.h
> @@ -32,6 +32,9 @@ struct nvmem_cell_info {
>  struct nvmem_cell *nvmem_cell_get(struct device_d *dev, const char *name);
>  void nvmem_cell_put(struct nvmem_cell *cell);
>  void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len);
> +void *nvmem_cell_get_and_read(struct device_node *np, const char *cell_name,
> > +			      size_t bytes);
> +
>  int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len);
>  
>  /* direct nvmem device read/write interface */
> @@ -55,6 +58,13 @@ static inline char *nvmem_cell_read(struct nvmem_cell *cell, size_t *len)
> >  	return ERR_PTR(-ENOSYS);
>  }
>  
> +static inline void *nvmem_cell_get_and_read(struct device_node *np,
> > +					    const char *cell_name,
> > +					    size_t bytes)
> +{
> > +	return ERR_PTR(-ENOSYS);
> +}
> +
>  static inline int nvmem_cell_write(struct nvmem_cell *cell,
> >  				    const char *buf, size_t len)
>  {

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

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

* Re: [PATCH v2 1/2] nvmem: Introduce nvmem_cell_get_and_read()
  2018-06-28  4:42 [PATCH v2 1/2] nvmem: Introduce nvmem_cell_get_and_read() Andrey Smirnov
  2018-06-28  4:42 ` [PATCH v2 2/2] ARM: rdu2: Fetch MAC address info from RAVE SP EEPROM Andrey Smirnov
  2018-06-28  9:46 ` [PATCH v2 1/2] nvmem: Introduce nvmem_cell_get_and_read() Lucas Stach
@ 2018-06-29  5:05 ` Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2018-06-29  5:05 UTC (permalink / raw)
  To: Andrey Smirnov; +Cc: barebox

On Wed, Jun 27, 2018 at 09:42:26PM -0700, Andrey Smirnov wrote:
> Introduce nvmem_cell_get_and_read() that combines getting a NVMEM cell
> by name and reading its contents.
> 
> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> ---
> 
> Changes since [v1]:
> 
>     - Added missing newline to core.c

Applied, thanks

Sascha

> 
> [v1] http://lists.infradead.org/pipermail/barebox/2018-June/033857.html
> 
>  drivers/nvmem/core.c           | 23 +++++++++++++++++++++++
>  include/linux/nvmem-consumer.h | 10 ++++++++++
>  2 files changed, 33 insertions(+)
> 
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index 53b934bb3..c0f61f453 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
> @@ -750,3 +750,26 @@ int nvmem_device_write(struct nvmem_device *nvmem,
>  	return bytes;
>  }
>  EXPORT_SYMBOL_GPL(nvmem_device_write);
> +
> +void *nvmem_cell_get_and_read(struct device_node *np, const char *cell_name,
> +			      size_t bytes)
> +{
> +	struct nvmem_cell *cell;
> +	void *value;
> +	size_t len;
> +
> +	cell = of_nvmem_cell_get(np, cell_name);
> +	if (IS_ERR(cell))
> +		return cell;
> +
> +	value = nvmem_cell_read(cell, &len);
> +	if (!IS_ERR(value) && len != bytes) {
> +		kfree(value);
> +		value = ERR_PTR(-EINVAL);
> +	}
> +
> +	nvmem_cell_put(cell);
> +
> +	return value;
> +}
> +EXPORT_SYMBOL_GPL(nvmem_cell_get_and_read);
> diff --git a/include/linux/nvmem-consumer.h b/include/linux/nvmem-consumer.h
> index 606cadb49..0ec2f05b9 100644
> --- a/include/linux/nvmem-consumer.h
> +++ b/include/linux/nvmem-consumer.h
> @@ -32,6 +32,9 @@ struct nvmem_cell_info {
>  struct nvmem_cell *nvmem_cell_get(struct device_d *dev, const char *name);
>  void nvmem_cell_put(struct nvmem_cell *cell);
>  void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len);
> +void *nvmem_cell_get_and_read(struct device_node *np, const char *cell_name,
> +			      size_t bytes);
> +
>  int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len);
>  
>  /* direct nvmem device read/write interface */
> @@ -55,6 +58,13 @@ static inline char *nvmem_cell_read(struct nvmem_cell *cell, size_t *len)
>  	return ERR_PTR(-ENOSYS);
>  }
>  
> +static inline void *nvmem_cell_get_and_read(struct device_node *np,
> +					    const char *cell_name,
> +					    size_t bytes)
> +{
> +	return ERR_PTR(-ENOSYS);
> +}
> +
>  static inline int nvmem_cell_write(struct nvmem_cell *cell,
>  				    const char *buf, size_t len)
>  {
> -- 
> 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] 4+ messages in thread

end of thread, other threads:[~2018-06-29  5:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-28  4:42 [PATCH v2 1/2] nvmem: Introduce nvmem_cell_get_and_read() Andrey Smirnov
2018-06-28  4:42 ` [PATCH v2 2/2] ARM: rdu2: Fetch MAC address info from RAVE SP EEPROM Andrey Smirnov
2018-06-28  9:46 ` [PATCH v2 1/2] nvmem: Introduce nvmem_cell_get_and_read() Lucas Stach
2018-06-29  5:05 ` Sascha Hauer

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