Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 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 | |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 21 | #include <linux/device.h> |
| 22 | #include <linux/interrupt.h> |
| 23 | #include <linux/irqdomain.h> |
| 24 | #include <linux/irq.h> |
Catalin Marinas | de88cbb | 2013-01-18 15:31:37 +0000 | [diff] [blame] | 25 | #include <linux/irqchip/chained_irq.h> |
Krzysztof Kozlowski | cfa76dd | 2017-05-16 20:56:27 +0200 | [diff] [blame] | 26 | #include <linux/of.h> |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 27 | #include <linux/of_irq.h> |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 28 | #include <linux/slab.h> |
Tomasz Figa | 1984695 | 2013-03-18 22:31:50 +0100 | [diff] [blame] | 29 | #include <linux/spinlock.h> |
Marek Szyprowski | 0773101 | 2017-01-26 10:29:25 +0100 | [diff] [blame] | 30 | #include <linux/regmap.h> |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 31 | #include <linux/err.h> |
Marek Szyprowski | 0773101 | 2017-01-26 10:29:25 +0100 | [diff] [blame] | 32 | #include <linux/soc/samsung/exynos-pmu.h> |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 33 | |
Krzysztof Kozlowski | 4460dc2 | 2017-06-15 17:06:28 +0200 | [diff] [blame] | 34 | #include <dt-bindings/pinctrl/samsung.h> |
| 35 | |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 36 | #include "pinctrl-samsung.h" |
| 37 | #include "pinctrl-exynos.h" |
| 38 | |
Tomasz Figa | 2e4a4fd | 2014-07-02 17:41:01 +0200 | [diff] [blame] | 39 | struct exynos_irq_chip { |
| 40 | struct irq_chip chip; |
| 41 | |
| 42 | u32 eint_con; |
| 43 | u32 eint_mask; |
| 44 | u32 eint_pend; |
| 45 | }; |
| 46 | |
| 47 | static inline struct exynos_irq_chip *to_exynos_irq_chip(struct irq_chip *chip) |
| 48 | { |
| 49 | return container_of(chip, struct exynos_irq_chip, chip); |
| 50 | } |
Tomasz Figa | 499147c | 2013-03-18 22:31:52 +0100 | [diff] [blame] | 51 | |
Tomasz Figa | 2e4a4fd | 2014-07-02 17:41:01 +0200 | [diff] [blame] | 52 | static void exynos_irq_mask(struct irq_data *irqd) |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 53 | { |
Tomasz Figa | 2e4a4fd | 2014-07-02 17:41:01 +0200 | [diff] [blame] | 54 | struct irq_chip *chip = irq_data_get_irq_chip(irqd); |
| 55 | struct exynos_irq_chip *our_chip = to_exynos_irq_chip(chip); |
Tomasz Figa | 595be72 | 2012-10-11 10:11:16 +0200 | [diff] [blame] | 56 | struct samsung_pin_bank *bank = irq_data_get_irq_chip_data(irqd); |
Tomasz Figa | 2e4a4fd | 2014-07-02 17:41:01 +0200 | [diff] [blame] | 57 | unsigned long reg_mask = our_chip->eint_mask + bank->eint_offset; |
Krzysztof Kozlowski | d0fffdb | 2021-04-08 21:50:29 +0200 | [diff] [blame] | 58 | unsigned int mask; |
Doug Anderson | 5ae8cf7 | 2013-06-12 10:33:17 -0700 | [diff] [blame] | 59 | unsigned long flags; |
| 60 | |
| 61 | spin_lock_irqsave(&bank->slock, flags); |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 62 | |
Chanwoo Choi | 8b1bd11 | 2016-11-09 17:40:10 +0900 | [diff] [blame] | 63 | mask = readl(bank->eint_base + reg_mask); |
Tomasz Figa | 595be72 | 2012-10-11 10:11:16 +0200 | [diff] [blame] | 64 | mask |= 1 << irqd->hwirq; |
Chanwoo Choi | 8b1bd11 | 2016-11-09 17:40:10 +0900 | [diff] [blame] | 65 | writel(mask, bank->eint_base + reg_mask); |
Doug Anderson | 5ae8cf7 | 2013-06-12 10:33:17 -0700 | [diff] [blame] | 66 | |
| 67 | spin_unlock_irqrestore(&bank->slock, flags); |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 68 | } |
| 69 | |
Tomasz Figa | 2e4a4fd | 2014-07-02 17:41:01 +0200 | [diff] [blame] | 70 | static void exynos_irq_ack(struct irq_data *irqd) |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 71 | { |
Tomasz Figa | 2e4a4fd | 2014-07-02 17:41:01 +0200 | [diff] [blame] | 72 | struct irq_chip *chip = irq_data_get_irq_chip(irqd); |
| 73 | struct exynos_irq_chip *our_chip = to_exynos_irq_chip(chip); |
Tomasz Figa | 595be72 | 2012-10-11 10:11:16 +0200 | [diff] [blame] | 74 | struct samsung_pin_bank *bank = irq_data_get_irq_chip_data(irqd); |
Tomasz Figa | 2e4a4fd | 2014-07-02 17:41:01 +0200 | [diff] [blame] | 75 | unsigned long reg_pend = our_chip->eint_pend + bank->eint_offset; |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 76 | |
Chanwoo Choi | 8b1bd11 | 2016-11-09 17:40:10 +0900 | [diff] [blame] | 77 | writel(1 << irqd->hwirq, bank->eint_base + reg_pend); |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 78 | } |
| 79 | |
Tomasz Figa | 2e4a4fd | 2014-07-02 17:41:01 +0200 | [diff] [blame] | 80 | static void exynos_irq_unmask(struct irq_data *irqd) |
Doug Anderson | 5ace03f | 2013-06-12 10:33:18 -0700 | [diff] [blame] | 81 | { |
Tomasz Figa | 2e4a4fd | 2014-07-02 17:41:01 +0200 | [diff] [blame] | 82 | struct irq_chip *chip = irq_data_get_irq_chip(irqd); |
| 83 | struct exynos_irq_chip *our_chip = to_exynos_irq_chip(chip); |
Doug Anderson | 5ace03f | 2013-06-12 10:33:18 -0700 | [diff] [blame] | 84 | struct samsung_pin_bank *bank = irq_data_get_irq_chip_data(irqd); |
Tomasz Figa | 2e4a4fd | 2014-07-02 17:41:01 +0200 | [diff] [blame] | 85 | unsigned long reg_mask = our_chip->eint_mask + bank->eint_offset; |
Krzysztof Kozlowski | d0fffdb | 2021-04-08 21:50:29 +0200 | [diff] [blame] | 86 | unsigned int mask; |
Doug Anderson | 5ace03f | 2013-06-12 10:33:18 -0700 | [diff] [blame] | 87 | unsigned long flags; |
| 88 | |
Doug Anderson | 5a68e7a | 2013-06-17 09:50:43 -0700 | [diff] [blame] | 89 | /* |
| 90 | * Ack level interrupts right before unmask |
| 91 | * |
| 92 | * If we don't do this we'll get a double-interrupt. Level triggered |
| 93 | * interrupts must not fire an interrupt if the level is not |
| 94 | * _currently_ active, even if it was active while the interrupt was |
| 95 | * masked. |
| 96 | */ |
| 97 | if (irqd_get_trigger_type(irqd) & IRQ_TYPE_LEVEL_MASK) |
Tomasz Figa | 2e4a4fd | 2014-07-02 17:41:01 +0200 | [diff] [blame] | 98 | exynos_irq_ack(irqd); |
Doug Anderson | 5a68e7a | 2013-06-17 09:50:43 -0700 | [diff] [blame] | 99 | |
Doug Anderson | 5ace03f | 2013-06-12 10:33:18 -0700 | [diff] [blame] | 100 | spin_lock_irqsave(&bank->slock, flags); |
| 101 | |
Chanwoo Choi | 8b1bd11 | 2016-11-09 17:40:10 +0900 | [diff] [blame] | 102 | mask = readl(bank->eint_base + reg_mask); |
Doug Anderson | 5ace03f | 2013-06-12 10:33:18 -0700 | [diff] [blame] | 103 | mask &= ~(1 << irqd->hwirq); |
Chanwoo Choi | 8b1bd11 | 2016-11-09 17:40:10 +0900 | [diff] [blame] | 104 | writel(mask, bank->eint_base + reg_mask); |
Doug Anderson | 5ace03f | 2013-06-12 10:33:18 -0700 | [diff] [blame] | 105 | |
| 106 | spin_unlock_irqrestore(&bank->slock, flags); |
| 107 | } |
| 108 | |
Tomasz Figa | 2e4a4fd | 2014-07-02 17:41:01 +0200 | [diff] [blame] | 109 | static int exynos_irq_set_type(struct irq_data *irqd, unsigned int type) |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 110 | { |
Tomasz Figa | 2e4a4fd | 2014-07-02 17:41:01 +0200 | [diff] [blame] | 111 | struct irq_chip *chip = irq_data_get_irq_chip(irqd); |
| 112 | struct exynos_irq_chip *our_chip = to_exynos_irq_chip(chip); |
Tomasz Figa | 595be72 | 2012-10-11 10:11:16 +0200 | [diff] [blame] | 113 | struct samsung_pin_bank *bank = irq_data_get_irq_chip_data(irqd); |
Tomasz Figa | f6a8249 | 2014-08-09 01:48:05 +0200 | [diff] [blame] | 114 | unsigned int shift = EXYNOS_EINT_CON_LEN * irqd->hwirq; |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 115 | unsigned int con, trig_type; |
Tomasz Figa | 2e4a4fd | 2014-07-02 17:41:01 +0200 | [diff] [blame] | 116 | unsigned long reg_con = our_chip->eint_con + bank->eint_offset; |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 117 | |
| 118 | switch (type) { |
| 119 | case IRQ_TYPE_EDGE_RISING: |
| 120 | trig_type = EXYNOS_EINT_EDGE_RISING; |
| 121 | break; |
| 122 | case IRQ_TYPE_EDGE_FALLING: |
| 123 | trig_type = EXYNOS_EINT_EDGE_FALLING; |
| 124 | break; |
| 125 | case IRQ_TYPE_EDGE_BOTH: |
| 126 | trig_type = EXYNOS_EINT_EDGE_BOTH; |
| 127 | break; |
| 128 | case IRQ_TYPE_LEVEL_HIGH: |
| 129 | trig_type = EXYNOS_EINT_LEVEL_HIGH; |
| 130 | break; |
| 131 | case IRQ_TYPE_LEVEL_LOW: |
| 132 | trig_type = EXYNOS_EINT_LEVEL_LOW; |
| 133 | break; |
| 134 | default: |
| 135 | pr_err("unsupported external interrupt type\n"); |
| 136 | return -EINVAL; |
| 137 | } |
| 138 | |
| 139 | if (type & IRQ_TYPE_EDGE_BOTH) |
Thomas Gleixner | 40ec168 | 2015-06-23 15:52:57 +0200 | [diff] [blame] | 140 | irq_set_handler_locked(irqd, handle_edge_irq); |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 141 | else |
Thomas Gleixner | 40ec168 | 2015-06-23 15:52:57 +0200 | [diff] [blame] | 142 | irq_set_handler_locked(irqd, handle_level_irq); |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 143 | |
Chanwoo Choi | 8b1bd11 | 2016-11-09 17:40:10 +0900 | [diff] [blame] | 144 | con = readl(bank->eint_base + reg_con); |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 145 | con &= ~(EXYNOS_EINT_CON_MASK << shift); |
| 146 | con |= trig_type << shift; |
Chanwoo Choi | 8b1bd11 | 2016-11-09 17:40:10 +0900 | [diff] [blame] | 147 | writel(con, bank->eint_base + reg_con); |
Tomasz Figa | ee2f573 | 2012-09-21 07:33:48 +0900 | [diff] [blame] | 148 | |
Tomasz Figa | f6a8249 | 2014-08-09 01:48:05 +0200 | [diff] [blame] | 149 | return 0; |
| 150 | } |
| 151 | |
| 152 | static int exynos_irq_request_resources(struct irq_data *irqd) |
| 153 | { |
Tomasz Figa | f6a8249 | 2014-08-09 01:48:05 +0200 | [diff] [blame] | 154 | struct samsung_pin_bank *bank = irq_data_get_irq_chip_data(irqd); |
Tomasz Figa | 94ce944 | 2014-09-23 21:05:39 +0200 | [diff] [blame] | 155 | const struct samsung_pin_bank_type *bank_type = bank->type; |
Krzysztof Kozlowski | bbed85f | 2017-07-18 19:43:28 +0200 | [diff] [blame] | 156 | unsigned long reg_con, flags; |
| 157 | unsigned int shift, mask, con; |
Tomasz Figa | f6a8249 | 2014-08-09 01:48:05 +0200 | [diff] [blame] | 158 | int ret; |
| 159 | |
Alexandre Courbot | e3a2e87 | 2014-10-23 17:27:07 +0900 | [diff] [blame] | 160 | ret = gpiochip_lock_as_irq(&bank->gpio_chip, irqd->hwirq); |
Tomasz Figa | f6a8249 | 2014-08-09 01:48:05 +0200 | [diff] [blame] | 161 | if (ret) { |
Linus Walleij | 58383c7 | 2015-11-04 09:56:26 +0100 | [diff] [blame] | 162 | dev_err(bank->gpio_chip.parent, |
| 163 | "unable to lock pin %s-%lu IRQ\n", |
Tomasz Figa | f6a8249 | 2014-08-09 01:48:05 +0200 | [diff] [blame] | 164 | bank->name, irqd->hwirq); |
| 165 | return ret; |
| 166 | } |
| 167 | |
Tomasz Figa | 43fc9e7 | 2013-03-18 22:31:53 +0100 | [diff] [blame] | 168 | reg_con = bank->pctl_offset + bank_type->reg_offset[PINCFG_TYPE_FUNC]; |
Tomasz Figa | f6a8249 | 2014-08-09 01:48:05 +0200 | [diff] [blame] | 169 | shift = irqd->hwirq * bank_type->fld_width[PINCFG_TYPE_FUNC]; |
Tomasz Figa | 499147c | 2013-03-18 22:31:52 +0100 | [diff] [blame] | 170 | mask = (1 << bank_type->fld_width[PINCFG_TYPE_FUNC]) - 1; |
Tomasz Figa | ee2f573 | 2012-09-21 07:33:48 +0900 | [diff] [blame] | 171 | |
Tomasz Figa | 1984695 | 2013-03-18 22:31:50 +0100 | [diff] [blame] | 172 | spin_lock_irqsave(&bank->slock, flags); |
| 173 | |
Krzysztof Kozlowski | af0b0ba | 2017-06-14 15:18:28 +0200 | [diff] [blame] | 174 | con = readl(bank->pctl_base + reg_con); |
Tomasz Figa | ee2f573 | 2012-09-21 07:33:48 +0900 | [diff] [blame] | 175 | con &= ~(mask << shift); |
Krzysztof Kozlowski | 4460dc2 | 2017-06-15 17:06:28 +0200 | [diff] [blame] | 176 | con |= EXYNOS_PIN_FUNC_EINT << shift; |
Krzysztof Kozlowski | af0b0ba | 2017-06-14 15:18:28 +0200 | [diff] [blame] | 177 | writel(con, bank->pctl_base + reg_con); |
Tomasz Figa | ee2f573 | 2012-09-21 07:33:48 +0900 | [diff] [blame] | 178 | |
Tomasz Figa | 1984695 | 2013-03-18 22:31:50 +0100 | [diff] [blame] | 179 | spin_unlock_irqrestore(&bank->slock, flags); |
| 180 | |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 181 | return 0; |
| 182 | } |
| 183 | |
Tomasz Figa | f6a8249 | 2014-08-09 01:48:05 +0200 | [diff] [blame] | 184 | static void exynos_irq_release_resources(struct irq_data *irqd) |
| 185 | { |
Tomasz Figa | f6a8249 | 2014-08-09 01:48:05 +0200 | [diff] [blame] | 186 | struct samsung_pin_bank *bank = irq_data_get_irq_chip_data(irqd); |
Tomasz Figa | 94ce944 | 2014-09-23 21:05:39 +0200 | [diff] [blame] | 187 | const struct samsung_pin_bank_type *bank_type = bank->type; |
Krzysztof Kozlowski | bbed85f | 2017-07-18 19:43:28 +0200 | [diff] [blame] | 188 | unsigned long reg_con, flags; |
| 189 | unsigned int shift, mask, con; |
Tomasz Figa | f6a8249 | 2014-08-09 01:48:05 +0200 | [diff] [blame] | 190 | |
| 191 | reg_con = bank->pctl_offset + bank_type->reg_offset[PINCFG_TYPE_FUNC]; |
| 192 | shift = irqd->hwirq * bank_type->fld_width[PINCFG_TYPE_FUNC]; |
| 193 | mask = (1 << bank_type->fld_width[PINCFG_TYPE_FUNC]) - 1; |
| 194 | |
Tomasz Figa | f6a8249 | 2014-08-09 01:48:05 +0200 | [diff] [blame] | 195 | spin_lock_irqsave(&bank->slock, flags); |
| 196 | |
Krzysztof Kozlowski | af0b0ba | 2017-06-14 15:18:28 +0200 | [diff] [blame] | 197 | con = readl(bank->pctl_base + reg_con); |
Tomasz Figa | f6a8249 | 2014-08-09 01:48:05 +0200 | [diff] [blame] | 198 | con &= ~(mask << shift); |
Krzysztof Kozlowski | 4460dc2 | 2017-06-15 17:06:28 +0200 | [diff] [blame] | 199 | con |= EXYNOS_PIN_FUNC_INPUT << shift; |
Krzysztof Kozlowski | af0b0ba | 2017-06-14 15:18:28 +0200 | [diff] [blame] | 200 | writel(con, bank->pctl_base + reg_con); |
Tomasz Figa | f6a8249 | 2014-08-09 01:48:05 +0200 | [diff] [blame] | 201 | |
| 202 | spin_unlock_irqrestore(&bank->slock, flags); |
| 203 | |
Alexandre Courbot | e3a2e87 | 2014-10-23 17:27:07 +0900 | [diff] [blame] | 204 | gpiochip_unlock_as_irq(&bank->gpio_chip, irqd->hwirq); |
Tomasz Figa | f6a8249 | 2014-08-09 01:48:05 +0200 | [diff] [blame] | 205 | } |
| 206 | |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 207 | /* |
| 208 | * irq_chip for gpio interrupts. |
| 209 | */ |
Tomasz Figa | 2e4a4fd | 2014-07-02 17:41:01 +0200 | [diff] [blame] | 210 | static struct exynos_irq_chip exynos_gpio_irq_chip = { |
| 211 | .chip = { |
| 212 | .name = "exynos_gpio_irq_chip", |
| 213 | .irq_unmask = exynos_irq_unmask, |
| 214 | .irq_mask = exynos_irq_mask, |
| 215 | .irq_ack = exynos_irq_ack, |
| 216 | .irq_set_type = exynos_irq_set_type, |
Tomasz Figa | f6a8249 | 2014-08-09 01:48:05 +0200 | [diff] [blame] | 217 | .irq_request_resources = exynos_irq_request_resources, |
| 218 | .irq_release_resources = exynos_irq_release_resources, |
Tomasz Figa | 2e4a4fd | 2014-07-02 17:41:01 +0200 | [diff] [blame] | 219 | }, |
| 220 | .eint_con = EXYNOS_GPIO_ECON_OFFSET, |
| 221 | .eint_mask = EXYNOS_GPIO_EMASK_OFFSET, |
| 222 | .eint_pend = EXYNOS_GPIO_EPEND_OFFSET, |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 223 | }; |
| 224 | |
Abhilash Kesavan | 6f5e41b | 2014-10-09 19:24:30 +0530 | [diff] [blame] | 225 | static int exynos_eint_irq_map(struct irq_domain *h, unsigned int virq, |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 226 | irq_hw_number_t hw) |
| 227 | { |
Tomasz Figa | 595be72 | 2012-10-11 10:11:16 +0200 | [diff] [blame] | 228 | struct samsung_pin_bank *b = h->host_data; |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 229 | |
Tomasz Figa | 595be72 | 2012-10-11 10:11:16 +0200 | [diff] [blame] | 230 | irq_set_chip_data(virq, b); |
Abhilash Kesavan | 0d3d30d | 2014-10-09 19:24:29 +0530 | [diff] [blame] | 231 | irq_set_chip_and_handler(virq, &b->irq_chip->chip, |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 232 | handle_level_irq); |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 233 | return 0; |
| 234 | } |
| 235 | |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 236 | /* |
Abhilash Kesavan | 6f5e41b | 2014-10-09 19:24:30 +0530 | [diff] [blame] | 237 | * irq domain callbacks for external gpio and wakeup interrupt controllers. |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 238 | */ |
Abhilash Kesavan | 6f5e41b | 2014-10-09 19:24:30 +0530 | [diff] [blame] | 239 | static const struct irq_domain_ops exynos_eint_irqd_ops = { |
| 240 | .map = exynos_eint_irq_map, |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 241 | .xlate = irq_domain_xlate_twocell, |
| 242 | }; |
| 243 | |
| 244 | static irqreturn_t exynos_eint_gpio_irq(int irq, void *data) |
| 245 | { |
| 246 | struct samsung_pinctrl_drv_data *d = data; |
Tomasz Figa | 1bf00d7 | 2014-09-23 21:05:40 +0200 | [diff] [blame] | 247 | struct samsung_pin_bank *bank = d->pin_banks; |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 248 | unsigned int svc, group, pin, virq; |
| 249 | |
Chanwoo Choi | 8b1bd11 | 2016-11-09 17:40:10 +0900 | [diff] [blame] | 250 | svc = readl(bank->eint_base + EXYNOS_SVC_OFFSET); |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 251 | group = EXYNOS_SVC_GROUP(svc); |
| 252 | pin = svc & EXYNOS_SVC_NUM_MASK; |
| 253 | |
| 254 | if (!group) |
| 255 | return IRQ_HANDLED; |
| 256 | bank += (group - 1); |
| 257 | |
Tomasz Figa | 595be72 | 2012-10-11 10:11:16 +0200 | [diff] [blame] | 258 | virq = irq_linear_revmap(bank->irq_domain, pin); |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 259 | if (!virq) |
| 260 | return IRQ_NONE; |
| 261 | generic_handle_irq(virq); |
| 262 | return IRQ_HANDLED; |
| 263 | } |
| 264 | |
Tomasz Figa | 7ccbc60 | 2013-05-22 16:03:17 +0200 | [diff] [blame] | 265 | struct exynos_eint_gpio_save { |
| 266 | u32 eint_con; |
| 267 | u32 eint_fltcon0; |
| 268 | u32 eint_fltcon1; |
Jonathan Bakker | acac338 | 2020-04-25 16:10:46 -0700 | [diff] [blame] | 269 | u32 eint_mask; |
Tomasz Figa | 7ccbc60 | 2013-05-22 16:03:17 +0200 | [diff] [blame] | 270 | }; |
| 271 | |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 272 | /* |
| 273 | * exynos_eint_gpio_init() - setup handling of external gpio interrupts. |
| 274 | * @d: driver data of samsung pinctrl driver. |
| 275 | */ |
Krzysztof Kozlowski | cfa76dd | 2017-05-16 20:56:27 +0200 | [diff] [blame] | 276 | int exynos_eint_gpio_init(struct samsung_pinctrl_drv_data *d) |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 277 | { |
Tomasz Figa | 595be72 | 2012-10-11 10:11:16 +0200 | [diff] [blame] | 278 | struct samsung_pin_bank *bank; |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 279 | struct device *dev = d->dev; |
Tomasz Figa | 7ccbc60 | 2013-05-22 16:03:17 +0200 | [diff] [blame] | 280 | int ret; |
| 281 | int i; |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 282 | |
| 283 | if (!d->irq) { |
| 284 | dev_err(dev, "irq number not available\n"); |
| 285 | return -EINVAL; |
| 286 | } |
| 287 | |
| 288 | ret = devm_request_irq(dev, d->irq, exynos_eint_gpio_irq, |
| 289 | 0, dev_name(dev), d); |
| 290 | if (ret) { |
| 291 | dev_err(dev, "irq request failed\n"); |
| 292 | return -ENXIO; |
| 293 | } |
| 294 | |
Tomasz Figa | 1bf00d7 | 2014-09-23 21:05:40 +0200 | [diff] [blame] | 295 | bank = d->pin_banks; |
| 296 | for (i = 0; i < d->nr_banks; ++i, ++bank) { |
Tomasz Figa | 595be72 | 2012-10-11 10:11:16 +0200 | [diff] [blame] | 297 | if (bank->eint_type != EINT_TYPE_GPIO) |
| 298 | continue; |
| 299 | bank->irq_domain = irq_domain_add_linear(bank->of_node, |
Abhilash Kesavan | 6f5e41b | 2014-10-09 19:24:30 +0530 | [diff] [blame] | 300 | bank->nr_pins, &exynos_eint_irqd_ops, bank); |
Tomasz Figa | 595be72 | 2012-10-11 10:11:16 +0200 | [diff] [blame] | 301 | if (!bank->irq_domain) { |
| 302 | dev_err(dev, "gpio irq domain add failed\n"); |
Tomasz Figa | 7ccbc60 | 2013-05-22 16:03:17 +0200 | [diff] [blame] | 303 | ret = -ENXIO; |
| 304 | goto err_domains; |
| 305 | } |
| 306 | |
| 307 | bank->soc_priv = devm_kzalloc(d->dev, |
| 308 | sizeof(struct exynos_eint_gpio_save), GFP_KERNEL); |
| 309 | if (!bank->soc_priv) { |
| 310 | irq_domain_remove(bank->irq_domain); |
| 311 | ret = -ENOMEM; |
| 312 | goto err_domains; |
Tomasz Figa | 595be72 | 2012-10-11 10:11:16 +0200 | [diff] [blame] | 313 | } |
Abhilash Kesavan | 0d3d30d | 2014-10-09 19:24:29 +0530 | [diff] [blame] | 314 | |
| 315 | bank->irq_chip = &exynos_gpio_irq_chip; |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | return 0; |
Tomasz Figa | 7ccbc60 | 2013-05-22 16:03:17 +0200 | [diff] [blame] | 319 | |
| 320 | err_domains: |
| 321 | for (--i, --bank; i >= 0; --i, --bank) { |
| 322 | if (bank->eint_type != EINT_TYPE_GPIO) |
| 323 | continue; |
| 324 | irq_domain_remove(bank->irq_domain); |
| 325 | } |
| 326 | |
| 327 | return ret; |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 328 | } |
| 329 | |
Tomasz Figa | ad350cd | 2013-05-17 18:24:27 +0200 | [diff] [blame] | 330 | static u32 exynos_eint_wake_mask = 0xffffffff; |
| 331 | |
| 332 | u32 exynos_get_eint_wake_mask(void) |
| 333 | { |
| 334 | return exynos_eint_wake_mask; |
| 335 | } |
| 336 | |
| 337 | static int exynos_wkup_irq_set_wake(struct irq_data *irqd, unsigned int on) |
| 338 | { |
| 339 | struct samsung_pin_bank *bank = irq_data_get_irq_chip_data(irqd); |
| 340 | unsigned long bit = 1UL << (2 * bank->eint_offset + irqd->hwirq); |
| 341 | |
| 342 | pr_info("wake %s for irq %d\n", on ? "enabled" : "disabled", irqd->irq); |
| 343 | |
| 344 | if (!on) |
| 345 | exynos_eint_wake_mask |= bit; |
| 346 | else |
| 347 | exynos_eint_wake_mask &= ~bit; |
| 348 | |
| 349 | return 0; |
| 350 | } |
| 351 | |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 352 | /* |
| 353 | * irq_chip for wakeup interrupts |
| 354 | */ |
Krzysztof Kozlowski | 71b96c3 | 2017-05-23 20:41:39 +0200 | [diff] [blame] | 355 | static const struct exynos_irq_chip exynos4210_wkup_irq_chip __initconst = { |
Tomasz Figa | 2e4a4fd | 2014-07-02 17:41:01 +0200 | [diff] [blame] | 356 | .chip = { |
Abhilash Kesavan | 14c255d | 2014-10-09 19:24:31 +0530 | [diff] [blame] | 357 | .name = "exynos4210_wkup_irq_chip", |
Tomasz Figa | 2e4a4fd | 2014-07-02 17:41:01 +0200 | [diff] [blame] | 358 | .irq_unmask = exynos_irq_unmask, |
| 359 | .irq_mask = exynos_irq_mask, |
| 360 | .irq_ack = exynos_irq_ack, |
| 361 | .irq_set_type = exynos_irq_set_type, |
| 362 | .irq_set_wake = exynos_wkup_irq_set_wake, |
Tomasz Figa | f6a8249 | 2014-08-09 01:48:05 +0200 | [diff] [blame] | 363 | .irq_request_resources = exynos_irq_request_resources, |
| 364 | .irq_release_resources = exynos_irq_release_resources, |
Tomasz Figa | 2e4a4fd | 2014-07-02 17:41:01 +0200 | [diff] [blame] | 365 | }, |
| 366 | .eint_con = EXYNOS_WKUP_ECON_OFFSET, |
| 367 | .eint_mask = EXYNOS_WKUP_EMASK_OFFSET, |
| 368 | .eint_pend = EXYNOS_WKUP_EPEND_OFFSET, |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 369 | }; |
| 370 | |
Krzysztof Kozlowski | 71b96c3 | 2017-05-23 20:41:39 +0200 | [diff] [blame] | 371 | static const struct exynos_irq_chip exynos7_wkup_irq_chip __initconst = { |
Abhilash Kesavan | 14c255d | 2014-10-09 19:24:31 +0530 | [diff] [blame] | 372 | .chip = { |
| 373 | .name = "exynos7_wkup_irq_chip", |
| 374 | .irq_unmask = exynos_irq_unmask, |
| 375 | .irq_mask = exynos_irq_mask, |
| 376 | .irq_ack = exynos_irq_ack, |
| 377 | .irq_set_type = exynos_irq_set_type, |
| 378 | .irq_set_wake = exynos_wkup_irq_set_wake, |
| 379 | .irq_request_resources = exynos_irq_request_resources, |
| 380 | .irq_release_resources = exynos_irq_release_resources, |
| 381 | }, |
| 382 | .eint_con = EXYNOS7_WKUP_ECON_OFFSET, |
| 383 | .eint_mask = EXYNOS7_WKUP_EMASK_OFFSET, |
| 384 | .eint_pend = EXYNOS7_WKUP_EPEND_OFFSET, |
| 385 | }; |
| 386 | |
| 387 | /* list of external wakeup controllers supported */ |
| 388 | static const struct of_device_id exynos_wkup_irq_ids[] = { |
| 389 | { .compatible = "samsung,exynos4210-wakeup-eint", |
| 390 | .data = &exynos4210_wkup_irq_chip }, |
| 391 | { .compatible = "samsung,exynos7-wakeup-eint", |
| 392 | .data = &exynos7_wkup_irq_chip }, |
| 393 | { } |
| 394 | }; |
| 395 | |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 396 | /* interrupt handler for wakeup interrupts 0..15 */ |
Thomas Gleixner | bd0b9ac | 2015-09-14 10:42:37 +0200 | [diff] [blame] | 397 | static void exynos_irq_eint0_15(struct irq_desc *desc) |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 398 | { |
Jiang Liu | 5663bb2 | 2015-06-04 12:13:16 +0800 | [diff] [blame] | 399 | struct exynos_weint_data *eintd = irq_desc_get_handler_data(desc); |
Tomasz Figa | a04b07c | 2012-10-11 10:11:18 +0200 | [diff] [blame] | 400 | struct samsung_pin_bank *bank = eintd->bank; |
Jiang Liu | 5663bb2 | 2015-06-04 12:13:16 +0800 | [diff] [blame] | 401 | struct irq_chip *chip = irq_desc_get_chip(desc); |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 402 | int eint_irq; |
| 403 | |
| 404 | chained_irq_enter(chip, desc); |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 405 | |
Tomasz Figa | a04b07c | 2012-10-11 10:11:18 +0200 | [diff] [blame] | 406 | eint_irq = irq_linear_revmap(bank->irq_domain, eintd->irq); |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 407 | generic_handle_irq(eint_irq); |
perr perr | 26fecf0 | 2016-08-16 18:45:29 +0800 | [diff] [blame] | 408 | |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 409 | chained_irq_exit(chip, desc); |
| 410 | } |
| 411 | |
Krzysztof Kozlowski | d0fffdb | 2021-04-08 21:50:29 +0200 | [diff] [blame] | 412 | static inline void exynos_irq_demux_eint(unsigned int pend, |
Tomasz Figa | a04b07c | 2012-10-11 10:11:18 +0200 | [diff] [blame] | 413 | struct irq_domain *domain) |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 414 | { |
| 415 | unsigned int irq; |
| 416 | |
| 417 | while (pend) { |
| 418 | irq = fls(pend) - 1; |
Tomasz Figa | a04b07c | 2012-10-11 10:11:18 +0200 | [diff] [blame] | 419 | generic_handle_irq(irq_find_mapping(domain, irq)); |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 420 | pend &= ~(1 << irq); |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | /* interrupt handler for wakeup interrupt 16 */ |
Thomas Gleixner | bd0b9ac | 2015-09-14 10:42:37 +0200 | [diff] [blame] | 425 | static void exynos_irq_demux_eint16_31(struct irq_desc *desc) |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 426 | { |
Jiang Liu | 5663bb2 | 2015-06-04 12:13:16 +0800 | [diff] [blame] | 427 | struct irq_chip *chip = irq_desc_get_chip(desc); |
| 428 | struct exynos_muxed_weint_data *eintd = irq_desc_get_handler_data(desc); |
Krzysztof Kozlowski | d0fffdb | 2021-04-08 21:50:29 +0200 | [diff] [blame] | 429 | unsigned int pend; |
| 430 | unsigned int mask; |
Tomasz Figa | a04b07c | 2012-10-11 10:11:18 +0200 | [diff] [blame] | 431 | int i; |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 432 | |
| 433 | chained_irq_enter(chip, desc); |
Tomasz Figa | a04b07c | 2012-10-11 10:11:18 +0200 | [diff] [blame] | 434 | |
| 435 | for (i = 0; i < eintd->nr_banks; ++i) { |
| 436 | struct samsung_pin_bank *b = eintd->banks[i]; |
Chanwoo Choi | 8b1bd11 | 2016-11-09 17:40:10 +0900 | [diff] [blame] | 437 | pend = readl(b->eint_base + b->irq_chip->eint_pend |
Tomasz Figa | 2e4a4fd | 2014-07-02 17:41:01 +0200 | [diff] [blame] | 438 | + b->eint_offset); |
Chanwoo Choi | 8b1bd11 | 2016-11-09 17:40:10 +0900 | [diff] [blame] | 439 | mask = readl(b->eint_base + b->irq_chip->eint_mask |
Tomasz Figa | 2e4a4fd | 2014-07-02 17:41:01 +0200 | [diff] [blame] | 440 | + b->eint_offset); |
Tomasz Figa | a04b07c | 2012-10-11 10:11:18 +0200 | [diff] [blame] | 441 | exynos_irq_demux_eint(pend & ~mask, b->irq_domain); |
| 442 | } |
| 443 | |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 444 | chained_irq_exit(chip, desc); |
| 445 | } |
| 446 | |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 447 | /* |
| 448 | * exynos_eint_wkup_init() - setup handling of external wakeup interrupts. |
| 449 | * @d: driver data of samsung pinctrl driver. |
| 450 | */ |
Krzysztof Kozlowski | cfa76dd | 2017-05-16 20:56:27 +0200 | [diff] [blame] | 451 | int exynos_eint_wkup_init(struct samsung_pinctrl_drv_data *d) |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 452 | { |
| 453 | struct device *dev = d->dev; |
Tomasz Figa | c3ad056 | 2012-09-21 07:34:01 +0900 | [diff] [blame] | 454 | struct device_node *wkup_np = NULL; |
| 455 | struct device_node *np; |
Tomasz Figa | a04b07c | 2012-10-11 10:11:18 +0200 | [diff] [blame] | 456 | struct samsung_pin_bank *bank; |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 457 | struct exynos_weint_data *weint_data; |
Tomasz Figa | a04b07c | 2012-10-11 10:11:18 +0200 | [diff] [blame] | 458 | struct exynos_muxed_weint_data *muxed_data; |
Abhilash Kesavan | 14c255d | 2014-10-09 19:24:31 +0530 | [diff] [blame] | 459 | struct exynos_irq_chip *irq_chip; |
Tomasz Figa | a04b07c | 2012-10-11 10:11:18 +0200 | [diff] [blame] | 460 | unsigned int muxed_banks = 0; |
| 461 | unsigned int i; |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 462 | int idx, irq; |
| 463 | |
Tomasz Figa | c3ad056 | 2012-09-21 07:34:01 +0900 | [diff] [blame] | 464 | for_each_child_of_node(dev->of_node, np) { |
Abhilash Kesavan | 14c255d | 2014-10-09 19:24:31 +0530 | [diff] [blame] | 465 | const struct of_device_id *match; |
| 466 | |
| 467 | match = of_match_node(exynos_wkup_irq_ids, np); |
| 468 | if (match) { |
| 469 | irq_chip = kmemdup(match->data, |
| 470 | sizeof(*irq_chip), GFP_KERNEL); |
Nishka Dasgupta | d892c978 | 2019-08-04 21:32:00 +0530 | [diff] [blame] | 471 | if (!irq_chip) { |
| 472 | of_node_put(np); |
Krzysztof Kozlowski | a1ea9a4 | 2017-05-23 20:41:40 +0200 | [diff] [blame] | 473 | return -ENOMEM; |
Nishka Dasgupta | d892c978 | 2019-08-04 21:32:00 +0530 | [diff] [blame] | 474 | } |
Tomasz Figa | c3ad056 | 2012-09-21 07:34:01 +0900 | [diff] [blame] | 475 | wkup_np = np; |
| 476 | break; |
| 477 | } |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 478 | } |
Tomasz Figa | c3ad056 | 2012-09-21 07:34:01 +0900 | [diff] [blame] | 479 | if (!wkup_np) |
| 480 | return -ENODEV; |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 481 | |
Tomasz Figa | 1bf00d7 | 2014-09-23 21:05:40 +0200 | [diff] [blame] | 482 | bank = d->pin_banks; |
| 483 | for (i = 0; i < d->nr_banks; ++i, ++bank) { |
Tomasz Figa | a04b07c | 2012-10-11 10:11:18 +0200 | [diff] [blame] | 484 | if (bank->eint_type != EINT_TYPE_WKUP) |
| 485 | continue; |
| 486 | |
| 487 | bank->irq_domain = irq_domain_add_linear(bank->of_node, |
Abhilash Kesavan | 6f5e41b | 2014-10-09 19:24:30 +0530 | [diff] [blame] | 488 | bank->nr_pins, &exynos_eint_irqd_ops, bank); |
Tomasz Figa | a04b07c | 2012-10-11 10:11:18 +0200 | [diff] [blame] | 489 | if (!bank->irq_domain) { |
| 490 | dev_err(dev, "wkup irq domain add failed\n"); |
| 491 | return -ENXIO; |
| 492 | } |
| 493 | |
Abhilash Kesavan | 14c255d | 2014-10-09 19:24:31 +0530 | [diff] [blame] | 494 | bank->irq_chip = irq_chip; |
Abhilash Kesavan | 0d3d30d | 2014-10-09 19:24:29 +0530 | [diff] [blame] | 495 | |
Tomasz Figa | a04b07c | 2012-10-11 10:11:18 +0200 | [diff] [blame] | 496 | if (!of_find_property(bank->of_node, "interrupts", NULL)) { |
| 497 | bank->eint_type = EINT_TYPE_WKUP_MUX; |
| 498 | ++muxed_banks; |
| 499 | continue; |
| 500 | } |
| 501 | |
| 502 | weint_data = devm_kzalloc(dev, bank->nr_pins |
| 503 | * sizeof(*weint_data), GFP_KERNEL); |
Marek Szyprowski | fa5c0f4 | 2017-01-19 14:48:45 +0100 | [diff] [blame] | 504 | if (!weint_data) |
Tomasz Figa | a04b07c | 2012-10-11 10:11:18 +0200 | [diff] [blame] | 505 | return -ENOMEM; |
Tomasz Figa | a04b07c | 2012-10-11 10:11:18 +0200 | [diff] [blame] | 506 | |
| 507 | for (idx = 0; idx < bank->nr_pins; ++idx) { |
| 508 | irq = irq_of_parse_and_map(bank->of_node, idx); |
| 509 | if (!irq) { |
| 510 | dev_err(dev, "irq number for eint-%s-%d not found\n", |
| 511 | bank->name, idx); |
| 512 | continue; |
| 513 | } |
| 514 | weint_data[idx].irq = idx; |
| 515 | weint_data[idx].bank = bank; |
Thomas Gleixner | c21f784 | 2015-06-21 21:11:07 +0200 | [diff] [blame] | 516 | irq_set_chained_handler_and_data(irq, |
| 517 | exynos_irq_eint0_15, |
| 518 | &weint_data[idx]); |
Tomasz Figa | a04b07c | 2012-10-11 10:11:18 +0200 | [diff] [blame] | 519 | } |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 520 | } |
| 521 | |
Tomasz Figa | a04b07c | 2012-10-11 10:11:18 +0200 | [diff] [blame] | 522 | if (!muxed_banks) |
| 523 | return 0; |
| 524 | |
| 525 | irq = irq_of_parse_and_map(wkup_np, 0); |
| 526 | if (!irq) { |
| 527 | dev_err(dev, "irq number for muxed EINTs not found\n"); |
| 528 | return 0; |
| 529 | } |
| 530 | |
| 531 | muxed_data = devm_kzalloc(dev, sizeof(*muxed_data) |
| 532 | + muxed_banks*sizeof(struct samsung_pin_bank *), GFP_KERNEL); |
Marek Szyprowski | fa5c0f4 | 2017-01-19 14:48:45 +0100 | [diff] [blame] | 533 | if (!muxed_data) |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 534 | return -ENOMEM; |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 535 | |
Thomas Gleixner | bb56fc3 | 2015-06-21 20:16:16 +0200 | [diff] [blame] | 536 | irq_set_chained_handler_and_data(irq, exynos_irq_demux_eint16_31, |
| 537 | muxed_data); |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 538 | |
Tomasz Figa | 1bf00d7 | 2014-09-23 21:05:40 +0200 | [diff] [blame] | 539 | bank = d->pin_banks; |
Tomasz Figa | a04b07c | 2012-10-11 10:11:18 +0200 | [diff] [blame] | 540 | idx = 0; |
Tomasz Figa | 1bf00d7 | 2014-09-23 21:05:40 +0200 | [diff] [blame] | 541 | for (i = 0; i < d->nr_banks; ++i, ++bank) { |
Tomasz Figa | a04b07c | 2012-10-11 10:11:18 +0200 | [diff] [blame] | 542 | if (bank->eint_type != EINT_TYPE_WKUP_MUX) |
| 543 | continue; |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 544 | |
Tomasz Figa | a04b07c | 2012-10-11 10:11:18 +0200 | [diff] [blame] | 545 | muxed_data->banks[idx++] = bank; |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 546 | } |
Tomasz Figa | a04b07c | 2012-10-11 10:11:18 +0200 | [diff] [blame] | 547 | muxed_data->nr_banks = muxed_banks; |
| 548 | |
Thomas Abraham | 43b169d | 2012-09-07 06:07:19 +0900 | [diff] [blame] | 549 | return 0; |
| 550 | } |
| 551 | |
Tomasz Figa | 7ccbc60 | 2013-05-22 16:03:17 +0200 | [diff] [blame] | 552 | static void exynos_pinctrl_suspend_bank( |
| 553 | struct samsung_pinctrl_drv_data *drvdata, |
| 554 | struct samsung_pin_bank *bank) |
| 555 | { |
| 556 | struct exynos_eint_gpio_save *save = bank->soc_priv; |
Chanwoo Choi | 8b1bd11 | 2016-11-09 17:40:10 +0900 | [diff] [blame] | 557 | void __iomem *regs = bank->eint_base; |
Tomasz Figa | 7ccbc60 | 2013-05-22 16:03:17 +0200 | [diff] [blame] | 558 | |
| 559 | save->eint_con = readl(regs + EXYNOS_GPIO_ECON_OFFSET |
| 560 | + bank->eint_offset); |
| 561 | save->eint_fltcon0 = readl(regs + EXYNOS_GPIO_EFLTCON_OFFSET |
| 562 | + 2 * bank->eint_offset); |
| 563 | save->eint_fltcon1 = readl(regs + EXYNOS_GPIO_EFLTCON_OFFSET |
| 564 | + 2 * bank->eint_offset + 4); |
Jonathan Bakker | acac338 | 2020-04-25 16:10:46 -0700 | [diff] [blame] | 565 | save->eint_mask = readl(regs + bank->irq_chip->eint_mask |
| 566 | + bank->eint_offset); |
Tomasz Figa | 7ccbc60 | 2013-05-22 16:03:17 +0200 | [diff] [blame] | 567 | |
| 568 | pr_debug("%s: save con %#010x\n", bank->name, save->eint_con); |
| 569 | pr_debug("%s: save fltcon0 %#010x\n", bank->name, save->eint_fltcon0); |
| 570 | pr_debug("%s: save fltcon1 %#010x\n", bank->name, save->eint_fltcon1); |
Jonathan Bakker | acac338 | 2020-04-25 16:10:46 -0700 | [diff] [blame] | 571 | pr_debug("%s: save mask %#010x\n", bank->name, save->eint_mask); |
Tomasz Figa | 7ccbc60 | 2013-05-22 16:03:17 +0200 | [diff] [blame] | 572 | } |
| 573 | |
Krzysztof Kozlowski | cfa76dd | 2017-05-16 20:56:27 +0200 | [diff] [blame] | 574 | void exynos_pinctrl_suspend(struct samsung_pinctrl_drv_data *drvdata) |
Tomasz Figa | 7ccbc60 | 2013-05-22 16:03:17 +0200 | [diff] [blame] | 575 | { |
Tomasz Figa | 1bf00d7 | 2014-09-23 21:05:40 +0200 | [diff] [blame] | 576 | struct samsung_pin_bank *bank = drvdata->pin_banks; |
Tomasz Figa | 7ccbc60 | 2013-05-22 16:03:17 +0200 | [diff] [blame] | 577 | int i; |
| 578 | |
Tomasz Figa | 1bf00d7 | 2014-09-23 21:05:40 +0200 | [diff] [blame] | 579 | for (i = 0; i < drvdata->nr_banks; ++i, ++bank) |
Tomasz Figa | 7ccbc60 | 2013-05-22 16:03:17 +0200 | [diff] [blame] | 580 | if (bank->eint_type == EINT_TYPE_GPIO) |
| 581 | exynos_pinctrl_suspend_bank(drvdata, bank); |
| 582 | } |
| 583 | |
| 584 | static void exynos_pinctrl_resume_bank( |
| 585 | struct samsung_pinctrl_drv_data *drvdata, |
| 586 | struct samsung_pin_bank *bank) |
| 587 | { |
| 588 | struct exynos_eint_gpio_save *save = bank->soc_priv; |
Chanwoo Choi | 8b1bd11 | 2016-11-09 17:40:10 +0900 | [diff] [blame] | 589 | void __iomem *regs = bank->eint_base; |
Tomasz Figa | 7ccbc60 | 2013-05-22 16:03:17 +0200 | [diff] [blame] | 590 | |
| 591 | pr_debug("%s: con %#010x => %#010x\n", bank->name, |
| 592 | readl(regs + EXYNOS_GPIO_ECON_OFFSET |
| 593 | + bank->eint_offset), save->eint_con); |
| 594 | pr_debug("%s: fltcon0 %#010x => %#010x\n", bank->name, |
| 595 | readl(regs + EXYNOS_GPIO_EFLTCON_OFFSET |
| 596 | + 2 * bank->eint_offset), save->eint_fltcon0); |
| 597 | pr_debug("%s: fltcon1 %#010x => %#010x\n", bank->name, |
| 598 | readl(regs + EXYNOS_GPIO_EFLTCON_OFFSET |
| 599 | + 2 * bank->eint_offset + 4), save->eint_fltcon1); |
Jonathan Bakker | acac338 | 2020-04-25 16:10:46 -0700 | [diff] [blame] | 600 | pr_debug("%s: mask %#010x => %#010x\n", bank->name, |
| 601 | readl(regs + bank->irq_chip->eint_mask |
| 602 | + bank->eint_offset), save->eint_mask); |
Tomasz Figa | 7ccbc60 | 2013-05-22 16:03:17 +0200 | [diff] [blame] | 603 | |
| 604 | writel(save->eint_con, regs + EXYNOS_GPIO_ECON_OFFSET |
| 605 | + bank->eint_offset); |
| 606 | writel(save->eint_fltcon0, regs + EXYNOS_GPIO_EFLTCON_OFFSET |
| 607 | + 2 * bank->eint_offset); |
| 608 | writel(save->eint_fltcon1, regs + EXYNOS_GPIO_EFLTCON_OFFSET |
| 609 | + 2 * bank->eint_offset + 4); |
Jonathan Bakker | acac338 | 2020-04-25 16:10:46 -0700 | [diff] [blame] | 610 | writel(save->eint_mask, regs + bank->irq_chip->eint_mask |
| 611 | + bank->eint_offset); |
Tomasz Figa | 7ccbc60 | 2013-05-22 16:03:17 +0200 | [diff] [blame] | 612 | } |
| 613 | |
Krzysztof Kozlowski | cfa76dd | 2017-05-16 20:56:27 +0200 | [diff] [blame] | 614 | void exynos_pinctrl_resume(struct samsung_pinctrl_drv_data *drvdata) |
Tomasz Figa | 7ccbc60 | 2013-05-22 16:03:17 +0200 | [diff] [blame] | 615 | { |
Tomasz Figa | 1bf00d7 | 2014-09-23 21:05:40 +0200 | [diff] [blame] | 616 | struct samsung_pin_bank *bank = drvdata->pin_banks; |
Tomasz Figa | 7ccbc60 | 2013-05-22 16:03:17 +0200 | [diff] [blame] | 617 | int i; |
| 618 | |
Tomasz Figa | 1bf00d7 | 2014-09-23 21:05:40 +0200 | [diff] [blame] | 619 | for (i = 0; i < drvdata->nr_banks; ++i, ++bank) |
Tomasz Figa | 7ccbc60 | 2013-05-22 16:03:17 +0200 | [diff] [blame] | 620 | if (bank->eint_type == EINT_TYPE_GPIO) |
| 621 | exynos_pinctrl_resume_bank(drvdata, bank); |
| 622 | } |
| 623 | |
Marek Szyprowski | 0773101 | 2017-01-26 10:29:25 +0100 | [diff] [blame] | 624 | static void exynos_retention_enable(struct samsung_pinctrl_drv_data *drvdata) |
| 625 | { |
| 626 | if (drvdata->retention_ctrl->refcnt) |
| 627 | atomic_inc(drvdata->retention_ctrl->refcnt); |
| 628 | } |
| 629 | |
| 630 | static void exynos_retention_disable(struct samsung_pinctrl_drv_data *drvdata) |
| 631 | { |
| 632 | struct samsung_retention_ctrl *ctrl = drvdata->retention_ctrl; |
| 633 | struct regmap *pmu_regs = ctrl->priv; |
| 634 | int i; |
| 635 | |
| 636 | if (ctrl->refcnt && !atomic_dec_and_test(ctrl->refcnt)) |
| 637 | return; |
| 638 | |
| 639 | for (i = 0; i < ctrl->nr_regs; i++) |
| 640 | regmap_write(pmu_regs, ctrl->regs[i], ctrl->value); |
| 641 | } |
| 642 | |
Krzysztof Kozlowski | cfa76dd | 2017-05-16 20:56:27 +0200 | [diff] [blame] | 643 | struct samsung_retention_ctrl * |
Marek Szyprowski | 0773101 | 2017-01-26 10:29:25 +0100 | [diff] [blame] | 644 | exynos_retention_init(struct samsung_pinctrl_drv_data *drvdata, |
| 645 | const struct samsung_retention_data *data) |
| 646 | { |
| 647 | struct samsung_retention_ctrl *ctrl; |
| 648 | struct regmap *pmu_regs; |
Marek Szyprowski | 8fe9bf0 | 2017-03-23 09:03:22 +0100 | [diff] [blame] | 649 | int i; |
Marek Szyprowski | 0773101 | 2017-01-26 10:29:25 +0100 | [diff] [blame] | 650 | |
| 651 | ctrl = devm_kzalloc(drvdata->dev, sizeof(*ctrl), GFP_KERNEL); |
| 652 | if (!ctrl) |
| 653 | return ERR_PTR(-ENOMEM); |
| 654 | |
| 655 | pmu_regs = exynos_get_pmu_regmap(); |
| 656 | if (IS_ERR(pmu_regs)) |
| 657 | return ERR_CAST(pmu_regs); |
| 658 | |
| 659 | ctrl->priv = pmu_regs; |
| 660 | ctrl->regs = data->regs; |
| 661 | ctrl->nr_regs = data->nr_regs; |
| 662 | ctrl->value = data->value; |
| 663 | ctrl->refcnt = data->refcnt; |
| 664 | ctrl->enable = exynos_retention_enable; |
| 665 | ctrl->disable = exynos_retention_disable; |
| 666 | |
Marek Szyprowski | 8fe9bf0 | 2017-03-23 09:03:22 +0100 | [diff] [blame] | 667 | /* Ensure that retention is disabled on driver init */ |
| 668 | for (i = 0; i < ctrl->nr_regs; i++) |
| 669 | regmap_write(pmu_regs, ctrl->regs[i], ctrl->value); |
| 670 | |
Marek Szyprowski | 0773101 | 2017-01-26 10:29:25 +0100 | [diff] [blame] | 671 | return ctrl; |
| 672 | } |