All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mfd/stmpe: Add support for irq over gpio pin
@ 2011-11-03  9:26 Viresh Kumar
  2011-11-07 12:29 ` Linus Walleij
  2011-11-08  8:36 ` Linus Walleij
  0 siblings, 2 replies; 4+ messages in thread
From: Viresh Kumar @ 2011-11-03  9:26 UTC (permalink / raw)
  To: rabin.vincent, linux-kernel, sameo
  Cc: armando.visconti, shiraz.hashim, vipin.kumar, rajeev-dlh.kumar,
	deepak.sikri, vipulkumar.samar, amit.virdi, viresh.kumar,
	pratyush.anand, bhupesh.sharma, viresh.linux, bhavna.yadav,
	vincenzo.frascino, mirko.gardi, srinidhi.kasagar, linus.walleij

On many boards, stmpe is present as an separate device (not as part of SoC).
Here gpio lines are mostly used for getting interrupts. This patch adds in
support to handle irq over gpio pin.

Signed-off-by: Viresh Kumar <viresh.kumar@st.com>
---
 drivers/mfd/stmpe.c       |   35 ++++++++++++++++++++++++++++-------
 include/linux/mfd/stmpe.h |    3 +++
 2 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/drivers/mfd/stmpe.c b/drivers/mfd/stmpe.c
index 2963689..239e46f 100644
--- a/drivers/mfd/stmpe.c
+++ b/drivers/mfd/stmpe.c
@@ -5,6 +5,7 @@
  * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
  */
 
+#include <linux/gpio.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/interrupt.h>
@@ -877,9 +878,10 @@ static int __devinit stmpe_devices_init(struct stmpe *stmpe)
 static int stmpe_suspend(struct device *dev)
 {
 	struct i2c_client *i2c = to_i2c_client(dev);
+	struct stmpe *stmpe = i2c_get_clientdata(i2c);
 
 	if (device_may_wakeup(&i2c->dev))
-		enable_irq_wake(i2c->irq);
+		enable_irq_wake(stmpe->irq);
 
 	return 0;
 }
@@ -887,9 +889,10 @@ static int stmpe_suspend(struct device *dev)
 static int stmpe_resume(struct device *dev)
 {
 	struct i2c_client *i2c = to_i2c_client(dev);
+	struct stmpe *stmpe = i2c_get_clientdata(i2c);
 
 	if (device_may_wakeup(&i2c->dev))
-		disable_irq_wake(i2c->irq);
+		disable_irq_wake(stmpe->irq);
 
 	return 0;
 }
