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>
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 IS_ENABLED(CONFIG_MTD_PHYSMAP)
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 IS_ENABLED(CONFIG_SPI_BFIN5XX)
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 IS_ENABLED(CONFIG_RTC_DRV_BFIN)
83 static struct platform_device rtc_device
= {
89 #if IS_ENABLED(CONFIG_BFIN_MAC)
90 #include <linux/bfin_mac.h>
91 static const unsigned short bfin_mac_peripherals
[] = {
105 static struct bfin_phydev_platform_data bfin_phydev_data
[] = {
108 .irq
= IRQ_MAC_PHYINT
,
112 static struct bfin_mii_bus_platform_data bfin_mii_bus_data
= {
114 .phydev_data
= bfin_phydev_data
,
115 .phy_mode
= PHY_INTERFACE_MODE_MII
,
116 .mac_peripherals
= bfin_mac_peripherals
,
121 static struct platform_device bfin_mii_bus
= {
122 .name
= "bfin_mii_bus",
124 .platform_data
= &bfin_mii_bus_data
,
128 static struct platform_device bfin_mac_device
= {
131 .platform_data
= &bfin_mii_bus
,
137 #if IS_ENABLED(CONFIG_MTD_M25P80)
138 static struct mtd_partition bfin_spi_flash_partitions
[] = {
140 .name
= "bootloader(spi)",
143 .mask_flags
= MTD_CAP_ROM
145 .name
= "linux kernel(spi)",
146 .size
= MTDPART_SIZ_FULL
,
147 .offset
= MTDPART_OFS_APPEND
,
151 static struct flash_platform_data bfin_spi_flash_data
= {
153 .parts
= bfin_spi_flash_partitions
,
154 .nr_parts
= ARRAY_SIZE(bfin_spi_flash_partitions
),
158 /* SPI flash chip (m25p64) */
159 static struct bfin5xx_spi_chip spi_flash_chip_info
= {
160 .enable_dma
= 0, /* use dma transfer with this chip*/
164 #if IS_ENABLED(CONFIG_MMC_SPI)
165 static struct bfin5xx_spi_chip mmc_spi_chip_info
= {
170 #if IS_ENABLED(CONFIG_TOUCHSCREEN_AD7877)
171 static const struct ad7877_platform_data bfin_ad7877_ts_info
= {
173 .vref_delay_usecs
= 50, /* internal, no capacitor */
176 .pressure_max
= 1000,
178 .stopacq_polarity
= 1,
179 .first_conversion_delay
= 3,
180 .acquisition_time
= 1,
182 .pen_down_acc_interval
= 1,
186 static struct spi_board_info bfin_spi_board_info
[] __initdata
= {
187 #if IS_ENABLED(CONFIG_MTD_M25P80)
189 /* the modalias must be the same as spi device driver name */
190 .modalias
= "m25p80", /* Name of spi_driver for this device */
191 .max_speed_hz
= 25000000, /* max spi clock (SCK) speed in HZ */
192 .bus_num
= 0, /* Framework bus number */
193 .chip_select
= 2, /* On BF518F-EZBRD it's SPI0_SSEL2 */
194 .platform_data
= &bfin_spi_flash_data
,
195 .controller_data
= &spi_flash_chip_info
,
200 #if IS_ENABLED(CONFIG_MMC_SPI)
202 .modalias
= "mmc_spi",
203 .max_speed_hz
= 25000000, /* max spi clock (SCK) speed in HZ */
206 .controller_data
= &mmc_spi_chip_info
,
210 #if IS_ENABLED(CONFIG_TOUCHSCREEN_AD7877)
212 .modalias
= "ad7877",
213 .platform_data
= &bfin_ad7877_ts_info
,
215 .max_speed_hz
= 12500000, /* max spi clock (SCK) speed in HZ */
220 #if IS_ENABLED(CONFIG_SND_SOC_WM8731) \
221 && defined(CONFIG_SND_SOC_WM8731_SPI)
223 .modalias
= "wm8731",
224 .max_speed_hz
= 3125000, /* max spi clock (SCK) speed in HZ */
230 #if IS_ENABLED(CONFIG_SPI_SPIDEV)
232 .modalias
= "spidev",
233 .max_speed_hz
= 3125000, /* max spi clock (SCK) speed in HZ */
238 #if IS_ENABLED(CONFIG_FB_BFIN_LQ035Q1)
240 .modalias
= "bfin-lq035q1-spi",
241 .max_speed_hz
= 20000000, /* max spi clock (SCK) speed in HZ */
244 .mode
= SPI_CPHA
| SPI_CPOL
,
249 /* SPI controller data */
250 #if IS_ENABLED(CONFIG_SPI_BFIN5XX)
252 static struct bfin5xx_spi_master bfin_spi0_info
= {
254 .enable_dma
= 1, /* master has the ability to do dma transfer */
255 .pin_req
= {P_SPI0_SCK
, P_SPI0_MISO
, P_SPI0_MOSI
, 0},
258 static struct resource bfin_spi0_resource
[] = {
260 .start
= SPI0_REGBASE
,
261 .end
= SPI0_REGBASE
+ 0xFF,
262 .flags
= IORESOURCE_MEM
,
267 .flags
= IORESOURCE_DMA
,
272 .flags
= IORESOURCE_IRQ
,
276 static struct platform_device bfin_spi0_device
= {
278 .id
= 0, /* Bus number */
279 .num_resources
= ARRAY_SIZE(bfin_spi0_resource
),
280 .resource
= bfin_spi0_resource
,
282 .platform_data
= &bfin_spi0_info
, /* Passed to driver */
287 static struct bfin5xx_spi_master bfin_spi1_info
= {
289 .enable_dma
= 1, /* master has the ability to do dma transfer */
290 .pin_req
= {P_SPI1_SCK
, P_SPI1_MISO
, P_SPI1_MOSI
, 0},
293 static struct resource bfin_spi1_resource
[] = {
295 .start
= SPI1_REGBASE
,
296 .end
= SPI1_REGBASE
+ 0xFF,
297 .flags
= IORESOURCE_MEM
,
302 .flags
= IORESOURCE_DMA
,
307 .flags
= IORESOURCE_IRQ
,
311 static struct platform_device bfin_spi1_device
= {
313 .id
= 1, /* Bus number */
314 .num_resources
= ARRAY_SIZE(bfin_spi1_resource
),
315 .resource
= bfin_spi1_resource
,
317 .platform_data
= &bfin_spi1_info
, /* Passed to driver */
320 #endif /* spi master and devices */
322 #if IS_ENABLED(CONFIG_SERIAL_BFIN)
323 #ifdef CONFIG_SERIAL_BFIN_UART0
324 static struct resource bfin_uart0_resources
[] = {
328 .flags
= IORESOURCE_MEM
,
331 .start
= IRQ_UART0_TX
,
333 .flags
= IORESOURCE_IRQ
,
336 .start
= IRQ_UART0_RX
,
338 .flags
= IORESOURCE_IRQ
,
341 .start
= IRQ_UART0_ERROR
,
342 .end
= IRQ_UART0_ERROR
,
343 .flags
= IORESOURCE_IRQ
,
346 .start
= CH_UART0_TX
,
348 .flags
= IORESOURCE_DMA
,
351 .start
= CH_UART0_RX
,
353 .flags
= IORESOURCE_DMA
,
357 static unsigned short bfin_uart0_peripherals
[] = {
358 P_UART0_TX
, P_UART0_RX
, 0
361 static struct platform_device bfin_uart0_device
= {
364 .num_resources
= ARRAY_SIZE(bfin_uart0_resources
),
365 .resource
= bfin_uart0_resources
,
367 .platform_data
= &bfin_uart0_peripherals
, /* Passed to driver */
371 #ifdef CONFIG_SERIAL_BFIN_UART1
372 static struct resource bfin_uart1_resources
[] = {
376 .flags
= IORESOURCE_MEM
,
379 .start
= IRQ_UART1_TX
,
381 .flags
= IORESOURCE_IRQ
,
384 .start
= IRQ_UART1_RX
,
386 .flags
= IORESOURCE_IRQ
,
389 .start
= IRQ_UART1_ERROR
,
390 .end
= IRQ_UART1_ERROR
,
391 .flags
= IORESOURCE_IRQ
,
394 .start
= CH_UART1_TX
,
396 .flags
= IORESOURCE_DMA
,
399 .start
= CH_UART1_RX
,
401 .flags
= IORESOURCE_DMA
,
405 static unsigned short bfin_uart1_peripherals
[] = {
406 P_UART1_TX
, P_UART1_RX
, 0
409 static struct platform_device bfin_uart1_device
= {
412 .num_resources
= ARRAY_SIZE(bfin_uart1_resources
),
413 .resource
= bfin_uart1_resources
,
415 .platform_data
= &bfin_uart1_peripherals
, /* Passed to driver */
421 #if IS_ENABLED(CONFIG_BFIN_SIR)
422 #ifdef CONFIG_BFIN_SIR0
423 static struct resource bfin_sir0_resources
[] = {
427 .flags
= IORESOURCE_MEM
,
430 .start
= IRQ_UART0_RX
,
431 .end
= IRQ_UART0_RX
+1,
432 .flags
= IORESOURCE_IRQ
,
435 .start
= CH_UART0_RX
,
436 .end
= CH_UART0_RX
+1,
437 .flags
= IORESOURCE_DMA
,
441 static struct platform_device bfin_sir0_device
= {
444 .num_resources
= ARRAY_SIZE(bfin_sir0_resources
),
445 .resource
= bfin_sir0_resources
,
448 #ifdef CONFIG_BFIN_SIR1
449 static struct resource bfin_sir1_resources
[] = {
453 .flags
= IORESOURCE_MEM
,
456 .start
= IRQ_UART1_RX
,
457 .end
= IRQ_UART1_RX
+1,
458 .flags
= IORESOURCE_IRQ
,
461 .start
= CH_UART1_RX
,
462 .end
= CH_UART1_RX
+1,
463 .flags
= IORESOURCE_DMA
,
467 static struct platform_device bfin_sir1_device
= {
470 .num_resources
= ARRAY_SIZE(bfin_sir1_resources
),
471 .resource
= bfin_sir1_resources
,
476 #if IS_ENABLED(CONFIG_SND_BF5XX_I2S)
477 static struct platform_device bfin_i2s
= {
479 .id
= CONFIG_SND_BF5XX_SPORT_NUM
,
480 /* TODO: add platform data here */
484 #if IS_ENABLED(CONFIG_I2C_BLACKFIN_TWI)
485 static const u16 bfin_twi0_pins
[] = {P_TWI0_SCL
, P_TWI0_SDA
, 0};
487 static struct resource bfin_twi0_resource
[] = {
489 .start
= TWI0_REGBASE
,
491 .flags
= IORESOURCE_MEM
,
496 .flags
= IORESOURCE_IRQ
,
500 static struct platform_device i2c_bfin_twi_device
= {
501 .name
= "i2c-bfin-twi",
503 .num_resources
= ARRAY_SIZE(bfin_twi0_resource
),
504 .resource
= bfin_twi0_resource
,
506 .platform_data
= &bfin_twi0_pins
,
511 static struct i2c_board_info __initdata bfin_i2c_board_info
[] = {
512 #if IS_ENABLED(CONFIG_BFIN_TWI_LCD)
514 I2C_BOARD_INFO("pcf8574_lcd", 0x22),
517 #if IS_ENABLED(CONFIG_INPUT_PCF8574)
519 I2C_BOARD_INFO("pcf8574_keypad", 0x27),
523 #if IS_ENABLED(CONFIG_SND_SOC_SSM2602)
525 I2C_BOARD_INFO("ssm2602", 0x1b),
530 #if IS_ENABLED(CONFIG_SERIAL_BFIN_SPORT)
531 #ifdef CONFIG_SERIAL_BFIN_SPORT0_UART
532 static struct resource bfin_sport0_uart_resources
[] = {
534 .start
= SPORT0_TCR1
,
535 .end
= SPORT0_MRCS3
+4,
536 .flags
= IORESOURCE_MEM
,
539 .start
= IRQ_SPORT0_RX
,
540 .end
= IRQ_SPORT0_RX
+1,
541 .flags
= IORESOURCE_IRQ
,
544 .start
= IRQ_SPORT0_ERROR
,
545 .end
= IRQ_SPORT0_ERROR
,
546 .flags
= IORESOURCE_IRQ
,
550 static unsigned short bfin_sport0_peripherals
[] = {
551 P_SPORT0_TFS
, P_SPORT0_DTPRI
, P_SPORT0_TSCLK
, P_SPORT0_RFS
,
552 P_SPORT0_DRPRI
, P_SPORT0_RSCLK
, 0
555 static struct platform_device bfin_sport0_uart_device
= {
556 .name
= "bfin-sport-uart",
558 .num_resources
= ARRAY_SIZE(bfin_sport0_uart_resources
),
559 .resource
= bfin_sport0_uart_resources
,
561 .platform_data
= &bfin_sport0_peripherals
, /* Passed to driver */
565 #ifdef CONFIG_SERIAL_BFIN_SPORT1_UART
566 static struct resource bfin_sport1_uart_resources
[] = {
568 .start
= SPORT1_TCR1
,
569 .end
= SPORT1_MRCS3
+4,
570 .flags
= IORESOURCE_MEM
,
573 .start
= IRQ_SPORT1_RX
,
574 .end
= IRQ_SPORT1_RX
+1,
575 .flags
= IORESOURCE_IRQ
,
578 .start
= IRQ_SPORT1_ERROR
,
579 .end
= IRQ_SPORT1_ERROR
,
580 .flags
= IORESOURCE_IRQ
,
584 static unsigned short bfin_sport1_peripherals
[] = {
585 P_SPORT1_TFS
, P_SPORT1_DTPRI
, P_SPORT1_TSCLK
, P_SPORT1_RFS
,
586 P_SPORT1_DRPRI
, P_SPORT1_RSCLK
, 0
589 static struct platform_device bfin_sport1_uart_device
= {
590 .name
= "bfin-sport-uart",
592 .num_resources
= ARRAY_SIZE(bfin_sport1_uart_resources
),
593 .resource
= bfin_sport1_uart_resources
,
595 .platform_data
= &bfin_sport1_peripherals
, /* Passed to driver */
601 #if IS_ENABLED(CONFIG_KEYBOARD_GPIO)
602 #include <linux/input.h>
603 #include <linux/gpio_keys.h>
605 static struct gpio_keys_button bfin_gpio_keys_table
[] = {
606 {BTN_0
, GPIO_PG0
, 1, "gpio-keys: BTN0"},
607 {BTN_1
, GPIO_PG13
, 1, "gpio-keys: BTN1"},
610 static struct gpio_keys_platform_data bfin_gpio_keys_data
= {
611 .buttons
= bfin_gpio_keys_table
,
612 .nbuttons
= ARRAY_SIZE(bfin_gpio_keys_table
),
615 static struct platform_device bfin_device_gpiokeys
= {
618 .platform_data
= &bfin_gpio_keys_data
,
623 #if IS_ENABLED(CONFIG_SDH_BFIN)
625 static struct bfin_sd_host bfin_sdh_data
= {
627 .irq_int0
= IRQ_RSI_INT0
,
628 .pin_req
= {P_RSI_DATA0
, P_RSI_DATA1
, P_RSI_DATA2
, P_RSI_DATA3
, P_RSI_CMD
, P_RSI_CLK
, 0},
631 static struct platform_device bf51x_sdh_device
= {
635 .platform_data
= &bfin_sdh_data
,
640 static const unsigned int cclk_vlev_datasheet
[] =
642 VRPAIR(VLEV_100
, 400000000),
643 VRPAIR(VLEV_105
, 426000000),
644 VRPAIR(VLEV_110
, 500000000),
645 VRPAIR(VLEV_115
, 533000000),
646 VRPAIR(VLEV_120
, 600000000),
649 static struct bfin_dpmc_platform_data bfin_dmpc_vreg_data
= {
650 .tuple_tab
= cclk_vlev_datasheet
,
651 .tabsize
= ARRAY_SIZE(cclk_vlev_datasheet
),
652 .vr_settling_time
= 25 /* us */,
655 static struct platform_device bfin_dpmc
= {
658 .platform_data
= &bfin_dmpc_vreg_data
,
662 static struct platform_device
*stamp_devices
[] __initdata
= {
666 #if IS_ENABLED(CONFIG_RTC_DRV_BFIN)
670 #if IS_ENABLED(CONFIG_BFIN_MAC)
675 #if IS_ENABLED(CONFIG_SPI_BFIN5XX)
680 #if IS_ENABLED(CONFIG_SERIAL_BFIN)
681 #ifdef CONFIG_SERIAL_BFIN_UART0
684 #ifdef CONFIG_SERIAL_BFIN_UART1
689 #if IS_ENABLED(CONFIG_BFIN_SIR)
690 #ifdef CONFIG_BFIN_SIR0
693 #ifdef CONFIG_BFIN_SIR1
698 #if IS_ENABLED(CONFIG_I2C_BLACKFIN_TWI)
699 &i2c_bfin_twi_device
,
702 #if IS_ENABLED(CONFIG_SND_BF5XX_I2S)
706 #if IS_ENABLED(CONFIG_SERIAL_BFIN_SPORT)
707 #ifdef CONFIG_SERIAL_BFIN_SPORT0_UART
708 &bfin_sport0_uart_device
,
710 #ifdef CONFIG_SERIAL_BFIN_SPORT1_UART
711 &bfin_sport1_uart_device
,
715 #if IS_ENABLED(CONFIG_KEYBOARD_GPIO)
716 &bfin_device_gpiokeys
,
719 #if IS_ENABLED(CONFIG_SDH_BFIN)
723 #if IS_ENABLED(CONFIG_MTD_PHYSMAP)
728 static int __init
ezbrd_init(void)
730 printk(KERN_INFO
"%s(): registering device resources\n", __func__
);
731 i2c_register_board_info(0, bfin_i2c_board_info
,
732 ARRAY_SIZE(bfin_i2c_board_info
));
733 platform_add_devices(stamp_devices
, ARRAY_SIZE(stamp_devices
));
734 spi_register_board_info(bfin_spi_board_info
, ARRAY_SIZE(bfin_spi_board_info
));
735 /* setup BF518-EZBRD GPIO pin PG11 to AMS2, PG15 to AMS3. */
736 peripheral_request(P_AMS2
, "ParaFlash");
737 #if !IS_ENABLED(CONFIG_SPI_BFIN5XX)
738 peripheral_request(P_AMS3
, "ParaFlash");
743 arch_initcall(ezbrd_init
);
745 static struct platform_device
*ezbrd_early_devices
[] __initdata
= {
746 #if defined(CONFIG_SERIAL_BFIN_CONSOLE) || defined(CONFIG_EARLY_PRINTK)
747 #ifdef CONFIG_SERIAL_BFIN_UART0
750 #ifdef CONFIG_SERIAL_BFIN_UART1
755 #if defined(CONFIG_SERIAL_BFIN_SPORT_CONSOLE)
756 #ifdef CONFIG_SERIAL_BFIN_SPORT0_UART
757 &bfin_sport0_uart_device
,
759 #ifdef CONFIG_SERIAL_BFIN_SPORT1_UART
760 &bfin_sport1_uart_device
,
765 void __init
native_machine_early_platform_add_devices(void)
767 printk(KERN_INFO
"register early platform devices\n");
768 early_platform_add_devices(ezbrd_early_devices
,
769 ARRAY_SIZE(ezbrd_early_devices
));
772 void native_machine_restart(char *cmd
)
774 /* workaround reboot hang when booting from SPI */
775 if ((bfin_read_SYSCR() & 0x7) == 0x3)
776 bfin_reset_boot_spi_cs(P_DEFAULT_BOOT_SPI_CS
);
779 int bfin_get_ether_addr(char *addr
)
781 /* the MAC is stored in OTP memory page 0xDF */
784 u32 (*otp_read
)(u32 page
, u32 flags
, u64
*page_content
) = (void *)0xEF00001A;
786 ret
= otp_read(0xDF, 0x00, &otp_mac
);
788 char *otp_mac_p
= (char *)&otp_mac
;
789 for (ret
= 0; ret
< 6; ++ret
)
790 addr
[ret
] = otp_mac_p
[5 - ret
];
794 EXPORT_SYMBOL(bfin_get_ether_addr
);