diff mbox series

[V2,07/14] ARM: dts: stm32: Use DT alias for the configuration EEPROM

Message ID 20200331004851.282583-8-marex@denx.de
State Superseded
Headers show
Series ARM: stm32: Fix Avenger96 | expand

Commit Message

Marek Vasut March 31, 2020, 12:48 a.m. UTC
Use DT /aliases node to establish a stable phandle to the configuration
EEPROM. This permits the configuration EEPROM to be moved e.g. to a
different address or a different bus. Adjust the board code to handle
new phandle lookup.

Signed-off-by: Marek Vasut <marex at denx.de>
Cc: Patrick Delaunay <patrick.delaunay at st.com>
Cc: Patrice Chotard <patrice.chotard at st.com>
---
V2: No change
---
 arch/arm/dts/stm32mp15xx-dhcom.dtsi     |  6 +++++-
 board/dhelectronics/dh_stm32mp1/board.c | 15 +++++++--------
 2 files changed, 12 insertions(+), 9 deletions(-)

Comments

Patrice CHOTARD March 31, 2020, 8:34 a.m. UTC | #1
Hi Marek

On 3/31/20 2:48 AM, Marek Vasut wrote:
> Use DT /aliases node to establish a stable phandle to the configuration
> EEPROM. This permits the configuration EEPROM to be moved e.g. to a
> different address or a different bus. Adjust the board code to handle
> new phandle lookup.
>
> Signed-off-by: Marek Vasut <marex at denx.de>
> Cc: Patrick Delaunay <patrick.delaunay at st.com>
> Cc: Patrice Chotard <patrice.chotard at st.com>

Reviewed-by: Patrice Chotard <patrice.chotard at st.com>

Thanks


