diff mbox

[2/2] input: goodix: Add device tree support for 5-finger chips

Message ID 1425458053-4559-1-git-send-email-mamlinav@gmail.com
State Superseded, archived
Headers show

Commit Message

Aleksei Mamlin March 4, 2015, 8:34 a.m. UTC
This patch adds device tree support for 5-finger chips, like GT911 and GT912.

Signed-off-by: Aleksei Mamlin <mamlinav@gmail.com>
Acked-by: Hans de Goede <hdegoede@redhat.com>
---
 .../bindings/input/touchscreen/goodix.txt          |  4 ++-
 drivers/input/touchscreen/goodix.c                 | 40 +++++++++++++++++-----
 2 files changed, 35 insertions(+), 9 deletions(-)

Comments

Bastien Nocera March 4, 2015, 9:19 a.m. UTC | #1
On Wed, 2015-03-04 at 11:34 +0300, Aleksei Mamlin wrote:
> This patch adds device tree support for 5-finger chips, like GT911 
> and GT912.

You should add the same support to the ACPI matching.

<snip>
>  #ifdef CONFIG_OF
>  static struct of_device_id goodix_of_match[] = {
> -       { .compatible = "goodix,gt9110" },
> -       { .compatible = "goodix,gt927" },
> -       { .compatible = "goodix,gt9271" },
> -       { .compatible = "goodix,gt928" },
> -       { .compatible = "goodix,gt967" },
> +       { .compatible = "goodix,gt911",  .data = (void *) 5 },
> +       { .compatible = "goodix,gt9110", .data = (void *) 10 },

There's no need to add "10" for these tablets as it's already the 
GOODIX_MAX_CONTACTS value. Or you need to add it to every instance.

I would also like a link to the spec sheets in the commit message.

> +       { .compatible = "goodix,gt912",  .data = (void *) 5 },
> +       { .compatible = "goodix,gt927",  .data = (void *) 10 },
> +       { .compatible = "goodix,gt9271", .data = (void *) 10 },
> +       { .compatible = "goodix,gt928",  .data = (void *) 10 },
> +       { .compatible = "goodix,gt967",  .data = (void *) 10 },
>         { }
>  };
>  MODULE_DEVICE_TABLE(of, goodix_of_match);
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Antonio Ospite March 4, 2015, 10:30 a.m. UTC | #2
On Wed,  4 Mar 2015 11:34:13 +0300
Aleksei Mamlin <mamlinav@gmail.com> wrote:

> This patch adds device tree support for 5-finger chips, like GT911 and GT912.
>

Hi Aleksei,

from a datasheet I found[1](Pag. 11) I see that some devices provide
the information about the max number of touch points in register 0x804C.

Have you tried if this is true on your 5-finger devices too?
If so, please use this mechanism to populate ts->max_touch_num to avoid
passing hardcoded data.

Thanks,
   Antonio

[1] http://www.wpgholdings.com/uploads/bu/bu_3/MID_20141112/GT9271_Datasheet_20130904.pdf
Aleksei Mamlin March 4, 2015, 10:55 a.m. UTC | #3
On Wed, 4 Mar 2015 11:30:40 +0100
Antonio Ospite <ao2@ao2.it> wrote:

> On Wed,  4 Mar 2015 11:34:13 +0300
> Aleksei Mamlin <mamlinav@gmail.com> wrote:
> 
> > This patch adds device tree support for 5-finger chips, like GT911 and GT912.
> >
> 
> Hi Aleksei,
> 
> from a datasheet I found[1](Pag. 11) I see that some devices provide
> the information about the max number of touch points in register 0x804C.
> 
> Have you tried if this is true on your 5-finger devices too?
> If so, please use this mechanism to populate ts->max_touch_num to avoid
> passing hardcoded data.
> 
Hi Antonio,

I checked datasheets and you are right, seems that all Goodix GT9xx series provides max number of touch points in register 0x804C.
I'll rewrite driver to use data from 0x804C register.


> Thanks,
>    Antonio
> 
> [1] http://www.wpgholdings.com/uploads/bu/bu_3/MID_20141112/GT9271_Datasheet_20130904.pdf
> 
> -- 
> Antonio Ospite
> http://ao2.it
> 
> A: Because it messes up the order in which people normally read text.
>    See http://en.wikipedia.org/wiki/Posting_style
> Q: Why is top-posting such a bad thing?
Aleksei Mamlin March 4, 2015, 5:53 p.m. UTC | #4
On Wed, 04 Mar 2015 10:19:08 +0100
Bastien Nocera <hadess@hadess.net> wrote:

> On Wed, 2015-03-04 at 11:34 +0300, Aleksei Mamlin wrote:
> > This patch adds device tree support for 5-finger chips, like GT911 
> > and GT912.
> 
> You should add the same support to the ACPI matching.

Hi Bastien,

I never seen ACPI ids for GT911 or GT912. It seems they are used only on Andriod tablets.

> 
> <snip>
> >  #ifdef CONFIG_OF
> >  static struct of_device_id goodix_of_match[] = {
> > -       { .compatible = "goodix,gt9110" },
> > -       { .compatible = "goodix,gt927" },
> > -       { .compatible = "goodix,gt9271" },
> > -       { .compatible = "goodix,gt928" },
> > -       { .compatible = "goodix,gt967" },
> > +       { .compatible = "goodix,gt911",  .data = (void *) 5 },
> > +       { .compatible = "goodix,gt9110", .data = (void *) 10 },
> 
> There's no need to add "10" for these tablets as it's already the 
> GOODIX_MAX_CONTACTS value. Or you need to add it to every instance.

Antonio Ospite showed me another way to set the max number of touch points.

> 
> I would also like a link to the spec sheets in the commit message.
> 
> > +       { .compatible = "goodix,gt912",  .data = (void *) 5 },
> > +       { .compatible = "goodix,gt927",  .data = (void *) 10 },
> > +       { .compatible = "goodix,gt9271", .data = (void *) 10 },
> > +       { .compatible = "goodix,gt928",  .data = (void *) 10 },
> > +       { .compatible = "goodix,gt967",  .data = (void *) 10 },
> >         { }
> >  };
> >  MODULE_DEVICE_TABLE(of, goodix_of_match);
diff mbox

