Commit 5e5786ef authored by Mark A. Greer's avatar Mark A. Greer Committed by Kevin Hilman

davinci: Factor out emac mac address handling

Factor out the code to extract that mac address from
i2c eeprom.
Signed-off-by: default avatarMark A. Greer <mgreer@mvista.com>
Signed-off-by: default avatarKevin Hilman <khilman@deeprootsystems.com>
parent b4b7f29b
......@@ -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)
......@@ -437,32 +438,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,
};
/*
......@@ -689,7 +670,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;
dm644x_init_emac(soc_info->emac_pdata);
/* Register the fixup for PHY on DaVinci */
phy_register_fixup_for_uid(LXT971_PHY_ID, LXT971_PHY_MASK,
......
......@@ -198,31 +198,12 @@ static struct pcf857x_platform_data pcf_data = {
* - 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[] = {
......@@ -261,7 +242,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;
dm646x_init_emac(soc_info->emac_pdata);
}
static __init void davinci_dm646x_evm_irq_init(void)
......
......@@ -165,7 +165,6 @@ static __init void davinci_sffsdr_init(void)
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;
dm644x_init_emac(soc_info->emac_pdata);
setup_usb(0, 0); /* We support only peripheral mode. */
......
......@@ -10,18 +10,34 @@
*/
#include <linux/module.h>
#include <linux/io.h>
#include <linux/etherdevice.h>
#include <asm/tlb.h>
#include <asm/mach/map.h>
#include <mach/common.h>
#include <mach/cpu.h>
#include <mach/emac.h>
#include "clock.h"
static struct davinci_soc_info davinci_soc_info;
void __iomem *davinci_intc_base;
void davinci_get_mac_addr(struct memory_accessor *mem_acc, void *context)
{
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));
}
}
struct davinci_soc_info *davinci_get_soc_info(void)
{
return &davinci_soc_info;
......
......@@ -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,
......
......@@ -11,6 +11,8 @@
#ifndef _MACH_DAVINCI_EMAC_H
#define _MACH_DAVINCI_EMAC_H
#include <linux/memory.h>
struct emac_platform_data {
char mac_addr[6];
u32 ctrl_reg_offset;
......@@ -28,7 +30,6 @@ enum {
EMAC_VERSION_1, /* DM644x */
EMAC_VERSION_2, /* DM646x */
};
void davinci_init_emac(struct emac_platform_data *pdata);
#endif
void davinci_get_mac_addr(struct memory_accessor *mem_acc, void *context);
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment