Index: uspace/drv/uhci-hcd/uhci.c
===================================================================
--- uspace/drv/uhci-hcd/uhci.c	(revision 57c0a7eb5ef14b723abc35cb15fec827c026d345)
+++ uspace/drv/uhci-hcd/uhci.c	(revision a7e2f0dab29fadc4ae66c44ba1629b177fd6679d)
@@ -61,6 +61,13 @@
 };
 
-static int usb_iface_get_address(ddf_fun_t *fun, devman_handle_t handle,
-    usb_address_t *address)
+/** Gets USB address of the calling device.
+ *
+ * @param[in] fun UHCI hc function.
+ * @param[in] handle Handle of the device seeking address.
+ * @param[out] address Place to store found address.
+ * @return Error code.
+ */
+static int usb_iface_get_address(
+    ddf_fun_t *fun, devman_handle_t handle, usb_address_t *address)
 {
 	assert(fun);
@@ -99,7 +106,15 @@
 
 static bool allowed_usb_packet(
-	bool low_speed, usb_transfer_type_t, size_t size);
-
-
+    bool low_speed, usb_transfer_type_t transfer, size_t size);
+/*----------------------------------------------------------------------------*/
+/** Initializes UHCI hcd driver structure
+ *
+ * @param[in] instance Memory place to initialize.
+ * @param[in] dev DDF device.
+ * @param[in] regs Address of I/O control registers.
+ * @param[in] size Size of I/O control registers.
+ * @return Error code.
+ * @note Should be called only once on any structure.
+ */
 int uhci_init(uhci_t *instance, ddf_dev_t *dev, void *regs, size_t reg_size)
 {
@@ -156,33 +171,46 @@
 }
 /*----------------------------------------------------------------------------*/
