Index: uspace/drv/uhci/debug.h
===================================================================
--- uspace/drv/uhci/debug.h	(revision bf5a3be3f91be8c93abd675e1ef6d32a4852ba39)
+++ uspace/drv/uhci/debug.h	(revision bf5a3be3f91be8c93abd675e1ef6d32a4852ba39)
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2010 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_DEBUG_H
+#define DRV_UHCI_DEBUG_H
+
+#include <usb/debug.h>
+
+#include "name.h"
+
+enum debug_levels {
+	DEBUG_LEVEL_FATAL_ERROR = 1,
+	DEBUG_LEVEL_CRITICAL_ERROR = 2,
+	DEBUG_LEVEL_ERROR = 3,
+	DEBUG_LEVEL_WARNING = 4,
+	DEBUG_LEVEL_INFO = 5
+};
+
+#define uhci_printf( level, fmt, args...) \
+	usb_dprintf( NAME, level, fmt, ##args )
+
+#define uhci_print_error( fmt, args... ) \
+	usb_dprintf( NAME, DEBUG_LEVEL_ERROR, fmt, ##args )
+
+#define uhci_print_info( fmt, args... ) \
+	usb_dprintf( NAME, DEBUG_LEVEL_INFO, fmt, ##args )
+
+#endif
+/**
+ * @}
+ */
Index: uspace/drv/uhci/main.c
===================================================================
--- uspace/drv/uhci/main.c	(revision f088c00baff82dafff909fe1a103cbfe3ce2acdb)
+++ uspace/drv/uhci/main.c	(revision bf5a3be3f91be8c93abd675e1ef6d32a4852ba39)
@@ -27,7 +27,7 @@
  */
 #include <usb/hcdhubd.h>
-#include <usb/debug.h>
 #include <errno.h>
 
+#include "debug.h"
 #include "iface.h"
 #include "name.h"
@@ -41,14 +41,9 @@
 static int uhci_add_device(device_t *device)
 {
-	usb_dprintf(NAME, 1, "uhci_add_device() called\n");
+//	usb_dprintf(NAME, DEBUG, "uhci_add_device() called\n");
+	uhci_print_info( "uhci_add_device() called\n" );
 	device->ops = &uhci_ops;
 
 	uhci_init( device, (void*)0xc020 );
-
-	/*
-	 * We need to announce the presence of our root hub.
-	 */
-//	usb_dprintf(NAME, 2, "adding root hub\n");
-//	usb_hcd_add_root_hub(device);
 
 	return EOK;
@@ -69,6 +64,6 @@
 	 * Do some global initializations.
 	 */
-	sleep( 5);
-	usb_dprintf_enable(NAME, 5);
+	sleep( 5 );
+	usb_dprintf_enable(NAME, DEBUG_LEVEL_INFO);
 
 	return driver_main(&uhci_driver);
Index: uspace/drv/uhci/root_hub/root_hub.c
===================================================================
--- uspace/drv/uhci/root_hub/root_hub.c	(revision f088c00baff82dafff909fe1a103cbfe3ce2acdb)
+++ uspace/drv/uhci/root_hub/root_hub.c	(revision bf5a3be3f91be8c93abd675e1ef6d32a4852ba39)
@@ -1,3 +1,5 @@
+#include <bool.h>
 #include <ddi.h>
+#include <devman.h>
 #include <async.h>
 #include <errno.h>
@@ -5,12 +7,16 @@
 #include <stdio.h>
 
-#include <usb/debug.h>
-
 #include "../name.h"
 #include "../uhci.h"
+#include "../debug.h"
 #include "port_status.h"
 #include "root_hub.h"
 
 #define ROOT_HUB_WAIT_USEC 10000000 /* 10 second */
+
+struct usb_match {
+	int id_score;
+	const char *id_string;
+};
 
 static int uhci_root_hub_check_ports( void *hc );
@@ -19,4 +25,6 @@
 static int uhci_root_hub_report_new_device(
   device_t *hc, usb_address_t address, int port, devman_handle_t *handle );
+static int uhci_root_hub_port_set_enabled(
+  uhci_root_hub_t *instance, unsigned port, bool enabled );
 
 /*----------------------------------------------------------------------------*/
@@ -29,5 +37,6 @@
 	const int ret = pio_enable( addr, sizeof(port_regs_t), (void**)&regs);
 	if (ret < 0) {
-		printf( NAME": Failed to gain access to port registers at %p\n", regs );
+		uhci_print_error(
+		  ": Failed to gain access to port registers at %p\n", regs );
 		return ret;
 	}
@@ -37,5 +46,5 @@
 	hub->checker = fibril_create( uhci_root_hub_check_ports, hc );
 	if (hub->checker == 0) {
-		printf( NAME": failed to launch root hub fibril." );
+		uhci_print_error( ": failed to launch root hub fibril." );
 		return ENOMEM;
 	}
@@ -51,4 +60,27 @@
 	//destroy fibril here
 	//disable access to registers
+	return EOK;
+}
+/*----------------------------------------------------------------------------*/
+static int uhci_root_hub_port_set_enabled( uhci_root_hub_t *instance,
+  unsigned port, bool enabled )
+{
+	assert( instance );
+	assert( instance->registers );
+	assert( port < UHCI_ROOT_HUB_PORT_COUNT );
+
+	volatile uint16_t * address =
+		&(instance->registers->portsc[port]);
+
+	/* read register value */
+	port_status_t port_status;
+	port_status.raw_value = pio_read_16( address );
+
+	/* enable port: register write */
+	port_status.status.enabled_change = 0;
+	port_status.status.enabled = (bool)enabled;
+	pio_write_16( address, port_status.raw_value );
+
+	uhci_print_info( "Enabled port %d.\n", port );
 	return EOK;
 }
@@ -65,5 +97,5 @@
 				&(uhci_instance->root_hub.registers->portsc[i]);
 
-			usb_dprintf( NAME, 1, "Port(%d) status address %p:\n", i, address );
+			uhci_print_info( "Port(%d) status address %p:\n", i, address );
 
 			/* read register value */
@@ -72,5 +104,5 @@
 
 			/* debug print */
-			usb_dprintf( NAME, 1, "Port(%d) status 0x%x:\n", i, port_status.raw_value );
+			uhci_print_info( "Port(%d) status %#x:\n", i, port_status.raw_value );
 			print_port_status( &port_status );
 
@@ -96,5 +128,5 @@
 	assert( port < UHCI_ROOT_HUB_PORT_COUNT );
 
-	usb_dprintf( NAME, 2, "Adding new device on port %d.\n", port );
+	uhci_print_info( "Adding new device on port %d.\n", port );
 
 	uhci_t *uhci_instance = (uhci_t*)hc->driver_data;
@@ -104,28 +136,17 @@
 
 	/* enable port */
-	{
-		volatile uint16_t * address =
-			&(uhci_instance->root_hub.registers->portsc[port]);
-
-		/* read register value */
-		port_status_t port_status;
-		port_status.raw_value = pio_read_16( address );
-
-		/* enable port: register write */
-		port_status.status.enabled = 1;
-		pio_write_16( address, port_status.raw_value );
-
-		usb_dprintf( NAME, 2, "Enabled port %d.\n", port );
-	}
+	uhci_root_hub_port_set_enabled( &uhci_instance->root_hub, port, true );
 
 	/* assign address to device */
-	usb_address_t address =
-	 uhci_root_hub_assign_address( hc );
-	if (address <= 0) {
-		printf( NAME": Failed to assign address to the device" );
-		return ENOMEM;
-	}
+	usb_address_t address = uhci_root_hub_assign_address( hc );
+
 	/* release default address */
 	usb_address_keeping_release_default( &uhci_instance->address_manager );
+
+	if (address <= 0) { /* address assigning went wrong */
+		uhci_root_hub_port_set_enabled( &uhci_instance->root_hub, port, false );
+		uhci_print_error( "Failed to assign address to the device" );
+		return ENOMEM;
+	}
 
 	/* report to devman */
@@ -148,10 +169,10 @@
 	uhci_t *uhci_instance = (uhci_t*)hc->driver_data;
 	/* get new address */
-	const usb_address_t usb_address = usb_address_keeping_request(
-	  &uhci_instance->address_manager );
+	const usb_address_t usb_address =
+	  usb_address_keeping_request( &uhci_instance->address_manager );
 
 	/* assign new address */
-	/* TODO send new address*/
-	usb_dprintf( NAME, 3, "Assigned address 0x%x.\n", usb_address );
+	/* TODO send new address to the device*/
+	uhci_print_error( "Assigned address %#x.\n", usb_address );
 
 	return usb_address;
@@ -165,13 +186,14 @@
 	assert( address <= USB11_ADDRESS_MAX );
 
-	int ret;
 	device_t *child = create_device();
 	if (child == NULL)
 		{ return ENOMEM; }
+
 	char *name;
-
-	ret = asprintf( &name, "usbdevice on hc%p/%d/0x%x", hc, hub_port, address );
+	int ret;
+
+	ret = asprintf( &name, "usbdevice on hc%p/%d/%#x", hc, hub_port, address );
 	if (ret < 0) {
-		usb_dprintf( NAME, 4, "Failed to create device name.\n" );
+		uhci_print_error( "Failed to create device name.\n" );
 		delete_device( child );
 		return ret;
@@ -179,9 +201,48 @@
 	child->name = name;
 
-	/* TODO create match ids */
+	/* TODO get and parse device descriptor */
+	const int vendor = 1;
+	const int product = 1;
+	const char* release = "unknown";
+	const char* class = "unknown";
+
+	/* create match ids TODO fix class printf*/
+	static const struct usb_match usb_matches[] = {
+	  { 100, "usb&vendor=%d&product=%d&release=%s" },
+	  {  90, "usb&vendor=%d&product=%d" },
+	  {  50, "usb&class=%d" },
+	  {   1, "usb&fallback" }
+	};
+
+	unsigned i = 0;
+	for (;i < sizeof( usb_matches )/ sizeof( struct usb_match ); ++i ) {
+		char *match_str;
+		const int ret = asprintf(
+		  &match_str, usb_matches[i].id_string, vendor, product, release, class );
+		if (ret < 0 ) {
+			uhci_print_error( "Failed to create matchid string.\n" );
+			delete_device( child );
+			return ret;
+		}
+		uhci_print_info( "Adding match id rule:%s\n", match_str );
+
+		match_id_t *id = create_match_id();
+		if (id == NULL) {
+			uhci_print_error( "Failed to create matchid.\n" );
+			delete_device( child );
+			free( match_str );
+			return ENOMEM;
+		}
+		id->id = match_str;
+		id->score = usb_matches[i].id_score;
+		add_match_id( &child->match_ids, id );
+
+		uhci_print_info( "Added match id, score: %d, string %s\n",
+		  id->score, id->id );
+	}
 
 	ret = child_device_register( child, hc );
 	if (ret < 0) {
-		usb_dprintf( NAME, 4, "Failed to create device name.\n" );
+		uhci_print_error( "Failed to create device name.\n" );
 		delete_device( child );
 		return ret;
Index: uspace/drv/uhci/uhci.c
===================================================================
--- uspace/drv/uhci/uhci.c	(revision f088c00baff82dafff909fe1a103cbfe3ce2acdb)
+++ uspace/drv/uhci/uhci.c	(revision bf5a3be3f91be8c93abd675e1ef6d32a4852ba39)
@@ -3,4 +3,5 @@
 #include <usb/usb.h>
 
+#include "debug.h"
 #include "name.h"
 #include "uhci.h"
@@ -10,5 +11,5 @@
 {
 	assert( device );
-	usb_dprintf(NAME, 1, "Initializing device at address %p\n", device);
+	uhci_print_info( "Initializing device at address %p\n", device);
 
 	/* create instance */
@@ -52,5 +53,5 @@
 	)
 {
-	usb_dprintf(NAME, 1, "transfer IN [%d.%d (%s); %zu]\n",
+	uhci_print_info( "transfer IN [%d.%d (%s); %zu]\n",
 	    target.address, target.endpoint,
 	    usb_str_transfer_type(transfer_type),
@@ -68,5 +69,5 @@
   )
 {
-	usb_dprintf(NAME, 1, "transfer OUT [%d.%d (%s); %zu]\n",
+	uhci_print_info( "transfer OUT [%d.%d (%s); %zu]\n",
 	    target.address, target.endpoint,
 	    usb_str_transfer_type(transfer_type),
@@ -84,5 +85,5 @@
   )
 {
-	usb_dprintf(NAME, 1, "transfer SETUP [%d.%d (%s); %zu]\n",
+	uhci_print_info( "transfer SETUP [%d.%d (%s); %zu]\n",
 	    target.address, target.endpoint,
 	    usb_str_transfer_type(transfer_type),
