2005-01-19 21:19:46

by Richard Koch

[permalink] [raw]
Subject: [PATCH] adding the ICS MK712 touchscreen driver to 2.6

Please include the patch below to bring the ICS MK712 touchscreen controller
support, which is in kernel 2.4, in to kernel 2.6.

This patch was constructed and applied to kernel version 2.6.10 and tested
successfully on several Gateway AOL Connected Touchpad computers.

This was based on the mk712.c 2.4.28 version. No functional changes applied
only minor
changes to conform to the 2.6 build structure. I choose to place the driver
under
input/touchscreen as this seemed most appropriate.

By making a contribution to this project, I certify that:

The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file.

Signed-off-by: Rick Koch <[email protected]>

patch also available at: http://home.comcast.net/~n1gp/mk712_2.6_patch


===========================================


diff -upN -X dontdiff linux-2.6.10/drivers/input/touchscreen/Kconfig
linux-2.6.10.mk712/drivers/input/touchscreen/Kconfig
--- linux-2.6.10/drivers/input/touchscreen/Kconfig 2004-12-24
16:34:45.000000000 -0500
+++ linux-2.6.10.mk712/drivers/input/touchscreen/Kconfig 2005-01-18
15:30:49.000000000 -0500
@@ -35,3 +35,15 @@ config TOUCHSCREEN_GUNZE
To compile this driver as a module, choose M here: the
module will be called gunze.

+config TOUCHSCREEN_MK712
+ tristate "ICS Mk712 touchscreen controller chip support"
+ depends on INPUT && INPUT_TOUCHSCREEN
+ help
+ Say Y here if you have the ICS Mk712 touchscreen controller
+ chip in your system.
+
+ If unsure, say N.
+
+ To compile this driver as a module, choose M here: the
+ module will be called mk712.
+
diff -upN -X dontdiff linux-2.6.10/drivers/input/touchscreen/Makefile
linux-2.6.10.mk712/drivers/input/touchscreen/Makefile
--- linux-2.6.10/drivers/input/touchscreen/Makefile 2004-12-24
16:35:28.000000000 -0500
+++ linux-2.6.10.mk712/drivers/input/touchscreen/Makefile 2005-01-18
15:42:43.000000000 -0500
@@ -6,3 +6,4 @@

obj-$(CONFIG_TOUCHSCREEN_BITSY) += h3600_ts_input.o
obj-$(CONFIG_TOUCHSCREEN_GUNZE) += gunze.o
+obj-$(CONFIG_TOUCHSCREEN_MK712) += mk712.o
diff -upN -X dontdiff linux-2.6.10/drivers/input/touchscreen/mk712.c
linux-2.6.10.mk712/drivers/input/touchscreen/mk712.c
--- linux-2.6.10/drivers/input/touchscreen/mk712.c 1969-12-31
19:00:00.000000000 -0500
+++ linux-2.6.10.mk712/drivers/input/touchscreen/mk712.c 2005-01-18
17:45:56.000000000 -0500
@@ -0,0 +1,507 @@
+/* -*- c -*- --------------------------------------------------------- *
+ *
+ * linux/drivers/char/mk712.c
+ *
+ * Copyright 1999-2002 Transmeta Corporation
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
+ *
+ * This driver supports the MK712 touch screen.
+ * based on busmouse.c, pc_keyb.c, and other mouse drivers
+ *
+ * 1999-12-18: original version, Daniel Quinlan
+ * 1999-12-19: added anti-jitter code, report pen-up events, fixed
mk712_poll
+ * to use queue_empty, Nathan Laredo
+ * 1999-12-20: improved random point rejection, Nathan Laredo
+ * 2000-01-05: checked in new anti-jitter code, changed mouse protocol,
fixed
+ * queue code, added module options, other fixes, Daniel
Quinlan
+ * 2002-03-15: Clean up for kernel merge <[email protected]>
+ * Fixed multi open race, fixed memory checks, fixed resource
+ * allocation, fixed close/powerdown bug, switched to new init
+ * 2005-01-18: Ported to 2.6 from 2.4.28, Rick Koch
+ *
+ *
------------------------------------------------------------------------- */
+
+#include <linux/module.h>
+
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/init.h>
+#include <linux/signal.h>
+#include <linux/errno.h>
+#include <linux/mm.h>
+#include <linux/poll.h>
+#include <linux/miscdevice.h>
+#include <linux/random.h>
+#include <linux/delay.h>
+#include <linux/ioport.h>
+#include <linux/slab.h>
+#include <linux/interrupt.h>
+
+#include <asm/io.h>
+#include <asm/uaccess.h>
+#include <asm/system.h>
+#include <asm/irq.h>
+
+#define DEBUG(x) x
+#define SQUARE(x) ((x)*(x))
+
+#define MK712_DEFAULT_IO 0x260 /* demo board: 0x200, 0x208, 0x300 */
+#define MK712_DEFAULT_IRQ 10 /* demo board: 10, 12, 14 or 15 */
+
+/* eight 8-bit registers */
+#define MK712_STATUS_LOW 0 /* READ */
+#define MK712_STATUS_HIGH 1 /* READ */
+#define MK712_X_LOW 2 /* READ */
+#define MK712_X_HIGH 3 /* READ */
+#define MK712_Y_LOW 4 /* READ */
+#define MK712_Y_HIGH 5 /* READ */
+#define MK712_CONTROL 6 /* R/W */
+#define MK712_RATE 7 /* R/W */
+
+/* status */
+#define MK712_STATUS_TOUCH 0x10
+#define MK712_CONVERSION_COMPLETE 0x80
+
+#define MK712_ENABLE_INT 0x01 /* enable interrupts */
+#define MK712_INT_ON_CONVERSION_COMPLETE 0x02 /* if bit 0 = 1 */
+#define MK712_INT_ON_CHANGE_IN_TOUCH_STATUS_A 0x04 /* if bit 0 = 1 */
+#define MK712_INT_ON_CHANGE_IN_TOUCH_STATUS_B 0x08 /* if bit 0 = 1 */
+#define MK712_ENABLE_PERIODIC_CONVERSIONS 0x10
+#define MK712_READ_ONE_POINT 0x20
+#define MK712_POWERDOWN_A 0x40
+#define MK712_POWERDOWN_B 0x80
+
+#define MK712_BUF_SIZE 256 /* a page */
+
+struct mk712_packet {
+ unsigned int header;
+ unsigned int x;
+ unsigned int y;
+ unsigned int reserved;
+};
+
+struct mk712_queue {
+ unsigned long head;
+ unsigned long tail;
+ wait_queue_head_t proc_list;
+ struct fasync_struct *fasync;
+ struct mk712_packet buf[256];
+};
+
+#ifdef MODULE
+static int io = 0;
+static int irq = 0;
+#endif
+static int mk712_io = MK712_DEFAULT_IO;
+static int mk712_irq = MK712_DEFAULT_IRQ;
+static int mk712_users = 0;
+static spinlock_t mk712_lock = SPIN_LOCK_UNLOCKED;
+static struct mk712_queue *queue; /* mouse data buffer */
+
+static struct mk712_packet get_from_queue(void)
+{
+ struct mk712_packet result;
+ unsigned long flags;
+
+ spin_lock_irqsave(&mk712_lock, flags);
+ result = queue->buf[queue->tail];
+ queue->tail = (queue->tail + 1) & (MK712_BUF_SIZE-1);
+ spin_unlock_irqrestore(&mk712_lock, flags);
+ return result;
+}
+
+static inline int queue_empty(void)
+{
+ return queue->head == queue->tail;
+}
+
+static int mk712_fasync(int fd, struct file *filp, int on)
+{
+ int retval;
+
+ retval = fasync_helper(fd, filp, on, &queue->fasync);
+ if (retval < 0)
+ return retval;
+ return 0;
+}
+
+static void mk712_output_packet(struct mk712_packet data)
+{
+ int head = queue->head;
+
+ queue->buf[head] = data;
+ head = (head + 1) & (MK712_BUF_SIZE-1);
+ if (head != queue->tail) {
+ queue->head = head;
+ kill_fasync(&queue->fasync, SIGIO, POLL_IN);
+ wake_up_interruptible(&queue->proc_list);
+ }
+}
+
+static int points = 0; /* number of stored points */
+static int output_point = 0; /* did I output a point since last release?
*/
+
+static void mk712_output_point(int x, int y)
+{
+ struct mk712_packet t;
+
+ t.header = 0;
+ t.x = x;
+ t.y = y;
+ t.reserved = 0;
+
+ mk712_output_packet(t);
+ output_point = 1;
+}
+
+static void mk712_store_point(int x_new, int y_new)
+{
+ static int x[3], y[3];
+ int x_out, y_out;
+
+ x[points] = x_new;
+ y[points] = y_new;
+
+ if (points == 1 && abs(x[0] - x[1]) < 88 && abs(y[0] - y[1]) < 88)
+ {
+ x_out = (x[0] + x[1]) >> 1;
+ y_out = (y[0] + y[1]) >> 1;
+ mk712_output_point(x_out, y_out);
+ }
+
+ if (points == 2) {
+ if ((abs(x[1] - x[2]) < 88 && abs(y[1] - y[2]) < 88) &&
+ (abs(x[0] - x[1]) < 88 && abs(y[0] - y[1]) < 88))
+ {
+ x_out = (x[0] + x[1] + x[2]) / 3;
+ y_out = (y[0] + y[1] + y[2]) / 3;
+ mk712_output_point(x_out, y_out);
+ }
+ else if (abs(x[1] - x[2]) < 88 && abs(y[1] - y[2]) < 88)
+ {
+ x_out = (x[1] + x[2]) >> 1;
+ y_out = (y[1] + y[2]) >> 1;
+ mk712_output_point(x_out, y_out);
+ }
+ else
+ {
+ int x_avg, y_avg, d0, d1, d2;
+
+ x_avg = (x[0] + x[1] + x[2]) / 3;
+ y_avg = (y[0] + y[1] + y[2]) / 3;
+
+ d0 = SQUARE(x[0] - x_avg) + SQUARE(y[0] - y_avg);
+ d1 = SQUARE(x[1] - x_avg) + SQUARE(y[1] - y_avg);
+ d2 = SQUARE(x[2] - x_avg) + SQUARE(y[2] - y_avg);
+
+ if (d2 > d1 && d2 > d0)
+ {
+ x_out = (x[0] + x[1]) >> 1;
+ y_out = (y[0] + y[1]) >> 1;
+ }
+ if (d1 > d0 && d1 > d2)
+ {
+ x_out = (x[0] + x[2]) >> 1;
+ y_out = (y[0] + y[2]) >> 1;
+ }
+ else
+ {
+ x_out = (x[1] + x[2]) >> 1;
+ y_out = (y[1] + y[2]) >> 1;
+ }
+
+ mk712_output_point(x_out, y_out);
+
+ x[0] = x[1];
+ x[1] = x[2];
+ y[0] = y[1];
+ y[1] = y[2];
+ }
+ }
+ else
+ {
+ points++;
+ }
+}
+
+static void mk712_release_event(void)
+{
+ struct mk712_packet t;
+
+ if (!output_point) {
+ points = 0;
+ return;
+ }
+ output_point = 0;
+
+ t.header = 1;
+ t.x = t.y = t.reserved = 0;
+
+ mk712_output_packet(t);
+ points = 0;
+}
+
+#define MK712_FILTER
+static irqreturn_t mk712_interrupt(int irq, void *dev_id, struct pt_regs
*regs)
+{
+ unsigned short x;
+ unsigned short y;
+ unsigned char status;
+ unsigned long flags;
+#ifdef MK712_FILTER
+ static int drop_next = 1;
+#endif
+
+ spin_lock_irqsave(&mk712_lock, flags);
+
+ status = inb(mk712_io + MK712_STATUS_LOW);
+
+ if (!(status & MK712_CONVERSION_COMPLETE)) {
+#ifdef MK712_FILTER
+ drop_next = 1;
+#endif
+ return IRQ_HANDLED;
+ }
+ if (!(status & MK712_STATUS_TOUCH)) /* release event */
+ {
+#ifdef MK712_FILTER
+ drop_next = 1;
+#endif
+ mk712_release_event();
+
+ spin_unlock_irqrestore(&mk712_lock, flags);
+ wake_up_interruptible(&queue->proc_list);
+
+ return IRQ_HANDLED;
+ }
+
+ x = inw(mk712_io + MK712_X_LOW) & 0x0fff;
+ y = inw(mk712_io + MK712_Y_LOW) & 0x0fff;
+
+#ifdef MK712_FILTER
+ if (drop_next)
+ {
+ drop_next = 0;
+
+ spin_unlock_irqrestore(&mk712_lock, flags);
+ wake_up_interruptible(&queue->proc_list);
+
+ return IRQ_HANDLED;
+ }
+#endif
+
+ x = inw(mk712_io + MK712_X_LOW) & 0x0fff;
+ y = inw(mk712_io + MK712_Y_LOW) & 0x0fff;
+
+ mk712_store_point(x, y);
+
+ spin_unlock_irqrestore(&mk712_lock, flags);
+ wake_up_interruptible(&queue->proc_list);
+ return IRQ_HANDLED;
+}
+
+static int mk712_open(struct inode *inode, struct file *file)
+{
+ unsigned char control;
+ unsigned long flags;
+
+ control = 0;
+
+ spin_lock_irqsave(&mk712_lock, flags);
+ if(!mk712_users++)
+ {
+ outb(0, mk712_io + MK712_CONTROL);
+
+ control |= (MK712_ENABLE_INT |
+ MK712_INT_ON_CONVERSION_COMPLETE |
+ MK712_INT_ON_CHANGE_IN_TOUCH_STATUS_B |
+ MK712_ENABLE_PERIODIC_CONVERSIONS |
+ MK712_POWERDOWN_A);
+ outb(control, mk712_io + MK712_CONTROL);
+
+ outb(10, mk712_io + MK712_RATE); /* default count = 10 */
+
+ queue->head = queue->tail = 0; /* Flush input queue */
+ }
+ spin_unlock_irqrestore(&mk712_lock, flags);
+ return 0;
+}
+
+static int mk712_close(struct inode * inode, struct file * file) {
+ /* power down controller */
+ unsigned long flags;
+ spin_lock_irqsave(&mk712_lock, flags);
+ if(--mk712_users==0)
+ outb(0, mk712_io + MK712_CONTROL);
+ spin_unlock_irqrestore(&mk712_lock, flags);
+ return 0;
+}
+
+static unsigned int mk712_poll(struct file *file, poll_table *wait)
+{
+ poll_wait(file, &queue->proc_list, wait);
+ if(!queue_empty())
+ return POLLIN | POLLRDNORM;
+ return 0;
+}
+
+static int mk712_ioctl(struct inode *inode, struct file * file,
+ unsigned int cmd, unsigned long arg)
+{
+ if (!inode)
+ BUG();
+ return -ENOTTY;
+}
+
+
+static ssize_t mk712_read(struct file *file, char *buffer,
+ size_t count, loff_t *pos)
+{
+ DECLARE_WAITQUEUE(wait, current);
+ ssize_t bytes_read = 0;
+ struct mk712_packet p;
+
+ /* wait for an event */
+ if (queue_empty()) {
+ if (file->f_flags & O_NONBLOCK)
+ return -EAGAIN;
+ add_wait_queue(&queue->proc_list, &wait);
+repeat:
+ set_current_state(TASK_INTERRUPTIBLE);
+ if (queue_empty() && !signal_pending(current)) {
+ schedule();
+ goto repeat;
+ }
+ current->state = TASK_RUNNING;
+ remove_wait_queue(&queue->proc_list, &wait);
+ }
+
+ while (bytes_read < count && !queue_empty()) {
+ p = get_from_queue();
+ if (copy_to_user (buffer+bytes_read, (void *) &p, sizeof(p)))
+ {
+ bytes_read = -EFAULT;
+ break;
+ }
+ bytes_read += sizeof(p);
+ }
+
+ if (bytes_read > 0)
+ {
+ file->f_dentry->d_inode->i_atime = CURRENT_TIME;
+ return bytes_read;
+ }
+
+ if (signal_pending(current))
+ return -ERESTARTSYS;
+
+ return bytes_read;
+}
+
+static ssize_t mk712_write(struct file *file, const char *buffer, size_t
count,
+ loff_t *ppos)
+{
+ return -EINVAL;
+}
+
+struct file_operations mk712_fops = {
+ owner: THIS_MODULE,
+ read: mk712_read,
+ write: mk712_write,
+ poll: mk712_poll,
+ ioctl: mk712_ioctl,
+ open: mk712_open,
+ release: mk712_close,
+ fasync: mk712_fasync,
+};
+
+static struct miscdevice mk712_touchscreen = {
+ MK712_MINOR, "mk712_touchscreen", &mk712_fops
+};
+
+int __init mk712_init(void)
+{
+#ifdef MODULE
+ if (io)
+ mk712_io = io;
+ if (irq)
+ mk712_irq = irq;
+#endif
+
+ if(!request_region(mk712_io, 8, "mk712_touchscreen"))
+ {
+ printk("mk712: unable to get IO region\n");
+ return -ENODEV;
+ }
+
+ /* set up wait queue */
+ queue = (struct mk712_queue *) kmalloc(sizeof(*queue), GFP_KERNEL);
+ if(queue == NULL)
+ {
+ release_region(mk712_io, 8);
+ return -ENOMEM;
+ }
+ memset(queue, 0, sizeof(*queue));
+ queue->head = queue->tail = 0;
+ init_waitqueue_head(&queue->proc_list);
+
+ /* The MK712 is ISA and hard-coded to a particular IRQ, so the
+ driver should keep the IRQ as long as it is loaded. */
+ if(request_irq(mk712_irq, mk712_interrupt, 0, "mk712_touchscreen",
+ queue))
+ {
+ printk("mk712: unable to get IRQ\n");
+ release_region(mk712_io, 8);
+ kfree(queue);
+ return -EBUSY;
+ }
+
+ /* register misc device */
+ if(misc_register(&mk712_touchscreen)<0)
+ {
+ release_region(mk712_io, 8);
+ kfree(queue);
+ free_irq(mk712_irq, queue);
+ return -ENODEV;
+ }
+ return 0;
+}
+
+static void __exit mk712_exit(void)
+{
+ misc_deregister(&mk712_touchscreen);
+ release_region(mk712_io, 8);
+ free_irq(mk712_irq, queue);
+ kfree(queue);
+ printk(KERN_INFO "mk712 touchscreen uninstalled\n");
+}
+
+MODULE_AUTHOR("Daniel Quinlan");
+MODULE_DESCRIPTION("MK712 touch screen driver");
+MODULE_PARM(io, "i");
+MODULE_PARM_DESC(io, "I/O base address of MK712 touch screen controller");
+MODULE_PARM(irq, "i");
+MODULE_PARM_DESC(irq, "IRQ of MK712 touch screen controller");
+MODULE_LICENSE("GPL");
+
+module_init(mk712_init);
+module_exit(mk712_exit);
+
+/*
+ * Local variables:
+ * c-file-style: "linux"
+ * End:
+ */
diff -upN -X dontdiff linux-2.6.10/include/linux/miscdevice.h
linux-2.6.10.mk712/include/linux/miscdevice.h
--- linux-2.6.10/include/linux/miscdevice.h 2004-12-24 16:34:58.000000000
-0500
+++ linux-2.6.10.mk712/include/linux/miscdevice.h 2005-01-18
11:27:59.000000000 -0500
@@ -12,6 +12,7 @@
#define APOLLO_MOUSE_MINOR 7
#define PC110PAD_MINOR 9
/*#define ADB_MOUSE_MINOR 10 FIXME OBSOLETE */
+#define MK712_MINOR 15 /* MK712 touch screen */
#define WATCHDOG_MINOR 130 /* Watchdog timer */
#define TEMP_MINOR 131 /* Temperature Sensor */
#define RTC_MINOR 135



2005-01-20 18:08:57

by Dmitry Torokhov

[permalink] [raw]
Subject: Re: [PATCH] adding the ICS MK712 touchscreen driver to 2.6

On Wed, 19 Jan 2005 16:18:49 -0500, Richard Koch <[email protected]> wrote:
> Please include the patch below to bring the ICS MK712 touchscreen controller
> support, which is in kernel 2.4, in to kernel 2.6.
>
> This patch was constructed and applied to kernel version 2.6.10 and tested
> successfully on several Gateway AOL Connected Touchpad computers.
>
> This was based on the mk712.c 2.4.28 version. No functional changes applied
> only minor
> changes to conform to the 2.6 build structure. I choose to place the driver
> under
> input/touchscreen as this seemed most appropriate.
>

Hi,

I think that the driver should be integrated into 2.6 input system
before merging it into the kernel so touchscreen data can be accessed
through standard interfaces (evdev, mousedev, tsdev) without the need
for a special device.

Also MODULE_PARM is obsolete and shoudl be repleced with module_param().

--
Dmitry

2005-02-05 19:33:49

by Vojtech Pavlik

[permalink] [raw]
Subject: Re: [PATCH] adding the ICS MK712 touchscreen driver to 2.6

On Wed, Jan 19, 2005 at 04:18:49PM -0500, Richard Koch wrote:
> Please include the patch below to bring the ICS MK712 touchscreen controller
> support, which is in kernel 2.4, in to kernel 2.6.
>
> This patch was constructed and applied to kernel version 2.6.10 and tested
> successfully on several Gateway AOL Connected Touchpad computers.
>
> This was based on the mk712.c 2.4.28 version. No functional changes applied
> only minor
> changes to conform to the 2.6 build structure. I choose to place the driver
> under
> input/touchscreen as this seemed most appropriate.
>
> By making a contribution to this project, I certify that:
>
> The contribution is based upon previous work that, to the best
> of my knowledge, is covered under an appropriate open source
> license and I have the right under that license to submit that
> work with modifications, whether created in whole or in part
> by me, under the same open source license (unless I am
> permitted to submit under a different license), as indicated
> in the file.
>
> Signed-off-by: Rick Koch <[email protected]>
>
> patch also available at: http://home.comcast.net/~n1gp/mk712_2.6_patch

Can you re-do the patch to be a proper input device instead of a misc
device driver? Then I'll gladly accept it.

> ===========================================
>
>
> diff -upN -X dontdiff linux-2.6.10/drivers/input/touchscreen/Kconfig
> linux-2.6.10.mk712/drivers/input/touchscreen/Kconfig
> --- linux-2.6.10/drivers/input/touchscreen/Kconfig 2004-12-24
> 16:34:45.000000000 -0500
> +++ linux-2.6.10.mk712/drivers/input/touchscreen/Kconfig 2005-01-18
> 15:30:49.000000000 -0500
> @@ -35,3 +35,15 @@ config TOUCHSCREEN_GUNZE
> To compile this driver as a module, choose M here: the
> module will be called gunze.
>
> +config TOUCHSCREEN_MK712
> + tristate "ICS Mk712 touchscreen controller chip support"
> + depends on INPUT && INPUT_TOUCHSCREEN
> + help
> + Say Y here if you have the ICS Mk712 touchscreen controller
> + chip in your system.
> +
> + If unsure, say N.
> +
> + To compile this driver as a module, choose M here: the
> + module will be called mk712.
> +
> diff -upN -X dontdiff linux-2.6.10/drivers/input/touchscreen/Makefile
> linux-2.6.10.mk712/drivers/input/touchscreen/Makefile
> --- linux-2.6.10/drivers/input/touchscreen/Makefile 2004-12-24
> 16:35:28.000000000 -0500
> +++ linux-2.6.10.mk712/drivers/input/touchscreen/Makefile 2005-01-18
> 15:42:43.000000000 -0500
> @@ -6,3 +6,4 @@
>
> obj-$(CONFIG_TOUCHSCREEN_BITSY) += h3600_ts_input.o
> obj-$(CONFIG_TOUCHSCREEN_GUNZE) += gunze.o
> +obj-$(CONFIG_TOUCHSCREEN_MK712) += mk712.o
> diff -upN -X dontdiff linux-2.6.10/drivers/input/touchscreen/mk712.c
> linux-2.6.10.mk712/drivers/input/touchscreen/mk712.c
> --- linux-2.6.10/drivers/input/touchscreen/mk712.c 1969-12-31
> 19:00:00.000000000 -0500
> +++ linux-2.6.10.mk712/drivers/input/touchscreen/mk712.c 2005-01-18
> 17:45:56.000000000 -0500
> @@ -0,0 +1,507 @@
> +/* -*- c -*- --------------------------------------------------------- *
> + *
> + * linux/drivers/char/mk712.c
> + *
> + * Copyright 1999-2002 Transmeta Corporation
> + *
> + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
> USA
> + *
> + * This driver supports the MK712 touch screen.
> + * based on busmouse.c, pc_keyb.c, and other mouse drivers
> + *
> + * 1999-12-18: original version, Daniel Quinlan
> + * 1999-12-19: added anti-jitter code, report pen-up events, fixed
> mk712_poll
> + * to use queue_empty, Nathan Laredo
> + * 1999-12-20: improved random point rejection, Nathan Laredo
> + * 2000-01-05: checked in new anti-jitter code, changed mouse protocol,
> fixed
> + * queue code, added module options, other fixes, Daniel
> Quinlan
> + * 2002-03-15: Clean up for kernel merge <[email protected]>
> + * Fixed multi open race, fixed memory checks, fixed resource
> + * allocation, fixed close/powerdown bug, switched to new init
> + * 2005-01-18: Ported to 2.6 from 2.4.28, Rick Koch
> + *
> + *
> ------------------------------------------------------------------------- */
> +
> +#include <linux/module.h>
> +
> +#include <linux/kernel.h>
> +#include <linux/sched.h>
> +#include <linux/init.h>
> +#include <linux/signal.h>
> +#include <linux/errno.h>
> +#include <linux/mm.h>
> +#include <linux/poll.h>
> +#include <linux/miscdevice.h>
> +#include <linux/random.h>
> +#include <linux/delay.h>
> +#include <linux/ioport.h>
> +#include <linux/slab.h>
> +#include <linux/interrupt.h>
> +
> +#include <asm/io.h>
> +#include <asm/uaccess.h>
> +#include <asm/system.h>
> +#include <asm/irq.h>
> +
> +#define DEBUG(x) x
> +#define SQUARE(x) ((x)*(x))
> +
> +#define MK712_DEFAULT_IO 0x260 /* demo board: 0x200, 0x208,
> 0x300 */
> +#define MK712_DEFAULT_IRQ 10 /* demo board: 10, 12, 14 or 15 */
> +
> +/* eight 8-bit registers */
> +#define MK712_STATUS_LOW 0 /* READ */
> +#define MK712_STATUS_HIGH 1 /* READ */
> +#define MK712_X_LOW 2 /* READ */
> +#define MK712_X_HIGH 3 /* READ */
> +#define MK712_Y_LOW 4 /* READ */
> +#define MK712_Y_HIGH 5 /* READ */
> +#define MK712_CONTROL 6 /* R/W */
> +#define MK712_RATE 7 /* R/W */
> +
> +/* status */
> +#define MK712_STATUS_TOUCH 0x10
> +#define MK712_CONVERSION_COMPLETE 0x80
> +
> +#define MK712_ENABLE_INT 0x01 /* enable interrupts */
> +#define MK712_INT_ON_CONVERSION_COMPLETE 0x02 /* if bit 0 = 1 */
> +#define MK712_INT_ON_CHANGE_IN_TOUCH_STATUS_A 0x04 /* if bit 0 = 1 */
> +#define MK712_INT_ON_CHANGE_IN_TOUCH_STATUS_B 0x08 /* if bit 0 = 1 */
> +#define MK712_ENABLE_PERIODIC_CONVERSIONS 0x10
> +#define MK712_READ_ONE_POINT 0x20
> +#define MK712_POWERDOWN_A 0x40
> +#define MK712_POWERDOWN_B 0x80
> +
> +#define MK712_BUF_SIZE 256 /* a page */
> +
> +struct mk712_packet {
> + unsigned int header;
> + unsigned int x;
> + unsigned int y;
> + unsigned int reserved;
> +};
> +
> +struct mk712_queue {
> + unsigned long head;
> + unsigned long tail;
> + wait_queue_head_t proc_list;
> + struct fasync_struct *fasync;
> + struct mk712_packet buf[256];
> +};
> +
> +#ifdef MODULE
> +static int io = 0;
> +static int irq = 0;
> +#endif
> +static int mk712_io = MK712_DEFAULT_IO;
> +static int mk712_irq = MK712_DEFAULT_IRQ;
> +static int mk712_users = 0;
> +static spinlock_t mk712_lock = SPIN_LOCK_UNLOCKED;
> +static struct mk712_queue *queue; /* mouse data buffer */
> +
> +static struct mk712_packet get_from_queue(void)
> +{
> + struct mk712_packet result;
> + unsigned long flags;
> +
> + spin_lock_irqsave(&mk712_lock, flags);
> + result = queue->buf[queue->tail];
> + queue->tail = (queue->tail + 1) & (MK712_BUF_SIZE-1);
> + spin_unlock_irqrestore(&mk712_lock, flags);
> + return result;
> +}
> +
> +static inline int queue_empty(void)
> +{
> + return queue->head == queue->tail;
> +}
> +
> +static int mk712_fasync(int fd, struct file *filp, int on)
> +{
> + int retval;
> +
> + retval = fasync_helper(fd, filp, on, &queue->fasync);
> + if (retval < 0)
> + return retval;
> + return 0;
> +}
> +
> +static void mk712_output_packet(struct mk712_packet data)
> +{
> + int head = queue->head;
> +
> + queue->buf[head] = data;
> + head = (head + 1) & (MK712_BUF_SIZE-1);
> + if (head != queue->tail) {
> + queue->head = head;
> + kill_fasync(&queue->fasync, SIGIO, POLL_IN);
> + wake_up_interruptible(&queue->proc_list);
> + }
> +}
> +
> +static int points = 0; /* number of stored points */
> +static int output_point = 0; /* did I output a point since last
> release? */
> +
> +static void mk712_output_point(int x, int y)
> +{
> + struct mk712_packet t;
> +
> + t.header = 0;
> + t.x = x;
> + t.y = y;
> + t.reserved = 0;
> +
> + mk712_output_packet(t);
> + output_point = 1;
> +}
> +
> +static void mk712_store_point(int x_new, int y_new)
> +{
> + static int x[3], y[3];
> + int x_out, y_out;
> +
> + x[points] = x_new;
> + y[points] = y_new;
> +
> + if (points == 1 && abs(x[0] - x[1]) < 88 && abs(y[0] - y[1]) < 88)
> + {
> + x_out = (x[0] + x[1]) >> 1;
> + y_out = (y[0] + y[1]) >> 1;
> + mk712_output_point(x_out, y_out);
> + }
> +
> + if (points == 2) {
> + if ((abs(x[1] - x[2]) < 88 && abs(y[1] - y[2]) < 88) &&
> + (abs(x[0] - x[1]) < 88 && abs(y[0] - y[1]) < 88))
> + {
> + x_out = (x[0] + x[1] + x[2]) / 3;
> + y_out = (y[0] + y[1] + y[2]) / 3;
> + mk712_output_point(x_out, y_out);
> + }
> + else if (abs(x[1] - x[2]) < 88 && abs(y[1] - y[2]) < 88)
> + {
> + x_out = (x[1] + x[2]) >> 1;
> + y_out = (y[1] + y[2]) >> 1;
> + mk712_output_point(x_out, y_out);
> + }
> + else
> + {
> + int x_avg, y_avg, d0, d1, d2;
> +
> + x_avg = (x[0] + x[1] + x[2]) / 3;
> + y_avg = (y[0] + y[1] + y[2]) / 3;
> +
> + d0 = SQUARE(x[0] - x_avg) + SQUARE(y[0] - y_avg);
> + d1 = SQUARE(x[1] - x_avg) + SQUARE(y[1] - y_avg);
> + d2 = SQUARE(x[2] - x_avg) + SQUARE(y[2] - y_avg);
> +
> + if (d2 > d1 && d2 > d0)
> + {
> + x_out = (x[0] + x[1]) >> 1;
> + y_out = (y[0] + y[1]) >> 1;
> + }
> + if (d1 > d0 && d1 > d2)
> + {
> + x_out = (x[0] + x[2]) >> 1;
> + y_out = (y[0] + y[2]) >> 1;
> + }
> + else
> + {
> + x_out = (x[1] + x[2]) >> 1;
> + y_out = (y[1] + y[2]) >> 1;
> + }
> +
> + mk712_output_point(x_out, y_out);
> +
> + x[0] = x[1];
> + x[1] = x[2];
> + y[0] = y[1];
> + y[1] = y[2];
> + }
> + }
> + else
> + {
> + points++;
> + }
> +}
> +
> +static void mk712_release_event(void)
> +{
> + struct mk712_packet t;
> +
> + if (!output_point) {
> + points = 0;
> + return;
> + }
> + output_point = 0;
> +
> + t.header = 1;
> + t.x = t.y = t.reserved = 0;
> +
> + mk712_output_packet(t);
> + points = 0;
> +}
> +
> +#define MK712_FILTER
> +static irqreturn_t mk712_interrupt(int irq, void *dev_id, struct pt_regs
> *regs)
> +{
> + unsigned short x;
> + unsigned short y;
> + unsigned char status;
> + unsigned long flags;
> +#ifdef MK712_FILTER
> + static int drop_next = 1;
> +#endif
> +
> + spin_lock_irqsave(&mk712_lock, flags);
> +
> + status = inb(mk712_io + MK712_STATUS_LOW);
> +
> + if (!(status & MK712_CONVERSION_COMPLETE)) {
> +#ifdef MK712_FILTER
> + drop_next = 1;
> +#endif
> + return IRQ_HANDLED;
> + }
> + if (!(status & MK712_STATUS_TOUCH)) /* release event */
> + {
> +#ifdef MK712_FILTER
> + drop_next = 1;
> +#endif
> + mk712_release_event();
> +
> + spin_unlock_irqrestore(&mk712_lock, flags);
> + wake_up_interruptible(&queue->proc_list);
> +
> + return IRQ_HANDLED;
> + }
> +
> + x = inw(mk712_io + MK712_X_LOW) & 0x0fff;
> + y = inw(mk712_io + MK712_Y_LOW) & 0x0fff;
> +
> +#ifdef MK712_FILTER
> + if (drop_next)
> + {
> + drop_next = 0;
> +
> + spin_unlock_irqrestore(&mk712_lock, flags);
> + wake_up_interruptible(&queue->proc_list);
> +
> + return IRQ_HANDLED;
> + }
> +#endif
> +
> + x = inw(mk712_io + MK712_X_LOW) & 0x0fff;
> + y = inw(mk712_io + MK712_Y_LOW) & 0x0fff;
> +
> + mk712_store_point(x, y);
> +
> + spin_unlock_irqrestore(&mk712_lock, flags);
> + wake_up_interruptible(&queue->proc_list);
> + return IRQ_HANDLED;
> +}
> +
> +static int mk712_open(struct inode *inode, struct file *file)
> +{
> + unsigned char control;
> + unsigned long flags;
> +
> + control = 0;
> +
> + spin_lock_irqsave(&mk712_lock, flags);
> + if(!mk712_users++)
> + {
> + outb(0, mk712_io + MK712_CONTROL);
> +
> + control |= (MK712_ENABLE_INT |
> + MK712_INT_ON_CONVERSION_COMPLETE |
> + MK712_INT_ON_CHANGE_IN_TOUCH_STATUS_B |
> + MK712_ENABLE_PERIODIC_CONVERSIONS |
> + MK712_POWERDOWN_A);
> + outb(control, mk712_io + MK712_CONTROL);
> +
> + outb(10, mk712_io + MK712_RATE); /* default count = 10 */
> +
> + queue->head = queue->tail = 0; /* Flush input queue
> */
> + }
> + spin_unlock_irqrestore(&mk712_lock, flags);
> + return 0;
> +}
> +
> +static int mk712_close(struct inode * inode, struct file * file) {
> + /* power down controller */
> + unsigned long flags;
> + spin_lock_irqsave(&mk712_lock, flags);
> + if(--mk712_users==0)
> + outb(0, mk712_io + MK712_CONTROL);
> + spin_unlock_irqrestore(&mk712_lock, flags);
> + return 0;
> +}
> +
> +static unsigned int mk712_poll(struct file *file, poll_table *wait)
> +{
> + poll_wait(file, &queue->proc_list, wait);
> + if(!queue_empty())
> + return POLLIN | POLLRDNORM;
> + return 0;
> +}
> +
> +static int mk712_ioctl(struct inode *inode, struct file * file,
> + unsigned int cmd, unsigned long arg)
> +{
> + if (!inode)
> + BUG();
> + return -ENOTTY;
> +}
> +
> +
> +static ssize_t mk712_read(struct file *file, char *buffer,
> + size_t count, loff_t *pos)
> +{
> + DECLARE_WAITQUEUE(wait, current);
> + ssize_t bytes_read = 0;
> + struct mk712_packet p;
> +
> + /* wait for an event */
> + if (queue_empty()) {
> + if (file->f_flags & O_NONBLOCK)
> + return -EAGAIN;
> + add_wait_queue(&queue->proc_list, &wait);
> +repeat:
> + set_current_state(TASK_INTERRUPTIBLE);
> + if (queue_empty() && !signal_pending(current)) {
> + schedule();
> + goto repeat;
> + }
> + current->state = TASK_RUNNING;
> + remove_wait_queue(&queue->proc_list, &wait);
> + }
> +
> + while (bytes_read < count && !queue_empty()) {
> + p = get_from_queue();
> + if (copy_to_user (buffer+bytes_read, (void *) &p, sizeof(p)))
> + {
> + bytes_read = -EFAULT;
> + break;
> + }
> + bytes_read += sizeof(p);
> + }
> +
> + if (bytes_read > 0)
> + {
> + file->f_dentry->d_inode->i_atime = CURRENT_TIME;
> + return bytes_read;
> + }
> +
> + if (signal_pending(current))
> + return -ERESTARTSYS;
> +
> + return bytes_read;
> +}
> +
> +static ssize_t mk712_write(struct file *file, const char *buffer, size_t
> count,
> + loff_t *ppos)
> +{
> + return -EINVAL;
> +}
> +
> +struct file_operations mk712_fops = {
> + owner: THIS_MODULE,
> + read: mk712_read,
> + write: mk712_write,
> + poll: mk712_poll,
> + ioctl: mk712_ioctl,
> + open: mk712_open,
> + release: mk712_close,
> + fasync: mk712_fasync,
> +};
> +
> +static struct miscdevice mk712_touchscreen = {
> + MK712_MINOR, "mk712_touchscreen", &mk712_fops
> +};
> +
> +int __init mk712_init(void)
> +{
> +#ifdef MODULE
> + if (io)
> + mk712_io = io;
> + if (irq)
> + mk712_irq = irq;
> +#endif
> +
> + if(!request_region(mk712_io, 8, "mk712_touchscreen"))
> + {
> + printk("mk712: unable to get IO region\n");
> + return -ENODEV;
> + }
> +
> + /* set up wait queue */
> + queue = (struct mk712_queue *) kmalloc(sizeof(*queue), GFP_KERNEL);
> + if(queue == NULL)
> + {
> + release_region(mk712_io, 8);
> + return -ENOMEM;
> + }
> + memset(queue, 0, sizeof(*queue));
> + queue->head = queue->tail = 0;
> + init_waitqueue_head(&queue->proc_list);
> +
> + /* The MK712 is ISA and hard-coded to a particular IRQ, so the
> + driver should keep the IRQ as long as it is loaded. */
> + if(request_irq(mk712_irq, mk712_interrupt, 0, "mk712_touchscreen",
> + queue))
> + {
> + printk("mk712: unable to get IRQ\n");
> + release_region(mk712_io, 8);
> + kfree(queue);
> + return -EBUSY;
> + }
> +
> + /* register misc device */
> + if(misc_register(&mk712_touchscreen)<0)
> + {
> + release_region(mk712_io, 8);
> + kfree(queue);
> + free_irq(mk712_irq, queue);
> + return -ENODEV;
> + }
> + return 0;
> +}
> +
> +static void __exit mk712_exit(void)
> +{
> + misc_deregister(&mk712_touchscreen);
> + release_region(mk712_io, 8);
> + free_irq(mk712_irq, queue);
> + kfree(queue);
> + printk(KERN_INFO "mk712 touchscreen uninstalled\n");
> +}
> +
> +MODULE_AUTHOR("Daniel Quinlan");
> +MODULE_DESCRIPTION("MK712 touch screen driver");
> +MODULE_PARM(io, "i");
> +MODULE_PARM_DESC(io, "I/O base address of MK712 touch screen controller");
> +MODULE_PARM(irq, "i");
> +MODULE_PARM_DESC(irq, "IRQ of MK712 touch screen controller");
> +MODULE_LICENSE("GPL");
> +
> +module_init(mk712_init);
> +module_exit(mk712_exit);
> +
> +/*
> + * Local variables:
> + * c-file-style: "linux"
> + * End:
> + */
> diff -upN -X dontdiff linux-2.6.10/include/linux/miscdevice.h
> linux-2.6.10.mk712/include/linux/miscdevice.h
> --- linux-2.6.10/include/linux/miscdevice.h 2004-12-24
> 16:34:58.000000000 -0500
> +++ linux-2.6.10.mk712/include/linux/miscdevice.h 2005-01-18
> 11:27:59.000000000 -0500
> @@ -12,6 +12,7 @@
> #define APOLLO_MOUSE_MINOR 7
> #define PC110PAD_MINOR 9
> /*#define ADB_MOUSE_MINOR 10 FIXME OBSOLETE */
> +#define MK712_MINOR 15 /* MK712 touch screen */
> #define WATCHDOG_MINOR 130 /* Watchdog timer */
> #define TEMP_MINOR 131 /* Temperature Sensor */
> #define RTC_MINOR 135
>
>
>

