ARM: tegra: whistler: enable spi-slave based modem.
[linux-2.6.git] / arch / arm / mach-tegra / board-whistler.c
1 /*
2  * arch/arm/mach-tegra/board-whistler.c
3  *
4  * Copyright (c) 2010 - 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/gpio_scrollwheel.h>
35 #include <linux/input.h>
36 #include <linux/platform_data/tegra_usb.h>
37 #include <linux/mfd/max8907c.h>
38 #include <linux/memblock.h>
39
40 #include <mach/clk.h>
41 #include <mach/iomap.h>
42 #include <mach/irqs.h>
43 #include <mach/pinmux.h>
44 #include <mach/iomap.h>
45 #include <mach/io.h>
46
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-whistler.h"
54 #include "devices.h"
55 #include "gpio-names.h"
56 #include "fuse.h"
57 #include "board-whistler-baseband.h"
58
59 static struct plat_serial8250_port debug_uart_platform_data[] = {
60         {
61                 .membase        = IO_ADDRESS(TEGRA_UARTA_BASE),
62                 .mapbase        = TEGRA_UARTA_BASE,
63                 .irq            = INT_UARTA,
64                 .flags          = UPF_BOOT_AUTOCONF | UPF_FIXED_TYPE,
65                 .type           = PORT_TEGRA,
66                 .iotype         = UPIO_MEM,
67                 .regshift       = 2,
68                 .uartclk        = 216000000,
69         }, {
70                 .flags          = 0,
71         }
72 };
73
74 static struct platform_device debug_uart = {
75         .name = "serial8250",
76         .id = PLAT8250_DEV_PLATFORM,
77         .dev = {
78                 .platform_data = debug_uart_platform_data,
79         },
80 };
81
82 #ifdef CONFIG_BCM4329_RFKILL
83
84 static struct resource whistler_bcm4329_rfkill_resources[] = {
85         {
86                 .name   = "bcm4329_nshutdown_gpio",
87                 .start  = TEGRA_GPIO_PU0,
88                 .end    = TEGRA_GPIO_PU0,
89                 .flags  = IORESOURCE_IO,
90         },
91 };
92
93 static struct platform_device whistler_bcm4329_rfkill_device = {
94         .name           = "bcm4329_rfkill",
95         .id             = -1,
96         .num_resources  = ARRAY_SIZE(whistler_bcm4329_rfkill_resources),
97         .resource       = whistler_bcm4329_rfkill_resources,
98 };
99
100 static noinline void __init whistler_bt_rfkill(void)
101 {
102         platform_device_register(&whistler_bcm4329_rfkill_device);
103         return;
104 }
105 #else
106 static inline void whistler_bt_rfkill(void) { }
107 #endif
108
109 static struct tegra_utmip_config utmi_phy_config[] = {
110         [0] = {
111                         .hssync_start_delay = 0,
112                         .idle_wait_delay = 17,
113                         .elastic_limit = 16,
114                         .term_range_adj = 6,
115                         .xcvr_setup = 15,
116                         .xcvr_lsfslew = 2,
117                         .xcvr_lsrslew = 2,
118                 },
119         [1] = {
120                         .hssync_start_delay = 0,
121                         .idle_wait_delay = 17,
122                         .elastic_limit = 16,
123                         .term_range_adj = 6,
124                         .xcvr_setup = 8,
125                         .xcvr_lsfslew = 2,
126                         .xcvr_lsrslew = 2,
127                 },
128 };
129
130 static struct tegra_ulpi_config ulpi_phy_config = {
131         .reset_gpio = TEGRA_GPIO_PG2,
132         .clk = "clk_dev2",
133         .inf_type = TEGRA_USB_LINK_ULPI,
134 };
135
136 static __initdata struct tegra_clk_init_table whistler_clk_init_table[] = {
137         /* name         parent          rate            enabled */
138         { "uarta",      "pll_p",        216000000,      true},
139         { "uartc",      "pll_m",        600000000,      false},
140         { "pwm",        "clk_32k",      32768,          false},
141         { "kbc",        "clk_32k",      32768,          true},
142         { "sdmmc2",     "pll_p",        25000000,       false},
143         { NULL,         NULL,           0,              0},
144 };
145
146 static struct tegra_i2c_platform_data whistler_i2c1_platform_data = {
147         .adapter_nr     = 0,
148         .bus_count      = 1,
149         .bus_clk_rate   = { 400000, 0 },
150 };
151
152 static const struct tegra_pingroup_config i2c2_ddc = {
153         .pingroup       = TEGRA_PINGROUP_DDC,
154         .func           = TEGRA_MUX_I2C2,
155 };
156
157 static const struct tegra_pingroup_config i2c2_gen2 = {
158         .pingroup       = TEGRA_PINGROUP_PTA,
159         .func           = TEGRA_MUX_I2C2,
160 };
161
162 static struct tegra_i2c_platform_data whistler_i2c2_platform_data = {
163         .adapter_nr     = 1,
164         .bus_count      = 2,
165         .bus_clk_rate   = { 400000, 100000 },
166         .bus_mux        = { &i2c2_ddc, &i2c2_gen2 },
167         .bus_mux_len    = { 1, 1 },
168 };
169
170 static struct tegra_i2c_platform_data whistler_i2c3_platform_data = {
171         .adapter_nr     = 3,
172         .bus_count      = 1,
173         .bus_clk_rate   = { 400000, 0 },
174 };
175
176 static struct tegra_i2c_platform_data whistler_dvc_platform_data = {
177         .adapter_nr     = 4,
178         .bus_count      = 1,
179         .bus_clk_rate   = { 400000, 0 },
180         .is_dvc         = true,
181 };
182
183 static void whistler_i2c_init(void)
184 {
185         tegra_i2c_device1.dev.platform_data = &whistler_i2c1_platform_data;
186         tegra_i2c_device2.dev.platform_data = &whistler_i2c2_platform_data;
187         tegra_i2c_device3.dev.platform_data = &whistler_i2c3_platform_data;
188         tegra_i2c_device4.dev.platform_data = &whistler_dvc_platform_data;
189
190         platform_device_register(&tegra_i2c_device4);
191         platform_device_register(&tegra_i2c_device3);
192         platform_device_register(&tegra_i2c_device2);
193         platform_device_register(&tegra_i2c_device1);
194 }
195
196 #define GPIO_SCROLL(_pinaction, _gpio, _desc)   \
197 {       \
198         .pinaction = GPIO_SCROLLWHEEL_PIN_##_pinaction, \
199         .gpio = TEGRA_GPIO_##_gpio,     \
200         .desc = _desc,  \
201         .active_low = 1,        \
202         .debounce_interval = 2, \
203 }
204
205 static struct gpio_scrollwheel_button scroll_keys[] = {
206         [0] = GPIO_SCROLL(ONOFF, PR3, "sw_onoff"),
207         [1] = GPIO_SCROLL(PRESS, PQ5, "sw_press"),
208         [2] = GPIO_SCROLL(ROT1, PQ3, "sw_rot1"),
209         [3] = GPIO_SCROLL(ROT2, PQ4, "sw_rot2"),
210 };
211
212 static struct gpio_scrollwheel_platform_data whistler_scroll_platform_data = {
213         .buttons = scroll_keys,
214         .nbuttons = ARRAY_SIZE(scroll_keys),
215 };
216
217 static struct platform_device whistler_scroll_device = {
218         .name   = "alps-gpio-scrollwheel",
219         .id     = 0,
220         .dev    = {
221                 .platform_data  = &whistler_scroll_platform_data,
222         },
223 };
224
225 static struct platform_device tegra_camera = {
226         .name = "tegra_camera",
227         .id = -1,
228 };
229
230 static struct platform_device *whistler_devices[] __initdata = {
231         &tegra_uartb_device,
232         &tegra_uartc_device,
233         &pmu_device,
234         &tegra_udc_device,
235         &tegra_gart_device,
236         &tegra_wdt_device,
237         &tegra_avp_device,
238         &whistler_scroll_device,
239         &tegra_camera,
240 };
241
242 static int __init whistler_scroll_init(void)
243 {
244         int i;
245         for (i = 0; i < ARRAY_SIZE(scroll_keys); i++)
246                 tegra_gpio_enable(scroll_keys[i].gpio);
247
248         return 0;
249 }
250
251 static struct usb_phy_plat_data tegra_usb_phy_pdata[] = {
252         [0] = {
253                         .instance = 0,
254                         .vbus_irq = MAX8907C_INT_BASE + MAX8907C_IRQ_VCHG_DC_R,
255                         .vbus_gpio = TEGRA_GPIO_PN6,
256         },
257         [1] = {
258                         .instance = 1,
259                         .vbus_gpio = -1,
260         },
261         [2] = {
262                         .instance = 2,
263                         .vbus_gpio = -1,
264         },
265 };
266
267 static struct tegra_ehci_platform_data tegra_ehci_pdata[] = {
268         [0] = {
269                         .phy_config = &utmi_phy_config[0],
270                         .operating_mode = TEGRA_USB_HOST,
271                         .power_down_on_bus_suspend = 1,
272                 },
273         [1] = {
274                         .phy_config = &ulpi_phy_config,
275                         .operating_mode = TEGRA_USB_HOST,
276                         .power_down_on_bus_suspend = 1,
277                 },
278         [2] = {
279                         .phy_config = &utmi_phy_config[1],
280                         .operating_mode = TEGRA_USB_HOST,
281                         .power_down_on_bus_suspend = 1,
282         },
283 };
284
285 static struct platform_device *tegra_usb_otg_host_register(void)
286 {
287         struct platform_device *pdev;
288         void *platform_data;
289         int val;
290
291         pdev = platform_device_alloc(tegra_ehci1_device.name,
292                         tegra_ehci1_device.id);
293         if (!pdev)
294                 return NULL;
295
296         val = platform_device_add_resources(pdev, tegra_ehci1_device.resource,
297                 tegra_ehci1_device.num_resources);
298         if (val)
299                 goto error;
300
301         pdev->dev.dma_mask =  tegra_ehci1_device.dev.dma_mask;
302         pdev->dev.coherent_dma_mask = tegra_ehci1_device.dev.coherent_dma_mask;
303
304         platform_data = kmalloc(sizeof(struct tegra_ehci_platform_data),
305                                 GFP_KERNEL);
306         if (!platform_data)
307                 goto error;
308
309         memcpy(platform_data, &tegra_ehci_pdata[0],
310                                 sizeof(struct tegra_ehci_platform_data));
311         pdev->dev.platform_data = platform_data;
312
313         val = platform_device_add(pdev);
314         if (val)
315                 goto error_add;
316
317         return pdev;
318
319 error_add:
320         kfree(platform_data);
321 error:
322         pr_err("%s: failed to add the host contoller device\n", __func__);
323         platform_device_put(pdev);
324         return NULL;
325 }
326
327 static void tegra_usb_otg_host_unregister(struct platform_device *pdev)
328 {
329         kfree(pdev->dev.platform_data);
330         platform_device_unregister(pdev);
331 }
332
333 static struct tegra_otg_platform_data tegra_otg_pdata = {
334         .host_register = &tegra_usb_otg_host_register,
335         .host_unregister = &tegra_usb_otg_host_unregister,
336 };
337
338 static int __init whistler_gps_init(void)
339 {
340         tegra_gpio_enable(TEGRA_GPIO_PU4);
341         return 0;
342 }
343
344 static void whistler_power_off(void)
345 {
346         int ret;
347
348         ret = max8907c_power_off();
349         if (ret)
350                 pr_err("whistler: failed to power off\n");
351
352         while (1);
353 }
354
355 static void __init whistler_power_off_init(void)
356 {
357         pm_power_off = whistler_power_off;
358 }
359
360 static void whistler_usb_init(void)
361 {
362         tegra_usb_phy_init(tegra_usb_phy_pdata, ARRAY_SIZE(tegra_usb_phy_pdata));
363
364         tegra_otg_device.dev.platform_data = &tegra_otg_pdata;
365         platform_device_register(&tegra_otg_device);
366
367         tegra_ehci3_device.dev.platform_data = &tegra_ehci_pdata[2];
368         platform_device_register(&tegra_ehci3_device);
369 }
370
371 static void __init tegra_whistler_init(void)
372 {
373         char serial[20];
374
375         tegra_common_init();
376         tegra_clk_init_from_table(whistler_clk_init_table);
377         whistler_pinmux_init();
378         whistler_i2c_init();
379         if (is_tegra_debug_uartport_hs() == true)
380                 platform_device_register(&tegra_uarta_device);
381         else
382                 platform_device_register(&debug_uart);
383         platform_add_devices(whistler_devices, ARRAY_SIZE(whistler_devices));
384
385         whistler_sdhci_init();
386         whistler_regulator_init();
387         whistler_panel_init();
388         whistler_sensors_init();
389         whistler_kbc_init();
390         whistler_bt_rfkill();
391         whistler_gps_init();
392         whistler_usb_init();
393         whistler_scroll_init();
394         whistler_power_off_init();
395         whistler_emc_init();
396         whistler_baseband_init();
397 }
398
399 int __init tegra_whistler_protected_aperture_init(void)
400 {
401         tegra_protected_aperture_init(tegra_grhost_aperture);
402         return 0;
403 }
404
405 void __init tegra_whistler_reserve(void)
406 {
407         if (memblock_reserve(0x0, 4096) < 0)
408                 pr_warn("Cannot reserve first 4K of memory for safety\n");
409
410         tegra_reserve(SZ_128M, SZ_8M, SZ_16M);
411 }
412
413 MACHINE_START(WHISTLER, "whistler")
414         .boot_params    = 0x00000100,
415         .phys_io        = IO_APB_PHYS,
416         .io_pg_offst    = ((IO_APB_VIRT) >> 18) & 0xfffc,
417         .init_irq       = tegra_init_irq,
418         .init_machine   = tegra_whistler_init,
419         .map_io         = tegra_map_common_io,
420         .reserve        = tegra_whistler_reserve,
421         .timer          = &tegra_timer,
422 MACHINE_END