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 defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
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 defined(CONFIG_RTC_DRV_BFIN) || defined(CONFIG_RTC_DRV_BFIN_MODULE)
77 static struct platform_device rtc_device = {
83 #if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
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 defined(CONFIG_MTD_M25P80) \
117 || defined(CONFIG_MTD_M25P80_MODULE)
118 static struct mtd_partition bfin_spi_flash_partitions[] = {
120 .name = "bootloader(spi)",
123 .mask_flags = MTD_CAP_ROM
125 .name = "linux kernel(spi)",
126 .size = MTDPART_SIZ_FULL,
127 .offset = MTDPART_OFS_APPEND,
131 static struct flash_platform_data bfin_spi_flash_data = {
133 .parts = bfin_spi_flash_partitions,
134 .nr_parts = ARRAY_SIZE(bfin_spi_flash_partitions),
138 /* SPI flash chip (m25p64) */
139 static struct bfin5xx_spi_chip spi_flash_chip_info = {
140 .enable_dma = 0, /* use dma transfer with this chip*/
144 #if defined(CONFIG_MMC_SPI) || defined(CONFIG_MMC_SPI_MODULE)
145 static struct bfin5xx_spi_chip mmc_spi_chip_info = {
150 #if defined(CONFIG_TOUCHSCREEN_AD7877) || defined(CONFIG_TOUCHSCREEN_AD7877_MODULE)
151 static const struct ad7877_platform_data bfin_ad7877_ts_info = {
153 .vref_delay_usecs = 50, /* internal, no capacitor */
156 .pressure_max = 1000,
158 .stopacq_polarity = 1,
159 .first_conversion_delay = 3,
160 .acquisition_time = 1,
162 .pen_down_acc_interval = 1,
166 static struct spi_board_info bfin_spi_board_info[] __initdata = {
167 #if defined(CONFIG_MTD_M25P80) \
168 || defined(CONFIG_MTD_M25P80_MODULE)
170 /* the modalias must be the same as spi device driver name */
171 .modalias = "m25p80", /* Name of spi_driver for this device */
172 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */
173 .bus_num = 0, /* Framework bus number */
174 .chip_select = 2, /* SPI0_SSEL2 */
175 .platform_data = &bfin_spi_flash_data,
176 .controller_data = &spi_flash_chip_info,
181 #if defined(CONFIG_MMC_SPI) || defined(CONFIG_MMC_SPI_MODULE)
183 .modalias = "mmc_spi",
184 .max_speed_hz = 20000000, /* max spi clock (SCK) speed in HZ */
187 .controller_data = &mmc_spi_chip_info,
191 #if defined(CONFIG_TOUCHSCREEN_AD7877) || defined(CONFIG_TOUCHSCREEN_AD7877_MODULE)
193 .modalias = "ad7877",
194 .platform_data = &bfin_ad7877_ts_info,
196 .max_speed_hz = 12500000, /* max spi clock (SCK) speed in HZ */
201 #if defined(CONFIG_SND_SOC_WM8731) || defined(CONFIG_SND_SOC_WM8731_MODULE) \
202 && defined(CONFIG_SND_SOC_WM8731_SPI)
204 .modalias = "wm8731",
205 .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */
211 #if defined(CONFIG_SPI_SPIDEV) || defined(CONFIG_SPI_SPIDEV_MODULE)
213 .modalias = "spidev",
214 .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */
219 #if defined(CONFIG_FB_BFIN_LQ035Q1) || defined(CONFIG_FB_BFIN_LQ035Q1_MODULE)
221 .modalias = "bfin-lq035q1-spi",
222 .max_speed_hz = 20000000, /* max spi clock (SCK) speed in HZ */
225 .mode = SPI_CPHA | SPI_CPOL,
230 /* SPI controller data */
231 #if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
233 static struct bfin5xx_spi_master bfin_spi0_info = {
235 .enable_dma = 1, /* master has the ability to do dma transfer */
236 .pin_req = {P_SPI0_SCK, P_SPI0_MISO, P_SPI0_MOSI, 0},
239 static struct resource bfin_spi0_resource[] = {
241 .start = SPI0_REGBASE,
242 .end = SPI0_REGBASE + 0xFF,
243 .flags = IORESOURCE_MEM,
248 .flags = IORESOURCE_DMA,
253 .flags = IORESOURCE_IRQ,
257 static struct platform_device bfin_spi0_device = {
259 .id = 0, /* Bus number */
260 .num_resources = ARRAY_SIZE(bfin_spi0_resource),
261 .resource = bfin_spi0_resource,
263 .platform_data = &bfin_spi0_info, /* Passed to driver */
268 static struct bfin5xx_spi_master bfin_spi1_info = {
270 .enable_dma = 1, /* master has the ability to do dma transfer */
271 .pin_req = {P_SPI1_SCK, P_SPI1_MISO, P_SPI1_MOSI, 0},
274 static struct resource bfin_spi1_resource[] = {
276 .start = SPI1_REGBASE,
277 .end = SPI1_REGBASE + 0xFF,
278 .flags = IORESOURCE_MEM,
283 .flags = IORESOURCE_DMA,
288 .flags = IORESOURCE_IRQ,
292 static struct platform_device bfin_spi1_device = {
294 .id = 1, /* Bus number */
295 .num_resources = ARRAY_SIZE(bfin_spi1_resource),
296 .resource = bfin_spi1_resource,
298 .platform_data = &bfin_spi1_info, /* Passed to driver */
301 #endif /* spi master and devices */
303 #if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
304 #ifdef CONFIG_SERIAL_BFIN_UART0
305 static struct resource bfin_uart0_resources[] = {
309 .flags = IORESOURCE_MEM,
312 .start = IRQ_UART0_RX,
313 .end = IRQ_UART0_RX+1,
314 .flags = IORESOURCE_IRQ,
317 .start = IRQ_UART0_ERROR,
318 .end = IRQ_UART0_ERROR,
319 .flags = IORESOURCE_IRQ,
322 .start = CH_UART0_TX,
324 .flags = IORESOURCE_DMA,
327 .start = CH_UART0_RX,
329 .flags = IORESOURCE_DMA,
333 static unsigned short bfin_uart0_peripherals[] = {
334 P_UART0_TX, P_UART0_RX, 0
337 static struct platform_device bfin_uart0_device = {
340 .num_resources = ARRAY_SIZE(bfin_uart0_resources),
341 .resource = bfin_uart0_resources,
343 .platform_data = &bfin_uart0_peripherals, /* Passed to driver */
347 #ifdef CONFIG_SERIAL_BFIN_UART1
348 static struct resource bfin_uart1_resources[] = {
352 .flags = IORESOURCE_MEM,
355 .start = IRQ_UART1_RX,
356 .end = IRQ_UART1_RX+1,
357 .flags = IORESOURCE_IRQ,
360 .start = IRQ_UART1_ERROR,
361 .end = IRQ_UART1_ERROR,
362 .flags = IORESOURCE_IRQ,
365 .start = CH_UART1_TX,
367 .flags = IORESOURCE_DMA,
370 .start = CH_UART1_RX,
372 .flags = IORESOURCE_DMA,
376 static unsigned short bfin_uart1_peripherals[] = {
377 P_UART1_TX, P_UART1_RX, 0
380 static struct platform_device bfin_uart1_device = {
383 .num_resources = ARRAY_SIZE(bfin_uart1_resources),
384 .resource = bfin_uart1_resources,
386 .platform_data = &bfin_uart1_peripherals, /* Passed to driver */
392 #if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
393 #ifdef CONFIG_BFIN_SIR0
394 static struct resource bfin_sir0_resources[] = {
398 .flags = IORESOURCE_MEM,
401 .start = IRQ_UART0_RX,
402 .end = IRQ_UART0_RX+1,
403 .flags = IORESOURCE_IRQ,
406 .start = CH_UART0_RX,
407 .end = CH_UART0_RX+1,
408 .flags = IORESOURCE_DMA,
412 static struct platform_device bfin_sir0_device = {
415 .num_resources = ARRAY_SIZE(bfin_sir0_resources),
416 .resource = bfin_sir0_resources,
419 #ifdef CONFIG_BFIN_SIR1
420 static struct resource bfin_sir1_resources[] = {
424 .flags = IORESOURCE_MEM,
427 .start = IRQ_UART1_RX,
428 .end = IRQ_UART1_RX+1,
429 .flags = IORESOURCE_IRQ,
432 .start = CH_UART1_RX,
433 .end = CH_UART1_RX+1,
434 .flags = IORESOURCE_DMA,
438 static struct platform_device bfin_sir1_device = {
441 .num_resources = ARRAY_SIZE(bfin_sir1_resources),
442 .resource = bfin_sir1_resources,
447 #if defined(CONFIG_I2C_BLACKFIN_TWI) || defined(CONFIG_I2C_BLACKFIN_TWI_MODULE)
448 static struct resource bfin_twi0_resource[] = {
450 .start = TWI0_REGBASE,
452 .flags = IORESOURCE_MEM,
457 .flags = IORESOURCE_IRQ,
461 static struct platform_device i2c_bfin_twi_device = {
462 .name = "i2c-bfin-twi",
464 .num_resources = ARRAY_SIZE(bfin_twi0_resource),
465 .resource = bfin_twi0_resource,
469 static struct i2c_board_info __initdata bfin_i2c_board_info[] = {
470 #if defined(CONFIG_BFIN_TWI_LCD) || defined(CONFIG_BFIN_TWI_LCD_MODULE)
472 I2C_BOARD_INFO("pcf8574_lcd", 0x22),
475 #if defined(CONFIG_INPUT_PCF8574) || defined(CONFIG_INPUT_PCF8574_MODULE)
477 I2C_BOARD_INFO("pcf8574_keypad", 0x27),
483 #if defined(CONFIG_SERIAL_BFIN_SPORT) || defined(CONFIG_SERIAL_BFIN_SPORT_MODULE)
484 #ifdef CONFIG_SERIAL_BFIN_SPORT0_UART
485 static struct resource bfin_sport0_uart_resources[] = {
487 .start = SPORT0_TCR1,
488 .end = SPORT0_MRCS3+4,
489 .flags = IORESOURCE_MEM,
492 .start = IRQ_SPORT0_RX,
493 .end = IRQ_SPORT0_RX+1,
494 .flags = IORESOURCE_IRQ,
497 .start = IRQ_SPORT0_ERROR,
498 .end = IRQ_SPORT0_ERROR,
499 .flags = IORESOURCE_IRQ,
503 static unsigned short bfin_sport0_peripherals[] = {
504 P_SPORT0_TFS, P_SPORT0_DTPRI, P_SPORT0_TSCLK, P_SPORT0_RFS,
505 P_SPORT0_DRPRI, P_SPORT0_RSCLK, 0
508 static struct platform_device bfin_sport0_uart_device = {
509 .name = "bfin-sport-uart",
511 .num_resources = ARRAY_SIZE(bfin_sport0_uart_resources),
512 .resource = bfin_sport0_uart_resources,
514 .platform_data = &bfin_sport0_peripherals, /* Passed to driver */
518 #ifdef CONFIG_SERIAL_BFIN_SPORT1_UART
519 static struct resource bfin_sport1_uart_resources[] = {
521 .start = SPORT1_TCR1,
522 .end = SPORT1_MRCS3+4,
523 .flags = IORESOURCE_MEM,
526 .start = IRQ_SPORT1_RX,
527 .end = IRQ_SPORT1_RX+1,
528 .flags = IORESOURCE_IRQ,
531 .start = IRQ_SPORT1_ERROR,
532 .end = IRQ_SPORT1_ERROR,
533 .flags = IORESOURCE_IRQ,
537 static unsigned short bfin_sport1_peripherals[] = {
538 P_SPORT1_TFS, P_SPORT1_DTPRI, P_SPORT1_TSCLK, P_SPORT1_RFS,
539 P_SPORT1_DRPRI, P_SPORT1_RSCLK, 0
542 static struct platform_device bfin_sport1_uart_device = {
543 .name = "bfin-sport-uart",
545 .num_resources = ARRAY_SIZE(bfin_sport1_uart_resources),
546 .resource = bfin_sport1_uart_resources,
548 .platform_data = &bfin_sport1_peripherals, /* Passed to driver */
554 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
555 #include <linux/input.h>
556 #include <linux/gpio_keys.h>
558 static struct gpio_keys_button bfin_gpio_keys_table[] = {
559 {BTN_0, GPIO_PG0, 1, "gpio-keys: BTN0"},
560 {BTN_1, GPIO_PG13, 1, "gpio-keys: BTN1"},
563 static struct gpio_keys_platform_data bfin_gpio_keys_data = {
564 .buttons = bfin_gpio_keys_table,
565 .nbuttons = ARRAY_SIZE(bfin_gpio_keys_table),
568 static struct platform_device bfin_device_gpiokeys = {
571 .platform_data = &bfin_gpio_keys_data,
576 #if defined(CONFIG_SDH_BFIN) || defined(CONFIG_SDH_BFIN_MODULE)
578 static struct bfin_sd_host bfin_sdh_data = {
580 .irq_int0 = IRQ_RSI_INT0,
581 .pin_req = {P_RSI_DATA0, P_RSI_DATA1, P_RSI_DATA2, P_RSI_DATA3, P_RSI_CMD, P_RSI_CLK, 0},
584 static struct platform_device bf51x_sdh_device = {
588 .platform_data = &bfin_sdh_data,
593 static const unsigned int cclk_vlev_datasheet[] =
595 VRPAIR(VLEV_100, 400000000),
596 VRPAIR(VLEV_105, 426000000),
597 VRPAIR(VLEV_110, 500000000),
598 VRPAIR(VLEV_115, 533000000),
599 VRPAIR(VLEV_120, 600000000),
602 static struct bfin_dpmc_platform_data bfin_dmpc_vreg_data = {
603 .tuple_tab = cclk_vlev_datasheet,
604 .tabsize = ARRAY_SIZE(cclk_vlev_datasheet),
605 .vr_settling_time = 25 /* us */,
608 static struct platform_device bfin_dpmc = {
611 .platform_data = &bfin_dmpc_vreg_data,
615 static struct platform_device *tcm_devices[] __initdata = {
619 #if defined(CONFIG_RTC_DRV_BFIN) || defined(CONFIG_RTC_DRV_BFIN_MODULE)
623 #if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
628 #if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
633 #if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
634 #ifdef CONFIG_SERIAL_BFIN_UART0
637 #ifdef CONFIG_SERIAL_BFIN_UART1
642 #if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
643 #ifdef CONFIG_BFIN_SIR0
646 #ifdef CONFIG_BFIN_SIR1
651 #if defined(CONFIG_I2C_BLACKFIN_TWI) || defined(CONFIG_I2C_BLACKFIN_TWI_MODULE)
652 &i2c_bfin_twi_device,
655 #if defined(CONFIG_SERIAL_BFIN_SPORT) || defined(CONFIG_SERIAL_BFIN_SPORT_MODULE)
656 #ifdef CONFIG_SERIAL_BFIN_SPORT0_UART
657 &bfin_sport0_uart_device,
659 #ifdef CONFIG_SERIAL_BFIN_SPORT1_UART
660 &bfin_sport1_uart_device,
664 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
665 &bfin_device_gpiokeys,
668 #if defined(CONFIG_SDH_BFIN) || defined(CONFIG_SDH_BFIN_MODULE)
672 #if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
677 static int __init tcm_init(void)
679 printk(KERN_INFO "%s(): registering device resources\n", __func__);
680 i2c_register_board_info(0, bfin_i2c_board_info,
681 ARRAY_SIZE(bfin_i2c_board_info));
682 platform_add_devices(tcm_devices, ARRAY_SIZE(tcm_devices));
683 spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info));
687 arch_initcall(tcm_init);
689 static struct platform_device *tcm_early_devices[] __initdata = {
690 #if defined(CONFIG_SERIAL_BFIN_CONSOLE) || defined(CONFIG_EARLY_PRINTK)
691 #ifdef CONFIG_SERIAL_BFIN_UART0
694 #ifdef CONFIG_SERIAL_BFIN_UART1
699 #if defined(CONFIG_SERIAL_BFIN_SPORT_CONSOLE)
700 #ifdef CONFIG_SERIAL_BFIN_SPORT0_UART
701 &bfin_sport0_uart_device,
703 #ifdef CONFIG_SERIAL_BFIN_SPORT1_UART
704 &bfin_sport1_uart_device,
709 void __init native_machine_early_platform_add_devices(void)
711 printk(KERN_INFO "register early platform devices\n");
712 early_platform_add_devices(tcm_early_devices,
713 ARRAY_SIZE(tcm_early_devices));
716 void native_machine_restart(char *cmd)
718 /* workaround reboot hang when booting from SPI */
719 if ((bfin_read_SYSCR() & 0x7) == 0x3)
720 bfin_reset_boot_spi_cs(P_DEFAULT_BOOT_SPI_CS);
723 void bfin_get_ether_addr(char *addr)
725 random_ether_addr(addr);
726 printk(KERN_WARNING "%s:%s: Setting Ethernet MAC to a random one\n", __FILE__, __func__);
728 EXPORT_SYMBOL(bfin_get_ether_addr);