msm: audio: qdsp5: NT mode encoding support for AMRNB
Add Non Tunnel mode AMRNB encoding support for 7x27a.
Signed-off-by: Manish Dewangan <manish@codeaurora.org>
diff --git a/arch/arm/mach-msm/qdsp5/audio_amrnb_in.c b/arch/arm/mach-msm/qdsp5/audio_amrnb_in.c
index 8d99a3d..2b4ead9 100644
--- a/arch/arm/mach-msm/qdsp5/audio_amrnb_in.c
+++ b/arch/arm/mach-msm/qdsp5/audio_amrnb_in.c
@@ -2,7 +2,7 @@
*
* amrnb encoder device
*
- * Copyright (c) 2009, Code Aurora Forum. All rights reserved.
+ * Copyright (c) 2009, 2011 Code Aurora Forum. All rights reserved.
*
* This code is based in part on arch/arm/mach-msm/qdsp5/audio_in.c, which is
* Copyright (C) 2008 Google, Inc.
@@ -22,6 +22,10 @@
*
*/
+
+#include <asm/atomic.h>
+#include <asm/ioctls.h>
+
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/miscdevice.h>
@@ -31,31 +35,54 @@
#include <linux/dma-mapping.h>
#include <linux/debugfs.h>
#include <linux/delay.h>
-
-#include <asm/atomic.h>
-#include <asm/ioctls.h>
-#include <mach/msm_adsp.h>
-#include <mach/msm_rpcrouter.h>
#include <linux/msm_audio_amrnb.h>
+#include <linux/android_pmem.h>
+#include <linux/memory_alloc.h>
#include "audmgr.h"
+#include <mach/msm_rpcrouter.h>
+#include <mach/msm_memtypes.h>
+#include <mach/iommu.h>
+#include <mach/msm_subsystem_map.h>
+#include <mach/iommu_domains.h>
+
+#include <mach/msm_adsp.h>
+#include <mach/qdsp5/qdsp5audpreproc.h>
#include <mach/qdsp5/qdsp5audpreproccmdi.h>
#include <mach/qdsp5/qdsp5audpreprocmsg.h>
#include <mach/qdsp5/qdsp5audreccmdi.h>
#include <mach/qdsp5/qdsp5audrecmsg.h>
#include <mach/debug_mm.h>
+#define FRAME_HEADER_SIZE 8 /* 8 bytes frame header */
+#define NT_FRAME_HEADER_SIZE 24 /* 24 bytes frame header */
/* FRAME_NUM must be a power of two */
-#define FRAME_NUM (8)
-#define FRAME_SIZE (22 * 2)
-#define DMASZ (FRAME_SIZE * FRAME_NUM)
+#define FRAME_NUM 8
+#define AMRNB_FRAME_SIZE 36 /* 36 bytes data */
+/*Tunnel mode : 1536 bytes data + 8 byte header*/
+#define FRAME_SIZE (AMRNB_FRAME_SIZE + FRAME_HEADER_SIZE)
+/* 1536 bytes data + 24 meta field*/
+#define NT_FRAME_SIZE (AMRNB_FRAME_SIZE + NT_FRAME_HEADER_SIZE)
+#define DMASZ (FRAME_SIZE * FRAME_NUM)
+#define NT_DMASZ (NT_FRAME_SIZE * FRAME_NUM)
+#define OUT_FRAME_NUM 2
+#define OUT_BUFFER_SIZE (4 * 1024 + NT_FRAME_HEADER_SIZE)
+#define BUFFER_SIZE (OUT_BUFFER_SIZE * OUT_FRAME_NUM)
+
+/* Offset from beginning of buffer*/
+#define AUDPREPROC_AMRNB_EOS_FLG_OFFSET 0x0A
+#define AUDPREPROC_AMRNB_EOS_FLG_MASK 0x01
+#define AUDPREPROC_AMRNB_EOS_NONE 0x0 /* No EOS detected */
+#define AUDPREPROC_AMRNB_EOS_SET 0x1 /* EOS set in meta field */
struct buffer {
void *data;
uint32_t size;
uint32_t read;
uint32_t addr;
+ uint32_t used;
+ uint32_t mfield_sz;
};
struct audio_amrnb_in {
@@ -64,16 +91,39 @@
spinlock_t dsp_lock;
atomic_t in_bytes;
+ atomic_t in_samples;
struct mutex lock;
struct mutex read_lock;
wait_queue_head_t wait;
+ wait_queue_head_t wait_enable;
+ /*write section*/
+ struct buffer out[OUT_FRAME_NUM];
- uint16_t audrec_obj_idx;
+ uint8_t out_head;
+ uint8_t out_tail;
+ uint8_t out_needed; /* number of buffers the dsp is waiting for */
+ uint32_t out_count;
- /* configuration to use on enable */
+ struct mutex write_lock;
+ wait_queue_head_t write_wait;
+ int32_t out_phys; /* physical address of write buffer */
+ char *out_data;
+ uint8_t mfield; /* meta field embedded in data */
+ uint8_t wflush; /*write flush */
+ uint8_t rflush; /*read flush*/
+ uint32_t out_frame_cnt;
+
+ struct msm_adsp_module *audrec;
+ struct msm_adsp_module *audpre;
+
+
+ /* configuration to use on next enable */
+ uint32_t samp_rate;
+ uint32_t channel_mode;
uint32_t buffer_size;
uint32_t enc_type; /* 0 for WAV ,1 for AAC,10 for AMRNB */
+ uint32_t mode; /* T or NT Mode*/
struct msm_audio_amrnb_enc_config amrnb_enc_cfg;
uint32_t dsp_cnt;
@@ -81,86 +131,191 @@
uint32_t in_tail; /* next buffer read() will read */
uint32_t in_count; /* number of buffers available to read() */
+ uint32_t eos_ack;
+ uint32_t flush_ack;
+
+ const char *module_name;
+ unsigned queue_ids;
+ uint16_t enc_id; /* Session Id */
+
+ unsigned short samp_rate_index;
+ uint32_t audrec_obj_idx ;
+
struct audmgr audmgr;
/* data allocated for various buffers */
char *data;
dma_addr_t phys;
+ struct msm_mapped_buffer *map_v_write;
- int opened;
- int enabled;
- int running;
- int stopped; /* set when stopped, cleared on flush */
-
+ uint8_t opened;
+ uint8_t enabled;
+ uint8_t running;
+ uint8_t stopped; /* set when stopped, cleared on flush */
};
-static int audio_amrnb_in_dsp_enable(struct audio_amrnb_in *audio, int enable);
-static int audio_amrnb_in_encmem_config(struct audio_amrnb_in *audio);
-static int audio_amrnb_in_encparam_config(struct audio_amrnb_in *audio);
-static int audio_amrnb_in_dsp_read_buffer(struct audio_amrnb_in *audio,
- uint32_t read_cnt);
-static void audio_amrnb_in_flush(struct audio_amrnb_in *audio);
-static void audio_amrnb_in_dsp_event(void *data, unsigned id, uint16_t *msg);
-
-static struct audio_amrnb_in the_audio_amrnb_in;
-
-/* must be called with audio->lock held */
-static int audio_amrnb_in_enable(struct audio_amrnb_in *audio)
-{
- struct audmgr_config cfg;
- int rc;
-
- if (audio->enabled)
- return 0;
-
- cfg.tx_rate = RPC_AUD_DEF_SAMPLE_RATE_8000;
- cfg.rx_rate = RPC_AUD_DEF_SAMPLE_RATE_NONE;
- cfg.def_method = RPC_AUD_DEF_METHOD_RECORD;
- cfg.codec = RPC_AUD_DEF_CODEC_AMR_NB;
- cfg.snd_method = RPC_SND_METHOD_MIDI;
-
- rc = audmgr_enable(&audio->audmgr, &cfg);
- if (rc < 0)
- return rc;
-
- if (audrectask_enable(audio->enc_type, audio_amrnb_in_dsp_event,
- audio)) {
- audmgr_disable(&audio->audmgr);
- MM_ERR("audrec_enable failed\n");
- return -ENODEV;
- }
-
- audio->enabled = 1;
- audio_amrnb_in_dsp_enable(audio, 1);
-
- return 0;
-}
-
-/* must be called with audio->lock held */
-static int audio_amrnb_in_disable(struct audio_amrnb_in *audio)
-{
- if (audio->enabled) {
- audio->enabled = 0;
- audio_amrnb_in_dsp_enable(audio, 0);
- wake_up(&audio->wait);
- audrectask_disable(audio->enc_type, audio);
- audmgr_disable(&audio->audmgr);
- }
- return 0;
-}
-
-/* ------------------- dsp --------------------- */
-struct audio_amrnb_in_frame {
+struct audio_frame {
uint16_t frame_count_lsw;
uint16_t frame_count_msw;
uint16_t frame_length;
uint16_t erased_pcm;
unsigned char raw_bitstream[];
-} __attribute__((packed));
+} __packed;
-static void audio_amrnb_in_get_dsp_frames(struct audio_amrnb_in *audio)
+struct audio_frame_nt {
+ uint16_t metadata_len;
+ uint16_t frame_count_lsw;
+ uint16_t frame_count_msw;
+ uint16_t frame_length;
+ uint16_t erased_pcm;
+ uint16_t reserved;
+ uint16_t time_stamp_dword_lsw;
+ uint16_t time_stamp_dword_msw;
+ uint16_t time_stamp_lsw;
+ uint16_t time_stamp_msw;
+ uint16_t nflag_lsw;
+ uint16_t nflag_msw;
+ unsigned char raw_bitstream[]; /* samples */
+} __packed;
+
+struct amrnb_encoded_meta_out {
+ uint16_t metadata_len;
+ uint16_t time_stamp_dword_lsw;
+ uint16_t time_stamp_dword_msw;
+ uint16_t time_stamp_lsw;
+ uint16_t time_stamp_msw;
+ uint16_t nflag_lsw;
+ uint16_t nflag_msw;
+};
+
+/* Audrec Queue command sent macro's */
+#define audio_send_queue_pre(audio, cmd, len) \
+ msm_adsp_write(audio->audpre, QDSP_uPAudPreProcCmdQueue, cmd, len)
+
+#define audio_send_queue_recbs(audio, cmd, len) \
+ msm_adsp_write(audio->audrec, ((audio->queue_ids & 0xFFFF0000) >> 16),\
+ cmd, len)
+#define audio_send_queue_rec(audio, cmd, len) \
+ msm_adsp_write(audio->audrec, (audio->queue_ids & 0x0000FFFF),\
+ cmd, len)
+
+static int audamrnb_in_dsp_enable(struct audio_amrnb_in *audio, int enable);
+static int audamrnb_in_encparam_config(struct audio_amrnb_in *audio);
+static int audamrnb_in_encmem_config(struct audio_amrnb_in *audio);
+static int audamrnb_in_dsp_read_buffer(struct audio_amrnb_in *audio,
+ uint32_t read_cnt);
+static void audamrnb_in_flush(struct audio_amrnb_in *audio);
+
+static void audamrnb_in_get_dsp_frames(struct audio_amrnb_in *audio);
+static int audpcm_config(struct audio_amrnb_in *audio);
+static void audamrnb_out_flush(struct audio_amrnb_in *audio);
+static int audamrnb_in_routing_mode_config(struct audio_amrnb_in *audio);
+static void audrec_pcm_send_data(struct audio_amrnb_in *audio, unsigned needed);
+static void audamrnb_nt_in_get_dsp_frames(struct audio_amrnb_in *audio);
+static void audamrnb_in_flush(struct audio_amrnb_in *audio);
+
+static unsigned convert_samp_index(unsigned index)
{
- struct audio_amrnb_in_frame *frame;
+ switch (index) {
+ case RPC_AUD_DEF_SAMPLE_RATE_48000: return 48000;
+ case RPC_AUD_DEF_SAMPLE_RATE_44100: return 44100;
+ case RPC_AUD_DEF_SAMPLE_RATE_32000: return 32000;
+ case RPC_AUD_DEF_SAMPLE_RATE_24000: return 24000;
+ case RPC_AUD_DEF_SAMPLE_RATE_22050: return 22050;
+ case RPC_AUD_DEF_SAMPLE_RATE_16000: return 16000;
+ case RPC_AUD_DEF_SAMPLE_RATE_12000: return 12000;
+ case RPC_AUD_DEF_SAMPLE_RATE_11025: return 11025;
+ case RPC_AUD_DEF_SAMPLE_RATE_8000: return 8000;
+ default: return 11025;
+ }
+}
+
+/* must be called with audio->lock held */
+static int audamrnb_in_enable(struct audio_amrnb_in *audio)
+{
+ struct audmgr_config cfg;
+ int32_t rc;
+
+ if (audio->enabled)
+ return 0;
+
+ cfg.tx_rate = audio->samp_rate;
+ cfg.rx_rate = RPC_AUD_DEF_SAMPLE_RATE_NONE;
+ cfg.def_method = RPC_AUD_DEF_METHOD_RECORD;
+ cfg.codec = RPC_AUD_DEF_CODEC_AMR_NB;
+ cfg.snd_method = RPC_SND_METHOD_MIDI;
+
+ if (audio->mode == MSM_AUD_ENC_MODE_TUNNEL) {
+ rc = audmgr_enable(&audio->audmgr, &cfg);
+ if (rc < 0)
+ return rc;
+
+ if (msm_adsp_enable(audio->audpre)) {
+ audmgr_disable(&audio->audmgr);
+ MM_ERR("msm_adsp_enable(audpre) failed\n");
+ return -ENODEV;
+ }
+ }
+ if (msm_adsp_enable(audio->audrec)) {
+ if (audio->mode == MSM_AUD_ENC_MODE_TUNNEL) {
+ audmgr_disable(&audio->audmgr);
+ msm_adsp_disable(audio->audpre);
+ }
+ MM_ERR("msm_adsp_enable(audrec) failed\n");
+ return -ENODEV;
+ }
+
+ audio->enabled = 1;
+ audamrnb_in_dsp_enable(audio, 1);
+
+ return 0;
+}
+
+/* must be called with audio->lock held */
+static int audamrnb_in_disable(struct audio_amrnb_in *audio)
+{
+ if (audio->enabled) {
+ audio->enabled = 0;
+
+ audamrnb_in_dsp_enable(audio, 0);
+
+ wake_up(&audio->wait);
+ wait_event_interruptible_timeout(audio->wait_enable,
+ audio->running == 0, 1*HZ);
+ msm_adsp_disable(audio->audrec);
+ if (audio->mode == MSM_AUD_ENC_MODE_TUNNEL) {
+ msm_adsp_disable(audio->audpre);
+ audmgr_disable(&audio->audmgr);
+ }
+ }
+ return 0;
+}
+
+/* ------------------- dsp --------------------- */
+static void audpre_dsp_event(void *data, unsigned id, size_t len,
+ void (*getevent)(void *ptr, size_t len))
+{
+ uint16_t msg[2];
+ getevent(msg, sizeof(msg));
+
+ switch (id) {
+ case AUDPREPROC_MSG_CMD_CFG_DONE_MSG:
+ MM_DBG("type %d, status_flag %d\n", msg[0], msg[1]);
+ break;
+ case AUDPREPROC_MSG_ERROR_MSG_ID:
+ MM_ERR("err_index %d\n", msg[0]);
+ break;
+ case ADSP_MESSAGE_ID:
+ MM_DBG("Received ADSP event: module enable(audpreproctask)\n");
+ break;
+ default:
+ MM_ERR("unknown event %d\n", id);
+ }
+}
+
+static void audamrnb_in_get_dsp_frames(struct audio_amrnb_in *audio)
+{
+ struct audio_frame *frame;
uint32_t index;
unsigned long flags;
index = audio->in_head;
@@ -168,89 +323,264 @@
frame = (void *) (((char *)audio->in[index].data) -
sizeof(*frame));
spin_lock_irqsave(&audio->dsp_lock, flags);
- audio->in[index].size = FRAME_SIZE - (sizeof(*frame)); /* Send
- Complete Transcoded Data, not actual frame part */
+
+ /* Send Complete Transcoded Data, not actual frame part */
+ audio->in[index].size = FRAME_SIZE - (sizeof(*frame));
+ /* statistics of read */
+ atomic_add(audio->in[index].size, &audio->in_bytes);
+ atomic_add(1, &audio->in_samples);
audio->in_head = (audio->in_head + 1) & (FRAME_NUM - 1);
/* If overflow, move the tail index foward. */
- if (audio->in_head == audio->in_tail)
+ if (audio->in_head == audio->in_tail) {
+ MM_ERR("Error! not able to keep up the read\n");
audio->in_tail = (audio->in_tail + 1) & (FRAME_NUM - 1);
- else
+ MM_ERR("in_count = %d\n", audio->in_count);
+ } else
audio->in_count++;
- audio_amrnb_in_dsp_read_buffer(audio, audio->dsp_cnt++);
+ audamrnb_in_dsp_read_buffer(audio, audio->dsp_cnt++);
spin_unlock_irqrestore(&audio->dsp_lock, flags);
wake_up(&audio->wait);
}
-static void audio_amrnb_in_dsp_event(void *data, unsigned id, uint16_t *msg)
+static void audamrnb_nt_in_get_dsp_frames(struct audio_amrnb_in *audio)
+{
+ struct audio_frame_nt *nt_frame;
+ uint32_t index;
+ unsigned long flags;
+
+ index = audio->in_head;
+ nt_frame = (void *) (((char *)audio->in[index].data) - \
+ sizeof(struct audio_frame_nt));
+ spin_lock_irqsave(&audio->dsp_lock, flags);
+ audio->in[index].size = nt_frame->frame_length;
+ /* statistics of read */
+ atomic_add(audio->in[index].size, &audio->in_bytes);
+ atomic_add(1, &audio->in_samples);
+
+ audio->in_head = (audio->in_head + 1) & (FRAME_NUM - 1);
+
+ /* If overflow, move the tail index foward. */
+ if (audio->in_head == audio->in_tail)
+ MM_DBG("Error! not able to keep up the read\n");
+ else
+ audio->in_count++;
+
+ spin_unlock_irqrestore(&audio->dsp_lock, flags);
+ wake_up(&audio->wait);
+}
+
+static int audrec_pcm_buffer_ptr_refresh(struct audio_amrnb_in *audio,
+ unsigned idx, unsigned len)
+{
+ struct audrec_cmd_pcm_buffer_ptr_refresh_arm_enc cmd;
+
+ if (len == NT_FRAME_HEADER_SIZE)
+ len = len / 2;
+ else
+ len = (len + NT_FRAME_HEADER_SIZE) / 2;
+ MM_DBG("len = %d\n", len);
+ memset(&cmd, 0, sizeof(cmd));
+ cmd.cmd_id = AUDREC_CMD_PCM_BUFFER_PTR_REFRESH_ARM_TO_ENC;
+ cmd.num_buffers = 1;
+ if (cmd.num_buffers == 1) {
+ cmd.buf_address_length[0] = (audio->out[idx].addr &
+ 0xffff0000) >> 16;
+ cmd.buf_address_length[1] = (audio->out[idx].addr &
+ 0x0000ffff);
+ cmd.buf_address_length[2] = (len & 0xffff0000) >> 16;
+ cmd.buf_address_length[3] = (len & 0x0000ffff);
+ }
+ audio->out_frame_cnt++;
+ return audio_send_queue_rec(audio, &cmd, sizeof(cmd));
+}
+
+static int audpcm_config(struct audio_amrnb_in *audio)
+{
+ struct audrec_cmd_pcm_cfg_arm_to_enc cmd;
+ MM_DBG("\n");
+ memset(&cmd, 0, sizeof(cmd));
+ cmd.cmd_id = AUDREC_CMD_PCM_CFG_ARM_TO_ENC;
+ cmd.config_update_flag = AUDREC_PCM_CONFIG_UPDATE_FLAG_ENABLE;
+ cmd.enable_flag = AUDREC_ENABLE_FLAG_VALUE;
+ cmd.sampling_freq = convert_samp_index(audio->samp_rate);
+ if (!audio->channel_mode)
+ cmd.channels = 1;
+ else
+ cmd.channels = 2;
+ cmd.frequency_of_intimation = 1;
+ cmd.max_number_of_buffers = OUT_FRAME_NUM;
+ return audio_send_queue_rec(audio, &cmd, sizeof(cmd));
+}
+
+
+static int audamrnb_in_routing_mode_config(struct audio_amrnb_in *audio)
+{
+ struct audrec_cmd_routing_mode cmd;
+
+ MM_DBG("\n");
+ memset(&cmd, 0, sizeof(cmd));
+ cmd.cmd_id = AUDREC_CMD_ROUTING_MODE;
+ if (audio->mode == MSM_AUD_ENC_MODE_NONTUNNEL)
+ cmd.routing_mode = 1;
+ return audio_send_queue_rec(audio, &cmd, sizeof(cmd));
+}
+
+static void audrec_dsp_event(void *data, unsigned id, size_t len,
+ void (*getevent)(void *ptr, size_t len))
{
struct audio_amrnb_in *audio = data;
+ if (data)
+ audio = data;
+ else {
+ MM_ERR("invalid data for event %x\n", id);
+ return;
+ }
switch (id) {
- case AUDREC_MSG_CMD_CFG_DONE_MSG:
- MM_DBG("CFG_DONE_MSG\n");
- if (msg[0] & AUDREC_MSG_CFG_DONE_ENC_ENA) {
- audio->audrec_obj_idx = msg[1];
- audio_amrnb_in_encmem_config(audio);
+ case AUDREC_MSG_CMD_CFG_DONE_MSG: {
+ struct audrec_msg_cmd_cfg_done_msg cmd_cfg_done_msg;
+ getevent(&cmd_cfg_done_msg, AUDREC_MSG_CMD_CFG_DONE_MSG_LEN);
+ if (cmd_cfg_done_msg.audrec_enc_type & \
+ AUDREC_MSG_CFG_DONE_ENC_ENA) {
+ audio->audrec_obj_idx = cmd_cfg_done_msg.audrec_obj_idx;
+ MM_DBG("CFG ENABLED\n");
+ if (audio->mode == MSM_AUD_ENC_MODE_NONTUNNEL) {
+ MM_DBG("routing command\n");
+ audamrnb_in_routing_mode_config(audio);
+ } else {
+ audamrnb_in_encmem_config(audio);
+ }
} else {
+ MM_DBG("CFG SLEEP\n");
audio->running = 0;
+ wake_up(&audio->wait_enable);
}
break;
- case AUDREC_MSG_CMD_AREC_MEM_CFG_DONE_MSG: {
- MM_DBG("AREC_MEM_CFG_DONE_MSG\n");
- if (msg[0] == audio->audrec_obj_idx)
- audio_amrnb_in_encparam_config(audio);
- else
- MM_ERR("AREC_MEM_CFG_DONE_MSG ERR\n");
+ }
+ case AUDREC_MSG_CMD_ROUTING_MODE_DONE_MSG: {
+ struct audrec_msg_cmd_routing_mode_done_msg \
+ routing_msg;
+ getevent(&routing_msg, AUDREC_MSG_CMD_ROUTING_MODE_DONE_MSG);
+ MM_DBG("AUDREC_MSG_CMD_ROUTING_MODE_DONE_MSG");
+ if (routing_msg.configuration == 0) {
+ MM_ERR("routing configuration failed\n");
+ audio->running = 0;
+ wake_up(&audio->wait_enable);
+ } else
+ audamrnb_in_encmem_config(audio);
break;
}
- case AUDREC_MSG_CMD_AREC_PARAM_CFG_DONE_MSG: {
- MM_DBG("AREC_PARAM_CFG_DONE_MSG\n");
- if (msg[0] == audio->audrec_obj_idx)
- audio->running = 1;
+ case AUDREC_MSG_CMD_AREC_MEM_CFG_DONE_MSG: {
+ MM_DBG("AREC_MEM_CFG_DONE_MSG\n");
+ if (audio->mode == MSM_AUD_ENC_MODE_TUNNEL)
+ audamrnb_in_encparam_config(audio);
else
- MM_ERR("AREC_PARAM_CFG_DONE_MSG ERR\n");
+ audpcm_config(audio);
+ break;
+ }
+
+ case AUDREC_CMD_PCM_CFG_ARM_TO_ENC_DONE_MSG: {
+ MM_DBG("AUDREC_CMD_PCM_CFG_ARM_TO_ENC_DONE_MSG");
+ audamrnb_in_encparam_config(audio);
+ break;
+ }
+ case AUDREC_MSG_CMD_AREC_PARAM_CFG_DONE_MSG: {
+ MM_DBG("AUDREC_MSG_CMD_AREC_PARAM_CFG_DONE_MSG\n");
+ audio->running = 1;
+ wake_up(&audio->wait_enable);
+ if (audio->mode == MSM_AUD_ENC_MODE_NONTUNNEL)
+ audrec_pcm_send_data(audio, 1);
+ break;
+ }
+ case AUDREC_CMD_PCM_BUFFER_PTR_UPDATE_ARM_TO_ENC_MSG: {
+ MM_DBG("ptr_update recieved from DSP\n");
+ audrec_pcm_send_data(audio, 1);
+ break;
+ }
+ case AUDREC_MSG_NO_EXT_PKT_AVAILABLE_MSG: {
+ struct audrec_msg_no_ext_pkt_avail_msg err_msg;
+ getevent(&err_msg, AUDREC_MSG_NO_EXT_PKT_AVAILABLE_MSG_LEN);
+ MM_DBG("NO_EXT_PKT_AVAILABLE_MSG %x\n",\
+ err_msg.audrec_err_id);
break;
}
case AUDREC_MSG_PACKET_READY_MSG: {
- MM_DBG("AUDREC_MSG_PACKET_READY_MSG\n");
- if (msg[0] == audio->audrec_obj_idx)
- audio_amrnb_in_get_dsp_frames(audio);
- else
- MM_ERR("PACKET_READY_MSG ERR\n");
+ struct audrec_msg_packet_ready_msg pkt_ready_msg;
+
+ getevent(&pkt_ready_msg, AUDREC_MSG_PACKET_READY_MSG_LEN);
+ MM_DBG("UP_PACKET_READY_MSG: write cnt msw %d \
+ write cnt lsw %d read cnt msw %d read cnt lsw %d \n",\
+ pkt_ready_msg.pkt_counter_msw, \
+ pkt_ready_msg.pkt_counter_lsw, \
+ pkt_ready_msg.pkt_read_cnt_msw, \
+ pkt_ready_msg.pkt_read_cnt_lsw);
+
+ audamrnb_in_get_dsp_frames(audio);
break;
}
- case AUDREC_MSG_FATAL_ERR_MSG: {
- MM_ERR("FATAL_ERR_MSG %x\n", msg[0]);
+ case AUDREC_UP_NT_PACKET_READY_MSG: {
+ struct audrec_up_nt_packet_ready_msg pkt_ready_msg;
+
+ getevent(&pkt_ready_msg, AUDREC_UP_NT_PACKET_READY_MSG_LEN);
+ MM_DBG("UP_NT_PACKET_READY_MSG: write cnt lsw %d \
+ write cnt msw %d read cnt lsw %d read cnt msw %d \n",\
+ pkt_ready_msg.audrec_packetwrite_cnt_lsw, \
+ pkt_ready_msg.audrec_packetwrite_cnt_msw, \
+ pkt_ready_msg.audrec_upprev_readcount_lsw, \
+ pkt_ready_msg.audrec_upprev_readcount_msw);
+
+ audamrnb_nt_in_get_dsp_frames(audio);
break;
}
+ case AUDREC_CMD_FLUSH_DONE_MSG: {
+ audio->wflush = 0;
+ audio->rflush = 0;
+ audio->flush_ack = 1;
+ wake_up(&audio->write_wait);
+ MM_DBG("flush ack recieved\n");
+ break;
+ }
+ case ADSP_MESSAGE_ID:
+ MM_DBG("Received ADSP event: module \
+ enable/disable(audrectask)\n");
+ break;
default:
MM_ERR("unknown event %d\n", id);
}
}
-static int audio_amrnb_in_dsp_enable(struct audio_amrnb_in *audio, int enable)
+struct msm_adsp_ops audpre_amrnb_adsp_ops = {
+ .event = audpre_dsp_event,
+};
+
+struct msm_adsp_ops audrec_amrnb_adsp_ops = {
+ .event = audrec_dsp_event,
+};
+
+static int audamrnb_in_dsp_enable(struct audio_amrnb_in *audio, int enable)
{
struct audrec_cmd_enc_cfg cmd;
memset(&cmd, 0, sizeof(cmd));
cmd.cmd_id = AUDREC_CMD_ENC_CFG;
- cmd.audrec_enc_type = (audio->enc_type) |
+ cmd.audrec_enc_type = (audio->enc_type & 0xFF) |
(enable ? AUDREC_CMD_ENC_ENA : AUDREC_CMD_ENC_DIS);
/* Don't care on enable, required on disable */
cmd.audrec_obj_idx = audio->audrec_obj_idx;
- return audrectask_send_cmdqueue(&cmd, sizeof(cmd));
+ return audio_send_queue_rec(audio, &cmd, sizeof(cmd));
}
-static int audio_amrnb_in_encmem_config(struct audio_amrnb_in *audio)
+static int audamrnb_in_encmem_config(struct audio_amrnb_in *audio)
{
struct audrec_cmd_arecmem_cfg cmd;
uint16_t *data = (void *) audio->data;
- unsigned cnt;
+ uint8_t n;
+ uint16_t header_len = 0;
memset(&cmd, 0, sizeof(cmd));
@@ -264,19 +594,24 @@
cmd.audrec_extpkt_buffer_num = FRAME_NUM;
/* prepare buffer pointers:
- * 4 halfword header + Frame Raw Packet (20ms data)
+ * T:36 bytes amrnb packet + 4 halfword header
+ * NT:36 bytes amrnb packet + 12 halfword header
*/
- for (cnt = 0; cnt < FRAME_NUM; cnt++) {
- audio->in[cnt].data = data + 4; /* Pointer to Raw Packet part*/
- MM_DBG(" audio->in[%d].data = %x \n", cnt,
- (unsigned int)audio->in[cnt].data);
- data += 22; /* Point to next Frame buffer */
+ if (audio->mode == MSM_AUD_ENC_MODE_TUNNEL)
+ header_len = FRAME_HEADER_SIZE/2;
+ else
+ header_len = NT_FRAME_HEADER_SIZE/2;
+
+ for (n = 0; n < FRAME_NUM; n++) {
+ audio->in[n].data = data + header_len;
+ data += (AMRNB_FRAME_SIZE/2) + header_len;
+ MM_DBG("0x%8x\n", (uint32_t)(audio->in[n].data - header_len*2));
}
- return audrectask_send_cmdqueue(&cmd, sizeof(cmd));
+ return audio_send_queue_rec(audio, &cmd, sizeof(cmd));
}
-static int audio_amrnb_in_encparam_config(struct audio_amrnb_in *audio)
+static int audamrnb_in_encparam_config(struct audio_amrnb_in *audio)
{
struct audrec_cmd_arecparam_amrnb_cfg cmd;
@@ -284,7 +619,7 @@
cmd.common.cmd_id = AUDREC_CMD_ARECPARAM_CFG;
cmd.common.audrec_obj_idx = audio->audrec_obj_idx;
- cmd.samp_rate_idx = 0xb; /* 8k Sampling rate */
+ cmd.samp_rate_idx = audio->samp_rate_index; /* 8k Sampling rate */
cmd.voicememoencweight1 = audio->amrnb_enc_cfg.voicememoencweight1;
cmd.voicememoencweight2 = audio->amrnb_enc_cfg.voicememoencweight2;
cmd.voicememoencweight3 = audio->amrnb_enc_cfg.voicememoencweight3;
@@ -311,10 +646,18 @@
MM_DBG("cmd.test_mode = 0x%4x\n", cmd.test_mode);
MM_DBG("cmd.used_mode = 0x%4x\n", cmd.used_mode);
- return audrectask_send_cmdqueue(&cmd, sizeof(cmd));
+ return audio_send_queue_rec(audio, &cmd, sizeof(cmd));
}
-static int audio_amrnb_in_dsp_read_buffer(struct audio_amrnb_in *audio,
+static int audamrnb_flush_command(struct audio_amrnb_in *audio)
+{
+ struct audrec_cmd_flush cmd;
+ MM_DBG("\n");
+ memset(&cmd, 0, sizeof(cmd));
+ cmd.cmd_id = AUDREC_CMD_FLUSH;
+ return audio_send_queue_rec(audio, &cmd, sizeof(cmd));
+}
+static int audamrnb_in_dsp_read_buffer(struct audio_amrnb_in *audio,
uint32_t read_cnt)
{
audrec_cmd_packet_ext_ptr cmd;
@@ -325,71 +668,132 @@
cmd.curr_rec_count_msw = read_cnt >> 16;
cmd.curr_rec_count_lsw = read_cnt;
- return audrectask_send_bitstreamqueue(&cmd, sizeof(cmd));
+ return audio_send_queue_recbs(audio, &cmd, sizeof(cmd));
}
-static void audio_amrnb_in_flush(struct audio_amrnb_in *audio)
+/* ------------------- device --------------------- */
+
+static void audamrnb_ioport_reset(struct audio_amrnb_in *audio)
{
- int i;
+ /* Make sure read/write thread are free from
+ * sleep and knowing that system is not able
+ * to process io request at the moment
+ */
+ wake_up(&audio->write_wait);
+ mutex_lock(&audio->write_lock);
+ audamrnb_in_flush(audio);
+ mutex_unlock(&audio->write_lock);
+ wake_up(&audio->wait);
+ mutex_lock(&audio->read_lock);
+ audamrnb_out_flush(audio);
+ mutex_unlock(&audio->read_lock);
+}
+
+static void audamrnb_in_flush(struct audio_amrnb_in *audio)
+{
+ uint8_t i;
audio->dsp_cnt = 0;
audio->in_head = 0;
audio->in_tail = 0;
audio->in_count = 0;
- for (i = 0; i < FRAME_NUM; i++) {
+ audio->eos_ack = 0;
+ for (i = FRAME_NUM-1; i >= 0; i--) {
audio->in[i].size = 0;
audio->in[i].read = 0;
}
+ MM_DBG("in_bytes %d\n", atomic_read(&audio->in_bytes));
+ MM_DBG("in_samples %d\n", atomic_read(&audio->in_samples));
+ atomic_set(&audio->in_bytes, 0);
+ atomic_set(&audio->in_samples, 0);
}
+static void audamrnb_out_flush(struct audio_amrnb_in *audio)
+{
+ uint8_t i;
+
+ audio->out_head = 0;
+ audio->out_tail = 0;
+ audio->out_count = 0;
+ for (i = OUT_FRAME_NUM-1; i >= 0; i--) {
+ audio->out[i].size = 0;
+ audio->out[i].read = 0;
+ audio->out[i].used = 0;
+ }
+}
/* ------------------- device --------------------- */
-static long audio_amrnb_in_ioctl(struct file *file,
+static long audamrnb_in_ioctl(struct file *file,
unsigned int cmd, unsigned long arg)
{
struct audio_amrnb_in *audio = file->private_data;
- int rc;
+ int32_t rc = 0;
+ MM_DBG("\n");
if (cmd == AUDIO_GET_STATS) {
struct msm_audio_stats stats;
stats.byte_count = atomic_read(&audio->in_bytes);
+ stats.sample_count = atomic_read(&audio->in_samples);
if (copy_to_user((void *) arg, &stats, sizeof(stats)))
return -EFAULT;
- return 0;
+ return rc;
}
mutex_lock(&audio->lock);
switch (cmd) {
- case AUDIO_START:
- rc = audio_amrnb_in_enable(audio);
+ case AUDIO_START: {
+ rc = audamrnb_in_enable(audio);
+ if (!rc) {
+ rc =
+ wait_event_interruptible_timeout(audio->wait_enable,
+ audio->running != 0, 1*HZ);
+ MM_INFO("state %d rc = %d\n", audio->running, rc);
+
+ if (audio->running == 0)
+ rc = -ENODEV;
+ else
+ rc = 0;
+ }
+ audio->stopped = 0;
break;
- case AUDIO_STOP:
- rc = audio_amrnb_in_disable(audio);
+ }
+ case AUDIO_STOP: {
+ rc = audamrnb_in_disable(audio);
audio->stopped = 1;
break;
- case AUDIO_FLUSH:
- if (audio->stopped) {
- /* Make sure we're stopped and we wake any threads
- * that might be blocked holding the read_lock.
- * While audio->stopped read threads will always
- * exit immediately.
- */
- wake_up(&audio->wait);
- mutex_lock(&audio->read_lock);
- audio_amrnb_in_flush(audio);
- mutex_unlock(&audio->read_lock);
+ }
+ case AUDIO_FLUSH: {
+ MM_DBG("AUDIO_FLUSH\n");
+ audio->rflush = 1;
+ audio->wflush = 1;
+ audamrnb_ioport_reset(audio);
+ if (audio->running) {
+ audamrnb_flush_command(audio);
+ rc = wait_event_interruptible(audio->write_wait,
+ !audio->wflush);
+ if (rc < 0) {
+ MM_ERR("AUDIO_FLUSH interrupted\n");
+ rc = -EINTR;
+ }
+ } else {
+ audio->rflush = 0;
+ audio->wflush = 0;
}
- case AUDIO_SET_CONFIG: {
- rc = -EINVAL; /* Buffer size better to come from upper */
break;
}
case AUDIO_GET_CONFIG: {
- struct msm_audio_config cfg;
- cfg.buffer_size = audio->buffer_size;
- cfg.buffer_count = FRAME_NUM;
- cfg.sample_rate = 8000;
+ struct msm_audio_config cfg;
+ memset(&cfg, 0, sizeof(cfg));
+ if (audio->mode == MSM_AUD_ENC_MODE_NONTUNNEL) {
+ cfg.buffer_size = OUT_BUFFER_SIZE;
+ cfg.buffer_count = OUT_FRAME_NUM;
+ } else {
+ cfg.buffer_size = audio->buffer_size;
+ cfg.buffer_count = FRAME_NUM;
+ }
+ cfg.sample_rate = convert_samp_index(audio->samp_rate);
cfg.channel_count = 1;
- cfg.type = 10;
+ cfg.type = 0;
cfg.unused[0] = 0;
cfg.unused[1] = 0;
cfg.unused[2] = 0;
@@ -399,6 +803,37 @@
rc = 0;
break;
}
+ case AUDIO_GET_STREAM_CONFIG: {
+ struct msm_audio_stream_config cfg;
+ memset(&cfg, 0, sizeof(cfg));
+ cfg.buffer_size = audio->buffer_size;
+ cfg.buffer_count = FRAME_NUM;
+ if (copy_to_user((void *)arg, &cfg, sizeof(cfg)))
+ rc = -EFAULT;
+ else
+ rc = 0;
+ break;
+ }
+ case AUDIO_SET_STREAM_CONFIG: {
+ struct msm_audio_stream_config cfg;
+ if (copy_from_user(&cfg, (void *) arg, sizeof(cfg))) {
+ rc = -EFAULT;
+ break;
+ }
+ /* Allow only single frame */
+ if (audio->mode == MSM_AUD_ENC_MODE_TUNNEL) {
+ if (cfg.buffer_size != (FRAME_SIZE - 8))
+ rc = -EINVAL;
+ break;
+ } else {
+ if (cfg.buffer_size != (AMRNB_FRAME_SIZE + 14))
+ rc = -EINVAL;
+ break;
+ }
+ audio->buffer_size = cfg.buffer_size;
+ break;
+ }
+
case AUDIO_GET_AMRNB_ENC_CONFIG: {
if (copy_to_user((void *)arg, &audio->amrnb_enc_cfg,
sizeof(audio->amrnb_enc_cfg)))
@@ -435,7 +870,7 @@
return rc;
}
-static ssize_t audio_amrnb_in_read(struct file *file,
+static ssize_t audamrnb_in_read(struct file *file,
char __user *buf,
size_t count, loff_t *pos)
{
@@ -445,24 +880,55 @@
void *data;
uint32_t index;
uint32_t size;
- int rc = 0;
-
+ int32_t rc = 0;
+ struct amrnb_encoded_meta_out meta_field;
+ struct audio_frame_nt *nt_frame;
+ MM_DBG("count = %d\n", count);
mutex_lock(&audio->read_lock);
while (count > 0) {
rc = wait_event_interruptible(
- audio->wait, (audio->in_count > 0) || audio->stopped);
+ audio->wait, (audio->in_count > 0) || audio->stopped ||
+ audio->rflush);
if (rc < 0)
break;
- if (audio->stopped) {
+ if (audio->rflush) {
rc = -EBUSY;
break;
}
+ if (audio->stopped && !audio->in_count) {
+ MM_DBG("Driver in stop state, No more buffer to read");
+ rc = 0;/* End of File */
+ break;
+ }
index = audio->in_tail;
data = (uint8_t *) audio->in[index].data;
size = audio->in[index].size;
+
+ if (audio->mode == MSM_AUD_ENC_MODE_NONTUNNEL) {
+ nt_frame = (struct audio_frame_nt *)(data -
+ sizeof(struct audio_frame_nt));
+ memcpy((char *)&meta_field.time_stamp_dword_lsw,
+ (char *)&nt_frame->time_stamp_dword_lsw,
+ (sizeof(struct amrnb_encoded_meta_out) - \
+ sizeof(uint16_t)));
+ meta_field.metadata_len =
+ sizeof(struct amrnb_encoded_meta_out);
+ if (copy_to_user((char *)start, (char *)&meta_field,
+ sizeof(struct amrnb_encoded_meta_out))) {
+ rc = -EFAULT;
+ break;
+ }
+ if (nt_frame->nflag_lsw & 0x0001) {
+ MM_ERR("recieved EOS in read call\n");
+ audio->eos_ack = 1;
+ }
+ buf += sizeof(struct amrnb_encoded_meta_out);
+ count -= sizeof(struct amrnb_encoded_meta_out);
+ }
if (count >= size) {
+ /* order the reads on the buffer */
dma_coherent_post_ops();
if (copy_to_user(buf, data, size)) {
rc = -EFAULT;
@@ -470,10 +936,9 @@
}
spin_lock_irqsave(&audio->dsp_lock, flags);
if (index != audio->in_tail) {
- /* overrun -- data is invalid
- and we need to retry */
- spin_unlock_irqrestore(&audio->dsp_lock,
- flags);
+ /* overrun -- data is
+ * invalid and we need to retry */
+ spin_unlock_irqrestore(&audio->dsp_lock, flags);
continue;
}
audio->in[index].size = 0;
@@ -482,10 +947,21 @@
spin_unlock_irqrestore(&audio->dsp_lock, flags);
count -= size;
buf += size;
+ if ((audio->mode == MSM_AUD_ENC_MODE_NONTUNNEL)) {
+ if (!audio->eos_ack) {
+ MM_DBG("sending read ptr command \
+ %d %d\n",
+ audio->dsp_cnt,
+ audio->in_tail);
+ audamrnb_in_dsp_read_buffer(audio,
+ audio->dsp_cnt++);
+ }
+ }
} else {
MM_ERR("short read\n");
break;
}
+
}
mutex_unlock(&audio->read_lock);
@@ -495,55 +971,306 @@
return rc;
}
-static ssize_t audio_amrnb_in_write(struct file *file,
+static void audrec_pcm_send_data(struct audio_amrnb_in *audio, unsigned needed)
+{
+ struct buffer *frame;
+ unsigned long flags;
+ MM_DBG("\n");
+ spin_lock_irqsave(&audio->dsp_lock, flags);
+ if (!audio->running)
+ goto done;
+
+ if (needed && !audio->wflush) {
+ /* We were called from the callback because the DSP
+ * requested more data. Note that the DSP does want
+ * more data, and if a buffer was in-flight, mark it
+ * as available (since the DSP must now be done with
+ * it).
+ */
+ audio->out_needed = 1;
+ frame = audio->out + audio->out_tail;
+ if (frame->used == 0xffffffff) {
+ MM_DBG("frame %d free\n", audio->out_tail);
+ frame->used = 0;
+ audio->out_tail ^= 1;
+ wake_up(&audio->write_wait);
+ }
+ }
+
+ if (audio->out_needed) {
+ /* If the DSP currently wants data and we have a
+ * buffer available, we will send it and reset
+ * the needed flag. We'll mark the buffer as in-flight
+ * so that it won't be recycled until the next buffer
+ * is requested
+ */
+
+ frame = audio->out + audio->out_tail;
+ if (frame->used) {
+ BUG_ON(frame->used == 0xffffffff);
+ audrec_pcm_buffer_ptr_refresh(audio,
+ audio->out_tail,
+ frame->used);
+ frame->used = 0xffffffff;
+ audio->out_needed = 0;
+ }
+ }
+ done:
+ spin_unlock_irqrestore(&audio->dsp_lock, flags);
+}
+
+static int audamrnb_in_fsync(struct file *file, int datasync)
+
+{
+ struct audio_amrnb_in *audio = file->private_data;
+ int32_t rc = 0;
+
+ MM_DBG("\n"); /* Macro prints the file name and function */
+ if (!audio->running || (audio->mode == MSM_AUD_ENC_MODE_TUNNEL)) {
+ rc = -EINVAL;
+ goto done_nolock;
+ }
+
+ mutex_lock(&audio->write_lock);
+
+ rc = wait_event_interruptible(audio->write_wait,
+ audio->wflush);
+ MM_DBG("waked on by some event audio->wflush = %d\n", audio->wflush);
+
+ if (rc < 0)
+ goto done;
+ else if (audio->wflush) {
+ rc = -EBUSY;
+ goto done;
+ }
+done:
+ mutex_unlock(&audio->write_lock);
+done_nolock:
+ return rc;
+
+}
+
+int audrec_amrnb_process_eos(struct audio_amrnb_in *audio,
+ const char __user *buf_start, unsigned short mfield_size)
+{
+ struct buffer *frame;
+ int32_t rc = 0;
+
+ frame = audio->out + audio->out_head;
+
+ rc = wait_event_interruptible(audio->write_wait,
+ (audio->out_needed &&
+ audio->out[0].used == 0 &&
+ audio->out[1].used == 0)
+ || (audio->stopped)
+ || (audio->wflush));
+
+ if (rc < 0)
+ goto done;
+ if (audio->stopped || audio->wflush) {
+ rc = -EBUSY;
+ goto done;
+ }
+ if (copy_from_user(frame->data, buf_start, mfield_size)) {
+ rc = -EFAULT;
+ goto done;
+ }
+
+ frame->mfield_sz = mfield_size;
+ audio->out_head ^= 1;
+ frame->used = mfield_size;
+ MM_DBG("copying meta_out frame->used = %d\n", frame->used);
+ audrec_pcm_send_data(audio, 0);
+done:
+ return rc;
+}
+
+static ssize_t audamrnb_in_write(struct file *file,
const char __user *buf,
size_t count, loff_t *pos)
{
- return -EINVAL;
+ struct audio_amrnb_in *audio = file->private_data;
+ const char __user *start = buf;
+ struct buffer *frame;
+ char *cpy_ptr;
+ int32_t rc = 0, eos_condition = AUDPREPROC_AMRNB_EOS_NONE;
+ unsigned short mfield_size = 0;
+ int32_t write_count = 0;
+ MM_DBG("cnt=%d\n", count);
+
+ if (count & 1)
+ return -EINVAL;
+
+ if (audio->mode != MSM_AUD_ENC_MODE_NONTUNNEL)
+ return -EINVAL;
+
+ mutex_lock(&audio->write_lock);
+ frame = audio->out + audio->out_head;
+ /* if supplied count is more than driver buffer size
+ * then only copy driver buffer size
+ */
+ if (count > frame->size)
+ count = frame->size;
+
+ write_count = count;
+ cpy_ptr = frame->data;
+ rc = wait_event_interruptible(audio->write_wait,
+ (frame->used == 0)
+ || (audio->stopped)
+ || (audio->wflush));
+ if (rc < 0)
+ goto error;
+
+ if (audio->stopped || audio->wflush) {
+ rc = -EBUSY;
+ goto error;
+ }
+ if (audio->mfield) {
+ if (buf == start) {
+ /* Processing beginning of user buffer */
+ if (__get_user(mfield_size,
+ (unsigned short __user *) buf)) {
+ rc = -EFAULT;
+ goto error;
+ } else if (mfield_size > count) {
+ rc = -EINVAL;
+ goto error;
+ }
+ MM_DBG("mf offset_val %x\n", mfield_size);
+ if (copy_from_user(cpy_ptr, buf, mfield_size)) {
+ rc = -EFAULT;
+ goto error;
+ }
+ /* Check if EOS flag is set and buffer has
+ * contains just meta field
+ */
+ if (cpy_ptr[AUDPREPROC_AMRNB_EOS_FLG_OFFSET] &
+ AUDPREPROC_AMRNB_EOS_FLG_MASK) {
+ eos_condition = AUDPREPROC_AMRNB_EOS_SET;
+ MM_DBG("EOS SET\n");
+ if (mfield_size == count) {
+ buf += mfield_size;
+ eos_condition = 0;
+ goto exit;
+ } else
+ cpy_ptr[AUDPREPROC_AMRNB_EOS_FLG_OFFSET] &=
+ ~AUDPREPROC_AMRNB_EOS_FLG_MASK;
+ }
+ cpy_ptr += mfield_size;
+ count -= mfield_size;
+ buf += mfield_size;
+ } else {
+ mfield_size = 0;
+ MM_DBG("continuous buffer\n");
+ }
+ frame->mfield_sz = mfield_size;
+ }
+ MM_DBG("copying the stream count = %d\n", count);
+ if (copy_from_user(cpy_ptr, buf, count)) {
+ rc = -EFAULT;
+ goto error;
+ }
+exit:
+ frame->used = count;
+ audio->out_head ^= 1;
+ if (!audio->flush_ack)
+ audrec_pcm_send_data(audio, 0);
+ else {
+ audrec_pcm_send_data(audio, 1);
+ audio->flush_ack = 0;
+ }
+ if (eos_condition == AUDPREPROC_AMRNB_EOS_SET)
+ rc = audrec_amrnb_process_eos(audio, start, mfield_size);
+ mutex_unlock(&audio->write_lock);
+ return write_count;
+error:
+ mutex_unlock(&audio->write_lock);
+ return rc;
}
-static int audio_amrnb_in_release(struct inode *inode, struct file *file)
+static int audamrnb_in_release(struct inode *inode, struct file *file)
{
struct audio_amrnb_in *audio = file->private_data;
-
+ int32_t dma_size = 0;
mutex_lock(&audio->lock);
- audio_amrnb_in_disable(audio);
- audio_amrnb_in_flush(audio);
+ audamrnb_in_disable(audio);
+ audamrnb_in_flush(audio);
+ msm_adsp_put(audio->audrec);
+
+ if (audio->mode == MSM_AUD_ENC_MODE_TUNNEL)
+ msm_adsp_put(audio->audpre);
+
+ audpreproc_aenc_free(audio->enc_id);
+ audio->audrec = NULL;
+ audio->audpre = NULL;
audio->opened = 0;
+ if ((audio->mode == MSM_AUD_ENC_MODE_NONTUNNEL) && \
+ (audio->out_data)) {
+ msm_subsystem_unmap_buffer(audio->map_v_write);
+ free_contiguous_memory_by_paddr(audio->out_phys);
+ audio->out_data = NULL;
+ }
if (audio->data) {
- dma_free_coherent(NULL, DMASZ, audio->data, audio->phys);
+ if (audio->mode == MSM_AUD_ENC_MODE_TUNNEL)
+ dma_size = DMASZ;
+ else
+ dma_size = NT_DMASZ;
+
+ dma_free_coherent(NULL,
+ dma_size, audio->data, audio->phys);
audio->data = NULL;
}
mutex_unlock(&audio->lock);
return 0;
}
+struct audio_amrnb_in the_audio_amrnb_in;
-static int audio_amrnb_in_open(struct inode *inode, struct file *file)
+static int audamrnb_in_open(struct inode *inode, struct file *file)
{
struct audio_amrnb_in *audio = &the_audio_amrnb_in;
- int rc;
+ int32_t rc;
+ int encid;
+ int32_t dma_size = 0;
mutex_lock(&audio->lock);
if (audio->opened) {
rc = -EBUSY;
goto done;
}
-
- if (!audio->data) {
- audio->data = dma_alloc_coherent(NULL, DMASZ,
- &audio->phys, GFP_KERNEL);
- if (!audio->data) {
- rc = -ENOMEM;
- goto done;
- }
+ if ((file->f_mode & FMODE_WRITE) &&
+ (file->f_mode & FMODE_READ)) {
+ audio->mode = MSM_AUD_ENC_MODE_NONTUNNEL;
+ dma_size = NT_DMASZ;
+ MM_DBG("Opened for non tunnel mode encoding\n");
+ } else if (!(file->f_mode & FMODE_WRITE) &&
+ (file->f_mode & FMODE_READ)) {
+ audio->mode = MSM_AUD_ENC_MODE_TUNNEL;
+ dma_size = DMASZ;
+ MM_DBG("Opened for tunnel mode encoding\n");
+ } else {
+ MM_ERR("Invalid mode\n");
+ rc = -EACCES;
+ goto done;
}
- rc = audmgr_open(&audio->audmgr);
- if (rc)
- goto err;
- audio->buffer_size = FRAME_SIZE - 8;
- audio->enc_type = 10;
+ /* Settings will be re-config at AUDIO_SET_CONFIG,
+ * but at least we need to have initial config
+ */
+ audio->samp_rate = RPC_AUD_DEF_SAMPLE_RATE_8000,
+ audio->samp_rate_index = AUDREC_CMD_SAMP_RATE_INDX_8000;
+ audio->channel_mode = AUDREC_CMD_STEREO_MODE_MONO;
+ if (audio->mode == MSM_AUD_ENC_MODE_NONTUNNEL)
+ audio->buffer_size = (AMRNB_FRAME_SIZE + 14);
+ else
+ audio->buffer_size = (FRAME_SIZE - 8);
+ audio->enc_type = AUDREC_CMD_TYPE_0_INDEX_AMRNB | audio->mode;
+
+ if (audio->mode == MSM_AUD_ENC_MODE_TUNNEL) {
+ rc = audmgr_open(&audio->audmgr);
+ if (rc)
+ goto done;
+ }
audio->amrnb_enc_cfg.voicememoencweight1 = 0x0000;
audio->amrnb_enc_cfg.voicememoencweight2 = 0x0000;
audio->amrnb_enc_cfg.voicememoencweight3 = 0x4000;
@@ -551,33 +1278,118 @@
audio->amrnb_enc_cfg.dtx_mode_enable = 0;
audio->amrnb_enc_cfg.test_mode_enable = 0;
audio->amrnb_enc_cfg.enc_mode = 7;
+
+ encid = audpreproc_aenc_alloc(audio->enc_type, &audio->module_name,
+ &audio->queue_ids);
+ if (encid < 0) {
+ MM_ERR("No free encoder available\n");
+ rc = -ENODEV;
+ goto done;
+ }
+ audio->enc_id = encid;
+ rc = msm_adsp_get(audio->module_name, &audio->audrec,
+ &audrec_amrnb_adsp_ops, audio);
+ if (rc) {
+ audpreproc_aenc_free(audio->enc_id);
+ goto done;
+ }
+
+ if (audio->mode == MSM_AUD_ENC_MODE_TUNNEL) {
+ rc = msm_adsp_get("AUDPREPROCTASK", &audio->audpre,
+ &audpre_amrnb_adsp_ops, audio);
+ if (rc) {
+ msm_adsp_put(audio->audrec);
+ audpreproc_aenc_free(audio->enc_id);
+ goto done;
+ }
+ }
audio->dsp_cnt = 0;
audio->stopped = 0;
+ audio->wflush = 0;
+ audio->rflush = 0;
+ audio->flush_ack = 0;
- audio_amrnb_in_flush(audio);
+ audamrnb_in_flush(audio);
+ audamrnb_out_flush(audio);
+ /* used dma_allco_coherent for backward compatibility with 7x27 */
+ audio->data = dma_alloc_coherent(NULL, dma_size,
+ &audio->phys, GFP_KERNEL);
+ if (!audio->data) {
+ MM_ERR("Unable to allocate DMA buffer\n");
+ goto evt_error;
+ }
+ audio->out_data = NULL;
+ if (audio->mode == MSM_AUD_ENC_MODE_NONTUNNEL) {
+ audio->out_phys = allocate_contiguous_ebi_nomap(BUFFER_SIZE,
+ SZ_4K);
+ if (!audio->out_phys) {
+ MM_ERR("could not allocate write buffers\n");
+ rc = -ENOMEM;
+ dma_free_coherent(NULL,
+ dma_size, audio->data, audio->phys);
+ goto evt_error;
+ } else {
+ audio->map_v_write = msm_subsystem_map_buffer(
+ audio->out_phys, BUFFER_SIZE,
+ MSM_SUBSYSTEM_MAP_KADDR, NULL, 0);
+ if (IS_ERR(audio->map_v_write)) {
+ MM_ERR("could not map write phys address\n");
+ rc = -ENOMEM;
+ dma_free_coherent(NULL,
+ dma_size, audio->data, audio->phys);
+ free_contiguous_memory_by_paddr(\
+ audio->out_phys);
+ goto evt_error;
+ }
+ audio->out_data = audio->map_v_write->vaddr;
+ MM_DBG("wr buf: phy addr 0x%08x kernel addr 0x%08x\n",
+ audio->out_phys,
+ (uint32_t)audio->out_data);
+ }
+
+ /* Initialize buffer */
+ audio->out[0].data = audio->out_data + 0;
+ audio->out[0].addr = audio->out_phys + 0;
+ audio->out[0].size = OUT_BUFFER_SIZE;
+
+ audio->out[1].data = audio->out_data + OUT_BUFFER_SIZE;
+ audio->out[1].addr = audio->out_phys + OUT_BUFFER_SIZE;
+ audio->out[1].size = OUT_BUFFER_SIZE;
+
+ MM_DBG("audio->out[0].data = %d audio->out[1].data = %d",
+ (uint32_t)audio->out[0].data,
+ (uint32_t)audio->out[1].data);
+ audio->mfield = NT_FRAME_HEADER_SIZE;
+ audio->out_frame_cnt++;
+ }
file->private_data = audio;
audio->opened = 1;
- rc = 0;
- goto done;
-err:
- dma_free_coherent(NULL, DMASZ, audio->data, audio->phys);
done:
mutex_unlock(&audio->lock);
return rc;
+evt_error:
+ msm_adsp_put(audio->audrec);
+ if (audio->mode == MSM_AUD_ENC_MODE_TUNNEL)
+ msm_adsp_put(audio->audpre);
+
+ audpreproc_aenc_free(audio->enc_id);
+ mutex_unlock(&audio->lock);
+ return rc;
}
static const struct file_operations audio_fops = {
.owner = THIS_MODULE,
- .open = audio_amrnb_in_open,
- .release = audio_amrnb_in_release,
- .read = audio_amrnb_in_read,
- .write = audio_amrnb_in_write,
- .unlocked_ioctl = audio_amrnb_in_ioctl,
+ .open = audamrnb_in_open,
+ .release = audamrnb_in_release,
+ .read = audamrnb_in_read,
+ .write = audamrnb_in_write,
+ .fsync = audamrnb_in_fsync,
+ .unlocked_ioctl = audamrnb_in_ioctl,
};
-struct miscdevice audio_amrnb_in_misc = {
+struct miscdevice audamrnb_in_misc = {
.minor = MISC_DYNAMIC_MINOR,
.name = "msm_amrnb_in",
.fops = &audio_fops,
@@ -593,9 +1405,9 @@
static ssize_t audamrnb_in_debug_read(struct file *file, char __user *buf,
size_t count, loff_t *ppos)
{
- const int debug_bufmax = 1024;
+ const int32_t debug_bufmax = 1024;
static char buffer[1024];
- int n = 0, i;
+ int32_t n = 0, i;
struct audio_amrnb_in *audio = file->private_data;
mutex_lock(&audio->lock);
@@ -636,7 +1448,7 @@
};
#endif
-static int __init audio_amrnb_in_init(void)
+static int __init audamrnb_in_init(void)
{
#ifdef CONFIG_DEBUG_FS
struct dentry *dentry;
@@ -646,6 +1458,9 @@
mutex_init(&the_audio_amrnb_in.read_lock);
spin_lock_init(&the_audio_amrnb_in.dsp_lock);
init_waitqueue_head(&the_audio_amrnb_in.wait);
+ init_waitqueue_head(&the_audio_amrnb_in.wait_enable);
+ mutex_init(&the_audio_amrnb_in.write_lock);
+ init_waitqueue_head(&the_audio_amrnb_in.write_wait);
#ifdef CONFIG_DEBUG_FS
dentry = debugfs_create_file("msm_amrnb_in", S_IFREG | S_IRUGO, NULL,
@@ -654,16 +1469,16 @@
if (IS_ERR(dentry))
MM_ERR("debugfs_create_file failed\n");
#endif
- return misc_register(&audio_amrnb_in_misc);
+ return misc_register(&audamrnb_in_misc);
}
-static void __exit audio_amrnb_in_exit(void)
+static void __exit audamrnb_in_exit(void)
{
- misc_deregister(&audio_amrnb_in_misc);
+ misc_deregister(&audamrnb_in_misc);
}
-module_init(audio_amrnb_in_init);
-module_exit(audio_amrnb_in_exit);
+module_init(audamrnb_in_init);
+module_exit(audamrnb_in_exit);
MODULE_DESCRIPTION("MSM AMRNB Encoder driver");
MODULE_LICENSE("GPL v2");