static int HandleVOIPCommand(void)
{
    static AUDIO_DRIVER_HANDLE_t drv_handle = NULL;

    switch(sgBrcm_auddrv_TestValues[1])
    {
        case 1://open the capture device
        {
            VOIP_buffer_count = 0;
            drv_handle = AUDIO_DRIVER_Open(AUDIO_DRIVER_VOIP);
            if ( !drv_handle )
                return -1;

            DEBUG(" Audio DDRIVER Open Complete\n");

            DEBUG(" Audio VOIP DDRIVER Config\n");
            //set UL callback
            AUDIO_DRIVER_Ctrl(drv_handle,AUDIO_DRIVER_SET_VOIP_UL_CB,(void*)VOIP_DumpUL_CB);

            //set the callback
            AUDIO_DRIVER_Ctrl(drv_handle,AUDIO_DRIVER_SET_VOIP_DL_CB,(void*)VOIP_FillDL_CB);
        }
        break;
        case 2:
        {
            AUDCTRL_SaveAudioModeFlag(AUDCTRL_SPK_HANDSET,0);
            AUDCTRL_EnableTelephony(AUDIO_HW_VOICE_IN,AUDIO_HW_VOICE_OUT,AUDCTRL_MIC_MAIN,AUDCTRL_SPK_HANDSET);
            AUDCTRL_SetTelephonySpkrVolume(AUDIO_HW_VOICE_OUT, AUDCTRL_SPK_HANDSET, AUDIO_VOLUME_DEFAULT, AUDIO_GAIN_FORMAT_VOL_LEVEL);
            AUDCTRL_SetTelephonyMicGain(AUDIO_HW_VOICE_IN, AUDCTRL_MIC_MAIN, AUDIO_VOLUME_DEFAULT);

            AUDIO_DRIVER_Ctrl(drv_handle,AUDIO_DRIVER_START,NULL);
        }
        break;
        case 3:
        {
            AUDIO_DRIVER_Ctrl(drv_handle,AUDIO_DRIVER_STOP,NULL);
            AUDCTRL_DisableTelephony(AUDIO_HW_VOICE_IN,AUDIO_HW_VOICE_OUT,AUDCTRL_MIC_MAIN,AUDCTRL_SPK_HANDSET);
        }
        break;
        case 4://close the capture device
            AUDIO_DRIVER_Close(drv_handle);
            break;
        default:
            break;
    }
    return 0;
}
Ejemplo n.º 2
0
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++
 *
 *  Function Name: AUDIO_DRIVER_CaptInterruptPeriodCB
 *
 *  Description: Playback inteerupt
 *
 *------------------------------------------------------------
 */
