1、写一个设备节点用来操作寄存器
static int codec_dmo_open_file(struct inode *inode, struct file *file)
{
return 0;
}
static ssize_t codec_dmo_write_file(struct file *file,
const char __user *user_buf, size_t count, loff_t *ppos)
{
int val;
char buf[10];
struct snd_soc_codec *codec;
codec = rt5640_pv->codec;
if(copy_from_user(&buf,user_buf,count)){
return 5;
}
sscanf(buf, "%d", &val);
if(val == 0){
snd_soc_update_bits(codec, 0x0d, 0xff00, 0x5000);
snd_soc_update_bits(codec, 0x64, 0xC000, 0x8000);
snd_soc_update_bits(codec, 0x3E, 0x0022, 0x0020);
snd_soc_update_bits(codec, 0x01, 0x8080, 0x8080);
snd_soc_update_bits(codec, 0x03, 0x8080, 0x0000);
}else if(val == 1){
snd_soc_update_bits(codec, 0x0d, 0xff00, 0x0000);
snd_soc_update_bits(codec, 0x64, 0xC000, 0x4000);
snd_soc_update_bits(codec, 0x3E, 0x0022, 0x0002);
snd_soc_update_bits(codec, 0x01, 0x8080, 0x0000);
snd_soc_update_bits(codec, 0x03, 0x8080, 0x8080);
}else{
snd_soc_update_bits(codec, 0x0d, 0xff00, 0x0000);
snd_soc_update_bits(codec, 0x64, 0xC000, 0x0000);
snd_soc_update_bits(codec, 0x3E, 0x0022, 0x0022);
snd_soc_update_bits(codec, 0x01, 0x8080, 0x8080);
snd_soc_update_bits(codec, 0x03, 0x8080, 0x8080);
}
return count;
}
static const struct file_operations codec_dmo_fops = {
.open = codec_dmo_open_file,
.write = codec_dmo_write_file,
};
int dmo_major;
static struct class *ztl_dmo_drv_class;
static int __init snd_soc_dmo_init(void)
{
dmo_major = register_chrdev(0, "ztl_dmo", &codec_dmo_fops);
ztl_dmo_drv_class = class_create(THIS_MODULE,"ztl_dmo");
device_create(ztl_dmo_drv_class,NULL,MKDEV(dmo_major,0),NULL,"ztl_dmo");
return 0;
}
static void __exit snd_soc_dmo_exit(void)
{
unregister_chrdev(dmo_major, "ztl_dmo");
device_destroy(ztl_dmo_drv_class,MKDEV(dmo_major,0));
class_destroy(ztl_dmo_drv_class);
}
module_init(snd_soc_dmo_init);
module_exit(snd_soc_dmo_exit);
然后通过操作 /dev/ztl_dmo 节点进行 对rt5640 的寄存器控制