I have a i2c device which is connected to iMX6DL module, I am able to write data on it with the following command in terminal:
i2cset -y 0 0x2c 0x00 0x05
I have wrote a character driver, I want to access this device in my driver and work with it, I could not find a article to describe how to use i2c in kernel space, How should I work with i2c in kernel space?
There are lots of material available on Internet You can start from here - I2C and SMBus Subsystem — The Linux Kernel documentation
thank you for your response, yes I saw that article and many others including some drivers.
In those articles there is a function called i2c_master_send. which I saw in all drivers used to send data to i2c bus. In this function there is a input structure called i2c_client. this structure must be filled to send data to i2c bus and device, but there is no describing or example that I could find to how to fill this structure. I assume if this structure filled correctly I am able to send data to my device on i2c0. Can you help me with i2c_client structure?
The struct i2c_client is described here.
I have reached to my goal with following code in my driver:
#define VOL1_CHIP_ADDRESS 0x2c
#define VOL1_DATA_ADDRESS 0
struct i2c_client *clientstr;
struct file * fp;
oldfs = get_fs();
fp = filp_open("/dev/i2c-0",O_RDWR,0);
clientstr = (struct i2c_client *)fp->private_data;
Perfect. Thanks for the feedback.