arch: arm: Enable SPDIF driver for Tegra30
[linux-2.6.git] / arch / arm / mach-tegra / board-cardhu.c
1 /*
2  * arch/arm/mach-tegra/board-cardhu.c
3  *
4  * Copyright (c) 2011, NVIDIA Corporation.
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 as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19  */
20
21 #include <linux/kernel.h>
22 #include <linux/init.h>
23 #include <linux/slab.h>
24 #include <linux/ctype.h>
25 #include <linux/platform_device.h>
26 #include <linux/clk.h>
27 #include <linux/serial_8250.h>
28 #include <linux/i2c.h>
29 #include <linux/i2c/panjit_ts.h>
30 #include <linux/dma-mapping.h>
31 #include <linux/delay.h>
32 #include <linux/i2c-tegra.h>
33 #include <linux/gpio.h>
34 #include <linux/input.h>
35 #include <linux/platform_data/tegra_usb.h>
36 #include <linux/spi/spi.h>
37 #include <linux/i2c/atmel_mxt_ts.h>
38 #include <linux/tegra_uart.h>
39 #include <linux/spi-tegra.h>
40
41 #include <sound/wm8903.h>
42
43 #include <mach/clk.h>
44 #include <mach/iomap.h>
45 #include <mach/irqs.h>
46 #include <mach/pinmux.h>
47 #include <mach/iomap.h>
48 #include <mach/io.h>
49 #include <mach/i2s.h>
50 #include <mach/tegra_wm8903_pdata.h>
51 #include <asm/mach-types.h>
52 #include <asm/mach/arch.h>
53 #include <mach/usb_phy.h>
54
55 #include "board.h"
56 #include "clock.h"
57 #include "board-cardhu.h"
58 #include "devices.h"
59 #include "gpio-names.h"
60 #include "fuse.h"
61 #include "pm.h"
62 #include "baseband-xmm-power.h"
63
64
65 /* !!!TODO: Change for cardhu (Taken from Ventana) */
66 static struct tegra_utmip_config utmi_phy_config[] = {
67         [0] = {
68                         .hssync_start_delay = 0,
69                         .idle_wait_delay = 17,
70                         .elastic_limit = 16,
71                         .term_range_adj = 6,
72                         .xcvr_setup = 15,
73                         .xcvr_setup_offset = 0,
74                         .xcvr_use_fuses = 1,
75                         .xcvr_lsfslew = 2,
76                         .xcvr_lsrslew = 2,
77         },
78         [1] = {
79                         .hssync_start_delay = 0,
80                         .idle_wait_delay = 17,
81                         .elastic_limit = 16,
82                         .term_range_adj = 6,
83                         .xcvr_setup = 15,
84                         .xcvr_setup_offset = 0,
85                         .xcvr_use_fuses = 1,
86                         .xcvr_lsfslew = 2,
87                         .xcvr_lsrslew = 2,
88         },
89         [2] = {
90                         .hssync_start_delay = 0,
91                         .idle_wait_delay = 17,
92                         .elastic_limit = 16,
93                         .term_range_adj = 6,
94                         .xcvr_setup = 8,
95                         .xcvr_setup_offset = 0,
96                         .xcvr_use_fuses = 1,
97                         .xcvr_lsfslew = 2,
98                         .xcvr_lsrslew = 2,
99         },
100 };
101
102 #ifdef CONFIG_BCM4329_RFKILL
103 static struct resource cardhu_bcm4329_rfkill_resources[] = {
104         {
105                 .name   = "bcm4329_nshutdown_gpio",
106                 .start  = TEGRA_GPIO_PU0,
107                 .end    = TEGRA_GPIO_PU0,
108                 .flags  = IORESOURCE_IO,
109         },
110 };
111
112 static struct platform_device cardhu_bcm4329_rfkill_device = {
113         .name = "bcm4329_rfkill",
114         .id             = -1,
115         .num_resources  = ARRAY_SIZE(cardhu_bcm4329_rfkill_resources),
116         .resource       = cardhu_bcm4329_rfkill_resources,
117 };
118
119 static noinline void __init cardhu_bt_rfkill(void)
120 {
121         platform_device_register(&cardhu_bcm4329_rfkill_device);
122
123         return;
124 }
125 #else
126 static inline void cardhu_bt_rfkill(void) { }
127 #endif
128
129 #ifdef CONFIG_BT_BLUESLEEP
130 static noinline void __init tegra_setup_bluesleep(void)
131 {
132         struct platform_device *pdev = NULL;
133         struct resource *res;
134
135         pdev = platform_device_alloc("bluesleep", 0);
136         if (!pdev) {
137                 pr_err("unable to allocate platform device for bluesleep");
138                 return;
139         }
140
141         res = kzalloc(sizeof(struct resource) * 3, GFP_KERNEL);
142         if (!res) {
143                 pr_err("unable to allocate resource for bluesleep\n");
144                 goto err_free_dev;
145         }
146
147         res[0].name   = "gpio_host_wake";
148         res[0].start  = TEGRA_GPIO_PU6;
149         res[0].end    = TEGRA_GPIO_PU6;
150         res[0].flags  = IORESOURCE_IO;
151
152         res[1].name   = "gpio_ext_wake";
153         res[1].start  = TEGRA_GPIO_PU1;
154         res[1].end    = TEGRA_GPIO_PU1;
155         res[1].flags  = IORESOURCE_IO;
156
157         res[2].name   = "host_wake";
158         res[2].start  = gpio_to_irq(TEGRA_GPIO_PU6);
159         res[2].end    = gpio_to_irq(TEGRA_GPIO_PU6);
160         res[2].flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE ;
161
162         if (platform_device_add_resources(pdev, res, 3)) {
163                 pr_err("unable to add resources to bluesleep device\n");
164                 goto err_free_res;
165         }
166
167         if (platform_device_add(pdev)) {
168                 pr_err("unable to add bluesleep device\n");
169                 goto err_free_res;
170         }
171         tegra_gpio_enable(TEGRA_GPIO_PU6);
172         tegra_gpio_enable(TEGRA_GPIO_PU1);
173
174 return;
175
176 err_free_res:
177         kfree(res);
178 err_free_dev:
179         platform_device_put(pdev);
180         return;
181 }
182 #else
183 static inline void tegra_setup_bluesleep(void) { }
184 #endif
185
186 static __initdata struct tegra_clk_init_table cardhu_clk_init_table[] = {
187         /* name         parent          rate            enabled */
188         { "pll_m",      NULL,           0,              true},
189         { "hda",        "pll_p",        108000000,      false},
190         { "hda2codec_2x","pll_p",       48000000,       false},
191         { "pwm",        "pll_p",        3187500,        false},
192         { "blink",      "clk_32k",      32768,          true},
193         { "i2s1",       "pll_a_out0",   0,              false},
194         { "spdif_out",  "pll_a_out0",   0,              false},
195         { "vi_sensor",  "pll_p",        150000000,      false},
196         { NULL,         NULL,           0,              0},
197 };
198
199 static struct tegra_i2c_platform_data cardhu_i2c1_platform_data = {
200         .adapter_nr     = 0,
201         .bus_count      = 1,
202         .bus_clk_rate   = { 100000, 0 },
203         .scl_gpio               = {TEGRA_GPIO_PC4, 0},
204         .sda_gpio               = {TEGRA_GPIO_PC5, 0},
205         .arb_recovery = arb_lost_recovery,
206 };
207
208 static struct tegra_i2c_platform_data cardhu_i2c2_platform_data = {
209         .adapter_nr     = 1,
210         .bus_count      = 1,
211         .bus_clk_rate   = { 100000, 0 },
212         .is_clkon_always = true,
213         .scl_gpio               = {TEGRA_GPIO_PT5, 0},
214         .sda_gpio               = {TEGRA_GPIO_PT6, 0},
215         .arb_recovery = arb_lost_recovery,
216 };
217
218 static struct tegra_i2c_platform_data cardhu_i2c3_platform_data = {
219         .adapter_nr     = 2,
220         .bus_count      = 1,
221         .bus_clk_rate   = { 100000, 0 },
222         .scl_gpio               = {TEGRA_GPIO_PBB1, 0},
223         .sda_gpio               = {TEGRA_GPIO_PBB2, 0},
224         .arb_recovery = arb_lost_recovery,
225 };
226
227 static struct tegra_i2c_platform_data cardhu_i2c4_platform_data = {
228         .adapter_nr     = 3,
229         .bus_count      = 1,
230         .bus_clk_rate   = { 100000, 0 },
231         .scl_gpio               = {TEGRA_GPIO_PV4, 0},
232         .sda_gpio               = {TEGRA_GPIO_PV5, 0},
233         .arb_recovery = arb_lost_recovery,
234 };
235
236 static struct tegra_i2c_platform_data cardhu_i2c5_platform_data = {
237         .adapter_nr     = 4,
238         .bus_count      = 1,
239         .bus_clk_rate   = { 400000, 0 },
240         .scl_gpio               = {TEGRA_GPIO_PZ6, 0},
241         .sda_gpio               = {TEGRA_GPIO_PZ7, 0},
242         .arb_recovery = arb_lost_recovery,
243 };
244
245
246 #if 0
247 struct tegra_wired_jack_conf audio_wr_jack_conf = {
248         .hp_det_n = TEGRA_GPIO_PW2,
249         .en_mic_ext = TEGRA_GPIO_PX1,
250         .en_mic_int = TEGRA_GPIO_PX0,
251 };
252 #endif
253
254 static struct wm8903_platform_data cardhu_wm8903_pdata = {
255         .irq_active_low = 0,
256         .micdet_cfg = 0,
257         .micdet_delay = 100,
258         .gpio_base = CARDHU_GPIO_WM8903(0),
259         .gpio_cfg = {
260                 WM8903_GPIO_NO_CONFIG,
261                 WM8903_GPIO_NO_CONFIG,
262                 0,
263                 WM8903_GPIO_NO_CONFIG,
264                 WM8903_GPIO_NO_CONFIG,
265         },
266 };
267
268 static struct i2c_board_info __initdata wm8903_board_info = {
269         I2C_BOARD_INFO("wm8903", 0x1a),
270         .platform_data = &cardhu_wm8903_pdata,
271         .irq = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_CDC_IRQ),
272 };
273
274 static void cardhu_i2c_init(void)
275 {
276         tegra_i2c_device1.dev.platform_data = &cardhu_i2c1_platform_data;
277         tegra_i2c_device2.dev.platform_data = &cardhu_i2c2_platform_data;
278         tegra_i2c_device3.dev.platform_data = &cardhu_i2c3_platform_data;
279         tegra_i2c_device4.dev.platform_data = &cardhu_i2c4_platform_data;
280         tegra_i2c_device5.dev.platform_data = &cardhu_i2c5_platform_data;
281
282         platform_device_register(&tegra_i2c_device5);
283         platform_device_register(&tegra_i2c_device4);
284         platform_device_register(&tegra_i2c_device3);
285         platform_device_register(&tegra_i2c_device2);
286         platform_device_register(&tegra_i2c_device1);
287
288         i2c_register_board_info(4, &wm8903_board_info, 1);
289 }
290
291 static struct platform_device *cardhu_uart_devices[] __initdata = {
292         &tegra_uarta_device,
293         &tegra_uartb_device,
294         &tegra_uartc_device,
295         &tegra_uartd_device,
296         &tegra_uarte_device,
297 };
298 static struct uart_clk_parent uart_parent_clk[] = {
299         [0] = {.name = "clk_m"},
300         [1] = {.name = "pll_p"},
301         [2] = {.name = "pll_m"},
302 };
303
304 static struct tegra_uart_platform_data cardhu_uart_pdata;
305
306 static void __init uart_debug_init(void)
307 {
308         struct board_info board_info;
309
310         tegra_get_board_info(&board_info);
311         /* UARTB is debug port
312          *       for SLT - E1186/E1187/PM269
313          *       for E1256
314          */
315         if (((board_info.sku & SKU_SLT_ULPI_SUPPORT) &&
316                 ((board_info.board_id == BOARD_E1186) ||
317                 (board_info.board_id == BOARD_E1187) ||
318                 (board_info.board_id == BOARD_PM269))) ||
319                 (board_info.board_id == BOARD_E1256)) {
320                         /* UARTB is the debug port. */
321                         pr_info("Selecting UARTB as the debug console\n");
322                         cardhu_uart_devices[1] = &debug_uartb_device;
323                         debug_uart_clk =  clk_get_sys("serial8250.0", "uartb");
324                         debug_uart_port_base = ((struct plat_serial8250_port *)(
325                                 debug_uartb_device.dev.platform_data))->mapbase;
326                         return;
327         }
328         /* UARTA is the debug port. */
329         pr_info("Selecting UARTA as the debug console\n");
330         cardhu_uart_devices[0] = &debug_uarta_device;
331         debug_uart_clk = clk_get_sys("serial8250.0", "uarta");
332         debug_uart_port_base = ((struct plat_serial8250_port *)(
333                         debug_uarta_device.dev.platform_data))->mapbase;
334 }
335
336 static void __init cardhu_uart_init(void)
337 {
338         struct clk *c;
339         int i;
340
341         for (i = 0; i < ARRAY_SIZE(uart_parent_clk); ++i) {
342                 c = tegra_get_clock_by_name(uart_parent_clk[i].name);
343                 if (IS_ERR_OR_NULL(c)) {
344                         pr_err("Not able to get the clock for %s\n",
345                                                 uart_parent_clk[i].name);
346                         continue;
347                 }
348                 uart_parent_clk[i].parent_clk = c;
349                 uart_parent_clk[i].fixed_clk_rate = clk_get_rate(c);
350         }
351         cardhu_uart_pdata.parent_clk_list = uart_parent_clk;
352         cardhu_uart_pdata.parent_clk_count = ARRAY_SIZE(uart_parent_clk);
353         tegra_uarta_device.dev.platform_data = &cardhu_uart_pdata;
354         tegra_uartb_device.dev.platform_data = &cardhu_uart_pdata;
355         tegra_uartc_device.dev.platform_data = &cardhu_uart_pdata;
356         tegra_uartd_device.dev.platform_data = &cardhu_uart_pdata;
357         tegra_uarte_device.dev.platform_data = &cardhu_uart_pdata;
358
359         /* Register low speed only if it is selected */
360         if (!is_tegra_debug_uartport_hs()) {
361                 uart_debug_init();
362                 /* Clock enable for the debug channel */
363                 if (!IS_ERR_OR_NULL(debug_uart_clk)) {
364                         pr_info("The debug console clock name is %s\n",
365                                                 debug_uart_clk->name);
366                         c = tegra_get_clock_by_name("pll_p");
367                         if (IS_ERR_OR_NULL(c))
368                                 pr_err("Not getting the parent clock pll_p\n");
369                         else
370                                 clk_set_parent(debug_uart_clk, c);
371
372                         clk_enable(debug_uart_clk);
373                         clk_set_rate(debug_uart_clk, clk_get_rate(c));
374                 } else {
375                         pr_err("Not getting the clock %s for debug console\n",
376                                         debug_uart_clk->name);
377                 }
378         }
379
380         platform_add_devices(cardhu_uart_devices,
381                                 ARRAY_SIZE(cardhu_uart_devices));
382 }
383
384 static struct platform_device tegra_camera = {
385         .name = "tegra_camera",
386         .id = -1,
387 };
388
389 static struct platform_device *cardhu_spi_devices[] __initdata = {
390         &tegra_spi_device4,
391 };
392
393 struct spi_clk_parent spi_parent_clk[] = {
394         [0] = {.name = "pll_p"},
395         [1] = {.name = "pll_m"},
396         [2] = {.name = "clk_m"},
397 };
398
399 static struct tegra_spi_platform_data cardhu_spi_pdata = {
400         .is_dma_based           = true,
401         .max_dma_buffer         = (16 * 1024),
402         .is_clkon_always        = false,
403         .max_rate               = 100000000,
404 };
405
406 static void __init cardhu_spi_init(void)
407 {
408         int i;
409         struct clk *c;
410         struct board_info board_info;
411
412         tegra_get_board_info(&board_info);
413
414         for (i = 0; i < ARRAY_SIZE(spi_parent_clk); ++i) {
415                 c = tegra_get_clock_by_name(spi_parent_clk[i].name);
416                 if (IS_ERR_OR_NULL(c)) {
417                         pr_err("Not able to get the clock for %s\n",
418                                                 spi_parent_clk[i].name);
419                         continue;
420                 }
421                 spi_parent_clk[i].parent_clk = c;
422                 spi_parent_clk[i].fixed_clk_rate = clk_get_rate(c);
423         }
424         cardhu_spi_pdata.parent_clk_list = spi_parent_clk;
425         cardhu_spi_pdata.parent_clk_count = ARRAY_SIZE(spi_parent_clk);
426         tegra_spi_device4.dev.platform_data = &cardhu_spi_pdata;
427         platform_add_devices(cardhu_spi_devices,
428                                 ARRAY_SIZE(cardhu_spi_devices));
429
430         if (board_info.board_id == BOARD_E1198) {
431                 tegra_spi_device2.dev.platform_data = &cardhu_spi_pdata;
432                 platform_device_register(&tegra_spi_device2);
433         }
434 }
435
436 static struct resource tegra_rtc_resources[] = {
437         [0] = {
438                 .start = TEGRA_RTC_BASE,
439                 .end = TEGRA_RTC_BASE + TEGRA_RTC_SIZE - 1,
440                 .flags = IORESOURCE_MEM,
441         },
442         [1] = {
443                 .start = INT_RTC,
444                 .end = INT_RTC,
445                 .flags = IORESOURCE_IRQ,
446         },
447 };
448
449 static struct platform_device tegra_rtc_device = {
450         .name = "tegra_rtc",
451         .id   = -1,
452         .resource = tegra_rtc_resources,
453         .num_resources = ARRAY_SIZE(tegra_rtc_resources),
454 };
455
456 static struct tegra_wm8903_platform_data cardhu_audio_pdata = {
457         .gpio_spkr_en           = TEGRA_GPIO_SPKR_EN,
458         .gpio_hp_det            = TEGRA_GPIO_HP_DET,
459         .gpio_hp_mute           = -1,
460         .gpio_int_mic_en        = -1,
461         .gpio_ext_mic_en        = -1,
462 };
463
464 static struct platform_device cardhu_audio_device = {
465         .name   = "tegra-snd-wm8903",
466         .id     = 0,
467         .dev    = {
468                 .platform_data  = &cardhu_audio_pdata,
469         },
470 };
471
472 static struct platform_device *cardhu_devices[] __initdata = {
473         &tegra_pmu_device,
474         &tegra_rtc_device,
475         &tegra_udc_device,
476 #if defined(CONFIG_SND_HDA_TEGRA)
477         &tegra_hda_device,
478 #endif
479 #if defined(CONFIG_TEGRA_IOVMM_SMMU)
480         &tegra_smmu_device,
481 #endif
482         &tegra_wdt_device,
483 #if defined(CONFIG_TEGRA_AVP)
484         &tegra_avp_device,
485 #endif
486         &tegra_camera,
487 #if defined(CONFIG_CRYPTO_DEV_TEGRA_SE)
488         &tegra_se_device,
489 #endif
490         &tegra_ahub_device,
491         &tegra_i2s_device1,
492         &tegra_spdif_device,
493         &spdif_dit_device,
494         &tegra_pcm_device,
495         &cardhu_audio_device,
496 #if defined(CONFIG_CRYPTO_DEV_TEGRA_AES)
497         &tegra_aes_device,
498 #endif
499 };
500
501 #define MXT_CONFIG_CRC  0xD62DE8
502 static const u8 config[] = {
503         0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
504         0xFF, 0xFF, 0x32, 0x0A, 0x00, 0x14, 0x14, 0x00,
505         0x00, 0x00, 0x00, 0x00, 0x00, 0x8B, 0x00, 0x00,
506         0x1B, 0x2A, 0x00, 0x20, 0x3C, 0x04, 0x05, 0x00,
507         0x02, 0x01, 0x00, 0x0A, 0x0A, 0x0A, 0x0A, 0xFF,
508         0x02, 0x55, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00,
509         0x00, 0x00, 0x00, 0x64, 0x02, 0x00, 0x00, 0x00,
510         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
511         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
512         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07,
513         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23,
514         0x00, 0x00, 0x00, 0x05, 0x0A, 0x15, 0x1E, 0x00,
515         0x00, 0x04, 0xFF, 0x03, 0x3F, 0x64, 0x64, 0x01,
516         0x0A, 0x14, 0x28, 0x4B, 0x00, 0x02, 0x00, 0x64,
517         0x00, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
518         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
519         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
520         0x00, 0x00, 0x00, 0x08, 0x10, 0x3C, 0x00, 0x00,
521         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
522         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
523 };
524
525 #define MXT_CONFIG_CRC_SKU2000  0xA24D9A
526 static const u8 config_sku2000[] = {
527         0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
528         0xFF, 0xFF, 0x32, 0x0A, 0x00, 0x14, 0x14, 0x19,
529         0x00, 0x00, 0x00, 0x00, 0x00, 0x8B, 0x00, 0x00,
530         0x1B, 0x2A, 0x00, 0x20, 0x3A, 0x04, 0x05, 0x00,  //23=thr  2 di
531         0x04, 0x04, 0x41, 0x0A, 0x0A, 0x0A, 0x0A, 0xFF,
532         0x02, 0x55, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00,
533         0x00, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00,  //0A=limit
534         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
535         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
536         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
537         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23,
538         0x00, 0x00, 0x00, 0x05, 0x0A, 0x15, 0x1E, 0x00,
539         0x00, 0x04, 0x00, 0x03, 0x3F, 0x64, 0x64, 0x01,
540         0x0A, 0x14, 0x28, 0x4B, 0x00, 0x02, 0x00, 0x64,
541         0x00, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
542         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
543         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
544         0x00, 0x00, 0x00, 0x08, 0x10, 0x3C, 0x00, 0x00,
545         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
546         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
547 };
548
549 static struct mxt_platform_data atmel_mxt_info = {
550         .x_line         = 27,
551         .y_line         = 42,
552         .x_size         = 768,
553         .y_size         = 1366,
554         .blen           = 0x20,
555         .threshold      = 0x3C,
556         .voltage        = 3300000,              /* 3.3V */
557         .orient         = 5,
558         .config         = config,
559         .config_length  = 157,
560         .config_crc     = MXT_CONFIG_CRC,
561         .irqflags       = IRQF_TRIGGER_FALLING,
562 /*      .read_chg       = &read_chg, */
563         .read_chg       = NULL,
564 };
565
566 static struct i2c_board_info __initdata atmel_i2c_info[] = {
567         {
568                 I2C_BOARD_INFO("atmel_mxt_ts", 0x5A),
569                 .irq = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PH4),
570                 .platform_data = &atmel_mxt_info,
571         }
572 };
573
574 static int __init cardhu_touch_init(void)
575 {
576         struct board_info BoardInfo;
577
578         tegra_gpio_enable(TEGRA_GPIO_PH4);
579         tegra_gpio_enable(TEGRA_GPIO_PH6);
580
581         gpio_request(TEGRA_GPIO_PH4, "atmel-irq");
582         gpio_direction_input(TEGRA_GPIO_PH4);
583
584         gpio_request(TEGRA_GPIO_PH6, "atmel-reset");
585         gpio_direction_output(TEGRA_GPIO_PH6, 0);
586         msleep(1);
587         gpio_set_value(TEGRA_GPIO_PH6, 1);
588         msleep(100);
589
590         tegra_get_board_info(&BoardInfo);
591         if ((BoardInfo.sku & SKU_TOUCH_MASK) == SKU_TOUCH_2000) {
592                 atmel_mxt_info.config = config_sku2000;
593                 atmel_mxt_info.config_crc = MXT_CONFIG_CRC_SKU2000;
594         }
595
596         i2c_register_board_info(1, atmel_i2c_info, 1);
597
598         return 0;
599 }
600
601 static struct tegra_uhsic_config uhsic_phy_config = {
602         .enable_gpio = EN_HSIC_GPIO,
603         .reset_gpio = -1,
604         .sync_start_delay = 9,
605         .idle_wait_delay = 17,
606         .term_range_adj = 0,
607         .elastic_underrun_limit = 16,
608         .elastic_overrun_limit = 16,
609 };
610
611 static struct tegra_ehci_platform_data tegra_ehci_uhsic_pdata = {
612         .phy_type = TEGRA_USB_PHY_TYPE_HSIC,
613         .phy_config = &uhsic_phy_config,
614         .operating_mode = TEGRA_USB_HOST,
615         .power_down_on_bus_suspend = 1,
616 };
617
618 static struct tegra_ehci_platform_data tegra_ehci_pdata[] = {
619         [0] = {
620                         .phy_config = &utmi_phy_config[0],
621                         .operating_mode = TEGRA_USB_HOST,
622                         .power_down_on_bus_suspend = 1,
623         },
624         [1] = {
625                         .phy_config = &utmi_phy_config[1],
626                         .operating_mode = TEGRA_USB_HOST,
627                         .power_down_on_bus_suspend = 1,
628         },
629         [2] = {
630                         .phy_config = &utmi_phy_config[2],
631                         .operating_mode = TEGRA_USB_HOST,
632                         .power_down_on_bus_suspend = 1,
633         },
634 };
635
636 static struct platform_device *tegra_usb_otg_host_register(void)
637 {
638         struct platform_device *pdev;
639         void *platform_data;
640         int val;
641
642         pdev = platform_device_alloc(tegra_ehci1_device.name,
643                 tegra_ehci1_device.id);
644         if (!pdev)
645                 return NULL;
646
647         val = platform_device_add_resources(pdev, tegra_ehci1_device.resource,
648                 tegra_ehci1_device.num_resources);
649         if (val)
650                 goto error;
651
652         pdev->dev.dma_mask =  tegra_ehci1_device.dev.dma_mask;
653         pdev->dev.coherent_dma_mask = tegra_ehci1_device.dev.coherent_dma_mask;
654
655         platform_data = kmalloc(sizeof(struct tegra_ehci_platform_data),
656                 GFP_KERNEL);
657         if (!platform_data)
658                 goto error;
659
660         memcpy(platform_data, &tegra_ehci_pdata[0],
661                                 sizeof(struct tegra_ehci_platform_data));
662         pdev->dev.platform_data = platform_data;
663
664         val = platform_device_add(pdev);
665         if (val)
666                 goto error_add;
667
668         return pdev;
669
670 error_add:
671         kfree(platform_data);
672 error:
673         pr_err("%s: failed to add the host contoller device\n", __func__);
674         platform_device_put(pdev);
675         return NULL;
676 }
677
678 static void tegra_usb_otg_host_unregister(struct platform_device *pdev)
679 {
680         platform_device_unregister(pdev);
681 }
682
683 #ifdef CONFIG_USB_SUPPORT
684 static struct usb_phy_plat_data tegra_usb_phy_pdata[] = {
685         [0] = {
686                         .instance = 0,
687                         .vbus_gpio = -1,
688                         .vbus_reg_supply = "vdd_vbus_micro_usb",
689         },
690         [1] = {
691                         .instance = 1,
692                         .vbus_gpio = -1,
693         },
694         [2] = {
695                         .instance = 2,
696                         .vbus_gpio = -1,
697                         .vbus_reg_supply = "vdd_vbus_typea_usb",
698         },
699 };
700
701 static struct tegra_otg_platform_data tegra_otg_pdata = {
702         .host_register = &tegra_usb_otg_host_register,
703         .host_unregister = &tegra_usb_otg_host_unregister,
704 };
705
706 static void cardhu_usb_init(void)
707 {
708         struct board_info bi;
709
710         tegra_get_board_info(&bi);
711
712         tegra_usb_phy_init(tegra_usb_phy_pdata,
713                         ARRAY_SIZE(tegra_usb_phy_pdata));
714
715         tegra_otg_device.dev.platform_data = &tegra_otg_pdata;
716         platform_device_register(&tegra_otg_device);
717         if (bi.board_id == BOARD_PM267) {
718                 uhsic_phy_config.reset_gpio =
719                         PM267_SMSC4640_HSIC_HUB_RESET_GPIO;
720                 tegra_ehci2_device.dev.platform_data = &tegra_ehci_uhsic_pdata;
721                 platform_device_register(&tegra_ehci2_device);
722         } else if (bi.board_id == BOARD_E1256) {
723                 tegra_ehci2_device.dev.platform_data = &tegra_ehci_uhsic_pdata;
724                 platform_device_register(&tegra_ehci2_device);
725         } else if (bi.board_id == BOARD_E1186) {
726                 tegra_ehci2_device.dev.platform_data = &tegra_ehci_uhsic_pdata;
727                 /* baseband registration happens in baseband-xmm-power  */
728         } else {
729                 tegra_ehci2_device.dev.platform_data = &tegra_ehci_pdata[1];
730                 platform_device_register(&tegra_ehci2_device);
731         }
732
733         tegra_ehci3_device.dev.platform_data = &tegra_ehci_pdata[2];
734         platform_device_register(&tegra_ehci3_device);
735
736 }
737 #else
738 static void cardhu_usb_init(void) { }
739 #endif
740
741 static void cardhu_gps_init(void)
742 {
743         tegra_gpio_enable(TEGRA_GPIO_PU2);
744         tegra_gpio_enable(TEGRA_GPIO_PU3);
745 }
746
747 static struct baseband_power_platform_data tegra_baseband_power_data = {
748         .baseband_type = BASEBAND_XMM,
749         .modem = {
750         .xmm = {
751                         .bb_rst = XMM_GPIO_BB_RST,
752                         .bb_on = XMM_GPIO_BB_ON,
753                         .ipc_bb_wake = XMM_GPIO_IPC_BB_WAKE,
754                         .ipc_ap_wake = XMM_GPIO_IPC_AP_WAKE,
755                         .ipc_hsic_active = XMM_GPIO_IPC_HSIC_ACTIVE,
756                         .ipc_hsic_sus_req = XMM_GPIO_IPC_HSIC_SUS_REQ,
757                         .hsic_device = &tegra_ehci2_device,
758                 },
759         },
760 };
761
762 static struct platform_device tegra_baseband_power_device = {
763         .name = "baseband_xmm_power",
764         .id = -1,
765         .dev = {
766                 .platform_data = &tegra_baseband_power_data,
767         },
768 };
769
770 static struct platform_device tegra_baseband_power2_device = {
771         .name = "baseband_xmm_power2",
772         .id = -1,
773         .dev = {
774                 .platform_data = &tegra_baseband_power_data,
775         },
776 };
777
778 static void cardhu_modem_init(void)
779 {
780         struct board_info board_info;
781         int w_disable_gpio, ret;
782
783         tegra_get_board_info(&board_info);
784         switch (board_info.board_id) {
785         case BOARD_E1291:
786                 if (board_info.fab < BOARD_FAB_A03) {
787                         w_disable_gpio = TEGRA_GPIO_PH5;
788                 } else {
789                         w_disable_gpio = TEGRA_GPIO_PDD5;
790                 }
791                 tegra_gpio_enable(w_disable_gpio);
792                 ret = gpio_request(w_disable_gpio, "w_disable_gpio");
793                 if (ret < 0)
794                         pr_err("%s: gpio_request failed for gpio %d\n",
795                                 __func__, w_disable_gpio);
796                 else
797                         gpio_direction_input(w_disable_gpio);
798
799                 /* E1291-A04: Set PERST signal to low */
800                 if (board_info.fab >= BOARD_FAB_A04) {
801                         ret = gpio_request(TEGRA_GPIO_PH7, "modem_perst");
802                         if (ret < 0) {
803                                 pr_err("%s(): Error in allocating gpio "
804                                         "TEGRA_GPIO_PH7\n", __func__);
805                                 break;
806                         }
807                         gpio_direction_output(TEGRA_GPIO_PH7, 0);
808                         tegra_gpio_enable(TEGRA_GPIO_PH7);
809                 }
810                 break;
811         case BOARD_E1186:
812                 tegra_gpio_enable(
813                         tegra_baseband_power_data.modem.xmm.bb_rst);
814                 tegra_gpio_enable(
815                         tegra_baseband_power_data.modem.xmm.bb_on);
816                 tegra_gpio_enable(
817                         tegra_baseband_power_data.modem.xmm.ipc_bb_wake);
818                 tegra_gpio_enable(
819                         tegra_baseband_power_data.modem.xmm.ipc_ap_wake);
820                 tegra_gpio_enable(
821                         tegra_baseband_power_data.modem.xmm.ipc_hsic_active);
822                 tegra_gpio_enable(
823                         tegra_baseband_power_data.modem.xmm.ipc_hsic_sus_req);
824                 platform_device_register(&tegra_baseband_power_device);
825                 platform_device_register(&tegra_baseband_power2_device);
826                 break;
827         default:
828                 break;
829         }
830
831 }
832
833 #ifdef CONFIG_SATA_AHCI_TEGRA
834 static void cardhu_sata_init(void)
835 {
836         platform_device_register(&tegra_sata_device);
837 }
838 #else
839 static void cardhu_sata_init(void) { }
840 #endif
841
842 static void __init tegra_cardhu_init(void)
843 {
844         tegra_clk_init_from_table(cardhu_clk_init_table);
845         cardhu_pinmux_init();
846         cardhu_i2c_init();
847         cardhu_spi_init();
848         cardhu_usb_init();
849 #ifdef CONFIG_TEGRA_EDP_LIMITS
850         cardhu_edp_init();
851 #endif
852         cardhu_uart_init();
853         cardhu_tsensor_init();
854         platform_add_devices(cardhu_devices, ARRAY_SIZE(cardhu_devices));
855         cardhu_sdhci_init();
856         cardhu_regulator_init();
857         cardhu_gpio_switch_regulator_init();
858         cardhu_suspend_init();
859         cardhu_power_off_init();
860         cardhu_touch_init();
861         cardhu_gps_init();
862         cardhu_modem_init();
863         cardhu_kbc_init();
864         cardhu_scroll_init();
865         cardhu_keys_init();
866         cardhu_panel_init();
867         cardhu_pmon_init();
868         cardhu_sensors_init();
869         cardhu_bt_rfkill();
870         tegra_setup_bluesleep();
871         cardhu_sata_init();
872         //audio_wired_jack_init();
873         cardhu_pins_state_init();
874         cardhu_emc_init();
875         tegra_release_bootloader_fb();
876 }
877
878 static void __init tegra_cardhu_reserve(void)
879 {
880 #if defined(CONFIG_NVMAP_CONVERT_CARVEOUT_TO_IOVMM)
881         tegra_reserve(0, SZ_8M, SZ_8M);
882 #else
883         tegra_reserve(SZ_128M, SZ_8M, SZ_8M);
884 #endif
885 }
886
887 MACHINE_START(CARDHU, "cardhu")
888         .boot_params    = 0x80000100,
889         .map_io         = tegra_map_common_io,
890         .reserve        = tegra_cardhu_reserve,
891         .init_early     = tegra_init_early,
892         .init_irq       = tegra_init_irq,
893         .timer          = &tegra_timer,
894         .init_machine   = tegra_cardhu_init,
895 MACHINE_END