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_ID_BLAN 0x70A3
85 #define USB_PRODUCT_ID_MTP 0x70A8
86 #define USB_PRODUCT_ID_MTP_ADB 0x70A9
87 #define USB_PRODUCT_ID_RNDIS 0x70AE
88 #define USB_PRODUCT_ID_RNDIS_ADB 0x70AF
89 #define USB_PRODUCT_ID_BP 0x70B0
90 #define USB_PRODUCT_ID_BP_ADB 0x70B1
91 #define USB_PRODUCT_ID_RNDIS_BP 0x70B2
92 #define USB_PRODUCT_ID_RNDIS_BP_ADB 0x70B3
93 #define USB_VENDOR_ID 0x22b8
101 static int __init parse_tag_nvidia(const struct tag *tag)
106 __tagtable(ATAG_NVIDIA, parse_tag_nvidia);
108 static unsigned long ramconsole_start = SZ_512M - SZ_1M;
109 static unsigned long ramconsole_size = SZ_1M;
111 static struct resource mdm6600_resources[] = {
113 .flags = IORESOURCE_IRQ,
114 .start = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PQ6),
115 .end = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PQ6),
119 static struct platform_device mdm6600_modem = {
120 .name = "mdm6600_modem",
122 .resource = mdm6600_resources,
123 .num_resources = ARRAY_SIZE(mdm6600_resources),
126 /* OTG gadget device */
127 static struct tegra_utmip_config udc_phy_config = {
128 .hssync_start_delay = 0,
129 .idle_wait_delay = 17,
137 static struct fsl_usb2_platform_data tegra_udc_pdata = {
138 .operating_mode = FSL_USB2_DR_DEVICE,
139 .phy_mode = FSL_USB2_PHY_UTMI,
140 .phy_config = &udc_phy_config,
143 /* OTG transceiver */
144 static struct resource cpcap_otg_resources[] = {
146 .start = TEGRA_USB_BASE,
147 .end = TEGRA_USB_BASE + TEGRA_USB_SIZE - 1,
148 .flags = IORESOURCE_MEM,
152 static struct platform_device cpcap_otg = {
155 .resource = cpcap_otg_resources,
156 .num_resources = ARRAY_SIZE(cpcap_otg_resources),
158 .platform_data = &tegra_ehci1_device,
162 static struct cpcap_audio_state stingray_cpcap_audio_state = {
164 .mode = CPCAP_AUDIO_MODE_NORMAL,
165 .codec_mode = CPCAP_AUDIO_CODEC_OFF,
166 .codec_rate = CPCAP_AUDIO_CODEC_RATE_8000_HZ,
167 .codec_mute = CPCAP_AUDIO_CODEC_MUTE,
168 .stdac_mode = CPCAP_AUDIO_STDAC_OFF,
169 .stdac_rate = CPCAP_AUDIO_STDAC_RATE_44100_HZ,
170 .stdac_mute = CPCAP_AUDIO_STDAC_MUTE,
171 .analog_source = CPCAP_AUDIO_ANALOG_SOURCE_OFF,
172 .codec_primary_speaker = CPCAP_AUDIO_OUT_NONE,
173 .codec_secondary_speaker = CPCAP_AUDIO_OUT_NONE,
174 .stdac_primary_speaker = CPCAP_AUDIO_OUT_NONE,
175 .stdac_secondary_speaker = CPCAP_AUDIO_OUT_NONE,
176 .ext_primary_speaker = CPCAP_AUDIO_OUT_NONE,
177 .ext_secondary_speaker = CPCAP_AUDIO_OUT_NONE,
178 .codec_primary_balance = CPCAP_AUDIO_BALANCE_NEUTRAL,
179 .stdac_primary_balance = CPCAP_AUDIO_BALANCE_NEUTRAL,
180 .ext_primary_balance = CPCAP_AUDIO_BALANCE_NEUTRAL,
182 .microphone = CPCAP_AUDIO_IN_NONE,
184 .rat_type = CPCAP_AUDIO_RAT_NONE
187 /* CPCAP is i2s master; tegra_audio_pdata.master == false */
188 static void init_dac2(bool bluetooth);
189 static struct cpcap_audio_platform_data cpcap_audio_pdata = {
191 .regulator = "vaudio",
192 .state = &stingray_cpcap_audio_state,
193 .speaker_gpio = TEGRA_GPIO_PR3,
195 .bluetooth_bypass = init_dac2,
198 static struct platform_device cpcap_audio_device = {
199 .name = "cpcap_audio",
202 .platform_data = &cpcap_audio_pdata,
206 /* This is the CPCAP Stereo DAC interface. */
207 static struct tegra_audio_platform_data tegra_audio_pdata = {
208 .i2s_master = false, /* CPCAP Stereo DAC */
209 .dsp_master = false, /* Don't care */
210 .dma_on = true, /* use dma by default */
211 .i2s_clk_rate = 24000000,
212 .dap_clk = "clk_dev1",
213 .audio_sync_clk = "audio_2x",
214 .mode = I2S_BIT_FORMAT_I2S,
215 .fifo_fmt = I2S_FIFO_PACKED,
216 .bit_size = I2S_BIT_SIZE_16,
217 .i2s_bus_width = 32, /* Using Packed 16 bit data, the dma is 32 bit. */
218 .dsp_bus_width = 16, /* When using DSP mode (unused), this should be 16 bit. */
219 .mask = TEGRA_AUDIO_ENABLE_TX,
222 /* Connected to CPCAP CODEC - Switchable to Bluetooth Audio. */
223 static struct tegra_audio_platform_data tegra_audio2_pdata = {
224 .i2s_master = false, /* CPCAP CODEC */
225 .dsp_master = true, /* Bluetooth */
226 .dsp_master_clk = 8000, /* Bluetooth audio speed */
227 .dma_on = true, /* use dma by default */
228 .i2s_clk_rate = 2000000, /* BCM4329 max bitclock is 2048000 Hz */
229 .dap_clk = "clk_dev1",
230 .audio_sync_clk = "audio_2x",
231 .mode = I2S_BIT_FORMAT_DSP, /* Using COCEC in network mode */
232 .fifo_fmt = I2S_FIFO_16_LSB,
233 .bit_size = I2S_BIT_SIZE_16,
234 .i2s_bus_width = 16, /* Capturing a single timeslot, mono 16 bits */
236 .mask = TEGRA_AUDIO_ENABLE_TX | TEGRA_AUDIO_ENABLE_RX,
239 static struct tegra_audio_platform_data tegra_spdif_pdata = {
240 .dma_on = true, /* use dma by default */
241 .i2s_clk_rate = 5644800,
242 .mode = SPDIF_BIT_MODE_MODE16BIT,
247 static char *usb_functions_mtp[] = { "mtp" };
248 static char *usb_functions_mtp_adb[] = { "mtp", "adb" };
249 #ifdef CONFIG_USB_ANDROID_ACCESSORY
250 static char *usb_functions_accessory[] = { "accessory" };
251 static char *usb_functions_accessory_adb[] = { "accessory", "adb" };
253 #ifdef CONFIG_USB_ANDROID_RNDIS
254 static char *usb_functions_rndis[] = { "rndis" };
255 static char *usb_functions_rndis_adb[] = { "rndis", "adb" };
257 static char *usb_functions_all[] = {
258 #ifdef CONFIG_USB_ANDROID_RNDIS
261 #ifdef CONFIG_USB_ANDROID_ACCESSORY
268 static struct android_usb_product usb_products[] = {
270 .product_id = USB_PRODUCT_ID_MTP,
271 .num_functions = ARRAY_SIZE(usb_functions_mtp),
272 .functions = usb_functions_mtp,
275 .product_id = USB_PRODUCT_ID_MTP_ADB,
276 .num_functions = ARRAY_SIZE(usb_functions_mtp_adb),
277 .functions = usb_functions_mtp_adb,
279 #ifdef CONFIG_USB_ANDROID_ACCESSORY
281 .vendor_id = USB_ACCESSORY_VENDOR_ID,
282 .product_id = USB_ACCESSORY_PRODUCT_ID,
283 .num_functions = ARRAY_SIZE(usb_functions_accessory),
284 .functions = usb_functions_accessory,
287 .vendor_id = USB_ACCESSORY_VENDOR_ID,
288 .product_id = USB_ACCESSORY_ADB_PRODUCT_ID,
289 .num_functions = ARRAY_SIZE(usb_functions_accessory_adb),
290 .functions = usb_functions_accessory_adb,
293 #ifdef CONFIG_USB_ANDROID_RNDIS
295 .product_id = USB_PRODUCT_ID_RNDIS,
296 .num_functions = ARRAY_SIZE(usb_functions_rndis),
297 .functions = usb_functions_rndis,
300 .product_id = USB_PRODUCT_ID_RNDIS_ADB,
301 .num_functions = ARRAY_SIZE(usb_functions_rndis_adb),
302 .functions = usb_functions_rndis_adb,
307 /* standard android USB platform data */
308 static struct android_usb_platform_data andusb_plat = {
309 .vendor_id = USB_VENDOR_ID,
310 .product_id = USB_PRODUCT_ID_MTP_ADB,
311 .manufacturer_name = USB_MANUFACTURER_NAME,
312 .product_name = USB_PRODUCT_NAME,
313 .serial_number = "0000",
314 .num_products = ARRAY_SIZE(usb_products),
315 .products = usb_products,
316 .num_functions = ARRAY_SIZE(usb_functions_all),
317 .functions = usb_functions_all,
320 static struct platform_device androidusb_device = {
321 .name = "android_usb",
324 .platform_data = &andusb_plat,
328 static char *factory_usb_functions[] = {
332 static struct android_usb_product factory_usb_products[] = {
334 .product_id = USB_PRODUCT_ID_BLAN,
335 .num_functions = ARRAY_SIZE(factory_usb_functions),
336 .functions = factory_usb_functions,
340 /* android USB platform data for factory test mode*/
341 static struct android_usb_platform_data andusb_plat_factory = {
342 .vendor_id = USB_VENDOR_ID,
343 .product_id = USB_PRODUCT_ID_BLAN,
344 .manufacturer_name = USB_MANUFACTURER_NAME,
345 .product_name = USB_PRODUCT_NAME,
346 .serial_number = "000000000",
347 .num_products = ARRAY_SIZE(factory_usb_products),
348 .products = factory_usb_products,
349 .num_functions = ARRAY_SIZE(factory_usb_functions),
350 .functions = factory_usb_functions,
353 static char *bp_usb_functions_bp[] = {
355 static char *bp_usb_functions_bp_adb[] = {
356 "acm", "usbnet", "adb"};
357 static char *bp_usb_functions_rndis_bp[] = {
358 "rndis", "acm", "usbnet"};
359 static char *bp_usb_functions_all[] = {
360 "rndis", "acm", "usbnet", "adb"};
362 static struct android_usb_product bp_usb_products[] = {
364 .product_id = USB_PRODUCT_ID_BP,
365 .num_functions = ARRAY_SIZE(bp_usb_functions_bp),
366 .functions = bp_usb_functions_bp,
369 .product_id = USB_PRODUCT_ID_BP_ADB,
370 .num_functions = ARRAY_SIZE(bp_usb_functions_bp_adb),
371 .functions = bp_usb_functions_bp_adb,
374 .product_id = USB_PRODUCT_ID_RNDIS_BP,
375 .num_functions = ARRAY_SIZE(bp_usb_functions_rndis_bp),
376 .functions = bp_usb_functions_rndis_bp,
379 .product_id = USB_PRODUCT_ID_RNDIS_BP_ADB,
380 .num_functions = ARRAY_SIZE(bp_usb_functions_all),
381 .functions = bp_usb_functions_all,
385 static struct android_usb_platform_data andusb_plat_bp = {
386 .vendor_id = USB_VENDOR_ID,
387 .product_id = USB_PRODUCT_ID_BP_ADB,
388 .manufacturer_name = USB_MANUFACTURER_NAME,
389 .product_name = USB_PRODUCT_NAME,
390 .serial_number = "0000",
391 .num_products = ARRAY_SIZE(bp_usb_products),
392 .products = bp_usb_products,
393 .num_functions = ARRAY_SIZE(bp_usb_functions_all),
394 .functions = bp_usb_functions_all,
397 static struct platform_device usbnet_device = {
401 #ifdef CONFIG_USB_ANDROID_RNDIS
402 static struct usb_ether_platform_data rndis_pdata = {
403 /* ethaddr is filled by board_serialno_setup */
404 .vendorID = USB_VENDOR_ID,
405 .vendorDescr = USB_MANUFACTURER_NAME,
408 static struct platform_device rndis_device = {
412 .platform_data = &rndis_pdata,
417 static struct acm_platform_data acm_pdata = {
418 /* Modify num_inst at runtime depending on boot_mode */
422 static struct platform_device acm_device = {
426 .platform_data = &acm_pdata,
430 static struct tegra_utmip_config utmi_phy_config[] = {
432 .hssync_start_delay = 0,
433 .idle_wait_delay = 17,
441 .hssync_start_delay = 0,
442 .idle_wait_delay = 17,
451 static struct tegra_ulpi_config ulpi_phy_config = {
452 .reset_gpio = TEGRA_GPIO_PG2,
456 static struct tegra_ehci_platform_data tegra_ehci_pdata[] = {
458 .phy_config = &utmi_phy_config[0],
459 .operating_mode = TEGRA_USB_OTG,
460 .power_down_on_bus_suspend = 0,
463 .phy_config = &ulpi_phy_config,
464 .operating_mode = TEGRA_USB_HOST,
465 .power_down_on_bus_suspend = 1,
468 .phy_config = &utmi_phy_config[1],
469 .operating_mode = TEGRA_USB_HOST,
470 .power_down_on_bus_suspend = 1,
474 /* bq24617 charger */
475 static struct resource bq24617_resources[] = {
478 .flags = IORESOURCE_IRQ,
479 .start = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PV5),
480 .end = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PV5),
484 .flags = IORESOURCE_IRQ,
485 .start = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PD1),
486 .end = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PD1),
490 .flags = IORESOURCE_IRQ,
491 .start = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PV6),
492 .end = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PV6),
496 static struct resource bq24617_resources_m1_p0[] = {
499 .flags = IORESOURCE_IRQ,
500 .start = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PV5),
501 .end = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PV5),
505 .flags = IORESOURCE_IRQ,
506 .start = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PV6),
507 .end = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PV6),
511 static struct platform_device bq24617_device = {
514 .resource = bq24617_resources,
515 .num_resources = ARRAY_SIZE(bq24617_resources),
518 static struct resource tegra_gart_resources[] = {
521 .flags = IORESOURCE_MEM,
522 .start = TEGRA_MC_BASE,
523 .end = TEGRA_MC_BASE + TEGRA_MC_SIZE - 1,
527 .flags = IORESOURCE_MEM,
529 .end = 0x58000000 - 1 + 32 * 1024 * 1024,
534 static struct platform_device tegra_gart_dev = {
535 .name = "tegra_gart",
537 .num_resources = ARRAY_SIZE(tegra_gart_resources),
538 .resource = tegra_gart_resources
541 static struct platform_device bcm4329_bluetooth_device = {
542 .name = "bcm4329_bluetooth",
546 static struct platform_device tegra_camera = {
547 .name = "tegra_camera",
551 static struct tegra_w1_timings tegra_w1_platform_timings = {
568 static struct tegra_w1_platform_data tegra_w1_pdata = {
570 .timings = &tegra_w1_platform_timings,
573 static struct resource ram_console_resources[] = {
575 /* .start and .end filled in later */
576 .flags = IORESOURCE_MEM,
580 static struct platform_device ram_console_device = {
581 .name = "ram_console",
583 .num_resources = ARRAY_SIZE(ram_console_resources),
584 .resource = ram_console_resources,
587 static struct nvmap_platform_carveout stingray_carveouts[] = {
590 .usage_mask = NVMAP_HEAP_CARVEOUT_IRAM,
591 .base = TEGRA_IRAM_BASE,
592 .size = TEGRA_IRAM_SIZE,
597 .usage_mask = NVMAP_HEAP_CARVEOUT_GENERIC,
598 /* .base and .size to be filled in later */
599 .buddy_size = SZ_32K,
603 static struct nvmap_platform_data stingray_nvmap_data = {
604 .carveouts = stingray_carveouts,
605 .nr_carveouts = ARRAY_SIZE(stingray_carveouts),
608 static struct platform_device stingray_nvmap_device = {
609 .name = "tegra-nvmap",
612 .platform_data = &stingray_nvmap_data,
616 static struct tegra_hsuart_platform_data tegra_uartc_pdata = {
617 .exit_lpm_cb = bcm_bt_lpm_exit_lpm_locked,
618 .rx_done_cb = bcm_bt_rx_done_locked,
621 static struct platform_device *stingray_devices[] __initdata = {
624 &bcm4329_bluetooth_device,
634 &stingray_nvmap_device,
635 &tegra_grhost_device,
648 extern struct tegra_sdhci_platform_data stingray_wifi_data; /* sdhci2 */
650 static struct tegra_sdhci_platform_data stingray_sdhci_platform_data4 = {
658 static struct tegra_i2c_platform_data stingray_i2c1_platform_data = {
661 .bus_clk_rate = { 400000 },
664 static struct tegra_i2c_platform_data stingray_i2c2_platform_data = {
669 static struct tegra_i2c_platform_data stingray_i2c3_platform_data = {
672 .bus_clk_rate = { 400000 },
675 static struct tegra_i2c_platform_data stingray_i2c4_platform_data = {
678 .bus_clk_rate = { 400000 },
682 static __initdata struct tegra_clk_init_table stingray_clk_init_table[] = {
683 /* name parent rate enabled */
684 { "uartb", "clk_m", 26000000, true},
685 { "uartc", "pll_m", 600000000, false},
686 /*{ "emc", "pll_p", 0, true},
687 { "emc", "pll_m", 600000000, false},*/
688 { "pll_m", NULL, 600000000, true},
689 { "mpe", "pll_m", 250000000, false},
690 { "pll_a", NULL, 56448000, false},
691 { "pll_a_out0", NULL, 11289600, false},
692 { "i2s1", "pll_p", 24000000, false},
693 { "i2s2", "pll_p", 2000000, false},
694 { "sdmmc2", "pll_m", 48000000, false},
695 { "spdif_out", "pll_a_out0", 5644800, false},
699 static void stingray_i2c_init(void)
701 tegra_i2c_device1.dev.platform_data = &stingray_i2c1_platform_data;
702 tegra_i2c_device2.dev.platform_data = &stingray_i2c2_platform_data;
703 tegra_i2c_device3.dev.platform_data = &stingray_i2c3_platform_data;
704 tegra_i2c_device4.dev.platform_data = &stingray_i2c4_platform_data;
706 platform_device_register(&tegra_i2c_device1);
707 platform_device_register(&tegra_i2c_device2);
708 platform_device_register(&tegra_i2c_device3);
709 platform_device_register(&tegra_i2c_device4);
712 static void stingray_sdhci_init(void)
714 /* TODO: setup GPIOs for cd, wd, and power */
715 tegra_sdhci_device2.dev.platform_data = &stingray_wifi_data;
716 tegra_sdhci_device4.dev.platform_data = &stingray_sdhci_platform_data4;
718 platform_device_register(&tegra_sdhci_device2);
719 platform_device_register(&tegra_sdhci_device4);
721 #define ATAG_BDADDR 0x43294329 /* stingray bluetooth address tag */
722 #define ATAG_BDADDR_SIZE 4
723 #define BDADDR_STR_SIZE 18
725 static char bdaddr[BDADDR_STR_SIZE];
727 module_param_string(bdaddr, bdaddr, sizeof(bdaddr), 0400);
728 MODULE_PARM_DESC(bdaddr, "bluetooth address");
730 static int __init parse_tag_bdaddr(const struct tag *tag)
732 unsigned char *b = (unsigned char *)&tag->u;
734 if (tag->hdr.size != ATAG_BDADDR_SIZE)
737 snprintf(bdaddr, BDADDR_STR_SIZE, "%02X:%02X:%02X:%02X:%02X:%02X",
738 b[0], b[1], b[2], b[3], b[4], b[5]);
742 __tagtable(ATAG_BDADDR, parse_tag_bdaddr);
744 static DEFINE_SPINLOCK(brcm_4329_enable_lock);
745 static int brcm_4329_enable_count;
747 static void stingray_w1_init(void)
749 tegra_w1_device.dev.platform_data = &tegra_w1_pdata;
750 platform_device_register(&tegra_w1_device);
754 #define ATAG_POWERUP_REASON 0xf1000401
755 #define ATAG_POWERUP_REASON_SIZE 3 /* size + tag id + tag data */
757 static unsigned int powerup_reason = PU_REASON_PWR_KEY_PRESS;
759 unsigned int stingray_powerup_reason (void)
761 return powerup_reason;
764 static int __init parse_tag_powerup_reason(const struct tag *tag)
766 if (tag->hdr.size != ATAG_POWERUP_REASON_SIZE)
768 memcpy(&powerup_reason, &tag->u, sizeof(powerup_reason));
769 printk(KERN_INFO "powerup reason=0x%08x\n", powerup_reason);
772 __tagtable(ATAG_POWERUP_REASON, parse_tag_powerup_reason);
774 #define BOOT_MODE_MAX_LEN 30
775 static char boot_mode[BOOT_MODE_MAX_LEN + 1];
776 int __init board_boot_mode_init(char *s)
778 strncpy(boot_mode, s, BOOT_MODE_MAX_LEN);
779 boot_mode[BOOT_MODE_MAX_LEN] = '\0';
780 printk(KERN_INFO "boot_mode=%s\n", boot_mode);
783 __setup("androidboot.mode=", board_boot_mode_init);
785 #define SERIAL_NUMBER_LENGTH 16
786 static char usb_serial_num[SERIAL_NUMBER_LENGTH + 1];
787 static int __init mot_usb_serial_num_setup(char *options)
789 strncpy(usb_serial_num, options, SERIAL_NUMBER_LENGTH);
790 usb_serial_num[SERIAL_NUMBER_LENGTH] = '\0';
791 printk(KERN_INFO "usb_serial_num=%s\n", usb_serial_num);
794 __setup("androidboot.serialno=", mot_usb_serial_num_setup);
796 static int mot_boot_recovery = 0;
797 static int __init mot_bm_recovery_setup(char *options)
799 mot_boot_recovery = 1;
802 __setup("rec", mot_bm_recovery_setup);
804 #define PRODUCT_TYPE_MAX_LEN 4
805 static char product_type[PRODUCT_TYPE_MAX_LEN + 1] = "cw";
806 static int __init stingray_product_type_parse(char *s)
808 strncpy(product_type, s, PRODUCT_TYPE_MAX_LEN);
809 product_type[PRODUCT_TYPE_MAX_LEN] = '\0';
810 printk(KERN_INFO "product_type=%s\n", product_type);
814 __setup("product_type=", stingray_product_type_parse);
816 bool stingray_hw_has_cdma(void)
818 return strstr(product_type, "c") != NULL;
821 bool stingray_hw_has_lte(void)
823 return strstr(product_type, "l") != NULL;
826 bool stingray_hw_has_wifi(void)
828 return strstr(product_type, "w") != NULL;
831 bool stingray_hw_has_umts(void)
833 return strstr(product_type, "u") != NULL;
836 static void stingray_usb_init(void)
841 struct android_usb_platform_data *platform_data;
843 int factorycable = !strncmp(boot_mode, "factorycable",
846 tegra_udc_device.dev.platform_data = &tegra_udc_pdata;
847 tegra_ehci2_device.dev.platform_data = &tegra_ehci_pdata[1];
848 tegra_ehci3_device.dev.platform_data = &tegra_ehci_pdata[2];
850 if (!(factorycable && mot_boot_recovery))
851 platform_device_register(&tegra_udc_device);
853 if (stingray_hw_has_cdma())
854 platform_device_register(&tegra_ehci2_device);
856 platform_device_register(&tegra_ehci3_device);
858 #ifdef CONFIG_USB_ANDROID_RNDIS
859 src = usb_serial_num;
861 /* create a fake MAC address from our serial number.
862 * first byte is 0x02 to signify locally administered.
864 rndis_pdata.ethaddr[0] = 0x02;
865 for (i = 0; *src; i++) {
866 /* XOR the USB serial across the remaining bytes */
867 rndis_pdata.ethaddr[i % (ETH_ALEN - 1) + 1] ^= *src++;
869 platform_device_register(&rndis_device);
872 if (!(factorycable && mot_boot_recovery)) {
874 platform_data = &andusb_plat_factory;
875 platform_device_register(&usbnet_device);
876 } else if (!strncmp(boot_mode, "bp-tools",
877 BOOT_MODE_MAX_LEN)) {
878 platform_data = &andusb_plat_bp;
879 platform_device_register(&usbnet_device);
880 /* acm: LTE Modem + QC Modem + QC Diag */
881 acm_pdata.num_inst = 3;
882 platform_device_register(&acm_device);
884 platform_data = &andusb_plat;
887 platform_data->serial_number = usb_serial_num;
888 androidusb_device.dev.platform_data = platform_data;
889 platform_device_register(&androidusb_device);
893 static void stingray_reset(char mode, const char *cmd)
895 /* Signal to CPCAP to stop the uC. */
896 gpio_set_value(TEGRA_GPIO_PG3, 0);
898 gpio_set_value(TEGRA_GPIO_PG3, 1);
901 tegra_assert_system_reset();
904 static void stingray_power_off(void)
906 printk(KERN_INFO "stingray_pm_power_off...\n");
910 /* signal WDI gpio to shutdown CPCAP, which will
911 cascade to all of the regulators. */
912 gpio_direction_output(TEGRA_GPIO_PV7, 0);
919 static void __init stingray_power_off_init(void)
921 tegra_gpio_enable(TEGRA_GPIO_PG3);
922 gpio_request(TEGRA_GPIO_PG3, "sys_restart_b");
923 gpio_direction_output(TEGRA_GPIO_PG3, 1);
924 tegra_reset = stingray_reset;
926 tegra_gpio_enable(TEGRA_GPIO_PV7);
927 if (!gpio_request(TEGRA_GPIO_PV7, "wdi"))
928 pm_power_off = stingray_power_off;
931 static unsigned int stingray_board_revision = STINGRAY_REVISION_UNKNOWN;
933 unsigned int stingray_revision(void)
935 return stingray_board_revision;
938 static int __init stingray_revision_parse(char *options)
940 if (!strcmp(options, "m1"))
941 stingray_board_revision = STINGRAY_REVISION_M1;
942 else if (!strcmp(options, "p0"))
943 stingray_board_revision = STINGRAY_REVISION_P0;
944 else if (!strcmp(options, "p1"))
945 stingray_board_revision = STINGRAY_REVISION_P1;
946 else if (!strcmp(options, "p2"))
947 stingray_board_revision = STINGRAY_REVISION_P2;
948 else if (!strcmp(options, "p3"))
949 stingray_board_revision = STINGRAY_REVISION_P3;
951 stingray_board_revision = system_rev;
953 printk(KERN_INFO "hw_rev=0x%x\n", stingray_board_revision);
957 __setup("hw_rev=", stingray_revision_parse);
959 int stingray_qbp_usb_hw_bypass_enabled(void)
961 /* We could use the boot_mode string instead of probing the HW, but
962 * that would not work if we enable run-time switching to this mode
965 if (gpio_get_value(TEGRA_GPIO_PT3) && !gpio_get_value(TEGRA_GPIO_PV4)) {
966 pr_info("stingray_qbp_usb_hw_bypass enabled\n");
972 static struct tegra_suspend_platform_data stingray_suspend = {
975 .core_timer = 0x7e7e,
976 .core_off_timer = 0xf,
977 .separate_req = true,
978 .corereq_high = true,
979 .sysclkreq_high = true,
980 .suspend_mode = TEGRA_SUSPEND_LP0,
983 static void *das_base = IO_ADDRESS(TEGRA_APB_MISC_BASE);
985 static inline void das_writel(unsigned long value, unsigned long offset)
987 writel(value, das_base + offset);
990 #define APB_MISC_DAS_DAP_CTRL_SEL_0 0xc00
991 #define APB_MISC_DAS_DAC_INPUT_DATA_CLK_SEL_0 0xc40
993 static void init_dac1(void)
995 bool master = tegra_audio_pdata.i2s_master;
997 das_writel((!master)<<31, APB_MISC_DAS_DAP_CTRL_SEL_0);
998 das_writel(0, APB_MISC_DAS_DAC_INPUT_DATA_CLK_SEL_0);
1001 static void init_dac2(bool bluetooth)
1004 /* DAC2 -> DAP2 for CPCAP CODEC */
1005 bool master = tegra_audio2_pdata.i2s_master;
1006 das_writel((!master)<<31 | 1, APB_MISC_DAS_DAP_CTRL_SEL_0 + 4);
1007 das_writel(1<<28 | 1<<24 | 1,
1008 APB_MISC_DAS_DAC_INPUT_DATA_CLK_SEL_0 + 4);
1010 /* DAC2 -> DAP4 for Bluetooth Voice */
1011 bool master = tegra_audio2_pdata.dsp_master;
1012 das_writel((!master)<<31 | 1, APB_MISC_DAS_DAP_CTRL_SEL_0 + 12);
1013 das_writel(3<<28 | 3<<24 | 3,
1014 APB_MISC_DAS_DAC_INPUT_DATA_CLK_SEL_0 + 4);
1018 void change_power_brcm_4329(bool enable) {
1019 unsigned long flags;
1021 spin_lock_irqsave(&brcm_4329_enable_lock, flags);
1023 gpio_set_value(TEGRA_GPIO_PU4, enable);
1024 brcm_4329_enable_count++;
1025 // The following shouldn't happen but protect
1026 // if the user doesn't cleanup.
1027 if (brcm_4329_enable_count > 2)
1028 brcm_4329_enable_count = 2;
1030 if (brcm_4329_enable_count > 0)
1031 brcm_4329_enable_count--;
1032 if (!brcm_4329_enable_count)
1033 gpio_set_value(TEGRA_GPIO_PU4, enable);
1035 spin_unlock_irqrestore(&brcm_4329_enable_lock, flags);
1038 static void __init tegra_stingray_init(void)
1041 struct resource *res;
1043 /* force consoles to stay enabled across suspend/resume */
1044 console_suspend_enabled = 0;
1046 tegra_common_init();
1047 tegra_init_suspend(&stingray_suspend);
1048 stingray_init_emc();
1050 /* Set the SDMMC2 (wifi) tap delay to 6. This value is determined
1051 * based on propagation delay on the PCB traces. */
1052 clk = clk_get_sys("sdhci-tegra.1", NULL);
1054 tegra_sdmmc_tap_delay(clk, 6);
1057 pr_err("Failed to set wifi sdmmc tap delay\n");
1060 /* Stingray has a USB switch that disconnects the usb port from the T20
1061 unless a factory cable is used, the factory jumper is set, or the
1062 usb_data_en gpio is set.
1064 if (!stingray_qbp_usb_hw_bypass_enabled()) {
1065 tegra_gpio_enable(TEGRA_GPIO_PV4);
1066 gpio_request(TEGRA_GPIO_PV4, "usb_data_en");
1067 gpio_direction_output(TEGRA_GPIO_PV4, 1);
1070 /* USB_FORCEON_N (TEGRA_GPIO_PC5) should be forced high at boot
1071 and will be pulled low by the hardware on attach */
1072 tegra_gpio_enable(TEGRA_GPIO_PC5);
1073 gpio_request(TEGRA_GPIO_PC5, "usb_forceon_n");
1074 gpio_direction_output(TEGRA_GPIO_PC5, 1);
1075 gpio_export(TEGRA_GPIO_PC5, false);
1077 tegra_gpio_enable(TEGRA_GPIO_PQ6);
1078 gpio_request(TEGRA_GPIO_PQ6, "usb_bp_rem_wake");
1079 gpio_direction_input(TEGRA_GPIO_PQ6);
1080 gpio_export(TEGRA_GPIO_PQ6, false);
1082 /* Enable charging */
1083 tegra_gpio_enable(TEGRA_GPIO_PV5);
1084 gpio_request(TEGRA_GPIO_PV5, "chg_stat1");
1085 gpio_direction_input(TEGRA_GPIO_PV5);
1086 gpio_export(TEGRA_GPIO_PV5, false);
1087 if (stingray_revision() <= STINGRAY_REVISION_P0) {
1088 bq24617_device.resource = bq24617_resources_m1_p0;
1089 bq24617_device.num_resources = ARRAY_SIZE(bq24617_resources_m1_p0);
1091 tegra_gpio_enable(TEGRA_GPIO_PV6);
1092 gpio_request(TEGRA_GPIO_PV6, "chg_stat2");
1093 gpio_direction_input(TEGRA_GPIO_PV6);
1094 gpio_export(TEGRA_GPIO_PV6, false);
1096 tegra_gpio_enable(TEGRA_GPIO_PJ0);
1097 gpio_request(TEGRA_GPIO_PJ0, "chg_disable");
1098 gpio_direction_output(TEGRA_GPIO_PJ0, 0);
1099 gpio_export(TEGRA_GPIO_PJ0, false);
1101 tegra_gpio_enable(TEGRA_GPIO_PV6);
1102 gpio_request(TEGRA_GPIO_PV6, "chg_detect");
1103 gpio_direction_input(TEGRA_GPIO_PV6);
1104 gpio_export(TEGRA_GPIO_PV6, false);
1106 tegra_gpio_enable(TEGRA_GPIO_PD1);
1107 gpio_request(TEGRA_GPIO_PD1, "chg_stat2");
1108 gpio_direction_input(TEGRA_GPIO_PD1);
1109 gpio_export(TEGRA_GPIO_PD1, false);
1111 if (stingray_revision() >= STINGRAY_REVISION_P2) {
1112 tegra_gpio_enable(TEGRA_GPIO_PS7);
1113 gpio_request(TEGRA_GPIO_PS7, "chg_disable");
1114 gpio_direction_output(TEGRA_GPIO_PS7, 0);
1115 gpio_export(TEGRA_GPIO_PS7, false);
1117 tegra_gpio_enable(TEGRA_GPIO_PI4);
1118 gpio_request(TEGRA_GPIO_PI4, "chg_disable");
1119 gpio_direction_output(TEGRA_GPIO_PI4, 0);
1120 gpio_export(TEGRA_GPIO_PI4, false);
1124 /* Enable charge LEDs */
1125 if (stingray_revision() >= STINGRAY_REVISION_P2) {
1126 tegra_gpio_enable(TEGRA_GPIO_PV0);
1127 gpio_request(TEGRA_GPIO_PV0, "chg_led_disable");
1128 gpio_direction_output(TEGRA_GPIO_PV0, 0);
1129 gpio_export(TEGRA_GPIO_PV0, false);
1130 } else if (stingray_revision() >= STINGRAY_REVISION_P0) {
1131 /* Set the SYS_CLK_REQ override bit to allow PZ5 to be used
1133 writel(0, IO_TO_VIRT(TEGRA_PMC_BASE + 0x01C));
1134 tegra_gpio_enable(TEGRA_GPIO_PZ5);
1135 gpio_request(TEGRA_GPIO_PZ5, "chg_led_disable");
1136 gpio_direction_output(TEGRA_GPIO_PZ5, 0);
1137 gpio_export(TEGRA_GPIO_PZ5, false);
1140 if (stingray_revision() <= STINGRAY_REVISION_P1) {
1141 pr_info("Disabling core dvfs on P1 hardware\n");
1142 tegra_dvfs_rail_disable_by_name("vdd_core");
1145 /* Enable 4329 Power GPIO */
1146 tegra_gpio_enable(TEGRA_GPIO_PU4);
1147 gpio_request(TEGRA_GPIO_PU4, "4329_pwr");
1148 gpio_direction_output(TEGRA_GPIO_PU4, 0);
1150 stingray_pinmux_init();
1152 tegra_clk_init_from_table(stingray_clk_init_table);
1154 clk = tegra_get_clock_by_name("uartb");
1155 tegra_serial_debug_init(TEGRA_UARTB_BASE, INT_UARTB,
1156 clk, INT_QUAD_RES_31, -1);
1160 tegra_i2s_device1.dev.platform_data = &tegra_audio_pdata;
1161 tegra_i2s_device2.dev.platform_data = &tegra_audio2_pdata;
1162 cpcap_device_register(&cpcap_audio_device);
1163 tegra_spdif_device.dev.platform_data = &tegra_spdif_pdata;
1165 tegra_ehci1_device.dev.platform_data = &tegra_ehci_pdata[0];
1166 tegra_uartc_device.dev.platform_data = &tegra_uartc_pdata;
1168 res = platform_get_resource(&ram_console_device, IORESOURCE_MEM, 0);
1169 res->start = ramconsole_start;
1170 res->end = ramconsole_start + ramconsole_size - 1;
1172 stingray_carveouts[1].base = tegra_carveout_start;
1173 stingray_carveouts[1].size = tegra_carveout_size;
1175 platform_add_devices(stingray_devices, ARRAY_SIZE(stingray_devices));
1177 stingray_i2c_init();
1178 stingray_power_off_init();
1179 stingray_keypad_init();
1180 stingray_touch_init();
1181 stingray_power_init();
1182 stingray_panel_init();
1183 stingray_sdhci_init();
1185 stingray_sensors_init();
1186 stingray_wlan_init();
1187 stingray_gps_init();
1188 stingray_usb_init();
1191 int __init stingray_protected_aperture_init(void)
1193 tegra_protected_aperture_init(tegra_grhost_aperture);
1194 memblock_free(tegra_bootloader_fb_start, tegra_bootloader_fb_size);
1197 late_initcall(stingray_protected_aperture_init);
1199 void __init stingray_map_io(void)
1201 tegra_map_common_io();
1204 static int __init stingray_ramconsole_arg(char *options)
1208 ramconsole_size = memparse(p, &p);
1210 ramconsole_start = memparse(p+1, &p);
1214 early_param("ramconsole", stingray_ramconsole_arg);
1216 void __init stingray_reserve(void)
1219 if (memblock_reserve(0x0, 4096) < 0)
1220 pr_warn("Cannot reserve first 4K of memory for safety\n");
1222 ret = memblock_remove(SZ_512M - SZ_2M, SZ_2M);
1224 pr_info("Failed to remove ram console\n");
1226 pr_info("Reserved %08lx@%08lx for ram console\n",
1227 ramconsole_start, ramconsole_size);
1229 tegra_reserve(SZ_256M, SZ_8M, SZ_16M);
1231 if (memblock_reserve(tegra_bootloader_fb_start, tegra_bootloader_fb_size))
1232 pr_info("Failed to reserve old framebuffer location\n");
1234 pr_info("HACK: Old framebuffer: %08lx - %08lx\n",
1235 tegra_bootloader_fb_start,
1236 tegra_bootloader_fb_start + tegra_bootloader_fb_size - 1);
1239 MACHINE_START(STINGRAY, "stingray")
1240 .boot_params = 0x00000100,
1241 .phys_io = IO_APB_PHYS,
1242 .io_pg_offst = ((IO_APB_VIRT) >> 18) & 0xfffc,
1243 .init_irq = tegra_init_irq,
1244 .init_machine = tegra_stingray_init,
1245 .map_io = stingray_map_io,
1246 .reserve = stingray_reserve,
1247 .timer = &tegra_timer,