interrupts.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. /*
  2. * interrupts.c: Interrupt mappings for PNX833X.
  3. *
  4. * Copyright 2008 NXP Semiconductors
  5. * Chris Steel <chris.steel@nxp.com>
  6. * Daniel Laird <daniel.j.laird@nxp.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. #include <linux/kernel.h>
  23. #include <linux/irq.h>
  24. #include <linux/hardirq.h>
  25. #include <linux/interrupt.h>
  26. #include <asm/mipsregs.h>
  27. #include <asm/irq_cpu.h>
  28. #include <irq.h>
  29. #include <irq-mapping.h>
  30. #include <gpio.h>
  31. static int mips_cpu_timer_irq;
  32. static const unsigned int irq_prio[PNX833X_PIC_NUM_IRQ] =
  33. {
  34. 0, /* unused */
  35. 4, /* PNX833X_PIC_I2C0_INT 1 */
  36. 4, /* PNX833X_PIC_I2C1_INT 2 */
  37. 1, /* PNX833X_PIC_UART0_INT 3 */
  38. 1, /* PNX833X_PIC_UART1_INT 4 */
  39. 6, /* PNX833X_PIC_TS_IN0_DV_INT 5 */
  40. 6, /* PNX833X_PIC_TS_IN0_DMA_INT 6 */
  41. 7, /* PNX833X_PIC_GPIO_INT 7 */
  42. 4, /* PNX833X_PIC_AUDIO_DEC_INT 8 */
  43. 5, /* PNX833X_PIC_VIDEO_DEC_INT 9 */
  44. 4, /* PNX833X_PIC_CONFIG_INT 10 */
  45. 4, /* PNX833X_PIC_AOI_INT 11 */
  46. 9, /* PNX833X_PIC_SYNC_INT 12 */
  47. 9, /* PNX8335_PIC_SATA_INT 13 */
  48. 4, /* PNX833X_PIC_OSD_INT 14 */
  49. 9, /* PNX833X_PIC_DISP1_INT 15 */
  50. 4, /* PNX833X_PIC_DEINTERLACER_INT 16 */
  51. 9, /* PNX833X_PIC_DISPLAY2_INT 17 */
  52. 4, /* PNX833X_PIC_VC_INT 18 */
  53. 4, /* PNX833X_PIC_SC_INT 19 */
  54. 9, /* PNX833X_PIC_IDE_INT 20 */
  55. 9, /* PNX833X_PIC_IDE_DMA_INT 21 */
  56. 6, /* PNX833X_PIC_TS_IN1_DV_INT 22 */
  57. 6, /* PNX833X_PIC_TS_IN1_DMA_INT 23 */
  58. 4, /* PNX833X_PIC_SGDX_DMA_INT 24 */
  59. 4, /* PNX833X_PIC_TS_OUT_INT 25 */
  60. 4, /* PNX833X_PIC_IR_INT 26 */
  61. 3, /* PNX833X_PIC_VMSP1_INT 27 */
  62. 3, /* PNX833X_PIC_VMSP2_INT 28 */
  63. 4, /* PNX833X_PIC_PIBC_INT 29 */
  64. 4, /* PNX833X_PIC_TS_IN0_TRD_INT 30 */
  65. 4, /* PNX833X_PIC_SGDX_TPD_INT 31 */
  66. 5, /* PNX833X_PIC_USB_INT 32 */
  67. 4, /* PNX833X_PIC_TS_IN1_TRD_INT 33 */
  68. 4, /* PNX833X_PIC_CLOCK_INT 34 */
  69. 4, /* PNX833X_PIC_SGDX_PARSER_INT 35 */
  70. 4, /* PNX833X_PIC_VMSP_DMA_INT 36 */
  71. #if defined(CONFIG_SOC_PNX8335)
  72. 4, /* PNX8335_PIC_MIU_INT 37 */
  73. 4, /* PNX8335_PIC_AVCHIP_IRQ_INT 38 */
  74. 9, /* PNX8335_PIC_SYNC_HD_INT 39 */
  75. 9, /* PNX8335_PIC_DISP_HD_INT 40 */
  76. 9, /* PNX8335_PIC_DISP_SCALER_INT 41 */
  77. 4, /* PNX8335_PIC_OSD_HD1_INT 42 */
  78. 4, /* PNX8335_PIC_DTL_WRITER_Y_INT 43 */
  79. 4, /* PNX8335_PIC_DTL_WRITER_C_INT 44 */
  80. 4, /* PNX8335_PIC_DTL_EMULATOR_Y_IR_INT 45 */
  81. 4, /* PNX8335_PIC_DTL_EMULATOR_C_IR_INT 46 */
  82. 4, /* PNX8335_PIC_DENC_TTX_INT 47 */
  83. 4, /* PNX8335_PIC_MMI_SIF0_INT 48 */
  84. 4, /* PNX8335_PIC_MMI_SIF1_INT 49 */
  85. 4, /* PNX8335_PIC_MMI_CDMMU_INT 50 */
  86. 4, /* PNX8335_PIC_PIBCS_INT 51 */
  87. 12, /* PNX8335_PIC_ETHERNET_INT 52 */
  88. 3, /* PNX8335_PIC_VMSP1_0_INT 53 */
  89. 3, /* PNX8335_PIC_VMSP1_1_INT 54 */
  90. 4, /* PNX8335_PIC_VMSP1_DMA_INT 55 */
  91. 4, /* PNX8335_PIC_TDGR_DE_INT 56 */
  92. 4, /* PNX8335_PIC_IR1_IRQ_INT 57 */
  93. #endif
  94. };
  95. static void pnx833x_timer_dispatch(void)
  96. {
  97. do_IRQ(mips_cpu_timer_irq);
  98. }
  99. static void pic_dispatch(void)
  100. {
  101. unsigned int irq = PNX833X_REGFIELD(PIC_INT_SRC, INT_SRC);
  102. if ((irq >= 1) && (irq < (PNX833X_PIC_NUM_IRQ))) {
  103. unsigned long priority = PNX833X_PIC_INT_PRIORITY;
  104. PNX833X_PIC_INT_PRIORITY = irq_prio[irq];
  105. if (irq == PNX833X_PIC_GPIO_INT) {
  106. unsigned long mask = PNX833X_PIO_INT_STATUS & PNX833X_PIO_INT_ENABLE;
  107. int pin;
  108. while ((pin = ffs(mask & 0xffff))) {
  109. pin -= 1;
  110. do_IRQ(PNX833X_GPIO_IRQ_BASE + pin);
  111. mask &= ~(1 << pin);
  112. }
  113. } else {
  114. do_IRQ(irq + PNX833X_PIC_IRQ_BASE);
  115. }
  116. PNX833X_PIC_INT_PRIORITY = priority;
  117. } else {
  118. printk(KERN_ERR "plat_irq_dispatch: unexpected irq %u\n", irq);
  119. }
  120. }
  121. asmlinkage void plat_irq_dispatch(void)
  122. {
  123. unsigned int pending = read_c0_status() & read_c0_cause();
  124. if (pending & STATUSF_IP4)
  125. pic_dispatch();
  126. else if (pending & STATUSF_IP7)
  127. do_IRQ(PNX833X_TIMER_IRQ);
  128. else
  129. spurious_interrupt();
  130. }
  131. static inline void pnx833x_hard_enable_pic_irq(unsigned int irq)
  132. {
  133. /* Currently we do this by setting IRQ priority to 1.
  134. If priority support is being implemented, 1 should be repalced
  135. by a better value. */
  136. PNX833X_PIC_INT_REG(irq) = irq_prio[irq];
  137. }
  138. static inline void pnx833x_hard_disable_pic_irq(unsigned int irq)
  139. {
  140. /* Disable IRQ by writing setting it's priority to 0 */
  141. PNX833X_PIC_INT_REG(irq) = 0;
  142. }
  143. static int irqflags[PNX833X_PIC_NUM_IRQ]; /* initialized by zeroes */
  144. #define IRQFLAG_STARTED 1
  145. #define IRQFLAG_DISABLED 2
  146. static DEFINE_SPINLOCK(pnx833x_irq_lock);
  147. static unsigned int pnx833x_startup_pic_irq(unsigned int irq)
  148. {
  149. unsigned long flags;
  150. unsigned int pic_irq = irq - PNX833X_PIC_IRQ_BASE;
  151. spin_lock_irqsave(&pnx833x_irq_lock, flags);
  152. irqflags[pic_irq] = IRQFLAG_STARTED; /* started, not disabled */
  153. pnx833x_hard_enable_pic_irq(pic_irq);
  154. spin_unlock_irqrestore(&pnx833x_irq_lock, flags);
  155. return 0;
  156. }
  157. static void pnx833x_shutdown_pic_irq(unsigned int irq)
  158. {
  159. unsigned long flags;
  160. unsigned int pic_irq = irq - PNX833X_PIC_IRQ_BASE;
  161. spin_lock_irqsave(&pnx833x_irq_lock, flags);
  162. irqflags[pic_irq] = 0; /* not started */
  163. pnx833x_hard_disable_pic_irq(pic_irq);
  164. spin_unlock_irqrestore(&pnx833x_irq_lock, flags);
  165. }
  166. static void pnx833x_enable_pic_irq(unsigned int irq)
  167. {
  168. unsigned long flags;
  169. unsigned int pic_irq = irq - PNX833X_PIC_IRQ_BASE;
  170. spin_lock_irqsave(&pnx833x_irq_lock, flags);
  171. irqflags[pic_irq] &= ~IRQFLAG_DISABLED;
  172. if (irqflags[pic_irq] == IRQFLAG_STARTED)
  173. pnx833x_hard_enable_pic_irq(pic_irq);
  174. spin_unlock_irqrestore(&pnx833x_irq_lock, flags);
  175. }
  176. static void pnx833x_disable_pic_irq(unsigned int irq)
  177. {
  178. unsigned long flags;
  179. unsigned int pic_irq = irq - PNX833X_PIC_IRQ_BASE;
  180. spin_lock_irqsave(&pnx833x_irq_lock, flags);
  181. irqflags[pic_irq] |= IRQFLAG_DISABLED;
  182. pnx833x_hard_disable_pic_irq(pic_irq);
  183. spin_unlock_irqrestore(&pnx833x_irq_lock, flags);
  184. }
  185. static void pnx833x_ack_pic_irq(unsigned int irq)
  186. {
  187. }
  188. static void pnx833x_end_pic_irq(unsigned int irq)
  189. {
  190. }
  191. static DEFINE_SPINLOCK(pnx833x_gpio_pnx833x_irq_lock);
  192. static unsigned int pnx833x_startup_gpio_irq(unsigned int irq)
  193. {
  194. int pin = irq - PNX833X_GPIO_IRQ_BASE;
  195. unsigned long flags;
  196. spin_lock_irqsave(&pnx833x_gpio_pnx833x_irq_lock, flags);
  197. pnx833x_gpio_enable_irq(pin);
  198. spin_unlock_irqrestore(&pnx833x_gpio_pnx833x_irq_lock, flags);
  199. return 0;
  200. }
  201. static void pnx833x_enable_gpio_irq(unsigned int irq)
  202. {
  203. int pin = irq - PNX833X_GPIO_IRQ_BASE;
  204. unsigned long flags;
  205. spin_lock_irqsave(&pnx833x_gpio_pnx833x_irq_lock, flags);
  206. pnx833x_gpio_enable_irq(pin);
  207. spin_unlock_irqrestore(&pnx833x_gpio_pnx833x_irq_lock, flags);
  208. }
  209. static void pnx833x_disable_gpio_irq(unsigned int irq)
  210. {
  211. int pin = irq - PNX833X_GPIO_IRQ_BASE;
  212. unsigned long flags;
  213. spin_lock_irqsave(&pnx833x_gpio_pnx833x_irq_lock, flags);
  214. pnx833x_gpio_disable_irq(pin);
  215. spin_unlock_irqrestore(&pnx833x_gpio_pnx833x_irq_lock, flags);
  216. }
  217. static void pnx833x_ack_gpio_irq(unsigned int irq)
  218. {
  219. }
  220. static void pnx833x_end_gpio_irq(unsigned int irq)
  221. {
  222. int pin = irq - PNX833X_GPIO_IRQ_BASE;
  223. unsigned long flags;
  224. spin_lock_irqsave(&pnx833x_gpio_pnx833x_irq_lock, flags);
  225. pnx833x_gpio_clear_irq(pin);
  226. spin_unlock_irqrestore(&pnx833x_gpio_pnx833x_irq_lock, flags);
  227. }
  228. static int pnx833x_set_type_gpio_irq(unsigned int irq, unsigned int flow_type)
  229. {
  230. int pin = irq - PNX833X_GPIO_IRQ_BASE;
  231. int gpio_mode;
  232. switch (flow_type) {
  233. case IRQ_TYPE_EDGE_RISING:
  234. gpio_mode = GPIO_INT_EDGE_RISING;
  235. break;
  236. case IRQ_TYPE_EDGE_FALLING:
  237. gpio_mode = GPIO_INT_EDGE_FALLING;
  238. break;
  239. case IRQ_TYPE_EDGE_BOTH:
  240. gpio_mode = GPIO_INT_EDGE_BOTH;
  241. break;
  242. case IRQ_TYPE_LEVEL_HIGH:
  243. gpio_mode = GPIO_INT_LEVEL_HIGH;
  244. break;
  245. case IRQ_TYPE_LEVEL_LOW:
  246. gpio_mode = GPIO_INT_LEVEL_LOW;
  247. break;
  248. default:
  249. gpio_mode = GPIO_INT_NONE;
  250. break;
  251. }
  252. pnx833x_gpio_setup_irq(gpio_mode, pin);
  253. return 0;
  254. }
  255. static struct irq_chip pnx833x_pic_irq_type = {
  256. .typename = "PNX-PIC",
  257. .startup = pnx833x_startup_pic_irq,
  258. .shutdown = pnx833x_shutdown_pic_irq,
  259. .enable = pnx833x_enable_pic_irq,
  260. .disable = pnx833x_disable_pic_irq,
  261. .ack = pnx833x_ack_pic_irq,
  262. .end = pnx833x_end_pic_irq
  263. };
  264. static struct irq_chip pnx833x_gpio_irq_type = {
  265. .typename = "PNX-GPIO",
  266. .startup = pnx833x_startup_gpio_irq,
  267. .shutdown = pnx833x_disable_gpio_irq,
  268. .enable = pnx833x_enable_gpio_irq,
  269. .disable = pnx833x_disable_gpio_irq,
  270. .ack = pnx833x_ack_gpio_irq,
  271. .end = pnx833x_end_gpio_irq,
  272. .set_type = pnx833x_set_type_gpio_irq
  273. };
  274. void __init arch_init_irq(void)
  275. {
  276. unsigned int irq;
  277. /* setup standard internal cpu irqs */
  278. mips_cpu_irq_init();
  279. /* Set IRQ information in irq_desc */
  280. for (irq = PNX833X_PIC_IRQ_BASE; irq < (PNX833X_PIC_IRQ_BASE + PNX833X_PIC_NUM_IRQ); irq++) {
  281. pnx833x_hard_disable_pic_irq(irq);
  282. set_irq_chip_and_handler(irq, &pnx833x_pic_irq_type, handle_simple_irq);
  283. }
  284. for (irq = PNX833X_GPIO_IRQ_BASE; irq < (PNX833X_GPIO_IRQ_BASE + PNX833X_GPIO_NUM_IRQ); irq++)
  285. set_irq_chip_and_handler(irq, &pnx833x_gpio_irq_type, handle_simple_irq);
  286. /* Set PIC priority limiter register to 0 */
  287. PNX833X_PIC_INT_PRIORITY = 0;
  288. /* Setup GPIO IRQ dispatching */
  289. pnx833x_startup_pic_irq(PNX833X_PIC_GPIO_INT);
  290. /* Enable PIC IRQs (HWIRQ2) */
  291. if (cpu_has_vint)
  292. set_vi_handler(4, pic_dispatch);
  293. write_c0_status(read_c0_status() | IE_IRQ2);
  294. }
  295. unsigned int __cpuinit get_c0_compare_int(void)
  296. {
  297. if (cpu_has_vint)
  298. set_vi_handler(cp0_compare_irq, pnx833x_timer_dispatch);
  299. mips_cpu_timer_irq = MIPS_CPU_IRQ_BASE + cp0_compare_irq;
  300. return mips_cpu_timer_irq;
  301. }
  302. void __init plat_time_init(void)
  303. {
  304. /* calculate mips_hpt_frequency based on PNX833X_CLOCK_CPUCP_CTL reg */
  305. extern unsigned long mips_hpt_frequency;
  306. unsigned long reg = PNX833X_CLOCK_CPUCP_CTL;
  307. if (!(PNX833X_BIT(reg, CLOCK_CPUCP_CTL, EXIT_RESET))) {
  308. /* Functional clock is disabled so use crystal frequency */
  309. mips_hpt_frequency = 25;
  310. } else {
  311. #if defined(CONFIG_SOC_PNX8335)
  312. /* Functional clock is enabled, so get clock multiplier */
  313. mips_hpt_frequency = 90 + (10 * PNX8335_REGFIELD(CLOCK_PLL_CPU_CTL, FREQ));
  314. #else
  315. static const unsigned long int freq[4] = {240, 160, 120, 80};
  316. mips_hpt_frequency = freq[PNX833X_FIELD(reg, CLOCK_CPUCP_CTL, DIV_CLOCK)];
  317. #endif
  318. }
  319. printk(KERN_INFO "CPU clock is %ld MHz\n", mips_hpt_frequency);
  320. mips_hpt_frequency *= 500000;
  321. }