73747bdfc72465e646f47e7079c1ab392e58e995
[linux-2.6.git] / arch / arm / mach-tegra / board-tegratab.c
1 /*
2  * arch/arm/mach-tegra/board-tegratab.c
3  *
4  * Copyright (c) 2013, 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/platform_data/tegra_usb_modem_power.h>
35 #include <linux/spi/spi.h>
36 #include <linux/spi/rm31080a_ts.h>
37 #include <linux/maxim_sti.h>
38 #include <linux/tegra_uart.h>
39 #include <linux/memblock.h>
40 #include <linux/spi-tegra.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/of_platform.h>
49 #include <linux/edp.h>
50
51 #include <asm/hardware/gic.h>
52
53 #include <mach/clk.h>
54 #include <mach/iomap.h>
55 #include <mach/irqs.h>
56 #include <mach/pinmux.h>
57 #include <mach/pinmux-t11.h>
58 #include <mach/iomap.h>
59 #include <mach/io.h>
60 #include <mach/io_dpd.h>
61 #include <mach/i2s.h>
62 #include <mach/tegra_asoc_pdata.h>
63 #include <asm/mach-types.h>
64 #include <asm/mach/arch.h>
65 #include <mach/usb_phy.h>
66 #include <mach/gpio-tegra.h>
67 #include <mach/tegra_fiq_debugger.h>
68 #include <mach/hardware.h>
69
70 #include "board-touch-raydium.h"
71 #include "board.h"
72 #include "board-common.h"
73 #include "board-touch-maxim_sti.h"
74 #include "clock.h"
75 #include "board-tegratab.h"
76 #include "devices.h"
77 #include "gpio-names.h"
78 #include "fuse.h"
79 #include "pm.h"
80 #include "pm-irq.h"
81 #include "common.h"
82 #include "tegra-board-id.h"
83
84 #if defined CONFIG_TI_ST || defined CONFIG_TI_ST_MODULE
85 struct ti_st_plat_data tegratab_wilink_pdata = {
86         .nshutdown_gpio = TEGRA_GPIO_PQ7,
87         .dev_name = BLUETOOTH_UART_DEV_NAME,
88         .flow_cntrl = 1,
89         .baud_rate = 3000000,
90 };
91
92 static struct platform_device wl128x_device = {
93         .name           = "kim",
94         .id             = -1,
95         .dev.platform_data = &tegratab_wilink_pdata,
96 };
97
98 static struct platform_device btwilink_device = {
99         .name = "btwilink",
100         .id = -1,
101 };
102
103 static noinline void __init tegratab_bt_st(void)
104 {
105         struct board_info board_info;
106
107         pr_info("tegratab_bt_st");
108         tegra_get_board_info(&board_info);
109
110         if (board_info.board_id == BOARD_P1640)
111                 tegratab_wilink_pdata.nshutdown_gpio = TEGRA_GPIO_PR1;
112
113         platform_device_register(&wl128x_device);
114         platform_device_register(&btwilink_device);
115 }
116
117 static struct resource tegratab_st_host_wake_resources[] = {
118         [0] = {
119                 .name = "host_wake",
120                 .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
121         },
122 };
123
124 static struct platform_device tegratab_st_host_wake_device = {
125         .name           = "st_host_wake",
126         .id             = 0,
127         .num_resources  = ARRAY_SIZE(tegratab_st_host_wake_resources),
128         .resource       = tegratab_st_host_wake_resources,
129 };
130
131 static noinline void __init tegratab_tegra_setup_st_host_wake(void)
132 {
133         tegratab_st_host_wake_resources[0].start =
134                 tegratab_st_host_wake_resources[0].end =
135                 gpio_to_irq(TEGRA_GPIO_PU6);
136         platform_device_register(&tegratab_st_host_wake_device);
137 }
138 #endif
139
140 static __initdata struct tegra_clk_init_table tegratab_clk_init_table[] = {
141         /* name         parent          rate            enabled */
142         { "pll_m",      NULL,           0,              false},
143         { "hda",        "pll_p",        108000000,      false},
144         { "hda2codec_2x", "pll_p",      48000000,       false},
145         { "pwm",        "pll_p",        48000000,       false},
146         { "i2s1",       "pll_a_out0",   0,              false},
147         { "i2s3",       "pll_a_out0",   0,              false},
148         { "i2s4",       "pll_a_out0",   0,              false},
149         { "spdif_out",  "pll_a_out0",   0,              false},
150         { "d_audio",    "clk_m",        12000000,       false},
151         { "dam0",       "clk_m",        12000000,       false},
152         { "dam1",       "clk_m",        12000000,       false},
153         { "dam2",       "clk_m",        12000000,       false},
154         { "audio1",     "i2s1_sync",    0,              false},
155         { "audio3",     "i2s3_sync",    0,              false},
156         /* Setting vi_sensor-clk to true for validation purpose, will imapact
157          * power, later set to be false.*/
158         { "vi_sensor",  "pll_p",        150000000,      false},
159         { "cilab",      "pll_p",        150000000,      false},
160         { "cilcd",      "pll_p",        150000000,      false},
161         { "cile",       "pll_p",        150000000,      false},
162         { "i2c1",       "pll_p",        3200000,        false},
163         { "i2c2",       "pll_p",        3200000,        false},
164         { "i2c3",       "pll_p",        3200000,        false},
165         { "i2c4",       "pll_p",        3200000,        false},
166         { "i2c5",       "pll_p",        3200000,        false},
167         { NULL,         NULL,           0,              0},
168 };
169
170 static __initdata struct tegra_clk_init_table e1569_wifi_clk_init_table[] = {
171         { "blink",      "clk_32k",      32768,          true},
172         { NULL,         NULL,           0,              0},
173 };
174
175 static __initdata struct tegra_clk_init_table P1640_wifi_clk_init_table[] = {
176         { "extern3",    "clk_32k",      32768,          true},
177         { "clk_out_3",  "extern3",      32768,          true},
178         { NULL,         NULL,           0,              0},
179 };
180
181 static struct tegra_i2c_platform_data tegratab_i2c1_platform_data = {
182         .adapter_nr     = 0,
183         .bus_count      = 1,
184         .bus_clk_rate   = { 100000, 0 },
185         .scl_gpio               = {TEGRA_GPIO_I2C1_SCL, 0},
186         .sda_gpio               = {TEGRA_GPIO_I2C1_SDA, 0},
187         .arb_recovery = arb_lost_recovery,
188 };
189
190 static struct tegra_i2c_platform_data tegratab_i2c2_platform_data = {
191         .adapter_nr     = 1,
192         .bus_count      = 1,
193         .bus_clk_rate   = { 100000, 0 },
194         .is_clkon_always = true,
195         .scl_gpio               = {TEGRA_GPIO_I2C2_SCL, 0},
196         .sda_gpio               = {TEGRA_GPIO_I2C2_SDA, 0},
197         .arb_recovery = arb_lost_recovery,
198 };
199
200 static struct tegra_i2c_platform_data tegratab_i2c3_platform_data = {
201         .adapter_nr     = 2,
202         .bus_count      = 1,
203         .bus_clk_rate   = { 400000, 0 },
204         .scl_gpio               = {TEGRA_GPIO_I2C3_SCL, 0},
205         .sda_gpio               = {TEGRA_GPIO_I2C3_SDA, 0},
206         .arb_recovery = arb_lost_recovery,
207 };
208
209 static struct tegra_i2c_platform_data tegratab_i2c4_platform_data = {
210         .adapter_nr     = 3,
211         .bus_count      = 1,
212         .bus_clk_rate   = { 10000, 0 },
213         .scl_gpio               = {TEGRA_GPIO_I2C4_SCL, 0},
214         .sda_gpio               = {TEGRA_GPIO_I2C4_SDA, 0},
215         .arb_recovery = arb_lost_recovery,
216 };
217
218 static struct tegra_i2c_platform_data tegratab_i2c5_platform_data = {
219         .adapter_nr     = 4,
220         .bus_count      = 1,
221         .bus_clk_rate   = { 400000, 0 },
222         .scl_gpio               = {TEGRA_GPIO_I2C5_SCL, 0},
223         .sda_gpio               = {TEGRA_GPIO_I2C5_SDA, 0},
224         .arb_recovery = arb_lost_recovery,
225 };
226
227 static struct i2c_board_info __initdata rt5640_board_info = {
228         I2C_BOARD_INFO("rt5640", 0x1c),
229 };
230
231 static struct i2c_board_info __initdata rt5639_board_info = {
232         I2C_BOARD_INFO("rt5639", 0x1c),
233 };
234
235 static void tegratab_i2c_init(void)
236 {
237         struct board_info board_info;
238
239         tegra_get_board_info(&board_info);
240
241         if (board_info.board_id == BOARD_P1640)
242                 i2c_register_board_info(0, &rt5639_board_info, 1);
243         else
244                 i2c_register_board_info(0, &rt5640_board_info, 1);
245 }
246
247 static struct platform_device *tegratab_uart_devices[] __initdata = {
248         &tegra_uarta_device,
249         &tegra_uartb_device,
250         &tegra_uartc_device,
251         &tegra_uartd_device,
252 };
253 static struct uart_clk_parent uart_parent_clk[] = {
254         [0] = {.name = "clk_m"},
255         [1] = {.name = "pll_p"},
256 #ifndef CONFIG_TEGRA_PLLM_RESTRICTED
257         [2] = {.name = "pll_m"},
258 #endif
259 };
260
261 static struct tegra_uart_platform_data tegratab_uart_pdata;
262 static struct tegra_uart_platform_data tegratab_loopback_uart_pdata;
263
264 static void __init uart_debug_init(void)
265 {
266         int debug_port_id;
267
268         debug_port_id = uart_console_debug_init(3);
269         if (debug_port_id < 0)
270                 return;
271
272         tegratab_uart_devices[debug_port_id] = uart_console_debug_device;
273 }
274
275 static void __init tegratab_uart_init(void)
276 {
277         struct clk *c;
278         int i;
279
280         for (i = 0; i < ARRAY_SIZE(uart_parent_clk); ++i) {
281                 c = tegra_get_clock_by_name(uart_parent_clk[i].name);
282                 if (IS_ERR_OR_NULL(c)) {
283                         pr_err("Not able to get the clock for %s\n",
284                                                 uart_parent_clk[i].name);
285                         continue;
286                 }
287                 uart_parent_clk[i].parent_clk = c;
288                 uart_parent_clk[i].fixed_clk_rate = clk_get_rate(c);
289         }
290         tegratab_uart_pdata.parent_clk_list = uart_parent_clk;
291         tegratab_uart_pdata.parent_clk_count = ARRAY_SIZE(uart_parent_clk);
292         tegratab_loopback_uart_pdata.parent_clk_list = uart_parent_clk;
293         tegratab_loopback_uart_pdata.parent_clk_count =
294                                                 ARRAY_SIZE(uart_parent_clk);
295         tegratab_loopback_uart_pdata.is_loopback = true;
296         tegra_uarta_device.dev.platform_data = &tegratab_uart_pdata;
297         tegra_uartb_device.dev.platform_data = &tegratab_uart_pdata;
298         tegra_uartc_device.dev.platform_data = &tegratab_uart_pdata;
299         tegra_uartd_device.dev.platform_data = &tegratab_uart_pdata;
300
301         /* Register low speed only if it is selected */
302         if (!is_tegra_debug_uartport_hs())
303                 uart_debug_init();
304
305         platform_add_devices(tegratab_uart_devices,
306                                 ARRAY_SIZE(tegratab_uart_devices));
307 }
308
309 static struct resource tegra_rtc_resources[] = {
310         [0] = {
311                 .start = TEGRA_RTC_BASE,
312                 .end = TEGRA_RTC_BASE + TEGRA_RTC_SIZE - 1,
313                 .flags = IORESOURCE_MEM,
314         },
315         [1] = {
316                 .start = INT_RTC,
317                 .end = INT_RTC,
318                 .flags = IORESOURCE_IRQ,
319         },
320 };
321
322 static struct platform_device tegra_rtc_device = {
323         .name = "tegra_rtc",
324         .id   = -1,
325         .resource = tegra_rtc_resources,
326         .num_resources = ARRAY_SIZE(tegra_rtc_resources),
327 };
328
329 static struct tegra_asoc_platform_data tegratab_audio_pdata = {
330         .gpio_spkr_en           = TEGRA_GPIO_SPKR_EN,
331         .gpio_hp_mute           = -1,
332         .gpio_int_mic_en        = TEGRA_GPIO_INT_MIC_EN,
333         .gpio_ext_mic_en        = TEGRA_GPIO_EXT_MIC_EN,
334         .gpio_ldo1_en           = TEGRA_GPIO_LDO1_EN,
335         .gpio_codec1 = TEGRA_GPIO_CODEC1_EN,
336         .gpio_codec2 = TEGRA_GPIO_CODEC2_EN,
337         .gpio_codec3 = TEGRA_GPIO_CODEC3_EN,
338         .micbias_gpio_absent = true,
339         .i2s_param[HIFI_CODEC]  = {
340                 .audio_port_id  = 1,
341                 .is_i2s_master  = 1,
342                 .i2s_mode       = TEGRA_DAIFMT_I2S,
343         },
344         .i2s_param[BT_SCO]      = {
345                 .audio_port_id  = 3,
346                 .is_i2s_master  = 1,
347                 .i2s_mode       = TEGRA_DAIFMT_DSP_A,
348         },
349         .edp_support    = true,
350         .edp_states     = {4760, 4760, 0},
351         .edp_vol        = {0x8, 0x8, 0x27},
352 };
353
354 static struct platform_device tegratab_audio_device = {
355         .name   = "tegra-snd-rt5640",
356         .id     = 0,
357         .dev    = {
358                 .platform_data = &tegratab_audio_pdata,
359         },
360 };
361
362 static struct platform_device *tegratab_devices[] __initdata = {
363         &tegra_pmu_device,
364         &tegra_rtc_device,
365         &tegra_udc_device,
366 #if defined(CONFIG_TEGRA_AVP)
367         &tegra_avp_device,
368 #endif
369 #if defined(CONFIG_CRYPTO_DEV_TEGRA_SE)
370         &tegra11_se_device,
371 #endif
372         &tegra_ahub_device,
373         &tegra_dam_device0,
374         &tegra_dam_device1,
375         &tegra_dam_device2,
376         &tegra_i2s_device1,
377         &tegra_i2s_device3,
378         &tegra_i2s_device4,
379         &tegra_spdif_device,
380         &spdif_dit_device,
381         &bluetooth_dit_device,
382         &tegra_pcm_device,
383         &tegratab_audio_device,
384         &tegra_hda_device,
385 #if defined(CONFIG_CRYPTO_DEV_TEGRA_AES)
386         &tegra_aes_device,
387 #endif
388 };
389
390 #ifdef CONFIG_USB_SUPPORT
391 static struct tegra_usb_platform_data tegra_udc_pdata = {
392         .port_otg = true,
393         .has_hostpc = true,
394         .support_pmu_vbus = true,
395         .id_det_type = TEGRA_USB_PMU_ID,
396         .phy_intf = TEGRA_USB_PHY_INTF_UTMI,
397         .op_mode = TEGRA_USB_OPMODE_DEVICE,
398         .u_data.dev = {
399                 .vbus_pmu_irq = 0,
400                 .vbus_gpio = -1,
401                 .charging_supported = false,
402                 .remote_wakeup_supported = false,
403         },
404         .u_cfg.utmi = {
405                 .hssync_start_delay = 0,
406                 .elastic_limit = 16,
407                 .idle_wait_delay = 17,
408                 .term_range_adj = 6,
409                 .xcvr_setup = 8,
410                 .xcvr_lsfslew = 2,
411                 .xcvr_lsrslew = 2,
412                 .xcvr_setup_offset = 0,
413                 .xcvr_use_fuses = 1,
414         },
415 };
416
417 static struct tegra_usb_platform_data tegra_ehci1_utmi_pdata = {
418         .port_otg = true,
419         .has_hostpc = true,
420         .support_pmu_vbus = true,
421         .id_det_type = TEGRA_USB_PMU_ID,
422         .unaligned_dma_buf_supported = false,
423         .phy_intf = TEGRA_USB_PHY_INTF_UTMI,
424         .op_mode = TEGRA_USB_OPMODE_HOST,
425         .u_data.host = {
426                 .vbus_gpio = -1,
427                 .hot_plug = false,
428                 .remote_wakeup_supported = true,
429                 .power_off_on_suspend = true,
430                 .turn_off_vbus_on_lp0 = true,
431         },
432         .u_cfg.utmi = {
433                 .hssync_start_delay = 0,
434                 .elastic_limit = 16,
435                 .idle_wait_delay = 17,
436                 .term_range_adj = 6,
437                 .xcvr_setup = 15,
438                 .xcvr_lsfslew = 2,
439                 .xcvr_lsrslew = 2,
440                 .xcvr_setup_offset = -5,
441                 .xcvr_use_fuses = 1,
442                 .vbus_oc_map = 0x4,
443                 .xcvr_hsslew_lsb = 3,
444         },
445 };
446
447 static struct tegra_usb_otg_data tegra_otg_pdata = {
448         .ehci_device = &tegra_ehci1_device,
449         .ehci_pdata = &tegra_ehci1_utmi_pdata,
450         .vbus_extcon_dev_name = "palmas-extcon",
451         .id_extcon_dev_name = "palmas-extcon",
452 };
453
454 static void tegratab_usb_init(void)
455 {
456         int usb_port_owner_info = tegra_get_usb_port_owner_info();
457
458         /* Set USB wake sources for tegratab */
459         tegra_set_usb_wake_source();
460
461         if (!(usb_port_owner_info & UTMI1_PORT_OWNER_XUSB)) {
462                 tegra_otg_device.dev.platform_data = &tegra_otg_pdata;
463                 platform_device_register(&tegra_otg_device);
464                 /* Setup the udc platform data */
465                 tegra_udc_device.dev.platform_data = &tegra_udc_pdata;
466         }
467 }
468
469 static struct gpio modem_gpios[] = { /* Nemo modem */
470         {MODEM_EN, GPIOF_OUT_INIT_HIGH, "MODEM EN"},
471         {MDM_RST, GPIOF_OUT_INIT_LOW, "MODEM RESET"},
472 };
473
474 static struct tegra_usb_platform_data tegra_ehci2_hsic_baseband_pdata = {
475         .port_otg = false,
476         .has_hostpc = true,
477         .unaligned_dma_buf_supported = false,
478         .phy_intf = TEGRA_USB_PHY_INTF_HSIC,
479         .op_mode = TEGRA_USB_OPMODE_HOST,
480         .u_data.host = {
481                 .vbus_gpio = -1,
482                 .hot_plug = false,
483                 .remote_wakeup_supported = true,
484                 .power_off_on_suspend = true,
485         },
486 };
487
488 static int baseband_init(void)
489 {
490         int ret;
491
492         ret = gpio_request_array(modem_gpios, ARRAY_SIZE(modem_gpios));
493         if (ret) {
494                 pr_warn("%s:gpio request failed\n", __func__);
495                 return ret;
496         }
497
498         /* enable pull-down for MDM_COLD_BOOT */
499         tegra_pinmux_set_pullupdown(TEGRA_PINGROUP_ULPI_DATA4,
500                                     TEGRA_PUPD_PULL_DOWN);
501
502         /* export GPIO for user space access through sysfs */
503         gpio_export(MDM_RST, false);
504
505         return 0;
506 }
507
508 static const struct tegra_modem_operations baseband_operations = {
509         .init = baseband_init,
510 };
511
512 static struct tegra_usb_modem_power_platform_data baseband_pdata = {
513         .ops = &baseband_operations,
514         .wake_gpio = -1,
515         .boot_gpio = MDM_COLDBOOT,
516         .boot_irq_flags = IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
517         .autosuspend_delay = 2000,
518         .short_autosuspend_delay = 50,
519         .tegra_ehci_device = &tegra_ehci2_device,
520         .tegra_ehci_pdata = &tegra_ehci2_hsic_baseband_pdata,
521 };
522
523 static struct platform_device icera_nemo_device = {
524         .name = "tegra_usb_modem_power",
525         .id = -1,
526         .dev = {
527                 .platform_data = &baseband_pdata,
528         },
529 };
530
531 static void tegratab_modem_init(void)
532 {
533         int modem_id = tegra_get_modem_id();
534         int usb_port_owner_info = tegra_get_usb_port_owner_info();
535         switch (modem_id) {
536         case TEGRA_BB_NEMO: /* on board i500 HSIC */
537                 if (!(usb_port_owner_info & HSIC1_PORT_OWNER_XUSB)) {
538                         platform_device_register(&icera_nemo_device);
539                 }
540                 break;
541         }
542 }
543
544 #else
545 static void tegratab_usb_init(void) { }
546 static void tegratab_modem_init(void) { }
547 #endif
548
549 static void tegratab_audio_init(void)
550 {
551         struct board_info board_info;
552
553         tegra_get_board_info(&board_info);
554
555         if (board_info.board_id == BOARD_P1640) {
556                 tegratab_audio_pdata.codec_name = "rt5639.0-001c";
557                 tegratab_audio_pdata.codec_dai_name = "rt5639-aif1";
558                 if (board_info.fab == BOARD_FAB_A00)
559                         tegratab_audio_pdata.gpio_hp_det = TEGRA_GPIO_HP_DET;
560                 else {/* from A01, CDC_IRQ from codec is used as interrupt */
561                         tegratab_audio_pdata.gpio_hp_det = TEGRA_GPIO_CDC_IRQ;
562                         tegratab_audio_pdata.use_codec_jd_irq = true;
563                 }
564         } else {
565                 tegratab_audio_pdata.codec_name = "rt5640.0-001c";
566                 tegratab_audio_pdata.codec_dai_name = "rt5640-aif1";
567                 tegratab_audio_pdata.gpio_hp_det = TEGRA_GPIO_HP_DET;
568         }
569 }
570
571
572 static struct platform_device *tegratab_spi_devices[] __initdata = {
573         &tegra11_spi_device1,
574 };
575
576 struct spi_clk_parent spi_parent_clk_tegratab[] = {
577         [0] = {.name = "pll_p"},
578 #ifndef CONFIG_TEGRA_PLLM_RESTRICTED
579         [1] = {.name = "pll_m"},
580         [2] = {.name = "clk_m"},
581 #else
582         [1] = {.name = "clk_m"},
583 #endif
584 };
585
586 static struct tegra_spi_platform_data tegratab_spi_pdata = {
587         .max_dma_buffer         = 16 * 1024,
588         .is_clkon_always        = false,
589         .max_rate               = 25000000,
590 };
591
592 static void __init tegratab_spi_init(void)
593 {
594         int i;
595         struct clk *c;
596         struct board_info board_info, display_board_info;
597
598         tegra_get_board_info(&board_info);
599         tegra_get_display_board_info(&display_board_info);
600
601         for (i = 0; i < ARRAY_SIZE(spi_parent_clk_tegratab); ++i) {
602                 c = tegra_get_clock_by_name(spi_parent_clk_tegratab[i].name);
603                 if (IS_ERR_OR_NULL(c)) {
604                         pr_err("Not able to get the clock for %s\n",
605                                         spi_parent_clk_tegratab[i].name);
606                         continue;
607                 }
608                 spi_parent_clk_tegratab[i].parent_clk = c;
609                 spi_parent_clk_tegratab[i].fixed_clk_rate = clk_get_rate(c);
610         }
611         tegratab_spi_pdata.parent_clk_list = spi_parent_clk_tegratab;
612         tegratab_spi_pdata.parent_clk_count =
613                 ARRAY_SIZE(spi_parent_clk_tegratab);
614         tegratab_spi_pdata.is_dma_based =
615                 (tegra_revision == TEGRA_REVISION_A01) ? false : true;
616         tegra11_spi_device1.dev.platform_data = &tegratab_spi_pdata;
617         platform_add_devices(tegratab_spi_devices,
618                 ARRAY_SIZE(tegratab_spi_devices));
619 }
620
621 #if defined(CONFIG_TOUCHSCREEN_MAXIM_STI) || \
622         defined(CONFIG_TOUCHSCREEN_MAXIM_STI_MODULE)
623 struct maxim_sti_pdata maxim_sti_pdata = {
624         .touch_fusion         = "/vendor/bin/touch_fusion",
625         .config_file          = "/vendor/firmware/touch_fusion.cfg",
626         .fw_name              = "maxim_fp35.bin",
627         .nl_family            = TF_FAMILY_NAME,
628         .nl_mc_groups         = 5,
629         .chip_access_method   = 2,
630         .default_reset_state  = 0,
631         .tx_buf_size          = 4100,
632         .rx_buf_size          = 4100,
633         .gpio_reset           = TOUCH_GPIO_RST_MAXIM_STI_SPI,
634         .gpio_irq             = TOUCH_GPIO_IRQ_MAXIM_STI_SPI
635 };
636
637 struct maxim_sti_pdata maxim_sti_pdata_rd = {
638         .touch_fusion         = "/vendor/bin/touch_fusion_rd",
639         .config_file          = "/vendor/firmware/touch_fusion.cfg",
640         .fw_name              = "maxim_fp35.bin",
641         .nl_family            = TF_FAMILY_NAME,
642         .nl_mc_groups         = 5,
643         .chip_access_method   = 2,
644         .default_reset_state  = 0,
645         .tx_buf_size          = 4100,
646         .rx_buf_size          = 4100,
647         .gpio_reset           = TOUCH_GPIO_RST_MAXIM_STI_SPI,
648         .gpio_irq             = TOUCH_GPIO_IRQ_MAXIM_STI_SPI
649 };
650
651 static struct tegra_spi_device_controller_data dev_cdata = {
652         .rx_clk_tap_delay = 0,
653         .is_hw_based_cs = true,
654         .tx_clk_tap_delay = 0,
655 };
656
657 struct spi_board_info maxim_sti_spi_board = {
658         .modalias = MAXIM_STI_NAME,
659         .bus_num = 0,
660         .chip_select = 0,
661         .max_speed_hz = 12 * 1000 * 1000,
662         .mode = SPI_MODE_0,
663         .platform_data = &maxim_sti_pdata_rd,
664         .controller_data = &dev_cdata
665 };
666 #else
667 static __initdata struct tegra_clk_init_table touch_clk_init_table[] = {
668         /* name         parent          rate            enabled */
669         { "extern2",    "pll_p",        41000000,       false},
670         { "clk_out_2",  "extern2",      40800000,       false},
671         { NULL,         NULL,           0,              0},
672 };
673
674 struct rm_spi_ts_platform_data rm31080ts_tegratab_data = {
675         .gpio_reset = TOUCH_GPIO_RST_RAYDIUM_SPI,
676         .config = 0,
677         .platform_id = RM_PLATFORM_D010,
678         .name_of_clock = "clk_out_2",
679         .name_of_clock_con = "extern2",
680 };
681
682 static struct tegra_spi_device_controller_data dev_cdata = {
683         .rx_clk_tap_delay = 0,
684         .tx_clk_tap_delay = 0,
685 };
686
687 struct spi_board_info rm31080a_tegratab_spi_board[1] = {
688         {
689          .modalias = "rm_ts_spidev",
690          .bus_num = 0,
691          .chip_select = 0,
692          .max_speed_hz = 12 * 1000 * 1000,
693          .mode = SPI_MODE_0,
694          .controller_data = &dev_cdata,
695          .platform_data = &rm31080ts_tegratab_data,
696          },
697 };
698 #endif
699
700 static int __init tegratab_touch_init(void)
701 {
702 #if defined(CONFIG_TOUCHSCREEN_MAXIM_STI) || \
703         defined(CONFIG_TOUCHSCREEN_MAXIM_STI_MODULE)
704         struct board_info board_info;
705
706         tegra_get_board_info(&board_info);
707         if (board_info.board_id == BOARD_P1640) {
708                 if (board_info.fab == BOARD_FAB_A00)
709                         maxim_sti_spi_board.platform_data = &maxim_sti_pdata;
710                 (void)touch_init_maxim_sti(&maxim_sti_spi_board);
711         }
712 #else
713         tegra_clk_init_from_table(touch_clk_init_table);
714         rm31080ts_tegratab_data.platform_id = RM_PLATFORM_D010;
715         mdelay(20);
716         rm31080a_tegratab_spi_board[0].irq =
717                 gpio_to_irq(TOUCH_GPIO_IRQ_RAYDIUM_SPI);
718         touch_init_raydium(TOUCH_GPIO_IRQ_RAYDIUM_SPI,
719                                 TOUCH_GPIO_RST_RAYDIUM_SPI,
720                                 &rm31080ts_tegratab_data,
721                                 &rm31080a_tegratab_spi_board[0],
722                                 ARRAY_SIZE(rm31080a_tegratab_spi_board));
723 #endif
724         return 0;
725 }
726
727 static void __init tegra_tegratab_early_init(void)
728 {
729         struct board_info board_info;
730
731         tegra_clk_init_from_table(tegratab_clk_init_table);
732         /* enable wifi 32K clk according to board revision */
733         tegra_get_board_info(&board_info);
734         if (board_info.board_id == BOARD_E1569)
735                 tegra_clk_init_from_table(e1569_wifi_clk_init_table);
736         else if (board_info.board_id == BOARD_P1640 &&
737                         board_info.fab == BOARD_FAB_A00)
738                 tegra_clk_init_from_table(P1640_wifi_clk_init_table);
739         tegra_clk_verify_parents();
740         tegra_soc_device_init("tegratab");
741 #if defined(CONFIG_TEGRA_IOVMM_SMMU) || defined(CONFIG_TEGRA_IOMMU_SMMU)
742         platform_device_register(&tegra_smmu_device);
743 #endif
744 }
745
746 struct of_dev_auxdata tegratab_auxdata_lookup[] __initdata = {
747         OF_DEV_AUXDATA("nvidia,tegra114-host1x", TEGRA_HOST1X_BASE, "host1x",
748                                 NULL),
749         OF_DEV_AUXDATA("nvidia,tegra114-gr3d", TEGRA_GR3D_BASE, "gr3d",
750                                 NULL),
751         OF_DEV_AUXDATA("nvidia,tegra114-gr2d", TEGRA_GR2D_BASE, "gr2d",
752                                 NULL),
753         OF_DEV_AUXDATA("nvidia,tegra114-msenc", TEGRA_MSENC_BASE, "msenc",
754                                 NULL),
755         OF_DEV_AUXDATA("nvidia,tegra114-vi", TEGRA_VI_BASE, "vi",
756                                 NULL),
757         OF_DEV_AUXDATA("nvidia,tegra114-isp", TEGRA_ISP_BASE, "isp",
758                                 NULL),
759         OF_DEV_AUXDATA("nvidia,tegra114-tsec", TEGRA_TSEC_BASE, "tsec",
760                                 NULL),
761         OF_DEV_AUXDATA("nvidia,tegra114-i2c", 0x7000c000, "tegra11-i2c.0",
762                 &tegratab_i2c1_platform_data),
763         OF_DEV_AUXDATA("nvidia,tegra114-i2c", 0x7000c400, "tegra11-i2c.1",
764                 &tegratab_i2c2_platform_data),
765         OF_DEV_AUXDATA("nvidia,tegra114-i2c", 0x7000c500, "tegra11-i2c.2",
766                 &tegratab_i2c3_platform_data),
767         OF_DEV_AUXDATA("nvidia,tegra114-i2c", 0x7000c700, "tegra11-i2c.3",
768                 &tegratab_i2c4_platform_data),
769         OF_DEV_AUXDATA("nvidia,tegra114-i2c", 0x7000d000, "tegra11-i2c.4",
770                 &tegratab_i2c5_platform_data),
771         {},
772 };
773
774 static void __init tegra_tegratab_late_init(void)
775 {
776         struct board_info board_info;
777         tegra_get_display_board_info(&board_info);
778
779         platform_device_register(&tegra_pinmux_device);
780         tegratab_pinmux_init();
781         tegratab_i2c_init();
782         tegratab_spi_init();
783         tegratab_usb_init();
784         tegratab_uart_init();
785         tegratab_audio_init();
786         platform_add_devices(tegratab_devices, ARRAY_SIZE(tegratab_devices));
787         tegra_ram_console_debug_init();
788         tegra_io_dpd_init();
789         tegratab_regulator_init();
790         tegratab_power_off_init();
791         tegratab_sdhci_init();
792         tegratab_suspend_init();
793         tegratab_emc_init();
794         tegratab_edp_init();
795         tegratab_touch_init();
796         tegratab_panel_init();
797         tegratab_kbc_init();
798         tegratab_pmon_init();
799 #if defined CONFIG_TI_ST || defined CONFIG_TI_ST_MODULE
800         tegratab_bt_st();
801         tegratab_tegra_setup_st_host_wake();
802 #endif
803         tegra_release_bootloader_fb();
804         tegratab_modem_init();
805 #ifdef CONFIG_TEGRA_WDT_RECOVERY
806         tegra_wdt_recovery_init();
807 #endif
808         tegra_serial_debug_init(TEGRA_UARTD_BASE, INT_WDT_CPU, NULL, -1, -1);
809         tegratab_sensors_init();
810         tegratab_soctherm_init();
811         tegra_register_fuse();
812 }
813
814 static void __init tegratab_ramconsole_reserve(unsigned long size)
815 {
816         tegra_ram_console_debug_reserve(SZ_1M);
817 }
818
819 static void __init tegra_tegratab_dt_init(void)
820 {
821         tegra_tegratab_early_init();
822
823 #ifdef CONFIG_USE_OF
824         of_platform_populate(NULL, of_default_bus_match_table,
825                 tegratab_auxdata_lookup, &platform_bus);
826 #endif
827
828         tegra_tegratab_late_init();
829 }
830
831 static void __init tegra_tegratab_reserve(void)
832 {
833 #if defined(CONFIG_NVMAP_CONVERT_CARVEOUT_TO_IOVMM)
834         /* 1920*1200*4*2 = 18432000 bytes */
835         tegra_reserve(0, SZ_16M + SZ_2M, SZ_16M);
836 #else
837         tegra_reserve(SZ_128M, SZ_16M + SZ_2M, SZ_4M);
838 #endif
839         tegratab_ramconsole_reserve(SZ_1M);
840 }
841
842 static const char * const tegratab_dt_board_compat[] = {
843         "nvidia,tegratab",
844         NULL
845 };
846
847 MACHINE_START(TEGRATAB, "tegratab")
848         .atag_offset    = 0x100,
849         .soc            = &tegra_soc_desc,
850         .map_io         = tegra_map_common_io,
851         .reserve        = tegra_tegratab_reserve,
852         .init_early     = tegra11x_init_early,
853         .init_irq       = tegra_dt_init_irq,
854         .handle_irq     = gic_handle_irq,
855         .timer          = &tegra_timer,
856         .init_machine   = tegra_tegratab_dt_init,
857         .restart        = tegra_assert_system_reset,
858         .dt_compat      = tegratab_dt_board_compat,
859 MACHINE_END