blob: 7111994ec344f7cb00c7da390bf2ce7184bb3857 [file] [log] [blame]
aghuge6c0b8db2012-07-31 10:48:37 +05301/*
2 * arch/arm/mach-tegra/board-dalmore.c
3 *
4 * Copyright (c) 2012, 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 version 2 as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20#include <linux/kernel.h>
21#include <linux/init.h>
22#include <linux/slab.h>
23#include <linux/ctype.h>
24#include <linux/platform_device.h>
25#include <linux/clk.h>
26#include <linux/serial_8250.h>
27#include <linux/i2c.h>
28#include <linux/dma-mapping.h>
29#include <linux/delay.h>
30#include <linux/i2c-tegra.h>
31#include <linux/gpio.h>
32#include <linux/input.h>
33#include <linux/platform_data/tegra_usb.h>
34#include <linux/spi/spi.h>
35#include <linux/tegra_uart.h>
36#include <linux/memblock.h>
37#include <linux/spi-tegra.h>
38#include <linux/nfc/pn544.h>
39#include <linux/skbuff.h>
40#include <linux/ti_wilink_st.h>
41#include <linux/regulator/consumer.h>
42#include <linux/smb349-charger.h>
43#include <linux/max17048_battery.h>
44#include <linux/leds.h>
45#include <linux/i2c/at24.h>
46
47#include <asm/hardware/gic.h>
48
49#include <mach/clk.h>
50#include <mach/iomap.h>
51#include <mach/irqs.h>
52#include <mach/pinmux.h>
53#include <mach/pinmux-tegra30.h>
54#include <mach/iomap.h>
55#include <mach/io.h>
56#include <mach/io_dpd.h>
57#include <mach/i2s.h>
58#include <mach/tegra_rt5640_pdata.h>
59#include <asm/mach-types.h>
60#include <asm/mach/arch.h>
61#include <mach/usb_phy.h>
62#include <mach/gpio-tegra.h>
63#include <mach/tegra_fiq_debugger.h>
64
65#include "board.h"
66#include "clock.h"
67#include "board-dalmore.h"
68#include "devices.h"
69#include "gpio-names.h"
70#include "fuse.h"
71#include "pm.h"
72#include "common.h"
73
74static __initdata struct tegra_clk_init_table dalmore_clk_init_table[] = {
75 /* name parent rate enabled */
76 { "pll_m", NULL, 0, false},
77 { "hda", "pll_p", 108000000, false},
78 { "hda2codec_2x", "pll_p", 48000000, false},
79 { "pwm", "pll_p", 3187500, false},
80 { "blink", "clk_32k", 32768, true},
81 { "i2s1", "pll_a_out0", 0, false},
82 { "i2s3", "pll_a_out0", 0, false},
83 { "i2s4", "pll_a_out0", 0, false},
84 { "spdif_out", "pll_a_out0", 0, false},
85 { "d_audio", "clk_m", 12000000, false},
86 { "dam0", "clk_m", 12000000, false},
87 { "dam1", "clk_m", 12000000, false},
88 { "dam2", "clk_m", 12000000, false},
89 { "audio1", "i2s1_sync", 0, false},
90 { "audio3", "i2s3_sync", 0, false},
91 { "vi_sensor", "pll_p", 150000000, false},
92 { "i2c1", "pll_p", 3200000, false},
93 { "i2c2", "pll_p", 3200000, false},
94 { "i2c3", "pll_p", 3200000, false},
95 { "i2c4", "pll_p", 3200000, false},
96 { "i2c5", "pll_p", 3200000, false},
97 { NULL, NULL, 0, 0},
98};
99
100static struct tegra_i2c_platform_data dalmore_i2c1_platform_data = {
101 .adapter_nr = 0,
102 .bus_count = 1,
103 .bus_clk_rate = { 100000, 0 },
104 .scl_gpio = {TEGRA_GPIO_I2C1_SCL, 0},
105 .sda_gpio = {TEGRA_GPIO_I2C1_SDA, 0},
106 .arb_recovery = arb_lost_recovery,
107};
108
109static struct tegra_i2c_platform_data dalmore_i2c2_platform_data = {
110 .adapter_nr = 1,
111 .bus_count = 1,
112 .bus_clk_rate = { 100000, 0 },
113 .is_clkon_always = true,
114 .scl_gpio = {TEGRA_GPIO_I2C2_SCL, 0},
115 .sda_gpio = {TEGRA_GPIO_I2C2_SDA, 0},
116 .arb_recovery = arb_lost_recovery,
117};
118
119static struct tegra_i2c_platform_data dalmore_i2c3_platform_data = {
120 .adapter_nr = 2,
121 .bus_count = 1,
122 .bus_clk_rate = { 100000, 0 },
123 .scl_gpio = {TEGRA_GPIO_I2C3_SCL, 0},
124 .sda_gpio = {TEGRA_GPIO_I2C3_SDA, 0},
125 .arb_recovery = arb_lost_recovery,
126};
127
128static struct tegra_i2c_platform_data dalmore_i2c4_platform_data = {
129 .adapter_nr = 3,
130 .bus_count = 1,
131 .bus_clk_rate = { 10000, 0 },
132 .scl_gpio = {TEGRA_GPIO_I2C4_SCL, 0},
133 .sda_gpio = {TEGRA_GPIO_I2C4_SDA, 0},
134 .arb_recovery = arb_lost_recovery,
135};
136
137static struct tegra_i2c_platform_data dalmore_i2c5_platform_data = {
138 .adapter_nr = 4,
139 .bus_count = 1,
140 .bus_clk_rate = { 400000, 0 },
141 .scl_gpio = {TEGRA_GPIO_I2C5_SCL, 0},
142 .sda_gpio = {TEGRA_GPIO_I2C5_SDA, 0},
143 .arb_recovery = arb_lost_recovery,
144};
145
146
147
148static void dalmore_i2c_init(void)
149{
150 struct board_info board_info;
151
152 tegra_get_board_info(&board_info);
153
154 tegra_i2c_device1.dev.platform_data = &dalmore_i2c1_platform_data;
155 tegra_i2c_device2.dev.platform_data = &dalmore_i2c2_platform_data;
156 tegra_i2c_device3.dev.platform_data = &dalmore_i2c3_platform_data;
157 tegra_i2c_device4.dev.platform_data = &dalmore_i2c4_platform_data;
158 tegra_i2c_device5.dev.platform_data = &dalmore_i2c5_platform_data;
159
160 platform_device_register(&tegra_i2c_device5);
161 platform_device_register(&tegra_i2c_device4);
162 platform_device_register(&tegra_i2c_device3);
163 platform_device_register(&tegra_i2c_device2);
164 platform_device_register(&tegra_i2c_device1);
165}
166
167static struct platform_device *dalmore_uart_devices[] __initdata = {
168 &tegra_uarta_device,
169 &tegra_uartb_device,
170 &tegra_uartc_device,
171 &tegra_uartd_device,
172 &tegra_uarte_device,
173};
174static struct uart_clk_parent uart_parent_clk[] = {
175 [0] = {.name = "clk_m"},
176 [1] = {.name = "pll_p"},
177#ifndef CONFIG_TEGRA_PLLM_RESTRICTED
178 [2] = {.name = "pll_m"},
179#endif
180};
181
182static struct tegra_uart_platform_data dalmore_uart_pdata;
183static struct tegra_uart_platform_data dalmore_loopback_uart_pdata;
184
185static void __init uart_debug_init(void)
186{
187 int debug_port_id;
188
189 debug_port_id = get_tegra_uart_debug_port_id();
190 if (debug_port_id < 0)
191 debug_port_id = 3;
192
193 switch (debug_port_id) {
194 case 0:
195 /* UARTA is the debug port. */
196 pr_info("Selecting UARTA as the debug console\n");
197 dalmore_uart_devices[0] = &debug_uarta_device;
198 debug_uart_clk = clk_get_sys("serial8250.0", "uarta");
199 debug_uart_port_base = ((struct plat_serial8250_port *)(
200 debug_uarta_device.dev.platform_data))->mapbase;
201 break;
202
203 case 1:
204 /* UARTB is the debug port. */
205 pr_info("Selecting UARTB as the debug console\n");
206 dalmore_uart_devices[1] = &debug_uartb_device;
207 debug_uart_clk = clk_get_sys("serial8250.0", "uartb");
208 debug_uart_port_base = ((struct plat_serial8250_port *)(
209 debug_uartb_device.dev.platform_data))->mapbase;
210 break;
211
212 case 2:
213 /* UARTC is the debug port. */
214 pr_info("Selecting UARTC as the debug console\n");
215 dalmore_uart_devices[2] = &debug_uartc_device;
216 debug_uart_clk = clk_get_sys("serial8250.0", "uartc");
217 debug_uart_port_base = ((struct plat_serial8250_port *)(
218 debug_uartc_device.dev.platform_data))->mapbase;
219 break;
220
221 case 3:
222 /* UARTD is the debug port. */
223 pr_info("Selecting UARTD as the debug console\n");
224 dalmore_uart_devices[3] = &debug_uartd_device;
225 debug_uart_clk = clk_get_sys("serial8250.0", "uartd");
226 debug_uart_port_base = ((struct plat_serial8250_port *)(
227 debug_uartd_device.dev.platform_data))->mapbase;
228 break;
229
230 case 4:
231 /* UARTE is the debug port. */
232 pr_info("Selecting UARTE as the debug console\n");
233 dalmore_uart_devices[4] = &debug_uarte_device;
234 debug_uart_clk = clk_get_sys("serial8250.0", "uarte");
235 debug_uart_port_base = ((struct plat_serial8250_port *)(
236 debug_uarte_device.dev.platform_data))->mapbase;
237 break;
238
239 default:
240 pr_info("The debug console id %d is invalid, Assuming UARTA",
241 debug_port_id);
242 dalmore_uart_devices[0] = &debug_uarta_device;
243 debug_uart_clk = clk_get_sys("serial8250.0", "uarta");
244 debug_uart_port_base = ((struct plat_serial8250_port *)(
245 debug_uarta_device.dev.platform_data))->mapbase;
246 break;
247 }
248}
249
250static void __init dalmore_uart_init(void)
251{
252 struct clk *c;
253 int i;
254
255 for (i = 0; i < ARRAY_SIZE(uart_parent_clk); ++i) {
256 c = tegra_get_clock_by_name(uart_parent_clk[i].name);
257 if (IS_ERR_OR_NULL(c)) {
258 pr_err("Not able to get the clock for %s\n",
259 uart_parent_clk[i].name);
260 continue;
261 }
262 uart_parent_clk[i].parent_clk = c;
263 uart_parent_clk[i].fixed_clk_rate = clk_get_rate(c);
264 }
265 dalmore_uart_pdata.parent_clk_list = uart_parent_clk;
266 dalmore_uart_pdata.parent_clk_count = ARRAY_SIZE(uart_parent_clk);
267 dalmore_loopback_uart_pdata.parent_clk_list = uart_parent_clk;
268 dalmore_loopback_uart_pdata.parent_clk_count =
269 ARRAY_SIZE(uart_parent_clk);
270 dalmore_loopback_uart_pdata.is_loopback = true;
271 tegra_uarta_device.dev.platform_data = &dalmore_uart_pdata;
272 tegra_uartb_device.dev.platform_data = &dalmore_uart_pdata;
273 tegra_uartc_device.dev.platform_data = &dalmore_uart_pdata;
274 tegra_uartd_device.dev.platform_data = &dalmore_uart_pdata;
275 /* UARTE is used for loopback test purpose */
276 tegra_uarte_device.dev.platform_data = &dalmore_loopback_uart_pdata;
277
278 /* Register low speed only if it is selected */
279 if (!is_tegra_debug_uartport_hs()) {
280 uart_debug_init();
281 /* Clock enable for the debug channel */
282 if (!IS_ERR_OR_NULL(debug_uart_clk)) {
283 pr_info("The debug console clock name is %s\n",
284 debug_uart_clk->name);
285 c = tegra_get_clock_by_name("pll_p");
286 if (IS_ERR_OR_NULL(c))
287 pr_err("Not getting the parent clock pll_p\n");
288 else
289 clk_set_parent(debug_uart_clk, c);
290
291 clk_enable(debug_uart_clk);
292 clk_set_rate(debug_uart_clk, clk_get_rate(c));
293 } else {
294 pr_err("Not getting the clock %s for debug console\n",
295 debug_uart_clk->name);
296 }
297 }
298
299 platform_add_devices(dalmore_uart_devices,
300 ARRAY_SIZE(dalmore_uart_devices));
301}
302
303static struct resource tegra_rtc_resources[] = {
304 [0] = {
305 .start = TEGRA_RTC_BASE,
306 .end = TEGRA_RTC_BASE + TEGRA_RTC_SIZE - 1,
307 .flags = IORESOURCE_MEM,
308 },
309 [1] = {
310 .start = INT_RTC,
311 .end = INT_RTC,
312 .flags = IORESOURCE_IRQ,
313 },
314};
315
316static struct platform_device tegra_rtc_device = {
317 .name = "tegra_rtc",
318 .id = -1,
319 .resource = tegra_rtc_resources,
320 .num_resources = ARRAY_SIZE(tegra_rtc_resources),
321};
322
323static struct tegra_rt5640_platform_data dalmore_audio_pdata = {
324 .gpio_spkr_en = TEGRA_GPIO_SPKR_EN,
325 .gpio_hp_det = TEGRA_GPIO_HP_DET,
326 .gpio_hp_mute = -1,
327 .gpio_int_mic_en = TEGRA_GPIO_INT_MIC_EN,
328 .gpio_ext_mic_en = TEGRA_GPIO_EXT_MIC_EN,
329};
330
331static struct platform_device dalmore_audio_device = {
332 .name = "tegra-snd-rt5640",
333 .id = 0,
334 .dev = {
335 .platform_data = &dalmore_audio_pdata,
336 },
337};
338
339
340static struct platform_device *dalmore_devices[] __initdata = {
341 &tegra_pmu_device,
342 &tegra_rtc_device,
343 &tegra_udc_device,
344#if defined(CONFIG_TEGRA_IOVMM_SMMU) || defined(CONFIG_TEGRA_IOMMU_SMMU)
345 &tegra_smmu_device,
346#endif
347#if defined(CONFIG_TEGRA_AVP)
348 &tegra_avp_device,
349#endif
350#if defined(CONFIG_CRYPTO_DEV_TEGRA_SE)
351 &tegra_se_device,
352#endif
353 &tegra_ahub_device,
354 &tegra_pcm_device,
355 &dalmore_audio_device,
356 &tegra_hda_device,
357#if defined(CONFIG_CRYPTO_DEV_TEGRA_AES)
358 &tegra_aes_device,
359#endif
360};
361
362static struct tegra_usb_platform_data tegra_udc_pdata = {
363 .port_otg = true,
364 .has_hostpc = true,
365 .phy_intf = TEGRA_USB_PHY_INTF_UTMI,
366 .op_mode = TEGRA_USB_OPMODE_DEVICE,
367 .u_data.dev = {
368 .vbus_pmu_irq = 0,
369 .vbus_gpio = -1,
370 .charging_supported = false,
371 .remote_wakeup_supported = false,
372 },
373 .u_cfg.utmi = {
374 .hssync_start_delay = 0,
375 .elastic_limit = 16,
376 .idle_wait_delay = 17,
377 .term_range_adj = 6,
378 .xcvr_setup = 8,
379 .xcvr_lsfslew = 2,
380 .xcvr_lsrslew = 2,
381 .xcvr_setup_offset = 0,
382 .xcvr_use_fuses = 1,
383 },
384};
385
386static struct tegra_usb_platform_data tegra_ehci1_utmi_pdata = {
387 .port_otg = true,
388 .has_hostpc = true,
389 .phy_intf = TEGRA_USB_PHY_INTF_UTMI,
390 .op_mode = TEGRA_USB_OPMODE_HOST,
391 .u_data.host = {
392 .vbus_gpio = -1,
393 .vbus_reg = "usb_vbus_otg",
394 .hot_plug = true,
395 .remote_wakeup_supported = true,
396 .power_off_on_suspend = true,
397 },
398 .u_cfg.utmi = {
399 .hssync_start_delay = 0,
400 .elastic_limit = 16,
401 .idle_wait_delay = 17,
402 .term_range_adj = 6,
403 .xcvr_setup = 15,
404 .xcvr_lsfslew = 2,
405 .xcvr_lsrslew = 2,
406 .xcvr_setup_offset = 0,
407 .xcvr_use_fuses = 1,
408 },
409};
410
411
412static struct tegra_usb_platform_data tegra_ehci2_utmi_pdata = {
413 .port_otg = false,
414 .has_hostpc = true,
415 .phy_intf = TEGRA_USB_PHY_INTF_UTMI,
416 .op_mode = TEGRA_USB_OPMODE_HOST,
417 .u_data.host = {
418 .vbus_gpio = -1,
419 .vbus_reg = NULL,
420 .hot_plug = false,
421 .remote_wakeup_supported = true,
422 .power_off_on_suspend = true,
423
424 },
425 .u_cfg.utmi = {
426 .hssync_start_delay = 0,
427 .elastic_limit = 16,
428 .idle_wait_delay = 17,
429 .term_range_adj = 6,
430 .xcvr_setup = 8,
431 .xcvr_lsfslew = 2,
432 .xcvr_lsrslew = 2,
433 .xcvr_setup_offset = 0,
434 .xcvr_use_fuses = 1,
435 },
436};
437
438static struct tegra_usb_otg_data tegra_otg_pdata = {
439 .ehci_device = &tegra_ehci1_device,
440 .ehci_pdata = &tegra_ehci1_utmi_pdata,
441};
442
443#if CONFIG_USB_SUPPORT
444static void dalmore_usb_init(void)
445{
446 tegra_otg_device.dev.platform_data = &tegra_otg_pdata;
447 platform_device_register(&tegra_otg_device);
448
449 /* Setup the udc platform data */
450 tegra_udc_device.dev.platform_data = &tegra_udc_pdata;
451
452 tegra_ehci2_device.dev.platform_data = &tegra_ehci2_utmi_pdata;
453 platform_device_register(&tegra_ehci2_device);
454}
455
456static void dalmore_modem_init(void)
457{
458 int ret;
459
460 ret = gpio_request(TEGRA_GPIO_W_DISABLE, "w_disable_gpio");
461 if (ret < 0)
462 pr_err("%s: gpio_request failed for gpio %d\n",
463 __func__, TEGRA_GPIO_W_DISABLE);
464 else
465 gpio_direction_output(TEGRA_GPIO_W_DISABLE, 1);
466
467
468 ret = gpio_request(TEGRA_GPIO_MODEM_RSVD1, "Port_V_PIN_0");
469 if (ret < 0)
470 pr_err("%s: gpio_request failed for gpio %d\n",
471 __func__, TEGRA_GPIO_MODEM_RSVD1);
472 else
473 gpio_direction_input(TEGRA_GPIO_MODEM_RSVD1);
474
475
476 ret = gpio_request(TEGRA_GPIO_MODEM_RSVD2, "Port_H_PIN_7");
477 if (ret < 0)
478 pr_err("%s: gpio_request failed for gpio %d\n",
479 __func__, TEGRA_GPIO_MODEM_RSVD2);
480 else
481 gpio_direction_output(TEGRA_GPIO_MODEM_RSVD2, 1);
482
483}
484
485#else
486static void dalmore_usb_init(void) { }
487static void dalmore_modem_init(void) { }
488#endif
489
490static void dalmore_audio_init(void)
491{
492 struct board_info board_info;
493
494 tegra_get_board_info(&board_info);
495
496 dalmore_audio_pdata.codec_name = "rt5640.4-001c";
497 dalmore_audio_pdata.codec_dai_name = "rt5640-aif1";
498}
499
500static void __init tegra_dalmore_init(void)
501{
502 tegra_clk_init_from_table(dalmore_clk_init_table);
503 tegra_enable_pinmux();
504 dalmore_pinmux_init();
505 dalmore_i2c_init();
506 dalmore_usb_init();
507 dalmore_uart_init();
508 dalmore_audio_init();
509 platform_add_devices(dalmore_devices, ARRAY_SIZE(dalmore_devices));
510 tegra_ram_console_debug_init();
511 tegra_io_dpd_init();
512 dalmore_sdhci_init();
513 dalmore_regulator_init();
514 dalmore_suspend_init();
515 dalmore_emc_init();
516 tegra_release_bootloader_fb();
517 dalmore_modem_init();
518#ifdef CONFIG_TEGRA_WDT_RECOVERY
519 tegra_wdt_recovery_init();
520#endif
521 tegra_serial_debug_init(TEGRA_UARTD_BASE, INT_WDT_CPU, NULL, -1, -1);
522}
523
524static void __init dalmore_ramconsole_reserve(unsigned long size)
525{
526 tegra_ram_console_debug_reserve(SZ_1M);
527}
528
529static void __init tegra_dalmore_reserve(void)
530{
531#if defined(CONFIG_NVMAP_CONVERT_CARVEOUT_TO_IOVMM)
532 /* support 1920X1200 with 24bpp */
533 tegra_reserve(0, SZ_8M + SZ_1M, SZ_8M + SZ_1M);
534#else
535 tegra_reserve(SZ_128M, SZ_8M, SZ_8M);
536#endif
537 dalmore_ramconsole_reserve(SZ_1M);
538}
539
540MACHINE_START(DALMORE, "dalmore")
541 .atag_offset = 0x100,
542 .soc = &tegra_soc_desc,
543 .map_io = tegra_map_common_io,
544 .reserve = tegra_dalmore_reserve,
545 .init_early = tegra30_init_early,
546 .init_irq = tegra_init_irq,
547 .handle_irq = gic_handle_irq,
548 .timer = &tegra_timer,
549 .init_machine = tegra_dalmore_init,
550 .restart = tegra_assert_system_reset,
551MACHINE_END