pcit.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. /*
  2. * PCI Tower specific code
  3. *
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file "COPYING" in the main directory of this archive
  6. * for more details.
  7. *
  8. * Copyright (C) 2006 Thomas Bogendoerfer (tsbogend@alpha.franken.de)
  9. */
  10. #include <linux/init.h>
  11. #include <linux/interrupt.h>
  12. #include <linux/pci.h>
  13. #include <linux/serial_8250.h>
  14. #include <asm/mc146818-time.h>
  15. #include <asm/sni.h>
  16. #include <asm/time.h>
  17. #include <asm/irq_cpu.h>
  18. #define PORT(_base,_irq) \
  19. { \
  20. .iobase = _base, \
  21. .irq = _irq, \
  22. .uartclk = 1843200, \
  23. .iotype = UPIO_PORT, \
  24. .flags = UPF_BOOT_AUTOCONF, \
  25. }
  26. static struct plat_serial8250_port pcit_data[] = {
  27. PORT(0x3f8, 0),
  28. PORT(0x2f8, 3),
  29. { },
  30. };
  31. static struct platform_device pcit_serial8250_device = {
  32. .name = "serial8250",
  33. .id = PLAT8250_DEV_PLATFORM,
  34. .dev = {
  35. .platform_data = pcit_data,
  36. },
  37. };
  38. static struct plat_serial8250_port pcit_cplus_data[] = {
  39. PORT(0x3f8, 4),
  40. PORT(0x2f8, 3),
  41. PORT(0x3e8, 4),
  42. PORT(0x2e8, 3),
  43. { },
  44. };
  45. static struct platform_device pcit_cplus_serial8250_device = {
  46. .name = "serial8250",
  47. .id = PLAT8250_DEV_PLATFORM,
  48. .dev = {
  49. .platform_data = pcit_cplus_data,
  50. },
  51. };
  52. static struct resource sni_io_resource = {
  53. .start = 0x00001000UL,
  54. .end = 0x03bfffffUL,
  55. .name = "PCIT IO MEM",
  56. .flags = IORESOURCE_IO,
  57. };
  58. static struct resource pcit_io_resources[] = {
  59. {
  60. .start = 0x00,
  61. .end = 0x1f,
  62. .name = "dma1",
  63. .flags = IORESOURCE_BUSY
  64. }, {
  65. .start = 0x40,
  66. .end = 0x5f,
  67. .name = "timer",
  68. .flags = IORESOURCE_BUSY
  69. }, {
  70. .start = 0x60,
  71. .end = 0x6f,
  72. .name = "keyboard",
  73. .flags = IORESOURCE_BUSY
  74. }, {
  75. .start = 0x80,
  76. .end = 0x8f,
  77. .name = "dma page reg",
  78. .flags = IORESOURCE_BUSY
  79. }, {
  80. .start = 0xc0,
  81. .end = 0xdf,
  82. .name = "dma2",
  83. .flags = IORESOURCE_BUSY
  84. }, {
  85. .start = 0xcfc,
  86. .end = 0xcff,
  87. .name = "PCI config data",
  88. .flags = IORESOURCE_BUSY
  89. }
  90. };
  91. static struct resource sni_mem_resource = {
  92. .start = 0x10000000UL,
  93. .end = 0xffffffffUL,
  94. .name = "PCIT PCI MEM",
  95. .flags = IORESOURCE_MEM
  96. };
  97. /*
  98. * The RM200/RM300 has a few holes in it's PCI/EISA memory address space used
  99. * for other purposes. Be paranoid and allocate all of the before the PCI
  100. * code gets a chance to to map anything else there ...
  101. *
  102. * This leaves the following areas available:
  103. *
  104. * 0x10000000 - 0x1009ffff (640kB) PCI/EISA/ISA Bus Memory
  105. * 0x10100000 - 0x13ffffff ( 15MB) PCI/EISA/ISA Bus Memory
  106. * 0x18000000 - 0x1fbfffff (124MB) PCI/EISA Bus Memory
  107. * 0x1ff08000 - 0x1ffeffff (816kB) PCI/EISA Bus Memory
  108. * 0xa0000000 - 0xffffffff (1.5GB) PCI/EISA Bus Memory
  109. */
  110. static struct resource pcit_mem_resources[] = {
  111. {
  112. .start = 0x14000000,
  113. .end = 0x17bfffff,
  114. .name = "PCI IO",
  115. .flags = IORESOURCE_BUSY
  116. }, {
  117. .start = 0x17c00000,
  118. .end = 0x17ffffff,
  119. .name = "Cache Replacement Area",
  120. .flags = IORESOURCE_BUSY
  121. }, {
  122. .start = 0x180a0000,
  123. .end = 0x180bffff,
  124. .name = "Video RAM area",
  125. .flags = IORESOURCE_BUSY
  126. }, {
  127. .start = 0x180c0000,
  128. .end = 0x180fffff,
  129. .name = "ISA Reserved",
  130. .flags = IORESOURCE_BUSY
  131. }, {
  132. .start = 0x19000000,
  133. .end = 0x1fbfffff,
  134. .name = "PCI MEM",
  135. .flags = IORESOURCE_BUSY
  136. }, {
  137. .start = 0x1fc00000,
  138. .end = 0x1fc7ffff,
  139. .name = "Boot PROM",
  140. .flags = IORESOURCE_BUSY
  141. }, {
  142. .start = 0x1fc80000,
  143. .end = 0x1fcfffff,
  144. .name = "Diag PROM",
  145. .flags = IORESOURCE_BUSY
  146. }, {
  147. .start = 0x1fd00000,
  148. .end = 0x1fdfffff,
  149. .name = "X-Bus",
  150. .flags = IORESOURCE_BUSY
  151. }, {
  152. .start = 0x1fe00000,
  153. .end = 0x1fefffff,
  154. .name = "BIOS map",
  155. .flags = IORESOURCE_BUSY
  156. }, {
  157. .start = 0x1ff00000,
  158. .end = 0x1ff7ffff,
  159. .name = "NVRAM / EEPROM",
  160. .flags = IORESOURCE_BUSY
  161. }, {
  162. .start = 0x1fff0000,
  163. .end = 0x1fffefff,
  164. .name = "MAUI ASIC",
  165. .flags = IORESOURCE_BUSY
  166. }, {
  167. .start = 0x1ffff000,
  168. .end = 0x1fffffff,
  169. .name = "MP Agent",
  170. .flags = IORESOURCE_BUSY
  171. }, {
  172. .start = 0x20000000,
  173. .end = 0x9fffffff,
  174. .name = "Main Memory",
  175. .flags = IORESOURCE_BUSY
  176. }
  177. };
  178. static void __init sni_pcit_resource_init(void)
  179. {
  180. int i;
  181. /* request I/O space for devices used on all i[345]86 PCs */
  182. for (i = 0; i < ARRAY_SIZE(pcit_io_resources); i++)
  183. request_resource(&ioport_resource, pcit_io_resources + i);
  184. /* request mem space for pcimt-specific devices */
  185. for (i = 0; i < ARRAY_SIZE(pcit_mem_resources); i++)
  186. request_resource(&sni_mem_resource, pcit_mem_resources + i);
  187. ioport_resource.end = sni_io_resource.end;
  188. }
  189. extern struct pci_ops sni_pcit_ops;
  190. static struct pci_controller sni_pcit_controller = {
  191. .pci_ops = &sni_pcit_ops,
  192. .mem_resource = &sni_mem_resource,
  193. .mem_offset = 0x10000000UL,
  194. .io_resource = &sni_io_resource,
  195. .io_offset = 0x00000000UL
  196. };
  197. static void enable_pcit_irq(unsigned int irq)
  198. {
  199. u32 mask = 1 << (irq - SNI_PCIT_INT_START + 24);
  200. *(volatile u32 *)SNI_PCIT_INT_REG |= mask;
  201. }
  202. void disable_pcit_irq(unsigned int irq)
  203. {
  204. u32 mask = 1 << (irq - SNI_PCIT_INT_START + 24);
  205. *(volatile u32 *)SNI_PCIT_INT_REG &= ~mask;
  206. }
  207. void end_pcit_irq(unsigned int irq)
  208. {
  209. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
  210. enable_pcit_irq(irq);
  211. }
  212. static struct irq_chip pcit_irq_type = {
  213. .typename = "PCIT",
  214. .ack = disable_pcit_irq,
  215. .mask = disable_pcit_irq,
  216. .mask_ack = disable_pcit_irq,
  217. .unmask = enable_pcit_irq,
  218. .end = end_pcit_irq,
  219. };
  220. static void pcit_hwint1(void)
  221. {
  222. u32 pending = *(volatile u32 *)SNI_PCIT_INT_REG;
  223. int irq;
  224. clear_c0_status(IE_IRQ1);
  225. irq = ffs((pending >> 16) & 0x7f);
  226. if (likely(irq > 0))
  227. do_IRQ (irq + SNI_PCIT_INT_START - 1);
  228. set_c0_status (IE_IRQ1);
  229. }
  230. static void pcit_hwint0(void)
  231. {
  232. u32 pending = *(volatile u32 *)SNI_PCIT_INT_REG;
  233. int irq;
  234. clear_c0_status(IE_IRQ0);
  235. irq = ffs((pending >> 16) & 0x7f);
  236. if (likely(irq > 0))
  237. do_IRQ (irq + SNI_PCIT_INT_START - 1);
  238. set_c0_status (IE_IRQ0);
  239. }
  240. static void sni_pcit_hwint(void)
  241. {
  242. u32 pending = (read_c0_cause() & read_c0_status());
  243. if (pending & C_IRQ1)
  244. pcit_hwint1();
  245. else if (pending & C_IRQ2)
  246. do_IRQ (SNI_MIPS_IRQ_CPU_BASE + 4);
  247. else if (pending & C_IRQ3)
  248. do_IRQ (SNI_MIPS_IRQ_CPU_BASE + 5);
  249. else if (pending & C_IRQ5)
  250. do_IRQ (SNI_MIPS_IRQ_CPU_BASE + 7);
  251. }
  252. static void sni_pcit_hwint_cplus(void)
  253. {
  254. u32 pending = (read_c0_cause() & read_c0_status());
  255. if (pending & C_IRQ0)
  256. pcit_hwint0();
  257. else if (pending & C_IRQ2)
  258. do_IRQ (SNI_MIPS_IRQ_CPU_BASE + 4);
  259. else if (pending & C_IRQ3)
  260. do_IRQ (SNI_MIPS_IRQ_CPU_BASE + 5);
  261. else if (pending & C_IRQ5)
  262. do_IRQ (SNI_MIPS_IRQ_CPU_BASE + 7);
  263. }
  264. void __init sni_pcit_irq_init(void)
  265. {
  266. int i;
  267. mips_cpu_irq_init();
  268. for (i = SNI_PCIT_INT_START; i <= SNI_PCIT_INT_END; i++)
  269. set_irq_chip(i, &pcit_irq_type);
  270. *(volatile u32 *)SNI_PCIT_INT_REG = 0;
  271. sni_hwint = sni_pcit_hwint;
  272. change_c0_status(ST0_IM, IE_IRQ1);
  273. setup_irq (SNI_PCIT_INT_START + 6, &sni_isa_irq);
  274. }
  275. void __init sni_pcit_cplus_irq_init(void)
  276. {
  277. int i;
  278. mips_cpu_irq_init();
  279. for (i = SNI_PCIT_INT_START; i <= SNI_PCIT_INT_END; i++)
  280. set_irq_chip(i, &pcit_irq_type);
  281. *(volatile u32 *)SNI_PCIT_INT_REG = 0;
  282. sni_hwint = sni_pcit_hwint_cplus;
  283. change_c0_status(ST0_IM, IE_IRQ0);
  284. setup_irq (SNI_PCIT_INT_START + 6, &sni_isa_irq);
  285. }
  286. void sni_pcit_init(void)
  287. {
  288. sni_pcit_resource_init();
  289. rtc_mips_get_time = mc146818_get_cmos_time;
  290. rtc_mips_set_time = mc146818_set_rtc_mmss;
  291. board_time_init = sni_cpu_time_init;
  292. #ifdef CONFIG_PCI
  293. register_pci_controller(&sni_pcit_controller);
  294. #endif
  295. }
  296. static int __init snirm_pcit_setup_devinit(void)
  297. {
  298. switch (sni_brd_type) {
  299. case SNI_BRD_PCI_TOWER:
  300. platform_device_register(&pcit_serial8250_device);
  301. break;
  302. case SNI_BRD_PCI_TOWER_CPLUS:
  303. platform_device_register(&pcit_cplus_serial8250_device);
  304. break;
  305. }
  306. return 0;
  307. }
  308. device_initcall(snirm_pcit_setup_devinit);