stamp.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. /*
  2. * Copyright 2004-2009 Analog Devices Inc.
  3. * 2005 National ICT Australia (NICTA)
  4. * Aidan Williams <aidan@nicta.com.au>
  5. *
  6. * Licensed under the GPL-2 or later.
  7. */
  8. #include <linux/device.h>
  9. #include <linux/platform_device.h>
  10. #include <linux/mtd/mtd.h>
  11. #include <linux/mtd/partitions.h>
  12. #include <linux/mtd/physmap.h>
  13. #include <linux/spi/spi.h>
  14. #include <linux/spi/flash.h>
  15. #include <linux/spi/mmc_spi.h>
  16. #if defined(CONFIG_USB_ISP1362_HCD) || defined(CONFIG_USB_ISP1362_HCD_MODULE)
  17. #include <linux/usb/isp1362.h>
  18. #endif
  19. #include <linux/irq.h>
  20. #include <linux/i2c.h>
  21. #include <asm/dma.h>
  22. #include <asm/bfin5xx_spi.h>
  23. #include <asm/reboot.h>
  24. #include <asm/portmux.h>
  25. #include <asm/dpmc.h>
  26. /*
  27. * Name the Board for the /proc/cpuinfo
  28. */
  29. const char bfin_board_name[] = "ADI BF533-STAMP";
  30. #if defined(CONFIG_RTC_DRV_BFIN) || defined(CONFIG_RTC_DRV_BFIN_MODULE)
  31. static struct platform_device rtc_device = {
  32. .name = "rtc-bfin",
  33. .id = -1,
  34. };
  35. #endif
  36. /*
  37. * Driver needs to know address, irq and flag pin.
  38. */
  39. #if defined(CONFIG_SMC91X) || defined(CONFIG_SMC91X_MODULE)
  40. #include <linux/smc91x.h>
  41. static struct smc91x_platdata smc91x_info = {
  42. .flags = SMC91X_USE_16BIT | SMC91X_NOWAIT,
  43. .leda = RPC_LED_100_10,
  44. .ledb = RPC_LED_TX_RX,
  45. };
  46. static struct resource smc91x_resources[] = {
  47. {
  48. .name = "smc91x-regs",
  49. .start = 0x20300300,
  50. .end = 0x20300300 + 16,
  51. .flags = IORESOURCE_MEM,
  52. }, {
  53. .start = IRQ_PF7,
  54. .end = IRQ_PF7,
  55. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL,
  56. },
  57. };
  58. static struct platform_device smc91x_device = {
  59. .name = "smc91x",
  60. .id = 0,
  61. .num_resources = ARRAY_SIZE(smc91x_resources),
  62. .resource = smc91x_resources,
  63. .dev = {
  64. .platform_data = &smc91x_info,
  65. },
  66. };
  67. #endif
  68. #if defined(CONFIG_USB_NET2272) || defined(CONFIG_USB_NET2272_MODULE)
  69. static struct resource net2272_bfin_resources[] = {
  70. {
  71. .start = 0x20300000,
  72. .end = 0x20300000 + 0x100,
  73. .flags = IORESOURCE_MEM,
  74. }, {
  75. .start = IRQ_PF10,
  76. .end = IRQ_PF10,
  77. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL,
  78. },
  79. };
  80. static struct platform_device net2272_bfin_device = {
  81. .name = "net2272",
  82. .id = -1,
  83. .num_resources = ARRAY_SIZE(net2272_bfin_resources),
  84. .resource = net2272_bfin_resources,
  85. };
  86. #endif
  87. #if defined(CONFIG_MTD_BFIN_ASYNC) || defined(CONFIG_MTD_BFIN_ASYNC_MODULE)
  88. static struct mtd_partition stamp_partitions[] = {
  89. {
  90. .name = "bootloader(nor)",
  91. .size = 0x40000,
  92. .offset = 0,
  93. }, {
  94. .name = "linux kernel(nor)",
  95. .size = 0x180000,
  96. .offset = MTDPART_OFS_APPEND,
  97. }, {
  98. .name = "file system(nor)",
  99. .size = MTDPART_SIZ_FULL,
  100. .offset = MTDPART_OFS_APPEND,
  101. }
  102. };
  103. static struct physmap_flash_data stamp_flash_data = {
  104. .width = 2,
  105. .parts = stamp_partitions,
  106. .nr_parts = ARRAY_SIZE(stamp_partitions),
  107. };
  108. static struct resource stamp_flash_resource[] = {
  109. {
  110. .name = "cfi_probe",
  111. .start = 0x20000000,
  112. .end = 0x203fffff,
  113. .flags = IORESOURCE_MEM,
  114. }, {
  115. .start = 0x7BB07BB0, /* AMBCTL0 setting when accessing flash */
  116. .end = 0x7BB07BB0, /* AMBCTL1 setting when accessing flash */
  117. .flags = IORESOURCE_MEM,
  118. }, {
  119. .start = GPIO_PF0,
  120. .flags = IORESOURCE_IRQ,
  121. }
  122. };
  123. static struct platform_device stamp_flash_device = {
  124. .name = "bfin-async-flash",
  125. .id = 0,
  126. .dev = {
  127. .platform_data = &stamp_flash_data,
  128. },
  129. .num_resources = ARRAY_SIZE(stamp_flash_resource),
  130. .resource = stamp_flash_resource,
  131. };
  132. #endif
  133. #if defined(CONFIG_MTD_M25P80) || defined(CONFIG_MTD_M25P80_MODULE)
  134. static struct mtd_partition bfin_spi_flash_partitions[] = {
  135. {
  136. .name = "bootloader(spi)",
  137. .size = 0x00040000,
  138. .offset = 0,
  139. .mask_flags = MTD_CAP_ROM
  140. }, {
  141. .name = "linux kernel(spi)",
  142. .size = 0x180000,
  143. .offset = MTDPART_OFS_APPEND,
  144. }, {
  145. .name = "file system(spi)",
  146. .size = MTDPART_SIZ_FULL,
  147. .offset = MTDPART_OFS_APPEND,
  148. }
  149. };
  150. static struct flash_platform_data bfin_spi_flash_data = {
  151. .name = "m25p80",
  152. .parts = bfin_spi_flash_partitions,
  153. .nr_parts = ARRAY_SIZE(bfin_spi_flash_partitions),
  154. .type = "m25p64",
  155. };
  156. /* SPI flash chip (m25p64) */
  157. static struct bfin5xx_spi_chip spi_flash_chip_info = {
  158. .enable_dma = 0, /* use dma transfer with this chip*/
  159. .bits_per_word = 8,
  160. };
  161. #endif
  162. #if defined(CONFIG_BFIN_SPI_ADC) || defined(CONFIG_BFIN_SPI_ADC_MODULE)
  163. /* SPI ADC chip */
  164. static struct bfin5xx_spi_chip spi_adc_chip_info = {
  165. .enable_dma = 1, /* use dma transfer with this chip*/
  166. .bits_per_word = 16,
  167. };
  168. #endif
  169. #if defined(CONFIG_SND_BLACKFIN_AD1836) || defined(CONFIG_SND_BLACKFIN_AD1836_MODULE)
  170. static struct bfin5xx_spi_chip ad1836_spi_chip_info = {
  171. .enable_dma = 0,
  172. .bits_per_word = 16,
  173. };
  174. #endif
  175. #if defined(CONFIG_SPI_SPIDEV) || defined(CONFIG_SPI_SPIDEV_MODULE)
  176. static struct bfin5xx_spi_chip spidev_chip_info = {
  177. .enable_dma = 0,
  178. .bits_per_word = 8,
  179. };
  180. #endif
  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)
  185. {
  186. return request_irq(MMC_SPI_CARD_DETECT_INT, detect_int,
  187. IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
  188. "mmc-spi-detect", data);
  189. }
  190. static void bfin_mmc_spi_exit(struct device *dev, void *data)
  191. {
  192. free_irq(MMC_SPI_CARD_DETECT_INT, data);
  193. }
  194. static struct mmc_spi_platform_data bfin_mmc_spi_pdata = {
  195. .init = bfin_mmc_spi_init,
  196. .exit = bfin_mmc_spi_exit,
  197. .detect_delay = 100, /* msecs */
  198. };
  199. static struct bfin5xx_spi_chip mmc_spi_chip_info = {
  200. .enable_dma = 0,
  201. .bits_per_word = 8,
  202. .pio_interrupt = 0,
  203. };
  204. #endif
  205. static struct spi_board_info bfin_spi_board_info[] __initdata = {
  206. #if defined(CONFIG_MTD_M25P80) || defined(CONFIG_MTD_M25P80_MODULE)
  207. {
  208. /* the modalias must be the same as spi device driver name */
  209. .modalias = "m25p80", /* Name of spi_driver for this device */
  210. .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */
  211. .bus_num = 0, /* Framework bus number */
  212. .chip_select = 2, /* Framework chip select. On STAMP537 it is SPISSEL2*/
  213. .platform_data = &bfin_spi_flash_data,
  214. .controller_data = &spi_flash_chip_info,
  215. .mode = SPI_MODE_3,
  216. },
  217. #endif
  218. #if defined(CONFIG_BFIN_SPI_ADC) || defined(CONFIG_BFIN_SPI_ADC_MODULE)
  219. {
  220. .modalias = "bfin_spi_adc", /* Name of spi_driver for this device */
  221. .max_speed_hz = 6250000, /* max spi clock (SCK) speed in HZ */
  222. .bus_num = 0, /* Framework bus number */
  223. .chip_select = 1, /* Framework chip select. */
  224. .platform_data = NULL, /* No spi_driver specific config */
  225. .controller_data = &spi_adc_chip_info,
  226. },
  227. #endif
  228. #if defined(CONFIG_SND_BLACKFIN_AD1836) || defined(CONFIG_SND_BLACKFIN_AD1836_MODULE)
  229. {
  230. .modalias = "ad1836",
  231. .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */
  232. .bus_num = 0,
  233. .chip_select = CONFIG_SND_BLACKFIN_SPI_PFBIT,
  234. .controller_data = &ad1836_spi_chip_info,
  235. },
  236. #endif
  237. #if defined(CONFIG_SPI_SPIDEV) || defined(CONFIG_SPI_SPIDEV_MODULE)
  238. {
  239. .modalias = "spidev",
  240. .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */
  241. .bus_num = 0,
  242. .chip_select = 1,
  243. .controller_data = &spidev_chip_info,
  244. },
  245. #endif
  246. #if defined(CONFIG_MMC_SPI) || defined(CONFIG_MMC_SPI_MODULE)
  247. {
  248. .modalias = "mmc_spi",
  249. .max_speed_hz = 20000000, /* max spi clock (SCK) speed in HZ */
  250. .bus_num = 0,
  251. .chip_select = 4,
  252. .platform_data = &bfin_mmc_spi_pdata,
  253. .controller_data = &mmc_spi_chip_info,
  254. .mode = SPI_MODE_3,
  255. },
  256. #endif
  257. };
  258. #if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
  259. /* SPI (0) */
  260. static struct resource bfin_spi0_resource[] = {
  261. [0] = {
  262. .start = SPI0_REGBASE,
  263. .end = SPI0_REGBASE + 0xFF,
  264. .flags = IORESOURCE_MEM,
  265. },
  266. [1] = {
  267. .start = CH_SPI,
  268. .end = CH_SPI,
  269. .flags = IORESOURCE_DMA,
  270. },
  271. [2] = {
  272. .start = IRQ_SPI,
  273. .end = IRQ_SPI,
  274. .flags = IORESOURCE_IRQ,
  275. }
  276. };
  277. /* SPI controller data */
  278. static struct bfin5xx_spi_master bfin_spi0_info = {
  279. .num_chipselect = 8,
  280. .enable_dma = 1, /* master has the ability to do dma transfer */
  281. .pin_req = {P_SPI0_SCK, P_SPI0_MISO, P_SPI0_MOSI, 0},
  282. };
  283. static struct platform_device bfin_spi0_device = {
  284. .name = "bfin-spi",
  285. .id = 0, /* Bus number */
  286. .num_resources = ARRAY_SIZE(bfin_spi0_resource),
  287. .resource = bfin_spi0_resource,
  288. .dev = {
  289. .platform_data = &bfin_spi0_info, /* Passed to driver */
  290. },
  291. };
  292. #endif /* spi master and devices */
  293. #if defined(CONFIG_FB_BF537_LQ035) || defined(CONFIG_FB_BF537_LQ035_MODULE)
  294. static struct platform_device bfin_fb_device = {
  295. .name = "bf537-fb",
  296. };
  297. #endif
  298. #if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
  299. static struct resource bfin_uart_resources[] = {
  300. {
  301. .start = 0xFFC00400,
  302. .end = 0xFFC004FF,
  303. .flags = IORESOURCE_MEM,
  304. },
  305. };
  306. static struct platform_device bfin_uart_device = {
  307. .name = "bfin-uart",
  308. .id = 1,
  309. .num_resources = ARRAY_SIZE(bfin_uart_resources),
  310. .resource = bfin_uart_resources,
  311. };
  312. #endif
  313. #if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
  314. #ifdef CONFIG_BFIN_SIR0
  315. static struct resource bfin_sir0_resources[] = {
  316. {
  317. .start = 0xFFC00400,
  318. .end = 0xFFC004FF,
  319. .flags = IORESOURCE_MEM,
  320. },
  321. {
  322. .start = IRQ_UART0_RX,
  323. .end = IRQ_UART0_RX+1,
  324. .flags = IORESOURCE_IRQ,
  325. },
  326. {
  327. .start = CH_UART0_RX,
  328. .end = CH_UART0_RX+1,
  329. .flags = IORESOURCE_DMA,
  330. },
  331. };
  332. static struct platform_device bfin_sir0_device = {
  333. .name = "bfin_sir",
  334. .id = 0,
  335. .num_resources = ARRAY_SIZE(bfin_sir0_resources),
  336. .resource = bfin_sir0_resources,
  337. };
  338. #endif
  339. #endif
  340. #if defined(CONFIG_SERIAL_BFIN_SPORT) || defined(CONFIG_SERIAL_BFIN_SPORT_MODULE)
  341. static struct platform_device bfin_sport0_uart_device = {
  342. .name = "bfin-sport-uart",
  343. .id = 0,
  344. };
  345. static struct platform_device bfin_sport1_uart_device = {
  346. .name = "bfin-sport-uart",
  347. .id = 1,
  348. };
  349. #endif
  350. #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
  351. #include <linux/input.h>
  352. #include <linux/gpio_keys.h>
  353. static struct gpio_keys_button bfin_gpio_keys_table[] = {
  354. {BTN_0, GPIO_PF5, 0, "gpio-keys: BTN0"},
  355. {BTN_1, GPIO_PF6, 0, "gpio-keys: BTN1"},
  356. {BTN_2, GPIO_PF8, 0, "gpio-keys: BTN2"},
  357. };
  358. static struct gpio_keys_platform_data bfin_gpio_keys_data = {
  359. .buttons = bfin_gpio_keys_table,
  360. .nbuttons = ARRAY_SIZE(bfin_gpio_keys_table),
  361. };
  362. static struct platform_device bfin_device_gpiokeys = {
  363. .name = "gpio-keys",
  364. .dev = {
  365. .platform_data = &bfin_gpio_keys_data,
  366. },
  367. };
  368. #endif
  369. #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
  370. #include <linux/i2c-gpio.h>
  371. static struct i2c_gpio_platform_data i2c_gpio_data = {
  372. .sda_pin = 2,
  373. .scl_pin = 3,
  374. .sda_is_open_drain = 0,
  375. .scl_is_open_drain = 0,
  376. .udelay = 40,
  377. };
  378. static struct platform_device i2c_gpio_device = {
  379. .name = "i2c-gpio",
  380. .id = 0,
  381. .dev = {
  382. .platform_data = &i2c_gpio_data,
  383. },
  384. };
  385. #endif
  386. static struct i2c_board_info __initdata bfin_i2c_board_info[] = {
  387. #if defined(CONFIG_JOYSTICK_AD7142) || defined(CONFIG_JOYSTICK_AD7142_MODULE)
  388. {
  389. I2C_BOARD_INFO("ad7142_joystick", 0x2C),
  390. .irq = 39,
  391. },
  392. #endif
  393. #if defined(CONFIG_BFIN_TWI_LCD) || defined(CONFIG_BFIN_TWI_LCD_MODULE)
  394. {
  395. I2C_BOARD_INFO("pcf8574_lcd", 0x22),
  396. },
  397. #endif
  398. #if defined(CONFIG_INPUT_PCF8574) || defined(CONFIG_INPUT_PCF8574_MODULE)
  399. {
  400. I2C_BOARD_INFO("pcf8574_keypad", 0x27),
  401. .irq = 39,
  402. },
  403. #endif
  404. #if defined(CONFIG_FB_BFIN_7393) || defined(CONFIG_FB_BFIN_7393_MODULE)
  405. {
  406. I2C_BOARD_INFO("bfin-adv7393", 0x2B),
  407. },
  408. #endif
  409. };
  410. static const unsigned int cclk_vlev_datasheet[] =
  411. {
  412. VRPAIR(VLEV_085, 250000000),
  413. VRPAIR(VLEV_090, 376000000),
  414. VRPAIR(VLEV_095, 426000000),
  415. VRPAIR(VLEV_100, 426000000),
  416. VRPAIR(VLEV_105, 476000000),
  417. VRPAIR(VLEV_110, 476000000),
  418. VRPAIR(VLEV_115, 476000000),
  419. VRPAIR(VLEV_120, 600000000),
  420. VRPAIR(VLEV_125, 600000000),
  421. VRPAIR(VLEV_130, 600000000),
  422. };
  423. static struct bfin_dpmc_platform_data bfin_dmpc_vreg_data = {
  424. .tuple_tab = cclk_vlev_datasheet,
  425. .tabsize = ARRAY_SIZE(cclk_vlev_datasheet),
  426. .vr_settling_time = 25 /* us */,
  427. };
  428. static struct platform_device bfin_dpmc = {
  429. .name = "bfin dpmc",
  430. .dev = {
  431. .platform_data = &bfin_dmpc_vreg_data,
  432. },
  433. };
  434. static struct platform_device *stamp_devices[] __initdata = {
  435. &bfin_dpmc,
  436. #if defined(CONFIG_RTC_DRV_BFIN) || defined(CONFIG_RTC_DRV_BFIN_MODULE)
  437. &rtc_device,
  438. #endif
  439. #if defined(CONFIG_SMC91X) || defined(CONFIG_SMC91X_MODULE)
  440. &smc91x_device,
  441. #endif
  442. #if defined(CONFIG_USB_NET2272) || defined(CONFIG_USB_NET2272_MODULE)
  443. &net2272_bfin_device,
  444. #endif
  445. #if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
  446. &bfin_spi0_device,
  447. #endif
  448. #if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
  449. &bfin_uart_device,
  450. #endif
  451. #if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
  452. #ifdef CONFIG_BFIN_SIR0
  453. &bfin_sir0_device,
  454. #endif
  455. #endif
  456. #if defined(CONFIG_SERIAL_BFIN_SPORT) || defined(CONFIG_SERIAL_BFIN_SPORT_MODULE)
  457. &bfin_sport0_uart_device,
  458. &bfin_sport1_uart_device,
  459. #endif
  460. #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
  461. &bfin_device_gpiokeys,
  462. #endif
  463. #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
  464. &i2c_gpio_device,
  465. #endif
  466. #if defined(CONFIG_MTD_BFIN_ASYNC) || defined(CONFIG_MTD_BFIN_ASYNC_MODULE)
  467. &stamp_flash_device,
  468. #endif
  469. };
  470. static int __init stamp_init(void)
  471. {
  472. int ret;
  473. printk(KERN_INFO "%s(): registering device resources\n", __func__);
  474. i2c_register_board_info(0, bfin_i2c_board_info,
  475. ARRAY_SIZE(bfin_i2c_board_info));
  476. ret = platform_add_devices(stamp_devices, ARRAY_SIZE(stamp_devices));
  477. if (ret < 0)
  478. return ret;
  479. #if defined(CONFIG_SMC91X) || defined(CONFIG_SMC91X_MODULE)
  480. /* setup BF533_STAMP CPLD to route AMS3 to Ethernet MAC */
  481. bfin_write_FIO_DIR(bfin_read_FIO_DIR() | PF0);
  482. bfin_write_FIO_FLAG_S(PF0);
  483. SSYNC();
  484. #endif
  485. spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info));
  486. return 0;
  487. }
  488. arch_initcall(stamp_init);
  489. void native_machine_restart(char *cmd)
  490. {
  491. /* workaround pull up on cpld / flash pin not being strong enough */
  492. bfin_write_FIO_INEN(~PF0);
  493. bfin_write_FIO_DIR(PF0);
  494. bfin_write_FIO_FLAG_C(PF0);
  495. }