+/** Initializes UHCI hcd hw resources.
+ *
+ * @param[in] instance UHCI structure to use.
+ */
 void uhci_init_hw(uhci_t *instance)
 {
 	assert(instance);
-
-	/* reset everything, who knows what touched it before us */
-	pio_write_16(&instance->registers->usbcmd, UHCI_CMD_GLOBAL_RESET);
+	regs_t *registers = instance->registers;
+
+	/* Reset everything, who knows what touched it before us */
+	pio_write_16(&registers->usbcmd, UHCI_CMD_GLOBAL_RESET);
 	async_usleep(10000); /* 10ms according to USB spec */
-	pio_write_16(&instance->registers->usbcmd, 0);
-
-	/* reset hc, all states and counters */
-	pio_write_16(&instance->registers->usbcmd, UHCI_CMD_HCRESET);
+	pio_write_16(&registers->usbcmd, 0);
+
+	/* Reset hc, all states and counters */
+	pio_write_16(&registers->usbcmd, UHCI_CMD_HCRESET);
 	do { async_usleep(10); }
-	while ((pio_read_16(&instance->registers->usbcmd) & UHCI_CMD_HCRESET) != 0);
-
-	/* set framelist pointer */
+	while ((pio_read_16(&registers->usbcmd) & UHCI_CMD_HCRESET) != 0);
+
+	/* Set framelist pointer */
 	const uint32_t pa = addr_to_phys(instance->frame_list);
-	pio_write_32(&instance->registers->flbaseadd, pa);
-
-	/* enable all interrupts, but resume interrupt */
+	pio_write_32(&registers->flbaseadd, pa);
+
+	/* Enable all interrupts, but resume interrupt */
 //	pio_write_16(&instance->registers->usbintr,
 //	    UHCI_INTR_CRC | UHCI_INTR_COMPLETE | UHCI_INTR_SHORT_PACKET);
 
-	uint16_t status = pio_read_16(&instance->registers->usbcmd);
-	usb_log_warning("Previous command value: %x.\n", status);
+	uint16_t status = pio_read_16(&registers->usbcmd);
+	if (status != 0)
+		usb_log_warning("Previous command value: %x.\n", status);
+
 	/* Start the hc with large(64B) packet FSBR */
-	pio_write_16(&instance->registers->usbcmd,
+	pio_write_16(&registers->usbcmd,
 	    UHCI_CMD_RUN_STOP | UHCI_CMD_MAX_PACKET | UHCI_CMD_CONFIGURE);
 }
 /*----------------------------------------------------------------------------*/
+/** Initializes UHCI hcd memory structures.
+ *
+ * @param[in] instance UHCI structure to use.
+ * @return Error code
+ * @note Should be called only once on any structure.
+ */
 int uhci_init_mem_structures(uhci_t *instance)
 {
@@ -196,24 +224,27 @@
 	} else (void) 0
 
-	/* init interrupt code */
+	/* Init interrupt code */
 	instance->interrupt_code.cmds = malloc(sizeof(uhci_cmds));
 	int ret = (instance->interrupt_code.cmds == NULL) ? ENOMEM : EOK;
-	CHECK_RET_DEST_CMDS_RETURN(ret, "Failed to allocate interrupt cmds space.\n");
+	CHECK_RET_DEST_CMDS_RETURN(ret,
+	    "Failed to allocate interrupt cmds space.\n");
 
 	{
 		irq_cmd_t *interrupt_commands = instance->interrupt_code.cmds;
 		memcpy(interrupt_commands, uhci_cmds, sizeof(uhci_cmds));
-		interrupt_commands[0].addr = (void*)&instance->registers->usbsts;
-		interrupt_commands[1].addr = (void*)&instance->registers->usbsts;
+		interrupt_commands[0].addr =
+		    (void*)&instance->registers->usbsts;
+		interrupt_commands[1].addr =
+		    (void*)&instance->registers->usbsts;
 		instance->interrupt_code.cmdcount =
 		    sizeof(uhci_cmds) / sizeof(irq_cmd_t);
 	}
 
-	/* init transfer lists */
+	/* Init transfer lists */
 	ret = uhci_init_transfer_lists(instance);
-	CHECK_RET_DEST_CMDS_RETURN(ret, "Failed to initialize transfer lists.\n");
+	CHECK_RET_DEST_CMDS_RETURN(ret, "Failed to init transfer lists.\n");
 	usb_log_debug("Initialized transfer lists.\n");
 
-	/* frame list initialization */
+	/* Init USB frame list page*/
 	instance->frame_list = get_page();
 	ret = instance ? EOK : ENOMEM;
@@ -221,5 +252,5 @@
 	usb_log_debug("Initialized frame list.\n");
 
-	/* initialize all frames to point to the first queue head */
+	/* Set all frames to point to the first queue head */
 	const uint32_t queue =
 	  instance->transfers_interrupt.queue_head_pa
@@ -231,5 +262,5 @@
 	}
 
-	/* init address keeper(libusb) */
+	/* Init device keeper*/
 	device_keeper_init(&instance->device_manager);
 	usb_log_debug("Initialized device manager.\n");
@@ -239,4 +270,10 @@
 }
 /*----------------------------------------------------------------------------*/
