Add support for HTC Shift Touchscreen
Subsystems (3)
PATCH 1/1 Add support for HTC Shift Touchscreen
From: Pau Oliva Fora <[email protected]>
The patch below adds support for HTC Shift UMPC touchscreen.
---
Patch against linux-2.6.25.4, should apply clean on other versions too.
drivers/input/touchscreen/htcpen.c +148 -0
@@ -0,0 +1,148 @@ +/* +* HTC Shift touchscreen driver +* +* Copyright (C) 2008 Pau Oliva Fora <[email protected]> +* +* Thanks to: +* Heikki Linnakangas - Penmount LPC touchscreen driver +* Wacom / Ping Cheng - Help on linuxwacom-devel +* Esteve Espuna - Ideas, tips, moral support :) +* +* Changelog: +* 29980517 v0.5 - code cleanup +* 29980517 v0.4 - initialization works (thanks esteve!) +* 20080514 v0.3 - works best with TouchKit egalax xorg driver +* 20080511 v0.2 - little hacks to make it more usable +* 20080510 v0.1 - works with evtouch driver +* 20080428 first non-working attempt +*/ + +/* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2 as published +* by the Free Software Foundation. +*/ + +#include <linux/errno.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/input.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/init.h> +#include <linux/irq.h> + +#define DRIVER_VERSION "v0.5" +#define DRIVER_DESC "HTC Shift touchscreen driver" + +MODULE_AUTHOR ("Pau Oliva Fora <[email protected]>" ); +MODULE_DESCRIPTION (DRIVER_DESC ); +MODULE_LICENSE ("GPL" ); + +#define HTCPEN_PORT0 0x068 +#define HTCPEN_PORT1 0x06c +#define HTCPEN_PORT2 0x0250 +#define HTCPEN_PORT3 0x0251 +#define HTCPEN_IRQ 3 + +static int inverse_y; +module_param (inverse_y, bool,0644 ); +MODULE_PARM_DESC (inverse_y,"If set Y axe is inversed." ); + +struct input_dev *htcpen_dev; + +static void poll_htcpen (void ) +{ + +unsigned short x, y, xy; +unsigned short touch; + +/* 0=press ; 1=release */ +outb_p (0xb ,HTCPEN_PORT2 ); + touch =inb_p (HTCPEN_PORT3 ); +if (touch) + touch =0 ; +else + touch =1 ; + +input_report_key (htcpen_dev,BTN_TOUCH , touch); + +/* only update x/y when screen is being touched */ +if (touch) { +outb_p (3 ,HTCPEN_PORT2 ); + x =inb_p (HTCPEN_PORT3 ); + +outb_p (5 ,HTCPEN_PORT2 ); + y =inb_p (HTCPEN_PORT3 ); + +outb_p (0xc ,HTCPEN_PORT2 ); + xy =inb_p (HTCPEN_PORT3 ); + + x =8 *255 -((x*8 )+((xy>>4 )&0xf )); + y = (y*8 )+(xy&0xf ); +if (inverse_y) + y =8 *255 -y; + +input_report_abs (htcpen_dev,ABS_X , x); +input_report_abs (htcpen_dev,ABS_Y , y); + } + +input_sync (htcpen_dev); + +inb_p (HTCPEN_PORT0 ); +} + +static irqreturn_t htcpen_interrupt (int irq,void *handle) +{ +poll_htcpen (); +return IRQ_HANDLED ; +} + + +static int __init htcpen_init (void ) +{ + +printk (KERN_INFO "htcpen: module inserted\n" ); + +inb_p (HTCPEN_PORT0 ); + + htcpen_dev =input_allocate_device (); +if (!htcpen_dev) { +printk (KERN_ERR "htcpen: can't allocate device\n" ); +return -ENOMEM ; + } + +if (request_irq (HTCPEN_IRQ , htcpen_interrupt,0 ,"htcpen" ,NULL )) { +printk (KERN_ERR "htcpen: irq busy\n" ); +return -EBUSY ; + } + + htcpen_dev->name ="HTC Pen TouchScreen" ; + htcpen_dev->id.bustype =BUS_ISA ; + htcpen_dev->id.vendor =0 ; + htcpen_dev->id.product =0 ; + htcpen_dev->id.version =0 ; + +input_set_abs_params (htcpen_dev,ABS_X ,0 ,255 *8 ,0 ,0 ); +input_set_abs_params (htcpen_dev,ABS_Y ,0 ,255 *8 ,0 ,0 ); + + htcpen_dev->evbit[0 ] =BIT_MASK (EV_ABS ) |BIT_MASK (EV_KEY ); + htcpen_dev->absbit[0 ] =BIT_MASK (ABS_X ) |BIT_MASK (ABS_Y ); + htcpen_dev->keybit[BIT_WORD (BTN_TOUCH )] =BIT_MASK (BTN_TOUCH ); + +input_register_device (htcpen_dev); + +outb_p (0xa2 ,HTCPEN_PORT1 ); + +return 0 ; +} + +static void __exit htcpen_exit(void) +{ +input_unregister_device (htcpen_dev); +free_irq (HTCPEN_IRQ ,NULL ); +printk (KERN_INFO "htcpen: module removed\n" ); +} + +module_init (htcpen_init); +module_exit (htcpen_exit);
drivers/input/touchscreen/Kconfig +11 -0
@@ -134,6 +134,17 @@ config TOUCHSCREEN_HP7XX To compile this driver as a module, choose M here: the module will be called jornada720_ts. +config TOUCHSCREEN_HTCPEN + tristate "HTC Shift X9500 touchscreen" + help + Say Y here if you have an HTC Shift UMPC also known as HTC X9500 + Clio / Shangrila and want to support the built-in touchscreen. + + If unsure, say N. + + To compile this driver as a module, choose M here: the + module will be called htcpen. + config TOUCHSCREEN_PENMOUNT tristate "Penmount serial touchscreen" select SERIO
drivers/input/touchscreen/Makefile +1 -0
@@ -14,6 +14,7 @@ obj-$(CONFIG_TOUCHSCREEN_MTOUCH) += mtou obj-$(CONFIG_TOUCHSCREEN_MK712) += mk712.o obj-$(CONFIG_TOUCHSCREEN_HP600) += hp680_ts_input.o obj-$(CONFIG_TOUCHSCREEN_HP7XX) += jornada720_ts.o +obj-$(CONFIG_TOUCHSCREEN_HTCPEN) += htcpen.o obj-$(CONFIG_TOUCHSCREEN_USB_COMPOSITE) += usbtouchscreen.o obj-$(CONFIG_TOUCHSCREEN_PENMOUNT) += penmount.o obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o
Hi Pau.
Some nitpick comments - looks good overall.
Quoted 25 lines · Pau Oliva Fora
From: Pau Oliva Fora <[email protected]>
The patch below adds support for HTC Shift UMPC touchscreen.
Signed-off-by Pau Oliva Fora <[email protected]>---
Patch against linux-2.6.25.4, should apply clean on other versions too.
diff -uprN
linux-2.6.25.4/drivers/input/touchscreen/htcpen.clinux/drivers/input/touchscreen/htcpen.c
---linux-2.6.25.4/drivers/input/touchscreen/htcpen.c1970-01-01
01:00:00.000000000 +0100
+++linux/drivers/input/touchscreen/htcpen.c2008-05-17
13:48:57.000000000 +0200drivers/input/touchscreen/htcpen.c +7
-0@@ -0,0 +1,148 @@ +/* +* HTC Shift touchscreen driver +* +* Copyright (C) 2008 Pau Oliva Fora <[email protected]> +* +* Thanks to: +* Heikki Linnakangas - Penmount LPC touchscreen driver
drivers/input/touchscreen/htcpen.c line 17
Quoted 10 lines
drivers/input/touchscreen/htcpen.c +10
-0+* Wacom / Ping Cheng - Help on linuxwacom-devel +* Esteve Espuna - Ideas, tips, moral support :) +* +* Changelog: +* 29980517 v0.5 - code cleanup +* 29980517 v0.4 - initialization works (thanks esteve!) +* 20080514 v0.3 - works best with TouchKit egalax xorg driver +* 20080511 v0.2 - little hacks to make it more usable +* 20080510 v0.1 - works with evtouch driver +* 20080428 first non-working attempt
Drop changelog - we do not keep them in-kernel. Here we rely on git.
You can add it to your commit message if your prefer to have it saved.
Quoted 18 lines
drivers/input/touchscreen/htcpen.c +18
-0+*/ + +/* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2 as published +* by the Free Software Foundation. +*/ + +#include <linux/errno.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/input.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/init.h> +#include <linux/irq.h> + +#define DRIVER_VERSION "v0.5"
drivers/input/touchscreen/htcpen.c line 45
Quoted 10 lines
drivers/input/touchscreen/htcpen.c +10
-0+#define DRIVER_DESC "HTC Shift touchscreen driver" + +MODULE_AUTHOR ("Pau Oliva Fora <[email protected]>" ); +MODULE_DESCRIPTION (DRIVER_DESC ); +MODULE_LICENSE ("GPL" ); + +#define HTCPEN_PORT0 0x068 +#define HTCPEN_PORT1 0x06c +#define HTCPEN_PORT2 0x0250 +#define HTCPEN_PORT3 0x0251
The use of the four ports would be nice to be documented
drivers/input/touchscreen/htcpen.c line 57
Quoted 12 lines
drivers/input/touchscreen/htcpen.c +12
-0+#define HTCPEN_IRQ 3 + +static int inverse_y; +module_param (inverse_y, bool,0644 ); +MODULE_PARM_DESC (inverse_y,"If set Y axe is inversed." ); + +struct input_dev *htcpen_dev; + +static void poll_htcpen (void ) +{ + +unsigned short x, y, xy;
General comment.
In kernel we usually do not have an empty line following the opening '{'
Quoted 5 lines
drivers/input/touchscreen/htcpen.c +5
-0+unsigned short touch; + +/* 0=press ; 1=release */ +outb_p (0xb ,HTCPEN_PORT2 ); + touch =inb_p (HTCPEN_PORT3 );
drivers/input/touchscreen/htcpen.c line 72
Quoted 10 lines
drivers/input/touchscreen/htcpen.c +10
-0+if (touch) + touch =0 ; +else + touch =1 ; + +input_report_key (htcpen_dev,BTN_TOUCH , touch); + +/* only update x/y when screen is being touched */ +if (touch) { +outb_p (3 ,HTCPEN_PORT2 );
What is the semantic of 3 here.
Add a comment or a DEFINE
drivers/input/touchscreen/htcpen.c line 75
Quoted 3 lines
drivers/input/touchscreen/htcpen.c +3
-0+ x =inb_p (HTCPEN_PORT3 ); + +outb_p (5 ,HTCPEN_PORT2 );
Same here.
drivers/input/touchscreen/htcpen.c line 78
Quoted 3 lines
drivers/input/touchscreen/htcpen.c +3
-0+ y =inb_p (HTCPEN_PORT3 ); + +outb_p (0xc ,HTCPEN_PORT2 );
Same here.
drivers/input/touchscreen/htcpen.c line 84
Quoted 6 lines
drivers/input/touchscreen/htcpen.c +6
-0+ xy =inb_p (HTCPEN_PORT3 ); + + x =8 *255 -((x*8 )+((xy>>4 )&0xf )); + y = (y*8 )+(xy&0xf ); +if (inverse_y) + y =8 *255 -y;
These calculations needs spaces and comments.
Quoted 24 lines
drivers/input/touchscreen/htcpen.c +24
-0+ +input_report_abs (htcpen_dev,ABS_X , x); +input_report_abs (htcpen_dev,ABS_Y , y); + } + +input_sync (htcpen_dev); + +inb_p (HTCPEN_PORT0 ); +} + +static irqreturn_t htcpen_interrupt (int irq,void *handle) +{ +poll_htcpen (); +return IRQ_HANDLED ; +} + + +static int __init htcpen_init (void ) +{ + +printk (KERN_INFO "htcpen: module inserted\n" ); + +inb_p (HTCPEN_PORT0 ); +
drivers/input/touchscreen/htcpen.c line 118
Quoted 10 lines
drivers/input/touchscreen/htcpen.c +10
-0+ htcpen_dev =input_allocate_device (); +if (!htcpen_dev) { +printk (KERN_ERR "htcpen: can't allocate device\n" ); +return -ENOMEM ; + } + +if (request_irq (HTCPEN_IRQ , htcpen_interrupt,0 ,"htcpen" ,NULL )) { +printk (KERN_ERR "htcpen: irq busy\n" ); +return -EBUSY ; + }
I would asusme you are missing a: input_unregister_device(htcpen_dev);?
drivers/input/touchscreen/htcpen.c line 127
Quoted 9 lines
drivers/input/touchscreen/htcpen.c +9
-0+ + htcpen_dev->name ="HTC Pen TouchScreen" ; + htcpen_dev->id.bustype =BUS_ISA ; + htcpen_dev->id.vendor =0 ; + htcpen_dev->id.product =0 ; + htcpen_dev->id.version =0 ; + +input_set_abs_params (htcpen_dev,ABS_X ,0 ,255 *8 ,0 ,0 ); +input_set_abs_params (htcpen_dev,ABS_Y ,0 ,255 *8 ,0 ,0 );
Again a 'magic' calculation
Quoted 11 lines
drivers/input/touchscreen/htcpen.c +11
-0+ + htcpen_dev->evbit[0 ] =BIT_MASK (EV_ABS ) |BIT_MASK (EV_KEY ); + htcpen_dev->absbit[0 ] =BIT_MASK (ABS_X ) |BIT_MASK (ABS_Y ); + htcpen_dev->keybit[BIT_WORD (BTN_TOUCH )] =BIT_MASK (BTN_TOUCH ); + +input_register_device (htcpen_dev); + +outb_p (0xa2 ,HTCPEN_PORT1 ); + +return 0 ; +}
drivers/input/touchscreen/htcpen.c line 148
Quoted 10 lines
drivers/input/touchscreen/htcpen.c +10
-0+ +static void __exit htcpen_exit(void) +{ +input_unregister_device (htcpen_dev); +free_irq (HTCPEN_IRQ ,NULL ); +printk (KERN_INFO "htcpen: module removed\n" ); +} + +module_init (htcpen_init); +module_exit (htcpen_exit);
Sam
Hi Pau,
Quoted 8 lines · Pau Oliva Fora
drivers/input/touchscreen/htcpen.c +7
-0@@ -0,0 +1,148 @@ +/* +* HTC Shift touchscreen driver +* +* Copyright (C) 2008 Pau Oliva Fora <[email protected]> +* +* Thanks to: +* Heikki Linnakangas - Penmount LPC touchscreen driver
drivers/input/touchscreen/htcpen.c line 17
Quoted 10 lines
drivers/input/touchscreen/htcpen.c +10
-0+* Wacom / Ping Cheng - Help on linuxwacom-devel +* Esteve Espuna - Ideas, tips, moral support :) +* +* Changelog: +* 29980517 v0.5 - code cleanup +* 29980517 v0.4 - initialization works (thanks esteve!) +* 20080514 v0.3 - works best with TouchKit egalax xorg driver +* 20080511 v0.2 - little hacks to make it more usable +* 20080510 v0.1 - works with evtouch driver +* 20080428 first non-working attempt
Please drop the changelog from your source file.
Quoted 8 lines
drivers/input/touchscreen/htcpen.c +8
-0+#define DRIVER_VERSION "v0.5" +#define DRIVER_DESC "HTC Shift touchscreen driver" + +MODULE_AUTHOR ("Pau Oliva Fora <[email protected]>" ); +MODULE_DESCRIPTION (DRIVER_DESC ); +MODULE_LICENSE ("GPL" ); + +#define HTCPEN_PORT0 0x068
drivers/input/touchscreen/htcpen.c line 52
Quoted 10 lines
drivers/input/touchscreen/htcpen.c +10
-0+#define HTCPEN_PORT1 0x06c +#define HTCPEN_PORT2 0x0250 +#define HTCPEN_PORT3 0x0251 +#define HTCPEN_IRQ 3 + +static int inverse_y; +module_param (inverse_y, bool,0644 ); +MODULE_PARM_DESC (inverse_y,"If set Y axe is inversed." ); + +struct input_dev *htcpen_dev;
Why are you not using isa_register_driver() instead?
drivers/input/touchscreen/htcpen.c line 56
Quoted 4 lines
drivers/input/touchscreen/htcpen.c +4
-0+ +static void poll_htcpen (void ) +{ +
Extra newline.
drivers/input/touchscreen/htcpen.c line 104
Quoted 5 lines
drivers/input/touchscreen/htcpen.c +5
-0+unsigned short x, y, xy; +unsigned short touch; +static int __init htcpen_init (void ) +{ +
Extra newline.
drivers/input/touchscreen/htcpen.c line 107
Quoted 3 lines
drivers/input/touchscreen/htcpen.c +3
-0+printk (KERN_INFO "htcpen: module inserted\n" ); + +inb_p (HTCPEN_PORT0 );
So there's no way to probe the existence of this device?
drivers/input/touchscreen/htcpen.c line 115
Quoted 8 lines
drivers/input/touchscreen/htcpen.c +8
-0+ + htcpen_dev =input_allocate_device (); +if (!htcpen_dev) { +printk (KERN_ERR "htcpen: can't allocate device\n" ); +return -ENOMEM ; + } + +if (request_irq (HTCPEN_IRQ , htcpen_interrupt,0 ,"htcpen" ,NULL )) {
This is leaking htcpen_dev here. Look at some other drivers for examples how to use gotos for this kind of error handling.
Quoted 4 lines
drivers/input/touchscreen/htcpen.c +4
-0+printk (KERN_ERR "htcpen: irq busy\n" ); +return -EBUSY ; + } +
From: Pau Oliva Fora <[email protected]>
The patch below adds support for HTC Shift UMPC touchscreen.
---
Patch against linux-2.6.25.4, should apply clean on other versions too. Thanks to Sam Ravnborg and Pekka Enberg for their comments, my reply below:
Quoted 1 line · Sam Ravnborg
The use of the four ports would be nice to be documented
done, changed the DEFINE names
Quoted 3 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ outb_p(3, HTCPEN_PORT2);What is the semantic of 3 here.
Add a comment or a DEFINE
added DEFINES for those
Quoted 1 line
These calculations needs spaces and comments.
Done, hope is ok now.
Quoted 1 line
I would asusme you are missing a:
input_unregister_device(htcpen_dev);?
no, device is not yet registered here.
Quoted 3 lines · Pekka Enberg
Quoted 1 line
+struct
input_dev*htcpen_dev;Why are you not using
isa_register_driver()instead?
I have no specifications from the manufacturer, so don't know how to properly prove the device, etc.
Quoted 5 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ printk(KERN_INFO "htcpen: module inserted\n"); + + inb_p(HTCPEN_PORT0);So there's no way to probe the existence of this device?
I can add a minimal sanity check if that is a must, but I don't have a datasheet and contacting HTC did not help.
Quoted 4 lines
Quoted 1 line
+ if (
request_irq(HTCPEN_IRQ, htcpen_interrupt, 0, "htcpen", NULL)) {This is leaking
htcpen_devhere. Look at some other drivers for examples how to use gotos for this kind of error handling.
Thanks, should be fixed now.
drivers/input/touchscreen/htcpen.c +155 -0
@@ -0,0 +1,155 @@ +/* +* HTC Shift touchscreen driver +* +* Copyright (C) 2008 Pau Oliva Fora <[email protected]> +* +* Thanks to: +* Heikki Linnakangas - Penmount LPC touchscreen driver +* Wacom / Ping Cheng - Help on linuxwacom-devel +* Esteve Espuna - Ideas, tips, moral support :) +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2 as published +* by the Free Software Foundation. +*/ + +#include <linux/errno.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/input.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/init.h> +#include <linux/irq.h> + +#define DRIVER_VERSION "v0.5" +#define DRIVER_DESC "HTC Shift touchscreen driver" + +MODULE_AUTHOR ("Pau Oliva Fora <[email protected]>" ); +MODULE_DESCRIPTION (DRIVER_DESC ); +MODULE_LICENSE ("GPL" ); + +#define HTCPEN_PORT_IRQ_CLEAR 0x068 +#define HTCPEN_PORT_INIT 0x06c +#define HTCPEN_PORT_INDEX 0x0250 +#define HTCPEN_PORT_DATA 0x0251 +#define HTCPEN_IRQ 3 + +#define X_INDEX 3 +#define Y_INDEX 5 +#define LSB_XY_INDEX 0xc +#define X_AXIS_MAX 2040 +#define Y_AXIS_MAX 2040 +#define DEVICE_ENABLE 0xa2 + +static int inverse_y; +module_param (inverse_y, bool,0644 ); +MODULE_PARM_DESC (inverse_y,"If set Y axis is inversed." ); + +struct input_dev *htcpen_dev; + +static void poll_htcpen (void ) +{ +unsigned short x, y, xy; +unsigned short touch; + +/* 0=press ; 1=release */ +outb_p (0xb ,HTCPEN_PORT_INDEX ); + touch =inb_p (HTCPEN_PORT_DATA ); +if (touch) + touch =0 ; +else + touch =1 ; + +input_report_key (htcpen_dev,BTN_TOUCH , touch); + +/* only update X/Y when screen is being touched */ +if (touch) { +outb_p (X_INDEX ,HTCPEN_PORT_INDEX ); + x =inb_p (HTCPEN_PORT_DATA ); + +outb_p (Y_INDEX ,HTCPEN_PORT_INDEX ); + y =inb_p (HTCPEN_PORT_DATA ); + +outb_p (LSB_XY_INDEX ,HTCPEN_PORT_INDEX ); + xy =inb_p (HTCPEN_PORT_DATA ); + +/* get high resolution value of X and Y using LSB */ + x =X_AXIS_MAX - ((x *8 ) + ((xy >>4 ) &0xf )); + y = (y *8 ) + (xy &0xf ); +if (inverse_y) + y =Y_AXIS_MAX - y; + +input_report_abs (htcpen_dev,ABS_X , x); +input_report_abs (htcpen_dev,ABS_Y , y); + } + +input_sync (htcpen_dev); + +inb_p (HTCPEN_PORT_IRQ_CLEAR ); +} + +static irqreturn_t htcpen_interrupt (int irq,void *handle) +{ +poll_htcpen (); +return IRQ_HANDLED ; +} + +static int __init htcpen_init (void ) +{ +int err; + +printk (KERN_INFO "htcpen: module inserted\n" ); + +inb_p (HTCPEN_PORT_IRQ_CLEAR ); + + htcpen_dev =input_allocate_device (); +if (!htcpen_dev) { +printk (KERN_ERR "htcpen: can't allocate device\n" ); + err = -ENOMEM ; + goto fail1; + } + + htcpen_dev->name ="HTC Pen TouchScreen" ; + htcpen_dev->id.bustype =BUS_ISA ; + htcpen_dev->id.vendor =0 ; + htcpen_dev->id.product =0 ; + htcpen_dev->id.version =0 ; + +input_set_abs_params (htcpen_dev,ABS_X ,0 ,X_AXIS_MAX ,0 ,0 ); +input_set_abs_params (htcpen_dev,ABS_Y ,0 ,Y_AXIS_MAX ,0 ,0 ); + + htcpen_dev->evbit[0 ] =BIT_MASK (EV_ABS ) |BIT_MASK (EV_KEY ); + htcpen_dev->absbit[0 ] =BIT_MASK (ABS_X ) |BIT_MASK (ABS_Y ); + htcpen_dev->keybit[BIT_WORD (BTN_TOUCH )] =BIT_MASK (BTN_TOUCH ); + + err =request_irq (HTCPEN_IRQ , htcpen_interrupt,0 ,"htcpen" , + htcpen_dev); +if (err) { +printk (KERN_ERR "htcpen: irq busy\n" ); + err = -EBUSY ; + goto fail1; + } + + err =input_register_device (htcpen_dev); +if (err) + goto fail2; + +outb_p (DEVICE_ENABLE ,HTCPEN_PORT_INIT ); + +return 0 ; + + fail2:free_irq (HTCPEN_IRQ , htcpen_dev); + fail1:input_free_device (htcpen_dev); +return err; +} + +static void __exit htcpen_exit(void) +{ +input_unregister_device (htcpen_dev); +free_irq (HTCPEN_IRQ , htcpen_dev); +printk (KERN_INFO "htcpen: module removed\n" ); +} + +module_init (htcpen_init); +module_exit (htcpen_exit);
drivers/input/touchscreen/Kconfig +11 -0
@@ -134,6 +134,17 @@ config TOUCHSCREEN_HP7XX To compile this driver as a module, choose M here: the module will be called jornada720_ts. +config TOUCHSCREEN_HTCPEN + tristate "HTC Shift X9500 touchscreen" + help + Say Y here if you have an HTC Shift UMPC also known as HTC X9500 + Clio / Shangrila and want to support the built-in touchscreen. + + If unsure, say N. + + To compile this driver as a module, choose M here: the + module will be called htcpen. + config TOUCHSCREEN_PENMOUNT tristate "Penmount serial touchscreen" select SERIO
drivers/input/touchscreen/Makefile +1 -0
@@ -14,6 +14,7 @@ obj-$(CONFIG_TOUCHSCREEN_MTOUCH) += mtou obj-$(CONFIG_TOUCHSCREEN_MK712) += mk712.o obj-$(CONFIG_TOUCHSCREEN_HP600) += hp680_ts_input.o obj-$(CONFIG_TOUCHSCREEN_HP7XX) += jornada720_ts.o +obj-$(CONFIG_TOUCHSCREEN_HTCPEN) += htcpen.o obj-$(CONFIG_TOUCHSCREEN_USB_COMPOSITE) += usbtouchscreen.o obj-$(CONFIG_TOUCHSCREEN_PENMOUNT) += penmount.o obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o
drivers/input/touchscreen/htcpen.c line 110
Quoted 13 lines · Pau Oliva Fora
drivers/input/touchscreen/htcpen.c +13
-0+static int __init htcpen_init (void ) +{ +int err; + +printk (KERN_INFO "htcpen: module inserted\n" ); + +inb_p (HTCPEN_PORT_IRQ_CLEAR ); + + htcpen_dev =input_allocate_device (); +if (!htcpen_dev) { +printk (KERN_ERR "htcpen: can't allocate device\n" ); + err = -ENOMEM ; + goto fail1;
htcpen_dev is null here, so no need to call input_free_device
Quoted 30 lines
drivers/input/touchscreen/htcpen.c +30
-0+ } + + htcpen_dev->name ="HTC Pen TouchScreen" ; + htcpen_dev->id.bustype =BUS_ISA ; + htcpen_dev->id.vendor =0 ; + htcpen_dev->id.product =0 ; + htcpen_dev->id.version =0 ; + +input_set_abs_params (htcpen_dev,ABS_X ,0 ,X_AXIS_MAX ,0 ,0 ); +input_set_abs_params (htcpen_dev,ABS_Y ,0 ,Y_AXIS_MAX ,0 ,0 ); + + htcpen_dev->evbit[0 ] =BIT_MASK (EV_ABS ) |BIT_MASK (EV_KEY ); + htcpen_dev->absbit[0 ] =BIT_MASK (ABS_X ) |BIT_MASK (ABS_Y ); + htcpen_dev->keybit[BIT_WORD (BTN_TOUCH )] =BIT_MASK (BTN_TOUCH ); + + err =request_irq (HTCPEN_IRQ , htcpen_interrupt,0 ,"htcpen" , + htcpen_dev); +if (err) { +printk (KERN_ERR "htcpen: irq busy\n" ); + err = -EBUSY ; + goto fail1; + } + + err =input_register_device (htcpen_dev); +if (err) + goto fail2; + +outb_p (DEVICE_ENABLE ,HTCPEN_PORT_INIT ); + +return 0 ;
drivers/input/touchscreen/htcpen.c line 150
Quoted 10 lines
drivers/input/touchscreen/htcpen.c +10
-0+ + fail2:free_irq (HTCPEN_IRQ , htcpen_dev); + fail1:input_free_device (htcpen_dev); +return err; +} + +static void __exit htcpen_exit(void) +{ +input_unregister_device (htcpen_dev); +free_irq (HTCPEN_IRQ , htcpen_dev);
input_free_device ?
drivers/input/touchscreen/htcpen.c line 152
Quoted 2 lines
drivers/input/touchscreen/htcpen.c +2
-0+printk (KERN_INFO "htcpen: module removed\n" ); +}
Marcin
Quoted 6 lines · Pau Oliva Fora
Quoted 3 lines
Quoted 1 line
+struct
input_dev*htcpen_dev;Why are you not using
isa_register_driver()instead?I have no specifications from the manufacturer, so don't know how to properly prove the device, etc.
You can still use isa_register_driver() which is nicer IMHO.
Quoted 8 lines · Pau Oliva Fora
Quoted 5 lines
drivers/input/touchscreen/htcpen.c
Quoted 3 lines
drivers/input/touchscreen/htcpen.c +3
-0+printk (KERN_INFO "htcpen: module inserted\n" ); + +inb_p (HTCPEN_PORT0 );So there's no way to probe the existence of this device?
I can add a minimal sanity check if that is a must, but I don't have a datasheet and contacting HTC did not help.
Well, you probably want distributions to be able to enable this by default so any kind probing is helpful, yes.
The patch below adds support for HTC Shift UMPC touchscreen.
---
Patch against linux-2.6.25.4, should apply clean on other versions too. Includes all the suggestions by Sam Ravnborg, Pekka Enberg and Marcin Slusarz.
drivers/input/touchscreen/htcpen.c +199 -0
@@ -0,0 +1,199 @@ +/* +* HTC Shift touchscreen driver +* +* Copyright (C) 2008 Pau Oliva Fora <[email protected]> +* +* Thanks to: +* Heikki Linnakangas - Penmount LPC touchscreen driver +* Wacom / Ping Cheng - Help on linuxwacom-devel +* Esteve Espuna - Ideas, tips, moral support :) +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2 as published +* by the Free Software Foundation. +*/ + +#include <linux/errno.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/input.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/init.h> +#include <linux/irq.h> +#include <linux/isa.h> + +#define DRIVER_VERSION "0.7" +#define DRIVER_DESC "HTC Shift touchscreen driver v" DRIVER_VERSION + +MODULE_AUTHOR ("Pau Oliva Fora <[email protected]>" ); +MODULE_DESCRIPTION (DRIVER_DESC ); +MODULE_VERSION (DRIVER_VERSION ); +MODULE_LICENSE ("GPL" ); + +#define HTCPEN_PORT_IRQ_CLEAR 0x068 +#define HTCPEN_PORT_INIT 0x06c +#define HTCPEN_PORT_INDEX 0x0250 +#define HTCPEN_PORT_DATA 0x0251 +#define HTCPEN_IRQ 3 + +#define X_INDEX 3 +#define Y_INDEX 5 +#define LSB_XY_INDEX 0xc +#define X_AXIS_MAX 2040 +#define Y_AXIS_MAX 2040 +#define DEVICE_ENABLE 0xa2 + +static int inverse_x; +module_param (inverse_x, bool,0644 ); +MODULE_PARM_DESC (inverse_x,"If set X axis is inversed" ); +static int inverse_y; +module_param (inverse_y, bool,0644 ); +MODULE_PARM_DESC (inverse_y,"If set Y axis is inversed" ); + +struct input_dev *htcpen_dev; + +static void poll_htcpen (void ) +{ +unsigned short x, y, xy; +unsigned short touch; + +/* 0=press ; 1=release */ +outb_p (0xb ,HTCPEN_PORT_INDEX ); + touch =inb_p (HTCPEN_PORT_DATA ); +if (touch) + touch =0 ; +else + touch =1 ; + +input_report_key (htcpen_dev,BTN_TOUCH , touch); + +/* only update X/Y when screen is being touched */ +if (touch) { +outb_p (X_INDEX ,HTCPEN_PORT_INDEX ); + x =inb_p (HTCPEN_PORT_DATA ); + +outb_p (Y_INDEX ,HTCPEN_PORT_INDEX ); + y =inb_p (HTCPEN_PORT_DATA ); + +outb_p (LSB_XY_INDEX ,HTCPEN_PORT_INDEX ); + xy =inb_p (HTCPEN_PORT_DATA ); + +/* get high resolution value of X and Y using LSB */ + x =X_AXIS_MAX - ((x *8 ) + ((xy >>4 ) &0xf )); + y = (y *8 ) + (xy &0xf ); +if (inverse_x) + x =X_AXIS_MAX - x; +if (inverse_y) + y =Y_AXIS_MAX - y; + +input_report_abs (htcpen_dev,ABS_X , x); +input_report_abs (htcpen_dev,ABS_Y , y); + } + +input_sync (htcpen_dev); + +inb_p (HTCPEN_PORT_IRQ_CLEAR ); +} + +static irqreturn_t htcpen_interrupt (int irq,void *handle) +{ +poll_htcpen (); +return IRQ_HANDLED ; +} + +static int __devinit htcpen_isa_probe (struct device *dev,unsigned int id) +{ +int err; + +printk (KERN_INFO "htcpen: %s\n" ,DRIVER_DESC ); + +inb_p (HTCPEN_PORT_IRQ_CLEAR ); + + htcpen_dev =input_allocate_device (); +if (!htcpen_dev) { +printk (KERN_ERR "htcpen: can't allocate device\n" ); + err = -ENOMEM ; + goto fail1; + } + + htcpen_dev->name ="HTC Pen TouchScreen" ; + htcpen_dev->id.bustype =BUS_ISA ; + htcpen_dev->id.vendor =0 ; + htcpen_dev->id.product =0 ; + htcpen_dev->id.version =0 ; + +input_set_abs_params (htcpen_dev,ABS_X ,0 ,X_AXIS_MAX ,0 ,0 ); +input_set_abs_params (htcpen_dev,ABS_Y ,0 ,Y_AXIS_MAX ,0 ,0 ); + + htcpen_dev->evbit[0 ] =BIT_MASK (EV_ABS ) |BIT_MASK (EV_KEY ); + htcpen_dev->absbit[0 ] =BIT_MASK (ABS_X ) |BIT_MASK (ABS_Y ); + htcpen_dev->keybit[BIT_WORD (BTN_TOUCH )] =BIT_MASK (BTN_TOUCH ); + + err =request_irq (HTCPEN_IRQ , htcpen_interrupt,0 ,"htcpen" , + htcpen_dev); +if (err) { +printk (KERN_ERR "htcpen: irq busy\n" ); + err = -EBUSY ; + goto fail2; + } + + err =input_register_device (htcpen_dev); +if (err) + goto fail3; + +outb_p (DEVICE_ENABLE ,HTCPEN_PORT_INIT ); + +return 0 ; + + fail3:free_irq (HTCPEN_IRQ , htcpen_dev); + fail2:input_free_device (htcpen_dev); + fail1: +return err; +} + +static int __devinit htcpen_isa_match (struct device *dev,unsigned int id) +{ +unsigned short val1, val2; + +/* device detection */ + val1 =inb_p (HTCPEN_PORT_INIT ); + val2 =inb_p (HTCPEN_PORT_IRQ_CLEAR ); +if ((val1 !=0x8 && val1 !=0x9 && val1 !=0xa ) || (val2 !=0x55 )) { +printk (KERN_ERR "htcpen: no such device\n" ); +return 0 ; + } +return 1 ; +} + +static int __devexit htcpen_isa_remove(struct device *dev, unsigned int id) +{ +input_unregister_device (htcpen_dev); +free_irq (HTCPEN_IRQ , htcpen_dev); +input_free_device (htcpen_dev); +printk (KERN_INFO "htcpen: module removed\n" ); +return 0 ; +} + +static struct isa_driver htcpen_isa_driver = { + .match = htcpen_isa_match, + .probe = htcpen_isa_probe, + .remove =__devexit_p (htcpen_isa_remove), + .driver = { + .owner =THIS_MODULE , + .name ="htcpen" , + } +}; + +static int __init htcpen_isa_init (void ) +{ +return isa_register_driver (&htcpen_isa_driver,1 ); +} + +static void __exit htcpen_isa_exit(void) +{ +isa_unregister_driver (&htcpen_isa_driver); +} + +module_init (htcpen_isa_init); +module_exit (htcpen_isa_exit);
drivers/input/touchscreen/Kconfig +11 -0
@@ -134,6 +134,17 @@ config TOUCHSCREEN_HP7XX To compile this driver as a module, choose M here: the module will be called jornada720_ts. +config TOUCHSCREEN_HTCPEN + tristate "HTC Shift X9500 touchscreen" + help + Say Y here if you have an HTC Shift UMPC also known as HTC X9500 + Clio / Shangrila and want to support the built-in touchscreen. + + If unsure, say N. + + To compile this driver as a module, choose M here: the + module will be called htcpen. + config TOUCHSCREEN_PENMOUNT tristate "Penmount serial touchscreen" select SERIO
drivers/input/touchscreen/Makefile +1 -0
@@ -14,6 +14,7 @@ obj-$(CONFIG_TOUCHSCREEN_MTOUCH) += mtou obj-$(CONFIG_TOUCHSCREEN_MK712) += mk712.o obj-$(CONFIG_TOUCHSCREEN_HP600) += hp680_ts_input.o obj-$(CONFIG_TOUCHSCREEN_HP7XX) += jornada720_ts.o +obj-$(CONFIG_TOUCHSCREEN_HTCPEN) += htcpen.o obj-$(CONFIG_TOUCHSCREEN_USB_COMPOSITE) += usbtouchscreen.o obj-$(CONFIG_TOUCHSCREEN_PENMOUNT) += penmount.o obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o
Quoted 62 lines · Pau Oliva Fora
The patch below adds support for HTC Shift UMPC touchscreen.
Signed-off-by Pau Oliva Fora <[email protected]>---
Patch against linux-2.6.25.4, should apply clean on other versions too. Includes all the suggestions by Sam Ravnborg, Pekka Enberg and Marcin Slusarz.
diff -uprN
linux-2.6.25.4/drivers/input/touchscreen/htcpen.clinux/drivers/input/touchscreen/htcpen.c
---linux-2.6.25.4/drivers/input/touchscreen/htcpen.c1970-01-01
01:00:00.000000000 +0100
+++linux/drivers/input/touchscreen/htcpen.c2008-05-19
04:44:16.000000000 +0200drivers/input/touchscreen/htcpen.c +44
-0@@ -0,0 +1,199 @@ +/* +* HTC Shift touchscreen driver +* +* Copyright (C) 2008 Pau Oliva Fora <[email protected]> +* +* Thanks to: +* Heikki Linnakangas - Penmount LPC touchscreen driver +* Wacom / Ping Cheng - Help on linuxwacom-devel +* Esteve Espuna - Ideas, tips, moral support :) +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2 as published +* by the Free Software Foundation. +*/ + +#include <linux/errno.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/input.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/init.h> +#include <linux/irq.h> +#include <linux/isa.h> + +#define DRIVER_VERSION "0.7" +#define DRIVER_DESC "HTC Shift touchscreen driver v" DRIVER_VERSION + +MODULE_AUTHOR ("Pau Oliva Fora <[email protected]>" ); +MODULE_DESCRIPTION (DRIVER_DESC ); +MODULE_VERSION (DRIVER_VERSION ); +MODULE_LICENSE ("GPL" ); + +#define HTCPEN_PORT_IRQ_CLEAR 0x068 +#define HTCPEN_PORT_INIT 0x06c +#define HTCPEN_PORT_INDEX 0x0250 +#define HTCPEN_PORT_DATA 0x0251 +#define HTCPEN_IRQ 3 + +#define X_INDEX 3 +#define Y_INDEX 5 +#define LSB_XY_INDEX 0xc +#define X_AXIS_MAX 2040 +#define Y_AXIS_MAX 2040
drivers/input/touchscreen/htcpen.c line 54
Quoted 10 lines
drivers/input/touchscreen/htcpen.c +10
-0+#define DEVICE_ENABLE 0xa2 + +static int inverse_x; +module_param (inverse_x, bool,0644 ); +MODULE_PARM_DESC (inverse_x,"If set X axis is inversed" ); +static int inverse_y; +module_param (inverse_y, bool,0644 ); +MODULE_PARM_DESC (inverse_y,"If set Y axis is inversed" ); + +struct input_dev *htcpen_dev;
The point of converting to isa_register_driver() is to use dev_set_drvdata()/dev_get_drvdata() instead of having a global variable like this.
From: Pau Oliva Fora <[email protected]>
The patch below adds support for HTC Shift UMPC touchscreen.
---
Patch against linux-2.6.25.4, should apply clean on other versions too. Includes all the suggestions from Sam Ravnborg, Pekka Enberg and Marcin Slusarz. Thank you all for your help, hopefully everything is ok now.
drivers/input/touchscreen/htcpen.c +205 -0
@@ -0,0 +1,205 @@ +/* +* HTC Shift touchscreen driver +* +* Copyright (C) 2008 Pau Oliva Fora <[email protected]> +* +* Thanks to: +* Heikki Linnakangas - Penmount LPC touchscreen driver +* Wacom / Ping Cheng - Help on linuxwacom-devel +* Esteve Espuna - Ideas, tips, moral support :) +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2 as published +* by the Free Software Foundation. +*/ + +#include <linux/errno.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/input.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/init.h> +#include <linux/irq.h> +#include <linux/isa.h> + +#define DRIVER_VERSION "0.8" +#define DRIVER_DESC "HTC Shift touchscreen driver v" DRIVER_VERSION + +MODULE_AUTHOR ("Pau Oliva Fora <[email protected]>" ); +MODULE_DESCRIPTION (DRIVER_DESC ); +MODULE_VERSION (DRIVER_VERSION ); +MODULE_LICENSE ("GPL" ); + +#define HTCPEN_PORT_IRQ_CLEAR 0x068 +#define HTCPEN_PORT_INIT 0x06c +#define HTCPEN_PORT_INDEX 0x0250 +#define HTCPEN_PORT_DATA 0x0251 +#define HTCPEN_IRQ 3 + +#define X_INDEX 3 +#define Y_INDEX 5 +#define LSB_XY_INDEX 0xc +#define X_AXIS_MAX 2040 +#define Y_AXIS_MAX 2040 +#define DEVICE_ENABLE 0xa2 + +static int inverse_x; +module_param (inverse_x, bool,0644 ); +MODULE_PARM_DESC (inverse_x,"If set X axis is inversed" ); +static int inverse_y; +module_param (inverse_y, bool,0644 ); +MODULE_PARM_DESC (inverse_y,"If set Y axis is inversed" ); + +static void poll_htcpen (struct input_dev *htcpen_dev) +{ +unsigned short x, y, xy; +unsigned short touch; + +/* 0=press ; 1=release */ +outb_p (0xb ,HTCPEN_PORT_INDEX ); + touch =inb_p (HTCPEN_PORT_DATA ); +if (touch) + touch =0 ; +else + touch =1 ; + +input_report_key (htcpen_dev,BTN_TOUCH , touch); + +/* only update X/Y when screen is being touched */ +if (touch) { +outb_p (X_INDEX ,HTCPEN_PORT_INDEX ); + x =inb_p (HTCPEN_PORT_DATA ); + +outb_p (Y_INDEX ,HTCPEN_PORT_INDEX ); + y =inb_p (HTCPEN_PORT_DATA ); + +outb_p (LSB_XY_INDEX ,HTCPEN_PORT_INDEX ); + xy =inb_p (HTCPEN_PORT_DATA ); + +/* get high resolution value of X and Y using LSB */ + x =X_AXIS_MAX - ((x *8 ) + ((xy >>4 ) &0xf )); + y = (y *8 ) + (xy &0xf ); +if (inverse_x) + x =X_AXIS_MAX - x; +if (inverse_y) + y =Y_AXIS_MAX - y; + +input_report_abs (htcpen_dev,ABS_X , x); +input_report_abs (htcpen_dev,ABS_Y , y); + } + +input_sync (htcpen_dev); + +inb_p (HTCPEN_PORT_IRQ_CLEAR ); +} + +static irqreturn_t htcpen_interrupt (int irq,void *handle) +{ +struct input_dev *htcpen_dev = handle; + +poll_htcpen (htcpen_dev); +return IRQ_HANDLED ; +} + +static int __devinit htcpen_isa_probe (struct device *dev,unsigned int id) +{ +int err; +struct input_dev *htcpen_dev; + +printk (KERN_INFO "htcpen: %s\n" ,DRIVER_DESC ); + +inb_p (HTCPEN_PORT_IRQ_CLEAR ); + + htcpen_dev =input_allocate_device (); +if (!htcpen_dev) { +printk (KERN_ERR "htcpen: can't allocate device\n" ); + err = -ENOMEM ; + goto input_alloc_failed; + } + + htcpen_dev->name ="HTC Pen TouchScreen" ; + htcpen_dev->id.bustype =BUS_ISA ; + htcpen_dev->id.vendor =0 ; + htcpen_dev->id.product =0 ; + htcpen_dev->id.version =0 ; + +input_set_abs_params (htcpen_dev,ABS_X ,0 ,X_AXIS_MAX ,0 ,0 ); +input_set_abs_params (htcpen_dev,ABS_Y ,0 ,Y_AXIS_MAX ,0 ,0 ); + + htcpen_dev->evbit[0 ] =BIT_MASK (EV_ABS ) |BIT_MASK (EV_KEY ); + htcpen_dev->absbit[0 ] =BIT_MASK (ABS_X ) |BIT_MASK (ABS_Y ); + htcpen_dev->keybit[BIT_WORD (BTN_TOUCH )] =BIT_MASK (BTN_TOUCH ); + + err =request_irq (HTCPEN_IRQ , htcpen_interrupt,0 ,"htcpen" , + htcpen_dev); +if (err) { +printk (KERN_ERR "htcpen: irq busy\n" ); + err = -EBUSY ; + goto request_irq_failed; + } + + err =input_register_device (htcpen_dev); +if (err) + goto input_register_failed; + +outb_p (DEVICE_ENABLE ,HTCPEN_PORT_INIT ); + +dev_set_drvdata (dev, htcpen_dev); +return 0 ; + + input_register_failed: +free_irq (HTCPEN_IRQ , htcpen_dev); + request_irq_failed: +input_free_device (htcpen_dev); + input_alloc_failed: +return err; +} + +static int __devinit htcpen_isa_match (struct device *dev,unsigned int id) +{ +unsigned short val1, val2; + +/* device detection */ +outb_p (0x8 ,HTCPEN_PORT_INIT ); + val1 =inb_p (HTCPEN_PORT_INIT ); + val2 =inb_p (HTCPEN_PORT_IRQ_CLEAR ); +if ((val1 >0xa ) || (val2 !=0x55 )) { +printk (KERN_ERR "htcpen: no such device (%x|%x)\n" , val1, val2); +return 0 ; + } +return 1 ; +} + +static int __devexit htcpen_isa_remove(struct device *dev, unsigned int id) +{ +input_unregister_device (dev_get_drvdata (dev)); +free_irq (HTCPEN_IRQ ,dev_get_drvdata (dev)); +input_free_device (dev_get_drvdata (dev)); +dev_set_drvdata (dev,NULL ); +printk (KERN_INFO "htcpen: module removed\n" ); +return 0 ; +} + +static struct isa_driver htcpen_isa_driver = { + .match = htcpen_isa_match, + .probe = htcpen_isa_probe, + .remove =__devexit_p (htcpen_isa_remove), + .driver = { + .owner =THIS_MODULE , + .name ="htcpen" , + } +}; + +static int __init htcpen_isa_init (void ) +{ +return isa_register_driver (&htcpen_isa_driver,1 ); +} + +static void __exit htcpen_isa_exit(void) +{ +isa_unregister_driver (&htcpen_isa_driver); +} + +module_init (htcpen_isa_init); +module_exit (htcpen_isa_exit);
drivers/input/touchscreen/Kconfig +12 -0
@@ -134,6 +134,18 @@ config TOUCHSCREEN_HP7XX To compile this driver as a module, choose M here: the module will be called jornada720_ts. +config TOUCHSCREEN_HTCPEN + tristate "HTC Shift X9500 touchscreen" + depends on ISA + help + Say Y here if you have an HTC Shift UMPC also known as HTC X9500 + Clio / Shangrila and want to support the built-in touchscreen. + + If unsure, say N. + + To compile this driver as a module, choose M here: the + module will be called htcpen. + config TOUCHSCREEN_PENMOUNT tristate "Penmount serial touchscreen" select SERIO
drivers/input/touchscreen/Makefile +1 -0
@@ -14,6 +14,7 @@ obj-$(CONFIG_TOUCHSCREEN_MTOUCH) += mtou obj-$(CONFIG_TOUCHSCREEN_MK712) += mk712.o obj-$(CONFIG_TOUCHSCREEN_HP600) += hp680_ts_input.o obj-$(CONFIG_TOUCHSCREEN_HP7XX) += jornada720_ts.o +obj-$(CONFIG_TOUCHSCREEN_HTCPEN) += htcpen.o obj-$(CONFIG_TOUCHSCREEN_USB_COMPOSITE) += usbtouchscreen.o obj-$(CONFIG_TOUCHSCREEN_PENMOUNT) += penmount.o obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o
MAINTAINERS +6 -0
@@ -1875,6 +1875,12 @@ M: [email protected] W: http://artax.karlin.mff.cuni.cz/~mikulas/vyplody/hpfs/index-e.cgi S: Maintained +HTCPEN TOUCHSCREEN DRIVER +P: Pau Oliva Fora +M: [email protected] +L: [email protected] +S: Maintained + HUGETLB FILESYSTEM P: William Irwin M: [email protected]
Dmitry Torokhov
maintainerHi Pau,
Quoted 6 lines · Pau Oliva Fora
From: Pau Oliva Fora <[email protected]>
The patch below adds support for HTC Shift UMPC touchscreen.
Signed-off-by Pau Oliva Fora <[email protected]>
Thank you for the patch, overall looks very good, some comments below:
drivers/input/touchscreen/htcpen.c line 28
Quoted 4 lines
drivers/input/touchscreen/htcpen.c +4
-0+ +#define DRIVER_VERSION "0.8" +#define DRIVER_DESC "HTC Shift touchscreen driver v" DRIVER_VERSION +
I'd lose the driver version, kernel version should be enough for tracking.
Quoted 14 lines
drivers/input/touchscreen/htcpen.c +14
-0+MODULE_AUTHOR ("Pau Oliva Fora <[email protected]>" ); +MODULE_DESCRIPTION (DRIVER_DESC ); +MODULE_VERSION (DRIVER_VERSION ); +MODULE_LICENSE ("GPL" ); + +#define HTCPEN_PORT_IRQ_CLEAR 0x068 +#define HTCPEN_PORT_INIT 0x06c +#define HTCPEN_PORT_INDEX 0x0250 +#define HTCPEN_PORT_DATA 0x0251 +#define HTCPEN_IRQ 3 + +#define X_INDEX 3 +#define Y_INDEX 5 +#define LSB_XY_INDEX 0xc
drivers/input/touchscreen/htcpen.c line 52
Quoted 10 lines
drivers/input/touchscreen/htcpen.c +10
-0+#define X_AXIS_MAX 2040 +#define Y_AXIS_MAX 2040 +#define DEVICE_ENABLE 0xa2 + +static int inverse_x; +module_param (inverse_x, bool,0644 ); +MODULE_PARM_DESC (inverse_x,"If set X axis is inversed" ); +static int inverse_y; +module_param (inverse_y, bool,0644 ); +MODULE_PARM_DESC (inverse_y,"If set Y axis is inversed" );
For some reason 'inverted' sounds better to my ear. Anyone with native English has any opinion here?
Quoted 29 lines
drivers/input/touchscreen/htcpen.c +29
-0+ +static void poll_htcpen (struct input_dev *htcpen_dev) +{ +unsigned short x, y, xy; +unsigned short touch; + +/* 0=press ; 1=release */ +outb_p (0xb ,HTCPEN_PORT_INDEX ); + touch =inb_p (HTCPEN_PORT_DATA ); +if (touch) + touch =0 ; +else + touch =1 ; + +input_report_key (htcpen_dev,BTN_TOUCH , touch); + +/* only update X/Y when screen is being touched */ +if (touch) { +outb_p (X_INDEX ,HTCPEN_PORT_INDEX ); + x =inb_p (HTCPEN_PORT_DATA ); + +outb_p (Y_INDEX ,HTCPEN_PORT_INDEX ); + y =inb_p (HTCPEN_PORT_DATA ); + +outb_p (LSB_XY_INDEX ,HTCPEN_PORT_INDEX ); + xy =inb_p (HTCPEN_PORT_DATA ); + +/* get high resolution value of X and Y using LSB */ + x =X_AXIS_MAX - ((x *8 ) + ((xy >>4 ) &0xf ));
drivers/input/touchscreen/htcpen.c line 91
Quoted 10 lines
drivers/input/touchscreen/htcpen.c +10
-0+ y = (y *8 ) + (xy &0xf ); +if (inverse_x) + x =X_AXIS_MAX - x; +if (inverse_y) + y =Y_AXIS_MAX - y; + +input_report_abs (htcpen_dev,ABS_X , x); +input_report_abs (htcpen_dev,ABS_Y , y); + } +
Maybe do:
if (inb_p(HTCPEN_PORT_DATA)) {
input_report_key(htcpen_dev, BTN_TOUCH, 0);
} else {
...
input_report_key(htcpen_dev, BTN_TOUCH, 1);
input_report_abs(htcpen_dev, ABS_X, x);
input_report_abs(htcpen_dev, ABS_Y, y);
}drivers/input/touchscreen/htcpen.c line 103
Quoted 12 lines
drivers/input/touchscreen/htcpen.c +12
-0+input_sync (htcpen_dev); + +inb_p (HTCPEN_PORT_IRQ_CLEAR ); +} + +static irqreturn_t htcpen_interrupt (int irq,void *handle) +{ +struct input_dev *htcpen_dev = handle; + +poll_htcpen (htcpen_dev); +return IRQ_HANDLED ; +}
Why don't you put the poll straight into IRQ handler body?
drivers/input/touchscreen/htcpen.c line 110
Quoted 7 lines
drivers/input/touchscreen/htcpen.c +7
-0+ +static int __devinit htcpen_isa_probe (struct device *dev,unsigned int id) +{ +int err; +struct input_dev *htcpen_dev; + +printk (KERN_INFO "htcpen: %s\n" ,DRIVER_DESC );
If you want the driver to print identification string it should go into the module init function, but I'd rather just keep it silent. If it finds the device input core will print nice message about the device.
Quoted 5 lines
drivers/input/touchscreen/htcpen.c +5
-0+ +inb_p (HTCPEN_PORT_IRQ_CLEAR ); + + htcpen_dev =input_allocate_device (); +if (!htcpen_dev) {
drivers/input/touchscreen/htcpen.c line 125
Quoted 10 lines
drivers/input/touchscreen/htcpen.c +10
-0+printk (KERN_ERR "htcpen: can't allocate device\n" ); + err = -ENOMEM ; + goto input_alloc_failed; + } + + htcpen_dev->name ="HTC Pen TouchScreen" ; + htcpen_dev->id.bustype =BUS_ISA ; + htcpen_dev->id.vendor =0 ; + htcpen_dev->id.product =0 ; + htcpen_dev->id.version =0 ;
input_allocate_device() zeroes the memory so initialize just what is needed.
drivers/input/touchscreen/htcpen.c line 131
Quoted 7 lines
drivers/input/touchscreen/htcpen.c +6
-0+ +input_set_abs_params (htcpen_dev,ABS_X ,0 ,X_AXIS_MAX ,0 ,0 ); +input_set_abs_params (htcpen_dev,ABS_Y ,0 ,Y_AXIS_MAX ,0 ,0 ); + + htcpen_dev->evbit[0 ] =BIT_MASK (EV_ABS ) |BIT_MASK (EV_KEY ); + htcpen_dev->absbit[0 ] =BIT_MASK (ABS_X ) |BIT_MASK (ABS_Y );
Not needed, input_set_abs_params does this for you.
drivers/input/touchscreen/htcpen.c line 138
Quoted 7 lines
drivers/input/touchscreen/htcpen.c +7
-0+ htcpen_dev->keybit[BIT_WORD (BTN_TOUCH )] =BIT_MASK (BTN_TOUCH ); + + err =request_irq (HTCPEN_IRQ , htcpen_interrupt,0 ,"htcpen" , + htcpen_dev); +if (err) { +printk (KERN_ERR "htcpen: irq busy\n" ); + err = -EBUSY ;
Just report the error returned by request_irq, no need to override it.
Quoted 20 lines
drivers/input/touchscreen/htcpen.c +20
-0+ goto request_irq_failed; + } + + err =input_register_device (htcpen_dev); +if (err) + goto input_register_failed; + +outb_p (DEVICE_ENABLE ,HTCPEN_PORT_INIT ); + +dev_set_drvdata (dev, htcpen_dev); +return 0 ; + + input_register_failed: +free_irq (HTCPEN_IRQ , htcpen_dev); + request_irq_failed: +input_free_device (htcpen_dev); + input_alloc_failed: +return err; +} +
drivers/input/touchscreen/htcpen.c line 168
Quoted 10 lines
drivers/input/touchscreen/htcpen.c +10
-0+static int __devinit htcpen_isa_match (struct device *dev,unsigned int id) +{ +unsigned short val1, val2; + +/* device detection */ +outb_p (0x8 ,HTCPEN_PORT_INIT ); + val1 =inb_p (HTCPEN_PORT_INIT ); + val2 =inb_p (HTCPEN_PORT_IRQ_CLEAR ); +if ((val1 >0xa ) || (val2 !=0x55 )) { +printk (KERN_ERR "htcpen: no such device (%x|%x)\n" , val1, val2);
KERN_DEBUG at most, I'd simply remove. Not having a device is not an error.
drivers/input/touchscreen/htcpen.c line 176
Quoted 8 lines
drivers/input/touchscreen/htcpen.c +8
-0+return 0 ; + } +return 1 ; +} + +static int __devexit htcpen_isa_remove(struct device *dev, unsigned int id) +{ +input_unregister_device (dev_get_drvdata (dev));
At this point the structure may be freed, but interrupts are still running and you haven't stopped the device. I would recommend implementing ->open() and ->close methonds for the input_dev and start and stop the device from there (I thought one of your patches did just that).
drivers/input/touchscreen/htcpen.c line 178
Quoted 2 lines
drivers/input/touchscreen/htcpen.c +2
-0+free_irq (HTCPEN_IRQ ,dev_get_drvdata (dev)); +input_free_device (dev_get_drvdata (dev));
Never call input_free_device after input_unregister_device. The input_dev structure is refcounted and will free itself one last user drops its reference. input_free_device may cause attempt to free already freed memory.
drivers/input/touchscreen/htcpen.c line 180
Quoted 2 lines
drivers/input/touchscreen/htcpen.c +2
-0+dev_set_drvdata (dev,NULL ); +printk (KERN_INFO "htcpen: module removed\n" );
Kill this too.
Quoted 23 lines
drivers/input/touchscreen/htcpen.c +23
-0+return 0 ; +} + +static struct isa_driver htcpen_isa_driver = { + .match = htcpen_isa_match, + .probe = htcpen_isa_probe, + .remove =__devexit_p (htcpen_isa_remove), + .driver = { + .owner =THIS_MODULE , + .name ="htcpen" , + } +}; + +static int __init htcpen_isa_init (void ) +{ +return isa_register_driver (&htcpen_isa_driver,1 ); +} + +static void __exit htcpen_isa_exit(void) +{ +isa_unregister_driver (&htcpen_isa_driver); +} +
Signature · 1 line
Dmitry
From: Pau Oliva Fora <[email protected]>
The patch below adds support for HTC Shift UMPC touchscreen.
---
Patch against linux-2.6.25.4, should apply clean on other versions too. Includes all the suggestions from Sam Ravnborg, Pekka Enberg, Marcin Slusarz and Dmitry Torokhov. Thank you all for your help.
drivers/input/touchscreen/htcpen.c +196 -0
@@ -0,0 +1,196 @@ +/* +* HTC Shift touchscreen driver +* +* Copyright (C) 2008 Pau Oliva Fora <[email protected]> +* +* Thanks to: +* Heikki Linnakangas - Penmount LPC touchscreen driver +* Wacom / Ping Cheng - Help on linuxwacom-devel +* Esteve Espuna - Ideas, tips, moral support :) +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2 as published +* by the Free Software Foundation. +*/ + +#include <linux/errno.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/input.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/init.h> +#include <linux/irq.h> +#include <linux/isa.h> + +MODULE_AUTHOR ("Pau Oliva Fora <[email protected]>" ); +MODULE_DESCRIPTION ("HTC Shift touchscreen driver" ); +MODULE_LICENSE ("GPL" ); + +#define HTCPEN_PORT_IRQ_CLEAR 0x068 +#define HTCPEN_PORT_INIT 0x06c +#define HTCPEN_PORT_INDEX 0x0250 +#define HTCPEN_PORT_DATA 0x0251 +#define HTCPEN_IRQ 3 + +#define X_INDEX 3 +#define Y_INDEX 5 +#define TOUCH_INDEX 0xb +#define LSB_XY_INDEX 0xc +#define X_AXIS_MAX 2040 +#define Y_AXIS_MAX 2040 +#define DEVICE_ENABLE 0xa2 + +static int invert_x; +module_param (invert_x, bool,0644 ); +MODULE_PARM_DESC (invert_x,"If set, X axis is inverted" ); +static int invert_y; +module_param (invert_y, bool,0644 ); +MODULE_PARM_DESC (invert_y,"If set, Y axis is inverted" ); + +static irqreturn_t htcpen_interrupt (int irq,void *handle) +{ +struct input_dev *htcpen_dev = handle; +unsigned short x, y, xy; + +/* 0=press ; 1=release */ +outb_p (TOUCH_INDEX ,HTCPEN_PORT_INDEX ); + +/* only update X/Y when screen is being touched */ +if (inb_p (HTCPEN_PORT_DATA )) { +input_report_key (htcpen_dev,BTN_TOUCH ,0 ); + }else { +outb_p (X_INDEX ,HTCPEN_PORT_INDEX ); + x =inb_p (HTCPEN_PORT_DATA ); + +outb_p (Y_INDEX ,HTCPEN_PORT_INDEX ); + y =inb_p (HTCPEN_PORT_DATA ); + +outb_p (LSB_XY_INDEX ,HTCPEN_PORT_INDEX ); + xy =inb_p (HTCPEN_PORT_DATA ); + +/* get high resolution value of X and Y using LSB */ + x =X_AXIS_MAX - ((x *8 ) + ((xy >>4 ) &0xf )); + y = (y *8 ) + (xy &0xf ); +if (invert_x) + x =X_AXIS_MAX - x; +if (invert_y) + y =Y_AXIS_MAX - y; + +input_report_key (htcpen_dev,BTN_TOUCH ,1 ); +input_report_abs (htcpen_dev,ABS_X , x); +input_report_abs (htcpen_dev,ABS_Y , y); + } + +input_sync (htcpen_dev); + +inb_p (HTCPEN_PORT_IRQ_CLEAR ); + +return IRQ_HANDLED ; +} + +static int htcpen_open (struct input_dev *dev) +{ +outb_p (DEVICE_ENABLE ,HTCPEN_PORT_INIT ); +return 0 ; +} + +static void htcpen_close (struct input_dev *dev) +{ +free_irq (HTCPEN_IRQ , dev); +} + +static int __devinit htcpen_isa_probe (struct device *dev,unsigned int id) +{ +int err; +struct input_dev *htcpen_dev; + +printk (KERN_ERR "principi del prove\n" ); + +inb_p (HTCPEN_PORT_IRQ_CLEAR ); + + htcpen_dev =input_allocate_device (); +if (!htcpen_dev) { +printk (KERN_ERR "htcpen: can't allocate device\n" ); + err = -ENOMEM ; + goto input_alloc_failed; + } + + htcpen_dev->name ="HTC Pen TouchScreen" ; + htcpen_dev->id.bustype =BUS_ISA ; + +input_set_abs_params (htcpen_dev,ABS_X ,0 ,X_AXIS_MAX ,0 ,0 ); +input_set_abs_params (htcpen_dev,ABS_Y ,0 ,Y_AXIS_MAX ,0 ,0 ); + + htcpen_dev->evbit[0 ] =BIT_MASK (EV_ABS ) |BIT_MASK (EV_KEY ); + htcpen_dev->keybit[BIT_WORD (BTN_TOUCH )] =BIT_MASK (BTN_TOUCH ); + htcpen_dev->open = htcpen_open; + htcpen_dev->close = htcpen_close; + + err =request_irq (HTCPEN_IRQ , htcpen_interrupt,0 ,"htcpen" , + htcpen_dev); +if (err) { +printk (KERN_ERR "htcpen: irq busy\n" ); + goto request_irq_failed; + } + + err =input_register_device (htcpen_dev); +if (err) + goto input_register_failed; + +dev_set_drvdata (dev, htcpen_dev); +return 0 ; + + input_register_failed: +free_irq (HTCPEN_IRQ , htcpen_dev); + request_irq_failed: +input_free_device (htcpen_dev); + input_alloc_failed: +return err; +} + +static int __devinit htcpen_isa_match (struct device *dev,unsigned int id) +{ +unsigned short val1, val2; + +/* device detection */ +outb_p (0x8 ,HTCPEN_PORT_INIT ); + val1 =inb_p (HTCPEN_PORT_INIT ); + val2 =inb_p (HTCPEN_PORT_IRQ_CLEAR ); +if ((val1 >0xc ) || (val2 !=0x55 )) { +printk (KERN_DEBUG "htcpen: no such device (%x|%x)\n" , + val1, val2); +return 0 ; + } +return 1 ; +} + +static int __devexit htcpen_isa_remove(struct device *dev, unsigned int id) +{ +input_unregister_device (dev_get_drvdata (dev)); +dev_set_drvdata (dev,NULL ); +return 0 ; +} + +static struct isa_driver htcpen_isa_driver = { + .match = htcpen_isa_match, + .probe = htcpen_isa_probe, + .remove =__devexit_p (htcpen_isa_remove), + .driver = { + .owner =THIS_MODULE , + .name ="htcpen" , + } +}; + +static int __init htcpen_isa_init (void ) +{ +return isa_register_driver (&htcpen_isa_driver,1 ); +} + +static void __exit htcpen_isa_exit(void) +{ +isa_unregister_driver (&htcpen_isa_driver); +} + +module_init (htcpen_isa_init); +module_exit (htcpen_isa_exit);
drivers/input/touchscreen/Kconfig +12 -0
@@ -134,6 +134,18 @@ config TOUCHSCREEN_HP7XX To compile this driver as a module, choose M here: the module will be called jornada720_ts. +config TOUCHSCREEN_HTCPEN + tristate "HTC Shift X9500 touchscreen" + depends on ISA + help + Say Y here if you have an HTC Shift UMPC also known as HTC X9500 + Clio / Shangrila and want to support the built-in touchscreen. + + If unsure, say N. + + To compile this driver as a module, choose M here: the + module will be called htcpen. + config TOUCHSCREEN_PENMOUNT tristate "Penmount serial touchscreen" select SERIO
drivers/input/touchscreen/Makefile +1 -0
@@ -14,6 +14,7 @@ obj-$(CONFIG_TOUCHSCREEN_MTOUCH) += mtou obj-$(CONFIG_TOUCHSCREEN_MK712) += mk712.o obj-$(CONFIG_TOUCHSCREEN_HP600) += hp680_ts_input.o obj-$(CONFIG_TOUCHSCREEN_HP7XX) += jornada720_ts.o +obj-$(CONFIG_TOUCHSCREEN_HTCPEN) += htcpen.o obj-$(CONFIG_TOUCHSCREEN_USB_COMPOSITE) += usbtouchscreen.o obj-$(CONFIG_TOUCHSCREEN_PENMOUNT) += penmount.o obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o
MAINTAINERS +6 -0
@@ -1875,6 +1875,12 @@ M: [email protected] W: http://artax.karlin.mff.cuni.cz/~mikulas/vyplody/hpfs/index-e.cgi S: Maintained +HTCPEN TOUCHSCREEN DRIVER +P: Pau Oliva Fora +M: [email protected] +L: [email protected] +S: Maintained + HUGETLB FILESYSTEM P: William Irwin M: [email protected]
Dmitry Torokhov
maintainerdrivers/input/touchscreen/htcpen.c line 102
Quoted 12 lines · Pau Oliva Fora
drivers/input/touchscreen/htcpen.c +12
-0+ +static int htcpen_open (struct input_dev *dev) +{ +outb_p (DEVICE_ENABLE ,HTCPEN_PORT_INIT ); +return 0 ; +} + +static void htcpen_close (struct input_dev *dev) +{ +free_irq (HTCPEN_IRQ , dev); +} +
No, this will not work.. next time you open the device you won't have IRQ anymore. You need the opposite of outb_p(DEVICE_ENABLE, HTCPEN_PORT_INIT); here.
Signature · 1 line
Dmitry
Quoted 18 lines · Dmitry Torokhov
drivers/input/touchscreen/htcpen.c line 102
Quoted 12 lines · Pau Oliva Fora
drivers/input/touchscreen/htcpen.c +12
-0+ +static int htcpen_open (struct input_dev *dev) +{ +outb_p (DEVICE_ENABLE ,HTCPEN_PORT_INIT ); +return 0 ; +} + +static void htcpen_close (struct input_dev *dev) +{ +free_irq (HTCPEN_IRQ , dev); +} +No, this will not work.. next time you open the device you won't have IRQ anymore. You need the opposite of
outb_p(DEVICE_ENABLE, HTCPEN_PORT_INIT); here.
It is actually working; it also works after suspend/resume without any issues.
I currently do not know a safe way of disabling the device, as HTC did not offer any specifications or datasheet when I requested, so everything in the driver has been reverse engineered.
Let me know if you think it's ok to leave it as is, otherwise I'll try to find the proper way to disable the device (it should not be much different than the way of enabling it).
Best Regards,
Pau Oliva
Dmitry Torokhov
maintainerQuoted 20 lines · Pau Oliva Fora
Quoted 18 lines · Dmitry Torokhov
drivers/input/touchscreen/htcpen.c line 102
Quoted 12 lines · Pau Oliva Fora
drivers/input/touchscreen/htcpen.c +12
-0+ +static int htcpen_open (struct input_dev *dev) +{ +outb_p (DEVICE_ENABLE ,HTCPEN_PORT_INIT ); +return 0 ; +} + +static void htcpen_close (struct input_dev *dev) +{ +free_irq (HTCPEN_IRQ , dev); +} +No, this will not work.. next time you open the device you won't have IRQ anymore. You need the opposite of
outb_p(DEVICE_ENABLE, HTCPEN_PORT_INIT); here.
Quoted 3 lines
It is actually working; it also works after suspend/resume without any issues.
You need to close the device. Making evdev a module and unloading it should do the trick (you don't use tsdev, do you?).
Quoted 7 lines
I currently do not know a safe way of disabling the device, as HTC did not offer any specifications or datasheet when I requested, so everything in the driver has been reverse engineered.
Let me know if you think it's ok to leave it as is, otherwise I'll try to find the proper way to disable the device (it should not be much different than the way of enabling it).
If you can't find the way to disable device then you need to revert to the old way, with enabling it in _probe() and freein irq in _remove(), you just need to make sure that you free_irq() first and then call input_unregister_device().
Also, like Andrey said, we might consider using DMI table so we dont poke IO ports on random boxes. Oh, and one more thing, you need to reserve the IO ports your driver is using with request_region.
Signature · 1 line
Dmitry
Quoted 19 lines · Dmitry Torokhov
Quoted 18 lines · Pau Oliva Fora
Quoted 17 lines · Dmitry Torokhov
Review
Quoted 12 lines · Pau Oliva Fora
(quoted diff) +12
-0+ +static int htcpen_open(struct input_dev *dev) +{ + outb_p(DEVICE_ENABLE, HTCPEN_PORT_INIT); + return 0; +} + +static void htcpen_close(struct input_dev *dev) +{ + free_irq(HTCPEN_IRQ, dev); +} +No, this will not work.. next time you open the device you won't have IRQ anymore. You need the opposite of
outb_p(DEVICE_ENABLE, HTCPEN_PORT_INIT); here.
Quoted 6 lines
Quoted 3 lines
It is actually working; it also works after suspend/resume without any issues.
You need to close the device. Making evdev a module and unloading it should do the trick (you don't use tsdev, do you?).
I use evdev.
Quoted 8 lines
Quoted 3 lines
Let me know if you think it's ok to leave it as is, otherwise I'll try to find the proper way to disable the device (it should not be much different than the way of enabling it).
If you can't find the way to disable device then you need to revert to the old way, with enabling it in
_probe()and freein irq in_remove(), you just need to make sure that youfree_irq()first and then callinput_unregister_device().
Finding a way to disable it was easy :-)
just need to write 0xa3 to 0x6c.
Quoted 2 lines
Also, like Andrey said, we might consider using DMI table so we dont poke IO ports on random boxes.
Thanks Andrey for the suggestion of using DMI table, see the patch below. Should I keep the old device detection using IO port stuff or just dmi_check_system() should be fine?
Quoted 2 lines
Oh, and one more thing, you need to
reserve the IO ports your driver is using withrequest_region.
Thanks, I implemented this too in the patch below, but I have a problem:
I can successfully reserve 0x250-0x251, but 0x68 and 0x6c are already reserved by the keyboard which takes range 0x60-0x6f according to /proc/ioports. I left the code for those ports commented out. What should I do in that case? I am a kernel newbie :)
drivers/input/touchscreen/htcpen.c +246 -0
@@ -0,0 +1,246 @@ +/* +* HTC Shift touchscreen driver +* +* Copyright (C) 2008 Pau Oliva Fora <[email protected]> +* +* Thanks to: +* Heikki Linnakangas - Penmount LPC touchscreen driver +* Wacom / Ping Cheng - Help on linuxwacom-devel +* Esteve Espuna - Ideas, tips, moral support :) +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2 as published +* by the Free Software Foundation. +*/ + +#include <linux/errno.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/input.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/init.h> +#include <linux/irq.h> +#include <linux/isa.h> +#include <linux/ioport.h> +#include <linux/dmi.h> + +MODULE_AUTHOR ("Pau Oliva Fora <[email protected]>" ); +MODULE_DESCRIPTION ("HTC Shift touchscreen driver" ); +MODULE_LICENSE ("GPL" ); + +#define HTCPEN_PORT_IRQ_CLEAR 0x068 +#define HTCPEN_PORT_INIT 0x06c +#define HTCPEN_PORT_INDEX 0x0250 +#define HTCPEN_PORT_DATA 0x0251 +#define HTCPEN_IRQ 3 + +#define X_INDEX 3 +#define Y_INDEX 5 +#define TOUCH_INDEX 0xb +#define LSB_XY_INDEX 0xc +#define X_AXIS_MAX 2040 +#define Y_AXIS_MAX 2040 +#define DEVICE_ENABLE 0xa2 +#define DEVICE_DISABLE 0xa3 + +static int invert_x; +module_param (invert_x, bool,0644 ); +MODULE_PARM_DESC (invert_x,"If set, X axis is inverted" ); +static int invert_y; +module_param (invert_y, bool,0644 ); +MODULE_PARM_DESC (invert_y,"If set, Y axis is inverted" ); + +static const struct dmi_system_id htcshift_dmi_table[] = { + { + .ident ="Shift" , + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"High Tech Computer Corp" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Shift" ), + }, + }, + { } +}; + +static irqreturn_t htcpen_interrupt (int irq,void *handle) +{ +struct input_dev *htcpen_dev = handle; +unsigned short x, y, xy; + +/* 0=press ; 1=release */ +outb_p (TOUCH_INDEX ,HTCPEN_PORT_INDEX ); + +/* only update X/Y when screen is being touched */ +if (inb_p (HTCPEN_PORT_DATA )) { +input_report_key (htcpen_dev,BTN_TOUCH ,0 ); + }else { +outb_p (X_INDEX ,HTCPEN_PORT_INDEX ); + x =inb_p (HTCPEN_PORT_DATA ); + +outb_p (Y_INDEX ,HTCPEN_PORT_INDEX ); + y =inb_p (HTCPEN_PORT_DATA ); + +outb_p (LSB_XY_INDEX ,HTCPEN_PORT_INDEX ); + xy =inb_p (HTCPEN_PORT_DATA ); + +/* get high resolution value of X and Y using LSB */ + x =X_AXIS_MAX - ((x *8 ) + ((xy >>4 ) &0xf )); + y = (y *8 ) + (xy &0xf ); +if (invert_x) + x =X_AXIS_MAX - x; +if (invert_y) + y =Y_AXIS_MAX - y; + +input_report_key (htcpen_dev,BTN_TOUCH ,1 ); +input_report_abs (htcpen_dev,ABS_X , x); +input_report_abs (htcpen_dev,ABS_Y , y); + } + +input_sync (htcpen_dev); + +inb_p (HTCPEN_PORT_IRQ_CLEAR ); + +return IRQ_HANDLED ; +} + +static int htcpen_open (struct input_dev *dev) +{ +outb_p (DEVICE_ENABLE ,HTCPEN_PORT_INIT ); +return 0 ; +} + +static void htcpen_close (struct input_dev *dev) +{ +free_irq (HTCPEN_IRQ , dev); +outb_p (DEVICE_DISABLE ,HTCPEN_PORT_INIT ); +} + +static int __devinit htcpen_isa_probe (struct device *dev,unsigned int id) +{ +int err; +struct input_dev *htcpen_dev; + +inb_p (HTCPEN_PORT_IRQ_CLEAR ); + + htcpen_dev =input_allocate_device (); +if (!htcpen_dev) { +printk (KERN_ERR "htcpen: can't allocate device\n" ); + err = -ENOMEM ; + goto input_alloc_failed; + } + + htcpen_dev->name ="HTC Pen TouchScreen" ; + htcpen_dev->id.bustype =BUS_ISA ; + +input_set_abs_params (htcpen_dev,ABS_X ,0 ,X_AXIS_MAX ,0 ,0 ); +input_set_abs_params (htcpen_dev,ABS_Y ,0 ,Y_AXIS_MAX ,0 ,0 ); + + htcpen_dev->evbit[0 ] =BIT_MASK (EV_ABS ) |BIT_MASK (EV_KEY ); + htcpen_dev->keybit[BIT_WORD (BTN_TOUCH )] =BIT_MASK (BTN_TOUCH ); + htcpen_dev->open = htcpen_open; + htcpen_dev->close = htcpen_close; + + err =request_irq (HTCPEN_IRQ , htcpen_interrupt,0 ,"htcpen" , + htcpen_dev); +if (err) { +printk (KERN_ERR "htcpen: irq busy\n" ); + err = -ENODEV ; + goto request_irq_failed; + } + +/* +if (!request_region(HTCPEN_PORT_IRQ_CLEAR, 1, "htcpen")) { +printk(KERN_WARNING "htcpen: unable to get IO region1\n"); +err = -ENODEV; +goto request_region1_failed; +} + +if (!request_region(HTCPEN_PORT_INIT, 1, "htcpen")) { +printk(KERN_WARNING "htcpen: unable to get IO region2\n"); +err = -ENODEV; +goto request_region2_failed; +} +*/ + +if (!request_region (HTCPEN_PORT_INDEX ,2 ,"htcpen" )) { +printk (KERN_WARNING "htcpen: unable to get IO region3\n" ); + err = -ENODEV ; + goto request_region3_failed; + } + + err =input_register_device (htcpen_dev); +if (err) + goto input_register_failed; + +dev_set_drvdata (dev, htcpen_dev); +return 0 ; + + input_register_failed: +release_region (HTCPEN_PORT_INDEX ,2 ); + request_region3_failed: +/* +release_region(HTCPEN_PORT_INIT, 1); +request_region2_failed: +release_region(HTCPEN_PORT_IRQ_CLEAR, 1); +request_region1_failed: +*/ +free_irq (HTCPEN_IRQ , htcpen_dev); + request_irq_failed: +input_free_device (htcpen_dev); + input_alloc_failed: +return err; +} + +static int __devinit htcpen_isa_match (struct device *dev,unsigned int id) +{ +unsigned short val1, val2; + +if (!dmi_check_system (htcshift_dmi_table)) +return 0 ; + +/* device detection */ +outb_p (0x8 ,HTCPEN_PORT_INIT ); + val1 =inb_p (HTCPEN_PORT_INIT ); + val2 =inb_p (HTCPEN_PORT_IRQ_CLEAR ); +if ((val1 >0xc ) || (val2 !=0x55 )) { +printk (KERN_DEBUG "htcpen: no such device (%x|%x)\n" , + val1, val2); +return 0 ; + } +return 1 ; +} + +static int __devexit htcpen_isa_remove(struct device *dev, unsigned int id) +{ +input_unregister_device (dev_get_drvdata (dev)); +dev_set_drvdata (dev,NULL ); +/* +release_region(HTCPEN_PORT_IRQ_CLEAR, 1); +release_region(HTCPEN_PORT_INIT, 1); +*/ +release_region (HTCPEN_PORT_INDEX ,2 ); +return 0 ; +} + +static struct isa_driver htcpen_isa_driver = { + .match = htcpen_isa_match, + .probe = htcpen_isa_probe, + .remove =__devexit_p (htcpen_isa_remove), + .driver = { + .owner =THIS_MODULE , + .name ="htcpen" , + } +}; + +static int __init htcpen_isa_init (void ) +{ +return isa_register_driver (&htcpen_isa_driver,1 ); +} + +static void __exit htcpen_isa_exit(void) +{ +isa_unregister_driver (&htcpen_isa_driver); +} + +module_init (htcpen_isa_init); +module_exit (htcpen_isa_exit);
drivers/input/touchscreen/Kconfig +12 -0
@@ -134,6 +134,18 @@ config TOUCHSCREEN_HP7XX To compile this driver as a module, choose M here: the module will be called jornada720_ts. +config TOUCHSCREEN_HTCPEN + tristate "HTC Shift X9500 touchscreen" + depends on ISA + help + Say Y here if you have an HTC Shift UMPC also known as HTC X9500 + Clio / Shangrila and want to support the built-in touchscreen. + + If unsure, say N. + + To compile this driver as a module, choose M here: the + module will be called htcpen. + config TOUCHSCREEN_PENMOUNT tristate "Penmount serial touchscreen" select SERIO
drivers/input/touchscreen/Makefile +1 -0
@@ -14,6 +14,7 @@ obj-$(CONFIG_TOUCHSCREEN_MTOUCH) += mtou obj-$(CONFIG_TOUCHSCREEN_MK712) += mk712.o obj-$(CONFIG_TOUCHSCREEN_HP600) += hp680_ts_input.o obj-$(CONFIG_TOUCHSCREEN_HP7XX) += jornada720_ts.o +obj-$(CONFIG_TOUCHSCREEN_HTCPEN) += htcpen.o obj-$(CONFIG_TOUCHSCREEN_USB_COMPOSITE) += usbtouchscreen.o obj-$(CONFIG_TOUCHSCREEN_PENMOUNT) += penmount.o obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o
MAINTAINERS +6 -0
@@ -1875,6 +1875,12 @@ M: [email protected] W: http://artax.karlin.mff.cuni.cz/~mikulas/vyplody/hpfs/index-e.cgi S: Maintained +HTCPEN TOUCHSCREEN DRIVER +P: Pau Oliva Fora +M: [email protected] +L: [email protected] +S: Maintained + HUGETLB FILESYSTEM P: William Irwin M: [email protected]
From: Pau Oliva Fora <[email protected]>
The patch below adds support for HTC Shift UMPC touchscreen.
---
Patch against linux-2.6.25.4, should apply clean on other versions too.
Quoted 3 lines
I can successfully reserve 0x250-0x251, but
0x68and0x6care already reserved by the keyboard which takes range 0x60-0x6f according to/proc/ioports. I left the code for those ports commented out.
I saw in the git changelog that this was fixed a few days ago:
"Reserve only ports 0x60 and 0x64 for the legacy PS/2 i8042 keyboad controller instead of 0x60-0x6F to allow the openipmi driver to work."
So I reserve all the needed ports now, although this will only work on linux kernel 2.6.26-rc2 or later, where the keyboard io ports reservation is done properly.
drivers/input/touchscreen/htcpen.c +248 -0
@@ -0,0 +1,248 @@ +/* +* HTC Shift touchscreen driver +* +* Copyright (C) 2008 Pau Oliva Fora <[email protected]> +* +* Thanks to: +* Heikki Linnakangas - Penmount LPC touchscreen driver +* Wacom / Ping Cheng - Help on linuxwacom-devel +* Esteve Espuna - Ideas, tips, moral support :) +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2 as published +* by the Free Software Foundation. +*/ + +#include <linux/errno.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/input.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/init.h> +#include <linux/irq.h> +#include <linux/isa.h> +#include <linux/ioport.h> +#include <linux/dmi.h> + +MODULE_AUTHOR ("Pau Oliva Fora <[email protected]>" ); +MODULE_DESCRIPTION ("HTC Shift touchscreen driver" ); +MODULE_LICENSE ("GPL" ); + +#define HTCPEN_PORT_IRQ_CLEAR 0x068 +#define HTCPEN_PORT_INIT 0x06c +#define HTCPEN_PORT_INDEX 0x0250 +#define HTCPEN_PORT_DATA 0x0251 +#define HTCPEN_IRQ 3 + +#define X_INDEX 3 +#define Y_INDEX 5 +#define TOUCH_INDEX 0xb +#define LSB_XY_INDEX 0xc +#define X_AXIS_MAX 2040 +#define Y_AXIS_MAX 2040 +#define DEVICE_ENABLE 0xa2 +#define DEVICE_DISABLE 0xa3 + +static int invert_x; +module_param (invert_x, bool,0644 ); +MODULE_PARM_DESC (invert_x,"If set, X axis is inverted" ); +static int invert_y; +module_param (invert_y, bool,0644 ); +MODULE_PARM_DESC (invert_y,"If set, Y axis is inverted" ); + +static const struct dmi_system_id htcshift_dmi_table[] = { + { + .ident ="Shift" , + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"High Tech Computer Corp" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Shift" ), + }, + }, + { } +}; + +static irqreturn_t htcpen_interrupt (int irq,void *handle) +{ +struct input_dev *htcpen_dev = handle; +unsigned short x, y, xy; + +/* 0=press ; 1=release */ +outb_p (TOUCH_INDEX ,HTCPEN_PORT_INDEX ); + +/* only update X/Y when screen is being touched */ +if (inb_p (HTCPEN_PORT_DATA )) { +input_report_key (htcpen_dev,BTN_TOUCH ,0 ); + }else { +outb_p (X_INDEX ,HTCPEN_PORT_INDEX ); + x =inb_p (HTCPEN_PORT_DATA ); + +outb_p (Y_INDEX ,HTCPEN_PORT_INDEX ); + y =inb_p (HTCPEN_PORT_DATA ); + +outb_p (LSB_XY_INDEX ,HTCPEN_PORT_INDEX ); + xy =inb_p (HTCPEN_PORT_DATA ); + +/* get high resolution value of X and Y using LSB */ + x =X_AXIS_MAX - ((x *8 ) + ((xy >>4 ) &0xf )); + y = (y *8 ) + (xy &0xf ); +if (invert_x) + x =X_AXIS_MAX - x; +if (invert_y) + y =Y_AXIS_MAX - y; + +input_report_key (htcpen_dev,BTN_TOUCH ,1 ); +input_report_abs (htcpen_dev,ABS_X , x); +input_report_abs (htcpen_dev,ABS_Y , y); + } + +input_sync (htcpen_dev); + +inb_p (HTCPEN_PORT_IRQ_CLEAR ); + +return IRQ_HANDLED ; +} + +static int htcpen_open (struct input_dev *dev) +{ +outb_p (DEVICE_ENABLE ,HTCPEN_PORT_INIT ); +return 0 ; +} + +static void htcpen_close (struct input_dev *dev) +{ +free_irq (HTCPEN_IRQ , dev); +outb_p (DEVICE_DISABLE ,HTCPEN_PORT_INIT ); +} + +static int __devinit htcpen_isa_probe (struct device *dev,unsigned int id) +{ +int err; +struct input_dev *htcpen_dev; + +inb_p (HTCPEN_PORT_IRQ_CLEAR ); + + htcpen_dev =input_allocate_device (); +if (!htcpen_dev) { +printk (KERN_ERR "htcpen: can't allocate device\n" ); + err = -ENOMEM ; + goto input_alloc_failed; + } + + htcpen_dev->name ="HTC Pen TouchScreen" ; + htcpen_dev->id.bustype =BUS_ISA ; + +input_set_abs_params (htcpen_dev,ABS_X ,0 ,X_AXIS_MAX ,0 ,0 ); +input_set_abs_params (htcpen_dev,ABS_Y ,0 ,Y_AXIS_MAX ,0 ,0 ); + + htcpen_dev->evbit[0 ] =BIT_MASK (EV_ABS ) |BIT_MASK (EV_KEY ); + htcpen_dev->keybit[BIT_WORD (BTN_TOUCH )] =BIT_MASK (BTN_TOUCH ); + htcpen_dev->open = htcpen_open; + htcpen_dev->close = htcpen_close; + + err =request_irq (HTCPEN_IRQ , htcpen_interrupt,0 ,"htcpen" , + htcpen_dev); +if (err) { +printk (KERN_ERR "htcpen: irq busy\n" ); + err = -ENODEV ; + goto request_irq_failed; + } + +if (!request_region (HTCPEN_PORT_IRQ_CLEAR ,1 ,"htcpen" )) { +printk (KERN_WARNING "htcpen: unable to get IO region 0x%x\n" , +HTCPEN_PORT_IRQ_CLEAR ); + err = -ENODEV ; + goto request_region1_failed; + } + +if (!request_region (HTCPEN_PORT_INIT ,1 ,"htcpen" )) { +printk (KERN_WARNING "htcpen: unable to get IO region 0x%x\n" , +HTCPEN_PORT_INIT ); + err = -ENODEV ; + goto request_region2_failed; + } + +if (!request_region (HTCPEN_PORT_INDEX ,2 ,"htcpen" )) { +printk (KERN_WARNING "htcpen: unable to get IO region 0x%x\n" , +HTCPEN_PORT_INDEX ); + err = -ENODEV ; + goto request_region3_failed; + } + + err =input_register_device (htcpen_dev); +if (err) + goto input_register_failed; + +dev_set_drvdata (dev, htcpen_dev); +return 0 ; + + input_register_failed: +release_region (HTCPEN_PORT_INDEX ,2 ); + request_region3_failed: +release_region (HTCPEN_PORT_INIT ,1 ); + request_region2_failed: +release_region (HTCPEN_PORT_IRQ_CLEAR ,1 ); + request_region1_failed: +free_irq (HTCPEN_IRQ , htcpen_dev); + request_irq_failed: +input_free_device (htcpen_dev); + input_alloc_failed: +return err; +} + +static int __devinit htcpen_isa_match (struct device *dev,unsigned int id) +{ +if (!dmi_check_system (htcshift_dmi_table)) +return 0 ; +return 1 ; +} + +static int __devexit htcpen_isa_remove(struct device *dev, unsigned int id) +{ +input_unregister_device (dev_get_drvdata (dev)); +dev_set_drvdata (dev,NULL ); +release_region (HTCPEN_PORT_IRQ_CLEAR ,1 ); +release_region (HTCPEN_PORT_INIT ,1 ); +release_region (HTCPEN_PORT_INDEX ,2 ); +return 0 ; +} + +#ifdef CONFIG_PM +static int htcpen_isa_suspend (struct device *dev,unsigned int n, +pm_message_t state) +{ +outb_p (DEVICE_DISABLE ,HTCPEN_PORT_INIT ); +return 0 ; +} +static int htcpen_isa_resume (struct device *dev,unsigned int n) +{ +return htcpen_open (dev_get_drvdata (dev)); +} +#endif + +static struct isa_driver htcpen_isa_driver = { + .match = htcpen_isa_match, + .probe = htcpen_isa_probe, + .remove =__devexit_p (htcpen_isa_remove), +#ifdef CONFIG_PM + .suspend = htcpen_isa_suspend, + .resume = htcpen_isa_resume, +#endif + .driver = { + .owner =THIS_MODULE , + .name ="htcpen" , + } +}; + +static int __init htcpen_isa_init (void ) +{ +return isa_register_driver (&htcpen_isa_driver,1 ); +} + +static void __exit htcpen_isa_exit(void) +{ +isa_unregister_driver (&htcpen_isa_driver); +} + +module_init (htcpen_isa_init); +module_exit (htcpen_isa_exit);
drivers/input/touchscreen/Kconfig +12 -0
@@ -134,6 +134,18 @@ config TOUCHSCREEN_HP7XX To compile this driver as a module, choose M here: the module will be called jornada720_ts. +config TOUCHSCREEN_HTCPEN + tristate "HTC Shift X9500 touchscreen" + depends on ISA + help + Say Y here if you have an HTC Shift UMPC also known as HTC X9500 + Clio / Shangrila and want to support the built-in touchscreen. + + If unsure, say N. + + To compile this driver as a module, choose M here: the + module will be called htcpen. + config TOUCHSCREEN_PENMOUNT tristate "Penmount serial touchscreen" select SERIO
drivers/input/touchscreen/Makefile +1 -0
@@ -14,6 +14,7 @@ obj-$(CONFIG_TOUCHSCREEN_MTOUCH) += mtou obj-$(CONFIG_TOUCHSCREEN_MK712) += mk712.o obj-$(CONFIG_TOUCHSCREEN_HP600) += hp680_ts_input.o obj-$(CONFIG_TOUCHSCREEN_HP7XX) += jornada720_ts.o +obj-$(CONFIG_TOUCHSCREEN_HTCPEN) += htcpen.o obj-$(CONFIG_TOUCHSCREEN_USB_COMPOSITE) += usbtouchscreen.o obj-$(CONFIG_TOUCHSCREEN_PENMOUNT) += penmount.o obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o
MAINTAINERS +6 -0
@@ -1875,6 +1875,12 @@ M: [email protected] W: http://artax.karlin.mff.cuni.cz/~mikulas/vyplody/hpfs/index-e.cgi S: Maintained +HTCPEN TOUCHSCREEN DRIVER +P: Pau Oliva Fora +M: [email protected] +L: [email protected] +S: Maintained + HUGETLB FILESYSTEM P: William Irwin M: [email protected]
Quoted 141 lines · Pau Oliva Fora
From: Pau Oliva Fora <[email protected]>
The patch below adds support for HTC Shift UMPC touchscreen.
Signed-off-by Pau Oliva Fora <[email protected]>---
Patch against linux-2.6.25.4, should apply clean on other versions too. Includes all the suggestions from Sam Ravnborg, Pekka Enberg, Marcin Slusarz and Dmitry Torokhov. Thank you all for your help.
diff -uprN
linux-2.6.25.4/drivers/input/touchscreen/htcpen.clinux/drivers/input/touchscreen/htcpen.cdrivers/input/touchscreen/htcpen.c +125
-0@@ -0,0 +1,196 @@ +/* +* HTC Shift touchscreen driver +* +* Copyright (C) 2008 Pau Oliva Fora <[email protected]> +* +* Thanks to: +* Heikki Linnakangas - Penmount LPC touchscreen driver +* Wacom / Ping Cheng - Help on linuxwacom-devel +* Esteve Espuna - Ideas, tips, moral support :) +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2 as published +* by the Free Software Foundation. +*/ + +#include <linux/errno.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/input.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/init.h> +#include <linux/irq.h> +#include <linux/isa.h> + +MODULE_AUTHOR ("Pau Oliva Fora <[email protected]>" ); +MODULE_DESCRIPTION ("HTC Shift touchscreen driver" ); +MODULE_LICENSE ("GPL" ); + +#define HTCPEN_PORT_IRQ_CLEAR 0x068 +#define HTCPEN_PORT_INIT 0x06c +#define HTCPEN_PORT_INDEX 0x0250 +#define HTCPEN_PORT_DATA 0x0251 +#define HTCPEN_IRQ 3 + +#define X_INDEX 3 +#define Y_INDEX 5 +#define TOUCH_INDEX 0xb +#define LSB_XY_INDEX 0xc +#define X_AXIS_MAX 2040 +#define Y_AXIS_MAX 2040 +#define DEVICE_ENABLE 0xa2 + +static int invert_x; +module_param (invert_x, bool,0644 ); +MODULE_PARM_DESC (invert_x,"If set, X axis is inverted" ); +static int invert_y; +module_param (invert_y, bool,0644 ); +MODULE_PARM_DESC (invert_y,"If set, Y axis is inverted" ); + +static irqreturn_t htcpen_interrupt (int irq,void *handle) +{ +struct input_dev *htcpen_dev = handle; +unsigned short x, y, xy; + +/* 0=press ; 1=release */ +outb_p (TOUCH_INDEX ,HTCPEN_PORT_INDEX ); + +/* only update X/Y when screen is being touched */ +if (inb_p (HTCPEN_PORT_DATA )) { +input_report_key (htcpen_dev,BTN_TOUCH ,0 ); + }else { +outb_p (X_INDEX ,HTCPEN_PORT_INDEX ); + x =inb_p (HTCPEN_PORT_DATA ); + +outb_p (Y_INDEX ,HTCPEN_PORT_INDEX ); + y =inb_p (HTCPEN_PORT_DATA ); + +outb_p (LSB_XY_INDEX ,HTCPEN_PORT_INDEX ); + xy =inb_p (HTCPEN_PORT_DATA ); + +/* get high resolution value of X and Y using LSB */ + x =X_AXIS_MAX - ((x *8 ) + ((xy >>4 ) &0xf )); + y = (y *8 ) + (xy &0xf ); +if (invert_x) + x =X_AXIS_MAX - x; +if (invert_y) + y =Y_AXIS_MAX - y; + +input_report_key (htcpen_dev,BTN_TOUCH ,1 ); +input_report_abs (htcpen_dev,ABS_X , x); +input_report_abs (htcpen_dev,ABS_Y , y); + } + +input_sync (htcpen_dev); + +inb_p (HTCPEN_PORT_IRQ_CLEAR ); + +return IRQ_HANDLED ; +} + +static int htcpen_open (struct input_dev *dev) +{ +outb_p (DEVICE_ENABLE ,HTCPEN_PORT_INIT ); +return 0 ; +} + +static void htcpen_close (struct input_dev *dev) +{ +free_irq (HTCPEN_IRQ , dev); +} + +static int __devinit htcpen_isa_probe (struct device *dev,unsigned int id) +{ +int err; +struct input_dev *htcpen_dev; + +printk (KERN_ERR "principi del prove\n" ); + +inb_p (HTCPEN_PORT_IRQ_CLEAR ); + + htcpen_dev =input_allocate_device (); +if (!htcpen_dev) { +printk (KERN_ERR "htcpen: can't allocate device\n" ); + err = -ENOMEM ; + goto input_alloc_failed; + } + + htcpen_dev->name ="HTC Pen TouchScreen" ; + htcpen_dev->id.bustype =BUS_ISA ; + +input_set_abs_params (htcpen_dev,ABS_X ,0 ,X_AXIS_MAX ,0 ,0 ); +input_set_abs_params (htcpen_dev,ABS_Y ,0 ,Y_AXIS_MAX ,0 ,0 ); + + htcpen_dev->evbit[0 ] =BIT_MASK (EV_ABS ) |BIT_MASK (EV_KEY );
drivers/input/touchscreen/htcpen.c line 135
Quoted 10 lines
drivers/input/touchscreen/htcpen.c +10
-0+ htcpen_dev->keybit[BIT_WORD (BTN_TOUCH )] =BIT_MASK (BTN_TOUCH ); + htcpen_dev->open = htcpen_open; + htcpen_dev->close = htcpen_close; + + err =request_irq (HTCPEN_IRQ , htcpen_interrupt,0 ,"htcpen" , + htcpen_dev); +if (err) { +printk (KERN_ERR "htcpen: irq busy\n" ); + goto request_irq_failed; + }
You must call request_region() to reserve ioport range here.
Quoted 18 lines
drivers/input/touchscreen/htcpen.c +18
-0+ + err =input_register_device (htcpen_dev); +if (err) + goto input_register_failed; + +dev_set_drvdata (dev, htcpen_dev); +return 0 ; + + input_register_failed: +free_irq (HTCPEN_IRQ , htcpen_dev); + request_irq_failed: +input_free_device (htcpen_dev); + input_alloc_failed: +return err; +} + +static int __devinit htcpen_isa_match (struct device *dev,unsigned int id) +{
drivers/input/touchscreen/htcpen.c line 164
Quoted 10 lines
drivers/input/touchscreen/htcpen.c +10
-0+unsigned short val1, val2; +/* device detection */ +outb_p (0x8 ,HTCPEN_PORT_INIT ); + val1 =inb_p (HTCPEN_PORT_INIT ); + val2 =inb_p (HTCPEN_PORT_IRQ_CLEAR ); +if ((val1 >0xc ) || (val2 !=0x55 )) { +printk (KERN_DEBUG "htcpen: no such device (%x|%x)\n" , + val1, val2); +return 0 ; + }
Poking on random ioports isn't very nice detection method. Has this machine useful DMI table ?
Quoted 80 lines
drivers/input/touchscreen/htcpen.c +32
-0+return 1 ; +} + +static int __devexit htcpen_isa_remove(struct device *dev, unsigned int id) +{ +input_unregister_device (dev_get_drvdata (dev)); +dev_set_drvdata (dev,NULL ); +return 0 ; +} + +static struct isa_driver htcpen_isa_driver = { + .match = htcpen_isa_match, + .probe = htcpen_isa_probe, + .remove =__devexit_p (htcpen_isa_remove), + .driver = { + .owner =THIS_MODULE , + .name ="htcpen" , + } +}; + +static int __init htcpen_isa_init (void ) +{ +return isa_register_driver (&htcpen_isa_driver,1 ); +} + +static void __exit htcpen_isa_exit(void) +{ +isa_unregister_driver (&htcpen_isa_driver); +} + +module_init (htcpen_isa_init); +module_exit (htcpen_isa_exit);diff -uprN linux-2.6.25.4/drivers/input/touchscreen/Kconfig linux/drivers/input/touchscreen/Kconfig
drivers/input/touchscreen/Kconfig +12
-0@@ -134,6 +134,18 @@ config TOUCHSCREEN_HP7XX To compile this driver as a module, choose M here: the module will be called jornada720_ts. +config TOUCHSCREEN_HTCPEN + tristate "HTC Shift X9500 touchscreen" + depends on ISA + help + Say Y here if you have an HTC Shift UMPC also known as HTC X9500 + Clio / Shangrila and want to support the built-in touchscreen. + + If unsure, say N. + + To compile this driver as a module, choose M here: the + module will be called htcpen. + config TOUCHSCREEN_PENMOUNT tristate "Penmount serial touchscreen" select SERIOdiff -uprN linux-2.6.25.4/drivers/input/touchscreen/Makefile linux/drivers/input/touchscreen/Makefile
drivers/input/touchscreen/Makefile +1
-0@@ -14,6 +14,7 @@ obj-$(CONFIG_TOUCHSCREEN_MTOUCH) += mtou obj-$(CONFIG_TOUCHSCREEN_MK712) += mk712.o obj-$(CONFIG_TOUCHSCREEN_HP600) += hp680_ts_input.o obj-$(CONFIG_TOUCHSCREEN_HP7XX) += jornada720_ts.o +obj-$(CONFIG_TOUCHSCREEN_HTCPEN) += htcpen.o obj-$(CONFIG_TOUCHSCREEN_USB_COMPOSITE) += usbtouchscreen.o obj-$(CONFIG_TOUCHSCREEN_PENMOUNT) += penmount.o obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.oMAINTAINERS +6
-0@@ -1875,6 +1875,12 @@ M: [email protected] W: http://artax.karlin.mff.cuni.cz/~mikulas/vyplody/hpfs/index-e.cgi S: Maintained +HTCPEN TOUCHSCREEN DRIVER +P: Pau Oliva Fora +M: [email protected] +L: [email protected] +S: Maintained + HUGETLB FILESYSTEM P: William Irwin M: [email protected]
Signature · 2 lines
Andrey Panin | Linux and UNIX system administrator [email protected] | PGP key: wwwkeys.pgp.net