fixup: cardhu k39 updates
[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 <mach/clk.h>
38 #include <mach/iomap.h>
39 #include <mach/irqs.h>
40 #include <mach/pinmux.h>
41 #include <mach/iomap.h>
42 #include <mach/io.h>
43 #include <mach/i2s.h>
44 #include <mach/audio.h>
45 #include <asm/mach-types.h>
46 #include <asm/mach/arch.h>
47 #include <mach/usb_phy.h>
48
49 #include "board.h"
50 #include "clock.h"
51 #include "board-cardhu.h"
52 #include "devices.h"
53 #include "gpio-names.h"
54 #include "fuse.h"
55
56
57 /* !!!TODO: Change for cardhu (Taken from Ventana) */
58 static struct tegra_utmip_config utmi_phy_config[] = {
59         [0] = {
60                         .hssync_start_delay = 0,
61                         .idle_wait_delay = 17,
62                         .elastic_limit = 16,
63                         .term_range_adj = 6,
64                         .xcvr_setup = 15,
65                         .xcvr_lsfslew = 2,
66                         .xcvr_lsrslew = 2,
67         },
68         [1] = {
69                         .hssync_start_delay = 0,
70                         .idle_wait_delay = 17,
71                         .elastic_limit = 16,
72                         .term_range_adj = 6,
73                         .xcvr_setup = 15,
74                         .xcvr_lsfslew = 2,
75                         .xcvr_lsrslew = 2,
76         },
77         [2] = {
78                         .hssync_start_delay = 0,
79                         .idle_wait_delay = 17,
80                         .elastic_limit = 16,
81                         .term_range_adj = 6,
82                         .xcvr_setup = 8,
83                         .xcvr_lsfslew = 2,
84                         .xcvr_lsrslew = 2,
85         },
86 };
87
88 #ifdef CONFIG_BCM4329_RFKILL
89 static struct resource cardhu_bcm4329_rfkill_resources[] = {
90         {
91                 .name   = "bcm4329_nshutdown_gpio",
92                 .start  = TEGRA_GPIO_PU0,
93                 .end    = TEGRA_GPIO_PU0,
94                 .flags  = IORESOURCE_IO,
95         },
96 };
97
98 static struct platform_device cardhu_bcm4329_rfkill_device = {
99         .name = "bcm4329_rfkill",
100         .id             = -1,
101         .num_resources  = ARRAY_SIZE(cardhu_bcm4329_rfkill_resources),
102         .resource       = cardhu_bcm4329_rfkill_resources,
103 };
104
105 static noinline void __init cardhu_bt_rfkill(void)
106 {
107         platform_device_register(&cardhu_bcm4329_rfkill_device);
108
109         return;
110 }
111 #else
112 static inline void cardhu_bt_rfkill(void) { }
113 #endif
114
115 #ifdef CONFIG_BT_BLUESLEEP
116 static noinline void __init tegra_setup_bluesleep(void)
117 {
118         struct platform_device *pdev = NULL;
119         struct resource *res;
120
121         pdev = platform_device_alloc("bluesleep", 0);
122         if (!pdev) {
123                 pr_err("unable to allocate platform device for bluesleep");
124                 return;
125         }
126
127         res = kzalloc(sizeof(struct resource) * 3, GFP_KERNEL);
128         if (!res) {
129                 pr_err("unable to allocate resource for bluesleep\n");
130                 goto err_free_dev;
131         }
132
133         res[0].name   = "gpio_host_wake";
134         res[0].start  = TEGRA_GPIO_PU6;
135         res[0].end    = TEGRA_GPIO_PU6;
136         res[0].flags  = IORESOURCE_IO;
137
138         res[1].name   = "gpio_ext_wake";
139         res[1].start  = TEGRA_GPIO_PU1;
140         res[1].end    = TEGRA_GPIO_PU1;
141         res[1].flags  = IORESOURCE_IO;
142
143         res[2].name   = "host_wake";
144         res[2].start  = gpio_to_irq(TEGRA_GPIO_PU6);
145         res[2].end    = gpio_to_irq(TEGRA_GPIO_PU6);
146         res[2].flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE ;
147
148         if (platform_device_add_resources(pdev, res, 3)) {
149                 pr_err("unable to add resources to bluesleep device\n");
150                 goto err_free_res;
151         }
152
153         if (platform_device_add(pdev)) {
154                 pr_err("unable to add bluesleep device\n");
155                 goto err_free_res;
156         }
157         tegra_gpio_enable(TEGRA_GPIO_PU6);
158         tegra_gpio_enable(TEGRA_GPIO_PU1);
159
160 return;
161
162 err_free_res:
163         kfree(res);
164 err_free_dev:
165         platform_device_put(pdev);
166         return;
167 }
168 #else
169 static inline void tegra_setup_bluesleep(void) { }
170 #endif
171
172 static __initdata struct tegra_clk_init_table cardhu_clk_init_table[] = {
173         /* name         parent          rate            enabled */
174         { "pll_m",      NULL,           0,              true},
175         { "hda",        "pll_p",        108000000,      false},
176         { "hda2codec_2x","pll_p",       48000000,       false},
177         { "pwm",        "clk_32k",      32768,          false},
178         { "blink",      "clk_32k",      32768,          true},
179         { "pll_a",      NULL,           552960000,      true},
180         { "pll_a_out0", NULL,           11289600,       true},
181         { "i2s1",       "pll_a_out0",   11289600,       true},
182         { "i2s2",       "pll_a_out0",   11289600,       true},
183         { "audio",      "pll_a_out0",   11289600,       true},
184         { "audio_2x",   "audio",        22579200,       true},
185         { NULL,         NULL,           0,              0},
186 };
187
188 static struct tegra_i2c_platform_data cardhu_i2c1_platform_data = {
189         .adapter_nr     = 0,
190         .bus_count      = 1,
191         .bus_clk_rate   = { 100000, 0 },
192 };
193
194 static struct tegra_i2c_platform_data cardhu_i2c2_platform_data = {
195         .adapter_nr     = 1,
196         .bus_count      = 1,
197         .bus_clk_rate   = { 100000, 0 },
198         .is_clkon_always = true,
199 };
200
201 static struct tegra_i2c_platform_data cardhu_i2c3_platform_data = {
202         .adapter_nr     = 2,
203         .bus_count      = 1,
204         .bus_clk_rate   = { 100000, 0 },
205 };
206
207 static struct tegra_i2c_platform_data cardhu_i2c4_platform_data = {
208         .adapter_nr     = 3,
209         .bus_count      = 1,
210         .bus_clk_rate   = { 100000, 0 },
211 };
212
213 static struct tegra_i2c_platform_data cardhu_i2c5_platform_data = {
214         .adapter_nr     = 4,
215         .bus_count      = 1,
216         .bus_clk_rate   = { 100000, 0 },
217 };
218
219
220 #if 0
221 struct tegra_wired_jack_conf audio_wr_jack_conf = {
222         .hp_det_n = TEGRA_GPIO_PW2,
223         .en_mic_ext = TEGRA_GPIO_PX1,
224         .en_mic_int = TEGRA_GPIO_PX0,
225 };
226 #endif
227
228 static void cardhu_i2c_init(void)
229 {
230         tegra_i2c_device1.dev.platform_data = &cardhu_i2c1_platform_data;
231         tegra_i2c_device2.dev.platform_data = &cardhu_i2c2_platform_data;
232         tegra_i2c_device3.dev.platform_data = &cardhu_i2c3_platform_data;
233         tegra_i2c_device4.dev.platform_data = &cardhu_i2c4_platform_data;
234         tegra_i2c_device5.dev.platform_data = &cardhu_i2c5_platform_data;
235
236         platform_device_register(&tegra_i2c_device5);
237         platform_device_register(&tegra_i2c_device4);
238         platform_device_register(&tegra_i2c_device3);
239         platform_device_register(&tegra_i2c_device2);
240         platform_device_register(&tegra_i2c_device1);
241 }
242
243 static struct platform_device *cardhu_uart_devices[] __initdata = {
244         &tegra_uarta_device,
245         &tegra_uartb_device,
246         &tegra_uartc_device,
247         &tegra_uartd_device,
248         &tegra_uarte_device,
249 };
250 static struct clk *debug_uart_clk;
251
252 static void __init uart_debug_init(void)
253 {
254         struct board_info board_info;
255
256         tegra_get_board_info(&board_info);
257         if (board_info.sku & SKU_SLT_ULPI_SUPPORT) {
258                 if ((board_info.board_id == BOARD_E1186) ||
259                         (board_info.board_id == BOARD_E1187) ||
260                         (board_info.board_id == BOARD_PM269)) {
261                                 /* UARTB is the debug port. */
262                                 pr_info("Selecting UARTB as the debug console\n");
263                                 cardhu_uart_devices[1] = &debug_uartb_device;
264                                 debug_uart_clk =
265                                         clk_get_sys("serial8250.0", "uartb");
266                                 return;
267                 }
268                 pr_err("%s(): Unhandled SKU information for Board 0x%04x\n",
269                                 __func__, board_info.board_id);
270         }
271         /* UARTA is the debug port. */
272         pr_info("Selecting UARTA as the debug console\n");
273         cardhu_uart_devices[0] = &debug_uarta_device;
274         debug_uart_clk = clk_get_sys("serial8250.0", "uarta");
275 }
276
277 static void __init cardhu_uart_init(void)
278 {
279         /* Register low speed only if it is selected */
280         if (!is_tegra_debug_uartport_hs()) {
281                 uart_debug_init();
282                 /* Clock enable for the debug channel */
283                 if (!IS_ERR_OR_NULL(debug_uart_clk)) {
284                         pr_info("The debug console clock name is %s\n",
285                                                 debug_uart_clk->name);
286                         clk_enable(debug_uart_clk);
287                         clk_set_rate(debug_uart_clk, 408000000);
288                 } else {
289                         pr_err("Not getting the clock %s for debug console\n",
290                                         debug_uart_clk->name);
291                 }
292         }
293
294         platform_add_devices(cardhu_uart_devices,
295                                 ARRAY_SIZE(cardhu_uart_devices));
296 }
297
298 static struct platform_device tegra_camera = {
299         .name = "tegra_camera",
300         .id = -1,
301 };
302
303 static struct platform_device *cardhu_devices[] __initdata = {
304         &tegra_pmu_device,
305         &tegra_udc_device,
306 #if defined(CONFIG_SND_HDA_TEGRA)
307         &tegra_hda_device,
308 #endif
309 #if defined(CONFIG_TEGRA_IOVMM_SMMU)
310         &tegra_smmu_device,
311 #endif
312         &tegra_wdt_device,
313         &tegra_avp_device,
314         &tegra_camera,
315         &tegra_spi_device4,
316 #if defined(CONFIG_CRYPTO_DEV_TEGRA_SE)
317         &tegra_se_device,
318 #endif
319 };
320
321 static int __init cardhu_touch_init(void)
322 {
323         return 0;
324 }
325
326 static struct usb_phy_plat_data tegra_usb_phy_pdata[] = {
327         [0] = {
328                         .instance = 0,
329                         .vbus_gpio = -1,
330                         .vbus_reg_supply = "vdd_vbus_micro_usb",
331         },
332         [1] = {
333                         .instance = 1,
334                         .vbus_gpio = -1,
335         },
336         [2] = {
337                         .instance = 2,
338                         .vbus_gpio = -1,
339                         .vbus_reg_supply = "vdd_vbus_typea_usb",
340         },
341 };
342
343 static struct tegra_ulpi_config uhsic_phy_config = {
344         .enable_gpio = EN_HSIC_GPIO,
345         .reset_gpio = -1,
346 };
347
348 static struct tegra_ehci_platform_data tegra_ehci_uhsic_pdata = {
349         .phy_type = TEGRA_USB_PHY_TYPE_HSIC,
350         .phy_config = &uhsic_phy_config,
351         .operating_mode = TEGRA_USB_HOST,
352         .power_down_on_bus_suspend = 1,
353 };
354
355 static struct tegra_ehci_platform_data tegra_ehci_pdata[] = {
356         [0] = {
357                         .phy_config = &utmi_phy_config[0],
358                         .operating_mode = TEGRA_USB_HOST,
359                         .power_down_on_bus_suspend = 1,
360         },
361         [1] = {
362                         .phy_config = &utmi_phy_config[1],
363                         .operating_mode = TEGRA_USB_HOST,
364                         .power_down_on_bus_suspend = 1,
365         },
366         [2] = {
367                         .phy_config = &utmi_phy_config[2],
368                         .operating_mode = TEGRA_USB_HOST,
369                         .power_down_on_bus_suspend = 1,
370         },
371 };
372
373 static struct platform_device *tegra_usb_otg_host_register(void)
374 {
375         struct platform_device *pdev;
376         void *platform_data;
377         int val;
378
379         pdev = platform_device_alloc(tegra_ehci1_device.name,
380                 tegra_ehci1_device.id);
381         if (!pdev)
382                 return NULL;
383
384         val = platform_device_add_resources(pdev, tegra_ehci1_device.resource,
385                 tegra_ehci1_device.num_resources);
386         if (val)
387                 goto error;
388
389         pdev->dev.dma_mask =  tegra_ehci1_device.dev.dma_mask;
390         pdev->dev.coherent_dma_mask = tegra_ehci1_device.dev.coherent_dma_mask;
391
392         platform_data = kmalloc(sizeof(struct tegra_ehci_platform_data),
393                 GFP_KERNEL);
394         if (!platform_data)
395                 goto error;
396
397         memcpy(platform_data, &tegra_ehci_pdata[0],
398                                 sizeof(struct tegra_ehci_platform_data));
399         pdev->dev.platform_data = platform_data;
400
401         val = platform_device_add(pdev);
402         if (val)
403                 goto error_add;
404
405         return pdev;
406
407 error_add:
408         kfree(platform_data);
409 error:
410         pr_err("%s: failed to add the host contoller device\n", __func__);
411         platform_device_put(pdev);
412         return NULL;
413 }
414
415 static void tegra_usb_otg_host_unregister(struct platform_device *pdev)
416 {
417         platform_device_unregister(pdev);
418 }
419
420 static struct tegra_otg_platform_data tegra_otg_pdata = {
421         .host_register = &tegra_usb_otg_host_register,
422         .host_unregister = &tegra_usb_otg_host_unregister,
423 };
424
425 static void cardhu_usb_init(void)
426 {
427         struct board_info bi;
428
429         tegra_get_board_info(&bi);
430
431         tegra_usb_phy_init(tegra_usb_phy_pdata, ARRAY_SIZE(tegra_usb_phy_pdata));
432
433         tegra_otg_device.dev.platform_data = &tegra_otg_pdata;
434         platform_device_register(&tegra_otg_device);
435
436         if (bi.board_id == BOARD_PM267) {
437                 uhsic_phy_config.reset_gpio =
438                         PM267_SMSC4640_HSIC_HUB_RESET_GPIO;
439                 tegra_ehci2_device.dev.platform_data = &tegra_ehci_uhsic_pdata;
440         } else if ((bi.board_id == BOARD_PM269) ||
441                 (bi.board_id == BOARD_E1186)) {
442                 tegra_ehci2_device.dev.platform_data = &tegra_ehci_uhsic_pdata;
443         } else {
444                 tegra_ehci2_device.dev.platform_data = &tegra_ehci_pdata[1];
445         }
446         platform_device_register(&tegra_ehci2_device);
447
448         tegra_ehci3_device.dev.platform_data = &tegra_ehci_pdata[2];
449         platform_device_register(&tegra_ehci3_device);
450
451 }
452
453 static void cardhu_gps_init(void)
454 {
455         tegra_gpio_enable(TEGRA_GPIO_PU2);
456         tegra_gpio_enable(TEGRA_GPIO_PU3);
457 }
458
459 static void cardhu_modem_init(void)
460 {
461         tegra_gpio_enable(TEGRA_GPIO_PH5);
462 }
463
464 #ifdef CONFIG_SATA_AHCI_TEGRA
465 static void cardhu_sata_init(void)
466 {
467         platform_device_register(&tegra_sata_device);
468 }
469 #else
470 static void cardhu_sata_init(void) { }
471 #endif
472
473 static void __init tegra_cardhu_init(void)
474 {
475         tegra_clk_init_from_table(cardhu_clk_init_table);
476         cardhu_pinmux_init();
477         cardhu_i2c_init();
478         cardhu_usb_init();
479 #ifdef CONFIG_TEGRA_EDP_LIMITS
480         cardhu_edp_init();
481 #endif
482         cardhu_uart_init();
483         platform_add_devices(cardhu_devices, ARRAY_SIZE(cardhu_devices));
484         cardhu_sdhci_init();
485         cardhu_regulator_init();
486         cardhu_gpio_switch_regulator_init();
487         cardhu_suspend_init();
488         cardhu_power_off_init();
489         cardhu_touch_init();
490         cardhu_gps_init();
491         cardhu_modem_init();
492         cardhu_kbc_init();
493         cardhu_scroll_init();
494         cardhu_keys_init();
495         cardhu_panel_init();
496         cardhu_pmon_init();
497         cardhu_sensors_init();
498         cardhu_bt_rfkill();
499         tegra_setup_bluesleep();
500         cardhu_sata_init();
501         //audio_wired_jack_init();
502         cardhu_pins_state_init();
503         cardhu_emc_init();
504 }
505
506 static void __init tegra_cardhu_reserve(void)
507 {
508 #if defined(CONFIG_NVMAP_CONVERT_CARVEOUT_TO_IOVMM)
509         tegra_reserve(0, SZ_8M, SZ_8M);
510 #else
511         tegra_reserve(SZ_128M, SZ_8M, SZ_8M);
512 #endif
513 }
514
515 MACHINE_START(CARDHU, "cardhu")
516         .boot_params    = 0x80000100,
517         .map_io         = tegra_map_common_io,
518         .reserve        = tegra_cardhu_reserve,
519         .init_early     = tegra_init_early,
520         .init_irq       = tegra_init_irq,
521         .timer          = &tegra_timer,
522         .init_machine   = tegra_cardhu_init,
523 MACHINE_END