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/platform_device.h>
11 #include <linux/mtd/mtd.h>
12 #include <linux/mtd/partitions.h>
13 #include <linux/mtd/physmap.h>
14 #include <linux/spi/spi.h>
15 #include <linux/spi/flash.h>
16 #include <linux/spi/mmc_spi.h>
17 #if defined(CONFIG_USB_ISP1362_HCD) || defined(CONFIG_USB_ISP1362_HCD_MODULE)
18 #include <linux/usb/isp1362.h>
20 #include <linux/irq.h>
21 #include <linux/i2c.h>
23 #include <asm/bfin5xx_spi.h>
24 #include <asm/reboot.h>
25 #include <asm/portmux.h>
29 * Name the Board for the /proc/cpuinfo
31 const char bfin_board_name
[] = "ADI BF533-STAMP";
33 #if defined(CONFIG_RTC_DRV_BFIN) || defined(CONFIG_RTC_DRV_BFIN_MODULE)
34 static struct platform_device rtc_device
= {
41 * Driver needs to know address, irq and flag pin.
43 #if defined(CONFIG_SMC91X) || defined(CONFIG_SMC91X_MODULE)
44 #include <linux/smc91x.h>
46 static struct smc91x_platdata smc91x_info
= {
47 .flags
= SMC91X_USE_16BIT
| SMC91X_NOWAIT
,
48 .leda
= RPC_LED_100_10
,
49 .ledb
= RPC_LED_TX_RX
,
52 static struct resource smc91x_resources
[] = {
54 .name
= "smc91x-regs",
56 .end
= 0x20300300 + 16,
57 .flags
= IORESOURCE_MEM
,
61 .flags
= IORESOURCE_IRQ
| IORESOURCE_IRQ_HIGHLEVEL
,
65 static struct platform_device smc91x_device
= {
68 .num_resources
= ARRAY_SIZE(smc91x_resources
),
69 .resource
= smc91x_resources
,
71 .platform_data
= &smc91x_info
,
76 #if defined(CONFIG_USB_NET2272) || defined(CONFIG_USB_NET2272_MODULE)
77 static struct resource net2272_bfin_resources
[] = {
80 .end
= 0x20300000 + 0x100,
81 .flags
= IORESOURCE_MEM
,
85 .flags
= IORESOURCE_IRQ
| IORESOURCE_IRQ_HIGHLEVEL
,
89 static struct platform_device net2272_bfin_device
= {
92 .num_resources
= ARRAY_SIZE(net2272_bfin_resources
),
93 .resource
= net2272_bfin_resources
,
97 #if defined(CONFIG_MTD_BFIN_ASYNC) || defined(CONFIG_MTD_BFIN_ASYNC_MODULE)
98 static struct mtd_partition stamp_partitions
[] = {
100 .name
= "bootloader(nor)",
104 .name
= "linux kernel(nor)",
106 .offset
= MTDPART_OFS_APPEND
,
108 .name
= "file system(nor)",
109 .size
= MTDPART_SIZ_FULL
,
110 .offset
= MTDPART_OFS_APPEND
,
114 static struct physmap_flash_data stamp_flash_data
= {
116 .parts
= stamp_partitions
,
117 .nr_parts
= ARRAY_SIZE(stamp_partitions
),
120 static struct resource stamp_flash_resource
[] = {
125 .flags
= IORESOURCE_MEM
,
127 .start
= 0x7BB07BB0, /* AMBCTL0 setting when accessing flash */
128 .end
= 0x7BB07BB0, /* AMBCTL1 setting when accessing flash */
129 .flags
= IORESOURCE_MEM
,
132 .flags
= IORESOURCE_IRQ
,
136 static struct platform_device stamp_flash_device
= {
137 .name
= "bfin-async-flash",
140 .platform_data
= &stamp_flash_data
,
142 .num_resources
= ARRAY_SIZE(stamp_flash_resource
),
143 .resource
= stamp_flash_resource
,
147 #if defined(CONFIG_MTD_M25P80) || defined(CONFIG_MTD_M25P80_MODULE)
148 static struct mtd_partition bfin_spi_flash_partitions
[] = {
150 .name
= "bootloader(spi)",
153 .mask_flags
= MTD_CAP_ROM
155 .name
= "linux kernel(spi)",
157 .offset
= MTDPART_OFS_APPEND
,
159 .name
= "file system(spi)",
160 .size
= MTDPART_SIZ_FULL
,
161 .offset
= MTDPART_OFS_APPEND
,
165 static struct flash_platform_data bfin_spi_flash_data
= {
167 .parts
= bfin_spi_flash_partitions
,
168 .nr_parts
= ARRAY_SIZE(bfin_spi_flash_partitions
),
172 /* SPI flash chip (m25p64) */
173 static struct bfin5xx_spi_chip spi_flash_chip_info
= {
174 .enable_dma
= 0, /* use dma transfer with this chip*/
179 #if defined(CONFIG_BFIN_SPI_ADC) || defined(CONFIG_BFIN_SPI_ADC_MODULE)
181 static struct bfin5xx_spi_chip spi_adc_chip_info
= {
182 .enable_dma
= 1, /* use dma transfer with this chip*/
187 #if defined(CONFIG_SND_BLACKFIN_AD1836) || defined(CONFIG_SND_BLACKFIN_AD1836_MODULE)
188 static struct bfin5xx_spi_chip ad1836_spi_chip_info
= {
194 #if defined(CONFIG_SPI_SPIDEV) || defined(CONFIG_SPI_SPIDEV_MODULE)
195 static struct bfin5xx_spi_chip spidev_chip_info
= {
201 #if defined(CONFIG_MMC_SPI) || defined(CONFIG_MMC_SPI_MODULE)
202 #define MMC_SPI_CARD_DETECT_INT IRQ_PF5
203 static int bfin_mmc_spi_init(struct device
*dev
,
204 irqreturn_t (*detect_int
)(int, void *), void *data
)
206 return request_irq(MMC_SPI_CARD_DETECT_INT
, detect_int
,
207 IRQF_TRIGGER_FALLING
| IRQF_TRIGGER_RISING
,
208 "mmc-spi-detect", data
);
211 static void bfin_mmc_spi_exit(struct device
*dev
, void *data
)
213 free_irq(MMC_SPI_CARD_DETECT_INT
, data
);
216 static struct mmc_spi_platform_data bfin_mmc_spi_pdata
= {
217 .init
= bfin_mmc_spi_init
,
218 .exit
= bfin_mmc_spi_exit
,
219 .detect_delay
= 100, /* msecs */
222 static struct bfin5xx_spi_chip mmc_spi_chip_info
= {
229 static struct spi_board_info bfin_spi_board_info
[] __initdata
= {
230 #if defined(CONFIG_MTD_M25P80) || defined(CONFIG_MTD_M25P80_MODULE)
232 /* the modalias must be the same as spi device driver name */
233 .modalias
= "m25p80", /* Name of spi_driver for this device */
234 .max_speed_hz
= 25000000, /* max spi clock (SCK) speed in HZ */
235 .bus_num
= 0, /* Framework bus number */
236 .chip_select
= 2, /* Framework chip select. On STAMP537 it is SPISSEL2*/
237 .platform_data
= &bfin_spi_flash_data
,
238 .controller_data
= &spi_flash_chip_info
,
243 #if defined(CONFIG_BFIN_SPI_ADC) || defined(CONFIG_BFIN_SPI_ADC_MODULE)
245 .modalias
= "bfin_spi_adc", /* Name of spi_driver for this device */
246 .max_speed_hz
= 6250000, /* max spi clock (SCK) speed in HZ */
247 .bus_num
= 0, /* Framework bus number */
248 .chip_select
= 1, /* Framework chip select. */
249 .platform_data
= NULL
, /* No spi_driver specific config */
250 .controller_data
= &spi_adc_chip_info
,
254 #if defined(CONFIG_SND_BLACKFIN_AD1836) || defined(CONFIG_SND_BLACKFIN_AD1836_MODULE)
256 .modalias
= "ad1836",
257 .max_speed_hz
= 3125000, /* max spi clock (SCK) speed in HZ */
259 .chip_select
= CONFIG_SND_BLACKFIN_SPI_PFBIT
,
260 .controller_data
= &ad1836_spi_chip_info
,
264 #if defined(CONFIG_SPI_SPIDEV) || defined(CONFIG_SPI_SPIDEV_MODULE)
266 .modalias
= "spidev",
267 .max_speed_hz
= 3125000, /* max spi clock (SCK) speed in HZ */
270 .controller_data
= &spidev_chip_info
,
273 #if defined(CONFIG_MMC_SPI) || defined(CONFIG_MMC_SPI_MODULE)
275 .modalias
= "mmc_spi",
276 .max_speed_hz
= 20000000, /* max spi clock (SCK) speed in HZ */
279 .platform_data
= &bfin_mmc_spi_pdata
,
280 .controller_data
= &mmc_spi_chip_info
,
286 #if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
288 static struct resource bfin_spi0_resource
[] = {
290 .start
= SPI0_REGBASE
,
291 .end
= SPI0_REGBASE
+ 0xFF,
292 .flags
= IORESOURCE_MEM
,
297 .flags
= IORESOURCE_DMA
,
302 .flags
= IORESOURCE_IRQ
,
306 /* SPI controller data */
307 static struct bfin5xx_spi_master bfin_spi0_info
= {
309 .enable_dma
= 1, /* master has the ability to do dma transfer */
310 .pin_req
= {P_SPI0_SCK
, P_SPI0_MISO
, P_SPI0_MOSI
, 0},
313 static struct platform_device bfin_spi0_device
= {
315 .id
= 0, /* Bus number */
316 .num_resources
= ARRAY_SIZE(bfin_spi0_resource
),
317 .resource
= bfin_spi0_resource
,
319 .platform_data
= &bfin_spi0_info
, /* Passed to driver */
322 #endif /* spi master and devices */
324 #if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
325 #ifdef CONFIG_SERIAL_BFIN_UART0
326 static struct resource bfin_uart0_resources
[] = {
328 .start
= BFIN_UART_THR
,
329 .end
= BFIN_UART_GCTL
+2,
330 .flags
= IORESOURCE_MEM
,
333 .start
= IRQ_UART0_RX
,
334 .end
= IRQ_UART0_RX
+ 1,
335 .flags
= IORESOURCE_IRQ
,
338 .start
= IRQ_UART0_ERROR
,
339 .end
= IRQ_UART0_ERROR
,
340 .flags
= IORESOURCE_IRQ
,
343 .start
= CH_UART0_TX
,
345 .flags
= IORESOURCE_DMA
,
348 .start
= CH_UART0_RX
,
350 .flags
= IORESOURCE_DMA
,
354 unsigned short bfin_uart0_peripherals
[] = {
355 P_UART0_TX
, P_UART0_RX
, 0
358 static struct platform_device bfin_uart0_device
= {
361 .num_resources
= ARRAY_SIZE(bfin_uart0_resources
),
362 .resource
= bfin_uart0_resources
,
364 .platform_data
= &bfin_uart0_peripherals
, /* Passed to driver */
370 #if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
371 #ifdef CONFIG_BFIN_SIR0
372 static struct resource bfin_sir0_resources
[] = {
376 .flags
= IORESOURCE_MEM
,
379 .start
= IRQ_UART0_RX
,
380 .end
= IRQ_UART0_RX
+1,
381 .flags
= IORESOURCE_IRQ
,
384 .start
= CH_UART0_RX
,
385 .end
= CH_UART0_RX
+1,
386 .flags
= IORESOURCE_DMA
,
390 static struct platform_device bfin_sir0_device
= {
393 .num_resources
= ARRAY_SIZE(bfin_sir0_resources
),
394 .resource
= bfin_sir0_resources
,
399 #if defined(CONFIG_SERIAL_BFIN_SPORT) || defined(CONFIG_SERIAL_BFIN_SPORT_MODULE)
400 #ifdef CONFIG_SERIAL_BFIN_SPORT0_UART
401 static struct resource bfin_sport0_uart_resources
[] = {
403 .start
= SPORT0_TCR1
,
404 .end
= SPORT0_MRCS3
+4,
405 .flags
= IORESOURCE_MEM
,
408 .start
= IRQ_SPORT0_RX
,
409 .end
= IRQ_SPORT0_RX
+1,
410 .flags
= IORESOURCE_IRQ
,
413 .start
= IRQ_SPORT0_ERROR
,
414 .end
= IRQ_SPORT0_ERROR
,
415 .flags
= IORESOURCE_IRQ
,
419 unsigned short bfin_sport0_peripherals
[] = {
420 P_SPORT0_TFS
, P_SPORT0_DTPRI
, P_SPORT0_TSCLK
, P_SPORT0_RFS
,
421 P_SPORT0_DRPRI
, P_SPORT0_RSCLK
, P_SPORT0_DRSEC
, P_SPORT0_DTSEC
, 0
424 static struct platform_device bfin_sport0_uart_device
= {
425 .name
= "bfin-sport-uart",
427 .num_resources
= ARRAY_SIZE(bfin_sport0_uart_resources
),
428 .resource
= bfin_sport0_uart_resources
,
430 .platform_data
= &bfin_sport0_peripherals
, /* Passed to driver */
434 #ifdef CONFIG_SERIAL_BFIN_SPORT1_UART
435 static struct resource bfin_sport1_uart_resources
[] = {
437 .start
= SPORT1_TCR1
,
438 .end
= SPORT1_MRCS3
+4,
439 .flags
= IORESOURCE_MEM
,
442 .start
= IRQ_SPORT1_RX
,
443 .end
= IRQ_SPORT1_RX
+1,
444 .flags
= IORESOURCE_IRQ
,
447 .start
= IRQ_SPORT1_ERROR
,
448 .end
= IRQ_SPORT1_ERROR
,
449 .flags
= IORESOURCE_IRQ
,
453 unsigned short bfin_sport1_peripherals
[] = {
454 P_SPORT1_TFS
, P_SPORT1_DTPRI
, P_SPORT1_TSCLK
, P_SPORT1_RFS
,
455 P_SPORT1_DRPRI
, P_SPORT1_RSCLK
, P_SPORT1_DRSEC
, P_SPORT1_DTSEC
, 0
458 static struct platform_device bfin_sport1_uart_device
= {
459 .name
= "bfin-sport-uart",
461 .num_resources
= ARRAY_SIZE(bfin_sport1_uart_resources
),
462 .resource
= bfin_sport1_uart_resources
,
464 .platform_data
= &bfin_sport1_peripherals
, /* Passed to driver */
470 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
471 #include <linux/input.h>
472 #include <linux/gpio_keys.h>
474 static struct gpio_keys_button bfin_gpio_keys_table
[] = {
475 {BTN_0
, GPIO_PF5
, 0, "gpio-keys: BTN0"},
476 {BTN_1
, GPIO_PF6
, 0, "gpio-keys: BTN1"},
477 {BTN_2
, GPIO_PF8
, 0, "gpio-keys: BTN2"},
480 static struct gpio_keys_platform_data bfin_gpio_keys_data
= {
481 .buttons
= bfin_gpio_keys_table
,
482 .nbuttons
= ARRAY_SIZE(bfin_gpio_keys_table
),
485 static struct platform_device bfin_device_gpiokeys
= {
488 .platform_data
= &bfin_gpio_keys_data
,
493 #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
494 #include <linux/i2c-gpio.h>
496 static struct i2c_gpio_platform_data i2c_gpio_data
= {
499 .sda_is_open_drain
= 0,
500 .scl_is_open_drain
= 0,
504 static struct platform_device i2c_gpio_device
= {
508 .platform_data
= &i2c_gpio_data
,
513 static struct i2c_board_info __initdata bfin_i2c_board_info
[] = {
514 #if defined(CONFIG_JOYSTICK_AD7142) || defined(CONFIG_JOYSTICK_AD7142_MODULE)
516 I2C_BOARD_INFO("ad7142_joystick", 0x2C),
520 #if defined(CONFIG_BFIN_TWI_LCD) || defined(CONFIG_BFIN_TWI_LCD_MODULE)
522 I2C_BOARD_INFO("pcf8574_lcd", 0x22),
525 #if defined(CONFIG_INPUT_PCF8574) || defined(CONFIG_INPUT_PCF8574_MODULE)
527 I2C_BOARD_INFO("pcf8574_keypad", 0x27),
531 #if defined(CONFIG_FB_BFIN_7393) || defined(CONFIG_FB_BFIN_7393_MODULE)
533 I2C_BOARD_INFO("bfin-adv7393", 0x2B),
538 static const unsigned int cclk_vlev_datasheet
[] =
540 VRPAIR(VLEV_085
, 250000000),
541 VRPAIR(VLEV_090
, 376000000),
542 VRPAIR(VLEV_095
, 426000000),
543 VRPAIR(VLEV_100
, 426000000),
544 VRPAIR(VLEV_105
, 476000000),
545 VRPAIR(VLEV_110
, 476000000),
546 VRPAIR(VLEV_115
, 476000000),
547 VRPAIR(VLEV_120
, 600000000),
548 VRPAIR(VLEV_125
, 600000000),
549 VRPAIR(VLEV_130
, 600000000),
552 static struct bfin_dpmc_platform_data bfin_dmpc_vreg_data
= {
553 .tuple_tab
= cclk_vlev_datasheet
,
554 .tabsize
= ARRAY_SIZE(cclk_vlev_datasheet
),
555 .vr_settling_time
= 25 /* us */,
558 static struct platform_device bfin_dpmc
= {
561 .platform_data
= &bfin_dmpc_vreg_data
,
565 static struct platform_device
*stamp_devices
[] __initdata
= {
569 #if defined(CONFIG_RTC_DRV_BFIN) || defined(CONFIG_RTC_DRV_BFIN_MODULE)
573 #if defined(CONFIG_SMC91X) || defined(CONFIG_SMC91X_MODULE)
577 #if defined(CONFIG_USB_NET2272) || defined(CONFIG_USB_NET2272_MODULE)
578 &net2272_bfin_device
,
581 #if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
585 #if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
586 #ifdef CONFIG_SERIAL_BFIN_UART0
591 #if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
592 #ifdef CONFIG_BFIN_SIR0
597 #if defined(CONFIG_SERIAL_BFIN_SPORT) || defined(CONFIG_SERIAL_BFIN_SPORT_MODULE)
598 #ifdef CONFIG_SERIAL_BFIN_SPORT0_UART
599 &bfin_sport0_uart_device
,
601 #ifdef CONFIG_SERIAL_BFIN_SPORT1_UART
602 &bfin_sport1_uart_device
,
606 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
607 &bfin_device_gpiokeys
,
610 #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
614 #if defined(CONFIG_MTD_BFIN_ASYNC) || defined(CONFIG_MTD_BFIN_ASYNC_MODULE)
619 static int __init
stamp_init(void)
623 printk(KERN_INFO
"%s(): registering device resources\n", __func__
);
625 i2c_register_board_info(0, bfin_i2c_board_info
,
626 ARRAY_SIZE(bfin_i2c_board_info
));
628 ret
= platform_add_devices(stamp_devices
, ARRAY_SIZE(stamp_devices
));
632 #if defined(CONFIG_SMC91X) || defined(CONFIG_SMC91X_MODULE)
633 /* setup BF533_STAMP CPLD to route AMS3 to Ethernet MAC */
634 bfin_write_FIO_DIR(bfin_read_FIO_DIR() | PF0
);
635 bfin_write_FIO_FLAG_S(PF0
);
639 spi_register_board_info(bfin_spi_board_info
, ARRAY_SIZE(bfin_spi_board_info
));
643 arch_initcall(stamp_init
);
645 static struct platform_device
*stamp_early_devices
[] __initdata
= {
646 #if defined(CONFIG_SERIAL_BFIN_CONSOLE) || defined(CONFIG_EARLY_PRINTK)
647 #ifdef CONFIG_SERIAL_BFIN_UART0
652 #if defined(CONFIG_SERIAL_BFIN_SPORT_CONSOLE)
653 #ifdef CONFIG_SERIAL_BFIN_SPORT0_UART
654 &bfin_sport0_uart_device
,
656 #ifdef CONFIG_SERIAL_BFIN_SPORT1_UART
657 &bfin_sport1_uart_device
,
662 void __init
native_machine_early_platform_add_devices(void)
664 printk(KERN_INFO
"register early platform devices\n");
665 early_platform_add_devices(stamp_early_devices
,
666 ARRAY_SIZE(stamp_early_devices
));
669 void native_machine_restart(char *cmd
)
671 /* workaround pull up on cpld / flash pin not being strong enough */
672 bfin_write_FIO_INEN(~PF0
);
673 bfin_write_FIO_DIR(PF0
);
674 bfin_write_FIO_FLAG_C(PF0
);