blob: 20547049b48976a81b47f0d2e2472d9407b40e14 [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>
50
Hemant Pedanekar548197b2009-07-17 23:30:36 +053051#if defined(CONFIG_BLK_DEV_PALMCHIP_BK3710) || \
52 defined(CONFIG_BLK_DEV_PALMCHIP_BK3710_MODULE)
53#define HAS_ATA 1
54#else
55#define HAS_ATA 0
56#endif
57
58/* CPLD Register 0 bits to control ATA */
59#define DM646X_EVM_ATA_RST BIT(0)
60#define DM646X_EVM_ATA_PWD BIT(1)
61
Kevin Hilmanac7b75b2009-05-07 06:19:40 -070062#define DM646X_EVM_PHY_MASK (0x2)
63#define DM646X_EVM_MDIO_FREQUENCY (2200000) /* PHY bus frequency */
64
Kevin Hilmane38d92f2009-04-29 17:44:58 -070065static struct davinci_uart_config uart_config __initdata = {
66 .enabled_uarts = (1 << 0),
67};
68
Hemant Pedanekar548197b2009-07-17 23:30:36 +053069/* CPLD Register 0 Client: used for I/O Control */
70static int cpld_reg0_probe(struct i2c_client *client,
71 const struct i2c_device_id *id)
72{
73 if (HAS_ATA) {
74 u8 data;
75 struct i2c_msg msg[2] = {
76 {
77 .addr = client->addr,
78 .flags = I2C_M_RD,
79 .len = 1,
80 .buf = &data,
81 },
82 {
83 .addr = client->addr,
84 .flags = 0,
85 .len = 1,
86 .buf = &data,
87 },
88 };
89
90 /* Clear ATA_RSTn and ATA_PWD bits to enable ATA operation. */
91 i2c_transfer(client->adapter, msg, 1);
92 data &= ~(DM646X_EVM_ATA_RST | DM646X_EVM_ATA_PWD);
93 i2c_transfer(client->adapter, msg + 1, 1);
94 }
95
96 return 0;
97}
98
99static const struct i2c_device_id cpld_reg_ids[] = {
100 { "cpld_reg0", 0, },
101 { },
102};
103
104static struct i2c_driver dm6467evm_cpld_driver = {
105 .driver.name = "cpld_reg0",
106 .id_table = cpld_reg_ids,
107 .probe = cpld_reg0_probe,
108};
109
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700110/* LEDS */
111
112static struct gpio_led evm_leds[] = {
113 { .name = "DS1", .active_low = 1, },
114 { .name = "DS2", .active_low = 1, },
115 { .name = "DS3", .active_low = 1, },
116 { .name = "DS4", .active_low = 1, },
117};
118
119static __initconst struct gpio_led_platform_data evm_led_data = {
120 .num_leds = ARRAY_SIZE(evm_leds),
121 .leds = evm_leds,
122};
123
124static struct platform_device *evm_led_dev;
125
126static int evm_led_setup(struct i2c_client *client, int gpio,
127 unsigned int ngpio, void *c)
128{
129 struct gpio_led *leds = evm_leds;
130 int status;
131
132 while (ngpio--) {
133 leds->gpio = gpio++;
134 leds++;
135 };
136
137 evm_led_dev = platform_device_alloc("leds-gpio", 0);
138 platform_device_add_data(evm_led_dev, &evm_led_data,
139 sizeof(evm_led_data));
140
141 evm_led_dev->dev.parent = &client->dev;
142 status = platform_device_add(evm_led_dev);
143 if (status < 0) {
144 platform_device_put(evm_led_dev);
145 evm_led_dev = NULL;
146 }
147 return status;
148}
149
150static int evm_led_teardown(struct i2c_client *client, int gpio,
151 unsigned ngpio, void *c)
152{
153 if (evm_led_dev) {
154 platform_device_unregister(evm_led_dev);
155 evm_led_dev = NULL;
156 }
157 return 0;
158}
159
160static int evm_sw_gpio[4] = { -EINVAL, -EINVAL, -EINVAL, -EINVAL };
161
162static int evm_sw_setup(struct i2c_client *client, int gpio,
163 unsigned ngpio, void *c)
164{
165 int status;
166 int i;
167 char label[10];
168
169 for (i = 0; i < 4; ++i) {
170 snprintf(label, 10, "user_sw%d", i);
171 status = gpio_request(gpio, label);
172 if (status)
173 goto out_free;
174 evm_sw_gpio[i] = gpio++;
175
176 status = gpio_direction_input(evm_sw_gpio[i]);
177 if (status) {
178 gpio_free(evm_sw_gpio[i]);
179 evm_sw_gpio[i] = -EINVAL;
180 goto out_free;
181 }
182
183 status = gpio_export(evm_sw_gpio[i], 0);
184 if (status) {
185 gpio_free(evm_sw_gpio[i]);
186 evm_sw_gpio[i] = -EINVAL;
187 goto out_free;
188 }
189 }
190 return status;
191out_free:
192 for (i = 0; i < 4; ++i) {
193 if (evm_sw_gpio[i] != -EINVAL) {
194 gpio_free(evm_sw_gpio[i]);
195 evm_sw_gpio[i] = -EINVAL;
196 }
197 }
198 return status;
199}
200
201static int evm_sw_teardown(struct i2c_client *client, int gpio,
202 unsigned ngpio, void *c)
203{
204 int i;
205
206 for (i = 0; i < 4; ++i) {
207 if (evm_sw_gpio[i] != -EINVAL) {
208 gpio_unexport(evm_sw_gpio[i]);
209 gpio_free(evm_sw_gpio[i]);
210 evm_sw_gpio[i] = -EINVAL;
211 }
212 }
213 return 0;
214}
215
216static int evm_pcf_setup(struct i2c_client *client, int gpio,
217 unsigned int ngpio, void *c)
218{
219 int status;
220
221 if (ngpio < 8)
222 return -EINVAL;
223
224 status = evm_sw_setup(client, gpio, 4, c);
225 if (status)
226 return status;
227
228 return evm_led_setup(client, gpio+4, 4, c);
229}
230
231static int evm_pcf_teardown(struct i2c_client *client, int gpio,
232 unsigned int ngpio, void *c)
233{
234 BUG_ON(ngpio < 8);
235
236 evm_sw_teardown(client, gpio, 4, c);
237 evm_led_teardown(client, gpio+4, 4, c);
238
239 return 0;
240}
241
242static struct pcf857x_platform_data pcf_data = {
243 .gpio_base = DAVINCI_N_GPIO+1,
244 .setup = evm_pcf_setup,
245 .teardown = evm_pcf_teardown,
246};
247
248/* Most of this EEPROM is unused, but U-Boot uses some data:
249 * - 0x7f00, 6 bytes Ethernet Address
250 * - ... newer boards may have more
251 */
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700252
253static struct at24_platform_data eeprom_info = {
254 .byte_len = (256*1024) / 8,
255 .page_size = 64,
256 .flags = AT24_FLAG_ADDR16,
Mark A. Greerb14dc0f2009-04-15 12:41:27 -0700257 .setup = davinci_get_mac_addr,
258 .context = (void *)0x7f00,
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700259};
260
Chaithrika U S25acf552009-06-05 06:28:08 -0400261static u8 dm646x_iis_serializer_direction[] = {
262 TX_MODE, RX_MODE, INACTIVE_MODE, INACTIVE_MODE,
263};
264
265static u8 dm646x_dit_serializer_direction[] = {
266 TX_MODE,
267};
268
269static struct snd_platform_data dm646x_evm_snd_data[] = {
270 {
Chaithrika U S25acf552009-06-05 06:28:08 -0400271 .tx_dma_offset = 0x400,
272 .rx_dma_offset = 0x400,
273 .op_mode = DAVINCI_MCASP_IIS_MODE,
274 .num_serializer = ARRAY_SIZE(dm646x_iis_serializer_direction),
275 .tdm_slots = 2,
276 .serial_dir = dm646x_iis_serializer_direction,
277 .eventq_no = EVENTQ_0,
278 },
279 {
Chaithrika U S25acf552009-06-05 06:28:08 -0400280 .tx_dma_offset = 0x400,
281 .rx_dma_offset = 0,
282 .op_mode = DAVINCI_MCASP_DIT_MODE,
283 .num_serializer = ARRAY_SIZE(dm646x_dit_serializer_direction),
284 .tdm_slots = 32,
285 .serial_dir = dm646x_dit_serializer_direction,
286 .eventq_no = EVENTQ_0,
287 },
288};
289
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700290static struct i2c_board_info __initdata i2c_info[] = {
291 {
292 I2C_BOARD_INFO("24c256", 0x50),
293 .platform_data = &eeprom_info,
294 },
295 {
296 I2C_BOARD_INFO("pcf8574a", 0x38),
297 .platform_data = &pcf_data,
298 },
Hemant Pedanekar548197b2009-07-17 23:30:36 +0530299 {
300 I2C_BOARD_INFO("cpld_reg0", 0x3a),
301 },
Chaithrika U S1a7ff8f2009-08-25 15:20:05 +0300302 {
303 I2C_BOARD_INFO("tlv320aic33", 0x18),
304 }
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700305};
306
307static struct davinci_i2c_platform_data i2c_pdata = {
308 .bus_freq = 100 /* kHz */,
309 .bus_delay = 0 /* usec */,
310};
311
312static void __init evm_init_i2c(void)
313{
314 davinci_init_i2c(&i2c_pdata);
Hemant Pedanekar548197b2009-07-17 23:30:36 +0530315 i2c_add_driver(&dm6467evm_cpld_driver);
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700316 i2c_register_board_info(1, i2c_info, ARRAY_SIZE(i2c_info));
317}
318
319static void __init davinci_map_io(void)
320{
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700321 dm646x_init();
322}
323
324static __init void evm_init(void)
325{
Mark A. Greer972412b2009-04-15 12:40:56 -0700326 struct davinci_soc_info *soc_info = &davinci_soc_info;
327
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700328 evm_init_i2c();
329 davinci_serial_init(&uart_config);
Chaithrika U S25acf552009-06-05 06:28:08 -0400330 dm646x_init_mcasp0(&dm646x_evm_snd_data[0]);
331 dm646x_init_mcasp1(&dm646x_evm_snd_data[1]);
Mark A. Greer972412b2009-04-15 12:40:56 -0700332
Hemant Pedanekar548197b2009-07-17 23:30:36 +0530333 if (HAS_ATA)
334 dm646x_init_ide();
335
Mark A. Greer972412b2009-04-15 12:40:56 -0700336 soc_info->emac_pdata->phy_mask = DM646X_EVM_PHY_MASK;
337 soc_info->emac_pdata->mdio_max_freq = DM646X_EVM_MDIO_FREQUENCY;
Kevin Hilmane38d92f2009-04-29 17:44:58 -0700338}
339
340static __init void davinci_dm646x_evm_irq_init(void)
341{
342 davinci_irq_init();
343}
344
345MACHINE_START(DAVINCI_DM6467_EVM, "DaVinci DM646x EVM")
346 .phys_io = IO_PHYS,
347 .io_pg_offst = (__IO_ADDRESS(IO_PHYS) >> 18) & 0xfffc,
348 .boot_params = (0x80000100),
349 .map_io = davinci_map_io,
350 .init_irq = davinci_dm646x_evm_irq_init,
351 .timer = &davinci_timer,
352 .init_machine = evm_init,
353MACHINE_END
354