Index: uspace/drv/audio/sb16/dsp.h
===================================================================
--- uspace/drv/audio/sb16/dsp.h	(revision cf083e84ee82f1305d773dd592e8655485b7eaaa)
+++ uspace/drv/audio/sb16/dsp.h	(revision cf083e84ee82f1305d773dd592e8655485b7eaaa)
@@ -0,0 +1,93 @@
+/*
+ * 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 drvaudiosb16
+ * @{
+ */
+/** @file
+ * @brief SB16 main structure combining all functionality
+ */
+#ifndef DRV_AUDIO_SB16_DSP_H
+#define DRV_AUDIO_SB16_DSP_H
+
+#include "registers.h"
+
+#ifndef DSP_PIO_DELAY
+#define DSP_PIO_DELAY udelay(10)
+#endif
+
+#ifndef DSP_RETRY_COUNT
+#define DSP_RETRY_COUNT 100
+#endif
+
+#define DSP_RESET_RESPONSE 0xaa
+
+static inline int dsp_write(sb16_regs_t *regs, uint8_t data)
+{
+	uint8_t status;
+	size_t attempts = DSP_RETRY_COUNT;
+	do {
+		DSP_PIO_DELAY;
+		status = pio_read_8(&regs->dsp_write);
+	} while (--attempts && ((status & DSP_WRITE_BUSY) != 0));
+	if ((status & DSP_WRITE_BUSY))
+		return EIO;
+	DSP_PIO_DELAY;
+	pio_write_8(&regs->dsp_write, data);
+	return EOK;
+}
+/*----------------------------------------------------------------------------*/
+static inline int dsp_read(sb16_regs_t *regs, uint8_t *data)
+{
+	assert(data);
+	uint8_t status;
+	size_t attempts = DSP_RETRY_COUNT;
+	do {
+		DSP_PIO_DELAY;
+		status = pio_read_8(&regs->dsp_read_status);
+	} while (--attempts && ((status & DSP_READ_READY) == 0));
+
+	if ((status & DSP_READ_READY) == 0)
+		return EIO;
+
+	DSP_PIO_DELAY;
+	*data = pio_read_8(&regs->dsp_data_read);
+	return EOK;
+}
+/*----------------------------------------------------------------------------*/
+static inline void dsp_reset(sb16_regs_t *regs)
+{
+	/* Reset DSP, see Chapter 2 of Sound Blaster HW programming guide */
+	pio_write_8(&regs->dsp_reset, 1);
+	udelay(3); /* Keep reset for 3 us */
+	pio_write_8(&regs->dsp_reset, 0);
+}
+#endif
+/**
+ * @}
+ */
Index: uspace/drv/audio/sb16/sb16.c
===================================================================
--- uspace/drv/audio/sb16/sb16.c	(revision 7d5057e12cf3ff9b3dce01b2dfe398b93855bb6b)
+++ uspace/drv/audio/sb16/sb16.c	(revision cf083e84ee82f1305d773dd592e8655485b7eaaa)
@@ -32,34 +32,7 @@
 #include "ddf_log.h"
 #include "dsp_commands.h"
+#include "dsp.h"
 #include "sb16.h"
 
-#define PIO_DELAY udelay(10)
-
-
-static inline void sb16_dsp_write(sb16_drv_t *drv, uint8_t data)
-{
-	assert(drv);
-	uint8_t status;
-	do {
-		PIO_DELAY;
-		status = pio_read_8(&drv->regs->dsp_write);
-	} while ((status & DSP_WRITE_BUSY) != 0);
-	PIO_DELAY;
-	pio_write_8(&drv->regs->dsp_write, data);
-}
-/*----------------------------------------------------------------------------*/
-static inline uint8_t sb16_dsp_read(sb16_drv_t *drv)
-{
-	assert(drv);
-	uint8_t status;
-	do {
-		PIO_DELAY;
-		status = pio_read_8(&drv->regs->dsp_read_status);
-	} while ((status & DSP_READ_READY) == 0);
-
-	PIO_DELAY;
-	return pio_read_8(&drv->regs->dsp_data_read);
-}
-/*----------------------------------------------------------------------------*/
 /* ISA interrupts should be edge-triggered so there should be no need for
  * irq code magic */
@@ -83,36 +56,24 @@
 	ddf_log_debug("PIO registers at %p accessible.\n", drv->regs);
 
-	/* Reset DSP, see Chapter 2 of Sound Blaster HW programming guide */
-	pio_write_8(&drv->regs->dsp_reset, 1);
-	udelay(3); /* Keep reset for 3 us */
-	pio_write_8(&drv->regs->dsp_reset, 0);
-
+	dsp_reset(drv->regs);
 	/* "DSP takes about 100 microseconds to initialize itself" */
 	udelay(100);
 
+	uint8_t response;
+	ret = dsp_read(drv->regs, &response);
+	if (ret != EOK) {
+		ddf_log_error("Failed to read DSP reset response value.\n");
+		return ret;
+	}
 
-	unsigned attempts = 100;
-	uint8_t status;
-	do {
-		PIO_DELAY;
-		status = pio_read_8(&drv->regs->dsp_read_status);
-	} while (--attempts && ((status & DSP_READ_READY) == 0));
-
-	if (status & DSP_READ_READY) {
-		const uint8_t response = sb16_dsp_read(drv);
-		if (response != 0xaa) {
-			ddf_log_error("Invalid DSP reset response: %x.\n",
-			    response);
-			return EIO;
-		}
-	} else {
-		ddf_log_error("Failed to reset Sound Blaster DSP.\n");
+	if (response != DSP_RESET_RESPONSE) {
+		ddf_log_error("Invalid DSP reset response: %x.\n", response);
 		return EIO;
 	}
 
 	/* Get DSP version number */
-	sb16_dsp_write(drv, DSP_VERSION);
-	drv->dsp_version.major = sb16_dsp_read(drv);
-	drv->dsp_version.minor = sb16_dsp_read(drv);
+	dsp_write(drv->regs, DSP_VERSION);
+	dsp_read(drv->regs, &drv->dsp_version.major);
+	dsp_read(drv->regs, &drv->dsp_version.minor);
 	ddf_log_note("Sound blaster DSP (%x.%x) Initialized.\n",
 	    drv->dsp_version.major, drv->dsp_version.minor);
