Commit 102feb1d authored by Lucas Stach's avatar Lucas Stach Committed by Dmitry Torokhov

Input: exc3000 - factor out vendor data request

Factor out the vendor data i2c request handling to make it reusable
for other functions. Also don't cache the model and firmware version
string in the device private data as we never use the cached version,
but always read from the device.
Signed-off-by: default avatarLucas Stach <l.stach@pengutronix.de>
Link: https://lore.kernel.org/r/20210125182527.1225245-3-l.stach@pengutronix.deSigned-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent a63d0120
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#define EXC3000_NUM_SLOTS 10 #define EXC3000_NUM_SLOTS 10
#define EXC3000_SLOTS_PER_FRAME 5 #define EXC3000_SLOTS_PER_FRAME 5
#define EXC3000_LEN_FRAME 66 #define EXC3000_LEN_FRAME 66
#define EXC3000_LEN_VENDOR_REQUEST 68
#define EXC3000_LEN_POINT 10 #define EXC3000_LEN_POINT 10
#define EXC3000_LEN_MODEL_NAME 16 #define EXC3000_LEN_MODEL_NAME 16
...@@ -77,9 +78,6 @@ struct exc3000_data { ...@@ -77,9 +78,6 @@ struct exc3000_data {
u8 buf[2 * EXC3000_LEN_FRAME]; u8 buf[2 * EXC3000_LEN_FRAME];
struct completion wait_event; struct completion wait_event;
struct mutex query_lock; struct mutex query_lock;
int query_result;
char model[EXC3000_LEN_MODEL_NAME];
char fw_version[EXC3000_LEN_FW_VERSION];
}; };
static void exc3000_report_slots(struct input_dev *input, static void exc3000_report_slots(struct input_dev *input,
...@@ -186,23 +184,6 @@ static int exc3000_handle_mt_event(struct exc3000_data *data) ...@@ -186,23 +184,6 @@ static int exc3000_handle_mt_event(struct exc3000_data *data)
return ret; return ret;
} }
static int exc3000_query_interrupt(struct exc3000_data *data)
{
u8 *buf = data->buf;
if (buf[0] != 'B')
return -EPROTO;
if (buf[4] == 'E')
strlcpy(data->model, buf + 5, sizeof(data->model));
else if (buf[4] == 'D')
strlcpy(data->fw_version, buf + 5, sizeof(data->fw_version));
else
return -EPROTO;
return 0;
}
static irqreturn_t exc3000_interrupt(int irq, void *dev_id) static irqreturn_t exc3000_interrupt(int irq, void *dev_id)
{ {
struct exc3000_data *data = dev_id; struct exc3000_data *data = dev_id;
...@@ -218,7 +199,6 @@ static irqreturn_t exc3000_interrupt(int irq, void *dev_id) ...@@ -218,7 +199,6 @@ static irqreturn_t exc3000_interrupt(int irq, void *dev_id)
switch (buf[2]) { switch (buf[2]) {
case EXC3000_VENDOR_EVENT: case EXC3000_VENDOR_EVENT:
data->query_result = exc3000_query_interrupt(data);
complete(&data->wait_event); complete(&data->wait_event);
break; break;
...@@ -235,73 +215,75 @@ static irqreturn_t exc3000_interrupt(int irq, void *dev_id) ...@@ -235,73 +215,75 @@ static irqreturn_t exc3000_interrupt(int irq, void *dev_id)
return IRQ_HANDLED; return IRQ_HANDLED;
} }
static ssize_t fw_version_show(struct device *dev, static int exc3000_vendor_data_request(struct exc3000_data *data, u8 *request,
struct device_attribute *attr, char *buf) u8 request_len, u8 *response, int timeout)
{ {
struct i2c_client *client = to_i2c_client(dev); u8 buf[EXC3000_LEN_VENDOR_REQUEST] = { 0x67, 0x00, 0x42, 0x00, 0x03 };
struct exc3000_data *data = i2c_get_clientdata(client); int ret;
static const u8 request[68] = {
0x67, 0x00, 0x42, 0x00, 0x03, 0x01, 'D', 0x00
};
int error;
mutex_lock(&data->query_lock); mutex_lock(&data->query_lock);
data->query_result = -ETIMEDOUT;
reinit_completion(&data->wait_event); reinit_completion(&data->wait_event);
error = i2c_master_send(client, request, sizeof(request)); buf[5] = request_len;
if (error < 0) { memcpy(&buf[6], request, request_len);
mutex_unlock(&data->query_lock);
return error; ret = i2c_master_send(data->client, buf, EXC3000_LEN_VENDOR_REQUEST);
if (ret < 0)
goto out_unlock;
if (response) {
ret = wait_for_completion_timeout(&data->wait_event,
timeout * HZ);
if (ret <= 0) {
ret = -ETIMEDOUT;
goto out_unlock;
} }
wait_for_completion_interruptible_timeout(&data->wait_event, 1 * HZ); if (data->buf[3] >= EXC3000_LEN_FRAME) {
mutex_unlock(&data->query_lock); ret = -ENOSPC;
goto out_unlock;
}
memcpy(response, &data->buf[4], data->buf[3]);
ret = data->buf[3];
}
if (data->query_result < 0) out_unlock:
return data->query_result; mutex_unlock(&data->query_lock);
return sprintf(buf, "%s\n", data->fw_version); return ret;
} }
static DEVICE_ATTR_RO(fw_version);
static ssize_t exc3000_get_model(struct exc3000_data *data) static ssize_t fw_version_show(struct device *dev,
struct device_attribute *attr, char *buf)
{ {
static const u8 request[68] = { struct i2c_client *client = to_i2c_client(dev);
0x67, 0x00, 0x42, 0x00, 0x03, 0x01, 'E', 0x00 struct exc3000_data *data = i2c_get_clientdata(client);
}; u8 response[EXC3000_LEN_FRAME];
struct i2c_client *client = data->client; int ret;
int error;
mutex_lock(&data->query_lock);
data->query_result = -ETIMEDOUT;
reinit_completion(&data->wait_event);
error = i2c_master_send(client, request, sizeof(request));
if (error < 0) {
mutex_unlock(&data->query_lock);
return error;
}
wait_for_completion_interruptible_timeout(&data->wait_event, 1 * HZ); ret = exc3000_vendor_data_request(data, (u8[]){'D'}, 1, response, 1);
mutex_unlock(&data->query_lock); if (ret < 0)
return ret;
return data->query_result; return sprintf(buf, "%s\n", &response[1]);
} }
static DEVICE_ATTR_RO(fw_version);
static ssize_t model_show(struct device *dev, static ssize_t model_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct exc3000_data *data = i2c_get_clientdata(client); struct exc3000_data *data = i2c_get_clientdata(client);
int error; u8 response[EXC3000_LEN_FRAME];
int ret;
error = exc3000_get_model(data); ret = exc3000_vendor_data_request(data, (u8[]){'E'}, 1, response, 1);
if (error < 0) if (ret < 0)
return error; return ret;
return sprintf(buf, "%s\n", data->model); return sprintf(buf, "%s\n", &response[1]);
} }
static DEVICE_ATTR_RO(model); static DEVICE_ATTR_RO(model);
...@@ -387,9 +369,15 @@ static int exc3000_probe(struct i2c_client *client) ...@@ -387,9 +369,15 @@ static int exc3000_probe(struct i2c_client *client)
* or two touch events anyways). * or two touch events anyways).
*/ */
for (retry = 0; retry < 3; retry++) { for (retry = 0; retry < 3; retry++) {
error = exc3000_get_model(data); u8 response[EXC3000_LEN_FRAME];
if (!error)
error = exc3000_vendor_data_request(data, (u8[]){'E'}, 1,
response, 1);
if (error > 0) {
dev_dbg(&client->dev, "TS Model: %s", &response[1]);
error = 0;
break; break;
}
dev_warn(&client->dev, "Retry %d get EETI EXC3000 model: %d\n", dev_warn(&client->dev, "Retry %d get EETI EXC3000 model: %d\n",
retry + 1, error); retry + 1, error);
} }
...@@ -397,8 +385,6 @@ static int exc3000_probe(struct i2c_client *client) ...@@ -397,8 +385,6 @@ static int exc3000_probe(struct i2c_client *client)
if (error) if (error)
return error; return error;
dev_dbg(&client->dev, "TS Model: %s", data->model);
i2c_set_clientdata(client, data); i2c_set_clientdata(client, data);
error = devm_device_add_group(&client->dev, &exc3000_attribute_group); error = devm_device_add_group(&client->dev, &exc3000_attribute_group);
......
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