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*/
145 #if defined(CONFIG_BFIN_SPI_ADC) \
146 || defined(CONFIG_BFIN_SPI_ADC_MODULE)
148 static struct bfin5xx_spi_chip spi_adc_chip_info
= {
149 .enable_dma
= 1, /* use dma transfer with this chip*/
154 #if defined(CONFIG_MMC_SPI) || defined(CONFIG_MMC_SPI_MODULE)
155 static struct bfin5xx_spi_chip mmc_spi_chip_info
= {
161 #if defined(CONFIG_TOUCHSCREEN_AD7877) || defined(CONFIG_TOUCHSCREEN_AD7877_MODULE)
162 static struct bfin5xx_spi_chip spi_ad7877_chip_info
= {
167 static const struct ad7877_platform_data bfin_ad7877_ts_info
= {
169 .vref_delay_usecs
= 50, /* internal, no capacitor */
172 .pressure_max
= 1000,
174 .stopacq_polarity
= 1,
175 .first_conversion_delay
= 3,
176 .acquisition_time
= 1,
178 .pen_down_acc_interval
= 1,
182 #if defined(CONFIG_SND_SOC_WM8731) || defined(CONFIG_SND_SOC_WM8731_MODULE) \
183 && defined(CONFIG_SND_SOC_WM8731_SPI)
184 static struct bfin5xx_spi_chip spi_wm8731_chip_info
= {
190 #if defined(CONFIG_SPI_SPIDEV) || defined(CONFIG_SPI_SPIDEV_MODULE)
191 static struct bfin5xx_spi_chip spidev_chip_info
= {
197 static struct spi_board_info bfin_spi_board_info
[] __initdata
= {
198 #if defined(CONFIG_MTD_M25P80) \
199 || defined(CONFIG_MTD_M25P80_MODULE)
201 /* the modalias must be the same as spi device driver name */
202 .modalias
= "m25p80", /* Name of spi_driver for this device */
203 .max_speed_hz
= 25000000, /* max spi clock (SCK) speed in HZ */
204 .bus_num
= 0, /* Framework bus number */
205 .chip_select
= 2, /* SPI0_SSEL2 */
206 .platform_data
= &bfin_spi_flash_data
,
207 .controller_data
= &spi_flash_chip_info
,
212 #if defined(CONFIG_BFIN_SPI_ADC) \
213 || defined(CONFIG_BFIN_SPI_ADC_MODULE)
215 .modalias
= "bfin_spi_adc", /* Name of spi_driver for this device */
216 .max_speed_hz
= 6250000, /* max spi clock (SCK) speed in HZ */
217 .bus_num
= 0, /* Framework bus number */
218 .chip_select
= 1, /* Framework chip select. */
219 .platform_data
= NULL
, /* No spi_driver specific config */
220 .controller_data
= &spi_adc_chip_info
,
224 #if defined(CONFIG_MMC_SPI) || defined(CONFIG_MMC_SPI_MODULE)
226 .modalias
= "mmc_spi",
227 .max_speed_hz
= 20000000, /* max spi clock (SCK) speed in HZ */
230 .controller_data
= &mmc_spi_chip_info
,
234 #if defined(CONFIG_TOUCHSCREEN_AD7877) || defined(CONFIG_TOUCHSCREEN_AD7877_MODULE)
236 .modalias
= "ad7877",
237 .platform_data
= &bfin_ad7877_ts_info
,
239 .max_speed_hz
= 12500000, /* max spi clock (SCK) speed in HZ */
242 .controller_data
= &spi_ad7877_chip_info
,
245 #if defined(CONFIG_SND_SOC_WM8731) || defined(CONFIG_SND_SOC_WM8731_MODULE) \
246 && defined(CONFIG_SND_SOC_WM8731_SPI)
248 .modalias
= "wm8731",
249 .max_speed_hz
= 3125000, /* max spi clock (SCK) speed in HZ */
252 .controller_data
= &spi_wm8731_chip_info
,
256 #if defined(CONFIG_SPI_SPIDEV) || defined(CONFIG_SPI_SPIDEV_MODULE)
258 .modalias
= "spidev",
259 .max_speed_hz
= 3125000, /* max spi clock (SCK) speed in HZ */
262 .controller_data
= &spidev_chip_info
,
265 #if defined(CONFIG_FB_BFIN_LQ035Q1) || defined(CONFIG_FB_BFIN_LQ035Q1_MODULE)
267 .modalias
= "bfin-lq035q1-spi",
268 .max_speed_hz
= 20000000, /* max spi clock (SCK) speed in HZ */
271 .controller_data
= &lq035q1_spi_chip_info
,
272 .mode
= SPI_CPHA
| SPI_CPOL
,
277 /* SPI controller data */
278 #if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
280 static struct bfin5xx_spi_master bfin_spi0_info
= {
282 .enable_dma
= 1, /* master has the ability to do dma transfer */
283 .pin_req
= {P_SPI0_SCK
, P_SPI0_MISO
, P_SPI0_MOSI
, 0},
286 static struct resource bfin_spi0_resource
[] = {
288 .start
= SPI0_REGBASE
,
289 .end
= SPI0_REGBASE
+ 0xFF,
290 .flags
= IORESOURCE_MEM
,
295 .flags
= IORESOURCE_DMA
,
300 .flags
= IORESOURCE_IRQ
,
304 static struct platform_device bfin_spi0_device
= {
306 .id
= 0, /* Bus number */
307 .num_resources
= ARRAY_SIZE(bfin_spi0_resource
),
308 .resource
= bfin_spi0_resource
,
310 .platform_data
= &bfin_spi0_info
, /* Passed to driver */
315 static struct bfin5xx_spi_master bfin_spi1_info
= {
317 .enable_dma
= 1, /* master has the ability to do dma transfer */
318 .pin_req
= {P_SPI1_SCK
, P_SPI1_MISO
, P_SPI1_MOSI
, 0},
321 static struct resource bfin_spi1_resource
[] = {
323 .start
= SPI1_REGBASE
,
324 .end
= SPI1_REGBASE
+ 0xFF,
325 .flags
= IORESOURCE_MEM
,
330 .flags
= IORESOURCE_DMA
,
335 .flags
= IORESOURCE_IRQ
,
339 static struct platform_device bfin_spi1_device
= {
341 .id
= 1, /* Bus number */
342 .num_resources
= ARRAY_SIZE(bfin_spi1_resource
),
343 .resource
= bfin_spi1_resource
,
345 .platform_data
= &bfin_spi1_info
, /* Passed to driver */
348 #endif /* spi master and devices */
350 #if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
351 #ifdef CONFIG_SERIAL_BFIN_UART0
352 static struct resource bfin_uart0_resources
[] = {
356 .flags
= IORESOURCE_MEM
,
359 .start
= IRQ_UART0_RX
,
360 .end
= IRQ_UART0_RX
+1,
361 .flags
= IORESOURCE_IRQ
,
364 .start
= IRQ_UART0_ERROR
,
365 .end
= IRQ_UART0_ERROR
,
366 .flags
= IORESOURCE_IRQ
,
369 .start
= CH_UART0_TX
,
371 .flags
= IORESOURCE_DMA
,
374 .start
= CH_UART0_RX
,
376 .flags
= IORESOURCE_DMA
,
380 static unsigned short bfin_uart0_peripherals
[] = {
381 P_UART0_TX
, P_UART0_RX
, 0
384 static struct platform_device bfin_uart0_device
= {
387 .num_resources
= ARRAY_SIZE(bfin_uart0_resources
),
388 .resource
= bfin_uart0_resources
,
390 .platform_data
= &bfin_uart0_peripherals
, /* Passed to driver */
394 #ifdef CONFIG_SERIAL_BFIN_UART1
395 static struct resource bfin_uart1_resources
[] = {
399 .flags
= IORESOURCE_MEM
,
402 .start
= IRQ_UART1_RX
,
403 .end
= IRQ_UART1_RX
+1,
404 .flags
= IORESOURCE_IRQ
,
407 .start
= IRQ_UART1_ERROR
,
408 .end
= IRQ_UART1_ERROR
,
409 .flags
= IORESOURCE_IRQ
,
412 .start
= CH_UART1_TX
,
414 .flags
= IORESOURCE_DMA
,
417 .start
= CH_UART1_RX
,
419 .flags
= IORESOURCE_DMA
,
423 static unsigned short bfin_uart1_peripherals
[] = {
424 P_UART1_TX
, P_UART1_RX
, 0
427 static struct platform_device bfin_uart1_device
= {
430 .num_resources
= ARRAY_SIZE(bfin_uart1_resources
),
431 .resource
= bfin_uart1_resources
,
433 .platform_data
= &bfin_uart1_peripherals
, /* Passed to driver */
439 #if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
440 #ifdef CONFIG_BFIN_SIR0
441 static struct resource bfin_sir0_resources
[] = {
445 .flags
= IORESOURCE_MEM
,
448 .start
= IRQ_UART0_RX
,
449 .end
= IRQ_UART0_RX
+1,
450 .flags
= IORESOURCE_IRQ
,
453 .start
= CH_UART0_RX
,
454 .end
= CH_UART0_RX
+1,
455 .flags
= IORESOURCE_DMA
,
459 static struct platform_device bfin_sir0_device
= {
462 .num_resources
= ARRAY_SIZE(bfin_sir0_resources
),
463 .resource
= bfin_sir0_resources
,
466 #ifdef CONFIG_BFIN_SIR1
467 static struct resource bfin_sir1_resources
[] = {
471 .flags
= IORESOURCE_MEM
,
474 .start
= IRQ_UART1_RX
,
475 .end
= IRQ_UART1_RX
+1,
476 .flags
= IORESOURCE_IRQ
,
479 .start
= CH_UART1_RX
,
480 .end
= CH_UART1_RX
+1,
481 .flags
= IORESOURCE_DMA
,
485 static struct platform_device bfin_sir1_device
= {
488 .num_resources
= ARRAY_SIZE(bfin_sir1_resources
),
489 .resource
= bfin_sir1_resources
,
494 #if defined(CONFIG_I2C_BLACKFIN_TWI) || defined(CONFIG_I2C_BLACKFIN_TWI_MODULE)
495 static struct resource bfin_twi0_resource
[] = {
497 .start
= TWI0_REGBASE
,
499 .flags
= IORESOURCE_MEM
,
504 .flags
= IORESOURCE_IRQ
,
508 static struct platform_device i2c_bfin_twi_device
= {
509 .name
= "i2c-bfin-twi",
511 .num_resources
= ARRAY_SIZE(bfin_twi0_resource
),
512 .resource
= bfin_twi0_resource
,
516 static struct i2c_board_info __initdata bfin_i2c_board_info
[] = {
517 #if defined(CONFIG_BFIN_TWI_LCD) || defined(CONFIG_BFIN_TWI_LCD_MODULE)
519 I2C_BOARD_INFO("pcf8574_lcd", 0x22),
522 #if defined(CONFIG_INPUT_PCF8574) || defined(CONFIG_INPUT_PCF8574_MODULE)
524 I2C_BOARD_INFO("pcf8574_keypad", 0x27),
530 #if defined(CONFIG_SERIAL_BFIN_SPORT) || defined(CONFIG_SERIAL_BFIN_SPORT_MODULE)
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 defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
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 defined(CONFIG_SDH_BFIN) || defined(CONFIG_SDH_BFIN_MODULE)
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
*tcm_devices
[] __initdata
= {
666 #if defined(CONFIG_RTC_DRV_BFIN) || defined(CONFIG_RTC_DRV_BFIN_MODULE)
670 #if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
675 #if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
680 #if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
681 #ifdef CONFIG_SERIAL_BFIN_UART0
684 #ifdef CONFIG_SERIAL_BFIN_UART1
689 #if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
690 #ifdef CONFIG_BFIN_SIR0
693 #ifdef CONFIG_BFIN_SIR1
698 #if defined(CONFIG_I2C_BLACKFIN_TWI) || defined(CONFIG_I2C_BLACKFIN_TWI_MODULE)
699 &i2c_bfin_twi_device
,
702 #if defined(CONFIG_SERIAL_BFIN_SPORT) || defined(CONFIG_SERIAL_BFIN_SPORT_MODULE)
703 #ifdef CONFIG_SERIAL_BFIN_SPORT0_UART
704 &bfin_sport0_uart_device
,
706 #ifdef CONFIG_SERIAL_BFIN_SPORT1_UART
707 &bfin_sport1_uart_device
,
711 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
712 &bfin_device_gpiokeys
,
715 #if defined(CONFIG_SDH_BFIN) || defined(CONFIG_SDH_BFIN_MODULE)
719 #if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
724 static int __init
tcm_init(void)
726 printk(KERN_INFO
"%s(): registering device resources\n", __func__
);
727 i2c_register_board_info(0, bfin_i2c_board_info
,
728 ARRAY_SIZE(bfin_i2c_board_info
));
729 platform_add_devices(tcm_devices
, ARRAY_SIZE(tcm_devices
));
730 spi_register_board_info(bfin_spi_board_info
, ARRAY_SIZE(bfin_spi_board_info
));
734 arch_initcall(tcm_init
);
736 static struct platform_device
*tcm_early_devices
[] __initdata
= {
737 #if defined(CONFIG_SERIAL_BFIN_CONSOLE) || defined(CONFIG_EARLY_PRINTK)
738 #ifdef CONFIG_SERIAL_BFIN_UART0
741 #ifdef CONFIG_SERIAL_BFIN_UART1
746 #if defined(CONFIG_SERIAL_BFIN_SPORT_CONSOLE)
747 #ifdef CONFIG_SERIAL_BFIN_SPORT0_UART
748 &bfin_sport0_uart_device
,
750 #ifdef CONFIG_SERIAL_BFIN_SPORT1_UART
751 &bfin_sport1_uart_device
,
756 void __init
native_machine_early_platform_add_devices(void)
758 printk(KERN_INFO
"register early platform devices\n");
759 early_platform_add_devices(tcm_early_devices
,
760 ARRAY_SIZE(tcm_early_devices
));
763 void native_machine_restart(char *cmd
)
765 /* workaround reboot hang when booting from SPI */
766 if ((bfin_read_SYSCR() & 0x7) == 0x3)
767 bfin_reset_boot_spi_cs(P_DEFAULT_BOOT_SPI_CS
);
770 void bfin_get_ether_addr(char *addr
)
772 random_ether_addr(addr
);
773 printk(KERN_WARNING
"%s:%s: Setting Ethernet MAC to a random one\n", __FILE__
, __func__
);
775 EXPORT_SYMBOL(bfin_get_ether_addr
);