⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jadei2s.c

📁 Audio codec--TLV320AIC31 驱动
💻 C
📖 第 1 页 / 共 3 页
字号:
               if (volP_add>0){ 
				org_vol_p++;
				volP_add--;
				volP_del++;
				}
				else{
                   printk("now is the max vol\n");
                   return -1;
                }
        }
        if  (add_del=='-') {
               if (volP_del>0){ 
				volP_del--;
				volP_add++;
				org_vol_p--;
				}
                else{
                        printk("now is the smallest vol\n");
                        return -1;
                }
        }
	
		value_vol=org_vol_p;
	
        aic23_for_vol[2]=value_vol;
	debug(" the vol value is %x\n",aic23_for_vol[2]);
        init_i2c();
        transmitData(2,&aic23_for_vol[1], 0x34/2 );

        mdelay(1);

        dele_i2c();
        return 1;

}



static int i2s_set_reg0(unsigned int value){

unsigned char aic23_for_reg0[3]={0x34,0x01,0x17};
unsigned char val1,val2;
unsigned int tmp;
	
	tmp = value;
	if (tmp > 0xff) val1 = 0x1;
		else val1=0x0;
	val2 = (unsigned char)(tmp && 0xff);
	
	aic23_for_reg0[1] = val1;
	aic23_for_reg0[2] = val2;
	
	init_i2c();
        transmitData(2,&aic23_for_reg0[1], 0x34/2 );

        mdelay(1);

        dele_i2c();
        return 1;

}
static int i2s_set_reg1(unsigned int value){
unsigned char aic23_for_reg1[3]={0x34,0x01,0x17};
unsigned char val1,val2;
unsigned int tmp;
        
        tmp = value;
        if (tmp > 0xff) val1 = 0x1;
                else val1=0x0;
        val2 = (unsigned char)(tmp && 0xff);

        aic23_for_reg1[1] = val1;
        aic23_for_reg1[2] = val2;
        
        init_i2c();
        transmitData(2,&aic23_for_reg1[1], 0x34/2 );

        mdelay(1);

        dele_i2c();
        return 1;


}
static int i2s_set_reg2(unsigned int value){

unsigned char aic23_for_reg2[3]={0x34,0x01,0x17};
unsigned char val1,val2;
unsigned int tmp;
        
        tmp = value;
        if (tmp > 0xff) val1 = 0x1;
                else val1=0x0;
        val2 = (unsigned char)(tmp && 0xff);

        aic23_for_reg2[1] = val1;
        aic23_for_reg2[2] = val2;
        
        init_i2c();
        transmitData(2,&aic23_for_reg2[1], 0x34/2 );

        mdelay(1);

        dele_i2c();
        return 1;

}
static int i2s_set_reg3(unsigned int value){
unsigned char aic23_for_reg3[3]={0x34,0x01,0x17};
unsigned char val1,val2;
unsigned int tmp;
        
        tmp = value;
        if (tmp > 0xff) val1 = 0x1;
                else val1=0x0;
        val2 = (unsigned char)(tmp && 0xff);

        aic23_for_reg3[1] = val1;
        aic23_for_reg3[2] = val2;
        
        init_i2c();
        transmitData(2,&aic23_for_reg3[1], 0x34/2 );

        mdelay(1);

        dele_i2c();
        return 1;


}
static int i2s_set_reg4(unsigned int value){
unsigned char aic23_for_reg4[3]={0x34,0x01,0x17};
unsigned char val1,val2;
unsigned int tmp;
        
        tmp = value;
        if (tmp > 0xff) val1 = 0x1;
                else val1=0x0;
        val2 = (unsigned char)(tmp && 0xff);

        aic23_for_reg4[1] = val1;
        aic23_for_reg4[2] = val2;
        
        init_i2c();
        transmitData(2,&aic23_for_reg4[1], 0x34/2 );

        mdelay(1);

        dele_i2c();
        return 1;


}
static int i2s_set_reg5(unsigned int value){
unsigned char aic23_for_reg5[3]={0x34,0x01,0x17};
unsigned char val1,val2;
unsigned int tmp;
        
        tmp = value;
        if (tmp > 0xff) val1 = 0x1;
                else val1=0x0;
        val2 = (unsigned char)(tmp && 0xff);

        aic23_for_reg5[1] = val1;
        aic23_for_reg5[2] = val2;
        
        init_i2c();
        transmitData(2,&aic23_for_reg5[1], 0x34/2 );

        mdelay(1);

        dele_i2c();
        return 1;


}
static int i2s_set_reg6(unsigned int value){
unsigned char aic23_for_reg6[3]={0x34,0x01,0x17};
unsigned char val1,val2;
unsigned int tmp;
        
        tmp = value;
        if (tmp > 0xff) val1 = 0x1;
                else val1=0x0;
        val2 = (unsigned char)(tmp && 0xff);

        aic23_for_reg6[1] = val1;
        aic23_for_reg6[2] = val2;
        
        init_i2c();
        transmitData(2,&aic23_for_reg6[1], 0x34/2 );

        mdelay(1);

        dele_i2c();
        return 1;


}
static int i2s_set_reg7(unsigned int value){
unsigned char aic23_for_reg7[3]={0x34,0x01,0x17};
unsigned char val1,val2;
unsigned int tmp;
        
        tmp = value;
        if (tmp > 0xff) val1 = 0x1;
                else val1=0x0;
        val2 = (unsigned char)(tmp && 0xff);

        aic23_for_reg7[1] = val1;
        aic23_for_reg7[2] = val2;
        
        init_i2c();
        transmitData(2,&aic23_for_reg7[1], 0x34/2 );

        mdelay(1);

        dele_i2c();
        return 1;


}

static int i2s_set_reg8(unsigned int value){
unsigned char aic23_for_reg8[3]={0x34,0x01,0x17};
unsigned char val1,val2;
unsigned int tmp;
        
        tmp = value;
        if (tmp > 0xff) val1 = 0x1;
                else val1=0x0;
        val2 = (unsigned char)(tmp && 0xff);

        aic23_for_reg8[1] = val1;
        aic23_for_reg8[2] = val2;
        
        init_i2c();
        transmitData(2,&aic23_for_reg8[1], 0x34/2 );

        mdelay(1);

        dele_i2c();
        return 1;


}
static int i2s_set_reg9(unsigned int value){
unsigned char aic23_for_reg9[3]={0x34,0x01,0x17};
unsigned char val1,val2;
unsigned int tmp;
        
        tmp = value;
        if (tmp > 0xff) val1 = 0x1;
                else val1=0x0;
        val2 = (unsigned char)(tmp && 0xff);

        aic23_for_reg9[1] = val1;
        aic23_for_reg9[2] = val2;
        
        init_i2c();
        transmitData(2,&aic23_for_reg9[1], 0x34/2 );

        mdelay(1);

        dele_i2c();
        return 1;


}

static int i2s_set_reg15(unsigned int value){
unsigned char aic23_for_reg15[3]={0x34,0x01,0x17};
unsigned char val1,val2;
unsigned int tmp;
        
        tmp = value;
        if (tmp > 0xff) val1 = 0x1;
                else val1=0x0;
        val2 = (unsigned char)(tmp && 0xff);

        aic23_for_reg15[1] = val1;
        aic23_for_reg15[2] = val2;
        
        init_i2c();
        transmitData(2,&aic23_for_reg15[1], 0x34/2 );

        mdelay(1);

        dele_i2c();
        return 1;

}


static int i2s_ioctl(struct inode *inode, struct file *filp,
                       unsigned int cmd, unsigned long arg)
{

 int err=0;

    if (_IOC_TYPE(cmd) != I2S_IOC_MAGIC) return -ENOTTY;
    if (_IOC_NR(cmd) > I2S_IOC_MAXNR) return -ENOTTY;

    if (_IOC_DIR(cmd) & _IOC_READ)
        err = !access_ok(VERIFY_WRITE, (void *)arg, _IOC_SIZE(cmd));
    else if (_IOC_DIR(cmd) & _IOC_WRITE)
        err =  !access_ok(VERIFY_READ, (void *)arg, _IOC_SIZE(cmd));
    if (err) return -EFAULT;
	
  switch (cmd)
    {
	#ifdef I2S_DEBUG   
      		case I2S_IOCHARDRESET:
         /*
          * reset the counter to 1, to allow unloading in case
          * of problems. Use 1, not 0, because the invoking
          * process has the device open.
          */
        
		return 0;
		break;
	#endif /* I2S_DEBUG */

      case I2S_IOCRESET:
       		return 0;
        	break;

	    case I2S_IOCLAST :
			return i2slastdone();
			break;
	    case I2S_IOCHWADDR :
			return i2sbufbaseaddr();
			break;
		case I2S_IOCVIRADDR :	
			return i2sbufviraddr();
			break;
		case I2S_IOC_SETFMT:
			return i2s_setFmt( (unsigned int)arg);
			break;
		case I2S_IOC_SETCh:
			return i2s_setChannel( (unsigned int)arg);
			break;
		case I2S_IOC_SETSPEED:
			#ifdef CONFIG_USE_wm8976
				return i2s_wm8976_setSpeed((unsigned int) arg);	
		
			#else
				return i2s_aic23_setSpeed((unsigned int) arg);
			#endif
			break;
		#ifdef CONFIG_USE_aic23
		case I2S_IOC_SetReVol:
                                return i2s_aic23_SetReVol((unsigned int) arg);
                        break;
		case I2S_IOC_SetPlVol:
                                return i2s_aic23_SetPlVol((unsigned int) arg);
			break;
		case I2S_IOC_GInt :
			    return i2s_miclin_mode();
			break;
		case I2S_IOC_GetVol :
			  return  i2s_get_vol();
			break;
		case I2S_IOC_SetReg0:
			return i2s_set_reg0((unsigned int) arg);
		
		case I2S_IOC_SetReg2:
                        return i2s_set_reg2((unsigned int) arg);
		case I2S_IOC_SetReg4:
                        return i2s_set_reg4((unsigned int) arg);
		case I2S_IOC_SetReg5:
                        return i2s_set_reg5((unsigned int) arg);
		case I2S_IOC_SetReg6:
                        return i2s_set_reg6((unsigned int) arg);
		case I2S_IOC_SetReg7:
                        return i2s_set_reg7((unsigned int) arg);
		case I2S_IOC_SetReg8:
                        return i2s_set_reg8((unsigned int) arg);
		case I2S_IOC_SetReg9:
                        return i2s_set_reg9((unsigned int) arg);
		case I2S_IOC_SetReg15:
                        return i2s_set_reg15((unsigned int) arg);
		#endif
	}

	return 0;
}