static void AUDIO_DRIVER_CaptInterruptPeriodCB(void *pPrivate)
{
	struct snd_pcm_substream *substream =
	    (struct snd_pcm_substream *)pPrivate;
	AUDIO_DRIVER_HANDLE_t drv_handle;
	AUDIO_DRIVER_TYPE_t drv_type;
	struct snd_pcm_runtime *runtime;
	brcm_alsa_chip_t *pChip = NULL;
	int substream_number;

	if (!substream) {
		aError("Invalid substream 0x%p\n", substream);
		return;
	}
	substream_number = substream->number + CTL_STREAM_PANEL_PCMIN - 1;
	pChip = snd_pcm_substream_chip(substream);
	runtime = substream->runtime;
	if (!runtime) {
		aError("CaptInterruptPeriodCBInvalid stream=%d runtime 0x%p\n",
		       substream_number, runtime);
		return;
	}
	drv_handle = substream->runtime->private_data;

	AUDIO_DRIVER_Ctrl(drv_handle, AUDIO_DRIVER_GET_DRV_TYPE,
			  (void *)&drv_type);

/*
	aTrace(LOG_ALSA_INTERFACE,
		"\n %lx:CaptInterruptPeriodCB drv_type=%d,\n",
		jiffies, (int)drv_type);
*/

	switch (drv_type) {
	case AUDIO_DRIVER_CAPT_HQ:
	case AUDIO_DRIVER_CAPT_VOICE:
		{
			/*update the PCM read pointer by period size */
			pChip->streamCtl[substream_number].stream_hw_ptr +=
			    runtime->period_size;
			if (pChip->streamCtl[substream_number].stream_hw_ptr >
			    runtime->boundary)
				pChip->streamCtl[substream_number].
				    stream_hw_ptr -= runtime->boundary;
			/*send the period elapsed */
			snd_pcm_period_elapsed(substream);

			/* logmsg_ready(substream, AUD_LOG_PCMIN); */
			common_log_capture(AUD_LOG_PCMIN, substream);

		}
		break;
	default:
		aWarn("CaptInterruptPeriodCB Invalid driver type\n");
		break;
	}
	return;
}
static int HandleCaptCommand(void)
{

    unsigned long period_ms;
    
    //unsigned long copy_bytes;
    static AUDIO_DRIVER_HANDLE_t drv_handle = NULL;
    //static AUDIO_DRIVER_BUFFER_t buf_param;
    static AUDIO_DRIVER_CONFIG_t drv_config;
    static dma_addr_t            dma_addr;
    static AUDCTRL_MICROPHONE_t     mic;
    //char* src;
    //char* dest;
    static AUDIO_DRIVER_TYPE_t drv_type;

    //temp
   // int ret, irq;


    switch(sgBrcm_auddrv_TestValues[1])
    {
        case 1://open the capture device
        {
            //dump_audio_registers();

            drv_type = sgBrcm_auddrv_TestValues[2];
  
            DEBUG(" Audio Capture DDRIVER Open\n");
            drv_handle = AUDIO_DRIVER_Open(drv_type);
            DEBUG(" Audio DDRIVER Open Complete\n");

        }
        break;
        case 2://configure capture device
        {
            DEBUG(" Audio Capture DDRIVER Config\n");
            //set the callback
            AUDIO_DRIVER_Ctrl(drv_handle,AUDIO_DRIVER_SET_CB,(void*)AUDIO_DRIVER_TEST_CaptInterruptPeriodCB);

            if(drv_type == AUDIO_DRIVER_CAPT_HQ)
            {
                // configure defaults
                drv_config.sample_rate = AUDIO_SAMPLING_RATE_48000;
                drv_config.num_channel = AUDIO_CHANNEL_STEREO;
                drv_config.bits_per_sample = AUDIO_16_BIT_PER_SAMPLE;
            }
            else if(drv_type == AUDIO_DRIVER_CAPT_VOICE)
            {
                // configure defaults
                drv_config.sample_rate = AUDIO_SAMPLING_RATE_8000;
                drv_config.num_channel = AUDIO_CHANNEL_MONO;
                drv_config.bits_per_sample = AUDIO_16_BIT_PER_SAMPLE;

            }

            if(sgBrcm_auddrv_TestValues[2] != 0)
                drv_config.sample_rate = sgBrcm_auddrv_TestValues[2];
            if(sgBrcm_auddrv_TestValues[3] != 0)
                drv_config.num_channel = sgBrcm_auddrv_TestValues[3];

            DEBUG("Config:sr=%d nc=%d bs=%d \n",drv_config.sample_rate,drv_config.num_channel,drv_config.bits_per_sample);
            
            AUDIO_DRIVER_Ctrl(drv_handle,AUDIO_DRIVER_CONFIG,(void*)&drv_config);

            period_ms = 100;
            if(sgBrcm_auddrv_TestValues[4] != 0)
                period_ms = sgBrcm_auddrv_TestValues[4];

            //set the interrupt period
            capt_period_bytes = period_ms * (drv_config.sample_rate/1000) * (drv_config.num_channel) * 2;
            capt_num_blocks =  PCM_TEST_MAX_CAPTURE_BUF_BYTES/capt_period_bytes;

            DEBUG("Period: ms=%d bytes=%d blocks:%d\n",period_ms,capt_period_bytes,capt_num_blocks);
            AUDIO_DRIVER_Ctrl(drv_handle,AUDIO_DRIVER_SET_INT_PERIOD,(void*)&capt_period_bytes);

            capt_buf_param.buf_size = PCM_TEST_MAX_CAPTURE_BUF_BYTES;
            capt_buf_param.pBuf = dma_alloc_coherent (NULL, capt_buf_param.buf_size, &dma_addr,GFP_KERNEL);
            if(capt_buf_param.pBuf == NULL)
            {
                DEBUG("Cannot allocate Buffer \n");
                return 0;
            }
            capt_buf_param.phy_addr = (UInt32)dma_addr;

            DEBUG("virt_addr = 0x%x phy_addr=0x%x\n",capt_buf_param.pBuf,(UInt32)dma_addr);

            memset(capt_buf_param.pBuf,0,PCM_TEST_MAX_CAPTURE_BUF_BYTES);
            //set the buffer params
            AUDIO_DRIVER_Ctrl(drv_handle,AUDIO_DRIVER_SET_BUF_PARAMS,(void*)&capt_buf_param);


            //dump_audio_registers();

            DEBUG(" Audio DDRIVER Config Complete\n");
        }
        break;
        case 3: //Start the capture
            {
                AUDIO_HW_ID_t           hw_id = AUDIO_HW_VOICE_IN;

                signed long timeout_jiffies = 2;

                DEBUG(" Start capture\n");
                mic = sgBrcm_auddrv_TestValues[2];

                if(drv_type == AUDIO_DRIVER_CAPT_HQ)
                {
                    hw_id = AUDIO_HW_AUDIO_IN;
                }

                AUDCTRL_EnableRecord(hw_id,
				                     AUDIO_HW_NONE,
                                     mic,
				                     drv_config.num_channel,
                                     drv_config.sample_rate);


                AUDIO_DRIVER_Ctrl(drv_handle,AUDIO_DRIVER_START,NULL);
                
                DEBUG("capture started\n");

                do
                {
                    DEBUG("Waiting...%d \n",timeout_jiffies);
                    //set_current_state(TASK_UNINTERRUPTIBLE);
                    // wait for 10sec 128 jiffies = 1 sec
                    timeout_jiffies = schedule_timeout (timeout_jiffies);
                }while (timeout_jiffies > 0);

                

                DEBUG(" Stop capture\n");

                AUDIO_DRIVER_Ctrl(drv_handle,AUDIO_DRIVER_STOP,NULL);

                AUDCTRL_DisableRecord(hw_id,AUDIO_HW_NONE,mic);

                DEBUG("capture stopped\n");

            }
            break;
        default:
            DEBUG(" Invalid capture Command\n");
    }
	return 0;
}
static int HandlePlayCommand(void)
{

    unsigned long period_ms;
    
    unsigned long copy_bytes;
    static AUDIO_DRIVER_HANDLE_t drv_handle = NULL;
    //static AUDIO_DRIVER_BUFFER_t buf_param;
    static AUDIO_DRIVER_CONFIG_t drv_config;
    static dma_addr_t            dma_addr;
    static AUDCTRL_SPEAKER_t     spkr;
    char* src;
    char* dest;

    //temp
    //int ret, irq;


    switch(sgBrcm_auddrv_TestValues[1])
    {
        case 1://open the plyabck device
        {
            //dump_audio_registers();
             
            DEBUG(" Audio DDRIVER Open\n");
            drv_handle = AUDIO_DRIVER_Open(AUDIO_DRIVER_PLAY_AUDIO);
            DEBUG(" Audio DDRIVER Open Complete\n");

#ifdef ENABLE_AUDVOC_ISR  //enable this for direct interrupt- csl_aud_drv_hw.c file also needs to be changed along with this
            // Temporory code
            ret = request_irq(IRQ_AUDVOC, audvoc_isr, IRQF_DISABLED, "aud_voc", NULL);
	        if (ret != 0) {
		        DEBUG(("Failed to register ISR.\n"));
		        return ret;
	        }
#endif
            
        }
        break;
        case 2://configure playback device
        {
            DEBUG(" Audio DDRIVER Config\n");
            //set the callback
            AUDIO_DRIVER_Ctrl(drv_handle,AUDIO_DRIVER_SET_CB,(void*)AUDIO_DRIVER_TEST_InterruptPeriodCB);

            // configure defaults
            drv_config.sample_rate = AUDIO_SAMPLING_RATE_8000;
            drv_config.num_channel = AUDIO_CHANNEL_STEREO;
            drv_config.bits_per_sample = AUDIO_16_BIT_PER_SAMPLE;

            if(sgBrcm_auddrv_TestValues[2] != 0)
                drv_config.sample_rate = sgBrcm_auddrv_TestValues[2];
            if(sgBrcm_auddrv_TestValues[3] != 0)
                drv_config.num_channel = sgBrcm_auddrv_TestValues[3];

            DEBUG("Config:sr=%d nc=%d bs=%d \n",drv_config.sample_rate,drv_config.num_channel,drv_config.bits_per_sample);
            
            AUDIO_DRIVER_Ctrl(drv_handle,AUDIO_DRIVER_CONFIG,(void*)&drv_config);

            period_ms = 100;
            if(sgBrcm_auddrv_TestValues[4] != 0)
                period_ms = sgBrcm_auddrv_TestValues[4];

            //set the interrupt period
            period_bytes = period_ms * (drv_config.sample_rate/1000) * (drv_config.num_channel) * 2;
            num_blocks =  PCM_TEST_MAX_PLAYBACK_BUF_BYTES/period_bytes;

            DEBUG("Period: ms=%d bytes=%d blocks:%d\n",period_ms,period_bytes,num_blocks);
            AUDIO_DRIVER_Ctrl(drv_handle,AUDIO_DRIVER_SET_INT_PERIOD,(void*)&period_bytes);

            buf_param.buf_size = PCM_TEST_MAX_PLAYBACK_BUF_BYTES;
            buf_param.pBuf = dma_alloc_coherent (NULL, buf_param.buf_size, &dma_addr,GFP_KERNEL);
            if(buf_param.pBuf == NULL)
            {
                DEBUG("Cannot allocate Buffer \n");
                return -1;
            }
            buf_param.phy_addr = (UInt32)dma_addr;

            DEBUG("virt_addr = 0x%x phy_addr=0x%x\n",buf_param.pBuf,(UInt32)dma_addr);

            current_ipbuffer_index = 0;
            dma_buffer_write_index = 0;

#if 1
            // copy the buffer with data
            if((num_blocks * period_bytes) <= sizeof(hqAudioTestBuf))
                copy_bytes = (num_blocks * period_bytes);
            else
                copy_bytes  = sizeof(hqAudioTestBuf);

            src = ((char*)hqAudioTestBuf) + current_ipbuffer_index;
            dest = buf_param.pBuf + dma_buffer_write_index;

            //memset(buf_param.pBuf,0,PCM_TEST_MAX_PLAYBACK_BUF_BYTES);
            memcpy(dest,src,copy_bytes);

            current_ipbuffer_index += copy_bytes;

            //if(current_ipbuffer_index >= sizeof(hqAudioTestBuf))
             //   current_ipbuffer_index = 0;
            
            //memset(buf_param.pBuf,0xbaba,PCM_TEST_MAX_PLAYBACK_BUF_BYTES);
#else
           if(PCM_TEST_MAX_PLAYBACK_BUF_BYTES <= sizeof(samplePCM16_inaudiotest))
                copy_bytes = PCM_TEST_MAX_PLAYBACK_BUF_BYTES;
            else
                copy_bytes  = sizeof(samplePCM16_inaudiotest);

            //memset(buf_param.pBuf,0,PCM_TEST_MAX_PLAYBACK_BUF_BYTES);
            memcpy(buf_param.pBuf,samplePCM16_inaudiotest,copy_bytes);
 

#endif

            //set the buffer params
            AUDIO_DRIVER_Ctrl(drv_handle,AUDIO_DRIVER_SET_BUF_PARAMS,(void*)&buf_param);

            //disable the voice path -- Just to be sure
            //AUDCTRL_DisableTelephony(AUDIO_HW_NONE, AUDIO_HW_NONE, AUDCTRL_MIC_MAIN , AUDCTRL_SPK_HANDSET);

            // clear anacr1
           // *((UInt32 *) (SYSCFG_BASE_ADDR+SYSCFG_ANACR1_OFFSET)) = 0;

            dump_audio_registers();

            DEBUG(" Audio DDRIVER Config Complete\n");
        }
        break;
        case 3: //Start the playback
            {
                //signed long timeout_jiffies = 2;

                DEBUG(" Start Playback\n");
                spkr = sgBrcm_auddrv_TestValues[2];

                AUDCTRL_SaveAudioModeFlag(spkr,0);


                AUDCTRL_EnablePlay(AUDIO_HW_NONE,
                                   AUDIO_HW_AUDIO_OUT,
                                   AUDIO_HW_NONE,
                                   spkr,
				                   drv_config.num_channel,
                                   drv_config.sample_rate
				                    );

               


                AUDIO_DRIVER_Ctrl(drv_handle,AUDIO_DRIVER_START,NULL);

                 
#if 0                
                DEBUG("Playback started\n");
                do
                {
                    DEBUG("Waiting...%d \n",timeout_jiffies);
                    //set_current_state(TASK_UNINTERRUPTIBLE);
                    // wait for 10sec 128 jiffies = 1 sec
                    timeout_jiffies = schedule_timeout (timeout_jiffies);
                }while (timeout_jiffies > 0);

                

                DEBUG(" Stop playback\n");

                AUDIO_DRIVER_Ctrl(drv_handle,AUDIO_DRIVER_STOP,NULL);

                //disable the playback path
                AUDCTRL_DisablePlay(AUDIO_HW_NONE,AUDIO_HW_AUDIO_OUT,spkr);


                AUDIO_DRIVER_Close(drv_handle);
#endif
            }
            break;
        default:
            DEBUG(" Invalid Playback Command\n");
    }
	return 0;	
}
Ejemplo n.º 5
0
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++
 *
 *  Function Name: AUDIO_DRIVER_InterruptPeriodCB
 *
 *  Description: Callback funtion when DMA done, running at
 *  worker thread context (worker_audio_playback)
 *
 *------------------------------------------------------------
 */
