irq-vic.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. /*
  2. * Copyright (C) 2007 Google, Inc.
  3. * Copyright (c) 2009, Code Aurora Forum. All rights reserved.
  4. *
  5. * This software is licensed under the terms of the GNU General Public
  6. * License version 2, as published by the Free Software Foundation, and
  7. * may be copied, distributed, and modified under those terms.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. */
  15. #include <linux/init.h>
  16. #include <linux/module.h>
  17. #include <linux/sched.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/ptrace.h>
  20. #include <linux/timer.h>
  21. #include <linux/irq.h>
  22. #include <linux/io.h>
  23. #include <asm/cacheflush.h>
  24. #include <mach/hardware.h>
  25. #include <mach/msm_iomap.h>
  26. #include "smd_private.h"
  27. enum {
  28. IRQ_DEBUG_SLEEP_INT_TRIGGER = 1U << 0,
  29. IRQ_DEBUG_SLEEP_INT = 1U << 1,
  30. IRQ_DEBUG_SLEEP_ABORT = 1U << 2,
  31. IRQ_DEBUG_SLEEP = 1U << 3,
  32. IRQ_DEBUG_SLEEP_REQUEST = 1U << 4,
  33. };
  34. static int msm_irq_debug_mask;
  35. module_param_named(debug_mask, msm_irq_debug_mask, int,
  36. S_IRUGO | S_IWUSR | S_IWGRP);
  37. #define VIC_REG(off) (MSM_VIC_BASE + (off))
  38. #define VIC_INT_TO_REG_ADDR(base, irq) (base + (irq / 32) * 4)
  39. #define VIC_INT_TO_REG_INDEX(irq) ((irq >> 5) & 3)
  40. #define VIC_INT_SELECT0 VIC_REG(0x0000) /* 1: FIQ, 0: IRQ */
  41. #define VIC_INT_SELECT1 VIC_REG(0x0004) /* 1: FIQ, 0: IRQ */
  42. #define VIC_INT_SELECT2 VIC_REG(0x0008) /* 1: FIQ, 0: IRQ */
  43. #define VIC_INT_SELECT3 VIC_REG(0x000C) /* 1: FIQ, 0: IRQ */
  44. #define VIC_INT_EN0 VIC_REG(0x0010)
  45. #define VIC_INT_EN1 VIC_REG(0x0014)
  46. #define VIC_INT_EN2 VIC_REG(0x0018)
  47. #define VIC_INT_EN3 VIC_REG(0x001C)
  48. #define VIC_INT_ENCLEAR0 VIC_REG(0x0020)
  49. #define VIC_INT_ENCLEAR1 VIC_REG(0x0024)
  50. #define VIC_INT_ENCLEAR2 VIC_REG(0x0028)
  51. #define VIC_INT_ENCLEAR3 VIC_REG(0x002C)
  52. #define VIC_INT_ENSET0 VIC_REG(0x0030)
  53. #define VIC_INT_ENSET1 VIC_REG(0x0034)
  54. #define VIC_INT_ENSET2 VIC_REG(0x0038)
  55. #define VIC_INT_ENSET3 VIC_REG(0x003C)
  56. #define VIC_INT_TYPE0 VIC_REG(0x0040) /* 1: EDGE, 0: LEVEL */
  57. #define VIC_INT_TYPE1 VIC_REG(0x0044) /* 1: EDGE, 0: LEVEL */
  58. #define VIC_INT_TYPE2 VIC_REG(0x0048) /* 1: EDGE, 0: LEVEL */
  59. #define VIC_INT_TYPE3 VIC_REG(0x004C) /* 1: EDGE, 0: LEVEL */
  60. #define VIC_INT_POLARITY0 VIC_REG(0x0050) /* 1: NEG, 0: POS */
  61. #define VIC_INT_POLARITY1 VIC_REG(0x0054) /* 1: NEG, 0: POS */
  62. #define VIC_INT_POLARITY2 VIC_REG(0x0058) /* 1: NEG, 0: POS */
  63. #define VIC_INT_POLARITY3 VIC_REG(0x005C) /* 1: NEG, 0: POS */
  64. #define VIC_NO_PEND_VAL VIC_REG(0x0060)
  65. #if defined(CONFIG_ARCH_MSM_SCORPION)
  66. #define VIC_NO_PEND_VAL_FIQ VIC_REG(0x0064)
  67. #define VIC_INT_MASTEREN VIC_REG(0x0068) /* 1: IRQ, 2: FIQ */
  68. #define VIC_CONFIG VIC_REG(0x006C) /* 1: USE SC VIC */
  69. #else
  70. #define VIC_INT_MASTEREN VIC_REG(0x0064) /* 1: IRQ, 2: FIQ */
  71. #define VIC_PROTECTION VIC_REG(0x006C) /* 1: ENABLE */
  72. #define VIC_CONFIG VIC_REG(0x0068) /* 1: USE ARM1136 VIC */
  73. #endif
  74. #define VIC_IRQ_STATUS0 VIC_REG(0x0080)
  75. #define VIC_IRQ_STATUS1 VIC_REG(0x0084)
  76. #define VIC_IRQ_STATUS2 VIC_REG(0x0088)
  77. #define VIC_IRQ_STATUS3 VIC_REG(0x008C)
  78. #define VIC_FIQ_STATUS0 VIC_REG(0x0090)
  79. #define VIC_FIQ_STATUS1 VIC_REG(0x0094)
  80. #define VIC_FIQ_STATUS2 VIC_REG(0x0098)
  81. #define VIC_FIQ_STATUS3 VIC_REG(0x009C)
  82. #define VIC_RAW_STATUS0 VIC_REG(0x00A0)
  83. #define VIC_RAW_STATUS1 VIC_REG(0x00A4)
  84. #define VIC_RAW_STATUS2 VIC_REG(0x00A8)
  85. #define VIC_RAW_STATUS3 VIC_REG(0x00AC)
  86. #define VIC_INT_CLEAR0 VIC_REG(0x00B0)
  87. #define VIC_INT_CLEAR1 VIC_REG(0x00B4)
  88. #define VIC_INT_CLEAR2 VIC_REG(0x00B8)
  89. #define VIC_INT_CLEAR3 VIC_REG(0x00BC)
  90. #define VIC_SOFTINT0 VIC_REG(0x00C0)
  91. #define VIC_SOFTINT1 VIC_REG(0x00C4)
  92. #define VIC_SOFTINT2 VIC_REG(0x00C8)
  93. #define VIC_SOFTINT3 VIC_REG(0x00CC)
  94. #define VIC_IRQ_VEC_RD VIC_REG(0x00D0) /* pending int # */
  95. #define VIC_IRQ_VEC_PEND_RD VIC_REG(0x00D4) /* pending vector addr */
  96. #define VIC_IRQ_VEC_WR VIC_REG(0x00D8)
  97. #if defined(CONFIG_ARCH_MSM_SCORPION)
  98. #define VIC_FIQ_VEC_RD VIC_REG(0x00DC)
  99. #define VIC_FIQ_VEC_PEND_RD VIC_REG(0x00E0)
  100. #define VIC_FIQ_VEC_WR VIC_REG(0x00E4)
  101. #define VIC_IRQ_IN_SERVICE VIC_REG(0x00E8)
  102. #define VIC_IRQ_IN_STACK VIC_REG(0x00EC)
  103. #define VIC_FIQ_IN_SERVICE VIC_REG(0x00F0)
  104. #define VIC_FIQ_IN_STACK VIC_REG(0x00F4)
  105. #define VIC_TEST_BUS_SEL VIC_REG(0x00F8)
  106. #define VIC_IRQ_CTRL_CONFIG VIC_REG(0x00FC)
  107. #else
  108. #define VIC_IRQ_IN_SERVICE VIC_REG(0x00E0)
  109. #define VIC_IRQ_IN_STACK VIC_REG(0x00E4)
  110. #define VIC_TEST_BUS_SEL VIC_REG(0x00E8)
  111. #endif
  112. #define VIC_VECTPRIORITY(n) VIC_REG(0x0200+((n) * 4))
  113. #define VIC_VECTADDR(n) VIC_REG(0x0400+((n) * 4))
  114. #if defined(CONFIG_ARCH_MSM7X30)
  115. #define VIC_NUM_REGS 4
  116. #else
  117. #define VIC_NUM_REGS 2
  118. #endif
  119. #if VIC_NUM_REGS == 2
  120. #define DPRINT_REGS(base_reg, format, ...) \
  121. printk(KERN_INFO format " %x %x\n", ##__VA_ARGS__, \
  122. readl(base_reg ## 0), readl(base_reg ## 1))
  123. #define DPRINT_ARRAY(array, format, ...) \
  124. printk(KERN_INFO format " %x %x\n", ##__VA_ARGS__, \
  125. array[0], array[1])
  126. #elif VIC_NUM_REGS == 4
  127. #define DPRINT_REGS(base_reg, format, ...) \
  128. printk(KERN_INFO format " %x %x %x %x\n", ##__VA_ARGS__, \
  129. readl(base_reg ## 0), readl(base_reg ## 1), \
  130. readl(base_reg ## 2), readl(base_reg ## 3))
  131. #define DPRINT_ARRAY(array, format, ...) \
  132. printk(KERN_INFO format " %x %x %x %x\n", ##__VA_ARGS__, \
  133. array[0], array[1], \
  134. array[2], array[3])
  135. #else
  136. #error "VIC_NUM_REGS set to illegal value"
  137. #endif
  138. static uint32_t msm_irq_smsm_wake_enable[2];
  139. static struct {
  140. uint32_t int_en[2];
  141. uint32_t int_type;
  142. uint32_t int_polarity;
  143. uint32_t int_select;
  144. } msm_irq_shadow_reg[VIC_NUM_REGS];
  145. static uint32_t msm_irq_idle_disable[VIC_NUM_REGS];
  146. #define SMSM_FAKE_IRQ (0xff)
  147. static uint8_t msm_irq_to_smsm[NR_IRQS] = {
  148. [INT_MDDI_EXT] = 1,
  149. [INT_MDDI_PRI] = 2,
  150. [INT_MDDI_CLIENT] = 3,
  151. [INT_USB_OTG] = 4,
  152. [INT_PWB_I2C] = 5,
  153. [INT_SDC1_0] = 6,
  154. [INT_SDC1_1] = 7,
  155. [INT_SDC2_0] = 8,
  156. [INT_SDC2_1] = 9,
  157. [INT_ADSP_A9_A11] = 10,
  158. [INT_UART1] = 11,
  159. [INT_UART2] = 12,
  160. [INT_UART3] = 13,
  161. [INT_UART1_RX] = 14,
  162. [INT_UART2_RX] = 15,
  163. [INT_UART3_RX] = 16,
  164. [INT_UART1DM_IRQ] = 17,
  165. [INT_UART1DM_RX] = 18,
  166. [INT_KEYSENSE] = 19,
  167. #if !defined(CONFIG_ARCH_MSM7X30)
  168. [INT_AD_HSSD] = 20,
  169. #endif
  170. [INT_NAND_WR_ER_DONE] = 21,
  171. [INT_NAND_OP_DONE] = 22,
  172. [INT_TCHSCRN1] = 23,
  173. [INT_TCHSCRN2] = 24,
  174. [INT_TCHSCRN_SSBI] = 25,
  175. [INT_USB_HS] = 26,
  176. [INT_UART2DM_RX] = 27,
  177. [INT_UART2DM_IRQ] = 28,
  178. [INT_SDC4_1] = 29,
  179. [INT_SDC4_0] = 30,
  180. [INT_SDC3_1] = 31,
  181. [INT_SDC3_0] = 32,
  182. /* fake wakeup interrupts */
  183. [INT_GPIO_GROUP1] = SMSM_FAKE_IRQ,
  184. [INT_GPIO_GROUP2] = SMSM_FAKE_IRQ,
  185. [INT_A9_M2A_0] = SMSM_FAKE_IRQ,
  186. [INT_A9_M2A_1] = SMSM_FAKE_IRQ,
  187. [INT_A9_M2A_5] = SMSM_FAKE_IRQ,
  188. [INT_GP_TIMER_EXP] = SMSM_FAKE_IRQ,
  189. [INT_DEBUG_TIMER_EXP] = SMSM_FAKE_IRQ,
  190. [INT_ADSP_A11] = SMSM_FAKE_IRQ,
  191. #ifdef CONFIG_ARCH_QSD8X50
  192. [INT_SIRC_0] = SMSM_FAKE_IRQ,
  193. [INT_SIRC_1] = SMSM_FAKE_IRQ,
  194. #endif
  195. };
  196. static inline void msm_irq_write_all_regs(void __iomem *base, unsigned int val)
  197. {
  198. int i;
  199. for (i = 0; i < VIC_NUM_REGS; i++)
  200. writel(val, base + (i * 4));
  201. }
  202. static void msm_irq_ack(unsigned int irq)
  203. {
  204. void __iomem *reg = VIC_INT_TO_REG_ADDR(VIC_INT_CLEAR0, irq);
  205. irq = 1 << (irq & 31);
  206. writel(irq, reg);
  207. }
  208. static void msm_irq_mask(unsigned int irq)
  209. {
  210. void __iomem *reg = VIC_INT_TO_REG_ADDR(VIC_INT_ENCLEAR0, irq);
  211. unsigned index = VIC_INT_TO_REG_INDEX(irq);
  212. uint32_t mask = 1UL << (irq & 31);
  213. int smsm_irq = msm_irq_to_smsm[irq];
  214. msm_irq_shadow_reg[index].int_en[0] &= ~mask;
  215. writel(mask, reg);
  216. if (smsm_irq == 0)
  217. msm_irq_idle_disable[index] &= ~mask;
  218. else {
  219. mask = 1UL << (smsm_irq - 1);
  220. msm_irq_smsm_wake_enable[0] &= ~mask;
  221. }
  222. }
  223. static void msm_irq_unmask(unsigned int irq)
  224. {
  225. void __iomem *reg = VIC_INT_TO_REG_ADDR(VIC_INT_ENSET0, irq);
  226. unsigned index = VIC_INT_TO_REG_INDEX(irq);
  227. uint32_t mask = 1UL << (irq & 31);
  228. int smsm_irq = msm_irq_to_smsm[irq];
  229. msm_irq_shadow_reg[index].int_en[0] |= mask;
  230. writel(mask, reg);
  231. if (smsm_irq == 0)
  232. msm_irq_idle_disable[index] |= mask;
  233. else {
  234. mask = 1UL << (smsm_irq - 1);
  235. msm_irq_smsm_wake_enable[0] |= mask;
  236. }
  237. }
  238. static int msm_irq_set_wake(unsigned int irq, unsigned int on)
  239. {
  240. unsigned index = VIC_INT_TO_REG_INDEX(irq);
  241. uint32_t mask = 1UL << (irq & 31);
  242. int smsm_irq = msm_irq_to_smsm[irq];
  243. if (smsm_irq == 0) {
  244. printk(KERN_ERR "msm_irq_set_wake: bad wakeup irq %d\n", irq);
  245. return -EINVAL;
  246. }
  247. if (on)
  248. msm_irq_shadow_reg[index].int_en[1] |= mask;
  249. else
  250. msm_irq_shadow_reg[index].int_en[1] &= ~mask;
  251. if (smsm_irq == SMSM_FAKE_IRQ)
  252. return 0;
  253. mask = 1UL << (smsm_irq - 1);
  254. if (on)
  255. msm_irq_smsm_wake_enable[1] |= mask;
  256. else
  257. msm_irq_smsm_wake_enable[1] &= ~mask;
  258. return 0;
  259. }
  260. static int msm_irq_set_type(unsigned int irq, unsigned int flow_type)
  261. {
  262. void __iomem *treg = VIC_INT_TO_REG_ADDR(VIC_INT_TYPE0, irq);
  263. void __iomem *preg = VIC_INT_TO_REG_ADDR(VIC_INT_POLARITY0, irq);
  264. unsigned index = VIC_INT_TO_REG_INDEX(irq);
  265. int b = 1 << (irq & 31);
  266. uint32_t polarity;
  267. uint32_t type;
  268. polarity = msm_irq_shadow_reg[index].int_polarity;
  269. if (flow_type & (IRQF_TRIGGER_FALLING | IRQF_TRIGGER_LOW))
  270. polarity |= b;
  271. if (flow_type & (IRQF_TRIGGER_RISING | IRQF_TRIGGER_HIGH))
  272. polarity &= ~b;
  273. writel(polarity, preg);
  274. msm_irq_shadow_reg[index].int_polarity = polarity;
  275. type = msm_irq_shadow_reg[index].int_type;
  276. if (flow_type & (IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING)) {
  277. type |= b;
  278. irq_desc[irq].handle_irq = handle_edge_irq;
  279. }
  280. if (flow_type & (IRQF_TRIGGER_HIGH | IRQF_TRIGGER_LOW)) {
  281. type &= ~b;
  282. irq_desc[irq].handle_irq = handle_level_irq;
  283. }
  284. writel(type, treg);
  285. msm_irq_shadow_reg[index].int_type = type;
  286. return 0;
  287. }
  288. static struct irq_chip msm_irq_chip = {
  289. .name = "msm",
  290. .disable = msm_irq_mask,
  291. .ack = msm_irq_ack,
  292. .mask = msm_irq_mask,
  293. .unmask = msm_irq_unmask,
  294. .set_wake = msm_irq_set_wake,
  295. .set_type = msm_irq_set_type,
  296. };
  297. void __init msm_init_irq(void)
  298. {
  299. unsigned n;
  300. /* select level interrupts */
  301. msm_irq_write_all_regs(VIC_INT_TYPE0, 0);
  302. /* select highlevel interrupts */
  303. msm_irq_write_all_regs(VIC_INT_POLARITY0, 0);
  304. /* select IRQ for all INTs */
  305. msm_irq_write_all_regs(VIC_INT_SELECT0, 0);
  306. /* disable all INTs */
  307. msm_irq_write_all_regs(VIC_INT_EN0, 0);
  308. /* don't use vic */
  309. writel(0, VIC_CONFIG);
  310. /* enable interrupt controller */
  311. writel(3, VIC_INT_MASTEREN);
  312. for (n = 0; n < NR_MSM_IRQS; n++) {
  313. set_irq_chip(n, &msm_irq_chip);
  314. set_irq_handler(n, handle_level_irq);
  315. set_irq_flags(n, IRQF_VALID);
  316. }
  317. }