arm64: uaccess: Fix omissions from usercopy whitelist
[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/delay.h>
11 #include <linux/platform_device.h>
12 #include <linux/mtd/mtd.h>
13 #include <linux/mtd/partitions.h>
14 #include <linux/mtd/physmap.h>
15 #include <linux/spi/spi.h>
16 #include <linux/spi/flash.h>
17 #include <linux/spi/mmc_spi.h>
18 #if IS_ENABLED(CONFIG_USB_ISP1362_HCD)
19 #include <linux/usb/isp1362.h>
20 #endif
21 #include <linux/gpio.h>
22 #include <linux/irq.h>
23 #include <linux/i2c.h>
24 #include <linux/gpio/machine.h>
25 #include <asm/dma.h>
26 #include <asm/bfin5xx_spi.h>
27 #include <asm/reboot.h>
28 #include <asm/portmux.h>
29 #include <asm/dpmc.h>
30
31 /*
32  * Name the Board for the /proc/cpuinfo
33  */
34 const char bfin_board_name[] = "ADI BF533-STAMP";
35
36 #if IS_ENABLED(CONFIG_RTC_DRV_BFIN)
37 static struct platform_device rtc_device = {
38         .name = "rtc-bfin",
39         .id   = -1,
40 };
41 #endif
42
43 /*
44  *  Driver needs to know address, irq and flag pin.
45  */
46 #if IS_ENABLED(CONFIG_SMC91X)
47 #include <linux/smc91x.h>
48
49 static struct smc91x_platdata smc91x_info = {
50         .flags = SMC91X_USE_16BIT | SMC91X_NOWAIT,
51         .leda = RPC_LED_100_10,
52         .ledb = RPC_LED_TX_RX,
53 };
54
55 static struct resource smc91x_resources[] = {
56         {
57                 .name = "smc91x-regs",
58                 .start = 0x20300300,
59                 .end = 0x20300300 + 16,
60                 .flags = IORESOURCE_MEM,
61         }, {
62                 .start = IRQ_PF7,
63                 .end = IRQ_PF7,
64                 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL,
65         },
66 };
67
68 static struct platform_device smc91x_device = {
69         .name = "smc91x",
70         .id = 0,
71         .num_resources = ARRAY_SIZE(smc91x_resources),
72         .resource = smc91x_resources,
73         .dev    = {
74                 .platform_data  = &smc91x_info,
75         },
76 };
77 #endif
78
79 #if IS_ENABLED(CONFIG_USB_NET2272)
80 static struct resource net2272_bfin_resources[] = {
81         {
82                 .start = 0x20300000,
83                 .end = 0x20300000 + 0x100,
84                 .flags = IORESOURCE_MEM,
85         }, {
86                 .start = 1,
87                 .flags = IORESOURCE_BUS,
88         }, {
89                 .start = IRQ_PF10,
90                 .end = IRQ_PF10,
91                 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL,
92         },
93 };
94
95 static struct platform_device net2272_bfin_device = {
96         .name = "net2272",
97         .id = -1,
98         .num_resources = ARRAY_SIZE(net2272_bfin_resources),
99         .resource = net2272_bfin_resources,
100 };
101 #endif
102
103 #if IS_ENABLED(CONFIG_MTD_BFIN_ASYNC)
104 static struct mtd_partition stamp_partitions[] = {
105         {
106                 .name   = "bootloader(nor)",
107                 .size   = 0x40000,
108                 .offset = 0,
109         }, {
110                 .name   = "linux kernel(nor)",
111                 .size   = 0x180000,
112                 .offset = MTDPART_OFS_APPEND,
113         }, {
114                 .name   = "file system(nor)",
115                 .size   = MTDPART_SIZ_FULL,
116                 .offset = MTDPART_OFS_APPEND,
117         }
118 };
119
120 static struct physmap_flash_data stamp_flash_data = {
121         .width    = 2,
122         .parts    = stamp_partitions,
123         .nr_parts = ARRAY_SIZE(stamp_partitions),
124 };
125
126 static struct resource stamp_flash_resource[] = {
127         {
128                 .name  = "cfi_probe",
129                 .start = 0x20000000,
130                 .end   = 0x203fffff,
131                 .flags = IORESOURCE_MEM,
132         }, {
133                 .start = 0x7BB07BB0,    /* AMBCTL0 setting when accessing flash */
134                 .end   = 0x7BB07BB0,    /* AMBCTL1 setting when accessing flash */
135                 .flags = IORESOURCE_MEM,
136         }, {
137                 .start = GPIO_PF0,
138                 .flags = IORESOURCE_IRQ,
139         }
140 };
141
142 static struct platform_device stamp_flash_device = {
143         .name          = "bfin-async-flash",
144         .id            = 0,
145         .dev = {
146                 .platform_data = &stamp_flash_data,
147         },
148         .num_resources = ARRAY_SIZE(stamp_flash_resource),
149         .resource      = stamp_flash_resource,
150 };
151 #endif
152
153 #if IS_ENABLED(CONFIG_MTD_M25P80)
154 static struct mtd_partition bfin_spi_flash_partitions[] = {
155         {
156                 .name = "bootloader(spi)",
157                 .size = 0x00040000,
158                 .offset = 0,
159                 .mask_flags = MTD_CAP_ROM
160         }, {
161                 .name = "linux kernel(spi)",
162                 .size = 0x180000,
163                 .offset = MTDPART_OFS_APPEND,
164         }, {
165                 .name = "file system(spi)",
166                 .size = MTDPART_SIZ_FULL,
167                 .offset = MTDPART_OFS_APPEND,
168         }
169 };
170
171 static struct flash_platform_data bfin_spi_flash_data = {
172         .name = "m25p80",
173         .parts = bfin_spi_flash_partitions,
174         .nr_parts = ARRAY_SIZE(bfin_spi_flash_partitions),
175         .type = "m25p64",
176 };
177
178 /* SPI flash chip (m25p64) */
179 static struct bfin5xx_spi_chip spi_flash_chip_info = {
180         .enable_dma = 0,         /* use dma transfer with this chip*/
181 };
182 #endif
183
184 #if IS_ENABLED(CONFIG_MMC_SPI)
185 #define MMC_SPI_CARD_DETECT_INT IRQ_PF5
186 static int bfin_mmc_spi_init(struct device *dev,
187         irqreturn_t (*detect_int)(int, void *), void *data)
188 {
189         return request_irq(MMC_SPI_CARD_DETECT_INT, detect_int,
190                 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
191                 "mmc-spi-detect", data);
192 }
193
194 static void bfin_mmc_spi_exit(struct device *dev, void *data)
195 {
196         free_irq(MMC_SPI_CARD_DETECT_INT, data);
197 }
198
199 static struct mmc_spi_platform_data bfin_mmc_spi_pdata = {
200         .init = bfin_mmc_spi_init,
201         .exit = bfin_mmc_spi_exit,
202         .detect_delay = 100, /* msecs */
203 };
204
205 static struct bfin5xx_spi_chip  mmc_spi_chip_info = {
206         .enable_dma = 0,
207         .pio_interrupt = 0,
208 };
209 #endif
210
211 static struct spi_board_info bfin_spi_board_info[] __initdata = {
212 #if IS_ENABLED(CONFIG_MTD_M25P80)
213         {
214                 /* the modalias must be the same as spi device driver name */
215                 .modalias = "m25p80", /* Name of spi_driver for this device */
216                 .max_speed_hz = 25000000,     /* max spi clock (SCK) speed in HZ */
217                 .bus_num = 0, /* Framework bus number */
218                 .chip_select = 2, /* Framework chip select. On STAMP537 it is SPISSEL2*/
219                 .platform_data = &bfin_spi_flash_data,
220                 .controller_data = &spi_flash_chip_info,
221                 .mode = SPI_MODE_3,
222         },
223 #endif
224
225 #if IS_ENABLED(CONFIG_SND_BF5XX_SOC_AD1836)
226         {
227                 .modalias = "ad1836",
228                 .max_speed_hz = 3125000,     /* max spi clock (SCK) speed in HZ */
229                 .bus_num = 0,
230                 .chip_select = 4,
231                 .platform_data = "ad1836", /* only includes chip name for the moment */
232                 .mode = SPI_MODE_3,
233         },
234 #endif
235
236 #if IS_ENABLED(CONFIG_SPI_SPIDEV)
237         {
238                 .modalias = "spidev",
239                 .max_speed_hz = 3125000,     /* max spi clock (SCK) speed in HZ */
240                 .bus_num = 0,
241                 .chip_select = 1,
242         },
243 #endif
244 #if IS_ENABLED(CONFIG_MMC_SPI)
245         {
246                 .modalias = "mmc_spi",
247                 .max_speed_hz = 20000000,     /* max spi clock (SCK) speed in HZ */
248                 .bus_num = 0,
249                 .chip_select = 4,
250                 .platform_data = &bfin_mmc_spi_pdata,
251                 .controller_data = &mmc_spi_chip_info,
252                 .mode = SPI_MODE_3,
253         },
254 #endif
255 };
256
257 #if IS_ENABLED(CONFIG_SPI_BFIN5XX)
258 /* SPI (0) */
259 static struct resource bfin_spi0_resource[] = {
260         [0] = {
261                 .start = SPI0_REGBASE,
262                 .end   = SPI0_REGBASE + 0xFF,
263                 .flags = IORESOURCE_MEM,
264         },
265         [1] = {
266                 .start = CH_SPI,
267                 .end   = CH_SPI,
268                 .flags = IORESOURCE_DMA,
269         },
270         [2] = {
271                 .start = IRQ_SPI,
272                 .end   = IRQ_SPI,
273                 .flags = IORESOURCE_IRQ,
274         }
275 };
276
277 /* SPI controller data */
278 static struct bfin5xx_spi_master bfin_spi0_info = {
279         .num_chipselect = 8,
280         .enable_dma = 1,  /* master has the ability to do dma transfer */
281         .pin_req = {P_SPI0_SCK, P_SPI0_MISO, P_SPI0_MOSI, 0},
282 };
283
284 static struct platform_device bfin_spi0_device = {
285         .name = "bfin-spi",
286         .id = 0, /* Bus number */
287         .num_resources = ARRAY_SIZE(bfin_spi0_resource),
288         .resource = bfin_spi0_resource,
289         .dev = {
290                 .platform_data = &bfin_spi0_info, /* Passed to driver */
291         },
292 };
293 #endif  /* spi master and devices */
294
295 #if IS_ENABLED(CONFIG_SERIAL_BFIN)
296 #ifdef CONFIG_SERIAL_BFIN_UART0
297 static struct resource bfin_uart0_resources[] = {
298         {
299                 .start = BFIN_UART_THR,
300                 .end = BFIN_UART_GCTL+2,
301                 .flags = IORESOURCE_MEM,
302         },
303         {
304                 .start = IRQ_UART0_TX,
305                 .end = IRQ_UART0_TX,
306                 .flags = IORESOURCE_IRQ,
307         },
308         {
309                 .start = IRQ_UART0_RX,
310                 .end = IRQ_UART0_RX,
311                 .flags = IORESOURCE_IRQ,
312         },
313         {
314                 .start = IRQ_UART0_ERROR,
315                 .end = IRQ_UART0_ERROR,
316                 .flags = IORESOURCE_IRQ,
317         },
318         {
319                 .start = CH_UART0_TX,
320                 .end = CH_UART0_TX,
321                 .flags = IORESOURCE_DMA,
322         },
323         {
324                 .start = CH_UART0_RX,
325                 .end = CH_UART0_RX,
326                 .flags = IORESOURCE_DMA,
327         },
328 };
329
330 static unsigned short bfin_uart0_peripherals[] = {
331         P_UART0_TX, P_UART0_RX, 0
332 };
333
334 static struct platform_device bfin_uart0_device = {
335         .name = "bfin-uart",
336         .id = 0,
337         .num_resources = ARRAY_SIZE(bfin_uart0_resources),
338         .resource = bfin_uart0_resources,
339         .dev = {
340                 .platform_data = &bfin_uart0_peripherals, /* Passed to driver */
341         },
342 };
343 #endif
344 #endif
345
346 #if IS_ENABLED(CONFIG_BFIN_SIR)
347 #ifdef CONFIG_BFIN_SIR0
348 static struct resource bfin_sir0_resources[] = {
349         {
350                 .start = 0xFFC00400,
351                 .end = 0xFFC004FF,
352                 .flags = IORESOURCE_MEM,
353         },
354         {
355                 .start = IRQ_UART0_RX,
356                 .end = IRQ_UART0_RX+1,
357                 .flags = IORESOURCE_IRQ,
358         },
359         {
360                 .start = CH_UART0_RX,
361                 .end = CH_UART0_RX+1,
362                 .flags = IORESOURCE_DMA,
363         },
364 };
365
366 static struct platform_device bfin_sir0_device = {
367         .name = "bfin_sir",
368         .id = 0,
369         .num_resources = ARRAY_SIZE(bfin_sir0_resources),
370         .resource = bfin_sir0_resources,
371 };
372 #endif
373 #endif
374
375 #if IS_ENABLED(CONFIG_SERIAL_BFIN_SPORT)
376 #ifdef CONFIG_SERIAL_BFIN_SPORT0_UART
377 static struct resource bfin_sport0_uart_resources[] = {
378         {
379                 .start = SPORT0_TCR1,
380                 .end = SPORT0_MRCS3+4,
381                 .flags = IORESOURCE_MEM,
382         },
383         {
384                 .start = IRQ_SPORT0_RX,
385                 .end = IRQ_SPORT0_RX+1,
386                 .flags = IORESOURCE_IRQ,
387         },
388         {
389                 .start = IRQ_SPORT0_ERROR,
390                 .end = IRQ_SPORT0_ERROR,
391                 .flags = IORESOURCE_IRQ,
392         },
393 };
394
395 static unsigned short bfin_sport0_peripherals[] = {
396         P_SPORT0_TFS, P_SPORT0_DTPRI, P_SPORT0_TSCLK, P_SPORT0_RFS,
397         P_SPORT0_DRPRI, P_SPORT0_RSCLK, 0
398 };
399
400 static struct platform_device bfin_sport0_uart_device = {
401         .name = "bfin-sport-uart",
402         .id = 0,
403         .num_resources = ARRAY_SIZE(bfin_sport0_uart_resources),
404         .resource = bfin_sport0_uart_resources,
405         .dev = {
406                 .platform_data = &bfin_sport0_peripherals, /* Passed to driver */
407         },
408 };
409 #endif
410 #ifdef CONFIG_SERIAL_BFIN_SPORT1_UART
411 static struct resource bfin_sport1_uart_resources[] = {
412         {
413                 .start = SPORT1_TCR1,
414                 .end = SPORT1_MRCS3+4,
415                 .flags = IORESOURCE_MEM,
416         },
417         {
418                 .start = IRQ_SPORT1_RX,
419                 .end = IRQ_SPORT1_RX+1,
420                 .flags = IORESOURCE_IRQ,
421         },
422         {
423                 .start = IRQ_SPORT1_ERROR,
424                 .end = IRQ_SPORT1_ERROR,
425                 .flags = IORESOURCE_IRQ,
426         },
427 };
428
429 static unsigned short bfin_sport1_peripherals[] = {
430         P_SPORT1_TFS, P_SPORT1_DTPRI, P_SPORT1_TSCLK, P_SPORT1_RFS,
431         P_SPORT1_DRPRI, P_SPORT1_RSCLK, 0
432 };
433
434 static struct platform_device bfin_sport1_uart_device = {
435         .name = "bfin-sport-uart",
436         .id = 1,
437         .num_resources = ARRAY_SIZE(bfin_sport1_uart_resources),
438         .resource = bfin_sport1_uart_resources,
439         .dev = {
440                 .platform_data = &bfin_sport1_peripherals, /* Passed to driver */
441         },
442 };
443 #endif
444 #endif
445
446 #if IS_ENABLED(CONFIG_BFIN_SPORT)
447 static struct resource bfin_sport0_resources[] = {
448         {
449                 .start = SPORT0_TCR1,
450                 .end = SPORT0_MRCS3+4,
451                 .flags = IORESOURCE_MEM,
452         },
453         {
454                 .start = IRQ_SPORT0_TX,
455                 .end = IRQ_SPORT0_TX+1,
456                 .flags = IORESOURCE_IRQ,
457         },
458         {
459                 .start = IRQ_SPORT0_RX,
460                 .end = IRQ_SPORT0_RX+1,
461                 .flags = IORESOURCE_IRQ,
462         },
463         {
464                 .start = IRQ_SPORT0_ERROR,
465                 .end = IRQ_SPORT0_ERROR,
466                 .flags = IORESOURCE_IRQ,
467         },
468         {
469                 .start = CH_SPORT0_TX,
470                 .end = CH_SPORT0_TX,
471                 .flags = IORESOURCE_DMA,
472         },
473         {
474                 .start = CH_SPORT0_RX,
475                 .end = CH_SPORT0_RX,
476                 .flags = IORESOURCE_DMA,
477         },
478 };
479 static struct platform_device bfin_sport0_device = {
480         .name = "bfin_sport_raw",
481         .id = 0,
482         .num_resources = ARRAY_SIZE(bfin_sport0_resources),
483         .resource = bfin_sport0_resources,
484         .dev = {
485                 .platform_data = &bfin_sport0_peripherals,
486         },
487 };
488 #endif
489
490 #if IS_ENABLED(CONFIG_KEYBOARD_GPIO)
491 #include <linux/input.h>
492 #include <linux/gpio_keys.h>
493
494 static struct gpio_keys_button bfin_gpio_keys_table[] = {
495         {BTN_0, GPIO_PF5, 0, "gpio-keys: BTN0"},
496         {BTN_1, GPIO_PF6, 0, "gpio-keys: BTN1"},
497         {BTN_2, GPIO_PF8, 0, "gpio-keys: BTN2"},
498 };
499
500 static struct gpio_keys_platform_data bfin_gpio_keys_data = {
501         .buttons        = bfin_gpio_keys_table,
502         .nbuttons       = ARRAY_SIZE(bfin_gpio_keys_table),
503 };
504
505 static struct platform_device bfin_device_gpiokeys = {
506         .name      = "gpio-keys",
507         .dev = {
508                 .platform_data = &bfin_gpio_keys_data,
509         },
510 };
511 #endif
512
513 #if IS_ENABLED(CONFIG_I2C_GPIO)
514 #include <linux/i2c-gpio.h>
515
516 static struct gpiod_lookup_table bfin_i2c_gpiod_table = {
517         .dev_id = "i2c-gpio",
518         .table = {
519                 GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF2, NULL, 0,
520                                 GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
521                 GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF3, NULL, 1,
522                                 GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
523         },
524 };
525
526 static struct i2c_gpio_platform_data i2c_gpio_data = {
527         .udelay                 = 10,
528 };
529
530 static struct platform_device i2c_gpio_device = {
531         .name           = "i2c-gpio",
532         .id             = 0,
533         .dev            = {
534                 .platform_data  = &i2c_gpio_data,
535         },
536 };
537 #endif
538
539 static struct i2c_board_info __initdata bfin_i2c_board_info[] = {
540 #if IS_ENABLED(CONFIG_JOYSTICK_AD7142)
541         {
542                 I2C_BOARD_INFO("ad7142_joystick", 0x2C),
543                 .irq = 39,
544         },
545 #endif
546 #if IS_ENABLED(CONFIG_BFIN_TWI_LCD)
547         {
548                 I2C_BOARD_INFO("pcf8574_lcd", 0x22),
549         },
550 #endif
551 #if IS_ENABLED(CONFIG_INPUT_PCF8574)
552         {
553                 I2C_BOARD_INFO("pcf8574_keypad", 0x27),
554                 .irq = 39,
555         },
556 #endif
557 #if IS_ENABLED(CONFIG_FB_BFIN_7393)
558         {
559                 I2C_BOARD_INFO("bfin-adv7393", 0x2B),
560         },
561 #endif
562 #if IS_ENABLED(CONFIG_BFIN_TWI_LCD)
563         {
564                 I2C_BOARD_INFO("ad5252", 0x2f),
565         },
566 #endif
567 };
568
569 static const unsigned int cclk_vlev_datasheet[] =
570 {
571         VRPAIR(VLEV_085, 250000000),
572         VRPAIR(VLEV_090, 376000000),
573         VRPAIR(VLEV_095, 426000000),
574         VRPAIR(VLEV_100, 426000000),
575         VRPAIR(VLEV_105, 476000000),
576         VRPAIR(VLEV_110, 476000000),
577         VRPAIR(VLEV_115, 476000000),
578         VRPAIR(VLEV_120, 600000000),
579         VRPAIR(VLEV_125, 600000000),
580         VRPAIR(VLEV_130, 600000000),
581 };
582
583 static struct bfin_dpmc_platform_data bfin_dmpc_vreg_data = {
584         .tuple_tab = cclk_vlev_datasheet,
585         .tabsize = ARRAY_SIZE(cclk_vlev_datasheet),
586         .vr_settling_time = 25 /* us */,
587 };
588
589 static struct platform_device bfin_dpmc = {
590         .name = "bfin dpmc",
591         .dev = {
592                 .platform_data = &bfin_dmpc_vreg_data,
593         },
594 };
595
596 #if IS_ENABLED(CONFIG_SND_BF5XX_I2S) || \
597         IS_ENABLED(CONFIG_SND_BF5XX_AC97)
598
599 #include <asm/bfin_sport.h>
600
601 #define SPORT_REQ(x) \
602         [x] = {P_SPORT##x##_TFS, P_SPORT##x##_DTPRI, P_SPORT##x##_TSCLK, \
603                 P_SPORT##x##_RFS, P_SPORT##x##_DRPRI, P_SPORT##x##_RSCLK, 0}
604
605 static const u16 bfin_snd_pin[][7] = {
606         SPORT_REQ(0),
607         SPORT_REQ(1),
608 };
609
610 static struct bfin_snd_platform_data bfin_snd_data[] = {
611         {
612                 .pin_req = &bfin_snd_pin[0][0],
613         },
614         {
615                 .pin_req = &bfin_snd_pin[1][0],
616         },
617 };
618
619 #define BFIN_SND_RES(x) \
620         [x] = { \
621                 { \
622                         .start = SPORT##x##_TCR1, \
623                         .end = SPORT##x##_TCR1, \
624                         .flags = IORESOURCE_MEM \
625                 }, \
626                 { \
627                         .start = CH_SPORT##x##_RX, \
628                         .end = CH_SPORT##x##_RX, \
629                         .flags = IORESOURCE_DMA, \
630                 }, \
631                 { \
632                         .start = CH_SPORT##x##_TX, \
633                         .end = CH_SPORT##x##_TX, \
634                         .flags = IORESOURCE_DMA, \
635                 }, \
636                 { \
637                         .start = IRQ_SPORT##x##_ERROR, \
638                         .end = IRQ_SPORT##x##_ERROR, \
639                         .flags = IORESOURCE_IRQ, \
640                 } \
641         }
642
643 static struct resource bfin_snd_resources[][4] = {
644         BFIN_SND_RES(0),
645         BFIN_SND_RES(1),
646 };
647 #endif
648
649 #if IS_ENABLED(CONFIG_SND_BF5XX_I2S)
650 static struct platform_device bfin_i2s_pcm = {
651         .name = "bfin-i2s-pcm-audio",
652         .id = -1,
653 };
654 #endif
655
656 #if IS_ENABLED(CONFIG_SND_BF5XX_AC97)
657 static struct platform_device bfin_ac97_pcm = {
658         .name = "bfin-ac97-pcm-audio",
659         .id = -1,
660 };
661 #endif
662
663 #if IS_ENABLED(CONFIG_SND_BF5XX_SOC_AD1836)
664 static const char * const ad1836_link[] = {
665         "bfin-i2s.0",
666         "spi0.4",
667 };
668 static struct platform_device bfin_ad1836_machine = {
669         .name = "bfin-snd-ad1836",
670         .id = -1,
671         .dev = {
672                 .platform_data = (void *)ad1836_link,
673         },
674 };
675 #endif
676
677 #if IS_ENABLED(CONFIG_SND_BF5XX_SOC_AD73311)
678 static const unsigned ad73311_gpio[] = {
679         GPIO_PF4,
680 };
681
682 static struct platform_device bfin_ad73311_machine = {
683         .name = "bfin-snd-ad73311",
684         .id = 1,
685         .dev = {
686                 .platform_data = (void *)ad73311_gpio,
687         },
688 };
689 #endif
690
691 #if IS_ENABLED(CONFIG_SND_SOC_AD73311)
692 static struct platform_device bfin_ad73311_codec_device = {
693         .name = "ad73311",
694         .id = -1,
695 };
696 #endif
697
698 #if IS_ENABLED(CONFIG_SND_SOC_AD74111)
699 static struct platform_device bfin_ad74111_codec_device = {
700         .name = "ad74111",
701         .id = -1,
702 };
703 #endif
704
705 #if IS_ENABLED(CONFIG_SND_BF5XX_SOC_I2S)
706 static struct platform_device bfin_i2s = {
707         .name = "bfin-i2s",
708         .id = CONFIG_SND_BF5XX_SPORT_NUM,
709         .num_resources =
710                 ARRAY_SIZE(bfin_snd_resources[CONFIG_SND_BF5XX_SPORT_NUM]),
711         .resource = bfin_snd_resources[CONFIG_SND_BF5XX_SPORT_NUM],
712         .dev = {
713                 .platform_data = &bfin_snd_data[CONFIG_SND_BF5XX_SPORT_NUM],
714         },
715 };
716 #endif
717
718 #if IS_ENABLED(CONFIG_SND_BF5XX_SOC_AC97)
719 static struct platform_device bfin_ac97 = {
720         .name = "bfin-ac97",
721         .id = CONFIG_SND_BF5XX_SPORT_NUM,
722         .num_resources =
723                 ARRAY_SIZE(bfin_snd_resources[CONFIG_SND_BF5XX_SPORT_NUM]),
724         .resource = bfin_snd_resources[CONFIG_SND_BF5XX_SPORT_NUM],
725         .dev = {
726                 .platform_data = &bfin_snd_data[CONFIG_SND_BF5XX_SPORT_NUM],
727         },
728 };
729 #endif
730
731 static struct platform_device *stamp_devices[] __initdata = {
732
733         &bfin_dpmc,
734
735 #if IS_ENABLED(CONFIG_RTC_DRV_BFIN)
736         &rtc_device,
737 #endif
738
739 #if IS_ENABLED(CONFIG_SMC91X)
740         &smc91x_device,
741 #endif
742
743 #if IS_ENABLED(CONFIG_USB_NET2272)
744         &net2272_bfin_device,
745 #endif
746
747 #if IS_ENABLED(CONFIG_SPI_BFIN5XX)
748         &bfin_spi0_device,
749 #endif
750
751 #if IS_ENABLED(CONFIG_SERIAL_BFIN)
752 #ifdef CONFIG_SERIAL_BFIN_UART0
753         &bfin_uart0_device,
754 #endif
755 #endif
756
757 #if IS_ENABLED(CONFIG_BFIN_SIR)
758 #ifdef CONFIG_BFIN_SIR0
759         &bfin_sir0_device,
760 #endif
761 #endif
762
763 #if IS_ENABLED(CONFIG_SERIAL_BFIN_SPORT)
764 #ifdef CONFIG_SERIAL_BFIN_SPORT0_UART
765         &bfin_sport0_uart_device,
766 #endif
767 #ifdef CONFIG_SERIAL_BFIN_SPORT1_UART
768         &bfin_sport1_uart_device,
769 #endif
770 #endif
771
772 #if IS_ENABLED(CONFIG_KEYBOARD_GPIO)
773         &bfin_device_gpiokeys,
774 #endif
775
776 #if IS_ENABLED(CONFIG_I2C_GPIO)
777         &i2c_gpio_device,
778 #endif
779
780 #if IS_ENABLED(CONFIG_MTD_BFIN_ASYNC)
781         &stamp_flash_device,
782 #endif
783
784 #if IS_ENABLED(CONFIG_SND_BF5XX_I2S)
785         &bfin_i2s_pcm,
786 #endif
787
788 #if IS_ENABLED(CONFIG_SND_BF5XX_AC97)
789         &bfin_ac97_pcm,
790 #endif
791
792 #if IS_ENABLED(CONFIG_SND_BF5XX_SOC_AD1836)
793         &bfin_ad1836_machine,
794 #endif
795
796 #if IS_ENABLED(CONFIG_SND_BF5XX_SOC_AD73311)
797         &bfin_ad73311_machine,
798 #endif
799
800 #if IS_ENABLED(CONFIG_SND_SOC_AD73311)
801         &bfin_ad73311_codec_device,
802 #endif
803
804 #if IS_ENABLED(CONFIG_SND_SOC_AD74111)
805         &bfin_ad74111_codec_device,
806 #endif
807
808 #if IS_ENABLED(CONFIG_SND_BF5XX_SOC_I2S)
809         &bfin_i2s,
810 #endif
811
812 #if IS_ENABLED(CONFIG_SND_BF5XX_SOC_AC97)
813         &bfin_ac97,
814 #endif
815 };
816
817 static int __init net2272_init(void)
818 {
819 #if IS_ENABLED(CONFIG_USB_NET2272)
820         int ret;
821
822         /* Set PF0 to 0, PF1 to 1 make /AMS3 work properly */
823         ret = gpio_request(GPIO_PF0, "net2272");
824         if (ret)
825                 return ret;
826
827         ret = gpio_request(GPIO_PF1, "net2272");
828         if (ret) {
829                 gpio_free(GPIO_PF0);
830                 return ret;
831         }
832
833         ret = gpio_request(GPIO_PF11, "net2272");
834         if (ret) {
835                 gpio_free(GPIO_PF0);
836                 gpio_free(GPIO_PF1);
837                 return ret;
838         }
839
840         gpio_direction_output(GPIO_PF0, 0);
841         gpio_direction_output(GPIO_PF1, 1);
842
843         /* Reset the USB chip */
844         gpio_direction_output(GPIO_PF11, 0);
845         mdelay(2);
846         gpio_set_value(GPIO_PF11, 1);
847 #endif
848
849         return 0;
850 }
851
852 static int __init stamp_init(void)
853 {
854         int ret;
855
856         printk(KERN_INFO "%s(): registering device resources\n", __func__);
857
858 #if IS_ENABLED(CONFIG_I2C_GPIO)
859         gpiod_add_lookup_table(&bfin_i2c_gpiod_table);
860 #endif
861         i2c_register_board_info(0, bfin_i2c_board_info,
862                                 ARRAY_SIZE(bfin_i2c_board_info));
863
864         ret = platform_add_devices(stamp_devices, ARRAY_SIZE(stamp_devices));
865         if (ret < 0)
866                 return ret;
867
868 #if IS_ENABLED(CONFIG_SMC91X)
869         /*
870          * setup BF533_STAMP CPLD to route AMS3 to Ethernet MAC.
871          * the bfin-async-map driver takes care of flipping between
872          * flash and ethernet when necessary.
873          */
874         ret = gpio_request(GPIO_PF0, "enet_cpld");
875         if (!ret) {
876                 gpio_direction_output(GPIO_PF0, 1);
877                 gpio_free(GPIO_PF0);
878         }
879 #endif
880
881         if (net2272_init())
882                 pr_warning("unable to configure net2272; it probably won't work\n");
883
884         spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info));
885         return 0;
886 }
887
888 arch_initcall(stamp_init);
889
890 static struct platform_device *stamp_early_devices[] __initdata = {
891 #if defined(CONFIG_SERIAL_BFIN_CONSOLE) || defined(CONFIG_EARLY_PRINTK)
892 #ifdef CONFIG_SERIAL_BFIN_UART0
893         &bfin_uart0_device,
894 #endif
895 #endif
896
897 #if defined(CONFIG_SERIAL_BFIN_SPORT_CONSOLE)
898 #ifdef CONFIG_SERIAL_BFIN_SPORT0_UART
899         &bfin_sport0_uart_device,
900 #endif
901 #ifdef CONFIG_SERIAL_BFIN_SPORT1_UART
902         &bfin_sport1_uart_device,
903 #endif
904 #endif
905 };
906
907 void __init native_machine_early_platform_add_devices(void)
908 {
909         printk(KERN_INFO "register early platform devices\n");
910         early_platform_add_devices(stamp_early_devices,
911                 ARRAY_SIZE(stamp_early_devices));
912 }
913
914 void native_machine_restart(char *cmd)
915 {
916         /* workaround pull up on cpld / flash pin not being strong enough */
917         gpio_request(GPIO_PF0, "flash_cpld");
918         gpio_direction_output(GPIO_PF0, 0);
919 }