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