--
Vojtech Pavlik
SuSE Labs, SuSE CR

2005-02-05 21:02:47

by Vojtech Pavlik

[permalink] [raw]
Subject: Re: [PATCH] adding the ICS MK712 touchscreen driver to 2.6

On Wed, Jan 19, 2005 at 04:18:49PM -0500, Richard Koch wrote:
> Please include the patch below to bring the ICS MK712 touchscreen controller
> support, which is in kernel 2.4, in to kernel 2.6.
>
> This patch was constructed and applied to kernel version 2.6.10 and tested
> successfully on several Gateway AOL Connected Touchpad computers.
>
> This was based on the mk712.c 2.4.28 version. No functional changes applied
> only minor
> changes to conform to the 2.6 build structure. I choose to place the driver
> under
> input/touchscreen as this seemed most appropriate.
>
> By making a contribution to this project, I certify that:
>
> The contribution is based upon previous work that, to the best
> of my knowledge, is covered under an appropriate open source
> license and I have the right under that license to submit that
> work with modifications, whether created in whole or in part
> by me, under the same open source license (unless I am
> permitted to submit under a different license), as indicated
> in the file.
>
> Signed-off-by: Rick Koch <[email protected]>
>
> patch also available at: http://home.comcast.net/~n1gp/mk712_2.6_patch

I converted it to a proper input driver for you. ;) Can you check it if
it still works?


[email protected], 2005-02-05 22:00:45+01:00, [email protected]
input: New driver for ICS MicroClock MK712 TouchScreens.

Signed-off-by: Vojtech Pavlik <[email protected]>


Kconfig | 11 +++
Makefile | 3
mk712.c | 201 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 214 insertions(+), 1 deletion(-)


