2 * TI DaVinci DM646X EVM board
4 * Derived from: arch/arm/mach-davinci/board-evm.c
5 * Copyright (C) 2006 Texas Instruments.
7 * (C) 2007-2008, MontaVista Software, Inc.
9 * This file is licensed under the terms of the GNU General Public License
10 * version 2. This program is licensed "as is" without any warranty of any
11 * kind, whether express or implied.
15 /**************************************************************************
17 **************************************************************************/
19 #include <linux/kernel.h>
20 #include <linux/module.h>
21 #include <linux/init.h>
23 #include <linux/major.h>
24 #include <linux/root_dev.h>
25 #include <linux/dma-mapping.h>
26 #include <linux/serial.h>
27 #include <linux/serial_8250.h>
28 #include <linux/leds.h>
29 #include <linux/gpio.h>
31 #include <linux/platform_device.h>
32 #include <linux/i2c.h>
33 #include <linux/i2c/at24.h>
34 #include <linux/i2c/pcf857x.h>
35 #include <linux/etherdevice.h>
37 #include <asm/setup.h>
38 #include <asm/mach-types.h>
39 #include <asm/mach/arch.h>
40 #include <asm/mach/map.h>
41 #include <asm/mach/flash.h>
43 #include <mach/dm646x.h>
44 #include <mach/common.h>
46 #include <mach/serial.h>
49 #include <mach/emac.h>
51 #define DM646X_EVM_PHY_MASK (0x2)
52 #define DM646X_EVM_MDIO_FREQUENCY (2200000) /* PHY bus frequency */
54 static struct emac_platform_data dm646x_evm_emac_pdata = {
55 .phy_mask = DM646X_EVM_PHY_MASK,
56 .mdio_max_freq = DM646X_EVM_MDIO_FREQUENCY,
59 static struct davinci_uart_config uart_config __initdata = {
60 .enabled_uarts = (1 << 0),
65 static struct gpio_led evm_leds[] = {
66 { .name = "DS1", .active_low = 1, },
67 { .name = "DS2", .active_low = 1, },
68 { .name = "DS3", .active_low = 1, },
69 { .name = "DS4", .active_low = 1, },
72 static __initconst struct gpio_led_platform_data evm_led_data = {
73 .num_leds = ARRAY_SIZE(evm_leds),
77 static struct platform_device *evm_led_dev;
79 static int evm_led_setup(struct i2c_client *client, int gpio,
80 unsigned int ngpio, void *c)
82 struct gpio_led *leds = evm_leds;
90 evm_led_dev = platform_device_alloc("leds-gpio", 0);
91 platform_device_add_data(evm_led_dev, &evm_led_data,
92 sizeof(evm_led_data));
94 evm_led_dev->dev.parent = &client->dev;
95 status = platform_device_add(evm_led_dev);
97 platform_device_put(evm_led_dev);
103 static int evm_led_teardown(struct i2c_client *client, int gpio,
104 unsigned ngpio, void *c)
107 platform_device_unregister(evm_led_dev);
113 static int evm_sw_gpio[4] = { -EINVAL, -EINVAL, -EINVAL, -EINVAL };
115 static int evm_sw_setup(struct i2c_client *client, int gpio,
116 unsigned ngpio, void *c)
122 for (i = 0; i < 4; ++i) {
123 snprintf(label, 10, "user_sw%d", i);
124 status = gpio_request(gpio, label);
127 evm_sw_gpio[i] = gpio++;
129 status = gpio_direction_input(evm_sw_gpio[i]);
131 gpio_free(evm_sw_gpio[i]);
132 evm_sw_gpio[i] = -EINVAL;
136 status = gpio_export(evm_sw_gpio[i], 0);
138 gpio_free(evm_sw_gpio[i]);
139 evm_sw_gpio[i] = -EINVAL;
145 for (i = 0; i < 4; ++i) {
146 if (evm_sw_gpio[i] != -EINVAL) {
147 gpio_free(evm_sw_gpio[i]);
148 evm_sw_gpio[i] = -EINVAL;
154 static int evm_sw_teardown(struct i2c_client *client, int gpio,
155 unsigned ngpio, void *c)
159 for (i = 0; i < 4; ++i) {
160 if (evm_sw_gpio[i] != -EINVAL) {
161 gpio_unexport(evm_sw_gpio[i]);
162 gpio_free(evm_sw_gpio[i]);
163 evm_sw_gpio[i] = -EINVAL;
169 static int evm_pcf_setup(struct i2c_client *client, int gpio,
170 unsigned int ngpio, void *c)
177 status = evm_sw_setup(client, gpio, 4, c);
181 return evm_led_setup(client, gpio+4, 4, c);
184 static int evm_pcf_teardown(struct i2c_client *client, int gpio,
185 unsigned int ngpio, void *c)
189 evm_sw_teardown(client, gpio, 4, c);
190 evm_led_teardown(client, gpio+4, 4, c);
195 static struct pcf857x_platform_data pcf_data = {
196 .gpio_base = DAVINCI_N_GPIO+1,
197 .setup = evm_pcf_setup,
198 .teardown = evm_pcf_teardown,
201 /* Most of this EEPROM is unused, but U-Boot uses some data:
202 * - 0x7f00, 6 bytes Ethernet Address
203 * - ... newer boards may have more
205 static struct memory_accessor *at24_mem_acc;
207 static void at24_setup(struct memory_accessor *mem_acc, void *context)
209 char mac_addr[ETH_ALEN];
211 at24_mem_acc = mem_acc;
213 /* Read MAC addr from EEPROM */
214 if (at24_mem_acc->read(at24_mem_acc, mac_addr, 0x7f00, ETH_ALEN) ==
216 pr_info("Read MAC addr from EEPROM: %pM\n", mac_addr);
217 memcpy(dm646x_evm_emac_pdata.mac_addr, mac_addr, ETH_ALEN);
221 static struct at24_platform_data eeprom_info = {
222 .byte_len = (256*1024) / 8,
224 .flags = AT24_FLAG_ADDR16,
228 int dm646xevm_eeprom_read(void *buf, off_t off, size_t count)
231 return at24_mem_acc->read(at24_mem_acc, buf, off, count);
234 EXPORT_SYMBOL(dm646xevm_eeprom_read);
236 int dm646xevm_eeprom_write(void *buf, off_t off, size_t count)
239 return at24_mem_acc->write(at24_mem_acc, buf, off, count);
242 EXPORT_SYMBOL(dm646xevm_eeprom_write);
244 static struct i2c_board_info __initdata i2c_info[] = {
246 I2C_BOARD_INFO("24c256", 0x50),
247 .platform_data = &eeprom_info,
250 I2C_BOARD_INFO("pcf8574a", 0x38),
251 .platform_data = &pcf_data,
255 static struct davinci_i2c_platform_data i2c_pdata = {
256 .bus_freq = 100 /* kHz */,
257 .bus_delay = 0 /* usec */,
260 static void __init evm_init_i2c(void)
262 davinci_init_i2c(&i2c_pdata);
263 i2c_register_board_info(1, i2c_info, ARRAY_SIZE(i2c_info));
266 static void __init davinci_map_io(void)
268 davinci_map_common_io();
272 static __init void evm_init(void)
275 davinci_serial_init(&uart_config);
276 dm646x_init_emac(&dm646x_evm_emac_pdata);
279 static __init void davinci_dm646x_evm_irq_init(void)
284 MACHINE_START(DAVINCI_DM6467_EVM, "DaVinci DM646x EVM")
286 .io_pg_offst = (__IO_ADDRESS(IO_PHYS) >> 18) & 0xfffc,
287 .boot_params = (0x80000100),
288 .map_io = davinci_map_io,
289 .init_irq = davinci_dm646x_evm_irq_init,
290 .timer = &davinci_timer,
291 .init_machine = evm_init,