gpio-pxa.c 15 KB

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