input: add driver for pixcir i2c touchscreens
Subsystems (2)
PATCH v2 1/1 input: add driver for pixcir i2c touchscreens
This patch adds a driver for PIXCIR's I2C connected touchscreens. Modify the text format as v2.
--- drivers/input/touchscreen/Kconfig | 9 + drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/pixcir_i2c_ts.c | 293 +++++++++++++++++++++++++++++ 3 files changed, 303 insertions(+), 0 deletions(-) create mode 100644 drivers/input/touchscreen/pixcir_i2c_ts.c
drivers/input/touchscreen/Kconfig +9 -0
@@ -693,4 +693,13 @@ 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 touchscreen panel support" + depends on I2C + help + Say Y here if you have a PIXCIR based touchscreen. + + To compile this driver as a module, choose M here: the + module will be called pixcir_i2c_ts. + endif
drivers/input/touchscreen/Makefile +1 -0
@@ -57,3 +57,4 @@ obj-$(CONFIG_TOUCHSCREEN_WM97XX_MAINSTONE) += mainstone-wm97xx.o obj-$(CONFIG_TOUCHSCREEN_WM97XX_ZYLONITE) += zylonite-wm97xx.o obj-$(CONFIG_TOUCHSCREEN_W90X900) += w90p910_ts.o obj-$(CONFIG_TOUCHSCREEN_TPS6507X) += tps6507x-ts.o +obj-$(CONFIG_TOUCHSCREEN_PIXCIR) += pixcir_i2c_ts.o
drivers/input/touchscreen/pixcir_i2c_ts.c new file +293 -0
293 lines not on this page · raw message
Signature · 1 line
1.7.0.4
Dmitry Torokhov
maintainerHi,
Quoted 4 lines · 卞建春
This patch adds a driver for PIXCIR's I2C connected touchscreens. Modify the text format as v2.
Signed-off-by Bee <[email protected]>
"Bee" and "Reed" sound like handles, not real names, which we expect in "Signed-off-by" strings.
Also, in addition to all comments made by Mark:
Quoted 30 lines
--- drivers/input/touchscreen/Kconfig | 9 + drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/pixcir_i2c_ts.c | 293 +++++++++++++++++++++++++++++ 3 files changed, 303 insertions(+), 0 deletions(-) create mode 100644 drivers/input/touchscreen/pixcir_i2c_ts.cdrivers/input/touchscreen/Kconfig +9
-0@@ -693,4 +693,13 @@ 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 touchscreen panel support" + depends on I2C + help + Say Y here if you have a PIXCIR based touchscreen. + + To compile this driver as a module, choose M here: the + module will be called pixcir_i2c_ts. + endifdrivers/input/touchscreen/Makefile +0
-0
drivers/input/touchscreen/Makefile obj-$(CONFIG_TOUCHSCREEN_WM97XX_MAINSTONE) += mainstone-wm97xx.o · line 60
Quoted 4 lines
drivers/input/touchscreen/Makefile +1
-0@@ -57,3 +57,4 @@ obj-$(CONFIG_TOUCHSCREEN_WM97XX_MAINSTONE) += mainstone-wm97xx.o obj-$(CONFIG_TOUCHSCREEN_WM97XX_ZYLONITE) += zylonite-wm97xx.o obj-$(CONFIG_TOUCHSCREEN_W90X900) += w90p910_ts.o obj-$(CONFIG_TOUCHSCREEN_TPS6507X) += tps6507x-ts.o +obj-$(CONFIG_TOUCHSCREEN_PIXCIR) += pixcir_i2c_ts.o
Please keep Kconfig and Makefile sorted alphabetically (it usually helps with merging as it is likely to avoid conflicts).
drivers/input/touchscreen/pixcir_i2c_ts.c line 1
Quoted 7 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +1
-0@@ -0,0 +1,293 @@ +/* drivers/input/touchscreen/pixcir_i2c_ts.c
No need to put file name in the comments, it simply makes it harder to rename if such need arises.
Quoted 72 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +72
-0+* +* Copyright (C) 2010-2011 Pixcir, Inc. +* +* 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/slab.h> +#include <linux/input.h> +#include <linux/i2c.h> +#include <linux/gpio.h> + +#define DRIVER_VERSION "v1.0" +#define DRIVER_AUTHOR "Bee<[email protected]>,Reed<[email protected]>" +#define DRIVER_DESC "Pixcir I2C Touchscreen Driver" +#define DRIVER_LICENSE "GPL" + +/* todo:check specs for resolution of touch screen */ +#define TOUCHSCREEN_MINX 0 +#define TOUCHSCREEN_MAXX 400 +#define TOUCHSCREEN_MINY 0 +#define TOUCHSCREEN_MAXY 600 + +#define DEBUG 0 + +static struct workqueue_struct *pixcir_wq; + +struct pixcir_i2c_ts_data { +struct i2c_client *client; +struct input_dev *input; +struct delayed_work work; +int irq; +}; + +static void pixcir_ts_poscheck (struct work_struct *work) +{ +struct pixcir_i2c_ts_data *tsdata =container_of (work, + struct pixcir_i2c_ts_data, + work.work); + +unsigned char touching, oldtouching; +int posx1, posy1, posx2, posy2; +u_int8_t Rdbuf[10 ], Wrbuf[1 ]; +int ret; +int z =50 ; +int w =15 ; + +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;
drivers/input/touchscreen/pixcir_i2c_ts.c line 83
Quoted 10 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +10
-0+ } + + 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 !=0 ?1 :0 ));
Just say
input_report_key(tsdata->input, BTN_TOUCH, touching);
input_report_key() normalizes to boolean internally.
drivers/input/touchscreen/pixcir_i2c_ts.c line 88
Quoted 5 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +5
-0+ +if (touching ==1 ) { +input_report_abs (tsdata->input,ABS_X , posx1); +input_report_abs (tsdata->input,ABS_Y , posy1); + }
Just send the data always.
drivers/input/touchscreen/pixcir_i2c_ts.c line 96
Quoted 8 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +8
-0+ +if (!(touching)) { + z =0 ; + w =0 ; + } +if (touching ==2 ) { +input_report_abs (tsdata->input,ABS_MT_TOUCH_MAJOR , z); +input_report_abs (tsdata->input,ABS_MT_WIDTH_MAJOR , w);
The device does not seem to report ABS_MT_TOUCH_MAJOR/ABS_MT_WIDTH_MAJOR so do not invent the values, don't send anything.
drivers/input/touchscreen/pixcir_i2c_ts.c line 104
Quoted 8 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +8
-0+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_TOUCH_MAJOR , z); +input_report_abs (tsdata->input,ABS_MT_WIDTH_MAJOR , w); +input_report_abs (tsdata->input,ABS_MT_POSITION_X , posx2); +input_report_abs (tsdata->input,ABS_MT_POSITION_Y , posy2);
So the hardware does not do any contact tracking? Henrik, any advise how to better handle this device?
Quoted 27 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +27
-0+input_mt_sync (tsdata->input); + } +input_sync (tsdata->input); + +out: +enable_irq (tsdata->irq); +} + +static irqreturn_t pixcir_ts_isr (int irq,void *dev_id) +{ +struct pixcir_i2c_ts_data *tsdata = dev_id; +disable_irq_nosync (irq); + +queue_work (pixcir_wq, &tsdata->work.work); + +return IRQ_HANDLED ; +} + +static int pixcir_ts_open (struct input_dev *dev) +{ +return 0 ; +} + +static void pixcir_ts_close (struct input_dev *dev) +{ + +}
drivers/input/touchscreen/pixcir_i2c_ts.c line 141
Quoted 10 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +10
-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; +int error; + +#ifdef DEBUG +printk (KERN_EMERG "pixcir_i2c_ts probe!\n" );
pr_debug() or dev_dbg().
drivers/input/touchscreen/pixcir_i2c_ts.c line 152
Quoted 11 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +11
-0+#endif + + 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);
I2c_set_clientdata()
drivers/input/touchscreen/pixcir_i2c_ts.c line 162
Quoted 10 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +10
-0+ + input =input_allocate_device (); +if (!input) { +dev_err (&client->dev,"Failed to allocate input device!\n" ); + error = -ENOMEM ; +input_free_device (input); +kfree (tsdata); + } + +set_bit (EV_SYN , input->evbit);
Set by input core, no need to bother with it in driver code.
drivers/input/touchscreen/pixcir_i2c_ts.c line 165
Quoted 3 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +3
-0+set_bit (EV_KEY , input->evbit); +set_bit (EV_ABS , input->evbit); +set_bit (BTN_TOUCH , input->keybit);
Use __set_bit(), no need to lock the bus.
Quoted 20 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +20
-0+input_set_abs_params (input,ABS_X , +TOUCHSCREEN_MINX ,TOUCHSCREEN_MAXX ,0 ,0 ); +input_set_abs_params (input,ABS_Y , +TOUCHSCREEN_MINY ,TOUCHSCREEN_MAXY ,0 ,0 ); +input_set_abs_params (input,ABS_MT_POSITION_X , +TOUCHSCREEN_MINX ,TOUCHSCREEN_MAXX ,0 ,0 ); +input_set_abs_params (input,ABS_MT_POSITION_Y , +TOUCHSCREEN_MINY ,TOUCHSCREEN_MAXY ,0 ,0 ); +input_set_abs_params (input,ABS_MT_TOUCH_MAJOR ,0 ,255 ,0 ,0 ); +input_set_abs_params (input,ABS_MT_WIDTH_MAJOR ,0 ,25 ,0 ,0 ); + + input->name = client->name; + input->id.bustype =BUS_I2C ; + input->dev.parent = &client->dev; + + input->open = pixcir_ts_open; + input->close = pixcir_ts_close; + +input_set_drvdata (input, tsdata); +
drivers/input/touchscreen/pixcir_i2c_ts.c line 195
Quoted 10 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +10
-0+ tsdata->client = client; + tsdata->input = input; + +INIT_WORK (&tsdata->work.work, pixcir_ts_poscheck); + + tsdata->irq = client->irq; + +if (input_register_device (input)) { +input_free_device (input); +kfree (tsdata);
Return the error reported by input_register_device()?
Quoted 9 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +9
-0+ } + +if (request_irq (tsdata->irq, pixcir_ts_isr, +IRQF_TRIGGER_LOW , client->name, tsdata)) { +dev_err (&client->dev,"Unable to request touchscreen IRQ.\n" ); +input_unregister_device (input); + input =NULL ; + } +
drivers/input/touchscreen/pixcir_i2c_ts.c line 214
Quoted 10 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +10
-0+device_init_wakeup (&client->dev,1 ); + +dev_err (&tsdata->client->dev,"insmod successfully!\n" ); + +return 0 ; +} + +static int pixcir_i2c_ts_remove (struct i2c_client *client) +{ +struct pixcir_i2c_ts_data *tsdata =dev_get_drvdata (&client->dev);
i2c_get_clientdata(). Also empty line between variable definitions and code.
Quoted 35 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +35
-0+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 ; +} +#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 }, + { }
drivers/input/touchscreen/pixcir_i2c_ts.c line 259
Quoted 10 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +10
-0+}; +MODULE_DEVICE_TABLE (i2c, pixcir_i2c_ts_id); + +static struct i2c_driver pixcir_i2c_ts_driver = { + .driver = { + .owner =THIS_MODULE , + .name ="pixcir_ts" , + }, + .probe = pixcir_i2c_ts_probe, + .remove = pixcir_i2c_ts_remove,
__devexit_p().
drivers/input/touchscreen/pixcir_i2c_ts.c line 261
Quoted 2 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +2
-0+ .suspend = pixcir_i2c_ts_suspend, + .resume = pixcir_i2c_ts_resume,
dev_pm_ops.
drivers/input/touchscreen/pixcir_i2c_ts.c line 271
Quoted 10 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +10
-0+ .id_table = pixcir_i2c_ts_id, +}; + +static int __init pixcir_i2c_ts_init (void ) +{ +#ifdef DEBUG +printk (KERN_EMERG "pixcir_i2c_init\n" ); +#endif + + pixcir_wq =create_singlethread_workqueue ("pixcir_wq" );
Not needed if you use threaded IRQ.
Thanks.
Signature · 5 lines
Dmitry -- 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
Hi Dmitry,
Thanks for your advice.
Quoted 7 lines
Hi,
Quoted 3 lines · 卞建春
This patch adds a driver for PIXCIR's I2C connected touchscreens. Modify the text format as v2.
Quoted 7 lines
Quoted 1 line
Signed-off-by Bee <[email protected]>"Bee" and "Reed" sound like handles, not real names, which we expect in "Signed-off-by" strings.
Also, in addition to all comments made by Mark:
Nice,thanks!
Quoted 29 lines
Quoted 29 lines
--- drivers/input/touchscreen/Kconfig | 9 + drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/pixcir_i2c_ts.c | 293 +++++++++++++++++++++++++++++ 3 files changed, 303 insertions(+), 0 deletions(-) create mode 100644 drivers/input/touchscreen/pixcir_i2c_ts.cdrivers/input/touchscreen/Kconfig +9
-0@@ -693,4 +693,13 @@ 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 touchscreen panel support" + depends on I2C + help + Say Y here if you have a PIXCIR based touchscreen. + + To compile this driver as a module, choose M here: the + module will be called pixcir_i2c_ts. + endifdrivers/input/touchscreen/Makefile +0
-0
Quoted 9 lines
drivers/input/touchscreen/Makefile obj-$(CONFIG_TOUCHSCREEN_WM97XX_MAINSTONE) += mainstone-wm97xx.o · line 60
Quoted 5 lines
drivers/input/touchscreen/Makefile +1
-0@@ -57,3 +57,4 @@ obj-$(CONFIG_TOUCHSCREEN_WM97XX_MAINSTONE) += mainstone-wm97xx.o obj-$(CONFIG_TOUCHSCREEN_WM97XX_ZYLONITE) += zylonite-wm97xx.o obj-$(CONFIG_TOUCHSCREEN_W90X900) += w90p910_ts.o obj-$(CONFIG_TOUCHSCREEN_TPS6507X) += tps6507x-ts.o +obj-$(CONFIG_TOUCHSCREEN_PIXCIR) += pixcir_i2c_ts.oPlease keep
KconfigandMakefilesorted alphabetically (it usually helps with merging as it is likely to avoid conflicts).
Thanks!
Quoted 11 lines
drivers/input/touchscreen/pixcir_i2c_ts.c line 1
Quoted 7 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +1
-0@@ -0,0 +1,293 @@ +/* drivers/input/touchscreen/pixcir_i2c_ts.c No need to put file name in the comments, it simply makes it harder to rename if such need arises.
Thanks!
Quoted 85 lines
Quoted 72 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +72
-0+* +* Copyright (C) 2010-2011 Pixcir, Inc. +* +* 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/slab.h> +#include <linux/input.h> +#include <linux/i2c.h> +#include <linux/gpio.h> + +#define DRIVER_VERSION "v1.0" +#define DRIVER_AUTHOR "Bee<[email protected]>,Reed<[email protected]>" +#define DRIVER_DESC "Pixcir I2C Touchscreen Driver" +#define DRIVER_LICENSE "GPL" + +/* todo:check specs for resolution of touch screen */ +#define TOUCHSCREEN_MINX 0 +#define TOUCHSCREEN_MAXX 400 +#define TOUCHSCREEN_MINY 0 +#define TOUCHSCREEN_MAXY 600 + +#define DEBUG 0 + +static struct workqueue_struct *pixcir_wq; + +struct pixcir_i2c_ts_data { +struct i2c_client *client; +struct input_dev *input; +struct delayed_work work; +int irq; +}; + +static void pixcir_ts_poscheck (struct work_struct *work) +{ +struct pixcir_i2c_ts_data *tsdata =container_of (work, + struct pixcir_i2c_ts_data, + work.work); + +unsigned char touching, oldtouching; +int posx1, posy1, posx2, posy2; +u_int8_t Rdbuf[10 ], Wrbuf[1 ]; +int ret; +int z =50 ; +int w =15 ; + +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;drivers/input/touchscreen/pixcir_i2c_ts.c line 83
Quoted 10 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +10
-0+ } + + 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 !=0 ?1 :0 ));Just say
Quoted 2 lines
input_report_key(tsdata->input, BTN_TOUCH, touching);
Great modify,thanks!
Quoted 10 lines
input_report_key()normalizes to boolean internally.drivers/input/touchscreen/pixcir_i2c_ts.c line 88
Quoted 5 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +5
-0+ +if (touching ==1 ) { +input_report_abs (tsdata->input,ABS_X , posx1); +input_report_abs (tsdata->input,ABS_Y , posy1); + }Just send the data always.
Thanks for you advice,I just want to separate from reporting multi points.
Quoted 12 lines
drivers/input/touchscreen/pixcir_i2c_ts.c line 96
Quoted 8 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +8
-0+ +if (!(touching)) { + z =0 ; + w =0 ; + } +if (touching ==2 ) { +input_report_abs (tsdata->input,ABS_MT_TOUCH_MAJOR , z); +input_report_abs (tsdata->input,ABS_MT_WIDTH_MAJOR , w);The device does not seem to report ABS_MT_TOUCH_MAJOR/ABS_MT_WIDTH_MAJOR so do not invent the values, don't send anything.
Nice, thaks!
Quoted 10 lines
drivers/input/touchscreen/pixcir_i2c_ts.c line 104
Quoted 8 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +8
-0+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_TOUCH_MAJOR , z); +input_report_abs (tsdata->input,ABS_MT_WIDTH_MAJOR , w); +input_report_abs (tsdata->input,ABS_MT_POSITION_X , posx2); +input_report_abs (tsdata->input,ABS_MT_POSITION_Y , posy2);So the hardware does not do any contact tracking?
Yes.
Quoted 33 lines
Henrik, any advise how to better handle this device?
Quoted 31 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +31
-0+input_mt_sync (tsdata->input); + } +input_sync (tsdata->input); + +out: +enable_irq (tsdata->irq); +} + +static irqreturn_t pixcir_ts_isr (int irq,void *dev_id) +{ +struct pixcir_i2c_ts_data *tsdata = dev_id; +disable_irq_nosync (irq); + +queue_work (pixcir_wq, &tsdata->work.work); + +return IRQ_HANDLED ; +} + +static int pixcir_ts_open (struct input_dev *dev) +{ +return 0 ; +} + +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) +{
Quoted 9 lines
drivers/input/touchscreen/pixcir_i2c_ts.c line 141
Quoted 6 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +6
-0+struct pixcir_i2c_ts_data *tsdata; +struct input_dev *input; +int error; + +#ifdef DEBUG +printk (KERN_EMERG "pixcir_i2c_ts probe!\n" );
pr_debug()ordev_dbg().
Nice, thanks!
Quoted 5 lines
Quoted 5 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +5
-0+#endif + + tsdata =kzalloc (sizeof (*tsdata),GFP_KERNEL ); +if (!tsdata) { +dev_err (&client->dev,"Failed to allocate driver data!\n" );
Quoted 9 lines
drivers/input/touchscreen/pixcir_i2c_ts.c line 152
Quoted 6 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +6
-0+ error = -ENOMEM ; +dev_set_drvdata (&client->dev,NULL ); +return error; + } + +dev_set_drvdata (&client->dev, tsdata);
I2c_set_clientdata()
Thanks!
Quoted 13 lines
drivers/input/touchscreen/pixcir_i2c_ts.c line 162
Quoted 10 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +10
-0+ + input =input_allocate_device (); +if (!input) { +dev_err (&client->dev,"Failed to allocate input device!\n" ); + error = -ENOMEM ; +input_free_device (input); +kfree (tsdata); + } + +set_bit (EV_SYN , input->evbit);Set by input core, no need to bother with it in driver code.
Quoted 7 lines
drivers/input/touchscreen/pixcir_i2c_ts.c line 165
Quoted 3 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +3
-0+set_bit (EV_KEY , input->evbit); +set_bit (EV_ABS , input->evbit); +set_bit (BTN_TOUCH , input->keybit);Use
__set_bit(), no need to lock the bus.
Great idea,thanks!
Quoted 24 lines
Quoted 24 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +24
-0+input_set_abs_params (input,ABS_X , +TOUCHSCREEN_MINX ,TOUCHSCREEN_MAXX ,0 ,0 ); +input_set_abs_params (input,ABS_Y , +TOUCHSCREEN_MINY ,TOUCHSCREEN_MAXY ,0 ,0 ); +input_set_abs_params (input,ABS_MT_POSITION_X , +TOUCHSCREEN_MINX ,TOUCHSCREEN_MAXX ,0 ,0 ); +input_set_abs_params (input,ABS_MT_POSITION_Y , +TOUCHSCREEN_MINY ,TOUCHSCREEN_MAXY ,0 ,0 ); +input_set_abs_params (input,ABS_MT_TOUCH_MAJOR ,0 ,255 ,0 ,0 ); +input_set_abs_params (input,ABS_MT_WIDTH_MAJOR ,0 ,25 ,0 ,0 ); + + input->name = client->name; + input->id.bustype =BUS_I2C ; + input->dev.parent = &client->dev; + + input->open = pixcir_ts_open; + input->close = pixcir_ts_close; + +input_set_drvdata (input, tsdata); + + tsdata->client = client; + tsdata->input = input; + +INIT_WORK (&tsdata->work.work, pixcir_ts_poscheck);
Quoted 9 lines
drivers/input/touchscreen/pixcir_i2c_ts.c line 195
Quoted 6 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +6
-0+ + tsdata->irq = client->irq; + +if (input_register_device (input)) { +input_free_device (input); +kfree (tsdata);Return the error reported by
input_register_device()?
En,it is better to report the error.
Quoted 14 lines
Quoted 14 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +14
-0+ } + +if (request_irq (tsdata->irq, pixcir_ts_isr, +IRQF_TRIGGER_LOW , 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 ); + +dev_err (&tsdata->client->dev,"insmod successfully!\n" ); + +return 0 ;
Quoted 9 lines
drivers/input/touchscreen/pixcir_i2c_ts.c line 214
Quoted 5 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +5
-0+} + +static int pixcir_i2c_ts_remove (struct i2c_client *client) +{ +struct pixcir_i2c_ts_data *tsdata =dev_get_drvdata (&client->dev);
i2c_get_clientdata(). Also empty line between variable definitions and code.
Sorry,what's the meaning here?
Quoted 48 lines
Quoted 35 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +35
-0+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 ; +} +#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 }, + { }drivers/input/touchscreen/pixcir_i2c_ts.c line 259
Quoted 10 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +10
-0+}; +MODULE_DEVICE_TABLE (i2c, pixcir_i2c_ts_id); + +static struct i2c_driver pixcir_i2c_ts_driver = { + .driver = { + .owner =THIS_MODULE , + .name ="pixcir_ts" , + }, + .probe = pixcir_i2c_ts_probe, + .remove = pixcir_i2c_ts_remove,
__devexit_p().
Quoted 5 lines
drivers/input/touchscreen/pixcir_i2c_ts.c line 261
Quoted 2 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +2
-0+ .suspend = pixcir_i2c_ts_suspend, + .resume = pixcir_i2c_ts_resume,
dev_pm_ops.
Great!
Quoted 4 lines
Quoted 4 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +4
-0+ .id_table = pixcir_i2c_ts_id, +}; + +static int __init pixcir_i2c_ts_init (void )
Quoted 9 lines
drivers/input/touchscreen/pixcir_i2c_ts.c line 271
Quoted 6 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +6
-0+{ +#ifdef DEBUG +printk (KERN_EMERG "pixcir_i2c_init\n" ); +#endif + + pixcir_wq =create_singlethread_workqueue ("pixcir_wq" );Not needed if you use threaded IRQ.
You mean the threaded IRQ is better than workqueue? If using the threaded IRQ should remove the request_irq()?
Thanks.
-----
Jcbian
--
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
Dmitry Torokhov
maintainerQuoted 9 lines · jcbian
Quoted 8 lines
drivers/input/touchscreen/pixcir_i2c_ts.c line 214
Quoted 4 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +4
-0+ +static int pixcir_i2c_ts_remove (struct i2c_client *client) +{ +struct pixcir_i2c_ts_data *tsdata =dev_get_drvdata (&client->dev);
i2c_get_clientdata(). Also empty line between variable definitions and code.Sorry,what's the meaning here?
1. Use i2c_get_clientdata() instead of dev_get_drvdata() to access driver-private data
2. Add an empty line between variable definitions and the rest of the code.
Quoted 7 lines
Quoted 5 lines
drivers/input/touchscreen/pixcir_i2c_ts.c line 271
Quoted 2 lines
drivers/input/touchscreen/pixcir_i2c_ts.c new file +2
-0+ + pixcir_wq =create_singlethread_workqueue ("pixcir_wq" );Not needed if you use threaded IRQ.
You mean the threaded IRQ is better than workqueue? If using the threaded IRQ should remove the
request_irq()?
You request your IRQ to be serviced by a special thread by doing request_threaded_irq(). Since interrupt processing will happen in a thread you will be able to use sleeping functions directly in your interrupt handler and won't need to rely on a separate workqueue (and do not need to concern yourself with canceling/shutting down the workqeue upon driver unload - which you did not do anyway ;) ).
Thanks.
Signature · 1 line
Dmitry
Hi jcbian,
Here are some duplicate comments and additions to what you already heard from Mark and Dmitry.
Quoted 8 lines
drivers/input/touchscreen/Kconfig +0
-0@@ -693,4 +693,13 @@ config TOUCHSCREEN_TPS6507X To compile this driver as a module, choose M here: the module will be called tps6507x_ts.
drivers/input/touchscreen/Kconfig config TOUCHSCREEN_TPS6507X · line 705
Quoted 10 lines
drivers/input/touchscreen/Kconfig +9
-0+config TOUCHSCREEN_PIXCIR + tristate "PIXCIR touchscreen panel support" + depends on I2C + help + Say Y here if you have a PIXCIR based touchscreen. + + To compile this driver as a module, choose M here: the + module will be called pixcir_i2c_ts. + endif
Please keep Kconfig entries in alphabetical order.
drivers/input/touchscreen/Kconfig
Quoted 4 lines
drivers/input/touchscreen/Kconfig +4
-0+#define DRIVER_VERSION "v1.0" +#define DRIVER_AUTHOR "Bee<[email protected]>,Reed<[email protected]>" +#define DRIVER_DESC "Pixcir I2C Touchscreen Driver" +#define DRIVER_LICENSE "GPL"
Please insert these directly in the module definition.
drivers/input/touchscreen/Kconfig
Quoted 5 lines
drivers/input/touchscreen/Kconfig +5
-0+/* todo:check specs for resolution of touch screen */ +#define TOUCHSCREEN_MINX 0 +#define TOUCHSCREEN_MAXX 400 +#define TOUCHSCREEN_MINY 0 +#define TOUCHSCREEN_MAXY 600
This should really be settled before mainline inclusion.
drivers/input/touchscreen/Kconfig
Quoted 2 lines
drivers/input/touchscreen/Kconfig +2
-0+ +#define DEBUG 0
Odd one...
Quoted 9 lines
drivers/input/touchscreen/Kconfig +9
-0+ +static struct workqueue_struct *pixcir_wq; + +struct pixcir_i2c_ts_data { + struct i2c_client *client; + struct input_dev *input; + struct delayed_work work; + int irq; +};
drivers/input/touchscreen/Kconfig
Quoted 10 lines
drivers/input/touchscreen/Kconfig +10
-0+ +static void pixcir_ts_poscheck(struct work_struct *work) +{ + struct pixcir_i2c_ts_data *tsdata = container_of(work, + struct pixcir_i2c_ts_data, + work.work); + + unsigned char touching, oldtouching; + int posx1, posy1, posx2, posy2; + u_int8_t Rdbuf[10], Wrbuf[1];
Please do not use capitals in variable names.
drivers/input/touchscreen/Kconfig
Quoted 3 lines
drivers/input/touchscreen/Kconfig +3
-0+ int ret; + int z = 50; + int w = 15;
Please remove these fake values altogether.
Quoted 39 lines
drivers/input/touchscreen/Kconfig +39
-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; + } + + 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 != 0 ? 1 : 0)); + + if (touching == 1) { + input_report_abs(tsdata->input, ABS_X, posx1); + input_report_abs(tsdata->input, ABS_Y, posy1); + } + + if (!(touching)) { + z = 0; + w = 0; + } + if (touching == 2) { + input_report_abs(tsdata->input, ABS_MT_TOUCH_MAJOR, z); + input_report_abs(tsdata->input, ABS_MT_WIDTH_MAJOR, w); + input_report_abs(tsdata->input, ABS_MT_POSITION_X, posx1);
drivers/input/touchscreen/Kconfig
Quoted 10 lines
drivers/input/touchscreen/Kconfig +10
-0+ input_report_abs(tsdata->input, ABS_MT_POSITION_Y, posy1); + input_mt_sync(tsdata->input); + + input_report_abs(tsdata->input, ABS_MT_TOUCH_MAJOR, z); + input_report_abs(tsdata->input, ABS_MT_WIDTH_MAJOR, w); + 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);
Please use the slotted type B protocol instead. If the device can track fingers, it is very simple to do, see for instance drivers/input/touchscreen/wacom_w8001.c. If the device cannot do tracking, please do tell and we will add in pending tracking support to the input core together with this driver.
Thanks,
Henrik
Hi Henrik
Thank you very much!
Quoted 133 lines
Hi jcbian,
Here are some duplicate comments and additions to what you already heard from Mark and Dmitry.
Quoted 8 lines
drivers/input/touchscreen/Kconfig +0
-0@@ -693,4 +693,13 @@ config TOUCHSCREEN_TPS6507X To compile this driver as a module, choose M here: the module will be called tps6507x_ts.drivers/input/touchscreen/Kconfig config TOUCHSCREEN_TPS6507X · line 705
Quoted 10 lines
drivers/input/touchscreen/Kconfig +9
-0+config TOUCHSCREEN_PIXCIR + tristate "PIXCIR touchscreen panel support" + depends on I2C + help + Say Y here if you have a PIXCIR based touchscreen. + + To compile this driver as a module, choose M here: the + module will be called pixcir_i2c_ts. + endifPlease keep
Kconfigentries in alphabetical order.drivers/input/touchscreen/Kconfig
Quoted 4 lines
drivers/input/touchscreen/Kconfig +4
-0+#define DRIVER_VERSION "v1.0" +#define DRIVER_AUTHOR "Bee<[email protected]>,Reed<[email protected]>" +#define DRIVER_DESC "Pixcir I2C Touchscreen Driver" +#define DRIVER_LICENSE "GPL"Please insert these directly in the module definition.
drivers/input/touchscreen/Kconfig
Quoted 5 lines
drivers/input/touchscreen/Kconfig +5
-0+/* todo:check specs for resolution of touch screen */ +#define TOUCHSCREEN_MINX 0 +#define TOUCHSCREEN_MAXX 400 +#define TOUCHSCREEN_MINY 0 +#define TOUCHSCREEN_MAXY 600This should really be settled before mainline inclusion.
drivers/input/touchscreen/Kconfig
Quoted 2 lines
drivers/input/touchscreen/Kconfig +2
-0+ +#define DEBUG 0Odd one...
Quoted 9 lines
drivers/input/touchscreen/Kconfig +9
-0+ +static struct workqueue_struct *pixcir_wq; + +struct pixcir_i2c_ts_data { + struct i2c_client *client; + struct input_dev *input; + struct delayed_work work; + int irq; +};drivers/input/touchscreen/Kconfig
Quoted 10 lines
drivers/input/touchscreen/Kconfig +10
-0+ +static void pixcir_ts_poscheck(struct work_struct *work) +{ + struct pixcir_i2c_ts_data *tsdata = container_of(work, + struct pixcir_i2c_ts_data, + work.work); + + unsigned char touching, oldtouching; + int posx1, posy1, posx2, posy2; + u_int8_t Rdbuf[10], Wrbuf[1];Please do not use capitals in variable names.
drivers/input/touchscreen/Kconfig
Quoted 3 lines
drivers/input/touchscreen/Kconfig +3
-0+ int ret; + int z = 50; + int w = 15;Please remove these fake values altogether.
Quoted 39 lines
drivers/input/touchscreen/Kconfig +39
-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; + } + + 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 != 0 ? 1 : 0)); + + if (touching == 1) { + input_report_abs(tsdata->input, ABS_X, posx1); + input_report_abs(tsdata->input, ABS_Y, posy1); + } + + if (!(touching)) { + z = 0; + w = 0; + } + if (touching == 2) { + input_report_abs(tsdata->input, ABS_MT_TOUCH_MAJOR, z); + input_report_abs(tsdata->input, ABS_MT_WIDTH_MAJOR, w); + input_report_abs(tsdata->input, ABS_MT_POSITION_X, posx1);drivers/input/touchscreen/Kconfig
Quoted 10 lines
drivers/input/touchscreen/Kconfig +10
-0+ input_report_abs(tsdata->input, ABS_MT_POSITION_Y, posy1); + input_mt_sync(tsdata->input); + + input_report_abs(tsdata->input, ABS_MT_TOUCH_MAJOR, z); + input_report_abs(tsdata->input, ABS_MT_WIDTH_MAJOR, w); + 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);Please use the slotted type B protocol instead. If the device can track fingers, it is very simple to do, see for instance
drivers/input/touchscreen/wacom_w8001.c. If the device cannot do tracking, please do tell and we will add in pending tracking support to the input core together with this driver.Thanks,
Henrik