2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1999-2001 Vojtech Pavlik
|
|
|
|
*
|
|
|
|
* USB HIDBP Keyboard 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 07:29:01 +00:00
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
2005-04-16 22:20:36 +00:00
|
|
|
* (at your option) any later version.
|
2005-05-29 07:29:01 +00:00
|
|
|
*
|
2005-04-16 22:20:36 +00: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 07:29:01 +00:00
|
|
|
*
|
2005-04-16 22:20:36 +00: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 07:29:01 +00:00
|
|
|
*
|
2005-04-16 22:20:36 +00: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
|
|
|
|
*/
|
|
|
|
|
2010-12-10 03:29:03 +00:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
2006-06-13 17:04:34 +00:00
|
|
|
#include <linux/usb/input.h>
|
2007-02-21 21:51:25 +00:00
|
|
|
#include <linux/hid.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Version Information
|
|
|
|
*/
|
|
|
|
#define DRIVER_VERSION ""
|
|
|
|
#define DRIVER_AUTHOR "Vojtech Pavlik <vojtech@ucw.cz>"
|
|
|
|
#define DRIVER_DESC "USB HID Boot Protocol keyboard driver"
|
|
|
|
#define DRIVER_LICENSE "GPL"
|
|
|
|
|
|
|
|
MODULE_AUTHOR(DRIVER_AUTHOR);
|
|
|
|
MODULE_DESCRIPTION(DRIVER_DESC);
|
|
|
|
MODULE_LICENSE(DRIVER_LICENSE);
|
|
|
|
|
2008-06-08 08:15:16 +00:00
|
|
|
static const unsigned char usb_kbd_keycode[256] = {
|
2005-04-16 22:20:36 +00:00
|
|
|
0, 0, 0, 0, 30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38,
|
|
|
|
50, 49, 24, 25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44, 2, 3,
|
|
|
|
4, 5, 6, 7, 8, 9, 10, 11, 28, 1, 14, 15, 57, 12, 13, 26,
|
|
|
|
27, 43, 43, 39, 40, 41, 51, 52, 53, 58, 59, 60, 61, 62, 63, 64,
|
|
|
|
65, 66, 67, 68, 87, 88, 99, 70,119,110,102,104,111,107,109,106,
|
|
|
|
105,108,103, 69, 98, 55, 74, 78, 96, 79, 80, 81, 75, 76, 77, 71,
|
|
|
|
72, 73, 82, 83, 86,127,116,117,183,184,185,186,187,188,189,190,
|
|
|
|
191,192,193,194,134,138,130,132,128,129,131,137,133,135,136,113,
|
|
|
|
115,114, 0, 0, 0,121, 0, 89, 93,124, 92, 94, 95, 0, 0, 0,
|
|
|
|
122,123, 90, 91, 85, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
29, 42, 56,125, 97, 54,100,126,164,166,165,163,161,115,114,113,
|
|
|
|
150,158,159,128,136,177,178,176,142,152,173,140
|
|
|
|
};
|
|
|
|
|
2011-11-23 10:25:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* struct usb_kbd - state of each attached keyboard
|
|
|
|
* @dev: input device associated with this keyboard
|
|
|
|
* @usbdev: usb device associated with this keyboard
|
|
|
|
* @old: data received in the past from the @irq URB representing which
|
|
|
|
* keys were pressed. By comparing with the current list of keys
|
|
|
|
* that are pressed, we are able to see key releases.
|
|
|
|
* @irq: URB for receiving a list of keys that are pressed when a
|
|
|
|
* new key is pressed or a key that was pressed is released.
|
|
|
|
* @led: URB for sending LEDs (e.g. numlock, ...)
|
|
|
|
* @newleds: data that will be sent with the @led URB representing which LEDs
|
|
|
|
should be on
|
|
|
|
* @name: Name of the keyboard. @dev's name field points to this buffer
|
|
|
|
* @phys: Physical path of the keyboard. @dev's phys field points to this
|
|
|
|
* buffer
|
|
|
|
* @new: Buffer for the @irq URB
|
|
|
|
* @cr: Control request for @led URB
|
|
|
|
* @leds: Buffer for the @led URB
|
|
|
|
* @new_dma: DMA address for @irq URB
|
|
|
|
* @leds_dma: DMA address for @led URB
|
|
|
|
* @leds_lock: spinlock that protects @leds, @newleds, and @led_urb_submitted
|
|
|
|
* @led_urb_submitted: indicates whether @led is in progress, i.e. it has been
|
|
|
|
* submitted and its completion handler has not returned yet
|
|
|
|
* without resubmitting @led
|
|
|
|
*/
|
2005-04-16 22:20:36 +00:00
|
|
|
struct usb_kbd {
|
2005-09-15 07:01:47 +00:00
|
|
|
struct input_dev *dev;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct usb_device *usbdev;
|
|
|
|
unsigned char old[8];
|
|
|
|
struct urb *irq, *led;
|
|
|
|
unsigned char newleds;
|
|
|
|
char name[128];
|
|
|
|
char phys[64];
|
|
|
|
|
|
|
|
unsigned char *new;
|
|
|
|
struct usb_ctrlrequest *cr;
|
|
|
|
unsigned char *leds;
|
|
|
|
dma_addr_t new_dma;
|
|
|
|
dma_addr_t leds_dma;
|
2011-11-23 10:25:34 +00:00
|
|
|
|
|
|
|
spinlock_t leds_lock;
|
|
|
|
bool led_urb_submitted;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
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 13:55:46 +00:00
|
|
|
static void usb_kbd_irq(struct urb *urb)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct usb_kbd *kbd = urb->context;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
switch (urb->status) {
|
|
|
|
case 0: /* success */
|
|
|
|
break;
|
|
|
|
case -ECONNRESET: /* unlink */
|
|
|
|
case -ENOENT:
|
|
|
|
case -ESHUTDOWN:
|
|
|
|
return;
|
|
|
|
/* -EPIPE: should clear the halt */
|
|
|
|
default: /* error */
|
|
|
|
goto resubmit;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 8; i++)
|
2005-09-15 07:01:47 +00:00
|
|
|
input_report_key(kbd->dev, usb_kbd_keycode[i + 224], (kbd->new[0] >> i) & 1);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
for (i = 2; i < 8; i++) {
|
|
|
|
|
|
|
|
if (kbd->old[i] > 3 && memscan(kbd->new + 2, kbd->old[i], 6) == kbd->new + 8) {
|
|
|
|
if (usb_kbd_keycode[kbd->old[i]])
|
2005-09-15 07:01:47 +00:00
|
|
|
input_report_key(kbd->dev, usb_kbd_keycode[kbd->old[i]], 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
else
|
2010-12-10 03:29:03 +00:00
|
|
|
hid_info(urb->dev,
|
|
|
|
"Unknown key (scancode %#x) released.\n",
|
|
|
|
kbd->old[i]);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (kbd->new[i] > 3 && memscan(kbd->old + 2, kbd->new[i], 6) == kbd->old + 8) {
|
|
|
|
if (usb_kbd_keycode[kbd->new[i]])
|
2005-09-15 07:01:47 +00:00
|
|
|
input_report_key(kbd->dev, usb_kbd_keycode[kbd->new[i]], 1);
|
2005-04-16 22:20:36 +00:00
|
|
|
else
|
2010-12-10 03:29:03 +00:00
|
|
|
hid_info(urb->dev,
|
|
|
|
"Unknown key (scancode %#x) released.\n",
|
|
|
|
kbd->new[i]);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-15 07:01:47 +00:00
|
|
|
input_sync(kbd->dev);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
memcpy(kbd->old, kbd->new, 8);
|
|
|
|
|
|
|
|
resubmit:
|
2006-12-07 04:33:16 +00:00
|
|
|
i = usb_submit_urb (urb, GFP_ATOMIC);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (i)
|
2010-12-10 03:29:03 +00:00
|
|
|
hid_err(urb->dev, "can't resubmit intr, %s-%s/input0, status %d",
|
|
|
|
kbd->usbdev->bus->bus_name,
|
|
|
|
kbd->usbdev->devpath, i);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2005-04-22 22:07:00 +00:00
|
|
|
static int usb_kbd_event(struct input_dev *dev, unsigned int type,
|
|
|
|
unsigned int code, int value)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2011-11-23 10:25:34 +00:00
|
|
|
unsigned long flags;
|
2007-05-09 08:17:31 +00:00
|
|
|
struct usb_kbd *kbd = input_get_drvdata(dev);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (type != EV_LED)
|
|
|
|
return -1;
|
|
|
|
|
2011-11-23 10:25:34 +00:00
|
|
|
spin_lock_irqsave(&kbd->leds_lock, flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
kbd->newleds = (!!test_bit(LED_KANA, dev->led) << 3) | (!!test_bit(LED_COMPOSE, dev->led) << 3) |
|
|
|
|
(!!test_bit(LED_SCROLLL, dev->led) << 2) | (!!test_bit(LED_CAPSL, dev->led) << 1) |
|
|
|
|
(!!test_bit(LED_NUML, dev->led));
|
|
|
|
|
2011-11-23 10:25:34 +00:00
|
|
|
if (kbd->led_urb_submitted){
|
|
|
|
spin_unlock_irqrestore(&kbd->leds_lock, flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
2011-11-23 10:25:34 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-11-23 10:25:34 +00:00
|
|
|
if (*(kbd->leds) == kbd->newleds){
|
|
|
|
spin_unlock_irqrestore(&kbd->leds_lock, flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
2011-11-23 10:25:34 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
*(kbd->leds) = kbd->newleds;
|
2011-11-23 10:25:34 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
kbd->led->dev = kbd->usbdev;
|
|
|
|
if (usb_submit_urb(kbd->led, GFP_ATOMIC))
|
2010-12-10 03:29:03 +00:00
|
|
|
pr_err("usb_submit_urb(leds) failed\n");
|
2011-11-23 10:25:34 +00:00
|
|
|
else
|
|
|
|
kbd->led_urb_submitted = true;
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&kbd->leds_lock, flags);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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 13:55:46 +00:00
|
|
|
static void usb_kbd_led(struct urb *urb)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2011-11-23 10:25:34 +00:00
|
|
|
unsigned long flags;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct usb_kbd *kbd = urb->context;
|
|
|
|
|
|
|
|
if (urb->status)
|
2010-12-10 03:29:03 +00:00
|
|
|
hid_warn(urb->dev, "led urb status %d received\n",
|
2008-10-11 22:25:51 +00:00
|
|
|
urb->status);
|
2005-05-29 07:29:01 +00:00
|
|
|
|
2011-11-23 10:25:34 +00:00
|
|
|
spin_lock_irqsave(&kbd->leds_lock, flags);
|
|
|
|
|
|
|
|
if (*(kbd->leds) == kbd->newleds){
|
|
|
|
kbd->led_urb_submitted = false;
|
|
|
|
spin_unlock_irqrestore(&kbd->leds_lock, flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
return;
|
2011-11-23 10:25:34 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
*(kbd->leds) = kbd->newleds;
|
2011-11-23 10:25:34 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
kbd->led->dev = kbd->usbdev;
|
2011-11-23 10:25:34 +00:00
|
|
|
if (usb_submit_urb(kbd->led, GFP_ATOMIC)){
|
2010-12-10 03:29:03 +00:00
|
|
|
hid_err(urb->dev, "usb_submit_urb(leds) failed\n");
|
2011-11-23 10:25:34 +00:00
|
|
|
kbd->led_urb_submitted = false;
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&kbd->leds_lock, flags);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int usb_kbd_open(struct input_dev *dev)
|
|
|
|
{
|
2007-05-09 08:17:31 +00:00
|
|
|
struct usb_kbd *kbd = input_get_drvdata(dev);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
kbd->irq->dev = kbd->usbdev;
|
2005-05-29 07:29:38 +00:00
|
|
|
if (usb_submit_urb(kbd->irq, GFP_KERNEL))
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void usb_kbd_close(struct input_dev *dev)
|
|
|
|
{
|
2007-05-09 08:17:31 +00:00
|
|
|
struct usb_kbd *kbd = input_get_drvdata(dev);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-05-29 07:29:38 +00:00
|
|
|
usb_kill_urb(kbd->irq);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int usb_kbd_alloc_mem(struct usb_device *dev, struct usb_kbd *kbd)
|
|
|
|
{
|
|
|
|
if (!(kbd->irq = usb_alloc_urb(0, GFP_KERNEL)))
|
|
|
|
return -1;
|
|
|
|
if (!(kbd->led = usb_alloc_urb(0, GFP_KERNEL)))
|
|
|
|
return -1;
|
2010-04-12 11:17:25 +00:00
|
|
|
if (!(kbd->new = usb_alloc_coherent(dev, 8, GFP_ATOMIC, &kbd->new_dma)))
|
2005-04-16 22:20:36 +00:00
|
|
|
return -1;
|
2010-03-05 20:10:17 +00:00
|
|
|
if (!(kbd->cr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_KERNEL)))
|
2005-04-16 22:20:36 +00:00
|
|
|
return -1;
|
2010-04-12 11:17:25 +00:00
|
|
|
if (!(kbd->leds = usb_alloc_coherent(dev, 1, GFP_ATOMIC, &kbd->leds_dma)))
|
2005-04-16 22:20:36 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void usb_kbd_free_mem(struct usb_device *dev, struct usb_kbd *kbd)
|
|
|
|
{
|
2006-11-08 14:35:58 +00:00
|
|
|
usb_free_urb(kbd->irq);
|
|
|
|
usb_free_urb(kbd->led);
|
2010-04-12 11:17:25 +00:00
|
|
|
usb_free_coherent(dev, 8, kbd->new, kbd->new_dma);
|
2010-03-05 20:10:17 +00:00
|
|
|
kfree(kbd->cr);
|
2010-04-12 11:17:25 +00:00
|
|
|
usb_free_coherent(dev, 1, kbd->leds, kbd->leds_dma);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2005-05-29 07:29:01 +00:00
|
|
|
static int usb_kbd_probe(struct usb_interface *iface,
|
2005-04-16 22:20:36 +00:00
|
|
|
const struct usb_device_id *id)
|
|
|
|
{
|
2005-09-15 07:01:47 +00:00
|
|
|
struct usb_device *dev = interface_to_usbdev(iface);
|
2005-04-16 22:20:36 +00:00
|
|
|
struct usb_host_interface *interface;
|
|
|
|
struct usb_endpoint_descriptor *endpoint;
|
|
|
|
struct usb_kbd *kbd;
|
2005-09-15 07:01:47 +00:00
|
|
|
struct input_dev *input_dev;
|
2005-04-16 22:20:36 +00:00
|
|
|
int i, pipe, maxp;
|
2007-04-04 08:40:57 +00:00
|
|
|
int error = -ENOMEM;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
interface = iface->cur_altsetting;
|
|
|
|
|
|
|
|
if (interface->desc.bNumEndpoints != 1)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
endpoint = &interface->endpoint[0].desc;
|
2006-10-26 16:02:59 +00:00
|
|
|
if (!usb_endpoint_is_int_in(endpoint))
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress);
|
|
|
|
maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe));
|
|
|
|
|
2005-09-15 07:01:47 +00:00
|
|
|
kbd = kzalloc(sizeof(struct usb_kbd), GFP_KERNEL);
|
|
|
|
input_dev = input_allocate_device();
|
|
|
|
if (!kbd || !input_dev)
|
|
|
|
goto fail1;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-09-15 07:01:47 +00:00
|
|
|
if (usb_kbd_alloc_mem(dev, kbd))
|
|
|
|
goto fail2;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
kbd->usbdev = dev;
|
2005-09-15 07:01:47 +00:00
|
|
|
kbd->dev = input_dev;
|
2011-11-23 10:25:34 +00:00
|
|
|
spin_lock_init(&kbd->leds_lock);
|
2005-09-15 07:01:47 +00:00
|
|
|
|
|
|
|
if (dev->manufacturer)
|
|
|
|
strlcpy(kbd->name, dev->manufacturer, sizeof(kbd->name));
|
|
|
|
|
|
|
|
if (dev->product) {
|
|
|
|
if (dev->manufacturer)
|
|
|
|
strlcat(kbd->name, " ", sizeof(kbd->name));
|
|
|
|
strlcat(kbd->name, dev->product, sizeof(kbd->name));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strlen(kbd->name))
|
|
|
|
snprintf(kbd->name, sizeof(kbd->name),
|
|
|
|
"USB HIDBP Keyboard %04x:%04x",
|
|
|
|
le16_to_cpu(dev->descriptor.idVendor),
|
|
|
|
le16_to_cpu(dev->descriptor.idProduct));
|
|
|
|
|
|
|
|
usb_make_path(dev, kbd->phys, sizeof(kbd->phys));
|
2009-11-23 16:26:38 +00:00
|
|
|
strlcat(kbd->phys, "/input0", sizeof(kbd->phys));
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-09-15 07:01:47 +00:00
|
|
|
input_dev->name = kbd->name;
|
|
|
|
input_dev->phys = kbd->phys;
|
|
|
|
usb_to_input_id(dev, &input_dev->id);
|
2007-05-09 08:17:31 +00:00
|
|
|
input_dev->dev.parent = &iface->dev;
|
|
|
|
|
|
|
|
input_set_drvdata(input_dev, kbd);
|
2005-09-15 07:01:47 +00:00
|
|
|
|
2007-10-19 06:40:32 +00:00
|
|
|
input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_LED) |
|
|
|
|
BIT_MASK(EV_REP);
|
|
|
|
input_dev->ledbit[0] = BIT_MASK(LED_NUML) | BIT_MASK(LED_CAPSL) |
|
|
|
|
BIT_MASK(LED_SCROLLL) | BIT_MASK(LED_COMPOSE) |
|
|
|
|
BIT_MASK(LED_KANA);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 255; i++)
|
2005-09-15 07:01:47 +00:00
|
|
|
set_bit(usb_kbd_keycode[i], input_dev->keybit);
|
|
|
|
clear_bit(0, input_dev->keybit);
|
2005-05-29 07:29:01 +00:00
|
|
|
|
2005-09-15 07:01:47 +00:00
|
|
|
input_dev->event = usb_kbd_event;
|
|
|
|
input_dev->open = usb_kbd_open;
|
|
|
|
input_dev->close = usb_kbd_close;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
usb_fill_int_urb(kbd->irq, dev, pipe,
|
|
|
|
kbd->new, (maxp > 8 ? 8 : maxp),
|
|
|
|
usb_kbd_irq, kbd, endpoint->bInterval);
|
|
|
|
kbd->irq->transfer_dma = kbd->new_dma;
|
|
|
|
kbd->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
|
|
|
|
|
|
|
|
kbd->cr->bRequestType = USB_TYPE_CLASS | USB_RECIP_INTERFACE;
|
|
|
|
kbd->cr->bRequest = 0x09;
|
|
|
|
kbd->cr->wValue = cpu_to_le16(0x200);
|
|
|
|
kbd->cr->wIndex = cpu_to_le16(interface->desc.bInterfaceNumber);
|
|
|
|
kbd->cr->wLength = cpu_to_le16(1);
|
|
|
|
|
|
|
|
usb_fill_control_urb(kbd->led, dev, usb_sndctrlpipe(dev, 0),
|
|
|
|
(void *) kbd->cr, kbd->leds, 1,
|
|
|
|
usb_kbd_led, kbd);
|
|
|
|
kbd->led->transfer_dma = kbd->leds_dma;
|
2010-03-05 20:10:17 +00:00
|
|
|
kbd->led->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-04-04 08:40:57 +00:00
|
|
|
error = input_register_device(kbd->dev);
|
|
|
|
if (error)
|
|
|
|
goto fail2;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
usb_set_intfdata(iface, kbd);
|
2010-04-02 17:21:58 +00:00
|
|
|
device_set_wakeup_enable(&dev->dev, 1);
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
2005-09-15 07:01:47 +00:00
|
|
|
|
2007-04-04 08:40:57 +00:00
|
|
|
fail2:
|
|
|
|
usb_kbd_free_mem(dev, kbd);
|
|
|
|
fail1:
|
|
|
|
input_free_device(input_dev);
|
2005-09-15 07:01:47 +00:00
|
|
|
kfree(kbd);
|
2007-04-04 08:40:57 +00:00
|
|
|
return error;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void usb_kbd_disconnect(struct usb_interface *intf)
|
|
|
|
{
|
|
|
|
struct usb_kbd *kbd = usb_get_intfdata (intf);
|
2005-05-29 07:29:01 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
usb_set_intfdata(intf, NULL);
|
|
|
|
if (kbd) {
|
|
|
|
usb_kill_urb(kbd->irq);
|
2005-09-15 07:01:47 +00:00
|
|
|
input_unregister_device(kbd->dev);
|
2005-04-16 22:20:36 +00:00
|
|
|
usb_kbd_free_mem(interface_to_usbdev(intf), kbd);
|
|
|
|
kfree(kbd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct usb_device_id usb_kbd_id_table [] = {
|
2007-02-21 21:51:25 +00:00
|
|
|
{ USB_INTERFACE_INFO(USB_INTERFACE_CLASS_HID, USB_INTERFACE_SUBCLASS_BOOT,
|
|
|
|
USB_INTERFACE_PROTOCOL_KEYBOARD) },
|
2005-04-16 22:20:36 +00:00
|
|
|
{ } /* Terminating entry */
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE (usb, usb_kbd_id_table);
|
|
|
|
|
|
|
|
static struct usb_driver usb_kbd_driver = {
|
|
|
|
.name = "usbkbd",
|
|
|
|
.probe = usb_kbd_probe,
|
|
|
|
.disconnect = usb_kbd_disconnect,
|
|
|
|
.id_table = usb_kbd_id_table,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init usb_kbd_init(void)
|
|
|
|
{
|
|
|
|
int result = usb_register(&usb_kbd_driver);
|
|
|
|
if (result == 0)
|
2008-10-11 22:14:23 +00:00
|
|
|
printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
|
|
|
|
DRIVER_DESC "\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit usb_kbd_exit(void)
|
|
|
|
{
|
|
|
|
usb_deregister(&usb_kbd_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(usb_kbd_init);
|
|
|
|
module_exit(usb_kbd_exit);
|