14

I am aware of I2C in a very basic level which relies inside linux kernel, but no clue to implement a basic I2C driver.

Trying to moving for a start in I2C device driver. could you please suggest any beginner tutorial with source code mapping !!

Ahmed Masud
  • 21,655
  • 3
  • 33
  • 58
San
  • 905
  • 3
  • 16
  • 33

3 Answers3

34

linux-source/Documentation/i2c/ has lot of the information you'd need. .../writing-clients.txt is a good place to start.

Have a look at the online version:

https://www.kernel.org/doc/Documentation/i2c/writing-clients

There is an okay sort of a tutorial at:

http://renjucnair.blogspot.ca/2012/01/writing-i2c-client-driver.html

Here is a good commentary on someone writing an i2c driver and has a tutorial feel to it:

http://www.embedded-bits.co.uk/2009/i2c-in-the-2632-linux-kernel/

Here is some sample code:

http://code.google.com/p/ldd-templates/source/browse/drivers/i2c/sample-i2c-client.c

Ahmed Masud
  • 21,655
  • 3
  • 33
  • 58
  • 1
    Thank you Ahmed !! I like your posts. I feel, I can see my code working from the 2nd link that you gave provided. Awesome links.. upvoted !! – San May 24 '13 at 10:48
  • 1
    sure.. Here I accepted it !! – San May 27 '13 at 04:21
  • [This](https://www.kernel.org/doc/Documentation/i2c/writing-clients) is a bit confusing, normally in a micro-controller you would initialize the registers, clock frequency, mode of operation, corresponding pins, etc, who does all that in this case? – Abel Tom Feb 23 '18 at 10:50
4

I2C driver is implemented as a platform driver in linux kernel.So first you need to understand the linux model for platform devices.

Please go through below documentation under linux kernel for platform devices: https://www.kernel.org/doc/Documentation/driver-model/platform.txt

You also need to understand the bus structure under linux kernel.Please refer to the below link: http://www.mjmwired.net/kernel/Documentation/driver-model/bus.txt

Now you can google for I2C drivers and further study.

a.saurabh
  • 1,163
  • 10
  • 15
-2

Have a look at the smbus modules available for many programming languages...then write the driver for your i2c device around that.

Mike Molt
  • 41
  • 1
  • 7