Merge branch 'tc1100-wmi' into release
[sfrench/cifs-2.6.git] / arch / blackfin / mach-bf533 / boards / stamp.c
1 /*
2  * Copyright 2004-2009 Analog Devices Inc.
3  *                2005 National ICT Australia (NICTA)
4  *                      Aidan Williams <aidan@nicta.com.au>
5  *
6  * Licensed under the GPL-2 or later.
7  */
8
9 #include <linux/device.h>
10 #include <linux/platform_device.h>
11 #include <linux/mtd/mtd.h>
12 #include <linux/mtd/partitions.h>
13 #include <linux/mtd/physmap.h>
14 #include <linux/spi/spi.h>
15 #include <linux/spi/flash.h>
16 #include <linux/spi/mmc_spi.h>
17 #if defined(CONFIG_USB_ISP1362_HCD) || defined(CONFIG_USB_ISP1362_HCD_MODULE)
18 #include <linux/usb/isp1362.h>
19 #endif
20 #include <linux/irq.h>
21 #include <linux/i2c.h>
22 #include <asm/dma.h>
23 #include <asm/bfin5xx_spi.h>
24 #include <asm/reboot.h>
25 #include <asm/portmux.h>
26 #include <asm/dpmc.h>
27
28 /*
29  * Name the Board for the /proc/cpuinfo
30  */
31 const char bfin_board_name[] = "ADI BF533-STAMP";
32
33 #if defined(CONFIG_RTC_DRV_BFIN) || defined(CONFIG_RTC_DRV_BFIN_MODULE)
34 static struct platform_device rtc_device = {
35         .name = "rtc-bfin",
36         .id   = -1,
37 };
38 #endif
39
40 /*
41  *  Driver needs to know address, irq and flag pin.
42  */
43 #if defined(CONFIG_SMC91X) || defined(CONFIG_SMC91X_MODULE)
44 #include <linux/smc91x.h>
45
46 static struct smc91x_platdata smc91x_info = {
47         .flags = SMC91X_USE_16BIT | SMC91X_NOWAIT,
48         .leda = RPC_LED_100_10,
49         .ledb = RPC_LED_TX_RX,
50 };
51
52 static struct resource smc91x_resources[] = {
53         {
54                 .name = "smc91x-regs",
55                 .start = 0x20300300,
56                 .end = 0x20300300 + 16,
57                 .flags = IORESOURCE_MEM,
58         }, {
59                 .start = IRQ_PF7,
60                 .end = IRQ_PF7,
61                 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL,
62         },
63 };
64
65 static struct platform_device smc91x_device = {
66         .name = "smc91x",
67         .id = 0,
68         .num_resources = ARRAY_SIZE(smc91x_resources),
69         .resource = smc91x_resources,
70         .dev    = {
71                 .platform_data  = &smc91x_info,
72         },
73 };
74 #endif
75
76 #if defined(CONFIG_USB_NET2272) || defined(CONFIG_USB_NET2272_MODULE)
77 static struct resource net2272_bfin_resources[] = {
78         {
79                 .start = 0x20300000,
80                 .end = 0x20300000 + 0x100,
81                 .flags = IORESOURCE_MEM,
82         }, {
83                 .start = IRQ_PF10,
84                 .end = IRQ_PF10,
85                 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL,
86         },
87 };
88
89 static struct platform_device net2272_bfin_device = {
90         .name = "net2272",
91         .id = -1,
92         .num_resources = ARRAY_SIZE(net2272_bfin_resources),
93         .resource = net2272_bfin_resources,
94 };
95 #endif
96
97 #if defined(CONFIG_MTD_BFIN_ASYNC) || defined(CONFIG_MTD_BFIN_ASYNC_MODULE)
98 static struct mtd_partition stamp_partitions[] = {
99         {
100                 .name   = "bootloader(nor)",
101                 .size   = 0x40000,
102                 .offset = 0,
103         }, {
104                 .name   = "linux kernel(nor)",
105                 .size   = 0x180000,
106                 .offset = MTDPART_OFS_APPEND,
107         }, {
108                 .name   = "file system(nor)",
109                 .size   = MTDPART_SIZ_FULL,
110                 .offset = MTDPART_OFS_APPEND,
111         }
112 };
113
114 static struct physmap_flash_data stamp_flash_data = {
115         .width    = 2,
116         .parts    = stamp_partitions,
117         .nr_parts = ARRAY_SIZE(stamp_partitions),
118 };
119
120 static struct resource stamp_flash_resource[] = {
121         {
122                 .name  = "cfi_probe",
123                 .start = 0x20000000,
124                 .end   = 0x203fffff,
125                 .flags = IORESOURCE_MEM,
126         }, {
127                 .start = 0x7BB07BB0,    /* AMBCTL0 setting when accessing flash */
128                 .end   = 0x7BB07BB0,    /* AMBCTL1 setting when accessing flash */
129                 .flags = IORESOURCE_MEM,
130         }, {
131                 .start = GPIO_PF0,
132                 .flags = IORESOURCE_IRQ,
133         }
134 };
135
136 static struct platform_device stamp_flash_device = {
137         .name          = "bfin-async-flash",
138         .id            = 0,
139         .dev = {
140                 .platform_data = &stamp_flash_data,
141         },
142         .num_resources = ARRAY_SIZE(stamp_flash_resource),
143         .resource      = stamp_flash_resource,
144 };
145 #endif
146
147 #if defined(CONFIG_MTD_M25P80) || defined(CONFIG_MTD_M25P80_MODULE)
148 static struct mtd_partition bfin_spi_flash_partitions[] = {
149         {
150                 .name = "bootloader(spi)",
151                 .size = 0x00040000,
152                 .offset = 0,
153                 .mask_flags = MTD_CAP_ROM
154         }, {
155                 .name = "linux kernel(spi)",
156                 .size = 0x180000,
157                 .offset = MTDPART_OFS_APPEND,
158         }, {
159                 .name = "file system(spi)",
160                 .size = MTDPART_SIZ_FULL,
161                 .offset = MTDPART_OFS_APPEND,
162         }
163 };
164
165 static struct flash_platform_data bfin_spi_flash_data = {
166         .name = "m25p80",
167         .parts = bfin_spi_flash_partitions,
168         .nr_parts = ARRAY_SIZE(bfin_spi_flash_partitions),
169         .type = "m25p64",
170 };
171
172 /* SPI flash chip (m25p64) */
173 static struct bfin5xx_spi_chip spi_flash_chip_info = {
174         .enable_dma = 0,         /* use dma transfer with this chip*/
175         .bits_per_word = 8,
176 };
177 #endif
178
179 #if defined(CONFIG_BFIN_SPI_ADC) || defined(CONFIG_BFIN_SPI_ADC_MODULE)
180 /* SPI ADC chip */
181 static struct bfin5xx_spi_chip spi_adc_chip_info = {
182         .enable_dma = 1,         /* use dma transfer with this chip*/
183         .bits_per_word = 16,
184 };
185 #endif
186
187 #if defined(CONFIG_SND_BLACKFIN_AD1836) || defined(CONFIG_SND_BLACKFIN_AD1836_MODULE)
188 static struct bfin5xx_spi_chip ad1836_spi_chip_info = {
189         .enable_dma = 0,
190         .bits_per_word = 16,
191 };
192 #endif
193
194 #if defined(CONFIG_SPI_SPIDEV) || defined(CONFIG_SPI_SPIDEV_MODULE)
195 static struct bfin5xx_spi_chip spidev_chip_info = {
196         .enable_dma = 0,
197         .bits_per_word = 8,
198 };
199 #endif
200
201 #if defined(CONFIG_MMC_SPI) || defined(CONFIG_MMC_SPI_MODULE)
202 #define MMC_SPI_CARD_DETECT_INT IRQ_PF5
203 static int bfin_mmc_spi_init(struct device *dev,
204         irqreturn_t (*detect_int)(int, void *), void *data)
205 {
206         return request_irq(MMC_SPI_CARD_DETECT_INT, detect_int,
207                 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
208                 "mmc-spi-detect", data);
209 }
210
211 static void bfin_mmc_spi_exit(struct device *dev, void *data)
212 {
213         free_irq(MMC_SPI_CARD_DETECT_INT, data);
214 }
215
216 static struct mmc_spi_platform_data bfin_mmc_spi_pdata = {
217         .init = bfin_mmc_spi_init,
218         .exit = bfin_mmc_spi_exit,
219         .detect_delay = 100, /* msecs */
220 };
221
222 static struct bfin5xx_spi_chip  mmc_spi_chip_info = {
223         .enable_dma = 0,
224         .bits_per_word = 8,
225         .pio_interrupt = 0,
226 };
227 #endif
228
229 static struct spi_board_info bfin_spi_board_info[] __initdata = {
230 #if defined(CONFIG_MTD_M25P80) || defined(CONFIG_MTD_M25P80_MODULE)
231         {
232                 /* the modalias must be the same as spi device driver name */
233                 .modalias = "m25p80", /* Name of spi_driver for this device */
234                 .max_speed_hz = 25000000,     /* max spi clock (SCK) speed in HZ */
235                 .bus_num = 0, /* Framework bus number */
236                 .chip_select = 2, /* Framework chip select. On STAMP537 it is SPISSEL2*/
237                 .platform_data = &bfin_spi_flash_data,
238                 .controller_data = &spi_flash_chip_info,
239                 .mode = SPI_MODE_3,
240         },
241 #endif
242
243 #if defined(CONFIG_BFIN_SPI_ADC) || defined(CONFIG_BFIN_SPI_ADC_MODULE)
244         {
245                 .modalias = "bfin_spi_adc", /* Name of spi_driver for this device */
246                 .max_speed_hz = 6250000,     /* max spi clock (SCK) speed in HZ */
247                 .bus_num = 0, /* Framework bus number */
248                 .chip_select = 1, /* Framework chip select. */
249                 .platform_data = NULL, /* No spi_driver specific config */
250                 .controller_data = &spi_adc_chip_info,
251         },
252 #endif
253
254 #if defined(CONFIG_SND_BLACKFIN_AD1836) || defined(CONFIG_SND_BLACKFIN_AD1836_MODULE)
255         {
256                 .modalias = "ad1836",
257                 .max_speed_hz = 3125000,     /* max spi clock (SCK) speed in HZ */
258                 .bus_num = 0,
259                 .chip_select = CONFIG_SND_BLACKFIN_SPI_PFBIT,
260                 .controller_data = &ad1836_spi_chip_info,
261         },
262 #endif
263
264 #if defined(CONFIG_SPI_SPIDEV) || defined(CONFIG_SPI_SPIDEV_MODULE)
265         {
266                 .modalias = "spidev",
267                 .max_speed_hz = 3125000,     /* max spi clock (SCK) speed in HZ */
268                 .bus_num = 0,
269                 .chip_select = 1,
270                 .controller_data = &spidev_chip_info,
271         },
272 #endif
273 #if defined(CONFIG_MMC_SPI) || defined(CONFIG_MMC_SPI_MODULE)
274         {
275                 .modalias = "mmc_spi",
276                 .max_speed_hz = 20000000,     /* max spi clock (SCK) speed in HZ */
277                 .bus_num = 0,
278                 .chip_select = 4,
279                 .platform_data = &bfin_mmc_spi_pdata,
280                 .controller_data = &mmc_spi_chip_info,
281                 .mode = SPI_MODE_3,
282         },
283 #endif
284 };
285
286 #if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
287 /* SPI (0) */
288 static struct resource bfin_spi0_resource[] = {
289         [0] = {
290                 .start = SPI0_REGBASE,
291                 .end   = SPI0_REGBASE + 0xFF,
292                 .flags = IORESOURCE_MEM,
293         },
294         [1] = {
295                 .start = CH_SPI,
296                 .end   = CH_SPI,
297                 .flags = IORESOURCE_DMA,
298         },
299         [2] = {
300                 .start = IRQ_SPI,
301                 .end   = IRQ_SPI,
302                 .flags = IORESOURCE_IRQ,
303         }
304 };
305
306 /* SPI controller data */
307 static struct bfin5xx_spi_master bfin_spi0_info = {
308         .num_chipselect = 8,
309         .enable_dma = 1,  /* master has the ability to do dma transfer */
310         .pin_req = {P_SPI0_SCK, P_SPI0_MISO, P_SPI0_MOSI, 0},
311 };
312
313 static struct platform_device bfin_spi0_device = {
314         .name = "bfin-spi",
315         .id = 0, /* Bus number */
316         .num_resources = ARRAY_SIZE(bfin_spi0_resource),
317         .resource = bfin_spi0_resource,
318         .dev = {
319                 .platform_data = &bfin_spi0_info, /* Passed to driver */
320         },
321 };
322 #endif  /* spi master and devices */
323
324 #if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
325 static struct resource bfin_uart_resources[] = {
326         {
327                 .start = 0xFFC00400,
328                 .end = 0xFFC004FF,
329                 .flags = IORESOURCE_MEM,
330         },
331 };
332
333 static struct platform_device bfin_uart_device = {
334         .name = "bfin-uart",
335         .id = 1,
336         .num_resources = ARRAY_SIZE(bfin_uart_resources),
337         .resource = bfin_uart_resources,
338 };
339 #endif
340
341 #if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
342 #ifdef CONFIG_BFIN_SIR0
343 static struct resource bfin_sir0_resources[] = {
344         {
345                 .start = 0xFFC00400,
346                 .end = 0xFFC004FF,
347                 .flags = IORESOURCE_MEM,
348         },
349         {
350                 .start = IRQ_UART0_RX,
351                 .end = IRQ_UART0_RX+1,
352                 .flags = IORESOURCE_IRQ,
353         },
354         {
355                 .start = CH_UART0_RX,
356                 .end = CH_UART0_RX+1,
357                 .flags = IORESOURCE_DMA,
358         },
359 };
360
361 static struct platform_device bfin_sir0_device = {
362         .name = "bfin_sir",
363         .id = 0,
364         .num_resources = ARRAY_SIZE(bfin_sir0_resources),
365         .resource = bfin_sir0_resources,
366 };
367 #endif
368 #endif
369
370 #if defined(CONFIG_SERIAL_BFIN_SPORT) || defined(CONFIG_SERIAL_BFIN_SPORT_MODULE)
371 static struct platform_device bfin_sport0_uart_device = {
372         .name = "bfin-sport-uart",
373         .id = 0,
374 };
375
376 static struct platform_device bfin_sport1_uart_device = {
377         .name = "bfin-sport-uart",
378         .id = 1,
379 };
380 #endif
381
382 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
383 #include <linux/input.h>
384 #include <linux/gpio_keys.h>
385
386 static struct gpio_keys_button bfin_gpio_keys_table[] = {
387         {BTN_0, GPIO_PF5, 0, "gpio-keys: BTN0"},
388         {BTN_1, GPIO_PF6, 0, "gpio-keys: BTN1"},
389         {BTN_2, GPIO_PF8, 0, "gpio-keys: BTN2"},
390 };
391
392 static struct gpio_keys_platform_data bfin_gpio_keys_data = {
393         .buttons        = bfin_gpio_keys_table,
394         .nbuttons       = ARRAY_SIZE(bfin_gpio_keys_table),
395 };
396
397 static struct platform_device bfin_device_gpiokeys = {
398         .name      = "gpio-keys",
399         .dev = {
400                 .platform_data = &bfin_gpio_keys_data,
401         },
402 };
403 #endif
404
405 #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
406 #include <linux/i2c-gpio.h>
407
408 static struct i2c_gpio_platform_data i2c_gpio_data = {
409         .sda_pin                = 2,
410         .scl_pin                = 3,
411         .sda_is_open_drain      = 0,
412         .scl_is_open_drain      = 0,
413         .udelay                 = 40,
414 };
415
416 static struct platform_device i2c_gpio_device = {
417         .name           = "i2c-gpio",
418         .id             = 0,
419         .dev            = {
420                 .platform_data  = &i2c_gpio_data,
421         },
422 };
423 #endif
424
425 static struct i2c_board_info __initdata bfin_i2c_board_info[] = {
426 #if defined(CONFIG_JOYSTICK_AD7142) || defined(CONFIG_JOYSTICK_AD7142_MODULE)
427         {
428                 I2C_BOARD_INFO("ad7142_joystick", 0x2C),
429                 .irq = 39,
430         },
431 #endif
432 #if defined(CONFIG_BFIN_TWI_LCD) || defined(CONFIG_BFIN_TWI_LCD_MODULE)
433         {
434                 I2C_BOARD_INFO("pcf8574_lcd", 0x22),
435         },
436 #endif
437 #if defined(CONFIG_INPUT_PCF8574) || defined(CONFIG_INPUT_PCF8574_MODULE)
438         {
439                 I2C_BOARD_INFO("pcf8574_keypad", 0x27),
440                 .irq = 39,
441         },
442 #endif
443 #if defined(CONFIG_FB_BFIN_7393) || defined(CONFIG_FB_BFIN_7393_MODULE)
444         {
445                 I2C_BOARD_INFO("bfin-adv7393", 0x2B),
446         },
447 #endif
448 };
449
450 static const unsigned int cclk_vlev_datasheet[] =
451 {
452         VRPAIR(VLEV_085, 250000000),
453         VRPAIR(VLEV_090, 376000000),
454         VRPAIR(VLEV_095, 426000000),
455         VRPAIR(VLEV_100, 426000000),
456         VRPAIR(VLEV_105, 476000000),
457         VRPAIR(VLEV_110, 476000000),
458         VRPAIR(VLEV_115, 476000000),
459         VRPAIR(VLEV_120, 600000000),
460         VRPAIR(VLEV_125, 600000000),
461         VRPAIR(VLEV_130, 600000000),
462 };
463
464 static struct bfin_dpmc_platform_data bfin_dmpc_vreg_data = {
465         .tuple_tab = cclk_vlev_datasheet,
466         .tabsize = ARRAY_SIZE(cclk_vlev_datasheet),
467         .vr_settling_time = 25 /* us */,
468 };
469
470 static struct platform_device bfin_dpmc = {
471         .name = "bfin dpmc",
472         .dev = {
473                 .platform_data = &bfin_dmpc_vreg_data,
474         },
475 };
476
477 static struct platform_device *stamp_devices[] __initdata = {
478
479         &bfin_dpmc,
480
481 #if defined(CONFIG_RTC_DRV_BFIN) || defined(CONFIG_RTC_DRV_BFIN_MODULE)
482         &rtc_device,
483 #endif
484
485 #if defined(CONFIG_SMC91X) || defined(CONFIG_SMC91X_MODULE)
486         &smc91x_device,
487 #endif
488
489 #if defined(CONFIG_USB_NET2272) || defined(CONFIG_USB_NET2272_MODULE)
490         &net2272_bfin_device,
491 #endif
492
493 #if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
494         &bfin_spi0_device,
495 #endif
496
497 #if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
498         &bfin_uart_device,
499 #endif
500
501 #if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
502 #ifdef CONFIG_BFIN_SIR0
503         &bfin_sir0_device,
504 #endif
505 #endif
506
507 #if defined(CONFIG_SERIAL_BFIN_SPORT) || defined(CONFIG_SERIAL_BFIN_SPORT_MODULE)
508         &bfin_sport0_uart_device,
509         &bfin_sport1_uart_device,
510 #endif
511
512 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
513         &bfin_device_gpiokeys,
514 #endif
515
516 #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
517         &i2c_gpio_device,
518 #endif
519
520 #if defined(CONFIG_MTD_BFIN_ASYNC) || defined(CONFIG_MTD_BFIN_ASYNC_MODULE)
521         &stamp_flash_device,
522 #endif
523 };
524
525 static int __init stamp_init(void)
526 {
527         int ret;
528
529         printk(KERN_INFO "%s(): registering device resources\n", __func__);
530
531         i2c_register_board_info(0, bfin_i2c_board_info,
532                                 ARRAY_SIZE(bfin_i2c_board_info));
533
534         ret = platform_add_devices(stamp_devices, ARRAY_SIZE(stamp_devices));
535         if (ret < 0)
536                 return ret;
537
538 #if defined(CONFIG_SMC91X) || defined(CONFIG_SMC91X_MODULE)
539         /* setup BF533_STAMP CPLD to route AMS3 to Ethernet MAC */
540         bfin_write_FIO_DIR(bfin_read_FIO_DIR() | PF0);
541         bfin_write_FIO_FLAG_S(PF0);
542         SSYNC();
543 #endif
544
545         spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info));
546         return 0;
547 }
548
549 arch_initcall(stamp_init);
550
551 void native_machine_restart(char *cmd)
552 {
553         /* workaround pull up on cpld / flash pin not being strong enough */
554         bfin_write_FIO_INEN(~PF0);
555         bfin_write_FIO_DIR(PF0);
556         bfin_write_FIO_FLAG_C(PF0);
557 }