excite_device.c 10 KB

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