ARM: tegra: restructuring battery EDP init code
[linux-3.10.git] / arch / arm / mach-tegra / board-pluto.c
1 /*
2  * arch/arm/mach-tegra/board-pluto.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/spi/spi.h>
35 #include <linux/spi/rm31080a_ts.h>
36 #include <linux/tegra_uart.h>
37 #include <linux/memblock.h>
38 #include <linux/spi-tegra.h>
39 #include <linux/nfc/pn544.h>
40 #include <linux/rfkill-gpio.h>
41 #include <linux/skbuff.h>
42 #include <linux/ti_wilink_st.h>
43 #include <linux/regulator/consumer.h>
44 #include <linux/smb349-charger.h>
45 #include <linux/max17048_battery.h>
46 #include <linux/leds.h>
47 #include <linux/i2c/at24.h>
48 #include <linux/mfd/max8831.h>
49 #include <linux/of_platform.h>
50 #include <linux/a2220.h>
51 #include <linux/edp.h>
52
53 #include <asm/hardware/gic.h>
54
55 #include <mach/clk.h>
56 #include <mach/iomap.h>
57 #include <mach/irqs.h>
58 #include <mach/pinmux.h>
59 #include <mach/pinmux-t11.h>
60 #include <mach/iomap.h>
61 #include <mach/io.h>
62 #include <mach/io_dpd.h>
63 #include <mach/i2s.h>
64 #include <mach/tegra_asoc_pdata.h>
65 #include <asm/mach-types.h>
66 #include <asm/mach/arch.h>
67 #include <mach/usb_phy.h>
68 #include <mach/gpio-tegra.h>
69 #include <mach/tegra_fiq_debugger.h>
70 #include <mach/tegra-bb-power.h>
71 #include <mach/tegra_usb_modem_power.h>
72
73 #include "board.h"
74 #include "board-common.h"
75 #include "board-touch-raydium.h"
76 #include "clock.h"
77 #include "board-pluto.h"
78 #include "tegra-board-id.h"
79 #include "devices.h"
80 #include "gpio-names.h"
81 #include "fuse.h"
82 #include "pm.h"
83 #include "common.h"
84
85 #ifdef CONFIG_BT_BLUESLEEP
86 static struct rfkill_gpio_platform_data pluto_bt_rfkill_pdata = {
87         .name           = "bt_rfkill",
88         .shutdown_gpio  = TEGRA_GPIO_PQ7,
89         .reset_gpio     = TEGRA_GPIO_PQ6,
90         .type           = RFKILL_TYPE_BLUETOOTH,
91 };
92
93 static struct platform_device pluto_bt_rfkill_device = {
94         .name = "rfkill_gpio",
95         .id             = -1,
96         .dev = {
97                 .platform_data = &pluto_bt_rfkill_pdata,
98         },
99 };
100
101 static noinline void __init pluto_setup_bt_rfkill(void)
102 {
103         platform_device_register(&pluto_bt_rfkill_device);
104 }
105
106 static struct resource pluto_bluesleep_resources[] = {
107         [0] = {
108                 .name = "gpio_host_wake",
109                         .start  = TEGRA_GPIO_PU6,
110                         .end    = TEGRA_GPIO_PU6,
111                         .flags  = IORESOURCE_IO,
112         },
113         [1] = {
114                 .name = "gpio_ext_wake",
115                         .start  = TEGRA_GPIO_PEE1,
116                         .end    = TEGRA_GPIO_PEE1,
117                         .flags  = IORESOURCE_IO,
118         },
119         [2] = {
120                 .name = "host_wake",
121                         .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
122         },
123 };
124
125 static struct platform_device pluto_bluesleep_device = {
126         .name           = "bluesleep",
127         .id             = -1,
128         .num_resources  = ARRAY_SIZE(pluto_bluesleep_resources),
129         .resource       = pluto_bluesleep_resources,
130 };
131
132 static noinline void __init pluto_setup_bluesleep(void)
133 {
134         pluto_bluesleep_resources[2].start =
135                 pluto_bluesleep_resources[2].end =
136                         gpio_to_irq(TEGRA_GPIO_PU6);
137         platform_device_register(&pluto_bluesleep_device);
138         return;
139 }
140 #elif defined CONFIG_BLUEDROID_PM
141 static struct resource pluto_bluedroid_pm_resources[] = {
142         [0] = {
143                 .name   = "shutdown_gpio",
144                 .start  = TEGRA_GPIO_PQ7,
145                 .end    = TEGRA_GPIO_PQ7,
146                 .flags  = IORESOURCE_IO,
147         },
148         [1] = {
149                 .name = "host_wake",
150                 .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
151         },
152         [2] = {
153                 .name = "gpio_ext_wake",
154                 .start  = TEGRA_GPIO_PEE1,
155                 .end    = TEGRA_GPIO_PEE1,
156                 .flags  = IORESOURCE_IO,
157         },
158         [3] = {
159                 .name = "gpio_host_wake",
160                 .start  = TEGRA_GPIO_PU6,
161                 .end    = TEGRA_GPIO_PU6,
162                 .flags  = IORESOURCE_IO,
163         },
164         [4] = {
165                 .name = "reset_gpio",
166                 .start  = TEGRA_GPIO_PQ6,
167                 .end    = TEGRA_GPIO_PQ6,
168                 .flags  = IORESOURCE_IO,
169         },
170 };
171
172 static struct platform_device pluto_bluedroid_pm_device = {
173         .name = "bluedroid_pm",
174         .id             = 0,
175         .num_resources  = ARRAY_SIZE(pluto_bluedroid_pm_resources),
176         .resource       = pluto_bluedroid_pm_resources,
177 };
178
179 static noinline void __init pluto_setup_bluedroid_pm(void)
180 {
181         pluto_bluedroid_pm_resources[1].start =
182                 pluto_bluedroid_pm_resources[1].end =
183                                         gpio_to_irq(TEGRA_GPIO_PU6);
184         platform_device_register(&pluto_bluedroid_pm_device);
185 }
186 #endif
187
188 static __initdata struct tegra_clk_init_table pluto_clk_init_table[] = {
189         /* name         parent          rate            enabled */
190         { "pll_m",      NULL,           0,              false},
191         { "hda",        "pll_p",        108000000,      false},
192         { "hda2codec_2x", "pll_p",      48000000,       false},
193         { "pwm",        "pll_p",        3187500,        false},
194         { "i2s1",       "pll_a_out0",   0,              false},
195         { "i2s2",       "pll_a_out0",   0,              false},
196         { "i2s3",       "pll_a_out0",   0,              false},
197         { "i2s4",       "pll_a_out0",   0,              false},
198         { "spdif_out",  "pll_a_out0",   0,              false},
199         { "d_audio",    "clk_m",        12000000,       false},
200         { "dam0",       "clk_m",        12000000,       false},
201         { "dam1",       "clk_m",        12000000,       false},
202         { "dam2",       "clk_m",        12000000,       false},
203         { "audio0",     "i2s0_sync",    0,              false},
204         { "audio1",     "i2s1_sync",    0,              false},
205         { "audio2",     "i2s2_sync",    0,              false},
206         { "audio3",     "i2s3_sync",    0,              false},
207         { "audio4",     "i2s4_sync",    0,              false},
208         { "vi_sensor",  "pll_p",        150000000,      false},
209         { "cilab",      "pll_p",        150000000,      false},
210         { "cilcd",      "pll_p",        150000000,      false},
211         { "cile",       "pll_p",        150000000,      false},
212         { "i2c1",       "pll_p",        3200000,        false},
213         { "i2c2",       "pll_p",        3200000,        false},
214         { "i2c3",       "pll_p",        3200000,        false},
215         { "i2c4",       "pll_p",        3200000,        false},
216         { "i2c5",       "pll_p",        3200000,        false},
217         { "extern3",    "clk_m",        12000000,       false},
218         { NULL,         NULL,           0,              0},
219 };
220
221 static struct tegra_i2c_platform_data pluto_i2c1_platform_data = {
222         .adapter_nr     = 0,
223         .bus_count      = 1,
224         .bus_clk_rate   = { 100000, 0 },
225         .scl_gpio               = {TEGRA_GPIO_I2C1_SCL, 0},
226         .sda_gpio               = {TEGRA_GPIO_I2C1_SDA, 0},
227         .arb_recovery = arb_lost_recovery,
228 };
229
230 static struct tegra_i2c_platform_data pluto_i2c2_platform_data = {
231         .adapter_nr     = 1,
232         .bus_count      = 1,
233         .bus_clk_rate   = { 100000, 0 },
234         .is_clkon_always = true,
235         .scl_gpio               = {TEGRA_GPIO_I2C2_SCL, 0},
236         .sda_gpio               = {TEGRA_GPIO_I2C2_SDA, 0},
237         .arb_recovery = arb_lost_recovery,
238 };
239
240 static struct tegra_i2c_platform_data pluto_i2c3_platform_data = {
241         .adapter_nr     = 2,
242         .bus_count      = 1,
243         .bus_clk_rate   = { 100000, 0 },
244         .scl_gpio               = {TEGRA_GPIO_I2C3_SCL, 0},
245         .sda_gpio               = {TEGRA_GPIO_I2C3_SDA, 0},
246         .arb_recovery = arb_lost_recovery,
247 };
248
249 static struct tegra_i2c_platform_data pluto_i2c4_platform_data = {
250         .adapter_nr     = 3,
251         .bus_count      = 1,
252         .bus_clk_rate   = { 10000, 0 },
253         .scl_gpio               = {TEGRA_GPIO_I2C4_SCL, 0},
254         .sda_gpio               = {TEGRA_GPIO_I2C4_SDA, 0},
255         .arb_recovery = arb_lost_recovery,
256 };
257
258 static struct tegra_i2c_platform_data pluto_i2c5_platform_data = {
259         .adapter_nr     = 4,
260         .bus_count      = 1,
261         .bus_clk_rate   = { 400000, 0 },
262         .scl_gpio               = {TEGRA_GPIO_I2C5_SCL, 0},
263         .sda_gpio               = {TEGRA_GPIO_I2C5_SDA, 0},
264         .arb_recovery = arb_lost_recovery,
265 };
266
267 static struct i2c_board_info __initdata cs42l73_board_info = {
268         I2C_BOARD_INFO("cs42l73", 0x4a),
269 };
270
271 static struct i2c_board_info __initdata pluto_codec_a2220_info = {
272         I2C_BOARD_INFO("audience_a2220", 0x3E),
273 };
274
275
276 static void pluto_i2c_init(void)
277 {
278         struct board_info board_info;
279
280         tegra_get_board_info(&board_info);
281 #ifndef CONFIG_ARCH_TEGRA_11x_SOC
282         tegra_i2c_device1.dev.platform_data = &pluto_i2c1_platform_data;
283         tegra_i2c_device2.dev.platform_data = &pluto_i2c2_platform_data;
284         tegra_i2c_device3.dev.platform_data = &pluto_i2c3_platform_data;
285         tegra_i2c_device4.dev.platform_data = &pluto_i2c4_platform_data;
286         tegra_i2c_device5.dev.platform_data = &pluto_i2c5_platform_data;
287
288         i2c_register_board_info(1, &pluto_i2c_led_info, 1);
289
290         platform_device_register(&tegra_i2c_device5);
291         platform_device_register(&tegra_i2c_device4);
292         platform_device_register(&tegra_i2c_device3);
293         platform_device_register(&tegra_i2c_device2);
294         platform_device_register(&tegra_i2c_device1);
295
296 #else
297         tegra11_i2c_device1.dev.platform_data = &pluto_i2c1_platform_data;
298         tegra11_i2c_device2.dev.platform_data = &pluto_i2c2_platform_data;
299         tegra11_i2c_device3.dev.platform_data = &pluto_i2c3_platform_data;
300         tegra11_i2c_device4.dev.platform_data = &pluto_i2c4_platform_data;
301         tegra11_i2c_device5.dev.platform_data = &pluto_i2c5_platform_data;
302
303         platform_device_register(&tegra11_i2c_device5);
304         platform_device_register(&tegra11_i2c_device4);
305         platform_device_register(&tegra11_i2c_device3);
306         platform_device_register(&tegra11_i2c_device2);
307         platform_device_register(&tegra11_i2c_device1);
308
309 #endif
310
311         i2c_register_board_info(0, &pluto_codec_a2220_info, 1);
312         i2c_register_board_info(0, &cs42l73_board_info, 1);
313 }
314
315 static struct platform_device *pluto_uart_devices[] __initdata = {
316         &tegra_uarta_device,
317         &tegra_uartb_device,
318         &tegra_uartc_device,
319         &tegra_uartd_device,
320 };
321 static struct uart_clk_parent uart_parent_clk[] = {
322         [0] = {.name = "clk_m"},
323         [1] = {.name = "pll_p"},
324 #ifndef CONFIG_TEGRA_PLLM_RESTRICTED
325         [2] = {.name = "pll_m"},
326 #endif
327 };
328
329 static struct tegra_uart_platform_data pluto_uart_pdata;
330 static struct tegra_uart_platform_data pluto_loopback_uart_pdata;
331
332 static void __init uart_debug_init(void)
333 {
334         int debug_port_id;
335
336         debug_port_id = uart_console_debug_init(3);
337         if (debug_port_id < 0)
338                 return;
339         pluto_uart_devices[debug_port_id] = uart_console_debug_device;
340 }
341
342 static void __init pluto_uart_init(void)
343 {
344         struct clk *c;
345         int i;
346
347         for (i = 0; i < ARRAY_SIZE(uart_parent_clk); ++i) {
348                 c = tegra_get_clock_by_name(uart_parent_clk[i].name);
349                 if (IS_ERR_OR_NULL(c)) {
350                         pr_err("Not able to get the clock for %s\n",
351                                                 uart_parent_clk[i].name);
352                         continue;
353                 }
354                 uart_parent_clk[i].parent_clk = c;
355                 uart_parent_clk[i].fixed_clk_rate = clk_get_rate(c);
356         }
357         pluto_uart_pdata.parent_clk_list = uart_parent_clk;
358         pluto_uart_pdata.parent_clk_count = ARRAY_SIZE(uart_parent_clk);
359         pluto_loopback_uart_pdata.parent_clk_list = uart_parent_clk;
360         pluto_loopback_uart_pdata.parent_clk_count =
361                                                 ARRAY_SIZE(uart_parent_clk);
362         pluto_loopback_uart_pdata.is_loopback = true;
363         tegra_uarta_device.dev.platform_data = &pluto_uart_pdata;
364         tegra_uartb_device.dev.platform_data = &pluto_uart_pdata;
365         tegra_uartc_device.dev.platform_data = &pluto_uart_pdata;
366         tegra_uartd_device.dev.platform_data = &pluto_uart_pdata;
367
368         /* Register low speed only if it is selected */
369         if (!is_tegra_debug_uartport_hs())
370                 uart_debug_init();
371
372         platform_add_devices(pluto_uart_devices,
373                                 ARRAY_SIZE(pluto_uart_devices));
374 }
375
376 static struct resource tegra_rtc_resources[] = {
377         [0] = {
378                 .start = TEGRA_RTC_BASE,
379                 .end = TEGRA_RTC_BASE + TEGRA_RTC_SIZE - 1,
380                 .flags = IORESOURCE_MEM,
381         },
382         [1] = {
383                 .start = INT_RTC,
384                 .end = INT_RTC,
385                 .flags = IORESOURCE_IRQ,
386         },
387 };
388
389 static struct platform_device tegra_rtc_device = {
390         .name = "tegra_rtc",
391         .id   = -1,
392         .resource = tegra_rtc_resources,
393         .num_resources = ARRAY_SIZE(tegra_rtc_resources),
394 };
395
396 static struct tegra_asoc_platform_data pluto_audio_pdata = {
397         .gpio_spkr_en           = TEGRA_GPIO_SPKR_EN,
398         .gpio_hp_det            = TEGRA_GPIO_HP_DET,
399         .gpio_hp_mute           = -1,
400         .gpio_int_mic_en        = TEGRA_GPIO_INT_MIC_EN,
401         .gpio_ext_mic_en        = TEGRA_GPIO_EXT_MIC_EN,
402         .gpio_ldo1_en           = TEGRA_GPIO_LDO1_EN,
403         .i2s_param[HIFI_CODEC]  = {
404                 .audio_port_id  = 1,
405                 .is_i2s_master  = 0,
406                 .i2s_mode       = TEGRA_DAIFMT_I2S,
407                 .sample_size    = 16,
408                 .channels       = 2,
409         },
410         .i2s_param[BASEBAND]    = {
411                 .audio_port_id  = 2,
412                 .is_i2s_master  = 1,
413                 .i2s_mode       = TEGRA_DAIFMT_I2S,
414                 .sample_size    = 16,
415                 .rate           = 16000,
416                 .channels       = 2,
417         },
418         .i2s_param[BT_SCO]      = {
419                 .audio_port_id  = 3,
420                 .is_i2s_master  = 1,
421                 .i2s_mode       = TEGRA_DAIFMT_DSP_A,
422                 .sample_size    = 16,
423         },
424         .i2s_param[VOICE_CODEC] = {
425                 .audio_port_id  = 0,
426                 .is_i2s_master  = 1,
427                 .i2s_mode       = TEGRA_DAIFMT_I2S,
428                 .sample_size    = 16,
429                 .rate           = 16000,
430                 .channels       = 2,
431         },
432 };
433
434 static struct platform_device pluto_audio_device = {
435         .name   = "tegra-snd-cs42l73",
436         .id     = 2,
437         .dev    = {
438                 .platform_data = &pluto_audio_pdata,
439         },
440 };
441
442 static struct platform_device tegra_camera = {
443         .name = "tegra_camera",
444         .id = -1,
445 };
446
447 #ifdef CONFIG_MHI_NETDEV
448 struct platform_device mhi_netdevice0 = {
449         .name = "mhi_net_device",
450         .id = 0,
451 };
452 #endif /* CONFIG_MHI_NETDEV */
453
454 static struct platform_device *pluto_devices[] __initdata = {
455         &tegra_pmu_device,
456         &tegra_rtc_device,
457         &tegra_udc_device,
458 #if defined(CONFIG_TEGRA_IOVMM_SMMU) || defined(CONFIG_TEGRA_IOMMU_SMMU)
459         &tegra_smmu_device,
460 #endif
461 #if defined(CONFIG_TEGRA_AVP)
462         &tegra_avp_device,
463 #endif
464         &tegra_camera,
465 #if defined(CONFIG_CRYPTO_DEV_TEGRA_SE)
466         &tegra11_se_device,
467 #endif
468         &tegra_ahub_device,
469         &tegra_dam_device0,
470         &tegra_dam_device1,
471         &tegra_dam_device2,
472         &tegra_i2s_device0,
473         &tegra_i2s_device1,
474         &tegra_i2s_device2,
475         &tegra_i2s_device3,
476         &tegra_i2s_device4,
477         &tegra_spdif_device,
478         &spdif_dit_device,
479         &bluetooth_dit_device,
480         &baseband_dit_device,
481         &pluto_audio_device,
482         &tegra_hda_device,
483 #if defined(CONFIG_CRYPTO_DEV_TEGRA_AES)
484         &tegra_aes_device,
485 #endif
486 #ifdef CONFIG_MHI_NETDEV
487         &mhi_netdevice0,  /* MHI netdevice */
488 #endif /* CONFIG_MHI_NETDEV */
489 };
490
491 #ifdef CONFIG_USB_SUPPORT
492 static struct tegra_usb_platform_data tegra_ehci3_hsic_smsc_hub_pdata = {
493         .port_otg = false,
494         .has_hostpc = true,
495         .unaligned_dma_buf_supported = false,
496         .phy_intf = TEGRA_USB_PHY_INTF_HSIC,
497         .op_mode        = TEGRA_USB_OPMODE_HOST,
498         .u_data.host = {
499                 .vbus_gpio = -1,
500                 .hot_plug = false,
501                 .remote_wakeup_supported = true,
502                 .power_off_on_suspend = true,
503         },
504 };
505
506 static struct tegra_usb_platform_data tegra_udc_pdata = {
507         .port_otg = true,
508         .has_hostpc = true,
509         .builtin_host_disabled = true,
510         .phy_intf = TEGRA_USB_PHY_INTF_UTMI,
511         .op_mode = TEGRA_USB_OPMODE_DEVICE,
512         .u_data.dev = {
513                 .vbus_pmu_irq = 0,
514                 .vbus_gpio = -1,
515                 .charging_supported = false,
516                 .remote_wakeup_supported = false,
517         },
518         .u_cfg.utmi = {
519                 .hssync_start_delay = 0,
520                 .elastic_limit = 16,
521                 .idle_wait_delay = 17,
522                 .term_range_adj = 6,
523                 .xcvr_setup = 8,
524                 .xcvr_lsfslew = 2,
525                 .xcvr_lsrslew = 2,
526                 .xcvr_setup_offset = 0,
527                 .xcvr_use_fuses = 1,
528         },
529 };
530
531 static struct tegra_usb_platform_data tegra_ehci1_utmi_pdata = {
532         .port_otg = true,
533         .has_hostpc = true,
534         .builtin_host_disabled = true,
535         .unaligned_dma_buf_supported = false,
536         .phy_intf = TEGRA_USB_PHY_INTF_UTMI,
537         .op_mode = TEGRA_USB_OPMODE_HOST,
538         .u_data.host = {
539                 .vbus_gpio = -1,
540                 .hot_plug = false,
541                 .remote_wakeup_supported = true,
542                 .power_off_on_suspend = true,
543         },
544         .u_cfg.utmi = {
545                 .hssync_start_delay = 0,
546                 .elastic_limit = 16,
547                 .idle_wait_delay = 17,
548                 .term_range_adj = 6,
549                 .xcvr_setup = 15,
550                 .xcvr_lsfslew = 2,
551                 .xcvr_lsrslew = 2,
552                 .xcvr_setup_offset = 0,
553                 .xcvr_use_fuses = 1,
554         },
555 };
556
557 static struct tegra_usb_otg_data tegra_otg_pdata = {
558         .ehci_device = &tegra_ehci1_device,
559         .ehci_pdata = &tegra_ehci1_utmi_pdata,
560 };
561
562 static struct regulator *baseband_reg;
563 static struct gpio modem_gpios[] = { /* i500 modem */
564         {MDM_RST, GPIOF_OUT_INIT_LOW, "MODEM RESET"},
565 };
566
567 static struct gpio modem2_gpios[] = {
568         {MDM2_PWR_ON, GPIOF_OUT_INIT_LOW, "MODEM2 PWR ON"},
569         {MDM2_RST, GPIOF_DIR_OUT, "MODEM2 RESET"},
570         {MDM2_ACK2, GPIOF_OUT_INIT_HIGH, "MODEM2 ACK2"},
571         {MDM2_ACK1, GPIOF_OUT_INIT_LOW, "MODEM2 ACK1"},
572 };
573
574 static void baseband2_post_phy_on(void);
575 static void baseband2_pre_phy_off(void);
576
577 static struct tegra_usb_phy_platform_ops baseband2_plat_ops = {
578         .pre_phy_off = baseband2_pre_phy_off,
579         .post_phy_on = baseband2_post_phy_on,
580 };
581
582 static struct tegra_usb_platform_data tegra_ehci2_hsic_baseband_pdata = {
583         .port_otg = false,
584         .has_hostpc = true,
585         .unaligned_dma_buf_supported = false,
586         .phy_intf = TEGRA_USB_PHY_INTF_HSIC,
587         .op_mode = TEGRA_USB_OPMODE_HOST,
588         .u_data.host = {
589                 .vbus_gpio = -1,
590                 .hot_plug = false,
591                 .remote_wakeup_supported = false,
592                 .power_off_on_suspend = false,
593         },
594 };
595
596 #ifdef CONFIG_ARCH_TEGRA_11x_SOC
597 static struct tegra_usb_platform_data tegra_ehci3_hsic_baseband2_pdata = {
598 #else
599 static struct tegra_usb_platform_data tegra_ehci2_hsic_baseband2_pdata = {
600 #endif
601         .port_otg = false,
602         .has_hostpc = true,
603         .unaligned_dma_buf_supported = false,
604         .phy_intf = TEGRA_USB_PHY_INTF_HSIC,
605         .op_mode = TEGRA_USB_OPMODE_HOST,
606         .u_data.host = {
607                 .vbus_gpio = -1,
608                 .hot_plug = false,
609                 .remote_wakeup_supported = false,
610                 .power_off_on_suspend = false,
611         },
612         .ops = &baseband2_plat_ops,
613 };
614
615 #ifdef CONFIG_TEGRA_BB_OEM1
616 static struct tegra_usb_platform_data tegra_hsic_pdata = {
617         .port_otg = false,
618         .has_hostpc = true,
619         .unaligned_dma_buf_supported = false,
620         .phy_intf = TEGRA_USB_PHY_INTF_HSIC,
621         .op_mode        = TEGRA_USB_OPMODE_HOST,
622         .u_data.host = {
623                 .vbus_gpio = -1,
624                 .hot_plug = false,
625                 .remote_wakeup_supported = true,
626                 .power_off_on_suspend = true,
627         },
628 };
629
630 static struct platform_device *
631 tegra_usb_hsic_host_register(struct platform_device *ehci_dev)
632 {
633         struct platform_device *pdev;
634         int val;
635
636         pdev = platform_device_alloc(ehci_dev->name, ehci_dev->id);
637         if (!pdev)
638                 return NULL;
639
640         val = platform_device_add_resources(pdev, ehci_dev->resource,
641                                                 ehci_dev->num_resources);
642         if (val)
643                 goto error;
644
645         pdev->dev.dma_mask =  ehci_dev->dev.dma_mask;
646         pdev->dev.coherent_dma_mask = ehci_dev->dev.coherent_dma_mask;
647
648         val = platform_device_add_data(pdev, &tegra_hsic_pdata,
649                         sizeof(struct tegra_usb_platform_data));
650         if (val)
651                 goto error;
652
653         val = platform_device_add(pdev);
654         if (val)
655                 goto error;
656
657         return pdev;
658
659 error:
660         pr_err("%s: failed to add the host contoller device\n", __func__);
661         platform_device_put(pdev);
662         return NULL;
663 }
664
665 static void tegra_usb_hsic_host_unregister(struct platform_device **platdev)
666 {
667         struct platform_device *pdev = *platdev;
668
669         if (pdev && &pdev->dev) {
670                 platform_device_unregister(pdev);
671                 *platdev = NULL;
672         } else
673                 pr_err("%s: no platform device\n", __func__);
674 }
675
676 static struct tegra_usb_phy_platform_ops oem1_hsic_pops;
677
678 static union tegra_bb_gpio_id bb_gpio_oem1 = {
679         .oem1 = {
680                 .reset = BB_OEM1_GPIO_RST,
681                 .pwron = BB_OEM1_GPIO_ON,
682                 .awr = BB_OEM1_GPIO_AWR,
683                 .cwr = BB_OEM1_GPIO_CWR,
684                 .spare = BB_OEM1_GPIO_SPARE,
685                 .wdi = BB_OEM1_GPIO_WDI,
686         },
687 };
688
689 static struct tegra_bb_pdata bb_pdata_oem1 = {
690         .id = &bb_gpio_oem1,
691         .device = &tegra_ehci3_device,
692         .ehci_register = tegra_usb_hsic_host_register,
693         .ehci_unregister = tegra_usb_hsic_host_unregister,
694         .bb_id = TEGRA_BB_OEM1,
695 };
696
697 static struct platform_device tegra_bb_oem1 = {
698         .name = "tegra_baseband_power",
699         .id = -1,
700         .dev = {
701                 .platform_data = &bb_pdata_oem1,
702         },
703 };
704 #endif
705
706 static int baseband_init(void)
707 {
708         int ret;
709
710         ret = gpio_request_array(modem_gpios, ARRAY_SIZE(modem_gpios));
711         if (ret) {
712                 pr_warn("%s:gpio request failed\n", __func__);
713                 return ret;
714         }
715
716         baseband_reg = regulator_get(NULL, "vdd_core_bb");
717         if (IS_ERR_OR_NULL(baseband_reg))
718                 pr_warn("%s: baseband regulator get failed\n", __func__);
719         else
720                 regulator_enable(baseband_reg);
721
722         /* enable pull-down for MDM1_COLD_BOOT */
723         tegra_pinmux_set_pullupdown(TEGRA_PINGROUP_ULPI_DATA4,
724                                     TEGRA_PUPD_PULL_DOWN);
725
726         /* export GPIO for user space access through sysfs */
727         gpio_export(MDM_RST, false);
728
729         return 0;
730 }
731
732 static const struct tegra_modem_operations baseband_operations = {
733         .init = baseband_init,
734 };
735
736 static struct tegra_usb_modem_power_platform_data baseband_pdata = {
737         .ops = &baseband_operations,
738         .wake_gpio = -1,
739         .boot_gpio = MDM_COLDBOOT,
740         .boot_irq_flags = IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
741         .autosuspend_delay = 2000,
742         .short_autosuspend_delay = 50,
743         .tegra_ehci_device = &tegra_ehci2_device,
744         .tegra_ehci_pdata = &tegra_ehci2_hsic_baseband_pdata,
745 };
746
747 static struct platform_device icera_baseband_device = {
748         .name = "tegra_usb_modem_power",
749         .id = -1,
750         .dev = {
751                 .platform_data = &baseband_pdata,
752         },
753 };
754
755 static void baseband2_post_phy_on(void)
756 {
757         /* set MDM2_ACK2 low */
758         gpio_set_value(MDM2_ACK2, 0);
759 }
760
761 static void baseband2_pre_phy_off(void)
762 {
763         /* set MDM2_ACK2 high */
764         gpio_set_value(MDM2_ACK2, 1);
765 }
766
767 static void baseband2_start(void)
768 {
769         /*
770          *  Leave baseband powered OFF.
771          *  User-space daemons will take care of powering it up.
772          */
773         pr_info("%s\n", __func__);
774         gpio_set_value(MDM2_PWR_ON, 0);
775 }
776
777 static void baseband2_reset(void)
778 {
779         /* Initiate power cycle on baseband sub system */
780         pr_info("%s\n", __func__);
781         gpio_set_value(MDM2_PWR_ON, 0);
782         mdelay(200);
783         gpio_set_value(MDM2_PWR_ON, 1);
784 }
785
786 static int baseband2_init(void)
787 {
788         int ret;
789
790         ret = gpio_request_array(modem2_gpios, ARRAY_SIZE(modem2_gpios));
791         if (ret)
792                 return ret;
793
794         /* enable pull-up for MDM2_REQ2 */
795         tegra_pinmux_set_pullupdown(TEGRA_PINGROUP_GPIO_PV1,
796                                     TEGRA_PUPD_PULL_UP);
797
798         /* export GPIO for user space access through sysfs */
799         gpio_export(MDM2_PWR_ON, false);
800
801         return 0;
802 }
803
804 static const struct tegra_modem_operations baseband2_operations = {
805         .init = baseband2_init,
806         .start = baseband2_start,
807         .reset = baseband2_reset,
808 };
809
810 static struct tegra_usb_modem_power_platform_data baseband2_pdata = {
811         .ops = &baseband2_operations,
812         .wake_gpio = MDM2_REQ2,
813         .wake_irq_flags = IRQF_TRIGGER_FALLING,
814         .boot_gpio = MDM2_COLDBOOT,
815         .boot_irq_flags = IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
816         .autosuspend_delay = 2000,
817         .short_autosuspend_delay = 50,
818 #ifdef CONFIG_ARCH_TEGRA_11x_SOC
819         .tegra_ehci_device = &tegra_ehci3_device,
820         .tegra_ehci_pdata = &tegra_ehci3_hsic_baseband2_pdata,
821 #else
822         .tegra_ehci_device = &tegra_ehci2_device,
823         .tegra_ehci_pdata = &tegra_ehci2_hsic_baseband2_pdata,
824 #endif
825 };
826
827 static struct platform_device icera_baseband2_device = {
828         .name = "tegra_usb_modem_power",
829         .id = -1,
830         .dev = {
831                 .platform_data = &baseband2_pdata,
832         },
833 };
834
835 static void pluto_usb_init(void)
836 {
837         int modem_id = tegra_get_modem_id();
838
839         tegra_otg_device.dev.platform_data = &tegra_otg_pdata;
840         platform_device_register(&tegra_otg_device);
841
842         /* Setup the udc platform data */
843         tegra_udc_device.dev.platform_data = &tegra_udc_pdata;
844
845         if (!modem_id) {
846                 tegra_ehci3_device.dev.platform_data =
847                         &tegra_ehci3_hsic_smsc_hub_pdata;
848                 platform_device_register(&tegra_ehci3_device);
849         }
850 }
851
852 static void pluto_modem_init(void)
853 {
854         int modem_id = tegra_get_modem_id();
855         struct board_info board_info;
856
857         tegra_get_board_info(&board_info);
858         pr_info("%s: modem_id = %d\n", __func__, modem_id);
859
860         switch (modem_id) {
861         case TEGRA_BB_I500: /* on board i500 HSIC */
862                 platform_device_register(&icera_baseband_device);
863                 break;
864         case TEGRA_BB_I500SWD: /* i500 SWD HSIC */
865                 platform_device_register(&icera_baseband2_device);
866                 break;
867 #ifdef CONFIG_TEGRA_BB_OEM1
868         case TEGRA_BB_OEM1:     /* OEM1 HSIC */
869                 if ((board_info.board_id == BOARD_E1575) ||
870                         ((board_info.board_id == BOARD_E1580) &&
871                                 (board_info.fab >= BOARD_FAB_A03))) {
872                         tegra_pinmux_set_tristate(TEGRA_PINGROUP_GPIO_X1_AUD,
873                                                         TEGRA_TRI_NORMAL);
874                         bb_gpio_oem1.oem1.pwron = BB_OEM1_GPIO_ON_V;
875                 }
876                 tegra_hsic_pdata.ops = &oem1_hsic_pops;
877                 tegra_ehci3_device.dev.platform_data
878                         = &tegra_hsic_pdata;
879                 platform_device_register(&tegra_bb_oem1);
880                 break;
881 #endif
882         default:
883                 return;
884         }
885 }
886
887 #else
888 static void pluto_usb_init(void) { }
889 static void pluto_modem_init(void) { }
890 #endif
891
892 static void pluto_audio_init(void)
893 {
894         struct board_info board_info;
895
896         tegra_get_board_info(&board_info);
897
898 }
899
900 static struct platform_device *pluto_spi_devices[] __initdata = {
901         &tegra11_spi_device4,
902 };
903
904 struct spi_clk_parent spi_parent_clk_pluto[] = {
905         [0] = {.name = "pll_p"},
906 #ifndef CONFIG_TEGRA_PLLM_RESTRICTED
907         [1] = {.name = "pll_m"},
908         [2] = {.name = "clk_m"},
909 #else
910         [1] = {.name = "clk_m"},
911 #endif
912 };
913
914 static struct tegra_spi_platform_data pluto_spi_pdata = {
915         .is_dma_based           = false,
916         .max_dma_buffer         = 16 * 1024,
917         .is_clkon_always        = false,
918         .max_rate               = 25000000,
919 };
920
921 static void __init pluto_spi_init(void)
922 {
923         int i;
924         struct clk *c;
925         struct board_info board_info, display_board_info;
926
927         tegra_get_board_info(&board_info);
928         tegra_get_display_board_info(&display_board_info);
929
930         for (i = 0; i < ARRAY_SIZE(spi_parent_clk_pluto); ++i) {
931                 c = tegra_get_clock_by_name(spi_parent_clk_pluto[i].name);
932                 if (IS_ERR_OR_NULL(c)) {
933                         pr_err("Not able to get the clock for %s\n",
934                                                 spi_parent_clk_pluto[i].name);
935                         continue;
936                 }
937                 spi_parent_clk_pluto[i].parent_clk = c;
938                 spi_parent_clk_pluto[i].fixed_clk_rate = clk_get_rate(c);
939         }
940         pluto_spi_pdata.parent_clk_list = spi_parent_clk_pluto;
941         pluto_spi_pdata.parent_clk_count = ARRAY_SIZE(spi_parent_clk_pluto);
942         tegra11_spi_device4.dev.platform_data = &pluto_spi_pdata;
943         platform_add_devices(pluto_spi_devices,
944                                 ARRAY_SIZE(pluto_spi_devices));
945 }
946
947 static __initdata struct tegra_clk_init_table touch_clk_init_table[] = {
948         /* name         parent          rate            enabled */
949         { "extern2",    "pll_p",        41000000,       false},
950         { "clk_out_2",  "extern2",      40800000,       false},
951         { NULL,         NULL,           0,              0},
952 };
953
954 struct rm_spi_ts_platform_data rm31080ts_pluto_data = {
955         .gpio_reset = 0,
956         .config = 0,
957         .platform_id = RM_PLATFORM_P005,
958         .name_of_clock = "clk_out_2",
959 };
960
961 static struct tegra_spi_device_controller_data dev_cdata = {
962         .rx_clk_tap_delay = 0,
963         .tx_clk_tap_delay = 0,
964 };
965
966 struct spi_board_info rm31080a_pluto_spi_board[1] = {
967         {
968          .modalias = "rm_ts_spidev",
969          .bus_num = 3,
970          .chip_select = 2,
971          .max_speed_hz = 12 * 1000 * 1000,
972          .mode = SPI_MODE_0,
973          .controller_data = &dev_cdata,
974          .platform_data = &rm31080ts_pluto_data,
975          },
976 };
977
978 static int __init pluto_touch_init(void)
979 {
980         tegra_clk_init_from_table(touch_clk_init_table);
981         clk_enable(tegra_get_clock_by_name("clk_out_2"));
982         mdelay(20);
983         rm31080a_pluto_spi_board[0].irq = gpio_to_irq(TOUCH_GPIO_IRQ_RAYDIUM_SPI);
984         touch_init_raydium(TOUCH_GPIO_IRQ_RAYDIUM_SPI,
985                                 TOUCH_GPIO_RST_RAYDIUM_SPI,
986                                 &rm31080ts_pluto_data,
987                                 &rm31080a_pluto_spi_board[0],
988                                 ARRAY_SIZE(rm31080a_pluto_spi_board));
989         return 0;
990 }
991
992 #ifdef CONFIG_EDP_FRAMEWORK
993 static struct edp_manager battery_edp_manager = {
994         .name = "battery",
995         .imax = 3250
996 };
997
998 static void __init pluto_battery_edp_init(void)
999 {
1000         struct edp_governor *g;
1001         int r;
1002
1003         r = edp_register_manager(&battery_edp_manager);
1004         if (r)
1005                 goto err_ret;
1006
1007         /* start with priority governor */
1008         g = edp_get_governor("priority");
1009         if (!g) {
1010                 r = -EFAULT;
1011                 goto err_ret;
1012         }
1013
1014         r = edp_set_governor(&battery_edp_manager, g);
1015         if (r)
1016                 goto err_ret;
1017
1018         return;
1019
1020 err_ret:
1021         pr_err("Battery EDP init failed with error %d\n", r);
1022         WARN_ON(1);
1023 }
1024 #else
1025 static inline void pluto_battery_edp_init(void) {}
1026 #endif
1027
1028 static void __init tegra_pluto_init(void)
1029 {
1030         pluto_battery_edp_init();
1031         tegra_clk_init_from_table(pluto_clk_init_table);
1032         tegra_soc_device_init("tegra_pluto");
1033         tegra_enable_pinmux();
1034         pluto_pinmux_init();
1035         pluto_i2c_init();
1036         pluto_spi_init();
1037         pluto_usb_init();
1038         pluto_uart_init();
1039         pluto_audio_init();
1040         platform_add_devices(pluto_devices, ARRAY_SIZE(pluto_devices));
1041         //tegra_ram_console_debug_init();
1042         tegra_io_dpd_init();
1043         pluto_sdhci_init();
1044         pluto_regulator_init();
1045         pluto_suspend_init();
1046         pluto_touch_init();
1047         pluto_emc_init();
1048         pluto_edp_init();
1049         pluto_panel_init();
1050         pluto_pmon_init();
1051         pluto_kbc_init();
1052 #ifdef CONFIG_BT_BLUESLEEP
1053         pluto_setup_bluesleep();
1054         pluto_setup_bt_rfkill();
1055 #elif defined CONFIG_BLUEDROID_PM
1056         pluto_setup_bluedroid_pm();
1057 #endif
1058         tegra_release_bootloader_fb();
1059         pluto_modem_init();
1060 #ifdef CONFIG_TEGRA_WDT_RECOVERY
1061         tegra_wdt_recovery_init();
1062 #endif
1063         pluto_sensors_init();
1064         tegra_serial_debug_init(TEGRA_UARTD_BASE, INT_WDT_CPU, NULL, -1, -1);
1065         pluto_soctherm_init();
1066 }
1067
1068 static void __init pluto_ramconsole_reserve(unsigned long size)
1069 {
1070         tegra_ram_console_debug_reserve(SZ_1M);
1071 }
1072
1073 static void __init tegra_pluto_dt_init(void)
1074 {
1075         tegra_pluto_init();
1076
1077         of_platform_populate(NULL,
1078                 of_default_bus_match_table, NULL, NULL);
1079 }
1080
1081 static void __init tegra_pluto_reserve(void)
1082 {
1083 #if defined(CONFIG_NVMAP_CONVERT_CARVEOUT_TO_IOVMM)
1084         /* for PANEL_5_SHARP_1080p: 1920*1080*4*2 = 16588800 bytes */
1085         tegra_reserve(0, SZ_16M, SZ_4M);
1086 #else
1087         tegra_reserve(SZ_128M, SZ_16M, SZ_4M);
1088 #endif
1089         pluto_ramconsole_reserve(SZ_1M);
1090 }
1091
1092 static const char * const pluto_dt_board_compat[] = {
1093         "nvidia,pluto",
1094         NULL
1095 };
1096
1097 MACHINE_START(TEGRA_PLUTO, "tegra_pluto")
1098         .atag_offset    = 0x100,
1099         .smp            = smp_ops(tegra_smp_ops),
1100         .map_io         = tegra_map_common_io,
1101         .reserve        = tegra_pluto_reserve,
1102 #ifdef CONFIG_ARCH_TEGRA_3x_SOC
1103         .init_early     = tegra30_init_early,
1104 #else
1105         .init_early     = tegra11x_init_early,
1106 #endif
1107         .init_irq       = tegra_init_irq,
1108         .handle_irq     = gic_handle_irq,
1109         .timer          = &tegra_timer,
1110         .init_machine   = tegra_pluto_dt_init,
1111         .restart        = tegra_assert_system_reset,
1112         .dt_compat      = pluto_dt_board_compat,
1113 MACHINE_END