Skip to contentSkip to conversation

The driver model, I2C and gpio provision on Sharp SL-C1000 (Akita)

RFC David Brownell 2 participants 3 messages Nov 3, 2005

lore
Share & tools
lore
#0 lore raw
Quoted 2 lines
Quoted 2 lines

It seems that making i2c init early is only sane choice. I realize PC people will hate it...

What do you mean by "early"? Other than maybe linking it earlier in the drivers/Makefile, and probably running some arch-specific i2c controller (and certain i2c chip) drivers at subsys_initcall rather than at device_initcall ... does the 2.6.14 kernel need changes?

Quoted 4 lines
Quoted 1 line

but apart from that, why is it impractical?

FWIW, I have also run into this "I need I2C early in boot, but it's not inited until late" on SiByte ...

Likewise on many OMAP boards, which tend to have the power management and other essential features on I2C.

Some board-specific init code ends up needing to run after the probe() logic of the tps6501x driver ... like for example, using a GPIO (!) there to power up the Ethernet controller which may be needed for the root filesystem. (At least on many development systems!)

You can see where that leads: we patched the i2c subsystem so that it runs at subsys_initcall ... and also the omap_i2c driver, and the tps65010 driver. No other drivers need to be changed, just the ones involved in that board's power management.

Richard:

Quoted 4 lines

I had to turn akita-ioexp into a platform device to get the suspend signal which is used to flush the workqueue. With a platform device available at machine init time, I can insert it as a parent of the corgi device chain which means its one of the last devices to be suspended.

By doing all that stuff as "subsys_initcall", the relevant I2C gpio hardware will be also be suspended "late" ... without such a fake platform device. Unless you're doing selective suspend, details of the device tree matter less than the order used to create devices.

- Dave

#1 lore raw
Quoted 8 lines · David Brownell

Likewise on many OMAP boards, which tend to have the power management and other essential features on I2C.

Some board-specific init code ends up needing to run after the probe() logic of the tps6501x driver ... like for example, using a GPIO (!) there to power up the Ethernet controller which may be needed for the root filesystem. (At least on many development systems!)

Quoted 4 lines

You can see where that leads: we patched the i2c subsystem so that it runs at subsys_initcall ... and also the omap_i2c driver, and the tps65010 driver. No other drivers need to be changed, just the ones involved in that board's power management.

Its not as simple as this in my case. Yes, you can patch the maxim i2c driver and the pxa i2c controller to run at subsys_initcall level which is fine. akita-ioexp has to run at a higher level (fs_initcall) as it will run before the i2c subsystem (being in arch as against drivers).

I don't think is feasible to go through the LCD, IrDA and sound subsystems trying to guarantee what init levels they're going to access the gpios at once you start getting to fs_initcall level.

This could be a case for putting akita-ioexp into drivers/i2c/chips but see my other thoughts below...

Quoted 11 lines

Richard:

Quoted 4 lines

I had to turn akita-ioexp into a platform device to get the suspend signal which is used to flush the workqueue. With a platform device available at machine init time, I can insert it as a parent of the corgi device chain which means its one of the last devices to be suspended.

By doing all that stuff as "subsys_initcall", the relevant I2C gpio hardware will be also be suspended "late" ... without such a fake platform device. Unless you're doing selective suspend, details of the device tree matter less than the order used to create devices.

I'd like to keep the device tree correct, then if anyone does want to selectively suspend things, it will work and it also works if someone decides to change the device init order around at some later date and not everything will break.

I'm coming to the view that I should merge the max7310 i2c driver into akita-ioexp and lose the general case driver for the following reasons:

1. Having a header file around for two functions seems excessive and I can't see any alternative
2. The MAX7310 has 56 different i2c addresses and no way of detecting the presence of the chip. Autoprobing on akita means you end up with the sound codec being taken by the max7310 driver. I don't like to think what it would do on other systems.
3. There's no interdependency between two drivers and hence it should be more robust.
4. I can lose the workqueue "find the i2c client" routine as the driver can know when the i2c device has been detected and the client setup. (the workqueue is still needed to act on gpio requests in case they come from interrupt context but the driver becomes simpler and of a more sane design).

