ARM: tegra: roth: No power off on USB bus suspend
[linux-3.10.git] / arch / arm / mach-tegra / board-roth.c
1 /*
2  * arch/arm/mach-tegra/board-roth.c
3  *
4  * Copyright (c) 2012, NVIDIA CORPORATION.  All rights reserved.
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 version 2 as
8  * published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18  */
19
20 #include <linux/kernel.h>
21 #include <linux/init.h>
22 #include <linux/slab.h>
23 #include <linux/ctype.h>
24 #include <linux/platform_device.h>
25 #include <linux/clk.h>
26 #include <linux/serial_8250.h>
27 #include <linux/i2c.h>
28 #include <linux/dma-mapping.h>
29 #include <linux/delay.h>
30 #include <linux/i2c-tegra.h>
31 #include <linux/gpio.h>
32 #include <linux/input.h>
33 #include <linux/platform_data/tegra_usb.h>
34 #include <linux/tegra_uart.h>
35 #include <linux/memblock.h>
36 #include <linux/rfkill-gpio.h>
37 #include <linux/skbuff.h>
38 #include <linux/ti_wilink_st.h>
39 #include <linux/regulator/consumer.h>
40 #include <linux/max17048_battery.h>
41 #include <linux/leds.h>
42 #include <linux/i2c/at24.h>
43 #include <linux/of_platform.h>
44
45 #include <asm/hardware/gic.h>
46
47 #include <mach/clk.h>
48 #include <mach/iomap.h>
49 #include <mach/irqs.h>
50 #include <mach/pinmux.h>
51 #include <mach/pinmux-tegra30.h>
52 #include <mach/iomap.h>
53 #include <mach/io.h>
54 #include <mach/io_dpd.h>
55 #include <mach/i2s.h>
56 #include <mach/tegra_asoc_pdata.h>
57 #include <asm/mach-types.h>
58 #include <asm/mach/arch.h>
59 #include <mach/usb_phy.h>
60 #include <mach/gpio-tegra.h>
61 #include <mach/tegra_fiq_debugger.h>
62 #include <mach/edp.h>
63
64 #include "board.h"
65 #include "board-common.h"
66 #include "clock.h"
67 #include "board-roth.h"
68 #include "devices.h"
69 #include "gpio-names.h"
70 #include "fuse.h"
71 #include "pm.h"
72 #include "common.h"
73 #include "tegra-board-id.h"
74
75 static struct rfkill_gpio_platform_data roth_bt_rfkill_pdata = {
76                 .name           = "bt_rfkill",
77                 .shutdown_gpio  = TEGRA_GPIO_PQ7,
78                 .type           = RFKILL_TYPE_BLUETOOTH,
79 };
80
81 static struct platform_device roth_bt_rfkill_device = {
82         .name = "rfkill_gpio",
83         .id             = -1,
84         .dev = {
85                 .platform_data = &roth_bt_rfkill_pdata,
86         },
87 };
88
89 static struct resource roth_bluesleep_resources[] = {
90         [0] = {
91                 .name = "gpio_host_wake",
92                         .start  = TEGRA_GPIO_PU6,
93                         .end    = TEGRA_GPIO_PU6,
94                         .flags  = IORESOURCE_IO,
95         },
96         [1] = {
97                 .name = "gpio_ext_wake",
98                         .start  = TEGRA_GPIO_PEE1,
99                         .end    = TEGRA_GPIO_PEE1,
100                         .flags  = IORESOURCE_IO,
101         },
102         [2] = {
103                 .name = "host_wake",
104                         .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
105         },
106 };
107
108 static struct platform_device roth_bluesleep_device = {
109         .name           = "bluesleep",
110         .id             = -1,
111         .num_resources  = ARRAY_SIZE(roth_bluesleep_resources),
112         .resource       = roth_bluesleep_resources,
113 };
114
115 static noinline void __init roth_setup_bt_rfkill(void)
116 {
117                 roth_bt_rfkill_pdata.reset_gpio = TEGRA_GPIO_PQ6;
118         platform_device_register(&roth_bt_rfkill_device);
119 }
120
121 static noinline void __init roth_setup_bluesleep(void)
122 {
123         roth_bluesleep_resources[2].start =
124                 roth_bluesleep_resources[2].end =
125                         gpio_to_irq(TEGRA_GPIO_PU6);
126         platform_device_register(&roth_bluesleep_device);
127         return;
128 }
129 static __initdata struct tegra_clk_init_table roth_clk_init_table[] = {
130         /* name         parent          rate            enabled */
131         { "pll_m",      NULL,           0,              false},
132         { "hda",        "pll_p",        108000000,      false},
133         { "hda2codec_2x", "pll_p",      48000000,       false},
134         { "pwm",        "pll_p",        3187500,        false},
135         { "blink",      "clk_32k",      32768,          true},
136         { "i2s1",       "pll_a_out0",   0,              false},
137         { "i2s3",       "pll_a_out0",   0,              false},
138         { "i2s4",       "pll_a_out0",   0,              false},
139         { "spdif_out",  "pll_a_out0",   0,              false},
140         { "d_audio",    "clk_m",        12000000,       false},
141         { "dam0",       "clk_m",        12000000,       false},
142         { "dam1",       "clk_m",        12000000,       false},
143         { "dam2",       "clk_m",        12000000,       false},
144         { "audio1",     "i2s1_sync",    0,              false},
145         { "audio3",     "i2s3_sync",    0,              false},
146         /* Setting vi_sensor-clk to true for validation purpose, will imapact
147          * power, later set to be false.*/
148         { "vi_sensor",  "pll_p",        150000000,      false},
149         { "cilab",      "pll_p",        150000000,      false},
150         { "cilcd",      "pll_p",        150000000,      false},
151         { "cile",       "pll_p",        150000000,      false},
152         { "i2c1",       "pll_p",        3200000,        false},
153         { "i2c2",       "pll_p",        3200000,        false},
154         { "i2c3",       "pll_p",        3200000,        false},
155         { "i2c4",       "pll_p",        3200000,        false},
156         { "i2c5",       "pll_p",        3200000,        false},
157         { NULL,         NULL,           0,              0},
158 };
159
160 static struct tegra_i2c_platform_data roth_i2c1_platform_data = {
161         .adapter_nr     = 0,
162         .bus_count      = 1,
163         .bus_clk_rate   = { 100000, 0 },
164         .scl_gpio               = {TEGRA_GPIO_I2C1_SCL, 0},
165         .sda_gpio               = {TEGRA_GPIO_I2C1_SDA, 0},
166         .arb_recovery = arb_lost_recovery,
167 };
168
169 static struct tegra_i2c_platform_data roth_i2c2_platform_data = {
170         .adapter_nr     = 1,
171         .bus_count      = 1,
172         .bus_clk_rate   = { 100000, 0 },
173         .is_clkon_always = true,
174         .scl_gpio               = {TEGRA_GPIO_I2C2_SCL, 0},
175         .sda_gpio               = {TEGRA_GPIO_I2C2_SDA, 0},
176         .arb_recovery = arb_lost_recovery,
177 };
178
179 static struct tegra_i2c_platform_data roth_i2c3_platform_data = {
180         .adapter_nr     = 2,
181         .bus_count      = 1,
182         .bus_clk_rate   = { 100000, 0 },
183         .scl_gpio               = {TEGRA_GPIO_I2C3_SCL, 0},
184         .sda_gpio               = {TEGRA_GPIO_I2C3_SDA, 0},
185         .arb_recovery = arb_lost_recovery,
186 };
187
188 static struct tegra_i2c_platform_data roth_i2c4_platform_data = {
189         .adapter_nr     = 3,
190         .bus_count      = 1,
191         .bus_clk_rate   = { 10000, 0 },
192         .scl_gpio               = {TEGRA_GPIO_I2C4_SCL, 0},
193         .sda_gpio               = {TEGRA_GPIO_I2C4_SDA, 0},
194         .arb_recovery = arb_lost_recovery,
195 };
196
197 static struct tegra_i2c_platform_data roth_i2c5_platform_data = {
198         .adapter_nr     = 4,
199         .bus_count      = 1,
200         .bus_clk_rate   = { 400000, 0 },
201         .scl_gpio               = {TEGRA_GPIO_I2C5_SCL, 0},
202         .sda_gpio               = {TEGRA_GPIO_I2C5_SDA, 0},
203         .arb_recovery = arb_lost_recovery,
204 };
205
206 #if defined(CONFIG_ARCH_TEGRA_11x_SOC)
207 static struct i2c_board_info __initdata rt5640_board_info = {
208         I2C_BOARD_INFO("rt5640", 0x1c),
209 };
210 #endif
211
212 static void roth_i2c_init(void)
213 {
214         tegra11_i2c_device1.dev.platform_data = &roth_i2c1_platform_data;
215         tegra11_i2c_device2.dev.platform_data = &roth_i2c2_platform_data;
216         tegra11_i2c_device3.dev.platform_data = &roth_i2c3_platform_data;
217         tegra11_i2c_device4.dev.platform_data = &roth_i2c4_platform_data;
218         tegra11_i2c_device5.dev.platform_data = &roth_i2c5_platform_data;
219
220         platform_device_register(&tegra11_i2c_device5);
221         platform_device_register(&tegra11_i2c_device4);
222         platform_device_register(&tegra11_i2c_device3);
223         platform_device_register(&tegra11_i2c_device2);
224         platform_device_register(&tegra11_i2c_device1);
225
226         i2c_register_board_info(0, &rt5640_board_info, 1);
227 }
228
229 static struct platform_device *roth_uart_devices[] __initdata = {
230         &tegra_uarta_device,
231         &tegra_uartb_device,
232         &tegra_uartc_device,
233         &tegra_uartd_device,
234 };
235 static struct uart_clk_parent uart_parent_clk[] = {
236         [0] = {.name = "clk_m"},
237         [1] = {.name = "pll_p"},
238 #ifndef CONFIG_TEGRA_PLLM_RESTRICTED
239         [2] = {.name = "pll_m"},
240 #endif
241 };
242
243 static struct tegra_uart_platform_data roth_uart_pdata;
244 static struct tegra_uart_platform_data roth_loopback_uart_pdata;
245
246 static void __init uart_debug_init(void)
247 {
248         int debug_port_id;
249
250         debug_port_id = uart_console_debug_init(3);
251         if (debug_port_id < 0)
252                 return;
253
254         roth_uart_devices[debug_port_id] = uart_console_debug_device;
255 }
256
257 static void __init roth_uart_init(void)
258 {
259         struct clk *c;
260         int i;
261
262         for (i = 0; i < ARRAY_SIZE(uart_parent_clk); ++i) {
263                 c = tegra_get_clock_by_name(uart_parent_clk[i].name);
264                 if (IS_ERR_OR_NULL(c)) {
265                         pr_err("Not able to get the clock for %s\n",
266                                                 uart_parent_clk[i].name);
267                         continue;
268                 }
269                 uart_parent_clk[i].parent_clk = c;
270                 uart_parent_clk[i].fixed_clk_rate = clk_get_rate(c);
271         }
272         roth_uart_pdata.parent_clk_list = uart_parent_clk;
273         roth_uart_pdata.parent_clk_count = ARRAY_SIZE(uart_parent_clk);
274         roth_loopback_uart_pdata.parent_clk_list = uart_parent_clk;
275         roth_loopback_uart_pdata.parent_clk_count =
276                                                 ARRAY_SIZE(uart_parent_clk);
277         roth_loopback_uart_pdata.is_loopback = true;
278         tegra_uarta_device.dev.platform_data = &roth_uart_pdata;
279         tegra_uartb_device.dev.platform_data = &roth_uart_pdata;
280         tegra_uartc_device.dev.platform_data = &roth_uart_pdata;
281         tegra_uartd_device.dev.platform_data = &roth_uart_pdata;
282
283         /* Register low speed only if it is selected */
284         if (!is_tegra_debug_uartport_hs())
285                 uart_debug_init();
286
287         platform_add_devices(roth_uart_devices,
288                                 ARRAY_SIZE(roth_uart_devices));
289 }
290
291 static struct resource tegra_rtc_resources[] = {
292         [0] = {
293                 .start = TEGRA_RTC_BASE,
294                 .end = TEGRA_RTC_BASE + TEGRA_RTC_SIZE - 1,
295                 .flags = IORESOURCE_MEM,
296         },
297         [1] = {
298                 .start = INT_RTC,
299                 .end = INT_RTC,
300                 .flags = IORESOURCE_IRQ,
301         },
302 };
303
304 static struct platform_device tegra_rtc_device = {
305         .name = "tegra_rtc",
306         .id   = -1,
307         .resource = tegra_rtc_resources,
308         .num_resources = ARRAY_SIZE(tegra_rtc_resources),
309 };
310
311 static struct tegra_asoc_platform_data roth_audio_pdata = {
312         .gpio_spkr_en           = TEGRA_GPIO_SPKR_EN,
313         .gpio_hp_det            = TEGRA_GPIO_HP_DET,
314         .gpio_hp_mute           = -1,
315         .gpio_int_mic_en        = TEGRA_GPIO_INT_MIC_EN,
316         .gpio_ext_mic_en        = TEGRA_GPIO_EXT_MIC_EN,
317         .gpio_ldo1_en           = TEGRA_GPIO_LDO1_EN,
318         .gpio_codec1 = TEGRA_GPIO_CODEC1_EN,
319         .gpio_codec2 = TEGRA_GPIO_CODEC2_EN,
320         .gpio_codec3 = TEGRA_GPIO_CODEC3_EN,
321         .i2s_param[HIFI_CODEC]  = {
322                 .audio_port_id  = 1,
323                 .is_i2s_master  = 1,
324                 .i2s_mode       = TEGRA_DAIFMT_I2S,
325         },
326         .i2s_param[BT_SCO]      = {
327                 .audio_port_id  = 3,
328                 .is_i2s_master  = 1,
329                 .i2s_mode       = TEGRA_DAIFMT_DSP_A,
330         },
331 };
332
333 static struct platform_device roth_audio_device = {
334         .name   = "tegra-snd-rt5640",
335         .id     = 0,
336         .dev    = {
337                 .platform_data = &roth_audio_pdata,
338         },
339 };
340
341 static struct platform_device tegra_camera = {
342         .name = "tegra_camera",
343         .id = -1,
344 };
345
346 static struct platform_device *roth_devices[] __initdata = {
347         &tegra_pmu_device,
348         &tegra_rtc_device,
349         &tegra_udc_device,
350 #if defined(CONFIG_TEGRA_IOVMM_SMMU) || defined(CONFIG_TEGRA_IOMMU_SMMU)
351         &tegra_smmu_device,
352 #endif
353 #if defined(CONFIG_TEGRA_AVP)
354         &tegra_avp_device,
355 #endif
356         &tegra_camera,
357 #if defined(CONFIG_CRYPTO_DEV_TEGRA_SE)
358         &tegra11_se_device,
359 #endif
360         &tegra_ahub_device,
361         &tegra_dam_device0,
362         &tegra_dam_device1,
363         &tegra_dam_device2,
364         &tegra_i2s_device1,
365         &tegra_i2s_device3,
366         &tegra_i2s_device4,
367         &tegra_spdif_device,
368         &spdif_dit_device,
369         &bluetooth_dit_device,
370         &roth_audio_device,
371         &tegra_hda_device,
372 #if defined(CONFIG_CRYPTO_DEV_TEGRA_AES)
373         &tegra_aes_device,
374 #endif
375 };
376
377 #ifdef CONFIG_USB_SUPPORT
378 static struct tegra_usb_platform_data tegra_udc_pdata = {
379         .port_otg = true,
380         .has_hostpc = true,
381         .phy_intf = TEGRA_USB_PHY_INTF_UTMI,
382         .op_mode = TEGRA_USB_OPMODE_DEVICE,
383         .u_data.dev = {
384                 .vbus_pmu_irq = 0,
385                 .vbus_gpio = -1,
386                 .charging_supported = false,
387                 .remote_wakeup_supported = false,
388         },
389         .u_cfg.utmi = {
390                 .hssync_start_delay = 0,
391                 .elastic_limit = 16,
392                 .idle_wait_delay = 17,
393                 .term_range_adj = 6,
394                 .xcvr_setup = 8,
395                 .xcvr_lsfslew = 2,
396                 .xcvr_lsrslew = 2,
397                 .xcvr_setup_offset = 0,
398                 .xcvr_use_fuses = 1,
399         },
400 };
401
402 static struct tegra_usb_platform_data tegra_ehci1_utmi_pdata = {
403         .port_otg = true,
404         .has_hostpc = true,
405         .unaligned_dma_buf_supported = false,
406         .phy_intf = TEGRA_USB_PHY_INTF_UTMI,
407         .op_mode = TEGRA_USB_OPMODE_HOST,
408         .u_data.host = {
409                 .vbus_gpio = -1,
410                 .hot_plug = true,
411                 .remote_wakeup_supported = true,
412                 .power_off_on_suspend = false,
413         },
414         .u_cfg.utmi = {
415                 .hssync_start_delay = 0,
416                 .elastic_limit = 16,
417                 .idle_wait_delay = 17,
418                 .term_range_adj = 6,
419                 .xcvr_setup = 15,
420                 .xcvr_lsfslew = 2,
421                 .xcvr_lsrslew = 2,
422                 .xcvr_setup_offset = 0,
423                 .xcvr_use_fuses = 1,
424         },
425 };
426
427 static struct tegra_usb_platform_data tegra_ehci3_utmi_pdata = {
428         .port_otg = false,
429         .has_hostpc = true,
430         .unaligned_dma_buf_supported = false,
431         .phy_intf = TEGRA_USB_PHY_INTF_UTMI,
432         .op_mode = TEGRA_USB_OPMODE_HOST,
433         .u_data.host = {
434                 .vbus_gpio = -1,
435                 .hot_plug = true,
436                 .remote_wakeup_supported = true,
437                 .power_off_on_suspend = false,
438         },
439         .u_cfg.utmi = {
440         .hssync_start_delay = 0,
441                 .elastic_limit = 16,
442                 .idle_wait_delay = 17,
443                 .term_range_adj = 6,
444                 .xcvr_setup = 8,
445                 .xcvr_lsfslew = 2,
446                 .xcvr_lsrslew = 2,
447                 .xcvr_setup_offset = 0,
448                 .xcvr_use_fuses = 1,
449         },
450 };
451
452 static struct tegra_usb_otg_data tegra_otg_pdata = {
453         .ehci_device = &tegra_ehci1_device,
454         .ehci_pdata = &tegra_ehci1_utmi_pdata,
455 };
456
457 static void roth_usb_init(void)
458 {
459         tegra_otg_device.dev.platform_data = &tegra_otg_pdata;
460         platform_device_register(&tegra_otg_device);
461
462         /* Setup the udc platform data */
463         tegra_udc_device.dev.platform_data = &tegra_udc_pdata;
464
465         tegra_ehci3_device.dev.platform_data = &tegra_ehci3_utmi_pdata;
466         platform_device_register(&tegra_ehci3_device);
467 }
468
469 #else
470 static void roth_usb_init(void) { }
471 #endif
472
473 static void roth_audio_init(void)
474 {
475         struct board_info board_info;
476
477         tegra_get_board_info(&board_info);
478
479         roth_audio_pdata.codec_name = "rt5640.0-001c";
480         roth_audio_pdata.codec_dai_name = "rt5640-aif1";
481 }
482
483
484 static void __init tegra_roth_init(void)
485 {
486
487         tegra_battery_edp_init(2500);
488         tegra_clk_init_from_table(roth_clk_init_table);
489         tegra_soc_device_init("roth");
490         tegra_enable_pinmux();
491         roth_pinmux_init();
492         roth_i2c_init();
493         roth_usb_init();
494         roth_uart_init();
495         roth_audio_init();
496         platform_add_devices(roth_devices, ARRAY_SIZE(roth_devices));
497         //tegra_ram_console_debug_init();
498         tegra_io_dpd_init();
499         roth_regulator_init();
500         roth_sdhci_init();
501         roth_suspend_init();
502         roth_emc_init();
503         roth_edp_init();
504         roth_panel_init();
505         roth_kbc_init();
506         roth_setup_bluesleep();
507         roth_setup_bt_rfkill();
508         tegra_release_bootloader_fb();
509 #ifdef CONFIG_TEGRA_WDT_RECOVERY
510         tegra_wdt_recovery_init();
511 #endif
512         tegra_serial_debug_init(TEGRA_UARTD_BASE, INT_WDT_CPU, NULL, -1, -1);
513         roth_sensors_init();
514         roth_soctherm_init();
515 }
516
517 static void __init roth_ramconsole_reserve(unsigned long size)
518 {
519         tegra_ram_console_debug_reserve(SZ_1M);
520 }
521
522 static void __init tegra_roth_dt_init(void)
523 {
524         tegra_roth_init();
525
526 #ifdef CONFIG_USE_OF
527         of_platform_populate(NULL,
528                 of_default_bus_match_table, NULL, NULL);
529 #endif
530 }
531
532 static void __init tegra_roth_reserve(void)
533 {
534 #if defined(CONFIG_NVMAP_CONVERT_CARVEOUT_TO_IOVMM)
535         /* 1920*1200*4*2 = 18432000 bytes */
536         tegra_reserve(0, SZ_16M + SZ_2M, SZ_4M);
537 #else
538         tegra_reserve(SZ_128M, SZ_16M + SZ_2M, SZ_4M);
539 #endif
540         roth_ramconsole_reserve(SZ_1M);
541 }
542
543 static const char * const roth_dt_board_compat[] = {
544         "nvidia,roth",
545         NULL
546 };
547
548 MACHINE_START(ROTH, "roth")
549         .atag_offset    = 0x100,
550         .smp            = smp_ops(tegra_smp_ops),
551         .map_io         = tegra_map_common_io,
552         .reserve        = tegra_roth_reserve,
553         .init_early     = tegra11x_init_early,
554         .init_irq       = tegra_init_irq,
555         .handle_irq     = gic_handle_irq,
556         .timer          = &tegra_timer,
557         .init_machine   = tegra_roth_dt_init,
558         .restart        = tegra_assert_system_reset,
559         .dt_compat      = roth_dt_board_compat,
560 MACHINE_END