linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC][PATCH] GPIO keys
@ 2010-07-27 14:41 Datta, Shubhrajyoti
  2010-07-27 17:00 ` Dmitry Torokhov
  0 siblings, 1 reply; 7+ messages in thread
From: Datta, Shubhrajyoti @ 2010-07-27 14:41 UTC (permalink / raw)
  To: linux-input@vger.kernel.org


Allowing the call of open and close functions.
If the gpio-keys device has some initialization
to be done allow the call of platform functions.
An example would be to enable the device.

Signed-off-by: Shubhrajyoti D <shubhrajyoti@ti.com>
---
 drivers/input/keyboard/gpio_keys.c |   23 +++++++++++++++++++++++
 include/linux/gpio_keys.h          |    1 +
 2 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
index b8213fd..f459f38 100644
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -38,6 +38,7 @@ struct gpio_keys_drvdata {
 	struct input_dev *input;
 	struct mutex disable_lock;
 	unsigned int n_buttons;
+	void (*enable)(int state);
 	struct gpio_button_data data[0];
 };
 
@@ -414,6 +415,24 @@ fail2:
 	return error;
 }
 
+static int gpio_keys_open(struct input_dev *dev)
+{
+	struct gpio_keys_drvdata *ddata;
+	ddata = input_get_drvdata(dev);
+	if (ddata->enable)
+		ddata->enable(1);
+	return 0;
+}
+
+static void gpio_keys_close(struct input_dev *dev)
+{
+	struct gpio_keys_drvdata *ddata;
+
+	ddata = input_get_drvdata(dev);
+	if (ddata->enable)
+		ddata->enable(0);
+}
+
 static int __devinit gpio_keys_probe(struct platform_device *pdev)
 {
 	struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
@@ -435,13 +454,17 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
 
 	ddata->input = input;
 	ddata->n_buttons = pdata->nbuttons;
+	ddata->enable =  pdata->enable;
 	mutex_init(&ddata->disable_lock);
 
 	platform_set_drvdata(pdev, ddata);
+	input_set_drvdata(input , ddata);
 
 	input->name = pdev->name;
 	input->phys = "gpio-keys/input0";
 	input->dev.parent = &pdev->dev;
+	input->open = gpio_keys_open;
+	input->close = gpio_keys_close;
 
 	input->id.bustype = BUS_HOST;
 	input->id.vendor = 0x0001;
diff --git a/include/linux/gpio_keys.h b/include/linux/gpio_keys.h
index cd0b3f3..5645996 100644
--- a/include/linux/gpio_keys.h
+++ b/include/linux/gpio_keys.h
@@ -17,6 +17,7 @@ struct gpio_keys_platform_data {
 	struct gpio_keys_button *buttons;
 	int nbuttons;
 	unsigned int rep:1;		/* enable input subsystem auto repeat */
+	void (*enable)(int state);
 };
 
 #endif
-- 
1.5.4.7


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

* Re: [RFC][PATCH] GPIO keys
  2010-07-27 14:41 [RFC][PATCH] GPIO keys Datta, Shubhrajyoti
@ 2010-07-27 17:00 ` Dmitry Torokhov
  2010-07-27 17:44   ` Datta, Shubhrajyoti
  0 siblings, 1 reply; 7+ messages in thread
From: Dmitry Torokhov @ 2010-07-27 17:00 UTC (permalink / raw)
  To: Datta, Shubhrajyoti; +Cc: linux-input@vger.kernel.org

Hi Shubhrajyoti,

On Tue, Jul 27, 2010 at 08:11:31PM +0530, Datta, Shubhrajyoti wrote:
> 
> Allowing the call of open and close functions.
> If the gpio-keys device has some initialization
> to be done allow the call of platform functions.
> An example would be to enable the device.
> 

Makes sense, although I'd prefer 2 separate methods. Also, make sure you
run you patch through scripts/checkpatch.pl - I see a coupe of small
formatting issues (note that I do not care strongly about 80 column
limit).

Thanks.

> Signed-off-by: Shubhrajyoti D <shubhrajyoti@ti.com>
> ---
>  drivers/input/keyboard/gpio_keys.c |   23 +++++++++++++++++++++++
>  include/linux/gpio_keys.h          |    1 +
>  2 files changed, 24 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
> index b8213fd..f459f38 100644
> --- a/drivers/input/keyboard/gpio_keys.c
> +++ b/drivers/input/keyboard/gpio_keys.c
> @@ -38,6 +38,7 @@ struct gpio_keys_drvdata {
>  	struct input_dev *input;
>  	struct mutex disable_lock;
>  	unsigned int n_buttons;
> +	void (*enable)(int state);
>  	struct gpio_button_data data[0];
>  };
>  
> @@ -414,6 +415,24 @@ fail2:
>  	return error;
>  }
>  
> +static int gpio_keys_open(struct input_dev *dev)
> +{
> +	struct gpio_keys_drvdata *ddata;
> +	ddata = input_get_drvdata(dev);
> +	if (ddata->enable)
> +		ddata->enable(1);
> +	return 0;
> +}
> +
> +static void gpio_keys_close(struct input_dev *dev)
> +{
> +	struct gpio_keys_drvdata *ddata;
> +
> +	ddata = input_get_drvdata(dev);
> +	if (ddata->enable)
> +		ddata->enable(0);
> +}
> +
>  static int __devinit gpio_keys_probe(struct platform_device *pdev)
>  {
>  	struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
> @@ -435,13 +454,17 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
>  
>  	ddata->input = input;
>  	ddata->n_buttons = pdata->nbuttons;
> +	ddata->enable =  pdata->enable;
>  	mutex_init(&ddata->disable_lock);
>  
>  	platform_set_drvdata(pdev, ddata);
> +	input_set_drvdata(input , ddata);
>  
>  	input->name = pdev->name;
>  	input->phys = "gpio-keys/input0";
>  	input->dev.parent = &pdev->dev;
> +	input->open = gpio_keys_open;
> +	input->close = gpio_keys_close;
>  
>  	input->id.bustype = BUS_HOST;
>  	input->id.vendor = 0x0001;
> diff --git a/include/linux/gpio_keys.h b/include/linux/gpio_keys.h
> index cd0b3f3..5645996 100644
> --- a/include/linux/gpio_keys.h
> +++ b/include/linux/gpio_keys.h
> @@ -17,6 +17,7 @@ struct gpio_keys_platform_data {
>  	struct gpio_keys_button *buttons;
>  	int nbuttons;
>  	unsigned int rep:1;		/* enable input subsystem auto repeat */
> +	void (*enable)(int state);
>  };
>  
>  #endif
> -- 
> 1.5.4.7
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-input" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

-- 
Dmitry

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

* RE: [RFC][PATCH] GPIO keys
  2010-07-27 17:00 ` Dmitry Torokhov
@ 2010-07-27 17:44   ` Datta, Shubhrajyoti
  2010-07-27 18:01     ` Datta, Shubhrajyoti
  0 siblings, 1 reply; 7+ messages in thread
From: Datta, Shubhrajyoti @ 2010-07-27 17:44 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: linux-input@vger.kernel.org

Hi Dmitry,

> -----Original Message-----
> From: Dmitry Torokhov [mailto:dmitry.torokhov@gmail.com]
> Sent: Tuesday, July 27, 2010 10:31 PM
> To: Datta, Shubhrajyoti
> Cc: linux-input@vger.kernel.org
> Subject: Re: [RFC][PATCH] GPIO keys
> 
> Hi Shubhrajyoti,
> 
> On Tue, Jul 27, 2010 at 08:11:31PM +0530, Datta, Shubhrajyoti wrote:
> >
> > Allowing the call of open and close functions.
> > If the gpio-keys device has some initialization
> > to be done allow the call of platform functions.
> > An example would be to enable the device.
> >
> 
> Makes sense, although I'd prefer 2 separate methods. Also, make sure you
> run you patch through scripts/checkpatch.pl - I see a coupe of small
> formatting issues (note that I do not care strongly about 80 column
> limit).
> 
I did run checkpatch maybe you may be I corrupted something while sending.
Will check.

