7d12e780e0
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead of passing regs around manually through all ~1800 interrupt handlers in the Linux kernel. The regs pointer is used in few places, but it potentially costs both stack space and code to pass it around. On the FRV arch, removing the regs parameter from all the genirq function results in a 20% speed up of the IRQ exit path (ie: from leaving timer_interrupt() to leaving do_IRQ()). Where appropriate, an arch may override the generic storage facility and do something different with the variable. On FRV, for instance, the address is maintained in GR28 at all times inside the kernel as part of general exception handling. Having looked over the code, it appears that the parameter may be handed down through up to twenty or so layers of functions. Consider a USB character device attached to a USB hub, attached to a USB controller that posts its interrupts through a cascaded auxiliary interrupt controller. A character device driver may want to pass regs to the sysrq handler through the input layer which adds another few layers of parameter passing. I've build this code with allyesconfig for x86_64 and i386. I've runtested the main part of the code on FRV and i386, though I can't test most of the drivers. I've also done partial conversion for powerpc and MIPS - these at least compile with minimal configurations. This will affect all archs. Mostly the changes should be relatively easy. Take do_IRQ(), store the regs pointer at the beginning, saving the old one: struct pt_regs *old_regs = set_irq_regs(regs); And put the old one back at the end: set_irq_regs(old_regs); Don't pass regs through to generic_handle_irq() or __do_IRQ(). In timer_interrupt(), this sort of change will be necessary: - update_process_times(user_mode(regs)); - profile_tick(CPU_PROFILING, regs); + update_process_times(user_mode(get_irq_regs())); + profile_tick(CPU_PROFILING); I'd like to move update_process_times()'s use of get_irq_regs() into itself, except that i386, alone of the archs, uses something other than user_mode(). Some notes on the interrupt handling in the drivers: (*) input_dev() is now gone entirely. The regs pointer is no longer stored in the input_dev struct. (*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does something different depending on whether it's been supplied with a regs pointer or not. (*) Various IRQ handler function pointers have been moved to type irq_handler_t. Signed-Off-By: David Howells <dhowells@redhat.com> (cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
393 lines
9.8 KiB
C
393 lines
9.8 KiB
C
/******************************************************************************
|
|
* touchkitusb.c -- Driver for eGalax TouchKit USB Touchscreens
|
|
*
|
|
* Copyright (C) 2004-2005 by Daniel Ritz <daniel.ritz@gmx.ch>
|
|
* Copyright (C) by Todd E. Johnson (mtouchusb.c)
|
|
*
|
|
* 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 mtouchusb.c
|
|
*
|
|
*****************************************************************************/
|
|
|
|
//#define DEBUG
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/module.h>
|
|
#include <linux/init.h>
|
|
#include <linux/usb/input.h>
|
|
|
|
#define TOUCHKIT_MIN_XC 0x0
|
|
#define TOUCHKIT_MAX_XC 0x07ff
|
|
#define TOUCHKIT_XC_FUZZ 0x0
|
|
#define TOUCHKIT_XC_FLAT 0x0
|
|
#define TOUCHKIT_MIN_YC 0x0
|
|
#define TOUCHKIT_MAX_YC 0x07ff
|
|
#define TOUCHKIT_YC_FUZZ 0x0
|
|
#define TOUCHKIT_YC_FLAT 0x0
|
|
#define TOUCHKIT_REPORT_DATA_SIZE 16
|
|
|
|
#define TOUCHKIT_DOWN 0x01
|
|
|
|
#define TOUCHKIT_PKT_TYPE_MASK 0xFE
|
|
#define TOUCHKIT_PKT_TYPE_REPT 0x80
|
|
#define TOUCHKIT_PKT_TYPE_DIAG 0x0A
|
|
|
|
#define DRIVER_VERSION "v0.1"
|
|
#define DRIVER_AUTHOR "Daniel Ritz <daniel.ritz@gmx.ch>"
|
|
#define DRIVER_DESC "eGalax TouchKit USB HID Touchscreen Driver"
|
|
|
|
static int swap_xy;
|
|
module_param(swap_xy, bool, 0644);
|
|
MODULE_PARM_DESC(swap_xy, "If set X and Y axes are swapped.");
|
|
|
|
struct touchkit_usb {
|
|
unsigned char *data;
|
|
dma_addr_t data_dma;
|
|
char buffer[TOUCHKIT_REPORT_DATA_SIZE];
|
|
int buf_len;
|
|
struct urb *irq;
|
|
struct usb_device *udev;
|
|
struct input_dev *input;
|
|
char name[128];
|
|
char phys[64];
|
|
};
|
|
|
|
static struct usb_device_id touchkit_devices[] = {
|
|
{USB_DEVICE(0x3823, 0x0001)},
|
|
{USB_DEVICE(0x0123, 0x0001)},
|
|
{USB_DEVICE(0x0eef, 0x0001)},
|
|
{USB_DEVICE(0x0eef, 0x0002)},
|
|
{}
|
|
};
|
|
|
|
/* helpers to read the data */
|
|
static inline int touchkit_get_touched(char *data)
|
|
{
|
|
return (data[0] & TOUCHKIT_DOWN) ? 1 : 0;
|
|
}
|
|
|
|
static inline int touchkit_get_x(char *data)
|
|
{
|
|
return ((data[3] & 0x0F) << 7) | (data[4] & 0x7F);
|
|
}
|
|
|
|
static inline int touchkit_get_y(char *data)
|
|
{
|
|
return ((data[1] & 0x0F) << 7) | (data[2] & 0x7F);
|
|
}
|
|
|
|
|
|
/* processes one input packet. */
|
|
static void touchkit_process_pkt(struct touchkit_usb *touchkit, char *pkt)
|
|
{
|
|
int x, y;
|
|
|
|
/* only process report packets */
|
|
if ((pkt[0] & TOUCHKIT_PKT_TYPE_MASK) != TOUCHKIT_PKT_TYPE_REPT)
|
|
return;
|
|
|
|
if (swap_xy) {
|
|
y = touchkit_get_x(pkt);
|
|
x = touchkit_get_y(pkt);
|
|
} else {
|
|
x = touchkit_get_x(pkt);
|
|
y = touchkit_get_y(pkt);
|
|
}
|
|
|
|
input_report_key(touchkit->input, BTN_TOUCH, touchkit_get_touched(pkt));
|
|
input_report_abs(touchkit->input, ABS_X, x);
|
|
input_report_abs(touchkit->input, ABS_Y, y);
|
|
input_sync(touchkit->input);
|
|
}
|
|
|
|
|
|
static int touchkit_get_pkt_len(char *buf)
|
|
{
|
|
switch (buf[0] & TOUCHKIT_PKT_TYPE_MASK) {
|
|
case TOUCHKIT_PKT_TYPE_REPT:
|
|
return 5;
|
|
|
|
case TOUCHKIT_PKT_TYPE_DIAG:
|
|
return buf[1] + 2;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void touchkit_process(struct touchkit_usb *touchkit, int len)
|
|
{
|
|
char *buffer;
|
|
int pkt_len, buf_len, pos;
|
|
|
|
/* if the buffer contains data, append */
|
|
if (unlikely(touchkit->buf_len)) {
|
|
int tmp;
|
|
|
|
/* if only 1 byte in buffer, add another one to get length */
|
|
if (touchkit->buf_len == 1)
|
|
touchkit->buffer[1] = touchkit->data[0];
|
|
|
|
pkt_len = touchkit_get_pkt_len(touchkit->buffer);
|
|
|
|
/* unknown packet: drop everything */
|
|
if (!pkt_len)
|
|
return;
|
|
|
|
/* append, process */
|
|
tmp = pkt_len - touchkit->buf_len;
|
|
memcpy(touchkit->buffer + touchkit->buf_len, touchkit->data, tmp);
|
|
touchkit_process_pkt(touchkit, touchkit->buffer);
|
|
|
|
buffer = touchkit->data + tmp;
|
|
buf_len = len - tmp;
|
|
} else {
|
|
buffer = touchkit->data;
|
|
buf_len = len;
|
|
}
|
|
|
|
/* only one byte left in buffer */
|
|
if (unlikely(buf_len == 1)) {
|
|
touchkit->buffer[0] = buffer[0];
|
|
touchkit->buf_len = 1;
|
|
return;
|
|
}
|
|
|
|
/* loop over the buffer */
|
|
pos = 0;
|
|
while (pos < buf_len) {
|
|
/* get packet len */
|
|
pkt_len = touchkit_get_pkt_len(buffer + pos);
|
|
|
|
/* unknown packet: drop everything */
|
|
if (unlikely(!pkt_len))
|
|
return;
|
|
|
|
/* full packet: process */
|
|
if (likely(pkt_len <= buf_len)) {
|
|
touchkit_process_pkt(touchkit, buffer + pos);
|
|
} else {
|
|
/* incomplete packet: save in buffer */
|
|
memcpy(touchkit->buffer, buffer + pos, buf_len - pos);
|
|
touchkit->buf_len = buf_len - pos;
|
|
}
|
|
pos += pkt_len;
|
|
}
|
|
}
|
|
|
|
|
|
static void touchkit_irq(struct urb *urb)
|
|
{
|
|
struct touchkit_usb *touchkit = urb->context;
|
|
int retval;
|
|
|
|
switch (urb->status) {
|
|
case 0:
|
|
/* success */
|
|
break;
|
|
case -ETIME:
|
|
/* 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;
|
|
}
|
|
|
|
touchkit_process(touchkit, urb->actual_length);
|
|
|
|
exit:
|
|
retval = usb_submit_urb(urb, GFP_ATOMIC);
|
|
if (retval)
|
|
err("%s - usb_submit_urb failed with result: %d",
|
|
__FUNCTION__, retval);
|
|
}
|
|
|
|
static int touchkit_open(struct input_dev *input)
|
|
{
|
|
struct touchkit_usb *touchkit = input->private;
|
|
|
|
touchkit->irq->dev = touchkit->udev;
|
|
|
|
if (usb_submit_urb(touchkit->irq, GFP_ATOMIC))
|
|
return -EIO;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void touchkit_close(struct input_dev *input)
|
|
{
|
|
struct touchkit_usb *touchkit = input->private;
|
|
|
|
usb_kill_urb(touchkit->irq);
|
|
}
|
|
|
|
static int touchkit_alloc_buffers(struct usb_device *udev,
|
|
struct touchkit_usb *touchkit)
|
|
{
|
|
touchkit->data = usb_buffer_alloc(udev, TOUCHKIT_REPORT_DATA_SIZE,
|
|
SLAB_ATOMIC, &touchkit->data_dma);
|
|
|
|
if (!touchkit->data)
|
|
return -1;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void touchkit_free_buffers(struct usb_device *udev,
|
|
struct touchkit_usb *touchkit)
|
|
{
|
|
if (touchkit->data)
|
|
usb_buffer_free(udev, TOUCHKIT_REPORT_DATA_SIZE,
|
|
touchkit->data, touchkit->data_dma);
|
|
}
|
|
|
|
static int touchkit_probe(struct usb_interface *intf,
|
|
const struct usb_device_id *id)
|
|
{
|
|
struct touchkit_usb *touchkit;
|
|
struct input_dev *input_dev;
|
|
struct usb_host_interface *interface;
|
|
struct usb_endpoint_descriptor *endpoint;
|
|
struct usb_device *udev = interface_to_usbdev(intf);
|
|
|
|
interface = intf->cur_altsetting;
|
|
endpoint = &interface->endpoint[0].desc;
|
|
|
|
touchkit = kzalloc(sizeof(struct touchkit_usb), GFP_KERNEL);
|
|
input_dev = input_allocate_device();
|
|
if (!touchkit || !input_dev)
|
|
goto out_free;
|
|
|
|
if (touchkit_alloc_buffers(udev, touchkit))
|
|
goto out_free;
|
|
|
|
touchkit->irq = usb_alloc_urb(0, GFP_KERNEL);
|
|
if (!touchkit->irq) {
|
|
dbg("%s - usb_alloc_urb failed: touchkit->irq", __FUNCTION__);
|
|
goto out_free_buffers;
|
|
}
|
|
|
|
touchkit->udev = udev;
|
|
touchkit->input = input_dev;
|
|
|
|
if (udev->manufacturer)
|
|
strlcpy(touchkit->name, udev->manufacturer, sizeof(touchkit->name));
|
|
|
|
if (udev->product) {
|
|
if (udev->manufacturer)
|
|
strlcat(touchkit->name, " ", sizeof(touchkit->name));
|
|
strlcat(touchkit->name, udev->product, sizeof(touchkit->name));
|
|
}
|
|
|
|
if (!strlen(touchkit->name))
|
|
snprintf(touchkit->name, sizeof(touchkit->name),
|
|
"USB Touchscreen %04x:%04x",
|
|
le16_to_cpu(udev->descriptor.idVendor),
|
|
le16_to_cpu(udev->descriptor.idProduct));
|
|
|
|
usb_make_path(udev, touchkit->phys, sizeof(touchkit->phys));
|
|
strlcpy(touchkit->phys, "/input0", sizeof(touchkit->phys));
|
|
|
|
input_dev->name = touchkit->name;
|
|
input_dev->phys = touchkit->phys;
|
|
usb_to_input_id(udev, &input_dev->id);
|
|
input_dev->cdev.dev = &intf->dev;
|
|
input_dev->private = touchkit;
|
|
input_dev->open = touchkit_open;
|
|
input_dev->close = touchkit_close;
|
|
|
|
input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
|
|
input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
|
|
input_set_abs_params(input_dev, ABS_X, TOUCHKIT_MIN_XC, TOUCHKIT_MAX_XC,
|
|
TOUCHKIT_XC_FUZZ, TOUCHKIT_XC_FLAT);
|
|
input_set_abs_params(input_dev, ABS_Y, TOUCHKIT_MIN_YC, TOUCHKIT_MAX_YC,
|
|
TOUCHKIT_YC_FUZZ, TOUCHKIT_YC_FLAT);
|
|
|
|
usb_fill_int_urb(touchkit->irq, touchkit->udev,
|
|
usb_rcvintpipe(touchkit->udev, 0x81),
|
|
touchkit->data, TOUCHKIT_REPORT_DATA_SIZE,
|
|
touchkit_irq, touchkit, endpoint->bInterval);
|
|
|
|
touchkit->irq->transfer_dma = touchkit->data_dma;
|
|
touchkit->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
|
|
|
|
input_register_device(touchkit->input);
|
|
|
|
usb_set_intfdata(intf, touchkit);
|
|
return 0;
|
|
|
|
out_free_buffers:
|
|
touchkit_free_buffers(udev, touchkit);
|
|
out_free:
|
|
input_free_device(input_dev);
|
|
kfree(touchkit);
|
|
return -ENOMEM;
|
|
}
|
|
|
|
static void touchkit_disconnect(struct usb_interface *intf)
|
|
{
|
|
struct touchkit_usb *touchkit = usb_get_intfdata(intf);
|
|
|
|
dbg("%s - called", __FUNCTION__);
|
|
|
|
if (!touchkit)
|
|
return;
|
|
|
|
dbg("%s - touchkit is initialized, cleaning up", __FUNCTION__);
|
|
usb_set_intfdata(intf, NULL);
|
|
usb_kill_urb(touchkit->irq);
|
|
input_unregister_device(touchkit->input);
|
|
usb_free_urb(touchkit->irq);
|
|
touchkit_free_buffers(interface_to_usbdev(intf), touchkit);
|
|
kfree(touchkit);
|
|
}
|
|
|
|
MODULE_DEVICE_TABLE(usb, touchkit_devices);
|
|
|
|
static struct usb_driver touchkit_driver = {
|
|
.name = "touchkitusb",
|
|
.probe = touchkit_probe,
|
|
.disconnect = touchkit_disconnect,
|
|
.id_table = touchkit_devices,
|
|
};
|
|
|
|
static int __init touchkit_init(void)
|
|
{
|
|
return usb_register(&touchkit_driver);
|
|
}
|
|
|
|
static void __exit touchkit_cleanup(void)
|
|
{
|
|
usb_deregister(&touchkit_driver);
|
|
}
|
|
|
|
module_init(touchkit_init);
|
|
module_exit(touchkit_cleanup);
|
|
|
|
MODULE_AUTHOR(DRIVER_AUTHOR);
|
|
MODULE_DESCRIPTION(DRIVER_DESC);
|
|
MODULE_LICENSE("GPL");
|