As with all bus dev DRV models, when we get a module, all we need to do is dev? DRV, the device driver
1, device
Method 1. Write an i2c_device.c yourself
#include <linux/kernel.h> #include <linux/module.h> #include <linux/platform_device.h> #include <linux/i2c.h> #include <linux/err.h> #include <linux/regmap.h> #include <linux/slab.h> //0x50 indicates the address of I2C device, which can be found in the I2C device chip manual static struct i2c_board_info at24cxx_info = { I2C_BOARD_INFO("at24c08", 0x50),//This name should be the same as the name in the ID table of the drv program }; static struct i2c_client *at24cxx_client; static int at24cxx_dev_init(void) { struct i2c_adapter *i2c_adap; i2c_adap = i2c_get_adapter(0);//The EEPROM to be tested here is connected to I2C bus 0, so the parameter here is 0 at24cxx_client = i2c_new_device(i2c_adap, &at24cxx_info); i2c_put_adapter(i2c_adap); return 0; } static void at24cxx_dev_exit(void) { i2c_unregister_device(at24cxx_client); } module_init(at24cxx_dev_init); module_exit(at24cxx_dev_exit); MODULE_LICENSE("GPL");
Method 2. Add device information directly to board level files
(1) Find the corresponding mach file in the directory of and arch/arm / to register
arch\arm\mach-s3c2440/mach-mini2440.c
static struct i2c_board_info i2c_devs[] __initdata = { { I2C_BOARD_INFO("eeprom", 0x50), }, { I2C_BOARD_INFO("isp1301_omap", 0x2d), .irq = OMAP_GPIO_IRQ(125), }, };
After adding the concept of device tree to Linux kernel, we will understand it more clearly with device tree
(2) Device tree for registration (my method)
&i2c1 { pinctrl-names = "default"; pinctrl-0 = <&i2c1_pins>; status = "okay"; clock-frequency = <400000>; tca9555: tca9555@20 { compatible = "ti,tca9555"; reg = <0x20>; };
Two, driver
Driver is the so-called driver we usually get from module manufacturers. How to implement driver?
Refer to the following post
I2C device driver under Linux 3.5
New handwritten Linux I2C driver