generic-chip.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Library implementing the most common irq chip callback functions
  4. *
  5. * Copyright (C) 2011, Thomas Gleixner
  6. */
  7. #include <linux/io.h>
  8. #include <linux/irq.h>
  9. #include <linux/slab.h>
  10. #include <linux/export.h>
  11. #include <linux/irqdomain.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/kernel_stat.h>
  14. #include <linux/syscore_ops.h>
  15. #include "internals.h"
  16. static LIST_HEAD(gc_list);
  17. static DEFINE_RAW_SPINLOCK(gc_lock);
  18. /**
  19. * irq_gc_noop - NOOP function
  20. * @d: irq_data
  21. */
  22. void irq_gc_noop(struct irq_data *d)
  23. {
  24. }
  25. /**
  26. * irq_gc_mask_disable_reg - Mask chip via disable register
  27. * @d: irq_data
  28. *
  29. * Chip has separate enable/disable registers instead of a single mask
  30. * register.
  31. */
  32. void irq_gc_mask_disable_reg(struct irq_data *d)
  33. {
  34. struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
  35. struct irq_chip_type *ct = irq_data_get_chip_type(d);
  36. u32 mask = d->mask;
  37. irq_gc_lock(gc);
  38. irq_reg_writel(gc, mask, ct->regs.disable);
  39. *ct->mask_cache &= ~mask;
  40. irq_gc_unlock(gc);
  41. }
  42. /**
  43. * irq_gc_mask_set_bit - Mask chip via setting bit in mask register
  44. * @d: irq_data
  45. *
  46. * Chip has a single mask register. Values of this register are cached
  47. * and protected by gc->lock
  48. */
  49. void irq_gc_mask_set_bit(struct irq_data *d)
  50. {
  51. struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
  52. struct irq_chip_type *ct = irq_data_get_chip_type(d);
  53. u32 mask = d->mask;
  54. irq_gc_lock(gc);
  55. *ct->mask_cache |= mask;
  56. irq_reg_writel(gc, *ct->mask_cache, ct->regs.mask);
  57. irq_gc_unlock(gc);
  58. }
  59. EXPORT_SYMBOL_GPL(irq_gc_mask_set_bit);
  60. /**
  61. * irq_gc_mask_clr_bit - Mask chip via clearing bit in mask register
  62. * @d: irq_data
  63. *
  64. * Chip has a single mask register. Values of this register are cached
  65. * and protected by gc->lock
  66. */
  67. void irq_gc_mask_clr_bit(struct irq_data *d)
  68. {
  69. struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
  70. struct irq_chip_type *ct = irq_data_get_chip_type(d);
  71. u32 mask = d->mask;
  72. irq_gc_lock(gc);
  73. *ct->mask_cache &= ~mask;
  74. irq_reg_writel(gc, *ct->mask_cache, ct->regs.mask);
  75. irq_gc_unlock(gc);
  76. }
  77. EXPORT_SYMBOL_GPL(irq_gc_mask_clr_bit);
  78. /**
  79. * irq_gc_unmask_enable_reg - Unmask chip via enable register
  80. * @d: irq_data
  81. *
  82. * Chip has separate enable/disable registers instead of a single mask
  83. * register.
  84. */
  85. void irq_gc_unmask_enable_reg(struct irq_data *d)
  86. {
  87. struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
  88. struct irq_chip_type *ct = irq_data_get_chip_type(d);
  89. u32 mask = d->mask;
  90. irq_gc_lock(gc);
  91. irq_reg_writel(gc, mask, ct->regs.enable);
  92. *ct->mask_cache |= mask;
  93. irq_gc_unlock(gc);
  94. }
  95. /**
  96. * irq_gc_ack_set_bit - Ack pending interrupt via setting bit
  97. * @d: irq_data
  98. */
  99. void irq_gc_ack_set_bit(struct irq_data *d)
  100. {
  101. struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
  102. struct irq_chip_type *ct = irq_data_get_chip_type(d);
  103. u32 mask = d->mask;
  104. irq_gc_lock(gc);
  105. irq_reg_writel(gc, mask, ct->regs.ack);
  106. irq_gc_unlock(gc);
  107. }
  108. EXPORT_SYMBOL_GPL(irq_gc_ack_set_bit);
  109. /**
  110. * irq_gc_ack_clr_bit - Ack pending interrupt via clearing bit
  111. * @d: irq_data
  112. */
  113. void irq_gc_ack_clr_bit(struct irq_data *d)
  114. {
  115. struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
  116. struct irq_chip_type *ct = irq_data_get_chip_type(d);
  117. u32 mask = ~d->mask;
  118. irq_gc_lock(gc);
  119. irq_reg_writel(gc, mask, ct->regs.ack);
  120. irq_gc_unlock(gc);
  121. }
  122. /**
  123. * irq_gc_mask_disable_and_ack_set - Mask and ack pending interrupt
  124. * @d: irq_data
  125. *
  126. * This generic implementation of the irq_mask_ack method is for chips
  127. * with separate enable/disable registers instead of a single mask
  128. * register and where a pending interrupt is acknowledged by setting a
  129. * bit.
  130. *
  131. * Note: This is the only permutation currently used. Similar generic
  132. * functions should be added here if other permutations are required.
  133. */
  134. void irq_gc_mask_disable_and_ack_set(struct irq_data *d)
  135. {
  136. struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
  137. struct irq_chip_type *ct = irq_data_get_chip_type(d);
  138. u32 mask = d->mask;
  139. irq_gc_lock(gc);
  140. irq_reg_writel(gc, mask, ct->regs.disable);
  141. *ct->mask_cache &= ~mask;
  142. irq_reg_writel(gc, mask, ct->regs.ack);
  143. irq_gc_unlock(gc);
  144. }
  145. /**
  146. * irq_gc_eoi - EOI interrupt
  147. * @d: irq_data
  148. */
  149. void irq_gc_eoi(struct irq_data *d)
  150. {
  151. struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
  152. struct irq_chip_type *ct = irq_data_get_chip_type(d);
  153. u32 mask = d->mask;
  154. irq_gc_lock(gc);
  155. irq_reg_writel(gc, mask, ct->regs.eoi);
  156. irq_gc_unlock(gc);
  157. }
  158. /**
  159. * irq_gc_set_wake - Set/clr wake bit for an interrupt
  160. * @d: irq_data
  161. * @on: Indicates whether the wake bit should be set or cleared
  162. *
  163. * For chips where the wake from suspend functionality is not
  164. * configured in a separate register and the wakeup active state is
  165. * just stored in a bitmask.
  166. */
  167. int irq_gc_set_wake(struct irq_data *d, unsigned int on)
  168. {
  169. struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
  170. u32 mask = d->mask;
  171. if (!(mask & gc->wake_enabled))
  172. return -EINVAL;
  173. irq_gc_lock(gc);
  174. if (on)
  175. gc->wake_active |= mask;
  176. else
  177. gc->wake_active &= ~mask;
  178. irq_gc_unlock(gc);
  179. return 0;
  180. }
  181. static u32 irq_readl_be(void __iomem *addr)
  182. {
  183. return ioread32be(addr);
  184. }
  185. static void irq_writel_be(u32 val, void __iomem *addr)
  186. {
  187. iowrite32be(val, addr);
  188. }
  189. void irq_init_generic_chip(struct irq_chip_generic *gc, const char *name,
  190. int num_ct, unsigned int irq_base,
  191. void __iomem *reg_base, irq_flow_handler_t handler)
  192. {
  193. raw_spin_lock_init(&gc->lock);
  194. gc->num_ct = num_ct;
  195. gc->irq_base = irq_base;
  196. gc->reg_base = reg_base;
  197. gc->chip_types->chip.name = name;
  198. gc->chip_types->handler = handler;
  199. }
  200. /**
  201. * irq_alloc_generic_chip - Allocate a generic chip and initialize it
  202. * @name: Name of the irq chip
  203. * @num_ct: Number of irq_chip_type instances associated with this
  204. * @irq_base: Interrupt base nr for this chip
  205. * @reg_base: Register base address (virtual)
  206. * @handler: Default flow handler associated with this chip
  207. *
  208. * Returns an initialized irq_chip_generic structure. The chip defaults
  209. * to the primary (index 0) irq_chip_type and @handler
  210. */
  211. struct irq_chip_generic *
  212. irq_alloc_generic_chip(const char *name, int num_ct, unsigned int irq_base,
  213. void __iomem *reg_base, irq_flow_handler_t handler)
  214. {
  215. struct irq_chip_generic *gc;
  216. unsigned long sz = sizeof(*gc) + num_ct * sizeof(struct irq_chip_type);
  217. gc = kzalloc(sz, GFP_KERNEL);
  218. if (gc) {
  219. irq_init_generic_chip(gc, name, num_ct, irq_base, reg_base,
  220. handler);
  221. }
  222. return gc;
  223. }
  224. EXPORT_SYMBOL_GPL(irq_alloc_generic_chip);
  225. static void
  226. irq_gc_init_mask_cache(struct irq_chip_generic *gc, enum irq_gc_flags flags)
  227. {
  228. struct irq_chip_type *ct = gc->chip_types;
  229. u32 *mskptr = &gc->mask_cache, mskreg = ct->regs.mask;
  230. int i;
  231. for (i = 0; i < gc->num_ct; i++) {
  232. if (flags & IRQ_GC_MASK_CACHE_PER_TYPE) {
  233. mskptr = &ct[i].mask_cache_priv;
  234. mskreg = ct[i].regs.mask;
  235. }
  236. ct[i].mask_cache = mskptr;
  237. if (flags & IRQ_GC_INIT_MASK_CACHE)
  238. *mskptr = irq_reg_readl(gc, mskreg);
  239. }
  240. }
  241. /**
  242. * __irq_alloc_domain_generic_chip - Allocate generic chips for an irq domain
  243. * @d: irq domain for which to allocate chips
  244. * @irqs_per_chip: Number of interrupts each chip handles (max 32)
  245. * @num_ct: Number of irq_chip_type instances associated with this
  246. * @name: Name of the irq chip
  247. * @handler: Default flow handler associated with these chips
  248. * @clr: IRQ_* bits to clear in the mapping function
  249. * @set: IRQ_* bits to set in the mapping function
  250. * @gcflags: Generic chip specific setup flags
  251. */
  252. int __irq_alloc_domain_generic_chips(struct irq_domain *d, int irqs_per_chip,
  253. int num_ct, const char *name,
  254. irq_flow_handler_t handler,
  255. unsigned int clr, unsigned int set,
  256. enum irq_gc_flags gcflags)
  257. {
  258. struct irq_domain_chip_generic *dgc;
  259. struct irq_chip_generic *gc;
  260. int numchips, sz, i;
  261. unsigned long flags;
  262. void *tmp;
  263. if (d->gc)
  264. return -EBUSY;
  265. numchips = DIV_ROUND_UP(d->revmap_size, irqs_per_chip);
  266. if (!numchips)
  267. return -EINVAL;
  268. /* Allocate a pointer, generic chip and chiptypes for each chip */
  269. sz = sizeof(*dgc) + numchips * sizeof(gc);
  270. sz += numchips * (sizeof(*gc) + num_ct * sizeof(struct irq_chip_type));
  271. tmp = dgc = kzalloc(sz, GFP_KERNEL);
  272. if (!dgc)
  273. return -ENOMEM;
  274. dgc->irqs_per_chip = irqs_per_chip;
  275. dgc->num_chips = numchips;
  276. dgc->irq_flags_to_set = set;
  277. dgc->irq_flags_to_clear = clr;
  278. dgc->gc_flags = gcflags;
  279. d->gc = dgc;
  280. /* Calc pointer to the first generic chip */
  281. tmp += sizeof(*dgc) + numchips * sizeof(gc);
  282. for (i = 0; i < numchips; i++) {
  283. /* Store the pointer to the generic chip */
  284. dgc->gc[i] = gc = tmp;
  285. irq_init_generic_chip(gc, name, num_ct, i * irqs_per_chip,
  286. NULL, handler);
  287. gc->domain = d;
  288. if (gcflags & IRQ_GC_BE_IO) {
  289. gc->reg_readl = &irq_readl_be;
  290. gc->reg_writel = &irq_writel_be;
  291. }
  292. raw_spin_lock_irqsave(&gc_lock, flags);
  293. list_add_tail(&gc->list, &gc_list);
  294. raw_spin_unlock_irqrestore(&gc_lock, flags);
  295. /* Calc pointer to the next generic chip */
  296. tmp += sizeof(*gc) + num_ct * sizeof(struct irq_chip_type);
  297. }
  298. return 0;
  299. }
  300. EXPORT_SYMBOL_GPL(__irq_alloc_domain_generic_chips);
  301. static struct irq_chip_generic *
  302. __irq_get_domain_generic_chip(struct irq_domain *d, unsigned int hw_irq)
  303. {
  304. struct irq_domain_chip_generic *dgc = d->gc;
  305. int idx;
  306. if (!dgc)
  307. return ERR_PTR(-ENODEV);
  308. idx = hw_irq / dgc->irqs_per_chip;
  309. if (idx >= dgc->num_chips)
  310. return ERR_PTR(-EINVAL);
  311. return dgc->gc[idx];
  312. }
  313. /**
  314. * irq_get_domain_generic_chip - Get a pointer to the generic chip of a hw_irq
  315. * @d: irq domain pointer
  316. * @hw_irq: Hardware interrupt number
  317. */
  318. struct irq_chip_generic *
  319. irq_get_domain_generic_chip(struct irq_domain *d, unsigned int hw_irq)
  320. {
  321. struct irq_chip_generic *gc = __irq_get_domain_generic_chip(d, hw_irq);
  322. return !IS_ERR(gc) ? gc : NULL;
  323. }
  324. EXPORT_SYMBOL_GPL(irq_get_domain_generic_chip);
  325. /*
  326. * Separate lockdep classes for interrupt chip which can nest irq_desc
  327. * lock and request mutex.
  328. */
  329. static struct lock_class_key irq_nested_lock_class;
  330. static struct lock_class_key irq_nested_request_class;
  331. /*
  332. * irq_map_generic_chip - Map a generic chip for an irq domain
  333. */
  334. int irq_map_generic_chip(struct irq_domain *d, unsigned int virq,
  335. irq_hw_number_t hw_irq)
  336. {
  337. struct irq_data *data = irq_domain_get_irq_data(d, virq);
  338. struct irq_domain_chip_generic *dgc = d->gc;
  339. struct irq_chip_generic *gc;
  340. struct irq_chip_type *ct;
  341. struct irq_chip *chip;
  342. unsigned long flags;
  343. int idx;
  344. gc = __irq_get_domain_generic_chip(d, hw_irq);
  345. if (IS_ERR(gc))
  346. return PTR_ERR(gc);
  347. idx = hw_irq % dgc->irqs_per_chip;
  348. if (test_bit(idx, &gc->unused))
  349. return -ENOTSUPP;
  350. if (test_bit(idx, &gc->installed))
  351. return -EBUSY;
  352. ct = gc->chip_types;
  353. chip = &ct->chip;
  354. /* We only init the cache for the first mapping of a generic chip */
  355. if (!gc->installed) {
  356. raw_spin_lock_irqsave(&gc->lock, flags);
  357. irq_gc_init_mask_cache(gc, dgc->gc_flags);
  358. raw_spin_unlock_irqrestore(&gc->lock, flags);
  359. }
  360. /* Mark the interrupt as installed */
  361. set_bit(idx, &gc->installed);
  362. if (dgc->gc_flags & IRQ_GC_INIT_NESTED_LOCK)
  363. irq_set_lockdep_class(virq, &irq_nested_lock_class,
  364. &irq_nested_request_class);
  365. if (chip->irq_calc_mask)
  366. chip->irq_calc_mask(data);
  367. else
  368. data->mask = 1 << idx;
  369. irq_domain_set_info(d, virq, hw_irq, chip, gc, ct->handler, NULL, NULL);
  370. irq_modify_status(virq, dgc->irq_flags_to_clear, dgc->irq_flags_to_set);
  371. return 0;
  372. }
  373. static void irq_unmap_generic_chip(struct irq_domain *d, unsigned int virq)
  374. {
  375. struct irq_data *data = irq_domain_get_irq_data(d, virq);
  376. struct irq_domain_chip_generic *dgc = d->gc;
  377. unsigned int hw_irq = data->hwirq;
  378. struct irq_chip_generic *gc;
  379. int irq_idx;
  380. gc = irq_get_domain_generic_chip(d, hw_irq);
  381. if (!gc)
  382. return;
  383. irq_idx = hw_irq % dgc->irqs_per_chip;
  384. clear_bit(irq_idx, &gc->installed);
  385. irq_domain_set_info(d, virq, hw_irq, &no_irq_chip, NULL, NULL, NULL,
  386. NULL);
  387. }
  388. struct irq_domain_ops irq_generic_chip_ops = {
  389. .map = irq_map_generic_chip,
  390. .unmap = irq_unmap_generic_chip,
  391. .xlate = irq_domain_xlate_onetwocell,
  392. };
  393. EXPORT_SYMBOL_GPL(irq_generic_chip_ops);
  394. /**
  395. * irq_setup_generic_chip - Setup a range of interrupts with a generic chip
  396. * @gc: Generic irq chip holding all data
  397. * @msk: Bitmask holding the irqs to initialize relative to gc->irq_base
  398. * @flags: Flags for initialization
  399. * @clr: IRQ_* bits to clear
  400. * @set: IRQ_* bits to set
  401. *
  402. * Set up max. 32 interrupts starting from gc->irq_base. Note, this
  403. * initializes all interrupts to the primary irq_chip_type and its
  404. * associated handler.
  405. */
  406. void irq_setup_generic_chip(struct irq_chip_generic *gc, u32 msk,
  407. enum irq_gc_flags flags, unsigned int clr,
  408. unsigned int set)
  409. {
  410. struct irq_chip_type *ct = gc->chip_types;
  411. struct irq_chip *chip = &ct->chip;
  412. unsigned int i;
  413. raw_spin_lock(&gc_lock);
  414. list_add_tail(&gc->list, &gc_list);
  415. raw_spin_unlock(&gc_lock);
  416. irq_gc_init_mask_cache(gc, flags);
  417. for (i = gc->irq_base; msk; msk >>= 1, i++) {
  418. if (!(msk & 0x01))
  419. continue;
  420. if (flags & IRQ_GC_INIT_NESTED_LOCK)
  421. irq_set_lockdep_class(i, &irq_nested_lock_class,
  422. &irq_nested_request_class);
  423. if (!(flags & IRQ_GC_NO_MASK)) {
  424. struct irq_data *d = irq_get_irq_data(i);
  425. if (chip->irq_calc_mask)
  426. chip->irq_calc_mask(d);
  427. else
  428. d->mask = 1 << (i - gc->irq_base);
  429. }
  430. irq_set_chip_and_handler(i, chip, ct->handler);
  431. irq_set_chip_data(i, gc);
  432. irq_modify_status(i, clr, set);
  433. }
  434. gc->irq_cnt = i - gc->irq_base;
  435. }
  436. EXPORT_SYMBOL_GPL(irq_setup_generic_chip);
  437. /**
  438. * irq_setup_alt_chip - Switch to alternative chip
  439. * @d: irq_data for this interrupt
  440. * @type: Flow type to be initialized
  441. *
  442. * Only to be called from chip->irq_set_type() callbacks.
  443. */
  444. int irq_setup_alt_chip(struct irq_data *d, unsigned int type)
  445. {
  446. struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
  447. struct irq_chip_type *ct = gc->chip_types;
  448. unsigned int i;
  449. for (i = 0; i < gc->num_ct; i++, ct++) {
  450. if (ct->type & type) {
  451. d->chip = &ct->chip;
  452. irq_data_to_desc(d)->handle_irq = ct->handler;
  453. return 0;
  454. }
  455. }
  456. return -EINVAL;
  457. }
  458. EXPORT_SYMBOL_GPL(irq_setup_alt_chip);
  459. /**
  460. * irq_remove_generic_chip - Remove a chip
  461. * @gc: Generic irq chip holding all data
  462. * @msk: Bitmask holding the irqs to initialize relative to gc->irq_base
  463. * @clr: IRQ_* bits to clear
  464. * @set: IRQ_* bits to set
  465. *
  466. * Remove up to 32 interrupts starting from gc->irq_base.
  467. */
  468. void irq_remove_generic_chip(struct irq_chip_generic *gc, u32 msk,
  469. unsigned int clr, unsigned int set)
  470. {
  471. unsigned int i = gc->irq_base;
  472. raw_spin_lock(&gc_lock);
  473. list_del(&gc->list);
  474. raw_spin_unlock(&gc_lock);
  475. for (; msk; msk >>= 1, i++) {
  476. if (!(msk & 0x01))
  477. continue;
  478. /* Remove handler first. That will mask the irq line */
  479. irq_set_handler(i, NULL);
  480. irq_set_chip(i, &no_irq_chip);
  481. irq_set_chip_data(i, NULL);
  482. irq_modify_status(i, clr, set);
  483. }
  484. }
  485. EXPORT_SYMBOL_GPL(irq_remove_generic_chip);
  486. static struct irq_data *irq_gc_get_irq_data(struct irq_chip_generic *gc)
  487. {
  488. unsigned int virq;
  489. if (!gc->domain)
  490. return irq_get_irq_data(gc->irq_base);
  491. /*
  492. * We don't know which of the irqs has been actually
  493. * installed. Use the first one.
  494. */
  495. if (!gc->installed)
  496. return NULL;
  497. virq = irq_find_mapping(gc->domain, gc->irq_base + __ffs(gc->installed));
  498. return virq ? irq_get_irq_data(virq) : NULL;
  499. }
  500. #ifdef CONFIG_PM
  501. static int irq_gc_suspend(void)
  502. {
  503. struct irq_chip_generic *gc;
  504. list_for_each_entry(gc, &gc_list, list) {
  505. struct irq_chip_type *ct = gc->chip_types;
  506. if (ct->chip.irq_suspend) {
  507. struct irq_data *data = irq_gc_get_irq_data(gc);
  508. if (data)
  509. ct->chip.irq_suspend(data);
  510. }
  511. if (gc->suspend)
  512. gc->suspend(gc);
  513. }
  514. return 0;
  515. }
  516. static void irq_gc_resume(void)
  517. {
  518. struct irq_chip_generic *gc;
  519. list_for_each_entry(gc, &gc_list, list) {
  520. struct irq_chip_type *ct = gc->chip_types;
  521. if (gc->resume)
  522. gc->resume(gc);
  523. if (ct->chip.irq_resume) {
  524. struct irq_data *data = irq_gc_get_irq_data(gc);
  525. if (data)
  526. ct->chip.irq_resume(data);
  527. }
  528. }
  529. }
  530. #else
  531. #define irq_gc_suspend NULL
  532. #define irq_gc_resume NULL
  533. #endif
  534. static void irq_gc_shutdown(void)
  535. {
  536. struct irq_chip_generic *gc;
  537. list_for_each_entry(gc, &gc_list, list) {
  538. struct irq_chip_type *ct = gc->chip_types;
  539. if (ct->chip.irq_pm_shutdown) {
  540. struct irq_data *data = irq_gc_get_irq_data(gc);
  541. if (data)
  542. ct->chip.irq_pm_shutdown(data);
  543. }
  544. }
  545. }
  546. static struct syscore_ops irq_gc_syscore_ops = {
  547. .suspend = irq_gc_suspend,
  548. .resume = irq_gc_resume,
  549. .shutdown = irq_gc_shutdown,
  550. };
  551. static int __init irq_gc_init_ops(void)
  552. {
  553. register_syscore_ops(&irq_gc_syscore_ops);
  554. return 0;
  555. }
  556. device_initcall(irq_gc_init_ops);