acvilon.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  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/jiffies.h>
  47. #include <linux/i2c-pca-platform.h>
  48. #include <linux/delay.h>
  49. #include <linux/io.h>
  50. #include <asm/dma.h>
  51. #include <asm/bfin5xx_spi.h>
  52. #include <asm/portmux.h>
  53. #include <asm/dpmc.h>
  54. #include <asm/cacheflush.h>
  55. #include <linux/i2c.h>
  56. /*
  57. * Name the Board for the /proc/cpuinfo
  58. */
  59. const char bfin_board_name[] = "Acvilon board";
  60. #if defined(CONFIG_USB_ISP1760_HCD) || defined(CONFIG_USB_ISP1760_HCD_MODULE)
  61. #include <linux/usb/isp1760.h>
  62. static struct resource bfin_isp1760_resources[] = {
  63. [0] = {
  64. .start = 0x20000000,
  65. .end = 0x20000000 + 0x000fffff,
  66. .flags = IORESOURCE_MEM,
  67. },
  68. [1] = {
  69. .start = IRQ_PF15,
  70. .end = IRQ_PF15,
  71. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
  72. },
  73. };
  74. static struct isp1760_platform_data isp1760_priv = {
  75. .is_isp1761 = 0,
  76. .port1_disable = 0,
  77. .bus_width_16 = 1,
  78. .port1_otg = 0,
  79. .analog_oc = 0,
  80. .dack_polarity_high = 0,
  81. .dreq_polarity_high = 0,
  82. };
  83. static struct platform_device bfin_isp1760_device = {
  84. .name = "isp1760-hcd",
  85. .id = 0,
  86. .dev = {
  87. .platform_data = &isp1760_priv,
  88. },
  89. .num_resources = ARRAY_SIZE(bfin_isp1760_resources),
  90. .resource = bfin_isp1760_resources,
  91. };
  92. #endif
  93. static struct resource bfin_i2c_pca_resources[] = {
  94. {
  95. .name = "pca9564-regs",
  96. .start = 0x2C000000,
  97. .end = 0x2C000000 + 16,
  98. .flags = IORESOURCE_MEM | IORESOURCE_MEM_32BIT,
  99. }, {
  100. .start = IRQ_PF8,
  101. .end = IRQ_PF8,
  102. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
  103. },
  104. };
  105. struct i2c_pca9564_pf_platform_data pca9564_platform_data = {
  106. .gpio = -1,
  107. .i2c_clock_speed = 330000,
  108. .timeout = HZ,
  109. };
  110. /* PCA9564 I2C Bus driver */
  111. static struct platform_device bfin_i2c_pca_device = {
  112. .name = "i2c-pca-platform",
  113. .id = 0,
  114. .num_resources = ARRAY_SIZE(bfin_i2c_pca_resources),
  115. .resource = bfin_i2c_pca_resources,
  116. .dev = {
  117. .platform_data = &pca9564_platform_data,
  118. }
  119. };
  120. /* I2C devices fitted. */
  121. static struct i2c_board_info acvilon_i2c_devs[] __initdata = {
  122. {
  123. I2C_BOARD_INFO("ds1339", 0x68),
  124. },
  125. {
  126. I2C_BOARD_INFO("tcn75", 0x49),
  127. },
  128. };
  129. #if defined(CONFIG_MTD_PLATRAM) || defined(CONFIG_MTD_PLATRAM_MODULE)
  130. static struct platdata_mtd_ram mtd_ram_data = {
  131. .mapname = "rootfs(RAM)",
  132. .bankwidth = 4,
  133. };
  134. static struct resource mtd_ram_resource = {
  135. .start = 0x4000000,
  136. .end = 0x5ffffff,
  137. .flags = IORESOURCE_MEM,
  138. };
  139. static struct platform_device mtd_ram_device = {
  140. .name = "mtd-ram",
  141. .id = 0,
  142. .dev = {
  143. .platform_data = &mtd_ram_data,
  144. },
  145. .num_resources = 1,
  146. .resource = &mtd_ram_resource,
  147. };
  148. #endif
  149. #if defined(CONFIG_SMSC911X) || defined(CONFIG_SMSC911X_MODULE)
  150. #include <linux/smsc911x.h>
  151. static struct resource smsc911x_resources[] = {
  152. {
  153. .name = "smsc911x-memory",
  154. .start = 0x28000000,
  155. .end = 0x28000000 + 0xFF,
  156. .flags = IORESOURCE_MEM,
  157. },
  158. {
  159. .start = IRQ_PF7,
  160. .end = IRQ_PF7,
  161. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
  162. },
  163. };
  164. static struct smsc911x_platform_config smsc911x_config = {
  165. .flags = SMSC911X_USE_32BIT | SMSC911X_SAVE_MAC_ADDRESS,
  166. .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
  167. .irq_type = SMSC911X_IRQ_TYPE_OPEN_DRAIN,
  168. .phy_interface = PHY_INTERFACE_MODE_MII,
  169. };
  170. static struct platform_device smsc911x_device = {
  171. .name = "smsc911x",
  172. .id = 0,
  173. .num_resources = ARRAY_SIZE(smsc911x_resources),
  174. .resource = smsc911x_resources,
  175. .dev = {
  176. .platform_data = &smsc911x_config,
  177. },
  178. };
  179. #endif
  180. #if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
  181. #ifdef CONFIG_SERIAL_BFIN_UART0
  182. static struct resource bfin_uart0_resources[] = {
  183. {
  184. .start = BFIN_UART_THR,
  185. .end = BFIN_UART_GCTL + 2,
  186. .flags = IORESOURCE_MEM,
  187. },
  188. {
  189. .start = IRQ_UART_RX,
  190. .end = IRQ_UART_RX + 1,
  191. .flags = IORESOURCE_IRQ,
  192. },
  193. {
  194. .start = IRQ_UART_ERROR,
  195. .end = IRQ_UART_ERROR,
  196. .flags = IORESOURCE_IRQ,
  197. },
  198. {
  199. .start = CH_UART_TX,
  200. .end = CH_UART_TX,
  201. .flags = IORESOURCE_DMA,
  202. },
  203. {
  204. .start = CH_UART_RX,
  205. .end = CH_UART_RX,
  206. .flags = IORESOURCE_DMA,
  207. },
  208. };
  209. static unsigned short bfin_uart0_peripherals[] = {
  210. P_UART0_TX, P_UART0_RX, 0
  211. };
  212. static struct platform_device bfin_uart0_device = {
  213. .name = "bfin-uart",
  214. .id = 0,
  215. .num_resources = ARRAY_SIZE(bfin_uart0_resources),
  216. .resource = bfin_uart0_resources,
  217. .dev = {
  218. /* Passed to driver */
  219. .platform_data = &bfin_uart0_peripherals,
  220. },
  221. };
  222. #endif
  223. #endif
  224. #if defined(CONFIG_MTD_NAND_PLATFORM) || defined(CONFIG_MTD_NAND_PLATFORM_MODULE)
  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. #define BFIN_NAND_PLAT_CLE 2
  238. #define BFIN_NAND_PLAT_ALE 3
  239. static void bfin_plat_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
  240. unsigned int ctrl)
  241. {
  242. struct nand_chip *this = mtd->priv;
  243. if (cmd == NAND_CMD_NONE)
  244. return;
  245. if (ctrl & NAND_CLE)
  246. writeb(cmd, this->IO_ADDR_W + (1 << BFIN_NAND_PLAT_CLE));
  247. else
  248. writeb(cmd, this->IO_ADDR_W + (1 << BFIN_NAND_PLAT_ALE));
  249. }
  250. #define BFIN_NAND_PLAT_READY GPIO_PF10
  251. static int bfin_plat_nand_dev_ready(struct mtd_info *mtd)
  252. {
  253. return gpio_get_value(BFIN_NAND_PLAT_READY);
  254. }
  255. static struct platform_nand_data bfin_plat_nand_data = {
  256. .chip = {
  257. .nr_chips = 1,
  258. .chip_delay = 30,
  259. .part_probe_types = part_probes,
  260. .partitions = bfin_plat_nand_partitions,
  261. .nr_partitions = ARRAY_SIZE(bfin_plat_nand_partitions),
  262. },
  263. .ctrl = {
  264. .cmd_ctrl = bfin_plat_nand_cmd_ctrl,
  265. .dev_ready = bfin_plat_nand_dev_ready,
  266. },
  267. };
  268. #define MAX(x, y) (x > y ? x : y)
  269. static struct resource bfin_plat_nand_resources = {
  270. .start = 0x24000000,
  271. .end = 0x24000000 + (1 << MAX(BFIN_NAND_PLAT_CLE, BFIN_NAND_PLAT_ALE)),
  272. .flags = IORESOURCE_MEM,
  273. };
  274. static struct platform_device bfin_async_nand_device = {
  275. .name = "gen_nand",
  276. .id = -1,
  277. .num_resources = 1,
  278. .resource = &bfin_plat_nand_resources,
  279. .dev = {
  280. .platform_data = &bfin_plat_nand_data,
  281. },
  282. };
  283. static void bfin_plat_nand_init(void)
  284. {
  285. gpio_request(BFIN_NAND_PLAT_READY, "bfin_nand_plat");
  286. }
  287. #else
  288. static void bfin_plat_nand_init(void)
  289. {
  290. }
  291. #endif
  292. #if defined(CONFIG_MTD_DATAFLASH) || defined(CONFIG_MTD_DATAFLASH_MODULE)
  293. static struct mtd_partition bfin_spi_dataflash_partitions[] = {
  294. {
  295. .name = "bootloader",
  296. .size = 0x4200,
  297. .offset = 0,
  298. .mask_flags = MTD_CAP_ROM},
  299. {
  300. .name = "u-boot",
  301. .size = 0x42000,
  302. .offset = MTDPART_OFS_APPEND,
  303. },
  304. {
  305. .name = "u-boot(params)",
  306. .size = 0x4200,
  307. .offset = MTDPART_OFS_APPEND,
  308. },
  309. {
  310. .name = "kernel",
  311. .size = 0x294000,
  312. .offset = MTDPART_OFS_APPEND,
  313. },
  314. {
  315. .name = "params",
  316. .size = 0x42000,
  317. .offset = MTDPART_OFS_APPEND,
  318. },
  319. {
  320. .name = "rootfs",
  321. .size = MTDPART_SIZ_FULL,
  322. .offset = MTDPART_OFS_APPEND,
  323. }
  324. };
  325. static struct flash_platform_data bfin_spi_dataflash_data = {
  326. .name = "SPI Dataflash",
  327. .parts = bfin_spi_dataflash_partitions,
  328. .nr_parts = ARRAY_SIZE(bfin_spi_dataflash_partitions),
  329. };
  330. /* DataFlash chip */
  331. static struct bfin5xx_spi_chip data_flash_chip_info = {
  332. .enable_dma = 0, /* use dma transfer with this chip */
  333. .bits_per_word = 8,
  334. };
  335. #endif
  336. #if defined(CONFIG_SPI_SPIDEV) || defined(CONFIG_SPI_SPIDEV_MODULE)
  337. static struct bfin5xx_spi_chip spidev_chip_info = {
  338. .enable_dma = 0,
  339. .bits_per_word = 8,
  340. };
  341. #endif
  342. #if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
  343. /* SPI (0) */
  344. static struct resource bfin_spi0_resource[] = {
  345. [0] = {
  346. .start = SPI0_REGBASE,
  347. .end = SPI0_REGBASE + 0xFF,
  348. .flags = IORESOURCE_MEM,
  349. },
  350. [1] = {
  351. .start = CH_SPI,
  352. .end = CH_SPI,
  353. .flags = IORESOURCE_DMA,
  354. },
  355. [2] = {
  356. .start = IRQ_SPI,
  357. .end = IRQ_SPI,
  358. .flags = IORESOURCE_IRQ,
  359. },
  360. };
  361. /* SPI controller data */
  362. static struct bfin5xx_spi_master bfin_spi0_info = {
  363. .num_chipselect = 8,
  364. .enable_dma = 1, /* master has the ability to do dma transfer */
  365. .pin_req = {P_SPI0_SCK, P_SPI0_MISO, P_SPI0_MOSI, 0},
  366. };
  367. static struct platform_device bfin_spi0_device = {
  368. .name = "bfin-spi",
  369. .id = 0, /* Bus number */
  370. .num_resources = ARRAY_SIZE(bfin_spi0_resource),
  371. .resource = bfin_spi0_resource,
  372. .dev = {
  373. .platform_data = &bfin_spi0_info, /* Passed to driver */
  374. },
  375. };
  376. #endif
  377. static struct spi_board_info bfin_spi_board_info[] __initdata = {
  378. #if defined(CONFIG_SPI_SPIDEV) || defined(CONFIG_SPI_SPIDEV_MODULE)
  379. {
  380. .modalias = "spidev",
  381. .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */
  382. .bus_num = 0,
  383. .chip_select = 3,
  384. .controller_data = &spidev_chip_info,
  385. },
  386. #endif
  387. #if defined(CONFIG_MTD_DATAFLASH) || defined(CONFIG_MTD_DATAFLASH_MODULE)
  388. { /* DataFlash chip */
  389. .modalias = "mtd_dataflash",
  390. .max_speed_hz = 33250000, /* max spi clock (SCK) speed in HZ */
  391. .bus_num = 0, /* Framework bus number */
  392. .chip_select = 2, /* Framework chip select */
  393. .platform_data = &bfin_spi_dataflash_data,
  394. .controller_data = &data_flash_chip_info,
  395. .mode = SPI_MODE_3,
  396. },
  397. #endif
  398. };
  399. static struct resource bfin_gpios_resources = {
  400. .start = 31,
  401. /* .end = MAX_BLACKFIN_GPIOS - 1, */
  402. .end = 32,
  403. .flags = IORESOURCE_IRQ,
  404. };
  405. static struct platform_device bfin_gpios_device = {
  406. .name = "simple-gpio",
  407. .id = -1,
  408. .num_resources = 1,
  409. .resource = &bfin_gpios_resources,
  410. };
  411. static const unsigned int cclk_vlev_datasheet[] = {
  412. VRPAIR(VLEV_085, 250000000),
  413. VRPAIR(VLEV_090, 300000000),
  414. VRPAIR(VLEV_095, 313000000),
  415. VRPAIR(VLEV_100, 350000000),
  416. VRPAIR(VLEV_105, 400000000),
  417. VRPAIR(VLEV_110, 444000000),
  418. VRPAIR(VLEV_115, 450000000),
  419. VRPAIR(VLEV_120, 475000000),
  420. VRPAIR(VLEV_125, 500000000),
  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 *acvilon_devices[] __initdata = {
  435. &bfin_dpmc,
  436. #if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
  437. &bfin_spi0_device,
  438. #endif
  439. #if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
  440. #ifdef CONFIG_SERIAL_BFIN_UART0
  441. &bfin_uart0_device,
  442. #endif
  443. #endif
  444. &bfin_gpios_device,
  445. #if defined(CONFIG_SMSC911X) || defined(CONFIG_SMSC911X_MODULE)
  446. &smsc911x_device,
  447. #endif
  448. &bfin_i2c_pca_device,
  449. #if defined(CONFIG_MTD_NAND_PLATFORM) || defined(CONFIG_MTD_NAND_PLATFORM_MODULE)
  450. &bfin_async_nand_device,
  451. #endif
  452. #if defined(CONFIG_MTD_PLATRAM) || defined(CONFIG_MTD_PLATRAM_MODULE)
  453. &mtd_ram_device,
  454. #endif
  455. };
  456. static int __init acvilon_init(void)
  457. {
  458. int ret;
  459. printk(KERN_INFO "%s(): registering device resources\n", __func__);
  460. bfin_plat_nand_init();
  461. ret =
  462. platform_add_devices(acvilon_devices, ARRAY_SIZE(acvilon_devices));
  463. if (ret < 0)
  464. return ret;
  465. i2c_register_board_info(0, acvilon_i2c_devs,
  466. ARRAY_SIZE(acvilon_i2c_devs));
  467. bfin_write_FIO0_FLAG_C(1 << 14);
  468. msleep(5);
  469. bfin_write_FIO0_FLAG_S(1 << 14);
  470. spi_register_board_info(bfin_spi_board_info,
  471. ARRAY_SIZE(bfin_spi_board_info));
  472. return 0;
  473. }
  474. arch_initcall(acvilon_init);
  475. static struct platform_device *acvilon_early_devices[] __initdata = {
  476. #if defined(CONFIG_SERIAL_BFIN_CONSOLE) || defined(CONFIG_EARLY_PRINTK)
  477. #ifdef CONFIG_SERIAL_BFIN_UART0
  478. &bfin_uart0_device,
  479. #endif
  480. #endif
  481. };
  482. void __init native_machine_early_platform_add_devices(void)
  483. {
  484. printk(KERN_INFO "register early platform devices\n");
  485. early_platform_add_devices(acvilon_early_devices,
  486. ARRAY_SIZE(acvilon_early_devices));
  487. }