2 * Copyright 2004-2009 Analog Devices Inc.
3 * 2005 National ICT Australia (NICTA)
4 * Aidan Williams <aidan@nicta.com.au>
6 * Licensed under the GPL-2 or later.
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 IS_ENABLED(CONFIG_USB_ISP1362_HCD)
18 #include <linux/usb/isp1362.h>
20 #include <linux/gpio.h>
21 #include <linux/irq.h>
22 #include <linux/i2c.h>
24 #include <asm/bfin5xx_spi.h>
25 #include <asm/reboot.h>
26 #include <asm/portmux.h>
30 * Name the Board for the /proc/cpuinfo
32 const char bfin_board_name[] = "ADI BF533-STAMP";
34 #if IS_ENABLED(CONFIG_RTC_DRV_BFIN)
35 static struct platform_device rtc_device = {
42 * Driver needs to know address, irq and flag pin.
44 #if IS_ENABLED(CONFIG_SMC91X)
45 #include <linux/smc91x.h>
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,
53 static struct resource smc91x_resources[] = {
55 .name = "smc91x-regs",
57 .end = 0x20300300 + 16,
58 .flags = IORESOURCE_MEM,
62 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL,
66 static struct platform_device smc91x_device = {
69 .num_resources = ARRAY_SIZE(smc91x_resources),
70 .resource = smc91x_resources,
72 .platform_data = &smc91x_info,
77 #if IS_ENABLED(CONFIG_USB_NET2272)
78 static struct resource net2272_bfin_resources[] = {
81 .end = 0x20300000 + 0x100,
82 .flags = IORESOURCE_MEM,
85 .flags = IORESOURCE_BUS,
89 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL,
93 static struct platform_device net2272_bfin_device = {
96 .num_resources = ARRAY_SIZE(net2272_bfin_resources),
97 .resource = net2272_bfin_resources,
101 #if IS_ENABLED(CONFIG_MTD_BFIN_ASYNC)
102 static struct mtd_partition stamp_partitions[] = {
104 .name = "bootloader(nor)",
108 .name = "linux kernel(nor)",
110 .offset = MTDPART_OFS_APPEND,
112 .name = "file system(nor)",
113 .size = MTDPART_SIZ_FULL,
114 .offset = MTDPART_OFS_APPEND,
118 static struct physmap_flash_data stamp_flash_data = {
120 .parts = stamp_partitions,
121 .nr_parts = ARRAY_SIZE(stamp_partitions),
124 static struct resource stamp_flash_resource[] = {
129 .flags = IORESOURCE_MEM,
131 .start = 0x7BB07BB0, /* AMBCTL0 setting when accessing flash */
132 .end = 0x7BB07BB0, /* AMBCTL1 setting when accessing flash */
133 .flags = IORESOURCE_MEM,
136 .flags = IORESOURCE_IRQ,
140 static struct platform_device stamp_flash_device = {
141 .name = "bfin-async-flash",
144 .platform_data = &stamp_flash_data,
146 .num_resources = ARRAY_SIZE(stamp_flash_resource),
147 .resource = stamp_flash_resource,
151 #if IS_ENABLED(CONFIG_MTD_M25P80)
152 static struct mtd_partition bfin_spi_flash_partitions[] = {
154 .name = "bootloader(spi)",
157 .mask_flags = MTD_CAP_ROM
159 .name = "linux kernel(spi)",
161 .offset = MTDPART_OFS_APPEND,
163 .name = "file system(spi)",
164 .size = MTDPART_SIZ_FULL,
165 .offset = MTDPART_OFS_APPEND,
169 static struct flash_platform_data bfin_spi_flash_data = {
171 .parts = bfin_spi_flash_partitions,
172 .nr_parts = ARRAY_SIZE(bfin_spi_flash_partitions),
176 /* SPI flash chip (m25p64) */
177 static struct bfin5xx_spi_chip spi_flash_chip_info = {
178 .enable_dma = 0, /* use dma transfer with this chip*/
182 #if IS_ENABLED(CONFIG_MMC_SPI)
183 #define MMC_SPI_CARD_DETECT_INT IRQ_PF5
184 static int bfin_mmc_spi_init(struct device *dev,
185 irqreturn_t (*detect_int)(int, void *), void *data)
187 return request_irq(MMC_SPI_CARD_DETECT_INT, detect_int,
188 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
189 "mmc-spi-detect", data);
192 static void bfin_mmc_spi_exit(struct device *dev, void *data)
194 free_irq(MMC_SPI_CARD_DETECT_INT, data);
197 static struct mmc_spi_platform_data bfin_mmc_spi_pdata = {
198 .init = bfin_mmc_spi_init,
199 .exit = bfin_mmc_spi_exit,
200 .detect_delay = 100, /* msecs */
203 static struct bfin5xx_spi_chip mmc_spi_chip_info = {
209 static struct spi_board_info bfin_spi_board_info[] __initdata = {
210 #if IS_ENABLED(CONFIG_MTD_M25P80)
212 /* the modalias must be the same as spi device driver name */
213 .modalias = "m25p80", /* Name of spi_driver for this device */
214 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */
215 .bus_num = 0, /* Framework bus number */
216 .chip_select = 2, /* Framework chip select. On STAMP537 it is SPISSEL2*/
217 .platform_data = &bfin_spi_flash_data,
218 .controller_data = &spi_flash_chip_info,
223 #if IS_ENABLED(CONFIG_SND_BF5XX_SOC_AD1836)
225 .modalias = "ad1836",
226 .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */
229 .platform_data = "ad1836", /* only includes chip name for the moment */
234 #if IS_ENABLED(CONFIG_SPI_SPIDEV)
236 .modalias = "spidev",
237 .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */
242 #if IS_ENABLED(CONFIG_MMC_SPI)
244 .modalias = "mmc_spi",
245 .max_speed_hz = 20000000, /* max spi clock (SCK) speed in HZ */
248 .platform_data = &bfin_mmc_spi_pdata,
249 .controller_data = &mmc_spi_chip_info,
255 #if IS_ENABLED(CONFIG_SPI_BFIN5XX)
257 static struct resource bfin_spi0_resource[] = {
259 .start = SPI0_REGBASE,
260 .end = SPI0_REGBASE + 0xFF,
261 .flags = IORESOURCE_MEM,
266 .flags = IORESOURCE_DMA,
271 .flags = IORESOURCE_IRQ,
275 /* SPI controller data */
276 static struct bfin5xx_spi_master bfin_spi0_info = {
278 .enable_dma = 1, /* master has the ability to do dma transfer */
279 .pin_req = {P_SPI0_SCK, P_SPI0_MISO, P_SPI0_MOSI, 0},
282 static struct platform_device bfin_spi0_device = {
284 .id = 0, /* Bus number */
285 .num_resources = ARRAY_SIZE(bfin_spi0_resource),
286 .resource = bfin_spi0_resource,
288 .platform_data = &bfin_spi0_info, /* Passed to driver */
291 #endif /* spi master and devices */
293 #if IS_ENABLED(CONFIG_SERIAL_BFIN)
294 #ifdef CONFIG_SERIAL_BFIN_UART0
295 static struct resource bfin_uart0_resources[] = {
297 .start = BFIN_UART_THR,
298 .end = BFIN_UART_GCTL+2,
299 .flags = IORESOURCE_MEM,
302 .start = IRQ_UART0_TX,
304 .flags = IORESOURCE_IRQ,
307 .start = IRQ_UART0_RX,
309 .flags = IORESOURCE_IRQ,
312 .start = IRQ_UART0_ERROR,
313 .end = IRQ_UART0_ERROR,
314 .flags = IORESOURCE_IRQ,
317 .start = CH_UART0_TX,
319 .flags = IORESOURCE_DMA,
322 .start = CH_UART0_RX,
324 .flags = IORESOURCE_DMA,
328 static unsigned short bfin_uart0_peripherals[] = {
329 P_UART0_TX, P_UART0_RX, 0
332 static struct platform_device bfin_uart0_device = {
335 .num_resources = ARRAY_SIZE(bfin_uart0_resources),
336 .resource = bfin_uart0_resources,
338 .platform_data = &bfin_uart0_peripherals, /* Passed to driver */
344 #if IS_ENABLED(CONFIG_BFIN_SIR)
345 #ifdef CONFIG_BFIN_SIR0
346 static struct resource bfin_sir0_resources[] = {
350 .flags = IORESOURCE_MEM,
353 .start = IRQ_UART0_RX,
354 .end = IRQ_UART0_RX+1,
355 .flags = IORESOURCE_IRQ,
358 .start = CH_UART0_RX,
359 .end = CH_UART0_RX+1,
360 .flags = IORESOURCE_DMA,
364 static struct platform_device bfin_sir0_device = {
367 .num_resources = ARRAY_SIZE(bfin_sir0_resources),
368 .resource = bfin_sir0_resources,
373 #if IS_ENABLED(CONFIG_SERIAL_BFIN_SPORT)
374 #ifdef CONFIG_SERIAL_BFIN_SPORT0_UART
375 static struct resource bfin_sport0_uart_resources[] = {
377 .start = SPORT0_TCR1,
378 .end = SPORT0_MRCS3+4,
379 .flags = IORESOURCE_MEM,
382 .start = IRQ_SPORT0_RX,
383 .end = IRQ_SPORT0_RX+1,
384 .flags = IORESOURCE_IRQ,
387 .start = IRQ_SPORT0_ERROR,
388 .end = IRQ_SPORT0_ERROR,
389 .flags = IORESOURCE_IRQ,
393 static unsigned short bfin_sport0_peripherals[] = {
394 P_SPORT0_TFS, P_SPORT0_DTPRI, P_SPORT0_TSCLK, P_SPORT0_RFS,
395 P_SPORT0_DRPRI, P_SPORT0_RSCLK, 0
398 static struct platform_device bfin_sport0_uart_device = {
399 .name = "bfin-sport-uart",
401 .num_resources = ARRAY_SIZE(bfin_sport0_uart_resources),
402 .resource = bfin_sport0_uart_resources,
404 .platform_data = &bfin_sport0_peripherals, /* Passed to driver */
408 #ifdef CONFIG_SERIAL_BFIN_SPORT1_UART
409 static struct resource bfin_sport1_uart_resources[] = {
411 .start = SPORT1_TCR1,
412 .end = SPORT1_MRCS3+4,
413 .flags = IORESOURCE_MEM,
416 .start = IRQ_SPORT1_RX,
417 .end = IRQ_SPORT1_RX+1,
418 .flags = IORESOURCE_IRQ,
421 .start = IRQ_SPORT1_ERROR,
422 .end = IRQ_SPORT1_ERROR,
423 .flags = IORESOURCE_IRQ,
427 static unsigned short bfin_sport1_peripherals[] = {
428 P_SPORT1_TFS, P_SPORT1_DTPRI, P_SPORT1_TSCLK, P_SPORT1_RFS,
429 P_SPORT1_DRPRI, P_SPORT1_RSCLK, 0
432 static struct platform_device bfin_sport1_uart_device = {
433 .name = "bfin-sport-uart",
435 .num_resources = ARRAY_SIZE(bfin_sport1_uart_resources),
436 .resource = bfin_sport1_uart_resources,
438 .platform_data = &bfin_sport1_peripherals, /* Passed to driver */
444 #if IS_ENABLED(CONFIG_BFIN_SPORT)
445 static struct resource bfin_sport0_resources[] = {
447 .start = SPORT0_TCR1,
448 .end = SPORT0_MRCS3+4,
449 .flags = IORESOURCE_MEM,
452 .start = IRQ_SPORT0_TX,
453 .end = IRQ_SPORT0_TX+1,
454 .flags = IORESOURCE_IRQ,
457 .start = IRQ_SPORT0_RX,
458 .end = IRQ_SPORT0_RX+1,
459 .flags = IORESOURCE_IRQ,
462 .start = IRQ_SPORT0_ERROR,
463 .end = IRQ_SPORT0_ERROR,
464 .flags = IORESOURCE_IRQ,
467 .start = CH_SPORT0_TX,
469 .flags = IORESOURCE_DMA,
472 .start = CH_SPORT0_RX,
474 .flags = IORESOURCE_DMA,
477 static struct platform_device bfin_sport0_device = {
478 .name = "bfin_sport_raw",
480 .num_resources = ARRAY_SIZE(bfin_sport0_resources),
481 .resource = bfin_sport0_resources,
483 .platform_data = &bfin_sport0_peripherals,
488 #if IS_ENABLED(CONFIG_KEYBOARD_GPIO)
489 #include <linux/input.h>
490 #include <linux/gpio_keys.h>
492 static struct gpio_keys_button bfin_gpio_keys_table[] = {
493 {BTN_0, GPIO_PF5, 0, "gpio-keys: BTN0"},
494 {BTN_1, GPIO_PF6, 0, "gpio-keys: BTN1"},
495 {BTN_2, GPIO_PF8, 0, "gpio-keys: BTN2"},
498 static struct gpio_keys_platform_data bfin_gpio_keys_data = {
499 .buttons = bfin_gpio_keys_table,
500 .nbuttons = ARRAY_SIZE(bfin_gpio_keys_table),
503 static struct platform_device bfin_device_gpiokeys = {
506 .platform_data = &bfin_gpio_keys_data,
511 #if IS_ENABLED(CONFIG_I2C_GPIO)
512 #include <linux/i2c-gpio.h>
514 static struct i2c_gpio_platform_data i2c_gpio_data = {
517 .sda_is_open_drain = 0,
518 .scl_is_open_drain = 0,
522 static struct platform_device i2c_gpio_device = {
526 .platform_data = &i2c_gpio_data,
531 static struct i2c_board_info __initdata bfin_i2c_board_info[] = {
532 #if IS_ENABLED(CONFIG_JOYSTICK_AD7142)
534 I2C_BOARD_INFO("ad7142_joystick", 0x2C),
538 #if IS_ENABLED(CONFIG_BFIN_TWI_LCD)
540 I2C_BOARD_INFO("pcf8574_lcd", 0x22),
543 #if IS_ENABLED(CONFIG_INPUT_PCF8574)
545 I2C_BOARD_INFO("pcf8574_keypad", 0x27),
549 #if IS_ENABLED(CONFIG_FB_BFIN_7393)
551 I2C_BOARD_INFO("bfin-adv7393", 0x2B),
554 #if IS_ENABLED(CONFIG_BFIN_TWI_LCD)
556 I2C_BOARD_INFO("ad5252", 0x2f),
561 static const unsigned int cclk_vlev_datasheet[] =
563 VRPAIR(VLEV_085, 250000000),
564 VRPAIR(VLEV_090, 376000000),
565 VRPAIR(VLEV_095, 426000000),
566 VRPAIR(VLEV_100, 426000000),
567 VRPAIR(VLEV_105, 476000000),
568 VRPAIR(VLEV_110, 476000000),
569 VRPAIR(VLEV_115, 476000000),
570 VRPAIR(VLEV_120, 600000000),
571 VRPAIR(VLEV_125, 600000000),
572 VRPAIR(VLEV_130, 600000000),
575 static struct bfin_dpmc_platform_data bfin_dmpc_vreg_data = {
576 .tuple_tab = cclk_vlev_datasheet,
577 .tabsize = ARRAY_SIZE(cclk_vlev_datasheet),
578 .vr_settling_time = 25 /* us */,
581 static struct platform_device bfin_dpmc = {
584 .platform_data = &bfin_dmpc_vreg_data,
588 #if IS_ENABLED(CONFIG_SND_BF5XX_I2S) || \
589 IS_ENABLED(CONFIG_SND_BF5XX_AC97)
591 #include <asm/bfin_sport.h>
593 #define SPORT_REQ(x) \
594 [x] = {P_SPORT##x##_TFS, P_SPORT##x##_DTPRI, P_SPORT##x##_TSCLK, \
595 P_SPORT##x##_RFS, P_SPORT##x##_DRPRI, P_SPORT##x##_RSCLK, 0}
597 static const u16 bfin_snd_pin[][7] = {
602 static struct bfin_snd_platform_data bfin_snd_data[] = {
604 .pin_req = &bfin_snd_pin[0][0],
607 .pin_req = &bfin_snd_pin[1][0],
611 #define BFIN_SND_RES(x) \
614 .start = SPORT##x##_TCR1, \
615 .end = SPORT##x##_TCR1, \
616 .flags = IORESOURCE_MEM \
619 .start = CH_SPORT##x##_RX, \
620 .end = CH_SPORT##x##_RX, \
621 .flags = IORESOURCE_DMA, \
624 .start = CH_SPORT##x##_TX, \
625 .end = CH_SPORT##x##_TX, \
626 .flags = IORESOURCE_DMA, \
629 .start = IRQ_SPORT##x##_ERROR, \
630 .end = IRQ_SPORT##x##_ERROR, \
631 .flags = IORESOURCE_IRQ, \
635 static struct resource bfin_snd_resources[][4] = {
641 #if IS_ENABLED(CONFIG_SND_BF5XX_I2S)
642 static struct platform_device bfin_i2s_pcm = {
643 .name = "bfin-i2s-pcm-audio",
648 #if IS_ENABLED(CONFIG_SND_BF5XX_AC97)
649 static struct platform_device bfin_ac97_pcm = {
650 .name = "bfin-ac97-pcm-audio",
655 #if IS_ENABLED(CONFIG_SND_BF5XX_SOC_AD1836)
656 static const char * const ad1836_link[] = {
660 static struct platform_device bfin_ad1836_machine = {
661 .name = "bfin-snd-ad1836",
664 .platform_data = (void *)ad1836_link,
669 #if IS_ENABLED(CONFIG_SND_BF5XX_SOC_AD73311)
670 static const unsigned ad73311_gpio[] = {
674 static struct platform_device bfin_ad73311_machine = {
675 .name = "bfin-snd-ad73311",
678 .platform_data = (void *)ad73311_gpio,
683 #if IS_ENABLED(CONFIG_SND_SOC_AD73311)
684 static struct platform_device bfin_ad73311_codec_device = {
690 #if IS_ENABLED(CONFIG_SND_SOC_AD74111)
691 static struct platform_device bfin_ad74111_codec_device = {
697 #if IS_ENABLED(CONFIG_SND_BF5XX_SOC_I2S)
698 static struct platform_device bfin_i2s = {
700 .id = CONFIG_SND_BF5XX_SPORT_NUM,
702 ARRAY_SIZE(bfin_snd_resources[CONFIG_SND_BF5XX_SPORT_NUM]),
703 .resource = bfin_snd_resources[CONFIG_SND_BF5XX_SPORT_NUM],
705 .platform_data = &bfin_snd_data[CONFIG_SND_BF5XX_SPORT_NUM],
710 #if IS_ENABLED(CONFIG_SND_BF5XX_SOC_AC97)
711 static struct platform_device bfin_ac97 = {
713 .id = CONFIG_SND_BF5XX_SPORT_NUM,
715 ARRAY_SIZE(bfin_snd_resources[CONFIG_SND_BF5XX_SPORT_NUM]),
716 .resource = bfin_snd_resources[CONFIG_SND_BF5XX_SPORT_NUM],
718 .platform_data = &bfin_snd_data[CONFIG_SND_BF5XX_SPORT_NUM],
723 static struct platform_device *stamp_devices[] __initdata = {
727 #if IS_ENABLED(CONFIG_RTC_DRV_BFIN)
731 #if IS_ENABLED(CONFIG_SMC91X)
735 #if IS_ENABLED(CONFIG_USB_NET2272)
736 &net2272_bfin_device,
739 #if IS_ENABLED(CONFIG_SPI_BFIN5XX)
743 #if IS_ENABLED(CONFIG_SERIAL_BFIN)
744 #ifdef CONFIG_SERIAL_BFIN_UART0
749 #if IS_ENABLED(CONFIG_BFIN_SIR)
750 #ifdef CONFIG_BFIN_SIR0
755 #if IS_ENABLED(CONFIG_SERIAL_BFIN_SPORT)
756 #ifdef CONFIG_SERIAL_BFIN_SPORT0_UART
757 &bfin_sport0_uart_device,
759 #ifdef CONFIG_SERIAL_BFIN_SPORT1_UART
760 &bfin_sport1_uart_device,
764 #if IS_ENABLED(CONFIG_KEYBOARD_GPIO)
765 &bfin_device_gpiokeys,
768 #if IS_ENABLED(CONFIG_I2C_GPIO)
772 #if IS_ENABLED(CONFIG_MTD_BFIN_ASYNC)
776 #if IS_ENABLED(CONFIG_SND_BF5XX_I2S)
780 #if IS_ENABLED(CONFIG_SND_BF5XX_AC97)
784 #if IS_ENABLED(CONFIG_SND_BF5XX_SOC_AD1836)
785 &bfin_ad1836_machine,
788 #if IS_ENABLED(CONFIG_SND_BF5XX_SOC_AD73311)
789 &bfin_ad73311_machine,
792 #if IS_ENABLED(CONFIG_SND_SOC_AD73311)
793 &bfin_ad73311_codec_device,
796 #if IS_ENABLED(CONFIG_SND_SOC_AD74111)
797 &bfin_ad74111_codec_device,
800 #if IS_ENABLED(CONFIG_SND_BF5XX_SOC_I2S)
804 #if IS_ENABLED(CONFIG_SND_BF5XX_SOC_AC97)
809 static int __init net2272_init(void)
811 #if IS_ENABLED(CONFIG_USB_NET2272)
814 /* Set PF0 to 0, PF1 to 1 make /AMS3 work properly */
815 ret = gpio_request(GPIO_PF0, "net2272");
819 ret = gpio_request(GPIO_PF1, "net2272");
825 ret = gpio_request(GPIO_PF11, "net2272");
832 gpio_direction_output(GPIO_PF0, 0);
833 gpio_direction_output(GPIO_PF1, 1);
835 /* Reset the USB chip */
836 gpio_direction_output(GPIO_PF11, 0);
838 gpio_set_value(GPIO_PF11, 1);
844 static int __init stamp_init(void)
848 printk(KERN_INFO "%s(): registering device resources\n", __func__);
850 i2c_register_board_info(0, bfin_i2c_board_info,
851 ARRAY_SIZE(bfin_i2c_board_info));
853 ret = platform_add_devices(stamp_devices, ARRAY_SIZE(stamp_devices));
857 #if IS_ENABLED(CONFIG_SMC91X)
859 * setup BF533_STAMP CPLD to route AMS3 to Ethernet MAC.
860 * the bfin-async-map driver takes care of flipping between
861 * flash and ethernet when necessary.
863 ret = gpio_request(GPIO_PF0, "enet_cpld");
865 gpio_direction_output(GPIO_PF0, 1);
871 pr_warning("unable to configure net2272; it probably won't work\n");
873 spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info));
877 arch_initcall(stamp_init);
879 static struct platform_device *stamp_early_devices[] __initdata = {
880 #if defined(CONFIG_SERIAL_BFIN_CONSOLE) || defined(CONFIG_EARLY_PRINTK)
881 #ifdef CONFIG_SERIAL_BFIN_UART0
886 #if defined(CONFIG_SERIAL_BFIN_SPORT_CONSOLE)
887 #ifdef CONFIG_SERIAL_BFIN_SPORT0_UART
888 &bfin_sport0_uart_device,
890 #ifdef CONFIG_SERIAL_BFIN_SPORT1_UART
891 &bfin_sport1_uart_device,
896 void __init native_machine_early_platform_add_devices(void)
898 printk(KERN_INFO "register early platform devices\n");
899 early_platform_add_devices(stamp_early_devices,
900 ARRAY_SIZE(stamp_early_devices));
903 void native_machine_restart(char *cmd)
905 /* workaround pull up on cpld / flash pin not being strong enough */
906 gpio_request(GPIO_PF0, "flash_cpld");
907 gpio_direction_output(GPIO_PF0, 0);