Index: uspace/drv/uhci-hcd/main.c
===================================================================
--- uspace/drv/uhci-hcd/main.c	(revision 885069012a36b1cdd184fc3a4444dfc7413023f0)
+++ uspace/drv/uhci-hcd/main.c	(revision 92b41f33ef178e2599a8d9390319bbd337092103)
@@ -33,17 +33,12 @@
  */
 #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 "iface.h"
-#include "pci.h"
-#include "uhci_hc.h"
-#include "uhci_rh.h"
+#include "uhci.h"
 
 #define NAME "uhci-hcd"
@@ -60,20 +55,5 @@
 };
 /*----------------------------------------------------------------------------*/
-/** IRQ handling callback, identifies devic
- *
- * @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);
-	uhci_hc_t *hc = dev_to_uhci(dev);
-	uint16_t status = IPC_GET_ARG1(*call);
-	assert(hc);
-	uhci_interrupt(hc, status);
-}
-/*----------------------------------------------------------------------------*/
-/** Initializes a new ddf driver instance of UHCI hcd.
+/** Initializes a new ddf driver instance for uhci hc and hub.
  *
  * @param[in] device DDF instance of the device to initialize.
@@ -85,85 +65,19 @@
 int uhci_add_device(ddf_dev_t *device)
 {
+	usb_log_info("uhci_add_device() called\n");
 	assert(device);
-	uhci_hc_t *hcd = NULL;
-#define CHECK_RET_FREE_HC_RETURN(ret, message...) \
-if (ret != EOK) { \
-	usb_log_error(message); \
-	if (hcd != NULL) \
-		free(hcd); \
-	return ret; \
-}
+	uhci_t *uhci = malloc(sizeof(uhci_t));
+	if (uhci == NULL) {
+		usb_log_error("Failed to allocate UHCI driver.\n");
+		return ENOMEM;
+	}
 
-	usb_log_info("uhci_add_device() called\n");
-
-	uintptr_t io_reg_base = 0;
-	size_t io_reg_size = 0;
-	int irq = 0;
-
-	int ret =
-	    pci_get_my_registers(device, &io_reg_base, &io_reg_size, &irq);
-	CHECK_RET_FREE_HC_RETURN(ret,
-	    "Failed(%d) to get I/O addresses:.\n", ret, device->handle);
-	usb_log_info("I/O regs at 0x%X (size %zu), IRQ %d.\n",
-	    io_reg_base, io_reg_size, irq);
-
-	ret = pci_disable_legacy(device);
-	CHECK_RET_FREE_HC_RETURN(ret,
-	    "Failed(%d) to disable legacy USB: %s.\n", ret, str_error(ret));
-
-#if 0
-	ret = pci_enable_interrupts(device);
+	int ret = uhci_init(uhci, device);
 	if (ret != EOK) {
-		usb_log_warning(
-		    "Failed(%d) to enable interrupts, fall back to polling.\n",
-		    ret);
+		usb_log_error("Failed to initialzie UHCI driver.\n");
+		return ret;
 	}
-#endif
-
-	hcd = malloc(sizeof(uhci_hc_t));
-	ret = (hcd != NULL) ? EOK : ENOMEM;
-	CHECK_RET_FREE_HC_RETURN(ret,
-	    "Failed(%d) to allocate memory for uhci hcd.\n", ret);
-
-	ret = uhci_init(hcd, device, (void*)io_reg_base, io_reg_size);
-	CHECK_RET_FREE_HC_RETURN(ret, "Failed(%d) to init uhci-hcd.\n", ret);
-#undef CHECK_RET_FREE_HC_RETURN
-
-	/*
-	 * We might free hcd, but that does not matter since no one
-	 * else would access driver_data anyway.
-	 */
-	device->driver_data = hcd;
-
-	ddf_fun_t *rh = NULL;
-#define CHECK_RET_FINI_FREE_RETURN(ret, message...) \
-if (ret != EOK) { \
-	usb_log_error(message); \
-	if (hcd != NULL) {\
-		uhci_fini(hcd); \
-		free(hcd); \
-	} \
-	if (rh != NULL) \
-		free(rh); \
-	return ret; \
-}
-
-	/* It does no harm if we register this on polling */
-	ret = register_interrupt_handler(device, irq, irq_handler,
-	    &hcd->interrupt_code);
-	CHECK_RET_FINI_FREE_RETURN(ret,
-	    "Failed(%d) to register interrupt handler.\n", ret);
-
-	ret = setup_root_hub(&rh, device);
-	CHECK_RET_FINI_FREE_RETURN(ret,
-	    "Failed(%d) to setup UHCI root hub.\n", ret);
-	rh->driver_data = hcd->ddf_instance;
-
-	ret = ddf_fun_bind(rh);
-	CHECK_RET_FINI_FREE_RETURN(ret,
-	    "Failed(%d) to register UHCI root hub.\n", ret);
-
+	device->driver_data = uhci;
 	return EOK;
-#undef CHECK_RET_FINI_FREE_RETURN
 }
 /*----------------------------------------------------------------------------*/
