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