linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] Input: make the GPIO mouse useful
@ 2017-09-17 11:14 Linus Walleij
  2017-09-17 11:14 ` [PATCH 1/5] input: mouse: Kill off platform data for GPIO mouse Linus Walleij
                   ` (5 more replies)
  0 siblings, 6 replies; 9+ messages in thread
From: Linus Walleij @ 2017-09-17 11:14 UTC (permalink / raw)
  To: Dmitry Torokhov, linux-input, Hans-Christian Noren Egtvedt; +Cc: Linus Walleij

The GPIO mouse device does not have any in-kernel users.

This series converts it to use descriptors, adds device tree
bindings and adds device tree probing so it can be used for
embedded target etc without proper mouse ports.

An alternative is to simply delete the driver. But I took
pity in it and I am also worried that the number of out-of-tree
users could be pretty large.

Hans-Christian: can you express your idea for the future of
this driver? Does this look all right to you? Do you want to
add some users in some device trees maybe?

Linus Walleij (5):
  input: mouse: Kill off platform data for GPIO mouse
  input: mouse: Rename GPIO mouse variables
  input: mouse: Add DT bindings for GPIO mice
  input: mouse: Convert GPIO mouse to use descriptors
  input: mouse: Add device tree probing to GPIO mouse

 .../devicetree/bindings/input/gpio-mouse.txt       |  32 ++++
 drivers/input/mouse/gpio_mouse.c                   | 195 +++++++++++----------
 include/linux/gpio_mouse.h                         |  61 -------
 3 files changed, 130 insertions(+), 158 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/input/gpio-mouse.txt
 delete mode 100644 include/linux/gpio_mouse.h

-- 
2.13.5


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

* [PATCH 1/5] input: mouse: Kill off platform data for GPIO mouse
  2017-09-17 11:14 [PATCH 0/5] Input: make the GPIO mouse useful Linus Walleij
@ 2017-09-17 11:14 ` Linus Walleij
  2017-09-17 11:14 ` [PATCH 2/5] input: mouse: Rename GPIO mouse variables Linus Walleij
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Linus Walleij @ 2017-09-17 11:14 UTC (permalink / raw)
  To: Dmitry Torokhov, linux-input, Hans-Christian Noren Egtvedt; +Cc: Linus Walleij

This is not used much: git grep  gpio_mouse_platform_data shows
that absolutely nothing in the kernel defines this platform
data.

It could be argued that the driver should be deleted. But that
is a bit harsh I think since it seems generally useful. So
this patch starts a series which repurposes it to be used with
hardware nodes from device tree or ACPI.

This first patch simply localize the platform data header and
allocates a dummy platform data.

Yes: this patch leaves the driver in a pretty useless state,
but since nothing is instantiating this driver, it doesn't
make it more useless than it already is. Later patches makes
use of the driver.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/input/mouse/gpio_mouse.c | 59 +++++++++++++++++++++++++++++++++-----
 include/linux/gpio_mouse.h       | 61 ----------------------------------------
 2 files changed, 52 insertions(+), 68 deletions(-)
 delete mode 100644 include/linux/gpio_mouse.h

diff --git a/drivers/input/mouse/gpio_mouse.c b/drivers/input/mouse/gpio_mouse.c
index ced07391304b..dcaba1e4fffb 100644
--- a/drivers/input/mouse/gpio_mouse.c
+++ b/drivers/input/mouse/gpio_mouse.c
@@ -12,8 +12,54 @@
 #include <linux/platform_device.h>
 #include <linux/input-polldev.h>
 #include <linux/gpio.h>
-#include <linux/gpio_mouse.h>
 
+#define GPIO_MOUSE_POLARITY_ACT_HIGH	0x00
+#define GPIO_MOUSE_POLARITY_ACT_LOW	0x01
+
+#define GPIO_MOUSE_PIN_UP	0
+#define GPIO_MOUSE_PIN_DOWN	1
+#define GPIO_MOUSE_PIN_LEFT	2
+#define GPIO_MOUSE_PIN_RIGHT	3
+#define GPIO_MOUSE_PIN_BLEFT	4
+#define GPIO_MOUSE_PIN_BMIDDLE	5
+#define GPIO_MOUSE_PIN_BRIGHT	6
+#define GPIO_MOUSE_PIN_MAX	7
+
+/**
+ * struct gpio_mouse_platform_data
+ * @scan_ms: integer in ms specifying the scan periode.
+ * @polarity: Pin polarity, active high or low.
+ * @up: GPIO line for up value.
+ * @down: GPIO line for down value.
+ * @left: GPIO line for left value.
+ * @right: GPIO line for right value.
+ * @bleft: GPIO line for left button.
+ * @bmiddle: GPIO line for middle button.
+ * @bright: GPIO line for right button.
+ * @pins: GPIO line numbers used for the mouse.
+ *
+ * This struct must be added to the platform_device in the board code.
+ * It is used by the gpio_mouse driver to setup GPIO lines and to
+ * calculate mouse movement.
+ */
+struct gpio_mouse_platform_data {
+	int scan_ms;
+	int polarity;
+
+	union {
+		struct {
+			int up;
+			int down;
+			int left;
+			int right;
+
+			int bleft;
+			int bmiddle;
+			int bright;
+		};
+		int pins[GPIO_MOUSE_PIN_MAX];
+	};
+};
 
 /*
  * Timer function which is run every scan_ms ms when the device is opened.
@@ -47,17 +93,16 @@ static void gpio_mouse_scan(struct input_polled_dev *dev)
 
 static int gpio_mouse_probe(struct platform_device *pdev)
 {
-	struct gpio_mouse_platform_data *pdata = dev_get_platdata(&pdev->dev);
+	struct device *dev = &pdev->dev;
+	struct gpio_mouse_platform_data *pdata;
 	struct input_polled_dev *input_poll;
 	struct input_dev *input;
 	int pin, i;
 	int error;
 
-	if (!pdata) {
-		dev_err(&pdev->dev, "no platform data\n");
-		error = -ENXIO;
-		goto out;
-	}
+	pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
+	if (!pdata)
+		return -ENOMEM;
 
 	if (pdata->scan_ms < 0) {
 		dev_err(&pdev->dev, "invalid scan time\n");
diff --git a/include/linux/gpio_mouse.h b/include/linux/gpio_mouse.h
deleted file mode 100644
index 44ed7aa14d85..000000000000
--- a/include/linux/gpio_mouse.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Driver for simulating a mouse on GPIO lines.
- *
- * Copyright (C) 2007 Atmel Corporation
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-
-#ifndef _GPIO_MOUSE_H
-#define _GPIO_MOUSE_H
-
-#define GPIO_MOUSE_POLARITY_ACT_HIGH	0x00
-#define GPIO_MOUSE_POLARITY_ACT_LOW	0x01
-
-#define GPIO_MOUSE_PIN_UP	0
-#define GPIO_MOUSE_PIN_DOWN	1
-#define GPIO_MOUSE_PIN_LEFT	2
-#define GPIO_MOUSE_PIN_RIGHT	3
-#define GPIO_MOUSE_PIN_BLEFT	4
-#define GPIO_MOUSE_PIN_BMIDDLE	5
-#define GPIO_MOUSE_PIN_BRIGHT	6
-#define GPIO_MOUSE_PIN_MAX	7
-
-/**
- * struct gpio_mouse_platform_data
- * @scan_ms: integer in ms specifying the scan periode.
- * @polarity: Pin polarity, active high or low.
- * @up: GPIO line for up value.
- * @down: GPIO line for down value.
- * @left: GPIO line for left value.
- * @right: GPIO line for right value.
- * @bleft: GPIO line for left button.
- * @bmiddle: GPIO line for middle button.
- * @bright: GPIO line for right button.
- *
- * This struct must be added to the platform_device in the board code.
- * It is used by the gpio_mouse driver to setup GPIO lines and to
- * calculate mouse movement.
- */
-struct gpio_mouse_platform_data {
-	int scan_ms;
-	int polarity;
-
-	union {
-		struct {
-			int up;
-			int down;
-			int left;
-			int right;
-
-			int bleft;
-			int bmiddle;
-			int bright;
-		};
-		int pins[GPIO_MOUSE_PIN_MAX];
-	};
-};
-
-#endif /* _GPIO_MOUSE_H */
-- 
2.13.5


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

