arm: tegra: cardhu: enabling bt auto power save
[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 static struct plat_serial8250_port debug_uart_platform_data[] = {
58         {
59                 .membase        = IO_ADDRESS(TEGRA_UARTA_BASE),
60                 .mapbase        = TEGRA_UARTA_BASE,
61                 .irq            = INT_UARTA,
62                 .flags          = UPF_BOOT_AUTOCONF | UPF_FIXED_TYPE,
63                 .type           = PORT_TEGRA,
64                 .iotype         = UPIO_MEM,
65                 .regshift       = 2,
66                 .uartclk        = 216000000,
67         }, {
68                 .flags          = 0,
69         }
70 };
71
72 static struct platform_device debug_uart = {
73         .name = "serial8250",
74         .id = PLAT8250_DEV_PLATFORM,
75         .dev = {
76                 .platform_data = debug_uart_platform_data,
77         },
78 };
79
80 /* !!!TODO: Change for cardhu (Taken from Ventana) */
81 static struct tegra_utmip_config utmi_phy_config[] = {
82         [0] = {
83                         .hssync_start_delay = 0,
84                         .idle_wait_delay = 17,
85                         .elastic_limit = 16,
86                         .term_range_adj = 6,
87                         .xcvr_setup = 15,
88                         .xcvr_lsfslew = 2,
89                         .xcvr_lsrslew = 2,
90         },
91         [1] = {
92                         .hssync_start_delay = 0,
93                         .idle_wait_delay = 17,
94                         .elastic_limit = 16,
95                         .term_range_adj = 6,
96                         .xcvr_setup = 15,
97                         .xcvr_lsfslew = 2,
98                         .xcvr_lsrslew = 2,
99         },
100         [2] = {
101                         .hssync_start_delay = 0,
102                         .idle_wait_delay = 17,
103                         .elastic_limit = 16,
104                         .term_range_adj = 6,
105                         .xcvr_setup = 8,
106                         .xcvr_lsfslew = 2,
107                         .xcvr_lsrslew = 2,
108         },
109 };
110
111 #ifdef CONFIG_BCM4329_RFKILL
112 static struct resource cardhu_bcm4329_rfkill_resources[] = {
113         {
114                 .name   = "bcm4329_nshutdown_gpio",
115                 .start  = TEGRA_GPIO_PU0,
116                 .end    = TEGRA_GPIO_PU0,
117                 .flags  = IORESOURCE_IO,
118         },
119 };
120
121 static struct platform_device cardhu_bcm4329_rfkill_device = {
122         .name = "bcm4329_rfkill",
123         .id             = -1,
124         .num_resources  = ARRAY_SIZE(cardhu_bcm4329_rfkill_resources),
125         .resource       = cardhu_bcm4329_rfkill_resources,
126 };
127
128 static noinline void __init cardhu_bt_rfkill(void)
129 {
130         platform_device_register(&cardhu_bcm4329_rfkill_device);
131
132         return;
133 }
134 #else
135 static inline void cardhu_bt_rfkill(void) { }
136 #endif
137
138 #ifdef CONFIG_BT_BLUESLEEP
139 static noinline void __init tegra_setup_bluesleep(void)
140 {
141         struct platform_device *pdev = NULL;
142         struct resource *res;
143
144         pdev = platform_device_alloc("bluesleep", 0);
145         if (!pdev) {
146                 pr_err("unable to allocate platform device for bluesleep");
147                 return;
148         }
149
150         res = kzalloc(sizeof(struct resource) * 3, GFP_KERNEL);
151         if (!res) {
152                 pr_err("unable to allocate resource for bluesleep\n");
153                 goto err_free_dev;
154         }
155
156         res[0].name   = "gpio_host_wake";
157         res[0].start  = TEGRA_GPIO_PU6;
158         res[0].end    = TEGRA_GPIO_PU6;
159         res[0].flags  = IORESOURCE_IO;
160
161         res[1].name   = "gpio_ext_wake";
162         res[1].start  = TEGRA_GPIO_PU1;
163         res[1].end    = TEGRA_GPIO_PU1;
164         res[1].flags  = IORESOURCE_IO;
165
166         res[2].name   = "host_wake";
167         res[2].start  = gpio_to_irq(TEGRA_GPIO_PU6);
168         res[2].end    = gpio_to_irq(TEGRA_GPIO_PU6);
169         res[2].flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE ;
170
171         if (platform_device_add_resources(pdev, res, 3)) {
172                 pr_err("unable to add resources to bluesleep device\n");
173                 goto err_free_res;
174         }
175
176         if (platform_device_add(pdev)) {
177                 pr_err("unable to add bluesleep device\n");
178                 goto err_free_res;
179         }
180         tegra_gpio_enable(TEGRA_GPIO_PU6);
181         tegra_gpio_enable(TEGRA_GPIO_PU1);
182
183 return;
184
185 err_free_res:
186         kfree(res);
187 err_free_dev:
188         platform_device_put(pdev);
189         return;
190 }
191 #else
192 static inline void tegra_setup_bluesleep(void) { }
193 #endif
194
195 static __initdata struct tegra_clk_init_table cardhu_clk_init_table[] = {
196         /* name         parent          rate            enabled */
197         { "uarta",      "pll_p",        216000000,      true},
198         { "uartb",      "pll_p",        216000000,      false},
199         { "uartc",      "pll_p",        216000000,      false},
200         { "uartd",      "pll_p",        216000000,      false},
201         { "uarte",      "pll_p",        216000000,      false},
202         { "pll_m",      NULL,           0,              true},
203         { "hda",        "pll_p",        108000000,      false},
204         { "hda2codec_2x","pll_p",       48000000,       false},
205         { "pll_p_out4", "pll_p",        216000000,      true },
206         { "pwm",        "clk_32k",      32768,          false},
207         { "blink",      "clk_32k",      32768,          true},
208         { "pll_a",      NULL,           56448000,       true},
209         { "pll_a_out0", NULL,           11289600,       true},
210         { "i2s1",       "pll_a_out0",   11289600,       true},
211         { "i2s2",       "pll_a_out0",   11289600,       true},
212         { "audio",      "pll_a_out0",   11289600,       true},
213         { "audio_2x",   "audio",        22579200,       true},
214         { NULL,         NULL,           0,              0},
215 };
216
217 static struct tegra_i2c_platform_data cardhu_i2c1_platform_data = {
218         .adapter_nr     = 0,
219         .bus_count      = 1,
220         .bus_clk_rate   = { 100000, 0 },
221 };
222
223 static struct tegra_i2c_platform_data cardhu_i2c2_platform_data = {
224         .adapter_nr     = 1,
225         .bus_count      = 1,
226         .bus_clk_rate   = { 100000, 0 },
227         .is_clkon_always = true,
228 };
229
230 static struct tegra_i2c_platform_data cardhu_i2c3_platform_data = {
231         .adapter_nr     = 2,
232         .bus_count      = 1,
233         .bus_clk_rate   = { 100000, 0 },
234 };
235
236 static struct tegra_i2c_platform_data cardhu_i2c4_platform_data = {
237         .adapter_nr     = 3,
238         .bus_count      = 1,
239         .bus_clk_rate   = { 100000, 0 },
240 };
241
242 static struct tegra_i2c_platform_data cardhu_i2c5_platform_data = {
243         .adapter_nr     = 4,
244         .bus_count      = 1,
245         .bus_clk_rate   = { 100000, 0 },
246 };
247
248
249 struct tegra_wired_jack_conf audio_wr_jack_conf = {
250         .hp_det_n = TEGRA_GPIO_PW2,
251         .en_mic_ext = TEGRA_GPIO_PX1,
252         .en_mic_int = TEGRA_GPIO_PX0,
253 };
254
255 static void cardhu_i2c_init(void)
256 {
257         tegra_i2c_device1.dev.platform_data = &cardhu_i2c1_platform_data;
258         tegra_i2c_device2.dev.platform_data = &cardhu_i2c2_platform_data;
259         tegra_i2c_device3.dev.platform_data = &cardhu_i2c3_platform_data;
260         tegra_i2c_device4.dev.platform_data = &cardhu_i2c4_platform_data;
261         tegra_i2c_device5.dev.platform_data = &cardhu_i2c5_platform_data;
262
263         platform_device_register(&tegra_i2c_device5);
264         platform_device_register(&tegra_i2c_device4);
265         platform_device_register(&tegra_i2c_device3);
266         platform_device_register(&tegra_i2c_device2);
267         platform_device_register(&tegra_i2c_device1);
268 }
269
270 static struct resource tegra_rtc_resources[] = {
271         [0] = {
272                 .start = TEGRA_RTC_BASE,
273                 .end = TEGRA_RTC_BASE + TEGRA_RTC_SIZE - 1,
274                 .flags = IORESOURCE_MEM,
275         },
276         [1] = {
277                 .start = INT_RTC,
278                 .end = INT_RTC,
279                 .flags = IORESOURCE_IRQ,
280         },
281 };
282
283 static struct platform_device tegra_rtc_device = {
284         .name = "tegra_rtc",
285         .id   = -1,
286         .resource = tegra_rtc_resources,
287         .num_resources = ARRAY_SIZE(tegra_rtc_resources),
288 };
289
290 static struct platform_device tegra_camera = {
291         .name = "tegra_camera",
292         .id = -1,
293 };
294
295 static struct platform_device *cardhu_devices[] __initdata = {
296         &debug_uart,
297         &tegra_uartb_device,
298         &tegra_uartc_device,
299         &tegra_uartd_device,
300         &tegra_uarte_device,
301         &pmu_device,
302         &tegra_rtc_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 };
315
316 static int __init cardhu_touch_init(void)
317 {
318         return 0;
319 }
320
321 static struct usb_phy_plat_data tegra_usb_phy_pdata[] = {
322         [0] = {
323                         .instance = 0,
324                         .vbus_gpio = -1,
325                         .vbus_reg_supply = "vdd_vbus_micro_usb",
326         },
327         [1] = {
328                         .instance = 1,
329                         .vbus_gpio = -1,
330         },
331         [2] = {
332                         .instance = 2,
333                         .vbus_gpio = -1,
334                         .vbus_reg_supply = "vdd_vbus_typea_usb",
335         },
336 };
337
338
339 static struct tegra_ehci_platform_data tegra_ehci_pdata[] = {
340         [0] = {
341                         .phy_config = &utmi_phy_config[0],
342                         .operating_mode = TEGRA_USB_HOST,
343                         .power_down_on_bus_suspend = 1,
344         },
345         [1] = {
346                         .phy_config = &utmi_phy_config[1],
347                         .operating_mode = TEGRA_USB_HOST,
348                         .power_down_on_bus_suspend = 1,
349         },
350         [2] = {
351                         .phy_config = &utmi_phy_config[2],
352                         .operating_mode = TEGRA_USB_HOST,
353                         .power_down_on_bus_suspend = 1,
354         },
355 };
356
357 struct platform_device *tegra_usb_otg_host_register(void)
358 {
359         struct platform_device *pdev;
360         void *platform_data;
361         int val;
362
363         pdev = platform_device_alloc(tegra_ehci1_device.name,
364                 tegra_ehci1_device.id);
365         if (!pdev)
366                 return NULL;
367
368         val = platform_device_add_resources(pdev, tegra_ehci1_device.resource,
369                 tegra_ehci1_device.num_resources);
370         if (val)
371                 goto error;
372
373         pdev->dev.dma_mask =  tegra_ehci1_device.dev.dma_mask;
374         pdev->dev.coherent_dma_mask = tegra_ehci1_device.dev.coherent_dma_mask;
375
376         platform_data = kmalloc(sizeof(struct tegra_ehci_platform_data),
377                 GFP_KERNEL);
378         if (!platform_data)
379                 goto error;
380
381         memcpy(platform_data, &tegra_ehci_pdata[0],
382                                 sizeof(struct tegra_ehci_platform_data));
383         pdev->dev.platform_data = platform_data;
384
385         val = platform_device_add(pdev);
386         if (val)
387                 goto error_add;
388
389         return pdev;
390
391 error_add:
392         kfree(platform_data);
393 error:
394         pr_err("%s: failed to add the host contoller device\n", __func__);
395         platform_device_put(pdev);
396         return NULL;
397 }
398
399 void tegra_usb_otg_host_unregister(struct platform_device *pdev)
400 {
401         platform_device_unregister(pdev);
402 }
403
404 static struct tegra_otg_platform_data tegra_otg_pdata = {
405         .host_register = &tegra_usb_otg_host_register,
406         .host_unregister = &tegra_usb_otg_host_unregister,
407 };
408
409 static void cardhu_usb_init(void)
410 {
411         tegra_usb_phy_init(tegra_usb_phy_pdata, ARRAY_SIZE(tegra_usb_phy_pdata));
412
413         tegra_otg_device.dev.platform_data = &tegra_otg_pdata;
414         platform_device_register(&tegra_otg_device);
415
416         tegra_ehci2_device.dev.platform_data = &tegra_ehci_pdata[1];
417         platform_device_register(&tegra_ehci2_device);
418
419
420         tegra_ehci3_device.dev.platform_data = &tegra_ehci_pdata[2];
421         platform_device_register(&tegra_ehci3_device);
422
423 }
424
425 static void cardhu_gps_init(void)
426 {
427         tegra_gpio_enable(TEGRA_GPIO_PU2);
428         tegra_gpio_enable(TEGRA_GPIO_PU3);
429 }
430
431 static void cardhu_modem_init(void)
432 {
433         tegra_gpio_enable(TEGRA_GPIO_PH5);
434 }
435
436 #ifdef CONFIG_SATA_AHCI_TEGRA
437 static void cardhu_sata_init(void)
438 {
439         platform_device_register(&tegra_sata_device);
440 }
441 #else
442 static void cardhu_sata_init(void) { }
443 #endif
444
445 static void __init tegra_cardhu_init(void)
446 {
447         tegra_common_init();
448         tegra_clk_init_from_table(cardhu_clk_init_table);
449         cardhu_pinmux_init();
450         cardhu_i2c_init();
451         cardhu_usb_init();
452         platform_add_devices(cardhu_devices, ARRAY_SIZE(cardhu_devices));
453         cardhu_sdhci_init();
454         cardhu_regulator_init();
455         cardhu_gpio_switch_regulator_init();
456         cardhu_suspend_init();
457         cardhu_power_off_init();
458         cardhu_touch_init();
459         cardhu_gps_init();
460         cardhu_modem_init();
461         cardhu_kbc_init();
462         cardhu_scroll_init();
463         cardhu_keys_init();
464         cardhu_panel_init();
465         cardhu_sensors_init();
466         cardhu_bt_rfkill();
467         tegra_setup_bluesleep();
468         cardhu_sata_init();
469         audio_wired_jack_init();
470         cardhu_pins_state_init();
471         cardhu_emc_init();
472 }
473
474 static void __init tegra_cardhu_reserve(void)
475 {
476         tegra_reserve(SZ_128M, SZ_4M, SZ_8M);
477 }
478
479 MACHINE_START(CARDHU, "cardhu")
480         .boot_params    = 0x80000100,
481         .phys_io        = IO_APB_PHYS,
482         .io_pg_offst    = ((IO_APB_VIRT) >> 18) & 0xfffc,
483         .init_irq       = tegra_init_irq,
484         .init_machine   = tegra_cardhu_init,
485         .map_io         = tegra_map_common_io,
486         .reserve        = tegra_cardhu_reserve,
487         .timer          = &tegra_timer,
488 MACHINE_END