Skip to contentSkip to conversation

input: add driver for pixcir i2c touchscreens

PATCH In review jcbian 3 participants 8 messages May 24, 2011 – Jul 23, 2011

Subsystems (2)
lore
Share & tools
lore

jcbian

author
#0 lore raw

PATCH v3 1/1 input: add driver for pixcir i2c touchscreens

Hi all,

This patch adds a driver for PIXCIR's I2C connected touchscreens. Request the IRQ by doing request_threaded_irq() as v3.

---
 drivers/input/touchscreen/Kconfig         |   12 ++
 drivers/input/touchscreen/Makefile        |    1 +
 drivers/input/touchscreen/pixcir_i2c_ts.c |  269
+++++++++++++++++++++++++++++
 drivers/input/touchscreen/pixcir_i2c_ts.h |   13 ++
 4 files changed, 295 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/touchscreen/pixcir_i2c_ts.c
 create mode 100644 drivers/input/touchscreen/pixcir_i2c_ts.h
(quoted diff) +0 -0

b/drivers/input/touchscreen/Kconfig
index 434fd80..e91f40f 100644

drivers/input/touchscreen/Kconfig +12 -0
@@ -714,4 +714,16 @@ config TOUCHSCREEN_TPS6507X
 	  To compile this driver as a module, choose M here: the
 	  module will be called tps6507x_ts.
 
+config TOUCHSCREEN_PIXCIR
+	tristate "PIXCIR I2C touchscreens"
+	depends on I2C
+	help
+	  Say Y here if you have a pixcir i2c touchscreen
+	  controller.
+
+	  If unsure, say N.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called pixcir_i2c_ts.
+
 endif
(quoted diff) +0 -0

b/drivers/input/touchscreen/Makefile
index ca94098..585c0f0 100644

drivers/input/touchscreen/Makefile +1 -0
@@ -38,6 +38,7 @@ obj-$(CONFIG_TOUCHSCREEN_HTCPEN)	+= htcpen.o
 obj-$(CONFIG_TOUCHSCREEN_USB_COMPOSITE)	+= usbtouchscreen.o
 obj-$(CONFIG_TOUCHSCREEN_PCAP)		+= pcap_ts.o
 obj-$(CONFIG_TOUCHSCREEN_PENMOUNT)	+= penmount.o
+obj-$(CONFIG_TOUCHSCREEN_PIXCIR)	+= pixcir_i2c_ts.o
 obj-$(CONFIG_TOUCHSCREEN_S3C2410)	+= s3c2410_ts.o
 obj-$(CONFIG_TOUCHSCREEN_ST1232)	+= st1232.o
 obj-$(CONFIG_TOUCHSCREEN_STMPE)		+= stmpe-ts.o
(quoted diff) +0 -0

b/drivers/input/touchscreen/pixcir_i2c_ts.c
new file mode 100644
index 0000000..b734813

