gpio-pxa.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. /*
  2. * linux/arch/arm/plat-pxa/gpio.c
  3. *
  4. * Generic PXA GPIO handling
  5. *
  6. * Author: Nicolas Pitre
  7. * Created: Jun 15, 2001
  8. * Copyright: MontaVista Software Inc.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #include <linux/clk.h>
  15. #include <linux/err.h>
  16. #include <linux/gpio.h>
  17. #include <linux/gpio-pxa.h>
  18. #include <linux/init.h>
  19. #include <linux/irq.h>
  20. #include <linux/io.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/syscore_ops.h>
  23. #include <linux/slab.h>
  24. #include <mach/irqs.h>
  25. /*
  26. * We handle the GPIOs by banks, each bank covers up to 32 GPIOs with
  27. * one set of registers. The register offsets are organized below:
  28. *
  29. * GPLR GPDR GPSR GPCR GRER GFER GEDR
  30. * BANK 0 - 0x0000 0x000C 0x0018 0x0024 0x0030 0x003C 0x0048
  31. * BANK 1 - 0x0004 0x0010 0x001C 0x0028 0x0034 0x0040 0x004C
  32. * BANK 2 - 0x0008 0x0014 0x0020 0x002C 0x0038 0x0044 0x0050
  33. *
  34. * BANK 3 - 0x0100 0x010C 0x0118 0x0124 0x0130 0x013C 0x0148
  35. * BANK 4 - 0x0104 0x0110 0x011C 0x0128 0x0134 0x0140 0x014C
  36. * BANK 5 - 0x0108 0x0114 0x0120 0x012C 0x0138 0x0144 0x0150
  37. *
  38. * NOTE:
  39. * BANK 3 is only available on PXA27x and later processors.
  40. * BANK 4 and 5 are only available on PXA935
  41. */
  42. #define GPLR_OFFSET 0x00
  43. #define GPDR_OFFSET 0x0C
  44. #define GPSR_OFFSET 0x18
  45. #define GPCR_OFFSET 0x24
  46. #define GRER_OFFSET 0x30
  47. #define GFER_OFFSET 0x3C
  48. #define GEDR_OFFSET 0x48
  49. #define GAFR_OFFSET 0x54
  50. #define ED_MASK_OFFSET 0x9C /* GPIO edge detection for AP side */
  51. #define BANK_OFF(n) (((n) < 3) ? (n) << 2 : 0x100 + (((n) - 3) << 2))
  52. int pxa_last_gpio;
  53. struct pxa_gpio_chip {
  54. struct gpio_chip chip;
  55. void __iomem *regbase;
  56. char label[10];
  57. unsigned long irq_mask;
  58. unsigned long irq_edge_rise;
  59. unsigned long irq_edge_fall;
  60. #ifdef CONFIG_PM
  61. unsigned long saved_gplr;
  62. unsigned long saved_gpdr;
  63. unsigned long saved_grer;
  64. unsigned long saved_gfer;
  65. #endif
  66. };
  67. enum {
  68. PXA25X_GPIO = 0,
  69. PXA26X_GPIO,
  70. PXA27X_GPIO,
  71. PXA3XX_GPIO,
  72. PXA93X_GPIO,
  73. MMP_GPIO = 0x10,
  74. MMP2_GPIO,
  75. };
  76. static DEFINE_SPINLOCK(gpio_lock);
  77. static struct pxa_gpio_chip *pxa_gpio_chips;
  78. static int gpio_type;
  79. static void __iomem *gpio_reg_base;
  80. #define for_each_gpio_chip(i, c) \
  81. for (i = 0, c = &pxa_gpio_chips[0]; i <= pxa_last_gpio; i += 32, c++)
  82. static inline void __iomem *gpio_chip_base(struct gpio_chip *c)
  83. {
  84. return container_of(c, struct pxa_gpio_chip, chip)->regbase;
  85. }
  86. static inline struct pxa_gpio_chip *gpio_to_pxachip(unsigned gpio)
  87. {
  88. return &pxa_gpio_chips[gpio_to_bank(gpio)];
  89. }
  90. static inline int gpio_is_pxa_type(int type)
  91. {
  92. return (type & MMP_GPIO) == 0;
  93. }
  94. static inline int gpio_is_mmp_type(int type)
  95. {
  96. return (type & MMP_GPIO) != 0;
  97. }
  98. /* GPIO86/87/88/89 on PXA26x have their direction bits in PXA_GPDR(2 inverted,
  99. * as well as their Alternate Function value being '1' for GPIO in GAFRx.
  100. */
  101. static inline int __gpio_is_inverted(int gpio)
  102. {
  103. if ((gpio_type == PXA26X_GPIO) && (gpio > 85))
  104. return 1;
  105. return 0;
  106. }
  107. /*
  108. * On PXA25x and PXA27x, GAFRx and GPDRx together decide the alternate
  109. * function of a GPIO, and GPDRx cannot be altered once configured. It
  110. * is attributed as "occupied" here (I know this terminology isn't
  111. * accurate, you are welcome to propose a better one :-)
  112. */
  113. static inline int __gpio_is_occupied(unsigned gpio)
  114. {
  115. struct pxa_gpio_chip *pxachip;
  116. void __iomem *base;
  117. unsigned long gafr = 0, gpdr = 0;
  118. int ret, af = 0, dir = 0;
  119. pxachip = gpio_to_pxachip(gpio);
  120. base = gpio_chip_base(&pxachip->chip);
  121. gpdr = readl_relaxed(base + GPDR_OFFSET);
  122. switch (gpio_type) {
  123. case PXA25X_GPIO:
  124. case PXA26X_GPIO:
  125. case PXA27X_GPIO:
  126. gafr = readl_relaxed(base + GAFR_OFFSET);
  127. af = (gafr >> ((gpio & 0xf) * 2)) & 0x3;
  128. dir = gpdr & GPIO_bit(gpio);
  129. if (__gpio_is_inverted(gpio))
  130. ret = (af != 1) || (dir == 0);
  131. else
  132. ret = (af != 0) || (dir != 0);
  133. break;
  134. default:
  135. ret = gpdr & GPIO_bit(gpio);
  136. break;
  137. }
  138. return ret;
  139. }
  140. #ifdef CONFIG_ARCH_PXA
  141. static inline int __pxa_gpio_to_irq(int gpio)
  142. {
  143. if (gpio_is_pxa_type(gpio_type))
  144. return PXA_GPIO_TO_IRQ(gpio);
  145. return -1;
  146. }
  147. static inline int __pxa_irq_to_gpio(int irq)
  148. {
  149. if (gpio_is_pxa_type(gpio_type))
  150. return irq - PXA_GPIO_TO_IRQ(0);
  151. return -1;
  152. }
  153. #else
  154. static inline int __pxa_gpio_to_irq(int gpio) { return -1; }
  155. static inline int __pxa_irq_to_gpio(int irq) { return -1; }
  156. #endif
  157. #ifdef CONFIG_ARCH_MMP
  158. static inline int __mmp_gpio_to_irq(int gpio)
  159. {
  160. if (gpio_is_mmp_type(gpio_type))
  161. return MMP_GPIO_TO_IRQ(gpio);
  162. return -1;
  163. }
  164. static inline int __mmp_irq_to_gpio(int irq)
  165. {
  166. if (gpio_is_mmp_type(gpio_type))
  167. return irq - MMP_GPIO_TO_IRQ(0);
  168. return -1;
  169. }
  170. #else
  171. static inline int __mmp_gpio_to_irq(int gpio) { return -1; }
  172. static inline int __mmp_irq_to_gpio(int irq) { return -1; }
  173. #endif
  174. static int pxa_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
  175. {
  176. int gpio, ret;
  177. gpio = chip->base + offset;
  178. ret = __pxa_gpio_to_irq(gpio);
  179. if (ret >= 0)
  180. return ret;
  181. return __mmp_gpio_to_irq(gpio);
  182. }
  183. int pxa_irq_to_gpio(int irq)
  184. {
  185. int ret;
  186. ret = __pxa_irq_to_gpio(irq);
  187. if (ret >= 0)
  188. return ret;
  189. return __mmp_irq_to_gpio(irq);
  190. }
  191. static int pxa_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
  192. {
  193. void __iomem *base = gpio_chip_base(chip);
  194. uint32_t value, mask = 1 << offset;
  195. unsigned long flags;
  196. spin_lock_irqsave(&gpio_lock, flags);
  197. value = readl_relaxed(base + GPDR_OFFSET);
  198. if (__gpio_is_inverted(chip->base + offset))
  199. value |= mask;
  200. else
  201. value &= ~mask;
  202. writel_relaxed(value, base + GPDR_OFFSET);
  203. spin_unlock_irqrestore(&gpio_lock, flags);
  204. return 0;
  205. }
  206. static int pxa_gpio_direction_output(struct gpio_chip *chip,
  207. unsigned offset, int value)
  208. {
  209. void __iomem *base = gpio_chip_base(chip);
  210. uint32_t tmp, mask = 1 << offset;
  211. unsigned long flags;
  212. writel_relaxed(mask, base + (value ? GPSR_OFFSET : GPCR_OFFSET));
  213. spin_lock_irqsave(&gpio_lock, flags);
  214. tmp = readl_relaxed(base + GPDR_OFFSET);
  215. if (__gpio_is_inverted(chip->base + offset))
  216. tmp &= ~mask;
  217. else
  218. tmp |= mask;
  219. writel_relaxed(tmp, base + GPDR_OFFSET);
  220. spin_unlock_irqrestore(&gpio_lock, flags);
  221. return 0;
  222. }
  223. static int pxa_gpio_get(struct gpio_chip *chip, unsigned offset)
  224. {
  225. return readl_relaxed(gpio_chip_base(chip) + GPLR_OFFSET) & (1 << offset);
  226. }
  227. static void pxa_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
  228. {
  229. writel_relaxed(1 << offset, gpio_chip_base(chip) +
  230. (value ? GPSR_OFFSET : GPCR_OFFSET));
  231. }
  232. static int __devinit pxa_init_gpio_chip(int gpio_end)
  233. {
  234. int i, gpio, nbanks = gpio_to_bank(gpio_end) + 1;
  235. struct pxa_gpio_chip *chips;
  236. chips = kzalloc(nbanks * sizeof(struct pxa_gpio_chip), GFP_KERNEL);
  237. if (chips == NULL) {
  238. pr_err("%s: failed to allocate GPIO chips\n", __func__);
  239. return -ENOMEM;
  240. }
  241. for (i = 0, gpio = 0; i < nbanks; i++, gpio += 32) {
  242. struct gpio_chip *c = &chips[i].chip;
  243. sprintf(chips[i].label, "gpio-%d", i);
  244. chips[i].regbase = gpio_reg_base + BANK_OFF(i);
  245. c->base = gpio;
  246. c->label = chips[i].label;
  247. c->direction_input = pxa_gpio_direction_input;
  248. c->direction_output = pxa_gpio_direction_output;
  249. c->get = pxa_gpio_get;
  250. c->set = pxa_gpio_set;
  251. c->to_irq = pxa_gpio_to_irq;
  252. /* number of GPIOs on last bank may be less than 32 */
  253. c->ngpio = (gpio + 31 > gpio_end) ? (gpio_end - gpio + 1) : 32;
  254. gpiochip_add(c);
  255. }
  256. pxa_gpio_chips = chips;
  257. return 0;
  258. }
  259. /* Update only those GRERx and GFERx edge detection register bits if those
  260. * bits are set in c->irq_mask
  261. */
  262. static inline void update_edge_detect(struct pxa_gpio_chip *c)
  263. {
  264. uint32_t grer, gfer;
  265. grer = readl_relaxed(c->regbase + GRER_OFFSET) & ~c->irq_mask;
  266. gfer = readl_relaxed(c->regbase + GFER_OFFSET) & ~c->irq_mask;
  267. grer |= c->irq_edge_rise & c->irq_mask;
  268. gfer |= c->irq_edge_fall & c->irq_mask;
  269. writel_relaxed(grer, c->regbase + GRER_OFFSET);
  270. writel_relaxed(gfer, c->regbase + GFER_OFFSET);
  271. }
  272. static int pxa_gpio_irq_type(struct irq_data *d, unsigned int type)
  273. {
  274. struct pxa_gpio_chip *c;
  275. int gpio = pxa_irq_to_gpio(d->irq);
  276. unsigned long gpdr, mask = GPIO_bit(gpio);
  277. c = gpio_to_pxachip(gpio);
  278. if (type == IRQ_TYPE_PROBE) {
  279. /* Don't mess with enabled GPIOs using preconfigured edges or
  280. * GPIOs set to alternate function or to output during probe
  281. */
  282. if ((c->irq_edge_rise | c->irq_edge_fall) & GPIO_bit(gpio))
  283. return 0;
  284. if (__gpio_is_occupied(gpio))
  285. return 0;
  286. type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
  287. }
  288. gpdr = readl_relaxed(c->regbase + GPDR_OFFSET);
  289. if (__gpio_is_inverted(gpio))
  290. writel_relaxed(gpdr | mask, c->regbase + GPDR_OFFSET);
  291. else
  292. writel_relaxed(gpdr & ~mask, c->regbase + GPDR_OFFSET);
  293. if (type & IRQ_TYPE_EDGE_RISING)
  294. c->irq_edge_rise |= mask;
  295. else
  296. c->irq_edge_rise &= ~mask;
  297. if (type & IRQ_TYPE_EDGE_FALLING)
  298. c->irq_edge_fall |= mask;
  299. else
  300. c->irq_edge_fall &= ~mask;
  301. update_edge_detect(c);
  302. pr_debug("%s: IRQ%d (GPIO%d) - edge%s%s\n", __func__, d->irq, gpio,
  303. ((type & IRQ_TYPE_EDGE_RISING) ? " rising" : ""),
  304. ((type & IRQ_TYPE_EDGE_FALLING) ? " falling" : ""));
  305. return 0;
  306. }
  307. static void pxa_gpio_demux_handler(unsigned int irq, struct irq_desc *desc)
  308. {
  309. struct pxa_gpio_chip *c;
  310. int loop, gpio, gpio_base, n;
  311. unsigned long gedr;
  312. do {
  313. loop = 0;
  314. for_each_gpio_chip(gpio, c) {
  315. gpio_base = c->chip.base;
  316. gedr = readl_relaxed(c->regbase + GEDR_OFFSET);
  317. gedr = gedr & c->irq_mask;
  318. writel_relaxed(gedr, c->regbase + GEDR_OFFSET);
  319. n = find_first_bit(&gedr, BITS_PER_LONG);
  320. while (n < BITS_PER_LONG) {
  321. loop = 1;
  322. generic_handle_irq(gpio_to_irq(gpio_base + n));
  323. n = find_next_bit(&gedr, BITS_PER_LONG, n + 1);
  324. }
  325. }
  326. } while (loop);
  327. }
  328. static void pxa_ack_muxed_gpio(struct irq_data *d)
  329. {
  330. int gpio = pxa_irq_to_gpio(d->irq);
  331. struct pxa_gpio_chip *c = gpio_to_pxachip(gpio);
  332. writel_relaxed(GPIO_bit(gpio), c->regbase + GEDR_OFFSET);
  333. }
  334. static void pxa_mask_muxed_gpio(struct irq_data *d)
  335. {
  336. int gpio = pxa_irq_to_gpio(d->irq);
  337. struct pxa_gpio_chip *c = gpio_to_pxachip(gpio);
  338. uint32_t grer, gfer;
  339. c->irq_mask &= ~GPIO_bit(gpio);
  340. grer = readl_relaxed(c->regbase + GRER_OFFSET) & ~GPIO_bit(gpio);
  341. gfer = readl_relaxed(c->regbase + GFER_OFFSET) & ~GPIO_bit(gpio);
  342. writel_relaxed(grer, c->regbase + GRER_OFFSET);
  343. writel_relaxed(gfer, c->regbase + GFER_OFFSET);
  344. }
  345. static void pxa_unmask_muxed_gpio(struct irq_data *d)
  346. {
  347. int gpio = pxa_irq_to_gpio(d->irq);
  348. struct pxa_gpio_chip *c = gpio_to_pxachip(gpio);
  349. c->irq_mask |= GPIO_bit(gpio);
  350. update_edge_detect(c);
  351. }
  352. static struct irq_chip pxa_muxed_gpio_chip = {
  353. .name = "GPIO",
  354. .irq_ack = pxa_ack_muxed_gpio,
  355. .irq_mask = pxa_mask_muxed_gpio,
  356. .irq_unmask = pxa_unmask_muxed_gpio,
  357. .irq_set_type = pxa_gpio_irq_type,
  358. };
  359. static int pxa_gpio_nums(void)
  360. {
  361. int count = 0;
  362. #ifdef CONFIG_ARCH_PXA
  363. if (cpu_is_pxa25x()) {
  364. #ifdef CONFIG_CPU_PXA26x
  365. count = 89;
  366. gpio_type = PXA26X_GPIO;
  367. #elif defined(CONFIG_PXA25x)
  368. count = 84;
  369. gpio_type = PXA26X_GPIO;
  370. #endif /* CONFIG_CPU_PXA26x */
  371. } else if (cpu_is_pxa27x()) {
  372. count = 120;
  373. gpio_type = PXA27X_GPIO;
  374. } else if (cpu_is_pxa93x() || cpu_is_pxa95x()) {
  375. count = 191;
  376. gpio_type = PXA93X_GPIO;
  377. } else if (cpu_is_pxa3xx()) {
  378. count = 127;
  379. gpio_type = PXA3XX_GPIO;
  380. }
  381. #endif /* CONFIG_ARCH_PXA */
  382. #ifdef CONFIG_ARCH_MMP
  383. if (cpu_is_pxa168() || cpu_is_pxa910()) {
  384. count = 127;
  385. gpio_type = MMP_GPIO;
  386. } else if (cpu_is_mmp2()) {
  387. count = 191;
  388. gpio_type = MMP2_GPIO;
  389. }
  390. #endif /* CONFIG_ARCH_MMP */
  391. return count;
  392. }
  393. static int __devinit pxa_gpio_probe(struct platform_device *pdev)
  394. {
  395. struct pxa_gpio_chip *c;
  396. struct resource *res;
  397. struct clk *clk;
  398. int gpio, irq, ret;
  399. int irq0 = 0, irq1 = 0, irq_mux, gpio_offset = 0;
  400. pxa_last_gpio = pxa_gpio_nums();
  401. if (!pxa_last_gpio)
  402. return -EINVAL;
  403. irq0 = platform_get_irq_byname(pdev, "gpio0");
  404. irq1 = platform_get_irq_byname(pdev, "gpio1");
  405. irq_mux = platform_get_irq_byname(pdev, "gpio_mux");
  406. if ((irq0 > 0 && irq1 <= 0) || (irq0 <= 0 && irq1 > 0)
  407. || (irq_mux <= 0))
  408. return -EINVAL;
  409. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  410. if (!res)
  411. return -EINVAL;
  412. gpio_reg_base = ioremap(res->start, resource_size(res));
  413. if (!gpio_reg_base)
  414. return -EINVAL;
  415. if (irq0 > 0)
  416. gpio_offset = 2;
  417. clk = clk_get(&pdev->dev, NULL);
  418. if (IS_ERR(clk)) {
  419. dev_err(&pdev->dev, "Error %ld to get gpio clock\n",
  420. PTR_ERR(clk));
  421. iounmap(gpio_reg_base);
  422. return PTR_ERR(clk);
  423. }
  424. ret = clk_prepare(clk);
  425. if (ret) {
  426. clk_put(clk);
  427. iounmap(gpio_reg_base);
  428. return ret;
  429. }
  430. ret = clk_enable(clk);
  431. if (ret) {
  432. clk_unprepare(clk);
  433. clk_put(clk);
  434. iounmap(gpio_reg_base);
  435. return ret;
  436. }
  437. /* Initialize GPIO chips */
  438. pxa_init_gpio_chip(pxa_last_gpio);
  439. /* clear all GPIO edge detects */
  440. for_each_gpio_chip(gpio, c) {
  441. writel_relaxed(0, c->regbase + GFER_OFFSET);
  442. writel_relaxed(0, c->regbase + GRER_OFFSET);
  443. writel_relaxed(~0,c->regbase + GEDR_OFFSET);
  444. /* unmask GPIO edge detect for AP side */
  445. if (gpio_is_mmp_type(gpio_type))
  446. writel_relaxed(~0, c->regbase + ED_MASK_OFFSET);
  447. }
  448. #ifdef CONFIG_ARCH_PXA
  449. irq = gpio_to_irq(0);
  450. irq_set_chip_and_handler(irq, &pxa_muxed_gpio_chip,
  451. handle_edge_irq);
  452. set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
  453. irq_set_chained_handler(IRQ_GPIO0, pxa_gpio_demux_handler);
  454. irq = gpio_to_irq(1);
  455. irq_set_chip_and_handler(irq, &pxa_muxed_gpio_chip,
  456. handle_edge_irq);
  457. set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
  458. irq_set_chained_handler(IRQ_GPIO1, pxa_gpio_demux_handler);
  459. #endif
  460. for (irq = gpio_to_irq(gpio_offset);
  461. irq <= gpio_to_irq(pxa_last_gpio); irq++) {
  462. irq_set_chip_and_handler(irq, &pxa_muxed_gpio_chip,
  463. handle_edge_irq);
  464. set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
  465. }
  466. irq_set_chained_handler(irq_mux, pxa_gpio_demux_handler);
  467. return 0;
  468. }
  469. static struct platform_driver pxa_gpio_driver = {
  470. .probe = pxa_gpio_probe,
  471. .driver = {
  472. .name = "pxa-gpio",
  473. },
  474. };
  475. static int __init pxa_gpio_init(void)
  476. {
  477. return platform_driver_register(&pxa_gpio_driver);
  478. }
  479. postcore_initcall(pxa_gpio_init);
  480. #ifdef CONFIG_PM
  481. static int pxa_gpio_suspend(void)
  482. {
  483. struct pxa_gpio_chip *c;
  484. int gpio;
  485. for_each_gpio_chip(gpio, c) {
  486. c->saved_gplr = readl_relaxed(c->regbase + GPLR_OFFSET);
  487. c->saved_gpdr = readl_relaxed(c->regbase + GPDR_OFFSET);
  488. c->saved_grer = readl_relaxed(c->regbase + GRER_OFFSET);
  489. c->saved_gfer = readl_relaxed(c->regbase + GFER_OFFSET);
  490. /* Clear GPIO transition detect bits */
  491. writel_relaxed(0xffffffff, c->regbase + GEDR_OFFSET);
  492. }
  493. return 0;
  494. }
  495. static void pxa_gpio_resume(void)
  496. {
  497. struct pxa_gpio_chip *c;
  498. int gpio;
  499. for_each_gpio_chip(gpio, c) {
  500. /* restore level with set/clear */
  501. writel_relaxed( c->saved_gplr, c->regbase + GPSR_OFFSET);
  502. writel_relaxed(~c->saved_gplr, c->regbase + GPCR_OFFSET);
  503. writel_relaxed(c->saved_grer, c->regbase + GRER_OFFSET);
  504. writel_relaxed(c->saved_gfer, c->regbase + GFER_OFFSET);
  505. writel_relaxed(c->saved_gpdr, c->regbase + GPDR_OFFSET);
  506. }
  507. }
  508. #else
  509. #define pxa_gpio_suspend NULL
  510. #define pxa_gpio_resume NULL
  511. #endif
  512. struct syscore_ops pxa_gpio_syscore_ops = {
  513. .suspend = pxa_gpio_suspend,
  514. .resume = pxa_gpio_resume,
  515. };
  516. static int __init pxa_gpio_sysinit(void)
  517. {
  518. register_syscore_ops(&pxa_gpio_syscore_ops);
  519. return 0;
  520. }
  521. postcore_initcall(pxa_gpio_sysinit);