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
,
84 .flags
= IORESOURCE_BUS
,
88 .flags
= IORESOURCE_IRQ
| IORESOURCE_IRQ_HIGHLEVEL
,
92 static struct platform_device net2272_bfin_device
= {
95 .num_resources
= ARRAY_SIZE(net2272_bfin_resources
),
96 .resource
= net2272_bfin_resources
,
100 #if defined(CONFIG_MTD_BFIN_ASYNC) || defined(CONFIG_MTD_BFIN_ASYNC_MODULE)
101 static struct mtd_partition stamp_partitions
[] = {
103 .name
= "bootloader(nor)",
107 .name
= "linux kernel(nor)",
109 .offset
= MTDPART_OFS_APPEND
,
111 .name
= "file system(nor)",
112 .size
= MTDPART_SIZ_FULL
,
113 .offset
= MTDPART_OFS_APPEND
,
117 static struct physmap_flash_data stamp_flash_data
= {
119 .parts
= stamp_partitions
,
120 .nr_parts
= ARRAY_SIZE(stamp_partitions
),
123 static struct resource stamp_flash_resource
[] = {
128 .flags
= IORESOURCE_MEM
,
130 .start
= 0x7BB07BB0, /* AMBCTL0 setting when accessing flash */
131 .end
= 0x7BB07BB0, /* AMBCTL1 setting when accessing flash */
132 .flags
= IORESOURCE_MEM
,
135 .flags
= IORESOURCE_IRQ
,
139 static struct platform_device stamp_flash_device
= {
140 .name
= "bfin-async-flash",
143 .platform_data
= &stamp_flash_data
,
145 .num_resources
= ARRAY_SIZE(stamp_flash_resource
),
146 .resource
= stamp_flash_resource
,
150 #if defined(CONFIG_MTD_M25P80) || defined(CONFIG_MTD_M25P80_MODULE)
151 static struct mtd_partition bfin_spi_flash_partitions
[] = {
153 .name
= "bootloader(spi)",
156 .mask_flags
= MTD_CAP_ROM
158 .name
= "linux kernel(spi)",
160 .offset
= MTDPART_OFS_APPEND
,
162 .name
= "file system(spi)",
163 .size
= MTDPART_SIZ_FULL
,
164 .offset
= MTDPART_OFS_APPEND
,
168 static struct flash_platform_data bfin_spi_flash_data
= {
170 .parts
= bfin_spi_flash_partitions
,
171 .nr_parts
= ARRAY_SIZE(bfin_spi_flash_partitions
),
175 /* SPI flash chip (m25p64) */
176 static struct bfin5xx_spi_chip spi_flash_chip_info
= {
177 .enable_dma
= 0, /* use dma transfer with this chip*/
181 #if defined(CONFIG_MMC_SPI) || defined(CONFIG_MMC_SPI_MODULE)
182 #define MMC_SPI_CARD_DETECT_INT IRQ_PF5
183 static int bfin_mmc_spi_init(struct device
*dev
,
184 irqreturn_t (*detect_int
)(int, void *), void *data
)
186 return request_irq(MMC_SPI_CARD_DETECT_INT
, detect_int
,
187 IRQF_TRIGGER_FALLING
| IRQF_TRIGGER_RISING
,
188 "mmc-spi-detect", data
);
191 static void bfin_mmc_spi_exit(struct device
*dev
, void *data
)
193 free_irq(MMC_SPI_CARD_DETECT_INT
, data
);
196 static struct mmc_spi_platform_data bfin_mmc_spi_pdata
= {
197 .init
= bfin_mmc_spi_init
,
198 .exit
= bfin_mmc_spi_exit
,
199 .detect_delay
= 100, /* msecs */
202 static struct bfin5xx_spi_chip mmc_spi_chip_info
= {
208 static struct spi_board_info bfin_spi_board_info
[] __initdata
= {
209 #if defined(CONFIG_MTD_M25P80) || defined(CONFIG_MTD_M25P80_MODULE)
211 /* the modalias must be the same as spi device driver name */
212 .modalias
= "m25p80", /* Name of spi_driver for this device */
213 .max_speed_hz
= 25000000, /* max spi clock (SCK) speed in HZ */
214 .bus_num
= 0, /* Framework bus number */
215 .chip_select
= 2, /* Framework chip select. On STAMP537 it is SPISSEL2*/
216 .platform_data
= &bfin_spi_flash_data
,
217 .controller_data
= &spi_flash_chip_info
,
222 #if defined(CONFIG_SND_BF5XX_SOC_AD183X) || defined(CONFIG_SND_BF5XX_SOC_AD183X_MODULE)
224 .modalias
= "ad183x",
225 .max_speed_hz
= 3125000, /* max spi clock (SCK) speed in HZ */
228 .platform_data
= "ad1836", /* only includes chip name for the moment */
233 #if defined(CONFIG_SPI_SPIDEV) || defined(CONFIG_SPI_SPIDEV_MODULE)
235 .modalias
= "spidev",
236 .max_speed_hz
= 3125000, /* max spi clock (SCK) speed in HZ */
241 #if defined(CONFIG_MMC_SPI) || defined(CONFIG_MMC_SPI_MODULE)
243 .modalias
= "mmc_spi",
244 .max_speed_hz
= 20000000, /* max spi clock (SCK) speed in HZ */
247 .platform_data
= &bfin_mmc_spi_pdata
,
248 .controller_data
= &mmc_spi_chip_info
,
254 #if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
256 static struct resource bfin_spi0_resource
[] = {
258 .start
= SPI0_REGBASE
,
259 .end
= SPI0_REGBASE
+ 0xFF,
260 .flags
= IORESOURCE_MEM
,
265 .flags
= IORESOURCE_DMA
,
270 .flags
= IORESOURCE_IRQ
,
274 /* SPI controller data */
275 static struct bfin5xx_spi_master bfin_spi0_info
= {
277 .enable_dma
= 1, /* master has the ability to do dma transfer */
278 .pin_req
= {P_SPI0_SCK
, P_SPI0_MISO
, P_SPI0_MOSI
, 0},
281 static struct platform_device bfin_spi0_device
= {
283 .id
= 0, /* Bus number */
284 .num_resources
= ARRAY_SIZE(bfin_spi0_resource
),
285 .resource
= bfin_spi0_resource
,
287 .platform_data
= &bfin_spi0_info
, /* Passed to driver */
290 #endif /* spi master and devices */
292 #if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
293 #ifdef CONFIG_SERIAL_BFIN_UART0
294 static struct resource bfin_uart0_resources
[] = {
296 .start
= BFIN_UART_THR
,
297 .end
= BFIN_UART_GCTL
+2,
298 .flags
= IORESOURCE_MEM
,
301 .start
= IRQ_UART0_TX
,
303 .flags
= IORESOURCE_IRQ
,
306 .start
= IRQ_UART0_RX
,
308 .flags
= IORESOURCE_IRQ
,
311 .start
= IRQ_UART0_ERROR
,
312 .end
= IRQ_UART0_ERROR
,
313 .flags
= IORESOURCE_IRQ
,
316 .start
= CH_UART0_TX
,
318 .flags
= IORESOURCE_DMA
,
321 .start
= CH_UART0_RX
,
323 .flags
= IORESOURCE_DMA
,
327 static unsigned short bfin_uart0_peripherals
[] = {
328 P_UART0_TX
, P_UART0_RX
, 0
331 static struct platform_device bfin_uart0_device
= {
334 .num_resources
= ARRAY_SIZE(bfin_uart0_resources
),
335 .resource
= bfin_uart0_resources
,
337 .platform_data
= &bfin_uart0_peripherals
, /* Passed to driver */
343 #if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
344 #ifdef CONFIG_BFIN_SIR0
345 static struct resource bfin_sir0_resources
[] = {
349 .flags
= IORESOURCE_MEM
,
352 .start
= IRQ_UART0_RX
,
353 .end
= IRQ_UART0_RX
+1,
354 .flags
= IORESOURCE_IRQ
,
357 .start
= CH_UART0_RX
,
358 .end
= CH_UART0_RX
+1,
359 .flags
= IORESOURCE_DMA
,
363 static struct platform_device bfin_sir0_device
= {
366 .num_resources
= ARRAY_SIZE(bfin_sir0_resources
),
367 .resource
= bfin_sir0_resources
,
372 #if defined(CONFIG_SERIAL_BFIN_SPORT) || defined(CONFIG_SERIAL_BFIN_SPORT_MODULE)
373 #ifdef CONFIG_SERIAL_BFIN_SPORT0_UART
374 static struct resource bfin_sport0_uart_resources
[] = {
376 .start
= SPORT0_TCR1
,
377 .end
= SPORT0_MRCS3
+4,
378 .flags
= IORESOURCE_MEM
,
381 .start
= IRQ_SPORT0_RX
,
382 .end
= IRQ_SPORT0_RX
+1,
383 .flags
= IORESOURCE_IRQ
,
386 .start
= IRQ_SPORT0_ERROR
,
387 .end
= IRQ_SPORT0_ERROR
,
388 .flags
= IORESOURCE_IRQ
,
392 static unsigned short bfin_sport0_peripherals
[] = {
393 P_SPORT0_TFS
, P_SPORT0_DTPRI
, P_SPORT0_TSCLK
, P_SPORT0_RFS
,
394 P_SPORT0_DRPRI
, P_SPORT0_RSCLK
, 0
397 static struct platform_device bfin_sport0_uart_device
= {
398 .name
= "bfin-sport-uart",
400 .num_resources
= ARRAY_SIZE(bfin_sport0_uart_resources
),
401 .resource
= bfin_sport0_uart_resources
,
403 .platform_data
= &bfin_sport0_peripherals
, /* Passed to driver */
407 #ifdef CONFIG_SERIAL_BFIN_SPORT1_UART
408 static struct resource bfin_sport1_uart_resources
[] = {
410 .start
= SPORT1_TCR1
,
411 .end
= SPORT1_MRCS3
+4,
412 .flags
= IORESOURCE_MEM
,
415 .start
= IRQ_SPORT1_RX
,
416 .end
= IRQ_SPORT1_RX
+1,
417 .flags
= IORESOURCE_IRQ
,
420 .start
= IRQ_SPORT1_ERROR
,
421 .end
= IRQ_SPORT1_ERROR
,
422 .flags
= IORESOURCE_IRQ
,
426 static unsigned short bfin_sport1_peripherals
[] = {
427 P_SPORT1_TFS
, P_SPORT1_DTPRI
, P_SPORT1_TSCLK
, P_SPORT1_RFS
,
428 P_SPORT1_DRPRI
, P_SPORT1_RSCLK
, 0
431 static struct platform_device bfin_sport1_uart_device
= {
432 .name
= "bfin-sport-uart",
434 .num_resources
= ARRAY_SIZE(bfin_sport1_uart_resources
),
435 .resource
= bfin_sport1_uart_resources
,
437 .platform_data
= &bfin_sport1_peripherals
, /* Passed to driver */
443 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
444 #include <linux/input.h>
445 #include <linux/gpio_keys.h>
447 static struct gpio_keys_button bfin_gpio_keys_table
[] = {
448 {BTN_0
, GPIO_PF5
, 0, "gpio-keys: BTN0"},
449 {BTN_1
, GPIO_PF6
, 0, "gpio-keys: BTN1"},
450 {BTN_2
, GPIO_PF8
, 0, "gpio-keys: BTN2"},
453 static struct gpio_keys_platform_data bfin_gpio_keys_data
= {
454 .buttons
= bfin_gpio_keys_table
,
455 .nbuttons
= ARRAY_SIZE(bfin_gpio_keys_table
),
458 static struct platform_device bfin_device_gpiokeys
= {
461 .platform_data
= &bfin_gpio_keys_data
,
466 #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
467 #include <linux/i2c-gpio.h>
469 static struct i2c_gpio_platform_data i2c_gpio_data
= {
472 .sda_is_open_drain
= 0,
473 .scl_is_open_drain
= 0,
477 static struct platform_device i2c_gpio_device
= {
481 .platform_data
= &i2c_gpio_data
,
486 static struct i2c_board_info __initdata bfin_i2c_board_info
[] = {
487 #if defined(CONFIG_JOYSTICK_AD7142) || defined(CONFIG_JOYSTICK_AD7142_MODULE)
489 I2C_BOARD_INFO("ad7142_joystick", 0x2C),
493 #if defined(CONFIG_BFIN_TWI_LCD) || defined(CONFIG_BFIN_TWI_LCD_MODULE)
495 I2C_BOARD_INFO("pcf8574_lcd", 0x22),
498 #if defined(CONFIG_INPUT_PCF8574) || defined(CONFIG_INPUT_PCF8574_MODULE)
500 I2C_BOARD_INFO("pcf8574_keypad", 0x27),
504 #if defined(CONFIG_FB_BFIN_7393) || defined(CONFIG_FB_BFIN_7393_MODULE)
506 I2C_BOARD_INFO("bfin-adv7393", 0x2B),
509 #if defined(CONFIG_BFIN_TWI_LCD) || defined(CONFIG_BFIN_TWI_LCD_MODULE)
511 I2C_BOARD_INFO("ad5252", 0x2f),
516 static const unsigned int cclk_vlev_datasheet
[] =
518 VRPAIR(VLEV_085
, 250000000),
519 VRPAIR(VLEV_090
, 376000000),
520 VRPAIR(VLEV_095
, 426000000),
521 VRPAIR(VLEV_100
, 426000000),
522 VRPAIR(VLEV_105
, 476000000),
523 VRPAIR(VLEV_110
, 476000000),
524 VRPAIR(VLEV_115
, 476000000),
525 VRPAIR(VLEV_120
, 600000000),
526 VRPAIR(VLEV_125
, 600000000),
527 VRPAIR(VLEV_130
, 600000000),
530 static struct bfin_dpmc_platform_data bfin_dmpc_vreg_data
= {
531 .tuple_tab
= cclk_vlev_datasheet
,
532 .tabsize
= ARRAY_SIZE(cclk_vlev_datasheet
),
533 .vr_settling_time
= 25 /* us */,
536 static struct platform_device bfin_dpmc
= {
539 .platform_data
= &bfin_dmpc_vreg_data
,
543 #if defined(CONFIG_SND_BF5XX_I2S) || defined(CONFIG_SND_BF5XX_I2S_MODULE)
544 static struct platform_device bfin_i2s
= {
546 .id
= CONFIG_SND_BF5XX_SPORT_NUM
,
547 /* TODO: add platform data here */
551 #if defined(CONFIG_SND_BF5XX_TDM) || defined(CONFIG_SND_BF5XX_TDM_MODULE)
552 static struct platform_device bfin_tdm
= {
554 .id
= CONFIG_SND_BF5XX_SPORT_NUM
,
555 /* TODO: add platform data here */
559 #if defined(CONFIG_SND_BF5XX_AC97) || defined(CONFIG_SND_BF5XX_AC97_MODULE)
560 static struct platform_device bfin_ac97
= {
562 .id
= CONFIG_SND_BF5XX_SPORT_NUM
,
563 /* TODO: add platform data here */
567 static struct platform_device
*stamp_devices
[] __initdata
= {
571 #if defined(CONFIG_RTC_DRV_BFIN) || defined(CONFIG_RTC_DRV_BFIN_MODULE)
575 #if defined(CONFIG_SMC91X) || defined(CONFIG_SMC91X_MODULE)
579 #if defined(CONFIG_USB_NET2272) || defined(CONFIG_USB_NET2272_MODULE)
580 &net2272_bfin_device
,
583 #if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
587 #if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
588 #ifdef CONFIG_SERIAL_BFIN_UART0
593 #if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
594 #ifdef CONFIG_BFIN_SIR0
599 #if defined(CONFIG_SERIAL_BFIN_SPORT) || defined(CONFIG_SERIAL_BFIN_SPORT_MODULE)
600 #ifdef CONFIG_SERIAL_BFIN_SPORT0_UART
601 &bfin_sport0_uart_device
,
603 #ifdef CONFIG_SERIAL_BFIN_SPORT1_UART
604 &bfin_sport1_uart_device
,
608 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
609 &bfin_device_gpiokeys
,
612 #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
616 #if defined(CONFIG_MTD_BFIN_ASYNC) || defined(CONFIG_MTD_BFIN_ASYNC_MODULE)
620 #if defined(CONFIG_SND_BF5XX_I2S) || defined(CONFIG_SND_BF5XX_I2S_MODULE)
624 #if defined(CONFIG_SND_BF5XX_TDM) || defined(CONFIG_SND_BF5XX_TDM_MODULE)
628 #if defined(CONFIG_SND_BF5XX_AC97) || defined(CONFIG_SND_BF5XX_AC97_MODULE)
633 static int __init
net2272_init(void)
635 #if defined(CONFIG_USB_NET2272) || defined(CONFIG_USB_NET2272_MODULE)
638 /* Set PF0 to 0, PF1 to 1 make /AMS3 work properly */
639 ret
= gpio_request(GPIO_PF0
, "net2272");
643 ret
= gpio_request(GPIO_PF1
, "net2272");
649 ret
= gpio_request(GPIO_PF11
, "net2272");
656 gpio_direction_output(GPIO_PF0
, 0);
657 gpio_direction_output(GPIO_PF1
, 1);
659 /* Reset the USB chip */
660 gpio_direction_output(GPIO_PF11
, 0);
662 gpio_set_value(GPIO_PF11
, 1);
668 static int __init
stamp_init(void)
672 printk(KERN_INFO
"%s(): registering device resources\n", __func__
);
674 i2c_register_board_info(0, bfin_i2c_board_info
,
675 ARRAY_SIZE(bfin_i2c_board_info
));
677 ret
= platform_add_devices(stamp_devices
, ARRAY_SIZE(stamp_devices
));
681 #if defined(CONFIG_SMC91X) || defined(CONFIG_SMC91X_MODULE)
683 * setup BF533_STAMP CPLD to route AMS3 to Ethernet MAC.
684 * the bfin-async-map driver takes care of flipping between
685 * flash and ethernet when necessary.
687 ret
= gpio_request(GPIO_PF0
, "enet_cpld");
689 gpio_direction_output(GPIO_PF0
, 1);
695 pr_warning("unable to configure net2272; it probably won't work\n");
697 spi_register_board_info(bfin_spi_board_info
, ARRAY_SIZE(bfin_spi_board_info
));
701 arch_initcall(stamp_init
);
703 static struct platform_device
*stamp_early_devices
[] __initdata
= {
704 #if defined(CONFIG_SERIAL_BFIN_CONSOLE) || defined(CONFIG_EARLY_PRINTK)
705 #ifdef CONFIG_SERIAL_BFIN_UART0
710 #if defined(CONFIG_SERIAL_BFIN_SPORT_CONSOLE)
711 #ifdef CONFIG_SERIAL_BFIN_SPORT0_UART
712 &bfin_sport0_uart_device
,
714 #ifdef CONFIG_SERIAL_BFIN_SPORT1_UART
715 &bfin_sport1_uart_device
,
720 void __init
native_machine_early_platform_add_devices(void)
722 printk(KERN_INFO
"register early platform devices\n");
723 early_platform_add_devices(stamp_early_devices
,
724 ARRAY_SIZE(stamp_early_devices
));
727 void native_machine_restart(char *cmd
)
729 /* workaround pull up on cpld / flash pin not being strong enough */
730 gpio_request(GPIO_PF0
, "flash_cpld");
731 gpio_direction_output(GPIO_PF0
, 0);