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/etherdevice.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
[] = "Bluetechnix TCM-BF518";
35 * Driver needs to know address, irq and flag pin.
38 #if IS_ENABLED(CONFIG_MTD_PHYSMAP)
39 static struct mtd_partition tcm_partitions
[] = {
41 .name
= "bootloader(nor)",
48 .offset
= MTDPART_OFS_APPEND
,
52 static struct physmap_flash_data tcm_flash_data
= {
54 .parts
= tcm_partitions
,
55 .nr_parts
= ARRAY_SIZE(tcm_partitions
),
58 static struct resource tcm_flash_resource
= {
61 .flags
= IORESOURCE_MEM
,
64 static struct platform_device tcm_flash_device
= {
65 .name
= "physmap-flash",
68 .platform_data
= &tcm_flash_data
,
71 .resource
= &tcm_flash_resource
,
75 #if IS_ENABLED(CONFIG_RTC_DRV_BFIN)
76 static struct platform_device rtc_device
= {
82 #if IS_ENABLED(CONFIG_BFIN_MAC)
83 #include <linux/bfin_mac.h>
84 static const unsigned short bfin_mac_peripherals
[] = P_MII0
;
86 static struct bfin_phydev_platform_data bfin_phydev_data
[] = {
89 .irq
= IRQ_MAC_PHYINT
,
93 static struct bfin_mii_bus_platform_data bfin_mii_bus_data
= {
95 .phydev_data
= bfin_phydev_data
,
96 .phy_mode
= PHY_INTERFACE_MODE_MII
,
97 .mac_peripherals
= bfin_mac_peripherals
,
100 static struct platform_device bfin_mii_bus
= {
101 .name
= "bfin_mii_bus",
103 .platform_data
= &bfin_mii_bus_data
,
107 static struct platform_device bfin_mac_device
= {
110 .platform_data
= &bfin_mii_bus
,
115 #if IS_ENABLED(CONFIG_MTD_M25P80)
116 static struct mtd_partition bfin_spi_flash_partitions
[] = {
118 .name
= "bootloader(spi)",
121 .mask_flags
= MTD_CAP_ROM
123 .name
= "linux kernel(spi)",
124 .size
= MTDPART_SIZ_FULL
,
125 .offset
= MTDPART_OFS_APPEND
,
129 static struct flash_platform_data bfin_spi_flash_data
= {
131 .parts
= bfin_spi_flash_partitions
,
132 .nr_parts
= ARRAY_SIZE(bfin_spi_flash_partitions
),
136 /* SPI flash chip (m25p64) */
137 static struct bfin5xx_spi_chip spi_flash_chip_info
= {
138 .enable_dma
= 0, /* use dma transfer with this chip*/
142 #if IS_ENABLED(CONFIG_MMC_SPI)
143 static struct bfin5xx_spi_chip mmc_spi_chip_info
= {
148 #if IS_ENABLED(CONFIG_TOUCHSCREEN_AD7877)
149 static const struct ad7877_platform_data bfin_ad7877_ts_info
= {
151 .vref_delay_usecs
= 50, /* internal, no capacitor */
154 .pressure_max
= 1000,
156 .stopacq_polarity
= 1,
157 .first_conversion_delay
= 3,
158 .acquisition_time
= 1,
160 .pen_down_acc_interval
= 1,
164 static struct spi_board_info bfin_spi_board_info
[] __initdata
= {
165 #if IS_ENABLED(CONFIG_MTD_M25P80)
167 /* the modalias must be the same as spi device driver name */
168 .modalias
= "m25p80", /* Name of spi_driver for this device */
169 .max_speed_hz
= 25000000, /* max spi clock (SCK) speed in HZ */
170 .bus_num
= 0, /* Framework bus number */
171 .chip_select
= 2, /* SPI0_SSEL2 */
172 .platform_data
= &bfin_spi_flash_data
,
173 .controller_data
= &spi_flash_chip_info
,
178 #if IS_ENABLED(CONFIG_MMC_SPI)
180 .modalias
= "mmc_spi",
181 .max_speed_hz
= 20000000, /* max spi clock (SCK) speed in HZ */
184 .controller_data
= &mmc_spi_chip_info
,
188 #if IS_ENABLED(CONFIG_TOUCHSCREEN_AD7877)
190 .modalias
= "ad7877",
191 .platform_data
= &bfin_ad7877_ts_info
,
193 .max_speed_hz
= 12500000, /* max spi clock (SCK) speed in HZ */
198 #if IS_ENABLED(CONFIG_SND_SOC_WM8731) \
199 && defined(CONFIG_SND_SOC_WM8731_SPI)
201 .modalias
= "wm8731",
202 .max_speed_hz
= 3125000, /* max spi clock (SCK) speed in HZ */
208 #if IS_ENABLED(CONFIG_SPI_SPIDEV)
210 .modalias
= "spidev",
211 .max_speed_hz
= 3125000, /* max spi clock (SCK) speed in HZ */
216 #if IS_ENABLED(CONFIG_FB_BFIN_LQ035Q1)
218 .modalias
= "bfin-lq035q1-spi",
219 .max_speed_hz
= 20000000, /* max spi clock (SCK) speed in HZ */
222 .mode
= SPI_CPHA
| SPI_CPOL
,
227 /* SPI controller data */
228 #if IS_ENABLED(CONFIG_SPI_BFIN5XX)
230 static struct bfin5xx_spi_master bfin_spi0_info
= {
232 .enable_dma
= 1, /* master has the ability to do dma transfer */
233 .pin_req
= {P_SPI0_SCK
, P_SPI0_MISO
, P_SPI0_MOSI
, 0},
236 static struct resource bfin_spi0_resource
[] = {
238 .start
= SPI0_REGBASE
,
239 .end
= SPI0_REGBASE
+ 0xFF,
240 .flags
= IORESOURCE_MEM
,
245 .flags
= IORESOURCE_DMA
,
250 .flags
= IORESOURCE_IRQ
,
254 static struct platform_device bfin_spi0_device
= {
256 .id
= 0, /* Bus number */
257 .num_resources
= ARRAY_SIZE(bfin_spi0_resource
),
258 .resource
= bfin_spi0_resource
,
260 .platform_data
= &bfin_spi0_info
, /* Passed to driver */
265 static struct bfin5xx_spi_master bfin_spi1_info
= {
267 .enable_dma
= 1, /* master has the ability to do dma transfer */
268 .pin_req
= {P_SPI1_SCK
, P_SPI1_MISO
, P_SPI1_MOSI
, 0},
271 static struct resource bfin_spi1_resource
[] = {
273 .start
= SPI1_REGBASE
,
274 .end
= SPI1_REGBASE
+ 0xFF,
275 .flags
= IORESOURCE_MEM
,
280 .flags
= IORESOURCE_DMA
,
285 .flags
= IORESOURCE_IRQ
,
289 static struct platform_device bfin_spi1_device
= {
291 .id
= 1, /* Bus number */
292 .num_resources
= ARRAY_SIZE(bfin_spi1_resource
),
293 .resource
= bfin_spi1_resource
,
295 .platform_data
= &bfin_spi1_info
, /* Passed to driver */
298 #endif /* spi master and devices */
300 #if IS_ENABLED(CONFIG_SERIAL_BFIN)
301 #ifdef CONFIG_SERIAL_BFIN_UART0
302 static struct resource bfin_uart0_resources
[] = {
306 .flags
= IORESOURCE_MEM
,
309 .start
= IRQ_UART0_TX
,
311 .flags
= IORESOURCE_IRQ
,
314 .start
= IRQ_UART0_RX
,
316 .flags
= IORESOURCE_IRQ
,
319 .start
= IRQ_UART0_ERROR
,
320 .end
= IRQ_UART0_ERROR
,
321 .flags
= IORESOURCE_IRQ
,
324 .start
= CH_UART0_TX
,
326 .flags
= IORESOURCE_DMA
,
329 .start
= CH_UART0_RX
,
331 .flags
= IORESOURCE_DMA
,
335 static unsigned short bfin_uart0_peripherals
[] = {
336 P_UART0_TX
, P_UART0_RX
, 0
339 static struct platform_device bfin_uart0_device
= {
342 .num_resources
= ARRAY_SIZE(bfin_uart0_resources
),
343 .resource
= bfin_uart0_resources
,
345 .platform_data
= &bfin_uart0_peripherals
, /* Passed to driver */
349 #ifdef CONFIG_SERIAL_BFIN_UART1
350 static struct resource bfin_uart1_resources
[] = {
354 .flags
= IORESOURCE_MEM
,
357 .start
= IRQ_UART1_TX
,
359 .flags
= IORESOURCE_IRQ
,
362 .start
= IRQ_UART1_RX
,
364 .flags
= IORESOURCE_IRQ
,
367 .start
= IRQ_UART1_ERROR
,
368 .end
= IRQ_UART1_ERROR
,
369 .flags
= IORESOURCE_IRQ
,
372 .start
= CH_UART1_TX
,
374 .flags
= IORESOURCE_DMA
,
377 .start
= CH_UART1_RX
,
379 .flags
= IORESOURCE_DMA
,
383 static unsigned short bfin_uart1_peripherals
[] = {
384 P_UART1_TX
, P_UART1_RX
, 0
387 static struct platform_device bfin_uart1_device
= {
390 .num_resources
= ARRAY_SIZE(bfin_uart1_resources
),
391 .resource
= bfin_uart1_resources
,
393 .platform_data
= &bfin_uart1_peripherals
, /* Passed to driver */
399 #if IS_ENABLED(CONFIG_BFIN_SIR)
400 #ifdef CONFIG_BFIN_SIR0
401 static struct resource bfin_sir0_resources
[] = {
405 .flags
= IORESOURCE_MEM
,
408 .start
= IRQ_UART0_RX
,
409 .end
= IRQ_UART0_RX
+1,
410 .flags
= IORESOURCE_IRQ
,
413 .start
= CH_UART0_RX
,
414 .end
= CH_UART0_RX
+1,
415 .flags
= IORESOURCE_DMA
,
419 static struct platform_device bfin_sir0_device
= {
422 .num_resources
= ARRAY_SIZE(bfin_sir0_resources
),
423 .resource
= bfin_sir0_resources
,
426 #ifdef CONFIG_BFIN_SIR1
427 static struct resource bfin_sir1_resources
[] = {
431 .flags
= IORESOURCE_MEM
,
434 .start
= IRQ_UART1_RX
,
435 .end
= IRQ_UART1_RX
+1,
436 .flags
= IORESOURCE_IRQ
,
439 .start
= CH_UART1_RX
,
440 .end
= CH_UART1_RX
+1,
441 .flags
= IORESOURCE_DMA
,
445 static struct platform_device bfin_sir1_device
= {
448 .num_resources
= ARRAY_SIZE(bfin_sir1_resources
),
449 .resource
= bfin_sir1_resources
,
454 #if IS_ENABLED(CONFIG_I2C_BLACKFIN_TWI)
455 static const u16 bfin_twi0_pins
[] = {P_TWI0_SCL
, P_TWI0_SDA
, 0};
457 static struct resource bfin_twi0_resource
[] = {
459 .start
= TWI0_REGBASE
,
461 .flags
= IORESOURCE_MEM
,
466 .flags
= IORESOURCE_IRQ
,
470 static struct platform_device i2c_bfin_twi_device
= {
471 .name
= "i2c-bfin-twi",
473 .num_resources
= ARRAY_SIZE(bfin_twi0_resource
),
474 .resource
= bfin_twi0_resource
,
476 .platform_data
= &bfin_twi0_pins
,
481 static struct i2c_board_info __initdata bfin_i2c_board_info
[] = {
482 #if IS_ENABLED(CONFIG_BFIN_TWI_LCD)
484 I2C_BOARD_INFO("pcf8574_lcd", 0x22),
487 #if IS_ENABLED(CONFIG_INPUT_PCF8574)
489 I2C_BOARD_INFO("pcf8574_keypad", 0x27),
495 #if IS_ENABLED(CONFIG_SERIAL_BFIN_SPORT)
496 #ifdef CONFIG_SERIAL_BFIN_SPORT0_UART
497 static struct resource bfin_sport0_uart_resources
[] = {
499 .start
= SPORT0_TCR1
,
500 .end
= SPORT0_MRCS3
+4,
501 .flags
= IORESOURCE_MEM
,
504 .start
= IRQ_SPORT0_RX
,
505 .end
= IRQ_SPORT0_RX
+1,
506 .flags
= IORESOURCE_IRQ
,
509 .start
= IRQ_SPORT0_ERROR
,
510 .end
= IRQ_SPORT0_ERROR
,
511 .flags
= IORESOURCE_IRQ
,
515 static unsigned short bfin_sport0_peripherals
[] = {
516 P_SPORT0_TFS
, P_SPORT0_DTPRI
, P_SPORT0_TSCLK
, P_SPORT0_RFS
,
517 P_SPORT0_DRPRI
, P_SPORT0_RSCLK
, 0
520 static struct platform_device bfin_sport0_uart_device
= {
521 .name
= "bfin-sport-uart",
523 .num_resources
= ARRAY_SIZE(bfin_sport0_uart_resources
),
524 .resource
= bfin_sport0_uart_resources
,
526 .platform_data
= &bfin_sport0_peripherals
, /* Passed to driver */
530 #ifdef CONFIG_SERIAL_BFIN_SPORT1_UART
531 static struct resource bfin_sport1_uart_resources
[] = {
533 .start
= SPORT1_TCR1
,
534 .end
= SPORT1_MRCS3
+4,
535 .flags
= IORESOURCE_MEM
,
538 .start
= IRQ_SPORT1_RX
,
539 .end
= IRQ_SPORT1_RX
+1,
540 .flags
= IORESOURCE_IRQ
,
543 .start
= IRQ_SPORT1_ERROR
,
544 .end
= IRQ_SPORT1_ERROR
,
545 .flags
= IORESOURCE_IRQ
,
549 static unsigned short bfin_sport1_peripherals
[] = {
550 P_SPORT1_TFS
, P_SPORT1_DTPRI
, P_SPORT1_TSCLK
, P_SPORT1_RFS
,
551 P_SPORT1_DRPRI
, P_SPORT1_RSCLK
, 0
554 static struct platform_device bfin_sport1_uart_device
= {
555 .name
= "bfin-sport-uart",
557 .num_resources
= ARRAY_SIZE(bfin_sport1_uart_resources
),
558 .resource
= bfin_sport1_uart_resources
,
560 .platform_data
= &bfin_sport1_peripherals
, /* Passed to driver */
566 #if IS_ENABLED(CONFIG_KEYBOARD_GPIO)
567 #include <linux/input.h>
568 #include <linux/gpio_keys.h>
570 static struct gpio_keys_button bfin_gpio_keys_table
[] = {
571 {BTN_0
, GPIO_PG0
, 1, "gpio-keys: BTN0"},
572 {BTN_1
, GPIO_PG13
, 1, "gpio-keys: BTN1"},
575 static struct gpio_keys_platform_data bfin_gpio_keys_data
= {
576 .buttons
= bfin_gpio_keys_table
,
577 .nbuttons
= ARRAY_SIZE(bfin_gpio_keys_table
),
580 static struct platform_device bfin_device_gpiokeys
= {
583 .platform_data
= &bfin_gpio_keys_data
,
588 #if IS_ENABLED(CONFIG_SDH_BFIN)
590 static struct bfin_sd_host bfin_sdh_data
= {
592 .irq_int0
= IRQ_RSI_INT0
,
593 .pin_req
= {P_RSI_DATA0
, P_RSI_DATA1
, P_RSI_DATA2
, P_RSI_DATA3
, P_RSI_CMD
, P_RSI_CLK
, 0},
596 static struct platform_device bf51x_sdh_device
= {
600 .platform_data
= &bfin_sdh_data
,
605 static const unsigned int cclk_vlev_datasheet
[] =
607 VRPAIR(VLEV_100
, 400000000),
608 VRPAIR(VLEV_105
, 426000000),
609 VRPAIR(VLEV_110
, 500000000),
610 VRPAIR(VLEV_115
, 533000000),
611 VRPAIR(VLEV_120
, 600000000),
614 static struct bfin_dpmc_platform_data bfin_dmpc_vreg_data
= {
615 .tuple_tab
= cclk_vlev_datasheet
,
616 .tabsize
= ARRAY_SIZE(cclk_vlev_datasheet
),
617 .vr_settling_time
= 25 /* us */,
620 static struct platform_device bfin_dpmc
= {
623 .platform_data
= &bfin_dmpc_vreg_data
,
627 static struct platform_device
*tcm_devices
[] __initdata
= {
631 #if IS_ENABLED(CONFIG_RTC_DRV_BFIN)
635 #if IS_ENABLED(CONFIG_BFIN_MAC)
640 #if IS_ENABLED(CONFIG_SPI_BFIN5XX)
645 #if IS_ENABLED(CONFIG_SERIAL_BFIN)
646 #ifdef CONFIG_SERIAL_BFIN_UART0
649 #ifdef CONFIG_SERIAL_BFIN_UART1
654 #if IS_ENABLED(CONFIG_BFIN_SIR)
655 #ifdef CONFIG_BFIN_SIR0
658 #ifdef CONFIG_BFIN_SIR1
663 #if IS_ENABLED(CONFIG_I2C_BLACKFIN_TWI)
664 &i2c_bfin_twi_device
,
667 #if IS_ENABLED(CONFIG_SERIAL_BFIN_SPORT)
668 #ifdef CONFIG_SERIAL_BFIN_SPORT0_UART
669 &bfin_sport0_uart_device
,
671 #ifdef CONFIG_SERIAL_BFIN_SPORT1_UART
672 &bfin_sport1_uart_device
,
676 #if IS_ENABLED(CONFIG_KEYBOARD_GPIO)
677 &bfin_device_gpiokeys
,
680 #if IS_ENABLED(CONFIG_SDH_BFIN)
684 #if IS_ENABLED(CONFIG_MTD_PHYSMAP)
689 static int __init
tcm_init(void)
691 printk(KERN_INFO
"%s(): registering device resources\n", __func__
);
692 i2c_register_board_info(0, bfin_i2c_board_info
,
693 ARRAY_SIZE(bfin_i2c_board_info
));
694 platform_add_devices(tcm_devices
, ARRAY_SIZE(tcm_devices
));
695 spi_register_board_info(bfin_spi_board_info
, ARRAY_SIZE(bfin_spi_board_info
));
699 arch_initcall(tcm_init
);
701 static struct platform_device
*tcm_early_devices
[] __initdata
= {
702 #if defined(CONFIG_SERIAL_BFIN_CONSOLE) || defined(CONFIG_EARLY_PRINTK)
703 #ifdef CONFIG_SERIAL_BFIN_UART0
706 #ifdef CONFIG_SERIAL_BFIN_UART1
711 #if defined(CONFIG_SERIAL_BFIN_SPORT_CONSOLE)
712 #ifdef CONFIG_SERIAL_BFIN_SPORT0_UART
713 &bfin_sport0_uart_device
,
715 #ifdef CONFIG_SERIAL_BFIN_SPORT1_UART
716 &bfin_sport1_uart_device
,
721 void __init
native_machine_early_platform_add_devices(void)
723 printk(KERN_INFO
"register early platform devices\n");
724 early_platform_add_devices(tcm_early_devices
,
725 ARRAY_SIZE(tcm_early_devices
));
728 void native_machine_restart(char *cmd
)
730 /* workaround reboot hang when booting from SPI */
731 if ((bfin_read_SYSCR() & 0x7) == 0x3)
732 bfin_reset_boot_spi_cs(P_DEFAULT_BOOT_SPI_CS
);
735 int bfin_get_ether_addr(char *addr
)
739 EXPORT_SYMBOL(bfin_get_ether_addr
);