Merge branch 'topic/cleanup' into for-linus
[linux-2.6-block.git] / arch / arm / mach-pxa / imote2.c
CommitLineData
b6795fa9
JC
1/*
2 * linux/arch/arm/mach-pxa/imote2.c
3 *
4 * Author: Ed C. Epp
5 * Created: Nov 05, 2002
6 * Copyright: Intel Corp.
7 *
8 * Modified 2008: Jonathan Cameron
9 *
10 * The Imote2 is a wireless sensor node platform sold
11 * by Crossbow (www.xbow.com).
12 */
13
14#include <linux/init.h>
15#include <linux/device.h>
16#include <linux/mtd/mtd.h>
17#include <linux/mtd/partitions.h>
18#include <linux/platform_device.h>
19#include <linux/regulator/machine.h>
20#include <linux/gpio.h>
21#include <linux/leds.h>
22#include <linux/spi/spi.h>
23#include <linux/i2c.h>
24#include <linux/mfd/da903x.h>
25
26#include <asm/mach-types.h>
27#include <asm/mach/arch.h>
28#include <asm/mach/map.h>
29#include <asm/mach/flash.h>
30
51c62982 31#include <mach/pxa27x.h>
b6795fa9 32#include <mach/i2c.h>
b6795fa9
JC
33#include <mach/udc.h>
34#include <mach/mmc.h>
35#include <mach/pxa2xx_spi.h>
36#include <mach/pxa27x-udc.h>
37
38#include "devices.h"
39#include "generic.h"
40
41static unsigned long imote2_pin_config[] __initdata = {
42
43 /* Device Identification for wakeup*/
44 GPIO102_GPIO,
45
46 /* Button */
47 GPIO91_GPIO,
48
49 /* DA9030 */
50 GPIO1_GPIO,
51
52 /* MMC */
53 GPIO32_MMC_CLK,
54 GPIO112_MMC_CMD,
55 GPIO92_MMC_DAT_0,
56 GPIO109_MMC_DAT_1,
57 GPIO110_MMC_DAT_2,
58 GPIO111_MMC_DAT_3,
59
60 /* 802.15.4 radio - driver out of mainline */
61 GPIO22_GPIO, /* CC_RSTN */
62 GPIO114_GPIO, /* CC_FIFO */
63 GPIO116_GPIO, /* CC_CCA */
64 GPIO0_GPIO, /* CC_FIFOP */
65 GPIO16_GPIO, /* CCSFD */
66 GPIO39_GPIO, /* CSn */
67 GPIO115_GPIO, /* Power enable */
68
69 /* I2C */
70 GPIO117_I2C_SCL,
71 GPIO118_I2C_SDA,
72
73 /* SSP 3 - 802.15.4 radio */
74 GPIO39_GPIO, /* Chip Select */
75 GPIO34_SSP3_SCLK,
76 GPIO35_SSP3_TXD,
77 GPIO41_SSP3_RXD,
78
79 /* SSP 2 - to daughter boards */
80 GPIO37_GPIO, /* Chip Select */
81 GPIO36_SSP2_SCLK,
82 GPIO38_SSP2_TXD,
83 GPIO11_SSP2_RXD,
84
85 /* SSP 1 - to daughter boards */
86 GPIO24_GPIO, /* Chip Select */
87 GPIO23_SSP1_SCLK,
88 GPIO25_SSP1_TXD,
89 GPIO26_SSP1_RXD,
90
91 /* BTUART Basic Connector*/
92 GPIO42_BTUART_RXD,
93 GPIO43_BTUART_TXD,
94 GPIO44_BTUART_CTS,
95 GPIO45_BTUART_RTS,
96
97 /* STUART Serial console via debug board*/
98 GPIO46_STUART_RXD,
99 GPIO47_STUART_TXD,
100
101 /* Basic sensor board */
102 GPIO96_GPIO, /* accelerometer interrupt */
103 GPIO99_GPIO, /* ADC interrupt */
104
105 /* Connector pins specified as gpios */
106 GPIO94_GPIO, /* large basic connector pin 14 */
107 GPIO10_GPIO, /* large basic connector pin 23 */
108
109 /* LEDS */
110 GPIO103_GPIO, /* red led */
111 GPIO104_GPIO, /* green led */
112 GPIO105_GPIO, /* blue led */
113};
114
115static struct gpio_led imote2_led_pins[] = {
116 {
117 .name = "imote2:red",
118 .gpio = 103,
119 .active_low = 1,
120 }, {
121 .name = "imote2:green",
122 .gpio = 104,
123 .active_low = 1,
124 }, {
125 .name = "imote2:blue",
126 .gpio = 105,
127 .active_low = 1,
128 },
129};
130
131static struct gpio_led_platform_data imote2_led_data = {
132 .num_leds = ARRAY_SIZE(imote2_led_pins),
133 .leds = imote2_led_pins,
134};
135
136static struct platform_device imote2_leds = {
137 .name = "leds-gpio",
138 .id = -1,
139 .dev = {
140 .platform_data = &imote2_led_data,
141 },
142};
143
144/* Reverse engineered partly from Platformx drivers */
145enum imote2_ldos{
146 vcc_vref,
147 vcc_cc2420,
148 vcc_mica,
149 vcc_bt,
150 /* The two voltages available to sensor boards */
151 vcc_sensor_1_8,
152 vcc_sensor_3,
153
154 vcc_sram_ext, /* directly connected to the pxa271 */
155 vcc_pxa_pll,
156 vcc_pxa_usim, /* Reference voltage for certain gpios */
157 vcc_pxa_mem,
158 vcc_pxa_flash,
159 vcc_pxa_core, /*Dc-Dc buck not yet supported */
160 vcc_lcd,
161 vcc_bb,
162 vcc_bbio,
163 vcc_io, /* cc2420 802.15.4 radio and pxa vcc_io ?*/
164};
165
166/* The values of the various regulator constraints are obviously dependent
167 * on exactly what is wired to each ldo. Unfortunately this information is
168 * not generally available. More information has been requested from Xbow
169 * but as of yet they haven't been forthcoming.
170 *
171 * Some of these are clearly Stargate 2 related (no way of plugging
172 * in an lcd on the IM2 for example!).
173 */
174static struct regulator_init_data imote2_ldo_init_data[] = {
175 [vcc_bbio] = {
176 .constraints = { /* board default 1.8V */
177 .name = "vcc_bbio",
178 .min_uV = 1800000,
179 .max_uV = 1800000,
180 },
181 },
182 [vcc_bb] = {
183 .constraints = { /* board default 2.8V */
184 .name = "vcc_bb",
185 .min_uV = 2700000,
186 .max_uV = 3000000,
187 },
188 },
189 [vcc_pxa_flash] = {
190 .constraints = {/* default is 1.8V */
191 .name = "vcc_pxa_flash",
192 .min_uV = 1800000,
193 .max_uV = 1800000,
194 },
195 },
196 [vcc_cc2420] = { /* also vcc_io */
197 .constraints = {
198 /* board default is 2.8V */
199 .name = "vcc_cc2420",
200 .min_uV = 2700000,
201 .max_uV = 3300000,
202 },
203 },
204 [vcc_vref] = { /* Reference for what? */
205 .constraints = { /* default 1.8V */
206 .name = "vcc_vref",
207 .min_uV = 1800000,
208 .max_uV = 1800000,
209 },
210 },
211 [vcc_sram_ext] = {
212 .constraints = { /* default 2.8V */
213 .name = "vcc_sram_ext",
214 .min_uV = 2800000,
215 .max_uV = 2800000,
216 },
217 },
218 [vcc_mica] = {
219 .constraints = { /* default 2.8V */
220 .name = "vcc_mica",
221 .min_uV = 2800000,
222 .max_uV = 2800000,
223 },
224 },
225 [vcc_bt] = {
226 .constraints = { /* default 2.8V */
227 .name = "vcc_bt",
228 .min_uV = 2800000,
229 .max_uV = 2800000,
230 },
231 },
232 [vcc_lcd] = {
233 .constraints = { /* default 2.8V */
234 .name = "vcc_lcd",
235 .min_uV = 2700000,
236 .max_uV = 3300000,
237 },
238 },
239 [vcc_io] = { /* Same or higher than everything
240 * bar vccbat and vccusb */
241 .constraints = { /* default 2.8V */
242 .name = "vcc_io",
243 .min_uV = 2692000,
244 .max_uV = 3300000,
245 },
246 },
247 [vcc_sensor_1_8] = {
248 .constraints = { /* default 1.8V */
249 .name = "vcc_sensor_1_8",
250 .min_uV = 1800000,
251 .max_uV = 1800000,
252 },
253 },
254 [vcc_sensor_3] = { /* curiously default 2.8V */
255 .constraints = {
256 .name = "vcc_sensor_3",
257 .min_uV = 2800000,
258 .max_uV = 3000000,
259 },
260 },
261 [vcc_pxa_pll] = { /* 1.17V - 1.43V, default 1.3V*/
262 .constraints = {
263 .name = "vcc_pxa_pll",
264 .min_uV = 1170000,
265 .max_uV = 1430000,
266 },
267 },
268 [vcc_pxa_usim] = {
269 .constraints = { /* default 1.8V */
270 .name = "vcc_pxa_usim",
271 .min_uV = 1710000,
272 .max_uV = 2160000,
273 },
274 },
275 [vcc_pxa_mem] = {
276 .constraints = { /* default 1.8V */
277 .name = "vcc_pxa_mem",
278 .min_uV = 1800000,
279 .max_uV = 1800000,
280 },
281 },
282};
283
284static struct da903x_subdev_info imote2_da9030_subdevs[] = {
285 {
286 .name = "da903x-regulator",
287 .id = DA9030_ID_LDO2,
288 .platform_data = &imote2_ldo_init_data[vcc_bbio],
289 }, {
290 .name = "da903x-regulator",
291 .id = DA9030_ID_LDO3,
292 .platform_data = &imote2_ldo_init_data[vcc_bb],
293 }, {
294 .name = "da903x-regulator",
295 .id = DA9030_ID_LDO4,
296 .platform_data = &imote2_ldo_init_data[vcc_pxa_flash],
297 }, {
298 .name = "da903x-regulator",
299 .id = DA9030_ID_LDO5,
300 .platform_data = &imote2_ldo_init_data[vcc_cc2420],
301 }, {
302 .name = "da903x-regulator",
303 .id = DA9030_ID_LDO6,
304 .platform_data = &imote2_ldo_init_data[vcc_vref],
305 }, {
306 .name = "da903x-regulator",
307 .id = DA9030_ID_LDO7,
308 .platform_data = &imote2_ldo_init_data[vcc_sram_ext],
309 }, {
310 .name = "da903x-regulator",
311 .id = DA9030_ID_LDO8,
312 .platform_data = &imote2_ldo_init_data[vcc_mica],
313 }, {
314 .name = "da903x-regulator",
315 .id = DA9030_ID_LDO9,
316 .platform_data = &imote2_ldo_init_data[vcc_bt],
317 }, {
318 .name = "da903x-regulator",
319 .id = DA9030_ID_LDO10,
320 .platform_data = &imote2_ldo_init_data[vcc_sensor_1_8],
321 }, {
322 .name = "da903x-regulator",
323 .id = DA9030_ID_LDO11,
324 .platform_data = &imote2_ldo_init_data[vcc_sensor_3],
325 }, {
326 .name = "da903x-regulator",
327 .id = DA9030_ID_LDO12,
328 .platform_data = &imote2_ldo_init_data[vcc_lcd],
329 }, {
330 .name = "da903x-regulator",
331 .id = DA9030_ID_LDO15,
332 .platform_data = &imote2_ldo_init_data[vcc_pxa_pll],
333 }, {
334 .name = "da903x-regulator",
335 .id = DA9030_ID_LDO17,
336 .platform_data = &imote2_ldo_init_data[vcc_pxa_usim],
337 }, {
338 .name = "da903x-regulator",
339 .id = DA9030_ID_LDO18,
340 .platform_data = &imote2_ldo_init_data[vcc_io],
341 }, {
342 .name = "da903x-regulator",
343 .id = DA9030_ID_LDO19,
344 .platform_data = &imote2_ldo_init_data[vcc_pxa_mem],
345 },
346};
347
348static struct da903x_platform_data imote2_da9030_pdata = {
349 .num_subdevs = ARRAY_SIZE(imote2_da9030_subdevs),
350 .subdevs = imote2_da9030_subdevs,
351};
352
353/* As the the imote2 doesn't currently have a conventional SD slot
354 * there is no option to hotplug cards, making all this rather simple
355 */
356static int imote2_mci_get_ro(struct device *dev)
357{
358 return 0;
359}
360
361/* Rather simple case as hotplugging not possible */
362static struct pxamci_platform_data imote2_mci_platform_data = {
363 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34, /* default anyway */
364 .get_ro = imote2_mci_get_ro,
365};
366
367static struct mtd_partition imote2flash_partitions[] = {
368 {
369 .name = "Bootloader",
370 .size = 0x00040000,
371 .offset = 0,
372 .mask_flags = MTD_WRITEABLE,
373 }, {
374 .name = "Kernel",
375 .size = 0x00200000,
376 .offset = 0x00040000,
377 .mask_flags = 0,
378 }, {
379 .name = "Filesystem",
380 .size = 0x01DC0000,
381 .offset = 0x00240000,
382 .mask_flags = 0,
383 },
384};
385
386static struct resource flash_resources = {
387 .start = PXA_CS0_PHYS,
388 .end = PXA_CS0_PHYS + SZ_32M - 1,
389 .flags = IORESOURCE_MEM,
390};
391
392static struct flash_platform_data imote2_flash_data = {
393 .map_name = "cfi_probe",
394 .parts = imote2flash_partitions,
395 .nr_parts = ARRAY_SIZE(imote2flash_partitions),
396 .name = "PXA27xOnChipROM",
397 .width = 2,
398};
399
400static struct platform_device imote2_flash_device = {
401 .name = "pxa2xx-flash",
402 .id = 0,
403 .dev = {
404 .platform_data = &imote2_flash_data,
405 },
406 .resource = &flash_resources,
407 .num_resources = 1,
408};
409
410/* Some of the drivers here are out of kernel at the moment (parts of IIO)
411 * and it may be a while before they are in the mainline.
412 */
413static struct i2c_board_info __initdata imote2_i2c_board_info[] = {
414 { /* UCAM sensor board */
d81e77f0 415 .type = "max1239",
b6795fa9
JC
416 .addr = 0x35,
417 }, { /* ITS400 Sensor board only */
418 .type = "max1363",
419 .addr = 0x34,
420 /* Through a nand gate - Also beware, on V2 sensor board the
421 * pull up resistors are missing.
422 */
423 .irq = IRQ_GPIO(99),
424 }, { /* ITS400 Sensor board only */
425 .type = "tsl2561",
426 .addr = 0x49,
427 /* Through a nand gate - Also beware, on V2 sensor board the
428 * pull up resistors are missing.
429 */
430 .irq = IRQ_GPIO(99),
431 }, { /* ITS400 Sensor board only */
432 .type = "tmp175",
433 .addr = 0x4A,
434 .irq = IRQ_GPIO(96),
435 },
436};
437
438static struct i2c_board_info __initdata imote2_pwr_i2c_board_info[] = {
439 {
440 .type = "da9030",
441 .addr = 0x49,
442 .platform_data = &imote2_da9030_pdata,
443 .irq = gpio_to_irq(1),
444 },
445};
446
447static struct pxa2xx_spi_master pxa_ssp_master_0_info = {
448 .num_chipselect = 1,
449};
450
451static struct pxa2xx_spi_master pxa_ssp_master_1_info = {
452 .num_chipselect = 1,
453};
454
455static struct pxa2xx_spi_master pxa_ssp_master_2_info = {
456 .num_chipselect = 1,
457};
458
459/* Patch posted by Eric Miao <eric.miao@marvell.com> will remove
460 * the need for these functions.
461 */
462static void spi1control(u32 command)
463{
464 gpio_set_value(24, command & PXA2XX_CS_ASSERT ? 0 : 1);
465};
466
467static void spi3control(u32 command)
468{
469 gpio_set_value(39, command & PXA2XX_CS_ASSERT ? 0 : 1);
470};
471
472static struct pxa2xx_spi_chip staccel_chip_info = {
473 .tx_threshold = 8,
474 .rx_threshold = 8,
475 .dma_burst_size = 8,
476 .timeout = 235,
477 .cs_control = spi1control,
478};
479
480static struct pxa2xx_spi_chip cc2420_info = {
481 .tx_threshold = 8,
482 .rx_threshold = 8,
483 .dma_burst_size = 8,
484 .timeout = 235,
485 .cs_control = spi3control,
486};
487
488static struct spi_board_info spi_board_info[] __initdata = {
489 { /* Driver in IIO */
490 .modalias = "lis3l02dq",
491 .max_speed_hz = 8000000,/* 8MHz max spi frequency at 3V */
492 .bus_num = 1,
493 .chip_select = 0,
494 .controller_data = &staccel_chip_info,
495 .irq = IRQ_GPIO(96),
496 }, { /* Driver out of kernel as it needs considerable rewriting */
497 .modalias = "cc2420",
498 .max_speed_hz = 6500000,
499 .bus_num = 3,
500 .chip_select = 0,
501 .controller_data = &cc2420_info,
502 },
503};
504
505static void im2_udc_command(int cmd)
506{
507 switch (cmd) {
508 case PXA2XX_UDC_CMD_CONNECT:
509 UP2OCR |= UP2OCR_HXOE | UP2OCR_DPPUE | UP2OCR_DPPUBE;
510 break;
511 case PXA2XX_UDC_CMD_DISCONNECT:
512 UP2OCR &= ~(UP2OCR_HXOE | UP2OCR_DPPUE | UP2OCR_DPPUBE);
513 break;
514 }
515}
516
517static struct pxa2xx_udc_mach_info imote2_udc_info __initdata = {
518 .udc_command = im2_udc_command,
519};
520
521static struct platform_device *imote2_devices[] = {
522 &imote2_flash_device,
523 &imote2_leds,
524};
525
526static struct i2c_pxa_platform_data i2c_pwr_pdata = {
527 .fast_mode = 1,
528};
529
530static struct i2c_pxa_platform_data i2c_pdata = {
531 .fast_mode = 1,
532};
533
534static void __init imote2_init(void)
535{
536
537 pxa2xx_mfp_config(ARRAY_AND_SIZE(imote2_pin_config));
538 /* SPI chip select directions - all other directions should
539 * be handled by drivers.*/
540 gpio_direction_output(37, 0);
541 gpio_direction_output(24, 0);
542 gpio_direction_output(39, 0);
543
544 platform_add_devices(imote2_devices, ARRAY_SIZE(imote2_devices));
545
546 pxa2xx_set_spi_info(1, &pxa_ssp_master_0_info);
547 pxa2xx_set_spi_info(2, &pxa_ssp_master_1_info);
548 pxa2xx_set_spi_info(3, &pxa_ssp_master_2_info);
549
550 spi_register_board_info(spi_board_info, ARRAY_SIZE(spi_board_info));
551
552 i2c_register_board_info(0, imote2_i2c_board_info,
553 ARRAY_SIZE(imote2_i2c_board_info));
554 i2c_register_board_info(1, imote2_pwr_i2c_board_info,
555 ARRAY_SIZE(imote2_pwr_i2c_board_info));
556
557 pxa27x_set_i2c_power_info(&i2c_pwr_pdata);
558 pxa_set_i2c_info(&i2c_pdata);
559
560 pxa_set_mci_info(&imote2_mci_platform_data);
561 pxa_set_udc_info(&imote2_udc_info);
562}
563
564MACHINE_START(INTELMOTE2, "IMOTE 2")
565 .phys_io = 0x40000000,
566 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
567 .map_io = pxa_map_io,
568 .init_irq = pxa27x_init_irq,
569 .timer = &pxa_timer,
570 .init_machine = imote2_init,
571 .boot_params = 0xA0000100,
572MACHINE_END