Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael...
[linux-2.6.git] / arch / blackfin / mach-bf533 / boards / blackstamp.c
1 /*
2  * Board Info File for the BlackStamp
3  *
4  * Copyright 2004-2008 Analog Devices Inc.
5  *                2008 Benjamin Matthews <bmat@lle.rochester.edu>
6  *                2005 National ICT Australia (NICTA)
7  *                      Aidan Williams <aidan@nicta.com.au>
8  *
9  * More info about the BlackStamp at:
10  *      http://blackfin.uclinux.org/gf/project/blackstamp/
11  *
12  * Licensed under the GPL-2 or later.
13  */
14
15 #include <linux/device.h>
16 #include <linux/platform_device.h>
17 #include <linux/mtd/mtd.h>
18 #include <linux/mtd/partitions.h>
19 #include <linux/mtd/physmap.h>
20 #include <linux/spi/spi.h>
21 #include <linux/spi/flash.h>
22 #include <linux/irq.h>
23 #include <linux/i2c.h>
24 #include <asm/dma.h>
25 #include <asm/bfin5xx_spi.h>
26 #include <asm/portmux.h>
27 #include <asm/dpmc.h>
28 #include <mach/fio_flag.h>
29
30 /*
31  * Name the Board for the /proc/cpuinfo
32  */
33 const char bfin_board_name[] = "BlackStamp";
34
35 #if defined(CONFIG_RTC_DRV_BFIN) || defined(CONFIG_RTC_DRV_BFIN_MODULE)
36 static struct platform_device rtc_device = {
37         .name = "rtc-bfin",
38         .id   = -1,
39 };
40 #endif
41
42 /*
43  *  Driver needs to know address, irq and flag pin.
44  */
45 #if defined(CONFIG_SMC91X) || defined(CONFIG_SMC91X_MODULE)
46 #include <linux/smc91x.h>
47
48 static struct smc91x_platdata smc91x_info = {
49         .flags = SMC91X_USE_16BIT | SMC91X_NOWAIT,
50         .leda = RPC_LED_100_10,
51         .ledb = RPC_LED_TX_RX,
52 };
53
54 static struct resource smc91x_resources[] = {
55         {
56                 .name = "smc91x-regs",
57                 .start = 0x20300300,
58                 .end = 0x20300300 + 16,
59                 .flags = IORESOURCE_MEM,
60         }, {
61                 .start = IRQ_PF3,
62                 .end = IRQ_PF3,
63                 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL,
64         },
65 };
66
67 static struct platform_device smc91x_device = {
68         .name = "smc91x",
69         .id = 0,
70         .num_resources = ARRAY_SIZE(smc91x_resources),
71         .resource = smc91x_resources,
72         .dev    = {
73                 .platform_data  = &smc91x_info,
74         },
75 };
76 #endif
77
78 #if defined(CONFIG_MTD_M25P80) || defined(CONFIG_MTD_M25P80_MODULE)
79 static struct mtd_partition bfin_spi_flash_partitions[] = {
80         {
81                 .name = "bootloader(spi)",
82                 .size = 0x00040000,
83                 .offset = 0,
84                 .mask_flags = MTD_CAP_ROM
85         }, {
86                 .name = "linux kernel(spi)",
87                 .size = 0x180000,
88                 .offset = MTDPART_OFS_APPEND,
89         }, {
90                 .name = "file system(spi)",
91                 .size = MTDPART_SIZ_FULL,
92                 .offset = MTDPART_OFS_APPEND,
93         }
94 };
95
96 static struct flash_platform_data bfin_spi_flash_data = {
97         .name = "m25p80",
98         .parts = bfin_spi_flash_partitions,
99         .nr_parts = ARRAY_SIZE(bfin_spi_flash_partitions),
100         .type = "m25p64",
101 };
102
103 /* SPI flash chip (m25p64) */
104 static struct bfin5xx_spi_chip spi_flash_chip_info = {
105         .enable_dma = 0,         /* use dma transfer with this chip*/
106         .bits_per_word = 8,
107 };
108 #endif
109
110 #if defined(CONFIG_MMC_SPI) || defined(CONFIG_MMC_SPI_MODULE)
111 static struct bfin5xx_spi_chip mmc_spi_chip_info = {
112         .enable_dma = 0,
113         .bits_per_word = 8,
114 };
115 #endif
116
117 #if defined(CONFIG_SPI_SPIDEV) || defined(CONFIG_SPI_SPIDEV_MODULE)
118 static struct bfin5xx_spi_chip spidev_chip_info = {
119         .enable_dma = 0,
120         .bits_per_word = 8,
121 };
122 #endif
123
124 static struct spi_board_info bfin_spi_board_info[] __initdata = {
125 #if defined(CONFIG_MTD_M25P80) || defined(CONFIG_MTD_M25P80_MODULE)
126         {
127                 /* the modalias must be the same as spi device driver name */
128                 .modalias = "m25p80", /* Name of spi_driver for this device */
129                 .max_speed_hz = 20000000,     /* max spi clock (SCK) speed in HZ */
130                 .bus_num = 0, /* Framework bus number */
131                 .chip_select = 2, /* Framework chip select. */
132                 .platform_data = &bfin_spi_flash_data,
133                 .controller_data = &spi_flash_chip_info,
134                 .mode = SPI_MODE_3,
135         },
136 #endif
137
138 #if defined(CONFIG_MMC_SPI) || defined(CONFIG_MMC_SPI_MODULE)
139         {
140                 .modalias = "mmc_spi",
141                 .max_speed_hz = 20000000,     /* max spi clock (SCK) speed in HZ */
142                 .bus_num = 0,
143                 .chip_select = 5,
144                 .controller_data = &mmc_spi_chip_info,
145                 .mode = SPI_MODE_3,
146         },
147 #endif
148
149 #if defined(CONFIG_SPI_SPIDEV) || defined(CONFIG_SPI_SPIDEV_MODULE)
150         {
151                 .modalias = "spidev",
152                 .max_speed_hz = 3125000,     /* max spi clock (SCK) speed in HZ */
153                 .bus_num = 0,
154                 .chip_select = 7,
155                 .controller_data = &spidev_chip_info,
156         },
157 #endif
158 };
159
160 #if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
161 /* SPI (0) */
162 static struct resource bfin_spi0_resource[] = {
163         [0] = {
164                 .start = SPI0_REGBASE,
165                 .end   = SPI0_REGBASE + 0xFF,
166                 .flags = IORESOURCE_MEM,
167         },
168         [1] = {
169                 .start = CH_SPI,
170                 .end   = CH_SPI,
171                 .flags = IORESOURCE_DMA,
172         },
173         [2] = {
174                 .start = IRQ_SPI,
175                 .end   = IRQ_SPI,
176                 .flags = IORESOURCE_IRQ,
177         }
178 };
179
180 /* SPI controller data */
181 static struct bfin5xx_spi_master bfin_spi0_info = {
182         .num_chipselect = 8,
183         .enable_dma = 1,  /* master has the ability to do dma transfer */
184         .pin_req = {P_SPI0_SCK, P_SPI0_MISO, P_SPI0_MOSI, 0},
185 };
186
187 static struct platform_device bfin_spi0_device = {
188         .name = "bfin-spi",
189         .id = 0, /* Bus number */
190         .num_resources = ARRAY_SIZE(bfin_spi0_resource),
191         .resource = bfin_spi0_resource,
192         .dev = {
193                 .platform_data = &bfin_spi0_info, /* Passed to driver */
194         },
195 };
196 #endif  /* spi master and devices */
197
198 #if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
199 #ifdef CONFIG_SERIAL_BFIN_UART0
200 static struct resource bfin_uart0_resources[] = {
201         {
202                 .start = BFIN_UART_THR,
203                 .end = BFIN_UART_GCTL+2,
204                 .flags = IORESOURCE_MEM,
205         },
206         {
207                 .start = IRQ_UART0_RX,
208                 .end = IRQ_UART0_RX + 1,
209                 .flags = IORESOURCE_IRQ,
210         },
211         {
212                 .start = IRQ_UART0_ERROR,
213                 .end = IRQ_UART0_ERROR,
214                 .flags = IORESOURCE_IRQ,
215         },
216         {
217                 .start = CH_UART0_TX,
218                 .end = CH_UART0_TX,
219                 .flags = IORESOURCE_DMA,
220         },
221         {
222                 .start = CH_UART0_RX,
223                 .end = CH_UART0_RX,
224                 .flags = IORESOURCE_DMA,
225         },
226 };
227
228 unsigned short bfin_uart0_peripherals[] = {
229         P_UART0_TX, P_UART0_RX, 0
230 };
231
232 static struct platform_device bfin_uart0_device = {
233         .name = "bfin-uart",
234         .id = 0,
235         .num_resources = ARRAY_SIZE(bfin_uart0_resources),
236         .resource = bfin_uart0_resources,
237         .dev = {
238                 .platform_data = &bfin_uart0_peripherals, /* Passed to driver */
239         },
240 };
241 #endif
242 #endif
243
244 #if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
245 #ifdef CONFIG_BFIN_SIR0
246 static struct resource bfin_sir0_resources[] = {
247         {
248                 .start = 0xFFC00400,
249                 .end = 0xFFC004FF,
250                 .flags = IORESOURCE_MEM,
251         },
252         {
253                 .start = IRQ_UART0_RX,
254                 .end = IRQ_UART0_RX+1,
255                 .flags = IORESOURCE_IRQ,
256         },
257         {
258                 .start = CH_UART0_RX,
259                 .end = CH_UART0_RX+1,
260                 .flags = IORESOURCE_DMA,
261         },
262 };
263
264 static struct platform_device bfin_sir0_device = {
265         .name = "bfin_sir",
266         .id = 0,
267         .num_resources = ARRAY_SIZE(bfin_sir0_resources),
268         .resource = bfin_sir0_resources,
269 };
270 #endif
271 #endif
272
273 #if defined(CONFIG_SERIAL_BFIN_SPORT) || defined(CONFIG_SERIAL_BFIN_SPORT_MODULE)
274 #ifdef CONFIG_SERIAL_BFIN_SPORT0_UART
275 static struct resource bfin_sport0_uart_resources[] = {
276         {
277                 .start = SPORT0_TCR1,
278                 .end = SPORT0_MRCS3+4,
279                 .flags = IORESOURCE_MEM,
280         },
281         {
282                 .start = IRQ_SPORT0_RX,
283                 .end = IRQ_SPORT0_RX+1,
284                 .flags = IORESOURCE_IRQ,
285         },
286         {
287                 .start = IRQ_SPORT0_ERROR,
288                 .end = IRQ_SPORT0_ERROR,
289                 .flags = IORESOURCE_IRQ,
290         },
291 };
292
293 unsigned short bfin_sport0_peripherals[] = {
294         P_SPORT0_TFS, P_SPORT0_DTPRI, P_SPORT0_TSCLK, P_SPORT0_RFS,
295         P_SPORT0_DRPRI, P_SPORT0_RSCLK, P_SPORT0_DRSEC, P_SPORT0_DTSEC, 0
296 };
297
298 static struct platform_device bfin_sport0_uart_device = {
299         .name = "bfin-sport-uart",
300         .id = 0,
301         .num_resources = ARRAY_SIZE(bfin_sport0_uart_resources),
302         .resource = bfin_sport0_uart_resources,
303         .dev = {
304                 .platform_data = &bfin_sport0_peripherals, /* Passed to driver */
305         },
306 };
307 #endif
308 #ifdef CONFIG_SERIAL_BFIN_SPORT1_UART
309 static struct resource bfin_sport1_uart_resources[] = {
310         {
311                 .start = SPORT1_TCR1,
312                 .end = SPORT1_MRCS3+4,
313                 .flags = IORESOURCE_MEM,
314         },
315         {
316                 .start = IRQ_SPORT1_RX,
317                 .end = IRQ_SPORT1_RX+1,
318                 .flags = IORESOURCE_IRQ,
319         },
320         {
321                 .start = IRQ_SPORT1_ERROR,
322                 .end = IRQ_SPORT1_ERROR,
323                 .flags = IORESOURCE_IRQ,
324         },
325 };
326
327 unsigned short bfin_sport1_peripherals[] = {
328         P_SPORT1_TFS, P_SPORT1_DTPRI, P_SPORT1_TSCLK, P_SPORT1_RFS,
329         P_SPORT1_DRPRI, P_SPORT1_RSCLK, P_SPORT1_DRSEC, P_SPORT1_DTSEC, 0
330 };
331
332 static struct platform_device bfin_sport1_uart_device = {
333         .name = "bfin-sport-uart",
334         .id = 1,
335         .num_resources = ARRAY_SIZE(bfin_sport1_uart_resources),
336         .resource = bfin_sport1_uart_resources,
337         .dev = {
338                 .platform_data = &bfin_sport1_peripherals, /* Passed to driver */
339         },
340 };
341 #endif
342 #endif
343
344 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
345 #include <linux/input.h>
346 #include <linux/gpio_keys.h>
347
348 static struct gpio_keys_button bfin_gpio_keys_table[] = {
349         {BTN_0, GPIO_PF4, 0, "gpio-keys: BTN0"},
350         {BTN_1, GPIO_PF5, 0, "gpio-keys: BTN1"},
351         {BTN_2, GPIO_PF6, 0, "gpio-keys: BTN2"},
352 }; /* Mapped to the first three PF Test Points */
353
354 static struct gpio_keys_platform_data bfin_gpio_keys_data = {
355         .buttons        = bfin_gpio_keys_table,
356         .nbuttons       = ARRAY_SIZE(bfin_gpio_keys_table),
357 };
358
359 static struct platform_device bfin_device_gpiokeys = {
360         .name      = "gpio-keys",
361         .dev = {
362                 .platform_data = &bfin_gpio_keys_data,
363         },
364 };
365 #endif
366
367 #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
368 #include <linux/i2c-gpio.h>
369
370 static struct i2c_gpio_platform_data i2c_gpio_data = {
371         .sda_pin                = 8,
372         .scl_pin                = 9,
373         .sda_is_open_drain      = 0,
374         .scl_is_open_drain      = 0,
375         .udelay                 = 40,
376 }; /* This hasn't actually been used these pins
377     * are (currently) free pins on the expansion connector */
378
379 static struct platform_device i2c_gpio_device = {
380         .name           = "i2c-gpio",
381         .id             = 0,
382         .dev            = {
383                 .platform_data  = &i2c_gpio_data,
384         },
385 };
386 #endif
387
388 static struct i2c_board_info __initdata bfin_i2c_board_info[] = {
389 };
390
391 static const unsigned int cclk_vlev_datasheet[] =
392 {
393         VRPAIR(VLEV_085, 250000000),
394         VRPAIR(VLEV_090, 376000000),
395         VRPAIR(VLEV_095, 426000000),
396         VRPAIR(VLEV_100, 426000000),
397         VRPAIR(VLEV_105, 476000000),
398         VRPAIR(VLEV_110, 476000000),
399         VRPAIR(VLEV_115, 476000000),
400         VRPAIR(VLEV_120, 600000000),
401         VRPAIR(VLEV_125, 600000000),
402         VRPAIR(VLEV_130, 600000000),
403 };
404
405 static struct bfin_dpmc_platform_data bfin_dmpc_vreg_data = {
406         .tuple_tab = cclk_vlev_datasheet,
407         .tabsize = ARRAY_SIZE(cclk_vlev_datasheet),
408         .vr_settling_time = 25 /* us */,
409 };
410
411 static struct platform_device bfin_dpmc = {
412         .name = "bfin dpmc",
413         .dev = {
414                 .platform_data = &bfin_dmpc_vreg_data,
415         },
416 };
417
418 static struct platform_device *stamp_devices[] __initdata = {
419
420         &bfin_dpmc,
421
422 #if defined(CONFIG_RTC_DRV_BFIN) || defined(CONFIG_RTC_DRV_BFIN_MODULE)
423         &rtc_device,
424 #endif
425
426 #if defined(CONFIG_SMC91X) || defined(CONFIG_SMC91X_MODULE)
427         &smc91x_device,
428 #endif
429
430
431 #if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
432         &bfin_spi0_device,
433 #endif
434
435 #if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
436 #ifdef CONFIG_SERIAL_BFIN_UART0
437         &bfin_uart0_device,
438 #endif
439 #endif
440
441 #if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
442 #ifdef CONFIG_BFIN_SIR0
443         &bfin_sir0_device,
444 #endif
445 #endif
446
447 #if defined(CONFIG_SERIAL_BFIN_SPORT) || defined(CONFIG_SERIAL_BFIN_SPORT_MODULE)
448 #ifdef CONFIG_SERIAL_BFIN_SPORT0_UART
449         &bfin_sport0_uart_device,
450 #endif
451 #ifdef CONFIG_SERIAL_BFIN_SPORT1_UART
452         &bfin_sport1_uart_device,
453 #endif
454 #endif
455
456 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
457         &bfin_device_gpiokeys,
458 #endif
459
460 #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
461         &i2c_gpio_device,
462 #endif
463 };
464
465 static int __init blackstamp_init(void)
466 {
467         int ret;
468
469         printk(KERN_INFO "%s(): registering device resources\n", __func__);
470
471         i2c_register_board_info(0, bfin_i2c_board_info,
472                                 ARRAY_SIZE(bfin_i2c_board_info));
473
474         ret = platform_add_devices(stamp_devices, ARRAY_SIZE(stamp_devices));
475         if (ret < 0)
476                 return ret;
477
478 #if defined(CONFIG_SMC91X) || defined(CONFIG_SMC91X_MODULE)
479         /* setup BF533_STAMP CPLD to route AMS3 to Ethernet MAC */
480         bfin_write_FIO_DIR(bfin_read_FIO_DIR() | PF0);
481         bfin_write_FIO_FLAG_S(PF0);
482         SSYNC();
483 #endif
484
485         spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info));
486         return 0;
487 }
488
489 arch_initcall(blackstamp_init);
490
491 static struct platform_device *stamp_early_devices[] __initdata = {
492 #if defined(CONFIG_SERIAL_BFIN_CONSOLE) || defined(CONFIG_EARLY_PRINTK)
493 #ifdef CONFIG_SERIAL_BFIN_UART0
494         &bfin_uart0_device,
495 #endif
496 #endif
497
498 #if defined(CONFIG_SERIAL_BFIN_SPORT_CONSOLE)
499 #ifdef CONFIG_SERIAL_BFIN_SPORT0_UART
500         &bfin_sport0_uart_device,
501 #endif
502 #ifdef CONFIG_SERIAL_BFIN_SPORT1_UART
503         &bfin_sport1_uart_device,
504 #endif
505 #endif
506 };
507
508 void __init native_machine_early_platform_add_devices(void)
509 {
510         printk(KERN_INFO "register early platform devices\n");
511         early_platform_add_devices(stamp_early_devices,
512                 ARRAY_SIZE(stamp_early_devices));
513 }