dnp5370.c 9.9 KB

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