* [PATCH 2/5] input: mouse: Rename GPIO mouse variables
  2017-09-17 11:14 [PATCH 0/5] Input: make the GPIO mouse useful Linus Walleij
  2017-09-17 11:14 ` [PATCH 1/5] input: mouse: Kill off platform data for GPIO mouse Linus Walleij
@ 2017-09-17 11:14 ` Linus Walleij
  2017-09-17 11:14 ` [PATCH 3/5] input: mouse: Add DT bindings for GPIO mice Linus Walleij
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Linus Walleij @ 2017-09-17 11:14 UTC (permalink / raw)
  To: Dmitry Torokhov, linux-input, Hans-Christian Noren Egtvedt; +Cc: Linus Walleij

Use more apropriate names for the "platform data" which is
now just a simple state container for the GPIO mouse.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/input/mouse/gpio_mouse.c | 40 ++++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/drivers/input/mouse/gpio_mouse.c b/drivers/input/mouse/gpio_mouse.c
index dcaba1e4fffb..d1914bb3531f 100644
--- a/drivers/input/mouse/gpio_mouse.c
+++ b/drivers/input/mouse/gpio_mouse.c
@@ -26,7 +26,7 @@
 #define GPIO_MOUSE_PIN_MAX	7
 
 /**
- * struct gpio_mouse_platform_data
+ * struct gpio_mouse
  * @scan_ms: integer in ms specifying the scan periode.
  * @polarity: Pin polarity, active high or low.
  * @up: GPIO line for up value.
@@ -42,7 +42,7 @@
  * It is used by the gpio_mouse driver to setup GPIO lines and to
  * calculate mouse movement.
  */
-struct gpio_mouse_platform_data {
+struct gpio_mouse {
 	int scan_ms;
 	int polarity;
 
@@ -67,7 +67,7 @@ struct gpio_mouse_platform_data {
  */
 static void gpio_mouse_scan(struct input_polled_dev *dev)
 {
-	struct gpio_mouse_platform_data *gpio = dev->private;
+	struct gpio_mouse *gpio = dev->private;
 	struct input_dev *input = dev->input;
 	int x, y;
 
@@ -94,24 +94,24 @@ static void gpio_mouse_scan(struct input_polled_dev *dev)
 static int gpio_mouse_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
-	struct gpio_mouse_platform_data *pdata;
+	struct gpio_mouse *gmouse;
 	struct input_polled_dev *input_poll;
 	struct input_dev *input;
 	int pin, i;
 	int error;
 
-	pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
-	if (!pdata)
+	gmouse = devm_kzalloc(dev, sizeof(*gmouse), GFP_KERNEL);
+	if (!gmouse)
 		return -ENOMEM;
 
-	if (pdata->scan_ms < 0) {
+	if (gmouse->scan_ms < 0) {
 		dev_err(&pdev->dev, "invalid scan time\n");
 		error = -EINVAL;
 		goto out;
 	}
 
 	for (i = 0; i < GPIO_MOUSE_PIN_MAX; i++) {
-		pin = pdata->pins[i];
+		pin = gmouse->pins[i];
 
 		if (pin < 0) {
 
@@ -148,9 +148,9 @@ static int gpio_mouse_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, input_poll);
 
 	/* set input-polldev handlers */
-	input_poll->private = pdata;
+	input_poll->private = gmouse;
 	input_poll->poll = gpio_mouse_scan;
-	input_poll->poll_interval = pdata->scan_ms;
+	input_poll->poll_interval = gmouse->scan_ms;
 
 	input = input_poll->input;
 	input->name = pdev->name;
@@ -159,11 +159,11 @@ static int gpio_mouse_probe(struct platform_device *pdev)
 
 	input_set_capability(input, EV_REL, REL_X);
 	input_set_capability(input, EV_REL, REL_Y);
-	if (pdata->bleft >= 0)
+	if (gmouse->bleft >= 0)
 		input_set_capability(input, EV_KEY, BTN_LEFT);
-	if (pdata->bmiddle >= 0)
+	if (gmouse->bmiddle >= 0)
 		input_set_capability(input, EV_KEY, BTN_MIDDLE);
-	if (pdata->bright >= 0)
+	if (gmouse->bright >= 0)
 		input_set_capability(input, EV_KEY, BTN_RIGHT);
 
 	error = input_register_polled_device(input_poll);
@@ -173,10 +173,10 @@ static int gpio_mouse_probe(struct platform_device *pdev)
 	}
 
 	dev_dbg(&pdev->dev, "%d ms scan time, buttons: %s%s%s\n",
-			pdata->scan_ms,
-			pdata->bleft < 0 ? "" : "left ",
-			pdata->bmiddle < 0 ? "" : "middle ",
-			pdata->bright < 0 ? "" : "right");
+			gmouse->scan_ms,
+			gmouse->bleft < 0 ? "" : "left ",
+			gmouse->bmiddle < 0 ? "" : "middle ",
+			gmouse->bright < 0 ? "" : "right");
 
 	return 0;
 
@@ -185,7 +185,7 @@ static int gpio_mouse_probe(struct platform_device *pdev)
 
  out_free_gpios:
 	while (--i >= 0) {
-		pin = pdata->pins[i];
+		pin = gmouse->pins[i];
 		if (pin)
 			gpio_free(pin);
 	}
@@ -196,14 +196,14 @@ static int gpio_mouse_probe(struct platform_device *pdev)
 static int gpio_mouse_remove(struct platform_device *pdev)
 {
 	struct input_polled_dev *input = platform_get_drvdata(pdev);
-	struct gpio_mouse_platform_data *pdata = input->private;
+	struct gpio_mouse *gmouse = input->private;
 	int pin, i;
 
 	input_unregister_polled_device(input);
 	input_free_polled_device(input);
 
 	for (i = 0; i < GPIO_MOUSE_PIN_MAX; i++) {
-		pin = pdata->pins[i];
+		pin = gmouse->pins[i];
 		if (pin >= 0)
 			gpio_free(pin);
 	}
-- 
2.13.5


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

* [PATCH 3/5] input: mouse: Add DT bindings for GPIO mice
  2017-09-17 11:14 [PATCH 0/5] Input: make the GPIO mouse useful Linus Walleij
  2017-09-17 11:14 ` [PATCH 1/5] input: mouse: Kill off platform data for GPIO mouse Linus Walleij
  2017-09-17 11:14 ` [PATCH 2/5] input: mouse: Rename GPIO mouse variables Linus Walleij
@ 2017-09-17 11:14 ` Linus Walleij
  2017-09-20 20:53   ` Rob Herring
  2017-09-17 11:14 ` [PATCH 4/5] input: mouse: Convert GPIO mouse to use descriptors Linus Walleij
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 9+ messages in thread
From: Linus Walleij @ 2017-09-17 11:14 UTC (permalink / raw)
  To: Dmitry Torokhov, linux-input, Hans-Christian Noren Egtvedt
  Cc: Linus Walleij, devicetree

