linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: linux-input@vger.kernel.org
Cc: "Bartosz Golaszewski" <bgolaszewski@baylibre.com>,
	"Brian Masney" <masneyb@onstation.org>,
	"Jonathan Bakker" <xc-racer2@live.ca>,
	"Luca Weiss" <luca@z3ntu.xyz>,
	"Maximilian Luz" <luzmaximilian@gmail.com>,
	"Paweł Chmiel" <pawel.mikolaj.chmiel@gmail.com>,
	"Richard Fontana" <rfontana@redhat.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH 20/22] Input: bma150 - switch to using polled mode of input devices
Date: Thu, 17 Oct 2019 13:42:14 -0700	[thread overview]
Message-ID: <20191017204217.106453-21-dmitry.torokhov@gmail.com> (raw)
In-Reply-To: <20191017204217.106453-1-dmitry.torokhov@gmail.com>

We have added polled mode to the normal input devices with the intent of
retiring input_polled_dev. This converts bma150 driver to use the polling
mode of standard input devices and removes dependency on INPUT_POLLDEV.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---

 drivers/input/misc/Kconfig  |   1 -
 drivers/input/misc/bma150.c | 155 ++++++++++--------------------------
 2 files changed, 44 insertions(+), 112 deletions(-)

diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index e1309cb190e1..438ec07e3b62 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -100,7 +100,6 @@ config INPUT_ATMEL_CAPTOUCH
 config INPUT_BMA150
 	tristate "BMA150/SMB380 acceleration sensor support"
 	depends on I2C
-	select INPUT_POLLDEV
 	help
 	  Say Y here if you have Bosch Sensortec's BMA150 or SMB380
 	  acceleration sensor hooked to an I2C bus.
diff --git a/drivers/input/misc/bma150.c b/drivers/input/misc/bma150.c
index d65b008a3c7a..a9d984da95f3 100644
--- a/drivers/input/misc/bma150.c
+++ b/drivers/input/misc/bma150.c
@@ -14,7 +14,6 @@
 #include <linux/module.h>
 #include <linux/i2c.h>
 #include <linux/input.h>
-#include <linux/input-polldev.h>
 #include <linux/interrupt.h>
 #include <linux/delay.h>
 #include <linux/slab.h>
@@ -123,7 +122,6 @@
 
 struct bma150_data {
 	struct i2c_client *client;
-	struct input_polled_dev *input_polled;
 	struct input_dev *input;
 	u8 mode;
 };
@@ -336,13 +334,16 @@ static irqreturn_t bma150_irq_thread(int irq, void *dev)
 	return IRQ_HANDLED;
 }
 
-static void bma150_poll(struct input_polled_dev *dev)
+static void bma150_poll(struct input_dev *input)
 {
-	bma150_report_xyz(dev->private);
+	struct bma150_data *bma150 = input_get_drvdata(input);
+
+	bma150_report_xyz(bma150);
 }
 
-static int bma150_open(struct bma150_data *bma150)
+static int bma150_open(struct input_dev *input)
 {
+	struct bma150_data *bma150 = input_get_drvdata(input);
 	int error;
 
 	error = pm_runtime_get_sync(&bma150->client->dev);
@@ -362,44 +363,18 @@ static int bma150_open(struct bma150_data *bma150)
 	return 0;
 }
 
-static void bma150_close(struct bma150_data *bma150)
+static void bma150_close(struct input_dev *input)
 {
+	struct bma150_data *bma150 = input_get_drvdata(input);
+
 	pm_runtime_put_sync(&bma150->client->dev);
 
 	if (bma150->mode != BMA150_MODE_SLEEP)
 		bma150_set_mode(bma150, BMA150_MODE_SLEEP);
 }
 
