rk3288 Android 7.1 rt5640 调试

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 的寄存器控制

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值