linux - 可以从 Linux i2c-dev 驱动程序中删除什么以作为仅适用于一个设备的新驱动程序的基础?

标签 linux linux-device-driver i2c

我正在尝试为恰好通过 I2C 进行通信的设备编写 Linux 字符设备驱动程序。该设备是一个带有提供 I2C 地址的代码的 Atmel 微 Controller 。它已经在 Linux 端使用典型的 i2c-dev 方法工作。

所以现在我想复制 i2c-dev 作为一个新的驱动程序,专门用于这个特定的设备,这样我就可以在上面添加一些我自己的特定于设备的抽象代码。但我想从 i2c-dev 中删除所有不必要的代码,这些代码目前使它变得通用。在这种情况下可以删除什么?

最佳答案

What can be removed in this situation?

你实际上是在问一个 XY 问题。
您最好查看和调整现有的 I2C 设备驱动程序,该驱动程序在所需功能方面已经很相似,而不是破解一个特殊情况的驱动程序以进行用户空间访问。

So now I want to replicate i2c-dev as a new driver that works specifically with this particular device, so that I can add some of my own device-specific abstraction code on top

那么您实际上需要编写一个“客户端驱动程序”,如下所述(来自 Linux Documentation/i2c/summary):

When we talk about I2C, we use the following terms:
   Bus    -> Algorithm
             Adapter
   Device -> Driver
             Client

 An Algorithm driver contains general code that can be used for a whole class
 of I2C adapters. Each specific adapter driver either depends on one algorithm
 driver, or includes its own implementation.

 A Driver driver (yes, this sounds ridiculous, sorry) contains the general
 code to access some type of device. Each detected device gets its own
 data in the Client structure. Usually, Driver and Client are more closely
 integrated than Algorithm and Adapter.

详情请见 Documentation/i2c/writing-clients .
要查找具有类似功能的驱动程序,请扫描 I2C client drivers 的列表.请注意,这些 I2C 驱动程序按其功能(例如 drivers/rtc/drivers/hwmon/)而不是其接口(interface)(即 I2C)位于 Linux 源代码树中。

关于linux - 可以从 Linux i2c-dev 驱动程序中删除什么以作为仅适用于一个设备的新驱动程序的基础?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27572297/

相关文章:

c - 让我知道以下有关 USB 调制解调器插件和插件通知处理程序 API 或 Linux 中的系统调用的信息

c - USB 描述符的 ID_SERIAL 和 ID_SERIAL_SHORT udev 属性有什么区别

Linux 设备驱动程序注册程序

python - 树莓派 : issue communicating via I2C

linux - 从内核树中编译 eBPF C 代码时出错

linux - 将变量中的内容附加到日志文件

arduino - Android 作为 I2C 从设备

c - 与传感器 CCS 编译器的 I2C 通信

linux - 阿尔萨 : How to do stop and resume audio?

linux - 如何在Linux服务器上不使用sudo安装git