Changeset bf38143 in mainline


Ignore:
Timestamp:
2011-09-26T15:26:48Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ce1e5ea
Parents:
bde691c
Message:

sb16: Use new sb_dsp_t structure.

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

Legend:

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

    rbde691c rbf38143  
    3434
    3535#include <libarch/ddi.h>
     36#include "ddf_log.h"
     37#include "dsp_commands.h"
    3638#include "dsp.h"
    3739
    38 int dsp_play_direct(sb16_regs_t *regs, const uint8_t *data, size_t size,
     40
     41#ifndef DSP_RETRY_COUNT
     42#define DSP_RETRY_COUNT 100
     43#endif
     44
     45#define DSP_RESET_RESPONSE 0xaa
     46
     47static inline int sb_dsp_read(sb_dsp_t *dsp, uint8_t *data)
     48{
     49        assert(data);
     50        assert(dsp);
     51        uint8_t status;
     52        size_t attempts = DSP_RETRY_COUNT;
     53        do {
     54                status = pio_read_8(&dsp->regs->dsp_read_status);
     55        } while (--attempts && ((status & DSP_READ_READY) == 0));
     56
     57        if ((status & DSP_READ_READY) == 0)
     58                return EIO;
     59
     60        *data = pio_read_8(&dsp->regs->dsp_data_read);
     61        return EOK;
     62}
     63/*----------------------------------------------------------------------------*/
     64static inline int sb_dsp_write(sb_dsp_t *dsp, uint8_t data)
     65{
     66        assert(dsp);
     67        uint8_t status;
     68        size_t attempts = DSP_RETRY_COUNT;
     69        do {
     70                status = pio_read_8(&dsp->regs->dsp_write);
     71        } while (--attempts && ((status & DSP_WRITE_BUSY) != 0));
     72
     73        if ((status & DSP_WRITE_BUSY))
     74                return EIO;
     75
     76        pio_write_8(&dsp->regs->dsp_write, data);
     77        return EOK;
     78}
     79/*----------------------------------------------------------------------------*/
     80static inline void sb_dsp_reset(sb_dsp_t *dsp)
     81{
     82        assert(dsp);
     83        /* Reset DSP, see Chapter 2 of Sound Blaster HW programming guide */
     84        pio_write_8(&dsp->regs->dsp_reset, 1);
     85        udelay(3); /* Keep reset for 3 us */
     86        pio_write_8(&dsp->regs->dsp_reset, 0);
     87}
     88/*----------------------------------------------------------------------------*/
     89int sb_dsp_init(sb_dsp_t *dsp, sb16_regs_t *regs)
     90{
     91        assert(dsp);
     92        dsp->regs = regs;
     93        sb_dsp_reset(dsp);
     94        /* "DSP takes about 100 microseconds to initialize itself" */
     95        udelay(100);
     96        uint8_t response;
     97        const int ret = sb_dsp_read(dsp, &response);
     98        if (ret != EOK) {
     99                ddf_log_error("Failed to read DSP reset response value.\n");
     100                return ret;
     101        }
     102        if (response != DSP_RESET_RESPONSE) {
     103                ddf_log_error("Invalid DSP reset response: %x.\n", response);
     104                return EIO;
     105        }
     106
     107        /* Get DSP version number */
     108        sb_dsp_write(dsp, DSP_VERSION);
     109        sb_dsp_read(dsp, &dsp->version.major);
     110        sb_dsp_read(dsp, &dsp->version.minor);
     111        return EOK;
     112}
     113/*----------------------------------------------------------------------------*/
     114int sb_dsp_play_direct(sb_dsp_t *dsp, const uint8_t *data, size_t size,
    39115    unsigned sampling_rate, unsigned channels, unsigned bit_depth)
    40116{
     117        assert(dsp);
    41118        if (channels != 1 || bit_depth != 8)
    42119                return EIO;
     
    44121        const unsigned wait_period = 1000000 / sampling_rate;
    45122        while (size--) {
    46                 pio_write_8(&regs->dsp_write, DIRECT_8B_OUTPUT);
    47                 pio_write_8(&regs->dsp_write, *data++);
     123                pio_write_8(&dsp->regs->dsp_write, DIRECT_8B_OUTPUT);
     124                pio_write_8(&dsp->regs->dsp_write, *data++);
    48125                udelay(wait_period);
    49126        }
  • uspace/drv/audio/sb16/dsp.h

    rbde691c rbf38143  
    3939
    4040#include "registers.h"
    41 #include "dsp_commands.h"
    4241
    43 #ifndef DSP_PIO_DELAY
    44 #define DSP_PIO_DELAY udelay(10)
    45 #endif
     42typedef struct sb_dsp_t {
     43        sb16_regs_t *regs;
     44        struct {
     45                uint8_t major;
     46                uint8_t minor;
     47        } version;
     48        uint8_t *data_buffer;
     49        uint8_t *buffer_position;
     50        size_t buffer_size;
     51} sb_dsp_t;
    4652
    47 #ifndef DSP_RETRY_COUNT
    48 #define DSP_RETRY_COUNT 100
    49 #endif
    5053
    51 #define DSP_RESET_RESPONSE 0xaa
    5254
    53 static inline int dsp_write(sb16_regs_t *regs, uint8_t data)
    54 {
    55         uint8_t status;
    56         size_t attempts = DSP_RETRY_COUNT;
    57         do {
    58                 DSP_PIO_DELAY;
    59                 status = pio_read_8(&regs->dsp_write);
    60         } while (--attempts && ((status & DSP_WRITE_BUSY) != 0));
    61         if ((status & DSP_WRITE_BUSY))
    62                 return EIO;
    63         DSP_PIO_DELAY;
    64         pio_write_8(&regs->dsp_write, data);
    65         return EOK;
    66 }
    6755/*----------------------------------------------------------------------------*/
    68 static inline int dsp_read(sb16_regs_t *regs, uint8_t *data)
    69 {
    70         assert(data);
    71         uint8_t status;
    72         size_t attempts = DSP_RETRY_COUNT;
    73         do {
    74                 DSP_PIO_DELAY;
    75                 status = pio_read_8(&regs->dsp_read_status);
    76         } while (--attempts && ((status & DSP_READ_READY) == 0));
    77 
    78         if ((status & DSP_READ_READY) == 0)
    79                 return EIO;
    80 
    81         DSP_PIO_DELAY;
    82         *data = pio_read_8(&regs->dsp_data_read);
    83         return EOK;
    84 }
     56int sb_dsp_init(sb_dsp_t *dsp, sb16_regs_t *regs);
    8557/*----------------------------------------------------------------------------*/
    86 static inline void dsp_reset(sb16_regs_t *regs)
    87 {
    88         /* Reset DSP, see Chapter 2 of Sound Blaster HW programming guide */
    89         pio_write_8(&regs->dsp_reset, 1);
    90         udelay(3); /* Keep reset for 3 us */
    91         pio_write_8(&regs->dsp_reset, 0);
    92 }
    93 /*----------------------------------------------------------------------------*/
    94 int dsp_play_direct(sb16_regs_t *regs, const uint8_t *data, size_t size,
     58int sb_dsp_play_direct(sb_dsp_t *dsp, const uint8_t *data, size_t size,
    9559    unsigned sample_rate, unsigned channels, unsigned bit_depth);
    9660#endif
  • uspace/drv/audio/sb16/sb16.c

    rbde691c rbf38143  
    6868        ddf_log_debug("PIO registers at %p accessible.\n", drv->regs);
    6969
    70         dsp_reset(drv->regs);
    71         /* "DSP takes about 100 microseconds to initialize itself" */
    72         udelay(100);
    73 
    74         uint8_t response;
    75         ret = dsp_read(drv->regs, &response);
     70        /* Initialize DSP */
     71        ret = sb_dsp_init(&drv->dsp, drv->regs);
    7672        if (ret != EOK) {
    77                 ddf_log_error("Failed to read DSP reset response value.\n");
     73                ddf_log_error("Failed to initialize SB DSP: %s.\n",
     74                    str_error(ret));
    7875                return ret;
    7976        }
    80 
    81         if (response != DSP_RESET_RESPONSE) {
    82                 ddf_log_error("Invalid DSP reset response: %x.\n", response);
    83                 return EIO;
    84         }
    85 
    86         /* Get DSP version number */
    87         dsp_write(drv->regs, DSP_VERSION);
    88         dsp_read(drv->regs, &drv->dsp_version.major);
    89         dsp_read(drv->regs, &drv->dsp_version.minor);
    9077        ddf_log_note("Sound blaster DSP (%x.%x) initialized.\n",
    91             drv->dsp_version.major, drv->dsp_version.minor);
     78            drv->dsp.version.major, drv->dsp.version.minor);
    9279
    9380        /* Initialize mixer */
    9481        const sb_mixer_type_t mixer_type = sb_mixer_type_by_dsp_version(
    95             drv->dsp_version.major, drv->dsp_version.minor);
     82            drv->dsp.version.major, drv->dsp.version.minor);
    9683
    9784        ret = sb_mixer_init(&drv->mixer, drv->regs, mixer_type);
  • uspace/drv/audio/sb16/sb16.h

    rbde691c rbf38143  
    3939#include <ddi.h>
    4040
     41#include "dsp.h"
    4142#include "mixer.h"
    4243#include "registers.h"
     
    4546        sb16_regs_t *regs;
    4647        mpu_regs_t *mpu_regs;
    47         struct {
    48                 uint8_t major;
    49                 uint8_t minor;
    50         } dsp_version;
     48        sb_dsp_t dsp;
    5149        sb_mixer_t mixer;
    5250} sb16_drv_t;
Note: See TracChangeset for help on using the changeset viewer.