excite_device.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. /*
  2. * Copyright (C) 2004 by Basler Vision Technologies AG
  3. * Author: Thomas Koeller <thomas.koeller@baslerweb.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #include <linux/kernel.h>
  20. #include <linux/init.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/ioport.h>
  23. #include <linux/err.h>
  24. #include <linux/jiffies.h>
  25. #include <linux/sched.h>
  26. #include <asm/types.h>
  27. #include <asm/rm9k-ocd.h>
  28. #include <excite.h>
  29. #include <rm9k_eth.h>
  30. #include <rm9k_wdt.h>
  31. #include <rm9k_xicap.h>
  32. #include <excite_nandflash.h>
  33. #include "excite_iodev.h"
  34. #define RM9K_GE_UNIT 0
  35. #define XICAP_UNIT 0
  36. #define NAND_UNIT 0
  37. #define DLL_TIMEOUT 3 /* seconds */
  38. #define RINIT(__start__, __end__, __name__, __parent__) { \
  39. .name = __name__ "_0", \
  40. .start = (__start__), \
  41. .end = (__end__), \
  42. .flags = 0, \
  43. .parent = (__parent__) \
  44. }
  45. #define RINIT_IRQ(__irq__, __name__) { \
  46. .name = __name__ "_0", \
  47. .start = (__irq__), \
  48. .end = (__irq__), \
  49. .flags = IORESOURCE_IRQ, \
  50. .parent = NULL \
  51. }
  52. enum {
  53. slice_xicap,
  54. slice_eth
  55. };
  56. static struct resource
  57. excite_ctr_resource __attribute__((unused)) = {
  58. .name = "GPI counters",
  59. .start = 0,
  60. .end = 5,
  61. .flags = 0,
  62. .parent = NULL,
  63. .sibling = NULL,
  64. .child = NULL
  65. },
  66. excite_gpislice_resource __attribute__((unused)) = {
  67. .name = "GPI slices",
  68. .start = 0,
  69. .end = 1,
  70. .flags = 0,
  71. .parent = NULL,
  72. .sibling = NULL,
  73. .child = NULL
  74. },
  75. excite_mdio_channel_resource __attribute__((unused)) = {
  76. .name = "MDIO channels",
  77. .start = 0,
  78. .end = 1,
  79. .flags = 0,
  80. .parent = NULL,
  81. .sibling = NULL,
  82. .child = NULL
  83. },
  84. excite_fifomem_resource __attribute__((unused)) = {
  85. .name = "FIFO memory",
  86. .start = 0,
  87. .end = 767,
  88. .flags = 0,
  89. .parent = NULL,
  90. .sibling = NULL,
  91. .child = NULL
  92. },
  93. excite_scram_resource __attribute__((unused)) = {
  94. .name = "Scratch RAM",
  95. .start = EXCITE_PHYS_SCRAM,
  96. .end = EXCITE_PHYS_SCRAM + EXCITE_SIZE_SCRAM - 1,
  97. .flags = IORESOURCE_MEM,
  98. .parent = NULL,
  99. .sibling = NULL,
  100. .child = NULL
  101. },
  102. excite_fpga_resource __attribute__((unused)) = {
  103. .name = "System FPGA",
  104. .start = EXCITE_PHYS_FPGA,
  105. .end = EXCITE_PHYS_FPGA + EXCITE_SIZE_FPGA - 1,
  106. .flags = IORESOURCE_MEM,
  107. .parent = NULL,
  108. .sibling = NULL,
  109. .child = NULL
  110. },
  111. excite_nand_resource __attribute__((unused)) = {
  112. .name = "NAND flash control",
  113. .start = EXCITE_PHYS_NAND,
  114. .end = EXCITE_PHYS_NAND + EXCITE_SIZE_NAND - 1,
  115. .flags = IORESOURCE_MEM,
  116. .parent = NULL,
  117. .sibling = NULL,
  118. .child = NULL
  119. },
  120. excite_titan_resource __attribute__((unused)) = {
  121. .name = "TITAN registers",
  122. .start = EXCITE_PHYS_TITAN,
  123. .end = EXCITE_PHYS_TITAN + EXCITE_SIZE_TITAN - 1,
  124. .flags = IORESOURCE_MEM,
  125. .parent = NULL,
  126. .sibling = NULL,
  127. .child = NULL
  128. };
  129. static void adjust_resources(struct resource *res, unsigned int n)
  130. {
  131. struct resource *p;
  132. const unsigned long mask = IORESOURCE_IO | IORESOURCE_MEM
  133. | IORESOURCE_IRQ | IORESOURCE_DMA;
  134. for (p = res; p < res + n; p++) {
  135. const struct resource * const parent = p->parent;
  136. if (parent) {
  137. p->start += parent->start;
  138. p->end += parent->start;
  139. p->flags = parent->flags & mask;
  140. }
  141. }
  142. }
  143. #if defined(CONFIG_EXCITE_FCAP_GPI) || defined(CONFIG_EXCITE_FCAP_GPI_MODULE)
  144. static struct resource xicap_rsrc[] = {
  145. RINIT(0x4840, 0x486f, XICAP_RESOURCE_FIFO_RX, &excite_titan_resource),
  146. RINIT(0x4940, 0x494b, XICAP_RESOURCE_FIFO_TX, &excite_titan_resource),
  147. RINIT(0x5040, 0x5127, XICAP_RESOURCE_XDMA, &excite_titan_resource),
  148. RINIT(0x1000, 0x112f, XICAP_RESOURCE_PKTPROC, &excite_titan_resource),
  149. RINIT(0x1100, 0x110f, XICAP_RESOURCE_PKT_STREAM, &excite_fpga_resource),
  150. RINIT(0x0800, 0x0bff, XICAP_RESOURCE_DMADESC, &excite_scram_resource),
  151. RINIT(slice_xicap, slice_xicap, XICAP_RESOURCE_GPI_SLICE, &excite_gpislice_resource),
  152. RINIT(0x0100, 0x02ff, XICAP_RESOURCE_FIFO_BLK, &excite_fifomem_resource),
  153. RINIT_IRQ(TITAN_IRQ, XICAP_RESOURCE_IRQ)
  154. };
  155. static struct platform_device xicap_pdev = {
  156. .name = XICAP_NAME,
  157. .id = XICAP_UNIT,
  158. .num_resources = ARRAY_SIZE(xicap_rsrc),
  159. .resource = xicap_rsrc
  160. };
  161. /*
  162. * Create a platform device for the GPI port that receives the
  163. * image data from the embedded camera.
  164. */
  165. static int __init xicap_devinit(void)
  166. {
  167. unsigned long tend;
  168. u32 reg;
  169. int retval;
  170. adjust_resources(xicap_rsrc, ARRAY_SIZE(xicap_rsrc));
  171. /* Power up the slice and configure it. */
  172. reg = titan_readl(CPTC1R);
  173. reg &= ~(0x11100 << slice_xicap);
  174. titan_writel(reg, CPTC1R);
  175. /* Enable slice & DLL. */
  176. reg= titan_readl(CPRR);
  177. reg &= ~(0x00030003 << (slice_xicap * 2));
  178. titan_writel(reg, CPRR);
  179. /* Wait for DLLs to lock */
  180. tend = jiffies + DLL_TIMEOUT * HZ;
  181. while (time_before(jiffies, tend)) {
  182. if (!(~titan_readl(CPDSR) & (0x1 << (slice_xicap * 4))))
  183. break;
  184. yield();
  185. }
  186. if (~titan_readl(CPDSR) & (0x1 << (slice_xicap * 4))) {
  187. printk(KERN_ERR "%s: DLL not locked after %u seconds\n",
  188. xicap_pdev.name, DLL_TIMEOUT);
  189. retval = -ETIME;
  190. } else {
  191. /* Register platform device */
  192. retval = platform_device_register(&xicap_pdev);
  193. }
  194. return retval;
  195. }
  196. device_initcall(xicap_devinit);
  197. #endif /* defined(CONFIG_EXCITE_FCAP_GPI) || defined(CONFIG_EXCITE_FCAP_GPI_MODULE) */
  198. #if defined(CONFIG_WDT_RM9K_GPI) || defined(CONFIG_WDT_RM9K_GPI_MODULE)
  199. static struct resource wdt_rsrc[] = {
  200. RINIT(0, 0, WDT_RESOURCE_COUNTER, &excite_ctr_resource),
  201. RINIT(0x0084, 0x008f, WDT_RESOURCE_REGS, &excite_titan_resource),
  202. RINIT_IRQ(TITAN_IRQ, WDT_RESOURCE_IRQ)
  203. };
  204. static struct platform_device wdt_pdev = {
  205. .name = WDT_NAME,
  206. .id = -1,
  207. .num_resources = ARRAY_SIZE(wdt_rsrc),
  208. .resource = wdt_rsrc
  209. };
  210. /*
  211. * Create a platform device for the GPI port that receives the
  212. * image data from the embedded camera.
  213. */
  214. static int __init wdt_devinit(void)
  215. {
  216. adjust_resources(wdt_rsrc, ARRAY_SIZE(wdt_rsrc));
  217. return platform_device_register(&wdt_pdev);
  218. }
  219. device_initcall(wdt_devinit);
  220. #endif /* defined(CONFIG_WDT_RM9K_GPI) || defined(CONFIG_WDT_RM9K_GPI_MODULE) */
  221. static struct resource excite_nandflash_rsrc[] = {
  222. RINIT(0x2000, 0x201f, EXCITE_NANDFLASH_RESOURCE_REGS, &excite_nand_resource)
  223. };
  224. static struct platform_device excite_nandflash_pdev = {
  225. .name = "excite_nand",
  226. .id = NAND_UNIT,
  227. .num_resources = ARRAY_SIZE(excite_nandflash_rsrc),
  228. .resource = excite_nandflash_rsrc
  229. };
  230. /*
  231. * Create a platform device for the access to the nand-flash
  232. * port
  233. */
  234. static int __init excite_nandflash_devinit(void)
  235. {
  236. adjust_resources(excite_nandflash_rsrc, ARRAY_SIZE(excite_nandflash_rsrc));
  237. /* nothing to be done here */
  238. /* Register platform device */
  239. return platform_device_register(&excite_nandflash_pdev);
  240. }
  241. device_initcall(excite_nandflash_devinit);
  242. static struct resource iodev_rsrc[] = {
  243. RINIT_IRQ(FPGA1_IRQ, IODEV_RESOURCE_IRQ)
  244. };
  245. static struct platform_device io_pdev = {
  246. .name = IODEV_NAME,
  247. .id = -1,
  248. .num_resources = ARRAY_SIZE(iodev_rsrc),
  249. .resource = iodev_rsrc
  250. };
  251. /*
  252. * Create a platform device for the external I/O ports.
  253. */
  254. static int __init io_devinit(void)
  255. {
  256. adjust_resources(iodev_rsrc, ARRAY_SIZE(iodev_rsrc));
  257. return platform_device_register(&io_pdev);
  258. }
  259. device_initcall(io_devinit);
  260. #if defined(CONFIG_RM9K_GE) || defined(CONFIG_RM9K_GE_MODULE)
  261. static struct resource rm9k_ge_rsrc[] = {
  262. RINIT(0x2200, 0x27ff, RM9K_GE_RESOURCE_MAC, &excite_titan_resource),
  263. RINIT(0x1800, 0x1fff, RM9K_GE_RESOURCE_MSTAT, &excite_titan_resource),
  264. RINIT(0x2000, 0x212f, RM9K_GE_RESOURCE_PKTPROC, &excite_titan_resource),
  265. RINIT(0x5140, 0x5227, RM9K_GE_RESOURCE_XDMA, &excite_titan_resource),
  266. RINIT(0x4870, 0x489f, RM9K_GE_RESOURCE_FIFO_RX, &excite_titan_resource),
  267. RINIT(0x494c, 0x4957, RM9K_GE_RESOURCE_FIFO_TX, &excite_titan_resource),
  268. RINIT(0x0000, 0x007f, RM9K_GE_RESOURCE_FIFOMEM_RX, &excite_fifomem_resource),
  269. RINIT(0x0080, 0x00ff, RM9K_GE_RESOURCE_FIFOMEM_TX, &excite_fifomem_resource),
  270. RINIT(0x0180, 0x019f, RM9K_GE_RESOURCE_PHY, &excite_titan_resource),
  271. RINIT(0x0000, 0x03ff, RM9K_GE_RESOURCE_DMADESC_RX, &excite_scram_resource),
  272. RINIT(0x0400, 0x07ff, RM9K_GE_RESOURCE_DMADESC_TX, &excite_scram_resource),
  273. RINIT(slice_eth, slice_eth, RM9K_GE_RESOURCE_GPI_SLICE, &excite_gpislice_resource),
  274. RINIT(0, 0, RM9K_GE_RESOURCE_MDIO_CHANNEL, &excite_mdio_channel_resource),
  275. RINIT_IRQ(TITAN_IRQ, RM9K_GE_RESOURCE_IRQ_MAIN),
  276. RINIT_IRQ(PHY_IRQ, RM9K_GE_RESOURCE_IRQ_PHY)
  277. };
  278. static struct platform_device rm9k_ge_pdev = {
  279. .name = RM9K_GE_NAME,
  280. .id = RM9K_GE_UNIT,
  281. .num_resources = ARRAY_SIZE(rm9k_ge_rsrc),
  282. .resource = rm9k_ge_rsrc
  283. };
  284. /*
  285. * Create a platform device for the Ethernet port.
  286. */
  287. static int __init rm9k_ge_devinit(void)
  288. {
  289. u32 reg;
  290. adjust_resources(rm9k_ge_rsrc, ARRAY_SIZE(rm9k_ge_rsrc));
  291. /* Power up the slice and configure it. */
  292. reg = titan_readl(CPTC1R);
  293. reg &= ~(0x11000 << slice_eth);
  294. reg |= 0x100 << slice_eth;
  295. titan_writel(reg, CPTC1R);
  296. /* Take the MAC out of reset, reset the DLLs. */
  297. reg = titan_readl(CPRR);
  298. reg &= ~(0x00030000 << (slice_eth * 2));
  299. reg |= 0x3 << (slice_eth * 2);
  300. titan_writel(reg, CPRR);
  301. return platform_device_register(&rm9k_ge_pdev);
  302. }
  303. device_initcall(rm9k_ge_devinit);
  304. #endif /* defined(CONFIG_RM9K_GE) || defined(CONFIG_RM9K_GE_MODULE) */
  305. static int __init excite_setup_devs(void)
  306. {
  307. int res;
  308. u32 reg;
  309. /* Enable xdma and fifo interrupts */
  310. reg = titan_readl(0x0050);
  311. titan_writel(reg | 0x18000000, 0x0050);
  312. res = request_resource(&iomem_resource, &excite_titan_resource);
  313. if (res)
  314. return res;
  315. res = request_resource(&iomem_resource, &excite_scram_resource);
  316. if (res)
  317. return res;
  318. res = request_resource(&iomem_resource, &excite_fpga_resource);
  319. if (res)
  320. return res;
  321. res = request_resource(&iomem_resource, &excite_nand_resource);
  322. if (res)
  323. return res;
  324. excite_fpga_resource.flags = excite_fpga_resource.parent->flags &
  325. ( IORESOURCE_IO | IORESOURCE_MEM
  326. | IORESOURCE_IRQ | IORESOURCE_DMA);
  327. excite_nand_resource.flags = excite_nand_resource.parent->flags &
  328. ( IORESOURCE_IO | IORESOURCE_MEM
  329. | IORESOURCE_IRQ | IORESOURCE_DMA);
  330. return 0;
  331. }
  332. arch_initcall(excite_setup_devs);