Merge branch 'for-tony' of git://gitorious.org/usb/usb into omap-for-linus
[pandora-kernel.git] / arch / arm / mach-omap2 / board-omap4panda.c
1 /*
2  * Board support file for OMAP4430 based PandaBoard.
3  *
4  * Copyright (C) 2010 Texas Instruments
5  *
6  * Author: David Anders <x0132446@ti.com>
7  *
8  * Based on mach-omap2/board-4430sdp.c
9  *
10  * Author: Santosh Shilimkar <santosh.shilimkar@ti.com>
11  *
12  * Based on mach-omap2/board-3430sdp.c
13  *
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License version 2 as
16  * published by the Free Software Foundation.
17  */
18
19 #include <linux/kernel.h>
20 #include <linux/init.h>
21 #include <linux/platform_device.h>
22 #include <linux/clk.h>
23 #include <linux/io.h>
24 #include <linux/leds.h>
25 #include <linux/gpio.h>
26 #include <linux/usb/otg.h>
27 #include <linux/i2c/twl.h>
28 #include <linux/regulator/machine.h>
29
30 #include <mach/hardware.h>
31 #include <mach/omap4-common.h>
32 #include <asm/mach-types.h>
33 #include <asm/mach/arch.h>
34 #include <asm/mach/map.h>
35
36 #include <plat/board.h>
37 #include <plat/common.h>
38 #include <plat/usb.h>
39 #include <plat/mmc.h>
40 #include "timer-gp.h"
41
42 #include "hsmmc.h"
43 #include "control.h"
44 #include "mux.h"
45
46 #define GPIO_HUB_POWER          1
47 #define GPIO_HUB_NRESET         62
48
49 static struct gpio_led gpio_leds[] = {
50         {
51                 .name                   = "pandaboard::status1",
52                 .default_trigger        = "heartbeat",
53                 .gpio                   = 7,
54         },
55         {
56                 .name                   = "pandaboard::status2",
57                 .default_trigger        = "mmc0",
58                 .gpio                   = 8,
59         },
60 };
61
62 static struct gpio_led_platform_data gpio_led_info = {
63         .leds           = gpio_leds,
64         .num_leds       = ARRAY_SIZE(gpio_leds),
65 };
66
67 static struct platform_device leds_gpio = {
68         .name   = "leds-gpio",
69         .id     = -1,
70         .dev    = {
71                 .platform_data  = &gpio_led_info,
72         },
73 };
74
75 static struct platform_device *panda_devices[] __initdata = {
76         &leds_gpio,
77 };
78
79 static void __init omap4_panda_init_early(void)
80 {
81         omap2_init_common_infrastructure();
82         omap2_init_common_devices(NULL, NULL);
83 }
84
85 static const struct ehci_hcd_omap_platform_data ehci_pdata __initconst = {
86         .port_mode[0] = EHCI_HCD_OMAP_MODE_PHY,
87         .port_mode[1] = EHCI_HCD_OMAP_MODE_UNKNOWN,
88         .port_mode[2] = EHCI_HCD_OMAP_MODE_UNKNOWN,
89         .phy_reset  = false,
90         .reset_gpio_port[0]  = -EINVAL,
91         .reset_gpio_port[1]  = -EINVAL,
92         .reset_gpio_port[2]  = -EINVAL
93 };
94
95 static void __init omap4_ehci_init(void)
96 {
97         int ret;
98         struct clk *phy_ref_clk;
99
100         /* FREF_CLK3 provides the 19.2 MHz reference clock to the PHY */
101         phy_ref_clk = clk_get(NULL, "auxclk3_ck");
102         if (IS_ERR(phy_ref_clk)) {
103                 pr_err("Cannot request auxclk3\n");
104                 goto error1;
105         }
106         clk_set_rate(phy_ref_clk, 19200000);
107         clk_enable(phy_ref_clk);
108
109         /* disable the power to the usb hub prior to init */
110         ret = gpio_request(GPIO_HUB_POWER, "hub_power");
111         if (ret) {
112                 pr_err("Cannot request GPIO %d\n", GPIO_HUB_POWER);
113                 goto error1;
114         }
115         gpio_export(GPIO_HUB_POWER, 0);
116         gpio_direction_output(GPIO_HUB_POWER, 0);
117         gpio_set_value(GPIO_HUB_POWER, 0);
118
119         /* reset phy+hub */
120         ret = gpio_request(GPIO_HUB_NRESET, "hub_nreset");
121         if (ret) {
122                 pr_err("Cannot request GPIO %d\n", GPIO_HUB_NRESET);
123                 goto error2;
124         }
125         gpio_export(GPIO_HUB_NRESET, 0);
126         gpio_direction_output(GPIO_HUB_NRESET, 0);
127         gpio_set_value(GPIO_HUB_NRESET, 0);
128         gpio_set_value(GPIO_HUB_NRESET, 1);
129
130         usb_ehci_init(&ehci_pdata);
131
132         /* enable power to hub */
133         gpio_set_value(GPIO_HUB_POWER, 1);
134         return;
135
136 error2:
137         gpio_free(GPIO_HUB_POWER);
138 error1:
139         pr_err("Unable to initialize EHCI power/reset\n");
140         return;
141
142 }
143
144 static struct omap_musb_board_data musb_board_data = {
145         .interface_type         = MUSB_INTERFACE_UTMI,
146         .mode                   = MUSB_OTG,
147         .power                  = 100,
148 };
149
150 static struct twl4030_usb_data omap4_usbphy_data = {
151         .phy_init       = omap4430_phy_init,
152         .phy_exit       = omap4430_phy_exit,
153         .phy_power      = omap4430_phy_power,
154         .phy_set_clock  = omap4430_phy_set_clk,
155 };
156
157 static struct omap2_hsmmc_info mmc[] = {
158         {
159                 .mmc            = 1,
160                 .caps           = MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA,
161                 .gpio_wp        = -EINVAL,
162                 .gpio_cd        = -EINVAL,
163         },
164         {}      /* Terminator */
165 };
166
167 static struct regulator_consumer_supply omap4_panda_vmmc_supply[] = {
168         {
169                 .supply = "vmmc",
170                 .dev_name = "mmci-omap-hs.0",
171         },
172 };
173
174 static int omap4_twl6030_hsmmc_late_init(struct device *dev)
175 {
176         int ret = 0;
177         struct platform_device *pdev = container_of(dev,
178                                 struct platform_device, dev);
179         struct omap_mmc_platform_data *pdata = dev->platform_data;
180
181         if (!pdata) {
182                 dev_err(dev, "%s: NULL platform data\n", __func__);
183                 return -EINVAL;
184         }
185         /* Setting MMC1 Card detect Irq */
186         if (pdev->id == 0) {
187                 ret = twl6030_mmc_card_detect_config();
188                  if (ret)
189                         dev_err(dev, "%s: Error card detect config(%d)\n",
190                                 __func__, ret);
191                  else
192                         pdata->slots[0].card_detect = twl6030_mmc_card_detect;
193         }
194         return ret;
195 }
196
197 static __init void omap4_twl6030_hsmmc_set_late_init(struct device *dev)
198 {
199         struct omap_mmc_platform_data *pdata;
200
201         /* dev can be null if CONFIG_MMC_OMAP_HS is not set */
202         if (!dev) {
203                 pr_err("Failed omap4_twl6030_hsmmc_set_late_init\n");
204                 return;
205         }
206         pdata = dev->platform_data;
207
208         pdata->init =   omap4_twl6030_hsmmc_late_init;
209 }
210
211 static int __init omap4_twl6030_hsmmc_init(struct omap2_hsmmc_info *controllers)
212 {
213         struct omap2_hsmmc_info *c;
214
215         omap2_hsmmc_init(controllers);
216         for (c = controllers; c->mmc; c++)
217                 omap4_twl6030_hsmmc_set_late_init(c->dev);
218
219         return 0;
220 }
221
222 static struct regulator_init_data omap4_panda_vaux1 = {
223         .constraints = {
224                 .min_uV                 = 1000000,
225                 .max_uV                 = 3000000,
226                 .apply_uV               = true,
227                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
228                                         | REGULATOR_MODE_STANDBY,
229                 .valid_ops_mask  = REGULATOR_CHANGE_VOLTAGE
230                                         | REGULATOR_CHANGE_MODE
231                                         | REGULATOR_CHANGE_STATUS,
232         },
233 };
234
235 static struct regulator_init_data omap4_panda_vaux2 = {
236         .constraints = {
237                 .min_uV                 = 1200000,
238                 .max_uV                 = 2800000,
239                 .apply_uV               = true,
240                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
241                                         | REGULATOR_MODE_STANDBY,
242                 .valid_ops_mask  = REGULATOR_CHANGE_VOLTAGE
243                                         | REGULATOR_CHANGE_MODE
244                                         | REGULATOR_CHANGE_STATUS,
245         },
246 };
247
248 static struct regulator_init_data omap4_panda_vaux3 = {
249         .constraints = {
250                 .min_uV                 = 1000000,
251                 .max_uV                 = 3000000,
252                 .apply_uV               = true,
253                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
254                                         | REGULATOR_MODE_STANDBY,
255                 .valid_ops_mask  = REGULATOR_CHANGE_VOLTAGE
256                                         | REGULATOR_CHANGE_MODE
257                                         | REGULATOR_CHANGE_STATUS,
258         },
259 };
260
261 /* VMMC1 for MMC1 card */
262 static struct regulator_init_data omap4_panda_vmmc = {
263         .constraints = {
264                 .min_uV                 = 1200000,
265                 .max_uV                 = 3000000,
266                 .apply_uV               = true,
267                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
268                                         | REGULATOR_MODE_STANDBY,
269                 .valid_ops_mask  = REGULATOR_CHANGE_VOLTAGE
270                                         | REGULATOR_CHANGE_MODE
271                                         | REGULATOR_CHANGE_STATUS,
272         },
273         .num_consumer_supplies  = 1,
274         .consumer_supplies      = omap4_panda_vmmc_supply,
275 };
276
277 static struct regulator_init_data omap4_panda_vpp = {
278         .constraints = {
279                 .min_uV                 = 1800000,
280                 .max_uV                 = 2500000,
281                 .apply_uV               = true,
282                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
283                                         | REGULATOR_MODE_STANDBY,
284                 .valid_ops_mask  = REGULATOR_CHANGE_VOLTAGE
285                                         | REGULATOR_CHANGE_MODE
286                                         | REGULATOR_CHANGE_STATUS,
287         },
288 };
289
290 static struct regulator_init_data omap4_panda_vusim = {
291         .constraints = {
292                 .min_uV                 = 1200000,
293                 .max_uV                 = 2900000,
294                 .apply_uV               = true,
295                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
296                                         | REGULATOR_MODE_STANDBY,
297                 .valid_ops_mask  = REGULATOR_CHANGE_VOLTAGE
298                                         | REGULATOR_CHANGE_MODE
299                                         | REGULATOR_CHANGE_STATUS,
300         },
301 };
302
303 static struct regulator_init_data omap4_panda_vana = {
304         .constraints = {
305                 .min_uV                 = 2100000,
306                 .max_uV                 = 2100000,
307                 .apply_uV               = true,
308                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
309                                         | REGULATOR_MODE_STANDBY,
310                 .valid_ops_mask  = REGULATOR_CHANGE_MODE
311                                         | REGULATOR_CHANGE_STATUS,
312         },
313 };
314
315 static struct regulator_init_data omap4_panda_vcxio = {
316         .constraints = {
317                 .min_uV                 = 1800000,
318                 .max_uV                 = 1800000,
319                 .apply_uV               = true,
320                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
321                                         | REGULATOR_MODE_STANDBY,
322                 .valid_ops_mask  = REGULATOR_CHANGE_MODE
323                                         | REGULATOR_CHANGE_STATUS,
324         },
325 };
326
327 static struct regulator_init_data omap4_panda_vdac = {
328         .constraints = {
329                 .min_uV                 = 1800000,
330                 .max_uV                 = 1800000,
331                 .apply_uV               = true,
332                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
333                                         | REGULATOR_MODE_STANDBY,
334                 .valid_ops_mask  = REGULATOR_CHANGE_MODE
335                                         | REGULATOR_CHANGE_STATUS,
336         },
337 };
338
339 static struct regulator_init_data omap4_panda_vusb = {
340         .constraints = {
341                 .min_uV                 = 3300000,
342                 .max_uV                 = 3300000,
343                 .apply_uV               = true,
344                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
345                                         | REGULATOR_MODE_STANDBY,
346                 .valid_ops_mask  =      REGULATOR_CHANGE_MODE
347                                         | REGULATOR_CHANGE_STATUS,
348         },
349 };
350
351 static struct twl4030_platform_data omap4_panda_twldata = {
352         .irq_base       = TWL6030_IRQ_BASE,
353         .irq_end        = TWL6030_IRQ_END,
354
355         /* Regulators */
356         .vmmc           = &omap4_panda_vmmc,
357         .vpp            = &omap4_panda_vpp,
358         .vusim          = &omap4_panda_vusim,
359         .vana           = &omap4_panda_vana,
360         .vcxio          = &omap4_panda_vcxio,
361         .vdac           = &omap4_panda_vdac,
362         .vusb           = &omap4_panda_vusb,
363         .vaux1          = &omap4_panda_vaux1,
364         .vaux2          = &omap4_panda_vaux2,
365         .vaux3          = &omap4_panda_vaux3,
366         .usb            = &omap4_usbphy_data,
367 };
368
369 static struct i2c_board_info __initdata omap4_panda_i2c_boardinfo[] = {
370         {
371                 I2C_BOARD_INFO("twl6030", 0x48),
372                 .flags = I2C_CLIENT_WAKE,
373                 .irq = OMAP44XX_IRQ_SYS_1N,
374                 .platform_data = &omap4_panda_twldata,
375         },
376 };
377 static int __init omap4_panda_i2c_init(void)
378 {
379         /*
380          * Phoenix Audio IC needs I2C1 to
381          * start with 400 KHz or less
382          */
383         omap_register_i2c_bus(1, 400, omap4_panda_i2c_boardinfo,
384                         ARRAY_SIZE(omap4_panda_i2c_boardinfo));
385         omap_register_i2c_bus(2, 400, NULL, 0);
386         omap_register_i2c_bus(3, 400, NULL, 0);
387         omap_register_i2c_bus(4, 400, NULL, 0);
388         return 0;
389 }
390
391 #ifdef CONFIG_OMAP_MUX
392 static struct omap_board_mux board_mux[] __initdata = {
393         { .reg_offset = OMAP_MUX_TERMINATOR },
394 };
395 #else
396 #define board_mux       NULL
397 #endif
398
399 static void __init omap4_panda_init(void)
400 {
401         int package = OMAP_PACKAGE_CBS;
402
403         if (omap_rev() == OMAP4430_REV_ES1_0)
404                 package = OMAP_PACKAGE_CBL;
405         omap4_mux_init(board_mux, package);
406
407         omap4_panda_i2c_init();
408         platform_add_devices(panda_devices, ARRAY_SIZE(panda_devices));
409         omap_serial_init();
410         omap4_twl6030_hsmmc_init(mmc);
411         omap4_ehci_init();
412         usb_musb_init(&musb_board_data);
413 }
414
415 static void __init omap4_panda_map_io(void)
416 {
417         omap2_set_globals_443x();
418         omap44xx_map_common_io();
419 }
420
421 MACHINE_START(OMAP4_PANDA, "OMAP4 Panda board")
422         /* Maintainer: David Anders - Texas Instruments Inc */
423         .boot_params    = 0x80000100,
424         .reserve        = omap_reserve,
425         .map_io         = omap4_panda_map_io,
426         .init_early     = omap4_panda_init_early,
427         .init_irq       = gic_init_irq,
428         .init_machine   = omap4_panda_init,
429         .timer          = &omap_timer,
430 MACHINE_END