This adds DT bindings for simple mice attached to GPIO lines.
As the properties are very general and pertains to all mice I
can think of, we use very generic names for the 4-7 GPIO lines,
"up", "down" etc.

Cc: devicetree@vger.kernel.org
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
This patch is inspired by the existance of a GPIO mouse driver
with no in-kernel users.
---
 .../devicetree/bindings/input/gpio-mouse.txt       | 32 ++++++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/gpio-mouse.txt

diff --git a/Documentation/devicetree/bindings/input/gpio-mouse.txt b/Documentation/devicetree/bindings/input/gpio-mouse.txt
new file mode 100644
index 000000000000..82622a439745
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/gpio-mouse.txt
@@ -0,0 +1,32 @@
+Device-Tree bindings for GPIO attached mice
+
+This simply uses standard GPIO handles to define a simple mouse connected
+to 4-7 GPIO lines.
+
+Required properties:
+	- compatible: must be "gpio-mouse"
+	- scan-interval: The scanning interval in milliseconds
+	- up-gpios: GPIO line phandle to the line indicating "up"
+	- down-gpios: GPIO line phandle to the line indicating "down"
+	- left-gpios: GPIO line phandle to the line indicating "left"
+	- right-gpios: GPIO line phandle to the line indicating "right"
+
+Optional properties:
+	- button-left-gpios: GPIO line handle to the left mouse button
+	- button-middle-gpios: GPIO line handle to the middle mouse button
+	- button-right-gpios: GPIO line handle to the right mouse button
+Example:
+
+#include <dt-bindings/gpio/gpio.h>
+
+gpio-mouse {
+	compatible = "gpio-keys";
+	scan-interval = <50>;
+	up-gpios = <&gpio0 0 GPIO_ACTIVE_LOW>;
+	down-gpios = <&gpio0 1 GPIO_ACTIVE_LOW>;
+	left-gpios = <&gpio0 2 GPIO_ACTIVE_LOW>;
+	right-gpios = <&gpio0 3 GPIO_ACTIVE_LOW>;
+	button-left-gpios = <&gpio0 4 GPIO_ACTIVE_LOW>;
+	button-middle-gpios = <&gpio0 5 GPIO_ACTIVE_LOW>;
+	button-right-gpios = <&gpio0 6 GPIO_ACTIVE_LOW>;
+};
-- 
2.13.5


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

* [PATCH 4/5] input: mouse: Convert GPIO mouse to use descriptors
  2017-09-17 11:14 [PATCH 0/5] Input: make the GPIO mouse useful Linus Walleij
                   ` (2 preceding siblings ...)
  2017-09-17 11:14 ` [PATCH 3/5] input: mouse: Add DT bindings for GPIO mice Linus Walleij
@ 2017-09-17 11:14 ` Linus Walleij
  2017-09-21 21:18   ` Dmitry Torokhov
  2017-09-17 11:14 ` [PATCH 5/5] input: mouse: Add device tree probing to GPIO mouse Linus Walleij
  2017-09-17 12:44 ` [PATCH 0/5] Input: make the GPIO mouse useful Hans-Christian Noren Egtvedt
  5 siblings, 1 reply; 9+ messages in thread
From: Linus Walleij @ 2017-09-17 11:14 UTC (permalink / raw)
  To: Dmitry Torokhov, linux-input, Hans-Christian Noren Egtvedt; +Cc: Linus Walleij

This converts the GPIO mouse to use descriptors and
fwnode properties. The polarity settings go out the window
since GPIO descriptor already know about polarity so this
should be configured in device tree or ACPI or similar.

Set scanning interval by default to 50ms if not found as
a property on the device.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/input/mouse/gpio_mouse.c | 171 ++++++++++++++-------------------------
 1 file changed, 60 insertions(+), 111 deletions(-)

