linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Walleij <linus.walleij@linaro.org>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>, linux-input@vger.kernel.org
Cc: Nikita Travkin <nikita@trvn.ru>,
	Michael Srba <Michael.Srba@seznam.cz>,
	Linus Walleij <linus.walleij@linaro.org>
Subject: [PATCH 2/5] Input: zinitix - Add dev variable in state
Date: Sun, 10 Apr 2022 14:00:56 +0200	[thread overview]
Message-ID: <20220410120059.2583849-2-linus.walleij@linaro.org> (raw)
In-Reply-To: <20220410120059.2583849-1-linus.walleij@linaro.org>

To avoid several steps of dereferencing the struct device from
the client, add a struct device *dev pointer to the state
container so we can easily get to the struct device. This makes
the code more compact and easier to read.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/input/touchscreen/zinitix.c | 37 +++++++++++++++--------------
 1 file changed, 19 insertions(+), 18 deletions(-)

diff --git a/drivers/input/touchscreen/zinitix.c b/drivers/input/touchscreen/zinitix.c
index cd13075ae3ab..11af1264cafa 100644
--- a/drivers/input/touchscreen/zinitix.c
+++ b/drivers/input/touchscreen/zinitix.c
@@ -142,6 +142,7 @@ struct touch_event {
 
 struct bt541_ts_data {
 	struct i2c_client *client;
+	struct device *dev;
 	struct input_dev *input_dev;
 	struct touchscreen_properties prop;
 	struct regulator_bulk_data supplies[2];
@@ -198,13 +199,13 @@ static int zinitix_init_touch(struct bt541_ts_data *bt541)
 
 	error = zinitix_write_cmd(client, BT541_SWRESET_CMD);
 	if (error) {
-		dev_err(&client->dev, "Failed to write reset command\n");
+		dev_err(bt541->dev, "Failed to write reset command\n");
 		return error;
 	}
 
 	error = zinitix_write_u16(client, BT541_INT_ENABLE_FLAG, 0x0);
 	if (error) {
-		dev_err(&client->dev,
+		dev_err(bt541->dev,
 			"Failed to reset interrupt enable flag\n");
 		return error;
 	}
@@ -252,7 +253,7 @@ static int zinitix_init_touch(struct bt541_ts_data *bt541)
 
 static int zinitix_init_regulators(struct bt541_ts_data *bt541)
 {
-	struct device *dev = &bt541->client->dev;
+	struct device *dev = bt541->dev;
 	int error;
 
 	/*
@@ -286,7 +287,7 @@ static int zinitix_send_power_on_sequence(struct bt541_ts_data *bt541)
 
 	error = zinitix_write_u16(client, 0xc000, 0x0001);
 	if (error) {
-		dev_err(&client->dev,
+		dev_err(bt541->dev,
 			"Failed to send power sequence(vendor cmd enable)\n");
 		return error;
 	}
@@ -294,7 +295,7 @@ static int zinitix_send_power_on_sequence(struct bt541_ts_data *bt541)
 
 	error = zinitix_write_cmd(client, 0xc004);
 	if (error) {
-		dev_err(&client->dev,
+		dev_err(bt541->dev,
 			"Failed to send power sequence (intn clear)\n");
 		return error;
 	}
@@ -302,7 +303,7 @@ static int zinitix_send_power_on_sequence(struct bt541_ts_data *bt541)
 
 	error = zinitix_write_u16(client, 0xc002, 0x0001);
 	if (error) {
-		dev_err(&client->dev,
+		dev_err(bt541->dev,
 			"Failed to send power sequence (nvm init)\n");
 		return error;
 	}
@@ -310,7 +311,7 @@ static int zinitix_send_power_on_sequence(struct bt541_ts_data *bt541)
 
 	error = zinitix_write_u16(client, 0xc001, 0x0001);
 	if (error) {
-		dev_err(&client->dev,
+		dev_err(bt541->dev,
 			"Failed to send power sequence (program start)\n");
 		return error;
 	}
@@ -353,7 +354,6 @@ static void zinitix_report_finger(struct bt541_ts_data *bt541, int slot,
 static irqreturn_t zinitix_ts_irq_handler(int irq, void *bt541_handler)
 {
 	struct bt541_ts_data *bt541 = bt541_handler;
-	struct i2c_client *client = bt541->client;
 	struct touch_event touch_event;
 	unsigned long finger_mask;
 	int error;
@@ -364,7 +364,7 @@ static irqreturn_t zinitix_ts_irq_handler(int irq, void *bt541_handler)
 	error = zinitix_read_data(bt541->client, BT541_POINT_STATUS_REG,
 				  &touch_event, sizeof(struct touch_event));
 	if (error) {
-		dev_err(&client->dev, "Failed to read in touchpoint struct\n");
+		dev_err(bt541->dev, "Failed to read in touchpoint struct\n");
 		goto out;
 	}
 
@@ -392,7 +392,7 @@ static int zinitix_start(struct bt541_ts_data *bt541)
 	error = regulator_bulk_enable(ARRAY_SIZE(bt541->supplies),
 				      bt541->supplies);
 	if (error) {
-		dev_err(&bt541->client->dev,
+		dev_err(bt541->dev,
 			"Failed to enable regulators: %d\n", error);
 		return error;
 	}
@@ -401,14 +401,14 @@ static int zinitix_start(struct bt541_ts_data *bt541)
 
 	error = zinitix_send_power_on_sequence(bt541);
 	if (error) {
-		dev_err(&bt541->client->dev,
+		dev_err(bt541->dev,
 			"Error while sending power-on sequence: %d\n", error);
 		return error;
 	}
 
 	error = zinitix_init_touch(bt541);
 	if (error) {
-		dev_err(&bt541->client->dev,
+		dev_err(bt541->dev,
 			"Error while configuring touch IC\n");
 		return error;
 	}
@@ -427,7 +427,7 @@ static int zinitix_stop(struct bt541_ts_data *bt541)
 	error = regulator_bulk_disable(ARRAY_SIZE(bt541->supplies),
 				       bt541->supplies);
 	if (error) {
-		dev_err(&bt541->client->dev,
+		dev_err(bt541->dev,
 			"Failed to disable regulators: %d\n", error);
 		return error;
 	}
@@ -454,9 +454,9 @@ static int zinitix_init_input_dev(struct bt541_ts_data *bt541)
 	struct input_dev *input_dev;
 	int error;
 
-	input_dev = devm_input_allocate_device(&bt541->client->dev);
+	input_dev = devm_input_allocate_device(bt541->dev);
 	if (!input_dev) {
-		dev_err(&bt541->client->dev,
+		dev_err(bt541->dev,
 			"Failed to allocate input device.");
 		return -ENOMEM;
 	}
@@ -477,7 +477,7 @@ static int zinitix_init_input_dev(struct bt541_ts_data *bt541)
 
 	touchscreen_parse_properties(input_dev, true, &bt541->prop);
 	if (!bt541->prop.max_x || !bt541->prop.max_y) {
-		dev_err(&bt541->client->dev,
+		dev_err(bt541->dev,
 			"Touchscreen-size-x and/or touchscreen-size-y not set in dts\n");
 		return -EINVAL;
 	}
@@ -485,14 +485,14 @@ static int zinitix_init_input_dev(struct bt541_ts_data *bt541)
 	error = input_mt_init_slots(input_dev, MAX_SUPPORTED_FINGER_NUM,
 				    INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED);
 	if (error) {
-		dev_err(&bt541->client->dev,
+		dev_err(bt541->dev,
 			"Failed to initialize MT slots: %d", error);
 		return error;
 	}
 
 	error = input_register_device(input_dev);
 	if (error) {
-		dev_err(&bt541->client->dev,
+		dev_err(bt541->dev,
 			"Failed to register input device: %d", error);
 		return error;
 	}
@@ -517,6 +517,7 @@ static int zinitix_ts_probe(struct i2c_client *client)
 		return -ENOMEM;
 
 	bt541->client = client;
+	bt541->dev = dev;
 	i2c_set_clientdata(client, bt541);
 
 	error = zinitix_init_regulators(bt541);
-- 
2.35.1


  reply	other threads:[~2022-04-10 12:03 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-10 12:00 [PATCH 1/5] Input: zinitix - Helper dev variable in probe() Linus Walleij
2022-04-10 12:00 ` Linus Walleij [this message]
2022-05-27  5:37   ` [PATCH 2/5] Input: zinitix - Add dev variable in state Dmitry Torokhov
2022-05-27 13:31     ` Linus Walleij
2022-04-10 12:00 ` [PATCH 3/5] Input: zinitix - Rename defines ZINITIX_* Linus Walleij
2022-05-27  5:48   ` Dmitry Torokhov
2022-04-10 12:00 ` [PATCH 4/5] Input: zinitix - Read and cache device version numbers Linus Walleij
2022-05-27  5:47   ` Dmitry Torokhov
2022-04-10 12:00 ` [PATCH 5/5] Input: zinitix - Support calibration Linus Walleij
2022-05-27  5:48   ` Dmitry Torokhov
2022-05-24 12:08 ` [PATCH 1/5] Input: zinitix - Helper dev variable in probe() Linus Walleij
2022-05-27  5:36 ` Dmitry Torokhov
2022-05-27 13:30   ` Linus Walleij

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=20220410120059.2583849-2-linus.walleij@linaro.org \
    --to=linus.walleij@linaro.org \
    --cc=Michael.Srba@seznam.cz \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=nikita@trvn.ru \
    /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).