diff mbox series

[U-Boot,v1,16/21] display5: net: Add function to read ethaddr from iMX6 fuses

Message ID 20180511145119.20942-17-lukma@denx.de
State Accepted
Commit c451713abf10db335cabe41099e8b28481a723b7
Delegated to: Stefano Babic
Headers show
Series This patch series brings in sync DISPLAY5 internal | expand

Commit Message

Lukasz Majewski May 11, 2018, 2:51 p.m. UTC
Signed-off-by: Lukasz Majewski <lukma@denx.de>
---

 board/liebherr/display5/display5.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

Comments

Joe Hershberger May 15, 2018, 9:16 p.m. UTC | #1
Hi Lukasz,

On Fri, May 11, 2018 at 9:51 AM, Lukasz Majewski <lukma@denx.de> wrote:
> Signed-off-by: Lukasz Majewski <lukma@denx.de>
> ---
>
>  board/liebherr/display5/display5.c | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
>
> diff --git a/board/liebherr/display5/display5.c b/board/liebherr/display5/display5.c
> index 4bade476a5..a3deba216c 100644
> --- a/board/liebherr/display5/display5.c
> +++ b/board/liebherr/display5/display5.c
> @@ -254,6 +254,25 @@ static void setup_iomux_enet(void)
>         gpio_direction_input(IMX_GPIO_NR(1, 28)); /*INT#_GBE*/
>  }
>
> +static int setup_mac_from_fuse(void)
> +{
> +       unsigned char enetaddr[6];
> +       int ret;
> +
> +       ret = eth_env_get_enetaddr("ethaddr", enetaddr);
> +       if (ret)        /* ethaddr is already set */
> +               return 0;
> +
> +       imx_get_mac_from_fuse(0, enetaddr);

Generally this should be registered as a read_rom_hwaddr handler.

Then you won't be recreating the logic around what to do with it.

> +
> +       if (is_valid_ethaddr(enetaddr)) {
> +               eth_env_set_enetaddr("ethaddr", enetaddr);
> +               return 0;
> +       }
> +
> +       return 0;
> +}
> +
>  int board_eth_init(bd_t *bd)
>  {
>         struct phy_device *phydev;
> @@ -268,6 +287,8 @@ int board_eth_init(bd_t *bd)
>         if (ret)
>                 return ret;
>
> +       setup_mac_from_fuse();
> +
>         bus = fec_get_miibus(IMX_FEC_BASE, -1);
>         if (!bus)
>                 return -ENODEV;
> --
> 2.11.0
>
> _______________________________________________
> U-Boot mailing list
> U-Boot@lists.denx.de
> https://lists.denx.de/listinfo/u-boot
Lukasz Majewski May 16, 2018, 2:46 p.m. UTC | #2
Hi Joe,

> Hi Lukasz,
> 
> On Fri, May 11, 2018 at 9:51 AM, Lukasz Majewski <lukma@denx.de>
> wrote:
> > Signed-off-by: Lukasz Majewski <lukma@denx.de>
> > ---
> >
> >  board/liebherr/display5/display5.c | 21 +++++++++++++++++++++
> >  1 file changed, 21 insertions(+)
> >
> > diff --git a/board/liebherr/display5/display5.c
> > b/board/liebherr/display5/display5.c index 4bade476a5..a3deba216c
> > 100644 --- a/board/liebherr/display5/display5.c
> > +++ b/board/liebherr/display5/display5.c
> > @@ -254,6 +254,25 @@ static void setup_iomux_enet(void)
> >         gpio_direction_input(IMX_GPIO_NR(1, 28)); /*INT#_GBE*/
> >  }
> >
> > +static int setup_mac_from_fuse(void)
> > +{
> > +       unsigned char enetaddr[6];
> > +       int ret;
> > +
> > +       ret = eth_env_get_enetaddr("ethaddr", enetaddr);
> > +       if (ret)        /* ethaddr is already set */
> > +               return 0;
> > +
> > +       imx_get_mac_from_fuse(0, enetaddr);  
> 
> Generally this should be registered as a read_rom_hwaddr handler.

This function seems like a generic approach for IMX SoC:
arch/arm/mach-imx/mac.c

On the other hand the fec_mxc.c driver seems to have such function:

	.read_rom_hwaddr	= fecmxc_read_rom_hwaddr,
(which latter on calls the above function).

To use this function in the automatic way I would need to enable DM_ETH
for this board.

> 
> Then you won't be recreating the logic around what to do with it.
> 
> > +
> > +       if (is_valid_ethaddr(enetaddr)) {
> > +               eth_env_set_enetaddr("ethaddr", enetaddr);
> > +               return 0;
> > +       }
> > +
> > +       return 0;
> > +}
> > +
> >  int board_eth_init(bd_t *bd)
> >  {
> >         struct phy_device *phydev;
> > @@ -268,6 +287,8 @@ int board_eth_init(bd_t *bd)
> >         if (ret)
> >                 return ret;
> >
> > +       setup_mac_from_fuse();
> > +
> >         bus = fec_get_miibus(IMX_FEC_BASE, -1);
> >         if (!bus)
> >                 return -ENODEV;
> > --
> > 2.11.0
> >
> > _______________________________________________
> > U-Boot mailing list
> > U-Boot@lists.denx.de
> > https://lists.denx.de/listinfo/u-boot  




Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de
Joe Hershberger May 16, 2018, 4:14 p.m. UTC | #3
On Wed, May 16, 2018 at 9:46 AM, Lukasz Majewski <lukma@denx.de> wrote:
> Hi Joe,
>
>> Hi Lukasz,
>>
>> On Fri, May 11, 2018 at 9:51 AM, Lukasz Majewski <lukma@denx.de>
>> wrote:
>> > Signed-off-by: Lukasz Majewski <lukma@denx.de>
>> > ---
>> >
>> >  board/liebherr/display5/display5.c | 21 +++++++++++++++++++++
>> >  1 file changed, 21 insertions(+)
>> >
>> > diff --git a/board/liebherr/display5/display5.c
>> > b/board/liebherr/display5/display5.c index 4bade476a5..a3deba216c
>> > 100644 --- a/board/liebherr/display5/display5.c
>> > +++ b/board/liebherr/display5/display5.c
>> > @@ -254,6 +254,25 @@ static void setup_iomux_enet(void)
>> >         gpio_direction_input(IMX_GPIO_NR(1, 28)); /*INT#_GBE*/
>> >  }
>> >
>> > +static int setup_mac_from_fuse(void)
>> > +{
>> > +       unsigned char enetaddr[6];
>> > +       int ret;
>> > +
>> > +       ret = eth_env_get_enetaddr("ethaddr", enetaddr);
>> > +       if (ret)        /* ethaddr is already set */
>> > +               return 0;
>> > +
>> > +       imx_get_mac_from_fuse(0, enetaddr);
>>
>> Generally this should be registered as a read_rom_hwaddr handler.
>
> This function seems like a generic approach for IMX SoC:
> arch/arm/mach-imx/mac.c
>
> On the other hand the fec_mxc.c driver seems to have such function:
>
>         .read_rom_hwaddr        = fecmxc_read_rom_hwaddr,
> (which latter on calls the above function).
>
> To use this function in the automatic way I would need to enable DM_ETH
> for this board.

Good idea.

>> Then you won't be recreating the logic around what to do with it.
>>
>> > +
>> > +       if (is_valid_ethaddr(enetaddr)) {
>> > +               eth_env_set_enetaddr("ethaddr", enetaddr);
>> > +               return 0;
>> > +       }
>> > +
>> > +       return 0;
>> > +}
>> > +
>> >  int board_eth_init(bd_t *bd)
>> >  {
>> >         struct phy_device *phydev;
>> > @@ -268,6 +287,8 @@ int board_eth_init(bd_t *bd)
>> >         if (ret)
>> >                 return ret;
>> >
>> > +       setup_mac_from_fuse();
>> > +
>> >         bus = fec_get_miibus(IMX_FEC_BASE, -1);
>> >         if (!bus)
>> >                 return -ENODEV;
>> > --
>> > 2.11.0
>> >
>> > _______________________________________________
>> > U-Boot mailing list
>> > U-Boot@lists.denx.de
>> > https://lists.denx.de/listinfo/u-boot
>
>
>
>
> Best regards,
>
> Lukasz Majewski
>
> --
>
> DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
> Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de
>
> _______________________________________________
> U-Boot mailing list
> U-Boot@lists.denx.de
> https://lists.denx.de/listinfo/u-boot
>
diff mbox series

Patch

diff --git a/board/liebherr/display5/display5.c b/board/liebherr/display5/display5.c
index 4bade476a5..a3deba216c 100644
--- a/board/liebherr/display5/display5.c
+++ b/board/liebherr/display5/display5.c
@@ -254,6 +254,25 @@  static void setup_iomux_enet(void)
 	gpio_direction_input(IMX_GPIO_NR(1, 28)); /*INT#_GBE*/
 }
 
+static int setup_mac_from_fuse(void)
+{
+	unsigned char enetaddr[6];
+	int ret;
+
+	ret = eth_env_get_enetaddr("ethaddr", enetaddr);
+	if (ret)	/* ethaddr is already set */
+		return 0;
+
+	imx_get_mac_from_fuse(0, enetaddr);
+
+	if (is_valid_ethaddr(enetaddr)) {
+		eth_env_set_enetaddr("ethaddr", enetaddr);
+		return 0;
+	}
+
+	return 0;
+}
+
 int board_eth_init(bd_t *bd)
 {
 	struct phy_device *phydev;
@@ -268,6 +287,8 @@  int board_eth_init(bd_t *bd)
 	if (ret)
 		return ret;
 
+	setup_mac_from_fuse();
+
 	bus = fec_get_miibus(IMX_FEC_BASE, -1);
 	if (!bus)
 		return -ENODEV;