33fe754453469ead95784b4b7bd7d2d9824f9084
[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-2012 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/synaptics_i2c_rmi.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 #include <linux/tegra_uart.h>
40 #include <linux/rfkill-gpio.h>
41
42 #include <mach/clk.h>
43 #include <mach/iomap.h>
44 #include <mach/irqs.h>
45 #include <mach/pinmux.h>
46 #include <mach/pinmux-tegra20.h>
47 #include <mach/iomap.h>
48 #include <mach/io.h>
49 #include <mach/i2s.h>
50 #include <mach/tegra_asoc_pdata.h>
51 #include <mach/gpio-tegra.h>
52
53 #include <sound/tlv320aic326x.h>
54
55 #include <asm/hardware/gic.h>
56 #include <asm/mach-types.h>
57 #include <asm/mach/arch.h>
58 #include <asm/hardware/gic.h>
59
60 #include <mach/usb_phy.h>
61
62 #include "board.h"
63 #include "clock.h"
64 #include "board-whistler.h"
65 #include "devices.h"
66 #include "gpio-names.h"
67 #include "fuse.h"
68 #include "pm.h"
69 #include "board-whistler-baseband.h"
70 #include "common.h"
71
72 #define SZ_3M (SZ_1M + SZ_2M)
73 #define SZ_152M (SZ_128M + SZ_16M + SZ_8M)
74 #define USB1_VBUS_GPIO TCA6416_GPIO_BASE
75
76 static struct platform_device *whistler_uart_devices[] __initdata = {
77         &tegra_uarta_device,
78         &tegra_uartb_device,
79         &tegra_uartc_device,
80 };
81
82 struct uart_clk_parent uart_parent_clk[] = {
83         [0] = {.name = "pll_p"},
84         [1] = {.name = "pll_m"},
85         [2] = {.name = "clk_m"},
86 };
87
88 static struct tegra_uart_platform_data whistler_uart_pdata;
89
90 static void __init uart_debug_init(void)
91 {
92         unsigned long rate;
93         struct clk *debug_uart_clk;
94         struct clk *c;
95         int modem_id = tegra_get_modem_id();
96
97         if (modem_id == 0x1) {
98                 /* UARTB is the debug port. */
99                 pr_info("Selecting UARTB as the debug console\n");
100                 whistler_uart_devices[1] = &debug_uartb_device;
101                 debug_uart_port_base = ((struct plat_serial8250_port *)(
102                         debug_uartb_device.dev.platform_data))->mapbase;
103                 debug_uart_clk = clk_get_sys("serial8250.0", "uartb");
104
105                 /* Clock enable for the debug channel */
106                 if (!IS_ERR_OR_NULL(debug_uart_clk)) {
107                         rate = ((struct plat_serial8250_port *)(
108                         debug_uartb_device.dev.platform_data))->uartclk;
109                         pr_info("The debug console clock name is %s\n",
110                                                 debug_uart_clk->name);
111                         c = tegra_get_clock_by_name("pll_p");
112                         if (IS_ERR_OR_NULL(c))
113                                 pr_err("Not getting the parent clock pll_p\n");
114                         else
115                                 clk_set_parent(debug_uart_clk, c);
116
117                         clk_enable(debug_uart_clk);
118                         clk_set_rate(debug_uart_clk, rate);
119                 } else {
120                         pr_err("Not getting the clock %s for debug console\n",
121                                                 debug_uart_clk->name);
122                 }
123         } else {
124                 /* UARTA is the debug port. */
125                 pr_info("Selecting UARTA as the debug console\n");
126                 whistler_uart_devices[0] = &debug_uarta_device;
127                 debug_uart_port_base = ((struct plat_serial8250_port *)(
128                         debug_uarta_device.dev.platform_data))->mapbase;
129                 debug_uart_clk = clk_get_sys("serial8250.0", "uarta");
130
131                 /* Clock enable for the debug channel */
132                 if (!IS_ERR_OR_NULL(debug_uart_clk)) {
133                         rate = ((struct plat_serial8250_port *)(
134                         debug_uarta_device.dev.platform_data))->uartclk;
135                         pr_info("The debug console clock name is %s\n",
136                                                 debug_uart_clk->name);
137                         c = tegra_get_clock_by_name("pll_p");
138                         if (IS_ERR_OR_NULL(c))
139                                 pr_err("Not getting the parent clock pll_p\n");
140                         else
141                                 clk_set_parent(debug_uart_clk, c);
142
143                         clk_enable(debug_uart_clk);
144                         clk_set_rate(debug_uart_clk, rate);
145                 } else {
146                         pr_err("Not getting the clock %s for debug console\n",
147                                                 debug_uart_clk->name);
148                 }
149         }
150 }
151
152 static void __init whistler_uart_init(void)
153 {
154         int i;
155         struct clk *c;
156
157         for (i = 0; i < ARRAY_SIZE(uart_parent_clk); ++i) {
158                 c = tegra_get_clock_by_name(uart_parent_clk[i].name);
159                 if (IS_ERR_OR_NULL(c)) {
160                         pr_err("Not able to get the clock for %s\n",
161                                                 uart_parent_clk[i].name);
162                         continue;
163                 }
164                 uart_parent_clk[i].parent_clk = c;
165                 uart_parent_clk[i].fixed_clk_rate = clk_get_rate(c);
166         }
167         whistler_uart_pdata.parent_clk_list = uart_parent_clk;
168         whistler_uart_pdata.parent_clk_count = ARRAY_SIZE(uart_parent_clk);
169
170         tegra_uarta_device.dev.platform_data = &whistler_uart_pdata;
171         tegra_uartb_device.dev.platform_data = &whistler_uart_pdata;
172         tegra_uartc_device.dev.platform_data = &whistler_uart_pdata;
173
174         if (!is_tegra_debug_uartport_hs())
175                 uart_debug_init();
176
177         platform_add_devices(whistler_uart_devices,
178                                 ARRAY_SIZE(whistler_uart_devices));
179 }
180 static struct rfkill_gpio_platform_data whistler_bt_rfkill_pdata[] = {
181         {
182                 .name           = "bt_rfkill",
183                 .shutdown_gpio  = TEGRA_GPIO_PU0,
184                 .reset_gpio     = TEGRA_GPIO_INVALID,
185                 .type           = RFKILL_TYPE_BLUETOOTH,
186         },
187 };
188
189 static struct platform_device whistler_bt_rfkill_device = {
190         .name = "rfkill_gpio",
191         .id   = -1,
192         .dev  = {
193                 .platform_data  = whistler_bt_rfkill_pdata,
194         },
195 };
196
197 static struct resource whistler_bluesleep_resources[] = {
198         [0] = {
199                 .name = "gpio_host_wake",
200                         .start  = TEGRA_GPIO_PU6,
201                         .end    = TEGRA_GPIO_PU6,
202                         .flags  = IORESOURCE_IO,
203         },
204         [1] = {
205                 .name = "gpio_ext_wake",
206                         .start  = TEGRA_GPIO_PU1,
207                         .end    = TEGRA_GPIO_PU1,
208                         .flags  = IORESOURCE_IO,
209         },
210         [2] = {
211                 .name = "host_wake",
212                         .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
213         },
214 };
215
216 static struct platform_device whistler_bluesleep_device = {
217         .name           = "bluesleep",
218         .id             = -1,
219         .num_resources  = ARRAY_SIZE(whistler_bluesleep_resources),
220         .resource       = whistler_bluesleep_resources,
221 };
222
223 static void __init whistler_setup_bluesleep(void)
224 {
225         whistler_bluesleep_resources[2].start =
226                 whistler_bluesleep_resources[2].end =
227                         gpio_to_irq(TEGRA_GPIO_PU6);
228         platform_device_register(&whistler_bluesleep_device);
229         return;
230 }
231
232 static __initdata struct tegra_clk_init_table whistler_clk_init_table[] = {
233         /* name         parent          rate            enabled */
234         { "pwm",        "clk_32k",      32768,          false},
235         { "kbc",        "clk_32k",      32768,          true},
236         { "sdmmc2",     "pll_p",        25000000,       false},
237         { "i2s1",       "pll_a_out0",   0,              false},
238         { "i2s2",       "pll_a_out0",   0,              false},
239         { "spdif_out",  "pll_a_out0",   0,              false},
240         { NULL,         NULL,           0,              0},
241 };
242
243 static struct tegra_i2c_platform_data whistler_i2c1_platform_data = {
244         .adapter_nr     = 0,
245         .bus_count      = 1,
246         .bus_clk_rate   = { 400000, 0 },
247         .scl_gpio               = {TEGRA_GPIO_PC4, 0},
248         .sda_gpio               = {TEGRA_GPIO_PC5, 0},
249         .arb_recovery = arb_lost_recovery,
250         .slave_addr = 0xFC,
251 };
252
253 static const struct tegra_pingroup_config i2c2_ddc = {
254         .pingroup       = TEGRA_PINGROUP_DDC,
255         .func           = TEGRA_MUX_I2C2,
256 };
257
258 static const struct tegra_pingroup_config i2c2_gen2 = {
259         .pingroup       = TEGRA_PINGROUP_PTA,
260         .func           = TEGRA_MUX_I2C2,
261 };
262
263 static struct tegra_i2c_platform_data whistler_i2c2_platform_data = {
264         .adapter_nr     = 1,
265         .bus_count      = 2,
266         .bus_clk_rate   = { 10000, 100000 },
267         .bus_mux        = { &i2c2_ddc, &i2c2_gen2 },
268         .bus_mux_len    = { 1, 1 },
269         .scl_gpio               = {0, TEGRA_GPIO_PT5},
270         .sda_gpio               = {0, TEGRA_GPIO_PT6},
271         .arb_recovery = arb_lost_recovery,
272         .slave_addr = 0xFC,
273 };
274
275 static struct tegra_i2c_platform_data whistler_i2c3_platform_data = {
276         .adapter_nr     = 3,
277         .bus_count      = 1,
278         .bus_clk_rate   = { 400000, 0 },
279         .scl_gpio               = {TEGRA_GPIO_PBB2, 0},
280         .sda_gpio               = {TEGRA_GPIO_PBB3, 0},
281         .arb_recovery = arb_lost_recovery,
282         .slave_addr = 0xFC,
283 };
284
285 static struct tegra_i2c_platform_data whistler_dvc_platform_data = {
286         .adapter_nr     = 4,
287         .bus_count      = 1,
288         .bus_clk_rate   = { 400000, 0 },
289         .is_dvc         = true,
290         .scl_gpio               = {TEGRA_GPIO_PZ6, 0},
291         .sda_gpio               = {TEGRA_GPIO_PZ7, 0},
292         .arb_recovery = arb_lost_recovery,
293 };
294
295 static struct aic326x_pdata whistler_aic3262_pdata = {
296         /* debounce time */
297         .debounce_time_ms = 512,
298 };
299
300 static struct i2c_board_info __initdata wm8753_board_info[] = {
301         {
302                 I2C_BOARD_INFO("wm8753", 0x1a),
303         },
304         {
305                 I2C_BOARD_INFO("aic3262-codec", 0x18),
306                 .platform_data = &whistler_aic3262_pdata,
307         },
308 };
309
310 static void whistler_i2c_init(void)
311 {
312         tegra_i2c_device1.dev.platform_data = &whistler_i2c1_platform_data;
313         tegra_i2c_device2.dev.platform_data = &whistler_i2c2_platform_data;
314         tegra_i2c_device3.dev.platform_data = &whistler_i2c3_platform_data;
315         tegra_i2c_device4.dev.platform_data = &whistler_dvc_platform_data;
316
317         platform_device_register(&tegra_i2c_device4);
318         platform_device_register(&tegra_i2c_device3);
319         platform_device_register(&tegra_i2c_device2);
320         platform_device_register(&tegra_i2c_device1);
321
322         wm8753_board_info[0].irq = wm8753_board_info[1].irq =
323                 gpio_to_irq(TEGRA_GPIO_HP_DET);
324         i2c_register_board_info(4, wm8753_board_info,
325                 ARRAY_SIZE(wm8753_board_info));
326 }
327
328 #define GPIO_SCROLL(_pinaction, _gpio, _desc)   \
329 {       \
330         .pinaction = GPIO_SCROLLWHEEL_PIN_##_pinaction, \
331         .gpio = TEGRA_GPIO_##_gpio,     \
332         .desc = _desc,  \
333         .active_low = 1,        \
334         .debounce_interval = 2, \
335 }
336
337 static struct gpio_scrollwheel_button scroll_keys[] = {
338         [0] = GPIO_SCROLL(ONOFF, PR3, "sw_onoff"),
339         [1] = GPIO_SCROLL(PRESS, PQ5, "sw_press"),
340         [2] = GPIO_SCROLL(ROT1, PQ3, "sw_rot1"),
341         [3] = GPIO_SCROLL(ROT2, PQ4, "sw_rot2"),
342 };
343
344 static struct gpio_scrollwheel_platform_data whistler_scroll_platform_data = {
345         .buttons = scroll_keys,
346         .nbuttons = ARRAY_SIZE(scroll_keys),
347 };
348
349 static struct platform_device whistler_scroll_device = {
350         .name   = "alps-gpio-scrollwheel",
351         .id     = 0,
352         .dev    = {
353                 .platform_data  = &whistler_scroll_platform_data,
354         },
355 };
356
357 static struct platform_device tegra_camera = {
358         .name = "tegra_camera",
359         .id = -1,
360 };
361
362 static struct tegra_asoc_platform_data whistler_audio_pdata = {
363         .gpio_spkr_en = -1,
364         .gpio_hp_det = TEGRA_GPIO_HP_DET,
365         .gpio_hp_mute = -1,
366         .gpio_int_mic_en = -1,
367         .gpio_ext_mic_en = -1,
368         .debounce_time_hp = 200,
369 };
370
371 static struct platform_device whistler_audio_aic326x_device = {
372         .name   = "tegra-snd-aic326x",
373         .id     = 0,
374         .dev    = {
375                 .platform_data  = &whistler_audio_pdata,
376         },
377 };
378
379 static struct platform_device whistler_audio_wm8753_device = {
380         .name   = "tegra-snd-wm8753",
381         .id     = 0,
382         .dev    = {
383                 .platform_data  = &whistler_audio_pdata,
384         },
385 };
386
387 static struct platform_device *whistler_devices[] __initdata = {
388         &tegra_pmu_device,
389         &tegra_udc_device,
390         &tegra_gart_device,
391         &tegra_aes_device,
392         &tegra_wdt_device,
393         &tegra_avp_device,
394         &whistler_scroll_device,
395         &tegra_camera,
396         &tegra_i2s_device1,
397         &tegra_i2s_device2,
398         &tegra_spdif_device,
399         &tegra_das_device,
400         &spdif_dit_device,
401         &bluetooth_dit_device,
402         &baseband_dit_device,
403         &whistler_bt_rfkill_device,
404         &tegra_pcm_device,
405         &whistler_audio_aic326x_device,
406         &whistler_audio_wm8753_device,
407 };
408
409 static struct synaptics_i2c_rmi_platform_data synaptics_pdata = {
410         .flags          = SYNAPTICS_FLIP_X | SYNAPTICS_FLIP_Y | SYNAPTICS_SWAP_XY,
411         .irqflags       = IRQF_TRIGGER_LOW,
412 };
413
414 static struct i2c_board_info whistler_i2c_touch_info[] = {
415         {
416                 I2C_BOARD_INFO("synaptics-rmi-ts", 0x20),
417                 .platform_data  = &synaptics_pdata,
418         },
419 };
420
421 static int __init whistler_touch_init(void)
422 {
423         whistler_i2c_touch_info[0].irq = gpio_to_irq(TEGRA_GPIO_PC6);
424         i2c_register_board_info(0, whistler_i2c_touch_info, 1);
425
426         return 0;
427 }
428
429 static struct tegra_usb_platform_data tegra_udc_pdata = {
430         .port_otg = true,
431         .has_hostpc = false,
432         .builtin_host_disabled = true,
433         .phy_intf = TEGRA_USB_PHY_INTF_UTMI,
434         .op_mode = TEGRA_USB_OPMODE_DEVICE,
435         .u_data.dev = {
436                 .vbus_pmu_irq = MAX8907C_INT_BASE + MAX8907C_IRQ_VCHG_DC_R,
437                 .vbus_gpio = -1,
438                 .charging_supported = false,
439                 .remote_wakeup_supported = false,
440         },
441         .u_cfg.utmi = {
442                 .hssync_start_delay = 0,
443                 .elastic_limit = 16,
444                 .idle_wait_delay = 17,
445                 .term_range_adj = 6,
446                 .xcvr_setup = 8,
447                 .xcvr_lsfslew = 2,
448                 .xcvr_lsrslew = 2,
449                 .xcvr_setup_offset = 0,
450                 .xcvr_use_fuses = 1,
451         },
452 };
453
454 static struct tegra_usb_platform_data tegra_ehci1_utmi_pdata = {
455         .port_otg = true,
456         .has_hostpc = false,
457         .builtin_host_disabled = true,
458         .phy_intf = TEGRA_USB_PHY_INTF_UTMI,
459         .op_mode        = TEGRA_USB_OPMODE_HOST,
460         .u_data.host = {
461                 .vbus_gpio = TEGRA_GPIO_PN6,
462                 .vbus_reg = NULL,
463                 .hot_plug = true,
464                 .remote_wakeup_supported = false,
465                 .power_off_on_suspend = true,
466         },
467         .u_cfg.utmi = {
468                 .hssync_start_delay = 9,
469                 .elastic_limit = 16,
470                 .idle_wait_delay = 17,
471                 .term_range_adj = 6,
472                 .xcvr_setup = 8,
473                 .xcvr_lsfslew = 2,
474                 .xcvr_lsrslew = 2,
475         },
476 };
477
478 static struct tegra_usb_otg_data tegra_otg_pdata = {
479         .ehci_device = &tegra_ehci1_device,
480         .ehci_pdata = &tegra_ehci1_utmi_pdata,
481 };
482
483 #define SERIAL_NUMBER_LENGTH 20
484 static void whistler_usb_init(void)
485 {
486         tegra_otg_device.dev.platform_data = &tegra_otg_pdata;
487         platform_device_register(&tegra_otg_device);
488
489         tegra_udc_device.dev.platform_data = &tegra_udc_pdata;
490 }
491
492 static void __init tegra_whistler_init(void)
493 {
494         int modem_id = tegra_get_modem_id();
495         tegra_clk_init_from_table(whistler_clk_init_table);
496         whistler_emc_init();
497         tegra_enable_pinmux();
498         whistler_pinmux_init();
499         whistler_i2c_init();
500         whistler_uart_init();
501         platform_add_devices(whistler_devices, ARRAY_SIZE(whistler_devices));
502         tegra_ram_console_debug_init();
503         whistler_sdhci_init();
504         whistler_regulator_init();
505         whistler_panel_init();
506         whistler_sensors_init();
507         whistler_touch_init();
508         whistler_kbc_init();
509         whistler_usb_init();
510         whistler_emc_init();
511         if (modem_id == 0x1)
512                 whistler_baseband_init();
513         whistler_setup_bluesleep();
514         tegra_release_bootloader_fb();
515 }
516
517 int __init tegra_whistler_protected_aperture_init(void)
518 {
519         tegra_protected_aperture_init(tegra_grhost_aperture);
520         return 0;
521 }
522
523 void __init tegra_whistler_reserve(void)
524 {
525         if (memblock_reserve(0x0, 4096) < 0)
526                 pr_warn("Cannot reserve first 4K of memory for safety\n");
527
528         tegra_reserve(SZ_152M, SZ_3M, SZ_1M);
529         tegra_ram_console_debug_reserve(SZ_1M);
530 }
531
532 MACHINE_START(WHISTLER, "whistler")
533         .atag_offset    = 0x100,
534         .soc            = &tegra_soc_desc,
535         .map_io         = tegra_map_common_io,
536         .init_early     = tegra20_init_early,
537         .init_irq       = tegra_init_irq,
538         .handle_irq     = gic_handle_irq,
539         .reserve        = tegra_whistler_reserve,
540         .timer          = &tegra_timer,
541         .init_machine   = tegra_whistler_init,
542         .restart        = tegra_assert_system_reset,
543 MACHINE_END