Merge tag 'sound-fix-5.1-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai...
[sfrench/cifs-2.6.git] / arch / arm / mach-pxa / stargate2.c
1 /*
2  *  linux/arch/arm/mach-pxa/stargate2.c
3  *
4  *  Author:     Ed C. Epp
5  *  Created:    Nov 05, 2002
6  *  Copyright:  Intel Corp.
7  *
8  *  Modified 2009:  Jonathan Cameron <jic23@cam.ac.uk>
9  *
10  *  This program is free software; you can redistribute it and/or modify
11  *  it under the terms of the GNU General Public License version 2 as
12  *  published by the Free Software Foundation.
13  */
14
15 #include <linux/init.h>
16 #include <linux/device.h>
17 #include <linux/interrupt.h>
18 #include <linux/sched.h>
19 #include <linux/bitops.h>
20 #include <linux/fb.h>
21 #include <linux/delay.h>
22 #include <linux/platform_device.h>
23 #include <linux/regulator/machine.h>
24 #include <linux/mtd/mtd.h>
25 #include <linux/mtd/plat-ram.h>
26 #include <linux/mtd/partitions.h>
27
28 #include <linux/platform_data/i2c-pxa.h>
29 #include <linux/platform_data/pcf857x.h>
30 #include <linux/smc91x.h>
31 #include <linux/gpio/machine.h>
32 #include <linux/gpio.h>
33 #include <linux/leds.h>
34 #include <linux/property.h>
35
36 #include <asm/types.h>
37 #include <asm/setup.h>
38 #include <asm/memory.h>
39 #include <asm/mach-types.h>
40 #include <asm/irq.h>
41
42 #include <asm/mach/arch.h>
43 #include <asm/mach/map.h>
44 #include <asm/mach/irq.h>
45 #include <asm/mach/flash.h>
46
47 #include "pxa27x.h"
48 #include <linux/platform_data/mmc-pxamci.h>
49 #include "udc.h"
50 #include "pxa27x-udc.h"
51 #include <mach/smemc.h>
52
53 #include <linux/spi/spi.h>
54 #include <linux/spi/pxa2xx_spi.h>
55 #include <linux/mfd/da903x.h>
56
57 #include "devices.h"
58 #include "generic.h"
59
60 #define STARGATE_NR_IRQS        (IRQ_BOARD_START + 8)
61
62 /* Bluetooth */
63 #define SG2_BT_RESET            81
64
65 /* SD */
66 #define SG2_GPIO_nSD_DETECT     90
67 #define SG2_SD_POWER_ENABLE     89
68
69 static unsigned long sg2_im2_unified_pin_config[] __initdata = {
70         /* Device Identification for wakeup*/
71         GPIO102_GPIO,
72         /* DA9030 */
73         GPIO1_GPIO,
74
75         /* MMC */
76         GPIO32_MMC_CLK,
77         GPIO112_MMC_CMD,
78         GPIO92_MMC_DAT_0,
79         GPIO109_MMC_DAT_1,
80         GPIO110_MMC_DAT_2,
81         GPIO111_MMC_DAT_3,
82
83         /* 802.15.4 radio - driver out of mainline */
84         GPIO22_GPIO,                    /* CC_RSTN */
85         GPIO114_GPIO,                   /* CC_FIFO */
86         GPIO116_GPIO,                   /* CC_CCA */
87         GPIO0_GPIO,                     /* CC_FIFOP */
88         GPIO16_GPIO,                    /* CCSFD */
89         GPIO115_GPIO,                   /* Power enable */
90
91         /* I2C */
92         GPIO117_I2C_SCL,
93         GPIO118_I2C_SDA,
94
95         /* SSP 3 - 802.15.4 radio */
96         GPIO39_GPIO,                    /* Chip Select */
97         GPIO34_SSP3_SCLK,
98         GPIO35_SSP3_TXD,
99         GPIO41_SSP3_RXD,
100
101         /* SSP 2 to daughter boards */
102         GPIO11_SSP2_RXD,
103         GPIO38_SSP2_TXD,
104         GPIO36_SSP2_SCLK,
105         GPIO37_GPIO, /* chip select */
106
107         /* SSP 1 - to daughter boards */
108         GPIO24_GPIO,                    /* Chip Select */
109         GPIO23_SSP1_SCLK,
110         GPIO25_SSP1_TXD,
111         GPIO26_SSP1_RXD,
112
113         /* BTUART Basic Connector*/
114         GPIO42_BTUART_RXD,
115         GPIO43_BTUART_TXD,
116         GPIO44_BTUART_CTS,
117         GPIO45_BTUART_RTS,
118
119         /* STUART  - IM2 via debug board not sure on SG2*/
120         GPIO46_STUART_RXD,
121         GPIO47_STUART_TXD,
122
123         /* Basic sensor board */
124         GPIO96_GPIO,    /* accelerometer interrupt */
125         GPIO99_GPIO,    /* ADC interrupt */
126
127         /* SHT15 */
128         GPIO100_GPIO,
129         GPIO98_GPIO,
130
131         /* Basic sensor board */
132         GPIO96_GPIO,    /* accelerometer interrupt */
133         GPIO99_GPIO,    /* ADC interrupt */
134
135         /* Connector pins specified as gpios */
136         GPIO94_GPIO, /* large basic connector pin 14 */
137         GPIO10_GPIO, /* large basic connector pin 23 */
138 };
139
140 static struct gpiod_lookup_table sht15_gpiod_table = {
141         .dev_id = "sht15",
142         .table = {
143                 /* FIXME: should this have |GPIO_OPEN_DRAIN set? */
144                 GPIO_LOOKUP("gpio-pxa", 100, "data", GPIO_ACTIVE_HIGH),
145                 GPIO_LOOKUP("gpio-pxa", 98, "clk", GPIO_ACTIVE_HIGH),
146         },
147 };
148
149 static struct platform_device sht15 = {
150         .name = "sht15",
151         .id = -1,
152 };
153
154 static struct regulator_consumer_supply stargate2_sensor_3_con[] = {
155         REGULATOR_SUPPLY("vcc", "sht15"),
156 };
157
158 enum stargate2_ldos{
159         vcc_vref,
160         vcc_cc2420,
161         /* a mote connector? */
162         vcc_mica,
163         /* the CSR bluecore chip */
164         vcc_bt,
165         /* The two voltages available to sensor boards */
166         vcc_sensor_1_8,
167         vcc_sensor_3,
168         /* directly connected to the pxa27x */
169         vcc_sram_ext,
170         vcc_pxa_pll,
171         vcc_pxa_usim, /* Reference voltage for certain gpios */
172         vcc_pxa_mem,
173         vcc_pxa_flash,
174         vcc_pxa_core, /*Dc-Dc buck not yet supported */
175         vcc_lcd,
176         vcc_bb,
177         vcc_bbio, /*not sure!*/
178         vcc_io, /* cc2420 802.15.4 radio and pxa vcc_io ?*/
179 };
180
181 /* The values of the various regulator constraints are obviously dependent
182  * on exactly what is wired to each ldo.  Unfortunately this information is
183  * not generally available.  More information has been requested from Xbow.
184  */
185 static struct regulator_init_data stargate2_ldo_init_data[] = {
186         [vcc_bbio] = {
187                 .constraints = { /* board default 1.8V */
188                         .name = "vcc_bbio",
189                         .min_uV = 1800000,
190                         .max_uV = 1800000,
191                 },
192         },
193         [vcc_bb] = {
194                 .constraints = { /* board default 2.8V */
195                         .name = "vcc_bb",
196                         .min_uV = 2700000,
197                         .max_uV = 3000000,
198                 },
199         },
200         [vcc_pxa_flash] = {
201                 .constraints = {/* default is 1.8V */
202                         .name = "vcc_pxa_flash",
203                         .min_uV = 1800000,
204                         .max_uV = 1800000,
205                 },
206         },
207         [vcc_cc2420] = { /* also vcc_io */
208                 .constraints = {
209                         /* board default is 2.8V */
210                         .name = "vcc_cc2420",
211                         .min_uV = 2700000,
212                         .max_uV = 3300000,
213                 },
214         },
215         [vcc_vref] = { /* Reference for what? */
216                 .constraints = { /* default 1.8V */
217                         .name = "vcc_vref",
218                         .min_uV = 1800000,
219                         .max_uV = 1800000,
220                 },
221         },
222         [vcc_sram_ext] = {
223                 .constraints = { /* default 2.8V */
224                         .name = "vcc_sram_ext",
225                         .min_uV = 2800000,
226                         .max_uV = 2800000,
227                 },
228         },
229         [vcc_mica] = {
230                 .constraints = { /* default 2.8V */
231                         .name = "vcc_mica",
232                         .min_uV = 2800000,
233                         .max_uV = 2800000,
234                 },
235         },
236         [vcc_bt] = {
237                 .constraints = { /* default 2.8V */
238                         .name = "vcc_bt",
239                         .min_uV = 2800000,
240                         .max_uV = 2800000,
241                 },
242         },
243         [vcc_lcd] = {
244                 .constraints = { /* default 2.8V */
245                         .name = "vcc_lcd",
246                         .min_uV = 2700000,
247                         .max_uV = 3300000,
248                 },
249         },
250         [vcc_io] = { /* Same or higher than everything
251                           * bar vccbat and vccusb */
252                 .constraints = { /* default 2.8V */
253                         .name = "vcc_io",
254                         .min_uV = 2692000,
255                         .max_uV = 3300000,
256                 },
257         },
258         [vcc_sensor_1_8] = {
259                 .constraints = { /* default 1.8V */
260                         .name = "vcc_sensor_1_8",
261                         .min_uV = 1800000,
262                         .max_uV = 1800000,
263                 },
264         },
265         [vcc_sensor_3] = { /* curiously default 2.8V */
266                 .constraints = {
267                         .name = "vcc_sensor_3",
268                         .min_uV = 2800000,
269                         .max_uV = 3000000,
270                 },
271                 .num_consumer_supplies = ARRAY_SIZE(stargate2_sensor_3_con),
272                 .consumer_supplies = stargate2_sensor_3_con,
273         },
274         [vcc_pxa_pll] = { /* 1.17V - 1.43V, default 1.3V*/
275                 .constraints = {
276                         .name = "vcc_pxa_pll",
277                         .min_uV = 1170000,
278                         .max_uV = 1430000,
279                 },
280         },
281         [vcc_pxa_usim] = {
282                 .constraints = { /* default 1.8V */
283                         .name = "vcc_pxa_usim",
284                         .min_uV = 1710000,
285                         .max_uV = 2160000,
286                 },
287         },
288         [vcc_pxa_mem] = {
289                 .constraints = { /* default 1.8V */
290                         .name = "vcc_pxa_mem",
291                         .min_uV = 1800000,
292                         .max_uV = 1800000,
293                 },
294         },
295 };
296
297 static struct mtd_partition stargate2flash_partitions[] = {
298         {
299                 .name = "Bootloader",
300                 .size = 0x00040000,
301                 .offset = 0,
302                 .mask_flags = 0,
303         }, {
304                 .name = "Kernel",
305                 .size = 0x00200000,
306                 .offset = 0x00040000,
307                 .mask_flags = 0
308         }, {
309                 .name = "Filesystem",
310                 .size = 0x01DC0000,
311                 .offset = 0x00240000,
312                 .mask_flags = 0
313         },
314 };
315
316 static struct resource flash_resources = {
317         .start = PXA_CS0_PHYS,
318         .end = PXA_CS0_PHYS + SZ_32M - 1,
319         .flags = IORESOURCE_MEM,
320 };
321
322 static struct flash_platform_data stargate2_flash_data = {
323         .map_name = "cfi_probe",
324         .parts = stargate2flash_partitions,
325         .nr_parts = ARRAY_SIZE(stargate2flash_partitions),
326         .name = "PXA27xOnChipROM",
327         .width = 2,
328 };
329
330 static struct platform_device stargate2_flash_device = {
331         .name = "pxa2xx-flash",
332         .id = 0,
333         .dev = {
334                 .platform_data = &stargate2_flash_data,
335         },
336         .resource = &flash_resources,
337         .num_resources = 1,
338 };
339
340 static struct pxa2xx_spi_controller pxa_ssp_master_0_info = {
341         .num_chipselect = 1,
342 };
343
344 static struct pxa2xx_spi_controller pxa_ssp_master_1_info = {
345         .num_chipselect = 1,
346 };
347
348 static struct pxa2xx_spi_controller pxa_ssp_master_2_info = {
349         .num_chipselect = 1,
350 };
351
352 /* An upcoming kernel change will scrap SFRM usage so these
353  * drivers have been moved to use gpio's via cs_control */
354 static struct pxa2xx_spi_chip staccel_chip_info = {
355         .tx_threshold = 8,
356         .rx_threshold = 8,
357         .dma_burst_size = 8,
358         .timeout = 235,
359         .gpio_cs = 24,
360 };
361
362 static struct pxa2xx_spi_chip cc2420_info = {
363         .tx_threshold = 8,
364         .rx_threshold = 8,
365         .dma_burst_size = 8,
366         .timeout = 235,
367         .gpio_cs = 39,
368 };
369
370 static struct spi_board_info spi_board_info[] __initdata = {
371         {
372                 .modalias = "lis3l02dq",
373                 .max_speed_hz = 8000000,/* 8MHz max spi frequency at 3V */
374                 .bus_num = 1,
375                 .chip_select = 0,
376                 .controller_data = &staccel_chip_info,
377                 .irq = PXA_GPIO_TO_IRQ(96),
378         }, {
379                 .modalias = "cc2420",
380                 .max_speed_hz = 6500000,
381                 .bus_num = 3,
382                 .chip_select = 0,
383                 .controller_data = &cc2420_info,
384         },
385 };
386
387 static void sg2_udc_command(int cmd)
388 {
389         switch (cmd) {
390         case PXA2XX_UDC_CMD_CONNECT:
391                 UP2OCR |=  UP2OCR_HXOE  | UP2OCR_DPPUE | UP2OCR_DPPUBE;
392                 break;
393         case PXA2XX_UDC_CMD_DISCONNECT:
394                 UP2OCR &= ~(UP2OCR_HXOE  | UP2OCR_DPPUE | UP2OCR_DPPUBE);
395                 break;
396         }
397 }
398
399 static struct i2c_pxa_platform_data i2c_pwr_pdata = {
400         .fast_mode = 1,
401 };
402
403 static struct i2c_pxa_platform_data i2c_pdata = {
404         .fast_mode = 1,
405 };
406
407 static void __init imote2_stargate2_init(void)
408 {
409
410         pxa2xx_mfp_config(ARRAY_AND_SIZE(sg2_im2_unified_pin_config));
411
412         pxa_set_ffuart_info(NULL);
413         pxa_set_btuart_info(NULL);
414         pxa_set_stuart_info(NULL);
415
416         pxa2xx_set_spi_info(1, &pxa_ssp_master_0_info);
417         pxa2xx_set_spi_info(2, &pxa_ssp_master_1_info);
418         pxa2xx_set_spi_info(3, &pxa_ssp_master_2_info);
419         spi_register_board_info(spi_board_info, ARRAY_SIZE(spi_board_info));
420
421
422         pxa27x_set_i2c_power_info(&i2c_pwr_pdata);
423         pxa_set_i2c_info(&i2c_pdata);
424 }
425
426 #ifdef CONFIG_MACH_INTELMOTE2
427 /* As the the imote2 doesn't currently have a conventional SD slot
428  * there is no option to hotplug cards, making all this rather simple
429  */
430 static int imote2_mci_get_ro(struct device *dev)
431 {
432         return 0;
433 }
434
435 /* Rather simple case as hotplugging not possible */
436 static struct pxamci_platform_data imote2_mci_platform_data = {
437         .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34, /* default anyway */
438         .get_ro = imote2_mci_get_ro,
439 };
440
441 static struct gpio_led imote2_led_pins[] = {
442         {
443                 .name       =  "imote2:red",
444                 .gpio       = 103,
445                 .active_low = 1,
446         }, {
447                 .name       = "imote2:green",
448                 .gpio       = 104,
449                 .active_low = 1,
450         }, {
451                 .name       = "imote2:blue",
452                 .gpio       = 105,
453                 .active_low = 1,
454         },
455 };
456
457 static struct gpio_led_platform_data imote2_led_data = {
458         .num_leds = ARRAY_SIZE(imote2_led_pins),
459         .leds     = imote2_led_pins,
460 };
461
462 static struct platform_device imote2_leds = {
463         .name = "leds-gpio",
464         .id   = -1,
465         .dev = {
466                 .platform_data = &imote2_led_data,
467         },
468 };
469
470 static struct da903x_subdev_info imote2_da9030_subdevs[] = {
471         {
472                 .name = "da903x-regulator",
473                 .id = DA9030_ID_LDO2,
474                 .platform_data = &stargate2_ldo_init_data[vcc_bbio],
475         }, {
476                 .name = "da903x-regulator",
477                 .id = DA9030_ID_LDO3,
478                 .platform_data = &stargate2_ldo_init_data[vcc_bb],
479         }, {
480                 .name = "da903x-regulator",
481                 .id = DA9030_ID_LDO4,
482                 .platform_data = &stargate2_ldo_init_data[vcc_pxa_flash],
483         }, {
484                 .name = "da903x-regulator",
485                 .id = DA9030_ID_LDO5,
486                 .platform_data = &stargate2_ldo_init_data[vcc_cc2420],
487         }, {
488                 .name = "da903x-regulator",
489                 .id = DA9030_ID_LDO6,
490                 .platform_data = &stargate2_ldo_init_data[vcc_vref],
491         }, {
492                 .name = "da903x-regulator",
493                 .id = DA9030_ID_LDO7,
494                 .platform_data = &stargate2_ldo_init_data[vcc_sram_ext],
495         }, {
496                 .name = "da903x-regulator",
497                 .id = DA9030_ID_LDO8,
498                 .platform_data = &stargate2_ldo_init_data[vcc_mica],
499         }, {
500                 .name = "da903x-regulator",
501                 .id = DA9030_ID_LDO9,
502                 .platform_data = &stargate2_ldo_init_data[vcc_bt],
503         }, {
504                 .name = "da903x-regulator",
505                 .id = DA9030_ID_LDO10,
506                 .platform_data = &stargate2_ldo_init_data[vcc_sensor_1_8],
507         }, {
508                 .name = "da903x-regulator",
509                 .id = DA9030_ID_LDO11,
510                 .platform_data = &stargate2_ldo_init_data[vcc_sensor_3],
511         }, {
512                 .name = "da903x-regulator",
513                 .id = DA9030_ID_LDO12,
514                 .platform_data = &stargate2_ldo_init_data[vcc_lcd],
515         }, {
516                 .name = "da903x-regulator",
517                 .id = DA9030_ID_LDO15,
518                 .platform_data = &stargate2_ldo_init_data[vcc_pxa_pll],
519         }, {
520                 .name = "da903x-regulator",
521                 .id = DA9030_ID_LDO17,
522                 .platform_data = &stargate2_ldo_init_data[vcc_pxa_usim],
523         }, {
524                 .name = "da903x-regulator", /*pxa vcc i/o and cc2420 vcc i/o */
525                 .id = DA9030_ID_LDO18,
526                 .platform_data = &stargate2_ldo_init_data[vcc_io],
527         }, {
528                 .name = "da903x-regulator",
529                 .id = DA9030_ID_LDO19,
530                 .platform_data = &stargate2_ldo_init_data[vcc_pxa_mem],
531         },
532 };
533
534 static struct da903x_platform_data imote2_da9030_pdata = {
535         .num_subdevs = ARRAY_SIZE(imote2_da9030_subdevs),
536         .subdevs = imote2_da9030_subdevs,
537 };
538
539 static struct i2c_board_info __initdata imote2_pwr_i2c_board_info[] = {
540         {
541                 .type = "da9030",
542                 .addr = 0x49,
543                 .platform_data = &imote2_da9030_pdata,
544                 .irq = PXA_GPIO_TO_IRQ(1),
545         },
546 };
547
548 static struct i2c_board_info __initdata imote2_i2c_board_info[] = {
549         { /* UCAM sensor board */
550                 .type = "max1239",
551                 .addr = 0x35,
552         }, { /* ITS400 Sensor board only */
553                 .type = "max1363",
554                 .addr = 0x34,
555                 /* Through a nand gate - Also beware, on V2 sensor board the
556                  * pull up resistors are missing.
557                  */
558                 .irq = PXA_GPIO_TO_IRQ(99),
559         }, { /* ITS400 Sensor board only */
560                 .type = "tsl2561",
561                 .addr = 0x49,
562                 /* Through a nand gate - Also beware, on V2 sensor board the
563                  * pull up resistors are missing.
564                  */
565                 .irq = PXA_GPIO_TO_IRQ(99),
566         }, { /* ITS400 Sensor board only */
567                 .type = "tmp175",
568                 .addr = 0x4A,
569                 .irq = PXA_GPIO_TO_IRQ(96),
570         }, { /* IMB400 Multimedia board */
571                 .type = "wm8940",
572                 .addr = 0x1A,
573         },
574 };
575
576 static unsigned long imote2_pin_config[] __initdata = {
577
578         /* Button */
579         GPIO91_GPIO,
580
581         /* LEDS */
582         GPIO103_GPIO, /* red led */
583         GPIO104_GPIO, /* green led */
584         GPIO105_GPIO, /* blue led */
585 };
586
587 static struct pxa2xx_udc_mach_info imote2_udc_info __initdata = {
588         .udc_command            = sg2_udc_command,
589 };
590
591 static struct platform_device imote2_audio_device = {
592         .name = "imote2-audio",
593         .id   = -1,
594 };
595
596 static struct platform_device *imote2_devices[] = {
597         &stargate2_flash_device,
598         &imote2_leds,
599         &sht15,
600         &imote2_audio_device,
601 };
602
603 static void __init imote2_init(void)
604 {
605         pxa2xx_mfp_config(ARRAY_AND_SIZE(imote2_pin_config));
606
607         imote2_stargate2_init();
608
609         gpiod_add_lookup_table(&sht15_gpiod_table);
610         platform_add_devices(imote2_devices, ARRAY_SIZE(imote2_devices));
611
612         i2c_register_board_info(0, imote2_i2c_board_info,
613                                 ARRAY_SIZE(imote2_i2c_board_info));
614         i2c_register_board_info(1, imote2_pwr_i2c_board_info,
615                                 ARRAY_SIZE(imote2_pwr_i2c_board_info));
616
617         pxa_set_mci_info(&imote2_mci_platform_data);
618         pxa_set_udc_info(&imote2_udc_info);
619 }
620 #endif
621
622 #ifdef CONFIG_MACH_STARGATE2
623
624 static unsigned long stargate2_pin_config[] __initdata = {
625
626         GPIO15_nCS_1, /* SRAM */
627         /* SMC91x */
628         GPIO80_nCS_4,
629         GPIO40_GPIO, /*cable detect?*/
630
631         /* Button */
632         GPIO91_GPIO | WAKEUP_ON_LEVEL_HIGH,
633
634         /* Compact Flash */
635         GPIO79_PSKTSEL,
636         GPIO48_nPOE,
637         GPIO49_nPWE,
638         GPIO50_nPIOR,
639         GPIO51_nPIOW,
640         GPIO85_nPCE_1,
641         GPIO54_nPCE_2,
642         GPIO55_nPREG,
643         GPIO56_nPWAIT,
644         GPIO57_nIOIS16,
645         GPIO120_GPIO, /* Buff ctrl */
646         GPIO108_GPIO, /* Power ctrl */
647         GPIO82_GPIO, /* Reset */
648         GPIO53_GPIO, /* SG2_S0_GPIO_DETECT */
649
650         /* MMC not shared with imote2 */
651         GPIO90_GPIO, /* nSD detect */
652         GPIO89_GPIO, /* SD_POWER_ENABLE */
653
654         /* Bluetooth */
655         GPIO81_GPIO, /* reset */
656 };
657
658 static struct resource smc91x_resources[] = {
659         [0] = {
660                 .name = "smc91x-regs",
661                 .start = (PXA_CS4_PHYS + 0x300),
662                 .end = (PXA_CS4_PHYS + 0xfffff),
663                 .flags = IORESOURCE_MEM,
664         },
665         [1] = {
666                 .start = PXA_GPIO_TO_IRQ(40),
667                 .end = PXA_GPIO_TO_IRQ(40),
668                 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
669         }
670 };
671
672 static struct smc91x_platdata stargate2_smc91x_info = {
673         .flags = SMC91X_USE_8BIT | SMC91X_USE_16BIT | SMC91X_USE_32BIT
674         | SMC91X_NOWAIT | SMC91X_USE_DMA,
675         .pxa_u16_align4 = true,
676 };
677
678 static struct platform_device smc91x_device = {
679         .name = "smc91x",
680         .id = -1,
681         .num_resources = ARRAY_SIZE(smc91x_resources),
682         .resource = smc91x_resources,
683         .dev = {
684                 .platform_data = &stargate2_smc91x_info,
685         },
686 };
687
688
689 /*
690  * The card detect interrupt isn't debounced so we delay it by 250ms
691  * to give the card a chance to fully insert / eject.
692  */
693 static int stargate2_mci_init(struct device *dev,
694                               irq_handler_t stargate2_detect_int,
695                               void *data)
696 {
697         int err;
698
699         err = gpio_request(SG2_SD_POWER_ENABLE, "SG2_sd_power_enable");
700         if (err) {
701                 printk(KERN_ERR "Can't get the gpio for SD power control");
702                 goto return_err;
703         }
704         gpio_direction_output(SG2_SD_POWER_ENABLE, 0);
705
706         err = gpio_request(SG2_GPIO_nSD_DETECT, "SG2_sd_detect");
707         if (err) {
708                 printk(KERN_ERR "Can't get the sd detect gpio");
709                 goto free_power_en;
710         }
711         gpio_direction_input(SG2_GPIO_nSD_DETECT);
712
713         err = request_irq(PXA_GPIO_TO_IRQ(SG2_GPIO_nSD_DETECT),
714                           stargate2_detect_int,
715                           IRQ_TYPE_EDGE_BOTH,
716                           "MMC card detect",
717                           data);
718         if (err) {
719                 printk(KERN_ERR "can't request MMC card detect IRQ\n");
720                 goto free_nsd_detect;
721         }
722         return 0;
723
724  free_nsd_detect:
725         gpio_free(SG2_GPIO_nSD_DETECT);
726  free_power_en:
727         gpio_free(SG2_SD_POWER_ENABLE);
728  return_err:
729         return err;
730 }
731
732 /**
733  * stargate2_mci_setpower() - set state of mmc power supply
734  *
735  * Very simple control. Either it is on or off and is controlled by
736  * a gpio pin */
737 static int stargate2_mci_setpower(struct device *dev, unsigned int vdd)
738 {
739         gpio_set_value(SG2_SD_POWER_ENABLE, !!vdd);
740         return 0;
741 }
742
743 static void stargate2_mci_exit(struct device *dev, void *data)
744 {
745         free_irq(PXA_GPIO_TO_IRQ(SG2_GPIO_nSD_DETECT), data);
746         gpio_free(SG2_SD_POWER_ENABLE);
747         gpio_free(SG2_GPIO_nSD_DETECT);
748 }
749
750 static struct pxamci_platform_data stargate2_mci_platform_data = {
751         .detect_delay_ms = 250,
752         .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
753         .init = stargate2_mci_init,
754         .setpower = stargate2_mci_setpower,
755         .exit = stargate2_mci_exit,
756 };
757
758
759 /*
760  * SRAM - The Stargate 2 has 32MB of SRAM.
761  *
762  * Here it is made available as an MTD. This will then
763  * typically have a cifs filesystem created on it to provide
764  * fast temporary storage.
765  */
766 static struct resource sram_resources = {
767         .start = PXA_CS1_PHYS,
768         .end = PXA_CS1_PHYS + SZ_32M-1,
769         .flags = IORESOURCE_MEM,
770 };
771
772 static struct platdata_mtd_ram stargate2_sram_pdata = {
773         .mapname = "Stargate2 SRAM",
774         .bankwidth = 2,
775 };
776
777 static struct platform_device stargate2_sram = {
778         .name = "mtd-ram",
779         .id = 0,
780         .resource = &sram_resources,
781         .num_resources = 1,
782         .dev = {
783                 .platform_data = &stargate2_sram_pdata,
784         },
785 };
786
787 static struct pcf857x_platform_data platform_data_pcf857x = {
788         .gpio_base = 128,
789         .n_latch = 0,
790         .setup = NULL,
791         .teardown = NULL,
792         .context = NULL,
793 };
794
795 static const struct property_entry pca9500_eeprom_properties[] = {
796         PROPERTY_ENTRY_U32("pagesize", 4),
797         { }
798 };
799
800 /**
801  * stargate2_reset_bluetooth() reset the bluecore to ensure consistent state
802  **/
803 static int stargate2_reset_bluetooth(void)
804 {
805         int err;
806         err = gpio_request(SG2_BT_RESET, "SG2_BT_RESET");
807         if (err) {
808                 printk(KERN_ERR "Could not get gpio for bluetooth reset\n");
809                 return err;
810         }
811         gpio_direction_output(SG2_BT_RESET, 1);
812         mdelay(5);
813         /* now reset it - 5 msec minimum */
814         gpio_set_value(SG2_BT_RESET, 0);
815         mdelay(10);
816         gpio_set_value(SG2_BT_RESET, 1);
817         gpio_free(SG2_BT_RESET);
818         return 0;
819 }
820
821 static struct led_info stargate2_leds[] = {
822         {
823                 .name = "sg2:red",
824                 .flags = DA9030_LED_RATE_ON,
825         }, {
826                 .name = "sg2:blue",
827                 .flags = DA9030_LED_RATE_ON,
828         }, {
829                 .name = "sg2:green",
830                 .flags = DA9030_LED_RATE_ON,
831         },
832 };
833
834 static struct da903x_subdev_info stargate2_da9030_subdevs[] = {
835         {
836                 .name = "da903x-led",
837                 .id = DA9030_ID_LED_2,
838                 .platform_data = &stargate2_leds[0],
839         }, {
840                 .name = "da903x-led",
841                 .id = DA9030_ID_LED_3,
842                 .platform_data = &stargate2_leds[2],
843         }, {
844                 .name = "da903x-led",
845                 .id = DA9030_ID_LED_4,
846                 .platform_data = &stargate2_leds[1],
847         }, {
848                 .name = "da903x-regulator",
849                 .id = DA9030_ID_LDO2,
850                 .platform_data = &stargate2_ldo_init_data[vcc_bbio],
851         }, {
852                 .name = "da903x-regulator",
853                 .id = DA9030_ID_LDO3,
854                 .platform_data = &stargate2_ldo_init_data[vcc_bb],
855         }, {
856                 .name = "da903x-regulator",
857                 .id = DA9030_ID_LDO4,
858                 .platform_data = &stargate2_ldo_init_data[vcc_pxa_flash],
859         }, {
860                 .name = "da903x-regulator",
861                 .id = DA9030_ID_LDO5,
862                 .platform_data = &stargate2_ldo_init_data[vcc_cc2420],
863         }, {
864                 .name = "da903x-regulator",
865                 .id = DA9030_ID_LDO6,
866                 .platform_data = &stargate2_ldo_init_data[vcc_vref],
867         }, {
868                 .name = "da903x-regulator",
869                 .id = DA9030_ID_LDO7,
870                 .platform_data = &stargate2_ldo_init_data[vcc_sram_ext],
871         }, {
872                 .name = "da903x-regulator",
873                 .id = DA9030_ID_LDO8,
874                 .platform_data = &stargate2_ldo_init_data[vcc_mica],
875         }, {
876                 .name = "da903x-regulator",
877                 .id = DA9030_ID_LDO9,
878                 .platform_data = &stargate2_ldo_init_data[vcc_bt],
879         }, {
880                 .name = "da903x-regulator",
881                 .id = DA9030_ID_LDO10,
882                 .platform_data = &stargate2_ldo_init_data[vcc_sensor_1_8],
883         }, {
884                 .name = "da903x-regulator",
885                 .id = DA9030_ID_LDO11,
886                 .platform_data = &stargate2_ldo_init_data[vcc_sensor_3],
887         }, {
888                 .name = "da903x-regulator",
889                 .id = DA9030_ID_LDO12,
890                 .platform_data = &stargate2_ldo_init_data[vcc_lcd],
891         }, {
892                 .name = "da903x-regulator",
893                 .id = DA9030_ID_LDO15,
894                 .platform_data = &stargate2_ldo_init_data[vcc_pxa_pll],
895         }, {
896                 .name = "da903x-regulator",
897                 .id = DA9030_ID_LDO17,
898                 .platform_data = &stargate2_ldo_init_data[vcc_pxa_usim],
899         }, {
900                 .name = "da903x-regulator", /*pxa vcc i/o and cc2420 vcc i/o */
901                 .id = DA9030_ID_LDO18,
902                 .platform_data = &stargate2_ldo_init_data[vcc_io],
903         }, {
904                 .name = "da903x-regulator",
905                 .id = DA9030_ID_LDO19,
906                 .platform_data = &stargate2_ldo_init_data[vcc_pxa_mem],
907         },
908 };
909
910 static struct da903x_platform_data stargate2_da9030_pdata = {
911         .num_subdevs = ARRAY_SIZE(stargate2_da9030_subdevs),
912         .subdevs = stargate2_da9030_subdevs,
913 };
914
915 static struct i2c_board_info __initdata stargate2_pwr_i2c_board_info[] = {
916         {
917                 .type = "da9030",
918                 .addr = 0x49,
919                 .platform_data = &stargate2_da9030_pdata,
920                 .irq = PXA_GPIO_TO_IRQ(1),
921         },
922 };
923
924 static struct i2c_board_info __initdata stargate2_i2c_board_info[] = {
925         /* Techically this a pca9500 - but it's compatible with the 8574
926          * for gpio expansion and the 24c02 for eeprom access.
927          */
928         {
929                 .type = "pcf8574",
930                 .addr =  0x27,
931                 .platform_data = &platform_data_pcf857x,
932         }, {
933                 .type = "24c02",
934                 .addr = 0x57,
935                 .properties = pca9500_eeprom_properties,
936         }, {
937                 .type = "max1238",
938                 .addr = 0x35,
939         }, { /* ITS400 Sensor board only */
940                 .type = "max1363",
941                 .addr = 0x34,
942                 /* Through a nand gate - Also beware, on V2 sensor board the
943                  * pull up resistors are missing.
944                  */
945                 .irq = PXA_GPIO_TO_IRQ(99),
946         }, { /* ITS400 Sensor board only */
947                 .type = "tsl2561",
948                 .addr = 0x49,
949                 /* Through a nand gate - Also beware, on V2 sensor board the
950                  * pull up resistors are missing.
951                  */
952                 .irq = PXA_GPIO_TO_IRQ(99),
953         }, { /* ITS400 Sensor board only */
954                 .type = "tmp175",
955                 .addr = 0x4A,
956                 .irq = PXA_GPIO_TO_IRQ(96),
957         },
958 };
959
960 /* Board doesn't support cable detection - so always lie and say
961  * something is there.
962  */
963 static int sg2_udc_detect(void)
964 {
965         return 1;
966 }
967
968 static struct pxa2xx_udc_mach_info stargate2_udc_info __initdata = {
969         .udc_is_connected       = sg2_udc_detect,
970         .udc_command            = sg2_udc_command,
971 };
972
973 static struct platform_device *stargate2_devices[] = {
974         &stargate2_flash_device,
975         &stargate2_sram,
976         &smc91x_device,
977         &sht15,
978 };
979
980 static void __init stargate2_init(void)
981 {
982         /* This is probably a board specific hack as this must be set
983            prior to connecting the MFP stuff up. */
984         __raw_writel(__raw_readl(MECR) & ~MECR_NOS, MECR);
985
986         pxa2xx_mfp_config(ARRAY_AND_SIZE(stargate2_pin_config));
987
988         imote2_stargate2_init();
989
990         gpiod_add_lookup_table(&sht15_gpiod_table);
991         platform_add_devices(ARRAY_AND_SIZE(stargate2_devices));
992
993         i2c_register_board_info(0, ARRAY_AND_SIZE(stargate2_i2c_board_info));
994         i2c_register_board_info(1, stargate2_pwr_i2c_board_info,
995                                 ARRAY_SIZE(stargate2_pwr_i2c_board_info));
996
997         pxa_set_mci_info(&stargate2_mci_platform_data);
998
999         pxa_set_udc_info(&stargate2_udc_info);
1000
1001         stargate2_reset_bluetooth();
1002 }
1003 #endif
1004
1005 #ifdef CONFIG_MACH_INTELMOTE2
1006 MACHINE_START(INTELMOTE2, "IMOTE 2")
1007         .map_io         = pxa27x_map_io,
1008         .nr_irqs        = PXA_NR_IRQS,
1009         .init_irq       = pxa27x_init_irq,
1010         .handle_irq     = pxa27x_handle_irq,
1011         .init_time      = pxa_timer_init,
1012         .init_machine   = imote2_init,
1013         .atag_offset    = 0x100,
1014         .restart        = pxa_restart,
1015 MACHINE_END
1016 #endif
1017
1018 #ifdef CONFIG_MACH_STARGATE2
1019 MACHINE_START(STARGATE2, "Stargate 2")
1020         .map_io = pxa27x_map_io,
1021         .nr_irqs = STARGATE_NR_IRQS,
1022         .init_irq = pxa27x_init_irq,
1023         .handle_irq = pxa27x_handle_irq,
1024         .init_time      = pxa_timer_init,
1025         .init_machine = stargate2_init,
1026         .atag_offset = 0x100,
1027         .restart        = pxa_restart,
1028 MACHINE_END
1029 #endif