Linux I2C device driver

本文介绍Linux I2C设备驱动的结构体填充及函数实现过程,包括attach_adapter、detach_client等关键函数的使用。此外,还详细阐述了如何通过i2c核心的i2c_add_driver和i2c_del_driver进行设备的添加与删除。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

**

Linux I2C device driver

**
主要工作:结构体的填充,与函数的实现
attach_adapter、detach_adapter、detach_client、device driver文件操作接口(read、write)

i2c-driver的初始化:

static struct i2c_driver hello_driver = {
    .driver = {
        .name = "hello",
    },
    .attach_adapter = hello_attach_adapter,
    .detach_client  = hello_detach_client,
    .command        = hello_command,
};

I2C 设备驱动的模块加载函数通用的方法是在 I2C 设备驱动的模块加载函数中完成两件事
(1)将 I2C 设备注册为一个字符设备
(2)通过 I2C 核心的 i2c_add_driver()函数添加 i2c_driver
在模块卸载函数中需要做相反的两件事
(1)通过 I2C 核心的 i2c_del_driver()函数删除 i2c_driver
(2)注销字符设备

This is, on the surface, a book about writing device drivers for the Linux system. That is a worthy goal, of course; the flow of new hardware products is not likely to slow down anytime soon, and somebody is going to have to make all those new gadgets work with Linux. But this book is also about how the Linux kernel works and how to adapt its workings to your needs or interests. Linux is an open system; with this book, we hope, it is more open and accessible to a larger community of developers. This is the third edition of Linux Device Drivers. The kernel has changed greatly since this book was first published, and we have tried to evolve the text to match. This edition covers the 2.6.10 kernel as completely as we are able. We have, this time around, elected to omit the discussion of backward compatibility with previous kernel versions. The changes from 2.4 are simply too large, and the 2.4 interface remains well documented in the (freely available) second edition. This edition contains quite a bit of new material relevant to the 2.6 kernel. The discussion of locking and concurrency has been expanded and moved into its own chapter. The Linux device model, which is new in 2.6, is covered in detail. There are new chapters on the USB bus and the serial driver subsystem; the chapter on PCI has also been enhanced. While the organization of the rest of the book resembles that of the earlier editions, every chapter has been thoroughly updated. We hope you enjoy reading this book as much as we have enjoyed writing it.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值