Пример #1
0
static void i2s_codec_init(void)
{
    __cpm_start_aic1();
    __cpm_start_aic2();

    __aic_enable();

    __i2s_internal_codec();
    __i2s_as_slave();
    __i2s_select_i2s();
    __aic_select_i2s(); 

    __aic_disable_byteswap();
    __aic_disable_unsignadj();
    __aic_disable_mono2stereo();

    i2s_codec_reset();

    REG_ICDC_CDCCR1 &= ~(ICDC_CDCCR1_SUSPD | ICDC_CDCCR1_RST);

    REG_ICDC_CDCCR2 = ( ICDC_CDCCR2_AINVOL(23) | ICDC_CDCCR2_SMPR(ICDC_CDCCR2_SMPR_44)
                      | ICDC_CDCCR2_HPVOL(ICDC_CDCCR2_HPVOL_0));

    mdelay(15);
    REG_ICDC_CDCCR1 &= ~(ICDC_CDCCR1_PDVR | ICDC_CDCCR1_VRCGL | ICDC_CDCCR1_VRCGH);
    REG_ICDC_CDCCR1 |= (ICDC_CDCCR1_EDAC | ICDC_CDCCR1_HPCG);

    mdelay(600);
    REG_ICDC_CDCCR1 &= ~(ICDC_CDCCR1_PDVRA | ICDC_CDCCR1_HPCG | ICDC_CDCCR1_PDHPM | ICDC_CDCCR1_PDHP);

    mdelay(2);

    /* CDCCR1.ELININ=0, CDCCR1.EMIC=0, CDCCR1.EADC=0, CDCCR1.SW1ON=0, CDCCR1.EDAC=1, CDCCR1.SW2ON=1, CDCCR1.HPMUTE=0 */
    REG_ICDC_CDCCR1 = (REG_ICDC_CDCCR1 & ~(ICDC_CDCCR1_ELININ | ICDC_CDCCR1_EMIC | ICDC_CDCCR1_EADC |
                                           ICDC_CDCCR1_SW1ON | ICDC_CDCCR1_HPMUTE)) | (ICDC_CDCCR1_EDAC
                                                                                    | ICDC_CDCCR1_SW2ON);

    HP_on_off_flag = 1; /* HP is on */
}
Пример #2
0
////////////////////////////////////////////////////
// 功能: 音频初始化
// 输入: 
// 输出:
// 返回: 
// 说明: 
////////////////////////////////////////////////////
int pcm_ioctl(unsigned int cmd, unsigned long arg)
{
	unsigned int data, temp, aicfr, aiccr;
	switch (cmd)
	{
		case PCM_SET_SAMPLE_RATE:
#ifdef KPRINTF_DEF
			kprintf("pcm_ioctl, PCM_SET_SAMPLE_RATE,arg = %d\n", arg);
#endif
			set_sample_rate(arg);
			break;

		case PCM_SET_CHANNEL:
#ifdef KPRINTF_DEF
			kprintf("pcm_ioctl, PCM_SET_CHANNEL,arg = %d.\n", arg);
#endif
			if (arg == 2)
				__aic_disable_mono2stereo();		//CLRREG32(AIC_CR, AICCR_M2S);
			else if (arg == 1)
				__aic_enable_mono2stereo();			//SETREG32(AIC_CR, AICCR_M2S);
			break;
			
		case PCM_SET_FORMAT:
#ifdef KPRINTF_DEF
			kprintf("pcm_ioctl, PCM_SET_FORMAT, arg = %d.\n",arg);
#endif
			// Config for Playback
			aicfr = INREG32(AIC_FR) & (~AIC_FR_TFTH_MASK);
			aiccr = INREG32(AIC_CR) & (~AIC_CR_OSS_MASK);
			temp = INREG32(A_DMA_DCM(PLAYBACK_CHANNEL)) & (~DCM_DP_MASK);
			if (arg == 16)
			{
				aicfr |= AICFR_TFTH(16);
				temp |= DCM_DP_16BIT;
				aiccr &= ~AIC_CR_AVSTSU;
				aiccr |= AIC_CR_OSS_16BIT;
			}
			else if (arg == 8)
			{
				aicfr |= AICFR_TFTH(16);
				temp |= DCM_DP_08BIT;
				aiccr |= AIC_CR_AVSTSU;
				aiccr |= AIC_CR_OSS_8BIT;
			}
			OUTREG32(AIC_FR, aicfr);
			OUTREG32(AIC_CR, aiccr);
			OUTREG32(A_DMA_DCM(PLAYBACK_CHANNEL), temp);
			
			// Config for Recorder
			temp = INREG32(A_DMA_DCM(RECORD_CHANNEL)) & (~DCM_DP_MASK);
			if (arg == 16)
				temp |= DCM_DP_16BIT;
			else if (arg == 8)
				temp |= DCM_DP_08BIT;

			OUTREG32(A_DMA_DCM(RECORD_CHANNEL), temp);
			break;
			
		case PCM_SET_MUTE:
#ifdef KPRINTF_DEF
			kprintf("pcm_ioctl, PCM_SET_MUTE, arg = %d.\n", arg);
#endif
			if ((g_volume == 0) || arg == 1)
			{
				codec_reg_set(A_CODEC_CR1, DAC_MUTE);
			}
			else
			{
				codec_reg_clear(A_CODEC_CR1, DAC_MUTE);
			}
			break;
			
		case PCM_SET_VOL:
		case PCM_SET_HP_VOL:
#ifdef KPRINTF_DEF
			kprintf("pcm_ioctl, PCM_SET_HP_VOL, val = %d.\n", arg);
#endif
			{
				int RegVolume = 0, VolDif = 0, JumpCoun = 0;
				data = arg > 31 ? 31 : arg;
				g_volume = data;
				RegVolume = get_volume_reg();
				VolDif = RegVolume > data ? (RegVolume - data) : (data - RegVolume);
#ifdef KPRINTF_DEF
				kprintf("set volume: voldif = %d,data = %d\n",VolDif,data);
#endif

				if (VolDif > 7)
				{
					for (JumpCoun = 0; JumpCoun <=  data; JumpCoun++)
					{
						set_volume_reg(JumpCoun);
						//MillinsecoundDelay(10);
					}
				}
				else
				{
					set_volume_reg(data);
				}
			}
			break;
			
		case PCM_SET_PAUSE:
#ifdef KPRINTF_DEF
			kprintf("pcm_ioctl, PCM_SET_PAUSE\n");
#endif
			MillinsecoundDelay(10);

			CLRREG32(AIC_CR, AIC_CR_ERPL);
			CLRREG32(A_DMA_DCS(PLAYBACK_CHANNEL), DCS_AR | DCS_HLT | DCS_CTE | DCS_CT);
			SETREG32(AIC_CR, AIC_CR_FLUSH_FIFO);
			OUTREG32(AIC_SR, 0x00000000);
			break;

		case PCM_SET_PLAY:
#ifdef KPRINTF_DEF
			kprintf("pcm_ioctl, PCM_SET_PLAY\n");
#endif
			codec_reg_clear(A_CODEC_PMR1, SB_ADC);
			jz_audio_reset();
			MillinsecoundDelay(10);
			codec_reg_clear(A_CODEC_CR1, HP_DIS);
			codec_reg_set(A_CODEC_PMR1, SB_LIN);

			codec_reg_clear(A_CODEC_PMR1, SB_DAC);
			codec_reg_set(A_CODEC_PMR1, SB_ADC);

			SETREG32(AIC_CR, AIC_CR_ERPL);
			break;

		case PCM_SET_REPLAY:
#ifdef KPRINTF_DEF
			kprintf("pcm_ioctl, PCM_SET_REPLAY\n");
#endif
			CLRREG32(AIC_CR, AIC_CR_EREC);
			CLRREG32(A_DMA_DCS(RECORD_CHANNEL), DCS_AR | DCS_HLT | DCS_CTE | DCS_CT);
			codec_reg_clear(A_CODEC_CR2, ADC_HPF);
			codec_reg_set(A_CODEC_CR1, SB_MICBIAS);
			codec_reg_clear(A_CODEC_CR1, BYPASS);
			codec_reg_set(A_CODEC_CR1, DACSEL);
			codec_reg_write(A_CODEC_CR3, 0xC0);
			codec_reg_clear(A_CODEC_PMR2, GIM);

			pcm_ioctl(PCM_SET_PLAY, 0);
			break;

		case PCM_SET_RECORD:
#ifdef KPRINTF_DEF
			kprintf("pcm_ioctl, PCM_SET_RECORD\n");
#endif
			jz_audio_reset();
			codec_reg_clear(A_CODEC_CR1, SB_MICBIAS);
			codec_reg_write(A_CODEC_CR3, 0x40);
			codec_reg_set(A_CODEC_PMR2, GIM);
			codec_reg_set(A_CODEC_PMR1, SB_LIN);
			codec_reg_set(A_CODEC_CR2, ADC_HPF);
			codec_reg_clear(A_CODEC_PMR1, SB_ADC);
			
			codec_reg_write(A_CODEC_CGR10, 0x88);
			break;

		case PCM_SET_RECORD_FM:
#ifdef KPRINTF_DEF
			kprintf("pcm_ioctl, PCM_SET_RECORD_FM\n");
#endif
			jz_audio_reset();
			codec_reg_clear(A_CODEC_CR1, DACSEL);
			codec_reg_set(A_CODEC_CR2, ADC_HPF);
			codec_reg_write(A_CODEC_CGR10, 0xff);
			break;

		case PCM_RESET:
#ifdef KPRINTF_DEF
			kprintf("pcm_ioctl, PCM_RESET\n");
#endif
			CLRREG32(A_DMA_DCS(PLAYBACK_CHANNEL), DCS_AR | DCS_HLT | DCS_CTE | DCS_CT);
			break;

		case PCM_GET_HP_VOL:
			return get_volume_reg();

		case PCM_GET_VOL:
			return get_volume_reg();

		case PCM_POWER_OFF:
#ifdef KPRINTF_DEF
			kprintf("pcm_ioctl, PCM_POWER_OFF\n");
#endif
			codec_reg_set(A_CODEC_CR1, DAC_MUTE);

			return 1;

		case PCM_POWER_ON:
#ifdef KPRINTF_DEF
			kprintf("pcm_ioctl, PCM_POWER_ON\n");
#endif
			codec_reg_clear(A_CODEC_CR1, DAC_MUTE);

			return 1;

		default:
#ifdef KPRINTF_DEF
			kprintf("pcm_ioctl:Unsupported I/O command: %08x\n", cmd);
#endif
			return -1;
	}
	
	return 0;
}