2 * arch/arm/mach-tegra/board-stingray.c
4 * Copyright (C) 2010 Google, Inc.
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
17 #include <linux/console.h>
18 #include <linux/kernel.h>
19 #include <linux/init.h>
20 #include <linux/platform_device.h>
21 #include <linux/serial_8250.h>
22 #include <linux/clk.h>
23 #include <linux/mtd/mtd.h>
24 #include <linux/mtd/partitions.h>
25 #include <linux/dma-mapping.h>
26 #include <linux/fsl_devices.h>
27 #include <linux/platform_data/tegra_usb.h>
28 #include <linux/pda_power.h>
29 #include <linux/gpio.h>
30 #include <linux/delay.h>
31 #include <linux/reboot.h>
32 #include <linux/i2c-tegra.h>
33 #include <linux/spi/cpcap.h>
34 #include <linux/memblock.h>
36 #include <asm/mach-types.h>
37 #include <asm/mach/arch.h>
38 #include <asm/mach/time.h>
39 #include <asm/setup.h>
43 #include <mach/iomap.h>
44 #include <mach/irqs.h>
45 #include <mach/iomap.h>
46 #include <mach/sdhci.h>
47 #include <mach/gpio.h>
49 #include <mach/usb_phy.h>
51 #include <mach/spdif.h>
52 #include <mach/audio.h>
53 #include <mach/cpcap_audio.h>
54 #include <mach/suspend.h>
55 #include <mach/system.h>
56 #include <mach/tegra_fiq_debugger.h>
57 #include <mach/tegra_hsuart.h>
58 #include <mach/nvmap.h>
59 #include <mach/bcm_bt_lpm.h>
61 #include <linux/usb/android_composite.h>
62 #include <linux/usb/f_accessory.h>
65 #include "board-stingray.h"
67 #include "gpio-names.h"
70 /* NVidia bootloader tags */
71 #define ATAG_NVIDIA 0x41000801
73 #define ATAG_NVIDIA_RM 0x1
74 #define ATAG_NVIDIA_DISPLAY 0x2
75 #define ATAG_NVIDIA_FRAMEBUFFER 0x3
76 #define ATAG_NVIDIA_CHIPSHMOO 0x4
77 #define ATAG_NVIDIA_CHIPSHMOOPHYS 0x5
78 #define ATAG_NVIDIA_PRESERVED_MEM_0 0x10000
79 #define ATAG_NVIDIA_PRESERVED_MEM_N 2
80 #define ATAG_NVIDIA_FORCE_32 0x7fffffff
82 #define USB_MANUFACTURER_NAME "Motorola"
83 #define USB_PRODUCT_NAME "MZ600"
84 #define USB_PRODUCT_NAME_LTE "MZ602"
85 #define USB_PRODUCT_NAME_WIFI_ONLY "MZ604"
86 #define USB_PRODUCT_ID_BLAN 0x70A3
87 #define USB_PRODUCT_ID_MTP 0x70A8
88 #define USB_PRODUCT_ID_MTP_ADB 0x70A9
89 #define USB_PRODUCT_ID_RNDIS 0x70AE
90 #define USB_PRODUCT_ID_RNDIS_ADB 0x70AF
91 #define USB_PRODUCT_ID_BP 0x70B0
92 #define USB_PRODUCT_ID_BP_ADB 0x70B1
93 #define USB_PRODUCT_ID_RNDIS_BP 0x70B2
94 #define USB_PRODUCT_ID_RNDIS_BP_ADB 0x70B3
95 #define USB_VENDOR_ID 0x22b8
103 static int __init parse_tag_nvidia(const struct tag *tag)
108 __tagtable(ATAG_NVIDIA, parse_tag_nvidia);
110 static unsigned long ramconsole_start = SZ_512M - SZ_1M;
111 static unsigned long ramconsole_size = SZ_1M;
113 static struct resource mdm6600_resources[] = {
115 .flags = IORESOURCE_IRQ,
116 .start = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PQ6),
117 .end = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PQ6),
121 static struct platform_device mdm6600_modem = {
122 .name = "mdm6600_modem",
124 .resource = mdm6600_resources,
125 .num_resources = ARRAY_SIZE(mdm6600_resources),
128 /* OTG gadget device */
129 static struct tegra_utmip_config udc_phy_config = {
130 .hssync_start_delay = 0,
131 .idle_wait_delay = 17,
139 static struct fsl_usb2_platform_data tegra_udc_pdata = {
140 .operating_mode = FSL_USB2_DR_DEVICE,
141 .phy_mode = FSL_USB2_PHY_UTMI,
142 .phy_config = &udc_phy_config,
145 /* OTG transceiver */
146 static struct resource cpcap_otg_resources[] = {
148 .start = TEGRA_USB_BASE,
149 .end = TEGRA_USB_BASE + TEGRA_USB_SIZE - 1,
150 .flags = IORESOURCE_MEM,
154 static struct platform_device cpcap_otg = {
157 .resource = cpcap_otg_resources,
158 .num_resources = ARRAY_SIZE(cpcap_otg_resources),
160 .platform_data = &tegra_ehci1_device,
164 static struct cpcap_audio_state stingray_cpcap_audio_state = {
166 .mode = CPCAP_AUDIO_MODE_NORMAL,
167 .codec_mode = CPCAP_AUDIO_CODEC_OFF,
168 .codec_rate = CPCAP_AUDIO_CODEC_RATE_8000_HZ,
169 .codec_mute = CPCAP_AUDIO_CODEC_MUTE,
170 .stdac_mode = CPCAP_AUDIO_STDAC_OFF,
171 .stdac_rate = CPCAP_AUDIO_STDAC_RATE_44100_HZ,
172 .stdac_mute = CPCAP_AUDIO_STDAC_MUTE,
173 .analog_source = CPCAP_AUDIO_ANALOG_SOURCE_OFF,
174 .codec_primary_speaker = CPCAP_AUDIO_OUT_NONE,
175 .codec_secondary_speaker = CPCAP_AUDIO_OUT_NONE,
176 .stdac_primary_speaker = CPCAP_AUDIO_OUT_NONE,
177 .stdac_secondary_speaker = CPCAP_AUDIO_OUT_NONE,
178 .ext_primary_speaker = CPCAP_AUDIO_OUT_NONE,
179 .ext_secondary_speaker = CPCAP_AUDIO_OUT_NONE,
180 .codec_primary_balance = CPCAP_AUDIO_BALANCE_NEUTRAL,
181 .stdac_primary_balance = CPCAP_AUDIO_BALANCE_NEUTRAL,
182 .ext_primary_balance = CPCAP_AUDIO_BALANCE_NEUTRAL,
184 .microphone = CPCAP_AUDIO_IN_NONE,
186 .rat_type = CPCAP_AUDIO_RAT_NONE
189 /* CPCAP is i2s master; tegra_audio_pdata.master == false */
190 static void init_dac2(bool bluetooth);
191 static struct cpcap_audio_platform_data cpcap_audio_pdata = {
193 .regulator = "vaudio",
194 .state = &stingray_cpcap_audio_state,
195 .speaker_gpio = TEGRA_GPIO_PR3,
197 .spdif_gpio = TEGRA_GPIO_PD4,
198 .bluetooth_bypass = init_dac2,
201 static struct platform_device cpcap_audio_device = {
202 .name = "cpcap_audio",
205 .platform_data = &cpcap_audio_pdata,
209 /* This is the CPCAP Stereo DAC interface. */
210 static struct tegra_audio_platform_data tegra_audio_pdata = {
211 .i2s_master = false, /* CPCAP Stereo DAC */
212 .dsp_master = false, /* Don't care */
213 .dma_on = true, /* use dma by default */
214 .i2s_clk_rate = 24000000,
215 .dap_clk = "clk_dev1",
216 .audio_sync_clk = "audio_2x",
217 .mode = I2S_BIT_FORMAT_I2S,
218 .fifo_fmt = I2S_FIFO_PACKED,
219 .bit_size = I2S_BIT_SIZE_16,
220 .i2s_bus_width = 32, /* Using Packed 16 bit data, the dma is 32 bit. */
221 .dsp_bus_width = 16, /* When using DSP mode (unused), this should be 16 bit. */
222 .mask = TEGRA_AUDIO_ENABLE_TX,
225 /* Connected to CPCAP CODEC - Switchable to Bluetooth Audio. */
226 static struct tegra_audio_platform_data tegra_audio2_pdata = {
227 .i2s_master = false, /* CPCAP CODEC */
228 .dsp_master = true, /* Bluetooth */
229 .dsp_master_clk = 8000, /* Bluetooth audio speed */
230 .dma_on = true, /* use dma by default */
231 .i2s_clk_rate = 2000000, /* BCM4329 max bitclock is 2048000 Hz */
232 .dap_clk = "clk_dev1",
233 .audio_sync_clk = "audio_2x",
234 .mode = I2S_BIT_FORMAT_DSP, /* Using COCEC in network mode */
235 .fifo_fmt = I2S_FIFO_16_LSB,
236 .bit_size = I2S_BIT_SIZE_16,
237 .i2s_bus_width = 16, /* Capturing a single timeslot, mono 16 bits */
239 .mask = TEGRA_AUDIO_ENABLE_TX | TEGRA_AUDIO_ENABLE_RX,
242 static struct tegra_audio_platform_data tegra_spdif_pdata = {
243 .dma_on = true, /* use dma by default */
244 .i2s_clk_rate = 5644800,
245 .mode = SPDIF_BIT_MODE_MODE16BIT,
250 static char *usb_functions_mtp[] = { "mtp" };
251 static char *usb_functions_mtp_adb[] = { "mtp", "adb" };
252 #ifdef CONFIG_USB_ANDROID_ACCESSORY
253 static char *usb_functions_accessory[] = { "accessory" };
254 static char *usb_functions_accessory_adb[] = { "accessory", "adb" };
256 #ifdef CONFIG_USB_ANDROID_RNDIS
257 static char *usb_functions_rndis[] = { "rndis" };
258 static char *usb_functions_rndis_adb[] = { "rndis", "adb" };
260 static char *usb_functions_all[] = {
261 #ifdef CONFIG_USB_ANDROID_RNDIS
264 #ifdef CONFIG_USB_ANDROID_ACCESSORY
271 static struct android_usb_product usb_products[] = {
273 .product_id = USB_PRODUCT_ID_MTP,
274 .num_functions = ARRAY_SIZE(usb_functions_mtp),
275 .functions = usb_functions_mtp,
278 .product_id = USB_PRODUCT_ID_MTP_ADB,
279 .num_functions = ARRAY_SIZE(usb_functions_mtp_adb),
280 .functions = usb_functions_mtp_adb,
282 #ifdef CONFIG_USB_ANDROID_ACCESSORY
284 .vendor_id = USB_ACCESSORY_VENDOR_ID,
285 .product_id = USB_ACCESSORY_PRODUCT_ID,
286 .num_functions = ARRAY_SIZE(usb_functions_accessory),
287 .functions = usb_functions_accessory,
290 .vendor_id = USB_ACCESSORY_VENDOR_ID,
291 .product_id = USB_ACCESSORY_ADB_PRODUCT_ID,
292 .num_functions = ARRAY_SIZE(usb_functions_accessory_adb),
293 .functions = usb_functions_accessory_adb,
296 #ifdef CONFIG_USB_ANDROID_RNDIS
298 .product_id = USB_PRODUCT_ID_RNDIS,
299 .num_functions = ARRAY_SIZE(usb_functions_rndis),
300 .functions = usb_functions_rndis,
303 .product_id = USB_PRODUCT_ID_RNDIS_ADB,
304 .num_functions = ARRAY_SIZE(usb_functions_rndis_adb),
305 .functions = usb_functions_rndis_adb,
310 /* standard android USB platform data */
311 static struct android_usb_platform_data andusb_plat = {
312 .vendor_id = USB_VENDOR_ID,
313 .product_id = USB_PRODUCT_ID_MTP_ADB,
314 .manufacturer_name = USB_MANUFACTURER_NAME,
315 .product_name = USB_PRODUCT_NAME,
316 .serial_number = "0000",
317 .num_products = ARRAY_SIZE(usb_products),
318 .products = usb_products,
319 .num_functions = ARRAY_SIZE(usb_functions_all),
320 .functions = usb_functions_all,
323 static struct platform_device androidusb_device = {
324 .name = "android_usb",
327 .platform_data = &andusb_plat,
331 static char *factory_usb_functions[] = {
335 static struct android_usb_product factory_usb_products[] = {
337 .product_id = USB_PRODUCT_ID_BLAN,
338 .num_functions = ARRAY_SIZE(factory_usb_functions),
339 .functions = factory_usb_functions,
343 /* android USB platform data for factory test mode*/
344 static struct android_usb_platform_data andusb_plat_factory = {
345 .vendor_id = USB_VENDOR_ID,
346 .product_id = USB_PRODUCT_ID_BLAN,
347 .manufacturer_name = USB_MANUFACTURER_NAME,
348 .product_name = USB_PRODUCT_NAME,
349 .serial_number = "000000000",
350 .num_products = ARRAY_SIZE(factory_usb_products),
351 .products = factory_usb_products,
352 .num_functions = ARRAY_SIZE(factory_usb_functions),
353 .functions = factory_usb_functions,
356 static char *bp_usb_functions_bp[] = {
358 static char *bp_usb_functions_bp_adb[] = {
359 "acm", "usbnet", "adb"};
360 static char *bp_usb_functions_rndis_bp[] = {
361 "rndis", "acm", "usbnet"};
362 static char *bp_usb_functions_all[] = {
363 "rndis", "acm", "usbnet", "adb"};
365 static struct android_usb_product bp_usb_products[] = {
367 .product_id = USB_PRODUCT_ID_BP,
368 .num_functions = ARRAY_SIZE(bp_usb_functions_bp),
369 .functions = bp_usb_functions_bp,
372 .product_id = USB_PRODUCT_ID_BP_ADB,
373 .num_functions = ARRAY_SIZE(bp_usb_functions_bp_adb),
374 .functions = bp_usb_functions_bp_adb,
377 .product_id = USB_PRODUCT_ID_RNDIS_BP,
378 .num_functions = ARRAY_SIZE(bp_usb_functions_rndis_bp),
379 .functions = bp_usb_functions_rndis_bp,
382 .product_id = USB_PRODUCT_ID_RNDIS_BP_ADB,
383 .num_functions = ARRAY_SIZE(bp_usb_functions_all),
384 .functions = bp_usb_functions_all,
388 static struct android_usb_platform_data andusb_plat_bp = {
389 .vendor_id = USB_VENDOR_ID,
390 .product_id = USB_PRODUCT_ID_BP_ADB,
391 .manufacturer_name = USB_MANUFACTURER_NAME,
392 .product_name = USB_PRODUCT_NAME,
393 .serial_number = "0000",
394 .num_products = ARRAY_SIZE(bp_usb_products),
395 .products = bp_usb_products,
396 .num_functions = ARRAY_SIZE(bp_usb_functions_all),
397 .functions = bp_usb_functions_all,
400 static struct platform_device usbnet_device = {
404 #ifdef CONFIG_USB_ANDROID_RNDIS
405 static struct usb_ether_platform_data rndis_pdata = {
406 /* ethaddr is filled by board_serialno_setup */
407 .vendorID = USB_VENDOR_ID,
408 .vendorDescr = USB_MANUFACTURER_NAME,
411 static struct platform_device rndis_device = {
415 .platform_data = &rndis_pdata,
420 static struct acm_platform_data acm_pdata = {
421 /* Modify num_inst at runtime depending on boot_mode */
425 static struct platform_device acm_device = {
429 .platform_data = &acm_pdata,
433 static struct tegra_utmip_config utmi_phy_config[] = {
435 .hssync_start_delay = 0,
436 .idle_wait_delay = 17,
444 .hssync_start_delay = 0,
445 .idle_wait_delay = 17,
454 static struct tegra_ulpi_config ulpi_phy_config = {
455 .reset_gpio = TEGRA_GPIO_PG2,
459 static struct tegra_ehci_platform_data tegra_ehci_pdata[] = {
461 .phy_config = &utmi_phy_config[0],
462 .operating_mode = TEGRA_USB_OTG,
463 .power_down_on_bus_suspend = 0,
466 .phy_config = &ulpi_phy_config,
467 .operating_mode = TEGRA_USB_HOST,
468 .power_down_on_bus_suspend = 1,
471 .phy_config = &utmi_phy_config[1],
472 .operating_mode = TEGRA_USB_HOST,
473 .power_down_on_bus_suspend = 1,
477 /* bq24617 charger */
478 static struct resource bq24617_resources[] = {
481 .flags = IORESOURCE_IRQ,
482 .start = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PV5),
483 .end = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PV5),
487 .flags = IORESOURCE_IRQ,
488 .start = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PD1),
489 .end = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PD1),
493 .flags = IORESOURCE_IRQ,
494 .start = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PV6),
495 .end = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PV6),
499 static struct resource bq24617_resources_m1_p0[] = {
502 .flags = IORESOURCE_IRQ,
503 .start = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PV5),
504 .end = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PV5),
508 .flags = IORESOURCE_IRQ,
509 .start = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PV6),
510 .end = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PV6),
514 static struct platform_device bq24617_device = {
517 .resource = bq24617_resources,
518 .num_resources = ARRAY_SIZE(bq24617_resources),
521 static struct resource tegra_gart_resources[] = {
524 .flags = IORESOURCE_MEM,
525 .start = TEGRA_MC_BASE,
526 .end = TEGRA_MC_BASE + TEGRA_MC_SIZE - 1,
530 .flags = IORESOURCE_MEM,
532 .end = 0x58000000 - 1 + 32 * 1024 * 1024,
537 static struct platform_device tegra_gart_dev = {
538 .name = "tegra_gart",
540 .num_resources = ARRAY_SIZE(tegra_gart_resources),
541 .resource = tegra_gart_resources
544 static struct platform_device bcm4329_bluetooth_device = {
545 .name = "bcm4329_bluetooth",
549 static struct platform_device tegra_camera = {
550 .name = "tegra_camera",
554 static struct tegra_w1_timings tegra_w1_platform_timings = {
571 static struct tegra_w1_platform_data tegra_w1_pdata = {
573 .timings = &tegra_w1_platform_timings,
576 static struct resource ram_console_resources[] = {
578 /* .start and .end filled in later */
579 .flags = IORESOURCE_MEM,
583 static struct platform_device ram_console_device = {
584 .name = "ram_console",
586 .num_resources = ARRAY_SIZE(ram_console_resources),
587 .resource = ram_console_resources,
590 static struct nvmap_platform_carveout stingray_carveouts[] = {
593 .usage_mask = NVMAP_HEAP_CARVEOUT_IRAM,
594 .base = TEGRA_IRAM_BASE,
595 .size = TEGRA_IRAM_SIZE,
600 .usage_mask = NVMAP_HEAP_CARVEOUT_GENERIC,
601 /* .base and .size to be filled in later */
602 .buddy_size = SZ_32K,
606 static struct nvmap_platform_data stingray_nvmap_data = {
607 .carveouts = stingray_carveouts,
608 .nr_carveouts = ARRAY_SIZE(stingray_carveouts),
611 static struct platform_device stingray_nvmap_device = {
612 .name = "tegra-nvmap",
615 .platform_data = &stingray_nvmap_data,
619 static struct tegra_hsuart_platform_data tegra_uartc_pdata = {
620 .exit_lpm_cb = bcm_bt_lpm_exit_lpm_locked,
621 .rx_done_cb = bcm_bt_rx_done_locked,
624 static struct platform_device *stingray_devices[] __initdata = {
627 &bcm4329_bluetooth_device,
637 &stingray_nvmap_device,
638 &tegra_grhost_device,
651 extern struct tegra_sdhci_platform_data stingray_wifi_data; /* sdhci2 */
653 static struct tegra_sdhci_platform_data stingray_sdhci_sdcard_platform_data = {
656 .cd_gpio = TEGRA_GPIO_PI5,
661 static struct tegra_sdhci_platform_data stingray_sdhci_platform_data4 = {
669 static struct tegra_i2c_platform_data stingray_i2c1_platform_data = {
672 .bus_clk_rate = { 400000 },
675 static struct tegra_i2c_platform_data stingray_i2c2_platform_data = {
680 static struct tegra_i2c_platform_data stingray_i2c3_platform_data = {
683 .bus_clk_rate = { 400000 },
686 static struct tegra_i2c_platform_data stingray_i2c4_platform_data = {
689 .bus_clk_rate = { 400000 },
693 static __initdata struct tegra_clk_init_table stingray_clk_init_table[] = {
694 /* name parent rate enabled */
695 { "uartb", "clk_m", 26000000, true},
696 { "uartc", "pll_m", 600000000, false},
697 /*{ "emc", "pll_p", 0, true},
698 { "emc", "pll_m", 600000000, false},*/
699 { "pll_m", NULL, 600000000, true},
700 { "mpe", "pll_m", 250000000, false},
701 { "pll_a", NULL, 56448000, false},
702 { "pll_a_out0", NULL, 11289600, false},
703 { "i2s1", "pll_p", 24000000, false},
704 { "i2s2", "pll_p", 2000000, false},
705 { "sdmmc2", "pll_m", 48000000, false},
706 { "spdif_out", "pll_a_out0", 5644800, false},
710 static void stingray_i2c_init(void)
712 tegra_i2c_device1.dev.platform_data = &stingray_i2c1_platform_data;
713 tegra_i2c_device2.dev.platform_data = &stingray_i2c2_platform_data;
714 tegra_i2c_device3.dev.platform_data = &stingray_i2c3_platform_data;
715 tegra_i2c_device4.dev.platform_data = &stingray_i2c4_platform_data;
717 platform_device_register(&tegra_i2c_device1);
718 platform_device_register(&tegra_i2c_device2);
719 platform_device_register(&tegra_i2c_device3);
720 platform_device_register(&tegra_i2c_device4);
723 static void stingray_sdhci_init(void)
725 /* TODO: setup GPIOs for cd, wd, and power */
726 tegra_sdhci_device2.dev.platform_data = &stingray_wifi_data;
727 tegra_sdhci_device3.dev.platform_data = &stingray_sdhci_sdcard_platform_data;
728 tegra_sdhci_device4.dev.platform_data = &stingray_sdhci_platform_data4;
730 platform_device_register(&tegra_sdhci_device2);
731 platform_device_register(&tegra_sdhci_device3);
732 platform_device_register(&tegra_sdhci_device4);
734 #define ATAG_BDADDR 0x43294329 /* stingray bluetooth address tag */
735 #define ATAG_BDADDR_SIZE 4
736 #define BDADDR_STR_SIZE 18
738 static char bdaddr[BDADDR_STR_SIZE];
740 module_param_string(bdaddr, bdaddr, sizeof(bdaddr), 0400);
741 MODULE_PARM_DESC(bdaddr, "bluetooth address");
743 static int __init parse_tag_bdaddr(const struct tag *tag)
745 unsigned char *b = (unsigned char *)&tag->u;
747 if (tag->hdr.size != ATAG_BDADDR_SIZE)
750 snprintf(bdaddr, BDADDR_STR_SIZE, "%02X:%02X:%02X:%02X:%02X:%02X",
751 b[0], b[1], b[2], b[3], b[4], b[5]);
755 __tagtable(ATAG_BDADDR, parse_tag_bdaddr);
757 static DEFINE_SPINLOCK(brcm_4329_enable_lock);
758 static int brcm_4329_enable_count;
760 static void stingray_w1_init(void)
762 tegra_w1_device.dev.platform_data = &tegra_w1_pdata;
763 platform_device_register(&tegra_w1_device);
767 #define ATAG_POWERUP_REASON 0xf1000401
768 #define ATAG_POWERUP_REASON_SIZE 3 /* size + tag id + tag data */
770 static unsigned int powerup_reason = PU_REASON_PWR_KEY_PRESS;
772 unsigned int stingray_powerup_reason (void)
774 return powerup_reason;
777 static int __init parse_tag_powerup_reason(const struct tag *tag)
779 if (tag->hdr.size != ATAG_POWERUP_REASON_SIZE)
781 memcpy(&powerup_reason, &tag->u, sizeof(powerup_reason));
782 printk(KERN_INFO "powerup reason=0x%08x\n", powerup_reason);
785 __tagtable(ATAG_POWERUP_REASON, parse_tag_powerup_reason);
787 #define BOOT_MODE_MAX_LEN 30
788 static char boot_mode[BOOT_MODE_MAX_LEN + 1];
789 int __init board_boot_mode_init(char *s)
791 strncpy(boot_mode, s, BOOT_MODE_MAX_LEN);
792 boot_mode[BOOT_MODE_MAX_LEN] = '\0';
793 printk(KERN_INFO "boot_mode=%s\n", boot_mode);
796 __setup("androidboot.mode=", board_boot_mode_init);
798 #define SERIAL_NUMBER_LENGTH 16
799 static char usb_serial_num[SERIAL_NUMBER_LENGTH + 1];
800 static int __init mot_usb_serial_num_setup(char *options)
802 strncpy(usb_serial_num, options, SERIAL_NUMBER_LENGTH);
803 usb_serial_num[SERIAL_NUMBER_LENGTH] = '\0';
804 printk(KERN_INFO "usb_serial_num=%s\n", usb_serial_num);
807 __setup("androidboot.serialno=", mot_usb_serial_num_setup);
809 static int mot_boot_recovery = 0;
810 static int __init mot_bm_recovery_setup(char *options)
812 mot_boot_recovery = 1;
815 __setup("rec", mot_bm_recovery_setup);
817 #define PRODUCT_TYPE_MAX_LEN 4
818 static char product_type[PRODUCT_TYPE_MAX_LEN + 1] = "cw";
819 static int __init stingray_product_type_parse(char *s)
821 strncpy(product_type, s, PRODUCT_TYPE_MAX_LEN);
822 product_type[PRODUCT_TYPE_MAX_LEN] = '\0';
823 printk(KERN_INFO "product_type=%s\n", product_type);
827 __setup("product_type=", stingray_product_type_parse);
829 bool stingray_hw_has_cdma(void)
831 return strstr(product_type, "c") != NULL;
834 bool stingray_hw_has_lte(void)
836 return strstr(product_type, "l") != NULL;
839 bool stingray_hw_has_wifi(void)
841 return strstr(product_type, "w") != NULL;
844 bool stingray_hw_has_umts(void)
846 return strstr(product_type, "u") != NULL;
849 static void stingray_usb_init(void)
854 struct android_usb_platform_data *platform_data;
856 int factorycable = !strncmp(boot_mode, "factorycable",
859 tegra_udc_device.dev.platform_data = &tegra_udc_pdata;
860 tegra_ehci2_device.dev.platform_data = &tegra_ehci_pdata[1];
861 tegra_ehci3_device.dev.platform_data = &tegra_ehci_pdata[2];
863 if (!(factorycable && mot_boot_recovery))
864 platform_device_register(&tegra_udc_device);
866 if (stingray_hw_has_cdma())
867 platform_device_register(&tegra_ehci2_device);
869 platform_device_register(&tegra_ehci3_device);
871 #ifdef CONFIG_USB_ANDROID_RNDIS
872 src = usb_serial_num;
874 /* create a fake MAC address from our serial number.
875 * first byte is 0x02 to signify locally administered.
877 rndis_pdata.ethaddr[0] = 0x02;
878 for (i = 0; *src; i++) {
879 /* XOR the USB serial across the remaining bytes */
880 rndis_pdata.ethaddr[i % (ETH_ALEN - 1) + 1] ^= *src++;
882 platform_device_register(&rndis_device);
885 if (!(factorycable && mot_boot_recovery)) {
887 platform_data = &andusb_plat_factory;
888 platform_device_register(&usbnet_device);
889 } else if (!strncmp(boot_mode, "bp-tools",
890 BOOT_MODE_MAX_LEN)) {
891 platform_data = &andusb_plat_bp;
892 platform_device_register(&usbnet_device);
893 /* acm: LTE Modem + QC Modem + QC Diag */
894 acm_pdata.num_inst = 3;
895 platform_device_register(&acm_device);
897 platform_data = &andusb_plat;
900 if (stingray_hw_has_lte())
901 platform_data->product_name = USB_PRODUCT_NAME_LTE;
902 else if (stingray_hw_has_cdma())
903 platform_data->product_name = USB_PRODUCT_NAME;
905 platform_data->product_name = USB_PRODUCT_NAME_WIFI_ONLY;
907 platform_data->serial_number = usb_serial_num;
908 androidusb_device.dev.platform_data = platform_data;
909 platform_device_register(&androidusb_device);
913 static void stingray_reset(char mode, const char *cmd)
915 /* Signal to CPCAP to stop the uC. */
916 gpio_set_value(TEGRA_GPIO_PG3, 0);
918 gpio_set_value(TEGRA_GPIO_PG3, 1);
921 tegra_assert_system_reset();
924 static void stingray_power_off(void)
926 printk(KERN_INFO "stingray_pm_power_off...\n");
930 /* signal WDI gpio to shutdown CPCAP, which will
931 cascade to all of the regulators. */
932 gpio_direction_output(TEGRA_GPIO_PV7, 0);
939 static void __init stingray_power_off_init(void)
941 tegra_gpio_enable(TEGRA_GPIO_PG3);
942 gpio_request(TEGRA_GPIO_PG3, "sys_restart_b");
943 gpio_direction_output(TEGRA_GPIO_PG3, 1);
944 tegra_reset = stingray_reset;
946 tegra_gpio_enable(TEGRA_GPIO_PV7);
947 if (!gpio_request(TEGRA_GPIO_PV7, "wdi"))
948 pm_power_off = stingray_power_off;
951 static unsigned int stingray_board_revision = STINGRAY_REVISION_UNKNOWN;
953 unsigned int stingray_revision(void)
955 return stingray_board_revision;
958 static int __init stingray_revision_parse(char *options)
960 if (!strcmp(options, "m1"))
961 stingray_board_revision = STINGRAY_REVISION_M1;
962 else if (!strcmp(options, "p0"))
963 stingray_board_revision = STINGRAY_REVISION_P0;
964 else if (!strcmp(options, "p1"))
965 stingray_board_revision = STINGRAY_REVISION_P1;
966 else if (!strcmp(options, "p2"))
967 stingray_board_revision = STINGRAY_REVISION_P2;
968 else if (!strcmp(options, "p3"))
969 stingray_board_revision = STINGRAY_REVISION_P3;
971 stingray_board_revision = system_rev;
973 printk(KERN_INFO "hw_rev=0x%x\n", stingray_board_revision);
977 __setup("hw_rev=", stingray_revision_parse);
979 int stingray_qbp_usb_hw_bypass_enabled(void)
981 /* We could use the boot_mode string instead of probing the HW, but
982 * that would not work if we enable run-time switching to this mode
985 if (gpio_get_value(TEGRA_GPIO_PT3) && !gpio_get_value(TEGRA_GPIO_PV4)) {
986 pr_info("stingray_qbp_usb_hw_bypass enabled\n");
992 static struct tegra_suspend_platform_data stingray_suspend = {
995 .core_timer = 0x7e7e,
996 .core_off_timer = 0xf,
997 .separate_req = true,
998 .corereq_high = true,
999 .sysclkreq_high = true,
1000 .suspend_mode = TEGRA_SUSPEND_LP0,
1003 static void *das_base = IO_ADDRESS(TEGRA_APB_MISC_BASE);
1005 static inline void das_writel(unsigned long value, unsigned long offset)
1007 writel(value, das_base + offset);
1010 #define APB_MISC_DAS_DAP_CTRL_SEL_0 0xc00
1011 #define APB_MISC_DAS_DAC_INPUT_DATA_CLK_SEL_0 0xc40
1013 static void init_dac1(void)
1015 bool master = tegra_audio_pdata.i2s_master;
1017 das_writel((!master)<<31, APB_MISC_DAS_DAP_CTRL_SEL_0);
1018 das_writel(0, APB_MISC_DAS_DAC_INPUT_DATA_CLK_SEL_0);
1021 static void init_dac2(bool bluetooth)
1024 /* DAC2 -> DAP2 for CPCAP CODEC */
1025 bool master = tegra_audio2_pdata.i2s_master;
1026 das_writel((!master)<<31 | 1, APB_MISC_DAS_DAP_CTRL_SEL_0 + 4);
1027 das_writel(1<<28 | 1<<24 | 1,
1028 APB_MISC_DAS_DAC_INPUT_DATA_CLK_SEL_0 + 4);
1030 /* DAC2 -> DAP4 for Bluetooth Voice */
1031 bool master = tegra_audio2_pdata.dsp_master;
1032 das_writel((!master)<<31 | 1, APB_MISC_DAS_DAP_CTRL_SEL_0 + 12);
1033 das_writel(3<<28 | 3<<24 | 3,
1034 APB_MISC_DAS_DAC_INPUT_DATA_CLK_SEL_0 + 4);
1038 void change_power_brcm_4329(bool enable) {
1039 unsigned long flags;
1041 spin_lock_irqsave(&brcm_4329_enable_lock, flags);
1043 gpio_set_value(TEGRA_GPIO_PU4, enable);
1044 brcm_4329_enable_count++;
1045 // The following shouldn't happen but protect
1046 // if the user doesn't cleanup.
1047 if (brcm_4329_enable_count > 2)
1048 brcm_4329_enable_count = 2;
1050 if (brcm_4329_enable_count > 0)
1051 brcm_4329_enable_count--;
1052 if (!brcm_4329_enable_count)
1053 gpio_set_value(TEGRA_GPIO_PU4, enable);
1055 spin_unlock_irqrestore(&brcm_4329_enable_lock, flags);
1058 static void __init tegra_stingray_init(void)
1061 struct resource *res;
1063 /* force consoles to stay enabled across suspend/resume */
1064 console_suspend_enabled = 0;
1066 tegra_common_init();
1067 tegra_init_suspend(&stingray_suspend);
1068 stingray_init_emc();
1070 /* Set the SDMMC2 (wifi) tap delay to 6. This value is determined
1071 * based on propagation delay on the PCB traces. */
1072 clk = clk_get_sys("sdhci-tegra.1", NULL);
1074 tegra_sdmmc_tap_delay(clk, 6);
1077 pr_err("Failed to set wifi sdmmc tap delay\n");
1080 /* Stingray has a USB switch that disconnects the usb port from the T20
1081 unless a factory cable is used, the factory jumper is set, or the
1082 usb_data_en gpio is set.
1084 if (!stingray_qbp_usb_hw_bypass_enabled()) {
1085 tegra_gpio_enable(TEGRA_GPIO_PV4);
1086 gpio_request(TEGRA_GPIO_PV4, "usb_data_en");
1087 gpio_direction_output(TEGRA_GPIO_PV4, 1);
1090 /* USB_FORCEON_N (TEGRA_GPIO_PC5) should be forced high at boot
1091 and will be pulled low by the hardware on attach */
1092 tegra_gpio_enable(TEGRA_GPIO_PC5);
1093 gpio_request(TEGRA_GPIO_PC5, "usb_forceon_n");
1094 gpio_direction_output(TEGRA_GPIO_PC5, 1);
1095 gpio_export(TEGRA_GPIO_PC5, false);
1097 tegra_gpio_enable(TEGRA_GPIO_PQ6);
1098 gpio_request(TEGRA_GPIO_PQ6, "usb_bp_rem_wake");
1099 gpio_direction_input(TEGRA_GPIO_PQ6);
1100 gpio_export(TEGRA_GPIO_PQ6, false);
1102 /* Enable charging */
1103 tegra_gpio_enable(TEGRA_GPIO_PV5);
1104 gpio_request(TEGRA_GPIO_PV5, "chg_stat1");
1105 gpio_direction_input(TEGRA_GPIO_PV5);
1106 gpio_export(TEGRA_GPIO_PV5, false);
1107 if (stingray_revision() <= STINGRAY_REVISION_P0) {
1108 bq24617_device.resource = bq24617_resources_m1_p0;
1109 bq24617_device.num_resources = ARRAY_SIZE(bq24617_resources_m1_p0);
1111 tegra_gpio_enable(TEGRA_GPIO_PV6);
1112 gpio_request(TEGRA_GPIO_PV6, "chg_stat2");
1113 gpio_direction_input(TEGRA_GPIO_PV6);
1114 gpio_export(TEGRA_GPIO_PV6, false);
1116 tegra_gpio_enable(TEGRA_GPIO_PJ0);
1117 gpio_request(TEGRA_GPIO_PJ0, "chg_disable");
1118 gpio_direction_output(TEGRA_GPIO_PJ0, 0);
1119 gpio_export(TEGRA_GPIO_PJ0, false);
1121 tegra_gpio_enable(TEGRA_GPIO_PV6);
1122 gpio_request(TEGRA_GPIO_PV6, "chg_detect");
1123 gpio_direction_input(TEGRA_GPIO_PV6);
1124 gpio_export(TEGRA_GPIO_PV6, false);
1126 tegra_gpio_enable(TEGRA_GPIO_PD1);
1127 gpio_request(TEGRA_GPIO_PD1, "chg_stat2");
1128 gpio_direction_input(TEGRA_GPIO_PD1);
1129 gpio_export(TEGRA_GPIO_PD1, false);
1131 if (stingray_revision() >= STINGRAY_REVISION_P2) {
1132 tegra_gpio_enable(TEGRA_GPIO_PS7);
1133 gpio_request(TEGRA_GPIO_PS7, "chg_disable");
1134 gpio_direction_output(TEGRA_GPIO_PS7, 0);
1135 gpio_export(TEGRA_GPIO_PS7, false);
1137 tegra_gpio_enable(TEGRA_GPIO_PI4);
1138 gpio_request(TEGRA_GPIO_PI4, "chg_disable");
1139 gpio_direction_output(TEGRA_GPIO_PI4, 0);
1140 gpio_export(TEGRA_GPIO_PI4, false);
1144 /* Enable charge LEDs */
1145 if (stingray_revision() >= STINGRAY_REVISION_P2) {
1146 tegra_gpio_enable(TEGRA_GPIO_PV0);
1147 gpio_request(TEGRA_GPIO_PV0, "chg_led_disable");
1148 gpio_direction_output(TEGRA_GPIO_PV0, 0);
1149 gpio_export(TEGRA_GPIO_PV0, false);
1150 } else if (stingray_revision() >= STINGRAY_REVISION_P0) {
1151 /* Set the SYS_CLK_REQ override bit to allow PZ5 to be used
1153 writel(0, IO_TO_VIRT(TEGRA_PMC_BASE + 0x01C));
1154 tegra_gpio_enable(TEGRA_GPIO_PZ5);
1155 gpio_request(TEGRA_GPIO_PZ5, "chg_led_disable");
1156 gpio_direction_output(TEGRA_GPIO_PZ5, 0);
1157 gpio_export(TEGRA_GPIO_PZ5, false);
1160 if (stingray_revision() <= STINGRAY_REVISION_P1) {
1161 pr_info("Disabling core dvfs on P1 hardware\n");
1162 tegra_dvfs_rail_disable_by_name("vdd_core");
1165 /* disable spdif GPIO for now */
1166 /* spdif line is turned on but never used, this causes pops
1167 on a speaker dock connected to HDMI monitor, later version
1168 h/w with spdif audio out will need this pin */
1169 tegra_gpio_enable(TEGRA_GPIO_PD4);
1170 gpio_request(TEGRA_GPIO_PD4, "spdif_enable");
1171 gpio_direction_output(TEGRA_GPIO_PD4, 0);
1172 gpio_export(TEGRA_GPIO_PD4, false);
1174 /* Enable 4329 Power GPIO */
1175 tegra_gpio_enable(TEGRA_GPIO_PU4);
1176 gpio_request(TEGRA_GPIO_PU4, "4329_pwr");
1177 gpio_direction_output(TEGRA_GPIO_PU4, 0);
1179 /* Enable GPIO for SD card detect */
1180 tegra_gpio_enable(TEGRA_GPIO_PI5);
1181 gpio_request(TEGRA_GPIO_PI5, "sdcard_detect");
1182 gpio_direction_input(TEGRA_GPIO_PI5);
1184 stingray_pinmux_init();
1186 tegra_clk_init_from_table(stingray_clk_init_table);
1188 clk = tegra_get_clock_by_name("uartb");
1189 tegra_serial_debug_init(TEGRA_UARTB_BASE, INT_UARTB,
1190 clk, INT_QUAD_RES_31, -1);
1194 tegra_i2s_device1.dev.platform_data = &tegra_audio_pdata;
1195 tegra_i2s_device2.dev.platform_data = &tegra_audio2_pdata;
1196 cpcap_device_register(&cpcap_audio_device);
1197 tegra_spdif_device.dev.platform_data = &tegra_spdif_pdata;
1199 tegra_ehci1_device.dev.platform_data = &tegra_ehci_pdata[0];
1200 tegra_uartc_device.dev.platform_data = &tegra_uartc_pdata;
1202 res = platform_get_resource(&ram_console_device, IORESOURCE_MEM, 0);
1203 res->start = ramconsole_start;
1204 res->end = ramconsole_start + ramconsole_size - 1;
1206 stingray_carveouts[1].base = tegra_carveout_start;
1207 stingray_carveouts[1].size = tegra_carveout_size;
1209 platform_add_devices(stingray_devices, ARRAY_SIZE(stingray_devices));
1211 stingray_i2c_init();
1212 stingray_power_off_init();
1213 stingray_keypad_init();
1214 stingray_touch_init();
1215 stingray_power_init();
1216 stingray_panel_init();
1217 stingray_sdhci_init();
1219 stingray_sensors_init();
1220 stingray_wlan_init();
1221 stingray_gps_init();
1222 stingray_usb_init();
1225 int __init stingray_protected_aperture_init(void)
1227 tegra_protected_aperture_init(tegra_grhost_aperture);
1228 memblock_free(tegra_bootloader_fb_start, tegra_bootloader_fb_size);
1231 late_initcall(stingray_protected_aperture_init);
1233 void __init stingray_map_io(void)
1235 tegra_map_common_io();
1238 static int __init stingray_ramconsole_arg(char *options)
1242 ramconsole_size = memparse(p, &p);
1244 ramconsole_start = memparse(p+1, &p);
1248 early_param("ramconsole", stingray_ramconsole_arg);
1250 void __init stingray_reserve(void)
1253 if (memblock_reserve(0x0, 4096) < 0)
1254 pr_warn("Cannot reserve first 4K of memory for safety\n");
1256 ret = memblock_remove(SZ_512M - SZ_2M, SZ_2M);
1258 pr_info("Failed to remove ram console\n");
1260 pr_info("Reserved %08lx@%08lx for ram console\n",
1261 ramconsole_start, ramconsole_size);
1263 tegra_reserve(SZ_256M, SZ_8M, SZ_16M);
1265 if (memblock_reserve(tegra_bootloader_fb_start, tegra_bootloader_fb_size))
1266 pr_info("Failed to reserve old framebuffer location\n");
1268 pr_info("HACK: Old framebuffer: %08lx - %08lx\n",
1269 tegra_bootloader_fb_start,
1270 tegra_bootloader_fb_start + tegra_bootloader_fb_size - 1);
1273 MACHINE_START(STINGRAY, "stingray")
1274 .boot_params = 0x00000100,
1275 .phys_io = IO_APB_PHYS,
1276 .io_pg_offst = ((IO_APB_VIRT) >> 18) & 0xfffc,
1277 .init_irq = tegra_init_irq,
1278 .init_machine = tegra_stingray_init,
1279 .map_io = stingray_map_io,
1280 .reserve = stingray_reserve,
1281 .timer = &tegra_timer,