All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Shubhrajyoti D <shubhrajyoti@ti.com>
Cc: linux-input@vger.kernel.org
Subject: Re: [RFC][PATCH] GPIO keys
Date: Tue, 3 Aug 2010 01:15:51 -0700	[thread overview]
Message-ID: <20100803081551.GA16029@core.coreip.homeip.net> (raw)
In-Reply-To: <1280300530-17096-1-git-send-email-shubhrajyoti@ti.com>

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

  reply	other threads:[~2010-08-03  8:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-28  7:02 [RFC][PATCH] GPIO keys Shubhrajyoti D
2010-08-03  8:15 ` Dmitry Torokhov [this message]
2010-08-03 15:54   ` Datta, Shubhrajyoti
  -- strict thread matches above, loose matches on Subject: below --
2010-07-27 14:41 Datta, Shubhrajyoti
2010-07-27 17:00 ` Dmitry Torokhov
2010-07-27 17:44   ` Datta, Shubhrajyoti
2010-07-27 18:01     ` Datta, Shubhrajyoti

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100803081551.GA16029@core.coreip.homeip.net \
    --to=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=shubhrajyoti@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.