blob: becae51d6dd114dc3e332307e602e265228d1fd0 [file] [log] [blame]
Kevin Hilmane38d92f2009-04-29 17:44:58 -07001/*
2 * TI DaVinci DM646X EVM board
3 *
4 * Derived from: arch/arm/mach-davinci/board-evm.c
5 * Copyright (C) 2006 Texas Instruments.
6 *
7 * (C) 2007-2008, MontaVista Software, Inc.
8 *
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.
12 *
13 */
14
15/**************************************************************************
16 * Included Files
17 **************************************************************************/
18
19#include <linux/kernel.h>
20#include <linux/module.h>
21#include <linux/init.h>
22#include <linux/fs.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>
30#include <linux/io.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>
36
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>
42
43#include <mach/dm646x.h>
44#include <mach/common.h>
45#include <mach/psc.h>
46#include <mach/serial.h>
47#include <mach/i2c.h>
Kevin Hilmanac7b75b2009-05-07 06:19:40 -070048#include <mach/mmc.h>
49#include <mach/emac.h>
Mark A. Greer79c3c0b2009-04-15 12:38:58 -070050#include <mach/common.h>
Kevin Hilmanac7b75b2009-05-07 06:19:40 -070051
52#define DM646X_EVM_PHY_MASK (0x2)
53#define DM646X_EVM_MDIO_FREQUENCY (2200000) /* PHY bus frequency */
54
55static struct emac_platform_data dm646x_evm_emac_pdata = {
56 .phy_mask = DM646X_EVM_PHY_MASK,
57 .mdio_max_freq = DM646X_EVM_MDIO_FREQUENCY,
58};
Kevin Hilmane38d92f2009-04-29 17:44:58 -070059
60static struct davinci_uart_config uart_config __initdata = {
61 .enabled_uarts = (1 << 0),
62};
63
64/* LEDS */
65
66static struct gpio_led evm_leds[] = {
67 { .name = "DS1", .active_low = 1, },
68 { .name = "DS2", .active_low = 1, },
69 { .name = "DS3", .active_low = 1, },
70 { .name = "DS4", .active_low = 1, },
71};
72
73static __initconst struct gpio_led_platform_data evm_led_data = {
74 .num_leds = ARRAY_SIZE(evm_leds),
75 .leds = evm_leds,
76};
77
78static struct platform_device *evm_led_dev;
79
80static int evm_led_setup(struct i2c_client *client, int gpio,
81 unsigned int ngpio, void *c)
82{
83 struct gpio_led *leds = evm_leds;
84 int status;
85
86 while (ngpio--) {
87 leds->gpio = gpio++;
88 leds++;
89 };
90
91 evm_led_dev = platform_device_alloc("leds-gpio", 0);
92 platform_device_add_data(evm_led_dev, &evm_led_data,
93 sizeof(evm_led_data));
94
95 evm_led_dev->dev.parent = &client->dev;
96 status = platform_device_add(evm_led_dev);
97 if (status < 0) {
98 platform_device_put(evm_led_dev);
99 evm_led_dev = NULL;
100 }
101 return status;
102}
103
104static int evm_led_teardown(struct i2c_client *client, int gpio,
105 unsigned ngpio, void *c)
106{
107 if (evm_led_dev) {
108 platform_device_unregister(evm_led_dev);
109 evm_led_dev = NULL;
110 }
111 return 0;
112}
113
114static int evm_sw_gpio[4] = { -EINVAL, -EINVAL, -EINVAL, -EINVAL };
115
116static int evm_sw_setup(struct i2c_client *client, int gpio,
117 unsigned ngpio, void *c)
118{
119 int status;
120 int i;
121 char label[10];
122
123 for (i = 0; i < 4; ++i) {
124 snprintf(label, 10, "user_sw%d", i);
125 status = gpio_request(gpio, label);
126 if (status)
127 goto out_free;
128 evm_sw_gpio[i] = gpio++;
129
130 status = gpio_direction_input(evm_sw_gpio[i]);
131 if (status) {
132 gpio_free(evm_sw_gpio[i]);
133 evm_sw_gpio[i] = -EINVAL;
134 goto out_free;
135 }
136
137 status = gpio_export(evm_sw_gpio[i], 0);
138 if (status) {
139 gpio_free(evm_sw_gpio[i]);
140 evm_sw_gpio[i] = -EINVAL;
141 goto out_free;
142 }
143 }
144 return status;
145out_free:
146 for (i = 0; i < 4; ++i) {
147 if (evm_sw_gpio[i] != -EINVAL) {
148 gpio_free(evm_sw_gpio[i]);
149 evm_sw_gpio[i] = -EINVAL;
150 }
151 }
152 return status;
153}
154
155static int evm_sw_teardown(struct i2c_client *client, int gpio,
156 unsigned ngpio, void *c)
157{
158 int i;
159
160 for (i = 0; i < 4; ++i) {
161 if (evm_sw_gpio[i] != -EINVAL) {
162 gpio_unexport(evm_sw_gpio[i]);
163 gpio_free(evm_sw_gpio[i]);
164 evm_sw_gpio[i] = -EINVAL;
165 }
166 }
167 return 0;
168}
169
170static int evm_pcf_setup(struct i2c_client *client, int gpio,
171 unsigned int ngpio, void *c)
172{
173 int status;
174
175 if (ngpio < 8)
176 return -EINVAL;
177
178 status = evm_sw_setup(client, gpio, 4, c);
179 if (status)
180 return status;
181
182 return evm_led_setup(client, gpio+4, 4, c);
183}
184
185static int evm_pcf_teardown(struct i2c_client *client, int gpio,
186 unsigned int ngpio, void *c)
187{
188 BUG_ON(ngpio < 8);
189
190 evm_sw_teardown(client, gpio, 4, c);
191 evm_led_teardown(client, gpio+4, 4, c);
192
193 return 0;
194}
195
196static struct pcf857x_platform_data pcf_data = {
197 .gpio_base = DAVINCI_N_GPIO+1,
198 .setup = evm_pcf_setup,
199 .teardown = evm_pcf_teardown,
200};
201
202/* Most of this EEPROM is unused, but U-Boot uses some data:
203 * - 0x7f00, 6 bytes Ethernet Address
204 * - ... newer boards may have more
205 */
206static struct memory_accessor *at24_mem_acc;
207
208static void at24_setup(struct memory_accessor *mem_acc, void *context)
209{
Kevin Hilmanac7b75b2009-05-07 06:19:40 -0700210 char mac_addr[ETH_ALEN];
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700211
212 at24_mem_acc = mem_acc;
213
214 /* Read MAC addr from EEPROM */
215 if (at24_mem_acc->read(at24_mem_acc, mac_addr, 0x7f00, ETH_ALEN) ==
Kevin Hilmanac7b75b2009-05-07 06:19:40 -0700216 ETH_ALEN) {
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700217 pr_info("Read MAC addr from EEPROM: %pM\n", mac_addr);
Kevin Hilmanac7b75b2009-05-07 06:19:40 -0700218 memcpy(dm646x_evm_emac_pdata.mac_addr, mac_addr, ETH_ALEN);
219 }
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700220}
221
222static struct at24_platform_data eeprom_info = {
223 .byte_len = (256*1024) / 8,
224 .page_size = 64,
225 .flags = AT24_FLAG_ADDR16,
226 .setup = at24_setup,
227};
228
229int dm646xevm_eeprom_read(void *buf, off_t off, size_t count)
230{
231 if (at24_mem_acc)
232 return at24_mem_acc->read(at24_mem_acc, buf, off, count);
233 return -ENODEV;
234}
235EXPORT_SYMBOL(dm646xevm_eeprom_read);
236
237int dm646xevm_eeprom_write(void *buf, off_t off, size_t count)
238{
239 if (at24_mem_acc)
240 return at24_mem_acc->write(at24_mem_acc, buf, off, count);
241 return -ENODEV;
242}
243EXPORT_SYMBOL(dm646xevm_eeprom_write);
244
245static struct i2c_board_info __initdata i2c_info[] = {
246 {
247 I2C_BOARD_INFO("24c256", 0x50),
248 .platform_data = &eeprom_info,
249 },
250 {
251 I2C_BOARD_INFO("pcf8574a", 0x38),
252 .platform_data = &pcf_data,
253 },
254};
255
256static struct davinci_i2c_platform_data i2c_pdata = {
257 .bus_freq = 100 /* kHz */,
258 .bus_delay = 0 /* usec */,
259};
260
261static void __init evm_init_i2c(void)
262{
263 davinci_init_i2c(&i2c_pdata);
264 i2c_register_board_info(1, i2c_info, ARRAY_SIZE(i2c_info));
265}
266
267static void __init davinci_map_io(void)
268{
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700269 dm646x_init();
270}
271
272static __init void evm_init(void)
273{
274 evm_init_i2c();
275 davinci_serial_init(&uart_config);
Kevin Hilmanac7b75b2009-05-07 06:19:40 -0700276 dm646x_init_emac(&dm646x_evm_emac_pdata);
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700277}
278
279static __init void davinci_dm646x_evm_irq_init(void)
280{
281 davinci_irq_init();
282}
283
284MACHINE_START(DAVINCI_DM6467_EVM, "DaVinci DM646x EVM")
285 .phys_io = IO_PHYS,
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,
292MACHINE_END
293