"Mark A. Greer" <[email protected]> writes:

> From: Mark A. Greer <[email protected]>
>
> Factor out the code to extract that mac address from
> i2c eeprom.  Also factor out the code that fixes up
> a bogus mac address.
>
> Signed-off-by: Mark A. Greer <[email protected]>

Mark,

I reworked this one slightly to apply on top of a patch I pushed a
patch from Troy Kisky which moved the random MAC addr generation into
the driver itself, which makes some sense and other net drivers do the
same if handed a bogus MAC.

As a result, I did the following...

> ---
>  arch/arm/mach-davinci/Makefile            |    3 +-
>  arch/arm/mach-davinci/board-dm644x-evm.c  |   26 ++--------------
>  arch/arm/mach-davinci/board-dm646x-evm.c  |   25 +--------------
>  arch/arm/mach-davinci/board-sffsdr.c      |    2 +-
>  arch/arm/mach-davinci/devices.c           |   26 ----------------
>  arch/arm/mach-davinci/include/mach/emac.h |    8 +++--
>  arch/arm/mach-davinci/mac_addr.c          |   47 
> +++++++++++++++++++++++++++++
>  7 files changed, 60 insertions(+), 77 deletions(-)
>  create mode 100644 arch/arm/mach-davinci/mac_addr.c
>
> diff --git a/arch/arm/mach-davinci/Makefile b/arch/arm/mach-davinci/Makefile
> index b8e54ac..ca68012 100644
> --- a/arch/arm/mach-davinci/Makefile
> +++ b/arch/arm/mach-davinci/Makefile
> @@ -5,7 +5,8 @@
>  
>  # Common objects
>  obj-y                        := time.o irq.o clock.o serial.o io.o psc.o \
> -                        gpio.o devices.o usb.o dma.o iram.o common.o
> +                        gpio.o devices.o usb.o dma.o iram.o common.o \
> +                        mac_addr.o
>
>  obj-$(CONFIG_DAVINCI_MUX)            += mux.o
>  
> diff --git a/arch/arm/mach-davinci/board-dm644x-evm.c 
> b/arch/arm/mach-davinci/board-dm644x-evm.c
> index 5052ec8..fab652b 100644
> --- a/arch/arm/mach-davinci/board-dm644x-evm.c
> +++ b/arch/arm/mach-davinci/board-dm644x-evm.c
> @@ -44,6 +44,7 @@
>  #include <mach/psc.h>
>  #include <mach/nand.h>
>  #include <mach/mmc.h>
> +#include <mach/emac.h>
>  #include <mach/common.h>
>  
>  #define DM644X_EVM_PHY_MASK          (0x2)
> @@ -408,32 +409,12 @@ static struct pcf857x_platform_data pcf_data_u35 = {
>   *  - 0x0039, 1 byte NTSC vs PAL (bit 0x80 == PAL)
>   *  - ... newer boards may have more
>   */
> -static struct memory_accessor *at24_mem_acc;
> -
> -static void at24_setup(struct memory_accessor *mem_acc, void *context)
> -{
> -#if defined(CONFIG_TI_DAVINCI_EMAC) || defined(CONFIG_TI_DAVINCI_EMAC_MODULE)
> -     DECLARE_MAC_BUF(mac_str);
> -     char mac_addr[6];
> -     struct davinci_soc_info *soc_info = davinci_get_soc_info();
> -
> -     at24_mem_acc = mem_acc;
> -
> -     /* Read MAC addr from EEPROM */
> -     if (at24_mem_acc->read(at24_mem_acc, mac_addr, 0x7f00, 6) == 6) {
> -             printk(KERN_INFO "Read MAC addr from EEPROM: %s\n",
> -                    print_mac(mac_str, mac_addr));
> -
> -             memcpy(soc_info->emac_pdata->mac_addr, mac_addr, 6);
> -     }
> -#endif
> -}
> -
>  static struct at24_platform_data eeprom_info = {
>       .byte_len       = (256*1024) / 8,
>       .page_size      = 64,
>       .flags          = AT24_FLAG_ADDR16,
> -     .setup          = at24_setup,
> +     .setup          = davinci_get_mac_addr,
> +     .context        = (void *)0x7f00,
>  };
>  
>  /*
> @@ -664,7 +645,6 @@ static __init void davinci_evm_init(void)
>  
>       soc_info->emac_pdata->phy_mask = DM644X_EVM_PHY_MASK;
>       soc_info->emac_pdata->mdio_max_freq = DM644X_EVM_MDIO_FREQUENCY;
> -     davinci_init_emac(soc_info->emac_pdata);
>  
>       /* Register the fixup for PHY on DaVinci */
>       phy_register_fixup_for_uid(LXT971_PHY_ID, LXT971_PHY_MASK,
> diff --git a/arch/arm/mach-davinci/board-dm646x-evm.c 
> b/arch/arm/mach-davinci/board-dm646x-evm.c
> index 9648fa2..9db1be3 100644
> --- a/arch/arm/mach-davinci/board-dm646x-evm.c
> +++ b/arch/arm/mach-davinci/board-dm646x-evm.c
> @@ -57,32 +57,12 @@ static struct davinci_uart_config uart_config __initdata 
> = {
>   *  - 0x7f00, 6 bytes Ethernet Address
>   *  - ... newer boards may have more
>   */
> -static struct memory_accessor *at24_mem_acc;
> -
> -static void at24_setup(struct memory_accessor *mem_acc, void *context)
> -{
> -#if defined(CONFIG_TI_DAVINCI_EMAC) || defined(CONFIG_TI_DAVINCI_EMAC_MODULE)
> -     DECLARE_MAC_BUF(mac_str);
> -     char mac_addr[6];
> -     struct davinci_soc_info *soc_info = davinci_get_soc_info();
> -
> -     at24_mem_acc = mem_acc;
> -
> -     /* Read MAC addr from EEPROM */
> -     if (at24_mem_acc->read(at24_mem_acc, mac_addr, 0x7f00, 6) == 6) {
> -             printk(KERN_INFO "Read MAC addr from EEPROM: %s\n",
> -             print_mac(mac_str, mac_addr));
> -
> -             memcpy(soc_info->emac_pdata->mac_addr, mac_addr, 6);
> -     }
> -#endif
> -}
> -
>  static struct at24_platform_data eeprom_info = {
>       .byte_len       = (256*1024) / 8,
>       .page_size      = 64,
>       .flags          = AT24_FLAG_ADDR16,
> -     .setup          = at24_setup,
> +     .setup          = davinci_get_mac_addr,
> +     .context        = (void *)0x7f00,
>  };
>  
>  static struct i2c_board_info __initdata i2c_info[] =  {
> @@ -121,7 +101,6 @@ static __init void evm_init(void)
>  
>       soc_info->emac_pdata->phy_mask = DM646X_EVM_PHY_MASK;
>       soc_info->emac_pdata->mdio_max_freq = DM646X_EVM_MDIO_FREQUENCY;
> -     davinci_init_emac(soc_info->emac_pdata);
>  }
>  
>  static __init void davinci_dm646x_evm_irq_init(void)
> diff --git a/arch/arm/mach-davinci/board-sffsdr.c 
> b/arch/arm/mach-davinci/board-sffsdr.c
> index c844014..503696d 100644
> --- a/arch/arm/mach-davinci/board-sffsdr.c
> +++ b/arch/arm/mach-davinci/board-sffsdr.c
> @@ -166,10 +166,10 @@ static __init void davinci_sffsdr_init(void)
>       sffsdr_init_i2c();
>       davinci_serial_init(&uart_config);
>  
> +     davinci_fixup_mac_addr(davinci_sffsdr_mac_addr);
>       memcpy(soc_info->emac_pdata->mac_addr, davinci_sffsdr_mac_addr, 6);
>       soc_info->emac_pdata->phy_mask = SFFSDR_PHY_MASK;
>       soc_info->emac_pdata->mdio_max_freq = SFFSDR_MDIO_FREQUENCY;
> -     davinci_init_emac(soc_info->emac_pdata);
>  
>       setup_usb(0, 0); /* We support only peripheral mode. */
>  
> diff --git a/arch/arm/mach-davinci/devices.c b/arch/arm/mach-davinci/devices.c
> index 050435c..d104cd8 100644
> --- a/arch/arm/mach-davinci/devices.c
> +++ b/arch/arm/mach-davinci/devices.c
> @@ -262,32 +262,6 @@ struct davinci_timer_instance davinci_timer_instance[2] 
> = {
>  
>  /*-------------------------------------------------------------------------*/
>  
> -#if defined(CONFIG_TI_DAVINCI_EMAC) || defined(CONFIG_TI_DAVINCI_EMAC_MODULE)
> -
> -void davinci_init_emac(struct emac_platform_data *pdata)
> -{
> -     DECLARE_MAC_BUF(buf);
> -
> -     /* if valid MAC exists, don't re-register */
> -     if (is_valid_ether_addr(pdata->mac_addr))
> -             return;
> -     else {
> -             /* Use random MAC if none passed */
> -             random_ether_addr(pdata->mac_addr);
> -
> -             printk(KERN_WARNING "%s: using random MAC addr: %s\n",
> -                    __func__, print_mac(buf, pdata->mac_addr));
> -     }
> -}
> -
> -#else
> -
> -void davinci_init_emac(struct emac_platform_data *unused) {}
> -
> -#endif
> -
> -/*-------------------------------------------------------------------------*/
> -
>  static int __init davinci_init_devices(void)
>  {
>       /* please keep these calls, and their implementations above,
> diff --git a/arch/arm/mach-davinci/include/mach/emac.h 
> b/arch/arm/mach-davinci/include/mach/emac.h
> index 84d3372..7c50a71 100644
> --- a/arch/arm/mach-davinci/include/mach/emac.h
> +++ b/arch/arm/mach-davinci/include/mach/emac.h
> @@ -11,6 +11,8 @@
>  #ifndef _MACH_DAVINCI_EMAC_H
>  #define _MACH_DAVINCI_EMAC_H
>  
> +#include <linux/i2c/at24.h>
> +

I changed this to <linux/memory.h>

>  struct emac_platform_data {
>       char mac_addr[6];
>       u32 ctrl_reg_offset;
> @@ -28,7 +30,7 @@ enum {
>       EMAC_VERSION_1, /* DM644x */
>       EMAC_VERSION_2, /* DM646x */
>  };
> -void davinci_init_emac(struct emac_platform_data *pdata);
> -#endif
> -
>  
> +void davinci_fixup_mac_addr(char *mac_addr);
> +void davinci_get_mac_addr(struct memory_accessor *mem_acc, void *context);
> +#endif
> diff --git a/arch/arm/mach-davinci/mac_addr.c 
> b/arch/arm/mach-davinci/mac_addr.c
> new file mode 100644
> index 0000000..4d8a963
> --- /dev/null
> +++ b/arch/arm/mach-davinci/mac_addr.c
> @@ -0,0 +1,47 @@
> +/*
> + * Helper routines for setting the EMAC MAC address
> + *
> + * Author: Kevin Hilman, MontaVista Software, Inc. <[email protected]>
> + *
> + * 2007 (c) MontaVista Software, Inc. This file is licensed under
> + * the terms of the GNU General Public License version 2. This program
> + * is licensed "as is" without any warranty of any kind, whether express
> + * or implied.
> + */
> +#include <linux/kernel.h>
> +#include <linux/etherdevice.h>
> +
> +#include <mach/emac.h>
> +#include <mach/common.h>
> +
> +/* Use a random mac addr if one passed in is invalid */
> +void davinci_fixup_mac_addr(char *mac_addr)
> +{
> +#if defined(CONFIG_TI_DAVINCI_EMAC) || defined(CONFIG_TI_DAVINCI_EMAC_MODULE)
> +     DECLARE_MAC_BUF(mac_str);
> +
> +     if (!is_valid_ether_addr(mac_addr)) {
> +             random_ether_addr(mac_addr);
> +
> +             pr_warning("%s: using random MAC addr: %s\n",
> +                             __func__, print_mac(mac_str, mac_addr));
> +     }
> +#endif

I dropped this function all together, since it was moved into the EMAC
driver by Troy's patch.

> +
> +void davinci_get_mac_addr(struct memory_accessor *mem_acc, void *context)
> +{
> +#if defined(CONFIG_TI_DAVINCI_EMAC) || defined(CONFIG_TI_DAVINCI_EMAC_MODULE)
> +     DECLARE_MAC_BUF(mac_str);
> +     struct davinci_soc_info *soc_info = davinci_get_soc_info();
> +     char *mac_addr = soc_info->emac_pdata->mac_addr;
> +     off_t offset = (off_t)context;
> +
> +     /* Read MAC addr from EEPROM */
> +     if (mem_acc->read(mem_acc, mac_addr, offset, 6) == 6) {
> +             pr_info("Read MAC addr from EEPROM: %s\n",
> +                             print_mac(mac_str, mac_addr));
> +             davinci_fixup_mac_addr(mac_addr);
> +     }
> +#endif
> +}

And moved this to common.c, without the #ifdef, thus leaving an empty
mac_addr.c which I dropped.

Any objections?

Kevin

_______________________________________________
Davinci-linux-open-source mailing list
[email protected]
http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source

Reply via email to