Patch

diff --git a/Documentation/devicetree/bindings/input/touchscreen/goodix.txt b/Documentation/devicetree/bindings/input/touchscreen/goodix.txt
index cbaf085..368e57f 100644
--- a/Documentation/devicetree/bindings/input/touchscreen/goodix.txt
+++ b/Documentation/devicetree/bindings/input/touchscreen/goodix.txt
@@ -2,7 +2,9 @@  Device tree bindings for Goodix GT9xx series touchscreen controller
 
 Required properties:
 
- - compatible		: Should be "goodix,gt9110"
+ - compatible		: Should be "goodix,gt911"
+				 or "goodix,gt9110"
+				 or "goodix,gt912"
 				 or "goodix,gt927"
 				 or "goodix,gt9271"
 				 or "goodix,gt928"
diff --git a/drivers/input/touchscreen/goodix.c b/drivers/input/touchscreen/goodix.c
index 16f016a..3da31d1 100644
--- a/drivers/input/touchscreen/goodix.c
+++ b/drivers/input/touchscreen/goodix.c
@@ -25,6 +25,7 @@ 
 #include <linux/slab.h>
 #include <linux/acpi.h>
 #include <linux/of.h>
+#include <linux/of_device.h>
 #include <asm/unaligned.h>
 
 struct goodix_ts_data {
@@ -101,7 +102,7 @@  static int goodix_ts_read_input_report(struct goodix_ts_data *ts, u8 *data)
 	}
 
 	touch_num = data[0] & 0x0f;
-	if (touch_num > GOODIX_MAX_CONTACTS)
+	if (touch_num > ts->max_touch_num)
 		return -EPROTO;
 
 	if (touch_num > 1) {
@@ -143,7 +144,7 @@  static void goodix_ts_report_touch(struct goodix_ts_data *ts, u8 *coor_data)
  */
 static void goodix_process_events(struct goodix_ts_data *ts)
 {
-	u8  point_data[1 + GOODIX_CONTACT_SIZE * GOODIX_MAX_CONTACTS];
+	u8  point_data[1 + GOODIX_CONTACT_SIZE * ts->max_touch_num];
 	int touch_num;
 	int i;
 
@@ -297,7 +298,7 @@  static int goodix_request_input_dev(struct goodix_ts_data *ts)
 	input_set_abs_params(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0);
 	input_set_abs_params(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
 
-	input_mt_init_slots(ts->input_dev, GOODIX_MAX_CONTACTS,
+	input_mt_init_slots(ts->input_dev, ts->max_touch_num,
 			    INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED);
 
 	ts->input_dev->name = "Goodix Capacitive TouchScreen";
@@ -317,9 +318,16 @@  static int goodix_request_input_dev(struct goodix_ts_data *ts)
 	return 0;
 }
 
+#ifdef CONFIG_OF
+static struct of_device_id goodix_of_match[];
+#endif
+
 static int goodix_ts_probe(struct i2c_client *client,
 			   const struct i2c_device_id *id)
 {
+#ifdef CONFIG_OF
+	const struct of_device_id *match;
+#endif
 	struct goodix_ts_data *ts;
 	unsigned long irq_flags;
 	int error;
@@ -336,6 +344,20 @@  static int goodix_ts_probe(struct i2c_client *client,
 	if (!ts)
 		return -ENOMEM;
 
+	ts->max_touch_num = GOODIX_MAX_CONTACTS;
+
+#ifdef CONFIG_OF
+	if (client->dev.of_node) {
+		match = of_match_device(of_match_ptr(goodix_of_match),
+							&client->dev);
+		if (!match) {
+			dev_err(&client->dev, "Unknown device model\n");
+			return -EINVAL;
+		}
+		ts->max_touch_num = (unsigned int)match->data;
+	}
+#endif
+
 	ts->client = client;
 	i2c_set_clientdata(client, ts);
 
@@ -384,11 +406,13 @@  MODULE_DEVICE_TABLE(acpi, goodix_acpi_match);
 
 #ifdef CONFIG_OF
 static struct of_device_id goodix_of_match[] = {
-	{ .compatible = "goodix,gt9110" },
-	{ .compatible = "goodix,gt927" },
-	{ .compatible = "goodix,gt9271" },
-	{ .compatible = "goodix,gt928" },
-	{ .compatible = "goodix,gt967" },
+	{ .compatible = "goodix,gt911",  .data = (void *) 5 },
+	{ .compatible = "goodix,gt9110", .data = (void *) 10 },
+	{ .compatible = "goodix,gt912",  .data = (void *) 5 },
+	{ .compatible = "goodix,gt927",  .data = (void *) 10 },
+	{ .compatible = "goodix,gt9271", .data = (void *) 10 },
+	{ .compatible = "goodix,gt928",  .data = (void *) 10 },
+	{ .compatible = "goodix,gt967",  .data = (void *) 10 },
 	{ }
 };
 MODULE_DEVICE_TABLE(of, goodix_of_match);