diff -Nru a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig
--- a/drivers/input/touchscreen/Kconfig 2005-02-05 22:01:13 +01:00
+++ b/drivers/input/touchscreen/Kconfig 2005-02-05 22:01:13 +01:00
@@ -48,4 +48,15 @@
To compile this driver as a module, choose M here: the
module will be called gunze.

+config TOUCHSCREEN_MK712
+ tristate "ICS MicroClock MK712 touchscreen"
+ help
+ Say Y here if you have the ICS MicroClock MK712 touchscreen
+ controller chip in your system.
+
+ If unsure, say N.
+
+ To compile this driver as a module, choose M here: the
+ module will be called mk712.
+
endif
diff -Nru a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile
--- a/drivers/input/touchscreen/Makefile 2005-02-05 22:01:13 +01:00
+++ b/drivers/input/touchscreen/Makefile 2005-02-05 22:01:13 +01:00
@@ -5,5 +5,6 @@
# Each configuration option enables a list of files.

obj-$(CONFIG_TOUCHSCREEN_BITSY) += h3600_ts_input.o
-obj-$(CONFIG_TOUCHSCREEN_GUNZE) += gunze.o
obj-$(CONFIG_TOUCHSCREEN_CORGI) += corgi_ts.o
+obj-$(CONFIG_TOUCHSCREEN_GUNZE) += gunze.o
+obj-$(CONFIG_TOUCHSCREEN_MK712) += mk712.o
diff -Nru a/drivers/input/touchscreen/mk712.c b/drivers/input/touchscreen/mk712.c
--- /dev/null Wed Dec 31 16:00:00 196900
+++ b/drivers/input/touchscreen/mk712.c 2005-02-05 22:01:13 +01:00
@@ -0,0 +1,201 @@
+/*
+ * ICS MK712 touchscreen controller driver
+ *
+ * Copyright (c) 1999-2002 Transmeta Corporation
+ * Copyright (c) 2005 Rick Koch <[email protected]>
+ * Copyright (c) 2005 Vojtech Pavlik <[email protected]>
+ */
+
+/*
+ * 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.
+ */
+
+/*
+ * This driver supports the ICS MicroClock MK712 TouchScreen controller,
+ * found in Gateway AOL Connected Touchpad computers.
+ *
+ * Documentation for ICS MK712 can be found at:
+ * http://www.icst.com/pdf/mk712.pdf
+ */
+
+/*
+ * 1999-12-18: original version, Daniel Quinlan
+ * 1999-12-19: added anti-jitter code, report pen-up events, fixed mk712_poll
+ * to use queue_empty, Nathan Laredo
+ * 1999-12-20: improved random point rejection, Nathan Laredo
+ * 2000-01-05: checked in new anti-jitter code, changed mouse protocol, fixed
+ * queue code, added module options, other fixes, Daniel Quinlan
+ * 2002-03-15: Clean up for kernel merge <[email protected]>
+ * Fixed multi open race, fixed memory checks, fixed resource
+ * allocation, fixed close/powerdown bug, switched to new init
+ * 2005-01-18: Ported to 2.6 from 2.4.28, Rick Koch
+ * 2005-02-05: Rewritten for the input layer, Vojtech Pavlik
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/errno.h>
+#include <linux/delay.h>
+#include <linux/ioport.h>
+#include <linux/interrupt.h>
+#include <linux/input.h>
+#include <asm/io.h>
+
+MODULE_AUTHOR("Daniel Quinlan <[email protected]>, Vojtech Pavlik <[email protected]>");
+MODULE_DESCRIPTION("ICS MicroClock MK712 TouchScreen driver");
+MODULE_LICENSE("GPL");
+
+static unsigned int mk712_io = 0x260; /* Also 0x200, 0x208, 0x300 */
+module_param_named(io, mk712_io, uint, 0);
+MODULE_PARM_DESC(io, "I/O base address of MK712 touchscreen controller");
+
+static unsigned int mk712_irq = 10; /* Also 12, 14, 15 */
+module_param_named(irq, mk712_irq, uint, 0);
+MODULE_PARM_DESC(irq, "IRQ of MK712 touchscreen controller");
+
+/* eight 8-bit registers */
+#define MK712_STATUS 0
+#define MK712_X 2
+#define MK712_Y 4
+#define MK712_CONTROL 6
+#define MK712_RATE 7
+
+/* status */
+#define MK712_STATUS_TOUCH 0x10
+#define MK712_CONVERSION_COMPLETE 0x80
+
+/* control */
+#define MK712_ENABLE_INT 0x01
+#define MK712_INT_ON_CONVERSION_COMPLETE 0x02
+#define MK712_INT_ON_CHANGE_IN_TOUCH_STATUS 0x04
+#define MK712_ENABLE_PERIODIC_CONVERSIONS 0x10
+#define MK712_READ_ONE_POINT 0x20
+#define MK712_POWERDOWN 0x40
+
+static int mk712_used = 0;
+static struct input_dev mk712_dev;
+
+static irqreturn_t mk712_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+{
+ unsigned char status;
+ static int debounce = 1;
+ static unsigned short last_x;
+ static unsigned short last_y;
+
+ input_regs(&mk712_dev, regs);
+
+ status = inb(mk712_io + MK712_STATUS);
+
+ if (~status & MK712_CONVERSION_COMPLETE) {
+ debounce = 1;
+ goto end;
+ }
+
+ if (~status & MK712_STATUS_TOUCH)
+ {
+ debounce = 1;
+ input_report_key(&mk712_dev, BTN_TOUCH, 0);
+ goto end;
+ }
+
+ if (debounce)
+ {
+ debounce = 0;
+ goto end;
+ }
+
+ input_report_key(&mk712_dev, BTN_TOUCH, 1);
+ input_report_abs(&mk712_dev, ABS_X, last_x);
+ input_report_abs(&mk712_dev, ABS_Y, last_y);
+
+end:
+
+ last_x = inw(mk712_io + MK712_X) & 0x0fff;
+ last_y = (inw(mk712_io + MK712_Y) & 0x0fff) * 3 / 4;
+ input_sync(&mk712_dev);
+ return IRQ_HANDLED;
+}
+
+static int mk712_open(struct input_dev *dev)
+{
+
+ if (mk712_used++)
+ return 0;
+
+ outb(0, mk712_io + MK712_CONTROL); /* Reset */
+
+ outb(MK712_ENABLE_INT | MK712_INT_ON_CONVERSION_COMPLETE |
+ MK712_INT_ON_CHANGE_IN_TOUCH_STATUS |
+ MK712_ENABLE_PERIODIC_CONVERSIONS |
+ MK712_POWERDOWN, mk712_io + MK712_CONTROL);
+
+ outb(10, mk712_io + MK712_RATE); /* 187 points per second */
+
+ return 0;
+}
+
+static void mk712_close(struct input_dev *dev)
+{
+ if (--mk712_used)
+ return;
+
+ outb(0, mk712_io + MK712_CONTROL);
+}
+
+static struct input_dev mk712_dev = {
+ .evbit = { BIT(EV_KEY) | BIT(EV_ABS) },
+ .keybit = { [LONG(BTN_LEFT)] = BIT(BTN_TOUCH) },
+ .absbit = { BIT(ABS_X) | BIT(ABS_Y) },
+ .open = mk712_open,
+ .close = mk712_close,
+ .name = "ICS MicroClock MK712 TouchScreen",
+ .phys = "isa0260/input0",
+ .absmin = { [ABS_X] = 0, [ABS_Y] = 0 },
+ .absmax = { [ABS_X] = 0xfff, [ABS_Y] = 0xbff },
+ .absfuzz = { [ABS_X] = 88, [ABS_Y] = 88 },
+ .id = {
+ .bustype = BUS_ISA,
+ .vendor = 0x0005,
+ .product = 0x0001,
+ .version = 0x0100,
+ },
+};
+
+int __init mk712_init(void)
+{
+
+ if(!request_region(mk712_io, 8, "mk712"))
+ {
+ printk(KERN_WARNING "mk712: unable to get IO region\n");
+ return -ENODEV;
+ }
+
+ if(request_irq(mk712_irq, mk712_interrupt, 0, "mk712", &mk712_dev))
+ {
+ printk(KERN_WARNING "mk712: unable to get IRQ\n");
+ release_region(mk712_io, 8);
+ return -EBUSY;
+ }
+
+ input_register_device(&mk712_dev);
+
+ printk(KERN_INFO "input: ICS MicroClock MK712 TouchScreen at %#x irq %d\n", mk712_io, mk712_irq);
+
+ return 0;
+}
+
+static void __exit mk712_exit(void)
+{
+ input_unregister_device(&mk712_dev);
+ free_irq(mk712_irq, &mk712_dev);
+ release_region(mk712_io, 8);
+}
+
+
+module_init(mk712_init);
+module_exit(mk712_exit);


--
Vojtech Pavlik
SuSE Labs, SuSE CR

2005-02-05 23:00:53

by Dmitry Torokhov

[permalink] [raw]
Subject: Re: [PATCH] adding the ICS MK712 touchscreen driver to 2.6

On Saturday 05 February 2005 16:02, Vojtech Pavlik wrote:
v> On Wed, Jan 19, 2005 at 04:18:49PM -0500, Richard Koch wrote:
> > Please include the patch below to bring the ICS MK712 touchscreen controller
> > support, which is in kernel 2.4, in to kernel 2.6.
> >
> > This patch was constructed and applied to kernel version 2.6.10 and tested
> > successfully on several Gateway AOL Connected Touchpad computers.
> >
> > This was based on the mk712.c 2.4.28 version. No functional changes applied
> > only minor
> > changes to conform to the 2.6 build structure. I choose to place the driver
> > under
> > input/touchscreen as this seemed most appropriate.
> >
> > By making a contribution to this project, I certify that:
> >
> > The contribution is based upon previous work that, to the best
> > of my knowledge, is covered under an appropriate open source
> > license and I have the right under that license to submit that
> > work with modifications, whether created in whole or in part
> > by me, under the same open source license (unless I am
> > permitted to submit under a different license), as indicated
> > in the file.
> >
> > Signed-off-by: Rick Koch <[email protected]>
> >
> > patch also available at: http://home.comcast.net/~n1gp/mk712_2.6_patch
>
> I converted it to a proper input driver for you. ;) Can you check it if
> it still works?
>
> +static irqreturn_t mk712_interrupt(int irq, void *dev_id, struct pt_regs *regs)
> +{
> + unsigned char status;
> + static int debounce = 1;
> + static unsigned short last_x;
> + static unsigned short last_y;
> +
> + input_regs(&mk712_dev, regs);
> +
> + status = inb(mk712_io + MK712_STATUS);
> +
> + if (~status & MK712_CONVERSION_COMPLETE) {
> + debounce = 1;
> + goto end;
> + }
> +
> + if (~status & MK712_STATUS_TOUCH)
> + {
> + debounce = 1;
> + input_report_key(&mk712_dev, BTN_TOUCH, 0);
> + goto end;
> + }
> +
> + if (debounce)
> + {
> + debounce = 0;
> + goto end;
> + }
> +
> + input_report_key(&mk712_dev, BTN_TOUCH, 1);
> + input_report_abs(&mk712_dev, ABS_X, last_x);
> + input_report_abs(&mk712_dev, ABS_Y, last_y);

Severe TAB vs. space damage...

> +static int mk712_open(struct input_dev *dev)
> +{
> +
> + if (mk712_used++)
> + return 0;
> +
> + outb(0, mk712_io + MK712_CONTROL); /* Reset */
> +

We really should stop ignoring races and locking issues. Atomic perhaps?


--
Dmitry

2005-02-06 09:28:44

by Vojtech Pavlik

[permalink] [raw]
Subject: Re: [PATCH] adding the ICS MK712 touchscreen driver to 2.6

On Sat, Feb 05, 2005 at 06:00:33PM -0500, Dmitry Torokhov wrote:

> > I converted it to a proper input driver for you. ;) Can you check it if
> > it still works?
> >
> > +static irqreturn_t mk712_interrupt(int irq, void *dev_id, struct pt_regs *regs)
> > +{
> > + unsigned char status;
> > + static int debounce = 1;
> > + static unsigned short last_x;
> > + static unsigned short last_y;
> > +
> > + input_regs(&mk712_dev, regs);
> > +
> > + status = inb(mk712_io + MK712_STATUS);
> > +
> > + if (~status & MK712_CONVERSION_COMPLETE) {
> > + debounce = 1;
> > + goto end;
> > + }
> > +
> > + if (~status & MK712_STATUS_TOUCH)
> > + {
> > + debounce = 1;
> > + input_report_key(&mk712_dev, BTN_TOUCH, 0);
> > + goto end;
> > + }
> > +
> > + if (debounce)
> > + {
> > + debounce = 0;
> > + goto end;
> > + }
> > +
> > + input_report_key(&mk712_dev, BTN_TOUCH, 1);
> > + input_report_abs(&mk712_dev, ABS_X, last_x);
> > + input_report_abs(&mk712_dev, ABS_Y, last_y);
>
> Severe TAB vs. space damage...
>
> > +static int mk712_open(struct input_dev *dev)
> > +{
> > +
> > + if (mk712_used++)
> > + return 0;
> > +
> > + outb(0, mk712_io + MK712_CONTROL); /* Reset */
> > +
>
> We really should stop ignoring races and locking issues. Atomic perhaps?

You're right, as usual. ;) How about this one? The spinlock also
protects from concurrent hardware register access. I'm always surprised
how much code the input API saves when converting a driver ...

[email protected], 2005-02-06 10:13:52+01:00, [email protected]
input: New driver for ICS MicroClock MK712 TouchScreens.

Signed-off-by: Vojtech Pavlik <[email protected]>


Kconfig | 11 +++
Makefile | 3
mk712.c | 222 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 235 insertions(+), 1 deletion(-)


diff -Nru a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig
--- a/drivers/input/touchscreen/Kconfig 2005-02-06 10:24:14 +01:00
+++ b/drivers/input/touchscreen/Kconfig 2005-02-06 10:24:14 +01:00
@@ -48,4 +48,15 @@
To compile this driver as a module, choose M here: the
module will be called gunze.

+config TOUCHSCREEN_MK712
+ tristate "ICS MicroClock MK712 touchscreen"
+ help
+ Say Y here if you have the ICS MicroClock MK712 touchscreen
+ controller chip in your system.
+
+ If unsure, say N.
+
+ To compile this driver as a module, choose M here: the
+ module will be called mk712.
+
endif
diff -Nru a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile
--- a/drivers/input/touchscreen/Makefile 2005-02-06 10:24:14 +01:00
+++ b/drivers/input/touchscreen/Makefile 2005-02-06 10:24:14 +01:00
@@ -5,5 +5,6 @@
# Each configuration option enables a list of files.

obj-$(CONFIG_TOUCHSCREEN_BITSY) += h3600_ts_input.o
-obj-$(CONFIG_TOUCHSCREEN_GUNZE) += gunze.o
obj-$(CONFIG_TOUCHSCREEN_CORGI) += corgi_ts.o
+obj-$(CONFIG_TOUCHSCREEN_GUNZE) += gunze.o
+obj-$(CONFIG_TOUCHSCREEN_MK712) += mk712.o
diff -Nru a/drivers/input/touchscreen/mk712.c b/drivers/input/touchscreen/mk712.c
--- /dev/null Wed Dec 31 16:00:00 196900
+++ b/drivers/input/touchscreen/mk712.c 2005-02-06 10:24:14 +01:00
@@ -0,0 +1,222 @@
+/*
+ * ICS MK712 touchscreen controller driver
+ *
+ * Copyright (c) 1999-2002 Transmeta Corporation
+ * Copyright (c) 2005 Rick Koch <[email protected]>
+ * Copyright (c) 2005 Vojtech Pavlik <[email protected]>
+ */
+
+/*
+ * 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.
+ */
+
+/*
+ * This driver supports the ICS MicroClock MK712 TouchScreen controller,
+ * found in Gateway AOL Connected Touchpad computers.
+ *
+ * Documentation for ICS MK712 can be found at:
+ * http://www.icst.com/pdf/mk712.pdf
+ */
+
+/*
+ * 1999-12-18: original version, Daniel Quinlan
+ * 1999-12-19: added anti-jitter code, report pen-up events, fixed mk712_poll
+ * to use queue_empty, Nathan Laredo
+ * 1999-12-20: improved random point rejection, Nathan Laredo
+ * 2000-01-05: checked in new anti-jitter code, changed mouse protocol, fixed
+ * queue code, added module options, other fixes, Daniel Quinlan
+ * 2002-03-15: Clean up for kernel merge <[email protected]>
+ * Fixed multi open race, fixed memory checks, fixed resource
+ * allocation, fixed close/powerdown bug, switched to new init
+ * 2005-01-18: Ported to 2.6 from 2.4.28, Rick Koch
+ * 2005-02-05: Rewritten for the input layer, Vojtech Pavlik
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/errno.h>
+#include <linux/delay.h>
+#include <linux/ioport.h>
+#include <linux/interrupt.h>
+#include <linux/input.h>
+#include <asm/io.h>
+
+MODULE_AUTHOR("Daniel Quinlan <[email protected]>, Vojtech Pavlik <[email protected]>");
+MODULE_DESCRIPTION("ICS MicroClock MK712 TouchScreen driver");
+MODULE_LICENSE("GPL");
+
+static unsigned int mk712_io = 0x260; /* Also 0x200, 0x208, 0x300 */
+module_param_named(io, mk712_io, uint, 0);
+MODULE_PARM_DESC(io, "I/O base address of MK712 touchscreen controller");
+
+static unsigned int mk712_irq = 10; /* Also 12, 14, 15 */
+module_param_named(irq, mk712_irq, uint, 0);
+MODULE_PARM_DESC(irq, "IRQ of MK712 touchscreen controller");
+
+/* eight 8-bit registers */
+#define MK712_STATUS 0
+#define MK712_X 2
+#define MK712_Y 4
+#define MK712_CONTROL 6
+#define MK712_RATE 7
+
+/* status */
+#define MK712_STATUS_TOUCH 0x10
+#define MK712_CONVERSION_COMPLETE 0x80
+
+/* control */
+#define MK712_ENABLE_INT 0x01
+#define MK712_INT_ON_CONVERSION_COMPLETE 0x02
+#define MK712_INT_ON_CHANGE_IN_TOUCH_STATUS 0x04
+#define MK712_ENABLE_PERIODIC_CONVERSIONS 0x10
+#define MK712_READ_ONE_POINT 0x20
+#define MK712_POWERUP 0x40
+
+static int mk712_used = 0;
+static struct input_dev mk712_dev;
+static DEFINE_SPINLOCK(mk712_lock);
+
+static irqreturn_t mk712_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+{
+ unsigned char status;
+ static int debounce = 1;
+ static unsigned short last_x;
+ static unsigned short last_y;
+
+ spin_lock(&mk712_lock);
+ input_regs(&mk712_dev, regs);
+
+ status = inb(mk712_io + MK712_STATUS);
+
+ if (~status & MK712_CONVERSION_COMPLETE) {
+ debounce = 1;
+ goto end;
+ }
+
+ if (~status & MK712_STATUS_TOUCH)
+ {
+ debounce = 1;
+ input_report_key(&mk712_dev, BTN_TOUCH, 0);
+ goto end;
+ }
+
+ if (debounce)
+ {
+ debounce = 0;
+ goto end;
+ }
+
+ input_report_key(&mk712_dev, BTN_TOUCH, 1);
+ input_report_abs(&mk712_dev, ABS_X, last_x);
+ input_report_abs(&mk712_dev, ABS_Y, last_y);
+
+end:
+
+ last_x = inw(mk712_io + MK712_X) & 0x0fff;
+ last_y = (inw(mk712_io + MK712_Y) & 0x0fff) * 3 / 4;
+ input_sync(&mk712_dev);
+ spin_unlock(&mk712_lock);
+ return IRQ_HANDLED;
+}
+
+static int mk712_open(struct input_dev *dev)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&mk712_lock, flags);
+
+ if (!mk712_used++) {
+
+ outb(0, mk712_io + MK712_CONTROL); /* Reset */
+
+ outb(MK712_ENABLE_INT | MK712_INT_ON_CONVERSION_COMPLETE |
+ MK712_INT_ON_CHANGE_IN_TOUCH_STATUS |
+ MK712_ENABLE_PERIODIC_CONVERSIONS |
+ MK712_POWERUP, mk712_io + MK712_CONTROL);
+
+ outb(10, mk712_io + MK712_RATE); /* 187 points per second */
+ }
+
+ spin_unlock_irqrestore(&mk712_lock, flags);
+
+ return 0;
+}
+
+static void mk712_close(struct input_dev *dev)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&mk712_lock, flags);
+
+ if (!--mk712_used)
+ outb(0, mk712_io + MK712_CONTROL);
+
+ spin_unlock_irqrestore(&mk712_lock, flags);
+}
+
+static struct input_dev mk712_dev = {
+ .evbit = { BIT(EV_KEY) | BIT(EV_ABS) },
+ .keybit = { [LONG(BTN_LEFT)] = BIT(BTN_TOUCH) },
+ .absbit = { BIT(ABS_X) | BIT(ABS_Y) },
+ .open = mk712_open,
+ .close = mk712_close,
+ .name = "ICS MicroClock MK712 TouchScreen",
+ .phys = "isa0260/input0",
+ .absmin = { [ABS_X] = 0, [ABS_Y] = 0 },
+ .absmax = { [ABS_X] = 0xfff, [ABS_Y] = 0xbff },
+ .absfuzz = { [ABS_X] = 88, [ABS_Y] = 88 },
+ .id = {
+ .bustype = BUS_ISA,
+ .vendor = 0x0005,
+ .product = 0x0001,
+ .version = 0x0100,
+ },
+};
+
+int __init mk712_init(void)
+{
+
+ if(!request_region(mk712_io, 8, "mk712"))
+ {
+ printk(KERN_WARNING "mk712: unable to get IO region\n");
+ return -ENODEV;
+ }
+
+ outb(0, mk712_io + MK712_CONTROL);
+
+ if ((inw(mk712_io + MK712_X) & 0xf000) || /* Sanity check */
+ (inw(mk712_io + MK712_Y) & 0xf000) ||
+ (inw(mk712_io + MK712_STATUS) & 0xf333)) {
+ printk(KERN_WARNING "mk712: device not present\n");
+ release_region(mk712_io, 8);
+ return -ENODEV;
+ }
+
+ if(request_irq(mk712_irq, mk712_interrupt, 0, "mk712", &mk712_dev))
+ {
+ printk(KERN_WARNING "mk712: unable to get IRQ\n");
+ release_region(mk712_io, 8);
+ return -EBUSY;
+ }
+
+ input_register_device(&mk712_dev);
+
+ printk(KERN_INFO "input: ICS MicroClock MK712 TouchScreen at %#x irq %d\n", mk712_io, mk712_irq);
+
+ return 0;
+}
+
+static void __exit mk712_exit(void)
+{
+ input_unregister_device(&mk712_dev);
+ free_irq(mk712_irq, &mk712_dev);
+ release_region(mk712_io, 8);
+}
+
+module_init(mk712_init);
+module_exit(mk712_exit);

--
Vojtech Pavlik
SuSE Labs, SuSE CR

2005-02-06 17:53:26

by Dmitry Torokhov

[permalink] [raw]
Subject: Re: [PATCH] adding the ICS MK712 touchscreen driver to 2.6

On Sunday 06 February 2005 04:25, Vojtech Pavlik wrote:
> You're right, as usual. ;) How about this one? The spinlock also
> protects from concurrent hardware register access. I'm always surprised
> how much code the input API saves when converting a driver ...
>

Yep, this looks much better.

--
Dmitry

2005-02-11 15:51:12

by Richard Koch

[permalink] [raw]
Subject: Re: [PATCH] adding the ICS MK712 touchscreen driver to 2.6

Hello again,

Thanks for the evtest.c program and the information about evtouch. After the
minor change from LONG(BTN_LEFT) to LONG(BTN_TOUCH), patch below, I
was able to then get touch on/off events. Also I tested this driver with the
"evtouch" Xwindows driver and it worked nicely.

Thanks,
Rick Koch

================== PATCH START ===================

--- linux-2.6.10.nopatches/drivers/input/touchscreen/mk712.c 2005-02-11
10:36:36.000000000 -0500
+++ linux-2.6.10/drivers/input/touchscreen/mk712.c 2005-02-11
10:34:33.000000000 -0500
@@ -161,7 +161,7 @@ static void mk712_close(struct input_dev

static struct input_dev mk712_dev = {
.evbit = { BIT(EV_KEY) | BIT(EV_ABS) },
- .keybit = { [LONG(BTN_LEFT)] = BIT(BTN_TOUCH) },
+ .keybit = { [LONG(BTN_TOUCH)] = BIT(BTN_TOUCH) },
.absbit = { BIT(ABS_X) | BIT(ABS_Y) },
.open = mk712_open,
.close = mk712_close,

===================PATCH END====================

> > >From: Vojtech Pavlik > >To: Dmitry Torokhov > >CC:
>[email protected],Richard Koch , >
> >[email protected] > >Subject: Re: [PATCH] adding the ICS MK712
>touchscreen driver to 2.6 > >Date: Sun, 6 Feb 2005 10:25:33 +0100 > > > >On
>Sat, Feb 05, 2005 at 06:00:33PM -0500, Dmitry Torokhov wrote: > > > >> > I
>converted it to a proper input driver for you. ;) Can you check it > >if it
>still works?
>
>--
>Vojtech Pavlik SuSE Labs, SuSE CR


2005-02-11 16:08:46

by Vojtech Pavlik

[permalink] [raw]
Subject: Re: [PATCH] adding the ICS MK712 touchscreen driver to 2.6

On Fri, Feb 11, 2005 at 10:50:19AM -0500, Richard Koch wrote:

> Thanks for the evtest.c program and the information about evtouch. After the
> minor change from LONG(BTN_LEFT) to LONG(BTN_TOUCH), patch below, I
> was able to then get touch on/off events. Also I tested this driver with the
> "evtouch" Xwindows driver and it worked nicely.

Thanks a lot for testing and for the fix!

--
Vojtech Pavlik
SuSE Labs, SuSE CR