Commit 7e168b81 authored by Dmitry Torokhov's avatar Dmitry Torokhov

Input: zforce_ts - use dev_err_probe() where appropriate

Use dev_err_probe() helper to log deferrals in the devices_deferred
debugfs file and avoid extra messages in the logs.

Also rename "ret" variables holding error codes only to "error".

Tested-by: Andreas Kemnade <andreas@kemnade.info> # Tolino Shine2HD
Link: https://lore.kernel.org/r/20240824055047.1706392-13-dmitry.torokhov@gmail.comSigned-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent c4a83492
...@@ -171,7 +171,7 @@ static int zforce_send_wait(struct zforce_ts *ts, const char *buf, int len) ...@@ -171,7 +171,7 @@ static int zforce_send_wait(struct zforce_ts *ts, const char *buf, int len)
ret = i2c_master_send(client, buf, len); ret = i2c_master_send(client, buf, len);
if (ret < 0) { if (ret < 0) {
dev_err(&client->dev, "i2c send data request error: %d\n", ret); dev_err(&client->dev, "i2c send data request error: %d\n", ret);
return ret;; return ret;
} }
dev_dbg(&client->dev, "waiting for result for command 0x%x\n", buf[2]); dev_dbg(&client->dev, "waiting for result for command 0x%x\n", buf[2]);
...@@ -187,7 +187,7 @@ static int zforce_command_wait(struct zforce_ts *ts, u8 cmd) ...@@ -187,7 +187,7 @@ static int zforce_command_wait(struct zforce_ts *ts, u8 cmd)
{ {
struct i2c_client *client = ts->client; struct i2c_client *client = ts->client;
char buf[3]; char buf[3];
int ret; int error;
dev_dbg(&client->dev, "%s: 0x%x\n", __func__, cmd); dev_dbg(&client->dev, "%s: 0x%x\n", __func__, cmd);
...@@ -195,10 +195,11 @@ static int zforce_command_wait(struct zforce_ts *ts, u8 cmd) ...@@ -195,10 +195,11 @@ static int zforce_command_wait(struct zforce_ts *ts, u8 cmd)
buf[1] = 1; /* data size, command only */ buf[1] = 1; /* data size, command only */
buf[2] = cmd; buf[2] = cmd;
ret = zforce_send_wait(ts, &buf[0], ARRAY_SIZE(buf)); error = zforce_send_wait(ts, &buf[0], ARRAY_SIZE(buf));
if (ret < 0) { if (error) {
dev_err(&client->dev, "i2c send data request error: %d\n", ret); dev_err(&client->dev, "i2c send data request error: %d\n",
return ret; error);
return error;
} }
return 0; return 0;
...@@ -246,40 +247,40 @@ static int zforce_setconfig(struct zforce_ts *ts, char b1) ...@@ -246,40 +247,40 @@ static int zforce_setconfig(struct zforce_ts *ts, char b1)
static int zforce_start(struct zforce_ts *ts) static int zforce_start(struct zforce_ts *ts)
{ {
struct i2c_client *client = ts->client; struct i2c_client *client = ts->client;
int ret; int error;
dev_dbg(&client->dev, "starting device\n"); dev_dbg(&client->dev, "starting device\n");
ret = zforce_command_wait(ts, COMMAND_INITIALIZE); error = zforce_command_wait(ts, COMMAND_INITIALIZE);
if (ret) { if (error) {
dev_err(&client->dev, "Unable to initialize, %d\n", ret); dev_err(&client->dev, "Unable to initialize, %d\n", error);
return ret; return error;
} }
ret = zforce_resolution(ts, ts->prop.max_x, ts->prop.max_y); error = zforce_resolution(ts, ts->prop.max_x, ts->prop.max_y);
if (ret) { if (error) {
dev_err(&client->dev, "Unable to set resolution, %d\n", ret); dev_err(&client->dev, "Unable to set resolution, %d\n", error);
goto error; goto err_deactivate;
} }
ret = zforce_scan_frequency(ts, 10, 50, 50); error = zforce_scan_frequency(ts, 10, 50, 50);
if (ret) { if (error) {
dev_err(&client->dev, "Unable to set scan frequency, %d\n", dev_err(&client->dev, "Unable to set scan frequency, %d\n",
ret); error);
goto error; goto err_deactivate;
} }
ret = zforce_setconfig(ts, SETCONFIG_DUALTOUCH); error = zforce_setconfig(ts, SETCONFIG_DUALTOUCH);
if (ret) { if (error) {
dev_err(&client->dev, "Unable to set config\n"); dev_err(&client->dev, "Unable to set config\n");
goto error; goto err_deactivate;
} }
/* start sending touch events */ /* start sending touch events */
ret = zforce_command(ts, COMMAND_DATAREQUEST); error = zforce_command(ts, COMMAND_DATAREQUEST);
if (ret) { if (error) {
dev_err(&client->dev, "Unable to request data\n"); dev_err(&client->dev, "Unable to request data\n");
goto error; goto err_deactivate;
} }
/* /*
...@@ -290,24 +291,24 @@ static int zforce_start(struct zforce_ts *ts) ...@@ -290,24 +291,24 @@ static int zforce_start(struct zforce_ts *ts)
return 0; return 0;
error: err_deactivate:
zforce_command_wait(ts, COMMAND_DEACTIVATE); zforce_command_wait(ts, COMMAND_DEACTIVATE);
return ret; return error;
} }
static int zforce_stop(struct zforce_ts *ts) static int zforce_stop(struct zforce_ts *ts)
{ {
struct i2c_client *client = ts->client; struct i2c_client *client = ts->client;
int ret; int error;
dev_dbg(&client->dev, "stopping device\n"); dev_dbg(&client->dev, "stopping device\n");
/* Deactivates touch sensing and puts the device into sleep. */ /* Deactivates touch sensing and puts the device into sleep. */
ret = zforce_command_wait(ts, COMMAND_DEACTIVATE); error = zforce_command_wait(ts, COMMAND_DEACTIVATE);
if (ret != 0) { if (error) {
dev_err(&client->dev, "could not deactivate device, %d\n", dev_err(&client->dev, "could not deactivate device, %d\n",
ret); error);
return ret; return error;
} }
return 0; return 0;
...@@ -451,7 +452,7 @@ static irqreturn_t zforce_irq_thread(int irq, void *dev_id) ...@@ -451,7 +452,7 @@ static irqreturn_t zforce_irq_thread(int irq, void *dev_id)
{ {
struct zforce_ts *ts = dev_id; struct zforce_ts *ts = dev_id;
struct i2c_client *client = ts->client; struct i2c_client *client = ts->client;
int ret; int error;
u8 payload_buffer[FRAME_MAXSIZE]; u8 payload_buffer[FRAME_MAXSIZE];
u8 *payload; u8 *payload;
bool suspending; bool suspending;
...@@ -482,10 +483,10 @@ static irqreturn_t zforce_irq_thread(int irq, void *dev_id) ...@@ -482,10 +483,10 @@ static irqreturn_t zforce_irq_thread(int irq, void *dev_id)
* no IRQ any more) * no IRQ any more)
*/ */
do { do {
ret = zforce_read_packet(ts, payload_buffer); error = zforce_read_packet(ts, payload_buffer);
if (ret < 0) { if (error) {
dev_err(&client->dev, dev_err(&client->dev,
"could not read packet, ret: %d\n", ret); "could not read packet, ret: %d\n", error);
break; break;
} }
...@@ -570,20 +571,18 @@ static void zforce_input_close(struct input_dev *dev) ...@@ -570,20 +571,18 @@ static void zforce_input_close(struct input_dev *dev)
{ {
struct zforce_ts *ts = input_get_drvdata(dev); struct zforce_ts *ts = input_get_drvdata(dev);
struct i2c_client *client = ts->client; struct i2c_client *client = ts->client;
int ret; int error;
ret = zforce_stop(ts); error = zforce_stop(ts);
if (ret) if (error)
dev_warn(&client->dev, "stopping zforce failed\n"); dev_warn(&client->dev, "stopping zforce failed\n");
return;
} }
static int __zforce_suspend(struct zforce_ts *ts) static int __zforce_suspend(struct zforce_ts *ts)
{ {
struct i2c_client *client = ts->client; struct i2c_client *client = ts->client;
struct input_dev *input = ts->input; struct input_dev *input = ts->input;
int ret; int error;
guard(mutex)(&input->mutex); guard(mutex)(&input->mutex);
...@@ -596,9 +595,9 @@ static int __zforce_suspend(struct zforce_ts *ts) ...@@ -596,9 +595,9 @@ static int __zforce_suspend(struct zforce_ts *ts)
/* Need to start device, if not open, to be a wakeup source. */ /* Need to start device, if not open, to be a wakeup source. */
if (!input_device_enabled(input)) { if (!input_device_enabled(input)) {
ret = zforce_start(ts); error = zforce_start(ts);
if (ret) if (error)
return ret; return error;
} }
enable_irq_wake(client->irq); enable_irq_wake(client->irq);
...@@ -606,9 +605,9 @@ static int __zforce_suspend(struct zforce_ts *ts) ...@@ -606,9 +605,9 @@ static int __zforce_suspend(struct zforce_ts *ts)
dev_dbg(&client->dev, dev_dbg(&client->dev,
"suspend without being a wakeup source\n"); "suspend without being a wakeup source\n");
ret = zforce_stop(ts); error = zforce_stop(ts);
if (ret) if (error)
return ret; return error;
disable_irq(client->irq); disable_irq(client->irq);
} }
...@@ -639,7 +638,7 @@ static int zforce_resume(struct device *dev) ...@@ -639,7 +638,7 @@ static int zforce_resume(struct device *dev)
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct zforce_ts *ts = i2c_get_clientdata(client); struct zforce_ts *ts = i2c_get_clientdata(client);
struct input_dev *input = ts->input; struct input_dev *input = ts->input;
int ret; int error;
guard(mutex)(&input->mutex); guard(mutex)(&input->mutex);
...@@ -652,18 +651,18 @@ static int zforce_resume(struct device *dev) ...@@ -652,18 +651,18 @@ static int zforce_resume(struct device *dev)
/* need to stop device if it was not open on suspend */ /* need to stop device if it was not open on suspend */
if (!input_device_enabled(input)) { if (!input_device_enabled(input)) {
ret = zforce_stop(ts); error = zforce_stop(ts);
if (ret) if (error)
return ret; return error;
} }
} else if (input_device_enabled(input)) { } else if (input_device_enabled(input)) {
dev_dbg(&client->dev, "resume without being a wakeup source\n"); dev_dbg(&client->dev, "resume without being a wakeup source\n");
enable_irq(client->irq); enable_irq(client->irq);
ret = zforce_start(ts); error = zforce_start(ts);
if (ret < 0) if (error)
return ret; return error;
} }
return 0; return 0;
...@@ -699,7 +698,7 @@ static int zforce_probe(struct i2c_client *client) ...@@ -699,7 +698,7 @@ static int zforce_probe(struct i2c_client *client)
{ {
struct zforce_ts *ts; struct zforce_ts *ts;
struct input_dev *input_dev; struct input_dev *input_dev;
int ret; int error;
ts = devm_kzalloc(&client->dev, sizeof(struct zforce_ts), GFP_KERNEL); ts = devm_kzalloc(&client->dev, sizeof(struct zforce_ts), GFP_KERNEL);
if (!ts) if (!ts)
...@@ -707,22 +706,18 @@ static int zforce_probe(struct i2c_client *client) ...@@ -707,22 +706,18 @@ static int zforce_probe(struct i2c_client *client)
ts->gpio_rst = devm_gpiod_get_optional(&client->dev, "reset", ts->gpio_rst = devm_gpiod_get_optional(&client->dev, "reset",
GPIOD_OUT_HIGH); GPIOD_OUT_HIGH);
if (IS_ERR(ts->gpio_rst)) { error = PTR_ERR_OR_ZERO(ts->gpio_rst);
ret = PTR_ERR(ts->gpio_rst); if (error)
dev_err(&client->dev, return dev_err_probe(&client->dev, error,
"failed to request reset GPIO: %d\n", ret); "failed to request reset GPIO\n");
return ret;
}
if (ts->gpio_rst) { if (ts->gpio_rst) {
ts->gpio_int = devm_gpiod_get_optional(&client->dev, "irq", ts->gpio_int = devm_gpiod_get_optional(&client->dev, "irq",
GPIOD_IN); GPIOD_IN);
if (IS_ERR(ts->gpio_int)) { error = PTR_ERR_OR_ZERO(ts->gpio_int);
ret = PTR_ERR(ts->gpio_int); if (error)
dev_err(&client->dev, return dev_err_probe(&client->dev, error,
"failed to request interrupt GPIO: %d\n", ret); "failed to request interrupt GPIO\n");
return ret;
}
} else { } else {
/* /*
* Deprecated GPIO handling for compatibility * Deprecated GPIO handling for compatibility
...@@ -732,33 +727,31 @@ static int zforce_probe(struct i2c_client *client) ...@@ -732,33 +727,31 @@ static int zforce_probe(struct i2c_client *client)
/* INT GPIO */ /* INT GPIO */
ts->gpio_int = devm_gpiod_get_index(&client->dev, NULL, 0, ts->gpio_int = devm_gpiod_get_index(&client->dev, NULL, 0,
GPIOD_IN); GPIOD_IN);
if (IS_ERR(ts->gpio_int)) {
ret = PTR_ERR(ts->gpio_int); error = PTR_ERR_OR_ZERO(ts->gpio_int);
dev_err(&client->dev, if (error)
"failed to request interrupt GPIO: %d\n", ret); return dev_err_probe(&client->dev, error,
return ret; "failed to request interrupt GPIO\n");
}
/* RST GPIO */ /* RST GPIO */
ts->gpio_rst = devm_gpiod_get_index(&client->dev, NULL, 1, ts->gpio_rst = devm_gpiod_get_index(&client->dev, NULL, 1,
GPIOD_OUT_HIGH); GPIOD_OUT_HIGH);
if (IS_ERR(ts->gpio_rst)) { error = PTR_ERR_OR_ZERO(ts->gpio_rst);
ret = PTR_ERR(ts->gpio_rst); if (error)
dev_err(&client->dev, return dev_err_probe(&client->dev, error,
"failed to request reset GPIO: %d\n", ret); "failed to request reset GPIO\n");
return ret;
}
} }
ts->reg_vdd = devm_regulator_get_optional(&client->dev, "vdd"); ts->reg_vdd = devm_regulator_get_optional(&client->dev, "vdd");
if (IS_ERR(ts->reg_vdd)) { error = PTR_ERR_OR_ZERO(ts->gpio_rst);
ret = PTR_ERR(ts->reg_vdd); if (error) {
if (ret != -ENOENT) if (error != -ENOENT)
return ret; return dev_err_probe(&client->dev, error,
"failed to request vdd supply\n");
} else { } else {
ret = regulator_enable(ts->reg_vdd); error = regulator_enable(ts->reg_vdd);
if (ret) if (error)
return ret; return error;
/* /*
* according to datasheet add 100us grace time after regular * according to datasheet add 100us grace time after regular
...@@ -767,23 +760,18 @@ static int zforce_probe(struct i2c_client *client) ...@@ -767,23 +760,18 @@ static int zforce_probe(struct i2c_client *client)
udelay(100); udelay(100);
} }
ret = devm_add_action_or_reset(&client->dev, zforce_reset, ts); error = devm_add_action_or_reset(&client->dev, zforce_reset, ts);
if (ret) { if (error)
dev_err(&client->dev, "failed to register reset action, %d\n", return dev_err_probe(&client->dev, error,
ret); "failed to register reset action\n");
/* hereafter the regulator will be disabled by the action */
return ret;
}
snprintf(ts->phys, sizeof(ts->phys), snprintf(ts->phys, sizeof(ts->phys),
"%s/input0", dev_name(&client->dev)); "%s/input0", dev_name(&client->dev));
input_dev = devm_input_allocate_device(&client->dev); input_dev = devm_input_allocate_device(&client->dev);
if (!input_dev) { if (!input_dev)
dev_err(&client->dev, "could not allocate input device\n"); return dev_err_probe(&client->dev, -ENOMEM,
return -ENOMEM; "could not allocate input device\n");
}
ts->client = client; ts->client = client;
ts->input = input_dev; ts->input = input_dev;
...@@ -797,10 +785,8 @@ static int zforce_probe(struct i2c_client *client) ...@@ -797,10 +785,8 @@ static int zforce_probe(struct i2c_client *client)
zforce_ts_parse_legacy_properties(ts); zforce_ts_parse_legacy_properties(ts);
touchscreen_parse_properties(input_dev, true, &ts->prop); touchscreen_parse_properties(input_dev, true, &ts->prop);
if (ts->prop.max_x == 0 || ts->prop.max_y == 0) { if (ts->prop.max_x == 0 || ts->prop.max_y == 0)
dev_err(&client->dev, "no size specified\n"); return dev_err_probe(&client->dev, -EINVAL, "no size specified");
return -EINVAL;
}
input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0,
ZFORCE_MAX_AREA, 0, 0); ZFORCE_MAX_AREA, 0, 0);
...@@ -808,10 +794,10 @@ static int zforce_probe(struct i2c_client *client) ...@@ -808,10 +794,10 @@ static int zforce_probe(struct i2c_client *client)
ZFORCE_MAX_AREA, 0, 0); ZFORCE_MAX_AREA, 0, 0);
input_set_abs_params(input_dev, ABS_MT_ORIENTATION, 0, 1, 0, 0); input_set_abs_params(input_dev, ABS_MT_ORIENTATION, 0, 1, 0, 0);
ret = input_mt_init_slots(input_dev, ZFORCE_REPORT_POINTS, error = input_mt_init_slots(input_dev, ZFORCE_REPORT_POINTS,
INPUT_MT_DIRECT); INPUT_MT_DIRECT);
if (ret) if (error)
return ret; return error;
input_set_drvdata(ts->input, ts); input_set_drvdata(ts->input, ts);
...@@ -824,14 +810,13 @@ static int zforce_probe(struct i2c_client *client) ...@@ -824,14 +810,13 @@ static int zforce_probe(struct i2c_client *client)
* Therefore we can trigger the interrupt anytime it is low and do * Therefore we can trigger the interrupt anytime it is low and do
* not need to limit it to the interrupt edge. * not need to limit it to the interrupt edge.
*/ */
ret = devm_request_threaded_irq(&client->dev, client->irq, error = devm_request_threaded_irq(&client->dev, client->irq,
zforce_irq, zforce_irq_thread, zforce_irq, zforce_irq_thread,
IRQF_TRIGGER_LOW | IRQF_ONESHOT, IRQF_TRIGGER_LOW | IRQF_ONESHOT,
input_dev->name, ts); input_dev->name, ts);
if (ret) { if (error)
dev_err(&client->dev, "irq %d request failed\n", client->irq); return dev_err_probe(&client->dev, error,
return ret; "irq %d request failed\n", client->irq);
}
i2c_set_clientdata(client, ts); i2c_set_clientdata(client, ts);
...@@ -843,33 +828,29 @@ static int zforce_probe(struct i2c_client *client) ...@@ -843,33 +828,29 @@ static int zforce_probe(struct i2c_client *client)
dev_warn(&client->dev, "bootcomplete timed out\n"); dev_warn(&client->dev, "bootcomplete timed out\n");
/* need to start device to get version information */ /* need to start device to get version information */
ret = zforce_command_wait(ts, COMMAND_INITIALIZE); error = zforce_command_wait(ts, COMMAND_INITIALIZE);
if (ret) { if (error)
dev_err(&client->dev, "unable to initialize, %d\n", ret); return dev_err_probe(&client->dev, error, "unable to initialize\n");
return ret;
}
/* this gets the firmware version among other information */ /* this gets the firmware version among other information */
ret = zforce_command_wait(ts, COMMAND_STATUS); error = zforce_command_wait(ts, COMMAND_STATUS);
if (ret < 0) { if (error) {
dev_err(&client->dev, "couldn't get status, %d\n", ret); dev_err_probe(&client->dev, error, "couldn't get status\n");
zforce_stop(ts); zforce_stop(ts);
return ret; return error;
} }
/* stop device and put it into sleep until it is opened */ /* stop device and put it into sleep until it is opened */
ret = zforce_stop(ts); error = zforce_stop(ts);
if (ret < 0) if (error)
return ret; return error;
device_set_wakeup_capable(&client->dev, true); device_set_wakeup_capable(&client->dev, true);
ret = input_register_device(input_dev); error = input_register_device(input_dev);
if (ret) { if (error)
dev_err(&client->dev, "could not register input device, %d\n", return dev_err_probe(&client->dev, error,
ret); "could not register input device\n");
return ret;
}
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment