Changeset 9dd79bc7 in mainline


Ignore:
Timestamp:
2011-09-24T16:32:12Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
61013bd
Parents:
b956810
Message:

sb16: Add hw DSP initialization.

Location:
uspace/drv/audio/sb16
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/audio/sb16/main.c

    rb956810 r9dd79bc7  
    132132        CHECK_RET_UNREG_DEST_RETURN(ret, "Failed to create dsp function.");
    133133
     134
     135        mixer_fun = ddf_fun_create(device, fun_exposed, "mixer");
     136        ret = dsp_fun ? EOK : ENOMEM;
     137        CHECK_RET_UNREG_DEST_RETURN(ret, "Failed to create mixer function.");
     138
     139        ret = sb16_init_sb16(soft_state, (void*)sb_regs, sb_regs_size);
     140        CHECK_RET_UNREG_DEST_RETURN(ret,
     141            "Failed to init sb16 driver: %s.\n", str_error(ret));
     142
    134143        ret = ddf_fun_bind(dsp_fun);
    135144        CHECK_RET_UNREG_DEST_RETURN(ret,
     
    137146        dsp_fun->driver_data = soft_state;
    138147
    139         mixer_fun = ddf_fun_create(device, fun_exposed, "mixer");
    140         ret = dsp_fun ? EOK : ENOMEM;
    141         CHECK_RET_UNREG_DEST_RETURN(ret, "Failed to create mixer function.");
    142 
    143148        ret = ddf_fun_bind(mixer_fun);
    144149        CHECK_RET_UNREG_DEST_RETURN(ret,
     
    146151        mixer_fun->driver_data = soft_state;
    147152
    148         ret = sb16_init_sb16(soft_state, (void*)sb_regs, sb_regs_size);
    149         CHECK_RET_UNREG_DEST_RETURN(ret,
    150             "Failed to init sb16 driver: %s.\n", str_error(ret));
    151153
    152154        ret = sb16_init_mpu(soft_state, (void*)mpu_regs, mpu_regs_size);
  • uspace/drv/audio/sb16/registers.h

    rb956810 r9dd79bc7  
    4646        ioport8_t fm_address_status2;
    4747        ioport8_t fm_data2;
    48         const ioport8_t dsp_data_read;
     48        ioport8_t dsp_data_read;
    4949        ioport8_t dsp_write; /* Both command and data, bit 7 is write status */
    50         const ioport8_t dsp_read_status; /* Bit 7 */
     50#define DSP_WRITE_READY (1 << 7)
     51        ioport8_t dsp_read_status; /* Bit 7 */
     52#define DSP_READ_READY (1 << 7)
    5153        ioport8_t reserved;
    5254        ioport8_t cd_command_data;
  • uspace/drv/audio/sb16/sb16.c

    rb956810 r9dd79bc7  
    2828
    2929#include <errno.h>
     30#include <libarch/ddi.h>
    3031
     32#include "ddf_log.h"
     33#include "dsp_commands.h"
    3134#include "sb16.h"
     35
     36
     37static inline void sb16_dsp_command(sb16_drv_t *drv, dsp_command_t command)
     38{
     39        assert(drv);
     40        uint8_t status;
     41        do {
     42                status = pio_read_8(&drv->regs->dsp_write);
     43        } while ((status & DSP_WRITE_READY) == 0);
     44
     45        pio_write_8(&drv->regs->dsp_write, command);
     46}
     47
     48static inline uint8_t sb16_dsp_read(sb16_drv_t *drv)
     49{
     50        assert(drv);
     51        uint8_t status;
     52        do {
     53                status = pio_read_8(&drv->regs->dsp_read_status);
     54        } while ((status & DSP_READ_READY) == 0);
     55        return pio_read_8(&drv->regs->dsp_data_read);
     56}
     57
    3258
    3359/* ISA interrupts should be edge-triggered so there should be no need for
     
    4571int sb16_init_sb16(sb16_drv_t *drv, void *regs, size_t size)
    4672{
    47         // TODO Setup registers
    48         // TODO Initialize dsp: get version number
    49         // TODO Initialize dsp: reset DSP
     73        assert(drv);
     74        /* Setup registers */
     75        int ret = pio_enable(regs, size, (void**)&drv->regs);
     76        if (ret != EOK)
     77                return ret;
     78        ddf_log_debug("PIO registers at %p accessible.\n", drv->regs);
     79
     80        /* Reset DSP, see Chapter 2 of Sound Blaster HW programming guide */
     81        pio_write_16(&drv->regs->dsp_reset, 1);
     82        udelay(3);
     83        pio_write_16(&drv->regs->dsp_reset, 0);
     84        udelay(100);
     85
     86        unsigned attempts = 100;
     87        uint8_t status;
     88        do {
     89                status = pio_read_8(&drv->regs->dsp_read_status);
     90                udelay(10);
     91        } while (--attempts && ((status & DSP_READ_READY) == 0));
     92
     93        if (status & DSP_READ_READY) {
     94                const uint8_t response = sb16_dsp_read(drv);
     95                if (response != 0xaa) {
     96                        ddf_log_error("Invalid DSP reset response: %x.\n",
     97                            response);
     98                        return EIO;
     99                }
     100        } else {
     101                ddf_log_error("Failed to reset Sound Blaster DSP.\n");
     102                return EIO;
     103        }
     104        ddf_log_note("Sound blaster reset!\n");
     105
     106
     107        /* Get DSP version number */
     108        sb16_dsp_command(drv, DSP_VERSION);
     109        const uint8_t major = sb16_dsp_read(drv);
     110        const uint8_t minor = sb16_dsp_read(drv);
     111        ddf_log_note("Sound blaster DSP version: %x.%x.\n", major, minor);
     112
     113
    50114        // TODO Initialize mixer
    51115        return EOK;
  • uspace/drv/audio/sb16/sb16.h

    rb956810 r9dd79bc7  
    5353 * @}
    5454 */
    55 
Note: See TracChangeset for help on using the changeset viewer.