diff options
Diffstat (limited to 'drivers/gpio/gpio-rcar.c')
-rw-r--r-- | drivers/gpio/gpio-rcar.c | 75 |
1 files changed, 25 insertions, 50 deletions
diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c index 584484e3f1e3..c49522efa7b3 100644 --- a/drivers/gpio/gpio-rcar.c +++ b/drivers/gpio/gpio-rcar.c | |||
@@ -21,7 +21,6 @@ | |||
21 | #include <linux/io.h> | 21 | #include <linux/io.h> |
22 | #include <linux/ioport.h> | 22 | #include <linux/ioport.h> |
23 | #include <linux/irq.h> | 23 | #include <linux/irq.h> |
24 | #include <linux/irqdomain.h> | ||
25 | #include <linux/module.h> | 24 | #include <linux/module.h> |
26 | #include <linux/of.h> | 25 | #include <linux/of.h> |
27 | #include <linux/pinctrl/consumer.h> | 26 | #include <linux/pinctrl/consumer.h> |
@@ -38,7 +37,6 @@ struct gpio_rcar_priv { | |||
38 | struct platform_device *pdev; | 37 | struct platform_device *pdev; |
39 | struct gpio_chip gpio_chip; | 38 | struct gpio_chip gpio_chip; |
40 | struct irq_chip irq_chip; | 39 | struct irq_chip irq_chip; |
41 | struct irq_domain *irq_domain; | ||
42 | }; | 40 | }; |
43 | 41 | ||
44 | #define IOINTSEL 0x00 | 42 | #define IOINTSEL 0x00 |
@@ -82,14 +80,18 @@ static void gpio_rcar_modify_bit(struct gpio_rcar_priv *p, int offs, | |||
82 | 80 | ||
83 | static void gpio_rcar_irq_disable(struct irq_data *d) | 81 | static void gpio_rcar_irq_disable(struct irq_data *d) |
84 | { | 82 | { |
85 | struct gpio_rcar_priv *p = irq_data_get_irq_chip_data(d); | 83 | struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
84 | struct gpio_rcar_priv *p = container_of(gc, struct gpio_rcar_priv, | ||
85 | gpio_chip); | ||
86 | 86 | ||
87 | gpio_rcar_write(p, INTMSK, ~BIT(irqd_to_hwirq(d))); | 87 | gpio_rcar_write(p, INTMSK, ~BIT(irqd_to_hwirq(d))); |
88 | } | 88 | } |
89 | 89 | ||
90 | static void gpio_rcar_irq_enable(struct irq_data *d) | 90 | static void gpio_rcar_irq_enable(struct irq_data *d) |
91 | { | 91 | { |
92 | struct gpio_rcar_priv *p = irq_data_get_irq_chip_data(d); | 92 | struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
93 | struct gpio_rcar_priv *p = container_of(gc, struct gpio_rcar_priv, | ||
94 | gpio_chip); | ||
93 | 95 | ||
94 | gpio_rcar_write(p, MSKCLR, BIT(irqd_to_hwirq(d))); | 96 | gpio_rcar_write(p, MSKCLR, BIT(irqd_to_hwirq(d))); |
95 | } | 97 | } |
@@ -131,7 +133,9 @@ static void gpio_rcar_config_interrupt_input_mode(struct gpio_rcar_priv *p, | |||
131 | 133 | ||
132 | static int gpio_rcar_irq_set_type(struct irq_data *d, unsigned int type) | 134 | static int gpio_rcar_irq_set_type(struct irq_data *d, unsigned int type) |
133 | { | 135 | { |
134 | struct gpio_rcar_priv *p = irq_data_get_irq_chip_data(d); | 136 | struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
137 | struct gpio_rcar_priv *p = container_of(gc, struct gpio_rcar_priv, | ||
138 | gpio_chip); | ||
135 | unsigned int hwirq = irqd_to_hwirq(d); | 139 | unsigned int hwirq = irqd_to_hwirq(d); |
136 | 140 | ||
137 | dev_dbg(&p->pdev->dev, "sense irq = %d, type = %d\n", hwirq, type); | 141 | dev_dbg(&p->pdev->dev, "sense irq = %d, type = %d\n", hwirq, type); |
@@ -175,7 +179,8 @@ static irqreturn_t gpio_rcar_irq_handler(int irq, void *dev_id) | |||
175 | gpio_rcar_read(p, INTMSK))) { | 179 | gpio_rcar_read(p, INTMSK))) { |
176 | offset = __ffs(pending); | 180 | offset = __ffs(pending); |
177 | gpio_rcar_write(p, INTCLR, BIT(offset)); | 181 | gpio_rcar_write(p, INTCLR, BIT(offset)); |
178 | generic_handle_irq(irq_find_mapping(p->irq_domain, offset)); | 182 | generic_handle_irq(irq_find_mapping(p->gpio_chip.irqdomain, |
183 | offset)); | ||
179 | irqs_handled++; | 184 | irqs_handled++; |
180 | } | 185 | } |
181 | 186 | ||
@@ -265,29 +270,6 @@ static int gpio_rcar_direction_output(struct gpio_chip *chip, unsigned offset, | |||
265 | return 0; | 270 | return 0; |
266 | } | 271 | } |
267 | 272 | ||
268 | static int gpio_rcar_to_irq(struct gpio_chip *chip, unsigned offset) | ||
269 | { | ||
270 | return irq_create_mapping(gpio_to_priv(chip)->irq_domain, offset); | ||
271 | } | ||
272 | |||
273 | static int gpio_rcar_irq_domain_map(struct irq_domain *h, unsigned int irq, | ||
274 | irq_hw_number_t hwirq) | ||
275 | { | ||
276 | struct gpio_rcar_priv *p = h->host_data; | ||
277 | |||
278 | dev_dbg(&p->pdev->dev, "map hw irq = %d, irq = %d\n", (int)hwirq, irq); | ||
279 | |||
280 | irq_set_chip_data(irq, h->host_data); | ||
281 | irq_set_chip_and_handler(irq, &p->irq_chip, handle_level_irq); | ||
282 | set_irq_flags(irq, IRQF_VALID); /* kill me now */ | ||
283 | return 0; | ||
284 | } | ||
285 | |||
286 | static struct irq_domain_ops gpio_rcar_irq_domain_ops = { | ||
287 | .map = gpio_rcar_irq_domain_map, | ||
288 | .xlate = irq_domain_xlate_twocell, | ||
289 | }; | ||
290 | |||
291 | struct gpio_rcar_info { | 273 | struct gpio_rcar_info { |
292 | bool has_both_edge_trigger; | 274 | bool has_both_edge_trigger; |
293 | }; | 275 | }; |
@@ -372,10 +354,8 @@ static int gpio_rcar_probe(struct platform_device *pdev) | |||
372 | int ret; | 354 | int ret; |
373 | 355 | ||
374 | p = devm_kzalloc(dev, sizeof(*p), GFP_KERNEL); | 356 | p = devm_kzalloc(dev, sizeof(*p), GFP_KERNEL); |
375 | if (!p) { | 357 | if (!p) |
376 | ret = -ENOMEM; | 358 | return -ENOMEM; |
377 | goto err0; | ||
378 | } | ||
379 | 359 | ||
380 | p->pdev = pdev; | 360 | p->pdev = pdev; |
381 | spin_lock_init(&p->lock); | 361 | spin_lock_init(&p->lock); |
@@ -413,7 +393,6 @@ static int gpio_rcar_probe(struct platform_device *pdev) | |||
413 | gpio_chip->get = gpio_rcar_get; | 393 | gpio_chip->get = gpio_rcar_get; |
414 | gpio_chip->direction_output = gpio_rcar_direction_output; | 394 | gpio_chip->direction_output = gpio_rcar_direction_output; |
415 | gpio_chip->set = gpio_rcar_set; | 395 | gpio_chip->set = gpio_rcar_set; |
416 | gpio_chip->to_irq = gpio_rcar_to_irq; | ||
417 | gpio_chip->label = name; | 396 | gpio_chip->label = name; |
418 | gpio_chip->dev = dev; | 397 | gpio_chip->dev = dev; |
419 | gpio_chip->owner = THIS_MODULE; | 398 | gpio_chip->owner = THIS_MODULE; |
@@ -428,16 +407,19 @@ static int gpio_rcar_probe(struct platform_device *pdev) | |||
428 | irq_chip->flags = IRQCHIP_SKIP_SET_WAKE | IRQCHIP_SET_TYPE_MASKED | 407 | irq_chip->flags = IRQCHIP_SKIP_SET_WAKE | IRQCHIP_SET_TYPE_MASKED |
429 | | IRQCHIP_MASK_ON_SUSPEND; | 408 | | IRQCHIP_MASK_ON_SUSPEND; |
430 | 409 | ||
431 | p->irq_domain = irq_domain_add_simple(pdev->dev.of_node, | 410 | ret = gpiochip_add(gpio_chip); |
432 | p->config.number_of_pins, | 411 | if (ret) { |
433 | p->config.irq_base, | 412 | dev_err(dev, "failed to add GPIO controller\n"); |
434 | &gpio_rcar_irq_domain_ops, p); | ||
435 | if (!p->irq_domain) { | ||
436 | ret = -ENXIO; | ||
437 | dev_err(dev, "cannot initialize irq domain\n"); | ||
438 | goto err0; | 413 | goto err0; |
439 | } | 414 | } |
440 | 415 | ||
416 | ret = gpiochip_irqchip_add(&p->gpio_chip, irq_chip, p->config.irq_base, | ||
417 | handle_level_irq, IRQ_TYPE_NONE); | ||
418 | if (ret) { | ||
419 | dev_err(dev, "cannot add irqchip\n"); | ||
420 | goto err1; | ||
421 | } | ||
422 | |||
441 | if (devm_request_irq(dev, irq->start, gpio_rcar_irq_handler, | 423 | if (devm_request_irq(dev, irq->start, gpio_rcar_irq_handler, |
442 | IRQF_SHARED, name, p)) { | 424 | IRQF_SHARED, name, p)) { |
443 | dev_err(dev, "failed to request IRQ\n"); | 425 | dev_err(dev, "failed to request IRQ\n"); |
@@ -445,17 +427,11 @@ static int gpio_rcar_probe(struct platform_device *pdev) | |||
445 | goto err1; | 427 | goto err1; |
446 | } | 428 | } |
447 | 429 | ||
448 | ret = gpiochip_add(gpio_chip); | ||
449 | if (ret) { | ||
450 | dev_err(dev, "failed to add GPIO controller\n"); | ||
451 | goto err1; | ||
452 | } | ||
453 | |||
454 | dev_info(dev, "driving %d GPIOs\n", p->config.number_of_pins); | 430 | dev_info(dev, "driving %d GPIOs\n", p->config.number_of_pins); |
455 | 431 | ||
456 | /* warn in case of mismatch if irq base is specified */ | 432 | /* warn in case of mismatch if irq base is specified */ |
457 | if (p->config.irq_base) { | 433 | if (p->config.irq_base) { |
458 | ret = irq_find_mapping(p->irq_domain, 0); | 434 | ret = irq_find_mapping(p->gpio_chip.irqdomain, 0); |
459 | if (p->config.irq_base != ret) | 435 | if (p->config.irq_base != ret) |
460 | dev_warn(dev, "irq base mismatch (%u/%u)\n", | 436 | dev_warn(dev, "irq base mismatch (%u/%u)\n", |
461 | p->config.irq_base, ret); | 437 | p->config.irq_base, ret); |
@@ -471,7 +447,7 @@ static int gpio_rcar_probe(struct platform_device *pdev) | |||
471 | return 0; | 447 | return 0; |
472 | 448 | ||
473 | err1: | 449 | err1: |
474 | irq_domain_remove(p->irq_domain); | 450 | gpiochip_remove(&p->gpio_chip); |
475 | err0: | 451 | err0: |
476 | pm_runtime_put(dev); | 452 | pm_runtime_put(dev); |
477 | pm_runtime_disable(dev); | 453 | pm_runtime_disable(dev); |
@@ -484,7 +460,6 @@ static int gpio_rcar_remove(struct platform_device *pdev) | |||
484 | 460 | ||
485 | gpiochip_remove(&p->gpio_chip); | 461 | gpiochip_remove(&p->gpio_chip); |
486 | 462 | ||
487 | irq_domain_remove(p->irq_domain); | ||
488 | pm_runtime_put(&pdev->dev); | 463 | pm_runtime_put(&pdev->dev); |
489 | pm_runtime_disable(&pdev->dev); | 464 | pm_runtime_disable(&pdev->dev); |
490 | return 0; | 465 | return 0; |