interrupts.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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 DEFINE_RAW_SPINLOCK(pnx833x_irq_lock);
  144. static unsigned int pnx833x_startup_pic_irq(unsigned int irq)
  145. {
  146. unsigned long flags;
  147. unsigned int pic_irq = irq - PNX833X_PIC_IRQ_BASE;
  148. raw_spin_lock_irqsave(&pnx833x_irq_lock, flags);
  149. pnx833x_hard_enable_pic_irq(pic_irq);
  150. raw_spin_unlock_irqrestore(&pnx833x_irq_lock, flags);
  151. return 0;
  152. }
  153. static void pnx833x_enable_pic_irq(struct irq_data *d)
  154. {
  155. unsigned long flags;
  156. unsigned int pic_irq = d->irq - PNX833X_PIC_IRQ_BASE;
  157. raw_spin_lock_irqsave(&pnx833x_irq_lock, flags);
  158. pnx833x_hard_enable_pic_irq(pic_irq);
  159. raw_spin_unlock_irqrestore(&pnx833x_irq_lock, flags);
  160. }
  161. static void pnx833x_disable_pic_irq(struct irq_data *d)
  162. {
  163. unsigned long flags;
  164. unsigned int pic_irq = d->irq - PNX833X_PIC_IRQ_BASE;
  165. raw_spin_lock_irqsave(&pnx833x_irq_lock, flags);
  166. pnx833x_hard_disable_pic_irq(pic_irq);
  167. raw_spin_unlock_irqrestore(&pnx833x_irq_lock, flags);
  168. }
  169. static DEFINE_RAW_SPINLOCK(pnx833x_gpio_pnx833x_irq_lock);
  170. static void pnx833x_enable_gpio_irq(struct irq_data *d)
  171. {
  172. int pin = d->irq - PNX833X_GPIO_IRQ_BASE;
  173. unsigned long flags;
  174. raw_spin_lock_irqsave(&pnx833x_gpio_pnx833x_irq_lock, flags);
  175. pnx833x_gpio_enable_irq(pin);
  176. raw_spin_unlock_irqrestore(&pnx833x_gpio_pnx833x_irq_lock, flags);
  177. }
  178. static void pnx833x_disable_gpio_irq(struct irq_data *d)
  179. {
  180. int pin = d->irq - PNX833X_GPIO_IRQ_BASE;
  181. unsigned long flags;
  182. raw_spin_lock_irqsave(&pnx833x_gpio_pnx833x_irq_lock, flags);
  183. pnx833x_gpio_disable_irq(pin);
  184. raw_spin_unlock_irqrestore(&pnx833x_gpio_pnx833x_irq_lock, flags);
  185. }
  186. static int pnx833x_set_type_gpio_irq(struct irq_data *d, unsigned int flow_type)
  187. {
  188. int pin = d->irq - PNX833X_GPIO_IRQ_BASE;
  189. int gpio_mode;
  190. switch (flow_type) {
  191. case IRQ_TYPE_EDGE_RISING:
  192. gpio_mode = GPIO_INT_EDGE_RISING;
  193. break;
  194. case IRQ_TYPE_EDGE_FALLING:
  195. gpio_mode = GPIO_INT_EDGE_FALLING;
  196. break;
  197. case IRQ_TYPE_EDGE_BOTH:
  198. gpio_mode = GPIO_INT_EDGE_BOTH;
  199. break;
  200. case IRQ_TYPE_LEVEL_HIGH:
  201. gpio_mode = GPIO_INT_LEVEL_HIGH;
  202. break;
  203. case IRQ_TYPE_LEVEL_LOW:
  204. gpio_mode = GPIO_INT_LEVEL_LOW;
  205. break;
  206. default:
  207. gpio_mode = GPIO_INT_NONE;
  208. break;
  209. }
  210. pnx833x_gpio_setup_irq(gpio_mode, pin);
  211. return 0;
  212. }
  213. static struct irq_chip pnx833x_pic_irq_type = {
  214. .name = "PNX-PIC",
  215. .irq_enable = pnx833x_enable_pic_irq,
  216. .irq_disable = pnx833x_disable_pic_irq,
  217. };
  218. static struct irq_chip pnx833x_gpio_irq_type = {
  219. .name = "PNX-GPIO",
  220. .irq_enable = pnx833x_enable_gpio_irq,
  221. .irq_disable = pnx833x_disable_gpio_irq,
  222. .irq_set_type = pnx833x_set_type_gpio_irq,
  223. };
  224. void __init arch_init_irq(void)
  225. {
  226. unsigned int irq;
  227. /* setup standard internal cpu irqs */
  228. mips_cpu_irq_init();
  229. /* Set IRQ information in irq_desc */
  230. for (irq = PNX833X_PIC_IRQ_BASE; irq < (PNX833X_PIC_IRQ_BASE + PNX833X_PIC_NUM_IRQ); irq++) {
  231. pnx833x_hard_disable_pic_irq(irq);
  232. irq_set_chip_and_handler(irq, &pnx833x_pic_irq_type,
  233. handle_simple_irq);
  234. }
  235. for (irq = PNX833X_GPIO_IRQ_BASE; irq < (PNX833X_GPIO_IRQ_BASE + PNX833X_GPIO_NUM_IRQ); irq++)
  236. irq_set_chip_and_handler(irq, &pnx833x_gpio_irq_type,
  237. handle_simple_irq);
  238. /* Set PIC priority limiter register to 0 */
  239. PNX833X_PIC_INT_PRIORITY = 0;
  240. /* Setup GPIO IRQ dispatching */
  241. pnx833x_startup_pic_irq(PNX833X_PIC_GPIO_INT);
  242. /* Enable PIC IRQs (HWIRQ2) */
  243. if (cpu_has_vint)
  244. set_vi_handler(4, pic_dispatch);
  245. write_c0_status(read_c0_status() | IE_IRQ2);
  246. }
  247. unsigned int __cpuinit get_c0_compare_int(void)
  248. {
  249. if (cpu_has_vint)
  250. set_vi_handler(cp0_compare_irq, pnx833x_timer_dispatch);
  251. mips_cpu_timer_irq = MIPS_CPU_IRQ_BASE + cp0_compare_irq;
  252. return mips_cpu_timer_irq;
  253. }
  254. void __init plat_time_init(void)
  255. {
  256. /* calculate mips_hpt_frequency based on PNX833X_CLOCK_CPUCP_CTL reg */
  257. extern unsigned long mips_hpt_frequency;
  258. unsigned long reg = PNX833X_CLOCK_CPUCP_CTL;
  259. if (!(PNX833X_BIT(reg, CLOCK_CPUCP_CTL, EXIT_RESET))) {
  260. /* Functional clock is disabled so use crystal frequency */
  261. mips_hpt_frequency = 25;
  262. } else {
  263. #if defined(CONFIG_SOC_PNX8335)
  264. /* Functional clock is enabled, so get clock multiplier */
  265. mips_hpt_frequency = 90 + (10 * PNX8335_REGFIELD(CLOCK_PLL_CPU_CTL, FREQ));
  266. #else
  267. static const unsigned long int freq[4] = {240, 160, 120, 80};
  268. mips_hpt_frequency = freq[PNX833X_FIELD(reg, CLOCK_CPUCP_CTL, DIV_CLOCK)];
  269. #endif
  270. }
  271. printk(KERN_INFO "CPU clock is %ld MHz\n", mips_hpt_frequency);
  272. mips_hpt_frequency *= 500000;
  273. }