static void AUDIO_DRIVER_InterruptPeriodCB(void *pPrivate)
{
	struct snd_pcm_substream *substream =
	    (struct snd_pcm_substream *)pPrivate;
	AUDIO_DRIVER_HANDLE_t drv_handle;
	AUDIO_DRIVER_TYPE_t drv_type;
	struct snd_pcm_runtime *runtime;
	brcm_alsa_chip_t *pChip = NULL;
	int stream_id = 0;

	if (!substream) {
		aError("Invalid substream 0x%p\n", substream);
		return;
	}
	pChip = snd_pcm_substream_chip(substream);

	runtime = substream->runtime;
	if (!runtime) {
		aError("InterruptPeriodCBInvalid runtime 0x%p\n", runtime);
		return;
	}
	drv_handle = substream->runtime->private_data;

	AUDIO_DRIVER_Ctrl(drv_handle, AUDIO_DRIVER_GET_DRV_TYPE,
			  (void *)&drv_type);

	stream_id = StreamIdOfDriver(drv_handle);
	BUG_ON(stream_id < CSL_CAPH_STREAM_NONE ||
		stream_id >= CSL_CAPH_STREAM_TOTAL);

	switch (drv_type) {
	case AUDIO_DRIVER_PLAY_VOICE:
	case AUDIO_DRIVER_PLAY_AUDIO:
	case AUDIO_DRIVER_PLAY_RINGER:
		{
			/*update the PCM read pointer by period size */
			int offset = runtime->period_size;
#if defined(DYNAMIC_DMA_PLAYBACK)
			/*period_size is actually the copy size at dyndma mode*/
			int dmaSize = csl_audio_render_get_dma_size(stream_id);
			if (dmaSize != 0)
				offset = bytes_to_frames(runtime, dmaSize);
#endif
			pChip->streamCtl[substream->number].stream_hw_ptr +=
				offset;
			if (pChip->streamCtl[substream->number].stream_hw_ptr
				> runtime->boundary)
				pChip->streamCtl[substream->number].
				stream_hw_ptr -= runtime->boundary;

			/* send the period elapsed */
			snd_pcm_period_elapsed(substream);

			/* logmsg_ready(substream, AUD_LOG_PCMOUT); */
			common_log_capture(AUD_LOG_PCMOUT, substream);


		}
		break;
	default:
		aWarn("InterruptPeriodCB Invalid driver type\n");
		break;
	}

	return;
}
static long voip_ioctl(struct file *hw, unsigned int cmd, unsigned long arg)
{
	bcm_caph_hwdep_voip_t *pvoip;
	voipdev *pvoipchrdevpvtdata;
	long ret = 0;
	Boolean enable = FALSE;
	Int32 size = 0;
	int data;
	voip_codec_type_data_t val;
	static UserCtrl_data_t *dataptr;
	brcm_alsa_chip_t *pchip = NULL;
	struct treq_sysparm_t *eq;
	struct snd_card *pcard = NULL;
	int rc;
	pvoipchrdevpvtdata = (voipdev *)hw->private_data;
	pvoip = (bcm_caph_hwdep_voip_t *)pvoipchrdevpvtdata->pvoip;
	pcard =  (struct snd_card *)pvoipchrdevpvtdata->card;
	pchip = (brcm_alsa_chip_t *)pcard->private_data;
	aTrace(LOG_ALSA_INTERFACE, "ALSA-CAPH hwdep_ioctl cmd=%08X\n", cmd);
	switch (cmd) {
	case VoIP_Ioctl_GetVersion:
		/* ret = put_user(BrcmAACEncVersion, (int __user *)arg); */
		break;
	case VoIP_Ioctl_Start:
		get_user(data, (int __user *)arg);
		aTrace(LOG_ALSA_INTERFACE, "VoIP_Ioctl_Start type=%d (2==UL)"
			"voipinstcnt=%u\n", data, voipinstcnt);
		rc = down_interruptible(&sVoipAction);
		if (rc)		
			return rc;
		
		aTrace(LOG_ALSA_INTERFACE,"VoIP_Ioctl_Start: acquired sVoipAction\n");
		if (voipinstcnt == 0) { /* start VoIP only once */
			BRCM_AUDIO_Param_RateChange_t param_rate_change;
			BRCM_AUDIO_Param_Open_t param_open;
			BRCM_AUDIO_Param_Prepare_t parm_prepare;
			BRCM_AUDIO_Param_Start_t param_start;
			voipinstcnt++;
			aTrace(LOG_ALSA_INTERFACE,"voipinstcnt=%d\n", voipinstcnt);
#if 0
			hw->private_data =
			    kzalloc(sizeof(bcm_caph_hwdep_voip_t), GFP_KERNEL);
			CAPH_ASSERT(hw->private_data);
			pvoip = (bcm_caph_hwdep_voip_t *) hw->private_data;
#endif
			pvoipchrdevpvtdata->pvoip =
			    kzalloc(sizeof(bcm_caph_hwdep_voip_t), GFP_KERNEL);
			pvoip = pvoipchrdevpvtdata->pvoip;
			CAPH_ASSERT(pvoip);
			init_waitqueue_head(&pvoip->sleep);
			pvoip->buffer_handle =
			    (audio_voip_driver_t *)
			    kzalloc(sizeof(audio_voip_driver_t), GFP_KERNEL);

			aTrace(LOG_ALSA_INTERFACE,"pvoip->buffer_handle=0x%x",pvoip->buffer_handle);
			
			if (pvoip->buffer_handle)
				memset((u8 *) pvoip->buffer_handle, 0,
				       sizeof(audio_voip_driver_t));
			else {
				pvoip->buffer_handle = NULL;
				voipinstcnt--;
				up(&sVoipAction);
				aError("voip_ioctl failed with ENOMEM 1");
				return -ENOMEM;
			}
/*ul data*/
			if (pchip->voip_data.codec_type_ul == VoIP_Codec_None)
			{
				if (pchip->voip_data.codec_type_dl != VoIP_Codec_None)
					pchip->voip_data.codec_type_ul = pchip->voip_data.codec_type_dl;
				else
					pchip->voip_data.codec_type_ul = VoIP_Codec_PCM_16K; // by default

				aTrace(LOG_ALSA_INTERFACE, "VoIP_Ioctl_Start: VoIPCmd forced UL codec [0x%x]\n",
					pchip->voip_data.codec_type_ul);
			}
			pvoip->codec_type_ul = pchip->voip_data.codec_type_ul;
			pvoip->frame_size_ul = svoipframelen[pvoip->
								codec_type_ul - 1];
			pvoip->buffer_size_ul = pvoip->frame_size_ul *
							VOIP_FRAMES_IN_BUFFER;
			pvoip->buffer_handle->voip_data_ul_buf_ptr =
			kzalloc(pvoip->buffer_size_ul, GFP_KERNEL);

			aTrace(LOG_ALSA_INTERFACE, "VoIP_Ioctl_Start: voip_data_ul_buf_ptr=0x%x,"
				"buffer_size_ul=%d\n",
			pvoip->buffer_handle->voip_data_ul_buf_ptr,
			pvoip->buffer_size_ul);
			
			if (pvoip->buffer_handle->voip_data_ul_buf_ptr)
				memset(pvoip->buffer_handle->
				       voip_data_ul_buf_ptr, 0,
				       pvoip->buffer_size_ul);
			else {
				if (pvoip->buffer_handle->
					voip_data_dl_buf_ptr) {
					kfree(pvoip->buffer_handle->
						voip_data_dl_buf_ptr);
					pvoip->buffer_handle->
						voip_data_dl_buf_ptr = NULL;
				}
				pvoip->buffer_handle->voip_data_ul_buf_ptr =
									NULL;
				kfree(pvoip->buffer_handle);
				pvoip->buffer_handle = NULL;
				voipinstcnt--;
				up(&sVoipAction);
				aError("voip_ioctl failed with ENOMEM 2");
				return -ENOMEM;
			}
/*dl data*/
			if (pchip->voip_data.codec_type_dl == VoIP_Codec_None)
			{
				if (pchip->voip_data.codec_type_ul != VoIP_Codec_None)
					pchip->voip_data.codec_type_dl = pchip->voip_data.codec_type_ul;
				else
					pchip->voip_data.codec_type_dl = VoIP_Codec_PCM_16K; // by default
				aTrace(LOG_ALSA_INTERFACE, "VoIP_Ioctl_Start: VoIPCmd forced DL codec [0x%x]\n",
					pchip->voip_data.codec_type_dl);
			}
			pvoip->codec_type_dl = pchip->voip_data.codec_type_dl;
			pvoip->frame_size_dl = svoipframelen[pvoip->
								codec_type_dl - 1];
			pvoip->buffer_size_dl = pvoip->frame_size_dl *
							VOIP_FRAMES_IN_BUFFER;
			pvoip->buffer_handle->voip_data_dl_buf_ptr =
				kzalloc(pvoip->buffer_size_dl, GFP_KERNEL);
			if (pvoip->buffer_handle->voip_data_dl_buf_ptr) {
				memset(pvoip->buffer_handle->
				       voip_data_dl_buf_ptr, 0,
				       pvoip->buffer_size_dl);
			} else {
				if (pvoip->buffer_handle->
					voip_data_ul_buf_ptr) {
					kfree(pvoip->buffer_handle->
						voip_data_ul_buf_ptr);
					pvoip->buffer_handle->
						voip_data_ul_buf_ptr = NULL;
				}
				pvoip->buffer_handle->voip_data_dl_buf_ptr =
									NULL;
				kfree(pvoip->buffer_handle);
				pvoip->buffer_handle = NULL;
				voipinstcnt--;
				up(&sVoipAction);
				aError("voip_ioctl failed with ENOMEM 3");
				return -ENOMEM;
			}
			param_open.drv_handle = NULL;
			param_open.drv_type = AUDIO_DRIVER_VOIP;
			AUDIO_Ctrl_Trigger(ACTION_AUD_OpenVoIP,
				&param_open, NULL, 1);
			pvoip->buffer_handle->drv_handle =
				param_open.drv_handle;
			if (!pvoip->buffer_handle->drv_handle) {
				kfree(pvoip->buffer_handle->
				      voip_data_dl_buf_ptr);
				pvoip->buffer_handle->
				      voip_data_dl_buf_ptr = NULL;
				kfree(pvoip->buffer_handle->
				      voip_data_ul_buf_ptr);
				pvoip->buffer_handle->
				      voip_data_ul_buf_ptr = NULL;
				kfree(pvoip->buffer_handle);
				pvoip->buffer_handle = NULL;
				voipinstcnt--;
				up(&sVoipAction);
				aError("voip_ioctl failed with ENOMEM 4");
				return -ENOMEM;
			}
			/* set UL callback */
			parm_prepare.drv_handle =
				pvoip->buffer_handle->drv_handle;
			parm_prepare.cbParams.voipULCallback =
				HWDEP_VOIP_DumpUL_CB;
			parm_prepare.cbParams.pPrivateData = (void *)pvoip;
			AUDIO_Ctrl_Trigger(
				ACTION_AUD_SET_VOIP_UL_CB,
				&parm_prepare, NULL, 0);
			/* set DL callback */
			parm_prepare.drv_handle =
				pvoip->buffer_handle->drv_handle;
			parm_prepare.cbParams.voipDLCallback =
				HWDEP_VOIP_FillDL_CB;
			parm_prepare.cbParams.pPrivateData = (void *)pvoip;
			AUDIO_Ctrl_Trigger(
				ACTION_AUD_SET_VOIP_DL_CB,
				&parm_prepare, NULL, 0);
			/* VoIP is always 16K.
			No need to set the codec type here*/
			if (isvolte) {
				if (((data == VoIP_UL) &&
					((pvoip->codec_type_ul == VoIP_Codec_PCM_16K) ||
					(pvoip->codec_type_ul == VOIP_Codec_AMR_WB_7K)))
				|| ((data == VoIP_DL) &&
					((pvoip->codec_type_dl == VoIP_Codec_PCM_16K) ||
					(pvoip->codec_type_dl == VOIP_Codec_AMR_WB_7K)))) {
					/* VOIP_PCM_16K or
					VOIP_AMR_WB_MODE_7k */
				param_rate_change.codecID = 0x0A;
			} else
				param_rate_change.codecID = 0x06;
			AUDIO_Ctrl_Trigger(ACTION_AUD_RateChange,
					&param_rate_change, NULL, 0);
			}
			param_start.drv_handle =
				pvoip->buffer_handle->drv_handle;
			param_start.data = (void *)&pchip->voip_data;
			AUDIO_Ctrl_Trigger(ACTION_AUD_StartVoIP,
				&param_start, NULL, 0);
			pvoip->writecount = VOIP_FRAMES_IN_BUFFER;
			pvoip->status = voip_hwdep_status_started;
			aTrace(LOG_ALSA_INTERFACE, "Status made to voip_hwdep_status_started");
		} else {
			voipinstcnt++;
			/*Limit Voip instance to two*/
			if (voipinstcnt > 2)
				voipinstcnt = 2;
			aTrace(LOG_ALSA_INTERFACE,
					"VoIP_Ioctl_Start -> just increment "
					"the count, voip already started voipinstcnt=%d\n", voipinstcnt);
		}
		if (pvoip != NULL) {
			if (data == VoIP_UL)
				pvoip->ulstarted = 1;
			else
				pvoip->dlstarted = 1;
		}
		up(&sVoipAction);
		aTrace(LOG_ALSA_INTERFACE, "VoIP_Ioctl_Start END voipinstcnt=%d\n",voipinstcnt);
		break;
	case VoIP_Ioctl_Stop:
		get_user(data, (int __user *)arg);
		aTrace(LOG_ALSA_INTERFACE, "VoIP_Ioctl_Stop type=%d (2==UL) "
			"voipinstcnt=%u\n", data, voipinstcnt);
		rc = down_interruptible(&sVoipAction);
		if (rc)		
			return rc;
		aTrace(LOG_ALSA_INTERFACE, "VoIP_Ioctl_Stop acquired sVoipAction");
		if (data == VoIP_UL)
			pvoip->ulstarted = 0;
		else
			pvoip->dlstarted = 0;
		if (voipinstcnt >= 2)
		{
			voipinstcnt--;
			aTrace(LOG_ALSA_INTERFACE, "VoIP_Ioctl_Stop--1--voipinstcnt=%d\n", voipinstcnt);
		}	
		else if ((voipinstcnt < 2) ||
				(pvoip->ulstarted == 0 &&
					pvoip->dlstarted == 0)) {
			BRCM_AUDIO_Param_Stop_t param_stop;
			BRCM_AUDIO_Param_Close_t param_close;
			voipinstcnt = 0;
			aTrace(LOG_ALSA_INTERFACE, "VoIP_Ioctl_Stop--2--voipinstcnt=%d\n", voipinstcnt);
			if (pvoip->buffer_handle)
			param_stop.drv_handle =
				pvoip->buffer_handle->drv_handle;
			else
				param_stop.drv_handle = NULL;
			AUDIO_Ctrl_Trigger(ACTION_AUD_StopVoIP,
				&param_stop, NULL, 0);
			if (pvoip->buffer_handle)
			param_close.drv_handle =
				pvoip->buffer_handle->drv_handle;
			else
				param_close.drv_handle = NULL;
			AUDIO_Ctrl_Trigger(ACTION_AUD_CloseVoIP,
				&param_close, NULL, 1);
			if (pvoip->buffer_handle) {
			kfree(pvoip->buffer_handle->voip_data_dl_buf_ptr);
			pvoip->buffer_handle->voip_data_dl_buf_ptr = NULL;
			kfree(pvoip->buffer_handle->voip_data_ul_buf_ptr);
			pvoip->buffer_handle->voip_data_ul_buf_ptr = NULL;
			kfree(pvoip->buffer_handle);
			pvoip->buffer_handle = NULL;
			}
			pvoip->status = voip_hwdep_status_stopped;
			wake_up(&pvoip->sleep);
		}
		up(&sVoipAction);
		break;
	case VoIP_Ioctl_SetSource:
		aTrace(LOG_ALSA_INTERFACE ,
				" Warning: VoIP_Ioctl_SetSource"
				"is depreciated , please"
				"use mixer control VC-SEL instead\n");
		break;
	case VoIP_Ioctl_SetSink:
		aTrace(LOG_ALSA_INTERFACE ,
				" Warning: VoIP_Ioctl_SetSink"
				"is depreciated, please"
				"use mixer control VC-SEL instead\n");
		break;
	case VoIP_Ioctl_SetCodecType:
		aTrace(LOG_ALSA_INTERFACE, "VoIP_Ioctl_SetCodecType\n");
		copy_from_user(&val, (int __user *)arg,
				   sizeof(voip_codec_type_data_t));
		if (val.ul_dl_type == VoIP_UL) {
			pchip->voip_data.codec_type_ul = val.codec_type;
			aTrace(LOG_ALSA_INTERFACE,
				" VoIP_Ioctl_SetCodecType (UL) codec_type %ld\n",
				pchip->voip_data.codec_type_ul);
		/*pvoip = (bcm_caph_hwdep_voip_t *) hw->private_data;*/
			if (!pvoip)
				break;
			pvoip->codec_type_ul = pchip->voip_data.codec_type_ul;
		} else {
			pchip->voip_data.codec_type_dl = val.codec_type;
			aTrace(LOG_ALSA_INTERFACE,
				" VoIP_Ioctl_SetCodecType (DL) codec_type %ld\n",
				pchip->voip_data.codec_type_dl);
		/*pvoip = (bcm_caph_hwdep_voip_t *) hw->private_data;*/
			if (!pvoip)
				break;
			pvoip->codec_type_dl = pchip->voip_data.codec_type_dl;
		}
		/*Check whether in a VoLTE call*/
		/*If no, do nothing.*/
		/*If yes, do the NB<->WB switching*/
		if (isvolte) {
			BRCM_AUDIO_Param_RateChange_t param_rate_change;
			if (pvoip->ulstarted == 0 && pvoip->dlstarted == 0)
				break;
			if (!(pvoip->buffer_handle))
				break;
			if (!(pvoip->buffer_handle->drv_handle))
				break;
			AUDIO_DRIVER_Ctrl(pvoip->buffer_handle->drv_handle,
				AUDIO_DRIVER_SET_AMR, &pchip->voip_data);
			if (((val.ul_dl_type == VoIP_UL) &&
				((pvoip->codec_type_ul == VoIP_Codec_PCM_16K) ||
				(pvoip->codec_type_ul == VOIP_Codec_AMR_WB_7K)))
			|| ((val.ul_dl_type == VoIP_DL) &&
				((pvoip->codec_type_dl == VoIP_Codec_PCM_16K) ||
				(pvoip->codec_type_dl == VOIP_Codec_AMR_WB_7K))))
				/* VOIP_PCM_16K or VOIP_AMR_WB_MODE_7k */
					param_rate_change.codecID = 0x0A;
			else
					param_rate_change.codecID = 0x06;
			AUDIO_Ctrl_Trigger(ACTION_AUD_RateChange,
					&param_rate_change, NULL, 0);
		}
		break;
	case VoIP_Ioctl_SetBitrate:
		get_user(data, (int __user *)arg);
		pchip->voip_data.bitrate_index = (u32) data;
		aTrace(LOG_ALSA_INTERFACE,
				" VoIP_Ioctl_SetBitrate bitrate_index %ld,\n",
				pchip->voip_data.bitrate_index);
		/*pvoip = (bcm_caph_hwdep_voip_t *) hw->private_data;*/
		if (!pvoip)
			break;
		if (isvolte) {
			if (pvoip->ulstarted == 0 && pvoip->dlstarted == 0)
				break;
			if (!(pvoip->buffer_handle))
				break;
			if (!(pvoip->buffer_handle->drv_handle))
				break;
			AUDIO_DRIVER_Ctrl(pvoip->buffer_handle->drv_handle,
				AUDIO_DRIVER_SET_AMR, &pchip->voip_data);
		}
		break;
	case VoIP_Ioctl_GetSource:
		{
		s32 *psel;
		psel = pchip->streamCtl[CTL_STREAM_PANEL_VOICECALL - 1]
			.iLineSelect;
		data = (int)psel[0];
		put_user(data, (int __user *)arg);
		}
		break;
	case VoIP_Ioctl_GetSink:
		{
		s32 *psel;
		psel = pchip->streamCtl[CTL_STREAM_PANEL_VOICECALL - 1]
			.iLineSelect;
		data = (int)psel[1];
		put_user(data, (int __user *)arg);
		}
		break;
	case VoIP_Ioctl_GetCodecType:
		aTrace(LOG_ALSA_INTERFACE, "voip_ioctl in VoIP_Ioctl_GetCodecType");
		copy_from_user(&val, (int __user *)arg,
				   sizeof(voip_codec_type_data_t));
		if (val.ul_dl_type == VoIP_UL)
			val.codec_type = (int)pchip->voip_data.codec_type_ul;
		else
			val.codec_type = (int)pchip->voip_data.codec_type_dl;
		aTrace(LOG_ALSA_INTERFACE,
			" VoIP_Ioctl_GetCodecType (UL:DL) codec_type %ld:%ld\n",
			pchip->voip_data.codec_type_ul, pchip->voip_data.codec_type_dl);
		copy_to_user((int __user *)arg, &val,
				   sizeof(voip_codec_type_data_t));
		break;
	case VoIP_Ioctl_GetBitrate:
		data = (int)pchip->voip_data.bitrate_index;
		put_user(data, (int __user *)arg);
		break;
	case VoIP_Ioctl_GetMode:
		{
			AudioMode_t mode = AUDCTRL_GetAudioMode();
			put_user((int)mode, (int __user *)arg);
			aTrace(LOG_ALSA_INTERFACE,
					" VoIP_Ioctl_GetMode mode %d,\n",
					mode);
		}
		break;
	case VoIP_Ioctl_SetMode:
		aTrace(LOG_ALSA_INTERFACE ,
				" Warning: VoIP_Ioctl_SetMode"
				"is depreciated, please "
				"use mixer control VC-SEL instead\n");
		break;
	case VoIP_Ioctl_SetVoLTEDTX:
		get_user(data, (int __user *)arg);
		pchip->voip_data.isDTXEnabled = (u8) data;
		aTrace(LOG_ALSA_INTERFACE, " VoIP_Ioctl_SetVoLTEDTX %d,\n",
				pchip->voip_data.isDTXEnabled);
		/*pvoip = (bcm_caph_hwdep_voip_t *) hw->private_data;*/
		if (!pvoip)
			break;
		if (!(pvoip->buffer_handle))
			break;
		if (!(pvoip->buffer_handle->drv_handle))
			break;
		AUDIO_DRIVER_Ctrl(pvoip->buffer_handle->drv_handle,
				AUDIO_DRIVER_SET_DTX, &pchip->voip_data);
		break;
	case VoIP_Ioctl_SetVoLTEFlag:
		get_user(data, (int __user *)arg);
		pchip->voip_data.isVoLTE = (u8) data;
		aTrace(LOG_ALSA_INTERFACE, " VoIP_Ioctl_SetFlag isVoLTE %d,\n",
				pchip->voip_data.isVoLTE);
		isvolte = pchip->voip_data.isVoLTE;
		break;
	case VoIP_Ioctl_GetVoLTEFlag:
		data = (int)pchip->voip_data.isVoLTE;
		put_user(data, (int __user *)arg);
		break;
	case DSPCtrl_Ioctl_SPCtrl:
		if (dataptr == NULL)
			dataptr = kzalloc(sizeof(UserCtrl_data_t), GFP_KERNEL);
		else
			memset(dataptr, 0, sizeof(UserCtrl_data_t));
		if (!dataptr)
			return -ENOMEM;
		ret =
		    copy_from_user(dataptr, (int __user *)arg,
				   sizeof(UserCtrl_data_t));
		enable = (Boolean) dataptr->data[0];
		size = dataptr->data[1];
		ret =
		    AUDDRV_User_CtrlDSP(AUDDRV_USER_SP_CTRL, enable, size,
					(void *)&(dataptr->data[2]));
		if (!enable) {
			kfree(dataptr);
			dataptr = NULL;
		}
		break;
	case DSPCtrl_Ioctl_SPSetVar:
		/*
		 * Will move this part later after we separate the voip and
		 * dspctrl connections.
		 */
		if (dataptr == NULL)
			dataptr = kzalloc(sizeof(UserCtrl_data_t), GFP_KERNEL);
		else
			memset(dataptr, 0, sizeof(UserCtrl_data_t));
		if (!dataptr)
			return -ENOMEM;
		ret =
		    copy_from_user(dataptr, (int __user *)arg,
				   sizeof(UserCtrl_data_t));
		size = dataptr->data[0];
		ret =
		    AUDDRV_User_CtrlDSP(AUDDRV_USER_SP_VAR, enable, size,
					(void *)&(dataptr->data[2]));
		break;
	case DSPCtrl_Ioctl_SPQuery:
		if (dataptr == NULL)
			dataptr = kzalloc(sizeof(UserCtrl_data_t), GFP_KERNEL);
		else
			memset(dataptr, 0, sizeof(UserCtrl_data_t));
		if (!dataptr)
			return -ENOMEM;
		ret =
		    AUDDRV_User_CtrlDSP(AUDDRV_USER_SP_QUERY, enable, size,
					(void *)dataptr);
		if (ret < 0)
			return ret;
		if (copy_to_user
		    ((int __user *)arg, dataptr, sizeof(UserCtrl_data_t)))
			return -EFAULT;
		break;
	case DSPCtrl_Ioctl_EQCtrl:
		if (dataptr == NULL)
			dataptr = kzalloc(sizeof(UserCtrl_data_t), GFP_KERNEL);
		else
			memset(dataptr, 0, sizeof(UserCtrl_data_t));
		if (!dataptr)
			return -ENOMEM;
		if (copy_from_user
		    (dataptr, (int __user *)arg, sizeof(UserCtrl_data_t)))
			return -EFAULT;
		enable = (Boolean) dataptr->data[0];
		ret =
		    AUDDRV_User_CtrlDSP(AUDDRV_USER_EQ_CTRL, enable, size,
					(void *)&(dataptr->data[2]));
		if (!enable) {
			kfree(dataptr);
			dataptr = NULL;
		}
		break;
	case Ctrl_Ioctl_SWEQParm:
		aTrace(LOG_ALSA_INTERFACE,
			"ALSA-CAPH hwdep_ioctl Ctrl_Ioctl_SWEQParm");
		eq = kzalloc(sizeof(*eq), GFP_KERNEL);
		if (eq == NULL) {
			aError("treq_sysparm_t mem alloc failed");
			return -ENOMEM;
		}
		/* get the sysparm from driver
		 SW EQ is only for music playback for now*/
		if (copy_from_user(eq, (int __user *)arg,
			sizeof(struct treq_sysparm_t))) {
			if (eq != NULL) {
				kfree(eq);
				eq = NULL;
			}
			return -EFAULT;
		}
		ret = AUDDRV_Get_TrEqParm((void *)eq,
			sizeof(*eq), AUDIO_APP_MUSIC,
			(eq->data)[TREQ_DATA_SIZE-1]);
		if (!ret) {
			if (copy_to_user((void __user *)arg, eq,
			sizeof(*eq))) {
				if (eq != NULL) {
					kfree(eq);
					eq = NULL;
				}
				return -EFAULT;
			}
		}
		if (eq != NULL) {
			kfree(eq);
			eq = NULL;
		}
		break;
	default:
		ret = -ENOTTY;
		break;
	}
	return ret;
}
void AUDIO_Ctrl_Process(
	BRCM_AUDIO_ACTION_en_t action_code,
	void *arg_param,
	void *callback,
    int  block
	)
{
   	TMsgAudioCtrl	msgAudioCtrl;
	unsigned int	len;
	AUDIO_DRIVER_TYPE_t drv_type;
    UInt32 app_profile = 0 ;
	static AudioApp_t prev_app_profile = 0;
	static AudioMode_t prev_mode_profile = 0;
	static bool mode_restore = FALSE;

	if(arg_param == NULL)
	{
		DEBUG("AUDIO_Ctrl_Process: arg_param is NULL \n");
		return;
	}
    switch (action_code)
    {
        case ACTION_AUD_StartPlay:
        {
            BRCM_AUDIO_Param_Start_t* param_start = (BRCM_AUDIO_Param_Start_t*) arg_param;
            
		//20110905 	//prev_app_profile = AUDDRV_GetAudioApp();
            app_profile = AUDIO_Policy_Get_Profile(AUDIO_APP_MUSIC);

            AUDIO_DRIVER_Ctrl(param_start->drv_handle,AUDIO_DRIVER_START,NULL);

            AUDIO_DRIVER_Ctrl(param_start->drv_handle,AUDIO_DRIVER_GET_DRV_TYPE,(void*)&drv_type);

            if (AUDIO_Policy_GetState() == BRCM_STATE_INCALL)
            {
                DEBUG("Play Music During Voice call \n");
                musicduringcall = TRUE;
                if ( sgTableIDChannelOfDev[param_start->substream_number].speaker == AUDCTRL_SPK_HEADSET ||
                     sgTableIDChannelOfDev[param_start->substream_number].speaker == AUDCTRL_SPK_BTM )
                {
                    DEBUG("Play Music During Voice call to HEADSET or BTM\n");
                    if ( app_profile == AUDIO_APP_VOICE_CALL )
                    {
                        DEBUG(" Play music during Voice call with BT Tap at 8k \r\n");
                        AUDCTRL_EnableTap (AUDIO_HW_TAP_VOICE, AUDCTRL_SPK_BTM, 8000);
                    }
                    else
                    {
                        DEBUG(" Play music during Voice call with BT Tap at 16k \r\n");
                        if ( sgTableIDChannelOfDev[param_start->substream_number].speaker == AUDCTRL_SPK_BTM )
                        {
                            AUDCTRL_EnableTap (AUDIO_HW_TAP_VOICE, AUDCTRL_SPK_BTM, 8000);
                        }
                        else
                        {
                            AUDCTRL_EnableTap (AUDIO_HW_TAP_VOICE, AUDCTRL_SPK_BTM, 16000);
                        }
                    }

                    AUDCTRL_EnablePlay(AUDIO_HW_NONE,
                                       sgTableIDChannelOfDev[param_start->substream_number].hw_id,
                                       AUDIO_HW_TAP_VOICE,
                                       AUDCTRL_SPK_BTM,
                                       param_start->channels,
                                       param_start->rate
                                      );
                }
                else
                {
                    DEBUG("Play Music During Voice call to HANDSET or LOUDSPEAKER\n");
                    if ( app_profile == AUDIO_APP_VOICE_CALL )
                    {
                        DEBUG(" Play music during Voice call with BT Tap at 8k \r\n");
                        AUDCTRL_EnableTap (AUDIO_HW_TAP_VOICE, AUDCTRL_SPK_HEADSET, 8000);
                    }
                    else
                    {
                        DEBUG(" Play music during Voice call with BT Tap at 16k \r\n");
                        AUDCTRL_EnableTap (AUDIO_HW_TAP_VOICE, AUDCTRL_SPK_HEADSET, 16000);
                    }

                    AUDCTRL_EnablePlay(AUDIO_HW_NONE,
                                       sgTableIDChannelOfDev[param_start->substream_number].hw_id,
                                       AUDIO_HW_TAP_VOICE,
                                       AUDCTRL_SPK_HEADSET,
                                       param_start->channels,
                                       param_start->rate
                                      );
                }
            }
            else
            {
               	AUDCTRL_SaveAudioModeFlag( sgTableIDChannelOfDev[param_start->substream_number].speaker,app_profile);
            
                if( sgTableIDChannelOfDev[param_start->substream_number].speaker == AUDCTRL_SPK_BTM )
                {
                    AUDCTRL_EnableTap (AUDIO_HW_TAP_VOICE, sgTableIDChannelOfDev[param_start->substream_number].speaker, 8000);

                    // Enable the playback the path
                    AUDCTRL_EnablePlay(AUDIO_HW_NONE,
                                       sgTableIDChannelOfDev[param_start->substream_number].hw_id,
                                       AUDIO_HW_TAP_VOICE,
                                       sgTableIDChannelOfDev[param_start->substream_number].speaker,
                                       param_start->channels,
                                       param_start->rate
				      );
                }
                else
                {
                    // Enable the playback the path
                    AUDCTRL_EnablePlay(AUDIO_HW_NONE,
                                       sgTableIDChannelOfDev[param_start->substream_number].hw_id,
                                       AUDIO_HW_NONE,
                                       sgTableIDChannelOfDev[param_start->substream_number].speaker,
                                       param_start->channels,
                                       param_start->rate
                                      );

                    //if (param_start->substream_number == 5)  // Ring case
                    if(extra_speaker)
                    {
                        DEBUG("Play to speaker as well \n");
                        AUDCTRL_AddPlaySpk(sgTableIDChannelOfDev[param_start->substream_number].hw_id, //		AUDIO_HW_ID_t			sink,
                                           AUDCTRL_SPK_LOUDSPK                 //          AUDCTRL_SPEAKER_t		spk
                                          );
                    }
                }
            }

            // set the slopgain register to max value
            AUDCTRL_SetPlayVolume(sgTableIDChannelOfDev[param_start->substream_number].hw_id,
                                  sgTableIDChannelOfDev[param_start->substream_number].speaker,
                                  AUDIO_GAIN_FORMAT_VOL_LEVEL,
                                  AUDIO_VOLUME_MAX,
                                  AUDIO_VOLUME_MAX
                                 );

            // start DMA now
            AUDIO_DRIVER_Ctrl(param_start->drv_handle,AUDIO_DRIVER_RESUME,NULL);

            playback_prev_time = 0;
            playback_triggered = 1;

        }
        break;
        case ACTION_AUD_StopPlay:
        {
            BRCM_AUDIO_Param_Stop_t* param_stop = (BRCM_AUDIO_Param_Stop_t*) arg_param;

            // stop DMA first
            AUDIO_DRIVER_Ctrl(param_stop->drv_handle,AUDIO_DRIVER_PAUSE,NULL);

            AUDIO_DRIVER_Ctrl(param_stop->drv_handle,AUDIO_DRIVER_GET_DRV_TYPE,(void*)&drv_type);
            //if (param_stop->substream_number == 5)  // Ring case
            if(extra_speaker)
            {
		            DEBUG(" REMOVING  LOUDSPK  \n");				  
                    AUDCTRL_RemovePlaySpk(sgTableIDChannelOfDev[param_stop->substream_number].hw_id, //		AUDIO_HW_ID_t			sink,
									  AUDCTRL_SPK_LOUDSPK				  //		  AUDCTRL_SPEAKER_t 	spk
                    );
            }

		//20110905	//AUDCTRL_SaveAudioModeFlag( AUDDRV_GetAudioMode(), prev_app_profile );

            //disable the playback path
            if (AUDIO_Policy_GetState() == BRCM_STATE_INCALL)
            {
                musicduringcall = FALSE;
                if ( sgTableIDChannelOfDev[param_stop->substream_number].speaker == AUDCTRL_SPK_HEADSET ||
                     sgTableIDChannelOfDev[param_stop->substream_number].speaker == AUDCTRL_SPK_BTM )
                {
                    AUDCTRL_DisablePlay(AUDIO_HW_NONE,
                                        sgTableIDChannelOfDev[param_stop->substream_number].hw_id,
                                        AUDCTRL_SPK_BTM
                                       );
                }
                else
                {
                    AUDCTRL_DisablePlay(AUDIO_HW_NONE,
                                        sgTableIDChannelOfDev[param_stop->substream_number].hw_id,
                                        AUDCTRL_SPK_HEADSET
                                       );
                }
                AUDCTRL_DisableTap (AUDIO_HW_TAP_VOICE);
            }
            else
            {
                if( sgTableIDChannelOfDev[param_stop->substream_number].speaker == AUDCTRL_SPK_BTM )
                {
                    AUDCTRL_DisablePlay(AUDIO_HW_NONE,
                                        sgTableIDChannelOfDev[param_stop->substream_number].hw_id,
                                        sgTableIDChannelOfDev[param_stop->substream_number].speaker
                                       );

                    AUDCTRL_DisableTap (AUDIO_HW_TAP_VOICE);
                }
                else
                {
                    AUDCTRL_DisablePlay(AUDIO_HW_NONE,
                                        sgTableIDChannelOfDev[param_stop->substream_number].hw_id,
                                        sgTableIDChannelOfDev[param_stop->substream_number].speaker
                                       );
                }
            }
            AUDIO_DRIVER_Ctrl(param_stop->drv_handle,AUDIO_DRIVER_STOP,NULL);

            playback_prev_time = 0;
            playback_triggered = 0;

            

        }
        break;
        case ACTION_AUD_PausePlay:
        {
            BRCM_AUDIO_Param_Pause_t* param_pause = (BRCM_AUDIO_Param_Pause_t*) arg_param;

            AUDIO_DRIVER_Ctrl(param_pause->drv_handle,AUDIO_DRIVER_GET_DRV_TYPE,(void*)&drv_type);

            //disable the playback path
             AUDCTRL_DisablePlay(AUDIO_HW_NONE,
                        sgTableIDChannelOfDev[param_pause->substream_number].hw_id,
                        sgTableIDChannelOfDev[param_pause->substream_number].speaker
                    );

            if( sgTableIDChannelOfDev[param_pause->substream_number].speaker == AUDCTRL_SPK_BTM )
            {
                AUDCTRL_DisableTap (AUDIO_HW_TAP_VOICE);
            }
            AUDIO_DRIVER_Ctrl(param_pause->drv_handle,AUDIO_DRIVER_PAUSE,NULL);
        }
        break;

        case ACTION_AUD_ResumePlay:
        {
            BRCM_AUDIO_Param_Resume_t* param_resume = (BRCM_AUDIO_Param_Resume_t*) arg_param;

            AUDIO_DRIVER_Ctrl(param_resume->drv_handle,AUDIO_DRIVER_GET_DRV_TYPE,(void*)&drv_type);

            AUDIO_DRIVER_Ctrl(param_resume->drv_handle,AUDIO_DRIVER_RESUME,NULL);

            if( sgTableIDChannelOfDev[param_resume->substream_number].speaker == AUDCTRL_SPK_BTM )
            {
                AUDCTRL_EnableTap (AUDIO_HW_TAP_VOICE, sgTableIDChannelOfDev[param_resume->substream_number].speaker, param_resume->rate);

                // Enable the playback the path
                AUDCTRL_EnablePlay(AUDIO_HW_NONE,
                                   sgTableIDChannelOfDev[param_resume->substream_number].hw_id,
                                   AUDIO_HW_TAP_VOICE,
                                   sgTableIDChannelOfDev[param_resume->substream_number].speaker,
				                   param_resume->channels,
                                   param_resume->rate
				    );
            }
            else
            {
                // Enable the playback the path
                AUDCTRL_EnablePlay(AUDIO_HW_NONE,
                                   sgTableIDChannelOfDev[param_resume->substream_number].hw_id,
                                   AUDIO_HW_NONE,
                                   sgTableIDChannelOfDev[param_resume->substream_number].speaker,
				                   param_resume->channels,
                                   param_resume->rate
				    );
            }
        }
        break;
        case ACTION_AUD_StartRecord:
        {
            AudioApp_t app_prof = AUDIO_APP_RECORDING;
            AudioMode_t  new_mode = AUDIO_MODE_SPEAKERPHONE;
            AudioMode_t cur_mode;

            BRCM_AUDIO_Param_Start_t* param_start = (BRCM_AUDIO_Param_Start_t*) arg_param;
            DEBUG("ACTION_AUD_StartRecord : param_start->substream_number -  %d \n",param_start->substream_number);

			prev_app_profile = AUDDRV_GetAudioApp();
            cur_mode = AUDCTRL_GetAudioMode();

            if ( cur_mode >= AUDIO_MODE_NUMBER )
                cur_mode = (AudioMode_t) (cur_mode - AUDIO_MODE_NUMBER);

            if (param_start->substream_number == 6 || param_start->substream_number == 7) // record request with Google voice search profile
			{
                app_prof = AUDIO_APP_RECORDING_GVS;
				mode_restore = TRUE;
				prev_mode_profile = cur_mode;
				DEBUG("ACTION_AUD_StartRecord : [%d, %d]", prev_app_profile, prev_mode_profile);
			}

            if (param_start->substream_number == 9 || param_start->substream_number == 10) // record request with voip profile
            {
				app_prof = AUDIO_APP_VOIP;
                new_mode = cur_mode; // use current mode based on earpiece or speaker
            }
            
            if (param_start->substream_number == 11 || param_start->substream_number == 12) // record request with voip incomm profile
            {
				app_prof = AUDIO_APP_VOIP_INCOMM;
                new_mode = cur_mode; // use current mode based on earpiece or speaker
            }

            if (param_start->substream_number == 1 || param_start->substream_number == 7  || param_start->substream_number == 8 
                || param_start->substream_number == 10 || param_start->substream_number == 12) // record request with auxilary mic
                new_mode = AUDIO_MODE_HEADSET;

            app_profile = AUDIO_Policy_Get_Profile(app_prof);
            new_mode = AUDIO_Policy_Get_Mode(new_mode);
            AUDCTRL_SaveAudioModeFlag(new_mode,app_profile);

            AUDCTRL_EnableRecord(sgTableIDChannelOfCaptDev[param_start->substream_number].hw_id,
				                     AUDIO_HW_NONE,
                                     sgTableIDChannelOfCaptDev[param_start->substream_number].mic,
				                     param_start->channels,
                                     param_start->rate);

            AUDIO_DRIVER_Ctrl(param_start->drv_handle,AUDIO_DRIVER_START,NULL);

             AUDIO_Policy_SetState(BRCM_STATE_RECORD);

        }
        break;
        case ACTION_AUD_StopRecord:
        {
            BRCM_AUDIO_Param_Stop_t* param_stop = (BRCM_AUDIO_Param_Stop_t*) arg_param;
               
            AUDIO_DRIVER_Ctrl(param_stop->drv_handle,AUDIO_DRIVER_STOP,NULL);

			if (mode_restore)
			{
				mode_restore = FALSE;
				AUDCTRL_SaveAudioModeFlag( prev_mode_profile, prev_app_profile );
				DEBUG("ACTION_AUD_StartRecord : [%d, %d]", prev_app_profile, prev_mode_profile);
			}
			else
			{
				AUDCTRL_SaveAudioModeFlag( AUDDRV_GetAudioMode(), prev_app_profile );
			}

            AUDCTRL_DisableRecord(sgTableIDChannelOfCaptDev[param_stop->substream_number].hw_id,
                                      AUDIO_HW_NONE,
                                      sgTableIDChannelOfCaptDev[param_stop->substream_number].mic);

            AUDIO_Policy_RestoreState();

        }
	break;
        case ACTION_AUD_OpenPlay:
        {
            BRCM_AUDIO_Param_Open_t* param_open = (BRCM_AUDIO_Param_Open_t*) arg_param;

            param_open->drv_handle = AUDIO_DRIVER_Open(sgTableIDChannelOfDev[param_open->substream_number].drv_type);

            DEBUG("param_open->drv_handle -  0x%x \n",param_open->drv_handle);

        }
        break;
        case ACTION_AUD_ClosePlay:
        {
            BRCM_AUDIO_Param_Close_t* param_close = (BRCM_AUDIO_Param_Close_t*) arg_param;

            DEBUG("param_close->drv_handle -  0x%x \n",param_close->drv_handle);

            AUDIO_DRIVER_Close(param_close->drv_handle);

        }
        break;

	case ACTION_AUD_OpenRecord:
        {
            BRCM_AUDIO_Param_Open_t* param_open = (BRCM_AUDIO_Param_Open_t*) arg_param;

            param_open->drv_handle = AUDIO_DRIVER_Open(sgTableIDChannelOfCaptDev[param_open->substream_number].drv_type);

            DEBUG("param_open->drv_handle -  0x%x \n",param_open->drv_handle);

        }
        break;

        case ACTION_AUD_CloseRecord:
        {
            BRCM_AUDIO_Param_Close_t* param_close = (BRCM_AUDIO_Param_Close_t*) arg_param;

            DEBUG("param_close->drv_handle -  0x%x \n",param_close->drv_handle);

            AUDIO_DRIVER_Close(param_close->drv_handle);

        }
        break;


        case ACTON_VOICECALL_START:
        {
            BRCM_VOICE_Param_Start_t* param_voice_start = (BRCM_VOICE_Param_Start_t*)arg_param;
            int vol_level;

            telephony_stream_number = param_voice_start->substream_number;

            if ( telephony_codecId == 10 )
            {
                DEBUG("Enable telephony WB Call \r\n");
                app_profile = AUDIO_Policy_Get_Profile(AUDIO_APP_VOICE_CALL_WB);
                AUDCTRL_SaveAudioModeFlag( sgTableIDChannelOfVoiceCallDev[telephony_stream_number-VOICE_CALL_SUB_DEVICE].speaker + AUDIO_MODE_NUMBER,app_profile);
            }
            else if ( telephony_codecId == 6 )
            {
                DEBUG("Enable telephony NB Call \r\n");
                app_profile = AUDIO_Policy_Get_Profile(AUDIO_APP_VOICE_CALL);
                AUDCTRL_SaveAudioModeFlag( sgTableIDChannelOfVoiceCallDev[telephony_stream_number-VOICE_CALL_SUB_DEVICE].speaker,app_profile);
            }
            else
            {
                DEBUG("Enable telephony Invalid Codec : Setting as NB \r\n");
                app_profile = AUDIO_Policy_Get_Profile(AUDIO_APP_VOICE_CALL);
                AUDCTRL_SaveAudioModeFlag( sgTableIDChannelOfVoiceCallDev[telephony_stream_number-VOICE_CALL_SUB_DEVICE].speaker,app_profile);
            }

            if ( (telephony_stream_number-VOICE_CALL_SUB_DEVICE) == 4 )
            {
		if ( telephony_codecId == 10 )
            	{
                	DEBUG("Enable telephony WB Call for BT NREC \r\n");
                	app_profile = AUDIO_Policy_Get_Profile(AUDIO_APP_VOICE_CALL_WB);
                	AUDCTRL_SaveAudioModeFlag(AUDCTRL_SPK_HANDSFREE, app_profile);
            	}
            	else if ( telephony_codecId == 6 )
            	{
                	DEBUG("Enable telephony NB Call BT NREC \r\n");
                	app_profile = AUDIO_Policy_Get_Profile(AUDIO_APP_VOICE_CALL);
                	AUDCTRL_SaveAudioModeFlag(AUDCTRL_SPK_HANDSFREE, app_profile);
            	}

                DEBUG(" Telephony : Turning Off EC and NS \r\n");
                //AUDCTRL_EC(FALSE, 0);
                //AUDCTRL_NS(FALSE);
            }
            else
            {
                DEBUG(" Telephony : Turning On EC and NS \r\n");
                //AUDCTRL_EC(TRUE, 0);
                //AUDCTRL_NS(TRUE);
            }

            vol_level= GetCtrlValue(BRCM_CTL_EAR_Playback_Volume);
            if(vol_level > 5)
                vol_level = 5;
            AUDCTRL_SetPlayVolume(AUDIO_HW_VOICE_OUT,AUDCTRL_SPK_HANDSET,AUDIO_GAIN_FORMAT_DSP_VOICE_VOL_GAIN,vol_level,vol_level);

            AUDCTRL_RateChangeTelephony();
            AUDCTRL_EnableTelephony(AUDIO_HW_VOICE_IN,AUDIO_HW_VOICE_OUT,sgTableIDChannelOfVoiceCallDev[telephony_stream_number-VOICE_CALL_SUB_DEVICE].mic,sgTableIDChannelOfVoiceCallDev[telephony_stream_number-VOICE_CALL_SUB_DEVICE].speaker);
            telephony_started = 1;

	        if(TRUE==GetCtrlValue(BRCM_CTL_Mic_Capture_Mute))
            {
                DEBUG("Muting device \r\n");
			    AUDCTRL_SetTelephonyMicMute(AUDIO_HW_VOICE_OUT,AUDCTRL_MIC_MAIN,TRUE);;
            }
            AUDIO_Policy_SetState(BRCM_STATE_INCALL);


        }
        break;

        case ACTON_VOICECALL_STOP:
        {
            BRCM_VOICE_Param_Stop_t* param_voice_stop = (BRCM_VOICE_Param_Stop_t*)arg_param;

            telephony_stream_number = param_voice_stop->substream_number;

            DEBUG("DISABLE TELEPHONY substream = %d \r\n", telephony_stream_number);
            AUDCTRL_DisableTelephony(AUDIO_HW_VOICE_IN,AUDIO_HW_VOICE_OUT,sgTableIDChannelOfVoiceCallDev[telephony_stream_number-VOICE_CALL_SUB_DEVICE].mic,sgTableIDChannelOfVoiceCallDev[telephony_stream_number-VOICE_CALL_SUB_DEVICE].speaker);
            telephony_started = 0;
             AUDIO_Policy_RestoreState();
        }
        break;

        case ACTON_VOICECALL_UPDATE:
        {
            int local_sub_stream_number = 0;
            BRCM_VOICE_Param_Update_t* param_voice_update = (BRCM_VOICE_Param_Update_t*)arg_param;

            DEBUG("TELEPHONY UPDATE codecId = %d \r\n", param_voice_update->voicecall_codecId);

            if ( telephony_codecId != param_voice_update->voicecall_codecId )
            {
                telephony_codecId = param_voice_update->voicecall_codecId;

                if (telephony_started)
                {
                    if ( telephony_codecId == 10 )
                    {
                        app_profile = AUDIO_Policy_Get_Profile(AUDIO_APP_VOICE_CALL_WB);
                        DEBUG("call_CodedId_hander : changing Mode to AMR-WB ===>\r\n");
                        AUDCTRL_SaveAudioModeFlag( sgTableIDChannelOfVoiceCallDev[telephony_stream_number - VOICE_CALL_SUB_DEVICE].speaker + AUDIO_MODE_NUMBER,app_profile);
                        DEBUG("call_CodedId_hander : changing Mode to AMR-WB <===\r\n");
                    }
                    else
                    {
                        app_profile = AUDIO_Policy_Get_Profile(AUDIO_APP_VOICE_CALL);
                        DEBUG("call_CodedId_hander : changing Mode to AMR-NB ===>\r\n");
                        AUDCTRL_SaveAudioModeFlag( sgTableIDChannelOfVoiceCallDev[telephony_stream_number - VOICE_CALL_SUB_DEVICE].speaker,app_profile );
                        DEBUG("call_CodedId_hander : changing Mode to AMR-NB <===\r\n");
                    }
                    DEBUG("call_CodedId_hander : AUDCTRL_RateChangeTelephony ===>\r\n");
                    if ( musicduringcall == TRUE )
                    {
                        local_sub_stream_number = (telephony_stream_number - VOICE_CALL_SUB_DEVICE)*2;
                        // wired headphone
                        if(telephony_stream_number == 17)
                        {
                            // set the substream number to same as headset
                            local_sub_stream_number = 4;
                        }

                        AUDCTRL_DisableTap (AUDIO_HW_TAP_VOICE);
                        if ( app_profile == AUDIO_APP_VOICE_CALL )
                        {
                            
                            AUDCTRL_RateChangeTelephony();
                            if( sgTableIDChannelOfDev[local_sub_stream_number].speaker == AUDCTRL_SPK_HEADSET ||
                                sgTableIDChannelOfDev[local_sub_stream_number].speaker == AUDCTRL_SPK_BTM )
                            {
                                AUDCTRL_EnableTap (AUDIO_HW_TAP_VOICE, AUDCTRL_SPK_BTM, 8000);
                            }
                            else
                            {
                                AUDCTRL_EnableTap (AUDIO_HW_TAP_VOICE, AUDCTRL_SPK_HEADSET, 8000);
                            }
                        }
                        else
                        {
                            AUDCTRL_RateChangeTelephony();
                            if( sgTableIDChannelOfDev[local_sub_stream_number].speaker == AUDCTRL_SPK_HEADSET )
                            {
                                AUDCTRL_EnableTap (AUDIO_HW_TAP_VOICE, AUDCTRL_SPK_BTM, 16000);
                            }
                            else if ( sgTableIDChannelOfDev[local_sub_stream_number].speaker == AUDCTRL_SPK_BTM )
                            {
                                AUDCTRL_EnableTap (AUDIO_HW_TAP_VOICE, AUDCTRL_SPK_BTM, 8000);
                            }
                            else
                            {
                                AUDCTRL_EnableTap (AUDIO_HW_TAP_VOICE, AUDCTRL_SPK_HEADSET, 16000);
                            }
                        }
                    }
                    else
                    {
                        AUDCTRL_RateChangeTelephony();
                    }
                    DEBUG("call_CodedId_hander : AUDCTRL_RateChangeTelephony <===\r\n");
                }
            }
        }
        break;
		
        case ACTON_FM_START:
        {
	    BRCM_FM_Param_Start_t* param_start = (BRCM_FM_Param_Start_t*) arg_param;
        app_profile = AUDIO_Policy_Get_Profile(AUDIO_APP_FM);
			
      	    AUDCTRL_SaveAudioModeFlag( sgTableIDChannelOfDev[param_start->substream_number].speaker,app_profile);
                			
	        // Enable the FM playback the path
            AUDCTRL_EnablePlay(AUDIO_HW_I2S_IN,
				sgTableIDChannelOfDev[param_start->substream_number].hw_id,
				AUDIO_HW_NONE,
				sgTableIDChannelOfDev[param_start->substream_number].speaker,
				param_start->channels,
				param_start->rate
						);
            // set the slopgain register to max value
            // 20110530 FM radio volume is controlled by FM radio chip.
            AUDCTRL_SetPlayVolume(sgTableIDChannelOfDev[param_start->substream_number].hw_id,
				  sgTableIDChannelOfDev[param_start->substream_number].speaker,
				  AUDIO_GAIN_FORMAT_FM_RADIO_DIGITAL_VOLUME_TABLE,
				  AUDIO_VOLUME_MAX,
				  AUDIO_VOLUME_MAX 
						);

            AUDIO_Policy_SetState(BRCM_STATE_FM);

	    }
        break;
		
        case ACTON_FM_STOP:
        {

            BRCM_FM_Param_Stop_t* param_fm_stop = (BRCM_FM_Param_Stop_t*)arg_param;
	
            //disable the FM playback path
            AUDCTRL_DisablePlay(AUDIO_HW_I2S_IN,
				  sgTableIDChannelOfDev[param_fm_stop->substream_number].hw_id,
				  sgTableIDChannelOfDev[param_fm_stop->substream_number].speaker
						 );
            AUDIO_Policy_RestoreState();
        }
        break;
        case  ACTON_ROUTE:
            {
                BRCM_AUDIO_Param_Route_t* parm_route = (BRCM_AUDIO_Param_Route_t*)arg_param;
                 DEBUG("ACTON_ROUTE  \n");			
                

                if(playback_triggered == 1){

                    if(parm_route->command == 1)
                    {
                        DEBUG(" ADDING  SPK - %d  \n",parm_route->speaker);				  
                        AUDCTRL_AddPlaySpk(AUDIO_HW_PLR_OUT,
                                               parm_route->speaker
                                              );
                        extra_speaker = 1;

                    }
                    else if (parm_route->command == 0)
                    {
             
                        DEBUG(" REMOVING  SPK - %d  \n",parm_route->speaker);				  
                        AUDCTRL_RemovePlaySpk(AUDIO_HW_PLR_OUT, 
									      parm_route->speaker	
                        );

                        extra_speaker = 0;
                    }
                }
                else
                {
                    if(parm_route->command == 1)
                        extra_speaker = 1;
                    else if (parm_route->command == 0)
                        extra_speaker = 0;
                }
            }
            break;
        default:
            DEBUG("Error AUDIO_Ctrl_Process Invalid acction command \n");
    }
    if(block)
    {
        // put the message in output fifo if waiting
        msgAudioCtrl.action_code = action_code;
	    if(arg_param)
		    memcpy(&msgAudioCtrl.param, arg_param, sizeof(BRCM_AUDIO_Control_Params_un_t));
	    else
		    memset(&msgAudioCtrl.param, 0, sizeof(BRCM_AUDIO_Control_Params_un_t));
	    msgAudioCtrl.pCallBack = callback;
        msgAudioCtrl.block = block;

        len = kfifo_in_locked(&sgThreadData.m_pkfifo_out, (unsigned char *)&msgAudioCtrl, sizeof(TMsgAudioCtrl), &sgThreadData.m_lock_out);
        if(len != sizeof(TMsgAudioCtrl))
		    DEBUG("Error AUDIO_Ctrl_Process len=%d expected %d \n", len, sizeof(TMsgAudioCtrl));
#if 1        
        // release the semaphore 
        DEBUG("Semaphore released - %d \n",action_code);
        OSSEMAPHORE_Release(sgThreadData.action_complete);
#endif
    }

}