pinctrl-exynos.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. /*
  2. * Exynos specific support for Samsung pinctrl/gpiolib driver with eint support.
  3. *
  4. * Copyright (c) 2012 Samsung Electronics Co., Ltd.
  5. * http://www.samsung.com
  6. * Copyright (c) 2012 Linaro Ltd
  7. * http://www.linaro.org
  8. *
  9. * Author: Thomas Abraham <thomas.ab@samsung.com>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This file contains the Samsung Exynos specific information required by the
  17. * the Samsung pinctrl/gpiolib driver. It also includes the implementation of
  18. * external gpio and wakeup interrupt support.
  19. */
  20. #include <linux/device.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/irqdomain.h>
  23. #include <linux/irq.h>
  24. #include <linux/irqchip/chained_irq.h>
  25. #include <linux/of.h>
  26. #include <linux/of_irq.h>
  27. #include <linux/slab.h>
  28. #include <linux/spinlock.h>
  29. #include <linux/regmap.h>
  30. #include <linux/err.h>
  31. #include <linux/soc/samsung/exynos-pmu.h>
  32. #include <dt-bindings/pinctrl/samsung.h>
  33. #include "pinctrl-samsung.h"
  34. #include "pinctrl-exynos.h"
  35. struct exynos_irq_chip {
  36. struct irq_chip chip;
  37. u32 eint_con;
  38. u32 eint_mask;
  39. u32 eint_pend;
  40. };
  41. static inline struct exynos_irq_chip *to_exynos_irq_chip(struct irq_chip *chip)
  42. {
  43. return container_of(chip, struct exynos_irq_chip, chip);
  44. }
  45. static void exynos_irq_mask(struct irq_data *irqd)
  46. {
  47. struct irq_chip *chip = irq_data_get_irq_chip(irqd);
  48. struct exynos_irq_chip *our_chip = to_exynos_irq_chip(chip);
  49. struct samsung_pin_bank *bank = irq_data_get_irq_chip_data(irqd);
  50. unsigned long reg_mask = our_chip->eint_mask + bank->eint_offset;
  51. unsigned int mask;
  52. unsigned long flags;
  53. spin_lock_irqsave(&bank->slock, flags);
  54. mask = readl(bank->eint_base + reg_mask);
  55. mask |= 1 << irqd->hwirq;
  56. writel(mask, bank->eint_base + reg_mask);
  57. spin_unlock_irqrestore(&bank->slock, flags);
  58. }
  59. static void exynos_irq_ack(struct irq_data *irqd)
  60. {
  61. struct irq_chip *chip = irq_data_get_irq_chip(irqd);
  62. struct exynos_irq_chip *our_chip = to_exynos_irq_chip(chip);
  63. struct samsung_pin_bank *bank = irq_data_get_irq_chip_data(irqd);
  64. unsigned long reg_pend = our_chip->eint_pend + bank->eint_offset;
  65. writel(1 << irqd->hwirq, bank->eint_base + reg_pend);
  66. }
  67. static void exynos_irq_unmask(struct irq_data *irqd)
  68. {
  69. struct irq_chip *chip = irq_data_get_irq_chip(irqd);
  70. struct exynos_irq_chip *our_chip = to_exynos_irq_chip(chip);
  71. struct samsung_pin_bank *bank = irq_data_get_irq_chip_data(irqd);
  72. unsigned long reg_mask = our_chip->eint_mask + bank->eint_offset;
  73. unsigned int mask;
  74. unsigned long flags;
  75. /*
  76. * Ack level interrupts right before unmask
  77. *
  78. * If we don't do this we'll get a double-interrupt. Level triggered
  79. * interrupts must not fire an interrupt if the level is not
  80. * _currently_ active, even if it was active while the interrupt was
  81. * masked.
  82. */
  83. if (irqd_get_trigger_type(irqd) & IRQ_TYPE_LEVEL_MASK)
  84. exynos_irq_ack(irqd);
  85. spin_lock_irqsave(&bank->slock, flags);
  86. mask = readl(bank->eint_base + reg_mask);
  87. mask &= ~(1 << irqd->hwirq);
  88. writel(mask, bank->eint_base + reg_mask);
  89. spin_unlock_irqrestore(&bank->slock, flags);
  90. }
  91. static int exynos_irq_set_type(struct irq_data *irqd, unsigned int type)
  92. {
  93. struct irq_chip *chip = irq_data_get_irq_chip(irqd);
  94. struct exynos_irq_chip *our_chip = to_exynos_irq_chip(chip);
  95. struct samsung_pin_bank *bank = irq_data_get_irq_chip_data(irqd);
  96. unsigned int shift = EXYNOS_EINT_CON_LEN * irqd->hwirq;
  97. unsigned int con, trig_type;
  98. unsigned long reg_con = our_chip->eint_con + bank->eint_offset;
  99. switch (type) {
  100. case IRQ_TYPE_EDGE_RISING:
  101. trig_type = EXYNOS_EINT_EDGE_RISING;
  102. break;
  103. case IRQ_TYPE_EDGE_FALLING:
  104. trig_type = EXYNOS_EINT_EDGE_FALLING;
  105. break;
  106. case IRQ_TYPE_EDGE_BOTH:
  107. trig_type = EXYNOS_EINT_EDGE_BOTH;
  108. break;
  109. case IRQ_TYPE_LEVEL_HIGH:
  110. trig_type = EXYNOS_EINT_LEVEL_HIGH;
  111. break;
  112. case IRQ_TYPE_LEVEL_LOW:
  113. trig_type = EXYNOS_EINT_LEVEL_LOW;
  114. break;
  115. default:
  116. pr_err("unsupported external interrupt type\n");
  117. return -EINVAL;
  118. }
  119. if (type & IRQ_TYPE_EDGE_BOTH)
  120. irq_set_handler_locked(irqd, handle_edge_irq);
  121. else
  122. irq_set_handler_locked(irqd, handle_level_irq);
  123. con = readl(bank->eint_base + reg_con);
  124. con &= ~(EXYNOS_EINT_CON_MASK << shift);
  125. con |= trig_type << shift;
  126. writel(con, bank->eint_base + reg_con);
  127. return 0;
  128. }
  129. static int exynos_irq_request_resources(struct irq_data *irqd)
  130. {
  131. struct samsung_pin_bank *bank = irq_data_get_irq_chip_data(irqd);
  132. const struct samsung_pin_bank_type *bank_type = bank->type;
  133. unsigned long reg_con, flags;
  134. unsigned int shift, mask, con;
  135. int ret;
  136. ret = gpiochip_lock_as_irq(&bank->gpio_chip, irqd->hwirq);
  137. if (ret) {
  138. dev_err(bank->gpio_chip.parent,
  139. "unable to lock pin %s-%lu IRQ\n",
  140. bank->name, irqd->hwirq);
  141. return ret;
  142. }
  143. reg_con = bank->pctl_offset + bank_type->reg_offset[PINCFG_TYPE_FUNC];
  144. shift = irqd->hwirq * bank_type->fld_width[PINCFG_TYPE_FUNC];
  145. mask = (1 << bank_type->fld_width[PINCFG_TYPE_FUNC]) - 1;
  146. spin_lock_irqsave(&bank->slock, flags);
  147. con = readl(bank->pctl_base + reg_con);
  148. con &= ~(mask << shift);
  149. con |= EXYNOS_PIN_FUNC_EINT << shift;
  150. writel(con, bank->pctl_base + reg_con);
  151. spin_unlock_irqrestore(&bank->slock, flags);
  152. return 0;
  153. }
  154. static void exynos_irq_release_resources(struct irq_data *irqd)
  155. {
  156. struct samsung_pin_bank *bank = irq_data_get_irq_chip_data(irqd);
  157. const struct samsung_pin_bank_type *bank_type = bank->type;
  158. unsigned long reg_con, flags;
  159. unsigned int shift, mask, con;
  160. reg_con = bank->pctl_offset + bank_type->reg_offset[PINCFG_TYPE_FUNC];
  161. shift = irqd->hwirq * bank_type->fld_width[PINCFG_TYPE_FUNC];
  162. mask = (1 << bank_type->fld_width[PINCFG_TYPE_FUNC]) - 1;
  163. spin_lock_irqsave(&bank->slock, flags);
  164. con = readl(bank->pctl_base + reg_con);
  165. con &= ~(mask << shift);
  166. con |= EXYNOS_PIN_FUNC_INPUT << shift;
  167. writel(con, bank->pctl_base + reg_con);
  168. spin_unlock_irqrestore(&bank->slock, flags);
  169. gpiochip_unlock_as_irq(&bank->gpio_chip, irqd->hwirq);
  170. }
  171. /*
  172. * irq_chip for gpio interrupts.
  173. */
  174. static struct exynos_irq_chip exynos_gpio_irq_chip = {
  175. .chip = {
  176. .name = "exynos_gpio_irq_chip",
  177. .irq_unmask = exynos_irq_unmask,
  178. .irq_mask = exynos_irq_mask,
  179. .irq_ack = exynos_irq_ack,
  180. .irq_set_type = exynos_irq_set_type,
  181. .irq_request_resources = exynos_irq_request_resources,
  182. .irq_release_resources = exynos_irq_release_resources,
  183. },
  184. .eint_con = EXYNOS_GPIO_ECON_OFFSET,
  185. .eint_mask = EXYNOS_GPIO_EMASK_OFFSET,
  186. .eint_pend = EXYNOS_GPIO_EPEND_OFFSET,
  187. };
  188. static int exynos_eint_irq_map(struct irq_domain *h, unsigned int virq,
  189. irq_hw_number_t hw)
  190. {
  191. struct samsung_pin_bank *b = h->host_data;
  192. irq_set_chip_data(virq, b);
  193. irq_set_chip_and_handler(virq, &b->irq_chip->chip,
  194. handle_level_irq);
  195. return 0;
  196. }
  197. /*
  198. * irq domain callbacks for external gpio and wakeup interrupt controllers.
  199. */
  200. static const struct irq_domain_ops exynos_eint_irqd_ops = {
  201. .map = exynos_eint_irq_map,
  202. .xlate = irq_domain_xlate_twocell,
  203. };
  204. static irqreturn_t exynos_eint_gpio_irq(int irq, void *data)
  205. {
  206. struct samsung_pinctrl_drv_data *d = data;
  207. struct samsung_pin_bank *bank = d->pin_banks;
  208. unsigned int svc, group, pin, virq;
  209. svc = readl(bank->eint_base + EXYNOS_SVC_OFFSET);
  210. group = EXYNOS_SVC_GROUP(svc);
  211. pin = svc & EXYNOS_SVC_NUM_MASK;
  212. if (!group)
  213. return IRQ_HANDLED;
  214. bank += (group - 1);
  215. virq = irq_linear_revmap(bank->irq_domain, pin);
  216. if (!virq)
  217. return IRQ_NONE;
  218. generic_handle_irq(virq);
  219. return IRQ_HANDLED;
  220. }
  221. struct exynos_eint_gpio_save {
  222. u32 eint_con;
  223. u32 eint_fltcon0;
  224. u32 eint_fltcon1;
  225. u32 eint_mask;
  226. };
  227. /*
  228. * exynos_eint_gpio_init() - setup handling of external gpio interrupts.
  229. * @d: driver data of samsung pinctrl driver.
  230. */
  231. int exynos_eint_gpio_init(struct samsung_pinctrl_drv_data *d)
  232. {
  233. struct samsung_pin_bank *bank;
  234. struct device *dev = d->dev;
  235. int ret;
  236. int i;
  237. if (!d->irq) {
  238. dev_err(dev, "irq number not available\n");
  239. return -EINVAL;
  240. }
  241. ret = devm_request_irq(dev, d->irq, exynos_eint_gpio_irq,
  242. 0, dev_name(dev), d);
  243. if (ret) {
  244. dev_err(dev, "irq request failed\n");
  245. return -ENXIO;
  246. }
  247. bank = d->pin_banks;
  248. for (i = 0; i < d->nr_banks; ++i, ++bank) {
  249. if (bank->eint_type != EINT_TYPE_GPIO)
  250. continue;
  251. bank->irq_domain = irq_domain_add_linear(bank->of_node,
  252. bank->nr_pins, &exynos_eint_irqd_ops, bank);
  253. if (!bank->irq_domain) {
  254. dev_err(dev, "gpio irq domain add failed\n");
  255. ret = -ENXIO;
  256. goto err_domains;
  257. }
  258. bank->soc_priv = devm_kzalloc(d->dev,
  259. sizeof(struct exynos_eint_gpio_save), GFP_KERNEL);
  260. if (!bank->soc_priv) {
  261. irq_domain_remove(bank->irq_domain);
  262. ret = -ENOMEM;
  263. goto err_domains;
  264. }
  265. bank->irq_chip = &exynos_gpio_irq_chip;
  266. }
  267. return 0;
  268. err_domains:
  269. for (--i, --bank; i >= 0; --i, --bank) {
  270. if (bank->eint_type != EINT_TYPE_GPIO)
  271. continue;
  272. irq_domain_remove(bank->irq_domain);
  273. }
  274. return ret;
  275. }
  276. static u32 exynos_eint_wake_mask = 0xffffffff;
  277. u32 exynos_get_eint_wake_mask(void)
  278. {
  279. return exynos_eint_wake_mask;
  280. }
  281. static int exynos_wkup_irq_set_wake(struct irq_data *irqd, unsigned int on)
  282. {
  283. struct samsung_pin_bank *bank = irq_data_get_irq_chip_data(irqd);
  284. unsigned long bit = 1UL << (2 * bank->eint_offset + irqd->hwirq);
  285. pr_info("wake %s for irq %d\n", on ? "enabled" : "disabled", irqd->irq);
  286. if (!on)
  287. exynos_eint_wake_mask |= bit;
  288. else
  289. exynos_eint_wake_mask &= ~bit;
  290. return 0;
  291. }
  292. /*
  293. * irq_chip for wakeup interrupts
  294. */
  295. static const struct exynos_irq_chip exynos4210_wkup_irq_chip __initconst = {
  296. .chip = {
  297. .name = "exynos4210_wkup_irq_chip",
  298. .irq_unmask = exynos_irq_unmask,
  299. .irq_mask = exynos_irq_mask,
  300. .irq_ack = exynos_irq_ack,
  301. .irq_set_type = exynos_irq_set_type,
  302. .irq_set_wake = exynos_wkup_irq_set_wake,
  303. .irq_request_resources = exynos_irq_request_resources,
  304. .irq_release_resources = exynos_irq_release_resources,
  305. },
  306. .eint_con = EXYNOS_WKUP_ECON_OFFSET,
  307. .eint_mask = EXYNOS_WKUP_EMASK_OFFSET,
  308. .eint_pend = EXYNOS_WKUP_EPEND_OFFSET,
  309. };
  310. static const struct exynos_irq_chip exynos7_wkup_irq_chip __initconst = {
  311. .chip = {
  312. .name = "exynos7_wkup_irq_chip",
  313. .irq_unmask = exynos_irq_unmask,
  314. .irq_mask = exynos_irq_mask,
  315. .irq_ack = exynos_irq_ack,
  316. .irq_set_type = exynos_irq_set_type,
  317. .irq_set_wake = exynos_wkup_irq_set_wake,
  318. .irq_request_resources = exynos_irq_request_resources,
  319. .irq_release_resources = exynos_irq_release_resources,
  320. },
  321. .eint_con = EXYNOS7_WKUP_ECON_OFFSET,
  322. .eint_mask = EXYNOS7_WKUP_EMASK_OFFSET,
  323. .eint_pend = EXYNOS7_WKUP_EPEND_OFFSET,
  324. };
  325. /* list of external wakeup controllers supported */
  326. static const struct of_device_id exynos_wkup_irq_ids[] = {
  327. { .compatible = "samsung,exynos4210-wakeup-eint",
  328. .data = &exynos4210_wkup_irq_chip },
  329. { .compatible = "samsung,exynos7-wakeup-eint",
  330. .data = &exynos7_wkup_irq_chip },
  331. { }
  332. };
  333. /* interrupt handler for wakeup interrupts 0..15 */
  334. static void exynos_irq_eint0_15(struct irq_desc *desc)
  335. {
  336. struct exynos_weint_data *eintd = irq_desc_get_handler_data(desc);
  337. struct samsung_pin_bank *bank = eintd->bank;
  338. struct irq_chip *chip = irq_desc_get_chip(desc);
  339. int eint_irq;
  340. chained_irq_enter(chip, desc);
  341. eint_irq = irq_linear_revmap(bank->irq_domain, eintd->irq);
  342. generic_handle_irq(eint_irq);
  343. chained_irq_exit(chip, desc);
  344. }
  345. static inline void exynos_irq_demux_eint(unsigned int pend,
  346. struct irq_domain *domain)
  347. {
  348. unsigned int irq;
  349. while (pend) {
  350. irq = fls(pend) - 1;
  351. generic_handle_irq(irq_find_mapping(domain, irq));
  352. pend &= ~(1 << irq);
  353. }
  354. }
  355. /* interrupt handler for wakeup interrupt 16 */
  356. static void exynos_irq_demux_eint16_31(struct irq_desc *desc)
  357. {
  358. struct irq_chip *chip = irq_desc_get_chip(desc);
  359. struct exynos_muxed_weint_data *eintd = irq_desc_get_handler_data(desc);
  360. unsigned int pend;
  361. unsigned int mask;
  362. int i;
  363. chained_irq_enter(chip, desc);
  364. for (i = 0; i < eintd->nr_banks; ++i) {
  365. struct samsung_pin_bank *b = eintd->banks[i];
  366. pend = readl(b->eint_base + b->irq_chip->eint_pend
  367. + b->eint_offset);
  368. mask = readl(b->eint_base + b->irq_chip->eint_mask
  369. + b->eint_offset);
  370. exynos_irq_demux_eint(pend & ~mask, b->irq_domain);
  371. }
  372. chained_irq_exit(chip, desc);
  373. }
  374. /*
  375. * exynos_eint_wkup_init() - setup handling of external wakeup interrupts.
  376. * @d: driver data of samsung pinctrl driver.
  377. */
  378. int exynos_eint_wkup_init(struct samsung_pinctrl_drv_data *d)
  379. {
  380. struct device *dev = d->dev;
  381. struct device_node *wkup_np = NULL;
  382. struct device_node *np;
  383. struct samsung_pin_bank *bank;
  384. struct exynos_weint_data *weint_data;
  385. struct exynos_muxed_weint_data *muxed_data;
  386. struct exynos_irq_chip *irq_chip;
  387. unsigned int muxed_banks = 0;
  388. unsigned int i;
  389. int idx, irq;
  390. for_each_child_of_node(dev->of_node, np) {
  391. const struct of_device_id *match;
  392. match = of_match_node(exynos_wkup_irq_ids, np);
  393. if (match) {
  394. irq_chip = kmemdup(match->data,
  395. sizeof(*irq_chip), GFP_KERNEL);
  396. if (!irq_chip) {
  397. of_node_put(np);
  398. return -ENOMEM;
  399. }
  400. wkup_np = np;
  401. break;
  402. }
  403. }
  404. if (!wkup_np)
  405. return -ENODEV;
  406. bank = d->pin_banks;
  407. for (i = 0; i < d->nr_banks; ++i, ++bank) {
  408. if (bank->eint_type != EINT_TYPE_WKUP)
  409. continue;
  410. bank->irq_domain = irq_domain_add_linear(bank->of_node,
  411. bank->nr_pins, &exynos_eint_irqd_ops, bank);
  412. if (!bank->irq_domain) {
  413. dev_err(dev, "wkup irq domain add failed\n");
  414. return -ENXIO;
  415. }
  416. bank->irq_chip = irq_chip;
  417. if (!of_find_property(bank->of_node, "interrupts", NULL)) {
  418. bank->eint_type = EINT_TYPE_WKUP_MUX;
  419. ++muxed_banks;
  420. continue;
  421. }
  422. weint_data = devm_kzalloc(dev, bank->nr_pins
  423. * sizeof(*weint_data), GFP_KERNEL);
  424. if (!weint_data)
  425. return -ENOMEM;
  426. for (idx = 0; idx < bank->nr_pins; ++idx) {
  427. irq = irq_of_parse_and_map(bank->of_node, idx);
  428. if (!irq) {
  429. dev_err(dev, "irq number for eint-%s-%d not found\n",
  430. bank->name, idx);
  431. continue;
  432. }
  433. weint_data[idx].irq = idx;
  434. weint_data[idx].bank = bank;
  435. irq_set_chained_handler_and_data(irq,
  436. exynos_irq_eint0_15,
  437. &weint_data[idx]);
  438. }
  439. }
  440. if (!muxed_banks)
  441. return 0;
  442. irq = irq_of_parse_and_map(wkup_np, 0);
  443. if (!irq) {
  444. dev_err(dev, "irq number for muxed EINTs not found\n");
  445. return 0;
  446. }
  447. muxed_data = devm_kzalloc(dev, sizeof(*muxed_data)
  448. + muxed_banks*sizeof(struct samsung_pin_bank *), GFP_KERNEL);
  449. if (!muxed_data)
  450. return -ENOMEM;
  451. irq_set_chained_handler_and_data(irq, exynos_irq_demux_eint16_31,
  452. muxed_data);
  453. bank = d->pin_banks;
  454. idx = 0;
  455. for (i = 0; i < d->nr_banks; ++i, ++bank) {
  456. if (bank->eint_type != EINT_TYPE_WKUP_MUX)
  457. continue;
  458. muxed_data->banks[idx++] = bank;
  459. }
  460. muxed_data->nr_banks = muxed_banks;
  461. return 0;
  462. }
  463. static void exynos_pinctrl_suspend_bank(
  464. struct samsung_pinctrl_drv_data *drvdata,
  465. struct samsung_pin_bank *bank)
  466. {
  467. struct exynos_eint_gpio_save *save = bank->soc_priv;
  468. void __iomem *regs = bank->eint_base;
  469. save->eint_con = readl(regs + EXYNOS_GPIO_ECON_OFFSET
  470. + bank->eint_offset);
  471. save->eint_fltcon0 = readl(regs + EXYNOS_GPIO_EFLTCON_OFFSET
  472. + 2 * bank->eint_offset);
  473. save->eint_fltcon1 = readl(regs + EXYNOS_GPIO_EFLTCON_OFFSET
  474. + 2 * bank->eint_offset + 4);
  475. save->eint_mask = readl(regs + bank->irq_chip->eint_mask
  476. + bank->eint_offset);
  477. pr_debug("%s: save con %#010x\n", bank->name, save->eint_con);
  478. pr_debug("%s: save fltcon0 %#010x\n", bank->name, save->eint_fltcon0);
  479. pr_debug("%s: save fltcon1 %#010x\n", bank->name, save->eint_fltcon1);
  480. pr_debug("%s: save mask %#010x\n", bank->name, save->eint_mask);
  481. }
  482. void exynos_pinctrl_suspend(struct samsung_pinctrl_drv_data *drvdata)
  483. {
  484. struct samsung_pin_bank *bank = drvdata->pin_banks;
  485. int i;
  486. for (i = 0; i < drvdata->nr_banks; ++i, ++bank)
  487. if (bank->eint_type == EINT_TYPE_GPIO)
  488. exynos_pinctrl_suspend_bank(drvdata, bank);
  489. }
  490. static void exynos_pinctrl_resume_bank(
  491. struct samsung_pinctrl_drv_data *drvdata,
  492. struct samsung_pin_bank *bank)
  493. {
  494. struct exynos_eint_gpio_save *save = bank->soc_priv;
  495. void __iomem *regs = bank->eint_base;
  496. pr_debug("%s: con %#010x => %#010x\n", bank->name,
  497. readl(regs + EXYNOS_GPIO_ECON_OFFSET
  498. + bank->eint_offset), save->eint_con);
  499. pr_debug("%s: fltcon0 %#010x => %#010x\n", bank->name,
  500. readl(regs + EXYNOS_GPIO_EFLTCON_OFFSET
  501. + 2 * bank->eint_offset), save->eint_fltcon0);
  502. pr_debug("%s: fltcon1 %#010x => %#010x\n", bank->name,
  503. readl(regs + EXYNOS_GPIO_EFLTCON_OFFSET
  504. + 2 * bank->eint_offset + 4), save->eint_fltcon1);
  505. pr_debug("%s: mask %#010x => %#010x\n", bank->name,
  506. readl(regs + bank->irq_chip->eint_mask
  507. + bank->eint_offset), save->eint_mask);
  508. writel(save->eint_con, regs + EXYNOS_GPIO_ECON_OFFSET
  509. + bank->eint_offset);
  510. writel(save->eint_fltcon0, regs + EXYNOS_GPIO_EFLTCON_OFFSET
  511. + 2 * bank->eint_offset);
  512. writel(save->eint_fltcon1, regs + EXYNOS_GPIO_EFLTCON_OFFSET
  513. + 2 * bank->eint_offset + 4);
  514. writel(save->eint_mask, regs + bank->irq_chip->eint_mask
  515. + bank->eint_offset);
  516. }
  517. void exynos_pinctrl_resume(struct samsung_pinctrl_drv_data *drvdata)
  518. {
  519. struct samsung_pin_bank *bank = drvdata->pin_banks;
  520. int i;
  521. for (i = 0; i < drvdata->nr_banks; ++i, ++bank)
  522. if (bank->eint_type == EINT_TYPE_GPIO)
  523. exynos_pinctrl_resume_bank(drvdata, bank);
  524. }
  525. static void exynos_retention_enable(struct samsung_pinctrl_drv_data *drvdata)
  526. {
  527. if (drvdata->retention_ctrl->refcnt)
  528. atomic_inc(drvdata->retention_ctrl->refcnt);
  529. }
  530. static void exynos_retention_disable(struct samsung_pinctrl_drv_data *drvdata)
  531. {
  532. struct samsung_retention_ctrl *ctrl = drvdata->retention_ctrl;
  533. struct regmap *pmu_regs = ctrl->priv;
  534. int i;
  535. if (ctrl->refcnt && !atomic_dec_and_test(ctrl->refcnt))
  536. return;
  537. for (i = 0; i < ctrl->nr_regs; i++)
  538. regmap_write(pmu_regs, ctrl->regs[i], ctrl->value);
  539. }
  540. struct samsung_retention_ctrl *
  541. exynos_retention_init(struct samsung_pinctrl_drv_data *drvdata,
  542. const struct samsung_retention_data *data)
  543. {
  544. struct samsung_retention_ctrl *ctrl;
  545. struct regmap *pmu_regs;
  546. int i;
  547. ctrl = devm_kzalloc(drvdata->dev, sizeof(*ctrl), GFP_KERNEL);
  548. if (!ctrl)
  549. return ERR_PTR(-ENOMEM);
  550. pmu_regs = exynos_get_pmu_regmap();
  551. if (IS_ERR(pmu_regs))
  552. return ERR_CAST(pmu_regs);
  553. ctrl->priv = pmu_regs;
  554. ctrl->regs = data->regs;
  555. ctrl->nr_regs = data->nr_regs;
  556. ctrl->value = data->value;
  557. ctrl->refcnt = data->refcnt;
  558. ctrl->enable = exynos_retention_enable;
  559. ctrl->disable = exynos_retention_disable;
  560. /* Ensure that retention is disabled on driver init */
  561. for (i = 0; i < ctrl->nr_regs; i++)
  562. regmap_write(pmu_regs, ctrl->regs[i], ctrl->value);
  563. return ctrl;
  564. }