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