Hi,
This is (a much delayed, sorry!) PATCHv2 of the EXC80Hxx support
patchset. Here is the changelog since [PATCHv1]:
- prepend new patch converting binding document to YAML
- prepend new patch switching to I2C probe_new
- append new patch adding reset-gpio support
- use explicit compatible values for the touchscreen chips instead of
a wildcast. Since the documentation, that I have is very vague let's
use different values for exc80h60 and exc80h84. This avoids wildcard
DT entries and means we are prepared when noticing differences
between the chips.
- add accidently removed terminator entry in exc3000_id
- use device structure with max_xy and name (suggested by Martin)
- use SZ_4K, SZ_16K defines (suggested by Dmitry)
- harden event check, so that MT1 and MT2 based chips only allow
their own event type.
- write more detailed commit description in the fw_version/model
sysfs patch to explain why the values are not cached and why
the simpler read(); sleep(); write() approach has not been used
- use DEVICE_ATTR_RO() in fw_version/model patch to improve readability
- fw_version/model: replace memcpy + null termination with strlcpy
- fw_version/model: increase buffer size for weird firmware versions
- fw_version/model: use sizeof() instead of hardcoded buffer sizes
- simplify exc3000_query_interrupt() by moving the complete() call to
the exc3000_interrupt().
I think I only ignored one review feedback, that the fw_version and
model sysfs nodes are attached to the input device instead of the
i2c device. This was done to avoid being racy:
http://kroah.com/log/blog/2013/06/26/how-to-create-a-sysfs-file-correctly/
Properties look like this after applying the patchset:
$ cat /sys/class/input/input1/{name,fw_version,model}
EETI EXC80H60 Touch Screen
00_T6
Orion_1320
Thanks in advance for looking at the patches,
-- Sebastian
[PATCHv1] https://lore.kernel.org/linux-input/[email protected]/
Sebastian Reichel (5):
dt-bindings: touchscreen: Convert EETI EXC3000 touchscreen to
json-schema
Input: EXC3000: switch to i2c's probe_new API
Input: EXC3000: add EXC80H60 and EXC80H84 support
Input: EXC3000: Add support to query model and fw_version
Input: EXC3000: Add reset gpio support
.../bindings/input/touchscreen/exc3000.txt | 26 --
.../bindings/input/touchscreen/exc3000.yaml | 58 +++++
drivers/input/touchscreen/exc3000.c | 243 ++++++++++++++++--
3 files changed, 281 insertions(+), 46 deletions(-)
delete mode 100644 Documentation/devicetree/bindings/input/touchscreen/exc3000.txt
create mode 100644 Documentation/devicetree/bindings/input/touchscreen/exc3000.yaml
--
2.26.2
Expose model and fw_version via sysfs. Also query the model
in probe to make sure, that the I2C communication with the
device works before successfully probing the driver.
This is a bit complicated, since EETI devices do not have
a sync interface. Sending the commands and directly reading
does not work. Sending the command and waiting for some time
is also not an option, since there might be touch events in
the mean time.
Last but not least we do not cache the results, since this
interface can be used to check the I2C communication is still
working as expected.
Signed-off-by: Sebastian Reichel <[email protected]>
---
drivers/input/touchscreen/exc3000.c | 138 +++++++++++++++++++++++++++-
1 file changed, 137 insertions(+), 1 deletion(-)
diff --git a/drivers/input/touchscreen/exc3000.c b/drivers/input/touchscreen/exc3000.c
index 9622cba514b3..1ae758bbf627 100644
--- a/drivers/input/touchscreen/exc3000.c
+++ b/drivers/input/touchscreen/exc3000.c
@@ -24,6 +24,9 @@
#define EXC3000_LEN_FRAME 66
#define EXC3000_LEN_POINT 10
+#define EXC3000_LEN_MODEL_NAME 16
+#define EXC3000_LEN_FW_VERSION 16
+
#define EXC3000_MT1_EVENT 0x06
#define EXC3000_MT2_EVENT 0x18
@@ -64,6 +67,11 @@ struct exc3000_data {
struct touchscreen_properties prop;
struct timer_list timer;
u8 buf[2 * EXC3000_LEN_FRAME];
+ struct completion wait_event;
+ 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,
@@ -149,6 +157,28 @@ static int exc3000_read_data(struct exc3000_data *data,
return 0;
}
+static int exc3000_query_interrupt(struct exc3000_data *data)
+{
+ u8 *buf = data->buf;
+ int err;
+
+ err = i2c_master_recv(data->client, buf, EXC3000_LEN_FRAME);
+ if (err < 0)
+ return err;
+
+ if (buf[0] != 0x42)
+ 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)
{
struct exc3000_data *data = dev_id;
@@ -157,6 +187,12 @@ static irqreturn_t exc3000_interrupt(int irq, void *dev_id)
int slots, total_slots;
int error;
+ if (mutex_is_locked(&data->query_lock)) {
+ data->query_result = exc3000_query_interrupt(data);
+ complete(&data->wait_event);
+ goto out;
+ }
+
error = exc3000_read_data(data, buf, &total_slots);
if (error) {
/* Schedule a timer to release "stuck" contacts */
@@ -184,11 +220,94 @@ static irqreturn_t exc3000_interrupt(int irq, void *dev_id)
return IRQ_HANDLED;
}
+static int fw_version_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct exc3000_data *data = dev_get_drvdata(dev);
+ static const u8 request[68] = {
+ 0x67, 0x00, 0x42, 0x00, 0x03, 0x01, 'D', 0x00
+ };
+ struct i2c_client *client = data->client;
+ int err;
+
+ mutex_lock(&data->query_lock);
+
+ data->query_result = -ETIMEDOUT;
+ reinit_completion(&data->wait_event);
+
+ err = i2c_master_send(client, request, sizeof(request));
+ if (err < 0) {
+ mutex_unlock(&data->query_lock);
+ return err;
+ }
+
+ wait_for_completion_interruptible_timeout(&data->wait_event, 1*HZ);
+ mutex_unlock(&data->query_lock);
+
+ if (data->query_result < 0)
+ return data->query_result;
+
+ return sprintf(buf, "%s\n", data->fw_version);
+}
+static DEVICE_ATTR_RO(fw_version);
+
+static ssize_t exc3000_get_model(struct exc3000_data *data)
+{
+ static const u8 request[68] = {
+ 0x67, 0x00, 0x42, 0x00, 0x03, 0x01, 'E', 0x00
+ };
+ struct i2c_client *client = data->client;
+ int err;
+
+ mutex_lock(&data->query_lock);
+ data->query_result = -ETIMEDOUT;
+ reinit_completion(&data->wait_event);
+
+ err = i2c_master_send(client, request, sizeof(request));
+ if (err < 0) {
+ mutex_unlock(&data->query_lock);
+ return err;
+ }
+
+ wait_for_completion_interruptible_timeout(&data->wait_event, 1 * HZ);
+ mutex_unlock(&data->query_lock);
+
+ return data->query_result;
+}
+
+static ssize_t model_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct exc3000_data *data = dev_get_drvdata(dev);
+ int err = exc3000_get_model(data);
+
+ if (err < 0)
+ return err;
+
+ return sprintf(buf, "%s\n", data->model);
+}
+static DEVICE_ATTR_RO(model);
+
+static struct attribute *sysfs_attrs[] = {
+ &dev_attr_fw_version.attr,
+ &dev_attr_model.attr,
+ NULL
+};
+
+static struct attribute_group exc3000_attribute_group = {
+ .attrs = sysfs_attrs
+};
+
+static const struct attribute_group *exc3000_attribute_groups[] = {
+ &exc3000_attribute_group,
+ NULL
+};
+
static int exc3000_probe(struct i2c_client *client)
{
struct exc3000_data *data;
struct input_dev *input;
- int error, max_xy;
+ int error, max_xy, retry;
data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
if (!data)
@@ -202,15 +321,19 @@ static int exc3000_probe(struct i2c_client *client)
data->info = &exc3000_info[eeti_dev_id];
}
timer_setup(&data->timer, exc3000_timer, 0);
+ init_completion(&data->wait_event);
+ mutex_init(&data->query_lock);
input = devm_input_allocate_device(&client->dev);
if (!input)
return -ENOMEM;
data->input = input;
+ input_set_drvdata(input, data);
input->name = data->info->name;
input->id.bustype = BUS_I2C;
+ input->dev.groups = exc3000_attribute_groups;
max_xy = data->info->max_xy;
input_set_abs_params(input, ABS_MT_POSITION_X, 0, max_xy, 0, 0);
@@ -233,6 +356,19 @@ static int exc3000_probe(struct i2c_client *client)
if (error)
return error;
+ for (retry = 0; retry < 3; ++retry) {
+ error = exc3000_get_model(data);
+ if (!error)
+ break;
+ dev_warn(&client->dev, "Retry %d get EETI EXC3000 model: %d\n",
+ retry + 1, error);
+ }
+
+ if (error)
+ return error;
+
+ dev_dbg(&client->dev, "TS Model: %s", data->model);
+
return 0;
}
--
2.26.2
Add basic support for an optional reset gpio.
Signed-off-by: Sebastian Reichel <[email protected]>
---
.../bindings/input/touchscreen/exc3000.yaml | 2 ++
drivers/input/touchscreen/exc3000.c | 29 +++++++++++++++----
2 files changed, 25 insertions(+), 6 deletions(-)
diff --git a/Documentation/devicetree/bindings/input/touchscreen/exc3000.yaml b/Documentation/devicetree/bindings/input/touchscreen/exc3000.yaml
index d83b61e884df..8b70b918c7ca 100644
--- a/Documentation/devicetree/bindings/input/touchscreen/exc3000.yaml
+++ b/Documentation/devicetree/bindings/input/touchscreen/exc3000.yaml
@@ -22,6 +22,8 @@ properties:
const: 0x2a
interrupts:
maxItems: 1
+ reset-gpios:
+ maxItems: 1
touchscreen-size-x: true
touchscreen-size-y: true
touchscreen-inverted-x: true
diff --git a/drivers/input/touchscreen/exc3000.c b/drivers/input/touchscreen/exc3000.c
index 1ae758bbf627..9fed66ef1719 100644
--- a/drivers/input/touchscreen/exc3000.c
+++ b/drivers/input/touchscreen/exc3000.c
@@ -8,7 +8,9 @@
*/
#include <linux/bitops.h>
+#include <linux/delay.h>
#include <linux/device.h>
+#include <linux/gpio/consumer.h>
#include <linux/i2c.h>
#include <linux/input.h>
#include <linux/input/mt.h>
@@ -32,6 +34,9 @@
#define EXC3000_TIMEOUT_MS 100
+#define EXC3000_RESET_MS 10
+#define EXC3000_READY_MS 100
+
static const struct i2c_device_id exc3000_id[];
struct eeti_dev_info {
@@ -65,6 +70,7 @@ struct exc3000_data {
const struct eeti_dev_info *info;
struct input_dev *input;
struct touchscreen_properties prop;
+ struct gpio_desc *reset;
struct timer_list timer;
u8 buf[2 * EXC3000_LEN_FRAME];
struct completion wait_event;
@@ -305,16 +311,17 @@ static const struct attribute_group *exc3000_attribute_groups[] = {
static int exc3000_probe(struct i2c_client *client)
{
+ struct device *dev = &client->dev;
struct exc3000_data *data;
struct input_dev *input;
int error, max_xy, retry;
- data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
+ data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
if (!data)
return -ENOMEM;
data->client = client;
- data->info = device_get_match_data(&client->dev);
+ data->info = device_get_match_data(dev);
if (!data->info) {
enum eeti_dev_id eeti_dev_id =
i2c_match_id(exc3000_id, client)->driver_data;
@@ -324,7 +331,17 @@ static int exc3000_probe(struct i2c_client *client)
init_completion(&data->wait_event);
mutex_init(&data->query_lock);
- input = devm_input_allocate_device(&client->dev);
+ data->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
+ if (IS_ERR(data->reset))
+ return PTR_ERR(data->reset);
+
+ if (data->reset) {
+ msleep(EXC3000_RESET_MS);
+ gpiod_set_value_cansleep(data->reset, 0);
+ msleep(EXC3000_READY_MS);
+ }
+
+ input = devm_input_allocate_device(dev);
if (!input)
return -ENOMEM;
@@ -350,7 +367,7 @@ static int exc3000_probe(struct i2c_client *client)
if (error)
return error;
- error = devm_request_threaded_irq(&client->dev, client->irq,
+ error = devm_request_threaded_irq(dev, client->irq,
NULL, exc3000_interrupt, IRQF_ONESHOT,
client->name, data);
if (error)
@@ -360,14 +377,14 @@ static int exc3000_probe(struct i2c_client *client)
error = exc3000_get_model(data);
if (!error)
break;
- dev_warn(&client->dev, "Retry %d get EETI EXC3000 model: %d\n",
+ dev_warn(dev, "Retry %d get EETI EXC3000 model: %d\n",
retry + 1, error);
}
if (error)
return error;
- dev_dbg(&client->dev, "TS Model: %s", data->model);
+ dev_dbg(dev, "TS Model: %s", data->model);
return 0;
}
--
2.26.2
Hi Sebastian,
Again a minor thing
On 19/5/20 20:24, Sebastian Reichel wrote:
> Add basic support for an optional reset gpio.
>
> Signed-off-by: Sebastian Reichel <[email protected]>
> ---
> .../bindings/input/touchscreen/exc3000.yaml | 2 ++
> drivers/input/touchscreen/exc3000.c | 29 +++++++++++++++----
> 2 files changed, 25 insertions(+), 6 deletions(-)
>
> diff --git a/Documentation/devicetree/bindings/input/touchscreen/exc3000.yaml b/Documentation/devicetree/bindings/input/touchscreen/exc3000.yaml
> index d83b61e884df..8b70b918c7ca 100644
> --- a/Documentation/devicetree/bindings/input/touchscreen/exc3000.yaml
> +++ b/Documentation/devicetree/bindings/input/touchscreen/exc3000.yaml
> @@ -22,6 +22,8 @@ properties:
> const: 0x2a
> interrupts:
> maxItems: 1
> + reset-gpios:
> + maxItems: 1
> touchscreen-size-x: true
> touchscreen-size-y: true
> touchscreen-inverted-x: true
> diff --git a/drivers/input/touchscreen/exc3000.c b/drivers/input/touchscreen/exc3000.c
> index 1ae758bbf627..9fed66ef1719 100644
> --- a/drivers/input/touchscreen/exc3000.c
> +++ b/drivers/input/touchscreen/exc3000.c
> @@ -8,7 +8,9 @@
> */
>
> #include <linux/bitops.h>
> +#include <linux/delay.h>
> #include <linux/device.h>
> +#include <linux/gpio/consumer.h>
> #include <linux/i2c.h>
> #include <linux/input.h>
> #include <linux/input/mt.h>
> @@ -32,6 +34,9 @@
>
> #define EXC3000_TIMEOUT_MS 100
>
> +#define EXC3000_RESET_MS 10
> +#define EXC3000_READY_MS 100
> +
> static const struct i2c_device_id exc3000_id[];
>
> struct eeti_dev_info {
> @@ -65,6 +70,7 @@ struct exc3000_data {
> const struct eeti_dev_info *info;
> struct input_dev *input;
> struct touchscreen_properties prop;
> + struct gpio_desc *reset;
> struct timer_list timer;
> u8 buf[2 * EXC3000_LEN_FRAME];
> struct completion wait_event;
> @@ -305,16 +311,17 @@ static const struct attribute_group *exc3000_attribute_groups[] = {
>
> static int exc3000_probe(struct i2c_client *client)
> {
> + struct device *dev = &client->dev;
This introduces more changes to the patch than the required. Is not that I am
against of this change but since what you are doing here is introduce an
optional reset I think would be better just introduce that change.
> struct exc3000_data *data;
> struct input_dev *input;
> int error, max_xy, retry;
>
> - data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
> + data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
> if (!data)
> return -ENOMEM;
>
> data->client = client;
> - data->info = device_get_match_data(&client->dev);
> + data->info = device_get_match_data(dev);
> if (!data->info) {
> enum eeti_dev_id eeti_dev_id =
> i2c_match_id(exc3000_id, client)->driver_data;
> @@ -324,7 +331,17 @@ static int exc3000_probe(struct i2c_client *client)
> init_completion(&data->wait_event);
> mutex_init(&data->query_lock);
>
> - input = devm_input_allocate_device(&client->dev);
> + data->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
nit: Just use &client->dev here ?
> + if (IS_ERR(data->reset))
> + return PTR_ERR(data->reset);
> +
> + if (data->reset) {
> + msleep(EXC3000_RESET_MS);
> + gpiod_set_value_cansleep(data->reset, 0);
> + msleep(EXC3000_READY_MS);
> + }
> +
> + input = devm_input_allocate_device(dev);
> if (!input)
> return -ENOMEM;
>
> @@ -350,7 +367,7 @@ static int exc3000_probe(struct i2c_client *client)
> if (error)
> return error;
>
> - error = devm_request_threaded_irq(&client->dev, client->irq,
> + error = devm_request_threaded_irq(dev, client->irq,
> NULL, exc3000_interrupt, IRQF_ONESHOT,
> client->name, data);
> if (error)
> @@ -360,14 +377,14 @@ static int exc3000_probe(struct i2c_client *client)
> error = exc3000_get_model(data);
> if (!error)
> break;
> - dev_warn(&client->dev, "Retry %d get EETI EXC3000 model: %d\n",
> + dev_warn(dev, "Retry %d get EETI EXC3000 model: %d\n",
> retry + 1, error);
> }
>
> if (error)
> return error;
>
> - dev_dbg(&client->dev, "TS Model: %s", data->model);
> + dev_dbg(dev, "TS Model: %s", data->model);
>
> return 0;
> }
>
Hi Sebastian,
On 19/5/20 20:24, Sebastian Reichel wrote:
> Expose model and fw_version via sysfs. Also query the model
> in probe to make sure, that the I2C communication with the
> device works before successfully probing the driver.
>
> This is a bit complicated, since EETI devices do not have
> a sync interface. Sending the commands and directly reading
> does not work. Sending the command and waiting for some time
> is also not an option, since there might be touch events in
> the mean time.
>
> Last but not least we do not cache the results, since this
> interface can be used to check the I2C communication is still
> working as expected.
>
> Signed-off-by: Sebastian Reichel <[email protected]>
> ---
> drivers/input/touchscreen/exc3000.c | 138 +++++++++++++++++++++++++++-
> 1 file changed, 137 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/input/touchscreen/exc3000.c b/drivers/input/touchscreen/exc3000.c
> index 9622cba514b3..1ae758bbf627 100644
> --- a/drivers/input/touchscreen/exc3000.c
> +++ b/drivers/input/touchscreen/exc3000.c
> @@ -24,6 +24,9 @@
> #define EXC3000_LEN_FRAME 66
> #define EXC3000_LEN_POINT 10
>
> +#define EXC3000_LEN_MODEL_NAME 16
> +#define EXC3000_LEN_FW_VERSION 16
> +
> #define EXC3000_MT1_EVENT 0x06
> #define EXC3000_MT2_EVENT 0x18
>
> @@ -64,6 +67,11 @@ struct exc3000_data {
> struct touchscreen_properties prop;
> struct timer_list timer;
> u8 buf[2 * EXC3000_LEN_FRAME];
> + struct completion wait_event;
> + 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,
> @@ -149,6 +157,28 @@ static int exc3000_read_data(struct exc3000_data *data,
> return 0;
> }
>
> +static int exc3000_query_interrupt(struct exc3000_data *data)
> +{
> + u8 *buf = data->buf;
> + int err;
> +
> + err = i2c_master_recv(data->client, buf, EXC3000_LEN_FRAME);
> + if (err < 0)
> + return err;
> +
> + if (buf[0] != 0x42)
> + 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)
> {
> struct exc3000_data *data = dev_id;
> @@ -157,6 +187,12 @@ static irqreturn_t exc3000_interrupt(int irq, void *dev_id)
> int slots, total_slots;
> int error;
>
> + if (mutex_is_locked(&data->query_lock)) {
> + data->query_result = exc3000_query_interrupt(data);
> + complete(&data->wait_event);
> + goto out;
> + }
> +
> error = exc3000_read_data(data, buf, &total_slots);
> if (error) {
> /* Schedule a timer to release "stuck" contacts */
> @@ -184,11 +220,94 @@ static irqreturn_t exc3000_interrupt(int irq, void *dev_id)
> return IRQ_HANDLED;
> }
>
> +static int fw_version_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + struct exc3000_data *data = dev_get_drvdata(dev);
> + static const u8 request[68] = {
> + 0x67, 0x00, 0x42, 0x00, 0x03, 0x01, 'D', 0x00
> + };
> + struct i2c_client *client = data->client;
> + int err;
> +
> + mutex_lock(&data->query_lock);
> +
> + data->query_result = -ETIMEDOUT;
> + reinit_completion(&data->wait_event);
> +
> + err = i2c_master_send(client, request, sizeof(request));
> + if (err < 0) {
> + mutex_unlock(&data->query_lock);
> + return err;
> + }
> +
> + wait_for_completion_interruptible_timeout(&data->wait_event, 1*HZ);
> + mutex_unlock(&data->query_lock);
> +
> + if (data->query_result < 0)
> + return data->query_result;
> +
> + return sprintf(buf, "%s\n", data->fw_version);
> +}
> +static DEVICE_ATTR_RO(fw_version);
> +
You should probably document the new sysfs entries, although are self-explanatory.
> +static ssize_t exc3000_get_model(struct exc3000_data *data)
> +{
> + static const u8 request[68] = {
> + 0x67, 0x00, 0x42, 0x00, 0x03, 0x01, 'E', 0x00
> + };
> + struct i2c_client *client = data->client;
> + int err;
> +
> + mutex_lock(&data->query_lock);
> + data->query_result = -ETIMEDOUT;
> + reinit_completion(&data->wait_event);
> +
> + err = i2c_master_send(client, request, sizeof(request));
> + if (err < 0) {
> + mutex_unlock(&data->query_lock);
> + return err;
> + }
> +
> + wait_for_completion_interruptible_timeout(&data->wait_event, 1 * HZ);
> + mutex_unlock(&data->query_lock);
> +
> + return data->query_result;
> +}
> +
> +static ssize_t model_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + struct exc3000_data *data = dev_get_drvdata(dev);
> + int err = exc3000_get_model(data);
> +
> + if (err < 0)
> + return err;
> +
> + return sprintf(buf, "%s\n", data->model);
> +}
> +static DEVICE_ATTR_RO(model);
> +
> +static struct attribute *sysfs_attrs[] = {
> + &dev_attr_fw_version.attr,
> + &dev_attr_model.attr,
> + NULL
> +};
> +
> +static struct attribute_group exc3000_attribute_group = {
> + .attrs = sysfs_attrs
> +};
> +
> +static const struct attribute_group *exc3000_attribute_groups[] = {
> + &exc3000_attribute_group,
> + NULL
> +};
> +
> static int exc3000_probe(struct i2c_client *client)
> {
> struct exc3000_data *data;
> struct input_dev *input;
> - int error, max_xy;
> + int error, max_xy, retry;
>
> data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
> if (!data)
> @@ -202,15 +321,19 @@ static int exc3000_probe(struct i2c_client *client)
> data->info = &exc3000_info[eeti_dev_id];
> }
> timer_setup(&data->timer, exc3000_timer, 0);
> + init_completion(&data->wait_event);
> + mutex_init(&data->query_lock);
>
> input = devm_input_allocate_device(&client->dev);
> if (!input)
> return -ENOMEM;
>
> data->input = input;
> + input_set_drvdata(input, data);
>
> input->name = data->info->name;
> input->id.bustype = BUS_I2C;
> + input->dev.groups = exc3000_attribute_groups;
>
> max_xy = data->info->max_xy;
> input_set_abs_params(input, ABS_MT_POSITION_X, 0, max_xy, 0, 0);
> @@ -233,6 +356,19 @@ static int exc3000_probe(struct i2c_client *client)
> if (error)
> return error;
>
> + for (retry = 0; retry < 3; ++retry) {
Just curious, is it known to fail and need retries?
> + error = exc3000_get_model(data);
> + if (!error)
> + break;
> + dev_warn(&client->dev, "Retry %d get EETI EXC3000 model: %d\n",
> + retry + 1, error);
> + }
> +
> + if (error)
> + return error;
> +
> + dev_dbg(&client->dev, "TS Model: %s", data->model);
> +
> return 0;
> }
>
>
Hi,
On Tue, May 19, 2020 at 11:12:16PM +0200, Enric Balletbo i Serra wrote:
> On 19/5/20 20:24, Sebastian Reichel wrote:
> > Expose model and fw_version via sysfs. Also query the model
> > in probe to make sure, that the I2C communication with the
> > device works before successfully probing the driver.
> >
> > This is a bit complicated, since EETI devices do not have
> > a sync interface. Sending the commands and directly reading
> > does not work. Sending the command and waiting for some time
> > is also not an option, since there might be touch events in
> > the mean time.
> >
> > Last but not least we do not cache the results, since this
> > interface can be used to check the I2C communication is still
> > working as expected.
> >
> > Signed-off-by: Sebastian Reichel <[email protected]>
> > ---
> > drivers/input/touchscreen/exc3000.c | 138 +++++++++++++++++++++++++++-
> > 1 file changed, 137 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/input/touchscreen/exc3000.c b/drivers/input/touchscreen/exc3000.c
> > index 9622cba514b3..1ae758bbf627 100644
> > --- a/drivers/input/touchscreen/exc3000.c
> > +++ b/drivers/input/touchscreen/exc3000.c
> > @@ -24,6 +24,9 @@
> > #define EXC3000_LEN_FRAME 66
> > #define EXC3000_LEN_POINT 10
> >
> > +#define EXC3000_LEN_MODEL_NAME 16
> > +#define EXC3000_LEN_FW_VERSION 16
> > +
> > #define EXC3000_MT1_EVENT 0x06
> > #define EXC3000_MT2_EVENT 0x18
> >
> > @@ -64,6 +67,11 @@ struct exc3000_data {
> > struct touchscreen_properties prop;
> > struct timer_list timer;
> > u8 buf[2 * EXC3000_LEN_FRAME];
> > + struct completion wait_event;
> > + 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,
> > @@ -149,6 +157,28 @@ static int exc3000_read_data(struct exc3000_data *data,
> > return 0;
> > }
> >
> > +static int exc3000_query_interrupt(struct exc3000_data *data)
> > +{
> > + u8 *buf = data->buf;
> > + int err;
> > +
> > + err = i2c_master_recv(data->client, buf, EXC3000_LEN_FRAME);
> > + if (err < 0)
> > + return err;
> > +
> > + if (buf[0] != 0x42)
> > + 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)
> > {
> > struct exc3000_data *data = dev_id;
> > @@ -157,6 +187,12 @@ static irqreturn_t exc3000_interrupt(int irq, void *dev_id)
> > int slots, total_slots;
> > int error;
> >
> > + if (mutex_is_locked(&data->query_lock)) {
> > + data->query_result = exc3000_query_interrupt(data);
> > + complete(&data->wait_event);
> > + goto out;
> > + }
> > +
> > error = exc3000_read_data(data, buf, &total_slots);
> > if (error) {
> > /* Schedule a timer to release "stuck" contacts */
> > @@ -184,11 +220,94 @@ static irqreturn_t exc3000_interrupt(int irq, void *dev_id)
> > return IRQ_HANDLED;
> > }
> >
> > +static int fw_version_show(struct device *dev,
> > + struct device_attribute *attr, char *buf)
> > +{
> > + struct exc3000_data *data = dev_get_drvdata(dev);
> > + static const u8 request[68] = {
> > + 0x67, 0x00, 0x42, 0x00, 0x03, 0x01, 'D', 0x00
> > + };
> > + struct i2c_client *client = data->client;
> > + int err;
> > +
> > + mutex_lock(&data->query_lock);
> > +
> > + data->query_result = -ETIMEDOUT;
> > + reinit_completion(&data->wait_event);
> > +
> > + err = i2c_master_send(client, request, sizeof(request));
> > + if (err < 0) {
> > + mutex_unlock(&data->query_lock);
> > + return err;
> > + }
> > +
> > + wait_for_completion_interruptible_timeout(&data->wait_event, 1*HZ);
> > + mutex_unlock(&data->query_lock);
> > +
> > + if (data->query_result < 0)
> > + return data->query_result;
> > +
> > + return sprintf(buf, "%s\n", data->fw_version);
> > +}
> > +static DEVICE_ATTR_RO(fw_version);
> > +
>
> You should probably document the new sysfs entries, although are
> self-explanatory.
I suppose I could create
Documentation/ABI/testing/sysfs-driver-input-exc3000 or is there a
better place for sysfs API documentation of input devices?
> > +static ssize_t exc3000_get_model(struct exc3000_data *data)
> > +{
> > + static const u8 request[68] = {
> > + 0x67, 0x00, 0x42, 0x00, 0x03, 0x01, 'E', 0x00
> > + };
> > + struct i2c_client *client = data->client;
> > + int err;
> > +
> > + mutex_lock(&data->query_lock);
> > + data->query_result = -ETIMEDOUT;
> > + reinit_completion(&data->wait_event);
> > +
> > + err = i2c_master_send(client, request, sizeof(request));
> > + if (err < 0) {
> > + mutex_unlock(&data->query_lock);
> > + return err;
> > + }
> > +
> > + wait_for_completion_interruptible_timeout(&data->wait_event, 1 * HZ);
> > + mutex_unlock(&data->query_lock);
> > +
> > + return data->query_result;
> > +}
> > +
> > +static ssize_t model_show(struct device *dev,
> > + struct device_attribute *attr, char *buf)
> > +{
> > + struct exc3000_data *data = dev_get_drvdata(dev);
> > + int err = exc3000_get_model(data);
> > +
> > + if (err < 0)
> > + return err;
> > +
> > + return sprintf(buf, "%s\n", data->model);
> > +}
> > +static DEVICE_ATTR_RO(model);
> > +
> > +static struct attribute *sysfs_attrs[] = {
> > + &dev_attr_fw_version.attr,
> > + &dev_attr_model.attr,
> > + NULL
> > +};
> > +
> > +static struct attribute_group exc3000_attribute_group = {
> > + .attrs = sysfs_attrs
> > +};
> > +
> > +static const struct attribute_group *exc3000_attribute_groups[] = {
> > + &exc3000_attribute_group,
> > + NULL
> > +};
> > +
> > static int exc3000_probe(struct i2c_client *client)
> > {
> > struct exc3000_data *data;
> > struct input_dev *input;
> > - int error, max_xy;
> > + int error, max_xy, retry;
> >
> > data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
> > if (!data)
> > @@ -202,15 +321,19 @@ static int exc3000_probe(struct i2c_client *client)
> > data->info = &exc3000_info[eeti_dev_id];
> > }
> > timer_setup(&data->timer, exc3000_timer, 0);
> > + init_completion(&data->wait_event);
> > + mutex_init(&data->query_lock);
> >
> > input = devm_input_allocate_device(&client->dev);
> > if (!input)
> > return -ENOMEM;
> >
> > data->input = input;
> > + input_set_drvdata(input, data);
> >
> > input->name = data->info->name;
> > input->id.bustype = BUS_I2C;
> > + input->dev.groups = exc3000_attribute_groups;
> >
> > max_xy = data->info->max_xy;
> > input_set_abs_params(input, ABS_MT_POSITION_X, 0, max_xy, 0, 0);
> > @@ -233,6 +356,19 @@ static int exc3000_probe(struct i2c_client *client)
> > if (error)
> > return error;
> >
> > + for (retry = 0; retry < 3; ++retry) {
>
> Just curious, is it known to fail and need retries?
No, but a single I?C transmission can always go bad and in that case
it makes sense to recover instead of failing to load the driver. Other
buses (e.g. PCI) handle this transparently, but I?C does not.
-- Sebastian
>
> > + error = exc3000_get_model(data);
> > + if (!error)
> > + break;
> > + dev_warn(&client->dev, "Retry %d get EETI EXC3000 model: %d\n",
> > + retry + 1, error);
> > + }
> > +
> > + if (error)
> > + return error;
> > +
> > + dev_dbg(&client->dev, "TS Model: %s", data->model);
> > +
> > return 0;
> > }
> >
> >
Hi Sebastian,
I love your patch! Yet something to improve:
[auto build test ERROR on input/next]
[also build test ERROR on v5.7-rc6 next-20200519]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Sebastian-Reichel/EXC3000-Updates/20200520-023207
base: https://git.kernel.org/pub/scm/linux/kernel/git/dtor/input.git next
config: x86_64-allyesconfig (attached as .config)
compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project 135b877874fae96b4372c8a3fbfaa8ff44ff86e3)
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
Reported-by: kbuild test robot <[email protected]>
All errors (new ones prefixed by >>, old ones prefixed by <<):
drivers/input/touchscreen/exc3000.c:51:13: error: use of undeclared identifier 'SZ_4K'
.max_xy = SZ_4K - 1,
^
drivers/input/touchscreen/exc3000.c:55:13: error: use of undeclared identifier 'SZ_16K'
.max_xy = SZ_16K - 1,
^
drivers/input/touchscreen/exc3000.c:59:13: error: use of undeclared identifier 'SZ_16K'
.max_xy = SZ_16K - 1,
^
drivers/input/touchscreen/exc3000.c:107:28: error: use of undeclared identifier 'SZ_16K'
if (data->info->max_xy == SZ_16K - 1)
^
>> drivers/input/touchscreen/exc3000.c:252:8: error: incompatible function pointer types initializing 'ssize_t (*)(struct device *, struct device_attribute *, char *)' (aka 'long (*)(struct device *, struct device_attribute *, char *)') with an expression of type 'int (struct device *, struct device_attribute *, char *)' [-Werror,-Wincompatible-function-pointer-types]
static DEVICE_ATTR_RO(fw_version);
^~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/device.h:133:45: note: expanded from macro 'DEVICE_ATTR_RO'
struct device_attribute dev_attr_##_name = __ATTR_RO(_name)
^~~~~~~~~~~~~~~~
include/linux/sysfs.h:117:10: note: expanded from macro '__ATTR_RO'
.show = _name##_show, ^~~~~~~~~~~~
<scratch space>:62:1: note: expanded from here
fw_version_show
^~~~~~~~~~~~~~~
5 errors generated.
vim +252 drivers/input/touchscreen/exc3000.c
47
48 static struct eeti_dev_info exc3000_info[] = {
49 [EETI_EXC3000] = {
50 .name = "EETI EXC3000 Touch Screen",
51 .max_xy = SZ_4K - 1,
52 },
53 [EETI_EXC80H60] = {
54 .name = "EETI EXC80H60 Touch Screen",
> 55 .max_xy = SZ_16K - 1,
56 },
57 [EETI_EXC80H84] = {
58 .name = "EETI EXC80H84 Touch Screen",
59 .max_xy = SZ_16K - 1,
60 },
61 };
62
63 struct exc3000_data {
64 struct i2c_client *client;
65 const struct eeti_dev_info *info;
66 struct input_dev *input;
67 struct touchscreen_properties prop;
68 struct timer_list timer;
69 u8 buf[2 * EXC3000_LEN_FRAME];
70 struct completion wait_event;
71 struct mutex query_lock;
72 int query_result;
73 char model[EXC3000_LEN_MODEL_NAME];
74 char fw_version[EXC3000_LEN_FW_VERSION];
75 };
76
77 static void exc3000_report_slots(struct input_dev *input,
78 struct touchscreen_properties *prop,
79 const u8 *buf, int num)
80 {
81 for (; num--; buf += EXC3000_LEN_POINT) {
82 if (buf[0] & BIT(0)) {
83 input_mt_slot(input, buf[1]);
84 input_mt_report_slot_state(input, MT_TOOL_FINGER, true);
85 touchscreen_report_pos(input, prop,
86 get_unaligned_le16(buf + 2),
87 get_unaligned_le16(buf + 4),
88 true);
89 }
90 }
91 }
92
93 static void exc3000_timer(struct timer_list *t)
94 {
95 struct exc3000_data *data = from_timer(data, t, timer);
96
97 input_mt_sync_frame(data->input);
98 input_sync(data->input);
99 }
100
101 static int exc3000_read_frame(struct exc3000_data *data, u8 *buf)
102 {
103 struct i2c_client *client = data->client;
104 u8 expected_event = EXC3000_MT1_EVENT;
105 int ret;
106
107 if (data->info->max_xy == SZ_16K - 1)
108 expected_event = EXC3000_MT2_EVENT;
109
110 ret = i2c_master_send(client, "'", 2);
111 if (ret < 0)
112 return ret;
113
114 if (ret != 2)
115 return -EIO;
116
117 ret = i2c_master_recv(client, buf, EXC3000_LEN_FRAME);
118 if (ret < 0)
119 return ret;
120
121 if (ret != EXC3000_LEN_FRAME)
122 return -EIO;
123
124 if (get_unaligned_le16(buf) != EXC3000_LEN_FRAME)
125 return -EINVAL;
126
127 if (buf[2] != expected_event)
128 return -EINVAL;
129
130 return 0;
131 }
132
133 static int exc3000_read_data(struct exc3000_data *data,
134 u8 *buf, int *n_slots)
135 {
136 int error;
137
138 error = exc3000_read_frame(data, buf);
139 if (error)
140 return error;
141
142 *n_slots = buf[3];
143 if (!*n_slots || *n_slots > EXC3000_NUM_SLOTS)
144 return -EINVAL;
145
146 if (*n_slots > EXC3000_SLOTS_PER_FRAME) {
147 /* Read 2nd frame to get the rest of the contacts. */
148 error = exc3000_read_frame(data, buf + EXC3000_LEN_FRAME);
149 if (error)
150 return error;
151
152 /* 2nd chunk must have number of contacts set to 0. */
153 if (buf[EXC3000_LEN_FRAME + 3] != 0)
154 return -EINVAL;
155 }
156
157 return 0;
158 }
159
160 static int exc3000_query_interrupt(struct exc3000_data *data)
161 {
162 u8 *buf = data->buf;
163 int err;
164
165 err = i2c_master_recv(data->client, buf, EXC3000_LEN_FRAME);
166 if (err < 0)
167 return err;
168
169 if (buf[0] != 0x42)
170 return -EPROTO;
171
172 if (buf[4] == 'E')
173 strlcpy(data->model, buf+5, sizeof(data->model));
174 else if (buf[4] == 'D')
175 strlcpy(data->fw_version, buf+5, sizeof(data->fw_version));
176 else
177 return -EPROTO;
178
179 return 0;
180 }
181
182 static irqreturn_t exc3000_interrupt(int irq, void *dev_id)
183 {
184 struct exc3000_data *data = dev_id;
185 struct input_dev *input = data->input;
186 u8 *buf = data->buf;
187 int slots, total_slots;
188 int error;
189
190 if (mutex_is_locked(&data->query_lock)) {
191 data->query_result = exc3000_query_interrupt(data);
192 complete(&data->wait_event);
193 goto out;
194 }
195
196 error = exc3000_read_data(data, buf, &total_slots);
197 if (error) {
198 /* Schedule a timer to release "stuck" contacts */
199 mod_timer(&data->timer,
200 jiffies + msecs_to_jiffies(EXC3000_TIMEOUT_MS));
201 goto out;
202 }
203
204 /*
205 * We read full state successfully, no contacts will be "stuck".
206 */
207 del_timer_sync(&data->timer);
208
209 while (total_slots > 0) {
210 slots = min(total_slots, EXC3000_SLOTS_PER_FRAME);
211 exc3000_report_slots(input, &data->prop, buf + 4, slots);
212 total_slots -= slots;
213 buf += EXC3000_LEN_FRAME;
214 }
215
216 input_mt_sync_frame(input);
217 input_sync(input);
218
219 out:
220 return IRQ_HANDLED;
221 }
222
223 static int fw_version_show(struct device *dev,
224 struct device_attribute *attr, char *buf)
225 {
226 struct exc3000_data *data = dev_get_drvdata(dev);
227 static const u8 request[68] = {
228 0x67, 0x00, 0x42, 0x00, 0x03, 0x01, 'D', 0x00
229 };
230 struct i2c_client *client = data->client;
231 int err;
232
233 mutex_lock(&data->query_lock);
234
235 data->query_result = -ETIMEDOUT;
236 reinit_completion(&data->wait_event);
237
238 err = i2c_master_send(client, request, sizeof(request));
239 if (err < 0) {
240 mutex_unlock(&data->query_lock);
241 return err;
242 }
243
244 wait_for_completion_interruptible_timeout(&data->wait_event, 1*HZ);
245 mutex_unlock(&data->query_lock);
246
247 if (data->query_result < 0)
248 return data->query_result;
249
250 return sprintf(buf, "%s\n", data->fw_version);
251 }
> 252 static DEVICE_ATTR_RO(fw_version);
253
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]
Hi Sebastian,
I love your patch! Yet something to improve:
[auto build test ERROR on input/next]
[also build test ERROR on v5.7-rc6 next-20200519]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Sebastian-Reichel/EXC3000-Updates/20200520-023207
base: https://git.kernel.org/pub/scm/linux/kernel/git/dtor/input.git next
config: ia64-randconfig-r023-20200519 (attached as .config)
compiler: ia64-linux-gcc (GCC) 9.3.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=ia64
If you fix the issue, kindly add following tag as appropriate
Reported-by: kbuild test robot <[email protected]>
All error/warnings (new ones prefixed by >>, old ones prefixed by <<):
In file included from include/linux/kobject.h:20,
from include/linux/device.h:17,
from drivers/input/touchscreen/exc3000.c:11:
>> drivers/input/touchscreen/exc3000.c:252:23: error: initialization of 'ssize_t (*)(struct device *, struct device_attribute *, char *)' {aka 'long int (*)(struct device *, struct device_attribute *, char *)'} from incompatible pointer type 'int (*)(struct device *, struct device_attribute *, char *)' [-Werror=incompatible-pointer-types]
252 | static DEVICE_ATTR_RO(fw_version);
| ^~~~~~~~~~
include/linux/sysfs.h:117:10: note: in definition of macro '__ATTR_RO'
117 | .show = _name##_show, | ^~~~~
>> drivers/input/touchscreen/exc3000.c:252:8: note: in expansion of macro 'DEVICE_ATTR_RO'
252 | static DEVICE_ATTR_RO(fw_version);
| ^~~~~~~~~~~~~~
drivers/input/touchscreen/exc3000.c:252:23: note: (near initialization for 'dev_attr_fw_version.show')
252 | static DEVICE_ATTR_RO(fw_version);
| ^~~~~~~~~~
include/linux/sysfs.h:117:10: note: in definition of macro '__ATTR_RO'
117 | .show = _name##_show, | ^~~~~
>> drivers/input/touchscreen/exc3000.c:252:8: note: in expansion of macro 'DEVICE_ATTR_RO'
252 | static DEVICE_ATTR_RO(fw_version);
| ^~~~~~~~~~~~~~
cc1: some warnings being treated as errors
vim +252 drivers/input/touchscreen/exc3000.c
222
223 static int fw_version_show(struct device *dev,
224 struct device_attribute *attr, char *buf)
225 {
226 struct exc3000_data *data = dev_get_drvdata(dev);
227 static const u8 request[68] = {
228 0x67, 0x00, 0x42, 0x00, 0x03, 0x01, 'D', 0x00
229 };
230 struct i2c_client *client = data->client;
231 int err;
232
233 mutex_lock(&data->query_lock);
234
235 data->query_result = -ETIMEDOUT;
236 reinit_completion(&data->wait_event);
237
238 err = i2c_master_send(client, request, sizeof(request));
239 if (err < 0) {
240 mutex_unlock(&data->query_lock);
241 return err;
242 }
243
244 wait_for_completion_interruptible_timeout(&data->wait_event, 1*HZ);
245 mutex_unlock(&data->query_lock);
246
247 if (data->query_result < 0)
248 return data->query_result;
249
250 return sprintf(buf, "%s\n", data->fw_version);
251 }
> 252 static DEVICE_ATTR_RO(fw_version);
253
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]