2005-03-04 10:35:57

by Hans-Christian Egtvedt

[permalink] [raw]
Subject: [PATCH] new driver for ITM Touch touchscreen

Hi!

I've ported the works from Chris Collins so the drivers compiles without
warnings and works (for me) with Linux 2.6.10 and 2.6.11. The driver is
not in the kernel now, but I would like to see it be a driver among all
the other touchscreen drivers.

The touchscreen panel is for example used on the LG L1510SF screen.

Any comments on the driver would be much appreciated.

--
Regards,
Hans-Christian Egtvedt <[email protected]>
MIVU Solutions DA


Attachments:
itmtouch-linux-2.6.11.patch (11.44 kB)
signature.asc (189.00 B)
This is a digitally signed message part
Download all attachments

2005-03-04 11:04:27

by Alexey Dobriyan

[permalink] [raw]
Subject: Re: [PATCH] new driver for ITM Touch touchscreen

On Friday 04 March 2005 12:30, Hans-Christian Egtvedt wrote:

> I've ported the works from Chris Collins so the drivers compiles without
> warnings and works (for me) with Linux 2.6.10 and 2.6.11.

> Any comments on the driver would be much appreciated.

> +struct itmtouch_dev {

> + int refcount; //

There is already generic interface for reference-counted objects. See
lib/kref.c and kref documentation at:

http://marc.theaimsgroup.com/?l=linux-kernel&m=110987233406767&w=2

Alexey

2005-03-04 14:53:55

by Dmitry Torokhov

[permalink] [raw]
Subject: Re: [PATCH] new driver for ITM Touch touchscreen

On Fri, 4 Mar 2005 14:03:37 +0200, Alexey Dobriyan <[email protected]> wrote:
> On Friday 04 March 2005 12:30, Hans-Christian Egtvedt wrote:
>
> > I've ported the works from Chris Collins so the drivers compiles without
> > warnings and works (for me) with Linux 2.6.10 and 2.6.11.
>
> > Any comments on the driver would be much appreciated.
>
> > +struct itmtouch_dev {
>
> > + int refcount; //
>
> There is already generic interface for reference-counted objects. See
> lib/kref.c and kref documentation at:
>
> http://marc.theaimsgroup.com/?l=linux-kernel&m=110987233406767&w=2
>

... which is absolutely unusable for this particular purpose - the
touchscreen object is not going away when refcount is 0. The variable
shoudl be renamed to "users" or something. Moreover it needs locking.

Anyway, all of this will be handled by the input core very shortly so
it can be left as is for now.

As far as the driver goes:

- yes, it does need input_sync;
- I prefer using input_set_abs_params instead of setting mix, max,
flat and fuzz for each axis manually;
- I believe "/* .. */" is preferred over "//"
- kill the commented out bad prototypes.

Also, is there a way to query the screen for actual size?

--
Dmitry

2005-03-04 16:21:17

by Hans-Christian Egtvedt

[permalink] [raw]
Subject: Re: [PATCH] new driver for ITM Touch touchscreen

On Fri, 2005-03-04 at 09:52 -0500, Dmitry Torokhov wrote:
> On Fri, 4 Mar 2005 14:03:37 +0200, Alexey Dobriyan <[email protected]> wrote:
> > On Friday 04 March 2005 12:30, Hans-Christian Egtvedt wrote:

<snip info about kref>

> As far as the driver goes:
>
> - yes, it does need input_sync;

One problem with input_sync is that the panel get's too fast, and double
click is experienced quite often, maybe some threshold is needed for low
values in Z-direction?

I'm probably doing something wrong here since I experience easy
doubleclicks when I just lightly touch the screen.

> - I prefer using input_set_abs_params instead of setting mix, max,
> flat and fuzz for each axis manually;

Thanks, I've adopted to those now, havn't had time to test with the
panel today, but my guess is that this dosn't make a big deal.

> - I believe "/* .. */" is preferred over "//"

Done.

> - kill the commented out bad prototypes.

Done.

> Also, is there a way to query the screen for actual size?

Sorry, the panel is a fixed size, and it gives out coordinates from 0 ->
4095 in both X- and Y-direction. In Z-direction (pressure strength) it
goes from 0 to 255.

Or did you want the size of the screen? Meaning you want to know if it's
a 15", 17" and so on?

--
Hans-Christian Egtvedt <[email protected]>
MIVU Solutions DA

2005-03-04 17:00:10

by Dmitry Torokhov

[permalink] [raw]
Subject: Re: [PATCH] new driver for ITM Touch touchscreen

On Fri, 04 Mar 2005 17:20:24 +0100, Hans-Christian Egtvedt <[email protected]> wrote:
> On Fri, 2005-03-04 at 09:52 -0500, Dmitry Torokhov wrote:
> > On Fri, 4 Mar 2005 14:03:37 +0200, Alexey Dobriyan <[email protected]> wrote:
> > > On Friday 04 March 2005 12:30, Hans-Christian Egtvedt wrote:
>
> <snip info about kref>
>
> > As far as the driver goes:
> >
> > - yes, it does need input_sync;
>
> One problem with input_sync is that the panel get's too fast, and double
> click is experienced quite often, maybe some threshold is needed for low
> values in Z-direction?
>
> I'm probably doing something wrong here since I experience easy
> doubleclicks when I just lightly touch the screen.
>

Yes, I think you need to use some threshold when reporting BTN_TOUCH
event. Still, always report ABS_PRESSURE as is. This way the
touchscreen is useable via legacy interfaces (mousedev. tsdev) and if
a specialized userspace driver is written it still can get pretty much
unmangled data from /dev/input/eventX. This will also allow such
driver adjust touchpad sensitivity, if needed.

> > Also, is there a way to query the screen for actual size?
>
> Sorry, the panel is a fixed size, and it gives out coordinates from 0 ->
> 4095 in both X- and Y-direction. In Z-direction (pressure strength) it
> goes from 0 to 255.
>
> Or did you want the size of the screen? Meaning you want to know if it's
> a 15", 17" and so on?
>

No, not physical sizes. I was wondering if soe touchscreens are
reporting let's say actual coordinates from 1100-3600 and others from
600-3850, instead of full 0-4096. Is there a way to query the hardware
and find the actual min and max for a device so it can be reported to
userspace.

--
Dmitry

P.S. When you post the updated version could you please CC Vojtech
Pavlik <[email protected]> as he is the current input system maintainer
and linux-input mailing list at [email protected].
Thanks!

2005-03-04 18:59:23

by Hans-Christian Egtvedt

[permalink] [raw]
Subject: Re: [PATCH] new driver for ITM Touch touchscreen

Around Fri 04 Mar 2005 11:54:18 +0000 or thereabout, Dmitry Torokhov wrote:
> On Fri, 04 Mar 2005 17:20:24 +0100, Hans-Christian Egtvedt <[email protected]> wrote:
>> On Fri, 2005-03-04 at 09:52 -0500, Dmitry Torokhov wrote:
>> > On Fri, 4 Mar 2005 14:03:37 +0200, Alexey Dobriyan <[email protected]> wrote:
>> > > On Friday 04 March 2005 12:30, Hans-Christian Egtvedt wrote:
>> > As far as the driver goes:
>> >
>> > - yes, it does need input_sync;
>> One problem with input_sync is that the panel get's too fast, and double
>> click is experienced quite often, maybe some threshold is needed for low
>> values in Z-direction?
>>
>> I'm probably doing something wrong here since I experience easy
>> doubleclicks when I just lightly touch the screen.
> Yes, I think you need to use some threshold when reporting BTN_TOUCH
> event. Still, always report ABS_PRESSURE as is. This way the
> touchscreen is useable via legacy interfaces (mousedev. tsdev) and if
> a specialized userspace driver is written it still can get pretty much
> unmangled data from /dev/input/eventX. This will also allow such
> driver adjust touchpad sensitivity, if needed.

OK, I'll try to find some better documentation about input devices, any
tips/pointers would be nice. I'm completly new to kernel drivers, I'm used to
writing drivers in embedded systems.

The driver is made in the way it is today because there is also a driver for
X which read raw events from /dev/input/eventX. It's called lictouch, I have
the source for it too, but I'm not (yet) part of any developing there.

It would be a really nice feature if one could use the touchscreen as a
legacy interface, but then I would need to be able to calibrate the screen in
the driver and not frontend. At least preferable.

>> > Also, is there a way to query the screen for actual size?
>>
>> Sorry, the panel is a fixed size, and it gives out coordinates from 0 ->
>> 4095 in both X- and Y-direction. In Z-direction (pressure strength) it
>> goes from 0 to 255.
>>
>> Or did you want the size of the screen? Meaning you want to know if it's
>> a 15", 17" and so on?
> No, not physical sizes. I was wondering if soe touchscreens are
> reporting let's say actual coordinates from 1100-3600 and others from
> 600-3850, instead of full 0-4096. Is there a way to query the hardware
> and find the actual min and max for a device so it can be reported to
> userspace.

I really don't have an answer, I'm still waiting for the datascheet to the
controller beeing used. When I get that I can perhaps do calibration in the
driver, and not with a config file or in xf86free/x.org config.

--
Regards
Hans-Christian Egtvedt
MIVU Solutions DA

2005-03-04 20:45:53

by Vojtech Pavlik

[permalink] [raw]
Subject: Re: [PATCH] new driver for ITM Touch touchscreen

On Fri, Mar 04, 2005 at 11:54:18AM -0500, Dmitry Torokhov wrote:

> No, not physical sizes. I was wondering if soe touchscreens are
> reporting let's say actual coordinates from 1100-3600 and others from
> 600-3850, instead of full 0-4096. Is there a way to query the hardware
> and find the actual min and max for a device so it can be reported to
> userspace.

Resistive touchscreens, due to their voltage-divider nature have
near-full range all the time, independent of the controller and sensor
combination, so setting min to 0 and max to 4096 is OK.

> P.S. When you post the updated version could you please CC Vojtech
> Pavlik <[email protected]> as he is the current input system maintainer
> and linux-input mailing list at [email protected].

Yes, please. ;)

--
Vojtech Pavlik
SuSE Labs, SuSE CR

2005-03-04 20:45:52

by Vojtech Pavlik

[permalink] [raw]
Subject: Re: [PATCH] new driver for ITM Touch touchscreen

On Fri, Mar 04, 2005 at 07:51:47PM +0100, Hans-Christian Egtvedt wrote:

> OK, I'll try to find some better documentation about input devices, any
> tips/pointers would be nice. I'm completly new to kernel drivers, I'm used to
> writing drivers in embedded systems.
>
> The driver is made in the way it is today because there is also a driver for
> X which read raw events from /dev/input/eventX. It's called lictouch, I have
> the source for it too, but I'm not (yet) part of any developing there.

Please take a look at 'evtouch' by Kenan Esau, which may fit your bill
as an X driver, too. [http://www.conan.de/lifebook]

> It would be a really nice feature if one could use the touchscreen as a
> legacy interface, but then I would need to be able to calibrate the screen in
> the driver and not frontend. At least preferable.

It's possible to do that to a certain degree using the EVIOCSABS
ioctl(). Only trivial linear calibration is supported, though.

--
Vojtech Pavlik
SuSE Labs, SuSE CR

2005-03-08 16:03:38

by Hans-Christian Egtvedt

[permalink] [raw]
Subject: Re: [PATCH] new driver for ITM Touch touchscreen

On Fri, 2005-03-04 at 11:54 -0500, Dmitry Torokhov wrote:
> On Fri, 04 Mar 2005 17:20:24 +0100, Hans-Christian Egtvedt <[email protected]> wrote:
> > On Fri, 2005-03-04 at 09:52 -0500, Dmitry Torokhov wrote:
> > > On Fri, 4 Mar 2005 14:03:37 +0200, Alexey Dobriyan <[email protected]> wrote:
> > > > On Friday 04 March 2005 12:30, Hans-Christian Egtvedt wrote:
> > > As far as the driver goes:
> > >
> > > - yes, it does need input_sync;
> >
> > One problem with input_sync is that the panel get's too fast, and double
> > click is experienced quite often, maybe some threshold is needed for low
> > values in Z-direction?
> >
> > I'm probably doing something wrong here since I experience easy
> > doubleclicks when I just lightly touch the screen.
>
> Yes, I think you need to use some threshold when reporting BTN_TOUCH
> event. Still, always report ABS_PRESSURE as is. This way the
> touchscreen is useable via legacy interfaces (mousedev. tsdev) and if
> a specialized userspace driver is written it still can get pretty much
> unmangled data from /dev/input/eventX. This will also allow such
> driver adjust touchpad sensitivity, if needed.

Do you have any pointers to where I should go to implement this
threshold? Is there an easy or smart way doing it?

<snip query about screen siz

> No, not physical sizes. I was wondering if soe touchscreens are
> reporting let's say actual coordinates from 1100-3600 and others from
> 600-3850, instead of full 0-4096. Is there a way to query the hardware
> and find the actual min and max for a device so it can be reported to
> userspace.

I really don't think the controller can now anything about the size of
the screen.

I've attached version 1.2.1 of the driver, fixed some typo, code cleanup
and discovered I used depricated functions so I moved to the new correct
way of doing killing of the urb.

Starting looking into ways of using the module directly as a standard
mouse, that will take away loads of worries for me about converting X
applications to x.org.

Any tips are welcome. Is this done before with a touchscreen?

--
Hans-Christian Egtvedt <[email protected]>
MIVU Solutions DA


Attachments:
itmtouch-1.2.1-linux-2.6.11.patch (10.93 kB)
signature.asc (189.00 B)
This is a digitally signed message part
Download all attachments

2005-03-08 17:25:23

by Dmitry Torokhov

[permalink] [raw]
Subject: Re: [PATCH] new driver for ITM Touch touchscreen

On Tue, 08 Mar 2005 17:01:00 +0100, Hans-Christian Egtvedt <[email protected]> wrote:
> On Fri, 2005-03-04 at 11:54 -0500, Dmitry Torokhov wrote:
> > On Fri, 04 Mar 2005 17:20:24 +0100, Hans-Christian Egtvedt <[email protected]> wrote:
> > > On Fri, 2005-03-04 at 09:52 -0500, Dmitry Torokhov wrote:
> > > > On Fri, 4 Mar 2005 14:03:37 +0200, Alexey Dobriyan <[email protected]> wrote:
> > > > > On Friday 04 March 2005 12:30, Hans-Christian Egtvedt wrote:
> > > > As far as the driver goes:
> > > >
> > > > - yes, it does need input_sync;
> > >
> > > One problem with input_sync is that the panel get's too fast, and double
> > > click is experienced quite often, maybe some threshold is needed for low
> > > values in Z-direction?
> > >
> > > I'm probably doing something wrong here since I experience easy
> > > doubleclicks when I just lightly touch the screen.
> >
> > Yes, I think you need to use some threshold when reporting BTN_TOUCH
> > event. Still, always report ABS_PRESSURE as is. This way the
> > touchscreen is useable via legacy interfaces (mousedev. tsdev) and if
> > a specialized userspace driver is written it still can get pretty much
> > unmangled data from /dev/input/eventX. This will also allow such
> > driver adjust touchpad sensitivity, if needed.
>
> Do you have any pointers to where I should go to implement this
> threshold? Is there an easy or smart way doing it?
>

I am not sure... that BTN_TOUCH - look slike it works off a single
flag reported by hardware. You porobably do not need to change it.

Try loading mousedev module (after adding input_sync back to your
driver) - it provides cooked PS/2 protocol to userspace - it should
bind to your driver. Then you can use GPM or X (read from
/dev/input/mice) to test the touchscreen and see if you have issue
with double clicks.

--
Dmitry

2005-03-08 17:49:05

by Vojtech Pavlik

[permalink] [raw]
Subject: Re: [PATCH] new driver for ITM Touch touchscreen

On Tue, Mar 08, 2005 at 12:25:09PM -0500, Dmitry Torokhov wrote:

> I am not sure... that BTN_TOUCH - look slike it works off a single
> flag reported by hardware. You porobably do not need to change it.

Indeed, if the hardware reports a touch flag it's best to use that.

> Try loading mousedev module (after adding input_sync back to your
> driver) - it provides cooked PS/2 protocol to userspace - it should
> bind to your driver. Then you can use GPM or X (read from
> /dev/input/mice) to test the touchscreen and see if you have issue
> with double clicks.

And for even better behavior, use 'evtouch' from Kenan Esau as an X
driver.

--
Vojtech Pavlik
SuSE Labs, SuSE CR

2005-03-08 18:25:18

by Paulo Marques

[permalink] [raw]
Subject: Re: [PATCH] new driver for ITM Touch touchscreen

Hans-Christian Egtvedt wrote:
> [...]
> Any tips are welcome. Is this done before with a touchscreen?

Just a minor nitpick, not really related to the mouse problem. More of
coding style problem.

IMHO the UCP and UCOM macros just obfuscate the code. If you do not want
to write "((unsigned char *) urb->transfer_buffer)[0]" every time (I can
perfectly understand that), maybe using a local "u8 *" var would do the
trick.

Something like this:

> static void itmtouch_irq(struct urb *urb, struct pt_regs *regs)
> {
> struct itmtouch_dev * itmtouch = urb->context;
> int retval;
> u8 *tbuf;
>
> ....
>
> input_regs(&itmtouch->inputdev, regs);
>
> tbuf = (u8 *)(urb->transfer_buffer);
>
> /* if pressure has been released, then don't report X/Y */
> if (!(tbuf[7] & 0x20)) {
> input_report_abs(&itmtouch->inputdev, ABS_X,
> (tbuf[0] & 0x1F) << 7 | (tbuf[3] & 0x7F));
> input_report_abs(&itmtouch->inputdev, ABS_Y,
> (tbuf[1] & 0x1F) << 7 | (tbuf[4] & 0x7F));
> }
>
> input_report_abs(&itmtouch->inputdev, ABS_PRESSURE,
> (tbuf[2] & 0x1) << 7 | (tbuf[5] & 0x7F));
> input_report_key(&itmtouch->inputdev, BTN_TOUCH, !(tbuf[7] & 0x20));
> /* TODO: Do we need to use input_sync() ? */
> /* input_sync(&itmtouch->inputdev); */
>
> ......

This is perfectly readable without one having to find out what those
macros mean, and it is even easier for the compiler to optimize (even
though gcc will probably optimize both versions just fine).

--
Paulo Marques - http://www.grupopie.com

All that is necessary for the triumph of evil is that good men do nothing.
Edmund Burke (1729 - 1797)

2005-03-10 16:22:40

by Vojtech Pavlik

[permalink] [raw]
Subject: Re: [PATCH] new driver for ITM Touch touchscreen

On Tue, Mar 08, 2005 at 05:01:00PM +0100, Hans-Christian Egtvedt wrote:

> I really don't think the controller can now anything about the size of
> the screen.
>
> I've attached version 1.2.1 of the driver, fixed some typo, code cleanup
> and discovered I used depricated functions so I moved to the new correct
> way of doing killing of the urb.

Pacth applied, with minor cleanups.

> --- kernel-source-2.6.11/drivers/usb/input/Kconfig 2004-12-24 22:35:23.000000000 +0100
> +++ linux-2.6.11/drivers/usb/input/Kconfig 2005-03-02 10:58:41.000000000 +0100
> @@ -190,6 +190,18 @@
> To compile this driver as a module, choose M here: the
> module will be called mtouchusb.
>
> +config USB_ITMTOUCH
> + tristate "ITM Touch USB Touchscreen Driver"
> + depends on USB && INPUT
> + ---help---
> + Say Y here if you want to use a ITM Touch USB
> + Touchscreen controller.
> +
> + This touchscreen is used in LG 1510SF monitors.
> +
> + To compile this driver as a module, choose M here: the
> + module will be called itmtouch.
> +
> config USB_EGALAX
> tristate "eGalax TouchKit USB Touchscreen Driver"
> depends on USB && INPUT
> --- kernel-source-2.6.11/drivers/usb/input/Makefile 2004-12-24 22:35:00.000000000 +0100
> +++ linux-2.6.11/drivers/usb/input/Makefile 2005-03-02 10:57:11.000000000 +0100
> @@ -33,6 +33,7 @@
> obj-$(CONFIG_USB_KBTAB) += kbtab.o
> obj-$(CONFIG_USB_MOUSE) += usbmouse.o
> obj-$(CONFIG_USB_MTOUCH) += mtouchusb.o
> +obj-$(CONFIG_USB_ITMTOUCH) += itmtouch.o
> obj-$(CONFIG_USB_EGALAX) += touchkitusb.o
> obj-$(CONFIG_USB_POWERMATE) += powermate.o
> obj-$(CONFIG_USB_WACOM) += wacom.o
> --- /dev/null 2005-03-01 19:15:30.000000000 +0100
> +++ linux-2.6.11/drivers/usb/input/itmtouch.c 2005-03-02 11:05:04.000000000 +0100
> @@ -0,0 +1,318 @@
> +/******************************************************************************
> + * itmtouch.c -- Driver for ITM touchscreen panel
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation; either version 2 of the
> + * License, or (at your option) any later version.
> + *
> + * 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 program; if not, write to the Free Software
> + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
> + *
> + * Based upon original work by Chris Collins <[email protected]>.
> + *
> + * History
> + * 1.0 & 1.1 2003 (CC) [email protected]
> + * Original version for 2.4.x kernels
> + *
> + * 1.2 02/03/2005 (HCE) [email protected]
> + * Complete rewrite to support Linux 2.6.10, thanks to mtouchusb.c for hints.
> + * Unfortunately no calibration support at this time.
> + *
> + * 1.2.1 09/03/2005 (HCE) [email protected]
> + * Code cleanup and adjusting syntax to start matching kernel standards
> + *
> + *****************************************************************************/
> +
> +/* In order to prevent poluting device space with YET ANOTHER character
> + * device, this driver pumps out raw coordinate events into the input
> + * event stream.
> + *
> + * They can be extracted using the input core raw events module.
> + *
> + * Kudos to ITM for providing me with the datasheet for the panel,
> + * even though it was a day later than I had finished writing this
> + * driver.
> + *
> + * It has meant that I've been able to correct my interpretation of the
> + * protocol packets however.
> + *
> + * CC -- 2003/9/29
> + */
> +
> +#include <linux/config.h>
> +
> +#ifdef CONFIG_USB_DEBUG
> + #define DEBUG
> +#else
> + #undef DEBUG
> +#endif
> +
> +#include <linux/kernel.h>
> +#include <linux/slab.h>
> +#include <linux/input.h>
> +#include <linux/module.h>
> +#include <linux/init.h>
> +#include <linux/usb.h>
> +
> +/* only an 8 byte buffer necessary for a single packet */
> +#define ITM_BUFSIZE 8
> +/* support a maximum of 4 such touchscreens at once */
> +#define MAXTOUCH 4
> +#define UCP(x) ((unsigned char*)(x))
> +#define UCOM(x,y,z) ((UCP((x)->transfer_buffer)[y]) & (z))
> +#define PATH_SIZE 64
> +
> +#define USB_VENDOR_ID_ITMINC 0x0403
> +#define USB_PRODUCT_ID_TOUCHPANEL 0xf9e9
> +
> +#define DRIVER_AUTHOR "Hans-Christian Egtvedt <[email protected]>"
> +#define DRIVER_VERSION "v1.2.1"
> +#define DRIVER_DESC "USB ITM Inc Touch Panel Driver"
> +#define DRIVER_LICENSE "GPL"
> +
> +MODULE_AUTHOR( DRIVER_AUTHOR );
> +MODULE_DESCRIPTION( DRIVER_DESC );
> +MODULE_LICENSE( DRIVER_LICENSE );
> +
> +struct itmtouch_dev {
> + struct usb_device *usbdev; /* usb device */
> + struct input_dev inputdev; /* input device */
> + struct urb *readurb; /* urb */
> + char rbuf[ITM_BUFSIZE]; /* data */
> + int users;
> + char name[128];
> + char phys[64];
> +};
> +
> +static struct usb_device_id itmtouch_ids [] = {
> + { USB_DEVICE(USB_VENDOR_ID_ITMINC, USB_PRODUCT_ID_TOUCHPANEL) },
> + { }
> +};
> +
> +static void itmtouch_irq(struct urb *urb, struct pt_regs *regs)
> +{
> + struct itmtouch_dev * itmtouch = urb->context;
> + int retval;
> +
> + switch (urb->status) {
> + case 0:
> + /* success */
> + break;
> + case -ETIMEDOUT:
> + /* this urb is timing out */
> + dbg("%s - urb timed out - was the device unplugged?",
> + __FUNCTION__);
> + return;
> + case -ECONNRESET:
> + case -ENOENT:
> + case -ESHUTDOWN:
> + /* this urb is terminated, clean up */
> + dbg("%s - urb shutting down with status: %d",
> + __FUNCTION__, urb->status);
> + return;
> + default:
> + dbg("%s - nonzero urb status received: %d",
> + __FUNCTION__, urb->status);
> + goto exit;
> + }
> +
> + input_regs(&itmtouch->inputdev, regs);
> +
> + /* if pressure has been released, then don't report X/Y */
> + if (!UCOM(urb, 7, 0x20)) {
> + input_report_abs(&itmtouch->inputdev, ABS_X,
> + UCOM(urb, 0, 0x1F) << 7 | UCOM(urb, 3, 0x7F));
> + input_report_abs(&itmtouch->inputdev, ABS_Y,
> + UCOM(urb, 1, 0x1F) << 7 | UCOM(urb, 4, 0x7F));
> + }
> +
> + input_report_abs(&itmtouch->inputdev, ABS_PRESSURE,
> + UCOM(urb, 2, 0x1) << 7 | UCOM(urb, 5, 0x7F));
> + input_report_key(&itmtouch->inputdev, BTN_TOUCH, !UCOM(urb, 7, 0x20));
> + /* TODO: Do we need to use input_sync() ? */
> + /* input_sync(&itmtouch->inputdev); */
> +
> +exit:
> + retval = usb_submit_urb (urb, GFP_ATOMIC);
> + if (retval)
> + printk(KERN_ERR "%s - usb_submit_urb failed with result: %d",
> + __FUNCTION__, retval);
> +}
> +
> +static int itmtouch_open(struct input_dev *input)
> +{
> + struct itmtouch_dev *itmtouch = input->private;
> +
> + if (itmtouch->users++)
> + return 0;
> +
> + itmtouch->readurb->dev = itmtouch->usbdev;
> +
> + if (usb_submit_urb (itmtouch->readurb, GFP_KERNEL))
> + {
> + itmtouch->users--;
> + return -EIO;
> + }
> +
> + return 0;
> +}
> +
> +static void itmtouch_close(struct input_dev *input)
> +{
> + struct itmtouch_dev *itmtouch = input->private;
> +
> + if (!--itmtouch->users)
> + usb_kill_urb (itmtouch->readurb);
> +}
> +
> +static int itmtouch_probe(struct usb_interface *intf, const struct usb_device_id *id)
> +{
> + struct itmtouch_dev *itmtouch;
> + struct usb_host_interface *interface;
> + struct usb_endpoint_descriptor *endpoint;
> + struct usb_device * udev = interface_to_usbdev(intf);
> + unsigned int pipe;
> + unsigned int maxp;
> + char path[PATH_SIZE];
> +
> + dbg("%s - called", __FUNCTION__);
> +
> + dbg("%s - setting interface", __FUNCTION__);
> + interface = intf->cur_altsetting;
> +
> + dbg("%s - setting endpoint", __FUNCTION__);
> + endpoint = &interface->endpoint[0].desc;
> +
> + if (id->idVendor != USB_VENDOR_ID_ITMINC || id->idProduct != USB_PRODUCT_ID_TOUCHPANEL) {
> + printk(KERN_WARNING "itmtouch: tried to bind to non-ts device.\n");
> + return -ENODEV;
> + }
> +
> + /* allocate memory space */
> + if (!(itmtouch = kmalloc (sizeof (struct itmtouch_dev), GFP_KERNEL))) {
> + err("%s - Out of memory.", __FUNCTION__);
> + return -ENOMEM;
> + }
> + memset(itmtouch, 0, sizeof(struct itmtouch_dev));
> +
> + /* fill in the USB device info */
> + itmtouch->usbdev = udev;
> +
> + itmtouch->inputdev.private = itmtouch;
> + itmtouch->inputdev.open = itmtouch_open;
> + itmtouch->inputdev.close = itmtouch_close;
> +
> + usb_make_path(udev, path, PATH_SIZE);
> +
> + /* set up the input queue */
> + itmtouch->inputdev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
> + itmtouch->inputdev.absbit[0] = BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE);
> + itmtouch->inputdev.keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
> +
> + itmtouch->inputdev.name = itmtouch->name;
> + itmtouch->inputdev.phys = itmtouch->phys;
> + itmtouch->inputdev.id.bustype = BUS_USB;
> + itmtouch->inputdev.id.vendor = udev->descriptor.idVendor;
> + itmtouch->inputdev.id.product = udev->descriptor.idProduct;
> + itmtouch->inputdev.id.version = udev->descriptor.bcdDevice;
> + itmtouch->inputdev.dev = &intf->dev;
> +
> + if (!strlen(itmtouch->name))
> + sprintf(itmtouch->name, "USB ITM touchscreen");
> +
> + /* device limits */
> + /* as specified by the ITM datasheet, X and Y are 12bit,
> + * Z (pressure) is 8 bit. However, the fields are defined up
> + * to 14 bits for future possible expansion.
> + */
> + input_set_abs_params(&itmtouch->inputdev, ABS_X, 0, 0x0FFF, 2, 0);
> + input_set_abs_params(&itmtouch->inputdev, ABS_Y, 0, 0x0FFF, 2, 0);
> + input_set_abs_params(&itmtouch->inputdev, ABS_PRESSURE, 0, 0xFF, 2, 0);
> +
> + /* initialise the URB so we can read from the transport stream */
> + pipe = usb_rcvintpipe(itmtouch->usbdev, endpoint->bEndpointAddress);
> +
> + maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
> +
> + if (maxp > ITM_BUFSIZE) {
> + printk(KERN_WARNING "itmtouch: WARNING: packet size > ITM_BUFSIZE\n");
> + maxp = ITM_BUFSIZE;
> + }
> +
> + itmtouch->readurb = usb_alloc_urb(0, GFP_KERNEL);
> +
> + if (!itmtouch->readurb) {
> + dbg("%s - usb_alloc_urb failed: itmtouch->readurb", __FUNCTION__);
> + kfree(itmtouch);
> + return -ENOMEM;
> + }
> +
> + dbg("%s - usb_fill_int_urb", __FUNCTION__);
> + usb_fill_int_urb(itmtouch->readurb,
> + itmtouch->usbdev,
> + pipe,
> + itmtouch->rbuf,
> + maxp,
> + itmtouch_irq,
> + itmtouch,
> + endpoint->bInterval);
> +
> + /* register the device with the input system */
> + dbg("%s - input_register_device", __FUNCTION__);
> + input_register_device(&itmtouch->inputdev);
> +
> + printk(KERN_INFO "itmtouch: %s registered on %s\n", itmtouch->name, path);
> + usb_set_intfdata(intf, itmtouch);
> +
> + return 0;
> +}
> +
> +static void itmtouch_disconnect(struct usb_interface *intf)
> +{
> + struct itmtouch_dev *itmtouch = usb_get_intfdata (intf);
> +
> + dbg("%s - called", __FUNCTION__);
> +
> + usb_set_intfdata(intf, NULL);
> + if (itmtouch) {
> + dbg("%s - itmtouch is initialized, cleaning up", __FUNCTION__);
> + input_unregister_device(&itmtouch->inputdev);
> + usb_kill_urb(itmtouch->readurb);
> + usb_free_urb(itmtouch->readurb);
> + kfree(itmtouch);
> + }
> +}
> +
> +MODULE_DEVICE_TABLE(usb, itmtouch_ids);
> +
> +static struct usb_driver itmtouch_driver = {
> + .owner = THIS_MODULE,
> + .name = "itmtouch",
> + .probe = itmtouch_probe,
> + .disconnect = itmtouch_disconnect,
> + .id_table = itmtouch_ids,
> +};
> +
> +static int __init itmtouch_init(void)
> +{
> + dbg("%s - called", __FUNCTION__);
> + info(DRIVER_DESC " " DRIVER_VERSION);
> + info(DRIVER_AUTHOR);
> + return usb_register(&itmtouch_driver);
> +}
> +
> +static void __exit itmtouch_exit(void)
> +{
> + dbg("%s - called", __FUNCTION__);
> + usb_deregister(&itmtouch_driver);
> +}
> +
> +module_init(itmtouch_init);
> +module_exit(itmtouch_exit);




--
Vojtech Pavlik
SuSE Labs, SuSE CR

2005-03-10 16:42:52

by Hans-Christian Egtvedt

[permalink] [raw]
Subject: Re: [PATCH] new driver for ITM Touch touchscreen

On Thu, 2005-03-10 at 17:18 +0100, Vojtech Pavlik wrote:
> On Tue, Mar 08, 2005 at 05:01:00PM +0100, Hans-Christian Egtvedt wrote:
>
> > I really don't think the controller can now anything about the size of
> > the screen.
> >
> > I've attached version 1.2.1 of the driver, fixed some typo, code cleanup
> > and discovered I used depricated functions so I moved to the new correct
> > way of doing killing of the urb.
>
> Pacth applied, with minor cleanups.

Could you send me your changes?

<snip patch file>

--
Hans-Christian Egtvedt <[email protected]>
MIVU Solutions DA

2005-03-10 16:50:11

by Vojtech Pavlik

[permalink] [raw]
Subject: Re: [PATCH] new driver for ITM Touch touchscreen

On Thu, Mar 10, 2005 at 05:41:42PM +0100, Hans-Christian Egtvedt wrote:
> On Thu, 2005-03-10 at 17:18 +0100, Vojtech Pavlik wrote:
> > On Tue, Mar 08, 2005 at 05:01:00PM +0100, Hans-Christian Egtvedt wrote:
> >
> > > I really don't think the controller can now anything about the size of
> > > the screen.
> > >
> > > I've attached version 1.2.1 of the driver, fixed some typo, code cleanup
> > > and discovered I used depricated functions so I moved to the new correct
> > > way of doing killing of the urb.
> >
> > Pacth applied, with minor cleanups.
>
> Could you send me your changes?

Here is the final patch:


[email protected], 2005-03-10 17:17:56+01:00, [email protected]
input: Add driver for ITM Touch USB touchscreens.

From: Hans-Christian Egtvedt <[email protected]>
Signed-off-by: Vojtech Pavlik <[email protected]>


Kconfig | 12 ++
Makefile | 1
itmtouch.c | 281 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 294 insertions(+)


diff -Nru a/drivers/usb/input/Kconfig b/drivers/usb/input/Kconfig
--- a/drivers/usb/input/Kconfig 2005-03-10 17:45:56 +01:00
+++ b/drivers/usb/input/Kconfig 2005-03-10 17:45:56 +01:00
@@ -190,6 +190,18 @@
To compile this driver as a module, choose M here: the
module will be called mtouchusb.

+config USB_ITMTOUCH
+ tristate "ITM Touch USB Touchscreen Driver"
+ depends on USB && INPUT
+ ---help---
+ Say Y here if you want to use a ITM Touch USB
+ Touchscreen controller.
+
+ This touchscreen is used in LG 1510SF monitors.
+
+ To compile this driver as a module, choose M here: the
+ module will be called itmtouch.
+
config USB_EGALAX
tristate "eGalax TouchKit USB Touchscreen Driver"
depends on USB && INPUT
diff -Nru a/drivers/usb/input/Makefile b/drivers/usb/input/Makefile
--- a/drivers/usb/input/Makefile 2005-03-10 17:45:56 +01:00
+++ b/drivers/usb/input/Makefile 2005-03-10 17:45:56 +01:00
@@ -33,6 +33,7 @@
obj-$(CONFIG_USB_KBTAB) += kbtab.o
obj-$(CONFIG_USB_MOUSE) += usbmouse.o
obj-$(CONFIG_USB_MTOUCH) += mtouchusb.o
+obj-$(CONFIG_USB_ITMTOUCH) += itmtouch.o
obj-$(CONFIG_USB_EGALAX) += touchkitusb.o
obj-$(CONFIG_USB_POWERMATE) += powermate.o
obj-$(CONFIG_USB_WACOM) += wacom.o
diff -Nru a/drivers/usb/input/itmtouch.c b/drivers/usb/input/itmtouch.c
--- /dev/null Wed Dec 31 16:00:00 196900
+++ b/drivers/usb/input/itmtouch.c 2005-03-10 17:45:56 +01:00
@@ -0,0 +1,281 @@
+/******************************************************************************
+ * itmtouch.c -- Driver for ITM touchscreen panel
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * 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 program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Based upon original work by Chris Collins <[email protected]>.
+ *
+ * Kudos to ITM for providing me with the datasheet for the panel,
+ * even though it was a day later than I had finished writing this
+ * driver.
+ *
+ * It has meant that I've been able to correct my interpretation of the
+ * protocol packets however.
+ *
+ * CC -- 2003/9/29
+ *
+ * History
+ * 1.0 & 1.1 2003 (CC) [email protected]
+ * Original version for 2.4.x kernels
+ *
+ * 1.2 02/03/2005 (HCE) [email protected]
+ * Complete rewrite to support Linux 2.6.10, thanks to mtouchusb.c for hints.
+ * Unfortunately no calibration support at this time.
+ *
+ * 1.2.1 09/03/2005 (HCE) [email protected]
+ * Code cleanup and adjusting syntax to start matching kernel standards
+ *
+ *****************************************************************************/
+
+#include <linux/config.h>
+
+#ifdef CONFIG_USB_DEBUG
+ #define DEBUG
+#else
+ #undef DEBUG
+#endif
+
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/input.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/usb.h>
+
+/* only an 8 byte buffer necessary for a single packet */
+#define ITM_BUFSIZE 8
+#define PATH_SIZE 64
+
+#define USB_VENDOR_ID_ITMINC 0x0403
+#define USB_PRODUCT_ID_TOUCHPANEL 0xf9e9
+
+#define DRIVER_AUTHOR "Hans-Christian Egtvedt <[email protected]>"
+#define DRIVER_VERSION "v1.2.1"
+#define DRIVER_DESC "USB ITM Inc Touch Panel Driver"
+#define DRIVER_LICENSE "GPL"
+
+MODULE_AUTHOR( DRIVER_AUTHOR );
+MODULE_DESCRIPTION( DRIVER_DESC );
+MODULE_LICENSE( DRIVER_LICENSE );
+
+struct itmtouch_dev {
+ struct usb_device *usbdev; /* usb device */
+ struct input_dev inputdev; /* input device */
+ struct urb *readurb; /* urb */
+ char rbuf[ITM_BUFSIZE]; /* data */
+ int users;
+ char name[128];
+ char phys[64];
+};
+
+static struct usb_device_id itmtouch_ids [] = {
+ { USB_DEVICE(USB_VENDOR_ID_ITMINC, USB_PRODUCT_ID_TOUCHPANEL) },
+ { }
+};
+
+static void itmtouch_irq(struct urb *urb, struct pt_regs *regs)
+{
+ struct itmtouch_dev * itmtouch = urb->context;
+ unsigned char *data = urb->transfer_buffer;
+ struct input_dev *dev = &itmtouch->inputdev;
+ int retval;
+
+ switch (urb->status) {
+ case 0:
+ /* success */
+ break;
+ case -ETIMEDOUT:
+ /* this urb is timing out */
+ dbg("%s - urb timed out - was the device unplugged?",
+ __FUNCTION__);
+ return;
+ case -ECONNRESET:
+ case -ENOENT:
+ case -ESHUTDOWN:
+ /* this urb is terminated, clean up */
+ dbg("%s - urb shutting down with status: %d",
+ __FUNCTION__, urb->status);
+ return;
+ default:
+ dbg("%s - nonzero urb status received: %d",
+ __FUNCTION__, urb->status);
+ goto exit;
+ }
+
+ input_regs(dev, regs);
+
+ /* if pressure has been released, then don't report X/Y */
+ if (data[7] & 0x20) {
+ input_report_abs(dev, ABS_X, (data[0] & 0x1F) << 7 | (data[3] & 0x7F));
+ input_report_abs(dev, ABS_Y, (data[1] & 0x1F) << 7 | (data[4] & 0x7F));
+ }
+
+ input_report_abs(dev, ABS_PRESSURE, (data[2] & 1) << 7 | (data[5] & 0x7F));
+ input_report_key(dev, BTN_TOUCH, ~data[7] & 0x20);
+ input_sync(dev);
+
+exit:
+ retval = usb_submit_urb (urb, GFP_ATOMIC);
+ if (retval)
+ printk(KERN_ERR "%s - usb_submit_urb failed with result: %d",
+ __FUNCTION__, retval);
+}
+
+static int itmtouch_open(struct input_dev *input)
+{
+ struct itmtouch_dev *itmtouch = input->private;
+
+ if (itmtouch->users++)
+ return 0;
+
+ itmtouch->readurb->dev = itmtouch->usbdev;
+
+ if (usb_submit_urb(itmtouch->readurb, GFP_KERNEL))
+ {
+ itmtouch->users--;
+ return -EIO;
+ }
+
+ return 0;
+}
+
+static void itmtouch_close(struct input_dev *input)
+{
+ struct itmtouch_dev *itmtouch = input->private;
+
+ if (!--itmtouch->users)
+ usb_kill_urb(itmtouch->readurb);
+}
+
+static int itmtouch_probe(struct usb_interface *intf, const struct usb_device_id *id)
+{
+ struct itmtouch_dev *itmtouch;
+ struct usb_host_interface *interface;
+ struct usb_endpoint_descriptor *endpoint;
+ struct usb_device *udev = interface_to_usbdev(intf);
+ unsigned int pipe;
+ unsigned int maxp;
+ char path[PATH_SIZE];
+
+ interface = intf->cur_altsetting;
+ endpoint = &interface->endpoint[0].desc;
+
+ if (!(itmtouch = kcalloc(1, sizeof(struct itmtouch_dev), GFP_KERNEL))) {
+ err("%s - Out of memory.", __FUNCTION__);
+ return -ENOMEM;
+ }
+
+ itmtouch->usbdev = udev;
+
+ itmtouch->inputdev.private = itmtouch;
+ itmtouch->inputdev.open = itmtouch_open;
+ itmtouch->inputdev.close = itmtouch_close;
+
+ usb_make_path(udev, path, PATH_SIZE);
+
+ itmtouch->inputdev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
+ itmtouch->inputdev.absbit[0] = BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE);
+ itmtouch->inputdev.keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
+
+ itmtouch->inputdev.name = itmtouch->name;
+ itmtouch->inputdev.phys = itmtouch->phys;
+ itmtouch->inputdev.id.bustype = BUS_USB;
+ itmtouch->inputdev.id.vendor = udev->descriptor.idVendor;
+ itmtouch->inputdev.id.product = udev->descriptor.idProduct;
+ itmtouch->inputdev.id.version = udev->descriptor.bcdDevice;
+ itmtouch->inputdev.dev = &intf->dev;
+
+ if (!strlen(itmtouch->name))
+ sprintf(itmtouch->name, "USB ITM touchscreen");
+
+ /* device limits */
+ /* as specified by the ITM datasheet, X and Y are 12bit,
+ * Z (pressure) is 8 bit. However, the fields are defined up
+ * to 14 bits for future possible expansion.
+ */
+ input_set_abs_params(&itmtouch->inputdev, ABS_X, 0, 0x0FFF, 2, 0);
+ input_set_abs_params(&itmtouch->inputdev, ABS_Y, 0, 0x0FFF, 2, 0);
+ input_set_abs_params(&itmtouch->inputdev, ABS_PRESSURE, 0, 0xFF, 2, 0);
+
+ /* initialise the URB so we can read from the transport stream */
+ pipe = usb_rcvintpipe(itmtouch->usbdev, endpoint->bEndpointAddress);
+ maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
+
+ if (maxp > ITM_BUFSIZE)
+ maxp = ITM_BUFSIZE;
+
+ itmtouch->readurb = usb_alloc_urb(0, GFP_KERNEL);
+
+ if (!itmtouch->readurb) {
+ dbg("%s - usb_alloc_urb failed: itmtouch->readurb", __FUNCTION__);
+ kfree(itmtouch);
+ return -ENOMEM;
+ }
+
+ usb_fill_int_urb(itmtouch->readurb,
+ itmtouch->usbdev,
+ pipe,
+ itmtouch->rbuf,
+ maxp,
+ itmtouch_irq,
+ itmtouch,
+ endpoint->bInterval);
+
+ input_register_device(&itmtouch->inputdev);
+
+ printk(KERN_INFO "itmtouch: %s registered on %s\n", itmtouch->name, path);
+ usb_set_intfdata(intf, itmtouch);
+
+ return 0;
+}
+
+static void itmtouch_disconnect(struct usb_interface *intf)
+{
+ struct itmtouch_dev *itmtouch = usb_get_intfdata(intf);
+
+ usb_set_intfdata(intf, NULL);
+
+ if (itmtouch) {
+ input_unregister_device(&itmtouch->inputdev);
+ usb_kill_urb(itmtouch->readurb);
+ usb_free_urb(itmtouch->readurb);
+ kfree(itmtouch);
+ }
+}
+
+MODULE_DEVICE_TABLE(usb, itmtouch_ids);
+
+static struct usb_driver itmtouch_driver = {
+ .owner = THIS_MODULE,
+ .name = "itmtouch",
+ .probe = itmtouch_probe,
+ .disconnect = itmtouch_disconnect,
+ .id_table = itmtouch_ids,
+};
+
+static int __init itmtouch_init(void)
+{
+ info(DRIVER_DESC " " DRIVER_VERSION);
+ info(DRIVER_AUTHOR);
+ return usb_register(&itmtouch_driver);
+}
+
+static void __exit itmtouch_exit(void)
+{
+ usb_deregister(&itmtouch_driver);
+}
+
+module_init(itmtouch_init);
+module_exit(itmtouch_exit);



--
Vojtech Pavlik
SuSE Labs, SuSE CR