0
votes

I'm trying to write a Linux character device driver for a device that just happens to communicate over I2C. The device is an Atmel microcontroller with code that provides an I2C address. It already works using the typical i2c-dev method on the Linux-side.

So now I want to replicate i2c-dev as a new driver that works specifically with this particular device, so that I can add some of my own device-specific abstraction code on top. But I'd like to trim out all the unnecessary code from i2c-dev that currently makes it generic. What can be removed in this situation?

1
Are you suggesting to actually use SPI instead of I2C? Or just for reference because the programming model is more similar?Crunchex

1 Answers

1
votes

What can be removed in this situation?

You're actually asking an XY question.
You would be better off looking at and adapting an existing I2C device driver that is already similar in required functionality, rather than hacking a special case driver for userspace access.

So now I want to replicate i2c-dev as a new driver that works specifically with this particular device, so that I can add some of my own device-specific abstraction code on top

So then you actually need to write a "Client driver" as described below (from Linux Documentation/i2c/summary):

When we talk about I2C, we use the following terms:
   Bus    -> Algorithm
             Adapter
   Device -> Driver
             Client

 An Algorithm driver contains general code that can be used for a whole class
 of I2C adapters. Each specific adapter driver either depends on one algorithm
 driver, or includes its own implementation.

 A Driver driver (yes, this sounds ridiculous, sorry) contains the general
 code to access some type of device. Each detected device gets its own
 data in the Client structure. Usually, Driver and Client are more closely
 integrated than Algorithm and Adapter.

Details are in Documentation/i2c/writing-clients.
To find a driver of similar functionality, scan the list of I2C client drivers. Note that these I2C drivers are located in the Linux source tree by their functionality (e.g. drivers/rtc/ or drivers/hwmon/) and not their interface (i.e. I2C).