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>
17 #include <linux/i2c.h>
18 #include <linux/irq.h>
19 #include <linux/interrupt.h>
21 #include <asm/bfin5xx_spi.h>
22 #include <asm/reboot.h>
23 #include <asm/portmux.h>
25 #include <asm/bfin_sdh.h>
26 #include <linux/spi/ad7877.h>
30 * Name the Board for the /proc/cpuinfo
32 const char bfin_board_name[] = "ADI BF518F-EZBRD";
35 * Driver needs to know address, irq and flag pin.
38 #if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
39 static struct mtd_partition ezbrd_partitions[] = {
41 .name = "bootloader(nor)",
45 .name = "linux kernel(nor)",
47 .offset = MTDPART_OFS_APPEND,
49 .name = "file system(nor)",
50 .size = MTDPART_SIZ_FULL,
51 .offset = MTDPART_OFS_APPEND,
55 static struct physmap_flash_data ezbrd_flash_data = {
57 .parts = ezbrd_partitions,
58 .nr_parts = ARRAY_SIZE(ezbrd_partitions),
61 static struct resource ezbrd_flash_resource = {
63 #if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
68 .flags = IORESOURCE_MEM,
71 static struct platform_device ezbrd_flash_device = {
72 .name = "physmap-flash",
75 .platform_data = &ezbrd_flash_data,
78 .resource = &ezbrd_flash_resource,
82 #if defined(CONFIG_RTC_DRV_BFIN) || defined(CONFIG_RTC_DRV_BFIN_MODULE)
83 static struct platform_device rtc_device = {
89 #if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
90 #include <linux/bfin_mac.h>
91 static const unsigned short bfin_mac_peripherals[] = {
105 static struct bfin_phydev_platform_data bfin_phydev_data[] = {
107 #if defined(CONFIG_NET_DSA_KSZ8893M) || defined(CONFIG_NET_DSA_KSZ8893M_MODULE)
112 .irq = IRQ_MAC_PHYINT,
116 static struct bfin_mii_bus_platform_data bfin_mii_bus_data = {
118 .phydev_data = bfin_phydev_data,
119 .phy_mode = PHY_INTERFACE_MODE_MII,
120 .mac_peripherals = bfin_mac_peripherals,
121 #if defined(CONFIG_NET_DSA_KSZ8893M) || defined(CONFIG_NET_DSA_KSZ8893M_MODULE)
122 .phy_mask = 0xfff7, /* Only probe the port phy connect to the on chip MAC */
126 static struct platform_device bfin_mii_bus = {
127 .name = "bfin_mii_bus",
129 .platform_data = &bfin_mii_bus_data,
133 static struct platform_device bfin_mac_device = {
136 .platform_data = &bfin_mii_bus,
140 #if defined(CONFIG_NET_DSA_KSZ8893M) || defined(CONFIG_NET_DSA_KSZ8893M_MODULE)
141 static struct dsa_chip_data ksz8893m_switch_chip_data = {
142 .mii_bus = &bfin_mii_bus.dev,
150 static struct dsa_platform_data ksz8893m_switch_data = {
152 .netdev = &bfin_mac_device.dev,
153 .chip = &ksz8893m_switch_chip_data,
156 static struct platform_device ksz8893m_switch_device = {
160 .dev.platform_data = &ksz8893m_switch_data,
165 #if defined(CONFIG_MTD_M25P80) \
166 || defined(CONFIG_MTD_M25P80_MODULE)
167 static struct mtd_partition bfin_spi_flash_partitions[] = {
169 .name = "bootloader(spi)",
172 .mask_flags = MTD_CAP_ROM
174 .name = "linux kernel(spi)",
175 .size = MTDPART_SIZ_FULL,
176 .offset = MTDPART_OFS_APPEND,
180 static struct flash_platform_data bfin_spi_flash_data = {
182 .parts = bfin_spi_flash_partitions,
183 .nr_parts = ARRAY_SIZE(bfin_spi_flash_partitions),
187 /* SPI flash chip (m25p64) */
188 static struct bfin5xx_spi_chip spi_flash_chip_info = {
189 .enable_dma = 0, /* use dma transfer with this chip*/
193 #if defined(CONFIG_MMC_SPI) || defined(CONFIG_MMC_SPI_MODULE)
194 static struct bfin5xx_spi_chip mmc_spi_chip_info = {
199 #if defined(CONFIG_TOUCHSCREEN_AD7877) || defined(CONFIG_TOUCHSCREEN_AD7877_MODULE)
200 static const struct ad7877_platform_data bfin_ad7877_ts_info = {
202 .vref_delay_usecs = 50, /* internal, no capacitor */
205 .pressure_max = 1000,
207 .stopacq_polarity = 1,
208 .first_conversion_delay = 3,
209 .acquisition_time = 1,
211 .pen_down_acc_interval = 1,
215 static struct spi_board_info bfin_spi_board_info[] __initdata = {
216 #if defined(CONFIG_MTD_M25P80) \
217 || defined(CONFIG_MTD_M25P80_MODULE)
219 /* the modalias must be the same as spi device driver name */
220 .modalias = "m25p80", /* Name of spi_driver for this device */
221 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */
222 .bus_num = 0, /* Framework bus number */
223 .chip_select = 2, /* On BF518F-EZBRD it's SPI0_SSEL2 */
224 .platform_data = &bfin_spi_flash_data,
225 .controller_data = &spi_flash_chip_info,
230 #if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
231 #if defined(CONFIG_NET_DSA_KSZ8893M) \
232 || defined(CONFIG_NET_DSA_KSZ8893M_MODULE)
234 .modalias = "ksz8893m",
235 .max_speed_hz = 5000000,
238 .platform_data = NULL,
244 #if defined(CONFIG_MMC_SPI) || defined(CONFIG_MMC_SPI_MODULE)
246 .modalias = "mmc_spi",
247 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */
250 .controller_data = &mmc_spi_chip_info,
254 #if defined(CONFIG_TOUCHSCREEN_AD7877) || defined(CONFIG_TOUCHSCREEN_AD7877_MODULE)
256 .modalias = "ad7877",
257 .platform_data = &bfin_ad7877_ts_info,
259 .max_speed_hz = 12500000, /* max spi clock (SCK) speed in HZ */
264 #if defined(CONFIG_SND_SOC_WM8731) || defined(CONFIG_SND_SOC_WM8731_MODULE) \
265 && defined(CONFIG_SND_SOC_WM8731_SPI)
267 .modalias = "wm8731",
268 .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */
274 #if defined(CONFIG_SPI_SPIDEV) || defined(CONFIG_SPI_SPIDEV_MODULE)
276 .modalias = "spidev",
277 .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */
282 #if defined(CONFIG_FB_BFIN_LQ035Q1) || defined(CONFIG_FB_BFIN_LQ035Q1_MODULE)
284 .modalias = "bfin-lq035q1-spi",
285 .max_speed_hz = 20000000, /* max spi clock (SCK) speed in HZ */
288 .mode = SPI_CPHA | SPI_CPOL,
293 /* SPI controller data */
294 #if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
296 static struct bfin5xx_spi_master bfin_spi0_info = {
298 .enable_dma = 1, /* master has the ability to do dma transfer */
299 .pin_req = {P_SPI0_SCK, P_SPI0_MISO, P_SPI0_MOSI, 0},
302 static struct resource bfin_spi0_resource[] = {
304 .start = SPI0_REGBASE,
305 .end = SPI0_REGBASE + 0xFF,
306 .flags = IORESOURCE_MEM,
311 .flags = IORESOURCE_DMA,
316 .flags = IORESOURCE_IRQ,
320 static struct platform_device bfin_spi0_device = {
322 .id = 0, /* Bus number */
323 .num_resources = ARRAY_SIZE(bfin_spi0_resource),
324 .resource = bfin_spi0_resource,
326 .platform_data = &bfin_spi0_info, /* Passed to driver */
331 static struct bfin5xx_spi_master bfin_spi1_info = {
333 .enable_dma = 1, /* master has the ability to do dma transfer */
334 .pin_req = {P_SPI1_SCK, P_SPI1_MISO, P_SPI1_MOSI, 0},
337 static struct resource bfin_spi1_resource[] = {
339 .start = SPI1_REGBASE,
340 .end = SPI1_REGBASE + 0xFF,
341 .flags = IORESOURCE_MEM,
346 .flags = IORESOURCE_DMA,
351 .flags = IORESOURCE_IRQ,
355 static struct platform_device bfin_spi1_device = {
357 .id = 1, /* Bus number */
358 .num_resources = ARRAY_SIZE(bfin_spi1_resource),
359 .resource = bfin_spi1_resource,
361 .platform_data = &bfin_spi1_info, /* Passed to driver */
364 #endif /* spi master and devices */
366 #if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
367 #ifdef CONFIG_SERIAL_BFIN_UART0
368 static struct resource bfin_uart0_resources[] = {
372 .flags = IORESOURCE_MEM,
375 .start = IRQ_UART0_RX,
376 .end = IRQ_UART0_RX+1,
377 .flags = IORESOURCE_IRQ,
380 .start = IRQ_UART0_ERROR,
381 .end = IRQ_UART0_ERROR,
382 .flags = IORESOURCE_IRQ,
385 .start = CH_UART0_TX,
387 .flags = IORESOURCE_DMA,
390 .start = CH_UART0_RX,
392 .flags = IORESOURCE_DMA,
396 static unsigned short bfin_uart0_peripherals[] = {
397 P_UART0_TX, P_UART0_RX, 0
400 static struct platform_device bfin_uart0_device = {
403 .num_resources = ARRAY_SIZE(bfin_uart0_resources),
404 .resource = bfin_uart0_resources,
406 .platform_data = &bfin_uart0_peripherals, /* Passed to driver */
410 #ifdef CONFIG_SERIAL_BFIN_UART1
411 static struct resource bfin_uart1_resources[] = {
415 .flags = IORESOURCE_MEM,
418 .start = IRQ_UART1_RX,
419 .end = IRQ_UART1_RX+1,
420 .flags = IORESOURCE_IRQ,
423 .start = IRQ_UART1_ERROR,
424 .end = IRQ_UART1_ERROR,
425 .flags = IORESOURCE_IRQ,
428 .start = CH_UART1_TX,
430 .flags = IORESOURCE_DMA,
433 .start = CH_UART1_RX,
435 .flags = IORESOURCE_DMA,
439 static unsigned short bfin_uart1_peripherals[] = {
440 P_UART1_TX, P_UART1_RX, 0
443 static struct platform_device bfin_uart1_device = {
446 .num_resources = ARRAY_SIZE(bfin_uart1_resources),
447 .resource = bfin_uart1_resources,
449 .platform_data = &bfin_uart1_peripherals, /* Passed to driver */
455 #if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
456 #ifdef CONFIG_BFIN_SIR0
457 static struct resource bfin_sir0_resources[] = {
461 .flags = IORESOURCE_MEM,
464 .start = IRQ_UART0_RX,
465 .end = IRQ_UART0_RX+1,
466 .flags = IORESOURCE_IRQ,
469 .start = CH_UART0_RX,
470 .end = CH_UART0_RX+1,
471 .flags = IORESOURCE_DMA,
475 static struct platform_device bfin_sir0_device = {
478 .num_resources = ARRAY_SIZE(bfin_sir0_resources),
479 .resource = bfin_sir0_resources,
482 #ifdef CONFIG_BFIN_SIR1
483 static struct resource bfin_sir1_resources[] = {
487 .flags = IORESOURCE_MEM,
490 .start = IRQ_UART1_RX,
491 .end = IRQ_UART1_RX+1,
492 .flags = IORESOURCE_IRQ,
495 .start = CH_UART1_RX,
496 .end = CH_UART1_RX+1,
497 .flags = IORESOURCE_DMA,
501 static struct platform_device bfin_sir1_device = {
504 .num_resources = ARRAY_SIZE(bfin_sir1_resources),
505 .resource = bfin_sir1_resources,
510 #if defined(CONFIG_SND_BF5XX_I2S) || defined(CONFIG_SND_BF5XX_I2S_MODULE)
511 static struct platform_device bfin_i2s = {
513 .id = CONFIG_SND_BF5XX_SPORT_NUM,
514 /* TODO: add platform data here */
518 #if defined(CONFIG_I2C_BLACKFIN_TWI) || defined(CONFIG_I2C_BLACKFIN_TWI_MODULE)
519 static struct resource bfin_twi0_resource[] = {
521 .start = TWI0_REGBASE,
523 .flags = IORESOURCE_MEM,
528 .flags = IORESOURCE_IRQ,
532 static struct platform_device i2c_bfin_twi_device = {
533 .name = "i2c-bfin-twi",
535 .num_resources = ARRAY_SIZE(bfin_twi0_resource),
536 .resource = bfin_twi0_resource,
540 static struct i2c_board_info __initdata bfin_i2c_board_info[] = {
541 #if defined(CONFIG_BFIN_TWI_LCD) || defined(CONFIG_BFIN_TWI_LCD_MODULE)
543 I2C_BOARD_INFO("pcf8574_lcd", 0x22),
546 #if defined(CONFIG_INPUT_PCF8574) || defined(CONFIG_INPUT_PCF8574_MODULE)
548 I2C_BOARD_INFO("pcf8574_keypad", 0x27),
552 #if defined(CONFIG_SND_SOC_SSM2602) || defined(CONFIG_SND_SOC_SSM2602_MODULE)
554 I2C_BOARD_INFO("ssm2602", 0x1b),
559 #if defined(CONFIG_SERIAL_BFIN_SPORT) || defined(CONFIG_SERIAL_BFIN_SPORT_MODULE)
560 #ifdef CONFIG_SERIAL_BFIN_SPORT0_UART
561 static struct resource bfin_sport0_uart_resources[] = {
563 .start = SPORT0_TCR1,
564 .end = SPORT0_MRCS3+4,
565 .flags = IORESOURCE_MEM,
568 .start = IRQ_SPORT0_RX,
569 .end = IRQ_SPORT0_RX+1,
570 .flags = IORESOURCE_IRQ,
573 .start = IRQ_SPORT0_ERROR,
574 .end = IRQ_SPORT0_ERROR,
575 .flags = IORESOURCE_IRQ,
579 static unsigned short bfin_sport0_peripherals[] = {
580 P_SPORT0_TFS, P_SPORT0_DTPRI, P_SPORT0_TSCLK, P_SPORT0_RFS,
581 P_SPORT0_DRPRI, P_SPORT0_RSCLK, 0
584 static struct platform_device bfin_sport0_uart_device = {
585 .name = "bfin-sport-uart",
587 .num_resources = ARRAY_SIZE(bfin_sport0_uart_resources),
588 .resource = bfin_sport0_uart_resources,
590 .platform_data = &bfin_sport0_peripherals, /* Passed to driver */
594 #ifdef CONFIG_SERIAL_BFIN_SPORT1_UART
595 static struct resource bfin_sport1_uart_resources[] = {
597 .start = SPORT1_TCR1,
598 .end = SPORT1_MRCS3+4,
599 .flags = IORESOURCE_MEM,
602 .start = IRQ_SPORT1_RX,
603 .end = IRQ_SPORT1_RX+1,
604 .flags = IORESOURCE_IRQ,
607 .start = IRQ_SPORT1_ERROR,
608 .end = IRQ_SPORT1_ERROR,
609 .flags = IORESOURCE_IRQ,
613 static unsigned short bfin_sport1_peripherals[] = {
614 P_SPORT1_TFS, P_SPORT1_DTPRI, P_SPORT1_TSCLK, P_SPORT1_RFS,
615 P_SPORT1_DRPRI, P_SPORT1_RSCLK, 0
618 static struct platform_device bfin_sport1_uart_device = {
619 .name = "bfin-sport-uart",
621 .num_resources = ARRAY_SIZE(bfin_sport1_uart_resources),
622 .resource = bfin_sport1_uart_resources,
624 .platform_data = &bfin_sport1_peripherals, /* Passed to driver */
630 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
631 #include <linux/input.h>
632 #include <linux/gpio_keys.h>
634 static struct gpio_keys_button bfin_gpio_keys_table[] = {
635 {BTN_0, GPIO_PG0, 1, "gpio-keys: BTN0"},
636 {BTN_1, GPIO_PG13, 1, "gpio-keys: BTN1"},
639 static struct gpio_keys_platform_data bfin_gpio_keys_data = {
640 .buttons = bfin_gpio_keys_table,
641 .nbuttons = ARRAY_SIZE(bfin_gpio_keys_table),
644 static struct platform_device bfin_device_gpiokeys = {
647 .platform_data = &bfin_gpio_keys_data,
652 #if defined(CONFIG_SDH_BFIN) || defined(CONFIG_SDH_BFIN_MODULE)
654 static struct bfin_sd_host bfin_sdh_data = {
656 .irq_int0 = IRQ_RSI_INT0,
657 .pin_req = {P_RSI_DATA0, P_RSI_DATA1, P_RSI_DATA2, P_RSI_DATA3, P_RSI_CMD, P_RSI_CLK, 0},
660 static struct platform_device bf51x_sdh_device = {
664 .platform_data = &bfin_sdh_data,
669 static const unsigned int cclk_vlev_datasheet[] =
671 VRPAIR(VLEV_100, 400000000),
672 VRPAIR(VLEV_105, 426000000),
673 VRPAIR(VLEV_110, 500000000),
674 VRPAIR(VLEV_115, 533000000),
675 VRPAIR(VLEV_120, 600000000),
678 static struct bfin_dpmc_platform_data bfin_dmpc_vreg_data = {
679 .tuple_tab = cclk_vlev_datasheet,
680 .tabsize = ARRAY_SIZE(cclk_vlev_datasheet),
681 .vr_settling_time = 25 /* us */,
684 static struct platform_device bfin_dpmc = {
687 .platform_data = &bfin_dmpc_vreg_data,
691 static struct platform_device *stamp_devices[] __initdata = {
695 #if defined(CONFIG_RTC_DRV_BFIN) || defined(CONFIG_RTC_DRV_BFIN_MODULE)
699 #if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
702 #if defined(CONFIG_NET_DSA_KSZ8893M) || defined(CONFIG_NET_DSA_KSZ8893M_MODULE)
703 &ksz8893m_switch_device,
707 #if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
712 #if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
713 #ifdef CONFIG_SERIAL_BFIN_UART0
716 #ifdef CONFIG_SERIAL_BFIN_UART1
721 #if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
722 #ifdef CONFIG_BFIN_SIR0
725 #ifdef CONFIG_BFIN_SIR1
730 #if defined(CONFIG_I2C_BLACKFIN_TWI) || defined(CONFIG_I2C_BLACKFIN_TWI_MODULE)
731 &i2c_bfin_twi_device,
734 #if defined(CONFIG_SND_BF5XX_I2S) || defined(CONFIG_SND_BF5XX_I2S_MODULE)
738 #if defined(CONFIG_SERIAL_BFIN_SPORT) || defined(CONFIG_SERIAL_BFIN_SPORT_MODULE)
739 #ifdef CONFIG_SERIAL_BFIN_SPORT0_UART
740 &bfin_sport0_uart_device,
742 #ifdef CONFIG_SERIAL_BFIN_SPORT1_UART
743 &bfin_sport1_uart_device,
747 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
748 &bfin_device_gpiokeys,
751 #if defined(CONFIG_SDH_BFIN) || defined(CONFIG_SDH_BFIN_MODULE)
755 #if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
760 static int __init ezbrd_init(void)
762 printk(KERN_INFO "%s(): registering device resources\n", __func__);
763 i2c_register_board_info(0, bfin_i2c_board_info,
764 ARRAY_SIZE(bfin_i2c_board_info));
765 platform_add_devices(stamp_devices, ARRAY_SIZE(stamp_devices));
766 spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info));
767 /* setup BF518-EZBRD GPIO pin PG11 to AMS2, PG15 to AMS3. */
768 peripheral_request(P_AMS2, "ParaFlash");
769 #if !defined(CONFIG_SPI_BFIN) && !defined(CONFIG_SPI_BFIN_MODULE)
770 peripheral_request(P_AMS3, "ParaFlash");
775 arch_initcall(ezbrd_init);
777 static struct platform_device *ezbrd_early_devices[] __initdata = {
778 #if defined(CONFIG_SERIAL_BFIN_CONSOLE) || defined(CONFIG_EARLY_PRINTK)
779 #ifdef CONFIG_SERIAL_BFIN_UART0
782 #ifdef CONFIG_SERIAL_BFIN_UART1
787 #if defined(CONFIG_SERIAL_BFIN_SPORT_CONSOLE)
788 #ifdef CONFIG_SERIAL_BFIN_SPORT0_UART
789 &bfin_sport0_uart_device,
791 #ifdef CONFIG_SERIAL_BFIN_SPORT1_UART
792 &bfin_sport1_uart_device,
797 void __init native_machine_early_platform_add_devices(void)
799 printk(KERN_INFO "register early platform devices\n");
800 early_platform_add_devices(ezbrd_early_devices,
801 ARRAY_SIZE(ezbrd_early_devices));
804 void native_machine_restart(char *cmd)
806 /* workaround reboot hang when booting from SPI */
807 if ((bfin_read_SYSCR() & 0x7) == 0x3)
808 bfin_reset_boot_spi_cs(P_DEFAULT_BOOT_SPI_CS);
811 void bfin_get_ether_addr(char *addr)
813 /* the MAC is stored in OTP memory page 0xDF */
816 u32 (*otp_read)(u32 page, u32 flags, u64 *page_content) = (void *)0xEF00001A;
818 ret = otp_read(0xDF, 0x00, &otp_mac);
820 char *otp_mac_p = (char *)&otp_mac;
821 for (ret = 0; ret < 6; ++ret)
822 addr[ret] = otp_mac_p[5 - ret];
825 EXPORT_SYMBOL(bfin_get_ether_addr);