acvilon.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. /*
  2. * File: arch/blackfin/mach-bf561/acvilon.c
  3. * Based on: arch/blackfin/mach-bf561/ezkit.c
  4. * Author:
  5. *
  6. * Created:
  7. * Description:
  8. *
  9. * Modified:
  10. * Copyright 2004-2006 Analog Devices Inc.
  11. * Copyright 2009 CJSC "NII STT"
  12. *
  13. * Bugs:
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 2 of the License, or
  18. * (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, see the file COPYING, or write
  27. * to the Free Software Foundation, Inc.,
  28. * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  29. *
  30. *
  31. * For more information about Acvilon BF561 SoM please
  32. * go to http://www.niistt.ru/
  33. *
  34. */
  35. #include <linux/device.h>
  36. #include <linux/platform_device.h>
  37. #include <linux/mtd/mtd.h>
  38. #include <linux/mtd/partitions.h>
  39. #include <linux/mtd/physmap.h>
  40. #include <linux/mtd/nand.h>
  41. #include <linux/mtd/plat-ram.h>
  42. #include <linux/spi/spi.h>
  43. #include <linux/spi/flash.h>
  44. #include <linux/irq.h>
  45. #include <linux/interrupt.h>
  46. #include <linux/i2c-pca-platform.h>
  47. #include <linux/delay.h>
  48. #include <linux/io.h>
  49. #include <asm/dma.h>
  50. #include <asm/bfin5xx_spi.h>
  51. #include <asm/portmux.h>
  52. #include <asm/dpmc.h>
  53. #include <asm/cacheflush.h>
  54. #include <linux/i2c.h>
  55. /*
  56. * Name the Board for the /proc/cpuinfo
  57. */
  58. const char bfin_board_name[] = "Acvilon board";
  59. #if defined(CONFIG_USB_ISP1760_HCD) || defined(CONFIG_USB_ISP1760_HCD_MODULE)
  60. #include <linux/usb/isp1760.h>
  61. static struct resource bfin_isp1760_resources[] = {
  62. [0] = {
  63. .start = 0x20000000,
  64. .end = 0x20000000 + 0x000fffff,
  65. .flags = IORESOURCE_MEM,
  66. },
  67. [1] = {
  68. .start = IRQ_PF15,
  69. .end = IRQ_PF15,
  70. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
  71. },
  72. };
  73. static struct isp1760_platform_data isp1760_priv = {
  74. .is_isp1761 = 0,
  75. .port1_disable = 0,
  76. .bus_width_16 = 1,
  77. .port1_otg = 0,
  78. .analog_oc = 0,
  79. .dack_polarity_high = 0,
  80. .dreq_polarity_high = 0,
  81. };
  82. static struct platform_device bfin_isp1760_device = {
  83. .name = "isp1760-hcd",
  84. .id = 0,
  85. .dev = {
  86. .platform_data = &isp1760_priv,
  87. },
  88. .num_resources = ARRAY_SIZE(bfin_isp1760_resources),
  89. .resource = bfin_isp1760_resources,
  90. };
  91. #endif
  92. static struct resource bfin_i2c_pca_resources[] = {
  93. {
  94. .name = "pca9564-regs",
  95. .start = 0x2C000000,
  96. .end = 0x2C000000 + 16,
  97. .flags = IORESOURCE_MEM | IORESOURCE_MEM_32BIT,
  98. }, {
  99. .start = IRQ_PF8,
  100. .end = IRQ_PF8,
  101. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
  102. },
  103. };
  104. struct i2c_pca9564_pf_platform_data pca9564_platform_data = {
  105. .gpio = -1,
  106. .i2c_clock_speed = 330000,
  107. .timeout = 10000
  108. };
  109. /* PCA9564 I2C Bus driver */
  110. static struct platform_device bfin_i2c_pca_device = {
  111. .name = "i2c-pca-platform",
  112. .id = 0,
  113. .num_resources = ARRAY_SIZE(bfin_i2c_pca_resources),
  114. .resource = bfin_i2c_pca_resources,
  115. .dev = {
  116. .platform_data = &pca9564_platform_data,
  117. }
  118. };
  119. /* I2C devices fitted. */
  120. static struct i2c_board_info acvilon_i2c_devs[] __initdata = {
  121. {
  122. I2C_BOARD_INFO("ds1339", 0x68),
  123. },
  124. {
  125. I2C_BOARD_INFO("tcn75", 0x49),
  126. },
  127. };
  128. #if defined(CONFIG_MTD_PLATRAM) || defined(CONFIG_MTD_PLATRAM_MODULE)
  129. static struct platdata_mtd_ram mtd_ram_data = {
  130. .mapname = "rootfs(RAM)",
  131. .bankwidth = 4,
  132. };
  133. static struct resource mtd_ram_resource = {
  134. .start = 0x4000000,
  135. .end = 0x5ffffff,
  136. .flags = IORESOURCE_MEM,
  137. };
  138. static struct platform_device mtd_ram_device = {
  139. .name = "mtd-ram",
  140. .id = 0,
  141. .dev = {
  142. .platform_data = &mtd_ram_data,
  143. },
  144. .num_resources = 1,
  145. .resource = &mtd_ram_resource,
  146. };
  147. #endif
  148. #if defined(CONFIG_SMSC911X) || defined(CONFIG_SMSC911X_MODULE)
  149. #include <linux/smsc911x.h>
  150. static struct resource smsc911x_resources[] = {
  151. {
  152. .name = "smsc911x-memory",
  153. .start = 0x28000000,
  154. .end = 0x28000000 + 0xFF,
  155. .flags = IORESOURCE_MEM,
  156. },
  157. {
  158. .start = IRQ_PF7,
  159. .end = IRQ_PF7,
  160. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
  161. },
  162. };
  163. static struct smsc911x_platform_config smsc911x_config = {
  164. .flags = SMSC911X_USE_32BIT,
  165. .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
  166. .irq_type = SMSC911X_IRQ_TYPE_OPEN_DRAIN,
  167. .phy_interface = PHY_INTERFACE_MODE_MII,
  168. };
  169. static struct platform_device smsc911x_device = {
  170. .name = "smsc911x",
  171. .id = 0,
  172. .num_resources = ARRAY_SIZE(smsc911x_resources),
  173. .resource = smsc911x_resources,
  174. .dev = {
  175. .platform_data = &smsc911x_config,
  176. },
  177. };
  178. #endif
  179. #if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
  180. #ifdef CONFIG_SERIAL_BFIN_UART0
  181. static struct resource bfin_uart0_resources[] = {
  182. {
  183. .start = BFIN_UART_THR,
  184. .end = BFIN_UART_GCTL + 2,
  185. .flags = IORESOURCE_MEM,
  186. },
  187. {
  188. .start = IRQ_UART_RX,
  189. .end = IRQ_UART_RX + 1,
  190. .flags = IORESOURCE_IRQ,
  191. },
  192. {
  193. .start = IRQ_UART_ERROR,
  194. .end = IRQ_UART_ERROR,
  195. .flags = IORESOURCE_IRQ,
  196. },
  197. {
  198. .start = CH_UART_TX,
  199. .end = CH_UART_TX,
  200. .flags = IORESOURCE_DMA,
  201. },
  202. {
  203. .start = CH_UART_RX,
  204. .end = CH_UART_RX,
  205. .flags = IORESOURCE_DMA,
  206. },
  207. };
  208. unsigned short bfin_uart0_peripherals[] = {
  209. P_UART0_TX, P_UART0_RX, 0
  210. };
  211. static struct platform_device bfin_uart0_device = {
  212. .name = "bfin-uart",
  213. .id = 0,
  214. .num_resources = ARRAY_SIZE(bfin_uart0_resources),
  215. .resource = bfin_uart0_resources,
  216. .dev = {
  217. /* Passed to driver */
  218. .platform_data = &bfin_uart0_peripherals,
  219. },
  220. };
  221. #endif
  222. #endif
  223. #if defined(CONFIG_MTD_NAND_PLATFORM) || defined(CONFIG_MTD_NAND_PLATFORM_MODULE)
  224. #ifdef CONFIG_MTD_PARTITIONS
  225. const char *part_probes[] = { "cmdlinepart", NULL };
  226. static struct mtd_partition bfin_plat_nand_partitions[] = {
  227. {
  228. .name = "params(nand)",
  229. .size = 32 * 1024 * 1024,
  230. .offset = 0,
  231. }, {
  232. .name = "userfs(nand)",
  233. .size = MTDPART_SIZ_FULL,
  234. .offset = MTDPART_OFS_APPEND,
  235. },
  236. };
  237. #endif
  238. #define BFIN_NAND_PLAT_CLE 2
  239. #define BFIN_NAND_PLAT_ALE 3
  240. static void bfin_plat_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
  241. unsigned int ctrl)
  242. {
  243. struct nand_chip *this = mtd->priv;
  244. if (cmd == NAND_CMD_NONE)
  245. return;
  246. if (ctrl & NAND_CLE)
  247. writeb(cmd, this->IO_ADDR_W + (1 << BFIN_NAND_PLAT_CLE));
  248. else
  249. writeb(cmd, this->IO_ADDR_W + (1 << BFIN_NAND_PLAT_ALE));
  250. }
  251. #define BFIN_NAND_PLAT_READY GPIO_PF10
  252. static int bfin_plat_nand_dev_ready(struct mtd_info *mtd)
  253. {
  254. return gpio_get_value(BFIN_NAND_PLAT_READY);
  255. }
  256. static struct platform_nand_data bfin_plat_nand_data = {
  257. .chip = {
  258. .chip_delay = 30,
  259. #ifdef CONFIG_MTD_PARTITIONS
  260. .part_probe_types = part_probes,
  261. .partitions = bfin_plat_nand_partitions,
  262. .nr_partitions = ARRAY_SIZE(bfin_plat_nand_partitions),
  263. #endif
  264. },
  265. .ctrl = {
  266. .cmd_ctrl = bfin_plat_nand_cmd_ctrl,
  267. .dev_ready = bfin_plat_nand_dev_ready,
  268. },
  269. };
  270. #define MAX(x, y) (x > y ? x : y)
  271. static struct resource bfin_plat_nand_resources = {
  272. .start = 0x24000000,
  273. .end = 0x24000000 + (1 << MAX(BFIN_NAND_PLAT_CLE, BFIN_NAND_PLAT_ALE)),
  274. .flags = IORESOURCE_IO,
  275. };
  276. static struct platform_device bfin_async_nand_device = {
  277. .name = "gen_nand",
  278. .id = -1,
  279. .num_resources = 1,
  280. .resource = &bfin_plat_nand_resources,
  281. .dev = {
  282. .platform_data = &bfin_plat_nand_data,
  283. },
  284. };
  285. static void bfin_plat_nand_init(void)
  286. {
  287. gpio_request(BFIN_NAND_PLAT_READY, "bfin_nand_plat");
  288. }
  289. #else
  290. static void bfin_plat_nand_init(void)
  291. {
  292. }
  293. #endif
  294. #if defined(CONFIG_MTD_DATAFLASH) || defined(CONFIG_MTD_DATAFLASH_MODULE)
  295. static struct mtd_partition bfin_spi_dataflash_partitions[] = {
  296. {
  297. .name = "bootloader",
  298. .size = 0x4200,
  299. .offset = 0,
  300. .mask_flags = MTD_CAP_ROM},
  301. {
  302. .name = "u-boot",
  303. .size = 0x42000,
  304. .offset = MTDPART_OFS_APPEND,
  305. },
  306. {
  307. .name = "u-boot(params)",
  308. .size = 0x4200,
  309. .offset = MTDPART_OFS_APPEND,
  310. },
  311. {
  312. .name = "kernel",
  313. .size = 0x294000,
  314. .offset = MTDPART_OFS_APPEND,
  315. },
  316. {
  317. .name = "params",
  318. .size = 0x42000,
  319. .offset = MTDPART_OFS_APPEND,
  320. },
  321. {
  322. .name = "rootfs",
  323. .size = MTDPART_SIZ_FULL,
  324. .offset = MTDPART_OFS_APPEND,
  325. }
  326. };
  327. static struct flash_platform_data bfin_spi_dataflash_data = {
  328. .name = "SPI Dataflash",
  329. .parts = bfin_spi_dataflash_partitions,
  330. .nr_parts = ARRAY_SIZE(bfin_spi_dataflash_partitions),
  331. };
  332. /* DataFlash chip */
  333. static struct bfin5xx_spi_chip data_flash_chip_info = {
  334. .enable_dma = 0, /* use dma transfer with this chip */
  335. .bits_per_word = 8,
  336. };
  337. #endif
  338. #if defined(CONFIG_SPI_SPIDEV) || defined(CONFIG_SPI_SPIDEV_MODULE)
  339. static struct bfin5xx_spi_chip spidev_chip_info = {
  340. .enable_dma = 0,
  341. .bits_per_word = 8,
  342. };
  343. #endif
  344. #if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
  345. /* SPI (0) */
  346. static struct resource bfin_spi0_resource[] = {
  347. [0] = {
  348. .start = SPI0_REGBASE,
  349. .end = SPI0_REGBASE + 0xFF,
  350. .flags = IORESOURCE_MEM,
  351. },
  352. [1] = {
  353. .start = CH_SPI,
  354. .end = CH_SPI,
  355. .flags = IORESOURCE_DMA,
  356. },
  357. [2] = {
  358. .start = IRQ_SPI,
  359. .end = IRQ_SPI,
  360. .flags = IORESOURCE_IRQ,
  361. },
  362. };
  363. /* SPI controller data */
  364. static struct bfin5xx_spi_master bfin_spi0_info = {
  365. .num_chipselect = 8,
  366. .enable_dma = 1, /* master has the ability to do dma transfer */
  367. .pin_req = {P_SPI0_SCK, P_SPI0_MISO, P_SPI0_MOSI, 0},
  368. };
  369. static struct platform_device bfin_spi0_device = {
  370. .name = "bfin-spi",
  371. .id = 0, /* Bus number */
  372. .num_resources = ARRAY_SIZE(bfin_spi0_resource),
  373. .resource = bfin_spi0_resource,
  374. .dev = {
  375. .platform_data = &bfin_spi0_info, /* Passed to driver */
  376. },
  377. };
  378. #endif
  379. static struct spi_board_info bfin_spi_board_info[] __initdata = {
  380. #if defined(CONFIG_SPI_SPIDEV) || defined(CONFIG_SPI_SPIDEV_MODULE)
  381. {
  382. .modalias = "spidev",
  383. .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */
  384. .bus_num = 0,
  385. .chip_select = 3,
  386. .controller_data = &spidev_chip_info,
  387. },
  388. #endif
  389. #if defined(CONFIG_MTD_DATAFLASH) || defined(CONFIG_MTD_DATAFLASH_MODULE)
  390. { /* DataFlash chip */
  391. .modalias = "mtd_dataflash",
  392. .max_speed_hz = 33250000, /* max spi clock (SCK) speed in HZ */
  393. .bus_num = 0, /* Framework bus number */
  394. .chip_select = 2, /* Framework chip select */
  395. .platform_data = &bfin_spi_dataflash_data,
  396. .controller_data = &data_flash_chip_info,
  397. .mode = SPI_MODE_3,
  398. },
  399. #endif
  400. };
  401. static struct resource bfin_gpios_resources = {
  402. .start = 31,
  403. /* .end = MAX_BLACKFIN_GPIOS - 1, */
  404. .end = 32,
  405. .flags = IORESOURCE_IRQ,
  406. };
  407. static struct platform_device bfin_gpios_device = {
  408. .name = "simple-gpio",
  409. .id = -1,
  410. .num_resources = 1,
  411. .resource = &bfin_gpios_resources,
  412. };
  413. static const unsigned int cclk_vlev_datasheet[] = {
  414. VRPAIR(VLEV_085, 250000000),
  415. VRPAIR(VLEV_090, 300000000),
  416. VRPAIR(VLEV_095, 313000000),
  417. VRPAIR(VLEV_100, 350000000),
  418. VRPAIR(VLEV_105, 400000000),
  419. VRPAIR(VLEV_110, 444000000),
  420. VRPAIR(VLEV_115, 450000000),
  421. VRPAIR(VLEV_120, 475000000),
  422. VRPAIR(VLEV_125, 500000000),
  423. VRPAIR(VLEV_130, 600000000),
  424. };
  425. static struct bfin_dpmc_platform_data bfin_dmpc_vreg_data = {
  426. .tuple_tab = cclk_vlev_datasheet,
  427. .tabsize = ARRAY_SIZE(cclk_vlev_datasheet),
  428. .vr_settling_time = 25 /* us */ ,
  429. };
  430. static struct platform_device bfin_dpmc = {
  431. .name = "bfin dpmc",
  432. .dev = {
  433. .platform_data = &bfin_dmpc_vreg_data,
  434. },
  435. };
  436. static struct platform_device *acvilon_devices[] __initdata = {
  437. &bfin_dpmc,
  438. #if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
  439. &bfin_spi0_device,
  440. #endif
  441. #if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
  442. #ifdef CONFIG_SERIAL_BFIN_UART0
  443. &bfin_uart0_device,
  444. #endif
  445. #endif
  446. &bfin_gpios_device,
  447. #if defined(CONFIG_SMSC911X) || defined(CONFIG_SMSC911X_MODULE)
  448. &smsc911x_device,
  449. #endif
  450. &bfin_i2c_pca_device,
  451. #if defined(CONFIG_MTD_NAND_PLATFORM) || defined(CONFIG_MTD_NAND_PLATFORM_MODULE)
  452. &bfin_async_nand_device,
  453. #endif
  454. #if defined(CONFIG_MTD_PLATRAM) || defined(CONFIG_MTD_PLATRAM_MODULE)
  455. &mtd_ram_device,
  456. #endif
  457. };
  458. static int __init acvilon_init(void)
  459. {
  460. int ret;
  461. printk(KERN_INFO "%s(): registering device resources\n", __func__);
  462. bfin_plat_nand_init();
  463. ret =
  464. platform_add_devices(acvilon_devices, ARRAY_SIZE(acvilon_devices));
  465. if (ret < 0)
  466. return ret;
  467. i2c_register_board_info(0, acvilon_i2c_devs,
  468. ARRAY_SIZE(acvilon_i2c_devs));
  469. bfin_write_FIO0_FLAG_C(1 << 14);
  470. msleep(5);
  471. bfin_write_FIO0_FLAG_S(1 << 14);
  472. spi_register_board_info(bfin_spi_board_info,
  473. ARRAY_SIZE(bfin_spi_board_info));
  474. return 0;
  475. }
  476. arch_initcall(acvilon_init);
  477. static struct platform_device *acvilon_early_devices[] __initdata = {
  478. #if defined(CONFIG_SERIAL_BFIN_CONSOLE) || defined(CONFIG_EARLY_PRINTK)
  479. #ifdef CONFIG_SERIAL_BFIN_UART0
  480. &bfin_uart0_device,
  481. #endif
  482. #endif
  483. };
  484. void __init native_machine_early_platform_add_devices(void)
  485. {
  486. printk(KERN_INFO "register early platform devices\n");
  487. early_platform_add_devices(acvilon_early_devices,
  488. ARRAY_SIZE(acvilon_early_devices));
  489. }