temp revert rk change
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-tegra / board-stingray.c
1 /*
2  * arch/arm/mach-tegra/board-stingray.c
3  *
4  * Copyright (C) 2010 Google, Inc.
5  *
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.
9  *
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.
14  *
15  */
16
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>
35
36 #include <asm/mach-types.h>
37 #include <asm/mach/arch.h>
38 #include <asm/mach/time.h>
39 #include <asm/setup.h>
40
41 #include <mach/io.h>
42 #include <mach/w1.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>
48 #include <mach/clk.h>
49 #include <mach/usb_phy.h>
50 #include <mach/i2s.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>
60
61 #include <linux/usb/android_composite.h>
62 #include <linux/usb/f_accessory.h>
63
64 #include "board.h"
65 #include "board-stingray.h"
66 #include "clock.h"
67 #include "gpio-names.h"
68 #include "devices.h"
69
70 /* NVidia bootloader tags */
71 #define ATAG_NVIDIA             0x41000801
72
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
81
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
96
97 struct tag_tegra {
98         __u32 bootarg_key;
99         __u32 bootarg_len;
100         char bootarg[1];
101 };
102
103 static int __init parse_tag_nvidia(const struct tag *tag)
104 {
105
106         return 0;
107 }
108 __tagtable(ATAG_NVIDIA, parse_tag_nvidia);
109
110 static unsigned long ramconsole_start = SZ_512M - SZ_1M;
111 static unsigned long ramconsole_size = SZ_1M;
112
113 static struct resource mdm6600_resources[] = {
114         [0] = {
115                 .flags = IORESOURCE_IRQ,
116                 .start = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PQ6),
117                 .end   = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PQ6),
118         },
119 };
120
121 static struct platform_device mdm6600_modem = {
122         .name = "mdm6600_modem",
123         .id   = -1,
124         .resource = mdm6600_resources,
125         .num_resources = ARRAY_SIZE(mdm6600_resources),
126 };
127
128 /* OTG gadget device */
129 static struct tegra_utmip_config udc_phy_config = {
130         .hssync_start_delay = 0,
131         .idle_wait_delay = 17,
132         .elastic_limit = 16,
133         .term_range_adj = 6,
134         .xcvr_setup = 15,
135         .xcvr_lsfslew = 1,
136         .xcvr_lsrslew = 1,
137 };
138
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,
143 };
144
145 /* OTG transceiver */
146 static struct resource cpcap_otg_resources[] = {
147         [0] = {
148                 .start  = TEGRA_USB_BASE,
149                 .end    = TEGRA_USB_BASE + TEGRA_USB_SIZE - 1,
150                 .flags  = IORESOURCE_MEM,
151         },
152 };
153
154 static struct platform_device cpcap_otg = {
155         .name = "cpcap-otg",
156         .id   = -1,
157         .resource = cpcap_otg_resources,
158         .num_resources = ARRAY_SIZE(cpcap_otg_resources),
159         .dev = {
160                 .platform_data = &tegra_ehci1_device,
161         },
162 };
163
164 static struct cpcap_audio_state stingray_cpcap_audio_state = {
165         .cpcap                   = NULL,
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,
183         .output_gain             = 7,
184         .microphone              = CPCAP_AUDIO_IN_NONE,
185         .input_gain              = 31,
186         .rat_type                = CPCAP_AUDIO_RAT_NONE
187 };
188
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 = {
192         .master = true,
193         .regulator = "vaudio",
194         .state = &stingray_cpcap_audio_state,
195         .speaker_gpio = TEGRA_GPIO_PR3,
196         .headset_gpio = -1,
197         .spdif_gpio = TEGRA_GPIO_PD4,
198         .bluetooth_bypass = init_dac2,
199 };
200
201 static struct platform_device cpcap_audio_device = {
202         .name   = "cpcap_audio",
203         .id     = -1,
204         .dev    = {
205                 .platform_data = &cpcap_audio_pdata,
206         },
207 };
208
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,
223 };
224
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 */
238         .dsp_bus_width = 16,
239         .mask           = TEGRA_AUDIO_ENABLE_TX | TEGRA_AUDIO_ENABLE_RX,
240 };
241
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,
246         .fifo_fmt       = 1,
247 };
248
249
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" };
255 #endif
256 #ifdef CONFIG_USB_ANDROID_RNDIS
257 static char *usb_functions_rndis[] = { "rndis" };
258 static char *usb_functions_rndis_adb[] = { "rndis", "adb" };
259 #endif
260 static char *usb_functions_all[] = {
261 #ifdef CONFIG_USB_ANDROID_RNDIS
262         "rndis",
263 #endif
264 #ifdef CONFIG_USB_ANDROID_ACCESSORY
265         "accessory",
266 #endif
267         "mtp",
268         "adb"
269 };
270
271 static struct android_usb_product usb_products[] = {
272         {
273                 .product_id     = USB_PRODUCT_ID_MTP,
274                 .num_functions  = ARRAY_SIZE(usb_functions_mtp),
275                 .functions      = usb_functions_mtp,
276         },
277         {
278                 .product_id     = USB_PRODUCT_ID_MTP_ADB,
279                 .num_functions  = ARRAY_SIZE(usb_functions_mtp_adb),
280                 .functions      = usb_functions_mtp_adb,
281         },
282 #ifdef CONFIG_USB_ANDROID_ACCESSORY
283         {
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,
288         },
289         {
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,
294         },
295 #endif
296 #ifdef CONFIG_USB_ANDROID_RNDIS
297         {
298                 .product_id     = USB_PRODUCT_ID_RNDIS,
299                 .num_functions  = ARRAY_SIZE(usb_functions_rndis),
300                 .functions      = usb_functions_rndis,
301         },
302         {
303                 .product_id     = USB_PRODUCT_ID_RNDIS_ADB,
304                 .num_functions  = ARRAY_SIZE(usb_functions_rndis_adb),
305                 .functions      = usb_functions_rndis_adb,
306         },
307 #endif
308 };
309
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,
321 };
322
323 static struct platform_device androidusb_device = {
324         .name   = "android_usb",
325         .id     = -1,
326         .dev    = {
327                 .platform_data  = &andusb_plat,
328         },
329 };
330
331 static char *factory_usb_functions[] = {
332         "usbnet"
333 };
334
335 static struct android_usb_product factory_usb_products[] = {
336         {
337                 .product_id     = USB_PRODUCT_ID_BLAN,
338                 .num_functions  = ARRAY_SIZE(factory_usb_functions),
339                 .functions      = factory_usb_functions,
340         },
341 };
342
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,
354 };
355
356 static char *bp_usb_functions_bp[] = {
357         "acm", "usbnet"};
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"};
364
365 static struct android_usb_product bp_usb_products[] = {
366         {
367                 .product_id     = USB_PRODUCT_ID_BP,
368                 .num_functions  = ARRAY_SIZE(bp_usb_functions_bp),
369                 .functions      = bp_usb_functions_bp,
370         },
371         {
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,
375         },
376         {
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,
380         },
381         {
382                 .product_id     = USB_PRODUCT_ID_RNDIS_BP_ADB,
383                 .num_functions  = ARRAY_SIZE(bp_usb_functions_all),
384                 .functions      = bp_usb_functions_all,
385         },
386 };
387
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,
398 };
399
400 static struct platform_device usbnet_device = {
401         .name = "usbnet",
402 };
403
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,
409 };
410
411 static struct platform_device rndis_device = {
412         .name   = "rndis",
413         .id     = -1,
414         .dev    = {
415                 .platform_data = &rndis_pdata,
416         },
417 };
418 #endif
419
420 static struct acm_platform_data acm_pdata = {
421         /* Modify num_inst at runtime depending on boot_mode */
422         .num_inst       = 1,
423 };
424
425 static struct platform_device acm_device = {
426         .name   = "acm",
427         .id     = -1,
428         .dev    = {
429                 .platform_data = &acm_pdata,
430         },
431 };
432
433 static struct tegra_utmip_config utmi_phy_config[] = {
434         [0] = {
435                 .hssync_start_delay = 0,
436                 .idle_wait_delay = 17,
437                 .elastic_limit = 16,
438                 .term_range_adj = 6,
439                 .xcvr_setup = 15,
440                 .xcvr_lsfslew = 2,
441                 .xcvr_lsrslew = 2,
442         },
443         [1] = {
444                 .hssync_start_delay = 0,
445                 .idle_wait_delay = 17,
446                 .elastic_limit = 16,
447                 .term_range_adj = 6,
448                 .xcvr_setup = 8,
449                 .xcvr_lsfslew = 2,
450                 .xcvr_lsrslew = 2,
451         },
452 };
453
454 static struct tegra_ulpi_config ulpi_phy_config = {
455         .reset_gpio = TEGRA_GPIO_PG2,
456         .clk = "clk_dev2",
457 };
458
459 static struct tegra_ehci_platform_data tegra_ehci_pdata[] = {
460         [0] = {
461                 .phy_config = &utmi_phy_config[0],
462                 .operating_mode = TEGRA_USB_OTG,
463                 .power_down_on_bus_suspend = 0,
464         },
465         [1] = {
466                 .phy_config = &ulpi_phy_config,
467                 .operating_mode = TEGRA_USB_HOST,
468                 .power_down_on_bus_suspend = 1,
469         },
470         [2] = {
471                 .phy_config = &utmi_phy_config[1],
472                 .operating_mode = TEGRA_USB_HOST,
473                 .power_down_on_bus_suspend = 1,
474         },
475 };
476
477 /* bq24617 charger */
478 static struct resource bq24617_resources[] = {
479         [0] = {
480                 .name  = "stat1",
481                 .flags = IORESOURCE_IRQ,
482                 .start = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PV5),
483                 .end   = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PV5),
484         },
485         [1] = {
486                 .name  = "stat2",
487                 .flags = IORESOURCE_IRQ,
488                 .start = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PD1),
489                 .end   = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PD1),
490         },
491         [2] = {
492                 .name  = "detect",
493                 .flags = IORESOURCE_IRQ,
494                 .start = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PV6),
495                 .end   = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PV6),
496         },
497 };
498
499 static struct resource bq24617_resources_m1_p0[] = {
500         [0] = {
501                 .name  = "stat1",
502                 .flags = IORESOURCE_IRQ,
503                 .start = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PV5),
504                 .end   = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PV5),
505         },
506         [1] = {
507                 .name  = "stat2",
508                 .flags = IORESOURCE_IRQ,
509                 .start = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PV6),
510                 .end   = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PV6),
511         },
512 };
513
514 static struct platform_device bq24617_device = {
515         .name           = "bq24617",
516         .id             = -1,
517         .resource       = bq24617_resources,
518         .num_resources  = ARRAY_SIZE(bq24617_resources),
519 };
520
521 static struct resource tegra_gart_resources[] = {
522     {
523         .name = "mc",
524         .flags = IORESOURCE_MEM,
525         .start = TEGRA_MC_BASE,
526         .end = TEGRA_MC_BASE + TEGRA_MC_SIZE - 1,
527     },
528     {
529         .name = "gart",
530         .flags = IORESOURCE_MEM,
531         .start = 0x58000000,
532         .end = 0x58000000 - 1 + 32 * 1024 * 1024,
533     }
534 };
535
536
537 static struct platform_device tegra_gart_dev = {
538     .name = "tegra_gart",
539     .id = -1,
540     .num_resources = ARRAY_SIZE(tegra_gart_resources),
541     .resource = tegra_gart_resources
542 };
543
544 static struct platform_device bcm4329_bluetooth_device = {
545         .name = "bcm4329_bluetooth",
546         .id = -1,
547 };
548
549 static struct platform_device tegra_camera = {
550         .name = "tegra_camera",
551         .id = -1,
552 };
553
554 static struct tegra_w1_timings tegra_w1_platform_timings = {
555         .tsu = 0x1,
556         .trelease = 0xf,
557         .trdv = 0xf,
558         .tlow0 = 0x3c,
559         .tlow1 = 0x1,
560         .tslot = 0x78,
561
562         .tpdl = 0x3c,
563         .tpdh = 0x1e,
564         .trstl = 0x1ea,
565         .trsth = 0x1df,
566
567         .rdsclk = 0x7,
568         .psclk = 0x50,
569 };
570
571 static struct tegra_w1_platform_data tegra_w1_pdata = {
572         .clk_id = NULL,
573         .timings = &tegra_w1_platform_timings,
574 };
575
576 static struct resource ram_console_resources[] = {
577         {
578                 /* .start and .end filled in later */
579                 .flags  = IORESOURCE_MEM,
580         },
581 };
582
583 static struct platform_device ram_console_device = {
584         .name           = "ram_console",
585         .id             = -1,
586         .num_resources  = ARRAY_SIZE(ram_console_resources),
587         .resource       = ram_console_resources,
588 };
589
590 static struct nvmap_platform_carveout stingray_carveouts[] = {
591         [0] = {
592                 .name           = "iram",
593                 .usage_mask     = NVMAP_HEAP_CARVEOUT_IRAM,
594                 .base           = TEGRA_IRAM_BASE,
595                 .size           = TEGRA_IRAM_SIZE,
596                 .buddy_size     = 0,
597         },
598         [1] = {
599                 .name           = "generic-0",
600                 .usage_mask     = NVMAP_HEAP_CARVEOUT_GENERIC,
601                 /* .base and .size to be filled in later */
602                 .buddy_size     = SZ_32K,
603         },
604 };
605
606 static struct nvmap_platform_data stingray_nvmap_data = {
607         .carveouts      = stingray_carveouts,
608         .nr_carveouts   = ARRAY_SIZE(stingray_carveouts),
609 };
610
611 static struct platform_device stingray_nvmap_device = {
612         .name   = "tegra-nvmap",
613         .id     = -1,
614         .dev    = {
615                 .platform_data = &stingray_nvmap_data,
616         },
617 };
618
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,
622 };
623
624 static struct platform_device *stingray_devices[] __initdata = {
625         &cpcap_otg,
626         &bq24617_device,
627         &bcm4329_bluetooth_device,
628         &tegra_uarta_device,
629         &tegra_uartc_device,
630         &tegra_uartd_device,
631         &tegra_uarte_device,
632         &tegra_spi_device1,
633         &tegra_spi_device2,
634         &tegra_spi_device3,
635         &tegra_spi_device4,
636         &tegra_gart_dev,
637         &stingray_nvmap_device,
638         &tegra_grhost_device,
639         &ram_console_device,
640         &tegra_camera,
641         &tegra_i2s_device1,
642         &tegra_i2s_device2,
643         &mdm6600_modem,
644         &tegra_spdif_device,
645         &tegra_avp_device,
646         &pmu_device,
647         &tegra_aes_device,
648         &tegra_wdt_device,
649 };
650
651 extern struct tegra_sdhci_platform_data stingray_wifi_data; /* sdhci2 */
652
653 static struct tegra_sdhci_platform_data stingray_sdhci_sdcard_platform_data = {
654         .clk_id = NULL,
655         .force_hs = 0,
656         .cd_gpio = TEGRA_GPIO_PI5,
657         .wp_gpio = -1,
658         .power_gpio = -1,
659 };
660
661 static struct tegra_sdhci_platform_data stingray_sdhci_platform_data4 = {
662         .clk_id = NULL,
663         .force_hs = 0,
664         .cd_gpio = -1,
665         .wp_gpio = -1,
666         .power_gpio = -1,
667 };
668
669 static struct tegra_i2c_platform_data stingray_i2c1_platform_data = {
670         .adapter_nr   = 0,
671         .bus_count    = 1,
672         .bus_clk_rate = { 400000 },
673 };
674
675 static struct tegra_i2c_platform_data stingray_i2c2_platform_data = {
676         .adapter_nr   = 1,
677         .bus_count    = 1,
678 };
679
680 static struct tegra_i2c_platform_data stingray_i2c3_platform_data = {
681         .adapter_nr   = 2,
682         .bus_count    = 1,
683         .bus_clk_rate = { 400000 },
684 };
685
686 static struct tegra_i2c_platform_data stingray_i2c4_platform_data = {
687         .adapter_nr   = 3,
688         .bus_count    = 1,
689         .bus_clk_rate = { 400000 },
690         .is_dvc       = true,
691 };
692
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},
707         { NULL,         NULL,           0,              0},
708 };
709
710 static void stingray_i2c_init(void)
711 {
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;
716
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);
721 }
722
723 static void stingray_sdhci_init(void)
724 {
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;
729
730         platform_device_register(&tegra_sdhci_device2);
731         platform_device_register(&tegra_sdhci_device3);
732         platform_device_register(&tegra_sdhci_device4);
733 }
734 #define ATAG_BDADDR 0x43294329  /* stingray bluetooth address tag */
735 #define ATAG_BDADDR_SIZE 4
736 #define BDADDR_STR_SIZE 18
737
738 static char bdaddr[BDADDR_STR_SIZE];
739
740 module_param_string(bdaddr, bdaddr, sizeof(bdaddr), 0400);
741 MODULE_PARM_DESC(bdaddr, "bluetooth address");
742
743 static int __init parse_tag_bdaddr(const struct tag *tag)
744 {
745         unsigned char *b = (unsigned char *)&tag->u;
746
747         if (tag->hdr.size != ATAG_BDADDR_SIZE)
748                 return -EINVAL;
749
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]);
752
753         return 0;
754 }
755 __tagtable(ATAG_BDADDR, parse_tag_bdaddr);
756
757 static DEFINE_SPINLOCK(brcm_4329_enable_lock);
758 static int brcm_4329_enable_count;
759
760 static void stingray_w1_init(void)
761 {
762         tegra_w1_device.dev.platform_data = &tegra_w1_pdata;
763         platform_device_register(&tegra_w1_device);
764 }
765
766 /* powerup reason */
767 #define ATAG_POWERUP_REASON              0xf1000401
768 #define ATAG_POWERUP_REASON_SIZE 3 /* size + tag id + tag data */
769
770 static unsigned int powerup_reason = PU_REASON_PWR_KEY_PRESS;
771
772 unsigned int stingray_powerup_reason (void)
773 {
774         return powerup_reason;
775 }
776
777 static int __init parse_tag_powerup_reason(const struct tag *tag)
778 {
779         if (tag->hdr.size != ATAG_POWERUP_REASON_SIZE)
780                 return -EINVAL;
781         memcpy(&powerup_reason, &tag->u, sizeof(powerup_reason));
782         printk(KERN_INFO "powerup reason=0x%08x\n", powerup_reason);
783         return 0;
784 }
785 __tagtable(ATAG_POWERUP_REASON, parse_tag_powerup_reason);
786
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)
790 {
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);
794         return 1;
795 }
796 __setup("androidboot.mode=", board_boot_mode_init);
797
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)
801 {
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);
805         return 1;
806 }
807 __setup("androidboot.serialno=", mot_usb_serial_num_setup);
808
809 static int mot_boot_recovery = 0;
810 static int __init mot_bm_recovery_setup(char *options)
811 {
812        mot_boot_recovery = 1;
813        return 1;
814 }
815 __setup("rec", mot_bm_recovery_setup);
816
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)
820 {
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);
824
825         return 1;
826 }
827 __setup("product_type=", stingray_product_type_parse);
828
829 bool stingray_hw_has_cdma(void)
830 {
831         return strstr(product_type, "c") != NULL;
832 }
833
834 bool stingray_hw_has_lte(void)
835 {
836         return strstr(product_type, "l") != NULL;
837 }
838
839 bool stingray_hw_has_wifi(void)
840 {
841         return strstr(product_type, "w") != NULL;
842 }
843
844 bool stingray_hw_has_umts(void)
845 {
846         return strstr(product_type, "u") != NULL;
847 }
848
849 static void stingray_usb_init(void)
850 {
851         char *src;
852         int i;
853
854         struct android_usb_platform_data *platform_data;
855
856         int factorycable = !strncmp(boot_mode, "factorycable",
857                         BOOT_MODE_MAX_LEN);
858
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];
862
863         if (!(factorycable && mot_boot_recovery))
864                 platform_device_register(&tegra_udc_device);
865
866         if (stingray_hw_has_cdma())
867                 platform_device_register(&tegra_ehci2_device);
868
869         platform_device_register(&tegra_ehci3_device);
870
871 #ifdef CONFIG_USB_ANDROID_RNDIS
872         src = usb_serial_num;
873
874         /* create a fake MAC address from our serial number.
875          * first byte is 0x02 to signify locally administered.
876          */
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++;
881         }
882         platform_device_register(&rndis_device);
883 #endif
884
885         if (!(factorycable && mot_boot_recovery)) {
886                 if (factorycable) {
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);
896                 } else {
897                         platform_data = &andusb_plat;
898                 }
899
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;
904                 else
905                         platform_data->product_name = USB_PRODUCT_NAME_WIFI_ONLY;
906
907                 platform_data->serial_number = usb_serial_num;
908                 androidusb_device.dev.platform_data = platform_data;
909                 platform_device_register(&androidusb_device);
910         }
911 }
912
913 static void stingray_reset(char mode, const char *cmd)
914 {
915         /* Signal to CPCAP to stop the uC. */
916         gpio_set_value(TEGRA_GPIO_PG3, 0);
917         mdelay(100);
918         gpio_set_value(TEGRA_GPIO_PG3, 1);
919         mdelay(100);
920
921         tegra_assert_system_reset();
922 }
923
924 static void stingray_power_off(void)
925 {
926         printk(KERN_INFO "stingray_pm_power_off...\n");
927
928         local_irq_disable();
929
930         /* signal WDI gpio to shutdown CPCAP, which will
931            cascade to all of the regulators. */
932         gpio_direction_output(TEGRA_GPIO_PV7, 0);
933
934         do {} while (1);
935
936         local_irq_enable();
937 }
938
939 static void __init stingray_power_off_init(void)
940 {
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;
945
946         tegra_gpio_enable(TEGRA_GPIO_PV7);
947         if (!gpio_request(TEGRA_GPIO_PV7, "wdi"))
948                 pm_power_off = stingray_power_off;
949 }
950
951 static unsigned int stingray_board_revision = STINGRAY_REVISION_UNKNOWN;
952
953 unsigned int stingray_revision(void)
954 {
955         return stingray_board_revision;
956 }
957
958 static int __init stingray_revision_parse(char *options)
959 {
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;
970         else
971                 stingray_board_revision = system_rev;
972
973         printk(KERN_INFO "hw_rev=0x%x\n", stingray_board_revision);
974
975         return 1;
976 }
977 __setup("hw_rev=", stingray_revision_parse);
978
979 int stingray_qbp_usb_hw_bypass_enabled(void)
980 {
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
983          * in the future.
984          */
985         if (gpio_get_value(TEGRA_GPIO_PT3) && !gpio_get_value(TEGRA_GPIO_PV4)) {
986                 pr_info("stingray_qbp_usb_hw_bypass enabled\n");
987                 return 1;
988         }
989         return 0;
990 }
991
992 static struct tegra_suspend_platform_data stingray_suspend = {
993         .cpu_timer = 1500,
994         .cpu_off_timer = 1,
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,
1001 };
1002
1003 static void *das_base = IO_ADDRESS(TEGRA_APB_MISC_BASE);
1004
1005 static inline void das_writel(unsigned long value, unsigned long offset)
1006 {
1007         writel(value, das_base + offset);
1008 }
1009
1010 #define APB_MISC_DAS_DAP_CTRL_SEL_0             0xc00
1011 #define APB_MISC_DAS_DAC_INPUT_DATA_CLK_SEL_0   0xc40
1012
1013 static void init_dac1(void)
1014 {
1015         bool master = tegra_audio_pdata.i2s_master;
1016         /* DAC1 -> DAP1 */
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);
1019 }
1020
1021 static void init_dac2(bool bluetooth)
1022 {
1023         if (!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);
1029         } else {
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);
1035         }
1036 }
1037
1038 void change_power_brcm_4329(bool enable) {
1039         unsigned long flags;
1040
1041         spin_lock_irqsave(&brcm_4329_enable_lock, flags);
1042         if (enable) {
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;
1049         } else {
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);
1054         }
1055         spin_unlock_irqrestore(&brcm_4329_enable_lock, flags);
1056 }
1057
1058 static void __init tegra_stingray_init(void)
1059 {
1060         struct clk *clk;
1061         struct resource *res;
1062
1063         /* force consoles to stay enabled across suspend/resume */
1064         console_suspend_enabled = 0;
1065
1066         tegra_common_init();
1067         tegra_init_suspend(&stingray_suspend);
1068         stingray_init_emc();
1069
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);
1073         if (!IS_ERR(clk)) {
1074                 tegra_sdmmc_tap_delay(clk, 6);
1075                 clk_put(clk);
1076         } else {
1077                 pr_err("Failed to set wifi sdmmc tap delay\n");
1078         }
1079
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.
1083          */
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);
1088         }
1089
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);
1096
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);
1101
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);
1110
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);
1115
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);
1120         } else {
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);
1125
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);
1130
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);
1136                 } else {
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);
1141                 }
1142         }
1143
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
1152                    as a GPIO. */
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);
1158         }
1159
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");
1163         }
1164
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);
1173
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);
1178
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);
1183
1184         stingray_pinmux_init();
1185
1186         tegra_clk_init_from_table(stingray_clk_init_table);
1187
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);
1191
1192         init_dac1();
1193         init_dac2(false);
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;
1198
1199         tegra_ehci1_device.dev.platform_data = &tegra_ehci_pdata[0];
1200         tegra_uartc_device.dev.platform_data = &tegra_uartc_pdata;
1201
1202         res = platform_get_resource(&ram_console_device, IORESOURCE_MEM, 0);
1203         res->start = ramconsole_start;
1204         res->end = ramconsole_start + ramconsole_size - 1;
1205
1206         stingray_carveouts[1].base = tegra_carveout_start;
1207         stingray_carveouts[1].size = tegra_carveout_size;
1208
1209         platform_add_devices(stingray_devices, ARRAY_SIZE(stingray_devices));
1210
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();
1218         stingray_w1_init();
1219         stingray_sensors_init();
1220         stingray_wlan_init();
1221         stingray_gps_init();
1222         stingray_usb_init();
1223 }
1224
1225 int __init stingray_protected_aperture_init(void)
1226 {
1227         tegra_protected_aperture_init(tegra_grhost_aperture);
1228         memblock_free(tegra_bootloader_fb_start, tegra_bootloader_fb_size);
1229         return 0;
1230 }
1231 late_initcall(stingray_protected_aperture_init);
1232
1233 void __init stingray_map_io(void)
1234 {
1235         tegra_map_common_io();
1236 }
1237
1238 static int __init stingray_ramconsole_arg(char *options)
1239 {
1240         char *p = options;
1241
1242         ramconsole_size = memparse(p, &p);
1243         if (*p == '@')
1244                 ramconsole_start = memparse(p+1, &p);
1245
1246         return 0;
1247 }
1248 early_param("ramconsole", stingray_ramconsole_arg);
1249
1250 void __init stingray_reserve(void)
1251 {
1252         long ret;
1253         if (memblock_reserve(0x0, 4096) < 0)
1254                 pr_warn("Cannot reserve first 4K of memory for safety\n");
1255
1256         ret = memblock_remove(SZ_512M - SZ_2M, SZ_2M);
1257         if (ret)
1258                 pr_info("Failed to remove ram console\n");
1259         else
1260                 pr_info("Reserved %08lx@%08lx for ram console\n",
1261                         ramconsole_start, ramconsole_size);
1262
1263         tegra_reserve(SZ_256M, SZ_8M, SZ_16M);
1264
1265         if (memblock_reserve(tegra_bootloader_fb_start, tegra_bootloader_fb_size))
1266                 pr_info("Failed to reserve old framebuffer location\n");
1267         else
1268                 pr_info("HACK: Old framebuffer:  %08lx - %08lx\n",
1269                         tegra_bootloader_fb_start,
1270                         tegra_bootloader_fb_start + tegra_bootloader_fb_size - 1);
1271 }
1272
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,
1282 MACHINE_END