video: tegra: host: add DT support
[linux-3.10.git] / arch / arm / mach-tegra / board-dalmore.c
1 /*
2  * arch/arm/mach-tegra/board-dalmore.c
3  *
4  * Copyright (c) 2012-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_xusb.h>
35 #include <linux/spi/spi.h>
36 #include <linux/spi/rm31080a_ts.h>
37 #include <linux/tegra_uart.h>
38 #include <linux/memblock.h>
39 #include <linux/spi-tegra.h>
40 #include <linux/nfc/pn544.h>
41 #include <linux/rfkill-gpio.h>
42 #include <linux/skbuff.h>
43 #include <linux/ti_wilink_st.h>
44 #include <linux/regulator/consumer.h>
45 #include <linux/smb349-charger.h>
46 #include <linux/max17048_battery.h>
47 #include <linux/leds.h>
48 #include <linux/i2c/at24.h>
49 #include <linux/of_platform.h>
50 #include <linux/edp.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/isomgr.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_usb_modem_power.h>
71
72 #include "board-touch-raydium.h"
73 #include "board.h"
74 #include "board-common.h"
75 #include "clock.h"
76 #include "board-dalmore.h"
77 #include "devices.h"
78 #include "gpio-names.h"
79 #include "fuse.h"
80 #include "pm.h"
81 #include "pm-irq.h"
82 #include "common.h"
83 #include "tegra-board-id.h"
84
85 static struct board_info board_info, display_board_info;
86
87 #ifdef CONFIG_BT_BLUESLEEP
88 static struct rfkill_gpio_platform_data dalmore_bt_rfkill_pdata = {
89                 .name           = "bt_rfkill",
90                 .shutdown_gpio  = TEGRA_GPIO_PQ7,
91                 .reset_gpio     = TEGRA_GPIO_PQ6,
92                 .type           = RFKILL_TYPE_BLUETOOTH,
93 };
94
95 static struct platform_device dalmore_bt_rfkill_device = {
96         .name = "rfkill_gpio",
97         .id             = -1,
98         .dev = {
99                 .platform_data = &dalmore_bt_rfkill_pdata,
100         },
101 };
102
103 static struct resource dalmore_bluesleep_resources[] = {
104         [0] = {
105                 .name = "gpio_host_wake",
106                         .start  = TEGRA_GPIO_PU6,
107                         .end    = TEGRA_GPIO_PU6,
108                         .flags  = IORESOURCE_IO,
109         },
110         [1] = {
111                 .name = "gpio_ext_wake",
112                         .start  = TEGRA_GPIO_PEE1,
113                         .end    = TEGRA_GPIO_PEE1,
114                         .flags  = IORESOURCE_IO,
115         },
116         [2] = {
117                 .name = "host_wake",
118                         .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
119         },
120 };
121
122 static struct platform_device dalmore_bluesleep_device = {
123         .name           = "bluesleep",
124         .id             = -1,
125         .num_resources  = ARRAY_SIZE(dalmore_bluesleep_resources),
126         .resource       = dalmore_bluesleep_resources,
127 };
128
129 static noinline void __init dalmore_setup_bt_rfkill(void)
130 {
131         platform_device_register(&dalmore_bt_rfkill_device);
132 }
133
134 static noinline void __init dalmore_setup_bluesleep(void)
135 {
136         dalmore_bluesleep_resources[2].start =
137                 dalmore_bluesleep_resources[2].end =
138                         gpio_to_irq(TEGRA_GPIO_PU6);
139         platform_device_register(&dalmore_bluesleep_device);
140         return;
141 }
142 #elif defined CONFIG_BLUEDROID_PM
143 static struct resource dalmore_bluedroid_pm_resources[] = {
144         [0] = {
145                 .name   = "shutdown_gpio",
146                 .start  = TEGRA_GPIO_PQ7,
147                 .end    = TEGRA_GPIO_PQ7,
148                 .flags  = IORESOURCE_IO,
149         },
150         [1] = {
151                 .name = "host_wake",
152                 .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
153         },
154         [2] = {
155                 .name = "gpio_ext_wake",
156                 .start  = TEGRA_GPIO_PEE1,
157                 .end    = TEGRA_GPIO_PEE1,
158                 .flags  = IORESOURCE_IO,
159         },
160         [3] = {
161                 .name = "gpio_host_wake",
162                 .start  = TEGRA_GPIO_PU6,
163                 .end    = TEGRA_GPIO_PU6,
164                 .flags  = IORESOURCE_IO,
165         },
166         [4] = {
167                 .name = "reset_gpio",
168                 .start  = TEGRA_GPIO_PQ6,
169                 .end    = TEGRA_GPIO_PQ6,
170                 .flags  = IORESOURCE_IO,
171         },
172 };
173
174 static struct platform_device dalmore_bluedroid_pm_device = {
175         .name = "bluedroid_pm",
176         .id             = 0,
177         .num_resources  = ARRAY_SIZE(dalmore_bluedroid_pm_resources),
178         .resource       = dalmore_bluedroid_pm_resources,
179 };
180
181 static noinline void __init dalmore_setup_bluedroid_pm(void)
182 {
183         dalmore_bluedroid_pm_resources[1].start =
184                 dalmore_bluedroid_pm_resources[1].end =
185                                 gpio_to_irq(TEGRA_GPIO_PU6);
186         platform_device_register(&dalmore_bluedroid_pm_device);
187 }
188 #endif
189
190 static __initdata struct tegra_clk_init_table dalmore_clk_init_table[] = {
191         /* name         parent          rate            enabled */
192         { "pll_m",      NULL,           0,              false},
193         { "hda",        "pll_p",        108000000,      false},
194         { "hda2codec_2x", "pll_p",      48000000,       false},
195         { "pwm",        "pll_p",        3187500,        false},
196         { "blink",      "clk_32k",      32768,          true},
197         { "i2s1",       "pll_a_out0",   0,              false},
198         { "i2s3",       "pll_a_out0",   0,              false},
199         { "i2s4",       "pll_a_out0",   0,              false},
200         { "spdif_out",  "pll_a_out0",   0,              false},
201         { "d_audio",    "clk_m",        12000000,       false},
202         { "dam0",       "clk_m",        12000000,       false},
203         { "dam1",       "clk_m",        12000000,       false},
204         { "dam2",       "clk_m",        12000000,       false},
205         { "audio1",     "i2s1_sync",    0,              false},
206         { "audio3",     "i2s3_sync",    0,              false},
207         /* Setting vi_sensor-clk to true for validation purpose, will imapact
208          * power, later set to be false.*/
209         { "vi_sensor",  "pll_p",        150000000,      false},
210         { "cilab",      "pll_p",        150000000,      false},
211         { "cilcd",      "pll_p",        150000000,      false},
212         { "cile",       "pll_p",        150000000,      false},
213         { "i2c1",       "pll_p",        3200000,        false},
214         { "i2c2",       "pll_p",        3200000,        false},
215         { "i2c3",       "pll_p",        3200000,        false},
216         { "i2c4",       "pll_p",        3200000,        false},
217         { "i2c5",       "pll_p",        3200000,        false},
218         { NULL,         NULL,           0,              0},
219 };
220
221 static struct tegra_i2c_platform_data dalmore_i2c1_platform_data = {
222         .bus_clk_rate   = 100000,
223         .scl_gpio       = TEGRA_GPIO_I2C1_SCL,
224         .sda_gpio       = TEGRA_GPIO_I2C1_SDA,
225 };
226
227 static struct tegra_i2c_platform_data dalmore_i2c2_platform_data = {
228         .bus_clk_rate   = 100000,
229         .is_clkon_always = true,
230         .scl_gpio       = TEGRA_GPIO_I2C2_SCL,
231         .sda_gpio       = TEGRA_GPIO_I2C2_SDA,
232 };
233
234 static struct tegra_i2c_platform_data dalmore_i2c3_platform_data = {
235         .bus_clk_rate   = 100000,
236         .scl_gpio       = TEGRA_GPIO_I2C3_SCL,
237         .sda_gpio       = TEGRA_GPIO_I2C3_SDA,
238 };
239
240 static struct tegra_i2c_platform_data dalmore_i2c4_platform_data = {
241         .bus_clk_rate   = 10000,
242         .scl_gpio       = TEGRA_GPIO_I2C4_SCL,
243         .sda_gpio       = TEGRA_GPIO_I2C4_SDA,
244 };
245
246 static struct tegra_i2c_platform_data dalmore_i2c5_platform_data = {
247         .bus_clk_rate   = 400000,
248         .scl_gpio       = TEGRA_GPIO_I2C5_SCL,
249         .sda_gpio       = TEGRA_GPIO_I2C5_SDA,
250 };
251
252 static struct i2c_board_info __initdata rt5640_board_info = {
253         I2C_BOARD_INFO("rt5640", 0x1c),
254 };
255
256 static struct pn544_i2c_platform_data nfc_pdata = {
257         .irq_gpio = TEGRA_GPIO_PW2,
258         .ven_gpio = TEGRA_GPIO_PQ3,
259         .firm_gpio = TEGRA_GPIO_PH0,
260 };
261
262 static struct i2c_board_info __initdata nfc_board_info = {
263         I2C_BOARD_INFO("pn544", 0x28),
264         .platform_data = &nfc_pdata,
265 };
266
267 static void dalmore_i2c_init(void)
268 {
269         tegra11_i2c_device1.dev.platform_data = &dalmore_i2c1_platform_data;
270         tegra11_i2c_device2.dev.platform_data = &dalmore_i2c2_platform_data;
271         tegra11_i2c_device3.dev.platform_data = &dalmore_i2c3_platform_data;
272         tegra11_i2c_device4.dev.platform_data = &dalmore_i2c4_platform_data;
273         tegra11_i2c_device5.dev.platform_data = &dalmore_i2c5_platform_data;
274
275         nfc_board_info.irq = gpio_to_irq(TEGRA_GPIO_PW2);
276         i2c_register_board_info(0, &nfc_board_info, 1);
277
278         platform_device_register(&tegra11_i2c_device5);
279         platform_device_register(&tegra11_i2c_device4);
280         platform_device_register(&tegra11_i2c_device3);
281         platform_device_register(&tegra11_i2c_device2);
282         platform_device_register(&tegra11_i2c_device1);
283
284         i2c_register_board_info(0, &rt5640_board_info, 1);
285 }
286
287 static struct platform_device *dalmore_uart_devices[] __initdata = {
288         &tegra_uarta_device,
289         &tegra_uartb_device,
290         &tegra_uartc_device,
291         &tegra_uartd_device,
292 };
293 static struct uart_clk_parent uart_parent_clk[] = {
294         [0] = {.name = "clk_m"},
295         [1] = {.name = "pll_p"},
296 #ifndef CONFIG_TEGRA_PLLM_RESTRICTED
297         [2] = {.name = "pll_m"},
298 #endif
299 };
300
301 static struct tegra_uart_platform_data dalmore_uart_pdata;
302 static struct tegra_uart_platform_data dalmore_loopback_uart_pdata;
303
304 static void __init uart_debug_init(void)
305 {
306         int debug_port_id;
307
308         debug_port_id = uart_console_debug_init(3);
309         if (debug_port_id < 0)
310                 return;
311
312         dalmore_uart_devices[debug_port_id] = uart_console_debug_device;
313 }
314
315 static void __init dalmore_uart_init(void)
316 {
317         struct clk *c;
318         int i;
319
320         for (i = 0; i < ARRAY_SIZE(uart_parent_clk); ++i) {
321                 c = tegra_get_clock_by_name(uart_parent_clk[i].name);
322                 if (IS_ERR_OR_NULL(c)) {
323                         pr_err("Not able to get the clock for %s\n",
324                                                 uart_parent_clk[i].name);
325                         continue;
326                 }
327                 uart_parent_clk[i].parent_clk = c;
328                 uart_parent_clk[i].fixed_clk_rate = clk_get_rate(c);
329         }
330         dalmore_uart_pdata.parent_clk_list = uart_parent_clk;
331         dalmore_uart_pdata.parent_clk_count = ARRAY_SIZE(uart_parent_clk);
332         dalmore_loopback_uart_pdata.parent_clk_list = uart_parent_clk;
333         dalmore_loopback_uart_pdata.parent_clk_count =
334                                                 ARRAY_SIZE(uart_parent_clk);
335         dalmore_loopback_uart_pdata.is_loopback = true;
336         tegra_uarta_device.dev.platform_data = &dalmore_uart_pdata;
337         tegra_uartb_device.dev.platform_data = &dalmore_uart_pdata;
338         tegra_uartc_device.dev.platform_data = &dalmore_uart_pdata;
339         tegra_uartd_device.dev.platform_data = &dalmore_uart_pdata;
340
341         /* Register low speed only if it is selected */
342         if (!is_tegra_debug_uartport_hs())
343                 uart_debug_init();
344
345         platform_add_devices(dalmore_uart_devices,
346                                 ARRAY_SIZE(dalmore_uart_devices));
347 }
348
349 static struct resource tegra_rtc_resources[] = {
350         [0] = {
351                 .start = TEGRA_RTC_BASE,
352                 .end = TEGRA_RTC_BASE + TEGRA_RTC_SIZE - 1,
353                 .flags = IORESOURCE_MEM,
354         },
355         [1] = {
356                 .start = INT_RTC,
357                 .end = INT_RTC,
358                 .flags = IORESOURCE_IRQ,
359         },
360 };
361
362 static struct platform_device tegra_rtc_device = {
363         .name = "tegra_rtc",
364         .id   = -1,
365         .resource = tegra_rtc_resources,
366         .num_resources = ARRAY_SIZE(tegra_rtc_resources),
367 };
368
369 static struct tegra_asoc_platform_data dalmore_audio_pdata = {
370         .gpio_spkr_en           = TEGRA_GPIO_SPKR_EN,
371         .gpio_hp_det            = TEGRA_GPIO_HP_DET,
372         .gpio_hp_mute           = -1,
373         .gpio_int_mic_en        = TEGRA_GPIO_INT_MIC_EN,
374         .gpio_ext_mic_en        = TEGRA_GPIO_EXT_MIC_EN,
375         .gpio_ldo1_en           = TEGRA_GPIO_LDO1_EN,
376         .gpio_codec1 = TEGRA_GPIO_CODEC1_EN,
377         .gpio_codec2 = TEGRA_GPIO_CODEC2_EN,
378         .gpio_codec3 = TEGRA_GPIO_CODEC3_EN,
379         .i2s_param[HIFI_CODEC]  = {
380                 .audio_port_id  = 1,
381                 .is_i2s_master  = 1,
382                 .i2s_mode       = TEGRA_DAIFMT_I2S,
383         },
384         .i2s_param[BT_SCO]      = {
385                 .audio_port_id  = 3,
386                 .is_i2s_master  = 1,
387                 .i2s_mode       = TEGRA_DAIFMT_DSP_A,
388         },
389 };
390
391 static struct platform_device dalmore_audio_device = {
392         .name   = "tegra-snd-rt5640",
393         .id     = 0,
394         .dev    = {
395                 .platform_data = &dalmore_audio_pdata,
396         },
397 };
398
399 #ifndef CONFIG_USE_OF
400 static struct platform_device tegra_camera = {
401         .name = "tegra_camera",
402         .id = -1,
403 };
404 #endif
405
406 static struct platform_device *dalmore_devices[] __initdata = {
407         &tegra_pmu_device,
408         &tegra_rtc_device,
409         &tegra_udc_device,
410 #if defined(CONFIG_TEGRA_AVP)
411         &tegra_avp_device,
412 #endif
413 #ifndef CONFIG_USE_OF
414         &tegra_camera,
415 #endif
416 #if defined(CONFIG_CRYPTO_DEV_TEGRA_SE)
417         &tegra11_se_device,
418 #endif
419         &tegra_ahub_device,
420         &tegra_dam_device0,
421         &tegra_dam_device1,
422         &tegra_dam_device2,
423         &tegra_i2s_device1,
424         &tegra_i2s_device3,
425         &tegra_i2s_device4,
426         &tegra_spdif_device,
427         &spdif_dit_device,
428         &bluetooth_dit_device,
429         &dalmore_audio_device,
430         &tegra_hda_device,
431 #if defined(CONFIG_CRYPTO_DEV_TEGRA_AES)
432         &tegra_aes_device,
433 #endif
434 };
435
436 #ifdef CONFIG_USB_SUPPORT
437 static struct tegra_usb_platform_data tegra_udc_pdata = {
438         .port_otg = true,
439         .has_hostpc = true,
440         .phy_intf = TEGRA_USB_PHY_INTF_UTMI,
441         .op_mode = TEGRA_USB_OPMODE_DEVICE,
442         .u_data.dev = {
443                 .vbus_pmu_irq = 0,
444                 .vbus_gpio = -1,
445                 .charging_supported = false,
446                 .remote_wakeup_supported = false,
447         },
448         .u_cfg.utmi = {
449                 .hssync_start_delay = 0,
450                 .elastic_limit = 16,
451                 .idle_wait_delay = 17,
452                 .term_range_adj = 6,
453                 .xcvr_setup = 8,
454                 .xcvr_lsfslew = 2,
455                 .xcvr_lsrslew = 2,
456                 .xcvr_setup_offset = 0,
457                 .xcvr_use_fuses = 1,
458         },
459 };
460
461 static struct tegra_usb_platform_data tegra_ehci1_utmi_pdata = {
462         .port_otg = true,
463         .has_hostpc = true,
464         .unaligned_dma_buf_supported = false,
465         .phy_intf = TEGRA_USB_PHY_INTF_UTMI,
466         .op_mode = TEGRA_USB_OPMODE_HOST,
467         .u_data.host = {
468                 .vbus_gpio = -1,
469                 .hot_plug = false,
470                 .remote_wakeup_supported = true,
471                 .power_off_on_suspend = true,
472         },
473         .u_cfg.utmi = {
474                 .hssync_start_delay = 0,
475                 .elastic_limit = 16,
476                 .idle_wait_delay = 17,
477                 .term_range_adj = 6,
478                 .xcvr_setup = 15,
479                 .xcvr_lsfslew = 2,
480                 .xcvr_lsrslew = 2,
481                 .xcvr_setup_offset = 0,
482                 .xcvr_use_fuses = 1,
483                 .vbus_oc_map = 0x4,
484         },
485 };
486
487 static struct tegra_usb_platform_data tegra_ehci3_utmi_pdata = {
488         .port_otg = false,
489         .has_hostpc = true,
490         .unaligned_dma_buf_supported = false,
491         .phy_intf = TEGRA_USB_PHY_INTF_UTMI,
492         .op_mode = TEGRA_USB_OPMODE_HOST,
493         .u_data.host = {
494                 .vbus_gpio = -1,
495                 .hot_plug = false,
496                 .remote_wakeup_supported = true,
497                 .power_off_on_suspend = true,
498         },
499         .u_cfg.utmi = {
500         .hssync_start_delay = 0,
501                 .elastic_limit = 16,
502                 .idle_wait_delay = 17,
503                 .term_range_adj = 6,
504                 .xcvr_setup = 8,
505                 .xcvr_lsfslew = 2,
506                 .xcvr_lsrslew = 2,
507                 .xcvr_setup_offset = 0,
508                 .xcvr_use_fuses = 1,
509                 .vbus_oc_map = 0x5,
510         },
511 };
512
513 static struct tegra_usb_otg_data tegra_otg_pdata = {
514         .ehci_device = &tegra_ehci1_device,
515         .ehci_pdata = &tegra_ehci1_utmi_pdata,
516 };
517
518 static void dalmore_usb_init(void)
519 {
520         int usb_port_owner_info = tegra_get_usb_port_owner_info();
521
522         /* Set USB wake sources for dalmore */
523         tegra_set_usb_wake_source();
524
525         if (!(usb_port_owner_info & UTMI1_PORT_OWNER_XUSB)) {
526                 tegra_otg_device.dev.platform_data = &tegra_otg_pdata;
527                 platform_device_register(&tegra_otg_device);
528                 /* Setup the udc platform data */
529                 tegra_udc_device.dev.platform_data = &tegra_udc_pdata;
530         }
531
532         if (!(usb_port_owner_info & UTMI2_PORT_OWNER_XUSB)) {
533                 tegra_ehci3_device.dev.platform_data = &tegra_ehci3_utmi_pdata;
534                 platform_device_register(&tegra_ehci3_device);
535         }
536 }
537
538 static struct tegra_xusb_pad_data xusb_padctl_data = {
539         .pad_mux = 0x4,
540         .port_cap = 0x10,
541         .snps_oc_map = 0x1fc,
542         .usb2_oc_map = 0x2f,
543         .ss_port_map = 0x1,
544         .oc_det = 0xb000,
545         .rx_wander = 0xf0,
546         .rx_eq = 0x307000,
547         .cdr_cntl = 0x26000000,
548         .dfe_cntl = 0x002008EE,
549         .otg_pad0_ctl0 = 0xffffffff,
550         .hs_slew = 0x30,
551         .otg_pad0_ctl1 = 0x0,
552         .otg_pad1_ctl0 = 0xffc7ffff,
553         .otg_pad1_ctl1 = 0x7,
554         .bias_pad_ctl0 = 0,
555         .hsic_pad0_ctl0 = 0xffff00ff,
556         .hsic_pad0_ctl1 = 0xffff00ff,
557         .pmc_value = 0xfff0ffff,
558 };
559
560 static void dalmore_xusb_init(void)
561 {
562         int usb_port_owner_info = tegra_get_usb_port_owner_info();
563
564         if (usb_port_owner_info & UTMI2_PORT_OWNER_XUSB) {
565                 u32 usb_calib0 = tegra_fuse_readl(FUSE_SKU_USB_CALIB_0);
566
567                 /*
568                  * read from usb_calib0 and pass to driver
569                  * set HS_CURR_LEVEL = usb_calib0[5:0]
570                  * set TERM_RANGE_ADJ = usb_calib0[10:7]
571                  * set HS_IREF_CAP = usb_calib0[14:13]
572                  * set HS_SQUELCH_LEVEL = usb_calib0[12:11]
573                  */
574
575                 xusb_padctl_data.hs_curr_level = (usb_calib0 >> 0) & 0x3f;
576                 xusb_padctl_data.hs_iref_cap = (usb_calib0 >> 13) & 0x3;
577                 xusb_padctl_data.hs_term_range_adj = (usb_calib0 >> 7) & 0xf;
578                 xusb_padctl_data.hs_squelch_level = (usb_calib0 >> 11) & 0x3;
579
580                 tegra_xhci_device.dev.platform_data = &xusb_padctl_data;
581                 platform_device_register(&tegra_xhci_device);
582         }
583 }
584
585 static struct gpio modem_gpios[] = { /* Nemo modem */
586         {MODEM_EN, GPIOF_OUT_INIT_HIGH, "MODEM EN"},
587         {MDM_RST, GPIOF_OUT_INIT_LOW, "MODEM RESET"},
588 };
589
590 static struct tegra_usb_platform_data tegra_ehci2_hsic_baseband_pdata = {
591         .port_otg = false,
592         .has_hostpc = true,
593         .unaligned_dma_buf_supported = false,
594         .phy_intf = TEGRA_USB_PHY_INTF_HSIC,
595         .op_mode = TEGRA_USB_OPMODE_HOST,
596         .u_data.host = {
597                 .vbus_gpio = -1,
598                 .hot_plug = false,
599                 .remote_wakeup_supported = true,
600                 .power_off_on_suspend = true,
601         },
602 };
603
604 static int baseband_init(void)
605 {
606         int ret;
607
608         ret = gpio_request_array(modem_gpios, ARRAY_SIZE(modem_gpios));
609         if (ret) {
610                 pr_warn("%s:gpio request failed\n", __func__);
611                 return ret;
612         }
613
614         /* enable pull-down for MDM_COLD_BOOT */
615         tegra_pinmux_set_pullupdown(TEGRA_PINGROUP_KB_COL5,
616                                     TEGRA_PUPD_PULL_DOWN);
617
618         /* export GPIO for user space access through sysfs */
619         gpio_export(MDM_RST, false);
620
621         return 0;
622 }
623
624 static const struct tegra_modem_operations baseband_operations = {
625         .init = baseband_init,
626 };
627
628 static struct tegra_usb_modem_power_platform_data baseband_pdata = {
629         .ops = &baseband_operations,
630         .wake_gpio = -1,
631         .boot_gpio = MDM_COLDBOOT,
632         .boot_irq_flags = IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
633         .autosuspend_delay = 2000,
634         .short_autosuspend_delay = 50,
635         .tegra_ehci_device = &tegra_ehci2_device,
636         .tegra_ehci_pdata = &tegra_ehci2_hsic_baseband_pdata,
637 };
638
639 static struct platform_device icera_nemo_device = {
640         .name = "tegra_usb_modem_power",
641         .id = -1,
642         .dev = {
643                 .platform_data = &baseband_pdata,
644         },
645 };
646
647 static void dalmore_modem_init(void)
648 {
649         int modem_id = tegra_get_modem_id();
650         int usb_port_owner_info = tegra_get_usb_port_owner_info();
651         switch (modem_id) {
652         case TEGRA_BB_NEMO: /* on board i500 HSIC */
653                 if (!(usb_port_owner_info & HSIC1_PORT_OWNER_XUSB))
654                         platform_device_register(&icera_nemo_device);
655                 break;
656         }
657 }
658
659 #else
660 static void dalmore_usb_init(void) { }
661 static void dalmore_modem_init(void) { }
662 static void dalmore_xusb_init(void) { }
663 #endif
664
665 static void dalmore_audio_init(void)
666 {
667         dalmore_audio_pdata.codec_name = "rt5640.0-001c";
668         dalmore_audio_pdata.codec_dai_name = "rt5640-aif1";
669 }
670
671
672 static struct platform_device *dalmore_spi_devices[] __initdata = {
673         &tegra11_spi_device4,
674 };
675
676 struct spi_clk_parent spi_parent_clk_dalmore[] = {
677         [0] = {.name = "pll_p"},
678 #ifndef CONFIG_TEGRA_PLLM_RESTRICTED
679         [1] = {.name = "pll_m"},
680         [2] = {.name = "clk_m"},
681 #else
682         [1] = {.name = "clk_m"},
683 #endif
684 };
685
686 static struct tegra_spi_platform_data dalmore_spi_pdata = {
687         .is_dma_based           = false,
688         .max_dma_buffer         = 16 * 1024,
689         .is_clkon_always        = false,
690         .max_rate               = 25000000,
691 };
692
693 static void __init dalmore_spi_init(void)
694 {
695         int i;
696         struct clk *c;
697
698         for (i = 0; i < ARRAY_SIZE(spi_parent_clk_dalmore); ++i) {
699                 c = tegra_get_clock_by_name(spi_parent_clk_dalmore[i].name);
700                 if (IS_ERR_OR_NULL(c)) {
701                         pr_err("Not able to get the clock for %s\n",
702                                                 spi_parent_clk_dalmore[i].name);
703                         continue;
704                 }
705                 spi_parent_clk_dalmore[i].parent_clk = c;
706                 spi_parent_clk_dalmore[i].fixed_clk_rate = clk_get_rate(c);
707         }
708         dalmore_spi_pdata.parent_clk_list = spi_parent_clk_dalmore;
709         dalmore_spi_pdata.parent_clk_count = ARRAY_SIZE(spi_parent_clk_dalmore);
710         tegra11_spi_device4.dev.platform_data = &dalmore_spi_pdata;
711         platform_add_devices(dalmore_spi_devices,
712                                 ARRAY_SIZE(dalmore_spi_devices));
713 }
714
715 static __initdata struct tegra_clk_init_table touch_clk_init_table[] = {
716         /* name         parent          rate            enabled */
717         { "extern2",    "pll_p",        41000000,       false},
718         { "clk_out_2",  "extern2",      40800000,       false},
719         { NULL,         NULL,           0,              0},
720 };
721
722 struct rm_spi_ts_platform_data rm31080ts_dalmore_data = {
723         .gpio_reset = 0,
724         .config = 0,
725         .platform_id = RM_PLATFORM_D010,
726         .name_of_clock = "clk_out_2",
727 };
728
729 static struct tegra_spi_device_controller_data dev_cdata = {
730         .rx_clk_tap_delay = 0,
731         .tx_clk_tap_delay = 16,
732 };
733
734 struct spi_board_info rm31080a_dalmore_spi_board[1] = {
735         {
736          .modalias = "rm_ts_spidev",
737          .bus_num = 3,
738          .chip_select = 2,
739          .max_speed_hz = 12 * 1000 * 1000,
740          .mode = SPI_MODE_0,
741          .controller_data = &dev_cdata,
742          .platform_data = &rm31080ts_dalmore_data,
743          },
744 };
745
746 static int __init dalmore_touch_init(void)
747 {
748         tegra_clk_init_from_table(touch_clk_init_table);
749         clk_enable(tegra_get_clock_by_name("clk_out_2"));
750         if (display_board_info.board_id == BOARD_E1582)
751                 rm31080ts_dalmore_data.platform_id = RM_PLATFORM_P005;
752         else
753                 rm31080ts_dalmore_data.platform_id = RM_PLATFORM_D010;
754         mdelay(20);
755         rm31080a_dalmore_spi_board[0].irq = gpio_to_irq(TOUCH_GPIO_IRQ_RAYDIUM_SPI);
756         touch_init_raydium(TOUCH_GPIO_IRQ_RAYDIUM_SPI,
757                                 TOUCH_GPIO_RST_RAYDIUM_SPI,
758                                 &rm31080ts_dalmore_data,
759                                 &rm31080a_dalmore_spi_board[0],
760                                 ARRAY_SIZE(rm31080a_dalmore_spi_board));
761         return 0;
762 }
763
764 #ifdef CONFIG_EDP_FRAMEWORK
765 static struct edp_manager battery_edp_manager = {
766         .name = "battery",
767         .imax = 2500
768 };
769
770 static void __init dalmore_battery_edp_init(void)
771 {
772         struct edp_governor *g;
773         int r;
774
775         r = edp_register_manager(&battery_edp_manager);
776         if (r)
777                 goto err_ret;
778
779         /* start with priority governor */
780         g = edp_get_governor("priority");
781         if (!g) {
782                 r = -EFAULT;
783                 goto err_ret;
784         }
785
786         r = edp_set_governor(&battery_edp_manager, g);
787         if (r)
788                 goto err_ret;
789
790         return;
791
792 err_ret:
793         pr_err("Battery EDP init failed with error %d\n", r);
794         WARN_ON(1);
795 }
796 #else
797 static inline void dalmore_battery_edp_init(void) {}
798 #endif
799
800 #ifdef CONFIG_USE_OF
801 struct of_dev_auxdata dalmore_auxdata_lookup[] __initdata = {
802         OF_DEV_AUXDATA("nvidia,tegra114-sdhci", 0x78000600, "sdhci-tegra.3",
803                                 NULL),
804         OF_DEV_AUXDATA("nvidia,tegra114-sdhci", 0x78000400, "sdhci-tegra.2",
805                                 NULL),
806         OF_DEV_AUXDATA("nvidia,tegra114-sdhci", 0x78000000, "sdhci-tegra.0",
807                                 &dalmore_tegra_sdhci_platform_data0),
808         OF_DEV_AUXDATA("nvidia,tegra114-camera", 0x0, "tegra_camera",
809                                 NULL),
810         OF_DEV_AUXDATA("nvidia,tegra114-host1x", TEGRA_HOST1X_BASE, "host1x",
811                                 NULL),
812         OF_DEV_AUXDATA("nvidia,tegra114-gr3d", TEGRA_GR3D_BASE, "gr3d",
813                                 NULL),
814         OF_DEV_AUXDATA("nvidia,tegra114-gr2d", TEGRA_GR2D_BASE, "gr2d",
815                                 NULL),
816         OF_DEV_AUXDATA("nvidia,tegra114-msenc", TEGRA_MSENC_BASE, "msenc",
817                                 NULL),
818         OF_DEV_AUXDATA("nvidia,tegra114-vi", TEGRA_VI_BASE, "vi",
819                                 NULL),
820         OF_DEV_AUXDATA("nvidia,tegra114-isp", TEGRA_ISP_BASE, "isp",
821                                 NULL),
822         OF_DEV_AUXDATA("nvidia,tegra114-tsec", TEGRA_TSEC_BASE, "tsec",
823                                 NULL),
824         {}
825 };
826 #endif
827
828 static void __init tegra_dalmore_early_init(void)
829 {
830         dalmore_battery_edp_init();
831         tegra_clk_init_from_table(dalmore_clk_init_table);
832         tegra_clk_vefify_parents();
833         tegra_smmu_init();
834         tegra_soc_device_init("dalmore");
835 }
836
837 static void __init tegra_dalmore_late_init(void)
838 {
839         platform_device_register(&tegra_pinmux_device);
840         dalmore_pinmux_init();
841         dalmore_i2c_init();
842         dalmore_spi_init();
843         dalmore_usb_init();
844         dalmore_xusb_init();
845         dalmore_uart_init();
846         dalmore_audio_init();
847         platform_add_devices(dalmore_devices, ARRAY_SIZE(dalmore_devices));
848         //tegra_ram_console_debug_init();
849         tegra_io_dpd_init();
850         dalmore_regulator_init();
851         dalmore_sdhci_init();
852         dalmore_suspend_init();
853         dalmore_emc_init();
854         dalmore_edp_init();
855         isomgr_init();
856         dalmore_touch_init();
857         if (board_info.board_id == BOARD_E1582)
858                 roth_panel_init();
859         else
860                 dalmore_panel_init();
861         dalmore_kbc_init();
862         dalmore_pmon_init();
863 #ifdef CONFIG_BT_BLUESLEEP
864         dalmore_setup_bluesleep();
865         dalmore_setup_bt_rfkill();
866 #elif defined CONFIG_BLUEDROID_PM
867         dalmore_setup_bluedroid_pm();
868 #endif
869         tegra_release_bootloader_fb();
870         dalmore_modem_init();
871 #ifdef CONFIG_TEGRA_WDT_RECOVERY
872         tegra_wdt_recovery_init();
873 #endif
874         tegra_serial_debug_init(TEGRA_UARTD_BASE, INT_WDT_CPU, NULL, -1, -1);
875         dalmore_sensors_init();
876         dalmore_soctherm_init();
877         tegra_register_fuse();
878 }
879
880 static void __init dalmore_ramconsole_reserve(unsigned long size)
881 {
882         tegra_ram_console_debug_reserve(SZ_1M);
883 }
884
885 static void __init tegra_dalmore_dt_init(void)
886 {
887         tegra_get_board_info(&board_info);
888         tegra_get_display_board_info(&display_board_info);
889
890         tegra_dalmore_early_init();
891
892         of_platform_populate(NULL,
893                 of_default_bus_match_table, dalmore_auxdata_lookup,
894                 &platform_bus);
895
896         tegra_dalmore_late_init();
897 }
898
899 static void __init tegra_dalmore_reserve(void)
900 {
901 #if defined(CONFIG_NVMAP_CONVERT_CARVEOUT_TO_IOVMM)
902         /* 1920*1200*4*2 = 18432000 bytes */
903         tegra_reserve(0, SZ_16M + SZ_2M, SZ_16M);
904 #else
905         tegra_reserve(SZ_128M, SZ_16M + SZ_2M, SZ_4M);
906 #endif
907         dalmore_ramconsole_reserve(SZ_1M);
908 }
909
910 static const char * const dalmore_dt_board_compat[] = {
911         "nvidia,dalmore",
912         NULL
913 };
914
915 MACHINE_START(DALMORE, "dalmore")
916         .atag_offset    = 0x100,
917         .smp            = smp_ops(tegra_smp_ops),
918         .map_io         = tegra_map_common_io,
919         .reserve        = tegra_dalmore_reserve,
920         .init_early     = tegra11x_init_early,
921         .init_irq       = tegra_dt_init_irq,
922         .handle_irq     = gic_handle_irq,
923         .timer          = &tegra_timer,
924         .init_machine   = tegra_dalmore_dt_init,
925         .restart        = tegra_assert_system_reset,
926         .dt_compat      = dalmore_dt_board_compat,
927 MACHINE_END