gpio-pxa.c 15 KB

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