ARM: tegra: Update cardhu boardfiles for K39
[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 struct tegra_wired_jack_conf audio_wr_jack_conf = {
221         .hp_det_n = TEGRA_GPIO_PW2,
222         .en_mic_ext = TEGRA_GPIO_PX1,
223         .en_mic_int = TEGRA_GPIO_PX0,
224 };
225
226 static void cardhu_i2c_init(void)
227 {
228         tegra_i2c_device1.dev.platform_data = &cardhu_i2c1_platform_data;
229         tegra_i2c_device2.dev.platform_data = &cardhu_i2c2_platform_data;
230         tegra_i2c_device3.dev.platform_data = &cardhu_i2c3_platform_data;
231         tegra_i2c_device4.dev.platform_data = &cardhu_i2c4_platform_data;
232         tegra_i2c_device5.dev.platform_data = &cardhu_i2c5_platform_data;
233
234         platform_device_register(&tegra_i2c_device5);
235         platform_device_register(&tegra_i2c_device4);
236         platform_device_register(&tegra_i2c_device3);
237         platform_device_register(&tegra_i2c_device2);
238         platform_device_register(&tegra_i2c_device1);
239 }
240
241 static struct platform_device *cardhu_uart_devices[] __initdata = {
242         &tegra_uarta_device,
243         &tegra_uartb_device,
244         &tegra_uartc_device,
245         &tegra_uartd_device,
246         &tegra_uarte_device,
247 };
248 static struct clk *debug_uart_clk;
249
250 static void __init uart_debug_init(void)
251 {
252         struct board_info board_info;
253
254         tegra_get_board_info(&board_info);
255         if (board_info.sku & SKU_SLT_ULPI_SUPPORT) {
256                 if ((board_info.board_id == BOARD_E1186) ||
257                         (board_info.board_id == BOARD_E1187) ||
258                         (board_info.board_id == BOARD_PM269)) {
259                                 /* UARTB is the debug port. */
260                                 pr_info("Selecting UARTB as the debug console\n");
261                                 cardhu_uart_devices[1] = &debug_uartb_device;
262                                 debug_uart_clk =
263                                         clk_get_sys("serial8250.0", "uartb");
264                                 return;
265                 }
266                 pr_err("%s(): Unhandled SKU information for Board 0x%04x\n",
267                                 __func__, board_info.board_id);
268         }
269         /* UARTA is the debug port. */
270         pr_info("Selecting UARTA as the debug console\n");
271         cardhu_uart_devices[0] = &debug_uarta_device;
272         debug_uart_clk = clk_get_sys("serial8250.0", "uarta");
273 }
274
275 static void __init cardhu_uart_init(void)
276 {
277         /* Register low speed only if it is selected */
278         if (!is_tegra_debug_uartport_hs()) {
279                 uart_debug_init();
280                 /* Clock enable for the debug channel */
281                 if (!IS_ERR_OR_NULL(debug_uart_clk)) {
282                         pr_info("The debug console clock name is %s\n",
283                                                 debug_uart_clk->name);
284                         clk_enable(debug_uart_clk);
285                         clk_set_rate(debug_uart_clk, 408000000);
286                 } else {
287                         pr_err("Not getting the clock %s for debug console\n",
288                                         debug_uart_clk->name);
289                 }
290         }
291
292         platform_add_devices(cardhu_uart_devices,
293                                 ARRAY_SIZE(cardhu_uart_devices));
294 }
295
296 static struct platform_device tegra_camera = {
297         .name = "tegra_camera",
298         .id = -1,
299 };
300
301 static struct platform_device *cardhu_devices[] __initdata = {
302         &pmu_device,
303         &tegra_udc_device,
304 #if defined(CONFIG_SND_HDA_TEGRA)
305         &tegra_hda_device,
306 #endif
307 #if defined(CONFIG_TEGRA_IOVMM_SMMU)
308         &tegra_smmu_device,
309 #endif
310         &tegra_wdt_device,
311         &tegra_avp_device,
312         &tegra_camera,
313         &tegra_spi_device4,
314 #if defined(CONFIG_CRYPTO_DEV_TEGRA_SE)
315         &tegra_se_device,
316 #endif
317 };
318
319 static int __init cardhu_touch_init(void)
320 {
321         return 0;
322 }
323
324 static struct usb_phy_plat_data tegra_usb_phy_pdata[] = {
325         [0] = {
326                         .instance = 0,
327                         .vbus_gpio = -1,
328                         .vbus_reg_supply = "vdd_vbus_micro_usb",
329         },
330         [1] = {
331                         .instance = 1,
332                         .vbus_gpio = -1,
333         },
334         [2] = {
335                         .instance = 2,
336                         .vbus_gpio = -1,
337                         .vbus_reg_supply = "vdd_vbus_typea_usb",
338         },
339 };
340
341 static struct tegra_ulpi_config uhsic_phy_config = {
342         .enable_gpio = EN_HSIC_GPIO,
343         .reset_gpio = -1,
344 };
345
346 static struct tegra_ehci_platform_data tegra_ehci_uhsic_pdata = {
347         .phy_type = TEGRA_USB_PHY_TYPE_HSIC,
348         .phy_config = &uhsic_phy_config,
349         .operating_mode = TEGRA_USB_HOST,
350         .power_down_on_bus_suspend = 1,
351 };
352
353 static struct tegra_ehci_platform_data tegra_ehci_pdata[] = {
354         [0] = {
355                         .phy_config = &utmi_phy_config[0],
356                         .operating_mode = TEGRA_USB_HOST,
357                         .power_down_on_bus_suspend = 1,
358         },
359         [1] = {
360                         .phy_config = &utmi_phy_config[1],
361                         .operating_mode = TEGRA_USB_HOST,
362                         .power_down_on_bus_suspend = 1,
363         },
364         [2] = {
365                         .phy_config = &utmi_phy_config[2],
366                         .operating_mode = TEGRA_USB_HOST,
367                         .power_down_on_bus_suspend = 1,
368         },
369 };
370
371 static struct platform_device *tegra_usb_otg_host_register(void)
372 {
373         struct platform_device *pdev;
374         void *platform_data;
375         int val;
376
377         pdev = platform_device_alloc(tegra_ehci1_device.name,
378                 tegra_ehci1_device.id);
379         if (!pdev)
380                 return NULL;
381
382         val = platform_device_add_resources(pdev, tegra_ehci1_device.resource,
383                 tegra_ehci1_device.num_resources);
384         if (val)
385                 goto error;
386
387         pdev->dev.dma_mask =  tegra_ehci1_device.dev.dma_mask;
388         pdev->dev.coherent_dma_mask = tegra_ehci1_device.dev.coherent_dma_mask;
389
390         platform_data = kmalloc(sizeof(struct tegra_ehci_platform_data),
391                 GFP_KERNEL);
392         if (!platform_data)
393                 goto error;
394
395         memcpy(platform_data, &tegra_ehci_pdata[0],
396                                 sizeof(struct tegra_ehci_platform_data));
397         pdev->dev.platform_data = platform_data;
398
399         val = platform_device_add(pdev);
400         if (val)
401                 goto error_add;
402
403         return pdev;
404
405 error_add:
406         kfree(platform_data);
407 error:
408         pr_err("%s: failed to add the host contoller device\n", __func__);
409         platform_device_put(pdev);
410         return NULL;
411 }
412
413 static void tegra_usb_otg_host_unregister(struct platform_device *pdev)
414 {
415         platform_device_unregister(pdev);
416 }
417
418 static struct tegra_otg_platform_data tegra_otg_pdata = {
419         .host_register = &tegra_usb_otg_host_register,
420         .host_unregister = &tegra_usb_otg_host_unregister,
421 };
422
423 static void cardhu_usb_init(void)
424 {
425         struct board_info bi;
426
427         tegra_get_board_info(&bi);
428
429         tegra_usb_phy_init(tegra_usb_phy_pdata, ARRAY_SIZE(tegra_usb_phy_pdata));
430
431         tegra_otg_device.dev.platform_data = &tegra_otg_pdata;
432         platform_device_register(&tegra_otg_device);
433
434         if (bi.board_id == BOARD_PM267) {
435                 uhsic_phy_config.reset_gpio =
436                         PM267_SMSC4640_HSIC_HUB_RESET_GPIO;
437                 tegra_ehci2_device.dev.platform_data = &tegra_ehci_uhsic_pdata;
438         } else if ((bi.board_id == BOARD_PM269) ||
439                 (bi.board_id == BOARD_E1186)) {
440                 tegra_ehci2_device.dev.platform_data = &tegra_ehci_uhsic_pdata;
441         } else {
442                 tegra_ehci2_device.dev.platform_data = &tegra_ehci_pdata[1];
443         }
444         platform_device_register(&tegra_ehci2_device);
445
446         tegra_ehci3_device.dev.platform_data = &tegra_ehci_pdata[2];
447         platform_device_register(&tegra_ehci3_device);
448
449 }
450
451 static void cardhu_gps_init(void)
452 {
453         tegra_gpio_enable(TEGRA_GPIO_PU2);
454         tegra_gpio_enable(TEGRA_GPIO_PU3);
455 }
456
457 static void cardhu_modem_init(void)
458 {
459         tegra_gpio_enable(TEGRA_GPIO_PH5);
460 }
461
462 #ifdef CONFIG_SATA_AHCI_TEGRA
463 static void cardhu_sata_init(void)
464 {
465         platform_device_register(&tegra_sata_device);
466 }
467 #else
468 static void cardhu_sata_init(void) { }
469 #endif
470
471 static void __init tegra_cardhu_init(void)
472 {
473         tegra_clk_init_from_table(cardhu_clk_init_table);
474         cardhu_pinmux_init();
475         cardhu_i2c_init();
476         cardhu_usb_init();
477 #ifdef CONFIG_TEGRA_EDP_LIMITS
478         cardhu_edp_init();
479 #endif
480         cardhu_uart_init();
481         platform_add_devices(cardhu_devices, ARRAY_SIZE(cardhu_devices));
482         cardhu_sdhci_init();
483         cardhu_regulator_init();
484         cardhu_gpio_switch_regulator_init();
485         cardhu_suspend_init();
486         cardhu_power_off_init();
487         cardhu_touch_init();
488         cardhu_gps_init();
489         cardhu_modem_init();
490         cardhu_kbc_init();
491         cardhu_scroll_init();
492         cardhu_keys_init();
493         cardhu_panel_init();
494         cardhu_pmon_init();
495         cardhu_sensors_init();
496         cardhu_bt_rfkill();
497         tegra_setup_bluesleep();
498         cardhu_sata_init();
499         audio_wired_jack_init();
500         cardhu_pins_state_init();
501         cardhu_emc_init();
502 }
503
504 static void __init tegra_cardhu_reserve(void)
505 {
506 #if defined(CONFIG_NVMAP_CONVERT_CARVEOUT_TO_IOVMM)
507         tegra_reserve(0, SZ_8M, SZ_8M);
508 #else
509         tegra_reserve(SZ_128M, SZ_8M, SZ_8M);
510 #endif
511 }
512
513 MACHINE_START(CARDHU, "cardhu")
514         .boot_params    = 0x80000100,
515         .map_io         = tegra_map_common_io,
516         .reserve        = tegra_cardhu_reserve,
517         .init_early     = tegra_init_early,
518         .init_irq       = tegra_init_irq,
519         .timer          = &tegra_timer,
520         .init_machine   = tegra_cardhu_init,
521 MACHINE_END