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/export.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>
18 #include <linux/i2c.h>
19 #include <linux/irq.h>
20 #include <linux/interrupt.h>
22 #include <asm/bfin5xx_spi.h>
23 #include <asm/reboot.h>
24 #include <asm/portmux.h>
26 #include <asm/bfin_sdh.h>
27 #include <linux/spi/ad7877.h>
31 * Name the Board for the /proc/cpuinfo
33 const char bfin_board_name[] = "ADI BF518F-EZBRD";
36 * Driver needs to know address, irq and flag pin.
39 #if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
40 static struct mtd_partition ezbrd_partitions[] = {
42 .name = "bootloader(nor)",
46 .name = "linux kernel(nor)",
48 .offset = MTDPART_OFS_APPEND,
50 .name = "file system(nor)",
51 .size = MTDPART_SIZ_FULL,
52 .offset = MTDPART_OFS_APPEND,
56 static struct physmap_flash_data ezbrd_flash_data = {
58 .parts = ezbrd_partitions,
59 .nr_parts = ARRAY_SIZE(ezbrd_partitions),
62 static struct resource ezbrd_flash_resource = {
64 #if defined(CONFIG_SPI_BFIN5XX) || defined(CONFIG_SPI_BFIN5XX_MODULE)
69 .flags = IORESOURCE_MEM,
72 static struct platform_device ezbrd_flash_device = {
73 .name = "physmap-flash",
76 .platform_data = &ezbrd_flash_data,
79 .resource = &ezbrd_flash_resource,
83 #if defined(CONFIG_RTC_DRV_BFIN) || defined(CONFIG_RTC_DRV_BFIN_MODULE)
84 static struct platform_device rtc_device = {
90 #if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
91 #include <linux/bfin_mac.h>
92 static const unsigned short bfin_mac_peripherals[] = {
106 static struct bfin_phydev_platform_data bfin_phydev_data[] = {
108 #if defined(CONFIG_NET_DSA_KSZ8893M) || defined(CONFIG_NET_DSA_KSZ8893M_MODULE)
113 .irq = IRQ_MAC_PHYINT,
117 static struct bfin_mii_bus_platform_data bfin_mii_bus_data = {
119 .phydev_data = bfin_phydev_data,
120 .phy_mode = PHY_INTERFACE_MODE_MII,
121 .mac_peripherals = bfin_mac_peripherals,
122 #if defined(CONFIG_NET_DSA_KSZ8893M) || defined(CONFIG_NET_DSA_KSZ8893M_MODULE)
123 .phy_mask = 0xfff7, /* Only probe the port phy connect to the on chip MAC */
129 static struct platform_device bfin_mii_bus = {
130 .name = "bfin_mii_bus",
132 .platform_data = &bfin_mii_bus_data,
136 static struct platform_device bfin_mac_device = {
139 .platform_data = &bfin_mii_bus,
143 #if defined(CONFIG_NET_DSA_KSZ8893M) || defined(CONFIG_NET_DSA_KSZ8893M_MODULE)
144 static struct dsa_chip_data ksz8893m_switch_chip_data = {
145 .mii_bus = &bfin_mii_bus.dev,
153 static struct dsa_platform_data ksz8893m_switch_data = {
155 .netdev = &bfin_mac_device.dev,
156 .chip = &ksz8893m_switch_chip_data,
159 static struct platform_device ksz8893m_switch_device = {
163 .dev.platform_data = &ksz8893m_switch_data,
168 #if defined(CONFIG_MTD_M25P80) \
169 || defined(CONFIG_MTD_M25P80_MODULE)
170 static struct mtd_partition bfin_spi_flash_partitions[] = {
172 .name = "bootloader(spi)",
175 .mask_flags = MTD_CAP_ROM
177 .name = "linux kernel(spi)",
178 .size = MTDPART_SIZ_FULL,
179 .offset = MTDPART_OFS_APPEND,
183 static struct flash_platform_data bfin_spi_flash_data = {
185 .parts = bfin_spi_flash_partitions,
186 .nr_parts = ARRAY_SIZE(bfin_spi_flash_partitions),
190 /* SPI flash chip (m25p64) */
191 static struct bfin5xx_spi_chip spi_flash_chip_info = {
192 .enable_dma = 0, /* use dma transfer with this chip*/
196 #if defined(CONFIG_MMC_SPI) || defined(CONFIG_MMC_SPI_MODULE)
197 static struct bfin5xx_spi_chip mmc_spi_chip_info = {
202 #if defined(CONFIG_TOUCHSCREEN_AD7877) || defined(CONFIG_TOUCHSCREEN_AD7877_MODULE)
203 static const struct ad7877_platform_data bfin_ad7877_ts_info = {
205 .vref_delay_usecs = 50, /* internal, no capacitor */
208 .pressure_max = 1000,
210 .stopacq_polarity = 1,
211 .first_conversion_delay = 3,
212 .acquisition_time = 1,
214 .pen_down_acc_interval = 1,
218 static struct spi_board_info bfin_spi_board_info[] __initdata = {
219 #if defined(CONFIG_MTD_M25P80) \
220 || defined(CONFIG_MTD_M25P80_MODULE)
222 /* the modalias must be the same as spi device driver name */
223 .modalias = "m25p80", /* Name of spi_driver for this device */
224 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */
225 .bus_num = 0, /* Framework bus number */
226 .chip_select = 2, /* On BF518F-EZBRD it's SPI0_SSEL2 */
227 .platform_data = &bfin_spi_flash_data,
228 .controller_data = &spi_flash_chip_info,
233 #if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
234 #if defined(CONFIG_NET_DSA_KSZ8893M) \
235 || defined(CONFIG_NET_DSA_KSZ8893M_MODULE)
237 .modalias = "ksz8893m",
238 .max_speed_hz = 5000000,
241 .platform_data = NULL,
247 #if defined(CONFIG_MMC_SPI) || defined(CONFIG_MMC_SPI_MODULE)
249 .modalias = "mmc_spi",
250 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */
253 .controller_data = &mmc_spi_chip_info,
257 #if defined(CONFIG_TOUCHSCREEN_AD7877) || defined(CONFIG_TOUCHSCREEN_AD7877_MODULE)
259 .modalias = "ad7877",
260 .platform_data = &bfin_ad7877_ts_info,
262 .max_speed_hz = 12500000, /* max spi clock (SCK) speed in HZ */
267 #if defined(CONFIG_SND_SOC_WM8731) || defined(CONFIG_SND_SOC_WM8731_MODULE) \
268 && defined(CONFIG_SND_SOC_WM8731_SPI)
270 .modalias = "wm8731",
271 .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */
277 #if defined(CONFIG_SPI_SPIDEV) || defined(CONFIG_SPI_SPIDEV_MODULE)
279 .modalias = "spidev",
280 .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */
285 #if defined(CONFIG_FB_BFIN_LQ035Q1) || defined(CONFIG_FB_BFIN_LQ035Q1_MODULE)
287 .modalias = "bfin-lq035q1-spi",
288 .max_speed_hz = 20000000, /* max spi clock (SCK) speed in HZ */
291 .mode = SPI_CPHA | SPI_CPOL,
296 /* SPI controller data */
297 #if defined(CONFIG_SPI_BFIN5XX) || defined(CONFIG_SPI_BFIN5XX_MODULE)
299 static struct bfin5xx_spi_master bfin_spi0_info = {
301 .enable_dma = 1, /* master has the ability to do dma transfer */
302 .pin_req = {P_SPI0_SCK, P_SPI0_MISO, P_SPI0_MOSI, 0},
305 static struct resource bfin_spi0_resource[] = {
307 .start = SPI0_REGBASE,
308 .end = SPI0_REGBASE + 0xFF,
309 .flags = IORESOURCE_MEM,
314 .flags = IORESOURCE_DMA,
319 .flags = IORESOURCE_IRQ,
323 static struct platform_device bfin_spi0_device = {
325 .id = 0, /* Bus number */
326 .num_resources = ARRAY_SIZE(bfin_spi0_resource),
327 .resource = bfin_spi0_resource,
329 .platform_data = &bfin_spi0_info, /* Passed to driver */
334 static struct bfin5xx_spi_master bfin_spi1_info = {
336 .enable_dma = 1, /* master has the ability to do dma transfer */
337 .pin_req = {P_SPI1_SCK, P_SPI1_MISO, P_SPI1_MOSI, 0},
340 static struct resource bfin_spi1_resource[] = {
342 .start = SPI1_REGBASE,
343 .end = SPI1_REGBASE + 0xFF,
344 .flags = IORESOURCE_MEM,
349 .flags = IORESOURCE_DMA,
354 .flags = IORESOURCE_IRQ,
358 static struct platform_device bfin_spi1_device = {
360 .id = 1, /* Bus number */
361 .num_resources = ARRAY_SIZE(bfin_spi1_resource),
362 .resource = bfin_spi1_resource,
364 .platform_data = &bfin_spi1_info, /* Passed to driver */
367 #endif /* spi master and devices */
369 #if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
370 #ifdef CONFIG_SERIAL_BFIN_UART0
371 static struct resource bfin_uart0_resources[] = {
375 .flags = IORESOURCE_MEM,
378 .start = IRQ_UART0_TX,
380 .flags = IORESOURCE_IRQ,
383 .start = IRQ_UART0_RX,
385 .flags = IORESOURCE_IRQ,
388 .start = IRQ_UART0_ERROR,
389 .end = IRQ_UART0_ERROR,
390 .flags = IORESOURCE_IRQ,
393 .start = CH_UART0_TX,
395 .flags = IORESOURCE_DMA,
398 .start = CH_UART0_RX,
400 .flags = IORESOURCE_DMA,
404 static unsigned short bfin_uart0_peripherals[] = {
405 P_UART0_TX, P_UART0_RX, 0
408 static struct platform_device bfin_uart0_device = {
411 .num_resources = ARRAY_SIZE(bfin_uart0_resources),
412 .resource = bfin_uart0_resources,
414 .platform_data = &bfin_uart0_peripherals, /* Passed to driver */
418 #ifdef CONFIG_SERIAL_BFIN_UART1
419 static struct resource bfin_uart1_resources[] = {
423 .flags = IORESOURCE_MEM,
426 .start = IRQ_UART1_TX,
428 .flags = IORESOURCE_IRQ,
431 .start = IRQ_UART1_RX,
433 .flags = IORESOURCE_IRQ,
436 .start = IRQ_UART1_ERROR,
437 .end = IRQ_UART1_ERROR,
438 .flags = IORESOURCE_IRQ,
441 .start = CH_UART1_TX,
443 .flags = IORESOURCE_DMA,
446 .start = CH_UART1_RX,
448 .flags = IORESOURCE_DMA,
452 static unsigned short bfin_uart1_peripherals[] = {
453 P_UART1_TX, P_UART1_RX, 0
456 static struct platform_device bfin_uart1_device = {
459 .num_resources = ARRAY_SIZE(bfin_uart1_resources),
460 .resource = bfin_uart1_resources,
462 .platform_data = &bfin_uart1_peripherals, /* Passed to driver */
468 #if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
469 #ifdef CONFIG_BFIN_SIR0
470 static struct resource bfin_sir0_resources[] = {
474 .flags = IORESOURCE_MEM,
477 .start = IRQ_UART0_RX,
478 .end = IRQ_UART0_RX+1,
479 .flags = IORESOURCE_IRQ,
482 .start = CH_UART0_RX,
483 .end = CH_UART0_RX+1,
484 .flags = IORESOURCE_DMA,
488 static struct platform_device bfin_sir0_device = {
491 .num_resources = ARRAY_SIZE(bfin_sir0_resources),
492 .resource = bfin_sir0_resources,
495 #ifdef CONFIG_BFIN_SIR1
496 static struct resource bfin_sir1_resources[] = {
500 .flags = IORESOURCE_MEM,
503 .start = IRQ_UART1_RX,
504 .end = IRQ_UART1_RX+1,
505 .flags = IORESOURCE_IRQ,
508 .start = CH_UART1_RX,
509 .end = CH_UART1_RX+1,
510 .flags = IORESOURCE_DMA,
514 static struct platform_device bfin_sir1_device = {
517 .num_resources = ARRAY_SIZE(bfin_sir1_resources),
518 .resource = bfin_sir1_resources,
523 #if defined(CONFIG_SND_BF5XX_I2S) || defined(CONFIG_SND_BF5XX_I2S_MODULE)
524 static struct platform_device bfin_i2s = {
526 .id = CONFIG_SND_BF5XX_SPORT_NUM,
527 /* TODO: add platform data here */
531 #if defined(CONFIG_I2C_BLACKFIN_TWI) || defined(CONFIG_I2C_BLACKFIN_TWI_MODULE)
532 static const u16 bfin_twi0_pins[] = {P_TWI0_SCL, P_TWI0_SDA, 0};
534 static struct resource bfin_twi0_resource[] = {
536 .start = TWI0_REGBASE,
538 .flags = IORESOURCE_MEM,
543 .flags = IORESOURCE_IRQ,
547 static struct platform_device i2c_bfin_twi_device = {
548 .name = "i2c-bfin-twi",
550 .num_resources = ARRAY_SIZE(bfin_twi0_resource),
551 .resource = bfin_twi0_resource,
553 .platform_data = &bfin_twi0_pins,
558 static struct i2c_board_info __initdata bfin_i2c_board_info[] = {
559 #if defined(CONFIG_BFIN_TWI_LCD) || defined(CONFIG_BFIN_TWI_LCD_MODULE)
561 I2C_BOARD_INFO("pcf8574_lcd", 0x22),
564 #if defined(CONFIG_INPUT_PCF8574) || defined(CONFIG_INPUT_PCF8574_MODULE)
566 I2C_BOARD_INFO("pcf8574_keypad", 0x27),
570 #if defined(CONFIG_SND_SOC_SSM2602) || defined(CONFIG_SND_SOC_SSM2602_MODULE)
572 I2C_BOARD_INFO("ssm2602", 0x1b),
577 #if defined(CONFIG_SERIAL_BFIN_SPORT) || defined(CONFIG_SERIAL_BFIN_SPORT_MODULE)
578 #ifdef CONFIG_SERIAL_BFIN_SPORT0_UART
579 static struct resource bfin_sport0_uart_resources[] = {
581 .start = SPORT0_TCR1,
582 .end = SPORT0_MRCS3+4,
583 .flags = IORESOURCE_MEM,
586 .start = IRQ_SPORT0_RX,
587 .end = IRQ_SPORT0_RX+1,
588 .flags = IORESOURCE_IRQ,
591 .start = IRQ_SPORT0_ERROR,
592 .end = IRQ_SPORT0_ERROR,
593 .flags = IORESOURCE_IRQ,
597 static unsigned short bfin_sport0_peripherals[] = {
598 P_SPORT0_TFS, P_SPORT0_DTPRI, P_SPORT0_TSCLK, P_SPORT0_RFS,
599 P_SPORT0_DRPRI, P_SPORT0_RSCLK, 0
602 static struct platform_device bfin_sport0_uart_device = {
603 .name = "bfin-sport-uart",
605 .num_resources = ARRAY_SIZE(bfin_sport0_uart_resources),
606 .resource = bfin_sport0_uart_resources,
608 .platform_data = &bfin_sport0_peripherals, /* Passed to driver */
612 #ifdef CONFIG_SERIAL_BFIN_SPORT1_UART
613 static struct resource bfin_sport1_uart_resources[] = {
615 .start = SPORT1_TCR1,
616 .end = SPORT1_MRCS3+4,
617 .flags = IORESOURCE_MEM,
620 .start = IRQ_SPORT1_RX,
621 .end = IRQ_SPORT1_RX+1,
622 .flags = IORESOURCE_IRQ,
625 .start = IRQ_SPORT1_ERROR,
626 .end = IRQ_SPORT1_ERROR,
627 .flags = IORESOURCE_IRQ,
631 static unsigned short bfin_sport1_peripherals[] = {
632 P_SPORT1_TFS, P_SPORT1_DTPRI, P_SPORT1_TSCLK, P_SPORT1_RFS,
633 P_SPORT1_DRPRI, P_SPORT1_RSCLK, 0
636 static struct platform_device bfin_sport1_uart_device = {
637 .name = "bfin-sport-uart",
639 .num_resources = ARRAY_SIZE(bfin_sport1_uart_resources),
640 .resource = bfin_sport1_uart_resources,
642 .platform_data = &bfin_sport1_peripherals, /* Passed to driver */
648 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
649 #include <linux/input.h>
650 #include <linux/gpio_keys.h>
652 static struct gpio_keys_button bfin_gpio_keys_table[] = {
653 {BTN_0, GPIO_PG0, 1, "gpio-keys: BTN0"},
654 {BTN_1, GPIO_PG13, 1, "gpio-keys: BTN1"},
657 static struct gpio_keys_platform_data bfin_gpio_keys_data = {
658 .buttons = bfin_gpio_keys_table,
659 .nbuttons = ARRAY_SIZE(bfin_gpio_keys_table),
662 static struct platform_device bfin_device_gpiokeys = {
665 .platform_data = &bfin_gpio_keys_data,
670 #if defined(CONFIG_SDH_BFIN) || defined(CONFIG_SDH_BFIN_MODULE)
672 static struct bfin_sd_host bfin_sdh_data = {
674 .irq_int0 = IRQ_RSI_INT0,
675 .pin_req = {P_RSI_DATA0, P_RSI_DATA1, P_RSI_DATA2, P_RSI_DATA3, P_RSI_CMD, P_RSI_CLK, 0},
678 static struct platform_device bf51x_sdh_device = {
682 .platform_data = &bfin_sdh_data,
687 static const unsigned int cclk_vlev_datasheet[] =
689 VRPAIR(VLEV_100, 400000000),
690 VRPAIR(VLEV_105, 426000000),
691 VRPAIR(VLEV_110, 500000000),
692 VRPAIR(VLEV_115, 533000000),
693 VRPAIR(VLEV_120, 600000000),
696 static struct bfin_dpmc_platform_data bfin_dmpc_vreg_data = {
697 .tuple_tab = cclk_vlev_datasheet,
698 .tabsize = ARRAY_SIZE(cclk_vlev_datasheet),
699 .vr_settling_time = 25 /* us */,
702 static struct platform_device bfin_dpmc = {
705 .platform_data = &bfin_dmpc_vreg_data,
709 static struct platform_device *stamp_devices[] __initdata = {
713 #if defined(CONFIG_RTC_DRV_BFIN) || defined(CONFIG_RTC_DRV_BFIN_MODULE)
717 #if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
720 #if defined(CONFIG_NET_DSA_KSZ8893M) || defined(CONFIG_NET_DSA_KSZ8893M_MODULE)
721 &ksz8893m_switch_device,
725 #if defined(CONFIG_SPI_BFIN5XX) || defined(CONFIG_SPI_BFIN5XX_MODULE)
730 #if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
731 #ifdef CONFIG_SERIAL_BFIN_UART0
734 #ifdef CONFIG_SERIAL_BFIN_UART1
739 #if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
740 #ifdef CONFIG_BFIN_SIR0
743 #ifdef CONFIG_BFIN_SIR1
748 #if defined(CONFIG_I2C_BLACKFIN_TWI) || defined(CONFIG_I2C_BLACKFIN_TWI_MODULE)
749 &i2c_bfin_twi_device,
752 #if defined(CONFIG_SND_BF5XX_I2S) || defined(CONFIG_SND_BF5XX_I2S_MODULE)
756 #if defined(CONFIG_SERIAL_BFIN_SPORT) || defined(CONFIG_SERIAL_BFIN_SPORT_MODULE)
757 #ifdef CONFIG_SERIAL_BFIN_SPORT0_UART
758 &bfin_sport0_uart_device,
760 #ifdef CONFIG_SERIAL_BFIN_SPORT1_UART
761 &bfin_sport1_uart_device,
765 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
766 &bfin_device_gpiokeys,
769 #if defined(CONFIG_SDH_BFIN) || defined(CONFIG_SDH_BFIN_MODULE)
773 #if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
778 static int __init ezbrd_init(void)
780 printk(KERN_INFO "%s(): registering device resources\n", __func__);
781 i2c_register_board_info(0, bfin_i2c_board_info,
782 ARRAY_SIZE(bfin_i2c_board_info));
783 platform_add_devices(stamp_devices, ARRAY_SIZE(stamp_devices));
784 spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info));
785 /* setup BF518-EZBRD GPIO pin PG11 to AMS2, PG15 to AMS3. */
786 peripheral_request(P_AMS2, "ParaFlash");
787 #if !defined(CONFIG_SPI_BFIN5XX) && !defined(CONFIG_SPI_BFIN5XX_MODULE)
788 peripheral_request(P_AMS3, "ParaFlash");
793 arch_initcall(ezbrd_init);
795 static struct platform_device *ezbrd_early_devices[] __initdata = {
796 #if defined(CONFIG_SERIAL_BFIN_CONSOLE) || defined(CONFIG_EARLY_PRINTK)
797 #ifdef CONFIG_SERIAL_BFIN_UART0
800 #ifdef CONFIG_SERIAL_BFIN_UART1
805 #if defined(CONFIG_SERIAL_BFIN_SPORT_CONSOLE)
806 #ifdef CONFIG_SERIAL_BFIN_SPORT0_UART
807 &bfin_sport0_uart_device,
809 #ifdef CONFIG_SERIAL_BFIN_SPORT1_UART
810 &bfin_sport1_uart_device,
815 void __init native_machine_early_platform_add_devices(void)
817 printk(KERN_INFO "register early platform devices\n");
818 early_platform_add_devices(ezbrd_early_devices,
819 ARRAY_SIZE(ezbrd_early_devices));
822 void native_machine_restart(char *cmd)
824 /* workaround reboot hang when booting from SPI */
825 if ((bfin_read_SYSCR() & 0x7) == 0x3)
826 bfin_reset_boot_spi_cs(P_DEFAULT_BOOT_SPI_CS);
829 int bfin_get_ether_addr(char *addr)
831 /* the MAC is stored in OTP memory page 0xDF */
834 u32 (*otp_read)(u32 page, u32 flags, u64 *page_content) = (void *)0xEF00001A;
836 ret = otp_read(0xDF, 0x00, &otp_mac);
838 char *otp_mac_p = (char *)&otp_mac;
839 for (ret = 0; ret < 6; ++ret)
840 addr[ret] = otp_mac_p[5 - ret];
844 EXPORT_SYMBOL(bfin_get_ether_addr);