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