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