[U-Boot] [PATCH V5 14/31] imx: refactor imx_get_mac_from_fuse

Stefano Babic sbabic at denx.de
Sun Jan 21 16:31:47 UTC 2018



On 10/01/2018 06:20, Peng Fan wrote:
> Move imx_get_mac_from_fuse to a new mac.c for i.MX6/7.
> Since fuse regs structure are different for i.MX6/7, use mac
> address offset in code and define a new local struture
> imx_mac_fuse.
> 
> Also sort the config order.
> 
> Signed-off-by: Peng Fan <peng.fan at nxp.com>
> Cc: Stefano Babic <sbabic at denx.de>
> Cc: Fabio Estevam <fabio.estevam at nxp.com>
> ---
>  arch/arm/mach-imx/Makefile  |  3 ++-
>  arch/arm/mach-imx/mac.c     | 61 +++++++++++++++++++++++++++++++++++++++++++++
>  arch/arm/mach-imx/mx6/soc.c | 34 -------------------------
>  arch/arm/mach-imx/mx7/soc.c | 32 ------------------------
>  4 files changed, 63 insertions(+), 67 deletions(-)
>  create mode 100644 arch/arm/mach-imx/mac.c
> 
> diff --git a/arch/arm/mach-imx/Makefile b/arch/arm/mach-imx/Makefile
> index 63db0e15c4..714b858e73 100644
> --- a/arch/arm/mach-imx/Makefile
> +++ b/arch/arm/mach-imx/Makefile
> @@ -25,12 +25,13 @@ obj-$(CONFIG_SYS_I2C_MXC) += i2c-mxv7.o
>  endif
>  ifeq ($(SOC),$(filter $(SOC),mx6 mx7))
>  obj-y 	+= cache.o init.o
> -obj-$(CONFIG_SATA) += sata.o
> +obj-$(CONFIG_FEC_MXC) += mac.o
>  obj-$(CONFIG_IMX_VIDEO_SKIP) += video.o
>  obj-$(CONFIG_IMX_RDC) += rdc-sema.o
>  ifneq ($(CONFIG_SPL_BUILD),y)
>  obj-$(CONFIG_IMX_BOOTAUX) += imx_bootaux.o
>  endif
> +obj-$(CONFIG_SATA) += sata.o
>  obj-$(CONFIG_SECURE_BOOT)    += hab.o
>  obj-$(CONFIG_SYSCOUNTER_TIMER) += syscounter.o
>  endif
> diff --git a/arch/arm/mach-imx/mac.c b/arch/arm/mach-imx/mac.c
> new file mode 100644
> index 0000000000..dd7fd92d31
> --- /dev/null
> +++ b/arch/arm/mach-imx/mac.c
> @@ -0,0 +1,61 @@
> +/*
> + * Copyright 2017 NXP
> + *
> + * Peng Fan <peng.fan at nxp.com>
> + *
> + * SPDX-License-Identifier:     GPL-2.0+
> + */
> +
> +#include <common.h>
> +#include <asm/arch/imx-regs.h>
> +#include <asm/io.h>
> +#include <asm/arch/sys_proto.h>
> +#include <errno.h>
> +
> +struct imx_mac_fuse {
> +	u32 mac_addr0;
> +	u32 rsvd0[3];
> +	u32 mac_addr1;
> +	u32 rsvd1[3];
> +	u32 mac_addr2;
> +	u32 rsvd2[7];
> +};
> +
> +#define MAC_FUSE_MX6_OFFSET	0x620
> +#define MAC_FUSE_MX7_OFFSET	0x640
> +
> +void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
> +{
> +	struct imx_mac_fuse *fuse;
> +	u32 offset;
> +	bool has_second_mac;
> +
> +	offset = is_mx6() ? MAC_FUSE_MX6_OFFSET : MAC_FUSE_MX7_OFFSET;
> +	fuse = (struct imx_mac_fuse *)(ulong)(OCOTP_BASE_ADDR + offset);
> +	has_second_mac = is_mx7() || is_mx6sx() || is_mx6ul() || is_mx6ull();
> +
> +	if (has_second_mac && dev_id == 1) {
> +		u32 value = readl(&fuse->mac_addr2);
> +
> +		mac[0] = value >> 24;
> +		mac[1] = value >> 16;
> +		mac[2] = value >> 8;
> +		mac[3] = value;
> +
> +		value = readl(&fuse->mac_addr1);
> +		mac[4] = value >> 24;
> +		mac[5] = value >> 16;
> +
> +	} else {
> +		u32 value = readl(&fuse->mac_addr1);
> +
> +		mac[0] = value >> 8;
> +		mac[1] = value;
> +
> +		value = readl(&fuse->mac_addr0);
> +		mac[2] = value >> 24;
> +		mac[3] = value >> 16;
> +		mac[4] = value >> 8;
> +		mac[5] = value;
> +	}
> +}
> diff --git a/arch/arm/mach-imx/mx6/soc.c b/arch/arm/mach-imx/mx6/soc.c
> index 43cb58106b..b3bee58f10 100644
> --- a/arch/arm/mach-imx/mx6/soc.c
> +++ b/arch/arm/mach-imx/mx6/soc.c
> @@ -518,40 +518,6 @@ int board_postclk_init(void)
>  	return 0;
>  }
>  
> -#if defined(CONFIG_FEC_MXC)
> -void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
> -{
> -	struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
> -	struct fuse_bank *bank = &ocotp->bank[4];
> -	struct fuse_bank4_regs *fuse =
> -			(struct fuse_bank4_regs *)bank->fuse_regs;
> -
> -	if ((is_mx6sx() || is_mx6ul() || is_mx6ull()) && dev_id == 1) {
> -		u32 value = readl(&fuse->mac_addr2);
> -		mac[0] = value >> 24 ;
> -		mac[1] = value >> 16 ;
> -		mac[2] = value >> 8 ;
> -		mac[3] = value ;
> -
> -		value = readl(&fuse->mac_addr1);
> -		mac[4] = value >> 24 ;
> -		mac[5] = value >> 16 ;
> -		
> -	} else {
> -		u32 value = readl(&fuse->mac_addr1);
> -		mac[0] = (value >> 8);
> -		mac[1] = value ;
> -
> -		value = readl(&fuse->mac_addr0);
> -		mac[2] = value >> 24 ;
> -		mac[3] = value >> 16 ;
> -		mac[4] = value >> 8 ;
> -		mac[5] = value ;
> -	}
> -
> -}
> -#endif
> -
>  #ifndef CONFIG_SPL_BUILD
>  /*
>   * cfg_val will be used for
> diff --git a/arch/arm/mach-imx/mx7/soc.c b/arch/arm/mach-imx/mx7/soc.c
> index 032dfcf2ce..10dec8bdf4 100644
> --- a/arch/arm/mach-imx/mx7/soc.c
> +++ b/arch/arm/mach-imx/mx7/soc.c
> @@ -208,38 +208,6 @@ void get_board_serial(struct tag_serialnr *serialnr)
>  }
>  #endif
>  
> -#if defined(CONFIG_FEC_MXC)
> -void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
> -{
> -	struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
> -	struct fuse_bank *bank = &ocotp->bank[9];
> -	struct fuse_bank9_regs *fuse =
> -		(struct fuse_bank9_regs *)bank->fuse_regs;
> -
> -	if (0 == dev_id) {
> -		u32 value = readl(&fuse->mac_addr1);
> -		mac[0] = (value >> 8);
> -		mac[1] = value;
> -
> -		value = readl(&fuse->mac_addr0);
> -		mac[2] = value >> 24;
> -		mac[3] = value >> 16;
> -		mac[4] = value >> 8;
> -		mac[5] = value;
> -	} else {
> -		u32 value = readl(&fuse->mac_addr2);
> -		mac[0] = value >> 24;
> -		mac[1] = value >> 16;
> -		mac[2] = value >> 8;
> -		mac[3] = value;
> -
> -		value = readl(&fuse->mac_addr1);
> -		mac[4] = value >> 24;
> -		mac[5] = value >> 16;
> -	}
> -}
> -#endif
> -
>  #ifdef CONFIG_IMX_BOOTAUX
>  int arch_auxiliary_core_up(u32 core_id, u32 boot_private_data)
>  {
> 

Reviewed-by: Stefano Babic <sbabic at denx.de>

Best regards,
Stefano Babic

-- 
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================


More information about the U-Boot mailing list