diff options
author | Patrick Georgi <patrick.georgi@coresystems.de> | 2008-09-02 16:06:22 +0000 |
---|---|---|
committer | Patrick Georgi <patrick.georgi@coresystems.de> | 2008-09-02 16:06:22 +0000 |
commit | d21f68bbd588f46c23066eb8d227b51e4823de41 (patch) | |
tree | 1c9c724d292b8de59599d98e8549177329953a12 /payloads/libpayload/drivers/usb/usbhid.c | |
parent | 5ccfa1ac7994888f57c60b80fff80e350ab3f16c (diff) | |
download | coreboot-d21f68bbd588f46c23066eb8d227b51e4823de41.tar.xz |
This patch adds USB capabilities to libpayload. It requires some
memalign implementation (eg. the one I sent yesterday).
Features:
- UHCI controller driver
- UHCI root hub driver
- USB MSC (Mass Storage Class) driver
- skeleton of a USB HID driver
(requires better interrupt transfer handling, which is TODO)
- skeleton of a USB hub driver
(needs several blank spots filled in, eg. power management.
Again: TODO)
OHCI and EHCI are not supported, though OHCI support should be rather
easy as the stack provides reasonable abstractions (or so I hope). EHCI
will probably be more complicated.
Isochronous transfers (eg. webcams, audio stuff, ...) are not supported.
They can be, but I doubt we'll have a reason for that in the boot
environment.
The MSC driver was tested against a couple of USB flash drives, and
should be reasonably tolerant by now. But I probably underestimate
the amount of bugs present in USB flash drives, so feedback is welcome.
Signed-off-by: Patrick Georgi <patrick.georgi@coresystems.de>
Acked-by: Jordan Crouse <jordan.crouse@amd.com>
git-svn-id: svn://svn.coreboot.org/coreboot/trunk@3560 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'payloads/libpayload/drivers/usb/usbhid.c')
-rw-r--r-- | payloads/libpayload/drivers/usb/usbhid.c | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/payloads/libpayload/drivers/usb/usbhid.c b/payloads/libpayload/drivers/usb/usbhid.c new file mode 100644 index 0000000000..414cc07cdb --- /dev/null +++ b/payloads/libpayload/drivers/usb/usbhid.c @@ -0,0 +1,137 @@ +/* + * This file is part of the libpayload project. + * + * Copyright (C) 2008 coresystems GmbH + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include "usb.h" + +enum { hid_subclass_none = 0, hid_subclass_boot = 1 }; +enum { hid_proto_boot = 0, hid_proto_report = 1 }; +enum { hid_boot_proto_none = 0, hid_boot_proto_keyboard = + 1, hid_boot_proto_mouse = 2 +}; +static const char *boot_protos[3] = { "(none)", "keyboard", "mouse" }; +enum { GET_REPORT = 0x1, GET_IDLE = 0x2, GET_PROTOCOL = 0x3, SET_REPORT = + 0x9, SET_IDLE = 0xa, SET_PROTOCOL = 0xb +}; + +static void +usb_hid_destroy (usbdev_t *dev) +{ +} + +int keypress; +char keymap[256] = { + -1, -1, -1, -1, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', + 'l', + 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', + '1', '2', + '3', '4', '5', '6', '7', '8', '9', '0', '\n', TERM_ESC, + TERM_BACKSPACE, TERM_TAB, ' ', '-', '=', '[', + ']', '\\', -1, ';', '\'', '`', ',', '.', '/', -1, -1, -1, -1, -1, -1, + -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, TERM_HOME, TERM_PPAGE, -1, + TERM_END, TERM_NPAGE, TERM_RIGHT, + TERM_LEFT, TERM_DOWN, TERM_UP, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, +}; + + +static void +usb_hid_poll (usbdev_t *dev) +{ + char buf[8]; + static int toggle = 0; + // hardcode to endpoint 1, 8 bytes + dev->controller->packet (dev, 1, IN, toggle, 8, buf); + toggle ^= 1; + // FIXME: manage buf[0]=special keys, too + keypress = keymap[buf[2]]; + if ((keypress == -1) && (buf[2] != 0)) { + printf ("%x %x %x %x %x %x %x %x\n", buf[0], buf[1], buf[2], + buf[3], buf[4], buf[5], buf[6], buf[7]); + } +} + +int (*oldhook) (void); + +int +hookfunc (void) +{ + int key; + if (oldhook != 0) + key = oldhook (); + if (key == -1) + key = keypress; + return key; +} + +void +usb_hid_init (usbdev_t *dev) +{ + + configuration_descriptor_t *cd = dev->configuration; + interface_descriptor_t *interface = ((char *) cd) + cd->bLength; + + if (interface->bInterfaceSubClass == hid_subclass_boot) { + printf (" supports boot interface..\n"); + printf (" it's a %s\n", + boot_protos[interface->bInterfaceProtocol]); + if (interface->bInterfaceProtocol == hid_boot_proto_keyboard) { + printf (" activating...\n"); + dev_req_t dr; + // set_protocol(hid_proto_boot) + dr.data_dir = host_to_device; + dr.req_type = class_type; + dr.req_recp = iface_recp; + dr.bRequest = SET_PROTOCOL; + dr.wValue = hid_proto_boot; + dr.wIndex = interface->bInterfaceNumber; + dr.wLength = 0; + dev->controller->control (dev, OUT, + sizeof (dev_req_t), &dr, 0, + 0); + + // only add here, because we only support boot-keyboard HID devices + // FIXME: make this a real console input driver instead, once the API is there + dev->destroy = usb_hid_destroy; + dev->poll = usb_hid_poll; + oldhook = getkey_hook; + getkey_hook = hookfunc; + } + } +} |