分析linux驱动关于设备树驱动和普通平台驱动的区别


//探测函数用于挂载驱动时获取I2C的设备ID
static int xrm117x_i2c_probe(struct i2c_client *i2c,
                   const struct i2c_device_id *id)
{
    struct xrm117x_devtype *devtype;
    unsigned long flags = 0;
    int ret;
    if (i2c->dev.of_node) {    //从设备树传入I2C的ID值
        const struct of_device_id *of_id =
                of_match_device(xrm117x_dt_ids, &i2c->dev);

        devtype = (struct xrm117x_devtype *)of_id->data;
    } else {                //从板载定义的信息中获取I2C的ID值
        devtype = (struct xrm117x_devtype *)id->driver_data;
        flags = IRQF_TRIGGER_FALLING;
    }
    xrm117x_i2c_client = i2c; 
    ret = xrm117x_probe(&i2c->dev, devtype,i2c->irq, flags);
    return ret;
}

//定义设备树用于匹配的驱动节点
static const struct of_device_id __maybe_unused xrm117x_dt_ids[] = {
    { .compatible = "exar,xrm117x",    .data = &xrm117x_devtype, },
    { }
};
MODULE_DEVICE_TABLE(of, xrm117x_dt_ids);

//定义设备驱动
static const struct i2c_device_id xrm117x_i2c_id_table[] = {
    { "xrm117x",    (kernel_ulong_t)&xrm117x_devtype, },
    { }
};
MODULE_DEVICE_TABLE(i2c, xrm117x_i2c_id_table);

static struct i2c_driver xrm117x_i2c_uart_driver = {
    .driver = {
        .name        = XRM117XX_NAME,
        .owner        = THIS_MODULE,
        .of_match_table    = of_match_ptr(xrm117x_dt_ids),
    },
    .probe        = xrm117x_i2c_probe,
    .remove        = xrm117x_i2c_remove,
    .id_table    = xrm117x_i2c_id_table,
};

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值