Hi,
This is PATCHv3 of the EXC80Hxx support patchset.
Changes since [PATCHv2]:
- add #include <linux/size.h> for SZ_4K and SZ_16K (kbuild test bot)
- fw_version_show must be ssize_t (kbuild test bot)
- rename YAML binding file to include eeti, prefix (Enric)
- noise from gpio-reset patch (Enric)
- add comment for the retry loop (Enric, Martin)
- document sysfs entries (Enric)
Changes 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/
Thanks in advance for looking at the patches,
-- Sebastian
[PATCHv2] https://lore.kernel.org/linux-input/[email protected]/
[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
.../ABI/testing/sysfs-driver-input-exc3000 | 15 ++
.../input/touchscreen/eeti,exc3000.yaml | 58 +++++
.../bindings/input/touchscreen/exc3000.txt | 26 --
drivers/input/touchscreen/exc3000.c | 245 ++++++++++++++++--
4 files changed, 301 insertions(+), 43 deletions(-)
create mode 100644 Documentation/ABI/testing/sysfs-driver-input-exc3000
create mode 100644 Documentation/devicetree/bindings/input/touchscreen/eeti,exc3000.yaml
delete mode 100644 Documentation/devicetree/bindings/input/touchscreen/exc3000.txt
--
2.26.2
This adds support for EXC80H60 and EXCH84 controllers, which
use a different event type id and have two extra bits for the
resolution (so the maximum is 16K instead of 4K).
Signed-off-by: Sebastian Reichel <[email protected]>
---
.../input/touchscreen/eeti,exc3000.yaml | 5 +-
drivers/input/touchscreen/exc3000.c | 80 +++++++++++++++----
2 files changed, 70 insertions(+), 15 deletions(-)
diff --git a/Documentation/devicetree/bindings/input/touchscreen/eeti,exc3000.yaml b/Documentation/devicetree/bindings/input/touchscreen/eeti,exc3000.yaml
index 022aa69a5dfe..7e6e23f8fa00 100644
--- a/Documentation/devicetree/bindings/input/touchscreen/eeti,exc3000.yaml
+++ b/Documentation/devicetree/bindings/input/touchscreen/eeti,exc3000.yaml
@@ -14,7 +14,10 @@ allOf:
properties:
compatible:
- const: eeti,exc3000
+ enum:
+ - eeti,exc3000
+ - eeti,exc80h60
+ - eeti,exc80h84
reg:
const: 0x2a
interrupts:
diff --git a/drivers/input/touchscreen/exc3000.c b/drivers/input/touchscreen/exc3000.c
index 555a14305cd4..b497bd2ae41d 100644
--- a/drivers/input/touchscreen/exc3000.c
+++ b/drivers/input/touchscreen/exc3000.c
@@ -16,6 +16,7 @@
#include <linux/interrupt.h>
#include <linux/module.h>
#include <linux/of.h>
+#include <linux/sizes.h>
#include <linux/timer.h>
#include <asm/unaligned.h>
@@ -23,11 +24,43 @@
#define EXC3000_SLOTS_PER_FRAME 5
#define EXC3000_LEN_FRAME 66
#define EXC3000_LEN_POINT 10
-#define EXC3000_MT_EVENT 6
+
+#define EXC3000_MT1_EVENT 0x06
+#define EXC3000_MT2_EVENT 0x18
+
#define EXC3000_TIMEOUT_MS 100
+static const struct i2c_device_id exc3000_id[];
+
+struct eeti_dev_info {
+ const char *name;
+ int max_xy;
+};
+
+enum eeti_dev_id {
+ EETI_EXC3000,
+ EETI_EXC80H60,
+ EETI_EXC80H84,
+};
+
+static struct eeti_dev_info exc3000_info[] = {
+ [EETI_EXC3000] = {
+ .name = "EETI EXC3000 Touch Screen",
+ .max_xy = SZ_4K - 1,
+ },
+ [EETI_EXC80H60] = {
+ .name = "EETI EXC80H60 Touch Screen",
+ .max_xy = SZ_16K - 1,
+ },
+ [EETI_EXC80H84] = {
+ .name = "EETI EXC80H84 Touch Screen",
+ .max_xy = SZ_16K - 1,
+ },
+};
+
struct exc3000_data {
struct i2c_client *client;
+ const struct eeti_dev_info *info;
struct input_dev *input;
struct touchscreen_properties prop;
struct timer_list timer;
@@ -58,10 +91,15 @@ static void exc3000_timer(struct timer_list *t)
input_sync(data->input);
}
-static int exc3000_read_frame(struct i2c_client *client, u8 *buf)
+static int exc3000_read_frame(struct exc3000_data *data, u8 *buf)
{
+ struct i2c_client *client = data->client;
+ u8 expected_event = EXC3000_MT1_EVENT;
int ret;
+ if (data->info->max_xy == SZ_16K - 1)
+ expected_event = EXC3000_MT2_EVENT;
+
ret = i2c_master_send(client, "'", 2);
if (ret < 0)
return ret;
@@ -76,19 +114,21 @@ static int exc3000_read_frame(struct i2c_client *client, u8 *buf)
if (ret != EXC3000_LEN_FRAME)
return -EIO;
- if (get_unaligned_le16(buf) != EXC3000_LEN_FRAME ||
- buf[2] != EXC3000_MT_EVENT)
+ if (get_unaligned_le16(buf) != EXC3000_LEN_FRAME)
+ return -EINVAL;
+
+ if (buf[2] != expected_event)
return -EINVAL;
return 0;
}
-static int exc3000_read_data(struct i2c_client *client,
+static int exc3000_read_data(struct exc3000_data *data,
u8 *buf, int *n_slots)
{
int error;
- error = exc3000_read_frame(client, buf);
+ error = exc3000_read_frame(data, buf);
if (error)
return error;
@@ -98,7 +138,7 @@ static int exc3000_read_data(struct i2c_client *client,
if (*n_slots > EXC3000_SLOTS_PER_FRAME) {
/* Read 2nd frame to get the rest of the contacts. */
- error = exc3000_read_frame(client, buf + EXC3000_LEN_FRAME);
+ error = exc3000_read_frame(data, buf + EXC3000_LEN_FRAME);
if (error)
return error;
@@ -118,7 +158,7 @@ static irqreturn_t exc3000_interrupt(int irq, void *dev_id)
int slots, total_slots;
int error;
- error = exc3000_read_data(data->client, buf, &total_slots);
+ error = exc3000_read_data(data, buf, &total_slots);
if (error) {
/* Schedule a timer to release "stuck" contacts */
mod_timer(&data->timer,
@@ -149,13 +189,19 @@ static int exc3000_probe(struct i2c_client *client)
{
struct exc3000_data *data;
struct input_dev *input;
- int error;
+ int error, max_xy;
data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
if (!data)
return -ENOMEM;
data->client = client;
+ data->info = device_get_match_data(&client->dev);
+ if (!data->info) {
+ enum eeti_dev_id eeti_dev_id =
+ i2c_match_id(exc3000_id, client)->driver_data;
+ data->info = &exc3000_info[eeti_dev_id];
+ }
timer_setup(&data->timer, exc3000_timer, 0);
input = devm_input_allocate_device(&client->dev);
@@ -164,11 +210,13 @@ static int exc3000_probe(struct i2c_client *client)
data->input = input;
- input->name = "EETI EXC3000 Touch Screen";
+ input->name = data->info->name;
input->id.bustype = BUS_I2C;
- input_set_abs_params(input, ABS_MT_POSITION_X, 0, 4095, 0, 0);
- input_set_abs_params(input, ABS_MT_POSITION_Y, 0, 4095, 0, 0);
+ max_xy = data->info->max_xy;
+ input_set_abs_params(input, ABS_MT_POSITION_X, 0, max_xy, 0, 0);
+ input_set_abs_params(input, ABS_MT_POSITION_Y, 0, max_xy, 0, 0);
+
touchscreen_parse_properties(input, true, &data->prop);
error = input_mt_init_slots(input, EXC3000_NUM_SLOTS,
@@ -190,14 +238,18 @@ static int exc3000_probe(struct i2c_client *client)
}
static const struct i2c_device_id exc3000_id[] = {
- { "exc3000", 0 },
+ { "exc3000", EETI_EXC3000 },
+ { "exc80h60", EETI_EXC80H60 },
+ { "exc80h84", EETI_EXC80H84 },
{ }
};
MODULE_DEVICE_TABLE(i2c, exc3000_id);
#ifdef CONFIG_OF
static const struct of_device_id exc3000_of_match[] = {
- { .compatible = "eeti,exc3000" },
+ { .compatible = "eeti,exc3000", .data = &exc3000_info[EETI_EXC3000] },
+ { .compatible = "eeti,exc80h60", .data = &exc3000_info[EETI_EXC80H60] },
+ { .compatible = "eeti,exc80h84", .data = &exc3000_info[EETI_EXC80H84] },
{ }
};
MODULE_DEVICE_TABLE(of, exc3000_of_match);
--
2.26.2
Add basic support for an optional reset gpio.
Signed-off-by: Sebastian Reichel <[email protected]>
---
.../input/touchscreen/eeti,exc3000.yaml | 2 ++
drivers/input/touchscreen/exc3000.c | 17 +++++++++++++++++
2 files changed, 19 insertions(+)
diff --git a/Documentation/devicetree/bindings/input/touchscreen/eeti,exc3000.yaml b/Documentation/devicetree/bindings/input/touchscreen/eeti,exc3000.yaml
index 7e6e23f8fa00..007adbc89c14 100644
--- a/Documentation/devicetree/bindings/input/touchscreen/eeti,exc3000.yaml
+++ b/Documentation/devicetree/bindings/input/touchscreen/eeti,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 b5a3bbb63504..de9d0ae1210a 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>
@@ -33,6 +35,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 {
@@ -66,6 +71,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;
@@ -325,6 +331,17 @@ static int exc3000_probe(struct i2c_client *client)
init_completion(&data->wait_event);
mutex_init(&data->query_lock);
+ data->reset = devm_gpiod_get_optional(&client->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(&client->dev);
if (!input)
return -ENOMEM;
--
2.26.2
Hi Sebastian,
On 20/5/20 17:39, Sebastian Reichel wrote:
> Add basic support for an optional reset gpio.
>
> Signed-off-by: Sebastian Reichel <[email protected]>
Thanks to address the comments I did in second version. so,
Reviewed-by: Enric Balletbo i Serra <[email protected]>
> ---
> .../input/touchscreen/eeti,exc3000.yaml | 2 ++
> drivers/input/touchscreen/exc3000.c | 17 +++++++++++++++++
> 2 files changed, 19 insertions(+)
>
> diff --git a/Documentation/devicetree/bindings/input/touchscreen/eeti,exc3000.yaml b/Documentation/devicetree/bindings/input/touchscreen/eeti,exc3000.yaml
> index 7e6e23f8fa00..007adbc89c14 100644
> --- a/Documentation/devicetree/bindings/input/touchscreen/eeti,exc3000.yaml
> +++ b/Documentation/devicetree/bindings/input/touchscreen/eeti,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 b5a3bbb63504..de9d0ae1210a 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>
> @@ -33,6 +35,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 {
> @@ -66,6 +71,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;
> @@ -325,6 +331,17 @@ static int exc3000_probe(struct i2c_client *client)
> init_completion(&data->wait_event);
> mutex_init(&data->query_lock);
>
> + data->reset = devm_gpiod_get_optional(&client->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(&client->dev);
> if (!input)
> return -ENOMEM;
>
Hi Sebastian,
On Wed, May 20, 2020 at 05:39:34PM +0200, Sebastian Reichel wrote:
>
> data->client = client;
> + data->info = device_get_match_data(&client->dev);
> + if (!data->info) {
> + enum eeti_dev_id eeti_dev_id =
> + i2c_match_id(exc3000_id, client)->driver_data;
I believe i2c devices can be instantiated via sysfs, so I think we
better handle case where we can't find matching id. Also driver_data is
enough to store a pointer, maybe we can have individual structures
instead of using an array and indexing here?
Thanks.
--
Dmitry
Hi,
On Wed, May 20, 2020 at 10:45:19AM -0700, Dmitry Torokhov wrote:
> Hi Sebastian,
>
> On Wed, May 20, 2020 at 05:39:34PM +0200, Sebastian Reichel wrote:
> >
> > data->client = client;
> > + data->info = device_get_match_data(&client->dev);
The above is for DT (and ACPI, but driver has no ACPI table).
> > + if (!data->info) {
> > + enum eeti_dev_id eeti_dev_id =
> > + i2c_match_id(exc3000_id, client)->driver_data;
>
> I believe i2c devices can be instantiated via sysfs, so I think we
> better handle case where we can't find matching id. Also driver_data is
> enough to store a pointer, maybe we can have individual structures
> instead of using an array and indexing here?
The above code is only for exactly this usecase (loading via sysfs).
There is zero chance, that we cannot find matching id. The sysfs
based probing works by providing the device address and the name
listed in driver's id_table. I took the above code style from
drivers/i2c/muxes/i2c-mux-ltc4306.c.
We can store the pointer directly in i2c_device_id's driver_data
field, but that requires two type casts (field is ulong instead
of pointer). The array variant feels a bit cleaner to me.
-- Sebastian
On Wed, May 20, 2020 at 11:20:03PM +0200, Sebastian Reichel wrote:
> Hi,
>
> On Wed, May 20, 2020 at 10:45:19AM -0700, Dmitry Torokhov wrote:
> > Hi Sebastian,
> >
> > On Wed, May 20, 2020 at 05:39:34PM +0200, Sebastian Reichel wrote:
> > >
> > > data->client = client;
> > > + data->info = device_get_match_data(&client->dev);
>
> The above is for DT (and ACPI, but driver has no ACPI table).
>
> > > + if (!data->info) {
> > > + enum eeti_dev_id eeti_dev_id =
> > > + i2c_match_id(exc3000_id, client)->driver_data;
> >
> > I believe i2c devices can be instantiated via sysfs, so I think we
> > better handle case where we can't find matching id. Also driver_data is
> > enough to store a pointer, maybe we can have individual structures
> > instead of using an array and indexing here?
>
> The above code is only for exactly this usecase (loading via sysfs).
> There is zero chance, that we cannot find matching id. The sysfs
> based probing works by providing the device address and the name
> listed in driver's id_table. I took the above code style from
> drivers/i2c/muxes/i2c-mux-ltc4306.c.
Ah, OK, so i2c does not provide the "new_id" attribute to extend the
match table.
>
> We can store the pointer directly in i2c_device_id's driver_data
> field, but that requires two type casts (field is ulong instead
> of pointer). The array variant feels a bit cleaner to me.
OK, fair enough. I'll wait for Rob to ack the yaml conversion and will
apply.
Thanks.
--
Dmitry