i2c_new_dummy有什么作用?

kzs*_*kzs 7 c linux-device-driver linux-kernel

我正在研究一个mfd驱动程序.有一个i2c总线,由四个i2c客户端设备共享(在单个IC上).所述i2c_new_dummy附接的适配器每个客户端时API被使用.

为什么有必要为不同的客户端使用不同的适配器逻辑?mfd设备实际上如何工作?

小智 7

众所周知,I2C总线将有来自规范定义的127个客户端; 一个7bit 地址1bit读/写.

第一个字节是I2C设备地址,与该地址匹配的设备将下拉该ACK位.接下来是数据,大部分时间这将是寄存器的地址.

因此,如果您有四个I2C客户端,即使它们包含在SOC中,您也将获得四个设备和四个客户端句柄.

但有时你不需要这么多.

另一种情况是当前的SOC,一个芯片(如tps65910)将具有很多功能,包括导通电压,CODEC等.每个驱动程序都将用于I2C设置寄存器.你不能为一个驱动程序请求一个句柄,所以这就是它调用的原因i2c_new_dummy.

来自内核i2c-core.c的评论,

/**
 * i2c_new_dummy - return a new i2c device bound to a dummy driver
 * @adapter: the adapter managing the device
 * @address: seven bit address to be used
 * Context: can sleep
 *
 * This returns an I2C client bound to the "dummy" driver, intended for use
 * with devices that consume multiple addresses.  Examples of such chips
 * include various EEPROMS (like 24c04 and 24c08 models).
 *
 * These dummy devices have two main uses.  First, most I2C and SMBus calls
 * except i2c_transfer() need a client handle; the dummy will be that handle.
 * And second, this prevents the specified address from being bound to a
 * different driver.
 *
 * This returns the new i2c client, which should be saved for later use with
 * i2c_unregister_device(); or NULL to indicate an error.
 */
Run Code Online (Sandbox Code Playgroud)