random: Fix handing of arch_get_random_long in get_random_bytes()
[pandora-kernel.git] / arch / blackfin / mach-bf537 / boards / pnav10.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/etherdevice.h>
11 #include <linux/platform_device.h>
12 #include <linux/mtd/mtd.h>
13 #include <linux/mtd/partitions.h>
14 #include <linux/spi/spi.h>
15 #include <linux/spi/flash.h>
16 #include <linux/irq.h>
17 #include <asm/dma.h>
18 #include <asm/bfin5xx_spi.h>
19 #include <asm/portmux.h>
20
21 #include <linux/spi/ad7877.h>
22
23 /*
24  * Name the Board for the /proc/cpuinfo
25  */
26 const char bfin_board_name[] = "ADI PNAV-1.0";
27
28 /*
29  *  Driver needs to know address, irq and flag pin.
30  */
31
32 #if defined(CONFIG_BFIN_CFPCMCIA) || defined(CONFIG_BFIN_CFPCMCIA_MODULE)
33 static struct resource bfin_pcmcia_cf_resources[] = {
34         {
35                 .start = 0x20310000, /* IO PORT */
36                 .end = 0x20312000,
37                 .flags = IORESOURCE_MEM,
38         }, {
39                 .start = 0x20311000, /* Attribute Memory */
40                 .end = 0x20311FFF,
41                 .flags = IORESOURCE_MEM,
42         }, {
43                 .start = IRQ_PF4,
44                 .end = IRQ_PF4,
45                 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
46         }, {
47                 .start = 6, /* Card Detect PF6 */
48                 .end = 6,
49                 .flags = IORESOURCE_IRQ,
50         },
51 };
52
53 static struct platform_device bfin_pcmcia_cf_device = {
54         .name = "bfin_cf_pcmcia",
55         .id = -1,
56         .num_resources = ARRAY_SIZE(bfin_pcmcia_cf_resources),
57         .resource = bfin_pcmcia_cf_resources,
58 };
59 #endif
60
61 #if defined(CONFIG_RTC_DRV_BFIN) || defined(CONFIG_RTC_DRV_BFIN_MODULE)
62 static struct platform_device rtc_device = {
63         .name = "rtc-bfin",
64         .id   = -1,
65 };
66 #endif
67
68 #if defined(CONFIG_SMC91X) || defined(CONFIG_SMC91X_MODULE)
69 #include <linux/smc91x.h>
70
71 static struct smc91x_platdata smc91x_info = {
72         .flags = SMC91X_USE_16BIT | SMC91X_NOWAIT,
73         .leda = RPC_LED_100_10,
74         .ledb = RPC_LED_TX_RX,
75 };
76
77 static struct resource smc91x_resources[] = {
78         {
79                 .name = "smc91x-regs",
80                 .start = 0x20300300,
81                 .end = 0x20300300 + 16,
82                 .flags = IORESOURCE_MEM,
83         }, {
84
85                 .start = IRQ_PF7,
86                 .end = IRQ_PF7,
87                 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL,
88         },
89 };
90 static struct platform_device smc91x_device = {
91         .name = "smc91x",
92         .id = 0,
93         .num_resources = ARRAY_SIZE(smc91x_resources),
94         .resource = smc91x_resources,
95         .dev    = {
96                 .platform_data  = &smc91x_info,
97         },
98 };
99 #endif
100
101 #if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
102 #include <linux/bfin_mac.h>
103 #include <linux/export.h>
104 static const unsigned short bfin_mac_peripherals[] = P_RMII0;
105
106 static struct bfin_phydev_platform_data bfin_phydev_data[] = {
107         {
108                 .addr = 1,
109                 .irq = IRQ_MAC_PHYINT,
110         },
111 };
112
113 static struct bfin_mii_bus_platform_data bfin_mii_bus_data = {
114         .phydev_number = 1,
115         .phydev_data = bfin_phydev_data,
116         .phy_mode = PHY_INTERFACE_MODE_RMII,
117         .mac_peripherals = bfin_mac_peripherals,
118 };
119
120 static struct platform_device bfin_mii_bus = {
121         .name = "bfin_mii_bus",
122         .dev = {
123                 .platform_data = &bfin_mii_bus_data,
124         }
125 };
126
127 static struct platform_device bfin_mac_device = {
128         .name = "bfin_mac",
129         .dev = {
130                 .platform_data = &bfin_mii_bus,
131         }
132 };
133 #endif
134
135 #if defined(CONFIG_USB_NET2272) || defined(CONFIG_USB_NET2272_MODULE)
136 static struct resource net2272_bfin_resources[] = {
137         {
138                 .start = 0x20300000,
139                 .end = 0x20300000 + 0x100,
140                 .flags = IORESOURCE_MEM,
141         }, {
142                 .start = IRQ_PF7,
143                 .end = IRQ_PF7,
144                 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL,
145         },
146 };
147
148 static struct platform_device net2272_bfin_device = {
149         .name = "net2272",
150         .id = -1,
151         .num_resources = ARRAY_SIZE(net2272_bfin_resources),
152         .resource = net2272_bfin_resources,
153 };
154 #endif
155
156 #if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
157 /* all SPI peripherals info goes here */
158
159 #if defined(CONFIG_MTD_M25P80) \
160         || defined(CONFIG_MTD_M25P80_MODULE)
161 static struct mtd_partition bfin_spi_flash_partitions[] = {
162         {
163                 .name = "bootloader(spi)",
164                 .size = 0x00020000,
165                 .offset = 0,
166                 .mask_flags = MTD_CAP_ROM
167         }, {
168                 .name = "linux kernel(spi)",
169                 .size = 0xe0000,
170                 .offset = 0x20000
171         }, {
172                 .name = "file system(spi)",
173                 .size = 0x700000,
174                 .offset = 0x00100000,
175         }
176 };
177
178 static struct flash_platform_data bfin_spi_flash_data = {
179         .name = "m25p80",
180         .parts = bfin_spi_flash_partitions,
181         .nr_parts = ARRAY_SIZE(bfin_spi_flash_partitions),
182         .type = "m25p64",
183 };
184
185 /* SPI flash chip (m25p64) */
186 static struct bfin5xx_spi_chip spi_flash_chip_info = {
187         .enable_dma = 0,         /* use dma transfer with this chip*/
188 };
189 #endif
190
191 #if defined(CONFIG_MMC_SPI) || defined(CONFIG_MMC_SPI_MODULE)
192 static struct bfin5xx_spi_chip mmc_spi_chip_info = {
193         .enable_dma = 0,
194 };
195 #endif
196
197 #if defined(CONFIG_TOUCHSCREEN_AD7877) || defined(CONFIG_TOUCHSCREEN_AD7877_MODULE)
198 static const struct ad7877_platform_data bfin_ad7877_ts_info = {
199         .model                  = 7877,
200         .vref_delay_usecs       = 50,   /* internal, no capacitor */
201         .x_plate_ohms           = 419,
202         .y_plate_ohms           = 486,
203         .pressure_max           = 1000,
204         .pressure_min           = 0,
205         .stopacq_polarity       = 1,
206         .first_conversion_delay = 3,
207         .acquisition_time       = 1,
208         .averaging              = 1,
209         .pen_down_acc_interval  = 1,
210 };
211 #endif
212
213 static struct spi_board_info bfin_spi_board_info[] __initdata = {
214 #if defined(CONFIG_MTD_M25P80) \
215         || defined(CONFIG_MTD_M25P80_MODULE)
216         {
217                 /* the modalias must be the same as spi device driver name */
218                 .modalias = "m25p80", /* Name of spi_driver for this device */
219                 .max_speed_hz = 25000000,     /* max spi clock (SCK) speed in HZ */
220                 .bus_num = 0, /* Framework bus number */
221                 .chip_select = 1, /* Framework chip select. On STAMP537 it is SPISSEL1*/
222                 .platform_data = &bfin_spi_flash_data,
223                 .controller_data = &spi_flash_chip_info,
224                 .mode = SPI_MODE_3,
225         },
226 #endif
227
228 #if defined(CONFIG_SND_BF5XX_SOC_AD183X) \
229         || defined(CONFIG_SND_BF5XX_SOC_AD183X_MODULE)
230         {
231                 .modalias = "ad183x",
232                 .max_speed_hz = 3125000,     /* max spi clock (SCK) speed in HZ */
233                 .bus_num = 0,
234                 .chip_select = 4,
235         },
236 #endif
237 #if defined(CONFIG_MMC_SPI) || defined(CONFIG_MMC_SPI_MODULE)
238         {
239                 .modalias = "mmc_spi",
240                 .max_speed_hz = 25000000,     /* max spi clock (SCK) speed in HZ */
241                 .bus_num = 0,
242                 .chip_select = 5,
243                 .controller_data = &mmc_spi_chip_info,
244                 .mode = SPI_MODE_3,
245         },
246 #endif
247 #if defined(CONFIG_TOUCHSCREEN_AD7877) || defined(CONFIG_TOUCHSCREEN_AD7877_MODULE)
248 {
249         .modalias               = "ad7877",
250         .platform_data          = &bfin_ad7877_ts_info,
251         .irq                    = IRQ_PF2,
252         .max_speed_hz           = 12500000,     /* max spi clock (SCK) speed in HZ */
253         .bus_num                = 0,
254         .chip_select            = 5,
255 },
256 #endif
257
258 };
259
260 /* SPI (0) */
261 static struct resource bfin_spi0_resource[] = {
262         [0] = {
263                 .start = SPI0_REGBASE,
264                 .end   = SPI0_REGBASE + 0xFF,
265                 .flags = IORESOURCE_MEM,
266                 },
267         [1] = {
268                 .start = CH_SPI,
269                 .end   = CH_SPI,
270                 .flags = IORESOURCE_DMA,
271         },
272         [2] = {
273                 .start = IRQ_SPI,
274                 .end   = IRQ_SPI,
275                 .flags = IORESOURCE_IRQ,
276         },
277 };
278
279 /* SPI controller data */
280 static struct bfin5xx_spi_master bfin_spi0_info = {
281         .num_chipselect = 8,
282         .enable_dma = 1,  /* master has the ability to do dma transfer */
283         .pin_req = {P_SPI0_SCK, P_SPI0_MISO, P_SPI0_MOSI, 0},
284 };
285
286 static struct platform_device bfin_spi0_device = {
287         .name = "bfin-spi",
288         .id = 0, /* Bus number */
289         .num_resources = ARRAY_SIZE(bfin_spi0_resource),
290         .resource = bfin_spi0_resource,
291         .dev = {
292                 .platform_data = &bfin_spi0_info, /* Passed to driver */
293         },
294 };
295 #endif  /* spi master and devices */
296
297 #if defined(CONFIG_FB_BF537_LQ035) || defined(CONFIG_FB_BF537_LQ035_MODULE)
298 static struct platform_device bfin_fb_device = {
299         .name = "bf537-lq035",
300 };
301 #endif
302
303 #if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
304 #ifdef CONFIG_SERIAL_BFIN_UART0
305 static struct resource bfin_uart0_resources[] = {
306         {
307                 .start = UART0_THR,
308                 .end = UART0_GCTL+2,
309                 .flags = IORESOURCE_MEM,
310         },
311         {
312                 .start = IRQ_UART0_RX,
313                 .end = IRQ_UART0_RX+1,
314                 .flags = IORESOURCE_IRQ,
315         },
316         {
317                 .start = IRQ_UART0_ERROR,
318                 .end = IRQ_UART0_ERROR,
319                 .flags = IORESOURCE_IRQ,
320         },
321         {
322                 .start = CH_UART0_TX,
323                 .end = CH_UART0_TX,
324                 .flags = IORESOURCE_DMA,
325         },
326         {
327                 .start = CH_UART0_RX,
328                 .end = CH_UART0_RX,
329                 .flags = IORESOURCE_DMA,
330         },
331 };
332
333 static unsigned short bfin_uart0_peripherals[] = {
334         P_UART0_TX, P_UART0_RX, 0
335 };
336
337 static struct platform_device bfin_uart0_device = {
338         .name = "bfin-uart",
339         .id = 0,
340         .num_resources = ARRAY_SIZE(bfin_uart0_resources),
341         .resource = bfin_uart0_resources,
342         .dev = {
343                 .platform_data = &bfin_uart0_peripherals, /* Passed to driver */
344         },
345 };
346 #endif
347 #ifdef CONFIG_SERIAL_BFIN_UART1
348 static struct resource bfin_uart1_resources[] = {
349         {
350                 .start = UART1_THR,
351                 .end = UART1_GCTL+2,
352                 .flags = IORESOURCE_MEM,
353         },
354         {
355                 .start = IRQ_UART1_RX,
356                 .end = IRQ_UART1_RX+1,
357                 .flags = IORESOURCE_IRQ,
358         },
359         {
360                 .start = IRQ_UART1_ERROR,
361                 .end = IRQ_UART1_ERROR,
362                 .flags = IORESOURCE_IRQ,
363         },
364         {
365                 .start = CH_UART1_TX,
366                 .end = CH_UART1_TX,
367                 .flags = IORESOURCE_DMA,
368         },
369         {
370                 .start = CH_UART1_RX,
371                 .end = CH_UART1_RX,
372                 .flags = IORESOURCE_DMA,
373         },
374 };
375
376 static unsigned short bfin_uart1_peripherals[] = {
377         P_UART1_TX, P_UART1_RX, 0
378 };
379
380 static struct platform_device bfin_uart1_device = {
381         .name = "bfin-uart",
382         .id = 1,
383         .num_resources = ARRAY_SIZE(bfin_uart1_resources),
384         .resource = bfin_uart1_resources,
385         .dev = {
386                 .platform_data = &bfin_uart1_peripherals, /* Passed to driver */
387         },
388 };
389 #endif
390 #endif
391
392 #if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
393 #ifdef CONFIG_BFIN_SIR0
394 static struct resource bfin_sir0_resources[] = {
395         {
396                 .start = 0xFFC00400,
397                 .end = 0xFFC004FF,
398                 .flags = IORESOURCE_MEM,
399         },
400         {
401                 .start = IRQ_UART0_RX,
402                 .end = IRQ_UART0_RX+1,
403                 .flags = IORESOURCE_IRQ,
404         },
405         {
406                 .start = CH_UART0_RX,
407                 .end = CH_UART0_RX+1,
408                 .flags = IORESOURCE_DMA,
409         },
410 };
411
412 static struct platform_device bfin_sir0_device = {
413         .name = "bfin_sir",
414         .id = 0,
415         .num_resources = ARRAY_SIZE(bfin_sir0_resources),
416         .resource = bfin_sir0_resources,
417 };
418 #endif
419 #ifdef CONFIG_BFIN_SIR1
420 static struct resource bfin_sir1_resources[] = {
421         {
422                 .start = 0xFFC02000,
423                 .end = 0xFFC020FF,
424                 .flags = IORESOURCE_MEM,
425         },
426         {
427                 .start = IRQ_UART1_RX,
428                 .end = IRQ_UART1_RX+1,
429                 .flags = IORESOURCE_IRQ,
430         },
431         {
432                 .start = CH_UART1_RX,
433                 .end = CH_UART1_RX+1,
434                 .flags = IORESOURCE_DMA,
435         },
436 };
437
438 static struct platform_device bfin_sir1_device = {
439         .name = "bfin_sir",
440         .id = 1,
441         .num_resources = ARRAY_SIZE(bfin_sir1_resources),
442         .resource = bfin_sir1_resources,
443 };
444 #endif
445 #endif
446
447 static struct platform_device *stamp_devices[] __initdata = {
448 #if defined(CONFIG_BFIN_CFPCMCIA) || defined(CONFIG_BFIN_CFPCMCIA_MODULE)
449         &bfin_pcmcia_cf_device,
450 #endif
451
452 #if defined(CONFIG_RTC_DRV_BFIN) || defined(CONFIG_RTC_DRV_BFIN_MODULE)
453         &rtc_device,
454 #endif
455
456 #if defined(CONFIG_SMC91X) || defined(CONFIG_SMC91X_MODULE)
457         &smc91x_device,
458 #endif
459
460 #if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
461         &bfin_mii_bus,
462         &bfin_mac_device,
463 #endif
464
465 #if defined(CONFIG_USB_NET2272) || defined(CONFIG_USB_NET2272_MODULE)
466         &net2272_bfin_device,
467 #endif
468
469 #if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
470         &bfin_spi0_device,
471 #endif
472
473 #if defined(CONFIG_FB_BF537_LQ035) || defined(CONFIG_FB_BF537_LQ035_MODULE)
474         &bfin_fb_device,
475 #endif
476
477 #if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
478 #ifdef CONFIG_SERIAL_BFIN_UART0
479         &bfin_uart0_device,
480 #endif
481 #ifdef CONFIG_SERIAL_BFIN_UART1
482         &bfin_uart1_device,
483 #endif
484 #endif
485
486 #if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
487 #ifdef CONFIG_BFIN_SIR0
488         &bfin_sir0_device,
489 #endif
490 #ifdef CONFIG_BFIN_SIR1
491         &bfin_sir1_device,
492 #endif
493 #endif
494 };
495
496 static int __init pnav_init(void)
497 {
498         printk(KERN_INFO "%s(): registering device resources\n", __func__);
499         platform_add_devices(stamp_devices, ARRAY_SIZE(stamp_devices));
500 #if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
501         spi_register_board_info(bfin_spi_board_info,
502                                 ARRAY_SIZE(bfin_spi_board_info));
503 #endif
504         return 0;
505 }
506
507 arch_initcall(pnav_init);
508
509 static struct platform_device *stamp_early_devices[] __initdata = {
510 #if defined(CONFIG_SERIAL_BFIN_CONSOLE) || defined(CONFIG_EARLY_PRINTK)
511 #ifdef CONFIG_SERIAL_BFIN_UART0
512         &bfin_uart0_device,
513 #endif
514 #ifdef CONFIG_SERIAL_BFIN_UART1
515         &bfin_uart1_device,
516 #endif
517 #endif
518 };
519
520 void __init native_machine_early_platform_add_devices(void)
521 {
522         printk(KERN_INFO "register early platform devices\n");
523         early_platform_add_devices(stamp_early_devices,
524                 ARRAY_SIZE(stamp_early_devices));
525 }
526
527 void bfin_get_ether_addr(char *addr)
528 {
529         random_ether_addr(addr);
530         printk(KERN_WARNING "%s:%s: Setting Ethernet MAC to a random one\n", __FILE__, __func__);
531 }
532 EXPORT_SYMBOL(bfin_get_ether_addr);