wm831x-irq.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. /*
  2. * wm831x-irq.c -- Interrupt controller support for Wolfson WM831x PMICs
  3. *
  4. * Copyright 2009 Wolfson Microelectronics PLC.
  5. *
  6. * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. *
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/module.h>
  16. #include <linux/i2c.h>
  17. #include <linux/irq.h>
  18. #include <linux/mfd/core.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/mfd/wm831x/core.h>
  21. #include <linux/mfd/wm831x/pdata.h>
  22. #include <linux/mfd/wm831x/gpio.h>
  23. #include <linux/mfd/wm831x/irq.h>
  24. #include <linux/delay.h>
  25. struct wm831x_irq_data {
  26. int primary;
  27. int reg;
  28. int mask;
  29. };
  30. static struct wm831x_irq_data wm831x_irqs[] = {
  31. [WM831X_IRQ_TEMP_THW] = {
  32. .primary = WM831X_TEMP_INT,
  33. .reg = 1,
  34. .mask = WM831X_TEMP_THW_EINT,
  35. },
  36. [WM831X_IRQ_GPIO_1] = {
  37. .primary = WM831X_GP_INT,
  38. .reg = 5,
  39. .mask = WM831X_GP1_EINT,
  40. },
  41. [WM831X_IRQ_GPIO_2] = {
  42. .primary = WM831X_GP_INT,
  43. .reg = 5,
  44. .mask = WM831X_GP2_EINT,
  45. },
  46. [WM831X_IRQ_GPIO_3] = {
  47. .primary = WM831X_GP_INT,
  48. .reg = 5,
  49. .mask = WM831X_GP3_EINT,
  50. },
  51. [WM831X_IRQ_GPIO_4] = {
  52. .primary = WM831X_GP_INT,
  53. .reg = 5,
  54. .mask = WM831X_GP4_EINT,
  55. },
  56. [WM831X_IRQ_GPIO_5] = {
  57. .primary = WM831X_GP_INT,
  58. .reg = 5,
  59. .mask = WM831X_GP5_EINT,
  60. },
  61. [WM831X_IRQ_GPIO_6] = {
  62. .primary = WM831X_GP_INT,
  63. .reg = 5,
  64. .mask = WM831X_GP6_EINT,
  65. },
  66. [WM831X_IRQ_GPIO_7] = {
  67. .primary = WM831X_GP_INT,
  68. .reg = 5,
  69. .mask = WM831X_GP7_EINT,
  70. },
  71. [WM831X_IRQ_GPIO_8] = {
  72. .primary = WM831X_GP_INT,
  73. .reg = 5,
  74. .mask = WM831X_GP8_EINT,
  75. },
  76. [WM831X_IRQ_GPIO_9] = {
  77. .primary = WM831X_GP_INT,
  78. .reg = 5,
  79. .mask = WM831X_GP9_EINT,
  80. },
  81. [WM831X_IRQ_GPIO_10] = {
  82. .primary = WM831X_GP_INT,
  83. .reg = 5,
  84. .mask = WM831X_GP10_EINT,
  85. },
  86. [WM831X_IRQ_GPIO_11] = {
  87. .primary = WM831X_GP_INT,
  88. .reg = 5,
  89. .mask = WM831X_GP11_EINT,
  90. },
  91. [WM831X_IRQ_GPIO_12] = {
  92. .primary = WM831X_GP_INT,
  93. .reg = 5,
  94. .mask = WM831X_GP12_EINT,
  95. },
  96. [WM831X_IRQ_GPIO_13] = {
  97. .primary = WM831X_GP_INT,
  98. .reg = 5,
  99. .mask = WM831X_GP13_EINT,
  100. },
  101. [WM831X_IRQ_GPIO_14] = {
  102. .primary = WM831X_GP_INT,
  103. .reg = 5,
  104. .mask = WM831X_GP14_EINT,
  105. },
  106. [WM831X_IRQ_GPIO_15] = {
  107. .primary = WM831X_GP_INT,
  108. .reg = 5,
  109. .mask = WM831X_GP15_EINT,
  110. },
  111. [WM831X_IRQ_GPIO_16] = {
  112. .primary = WM831X_GP_INT,
  113. .reg = 5,
  114. .mask = WM831X_GP16_EINT,
  115. },
  116. [WM831X_IRQ_ON] = {
  117. .primary = WM831X_ON_PIN_INT,
  118. .reg = 1,
  119. .mask = WM831X_ON_PIN_EINT,
  120. },
  121. [WM831X_IRQ_PPM_SYSLO] = {
  122. .primary = WM831X_PPM_INT,
  123. .reg = 1,
  124. .mask = WM831X_PPM_SYSLO_EINT,
  125. },
  126. [WM831X_IRQ_PPM_PWR_SRC] = {
  127. .primary = WM831X_PPM_INT,
  128. .reg = 1,
  129. .mask = WM831X_PPM_PWR_SRC_EINT,
  130. },
  131. [WM831X_IRQ_PPM_USB_CURR] = {
  132. .primary = WM831X_PPM_INT,
  133. .reg = 1,
  134. .mask = WM831X_PPM_USB_CURR_EINT,
  135. },
  136. [WM831X_IRQ_WDOG_TO] = {
  137. .primary = WM831X_WDOG_INT,
  138. .reg = 1,
  139. .mask = WM831X_WDOG_TO_EINT,
  140. },
  141. [WM831X_IRQ_RTC_PER] = {
  142. .primary = WM831X_RTC_INT,
  143. .reg = 1,
  144. .mask = WM831X_RTC_PER_EINT,
  145. },
  146. [WM831X_IRQ_RTC_ALM] = {
  147. .primary = WM831X_RTC_INT,
  148. .reg = 1,
  149. .mask = WM831X_RTC_ALM_EINT,
  150. },
  151. [WM831X_IRQ_CHG_BATT_HOT] = {
  152. .primary = WM831X_CHG_INT,
  153. .reg = 2,
  154. .mask = WM831X_CHG_BATT_HOT_EINT,
  155. },
  156. [WM831X_IRQ_CHG_BATT_COLD] = {
  157. .primary = WM831X_CHG_INT,
  158. .reg = 2,
  159. .mask = WM831X_CHG_BATT_COLD_EINT,
  160. },
  161. [WM831X_IRQ_CHG_BATT_FAIL] = {
  162. .primary = WM831X_CHG_INT,
  163. .reg = 2,
  164. .mask = WM831X_CHG_BATT_FAIL_EINT,
  165. },
  166. [WM831X_IRQ_CHG_OV] = {
  167. .primary = WM831X_CHG_INT,
  168. .reg = 2,
  169. .mask = WM831X_CHG_OV_EINT,
  170. },
  171. [WM831X_IRQ_CHG_END] = {
  172. .primary = WM831X_CHG_INT,
  173. .reg = 2,
  174. .mask = WM831X_CHG_END_EINT,
  175. },
  176. [WM831X_IRQ_CHG_TO] = {
  177. .primary = WM831X_CHG_INT,
  178. .reg = 2,
  179. .mask = WM831X_CHG_TO_EINT,
  180. },
  181. [WM831X_IRQ_CHG_MODE] = {
  182. .primary = WM831X_CHG_INT,
  183. .reg = 2,
  184. .mask = WM831X_CHG_MODE_EINT,
  185. },
  186. [WM831X_IRQ_CHG_START] = {
  187. .primary = WM831X_CHG_INT,
  188. .reg = 2,
  189. .mask = WM831X_CHG_START_EINT,
  190. },
  191. [WM831X_IRQ_TCHDATA] = {
  192. .primary = WM831X_TCHDATA_INT,
  193. .reg = 1,
  194. .mask = WM831X_TCHDATA_EINT,
  195. },
  196. [WM831X_IRQ_TCHPD] = {
  197. .primary = WM831X_TCHPD_INT,
  198. .reg = 1,
  199. .mask = WM831X_TCHPD_EINT,
  200. },
  201. [WM831X_IRQ_AUXADC_DATA] = {
  202. .primary = WM831X_AUXADC_INT,
  203. .reg = 1,
  204. .mask = WM831X_AUXADC_DATA_EINT,
  205. },
  206. [WM831X_IRQ_AUXADC_DCOMP1] = {
  207. .primary = WM831X_AUXADC_INT,
  208. .reg = 1,
  209. .mask = WM831X_AUXADC_DCOMP1_EINT,
  210. },
  211. [WM831X_IRQ_AUXADC_DCOMP2] = {
  212. .primary = WM831X_AUXADC_INT,
  213. .reg = 1,
  214. .mask = WM831X_AUXADC_DCOMP2_EINT,
  215. },
  216. [WM831X_IRQ_AUXADC_DCOMP3] = {
  217. .primary = WM831X_AUXADC_INT,
  218. .reg = 1,
  219. .mask = WM831X_AUXADC_DCOMP3_EINT,
  220. },
  221. [WM831X_IRQ_AUXADC_DCOMP4] = {
  222. .primary = WM831X_AUXADC_INT,
  223. .reg = 1,
  224. .mask = WM831X_AUXADC_DCOMP4_EINT,
  225. },
  226. [WM831X_IRQ_CS1] = {
  227. .primary = WM831X_CS_INT,
  228. .reg = 2,
  229. .mask = WM831X_CS1_EINT,
  230. },
  231. [WM831X_IRQ_CS2] = {
  232. .primary = WM831X_CS_INT,
  233. .reg = 2,
  234. .mask = WM831X_CS2_EINT,
  235. },
  236. [WM831X_IRQ_HC_DC1] = {
  237. .primary = WM831X_HC_INT,
  238. .reg = 4,
  239. .mask = WM831X_HC_DC1_EINT,
  240. },
  241. [WM831X_IRQ_HC_DC2] = {
  242. .primary = WM831X_HC_INT,
  243. .reg = 4,
  244. .mask = WM831X_HC_DC2_EINT,
  245. },
  246. [WM831X_IRQ_UV_LDO1] = {
  247. .primary = WM831X_UV_INT,
  248. .reg = 3,
  249. .mask = WM831X_UV_LDO1_EINT,
  250. },
  251. [WM831X_IRQ_UV_LDO2] = {
  252. .primary = WM831X_UV_INT,
  253. .reg = 3,
  254. .mask = WM831X_UV_LDO2_EINT,
  255. },
  256. [WM831X_IRQ_UV_LDO3] = {
  257. .primary = WM831X_UV_INT,
  258. .reg = 3,
  259. .mask = WM831X_UV_LDO3_EINT,
  260. },
  261. [WM831X_IRQ_UV_LDO4] = {
  262. .primary = WM831X_UV_INT,
  263. .reg = 3,
  264. .mask = WM831X_UV_LDO4_EINT,
  265. },
  266. [WM831X_IRQ_UV_LDO5] = {
  267. .primary = WM831X_UV_INT,
  268. .reg = 3,
  269. .mask = WM831X_UV_LDO5_EINT,
  270. },
  271. [WM831X_IRQ_UV_LDO6] = {
  272. .primary = WM831X_UV_INT,
  273. .reg = 3,
  274. .mask = WM831X_UV_LDO6_EINT,
  275. },
  276. [WM831X_IRQ_UV_LDO7] = {
  277. .primary = WM831X_UV_INT,
  278. .reg = 3,
  279. .mask = WM831X_UV_LDO7_EINT,
  280. },
  281. [WM831X_IRQ_UV_LDO8] = {
  282. .primary = WM831X_UV_INT,
  283. .reg = 3,
  284. .mask = WM831X_UV_LDO8_EINT,
  285. },
  286. [WM831X_IRQ_UV_LDO9] = {
  287. .primary = WM831X_UV_INT,
  288. .reg = 3,
  289. .mask = WM831X_UV_LDO9_EINT,
  290. },
  291. [WM831X_IRQ_UV_LDO10] = {
  292. .primary = WM831X_UV_INT,
  293. .reg = 3,
  294. .mask = WM831X_UV_LDO10_EINT,
  295. },
  296. [WM831X_IRQ_UV_DC1] = {
  297. .primary = WM831X_UV_INT,
  298. .reg = 4,
  299. .mask = WM831X_UV_DC1_EINT,
  300. },
  301. [WM831X_IRQ_UV_DC2] = {
  302. .primary = WM831X_UV_INT,
  303. .reg = 4,
  304. .mask = WM831X_UV_DC2_EINT,
  305. },
  306. [WM831X_IRQ_UV_DC3] = {
  307. .primary = WM831X_UV_INT,
  308. .reg = 4,
  309. .mask = WM831X_UV_DC3_EINT,
  310. },
  311. [WM831X_IRQ_UV_DC4] = {
  312. .primary = WM831X_UV_INT,
  313. .reg = 4,
  314. .mask = WM831X_UV_DC4_EINT,
  315. },
  316. };
  317. static inline int irq_data_to_status_reg(struct wm831x_irq_data *irq_data)
  318. {
  319. return WM831X_INTERRUPT_STATUS_1 - 1 + irq_data->reg;
  320. }
  321. static inline struct wm831x_irq_data *irq_to_wm831x_irq(struct wm831x *wm831x,
  322. int irq)
  323. {
  324. return &wm831x_irqs[irq - wm831x->irq_base];
  325. }
  326. static void wm831x_irq_lock(struct irq_data *data)
  327. {
  328. struct wm831x *wm831x = irq_data_get_irq_chip_data(data);
  329. mutex_lock(&wm831x->irq_lock);
  330. }
  331. static void wm831x_irq_sync_unlock(struct irq_data *data)
  332. {
  333. struct wm831x *wm831x = irq_data_get_irq_chip_data(data);
  334. int i;
  335. for (i = 0; i < ARRAY_SIZE(wm831x->gpio_update); i++) {
  336. if (wm831x->gpio_update[i]) {
  337. wm831x_set_bits(wm831x, WM831X_GPIO1_CONTROL + i,
  338. WM831X_GPN_INT_MODE | WM831X_GPN_POL,
  339. wm831x->gpio_update[i]);
  340. wm831x->gpio_update[i] = 0;
  341. }
  342. }
  343. for (i = 0; i < ARRAY_SIZE(wm831x->irq_masks_cur); i++) {
  344. /* If there's been a change in the mask write it back
  345. * to the hardware. */
  346. if (wm831x->irq_masks_cur[i] != wm831x->irq_masks_cache[i]) {
  347. dev_dbg(wm831x->dev, "IRQ mask sync: %x = %x\n",
  348. WM831X_INTERRUPT_STATUS_1_MASK + i,
  349. wm831x->irq_masks_cur[i]);
  350. wm831x->irq_masks_cache[i] = wm831x->irq_masks_cur[i];
  351. wm831x_reg_write(wm831x,
  352. WM831X_INTERRUPT_STATUS_1_MASK + i,
  353. wm831x->irq_masks_cur[i]);
  354. }
  355. }
  356. mutex_unlock(&wm831x->irq_lock);
  357. }
  358. static void wm831x_irq_enable(struct irq_data *data)
  359. {
  360. struct wm831x *wm831x = irq_data_get_irq_chip_data(data);
  361. struct wm831x_irq_data *irq_data = irq_to_wm831x_irq(wm831x,
  362. data->irq);
  363. wm831x->irq_masks_cur[irq_data->reg - 1] &= ~irq_data->mask;
  364. }
  365. static void wm831x_irq_disable(struct irq_data *data)
  366. {
  367. struct wm831x *wm831x = irq_data_get_irq_chip_data(data);
  368. struct wm831x_irq_data *irq_data = irq_to_wm831x_irq(wm831x,
  369. data->irq);
  370. wm831x->irq_masks_cur[irq_data->reg - 1] |= irq_data->mask;
  371. }
  372. static int wm831x_irq_set_type(struct irq_data *data, unsigned int type)
  373. {
  374. struct wm831x *wm831x = irq_data_get_irq_chip_data(data);
  375. int irq;
  376. irq = data->irq - wm831x->irq_base;
  377. if (irq < WM831X_IRQ_GPIO_1 || irq > WM831X_IRQ_GPIO_11) {
  378. /* Ignore internal-only IRQs */
  379. if (irq >= 0 && irq < WM831X_NUM_IRQS)
  380. return 0;
  381. else
  382. return -EINVAL;
  383. }
  384. /* Rebase the IRQ into the GPIO range so we've got a sensible array
  385. * index.
  386. */
  387. irq -= WM831X_IRQ_GPIO_1;
  388. /* We set the high bit to flag that we need an update; don't
  389. * do the update here as we can be called with the bus lock
  390. * held.
  391. */
  392. switch (type) {
  393. case IRQ_TYPE_EDGE_BOTH:
  394. wm831x->gpio_update[irq] = 0x10000 | WM831X_GPN_INT_MODE;
  395. wm831x->gpio_level[irq] = false;
  396. break;
  397. case IRQ_TYPE_EDGE_RISING:
  398. wm831x->gpio_update[irq] = 0x10000 | WM831X_GPN_POL;
  399. wm831x->gpio_level[irq] = false;
  400. break;
  401. case IRQ_TYPE_EDGE_FALLING:
  402. wm831x->gpio_update[irq] = 0x10000;
  403. wm831x->gpio_level[irq] = false;
  404. break;
  405. case IRQ_TYPE_LEVEL_HIGH:
  406. wm831x->gpio_update[irq] = 0x10000 | WM831X_GPN_POL;
  407. wm831x->gpio_level[irq] = true;
  408. break;
  409. default:
  410. return -EINVAL;
  411. }
  412. return 0;
  413. }
  414. static struct irq_chip wm831x_irq_chip = {
  415. .name = "wm831x",
  416. .irq_bus_lock = wm831x_irq_lock,
  417. .irq_bus_sync_unlock = wm831x_irq_sync_unlock,
  418. .irq_disable = wm831x_irq_disable,
  419. .irq_enable = wm831x_irq_enable,
  420. .irq_set_type = wm831x_irq_set_type,
  421. };
  422. /* The processing of the primary interrupt occurs in a thread so that
  423. * we can interact with the device over I2C or SPI. */
  424. static irqreturn_t wm831x_irq_thread(int irq, void *data)
  425. {
  426. struct wm831x *wm831x = data;
  427. unsigned int i;
  428. int primary, status_addr, ret;
  429. int status_regs[WM831X_NUM_IRQ_REGS] = { 0 };
  430. int read[WM831X_NUM_IRQ_REGS] = { 0 };
  431. int *status;
  432. primary = wm831x_reg_read(wm831x, WM831X_SYSTEM_INTERRUPTS);
  433. if (primary < 0) {
  434. dev_err(wm831x->dev, "Failed to read system interrupt: %d\n",
  435. primary);
  436. goto out;
  437. }
  438. /* The touch interrupts are visible in the primary register as
  439. * an optimisation; open code this to avoid complicating the
  440. * main handling loop and so we can also skip iterating the
  441. * descriptors.
  442. */
  443. if (primary & WM831X_TCHPD_INT)
  444. handle_nested_irq(wm831x->irq_base + WM831X_IRQ_TCHPD);
  445. if (primary & WM831X_TCHDATA_INT)
  446. handle_nested_irq(wm831x->irq_base + WM831X_IRQ_TCHDATA);
  447. primary &= ~(WM831X_TCHDATA_EINT | WM831X_TCHPD_EINT);
  448. for (i = 0; i < ARRAY_SIZE(wm831x_irqs); i++) {
  449. int offset = wm831x_irqs[i].reg - 1;
  450. if (!(primary & wm831x_irqs[i].primary))
  451. continue;
  452. status = &status_regs[offset];
  453. /* Hopefully there should only be one register to read
  454. * each time otherwise we ought to do a block read. */
  455. if (!read[offset]) {
  456. status_addr = irq_data_to_status_reg(&wm831x_irqs[i]);
  457. *status = wm831x_reg_read(wm831x, status_addr);
  458. if (*status < 0) {
  459. dev_err(wm831x->dev,
  460. "Failed to read IRQ status: %d\n",
  461. *status);
  462. goto out;
  463. }
  464. read[offset] = 1;
  465. /* Ignore any bits that we don't think are masked */
  466. *status &= ~wm831x->irq_masks_cur[offset];
  467. /* Acknowledge now so we don't miss
  468. * notifications while we handle.
  469. */
  470. wm831x_reg_write(wm831x, status_addr, *status);
  471. }
  472. if (*status & wm831x_irqs[i].mask)
  473. handle_nested_irq(wm831x->irq_base + i);
  474. /* Simulate an edge triggered IRQ by polling the input
  475. * status. This is sucky but improves interoperability.
  476. */
  477. if (primary == WM831X_GP_INT &&
  478. wm831x->gpio_level[i - WM831X_IRQ_GPIO_1]) {
  479. ret = wm831x_reg_read(wm831x, WM831X_GPIO_LEVEL);
  480. while (ret & 1 << (i - WM831X_IRQ_GPIO_1)) {
  481. handle_nested_irq(wm831x->irq_base + i);
  482. ret = wm831x_reg_read(wm831x,
  483. WM831X_GPIO_LEVEL);
  484. }
  485. }
  486. }
  487. out:
  488. return IRQ_HANDLED;
  489. }
  490. int wm831x_irq_init(struct wm831x *wm831x, int irq)
  491. {
  492. struct wm831x_pdata *pdata = wm831x->dev->platform_data;
  493. int i, cur_irq, ret;
  494. mutex_init(&wm831x->irq_lock);
  495. /* Mask the individual interrupt sources */
  496. for (i = 0; i < ARRAY_SIZE(wm831x->irq_masks_cur); i++) {
  497. wm831x->irq_masks_cur[i] = 0xffff;
  498. wm831x->irq_masks_cache[i] = 0xffff;
  499. wm831x_reg_write(wm831x, WM831X_INTERRUPT_STATUS_1_MASK + i,
  500. 0xffff);
  501. }
  502. /* Try to dynamically allocate IRQs if no base is specified */
  503. if (!pdata || !pdata->irq_base)
  504. wm831x->irq_base = -1;
  505. else
  506. wm831x->irq_base = pdata->irq_base;
  507. wm831x->irq_base = irq_alloc_descs(wm831x->irq_base, 0,
  508. WM831X_NUM_IRQS, 0);
  509. if (wm831x->irq_base < 0) {
  510. dev_warn(wm831x->dev, "Failed to allocate IRQs: %d\n",
  511. wm831x->irq_base);
  512. wm831x->irq_base = 0;
  513. return 0;
  514. }
  515. if (pdata && pdata->irq_cmos)
  516. i = 0;
  517. else
  518. i = WM831X_IRQ_OD;
  519. wm831x_set_bits(wm831x, WM831X_IRQ_CONFIG,
  520. WM831X_IRQ_OD, i);
  521. /* Try to flag /IRQ as a wake source; there are a number of
  522. * unconditional wake sources in the PMIC so this isn't
  523. * conditional but we don't actually care *too* much if it
  524. * fails.
  525. */
  526. ret = enable_irq_wake(irq);
  527. if (ret != 0) {
  528. dev_warn(wm831x->dev, "Can't enable IRQ as wake source: %d\n",
  529. ret);
  530. }
  531. wm831x->irq = irq;
  532. /* Register them with genirq */
  533. for (cur_irq = wm831x->irq_base;
  534. cur_irq < ARRAY_SIZE(wm831x_irqs) + wm831x->irq_base;
  535. cur_irq++) {
  536. irq_set_chip_data(cur_irq, wm831x);
  537. irq_set_chip_and_handler(cur_irq, &wm831x_irq_chip,
  538. handle_edge_irq);
  539. irq_set_nested_thread(cur_irq, 1);
  540. /* ARM needs us to explicitly flag the IRQ as valid
  541. * and will set them noprobe when we do so. */
  542. #ifdef CONFIG_ARM
  543. set_irq_flags(cur_irq, IRQF_VALID);
  544. #else
  545. irq_set_noprobe(cur_irq);
  546. #endif
  547. }
  548. if (irq) {
  549. ret = request_threaded_irq(irq, NULL, wm831x_irq_thread,
  550. IRQF_TRIGGER_LOW | IRQF_ONESHOT,
  551. "wm831x", wm831x);
  552. if (ret != 0) {
  553. dev_err(wm831x->dev, "Failed to request IRQ %d: %d\n",
  554. irq, ret);
  555. return ret;
  556. }
  557. } else {
  558. dev_warn(wm831x->dev,
  559. "No interrupt specified - functionality limited\n");
  560. }
  561. /* Enable top level interrupts, we mask at secondary level */
  562. wm831x_reg_write(wm831x, WM831X_SYSTEM_INTERRUPTS_MASK, 0);
  563. return 0;
  564. }
  565. void wm831x_irq_exit(struct wm831x *wm831x)
  566. {
  567. if (wm831x->irq)
  568. free_irq(wm831x->irq, wm831x);
  569. }