aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark A. Greer <mgreer@mvista.com>2009-04-15 15:41:27 -0400
committerKevin Hilman <khilman@deeprootsystems.com>2009-05-28 18:17:47 -0400
commitb14dc0f9942a9c318c6c49f29511d88b3642e2d0 (patch)
treeef9a9f0502c62a059de7ef7bb4949d5f51f8c8d1
parentc97909fcf1611645f0fe235b332e39623588d84c (diff)
davinci: Factor out emac mac address handling
Factor out the code to extract that mac address from i2c eeprom. Signed-off-by: Mark A. Greer <mgreer@mvista.com> Signed-off-by: Kevin Hilman <khilman@deeprootsystems.com>
-rw-r--r--arch/arm/mach-davinci/board-dm644x-evm.c21
-rw-r--r--arch/arm/mach-davinci/board-dm646x-evm.c20
-rw-r--r--arch/arm/mach-davinci/common.c12
-rw-r--r--arch/arm/mach-davinci/devices.c26
-rw-r--r--arch/arm/mach-davinci/include/mach/emac.h6
5 files changed, 20 insertions, 65 deletions
diff --git a/arch/arm/mach-davinci/board-dm644x-evm.c b/arch/arm/mach-davinci/board-dm644x-evm.c
index 987d27fcacb..d9d40450bdc 100644
--- a/arch/arm/mach-davinci/board-dm644x-evm.c
+++ b/arch/arm/mach-davinci/board-dm644x-evm.c
@@ -44,6 +44,7 @@
44#include <mach/psc.h> 44#include <mach/psc.h>
45#include <mach/nand.h> 45#include <mach/nand.h>
46#include <mach/mmc.h> 46#include <mach/mmc.h>
47#include <mach/emac.h>
47#include <mach/common.h> 48#include <mach/common.h>
48 49
49#define DM644X_EVM_PHY_MASK (0x2) 50#define DM644X_EVM_PHY_MASK (0x2)
@@ -437,28 +438,13 @@ static struct pcf857x_platform_data pcf_data_u35 = {
437 * - 0x0039, 1 byte NTSC vs PAL (bit 0x80 == PAL) 438 * - 0x0039, 1 byte NTSC vs PAL (bit 0x80 == PAL)
438 * - ... newer boards may have more 439 * - ... newer boards may have more
439 */ 440 */
440static struct memory_accessor *at24_mem_acc;
441
442static void at24_setup(struct memory_accessor *mem_acc, void *context)
443{
444 char mac_addr[ETH_ALEN];
445 struct davinci_soc_info *soc_info = &davinci_soc_info;
446
447 at24_mem_acc = mem_acc;
448
449 /* Read MAC addr from EEPROM */
450 if (at24_mem_acc->read(at24_mem_acc, mac_addr, 0x7f00, ETH_ALEN) ==
451 ETH_ALEN) {
452 printk(KERN_INFO "Read MAC addr from EEPROM: %pM\n", mac_addr);
453 memcpy(soc_info->emac_pdata->mac_addr, mac_addr, ETH_ALEN);
454 }
455}
456 441
457static struct at24_platform_data eeprom_info = { 442static struct at24_platform_data eeprom_info = {
458 .byte_len = (256*1024) / 8, 443 .byte_len = (256*1024) / 8,
459 .page_size = 64, 444 .page_size = 64,
460 .flags = AT24_FLAG_ADDR16, 445 .flags = AT24_FLAG_ADDR16,
461 .setup = at24_setup, 446 .setup = davinci_get_mac_addr,
447 .context = (void *)0x7f00,
462}; 448};
463 449
464/* 450/*
@@ -684,7 +670,6 @@ static __init void davinci_evm_init(void)
684 670
685 soc_info->emac_pdata->phy_mask = DM644X_EVM_PHY_MASK; 671 soc_info->emac_pdata->phy_mask = DM644X_EVM_PHY_MASK;
686 soc_info->emac_pdata->mdio_max_freq = DM644X_EVM_MDIO_FREQUENCY; 672 soc_info->emac_pdata->mdio_max_freq = DM644X_EVM_MDIO_FREQUENCY;
687 dm644x_init_emac(soc_info->emac_pdata);
688 673
689 /* Register the fixup for PHY on DaVinci */ 674 /* Register the fixup for PHY on DaVinci */
690 phy_register_fixup_for_uid(LXT971_PHY_ID, LXT971_PHY_MASK, 675 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 44e2ab665af..e17de635262 100644
--- a/arch/arm/mach-davinci/board-dm646x-evm.c
+++ b/arch/arm/mach-davinci/board-dm646x-evm.c
@@ -198,28 +198,13 @@ static struct pcf857x_platform_data pcf_data = {
198 * - 0x7f00, 6 bytes Ethernet Address 198 * - 0x7f00, 6 bytes Ethernet Address
199 * - ... newer boards may have more 199 * - ... newer boards may have more
200 */ 200 */
201static struct memory_accessor *at24_mem_acc;
202
203static void at24_setup(struct memory_accessor *mem_acc, void *context)
204{
205 char mac_addr[ETH_ALEN];
206 struct davinci_soc_info *soc_info = &davinci_soc_info;
207
208 at24_mem_acc = mem_acc;
209
210 /* Read MAC addr from EEPROM */
211 if (at24_mem_acc->read(at24_mem_acc, mac_addr, 0x7f00, ETH_ALEN) ==
212 ETH_ALEN) {
213 pr_info("Read MAC addr from EEPROM: %pM\n", mac_addr);
214 memcpy(soc_info->emac_pdata->mac_addr, mac_addr, ETH_ALEN);
215 }
216}
217 201
218static struct at24_platform_data eeprom_info = { 202static struct at24_platform_data eeprom_info = {
219 .byte_len = (256*1024) / 8, 203 .byte_len = (256*1024) / 8,
220 .page_size = 64, 204 .page_size = 64,
221 .flags = AT24_FLAG_ADDR16, 205 .flags = AT24_FLAG_ADDR16,
222 .setup = at24_setup, 206 .setup = davinci_get_mac_addr,
207 .context = (void *)0x7f00,
223}; 208};
224 209
225static struct i2c_board_info __initdata i2c_info[] = { 210static struct i2c_board_info __initdata i2c_info[] = {
@@ -258,7 +243,6 @@ static __init void evm_init(void)
258 243
259 soc_info->emac_pdata->phy_mask = DM646X_EVM_PHY_MASK; 244 soc_info->emac_pdata->phy_mask = DM646X_EVM_PHY_MASK;
260 soc_info->emac_pdata->mdio_max_freq = DM646X_EVM_MDIO_FREQUENCY; 245 soc_info->emac_pdata->mdio_max_freq = DM646X_EVM_MDIO_FREQUENCY;
261 dm646x_init_emac(soc_info->emac_pdata);
262} 246}
263 247
264static __init void davinci_dm646x_evm_irq_init(void) 248static __init void davinci_dm646x_evm_irq_init(void)
diff --git a/arch/arm/mach-davinci/common.c b/arch/arm/mach-davinci/common.c
index d72d517d090..169ec73f8d7 100644
--- a/arch/arm/mach-davinci/common.c
+++ b/arch/arm/mach-davinci/common.c
@@ -10,12 +10,14 @@
10 */ 10 */
11#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/io.h> 12#include <linux/io.h>
13#include <linux/etherdevice.h>
13 14
14#include <asm/tlb.h> 15#include <asm/tlb.h>
15#include <asm/mach/map.h> 16#include <asm/mach/map.h>
16 17
17#include <mach/common.h> 18#include <mach/common.h>
18#include <mach/cputype.h> 19#include <mach/cputype.h>
20#include <mach/emac.h>
19 21
20#include "clock.h" 22#include "clock.h"
21 23
@@ -24,6 +26,16 @@ EXPORT_SYMBOL(davinci_soc_info);
24 26
25void __iomem *davinci_intc_base; 27void __iomem *davinci_intc_base;
26 28
29void davinci_get_mac_addr(struct memory_accessor *mem_acc, void *context)
30{
31 char *mac_addr = davinci_soc_info.emac_pdata->mac_addr;
32 off_t offset = (off_t)context;
33
34 /* Read MAC addr from EEPROM */
35 if (mem_acc->read(mem_acc, mac_addr, offset, ETH_ALEN) == ETH_ALEN)
36 pr_info("Read MAC addr from EEPROM: %pM\n", mac_addr);
37}
38
27static struct davinci_id * __init davinci_get_id(u32 jtag_id) 39static struct davinci_id * __init davinci_get_id(u32 jtag_id)
28{ 40{
29 int i; 41 int i;
diff --git a/arch/arm/mach-davinci/devices.c b/arch/arm/mach-davinci/devices.c
index c0195cd3a2c..c85091c25d1 100644
--- a/arch/arm/mach-davinci/devices.c
+++ b/arch/arm/mach-davinci/devices.c
@@ -254,32 +254,6 @@ struct davinci_timer_instance davinci_timer_instance[2] = {
254 254
255/*-------------------------------------------------------------------------*/ 255/*-------------------------------------------------------------------------*/
256 256
257#if defined(CONFIG_TI_DAVINCI_EMAC) || defined(CONFIG_TI_DAVINCI_EMAC_MODULE)
258
259void davinci_init_emac(struct emac_platform_data *pdata)
260{
261 DECLARE_MAC_BUF(buf);
262
263 /* if valid MAC exists, don't re-register */
264 if (is_valid_ether_addr(pdata->mac_addr))
265 return;
266 else {
267 /* Use random MAC if none passed */
268 random_ether_addr(pdata->mac_addr);
269
270 printk(KERN_WARNING "%s: using random MAC addr: %s\n",
271 __func__, print_mac(buf, pdata->mac_addr));
272 }
273}
274
275#else
276
277void davinci_init_emac(struct emac_platform_data *unused) {}
278
279#endif
280
281/*-------------------------------------------------------------------------*/
282
283static int __init davinci_init_devices(void) 257static int __init davinci_init_devices(void)
284{ 258{
285 /* please keep these calls, and their implementations above, 259 /* 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 549fcced217..beff4fb7c84 100644
--- a/arch/arm/mach-davinci/include/mach/emac.h
+++ b/arch/arm/mach-davinci/include/mach/emac.h
@@ -12,6 +12,7 @@
12#define _MACH_DAVINCI_EMAC_H 12#define _MACH_DAVINCI_EMAC_H
13 13
14#include <linux/if_ether.h> 14#include <linux/if_ether.h>
15#include <linux/memory.h>
15 16
16struct emac_platform_data { 17struct emac_platform_data {
17 char mac_addr[ETH_ALEN]; 18 char mac_addr[ETH_ALEN];
@@ -30,7 +31,6 @@ enum {
30 EMAC_VERSION_1, /* DM644x */ 31 EMAC_VERSION_1, /* DM644x */
31 EMAC_VERSION_2, /* DM646x */ 32 EMAC_VERSION_2, /* DM646x */
32}; 33};
33void davinci_init_emac(struct emac_platform_data *pdata);
34#endif
35
36 34
35void davinci_get_mac_addr(struct memory_accessor *mem_acc, void *context);
36#endif