pcit.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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, 0),
  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 = 0x00000000UL,
  54. .end = 0x03bfffffUL,
  55. .name = "PCIT IO",
  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 = 0xcf8,
  86. .end = 0xcfb,
  87. .name = "PCI config addr",
  88. .flags = IORESOURCE_BUSY
  89. }, {
  90. .start = 0xcfc,
  91. .end = 0xcff,
  92. .name = "PCI config data",
  93. .flags = IORESOURCE_BUSY
  94. }
  95. };
  96. static struct resource sni_mem_resource = {
  97. .start = 0x18000000UL,
  98. .end = 0x1fbfffffUL,
  99. .name = "PCIT PCI MEM",
  100. .flags = IORESOURCE_MEM
  101. };
  102. static void __init sni_pcit_resource_init(void)
  103. {
  104. int i;
  105. /* request I/O space for devices used on all i[345]86 PCs */
  106. for (i = 0; i < ARRAY_SIZE(pcit_io_resources); i++)
  107. request_resource(&sni_io_resource, pcit_io_resources + i);
  108. }
  109. extern struct pci_ops sni_pcit_ops;
  110. static struct pci_controller sni_pcit_controller = {
  111. .pci_ops = &sni_pcit_ops,
  112. .mem_resource = &sni_mem_resource,
  113. .mem_offset = 0x00000000UL,
  114. .io_resource = &sni_io_resource,
  115. .io_offset = 0x00000000UL,
  116. .io_map_base = SNI_PORT_BASE
  117. };
  118. static void enable_pcit_irq(unsigned int irq)
  119. {
  120. u32 mask = 1 << (irq - SNI_PCIT_INT_START + 24);
  121. *(volatile u32 *)SNI_PCIT_INT_REG |= mask;
  122. }
  123. void disable_pcit_irq(unsigned int irq)
  124. {
  125. u32 mask = 1 << (irq - SNI_PCIT_INT_START + 24);
  126. *(volatile u32 *)SNI_PCIT_INT_REG &= ~mask;
  127. }
  128. void end_pcit_irq(unsigned int irq)
  129. {
  130. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
  131. enable_pcit_irq(irq);
  132. }
  133. static struct irq_chip pcit_irq_type = {
  134. .typename = "PCIT",
  135. .ack = disable_pcit_irq,
  136. .mask = disable_pcit_irq,
  137. .mask_ack = disable_pcit_irq,
  138. .unmask = enable_pcit_irq,
  139. .end = end_pcit_irq,
  140. };
  141. static void pcit_hwint1(void)
  142. {
  143. u32 pending = *(volatile u32 *)SNI_PCIT_INT_REG;
  144. int irq;
  145. clear_c0_status(IE_IRQ1);
  146. irq = ffs((pending >> 16) & 0x7f);
  147. if (likely(irq > 0))
  148. do_IRQ (irq + SNI_PCIT_INT_START - 1);
  149. set_c0_status (IE_IRQ1);
  150. }
  151. static void pcit_hwint0(void)
  152. {
  153. u32 pending = *(volatile u32 *)SNI_PCIT_INT_REG;
  154. int irq;
  155. clear_c0_status(IE_IRQ0);
  156. irq = ffs((pending >> 16) & 0x3f);
  157. if (likely(irq > 0))
  158. do_IRQ (irq + SNI_PCIT_INT_START - 1);
  159. set_c0_status (IE_IRQ0);
  160. }
  161. static void sni_pcit_hwint(void)
  162. {
  163. u32 pending = read_c0_cause() & read_c0_status();
  164. if (pending & C_IRQ1)
  165. pcit_hwint1();
  166. else if (pending & C_IRQ2)
  167. do_IRQ (MIPS_CPU_IRQ_BASE + 4);
  168. else if (pending & C_IRQ3)
  169. do_IRQ (MIPS_CPU_IRQ_BASE + 5);
  170. else if (pending & C_IRQ5)
  171. do_IRQ (MIPS_CPU_IRQ_BASE + 7);
  172. }
  173. static void sni_pcit_hwint_cplus(void)
  174. {
  175. u32 pending = read_c0_cause() & read_c0_status();
  176. if (pending & C_IRQ0)
  177. pcit_hwint0();
  178. else if (pending & C_IRQ1)
  179. do_IRQ (MIPS_CPU_IRQ_BASE + 3);
  180. else if (pending & C_IRQ2)
  181. do_IRQ (MIPS_CPU_IRQ_BASE + 4);
  182. else if (pending & C_IRQ3)
  183. do_IRQ (MIPS_CPU_IRQ_BASE + 5);
  184. else if (pending & C_IRQ5)
  185. do_IRQ (MIPS_CPU_IRQ_BASE + 7);
  186. }
  187. void __init sni_pcit_irq_init(void)
  188. {
  189. int i;
  190. mips_cpu_irq_init();
  191. for (i = SNI_PCIT_INT_START; i <= SNI_PCIT_INT_END; i++)
  192. set_irq_chip(i, &pcit_irq_type);
  193. *(volatile u32 *)SNI_PCIT_INT_REG = 0;
  194. sni_hwint = sni_pcit_hwint;
  195. change_c0_status(ST0_IM, IE_IRQ1);
  196. setup_irq (SNI_PCIT_INT_START + 6, &sni_isa_irq);
  197. }
  198. void __init sni_pcit_cplus_irq_init(void)
  199. {
  200. int i;
  201. mips_cpu_irq_init();
  202. for (i = SNI_PCIT_INT_START; i <= SNI_PCIT_INT_END; i++)
  203. set_irq_chip(i, &pcit_irq_type);
  204. *(volatile u32 *)SNI_PCIT_INT_REG = 0x40000000;
  205. sni_hwint = sni_pcit_hwint_cplus;
  206. change_c0_status(ST0_IM, IE_IRQ0);
  207. setup_irq (MIPS_CPU_IRQ_BASE + 3, &sni_isa_irq);
  208. }
  209. void sni_pcit_init(void)
  210. {
  211. rtc_mips_get_time = mc146818_get_cmos_time;
  212. rtc_mips_set_time = mc146818_set_rtc_mmss;
  213. board_time_init = sni_cpu_time_init;
  214. ioport_resource.end = sni_io_resource.end;
  215. #ifdef CONFIG_PCI
  216. PCIBIOS_MIN_IO = 0x9000;
  217. register_pci_controller(&sni_pcit_controller);
  218. #endif
  219. sni_pcit_resource_init();
  220. }
  221. static int __init snirm_pcit_setup_devinit(void)
  222. {
  223. switch (sni_brd_type) {
  224. case SNI_BRD_PCI_TOWER:
  225. platform_device_register(&pcit_serial8250_device);
  226. break;
  227. case SNI_BRD_PCI_TOWER_CPLUS:
  228. platform_device_register(&pcit_cplus_serial8250_device);
  229. break;
  230. }
  231. return 0;
  232. }
  233. device_initcall(snirm_pcit_setup_devinit);