Changeset 5b1adf5 in mainline
- Timestamp:
- 2013-08-23T14:21:58Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f7fba727
- Parents:
- cf02eaf
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/audio/sb16/main.c
rcf02eaf r5b1adf5 53 53 int *irq, int *dma8, int *dma16); 54 54 static int sb_enable_interrupts(ddf_dev_t *device); 55 /*----------------------------------------------------------------------------*/ 55 56 56 static driver_ops_t sb_driver_ops = { 57 57 .dev_add = sb_add_device, 58 58 }; 59 /*----------------------------------------------------------------------------*/ 59 60 60 static driver_t sb_driver = { 61 61 .name = NAME, 62 62 .driver_ops = &sb_driver_ops 63 63 }; 64 //static ddf_dev_ops_t sb_ops = {}; 65 /*----------------------------------------------------------------------------*/ 66 /** Initializes global driver structures (NONE). 64 65 /** Initialize global driver structures (NONE). 67 66 * 68 67 * @param[in] argc Nmber of arguments in argv vector (ignored). … … 81 80 static void irq_handler(ddf_dev_t *dev, ipc_callid_t iid, ipc_call_t *call) 82 81 { 83 assert(dev);84 82 sb16_t *sb16_dev = ddf_dev_data_get(dev); 85 assert(sb16_dev);86 83 sb16_interrupt(sb16_dev); 87 84 } 88 85 89 /** Initialize s a new ddf driver instance of SB16.86 /** Initialize new SB16 driver instance. 90 87 * 91 88 * @param[in] device DDF instance of the device to initialize. … … 94 91 static int sb_add_device(ddf_dev_t *device) 95 92 { 96 #define CHECK_RET_RETURN(ret, msg...) \ 97 if (ret != EOK) { \ 98 ddf_log_error(msg); \ 99 return ret; \ 100 } else (void)0 101 102 assert(device); 93 bool handler_regd = false; 94 const size_t irq_cmd_count = sb16_irq_code_size(); 95 irq_cmd_t irq_cmds[irq_cmd_count]; 96 irq_pio_range_t irq_ranges[1]; 103 97 104 98 sb16_t *soft_state = ddf_dev_data_alloc(device, sizeof(sb16_t)); 105 int ret = soft_state ? EOK : ENOMEM; 106 CHECK_RET_RETURN(ret, "Failed to allocate sb16 structure."); 99 int rc = soft_state ? EOK : ENOMEM; 100 if (rc != EOK) { 101 ddf_log_error("Failed to allocate sb16 structure."); 102 goto error; 103 } 107 104 108 105 uintptr_t sb_regs = 0, mpu_regs = 0; … … 110 107 int irq = 0, dma8 = 0, dma16 = 0; 111 108 112 r et= sb_get_res(device, &sb_regs, &sb_regs_size, &mpu_regs,109 rc = sb_get_res(device, &sb_regs, &sb_regs_size, &mpu_regs, 113 110 &mpu_regs_size, &irq, &dma8, &dma16); 114 CHECK_RET_RETURN(ret, "Failed to get resources: %s.", str_error(ret));115 116 const size_t irq_cmd_count = sb16_irq_code_size();117 irq_cmd_t irq_cmds[irq_cmd_count];118 irq_pio_range_t irq_ranges[1]; 111 if (rc != EOK) { 112 ddf_log_error("Failed to get resources: %s.", str_error(rc)); 113 goto error; 114 } 115 119 116 sb16_irq_code((void*)sb_regs, dma8, dma16, irq_cmds, irq_ranges); 120 117 … … 126 123 }; 127 124 128 ret = register_interrupt_handler(device, irq, irq_handler, &irq_code); 129 CHECK_RET_RETURN(ret, 130 "Failed to register irq handler: %s.", str_error(ret)); 131 132 #define CHECK_RET_UNREG_DEST_RETURN(ret, msg...) \ 133 if (ret != EOK) { \ 134 ddf_log_error(msg); \ 135 unregister_interrupt_handler(device, irq); \ 136 return ret; \ 137 } else (void)0 138 139 ret = sb_enable_interrupts(device); 140 CHECK_RET_UNREG_DEST_RETURN(ret, "Failed to enable interrupts: %s.", 141 str_error(ret)); 142 143 ret = sb16_init_sb16( 144 soft_state, (void*)sb_regs, sb_regs_size, device, dma8, dma16); 145 CHECK_RET_UNREG_DEST_RETURN(ret, 146 "Failed to init sb16 driver: %s.", str_error(ret)); 147 148 ret = sb16_init_mpu(soft_state, (void*)mpu_regs, mpu_regs_size); 149 if (ret == EOK) { 125 rc = register_interrupt_handler(device, irq, irq_handler, &irq_code); 126 if (rc != EOK) { 127 ddf_log_error("Failed to register irq handler: %s.", 128 str_error(rc)); 129 goto error; 130 } 131 132 handler_regd = true; 133 134 rc = sb_enable_interrupts(device); 135 if (rc != EOK) { 136 ddf_log_error("Failed to enable interrupts: %s.", 137 str_error(rc)); 138 goto error; 139 } 140 141 rc = sb16_init_sb16(soft_state, (void*)sb_regs, sb_regs_size, device, 142 dma8, dma16); 143 if (rc != EOK) { 144 ddf_log_error("Failed to init sb16 driver: %s.", 145 str_error(rc)); 146 goto error; 147 } 148 149 rc = sb16_init_mpu(soft_state, (void*)mpu_regs, mpu_regs_size); 150 if (rc == EOK) { 150 151 ddf_fun_t *mpu_fun = 151 152 ddf_fun_create(device, fun_exposed, "midi"); 152 153 if (mpu_fun) { 153 r et= ddf_fun_bind(mpu_fun);154 if (r et!= EOK)154 rc = ddf_fun_bind(mpu_fun); 155 if (rc != EOK) 155 156 ddf_log_error( 156 157 "Failed to bind midi function: %s.", 157 str_error(r et));158 str_error(rc)); 158 159 } else { 159 160 ddf_log_error("Failed to create midi function."); 160 161 } 161 162 } else { 162 ddf_log_warning("Failed to init mpu driver: %s.", str_error(ret)); 163 ddf_log_warning("Failed to init mpu driver: %s.", 164 str_error(rc)); 163 165 } 164 166 165 167 /* MPU state does not matter */ 166 168 return EOK; 169 error: 170 if (handler_regd) 171 unregister_interrupt_handler(device, irq); 172 return rc; 167 173 } 168 174
Note:
See TracChangeset
for help on using the changeset viewer.