irq-renesas-intc-irqpin.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. /*
  2. * Renesas INTC External IRQ Pin Driver
  3. *
  4. * Copyright (C) 2013 Magnus Damm
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #include <linux/init.h>
  20. #include <linux/of.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/spinlock.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/ioport.h>
  25. #include <linux/io.h>
  26. #include <linux/irq.h>
  27. #include <linux/irqdomain.h>
  28. #include <linux/err.h>
  29. #include <linux/slab.h>
  30. #include <linux/module.h>
  31. #include <linux/of_device.h>
  32. #include <linux/pm_runtime.h>
  33. #define INTC_IRQPIN_MAX 8 /* maximum 8 interrupts per driver instance */
  34. #define INTC_IRQPIN_REG_SENSE 0 /* ICRn */
  35. #define INTC_IRQPIN_REG_PRIO 1 /* INTPRInn */
  36. #define INTC_IRQPIN_REG_SOURCE 2 /* INTREQnn */
  37. #define INTC_IRQPIN_REG_MASK 3 /* INTMSKnn */
  38. #define INTC_IRQPIN_REG_CLEAR 4 /* INTMSKCLRnn */
  39. #define INTC_IRQPIN_REG_NR_MANDATORY 5
  40. #define INTC_IRQPIN_REG_IRLM 5 /* ICR0 with IRLM bit (optional) */
  41. #define INTC_IRQPIN_REG_NR 6
  42. /* INTC external IRQ PIN hardware register access:
  43. *
  44. * SENSE is read-write 32-bit with 2-bits or 4-bits per IRQ (*)
  45. * PRIO is read-write 32-bit with 4-bits per IRQ (**)
  46. * SOURCE is read-only 32-bit or 8-bit with 1-bit per IRQ (***)
  47. * MASK is write-only 32-bit or 8-bit with 1-bit per IRQ (***)
  48. * CLEAR is write-only 32-bit or 8-bit with 1-bit per IRQ (***)
  49. *
  50. * (*) May be accessed by more than one driver instance - lock needed
  51. * (**) Read-modify-write access by one driver instance - lock needed
  52. * (***) Accessed by one driver instance only - no locking needed
  53. */
  54. struct intc_irqpin_iomem {
  55. void __iomem *iomem;
  56. unsigned long (*read)(void __iomem *iomem);
  57. void (*write)(void __iomem *iomem, unsigned long data);
  58. int width;
  59. };
  60. struct intc_irqpin_irq {
  61. int hw_irq;
  62. int requested_irq;
  63. int domain_irq;
  64. struct intc_irqpin_priv *p;
  65. };
  66. struct intc_irqpin_priv {
  67. struct intc_irqpin_iomem iomem[INTC_IRQPIN_REG_NR];
  68. struct intc_irqpin_irq irq[INTC_IRQPIN_MAX];
  69. unsigned int sense_bitfield_width;
  70. struct platform_device *pdev;
  71. struct irq_chip irq_chip;
  72. struct irq_domain *irq_domain;
  73. atomic_t wakeup_path;
  74. unsigned shared_irqs:1;
  75. u8 shared_irq_mask;
  76. };
  77. struct intc_irqpin_config {
  78. unsigned int irlm_bit;
  79. unsigned needs_irlm:1;
  80. };
  81. static unsigned long intc_irqpin_read32(void __iomem *iomem)
  82. {
  83. return ioread32(iomem);
  84. }
  85. static unsigned long intc_irqpin_read8(void __iomem *iomem)
  86. {
  87. return ioread8(iomem);
  88. }
  89. static void intc_irqpin_write32(void __iomem *iomem, unsigned long data)
  90. {
  91. iowrite32(data, iomem);
  92. }
  93. static void intc_irqpin_write8(void __iomem *iomem, unsigned long data)
  94. {
  95. iowrite8(data, iomem);
  96. }
  97. static inline unsigned long intc_irqpin_read(struct intc_irqpin_priv *p,
  98. int reg)
  99. {
  100. struct intc_irqpin_iomem *i = &p->iomem[reg];
  101. return i->read(i->iomem);
  102. }
  103. static inline void intc_irqpin_write(struct intc_irqpin_priv *p,
  104. int reg, unsigned long data)
  105. {
  106. struct intc_irqpin_iomem *i = &p->iomem[reg];
  107. i->write(i->iomem, data);
  108. }
  109. static inline unsigned long intc_irqpin_hwirq_mask(struct intc_irqpin_priv *p,
  110. int reg, int hw_irq)
  111. {
  112. return BIT((p->iomem[reg].width - 1) - hw_irq);
  113. }
  114. static inline void intc_irqpin_irq_write_hwirq(struct intc_irqpin_priv *p,
  115. int reg, int hw_irq)
  116. {
  117. intc_irqpin_write(p, reg, intc_irqpin_hwirq_mask(p, reg, hw_irq));
  118. }
  119. static DEFINE_RAW_SPINLOCK(intc_irqpin_lock); /* only used by slow path */
  120. static void intc_irqpin_read_modify_write(struct intc_irqpin_priv *p,
  121. int reg, int shift,
  122. int width, int value)
  123. {
  124. unsigned long flags;
  125. unsigned long tmp;
  126. raw_spin_lock_irqsave(&intc_irqpin_lock, flags);
  127. tmp = intc_irqpin_read(p, reg);
  128. tmp &= ~(((1 << width) - 1) << shift);
  129. tmp |= value << shift;
  130. intc_irqpin_write(p, reg, tmp);
  131. raw_spin_unlock_irqrestore(&intc_irqpin_lock, flags);
  132. }
  133. static void intc_irqpin_mask_unmask_prio(struct intc_irqpin_priv *p,
  134. int irq, int do_mask)
  135. {
  136. /* The PRIO register is assumed to be 32-bit with fixed 4-bit fields. */
  137. int bitfield_width = 4;
  138. int shift = 32 - (irq + 1) * bitfield_width;
  139. intc_irqpin_read_modify_write(p, INTC_IRQPIN_REG_PRIO,
  140. shift, bitfield_width,
  141. do_mask ? 0 : (1 << bitfield_width) - 1);
  142. }
  143. static int intc_irqpin_set_sense(struct intc_irqpin_priv *p, int irq, int value)
  144. {
  145. /* The SENSE register is assumed to be 32-bit. */
  146. int bitfield_width = p->sense_bitfield_width;
  147. int shift = 32 - (irq + 1) * bitfield_width;
  148. dev_dbg(&p->pdev->dev, "sense irq = %d, mode = %d\n", irq, value);
  149. if (value >= (1 << bitfield_width))
  150. return -EINVAL;
  151. intc_irqpin_read_modify_write(p, INTC_IRQPIN_REG_SENSE, shift,
  152. bitfield_width, value);
  153. return 0;
  154. }
  155. static void intc_irqpin_dbg(struct intc_irqpin_irq *i, char *str)
  156. {
  157. dev_dbg(&i->p->pdev->dev, "%s (%d:%d:%d)\n",
  158. str, i->requested_irq, i->hw_irq, i->domain_irq);
  159. }
  160. static void intc_irqpin_irq_enable(struct irq_data *d)
  161. {
  162. struct intc_irqpin_priv *p = irq_data_get_irq_chip_data(d);
  163. int hw_irq = irqd_to_hwirq(d);
  164. intc_irqpin_dbg(&p->irq[hw_irq], "enable");
  165. intc_irqpin_irq_write_hwirq(p, INTC_IRQPIN_REG_CLEAR, hw_irq);
  166. }
  167. static void intc_irqpin_irq_disable(struct irq_data *d)
  168. {
  169. struct intc_irqpin_priv *p = irq_data_get_irq_chip_data(d);
  170. int hw_irq = irqd_to_hwirq(d);
  171. intc_irqpin_dbg(&p->irq[hw_irq], "disable");
  172. intc_irqpin_irq_write_hwirq(p, INTC_IRQPIN_REG_MASK, hw_irq);
  173. }
  174. static void intc_irqpin_shared_irq_enable(struct irq_data *d)
  175. {
  176. struct intc_irqpin_priv *p = irq_data_get_irq_chip_data(d);
  177. int hw_irq = irqd_to_hwirq(d);
  178. intc_irqpin_dbg(&p->irq[hw_irq], "shared enable");
  179. intc_irqpin_irq_write_hwirq(p, INTC_IRQPIN_REG_CLEAR, hw_irq);
  180. p->shared_irq_mask &= ~BIT(hw_irq);
  181. }
  182. static void intc_irqpin_shared_irq_disable(struct irq_data *d)
  183. {
  184. struct intc_irqpin_priv *p = irq_data_get_irq_chip_data(d);
  185. int hw_irq = irqd_to_hwirq(d);
  186. intc_irqpin_dbg(&p->irq[hw_irq], "shared disable");
  187. intc_irqpin_irq_write_hwirq(p, INTC_IRQPIN_REG_MASK, hw_irq);
  188. p->shared_irq_mask |= BIT(hw_irq);
  189. }
  190. static void intc_irqpin_irq_enable_force(struct irq_data *d)
  191. {
  192. struct intc_irqpin_priv *p = irq_data_get_irq_chip_data(d);
  193. int irq = p->irq[irqd_to_hwirq(d)].requested_irq;
  194. intc_irqpin_irq_enable(d);
  195. /* enable interrupt through parent interrupt controller,
  196. * assumes non-shared interrupt with 1:1 mapping
  197. * needed for busted IRQs on some SoCs like sh73a0
  198. */
  199. irq_get_chip(irq)->irq_unmask(irq_get_irq_data(irq));
  200. }
  201. static void intc_irqpin_irq_disable_force(struct irq_data *d)
  202. {
  203. struct intc_irqpin_priv *p = irq_data_get_irq_chip_data(d);
  204. int irq = p->irq[irqd_to_hwirq(d)].requested_irq;
  205. /* disable interrupt through parent interrupt controller,
  206. * assumes non-shared interrupt with 1:1 mapping
  207. * needed for busted IRQs on some SoCs like sh73a0
  208. */
  209. irq_get_chip(irq)->irq_mask(irq_get_irq_data(irq));
  210. intc_irqpin_irq_disable(d);
  211. }
  212. #define INTC_IRQ_SENSE_VALID 0x10
  213. #define INTC_IRQ_SENSE(x) (x + INTC_IRQ_SENSE_VALID)
  214. static unsigned char intc_irqpin_sense[IRQ_TYPE_SENSE_MASK + 1] = {
  215. [IRQ_TYPE_EDGE_FALLING] = INTC_IRQ_SENSE(0x00),
  216. [IRQ_TYPE_EDGE_RISING] = INTC_IRQ_SENSE(0x01),
  217. [IRQ_TYPE_LEVEL_LOW] = INTC_IRQ_SENSE(0x02),
  218. [IRQ_TYPE_LEVEL_HIGH] = INTC_IRQ_SENSE(0x03),
  219. [IRQ_TYPE_EDGE_BOTH] = INTC_IRQ_SENSE(0x04),
  220. };
  221. static int intc_irqpin_irq_set_type(struct irq_data *d, unsigned int type)
  222. {
  223. unsigned char value = intc_irqpin_sense[type & IRQ_TYPE_SENSE_MASK];
  224. struct intc_irqpin_priv *p = irq_data_get_irq_chip_data(d);
  225. if (!(value & INTC_IRQ_SENSE_VALID))
  226. return -EINVAL;
  227. return intc_irqpin_set_sense(p, irqd_to_hwirq(d),
  228. value ^ INTC_IRQ_SENSE_VALID);
  229. }
  230. static int intc_irqpin_irq_set_wake(struct irq_data *d, unsigned int on)
  231. {
  232. struct intc_irqpin_priv *p = irq_data_get_irq_chip_data(d);
  233. int hw_irq = irqd_to_hwirq(d);
  234. irq_set_irq_wake(p->irq[hw_irq].requested_irq, on);
  235. if (on)
  236. atomic_inc(&p->wakeup_path);
  237. else
  238. atomic_dec(&p->wakeup_path);
  239. return 0;
  240. }
  241. static irqreturn_t intc_irqpin_irq_handler(int irq, void *dev_id)
  242. {
  243. struct intc_irqpin_irq *i = dev_id;
  244. struct intc_irqpin_priv *p = i->p;
  245. unsigned long bit;
  246. intc_irqpin_dbg(i, "demux1");
  247. bit = intc_irqpin_hwirq_mask(p, INTC_IRQPIN_REG_SOURCE, i->hw_irq);
  248. if (intc_irqpin_read(p, INTC_IRQPIN_REG_SOURCE) & bit) {
  249. intc_irqpin_write(p, INTC_IRQPIN_REG_SOURCE, ~bit);
  250. intc_irqpin_dbg(i, "demux2");
  251. generic_handle_irq(i->domain_irq);
  252. return IRQ_HANDLED;
  253. }
  254. return IRQ_NONE;
  255. }
  256. static irqreturn_t intc_irqpin_shared_irq_handler(int irq, void *dev_id)
  257. {
  258. struct intc_irqpin_priv *p = dev_id;
  259. unsigned int reg_source = intc_irqpin_read(p, INTC_IRQPIN_REG_SOURCE);
  260. irqreturn_t status = IRQ_NONE;
  261. int k;
  262. for (k = 0; k < 8; k++) {
  263. if (reg_source & BIT(7 - k)) {
  264. if (BIT(k) & p->shared_irq_mask)
  265. continue;
  266. status |= intc_irqpin_irq_handler(irq, &p->irq[k]);
  267. }
  268. }
  269. return status;
  270. }
  271. /*
  272. * This lock class tells lockdep that INTC External IRQ Pin irqs are in a
  273. * different category than their parents, so it won't report false recursion.
  274. */
  275. static struct lock_class_key intc_irqpin_irq_lock_class;
  276. /* And this is for the request mutex */
  277. static struct lock_class_key intc_irqpin_irq_request_class;
  278. static int intc_irqpin_irq_domain_map(struct irq_domain *h, unsigned int virq,
  279. irq_hw_number_t hw)
  280. {
  281. struct intc_irqpin_priv *p = h->host_data;
  282. p->irq[hw].domain_irq = virq;
  283. p->irq[hw].hw_irq = hw;
  284. intc_irqpin_dbg(&p->irq[hw], "map");
  285. irq_set_chip_data(virq, h->host_data);
  286. irq_set_lockdep_class(virq, &intc_irqpin_irq_lock_class,
  287. &intc_irqpin_irq_request_class);
  288. irq_set_chip_and_handler(virq, &p->irq_chip, handle_level_irq);
  289. return 0;
  290. }
  291. static const struct irq_domain_ops intc_irqpin_irq_domain_ops = {
  292. .map = intc_irqpin_irq_domain_map,
  293. .xlate = irq_domain_xlate_twocell,
  294. };
  295. static const struct intc_irqpin_config intc_irqpin_irlm_r8a777x = {
  296. .irlm_bit = 23, /* ICR0.IRLM0 */
  297. .needs_irlm = 1,
  298. };
  299. static const struct intc_irqpin_config intc_irqpin_rmobile = {
  300. .needs_irlm = 0,
  301. };
  302. static const struct of_device_id intc_irqpin_dt_ids[] = {
  303. { .compatible = "renesas,intc-irqpin", },
  304. { .compatible = "renesas,intc-irqpin-r8a7778",
  305. .data = &intc_irqpin_irlm_r8a777x },
  306. { .compatible = "renesas,intc-irqpin-r8a7779",
  307. .data = &intc_irqpin_irlm_r8a777x },
  308. { .compatible = "renesas,intc-irqpin-r8a7740",
  309. .data = &intc_irqpin_rmobile },
  310. { .compatible = "renesas,intc-irqpin-sh73a0",
  311. .data = &intc_irqpin_rmobile },
  312. {},
  313. };
  314. MODULE_DEVICE_TABLE(of, intc_irqpin_dt_ids);
  315. static int intc_irqpin_probe(struct platform_device *pdev)
  316. {
  317. const struct intc_irqpin_config *config;
  318. struct device *dev = &pdev->dev;
  319. struct intc_irqpin_priv *p;
  320. struct intc_irqpin_iomem *i;
  321. struct resource *io[INTC_IRQPIN_REG_NR];
  322. struct resource *irq;
  323. struct irq_chip *irq_chip;
  324. void (*enable_fn)(struct irq_data *d);
  325. void (*disable_fn)(struct irq_data *d);
  326. const char *name = dev_name(dev);
  327. bool control_parent;
  328. unsigned int nirqs;
  329. int ref_irq;
  330. int ret;
  331. int k;
  332. p = devm_kzalloc(dev, sizeof(*p), GFP_KERNEL);
  333. if (!p) {
  334. dev_err(dev, "failed to allocate driver data\n");
  335. return -ENOMEM;
  336. }
  337. /* deal with driver instance configuration */
  338. of_property_read_u32(dev->of_node, "sense-bitfield-width",
  339. &p->sense_bitfield_width);
  340. control_parent = of_property_read_bool(dev->of_node, "control-parent");
  341. if (!p->sense_bitfield_width)
  342. p->sense_bitfield_width = 4; /* default to 4 bits */
  343. p->pdev = pdev;
  344. platform_set_drvdata(pdev, p);
  345. config = of_device_get_match_data(dev);
  346. pm_runtime_enable(dev);
  347. pm_runtime_get_sync(dev);
  348. /* get hold of register banks */
  349. memset(io, 0, sizeof(io));
  350. for (k = 0; k < INTC_IRQPIN_REG_NR; k++) {
  351. io[k] = platform_get_resource(pdev, IORESOURCE_MEM, k);
  352. if (!io[k] && k < INTC_IRQPIN_REG_NR_MANDATORY) {
  353. dev_err(dev, "not enough IOMEM resources\n");
  354. ret = -EINVAL;
  355. goto err0;
  356. }
  357. }
  358. /* allow any number of IRQs between 1 and INTC_IRQPIN_MAX */
  359. for (k = 0; k < INTC_IRQPIN_MAX; k++) {
  360. irq = platform_get_resource(pdev, IORESOURCE_IRQ, k);
  361. if (!irq)
  362. break;
  363. p->irq[k].p = p;
  364. p->irq[k].requested_irq = irq->start;
  365. }
  366. nirqs = k;
  367. if (nirqs < 1) {
  368. dev_err(dev, "not enough IRQ resources\n");
  369. ret = -EINVAL;
  370. goto err0;
  371. }
  372. /* ioremap IOMEM and setup read/write callbacks */
  373. for (k = 0; k < INTC_IRQPIN_REG_NR; k++) {
  374. i = &p->iomem[k];
  375. /* handle optional registers */
  376. if (!io[k])
  377. continue;
  378. switch (resource_size(io[k])) {
  379. case 1:
  380. i->width = 8;
  381. i->read = intc_irqpin_read8;
  382. i->write = intc_irqpin_write8;
  383. break;
  384. case 4:
  385. i->width = 32;
  386. i->read = intc_irqpin_read32;
  387. i->write = intc_irqpin_write32;
  388. break;
  389. default:
  390. dev_err(dev, "IOMEM size mismatch\n");
  391. ret = -EINVAL;
  392. goto err0;
  393. }
  394. i->iomem = devm_ioremap_nocache(dev, io[k]->start,
  395. resource_size(io[k]));
  396. if (!i->iomem) {
  397. dev_err(dev, "failed to remap IOMEM\n");
  398. ret = -ENXIO;
  399. goto err0;
  400. }
  401. }
  402. /* configure "individual IRQ mode" where needed */
  403. if (config && config->needs_irlm) {
  404. if (io[INTC_IRQPIN_REG_IRLM])
  405. intc_irqpin_read_modify_write(p, INTC_IRQPIN_REG_IRLM,
  406. config->irlm_bit, 1, 1);
  407. else
  408. dev_warn(dev, "unable to select IRLM mode\n");
  409. }
  410. /* mask all interrupts using priority */
  411. for (k = 0; k < nirqs; k++)
  412. intc_irqpin_mask_unmask_prio(p, k, 1);
  413. /* clear all pending interrupts */
  414. intc_irqpin_write(p, INTC_IRQPIN_REG_SOURCE, 0x0);
  415. /* scan for shared interrupt lines */
  416. ref_irq = p->irq[0].requested_irq;
  417. p->shared_irqs = 1;
  418. for (k = 1; k < nirqs; k++) {
  419. if (ref_irq != p->irq[k].requested_irq) {
  420. p->shared_irqs = 0;
  421. break;
  422. }
  423. }
  424. /* use more severe masking method if requested */
  425. if (control_parent) {
  426. enable_fn = intc_irqpin_irq_enable_force;
  427. disable_fn = intc_irqpin_irq_disable_force;
  428. } else if (!p->shared_irqs) {
  429. enable_fn = intc_irqpin_irq_enable;
  430. disable_fn = intc_irqpin_irq_disable;
  431. } else {
  432. enable_fn = intc_irqpin_shared_irq_enable;
  433. disable_fn = intc_irqpin_shared_irq_disable;
  434. }
  435. irq_chip = &p->irq_chip;
  436. irq_chip->name = name;
  437. irq_chip->irq_mask = disable_fn;
  438. irq_chip->irq_unmask = enable_fn;
  439. irq_chip->irq_set_type = intc_irqpin_irq_set_type;
  440. irq_chip->irq_set_wake = intc_irqpin_irq_set_wake;
  441. irq_chip->flags = IRQCHIP_MASK_ON_SUSPEND;
  442. p->irq_domain = irq_domain_add_simple(dev->of_node, nirqs, 0,
  443. &intc_irqpin_irq_domain_ops, p);
  444. if (!p->irq_domain) {
  445. ret = -ENXIO;
  446. dev_err(dev, "cannot initialize irq domain\n");
  447. goto err0;
  448. }
  449. if (p->shared_irqs) {
  450. /* request one shared interrupt */
  451. if (devm_request_irq(dev, p->irq[0].requested_irq,
  452. intc_irqpin_shared_irq_handler,
  453. IRQF_SHARED, name, p)) {
  454. dev_err(dev, "failed to request low IRQ\n");
  455. ret = -ENOENT;
  456. goto err1;
  457. }
  458. } else {
  459. /* request interrupts one by one */
  460. for (k = 0; k < nirqs; k++) {
  461. if (devm_request_irq(dev, p->irq[k].requested_irq,
  462. intc_irqpin_irq_handler, 0, name,
  463. &p->irq[k])) {
  464. dev_err(dev, "failed to request low IRQ\n");
  465. ret = -ENOENT;
  466. goto err1;
  467. }
  468. }
  469. }
  470. /* unmask all interrupts on prio level */
  471. for (k = 0; k < nirqs; k++)
  472. intc_irqpin_mask_unmask_prio(p, k, 0);
  473. dev_info(dev, "driving %d irqs\n", nirqs);
  474. return 0;
  475. err1:
  476. irq_domain_remove(p->irq_domain);
  477. err0:
  478. pm_runtime_put(dev);
  479. pm_runtime_disable(dev);
  480. return ret;
  481. }
  482. static int intc_irqpin_remove(struct platform_device *pdev)
  483. {
  484. struct intc_irqpin_priv *p = platform_get_drvdata(pdev);
  485. irq_domain_remove(p->irq_domain);
  486. pm_runtime_put(&pdev->dev);
  487. pm_runtime_disable(&pdev->dev);
  488. return 0;
  489. }
  490. static int __maybe_unused intc_irqpin_suspend(struct device *dev)
  491. {
  492. struct intc_irqpin_priv *p = dev_get_drvdata(dev);
  493. if (atomic_read(&p->wakeup_path))
  494. device_set_wakeup_path(dev);
  495. return 0;
  496. }
  497. static SIMPLE_DEV_PM_OPS(intc_irqpin_pm_ops, intc_irqpin_suspend, NULL);
  498. static struct platform_driver intc_irqpin_device_driver = {
  499. .probe = intc_irqpin_probe,
  500. .remove = intc_irqpin_remove,
  501. .driver = {
  502. .name = "renesas_intc_irqpin",
  503. .of_match_table = intc_irqpin_dt_ids,
  504. .pm = &intc_irqpin_pm_ops,
  505. }
  506. };
  507. static int __init intc_irqpin_init(void)
  508. {
  509. return platform_driver_register(&intc_irqpin_device_driver);
  510. }
  511. postcore_initcall(intc_irqpin_init);
  512. static void __exit intc_irqpin_exit(void)
  513. {
  514. platform_driver_unregister(&intc_irqpin_device_driver);
  515. }
  516. module_exit(intc_irqpin_exit);
  517. MODULE_AUTHOR("Magnus Damm");
  518. MODULE_DESCRIPTION("Renesas INTC External IRQ Pin Driver");
  519. MODULE_LICENSE("GPL v2");