diff --git a/drivers/input/mouse/gpio_mouse.c b/drivers/input/mouse/gpio_mouse.c
index d1914bb3531f..7bd2a8ac6e6e 100644
--- a/drivers/input/mouse/gpio_mouse.c
+++ b/drivers/input/mouse/gpio_mouse.c
@@ -2,6 +2,7 @@
  * Driver for simulating a mouse on GPIO lines.
  *
  * Copyright (C) 2007 Atmel Corporation
+ * Copyright (C) 2017 Linus Walleij <linus.walleij@linaro.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
@@ -11,24 +12,12 @@
 #include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/input-polldev.h>
-#include <linux/gpio.h>
-
-#define GPIO_MOUSE_POLARITY_ACT_HIGH	0x00
-#define GPIO_MOUSE_POLARITY_ACT_LOW	0x01
-
-#define GPIO_MOUSE_PIN_UP	0
-#define GPIO_MOUSE_PIN_DOWN	1
-#define GPIO_MOUSE_PIN_LEFT	2
-#define GPIO_MOUSE_PIN_RIGHT	3
-#define GPIO_MOUSE_PIN_BLEFT	4
-#define GPIO_MOUSE_PIN_BMIDDLE	5
-#define GPIO_MOUSE_PIN_BRIGHT	6
-#define GPIO_MOUSE_PIN_MAX	7
+#include <linux/gpio/consumer.h>
+#include <linux/property.h>
 
 /**
  * struct gpio_mouse
- * @scan_ms: integer in ms specifying the scan periode.
- * @polarity: Pin polarity, active high or low.
+ * @scan_ms: the scan interval in milliseconds.
  * @up: GPIO line for up value.
  * @down: GPIO line for down value.
  * @left: GPIO line for left value.
@@ -36,29 +25,20 @@
  * @bleft: GPIO line for left button.
  * @bmiddle: GPIO line for middle button.
  * @bright: GPIO line for right button.
- * @pins: GPIO line numbers used for the mouse.
  *
  * This struct must be added to the platform_device in the board code.
  * It is used by the gpio_mouse driver to setup GPIO lines and to
  * calculate mouse movement.
  */
 struct gpio_mouse {
-	int scan_ms;
-	int polarity;
-
-	union {
-		struct {
-			int up;
-			int down;
-			int left;
-			int right;
-
-			int bleft;
-			int bmiddle;
-			int bright;
-		};
-		int pins[GPIO_MOUSE_PIN_MAX];
-	};
+	u32 scan_ms;
+	struct gpio_desc *up;
+	struct gpio_desc *down;
+	struct gpio_desc *left;
+	struct gpio_desc *right;
+	struct gpio_desc *bleft;
+	struct gpio_desc *bmiddle;
+	struct gpio_desc *bright;
 };
 
 /*
@@ -71,20 +51,18 @@ static void gpio_mouse_scan(struct input_polled_dev *dev)
 	struct input_dev *input = dev->input;
 	int x, y;
 
-	if (gpio->bleft >= 0)
+	if (!IS_ERR(gpio->bleft))
 		input_report_key(input, BTN_LEFT,
-				gpio_get_value(gpio->bleft) ^ gpio->polarity);
-	if (gpio->bmiddle >= 0)
+				 gpiod_get_value(gpio->bleft));
+	if (!IS_ERR(gpio->bmiddle))
 		input_report_key(input, BTN_MIDDLE,
-				gpio_get_value(gpio->bmiddle) ^ gpio->polarity);
-	if (gpio->bright >= 0)
+				 gpiod_get_value(gpio->bmiddle));
+	if (!IS_ERR(gpio->bright))
 		input_report_key(input, BTN_RIGHT,
-				gpio_get_value(gpio->bright) ^ gpio->polarity);
+				 gpiod_get_value(gpio->bright));
 
-	x = (gpio_get_value(gpio->right) ^ gpio->polarity)
-		- (gpio_get_value(gpio->left) ^ gpio->polarity);
-	y = (gpio_get_value(gpio->down) ^ gpio->polarity)
-		- (gpio_get_value(gpio->up) ^ gpio->polarity);
+	x = gpiod_get_value(gpio->right) - gpiod_get_value(gpio->left);
+	y = gpiod_get_value(gpio->down) - gpiod_get_value(gpio->up);
 
 	input_report_rel(input, REL_X, x);
 	input_report_rel(input, REL_Y, y);
@@ -97,52 +75,45 @@ static int gpio_mouse_probe(struct platform_device *pdev)
 	struct gpio_mouse *gmouse;
 	struct input_polled_dev *input_poll;
 	struct input_dev *input;
-	int pin, i;
-	int error;
+	int ret;
 
 	gmouse = devm_kzalloc(dev, sizeof(*gmouse), GFP_KERNEL);
 	if (!gmouse)
 		return -ENOMEM;
 
-	if (gmouse->scan_ms < 0) {
-		dev_err(&pdev->dev, "invalid scan time\n");
-		error = -EINVAL;
-		goto out;
-	}
-
-	for (i = 0; i < GPIO_MOUSE_PIN_MAX; i++) {
-		pin = gmouse->pins[i];
-
-		if (pin < 0) {
-
-			if (i <= GPIO_MOUSE_PIN_RIGHT) {
-				/* Mouse direction is required. */
-				dev_err(&pdev->dev,
-					"missing GPIO for directions\n");
-				error = -EINVAL;
-				goto out_free_gpios;
-			}
-
-			if (i == GPIO_MOUSE_PIN_BLEFT)
-				dev_dbg(&pdev->dev, "no left button defined\n");
-
-		} else {
-			error = gpio_request(pin, "gpio_mouse");
-			if (error) {
-				dev_err(&pdev->dev, "fail %d pin (%d idx)\n",
-					pin, i);
-				goto out_free_gpios;
-			}
-
-			gpio_direction_input(pin);
-		}
+	/* Assign some default scanning time */
+	ret = device_property_read_u32(dev, "scan-interval",
+				       &gmouse->scan_ms);
+	if (ret || (gmouse->scan_ms == 0)) {
+		dev_err(dev, "invalid scan time, set to 50 ms\n");
+		gmouse->scan_ms = 50;
 	}
 
