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>
31 * Name the Board for the /proc/cpuinfo
33 const char bfin_board_name[] = "Bluetechnix TCM-BF518";
36 * Driver needs to know address, irq and flag pin.
39 #if IS_ENABLED(CONFIG_MTD_PHYSMAP)
40 static struct mtd_partition tcm_partitions[] = {
42 .name = "bootloader(nor)",
49 .offset = MTDPART_OFS_APPEND,
53 static struct physmap_flash_data tcm_flash_data = {
55 .parts = tcm_partitions,
56 .nr_parts = ARRAY_SIZE(tcm_partitions),
59 static struct resource tcm_flash_resource = {
62 .flags = IORESOURCE_MEM,
65 static struct platform_device tcm_flash_device = {
66 .name = "physmap-flash",
69 .platform_data = &tcm_flash_data,
72 .resource = &tcm_flash_resource,
76 #if IS_ENABLED(CONFIG_RTC_DRV_BFIN)
77 static struct platform_device rtc_device = {
83 #if IS_ENABLED(CONFIG_BFIN_MAC)
84 #include <linux/bfin_mac.h>
85 static const unsigned short bfin_mac_peripherals[] = P_MII0;
87 static struct bfin_phydev_platform_data bfin_phydev_data[] = {
90 .irq = IRQ_MAC_PHYINT,
94 static struct bfin_mii_bus_platform_data bfin_mii_bus_data = {
96 .phydev_data = bfin_phydev_data,
97 .phy_mode = PHY_INTERFACE_MODE_MII,
98 .mac_peripherals = bfin_mac_peripherals,
101 static struct platform_device bfin_mii_bus = {
102 .name = "bfin_mii_bus",
104 .platform_data = &bfin_mii_bus_data,
108 static struct platform_device bfin_mac_device = {
111 .platform_data = &bfin_mii_bus,
116 #if IS_ENABLED(CONFIG_MTD_M25P80)
117 static struct mtd_partition bfin_spi_flash_partitions[] = {
119 .name = "bootloader(spi)",
122 .mask_flags = MTD_CAP_ROM
124 .name = "linux kernel(spi)",
125 .size = MTDPART_SIZ_FULL,
126 .offset = MTDPART_OFS_APPEND,
130 static struct flash_platform_data bfin_spi_flash_data = {
132 .parts = bfin_spi_flash_partitions,
133 .nr_parts = ARRAY_SIZE(bfin_spi_flash_partitions),
137 /* SPI flash chip (m25p64) */
138 static struct bfin5xx_spi_chip spi_flash_chip_info = {
139 .enable_dma = 0, /* use dma transfer with this chip*/
143 #if IS_ENABLED(CONFIG_MMC_SPI)
144 static struct bfin5xx_spi_chip mmc_spi_chip_info = {
149 #if IS_ENABLED(CONFIG_TOUCHSCREEN_AD7877)
150 static const struct ad7877_platform_data bfin_ad7877_ts_info = {
152 .vref_delay_usecs = 50, /* internal, no capacitor */
155 .pressure_max = 1000,
157 .stopacq_polarity = 1,
158 .first_conversion_delay = 3,
159 .acquisition_time = 1,
161 .pen_down_acc_interval = 1,
165 static struct spi_board_info bfin_spi_board_info[] __initdata = {
166 #if IS_ENABLED(CONFIG_MTD_M25P80)
168 /* the modalias must be the same as spi device driver name */
169 .modalias = "m25p80", /* Name of spi_driver for this device */
170 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */
171 .bus_num = 0, /* Framework bus number */
172 .chip_select = 2, /* SPI0_SSEL2 */
173 .platform_data = &bfin_spi_flash_data,
174 .controller_data = &spi_flash_chip_info,
179 #if IS_ENABLED(CONFIG_MMC_SPI)
181 .modalias = "mmc_spi",
182 .max_speed_hz = 20000000, /* max spi clock (SCK) speed in HZ */
185 .controller_data = &mmc_spi_chip_info,
189 #if IS_ENABLED(CONFIG_TOUCHSCREEN_AD7877)
191 .modalias = "ad7877",
192 .platform_data = &bfin_ad7877_ts_info,
194 .max_speed_hz = 12500000, /* max spi clock (SCK) speed in HZ */
199 #if IS_ENABLED(CONFIG_SND_SOC_WM8731) \
200 && defined(CONFIG_SND_SOC_WM8731_SPI)
202 .modalias = "wm8731",
203 .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */
209 #if IS_ENABLED(CONFIG_SPI_SPIDEV)
211 .modalias = "spidev",
212 .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */
217 #if IS_ENABLED(CONFIG_FB_BFIN_LQ035Q1)
219 .modalias = "bfin-lq035q1-spi",
220 .max_speed_hz = 20000000, /* max spi clock (SCK) speed in HZ */
223 .mode = SPI_CPHA | SPI_CPOL,
228 /* SPI controller data */
229 #if IS_ENABLED(CONFIG_SPI_BFIN5XX)
231 static struct bfin5xx_spi_master bfin_spi0_info = {
233 .enable_dma = 1, /* master has the ability to do dma transfer */
234 .pin_req = {P_SPI0_SCK, P_SPI0_MISO, P_SPI0_MOSI, 0},
237 static struct resource bfin_spi0_resource[] = {
239 .start = SPI0_REGBASE,
240 .end = SPI0_REGBASE + 0xFF,
241 .flags = IORESOURCE_MEM,
246 .flags = IORESOURCE_DMA,
251 .flags = IORESOURCE_IRQ,
255 static struct platform_device bfin_spi0_device = {
257 .id = 0, /* Bus number */
258 .num_resources = ARRAY_SIZE(bfin_spi0_resource),
259 .resource = bfin_spi0_resource,
261 .platform_data = &bfin_spi0_info, /* Passed to driver */
266 static struct bfin5xx_spi_master bfin_spi1_info = {
268 .enable_dma = 1, /* master has the ability to do dma transfer */
269 .pin_req = {P_SPI1_SCK, P_SPI1_MISO, P_SPI1_MOSI, 0},
272 static struct resource bfin_spi1_resource[] = {
274 .start = SPI1_REGBASE,
275 .end = SPI1_REGBASE + 0xFF,
276 .flags = IORESOURCE_MEM,
281 .flags = IORESOURCE_DMA,
286 .flags = IORESOURCE_IRQ,
290 static struct platform_device bfin_spi1_device = {
292 .id = 1, /* Bus number */
293 .num_resources = ARRAY_SIZE(bfin_spi1_resource),
294 .resource = bfin_spi1_resource,
296 .platform_data = &bfin_spi1_info, /* Passed to driver */
299 #endif /* spi master and devices */
301 #if IS_ENABLED(CONFIG_SERIAL_BFIN)
302 #ifdef CONFIG_SERIAL_BFIN_UART0
303 static struct resource bfin_uart0_resources[] = {
307 .flags = IORESOURCE_MEM,
310 .start = IRQ_UART0_TX,
312 .flags = IORESOURCE_IRQ,
315 .start = IRQ_UART0_RX,
317 .flags = IORESOURCE_IRQ,
320 .start = IRQ_UART0_ERROR,
321 .end = IRQ_UART0_ERROR,
322 .flags = IORESOURCE_IRQ,
325 .start = CH_UART0_TX,
327 .flags = IORESOURCE_DMA,
330 .start = CH_UART0_RX,
332 .flags = IORESOURCE_DMA,
336 static unsigned short bfin_uart0_peripherals[] = {
337 P_UART0_TX, P_UART0_RX, 0
340 static struct platform_device bfin_uart0_device = {
343 .num_resources = ARRAY_SIZE(bfin_uart0_resources),
344 .resource = bfin_uart0_resources,
346 .platform_data = &bfin_uart0_peripherals, /* Passed to driver */
350 #ifdef CONFIG_SERIAL_BFIN_UART1
351 static struct resource bfin_uart1_resources[] = {
355 .flags = IORESOURCE_MEM,
358 .start = IRQ_UART1_TX,
360 .flags = IORESOURCE_IRQ,
363 .start = IRQ_UART1_RX,
365 .flags = IORESOURCE_IRQ,
368 .start = IRQ_UART1_ERROR,
369 .end = IRQ_UART1_ERROR,
370 .flags = IORESOURCE_IRQ,
373 .start = CH_UART1_TX,
375 .flags = IORESOURCE_DMA,
378 .start = CH_UART1_RX,
380 .flags = IORESOURCE_DMA,
384 static unsigned short bfin_uart1_peripherals[] = {
385 P_UART1_TX, P_UART1_RX, 0
388 static struct platform_device bfin_uart1_device = {
391 .num_resources = ARRAY_SIZE(bfin_uart1_resources),
392 .resource = bfin_uart1_resources,
394 .platform_data = &bfin_uart1_peripherals, /* Passed to driver */
400 #if IS_ENABLED(CONFIG_BFIN_SIR)
401 #ifdef CONFIG_BFIN_SIR0
402 static struct resource bfin_sir0_resources[] = {
406 .flags = IORESOURCE_MEM,
409 .start = IRQ_UART0_RX,
410 .end = IRQ_UART0_RX+1,
411 .flags = IORESOURCE_IRQ,
414 .start = CH_UART0_RX,
415 .end = CH_UART0_RX+1,
416 .flags = IORESOURCE_DMA,
420 static struct platform_device bfin_sir0_device = {
423 .num_resources = ARRAY_SIZE(bfin_sir0_resources),
424 .resource = bfin_sir0_resources,
427 #ifdef CONFIG_BFIN_SIR1
428 static struct resource bfin_sir1_resources[] = {
432 .flags = IORESOURCE_MEM,
435 .start = IRQ_UART1_RX,
436 .end = IRQ_UART1_RX+1,
437 .flags = IORESOURCE_IRQ,
440 .start = CH_UART1_RX,
441 .end = CH_UART1_RX+1,
442 .flags = IORESOURCE_DMA,
446 static struct platform_device bfin_sir1_device = {
449 .num_resources = ARRAY_SIZE(bfin_sir1_resources),
450 .resource = bfin_sir1_resources,
455 #if IS_ENABLED(CONFIG_I2C_BLACKFIN_TWI)
456 static const u16 bfin_twi0_pins[] = {P_TWI0_SCL, P_TWI0_SDA, 0};
458 static struct resource bfin_twi0_resource[] = {
460 .start = TWI0_REGBASE,
462 .flags = IORESOURCE_MEM,
467 .flags = IORESOURCE_IRQ,
471 static struct platform_device i2c_bfin_twi_device = {
472 .name = "i2c-bfin-twi",
474 .num_resources = ARRAY_SIZE(bfin_twi0_resource),
475 .resource = bfin_twi0_resource,
477 .platform_data = &bfin_twi0_pins,
482 static struct i2c_board_info __initdata bfin_i2c_board_info[] = {
483 #if IS_ENABLED(CONFIG_BFIN_TWI_LCD)
485 I2C_BOARD_INFO("pcf8574_lcd", 0x22),
488 #if IS_ENABLED(CONFIG_INPUT_PCF8574)
490 I2C_BOARD_INFO("pcf8574_keypad", 0x27),
496 #if IS_ENABLED(CONFIG_SERIAL_BFIN_SPORT)
497 #ifdef CONFIG_SERIAL_BFIN_SPORT0_UART
498 static struct resource bfin_sport0_uart_resources[] = {
500 .start = SPORT0_TCR1,
501 .end = SPORT0_MRCS3+4,
502 .flags = IORESOURCE_MEM,
505 .start = IRQ_SPORT0_RX,
506 .end = IRQ_SPORT0_RX+1,
507 .flags = IORESOURCE_IRQ,
510 .start = IRQ_SPORT0_ERROR,
511 .end = IRQ_SPORT0_ERROR,
512 .flags = IORESOURCE_IRQ,
516 static unsigned short bfin_sport0_peripherals[] = {
517 P_SPORT0_TFS, P_SPORT0_DTPRI, P_SPORT0_TSCLK, P_SPORT0_RFS,
518 P_SPORT0_DRPRI, P_SPORT0_RSCLK, 0
521 static struct platform_device bfin_sport0_uart_device = {
522 .name = "bfin-sport-uart",
524 .num_resources = ARRAY_SIZE(bfin_sport0_uart_resources),
525 .resource = bfin_sport0_uart_resources,
527 .platform_data = &bfin_sport0_peripherals, /* Passed to driver */
531 #ifdef CONFIG_SERIAL_BFIN_SPORT1_UART
532 static struct resource bfin_sport1_uart_resources[] = {
534 .start = SPORT1_TCR1,
535 .end = SPORT1_MRCS3+4,
536 .flags = IORESOURCE_MEM,
539 .start = IRQ_SPORT1_RX,
540 .end = IRQ_SPORT1_RX+1,
541 .flags = IORESOURCE_IRQ,
544 .start = IRQ_SPORT1_ERROR,
545 .end = IRQ_SPORT1_ERROR,
546 .flags = IORESOURCE_IRQ,
550 static unsigned short bfin_sport1_peripherals[] = {
551 P_SPORT1_TFS, P_SPORT1_DTPRI, P_SPORT1_TSCLK, P_SPORT1_RFS,
552 P_SPORT1_DRPRI, P_SPORT1_RSCLK, 0
555 static struct platform_device bfin_sport1_uart_device = {
556 .name = "bfin-sport-uart",
558 .num_resources = ARRAY_SIZE(bfin_sport1_uart_resources),
559 .resource = bfin_sport1_uart_resources,
561 .platform_data = &bfin_sport1_peripherals, /* Passed to driver */
567 #if IS_ENABLED(CONFIG_KEYBOARD_GPIO)
568 #include <linux/input.h>
569 #include <linux/gpio_keys.h>
571 static struct gpio_keys_button bfin_gpio_keys_table[] = {
572 {BTN_0, GPIO_PG0, 1, "gpio-keys: BTN0"},
573 {BTN_1, GPIO_PG13, 1, "gpio-keys: BTN1"},
576 static struct gpio_keys_platform_data bfin_gpio_keys_data = {
577 .buttons = bfin_gpio_keys_table,
578 .nbuttons = ARRAY_SIZE(bfin_gpio_keys_table),
581 static struct platform_device bfin_device_gpiokeys = {
584 .platform_data = &bfin_gpio_keys_data,
589 #if IS_ENABLED(CONFIG_SDH_BFIN)
591 static struct bfin_sd_host bfin_sdh_data = {
593 .irq_int0 = IRQ_RSI_INT0,
594 .pin_req = {P_RSI_DATA0, P_RSI_DATA1, P_RSI_DATA2, P_RSI_DATA3, P_RSI_CMD, P_RSI_CLK, 0},
597 static struct platform_device bf51x_sdh_device = {
601 .platform_data = &bfin_sdh_data,
606 static const unsigned int cclk_vlev_datasheet[] =
608 VRPAIR(VLEV_100, 400000000),
609 VRPAIR(VLEV_105, 426000000),
610 VRPAIR(VLEV_110, 500000000),
611 VRPAIR(VLEV_115, 533000000),
612 VRPAIR(VLEV_120, 600000000),
615 static struct bfin_dpmc_platform_data bfin_dmpc_vreg_data = {
616 .tuple_tab = cclk_vlev_datasheet,
617 .tabsize = ARRAY_SIZE(cclk_vlev_datasheet),
618 .vr_settling_time = 25 /* us */,
621 static struct platform_device bfin_dpmc = {
624 .platform_data = &bfin_dmpc_vreg_data,
628 static struct platform_device *tcm_devices[] __initdata = {
632 #if IS_ENABLED(CONFIG_RTC_DRV_BFIN)
636 #if IS_ENABLED(CONFIG_BFIN_MAC)
641 #if IS_ENABLED(CONFIG_SPI_BFIN5XX)
646 #if IS_ENABLED(CONFIG_SERIAL_BFIN)
647 #ifdef CONFIG_SERIAL_BFIN_UART0
650 #ifdef CONFIG_SERIAL_BFIN_UART1
655 #if IS_ENABLED(CONFIG_BFIN_SIR)
656 #ifdef CONFIG_BFIN_SIR0
659 #ifdef CONFIG_BFIN_SIR1
664 #if IS_ENABLED(CONFIG_I2C_BLACKFIN_TWI)
665 &i2c_bfin_twi_device,
668 #if IS_ENABLED(CONFIG_SERIAL_BFIN_SPORT)
669 #ifdef CONFIG_SERIAL_BFIN_SPORT0_UART
670 &bfin_sport0_uart_device,
672 #ifdef CONFIG_SERIAL_BFIN_SPORT1_UART
673 &bfin_sport1_uart_device,
677 #if IS_ENABLED(CONFIG_KEYBOARD_GPIO)
678 &bfin_device_gpiokeys,
681 #if IS_ENABLED(CONFIG_SDH_BFIN)
685 #if IS_ENABLED(CONFIG_MTD_PHYSMAP)
690 static int __init tcm_init(void)
692 printk(KERN_INFO "%s(): registering device resources\n", __func__);
693 i2c_register_board_info(0, bfin_i2c_board_info,
694 ARRAY_SIZE(bfin_i2c_board_info));
695 platform_add_devices(tcm_devices, ARRAY_SIZE(tcm_devices));
696 spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info));
700 arch_initcall(tcm_init);
702 static struct platform_device *tcm_early_devices[] __initdata = {
703 #if defined(CONFIG_SERIAL_BFIN_CONSOLE) || defined(CONFIG_EARLY_PRINTK)
704 #ifdef CONFIG_SERIAL_BFIN_UART0
707 #ifdef CONFIG_SERIAL_BFIN_UART1
712 #if defined(CONFIG_SERIAL_BFIN_SPORT_CONSOLE)
713 #ifdef CONFIG_SERIAL_BFIN_SPORT0_UART
714 &bfin_sport0_uart_device,
716 #ifdef CONFIG_SERIAL_BFIN_SPORT1_UART
717 &bfin_sport1_uart_device,
722 void __init native_machine_early_platform_add_devices(void)
724 printk(KERN_INFO "register early platform devices\n");
725 early_platform_add_devices(tcm_early_devices,
726 ARRAY_SIZE(tcm_early_devices));
729 void native_machine_restart(char *cmd)
731 /* workaround reboot hang when booting from SPI */
732 if ((bfin_read_SYSCR() & 0x7) == 0x3)
733 bfin_reset_boot_spi_cs(P_DEFAULT_BOOT_SPI_CS);
736 int bfin_get_ether_addr(char *addr)
740 EXPORT_SYMBOL(bfin_get_ether_addr);