8c8e90696042b7aeeb8aa5090dc65c586b378177
[linux-2.6.git] / arch / arm / mach-tegra / board-whistler.c
1 /*
2  * arch/arm/mach-tegra/board-whistler.c
3  *
4  * Copyright (c) 2012-2013, NVIDIA CORPORATION. All rights reserved.
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         .i2s_param[HIFI_CODEC]  = {
370                 .audio_port_id  = 0,
371                 .is_i2s_master  = 1,
372                 .i2s_mode       = TEGRA_DAIFMT_I2S,
373                 .sample_size    = 16,
374         },
375         .i2s_param[BASEBAND]    = {
376                 .audio_port_id  = 2,
377                 .is_i2s_master  = 1,
378                 .i2s_mode       = TEGRA_DAIFMT_DSP_A,
379                 .sample_size    = 16,
380                 .rate           = 8000,
381                 .channels       = 1,
382         },
383         .i2s_param[BT_SCO]      = {
384                 .sample_size    = 16,
385                 .audio_port_id  = 3,
386                 .is_i2s_master  = 1,
387                 .i2s_mode       = TEGRA_DAIFMT_DSP_A,
388         },
389 };
390
391 static struct platform_device whistler_audio_aic326x_device = {
392         .name   = "tegra-snd-aic326x",
393         .id     = 0,
394         .dev    = {
395                 .platform_data  = &whistler_audio_pdata,
396         },
397 };
398
399 static struct platform_device whistler_audio_wm8753_device = {
400         .name   = "tegra-snd-wm8753",
401         .id     = 0,
402         .dev    = {
403                 .platform_data  = &whistler_audio_pdata,
404         },
405 };
406
407 static struct platform_device *whistler_devices[] __initdata = {
408         &tegra_pmu_device,
409         &tegra_udc_device,
410         &tegra_gart_device,
411         &tegra_aes_device,
412         &tegra_wdt_device,
413         &tegra_avp_device,
414         &whistler_scroll_device,
415         &tegra_camera,
416         &tegra_i2s_device1,
417         &tegra_i2s_device2,
418         &tegra_spdif_device,
419         &tegra_das_device,
420         &spdif_dit_device,
421         &bluetooth_dit_device,
422         &baseband_dit_device,
423         &whistler_bt_rfkill_device,
424         &tegra_pcm_device,
425         &whistler_audio_aic326x_device,
426         &whistler_audio_wm8753_device,
427 };
428
429 static struct synaptics_i2c_rmi_platform_data synaptics_pdata = {
430         .flags          = SYNAPTICS_FLIP_X | SYNAPTICS_FLIP_Y | SYNAPTICS_SWAP_XY,
431         .irqflags       = IRQF_TRIGGER_LOW,
432 };
433
434 static struct i2c_board_info whistler_i2c_touch_info[] = {
435         {
436                 I2C_BOARD_INFO("synaptics-rmi-ts", 0x20),
437                 .platform_data  = &synaptics_pdata,
438         },
439 };
440
441 static int __init whistler_touch_init(void)
442 {
443         whistler_i2c_touch_info[0].irq = gpio_to_irq(TEGRA_GPIO_PC6);
444         i2c_register_board_info(0, whistler_i2c_touch_info, 1);
445
446         return 0;
447 }
448
449 static struct tegra_usb_platform_data tegra_udc_pdata = {
450         .port_otg = true,
451         .has_hostpc = false,
452         .id_det_type = TEGRA_USB_VIRTUAL_ID,
453         .phy_intf = TEGRA_USB_PHY_INTF_UTMI,
454         .op_mode = TEGRA_USB_OPMODE_DEVICE,
455         .u_data.dev = {
456                 .vbus_pmu_irq = MAX8907C_INT_BASE + MAX8907C_IRQ_VCHG_DC_R,
457                 .vbus_gpio = -1,
458                 .charging_supported = false,
459                 .remote_wakeup_supported = false,
460         },
461         .u_cfg.utmi = {
462                 .hssync_start_delay = 0,
463                 .elastic_limit = 16,
464                 .idle_wait_delay = 17,
465                 .term_range_adj = 6,
466                 .xcvr_setup = 8,
467                 .xcvr_lsfslew = 2,
468                 .xcvr_lsrslew = 2,
469                 .xcvr_setup_offset = 0,
470                 .xcvr_use_fuses = 1,
471         },
472 };
473
474 static struct tegra_usb_platform_data tegra_ehci1_utmi_pdata = {
475         .port_otg = true,
476         .has_hostpc = false,
477         .id_det_type = TEGRA_USB_VIRTUAL_ID,
478         .phy_intf = TEGRA_USB_PHY_INTF_UTMI,
479         .op_mode        = TEGRA_USB_OPMODE_HOST,
480         .u_data.host = {
481                 .vbus_gpio = TEGRA_GPIO_PN6,
482                 .hot_plug = true,
483                 .remote_wakeup_supported = false,
484                 .power_off_on_suspend = true,
485         },
486         .u_cfg.utmi = {
487                 .hssync_start_delay = 9,
488                 .elastic_limit = 16,
489                 .idle_wait_delay = 17,
490                 .term_range_adj = 6,
491                 .xcvr_setup = 8,
492                 .xcvr_lsfslew = 2,
493                 .xcvr_lsrslew = 2,
494         },
495 };
496
497 static struct tegra_usb_otg_data tegra_otg_pdata = {
498         .ehci_device = &tegra_ehci1_device,
499         .ehci_pdata = &tegra_ehci1_utmi_pdata,
500 };
501
502 #define SERIAL_NUMBER_LENGTH 20
503 static void whistler_usb_init(void)
504 {
505         tegra_otg_device.dev.platform_data = &tegra_otg_pdata;
506         platform_device_register(&tegra_otg_device);
507
508         tegra_udc_device.dev.platform_data = &tegra_udc_pdata;
509 }
510
511 static void __init tegra_whistler_init(void)
512 {
513         int modem_id = tegra_get_modem_id();
514         tegra_clk_init_from_table(whistler_clk_init_table);
515         whistler_emc_init();
516         tegra_soc_device_init("whistler");
517         tegra_enable_pinmux();
518         whistler_pinmux_init();
519         whistler_i2c_init();
520         whistler_uart_init();
521         platform_add_devices(whistler_devices, ARRAY_SIZE(whistler_devices));
522         tegra_ram_console_debug_init();
523         whistler_sdhci_init();
524         whistler_regulator_init();
525         whistler_panel_init();
526         whistler_sensors_init();
527         whistler_touch_init();
528         whistler_kbc_init();
529         whistler_usb_init();
530         whistler_emc_init();
531         if (modem_id == 0x1)
532                 whistler_baseband_init();
533         whistler_setup_bluesleep();
534         tegra_release_bootloader_fb();
535 }
536
537 int __init tegra_whistler_protected_aperture_init(void)
538 {
539         tegra_protected_aperture_init(tegra_grhost_aperture);
540         return 0;
541 }
542
543 void __init tegra_whistler_reserve(void)
544 {
545         if (memblock_reserve(0x0, 4096) < 0)
546                 pr_warn("Cannot reserve first 4K of memory for safety\n");
547
548         tegra_reserve(SZ_152M, SZ_3M, SZ_1M);
549         tegra_ram_console_debug_reserve(SZ_1M);
550 }
551
552 static const char *whistler_dt_board_compat[] = {
553         "nvidia,whistler",
554         NULL
555 };
556
557 MACHINE_START(WHISTLER, "whistler")
558         .atag_offset    = 0x100,
559         .soc            = &tegra_soc_desc,
560         .map_io         = tegra_map_common_io,
561         .init_early     = tegra20_init_early,
562         .init_irq       = tegra_init_irq,
563         .handle_irq     = gic_handle_irq,
564         .reserve        = tegra_whistler_reserve,
565         .timer          = &tegra_timer,
566         .init_machine   = tegra_whistler_init,
567         .restart        = tegra_assert_system_reset,
568         .dt_compat      = whistler_dt_board_compat,
569 MACHINE_END