Index: boot/arch/amd64/Makefile.inc
===================================================================
--- boot/arch/amd64/Makefile.inc	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ boot/arch/amd64/Makefile.inc	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -49,5 +49,5 @@
 	usbflbk \
 	usbhub \
-	usbkbd \
+	usbhid \
 	usbmid \
 	usbmouse \
Index: kernel/generic/src/console/console.c
===================================================================
--- kernel/generic/src/console/console.c	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ kernel/generic/src/console/console.c	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -53,14 +53,5 @@
 #include <str.h>
 
-/*
- * devman produces a lot of output and by giving so many pages
- * we to allow /app/klog to catch-up.
- */
-#ifdef CONFIG_DEVMAN_EARLY_LAUNCH
-#define KLOG_PAGES    64
-#else
 #define KLOG_PAGES    4
-#endif
-
 #define KLOG_LENGTH   (KLOG_PAGES * PAGE_SIZE / sizeof(wchar_t))
 #define KLOG_LATENCY  8
Index: kernel/generic/src/mm/as.c
===================================================================
--- kernel/generic/src/mm/as.c	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ kernel/generic/src/mm/as.c	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -1949,5 +1949,5 @@
 sysarg_t sys_as_area_create(uintptr_t address, size_t size, unsigned int flags)
 {
-	if (as_area_create(AS, flags, size, address,
+	if (as_area_create(AS, flags | AS_AREA_CACHEABLE, size, address,
 	    AS_AREA_ATTR_NONE, &anon_backend, NULL))
 		return (sysarg_t) address;
Index: uspace/Makefile
===================================================================
--- uspace/Makefile	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ uspace/Makefile	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -122,5 +122,5 @@
 		drv/uhci-rhd \
 		drv/usbflbk \
-		drv/usbkbd \
+		drv/usbhid \
 		drv/usbhub \
 		drv/usbmid \
@@ -142,5 +142,5 @@
 		drv/uhci-rhd \
 		drv/usbflbk \
-		drv/usbkbd \
+		drv/usbhid \
 		drv/usbhub \
 		drv/usbmid \
Index: uspace/app/init/init.c
===================================================================
--- uspace/app/init/init.c	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ uspace/app/init/init.c	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -288,4 +288,8 @@
 	
 	spawn("/srv/clip");
+
+#ifdef CONFIG_DEVMAN_EARLY_LAUNCH
+	spawn("/srv/devman");
+#endif
 	
 	/*
@@ -314,7 +318,5 @@
 	getterm("term/vc6", "/app/klog", false);
 
-#ifdef CONFIG_DEVMAN_EARLY_LAUNCH
-	spawn("/srv/devman");
-#else
+#ifndef CONFIG_DEVMAN_EARLY_LAUNCH
 	getterm("term/vc7", "/srv/devman", false);
 #endif
Index: uspace/drv/ohci/Makefile
===================================================================
--- uspace/drv/ohci/Makefile	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ uspace/drv/ohci/Makefile	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -37,5 +37,4 @@
 	main.c \
 	hc.c \
-	ohci.c \
 	root_hub.c \
 	pci.c
Index: uspace/drv/ohci/batch.c
===================================================================
--- uspace/drv/ohci/batch.c	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ uspace/drv/ohci/batch.c	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -118,5 +118,5 @@
 	instance->next_step = batch_call_in_and_dispose;
 	/* TODO: implement */
-	usb_log_debug("Batch(%p) CONTROL READ initialized.\n", instance);
+	usb_log_debug("Batch(%p) CONTROL WRITE initialized.\n", instance);
 }
 /*----------------------------------------------------------------------------*/
Index: uspace/drv/ohci/hc.c
===================================================================
--- uspace/drv/ohci/hc.c	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ uspace/drv/ohci/hc.c	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -39,4 +39,5 @@
 #include <usb/debug.h>
 #include <usb/usb.h>
+#include <usb/hub.h>
 #include <usb/ddfiface.h>
 #include <usb/usbdevice.h>
@@ -44,31 +45,6 @@
 #include "hc.h"
 
+static int dummy_reset(int foo, void *arg);
 static int interrupt_emulator(hc_t *instance);
-/*----------------------------------------------------------------------------*/
-int hc_register_hub(hc_t *instance, ddf_fun_t *hub_fun)
-{
-	assert(instance);
-	assert(hub_fun);
-
-	usb_address_t hub_address =
-	    device_keeper_get_free_address(&instance->manager, USB_SPEED_FULL);
-	instance->rh.address = hub_address;
-	usb_device_keeper_bind(
-	    &instance->manager, hub_address, hub_fun->handle);
-
-	char *match_str = NULL;
-	int ret = asprintf(&match_str, "usb&mid");
-	ret = (match_str == NULL) ? ret : EOK;
-	if (ret < 0) {
-		usb_log_error("Failed to create root hub match-id string.\n");
-		return ret;
-	}
-
-	ret = ddf_fun_add_match_id(hub_fun, match_str, 100);
-	if (ret != EOK) {
-		usb_log_error("Failed add create root hub match-id.\n");
-	}
-	return ret;
-}
 /*----------------------------------------------------------------------------*/
 int hc_init(hc_t *instance, ddf_fun_t *fun, ddf_dev_t *dev,
@@ -92,7 +68,44 @@
 	}
 
+
 	rh_init(&instance->rh, dev, instance->registers);
+	/* TODO: implement */
+	return EOK;
+}
+/*----------------------------------------------------------------------------*/
+int hc_register_hub(hc_t *instance)
+{
+	async_usleep(1000000);
+#define CHECK_RET_RETURN(ret, msg...) \
+	if (ret != EOK) { \
+		usb_log_error(msg); \
+		return ret; \
+	} else (void)0
+	assert(instance);
+	assert(instance->ddf_instance);
+	assert(instance->ddf_instance->handle);
+	ddf_dev_t *dev = instance->rh.device;
+	int ret = EOK;
 
-	/* TODO: implement */
+	usb_hc_connection_t conn;
+	ret =
+	    usb_hc_connection_initialize(&conn, instance->ddf_instance->handle);
+	CHECK_RET_RETURN(ret, "Failed to initialize hc connection.\n");
+
+	ret = usb_hc_connection_open(&conn);
+	CHECK_RET_RETURN(ret, "Failed to open hc connection.\n");
+
+	usb_address_t address;
+	devman_handle_t handle;
+	ret = usb_hc_new_device_wrapper(dev, &conn, USB_SPEED_FULL, dummy_reset,
+	    0, instance, &address, &handle, NULL, NULL, NULL);
+	if (ret != EOK) {
+		usb_log_error("Failed to add rh device.\n");
+		instance->rh.address = -1;
+		return ret;
+	}
+
+	ret = usb_hc_connection_close(&conn);
+	CHECK_RET_RETURN(ret, "Failed to close hc connection.\n");
 	return EOK;
 }
@@ -121,5 +134,13 @@
 }
 /*----------------------------------------------------------------------------*/
-int interrupt_emulator(hc_t *instance)
+static int dummy_reset(int foo, void *arg)
+{
+	hc_t *hc = (hc_t*)arg;
+	assert(hc);
+	hc->rh.address = 0;
+	return EOK;
+}
+/*----------------------------------------------------------------------------*/
+static int interrupt_emulator(hc_t *instance)
 {
 	assert(instance);
Index: uspace/drv/ohci/hc.h
===================================================================
--- uspace/drv/ohci/hc.h	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ uspace/drv/ohci/hc.h	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -57,8 +57,8 @@
 } hc_t;
 
-int hc_register_hub(hc_t *instance, ddf_fun_t *hub_fun);
-
 int hc_init(hc_t *instance, ddf_fun_t *fun, ddf_dev_t *dev,
      uintptr_t regs, size_t reg_size, bool interrupts);
+
+int hc_register_hub(hc_t *instance);
 
 int hc_schedule(hc_t *instance, usb_transfer_batch_t *batch);
Index: uspace/drv/ohci/iface.h
===================================================================
--- uspace/drv/ohci/iface.h	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ uspace/drv/ohci/iface.h	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -33,8 +33,10 @@
  * Common OHCI definitions.
  */
-#ifndef DRV_OHCI_IFACE_H
-#define DRV_OHCI_IFACE_H
+#ifndef DRV_OHCI_OHCI_H
+#define DRV_OHCI_OHCI_H
 
 #include <usbhc_iface.h>
+
+#define NAME "ohci"
 
 extern usbhc_iface_t hc_iface;
Index: uspace/drv/ohci/main.c
===================================================================
--- uspace/drv/ohci/main.c	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ uspace/drv/ohci/main.c	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -34,14 +34,57 @@
  */
 #include <ddf/driver.h>
+#include <ddf/interrupt.h>
+#include <device/hw_res.h>
 #include <errno.h>
 #include <str_error.h>
 
+#include <usb_iface.h>
+#include <usb/ddfiface.h>
 #include <usb/debug.h>
 
-#include "ohci.h"
-
-#define NAME "ohci"
+#include "pci.h"
+#include "iface.h"
+#include "hc.h"
 
 static int ohci_add_device(ddf_dev_t *device);
+static int get_hc_handle(ddf_fun_t *fun, devman_handle_t *handle)
+{
+	assert(handle);
+  assert(fun != NULL);
+
+  *handle = fun->handle;
+  return EOK;
+}
+/*----------------------------------------------------------------------------*/
+static int get_address(
+    ddf_fun_t *fun, devman_handle_t handle, usb_address_t *address)
+{
+	assert(fun);
+	usb_device_keeper_t *manager = &fun_to_hc(fun)->manager;
+  usb_address_t addr = usb_device_keeper_find(manager, handle);
+  if (addr < 0) {
+    return addr;
+  }
+
+  if (address != NULL) {
+    *address = addr;
+  }
+
+  return EOK;
+}
+/*----------------------------------------------------------------------------*/
+/** IRQ handling callback, identifies device
+ *
+ * @param[in] dev DDF instance of the device to use.
+ * @param[in] iid (Unused).
+ * @param[in] call Pointer to the call that represents interrupt.
+ */
+static void irq_handler(ddf_dev_t *dev, ipc_callid_t iid, ipc_call_t *call)
+{
+	assert(dev);
+	hc_t *hc = (hc_t*)dev->driver_data;
+	assert(hc);
+	hc_interrupt(hc, 0);
+}
 /*----------------------------------------------------------------------------*/
 static driver_ops_t ohci_driver_ops = {
@@ -54,4 +97,14 @@
 };
 /*----------------------------------------------------------------------------*/
+static usb_iface_t hc_usb_iface = {
+	.get_address = get_address,
+	.get_hc_handle = get_hc_handle,
+};
+/*----------------------------------------------------------------------------*/
+static ddf_dev_ops_t hc_ops = {
+	.interfaces[USB_DEV_IFACE] = &hc_usb_iface,
+	.interfaces[USBHC_DEV_IFACE] = &hc_iface,
+};
+/*----------------------------------------------------------------------------*/
 /** Initializes a new ddf driver instance of OHCI hcd.
  *
@@ -59,25 +112,86 @@
  * @return Error code.
  */
-int ohci_add_device(ddf_dev_t *device)
-{
-	usb_log_debug("ohci_add_device() called\n");
+static int ohci_add_device(ddf_dev_t *device)
+{
 	assert(device);
-	ohci_t *ohci = malloc(sizeof(ohci_t));
-	if (ohci == NULL) {
+#define CHECK_RET_RETURN(ret, message...) \
+if (ret != EOK) { \
+	usb_log_error(message); \
+	return ret; \
+}
+
+	uintptr_t mem_reg_base = 0;
+	size_t mem_reg_size = 0;
+	int irq = 0;
+
+	int ret =
+	    pci_get_my_registers(device, &mem_reg_base, &mem_reg_size, &irq);
+	CHECK_RET_RETURN(ret,
+	    "Failed(%d) to get memory addresses:.\n", ret, device->handle);
+	usb_log_info("Memory mapped regs at 0x%X (size %zu), IRQ %d.\n",
+	    mem_reg_base, mem_reg_size, irq);
+
+	ret = pci_disable_legacy(device);
+	CHECK_RET_RETURN(ret,
+	    "Failed(%d) disable legacy USB: %s.\n", ret, str_error(ret));
+
+	hc_t *hcd = malloc(sizeof(hc_t));
+	if (hcd == NULL) {
 		usb_log_error("Failed to allocate OHCI driver.\n");
 		return ENOMEM;
 	}
 
-	int ret = ohci_init(ohci, device);
+	ddf_fun_t *hc_fun = ddf_fun_create(device, fun_exposed, "ohci-hc");
+	if (hc_fun == NULL) {
+		usb_log_error("Failed to create OHCI function.\n");
+		free(hcd);
+		return ENOMEM;
+	}
+
+
+	bool interrupts = false;
+#ifdef CONFIG_USBHC_NO_INTERRUPTS
+	usb_log_warning("Interrupts disabled in OS config, " \
+	    "falling back to polling.\n");
+#else
+	ret = pci_enable_interrupts(device);
 	if (ret != EOK) {
-		usb_log_error("Failed to initialize OHCI driver: %s.\n",
+		usb_log_warning("Failed to enable interrupts: %s.\n",
 		    str_error(ret));
+		usb_log_info("HW interrupts not available, " \
+		    "falling back to polling.\n");
+	} else {
+		usb_log_debug("Hw interrupts enabled.\n");
+		interrupts = true;
+	}
+#endif
+
+	ret = hc_init(hcd, hc_fun, device, mem_reg_base, mem_reg_size, interrupts);
+	if (ret != EOK) {
+		usb_log_error("Failed to initialize OHCI driver.\n");
+		free(hcd);
 		return ret;
 	}
-	device->driver_data = ohci;
-
-	usb_log_info("Controlling new OHCI device `%s'.\n", device->name);
+
+	ret = register_interrupt_handler(device, irq, irq_handler, NULL);
+
+	hc_fun->ops = &hc_ops;
+	ret = ddf_fun_bind(hc_fun);
+	if (ret != EOK) {
+		usb_log_error("Failed to bind OHCI function.\n");
+		ddf_fun_destroy(hc_fun);
+		free(hcd);
+		return ret;
+	}
+	hc_fun->driver_data = hcd;
+
+	fid_t later = fibril_create((int(*)(void*))hc_register_hub, hcd);
+	fibril_add_ready(later);
+
+	usb_log_info("Controlling new OHCI device `%s' (handle %llu).\n",
+	    device->name, device->handle);
 
 	return EOK;
+#undef CHECK_RET_RETURN
 }
 /*----------------------------------------------------------------------------*/
Index: pace/drv/ohci/ohci.c
===================================================================
--- uspace/drv/ohci/ohci.c	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ 	(revision )
@@ -1,225 +1,0 @@
-/*
- * Copyright (c) 2011 Jan Vesely
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - 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.
- * - 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 ``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 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.
- */
-
-/** @addtogroup drvusbohci
- * @{
- */
-/** @file
- * @brief UHCI driver
- */
-#include <errno.h>
-#include <str_error.h>
-#include <ddf/interrupt.h>
-#include <usb_iface.h>
-#include <usb/usb.h>
-#include <usb/ddfiface.h>
-#include <usb/debug.h>
-
-#include "ohci.h"
-#include "iface.h"
-#include "pci.h"
-
-/** IRQ handling callback, identifies device
- *
- * @param[in] dev DDF instance of the device to use.
- * @param[in] iid (Unused).
- * @param[in] call Pointer to the call that represents interrupt.
- */
-static void irq_handler(ddf_dev_t *dev, ipc_callid_t iid, ipc_call_t *call)
-{
-	assert(dev);
-	hc_t *hc = &((ohci_t*)dev->driver_data)->hc;
-	uint16_t status = IPC_GET_ARG1(*call);
-	assert(hc);
-	hc_interrupt(hc, status);
-}
-/*----------------------------------------------------------------------------*/
-/** Get address of the device identified by handle.
- *
- * @param[in] dev DDF instance of the device to use.
- * @param[in] iid (Unused).
- * @param[in] call Pointer to the call that represents interrupt.
- */
-static int usb_iface_get_address(
-    ddf_fun_t *fun, devman_handle_t handle, usb_address_t *address)
-{
-	assert(fun);
-	usb_device_keeper_t *manager = &((ohci_t*)fun->dev->driver_data)->hc.manager;
-
-	usb_address_t addr = usb_device_keeper_find(manager, handle);
-	if (addr < 0) {
-		return addr;
-	}
-
-	if (address != NULL) {
-		*address = addr;
-	}
-
-	return EOK;
-}
-/*----------------------------------------------------------------------------*/
-/** Gets handle of the respective hc (this device, hc function).
- *
- * @param[in] root_hub_fun Root hub function seeking hc handle.
- * @param[out] handle Place to write the handle.
- * @return Error code.
- */
-static int usb_iface_get_hc_handle(
-    ddf_fun_t *fun, devman_handle_t *handle)
-{
-	assert(handle);
-	ddf_fun_t *hc_fun = ((ohci_t*)fun->dev->driver_data)->hc_fun;
-	assert(hc_fun != NULL);
-
-	*handle = hc_fun->handle;
-	return EOK;
-}
-/*----------------------------------------------------------------------------*/
-/** This iface is generic for both RH and HC. */
-static usb_iface_t usb_iface = {
-	.get_hc_handle = usb_iface_get_hc_handle,
-	.get_address = usb_iface_get_address
-};
-/*----------------------------------------------------------------------------*/
-static ddf_dev_ops_t hc_ops = {
-	.interfaces[USBHC_DEV_IFACE] = &hc_iface, /* see iface.h/c */
-};
-/*----------------------------------------------------------------------------*/
-static ddf_dev_ops_t rh_ops = {
-	.interfaces[USB_DEV_IFACE] = &usb_iface,
-};
-/*----------------------------------------------------------------------------*/
-/** Initialize hc and rh ddf structures and their respective drivers.
- *
- * @param[in] instance UHCI structure to use.
- * @param[in] device DDF instance of the device to use.
- *
- * This function does all the preparatory work for hc and rh drivers:
- *  - gets device hw resources
- *  - disables UHCI legacy support
- *  - asks for interrupt
- *  - registers interrupt handler
- */
-int ohci_init(ohci_t *instance, ddf_dev_t *device)
-{
-	assert(instance);
-	instance->hc_fun = NULL;
-	instance->rh_fun = NULL;
-#define CHECK_RET_DEST_FUN_RETURN(ret, message...) \
-if (ret != EOK) { \
-	usb_log_error(message); \
-	if (instance->hc_fun) \
-		ddf_fun_destroy(instance->hc_fun); \
-	if (instance->rh_fun) \
-		ddf_fun_destroy(instance->rh_fun); \
-	return ret; \
-}
-
-	uintptr_t mem_reg_base = 0;
-	size_t mem_reg_size = 0;
-	int irq = 0;
-
-	int ret =
-	    pci_get_my_registers(device, &mem_reg_base, &mem_reg_size, &irq);
-	CHECK_RET_DEST_FUN_RETURN(ret,
-	    "Failed(%d) to get memory addresses:.\n", ret, device->handle);
-	usb_log_debug("Memory mapped regs at 0x%X (size %zu), IRQ %d.\n",
-	    mem_reg_base, mem_reg_size, irq);
-
-	ret = pci_disable_legacy(device);
-	CHECK_RET_DEST_FUN_RETURN(ret,
-	    "Failed(%d) to disable legacy USB: %s.\n", ret, str_error(ret));
-
-	bool interrupts = false;
-#ifdef CONFIG_USBHC_NO_INTERRUPTS
-	usb_log_warning("Interrupts disabled in OS config, " \
-	    "falling back to polling.\n");
-#else
-	ret = pci_enable_interrupts(device);
-	if (ret != EOK) {
-		usb_log_warning("Failed to enable interrupts: %s.\n",
-		    str_error(ret));
-		usb_log_info("HW interrupts not available, " \
-		    "falling back to polling.\n");
-	} else {
-		usb_log_debug("Hw interrupts enabled.\n");
-		interrupts = true;
-	}
-#endif
-
-	instance->hc_fun = ddf_fun_create(device, fun_exposed, "ohci-hc");
-	ret = (instance->hc_fun == NULL) ? ENOMEM : EOK;
-	CHECK_RET_DEST_FUN_RETURN(ret,
-	    "Failed(%d) to create HC function.\n", ret);
-
-	ret = hc_init(&instance->hc, instance->hc_fun, device,
-	    mem_reg_base, mem_reg_size, interrupts);
-	CHECK_RET_DEST_FUN_RETURN(ret, "Failed(%d) to init ohci-hcd.\n", ret);
-	instance->hc_fun->ops = &hc_ops;
-	instance->hc_fun->driver_data = &instance->hc;
-	ret = ddf_fun_bind(instance->hc_fun);
-	CHECK_RET_DEST_FUN_RETURN(ret,
-	    "Failed(%d) to bind UHCI device function: %s.\n",
-	    ret, str_error(ret));
-#undef CHECK_RET_HC_RETURN
-
-#define CHECK_RET_FINI_RETURN(ret, message...) \
-if (ret != EOK) { \
-	usb_log_error(message); \
-	if (instance->hc_fun) \
-		ddf_fun_destroy(instance->hc_fun); \
-	if (instance->rh_fun) \
-		ddf_fun_destroy(instance->rh_fun); \
-	hc_fini(&instance->hc); \
-	return ret; \
-}
-
-	/* It does no harm if we register this on polling */
-	ret = register_interrupt_handler(device, irq, irq_handler, NULL);
-	CHECK_RET_FINI_RETURN(ret,
-	    "Failed(%d) to register interrupt handler.\n", ret);
-
-	instance->rh_fun = ddf_fun_create(device, fun_inner, "ohci-rh");
-	ret = (instance->rh_fun == NULL) ? ENOMEM : EOK;
-	CHECK_RET_FINI_RETURN(ret,
-	    "Failed(%d) to create root hub function.\n", ret);
-
-	hc_register_hub(&instance->hc, instance->rh_fun);
-
-	instance->rh_fun->ops = &rh_ops;
-	instance->rh_fun->driver_data = NULL;
-	ret = ddf_fun_bind(instance->rh_fun);
-	CHECK_RET_FINI_RETURN(ret,
-	    "Failed(%d) to register UHCI root hub.\n", ret);
-
-	return EOK;
-#undef CHECK_RET_FINI_RETURN
-}
-/**
- * @}
- */
Index: pace/drv/ohci/ohci.h
===================================================================
--- uspace/drv/ohci/ohci.h	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ 	(revision )
@@ -1,56 +1,0 @@
-/*
- * Copyright (c) 2011 Jan Vesely
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - 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.
- * - 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 ``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 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.
- */
-
-/** @addtogroup drvusbohci
- * @{
- */
-/** @file
- * @brief OHCI driver main structure for both host controller and root-hub.
- */
-#ifndef DRV_OHCI_OHCI_H
-#define DRV_OHCI_OHCI_H
-#include <ddi.h>
-#include <ddf/driver.h>
-
-#include "hc.h"
-#include "root_hub.h"
-
-typedef struct ohci {
-	ddf_fun_t *hc_fun;
-	ddf_fun_t *rh_fun;
-
-	hc_t hc;
-	rh_t rh;
-} ohci_t;
-
-int ohci_init(ohci_t *instance, ddf_dev_t *device);
-
-#endif
-/**
- * @}
- */
Index: uspace/drv/ohci/root_hub.c
===================================================================
--- uspace/drv/ohci/root_hub.c	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ uspace/drv/ohci/root_hub.c	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -39,61 +39,4 @@
 
 #include "root_hub.h"
-#include "usb/classes/classes.h"
-#include <usb/request.h>
-#include <usb/classes/hub.h>
-
-static const usb_standard_device_descriptor_t ohci_rh_device_descriptor =
-{
-		.configuration_count = 1,
-		.descriptor_type = USB_DESCTYPE_DEVICE,
-		.device_class = USB_CLASS_HUB,
-		.device_protocol = 0,
-		.device_subclass = 0,
-		.device_version = 0,
-		.length = sizeof(usb_standard_device_descriptor_t),
-		/// \TODO this value is guessed
-		.max_packet_size = 8,
-		.vendor_id = 0x16db,
-		.product_id = 0x0001,
-		/// \TODO these values migt be different
-		.str_serial_number = 0,
-		.usb_spec_version = 0,
-};
-
-static const usb_standard_configuration_descriptor_t ohci_rh_conf_descriptor =
-{
-	/// \TODO some values are default or guessed
-	.attributes = 1<<7,
-	.configuration_number = 1,
-	.descriptor_type = USB_DESCTYPE_CONFIGURATION,
-	.interface_count = 1,
-	.length = sizeof(usb_standard_configuration_descriptor_t),
-	.max_power = 100,
-	.str_configuration = 0,
-};
-
-static const usb_standard_interface_descriptor_t ohci_rh_iface_descriptor =
-{
-	.alternate_setting = 0,
-	.descriptor_type = USB_DESCTYPE_INTERFACE,
-	.endpoint_count = 1,
-	.interface_class = USB_CLASS_HUB,
-	/// \TODO is this correct?
-	.interface_number = 1,
-	.interface_protocol = 0,
-	.interface_subclass = 0,
-	.length = sizeof(usb_standard_interface_descriptor_t),
-	.str_interface = 0,
-};
-
-static const usb_standard_endpoint_descriptor_t ohci_rh_ep_descriptor =
-{
-	.attributes = USB_TRANSFER_INTERRUPT,
-	.descriptor_type = USB_DESCTYPE_ENDPOINT,
-	.endpoint_address = 1 + (1<<7),
-	.length = sizeof(usb_standard_endpoint_descriptor_t),
-	.max_packet_size = 8,
-	.poll_interval = 255,
-};
 
 /** Root hub initialization
@@ -107,477 +50,24 @@
 	instance->device = dev;
 
-
 	usb_log_info("OHCI root hub with %d ports.\n", regs->rh_desc_a & 0xff);
 
-	//start generic usb hub driver
-	
 	/* TODO: implement */
 	return EOK;
 }
 /*----------------------------------------------------------------------------*/
-
-
-static int process_get_port_status_request(rh_t *instance, uint16_t port,
-		usb_transfer_batch_t * request){
-	if(port<1 || port>instance->port_count)
-		return EINVAL;
-	uint32_t * uint32_buffer = (uint32_t*)request->buffer;
-	request->transfered_size = 4;
-	uint32_buffer[0] = instance->registers->rh_port_status[port -1];
-	return EOK;
-}
-
-static int process_get_hub_status_request(rh_t *instance,
-		usb_transfer_batch_t * request){
-	uint32_t * uint32_buffer = (uint32_t*)request->buffer;
-	//bits, 0,1,16,17
-	request->transfered_size = 4;
-	uint32_t mask = 1 & (1<<1) & (1<<16) & (1<<17);
-	uint32_buffer[0] = mask & instance->registers->rh_status;
-	return EOK;
-
-}
-
-static void usb_create_serialized_hub_descriptor(rh_t *instance, uint8_t ** out_result,
-		size_t * out_size) {
-	//base size
-	size_t size = 7;
-	//variable size according to port count
-	size_t var_size = instance->port_count / 8 +
-			((instance->port_count % 8 > 0) ? 1 : 0);
-	size += 2 * var_size;
-	uint8_t * result = (uint8_t*) malloc(size);
-	bzero(result,size);
-	//size
-	result[0] = size;
-	//descriptor type
-	result[1] = USB_DESCTYPE_HUB;
-	result[2] = instance->port_count;
-	uint32_t hub_desc_reg = instance->registers->rh_desc_a;
-	result[3] = 
-			((hub_desc_reg >> 8) %2) +
-			(((hub_desc_reg >> 9) %2) << 1) +
-			(((hub_desc_reg >> 10) %2) << 2) +
-			(((hub_desc_reg >> 11) %2) << 3) +
-			(((hub_desc_reg >> 12) %2) << 4);
-	result[4] = 0;
-	result[5] = /*descriptor->pwr_on_2_good_time*/ 50;
-	result[6] = 50;
-
-	int port;
-	for (port = 1; port <= instance->port_count; ++port) {
-		result[7 + port/8] +=
-				((instance->registers->rh_desc_b >> port)%2) << (port%8);
-	}
-	size_t i;
-	for (i = 0; i < var_size; ++i) {
-		result[7 + var_size + i] = 255;
-	}
-	(*out_result) = result;
-	(*out_size) = size;
-}
-
-
-static int process_get_status_request(rh_t *instance,
-		usb_transfer_batch_t * request)
-{
-	size_t buffer_size = request->buffer_size;
-	usb_device_request_setup_packet_t * request_packet =
-			(usb_device_request_setup_packet_t*)
-			request->setup_buffer;
-
-	usb_hub_bm_request_type_t request_type = request_packet->request_type;
-	if(buffer_size<4/*request_packet->length*/){///\TODO
-		usb_log_warning("requested more data than buffer size\n");
-		return EINVAL;
-	}
-
-	if(request_type == USB_HUB_REQ_TYPE_GET_HUB_STATUS)
-		return process_get_hub_status_request(instance, request);
-	if(request_type == USB_HUB_REQ_TYPE_GET_PORT_STATUS)
-		return process_get_port_status_request(instance, request_packet->index,
-				request);
-	return ENOTSUP;
-}
-
-static void create_interrupt_mask(rh_t *instance, void ** buffer,
-		size_t * buffer_size){
-	int bit_count = instance->port_count + 1;
-	(*buffer_size) = (bit_count / 8) + (bit_count%8==0)?0:1;
-	(*buffer) = malloc(*buffer_size);
-	uint8_t * bitmap = (uint8_t*)(*buffer);
-	uint32_t mask = (1<<16) + (1<<17);
-	bzero(bitmap,(*buffer_size));
-	if(instance->registers->rh_status & mask){
-		bitmap[0] = 1;
-	}
-	int port;
-	mask = 0;
-	int i;
-	for(i=16;i<=20;++i)
-		mask += 1<<i;
-	for(port = 1; port<=instance->port_count;++port){
-		if(mask & instance->registers->rh_port_status[port-1]){
-			bitmap[(port+1)/8] += 1<<(port%8);
-		}
-	}
-}
-
-
-static int process_get_descriptor_request(rh_t *instance,
-		usb_transfer_batch_t *request){
-	/// \TODO
-	usb_device_request_setup_packet_t * setup_request =
-			(usb_device_request_setup_packet_t*)request->setup_buffer;
-	size_t size;
-	const void * result_descriptor;
-	const uint16_t setup_request_value = setup_request->value_high;
-			//(setup_request->value_low << 8);
-	bool del = false;
-
-	switch (setup_request_value)
-	{
-	case USB_DESCTYPE_HUB: {
-		uint8_t * descriptor;
-		usb_create_serialized_hub_descriptor(
-		    instance, &descriptor, &size);
-		result_descriptor = descriptor;
-		break;
-	}
-	case USB_DESCTYPE_DEVICE: {
-		usb_log_debug("USB_DESCTYPE_DEVICE\n");
-		result_descriptor = &ohci_rh_device_descriptor;
-		size = sizeof(ohci_rh_device_descriptor);
-		break;
-	}
-	case USB_DESCTYPE_CONFIGURATION: {
-		usb_log_debug("USB_DESCTYPE_CONFIGURATION\n");
-		usb_standard_configuration_descriptor_t * descriptor =
-				malloc(sizeof(usb_standard_configuration_descriptor_t));
-		memcpy(descriptor, &ohci_rh_conf_descriptor,
-		    sizeof(usb_standard_configuration_descriptor_t));
-		/// \TODO should this include device descriptor?
-		const size_t hub_descriptor_size = 7 +
-				2* (instance->port_count / 8 +
-				((instance->port_count % 8 > 0) ? 1 : 0));
-		descriptor->total_length =
-				sizeof(usb_standard_configuration_descriptor_t)+
-				sizeof(usb_standard_endpoint_descriptor_t)+
-				sizeof(usb_standard_interface_descriptor_t)+
-				hub_descriptor_size;
-		result_descriptor = descriptor;
-		size = sizeof(usb_standard_configuration_descriptor_t);
-		del = true;
-		break;
-	}
-	case USB_DESCTYPE_INTERFACE: {
-		usb_log_debug("USB_DESCTYPE_INTERFACE\n");
-		result_descriptor = &ohci_rh_iface_descriptor;
-		size = sizeof(ohci_rh_iface_descriptor);
-		break;
-	}
-	case USB_DESCTYPE_ENDPOINT: {
-		usb_log_debug("USB_DESCTYPE_ENDPOINT\n");
-		result_descriptor = &ohci_rh_ep_descriptor;
-		size = sizeof(ohci_rh_ep_descriptor);
-		break;
-	}
-	default: {
-		usb_log_debug("USB_DESCTYPE_EINVAL %d \n",setup_request->value);
-		usb_log_debug("\ttype %d\n\trequest %d\n\tvalue %d\n\tindex %d\n\tlen %d\n ",
-				setup_request->request_type,
-				setup_request->request,
-				setup_request_value,
-				setup_request->index,
-				setup_request->length
-				);
-		return EINVAL;
-	}
-	}
-#if 0
-	if(setup_request_value == USB_DESCTYPE_HUB){
-		usb_log_debug("USB_DESCTYPE_HUB\n");
-		//create hub descriptor
-		uint8_t * descriptor;
-		usb_create_serialized_hub_descriptor(instance, 
-				&descriptor, &size);
-		result_descriptor = descriptor;
-	}else if(setup_request_value == USB_DESCTYPE_DEVICE){
-		//create std device descriptor
-		usb_log_debug("USB_DESCTYPE_DEVICE\n");
-		usb_standard_device_descriptor_t * descriptor =
-				(usb_standard_device_descriptor_t*)
-				malloc(sizeof(usb_standard_device_descriptor_t));
-		descriptor->configuration_count = 1;
-		descriptor->descriptor_type = USB_DESCTYPE_DEVICE;
-		descriptor->device_class = USB_CLASS_HUB;
-		descriptor->device_protocol = 0;
-		descriptor->device_subclass = 0;
-		descriptor->device_version = 0;
-		descriptor->length = sizeof(usb_standard_device_descriptor_t);
-		/// \TODO this value is guessed
-		descriptor->max_packet_size = 8;
-		descriptor->product_id = 0x0001;
-		/// \TODO these values migt be different
-		descriptor->str_serial_number = 0;
-		descriptor->str_serial_number = 0;
-		descriptor->usb_spec_version = 0;
-		descriptor->vendor_id = 0x16db;
-		result_descriptor = descriptor;
-		size = sizeof(usb_standard_device_descriptor_t);
-	}else if(setup_request_value == USB_DESCTYPE_CONFIGURATION){
-		usb_log_debug("USB_DESCTYPE_CONFIGURATION\n");
-		usb_standard_configuration_descriptor_t * descriptor =
-				(usb_standard_configuration_descriptor_t*)
-				malloc(sizeof(usb_standard_configuration_descriptor_t));
-		/// \TODO some values are default or guessed
-		descriptor->attributes = 1<<7;
-		descriptor->configuration_number = 1;
-		descriptor->descriptor_type = USB_DESCTYPE_CONFIGURATION;
-		descriptor->interface_count = 1;
-		descriptor->length = sizeof(usb_standard_configuration_descriptor_t);
-		descriptor->max_power = 100;
-		descriptor->str_configuration = 0;
-		/// \TODO should this include device descriptor?
-		size_t hub_descriptor_size = 7 +
-				2* (instance->port_count / 8 +
-				((instance->port_count % 8 > 0) ? 1 : 0));
-		descriptor->total_length =
-				sizeof(usb_standard_configuration_descriptor_t)+
-				sizeof(usb_standard_endpoint_descriptor_t)+
-				sizeof(usb_standard_interface_descriptor_t)+
-				hub_descriptor_size;
-		result_descriptor = descriptor;
-		size = sizeof(usb_standard_configuration_descriptor_t);
-
-	}else if(setup_request_value == USB_DESCTYPE_INTERFACE){
-		usb_log_debug("USB_DESCTYPE_INTERFACE\n");
-		usb_standard_interface_descriptor_t * descriptor =
-				(usb_standard_interface_descriptor_t*)
-				malloc(sizeof(usb_standard_interface_descriptor_t));
-		descriptor->alternate_setting = 0;
-		descriptor->descriptor_type = USB_DESCTYPE_INTERFACE;
-		descriptor->endpoint_count = 1;
-		descriptor->interface_class = USB_CLASS_HUB;
-		/// \TODO is this correct?
-		descriptor->interface_number = 1;
-		descriptor->interface_protocol = 0;
-		descriptor->interface_subclass = 0;
-		descriptor->length = sizeof(usb_standard_interface_descriptor_t);
-		descriptor->str_interface = 0;
-		result_descriptor = descriptor;
-		size = sizeof(usb_standard_interface_descriptor_t);
-	}else if(setup_request_value == USB_DESCTYPE_ENDPOINT){
-		usb_log_debug("USB_DESCTYPE_ENDPOINT\n");
-		usb_standard_endpoint_descriptor_t * descriptor =
-				(usb_standard_endpoint_descriptor_t*)
-				malloc(sizeof(usb_standard_endpoint_descriptor_t));
-		descriptor->attributes = USB_TRANSFER_INTERRUPT;
-		descriptor->descriptor_type = USB_DESCTYPE_ENDPOINT;
-		descriptor->endpoint_address = 1 + (1<<7);
-		descriptor->length = sizeof(usb_standard_endpoint_descriptor_t);
-		descriptor->max_packet_size = 8;
-		descriptor->poll_interval = 255;
-		result_descriptor = descriptor;
-		size = sizeof(usb_standard_endpoint_descriptor_t);
-	}else{
-		usb_log_debug("USB_DESCTYPE_EINVAL %d \n",setup_request->value);
-		usb_log_debug("\ttype %d\n\trequest %d\n\tvalue %d\n\tindex %d\n\tlen %d\n ",
-				setup_request->request_type,
-				setup_request->request,
-				setup_request_value,
-				setup_request->index,
-				setup_request->length
-				);
-		return EINVAL;
-	}
-#endif
-	if(request->buffer_size < size){
-		size = request->buffer_size;
-	}
-	request->transfered_size = size;
-	memcpy(request->buffer,result_descriptor,size);
-	if (del)
-		free(result_descriptor);
-	return EOK;
-}
-
-static int process_get_configuration_request(rh_t *instance, 
-		usb_transfer_batch_t *request){
-	//set and get configuration requests do not have any meaning, only dummy
-	//values are returned
-	if(request->buffer_size != 1)
-		return EINVAL;
-	request->buffer[0] = 1;
-	request->transfered_size = 1;
-	return EOK;
-}
-
-static int process_hub_feature_set_request(rh_t *instance,
-		uint16_t feature, bool enable){
-	if(feature > USB_HUB_FEATURE_C_HUB_OVER_CURRENT)
-		return EINVAL;
-	instance->registers->rh_status =
-			enable ?
-			(instance->registers->rh_status | (1<<feature))
-			:
-			(instance->registers->rh_status & (~(1<<feature)));
-	/// \TODO any error?
-	return EOK;
-}
-
-static int process_port_feature_set_request(rh_t *instance,
-		uint16_t feature, uint16_t port, bool enable){
-	if(feature > USB_HUB_FEATURE_C_PORT_RESET)
-		return EINVAL;
-	if(port<1 || port>instance->port_count)
-		return EINVAL;
-	instance->registers->rh_port_status[port - 1] =
-			enable ?
-			(instance->registers->rh_port_status[port - 1] | (1<<feature))
-			:
-			(instance->registers->rh_port_status[port - 1] & (~(1<<feature)));
-	/// \TODO any error?
-	return EOK;
-}
-
-static int process_address_set_request(rh_t *instance,
-		uint16_t address){
-	instance->address = address;
-	return EOK;
-}
-
-static int process_request_with_output(rh_t *instance,
-		usb_transfer_batch_t *request){
-	usb_device_request_setup_packet_t * setup_request =
-			(usb_device_request_setup_packet_t*)request->setup_buffer;
-	if(setup_request->request == USB_DEVREQ_GET_STATUS){
-		usb_log_debug("USB_DEVREQ_GET_STATUS\n");
-		return process_get_status_request(instance, request);
-	}
-	if(setup_request->request == USB_DEVREQ_GET_DESCRIPTOR){
-		usb_log_debug("USB_DEVREQ_GET_DESCRIPTOR\n");
-		return process_get_descriptor_request(instance, request);
-	}
-	if(setup_request->request == USB_DEVREQ_GET_CONFIGURATION){
-		usb_log_debug("USB_DEVREQ_GET_CONFIGURATION\n");
-		return process_get_configuration_request(instance, request);
-	}
-	return ENOTSUP;
-}
-
-static int process_request_with_input(rh_t *instance,
-		usb_transfer_batch_t *request){
-	usb_device_request_setup_packet_t * setup_request =
-			(usb_device_request_setup_packet_t*)request->setup_buffer;
-	request->transfered_size = 0;
-	if(setup_request->request == USB_DEVREQ_SET_DESCRIPTOR){
-		return ENOTSUP;
-	}
-	if(setup_request->request == USB_DEVREQ_SET_CONFIGURATION){
-		//set and get configuration requests do not have any meaning,
-		//only dummy values are returned
-		return EOK;
-	}
-	return ENOTSUP;
-}
-
-
-static int process_request_without_data(rh_t *instance,
-		usb_transfer_batch_t *request){
-	usb_device_request_setup_packet_t * setup_request =
-			(usb_device_request_setup_packet_t*)request->setup_buffer;
-	request->transfered_size = 0;
-	if(setup_request->request == USB_DEVREQ_CLEAR_FEATURE
-				|| setup_request->request == USB_DEVREQ_SET_FEATURE){
-		if(setup_request->request_type == USB_HUB_REQ_TYPE_SET_HUB_FEATURE){
-			usb_log_debug("USB_HUB_REQ_TYPE_SET_HUB_FEATURE\n");
-			return process_hub_feature_set_request(instance, setup_request->value,
-					setup_request->request == USB_DEVREQ_SET_FEATURE);
-		}
-		if(setup_request->request_type == USB_HUB_REQ_TYPE_SET_PORT_FEATURE){
-			usb_log_debug("USB_HUB_REQ_TYPE_SET_PORT_FEATURE\n");
-			return process_port_feature_set_request(instance, setup_request->value,
-					setup_request->index,
-					setup_request->request == USB_DEVREQ_SET_FEATURE);
-		}
-		usb_log_debug("USB_HUB_REQ_TYPE_INVALID %d\n",setup_request->request_type);
-		return EINVAL;
-	}
-	if(setup_request->request == USB_DEVREQ_SET_ADDRESS){
-		usb_log_debug("USB_DEVREQ_SET_ADDRESS\n");
-		return process_address_set_request(instance, setup_request->value);
-	}
-	usb_log_debug("USB_DEVREQ_SET_ENOTSUP %d\n",setup_request->request_type);
-	return ENOTSUP;
-}
-
-
-/**
- *
- * @param instance
- * @param request
- * @return
- */
 int rh_request(rh_t *instance, usb_transfer_batch_t *request)
 {
 	assert(instance);
 	assert(request);
-	int opResult;
-	if(request->transfer_type == USB_TRANSFER_CONTROL){
-		if (request->setup_buffer) {
-			usb_log_info("Root hub got CTRL packet: %s.\n",
-				usb_debug_str_buffer((const uint8_t *)request->setup_buffer, 8, 8));
-			if(sizeof(usb_device_request_setup_packet_t)>request->setup_size){
-				usb_log_error("setup packet too small\n");
-				return EINVAL;
-			}
-			usb_device_request_setup_packet_t * setup_request =
-					(usb_device_request_setup_packet_t*)request->setup_buffer;
-			if(
-				setup_request->request == USB_DEVREQ_GET_STATUS
-				|| setup_request->request == USB_DEVREQ_GET_DESCRIPTOR
-				|| setup_request->request == USB_DEVREQ_GET_CONFIGURATION
-			){
-				usb_log_debug("processing request with output\n");
-				opResult = process_request_with_output(instance,request);
-			}else if(
-				setup_request->request == USB_DEVREQ_CLEAR_FEATURE
-				|| setup_request->request == USB_DEVREQ_SET_FEATURE
-				|| setup_request->request == USB_DEVREQ_SET_ADDRESS
-			){
-				usb_log_debug("processing request without additional data\n");
-				opResult = process_request_without_data(instance,request);
-			}else if(setup_request->request == USB_DEVREQ_SET_DESCRIPTOR
-					|| setup_request->request == USB_DEVREQ_SET_CONFIGURATION
-			){
-				usb_log_debug("processing request with input\n");
-				opResult = process_request_with_input(instance,request);
-			}else{
-				usb_log_warning("received unsuported request: %d\n",
-						setup_request->request
-						);
-				opResult = ENOTSUP;
-			}
-		}else{
-			usb_log_error("root hub received empty transaction?");
-			opResult = EINVAL;
-		}
-	}else if(request->transfer_type == USB_TRANSFER_INTERRUPT){
-		usb_log_info("Root hub got INTERRUPT packet\n");
-		void * buffer;
-		create_interrupt_mask(instance, &buffer,
-			&(request->transfered_size));
-		memcpy(request->transport_buffer,buffer, request->transfered_size);
-		opResult = EOK;
-	}else{
-		opResult = EINVAL;
+	/* TODO: implement */
+	if (request->setup_buffer) {
+		usb_log_info("Root hub got SETUP packet: %s.\n",
+		    usb_debug_str_buffer((const uint8_t *)request->setup_buffer, 8, 8));
 	}
-	usb_transfer_batch_finish(request, opResult);
+	usb_log_error("Root hub request processing not implemented.\n");
+	usb_transfer_batch_finish(request, ENOTSUP);
 	return EOK;
 }
 /*----------------------------------------------------------------------------*/
-
-
 void rh_interrupt(rh_t *instance)
 {
Index: uspace/drv/ohci/root_hub.h
===================================================================
--- uspace/drv/ohci/root_hub.h	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ uspace/drv/ohci/root_hub.h	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -45,5 +45,4 @@
 	usb_address_t address;
 	ddf_dev_t *device;
-	int port_count;
 } rh_t;
 
Index: uspace/drv/uhci-hcd/Makefile
===================================================================
--- uspace/drv/uhci-hcd/Makefile	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ uspace/drv/uhci-hcd/Makefile	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -40,5 +40,4 @@
 	root_hub.c \
 	hw_struct/transfer_descriptor.c \
-	utils/slab.c \
 	pci.c \
 	batch.c
Index: uspace/drv/uhci-hcd/hc.c
===================================================================
--- uspace/drv/uhci-hcd/hc.c	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ uspace/drv/uhci-hcd/hc.c	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -223,5 +223,5 @@
 	ret = instance ? EOK : ENOMEM;
 	CHECK_RET_DEST_CMDS_RETURN(ret, "Failed to get frame list page.\n");
-	usb_log_debug("Initialized frame list at %p.\n", instance->frame_list);
+	usb_log_debug("Initialized frame list.\n");
 
 	/* Set all frames to point to the first queue head */
@@ -336,8 +336,4 @@
 	    instance->transfers[batch->speed][batch->transfer_type];
 	assert(list);
-	if (batch->transfer_type == USB_TRANSFER_CONTROL) {
-		usb_device_keeper_use_control(
-		    &instance->manager, batch->target.address);
-	}
 	transfer_list_add_batch(list, batch);
 
@@ -361,25 +357,8 @@
 	/* Lower 2 bits are transaction error and transaction complete */
 	if (status & 0x3) {
-		LIST_INITIALIZE(done);
-		transfer_list_remove_finished(
-		    &instance->transfers_interrupt, &done);
-		transfer_list_remove_finished(
-		    &instance->transfers_control_slow, &done);
-		transfer_list_remove_finished(
-		    &instance->transfers_control_full, &done);
-		transfer_list_remove_finished(
-		    &instance->transfers_bulk_full, &done);
-
-		while (!list_empty(&done)) {
-			link_t *item = done.next;
-			list_remove(item);
-			usb_transfer_batch_t *batch =
-			    list_get_instance(item, usb_transfer_batch_t, link);
-			if (batch->transfer_type == USB_TRANSFER_CONTROL) {
-				usb_device_keeper_release_control(
-				    &instance->manager, batch->target.address);
-			}
-			batch->next_step(batch);
-		}
+		transfer_list_remove_finished(&instance->transfers_interrupt);
+		transfer_list_remove_finished(&instance->transfers_control_slow);
+		transfer_list_remove_finished(&instance->transfers_control_full);
+		transfer_list_remove_finished(&instance->transfers_bulk_full);
 	}
 	/* bits 4 and 5 indicate hc error */
Index: uspace/drv/uhci-hcd/root_hub.c
===================================================================
--- uspace/drv/uhci-hcd/root_hub.c	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ uspace/drv/uhci-hcd/root_hub.c	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -48,5 +48,6 @@
  * @return Error code.
  */
-int rh_init(rh_t *instance, ddf_fun_t *fun, uintptr_t reg_addr, size_t reg_size)
+int rh_init(
+    rh_t *instance, ddf_fun_t *fun, uintptr_t reg_addr, size_t reg_size)
 {
 	assert(fun);
Index: uspace/drv/uhci-hcd/transfer_list.c
===================================================================
--- uspace/drv/uhci-hcd/transfer_list.c	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ uspace/drv/uhci-hcd/transfer_list.c	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -58,6 +58,4 @@
 	}
 	instance->queue_head_pa = addr_to_phys(instance->queue_head);
-	usb_log_debug2("Transfer list %s setup with QH: %p(%p).\n",
-	    name, instance->queue_head, instance->queue_head_pa);
 
 	qh_init(instance->queue_head);
@@ -120,6 +118,4 @@
 	qh_set_next_qh(last_qh, pa);
 
-	asm volatile ("": : :"memory");
-
 	/* Add to the driver list */
 	list_append(&batch->link, &instance->batch_list);
@@ -141,8 +137,9 @@
  * this transfer list leading to the deadlock if its done inline.
  */
-void transfer_list_remove_finished(transfer_list_t *instance, link_t *done)
-{
-	assert(instance);
-	assert(done);
+void transfer_list_remove_finished(transfer_list_t *instance)
+{
+	assert(instance);
+
+	LIST_INITIALIZE(done);
 
 	fibril_mutex_lock(&instance->guard);
@@ -156,5 +153,5 @@
 			/* Save for post-processing */
 			transfer_list_remove_batch(instance, batch);
-			list_append(current, done);
+			list_append(current, &done);
 		}
 		current = next;
@@ -162,4 +159,11 @@
 	fibril_mutex_unlock(&instance->guard);
 
+	while (!list_empty(&done)) {
+		link_t *item = done.next;
+		list_remove(item);
+		usb_transfer_batch_t *batch =
+		    list_get_instance(item, usb_transfer_batch_t, link);
+		batch->next_step(batch);
+	}
 }
 /*----------------------------------------------------------------------------*/
@@ -218,5 +222,4 @@
 		qpos = "NOT FIRST";
 	}
-	asm volatile ("": : :"memory");
 	/* Remove from the batch list */
 	list_remove(&batch->link);
Index: uspace/drv/uhci-hcd/transfer_list.h
===================================================================
--- uspace/drv/uhci-hcd/transfer_list.h	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ uspace/drv/uhci-hcd/transfer_list.h	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -67,5 +67,5 @@
 void transfer_list_add_batch(transfer_list_t *instance, usb_transfer_batch_t *batch);
 
-void transfer_list_remove_finished(transfer_list_t *instance, link_t *done);
+void transfer_list_remove_finished(transfer_list_t *instance);
 
 void transfer_list_abort_all(transfer_list_t *instance);
Index: uspace/drv/uhci-hcd/uhci.c
===================================================================
--- uspace/drv/uhci-hcd/uhci.c	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ uspace/drv/uhci-hcd/uhci.c	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -44,4 +44,5 @@
 #include "pci.h"
 
+
 /** IRQ handling callback, identifies device
  *
@@ -107,5 +108,5 @@
 /*----------------------------------------------------------------------------*/
 static ddf_dev_ops_t hc_ops = {
-//	.interfaces[USB_DEV_IFACE] = &usb_iface,
+	.interfaces[USB_DEV_IFACE] = &usb_iface,
 	.interfaces[USBHC_DEV_IFACE] = &hc_iface, /* see iface.h/c */
 };
Index: uspace/drv/uhci-hcd/utils/malloc32.h
===================================================================
--- uspace/drv/uhci-hcd/utils/malloc32.h	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ uspace/drv/uhci-hcd/utils/malloc32.h	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -40,9 +40,6 @@
 #include <as.h>
 
-#include "slab.h"
-
 #define UHCI_STRCUTURES_ALIGNMENT 16
 #define UHCI_REQUIRED_PAGE_SIZE 4096
-
 
 /** Get physical address translation
@@ -57,6 +54,5 @@
 
 	uintptr_t result;
-	const int ret = as_get_physical_mapping(addr, &result);
-	assert(ret == EOK);
+	int ret = as_get_physical_mapping(addr, &result);
 
 	if (ret != EOK)
@@ -70,10 +66,6 @@
  * @return Address of the alligned and big enough memory place, NULL on failure.
  */
-static inline void * malloc32(size_t size) {
-	if (size <= SLAB_ELEMENT_SIZE)
-		return slab_malloc_g();
-	assert(false);
-	return memalign(UHCI_STRCUTURES_ALIGNMENT, size);
-}
+static inline void * malloc32(size_t size)
+	{ return memalign(UHCI_STRCUTURES_ALIGNMENT, size); }
 /*----------------------------------------------------------------------------*/
 /** Physical mallocator simulator
@@ -81,11 +73,6 @@
  * @param[in] addr Address of the place allocated by malloc32
  */
-static inline void free32(void *addr) {
-	if (!addr)
-		return;
-	if (slab_in_range_g(addr))
-		return slab_free_g(addr);
-	free(addr);
-}
+static inline void free32(void *addr)
+	{ if (addr) free(addr); }
 /*----------------------------------------------------------------------------*/
 /** Create 4KB page mapping
@@ -95,9 +82,10 @@
 static inline void * get_page(void)
 {
-	void *free_address = as_get_mappable_page(UHCI_REQUIRED_PAGE_SIZE);
-	assert(free_address); /* TODO: remove this assert */
+	void * free_address = as_get_mappable_page(UHCI_REQUIRED_PAGE_SIZE);
+	assert(free_address);
 	if (free_address == 0)
 		return NULL;
-	void *ret = as_area_create(free_address, UHCI_REQUIRED_PAGE_SIZE,
+	void* ret =
+	  as_area_create(free_address, UHCI_REQUIRED_PAGE_SIZE,
 		  AS_AREA_READ | AS_AREA_WRITE);
 	if (ret != free_address)
Index: pace/drv/uhci-hcd/utils/slab.c
===================================================================
--- uspace/drv/uhci-hcd/utils/slab.c	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ 	(revision )
@@ -1,141 +1,0 @@
-/*
- * Copyright (c) 2011 Jan Vesely
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - 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.
- * - 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 ``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 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.
- */
-/** @addtogroup usb
- * @{
- */
-/** @file
- * @brief UHCI driver
- */
-#include <as.h>
-#include <assert.h>
-#include <fibril_synch.h>
-#include <usb/debug.h>
-
-#include "slab.h"
-
-#define SLAB_SIZE (PAGE_SIZE * 16)
-#define SLAB_ELEMENT_COUNT (SLAB_SIZE / SLAB_ELEMENT_SIZE)
-
-typedef struct slab {
-	void *page;
-	bool slabs[SLAB_ELEMENT_COUNT];
-	fibril_mutex_t guard;
-} slab_t;
-
-static slab_t global_slab;
-
-static void * slab_malloc(slab_t *intance);
-static bool slab_in_range(slab_t *intance, void *addr);
-static void slab_free(slab_t *intance, void *addr);
-/*----------------------------------------------------------------------------*/
-void * slab_malloc_g(void)
-{
-	return slab_malloc(&global_slab);
-}
-/*----------------------------------------------------------------------------*/
-void slab_free_g(void *addr)
-{
-	return slab_free(&global_slab, addr);
-}
-/*----------------------------------------------------------------------------*/
-bool slab_in_range_g(void *addr)
-{
-	return slab_in_range(&global_slab, addr);
-}
-/*----------------------------------------------------------------------------*/
-static void slab_init(slab_t *instance)
-{
-	static FIBRIL_MUTEX_INITIALIZE(init_mutex);
-	assert(instance);
-	fibril_mutex_lock(&init_mutex);
-	if (instance->page != NULL) {
-		/* already initialized */
-		fibril_mutex_unlock(&init_mutex);
-		return;
-	}
-	fibril_mutex_initialize(&instance->guard);
-	size_t i = 0;
-	for (;i < SLAB_ELEMENT_COUNT; ++i) {
-		instance->slabs[i] = true;
-	}
-	instance->page = as_get_mappable_page(SLAB_SIZE);
-	if (instance->page != NULL) {
-		void* ret =
-		    as_area_create(instance->page, SLAB_SIZE, AS_AREA_READ | AS_AREA_WRITE);
-		if (ret != instance->page) {
-			instance->page = NULL;
-		}
-	}
-	memset(instance->page, 0xa, SLAB_SIZE);
-	fibril_mutex_unlock(&init_mutex);
-	usb_log_debug2("SLAB initialized at %p.\n", instance->page);
-}
-/*----------------------------------------------------------------------------*/
-static void * slab_malloc(slab_t *instance) {
-	assert(instance);
-	if (instance->page == NULL)
-		slab_init(instance);
-
-	fibril_mutex_lock(&instance->guard);
-	void *addr = NULL;
-	size_t i = 0;
-	for (; i < SLAB_ELEMENT_COUNT; ++i) {
-		if (instance->slabs[i]) {
-			instance->slabs[i] = false;
-			addr = (instance->page + (i * SLAB_ELEMENT_SIZE));
-			break;
-		}
-	}
-	fibril_mutex_unlock(&instance->guard);
-
-	return addr;
-}
-/*----------------------------------------------------------------------------*/
-static bool slab_in_range(slab_t *instance, void *addr) {
-	assert(instance);
-	bool in_range = (instance->page != NULL) &&
-		(addr >= instance->page) && (addr < instance->page + SLAB_SIZE);
-	return in_range;
-}
-/*----------------------------------------------------------------------------*/
-static void slab_free(slab_t *instance, void *addr)
-{
-	assert(instance);
-	assert(slab_in_range(instance, addr));
-	memset(addr, 0xa, SLAB_ELEMENT_SIZE);
-
-	const size_t pos = (addr - instance->page) /  SLAB_ELEMENT_SIZE;
-
-	fibril_mutex_lock(&instance->guard);
-	assert(instance->slabs[pos] == false);
-	instance->slabs[pos] = true;
-	fibril_mutex_unlock(&instance->guard);
-}
-/**
- * @}
- */
Index: pace/drv/uhci-hcd/utils/slab.h
===================================================================
--- uspace/drv/uhci-hcd/utils/slab.h	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ 	(revision )
@@ -1,50 +1,0 @@
-/*
- * Copyright (c) 2011 Jan Vesely
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - 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.
- * - 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 ``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 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.
- */
-/** @addtogroup usb
- * @{
- */
-/** @file
- * @brief UHCI driver
- */
-#ifndef DRV_UHCI_SLAB_H
-#define DRV_UHCI_SLAB_H
-
-#include <bool.h>
-
-#define SLAB_ELEMENT_SIZE 1024
-
-void * slab_malloc_g(void);
-
-void slab_free_g(void *addr);
-
-bool slab_in_range_g(void *addr);
-
-#endif
-/**
- * @}
- */
Index: uspace/drv/usbhid/Makefile
===================================================================
--- uspace/drv/usbhid/Makefile	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
+++ uspace/drv/usbhid/Makefile	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -0,0 +1,55 @@
+#
+# Copyright (c) 2010-2011 Vojtech Horky
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - 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.
+# - 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 ``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 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.
+#
+
+USPACE_PREFIX = ../..
+LIBS = $(LIBDRV_PREFIX)/libdrv.a $(LIBUSB_PREFIX)/libusb.a
+EXTRA_CFLAGS += -I$(LIBDRV_PREFIX)/include -I$(LIBUSB_PREFIX)/include -I.
+BINARY = usbhid
+
+STOLEN_LAYOUT_SOURCES = \
+	layout/us_qwerty.c \
+	layout/us_dvorak.c \
+	layout/cz.c
+
+SOURCES = \
+	main.c \
+	conv.c \
+	hidreq.c \
+	kbddev.c \
+	kbdrepeat.c \
+	hiddev.c \
+	$(STOLEN_LAYOUT_SOURCES)
+
+EXTRA_CLEAN = $(STOLEN_LAYOUT_SOURCES)
+
+SRV_KBD = $(USPACE_PREFIX)/srv/hid/kbd
+
+include $(USPACE_PREFIX)/Makefile.common
+
+layout/%.c: $(SRV_KBD)/layout/%.c
+	ln -sfn ../$< $@
Index: uspace/drv/usbhid/conv.c
===================================================================
--- uspace/drv/usbhid/conv.c	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
+++ uspace/drv/usbhid/conv.c	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -0,0 +1,193 @@
+/*
+ * Copyright (c) 2011 Lubos Slovak
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - 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.
+ * - 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 ``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 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.
+ */
+
+/** @addtogroup drvusbhid
+ * @{
+ */
+/** @file
+ * USB scancode parser.
+ */
+
+#include <io/keycode.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <usb/debug.h>
+#include "conv.h"
+
+/**
+ * Mapping between USB HID key codes (from HID Usage Tables) and corresponding
+ * HelenOS key codes.
+ */
+static int scanmap_simple[255] = {
+
+//	[0x29] = KC_BACKTICK,
+
+//	[0x02] = KC_1,
+//	[0x03] = KC_2,
+	[0x04] = KC_A,
+	[0x05] = KC_B,
+	[0x06] = KC_C,
+	[0x07] = KC_D,
+	[0x08] = KC_E,
+	[0x09] = KC_F,
+	[0x0a] = KC_G,
+	[0x0b] = KC_H,
+	[0x0c] = KC_I,
+	[0x0d] = KC_J,
+	[0x0e] = KC_K,
+	[0x0f] = KC_L,
+	[0x10] = KC_M,
+	[0x11] = KC_N,
+	[0x12] = KC_O,
+	[0x13] = KC_P,
+	[0x14] = KC_Q,
+	[0x15] = KC_R,
+	[0x16] = KC_S,
+	[0x17] = KC_T,
+	[0x18] = KC_U,
+	[0x19] = KC_V,
+	[0x1a] = KC_W,
+	[0x1b] = KC_X,
+	[0x1c] = KC_Y,
+	[0x1d] = KC_Z,
+
+	[0x1e] = KC_1,
+	[0x1f] = KC_2,
+	[0x20] = KC_3,
+	[0x21] = KC_4,
+	[0x22] = KC_5,
+	[0x23] = KC_6,
+	[0x24] = KC_7,
+	[0x25] = KC_8,
+	[0x26] = KC_9,
+	[0x27] = KC_0,
+	
+	[0x28] = KC_ENTER,
+	[0x29] = KC_ESCAPE,
+	[0x2a] = KC_BACKSPACE,
+	[0x2b] = KC_TAB,
+	[0x2c] = KC_SPACE,
+
+	[0x2d] = KC_MINUS,  // same as DASH? (- or _)
+	[0x2e] = KC_EQUALS,
+	[0x2f] = KC_LBRACKET,
+	[0x30] = KC_RBRACKET,
+	[0x31] = KC_BACKSLASH,
+	//[0x32] = KC_,	// TODO: HASH??? maybe some as 0x31 - backslash
+	[0x33] = KC_SEMICOLON,
+	[0x34] = KC_QUOTE,  // same as APOSTROPHE? (')
+	[0x35] = KC_BACKTICK,  // same as GRAVE ACCENT?? (`)
+	[0x36] = KC_COMMA,
+	[0x37] = KC_PERIOD,
+	[0x38] = KC_SLASH,
+
+	[0x39] = KC_CAPS_LOCK,
+	
+	[0x3a] = KC_F1,
+	[0x3b] = KC_F2,
+	[0x3c] = KC_F3,
+	[0x3d] = KC_F4,
+	[0x3e] = KC_F5,
+	[0x3f] = KC_F6,
+	[0x40] = KC_F7,
+	[0x41] = KC_F8,
+	[0x42] = KC_F9,
+	[0x43] = KC_F10,
+	[0x44] = KC_F11,
+	[0x45] = KC_F12,
+	
+	[0x46] = KC_PRTSCR,
+	[0x47] = KC_SCROLL_LOCK,
+	[0x48] = KC_PAUSE,
+	[0x49] = KC_INSERT,
+	[0x4a] = KC_HOME,
+	[0x4b] = KC_PAGE_UP,
+	[0x4c] = KC_DELETE,
+	[0x4d] = KC_END,
+	[0x4e] = KC_PAGE_DOWN,
+	[0x4f] = KC_RIGHT,
+	[0x50] = KC_LEFT,
+	[0x51] = KC_DOWN,
+	[0x52] = KC_UP,
+	
+	//[0x64] = // some funny key
+	
+	[0xe0] = KC_LCTRL,
+	[0xe1] = KC_LSHIFT,
+	[0xe2] = KC_LALT,
+	//[0xe3] = KC_L	// TODO: left GUI
+	[0xe4] = KC_RCTRL,
+	[0xe5] = KC_RSHIFT,
+	[0xe6] = KC_RALT,
+	//[0xe7] = KC_R	// TODO: right GUI
+	
+	[0x53] = KC_NUM_LOCK,
+	[0x54] = KC_NSLASH,
+	[0x55] = KC_NTIMES,
+	[0x56] = KC_NMINUS,
+	[0x57] = KC_NPLUS,
+	[0x58] = KC_NENTER,
+	[0x59] = KC_N1,
+	[0x5a] = KC_N2,
+	[0x5b] = KC_N3,
+	[0x5c] = KC_N4,
+	[0x5d] = KC_N5,
+	[0x5e] = KC_N6,
+	[0x5f] = KC_N7,
+	[0x60] = KC_N8,
+	[0x61] = KC_N9,
+	[0x62] = KC_N0,
+	[0x63] = KC_NPERIOD
+	
+};
+
+/**
+ * Translate USB HID key codes (from HID Usage Tables) to generic key codes
+ * recognized by HelenOS.
+ *
+ * @param scancode USB HID key code (from HID Usage Tables).
+ * 
+ * @retval HelenOS key code corresponding to the given USB HID key code.
+ */
+unsigned int usbhid_parse_scancode(int scancode)
+{
+	unsigned int key;
+	int *map = scanmap_simple;
+	size_t map_length = sizeof(scanmap_simple) / sizeof(int);
+
+	if ((scancode < 0) || ((size_t) scancode >= map_length))
+		return -1;
+
+	key = map[scancode];
+	
+	return key;
+}
+
+/**
+ * @}
+ */
Index: uspace/drv/usbhid/conv.h
===================================================================
--- uspace/drv/usbhid/conv.h	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
+++ uspace/drv/usbhid/conv.h	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2011 Lubos Slovak
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - 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.
+ * - 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 ``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 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.
+ */
+
+/** @addtogroup drvusbhid
+ * @{
+ */
+/** @file
+ * USB scancode parser.
+ */
+
+#ifndef USBHID_CONV_H_
+#define USBHID_CONV_H_
+
+unsigned int usbhid_parse_scancode(int scancode);
+
+#endif /* USBHID_CONV_H_ */
+
+/**
+ * @}
+ */
Index: uspace/drv/usbhid/descdump.c
===================================================================
--- uspace/drv/usbhid/descdump.c	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
+++ uspace/drv/usbhid/descdump.c	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -0,0 +1,201 @@
+/*
+ * Copyright (c) 2010 Lubos Slovak
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - 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.
+ * - 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 ``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 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.
+ */
+
+/** @addtogroup drvusbhid
+ * @{
+ */
+/** @file
+ * Descriptor dumping.
+ */
+
+#include <usb/classes/hid.h>
+#include <stdio.h>
+#include <assert.h>
+
+#include "descdump.h"
+
+/*----------------------------------------------------------------------------*/
+
+#define BYTES_PER_LINE 12
+
+/**
+ * Dumps the given buffer in hexadecimal format to standard output.
+ *
+ * @param msg Message to print before the buffer.
+ * @param buffer Buffer to print.
+ * @param length Size of the buffer in bytes.
+ */
+static void dump_buffer(const char *msg, const uint8_t *buffer, size_t length)
+{
+	printf("%s\n", msg);
+
+	size_t i;
+	for (i = 0; i < length; i++) {
+		printf("  0x%02X", buffer[i]);
+		if (((i > 0) && (((i+1) % BYTES_PER_LINE) == 0))
+		    || (i + 1 == length)) {
+			printf("\n");
+		}
+	}
+}
+
+/*----------------------------------------------------------------------------*/
+
+#define INDENT "  "
+
+/**
+ * Print standard configuration descriptor to standard output.
+ *
+ * @param index Index of the descriptor.
+ * @param d Standard configuration descriptor to print.
+ */
+void dump_standard_configuration_descriptor(
+    int index, const usb_standard_configuration_descriptor_t *d)
+{
+	bool self_powered = d->attributes & 64;
+	bool remote_wakeup = d->attributes & 32;
+	
+	printf("Standard configuration descriptor #%d\n", index);
+	printf(INDENT "bLength = %d\n", d->length);
+	printf(INDENT "bDescriptorType = 0x%02x\n", d->descriptor_type);
+	printf(INDENT "wTotalLength = %d\n", d->total_length);
+	printf(INDENT "bNumInterfaces = %d\n", d->interface_count);
+	printf(INDENT "bConfigurationValue = %d\n", d->configuration_number);
+	printf(INDENT "iConfiguration = %d\n", d->str_configuration);
+	printf(INDENT "bmAttributes = %d [%s%s%s]\n", d->attributes,
+	    self_powered ? "self-powered" : "",
+	    (self_powered & remote_wakeup) ? ", " : "",
+	    remote_wakeup ? "remote-wakeup" : "");
+	printf(INDENT "MaxPower = %d (%dmA)\n", d->max_power,
+	    2 * d->max_power);
+	// printf(INDENT " = %d\n", d->);
+}
+
+/**
+ * Print standard interface descriptor to standard output.
+ *
+ * @param d Standard interface descriptor to print.
+ */
+void dump_standard_interface_descriptor(
+    const usb_standard_interface_descriptor_t *d)
+{
+	printf("Standard interface descriptor\n");
+	printf(INDENT "bLength = %d\n", d->length);
+	printf(INDENT "bDescriptorType = 0x%02x\n", d->descriptor_type);
+	printf(INDENT "bInterfaceNumber = %d\n", d->interface_number);
+	printf(INDENT "bAlternateSetting = %d\n", d->alternate_setting);
+	printf(INDENT "bNumEndpoints = %d\n", d->endpoint_count);
+	printf(INDENT "bInterfaceClass = %d\n", d->interface_class);
+	printf(INDENT "bInterfaceSubClass = %d\n", d->interface_subclass);
+	printf(INDENT "bInterfaceProtocol = %d\n", d->interface_protocol);
+	printf(INDENT "iInterface = %d\n", d->str_interface);
+}
+
+/**
+ * Print standard endpoint descriptor to standard output.
+ *
+ * @param d Standard endpoint descriptor to print.
+ */
+void dump_standard_endpoint_descriptor(
+    const usb_standard_endpoint_descriptor_t *d)
+{
+	const char *transfer_type;
+	switch (d->attributes & 3) {
+	case USB_TRANSFER_CONTROL:
+		transfer_type = "control";
+		break;
+	case USB_TRANSFER_ISOCHRONOUS:
+		transfer_type = "isochronous";
+		break;
+	case USB_TRANSFER_BULK:
+		transfer_type = "bulk";
+		break;
+	case USB_TRANSFER_INTERRUPT:
+		transfer_type = "interrupt";
+		break;
+	}
+
+	printf("Standard endpoint descriptor\n");
+	printf(INDENT "bLength = %d\n", d->length);
+	printf(INDENT "bDescriptorType = 0x%02x\n", d->descriptor_type);
+	printf(INDENT "bmAttributes = %d [%s]\n", d->attributes, transfer_type);
+	printf(INDENT "wMaxPacketSize = %d\n", d->max_packet_size);
+	printf(INDENT "bInterval = %d\n", d->poll_interval);
+}
+
+/**
+ * Print standard HID descriptor to standard output.
+ *
+ * @param d Standard HID descriptor to print.
+ */
+void dump_standard_hid_descriptor_header(
+    const usb_standard_hid_descriptor_t *d)
+{
+	printf("Standard HID descriptor\n");
+	printf(INDENT "bLength = %d\n", d->length);
+	printf(INDENT "bDescriptorType = 0x%02x\n", d->descriptor_type);
+	printf(INDENT "bcdHID = %d\n", d->spec_release);
+	printf(INDENT "bCountryCode = %d\n", d->country_code);
+	printf(INDENT "bNumDescriptors = %d\n", d->class_desc_count);
+	printf(INDENT "bDescriptorType = %d\n", d->report_desc_info.type);
+	printf(INDENT "wDescriptorLength = %d\n", d->report_desc_info.length);
+}
+
+/**
+ * Print HID class-specific descriptor header (type and length) to standard 
+ * output.
+ * 
+ * @param d HID class-specific descriptor header to print.
+ */
+void dump_standard_hid_class_descriptor_info(
+    const usb_standard_hid_class_descriptor_info_t *d)
+{
+	printf(INDENT "bDescriptorType = %d\n", d->type);
+	printf(INDENT "wDescriptorLength = %d\n", d->length);
+}
+
+/**
+ * Print HID class-specific descriptor (without the header) to standard output.
+ *
+ * @param index Index of the descriptor.
+ * @param type Type of the HID class-specific descriptor (Report or Physical).
+ * @param d HID class descriptor to print.
+ * @param size Size of the descriptor in bytes.
+ */
+void dump_hid_class_descriptor(int index, uint8_t type, 
+    const uint8_t *d, size_t size )
+{
+	printf("Class-specific descriptor #%d (type: %u)\n", index, type);
+	assert(d != NULL);
+	dump_buffer("", d, size);
+}
+
+/**
+ * @}
+ */
+
Index: uspace/drv/usbhid/descdump.h
===================================================================
--- uspace/drv/usbhid/descdump.h	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
+++ uspace/drv/usbhid/descdump.h	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2010 Lubos Slovak
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - 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.
+ * - 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 ``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 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.
+ */
+
+/** @addtogroup drvusbhid
+ * @{
+ */
+/** @file
+ * Descriptor dumping.
+ */
+
+#ifndef USBHID_DESCDUMP_H_
+#define USBHID_DESCDUMP_H_
+
+#include <usb/descriptor.h>
+#include <usb/classes/hid.h>
+
+void dump_standard_configuration_descriptor(
+    int index, const usb_standard_configuration_descriptor_t *d);
+
+void dump_standard_interface_descriptor(
+    const usb_standard_interface_descriptor_t *d);
+
+void dump_standard_endpoint_descriptor(
+    const usb_standard_endpoint_descriptor_t *d);
+
+void dump_standard_hid_descriptor_header(
+    const usb_standard_hid_descriptor_t *d);
+
+void dump_standard_hid_class_descriptor_info(
+    const usb_standard_hid_class_descriptor_info_t *d);
+
+void dump_hid_class_descriptor(int index, uint8_t type, 
+    const uint8_t *d, size_t size);
+
+#endif /* USBHID_DESCDUMP_H_ */
+
+/**
+ * @}
+ */
Index: uspace/drv/usbhid/hiddev.c
===================================================================
--- uspace/drv/usbhid/hiddev.c	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
+++ uspace/drv/usbhid/hiddev.c	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -0,0 +1,463 @@
+/*
+ * Copyright (c) 2011 Lubos Slovak
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - 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.
+ * - 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 ``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 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.
+ */
+
+/** @addtogroup drvusbhid
+ * @{
+ */
+/**
+ * @file
+ * Generic USB HID device structure and API.
+ */
+
+#include <assert.h>
+#include <errno.h>
+#include <str_error.h>
+
+#include <ddf/driver.h>
+
+#include <usb/dp.h>
+#include <usb/debug.h>
+#include <usb/request.h>
+#include <usb/descriptor.h>
+#include <usb/classes/hid.h>
+#include <usb/pipes.h>
+
+#include "hiddev.h"
+
+/*----------------------------------------------------------------------------*/
+/* Non-API functions                                                          */
+/*----------------------------------------------------------------------------*/
+/**
+ * Retreives HID Report descriptor from the device.
+ *
+ * This function first parses the HID descriptor from the Interface descriptor
+ * to get the size of the Report descriptor and then requests the Report 
+ * descriptor from the device.
+ *
+ * @param hid_dev HID device structure.
+ * @param config_desc Full configuration descriptor (including all nested
+ *                    descriptors).
+ * @param config_desc_size Size of the full configuration descriptor (in bytes).
+ * @param iface_desc Pointer to the interface descriptor inside the full
+ *                   configuration descriptor (@a config_desc) for the interface
+ *                   assigned with this device (@a hid_dev).
+ *
+ * @retval EOK if successful.
+ * @retval ENOENT if no HID descriptor could be found.
+ * @retval EINVAL if the HID descriptor  or HID report descriptor have different
+ *                size than expected.
+ * @retval ENOMEM if some allocation failed.
+ * @return Other value inherited from function usb_request_get_descriptor().
+ *
+ * @sa usb_request_get_descriptor()
+ */
+static int usbhid_dev_get_report_descriptor(usbhid_dev_t *hid_dev, 
+    uint8_t *config_desc, size_t config_desc_size, uint8_t *iface_desc)
+{
+	assert(hid_dev != NULL);
+	assert(config_desc != NULL);
+	assert(config_desc_size != 0);
+	assert(iface_desc != NULL);
+	
+	usb_dp_parser_t parser =  {
+		.nesting = usb_dp_standard_descriptor_nesting
+	};
+	
+	usb_dp_parser_data_t parser_data = {
+		.data = config_desc,
+		.size = config_desc_size,
+		.arg = NULL
+	};
+	
+	/*
+	 * First nested descriptor of interface descriptor.
+	 */
+	uint8_t *d = 
+	    usb_dp_get_nested_descriptor(&parser, &parser_data, iface_desc);
+	
+	/*
+	 * Search through siblings until the HID descriptor is found.
+	 */
+	while (d != NULL && *(d + 1) != USB_DESCTYPE_HID) {
+		d = usb_dp_get_sibling_descriptor(&parser, &parser_data, 
+		    iface_desc, d);
+	}
+	
+	if (d == NULL) {
+		usb_log_fatal("No HID descriptor found!\n");
+		return ENOENT;
+	}
+	
+	if (*d != sizeof(usb_standard_hid_descriptor_t)) {
+		usb_log_fatal("HID descriptor hass wrong size (%u, expected %u"
+		    ")\n", *d, sizeof(usb_standard_hid_descriptor_t));
+		return EINVAL;
+	}
+	
+	usb_standard_hid_descriptor_t *hid_desc = 
+	    (usb_standard_hid_descriptor_t *)d;
+	
+	uint16_t length =  hid_desc->report_desc_info.length;
+	size_t actual_size = 0;
+
+	/*
+	 * Allocate space for the report descriptor.
+	 */
+	hid_dev->report_desc = (uint8_t *)malloc(length);
+	if (hid_dev->report_desc == NULL) {
+		usb_log_fatal("Failed to allocate space for Report descriptor."
+		    "\n");
+		return ENOMEM;
+	}
+	
+	usb_log_debug("Getting Report descriptor, expected size: %u\n", length);
+	
+	/*
+	 * Get the descriptor from the device.
+	 */
+	int rc = usb_request_get_descriptor(&hid_dev->ctrl_pipe,
+	    USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_INTERFACE,
+	    USB_DESCTYPE_HID_REPORT, 0,
+	    hid_dev->iface, hid_dev->report_desc, length, &actual_size);
+
+	if (rc != EOK) {
+		return rc;
+	}
+
+	if (actual_size != length) {
+		free(hid_dev->report_desc);
+		hid_dev->report_desc = NULL;
+		usb_log_fatal("Report descriptor has wrong size (%u, expected "
+		    "%u)\n", actual_size, length);
+		return EINVAL;
+	}
+	
+	hid_dev->report_desc_size = length;
+	
+	usb_log_debug("Done.\n");
+	
+	return EOK;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+ * Retreives descriptors from the device, initializes pipes and stores 
+ * important information from descriptors.
+ *
+ * Initializes the polling pipe described by the given endpoint description
+ * (@a poll_ep_desc).
+ * 
+ * Information retreived from descriptors and stored in the HID device structure:
+ *    - Assigned interface number (the interface controlled by this instance of
+ *                                 the driver)
+ *    - Polling interval (from the interface descriptor)
+ *    - Report descriptor
+ *
+ * @param hid_dev HID device structure to be initialized.
+ * @param poll_ep_desc Description of the polling (Interrupt In) endpoint
+ *                     that has to be present in the device in order to
+ *                     successfuly initialize the structure.
+ *
+ * @sa usb_pipe_initialize_from_configuration(), 
+ *     usbhid_dev_get_report_descriptor()
+ */
+static int usbhid_dev_process_descriptors(usbhid_dev_t *hid_dev, 
+    usb_endpoint_description_t *poll_ep_desc) 
+{
+	assert(hid_dev != NULL);
+	
+	usb_log_debug("Processing descriptors...\n");
+	
+	int rc;
+
+	uint8_t *descriptors = NULL;
+	size_t descriptors_size;
+	rc = usb_request_get_full_configuration_descriptor_alloc(
+	    &hid_dev->ctrl_pipe, 0, (void **) &descriptors, &descriptors_size);
+	if (rc != EOK) {
+		usb_log_error("Failed to retrieve config descriptor: %s.\n",
+		    str_error(rc));
+		return rc;
+	}
+	
+	/*
+	 * Initialize the interrupt in endpoint.
+	 */
+	usb_endpoint_mapping_t endpoint_mapping[1] = {
+		{
+			.pipe = &hid_dev->poll_pipe,
+			.description = poll_ep_desc,
+			.interface_no =
+			    usb_device_get_assigned_interface(hid_dev->device)
+		}
+	};
+	
+	rc = usb_pipe_initialize_from_configuration(
+	    endpoint_mapping, 1, descriptors, descriptors_size,
+	    &hid_dev->wire);
+	
+	if (rc != EOK) {
+		usb_log_error("Failed to initialize poll pipe: %s.\n",
+		    str_error(rc));
+		free(descriptors);
+		return rc;
+	}
+	
+	if (!endpoint_mapping[0].present) {
+		usb_log_warning("Not accepting device.\n");
+		free(descriptors);
+		return EREFUSED;  // probably not very good return value
+	}
+	
+	usb_log_debug("Accepted device. Saving interface, and getting Report"
+	    " descriptor.\n");
+	
+	/*
+	 * Save assigned interface number.
+	 */
+	if (endpoint_mapping[0].interface_no < 0) {
+		usb_log_error("Bad interface number.\n");
+		free(descriptors);
+		return EINVAL;
+	}
+	
+	hid_dev->iface = endpoint_mapping[0].interface_no;
+	
+	assert(endpoint_mapping[0].interface != NULL);
+	
+	/*
+	 * Save polling interval
+	 */
+	hid_dev->poll_interval = endpoint_mapping[0].descriptor->poll_interval;
+	assert(hid_dev->poll_interval > 0);
+	
+	rc = usbhid_dev_get_report_descriptor(hid_dev,
+	    descriptors, descriptors_size,
+	    (uint8_t *)endpoint_mapping[0].interface);
+	
+	free(descriptors);
+	
+	if (rc != EOK) {
+		usb_log_warning("Problem with getting Report descriptor: %s.\n",
+		    str_error(rc));
+		return rc;
+	}
+	
+	rc = usb_hid_parse_report_descriptor(hid_dev->parser, 
+	    hid_dev->report_desc, hid_dev->report_desc_size);
+	if (rc != EOK) {
+		usb_log_warning("Problem parsing Report descriptor: %s.\n",
+		    str_error(rc));
+		return rc;
+	}
+	
+	usb_hid_descriptor_print(hid_dev->parser);
+	
+	return EOK;
+}
+
+/*----------------------------------------------------------------------------*/
+/* API functions                                                              */
+/*----------------------------------------------------------------------------*/
+/**
+ * Creates new uninitialized HID device structure.
+ *
+ * @return Pointer to the new HID device structure, or NULL if an error occured.
+ */
+usbhid_dev_t *usbhid_dev_new(void)
+{
+	usbhid_dev_t *dev = 
+	    (usbhid_dev_t *)malloc(sizeof(usbhid_dev_t));
+
+	if (dev == NULL) {
+		usb_log_fatal("No memory!\n");
+		return NULL;
+	}
+	
+	memset(dev, 0, sizeof(usbhid_dev_t));
+	
+	dev->parser = (usb_hid_report_parser_t *)(malloc(sizeof(
+	    usb_hid_report_parser_t)));
+	if (dev->parser == NULL) {
+		usb_log_fatal("No memory!\n");
+		free(dev);
+		return NULL;
+	}
+	
+	dev->initialized = 0;
+	
+	return dev;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+ * Properly destroys the HID device structure.
+ *
+ * @note Currently does not clean-up the used pipes, as there are no functions
+ *       offering such functionality.
+ * 
+ * @param hid_dev Pointer to the structure to be destroyed.
+ */
+void usbhid_dev_free(usbhid_dev_t **hid_dev)
+{
+	if (hid_dev == NULL || *hid_dev == NULL) {
+		return;
+	}
+	
+	// free the report descriptor
+	if ((*hid_dev)->report_desc != NULL) {
+		free((*hid_dev)->report_desc);
+	}
+	// destroy the parser
+	if ((*hid_dev)->parser != NULL) {
+		usb_hid_free_report_parser((*hid_dev)->parser);
+	}
+	
+	// TODO: cleanup pipes
+	
+	free(*hid_dev);
+	*hid_dev = NULL;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+ * Initializes HID device structure.
+ *
+ * @param hid_dev HID device structure to be initialized.
+ * @param dev DDF device representing the HID device.
+ * @param poll_ep_desc Description of the polling (Interrupt In) endpoint
+ *                     that has to be present in the device in order to
+ *                     successfuly initialize the structure.
+ *
+ * @retval EOK if successful.
+ * @retval EINVAL if some argument is missing.
+ * @return Other value inherited from one of functions 
+ *         usb_device_connection_initialize_from_device(),
+ *         usb_pipe_initialize_default_control(),
+ *         usb_pipe_start_session(), usb_pipe_end_session(),
+ *         usbhid_dev_process_descriptors().
+ *
+ * @sa usbhid_dev_process_descriptors()
+ */
+int usbhid_dev_init(usbhid_dev_t *hid_dev, ddf_dev_t *dev, 
+    usb_endpoint_description_t *poll_ep_desc)
+{
+	usb_log_debug("Initializing HID device structure.\n");
+	
+	if (hid_dev == NULL) {
+		usb_log_error("Failed to init HID device structure: no "
+		    "structure given.\n");
+		return EINVAL;
+	}
+	
+	if (dev == NULL) {
+		usb_log_error("Failed to init HID device structure: no device"
+		    " given.\n");
+		return EINVAL;
+	}
+	
+	if (poll_ep_desc == NULL) {
+		usb_log_error("No poll endpoint description given.\n");
+		return EINVAL;
+	}
+	
+	hid_dev->device = dev;
+	
+	int rc;
+
+	/*
+	 * Initialize the backing connection to the host controller.
+	 */
+	rc = usb_device_connection_initialize_from_device(&hid_dev->wire, dev);
+	if (rc != EOK) {
+		usb_log_error("Problem initializing connection to device: %s."
+		    "\n", str_error(rc));
+		return rc;
+	}
+
+	/*
+	 * Initialize device pipes.
+	 */
+	rc = usb_pipe_initialize_default_control(&hid_dev->ctrl_pipe,
+	    &hid_dev->wire);
+	if (rc != EOK) {
+		usb_log_error("Failed to initialize default control pipe: %s."
+		    "\n", str_error(rc));
+		return rc;
+	}
+	rc = usb_pipe_probe_default_control(&hid_dev->ctrl_pipe);
+	if (rc != EOK) {
+		usb_log_error("Probing default control pipe failed: %s.\n",
+		    str_error(rc));
+		return rc;
+	}
+
+	/*
+	 * Initialize the report parser.
+	 */
+	rc = usb_hid_parser_init(hid_dev->parser);
+	if (rc != EOK) {
+		usb_log_error("Failed to initialize report parser.\n");
+		return rc;
+	}
+
+	/*
+	 * Get descriptors, parse descriptors and save endpoints.
+	 */
+	rc = usb_pipe_start_session(&hid_dev->ctrl_pipe);
+	if (rc != EOK) {
+		usb_log_error("Failed to start session on the control pipe: %s"
+		    ".\n", str_error(rc));
+		return rc;
+	}
+	
+	rc = usbhid_dev_process_descriptors(hid_dev, poll_ep_desc);
+	if (rc != EOK) {
+		/* TODO: end session?? */
+		usb_pipe_end_session(&hid_dev->ctrl_pipe);
+		usb_log_error("Failed to process descriptors: %s.\n",
+		    str_error(rc));
+		return rc;
+	}
+	
+	rc = usb_pipe_end_session(&hid_dev->ctrl_pipe);
+	if (rc != EOK) {
+		usb_log_warning("Failed to start session on the control pipe: "
+		    "%s.\n", str_error(rc));
+		return rc;
+	}
+	
+	hid_dev->initialized = 1;
+	usb_log_debug("HID device structure initialized.\n");
+	
+	return EOK;
+}
+
+/**
+ * @}
+ */
Index: uspace/drv/usbhid/hiddev.h
===================================================================
--- uspace/drv/usbhid/hiddev.h	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
+++ uspace/drv/usbhid/hiddev.h	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 2011 Lubos Slovak
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - 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.
+ * - 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 ``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 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.
+ */
+
+/** @addtogroup drvusbhid
+ * @{
+ */
+/** @file
+ * Generic USB HID device structure and API.
+ *
+ * @todo Add function for parsing report - this is generic HID function, not
+ *       keyboard-specific, as the report parser is also generic.
+ * @todo Add function for polling as that is also a generic HID process.
+ * @todo Add interrupt in pipe to the structure.
+ */
+
+#ifndef USBHID_HIDDEV_H_
+#define USBHID_HIDDEV_H_
+
+#include <stdint.h>
+
+#include <ddf/driver.h>
+
+#include <usb/classes/hid.h>
+#include <usb/pipes.h>
+#include <usb/classes/hidparser.h>
+
+/*----------------------------------------------------------------------------*/
+
+/**
+ * USB/HID device type.
+ *
+ * Holds a reference to DDF device structure, and HID-specific data, such 
+ * as information about used pipes (one Control pipe and one Interrupt In pipe),
+ * polling interval, assigned interface number, Report descriptor and a
+ * reference to the Report parser used to parse incoming reports and composing
+ * outgoing reports.
+ */
+typedef struct {
+	/** DDF device representing the controlled HID device. */
+	ddf_dev_t *device;
+
+	/** Physical connection to the device. */
+	usb_device_connection_t wire;
+	/** USB pipe corresponding to the default Control endpoint. */
+	usb_pipe_t ctrl_pipe;
+	/** USB pipe corresponding to the Interrupt In (polling) pipe. */
+	usb_pipe_t poll_pipe;
+	
+	/** Polling interval retreived from the Interface descriptor. */
+	short poll_interval;
+	
+	/** Interface number assigned to this device. */
+	uint16_t iface;
+	
+	/** Report descriptor. */
+	uint8_t *report_desc;
+
+	size_t report_desc_size;
+
+	/** HID Report parser. */
+	usb_hid_report_parser_t *parser;
+	
+	/** State of the structure (for checking before use). */
+	int initialized;
+} usbhid_dev_t;
+
+/*----------------------------------------------------------------------------*/
+
+usbhid_dev_t *usbhid_dev_new(void);
+
+void usbhid_dev_free(usbhid_dev_t **hid_dev);
+
+int usbhid_dev_init(usbhid_dev_t *hid_dev, ddf_dev_t *dev,
+    usb_endpoint_description_t *poll_ep_desc);
+
+/*----------------------------------------------------------------------------*/
+
+#endif /* USBHID_HIDDEV_H_ */
+
+/**
+ * @}
+ */
Index: uspace/drv/usbhid/hidreq.c
===================================================================
--- uspace/drv/usbhid/hidreq.c	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
+++ uspace/drv/usbhid/hidreq.c	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -0,0 +1,446 @@
+/*
+ * Copyright (c) 2011 Lubos Slovak
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - 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.
+ * - 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 ``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 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.
+ */
+
+/** @addtogroup drvusbhid
+ * @{
+ */
+/** @file
+ * HID class-specific requests.
+ */
+
+#include <stdint.h>
+#include <errno.h>
+#include <str_error.h>
+
+#include <usb/classes/hid.h>
+#include <usb/debug.h>
+#include <usb/request.h>
+
+#include "hidreq.h"
+#include "hiddev.h"
+
+/*----------------------------------------------------------------------------*/
+/**
+ * Send Set Report request to the HID device.
+ *
+ * @param hid_dev HID device to send the request to.
+ * @param type Type of the report.
+ * @param buffer Report data.
+ * @param buf_size Report data size (in bytes).
+ *
+ * @retval EOK if successful.
+ * @retval EINVAL if no HID device is given.
+ * @return Other value inherited from one of functions 
+ *         usb_pipe_start_session(), usb_pipe_end_session(),
+ *         usb_control_request_set().
+ */
+int usbhid_req_set_report(usbhid_dev_t *hid_dev,
+    usb_hid_report_type_t type, uint8_t *buffer, size_t buf_size)
+{
+	if (hid_dev == NULL) {
+		usb_log_error("usbhid_req_set_report(): no HID device structure"
+		    " given.\n");
+		return EINVAL;
+	}
+	
+	/*
+	 * No need for checking other parameters, as they are checked in
+	 * the called function (usb_control_request_set()).
+	 */
+	
+	int rc, sess_rc;
+	
+	sess_rc = usb_pipe_start_session(&hid_dev->ctrl_pipe);
+	if (sess_rc != EOK) {
+		usb_log_warning("Failed to start a session: %s.\n",
+		    str_error(sess_rc));
+		return sess_rc;
+	}
+	
+	uint16_t value = 0;
+	value |= (type << 8);
+
+	usb_log_debug("Sending Set_Report request to the device.\n");
+	
+	rc = usb_control_request_set(&hid_dev->ctrl_pipe, 
+	    USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE, 
+	    USB_HIDREQ_SET_REPORT, value, hid_dev->iface, buffer, buf_size);
+
+	sess_rc = usb_pipe_end_session(&hid_dev->ctrl_pipe);
+
+	if (rc != EOK) {
+		usb_log_warning("Error sending output report to the keyboard: "
+		    "%s.\n", str_error(rc));
+		return rc;
+	}
+
+	if (sess_rc != EOK) {
+		usb_log_warning("Error closing session: %s.\n",
+		    str_error(sess_rc));
+		return sess_rc;
+	}
+	
+	return EOK;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+ * Send Set Protocol request to the HID device.
+ *
+ * @param hid_dev HID device to send the request to.
+ * @param protocol Protocol to set.
+ *
+ * @retval EOK if successful.
+ * @retval EINVAL if no HID device is given.
+ * @return Other value inherited from one of functions 
+ *         usb_pipe_start_session(), usb_pipe_end_session(),
+ *         usb_control_request_set().
+ */
+int usbhid_req_set_protocol(usbhid_dev_t *hid_dev, usb_hid_protocol_t protocol)
+{
+	if (hid_dev == NULL) {
+		usb_log_error("usbhid_req_set_protocol(): no HID device "
+		    "structure given.\n");
+		return EINVAL;
+	}
+	
+	/*
+	 * No need for checking other parameters, as they are checked in
+	 * the called function (usb_control_request_set()).
+	 */
+	
+	int rc, sess_rc;
+	
+	sess_rc = usb_pipe_start_session(&hid_dev->ctrl_pipe);
+	if (sess_rc != EOK) {
+		usb_log_warning("Failed to start a session: %s.\n",
+		    str_error(sess_rc));
+		return sess_rc;
+	}
+
+	usb_log_debug("Sending Set_Protocol request to the device ("
+	    "protocol: %d, iface: %d).\n", protocol, hid_dev->iface);
+	
+	rc = usb_control_request_set(&hid_dev->ctrl_pipe, 
+	    USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE, 
+	    USB_HIDREQ_SET_PROTOCOL, protocol, hid_dev->iface, NULL, 0);
+
+	sess_rc = usb_pipe_end_session(&hid_dev->ctrl_pipe);
+
+	if (rc != EOK) {
+		usb_log_warning("Error sending output report to the keyboard: "
+		    "%s.\n", str_error(rc));
+		return rc;
+	}
+
+	if (sess_rc != EOK) {
+		usb_log_warning("Error closing session: %s.\n",
+		    str_error(sess_rc));
+		return sess_rc;
+	}
+	
+	return EOK;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+ * Send Set Idle request to the HID device.
+ *
+ * @param hid_dev HID device to send the request to.
+ * @param duration Duration value (is multiplicated by 4 by the device to
+ *                 get real duration in miliseconds).
+ *
+ * @retval EOK if successful.
+ * @retval EINVAL if no HID device is given.
+ * @return Other value inherited from one of functions 
+ *         usb_pipe_start_session(), usb_pipe_end_session(),
+ *         usb_control_request_set().
+ */
+int usbhid_req_set_idle(usbhid_dev_t *hid_dev, uint8_t duration)
+{
+	if (hid_dev == NULL) {
+		usb_log_error("usbhid_req_set_idle(): no HID device "
+		    "structure given.\n");
+		return EINVAL;
+	}
+	
+	/*
+	 * No need for checking other parameters, as they are checked in
+	 * the called function (usb_control_request_set()).
+	 */
+	
+	int rc, sess_rc;
+	
+	sess_rc = usb_pipe_start_session(&hid_dev->ctrl_pipe);
+	if (sess_rc != EOK) {
+		usb_log_warning("Failed to start a session: %s.\n",
+		    str_error(sess_rc));
+		return sess_rc;
+	}
+
+	usb_log_debug("Sending Set_Idle request to the device ("
+	    "duration: %u, iface: %d).\n", duration, hid_dev->iface);
+	
+	uint16_t value = duration << 8;
+	
+	rc = usb_control_request_set(&hid_dev->ctrl_pipe, 
+	    USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE, 
+	    USB_HIDREQ_SET_IDLE, value, hid_dev->iface, NULL, 0);
+
+	sess_rc = usb_pipe_end_session(&hid_dev->ctrl_pipe);
+
+	if (rc != EOK) {
+		usb_log_warning("Error sending output report to the keyboard: "
+		    "%s.\n", str_error(rc));
+		return rc;
+	}
+
+	if (sess_rc != EOK) {
+		usb_log_warning("Error closing session: %s.\n",
+		    str_error(sess_rc));
+		return sess_rc;
+	}
+	
+	return EOK;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+ * Send Get Report request to the HID device.
+ *
+ * @param[in] hid_dev HID device to send the request to.
+ * @param[in] type Type of the report.
+ * @param[in][out] buffer Buffer for the report data.
+ * @param[in] buf_size Size of the buffer (in bytes).
+ * @param[out] actual_size Actual size of report received from the device 
+ *                         (in bytes).
+ *
+ * @retval EOK if successful.
+ * @retval EINVAL if no HID device is given.
+ * @return Other value inherited from one of functions 
+ *         usb_pipe_start_session(), usb_pipe_end_session(),
+ *         usb_control_request_set().
+ */
+int usbhid_req_get_report(usbhid_dev_t *hid_dev, usb_hid_report_type_t type, 
+    uint8_t *buffer, size_t buf_size, size_t *actual_size)
+{
+	if (hid_dev == NULL) {
+		usb_log_error("usbhid_req_set_report(): no HID device structure"
+		    " given.\n");
+		return EINVAL;
+	}
+	
+	/*
+	 * No need for checking other parameters, as they are checked in
+	 * the called function (usb_control_request_set()).
+	 */
+	
+	int rc, sess_rc;
+	
+	sess_rc = usb_pipe_start_session(&hid_dev->ctrl_pipe);
+	if (sess_rc != EOK) {
+		usb_log_warning("Failed to start a session: %s.\n",
+		    str_error(sess_rc));
+		return sess_rc;
+	}
+
+	uint16_t value = 0;
+	value |= (type << 8);
+	
+	usb_log_debug("Sending Get_Report request to the device.\n");
+	
+	rc = usb_control_request_get(&hid_dev->ctrl_pipe, 
+	    USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE, 
+	    USB_HIDREQ_GET_REPORT, value, hid_dev->iface, buffer, buf_size,
+	    actual_size);
+
+	sess_rc = usb_pipe_end_session(&hid_dev->ctrl_pipe);
+
+	if (rc != EOK) {
+		usb_log_warning("Error sending output report to the keyboard: "
+		    "%s.\n", str_error(rc));
+		return rc;
+	}
+
+	if (sess_rc != EOK) {
+		usb_log_warning("Error closing session: %s.\n",
+		    str_error(sess_rc));
+		return sess_rc;
+	}
+	
+	return EOK;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+ * Send Get Protocol request to the HID device.
+ *
+ * @param[in] hid_dev HID device to send the request to.
+ * @param[out] protocol Current protocol of the device.
+ *
+ * @retval EOK if successful.
+ * @retval EINVAL if no HID device is given.
+ * @return Other value inherited from one of functions 
+ *         usb_pipe_start_session(), usb_pipe_end_session(),
+ *         usb_control_request_set().
+ */
+int usbhid_req_get_protocol(usbhid_dev_t *hid_dev, usb_hid_protocol_t *protocol)
+{
+	if (hid_dev == NULL) {
+		usb_log_error("usbhid_req_set_protocol(): no HID device "
+		    "structure given.\n");
+		return EINVAL;
+	}
+	
+	/*
+	 * No need for checking other parameters, as they are checked in
+	 * the called function (usb_control_request_set()).
+	 */
+	
+	int rc, sess_rc;
+	
+	sess_rc = usb_pipe_start_session(&hid_dev->ctrl_pipe);
+	if (sess_rc != EOK) {
+		usb_log_warning("Failed to start a session: %s.\n",
+		    str_error(sess_rc));
+		return sess_rc;
+	}
+
+	usb_log_debug("Sending Get_Protocol request to the device ("
+	    "iface: %d).\n", hid_dev->iface);
+	
+	uint8_t buffer[1];
+	size_t actual_size = 0;
+	
+	rc = usb_control_request_get(&hid_dev->ctrl_pipe, 
+	    USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE, 
+	    USB_HIDREQ_GET_PROTOCOL, 0, hid_dev->iface, buffer, 1, &actual_size);
+
+	sess_rc = usb_pipe_end_session(&hid_dev->ctrl_pipe);
+
+	if (rc != EOK) {
+		usb_log_warning("Error sending output report to the keyboard: "
+		    "%s.\n", str_error(rc));
+		return rc;
+	}
+
+	if (sess_rc != EOK) {
+		usb_log_warning("Error closing session: %s.\n",
+		    str_error(sess_rc));
+		return sess_rc;
+	}
+	
+	if (actual_size != 1) {
+		usb_log_warning("Wrong data size: %zu, expected: 1.\n",
+			actual_size);
+		return ELIMIT;
+	}
+	
+	*protocol = buffer[0];
+	
+	return EOK;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+ * Send Get Idle request to the HID device.
+ *
+ * @param[in] hid_dev HID device to send the request to.
+ * @param[out] duration Duration value (multiplicate by 4 to get real duration
+ *                      in miliseconds).
+ *
+ * @retval EOK if successful.
+ * @retval EINVAL if no HID device is given.
+ * @return Other value inherited from one of functions 
+ *         usb_pipe_start_session(), usb_pipe_end_session(),
+ *         usb_control_request_set().
+ */
+int usbhid_req_get_idle(usbhid_dev_t *hid_dev, uint8_t *duration)
+{
+	if (hid_dev == NULL) {
+		usb_log_error("usbhid_req_set_idle(): no HID device "
+		    "structure given.\n");
+		return EINVAL;
+	}
+	
+	/*
+	 * No need for checking other parameters, as they are checked in
+	 * the called function (usb_control_request_set()).
+	 */
+	
+	int rc, sess_rc;
+	
+	sess_rc = usb_pipe_start_session(&hid_dev->ctrl_pipe);
+	if (sess_rc != EOK) {
+		usb_log_warning("Failed to start a session: %s.\n",
+		    str_error(sess_rc));
+		return sess_rc;
+	}
+
+	usb_log_debug("Sending Get_Idle request to the device ("
+	    "iface: %d).\n", hid_dev->iface);
+	
+	uint16_t value = 0;
+	uint8_t buffer[1];
+	size_t actual_size = 0;
+	
+	rc = usb_control_request_get(&hid_dev->ctrl_pipe, 
+	    USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE, 
+	    USB_HIDREQ_GET_IDLE, value, hid_dev->iface, buffer, 1, 
+	    &actual_size);
+
+	sess_rc = usb_pipe_end_session(&hid_dev->ctrl_pipe);
+
+	if (rc != EOK) {
+		usb_log_warning("Error sending output report to the keyboard: "
+		    "%s.\n", str_error(rc));
+		return rc;
+	}
+
+	if (sess_rc != EOK) {
+		usb_log_warning("Error closing session: %s.\n",
+		    str_error(sess_rc));
+		return sess_rc;
+	}
+	
+	if (actual_size != 1) {
+		usb_log_warning("Wrong data size: %zu, expected: 1.\n",
+			actual_size);
+		return ELIMIT;
+	}
+	
+	*duration = buffer[0];
+	
+	return EOK;
+}
+
+/*----------------------------------------------------------------------------*/
+
+/**
+ * @}
+ */
Index: uspace/drv/usbhid/hidreq.h
===================================================================
--- uspace/drv/usbhid/hidreq.h	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
+++ uspace/drv/usbhid/hidreq.h	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2011 Lubos Slovak
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - 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.
+ * - 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 ``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 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.
+ */
+
+/** @addtogroup drvusbhid
+ * @{
+ */
+/** @file
+ * HID class-specific requests.
+ */
+
+#ifndef USBHID_HIDREQ_H_
+#define USBHID_HIDREQ_H_
+
+#include <stdint.h>
+
+#include <usb/classes/hid.h>
+
+#include "hiddev.h"
+
+/*----------------------------------------------------------------------------*/
+
+int usbhid_req_set_report(usbhid_dev_t *hid_dev,
+    usb_hid_report_type_t type, uint8_t *buffer, size_t buf_size);
+
+int usbhid_req_set_protocol(usbhid_dev_t *hid_dev, usb_hid_protocol_t protocol);
+
+int usbhid_req_set_idle(usbhid_dev_t *hid_dev, uint8_t duration);
+
+int usbhid_req_get_report(usbhid_dev_t *hid_dev, usb_hid_report_type_t type, 
+    uint8_t *buffer, size_t buf_size, size_t *actual_size);
+
+int usbhid_req_get_protocol(usbhid_dev_t *hid_dev, usb_hid_protocol_t *protocol);
+
+int usbhid_req_get_idle(usbhid_dev_t *hid_dev, uint8_t *duration);
+
+/*----------------------------------------------------------------------------*/
+
+#endif /* USBHID_HIDREQ_H_ */
+
+/**
+ * @}
+ */
Index: uspace/drv/usbhid/kbd.h
===================================================================
--- uspace/drv/usbhid/kbd.h	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
+++ uspace/drv/usbhid/kbd.h	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -0,0 +1,5 @@
+/*
+ * Dummy file because of shared layout sources.
+ *
+ * Do not delete.
+ */
Index: uspace/drv/usbhid/kbddev.c
===================================================================
--- uspace/drv/usbhid/kbddev.c	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
+++ uspace/drv/usbhid/kbddev.c	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -0,0 +1,1026 @@
+/*
+ * Copyright (c) 2011 Lubos Slovak
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - 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.
+ * - 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 ``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 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.
+ */
+
+/** @addtogroup drvusbhid
+ * @{
+ */
+/**
+ * @file
+ * USB HID keyboard device structure and API.
+ */
+
+#include <errno.h>
+#include <str_error.h>
+#include <stdio.h>
+
+#include <io/keycode.h>
+#include <ipc/kbd.h>
+#include <async.h>
+#include <fibril.h>
+#include <fibril_synch.h>
+
+#include <usb/usb.h>
+#include <usb/classes/hid.h>
+#include <usb/pipes.h>
+#include <usb/debug.h>
+#include <usb/classes/hidparser.h>
+#include <usb/classes/classes.h>
+#include <usb/classes/hidut.h>
+
+#include "kbddev.h"
+#include "hiddev.h"
+#include "hidreq.h"
+#include "layout.h"
+#include "conv.h"
+#include "kbdrepeat.h"
+
+/*----------------------------------------------------------------------------*/
+/** Default modifiers when the keyboard is initialized. */
+static const unsigned DEFAULT_ACTIVE_MODS = KM_NUM_LOCK;
+
+/** Boot protocol report size (key part). */
+static const size_t BOOTP_REPORT_SIZE = 6;
+
+/** Boot protocol total report size. */
+static const size_t BOOTP_BUFFER_SIZE = 8;
+
+/** Boot protocol output report size. */
+static const size_t BOOTP_BUFFER_OUT_SIZE = 1;
+
+/** Boot protocol error key code. */
+static const uint8_t BOOTP_ERROR_ROLLOVER = 1;
+
+/** Default idle rate for keyboards. */
+static const uint8_t IDLE_RATE = 0;
+
+/** Delay before a pressed key starts auto-repeating. */
+static const unsigned int DEFAULT_DELAY_BEFORE_FIRST_REPEAT = 500 * 1000;
+
+/** Delay between two repeats of a pressed key when auto-repeating. */
+static const unsigned int DEFAULT_REPEAT_DELAY = 50 * 1000;
+
+/** Keyboard polling endpoint description for boot protocol class. */
+static usb_endpoint_description_t poll_endpoint_description = {
+	.transfer_type = USB_TRANSFER_INTERRUPT,
+	.direction = USB_DIRECTION_IN,
+	.interface_class = USB_CLASS_HID,
+	.interface_subclass = USB_HID_SUBCLASS_BOOT,
+	.interface_protocol = USB_HID_PROTOCOL_KEYBOARD,
+	.flags = 0
+};
+
+typedef enum usbhid_kbd_flags {
+	USBHID_KBD_STATUS_UNINITIALIZED = 0,
+	USBHID_KBD_STATUS_INITIALIZED = 1,
+	USBHID_KBD_STATUS_TO_DESTROY = -1
+} usbhid_kbd_flags;
+
+/*----------------------------------------------------------------------------*/
+/* Keyboard layouts                                                           */
+/*----------------------------------------------------------------------------*/
+
+#define NUM_LAYOUTS 3
+
+/** Keyboard layout map. */
+static layout_op_t *layout[NUM_LAYOUTS] = {
+	&us_qwerty_op,
+	&us_dvorak_op,
+	&cz_op
+};
+
+static int active_layout = 0;
+
+/*----------------------------------------------------------------------------*/
+/* Modifier constants                                                         */
+/*----------------------------------------------------------------------------*/
+/** Mapping of USB modifier key codes to generic modifier key codes. */
+static const keycode_t usbhid_modifiers_keycodes[USB_HID_MOD_COUNT] = {
+	KC_LCTRL,         /* USB_HID_MOD_LCTRL */
+	KC_LSHIFT,        /* USB_HID_MOD_LSHIFT */
+	KC_LALT,          /* USB_HID_MOD_LALT */
+	0,                /* USB_HID_MOD_LGUI */
+	KC_RCTRL,         /* USB_HID_MOD_RCTRL */
+	KC_RSHIFT,        /* USB_HID_MOD_RSHIFT */
+	KC_RALT,          /* USB_HID_MOD_RALT */
+	0,                /* USB_HID_MOD_RGUI */
+};
+
+typedef enum usbhid_lock_code {
+	USBHID_LOCK_NUM = 0x53,
+	USBHID_LOCK_CAPS = 0x39,
+	USBHID_LOCK_SCROLL = 0x47,
+	USBHID_LOCK_COUNT = 3
+} usbhid_lock_code;
+
+static const usbhid_lock_code usbhid_lock_codes[USBHID_LOCK_COUNT] = {
+	USBHID_LOCK_NUM,
+	USBHID_LOCK_CAPS,
+	USBHID_LOCK_SCROLL
+};
+
+/*----------------------------------------------------------------------------*/
+/* IPC method handler                                                         */
+/*----------------------------------------------------------------------------*/
+
+static void default_connection_handler(ddf_fun_t *, ipc_callid_t, ipc_call_t *);
+static ddf_dev_ops_t keyboard_ops = {
+	.default_handler = default_connection_handler
+};
+
+/** 
+ * Default handler for IPC methods not handled by DDF.
+ *
+ * Currently recognizes only one method (IPC_M_CONNECT_TO_ME), in which case it
+ * assumes the caller is the console and thus it stores IPC phone to it for 
+ * later use by the driver to notify about key events.
+ *
+ * @param fun Device function handling the call.
+ * @param icallid Call id.
+ * @param icall Call data.
+ */
+void default_connection_handler(ddf_fun_t *fun,
+    ipc_callid_t icallid, ipc_call_t *icall)
+{
+	sysarg_t method = IPC_GET_IMETHOD(*icall);
+	
+	usbhid_kbd_t *kbd_dev = (usbhid_kbd_t *)fun->driver_data;
+	assert(kbd_dev != NULL);
+
+	if (method == IPC_M_CONNECT_TO_ME) {
+		int callback = IPC_GET_ARG5(*icall);
+
+		if (kbd_dev->console_phone != -1) {
+			async_answer_0(icallid, ELIMIT);
+			return;
+		}
+
+		kbd_dev->console_phone = callback;
+		async_answer_0(icallid, EOK);
+		return;
+	}
+	
+	async_answer_0(icallid, EINVAL);
+}
+
+/*----------------------------------------------------------------------------*/
+/* Key processing functions                                                   */
+/*----------------------------------------------------------------------------*/
+/**
+ * Handles turning of LED lights on and off.
+ *
+ * In case of USB keyboards, the LEDs are handled in the driver, not in the 
+ * device. When there should be a change (lock key was pressed), the driver
+ * uses a Set_Report request sent to the device to set the state of the LEDs.
+ *
+ * This functions sets the LED lights according to current settings of modifiers
+ * kept in the keyboard device structure.
+ *
+ * @param kbd_dev Keyboard device structure.
+ */
+static void usbhid_kbd_set_led(usbhid_kbd_t *kbd_dev) 
+{
+	uint8_t buffer[BOOTP_BUFFER_OUT_SIZE];
+	int rc= 0;
+	
+	memset(buffer, 0, BOOTP_BUFFER_OUT_SIZE);
+	uint8_t leds = 0;
+
+	if (kbd_dev->mods & KM_NUM_LOCK) {
+		leds |= USB_HID_LED_NUM_LOCK;
+	}
+	
+	if (kbd_dev->mods & KM_CAPS_LOCK) {
+		leds |= USB_HID_LED_CAPS_LOCK;
+	}
+	
+	if (kbd_dev->mods & KM_SCROLL_LOCK) {
+		leds |= USB_HID_LED_SCROLL_LOCK;
+	}
+
+	// TODO: COMPOSE and KANA
+	
+	usb_log_debug("Creating output report.\n");
+	usb_log_debug("Leds: 0x%x\n", leds);
+	if ((rc = usb_hid_boot_keyboard_output_report(
+	    leds, buffer, BOOTP_BUFFER_OUT_SIZE)) != EOK) {
+		usb_log_warning("Error composing output report to the keyboard:"
+		    "%s.\n", str_error(rc));
+		return;
+	}
+	
+	usb_log_debug("Output report buffer: %s\n", 
+	    usb_debug_str_buffer(buffer, BOOTP_BUFFER_OUT_SIZE, 0));
+	
+	assert(kbd_dev->hid_dev != NULL);
+	assert(kbd_dev->hid_dev->initialized == USBHID_KBD_STATUS_INITIALIZED);
+	usbhid_req_set_report(kbd_dev->hid_dev, USB_HID_REPORT_TYPE_OUTPUT, 
+	    buffer, BOOTP_BUFFER_OUT_SIZE);
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+ * Processes key events.
+ *
+ * @note This function was copied from AT keyboard driver and modified to suit
+ *       USB keyboard.
+ *
+ * @note Lock keys are not sent to the console, as they are completely handled
+ *       in the driver. It may, however, be required later that the driver
+ *       sends also these keys to application (otherwise it cannot use those
+ *       keys at all).
+ * 
+ * @param kbd_dev Keyboard device structure.
+ * @param type Type of the event (press / release). Recognized values: 
+ *             KEY_PRESS, KEY_RELEASE
+ * @param key Key code of the key according to HID Usage Tables.
+ */
+void usbhid_kbd_push_ev(usbhid_kbd_t *kbd_dev, int type, unsigned int key)
+{
+	console_event_t ev;
+	unsigned mod_mask;
+
+	/*
+	 * These parts are copy-pasted from the AT keyboard driver.
+	 *
+	 * They definitely require some refactoring, but will keep it for later
+	 * when the console and keyboard system is changed in HelenOS.
+	 */
+	switch (key) {
+	case KC_LCTRL: mod_mask = KM_LCTRL; break;
+	case KC_RCTRL: mod_mask = KM_RCTRL; break;
+	case KC_LSHIFT: mod_mask = KM_LSHIFT; break;
+	case KC_RSHIFT: mod_mask = KM_RSHIFT; break;
+	case KC_LALT: mod_mask = KM_LALT; break;
+	case KC_RALT: mod_mask = KM_RALT; break;
+	default: mod_mask = 0; break;
+	}
+
+	if (mod_mask != 0) {
+		if (type == KEY_PRESS)
+			kbd_dev->mods = kbd_dev->mods | mod_mask;
+		else
+			kbd_dev->mods = kbd_dev->mods & ~mod_mask;
+	}
+
+	switch (key) {
+	case KC_CAPS_LOCK: mod_mask = KM_CAPS_LOCK; break;
+	case KC_NUM_LOCK: mod_mask = KM_NUM_LOCK; break;
+	case KC_SCROLL_LOCK: mod_mask = KM_SCROLL_LOCK; break;
+	default: mod_mask = 0; break;
+	}
+
+	if (mod_mask != 0) {
+		if (type == KEY_PRESS) {
+			/*
+			 * Only change lock state on transition from released
+			 * to pressed. This prevents autorepeat from messing
+			 * up the lock state.
+			 */
+			unsigned int locks_old = kbd_dev->lock_keys;
+			
+			kbd_dev->mods = 
+			    kbd_dev->mods ^ (mod_mask & ~kbd_dev->lock_keys);
+			kbd_dev->lock_keys = kbd_dev->lock_keys | mod_mask;
+
+			/* Update keyboard lock indicator lights. */
+			if (kbd_dev->lock_keys != locks_old) {
+				usbhid_kbd_set_led(kbd_dev);
+			}
+		} else {
+			kbd_dev->lock_keys = kbd_dev->lock_keys & ~mod_mask;
+		}
+	}
+
+	if (key == KC_CAPS_LOCK || key == KC_NUM_LOCK || key == KC_SCROLL_LOCK) {
+		// do not send anything to the console, this is our business
+		return;
+	}
+	
+	if (type == KEY_PRESS && (kbd_dev->mods & KM_LCTRL) && key == KC_F1) {
+		active_layout = 0;
+		layout[active_layout]->reset();
+		return;
+	}
+
+	if (type == KEY_PRESS && (kbd_dev->mods & KM_LCTRL) && key == KC_F2) {
+		active_layout = 1;
+		layout[active_layout]->reset();
+		return;
+	}
+
+	if (type == KEY_PRESS && (kbd_dev->mods & KM_LCTRL) && key == KC_F3) {
+		active_layout = 2;
+		layout[active_layout]->reset();
+		return;
+	}
+	
+	ev.type = type;
+	ev.key = key;
+	ev.mods = kbd_dev->mods;
+
+	ev.c = layout[active_layout]->parse_ev(&ev);
+
+	usb_log_debug2("Sending key %d to the console\n", ev.key);
+	if (kbd_dev->console_phone < 0) {
+		usb_log_warning(
+		    "Connection to console not ready, key discarded.\n");
+		return;
+	}
+	
+	async_msg_4(kbd_dev->console_phone, KBD_EVENT, ev.type, ev.key, 
+	    ev.mods, ev.c);
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+ * Checks if modifiers were pressed or released and generates key events.
+ *
+ * @param kbd_dev Keyboard device structure.
+ * @param modifiers Bitmap of modifiers.
+ *
+ * @sa usbhid_kbd_push_ev()
+ */
+//static void usbhid_kbd_check_modifier_changes(usbhid_kbd_t *kbd_dev, 
+//    const uint8_t *key_codes, size_t count)
+//{
+//	/*
+//	 * TODO: why the USB keyboard has NUM_, SCROLL_ and CAPS_LOCK
+//	 *       both as modifiers and as keyUSB_HID_LOCK_COUNTs with their own scancodes???
+//	 *
+//	 * modifiers should be sent as normal keys to usbhid_parse_scancode()!!
+//	 * so maybe it would be better if I received it from report parser in 
+//	 * that way
+//	 */
+	
+//	int i;
+//	for (i = 0; i < count; ++i) {
+//		if ((modifiers & usb_hid_modifiers_consts[i]) &&
+//		    !(kbd_dev->modifiers & usb_hid_modifiers_consts[i])) {
+//			// modifier pressed
+//			if (usbhid_modifiers_keycodes[i] != 0) {
+//				usbhid_kbd_push_ev(kbd_dev, KEY_PRESS, 
+//				    usbhid_modifiers_keycodes[i]);
+//			}
+//		} else if (!(modifiers & usb_hid_modifiers_consts[i]) &&
+//		    (kbd_dev->modifiers & usb_hid_modifiers_consts[i])) {
+//			// modifier released
+//			if (usbhid_modifiers_keycodes[i] != 0) {
+//				usbhid_kbd_push_ev(kbd_dev, KEY_RELEASE, 
+//				    usbhid_modifiers_keycodes[i]);
+//			}
+//		}	// no change
+//	}
+	
+//	kbd_dev->modifiers = modifiers;
+//}
+
+/*----------------------------------------------------------------------------*/
+
+static inline int usbhid_kbd_is_lock(unsigned int key_code) 
+{
+	return (key_code == KC_NUM_LOCK
+	    || key_code == KC_SCROLL_LOCK
+	    || key_code == KC_CAPS_LOCK);
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+ * Checks if some keys were pressed or released and generates key events.
+ *
+ * An event is created only when key is pressed or released. Besides handling
+ * the events (usbhid_kbd_push_ev()), the auto-repeat fibril is notified about
+ * key presses and releases (see usbhid_kbd_repeat_start() and 
+ * usbhid_kbd_repeat_stop()).
+ *
+ * @param kbd_dev Keyboard device structure.
+ * @param key_codes Parsed keyboard report - codes of currently pressed keys 
+ *                  according to HID Usage Tables.
+ * @param count Number of key codes in report (size of the report).
+ *
+ * @sa usbhid_kbd_push_ev(), usbhid_kbd_repeat_start(), usbhid_kbd_repeat_stop()
+ */
+static void usbhid_kbd_check_key_changes(usbhid_kbd_t *kbd_dev, 
+    const uint8_t *key_codes, size_t count)
+{
+	unsigned int key;
+	unsigned int i, j;
+	
+	/*
+	 * First of all, check if the kbd have reported phantom state.
+	 *
+	 * TODO: this must be changed as we don't know which keys are modifiers
+	 *       and which are regular keys.
+	 */
+	i = 0;
+	// all fields should report Error Rollover
+	while (i < count &&
+	    key_codes[i] == BOOTP_ERROR_ROLLOVER) {
+		++i;
+	}
+	if (i == count) {
+		usb_log_debug("Phantom state occured.\n");
+		// phantom state, do nothing
+		return;
+	}
+	
+	/* TODO: quite dummy right now, think of better implementation */
+	assert(count == kbd_dev->key_count);
+	
+	/*
+	 * 1) Key releases
+	 */
+	for (j = 0; j < count; ++j) {
+		// try to find the old key in the new key list
+		i = 0;
+		while (i < kbd_dev->key_count
+		    && key_codes[i] != kbd_dev->keys[j]) {
+			++i;
+		}
+		
+		if (i == count) {
+			// not found, i.e. the key was released
+			key = usbhid_parse_scancode(kbd_dev->keys[j]);
+			if (!usbhid_kbd_is_lock(key)) {
+				usbhid_kbd_repeat_stop(kbd_dev, key);
+			}
+			usbhid_kbd_push_ev(kbd_dev, KEY_RELEASE, key);
+			usb_log_debug2("Key released: %d\n", key);
+		} else {
+			// found, nothing happens
+		}
+	}
+	
+	/*
+	 * 1) Key presses
+	 */
+	for (i = 0; i < kbd_dev->key_count; ++i) {
+		// try to find the new key in the old key list
+		j = 0;
+		while (j < count && kbd_dev->keys[j] != key_codes[i]) { 
+			++j;
+		}
+		
+		if (j == count) {
+			// not found, i.e. new key pressed
+			key = usbhid_parse_scancode(key_codes[i]);
+			usb_log_debug2("Key pressed: %d (keycode: %d)\n", key,
+			    key_codes[i]);
+			usbhid_kbd_push_ev(kbd_dev, KEY_PRESS, key);
+			if (!usbhid_kbd_is_lock(key)) {
+				usbhid_kbd_repeat_start(kbd_dev, key);
+			}
+		} else {
+			// found, nothing happens
+		}
+	}
+	
+	memcpy(kbd_dev->keys, key_codes, count);
+
+	usb_log_debug("New stored keycodes: %s\n", 
+	    usb_debug_str_buffer(kbd_dev->keys, kbd_dev->key_count, 0));
+}
+
+/*----------------------------------------------------------------------------*/
+/* Callbacks for parser                                                       */
+/*----------------------------------------------------------------------------*/
+/**
+ * Callback function for the HID report parser.
+ *
+ * This function is called by the HID report parser with the parsed report.
+ * The parsed report is used to check if any events occured (key was pressed or
+ * released, modifier was pressed or released).
+ *
+ * @param key_codes Parsed keyboard report - codes of currently pressed keys 
+ *                  according to HID Usage Tables.
+ * @param count Number of key codes in report (size of the report).
+ * @param modifiers Bitmap of modifiers (Ctrl, Alt, Shift, GUI).
+ * @param arg User-specified argument. Expects pointer to the keyboard device
+ *            structure representing the keyboard.
+ *
+ * @sa usbhid_kbd_check_key_changes(), usbhid_kbd_check_modifier_changes()
+ */
+static void usbhid_kbd_process_keycodes(const uint8_t *key_codes, size_t count,
+    uint8_t modifiers, void *arg)
+{
+	if (arg == NULL) {
+		usb_log_warning("Missing argument in callback "
+		    "usbhid_process_keycodes().\n");
+		return;
+	}
+	
+	usbhid_kbd_t *kbd_dev = (usbhid_kbd_t *)arg;
+	assert(kbd_dev != NULL);
+
+	usb_log_debug("Got keys from parser: %s\n", 
+	    usb_debug_str_buffer(key_codes, count, 0));
+	
+	if (count != kbd_dev->key_count) {
+		usb_log_warning("Number of received keycodes (%d) differs from"
+		    " expected number (%d).\n", count, kbd_dev->key_count);
+		return;
+	}
+	
+	///usbhid_kbd_check_modifier_changes(kbd_dev, key_codes, count);
+	usbhid_kbd_check_key_changes(kbd_dev, key_codes, count);
+}
+
+/*----------------------------------------------------------------------------*/
+/* General kbd functions                                                      */
+/*----------------------------------------------------------------------------*/
+/**
+ * Processes data received from the device in form of report.
+ *
+ * This function uses the HID report parser to translate the data received from
+ * the device into generic USB HID key codes and into generic modifiers bitmap.
+ * The parser then calls the given callback (usbhid_kbd_process_keycodes()).
+ *
+ * @note Currently, only the boot protocol is supported.
+ *
+ * @param kbd_dev Keyboard device structure (must be initialized).
+ * @param buffer Data from the keyboard (i.e. the report).
+ * @param actual_size Size of the data from keyboard (report size) in bytes.
+ *
+ * @sa usbhid_kbd_process_keycodes(), usb_hid_boot_keyboard_input_report().
+ */
+static void usbhid_kbd_process_data(usbhid_kbd_t *kbd_dev,
+                                    uint8_t *buffer, size_t actual_size)
+{
+	assert(kbd_dev->initialized == USBHID_KBD_STATUS_INITIALIZED);
+	assert(kbd_dev->hid_dev->parser != NULL);
+	
+	usb_hid_report_in_callbacks_t *callbacks =
+	    (usb_hid_report_in_callbacks_t *)malloc(
+	        sizeof(usb_hid_report_in_callbacks_t));
+	
+	callbacks->keyboard = usbhid_kbd_process_keycodes;
+
+	usb_log_debug("Calling usb_hid_parse_report() with "
+	    "buffer %s\n", usb_debug_str_buffer(buffer, actual_size, 0));
+	
+//	int rc = usb_hid_boot_keyboard_input_report(buffer, actual_size,
+//	    callbacks, kbd_dev);
+	int rc = usb_hid_parse_report(kbd_dev->hid_dev->parser, buffer,
+	    actual_size, callbacks, kbd_dev);
+	
+	if (rc != EOK) {
+		usb_log_warning("Error in usb_hid_boot_keyboard_input_report():"
+		    "%s\n", str_error(rc));
+	}
+}
+
+/*----------------------------------------------------------------------------*/
+/* HID/KBD structure manipulation                                             */
+/*----------------------------------------------------------------------------*/
+/**
+ * Creates a new USB/HID keyboard structure.
+ *
+ * The structure returned by this function is not initialized. Use 
+ * usbhid_kbd_init() to initialize it prior to polling.
+ *
+ * @return New uninitialized structure for representing a USB/HID keyboard or
+ *         NULL if not successful (memory error).
+ */
+static usbhid_kbd_t *usbhid_kbd_new(void)
+{
+	usbhid_kbd_t *kbd_dev = 
+	    (usbhid_kbd_t *)malloc(sizeof(usbhid_kbd_t));
+
+	if (kbd_dev == NULL) {
+		usb_log_fatal("No memory!\n");
+		return NULL;
+	}
+	
+	memset(kbd_dev, 0, sizeof(usbhid_kbd_t));
+	
+	kbd_dev->hid_dev = usbhid_dev_new();
+	if (kbd_dev->hid_dev == NULL) {
+		usb_log_fatal("Could not create HID device structure.\n");
+		return NULL;
+	}
+	
+	kbd_dev->console_phone = -1;
+	kbd_dev->initialized = USBHID_KBD_STATUS_UNINITIALIZED;
+	
+	return kbd_dev;
+}
+
+/*----------------------------------------------------------------------------*/
+
+static void usbhid_kbd_mark_unusable(usbhid_kbd_t *kbd_dev)
+{
+	kbd_dev->initialized = USBHID_KBD_STATUS_TO_DESTROY;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+ * Initialization of the USB/HID keyboard structure.
+ *
+ * This functions initializes required structures from the device's descriptors.
+ *
+ * During initialization, the keyboard is switched into boot protocol, the idle
+ * rate is set to 0 (infinity), resulting in the keyboard only reporting event
+ * when a key is pressed or released. Finally, the LED lights are turned on 
+ * according to the default setup of lock keys.
+ *
+ * @note By default, the keyboards is initialized with Num Lock turned on and 
+ *       other locks turned off.
+ *
+ * @param kbd_dev Keyboard device structure to be initialized.
+ * @param dev DDF device structure of the keyboard.
+ *
+ * @retval EOK if successful.
+ * @retval EINVAL if some parameter is not given.
+ * @return Other value inherited from function usbhid_dev_init().
+ */
+static int usbhid_kbd_init(usbhid_kbd_t *kbd_dev, ddf_dev_t *dev)
+{
+	int rc;
+	
+	usb_log_debug("Initializing HID/KBD structure...\n");
+	
+	if (kbd_dev == NULL) {
+		usb_log_error("Failed to init keyboard structure: no structure"
+		    " given.\n");
+		return EINVAL;
+	}
+	
+	if (dev == NULL) {
+		usb_log_error("Failed to init keyboard structure: no device"
+		    " given.\n");
+		return EINVAL;
+	}
+	
+	if (kbd_dev->initialized == USBHID_KBD_STATUS_INITIALIZED) {
+		usb_log_warning("Keyboard structure already initialized.\n");
+		return EINVAL;
+	}
+	
+	rc = usbhid_dev_init(kbd_dev->hid_dev, dev, &poll_endpoint_description);
+	
+	if (rc != EOK) {
+		usb_log_error("Failed to initialize HID device structure: %s\n",
+		   str_error(rc));
+		return rc;
+	}
+	
+	assert(kbd_dev->hid_dev->initialized == USBHID_KBD_STATUS_INITIALIZED);
+	
+	// save the size of the report (boot protocol report by default)
+//	kbd_dev->key_count = BOOTP_REPORT_SIZE;
+	
+	usb_hid_report_path_t path;
+	path.usage_page = USB_HIDUT_PAGE_KEYBOARD;
+	kbd_dev->key_count = usb_hid_report_input_length(
+	    kbd_dev->hid_dev->parser, &path);
+	
+	usb_log_debug("Size of the input report: %zu\n", kbd_dev->key_count);
+	
+	kbd_dev->keys = (uint8_t *)calloc(
+	    kbd_dev->key_count, sizeof(uint8_t));
+	
+	if (kbd_dev->keys == NULL) {
+		usb_log_fatal("No memory!\n");
+		return ENOMEM;
+	}
+	
+	kbd_dev->modifiers = 0;
+	kbd_dev->mods = DEFAULT_ACTIVE_MODS;
+	kbd_dev->lock_keys = 0;
+	
+	kbd_dev->repeat.key_new = 0;
+	kbd_dev->repeat.key_repeated = 0;
+	kbd_dev->repeat.delay_before = DEFAULT_DELAY_BEFORE_FIRST_REPEAT;
+	kbd_dev->repeat.delay_between = DEFAULT_REPEAT_DELAY;
+	
+	kbd_dev->repeat_mtx = (fibril_mutex_t *)(
+	    malloc(sizeof(fibril_mutex_t)));
+	if (kbd_dev->repeat_mtx == NULL) {
+		usb_log_fatal("No memory!\n");
+		free(kbd_dev->keys);
+		return ENOMEM;
+	}
+	
+	fibril_mutex_initialize(kbd_dev->repeat_mtx);
+	
+	/*
+	 * Set boot protocol.
+	 * Set LEDs according to initial setup.
+	 * Set Idle rate
+	 */
+	assert(kbd_dev->hid_dev != NULL);
+	assert(kbd_dev->hid_dev->initialized);
+	//usbhid_req_set_protocol(kbd_dev->hid_dev, USB_HID_PROTOCOL_BOOT);
+	
+	usbhid_kbd_set_led(kbd_dev);
+	
+	usbhid_req_set_idle(kbd_dev->hid_dev, IDLE_RATE);
+	
+	kbd_dev->initialized = USBHID_KBD_STATUS_INITIALIZED;
+	usb_log_debug("HID/KBD device structure initialized.\n");
+	
+	return EOK;
+}
+
+/*----------------------------------------------------------------------------*/
+/* HID/KBD polling                                                            */
+/*----------------------------------------------------------------------------*/
+/**
+ * Main keyboard polling function.
+ *
+ * This function uses the Interrupt In pipe of the keyboard to poll for events.
+ * The keyboard is initialized in a way that it reports only when a key is 
+ * pressed or released, so there is no actual need for any sleeping between
+ * polls (see usbhid_kbd_try_add_device() or usbhid_kbd_init()).
+ *
+ * @param kbd_dev Initialized keyboard structure representing the device to 
+ *                poll.
+ *
+ * @sa usbhid_kbd_process_data()
+ */
+static void usbhid_kbd_poll(usbhid_kbd_t *kbd_dev)
+{
+	int rc, sess_rc;
+	uint8_t buffer[BOOTP_BUFFER_SIZE];
+	size_t actual_size;
+	
+	usb_log_debug("Polling keyboard...\n");
+	
+	if (!kbd_dev->initialized) {
+		usb_log_error("HID/KBD device not initialized!\n");
+		return;
+	}
+	
+	assert(kbd_dev->hid_dev != NULL);
+	assert(kbd_dev->hid_dev->initialized);
+
+	while (true) {
+		sess_rc = usb_pipe_start_session(
+		    &kbd_dev->hid_dev->poll_pipe);
+		if (sess_rc != EOK) {
+			usb_log_warning("Failed to start a session: %s.\n",
+			    str_error(sess_rc));
+			break;
+		}
+
+		rc = usb_pipe_read(&kbd_dev->hid_dev->poll_pipe, 
+		    buffer, BOOTP_BUFFER_SIZE, &actual_size);
+		
+		sess_rc = usb_pipe_end_session(
+		    &kbd_dev->hid_dev->poll_pipe);
+
+		if (rc != EOK) {
+			usb_log_warning("Error polling the keyboard: %s.\n",
+			    str_error(rc));
+			break;
+		}
+
+		if (sess_rc != EOK) {
+			usb_log_warning("Error closing session: %s.\n",
+			    str_error(sess_rc));
+			break;
+		}
+
+		/*
+		 * If the keyboard answered with NAK, it returned no data.
+		 * This implies that no change happened since last query.
+		 */
+		if (actual_size == 0) {
+			usb_log_debug("Keyboard returned NAK\n");
+			continue;
+		}
+
+		/*
+		 * TODO: Process pressed keys.
+		 */
+		usb_log_debug("Calling usbhid_kbd_process_data()\n");
+		usbhid_kbd_process_data(kbd_dev, buffer, actual_size);
+		
+		// disabled for now, no reason to sleep
+		//async_usleep(kbd_dev->hid_dev->poll_interval);
+	}
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+ * Function executed by the main driver fibril.
+ *
+ * Just starts polling the keyboard for events.
+ * 
+ * @param arg Initialized keyboard device structure (of type usbhid_kbd_t) 
+ *            representing the device.
+ *
+ * @retval EOK if the fibril finished polling the device.
+ * @retval EINVAL if no device was given in the argument.
+ *
+ * @sa usbhid_kbd_poll()
+ *
+ * @todo Change return value - only case when the fibril finishes is in case
+ *       of some error, so the error should probably be propagated from function
+ *       usbhid_kbd_poll() to here and up.
+ */
+static int usbhid_kbd_fibril(void *arg)
+{
+	if (arg == NULL) {
+		usb_log_error("No device!\n");
+		return EINVAL;
+	}
+	
+	usbhid_kbd_t *kbd_dev = (usbhid_kbd_t *)arg;
+
+	usbhid_kbd_poll(kbd_dev);
+	
+	// as there is another fibril using this device, so we must leave the
+	// structure to it, but mark it for destroying.
+	usbhid_kbd_mark_unusable(kbd_dev);
+	// at the end, properly destroy the KBD structure
+//	usbhid_kbd_free(&kbd_dev);
+//	assert(kbd_dev == NULL);
+
+	return EOK;
+}
+
+/*----------------------------------------------------------------------------*/
+/* API functions                                                              */
+/*----------------------------------------------------------------------------*/
+/**
+ * Function for adding a new device of type USB/HID/keyboard.
+ *
+ * This functions initializes required structures from the device's descriptors
+ * and starts new fibril for polling the keyboard for events and another one for
+ * handling auto-repeat of keys.
+ *
+ * During initialization, the keyboard is switched into boot protocol, the idle
+ * rate is set to 0 (infinity), resulting in the keyboard only reporting event
+ * when a key is pressed or released. Finally, the LED lights are turned on 
+ * according to the default setup of lock keys.
+ *
+ * @note By default, the keyboards is initialized with Num Lock turned on and 
+ *       other locks turned off.
+ * @note Currently supports only boot-protocol keyboards.
+ *
+ * @param dev Device to add.
+ *
+ * @retval EOK if successful.
+ * @retval ENOMEM if there
+ * @return Other error code inherited from one of functions usbhid_kbd_init(),
+ *         ddf_fun_bind() and ddf_fun_add_to_class().
+ *
+ * @sa usbhid_kbd_fibril(), usbhid_kbd_repeat_fibril()
+ */
+int usbhid_kbd_try_add_device(ddf_dev_t *dev)
+{
+	/*
+	 * Create default function.
+	 */
+	ddf_fun_t *kbd_fun = ddf_fun_create(dev, fun_exposed, "keyboard");
+	if (kbd_fun == NULL) {
+		usb_log_error("Could not create DDF function node.\n");
+		return ENOMEM;
+	}
+	
+	/* 
+	 * Initialize device (get and process descriptors, get address, etc.)
+	 */
+	usb_log_debug("Initializing USB/HID KBD device...\n");
+	
+	usbhid_kbd_t *kbd_dev = usbhid_kbd_new();
+	if (kbd_dev == NULL) {
+		usb_log_error("Error while creating USB/HID KBD device "
+		    "structure.\n");
+		ddf_fun_destroy(kbd_fun);
+		return ENOMEM;  // TODO: some other code??
+	}
+	
+	int rc = usbhid_kbd_init(kbd_dev, dev);
+	
+	if (rc != EOK) {
+		usb_log_error("Failed to initialize USB/HID KBD device.\n");
+		ddf_fun_destroy(kbd_fun);
+		usbhid_kbd_free(&kbd_dev);
+		return rc;
+	}	
+	
+	usb_log_debug("USB/HID KBD device structure initialized.\n");
+	
+	/*
+	 * Store the initialized keyboard device and keyboard ops
+	 * to the DDF function.
+	 */
+	kbd_fun->driver_data = kbd_dev;
+	kbd_fun->ops = &keyboard_ops;
+
+	rc = ddf_fun_bind(kbd_fun);
+	if (rc != EOK) {
+		usb_log_error("Could not bind DDF function: %s.\n",
+		    str_error(rc));
+		// TODO: Can / should I destroy the DDF function?
+		ddf_fun_destroy(kbd_fun);
+		usbhid_kbd_free(&kbd_dev);
+		return rc;
+	}
+	
+	rc = ddf_fun_add_to_class(kbd_fun, "keyboard");
+	if (rc != EOK) {
+		usb_log_error(
+		    "Could not add DDF function to class 'keyboard': %s.\n",
+		    str_error(rc));
+		// TODO: Can / should I destroy the DDF function?
+		ddf_fun_destroy(kbd_fun);
+		usbhid_kbd_free(&kbd_dev);
+		return rc;
+	}
+	
+	/*
+	 * Create new fibril for handling this keyboard
+	 */
+	fid_t fid = fibril_create(usbhid_kbd_fibril, kbd_dev);
+	if (fid == 0) {
+		usb_log_error("Failed to start fibril for `%s' device.\n",
+		    dev->name);
+		return ENOMEM;
+	}
+	fibril_add_ready(fid);
+	
+	/*
+	 * Create new fibril for auto-repeat
+	 */
+	fid = fibril_create(usbhid_kbd_repeat_fibril, kbd_dev);
+	if (fid == 0) {
+		usb_log_error("Failed to start fibril for KBD auto-repeat");
+		return ENOMEM;
+	}
+	fibril_add_ready(fid);
+
+	(void)keyboard_ops;
+
+	/*
+	 * Hurrah, device is initialized.
+	 */
+	return EOK;
+}
+
+/*----------------------------------------------------------------------------*/
+
+int usbhid_kbd_is_usable(const usbhid_kbd_t *kbd_dev)
+{
+	return (kbd_dev->initialized == USBHID_KBD_STATUS_INITIALIZED);
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+ * Properly destroys the USB/HID keyboard structure.
+ *
+ * @param kbd_dev Pointer to the structure to be destroyed.
+ */
+void usbhid_kbd_free(usbhid_kbd_t **kbd_dev)
+{
+	if (kbd_dev == NULL || *kbd_dev == NULL) {
+		return;
+	}
+	
+	// hangup phone to the console
+	async_hangup((*kbd_dev)->console_phone);
+	
+	if ((*kbd_dev)->hid_dev != NULL) {
+		usbhid_dev_free(&(*kbd_dev)->hid_dev);
+		assert((*kbd_dev)->hid_dev == NULL);
+	}
+	
+	if ((*kbd_dev)->repeat_mtx != NULL) {
+		/* TODO: replace by some check and wait */
+		assert(!fibril_mutex_is_locked((*kbd_dev)->repeat_mtx));
+		free((*kbd_dev)->repeat_mtx);
+	}
+
+	free(*kbd_dev);
+	*kbd_dev = NULL;
+}
+
+/**
+ * @}
+ */
Index: uspace/drv/usbhid/kbddev.h
===================================================================
--- uspace/drv/usbhid/kbddev.h	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
+++ uspace/drv/usbhid/kbddev.h	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -0,0 +1,126 @@
+/*
+ * Copyright (c) 2011 Lubos Slovak
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - 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.
+ * - 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 ``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 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.
+ */
+
+/** @addtogroup drvusbhid
+ * @{
+ */
+/** @file
+ * USB HID keyboard device structure and API.
+ */
+
+#ifndef USBHID_KBDDEV_H_
+#define USBHID_KBDDEV_H_
+
+#include <stdint.h>
+
+#include <fibril_synch.h>
+
+#include <usb/classes/hid.h>
+#include <usb/classes/hidparser.h>
+#include <ddf/driver.h>
+#include <usb/pipes.h>
+
+#include "hiddev.h"
+
+/*----------------------------------------------------------------------------*/
+/**
+ * Structure for keeping information needed for auto-repeat of keys.
+ */
+typedef struct {
+	/** Last pressed key. */
+	unsigned int key_new;
+	/** Key to be repeated. */
+	unsigned int key_repeated;
+	/** Delay before first repeat in microseconds. */
+	unsigned int delay_before;
+	/** Delay between repeats in microseconds. */
+	unsigned int delay_between;
+} usbhid_kbd_repeat_t;
+
+/**
+ * USB/HID keyboard device type.
+ *
+ * Holds a reference to generic USB/HID device structure and keyboard-specific
+ * data, such as currently pressed keys, modifiers and lock keys.
+ *
+ * Also holds a IPC phone to the console (since there is now no other way to 
+ * communicate with it).
+ *
+ * @note Storing active lock keys in this structure results in their setting
+ *       being device-specific.
+ */
+typedef struct {
+	/** Structure holding generic USB/HID device information. */
+	usbhid_dev_t *hid_dev;
+	
+	/** Currently pressed keys (not translated to key codes). */
+	uint8_t *keys;
+	/** Count of stored keys (i.e. number of keys in the report). */
+	size_t key_count;
+	/** Currently pressed modifiers (bitmap). */
+	uint8_t modifiers;
+	
+	/** Currently active modifiers including locks. Sent to the console. */
+	unsigned mods;
+	
+	/** Currently active lock keys. */
+	unsigned lock_keys;
+	
+	/** IPC phone to the console device (for sending key events). */
+	int console_phone;
+	
+	/** Information for auto-repeat of keys. */
+	usbhid_kbd_repeat_t repeat;
+	
+	/** Mutex for accessing the information about auto-repeat. */
+	fibril_mutex_t *repeat_mtx;
+	
+	/** State of the structure (for checking before use). 
+	 * 
+	 * 0 - not initialized
+	 * 1 - initialized
+	 * -1 - ready for destroying
+	 */
+	int initialized;
+} usbhid_kbd_t;
+
+/*----------------------------------------------------------------------------*/
+
+int usbhid_kbd_try_add_device(ddf_dev_t *dev);
+
+int usbhid_kbd_is_usable(const usbhid_kbd_t *kbd_dev);
+
+void usbhid_kbd_free(usbhid_kbd_t **kbd_dev);
+
+void usbhid_kbd_push_ev(usbhid_kbd_t *kbd_dev, int type, unsigned int key);
+
+#endif /* USBHID_KBDDEV_H_ */
+
+/**
+ * @}
+ */
Index: uspace/drv/usbhid/kbdrepeat.c
===================================================================
--- uspace/drv/usbhid/kbdrepeat.c	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
+++ uspace/drv/usbhid/kbdrepeat.c	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -0,0 +1,183 @@
+/*
+ * Copyright (c) 2011 Lubos Slovak
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - 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.
+ * - 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 ``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 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.
+ */
+
+/** @addtogroup drvusbhid
+ * @{
+ */
+/**
+ * @file
+ * USB HID keyboard autorepeat facilities
+ */
+
+#include <fibril_synch.h>
+#include <io/keycode.h>
+#include <io/console.h>
+#include <errno.h>
+
+#include <usb/debug.h>
+
+#include "kbdrepeat.h"
+#include "kbddev.h"
+
+
+/** Delay between auto-repeat state checks when no key is being repeated. */
+static unsigned int CHECK_DELAY = 10000;
+
+/*----------------------------------------------------------------------------*/
+/**
+ * Main loop handling the auto-repeat of keys.
+ *
+ * This functions periodically checks if there is some key to be auto-repeated.
+ *
+ * If a new key is to be repeated, it uses the delay before first repeat stored
+ * in the keyboard structure to wait until the key has to start repeating.
+ *
+ * If the same key is still pressed, it uses the delay between repeats stored
+ * in the keyboard structure to wait until the key should be repeated.
+ * 
+ * If the currently repeated key is not pressed any more (
+ * usbhid_kbd_repeat_stop() was called), it stops repeating it and starts 
+ * checking again.
+ *
+ * @note For accessing the keyboard device auto-repeat information a fibril
+ *       mutex (repeat_mtx) from the @a kbd structure is used.
+ * 
+ * @param kbd Keyboard device structure.
+ */
+static void usbhid_kbd_repeat_loop(usbhid_kbd_t *kbd)
+{
+	unsigned int delay = 0;
+	
+	usb_log_debug("Starting autorepeat loop.\n");
+
+	while (true) {
+		// check if the kbd structure is usable
+		if (!usbhid_kbd_is_usable(kbd)) {
+			usbhid_kbd_free(&kbd);
+			assert(kbd == NULL);
+			return;
+		}
+		
+		fibril_mutex_lock(kbd->repeat_mtx);
+
+		if (kbd->repeat.key_new > 0) {
+			if (kbd->repeat.key_new == kbd->repeat.key_repeated) {
+				usb_log_debug2("Repeating key: %u.\n", 
+				    kbd->repeat.key_repeated);
+				usbhid_kbd_push_ev(kbd, KEY_PRESS, 
+				    kbd->repeat.key_repeated);
+				delay = kbd->repeat.delay_between;
+			} else {
+				usb_log_debug("New key to repeat: %u.\n", 
+				    kbd->repeat.key_new);
+				kbd->repeat.key_repeated = kbd->repeat.key_new;
+				delay = kbd->repeat.delay_before;
+			}
+		} else {
+			if (kbd->repeat.key_repeated > 0) {
+				usb_log_debug("Stopping to repeat key: %u.\n", 
+				    kbd->repeat.key_repeated);
+				kbd->repeat.key_repeated = 0;
+			}
+			delay = CHECK_DELAY;
+		}
+		fibril_mutex_unlock(kbd->repeat_mtx);
+		
+		async_usleep(delay);
+	}
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+ * Main routine to be executed by a fibril for handling auto-repeat.
+ *
+ * Starts the loop for checking changes in auto-repeat.
+ * 
+ * @param arg User-specified argument. Expects pointer to the keyboard device
+ *            structure representing the keyboard.
+ *
+ * @retval EOK if the routine has finished.
+ * @retval EINVAL if no argument is supplied.
+ */
+int usbhid_kbd_repeat_fibril(void *arg)
+{
+	usb_log_debug("Autorepeat fibril spawned.\n");
+	
+	if (arg == NULL) {
+		usb_log_error("No device!\n");
+		return EINVAL;
+	}
+	
+	usbhid_kbd_t *kbd = (usbhid_kbd_t *)arg;
+	
+	usbhid_kbd_repeat_loop(kbd);
+	
+	return EOK;
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+ * Start repeating particular key.
+ *
+ * @note Only one key is repeated at any time, so calling this function 
+ *       effectively cancels auto-repeat of the current repeated key (if any)
+ *       and 'schedules' another key for auto-repeat.
+ *
+ * @param kbd Keyboard device structure.
+ * @param key Key to start repeating.
+ */
+void usbhid_kbd_repeat_start(usbhid_kbd_t *kbd, unsigned int key)
+{
+	fibril_mutex_lock(kbd->repeat_mtx);
+	kbd->repeat.key_new = key;
+	fibril_mutex_unlock(kbd->repeat_mtx);
+}
+
+/*----------------------------------------------------------------------------*/
+/**
+ * Stop repeating particular key.
+ *
+ * @note Only one key is repeated at any time, but this function may be called
+ *       even with key that is not currently repeated (in that case nothing 
+ *       happens).
+ *
+ * @param kbd Keyboard device structure.
+ * @param key Key to stop repeating.
+ */
+void usbhid_kbd_repeat_stop(usbhid_kbd_t *kbd, unsigned int key)
+{
+	fibril_mutex_lock(kbd->repeat_mtx);
+	if (key == kbd->repeat.key_new) {
+		kbd->repeat.key_new = 0;
+	}
+	fibril_mutex_unlock(kbd->repeat_mtx);
+}
+
+/**
+ * @}
+ */
Index: uspace/drv/usbhid/kbdrepeat.h
===================================================================
--- uspace/drv/usbhid/kbdrepeat.h	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
+++ uspace/drv/usbhid/kbdrepeat.h	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2011 Lubos Slovak
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - 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.
+ * - 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 ``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 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.
+ */
+
+/** @addtogroup drvusbhid
+ * @{
+ */
+/** @file
+ * USB HID keyboard autorepeat facilities
+ */
+
+#ifndef USBHID_KBDREPEAT_H_
+#define USBHID_KBDREPEAT_H_
+
+#include "kbddev.h"
+
+/*----------------------------------------------------------------------------*/
+
+int usbhid_kbd_repeat_fibril(void *arg);
+
+void usbhid_kbd_repeat_start(usbhid_kbd_t *kbd, unsigned int key);
+
+void usbhid_kbd_repeat_stop(usbhid_kbd_t *kbd, unsigned int key);
+
+#endif /* USBHID_KBDREPEAT_H_ */
+
+/**
+ * @}
+ */
Index: uspace/drv/usbhid/layout.h
===================================================================
--- uspace/drv/usbhid/layout.h	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
+++ uspace/drv/usbhid/layout.h	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2009 Jiri Svoboda
+ * Copyright (c) 2011 Lubos Slovak 
+ * (copied from /uspace/srv/hid/kbd/include/layout.h)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - 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.
+ * - 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 ``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 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.
+ */
+
+/** @addtogroup drvusbhid
+ * @{
+ */
+/** @file
+ * Keyboard layout.
+ */
+
+#ifndef USBHID_LAYOUT_H_
+#define USBHID_LAYOUT_H_
+
+#include <sys/types.h>
+#include <io/console.h>
+
+typedef struct {
+	void (*reset)(void);
+	wchar_t (*parse_ev)(console_event_t *);
+} layout_op_t;
+
+extern layout_op_t us_qwerty_op;
+extern layout_op_t us_dvorak_op;
+extern layout_op_t cz_op;
+
+#endif
+
+/**
+ * @}
+ */
Index: uspace/drv/usbhid/main.c
===================================================================
--- uspace/drv/usbhid/main.c	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
+++ uspace/drv/usbhid/main.c	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2010 Vojtech Horky
+ * Copyright (c) 2011 Lubos Slovak
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - 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.
+ * - 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 ``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 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.
+ */
+
+/** @addtogroup drvusbhid
+ * @{
+ */
+/**
+ * @file
+ * Main routines of USB HID driver.
+ */
+
+#include <ddf/driver.h>
+#include <usb/debug.h>
+#include <errno.h>
+#include <str_error.h>
+
+#include "kbddev.h"
+
+/*----------------------------------------------------------------------------*/
+
+#define NAME "usbhid"
+
+/*----------------------------------------------------------------------------*/
+/**
+ * Callback for passing a new device to the driver.
+ *
+ * @note Currently, only boot-protocol keyboards are supported by this driver.
+ *
+ * @param dev Structure representing the new device.
+ *
+ * @retval EOK if successful. 
+ * @retval EREFUSED if the device is not supported.
+ */
+static int usbhid_add_device(ddf_dev_t *dev)
+{
+	usb_log_debug("usbhid_add_device()\n");
+	
+	int rc = usbhid_kbd_try_add_device(dev);
+	
+	if (rc != EOK) {
+		usb_log_warning("Device is not a supported keyboard.\n");
+		usb_log_error("Failed to add HID device: %s.\n",
+		    str_error(rc));
+		return rc;
+	}
+	
+	usb_log_info("Keyboard `%s' ready to use.\n", dev->name);
+
+	return EOK;
+}
+
+/*----------------------------------------------------------------------------*/
+
+static driver_ops_t kbd_driver_ops = {
+	.add_device = usbhid_add_device,
+};
+
+/*----------------------------------------------------------------------------*/
+
+static driver_t kbd_driver = {
+	.name = NAME,
+	.driver_ops = &kbd_driver_ops
+};
+
+/*----------------------------------------------------------------------------*/
+
+int main(int argc, char *argv[])
+{
+	printf(NAME ": HelenOS USB HID driver.\n");
+
+	usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME);
+
+	return ddf_driver_main(&kbd_driver);
+}
+
+/**
+ * @}
+ */
Index: uspace/drv/usbhid/usbhid.ma
===================================================================
--- uspace/drv/usbhid/usbhid.ma	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
+++ uspace/drv/usbhid/usbhid.ma	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -0,0 +1,2 @@
+100 usb&interface&class=HID&subclass=0x01&protocol=0x01
+10 usb&interface&class=HID
Index: uspace/drv/usbhub/port_status.h
===================================================================
--- uspace/drv/usbhub/port_status.h	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ uspace/drv/usbhub/port_status.h	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -30,6 +30,6 @@
  */
 
-#ifndef HUB_PORT_STATUS_H
-#define	HUB_PORT_STATUS_H
+#ifndef PORT_STATUS_H
+#define	PORT_STATUS_H
 
 #include <bool.h>
@@ -335,5 +335,5 @@
 
 
-#endif	/* HUB_PORT_STATUS_H */
+#endif	/* PORT_STATUS_H */
 
 /**
Index: uspace/drv/usbhub/usbhub.c
===================================================================
--- uspace/drv/usbhub/usbhub.c	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ uspace/drv/usbhub/usbhub.c	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -162,5 +162,7 @@
 	    std_descriptor->configuration_count);
 	if(std_descriptor->configuration_count<1){
-		usb_log_error("there are no configurations available\n");
+		usb_log_error("THERE ARE NO CONFIGURATIONS AVAILABLE\n");
+		//shouldn`t I return?
+		//definitely
 		return EINVAL;
 	}
Index: pace/drv/usbkbd/Makefile
===================================================================
--- uspace/drv/usbkbd/Makefile	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ 	(revision )
@@ -1,53 +1,0 @@
-#
-# Copyright (c) 2010-2011 Vojtech Horky
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-#
-# - Redistributions of source code must retain the above copyright
-#   notice, this list of conditions and the following disclaimer.
-# - 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.
-# - 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 ``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 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.
-#
-
-USPACE_PREFIX = ../..
-LIBS = $(LIBDRV_PREFIX)/libdrv.a $(LIBUSB_PREFIX)/libusb.a
-EXTRA_CFLAGS += -I$(LIBDRV_PREFIX)/include -I$(LIBUSB_PREFIX)/include -I.
-BINARY = usbkbd
-
-STOLEN_LAYOUT_SOURCES = \
-	layout/us_qwerty.c \
-	layout/us_dvorak.c \
-	layout/cz.c
-
-SOURCES = \
-	main.c \
-	conv.c \
-	kbddev.c \
-	kbdrepeat.c \
-	$(STOLEN_LAYOUT_SOURCES)
-
-EXTRA_CLEAN = $(STOLEN_LAYOUT_SOURCES)
-
-SRV_KBD = $(USPACE_PREFIX)/srv/hid/kbd
-
-include $(USPACE_PREFIX)/Makefile.common
-
-layout/%.c: $(SRV_KBD)/layout/%.c
-	ln -sfn ../$< $@
Index: pace/drv/usbkbd/conv.c
===================================================================
--- uspace/drv/usbkbd/conv.c	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ 	(revision )
@@ -1,193 +1,0 @@
-/*
- * Copyright (c) 2011 Lubos Slovak
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - 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.
- * - 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 ``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 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.
- */
-
-/** @addtogroup drvusbhid
- * @{
- */
-/** @file
- * USB scancode parser.
- */
-
-#include <io/keycode.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <usb/debug.h>
-#include "conv.h"
-
-/**
- * Mapping between USB HID key codes (from HID Usage Tables) and corresponding
- * HelenOS key codes.
- */
-static int scanmap_simple[255] = {
-
-//	[0x29] = KC_BACKTICK,
-
-//	[0x02] = KC_1,
-//	[0x03] = KC_2,
-	[0x04] = KC_A,
-	[0x05] = KC_B,
-	[0x06] = KC_C,
-	[0x07] = KC_D,
-	[0x08] = KC_E,
-	[0x09] = KC_F,
-	[0x0a] = KC_G,
-	[0x0b] = KC_H,
-	[0x0c] = KC_I,
-	[0x0d] = KC_J,
-	[0x0e] = KC_K,
-	[0x0f] = KC_L,
-	[0x10] = KC_M,
-	[0x11] = KC_N,
-	[0x12] = KC_O,
-	[0x13] = KC_P,
-	[0x14] = KC_Q,
-	[0x15] = KC_R,
-	[0x16] = KC_S,
-	[0x17] = KC_T,
-	[0x18] = KC_U,
-	[0x19] = KC_V,
-	[0x1a] = KC_W,
-	[0x1b] = KC_X,
-	[0x1c] = KC_Y,
-	[0x1d] = KC_Z,
-
-	[0x1e] = KC_1,
-	[0x1f] = KC_2,
-	[0x20] = KC_3,
-	[0x21] = KC_4,
-	[0x22] = KC_5,
-	[0x23] = KC_6,
-	[0x24] = KC_7,
-	[0x25] = KC_8,
-	[0x26] = KC_9,
-	[0x27] = KC_0,
-	
-	[0x28] = KC_ENTER,
-	[0x29] = KC_ESCAPE,
-	[0x2a] = KC_BACKSPACE,
-	[0x2b] = KC_TAB,
-	[0x2c] = KC_SPACE,
-
-	[0x2d] = KC_MINUS,  // same as DASH? (- or _)
-	[0x2e] = KC_EQUALS,
-	[0x2f] = KC_LBRACKET,
-	[0x30] = KC_RBRACKET,
-	[0x31] = KC_BACKSLASH,
-	//[0x32] = KC_,	// TODO: HASH??? maybe some as 0x31 - backslash
-	[0x33] = KC_SEMICOLON,
-	[0x34] = KC_QUOTE,  // same as APOSTROPHE? (')
-	[0x35] = KC_BACKTICK,  // same as GRAVE ACCENT?? (`)
-	[0x36] = KC_COMMA,
-	[0x37] = KC_PERIOD,
-	[0x38] = KC_SLASH,
-
-	[0x39] = KC_CAPS_LOCK,
-	
-	[0x3a] = KC_F1,
-	[0x3b] = KC_F2,
-	[0x3c] = KC_F3,
-	[0x3d] = KC_F4,
-	[0x3e] = KC_F5,
-	[0x3f] = KC_F6,
-	[0x40] = KC_F7,
-	[0x41] = KC_F8,
-	[0x42] = KC_F9,
-	[0x43] = KC_F10,
-	[0x44] = KC_F11,
-	[0x45] = KC_F12,
-	
-	[0x46] = KC_PRTSCR,
-	[0x47] = KC_SCROLL_LOCK,
-	[0x48] = KC_PAUSE,
-	[0x49] = KC_INSERT,
-	[0x4a] = KC_HOME,
-	[0x4b] = KC_PAGE_UP,
-	[0x4c] = KC_DELETE,
-	[0x4d] = KC_END,
-	[0x4e] = KC_PAGE_DOWN,
-	[0x4f] = KC_RIGHT,
-	[0x50] = KC_LEFT,
-	[0x51] = KC_DOWN,
-	[0x52] = KC_UP,
-	
-	//[0x64] = // some funny key
-	
-	[0xe0] = KC_LCTRL,
-	[0xe1] = KC_LSHIFT,
-	[0xe2] = KC_LALT,
-	//[0xe3] = KC_L	// TODO: left GUI
-	[0xe4] = KC_RCTRL,
-	[0xe5] = KC_RSHIFT,
-	[0xe6] = KC_RALT,
-	//[0xe7] = KC_R	// TODO: right GUI
-	
-	[0x53] = KC_NUM_LOCK,
-	[0x54] = KC_NSLASH,
-	[0x55] = KC_NTIMES,
-	[0x56] = KC_NMINUS,
-	[0x57] = KC_NPLUS,
-	[0x58] = KC_NENTER,
-	[0x59] = KC_N1,
-	[0x5a] = KC_N2,
-	[0x5b] = KC_N3,
-	[0x5c] = KC_N4,
-	[0x5d] = KC_N5,
-	[0x5e] = KC_N6,
-	[0x5f] = KC_N7,
-	[0x60] = KC_N8,
-	[0x61] = KC_N9,
-	[0x62] = KC_N0,
-	[0x63] = KC_NPERIOD
-	
-};
-
-/**
- * Translate USB HID key codes (from HID Usage Tables) to generic key codes
- * recognized by HelenOS.
- *
- * @param scancode USB HID key code (from HID Usage Tables).
- * 
- * @retval HelenOS key code corresponding to the given USB HID key code.
- */
-unsigned int usbhid_parse_scancode(int scancode)
-{
-	unsigned int key;
-	int *map = scanmap_simple;
-	size_t map_length = sizeof(scanmap_simple) / sizeof(int);
-
-	if ((scancode < 0) || ((size_t) scancode >= map_length))
-		return -1;
-
-	key = map[scancode];
-	
-	return key;
-}
-
-/**
- * @}
- */
Index: pace/drv/usbkbd/conv.h
===================================================================
--- uspace/drv/usbkbd/conv.h	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ 	(revision )
@@ -1,45 +1,0 @@
-/*
- * Copyright (c) 2011 Lubos Slovak
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - 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.
- * - 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 ``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 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.
- */
-
-/** @addtogroup drvusbhid
- * @{
- */
-/** @file
- * USB scancode parser.
- */
-
-#ifndef USB_KBD_CONV_H_
-#define USB_KBD_CONV_H_
-
-unsigned int usbhid_parse_scancode(int scancode);
-
-#endif /* USB_KBD_CONV_H_ */
-
-/**
- * @}
- */
Index: pace/drv/usbkbd/kbd.h
===================================================================
--- uspace/drv/usbkbd/kbd.h	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ 	(revision )
@@ -1,5 +1,0 @@
-/*
- * Dummy file because of shared layout sources.
- *
- * Do not delete.
- */
Index: pace/drv/usbkbd/kbddev.c
===================================================================
--- uspace/drv/usbkbd/kbddev.c	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ 	(revision )
@@ -1,889 +1,0 @@
-/*
- * Copyright (c) 2011 Lubos Slovak
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - 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.
- * - 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 ``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 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.
- */
-
-/** @addtogroup drvusbhid
- * @{
- */
-/**
- * @file
- * USB HID keyboard device structure and API.
- */
-
-#include <errno.h>
-#include <str_error.h>
-#include <stdio.h>
-
-#include <io/keycode.h>
-#include <ipc/kbd.h>
-#include <async.h>
-#include <fibril.h>
-#include <fibril_synch.h>
-
-#include <usb/usb.h>
-#include <usb/dp.h>
-#include <usb/request.h>
-#include <usb/classes/hid.h>
-#include <usb/pipes.h>
-#include <usb/debug.h>
-#include <usb/classes/hidparser.h>
-#include <usb/classes/classes.h>
-#include <usb/classes/hidut.h>
-#include <usb/classes/hidreq.h>
-#include <usb/classes/hidreport.h>
-
-#include <usb/devdrv.h>
-
-#include "kbddev.h"
-
-#include "layout.h"
-#include "conv.h"
-#include "kbdrepeat.h"
-
-/*----------------------------------------------------------------------------*/
-/** Default modifiers when the keyboard is initialized. */
-static const unsigned DEFAULT_ACTIVE_MODS = KM_NUM_LOCK;
-
-/** Boot protocol report size (key part). */
-static const size_t BOOTP_REPORT_SIZE = 6;
-
-/** Boot protocol total report size. */
-static const size_t BOOTP_BUFFER_SIZE = 8;
-
-/** Boot protocol output report size. */
-static const size_t BOOTP_BUFFER_OUT_SIZE = 1;
-
-/** Boot protocol error key code. */
-static const uint8_t BOOTP_ERROR_ROLLOVER = 1;
-
-/** Default idle rate for keyboards. */
-static const uint8_t IDLE_RATE = 0;
-
-/** Delay before a pressed key starts auto-repeating. */
-static const unsigned int DEFAULT_DELAY_BEFORE_FIRST_REPEAT = 500 * 1000;
-
-/** Delay between two repeats of a pressed key when auto-repeating. */
-static const unsigned int DEFAULT_REPEAT_DELAY = 50 * 1000;
-
-/*----------------------------------------------------------------------------*/
-
-/** Keyboard polling endpoint description for boot protocol class. */
-static usb_endpoint_description_t boot_poll_endpoint_description = {
-	.transfer_type = USB_TRANSFER_INTERRUPT,
-	.direction = USB_DIRECTION_IN,
-	.interface_class = USB_CLASS_HID,
-	.interface_subclass = USB_HID_SUBCLASS_BOOT,
-	.interface_protocol = USB_HID_PROTOCOL_KEYBOARD,
-	.flags = 0
-};
-
-/* Array of endpoints expected on the device, NULL terminated. */
-usb_endpoint_description_t 
-    *usb_kbd_endpoints[USB_KBD_POLL_EP_COUNT + 1] = {
-	&boot_poll_endpoint_description,
-	NULL
-};
-
-/*----------------------------------------------------------------------------*/
-
-enum {
-	BOOT_REPORT_DESCRIPTOR_SIZE = 63
-};
-
-static const uint8_t BOOT_REPORT_DESCRIPTOR[BOOT_REPORT_DESCRIPTOR_SIZE] = {
-        0x05, 0x01,  // Usage Page (Generic Desktop),
-        0x09, 0x06,  // Usage (Keyboard),
-        0xA1, 0x01,  // Collection (Application),
-        0x75, 0x01,  //   Report Size (1),
-        0x95, 0x08,  //   Report Count (8),       
-        0x05, 0x07,  //   Usage Page (Key Codes);
-        0x19, 0xE0,  //   Usage Minimum (224),
-        0x29, 0xE7,  //   Usage Maximum (231),
-        0x15, 0x00,  //   Logical Minimum (0),
-        0x25, 0x01,  //   Logical Maximum (1),
-        0x81, 0x02,  //   Input (Data, Variable, Absolute),   ; Modifier byte
-	0x95, 0x01,  //   Report Count (1),
-        0x75, 0x08,  //   Report Size (8),
-        0x81, 0x01,  //   Input (Constant),                   ; Reserved byte
-        0x95, 0x05,  //   Report Count (5),
-        0x75, 0x01,  //   Report Size (1),
-        0x05, 0x08,  //   Usage Page (Page# for LEDs),
-        0x19, 0x01,  //   Usage Minimum (1),
-        0x29, 0x05,  //   Usage Maxmimum (5),
-        0x91, 0x02,  //   Output (Data, Variable, Absolute),  ; LED report
-        0x95, 0x01,  //   Report Count (1),
-        0x75, 0x03,  //   Report Size (3),
-        0x91, 0x01,  //   Output (Constant),              ; LED report padding
-        0x95, 0x06,  //   Report Count (6),
-        0x75, 0x08,  //   Report Size (8),
-        0x15, 0x00,  //   Logical Minimum (0),
-        0x25, 0xff,  //   Logical Maximum (255),
-        0x05, 0x07,  //   Usage Page (Key Codes),
-        0x19, 0x00,  //   Usage Minimum (0),
-        0x29, 0xff,  //   Usage Maximum (255),
-        0x81, 0x00,  //   Input (Data, Array),            ; Key arrays (6 bytes)
-        0xC0           // End Collection
-
-};
-
-/*----------------------------------------------------------------------------*/
-
-typedef enum usb_kbd_flags {
-	USB_KBD_STATUS_UNINITIALIZED = 0,
-	USB_KBD_STATUS_INITIALIZED = 1,
-	USB_KBD_STATUS_TO_DESTROY = -1
-} usb_kbd_flags;
-
-/*----------------------------------------------------------------------------*/
-/* Keyboard layouts                                                           */
-/*----------------------------------------------------------------------------*/
-
-#define NUM_LAYOUTS 3
-
-/** Keyboard layout map. */
-static layout_op_t *layout[NUM_LAYOUTS] = {
-	&us_qwerty_op,
-	&us_dvorak_op,
-	&cz_op
-};
-
-static int active_layout = 0;
-
-/*----------------------------------------------------------------------------*/
-/* Modifier constants                                                         */
-/*----------------------------------------------------------------------------*/
-/** Mapping of USB modifier key codes to generic modifier key codes. */
-static const keycode_t usbhid_modifiers_keycodes[USB_HID_MOD_COUNT] = {
-	KC_LCTRL,         /* USB_HID_MOD_LCTRL */
-	KC_LSHIFT,        /* USB_HID_MOD_LSHIFT */
-	KC_LALT,          /* USB_HID_MOD_LALT */
-	0,                /* USB_HID_MOD_LGUI */
-	KC_RCTRL,         /* USB_HID_MOD_RCTRL */
-	KC_RSHIFT,        /* USB_HID_MOD_RSHIFT */
-	KC_RALT,          /* USB_HID_MOD_RALT */
-	0,                /* USB_HID_MOD_RGUI */
-};
-
-typedef enum usbhid_lock_code {
-	USB_KBD_LOCK_NUM = 0x53,
-	USB_KBD_LOCK_CAPS = 0x39,
-	USB_KBD_LOCK_SCROLL = 0x47,
-	USB_KBD_LOCK_COUNT = 3
-} usbhid_lock_code;
-
-static const usbhid_lock_code usbhid_lock_codes[USB_KBD_LOCK_COUNT] = {
-	USB_KBD_LOCK_NUM,
-	USB_KBD_LOCK_CAPS,
-	USB_KBD_LOCK_SCROLL
-};
-
-/*----------------------------------------------------------------------------*/
-/* IPC method handler                                                         */
-/*----------------------------------------------------------------------------*/
-
-static void default_connection_handler(ddf_fun_t *, ipc_callid_t, ipc_call_t *);
-ddf_dev_ops_t keyboard_ops = {
-	.default_handler = default_connection_handler
-};
-
-/** 
- * Default handler for IPC methods not handled by DDF.
- *
- * Currently recognizes only one method (IPC_M_CONNECT_TO_ME), in which case it
- * assumes the caller is the console and thus it stores IPC phone to it for 
- * later use by the driver to notify about key events.
- *
- * @param fun Device function handling the call.
- * @param icallid Call id.
- * @param icall Call data.
- */
-void default_connection_handler(ddf_fun_t *fun,
-    ipc_callid_t icallid, ipc_call_t *icall)
-{
-	sysarg_t method = IPC_GET_IMETHOD(*icall);
-	
-	usb_kbd_t *kbd_dev = (usb_kbd_t *)fun->driver_data;
-	assert(kbd_dev != NULL);
-
-	if (method == IPC_M_CONNECT_TO_ME) {
-		int callback = IPC_GET_ARG5(*icall);
-
-		if (kbd_dev->console_phone != -1) {
-			async_answer_0(icallid, ELIMIT);
-			return;
-		}
-
-		kbd_dev->console_phone = callback;
-		async_answer_0(icallid, EOK);
-		return;
-	}
-	
-	async_answer_0(icallid, EINVAL);
-}
-
-/*----------------------------------------------------------------------------*/
-/* Key processing functions                                                   */
-/*----------------------------------------------------------------------------*/
-/**
- * Handles turning of LED lights on and off.
- *
- * In case of USB keyboards, the LEDs are handled in the driver, not in the 
- * device. When there should be a change (lock key was pressed), the driver
- * uses a Set_Report request sent to the device to set the state of the LEDs.
- *
- * This functions sets the LED lights according to current settings of modifiers
- * kept in the keyboard device structure.
- *
- * @param kbd_dev Keyboard device structure.
- */
-static void usb_kbd_set_led(usb_kbd_t *kbd_dev) 
-{
-	uint8_t buffer[BOOTP_BUFFER_OUT_SIZE];
-	int rc= 0;
-	
-	memset(buffer, 0, BOOTP_BUFFER_OUT_SIZE);
-	uint8_t leds = 0;
-
-	if (kbd_dev->mods & KM_NUM_LOCK) {
-		leds |= USB_HID_LED_NUM_LOCK;
-	}
-	
-	if (kbd_dev->mods & KM_CAPS_LOCK) {
-		leds |= USB_HID_LED_CAPS_LOCK;
-	}
-	
-	if (kbd_dev->mods & KM_SCROLL_LOCK) {
-		leds |= USB_HID_LED_SCROLL_LOCK;
-	}
-
-	// TODO: COMPOSE and KANA
-	
-	usb_log_debug("Creating output report.\n");
-	usb_log_debug("Leds: 0x%x\n", leds);
-	if ((rc = usb_hid_boot_keyboard_output_report(
-	    leds, buffer, BOOTP_BUFFER_OUT_SIZE)) != EOK) {
-		usb_log_warning("Error composing output report to the keyboard:"
-		    "%s.\n", str_error(rc));
-		return;
-	}
-	
-	usb_log_debug("Output report buffer: %s\n", 
-	    usb_debug_str_buffer(buffer, BOOTP_BUFFER_OUT_SIZE, 0));
-	
-	assert(kbd_dev->usb_dev != NULL);
-	
-	usbhid_req_set_report(&kbd_dev->usb_dev->ctrl_pipe, 
-	    kbd_dev->usb_dev->interface_no, USB_HID_REPORT_TYPE_OUTPUT, 
-	    buffer, BOOTP_BUFFER_OUT_SIZE);
-}
-
-/*----------------------------------------------------------------------------*/
-/**
- * Processes key events.
- *
- * @note This function was copied from AT keyboard driver and modified to suit
- *       USB keyboard.
- *
- * @note Lock keys are not sent to the console, as they are completely handled
- *       in the driver. It may, however, be required later that the driver
- *       sends also these keys to application (otherwise it cannot use those
- *       keys at all).
- * 
- * @param kbd_dev Keyboard device structure.
- * @param type Type of the event (press / release). Recognized values: 
- *             KEY_PRESS, KEY_RELEASE
- * @param key Key code of the key according to HID Usage Tables.
- */
-void usb_kbd_push_ev(usb_kbd_t *kbd_dev, int type, unsigned int key)
-{
-	console_event_t ev;
-	unsigned mod_mask;
-
-	/*
-	 * These parts are copy-pasted from the AT keyboard driver.
-	 *
-	 * They definitely require some refactoring, but will keep it for later
-	 * when the console and keyboard system is changed in HelenOS.
-	 */
-	switch (key) {
-	case KC_LCTRL: mod_mask = KM_LCTRL; break;
-	case KC_RCTRL: mod_mask = KM_RCTRL; break;
-	case KC_LSHIFT: mod_mask = KM_LSHIFT; break;
-	case KC_RSHIFT: mod_mask = KM_RSHIFT; break;
-	case KC_LALT: mod_mask = KM_LALT; break;
-	case KC_RALT: mod_mask = KM_RALT; break;
-	default: mod_mask = 0; break;
-	}
-
-	if (mod_mask != 0) {
-		if (type == KEY_PRESS)
-			kbd_dev->mods = kbd_dev->mods | mod_mask;
-		else
-			kbd_dev->mods = kbd_dev->mods & ~mod_mask;
-	}
-
-	switch (key) {
-	case KC_CAPS_LOCK: mod_mask = KM_CAPS_LOCK; break;
-	case KC_NUM_LOCK: mod_mask = KM_NUM_LOCK; break;
-	case KC_SCROLL_LOCK: mod_mask = KM_SCROLL_LOCK; break;
-	default: mod_mask = 0; break;
-	}
-
-	if (mod_mask != 0) {
-		if (type == KEY_PRESS) {
-			/*
-			 * Only change lock state on transition from released
-			 * to pressed. This prevents autorepeat from messing
-			 * up the lock state.
-			 */
-			unsigned int locks_old = kbd_dev->lock_keys;
-			
-			kbd_dev->mods = 
-			    kbd_dev->mods ^ (mod_mask & ~kbd_dev->lock_keys);
-			kbd_dev->lock_keys = kbd_dev->lock_keys | mod_mask;
-
-			/* Update keyboard lock indicator lights. */
-			if (kbd_dev->lock_keys != locks_old) {
-				usb_kbd_set_led(kbd_dev);
-			}
-		} else {
-			kbd_dev->lock_keys = kbd_dev->lock_keys & ~mod_mask;
-		}
-	}
-
-	if (key == KC_CAPS_LOCK || key == KC_NUM_LOCK || key == KC_SCROLL_LOCK) {
-		// do not send anything to the console, this is our business
-		return;
-	}
-	
-	if (type == KEY_PRESS && (kbd_dev->mods & KM_LCTRL) && key == KC_F1) {
-		active_layout = 0;
-		layout[active_layout]->reset();
-		return;
-	}
-
-	if (type == KEY_PRESS && (kbd_dev->mods & KM_LCTRL) && key == KC_F2) {
-		active_layout = 1;
-		layout[active_layout]->reset();
-		return;
-	}
-
-	if (type == KEY_PRESS && (kbd_dev->mods & KM_LCTRL) && key == KC_F3) {
-		active_layout = 2;
-		layout[active_layout]->reset();
-		return;
-	}
-	
-	ev.type = type;
-	ev.key = key;
-	ev.mods = kbd_dev->mods;
-
-	ev.c = layout[active_layout]->parse_ev(&ev);
-
-	usb_log_debug2("Sending key %d to the console\n", ev.key);
-	if (kbd_dev->console_phone < 0) {
-		usb_log_warning(
-		    "Connection to console not ready, key discarded.\n");
-		return;
-	}
-	
-	async_msg_4(kbd_dev->console_phone, KBD_EVENT, ev.type, ev.key, 
-	    ev.mods, ev.c);
-}
-
-/*----------------------------------------------------------------------------*/
-
-static inline int usb_kbd_is_lock(unsigned int key_code) 
-{
-	return (key_code == KC_NUM_LOCK
-	    || key_code == KC_SCROLL_LOCK
-	    || key_code == KC_CAPS_LOCK);
-}
-
-/*----------------------------------------------------------------------------*/
-/**
- * Checks if some keys were pressed or released and generates key events.
- *
- * An event is created only when key is pressed or released. Besides handling
- * the events (usb_kbd_push_ev()), the auto-repeat fibril is notified about
- * key presses and releases (see usb_kbd_repeat_start() and 
- * usb_kbd_repeat_stop()).
- *
- * @param kbd_dev Keyboard device structure.
- * @param key_codes Parsed keyboard report - codes of currently pressed keys 
- *                  according to HID Usage Tables.
- * @param count Number of key codes in report (size of the report).
- *
- * @sa usb_kbd_push_ev(), usb_kbd_repeat_start(), usb_kbd_repeat_stop()
- */
-static void usb_kbd_check_key_changes(usb_kbd_t *kbd_dev, 
-    const uint8_t *key_codes, size_t count)
-{
-	unsigned int key;
-	unsigned int i, j;
-	
-	/*
-	 * First of all, check if the kbd have reported phantom state.
-	 *
-	 *  this must be changed as we don't know which keys are modifiers
-	 *       and which are regular keys.
-	 */
-	i = 0;
-	// all fields should report Error Rollover
-	while (i < count &&
-	    key_codes[i] == BOOTP_ERROR_ROLLOVER) {
-		++i;
-	}
-	if (i == count) {
-		usb_log_debug("Phantom state occured.\n");
-		// phantom state, do nothing
-		return;
-	}
-	
-	/* TODO: quite dummy right now, think of better implementation */
-	assert(count == kbd_dev->key_count);
-	
-	/*
-	 * 1) Key releases
-	 */
-	for (j = 0; j < count; ++j) {
-		// try to find the old key in the new key list
-		i = 0;
-		while (i < kbd_dev->key_count
-		    && key_codes[i] != kbd_dev->keys[j]) {
-			++i;
-		}
-		
-		if (i == count) {
-			// not found, i.e. the key was released
-			key = usbhid_parse_scancode(kbd_dev->keys[j]);
-			if (!usb_kbd_is_lock(key)) {
-				usb_kbd_repeat_stop(kbd_dev, key);
-			}
-			usb_kbd_push_ev(kbd_dev, KEY_RELEASE, key);
-			usb_log_debug2("Key released: %d\n", key);
-		} else {
-			// found, nothing happens
-		}
-	}
-	
-	/*
-	 * 1) Key presses
-	 */
-	for (i = 0; i < kbd_dev->key_count; ++i) {
-		// try to find the new key in the old key list
-		j = 0;
-		while (j < count && kbd_dev->keys[j] != key_codes[i]) { 
-			++j;
-		}
-		
-		if (j == count) {
-			// not found, i.e. new key pressed
-			key = usbhid_parse_scancode(key_codes[i]);
-			usb_log_debug2("Key pressed: %d (keycode: %d)\n", key,
-			    key_codes[i]);
-			usb_kbd_push_ev(kbd_dev, KEY_PRESS, key);
-			if (!usb_kbd_is_lock(key)) {
-				usb_kbd_repeat_start(kbd_dev, key);
-			}
-		} else {
-			// found, nothing happens
-		}
-	}
-	
-	memcpy(kbd_dev->keys, key_codes, count);
-
-	usb_log_debug("New stored keycodes: %s\n", 
-	    usb_debug_str_buffer(kbd_dev->keys, kbd_dev->key_count, 0));
-}
-
-/*----------------------------------------------------------------------------*/
-/* Callbacks for parser                                                       */
-/*----------------------------------------------------------------------------*/
-/**
- * Callback function for the HID report parser.
- *
- * This function is called by the HID report parser with the parsed report.
- * The parsed report is used to check if any events occured (key was pressed or
- * released, modifier was pressed or released).
- *
- * @param key_codes Parsed keyboard report - codes of currently pressed keys 
- *                  according to HID Usage Tables.
- * @param count Number of key codes in report (size of the report).
- * @param modifiers Bitmap of modifiers (Ctrl, Alt, Shift, GUI).
- * @param arg User-specified argument. Expects pointer to the keyboard device
- *            structure representing the keyboard.
- *
- * @sa usb_kbd_check_key_changes(), usb_kbd_check_modifier_changes()
- */
-static void usb_kbd_process_keycodes(const uint8_t *key_codes, size_t count,
-    uint8_t modifiers, void *arg)
-{
-	if (arg == NULL) {
-		usb_log_warning("Missing argument in callback "
-		    "usbhid_process_keycodes().\n");
-		return;
-	}
-	
-	usb_kbd_t *kbd_dev = (usb_kbd_t *)arg;
-	assert(kbd_dev != NULL);
-
-	usb_log_debug("Got keys from parser: %s\n", 
-	    usb_debug_str_buffer(key_codes, count, 0));
-	
-	if (count != kbd_dev->key_count) {
-		usb_log_warning("Number of received keycodes (%d) differs from"
-		    " expected number (%d).\n", count, kbd_dev->key_count);
-		return;
-	}
-	
-	///usb_kbd_check_modifier_changes(kbd_dev, key_codes, count);
-	usb_kbd_check_key_changes(kbd_dev, key_codes, count);
-}
-
-/*----------------------------------------------------------------------------*/
-/* General kbd functions                                                      */
-/*----------------------------------------------------------------------------*/
-/**
- * Processes data received from the device in form of report.
- *
- * This function uses the HID report parser to translate the data received from
- * the device into generic USB HID key codes and into generic modifiers bitmap.
- * The parser then calls the given callback (usb_kbd_process_keycodes()).
- *
- * @note Currently, only the boot protocol is supported.
- *
- * @param kbd_dev Keyboard device structure (must be initialized).
- * @param buffer Data from the keyboard (i.e. the report).
- * @param actual_size Size of the data from keyboard (report size) in bytes.
- *
- * @sa usb_kbd_process_keycodes(), usb_hid_boot_keyboard_input_report(),
- *     usb_hid_parse_report().
- */
-static void usb_kbd_process_data(usb_kbd_t *kbd_dev,
-                                    uint8_t *buffer, size_t actual_size)
-{
-	assert(kbd_dev->initialized == USB_KBD_STATUS_INITIALIZED);
-	assert(kbd_dev->parser != NULL);
-	
-	usb_hid_report_in_callbacks_t *callbacks =
-	    (usb_hid_report_in_callbacks_t *)malloc(
-	        sizeof(usb_hid_report_in_callbacks_t));
-	
-	callbacks->keyboard = usb_kbd_process_keycodes;
-
-	usb_log_debug("Calling usb_hid_parse_report() with "
-	    "buffer %s\n", usb_debug_str_buffer(buffer, actual_size, 0));
-	
-//	int rc = usb_hid_boot_keyboard_input_report(buffer, actual_size,
-//	    callbacks, kbd_dev);
-	usb_hid_report_path_t *path = usb_hid_report_path();
-	usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_KEYBOARD, 0);
-	
-	int rc = usb_hid_parse_report(kbd_dev->parser, buffer,
-	    actual_size, path, USB_HID_PATH_COMPARE_STRICT, callbacks, kbd_dev);
-
-	usb_hid_report_path_free (path);
-	
-	if (rc != EOK) {
-		usb_log_warning("Error in usb_hid_boot_keyboard_input_report():"
-		    "%s\n", str_error(rc));
-	}
-}
-
-/*----------------------------------------------------------------------------*/
-/* HID/KBD structure manipulation                                             */
-/*----------------------------------------------------------------------------*/
-
-static void usb_kbd_mark_unusable(usb_kbd_t *kbd_dev)
-{
-	kbd_dev->initialized = USB_KBD_STATUS_TO_DESTROY;
-}
-
-
-/*----------------------------------------------------------------------------*/
-/* API functions                                                              */
-/*----------------------------------------------------------------------------*/
-/**
- * Creates a new USB/HID keyboard structure.
- *
- * The structure returned by this function is not initialized. Use 
- * usb_kbd_init() to initialize it prior to polling.
- *
- * @return New uninitialized structure for representing a USB/HID keyboard or
- *         NULL if not successful (memory error).
- */
-usb_kbd_t *usb_kbd_new(void)
-{
-	usb_kbd_t *kbd_dev = 
-	    (usb_kbd_t *)malloc(sizeof(usb_kbd_t));
-
-	if (kbd_dev == NULL) {
-		usb_log_fatal("No memory!\n");
-		return NULL;
-	}
-	
-	memset(kbd_dev, 0, sizeof(usb_kbd_t));
-	
-	kbd_dev->parser = (usb_hid_report_parser_t *)(malloc(sizeof(
-	    usb_hid_report_parser_t)));
-	if (kbd_dev->parser == NULL) {
-		usb_log_fatal("No memory!\n");
-		free(kbd_dev);
-		return NULL;
-	}
-	
-	kbd_dev->console_phone = -1;
-	kbd_dev->initialized = USB_KBD_STATUS_UNINITIALIZED;
-	
-	return kbd_dev;
-}
-
-/*----------------------------------------------------------------------------*/
-/**
- * Initialization of the USB/HID keyboard structure.
- *
- * This functions initializes required structures from the device's descriptors.
- *
- * During initialization, the keyboard is switched into boot protocol, the idle
- * rate is set to 0 (infinity), resulting in the keyboard only reporting event
- * when a key is pressed or released. Finally, the LED lights are turned on 
- * according to the default setup of lock keys.
- *
- * @note By default, the keyboards is initialized with Num Lock turned on and 
- *       other locks turned off.
- *
- * @param kbd_dev Keyboard device structure to be initialized.
- * @param dev DDF device structure of the keyboard.
- *
- * @retval EOK if successful.
- * @retval EINVAL if some parameter is not given.
- * @return Other value inherited from function usbhid_dev_init().
- */
-int usb_kbd_init(usb_kbd_t *kbd_dev, usb_device_t *dev)
-{
-	int rc;
-	
-	usb_log_debug("Initializing HID/KBD structure...\n");
-	
-	if (kbd_dev == NULL) {
-		usb_log_error("Failed to init keyboard structure: no structure"
-		    " given.\n");
-		return EINVAL;
-	}
-	
-	if (dev == NULL) {
-		usb_log_error("Failed to init keyboard structure: no USB device"
-		    " given.\n");
-		return EINVAL;
-	}
-	
-	if (kbd_dev->initialized == USB_KBD_STATUS_INITIALIZED) {
-		usb_log_warning("Keyboard structure already initialized.\n");
-		return EINVAL;
-	}
-	
-	/* TODO: does not work! */
-	if (!dev->pipes[USB_KBD_POLL_EP_NO].present) {
-		usb_log_warning("Required endpoint not found - probably not "
-		    "a supported device.\n");
-		return ENOTSUP;
-	}
-	
-	/* The USB device should already be initialized, save it in structure */
-	kbd_dev->usb_dev = dev;
-	
-	/* Initialize the report parser. */
-	rc = usb_hid_parser_init(kbd_dev->parser);
-	if (rc != EOK) {
-		usb_log_error("Failed to initialize report parser.\n");
-		return rc;
-	}
-	
-	/* Get the report descriptor and parse it. */
-	rc = usb_hid_process_report_descriptor(kbd_dev->usb_dev, 
-	    kbd_dev->parser);
-	if (rc != EOK) {
-		usb_log_warning("Could not process report descriptor, "
-		    "falling back to boot protocol.\n");
-		rc = usb_hid_parse_report_descriptor(kbd_dev->parser, 
-		    BOOT_REPORT_DESCRIPTOR, BOOT_REPORT_DESCRIPTOR_SIZE);
-		if (rc != EOK) {
-			usb_log_error("Failed to parse boot report descriptor:"
-			    " %s.\n", str_error(rc));
-			return rc;
-		}
-		
-		rc = usbhid_req_set_protocol(&kbd_dev->usb_dev->ctrl_pipe, 
-		    kbd_dev->usb_dev->interface_no, USB_HID_PROTOCOL_BOOT);
-		
-		if (rc != EOK) {
-			usb_log_warning("Failed to set boot protocol to the "
-			    "device: %s\n", str_error(rc));
-			return rc;
-		}
-	}
-	
-	/*
-	 * TODO: make more general
-	 */
-	usb_hid_report_path_t *path = usb_hid_report_path();
-	usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_KEYBOARD, 0);
-	kbd_dev->key_count = usb_hid_report_input_length(
-	    kbd_dev->parser, path, USB_HID_PATH_COMPARE_STRICT);
-	usb_hid_report_path_free (path);
-	
-	usb_log_debug("Size of the input report: %zu\n", kbd_dev->key_count);
-	
-	kbd_dev->keys = (uint8_t *)calloc(
-	    kbd_dev->key_count, sizeof(uint8_t));
-	
-	if (kbd_dev->keys == NULL) {
-		usb_log_fatal("No memory!\n");
-		return ENOMEM;
-	}
-	
-	kbd_dev->modifiers = 0;
-	kbd_dev->mods = DEFAULT_ACTIVE_MODS;
-	kbd_dev->lock_keys = 0;
-	
-	kbd_dev->repeat.key_new = 0;
-	kbd_dev->repeat.key_repeated = 0;
-	kbd_dev->repeat.delay_before = DEFAULT_DELAY_BEFORE_FIRST_REPEAT;
-	kbd_dev->repeat.delay_between = DEFAULT_REPEAT_DELAY;
-	
-	kbd_dev->repeat_mtx = (fibril_mutex_t *)(
-	    malloc(sizeof(fibril_mutex_t)));
-	if (kbd_dev->repeat_mtx == NULL) {
-		usb_log_fatal("No memory!\n");
-		free(kbd_dev->keys);
-		return ENOMEM;
-	}
-	
-	fibril_mutex_initialize(kbd_dev->repeat_mtx);
-	
-	/*
-	 * Set LEDs according to initial setup.
-	 * Set Idle rate
-	 */
-	usb_kbd_set_led(kbd_dev);
-	
-	usbhid_req_set_idle(&kbd_dev->usb_dev->ctrl_pipe, 
-	    kbd_dev->usb_dev->interface_no, IDLE_RATE);
-	
-	kbd_dev->initialized = USB_KBD_STATUS_INITIALIZED;
-	usb_log_debug("HID/KBD device structure initialized.\n");
-	
-	return EOK;
-}
-
-/*----------------------------------------------------------------------------*/
-
-bool usb_kbd_polling_callback(usb_device_t *dev, uint8_t *buffer,
-     size_t buffer_size, void *arg)
-{
-	if (dev == NULL || buffer == NULL || arg == NULL) {
-		// do not continue polling (???)
-		return false;
-	}
-	
-	usb_kbd_t *kbd_dev = (usb_kbd_t *)arg;
-	
-	// TODO: add return value from this function
-	usb_kbd_process_data(kbd_dev, buffer, buffer_size);
-	
-	return true;
-}
-
-/*----------------------------------------------------------------------------*/
-
-void usb_kbd_polling_ended_callback(usb_device_t *dev, bool reason, 
-     void *arg)
-{
-	if (dev == NULL || arg == NULL) {
-		return;
-	}
-	
-	usb_kbd_t *kbd = (usb_kbd_t *)arg;
-	
-	usb_kbd_mark_unusable(kbd);
-}
-
-/*----------------------------------------------------------------------------*/
-
-int usb_kbd_is_initialized(const usb_kbd_t *kbd_dev)
-{
-	return (kbd_dev->initialized == USB_KBD_STATUS_INITIALIZED);
-}
-
-/*----------------------------------------------------------------------------*/
-
-int usb_kbd_is_ready_to_destroy(const usb_kbd_t *kbd_dev)
-{
-	return (kbd_dev->initialized == USB_KBD_STATUS_TO_DESTROY);
-}
-
-/*----------------------------------------------------------------------------*/
-/**
- * Properly destroys the USB/HID keyboard structure.
- *
- * @param kbd_dev Pointer to the structure to be destroyed.
- */
-void usb_kbd_free(usb_kbd_t **kbd_dev)
-{
-	if (kbd_dev == NULL || *kbd_dev == NULL) {
-		return;
-	}
-	
-	// hangup phone to the console
-	async_hangup((*kbd_dev)->console_phone);
-	
-//	if ((*kbd_dev)->hid_dev != NULL) {
-//		usbhid_dev_free(&(*kbd_dev)->hid_dev);
-//		assert((*kbd_dev)->hid_dev == NULL);
-//	}
-	
-	if ((*kbd_dev)->repeat_mtx != NULL) {
-		/* TODO: replace by some check and wait */
-		assert(!fibril_mutex_is_locked((*kbd_dev)->repeat_mtx));
-		free((*kbd_dev)->repeat_mtx);
-	}
-	
-	// destroy the parser
-	if ((*kbd_dev)->parser != NULL) {
-		usb_hid_free_report_parser((*kbd_dev)->parser);
-	}
-	
-	/* TODO: what about the USB device structure?? */
-
-	free(*kbd_dev);
-	*kbd_dev = NULL;
-}
-
-/**
- * @}
- */
Index: pace/drv/usbkbd/kbddev.h
===================================================================
--- uspace/drv/usbkbd/kbddev.h	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ 	(revision )
@@ -1,144 +1,0 @@
-/*
- * Copyright (c) 2011 Lubos Slovak
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - 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.
- * - 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 ``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 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.
- */
-
-/** @addtogroup drvusbhid
- * @{
- */
-/** @file
- * USB HID keyboard device structure and API.
- */
-
-#ifndef USB_KBDDEV_H_
-#define USB_KBDDEV_H_
-
-#include <stdint.h>
-
-#include <fibril_synch.h>
-
-#include <usb/classes/hid.h>
-#include <usb/classes/hidparser.h>
-#include <ddf/driver.h>
-#include <usb/pipes.h>
-#include <usb/devdrv.h>
-
-#include "kbdrepeat.h"
-
-/*----------------------------------------------------------------------------*/
-/**
- * USB/HID keyboard device type.
- *
- * Holds a reference to generic USB/HID device structure and keyboard-specific
- * data, such as currently pressed keys, modifiers and lock keys.
- *
- * Also holds a IPC phone to the console (since there is now no other way to 
- * communicate with it).
- *
- * @note Storing active lock keys in this structure results in their setting
- *       being device-specific.
- */
-typedef struct usb_kbd_t {
-	/** Structure holding generic USB device information. */
-	//usbhid_dev_t *hid_dev;
-	usb_device_t *usb_dev;
-	
-	/** Currently pressed keys (not translated to key codes). */
-	uint8_t *keys;
-	/** Count of stored keys (i.e. number of keys in the report). */
-	size_t key_count;
-	/** Currently pressed modifiers (bitmap). */
-	uint8_t modifiers;
-	
-	/** Currently active modifiers including locks. Sent to the console. */
-	unsigned mods;
-	
-	/** Currently active lock keys. */
-	unsigned lock_keys;
-	
-	/** IPC phone to the console device (for sending key events). */
-	int console_phone;
-	
-	/** Information for auto-repeat of keys. */
-	usb_kbd_repeat_t repeat;
-	
-	/** Mutex for accessing the information about auto-repeat. */
-	fibril_mutex_t *repeat_mtx;
-	
-	/** Report descriptor. */
-	uint8_t *report_desc;
-
-	/** Report descriptor size. */
-	size_t report_desc_size;
-
-	/** HID Report parser. */
-	usb_hid_report_parser_t *parser;
-	
-	/** State of the structure (for checking before use). 
-	 * 
-	 * 0 - not initialized
-	 * 1 - initialized
-	 * -1 - ready for destroying
-	 */
-	int initialized;
-} usb_kbd_t;
-
-/*----------------------------------------------------------------------------*/
-
-enum {
-	USB_KBD_POLL_EP_NO = 0,
-	USB_KBD_POLL_EP_COUNT = 1
-};
-
-usb_endpoint_description_t *usb_kbd_endpoints[USB_KBD_POLL_EP_COUNT + 1];
-
-ddf_dev_ops_t keyboard_ops;
-
-/*----------------------------------------------------------------------------*/
-
-usb_kbd_t *usb_kbd_new(void);
-
-int usb_kbd_init(usb_kbd_t *kbd_dev, usb_device_t *dev);
-
-bool usb_kbd_polling_callback(usb_device_t *dev, uint8_t *buffer,
-     size_t buffer_size, void *arg);
-
-void usb_kbd_polling_ended_callback(usb_device_t *dev, bool reason, 
-     void *arg);
-
-int usb_kbd_is_initialized(const usb_kbd_t *kbd_dev);
-
-int usb_kbd_is_ready_to_destroy(const usb_kbd_t *kbd_dev);
-
-void usb_kbd_free(usb_kbd_t **kbd_dev);
-
-void usb_kbd_push_ev(usb_kbd_t *kbd_dev, int type, unsigned int key);
-
-#endif /* USB_KBDDEV_H_ */
-
-/**
- * @}
- */
Index: pace/drv/usbkbd/kbdrepeat.c
===================================================================
--- uspace/drv/usbkbd/kbdrepeat.c	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ 	(revision )
@@ -1,185 +1,0 @@
-/*
- * Copyright (c) 2011 Lubos Slovak
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - 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.
- * - 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 ``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 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.
- */
-
-/** @addtogroup drvusbhid
- * @{
- */
-/**
- * @file
- * USB HID keyboard autorepeat facilities
- */
-
-#include <fibril_synch.h>
-#include <io/keycode.h>
-#include <io/console.h>
-#include <errno.h>
-
-#include <usb/debug.h>
-
-#include "kbdrepeat.h"
-#include "kbddev.h"
-
-
-/** Delay between auto-repeat state checks when no key is being repeated. */
-static unsigned int CHECK_DELAY = 10000;
-
-/*----------------------------------------------------------------------------*/
-/**
- * Main loop handling the auto-repeat of keys.
- *
- * This functions periodically checks if there is some key to be auto-repeated.
- *
- * If a new key is to be repeated, it uses the delay before first repeat stored
- * in the keyboard structure to wait until the key has to start repeating.
- *
- * If the same key is still pressed, it uses the delay between repeats stored
- * in the keyboard structure to wait until the key should be repeated.
- * 
- * If the currently repeated key is not pressed any more (
- * usb_kbd_repeat_stop() was called), it stops repeating it and starts 
- * checking again.
- *
- * @note For accessing the keyboard device auto-repeat information a fibril
- *       mutex (repeat_mtx) from the @a kbd structure is used.
- * 
- * @param kbd Keyboard device structure.
- */
-static void usb_kbd_repeat_loop(usb_kbd_t *kbd)
-{
-	unsigned int delay = 0;
-	
-	usb_log_debug("Starting autorepeat loop.\n");
-
-	while (true) {
-		// check if the kbd structure is usable
-		if (!usb_kbd_is_initialized(kbd)) {
-			if (usb_kbd_is_ready_to_destroy(kbd)) {
-				usb_kbd_free(&kbd);
-				assert(kbd == NULL);
-			}
-			return;
-		}
-		
-		fibril_mutex_lock(kbd->repeat_mtx);
-
-		if (kbd->repeat.key_new > 0) {
-			if (kbd->repeat.key_new == kbd->repeat.key_repeated) {
-				usb_log_debug2("Repeating key: %u.\n", 
-				    kbd->repeat.key_repeated);
-				usb_kbd_push_ev(kbd, KEY_PRESS, 
-				    kbd->repeat.key_repeated);
-				delay = kbd->repeat.delay_between;
-			} else {
-				usb_log_debug("New key to repeat: %u.\n", 
-				    kbd->repeat.key_new);
-				kbd->repeat.key_repeated = kbd->repeat.key_new;
-				delay = kbd->repeat.delay_before;
-			}
-		} else {
-			if (kbd->repeat.key_repeated > 0) {
-				usb_log_debug("Stopping to repeat key: %u.\n", 
-				    kbd->repeat.key_repeated);
-				kbd->repeat.key_repeated = 0;
-			}
-			delay = CHECK_DELAY;
-		}
-		fibril_mutex_unlock(kbd->repeat_mtx);
-		
-		async_usleep(delay);
-	}
-}
-
-/*----------------------------------------------------------------------------*/
-/**
- * Main routine to be executed by a fibril for handling auto-repeat.
- *
- * Starts the loop for checking changes in auto-repeat.
- * 
- * @param arg User-specified argument. Expects pointer to the keyboard device
- *            structure representing the keyboard.
- *
- * @retval EOK if the routine has finished.
- * @retval EINVAL if no argument is supplied.
- */
-int usb_kbd_repeat_fibril(void *arg)
-{
-	usb_log_debug("Autorepeat fibril spawned.\n");
-	
-	if (arg == NULL) {
-		usb_log_error("No device!\n");
-		return EINVAL;
-	}
-	
-	usb_kbd_t *kbd = (usb_kbd_t *)arg;
-	
-	usb_kbd_repeat_loop(kbd);
-	
-	return EOK;
-}
-
-/*----------------------------------------------------------------------------*/
-/**
- * Start repeating particular key.
- *
- * @note Only one key is repeated at any time, so calling this function 
- *       effectively cancels auto-repeat of the current repeated key (if any)
- *       and 'schedules' another key for auto-repeat.
- *
- * @param kbd Keyboard device structure.
- * @param key Key to start repeating.
- */
-void usb_kbd_repeat_start(usb_kbd_t *kbd, unsigned int key)
-{
-	fibril_mutex_lock(kbd->repeat_mtx);
-	kbd->repeat.key_new = key;
-	fibril_mutex_unlock(kbd->repeat_mtx);
-}
-
-/*----------------------------------------------------------------------------*/
-/**
- * Stop repeating particular key.
- *
- * @note Only one key is repeated at any time, but this function may be called
- *       even with key that is not currently repeated (in that case nothing 
- *       happens).
- *
- * @param kbd Keyboard device structure.
- * @param key Key to stop repeating.
- */
-void usb_kbd_repeat_stop(usb_kbd_t *kbd, unsigned int key)
-{
-	fibril_mutex_lock(kbd->repeat_mtx);
-	if (key == kbd->repeat.key_new) {
-		kbd->repeat.key_new = 0;
-	}
-	fibril_mutex_unlock(kbd->repeat_mtx);
-}
-
-/**
- * @}
- */
Index: pace/drv/usbkbd/kbdrepeat.h
===================================================================
--- uspace/drv/usbkbd/kbdrepeat.h	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ 	(revision )
@@ -1,68 +1,0 @@
-/*
- * Copyright (c) 2011 Lubos Slovak
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - 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.
- * - 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 ``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 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.
- */
-
-/** @addtogroup drvusbhid
- * @{
- */
-/** @file
- * USB HID keyboard autorepeat facilities
- */
-
-#ifndef USB_KBDREPEAT_H_
-#define USB_KBDREPEAT_H_
-
-struct usb_kbd_t;
-
-/*----------------------------------------------------------------------------*/
-/**
- * Structure for keeping information needed for auto-repeat of keys.
- */
-typedef struct {
-	/** Last pressed key. */
-	unsigned int key_new;
-	/** Key to be repeated. */
-	unsigned int key_repeated;
-	/** Delay before first repeat in microseconds. */
-	unsigned int delay_before;
-	/** Delay between repeats in microseconds. */
-	unsigned int delay_between;
-} usb_kbd_repeat_t;
-
-/*----------------------------------------------------------------------------*/
-
-int usb_kbd_repeat_fibril(void *arg);
-
-void usb_kbd_repeat_start(struct usb_kbd_t *kbd, unsigned int key);
-
-void usb_kbd_repeat_stop(struct usb_kbd_t *kbd, unsigned int key);
-
-#endif /* USB_KBDREPEAT_H_ */
-
-/**
- * @}
- */
Index: pace/drv/usbkbd/layout.h
===================================================================
--- uspace/drv/usbkbd/layout.h	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ 	(revision )
@@ -1,57 +1,0 @@
-/*
- * Copyright (c) 2009 Jiri Svoboda
- * Copyright (c) 2011 Lubos Slovak 
- * (copied from /uspace/srv/hid/kbd/include/layout.h)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - 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.
- * - 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 ``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 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.
- */
-
-/** @addtogroup drvusbhid
- * @{
- */
-/** @file
- * Keyboard layout.
- */
-
-#ifndef USB_KBD_LAYOUT_H_
-#define USB_KBD_LAYOUT_H_
-
-#include <sys/types.h>
-#include <io/console.h>
-
-typedef struct {
-	void (*reset)(void);
-	wchar_t (*parse_ev)(console_event_t *);
-} layout_op_t;
-
-extern layout_op_t us_qwerty_op;
-extern layout_op_t us_dvorak_op;
-extern layout_op_t cz_op;
-
-#endif
-
-/**
- * @}
- */
Index: pace/drv/usbkbd/main.c
===================================================================
--- uspace/drv/usbkbd/main.c	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ 	(revision )
@@ -1,264 +1,0 @@
-/*
- * Copyright (c) 2010 Vojtech Horky
- * Copyright (c) 2011 Lubos Slovak
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - 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.
- * - 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 ``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 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.
- */
-
-/** @addtogroup drvusbhid
- * @{
- */
-/**
- * @file
- * Main routines of USB HID driver.
- */
-
-#include <ddf/driver.h>
-#include <usb/debug.h>
-#include <errno.h>
-#include <str_error.h>
-
-#include <usb/devdrv.h>
-
-#include "kbddev.h"
-#include "kbdrepeat.h"
-
-/*----------------------------------------------------------------------------*/
-
-#define NAME "usbkbd"
-
-/**
- * Function for adding a new device of type USB/HID/keyboard.
- *
- * This functions initializes required structures from the device's descriptors
- * and starts new fibril for polling the keyboard for events and another one for
- * handling auto-repeat of keys.
- *
- * During initialization, the keyboard is switched into boot protocol, the idle
- * rate is set to 0 (infinity), resulting in the keyboard only reporting event
- * when a key is pressed or released. Finally, the LED lights are turned on 
- * according to the default setup of lock keys.
- *
- * @note By default, the keyboards is initialized with Num Lock turned on and 
- *       other locks turned off.
- * @note Currently supports only boot-protocol keyboards.
- *
- * @param dev Device to add.
- *
- * @retval EOK if successful.
- * @retval ENOMEM if there
- * @return Other error code inherited from one of functions usb_kbd_init(),
- *         ddf_fun_bind() and ddf_fun_add_to_class().
- *
- * @sa usb_kbd_fibril(), usb_kbd_repeat_fibril()
- */
-static int usbhid_try_add_device(usb_device_t *dev)
-{
-	/* Create the function exposed under /dev/devices. */
-	ddf_fun_t *kbd_fun = ddf_fun_create(dev->ddf_dev, fun_exposed, 
-	    "keyboard");
-	if (kbd_fun == NULL) {
-		usb_log_error("Could not create DDF function node.\n");
-		return ENOMEM;
-	}
-	
-	/* 
-	 * Initialize device (get and process descriptors, get address, etc.)
-	 */
-	usb_log_debug("Initializing USB/HID KBD device...\n");
-	
-	usb_kbd_t *kbd_dev = usb_kbd_new();
-	if (kbd_dev == NULL) {
-		usb_log_error("Error while creating USB/HID KBD device "
-		    "structure.\n");
-		ddf_fun_destroy(kbd_fun);
-		return ENOMEM;  // TODO: some other code??
-	}
-	
-	int rc = usb_kbd_init(kbd_dev, dev);
-	
-	if (rc != EOK) {
-		usb_log_error("Failed to initialize USB/HID KBD device.\n");
-		ddf_fun_destroy(kbd_fun);
-		usb_kbd_free(&kbd_dev);
-		return rc;
-	}	
-	
-	usb_log_debug("USB/HID KBD device structure initialized.\n");
-	
-	/*
-	 * Store the initialized keyboard device and keyboard ops
-	 * to the DDF function.
-	 */
-	kbd_fun->driver_data = kbd_dev;
-	kbd_fun->ops = &keyboard_ops;
-
-	rc = ddf_fun_bind(kbd_fun);
-	if (rc != EOK) {
-		usb_log_error("Could not bind DDF function: %s.\n",
-		    str_error(rc));
-		// TODO: Can / should I destroy the DDF function?
-		ddf_fun_destroy(kbd_fun);
-		usb_kbd_free(&kbd_dev);
-		return rc;
-	}
-	
-	rc = ddf_fun_add_to_class(kbd_fun, "keyboard");
-	if (rc != EOK) {
-		usb_log_error(
-		    "Could not add DDF function to class 'keyboard': %s.\n",
-		    str_error(rc));
-		// TODO: Can / should I destroy the DDF function?
-		ddf_fun_destroy(kbd_fun);
-		usb_kbd_free(&kbd_dev);
-		return rc;
-	}
-	
-	/*
-	 * Create new fibril for handling this keyboard
-	 */
-	//fid_t fid = fibril_create(usb_kbd_fibril, kbd_dev);
-	
-	/* Start automated polling function.
-	 * This will create a separate fibril that will query the device
-	 * for the data continuously 
-	 */
-       rc = usb_device_auto_poll(dev,
-	   /* Index of the polling pipe. */
-	   USB_KBD_POLL_EP_NO,
-	   /* Callback when data arrives. */
-	   usb_kbd_polling_callback,
-	   /* How much data to request. */
-	   dev->pipes[USB_KBD_POLL_EP_NO].pipe->max_packet_size,
-	   /* Callback when the polling ends. */
-	   usb_kbd_polling_ended_callback,
-	   /* Custom argument. */
-	   kbd_dev);
-	
-	
-	if (rc != EOK) {
-		usb_log_error("Failed to start polling fibril for `%s'.\n",
-		    dev->ddf_dev->name);
-		return rc;
-	}
-	//fibril_add_ready(fid);
-	
-	/*
-	 * Create new fibril for auto-repeat
-	 */
-	fid_t fid = fibril_create(usb_kbd_repeat_fibril, kbd_dev);
-	if (fid == 0) {
-		usb_log_error("Failed to start fibril for KBD auto-repeat");
-		return ENOMEM;
-	}
-	fibril_add_ready(fid);
-
-	(void)keyboard_ops;
-
-	/*
-	 * Hurrah, device is initialized.
-	 */
-	return EOK;
-}
-
-/*----------------------------------------------------------------------------*/
-/**
- * Callback for passing a new device to the driver.
- *
- * @note Currently, only boot-protocol keyboards are supported by this driver.
- *
- * @param dev Structure representing the new device.
- *
- * @retval EOK if successful. 
- * @retval EREFUSED if the device is not supported.
- */
-static int usbhid_add_device(usb_device_t *dev)
-{
-	usb_log_debug("usbhid_add_device()\n");
-	
-	if (dev->interface_no < 0) {
-		usb_log_warning("Device is not a supported keyboard.\n");
-		usb_log_error("Failed to add HID device: endpoint not found."
-		    "\n");
-		return ENOTSUP;
-	}
-	
-	int rc = usbhid_try_add_device(dev);
-	
-	if (rc != EOK) {
-		usb_log_warning("Device is not a supported keyboard.\n");
-		usb_log_error("Failed to add HID device: %s.\n",
-		    str_error(rc));
-		return rc;
-	}
-	
-	usb_log_info("Keyboard `%s' ready to use.\n", dev->ddf_dev->name);
-
-	return EOK;
-}
-
-/*----------------------------------------------------------------------------*/
-
-/* Currently, the framework supports only device adding. Once the framework
- * supports unplug, more callbacks will be added. */
-static usb_driver_ops_t usbhid_driver_ops = {
-        .add_device = usbhid_add_device,
-};
-
-
-/* The driver itself. */
-static usb_driver_t usbhid_driver = {
-        .name = NAME,
-        .ops = &usbhid_driver_ops,
-        .endpoints = usb_kbd_endpoints
-};
-
-/*----------------------------------------------------------------------------*/
-
-//static driver_ops_t kbd_driver_ops = {
-//	.add_device = usbhid_add_device,
-//};
-
-///*----------------------------------------------------------------------------*/
-
-//static driver_t kbd_driver = {
-//	.name = NAME,
-//	.driver_ops = &kbd_driver_ops
-//};
-
-/*----------------------------------------------------------------------------*/
-
-int main(int argc, char *argv[])
-{
-	printf(NAME ": HelenOS USB HID driver.\n");
-
-	usb_log_enable(USB_LOG_LEVEL_DEBUG, NAME);
-
-	return usb_driver_main(&usbhid_driver);
-}
-
-/**
- * @}
- */
Index: pace/drv/usbkbd/usbkbd.ma
===================================================================
--- uspace/drv/usbkbd/usbkbd.ma	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ 	(revision )
@@ -1,2 +1,0 @@
-100 usb&interface&class=HID&subclass=0x01&protocol=0x01
-10 usb&interface&class=HID
Index: uspace/lib/c/generic/malloc.c
===================================================================
--- uspace/lib/c/generic/malloc.c	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ uspace/lib/c/generic/malloc.c	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -240,5 +240,5 @@
 	size_t asize = ALIGN_UP(size, PAGE_SIZE);
 	
-	astart = as_area_create(astart, asize, AS_AREA_WRITE | AS_AREA_READ | AS_AREA_CACHEABLE);
+	astart = as_area_create(astart, asize, AS_AREA_WRITE | AS_AREA_READ);
 	if (astart == (void *) -1)
 		return false;
Index: uspace/lib/usb/Makefile
===================================================================
--- uspace/lib/usb/Makefile	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ uspace/lib/usb/Makefile	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -50,6 +50,4 @@
 	src/usb.c \
 	src/usbdevice.c \
-	src/hidreq.c \
-	src/hidreport.c \
 	src/host/device_keeper.c \
 	src/host/batch.c
Index: uspace/lib/usb/include/usb/classes/hidparser.h
===================================================================
--- uspace/lib/usb/include/usb/classes/hidparser.h	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ uspace/lib/usb/include/usb/classes/hidparser.h	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -70,18 +70,6 @@
  * Description of path of usage pages and usages in report descriptor
  */
-#define USB_HID_PATH_COMPARE_STRICT				0
-#define USB_HID_PATH_COMPARE_END				1
-#define USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY	4
-
 typedef struct {
 	int32_t usage_page;
-	int32_t usage;
-
-	link_t link;
-} usb_hid_report_usage_path_t;
-
-typedef struct {
-	int depth;	
-	link_t link;
 } usb_hid_report_path_t;
 
@@ -91,4 +79,6 @@
 typedef struct {
 	int32_t id;
+	int32_t usage_page;
+	int32_t	usage;	
 	int32_t usage_minimum;
 	int32_t usage_maximum;
@@ -117,5 +107,4 @@
 	uint8_t item_flags;
 
-	usb_hid_report_path_t *usage_path;
 	link_t link;
 } usb_hid_report_item_t;
@@ -128,4 +117,5 @@
 	link_t feature;
 } usb_hid_report_parser_t;	
+
 
 
@@ -204,9 +194,8 @@
 int usb_hid_parse_report(const usb_hid_report_parser_t *parser,  
     const uint8_t *data, size_t size,
-    usb_hid_report_path_t *path, int flags,
     const usb_hid_report_in_callbacks_t *callbacks, void *arg);
 
 int usb_hid_report_input_length(const usb_hid_report_parser_t *parser,
-	usb_hid_report_path_t *path, int flags);
+	const usb_hid_report_path_t *path);
 
 
@@ -215,20 +204,4 @@
 void usb_hid_descriptor_print(usb_hid_report_parser_t *parser);
 
-/* usage path functions */
-usb_hid_report_path_t *usb_hid_report_path(void);
-void usb_hid_report_path_free(usb_hid_report_path_t *path);
-int usb_hid_report_path_append_item(usb_hid_report_path_t *usage_path, int32_t usage_page, int32_t usage);
-void usb_hid_report_remove_last_item(usb_hid_report_path_t *usage_path);
-void usb_hid_report_null_last_item(usb_hid_report_path_t *usage_path);
-void usb_hid_report_set_last_item(usb_hid_report_path_t *usage_path, int32_t tag, int32_t data);
-int usb_hid_report_compare_usage_path(usb_hid_report_path_t *report_path, usb_hid_report_path_t *path, int flags);
-int	usb_hid_report_path_clone(usb_hid_report_path_t *new_usage_path, usb_hid_report_path_t *usage_path);
-
-
-// output
-//	- funkce co vrati cesty poli v output reportu
-//	- funkce co pro danou cestu nastavi data
-//	- finalize
-
 #endif
 /**
Index: pace/lib/usb/include/usb/classes/hidreport.h
===================================================================
--- uspace/lib/usb/include/usb/classes/hidreport.h	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ 	(revision )
@@ -1,65 +1,0 @@
-/*
- * Copyright (c) 2011 Lubos Slovak
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - 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.
- * - 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 ``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 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.
- */
-
-/** @addtogroup libusb
- * @{
- */
-/** @file
- * USB HID report parser initialization from descriptors.
- */
-
-#ifndef LIBUSB_HIDREPORT_H_
-#define LIBUSB_HIDREPORT_H_
-
-#include <usb/devdrv.h>
-#include <usb/classes/hidparser.h>
-
-/**
- * Retrieves the Report descriptor from the USB device and initializes the
- * report parser.
- *
- * \param dev USB device representing a HID device.
- * \param parser HID Report parser.
- *
- * \retval EOK if successful.
- * \retval EINVAL if one of the parameters is not given (is NULL).
- * \retval ENOENT if there are some descriptors missing.
- * \retval ENOMEM if an error with allocation occured.
- * \retval EINVAL if the Report descriptor's size does not match the size 
- *         from the interface descriptor.
- * \return Other value inherited from function usb_pipe_start_session(),
- *         usb_pipe_end_session() or usb_request_get_descriptor().
- */
-int usb_hid_process_report_descriptor(usb_device_t *dev, 
-    usb_hid_report_parser_t *parser);
-
-#endif /* LIBUSB_HIDREPORT_H_ */
-
-/**
- * @}
- */
Index: pace/lib/usb/include/usb/classes/hidreq.h
===================================================================
--- uspace/lib/usb/include/usb/classes/hidreq.h	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ 	(revision )
@@ -1,69 +1,0 @@
-/*
- * Copyright (c) 2011 Lubos Slovak
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - 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.
- * - 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 ``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 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.
- */
-
-/** @addtogroup libusb
- * @{
- */
-/** @file
- * HID class-specific requests.
- */
-
-#ifndef USB_KBD_HIDREQ_H_
-#define USB_KBD_HIDREQ_H_
-
-#include <stdint.h>
-
-#include <usb/classes/hid.h>
-#include <usb/pipes.h>
-
-/*----------------------------------------------------------------------------*/
-
-int usbhid_req_set_report(usb_pipe_t *ctrl_pipe, int iface_no,
-    usb_hid_report_type_t type, uint8_t *buffer, size_t buf_size);
-
-int usbhid_req_set_protocol(usb_pipe_t *ctrl_pipe, int iface_no, 
-    usb_hid_protocol_t protocol);
-
-int usbhid_req_set_idle(usb_pipe_t *ctrl_pipe, int iface_no, uint8_t duration);
-
-int usbhid_req_get_report(usb_pipe_t *ctrl_pipe, int iface_no, 
-    usb_hid_report_type_t type, uint8_t *buffer, size_t buf_size, 
-    size_t *actual_size);
-
-int usbhid_req_get_protocol(usb_pipe_t *ctrl_pipe, int iface_no, 
-    usb_hid_protocol_t *protocol);
-
-int usbhid_req_get_idle(usb_pipe_t *ctrl_pipe, int iface_no, uint8_t *duration);
-
-/*----------------------------------------------------------------------------*/
-
-#endif /* USB_KBD_HIDREQ_H_ */
-
-/**
- * @}
- */
Index: uspace/lib/usb/include/usb/host/device_keeper.h
===================================================================
--- uspace/lib/usb/include/usb/host/device_keeper.h	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ uspace/lib/usb/include/usb/host/device_keeper.h	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -51,5 +51,4 @@
 	usb_speed_t speed;
 	bool occupied;
-	bool control_used;
 	uint16_t toggle_status[2];
 	devman_handle_t handle;
@@ -62,5 +61,5 @@
 	struct usb_device_info devices[USB_ADDRESS_COUNT];
 	fibril_mutex_t guard;
-	fibril_condvar_t change;
+	fibril_condvar_t default_address_occupied;
 	usb_address_t last_address;
 } usb_device_keeper_t;
@@ -98,10 +97,4 @@
     usb_address_t address);
 
-void usb_device_keeper_use_control(usb_device_keeper_t *instance,
-    usb_address_t address);
-
-void usb_device_keeper_release_control(usb_device_keeper_t *instance,
-    usb_address_t address);
-
 #endif
 /**
Index: uspace/lib/usb/src/hidparser.c
===================================================================
--- uspace/lib/usb/src/hidparser.c	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ uspace/lib/usb/src/hidparser.c	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -47,11 +47,11 @@
 
 int usb_hid_report_parse_tag(uint8_t tag, uint8_t class, const uint8_t *data, size_t item_size,
-                             usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path);
+                             usb_hid_report_item_t *report_item);
 int usb_hid_report_parse_main_tag(uint8_t tag, const uint8_t *data, size_t item_size,
-                             usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path);
+                             usb_hid_report_item_t *report_item);
 int usb_hid_report_parse_global_tag(uint8_t tag, const uint8_t *data, size_t item_size,
-                             usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path);
+                             usb_hid_report_item_t *report_item);
 int usb_hid_report_parse_local_tag(uint8_t tag, const uint8_t *data, size_t item_size,
-                             usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path);
+                             usb_hid_report_item_t *report_item);
 
 void usb_hid_descriptor_print_list(link_t *head);
@@ -63,5 +63,4 @@
 int usb_pow(int a, int b);
 
-
 int usb_pow(int a, int b)
 {
@@ -85,5 +84,5 @@
 {
    if(parser == NULL) {
-	return EINVAL;
+	return -1;
    }
 
@@ -111,7 +110,5 @@
 	int ret;
 	usb_hid_report_item_t *report_item=0;
-	usb_hid_report_item_t *new_report_item;	
-	usb_hid_report_path_t *usage_path;
-	usb_hid_report_path_t *tmp_usage_path;
+	usb_hid_report_item_t *new_report_item;
 
 	size_t offset_input=0;
@@ -120,27 +117,16 @@
 	
 
-	/* parser structure initialization*/
-	if(usb_hid_parser_init(parser) != EOK) {
-		return EINVAL;
-	}
-	
-
-	/*report item initialization*/
 	if(!(report_item=malloc(sizeof(usb_hid_report_item_t)))){
 		return ENOMEM;
 	}
 	memset(report_item, 0, sizeof(usb_hid_report_item_t));
-	list_initialize(&(report_item->link));	
-
-	/* usage path context initialization */
-	if(!(usage_path=usb_hid_report_path())){
-		return ENOMEM;
-	}
-	
+	
+	link_initialize(&(report_item->link));	
+
 	while(i<size){	
 		if(!USB_HID_ITEM_IS_LONG(data[i])){
 
 			if((i+USB_HID_ITEM_SIZE(data[i]))>= size){
-				return EINVAL; // TODO ERROR CODE
+				return -1; // TODO ERROR CODE
 			}
 			
@@ -155,24 +141,10 @@
 			
 			ret = usb_hid_report_parse_tag(tag,class,data+i+1,
-			                               item_size,report_item, usage_path);
+			                         item_size,report_item);
 			usb_log_debug2("ret: %u\n", ret);
 			switch(ret){
 				case USB_HID_NEW_REPORT_ITEM:
 					// store report item to report and create the new one
-					usb_log_debug("\nNEW REPORT ITEM: %X",ret);
-
-					// store current usage path
-					report_item->usage_path = usage_path;
-
-					// new current usage path 
-					tmp_usage_path = usb_hid_report_path();
-					
-					// copy old path to the new one
-					usb_hid_report_path_clone(tmp_usage_path, usage_path);
-
-					// swap
-					usage_path = tmp_usage_path;
-					tmp_usage_path = NULL;
-
+					usb_log_debug("\nNEW REPORT ITEM: %X",tag);
 					
 					switch(tag) {
@@ -212,5 +184,5 @@
 					link_initialize(&(new_report_item->link));
 					report_item = new_report_item;
-										
+					
 					break;
 				case USB_HID_REPORT_TAG_PUSH:
@@ -312,5 +284,5 @@
  */
 int usb_hid_report_parse_tag(uint8_t tag, uint8_t class, const uint8_t *data, size_t item_size,
-                             usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path)
+                             usb_hid_report_item_t *report_item)
 {	
 	int ret;
@@ -319,5 +291,5 @@
 		case USB_HID_TAG_CLASS_MAIN:
 
-			if((ret=usb_hid_report_parse_main_tag(tag,data,item_size,report_item, usage_path)) == EOK) {
+			if((ret=usb_hid_report_parse_main_tag(tag,data,item_size,report_item)) == EOK) {
 				return USB_HID_NEW_REPORT_ITEM;
 			}
@@ -329,9 +301,9 @@
 
 		case USB_HID_TAG_CLASS_GLOBAL:	
-			return usb_hid_report_parse_global_tag(tag,data,item_size,report_item, usage_path);
+			return usb_hid_report_parse_global_tag(tag,data,item_size,report_item);
 			break;
 
 		case USB_HID_TAG_CLASS_LOCAL:			
-			return usb_hid_report_parse_local_tag(tag,data,item_size,report_item, usage_path);
+			return usb_hid_report_parse_local_tag(tag,data,item_size,report_item);
 			break;
 		default:
@@ -351,6 +323,6 @@
 
 int usb_hid_report_parse_main_tag(uint8_t tag, const uint8_t *data, size_t item_size,
-                             usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path)
-{		
+                             usb_hid_report_item_t *report_item)
+{
 	switch(tag)
 	{
@@ -363,14 +335,10 @@
 			
 		case USB_HID_REPORT_TAG_COLLECTION:
-			usb_hid_report_path_append_item(usage_path, 0, 0);
-						
+			// TODO
 			return USB_HID_NO_ACTION;
 			break;
 			
 		case USB_HID_REPORT_TAG_END_COLLECTION:
-			// TODO
-			// znici posledni uroven ve vsech usage paths
-			// otazka jestli nema nicit dve, respektive novou posledni vynulovat?
-			usb_hid_report_remove_last_item(usage_path);
+			/* should be ignored */
 			return USB_HID_NO_ACTION;
 			break;
@@ -393,5 +361,5 @@
 
 int usb_hid_report_parse_global_tag(uint8_t tag, const uint8_t *data, size_t item_size,
-                             usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path)
+                             usb_hid_report_item_t *report_item)
 {
 	// TODO take care about the bit length of data
@@ -399,7 +367,5 @@
 	{
 		case USB_HID_REPORT_TAG_USAGE_PAGE:
-			// zmeni to jenom v poslednim poli aktualni usage path
-			usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_GLOBAL,
-				usb_hid_report_tag_data_int32(data,item_size));
+			report_item->usage_page = usb_hid_report_tag_data_int32(data,item_size);
 			break;
 		case USB_HID_REPORT_TAG_LOGICAL_MINIMUM:
@@ -452,11 +418,10 @@
  */
 int usb_hid_report_parse_local_tag(uint8_t tag, const uint8_t *data, size_t item_size,
-                             usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path)
+                             usb_hid_report_item_t *report_item)
 {
 	switch(tag)
 	{
 		case USB_HID_REPORT_TAG_USAGE:
-			usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_LOCAL,
-				usb_hid_report_tag_data_int32(data,item_size));
+			report_item->usage = usb_hid_report_tag_data_int32(data,item_size);
 			break;
 		case USB_HID_REPORT_TAG_USAGE_MINIMUM:
@@ -526,6 +491,4 @@
 {
 	usb_hid_report_item_t *report_item;
-	usb_hid_report_usage_path_t *path_item;
-	link_t *path;
 	link_t *item;
 	
@@ -544,16 +507,6 @@
 		usb_log_debug("\tCONSTANT/VAR: %X\n", USB_HID_ITEM_FLAG_CONSTANT(report_item->item_flags));
 		usb_log_debug("\tVARIABLE/ARRAY: %X\n", USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags));
-		usb_log_debug("\tUSAGE PATH:\n");
-
-		path = report_item->usage_path->link.next;
-		while(path != &report_item->usage_path->link)	{
-			path_item = list_get_instance(path, usb_hid_report_usage_path_t, link);
-			usb_log_debug("\t\tUSAGE PAGE: %X, USAGE: %X\n", path_item->usage_page, path_item->usage);
-			path = path->next;
-		}
-		
-		
-//		usb_log_debug("\tUSAGE: %X\n", report_item->usage);
-//		usb_log_debug("\tUSAGE PAGE: %X\n", report_item->usage_page);
+		usb_log_debug("\tUSAGE: %X\n", report_item->usage);
+		usb_log_debug("\tUSAGE PAGE: %X\n", report_item->usage_page);
 		usb_log_debug("\tLOGMIN: %X\n", report_item->logical_minimum);
 		usb_log_debug("\tLOGMAX: %X\n", report_item->logical_maximum);		
@@ -577,8 +530,4 @@
 void usb_hid_descriptor_print(usb_hid_report_parser_t *parser)
 {
-	if(parser == NULL) {
-		return;
-	}
-	
 	usb_log_debug("INPUT:\n");
 	usb_hid_descriptor_print_list(&parser->input);
@@ -612,10 +561,4 @@
 	
 	    report_item = list_get_instance(next, usb_hid_report_item_t, link);
-
-		while(!list_empty(&report_item->usage_path->link)) {
-			usb_hid_report_remove_last_item(report_item->usage_path);
-		}
-
-		
 	    next = next->next;
 	    
@@ -657,5 +600,4 @@
 int usb_hid_parse_report(const usb_hid_report_parser_t *parser,  
     const uint8_t *data, size_t size,
-    usb_hid_report_path_t *path, int flags,
     const usb_hid_report_in_callbacks_t *callbacks, void *arg)
 {
@@ -673,11 +615,8 @@
 	size_t j=0;
 
-	if(parser == NULL) {
-		return EINVAL;
-	}
-
-	
 	// get the size of result keycodes array
-	key_count = usb_hid_report_input_length(parser, path, flags);
+	usb_hid_report_path_t path;
+	path.usage_page = BAD_HACK_USAGE_PAGE;
+	key_count = usb_hid_report_input_length(parser, &path);
 
 	if(!(keys = malloc(sizeof(uint8_t) * key_count))){
@@ -690,6 +629,6 @@
 
 		item = list_get_instance(list_item, usb_hid_report_item_t, link);
-		if(!USB_HID_ITEM_FLAG_CONSTANT(item->item_flags) && 
-		   (usb_hid_report_compare_usage_path(item->usage_path, path, flags) == EOK)) {
+		if(!USB_HID_ITEM_FLAG_CONSTANT(item->item_flags) &&
+		   (item->usage_page == path.usage_page)) {
 			for(j=0; j<(size_t)(item->count); j++) {
 				if((USB_HID_ITEM_FLAG_VARIABLE(item->item_flags) == 0) ||
@@ -701,5 +640,5 @@
 					// bitmapa
 					if((item_value = usb_hid_translate_data(item, data, j)) != 0) {
-						keys[i++] = (item->count - 1 - j) + item->usage_minimum;
+						keys[i++] = j + item->usage_minimum;
 					}
 					else {
@@ -797,19 +736,15 @@
 
 int usb_hid_report_input_length(const usb_hid_report_parser_t *parser,
-	usb_hid_report_path_t *path, int flags)
-{	
+	const usb_hid_report_path_t *path)
+{
 	int ret = 0;
 	link_t *item;
 	usb_hid_report_item_t *report_item;
 
-	if(parser == NULL) {
-		return EINVAL;
-	}
-	
 	item = (&parser->input)->next;
 	while(&parser->input != item) {
 		report_item = list_get_instance(item, usb_hid_report_item_t, link);
 		if(!USB_HID_ITEM_FLAG_CONSTANT(report_item->item_flags) &&
-		   (usb_hid_report_compare_usage_path(report_item->usage_path, path, flags) == EOK)) {
+		   (report_item->usage_page == path->usage_page)) {
 			ret += report_item->count;
 		}
@@ -822,224 +757,4 @@
 
 
-/**
- * 
- */
-int usb_hid_report_path_append_item(usb_hid_report_path_t *usage_path, 
-                                    int32_t usage_page, int32_t usage)
-{	
-	usb_hid_report_usage_path_t *item;
-
-	if(!(item=malloc(sizeof(usb_hid_report_usage_path_t)))) {
-		return ENOMEM;
-	}
-	list_initialize(&item->link);
-
-	item->usage = usage;
-	item->usage_page = usage_page;
-	
-	list_append (&usage_path->link, &item->link);
-	usage_path->depth++;
-	return EOK;
-}
-
-/**
- *
- */
-void usb_hid_report_remove_last_item(usb_hid_report_path_t *usage_path)
-{
-	usb_hid_report_usage_path_t *item;
-	
-	if(!list_empty(&usage_path->link)){
-		item = list_get_instance(usage_path->link.prev, usb_hid_report_usage_path_t, link);		
-		list_remove(usage_path->link.prev);
-		usage_path->depth--;
-		free(item);
-	}
-}
-
-/**
- *
- */
-void usb_hid_report_null_last_item(usb_hid_report_path_t *usage_path)
-{
-	usb_hid_report_usage_path_t *item;
-	
-	if(!list_empty(&usage_path->link)){	
-		item = list_get_instance(usage_path->link.prev, usb_hid_report_usage_path_t, link);
-		memset(item, 0, sizeof(usb_hid_report_usage_path_t));
-	}
-}
-
-/**
- *
- */
-void usb_hid_report_set_last_item(usb_hid_report_path_t *usage_path, int32_t tag, int32_t data)
-{
-	usb_hid_report_usage_path_t *item;
-	
-	if(!list_empty(&usage_path->link)){	
-		item = list_get_instance(usage_path->link.prev, usb_hid_report_usage_path_t, link);
-
-		switch(tag) {
-			case USB_HID_TAG_CLASS_GLOBAL:
-				item->usage_page = data;
-				break;
-			case USB_HID_TAG_CLASS_LOCAL:
-				item->usage = data;
-				break;
-		}
-	}
-	
-}
-
-/**
- *
- */
-int usb_hid_report_compare_usage_path(usb_hid_report_path_t *report_path, 
-                                      usb_hid_report_path_t *path,
-                                      int flags)
-{
-	usb_hid_report_usage_path_t *report_item;
-	usb_hid_report_usage_path_t *path_item;
-
-	link_t *report_link;
-	link_t *path_link;
-
-	int only_page;
-
-	if(path->depth == 0){
-		return EOK;
-	}
-
-
-	if((only_page = flags & USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY) != 0){
-		flags -= USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY;
-	}
-	
-	switch(flags){
-		/* path must be completly identical */
-		case USB_HID_PATH_COMPARE_STRICT:
-				if(report_path->depth != path->depth){
-					return 1;
-				}
-
-				report_link = report_path->link.next;
-				path_link = path->link.next;
-			
-				while((report_link != &report_path->link) && (path_link != &path->link)) {
-					report_item = list_get_instance(report_link, usb_hid_report_usage_path_t, link);
-					path_item = list_get_instance(path_link, usb_hid_report_usage_path_t, link);		
-
-					if((report_item->usage_page != path_item->usage_page) || 
-					   ((only_page == 0) && (report_item->usage != path_item->usage))) {
-						   return 1;
-					} else {
-						report_link = report_link->next;
-						path_link = path_link->next;			
-					}
-			
-				}
-
-				if((report_link == &report_path->link) && (path_link == &path->link)) {
-					return EOK;
-				}
-				else {
-					return 1;
-				}						
-			break;
-
-		/* given path must be the end of the report one*/
-		case USB_HID_PATH_COMPARE_END:
-				report_link = report_path->link.prev;
-				path_link = path->link.prev;
-
-				if(list_empty(&path->link)){
-					return EOK;
-				}
-			
-				while((report_link != &report_path->link) && (path_link != &path->link)) {
-					report_item = list_get_instance(report_link, usb_hid_report_usage_path_t, link);
-					path_item = list_get_instance(path_link, usb_hid_report_usage_path_t, link);		
-
-					if((report_item->usage_page != path_item->usage_page) || 
-					   ((only_page == 0) && (report_item->usage != path_item->usage))) {
-						   return 1;
-					} else {
-						report_link = report_link->prev;
-						path_link = path_link->prev;			
-					}
-			
-				}
-
-				if(path_link == &path->link) {
-					return EOK;
-				}
-				else {
-					return 1;
-				}						
-			
-			break;
-
-		default:
-			return EINVAL;
-	}
-	
-	
-	
-	
-}
-
-/**
- *
- */
-usb_hid_report_path_t *usb_hid_report_path(void)
-{
-	usb_hid_report_path_t *path;
-	path = malloc(sizeof(usb_hid_report_path_t));
-	if(!path){
-		return NULL;
-	}
-	else {
-		path->depth = 0;
-		list_initialize(&path->link);
-		return path;
-	}
-}
-
-/**
- *
- */
-void usb_hid_report_path_free(usb_hid_report_path_t *path)
-{
-	while(!list_empty(&path->link)){
-		usb_hid_report_remove_last_item(path);
-	}
-}
-
-
-/**
- *
- */
-int	usb_hid_report_path_clone(usb_hid_report_path_t *new_usage_path, usb_hid_report_path_t *usage_path)
-{
-	usb_hid_report_usage_path_t *path_item;
-	link_t *path_link;
-
-	
-	if(list_empty(&usage_path->link)){
-		return EOK;
-	}
-
-	path_link = usage_path->link.next;
-	while(path_link != &usage_path->link) {
-		path_item = list_get_instance(path_link, usb_hid_report_usage_path_t, link);
-		usb_hid_report_path_append_item (new_usage_path, path_item->usage_page, path_item->usage);
-
-		path_link = path_link->next;
-	}
-
-	return EOK;
-}
-
 
 /**
Index: pace/lib/usb/src/hidreport.c
===================================================================
--- uspace/lib/usb/src/hidreport.c	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ 	(revision )
@@ -1,228 +1,0 @@
-/*
- * Copyright (c) 2011 Lubos Slovak
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - 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.
- * - 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 ``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 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.
- */
-
-/** @addtogroup libusb
- * @{
- */
-/**
- * @file
- * USB HID keyboard device structure and API.
- */
-
-#include <assert.h>
-#include <errno.h>
-#include <str_error.h>
-
-#include <usb/debug.h>
-#include <usb/classes/hidparser.h>
-#include <usb/dp.h>
-#include <usb/devdrv.h>
-#include <usb/pipes.h>
-#include <usb/classes/hid.h>
-#include <usb/descriptor.h>
-#include <usb/request.h>
-
-#include <usb/classes/hidreport.h>
-
-static int usb_hid_get_report_descriptor(usb_device_t *dev, 
-    uint8_t **report_desc, size_t *size)
-{
-	assert(report_desc != NULL);
-	assert(size != NULL);
-	
-	usb_dp_parser_t parser =  {
-		.nesting = usb_dp_standard_descriptor_nesting
-	};
-	
-	usb_dp_parser_data_t parser_data = {
-		.data = dev->descriptors.configuration,
-		.size = dev->descriptors.configuration_size,
-		.arg = NULL
-	};
-	
-	/*
-	 * First nested descriptor of the configuration descriptor.
-	 */
-	uint8_t *d = 
-	    usb_dp_get_nested_descriptor(&parser, &parser_data, 
-	    dev->descriptors.configuration);
-	
-	/*
-	 * Find the interface descriptor corresponding to our interface number.
-	 */
-	int i = 0;
-	while (d != NULL && i < dev->interface_no) {
-		d = usb_dp_get_sibling_descriptor(&parser, &parser_data, 
-		    dev->descriptors.configuration, d);
-	}
-	
-	if (d == NULL) {
-		usb_log_error("The %d. interface descriptor not found!\n",
-		    dev->interface_no);
-		return ENOENT;
-	}
-	
-	/*
-	 * First nested descriptor of the interface descriptor.
-	 */
-	uint8_t *iface_desc = d;
-	d = usb_dp_get_nested_descriptor(&parser, &parser_data, iface_desc);
-	
-	/*
-	 * Search through siblings until the HID descriptor is found.
-	 */
-	while (d != NULL && *(d + 1) != USB_DESCTYPE_HID) {
-		d = usb_dp_get_sibling_descriptor(&parser, &parser_data, 
-		    iface_desc, d);
-	}
-	
-	if (d == NULL) {
-		usb_log_fatal("No HID descriptor found!\n");
-		return ENOENT;
-	}
-	
-	if (*d != sizeof(usb_standard_hid_descriptor_t)) {
-		usb_log_error("HID descriptor hass wrong size (%u, expected %u"
-		    ")\n", *d, sizeof(usb_standard_hid_descriptor_t));
-		return EINVAL;
-	}
-	
-	usb_standard_hid_descriptor_t *hid_desc = 
-	    (usb_standard_hid_descriptor_t *)d;
-	
-	uint16_t length =  hid_desc->report_desc_info.length;
-	size_t actual_size = 0;
-	
-	/*
-	 * Start session for the control transfer.
-	 */
-	int sess_rc = usb_pipe_start_session(&dev->ctrl_pipe);
-	if (sess_rc != EOK) {
-		usb_log_warning("Failed to start a session: %s.\n",
-		    str_error(sess_rc));
-		return sess_rc;
-	}
-
-	/*
-	 * Allocate space for the report descriptor.
-	 */
-	*report_desc = (uint8_t *)malloc(length);
-	if (*report_desc == NULL) {
-		usb_log_error("Failed to allocate space for Report descriptor."
-		    "\n");
-		return ENOMEM;
-	}
-	
-	usb_log_debug("Getting Report descriptor, expected size: %u\n", length);
-	
-	/*
-	 * Get the descriptor from the device.
-	 */
-	int rc = usb_request_get_descriptor(&dev->ctrl_pipe,
-	    USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_INTERFACE,
-	    USB_DESCTYPE_HID_REPORT, 0, dev->interface_no,
-	    *report_desc, length, &actual_size);
-
-	if (rc != EOK) {
-		free(*report_desc);
-		*report_desc = NULL;
-		return rc;
-	}
-
-	if (actual_size != length) {
-		free(*report_desc);
-		*report_desc = NULL;
-		usb_log_error("Report descriptor has wrong size (%u, expected "
-		    "%u)\n", actual_size, length);
-		return EINVAL;
-	}
-	
-	/*
-	 * End session for the control transfer.
-	 */
-	sess_rc = usb_pipe_end_session(&dev->ctrl_pipe);
-	if (sess_rc != EOK) {
-		usb_log_warning("Failed to end a session: %s.\n",
-		    str_error(sess_rc));
-		free(*report_desc);
-		*report_desc = NULL;
-		return sess_rc;
-	}
-	
-	*size = length;
-	
-	usb_log_debug("Done.\n");
-	
-	return EOK;
-}
-
-/*----------------------------------------------------------------------------*/
-
-int usb_hid_process_report_descriptor(usb_device_t *dev, 
-    usb_hid_report_parser_t *parser)
-{
-	if (dev == NULL || parser == NULL) {
-		usb_log_error("Failed to process Report descriptor: wrong "
-		    "parameters given.\n");
-		return EINVAL;
-	}
-	
-	uint8_t *report_desc = NULL;
-	size_t report_size;
-	
-	int rc = usb_hid_get_report_descriptor(dev, &report_desc, 
-	    &report_size);
-	
-	if (rc != EOK) {
-		usb_log_error("Problem with getting Report descriptor: %s.\n",
-		    str_error(rc));
-		if (report_desc != NULL) {
-			free(report_desc);
-		}
-		return rc;
-	}
-	
-	assert(report_desc != NULL);
-	
-	rc = usb_hid_parse_report_descriptor(parser, report_desc, report_size);
-	if (rc != EOK) {
-		usb_log_error("Problem parsing Report descriptor: %s.\n",
-		    str_error(rc));
-		free(report_desc);
-		return rc;
-	}
-	
-	usb_hid_descriptor_print(parser);
-	free(report_desc);
-	
-	return EOK;
-}
-
-/**
- * @}
- */
Index: pace/lib/usb/src/hidreq.c
===================================================================
--- uspace/lib/usb/src/hidreq.c	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ 	(revision )
@@ -1,479 +1,0 @@
-/*
- * Copyright (c) 2011 Lubos Slovak
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - 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.
- * - 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 ``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 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.
- */
-
-/** @addtogroup drvusbhid
- * @{
- */
-/** @file
- * HID class-specific requests.
- */
-
-#include <stdint.h>
-#include <errno.h>
-#include <str_error.h>
-
-#include <usb/classes/hid.h>
-#include <usb/debug.h>
-#include <usb/request.h>
-#include <usb/pipes.h>
-
-#include <usb/classes/hidreq.h>
-
-/*----------------------------------------------------------------------------*/
-/**
- * Send Set Report request to the HID device.
- *
- * @param hid_dev HID device to send the request to.
- * @param type Type of the report.
- * @param buffer Report data.
- * @param buf_size Report data size (in bytes).
- *
- * @retval EOK if successful.
- * @retval EINVAL if no HID device is given.
- * @return Other value inherited from one of functions 
- *         usb_pipe_start_session(), usb_pipe_end_session(),
- *         usb_control_request_set().
- */
-int usbhid_req_set_report(usb_pipe_t *ctrl_pipe, int iface_no,
-    usb_hid_report_type_t type, uint8_t *buffer, size_t buf_size)
-{
-	if (ctrl_pipe == NULL) {
-		usb_log_warning("usbhid_req_set_report(): no pipe given.\n");
-		return EINVAL;
-	}
-	
-	if (iface_no < 0) {
-		usb_log_warning("usbhid_req_set_report(): no interface given."
-		    "\n");
-		return EINVAL;
-	}
-	
-	/*
-	 * No need for checking other parameters, as they are checked in
-	 * the called function (usb_control_request_set()).
-	 */
-	
-	int rc, sess_rc;
-	
-	sess_rc = usb_pipe_start_session(ctrl_pipe);
-	if (sess_rc != EOK) {
-		usb_log_warning("Failed to start a session: %s.\n",
-		    str_error(sess_rc));
-		return sess_rc;
-	}
-	
-	uint16_t value = 0;
-	value |= (type << 8);
-
-	usb_log_debug("Sending Set_Report request to the device.\n");
-	
-	rc = usb_control_request_set(ctrl_pipe, 
-	    USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE, 
-	    USB_HIDREQ_SET_REPORT, value, iface_no, buffer, buf_size);
-
-	sess_rc = usb_pipe_end_session(ctrl_pipe);
-
-	if (rc != EOK) {
-		usb_log_warning("Error sending output report to the keyboard: "
-		    "%s.\n", str_error(rc));
-		return rc;
-	}
-
-	if (sess_rc != EOK) {
-		usb_log_warning("Error closing session: %s.\n",
-		    str_error(sess_rc));
-		return sess_rc;
-	}
-	
-	return EOK;
-}
-
-/*----------------------------------------------------------------------------*/
-/**
- * Send Set Protocol request to the HID device.
- *
- * @param hid_dev HID device to send the request to.
- * @param protocol Protocol to set.
- *
- * @retval EOK if successful.
- * @retval EINVAL if no HID device is given.
- * @return Other value inherited from one of functions 
- *         usb_pipe_start_session(), usb_pipe_end_session(),
- *         usb_control_request_set().
- */
-int usbhid_req_set_protocol(usb_pipe_t *ctrl_pipe, int iface_no,
-    usb_hid_protocol_t protocol)
-{
-	if (ctrl_pipe == NULL) {
-		usb_log_warning("usbhid_req_set_report(): no pipe given.\n");
-		return EINVAL;
-	}
-	
-	if (iface_no < 0) {
-		usb_log_warning("usbhid_req_set_report(): no interface given."
-		    "\n");
-		return EINVAL;
-	}
-	
-	/*
-	 * No need for checking other parameters, as they are checked in
-	 * the called function (usb_control_request_set()).
-	 */
-	
-	int rc, sess_rc;
-	
-	sess_rc = usb_pipe_start_session(ctrl_pipe);
-	if (sess_rc != EOK) {
-		usb_log_warning("Failed to start a session: %s.\n",
-		    str_error(sess_rc));
-		return sess_rc;
-	}
-
-	usb_log_debug("Sending Set_Protocol request to the device ("
-	    "protocol: %d, iface: %d).\n", protocol, iface_no);
-	
-	rc = usb_control_request_set(ctrl_pipe, 
-	    USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE, 
-	    USB_HIDREQ_SET_PROTOCOL, protocol, iface_no, NULL, 0);
-
-	sess_rc = usb_pipe_end_session(ctrl_pipe);
-
-	if (rc != EOK) {
-		usb_log_warning("Error sending output report to the keyboard: "
-		    "%s.\n", str_error(rc));
-		return rc;
-	}
-
-	if (sess_rc != EOK) {
-		usb_log_warning("Error closing session: %s.\n",
-		    str_error(sess_rc));
-		return sess_rc;
-	}
-	
-	return EOK;
-}
-
-/*----------------------------------------------------------------------------*/
-/**
- * Send Set Idle request to the HID device.
- *
- * @param hid_dev HID device to send the request to.
- * @param duration Duration value (is multiplicated by 4 by the device to
- *                 get real duration in miliseconds).
- *
- * @retval EOK if successful.
- * @retval EINVAL if no HID device is given.
- * @return Other value inherited from one of functions 
- *         usb_pipe_start_session(), usb_pipe_end_session(),
- *         usb_control_request_set().
- */
-int usbhid_req_set_idle(usb_pipe_t *ctrl_pipe, int iface_no, uint8_t duration)
-{
-	if (ctrl_pipe == NULL) {
-		usb_log_warning("usbhid_req_set_report(): no pipe given.\n");
-		return EINVAL;
-	}
-	
-	if (iface_no < 0) {
-		usb_log_warning("usbhid_req_set_report(): no interface given."
-		    "\n");
-		return EINVAL;
-	}
-	
-	/*
-	 * No need for checking other parameters, as they are checked in
-	 * the called function (usb_control_request_set()).
-	 */
-	
-	int rc, sess_rc;
-	
-	sess_rc = usb_pipe_start_session(ctrl_pipe);
-	if (sess_rc != EOK) {
-		usb_log_warning("Failed to start a session: %s.\n",
-		    str_error(sess_rc));
-		return sess_rc;
-	}
-
-	usb_log_debug("Sending Set_Idle request to the device ("
-	    "duration: %u, iface: %d).\n", duration, iface_no);
-	
-	uint16_t value = duration << 8;
-	
-	rc = usb_control_request_set(ctrl_pipe, 
-	    USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE, 
-	    USB_HIDREQ_SET_IDLE, value, iface_no, NULL, 0);
-
-	sess_rc = usb_pipe_end_session(ctrl_pipe);
-
-	if (rc != EOK) {
-		usb_log_warning("Error sending output report to the keyboard: "
-		    "%s.\n", str_error(rc));
-		return rc;
-	}
-
-	if (sess_rc != EOK) {
-		usb_log_warning("Error closing session: %s.\n",
-		    str_error(sess_rc));
-		return sess_rc;
-	}
-	
-	return EOK;
-}
-
-/*----------------------------------------------------------------------------*/
-/**
- * Send Get Report request to the HID device.
- *
- * @param[in] hid_dev HID device to send the request to.
- * @param[in] type Type of the report.
- * @param[in][out] buffer Buffer for the report data.
- * @param[in] buf_size Size of the buffer (in bytes).
- * @param[out] actual_size Actual size of report received from the device 
- *                         (in bytes).
- *
- * @retval EOK if successful.
- * @retval EINVAL if no HID device is given.
- * @return Other value inherited from one of functions 
- *         usb_pipe_start_session(), usb_pipe_end_session(),
- *         usb_control_request_set().
- */
-int usbhid_req_get_report(usb_pipe_t *ctrl_pipe, int iface_no, 
-    usb_hid_report_type_t type, uint8_t *buffer, size_t buf_size, 
-    size_t *actual_size)
-{
-	if (ctrl_pipe == NULL) {
-		usb_log_warning("usbhid_req_set_report(): no pipe given.\n");
-		return EINVAL;
-	}
-	
-	if (iface_no < 0) {
-		usb_log_warning("usbhid_req_set_report(): no interface given."
-		    "\n");
-		return EINVAL;
-	}
-	
-	/*
-	 * No need for checking other parameters, as they are checked in
-	 * the called function (usb_control_request_set()).
-	 */
-	
-	int rc, sess_rc;
-	
-	sess_rc = usb_pipe_start_session(ctrl_pipe);
-	if (sess_rc != EOK) {
-		usb_log_warning("Failed to start a session: %s.\n",
-		    str_error(sess_rc));
-		return sess_rc;
-	}
-
-	uint16_t value = 0;
-	value |= (type << 8);
-	
-	usb_log_debug("Sending Get_Report request to the device.\n");
-	
-	rc = usb_control_request_get(ctrl_pipe, 
-	    USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE, 
-	    USB_HIDREQ_GET_REPORT, value, iface_no, buffer, buf_size,
-	    actual_size);
-
-	sess_rc = usb_pipe_end_session(ctrl_pipe);
-
-	if (rc != EOK) {
-		usb_log_warning("Error sending output report to the keyboard: "
-		    "%s.\n", str_error(rc));
-		return rc;
-	}
-
-	if (sess_rc != EOK) {
-		usb_log_warning("Error closing session: %s.\n",
-		    str_error(sess_rc));
-		return sess_rc;
-	}
-	
-	return EOK;
-}
-
-/*----------------------------------------------------------------------------*/
-/**
- * Send Get Protocol request to the HID device.
- *
- * @param[in] hid_dev HID device to send the request to.
- * @param[out] protocol Current protocol of the device.
- *
- * @retval EOK if successful.
- * @retval EINVAL if no HID device is given.
- * @return Other value inherited from one of functions 
- *         usb_pipe_start_session(), usb_pipe_end_session(),
- *         usb_control_request_set().
- */
-int usbhid_req_get_protocol(usb_pipe_t *ctrl_pipe, int iface_no, 
-    usb_hid_protocol_t *protocol)
-{
-	if (ctrl_pipe == NULL) {
-		usb_log_warning("usbhid_req_set_report(): no pipe given.\n");
-		return EINVAL;
-	}
-	
-	if (iface_no < 0) {
-		usb_log_warning("usbhid_req_set_report(): no interface given."
-		    "\n");
-		return EINVAL;
-	}
-	
-	/*
-	 * No need for checking other parameters, as they are checked in
-	 * the called function (usb_control_request_set()).
-	 */
-	
-	int rc, sess_rc;
-	
-	sess_rc = usb_pipe_start_session(ctrl_pipe);
-	if (sess_rc != EOK) {
-		usb_log_warning("Failed to start a session: %s.\n",
-		    str_error(sess_rc));
-		return sess_rc;
-	}
-
-	usb_log_debug("Sending Get_Protocol request to the device ("
-	    "iface: %d).\n", iface_no);
-	
-	uint8_t buffer[1];
-	size_t actual_size = 0;
-	
-	rc = usb_control_request_get(ctrl_pipe, 
-	    USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE, 
-	    USB_HIDREQ_GET_PROTOCOL, 0, iface_no, buffer, 1, &actual_size);
-
-	sess_rc = usb_pipe_end_session(ctrl_pipe);
-
-	if (rc != EOK) {
-		usb_log_warning("Error sending output report to the keyboard: "
-		    "%s.\n", str_error(rc));
-		return rc;
-	}
-
-	if (sess_rc != EOK) {
-		usb_log_warning("Error closing session: %s.\n",
-		    str_error(sess_rc));
-		return sess_rc;
-	}
-	
-	if (actual_size != 1) {
-		usb_log_warning("Wrong data size: %zu, expected: 1.\n",
-			actual_size);
-		return ELIMIT;
-	}
-	
-	*protocol = buffer[0];
-	
-	return EOK;
-}
-
-/*----------------------------------------------------------------------------*/
-/**
- * Send Get Idle request to the HID device.
- *
- * @param[in] hid_dev HID device to send the request to.
- * @param[out] duration Duration value (multiplicate by 4 to get real duration
- *                      in miliseconds).
- *
- * @retval EOK if successful.
- * @retval EINVAL if no HID device is given.
- * @return Other value inherited from one of functions 
- *         usb_pipe_start_session(), usb_pipe_end_session(),
- *         usb_control_request_set().
- */
-int usbhid_req_get_idle(usb_pipe_t *ctrl_pipe, int iface_no, uint8_t *duration)
-{
-	if (ctrl_pipe == NULL) {
-		usb_log_warning("usbhid_req_set_report(): no pipe given.\n");
-		return EINVAL;
-	}
-	
-	if (iface_no < 0) {
-		usb_log_warning("usbhid_req_set_report(): no interface given."
-		    "\n");
-		return EINVAL;
-	}
-	
-	/*
-	 * No need for checking other parameters, as they are checked in
-	 * the called function (usb_control_request_set()).
-	 */
-	
-	int rc, sess_rc;
-	
-	sess_rc = usb_pipe_start_session(ctrl_pipe);
-	if (sess_rc != EOK) {
-		usb_log_warning("Failed to start a session: %s.\n",
-		    str_error(sess_rc));
-		return sess_rc;
-	}
-
-	usb_log_debug("Sending Get_Idle request to the device ("
-	    "iface: %d).\n", iface_no);
-	
-	uint16_t value = 0;
-	uint8_t buffer[1];
-	size_t actual_size = 0;
-	
-	rc = usb_control_request_get(ctrl_pipe, 
-	    USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE, 
-	    USB_HIDREQ_GET_IDLE, value, iface_no, buffer, 1, 
-	    &actual_size);
-
-	sess_rc = usb_pipe_end_session(ctrl_pipe);
-
-	if (rc != EOK) {
-		usb_log_warning("Error sending output report to the keyboard: "
-		    "%s.\n", str_error(rc));
-		return rc;
-	}
-
-	if (sess_rc != EOK) {
-		usb_log_warning("Error closing session: %s.\n",
-		    str_error(sess_rc));
-		return sess_rc;
-	}
-	
-	if (actual_size != 1) {
-		usb_log_warning("Wrong data size: %zu, expected: 1.\n",
-			actual_size);
-		return ELIMIT;
-	}
-	
-	*duration = buffer[0];
-	
-	return EOK;
-}
-
-/*----------------------------------------------------------------------------*/
-
-/**
- * @}
- */
Index: uspace/lib/usb/src/host/device_keeper.c
===================================================================
--- uspace/lib/usb/src/host/device_keeper.c	(revision 291b8bc66a941bac60fdea3ad481eb7b27bfcf40)
+++ uspace/lib/usb/src/host/device_keeper.c	(revision 889e8e3c68f741489743165141ddb4ccfad90112)
@@ -49,10 +49,9 @@
 	assert(instance);
 	fibril_mutex_initialize(&instance->guard);
-	fibril_condvar_initialize(&instance->change);
+	fibril_condvar_initialize(&instance->default_address_occupied);
 	instance->last_address = 0;
 	unsigned i = 0;
 	for (; i < USB_ADDRESS_COUNT; ++i) {
 		instance->devices[i].occupied = false;
-		instance->devices[i].control_used = false;
 		instance->devices[i].handle = 0;
 		instance->devices[i].toggle_status[0] = 0;
@@ -72,5 +71,6 @@
 	fibril_mutex_lock(&instance->guard);
 	while (instance->devices[USB_ADDRESS_DEFAULT].occupied) {
-		fibril_condvar_wait(&instance->change, &instance->guard);
+		fibril_condvar_wait(&instance->default_address_occupied,
+		    &instance->guard);
 	}
 	instance->devices[USB_ADDRESS_DEFAULT].occupied = true;
@@ -90,5 +90,5 @@
 	instance->devices[USB_ADDRESS_DEFAULT].occupied = false;
 	fibril_mutex_unlock(&instance->guard);
-	fibril_condvar_signal(&instance->change);
+	fibril_condvar_signal(&instance->default_address_occupied);
 }
 /*----------------------------------------------------------------------------*/
@@ -309,26 +309,5 @@
 	return instance->devices[address].speed;
 }
-/*----------------------------------------------------------------------------*/
-void usb_device_keeper_use_control(usb_device_keeper_t *instance,
-    usb_address_t address)
-{
-	assert(instance);
-	fibril_mutex_lock(&instance->guard);
-	while (instance->devices[address].control_used) {
-		fibril_condvar_wait(&instance->change, &instance->guard);
-	}
-	instance->devices[address].control_used = true;
-	fibril_mutex_unlock(&instance->guard);
-}
-/*----------------------------------------------------------------------------*/
-void usb_device_keeper_release_control(usb_device_keeper_t *instance,
-    usb_address_t address)
-{
-	assert(instance);
-	fibril_mutex_lock(&instance->guard);
-	instance->devices[address].control_used = false;
-	fibril_mutex_unlock(&instance->guard);
-	fibril_condvar_signal(&instance->change);
-}
+
 /**
  * @}
