arm: tegra: Enable XCVR setup through fuses
[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         { "vi_sensor",  "pll_p",        150000000,      false},
195         { NULL,         NULL,           0,              0},
196 };
197
198 static struct tegra_i2c_platform_data cardhu_i2c1_platform_data = {
199         .adapter_nr     = 0,
200         .bus_count      = 1,
201         .bus_clk_rate   = { 100000, 0 },
202         .scl_gpio               = {TEGRA_GPIO_PC4, 0},
203         .sda_gpio               = {TEGRA_GPIO_PC5, 0},
204         .arb_recovery = arb_lost_recovery,
205 };
206
207 static struct tegra_i2c_platform_data cardhu_i2c2_platform_data = {
208         .adapter_nr     = 1,
209         .bus_count      = 1,
210         .bus_clk_rate   = { 100000, 0 },
211         .is_clkon_always = true,
212         .scl_gpio               = {TEGRA_GPIO_PT5, 0},
213         .sda_gpio               = {TEGRA_GPIO_PT6, 0},
214         .arb_recovery = arb_lost_recovery,
215 };
216
217 static struct tegra_i2c_platform_data cardhu_i2c3_platform_data = {
218         .adapter_nr     = 2,
219         .bus_count      = 1,
220         .bus_clk_rate   = { 100000, 0 },
221         .scl_gpio               = {TEGRA_GPIO_PBB1, 0},
222         .sda_gpio               = {TEGRA_GPIO_PBB2, 0},
223         .arb_recovery = arb_lost_recovery,
224 };
225
226 static struct tegra_i2c_platform_data cardhu_i2c4_platform_data = {
227         .adapter_nr     = 3,
228         .bus_count      = 1,
229         .bus_clk_rate   = { 100000, 0 },
230         .scl_gpio               = {TEGRA_GPIO_PV4, 0},
231         .sda_gpio               = {TEGRA_GPIO_PV5, 0},
232         .arb_recovery = arb_lost_recovery,
233 };
234
235 static struct tegra_i2c_platform_data cardhu_i2c5_platform_data = {
236         .adapter_nr     = 4,
237         .bus_count      = 1,
238         .bus_clk_rate   = { 100000, 0 },
239         .scl_gpio               = {TEGRA_GPIO_PZ6, 0},
240         .sda_gpio               = {TEGRA_GPIO_PZ7, 0},
241         .arb_recovery = arb_lost_recovery,
242 };
243
244
245 #if 0
246 struct tegra_wired_jack_conf audio_wr_jack_conf = {
247         .hp_det_n = TEGRA_GPIO_PW2,
248         .en_mic_ext = TEGRA_GPIO_PX1,
249         .en_mic_int = TEGRA_GPIO_PX0,
250 };
251 #endif
252
253 static struct wm8903_platform_data cardhu_wm8903_pdata = {
254         .irq_active_low = 0,
255         .micdet_cfg = 0,
256         .micdet_delay = 100,
257         .gpio_base = CARDHU_GPIO_WM8903(0),
258         .gpio_cfg = {
259                 WM8903_GPIO_NO_CONFIG,
260                 WM8903_GPIO_NO_CONFIG,
261                 0,
262                 WM8903_GPIO_NO_CONFIG,
263                 WM8903_GPIO_NO_CONFIG,
264         },
265 };
266
267 static struct i2c_board_info __initdata wm8903_board_info = {
268         I2C_BOARD_INFO("wm8903", 0x1a),
269         .platform_data = &cardhu_wm8903_pdata,
270         .irq = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_CDC_IRQ),
271 };
272
273 static void cardhu_i2c_init(void)
274 {
275         tegra_i2c_device1.dev.platform_data = &cardhu_i2c1_platform_data;
276         tegra_i2c_device2.dev.platform_data = &cardhu_i2c2_platform_data;
277         tegra_i2c_device3.dev.platform_data = &cardhu_i2c3_platform_data;
278         tegra_i2c_device4.dev.platform_data = &cardhu_i2c4_platform_data;
279         tegra_i2c_device5.dev.platform_data = &cardhu_i2c5_platform_data;
280
281         platform_device_register(&tegra_i2c_device5);
282         platform_device_register(&tegra_i2c_device4);
283         platform_device_register(&tegra_i2c_device3);
284         platform_device_register(&tegra_i2c_device2);
285         platform_device_register(&tegra_i2c_device1);
286
287         i2c_register_board_info(4, &wm8903_board_info, 1);
288 }
289
290 static struct platform_device *cardhu_uart_devices[] __initdata = {
291         &tegra_uarta_device,
292         &tegra_uartb_device,
293         &tegra_uartc_device,
294         &tegra_uartd_device,
295         &tegra_uarte_device,
296 };
297 static struct uart_clk_parent uart_parent_clk[] = {
298         [0] = {.name = "clk_m"},
299         [1] = {.name = "pll_p"},
300         [2] = {.name = "pll_m"},
301 };
302
303 static struct tegra_uart_platform_data cardhu_uart_pdata;
304
305 static void __init uart_debug_init(void)
306 {
307         struct board_info board_info;
308
309         tegra_get_board_info(&board_info);
310         /* UARTB is debug port
311          *       for SLT - E1186/E1187/PM269
312          *       for E1256
313          */
314         if (((board_info.sku & SKU_SLT_ULPI_SUPPORT) &&
315                 ((board_info.board_id == BOARD_E1186) ||
316                 (board_info.board_id == BOARD_E1187) ||
317                 (board_info.board_id == BOARD_PM269))) ||
318                 (board_info.board_id == BOARD_E1256)) {
319                         /* UARTB is the debug port. */
320                         pr_info("Selecting UARTB as the debug console\n");
321                         cardhu_uart_devices[1] = &debug_uartb_device;
322                         debug_uart_clk =  clk_get_sys("serial8250.0", "uartb");
323                         debug_uart_port_base = ((struct plat_serial8250_port *)(
324                                 debug_uartb_device.dev.platform_data))->mapbase;
325                         return;
326         }
327         /* UARTA is the debug port. */
328         pr_info("Selecting UARTA as the debug console\n");
329         cardhu_uart_devices[0] = &debug_uarta_device;
330         debug_uart_clk = clk_get_sys("serial8250.0", "uarta");
331         debug_uart_port_base = ((struct plat_serial8250_port *)(
332                         debug_uarta_device.dev.platform_data))->mapbase;
333 }
334
335 static void __init cardhu_uart_init(void)
336 {
337         struct clk *c;
338         int i;
339
340         for (i = 0; i < ARRAY_SIZE(uart_parent_clk); ++i) {
341                 c = tegra_get_clock_by_name(uart_parent_clk[i].name);
342                 if (IS_ERR_OR_NULL(c)) {
343                         pr_err("Not able to get the clock for %s\n",
344                                                 uart_parent_clk[i].name);
345                         continue;
346                 }
347                 uart_parent_clk[i].parent_clk = c;
348                 uart_parent_clk[i].fixed_clk_rate = clk_get_rate(c);
349         }
350         cardhu_uart_pdata.parent_clk_list = uart_parent_clk;
351         cardhu_uart_pdata.parent_clk_count = ARRAY_SIZE(uart_parent_clk);
352         tegra_uarta_device.dev.platform_data = &cardhu_uart_pdata;
353         tegra_uartb_device.dev.platform_data = &cardhu_uart_pdata;
354         tegra_uartc_device.dev.platform_data = &cardhu_uart_pdata;
355         tegra_uartd_device.dev.platform_data = &cardhu_uart_pdata;
356         tegra_uarte_device.dev.platform_data = &cardhu_uart_pdata;
357
358         /* Register low speed only if it is selected */
359         if (!is_tegra_debug_uartport_hs()) {
360                 uart_debug_init();
361                 /* Clock enable for the debug channel */
362                 if (!IS_ERR_OR_NULL(debug_uart_clk)) {
363                         pr_info("The debug console clock name is %s\n",
364                                                 debug_uart_clk->name);
365                         c = tegra_get_clock_by_name("pll_p");
366                         if (IS_ERR_OR_NULL(c))
367                                 pr_err("Not getting the parent clock pll_p\n");
368                         else
369                                 clk_set_parent(debug_uart_clk, c);
370
371                         clk_enable(debug_uart_clk);
372                         clk_set_rate(debug_uart_clk, clk_get_rate(c));
373                 } else {
374                         pr_err("Not getting the clock %s for debug console\n",
375                                         debug_uart_clk->name);
376                 }
377         }
378
379         platform_add_devices(cardhu_uart_devices,
380                                 ARRAY_SIZE(cardhu_uart_devices));
381 }
382
383 static struct platform_device tegra_camera = {
384         .name = "tegra_camera",
385         .id = -1,
386 };
387
388 static struct platform_device *cardhu_spi_devices[] __initdata = {
389         &tegra_spi_device4,
390 };
391
392 struct spi_clk_parent spi_parent_clk[] = {
393         [0] = {.name = "pll_p"},
394         [1] = {.name = "pll_m"},
395         [2] = {.name = "clk_m"},
396 };
397
398 static struct tegra_spi_platform_data cardhu_spi_pdata = {
399         .is_dma_based           = true,
400         .max_dma_buffer         = (16 * 1024),
401         .is_clkon_always        = false,
402         .max_rate               = 100000000,
403 };
404
405 static void __init cardhu_spi_init(void)
406 {
407         int i;
408         struct clk *c;
409         struct board_info board_info;
410
411         tegra_get_board_info(&board_info);
412
413         for (i = 0; i < ARRAY_SIZE(spi_parent_clk); ++i) {
414                 c = tegra_get_clock_by_name(spi_parent_clk[i].name);
415                 if (IS_ERR_OR_NULL(c)) {
416                         pr_err("Not able to get the clock for %s\n",
417                                                 spi_parent_clk[i].name);
418                         continue;
419                 }
420                 spi_parent_clk[i].parent_clk = c;
421                 spi_parent_clk[i].fixed_clk_rate = clk_get_rate(c);
422         }
423         cardhu_spi_pdata.parent_clk_list = spi_parent_clk;
424         cardhu_spi_pdata.parent_clk_count = ARRAY_SIZE(spi_parent_clk);
425         tegra_spi_device4.dev.platform_data = &cardhu_spi_pdata;
426         platform_add_devices(cardhu_spi_devices,
427                                 ARRAY_SIZE(cardhu_spi_devices));
428
429         if (board_info.board_id == BOARD_E1198) {
430                 tegra_spi_device2.dev.platform_data = &cardhu_spi_pdata;
431                 platform_device_register(&tegra_spi_device2);
432         }
433 }
434
435 static struct tegra_wm8903_platform_data cardhu_audio_pdata = {
436         .gpio_spkr_en           = TEGRA_GPIO_SPKR_EN,
437         .gpio_hp_det            = TEGRA_GPIO_HP_DET,
438         .gpio_hp_mute           = -1,
439         .gpio_int_mic_en        = -1,
440         .gpio_ext_mic_en        = -1,
441 };
442
443 static struct platform_device cardhu_audio_device = {
444         .name   = "tegra-snd-wm8903",
445         .id     = 0,
446         .dev    = {
447                 .platform_data  = &cardhu_audio_pdata,
448         },
449 };
450
451 static struct platform_device *cardhu_devices[] __initdata = {
452         &tegra_pmu_device,
453         &tegra_udc_device,
454 #if defined(CONFIG_SND_HDA_TEGRA)
455         &tegra_hda_device,
456 #endif
457 #if defined(CONFIG_TEGRA_IOVMM_SMMU)
458         &tegra_smmu_device,
459 #endif
460         &tegra_wdt_device,
461 #if defined(CONFIG_TEGRA_AVP)
462         &tegra_avp_device,
463 #endif
464         &tegra_camera,
465 #if defined(CONFIG_CRYPTO_DEV_TEGRA_SE)
466         &tegra_se_device,
467 #endif
468         &tegra_ahub_device,
469         &tegra_i2s_device1,
470         &tegra_pcm_device,
471         &cardhu_audio_device,
472 #if defined(CONFIG_CRYPTO_DEV_TEGRA_AES)
473         &tegra_aes_device,
474 #endif
475 };
476
477 #define MXT_CONFIG_CRC  0xD62DE8
478 static const u8 config[] = {
479         0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
480         0xFF, 0xFF, 0x32, 0x0A, 0x00, 0x14, 0x14, 0x00,
481         0x00, 0x00, 0x00, 0x00, 0x00, 0x8B, 0x00, 0x00,
482         0x1B, 0x2A, 0x00, 0x20, 0x3C, 0x04, 0x05, 0x00,
483         0x02, 0x01, 0x00, 0x0A, 0x0A, 0x0A, 0x0A, 0xFF,
484         0x02, 0x55, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00,
485         0x00, 0x00, 0x00, 0x64, 0x02, 0x00, 0x00, 0x00,
486         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
487         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
488         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07,
489         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23,
490         0x00, 0x00, 0x00, 0x05, 0x0A, 0x15, 0x1E, 0x00,
491         0x00, 0x04, 0xFF, 0x03, 0x3F, 0x64, 0x64, 0x01,
492         0x0A, 0x14, 0x28, 0x4B, 0x00, 0x02, 0x00, 0x64,
493         0x00, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
494         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
495         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
496         0x00, 0x00, 0x00, 0x08, 0x10, 0x3C, 0x00, 0x00,
497         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
498         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
499 };
500
501 #define MXT_CONFIG_CRC_SKU2000  0xA24D9A
502 static const u8 config_sku2000[] = {
503         0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
504         0xFF, 0xFF, 0x32, 0x0A, 0x00, 0x14, 0x14, 0x19,
505         0x00, 0x00, 0x00, 0x00, 0x00, 0x8B, 0x00, 0x00,
506         0x1B, 0x2A, 0x00, 0x20, 0x3A, 0x04, 0x05, 0x00,  //23=thr  2 di
507         0x04, 0x04, 0x41, 0x0A, 0x0A, 0x0A, 0x0A, 0xFF,
508         0x02, 0x55, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00,
509         0x00, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00,  //0A=limit
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, 0x00,
513         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23,
514         0x00, 0x00, 0x00, 0x05, 0x0A, 0x15, 0x1E, 0x00,
515         0x00, 0x04, 0x00, 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 static struct mxt_platform_data atmel_mxt_info = {
526         .x_line         = 27,
527         .y_line         = 42,
528         .x_size         = 768,
529         .y_size         = 1366,
530         .blen           = 0x20,
531         .threshold      = 0x3C,
532         .voltage        = 3300000,              /* 3.3V */
533         .orient         = 5,
534         .config         = config,
535         .config_length  = 157,
536         .config_crc     = MXT_CONFIG_CRC,
537         .irqflags       = IRQF_TRIGGER_FALLING,
538 /*      .read_chg       = &read_chg, */
539         .read_chg       = NULL,
540 };
541
542 static struct i2c_board_info __initdata atmel_i2c_info[] = {
543         {
544                 I2C_BOARD_INFO("atmel_mxt_ts", 0x5A),
545                 .irq = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PH4),
546                 .platform_data = &atmel_mxt_info,
547         }
548 };
549
550 static int __init cardhu_touch_init(void)
551 {
552         struct board_info BoardInfo;
553
554         tegra_gpio_enable(TEGRA_GPIO_PH4);
555         tegra_gpio_enable(TEGRA_GPIO_PH6);
556
557         gpio_request(TEGRA_GPIO_PH4, "atmel-irq");
558         gpio_direction_input(TEGRA_GPIO_PH4);
559
560         gpio_request(TEGRA_GPIO_PH6, "atmel-reset");
561         gpio_direction_output(TEGRA_GPIO_PH6, 0);
562         msleep(1);
563         gpio_set_value(TEGRA_GPIO_PH6, 1);
564         msleep(100);
565
566         tegra_get_board_info(&BoardInfo);
567         if ((BoardInfo.sku & SKU_TOUCH_MASK) == SKU_TOUCH_2000) {
568                 atmel_mxt_info.config = config_sku2000;
569                 atmel_mxt_info.config_crc = MXT_CONFIG_CRC_SKU2000;
570         }
571
572         i2c_register_board_info(1, atmel_i2c_info, 1);
573
574         return 0;
575 }
576
577 static struct tegra_uhsic_config uhsic_phy_config = {
578         .enable_gpio = EN_HSIC_GPIO,
579         .reset_gpio = -1,
580         .sync_start_delay = 9,
581         .idle_wait_delay = 17,
582         .term_range_adj = 0,
583         .elastic_underrun_limit = 16,
584         .elastic_overrun_limit = 16,
585 };
586
587 static struct tegra_ehci_platform_data tegra_ehci_uhsic_pdata = {
588         .phy_type = TEGRA_USB_PHY_TYPE_HSIC,
589         .phy_config = &uhsic_phy_config,
590         .operating_mode = TEGRA_USB_HOST,
591         .power_down_on_bus_suspend = 1,
592 };
593
594 static struct tegra_ehci_platform_data tegra_ehci_pdata[] = {
595         [0] = {
596                         .phy_config = &utmi_phy_config[0],
597                         .operating_mode = TEGRA_USB_HOST,
598                         .power_down_on_bus_suspend = 1,
599         },
600         [1] = {
601                         .phy_config = &utmi_phy_config[1],
602                         .operating_mode = TEGRA_USB_HOST,
603                         .power_down_on_bus_suspend = 1,
604         },
605         [2] = {
606                         .phy_config = &utmi_phy_config[2],
607                         .operating_mode = TEGRA_USB_HOST,
608                         .power_down_on_bus_suspend = 1,
609         },
610 };
611
612 static struct platform_device *tegra_usb_otg_host_register(void)
613 {
614         struct platform_device *pdev;
615         void *platform_data;
616         int val;
617
618         pdev = platform_device_alloc(tegra_ehci1_device.name,
619                 tegra_ehci1_device.id);
620         if (!pdev)
621                 return NULL;
622
623         val = platform_device_add_resources(pdev, tegra_ehci1_device.resource,
624                 tegra_ehci1_device.num_resources);
625         if (val)
626                 goto error;
627
628         pdev->dev.dma_mask =  tegra_ehci1_device.dev.dma_mask;
629         pdev->dev.coherent_dma_mask = tegra_ehci1_device.dev.coherent_dma_mask;
630
631         platform_data = kmalloc(sizeof(struct tegra_ehci_platform_data),
632                 GFP_KERNEL);
633         if (!platform_data)
634                 goto error;
635
636         memcpy(platform_data, &tegra_ehci_pdata[0],
637                                 sizeof(struct tegra_ehci_platform_data));
638         pdev->dev.platform_data = platform_data;
639
640         val = platform_device_add(pdev);
641         if (val)
642                 goto error_add;
643
644         return pdev;
645
646 error_add:
647         kfree(platform_data);
648 error:
649         pr_err("%s: failed to add the host contoller device\n", __func__);
650         platform_device_put(pdev);
651         return NULL;
652 }
653
654 static void tegra_usb_otg_host_unregister(struct platform_device *pdev)
655 {
656         platform_device_unregister(pdev);
657 }
658
659 #ifdef CONFIG_USB_SUPPORT
660 static struct usb_phy_plat_data tegra_usb_phy_pdata[] = {
661         [0] = {
662                         .instance = 0,
663                         .vbus_gpio = -1,
664                         .vbus_reg_supply = "vdd_vbus_micro_usb",
665         },
666         [1] = {
667                         .instance = 1,
668                         .vbus_gpio = -1,
669         },
670         [2] = {
671                         .instance = 2,
672                         .vbus_gpio = -1,
673                         .vbus_reg_supply = "vdd_vbus_typea_usb",
674         },
675 };
676
677 static struct tegra_otg_platform_data tegra_otg_pdata = {
678         .host_register = &tegra_usb_otg_host_register,
679         .host_unregister = &tegra_usb_otg_host_unregister,
680 };
681
682 static void cardhu_usb_init(void)
683 {
684         struct board_info bi;
685
686         tegra_get_board_info(&bi);
687
688         tegra_usb_phy_init(tegra_usb_phy_pdata,
689                         ARRAY_SIZE(tegra_usb_phy_pdata));
690
691         tegra_otg_device.dev.platform_data = &tegra_otg_pdata;
692         platform_device_register(&tegra_otg_device);
693         if (bi.board_id == BOARD_PM267) {
694                 uhsic_phy_config.reset_gpio =
695                         PM267_SMSC4640_HSIC_HUB_RESET_GPIO;
696                 tegra_ehci2_device.dev.platform_data = &tegra_ehci_uhsic_pdata;
697                 platform_device_register(&tegra_ehci2_device);
698         } else if (bi.board_id == BOARD_E1256) {
699                 tegra_ehci2_device.dev.platform_data = &tegra_ehci_uhsic_pdata;
700                 platform_device_register(&tegra_ehci2_device);
701         } else if (bi.board_id == BOARD_E1186) {
702                 tegra_ehci2_device.dev.platform_data = &tegra_ehci_uhsic_pdata;
703                 /* baseband registration happens in baseband-xmm-power  */
704         } else {
705                 tegra_ehci2_device.dev.platform_data = &tegra_ehci_pdata[1];
706                 platform_device_register(&tegra_ehci2_device);
707         }
708
709         tegra_ehci3_device.dev.platform_data = &tegra_ehci_pdata[2];
710         platform_device_register(&tegra_ehci3_device);
711
712 }
713 #else
714 static void cardhu_usb_init(void) { }
715 #endif
716
717 static void cardhu_gps_init(void)
718 {
719         tegra_gpio_enable(TEGRA_GPIO_PU2);
720         tegra_gpio_enable(TEGRA_GPIO_PU3);
721 }
722
723 static struct baseband_power_platform_data tegra_baseband_power_data = {
724         .baseband_type = BASEBAND_XMM,
725         .modem = {
726         .xmm = {
727                         .bb_rst = XMM_GPIO_BB_RST,
728                         .bb_on = XMM_GPIO_BB_ON,
729                         .ipc_bb_wake = XMM_GPIO_IPC_BB_WAKE,
730                         .ipc_ap_wake = XMM_GPIO_IPC_AP_WAKE,
731                         .ipc_hsic_active = XMM_GPIO_IPC_HSIC_ACTIVE,
732                         .ipc_hsic_sus_req = XMM_GPIO_IPC_HSIC_SUS_REQ,
733                         .hsic_device = &tegra_ehci2_device,
734                 },
735         },
736 };
737
738 static struct platform_device tegra_baseband_power_device = {
739         .name = "baseband_xmm_power",
740         .id = -1,
741         .dev = {
742                 .platform_data = &tegra_baseband_power_data,
743         },
744 };
745
746 static struct platform_device tegra_baseband_power2_device = {
747         .name = "baseband_xmm_power2",
748         .id = -1,
749         .dev = {
750                 .platform_data = &tegra_baseband_power_data,
751         },
752 };
753
754 static void cardhu_modem_init(void)
755 {
756         struct board_info board_info;
757         int w_disable_gpio, ret;
758
759         tegra_get_board_info(&board_info);
760         switch (board_info.board_id) {
761         case BOARD_E1291:
762                 if (board_info.fab < BOARD_FAB_A03) {
763                         w_disable_gpio = TEGRA_GPIO_PH5;
764                 } else {
765                         w_disable_gpio = TEGRA_GPIO_PDD5;
766                 }
767                 tegra_gpio_enable(w_disable_gpio);
768                 ret = gpio_request(w_disable_gpio, "w_disable_gpio");
769                 if (ret < 0)
770                         pr_err("%s: gpio_request failed for gpio %d\n",
771                                 __func__, w_disable_gpio);
772                 else
773                         gpio_direction_input(w_disable_gpio);
774
775                 /* E1291-A04: Set PERST signal to low */
776                 if (board_info.fab >= BOARD_FAB_A04) {
777                         ret = gpio_request(TEGRA_GPIO_PH7, "modem_perst");
778                         if (ret < 0) {
779                                 pr_err("%s(): Error in allocating gpio "
780                                         "TEGRA_GPIO_PH7\n", __func__);
781                                 break;
782                         }
783                         gpio_direction_output(TEGRA_GPIO_PH7, 0);
784                         tegra_gpio_enable(TEGRA_GPIO_PH7);
785                 }
786                 break;
787         case BOARD_E1186:
788                 tegra_gpio_enable(
789                         tegra_baseband_power_data.modem.xmm.bb_rst);
790                 tegra_gpio_enable(
791                         tegra_baseband_power_data.modem.xmm.bb_on);
792                 tegra_gpio_enable(
793                         tegra_baseband_power_data.modem.xmm.ipc_bb_wake);
794                 tegra_gpio_enable(
795                         tegra_baseband_power_data.modem.xmm.ipc_ap_wake);
796                 tegra_gpio_enable(
797                         tegra_baseband_power_data.modem.xmm.ipc_hsic_active);
798                 tegra_gpio_enable(
799                         tegra_baseband_power_data.modem.xmm.ipc_hsic_sus_req);
800                 platform_device_register(&tegra_baseband_power_device);
801                 platform_device_register(&tegra_baseband_power2_device);
802                 break;
803         default:
804                 break;
805         }
806
807 }
808
809 #ifdef CONFIG_SATA_AHCI_TEGRA
810 static void cardhu_sata_init(void)
811 {
812         platform_device_register(&tegra_sata_device);
813 }
814 #else
815 static void cardhu_sata_init(void) { }
816 #endif
817
818 static void __init tegra_cardhu_init(void)
819 {
820         tegra_clk_init_from_table(cardhu_clk_init_table);
821         cardhu_pinmux_init();
822         cardhu_i2c_init();
823         cardhu_spi_init();
824         cardhu_usb_init();
825 #ifdef CONFIG_TEGRA_EDP_LIMITS
826         cardhu_edp_init();
827 #endif
828         cardhu_uart_init();
829         cardhu_tsensor_init();
830         platform_add_devices(cardhu_devices, ARRAY_SIZE(cardhu_devices));
831         cardhu_sdhci_init();
832         cardhu_regulator_init();
833         cardhu_gpio_switch_regulator_init();
834         cardhu_suspend_init();
835         cardhu_power_off_init();
836         cardhu_touch_init();
837         cardhu_gps_init();
838         cardhu_modem_init();
839         cardhu_kbc_init();
840         cardhu_scroll_init();
841         cardhu_keys_init();
842         cardhu_panel_init();
843         cardhu_pmon_init();
844         cardhu_sensors_init();
845         cardhu_bt_rfkill();
846         tegra_setup_bluesleep();
847         cardhu_sata_init();
848         //audio_wired_jack_init();
849         cardhu_pins_state_init();
850         cardhu_emc_init();
851         tegra_release_bootloader_fb();
852 }
853
854 static void __init tegra_cardhu_reserve(void)
855 {
856 #if defined(CONFIG_NVMAP_CONVERT_CARVEOUT_TO_IOVMM)
857         tegra_reserve(0, SZ_8M, SZ_8M);
858 #else
859         tegra_reserve(SZ_128M, SZ_8M, SZ_8M);
860 #endif
861 }
862
863 MACHINE_START(CARDHU, "cardhu")
864         .boot_params    = 0x80000100,
865         .map_io         = tegra_map_common_io,
866         .reserve        = tegra_cardhu_reserve,
867         .init_early     = tegra_init_early,
868         .init_irq       = tegra_init_irq,
869         .timer          = &tegra_timer,
870         .init_machine   = tegra_cardhu_init,
871 MACHINE_END