Richard

#2 lore raw
Quoted 5 lines · Richard Purdie

Its not as simple as this in my case. Yes, you can patch the maxim i2c driver and the pxa i2c controller to run at subsys_initcall level which is fine. akita-ioexp has to run at a higher level (fs_initcall) as it will run before the i2c subsystem (being in arch as against drivers).

The general policy is that the "arch" directories shouldn't have drivers; they should live in the "drivers" directories. Then there are still issues of how board-specific code should be handled; hooking via platform_data doesn't quite solve all the important cases.

And of course I2C doesn't even support platform_data for board-specific data. Which means that adding board-specific code to I2C drivers is all but inevitable. (Or in the extreme, making drivers board-specific not general-purpose.)

Quoted 4 lines

I'd like to keep the device tree correct, then if anyone does want to selectively suspend things, it will work and it also works if someone decides to change the device init order around at some later date and not everything will break.

Don't assume that the device tree _model_ is ready to handle selective suspend yet. For one thing, the pm_parent mechanism is unusable, and that was originally intended to be the way to handle exceptions like these (where the "control tree" doesn't match the "power tree", or however you want to describe it).

I expect that by the time selective suspend is generally usable, the driver model support for it will have evolved substantially. In any case, it's not worth too much effort just now to try and make it work.

Quoted 5 lines

I'm coming to the view that I should merge the max7310 i2c driver into akita-ioexp and lose the general case driver for the following reasons:

1. Having a header file around for two functions seems excessive and I can't see any alternative

I'd have said that for the tps6501x, but its header now exports more like seven functions. Only a few are for GPIOs; and that doesn't even handle (yet!) the various IRQ sources!

A general purpose driver for max7310 (and similar I2C GPIO chips) should handle IRQs from input pins, too.

Quoted 4 lines

2. The MAX7310 has 56 different i2c addresses and no way of detecting the presence of the chip. Autoprobing on akita means you end up with the sound codec being taken by the max7310 driver. I don't like to think what it would do on other systems.

IMO this is a general problem with the I2C framework. It should be possible for board-specific init logic to (a) declare what devices exist, (b) what drivers they'll use, and (c) provide platform_data specific to that device, which could include board-specific callbacks.

The closest I think you can come now is to provide driver options on the kernel command line, like max7310.force, instead of trying to probe those way-too-many addresses. That can handle (a) and (b) but not (c); and it's an awkward way to handle static config data.

A related solution is for the driver init code to patch the i2c probe table based on what board is present (machine_is_akita etc) before registering that I2C driver. That's less error prone than relying on command line parameters. And again, that ignores (c).

Quoted 4 lines

3. There's no interdependency between two drivers and hence it should be more robust.
4. I can lose the workqueue "find the i2c client" routine as the driver can know when the i2c device has been detected and the client setup.

Yeah, the max7310 probe() could benefit from platform data holding a callback used to register a handle to that chip. The workqueue wouldn't be needed since the callback could just provide the right device.

Quoted 3 lines

(the workqueue is still needed to act on gpio requests in case they come from interrupt context but the driver becomes simpler and of a more sane design).

The TPS6501x driver currently just uses keventd rather than a dedicated workqueue. But again, this is a general problem in the I2C framework; if it had an asynch message model with completion callbacks, it'd be easy to issue requests from irq contexts, and task-synchronous calls could just use "struct completion" to wait for the callback.

That SPI framework code I did was specifically paying attention to those driver (and I/O) model issues, so it doesn't have the same glitches. The core I/O model is asynchronous, and board-specific code can provice platform_data and other hooks that'll kick in on device creation. I'd hope that once that all shakes out, the I2C stack can start to adopt the same sort of fixes.

- Dave

Quoted 2 lines

Richard