Changeset 7a69340 in mainline for uspace/drv/audio/sb16/main.c
- Timestamp:
- 2011-09-24T13:41:14Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b956810
- Parents:
- 53738d3
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/audio/sb16/main.c
r53738d3 r7a69340 41 41 #include <stdio.h> 42 42 #include <errno.h> 43 44 //#include <str_error.h> 43 #include <str_error.h> 45 44 46 45 #include "ddf_log.h" … … 78 77 } 79 78 /*----------------------------------------------------------------------------*/ 79 static 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 /*----------------------------------------------------------------------------*/ 80 84 /** Initializes a new ddf driver instance of SB16. 81 85 * … … 85 89 static int sb_add_device(ddf_dev_t *device) 86 90 { 91 #define CHECK_RET_FREE_RETURN(ret, msg...) \ 92 if (ret != EOK) { \ 93 free(soft_state); \ 94 ddf_log_error(msg); \ 95 return ret; \ 96 } else (void)0 97 87 98 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 88 104 uintptr_t sb_regs = 0, mpu_regs = 0; 89 105 size_t sb_regs_size = 0, mpu_regs_size = 0; 90 106 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, 92 109 &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...) \ 120 if (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; 95 171 } 96 172 /*----------------------------------------------------------------------------*/
Note:
See TracChangeset
for help on using the changeset viewer.