generic-chip.c 16 KB

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