-	input_poll = input_allocate_polled_device();
+	/*
+	 * These are compulsory GPIOs so bail out if any of them are
+	 * not found.
+	 */
+	gmouse->up = devm_gpiod_get(dev, "up", GPIOD_IN);
+	if (IS_ERR(gmouse->up))
+		return PTR_ERR(gmouse->up);
+	gmouse->down = devm_gpiod_get(dev, "down", GPIOD_IN);
+	if (IS_ERR(gmouse->down))
+		return PTR_ERR(gmouse->down);
+	gmouse->left = devm_gpiod_get(dev, "left", GPIOD_IN);
+	if (IS_ERR(gmouse->left))
+		return PTR_ERR(gmouse->left);
+	gmouse->right = devm_gpiod_get(dev, "right", GPIOD_IN);
+	if (IS_ERR(gmouse->right))
+		return PTR_ERR(gmouse->right);
+
+	gmouse->bleft = devm_gpiod_get(dev, "button-left", GPIOD_IN);
+	gmouse->bmiddle = devm_gpiod_get(dev, "button-middle", GPIOD_IN);
+	gmouse->bright = devm_gpiod_get(dev, "button-right", GPIOD_IN);
+
+	input_poll = devm_input_allocate_polled_device(dev);
 	if (!input_poll) {
-		dev_err(&pdev->dev, "not enough memory for input device\n");
-		error = -ENOMEM;
-		goto out_free_gpios;
+		dev_err(dev, "not enough memory for input device\n");
+		return -ENOMEM;
 	}
 
 	platform_set_drvdata(pdev, input_poll);
@@ -166,48 +137,26 @@ static int gpio_mouse_probe(struct platform_device *pdev)
 	if (gmouse->bright >= 0)
 		input_set_capability(input, EV_KEY, BTN_RIGHT);
 
-	error = input_register_polled_device(input_poll);
-	if (error) {
-		dev_err(&pdev->dev, "could not register input device\n");
-		goto out_free_polldev;
+	ret = input_register_polled_device(input_poll);
+	if (ret) {
+		dev_err(dev, "could not register input device\n");
+		return ret;
 	}
 
-	dev_dbg(&pdev->dev, "%d ms scan time, buttons: %s%s%s\n",
-			gmouse->scan_ms,
-			gmouse->bleft < 0 ? "" : "left ",
-			gmouse->bmiddle < 0 ? "" : "middle ",
-			gmouse->bright < 0 ? "" : "right");
+	dev_dbg(dev, "%d ms scan time, buttons: %s%s%s\n",
+		gmouse->scan_ms,
+		IS_ERR(gmouse->bleft) ? "" : "left ",
+		IS_ERR(gmouse->bmiddle) ? "" : "middle ",
+		IS_ERR(gmouse->bright) ? "" : "right");
 
 	return 0;
-
- out_free_polldev:
-	input_free_polled_device(input_poll);
-
- out_free_gpios:
-	while (--i >= 0) {
-		pin = gmouse->pins[i];
-		if (pin)
-			gpio_free(pin);
-	}
- out:
-	return error;
 }
 
 static int gpio_mouse_remove(struct platform_device *pdev)
 {
 	struct input_polled_dev *input = platform_get_drvdata(pdev);
-	struct gpio_mouse *gmouse = input->private;
-	int pin, i;
 
 	input_unregister_polled_device(input);
-	input_free_polled_device(input);
-
-	for (i = 0; i < GPIO_MOUSE_PIN_MAX; i++) {
-		pin = gmouse->pins[i];
-		if (pin >= 0)
-			gpio_free(pin);
-	}
-
 	return 0;
 }
 
-- 
2.13.5


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

* [PATCH 5/5] input: mouse: Add device tree probing to GPIO mouse
  2017-09-17 11:14 [PATCH 0/5] Input: make the GPIO mouse useful Linus Walleij
                   ` (3 preceding siblings ...)
  2017-09-17 11:14 ` [PATCH 4/5] input: mouse: Convert GPIO mouse to use descriptors Linus Walleij
@ 2017-09-17 11:14 ` Linus Walleij
  2017-09-17 12:44 ` [PATCH 0/5] Input: make the GPIO mouse useful Hans-Christian Noren Egtvedt
  5 siblings, 0 replies; 9+ messages in thread
From: Linus Walleij @ 2017-09-17 11:14 UTC (permalink / raw)
  To: Dmitry Torokhov, linux-input, Hans-Christian Noren Egtvedt; +Cc: Linus Walleij

This makes the GPIO mouse probe nicely from the device tree
if found in a tree. As the driver uses device properties it
can easily be amended to also probe from ACPI devices.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/input/mouse/gpio_mouse.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/input/mouse/gpio_mouse.c b/drivers/input/mouse/gpio_mouse.c
index 7bd2a8ac6e6e..bf748efb270a 100644
--- a/drivers/input/mouse/gpio_mouse.c
+++ b/drivers/input/mouse/gpio_mouse.c
@@ -14,6 +14,7 @@
 #include <linux/input-polldev.h>
 #include <linux/gpio/consumer.h>
 #include <linux/property.h>
+#include <linux/of.h>
 
 /**
  * struct gpio_mouse
@@ -160,11 +161,18 @@ static int gpio_mouse_remove(struct platform_device *pdev)
 	return 0;
 }
 
+static const struct of_device_id gpio_mouse_of_match[] = {
+	{ .compatible = "gpio-mouse", },
+	{ },
+};
+MODULE_DEVICE_TABLE(of, gpio_mouse_of_match);
+
 static struct platform_driver gpio_mouse_device_driver = {
 	.probe		= gpio_mouse_probe,
 	.remove		= gpio_mouse_remove,
 	.driver		= {
 		.name	= "gpio_mouse",
+		.of_match_table = gpio_mouse_of_match,
 	}
 };
 module_platform_driver(gpio_mouse_device_driver);
@@ -173,4 +181,3 @@ MODULE_AUTHOR("Hans-Christian Egtvedt <egtvedt@samfundet.no>");
 MODULE_DESCRIPTION("GPIO mouse driver");
 MODULE_LICENSE("GPL");
 MODULE_ALIAS("platform:gpio_mouse"); /* work with hotplug and coldplug */
-
-- 
2.13.5


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