drivers/input/touchscreen/pixcir_i2c_ts.c new file +17 -0
@@ -0,0 +1,269 @@
+/* drivers/input/touchscreen/pixcir_i2c_ts.c
+ *
+ * Copyright (C) 2010-2011 Pixcir, Inc.
+ * V1.0
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307

USA
+ */
+#include <linux/module.h>
+#include <linux/interrupt.h>
+#include <linux/workqueue.h>
+#include <linux/slab.h>
+#include <linux/input.h>
+#include <linux/i2c.h>
+#include "pixcir_i2c_ts.h"
+
+struct pixcir_i2c_ts_data {
+ struct i2c_client *client;
+ struct input_dev *input;
+ wait_queue_head_t wait;
+ const struct pixcir_i2c_ts_platform *chip;
+ unsigned int attb_pin;
+ int irq;
+};
+
+static int pixcir_ts_poscheck(struct pixcir_i2c_ts_data *data) +{
+ struct pixcir_i2c_ts_data *tsdata = data;
+
+ u8 touching, oldtouching;
+ u16 posx1, posy1, posx2, posy2;
+ u8 rdbuf[10], wrbuf[1];
+ int ret;
+
+ memset(wrbuf, 0, sizeof(wrbuf));
+ memset(rdbuf, 0, sizeof(rdbuf));
+
+ wrbuf[0] = 0;
+ ret = i2c_master_send(tsdata->client, wrbuf, 1);
+ if (ret != 1) {
+ dev_err(&tsdata->client->dev, "Unable to write to i2c touchscreen!\n");
+ goto out;
+ }
+
+ ret = i2c_master_recv(tsdata->client, rdbuf, sizeof(rdbuf));
+ if (ret != sizeof(rdbuf)) {
+ dev_err(&tsdata->client->dev, "Unable to read i2c page!\n");
+ goto out;
+ }
+
+ touching = rdbuf[0];
+ oldtouching = rdbuf[1];

+	posx1 = ((rdbuf[3] << 8) | rdbuf[2]);
+	posy1 = ((rdbuf[5] << 8) | rdbuf[4]);
+	posx2 = ((rdbuf[7] << 8) | rdbuf[6]);
+	posy2 = ((rdbuf[9] << 8) | rdbuf[8]);

+
+ input_report_key(tsdata->input, BTN_TOUCH, touching);
+
+ if (touching == 1) {
+ input_report_abs(tsdata->input, ABS_X, posx1);
+ input_report_abs(tsdata->input, ABS_Y, posy1);
+ }
+
+ if (touching == 2) {
+ input_report_abs(tsdata->input, ABS_MT_POSITION_X, posx1);
+ input_report_abs(tsdata->input, ABS_MT_POSITION_Y, posy1);
+ input_mt_sync(tsdata->input);
+
+ input_report_abs(tsdata->input, ABS_MT_POSITION_X, posx2);
+ input_report_abs(tsdata->input, ABS_MT_POSITION_Y, posy2);
+ input_mt_sync(tsdata->input);
+ } else
+ input_mt_sync(tsdata->input);
+ input_sync(tsdata->input);
+
+ return 0;
+
+out:
+ return -EINVAL;
+}
+
+static irqreturn_t pixcir_ts_isr(int irq, void *dev_id) +{
+ struct pixcir_i2c_ts_data *tsdata = dev_id;
+
+ do {
+ pixcir_ts_poscheck(tsdata);
+ tsdata->attb_pin = tsdata->chip->attb_read_val();
+ if (tsdata->attb_pin == ATTB_PIN_LOW)
+ wait_event_timeout(tsdata->wait, TRUE,
+ msecs_to_jiffies(20));
+ } while (!tsdata->attb_pin);
+
+ return IRQ_HANDLED;
+}
+
+static void pixcir_ts_close(struct input_dev *dev) +{
+
+}
+
+static int pixcir_i2c_ts_probe(struct i2c_client *client,
+ const struct i2c_device_id *id)
+{
+ struct pixcir_i2c_ts_data *tsdata;
+ struct input_dev *input;
+ const struct pixcir_i2c_ts_platform *pdata =
+ client->dev.platform_data;
+ int error;
+
+ if (!pdata) {
+ dev_err(&client->dev, "platform data not defined\n");
+ return -EINVAL;
+ }
+
+ tsdata = kzalloc(sizeof(*tsdata), GFP_KERNEL);
+ if (!tsdata) {
+ dev_err(&client->dev, "Failed to allocate driver data!\n");
+ error = -ENOMEM;
+ dev_set_drvdata(&client->dev, NULL);
+ return error;
+ }
+
+ dev_set_drvdata(&client->dev, tsdata);
+
+ input = input_allocate_device();
+ if (!input) {
+ dev_err(&client->dev, "Failed to allocate input device!\n");
+ error = -ENOMEM;
+ input_free_device(input);
+ kfree(tsdata);
+ }
+
+ init_waitqueue_head(&tsdata->wait);
+
+ input->name = client->name;
+ input->id.bustype = BUS_I2C;
+ input->dev.parent = &client->dev;
+
+ input->close = pixcir_ts_close;
+
+ input_set_drvdata(input, tsdata);
+
+ tsdata->client = client;
+ tsdata->input = input;
+ tsdata->chip = pdata;
+ tsdata->irq = client->irq;
+
+ set_bit(EV_SYN, input->evbit);
+ set_bit(EV_KEY, input->evbit);
+ set_bit(EV_ABS, input->evbit);
+ set_bit(BTN_TOUCH, input->keybit);
+ input_set_abs_params(input, ABS_X, 0, pdata->ts_x_max, 0, 0);
+ input_set_abs_params(input, ABS_Y, 0, pdata->ts_y_max, 0, 0);
+ input_set_abs_params(input, ABS_MT_POSITION_X, 0, pdata->ts_x_max, 0, 0);
+ input_set_abs_params(input, ABS_MT_POSITION_Y, 0, pdata->ts_y_max, 0, 0);
+
+ if (input_register_device(input)) {
+ input_free_device(input);
+ kfree(tsdata);
+ }
+
+ if (request_threaded_irq(tsdata->irq, NULL, pixcir_ts_isr,
+ IRQF_TRIGGER_FALLING, client->name, tsdata)) {
+ dev_err(&client->dev, "Unable to request touchscreen IRQ.\n");
+ input_unregister_device(input);
+ input = NULL;
+ }
+
+ device_init_wakeup(&client->dev, 1);
+
+ return 0;
+}
+
+static int pixcir_i2c_ts_remove(struct i2c_client *client) +{
+ struct pixcir_i2c_ts_data *tsdata;
+
+ tsdata = i2c_get_clientdata(client);
+ wake_up(&tsdata->wait);
+ free_irq(tsdata->irq, tsdata);
+ input_unregister_device(tsdata->input);
+ kfree(tsdata);
+ dev_set_drvdata(&client->dev, NULL);
+ return 0;
+}
+
+#ifdef CONFIG_PM
+static int pixcir_i2c_ts_suspend(struct i2c_client *client, pm_message_t mesg)
+{
+ struct pixcir_i2c_ts_data *tsdata = dev_get_drvdata(&client->dev);
+
+ if (device_may_wakeup(&client->dev))
+ enable_irq_wake(tsdata->irq);
+
+ return 0;
+}
+
+static int pixcir_i2c_ts_resume(struct i2c_client *client) +{
+ struct pixcir_i2c_ts_data *tsdata = dev_get_drvdata(&client->dev);
+
+ if (device_may_wakeup(&client->dev))
+ disable_irq_wake(tsdata->irq);
+
+ return 0;
+}
+
+static const struct dev_pm_ops pixcir_dev_pm_ops = {
+ .suspend = pixcir_i2c_ts_suspend,
+ .resume = pixcir_i2c_ts_resume,
+};
+
+#else
+#define pixcir_i2c_ts_suspend NULL
+#define pixcir_i2c_ts_resume NULL
+#endif
+
+static const struct i2c_device_id pixcir_i2c_ts_id[] = {
+ { "pixcir_ts", 0 },
+ { }
+};
+MODULE_DEVICE_TABLE(i2c, pixcir_i2c_ts_id);
+
+static struct i2c_driver pixcir_i2c_ts_driver = {
+ .driver = {
+ .owner = THIS_MODULE,
+ .name = "pixcir_ts",
+#ifdef PM_CONFIG
+ .pm = &pixcir_dev_pm_ops,
+#endif
+ },
+ .probe = pixcir_i2c_ts_probe,
+ .remove = pixcir_i2c_ts_remove,
+ .id_table = pixcir_i2c_ts_id,
+};
+
+static int __init pixcir_i2c_ts_init(void)
+{
+ /*pixcir_wq = create_singlethread_workqueue("pixcir_wq");
+ if (!pixcir_wq)
+ return -ENOMEM;*/
+ return i2c_add_driver(&pixcir_i2c_ts_driver);
+}
+
+static void __exit pixcir_i2c_ts_exit(void)
+{
+ i2c_del_driver(&pixcir_i2c_ts_driver);
+ /*if (pixcir_wq)
+ destroy_workqueue(pixcir_wq);*/
+}
+
+MODULE_AUTHOR("Jianchun Bian<[email protected]>,Dequan Meng<[email protected]>"); +MODULE_DESCRIPTION("Pixcir I2C Touchscreen Driver"); +MODULE_LICENSE("GPL");
+
+module_init(pixcir_i2c_ts_init); +module_exit(pixcir_i2c_ts_exit);

(quoted diff) +0 -0

b/drivers/input/touchscreen/pixcir_i2c_ts.h
new file mode 100644
index 0000000..b037c27

drivers/input/touchscreen/pixcir_i2c_ts.h new file +13 -0
@@ -0,0 +1,13 @@
+#ifndef	_PIXCIR_I2C_TS_H
+#define	_PIXCIR_I2C_TS_H
+
+#define	TRUE		1
+#define	ATTB_PIN_LOW	0
+
+struct pixcir_i2c_ts_platform {
+	int (*attb_read_val) (void);
+	int ts_x_max;
+	int ts_y_max;
+};
+
+#endif
Signature · 6 lines
1.7.0.4


-- 
Best Regards
Bee/Pixcir
#1 lore raw

Hi jcbian,

Quoted 2 lines

This patch adds a driver for PIXCIR's I2C connected touchscreens. Request the IRQ by doing request_threaded_irq() as v3.

Some MT comments below.

Quoted 1 line

+static int pixcir_ts_poscheck(struct pixcir_i2c_ts_data *data)

Perhaps it is possible to find a more descriptive name?

Quoted 7 lines
(quoted diff) +7 -0
+{
+	struct pixcir_i2c_ts_data *tsdata = data;
+
+	u8 touching, oldtouching;
+	u16 posx1, posy1, posx2, posy2;
+	u8 rdbuf[10], wrbuf[1];
+	int ret;

Review

Quoted 10 lines
(quoted diff) +10 -0
+
+	memset(wrbuf, 0, sizeof(wrbuf));
+	memset(rdbuf, 0, sizeof(rdbuf));
+
+	wrbuf[0] = 0;
+	ret = i2c_master_send(tsdata->client, wrbuf, 1);
+	if (ret != 1) {
+		dev_err(&tsdata->client->dev, "Unable to write to i2c touchscreen!\n");
+		goto out;
+	}

How about returning the error code here directly instead?

Review

Quoted 6 lines
(quoted diff) +6 -0
+
+	ret = i2c_master_recv(tsdata->client, rdbuf, sizeof(rdbuf));
+	if (ret != sizeof(rdbuf)) {
+		dev_err(&tsdata->client->dev, "Unable to read i2c page!\n");
+		goto out;
+	}

Ditto.

Review

Quoted 3 lines
(quoted diff) +3 -0
+
+	touching = rdbuf[0];
+	oldtouching = rdbuf[1];

Is oldtouching ever used?

Review

Quoted 11 lines
(quoted diff) +11 -0
+	posx1 = ((rdbuf[3] << 8) | rdbuf[2]);
+	posy1 = ((rdbuf[5] << 8) | rdbuf[4]);
+	posx2 = ((rdbuf[7] << 8) | rdbuf[6]);
+	posy2 = ((rdbuf[9] << 8) | rdbuf[8]);
+
+	input_report_key(tsdata->input, BTN_TOUCH, touching);
+
+	if (touching == 1) {
+		input_report_abs(tsdata->input, ABS_X, posx1);
+		input_report_abs(tsdata->input, ABS_Y, posy1);
+	}

No MT data for one finger?

Review

Quoted 11 lines
(quoted diff) +11 -0
+
+	if (touching == 2) {
+		input_report_abs(tsdata->input, ABS_MT_POSITION_X, posx1);
+		input_report_abs(tsdata->input, ABS_MT_POSITION_Y, posy1);
+		input_mt_sync(tsdata->input);
+
+		input_report_abs(tsdata->input, ABS_MT_POSITION_X, posx2);
+		input_report_abs(tsdata->input, ABS_MT_POSITION_Y, posy2);
+		input_mt_sync(tsdata->input);
+	} else
+		input_mt_sync(tsdata->input);

input_mt_sync() is always called, please simplify.

Quoted 8 lines
(quoted diff) +8 -0
+	input_sync(tsdata->input);
+
+	return 0;
+
+out:
+	return -EINVAL;
+}
+

[...]

Quoted 45 lines
(quoted diff) +45 -0
+static int pixcir_i2c_ts_probe(struct i2c_client *client,
+			  const struct i2c_device_id *id)
+{
+	struct pixcir_i2c_ts_data *tsdata;
+	struct input_dev *input;
+	const struct pixcir_i2c_ts_platform *pdata =
+					client->dev.platform_data;
+	int error;
+
+	if (!pdata) {
+		dev_err(&client->dev, "platform data not defined\n");
+		return -EINVAL;
+	}
+
+	tsdata = kzalloc(sizeof(*tsdata), GFP_KERNEL);
+	if (!tsdata) {
+		dev_err(&client->dev, "Failed to allocate driver data!\n");
+		error = -ENOMEM;
+		dev_set_drvdata(&client->dev, NULL);
+		return error;
+	}
+
+	dev_set_drvdata(&client->dev, tsdata);
+
+	input = input_allocate_device();
+	if (!input) {
+		dev_err(&client->dev, "Failed to allocate input device!\n");
+		error = -ENOMEM;
+		input_free_device(input);
+		kfree(tsdata);
+	}
+
+	init_waitqueue_head(&tsdata->wait);
+
+	input->name = client->name;
+	input->id.bustype = BUS_I2C;
+	input->dev.parent = &client->dev;
+
+	input->close = pixcir_ts_close;
+
+	input_set_drvdata(input, tsdata);
+
+	tsdata->client = client;
+	tsdata->input = input;
+	tsdata->chip = pdata;

Review

Quoted 10 lines
(quoted diff) +10 -0
+	tsdata->irq = client->irq;
+
+	set_bit(EV_SYN, input->evbit);
+	set_bit(EV_KEY, input->evbit);
+	set_bit(EV_ABS, input->evbit);
+	set_bit(BTN_TOUCH, input->keybit);
+	input_set_abs_params(input, ABS_X, 0, pdata->ts_x_max, 0, 0);
+	input_set_abs_params(input, ABS_Y, 0, pdata->ts_y_max, 0, 0);
+	input_set_abs_params(input, ABS_MT_POSITION_X, 0, pdata->ts_x_max, 0, 0);
+	input_set_abs_params(input, ABS_MT_POSITION_Y, 0, pdata->ts_y_max, 0, 0);

Is the device not capable of finger tracking? If not, it might be time to turn finger tracking on in the input core. It is preferrable to use protocol B these days.

Quoted 7 lines
(quoted diff) +7 -0
+
+	if (input_register_device(input)) {
+		input_free_device(input);
+		kfree(tsdata);
+	}
+
+	if (request_threaded_irq(tsdata->irq, NULL, pixcir_ts_isr,

Review

Quoted 10 lines
(quoted diff) +10 -0
+			IRQF_TRIGGER_FALLING, client->name, tsdata)) {
+		dev_err(&client->dev, "Unable to request touchscreen IRQ.\n");
+		input_unregister_device(input);
+		input = NULL;
+	}
+
+	device_init_wakeup(&client->dev, 1);
+
+	return 0;
+}

Thanks,
Henrik

maintainer
#2 lore raw
In reply to jcbian

Hi Jianchun,

Review

Quoted 11 lines · jcbian
(quoted diff) +11 -0
+
+static irqreturn_t pixcir_ts_isr(int irq, void *dev_id)
+{
+	struct pixcir_i2c_ts_data *tsdata = dev_id;
+
+	do {
+		pixcir_ts_poscheck(tsdata);
+		tsdata->attb_pin = tsdata->chip->attb_read_val();
+		if (tsdata->attb_pin == ATTB_PIN_LOW)
+			wait_event_timeout(tsdata->wait, TRUE,
+					msecs_to_jiffies(20));

This doews not mak sense, you do not do any waiting here since your condition is 'TRUE' and this the thread never sleeps but spins constantly.

You also ignored my other comments...

Does the patch below still work for you?

Thanks.

Signature · 20 lines
Dmitry


Input: add driver for pixcir i2c touchscreens

From: Jianchun Bian <[email protected]>

This patch adds a driver for PIXCIR's I2C connected touchscreens.

Signed-off-by: Jianchun <[email protected]>
Signed-off-by: Dmitry Torokhov <[email protected]>
---

 drivers/input/touchscreen/Kconfig         |   12 +
 drivers/input/touchscreen/Makefile        |    1 
 drivers/input/touchscreen/pixcir_i2c_ts.c |  235 +++++++++++++++++++++++++++++
 include/linux/input/pixcir_ts.h           |   10 +
 4 files changed, 258 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/touchscreen/pixcir_i2c_ts.c
 create mode 100644 include/linux/input/pixcir_ts.h
drivers/input/touchscreen/Kconfig +12 -0
index a369c94..358be1f 100644
@@ -464,6 +464,18 @@ config TOUCHSCREEN_UCB1400
 	  To compile this driver as a module, choose M here: the
 	  module will be called ucb1400_ts.
 
+config TOUCHSCREEN_PIXCIR
+	tristate "PIXCIR I2C touchscreens"
+	depends on I2C
+	help
+	  Say Y here if you have a pixcir i2c touchscreen
+	  controller.
+
+	  If unsure, say N.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called pixcir_i2c_ts.
+
 config TOUCHSCREEN_WM831X
 	tristate "Support for WM831x touchscreen controllers"
 	depends on MFD_WM831X
drivers/input/touchscreen/Makefile +1 -0
index 141ee3e..c0727a4 100644
@@ -42,6 +42,7 @@ obj-$(CONFIG_TOUCHSCREEN_HTCPEN)	+= htcpen.o
 obj-$(CONFIG_TOUCHSCREEN_USB_COMPOSITE)	+= usbtouchscreen.o
 obj-$(CONFIG_TOUCHSCREEN_PCAP)		+= pcap_ts.o
 obj-$(CONFIG_TOUCHSCREEN_PENMOUNT)	+= penmount.o
+obj-$(CONFIG_TOUCHSCREEN_PIXCIR)	+= pixcir_i2c_ts.o
 obj-$(CONFIG_TOUCHSCREEN_S3C2410)	+= s3c2410_ts.o
 obj-$(CONFIG_TOUCHSCREEN_ST1232)	+= st1232.o
 obj-$(CONFIG_TOUCHSCREEN_STMPE)		+= stmpe-ts.o
drivers/input/touchscreen/pixcir_i2c_ts.c new file +235 -0

235 lines not on this page · raw message

include/linux/input/pixcir_ts.h new file +10 -0
new file mode 100644
index 0000000..7163d91
@@ -0,0 +1,10 @@
+#ifndef	_PIXCIR_I2C_TS_H
+#define	_PIXCIR_I2C_TS_H
+
+struct pixcir_ts_platform_data {
+	int (*attb_read_val)(void);
+	int x_max;
+	int y_max;
+};
+
+#endif
#3 lore raw

Hi Dmitry,

Quoted 37 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +37 -0
+static void pixcir_ts_poscheck(struct pixcir_i2c_ts_data *data)
+{
+	struct pixcir_i2c_ts_data *tsdata = data;
+
+	u8 touching;
+	u16 posx1, posy1, posx2, posy2;
+	u8 rdbuf[10], wrbuf[1] = { 0 };
+	int ret;
+
+	ret = i2c_master_send(tsdata->client, wrbuf, sizeof(wrbuf));
+	if (ret != sizeof(wrbuf)) {
+		dev_err(&tsdata->client->dev,
+			"%s: i2c_master_send failed(), ret=%d\n",
+			__func__, ret);
+		return;
+	}
+
+	ret = i2c_master_recv(tsdata->client, rdbuf, sizeof(rdbuf));
+	if (ret != sizeof(rdbuf)) {
+		dev_err(&tsdata->client->dev,
+			"%s: i2c_master_recv failed(), ret=%d\n",
+			__func__, ret);
+		return;
+	}
+
+	touching = rdbuf[0];
+	posx1 = (rdbuf[3] << 8) | rdbuf[2];
+	posy1 = (rdbuf[5] << 8) | rdbuf[4];
+	posx2 = (rdbuf[7] << 8) | rdbuf[6];
+	posy2 = (rdbuf[9] << 8) | rdbuf[8];
+
+	input_report_key(tsdata->input, BTN_TOUCH, touching);
+	input_report_abs(tsdata->input, ABS_X, posx1);
+	input_report_abs(tsdata->input, ABS_Y, posy1);
+
+	input_report_abs(tsdata->input, ABS_MT_POSITION_X, posx1);
+	input_report_abs(tsdata->input, ABS_MT_POSITION_Y, posy1);

drivers/input/touchscreen/pixcir_i2c_ts.c line 81

Quoted 10 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +10 -0
+	input_mt_sync(tsdata->input);
+
+	if (touching == 2) {
+		input_report_abs(tsdata->input, ABS_MT_POSITION_X, posx2);
+		input_report_abs(tsdata->input, ABS_MT_POSITION_Y, posy2);
+		input_mt_sync(tsdata->input);
+	}
+
+	input_sync(tsdata->input);
+}

If the above function handles zero fingers as well, the MT finger count comes out wrong in that case.

Cheers,
Henrik

maintainer
#4 lore raw
Quoted 4 lines · Henrik Rydberg

If the above function handles zero fingers as well, the MT finger count comes out wrong in that case.

Hmm, indeed. How about the patch below instead?

Thanks.

Signature · 19 lines
Dmitry

Input: add driver for pixcir i2c touchscreens

From: Jianchun Bian <[email protected]>

This patch adds a driver for PIXCIR's I2C connected touchscreens.

Signed-off-by: Jianchun <[email protected]>
Signed-off-by: Dmitry Torokhov <[email protected]>
---

 drivers/input/touchscreen/Kconfig         |   12 +
 drivers/input/touchscreen/Makefile        |    1 
 drivers/input/touchscreen/pixcir_i2c_ts.c |  242 +++++++++++++++++++++++++++++
 include/linux/input/pixcir_ts.h           |   10 +
 4 files changed, 265 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/touchscreen/pixcir_i2c_ts.c
 create mode 100644 include/linux/input/pixcir_ts.h
drivers/input/touchscreen/Kconfig +12 -0
index a369c94..358be1f 100644
@@ -464,6 +464,18 @@ config TOUCHSCREEN_UCB1400
 	  To compile this driver as a module, choose M here: the
 	  module will be called ucb1400_ts.
 
+config TOUCHSCREEN_PIXCIR
+	tristate "PIXCIR I2C touchscreens"
+	depends on I2C
+	help
+	  Say Y here if you have a pixcir i2c touchscreen
+	  controller.
+
+	  If unsure, say N.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called pixcir_i2c_ts.
+
 config TOUCHSCREEN_WM831X
 	tristate "Support for WM831x touchscreen controllers"
 	depends on MFD_WM831X
drivers/input/touchscreen/Makefile +1 -0
index 141ee3e..c0727a4 100644
@@ -42,6 +42,7 @@ obj-$(CONFIG_TOUCHSCREEN_HTCPEN)	+= htcpen.o
 obj-$(CONFIG_TOUCHSCREEN_USB_COMPOSITE)	+= usbtouchscreen.o
 obj-$(CONFIG_TOUCHSCREEN_PCAP)		+= pcap_ts.o
 obj-$(CONFIG_TOUCHSCREEN_PENMOUNT)	+= penmount.o
+obj-$(CONFIG_TOUCHSCREEN_PIXCIR)	+= pixcir_i2c_ts.o
 obj-$(CONFIG_TOUCHSCREEN_S3C2410)	+= s3c2410_ts.o
 obj-$(CONFIG_TOUCHSCREEN_ST1232)	+= st1232.o
 obj-$(CONFIG_TOUCHSCREEN_STMPE)		+= stmpe-ts.o
drivers/input/touchscreen/pixcir_i2c_ts.c new file +242 -0

242 lines not on this page · raw message

include/linux/input/pixcir_ts.h new file +10 -0
new file mode 100644
index 0000000..7163d91
@@ -0,0 +1,10 @@
+#ifndef	_PIXCIR_I2C_TS_H
+#define	_PIXCIR_I2C_TS_H
+
+struct pixcir_ts_platform_data {
+	int (*attb_read_val)(void);
+	int x_max;
+	int y_max;
+};
+
+#endif
author
#5 lore raw

Hi Dmitry & Henrik,

Thanks for your suggestions and modification .I have test it and it works well.
Indeed,I think the old_touch is not needed,the follow

+ if (old_touch)
+ input_mt_sync(tsdata->input);

could be removed. So,How about below?

Thanks.
--
Jcbian

Input: add driver for pixcir i2c touchscreens

From: Jianchun Bian <[email protected]>

This patch adds a driver for PIXCIR's I2C connected touchscreens.

---

 drivers/input/touchscreen/Kconfig         |   12 +
 drivers/input/touchscreen/Makefile        |    1 
 drivers/input/touchscreen/pixcir_i2c_ts.c |  242 +++++++++++++++++++++++++++++
 include/linux/input/pixcir_ts.h           |   10 +
 4 files changed, 265 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/touchscreen/pixcir_i2c_ts.c
 create mode 100644 include/linux/input/pixcir_ts.h
drivers/input/touchscreen/Kconfig +12 -0
index a369c94..358be1f 100644
@@ -464,6 +464,18 @@ config TOUCHSCREEN_UCB1400
 	  To compile this driver as a module, choose M here: the
 	  module will be called ucb1400_ts.
 
+config TOUCHSCREEN_PIXCIR
+	tristate "PIXCIR I2C touchscreens"
+	depends on I2C
+	help
+	  Say Y here if you have a pixcir i2c touchscreen
+	  controller.
+
+	  If unsure, say N.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called pixcir_i2c_ts.
+
 config TOUCHSCREEN_WM831X
 	tristate "Support for WM831x touchscreen controllers"
 	depends on MFD_WM831X
drivers/input/touchscreen/Makefile +1 -0
index 141ee3e..c0727a4 100644
@@ -42,6 +42,7 @@ obj-$(CONFIG_TOUCHSCREEN_HTCPEN)	+= htcpen.o
 obj-$(CONFIG_TOUCHSCREEN_USB_COMPOSITE)	+= usbtouchscreen.o
 obj-$(CONFIG_TOUCHSCREEN_PCAP)		+= pcap_ts.o
 obj-$(CONFIG_TOUCHSCREEN_PENMOUNT)	+= penmount.o
+obj-$(CONFIG_TOUCHSCREEN_PIXCIR)	+= pixcir_i2c_ts.o
 obj-$(CONFIG_TOUCHSCREEN_S3C2410)	+= s3c2410_ts.o
 obj-$(CONFIG_TOUCHSCREEN_ST1232)	+= st1232.o
 obj-$(CONFIG_TOUCHSCREEN_STMPE)		+= stmpe-ts.o
drivers/input/touchscreen/pixcir_i2c_ts.c new file +239 -0

239 lines not on this page · raw message

include/linux/input/pixcir_ts.h new file +10 -0
new file mode 100644
index 0000000..7163d91
@@ -0,0 +1,10 @@
+#ifndef	_PIXCIR_I2C_TS_H
+#define	_PIXCIR_I2C_TS_H
+
+struct pixcir_ts_platform_data {
+	int (*attb_read_val)(void);
+	int x_max;
+	int y_max;
+};
+
+#endif

--
To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#6 lore raw
Quoted 9 lines · jcbian

Hi Dmitry & Henrik,

Thanks for your suggestions and modification .I have test it and it works well.
Indeed,I think the old_touch is not needed,the follow

(quoted diff) +2 -0
+		if (old_touch)
+			input_mt_sync(tsdata->input);

could be removed. So,How about below?

Also fine, although the removed brackets is a slight style violation. No need to resend though.

Quoted 41 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +41 -0
+static void pixcir_ts_poscheck(struct pixcir_i2c_ts_data *data)
+{
+	struct pixcir_i2c_ts_data *tsdata = data;
+	u8 rdbuf[10], wrbuf[1] = { 0 };
+	u8 touch, old_touch;
+	int ret;
+
+	ret = i2c_master_send(tsdata->client, wrbuf, sizeof(wrbuf));
+	if (ret != sizeof(wrbuf)) {
+		dev_err(&tsdata->client->dev,
+			"%s: i2c_master_send failed(), ret=%d\n",
+			__func__, ret);
+		return;
+	}
+
+	ret = i2c_master_recv(tsdata->client, rdbuf, sizeof(rdbuf));
+	if (ret != sizeof(rdbuf)) {
+		dev_err(&tsdata->client->dev,
+			"%s: i2c_master_recv failed(), ret=%d\n",
+			__func__, ret);
+		return;
+	}
+
+	touch = rdbuf[0];
+	old_touch = rdbuf[1];
+	if (touch) {
+		u16 posx1 = (rdbuf[3] << 8) | rdbuf[2];
+		u16 posy1 = (rdbuf[5] << 8) | rdbuf[4];
+		u16 posx2 = (rdbuf[7] << 8) | rdbuf[6];
+		u16 posy2 = (rdbuf[9] << 8) | rdbuf[8];
+
+		input_report_key(tsdata->input, BTN_TOUCH, 1);
+		input_report_abs(tsdata->input, ABS_X, posx1);
+		input_report_abs(tsdata->input, ABS_Y, posy1);
+
+		input_report_abs(tsdata->input, ABS_MT_POSITION_X, posx1);
+		input_report_abs(tsdata->input, ABS_MT_POSITION_Y, posy1);
+		input_mt_sync(tsdata->input);
+
+		if (touch == 2) {
+			input_report_abs(tsdata->input,

drivers/input/touchscreen/pixcir_i2c_ts.c line 85

Quoted 10 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +10 -0
+					 ABS_MT_POSITION_X, posx2);
+			input_report_abs(tsdata->input,
+					 ABS_MT_POSITION_Y, posy2);
+			input_mt_sync(tsdata->input);
+		}
+	} else
+		input_report_key(tsdata->input, BTN_TOUCH, 0);
+
+	input_sync(tsdata->input);
+}

Thanks,
Henrik

#7 lore raw
In reply to Dmitry Torokhov
Quoted 7 lines · Dmitry Torokhov
Quoted 4 lines · Henrik Rydberg

If the above function handles zero fingers as well, the MT finger count comes out wrong in that case.

Hmm, indeed. How about the patch below instead?

Looks good, thanks.

Quoted 44 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +44 -0
+static void pixcir_ts_poscheck(struct pixcir_i2c_ts_data *data)
+{
+	struct pixcir_i2c_ts_data *tsdata = data;
+	u8 rdbuf[10], wrbuf[1] = { 0 };
+	u8 touch, old_touch;
+	int ret;
+
+	ret = i2c_master_send(tsdata->client, wrbuf, sizeof(wrbuf));
+	if (ret != sizeof(wrbuf)) {
+		dev_err(&tsdata->client->dev,
+			"%s: i2c_master_send failed(), ret=%d\n",
+			__func__, ret);
+		return;
+	}
+
+	ret = i2c_master_recv(tsdata->client, rdbuf, sizeof(rdbuf));
+	if (ret != sizeof(rdbuf)) {
+		dev_err(&tsdata->client->dev,
+			"%s: i2c_master_recv failed(), ret=%d\n",
+			__func__, ret);
+		return;
+	}
+
+	touch = rdbuf[0];
+	old_touch = rdbuf[1];
+	if (touch) {
+		u16 posx1 = (rdbuf[3] << 8) | rdbuf[2];
+		u16 posy1 = (rdbuf[5] << 8) | rdbuf[4];
+		u16 posx2 = (rdbuf[7] << 8) | rdbuf[6];
+		u16 posy2 = (rdbuf[9] << 8) | rdbuf[8];
+
+		input_report_key(tsdata->input, BTN_TOUCH, 1);
+		input_report_abs(tsdata->input, ABS_X, posx1);
+		input_report_abs(tsdata->input, ABS_Y, posy1);
+
+		input_report_abs(tsdata->input, ABS_MT_POSITION_X, posx1);
+		input_report_abs(tsdata->input, ABS_MT_POSITION_Y, posy1);
+		input_mt_sync(tsdata->input);
+
+		if (touch == 2) {
+			input_report_abs(tsdata->input,
+					 ABS_MT_POSITION_X, posx2);
+			input_report_abs(tsdata->input,
+					 ABS_MT_POSITION_Y, posy2);

drivers/input/touchscreen/pixcir_i2c_ts.c line 88

Quoted 10 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +10 -0
+			input_mt_sync(tsdata->input);
+		}
+	} else {
+		input_report_key(tsdata->input, BTN_TOUCH, 0);
+		if (old_touch)
+			input_mt_sync(tsdata->input);
+	}
+
+	input_sync(tsdata->input);
+}

Henrik