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