* Re: [PATCH 0/5] Input: make the GPIO mouse useful
  2017-09-17 11:14 [PATCH 0/5] Input: make the GPIO mouse useful Linus Walleij
                   ` (4 preceding siblings ...)
  2017-09-17 11:14 ` [PATCH 5/5] input: mouse: Add device tree probing to GPIO mouse Linus Walleij
@ 2017-09-17 12:44 ` Hans-Christian Noren Egtvedt
  5 siblings, 0 replies; 9+ messages in thread
From: Hans-Christian Noren Egtvedt @ 2017-09-17 12:44 UTC (permalink / raw)
  To: Linus Walleij; +Cc: Dmitry Torokhov, linux-input

Around Sun 17 Sep 2017 13:14:40 +0200 or thereabout, Linus Walleij wrote:
> The GPIO mouse device does not have any in-kernel users.
> 
> This series converts it to use descriptors, adds device tree
> bindings and adds device tree probing so it can be used for
> embedded target etc without proper mouse ports.
> 
> An alternative is to simply delete the driver. But I took
> pity in it and I am also worried that the number of out-of-tree
> users could be pretty large.
> 
> Hans-Christian: can you express your idea for the future of
> this driver? Does this look all right to you? Do you want to
> add some users in some device trees maybe?

I had completely forgotten about this driver. IIRC we used it quite a lot on
various stages of development for Atmel's AVR32 processors, an architecture
now removed from the kernel.

I have found it quite useful when needing a simple input mouse like device on
embedded systems, so hopefully it is of value for other users.

OTOH, I have not used this driver for years, but if somebody do occasionally
use it, I do not mind it staying around. If the majority of people want it
out, then I will not object that either.

> Linus Walleij (5):
>   input: mouse: Kill off platform data for GPIO mouse
>   input: mouse: Rename GPIO mouse variables
>   input: mouse: Add DT bindings for GPIO mice
>   input: mouse: Convert GPIO mouse to use descriptors
>   input: mouse: Add device tree probing to GPIO mouse
> 
>  .../devicetree/bindings/input/gpio-mouse.txt       |  32 ++++
>  drivers/input/mouse/gpio_mouse.c                   | 195 +++++++++++----------
>  include/linux/gpio_mouse.h                         |  61 -------
>  3 files changed, 130 insertions(+), 158 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/input/gpio-mouse.txt
>  delete mode 100644 include/linux/gpio_mouse.h

Good work, this driver is a lot more usable rewritten to support device tree
instead of platform data. I would assume any 4.14++ kernel users is over on
device tree anyway.

Acked-by: Hans-Christian Noren Egtvedt <egtvedt@samfundet.no> on these five
patches.

-- 
mvh
Hans-Christian Noren Egtvedt

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

* Re: [PATCH 3/5] input: mouse: Add DT bindings for GPIO mice
  2017-09-17 11:14 ` [PATCH 3/5] input: mouse: Add DT bindings for GPIO mice Linus Walleij
@ 2017-09-20 20:53   ` Rob Herring
  0 siblings, 0 replies; 9+ messages in thread
From: Rob Herring @ 2017-09-20 20:53 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Dmitry Torokhov, linux-input, Hans-Christian Noren Egtvedt,
	devicetree

On Sun, Sep 17, 2017 at 01:14:43PM +0200, Linus Walleij wrote:
> This adds DT bindings for simple mice attached to GPIO lines.
> As the properties are very general and pertains to all mice I
> can think of, we use very generic names for the 4-7 GPIO lines,
> "up", "down" etc.
> 
> Cc: devicetree@vger.kernel.org
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---
> This patch is inspired by the existance of a GPIO mouse driver
> with no in-kernel users.

In userspace? Doesn't seem like common h/w or that it would work well.

> ---
>  .../devicetree/bindings/input/gpio-mouse.txt       | 32 ++++++++++++++++++++++
>  1 file changed, 32 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/input/gpio-mouse.txt
> 
> diff --git a/Documentation/devicetree/bindings/input/gpio-mouse.txt b/Documentation/devicetree/bindings/input/gpio-mouse.txt
> new file mode 100644
> index 000000000000..82622a439745
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/input/gpio-mouse.txt
> @@ -0,0 +1,32 @@
> +Device-Tree bindings for GPIO attached mice
> +
> +This simply uses standard GPIO handles to define a simple mouse connected
> +to 4-7 GPIO lines.

Presumably we have to have 1 button, so 5-7 lines?

> +
> +Required properties:
> +	- compatible: must be "gpio-mouse"
> +	- scan-interval: The scanning interval in milliseconds

Add a unit suffix. Unless we can gain something sharing this with other 
input bindings.

> +	- up-gpios: GPIO line phandle to the line indicating "up"
> +	- down-gpios: GPIO line phandle to the line indicating "down"
> +	- left-gpios: GPIO line phandle to the line indicating "left"
> +	- right-gpios: GPIO line phandle to the line indicating "right"
> +
> +Optional properties:
> +	- button-left-gpios: GPIO line handle to the left mouse button
> +	- button-middle-gpios: GPIO line handle to the middle mouse button
> +	- button-right-gpios: GPIO line handle to the right mouse button
> +Example:
> +
> +#include <dt-bindings/gpio/gpio.h>
> +
> +gpio-mouse {
> +	compatible = "gpio-keys";

copy-n-paste error.

> +	scan-interval = <50>;
> +	up-gpios = <&gpio0 0 GPIO_ACTIVE_LOW>;
> +	down-gpios = <&gpio0 1 GPIO_ACTIVE_LOW>;
> +	left-gpios = <&gpio0 2 GPIO_ACTIVE_LOW>;
> +	right-gpios = <&gpio0 3 GPIO_ACTIVE_LOW>;
> +	button-left-gpios = <&gpio0 4 GPIO_ACTIVE_LOW>;
> +	button-middle-gpios = <&gpio0 5 GPIO_ACTIVE_LOW>;
> +	button-right-gpios = <&gpio0 6 GPIO_ACTIVE_LOW>;
> +};
> -- 
> 2.13.5
> 
> --
> To unsubscribe from this list: send the line "unsubscribe devicetree" 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] 9+ messages in thread

* Re: [PATCH 4/5] input: mouse: Convert GPIO mouse to use descriptors
  2017-09-17 11:14 ` [PATCH 4/5] input: mouse: Convert GPIO mouse to use descriptors Linus Walleij
