Index: uspace/drv/char/i8042/main.c
===================================================================
--- uspace/drv/char/i8042/main.c	(revision 8bb95403773445b62a56729df809c5540b3f91a5)
+++ uspace/drv/char/i8042/main.c	(revision b99a5e85052a524769bf0a363d99e387e28b50dd)
@@ -26,7 +26,9 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
+
 /** @addtogroup drvi8042
  * @{
  */
+
 /** @file
  * @brief i8042 driver DDF bits.
@@ -41,12 +43,100 @@
 #include <ddf/log.h>
 #include <stdio.h>
-
 #include "i8042.h"
 
-#define NAME "i8042"
+#define CHECK_RET_RETURN(ret, message...) \
+	do { \
+		if (ret != EOK) { \
+			ddf_msg(LVL_ERROR, message); \
+			return ret; \
+		} \
+	} while (0)
 
-static int get_my_registers(const ddf_dev_t *dev,
-    uintptr_t *io_reg_address, size_t *io_reg_size, int *kbd, int *mouse);
-static int i8042_dev_add(ddf_dev_t *device);
+/** Get address of I/O registers.
+ *
+ * @param[in]  dev            Device asking for the addresses.
+ * @param[out] io_reg_address Base address of the memory range.
+ * @param[out] io_reg_size    Size of the memory range.
+ * @param[out] kbd_irq        Primary port IRQ.
+ * @param[out] mouse_irq      Auxiliary port IRQ.
+ *
+ * @return Error code.
+ *
+ */
+static int get_my_registers(const ddf_dev_t *dev, uintptr_t *io_reg_address,
+    size_t *io_reg_size, int *kbd_irq, int *mouse_irq)
+{
+	assert(dev);
+	
+	async_sess_t *parent_sess =
+	    devman_parent_device_connect(EXCHANGE_SERIALIZE, dev->handle,
+	    IPC_FLAG_BLOCKING);
+	if (!parent_sess)
+		return ENOMEM;
+	
+	hw_res_list_parsed_t hw_resources;
+	hw_res_list_parsed_init(&hw_resources);
+	const int ret = hw_res_get_list_parsed(parent_sess, &hw_resources, 0);
+	async_hangup(parent_sess);
+	if (ret != EOK)
+		return ret;
+	
+	if ((hw_resources.irqs.count != 2) ||
+	    (hw_resources.io_ranges.count != 1)) {
+		hw_res_list_parsed_clean(&hw_resources);
+		return EINVAL;
+	}
+	
+	if (io_reg_address)
+		*io_reg_address = hw_resources.io_ranges.ranges[0].address;
+	
+	if (io_reg_size)
+		*io_reg_size = hw_resources.io_ranges.ranges[0].size;
+	
+	if (kbd_irq)
+		*kbd_irq = hw_resources.irqs.irqs[0];
+	
+	if (mouse_irq)
+		*mouse_irq = hw_resources.irqs.irqs[1];
+	
+	hw_res_list_parsed_clean(&hw_resources);
+	return EOK;
+}
+
+/** Initialize a new ddf driver instance of i8042 driver
+ *
+ * @param[in] device DDF instance of the device to initialize.
+ *
+ * @return Error code.
+ *
+ */
+static int i8042_dev_add(ddf_dev_t *device)
+{
+	if (!device)
+		return EINVAL;
+	
+	uintptr_t io_regs = 0;
+	size_t io_size = 0;
+	int kbd = 0;
+	int mouse = 0;
+	
+	int ret = get_my_registers(device, &io_regs, &io_size, &kbd, &mouse);
+	CHECK_RET_RETURN(ret, "Failed to get registers: %s.",
+	    str_error(ret));
+	ddf_msg(LVL_DEBUG, "I/O regs at %p (size %zuB), IRQ kbd %d, IRQ mouse %d.",
+	    (void *) io_regs, io_size, kbd, mouse);
+	
+	i8042_t *i8042 = ddf_dev_data_alloc(device, sizeof(i8042_t));
+	ret = (i8042 == NULL) ? ENOMEM : EOK;
+	CHECK_RET_RETURN(ret, "Failed to allocate i8042 driver instance.");
+	
+	ret = i8042_init(i8042, (void *) io_regs, io_size, kbd, mouse, device);
+	CHECK_RET_RETURN(ret, "Failed to initialize i8042 driver: %s.",
+	    str_error(ret));
+	
+	ddf_msg(LVL_NOTE, "Controlling '%s' (%" PRIun ").",
+	    device->name, device->handle);
+	return EOK;
+}
 
 /** DDF driver operations. */
