Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* |
| 2 | * aac audio decoder device |
| 3 | * |
| 4 | * Copyright (C) 2008 Google, Inc. |
| 5 | * Copyright (C) 2008 HTC Corporation |
Duy Truong | 790f06d | 2013-02-13 16:38:12 -0800 | [diff] [blame] | 6 | * Copyright (c) 2008-2012, The Linux Foundation. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7 | * |
| 8 | * This software is licensed under the terms of the GNU General Public |
| 9 | * License version 2, as published by the Free Software Foundation, and |
| 10 | * may be copied, distributed, and modified under those terms. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | */ |
| 18 | |
Santosh Mardi | fdc227a | 2011-07-11 17:20:34 +0530 | [diff] [blame] | 19 | #include <asm/atomic.h> |
| 20 | #include <asm/ioctls.h> |
| 21 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 22 | #include <linux/module.h> |
| 23 | #include <linux/fs.h> |
| 24 | #include <linux/miscdevice.h> |
| 25 | #include <linux/uaccess.h> |
| 26 | #include <linux/kthread.h> |
| 27 | #include <linux/wait.h> |
| 28 | #include <linux/dma-mapping.h> |
| 29 | #include <linux/debugfs.h> |
| 30 | #include <linux/delay.h> |
| 31 | #include <linux/list.h> |
| 32 | #include <linux/earlysuspend.h> |
| 33 | #include <linux/android_pmem.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 34 | #include <linux/slab.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 35 | #include <linux/msm_audio_aac.h> |
Santosh Mardi | fdc227a | 2011-07-11 17:20:34 +0530 | [diff] [blame] | 36 | #include <linux/memory_alloc.h> |
| 37 | |
| 38 | #include <mach/msm_adsp.h> |
| 39 | #include <mach/iommu.h> |
| 40 | #include <mach/iommu_domains.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 41 | #include <mach/qdsp5v2/qdsp5audppmsg.h> |
| 42 | #include <mach/qdsp5v2/qdsp5audplaycmdi.h> |
| 43 | #include <mach/qdsp5v2/qdsp5audplaymsg.h> |
| 44 | #include <mach/qdsp5v2/audio_dev_ctl.h> |
| 45 | #include <mach/qdsp5v2/audpp.h> |
| 46 | #include <mach/qdsp5v2/audio_dev_ctl.h> |
| 47 | #include <mach/debug_mm.h> |
Santosh Mardi | fdc227a | 2011-07-11 17:20:34 +0530 | [diff] [blame] | 48 | #include <mach/msm_memtypes.h> |
| 49 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 50 | |
| 51 | #define BUFSZ 32768 |
| 52 | #define DMASZ (BUFSZ * 2) |
| 53 | #define BUFSZ_MIN 4096 |
| 54 | #define DMASZ_MIN (BUFSZ_MIN * 2) |
| 55 | |
| 56 | #define AUDPLAY_INVALID_READ_PTR_OFFSET 0xFFFF |
| 57 | #define AUDDEC_DEC_AAC 5 |
| 58 | |
| 59 | #define PCM_BUFSZ_MIN 9600 /* Hold one stereo AAC frame */ |
| 60 | #define PCM_BUF_MAX_COUNT 5 /* DSP only accepts 5 buffers at most |
| 61 | but support 2 buffers currently */ |
| 62 | #define ROUTING_MODE_FTRT 1 |
| 63 | #define ROUTING_MODE_RT 2 |
| 64 | /* Decoder status received from AUDPPTASK */ |
| 65 | #define AUDPP_DEC_STATUS_SLEEP 0 |
| 66 | #define AUDPP_DEC_STATUS_INIT 1 |
| 67 | #define AUDPP_DEC_STATUS_CFG 2 |
| 68 | #define AUDPP_DEC_STATUS_PLAY 3 |
| 69 | |
| 70 | #define AUDAAC_METAFIELD_MASK 0xFFFF0000 |
| 71 | #define AUDAAC_EOS_FLG_OFFSET 0x0A /* Offset from beginning of buffer */ |
| 72 | #define AUDAAC_EOS_FLG_MASK 0x01 |
| 73 | #define AUDAAC_EOS_NONE 0x0 /* No EOS detected */ |
| 74 | #define AUDAAC_EOS_SET 0x1 /* EOS set in meta field */ |
| 75 | |
| 76 | #define AUDAAC_EVENT_NUM 10 /* Default number of pre-allocated event packets */ |
| 77 | |
| 78 | #define BITSTREAM_ERROR_THRESHOLD_VALUE 0x1 /* DEFAULT THRESHOLD VALUE */ |
| 79 | |
| 80 | struct buffer { |
| 81 | void *data; |
| 82 | unsigned size; |
| 83 | unsigned used; /* Input usage actual DSP produced PCM size */ |
| 84 | unsigned addr; |
| 85 | unsigned short mfield_sz; /*only useful for data has meta field */ |
| 86 | }; |
| 87 | |
| 88 | #ifdef CONFIG_HAS_EARLYSUSPEND |
| 89 | struct audaac_suspend_ctl { |
| 90 | struct early_suspend node; |
| 91 | struct audio *audio; |
| 92 | }; |
| 93 | #endif |
| 94 | |
| 95 | struct audaac_event{ |
| 96 | struct list_head list; |
| 97 | int event_type; |
| 98 | union msm_audio_event_payload payload; |
| 99 | }; |
| 100 | |
| 101 | struct audio { |
| 102 | struct buffer out[2]; |
| 103 | |
| 104 | spinlock_t dsp_lock; |
| 105 | |
| 106 | uint8_t out_head; |
| 107 | uint8_t out_tail; |
| 108 | uint8_t out_needed; /* number of buffers the dsp is waiting for */ |
| 109 | unsigned out_dma_sz; |
| 110 | |
| 111 | atomic_t out_bytes; |
| 112 | |
| 113 | struct mutex lock; |
| 114 | struct mutex write_lock; |
| 115 | wait_queue_head_t write_wait; |
| 116 | |
| 117 | /* Host PCM section */ |
| 118 | struct buffer in[PCM_BUF_MAX_COUNT]; |
| 119 | struct mutex read_lock; |
| 120 | wait_queue_head_t read_wait; /* Wait queue for read */ |
| 121 | char *read_data; /* pointer to reader buffer */ |
| 122 | int32_t read_phys; /* physical address of reader buffer */ |
| 123 | uint8_t read_next; /* index to input buffers to be read next */ |
| 124 | uint8_t fill_next; /* index to buffer that DSP should be filling */ |
| 125 | uint8_t pcm_buf_count; /* number of pcm buffer allocated */ |
| 126 | /* ---- End of Host PCM section */ |
| 127 | |
| 128 | struct msm_adsp_module *audplay; |
| 129 | |
| 130 | /* configuration to use on next enable */ |
| 131 | uint32_t out_sample_rate; |
| 132 | uint32_t out_channel_mode; |
| 133 | struct msm_audio_aac_config aac_config; |
| 134 | |
| 135 | /* AV sync Info */ |
| 136 | int avsync_flag; /* Flag to indicate feedback from DSP */ |
| 137 | wait_queue_head_t avsync_wait;/* Wait queue for AV Sync Message */ |
| 138 | /* 48 bits sample/bytes counter per channel */ |
| 139 | uint16_t avsync[AUDPP_AVSYNC_CH_COUNT * AUDPP_AVSYNC_NUM_WORDS + 1]; |
| 140 | |
| 141 | /* data allocated for various buffers */ |
| 142 | char *data; |
| 143 | int32_t phys; /* physical address of write buffer */ |
Laura Abbott | 6139969 | 2012-04-30 14:25:46 -0700 | [diff] [blame] | 144 | void *map_v_read; |
| 145 | void *map_v_write; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 146 | |
| 147 | int mfield; /* meta field embedded in data */ |
| 148 | int rflush; /* Read flush */ |
| 149 | int wflush; /* Write flush */ |
| 150 | int opened; |
| 151 | int enabled; |
| 152 | int running; |
| 153 | int stopped; /* set when stopped, cleared on flush */ |
| 154 | int pcm_feedback; |
| 155 | int buf_refresh; |
| 156 | int teos; /* valid only if tunnel mode & no data left for decoder */ |
| 157 | enum msm_aud_decoder_state dec_state; /* Represents decoder state */ |
| 158 | int reserved; /* A byte is being reserved */ |
| 159 | char rsv_byte; /* Handle odd length user data */ |
| 160 | |
| 161 | const char *module_name; |
| 162 | unsigned queue_id; |
| 163 | uint16_t dec_id; |
| 164 | uint32_t read_ptr_offset; |
| 165 | int16_t source; |
| 166 | |
| 167 | #ifdef CONFIG_HAS_EARLYSUSPEND |
| 168 | struct audaac_suspend_ctl suspend_ctl; |
| 169 | #endif |
| 170 | |
| 171 | #ifdef CONFIG_DEBUG_FS |
| 172 | struct dentry *dentry; |
| 173 | #endif |
| 174 | |
| 175 | wait_queue_head_t wait; |
| 176 | struct list_head free_event_queue; |
| 177 | struct list_head event_queue; |
| 178 | wait_queue_head_t event_wait; |
| 179 | spinlock_t event_queue_lock; |
| 180 | struct mutex get_event_lock; |
| 181 | int event_abort; |
| 182 | uint32_t device_events; |
| 183 | |
| 184 | struct msm_audio_bitstream_info stream_info; |
| 185 | struct msm_audio_bitstream_error_info bitstream_error_info; |
| 186 | uint32_t bitstream_error_threshold_value; |
| 187 | |
| 188 | int eq_enable; |
| 189 | int eq_needs_commit; |
| 190 | struct audpp_cmd_cfg_object_params_eqalizer eq; |
| 191 | struct audpp_cmd_cfg_object_params_volume vol_pan; |
| 192 | }; |
| 193 | |
| 194 | static int auddec_dsp_config(struct audio *audio, int enable); |
| 195 | static void audpp_cmd_cfg_adec_params(struct audio *audio); |
| 196 | static void audpp_cmd_cfg_routing_mode(struct audio *audio); |
| 197 | static void audplay_send_data(struct audio *audio, unsigned needed); |
| 198 | static void audplay_error_threshold_config(struct audio *audio); |
| 199 | static void audplay_config_hostpcm(struct audio *audio); |
| 200 | static void audplay_buffer_refresh(struct audio *audio); |
| 201 | static void audio_dsp_event(void *private, unsigned id, uint16_t *msg); |
| 202 | static void audaac_post_event(struct audio *audio, int type, |
| 203 | union msm_audio_event_payload payload); |
| 204 | |
| 205 | /* must be called with audio->lock held */ |
| 206 | static int audio_enable(struct audio *audio) |
| 207 | { |
| 208 | MM_DBG("\n"); /* Macro prints the file name and function */ |
| 209 | |
| 210 | if (audio->enabled) |
| 211 | return 0; |
| 212 | |
| 213 | audio->dec_state = MSM_AUD_DECODER_STATE_NONE; |
| 214 | audio->out_tail = 0; |
| 215 | audio->out_needed = 0; |
| 216 | |
| 217 | if (msm_adsp_enable(audio->audplay)) { |
| 218 | MM_ERR("msm_adsp_enable(audplay) failed\n"); |
| 219 | return -ENODEV; |
| 220 | } |
| 221 | |
| 222 | if (audpp_enable(audio->dec_id, audio_dsp_event, audio)) { |
| 223 | MM_ERR("audpp_enable() failed\n"); |
| 224 | msm_adsp_disable(audio->audplay); |
| 225 | return -ENODEV; |
| 226 | } |
| 227 | audio->enabled = 1; |
| 228 | return 0; |
| 229 | } |
| 230 | |
| 231 | static void aac_listner(u32 evt_id, union auddev_evt_data *evt_payload, |
| 232 | void *private_data) |
| 233 | { |
| 234 | struct audio *audio = (struct audio *) private_data; |
| 235 | switch (evt_id) { |
| 236 | case AUDDEV_EVT_DEV_RDY: |
| 237 | MM_DBG(":AUDDEV_EVT_DEV_RDY\n"); |
| 238 | audio->source |= (0x1 << evt_payload->routing_id); |
| 239 | if (audio->running == 1 && audio->enabled == 1) |
| 240 | audpp_route_stream(audio->dec_id, audio->source); |
| 241 | break; |
| 242 | case AUDDEV_EVT_DEV_RLS: |
| 243 | MM_DBG(":AUDDEV_EVT_DEV_RLS\n"); |
| 244 | audio->source &= ~(0x1 << evt_payload->routing_id); |
| 245 | if (audio->running == 1 && audio->enabled == 1) |
| 246 | audpp_route_stream(audio->dec_id, audio->source); |
| 247 | break; |
| 248 | case AUDDEV_EVT_STREAM_VOL_CHG: |
| 249 | audio->vol_pan.volume = evt_payload->session_vol; |
| 250 | MM_DBG(":AUDDEV_EVT_STREAM_VOL_CHG, stream vol %d\n", |
| 251 | audio->vol_pan.volume); |
| 252 | if (audio->running) |
| 253 | audpp_dsp_set_vol_pan(audio->dec_id, &audio->vol_pan, |
| 254 | POPP); |
| 255 | break; |
| 256 | default: |
| 257 | MM_ERR(":ERROR:wrong event\n"); |
| 258 | break; |
| 259 | } |
| 260 | } |
| 261 | /* must be called with audio->lock held */ |
| 262 | static int audio_disable(struct audio *audio) |
| 263 | { |
| 264 | int rc = 0; |
| 265 | MM_DBG("\n"); /* Macro prints the file name and function */ |
| 266 | if (audio->enabled) { |
| 267 | audio->enabled = 0; |
| 268 | audio->dec_state = MSM_AUD_DECODER_STATE_NONE; |
| 269 | auddec_dsp_config(audio, 0); |
| 270 | rc = wait_event_interruptible_timeout(audio->wait, |
| 271 | audio->dec_state != MSM_AUD_DECODER_STATE_NONE, |
| 272 | msecs_to_jiffies(MSM_AUD_DECODER_WAIT_MS)); |
| 273 | if (rc == 0) |
| 274 | rc = -ETIMEDOUT; |
| 275 | else if (audio->dec_state != MSM_AUD_DECODER_STATE_CLOSE) |
| 276 | rc = -EFAULT; |
| 277 | else |
| 278 | rc = 0; |
| 279 | wake_up(&audio->write_wait); |
| 280 | wake_up(&audio->read_wait); |
| 281 | msm_adsp_disable(audio->audplay); |
| 282 | audpp_disable(audio->dec_id, audio); |
| 283 | audio->out_needed = 0; |
| 284 | } |
| 285 | return rc; |
| 286 | } |
| 287 | |
| 288 | /* ------------------- dsp --------------------- */ |
| 289 | static void audio_update_pcm_buf_entry(struct audio *audio, uint32_t *payload) |
| 290 | { |
| 291 | uint8_t index; |
| 292 | unsigned long flags; |
| 293 | |
| 294 | if (audio->rflush) |
| 295 | return; |
| 296 | |
| 297 | spin_lock_irqsave(&audio->dsp_lock, flags); |
| 298 | for (index = 0; index < payload[1]; index++) { |
| 299 | if (audio->in[audio->fill_next].addr == |
| 300 | payload[2 + index * 2]) { |
| 301 | MM_DBG("in[%d] ready\n", audio->fill_next); |
| 302 | audio->in[audio->fill_next].used = |
| 303 | payload[3 + index * 2]; |
| 304 | if ((++audio->fill_next) == audio->pcm_buf_count) |
| 305 | audio->fill_next = 0; |
| 306 | |
| 307 | } else { |
| 308 | MM_ERR("expected=%x ret=%x\n", |
| 309 | audio->in[audio->fill_next].addr, |
| 310 | payload[1 + index * 2]); |
| 311 | break; |
| 312 | } |
| 313 | } |
| 314 | if (audio->in[audio->fill_next].used == 0) { |
| 315 | audplay_buffer_refresh(audio); |
| 316 | } else { |
| 317 | MM_DBG("read cannot keep up\n"); |
| 318 | audio->buf_refresh = 1; |
| 319 | } |
| 320 | wake_up(&audio->read_wait); |
| 321 | spin_unlock_irqrestore(&audio->dsp_lock, flags); |
| 322 | |
| 323 | } |
| 324 | |
| 325 | static void audaac_bitstream_error_info(struct audio *audio, uint32_t *payload) |
| 326 | { |
| 327 | unsigned long flags; |
| 328 | union msm_audio_event_payload e_payload; |
| 329 | |
| 330 | if (payload[0] != AUDDEC_DEC_AAC) { |
| 331 | MM_ERR("Unexpected bitstream error info from DSP:\ |
| 332 | Invalid decoder\n"); |
| 333 | return; |
| 334 | } |
| 335 | |
| 336 | /* get stream info from DSP msg */ |
| 337 | spin_lock_irqsave(&audio->dsp_lock, flags); |
| 338 | |
| 339 | audio->bitstream_error_info.dec_id = payload[0]; |
| 340 | audio->bitstream_error_info.err_msg_indicator = payload[1]; |
| 341 | audio->bitstream_error_info.err_type = payload[2]; |
| 342 | |
| 343 | spin_unlock_irqrestore(&audio->dsp_lock, flags); |
| 344 | MM_ERR("bit_stream_error_type=%d error_count=%d\n", |
| 345 | audio->bitstream_error_info.err_type, (0x0000FFFF & |
| 346 | audio->bitstream_error_info.err_msg_indicator)); |
| 347 | |
| 348 | /* send event to ARM to notify error info coming */ |
| 349 | e_payload.error_info = audio->bitstream_error_info; |
| 350 | audaac_post_event(audio, AUDIO_EVENT_BITSTREAM_ERROR_INFO, e_payload); |
| 351 | } |
| 352 | |
| 353 | static void audaac_update_stream_info(struct audio *audio, uint32_t *payload) |
| 354 | { |
| 355 | unsigned long flags; |
| 356 | union msm_audio_event_payload e_payload; |
| 357 | |
| 358 | /* get stream info from DSP msg */ |
| 359 | spin_lock_irqsave(&audio->dsp_lock, flags); |
| 360 | |
| 361 | audio->stream_info.codec_type = AUDIO_CODEC_TYPE_AAC; |
| 362 | audio->stream_info.chan_info = (0x0000FFFF & payload[1]); |
| 363 | audio->stream_info.sample_rate = (0x0000FFFF & payload[2]); |
| 364 | audio->stream_info.bit_stream_info = (0x0000FFFF & payload[3]); |
| 365 | audio->stream_info.bit_rate = payload[4]; |
| 366 | |
| 367 | spin_unlock_irqrestore(&audio->dsp_lock, flags); |
| 368 | MM_DBG("chan_info=%d, sample_rate=%d, bit_stream_info=%d\n", |
| 369 | audio->stream_info.chan_info, |
| 370 | audio->stream_info.sample_rate, |
| 371 | audio->stream_info.bit_stream_info); |
| 372 | |
| 373 | /* send event to ARM to notify steam info coming */ |
| 374 | e_payload.stream_info = audio->stream_info; |
| 375 | audaac_post_event(audio, AUDIO_EVENT_STREAM_INFO, e_payload); |
| 376 | } |
| 377 | static void audplay_dsp_event(void *data, unsigned id, size_t len, |
| 378 | void (*getevent) (void *ptr, size_t len)) |
| 379 | { |
| 380 | struct audio *audio = data; |
| 381 | uint32_t msg[28]; |
| 382 | getevent(msg, sizeof(msg)); |
| 383 | |
| 384 | MM_DBG("msg_id=%x\n", id); |
| 385 | |
| 386 | switch (id) { |
| 387 | case AUDPLAY_MSG_DEC_NEEDS_DATA: |
| 388 | audplay_send_data(audio, 1); |
| 389 | break; |
| 390 | |
| 391 | case AUDPLAY_MSG_BUFFER_UPDATE: |
| 392 | audio_update_pcm_buf_entry(audio, msg); |
| 393 | break; |
| 394 | |
| 395 | case AUDPLAY_UP_STREAM_INFO: |
| 396 | if ((msg[1] & AUDPLAY_STREAM_INFO_MSG_MASK) == |
| 397 | AUDPLAY_STREAM_INFO_MSG_MASK) { |
| 398 | audaac_bitstream_error_info(audio, msg); |
| 399 | } else { |
| 400 | audaac_update_stream_info(audio, msg); |
| 401 | } |
| 402 | break; |
| 403 | |
| 404 | case AUDPLAY_UP_OUTPORT_FLUSH_ACK: |
| 405 | MM_DBG("OUTPORT_FLUSH_ACK\n"); |
| 406 | audio->rflush = 0; |
| 407 | wake_up(&audio->read_wait); |
| 408 | if (audio->pcm_feedback) |
| 409 | audplay_buffer_refresh(audio); |
| 410 | break; |
| 411 | |
| 412 | case ADSP_MESSAGE_ID: |
| 413 | MM_DBG("Received ADSP event: module enable(audplaytask)\n"); |
| 414 | break; |
| 415 | |
| 416 | default: |
| 417 | MM_ERR("unexpected message from decoder \n"); |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | static void audio_dsp_event(void *private, unsigned id, uint16_t *msg) |
| 422 | { |
| 423 | struct audio *audio = private; |
| 424 | |
| 425 | switch (id) { |
| 426 | case AUDPP_MSG_STATUS_MSG:{ |
| 427 | unsigned status = msg[1]; |
| 428 | |
| 429 | switch (status) { |
| 430 | case AUDPP_DEC_STATUS_SLEEP: { |
| 431 | uint16_t reason = msg[2]; |
| 432 | MM_DBG("decoder status: sleep reason = \ |
| 433 | 0x%04x\n", reason); |
| 434 | if ((reason == AUDPP_MSG_REASON_MEM) |
| 435 | || (reason == |
| 436 | AUDPP_MSG_REASON_NODECODER)) { |
| 437 | audio->dec_state = |
| 438 | MSM_AUD_DECODER_STATE_FAILURE; |
| 439 | wake_up(&audio->wait); |
| 440 | } else if (reason == AUDPP_MSG_REASON_NONE) { |
| 441 | /* decoder is in disable state */ |
| 442 | audio->dec_state = |
| 443 | MSM_AUD_DECODER_STATE_CLOSE; |
| 444 | wake_up(&audio->wait); |
| 445 | } |
| 446 | break; |
| 447 | } |
| 448 | case AUDPP_DEC_STATUS_INIT: |
| 449 | MM_DBG("decoder status: init \n"); |
| 450 | if (audio->pcm_feedback) |
| 451 | audpp_cmd_cfg_routing_mode(audio); |
| 452 | else |
| 453 | audpp_cmd_cfg_adec_params(audio); |
| 454 | break; |
| 455 | |
| 456 | case AUDPP_DEC_STATUS_CFG: |
| 457 | MM_DBG("decoder status: cfg \n"); |
| 458 | break; |
| 459 | case AUDPP_DEC_STATUS_PLAY: |
| 460 | MM_DBG("decoder status: play \n"); |
| 461 | /* send mixer command */ |
| 462 | audpp_route_stream(audio->dec_id, |
| 463 | audio->source); |
| 464 | if (audio->pcm_feedback) { |
| 465 | audplay_error_threshold_config(audio); |
| 466 | audplay_config_hostpcm(audio); |
| 467 | audplay_buffer_refresh(audio); |
| 468 | } |
| 469 | audio->dec_state = |
| 470 | MSM_AUD_DECODER_STATE_SUCCESS; |
| 471 | wake_up(&audio->wait); |
| 472 | break; |
| 473 | default: |
| 474 | MM_ERR("unknown decoder status \n"); |
| 475 | } |
| 476 | break; |
| 477 | } |
| 478 | case AUDPP_MSG_CFG_MSG: |
| 479 | if (msg[0] == AUDPP_MSG_ENA_ENA) { |
| 480 | MM_DBG("CFG_MSG ENABLE\n"); |
| 481 | auddec_dsp_config(audio, 1); |
| 482 | audio->out_needed = 0; |
| 483 | audio->running = 1; |
| 484 | audpp_dsp_set_vol_pan(audio->dec_id, &audio->vol_pan, |
| 485 | POPP); |
| 486 | audpp_dsp_set_eq(audio->dec_id, audio->eq_enable, |
| 487 | &audio->eq, POPP); |
| 488 | } else if (msg[0] == AUDPP_MSG_ENA_DIS) { |
| 489 | MM_DBG("CFG_MSG DISABLE\n"); |
| 490 | audio->running = 0; |
| 491 | } else { |
| 492 | MM_DBG("CFG_MSG %d?\n", msg[0]); |
| 493 | } |
| 494 | break; |
| 495 | case AUDPP_MSG_ROUTING_ACK: |
| 496 | MM_DBG("ROUTING_ACK mode=%d\n", msg[1]); |
| 497 | audpp_cmd_cfg_adec_params(audio); |
| 498 | break; |
| 499 | |
| 500 | case AUDPP_MSG_FLUSH_ACK: |
| 501 | MM_DBG("FLUSH_ACK\n"); |
| 502 | audio->wflush = 0; |
| 503 | audio->rflush = 0; |
| 504 | wake_up(&audio->write_wait); |
| 505 | if (audio->pcm_feedback) |
| 506 | audplay_buffer_refresh(audio); |
| 507 | break; |
| 508 | |
| 509 | case AUDPP_MSG_PCMDMAMISSED: |
| 510 | MM_DBG("PCMDMAMISSED\n"); |
| 511 | audio->teos = 1; |
| 512 | wake_up(&audio->write_wait); |
| 513 | break; |
| 514 | |
| 515 | case AUDPP_MSG_AVSYNC_MSG: |
| 516 | MM_DBG("AUDPP_MSG_AVSYNC_MSG\n"); |
| 517 | memcpy(&audio->avsync[0], msg, sizeof(audio->avsync)); |
| 518 | audio->avsync_flag = 1; |
| 519 | wake_up(&audio->avsync_wait); |
| 520 | break; |
| 521 | |
| 522 | default: |
| 523 | MM_ERR("UNKNOWN (%d)\n", id); |
| 524 | } |
| 525 | |
| 526 | } |
| 527 | |
| 528 | struct msm_adsp_ops audplay_adsp_ops_aac = { |
| 529 | .event = audplay_dsp_event, |
| 530 | }; |
| 531 | |
| 532 | #define audplay_send_queue0(audio, cmd, len) \ |
| 533 | msm_adsp_write(audio->audplay, audio->queue_id,\ |
| 534 | cmd, len) |
| 535 | |
| 536 | static int auddec_dsp_config(struct audio *audio, int enable) |
| 537 | { |
| 538 | struct audpp_cmd_cfg_dec_type cfg_dec_cmd; |
| 539 | |
| 540 | memset(&cfg_dec_cmd, 0, sizeof(cfg_dec_cmd)); |
| 541 | |
| 542 | cfg_dec_cmd.cmd_id = AUDPP_CMD_CFG_DEC_TYPE; |
| 543 | if (enable) |
| 544 | cfg_dec_cmd.dec_cfg = AUDPP_CMD_UPDATDE_CFG_DEC | |
| 545 | AUDPP_CMD_ENA_DEC_V | AUDDEC_DEC_AAC; |
| 546 | else |
| 547 | cfg_dec_cmd.dec_cfg = AUDPP_CMD_UPDATDE_CFG_DEC | |
| 548 | AUDPP_CMD_DIS_DEC_V; |
| 549 | cfg_dec_cmd.dm_mode = 0x0; |
| 550 | cfg_dec_cmd.stream_id = audio->dec_id; |
| 551 | |
| 552 | return audpp_send_queue1(&cfg_dec_cmd, sizeof(cfg_dec_cmd)); |
| 553 | } |
| 554 | |
| 555 | static void audpp_cmd_cfg_adec_params(struct audio *audio) |
| 556 | { |
| 557 | struct audpp_cmd_cfg_adec_params_aac cmd; |
| 558 | |
| 559 | memset(&cmd, 0, sizeof(cmd)); |
| 560 | cmd.common.cmd_id = AUDPP_CMD_CFG_ADEC_PARAMS; |
| 561 | cmd.common.length = AUDPP_CMD_CFG_ADEC_PARAMS_AAC_LEN; |
| 562 | cmd.common.dec_id = audio->dec_id; |
| 563 | cmd.common.input_sampling_frequency = audio->out_sample_rate; |
| 564 | cmd.format = audio->aac_config.format; |
| 565 | cmd.audio_object = audio->aac_config.audio_object; |
| 566 | cmd.ep_config = audio->aac_config.ep_config; |
| 567 | cmd.aac_section_data_resilience_flag = |
| 568 | audio->aac_config.aac_section_data_resilience_flag; |
| 569 | cmd.aac_scalefactor_data_resilience_flag = |
| 570 | audio->aac_config.aac_scalefactor_data_resilience_flag; |
| 571 | cmd.aac_spectral_data_resilience_flag = |
| 572 | audio->aac_config.aac_spectral_data_resilience_flag; |
| 573 | cmd.sbr_on_flag = audio->aac_config.sbr_on_flag; |
| 574 | cmd.sbr_ps_on_flag = audio->aac_config.sbr_ps_on_flag; |
| 575 | cmd.channel_configuration = audio->aac_config.channel_configuration; |
| 576 | |
| 577 | audpp_send_queue2(&cmd, sizeof(cmd)); |
| 578 | } |
| 579 | |
| 580 | static void audpp_cmd_cfg_routing_mode(struct audio *audio) |
| 581 | { |
| 582 | struct audpp_cmd_routing_mode cmd; |
| 583 | MM_DBG("\n"); /* Macro prints the file name and function */ |
| 584 | memset(&cmd, 0, sizeof(cmd)); |
| 585 | cmd.cmd_id = AUDPP_CMD_ROUTING_MODE; |
| 586 | cmd.object_number = audio->dec_id; |
| 587 | if (audio->pcm_feedback) |
| 588 | cmd.routing_mode = ROUTING_MODE_FTRT; |
| 589 | else |
| 590 | cmd.routing_mode = ROUTING_MODE_RT; |
| 591 | |
| 592 | audpp_send_queue1(&cmd, sizeof(cmd)); |
| 593 | } |
| 594 | |
| 595 | static int audplay_dsp_send_data_avail(struct audio *audio, |
| 596 | unsigned idx, unsigned len) |
| 597 | { |
| 598 | struct audplay_cmd_bitstream_data_avail_nt2 cmd; |
| 599 | |
| 600 | cmd.cmd_id = AUDPLAY_CMD_BITSTREAM_DATA_AVAIL_NT2; |
| 601 | if (audio->mfield) |
| 602 | cmd.decoder_id = AUDAAC_METAFIELD_MASK | |
| 603 | (audio->out[idx].mfield_sz >> 1); |
| 604 | else |
| 605 | cmd.decoder_id = audio->dec_id; |
| 606 | cmd.buf_ptr = audio->out[idx].addr; |
| 607 | cmd.buf_size = len / 2; |
| 608 | cmd.partition_number = 0; |
| 609 | return audplay_send_queue0(audio, &cmd, sizeof(cmd)); |
| 610 | } |
| 611 | |
| 612 | static void audplay_buffer_refresh(struct audio *audio) |
| 613 | { |
| 614 | struct audplay_cmd_buffer_refresh refresh_cmd; |
| 615 | |
| 616 | refresh_cmd.cmd_id = AUDPLAY_CMD_BUFFER_REFRESH; |
| 617 | refresh_cmd.num_buffers = 1; |
| 618 | refresh_cmd.buf0_address = audio->in[audio->fill_next].addr; |
| 619 | /* AAC frame size */ |
| 620 | refresh_cmd.buf0_length = audio->in[audio->fill_next].size - |
| 621 | (audio->in[audio->fill_next].size % 1024) |
| 622 | + (audio->mfield ? 24 : 0); |
| 623 | refresh_cmd.buf_read_count = 0; |
| 624 | MM_DBG("buf0_addr=%x buf0_len=%d\n", refresh_cmd.buf0_address, |
| 625 | refresh_cmd.buf0_length); |
| 626 | (void)audplay_send_queue0(audio, &refresh_cmd, sizeof(refresh_cmd)); |
| 627 | } |
| 628 | |
| 629 | static void audplay_outport_flush(struct audio *audio) |
| 630 | { |
| 631 | struct audplay_cmd_outport_flush op_flush_cmd; |
| 632 | |
| 633 | MM_DBG("\n"); /* Macro prints the file name and function */ |
| 634 | op_flush_cmd.cmd_id = AUDPLAY_CMD_OUTPORT_FLUSH; |
| 635 | (void)audplay_send_queue0(audio, &op_flush_cmd, sizeof(op_flush_cmd)); |
| 636 | } |
| 637 | |
| 638 | static void audplay_error_threshold_config(struct audio *audio) |
| 639 | { |
| 640 | union audplay_cmd_channel_info ch_cfg_cmd; |
| 641 | |
| 642 | MM_DBG("\n"); /* Macro prints the file name and function */ |
| 643 | ch_cfg_cmd.thr_update.cmd_id = AUDPLAY_CMD_CHANNEL_INFO; |
| 644 | ch_cfg_cmd.thr_update.threshold_update = AUDPLAY_ERROR_THRESHOLD_ENABLE; |
| 645 | ch_cfg_cmd.thr_update.threshold_value = |
| 646 | audio->bitstream_error_threshold_value; |
| 647 | (void)audplay_send_queue0(audio, &ch_cfg_cmd, sizeof(ch_cfg_cmd)); |
| 648 | } |
| 649 | |
| 650 | static void audplay_config_hostpcm(struct audio *audio) |
| 651 | { |
| 652 | struct audplay_cmd_hpcm_buf_cfg cfg_cmd; |
| 653 | |
| 654 | MM_DBG("\n"); /* Macro prints the file name and function */ |
| 655 | cfg_cmd.cmd_id = AUDPLAY_CMD_HPCM_BUF_CFG; |
| 656 | cfg_cmd.max_buffers = audio->pcm_buf_count; |
| 657 | cfg_cmd.byte_swap = 0; |
| 658 | cfg_cmd.hostpcm_config = (0x8000) | (0x4000); |
| 659 | cfg_cmd.feedback_frequency = 1; |
| 660 | cfg_cmd.partition_number = 0; |
| 661 | (void)audplay_send_queue0(audio, &cfg_cmd, sizeof(cfg_cmd)); |
| 662 | |
| 663 | } |
| 664 | |
| 665 | static void audplay_send_data(struct audio *audio, unsigned needed) |
| 666 | { |
| 667 | struct buffer *frame; |
| 668 | unsigned long flags; |
| 669 | |
| 670 | spin_lock_irqsave(&audio->dsp_lock, flags); |
| 671 | if (!audio->running) |
| 672 | goto done; |
| 673 | |
| 674 | if (needed && !audio->wflush) { |
| 675 | /* We were called from the callback because the DSP |
| 676 | * requested more data. Note that the DSP does want |
| 677 | * more data, and if a buffer was in-flight, mark it |
| 678 | * as available (since the DSP must now be done with |
| 679 | * it). |
| 680 | */ |
| 681 | audio->out_needed = 1; |
| 682 | frame = audio->out + audio->out_tail; |
| 683 | if (frame->used == 0xffffffff) { |
| 684 | MM_DBG("frame %d free\n", audio->out_tail); |
| 685 | frame->used = 0; |
| 686 | audio->out_tail ^= 1; |
| 687 | wake_up(&audio->write_wait); |
| 688 | } |
| 689 | } |
| 690 | |
| 691 | if (audio->out_needed) { |
| 692 | /* If the DSP currently wants data and we have a |
| 693 | * buffer available, we will send it and reset |
| 694 | * the needed flag. We'll mark the buffer as in-flight |
| 695 | * so that it won't be recycled until the next buffer |
| 696 | * is requested |
| 697 | */ |
| 698 | |
| 699 | frame = audio->out + audio->out_tail; |
| 700 | if (frame->used) { |
| 701 | BUG_ON(frame->used == 0xffffffff); |
| 702 | MM_DBG("frame %d busy\n", audio->out_tail); |
| 703 | audplay_dsp_send_data_avail(audio, audio->out_tail, |
| 704 | frame->used); |
| 705 | frame->used = 0xffffffff; |
| 706 | audio->out_needed = 0; |
| 707 | } |
| 708 | } |
| 709 | done: |
| 710 | spin_unlock_irqrestore(&audio->dsp_lock, flags); |
| 711 | } |
| 712 | |
| 713 | /* ------------------- device --------------------- */ |
| 714 | |
| 715 | static void audio_flush(struct audio *audio) |
| 716 | { |
| 717 | audio->out[0].used = 0; |
| 718 | audio->out[1].used = 0; |
| 719 | audio->out_head = 0; |
| 720 | audio->out_tail = 0; |
| 721 | audio->reserved = 0; |
| 722 | audio->out_needed = 0; |
| 723 | atomic_set(&audio->out_bytes, 0); |
| 724 | } |
| 725 | |
| 726 | static void audio_flush_pcm_buf(struct audio *audio) |
| 727 | { |
| 728 | uint8_t index; |
| 729 | |
| 730 | for (index = 0; index < PCM_BUF_MAX_COUNT; index++) |
| 731 | audio->in[index].used = 0; |
| 732 | audio->buf_refresh = 0; |
| 733 | audio->read_next = 0; |
| 734 | audio->fill_next = 0; |
| 735 | } |
| 736 | |
| 737 | static int audaac_validate_usr_config(struct msm_audio_aac_config *config) |
| 738 | { |
| 739 | int ret_val = -1; |
| 740 | |
| 741 | if (config->format != AUDIO_AAC_FORMAT_ADTS && |
| 742 | config->format != AUDIO_AAC_FORMAT_RAW && |
| 743 | config->format != AUDIO_AAC_FORMAT_PSUEDO_RAW && |
| 744 | config->format != AUDIO_AAC_FORMAT_LOAS) |
| 745 | goto done; |
| 746 | |
| 747 | if (config->audio_object != AUDIO_AAC_OBJECT_LC && |
| 748 | config->audio_object != AUDIO_AAC_OBJECT_LTP && |
| 749 | config->audio_object != AUDIO_AAC_OBJECT_BSAC && |
| 750 | config->audio_object != AUDIO_AAC_OBJECT_ERLC) |
| 751 | goto done; |
| 752 | |
| 753 | if (config->audio_object == AUDIO_AAC_OBJECT_ERLC) { |
| 754 | if (config->ep_config > 3) |
| 755 | goto done; |
| 756 | if (config->aac_scalefactor_data_resilience_flag != |
| 757 | AUDIO_AAC_SCA_DATA_RES_OFF && |
| 758 | config->aac_scalefactor_data_resilience_flag != |
| 759 | AUDIO_AAC_SCA_DATA_RES_ON) |
| 760 | goto done; |
| 761 | if (config->aac_section_data_resilience_flag != |
| 762 | AUDIO_AAC_SEC_DATA_RES_OFF && |
| 763 | config->aac_section_data_resilience_flag != |
| 764 | AUDIO_AAC_SEC_DATA_RES_ON) |
| 765 | goto done; |
| 766 | if (config->aac_spectral_data_resilience_flag != |
| 767 | AUDIO_AAC_SPEC_DATA_RES_OFF && |
| 768 | config->aac_spectral_data_resilience_flag != |
| 769 | AUDIO_AAC_SPEC_DATA_RES_ON) |
| 770 | goto done; |
| 771 | } else { |
| 772 | config->aac_section_data_resilience_flag = |
| 773 | AUDIO_AAC_SEC_DATA_RES_OFF; |
| 774 | config->aac_scalefactor_data_resilience_flag = |
| 775 | AUDIO_AAC_SCA_DATA_RES_OFF; |
| 776 | config->aac_spectral_data_resilience_flag = |
| 777 | AUDIO_AAC_SPEC_DATA_RES_OFF; |
| 778 | } |
| 779 | |
| 780 | #ifndef CONFIG_AUDIO_AAC_PLUS |
| 781 | if (AUDIO_AAC_SBR_ON_FLAG_OFF != config->sbr_on_flag) |
| 782 | goto done; |
| 783 | #else |
| 784 | if (config->sbr_on_flag != AUDIO_AAC_SBR_ON_FLAG_OFF && |
| 785 | config->sbr_on_flag != AUDIO_AAC_SBR_ON_FLAG_ON) |
| 786 | goto done; |
| 787 | #endif |
| 788 | |
| 789 | #ifndef CONFIG_AUDIO_ENHANCED_AAC_PLUS |
| 790 | if (AUDIO_AAC_SBR_PS_ON_FLAG_OFF != config->sbr_ps_on_flag) |
| 791 | goto done; |
| 792 | #else |
| 793 | if (config->sbr_ps_on_flag != AUDIO_AAC_SBR_PS_ON_FLAG_OFF && |
| 794 | config->sbr_ps_on_flag != AUDIO_AAC_SBR_PS_ON_FLAG_ON) |
| 795 | goto done; |
| 796 | #endif |
| 797 | |
| 798 | if (config->dual_mono_mode > AUDIO_AAC_DUAL_MONO_PL_SR) |
| 799 | goto done; |
| 800 | |
| 801 | if (config->channel_configuration > 2) |
| 802 | goto done; |
| 803 | |
| 804 | ret_val = 0; |
| 805 | done: |
| 806 | return ret_val; |
| 807 | } |
| 808 | |
| 809 | static void audio_ioport_reset(struct audio *audio) |
| 810 | { |
| 811 | /* Make sure read/write thread are free from |
| 812 | * sleep and knowing that system is not able |
| 813 | * to process io request at the moment |
| 814 | */ |
| 815 | wake_up(&audio->write_wait); |
| 816 | mutex_lock(&audio->write_lock); |
| 817 | audio_flush(audio); |
| 818 | mutex_unlock(&audio->write_lock); |
| 819 | wake_up(&audio->read_wait); |
| 820 | mutex_lock(&audio->read_lock); |
| 821 | audio_flush_pcm_buf(audio); |
| 822 | mutex_unlock(&audio->read_lock); |
| 823 | audio->avsync_flag = 1; |
| 824 | wake_up(&audio->avsync_wait); |
| 825 | |
| 826 | } |
| 827 | |
| 828 | static int audaac_events_pending(struct audio *audio) |
| 829 | { |
| 830 | unsigned long flags; |
| 831 | int empty; |
| 832 | |
| 833 | spin_lock_irqsave(&audio->event_queue_lock, flags); |
| 834 | empty = !list_empty(&audio->event_queue); |
| 835 | spin_unlock_irqrestore(&audio->event_queue_lock, flags); |
| 836 | return empty || audio->event_abort; |
| 837 | } |
| 838 | |
| 839 | static void audaac_reset_event_queue(struct audio *audio) |
| 840 | { |
| 841 | unsigned long flags; |
| 842 | struct audaac_event *drv_evt; |
| 843 | struct list_head *ptr, *next; |
| 844 | |
| 845 | spin_lock_irqsave(&audio->event_queue_lock, flags); |
| 846 | list_for_each_safe(ptr, next, &audio->event_queue) { |
| 847 | drv_evt = list_first_entry(&audio->event_queue, |
| 848 | struct audaac_event, list); |
| 849 | list_del(&drv_evt->list); |
| 850 | kfree(drv_evt); |
| 851 | } |
| 852 | list_for_each_safe(ptr, next, &audio->free_event_queue) { |
| 853 | drv_evt = list_first_entry(&audio->free_event_queue, |
| 854 | struct audaac_event, list); |
| 855 | list_del(&drv_evt->list); |
| 856 | kfree(drv_evt); |
| 857 | } |
| 858 | spin_unlock_irqrestore(&audio->event_queue_lock, flags); |
| 859 | |
| 860 | return; |
| 861 | } |
| 862 | |
| 863 | static long audaac_process_event_req(struct audio *audio, void __user *arg) |
| 864 | { |
| 865 | long rc; |
| 866 | struct msm_audio_event usr_evt; |
| 867 | struct audaac_event *drv_evt = NULL; |
| 868 | int timeout; |
| 869 | unsigned long flags; |
| 870 | |
| 871 | if (copy_from_user(&usr_evt, arg, sizeof(struct msm_audio_event))) |
| 872 | return -EFAULT; |
| 873 | |
| 874 | timeout = (int) usr_evt.timeout_ms; |
| 875 | |
| 876 | if (timeout > 0) { |
| 877 | rc = wait_event_interruptible_timeout( |
| 878 | audio->event_wait, audaac_events_pending(audio), |
| 879 | msecs_to_jiffies(timeout)); |
| 880 | if (rc == 0) |
| 881 | return -ETIMEDOUT; |
| 882 | } else { |
| 883 | rc = wait_event_interruptible( |
| 884 | audio->event_wait, audaac_events_pending(audio)); |
| 885 | } |
| 886 | |
| 887 | if (rc < 0) |
| 888 | return rc; |
| 889 | |
| 890 | if (audio->event_abort) { |
| 891 | audio->event_abort = 0; |
| 892 | return -ENODEV; |
| 893 | } |
| 894 | |
| 895 | rc = 0; |
| 896 | |
| 897 | spin_lock_irqsave(&audio->event_queue_lock, flags); |
| 898 | if (!list_empty(&audio->event_queue)) { |
| 899 | drv_evt = list_first_entry(&audio->event_queue, |
| 900 | struct audaac_event, list); |
| 901 | list_del(&drv_evt->list); |
| 902 | } |
| 903 | if (drv_evt) { |
| 904 | usr_evt.event_type = drv_evt->event_type; |
| 905 | usr_evt.event_payload = drv_evt->payload; |
| 906 | list_add_tail(&drv_evt->list, &audio->free_event_queue); |
| 907 | } else |
| 908 | rc = -1; |
| 909 | spin_unlock_irqrestore(&audio->event_queue_lock, flags); |
| 910 | |
| 911 | if (!rc && copy_to_user(arg, &usr_evt, sizeof(usr_evt))) |
| 912 | rc = -EFAULT; |
| 913 | |
| 914 | return rc; |
| 915 | } |
| 916 | |
| 917 | static int audio_enable_eq(struct audio *audio, int enable) |
| 918 | { |
| 919 | if (audio->eq_enable == enable && !audio->eq_needs_commit) |
| 920 | return 0; |
| 921 | |
| 922 | audio->eq_enable = enable; |
| 923 | |
| 924 | if (audio->running) { |
| 925 | audpp_dsp_set_eq(audio->dec_id, enable, &audio->eq, POPP); |
| 926 | audio->eq_needs_commit = 0; |
| 927 | } |
| 928 | return 0; |
| 929 | } |
| 930 | |
| 931 | static int audio_get_avsync_data(struct audio *audio, |
| 932 | struct msm_audio_stats *stats) |
| 933 | { |
| 934 | int rc = -EINVAL; |
| 935 | unsigned long flags; |
| 936 | |
| 937 | local_irq_save(flags); |
| 938 | if (audio->dec_id == audio->avsync[0] && audio->avsync_flag) { |
| 939 | /* av_sync sample count */ |
| 940 | stats->sample_count = (audio->avsync[2] << 16) | |
| 941 | (audio->avsync[3]); |
| 942 | |
| 943 | /* av_sync byte_count */ |
| 944 | stats->byte_count = (audio->avsync[5] << 16) | |
| 945 | (audio->avsync[6]); |
| 946 | |
| 947 | audio->avsync_flag = 0; |
| 948 | rc = 0; |
| 949 | } |
| 950 | local_irq_restore(flags); |
| 951 | return rc; |
| 952 | |
| 953 | } |
| 954 | |
| 955 | static long audio_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
| 956 | { |
| 957 | struct audio *audio = file->private_data; |
| 958 | int rc = -EINVAL; |
| 959 | unsigned long flags = 0; |
| 960 | uint16_t enable_mask; |
| 961 | int enable; |
| 962 | int prev_state; |
| 963 | |
| 964 | MM_DBG("cmd = %d\n", cmd); |
| 965 | |
| 966 | if (cmd == AUDIO_GET_STATS) { |
| 967 | struct msm_audio_stats stats; |
| 968 | |
| 969 | audio->avsync_flag = 0; |
| 970 | memset(&stats, 0, sizeof(stats)); |
| 971 | if (audpp_query_avsync(audio->dec_id) < 0) |
| 972 | return rc; |
| 973 | |
| 974 | rc = wait_event_interruptible_timeout(audio->avsync_wait, |
| 975 | (audio->avsync_flag == 1), |
| 976 | msecs_to_jiffies(AUDPP_AVSYNC_EVENT_TIMEOUT)); |
| 977 | |
| 978 | if (rc < 0) |
| 979 | return rc; |
| 980 | else if ((rc > 0) || ((rc == 0) && (audio->avsync_flag == 1))) { |
| 981 | if (audio_get_avsync_data(audio, &stats) < 0) |
| 982 | return rc; |
| 983 | |
| 984 | if (copy_to_user((void *)arg, &stats, sizeof(stats))) |
| 985 | return -EFAULT; |
| 986 | return 0; |
| 987 | } else |
| 988 | return -EAGAIN; |
| 989 | } |
| 990 | |
| 991 | switch (cmd) { |
| 992 | case AUDIO_ENABLE_AUDPP: |
| 993 | if (copy_from_user(&enable_mask, (void *) arg, |
| 994 | sizeof(enable_mask))) { |
| 995 | rc = -EFAULT; |
| 996 | break; |
| 997 | } |
| 998 | |
| 999 | spin_lock_irqsave(&audio->dsp_lock, flags); |
| 1000 | enable = (enable_mask & EQ_ENABLE) ? 1 : 0; |
| 1001 | audio_enable_eq(audio, enable); |
| 1002 | spin_unlock_irqrestore(&audio->dsp_lock, flags); |
| 1003 | rc = 0; |
| 1004 | break; |
| 1005 | case AUDIO_SET_VOLUME: |
| 1006 | spin_lock_irqsave(&audio->dsp_lock, flags); |
| 1007 | audio->vol_pan.volume = arg; |
| 1008 | if (audio->running) |
| 1009 | audpp_dsp_set_vol_pan(audio->dec_id, &audio->vol_pan, |
| 1010 | POPP); |
| 1011 | spin_unlock_irqrestore(&audio->dsp_lock, flags); |
| 1012 | rc = 0; |
| 1013 | break; |
| 1014 | |
| 1015 | case AUDIO_SET_PAN: |
| 1016 | spin_lock_irqsave(&audio->dsp_lock, flags); |
| 1017 | audio->vol_pan.pan = arg; |
| 1018 | if (audio->running) |
| 1019 | audpp_dsp_set_vol_pan(audio->dec_id, &audio->vol_pan, |
| 1020 | POPP); |
| 1021 | spin_unlock_irqrestore(&audio->dsp_lock, flags); |
| 1022 | rc = 0; |
| 1023 | break; |
| 1024 | |
| 1025 | case AUDIO_SET_EQ: |
| 1026 | prev_state = audio->eq_enable; |
| 1027 | audio->eq_enable = 0; |
| 1028 | if (copy_from_user(&audio->eq.num_bands, (void *) arg, |
| 1029 | sizeof(audio->eq) - |
| 1030 | (AUDPP_CMD_CFG_OBJECT_PARAMS_COMMON_LEN + 2))) { |
| 1031 | rc = -EFAULT; |
| 1032 | break; |
| 1033 | } |
| 1034 | audio->eq_enable = prev_state; |
| 1035 | audio->eq_needs_commit = 1; |
| 1036 | rc = 0; |
| 1037 | break; |
| 1038 | } |
| 1039 | |
| 1040 | if (-EINVAL != rc) |
| 1041 | return rc; |
| 1042 | |
| 1043 | if (cmd == AUDIO_GET_EVENT) { |
| 1044 | MM_DBG("AUDIO_GET_EVENT\n"); |
| 1045 | if (mutex_trylock(&audio->get_event_lock)) { |
| 1046 | rc = audaac_process_event_req(audio, |
| 1047 | (void __user *) arg); |
| 1048 | mutex_unlock(&audio->get_event_lock); |
| 1049 | } else |
| 1050 | rc = -EBUSY; |
| 1051 | return rc; |
| 1052 | } |
| 1053 | |
| 1054 | if (cmd == AUDIO_ABORT_GET_EVENT) { |
| 1055 | audio->event_abort = 1; |
| 1056 | wake_up(&audio->event_wait); |
| 1057 | return 0; |
| 1058 | } |
| 1059 | |
| 1060 | mutex_lock(&audio->lock); |
| 1061 | switch (cmd) { |
| 1062 | case AUDIO_START: |
| 1063 | MM_DBG("AUDIO_START\n"); |
| 1064 | rc = audio_enable(audio); |
| 1065 | if (!rc) { |
| 1066 | rc = wait_event_interruptible_timeout(audio->wait, |
| 1067 | audio->dec_state != MSM_AUD_DECODER_STATE_NONE, |
| 1068 | msecs_to_jiffies(MSM_AUD_DECODER_WAIT_MS)); |
| 1069 | MM_INFO("dec_state %d rc = %d\n", audio->dec_state, rc); |
| 1070 | |
| 1071 | if (audio->dec_state != MSM_AUD_DECODER_STATE_SUCCESS) |
| 1072 | rc = -ENODEV; |
| 1073 | else |
| 1074 | rc = 0; |
| 1075 | } |
| 1076 | break; |
| 1077 | case AUDIO_STOP: |
| 1078 | MM_DBG("AUDIO_STOP\n"); |
| 1079 | rc = audio_disable(audio); |
| 1080 | audio->stopped = 1; |
| 1081 | audio_ioport_reset(audio); |
| 1082 | audio->stopped = 0; |
| 1083 | break; |
| 1084 | case AUDIO_FLUSH: |
| 1085 | MM_DBG("AUDIO_FLUSH running=%d\n", audio->running); |
| 1086 | audio->rflush = 1; |
| 1087 | audio->wflush = 1; |
| 1088 | audio_ioport_reset(audio); |
| 1089 | if (audio->running) { |
| 1090 | audpp_flush(audio->dec_id); |
| 1091 | rc = wait_event_interruptible(audio->write_wait, |
| 1092 | !audio->wflush); |
| 1093 | if (rc < 0) { |
| 1094 | MM_ERR("AUDIO_FLUSH interrupted\n"); |
| 1095 | rc = -EINTR; |
| 1096 | } |
| 1097 | } else { |
| 1098 | audio->rflush = 0; |
| 1099 | audio->wflush = 0; |
| 1100 | } |
| 1101 | break; |
| 1102 | |
| 1103 | case AUDIO_OUTPORT_FLUSH: |
| 1104 | MM_DBG("AUDIO_OUTPORT_FLUSH\n"); |
| 1105 | audio->rflush = 1; |
| 1106 | wake_up(&audio->read_wait); |
| 1107 | mutex_lock(&audio->read_lock); |
| 1108 | audio_flush_pcm_buf(audio); |
| 1109 | mutex_unlock(&audio->read_lock); |
| 1110 | audplay_outport_flush(audio); |
| 1111 | rc = wait_event_interruptible(audio->read_wait, |
| 1112 | !audio->rflush); |
| 1113 | if (rc < 0) { |
| 1114 | MM_ERR("AUDPLAY_OUTPORT_FLUSH interrupted\n"); |
| 1115 | rc = -EINTR; |
| 1116 | } |
| 1117 | break; |
| 1118 | |
| 1119 | case AUDIO_SET_CONFIG:{ |
| 1120 | struct msm_audio_config config; |
| 1121 | |
| 1122 | if (copy_from_user |
| 1123 | (&config, (void *)arg, sizeof(config))) { |
| 1124 | rc = -EFAULT; |
| 1125 | break; |
| 1126 | } |
| 1127 | |
| 1128 | if (config.channel_count == 1) { |
| 1129 | config.channel_count = |
| 1130 | AUDPP_CMD_PCM_INTF_MONO_V; |
| 1131 | } else if (config.channel_count == 2) { |
| 1132 | config.channel_count = |
| 1133 | AUDPP_CMD_PCM_INTF_STEREO_V; |
| 1134 | } else { |
| 1135 | rc = -EINVAL; |
| 1136 | break; |
| 1137 | } |
| 1138 | |
| 1139 | audio->out_sample_rate = config.sample_rate; |
| 1140 | audio->out_channel_mode = config.channel_count; |
| 1141 | audio->mfield = config.meta_field; |
| 1142 | rc = 0; |
| 1143 | break; |
| 1144 | } |
| 1145 | case AUDIO_GET_CONFIG:{ |
| 1146 | struct msm_audio_config config; |
| 1147 | config.buffer_size = (audio->out_dma_sz >> 1); |
| 1148 | config.buffer_count = 2; |
| 1149 | config.sample_rate = audio->out_sample_rate; |
| 1150 | if (audio->out_channel_mode == |
| 1151 | AUDPP_CMD_PCM_INTF_MONO_V) { |
| 1152 | config.channel_count = 1; |
| 1153 | } else { |
| 1154 | config.channel_count = 2; |
| 1155 | } |
| 1156 | config.meta_field = 0; |
| 1157 | config.unused[0] = 0; |
| 1158 | config.unused[1] = 0; |
| 1159 | config.unused[2] = 0; |
| 1160 | if (copy_to_user((void *)arg, &config, |
| 1161 | sizeof(config))) |
| 1162 | rc = -EFAULT; |
| 1163 | else |
| 1164 | rc = 0; |
| 1165 | |
| 1166 | break; |
| 1167 | } |
| 1168 | case AUDIO_GET_AAC_CONFIG:{ |
| 1169 | if (copy_to_user((void *)arg, &audio->aac_config, |
| 1170 | sizeof(audio->aac_config))) |
| 1171 | rc = -EFAULT; |
| 1172 | else |
| 1173 | rc = 0; |
| 1174 | break; |
| 1175 | } |
| 1176 | case AUDIO_SET_AAC_CONFIG:{ |
| 1177 | struct msm_audio_aac_config usr_config; |
| 1178 | |
| 1179 | if (copy_from_user |
| 1180 | (&usr_config, (void *)arg, |
| 1181 | sizeof(usr_config))) { |
| 1182 | rc = -EFAULT; |
| 1183 | break; |
| 1184 | } |
| 1185 | |
| 1186 | if (audaac_validate_usr_config(&usr_config) == 0) { |
| 1187 | audio->aac_config = usr_config; |
| 1188 | rc = 0; |
| 1189 | } else |
| 1190 | rc = -EINVAL; |
| 1191 | |
| 1192 | break; |
| 1193 | } |
| 1194 | case AUDIO_GET_PCM_CONFIG:{ |
| 1195 | struct msm_audio_pcm_config config; |
| 1196 | config.pcm_feedback = audio->pcm_feedback; |
| 1197 | config.buffer_count = PCM_BUF_MAX_COUNT; |
| 1198 | config.buffer_size = PCM_BUFSZ_MIN; |
| 1199 | if (copy_to_user((void *)arg, &config, |
| 1200 | sizeof(config))) |
| 1201 | rc = -EFAULT; |
| 1202 | else |
| 1203 | rc = 0; |
| 1204 | break; |
| 1205 | } |
| 1206 | case AUDIO_SET_PCM_CONFIG:{ |
| 1207 | struct msm_audio_pcm_config config; |
| 1208 | if (copy_from_user |
| 1209 | (&config, (void *)arg, sizeof(config))) { |
| 1210 | rc = -EFAULT; |
| 1211 | break; |
| 1212 | } |
| 1213 | if (config.pcm_feedback != audio->pcm_feedback) { |
| 1214 | MM_ERR("Not sufficient permission to" |
| 1215 | "change the playback mode\n"); |
| 1216 | rc = -EACCES; |
| 1217 | break; |
| 1218 | } |
| 1219 | if ((config.buffer_count > PCM_BUF_MAX_COUNT) || |
| 1220 | (config.buffer_count == 1)) |
| 1221 | config.buffer_count = PCM_BUF_MAX_COUNT; |
| 1222 | |
| 1223 | if (config.buffer_size < PCM_BUFSZ_MIN) |
| 1224 | config.buffer_size = PCM_BUFSZ_MIN; |
| 1225 | |
| 1226 | /* Check if pcm feedback is required */ |
| 1227 | if (config.pcm_feedback) { |
| 1228 | audio->buf_refresh = 0; |
| 1229 | audio->read_next = 0; |
| 1230 | audio->fill_next = 0; |
| 1231 | } |
| 1232 | rc = 0; |
| 1233 | break; |
| 1234 | } |
| 1235 | case AUDIO_PAUSE: |
| 1236 | MM_DBG("AUDIO_PAUSE %ld\n", arg); |
| 1237 | rc = audpp_pause(audio->dec_id, (int) arg); |
| 1238 | break; |
| 1239 | case AUDIO_GET_STREAM_INFO:{ |
| 1240 | if (audio->stream_info.sample_rate == 0) { |
| 1241 | /* haven't received DSP stream event, |
| 1242 | the stream info is not updated */ |
| 1243 | rc = -EPERM; |
| 1244 | break; |
| 1245 | } |
| 1246 | if (copy_to_user((void *)arg, &audio->stream_info, |
| 1247 | sizeof(struct msm_audio_bitstream_info))) |
| 1248 | rc = -EFAULT; |
| 1249 | else |
| 1250 | rc = 0; |
| 1251 | break; |
| 1252 | } |
| 1253 | case AUDIO_GET_BITSTREAM_ERROR_INFO:{ |
| 1254 | if ((audio->bitstream_error_info.err_msg_indicator & |
| 1255 | AUDPLAY_STREAM_INFO_MSG_MASK) == |
| 1256 | AUDPLAY_STREAM_INFO_MSG_MASK) { |
| 1257 | /* haven't received bitstream error info event, |
| 1258 | the bitstream error info is not updated */ |
| 1259 | rc = -EPERM; |
| 1260 | break; |
| 1261 | } |
| 1262 | if (copy_to_user((void *)arg, &audio->bitstream_error_info, |
| 1263 | sizeof(struct msm_audio_bitstream_error_info))) |
| 1264 | rc = -EFAULT; |
| 1265 | else |
| 1266 | rc = 0; |
| 1267 | break; |
| 1268 | } |
| 1269 | case AUDIO_GET_SESSION_ID: |
| 1270 | if (copy_to_user((void *) arg, &audio->dec_id, |
| 1271 | sizeof(unsigned short))) |
| 1272 | rc = -EFAULT; |
| 1273 | else |
| 1274 | rc = 0; |
| 1275 | break; |
| 1276 | case AUDIO_SET_ERR_THRESHOLD_VALUE: |
| 1277 | if (copy_from_user(&audio->bitstream_error_threshold_value, |
| 1278 | (void *)arg, sizeof(uint32_t))) |
| 1279 | rc = -EFAULT; |
| 1280 | else |
| 1281 | rc = 0; |
| 1282 | break; |
| 1283 | default: |
| 1284 | rc = -EINVAL; |
| 1285 | } |
| 1286 | mutex_unlock(&audio->lock); |
| 1287 | return rc; |
| 1288 | } |
| 1289 | /* Only useful in tunnel-mode */ |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1290 | static int audaac_fsync(struct file *file, loff_t ppos1, loff_t ppos2, int datasync) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1291 | { |
| 1292 | struct audio *audio = file->private_data; |
| 1293 | struct buffer *frame; |
| 1294 | int rc = 0; |
| 1295 | |
| 1296 | MM_DBG("\n"); /* Macro prints the file name and function */ |
| 1297 | |
| 1298 | if (!audio->running || audio->pcm_feedback) { |
| 1299 | rc = -EINVAL; |
| 1300 | goto done_nolock; |
| 1301 | } |
| 1302 | |
| 1303 | mutex_lock(&audio->write_lock); |
| 1304 | |
| 1305 | rc = wait_event_interruptible(audio->write_wait, |
| 1306 | (!audio->out[0].used && |
| 1307 | !audio->out[1].used && |
| 1308 | audio->out_needed) || audio->wflush); |
| 1309 | |
| 1310 | if (rc < 0) |
| 1311 | goto done; |
| 1312 | else if (audio->wflush) { |
| 1313 | rc = -EBUSY; |
| 1314 | goto done; |
| 1315 | } |
| 1316 | |
| 1317 | if (audio->reserved) { |
| 1318 | MM_DBG("send reserved byte\n"); |
| 1319 | frame = audio->out + audio->out_tail; |
| 1320 | ((char *) frame->data)[0] = audio->rsv_byte; |
| 1321 | ((char *) frame->data)[1] = 0; |
| 1322 | frame->used = 2; |
| 1323 | audplay_send_data(audio, 0); |
| 1324 | |
| 1325 | rc = wait_event_interruptible(audio->write_wait, |
| 1326 | (!audio->out[0].used && |
| 1327 | !audio->out[1].used && |
| 1328 | audio->out_needed) || audio->wflush); |
| 1329 | |
| 1330 | if (rc < 0) |
| 1331 | goto done; |
| 1332 | else if (audio->wflush) { |
| 1333 | rc = -EBUSY; |
| 1334 | goto done; |
| 1335 | } |
| 1336 | } |
| 1337 | |
| 1338 | /* pcm dmamiss message is sent continously |
| 1339 | * when decoder is starved so no race |
| 1340 | * condition concern |
| 1341 | */ |
| 1342 | audio->teos = 0; |
| 1343 | |
| 1344 | rc = wait_event_interruptible(audio->write_wait, |
| 1345 | audio->teos || audio->wflush); |
| 1346 | |
| 1347 | if (audio->wflush) |
| 1348 | rc = -EBUSY; |
| 1349 | |
| 1350 | done: |
| 1351 | mutex_unlock(&audio->write_lock); |
| 1352 | done_nolock: |
| 1353 | return rc; |
| 1354 | } |
| 1355 | |
| 1356 | static ssize_t audio_read(struct file *file, char __user *buf, size_t count, |
| 1357 | loff_t *pos) |
| 1358 | { |
| 1359 | struct audio *audio = file->private_data; |
| 1360 | const char __user *start = buf; |
| 1361 | int rc = 0; |
| 1362 | |
| 1363 | if (!audio->pcm_feedback) |
| 1364 | return 0; /* PCM feedback is not enabled. Nothing to read */ |
| 1365 | |
| 1366 | mutex_lock(&audio->read_lock); |
| 1367 | MM_DBG("to read %d \n", count); |
| 1368 | while (count > 0) { |
| 1369 | rc = wait_event_interruptible_timeout(audio->read_wait, |
| 1370 | (audio->in[audio->read_next]. |
| 1371 | used > 0) || (audio->stopped) |
| 1372 | || (audio->rflush), |
| 1373 | msecs_to_jiffies(MSM_AUD_BUFFER_UPDATE_WAIT_MS)); |
| 1374 | |
| 1375 | if (rc == 0) { |
| 1376 | rc = -ETIMEDOUT; |
| 1377 | break; |
| 1378 | } else if (rc < 0) |
| 1379 | break; |
| 1380 | |
| 1381 | if (audio->stopped || audio->rflush) { |
| 1382 | rc = -EBUSY; |
| 1383 | break; |
| 1384 | } |
| 1385 | |
| 1386 | if (count < audio->in[audio->read_next].used) { |
| 1387 | /* Read must happen in frame boundary. Since driver |
| 1388 | does not know frame size, read count must be greater |
| 1389 | or equal to size of PCM samples */ |
| 1390 | MM_DBG("no partial frame done reading\n"); |
| 1391 | break; |
| 1392 | } else { |
| 1393 | MM_DBG("read from in[%d]\n", audio->read_next); |
| 1394 | if (copy_to_user |
| 1395 | (buf, audio->in[audio->read_next].data, |
| 1396 | audio->in[audio->read_next].used)) { |
| 1397 | MM_ERR("invalid addr %x\n", (unsigned int)buf); |
| 1398 | rc = -EFAULT; |
| 1399 | break; |
| 1400 | } |
| 1401 | count -= audio->in[audio->read_next].used; |
| 1402 | buf += audio->in[audio->read_next].used; |
| 1403 | audio->in[audio->read_next].used = 0; |
| 1404 | if ((++audio->read_next) == audio->pcm_buf_count) |
| 1405 | audio->read_next = 0; |
| 1406 | break; |
| 1407 | /* |
| 1408 | * Force to exit while loop |
| 1409 | * to prevent output thread |
| 1410 | * sleep too long if data is not |
| 1411 | * ready at this moment. |
| 1412 | */ |
| 1413 | } |
| 1414 | } |
| 1415 | |
| 1416 | /* don't feed output buffer to HW decoder during flushing |
| 1417 | * buffer refresh command will be sent once flush completes |
| 1418 | * send buf refresh command here can confuse HW decoder |
| 1419 | */ |
| 1420 | if (audio->buf_refresh && !audio->rflush) { |
| 1421 | audio->buf_refresh = 0; |
| 1422 | MM_DBG("kick start pcm feedback again\n"); |
| 1423 | audplay_buffer_refresh(audio); |
| 1424 | } |
| 1425 | |
| 1426 | mutex_unlock(&audio->read_lock); |
| 1427 | |
| 1428 | if (buf > start) |
| 1429 | rc = buf - start; |
| 1430 | |
| 1431 | MM_DBG("read %d bytes\n", rc); |
| 1432 | return rc; |
| 1433 | } |
| 1434 | |
| 1435 | static int audaac_process_eos(struct audio *audio, |
| 1436 | const char __user *buf_start, unsigned short mfield_size) |
| 1437 | { |
| 1438 | struct buffer *frame; |
| 1439 | char *buf_ptr; |
| 1440 | int rc = 0; |
| 1441 | |
| 1442 | MM_DBG("signal input EOS reserved=%d\n", audio->reserved); |
| 1443 | if (audio->reserved) { |
| 1444 | MM_DBG("Pass reserve byte\n"); |
| 1445 | frame = audio->out + audio->out_head; |
| 1446 | buf_ptr = frame->data; |
| 1447 | rc = wait_event_interruptible(audio->write_wait, |
| 1448 | (frame->used == 0) |
| 1449 | || (audio->stopped) |
| 1450 | || (audio->wflush)); |
| 1451 | if (rc < 0) |
| 1452 | goto done; |
| 1453 | if (audio->stopped || audio->wflush) { |
| 1454 | rc = -EBUSY; |
| 1455 | goto done; |
| 1456 | } |
| 1457 | buf_ptr[0] = audio->rsv_byte; |
| 1458 | buf_ptr[1] = 0; |
| 1459 | audio->out_head ^= 1; |
| 1460 | frame->mfield_sz = 0; |
| 1461 | audio->reserved = 0; |
| 1462 | frame->used = 2; |
| 1463 | audplay_send_data(audio, 0); |
| 1464 | } |
| 1465 | MM_DBG("Now signal input EOS after reserved bytes %d %d %d\n", |
| 1466 | audio->out[0].used, audio->out[1].used, audio->out_needed); |
| 1467 | frame = audio->out + audio->out_head; |
| 1468 | |
| 1469 | rc = wait_event_interruptible(audio->write_wait, |
| 1470 | (audio->out_needed && |
| 1471 | audio->out[0].used == 0 && |
| 1472 | audio->out[1].used == 0) |
| 1473 | || (audio->stopped) |
| 1474 | || (audio->wflush)); |
| 1475 | |
| 1476 | if (rc < 0) |
| 1477 | goto done; |
| 1478 | if (audio->stopped || audio->wflush) { |
| 1479 | rc = -EBUSY; |
| 1480 | goto done; |
| 1481 | } |
| 1482 | |
| 1483 | if (copy_from_user(frame->data, buf_start, mfield_size)) { |
| 1484 | rc = -EFAULT; |
| 1485 | goto done; |
| 1486 | } |
| 1487 | |
| 1488 | frame->mfield_sz = mfield_size; |
| 1489 | audio->out_head ^= 1; |
| 1490 | frame->used = mfield_size; |
| 1491 | audplay_send_data(audio, 0); |
| 1492 | done: |
| 1493 | return rc; |
| 1494 | } |
| 1495 | static ssize_t audio_write(struct file *file, const char __user *buf, |
| 1496 | size_t count, loff_t *pos) |
| 1497 | { |
| 1498 | struct audio *audio = file->private_data; |
| 1499 | const char __user *start = buf; |
| 1500 | struct buffer *frame; |
| 1501 | size_t xfer; |
| 1502 | char *cpy_ptr; |
| 1503 | int rc = 0, eos_condition = AUDAAC_EOS_NONE; |
| 1504 | unsigned dsize; |
| 1505 | |
| 1506 | unsigned short mfield_size = 0; |
| 1507 | MM_DBG("cnt=%d\n", count); |
| 1508 | mutex_lock(&audio->write_lock); |
| 1509 | while (count > 0) { |
| 1510 | frame = audio->out + audio->out_head; |
| 1511 | cpy_ptr = frame->data; |
| 1512 | dsize = 0; |
| 1513 | rc = wait_event_interruptible(audio->write_wait, |
| 1514 | (frame->used == 0) |
| 1515 | || (audio->stopped) |
| 1516 | || (audio->wflush)); |
| 1517 | if (rc < 0) |
| 1518 | break; |
| 1519 | if (audio->stopped || audio->wflush) { |
| 1520 | rc = -EBUSY; |
| 1521 | break; |
| 1522 | } |
| 1523 | if (audio->mfield) { |
| 1524 | if (buf == start) { |
| 1525 | /* Processing beginning of user buffer */ |
| 1526 | if (__get_user(mfield_size, |
| 1527 | (unsigned short __user *) buf)) { |
| 1528 | rc = -EFAULT; |
| 1529 | break; |
| 1530 | } else if (mfield_size > count) { |
| 1531 | rc = -EINVAL; |
| 1532 | break; |
| 1533 | } |
| 1534 | MM_DBG("mf offset_val %x\n", mfield_size); |
| 1535 | if (copy_from_user(cpy_ptr, buf, mfield_size)) { |
| 1536 | rc = -EFAULT; |
| 1537 | break; |
| 1538 | } |
| 1539 | /* Check if EOS flag is set and buffer has |
| 1540 | * contains just meta field |
| 1541 | */ |
| 1542 | if (cpy_ptr[AUDAAC_EOS_FLG_OFFSET] & |
| 1543 | AUDAAC_EOS_FLG_MASK) { |
| 1544 | MM_DBG("eos set\n"); |
| 1545 | eos_condition = AUDAAC_EOS_SET; |
| 1546 | if (mfield_size == count) { |
| 1547 | buf += mfield_size; |
| 1548 | break; |
| 1549 | } else |
| 1550 | cpy_ptr[AUDAAC_EOS_FLG_OFFSET] &= |
| 1551 | ~AUDAAC_EOS_FLG_MASK; |
| 1552 | } |
| 1553 | /* Check EOS to see if */ |
| 1554 | cpy_ptr += mfield_size; |
| 1555 | count -= mfield_size; |
| 1556 | dsize += mfield_size; |
| 1557 | buf += mfield_size; |
| 1558 | } else { |
| 1559 | mfield_size = 0; |
| 1560 | MM_DBG("continuous buffer\n"); |
| 1561 | } |
| 1562 | frame->mfield_sz = mfield_size; |
| 1563 | } |
| 1564 | |
| 1565 | if (audio->reserved) { |
| 1566 | MM_DBG("append reserved byte %x\n", |
| 1567 | audio->rsv_byte); |
| 1568 | *cpy_ptr = audio->rsv_byte; |
| 1569 | xfer = (count > ((frame->size - mfield_size) - 1)) ? |
| 1570 | (frame->size - mfield_size) - 1 : count; |
| 1571 | cpy_ptr++; |
| 1572 | dsize += 1; |
| 1573 | audio->reserved = 0; |
| 1574 | } else |
| 1575 | xfer = (count > (frame->size - mfield_size)) ? |
| 1576 | (frame->size - mfield_size) : count; |
| 1577 | |
| 1578 | if (copy_from_user(cpy_ptr, buf, xfer)) { |
| 1579 | rc = -EFAULT; |
| 1580 | break; |
| 1581 | } |
| 1582 | |
| 1583 | dsize += xfer; |
| 1584 | if (dsize & 1) { |
| 1585 | audio->rsv_byte = ((char *) frame->data)[dsize - 1]; |
| 1586 | MM_DBG("odd length buf reserve last byte %x\n", |
| 1587 | audio->rsv_byte); |
| 1588 | audio->reserved = 1; |
| 1589 | dsize--; |
| 1590 | } |
| 1591 | count -= xfer; |
| 1592 | buf += xfer; |
| 1593 | |
| 1594 | if (dsize > 0) { |
| 1595 | audio->out_head ^= 1; |
| 1596 | frame->used = dsize; |
| 1597 | audplay_send_data(audio, 0); |
| 1598 | } |
| 1599 | } |
| 1600 | MM_DBG("eos_condition %x buf[0x%x] start[0x%x]\n", eos_condition, |
| 1601 | (int) buf, (int) start); |
| 1602 | if (eos_condition == AUDAAC_EOS_SET) |
| 1603 | rc = audaac_process_eos(audio, start, mfield_size); |
| 1604 | mutex_unlock(&audio->write_lock); |
| 1605 | if (!rc) { |
| 1606 | if (buf > start) |
| 1607 | return buf - start; |
| 1608 | } |
| 1609 | return rc; |
| 1610 | } |
| 1611 | |
| 1612 | static int audio_release(struct inode *inode, struct file *file) |
| 1613 | { |
| 1614 | struct audio *audio = file->private_data; |
| 1615 | |
| 1616 | MM_INFO("audio instance 0x%08x freeing\n", (int)audio); |
| 1617 | |
| 1618 | mutex_lock(&audio->lock); |
| 1619 | auddev_unregister_evt_listner(AUDDEV_CLNT_DEC, audio->dec_id); |
| 1620 | audio_disable(audio); |
| 1621 | audio_flush(audio); |
| 1622 | audio_flush_pcm_buf(audio); |
| 1623 | msm_adsp_put(audio->audplay); |
| 1624 | audpp_adec_free(audio->dec_id); |
| 1625 | #ifdef CONFIG_HAS_EARLYSUSPEND |
| 1626 | unregister_early_suspend(&audio->suspend_ctl.node); |
| 1627 | #endif |
| 1628 | audio->event_abort = 1; |
| 1629 | wake_up(&audio->event_wait); |
| 1630 | audaac_reset_event_queue(audio); |
Laura Abbott | 6139969 | 2012-04-30 14:25:46 -0700 | [diff] [blame] | 1631 | iounmap(audio->map_v_write); |
Santosh Mardi | fdc227a | 2011-07-11 17:20:34 +0530 | [diff] [blame] | 1632 | free_contiguous_memory_by_paddr(audio->phys); |
Laura Abbott | 6139969 | 2012-04-30 14:25:46 -0700 | [diff] [blame] | 1633 | iounmap(audio->map_v_read); |
Santosh Mardi | fdc227a | 2011-07-11 17:20:34 +0530 | [diff] [blame] | 1634 | free_contiguous_memory_by_paddr(audio->read_phys); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1635 | mutex_unlock(&audio->lock); |
| 1636 | #ifdef CONFIG_DEBUG_FS |
| 1637 | if (audio->dentry) |
| 1638 | debugfs_remove(audio->dentry); |
| 1639 | #endif |
| 1640 | kfree(audio); |
| 1641 | return 0; |
| 1642 | } |
| 1643 | |
| 1644 | static void audaac_post_event(struct audio *audio, int type, |
| 1645 | union msm_audio_event_payload payload) |
| 1646 | { |
| 1647 | struct audaac_event *e_node = NULL; |
| 1648 | unsigned long flags; |
| 1649 | |
| 1650 | spin_lock_irqsave(&audio->event_queue_lock, flags); |
| 1651 | |
| 1652 | if (!list_empty(&audio->free_event_queue)) { |
| 1653 | e_node = list_first_entry(&audio->free_event_queue, |
| 1654 | struct audaac_event, list); |
| 1655 | list_del(&e_node->list); |
| 1656 | } else { |
| 1657 | e_node = kmalloc(sizeof(struct audaac_event), GFP_ATOMIC); |
| 1658 | if (!e_node) { |
| 1659 | MM_ERR("No mem to post event %d\n", type); |
| 1660 | return; |
| 1661 | } |
| 1662 | } |
| 1663 | |
| 1664 | e_node->event_type = type; |
| 1665 | e_node->payload = payload; |
| 1666 | |
| 1667 | list_add_tail(&e_node->list, &audio->event_queue); |
| 1668 | spin_unlock_irqrestore(&audio->event_queue_lock, flags); |
| 1669 | wake_up(&audio->event_wait); |
| 1670 | } |
| 1671 | |
| 1672 | #ifdef CONFIG_HAS_EARLYSUSPEND |
| 1673 | static void audaac_suspend(struct early_suspend *h) |
| 1674 | { |
| 1675 | struct audaac_suspend_ctl *ctl = |
| 1676 | container_of(h, struct audaac_suspend_ctl, node); |
| 1677 | union msm_audio_event_payload payload; |
| 1678 | |
| 1679 | MM_DBG("\n"); /* Macro prints the file name and function */ |
| 1680 | audaac_post_event(ctl->audio, AUDIO_EVENT_SUSPEND, payload); |
| 1681 | } |
| 1682 | |
| 1683 | static void audaac_resume(struct early_suspend *h) |
| 1684 | { |
| 1685 | struct audaac_suspend_ctl *ctl = |
| 1686 | container_of(h, struct audaac_suspend_ctl, node); |
| 1687 | union msm_audio_event_payload payload; |
| 1688 | |
| 1689 | MM_DBG("\n"); /* Macro prints the file name and function */ |
| 1690 | audaac_post_event(ctl->audio, AUDIO_EVENT_RESUME, payload); |
| 1691 | } |
| 1692 | #endif |
| 1693 | |
| 1694 | #ifdef CONFIG_DEBUG_FS |
| 1695 | static ssize_t audaac_debug_open(struct inode *inode, struct file *file) |
| 1696 | { |
| 1697 | file->private_data = inode->i_private; |
| 1698 | return 0; |
| 1699 | } |
| 1700 | |
| 1701 | static ssize_t audaac_debug_read(struct file *file, char __user *buf, |
| 1702 | size_t count, loff_t *ppos) |
| 1703 | { |
| 1704 | const int debug_bufmax = 1024; |
| 1705 | static char buffer[1024]; |
| 1706 | int n = 0, i; |
| 1707 | struct audio *audio = file->private_data; |
| 1708 | |
| 1709 | mutex_lock(&audio->lock); |
| 1710 | n = scnprintf(buffer, debug_bufmax, "opened %d\n", audio->opened); |
| 1711 | n += scnprintf(buffer + n, debug_bufmax - n, |
| 1712 | "enabled %d\n", audio->enabled); |
| 1713 | n += scnprintf(buffer + n, debug_bufmax - n, |
| 1714 | "stopped %d\n", audio->stopped); |
| 1715 | n += scnprintf(buffer + n, debug_bufmax - n, |
| 1716 | "pcm_feedback %d\n", audio->pcm_feedback); |
| 1717 | n += scnprintf(buffer + n, debug_bufmax - n, |
| 1718 | "out_buf_sz %d\n", audio->out[0].size); |
| 1719 | n += scnprintf(buffer + n, debug_bufmax - n, |
| 1720 | "pcm_buf_count %d \n", audio->pcm_buf_count); |
| 1721 | n += scnprintf(buffer + n, debug_bufmax - n, |
| 1722 | "pcm_buf_sz %d \n", audio->in[0].size); |
| 1723 | n += scnprintf(buffer + n, debug_bufmax - n, |
| 1724 | "volume %x \n", audio->vol_pan.volume); |
| 1725 | n += scnprintf(buffer + n, debug_bufmax - n, |
| 1726 | "sample rate %d \n", audio->out_sample_rate); |
| 1727 | n += scnprintf(buffer + n, debug_bufmax - n, |
| 1728 | "channel mode %d \n", audio->out_channel_mode); |
| 1729 | mutex_unlock(&audio->lock); |
| 1730 | /* Following variables are only useful for debugging when |
| 1731 | * when playback halts unexpectedly. Thus, no mutual exclusion |
| 1732 | * enforced |
| 1733 | */ |
| 1734 | n += scnprintf(buffer + n, debug_bufmax - n, |
| 1735 | "wflush %d\n", audio->wflush); |
| 1736 | n += scnprintf(buffer + n, debug_bufmax - n, |
| 1737 | "rflush %d\n", audio->rflush); |
| 1738 | n += scnprintf(buffer + n, debug_bufmax - n, |
| 1739 | "running %d \n", audio->running); |
| 1740 | n += scnprintf(buffer + n, debug_bufmax - n, |
| 1741 | "dec state %d \n", audio->dec_state); |
| 1742 | n += scnprintf(buffer + n, debug_bufmax - n, |
| 1743 | "out_needed %d \n", audio->out_needed); |
| 1744 | n += scnprintf(buffer + n, debug_bufmax - n, |
| 1745 | "out_head %d \n", audio->out_head); |
| 1746 | n += scnprintf(buffer + n, debug_bufmax - n, |
| 1747 | "out_tail %d \n", audio->out_tail); |
| 1748 | n += scnprintf(buffer + n, debug_bufmax - n, |
| 1749 | "out[0].used %d \n", audio->out[0].used); |
| 1750 | n += scnprintf(buffer + n, debug_bufmax - n, |
| 1751 | "out[1].used %d \n", audio->out[1].used); |
| 1752 | n += scnprintf(buffer + n, debug_bufmax - n, |
| 1753 | "buffer_refresh %d \n", audio->buf_refresh); |
| 1754 | n += scnprintf(buffer + n, debug_bufmax - n, |
| 1755 | "read_next %d \n", audio->read_next); |
| 1756 | n += scnprintf(buffer + n, debug_bufmax - n, |
| 1757 | "fill_next %d \n", audio->fill_next); |
| 1758 | for (i = 0; i < audio->pcm_buf_count; i++) |
| 1759 | n += scnprintf(buffer + n, debug_bufmax - n, |
| 1760 | "in[%d].used %d \n", i, audio->in[i].used); |
| 1761 | buffer[n] = 0; |
| 1762 | return simple_read_from_buffer(buf, count, ppos, buffer, n); |
| 1763 | } |
| 1764 | |
| 1765 | static const struct file_operations audaac_debug_fops = { |
| 1766 | .read = audaac_debug_read, |
| 1767 | .open = audaac_debug_open, |
| 1768 | }; |
| 1769 | #endif |
| 1770 | |
| 1771 | static int audio_open(struct inode *inode, struct file *file) |
| 1772 | { |
| 1773 | struct audio *audio = NULL; |
| 1774 | int rc, dec_attrb, decid, index, offset = 0; |
| 1775 | unsigned pmem_sz = DMASZ; |
| 1776 | struct audaac_event *e_node = NULL; |
| 1777 | #ifdef CONFIG_DEBUG_FS |
| 1778 | /* 4 bytes represents decoder number, 1 byte for terminate string */ |
| 1779 | char name[sizeof "msm_aac_" + 5]; |
| 1780 | #endif |
| 1781 | |
| 1782 | /* Allocate audio instance, set to zero */ |
| 1783 | audio = kzalloc(sizeof(struct audio), GFP_KERNEL); |
| 1784 | if (!audio) { |
| 1785 | MM_ERR("no memory to allocate audio instance \n"); |
| 1786 | rc = -ENOMEM; |
| 1787 | goto done; |
| 1788 | } |
| 1789 | MM_INFO("audio instance 0x%08x created\n", (int)audio); |
| 1790 | |
| 1791 | /* Allocate the decoder */ |
| 1792 | dec_attrb = AUDDEC_DEC_AAC; |
| 1793 | if ((file->f_mode & FMODE_WRITE) && |
| 1794 | (file->f_mode & FMODE_READ)) { |
| 1795 | dec_attrb |= MSM_AUD_MODE_NONTUNNEL; |
| 1796 | audio->pcm_feedback = NON_TUNNEL_MODE_PLAYBACK; |
| 1797 | } else if ((file->f_mode & FMODE_WRITE) && |
| 1798 | !(file->f_mode & FMODE_READ)) { |
| 1799 | dec_attrb |= MSM_AUD_MODE_TUNNEL; |
| 1800 | audio->pcm_feedback = TUNNEL_MODE_PLAYBACK; |
| 1801 | } else { |
| 1802 | kfree(audio); |
| 1803 | rc = -EACCES; |
| 1804 | goto done; |
| 1805 | } |
| 1806 | decid = audpp_adec_alloc(dec_attrb, &audio->module_name, |
| 1807 | &audio->queue_id); |
| 1808 | |
| 1809 | if (decid < 0) { |
| 1810 | MM_ERR("No free decoder available, freeing instance 0x%08x\n", |
| 1811 | (int)audio); |
| 1812 | rc = -ENODEV; |
| 1813 | kfree(audio); |
| 1814 | goto done; |
| 1815 | } |
| 1816 | audio->dec_id = decid & MSM_AUD_DECODER_MASK; |
| 1817 | |
| 1818 | while (pmem_sz >= DMASZ_MIN) { |
Santosh Mardi | fdc227a | 2011-07-11 17:20:34 +0530 | [diff] [blame] | 1819 | MM_DBG("pmemsz = %d\n", pmem_sz); |
| 1820 | audio->phys = allocate_contiguous_ebi_nomap(pmem_sz, SZ_4K); |
| 1821 | if (audio->phys) { |
| 1822 | audio->map_v_write = |
Laura Abbott | 6139969 | 2012-04-30 14:25:46 -0700 | [diff] [blame] | 1823 | ioremap(audio->phys, |
| 1824 | pmem_sz); |
Santosh Mardi | fdc227a | 2011-07-11 17:20:34 +0530 | [diff] [blame] | 1825 | if (IS_ERR(audio->map_v_write)) { |
| 1826 | MM_ERR("could not map write phys address, \ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1827 | freeing instance 0x%08x\n", |
| 1828 | (int)audio); |
| 1829 | rc = -ENOMEM; |
Santosh Mardi | fdc227a | 2011-07-11 17:20:34 +0530 | [diff] [blame] | 1830 | free_contiguous_memory_by_paddr(audio->phys); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1831 | audpp_adec_free(audio->dec_id); |
| 1832 | kfree(audio); |
| 1833 | goto done; |
| 1834 | } |
Laura Abbott | 6139969 | 2012-04-30 14:25:46 -0700 | [diff] [blame] | 1835 | audio->data = (u8 *)audio->map_v_write; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1836 | MM_DBG("write buf: phy addr 0x%08x kernel addr \ |
| 1837 | 0x%08x\n", audio->phys, (int)audio->data); |
| 1838 | break; |
| 1839 | } else if (pmem_sz == DMASZ_MIN) { |
| 1840 | MM_ERR("could not allocate write buffers, freeing \ |
| 1841 | instance 0x%08x\n", (int)audio); |
| 1842 | rc = -ENOMEM; |
| 1843 | audpp_adec_free(audio->dec_id); |
| 1844 | kfree(audio); |
| 1845 | goto done; |
| 1846 | } else |
| 1847 | pmem_sz >>= 1; |
| 1848 | } |
| 1849 | audio->out_dma_sz = pmem_sz; |
| 1850 | |
Santosh Mardi | fdc227a | 2011-07-11 17:20:34 +0530 | [diff] [blame] | 1851 | audio->read_phys = allocate_contiguous_ebi_nomap(PCM_BUFSZ_MIN |
| 1852 | * PCM_BUF_MAX_COUNT, SZ_4K); |
| 1853 | if (!audio->read_phys) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1854 | MM_ERR("could not allocate read buffers, freeing instance \ |
| 1855 | 0x%08x\n", (int)audio); |
| 1856 | rc = -ENOMEM; |
Laura Abbott | 6139969 | 2012-04-30 14:25:46 -0700 | [diff] [blame] | 1857 | iounmap(audio->map_v_write); |
Santosh Mardi | fdc227a | 2011-07-11 17:20:34 +0530 | [diff] [blame] | 1858 | free_contiguous_memory_by_paddr(audio->phys); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1859 | audpp_adec_free(audio->dec_id); |
| 1860 | kfree(audio); |
| 1861 | goto done; |
| 1862 | } |
Laura Abbott | 6139969 | 2012-04-30 14:25:46 -0700 | [diff] [blame] | 1863 | audio->map_v_read = ioremap(audio->read_phys, |
| 1864 | PCM_BUFSZ_MIN * PCM_BUF_MAX_COUNT); |
Santosh Mardi | fdc227a | 2011-07-11 17:20:34 +0530 | [diff] [blame] | 1865 | if (IS_ERR(audio->map_v_read)) { |
| 1866 | MM_ERR("could not map read phys address, freeing instance \ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1867 | 0x%08x\n", (int)audio); |
| 1868 | rc = -ENOMEM; |
Laura Abbott | 6139969 | 2012-04-30 14:25:46 -0700 | [diff] [blame] | 1869 | iounmap(audio->map_v_write); |
Santosh Mardi | fdc227a | 2011-07-11 17:20:34 +0530 | [diff] [blame] | 1870 | free_contiguous_memory_by_paddr(audio->phys); |
| 1871 | free_contiguous_memory_by_paddr(audio->read_phys); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1872 | audpp_adec_free(audio->dec_id); |
| 1873 | kfree(audio); |
| 1874 | goto done; |
| 1875 | } |
Laura Abbott | 6139969 | 2012-04-30 14:25:46 -0700 | [diff] [blame] | 1876 | audio->read_data = audio->map_v_read; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1877 | MM_DBG("read buf: phy addr 0x%08x kernel addr 0x%08x\n", |
| 1878 | audio->read_phys, (int)audio->read_data); |
| 1879 | |
| 1880 | rc = msm_adsp_get(audio->module_name, &audio->audplay, |
| 1881 | &audplay_adsp_ops_aac, audio); |
| 1882 | if (rc) { |
| 1883 | MM_ERR("failed to get %s module, freeing instance 0x%08x\n", |
| 1884 | audio->module_name, (int)audio); |
| 1885 | goto err; |
| 1886 | } |
| 1887 | |
| 1888 | mutex_init(&audio->lock); |
| 1889 | mutex_init(&audio->write_lock); |
| 1890 | mutex_init(&audio->read_lock); |
| 1891 | mutex_init(&audio->get_event_lock); |
| 1892 | spin_lock_init(&audio->dsp_lock); |
| 1893 | spin_lock_init(&audio->event_queue_lock); |
| 1894 | INIT_LIST_HEAD(&audio->free_event_queue); |
| 1895 | INIT_LIST_HEAD(&audio->event_queue); |
| 1896 | init_waitqueue_head(&audio->write_wait); |
| 1897 | init_waitqueue_head(&audio->read_wait); |
| 1898 | init_waitqueue_head(&audio->wait); |
| 1899 | init_waitqueue_head(&audio->event_wait); |
| 1900 | init_waitqueue_head(&audio->avsync_wait); |
| 1901 | |
| 1902 | audio->out[0].data = audio->data + 0; |
| 1903 | audio->out[0].addr = audio->phys + 0; |
| 1904 | audio->out[0].size = audio->out_dma_sz >> 1; |
| 1905 | |
| 1906 | audio->out[1].data = audio->data + audio->out[0].size; |
| 1907 | audio->out[1].addr = audio->phys + audio->out[0].size; |
| 1908 | audio->out[1].size = audio->out[0].size; |
| 1909 | |
| 1910 | audio->pcm_buf_count = PCM_BUF_MAX_COUNT; |
| 1911 | for (index = 0; index < PCM_BUF_MAX_COUNT; index++) { |
| 1912 | audio->in[index].data = audio->read_data + offset; |
| 1913 | audio->in[index].addr = audio->read_phys + offset; |
| 1914 | audio->in[index].size = PCM_BUFSZ_MIN; |
| 1915 | audio->in[index].used = 0; |
| 1916 | offset += PCM_BUFSZ_MIN; |
| 1917 | } |
| 1918 | |
| 1919 | audio->out_sample_rate = 44100; |
| 1920 | audio->out_channel_mode = AUDPP_CMD_PCM_INTF_STEREO_V; |
| 1921 | audio->aac_config.format = AUDIO_AAC_FORMAT_ADTS; |
| 1922 | audio->aac_config.audio_object = AUDIO_AAC_OBJECT_LC; |
| 1923 | audio->aac_config.ep_config = 0; |
| 1924 | audio->aac_config.aac_section_data_resilience_flag = |
| 1925 | AUDIO_AAC_SEC_DATA_RES_OFF; |
| 1926 | audio->aac_config.aac_scalefactor_data_resilience_flag = |
| 1927 | AUDIO_AAC_SCA_DATA_RES_OFF; |
| 1928 | audio->aac_config.aac_spectral_data_resilience_flag = |
| 1929 | AUDIO_AAC_SPEC_DATA_RES_OFF; |
| 1930 | #ifdef CONFIG_AUDIO_AAC_PLUS |
| 1931 | audio->aac_config.sbr_on_flag = AUDIO_AAC_SBR_ON_FLAG_ON; |
| 1932 | #else |
| 1933 | audio->aac_config.sbr_on_flag = AUDIO_AAC_SBR_ON_FLAG_OFF; |
| 1934 | #endif |
| 1935 | #ifdef CONFIG_AUDIO_ENHANCED_AAC_PLUS |
| 1936 | audio->aac_config.sbr_ps_on_flag = AUDIO_AAC_SBR_PS_ON_FLAG_ON; |
| 1937 | #else |
| 1938 | audio->aac_config.sbr_ps_on_flag = AUDIO_AAC_SBR_PS_ON_FLAG_OFF; |
| 1939 | #endif |
| 1940 | audio->aac_config.dual_mono_mode = AUDIO_AAC_DUAL_MONO_PL_SR; |
| 1941 | audio->aac_config.channel_configuration = 2; |
| 1942 | audio->vol_pan.volume = 0x2000; |
| 1943 | audio->bitstream_error_threshold_value = |
| 1944 | BITSTREAM_ERROR_THRESHOLD_VALUE; |
| 1945 | |
| 1946 | audio_flush(audio); |
| 1947 | |
| 1948 | file->private_data = audio; |
| 1949 | audio->opened = 1; |
| 1950 | |
| 1951 | audio->device_events = AUDDEV_EVT_DEV_RDY |
| 1952 | |AUDDEV_EVT_DEV_RLS| |
| 1953 | AUDDEV_EVT_STREAM_VOL_CHG; |
| 1954 | |
| 1955 | rc = auddev_register_evt_listner(audio->device_events, |
| 1956 | AUDDEV_CLNT_DEC, |
| 1957 | audio->dec_id, |
| 1958 | aac_listner, |
| 1959 | (void *)audio); |
| 1960 | if (rc) { |
| 1961 | MM_ERR("%s: failed to register listner\n", __func__); |
| 1962 | goto event_err; |
| 1963 | } |
| 1964 | |
| 1965 | #ifdef CONFIG_DEBUG_FS |
| 1966 | snprintf(name, sizeof name, "msm_aac_%04x", audio->dec_id); |
| 1967 | audio->dentry = debugfs_create_file(name, S_IFREG | S_IRUGO, |
| 1968 | NULL, (void *) audio, |
| 1969 | &audaac_debug_fops); |
| 1970 | |
| 1971 | if (IS_ERR(audio->dentry)) |
| 1972 | MM_DBG("debugfs_create_file failed\n"); |
| 1973 | #endif |
| 1974 | #ifdef CONFIG_HAS_EARLYSUSPEND |
| 1975 | audio->suspend_ctl.node.level = EARLY_SUSPEND_LEVEL_DISABLE_FB; |
| 1976 | audio->suspend_ctl.node.resume = audaac_resume; |
| 1977 | audio->suspend_ctl.node.suspend = audaac_suspend; |
| 1978 | audio->suspend_ctl.audio = audio; |
| 1979 | register_early_suspend(&audio->suspend_ctl.node); |
| 1980 | #endif |
| 1981 | for (index = 0; index < AUDAAC_EVENT_NUM; index++) { |
| 1982 | e_node = kmalloc(sizeof(struct audaac_event), GFP_KERNEL); |
| 1983 | if (e_node) |
| 1984 | list_add_tail(&e_node->list, &audio->free_event_queue); |
| 1985 | else { |
| 1986 | MM_ERR("event pkt alloc failed\n"); |
| 1987 | break; |
| 1988 | } |
| 1989 | } |
| 1990 | memset(&audio->stream_info, 0, sizeof(struct msm_audio_bitstream_info)); |
| 1991 | memset(&audio->bitstream_error_info, 0, |
| 1992 | sizeof(struct msm_audio_bitstream_info)); |
| 1993 | done: |
| 1994 | return rc; |
| 1995 | event_err: |
| 1996 | msm_adsp_put(audio->audplay); |
| 1997 | err: |
Laura Abbott | 6139969 | 2012-04-30 14:25:46 -0700 | [diff] [blame] | 1998 | iounmap(audio->map_v_write); |
Santosh Mardi | fdc227a | 2011-07-11 17:20:34 +0530 | [diff] [blame] | 1999 | free_contiguous_memory_by_paddr(audio->phys); |
Laura Abbott | 6139969 | 2012-04-30 14:25:46 -0700 | [diff] [blame] | 2000 | iounmap(audio->map_v_read); |
Santosh Mardi | fdc227a | 2011-07-11 17:20:34 +0530 | [diff] [blame] | 2001 | free_contiguous_memory_by_paddr(audio->read_phys); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2002 | audpp_adec_free(audio->dec_id); |
| 2003 | kfree(audio); |
| 2004 | return rc; |
| 2005 | } |
| 2006 | |
| 2007 | static const struct file_operations audio_aac_fops = { |
| 2008 | .owner = THIS_MODULE, |
| 2009 | .open = audio_open, |
| 2010 | .release = audio_release, |
| 2011 | .read = audio_read, |
| 2012 | .write = audio_write, |
| 2013 | .unlocked_ioctl = audio_ioctl, |
| 2014 | .fsync = audaac_fsync |
| 2015 | }; |
| 2016 | |
| 2017 | struct miscdevice audio_aac_misc = { |
| 2018 | .minor = MISC_DYNAMIC_MINOR, |
| 2019 | .name = "msm_aac", |
| 2020 | .fops = &audio_aac_fops, |
| 2021 | }; |
| 2022 | |
| 2023 | static int __init audio_init(void) |
| 2024 | { |
| 2025 | return misc_register(&audio_aac_misc); |
| 2026 | } |
| 2027 | |
| 2028 | static void __exit audio_exit(void) |
| 2029 | { |
| 2030 | misc_deregister(&audio_aac_misc); |
| 2031 | } |
| 2032 | |
| 2033 | module_init(audio_init); |
| 2034 | module_exit(audio_exit); |
| 2035 | |
| 2036 | MODULE_DESCRIPTION("MSM AAC driver"); |
| 2037 | MODULE_LICENSE("GPL v2"); |