Changeset 5eed99d in mainline
- Timestamp:
- 2012-08-30T11:54:53Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f2a92b0
- Parents:
- 92b638c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/audio/sb16/dsp.c
r92b638c r5eed99d 81 81 82 82 83 static inline void sb_dsp_change_state(sb_dsp_t *dsp, dsp_state_t state)83 static inline void dsp_change_state(sb_dsp_t *dsp, dsp_state_t state) 84 84 { 85 85 assert(dsp); … … 89 89 } 90 90 91 static inline int sb_dsp_read(sb_dsp_t *dsp, uint8_t *data)91 static inline int dsp_read(sb_dsp_t *dsp, uint8_t *data) 92 92 { 93 93 assert(data); … … 106 106 } 107 107 108 static inline int sb_dsp_write(sb_dsp_t *dsp, uint8_t data)108 static inline int dsp_write(sb_dsp_t *dsp, uint8_t data) 109 109 { 110 110 assert(dsp); … … 122 122 } 123 123 124 static inline void sb_dsp_reset(sb_dsp_t *dsp)124 static inline void dsp_reset(sb_dsp_t *dsp) 125 125 { 126 126 assert(dsp); … … 129 129 udelay(3); /* Keep reset for 3 us */ 130 130 pio_write_8(&dsp->regs->dsp_reset, 0); 131 } 132 133 static inline void sb_dsp_start_active(sb_dsp_t *dsp, uint8_t command) 134 { 135 sb_dsp_write(dsp, command); 136 sb_dsp_write(dsp, dsp->active.mode); 137 sb_dsp_write(dsp, (dsp->active.samples - 1) & 0xff); 138 sb_dsp_write(dsp, (dsp->active.samples - 1) >> 8); 139 } 140 141 static inline void sb_dsp_set_sampling_rate(sb_dsp_t *dsp, unsigned rate) 142 { 143 sb_dsp_write(dsp, SET_SAMPLING_RATE_OUTPUT); 144 sb_dsp_write(dsp, rate >> 8); 145 sb_dsp_write(dsp, rate & 0xff); 131 /* "DSP takes about 100 microseconds to initialize itself" */ 132 udelay(100); 133 } 134 135 static inline void dsp_start_current_active(sb_dsp_t *dsp, uint8_t command) 136 { 137 dsp_write(dsp, command); 138 dsp_write(dsp, dsp->active.mode); 139 dsp_write(dsp, (dsp->active.samples - 1) & 0xff); 140 dsp_write(dsp, (dsp->active.samples - 1) >> 8); 141 } 142 143 static inline void dsp_set_sampling_rate(sb_dsp_t *dsp, unsigned rate) 144 { 145 dsp_write(dsp, SET_SAMPLING_RATE_OUTPUT); 146 dsp_write(dsp, rate >> 8); 147 dsp_write(dsp, rate & 0xff); 146 148 ddf_log_verbose("Sampling rate: %hhx:%hhx.", rate >> 8, rate & 0xff); 147 149 } 148 150 149 static inline int sb_setup_dma(sb_dsp_t *dsp, uintptr_t pa, size_t size) 151 static inline void dsp_report_event(sb_dsp_t *dsp, pcm_event_t event) 152 { 153 assert(dsp); 154 if (!dsp->event_exchange) 155 ddf_log_warning("No one listening for event %u", event); 156 async_msg_1(dsp->event_exchange, event, dsp->active.frame_count); 157 } 158 159 static inline int setup_dma(sb_dsp_t *dsp, uintptr_t pa, size_t size) 150 160 { 151 161 async_sess_t *sess = devman_parent_device_connect(EXCHANGE_ATOMIC, … … 160 170 } 161 171 162 static inline int s b_setup_buffer(sb_dsp_t *dsp, size_t size)172 static inline int setup_buffer(sb_dsp_t *dsp, size_t size) 163 173 { 164 174 assert(dsp); … … 177 187 178 188 /* Setup 16 bit channel */ 179 ret = s b_setup_dma(dsp, (uintptr_t)pa, size);189 ret = setup_dma(dsp, (uintptr_t)pa, size); 180 190 if (ret == EOK) { 181 191 dsp->buffer.data = buffer; … … 189 199 } 190 200 191 static inline void dsp_report_event(sb_dsp_t *dsp, pcm_event_t event)192 {193 assert(dsp);194 if (!dsp->event_exchange)195 ddf_log_warning("No one listening for event %u", event);196 async_msg_1(dsp->event_exchange, event, dsp->active.frame_count);197 }198 199 201 static inline size_t sample_count(pcm_sample_format_t format, size_t byte_count) 200 202 { … … 213 215 dsp->sb_dev = dev; 214 216 dsp->state = DSP_NO_BUFFER; 215 sb_dsp_reset(dsp); 216 /* "DSP takes about 100 microseconds to initialize itself" */ 217 udelay(100); 217 dsp_reset(dsp); 218 218 uint8_t response; 219 const int ret = sb_dsp_read(dsp, &response);219 const int ret = dsp_read(dsp, &response); 220 220 if (ret != EOK) { 221 221 ddf_log_error("Failed to read DSP reset response value."); … … 228 228 229 229 /* Get DSP version number */ 230 sb_dsp_write(dsp, DSP_VERSION);231 sb_dsp_read(dsp, &dsp->version.major);232 sb_dsp_read(dsp, &dsp->version.minor);230 dsp_write(dsp, DSP_VERSION); 231 dsp_read(dsp, &dsp->version.major); 232 dsp_read(dsp, &dsp->version.minor); 233 233 234 234 return ret; … … 248 248 case DSP_PLAYBACK_NOEVENTS: 249 249 #ifndef AUTO_DMA_MODE 250 sb_dsp_start_active(dsp, SINGLE_DMA_16B_DA);250 dsp_start_current_active(dsp, SINGLE_DMA_16B_DA); 251 251 #endif 252 252 break; … … 255 255 case DSP_CAPTURE_NOEVENTS: 256 256 #ifndef AUTO_DMA_MODE 257 sb_dsp_start_active(dsp, SINGLE_DMA_16B_DA);257 dsp_start_current_active(dsp, SINGLE_DMA_16B_DA); 258 258 #endif 259 259 break; … … 262 262 async_exchange_end(dsp->event_exchange); 263 263 dsp->event_exchange = NULL; 264 sb_dsp_change_state(dsp, DSP_STOPPED);264 dsp_change_state(dsp, DSP_STOPPED); 265 265 break; 266 266 case DSP_PLAYBACK_TERMINATE: … … 268 268 async_exchange_end(dsp->event_exchange); 269 269 dsp->event_exchange = NULL; 270 sb_dsp_change_state(dsp, DSP_STOPPED);270 dsp_change_state(dsp, DSP_STOPPED); 271 271 break; 272 272 default: … … 367 367 assert(dsp->buffer.data == NULL); 368 368 369 const int ret = s b_setup_buffer(dsp, *size);369 const int ret = setup_buffer(dsp, *size); 370 370 if (ret == EOK) { 371 371 ddf_log_debug("Providing buffer: %p, %zu B.", … … 376 376 if (size) 377 377 *size = dsp->buffer.size; 378 sb_dsp_change_state(dsp, DSP_READY);378 dsp_change_state(dsp, DSP_READY); 379 379 } 380 380 return ret; … … 391 391 dsp->buffer.size = 0; 392 392 ddf_log_debug("DSP buffer released."); 393 sb_dsp_change_state(dsp, DSP_NO_BUFFER);393 dsp_change_state(dsp, DSP_NO_BUFFER); 394 394 return EOK; 395 395 } … … 427 427 dsp->active.frame_count = 0; 428 428 429 sb_dsp_set_sampling_rate(dsp, sampling_rate);429 dsp_set_sampling_rate(dsp, sampling_rate); 430 430 431 431 #ifdef AUTO_DMA_MODE 432 sb_dsp_start_active(dsp, AUTO_DMA_16B_DA_FIFO);432 dsp_start_current_active(dsp, AUTO_DMA_16B_DA_FIFO); 433 433 #else 434 sb_dsp_start_active(dsp, SINGLE_DMA_16B_DA);434 dsp_start_current_active(dsp, SINGLE_DMA_16B_DA); 435 435 #endif 436 436 … … 439 439 sampling_rate / (dsp->active.samples * channels)); 440 440 441 sb_dsp_change_state(dsp,441 dsp_change_state(dsp, 442 442 frames ? DSP_PLAYBACK_ACTIVE_EVENTS : DSP_PLAYBACK_NOEVENTS); 443 443 if (dsp->state == DSP_PLAYBACK_ACTIVE_EVENTS) … … 454 454 immediate) 455 455 { 456 sb_dsp_write(dsp, DMA_16B_PAUSE);457 sb_dsp_reset(dsp);456 dsp_write(dsp, DMA_16B_PAUSE); 457 dsp_reset(dsp); 458 458 ddf_log_debug("Stopped playback"); 459 sb_dsp_change_state(dsp, DSP_STOPPED);459 dsp_change_state(dsp, DSP_STOPPED); 460 460 return EOK; 461 461 } … … 464 464 /* Stop after current fragment */ 465 465 assert(!immediate); 466 sb_dsp_write(dsp, DMA_16B_EXIT);466 dsp_write(dsp, DMA_16B_EXIT); 467 467 ddf_log_debug("Last playback fragment"); 468 sb_dsp_change_state(dsp, DSP_PLAYBACK_TERMINATE);468 dsp_change_state(dsp, DSP_PLAYBACK_TERMINATE); 469 469 return EOK; 470 470 } … … 502 502 dsp->active.frame_count = 0; 503 503 504 sb_dsp_set_sampling_rate(dsp, sampling_rate);504 dsp_set_sampling_rate(dsp, sampling_rate); 505 505 506 506 #ifdef AUTO_DMA_MODE 507 sb_dsp_start_active(dsp, AUTO_DMA_16B_AD_FIFO);507 dsp_start_current_active(dsp, AUTO_DMA_16B_AD_FIFO); 508 508 #else 509 sb_dsp_start_active(dsp, SINGLE_DMA_16B_AD);509 dsp_start_current_active(dsp, SINGLE_DMA_16B_AD); 510 510 #endif 511 511 … … 513 513 "(~1/%u sec)", dsp->active.samples, 514 514 sampling_rate / (dsp->active.samples * channels)); 515 sb_dsp_change_state(dsp,515 dsp_change_state(dsp, 516 516 frames ? DSP_CAPTURE_ACTIVE_EVENTS : DSP_CAPTURE_NOEVENTS); 517 517 if (dsp->state == DSP_CAPTURE_ACTIVE_EVENTS) … … 527 527 immediate) 528 528 { 529 sb_dsp_write(dsp, DMA_16B_PAUSE);530 sb_dsp_reset(dsp);529 dsp_write(dsp, DMA_16B_PAUSE); 530 dsp_reset(dsp); 531 531 ddf_log_debug("Stopped capture fragment"); 532 sb_dsp_change_state(dsp, DSP_STOPPED);532 dsp_change_state(dsp, DSP_STOPPED); 533 533 return EOK; 534 534 } … … 537 537 /* Stop after current fragment */ 538 538 assert(!immediate); 539 sb_dsp_write(dsp, DMA_16B_EXIT);539 dsp_write(dsp, DMA_16B_EXIT); 540 540 ddf_log_debug("Last capture fragment"); 541 sb_dsp_change_state(dsp, DSP_CAPTURE_TERMINATE);541 dsp_change_state(dsp, DSP_CAPTURE_TERMINATE); 542 542 return EOK; 543 543 }
Note:
See TracChangeset
for help on using the changeset viewer.