diff options
author | Kuninori Morimoto <morimoto.kuninori@renesas.com> | 2009-09-10 01:39:58 +0000 |
---|---|---|
committer | Paul Mundt <lethal@linux-sh.org> | 2009-09-11 13:19:18 +0900 |
commit | 4907d57f76dc1d6c49c19c653fb705b9a2a8487c (patch) | |
tree | ff81abc32feb86dfd1c2fd4e392aebba23af66c7 | |
parent | be4ebf999a38dfe9d7d705c4913624ec816c48f2 (diff) |
sh: EcoVec24: write MAC address in boot
Signed-off-by: Kuninori Morimoto <morimoto.kuninori@renesas.com>
Signed-off-by: Paul Mundt <lethal@linux-sh.org>
-rw-r--r-- | arch/sh/boards/mach-ecovec24/setup.c | 81 |
1 files changed, 79 insertions, 2 deletions
diff --git a/arch/sh/boards/mach-ecovec24/setup.c b/arch/sh/boards/mach-ecovec24/setup.c index b44c06058e3..6cd1b782845 100644 --- a/arch/sh/boards/mach-ecovec24/setup.c +++ b/arch/sh/boards/mach-ecovec24/setup.c @@ -17,6 +17,7 @@ #include <linux/io.h> #include <linux/delay.h> #include <linux/usb/r8a66597.h> +#include <linux/i2c.h> #include <video/sh_mobile_lcdc.h> #include <media/sh_mobile_ceu.h> #include <asm/heartbeat.h> @@ -342,9 +343,77 @@ static struct platform_device *ecovec_devices[] __initdata = { &ceu1_device, }; +#define EEPROM_ADDR 0x50 +static u8 mac_read(struct i2c_adapter *a, u8 command) +{ + struct i2c_msg msg[2]; + u8 buf; + int ret; + + msg[0].addr = EEPROM_ADDR; + msg[0].flags = 0; + msg[0].len = 1; + msg[0].buf = &command; + + msg[1].addr = EEPROM_ADDR; + msg[1].flags = I2C_M_RD; + msg[1].len = 1; + msg[1].buf = &buf; + + ret = i2c_transfer(a, msg, 2); + if (ret < 0) { + printk(KERN_ERR "error %d\n", ret); + buf = 0xff; + } + + return buf; +} + +#define MAC_LEN 6 +static void __init sh_eth_init(void) +{ + struct i2c_adapter *a = i2c_get_adapter(1); + struct clk *eth_clk; + u8 mac[MAC_LEN]; + int i; + + if (!a) { + pr_err("can not get I2C 1\n"); + return; + } + + eth_clk = clk_get(NULL, "eth0"); + if (!eth_clk) { + pr_err("can not get eth0 clk\n"); + return; + } + + /* read MAC address frome EEPROM */ + for (i = 0; i < MAC_LEN; i++) { + mac[i] = mac_read(a, 0x10 + i); + msleep(10); + } + + /* clock enable */ + clk_enable(eth_clk); + + /* reset sh-eth */ + ctrl_outl(0x1, SH_ETH_ADDR + 0x0); + + /* set MAC addr */ + ctrl_outl((mac[0] << 24) | + (mac[1] << 16) | + (mac[2] << 8) | + (mac[3] << 0), SH_ETH_MAHR); + ctrl_outl((mac[4] << 8) | + (mac[5] << 0), SH_ETH_MALR); + + clk_put(eth_clk); +} + #define PORT_HIZA 0xA4050158 #define IODRIVEA 0xA405018A -static int __init devices_setup(void) +static int __init arch_setup(void) { /* enable SCIFA0 */ gpio_request(GPIO_FN_SCIF0_TXD, NULL); @@ -521,7 +590,15 @@ static int __init devices_setup(void) return platform_add_devices(ecovec_devices, ARRAY_SIZE(ecovec_devices)); } -arch_initcall(devices_setup); +arch_initcall(arch_setup); + +static int __init devices_setup(void) +{ + sh_eth_init(); + return 0; +} +device_initcall(devices_setup); + static struct sh_machine_vector mv_ecovec __initmv = { .mv_name = "R0P7724 (EcoVec)", |