q6audio_v2.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * Copyright (c) 2012-2013, 2015-2017, The Linux Foundation. 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. #include <linux/module.h>
  14. #include <linux/fs.h>
  15. #include <linux/miscdevice.h>
  16. #include <linux/uaccess.h>
  17. #include <linux/sched.h>
  18. #include <linux/wait.h>
  19. #include <linux/dma-mapping.h>
  20. #include <linux/slab.h>
  21. #include <linux/atomic.h>
  22. #include <asm/ioctls.h>
  23. #include "audio_utils.h"
  24. void q6asm_in_cb(uint32_t opcode, uint32_t token,
  25. uint32_t *payload, void *priv)
  26. {
  27. struct q6audio_in *audio = (struct q6audio_in *)priv;
  28. unsigned long flags;
  29. pr_debug("%s:session id %d: opcode[0x%x]\n", __func__,
  30. audio->ac->session, opcode);
  31. spin_lock_irqsave(&audio->dsp_lock, flags);
  32. switch (opcode) {
  33. case ASM_DATA_EVENT_READ_DONE_V2:
  34. audio_in_get_dsp_frames(audio, token, payload);
  35. break;
  36. case ASM_DATA_EVENT_WRITE_DONE_V2:
  37. atomic_inc(&audio->in_count);
  38. wake_up(&audio->write_wait);
  39. break;
  40. case ASM_DATA_EVENT_RENDERED_EOS:
  41. audio->eos_rsp = 1;
  42. wake_up(&audio->read_wait);
  43. break;
  44. case ASM_STREAM_CMDRSP_GET_PP_PARAMS_V2:
  45. break;
  46. case ASM_SESSION_EVENTX_OVERFLOW:
  47. pr_err("%s:session id %d: ASM_SESSION_EVENT_TX_OVERFLOW\n",
  48. __func__, audio->ac->session);
  49. break;
  50. case RESET_EVENTS:
  51. pr_debug("%s:received RESET EVENTS\n", __func__);
  52. audio->enabled = 0;
  53. audio->stopped = 1;
  54. audio->event_abort = 1;
  55. audio->reset_event = true;
  56. wake_up(&audio->read_wait);
  57. wake_up(&audio->write_wait);
  58. break;
  59. default:
  60. pr_debug("%s:session id %d: Ignore opcode[0x%x]\n", __func__,
  61. audio->ac->session, opcode);
  62. break;
  63. }
  64. spin_unlock_irqrestore(&audio->dsp_lock, flags);
  65. }
  66. void audio_in_get_dsp_frames(void *priv,
  67. uint32_t token, uint32_t *payload)
  68. {
  69. struct q6audio_in *audio = (struct q6audio_in *)priv;
  70. uint32_t index;
  71. index = q6asm_get_buf_index_from_token(token);
  72. pr_debug("%s:session id %d: index=%d nr frames=%d offset[%d]\n",
  73. __func__, audio->ac->session, token, payload[9],
  74. payload[5]);
  75. pr_debug("%s:session id %d: timemsw=%d lsw=%d\n", __func__,
  76. audio->ac->session, payload[7], payload[6]);
  77. pr_debug("%s:session id %d: uflags=0x%8x uid=0x%8x\n", __func__,
  78. audio->ac->session, payload[8], payload[10]);
  79. pr_debug("%s:session id %d: enc_framesotal_size=0x%8x\n", __func__,
  80. audio->ac->session, payload[4]);
  81. /* Ensure the index is within max array size: FRAME_NUM */
  82. if (index >= FRAME_NUM) {
  83. pr_err("%s: Invalid index %d\n",
  84. __func__, index);
  85. return;
  86. }
  87. audio->out_frame_info[index][0] = payload[9];
  88. audio->out_frame_info[index][1] = payload[5];
  89. /* statistics of read */
  90. atomic_add(payload[4], &audio->in_bytes);
  91. atomic_add(payload[9], &audio->in_samples);
  92. if (atomic_read(&audio->out_count) <= audio->str_cfg.buffer_count) {
  93. atomic_inc(&audio->out_count);
  94. wake_up(&audio->read_wait);
  95. }
  96. }