gpio-pxa.c 17 KB

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