Xian Stannard
Xian Stannard

Reputation: 376

How should I structure a linux driver that uses several chips in one device?

I have a hardware device that consists of 3 separate chips on an I2C bus. I would like to group them together and expose them to userland as one logical device. The user would see the logical device represented by a single directory somewhere in /sys as well as the nodes you'd expect from the I2C chips under /sys/class/i2c-adapter/i2c-?/*.

One of the chips is an MCP23017 which as far as I can tell already has a driver (drivers/gpio/gpio-mcp23s08.c) and I'd like to reuse it. Another of the chips is a PCA9685 and I would like to contribute a driver for this chip that uses the PWM system in include/linux/pwm.h. The third chip is an MCU running custom firmware.

How should I structure the set of drivers? One idea I had is to register a platform driver to present the logical device, and use I2C drivers from within that. Is this a good way to go? Are there better ways?

The logical device is a motor driver board and IR receiver. I have a simple diagram of its structure.

I'm looking to create two interfaces. The first similar to /sys/class/gpio where motors can be 'exported' and then accessed via reading and writing attributes. This would be useful for shell script access and quick debugging of the mechanical parts of the system attached to the motors. The second a character device node in /dev where data can be read or written in binary format, more useful for application control.

Upvotes: 4

Views: 292

Answers (1)

wiesniak
wiesniak

Reputation: 583

it seems not usual design, are you sure you have access to I2C bus of all chips ?

I think you should be able to talk only to MCU, and MCU should manage other devices. Otherwise, why MCU is there ? However, I cannot see your diagram, perhaps link is wrong.

Upvotes: 1

Related Questions