@ 2017-09-21 21:18   ` Dmitry Torokhov
  0 siblings, 0 replies; 9+ messages in thread
From: Dmitry Torokhov @ 2017-09-21 21:18 UTC (permalink / raw)
  To: Linus Walleij; +Cc: linux-input, Hans-Christian Noren Egtvedt

Hi Linus,

On Sun, Sep 17, 2017 at 01:14:44PM +0200, Linus Walleij wrote:
> This converts the GPIO mouse to use descriptors and
> fwnode properties. The polarity settings go out the window
> since GPIO descriptor already know about polarity so this
> should be configured in device tree or ACPI or similar.
> 
> Set scanning interval by default to 50ms if not found as
> a property on the device.
> 
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---
>  drivers/input/mouse/gpio_mouse.c | 171 ++++++++++++++-------------------------
>  1 file changed, 60 insertions(+), 111 deletions(-)
> 
> diff --git a/drivers/input/mouse/gpio_mouse.c b/drivers/input/mouse/gpio_mouse.c
> index d1914bb3531f..7bd2a8ac6e6e 100644
> --- a/drivers/input/mouse/gpio_mouse.c
> +++ b/drivers/input/mouse/gpio_mouse.c
> @@ -2,6 +2,7 @@
>   * Driver for simulating a mouse on GPIO lines.
>   *
>   * Copyright (C) 2007 Atmel Corporation
> + * Copyright (C) 2017 Linus Walleij <linus.walleij@linaro.org>
>   *
>   * This program is free software; you can redistribute it and/or modify
>   * it under the terms of the GNU General Public License version 2 as
> @@ -11,24 +12,12 @@
>  #include <linux/module.h>
>  #include <linux/platform_device.h>
>  #include <linux/input-polldev.h>
> -#include <linux/gpio.h>
> -
> -#define GPIO_MOUSE_POLARITY_ACT_HIGH	0x00
> -#define GPIO_MOUSE_POLARITY_ACT_LOW	0x01
> -
> -#define GPIO_MOUSE_PIN_UP	0
> -#define GPIO_MOUSE_PIN_DOWN	1
> -#define GPIO_MOUSE_PIN_LEFT	2
> -#define GPIO_MOUSE_PIN_RIGHT	3
> -#define GPIO_MOUSE_PIN_BLEFT	4
> -#define GPIO_MOUSE_PIN_BMIDDLE	5
> -#define GPIO_MOUSE_PIN_BRIGHT	6
> -#define GPIO_MOUSE_PIN_MAX	7
> +#include <linux/gpio/consumer.h>
> +#include <linux/property.h>
>  
>  /**
>   * struct gpio_mouse
> - * @scan_ms: integer in ms specifying the scan periode.
> - * @polarity: Pin polarity, active high or low.
> + * @scan_ms: the scan interval in milliseconds.
>   * @up: GPIO line for up value.
>   * @down: GPIO line for down value.
>   * @left: GPIO line for left value.
> @@ -36,29 +25,20 @@
>   * @bleft: GPIO line for left button.
>   * @bmiddle: GPIO line for middle button.
>   * @bright: GPIO line for right button.
> - * @pins: GPIO line numbers used for the mouse.
>   *
>   * This struct must be added to the platform_device in the board code.
>   * It is used by the gpio_mouse driver to setup GPIO lines and to
>   * calculate mouse movement.
>   */
>  struct gpio_mouse {
> -	int scan_ms;
> -	int polarity;
> -
> -	union {
> -		struct {
> -			int up;
> -			int down;
> -			int left;
> -			int right;
> -
> -			int bleft;
> -			int bmiddle;
> -			int bright;
> -		};
> -		int pins[GPIO_MOUSE_PIN_MAX];
> -	};
> +	u32 scan_ms;
> +	struct gpio_desc *up;
> +	struct gpio_desc *down;
> +	struct gpio_desc *left;
> +	struct gpio_desc *right;
> +	struct gpio_desc *bleft;
> +	struct gpio_desc *bmiddle;
> +	struct gpio_desc *bright;
>  };
>  
>  /*
> @@ -71,20 +51,18 @@ static void gpio_mouse_scan(struct input_polled_dev *dev)
>  	struct input_dev *input = dev->input;
>  	int x, y;
>  
> -	if (gpio->bleft >= 0)
> +	if (!IS_ERR(gpio->bleft))
>  		input_report_key(input, BTN_LEFT,
> -				gpio_get_value(gpio->bleft) ^ gpio->polarity);
> -	if (gpio->bmiddle >= 0)
> +				 gpiod_get_value(gpio->bleft));
> +	if (!IS_ERR(gpio->bmiddle))
>  		input_report_key(input, BTN_MIDDLE,
> -				gpio_get_value(gpio->bmiddle) ^ gpio->polarity);
> -	if (gpio->bright >= 0)
> +				 gpiod_get_value(gpio->bmiddle));
> +	if (!IS_ERR(gpio->bright))
>  		input_report_key(input, BTN_RIGHT,
> -				gpio_get_value(gpio->bright) ^ gpio->polarity);
> +				 gpiod_get_value(gpio->bright));
>  
> -	x = (gpio_get_value(gpio->right) ^ gpio->polarity)
> -		- (gpio_get_value(gpio->left) ^ gpio->polarity);
> -	y = (gpio_get_value(gpio->down) ^ gpio->polarity)
> -		- (gpio_get_value(gpio->up) ^ gpio->polarity);
> +	x = gpiod_get_value(gpio->right) - gpiod_get_value(gpio->left);
> +	y = gpiod_get_value(gpio->down) - gpiod_get_value(gpio->up);
>  
>  	input_report_rel(input, REL_X, x);
>  	input_report_rel(input, REL_Y, y);
> @@ -97,52 +75,45 @@ static int gpio_mouse_probe(struct platform_device *pdev)
>  	struct gpio_mouse *gmouse;
>  	struct input_polled_dev *input_poll;
>  	struct input_dev *input;
> -	int pin, i;
> -	int error;
> +	int ret;
>  
>  	gmouse = devm_kzalloc(dev, sizeof(*gmouse), GFP_KERNEL);
>  	if (!gmouse)
>  		return -ENOMEM;
>  
> -	if (gmouse->scan_ms < 0) {
> -		dev_err(&pdev->dev, "invalid scan time\n");
> -		error = -EINVAL;
> -		goto out;
> -	}
> -
> -	for (i = 0; i < GPIO_MOUSE_PIN_MAX; i++) {
> -		pin = gmouse->pins[i];
> -
> -		if (pin < 0) {
> -
> -			if (i <= GPIO_MOUSE_PIN_RIGHT) {
> -				/* Mouse direction is required. */
> -				dev_err(&pdev->dev,
> -					"missing GPIO for directions\n");
> -				error = -EINVAL;
> -				goto out_free_gpios;
> -			}
> -
> -			if (i == GPIO_MOUSE_PIN_BLEFT)
> -				dev_dbg(&pdev->dev, "no left button defined\n");
> -
> -		} else {
> -			error = gpio_request(pin, "gpio_mouse");
> -			if (error) {
> -				dev_err(&pdev->dev, "fail %d pin (%d idx)\n",
> -					pin, i);
> -				goto out_free_gpios;
> -			}
> -
> -			gpio_direction_input(pin);
> -		}
> +	/* Assign some default scanning time */
> +	ret = device_property_read_u32(dev, "scan-interval",
> +				       &gmouse->scan_ms);
> +	if (ret || (gmouse->scan_ms == 0)) {
> +		dev_err(dev, "invalid scan time, set to 50 ms\n");
> +		gmouse->scan_ms = 50;
>  	}
>  
> -	input_poll = input_allocate_polled_device();
> +	/*
> +	 * These are compulsory GPIOs so bail out if any of them are
> +	 * not found.
> +	 */
> +	gmouse->up = devm_gpiod_get(dev, "up", GPIOD_IN);
> +	if (IS_ERR(gmouse->up))
> +		return PTR_ERR(gmouse->up);
> +	gmouse->down = devm_gpiod_get(dev, "down", GPIOD_IN);
> +	if (IS_ERR(gmouse->down))
> +		return PTR_ERR(gmouse->down);
> +	gmouse->left = devm_gpiod_get(dev, "left", GPIOD_IN);
> +	if (IS_ERR(gmouse->left))
> +		return PTR_ERR(gmouse->left);
> +	gmouse->right = devm_gpiod_get(dev, "right", GPIOD_IN);
> +	if (IS_ERR(gmouse->right))
> +		return PTR_ERR(gmouse->right);
> +
> +	gmouse->bleft = devm_gpiod_get(dev, "button-left", GPIOD_IN);
> +	gmouse->bmiddle = devm_gpiod_get(dev, "button-middle", GPIOD_IN);
> +	gmouse->bright = devm_gpiod_get(dev, "button-right", GPIOD_IN);

Why not devm_gpiod_get_optional() for these 3? You do want to catch
-EPROBE_DEFER at least.

> +
> +	input_poll = devm_input_allocate_polled_device(dev);
>  	if (!input_poll) {
> -		dev_err(&pdev->dev, "not enough memory for input device\n");
> -		error = -ENOMEM;
> -		goto out_free_gpios;
> +		dev_err(dev, "not enough memory for input device\n");
> +		return -ENOMEM;
>  	}
>  
>  	platform_set_drvdata(pdev, input_poll);
> @@ -166,48 +137,26 @@ static int gpio_mouse_probe(struct platform_device *pdev)
>  	if (gmouse->bright >= 0)
>  		input_set_capability(input, EV_KEY, BTN_RIGHT);
>  
> -	error = input_register_polled_device(input_poll);
> -	if (error) {
> -		dev_err(&pdev->dev, "could not register input device\n");
> -		goto out_free_polldev;
> +	ret = input_register_polled_device(input_poll);
> +	if (ret) {
> +		dev_err(dev, "could not register input device\n");
> +		return ret;
>  	}
>  
> -	dev_dbg(&pdev->dev, "%d ms scan time, buttons: %s%s%s\n",
> -			gmouse->scan_ms,
> -			gmouse->bleft < 0 ? "" : "left ",
> -			gmouse->bmiddle < 0 ? "" : "middle ",
> -			gmouse->bright < 0 ? "" : "right");
> +	dev_dbg(dev, "%d ms scan time, buttons: %s%s%s\n",
> +		gmouse->scan_ms,
> +		IS_ERR(gmouse->bleft) ? "" : "left ",
> +		IS_ERR(gmouse->bmiddle) ? "" : "middle ",
> +		IS_ERR(gmouse->bright) ? "" : "right");
>  
>  	return 0;
> -
> - out_free_polldev:
> -	input_free_polled_device(input_poll);
> -
> - out_free_gpios:
> -	while (--i >= 0) {
> -		pin = gmouse->pins[i];
> -		if (pin)
> -			gpio_free(pin);
> -	}
> - out:
> -	return error;
>  }
>  
>  static int gpio_mouse_remove(struct platform_device *pdev)
>  {
>  	struct input_polled_dev *input = platform_get_drvdata(pdev);
> -	struct gpio_mouse *gmouse = input->private;
> -	int pin, i;
>  
>  	input_unregister_polled_device(input);

With devm you do not need to keep unregister.

> -	input_free_polled_device(input);
> -
> -	for (i = 0; i < GPIO_MOUSE_PIN_MAX; i++) {
> -		pin = gmouse->pins[i];
> -		if (pin >= 0)
> -			gpio_free(pin);
> -	}
> -
>  	return 0;
>  }
>  
> -- 
> 2.13.5
> 

Thanks.

-- 
Dmitry

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

end of thread, other threads:[~2017-09-21 21:18 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-17 11:14 [PATCH 0/5] Input: make the GPIO mouse useful Linus Walleij
2017-09-17 11:14 ` [PATCH 1/5] input: mouse: Kill off platform data for GPIO mouse Linus Walleij
2017-09-17 11:14 ` [PATCH 2/5] input: mouse: Rename GPIO mouse variables Linus Walleij
2017-09-17 11:14 ` [PATCH 3/5] input: mouse: Add DT bindings for GPIO mice Linus Walleij
2017-09-20 20:53   ` Rob Herring
2017-09-17 11:14 ` [PATCH 4/5] input: mouse: Convert GPIO mouse to use descriptors Linus Walleij
2017-09-21 21:18   ` Dmitry Torokhov
2017-09-17 11:14 ` [PATCH 5/5] input: mouse: Add device tree probing to GPIO mouse Linus Walleij
2017-09-17 12:44 ` [PATCH 0/5] Input: make the GPIO mouse useful Hans-Christian Noren Egtvedt

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