@@ -925,15 +928,28 @@ static int __devinit stmpe_probe(struct i2c_client *i2c,
 
 	i2c_set_clientdata(i2c, stmpe);
 
+	if (pdata->irq_over_gpio) {
+		ret = gpio_request_one(pdata->irq_gpio, GPIOF_DIR_IN, "stmpe");
+		if (ret) {
+			dev_err(stmpe->dev, "failed to request IRQ GPIO: %d\n",
+					ret);
+			goto out_free;
+		}
+
+		stmpe->irq = gpio_to_irq(pdata->irq_gpio);
+	} else {
+		stmpe->irq = i2c->irq;
+	}
+
 	ret = stmpe_chip_init(stmpe);
 	if (ret)
-		goto out_free;
+		goto free_gpio;
 
 	ret = stmpe_irq_init(stmpe);
 	if (ret)
-		goto out_free;
+		goto free_gpio;
 
-	ret = request_threaded_irq(stmpe->i2c->irq, NULL, stmpe_irq,
+	ret = request_threaded_irq(stmpe->irq, NULL, stmpe_irq,
 				   pdata->irq_trigger | IRQF_ONESHOT,
 				   "stmpe", stmpe);
 	if (ret) {
@@ -951,9 +967,11 @@ static int __devinit stmpe_probe(struct i2c_client *i2c,
 
 out_removedevs:
 	mfd_remove_devices(stmpe->dev);
-	free_irq(stmpe->i2c->irq, stmpe);
+	free_irq(stmpe->irq, stmpe);
 out_removeirq:
 	stmpe_irq_remove(stmpe);
+free_gpio:
+	gpio_free(pdata->irq_gpio);
 out_free:
 	kfree(stmpe);
 	return ret;
@@ -965,9 +983,12 @@ static int __devexit stmpe_remove(struct i2c_client *client)
 
 	mfd_remove_devices(stmpe->dev);
 
-	free_irq(stmpe->i2c->irq, stmpe);
+	free_irq(stmpe->irq, stmpe);
 	stmpe_irq_remove(stmpe);
 
+	if (stmpe->pdata->irq_over_gpio)
+		gpio_free(stmpe->pdata->irq_gpio);
+
 	kfree(stmpe);
 
 	return 0;
diff --git a/include/linux/mfd/stmpe.h b/include/linux/mfd/stmpe.h
index be1af7c..7901351 100644
--- a/include/linux/mfd/stmpe.h
+++ b/include/linux/mfd/stmpe.h
@@ -76,6 +76,7 @@ struct stmpe {
 	struct stmpe_variant_info *variant;
 	const u8 *regs;
 
+	int irq;
 	int irq_base;
 	int num_gpios;
 	u8 ier[2];
@@ -194,6 +195,8 @@ struct stmpe_platform_data {
 	unsigned int irq_trigger;
 	bool irq_invert_polarity;
 	bool autosleep;
+	bool irq_over_gpio;
+	int irq_gpio;
 	int autosleep_timeout;
 
 	struct stmpe_gpio_platform_data *gpio;
-- 
1.7.2.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] mfd/stmpe: Add support for irq over gpio pin
  2011-11-03  9:26 [PATCH] mfd/stmpe: Add support for irq over gpio pin Viresh Kumar
@ 2011-11-07 12:29 ` Linus Walleij
  2011-11-08  3:48   ` Viresh Kumar
  2011-11-08  8:36 ` Linus Walleij
  1 sibling, 1 reply; 4+ messages in thread
From: Linus Walleij @ 2011-11-07 12:29 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: rabin.vincent, linux-kernel, sameo, armando.visconti,
	shiraz.hashim, vipin.kumar, rajeev-dlh.kumar, deepak.sikri,
	vipulkumar.samar, amit.virdi, pratyush.anand, bhupesh.sharma,
	viresh.linux, bhavna.yadav, vincenzo.frascino, mirko.gardi,
	srinidhi.kasagar, linus.walleij

Hi Viresh,

On Thu, Nov 3, 2011 at 10:26 AM, Viresh Kumar <viresh.kumar@st.com> wrote:

> @@ -925,15 +928,28 @@ static int __devinit stmpe_probe(struct i2c_client *i2c,
>
>        i2c_set_clientdata(i2c, stmpe);
>
> +       if (pdata->irq_over_gpio) {
> +               ret = gpio_request_one(pdata->irq_gpio, GPIOF_DIR_IN, "stmpe");
> +               if (ret) {
> +                       dev_err(stmpe->dev, "failed to request IRQ GPIO: %d\n",
> +                                       ret);
> +                       goto out_free;
> +               }
> +
> +               stmpe->irq = gpio_to_irq(pdata->irq_gpio);
> +       } else {
> +               stmpe->irq = i2c->irq;
> +       }
> +
>        ret = stmpe_chip_init(stmpe);
>        if (ret)
> -               goto out_free;
> +               goto free_gpio;
>
>        ret = stmpe_irq_init(stmpe);
>        if (ret)
> -               goto out_free;
> +               goto free_gpio;
>
> -       ret = request_threaded_irq(stmpe->i2c->irq, NULL, stmpe_irq,
> +       ret = request_threaded_irq(stmpe->irq, NULL, stmpe_irq,
>                                   pdata->irq_trigger | IRQF_ONESHOT,
>                                   "stmpe", stmpe);
>        if (ret) {
> @@ -951,9 +967,11 @@ static int __devinit stmpe_probe(struct i2c_client *i2c,
>
>  out_removedevs:
>        mfd_remove_devices(stmpe->dev);
> -       free_irq(stmpe->i2c->irq, stmpe);
> +       free_irq(stmpe->irq, stmpe);
>  out_removeirq:
>        stmpe_irq_remove(stmpe);
> +free_gpio:
> +       gpio_free(pdata->irq_gpio);

Will that work if you didn't request irq over GPIO?

If you did not request GPIO and stmpe_chip_init()
fails this will still be executed.

Maybe:

if (pdata->irq_over_gpio)
   gpio_free(pdata->irq_gpio);

>  out_free:
>        kfree(stmpe);
>        return ret;
> @@ -965,9 +983,12 @@ static int __devexit stmpe_remove(struct i2c_client *client)
>
>        mfd_remove_devices(stmpe->dev);
>
> -       free_irq(stmpe->i2c->irq, stmpe);
> +       free_irq(stmpe->irq, stmpe);
>        stmpe_irq_remove(stmpe);
>
> +       if (stmpe->pdata->irq_over_gpio)
> +               gpio_free(stmpe->pdata->irq_gpio);
> +

Here it seems correct.

> diff --git a/include/linux/mfd/stmpe.h b/include/linux/mfd/stmpe.h
> index be1af7c..7901351 100644
> --- a/include/linux/mfd/stmpe.h
> +++ b/include/linux/mfd/stmpe.h
> @@ -76,6 +76,7 @@ struct stmpe {
>        struct stmpe_variant_info *variant;
>        const u8 *regs;
>
> +       int irq;
>        int irq_base;
>        int num_gpios;
>        u8 ier[2];
> @@ -194,6 +195,8 @@ struct stmpe_platform_data {
>        unsigned int irq_trigger;
>        bool irq_invert_polarity;
>        bool autosleep;
> +       bool irq_over_gpio;
> +       int irq_gpio;
>        int autosleep_timeout;

Please also update the kerneldoc for struct stmpe.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mfd/stmpe: Add support for irq over gpio pin
  2011-11-07 12:29 ` Linus Walleij
@ 2011-11-08  3:48   ` Viresh Kumar
  0 siblings, 0 replies; 4+ messages in thread
From: Viresh Kumar @ 2011-11-08  3:48 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Rabin VINCENT, linux-kernel@vger.kernel.org,
	sameo@linux.intel.com, Armando VISCONTI, Shiraz HASHIM,
	Vipin KUMAR, Rajeev KUMAR, Deepak SIKRI, Vipul Kumar SAMAR,
	Amit VIRDI, Pratyush ANAND, Bhupesh SHARMA,
	viresh.linux@gmail.com, Bhavna YADAV, Vincenzo FRASCINO,
	Mirko GARDI, Srinidhi KASAGAR, Linus WALLEIJ

On 11/7/2011 5:59 PM, Linus Walleij wrote:
> On Thu, Nov 3, 2011 at 10:26 AM, Viresh Kumar <viresh.kumar@st.com> wrote:

>> +free_gpio:
>> +       gpio_free(pdata->irq_gpio);
> 
> Will that work if you didn't request irq over GPIO?
> 
> If you did not request GPIO and stmpe_chip_init()
> fails this will still be executed.
> 
> Maybe:
> 
> if (pdata->irq_over_gpio)
>    gpio_free(pdata->irq_gpio);
> 

:(
Silly mistake.

>> diff --git a/include/linux/mfd/stmpe.h b/include/linux/mfd/stmpe.h
>> index be1af7c..7901351 100644
>> --- a/include/linux/mfd/stmpe.h
>> +++ b/include/linux/mfd/stmpe.h
>> @@ -76,6 +76,7 @@ struct stmpe {
>>        struct stmpe_variant_info *variant;
>>        const u8 *regs;
>>
>> +       int irq;
>>        int irq_base;
>>        int num_gpios;
>>        u8 ier[2];
>> @@ -194,6 +195,8 @@ struct stmpe_platform_data {
>>        unsigned int irq_trigger;
>>        bool irq_invert_polarity;
>>        bool autosleep;
>> +       bool irq_over_gpio;
>> +       int irq_gpio;
>>        int autosleep_timeout;
> 
> Please also update the kerneldoc for struct stmpe.

Sure.

-- 
viresh

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mfd/stmpe: Add support for irq over gpio pin
  2011-11-03  9:26 [PATCH] mfd/stmpe: Add support for irq over gpio pin Viresh Kumar
  2011-11-07 12:29 ` Linus Walleij
@ 2011-11-08  8:36 ` Linus Walleij
  1 sibling, 0 replies; 4+ messages in thread
From: Linus Walleij @ 2011-11-08  8:36 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: rabin.vincent, linux-kernel, sameo, armando.visconti,
	shiraz.hashim, vipin.kumar, rajeev-dlh.kumar, deepak.sikri,
	vipulkumar.samar, amit.virdi, pratyush.anand, bhupesh.sharma,
	viresh.linux, bhavna.yadav, vincenzo.frascino, mirko.gardi,
	srinidhi.kasagar, linus.walleij

On Thu, Nov 3, 2011 at 10:26 AM, Viresh Kumar <viresh.kumar@st.com> wrote:

> On many boards, stmpe is present as an separate device (not as part of SoC).
> Here gpio lines are mostly used for getting interrupts. This patch adds in
> support to handle irq over gpio pin.
>
> Signed-off-by: Viresh Kumar <viresh.kumar@st.com>

OK looks good now!
Acked-by: Linus Walleij <linus.walleij@linaro.org>

Thanks,
Linus Walleij

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-11-08  8:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-03  9:26 [PATCH] mfd/stmpe: Add support for irq over gpio pin Viresh Kumar
2011-11-07 12:29 ` Linus Walleij
2011-11-08  3:48   ` Viresh Kumar
2011-11-08  8:36 ` Linus Walleij

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.