diff mbox series

[2/5] Input: zinitix - Add dev variable in state

Message ID 20220410120059.2583849-2-linus.walleij@linaro.org
State New
Headers show
Series [1/5] Input: zinitix - Helper dev variable in probe() | expand

Commit Message

Linus Walleij April 10, 2022, noon UTC
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(-)

Comments

Dmitry Torokhov May 27, 2022, 5:37 a.m. UTC | #1
On Sun, Apr 10, 2022 at 02:00:56PM +0200, Linus Walleij wrote:
> 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.

Same concern as the previous patch...

Thanks.
Linus Walleij May 27, 2022, 1:31 p.m. UTC | #2
On Fri, May 27, 2022 at 7:37 AM Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
> On Sun, Apr 10, 2022 at 02:00:56PM +0200, Linus Walleij wrote:
> > 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.
>
> Same concern as the previous patch...

No problem, I drop this too.

Yours,
Linus Walleij
diff mbox series

Patch

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