mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 2/4] input: gpio-keys: separate internal data from platform_data
Date: Fri, 14 Feb 2014 16:38:52 +0100	[thread overview]
Message-ID: <1392392334-20254-3-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1392392334-20254-1-git-send-email-s.hauer@pengutronix.de>

Do not abuse platform data for internal driver data, instead
use a separate struct for that.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/input/gpio_keys.c | 80 +++++++++++++++++++++++++++++++++--------------
 include/gpio_keys.h       |  7 -----
 2 files changed, 57 insertions(+), 30 deletions(-)

diff --git a/drivers/input/gpio_keys.c b/drivers/input/gpio_keys.c
index 18a29f0..418158f 100644
--- a/drivers/input/gpio_keys.c
+++ b/drivers/input/gpio_keys.c
@@ -12,31 +12,52 @@
 #include <poller.h>
 #include <gpio.h>
 
-static inline struct gpio_keys_platform_data *
+struct gpio_key {
+	int code;
+
+	int gpio;
+	int active_low;
+
+	int previous_state;
+};
+
+struct gpio_keys {
+	struct gpio_key *buttons;
+	int nbuttons;
+
+	/* optional */
+	int fifo_size;
+
+	struct kfifo *recv_fifo;
+	struct poller_struct poller;
+	struct console_device cdev;
+};
+
+static inline struct gpio_keys *
 poller_to_gk_pdata(struct poller_struct *poller)
 {
-	return container_of(poller, struct gpio_keys_platform_data, poller);
+	return container_of(poller, struct gpio_keys, poller);
 }
 
-static inline struct gpio_keys_platform_data *
+static inline struct gpio_keys *
 cdev_to_gk_pdata(struct console_device *cdev)
 {
-	return container_of(cdev, struct gpio_keys_platform_data, cdev);
+	return container_of(cdev, struct gpio_keys, cdev);
 }
 
 static void gpio_key_poller(struct poller_struct *poller)
 {
-	struct gpio_keys_platform_data *pdata = poller_to_gk_pdata(poller);
-	struct gpio_keys_button *gb;
+	struct gpio_keys *gk = poller_to_gk_pdata(poller);
+	struct gpio_key *gb;
 	int i, val;
 
-	for (i = 0; i < pdata->nbuttons; i++) {
+	for (i = 0; i < gk->nbuttons; i++) {
 
-		gb = &pdata->buttons[i];
+		gb = &gk->buttons[i];
 		val = gpio_get_value(gb->gpio);
 
 		if (val != gb->previous_state && val != gb->active_low) {
-			kfifo_put(pdata->recv_fifo, (u_char*)&gb->code, sizeof(int));
+			kfifo_put(gk->recv_fifo, (u_char*)&gb->code, sizeof(int));
 			debug("pressed gpio(%d) as %d\n", gb->gpio, gb->code);
 		}
 		gb->previous_state = val;
@@ -45,17 +66,17 @@ static void gpio_key_poller(struct poller_struct *poller)
 
 static int gpio_keys_tstc(struct console_device *cdev)
 {
-	struct gpio_keys_platform_data *pdata = cdev_to_gk_pdata(cdev);
+	struct gpio_keys *gk = cdev_to_gk_pdata(cdev);
 
-	return (kfifo_len(pdata->recv_fifo) == 0) ? 0 : 1;
+	return (kfifo_len(gk->recv_fifo) == 0) ? 0 : 1;
 }
 
 static int gpio_keys_getc(struct console_device *cdev)
 {
 	int code = 0;
-	struct gpio_keys_platform_data *pdata = cdev_to_gk_pdata(cdev);
+	struct gpio_keys *gk = cdev_to_gk_pdata(cdev);
 
-	kfifo_get(pdata->recv_fifo, (u_char*)&code, sizeof(int));
+	kfifo_get(gk->recv_fifo, (u_char*)&code, sizeof(int));
 	return code;
 }
 
@@ -64,6 +85,7 @@ static int __init gpio_keys_probe(struct device_d *dev)
 	int ret, i, gpio;
 	struct gpio_keys_platform_data *pdata;
 	struct console_device *cdev;
+	struct gpio_keys *gk;
 
 	pdata = dev->platform_data;
 
@@ -73,34 +95,46 @@ static int __init gpio_keys_probe(struct device_d *dev)
 		return -ENODEV;
 	}
 
-	if (!pdata->fifo_size)
-		pdata->fifo_size = 50;
+	gk = xzalloc(sizeof(*gk));
+
+	gk->fifo_size = 50;
+
+	if (pdata->fifo_size)
+		gk->fifo_size = pdata->fifo_size;
 
-	pdata->recv_fifo = kfifo_alloc(pdata->fifo_size);
+	gk->recv_fifo = kfifo_alloc(pdata->fifo_size);
+
+	gk->buttons = xzalloc(pdata->nbuttons * sizeof(*gk->buttons));
+	gk->nbuttons = pdata->nbuttons;
+
+	for (i = 0; i < gk->nbuttons; i++) {
+		gk->buttons[i].gpio = pdata->buttons[i].gpio;
+		gk->buttons[i].code = pdata->buttons[i].code;
+		gk->buttons[i].active_low = pdata->buttons[i].active_low;
+	}
 
 	for (i = 0; i < pdata->nbuttons; i++) {
-		gpio = pdata->buttons[i].gpio;
+		gpio = gk->buttons[i].gpio;
 		ret = gpio_request(gpio, "gpio_keys");
 		if (ret) {
 			pr_err("gpio_keys: (%d) can not be requested\n", gpio);
 			return ret;
 		}
 		gpio_direction_input(gpio);
-		pdata->buttons[i].previous_state =
-			pdata->buttons[i].active_low;
+		gk->buttons[i].previous_state = gk->buttons[i].active_low;
 	}
 
-	pdata->poller.func = gpio_key_poller;
+	gk->poller.func = gpio_key_poller;
 
-	cdev = &pdata->cdev;
+	cdev = &gk->cdev;
 	dev->type_data = cdev;
 	cdev->dev = dev;
 	cdev->tstc = gpio_keys_tstc;
 	cdev->getc = gpio_keys_getc;
 
-	console_register(&pdata->cdev);
+	console_register(&gk->cdev);
 
-	return poller_register(&pdata->poller);
+	return poller_register(&gk->poller);
 }
 
 static struct driver_d gpio_keys_driver = {
diff --git a/include/gpio_keys.h b/include/gpio_keys.h
index fc548fa..f4a22e1 100644
--- a/include/gpio_keys.h
+++ b/include/gpio_keys.h
@@ -10,9 +10,6 @@ struct gpio_keys_button {
 
 	int gpio;
 	int active_low;
-
-	/* internal */
-	int previous_state;
 };
 
 struct gpio_keys_platform_data {
@@ -21,10 +18,6 @@ struct gpio_keys_platform_data {
 
 	/* optional */
 	int fifo_size;
-
-	struct kfifo *recv_fifo;
-	struct poller_struct poller;
-	struct console_device cdev;
 };
 
 #endif
-- 
1.8.5.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2014-02-14 15:39 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-14 15:38 Add devicetree support to gpio-keys driver Sascha Hauer
2014-02-14 15:38 ` [PATCH 1/4] input: Add BB_ prefix to KEY_ defines Sascha Hauer
2014-02-14 15:38 ` Sascha Hauer [this message]
2014-02-14 15:38 ` [PATCH 3/4] input: Add keycode to barebox key translation table Sascha Hauer
2014-02-14 15:38 ` [PATCH 4/4] input: gpio-keys: Add devicetree probe support Sascha Hauer

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=1392392334-20254-3-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox