2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1999-2001 Vojtech Pavlik
|
|
|
|
*
|
|
|
|
* USB HIDBP Mouse support
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
2005-05-29 14:29:01 +07:00
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
2005-04-17 05:20:36 +07:00
|
|
|
* (at your option) any later version.
|
2005-05-29 14:29:01 +07:00
|
|
|
*
|
2005-04-17 05:20:36 +07:00
|
|
|
* 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.
|
2005-05-29 14:29:01 +07:00
|
|
|
*
|
2005-04-17 05:20:36 +07:00
|
|
|
* 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
|
2005-05-29 14:29:01 +07:00
|
|
|
*
|
2005-04-17 05:20:36 +07:00
|
|
|
* Should you need to contact me, the author, you can do so either by
|
|
|
|
* e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
|
|
|
|
* Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
2006-06-14 00:04:34 +07:00
|
|
|
#include <linux/usb/input.h>
|
2007-02-22 04:51:25 +07:00
|
|
|
#include <linux/hid.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-06-19 04:36:49 +07:00
|
|
|
/* for apple IDs */
|
|
|
|
#ifdef CONFIG_USB_HID_MODULE
|
|
|
|
#include "../hid-ids.h"
|
|
|
|
#endif
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* Version Information
|
|
|
|
*/
|
|
|
|
#define DRIVER_VERSION "v1.6"
|
|
|
|
#define DRIVER_AUTHOR "Vojtech Pavlik <vojtech@ucw.cz>"
|
|
|
|
#define DRIVER_DESC "USB HID Boot Protocol mouse driver"
|
|
|
|
#define DRIVER_LICENSE "GPL"
|
|
|
|
|
|
|
|
MODULE_AUTHOR(DRIVER_AUTHOR);
|
|
|
|
MODULE_DESCRIPTION(DRIVER_DESC);
|
|
|
|
MODULE_LICENSE(DRIVER_LICENSE);
|
|
|
|
|
|
|
|
struct usb_mouse {
|
|
|
|
char name[128];
|
|
|
|
char phys[64];
|
|
|
|
struct usb_device *usbdev;
|
2005-09-15 14:01:47 +07:00
|
|
|
struct input_dev *dev;
|
2005-04-17 05:20:36 +07:00
|
|
|
struct urb *irq;
|
|
|
|
|
|
|
|
signed char *data;
|
|
|
|
dma_addr_t data_dma;
|
|
|
|
};
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
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)
2006-10-05 20:55:46 +07:00
|
|
|
static void usb_mouse_irq(struct urb *urb)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
struct usb_mouse *mouse = urb->context;
|
|
|
|
signed char *data = mouse->data;
|
2005-09-15 14:01:47 +07:00
|
|
|
struct input_dev *dev = mouse->dev;
|
2005-04-17 05:20:36 +07:00
|
|
|
int status;
|
|
|
|
|
|
|
|
switch (urb->status) {
|
|
|
|
case 0: /* success */
|
|
|
|
break;
|
|
|
|
case -ECONNRESET: /* unlink */
|
|
|
|
case -ENOENT:
|
|
|
|
case -ESHUTDOWN:
|
|
|
|
return;
|
|
|
|
/* -EPIPE: should clear the halt */
|
|
|
|
default: /* error */
|
|
|
|
goto resubmit;
|
|
|
|
}
|
|
|
|
|
|
|
|
input_report_key(dev, BTN_LEFT, data[0] & 0x01);
|
|
|
|
input_report_key(dev, BTN_RIGHT, data[0] & 0x02);
|
|
|
|
input_report_key(dev, BTN_MIDDLE, data[0] & 0x04);
|
|
|
|
input_report_key(dev, BTN_SIDE, data[0] & 0x08);
|
|
|
|
input_report_key(dev, BTN_EXTRA, data[0] & 0x10);
|
|
|
|
|
|
|
|
input_report_rel(dev, REL_X, data[1]);
|
|
|
|
input_report_rel(dev, REL_Y, data[2]);
|
|
|
|
input_report_rel(dev, REL_WHEEL, data[3]);
|
|
|
|
|
|
|
|
input_sync(dev);
|
|
|
|
resubmit:
|
2006-12-07 11:33:16 +07:00
|
|
|
status = usb_submit_urb (urb, GFP_ATOMIC);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (status)
|
|
|
|
err ("can't resubmit intr, %s-%s/input0, status %d",
|
|
|
|
mouse->usbdev->bus->bus_name,
|
|
|
|
mouse->usbdev->devpath, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int usb_mouse_open(struct input_dev *dev)
|
|
|
|
{
|
2007-05-09 15:17:31 +07:00
|
|
|
struct usb_mouse *mouse = input_get_drvdata(dev);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
mouse->irq->dev = mouse->usbdev;
|
2005-05-29 14:29:38 +07:00
|
|
|
if (usb_submit_urb(mouse->irq, GFP_KERNEL))
|
2005-04-17 05:20:36 +07:00
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void usb_mouse_close(struct input_dev *dev)
|
|
|
|
{
|
2007-05-09 15:17:31 +07:00
|
|
|
struct usb_mouse *mouse = input_get_drvdata(dev);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2005-05-29 14:29:38 +07:00
|
|
|
usb_kill_urb(mouse->irq);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2005-09-15 14:01:47 +07:00
|
|
|
static int usb_mouse_probe(struct usb_interface *intf, const struct usb_device_id *id)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2005-09-15 14:01:47 +07:00
|
|
|
struct usb_device *dev = interface_to_usbdev(intf);
|
2005-04-17 05:20:36 +07:00
|
|
|
struct usb_host_interface *interface;
|
|
|
|
struct usb_endpoint_descriptor *endpoint;
|
|
|
|
struct usb_mouse *mouse;
|
2005-09-15 14:01:47 +07:00
|
|
|
struct input_dev *input_dev;
|
2005-04-17 05:20:36 +07:00
|
|
|
int pipe, maxp;
|
2007-04-04 15:40:57 +07:00
|
|
|
int error = -ENOMEM;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
interface = intf->cur_altsetting;
|
|
|
|
|
2005-05-29 14:29:01 +07:00
|
|
|
if (interface->desc.bNumEndpoints != 1)
|
2005-04-17 05:20:36 +07:00
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
endpoint = &interface->endpoint[0].desc;
|
2006-10-26 23:03:00 +07:00
|
|
|
if (!usb_endpoint_is_int_in(endpoint))
|
2005-04-17 05:20:36 +07:00
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress);
|
|
|
|
maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe));
|
|
|
|
|
2005-09-15 14:01:47 +07:00
|
|
|
mouse = kzalloc(sizeof(struct usb_mouse), GFP_KERNEL);
|
|
|
|
input_dev = input_allocate_device();
|
|
|
|
if (!mouse || !input_dev)
|
|
|
|
goto fail1;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2006-12-07 11:33:16 +07:00
|
|
|
mouse->data = usb_buffer_alloc(dev, 8, GFP_ATOMIC, &mouse->data_dma);
|
2005-09-15 14:01:47 +07:00
|
|
|
if (!mouse->data)
|
|
|
|
goto fail1;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
mouse->irq = usb_alloc_urb(0, GFP_KERNEL);
|
2005-09-15 14:01:47 +07:00
|
|
|
if (!mouse->irq)
|
|
|
|
goto fail2;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
mouse->usbdev = dev;
|
2005-09-15 14:01:47 +07:00
|
|
|
mouse->dev = input_dev;
|
|
|
|
|
|
|
|
if (dev->manufacturer)
|
|
|
|
strlcpy(mouse->name, dev->manufacturer, sizeof(mouse->name));
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2005-09-15 14:01:47 +07:00
|
|
|
if (dev->product) {
|
|
|
|
if (dev->manufacturer)
|
|
|
|
strlcat(mouse->name, " ", sizeof(mouse->name));
|
|
|
|
strlcat(mouse->name, dev->product, sizeof(mouse->name));
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2005-09-15 14:01:47 +07:00
|
|
|
if (!strlen(mouse->name))
|
|
|
|
snprintf(mouse->name, sizeof(mouse->name),
|
|
|
|
"USB HIDBP Mouse %04x:%04x",
|
|
|
|
le16_to_cpu(dev->descriptor.idVendor),
|
|
|
|
le16_to_cpu(dev->descriptor.idProduct));
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2005-09-15 14:01:47 +07:00
|
|
|
usb_make_path(dev, mouse->phys, sizeof(mouse->phys));
|
|
|
|
strlcat(mouse->phys, "/input0", sizeof(mouse->phys));
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2005-09-15 14:01:47 +07:00
|
|
|
input_dev->name = mouse->name;
|
|
|
|
input_dev->phys = mouse->phys;
|
|
|
|
usb_to_input_id(dev, &input_dev->id);
|
2007-05-09 15:17:31 +07:00
|
|
|
input_dev->dev.parent = &intf->dev;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-10-19 13:40:32 +07:00
|
|
|
input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
|
|
|
|
input_dev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) |
|
|
|
|
BIT_MASK(BTN_RIGHT) | BIT_MASK(BTN_MIDDLE);
|
|
|
|
input_dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
|
|
|
|
input_dev->keybit[BIT_WORD(BTN_MOUSE)] |= BIT_MASK(BTN_SIDE) |
|
|
|
|
BIT_MASK(BTN_EXTRA);
|
|
|
|
input_dev->relbit[0] |= BIT_MASK(REL_WHEEL);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-05-09 15:17:31 +07:00
|
|
|
input_set_drvdata(input_dev, mouse);
|
|
|
|
|
2005-09-15 14:01:47 +07:00
|
|
|
input_dev->open = usb_mouse_open;
|
|
|
|
input_dev->close = usb_mouse_close;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
usb_fill_int_urb(mouse->irq, dev, pipe, mouse->data,
|
|
|
|
(maxp > 8 ? 8 : maxp),
|
|
|
|
usb_mouse_irq, mouse, endpoint->bInterval);
|
|
|
|
mouse->irq->transfer_dma = mouse->data_dma;
|
|
|
|
mouse->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
|
|
|
|
|
2007-04-04 15:40:57 +07:00
|
|
|
error = input_register_device(mouse->dev);
|
|
|
|
if (error)
|
|
|
|
goto fail3;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
usb_set_intfdata(intf, mouse);
|
|
|
|
return 0;
|
2005-09-15 14:01:47 +07:00
|
|
|
|
2007-04-04 15:40:57 +07:00
|
|
|
fail3:
|
|
|
|
usb_free_urb(mouse->irq);
|
|
|
|
fail2:
|
|
|
|
usb_buffer_free(dev, 8, mouse->data, mouse->data_dma);
|
|
|
|
fail1:
|
|
|
|
input_free_device(input_dev);
|
2005-09-15 14:01:47 +07:00
|
|
|
kfree(mouse);
|
2007-04-04 15:40:57 +07:00
|
|
|
return error;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void usb_mouse_disconnect(struct usb_interface *intf)
|
|
|
|
{
|
|
|
|
struct usb_mouse *mouse = usb_get_intfdata (intf);
|
2005-05-29 14:29:01 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
usb_set_intfdata(intf, NULL);
|
|
|
|
if (mouse) {
|
|
|
|
usb_kill_urb(mouse->irq);
|
2005-09-15 14:01:47 +07:00
|
|
|
input_unregister_device(mouse->dev);
|
2005-04-17 05:20:36 +07:00
|
|
|
usb_free_urb(mouse->irq);
|
|
|
|
usb_buffer_free(interface_to_usbdev(intf), 8, mouse->data, mouse->data_dma);
|
|
|
|
kfree(mouse);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct usb_device_id usb_mouse_id_table [] = {
|
2007-02-22 04:51:25 +07:00
|
|
|
{ USB_INTERFACE_INFO(USB_INTERFACE_CLASS_HID, USB_INTERFACE_SUBCLASS_BOOT,
|
|
|
|
USB_INTERFACE_PROTOCOL_MOUSE) },
|
2006-09-06 07:37:21 +07:00
|
|
|
{ } /* Terminating entry */
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE (usb, usb_mouse_id_table);
|
|
|
|
|
|
|
|
static struct usb_driver usb_mouse_driver = {
|
|
|
|
.name = "usbmouse",
|
|
|
|
.probe = usb_mouse_probe,
|
|
|
|
.disconnect = usb_mouse_disconnect,
|
|
|
|
.id_table = usb_mouse_id_table,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init usb_mouse_init(void)
|
|
|
|
{
|
|
|
|
int retval = usb_register(&usb_mouse_driver);
|
2005-05-29 14:29:01 +07:00
|
|
|
if (retval == 0)
|
2008-10-12 05:14:23 +07:00
|
|
|
printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
|
|
|
|
DRIVER_DESC "\n");
|
2005-04-17 05:20:36 +07:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit usb_mouse_exit(void)
|
|
|
|
{
|
|
|
|
usb_deregister(&usb_mouse_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(usb_mouse_init);
|
|
|
|
module_exit(usb_mouse_exit);
|