acvilon.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  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. #ifdef CONFIG_MTD_PARTITIONS
  226. const char *part_probes[] = { "cmdlinepart", NULL };
  227. static struct mtd_partition bfin_plat_nand_partitions[] = {
  228. {
  229. .name = "params(nand)",
  230. .size = 32 * 1024 * 1024,
  231. .offset = 0,
  232. }, {
  233. .name = "userfs(nand)",
  234. .size = MTDPART_SIZ_FULL,
  235. .offset = MTDPART_OFS_APPEND,
  236. },
  237. };
  238. #endif
  239. #define BFIN_NAND_PLAT_CLE 2
  240. #define BFIN_NAND_PLAT_ALE 3
  241. static void bfin_plat_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
  242. unsigned int ctrl)
  243. {
  244. struct nand_chip *this = mtd->priv;
  245. if (cmd == NAND_CMD_NONE)
  246. return;
  247. if (ctrl & NAND_CLE)
  248. writeb(cmd, this->IO_ADDR_W + (1 << BFIN_NAND_PLAT_CLE));
  249. else
  250. writeb(cmd, this->IO_ADDR_W + (1 << BFIN_NAND_PLAT_ALE));
  251. }
  252. #define BFIN_NAND_PLAT_READY GPIO_PF10
  253. static int bfin_plat_nand_dev_ready(struct mtd_info *mtd)
  254. {
  255. return gpio_get_value(BFIN_NAND_PLAT_READY);
  256. }
  257. static struct platform_nand_data bfin_plat_nand_data = {
  258. .chip = {
  259. .nr_chips = 1,
  260. .chip_delay = 30,
  261. #ifdef CONFIG_MTD_PARTITIONS
  262. .part_probe_types = part_probes,
  263. .partitions = bfin_plat_nand_partitions,
  264. .nr_partitions = ARRAY_SIZE(bfin_plat_nand_partitions),
  265. #endif
  266. },
  267. .ctrl = {
  268. .cmd_ctrl = bfin_plat_nand_cmd_ctrl,
  269. .dev_ready = bfin_plat_nand_dev_ready,
  270. },
  271. };
  272. #define MAX(x, y) (x > y ? x : y)
  273. static struct resource bfin_plat_nand_resources = {
  274. .start = 0x24000000,
  275. .end = 0x24000000 + (1 << MAX(BFIN_NAND_PLAT_CLE, BFIN_NAND_PLAT_ALE)),
  276. .flags = IORESOURCE_MEM,
  277. };
  278. static struct platform_device bfin_async_nand_device = {
  279. .name = "gen_nand",
  280. .id = -1,
  281. .num_resources = 1,
  282. .resource = &bfin_plat_nand_resources,
  283. .dev = {
  284. .platform_data = &bfin_plat_nand_data,
  285. },
  286. };
  287. static void bfin_plat_nand_init(void)
  288. {
  289. gpio_request(BFIN_NAND_PLAT_READY, "bfin_nand_plat");
  290. }
  291. #else
  292. static void bfin_plat_nand_init(void)
  293. {
  294. }
  295. #endif
  296. #if defined(CONFIG_MTD_DATAFLASH) || defined(CONFIG_MTD_DATAFLASH_MODULE)
  297. static struct mtd_partition bfin_spi_dataflash_partitions[] = {
  298. {
  299. .name = "bootloader",
  300. .size = 0x4200,
  301. .offset = 0,
  302. .mask_flags = MTD_CAP_ROM},
  303. {
  304. .name = "u-boot",
  305. .size = 0x42000,
  306. .offset = MTDPART_OFS_APPEND,
  307. },
  308. {
  309. .name = "u-boot(params)",
  310. .size = 0x4200,
  311. .offset = MTDPART_OFS_APPEND,
  312. },
  313. {
  314. .name = "kernel",
  315. .size = 0x294000,
  316. .offset = MTDPART_OFS_APPEND,
  317. },
  318. {
  319. .name = "params",
  320. .size = 0x42000,
  321. .offset = MTDPART_OFS_APPEND,
  322. },
  323. {
  324. .name = "rootfs",
  325. .size = MTDPART_SIZ_FULL,
  326. .offset = MTDPART_OFS_APPEND,
  327. }
  328. };
  329. static struct flash_platform_data bfin_spi_dataflash_data = {
  330. .name = "SPI Dataflash",
  331. .parts = bfin_spi_dataflash_partitions,
  332. .nr_parts = ARRAY_SIZE(bfin_spi_dataflash_partitions),
  333. };
  334. /* DataFlash chip */
  335. static struct bfin5xx_spi_chip data_flash_chip_info = {
  336. .enable_dma = 0, /* use dma transfer with this chip */
  337. .bits_per_word = 8,
  338. };
  339. #endif
  340. #if defined(CONFIG_SPI_SPIDEV) || defined(CONFIG_SPI_SPIDEV_MODULE)
  341. static struct bfin5xx_spi_chip spidev_chip_info = {
  342. .enable_dma = 0,
  343. .bits_per_word = 8,
  344. };
  345. #endif
  346. #if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
  347. /* SPI (0) */
  348. static struct resource bfin_spi0_resource[] = {
  349. [0] = {
  350. .start = SPI0_REGBASE,
  351. .end = SPI0_REGBASE + 0xFF,
  352. .flags = IORESOURCE_MEM,
  353. },
  354. [1] = {
  355. .start = CH_SPI,
  356. .end = CH_SPI,
  357. .flags = IORESOURCE_DMA,
  358. },
  359. [2] = {
  360. .start = IRQ_SPI,
  361. .end = IRQ_SPI,
  362. .flags = IORESOURCE_IRQ,
  363. },
  364. };
  365. /* SPI controller data */
  366. static struct bfin5xx_spi_master bfin_spi0_info = {
  367. .num_chipselect = 8,
  368. .enable_dma = 1, /* master has the ability to do dma transfer */
  369. .pin_req = {P_SPI0_SCK, P_SPI0_MISO, P_SPI0_MOSI, 0},
  370. };
  371. static struct platform_device bfin_spi0_device = {
  372. .name = "bfin-spi",
  373. .id = 0, /* Bus number */
  374. .num_resources = ARRAY_SIZE(bfin_spi0_resource),
  375. .resource = bfin_spi0_resource,
  376. .dev = {
  377. .platform_data = &bfin_spi0_info, /* Passed to driver */
  378. },
  379. };
  380. #endif
  381. static struct spi_board_info bfin_spi_board_info[] __initdata = {
  382. #if defined(CONFIG_SPI_SPIDEV) || defined(CONFIG_SPI_SPIDEV_MODULE)
  383. {
  384. .modalias = "spidev",
  385. .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */
  386. .bus_num = 0,
  387. .chip_select = 3,
  388. .controller_data = &spidev_chip_info,
  389. },
  390. #endif
  391. #if defined(CONFIG_MTD_DATAFLASH) || defined(CONFIG_MTD_DATAFLASH_MODULE)
  392. { /* DataFlash chip */
  393. .modalias = "mtd_dataflash",
  394. .max_speed_hz = 33250000, /* max spi clock (SCK) speed in HZ */
  395. .bus_num = 0, /* Framework bus number */
  396. .chip_select = 2, /* Framework chip select */
  397. .platform_data = &bfin_spi_dataflash_data,
  398. .controller_data = &data_flash_chip_info,
  399. .mode = SPI_MODE_3,
  400. },
  401. #endif
  402. };
  403. static struct resource bfin_gpios_resources = {
  404. .start = 31,
  405. /* .end = MAX_BLACKFIN_GPIOS - 1, */
  406. .end = 32,
  407. .flags = IORESOURCE_IRQ,
  408. };
  409. static struct platform_device bfin_gpios_device = {
  410. .name = "simple-gpio",
  411. .id = -1,
  412. .num_resources = 1,
  413. .resource = &bfin_gpios_resources,
  414. };
  415. static const unsigned int cclk_vlev_datasheet[] = {
  416. VRPAIR(VLEV_085, 250000000),
  417. VRPAIR(VLEV_090, 300000000),
  418. VRPAIR(VLEV_095, 313000000),
  419. VRPAIR(VLEV_100, 350000000),
  420. VRPAIR(VLEV_105, 400000000),
  421. VRPAIR(VLEV_110, 444000000),
  422. VRPAIR(VLEV_115, 450000000),
  423. VRPAIR(VLEV_120, 475000000),
  424. VRPAIR(VLEV_125, 500000000),
  425. VRPAIR(VLEV_130, 600000000),
  426. };
  427. static struct bfin_dpmc_platform_data bfin_dmpc_vreg_data = {
  428. .tuple_tab = cclk_vlev_datasheet,
  429. .tabsize = ARRAY_SIZE(cclk_vlev_datasheet),
  430. .vr_settling_time = 25 /* us */ ,
  431. };
  432. static struct platform_device bfin_dpmc = {
  433. .name = "bfin dpmc",
  434. .dev = {
  435. .platform_data = &bfin_dmpc_vreg_data,
  436. },
  437. };
  438. static struct platform_device *acvilon_devices[] __initdata = {
  439. &bfin_dpmc,
  440. #if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
  441. &bfin_spi0_device,
  442. #endif
  443. #if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
  444. #ifdef CONFIG_SERIAL_BFIN_UART0
  445. &bfin_uart0_device,
  446. #endif
  447. #endif
  448. &bfin_gpios_device,
  449. #if defined(CONFIG_SMSC911X) || defined(CONFIG_SMSC911X_MODULE)
  450. &smsc911x_device,
  451. #endif
  452. &bfin_i2c_pca_device,
  453. #if defined(CONFIG_MTD_NAND_PLATFORM) || defined(CONFIG_MTD_NAND_PLATFORM_MODULE)
  454. &bfin_async_nand_device,
  455. #endif
  456. #if defined(CONFIG_MTD_PLATRAM) || defined(CONFIG_MTD_PLATRAM_MODULE)
  457. &mtd_ram_device,
  458. #endif
  459. };
  460. static int __init acvilon_init(void)
  461. {
  462. int ret;
  463. printk(KERN_INFO "%s(): registering device resources\n", __func__);
  464. bfin_plat_nand_init();
  465. ret =
  466. platform_add_devices(acvilon_devices, ARRAY_SIZE(acvilon_devices));
  467. if (ret < 0)
  468. return ret;
  469. i2c_register_board_info(0, acvilon_i2c_devs,
  470. ARRAY_SIZE(acvilon_i2c_devs));
  471. bfin_write_FIO0_FLAG_C(1 << 14);
  472. msleep(5);
  473. bfin_write_FIO0_FLAG_S(1 << 14);
  474. spi_register_board_info(bfin_spi_board_info,
  475. ARRAY_SIZE(bfin_spi_board_info));
  476. return 0;
  477. }
  478. arch_initcall(acvilon_init);
  479. static struct platform_device *acvilon_early_devices[] __initdata = {
  480. #if defined(CONFIG_SERIAL_BFIN_CONSOLE) || defined(CONFIG_EARLY_PRINTK)
  481. #ifdef CONFIG_SERIAL_BFIN_UART0
  482. &bfin_uart0_device,
  483. #endif
  484. #endif
  485. };
  486. void __init native_machine_early_platform_add_devices(void)
  487. {
  488. printk(KERN_INFO "register early platform devices\n");
  489. early_platform_add_devices(acvilon_early_devices,
  490. ARRAY_SIZE(acvilon_early_devices));
  491. }