@@ -61,107 +151,11 @@
 };
 
-/** Initialize global driver structures (NONE).
- *
- * @param[in] argc Nmber of arguments in argv vector (ignored).
- * @param[in] argv Cmdline argument vector (ignored).
- * @return Error code.
- *
- * Driver debug level is set here.
- */
 int main(int argc, char *argv[])
 {
-	printf(NAME ": HelenOS ps/2 driver.\n");
+	printf("%s: HelenOS PS/2 driver.\n", NAME);
 	ddf_log_init(NAME, LVL_NOTE);
 	return ddf_driver_main(&i8042_driver);
 }
 
-/** Initialize a new ddf driver instance of i8042 driver
- *
- * @param[in] device DDF instance of the device to initialize.
- * @return Error code.
- */
-static int i8042_dev_add(ddf_dev_t *device)
-{
-	if (!device)
-		return EINVAL;
-
-#define CHECK_RET_RETURN(ret, message...) \
-if (ret != EOK) { \
-	ddf_msg(LVL_ERROR, message); \
-	return ret; \
-} else (void)0
-
-	uintptr_t io_regs = 0;
-	size_t io_size = 0;
-	int kbd = 0, mouse = 0;
-
-	int ret = get_my_registers(device, &io_regs, &io_size, &kbd, &mouse);
-	CHECK_RET_RETURN(ret,
-	    "Failed to get registers: %s.", str_error(ret));
-	ddf_msg(LVL_DEBUG,
-	    "I/O regs at %p (size %zuB), IRQ kbd %d, IRQ mouse %d.",
-	    (void *) io_regs, io_size, kbd, mouse);
-
-	i8042_t *i8042 = ddf_dev_data_alloc(device, sizeof(i8042_t));
-	ret = (i8042 == NULL) ? ENOMEM : EOK;
-	CHECK_RET_RETURN(ret, "Failed to allocate i8042 driver instance.");
-
-	ret = i8042_init(i8042, (void*)io_regs, io_size, kbd, mouse, device);
-	CHECK_RET_RETURN(ret,
-	    "Failed to initialize i8042 driver: %s.", str_error(ret));
-
-	ddf_msg(LVL_NOTE, "Controlling '%s' (%" PRIun ").",
-	    device->name, device->handle);
-	return EOK;
-}
-
-/** Get address of I/O registers.
- *
- * @param[in] dev Device asking for the addresses.
- * @param[out] io_reg_address Base address of the memory range.
- * @param[out] io_reg_size Size of the memory range.
- * @param[out] kbd_irq Primary port IRQ.
- * @param[out] mouse_irq Auxiliary port IRQ.
- * @return Error code.
- */
-int get_my_registers(const ddf_dev_t *dev, uintptr_t *io_reg_address,
-    size_t *io_reg_size, int *kbd_irq, int *mouse_irq)
-{
-	assert(dev);
-
-	async_sess_t *parent_sess =
-	    devman_parent_device_connect(EXCHANGE_SERIALIZE, dev->handle,
-	    IPC_FLAG_BLOCKING);
-	if (!parent_sess)
-		return ENOMEM;
-
-	hw_res_list_parsed_t hw_resources;
-	hw_res_list_parsed_init(&hw_resources);
-	const int ret = hw_res_get_list_parsed(parent_sess, &hw_resources, 0);
-	async_hangup(parent_sess);
-	if (ret != EOK) {
-		return ret;
-	}
-
-	if (hw_resources.irqs.count != 2 || hw_resources.io_ranges.count != 1) {
-		hw_res_list_parsed_clean(&hw_resources);
-		return EINVAL;
-	}
-
-	if (io_reg_address)
-		*io_reg_address = hw_resources.io_ranges.ranges[0].address;
-
-	if (io_reg_size)
-		*io_reg_size = hw_resources.io_ranges.ranges[0].size;
-
-	if (kbd_irq)
-		*kbd_irq = hw_resources.irqs.irqs[0];
-
-	if (mouse_irq)
-		*mouse_irq = hw_resources.irqs.irqs[1];
-
-	hw_res_list_parsed_clean(&hw_resources);
-	return EOK;
-}
 /**
  * @}