+/** Initializes UHCI hcd transfer lists.
+ *
+ * @param[in] instance UHCI structure to use.
+ * @return Error code
+ * @note Should be called only once on any structure.
+ */
 int uhci_init_transfer_lists(uhci_t *instance)
 {
@@ -257,8 +294,10 @@
 	CHECK_RET_CLEAR_RETURN(ret, "Failed to init BULK list.");
 
-	ret = transfer_list_init(&instance->transfers_control_full, "CONTROL_FULL");
+	ret = transfer_list_init(
+	    &instance->transfers_control_full, "CONTROL_FULL");
 	CHECK_RET_CLEAR_RETURN(ret, "Failed to init CONTROL FULL list.");
 
-	ret = transfer_list_init(&instance->transfers_control_slow, "CONTROL_SLOW");
+	ret = transfer_list_init(
+	    &instance->transfers_control_slow, "CONTROL_SLOW");
 	CHECK_RET_CLEAR_RETURN(ret, "Failed to init CONTROL SLOW list.");
 
@@ -279,13 +318,14 @@
 #endif
 
-	instance->transfers[0][USB_TRANSFER_INTERRUPT] =
+	/* Assign pointers to be used during scheduling */
+	instance->transfers[USB_SPEED_FULL][USB_TRANSFER_INTERRUPT] =
 	  &instance->transfers_interrupt;
-	instance->transfers[1][USB_TRANSFER_INTERRUPT] =
+	instance->transfers[USB_SPEED_LOW][USB_TRANSFER_INTERRUPT] =
 	  &instance->transfers_interrupt;
-	instance->transfers[0][USB_TRANSFER_CONTROL] =
+	instance->transfers[USB_SPEED_FULL][USB_TRANSFER_CONTROL] =
 	  &instance->transfers_control_full;
-	instance->transfers[1][USB_TRANSFER_CONTROL] =
+	instance->transfers[USB_SPEED_LOW][USB_TRANSFER_CONTROL] =
 	  &instance->transfers_control_slow;
-	instance->transfers[0][USB_TRANSFER_BULK] =
+	instance->transfers[USB_SPEED_FULL][USB_TRANSFER_BULK] =
 	  &instance->transfers_bulk_full;
 
@@ -294,4 +334,10 @@
 }
 /*----------------------------------------------------------------------------*/
+/** Schedules batch for execution.
+ *
+ * @param[in] instance UHCI structure to use.
+ * @param[in] batch Transfer batch to schedule.
+ * @return Error code
+ */
 int uhci_schedule(uhci_t *instance, batch_t *batch)
 {
@@ -301,5 +347,6 @@
 	if (!allowed_usb_packet(
 	    low_speed, batch->transfer_type, batch->max_packet_size)) {
-		usb_log_warning("Invalid USB packet specified %s SPEED %d %zu.\n",
+		usb_log_warning(
+		    "Invalid USB packet specified %s SPEED %d %zu.\n",
 		    low_speed ? "LOW" : "FULL" , batch->transfer_type,
 		    batch->max_packet_size);
@@ -316,7 +363,13 @@
 }
 /*----------------------------------------------------------------------------*/
+/** Takes action based on the interrupt cause.
+ *
+ * @param[in] instance UHCI structure to use.
+ * @param[in] status Value of the stsatus regiser at the time of interrupt.
+ */
 void uhci_interrupt(uhci_t *instance, uint16_t status)
 {
 	assert(instance);
+	/* TODO: Check interrupt cause here */
 	transfer_list_remove_finished(&instance->transfers_interrupt);
 	transfer_list_remove_finished(&instance->transfers_control_slow);
@@ -325,4 +378,9 @@
 }
 /*----------------------------------------------------------------------------*/
+/** Polling function, emulates interrupts.
+ *
+ * @param[in] arg UHCI structure to use.
+ * @return EOK
+ */
 int uhci_interrupt_emulator(void* arg)
 {
@@ -343,4 +401,9 @@
 }
 /*---------------------------------------------------------------------------*/
+/** Debug function, checks consistency of memory structures.
+ *
+ * @param[in] arg UHCI structure to use.
+ * @return EOK
+ */
 int uhci_debug_checker(void *arg)
 {
@@ -401,8 +464,15 @@
 		async_usleep(UHCI_DEBUGER_TIMEOUT);
 	}
-	return 0;
+	return EOK;
 #undef QH
 }
 /*----------------------------------------------------------------------------*/
+/** Checks transfer packets, for USB validity
+ *
+ * @param[in] low_speed Transfer speed.
+ * @param[in] transfer Transer type
+ * @param[in] size Maximum size of used packets
+ * @return EOK
+ */
 bool allowed_usb_packet(
     bool low_speed, usb_transfer_type_t transfer, size_t size)