> ---
> V2: No change
> ---
>  arch/arm/dts/stm32mp15xx-dhcom.dtsi     |  6 +++++-
>  board/dhelectronics/dh_stm32mp1/board.c | 15 +++++++--------
>  2 files changed, 12 insertions(+), 9 deletions(-)
>
> diff --git a/arch/arm/dts/stm32mp15xx-dhcom.dtsi b/arch/arm/dts/stm32mp15xx-dhcom.dtsi
> index bed69c97b6..e5be0a79ac 100644
> --- a/arch/arm/dts/stm32mp15xx-dhcom.dtsi
> +++ b/arch/arm/dts/stm32mp15xx-dhcom.dtsi
> @@ -10,6 +10,10 @@
>  #include <dt-bindings/mfd/st,stpmic1.h>
>  
>  / {
> +	aliases {
> +		eeprom0 = &eeprom0;
> +	};
> +
>  	memory at c0000000 {
>  		device_type = "memory";
>  		reg = <0xC0000000 0x40000000>;
> @@ -187,7 +191,7 @@
>  		};
>  	};
>  
> -	eeprom at 50 {
> +	eeprom0: eeprom at 50 {
>  		compatible = "atmel,24c02";
>  		reg = <0x50>;
>  		pagesize = <16>;
> diff --git a/board/dhelectronics/dh_stm32mp1/board.c b/board/dhelectronics/dh_stm32mp1/board.c
> index 109d9ec935..a3458a2623 100644
> --- a/board/dhelectronics/dh_stm32mp1/board.c
> +++ b/board/dhelectronics/dh_stm32mp1/board.c
> @@ -78,22 +78,21 @@ DECLARE_GLOBAL_DATA_PTR;
>  
>  int setup_mac_address(void)
>  {
> -	struct udevice *dev;
> -	ofnode eeprom;
>  	unsigned char enetaddr[6];
> -	int ret;
> +	struct udevice *dev;
> +	int off, ret;
>  
>  	ret = eth_env_get_enetaddr("ethaddr", enetaddr);
>  	if (ret)	/* ethaddr is already set */
>  		return 0;
>  
> -	eeprom = ofnode_path("/soc/i2c at 5c002000/eeprom at 50");
> -	if (!ofnode_valid(eeprom)) {
> -		printf("Invalid hardware path to EEPROM!\n");
> -		return -ENODEV;
> +	off = fdt_path_offset(gd->fdt_blob, "eeprom0");
> +	if (off < 0) {
> +		printf("%s: No eeprom0 path offset\n", __func__);
> +		return off;
>  	}
>  
> -	ret = uclass_get_device_by_ofnode(UCLASS_I2C_EEPROM, eeprom, &dev);
> +	ret = uclass_get_device_by_of_offset(UCLASS_I2C_EEPROM, off, &dev);
>  	if (ret) {
>  		printf("Cannot find EEPROM!\n");
>  		return ret;
Patrick Delaunay March 31, 2020, 1:56 p.m. UTC | #2
Hi Marek,

> From: Marek Vasut <marex at denx.de>
> Sent: mardi 31 mars 2020 02:49
> 
> Use DT /aliases node to establish a stable phandle to the configuration EEPROM.
> This permits the configuration EEPROM to be moved e.g. to a different address or
> a different bus. Adjust the board code to handle new phandle lookup.
> 
> Signed-off-by: Marek Vasut <marex at denx.de>
> Cc: Patrick Delaunay <patrick.delaunay at st.com>
> Cc: Patrice Chotard <patrice.chotard at st.com>
> ---
> V2: No change
> ---

Reviewed-by: Patrick Delaunay <patrick.delaunay at st.com>

Thanks

Patrick
diff mbox series

Patch

diff --git a/arch/arm/dts/stm32mp15xx-dhcom.dtsi b/arch/arm/dts/stm32mp15xx-dhcom.dtsi
index bed69c97b6..e5be0a79ac 100644
--- a/arch/arm/dts/stm32mp15xx-dhcom.dtsi
+++ b/arch/arm/dts/stm32mp15xx-dhcom.dtsi
@@ -10,6 +10,10 @@ 
 #include <dt-bindings/mfd/st,stpmic1.h>
 
 / {
+	aliases {
+		eeprom0 = &eeprom0;
+	};
+
 	memory at c0000000 {
 		device_type = "memory";
 		reg = <0xC0000000 0x40000000>;
@@ -187,7 +191,7 @@ 
 		};
 	};
 
-	eeprom at 50 {
+	eeprom0: eeprom at 50 {
 		compatible = "atmel,24c02";
 		reg = <0x50>;
 		pagesize = <16>;
diff --git a/board/dhelectronics/dh_stm32mp1/board.c b/board/dhelectronics/dh_stm32mp1/board.c
index 109d9ec935..a3458a2623 100644
--- a/board/dhelectronics/dh_stm32mp1/board.c
+++ b/board/dhelectronics/dh_stm32mp1/board.c
@@ -78,22 +78,21 @@  DECLARE_GLOBAL_DATA_PTR;
 
 int setup_mac_address(void)
 {
-	struct udevice *dev;
-	ofnode eeprom;
 	unsigned char enetaddr[6];
-	int ret;
+	struct udevice *dev;
+	int off, ret;
 
 	ret = eth_env_get_enetaddr("ethaddr", enetaddr);
 	if (ret)	/* ethaddr is already set */
 		return 0;
 
-	eeprom = ofnode_path("/soc/i2c at 5c002000/eeprom at 50");
-	if (!ofnode_valid(eeprom)) {
-		printf("Invalid hardware path to EEPROM!\n");
-		return -ENODEV;
+	off = fdt_path_offset(gd->fdt_blob, "eeprom0");
+	if (off < 0) {
+		printf("%s: No eeprom0 path offset\n", __func__);
+		return off;
 	}
 
-	ret = uclass_get_device_by_ofnode(UCLASS_I2C_EEPROM, eeprom, &dev);
+	ret = uclass_get_device_by_of_offset(UCLASS_I2C_EEPROM, off, &dev);
 	if (ret) {
 		printf("Cannot find EEPROM!\n");
 		return ret;