wm8350-irq.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. /*
  2. * wm8350-irq.c -- IRQ support for Wolfson WM8350
  3. *
  4. * Copyright 2007, 2008, 2009 Wolfson Microelectronics PLC.
  5. *
  6. * Author: Liam Girdwood, Mark Brown
  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/bug.h>
  17. #include <linux/device.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/irq.h>
  20. #include <linux/mfd/wm8350/core.h>
  21. #include <linux/mfd/wm8350/audio.h>
  22. #include <linux/mfd/wm8350/comparator.h>
  23. #include <linux/mfd/wm8350/gpio.h>
  24. #include <linux/mfd/wm8350/pmic.h>
  25. #include <linux/mfd/wm8350/rtc.h>
  26. #include <linux/mfd/wm8350/supply.h>
  27. #include <linux/mfd/wm8350/wdt.h>
  28. #define WM8350_INT_OFFSET_1 0
  29. #define WM8350_INT_OFFSET_2 1
  30. #define WM8350_POWER_UP_INT_OFFSET 2
  31. #define WM8350_UNDER_VOLTAGE_INT_OFFSET 3
  32. #define WM8350_OVER_CURRENT_INT_OFFSET 4
  33. #define WM8350_GPIO_INT_OFFSET 5
  34. #define WM8350_COMPARATOR_INT_OFFSET 6
  35. struct wm8350_irq_data {
  36. int primary;
  37. int reg;
  38. int mask;
  39. int primary_only;
  40. };
  41. static struct wm8350_irq_data wm8350_irqs[] = {
  42. [WM8350_IRQ_OC_LS] = {
  43. .primary = WM8350_OC_INT,
  44. .reg = WM8350_OVER_CURRENT_INT_OFFSET,
  45. .mask = WM8350_OC_LS_EINT,
  46. .primary_only = 1,
  47. },
  48. [WM8350_IRQ_UV_DC1] = {
  49. .primary = WM8350_UV_INT,
  50. .reg = WM8350_UNDER_VOLTAGE_INT_OFFSET,
  51. .mask = WM8350_UV_DC1_EINT,
  52. },
  53. [WM8350_IRQ_UV_DC2] = {
  54. .primary = WM8350_UV_INT,
  55. .reg = WM8350_UNDER_VOLTAGE_INT_OFFSET,
  56. .mask = WM8350_UV_DC2_EINT,
  57. },
  58. [WM8350_IRQ_UV_DC3] = {
  59. .primary = WM8350_UV_INT,
  60. .reg = WM8350_UNDER_VOLTAGE_INT_OFFSET,
  61. .mask = WM8350_UV_DC3_EINT,
  62. },
  63. [WM8350_IRQ_UV_DC4] = {
  64. .primary = WM8350_UV_INT,
  65. .reg = WM8350_UNDER_VOLTAGE_INT_OFFSET,
  66. .mask = WM8350_UV_DC4_EINT,
  67. },
  68. [WM8350_IRQ_UV_DC5] = {
  69. .primary = WM8350_UV_INT,
  70. .reg = WM8350_UNDER_VOLTAGE_INT_OFFSET,
  71. .mask = WM8350_UV_DC5_EINT,
  72. },
  73. [WM8350_IRQ_UV_DC6] = {
  74. .primary = WM8350_UV_INT,
  75. .reg = WM8350_UNDER_VOLTAGE_INT_OFFSET,
  76. .mask = WM8350_UV_DC6_EINT,
  77. },
  78. [WM8350_IRQ_UV_LDO1] = {
  79. .primary = WM8350_UV_INT,
  80. .reg = WM8350_UNDER_VOLTAGE_INT_OFFSET,
  81. .mask = WM8350_UV_LDO1_EINT,
  82. },
  83. [WM8350_IRQ_UV_LDO2] = {
  84. .primary = WM8350_UV_INT,
  85. .reg = WM8350_UNDER_VOLTAGE_INT_OFFSET,
  86. .mask = WM8350_UV_LDO2_EINT,
  87. },
  88. [WM8350_IRQ_UV_LDO3] = {
  89. .primary = WM8350_UV_INT,
  90. .reg = WM8350_UNDER_VOLTAGE_INT_OFFSET,
  91. .mask = WM8350_UV_LDO3_EINT,
  92. },
  93. [WM8350_IRQ_UV_LDO4] = {
  94. .primary = WM8350_UV_INT,
  95. .reg = WM8350_UNDER_VOLTAGE_INT_OFFSET,
  96. .mask = WM8350_UV_LDO4_EINT,
  97. },
  98. [WM8350_IRQ_CHG_BAT_HOT] = {
  99. .primary = WM8350_CHG_INT,
  100. .reg = WM8350_INT_OFFSET_1,
  101. .mask = WM8350_CHG_BAT_HOT_EINT,
  102. },
  103. [WM8350_IRQ_CHG_BAT_COLD] = {
  104. .primary = WM8350_CHG_INT,
  105. .reg = WM8350_INT_OFFSET_1,
  106. .mask = WM8350_CHG_BAT_COLD_EINT,
  107. },
  108. [WM8350_IRQ_CHG_BAT_FAIL] = {
  109. .primary = WM8350_CHG_INT,
  110. .reg = WM8350_INT_OFFSET_1,
  111. .mask = WM8350_CHG_BAT_FAIL_EINT,
  112. },
  113. [WM8350_IRQ_CHG_TO] = {
  114. .primary = WM8350_CHG_INT,
  115. .reg = WM8350_INT_OFFSET_1,
  116. .mask = WM8350_CHG_TO_EINT,
  117. },
  118. [WM8350_IRQ_CHG_END] = {
  119. .primary = WM8350_CHG_INT,
  120. .reg = WM8350_INT_OFFSET_1,
  121. .mask = WM8350_CHG_END_EINT,
  122. },
  123. [WM8350_IRQ_CHG_START] = {
  124. .primary = WM8350_CHG_INT,
  125. .reg = WM8350_INT_OFFSET_1,
  126. .mask = WM8350_CHG_START_EINT,
  127. },
  128. [WM8350_IRQ_CHG_FAST_RDY] = {
  129. .primary = WM8350_CHG_INT,
  130. .reg = WM8350_INT_OFFSET_1,
  131. .mask = WM8350_CHG_FAST_RDY_EINT,
  132. },
  133. [WM8350_IRQ_CHG_VBATT_LT_3P9] = {
  134. .primary = WM8350_CHG_INT,
  135. .reg = WM8350_INT_OFFSET_1,
  136. .mask = WM8350_CHG_VBATT_LT_3P9_EINT,
  137. },
  138. [WM8350_IRQ_CHG_VBATT_LT_3P1] = {
  139. .primary = WM8350_CHG_INT,
  140. .reg = WM8350_INT_OFFSET_1,
  141. .mask = WM8350_CHG_VBATT_LT_3P1_EINT,
  142. },
  143. [WM8350_IRQ_CHG_VBATT_LT_2P85] = {
  144. .primary = WM8350_CHG_INT,
  145. .reg = WM8350_INT_OFFSET_1,
  146. .mask = WM8350_CHG_VBATT_LT_2P85_EINT,
  147. },
  148. [WM8350_IRQ_RTC_ALM] = {
  149. .primary = WM8350_RTC_INT,
  150. .reg = WM8350_INT_OFFSET_1,
  151. .mask = WM8350_RTC_ALM_EINT,
  152. },
  153. [WM8350_IRQ_RTC_SEC] = {
  154. .primary = WM8350_RTC_INT,
  155. .reg = WM8350_INT_OFFSET_1,
  156. .mask = WM8350_RTC_SEC_EINT,
  157. },
  158. [WM8350_IRQ_RTC_PER] = {
  159. .primary = WM8350_RTC_INT,
  160. .reg = WM8350_INT_OFFSET_1,
  161. .mask = WM8350_RTC_PER_EINT,
  162. },
  163. [WM8350_IRQ_CS1] = {
  164. .primary = WM8350_CS_INT,
  165. .reg = WM8350_INT_OFFSET_2,
  166. .mask = WM8350_CS1_EINT,
  167. },
  168. [WM8350_IRQ_CS2] = {
  169. .primary = WM8350_CS_INT,
  170. .reg = WM8350_INT_OFFSET_2,
  171. .mask = WM8350_CS2_EINT,
  172. },
  173. [WM8350_IRQ_SYS_HYST_COMP_FAIL] = {
  174. .primary = WM8350_SYS_INT,
  175. .reg = WM8350_INT_OFFSET_2,
  176. .mask = WM8350_SYS_HYST_COMP_FAIL_EINT,
  177. },
  178. [WM8350_IRQ_SYS_CHIP_GT115] = {
  179. .primary = WM8350_SYS_INT,
  180. .reg = WM8350_INT_OFFSET_2,
  181. .mask = WM8350_SYS_CHIP_GT115_EINT,
  182. },
  183. [WM8350_IRQ_SYS_CHIP_GT140] = {
  184. .primary = WM8350_SYS_INT,
  185. .reg = WM8350_INT_OFFSET_2,
  186. .mask = WM8350_SYS_CHIP_GT140_EINT,
  187. },
  188. [WM8350_IRQ_SYS_WDOG_TO] = {
  189. .primary = WM8350_SYS_INT,
  190. .reg = WM8350_INT_OFFSET_2,
  191. .mask = WM8350_SYS_WDOG_TO_EINT,
  192. },
  193. [WM8350_IRQ_AUXADC_DATARDY] = {
  194. .primary = WM8350_AUXADC_INT,
  195. .reg = WM8350_INT_OFFSET_2,
  196. .mask = WM8350_AUXADC_DATARDY_EINT,
  197. },
  198. [WM8350_IRQ_AUXADC_DCOMP4] = {
  199. .primary = WM8350_AUXADC_INT,
  200. .reg = WM8350_INT_OFFSET_2,
  201. .mask = WM8350_AUXADC_DCOMP4_EINT,
  202. },
  203. [WM8350_IRQ_AUXADC_DCOMP3] = {
  204. .primary = WM8350_AUXADC_INT,
  205. .reg = WM8350_INT_OFFSET_2,
  206. .mask = WM8350_AUXADC_DCOMP3_EINT,
  207. },
  208. [WM8350_IRQ_AUXADC_DCOMP2] = {
  209. .primary = WM8350_AUXADC_INT,
  210. .reg = WM8350_INT_OFFSET_2,
  211. .mask = WM8350_AUXADC_DCOMP2_EINT,
  212. },
  213. [WM8350_IRQ_AUXADC_DCOMP1] = {
  214. .primary = WM8350_AUXADC_INT,
  215. .reg = WM8350_INT_OFFSET_2,
  216. .mask = WM8350_AUXADC_DCOMP1_EINT,
  217. },
  218. [WM8350_IRQ_USB_LIMIT] = {
  219. .primary = WM8350_USB_INT,
  220. .reg = WM8350_INT_OFFSET_2,
  221. .mask = WM8350_USB_LIMIT_EINT,
  222. .primary_only = 1,
  223. },
  224. [WM8350_IRQ_WKUP_OFF_STATE] = {
  225. .primary = WM8350_WKUP_INT,
  226. .reg = WM8350_COMPARATOR_INT_OFFSET,
  227. .mask = WM8350_WKUP_OFF_STATE_EINT,
  228. },
  229. [WM8350_IRQ_WKUP_HIB_STATE] = {
  230. .primary = WM8350_WKUP_INT,
  231. .reg = WM8350_COMPARATOR_INT_OFFSET,
  232. .mask = WM8350_WKUP_HIB_STATE_EINT,
  233. },
  234. [WM8350_IRQ_WKUP_CONV_FAULT] = {
  235. .primary = WM8350_WKUP_INT,
  236. .reg = WM8350_COMPARATOR_INT_OFFSET,
  237. .mask = WM8350_WKUP_CONV_FAULT_EINT,
  238. },
  239. [WM8350_IRQ_WKUP_WDOG_RST] = {
  240. .primary = WM8350_WKUP_INT,
  241. .reg = WM8350_COMPARATOR_INT_OFFSET,
  242. .mask = WM8350_WKUP_WDOG_RST_EINT,
  243. },
  244. [WM8350_IRQ_WKUP_GP_PWR_ON] = {
  245. .primary = WM8350_WKUP_INT,
  246. .reg = WM8350_COMPARATOR_INT_OFFSET,
  247. .mask = WM8350_WKUP_GP_PWR_ON_EINT,
  248. },
  249. [WM8350_IRQ_WKUP_ONKEY] = {
  250. .primary = WM8350_WKUP_INT,
  251. .reg = WM8350_COMPARATOR_INT_OFFSET,
  252. .mask = WM8350_WKUP_ONKEY_EINT,
  253. },
  254. [WM8350_IRQ_WKUP_GP_WAKEUP] = {
  255. .primary = WM8350_WKUP_INT,
  256. .reg = WM8350_COMPARATOR_INT_OFFSET,
  257. .mask = WM8350_WKUP_GP_WAKEUP_EINT,
  258. },
  259. [WM8350_IRQ_CODEC_JCK_DET_L] = {
  260. .primary = WM8350_CODEC_INT,
  261. .reg = WM8350_COMPARATOR_INT_OFFSET,
  262. .mask = WM8350_CODEC_JCK_DET_L_EINT,
  263. },
  264. [WM8350_IRQ_CODEC_JCK_DET_R] = {
  265. .primary = WM8350_CODEC_INT,
  266. .reg = WM8350_COMPARATOR_INT_OFFSET,
  267. .mask = WM8350_CODEC_JCK_DET_R_EINT,
  268. },
  269. [WM8350_IRQ_CODEC_MICSCD] = {
  270. .primary = WM8350_CODEC_INT,
  271. .reg = WM8350_COMPARATOR_INT_OFFSET,
  272. .mask = WM8350_CODEC_MICSCD_EINT,
  273. },
  274. [WM8350_IRQ_CODEC_MICD] = {
  275. .primary = WM8350_CODEC_INT,
  276. .reg = WM8350_COMPARATOR_INT_OFFSET,
  277. .mask = WM8350_CODEC_MICD_EINT,
  278. },
  279. [WM8350_IRQ_EXT_USB_FB] = {
  280. .primary = WM8350_EXT_INT,
  281. .reg = WM8350_COMPARATOR_INT_OFFSET,
  282. .mask = WM8350_EXT_USB_FB_EINT,
  283. },
  284. [WM8350_IRQ_EXT_WALL_FB] = {
  285. .primary = WM8350_EXT_INT,
  286. .reg = WM8350_COMPARATOR_INT_OFFSET,
  287. .mask = WM8350_EXT_WALL_FB_EINT,
  288. },
  289. [WM8350_IRQ_EXT_BAT_FB] = {
  290. .primary = WM8350_EXT_INT,
  291. .reg = WM8350_COMPARATOR_INT_OFFSET,
  292. .mask = WM8350_EXT_BAT_FB_EINT,
  293. },
  294. [WM8350_IRQ_GPIO(0)] = {
  295. .primary = WM8350_GP_INT,
  296. .reg = WM8350_GPIO_INT_OFFSET,
  297. .mask = WM8350_GP0_EINT,
  298. },
  299. [WM8350_IRQ_GPIO(1)] = {
  300. .primary = WM8350_GP_INT,
  301. .reg = WM8350_GPIO_INT_OFFSET,
  302. .mask = WM8350_GP1_EINT,
  303. },
  304. [WM8350_IRQ_GPIO(2)] = {
  305. .primary = WM8350_GP_INT,
  306. .reg = WM8350_GPIO_INT_OFFSET,
  307. .mask = WM8350_GP2_EINT,
  308. },
  309. [WM8350_IRQ_GPIO(3)] = {
  310. .primary = WM8350_GP_INT,
  311. .reg = WM8350_GPIO_INT_OFFSET,
  312. .mask = WM8350_GP3_EINT,
  313. },
  314. [WM8350_IRQ_GPIO(4)] = {
  315. .primary = WM8350_GP_INT,
  316. .reg = WM8350_GPIO_INT_OFFSET,
  317. .mask = WM8350_GP4_EINT,
  318. },
  319. [WM8350_IRQ_GPIO(5)] = {
  320. .primary = WM8350_GP_INT,
  321. .reg = WM8350_GPIO_INT_OFFSET,
  322. .mask = WM8350_GP5_EINT,
  323. },
  324. [WM8350_IRQ_GPIO(6)] = {
  325. .primary = WM8350_GP_INT,
  326. .reg = WM8350_GPIO_INT_OFFSET,
  327. .mask = WM8350_GP6_EINT,
  328. },
  329. [WM8350_IRQ_GPIO(7)] = {
  330. .primary = WM8350_GP_INT,
  331. .reg = WM8350_GPIO_INT_OFFSET,
  332. .mask = WM8350_GP7_EINT,
  333. },
  334. [WM8350_IRQ_GPIO(8)] = {
  335. .primary = WM8350_GP_INT,
  336. .reg = WM8350_GPIO_INT_OFFSET,
  337. .mask = WM8350_GP8_EINT,
  338. },
  339. [WM8350_IRQ_GPIO(9)] = {
  340. .primary = WM8350_GP_INT,
  341. .reg = WM8350_GPIO_INT_OFFSET,
  342. .mask = WM8350_GP9_EINT,
  343. },
  344. [WM8350_IRQ_GPIO(10)] = {
  345. .primary = WM8350_GP_INT,
  346. .reg = WM8350_GPIO_INT_OFFSET,
  347. .mask = WM8350_GP10_EINT,
  348. },
  349. [WM8350_IRQ_GPIO(11)] = {
  350. .primary = WM8350_GP_INT,
  351. .reg = WM8350_GPIO_INT_OFFSET,
  352. .mask = WM8350_GP11_EINT,
  353. },
  354. [WM8350_IRQ_GPIO(12)] = {
  355. .primary = WM8350_GP_INT,
  356. .reg = WM8350_GPIO_INT_OFFSET,
  357. .mask = WM8350_GP12_EINT,
  358. },
  359. };
  360. static inline struct wm8350_irq_data *irq_to_wm8350_irq(struct wm8350 *wm8350,
  361. int irq)
  362. {
  363. return &wm8350_irqs[irq - wm8350->irq_base];
  364. }
  365. /*
  366. * This is a threaded IRQ handler so can access I2C/SPI. Since all
  367. * interrupts are clear on read the IRQ line will be reasserted and
  368. * the physical IRQ will be handled again if another interrupt is
  369. * asserted while we run - in the normal course of events this is a
  370. * rare occurrence so we save I2C/SPI reads. We're also assuming that
  371. * it's rare to get lots of interrupts firing simultaneously so try to
  372. * minimise I/O.
  373. */
  374. static irqreturn_t wm8350_irq(int irq, void *irq_data)
  375. {
  376. struct wm8350 *wm8350 = irq_data;
  377. u16 level_one;
  378. u16 sub_reg[WM8350_NUM_IRQ_REGS];
  379. int read_done[WM8350_NUM_IRQ_REGS];
  380. struct wm8350_irq_data *data;
  381. int i;
  382. level_one = wm8350_reg_read(wm8350, WM8350_SYSTEM_INTERRUPTS)
  383. & ~wm8350_reg_read(wm8350, WM8350_SYSTEM_INTERRUPTS_MASK);
  384. if (!level_one)
  385. return IRQ_NONE;
  386. memset(&read_done, 0, sizeof(read_done));
  387. for (i = 0; i < ARRAY_SIZE(wm8350_irqs); i++) {
  388. data = &wm8350_irqs[i];
  389. if (!(level_one & data->primary))
  390. continue;
  391. if (!read_done[data->reg]) {
  392. sub_reg[data->reg] =
  393. wm8350_reg_read(wm8350, WM8350_INT_STATUS_1 +
  394. data->reg);
  395. sub_reg[data->reg] &= ~wm8350->irq_masks[data->reg];
  396. read_done[data->reg] = 1;
  397. }
  398. if (sub_reg[data->reg] & data->mask)
  399. handle_nested_irq(wm8350->irq_base + i);
  400. }
  401. return IRQ_HANDLED;
  402. }
  403. static void wm8350_irq_lock(struct irq_data *data)
  404. {
  405. struct wm8350 *wm8350 = irq_data_get_irq_chip_data(data);
  406. mutex_lock(&wm8350->irq_lock);
  407. }
  408. static void wm8350_irq_sync_unlock(struct irq_data *data)
  409. {
  410. struct wm8350 *wm8350 = irq_data_get_irq_chip_data(data);
  411. int i;
  412. for (i = 0; i < ARRAY_SIZE(wm8350->irq_masks); i++) {
  413. /* If there's been a change in the mask write it back
  414. * to the hardware. */
  415. WARN_ON(regmap_update_bits(wm8350->regmap,
  416. WM8350_INT_STATUS_1_MASK + i,
  417. 0xffff, wm8350->irq_masks[i]));
  418. }
  419. mutex_unlock(&wm8350->irq_lock);
  420. }
  421. static void wm8350_irq_enable(struct irq_data *data)
  422. {
  423. struct wm8350 *wm8350 = irq_data_get_irq_chip_data(data);
  424. struct wm8350_irq_data *irq_data = irq_to_wm8350_irq(wm8350,
  425. data->irq);
  426. wm8350->irq_masks[irq_data->reg] &= ~irq_data->mask;
  427. }
  428. static void wm8350_irq_disable(struct irq_data *data)
  429. {
  430. struct wm8350 *wm8350 = irq_data_get_irq_chip_data(data);
  431. struct wm8350_irq_data *irq_data = irq_to_wm8350_irq(wm8350,
  432. data->irq);
  433. wm8350->irq_masks[irq_data->reg] |= irq_data->mask;
  434. }
  435. static struct irq_chip wm8350_irq_chip = {
  436. .name = "wm8350",
  437. .irq_bus_lock = wm8350_irq_lock,
  438. .irq_bus_sync_unlock = wm8350_irq_sync_unlock,
  439. .irq_disable = wm8350_irq_disable,
  440. .irq_enable = wm8350_irq_enable,
  441. };
  442. int wm8350_irq_init(struct wm8350 *wm8350, int irq,
  443. struct wm8350_platform_data *pdata)
  444. {
  445. int ret, cur_irq, i;
  446. int flags = IRQF_ONESHOT;
  447. int irq_base = -1;
  448. if (!irq) {
  449. dev_warn(wm8350->dev, "No interrupt support, no core IRQ\n");
  450. return 0;
  451. }
  452. /* Mask top level interrupts */
  453. wm8350_reg_write(wm8350, WM8350_SYSTEM_INTERRUPTS_MASK, 0xFFFF);
  454. /* Mask all individual interrupts by default and cache the
  455. * masks. We read the masks back since there are unwritable
  456. * bits in the mask registers. */
  457. for (i = 0; i < ARRAY_SIZE(wm8350->irq_masks); i++) {
  458. wm8350_reg_write(wm8350, WM8350_INT_STATUS_1_MASK + i,
  459. 0xFFFF);
  460. wm8350->irq_masks[i] =
  461. wm8350_reg_read(wm8350,
  462. WM8350_INT_STATUS_1_MASK + i);
  463. }
  464. mutex_init(&wm8350->irq_lock);
  465. wm8350->chip_irq = irq;
  466. if (pdata && pdata->irq_base > 0)
  467. irq_base = pdata->irq_base;
  468. wm8350->irq_base =
  469. irq_alloc_descs(irq_base, 0, ARRAY_SIZE(wm8350_irqs), 0);
  470. if (wm8350->irq_base < 0) {
  471. dev_warn(wm8350->dev, "Allocating irqs failed with %d\n",
  472. wm8350->irq_base);
  473. return 0;
  474. }
  475. if (pdata && pdata->irq_high) {
  476. flags |= IRQF_TRIGGER_HIGH;
  477. wm8350_set_bits(wm8350, WM8350_SYSTEM_CONTROL_1,
  478. WM8350_IRQ_POL);
  479. } else {
  480. flags |= IRQF_TRIGGER_LOW;
  481. wm8350_clear_bits(wm8350, WM8350_SYSTEM_CONTROL_1,
  482. WM8350_IRQ_POL);
  483. }
  484. /* Register with genirq */
  485. for (cur_irq = wm8350->irq_base;
  486. cur_irq < ARRAY_SIZE(wm8350_irqs) + wm8350->irq_base;
  487. cur_irq++) {
  488. irq_set_chip_data(cur_irq, wm8350);
  489. irq_set_chip_and_handler(cur_irq, &wm8350_irq_chip,
  490. handle_edge_irq);
  491. irq_set_nested_thread(cur_irq, 1);
  492. irq_clear_status_flags(cur_irq, IRQ_NOREQUEST | IRQ_NOPROBE);
  493. }
  494. ret = request_threaded_irq(irq, NULL, wm8350_irq, flags,
  495. "wm8350", wm8350);
  496. if (ret != 0)
  497. dev_err(wm8350->dev, "Failed to request IRQ: %d\n", ret);
  498. /* Allow interrupts to fire */
  499. wm8350_reg_write(wm8350, WM8350_SYSTEM_INTERRUPTS_MASK, 0);
  500. return ret;
  501. }
  502. int wm8350_irq_exit(struct wm8350 *wm8350)
  503. {
  504. free_irq(wm8350->chip_irq, wm8350);
  505. return 0;
  506. }