dnp5370.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. /*
  2. * This is the configuration for SSV Dil/NetPC DNP/5370 board.
  3. *
  4. * DIL module: http://www.dilnetpc.com/dnp0086.htm
  5. * SK28 (starter kit): http://www.dilnetpc.com/dnp0088.htm
  6. *
  7. * Copyright 2010 3ality Digital Systems
  8. * Copyright 2005 National ICT Australia (NICTA)
  9. * Copyright 2004-2006 Analog Devices Inc.
  10. *
  11. * Licensed under the GPL-2 or later.
  12. */
  13. #include <linux/device.h>
  14. #include <linux/export.h>
  15. #include <linux/kernel.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/io.h>
  18. #include <linux/mtd/mtd.h>
  19. #include <linux/mtd/nand.h>
  20. #include <linux/mtd/partitions.h>
  21. #include <linux/mtd/plat-ram.h>
  22. #include <linux/mtd/physmap.h>
  23. #include <linux/spi/spi.h>
  24. #include <linux/spi/flash.h>
  25. #include <linux/irq.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/i2c.h>
  28. #include <linux/spi/mmc_spi.h>
  29. #include <linux/phy.h>
  30. #include <asm/dma.h>
  31. #include <asm/bfin5xx_spi.h>
  32. #include <asm/reboot.h>
  33. #include <asm/portmux.h>
  34. #include <asm/dpmc.h>
  35. /*
  36. * Name the Board for the /proc/cpuinfo
  37. */
  38. const char bfin_board_name[] = "DNP/5370";
  39. #define FLASH_MAC 0x202f0000
  40. #define CONFIG_MTD_PHYSMAP_LEN 0x300000
  41. #if IS_ENABLED(CONFIG_RTC_DRV_BFIN)
  42. static struct platform_device rtc_device = {
  43. .name = "rtc-bfin",
  44. .id = -1,
  45. };
  46. #endif
  47. #if IS_ENABLED(CONFIG_BFIN_MAC)
  48. #include <linux/bfin_mac.h>
  49. static const unsigned short bfin_mac_peripherals[] = P_RMII0;
  50. static struct bfin_phydev_platform_data bfin_phydev_data[] = {
  51. {
  52. .addr = 1,
  53. .irq = PHY_POLL, /* IRQ_MAC_PHYINT */
  54. },
  55. };
  56. static struct bfin_mii_bus_platform_data bfin_mii_bus_data = {
  57. .phydev_number = 1,
  58. .phydev_data = bfin_phydev_data,
  59. .phy_mode = PHY_INTERFACE_MODE_RMII,
  60. .mac_peripherals = bfin_mac_peripherals,
  61. };
  62. static struct platform_device bfin_mii_bus = {
  63. .name = "bfin_mii_bus",
  64. .dev = {
  65. .platform_data = &bfin_mii_bus_data,
  66. }
  67. };
  68. static struct platform_device bfin_mac_device = {
  69. .name = "bfin_mac",
  70. .dev = {
  71. .platform_data = &bfin_mii_bus,
  72. }
  73. };
  74. #endif
  75. #if IS_ENABLED(CONFIG_MTD_PHYSMAP)
  76. static struct mtd_partition asmb_flash_partitions[] = {
  77. {
  78. .name = "bootloader(nor)",
  79. .size = 0x30000,
  80. .offset = 0,
  81. }, {
  82. .name = "linux kernel and rootfs(nor)",
  83. .size = 0x300000 - 0x30000 - 0x10000,
  84. .offset = MTDPART_OFS_APPEND,
  85. }, {
  86. .name = "MAC address(nor)",
  87. .size = 0x10000,
  88. .offset = MTDPART_OFS_APPEND,
  89. .mask_flags = MTD_WRITEABLE,
  90. }
  91. };
  92. static struct physmap_flash_data asmb_flash_data = {
  93. .width = 1,
  94. .parts = asmb_flash_partitions,
  95. .nr_parts = ARRAY_SIZE(asmb_flash_partitions),
  96. };
  97. static struct resource asmb_flash_resource = {
  98. .start = 0x20000000,
  99. .end = 0x202fffff,
  100. .flags = IORESOURCE_MEM,
  101. };
  102. /* 4 MB NOR flash attached to async memory banks 0-2,
  103. * therefore only 3 MB visible.
  104. */
  105. static struct platform_device asmb_flash_device = {
  106. .name = "physmap-flash",
  107. .id = 0,
  108. .dev = {
  109. .platform_data = &asmb_flash_data,
  110. },
  111. .num_resources = 1,
  112. .resource = &asmb_flash_resource,
  113. };
  114. #endif
  115. #if IS_ENABLED(CONFIG_SPI_BFIN5XX)
  116. #if IS_ENABLED(CONFIG_MMC_SPI)
  117. static struct bfin5xx_spi_chip mmc_spi_chip_info = {
  118. .enable_dma = 0, /* use no dma transfer with this chip*/
  119. };
  120. #endif
  121. #if IS_ENABLED(CONFIG_MTD_DATAFLASH)
  122. /* This mapping is for at45db642 it has 1056 page size,
  123. * partition size and offset should be page aligned
  124. */
  125. static struct mtd_partition bfin_spi_dataflash_partitions[] = {
  126. {
  127. .name = "JFFS2 dataflash(nor)",
  128. #ifdef CONFIG_MTD_PAGESIZE_1024
  129. .offset = 0x40000,
  130. .size = 0x7C0000,
  131. #else
  132. .offset = 0x0,
  133. .size = 0x840000,
  134. #endif
  135. }
  136. };
  137. static struct flash_platform_data bfin_spi_dataflash_data = {
  138. .name = "mtd_dataflash",
  139. .parts = bfin_spi_dataflash_partitions,
  140. .nr_parts = ARRAY_SIZE(bfin_spi_dataflash_partitions),
  141. .type = "mtd_dataflash",
  142. };
  143. static struct bfin5xx_spi_chip spi_dataflash_chip_info = {
  144. .enable_dma = 0, /* use no dma transfer with this chip*/
  145. };
  146. #endif
  147. static struct spi_board_info bfin_spi_board_info[] __initdata = {
  148. /* SD/MMC card reader at SPI bus */
  149. #if IS_ENABLED(CONFIG_MMC_SPI)
  150. {
  151. .modalias = "mmc_spi",
  152. .max_speed_hz = 20000000,
  153. .bus_num = 0,
  154. .chip_select = 1,
  155. .controller_data = &mmc_spi_chip_info,
  156. .mode = SPI_MODE_3,
  157. },
  158. #endif
  159. /* 8 Megabyte Atmel NOR flash chip at SPI bus */
  160. #if IS_ENABLED(CONFIG_MTD_DATAFLASH)
  161. {
  162. .modalias = "mtd_dataflash",
  163. .max_speed_hz = 16700000,
  164. .bus_num = 0,
  165. .chip_select = 2,
  166. .platform_data = &bfin_spi_dataflash_data,
  167. .controller_data = &spi_dataflash_chip_info,
  168. .mode = SPI_MODE_3, /* SPI_CPHA and SPI_CPOL */
  169. },
  170. #endif
  171. };
  172. /* SPI controller data */
  173. /* SPI (0) */
  174. static struct resource bfin_spi0_resource[] = {
  175. [0] = {
  176. .start = SPI0_REGBASE,
  177. .end = SPI0_REGBASE + 0xFF,
  178. .flags = IORESOURCE_MEM,
  179. },
  180. [1] = {
  181. .start = CH_SPI,
  182. .end = CH_SPI,
  183. .flags = IORESOURCE_DMA,
  184. },
  185. [2] = {
  186. .start = IRQ_SPI,
  187. .end = IRQ_SPI,
  188. .flags = IORESOURCE_IRQ,
  189. },
  190. };
  191. static struct bfin5xx_spi_master spi_bfin_master_info = {
  192. .num_chipselect = 8,
  193. .enable_dma = 1, /* master has the ability to do dma transfer */
  194. .pin_req = {P_SPI0_SCK, P_SPI0_MISO, P_SPI0_MOSI, 0},
  195. };
  196. static struct platform_device spi_bfin_master_device = {
  197. .name = "bfin-spi",
  198. .id = 0, /* Bus number */
  199. .num_resources = ARRAY_SIZE(bfin_spi0_resource),
  200. .resource = bfin_spi0_resource,
  201. .dev = {
  202. .platform_data = &spi_bfin_master_info, /* Passed to driver */
  203. },
  204. };
  205. #endif
  206. #if IS_ENABLED(CONFIG_SERIAL_BFIN)
  207. #ifdef CONFIG_SERIAL_BFIN_UART0
  208. static struct resource bfin_uart0_resources[] = {
  209. {
  210. .start = UART0_THR,
  211. .end = UART0_GCTL+2,
  212. .flags = IORESOURCE_MEM,
  213. },
  214. {
  215. .start = IRQ_UART0_TX,
  216. .end = IRQ_UART0_TX,
  217. .flags = IORESOURCE_IRQ,
  218. },
  219. {
  220. .start = IRQ_UART0_RX,
  221. .end = IRQ_UART0_RX,
  222. .flags = IORESOURCE_IRQ,
  223. },
  224. {
  225. .start = IRQ_UART0_ERROR,
  226. .end = IRQ_UART0_ERROR,
  227. .flags = IORESOURCE_IRQ,
  228. },
  229. {
  230. .start = CH_UART0_TX,
  231. .end = CH_UART0_TX,
  232. .flags = IORESOURCE_DMA,
  233. },
  234. {
  235. .start = CH_UART0_RX,
  236. .end = CH_UART0_RX,
  237. .flags = IORESOURCE_DMA,
  238. },
  239. };
  240. static unsigned short bfin_uart0_peripherals[] = {
  241. P_UART0_TX, P_UART0_RX, 0
  242. };
  243. static struct platform_device bfin_uart0_device = {
  244. .name = "bfin-uart",
  245. .id = 0,
  246. .num_resources = ARRAY_SIZE(bfin_uart0_resources),
  247. .resource = bfin_uart0_resources,
  248. .dev = {
  249. .platform_data = &bfin_uart0_peripherals, /* Passed to driver */
  250. },
  251. };
  252. #endif
  253. #ifdef CONFIG_SERIAL_BFIN_UART1
  254. static struct resource bfin_uart1_resources[] = {
  255. {
  256. .start = UART1_THR,
  257. .end = UART1_GCTL+2,
  258. .flags = IORESOURCE_MEM,
  259. },
  260. {
  261. .start = IRQ_UART1_TX,
  262. .end = IRQ_UART1_TX,
  263. .flags = IORESOURCE_IRQ,
  264. },
  265. {
  266. .start = IRQ_UART1_RX,
  267. .end = IRQ_UART1_RX,
  268. .flags = IORESOURCE_IRQ,
  269. },
  270. {
  271. .start = IRQ_UART1_ERROR,
  272. .end = IRQ_UART1_ERROR,
  273. .flags = IORESOURCE_IRQ,
  274. },
  275. {
  276. .start = CH_UART1_TX,
  277. .end = CH_UART1_TX,
  278. .flags = IORESOURCE_DMA,
  279. },
  280. {
  281. .start = CH_UART1_RX,
  282. .end = CH_UART1_RX,
  283. .flags = IORESOURCE_DMA,
  284. },
  285. };
  286. static unsigned short bfin_uart1_peripherals[] = {
  287. P_UART1_TX, P_UART1_RX, 0
  288. };
  289. static struct platform_device bfin_uart1_device = {
  290. .name = "bfin-uart",
  291. .id = 1,
  292. .num_resources = ARRAY_SIZE(bfin_uart1_resources),
  293. .resource = bfin_uart1_resources,
  294. .dev = {
  295. .platform_data = &bfin_uart1_peripherals, /* Passed to driver */
  296. },
  297. };
  298. #endif
  299. #endif
  300. #if IS_ENABLED(CONFIG_I2C_BLACKFIN_TWI)
  301. static const u16 bfin_twi0_pins[] = {P_TWI0_SCL, P_TWI0_SDA, 0};
  302. static struct resource bfin_twi0_resource[] = {
  303. [0] = {
  304. .start = TWI0_REGBASE,
  305. .end = TWI0_REGBASE + 0xff,
  306. .flags = IORESOURCE_MEM,
  307. },
  308. [1] = {
  309. .start = IRQ_TWI,
  310. .end = IRQ_TWI,
  311. .flags = IORESOURCE_IRQ,
  312. },
  313. };
  314. static struct platform_device i2c_bfin_twi_device = {
  315. .name = "i2c-bfin-twi",
  316. .id = 0,
  317. .num_resources = ARRAY_SIZE(bfin_twi0_resource),
  318. .resource = bfin_twi0_resource,
  319. .dev = {
  320. .platform_data = &bfin_twi0_pins,
  321. },
  322. };
  323. #endif
  324. static struct platform_device *dnp5370_devices[] __initdata = {
  325. #if IS_ENABLED(CONFIG_SERIAL_BFIN)
  326. #ifdef CONFIG_SERIAL_BFIN_UART0
  327. &bfin_uart0_device,
  328. #endif
  329. #ifdef CONFIG_SERIAL_BFIN_UART1
  330. &bfin_uart1_device,
  331. #endif
  332. #endif
  333. #if IS_ENABLED(CONFIG_MTD_PHYSMAP)
  334. &asmb_flash_device,
  335. #endif
  336. #if IS_ENABLED(CONFIG_BFIN_MAC)
  337. &bfin_mii_bus,
  338. &bfin_mac_device,
  339. #endif
  340. #if IS_ENABLED(CONFIG_SPI_BFIN5XX)
  341. &spi_bfin_master_device,
  342. #endif
  343. #if IS_ENABLED(CONFIG_I2C_BLACKFIN_TWI)
  344. &i2c_bfin_twi_device,
  345. #endif
  346. #if IS_ENABLED(CONFIG_RTC_DRV_BFIN)
  347. &rtc_device,
  348. #endif
  349. };
  350. static int __init dnp5370_init(void)
  351. {
  352. printk(KERN_INFO "DNP/5370: registering device resources\n");
  353. platform_add_devices(dnp5370_devices, ARRAY_SIZE(dnp5370_devices));
  354. printk(KERN_INFO "DNP/5370: registering %zu SPI slave devices\n",
  355. ARRAY_SIZE(bfin_spi_board_info));
  356. spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info));
  357. printk(KERN_INFO "DNP/5370: MAC %pM\n", (void *)FLASH_MAC);
  358. return 0;
  359. }
  360. arch_initcall(dnp5370_init);
  361. /*
  362. * Currently the MAC address is saved in Flash by U-Boot
  363. */
  364. int bfin_get_ether_addr(char *addr)
  365. {
  366. *(u32 *)(&(addr[0])) = bfin_read32(FLASH_MAC);
  367. *(u16 *)(&(addr[4])) = bfin_read16(FLASH_MAC + 4);
  368. return 0;
  369. }
  370. EXPORT_SYMBOL(bfin_get_ether_addr);