-static int bma150_irq_open(struct input_dev *input)
-{
-	struct bma150_data *bma150 = input_get_drvdata(input);
-
-	return bma150_open(bma150);
-}
-
-static void bma150_irq_close(struct input_dev *input)
-{
-	struct bma150_data *bma150 = input_get_drvdata(input);
-
-	bma150_close(bma150);
-}
-
-static void bma150_poll_open(struct input_polled_dev *ipoll_dev)
-{
-	struct bma150_data *bma150 = ipoll_dev->private;
-
-	bma150_open(bma150);
-}
-
-static void bma150_poll_close(struct input_polled_dev *ipoll_dev)
-{
-	struct bma150_data *bma150 = ipoll_dev->private;
-
-	bma150_close(bma150);
-}
-
 static int bma150_initialize(struct bma150_data *bma150,
-				       const struct bma150_cfg *cfg)
+			     const struct bma150_cfg *cfg)
 {
 	int error;
 
@@ -439,78 +414,14 @@ static int bma150_initialize(struct bma150_data *bma150,
 	return bma150_set_mode(bma150, BMA150_MODE_SLEEP);
 }
 
-static void bma150_init_input_device(struct input_dev *idev)
-{
-	idev->name = BMA150_DRIVER;
-	idev->phys = BMA150_DRIVER "/input0";
-	idev->id.bustype = BUS_I2C;
-
-	idev->evbit[0] = BIT_MASK(EV_ABS);
-	input_set_abs_params(idev, ABS_X, ABSMIN_ACC_VAL, ABSMAX_ACC_VAL, 0, 0);
-	input_set_abs_params(idev, ABS_Y, ABSMIN_ACC_VAL, ABSMAX_ACC_VAL, 0, 0);
-	input_set_abs_params(idev, ABS_Z, ABSMIN_ACC_VAL, ABSMAX_ACC_VAL, 0, 0);
-}
-
-static int bma150_register_input_device(struct bma150_data *bma150)
-{
-	struct input_dev *idev;
-	int error;
-
-	idev = devm_input_allocate_device(&bma150->client->dev);
-	if (!idev)
-		return -ENOMEM;
-
-	bma150_init_input_device(idev);
-
-	idev->open = bma150_irq_open;
-	idev->close = bma150_irq_close;
-	input_set_drvdata(idev, bma150);
-
-	bma150->input = idev;
-
-	error = input_register_device(idev);
-	if (error)
-		return error;
-
-	return 0;
-}
-
-static int bma150_register_polled_device(struct bma150_data *bma150)
-{
-	struct input_polled_dev *ipoll_dev;
-	int error;
-
-	ipoll_dev = devm_input_allocate_polled_device(&bma150->client->dev);
-	if (!ipoll_dev)
-		return -ENOMEM;
-
-	ipoll_dev->private = bma150;
-	ipoll_dev->open = bma150_poll_open;
-	ipoll_dev->close = bma150_poll_close;
-	ipoll_dev->poll = bma150_poll;
-	ipoll_dev->poll_interval = BMA150_POLL_INTERVAL;
-	ipoll_dev->poll_interval_min = BMA150_POLL_MIN;
-	ipoll_dev->poll_interval_max = BMA150_POLL_MAX;
-
-	bma150_init_input_device(ipoll_dev->input);
-
-	bma150->input_polled = ipoll_dev;
-	bma150->input = ipoll_dev->input;
-
-	error = input_register_polled_device(ipoll_dev);
-	if (error)
-		return error;
-
-	return 0;
-}
-
 static int bma150_probe(struct i2c_client *client,
-				  const struct i2c_device_id *id)
+			const struct i2c_device_id *id)
 {
 	const struct bma150_platform_data *pdata =
 			dev_get_platdata(&client->dev);
 	const struct bma150_cfg *cfg;
 	struct bma150_data *bma150;
+	struct input_dev *idev;
 	int chip_id;
 	int error;
 
@@ -550,11 +461,39 @@ static int bma150_probe(struct i2c_client *client,
 	if (error)
 		return error;
 
-	if (client->irq > 0) {
-		error = bma150_register_input_device(bma150);
+	idev = devm_input_allocate_device(&bma150->client->dev);
+	if (!idev)
+		return -ENOMEM;
+
+	input_set_drvdata(idev, bma150);
+	bma150->input = idev;
+
+	idev->name = BMA150_DRIVER;
+	idev->phys = BMA150_DRIVER "/input0";
+	idev->id.bustype = BUS_I2C;
+
+	idev->open = bma150_open;
+	idev->close = bma150_close;
+
+	input_set_abs_params(idev, ABS_X, ABSMIN_ACC_VAL, ABSMAX_ACC_VAL, 0, 0);
+	input_set_abs_params(idev, ABS_Y, ABSMIN_ACC_VAL, ABSMAX_ACC_VAL, 0, 0);
+	input_set_abs_params(idev, ABS_Z, ABSMIN_ACC_VAL, ABSMAX_ACC_VAL, 0, 0);
+
+	if (client->irq <= 0) {
+		error = input_setup_polling(idev, bma150_poll);
 		if (error)
 			return error;
 
+		input_set_poll_interval(idev, BMA150_POLL_INTERVAL);
+		input_set_min_poll_interval(idev, BMA150_POLL_MIN);
+		input_set_max_poll_interval(idev, BMA150_POLL_MAX);
+	}
+
+	error = input_register_device(idev);
+	if (error)
+		return error;
+
+	if (client->irq > 0) {
 		error = devm_request_threaded_irq(&client->dev, client->irq,
 					NULL, bma150_irq_thread,
 					IRQF_TRIGGER_RISING | IRQF_ONESHOT,
@@ -565,10 +504,6 @@ static int bma150_probe(struct i2c_client *client,
 				client->irq, error);
 			return error;
 		}
-	} else {
-		error = bma150_register_polled_device(bma150);
-		if (error)
-			return error;
 	}
 
 	i2c_set_clientdata(client, bma150);
@@ -585,8 +520,7 @@ static int bma150_remove(struct i2c_client *client)
 	return 0;
 }
 
-#ifdef CONFIG_PM
-static int bma150_suspend(struct device *dev)
+static int __maybe_unused bma150_suspend(struct device *dev)
 {
 	struct i2c_client *client = to_i2c_client(dev);
 	struct bma150_data *bma150 = i2c_get_clientdata(client);
@@ -594,14 +528,13 @@ static int bma150_suspend(struct device *dev)
 	return bma150_set_mode(bma150, BMA150_MODE_SLEEP);
 }
 
-static int bma150_resume(struct device *dev)
+static int __maybe_unused bma150_resume(struct device *dev)
 {
 	struct i2c_client *client = to_i2c_client(dev);
 	struct bma150_data *bma150 = i2c_get_clientdata(client);
 
 	return bma150_set_mode(bma150, BMA150_MODE_NORMAL);
 }
-#endif
 
 static UNIVERSAL_DEV_PM_OPS(bma150_pm, bma150_suspend, bma150_resume, NULL);
 
-- 
2.23.0.866.gb869b98d4c-goog


  parent reply	other threads:[~2019-10-17 20:43 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-17 20:41 [PATCH 00/22] Stop using input_polled_dev in polling drivers Dmitry Torokhov
2019-10-17 20:41 ` [PATCH 01/22] Input: raspberrypi-ts - switch to using polled mode of input devices Dmitry Torokhov
2019-10-17 20:41 ` [PATCH 02/22] Input: sur40 " Dmitry Torokhov
2019-10-17 20:41 ` [PATCH 03/22] Input: ts4800-ts " Dmitry Torokhov
2019-10-17 20:41 ` [PATCH 04/22] Input: tsc6507x-ts " Dmitry Torokhov
2019-10-17 20:41 ` [PATCH 05/22] Input: adc-keys " Dmitry Torokhov
2019-10-17 20:42 ` [PATCH 06/22] Input: clps711x-keypad " Dmitry Torokhov
2019-10-17 20:42 ` [PATCH 07/22] Input: jornada680_kbd " Dmitry Torokhov
2019-10-17 20:42 ` [PATCH 08/22] Input: gpio_keys_polled " Dmitry Torokhov
2019-10-17 20:42 ` [PATCH 09/22] Input: apanel " Dmitry Torokhov
2019-10-21 20:05   ` Sven Van Asbroeck
2019-10-21 21:27     ` Dmitry Torokhov
2019-10-22 13:21       ` Sven Van Asbroeck
2019-10-17 20:42 ` [PATCH 10/22] Input: wistron_btns " Dmitry Torokhov
2019-10-17 20:42 ` [PATCH 11/22] Input: cobalt_btns - convert to use managed resources Dmitry Torokhov
2019-10-17 20:42 ` [PATCH 12/22] Input: cobalt_btns - switch to using polled mode of input devices Dmitry Torokhov
2019-10-17 20:42 ` [PATCH 13/22] Input: sgi_btns - switch to using managed resources Dmitry Torokhov
2019-10-17 20:42 ` [PATCH 14/22] Input: sgi_btns - switch to using polled mode of input devices Dmitry Torokhov
2019-10-17 20:42 ` [PATCH 15/22] Input: rb532_button - switch to using managed resources Dmitry Torokhov
2019-10-17 20:42 ` [PATCH 16/22] Input: rb532_button - switch to using polled mode of input devices Dmitry Torokhov
2019-10-17 20:42 ` [PATCH 17/22] Input: gpio_decoder " Dmitry Torokhov
2019-10-17 20:42 ` [PATCH 18/22] Input: mma8450 " Dmitry Torokhov
2019-10-17 20:42 ` [PATCH 19/22] Input: bma150 - use managed resources helpers Dmitry Torokhov
2019-10-17 20:42 ` Dmitry Torokhov [this message]
2019-10-17 20:42 ` [PATCH 21/22] Input: kxtj9 - switch to using managed resources Dmitry Torokhov
2019-10-17 20:42 ` [PATCH 22/22] Input: kxtj9 - switch to using polled mode of input devices Dmitry Torokhov
2019-10-18  8:44 ` [PATCH 00/22] Stop using input_polled_dev in polling drivers Andy Shevchenko
2019-10-21  8:03   ` Marco Felsch

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=20191017204217.106453-21-dmitry.torokhov@gmail.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=bgolaszewski@baylibre.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luca@z3ntu.xyz \
    --cc=luzmaximilian@gmail.com \
    --cc=masneyb@onstation.org \
    --cc=pawel.mikolaj.chmiel@gmail.com \
    --cc=rfontana@redhat.com \
    --cc=xc-racer2@live.ca \
    /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;
as well as URLs for NNTP newsgroup(s).