I chose this approach as at later point maybe some driver may use it for custom suspend and resume etc. However will send another patch if you so prefer.
> Thanks.
> 
> > Signed-off-by: Shubhrajyoti D <shubhrajyoti@ti.com>
> > ---
> >  drivers/input/keyboard/gpio_keys.c |   23 +++++++++++++++++++++++
> >  include/linux/gpio_keys.h          |    1 +
> >  2 files changed, 24 insertions(+), 0 deletions(-)
> >
> > diff --git a/drivers/input/keyboard/gpio_keys.c
> b/drivers/input/keyboard/gpio_keys.c
> > index b8213fd..f459f38 100644
> > --- a/drivers/input/keyboard/gpio_keys.c
> > +++ b/drivers/input/keyboard/gpio_keys.c
> > @@ -38,6 +38,7 @@ struct gpio_keys_drvdata {
> >  	struct input_dev *input;
> >  	struct mutex disable_lock;
> >  	unsigned int n_buttons;
> > +	void (*enable)(int state);
> >  	struct gpio_button_data data[0];
> >  };
> >
> > @@ -414,6 +415,24 @@ fail2:
> >  	return error;
> >  }
> >
> > +static int gpio_keys_open(struct input_dev *dev)
> > +{
> > +	struct gpio_keys_drvdata *ddata;
> > +	ddata = input_get_drvdata(dev);
> > +	if (ddata->enable)
> > +		ddata->enable(1);
> > +	return 0;
> > +}
> > +
> > +static void gpio_keys_close(struct input_dev *dev)
> > +{
> > +	struct gpio_keys_drvdata *ddata;
> > +
> > +	ddata = input_get_drvdata(dev);
> > +	if (ddata->enable)
> > +		ddata->enable(0);
> > +}
> > +
> >  static int __devinit gpio_keys_probe(struct platform_device *pdev)
> >  {
> >  	struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
> > @@ -435,13 +454,17 @@ static int __devinit gpio_keys_probe(struct
> platform_device *pdev)
> >
> >  	ddata->input = input;
> >  	ddata->n_buttons = pdata->nbuttons;
> > +	ddata->enable =  pdata->enable;
> >  	mutex_init(&ddata->disable_lock);
> >
> >  	platform_set_drvdata(pdev, ddata);
> > +	input_set_drvdata(input , ddata);
> >
> >  	input->name = pdev->name;
> >  	input->phys = "gpio-keys/input0";
> >  	input->dev.parent = &pdev->dev;
> > +	input->open = gpio_keys_open;
> > +	input->close = gpio_keys_close;
> >
> >  	input->id.bustype = BUS_HOST;
> >  	input->id.vendor = 0x0001;
> > diff --git a/include/linux/gpio_keys.h b/include/linux/gpio_keys.h
> > index cd0b3f3..5645996 100644
> > --- a/include/linux/gpio_keys.h
> > +++ b/include/linux/gpio_keys.h
> > @@ -17,6 +17,7 @@ struct gpio_keys_platform_data {
> >  	struct gpio_keys_button *buttons;
> >  	int nbuttons;
> >  	unsigned int rep:1;		/* enable input subsystem auto repeat
> */
> > +	void (*enable)(int state);
> >  };
> >
> >  #endif
> > --
> > 1.5.4.7
> >
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-input"
> in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
> --
> Dmitry

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

* RE: [RFC][PATCH] GPIO keys
  2010-07-27 17:44   ` Datta, Shubhrajyoti
@ 2010-07-27 18:01     ` Datta, Shubhrajyoti
  0 siblings, 0 replies; 7+ messages in thread
From: Datta, Shubhrajyoti @ 2010-07-27 18:01 UTC (permalink / raw)
  To: Datta, Shubhrajyoti, Dmitry Torokhov; +Cc: linux-input@vger.kernel.org



> -----Original Message-----
> From: linux-input-owner@vger.kernel.org [mailto:linux-input-
> owner@vger.kernel.org] On Behalf Of Datta, Shubhrajyoti
> Sent: Tuesday, July 27, 2010 11:15 PM
> To: Dmitry Torokhov
> Cc: linux-input@vger.kernel.org
> Subject: RE: [RFC][PATCH] GPIO keys
> 
> Hi Dmitry,
> 
> > -----Original Message-----
> > From: Dmitry Torokhov [mailto:dmitry.torokhov@gmail.com]
> > Sent: Tuesday, July 27, 2010 10:31 PM
> > To: Datta, Shubhrajyoti
> > Cc: linux-input@vger.kernel.org
> > Subject: Re: [RFC][PATCH] GPIO keys
> >
> > Hi Shubhrajyoti,
> >
> > On Tue, Jul 27, 2010 at 08:11:31PM +0530, Datta, Shubhrajyoti wrote:
> > >
> > > Allowing the call of open and close functions.
> > > If the gpio-keys device has some initialization
> > > to be done allow the call of platform functions.
> > > An example would be to enable the device.
> > >
> >
> > Makes sense, although I'd prefer 2 separate methods. Also, make sure you
> > run you patch through scripts/checkpatch.pl - I see a coupe of small
> > formatting issues (note that I do not care strongly about 80 column
> > limit).
> >
> I did run checkpatch maybe you may be I corrupted something while sending.
> Will check.
> 
may be I corrupted something while sending. 
-Correcting the typo 
> I chose this approach as at later point maybe some driver may use it for
> custom suspend and resume etc. However will send another patch if you so
> prefer.
> > Thanks.
> >
> > > Signed-off-by: Shubhrajyoti D <shubhrajyoti@ti.com>
> > > ---
> > >  drivers/input/keyboard/gpio_keys.c |   23 +++++++++++++++++++++++
> > >  include/linux/gpio_keys.h          |    1 +
> > >  2 files changed, 24 insertions(+), 0 deletions(-)
> > >
> > > diff --git a/drivers/input/keyboard/gpio_keys.c
> > b/drivers/input/keyboard/gpio_keys.c
> > > index b8213fd..f459f38 100644
> > > --- a/drivers/input/keyboard/gpio_keys.c
> > > +++ b/drivers/input/keyboard/gpio_keys.c
> > > @@ -38,6 +38,7 @@ struct gpio_keys_drvdata {
> > >  	struct input_dev *input;
> > >  	struct mutex disable_lock;
> > >  	unsigned int n_buttons;
> > > +	void (*enable)(int state);
> > >  	struct gpio_button_data data[0];
> > >  };
> > >
> > > @@ -414,6 +415,24 @@ fail2:
> > >  	return error;
> > >  }
> > >
> > > +static int gpio_keys_open(struct input_dev *dev)
> > > +{
> > > +	struct gpio_keys_drvdata *ddata;
> > > +	ddata = input_get_drvdata(dev);
> > > +	if (ddata->enable)
> > > +		ddata->enable(1);
> > > +	return 0;
> > > +}
> > > +
> > > +static void gpio_keys_close(struct input_dev *dev)
> > > +{
> > > +	struct gpio_keys_drvdata *ddata;
> > > +
> > > +	ddata = input_get_drvdata(dev);
> > > +	if (ddata->enable)
> > > +		ddata->enable(0);
> > > +}
> > > +
> > >  static int __devinit gpio_keys_probe(struct platform_device *pdev)
> > >  {
> > >  	struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
> > > @@ -435,13 +454,17 @@ static int __devinit gpio_keys_probe(struct
> > platform_device *pdev)
> > >
> > >  	ddata->input = input;
> > >  	ddata->n_buttons = pdata->nbuttons;
> > > +	ddata->enable =  pdata->enable;
> > >  	mutex_init(&ddata->disable_lock);
> > >
> > >  	platform_set_drvdata(pdev, ddata);
> > > +	input_set_drvdata(input , ddata);
> > >
> > >  	input->name = pdev->name;
> > >  	input->phys = "gpio-keys/input0";
> > >  	input->dev.parent = &pdev->dev;
> > > +	input->open = gpio_keys_open;
> > > +	input->close = gpio_keys_close;
> > >
> > >  	input->id.bustype = BUS_HOST;
> > >  	input->id.vendor = 0x0001;
> > > diff --git a/include/linux/gpio_keys.h b/include/linux/gpio_keys.h
> > > index cd0b3f3..5645996 100644
> > > --- a/include/linux/gpio_keys.h
> > > +++ b/include/linux/gpio_keys.h
> > > @@ -17,6 +17,7 @@ struct gpio_keys_platform_data {
> > >  	struct gpio_keys_button *buttons;
> > >  	int nbuttons;
> > >  	unsigned int rep:1;		/* enable input subsystem auto repeat
> > */
> > > +	void (*enable)(int state);
> > >  };
> > >
> > >  #endif
> > > --
> > > 1.5.4.7
> > >
> > > --
> > > To unsubscribe from this list: send the line "unsubscribe linux-input"
> > in
> > > the body of a message to majordomo@vger.kernel.org
> > > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> >
> > --
> > Dmitry
> --
> To unsubscribe from this list: send the line "unsubscribe linux-input" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [RFC][PATCH] GPIO keys
@ 2010-07-28  7:02 Shubhrajyoti D
  2010-08-03  8:15 ` Dmitry Torokhov
  0 siblings, 1 reply; 7+ messages in thread
From: Shubhrajyoti D @ 2010-07-28  7:02 UTC (permalink / raw)
  To: linux-input; +Cc: Shubhrajyoti D

Allowing the call of open and close functions.
If the gpio-keys device has some initialization
to be done allow the call of platform functions.
An example would be to enable the device.
- Having seperate functions for open and close

Signed-off-by: Shubhrajyoti D <shubhrajyoti@ti.com>
---
 drivers/input/keyboard/gpio_keys.c |   25 +++++++++++++++++++++++++
 include/linux/gpio_keys.h          |    2 ++
 2 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
index b8213fd..d06644d 100644
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -38,6 +38,8 @@ struct gpio_keys_drvdata {
 	struct input_dev *input;
 	struct mutex disable_lock;
 	unsigned int n_buttons;
+	void (*enable)(void);
+	void (*disable)(void);
 	struct gpio_button_data data[0];
 };
 
@@ -414,6 +416,24 @@ fail2:
 	return error;
 }
 
+static int gpio_keys_open(struct input_dev *dev)
+{
+	struct gpio_keys_drvdata *ddata;
+	ddata = input_get_drvdata(dev);
+	if (ddata->enable)
+		ddata->enable();
+	return 0;
+}
+
+static void gpio_keys_close(struct input_dev *dev)
+{
+	struct gpio_keys_drvdata *ddata;
+
+	ddata = input_get_drvdata(dev);
+	if (ddata->disable)
+		ddata->disable();
+}
+
 static int __devinit gpio_keys_probe(struct platform_device *pdev)
 {
 	struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
@@ -435,13 +455,18 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
 
 	ddata->input = input;
 	ddata->n_buttons = pdata->nbuttons;
+	ddata->enable =  pdata->enable;
+	ddata->disable =  pdata->disable;
 	mutex_init(&ddata->disable_lock);
 
 	platform_set_drvdata(pdev, ddata);
+	input_set_drvdata(input , ddata);
 
 	input->name = pdev->name;
 	input->phys = "gpio-keys/input0";
 	input->dev.parent = &pdev->dev;
+	input->open = gpio_keys_open;
+	input->close = gpio_keys_close;
 
 	input->id.bustype = BUS_HOST;
 	input->id.vendor = 0x0001;
diff --git a/include/linux/gpio_keys.h b/include/linux/gpio_keys.h
index cd0b3f3..5089b1b 100644
--- a/include/linux/gpio_keys.h
+++ b/include/linux/gpio_keys.h
@@ -17,6 +17,8 @@ struct gpio_keys_platform_data {
 	struct gpio_keys_button *buttons;
 	int nbuttons;
 	unsigned int rep:1;		/* enable input subsystem auto repeat */
+	void (*enable)(void);
+	void (*disable)(void);
 };
 
 #endif
-- 
1.5.4.7


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

* Re: [RFC][PATCH] GPIO keys
  2010-07-28  7:02 Shubhrajyoti D
@ 2010-08-03  8:15 ` Dmitry Torokhov
  2010-08-03 15:54   ` Datta, Shubhrajyoti
  0 siblings, 1 reply; 7+ messages in thread
From: Dmitry Torokhov @ 2010-08-03  8:15 UTC (permalink / raw)
  To: Shubhrajyoti D; +Cc: linux-input

Hi,

On Wed, Jul 28, 2010 at 12:32:10PM +0530, Shubhrajyoti D wrote:
> Allowing the call of open and close functions.
> If the gpio-keys device has some initialization
> to be done allow the call of platform functions.
> An example would be to enable the device.
> - Having seperate functions for open and close
> 

I think the patch can be improved still:

 - enable() should be allowed to fail and stop the device from
   being opened;

 - Pass the parent device into the callbacks so that they can
   differentiate in case there are 2 sets of gpio keys (or maybe
   you share the callbacks beween drivers, etc.

Does the following work for you?

Thanks.

-- 
Dmitry

Input: gpio_keys - add hooks to enable/disable device

From: Shubhrajyoti D <shubhrajyoti@ti.com>

Allow platform code to specify callbcks that will be invoked when
input device is opened or closed, allowing, for example, to enable
the device.

Signed-off-by: Shubhrajyoti D <shubhrajyoti@ti.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
---

 drivers/input/keyboard/gpio_keys.c |   22 ++++++++++++++++++++++
 include/linux/gpio_keys.h          |    2 ++
 2 files changed, 24 insertions(+), 0 deletions(-)


diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
index a9fd147..6069abe 100644
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -39,6 +39,8 @@ struct gpio_keys_drvdata {
 	struct input_dev *input;
 	struct mutex disable_lock;
 	unsigned int n_buttons;
+	int (*enable)(struct device *dev);
+	void (*disable)(struct device *dev);
 	struct gpio_button_data data[0];
 };
 
@@ -423,6 +425,21 @@ fail2:
 	return error;
 }
 
+static int gpio_keys_open(struct input_dev *input)
+{
+	struct gpio_keys_drvdata *ddata = input_get_drvdata(input);
+
+	return ddata->enable ? ddata->enable(input->dev.parent) : 0;
+}
+
+static void gpio_keys_close(struct input_dev *input)
+{
+	struct gpio_keys_drvdata *ddata = input_get_drvdata(input);
+
+	if (ddata->disable)
+		ddata->disable(input->dev.parent);
+}
+
 static int __devinit gpio_keys_probe(struct platform_device *pdev)
 {
 	struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
@@ -444,13 +461,18 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
 
 	ddata->input = input;
 	ddata->n_buttons = pdata->nbuttons;
+	ddata->enable = pdata->enable;
+	ddata->disable = pdata->disable;
 	mutex_init(&ddata->disable_lock);
 
 	platform_set_drvdata(pdev, ddata);
+	input_set_drvdata(input, ddata);
 
 	input->name = pdev->name;
 	input->phys = "gpio-keys/input0";
 	input->dev.parent = &pdev->dev;
+	input->open = gpio_keys_open;
+	input->close = gpio_keys_close;
 
 	input->id.bustype = BUS_HOST;
 	input->id.vendor = 0x0001;
diff --git a/include/linux/gpio_keys.h b/include/linux/gpio_keys.h
index cd0b3f3..ce73a30 100644
--- a/include/linux/gpio_keys.h
+++ b/include/linux/gpio_keys.h
@@ -17,6 +17,8 @@ struct gpio_keys_platform_data {
 	struct gpio_keys_button *buttons;
 	int nbuttons;
 	unsigned int rep:1;		/* enable input subsystem auto repeat */
+	int (*enable)(struct device *dev);
+	void (*disable)(struct device *dev);
 };
 
 #endif

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

* RE: [RFC][PATCH] GPIO keys
  2010-08-03  8:15 ` Dmitry Torokhov
@ 2010-08-03 15:54   ` Datta, Shubhrajyoti
  0 siblings, 0 replies; 7+ messages in thread
From: Datta, Shubhrajyoti @ 2010-08-03 15:54 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: linux-input@vger.kernel.org


Hi,
> -----Original Message-----
> From: Dmitry Torokhov [mailto:dmitry.torokhov@gmail.com]
> Sent: Tuesday, August 03, 2010 1:46 PM
> To: Datta, Shubhrajyoti
> Cc: linux-input@vger.kernel.org
> Subject: Re: [RFC][PATCH] GPIO keys
> 
> Hi,
> 
> On Wed, Jul 28, 2010 at 12:32:10PM +0530, Shubhrajyoti D wrote:
> > Allowing the call of open and close functions.
> > If the gpio-keys device has some initialization
> > to be done allow the call of platform functions.
> > An example would be to enable the device.
> > - Having seperate functions for open and close
> >
> 
> I think the patch can be improved still:
> 
>  - enable() should be allowed to fail and stop the device from
>    being opened;
> 
>  - Pass the parent device into the callbacks so that they can
>    differentiate in case there are 2 sets of gpio keys (or maybe
>    you share the callbacks beween drivers, etc.
I agree. Yes missed that case earlier.
> 
> Does the following work for you?
Yes it does 

Thanks and regards,
Shubhrajyoti
> 
> Thanks.
> 
> --
> Dmitry
> 
> Input: gpio_keys - add hooks to enable/disable device
> 
> From: Shubhrajyoti D <shubhrajyoti@ti.com>
> 
> Allow platform code to specify callbcks that will be invoked when
> input device is opened or closed, allowing, for example, to enable
> the device.
> 
> Signed-off-by: Shubhrajyoti D <shubhrajyoti@ti.com>
> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
> ---
> 
>  drivers/input/keyboard/gpio_keys.c |   22 ++++++++++++++++++++++
>  include/linux/gpio_keys.h          |    2 ++
>  2 files changed, 24 insertions(+), 0 deletions(-)
> 
> 
> diff --git a/drivers/input/keyboard/gpio_keys.c
> b/drivers/input/keyboard/gpio_keys.c
> index a9fd147..6069abe 100644
> --- a/drivers/input/keyboard/gpio_keys.c
> +++ b/drivers/input/keyboard/gpio_keys.c
> @@ -39,6 +39,8 @@ struct gpio_keys_drvdata {
>  	struct input_dev *input;
>  	struct mutex disable_lock;
>  	unsigned int n_buttons;
> +	int (*enable)(struct device *dev);
> +	void (*disable)(struct device *dev);
>  	struct gpio_button_data data[0];
>  };
> 
> @@ -423,6 +425,21 @@ fail2:
>  	return error;
>  }
> 
> +static int gpio_keys_open(struct input_dev *input)
> +{
> +	struct gpio_keys_drvdata *ddata = input_get_drvdata(input);
> +
> +	return ddata->enable ? ddata->enable(input->dev.parent) : 0;
> +}
> +
> +static void gpio_keys_close(struct input_dev *input)
> +{
> +	struct gpio_keys_drvdata *ddata = input_get_drvdata(input);
> +
> +	if (ddata->disable)
> +		ddata->disable(input->dev.parent);
> +}
> +
>  static int __devinit gpio_keys_probe(struct platform_device *pdev)
>  {
>  	struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
> @@ -444,13 +461,18 @@ static int __devinit gpio_keys_probe(struct
> platform_device *pdev)
> 
>  	ddata->input = input;
>  	ddata->n_buttons = pdata->nbuttons;
> +	ddata->enable = pdata->enable;
> +	ddata->disable = pdata->disable;
>  	mutex_init(&ddata->disable_lock);
> 
>  	platform_set_drvdata(pdev, ddata);
> +	input_set_drvdata(input, ddata);
> 
>  	input->name = pdev->name;
>  	input->phys = "gpio-keys/input0";
>  	input->dev.parent = &pdev->dev;
> +	input->open = gpio_keys_open;
> +	input->close = gpio_keys_close;
> 
>  	input->id.bustype = BUS_HOST;
>  	input->id.vendor = 0x0001;
> diff --git a/include/linux/gpio_keys.h b/include/linux/gpio_keys.h
> index cd0b3f3..ce73a30 100644
> --- a/include/linux/gpio_keys.h
> +++ b/include/linux/gpio_keys.h
> @@ -17,6 +17,8 @@ struct gpio_keys_platform_data {
>  	struct gpio_keys_button *buttons;
>  	int nbuttons;
>  	unsigned int rep:1;		/* enable input subsystem auto repeat
> */
> +	int (*enable)(struct device *dev);
> +	void (*disable)(struct device *dev);
>  };
> 
>  #endif

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

end of thread, other threads:[~2010-08-03 15:54 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-27 14:41 [RFC][PATCH] GPIO keys Datta, Shubhrajyoti
2010-07-27 17:00 ` Dmitry Torokhov
2010-07-27 17:44   ` Datta, Shubhrajyoti
2010-07-27 18:01     ` Datta, Shubhrajyoti
  -- strict thread matches above, loose matches on Subject: below --
2010-07-28  7:02 Shubhrajyoti D
2010-08-03  8:15 ` Dmitry Torokhov
2010-08-03 15:54   ` Datta, Shubhrajyoti

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).