* [PATCH 0/2] Improvement for pca953x drivers
@ 2013-01-25 16:59 Gregory CLEMENT
2013-01-25 16:59 ` [PATCH 1/2] gpio: pca953x: use simple irqdomain Gregory CLEMENT
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Gregory CLEMENT @ 2013-01-25 16:59 UTC (permalink / raw)
To: linux-arm-kernel
Hi Linus,
those two patches are the begining of the improvement work we have
spoken about earlier. I started with the two patches you sent.
I've just made a small fix to make it build on the 2nd patch so I keep
your autorship and signed-off.
For the second one, it didn't build too, but I made a more substantial
change on it by moving the setting of the irq to the map function. So
for this one, I took the authorship and remove your signed-off to not
make you responsible of my possible bug! :)
I've compiled and run it, but as I don't have support for the pca905
interrupt on my board, I can't say it didn't break anything. Maybe
this time again Maxime will be willing to test it.
For the remaining improvement related to the PWA and MMP #ifdef, I
hope to be able to work on it this week-end.
Regards
Gregory CLEMENT (1):
gpio: pca953x: use simple irqdomain
Linus Walleij (1):
gpio: pca953x: use managed resources
drivers/gpio/gpio-pca953x.c | 97 ++++++++++++++++---------------------------
1 file changed, 36 insertions(+), 61 deletions(-)
--
1.7.9.5
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/2] gpio: pca953x: use simple irqdomain
2013-01-25 16:59 [PATCH 0/2] Improvement for pca953x drivers Gregory CLEMENT
@ 2013-01-25 16:59 ` Gregory CLEMENT
2013-01-28 10:16 ` Linus Walleij
2013-01-25 16:59 ` [PATCH 2/2] gpio: pca953x: use managed resources Gregory CLEMENT
2013-01-28 10:14 ` [PATCH 0/2] Improvement for pca953x drivers Linus Walleij
2 siblings, 1 reply; 7+ messages in thread
From: Gregory CLEMENT @ 2013-01-25 16:59 UTC (permalink / raw)
To: linux-arm-kernel
This switches the legacy irqdomain to the simple one, which will
auto-allocate descriptors, and also make sure that we use
irq_create_mapping() in the to_irq function. Also use the map function
of irq_domain_ops to setup the irq configuration on demand and no more
statically during the initialization of the driver.
Based on a initial patch from Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Gregory CLEMENT <gregory.clement@free-electrons.com>
---
drivers/gpio/gpio-pca953x.c | 65 +++++++++++++++++++------------------------
1 file changed, 28 insertions(+), 37 deletions(-)
diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
index 3a68aed..1dc9906 100644
--- a/drivers/gpio/gpio-pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -89,7 +89,6 @@ struct pca953x_chip {
u8 irq_stat[MAX_BANK];
u8 irq_trig_raise[MAX_BANK];
u8 irq_trig_fall[MAX_BANK];
- int irq_base;
struct irq_domain *domain;
#endif
@@ -372,7 +371,7 @@ static int pca953x_gpio_to_irq(struct gpio_chip *gc, unsigned off)
struct pca953x_chip *chip;
chip = container_of(gc, struct pca953x_chip, gpio_chip);
- return chip->irq_base + off;
+ return irq_create_mapping(chip->domain, off);
}
static void pca953x_irq_mask(struct irq_data *d)
@@ -520,6 +519,27 @@ static irqreturn_t pca953x_irq_handler(int irq, void *devid)
return IRQ_HANDLED;
}
+static int pca953x_gpio_irq_map(struct irq_domain *d, unsigned int irq,
+ irq_hw_number_t hwirq)
+{
+ irq_clear_status_flags(irq, IRQ_NOREQUEST);
+ irq_set_chip_data(irq, d->host_data);
+ irq_set_chip(irq, &pca953x_irq_chip);
+ irq_set_nested_thread(irq, true);
+#ifdef CONFIG_ARM
+ set_irq_flags(irq, IRQF_VALID);
+#else
+ irq_set_noprobe(irq);
+#endif
+
+ return 0;
+}
+
+static const struct irq_domain_ops pca953x_irq_simple_ops = {
+ .map = pca953x_gpio_irq_map,
+ .xlate = irq_domain_xlate_twocell,
+};
+
static int pca953x_irq_setup(struct pca953x_chip *chip,
const struct i2c_device_id *id,
int irq_base)
@@ -529,7 +549,6 @@ static int pca953x_irq_setup(struct pca953x_chip *chip,
if (irq_base != -1
&& (id->driver_data & PCA_INT)) {
- int lvl;
switch (chip->chip_type) {
case PCA953X_TYPE:
@@ -552,34 +571,13 @@ static int pca953x_irq_setup(struct pca953x_chip *chip,
chip->irq_stat[i] &= chip->reg_direction[i];
mutex_init(&chip->irq_lock);
- chip->irq_base = irq_alloc_descs(-1, irq_base, chip->gpio_chip.ngpio, -1);
- if (chip->irq_base < 0)
- goto out_failed;
-
- chip->domain = irq_domain_add_legacy(client->dev.of_node,
+ chip->domain = irq_domain_add_simple(client->dev.of_node,
chip->gpio_chip.ngpio,
- chip->irq_base,
- 0,
- &irq_domain_simple_ops,
+ irq_base,
+ &pca953x_irq_simple_ops,
NULL);
- if (!chip->domain) {
- ret = -ENODEV;
- goto out_irqdesc_free;
- }
-
- for (lvl = 0; lvl < chip->gpio_chip.ngpio; lvl++) {
- int irq = lvl + chip->irq_base;
-
- irq_clear_status_flags(irq, IRQ_NOREQUEST);
- irq_set_chip_data(irq, chip);
- irq_set_chip(irq, &pca953x_irq_chip);
- irq_set_nested_thread(irq, true);
-#ifdef CONFIG_ARM
- set_irq_flags(irq, IRQF_VALID);
-#else
- irq_set_noprobe(irq);
-#endif
- }
+ if (!chip->domain)
+ return -ENODEV;
ret = request_threaded_irq(client->irq,
NULL,
@@ -589,25 +587,18 @@ static int pca953x_irq_setup(struct pca953x_chip *chip,
if (ret) {
dev_err(&client->dev, "failed to request irq %d\n",
client->irq);
- goto out_irqdesc_free;
+ return ret;
}
chip->gpio_chip.to_irq = pca953x_gpio_to_irq;
}
return 0;
-
-out_irqdesc_free:
- irq_free_descs(chip->irq_base, chip->gpio_chip.ngpio);
-out_failed:
- chip->irq_base = -1;
- return ret;
}
static void pca953x_irq_teardown(struct pca953x_chip *chip)
{
if (chip->irq_base != -1) {
- irq_free_descs(chip->irq_base, chip->gpio_chip.ngpio);
free_irq(chip->client->irq, chip);
}
}
--
1.7.9.5
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/2] gpio: pca953x: use managed resources
2013-01-25 16:59 [PATCH 0/2] Improvement for pca953x drivers Gregory CLEMENT
2013-01-25 16:59 ` [PATCH 1/2] gpio: pca953x: use simple irqdomain Gregory CLEMENT
@ 2013-01-25 16:59 ` Gregory CLEMENT
2013-01-28 10:17 ` Linus Walleij
2013-01-28 10:14 ` [PATCH 0/2] Improvement for pca953x drivers Linus Walleij
2 siblings, 1 reply; 7+ messages in thread
From: Gregory CLEMENT @ 2013-01-25 16:59 UTC (permalink / raw)
To: linux-arm-kernel
From: Linus Walleij <linus.walleij@linaro.org>
Using the devm_* managed resources the pca driver can be simplified
and cut down on boilerplate code.
[gcl: fixed a inccorect reference to a removed label, "goto fail_out"
became "return ret"]
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Gregory CLEMENT <gregory.clement@free-electrons.com>
---
drivers/gpio/gpio-pca953x.c | 32 ++++++++------------------------
1 file changed, 8 insertions(+), 24 deletions(-)
diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
index 1dc9906..2405946 100644
--- a/drivers/gpio/gpio-pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -560,7 +560,7 @@ static int pca953x_irq_setup(struct pca953x_chip *chip,
}
ret = pca953x_read_regs(chip, offset, chip->irq_stat);
if (ret)
- goto out_failed;
+ return ret;
/*
* There is no way to know which GPIO line generated the
@@ -579,7 +579,8 @@ static int pca953x_irq_setup(struct pca953x_chip *chip,
if (!chip->domain)
return -ENODEV;
- ret = request_threaded_irq(client->irq,
+ ret = devm_request_threaded_irq(&client->dev,
+ client->irq,
NULL,
pca953x_irq_handler,
IRQF_TRIGGER_LOW | IRQF_ONESHOT,
@@ -596,12 +597,6 @@ static int pca953x_irq_setup(struct pca953x_chip *chip,
return 0;
}
-static void pca953x_irq_teardown(struct pca953x_chip *chip)
-{
- if (chip->irq_base != -1) {
- free_irq(chip->client->irq, chip);
- }
-}
#else /* CONFIG_GPIO_PCA953X_IRQ */
static int pca953x_irq_setup(struct pca953x_chip *chip,
const struct i2c_device_id *id,
@@ -614,10 +609,6 @@ static int pca953x_irq_setup(struct pca953x_chip *chip,
return 0;
}
-
-static void pca953x_irq_teardown(struct pca953x_chip *chip)
-{
-}
#endif
/*
@@ -736,7 +727,8 @@ static int pca953x_probe(struct i2c_client *client,
int ret;
u32 invert = 0;
- chip = kzalloc(sizeof(struct pca953x_chip), GFP_KERNEL);
+ chip = devm_kzalloc(&client->dev,
+ sizeof(struct pca953x_chip), GFP_KERNEL);
if (chip == NULL)
return -ENOMEM;
@@ -771,15 +763,15 @@ static int pca953x_probe(struct i2c_client *client,
else
ret = device_pca957x_init(chip, invert);
if (ret)
- goto out_failed;
+ return ret;
ret = pca953x_irq_setup(chip, id, irq_base);
if (ret)
- goto out_failed;
+ return ret;
ret = gpiochip_add(&chip->gpio_chip);
if (ret)
- goto out_failed_irq;
+ return ret;
if (pdata && pdata->setup) {
ret = pdata->setup(client, chip->gpio_chip.base,
@@ -790,12 +782,6 @@ static int pca953x_probe(struct i2c_client *client,
i2c_set_clientdata(client, chip);
return 0;
-
-out_failed_irq:
- pca953x_irq_teardown(chip);
-out_failed:
- kfree(chip);
- return ret;
}
static int pca953x_remove(struct i2c_client *client)
@@ -821,8 +807,6 @@ static int pca953x_remove(struct i2c_client *client)
return ret;
}
- pca953x_irq_teardown(chip);
- kfree(chip);
return 0;
}
--
1.7.9.5
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 0/2] Improvement for pca953x drivers
2013-01-25 16:59 [PATCH 0/2] Improvement for pca953x drivers Gregory CLEMENT
2013-01-25 16:59 ` [PATCH 1/2] gpio: pca953x: use simple irqdomain Gregory CLEMENT
2013-01-25 16:59 ` [PATCH 2/2] gpio: pca953x: use managed resources Gregory CLEMENT
@ 2013-01-28 10:14 ` Linus Walleij
2 siblings, 0 replies; 7+ messages in thread
From: Linus Walleij @ 2013-01-28 10:14 UTC (permalink / raw)
To: linux-arm-kernel
On Fri, Jan 25, 2013 at 5:59 PM, Gregory CLEMENT
<gregory.clement@free-electrons.com> wrote:
> those two patches are the begining of the improvement work we have
> spoken about earlier. I started with the two patches you sent.
Thanks for doing this!! :-)
> I've just made a small fix to make it build on the 2nd patch so I keep
> your autorship and signed-off.
OK I don't care about authorship & such stuff, the important thing
to me is that the code works and looks nice and maintainable.
> I've compiled and run it, but as I don't have support for the pca905
> interrupt on my board, I can't say it didn't break anything. Maybe
> this time again Maxime will be willing to test it.
I will apply the patches and then Maxime can shout if it breaks :-)
> For the remaining improvement related to the PWA and MMP #ifdef, I
> hope to be able to work on it this week-end.
Excellent, thanks!
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/2] gpio: pca953x: use simple irqdomain
2013-01-25 16:59 ` [PATCH 1/2] gpio: pca953x: use simple irqdomain Gregory CLEMENT
@ 2013-01-28 10:16 ` Linus Walleij
0 siblings, 0 replies; 7+ messages in thread
From: Linus Walleij @ 2013-01-28 10:16 UTC (permalink / raw)
To: linux-arm-kernel
On Fri, Jan 25, 2013 at 5:59 PM, Gregory CLEMENT
<gregory.clement@free-electrons.com> wrote:
> This switches the legacy irqdomain to the simple one, which will
> auto-allocate descriptors, and also make sure that we use
> irq_create_mapping() in the to_irq function. Also use the map function
> of irq_domain_ops to setup the irq configuration on demand and no more
> statically during the initialization of the driver.
>
> Based on a initial patch from Linus Walleij <linus.walleij@linaro.org>
>
> Signed-off-by: Gregory CLEMENT <gregory.clement@free-electrons.com>
Patch applied!
Thanks,
Linus Walleij
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/2] gpio: pca953x: use managed resources
2013-01-25 16:59 ` [PATCH 2/2] gpio: pca953x: use managed resources Gregory CLEMENT
@ 2013-01-28 10:17 ` Linus Walleij
2013-01-28 15:04 ` Russell King - ARM Linux
0 siblings, 1 reply; 7+ messages in thread
From: Linus Walleij @ 2013-01-28 10:17 UTC (permalink / raw)
To: linux-arm-kernel
On Fri, Jan 25, 2013 at 5:59 PM, Gregory CLEMENT
<gregory.clement@free-electrons.com> wrote:
> From: Linus Walleij <linus.walleij@linaro.org>
>
> Using the devm_* managed resources the pca driver can be simplified
> and cut down on boilerplate code.
>
> [gcl: fixed a inccorect reference to a removed label, "goto fail_out"
> became "return ret"]
Oh now "gcl" means both Grant C. Likely and Gregory CLement :-)
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> Signed-off-by: Gregory CLEMENT <gregory.clement@free-electrons.com>
Patch applied, thanks!
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/2] gpio: pca953x: use managed resources
2013-01-28 10:17 ` Linus Walleij
@ 2013-01-28 15:04 ` Russell King - ARM Linux
0 siblings, 0 replies; 7+ messages in thread
From: Russell King - ARM Linux @ 2013-01-28 15:04 UTC (permalink / raw)
To: linux-arm-kernel
On Mon, Jan 28, 2013 at 11:17:48AM +0100, Linus Walleij wrote:
> On Fri, Jan 25, 2013 at 5:59 PM, Gregory CLEMENT
> <gregory.clement@free-electrons.com> wrote:
>
> > From: Linus Walleij <linus.walleij@linaro.org>
> >
> > Using the devm_* managed resources the pca driver can be simplified
> > and cut down on boilerplate code.
> >
> > [gcl: fixed a inccorect reference to a removed label, "goto fail_out"
> > became "return ret"]
>
> Oh now "gcl" means both Grant C. Likely and Gregory CLement :-)
I'd say gcl means Grant C. Likely. gc would be Gregory Clement.
Initials. :) Using anything else results in yet more many namespace
clashes.
Maybe we should switch to a numeric namespace instead? :)
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2013-01-28 15:04 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-25 16:59 [PATCH 0/2] Improvement for pca953x drivers Gregory CLEMENT
2013-01-25 16:59 ` [PATCH 1/2] gpio: pca953x: use simple irqdomain Gregory CLEMENT
2013-01-28 10:16 ` Linus Walleij
2013-01-25 16:59 ` [PATCH 2/2] gpio: pca953x: use managed resources Gregory CLEMENT
2013-01-28 10:17 ` Linus Walleij
2013-01-28 15:04 ` Russell King - ARM Linux
2013-01-28 10:14 ` [PATCH 0/2] Improvement for pca953x drivers Linus Walleij
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).