acvilon.c 12 KB

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