Harmandeep Singh | c35fa07d | 2012-05-31 07:08:59 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 Code Aurora Forum. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 and |
| 6 | * only version 2 as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | */ |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/fs.h> |
| 16 | #include <linux/miscdevice.h> |
| 17 | #include <linux/uaccess.h> |
| 18 | #include <linux/sched.h> |
| 19 | #include <linux/wait.h> |
| 20 | #include <linux/dma-mapping.h> |
| 21 | #include <linux/slab.h> |
| 22 | #include <asm/atomic.h> |
| 23 | #include <asm/ioctls.h> |
| 24 | #include "audio_utils_aio.h" |
| 25 | |
| 26 | void q6_audio_cb(uint32_t opcode, uint32_t token, |
| 27 | uint32_t *payload, void *priv) |
| 28 | { |
| 29 | struct q6audio_aio *audio = (struct q6audio_aio *)priv; |
| 30 | |
| 31 | pr_debug("%s:opcode = %x token = 0x%x\n", __func__, opcode, token); |
| 32 | switch (opcode) { |
| 33 | case ASM_DATA_EVENT_WRITE_DONE: |
| 34 | case ASM_DATA_EVENT_READ_DONE: |
| 35 | case ASM_DATA_CMDRSP_EOS: |
| 36 | case ASM_DATA_CMD_MEDIA_FORMAT_UPDATE: |
| 37 | case ASM_STREAM_CMD_SET_ENCDEC_PARAM: |
| 38 | case ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY: |
| 39 | case ASM_DATA_EVENT_ENC_SR_CM_NOTIFY: |
Deepa Madiregama | 14e9e76 | 2012-08-29 12:27:41 +0530 | [diff] [blame] | 40 | case APR_BASIC_RSP_RESULT: |
Harmandeep Singh | c35fa07d | 2012-05-31 07:08:59 -0700 | [diff] [blame] | 41 | audio_aio_cb(opcode, token, payload, audio); |
| 42 | break; |
| 43 | default: |
| 44 | pr_debug("%s:Unhandled event = 0x%8x\n", __func__, opcode); |
| 45 | break; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | void audio_aio_cb(uint32_t opcode, uint32_t token, |
| 50 | uint32_t *payload, void *priv) |
| 51 | { |
| 52 | union msm_audio_event_payload e_payload; |
| 53 | struct q6audio_aio *audio = (struct q6audio_aio *)priv; |
| 54 | |
| 55 | switch (opcode) { |
| 56 | case ASM_DATA_EVENT_WRITE_DONE: |
| 57 | pr_debug("%s[%p]:ASM_DATA_EVENT_WRITE_DONE token = 0x%x\n", |
| 58 | __func__, audio, token); |
| 59 | audio_aio_async_write_ack(audio, token, payload); |
| 60 | break; |
| 61 | case ASM_DATA_EVENT_READ_DONE: |
| 62 | pr_debug("%s[%p]:ASM_DATA_EVENT_READ_DONE token = 0x%x\n", |
| 63 | __func__, audio, token); |
| 64 | audio_aio_async_read_ack(audio, token, payload); |
| 65 | break; |
| 66 | case ASM_DATA_CMDRSP_EOS: |
| 67 | /* EOS Handle */ |
| 68 | pr_debug("%s[%p]:ASM_DATA_CMDRSP_EOS\n", __func__, audio); |
| 69 | if (audio->feedback) { /* Non-Tunnel mode */ |
| 70 | audio->eos_rsp = 1; |
| 71 | /* propagate input EOS i/p buffer, |
| 72 | after receiving DSP acknowledgement */ |
| 73 | if (audio->eos_flag && |
| 74 | (audio->eos_write_payload.aio_buf.buf_addr)) { |
| 75 | audio_aio_post_event(audio, |
| 76 | AUDIO_EVENT_WRITE_DONE, |
| 77 | audio->eos_write_payload); |
| 78 | memset(&audio->eos_write_payload , 0, |
| 79 | sizeof(union msm_audio_event_payload)); |
| 80 | audio->eos_flag = 0; |
| 81 | } |
| 82 | } else { /* Tunnel mode */ |
| 83 | audio->eos_rsp = 1; |
| 84 | wake_up(&audio->write_wait); |
| 85 | wake_up(&audio->cmd_wait); |
| 86 | } |
| 87 | break; |
| 88 | case ASM_DATA_CMD_MEDIA_FORMAT_UPDATE: |
| 89 | case ASM_STREAM_CMD_SET_ENCDEC_PARAM: |
| 90 | pr_debug("%s[%p]:payload0[%x] payloa1d[%x]opcode= 0x%x\n", |
| 91 | __func__, audio, payload[0], payload[1], opcode); |
| 92 | break; |
| 93 | case ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY: |
| 94 | case ASM_DATA_EVENT_ENC_SR_CM_NOTIFY: |
| 95 | pr_debug("%s[%p]: ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY, " |
| 96 | |
| 97 | "payload[0]-sr = %d, payload[1]-chl = %d, " |
| 98 | "payload[2] = %d, payload[3] = %d\n", __func__, |
| 99 | audio, payload[0], payload[1], payload[2], |
| 100 | payload[3]); |
Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 101 | pr_debug("%s[%p]: ASM_DATA_EVENT_SR_CM_CHANGE_NOTIFY, sr(prev) = %d, chl(prev) = %d,", |
| 102 | __func__, audio, audio->pcm_cfg.sample_rate, |
Harmandeep Singh | c35fa07d | 2012-05-31 07:08:59 -0700 | [diff] [blame] | 103 | audio->pcm_cfg.channel_count); |
| 104 | audio->pcm_cfg.sample_rate = payload[0]; |
| 105 | audio->pcm_cfg.channel_count = payload[1] & 0xFFFF; |
| 106 | e_payload.stream_info.chan_info = audio->pcm_cfg.channel_count; |
| 107 | e_payload.stream_info.sample_rate = audio->pcm_cfg.sample_rate; |
| 108 | audio_aio_post_event(audio, AUDIO_EVENT_STREAM_INFO, e_payload); |
| 109 | break; |
Deepa Madiregama | 14e9e76 | 2012-08-29 12:27:41 +0530 | [diff] [blame] | 110 | case APR_BASIC_RSP_RESULT: |
| 111 | switch (payload[0]) { |
| 112 | case ASM_STREAM_CMD_CLOSE: |
| 113 | audio_aio_unmap_ion_region(audio); |
| 114 | break; |
| 115 | default: |
| 116 | break; |
| 117 | } |
| 118 | break; |
Harmandeep Singh | c35fa07d | 2012-05-31 07:08:59 -0700 | [diff] [blame] | 119 | default: |
| 120 | break; |
| 121 | } |
| 122 | } |
Harmandeep Singh | eaf59b4 | 2012-06-05 21:46:02 -0700 | [diff] [blame] | 123 | |
| 124 | /* Read buffer from DSP / Handle Ack from DSP */ |
| 125 | void audio_aio_async_read_ack(struct q6audio_aio *audio, uint32_t token, |
| 126 | uint32_t *payload) |
| 127 | { |
| 128 | unsigned long flags; |
| 129 | union msm_audio_event_payload event_payload; |
| 130 | struct audio_aio_buffer_node *filled_buf; |
| 131 | |
| 132 | /* No active flush in progress */ |
| 133 | if (audio->rflush) |
| 134 | return; |
| 135 | |
| 136 | /* Statistics of read */ |
| 137 | atomic_add(payload[2], &audio->in_bytes); |
| 138 | atomic_add(payload[7], &audio->in_samples); |
| 139 | |
| 140 | spin_lock_irqsave(&audio->dsp_lock, flags); |
| 141 | BUG_ON(list_empty(&audio->in_queue)); |
| 142 | filled_buf = list_first_entry(&audio->in_queue, |
| 143 | struct audio_aio_buffer_node, list); |
| 144 | if (token == (filled_buf->token)) { |
| 145 | list_del(&filled_buf->list); |
| 146 | spin_unlock_irqrestore(&audio->dsp_lock, flags); |
| 147 | event_payload.aio_buf = filled_buf->buf; |
| 148 | /* Read done Buffer due to flush/normal condition |
| 149 | after EOS event, so append EOS buffer */ |
| 150 | if (audio->eos_rsp == 0x1) { |
| 151 | event_payload.aio_buf.data_len = |
| 152 | insert_eos_buf(audio, filled_buf); |
| 153 | /* Reset flag back to indicate eos intimated */ |
| 154 | audio->eos_rsp = 0; |
| 155 | } else { |
| 156 | filled_buf->meta_info.meta_out.num_of_frames = |
| 157 | payload[7]; |
| 158 | event_payload.aio_buf.data_len = payload[2] + \ |
| 159 | payload[3] + \ |
| 160 | sizeof(struct dec_meta_out); |
| 161 | pr_debug("%s[%p]:nr of frames 0x%8x len=%d\n", |
| 162 | __func__, audio, |
| 163 | filled_buf->meta_info.meta_out.num_of_frames, |
| 164 | event_payload.aio_buf.data_len); |
| 165 | extract_meta_out_info(audio, filled_buf, 0); |
| 166 | audio->eos_rsp = 0; |
| 167 | } |
| 168 | audio_aio_post_event(audio, AUDIO_EVENT_READ_DONE, |
| 169 | event_payload); |
| 170 | kfree(filled_buf); |
| 171 | } else { |
| 172 | pr_err("%s[%p]:expected=%lx ret=%x\n", |
| 173 | __func__, audio, filled_buf->token, token); |
| 174 | spin_unlock_irqrestore(&audio->dsp_lock, flags); |
| 175 | } |
| 176 | } |