How I2C driver works in Linux?

How I2C driver works in Linux?

I2C device drivers using this binding model work just like any other kind of driver in Linux: they provide a probe() method to bind to those devices, and a remove() method to unbind. static int foo_probe(struct i2c_client *client, const struct i2c_device_id *id); static int foo_remove(struct i2c_client *client);

Why I2C driver is used?

I2C is the name for a two-wire serial bus protocol originally developed by Phillips. It commonly is used in embedded systems so different components can communicate; PC motherboards use I2C to talk to different sensor chips.

What is the difference between SMBus and I2C?

I2C allows several modes, Standard, Fast and High-Speed. Standard mode allows clock frequencies as high as 100kHz while Fast and High-Speed modes are faster. SMbus allows clock frequencies only as high as 100kHz, so it is not necessary to compare SMBus to any but I2C Standard mode.

What is Module_device_table?

MODULE_DEVICE_TABLE is used to generate map files by depmod program; When device is hot-plugged, bus driver generates hotplug event.

How to write kernel drivers for I2C devices?

This is a small guide for those who want to write kernel drivers for I2C or SMBus devices, using Linux as the protocol host/master (not slave). To set up a driver, you need to do several things.

How to instantiate an I2C device in Linux?

If you know for a fact that an I2C device is connected to a given I2C bus, you can instantiate that device by simply filling an i2c_board_info structure with the device address and driver name, and calling i2c_new_client_device ().

When do I2C devices need to be detected?

Sometimes you do not know in advance which I2C devices are connected to a given I2C bus. This is for example the case of hardware monitoring devices on a PC’s SMBus. In that case, you may want to let your driver detect supported devices automatically.

How are I2C devices controlled in userspace?

Usually, I2C devices are controlled by a kernel driver. But it is also possible to access all devices on an adapter from userspace, through the /dev interface. You need to load module i2c-dev for this. Each registered I2C adapter gets a number, counting from 0.