9dc4813c86452c6041d3373812422de9d5e9e3a8
[safe/jmp/linux-2.6] / arch / arm / mach-davinci / board-da830-evm.c
1 /*
2  * TI DA830/OMAP L137 EVM board
3  *
4  * Author: Mark A. Greer <mgreer@mvista.com>
5  * Derived from: arch/arm/mach-davinci/board-dm644x-evm.c
6  *
7  * 2007, 2009 (c) MontaVista Software, Inc. This file is licensed under
8  * the terms of the GNU General Public License version 2. This program
9  * is licensed "as is" without any warranty of any kind, whether express
10  * or implied.
11  */
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/init.h>
15 #include <linux/console.h>
16 #include <linux/interrupt.h>
17 #include <linux/gpio.h>
18 #include <linux/i2c.h>
19 #include <linux/i2c/pcf857x.h>
20 #include <linux/i2c/at24.h>
21
22 #include <asm/mach-types.h>
23 #include <asm/mach/arch.h>
24
25 #include <mach/common.h>
26 #include <mach/irqs.h>
27 #include <mach/cp_intc.h>
28 #include <mach/mux.h>
29 #include <mach/gpio.h>
30 #include <mach/da8xx.h>
31 #include <mach/asp.h>
32 #include <mach/usb.h>
33
34 #define DA830_EVM_PHY_MASK              0x0
35 #define DA830_EVM_MDIO_FREQUENCY        2200000 /* PHY bus frequency */
36
37 static struct at24_platform_data da830_evm_i2c_eeprom_info = {
38         .byte_len       = SZ_256K / 8,
39         .page_size      = 64,
40         .flags          = AT24_FLAG_ADDR16,
41         .setup          = davinci_get_mac_addr,
42         .context        = (void *)0x7f00,
43 };
44
45 static int da830_evm_ui_expander_setup(struct i2c_client *client, int gpio,
46                 unsigned ngpio, void *context)
47 {
48         gpio_request(gpio + 6, "MUX_MODE");
49 #ifdef CONFIG_DA830_UI_LCD
50         gpio_direction_output(gpio + 6, 0);
51 #else /* Must be NAND or NOR */
52         gpio_direction_output(gpio + 6, 1);
53 #endif
54         return 0;
55 }
56
57 static int da830_evm_ui_expander_teardown(struct i2c_client *client, int gpio,
58                 unsigned ngpio, void *context)
59 {
60         gpio_free(gpio + 6);
61         return 0;
62 }
63
64 static struct pcf857x_platform_data da830_evm_ui_expander_info = {
65         .gpio_base      = DAVINCI_N_GPIO,
66         .setup          = da830_evm_ui_expander_setup,
67         .teardown       = da830_evm_ui_expander_teardown,
68 };
69
70 static struct i2c_board_info __initdata da830_evm_i2c_devices[] = {
71         {
72                 I2C_BOARD_INFO("24c256", 0x50),
73                 .platform_data  = &da830_evm_i2c_eeprom_info,
74         },
75         {
76                 I2C_BOARD_INFO("tlv320aic3x", 0x18),
77         },
78         {
79                 I2C_BOARD_INFO("pcf8574", 0x3f),
80                 .platform_data  = &da830_evm_ui_expander_info,
81         },
82 };
83
84 static struct davinci_i2c_platform_data da830_evm_i2c_0_pdata = {
85         .bus_freq       = 100,  /* kHz */
86         .bus_delay      = 0,    /* usec */
87 };
88
89 /*
90  * USB1 VBUS is controlled by GPIO1[15], over-current is reported on GPIO2[4].
91  */
92 #define ON_BD_USB_DRV   GPIO_TO_PIN(1, 15)
93 #define ON_BD_USB_OVC   GPIO_TO_PIN(2, 4)
94
95 static const short da830_evm_usb11_pins[] = {
96         DA830_GPIO1_15, DA830_GPIO2_4,
97         -1
98 };
99
100 static da8xx_ocic_handler_t da830_evm_usb_ocic_handler;
101
102 static int da830_evm_usb_set_power(unsigned port, int on)
103 {
104         gpio_set_value(ON_BD_USB_DRV, on);
105         return 0;
106 }
107
108 static int da830_evm_usb_get_power(unsigned port)
109 {
110         return gpio_get_value(ON_BD_USB_DRV);
111 }
112
113 static int da830_evm_usb_get_oci(unsigned port)
114 {
115         return !gpio_get_value(ON_BD_USB_OVC);
116 }
117
118 static irqreturn_t da830_evm_usb_ocic_irq(int, void *);
119
120 static int da830_evm_usb_ocic_notify(da8xx_ocic_handler_t handler)
121 {
122         int irq         = gpio_to_irq(ON_BD_USB_OVC);
123         int error       = 0;
124
125         if (handler != NULL) {
126                 da830_evm_usb_ocic_handler = handler;
127
128                 error = request_irq(irq, da830_evm_usb_ocic_irq, IRQF_DISABLED |
129                                     IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
130                                     "OHCI over-current indicator", NULL);
131                 if (error)
132                         printk(KERN_ERR "%s: could not request IRQ to watch "
133                                "over-current indicator changes\n", __func__);
134         } else
135                 free_irq(irq, NULL);
136
137         return error;
138 }
139
140 static struct da8xx_ohci_root_hub da830_evm_usb11_pdata = {
141         .set_power      = da830_evm_usb_set_power,
142         .get_power      = da830_evm_usb_get_power,
143         .get_oci        = da830_evm_usb_get_oci,
144         .ocic_notify    = da830_evm_usb_ocic_notify,
145
146         /* TPS2065 switch @ 5V */
147         .potpgt         = (3 + 1) / 2,  /* 3 ms max */
148 };
149
150 static irqreturn_t da830_evm_usb_ocic_irq(int irq, void *dev_id)
151 {
152         da830_evm_usb_ocic_handler(&da830_evm_usb11_pdata, 1);
153         return IRQ_HANDLED;
154 }
155
156 static __init void da830_evm_usb_init(void)
157 {
158         u32 cfgchip2;
159         int ret;
160
161         /*
162          * Set up USB clock/mode in the CFGCHIP2 register.
163          * FYI:  CFGCHIP2 is 0x0000ef00 initially.
164          */
165         cfgchip2 = __raw_readl(DA8XX_SYSCFG_VIRT(DA8XX_CFGCHIP2_REG));
166
167         /* USB2.0 PHY reference clock is 24 MHz */
168         cfgchip2 &= ~CFGCHIP2_REFFREQ;
169         cfgchip2 |=  CFGCHIP2_REFFREQ_24MHZ;
170
171         /*
172          * Select internal reference clock for USB 2.0 PHY
173          * and use it as a clock source for USB 1.1 PHY
174          * (this is the default setting anyway).
175          */
176         cfgchip2 &= ~CFGCHIP2_USB1PHYCLKMUX;
177         cfgchip2 |=  CFGCHIP2_USB2PHYCLKMUX;
178
179         __raw_writel(cfgchip2, DA8XX_SYSCFG_VIRT(DA8XX_CFGCHIP2_REG));
180
181         ret = da8xx_pinmux_setup(da830_evm_usb11_pins);
182         if (ret) {
183                 pr_warning("%s: USB 1.1 PinMux setup failed: %d\n",
184                            __func__, ret);
185                 return;
186         }
187
188         ret = gpio_request(ON_BD_USB_DRV, "ON_BD_USB_DRV");
189         if (ret) {
190                 printk(KERN_ERR "%s: failed to request GPIO for USB 1.1 port "
191                        "power control: %d\n", __func__, ret);
192                 return;
193         }
194         gpio_direction_output(ON_BD_USB_DRV, 0);
195
196         ret = gpio_request(ON_BD_USB_OVC, "ON_BD_USB_OVC");
197         if (ret) {
198                 printk(KERN_ERR "%s: failed to request GPIO for USB 1.1 port "
199                        "over-current indicator: %d\n", __func__, ret);
200                 return;
201         }
202         gpio_direction_input(ON_BD_USB_OVC);
203
204         ret = da8xx_register_usb11(&da830_evm_usb11_pdata);
205         if (ret)
206                 pr_warning("%s: USB 1.1 registration failed: %d\n",
207                            __func__, ret);
208 }
209
210 static struct davinci_uart_config da830_evm_uart_config __initdata = {
211         .enabled_uarts = 0x7,
212 };
213
214 static const short da830_evm_mcasp1_pins[] = {
215         DA830_AHCLKX1, DA830_ACLKX1, DA830_AFSX1, DA830_AHCLKR1, DA830_AFSR1,
216         DA830_AMUTE1, DA830_AXR1_0, DA830_AXR1_1, DA830_AXR1_2, DA830_AXR1_5,
217         DA830_ACLKR1, DA830_AXR1_6, DA830_AXR1_7, DA830_AXR1_8, DA830_AXR1_10,
218         DA830_AXR1_11,
219         -1
220 };
221
222 static u8 da830_iis_serializer_direction[] = {
223         RX_MODE,        INACTIVE_MODE,  INACTIVE_MODE,  INACTIVE_MODE,
224         INACTIVE_MODE,  TX_MODE,        INACTIVE_MODE,  INACTIVE_MODE,
225         INACTIVE_MODE,  INACTIVE_MODE,  INACTIVE_MODE,  INACTIVE_MODE,
226 };
227
228 static struct snd_platform_data da830_evm_snd_data = {
229         .tx_dma_offset  = 0x2000,
230         .rx_dma_offset  = 0x2000,
231         .op_mode        = DAVINCI_MCASP_IIS_MODE,
232         .num_serializer = ARRAY_SIZE(da830_iis_serializer_direction),
233         .tdm_slots      = 2,
234         .serial_dir     = da830_iis_serializer_direction,
235         .eventq_no      = EVENTQ_0,
236         .version        = MCASP_VERSION_2,
237         .txnumevt       = 1,
238         .rxnumevt       = 1,
239 };
240
241 /*
242  * GPIO2[1] is used as MMC_SD_WP and GPIO2[2] as MMC_SD_INS.
243  */
244 static const short da830_evm_mmc_sd_pins[] = {
245         DA830_MMCSD_DAT_0, DA830_MMCSD_DAT_1, DA830_MMCSD_DAT_2,
246         DA830_MMCSD_DAT_3, DA830_MMCSD_DAT_4, DA830_MMCSD_DAT_5,
247         DA830_MMCSD_DAT_6, DA830_MMCSD_DAT_7, DA830_MMCSD_CLK,
248         DA830_MMCSD_CMD,   DA830_GPIO2_1,     DA830_GPIO2_2,
249         -1
250 };
251
252 #define DA830_MMCSD_WP_PIN              GPIO_TO_PIN(2, 1)
253
254 static int da830_evm_mmc_get_ro(int index)
255 {
256         return gpio_get_value(DA830_MMCSD_WP_PIN);
257 }
258
259 static struct davinci_mmc_config da830_evm_mmc_config = {
260         .get_ro                 = da830_evm_mmc_get_ro,
261         .wires                  = 4,
262         .version                = MMC_CTLR_VERSION_2,
263 };
264
265 static inline void da830_evm_init_mmc(void)
266 {
267         int ret;
268
269         ret = da8xx_pinmux_setup(da830_evm_mmc_sd_pins);
270         if (ret) {
271                 pr_warning("da830_evm_init: mmc/sd mux setup failed: %d\n",
272                                 ret);
273                 return;
274         }
275
276         ret = gpio_request(DA830_MMCSD_WP_PIN, "MMC WP");
277         if (ret) {
278                 pr_warning("da830_evm_init: can not open GPIO %d\n",
279                            DA830_MMCSD_WP_PIN);
280                 return;
281         }
282         gpio_direction_input(DA830_MMCSD_WP_PIN);
283
284         ret = da8xx_register_mmcsd0(&da830_evm_mmc_config);
285         if (ret) {
286                 pr_warning("da830_evm_init: mmc/sd registration failed: %d\n",
287                                 ret);
288                 gpio_free(DA830_MMCSD_WP_PIN);
289         }
290 }
291
292 static __init void da830_evm_init(void)
293 {
294         struct davinci_soc_info *soc_info = &davinci_soc_info;
295         int ret;
296
297         ret = da8xx_register_edma();
298         if (ret)
299                 pr_warning("da830_evm_init: edma registration failed: %d\n",
300                                 ret);
301
302         ret = da8xx_pinmux_setup(da830_i2c0_pins);
303         if (ret)
304                 pr_warning("da830_evm_init: i2c0 mux setup failed: %d\n",
305                                 ret);
306
307         ret = da8xx_register_i2c(0, &da830_evm_i2c_0_pdata);
308         if (ret)
309                 pr_warning("da830_evm_init: i2c0 registration failed: %d\n",
310                                 ret);
311
312         da830_evm_usb_init();
313
314         soc_info->emac_pdata->phy_mask = DA830_EVM_PHY_MASK;
315         soc_info->emac_pdata->mdio_max_freq = DA830_EVM_MDIO_FREQUENCY;
316         soc_info->emac_pdata->rmii_en = 1;
317
318         ret = da8xx_pinmux_setup(da830_cpgmac_pins);
319         if (ret)
320                 pr_warning("da830_evm_init: cpgmac mux setup failed: %d\n",
321                                 ret);
322
323         ret = da8xx_register_emac();
324         if (ret)
325                 pr_warning("da830_evm_init: emac registration failed: %d\n",
326                                 ret);
327
328         ret = da8xx_register_watchdog();
329         if (ret)
330                 pr_warning("da830_evm_init: watchdog registration failed: %d\n",
331                                 ret);
332
333         davinci_serial_init(&da830_evm_uart_config);
334         i2c_register_board_info(1, da830_evm_i2c_devices,
335                         ARRAY_SIZE(da830_evm_i2c_devices));
336
337         ret = da8xx_pinmux_setup(da830_evm_mcasp1_pins);
338         if (ret)
339                 pr_warning("da830_evm_init: mcasp1 mux setup failed: %d\n",
340                                 ret);
341
342         da8xx_register_mcasp(1, &da830_evm_snd_data);
343
344         da830_evm_init_mmc();
345
346 #ifdef CONFIG_DA830_UI_LCD
347         ret = da8xx_pinmux_setup(da830_lcdcntl_pins);
348         if (ret)
349                 pr_warning("da830_evm_init: lcdcntl mux setup failed: %d\n",
350                                 ret);
351
352         ret = da8xx_register_lcdc(&sharp_lcd035q3dg01_pdata);
353         if (ret)
354                 pr_warning("da830_evm_init: lcd setup failed: %d\n", ret);
355 #endif
356
357         ret = da8xx_register_rtc();
358         if (ret)
359                 pr_warning("da830_evm_init: rtc setup failed: %d\n", ret);
360 }
361
362 #ifdef CONFIG_SERIAL_8250_CONSOLE
363 static int __init da830_evm_console_init(void)
364 {
365         return add_preferred_console("ttyS", 2, "115200");
366 }
367 console_initcall(da830_evm_console_init);
368 #endif
369
370 static __init void da830_evm_irq_init(void)
371 {
372         struct davinci_soc_info *soc_info = &davinci_soc_info;
373
374         cp_intc_init((void __iomem *)DA8XX_CP_INTC_VIRT, DA830_N_CP_INTC_IRQ,
375                         soc_info->intc_irq_prios);
376 }
377
378 static void __init da830_evm_map_io(void)
379 {
380         da830_init();
381 }
382
383 MACHINE_START(DAVINCI_DA830_EVM, "DaVinci DA830/OMAP L137 EVM")
384         .phys_io        = IO_PHYS,
385         .io_pg_offst    = (__IO_ADDRESS(IO_PHYS) >> 18) & 0xfffc,
386         .boot_params    = (DA8XX_DDR_BASE + 0x100),
387         .map_io         = da830_evm_map_io,
388         .init_irq       = da830_evm_irq_init,
389         .timer          = &davinci_timer,
390         .init_machine   = da830_evm_init,
391 MACHINE_END