Krzysztof Kozlowski | 221173a | 2017-12-26 19:09:42 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | // |
| 3 | // S3C24XX specific support for Samsung pinctrl/gpiolib driver. |
| 4 | // |
| 5 | // Copyright (c) 2013 Heiko Stuebner <heiko@sntech.de> |
| 6 | // |
| 7 | // This file contains the SamsungS3C24XX specific information required by the |
| 8 | // Samsung pinctrl/gpiolib driver. It also includes the implementation of |
| 9 | // external gpio and wakeup interrupt support. |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 10 | |
Paul Gortmaker | 8208b28 | 2017-05-22 16:56:46 -0400 | [diff] [blame] | 11 | #include <linux/init.h> |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 12 | #include <linux/device.h> |
| 13 | #include <linux/interrupt.h> |
| 14 | #include <linux/irqdomain.h> |
| 15 | #include <linux/irq.h> |
| 16 | #include <linux/of_irq.h> |
Heiko Stuebner | c2c70a7 | 2013-06-19 02:41:14 +0900 | [diff] [blame] | 17 | #include <linux/irqchip/chained_irq.h> |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 18 | #include <linux/io.h> |
| 19 | #include <linux/slab.h> |
| 20 | #include <linux/err.h> |
| 21 | |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 22 | #include "pinctrl-samsung.h" |
| 23 | |
| 24 | #define NUM_EINT 24 |
| 25 | #define NUM_EINT_IRQ 6 |
| 26 | #define EINT_MAX_PER_GROUP 8 |
| 27 | |
| 28 | #define EINTPEND_REG 0xa8 |
| 29 | #define EINTMASK_REG 0xa4 |
| 30 | |
| 31 | #define EINT_GROUP(i) ((int)((i) / EINT_MAX_PER_GROUP)) |
| 32 | #define EINT_REG(i) ((EINT_GROUP(i) * 4) + 0x88) |
| 33 | #define EINT_OFFS(i) ((i) % EINT_MAX_PER_GROUP * 4) |
| 34 | |
| 35 | #define EINT_LEVEL_LOW 0 |
| 36 | #define EINT_LEVEL_HIGH 1 |
| 37 | #define EINT_EDGE_FALLING 2 |
| 38 | #define EINT_EDGE_RISING 4 |
| 39 | #define EINT_EDGE_BOTH 6 |
| 40 | #define EINT_MASK 0xf |
| 41 | |
Tomasz Figa | 94ce944 | 2014-09-23 21:05:39 +0200 | [diff] [blame] | 42 | static const struct samsung_pin_bank_type bank_type_1bit = { |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 43 | .fld_width = { 1, 1, }, |
| 44 | .reg_offset = { 0x00, 0x04, }, |
| 45 | }; |
| 46 | |
Tomasz Figa | 94ce944 | 2014-09-23 21:05:39 +0200 | [diff] [blame] | 47 | static const struct samsung_pin_bank_type bank_type_2bit = { |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 48 | .fld_width = { 2, 1, 2, }, |
| 49 | .reg_offset = { 0x00, 0x04, 0x08, }, |
| 50 | }; |
| 51 | |
| 52 | #define PIN_BANK_A(pins, reg, id) \ |
| 53 | { \ |
| 54 | .type = &bank_type_1bit, \ |
| 55 | .pctl_offset = reg, \ |
| 56 | .nr_pins = pins, \ |
| 57 | .eint_type = EINT_TYPE_NONE, \ |
| 58 | .name = id \ |
| 59 | } |
| 60 | |
| 61 | #define PIN_BANK_2BIT(pins, reg, id) \ |
| 62 | { \ |
| 63 | .type = &bank_type_2bit, \ |
| 64 | .pctl_offset = reg, \ |
| 65 | .nr_pins = pins, \ |
| 66 | .eint_type = EINT_TYPE_NONE, \ |
| 67 | .name = id \ |
| 68 | } |
| 69 | |
| 70 | #define PIN_BANK_2BIT_EINTW(pins, reg, id, eoffs, emask)\ |
| 71 | { \ |
| 72 | .type = &bank_type_2bit, \ |
| 73 | .pctl_offset = reg, \ |
| 74 | .nr_pins = pins, \ |
| 75 | .eint_type = EINT_TYPE_WKUP, \ |
| 76 | .eint_func = 2, \ |
| 77 | .eint_mask = emask, \ |
| 78 | .eint_offset = eoffs, \ |
| 79 | .name = id \ |
| 80 | } |
| 81 | |
| 82 | /** |
Lee Jones | 26b7216 | 2020-07-13 15:49:12 +0100 | [diff] [blame] | 83 | * struct s3c24xx_eint_data - EINT common data |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 84 | * @drvdata: pin controller driver data |
| 85 | * @domains: IRQ domains of particular EINT interrupts |
| 86 | * @parents: mapped parent irqs in the main interrupt controller |
| 87 | */ |
| 88 | struct s3c24xx_eint_data { |
| 89 | struct samsung_pinctrl_drv_data *drvdata; |
| 90 | struct irq_domain *domains[NUM_EINT]; |
| 91 | int parents[NUM_EINT_IRQ]; |
| 92 | }; |
| 93 | |
| 94 | /** |
Lee Jones | 26b7216 | 2020-07-13 15:49:12 +0100 | [diff] [blame] | 95 | * struct s3c24xx_eint_domain_data - per irq-domain data |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 96 | * @bank: pin bank related to the domain |
| 97 | * @eint_data: common data |
Lee Jones | 26b7216 | 2020-07-13 15:49:12 +0100 | [diff] [blame] | 98 | * @eint0_3_parent_only: live eints 0-3 only in the main intc |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 99 | */ |
| 100 | struct s3c24xx_eint_domain_data { |
| 101 | struct samsung_pin_bank *bank; |
| 102 | struct s3c24xx_eint_data *eint_data; |
| 103 | bool eint0_3_parent_only; |
| 104 | }; |
| 105 | |
| 106 | static int s3c24xx_eint_get_trigger(unsigned int type) |
| 107 | { |
| 108 | switch (type) { |
| 109 | case IRQ_TYPE_EDGE_RISING: |
| 110 | return EINT_EDGE_RISING; |
| 111 | break; |
| 112 | case IRQ_TYPE_EDGE_FALLING: |
| 113 | return EINT_EDGE_FALLING; |
| 114 | break; |
| 115 | case IRQ_TYPE_EDGE_BOTH: |
| 116 | return EINT_EDGE_BOTH; |
| 117 | break; |
| 118 | case IRQ_TYPE_LEVEL_HIGH: |
| 119 | return EINT_LEVEL_HIGH; |
| 120 | break; |
| 121 | case IRQ_TYPE_LEVEL_LOW: |
| 122 | return EINT_LEVEL_LOW; |
| 123 | break; |
| 124 | default: |
| 125 | return -EINVAL; |
| 126 | } |
| 127 | } |
| 128 | |
Thomas Gleixner | f66eb49 | 2015-06-23 15:52:57 +0200 | [diff] [blame] | 129 | static void s3c24xx_eint_set_handler(struct irq_data *d, unsigned int type) |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 130 | { |
| 131 | /* Edge- and level-triggered interrupts need different handlers */ |
| 132 | if (type & IRQ_TYPE_EDGE_BOTH) |
Thomas Gleixner | f66eb49 | 2015-06-23 15:52:57 +0200 | [diff] [blame] | 133 | irq_set_handler_locked(d, handle_edge_irq); |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 134 | else |
Thomas Gleixner | f66eb49 | 2015-06-23 15:52:57 +0200 | [diff] [blame] | 135 | irq_set_handler_locked(d, handle_level_irq); |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | static void s3c24xx_eint_set_function(struct samsung_pinctrl_drv_data *d, |
| 139 | struct samsung_pin_bank *bank, int pin) |
| 140 | { |
Tomasz Figa | 94ce944 | 2014-09-23 21:05:39 +0200 | [diff] [blame] | 141 | const struct samsung_pin_bank_type *bank_type = bank->type; |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 142 | unsigned long flags; |
| 143 | void __iomem *reg; |
| 144 | u8 shift; |
| 145 | u32 mask; |
| 146 | u32 val; |
| 147 | |
| 148 | /* Make sure that pin is configured as interrupt */ |
Krzysztof Kozlowski | cee7413 | 2017-06-15 17:46:37 +0200 | [diff] [blame] | 149 | reg = d->virt_base + bank->pctl_offset; |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 150 | shift = pin * bank_type->fld_width[PINCFG_TYPE_FUNC]; |
| 151 | mask = (1 << bank_type->fld_width[PINCFG_TYPE_FUNC]) - 1; |
| 152 | |
| 153 | spin_lock_irqsave(&bank->slock, flags); |
| 154 | |
| 155 | val = readl(reg); |
| 156 | val &= ~(mask << shift); |
| 157 | val |= bank->eint_func << shift; |
| 158 | writel(val, reg); |
| 159 | |
| 160 | spin_unlock_irqrestore(&bank->slock, flags); |
| 161 | } |
| 162 | |
| 163 | static int s3c24xx_eint_type(struct irq_data *data, unsigned int type) |
| 164 | { |
| 165 | struct samsung_pin_bank *bank = irq_data_get_irq_chip_data(data); |
| 166 | struct samsung_pinctrl_drv_data *d = bank->drvdata; |
| 167 | int index = bank->eint_offset + data->hwirq; |
| 168 | void __iomem *reg; |
| 169 | int trigger; |
| 170 | u8 shift; |
| 171 | u32 val; |
| 172 | |
| 173 | trigger = s3c24xx_eint_get_trigger(type); |
| 174 | if (trigger < 0) { |
| 175 | dev_err(d->dev, "unsupported external interrupt type\n"); |
| 176 | return -EINVAL; |
| 177 | } |
| 178 | |
Thomas Gleixner | f66eb49 | 2015-06-23 15:52:57 +0200 | [diff] [blame] | 179 | s3c24xx_eint_set_handler(data, type); |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 180 | |
| 181 | /* Set up interrupt trigger */ |
Krzysztof Kozlowski | cee7413 | 2017-06-15 17:46:37 +0200 | [diff] [blame] | 182 | reg = d->virt_base + EINT_REG(index); |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 183 | shift = EINT_OFFS(index); |
| 184 | |
| 185 | val = readl(reg); |
| 186 | val &= ~(EINT_MASK << shift); |
| 187 | val |= trigger << shift; |
| 188 | writel(val, reg); |
| 189 | |
| 190 | s3c24xx_eint_set_function(d, bank, data->hwirq); |
| 191 | |
| 192 | return 0; |
| 193 | } |
| 194 | |
| 195 | /* Handling of EINTs 0-3 on all except S3C2412 and S3C2413 */ |
| 196 | |
| 197 | static void s3c2410_eint0_3_ack(struct irq_data *data) |
| 198 | { |
| 199 | struct samsung_pin_bank *bank = irq_data_get_irq_chip_data(data); |
| 200 | struct s3c24xx_eint_domain_data *ddata = bank->irq_domain->host_data; |
| 201 | struct s3c24xx_eint_data *eint_data = ddata->eint_data; |
| 202 | int parent_irq = eint_data->parents[data->hwirq]; |
| 203 | struct irq_chip *parent_chip = irq_get_chip(parent_irq); |
| 204 | |
| 205 | parent_chip->irq_ack(irq_get_irq_data(parent_irq)); |
| 206 | } |
| 207 | |
| 208 | static void s3c2410_eint0_3_mask(struct irq_data *data) |
| 209 | { |
| 210 | struct samsung_pin_bank *bank = irq_data_get_irq_chip_data(data); |
| 211 | struct s3c24xx_eint_domain_data *ddata = bank->irq_domain->host_data; |
| 212 | struct s3c24xx_eint_data *eint_data = ddata->eint_data; |
| 213 | int parent_irq = eint_data->parents[data->hwirq]; |
| 214 | struct irq_chip *parent_chip = irq_get_chip(parent_irq); |
| 215 | |
| 216 | parent_chip->irq_mask(irq_get_irq_data(parent_irq)); |
| 217 | } |
| 218 | |
| 219 | static void s3c2410_eint0_3_unmask(struct irq_data *data) |
| 220 | { |
| 221 | struct samsung_pin_bank *bank = irq_data_get_irq_chip_data(data); |
| 222 | struct s3c24xx_eint_domain_data *ddata = bank->irq_domain->host_data; |
| 223 | struct s3c24xx_eint_data *eint_data = ddata->eint_data; |
| 224 | int parent_irq = eint_data->parents[data->hwirq]; |
| 225 | struct irq_chip *parent_chip = irq_get_chip(parent_irq); |
| 226 | |
| 227 | parent_chip->irq_unmask(irq_get_irq_data(parent_irq)); |
| 228 | } |
| 229 | |
| 230 | static struct irq_chip s3c2410_eint0_3_chip = { |
| 231 | .name = "s3c2410-eint0_3", |
| 232 | .irq_ack = s3c2410_eint0_3_ack, |
| 233 | .irq_mask = s3c2410_eint0_3_mask, |
| 234 | .irq_unmask = s3c2410_eint0_3_unmask, |
| 235 | .irq_set_type = s3c24xx_eint_type, |
| 236 | }; |
| 237 | |
Thomas Gleixner | bd0b9ac | 2015-09-14 10:42:37 +0200 | [diff] [blame] | 238 | static void s3c2410_demux_eint0_3(struct irq_desc *desc) |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 239 | { |
| 240 | struct irq_data *data = irq_desc_get_irq_data(desc); |
Jiang Liu | 5663bb2 | 2015-06-04 12:13:16 +0800 | [diff] [blame] | 241 | struct s3c24xx_eint_data *eint_data = irq_desc_get_handler_data(desc); |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 242 | unsigned int virq; |
| 243 | |
| 244 | /* the first 4 eints have a simple 1 to 1 mapping */ |
| 245 | virq = irq_linear_revmap(eint_data->domains[data->hwirq], data->hwirq); |
| 246 | /* Something must be really wrong if an unmapped EINT is unmasked */ |
| 247 | BUG_ON(!virq); |
| 248 | |
| 249 | generic_handle_irq(virq); |
| 250 | } |
| 251 | |
| 252 | /* Handling of EINTs 0-3 on S3C2412 and S3C2413 */ |
| 253 | |
| 254 | static void s3c2412_eint0_3_ack(struct irq_data *data) |
| 255 | { |
| 256 | struct samsung_pin_bank *bank = irq_data_get_irq_chip_data(data); |
Krzysztof Kozlowski | cee7413 | 2017-06-15 17:46:37 +0200 | [diff] [blame] | 257 | struct samsung_pinctrl_drv_data *d = bank->drvdata; |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 258 | |
| 259 | unsigned long bitval = 1UL << data->hwirq; |
Krzysztof Kozlowski | cee7413 | 2017-06-15 17:46:37 +0200 | [diff] [blame] | 260 | writel(bitval, d->virt_base + EINTPEND_REG); |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | static void s3c2412_eint0_3_mask(struct irq_data *data) |
| 264 | { |
| 265 | struct samsung_pin_bank *bank = irq_data_get_irq_chip_data(data); |
Krzysztof Kozlowski | cee7413 | 2017-06-15 17:46:37 +0200 | [diff] [blame] | 266 | struct samsung_pinctrl_drv_data *d = bank->drvdata; |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 267 | unsigned long mask; |
| 268 | |
Krzysztof Kozlowski | cee7413 | 2017-06-15 17:46:37 +0200 | [diff] [blame] | 269 | mask = readl(d->virt_base + EINTMASK_REG); |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 270 | mask |= (1UL << data->hwirq); |
Krzysztof Kozlowski | cee7413 | 2017-06-15 17:46:37 +0200 | [diff] [blame] | 271 | writel(mask, d->virt_base + EINTMASK_REG); |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | static void s3c2412_eint0_3_unmask(struct irq_data *data) |
| 275 | { |
| 276 | struct samsung_pin_bank *bank = irq_data_get_irq_chip_data(data); |
Krzysztof Kozlowski | cee7413 | 2017-06-15 17:46:37 +0200 | [diff] [blame] | 277 | struct samsung_pinctrl_drv_data *d = bank->drvdata; |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 278 | unsigned long mask; |
| 279 | |
Krzysztof Kozlowski | cee7413 | 2017-06-15 17:46:37 +0200 | [diff] [blame] | 280 | mask = readl(d->virt_base + EINTMASK_REG); |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 281 | mask &= ~(1UL << data->hwirq); |
Krzysztof Kozlowski | cee7413 | 2017-06-15 17:46:37 +0200 | [diff] [blame] | 282 | writel(mask, d->virt_base + EINTMASK_REG); |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | static struct irq_chip s3c2412_eint0_3_chip = { |
| 286 | .name = "s3c2412-eint0_3", |
| 287 | .irq_ack = s3c2412_eint0_3_ack, |
| 288 | .irq_mask = s3c2412_eint0_3_mask, |
| 289 | .irq_unmask = s3c2412_eint0_3_unmask, |
| 290 | .irq_set_type = s3c24xx_eint_type, |
| 291 | }; |
| 292 | |
Thomas Gleixner | bd0b9ac | 2015-09-14 10:42:37 +0200 | [diff] [blame] | 293 | static void s3c2412_demux_eint0_3(struct irq_desc *desc) |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 294 | { |
Jiang Liu | 5663bb2 | 2015-06-04 12:13:16 +0800 | [diff] [blame] | 295 | struct s3c24xx_eint_data *eint_data = irq_desc_get_handler_data(desc); |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 296 | struct irq_data *data = irq_desc_get_irq_data(desc); |
Jiang Liu | 5663bb2 | 2015-06-04 12:13:16 +0800 | [diff] [blame] | 297 | struct irq_chip *chip = irq_data_get_irq_chip(data); |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 298 | unsigned int virq; |
| 299 | |
| 300 | chained_irq_enter(chip, desc); |
| 301 | |
| 302 | /* the first 4 eints have a simple 1 to 1 mapping */ |
| 303 | virq = irq_linear_revmap(eint_data->domains[data->hwirq], data->hwirq); |
| 304 | /* Something must be really wrong if an unmapped EINT is unmasked */ |
| 305 | BUG_ON(!virq); |
| 306 | |
| 307 | generic_handle_irq(virq); |
| 308 | |
| 309 | chained_irq_exit(chip, desc); |
| 310 | } |
| 311 | |
| 312 | /* Handling of all other eints */ |
| 313 | |
| 314 | static void s3c24xx_eint_ack(struct irq_data *data) |
| 315 | { |
| 316 | struct samsung_pin_bank *bank = irq_data_get_irq_chip_data(data); |
Krzysztof Kozlowski | cee7413 | 2017-06-15 17:46:37 +0200 | [diff] [blame] | 317 | struct samsung_pinctrl_drv_data *d = bank->drvdata; |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 318 | unsigned char index = bank->eint_offset + data->hwirq; |
| 319 | |
Krzysztof Kozlowski | cee7413 | 2017-06-15 17:46:37 +0200 | [diff] [blame] | 320 | writel(1UL << index, d->virt_base + EINTPEND_REG); |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | static void s3c24xx_eint_mask(struct irq_data *data) |
| 324 | { |
| 325 | struct samsung_pin_bank *bank = irq_data_get_irq_chip_data(data); |
Krzysztof Kozlowski | cee7413 | 2017-06-15 17:46:37 +0200 | [diff] [blame] | 326 | struct samsung_pinctrl_drv_data *d = bank->drvdata; |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 327 | unsigned char index = bank->eint_offset + data->hwirq; |
| 328 | unsigned long mask; |
| 329 | |
Krzysztof Kozlowski | cee7413 | 2017-06-15 17:46:37 +0200 | [diff] [blame] | 330 | mask = readl(d->virt_base + EINTMASK_REG); |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 331 | mask |= (1UL << index); |
Krzysztof Kozlowski | cee7413 | 2017-06-15 17:46:37 +0200 | [diff] [blame] | 332 | writel(mask, d->virt_base + EINTMASK_REG); |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | static void s3c24xx_eint_unmask(struct irq_data *data) |
| 336 | { |
| 337 | struct samsung_pin_bank *bank = irq_data_get_irq_chip_data(data); |
Krzysztof Kozlowski | cee7413 | 2017-06-15 17:46:37 +0200 | [diff] [blame] | 338 | struct samsung_pinctrl_drv_data *d = bank->drvdata; |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 339 | unsigned char index = bank->eint_offset + data->hwirq; |
| 340 | unsigned long mask; |
| 341 | |
Krzysztof Kozlowski | cee7413 | 2017-06-15 17:46:37 +0200 | [diff] [blame] | 342 | mask = readl(d->virt_base + EINTMASK_REG); |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 343 | mask &= ~(1UL << index); |
Krzysztof Kozlowski | cee7413 | 2017-06-15 17:46:37 +0200 | [diff] [blame] | 344 | writel(mask, d->virt_base + EINTMASK_REG); |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | static struct irq_chip s3c24xx_eint_chip = { |
| 348 | .name = "s3c-eint", |
| 349 | .irq_ack = s3c24xx_eint_ack, |
| 350 | .irq_mask = s3c24xx_eint_mask, |
| 351 | .irq_unmask = s3c24xx_eint_unmask, |
| 352 | .irq_set_type = s3c24xx_eint_type, |
| 353 | }; |
| 354 | |
Jiang Liu | 5663bb2 | 2015-06-04 12:13:16 +0800 | [diff] [blame] | 355 | static inline void s3c24xx_demux_eint(struct irq_desc *desc, |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 356 | u32 offset, u32 range) |
| 357 | { |
Jiang Liu | 5663bb2 | 2015-06-04 12:13:16 +0800 | [diff] [blame] | 358 | struct s3c24xx_eint_data *data = irq_desc_get_handler_data(desc); |
Linus Walleij | fa84b52 | 2015-09-08 16:46:40 +0200 | [diff] [blame] | 359 | struct irq_chip *chip = irq_desc_get_chip(desc); |
Krzysztof Kozlowski | cee7413 | 2017-06-15 17:46:37 +0200 | [diff] [blame] | 360 | struct samsung_pinctrl_drv_data *d = data->drvdata; |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 361 | unsigned int pend, mask; |
| 362 | |
| 363 | chained_irq_enter(chip, desc); |
| 364 | |
Krzysztof Kozlowski | cee7413 | 2017-06-15 17:46:37 +0200 | [diff] [blame] | 365 | pend = readl(d->virt_base + EINTPEND_REG); |
| 366 | mask = readl(d->virt_base + EINTMASK_REG); |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 367 | |
| 368 | pend &= ~mask; |
| 369 | pend &= range; |
| 370 | |
| 371 | while (pend) { |
Jiang Liu | 5663bb2 | 2015-06-04 12:13:16 +0800 | [diff] [blame] | 372 | unsigned int virq, irq; |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 373 | |
| 374 | irq = __ffs(pend); |
| 375 | pend &= ~(1 << irq); |
| 376 | virq = irq_linear_revmap(data->domains[irq], irq - offset); |
| 377 | /* Something is really wrong if an unmapped EINT is unmasked */ |
| 378 | BUG_ON(!virq); |
| 379 | |
| 380 | generic_handle_irq(virq); |
| 381 | } |
| 382 | |
| 383 | chained_irq_exit(chip, desc); |
| 384 | } |
| 385 | |
Thomas Gleixner | bd0b9ac | 2015-09-14 10:42:37 +0200 | [diff] [blame] | 386 | static void s3c24xx_demux_eint4_7(struct irq_desc *desc) |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 387 | { |
Jiang Liu | 5663bb2 | 2015-06-04 12:13:16 +0800 | [diff] [blame] | 388 | s3c24xx_demux_eint(desc, 0, 0xf0); |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 389 | } |
| 390 | |
Thomas Gleixner | bd0b9ac | 2015-09-14 10:42:37 +0200 | [diff] [blame] | 391 | static void s3c24xx_demux_eint8_23(struct irq_desc *desc) |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 392 | { |
Jiang Liu | 5663bb2 | 2015-06-04 12:13:16 +0800 | [diff] [blame] | 393 | s3c24xx_demux_eint(desc, 8, 0xffff00); |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | static irq_flow_handler_t s3c2410_eint_handlers[NUM_EINT_IRQ] = { |
| 397 | s3c2410_demux_eint0_3, |
| 398 | s3c2410_demux_eint0_3, |
| 399 | s3c2410_demux_eint0_3, |
| 400 | s3c2410_demux_eint0_3, |
| 401 | s3c24xx_demux_eint4_7, |
| 402 | s3c24xx_demux_eint8_23, |
| 403 | }; |
| 404 | |
| 405 | static irq_flow_handler_t s3c2412_eint_handlers[NUM_EINT_IRQ] = { |
| 406 | s3c2412_demux_eint0_3, |
| 407 | s3c2412_demux_eint0_3, |
| 408 | s3c2412_demux_eint0_3, |
| 409 | s3c2412_demux_eint0_3, |
| 410 | s3c24xx_demux_eint4_7, |
| 411 | s3c24xx_demux_eint8_23, |
| 412 | }; |
| 413 | |
| 414 | static int s3c24xx_gpf_irq_map(struct irq_domain *h, unsigned int virq, |
| 415 | irq_hw_number_t hw) |
| 416 | { |
| 417 | struct s3c24xx_eint_domain_data *ddata = h->host_data; |
| 418 | struct samsung_pin_bank *bank = ddata->bank; |
| 419 | |
| 420 | if (!(bank->eint_mask & (1 << (bank->eint_offset + hw)))) |
| 421 | return -EINVAL; |
| 422 | |
| 423 | if (hw <= 3) { |
| 424 | if (ddata->eint0_3_parent_only) |
| 425 | irq_set_chip_and_handler(virq, &s3c2410_eint0_3_chip, |
| 426 | handle_edge_irq); |
| 427 | else |
| 428 | irq_set_chip_and_handler(virq, &s3c2412_eint0_3_chip, |
| 429 | handle_edge_irq); |
| 430 | } else { |
| 431 | irq_set_chip_and_handler(virq, &s3c24xx_eint_chip, |
| 432 | handle_edge_irq); |
| 433 | } |
| 434 | irq_set_chip_data(virq, bank); |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 435 | return 0; |
| 436 | } |
| 437 | |
| 438 | static const struct irq_domain_ops s3c24xx_gpf_irq_ops = { |
| 439 | .map = s3c24xx_gpf_irq_map, |
| 440 | .xlate = irq_domain_xlate_twocell, |
| 441 | }; |
| 442 | |
| 443 | static int s3c24xx_gpg_irq_map(struct irq_domain *h, unsigned int virq, |
| 444 | irq_hw_number_t hw) |
| 445 | { |
| 446 | struct s3c24xx_eint_domain_data *ddata = h->host_data; |
| 447 | struct samsung_pin_bank *bank = ddata->bank; |
| 448 | |
| 449 | if (!(bank->eint_mask & (1 << (bank->eint_offset + hw)))) |
| 450 | return -EINVAL; |
| 451 | |
| 452 | irq_set_chip_and_handler(virq, &s3c24xx_eint_chip, handle_edge_irq); |
| 453 | irq_set_chip_data(virq, bank); |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 454 | return 0; |
| 455 | } |
| 456 | |
| 457 | static const struct irq_domain_ops s3c24xx_gpg_irq_ops = { |
| 458 | .map = s3c24xx_gpg_irq_map, |
| 459 | .xlate = irq_domain_xlate_twocell, |
| 460 | }; |
| 461 | |
| 462 | static const struct of_device_id s3c24xx_eint_irq_ids[] = { |
| 463 | { .compatible = "samsung,s3c2410-wakeup-eint", .data = (void *)1 }, |
| 464 | { .compatible = "samsung,s3c2412-wakeup-eint", .data = (void *)0 }, |
| 465 | { } |
| 466 | }; |
| 467 | |
| 468 | static int s3c24xx_eint_init(struct samsung_pinctrl_drv_data *d) |
| 469 | { |
| 470 | struct device *dev = d->dev; |
| 471 | const struct of_device_id *match; |
| 472 | struct device_node *eint_np = NULL; |
| 473 | struct device_node *np; |
| 474 | struct samsung_pin_bank *bank; |
| 475 | struct s3c24xx_eint_data *eint_data; |
| 476 | const struct irq_domain_ops *ops; |
| 477 | unsigned int i; |
| 478 | bool eint0_3_parent_only; |
| 479 | irq_flow_handler_t *handlers; |
| 480 | |
| 481 | for_each_child_of_node(dev->of_node, np) { |
| 482 | match = of_match_node(s3c24xx_eint_irq_ids, np); |
| 483 | if (match) { |
| 484 | eint_np = np; |
| 485 | eint0_3_parent_only = (bool)match->data; |
| 486 | break; |
| 487 | } |
| 488 | } |
| 489 | if (!eint_np) |
| 490 | return -ENODEV; |
| 491 | |
| 492 | eint_data = devm_kzalloc(dev, sizeof(*eint_data), GFP_KERNEL); |
Krzysztof Kozlowski | 6fbbcb0 | 2019-08-05 18:27:08 +0200 | [diff] [blame] | 493 | if (!eint_data) { |
| 494 | of_node_put(eint_np); |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 495 | return -ENOMEM; |
Krzysztof Kozlowski | 6fbbcb0 | 2019-08-05 18:27:08 +0200 | [diff] [blame] | 496 | } |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 497 | |
| 498 | eint_data->drvdata = d; |
| 499 | |
| 500 | handlers = eint0_3_parent_only ? s3c2410_eint_handlers |
| 501 | : s3c2412_eint_handlers; |
| 502 | for (i = 0; i < NUM_EINT_IRQ; ++i) { |
| 503 | unsigned int irq; |
| 504 | |
| 505 | irq = irq_of_parse_and_map(eint_np, i); |
| 506 | if (!irq) { |
| 507 | dev_err(dev, "failed to get wakeup EINT IRQ %d\n", i); |
Krzysztof Kozlowski | 6fbbcb0 | 2019-08-05 18:27:08 +0200 | [diff] [blame] | 508 | of_node_put(eint_np); |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 509 | return -ENXIO; |
| 510 | } |
| 511 | |
| 512 | eint_data->parents[i] = irq; |
Thomas Gleixner | 0cfc45c | 2015-06-21 20:16:17 +0200 | [diff] [blame] | 513 | irq_set_chained_handler_and_data(irq, handlers[i], eint_data); |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 514 | } |
Krzysztof Kozlowski | 6fbbcb0 | 2019-08-05 18:27:08 +0200 | [diff] [blame] | 515 | of_node_put(eint_np); |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 516 | |
Tomasz Figa | 1bf00d7 | 2014-09-23 21:05:40 +0200 | [diff] [blame] | 517 | bank = d->pin_banks; |
| 518 | for (i = 0; i < d->nr_banks; ++i, ++bank) { |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 519 | struct s3c24xx_eint_domain_data *ddata; |
| 520 | unsigned int mask; |
| 521 | unsigned int irq; |
| 522 | unsigned int pin; |
| 523 | |
| 524 | if (bank->eint_type != EINT_TYPE_WKUP) |
| 525 | continue; |
| 526 | |
| 527 | ddata = devm_kzalloc(dev, sizeof(*ddata), GFP_KERNEL); |
| 528 | if (!ddata) |
| 529 | return -ENOMEM; |
| 530 | |
| 531 | ddata->bank = bank; |
| 532 | ddata->eint_data = eint_data; |
| 533 | ddata->eint0_3_parent_only = eint0_3_parent_only; |
| 534 | |
| 535 | ops = (bank->eint_offset == 0) ? &s3c24xx_gpf_irq_ops |
| 536 | : &s3c24xx_gpg_irq_ops; |
| 537 | |
| 538 | bank->irq_domain = irq_domain_add_linear(bank->of_node, |
| 539 | bank->nr_pins, ops, ddata); |
| 540 | if (!bank->irq_domain) { |
| 541 | dev_err(dev, "wkup irq domain add failed\n"); |
| 542 | return -ENXIO; |
| 543 | } |
| 544 | |
| 545 | irq = bank->eint_offset; |
| 546 | mask = bank->eint_mask; |
| 547 | for (pin = 0; mask; ++pin, mask >>= 1) { |
Dan Carpenter | 774e2d9 | 2013-08-27 04:11:26 +0300 | [diff] [blame] | 548 | if (irq >= NUM_EINT) |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 549 | break; |
| 550 | if (!(mask & 1)) |
| 551 | continue; |
| 552 | eint_data->domains[irq] = bank->irq_domain; |
| 553 | ++irq; |
| 554 | } |
| 555 | } |
| 556 | |
| 557 | return 0; |
| 558 | } |
| 559 | |
Tomasz Figa | 8100cf4 | 2014-09-23 21:05:41 +0200 | [diff] [blame] | 560 | static const struct samsung_pin_bank_data s3c2412_pin_banks[] __initconst = { |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 561 | PIN_BANK_A(23, 0x000, "gpa"), |
| 562 | PIN_BANK_2BIT(11, 0x010, "gpb"), |
| 563 | PIN_BANK_2BIT(16, 0x020, "gpc"), |
| 564 | PIN_BANK_2BIT(16, 0x030, "gpd"), |
| 565 | PIN_BANK_2BIT(16, 0x040, "gpe"), |
| 566 | PIN_BANK_2BIT_EINTW(8, 0x050, "gpf", 0, 0xff), |
| 567 | PIN_BANK_2BIT_EINTW(16, 0x060, "gpg", 8, 0xffff00), |
| 568 | PIN_BANK_2BIT(11, 0x070, "gph"), |
| 569 | PIN_BANK_2BIT(13, 0x080, "gpj"), |
| 570 | }; |
| 571 | |
Krzysztof Kozlowski | 93b0bea | 2018-02-20 19:17:51 +0100 | [diff] [blame] | 572 | static const struct samsung_pin_ctrl s3c2412_pin_ctrl[] __initconst = { |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 573 | { |
| 574 | .pin_banks = s3c2412_pin_banks, |
| 575 | .nr_banks = ARRAY_SIZE(s3c2412_pin_banks), |
| 576 | .eint_wkup_init = s3c24xx_eint_init, |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 577 | }, |
| 578 | }; |
| 579 | |
Krzysztof Kozlowski | 93b0bea | 2018-02-20 19:17:51 +0100 | [diff] [blame] | 580 | const struct samsung_pinctrl_of_match_data s3c2412_of_data __initconst = { |
| 581 | .ctrl = s3c2412_pin_ctrl, |
| 582 | .num_ctrl = ARRAY_SIZE(s3c2412_pin_ctrl), |
| 583 | }; |
| 584 | |
Tomasz Figa | 8100cf4 | 2014-09-23 21:05:41 +0200 | [diff] [blame] | 585 | static const struct samsung_pin_bank_data s3c2416_pin_banks[] __initconst = { |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 586 | PIN_BANK_A(27, 0x000, "gpa"), |
| 587 | PIN_BANK_2BIT(11, 0x010, "gpb"), |
| 588 | PIN_BANK_2BIT(16, 0x020, "gpc"), |
| 589 | PIN_BANK_2BIT(16, 0x030, "gpd"), |
| 590 | PIN_BANK_2BIT(16, 0x040, "gpe"), |
| 591 | PIN_BANK_2BIT_EINTW(8, 0x050, "gpf", 0, 0xff), |
| 592 | PIN_BANK_2BIT_EINTW(8, 0x060, "gpg", 8, 0xff00), |
| 593 | PIN_BANK_2BIT(15, 0x070, "gph"), |
| 594 | PIN_BANK_2BIT(16, 0x0e0, "gpk"), |
| 595 | PIN_BANK_2BIT(14, 0x0f0, "gpl"), |
| 596 | PIN_BANK_2BIT(2, 0x100, "gpm"), |
| 597 | }; |
| 598 | |
Krzysztof Kozlowski | 93b0bea | 2018-02-20 19:17:51 +0100 | [diff] [blame] | 599 | static const struct samsung_pin_ctrl s3c2416_pin_ctrl[] __initconst = { |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 600 | { |
| 601 | .pin_banks = s3c2416_pin_banks, |
| 602 | .nr_banks = ARRAY_SIZE(s3c2416_pin_banks), |
| 603 | .eint_wkup_init = s3c24xx_eint_init, |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 604 | }, |
| 605 | }; |
| 606 | |
Krzysztof Kozlowski | 93b0bea | 2018-02-20 19:17:51 +0100 | [diff] [blame] | 607 | const struct samsung_pinctrl_of_match_data s3c2416_of_data __initconst = { |
| 608 | .ctrl = s3c2416_pin_ctrl, |
| 609 | .num_ctrl = ARRAY_SIZE(s3c2416_pin_ctrl), |
| 610 | }; |
| 611 | |
Tomasz Figa | 8100cf4 | 2014-09-23 21:05:41 +0200 | [diff] [blame] | 612 | static const struct samsung_pin_bank_data s3c2440_pin_banks[] __initconst = { |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 613 | PIN_BANK_A(25, 0x000, "gpa"), |
| 614 | PIN_BANK_2BIT(11, 0x010, "gpb"), |
| 615 | PIN_BANK_2BIT(16, 0x020, "gpc"), |
| 616 | PIN_BANK_2BIT(16, 0x030, "gpd"), |
| 617 | PIN_BANK_2BIT(16, 0x040, "gpe"), |
| 618 | PIN_BANK_2BIT_EINTW(8, 0x050, "gpf", 0, 0xff), |
| 619 | PIN_BANK_2BIT_EINTW(16, 0x060, "gpg", 8, 0xffff00), |
| 620 | PIN_BANK_2BIT(11, 0x070, "gph"), |
| 621 | PIN_BANK_2BIT(13, 0x0d0, "gpj"), |
| 622 | }; |
| 623 | |
Krzysztof Kozlowski | 93b0bea | 2018-02-20 19:17:51 +0100 | [diff] [blame] | 624 | static const struct samsung_pin_ctrl s3c2440_pin_ctrl[] __initconst = { |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 625 | { |
| 626 | .pin_banks = s3c2440_pin_banks, |
| 627 | .nr_banks = ARRAY_SIZE(s3c2440_pin_banks), |
| 628 | .eint_wkup_init = s3c24xx_eint_init, |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 629 | }, |
| 630 | }; |
| 631 | |
Krzysztof Kozlowski | 93b0bea | 2018-02-20 19:17:51 +0100 | [diff] [blame] | 632 | const struct samsung_pinctrl_of_match_data s3c2440_of_data __initconst = { |
| 633 | .ctrl = s3c2440_pin_ctrl, |
| 634 | .num_ctrl = ARRAY_SIZE(s3c2440_pin_ctrl), |
| 635 | }; |
| 636 | |
Tomasz Figa | 8100cf4 | 2014-09-23 21:05:41 +0200 | [diff] [blame] | 637 | static const struct samsung_pin_bank_data s3c2450_pin_banks[] __initconst = { |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 638 | PIN_BANK_A(28, 0x000, "gpa"), |
| 639 | PIN_BANK_2BIT(11, 0x010, "gpb"), |
| 640 | PIN_BANK_2BIT(16, 0x020, "gpc"), |
| 641 | PIN_BANK_2BIT(16, 0x030, "gpd"), |
| 642 | PIN_BANK_2BIT(16, 0x040, "gpe"), |
| 643 | PIN_BANK_2BIT_EINTW(8, 0x050, "gpf", 0, 0xff), |
| 644 | PIN_BANK_2BIT_EINTW(16, 0x060, "gpg", 8, 0xffff00), |
| 645 | PIN_BANK_2BIT(15, 0x070, "gph"), |
| 646 | PIN_BANK_2BIT(16, 0x0d0, "gpj"), |
| 647 | PIN_BANK_2BIT(16, 0x0e0, "gpk"), |
| 648 | PIN_BANK_2BIT(15, 0x0f0, "gpl"), |
| 649 | PIN_BANK_2BIT(2, 0x100, "gpm"), |
| 650 | }; |
| 651 | |
Krzysztof Kozlowski | 93b0bea | 2018-02-20 19:17:51 +0100 | [diff] [blame] | 652 | static const struct samsung_pin_ctrl s3c2450_pin_ctrl[] __initconst = { |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 653 | { |
| 654 | .pin_banks = s3c2450_pin_banks, |
| 655 | .nr_banks = ARRAY_SIZE(s3c2450_pin_banks), |
| 656 | .eint_wkup_init = s3c24xx_eint_init, |
Heiko Stuebner | af99a75 | 2013-05-21 00:56:13 +0900 | [diff] [blame] | 657 | }, |
| 658 | }; |
Krzysztof Kozlowski | 93b0bea | 2018-02-20 19:17:51 +0100 | [diff] [blame] | 659 | |
| 660 | const struct samsung_pinctrl_of_match_data s3c2450_of_data __initconst = { |
| 661 | .ctrl = s3c2450_pin_ctrl, |
| 662 | .num_ctrl = ARRAY_SIZE(s3c2450_pin_ctrl), |
| 663 | }; |