static int test_close()
{

//	PinMask( 1 , 1 );
	init_i2c();
	transmitData( 2 , &aic23_for_close[1], 0x34/2 );

	mdelay(1);
	
	dele_i2c();
	return 0;
 
}

/* for play and record init-test*/
static int i2s_test()
{

	int i, loop=0; 
	int error;

	Play_Buffer = kmalloc(PLAYBUFSIZE, GFP_KERNEL);
	if(Play_Buffer==NULL){
		printk("SOUND: error malloc Play_Buffer\n");
		return -ENODEV;
	}

	for (i=0;i<4096; i++)
        {
        if (loop<48){
                         Play_Buffer[i]= (sinewave[loop] >> 4);
                loop++;
                }
        else{
                loop=0;
                Play_Buffer[i]= (sinewave[loop] >> 4);
                loop++;
                }
        }


	error = init_playback_dma();
	if (error != 0)
	{
		printk("SOUND: init_playback_dma  fail !\n");
		return -ENODEV;
	}
	
		error = start_play_dma(Play_Buffer, PLAYBUFSIZE);
		if (error != 0)
		{
			printk("SOUND: start_play_dma fail !%\n");
			return -ENODEV;
		}
	
	#ifdef CONFIG_USE_aic23
	test_close();
	ver_free_dma(ch_p);
	ver_end_dma(ch_p);
		
	kfree(Play_Buffer);
	#endif

}



static struct file_operations i2s_fops = {
    open:i2s_open,
    release:i2s_release,
	read:i2s_read,
	write:i2s_write,
	ioctl:i2s_ioctl,
};

static int __init setup_i2s(char *str)
{
	if(str[0] == 'l') use_i2s=1;
	else if(str[0]=='m') use_i2s=2;
	else if (str[0]=='q') use_i2s=3;	
	else if (str[0]=='p') use_i2s=4;
	
	return 1;
}


__init int i2s_init(void)
{ 
	int error;

	printk(" use_i2s=%d\n",use_i2s);

	if(use_i2s == 0) return -ENODEV;   
	
	if( register_chrdev(205, "i2s-snd", &i2s_fops) < 0){
		printk("register i2s_snd failed\n");
		return -ENODEV;
	}

	
	#ifdef  CONFIG_USE_wm8976
 	error=init_wm8976();
	#endif

	#ifdef CONFIG_USE_aic23
	error=init_AIC23();
	#endif
	
	if (error != 0)
	{
		printk("SOUND: init_i2c fail !\n");
		return -ENODEV;
	}
	
	error = init_i2sbase();
	if (error != 0)
	{
		printk("SOUND: init_i2s fail !\n");
		return -ENODEV;
	}


	 i2s_test();
	
	#ifdef CONFIG_USE_aic23
	if((error=init_GPIO5())!=0) 
        {        
	printk( "GPIO INIT ERROR\n");	
	return -ENODEV;
  	}
	
  	if((error=request_irq(INT_VIC_IIS_GP5_0, i2s_interrupt, SA_SHIRQ, "i2s_tlv320aic23b", IIS_BASE))!=0){
	              printk(KERN_WARNING "i2s: unable to get IRQ\n");
                return -EBUSY; 
        }
	#endif
	
	printk("<1>i2s-snd ok\n");
	
	return 0;
}

module_init(i2s_init);
__setup("i2s=", setup_i2s);




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -