Changeset 7a69340 in mainline


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

sb16: Register functions (mixer, dsp, midi)

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

Legend:

Unmodified
Added
Removed
  • uspace/drv/audio/sb16/Makefile

    r53738d3 r7a69340  
    3838
    3939SOURCES = \
    40         main.c
     40        main.c \
     41        sb16.c
    4142
    4243include $(USPACE_PREFIX)/Makefile.common
  • uspace/drv/audio/sb16/ddf_log.h

    r53738d3 r7a69340  
    4040#define ddf_log_fatal(msg...) ddf_msg(LVL_FATAL, msg)
    4141#define ddf_log_error(msg...) ddf_msg(LVL_ERROR, msg)
    42 #define ddf_log_warning(msg...) ddf_msg(LVL_WARNING, msg)
     42#define ddf_log_warning(msg...) ddf_msg(LVL_WARN, msg)
    4343#define ddf_log_note(msg...) ddf_msg(LVL_NOTE, msg)
    4444#define ddf_log_debug(msg...) ddf_msg(LVL_DEBUG, msg)
  • uspace/drv/audio/sb16/main.c

    r53738d3 r7a69340  
    4141#include <stdio.h>
    4242#include <errno.h>
    43 
    44 //#include <str_error.h>
     43#include <str_error.h>
    4544
    4645#include "ddf_log.h"
     
    7877}
    7978/*----------------------------------------------------------------------------*/
     79static void irq_handler(ddf_dev_t *dev, ipc_callid_t iid, ipc_call_t *call)
     80{
     81        ddf_log_note("SB16 IRQ handler.\n");
     82}
     83/*----------------------------------------------------------------------------*/
    8084/** Initializes a new ddf driver instance of SB16.
    8185 *
     
    8589static int sb_add_device(ddf_dev_t *device)
    8690{
     91#define CHECK_RET_FREE_RETURN(ret, msg...) \
     92if (ret != EOK) { \
     93        free(soft_state); \
     94        ddf_log_error(msg); \
     95        return ret; \
     96} else (void)0
     97
    8798        assert(device);
     99
     100        sb16_drv_t *soft_state = malloc(sizeof(sb16_drv_t));
     101        int ret = soft_state ? EOK : ENOMEM;
     102        CHECK_RET_FREE_RETURN(ret, "Failed to allocate sb16 structure.\n");
     103
    88104        uintptr_t sb_regs = 0, mpu_regs = 0;
    89105        size_t sb_regs_size = 0, mpu_regs_size = 0;
    90106        int irq = 0;
    91         int ret = sb_get_res(device, &sb_regs, &sb_regs_size, &mpu_regs,
     107
     108        ret = sb_get_res(device, &sb_regs, &sb_regs_size, &mpu_regs,
    92109            &mpu_regs_size, &irq);
    93 
    94         return ret;
     110        CHECK_RET_FREE_RETURN(ret,
     111            "Failed to get resources: %s.\n", str_error(ret));
     112
     113        irq_code_t *irq_code = sb16_irq_code();
     114        ret = register_interrupt_handler(device, irq, irq_handler, irq_code);
     115        CHECK_RET_FREE_RETURN(ret,
     116            "Failed to register irq handler: %s.\n", str_error(ret));
     117
     118        ddf_fun_t *dsp_fun = NULL, *mixer_fun = NULL;
     119#define CHECK_RET_UNREG_DEST_RETURN(ret, msg...) \
     120if (ret != EOK) { \
     121        ddf_log_error(msg); \
     122        if (dsp_fun) \
     123                ddf_fun_destroy(dsp_fun); \
     124        if (mixer_fun) \
     125                ddf_fun_destroy(mixer_fun); \
     126        free(soft_state); \
     127        unregister_interrupt_handler(device, irq); \
     128        return ret; \
     129} else (void)0
     130        dsp_fun = ddf_fun_create(device, fun_exposed, "dsp");
     131        ret = dsp_fun ? EOK : ENOMEM;
     132        CHECK_RET_UNREG_DEST_RETURN(ret, "Failed to create dsp function.");
     133
     134        ret = ddf_fun_bind(dsp_fun);
     135        CHECK_RET_UNREG_DEST_RETURN(ret,
     136            "Failed to bind dsp function: %s.\n", str_error(ret));
     137        dsp_fun->driver_data = soft_state;
     138
     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
     143        ret = ddf_fun_bind(mixer_fun);
     144        CHECK_RET_UNREG_DEST_RETURN(ret,
     145            "Failed to bind mixer function: %s.\n", str_error(ret));
     146        mixer_fun->driver_data = soft_state;
     147
     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));
     151
     152        ret = sb16_init_mpu(soft_state, (void*)mpu_regs, mpu_regs_size);
     153        if (ret == EOK) {
     154                ddf_fun_t *mpu_fun =
     155                    ddf_fun_create(device, fun_exposed, "midi");
     156                if (mpu_fun) {
     157                        ret = ddf_fun_bind(mpu_fun);
     158                        if (ret != EOK)
     159                                ddf_log_error(
     160                                    "Failed to bind midi function: %s.\n",
     161                                    str_error(ret));
     162                } else {
     163                        ddf_log_error("Failed to create midi function.\n");
     164                }
     165        } else {
     166            ddf_log_warning("Failed to init mpu driver: %s.\n", str_error(ret));
     167        }
     168
     169        /* MPU state does not matter */
     170        return EOK;
    95171}
    96172/*----------------------------------------------------------------------------*/
  • uspace/drv/audio/sb16/sb16.h

    r53738d3 r7a69340  
    3737
    3838#include <ddf/driver.h>
     39#include <ddi.h>
    3940#include "registers.h"
    4041
     
    4445} sb16_drv_t;
    4546
     47irq_code_t * sb16_irq_code(void);
    4648int sb16_init_sb16(sb16_drv_t *drv, void *regs, size_t size);
    4749int sb16_init_mpu(sb16_drv_t *drv, void *regs, size_t size);
Note: See TracChangeset for help on using the changeset viewer.