arm: tegra: nvmap: Forcing to convert CarveOut requests to IOVM
[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         { "pwm",        "clk_32k",      32768,          false},
206         { "blink",      "clk_32k",      32768,          true},
207         { "pll_a",      NULL,           56448000,       true},
208         { "pll_a_out0", NULL,           11289600,       true},
209         { "i2s1",       "pll_a_out0",   11289600,       true},
210         { "i2s2",       "pll_a_out0",   11289600,       true},
211         { "audio",      "pll_a_out0",   11289600,       true},
212         { "audio_2x",   "audio",        22579200,       true},
213         { NULL,         NULL,           0,              0},
214 };
215
216 static struct tegra_i2c_platform_data cardhu_i2c1_platform_data = {
217         .adapter_nr     = 0,
218         .bus_count      = 1,
219         .bus_clk_rate   = { 100000, 0 },
220 };
221
222 static struct tegra_i2c_platform_data cardhu_i2c2_platform_data = {
223         .adapter_nr     = 1,
224         .bus_count      = 1,
225         .bus_clk_rate   = { 100000, 0 },
226         .is_clkon_always = true,
227 };
228
229 static struct tegra_i2c_platform_data cardhu_i2c3_platform_data = {
230         .adapter_nr     = 2,
231         .bus_count      = 1,
232         .bus_clk_rate   = { 100000, 0 },
233 };
234
235 static struct tegra_i2c_platform_data cardhu_i2c4_platform_data = {
236         .adapter_nr     = 3,
237         .bus_count      = 1,
238         .bus_clk_rate   = { 100000, 0 },
239 };
240
241 static struct tegra_i2c_platform_data cardhu_i2c5_platform_data = {
242         .adapter_nr     = 4,
243         .bus_count      = 1,
244         .bus_clk_rate   = { 100000, 0 },
245 };
246
247
248 struct tegra_wired_jack_conf audio_wr_jack_conf = {
249         .hp_det_n = TEGRA_GPIO_PW2,
250         .en_mic_ext = TEGRA_GPIO_PX1,
251         .en_mic_int = TEGRA_GPIO_PX0,
252 };
253
254 static void cardhu_i2c_init(void)
255 {
256         tegra_i2c_device1.dev.platform_data = &cardhu_i2c1_platform_data;
257         tegra_i2c_device2.dev.platform_data = &cardhu_i2c2_platform_data;
258         tegra_i2c_device3.dev.platform_data = &cardhu_i2c3_platform_data;
259         tegra_i2c_device4.dev.platform_data = &cardhu_i2c4_platform_data;
260         tegra_i2c_device5.dev.platform_data = &cardhu_i2c5_platform_data;
261
262         platform_device_register(&tegra_i2c_device5);
263         platform_device_register(&tegra_i2c_device4);
264         platform_device_register(&tegra_i2c_device3);
265         platform_device_register(&tegra_i2c_device2);
266         platform_device_register(&tegra_i2c_device1);
267 }
268
269 #if defined(CONFIG_RTC_DRV_TEGRA)
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 #endif
290
291 static struct platform_device tegra_camera = {
292         .name = "tegra_camera",
293         .id = -1,
294 };
295
296 static struct platform_device *cardhu_devices[] __initdata = {
297         &debug_uart,
298         &tegra_uartb_device,
299         &tegra_uartc_device,
300         &tegra_uartd_device,
301         &tegra_uarte_device,
302         &pmu_device,
303 #if defined(CONFIG_RTC_DRV_TEGRA)
304         &tegra_rtc_device,
305 #endif
306         &tegra_udc_device,
307 #if defined(CONFIG_SND_HDA_TEGRA)
308         &tegra_hda_device,
309 #endif
310 #if defined(CONFIG_TEGRA_IOVMM_SMMU)
311         &tegra_smmu_device,
312 #endif
313         &tegra_wdt_device,
314         &tegra_avp_device,
315         &tegra_camera,
316         &tegra_spi_device4,
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 = PM267_SMSC4640_HSIC_HUB_RESET_GPIO,
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 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 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) || (bi.board_id == BOARD_E1186)) {
435                 tegra_ehci2_device.dev.platform_data = &tegra_ehci_uhsic_pdata;
436         } else {
437                 tegra_ehci2_device.dev.platform_data = &tegra_ehci_pdata[1];
438         }
439         platform_device_register(&tegra_ehci2_device);
440
441         tegra_ehci3_device.dev.platform_data = &tegra_ehci_pdata[2];
442         platform_device_register(&tegra_ehci3_device);
443
444 }
445
446 static void cardhu_gps_init(void)
447 {
448         tegra_gpio_enable(TEGRA_GPIO_PU2);
449         tegra_gpio_enable(TEGRA_GPIO_PU3);
450 }
451
452 static void cardhu_modem_init(void)
453 {
454         tegra_gpio_enable(TEGRA_GPIO_PH5);
455 }
456
457 #ifdef CONFIG_SATA_AHCI_TEGRA
458 static void cardhu_sata_init(void)
459 {
460         platform_device_register(&tegra_sata_device);
461 }
462 #else
463 static void cardhu_sata_init(void) { }
464 #endif
465
466 static void __init tegra_cardhu_init(void)
467 {
468         tegra_common_init();
469         tegra_clk_init_from_table(cardhu_clk_init_table);
470         cardhu_pinmux_init();
471         cardhu_i2c_init();
472         cardhu_usb_init();
473         platform_add_devices(cardhu_devices, ARRAY_SIZE(cardhu_devices));
474         cardhu_sdhci_init();
475         cardhu_regulator_init();
476         cardhu_gpio_switch_regulator_init();
477         cardhu_suspend_init();
478         cardhu_power_off_init();
479         cardhu_touch_init();
480         cardhu_gps_init();
481         cardhu_modem_init();
482         cardhu_kbc_init();
483         cardhu_scroll_init();
484         cardhu_keys_init();
485         cardhu_panel_init();
486         cardhu_sensors_init();
487         cardhu_bt_rfkill();
488         tegra_setup_bluesleep();
489         cardhu_sata_init();
490         audio_wired_jack_init();
491         cardhu_pins_state_init();
492         cardhu_emc_init();
493 }
494
495 static void __init tegra_cardhu_reserve(void)
496 {
497 #if defined(CONFIG_NVMAP_CONVERT_CARVEOUT_TO_IOVMM)
498         tegra_reserve(0, SZ_4M, SZ_8M);
499 #else
500         tegra_reserve(SZ_128M, SZ_4M, SZ_8M);
501 #endif
502 }
503
504 MACHINE_START(CARDHU, "cardhu")
505         .boot_params    = 0x80000100,
506         .phys_io        = IO_APB_PHYS,
507         .io_pg_offst    = ((IO_APB_VIRT) >> 18) & 0xfffc,
508         .init_irq       = tegra_init_irq,
509         .init_machine   = tegra_cardhu_init,
510         .map_io         = tegra_map_common_io,
511         .reserve        = tegra_cardhu_reserve,
512         .timer          = &tegra_timer,
513 MACHINE_END