arm: tegra: usb_phy: Link ULPI platform data
[linux-2.6.git] / arch / arm / mach-tegra / board-curacao.c
1 /*
2  * arch/arm/mach-tegra/board-curacao.c
3  *
4  * Copyright (c) 2011-2012, NVIDIA Corporation.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19  */
20
21 #include <linux/kernel.h>
22 #include <linux/init.h>
23 #include <linux/slab.h>
24 #include <linux/ctype.h>
25 #include <linux/platform_device.h>
26 #include <linux/clk.h>
27 #include <linux/serial_8250.h>
28 #include <linux/tegra_uart.h>
29 #include <linux/i2c.h>
30 #include <linux/i2c/panjit_ts.h>
31 #include <linux/dma-mapping.h>
32 #include <linux/delay.h>
33 #include <linux/i2c-tegra.h>
34 #include <linux/gpio.h>
35 #include <linux/gpio_keys.h>
36 #include <linux/input.h>
37 #include <linux/platform_data/tegra_usb.h>
38
39 #include <mach/clk.h>
40 #include <mach/gpio-tegra.h>
41 #include <mach/iomap.h>
42 #include <mach/io_dpd.h>
43 #include <mach/irqs.h>
44 #include <mach/pinmux.h>
45 #include <mach/iomap.h>
46 #include <mach/io.h>
47 #include <mach/i2s.h>
48 #include <mach/audio.h>
49 #include <mach/usb_phy.h>
50 #include <mach/nand.h>
51 #include <mach/hardware.h>
52
53 #include <asm/hardware/gic.h>
54 #include <asm/mach-types.h>
55 #include <asm/mach/arch.h>
56
57 #include "board.h"
58 #include "board-curacao.h"
59 #include "clock.h"
60 #include "common.h"
61 #include "devices.h"
62 #include "fuse.h"
63 #include "gpio-names.h"
64
65 #define ENABLE_OTG 0
66
67 static struct plat_serial8250_port debug_uart_platform_data[] = {
68         {
69                 .membase        = IO_ADDRESS(TEGRA_UARTA_BASE),
70                 .mapbase        = TEGRA_UARTA_BASE,
71                 .irq            = INT_UARTA,
72                 .flags          = UPF_BOOT_AUTOCONF | UPF_FIXED_TYPE,
73                 .type           = PORT_TEGRA,
74                 .iotype         = UPIO_MEM,
75                 .regshift       = 2,
76                 .uartclk        = 13000000,
77         }, {
78                 .flags          = 0,
79         }
80 };
81
82 static struct platform_device debug_uart = {
83         .name = "serial8250",
84         .id = PLAT8250_DEV_PLATFORM,
85         .dev = {
86                 .platform_data = debug_uart_platform_data,
87         },
88 };
89
90
91 #ifdef CONFIG_BCM4329_RFKILL
92
93 static struct resource curacao_bcm4329_rfkill_resources[] = {
94         {
95                 .name   = "bcm4329_nreset_gpio",
96                 .start  = TEGRA_GPIO_PU0,
97                 .end    = TEGRA_GPIO_PU0,
98                 .flags  = IORESOURCE_IO,
99         },
100         {
101                 .name   = "bcm4329_nshutdown_gpio",
102                 .start  = TEGRA_GPIO_PK2,
103                 .end    = TEGRA_GPIO_PK2,
104                 .flags  = IORESOURCE_IO,
105         },
106 };
107
108 static struct platform_device curacao_bcm4329_rfkill_device = {
109         .name = "bcm4329_rfkill",
110         .id             = -1,
111         .num_resources  = ARRAY_SIZE(curacao_bcm4329_rfkill_resources),
112         .resource       = curacao_bcm4329_rfkill_resources,
113 };
114
115 static noinline void __init curacao_bt_rfkill(void)
116 {
117         /*Add Clock Resource*/
118         clk_add_alias("bcm4329_32k_clk", curacao_bcm4329_rfkill_device.name, \
119                                 "blink", NULL);
120
121         platform_device_register(&curacao_bcm4329_rfkill_device);
122
123         return;
124 }
125 #else
126 static inline void curacao_bt_rfkill(void) { }
127 #endif
128
129 static __initdata struct tegra_clk_init_table curacao_clk_init_table[] = {
130         /* name         parent          rate            enabled */
131         { "uarta",      "clk_m",        13000000,       true},
132         { "uartb",      "clk_m",        13000000,       true},
133         { "uartc",      "clk_m",        13000000,       true},
134         { "uartd",      "clk_m",        13000000,       true},
135         { "uarte",      "clk_m",        13000000,       true},
136         { "sdmmc1",     "clk_m",        13000000,       false},
137         { "sdmmc3",     "clk_m",        13000000,       false},
138         { "sdmmc4",     "clk_m",        13000000,       false},
139         { "blink",      "clk_32k",      32768,          false},
140         { "pwm",        "clk_32k",      32768,          false},
141         { "blink",      "clk_32k",      32768,          false},
142         { "pll_a",      NULL,           56448000,       true},
143         { "pll_a_out0", NULL,           11289600,       true},
144         { "i2s1",       "pll_a_out0",   11289600,       true},
145         { "i2s2",       "pll_a_out0",   11289600,       true},
146         { "d_audio",    "pll_a_out0",   11289600,       false},
147         { "audio_2x",   "audio",        22579200,       true},
148         { NULL,         NULL,           0,              0},
149 };
150
151 static struct i2c_board_info __initdata curacao_i2c_bus1_board_info[] = {
152         {
153                 I2C_BOARD_INFO("wm8903", 0x1a),
154         },
155 };
156
157 static struct tegra_i2c_platform_data curacao_i2c1_platform_data = {
158         .adapter_nr     = 0,
159         .bus_count      = 1,
160         .bus_clk_rate   = { 100000, 0 },
161 };
162
163 #if 0   /* !!!FIXME!!! */
164 static const struct tegra_pingroup_config i2c2_ddc = {
165         .pingroup       = TEGRA_PINGROUP_DDC,
166         .func           = TEGRA_MUX_I2C2,
167 };
168
169 static const struct tegra_pingroup_config i2c2_gen2 = {
170         .pingroup       = TEGRA_PINGROUP_PTA,
171         .func           = TEGRA_MUX_I2C2,
172 };
173 #endif
174
175 static struct tegra_i2c_slave_platform_data curacao_i2c2_slave_platform_data = {
176         .adapter_nr     = 1,
177         .bus_clk_rate   = 100000,
178 };
179
180 static struct tegra_i2c_platform_data curacao_i2c3_platform_data = {
181         .adapter_nr     = 3,
182         .bus_count      = 1,
183         .bus_clk_rate   = { 100000, 0 },
184 };
185
186 static struct tegra_i2c_platform_data curacao_i2c4_platform_data = {
187         .adapter_nr     = 4,
188         .bus_count      = 1,
189         .bus_clk_rate   = { 100000, 0 },
190 };
191
192 static struct tegra_i2c_platform_data curacao_i2c5_platform_data = {
193         .adapter_nr     = 5,
194         .bus_count      = 1,
195         .bus_clk_rate   = { 100000, 0 },
196 };
197
198 static void curacao_i2c_init(void)
199 {
200         tegra11_i2c_device1.dev.platform_data = &curacao_i2c1_platform_data;
201         tegra_i2c_slave_device2.dev.platform_data =
202                                         &curacao_i2c2_slave_platform_data;
203         tegra11_i2c_device3.dev.platform_data = &curacao_i2c3_platform_data;
204         tegra11_i2c_device4.dev.platform_data = &curacao_i2c4_platform_data;
205         tegra11_i2c_device5.dev.platform_data = &curacao_i2c5_platform_data;
206
207         i2c_register_board_info(0, curacao_i2c_bus1_board_info, 1);
208
209         platform_device_register(&tegra11_i2c_device5);
210         platform_device_register(&tegra11_i2c_device4);
211         platform_device_register(&tegra11_i2c_device3);
212         platform_device_register(&tegra_i2c_slave_device2);
213         platform_device_register(&tegra11_i2c_device1);
214 }
215
216 #define GPIO_KEY(_id, _gpio, _iswake)           \
217         {                                       \
218                 .code = _id,                    \
219                 .gpio = TEGRA_GPIO_##_gpio,     \
220                 .active_low = 1,                \
221                 .desc = #_id,                   \
222                 .type = EV_KEY,                 \
223                 .wakeup = _iswake,              \
224                 .debounce_interval = 10,        \
225         }
226
227 /* !!!FIXME!!! */
228 static struct gpio_keys_button curacao_keys[] = {
229         [0] = GPIO_KEY(KEY_MENU, PQ0, 0),
230         [1] = GPIO_KEY(KEY_HOME, PQ1, 0),
231         [2] = GPIO_KEY(KEY_BACK, PQ2, 0),
232         [3] = GPIO_KEY(KEY_VOLUMEUP, PQ3, 0),
233         [4] = GPIO_KEY(KEY_VOLUMEDOWN, PQ4, 0),
234         [5] = GPIO_KEY(KEY_POWER, PV2, 1),
235 };
236
237 static struct gpio_keys_platform_data curacao_keys_platform_data = {
238         .buttons        = curacao_keys,
239         .nbuttons       = ARRAY_SIZE(curacao_keys),
240 };
241
242 static struct platform_device curacao_keys_device = {
243         .name   = "gpio-keys",
244         .id     = 0,
245         .dev    = {
246                 .platform_data  = &curacao_keys_platform_data,
247         },
248 };
249
250 static struct platform_device tegra_camera = {
251         .name = "tegra_camera",
252         .id = -1,
253 };
254
255 static struct resource tegra_rtc_resources[] = {
256         [0] = {
257                 .start = TEGRA_RTC_BASE,
258                 .end = TEGRA_RTC_BASE + TEGRA_RTC_SIZE - 1,
259                 .flags = IORESOURCE_MEM,
260         },
261         [1] = {
262                 .start = INT_RTC,
263                 .end = INT_RTC,
264                 .flags = IORESOURCE_IRQ,
265         },
266 };
267
268 static struct platform_device tegra_rtc_device = {
269         .name = "tegra_rtc",
270         .id   = -1,
271         .resource = tegra_rtc_resources,
272         .num_resources = ARRAY_SIZE(tegra_rtc_resources),
273 };
274
275 #if defined(CONFIG_MTD_NAND_TEGRA)
276 static struct resource nand_resources[] = {
277         [0] = {
278                 .start = INT_NANDFLASH,
279                 .end   = INT_NANDFLASH,
280                 .flags = IORESOURCE_IRQ
281         },
282         [1] = {
283                 .start = TEGRA_NAND_BASE,
284                 .end = TEGRA_NAND_BASE + TEGRA_NAND_SIZE - 1,
285                 .flags = IORESOURCE_MEM
286         }
287 };
288
289 static struct tegra_nand_chip_parms nand_chip_parms[] = {
290         /* Samsung K5E2G1GACM */
291         [0] = {
292                 .vendor_id   = 0xEC,
293                 .device_id   = 0xAA,
294                 .capacity    = 256,
295                 .timing      = {
296                         .trp            = 21,
297                         .trh            = 15,
298                         .twp            = 21,
299                         .twh            = 15,
300                         .tcs            = 31,
301                         .twhr           = 60,
302                         .tcr_tar_trr    = 20,
303                         .twb            = 100,
304                         .trp_resp       = 30,
305                         .tadl           = 100,
306                 },
307         },
308         /* Hynix H5PS1GB3EFR */
309         [1] = {
310                 .vendor_id   = 0xAD,
311                 .device_id   = 0xDC,
312                 .capacity    = 512,
313                 .timing      = {
314                         .trp            = 12,
315                         .trh            = 10,
316                         .twp            = 12,
317                         .twh            = 10,
318                         .tcs            = 20,
319                         .twhr           = 80,
320                         .tcr_tar_trr    = 20,
321                         .twb            = 100,
322                         .trp_resp       = 20,
323                         .tadl           = 70,
324                 },
325         },
326 };
327
328 struct tegra_nand_platform nand_data = {
329         .max_chips      = 8,
330         .chip_parms     = nand_chip_parms,
331         .nr_chip_parms  = ARRAY_SIZE(nand_chip_parms),
332 };
333
334 struct platform_device tegra_nand_device = {
335         .name          = "tegra_nand",
336         .id            = -1,
337         .resource      = nand_resources,
338         .num_resources = ARRAY_SIZE(nand_resources),
339         .dev            = {
340                 .platform_data = &nand_data,
341         },
342 };
343 #endif
344
345 #if defined(CONFIG_TEGRA_SIMULATION_PLATFORM) && defined(CONFIG_SMC91X)
346 static struct resource tegra_sim_smc91x_resources[] = {
347         [0] = {
348                 .start          = TEGRA_SIM_ETH_BASE,
349                 .end            = TEGRA_SIM_ETH_BASE + TEGRA_SIM_ETH_SIZE - 1,
350                 .flags          = IORESOURCE_MEM,
351         },
352         [1] = {
353                 .start          = IRQ_ETH,
354                 .end            = IRQ_ETH,
355                 .flags          = IORESOURCE_IRQ,
356         },
357 };
358
359 static struct platform_device tegra_sim_smc91x_device = {
360         .name           = "smc91x",
361         .id             = 0,
362         .num_resources  = ARRAY_SIZE(tegra_sim_smc91x_resources),
363         .resource       = tegra_sim_smc91x_resources,
364 };
365 #endif
366
367 static struct platform_device *curacao_devices[] __initdata = {
368 #if ENABLE_OTG
369         &tegra_otg_device,
370 #endif
371         &debug_uart,
372         &tegra_pmu_device,
373         &tegra_rtc_device,
374         &tegra_udc_device,
375 #if defined(CONFIG_TEGRA_IOVMM_SMMU)
376         &tegra_smmu_device,
377 #endif
378         &curacao_keys_device,
379 #if defined(CONFIG_SND_HDA_TEGRA)
380         &tegra_hda_device,
381 #endif
382         &tegra_avp_device,
383         &tegra_camera,
384 #if defined(CONFIG_CRYPTO_DEV_TEGRA_SE)
385         &tegra11_se_device,
386 #endif
387 #if defined(CONFIG_MTD_NAND_TEGRA)
388         &tegra_nand_device,
389 #endif
390
391 #if defined(CONFIG_TEGRA_SIMULATION_PLATFORM) && defined(CONFIG_SMC91X)
392         &tegra_sim_smc91x_device,
393 #endif
394 };
395
396 static void curacao_keys_init(void)
397 {
398         int i;
399
400         for (i = 0; i < ARRAY_SIZE(curacao_keys); i++)
401                 tegra_gpio_enable(curacao_keys[i].gpio);
402 }
403
404 static int __init curacao_touch_init(void)
405 {
406         return 0;
407 }
408
409
410 #if defined(USB_HOST_ONLY)
411 static struct tegra_usb_platform_data tegra_ehci1_utmi_pdata = {
412         .port_otg = true,
413         .has_hostpc = true,
414         .unaligned_dma_buf_supported = true,
415         .phy_intf = TEGRA_USB_PHY_INTF_UTMI,
416         .op_mode = TEGRA_USB_OPMODE_HOST,
417         .u_data.host = {
418                 .vbus_gpio = -1,
419                 .vbus_reg = "vdd_vbus_micro_usb",
420                 .hot_plug = true,
421                 .remote_wakeup_supported = true,
422                 .power_off_on_suspend = true,
423         },
424         .u_cfg.utmi = {
425                 .hssync_start_delay = 0,
426                 .elastic_limit = 16,
427                 .idle_wait_delay = 17,
428                 .term_range_adj = 6,
429                 .xcvr_setup = 15,
430                 .xcvr_lsfslew = 2,
431                 .xcvr_lsrslew = 2,
432                 .xcvr_setup_offset = 0,
433                 .xcvr_use_fuses = 1,
434         },
435 };
436
437
438 static void ulpi_link_platform_open(void)
439 {
440         int reset_gpio = TEGRA_GPIO_PV1;
441
442         gpio_request(reset_gpio, "ulpi_phy_reset");
443         gpio_direction_output(reset_gpio, 0);
444         tegra_gpio_enable(reset_gpio);
445
446         gpio_direction_output(reset_gpio, 0);
447         msleep(5);
448         gpio_direction_output(reset_gpio, 1);
449 }
450
451 static struct tegra_usb_phy_platform_ops ulpi_link_plat_ops = {
452         .open = ulpi_link_platform_open,
453 };
454
455 static struct tegra_usb_platform_data tegra_ehci2_ulpi_link_pdata = {
456         .port_otg = false,
457         .has_hostpc = true,
458         .unaligned_dma_buf_supported = true,
459         .phy_intf = TEGRA_USB_PHY_INTF_ULPI_LINK,
460         .op_mode        = TEGRA_USB_OPMODE_HOST,
461         .u_data.host = {
462                 .vbus_gpio = -1,
463                 .vbus_reg = NULL,
464                 .hot_plug = false,
465                 .remote_wakeup_supported = false,
466                 .power_off_on_suspend = true,
467         },
468         .u_cfg.ulpi = {
469                 .shadow_clk_delay = 10,
470                 .clock_out_delay = 1,
471                 .data_trimmer = 4,
472                 .stpdirnxt_trimmer = 4,
473                 .dir_trimmer = 4,
474                 .clk = "cdev2",
475         },
476         .ops = &ulpi_link_plat_ops,
477 };
478 #else
479
480 static struct tegra_usb_platform_data tegra_udc_pdata = {
481         .port_otg = true,
482         .has_hostpc = true,
483         .phy_intf = TEGRA_USB_PHY_INTF_UTMI,
484         .op_mode = TEGRA_USB_OPMODE_DEVICE,
485         .u_data.dev = {
486                 .vbus_pmu_irq = 0,
487                 .vbus_gpio = -1,
488                 .charging_supported = false,
489                 .remote_wakeup_supported = false,
490         },
491         .u_cfg.utmi = {
492                 .hssync_start_delay = 0,
493                 .elastic_limit = 16,
494                 .idle_wait_delay = 17,
495                 .term_range_adj = 6,
496                 .xcvr_setup = 8,
497                 .xcvr_lsfslew = 2,
498                 .xcvr_lsrslew = 2,
499                 .xcvr_setup_offset = 0,
500                 .xcvr_use_fuses = 1,
501         },
502 };
503
504 #endif
505
506 static void curacao_usb_init(void)
507 {
508 #if defined(USB_HOST_ONLY)
509         tegra_ehci1_device.dev.platform_data = &tegra_ehci1_utmi_pdata;
510         platform_device_register(&tegra_ehci1_device);
511
512         tegra_ehci2_device.dev.platform_data = &tegra_ehci2_ulpi_link_pdata;
513         platform_device_register(&tegra_ehci2_device);
514 #else
515         /* setup the udc platform data */
516         tegra_udc_device.dev.platform_data = &tegra_udc_pdata;
517
518 #endif
519 }
520
521 static struct platform_device *curacao_hs_uart_devices[] __initdata = {
522         &tegra_uartb_device,
523         &tegra_uartc_device,
524         &tegra_uartd_device,
525         &tegra_uarte_device,
526 };
527
528 static struct uart_clk_parent uart_parent_clk[] = {
529         [0] = {.name = "clk_m"},
530 };
531
532 static struct tegra_uart_platform_data curacao_uart_pdata;
533 static struct tegra_uart_platform_data curacao_loopback_uart_pdata;
534
535 static void __init curacao_hs_uart_init(void)
536 {
537         struct clk *c;
538         int i;
539
540         for (i = 0; i < ARRAY_SIZE(uart_parent_clk); ++i) {
541                 c = tegra_get_clock_by_name(uart_parent_clk[i].name);
542                 if (IS_ERR_OR_NULL(c)) {
543                         pr_err("Not able to get the clock for %s\n",
544                                         uart_parent_clk[i].name);
545                         continue;
546                 }
547                 uart_parent_clk[i].parent_clk = c;
548                 uart_parent_clk[i].fixed_clk_rate = clk_get_rate(c);
549         }
550         curacao_uart_pdata.parent_clk_list = uart_parent_clk;
551         curacao_loopback_uart_pdata.parent_clk_list = uart_parent_clk;
552         curacao_uart_pdata.parent_clk_count = ARRAY_SIZE(uart_parent_clk);
553         curacao_loopback_uart_pdata.parent_clk_count =
554                                                 ARRAY_SIZE(uart_parent_clk);
555         curacao_loopback_uart_pdata.is_loopback = true;
556         tegra_uartb_device.dev.platform_data = &curacao_uart_pdata;
557         tegra_uartc_device.dev.platform_data = &curacao_uart_pdata;
558         tegra_uartd_device.dev.platform_data = &curacao_uart_pdata;
559         tegra_uarte_device.dev.platform_data = &curacao_loopback_uart_pdata;
560         platform_add_devices(curacao_hs_uart_devices,
561                                 ARRAY_SIZE(curacao_hs_uart_devices));
562 }
563
564 static void __init tegra_curacao_init(void)
565 {
566         tegra_clk_init_from_table(curacao_clk_init_table);
567         tegra_enable_pinmux();
568         curacao_pinmux_init();
569
570         if (tegra_revision == TEGRA_REVISION_QT)
571                 debug_uart_platform_data[0].uartclk = tegra_clk_measure_input_freq();
572
573         platform_add_devices(curacao_devices, ARRAY_SIZE(curacao_devices));
574
575         curacao_power_off_init();
576         tegra_io_dpd_init();
577         curacao_sdhci_init();
578         curacao_i2c_init();
579         curacao_regulator_init();
580         curacao_suspend_init();
581         curacao_touch_init();
582         curacao_keys_init();
583         curacao_usb_init();
584         curacao_panel_init();
585         curacao_hs_uart_init();
586         curacao_bt_rfkill();
587         curacao_sensors_init();
588 }
589
590 static void __init tegra_curacao_reserve(void)
591 {
592 #if defined(CONFIG_NVMAP_CONVERT_CARVEOUT_TO_IOVMM)
593         tegra_reserve(0, SZ_4M, 0);
594 #else
595         tegra_reserve(SZ_32M, SZ_4M, 0);
596 #endif
597 }
598
599 MACHINE_START(CURACAO, CURACAO_BOARD_NAME)
600         .atag_offset    = 0x80000100,
601         .soc            = &tegra_soc_desc,
602         .map_io         = tegra_map_common_io,
603         .reserve        = tegra_curacao_reserve,
604         .init_early     = tegra11x_init_early,
605         .init_irq       = tegra_init_irq,
606         .handle_irq     = gic_handle_irq,
607         .timer          = &tegra_timer,
608         .init_machine   = tegra_curacao_init,
609 MACHINE_END