ISA Drivers¶
The following text is adapted from the commit message of the initialcommit of the ISA bus driver authored by Rene Herman.
During the recent “isa drivers using platform devices” discussion it waspointed out that (ALSA) ISA drivers ran into the problem of not havingthe option to fail driver load (device registration rather) upon notfinding their hardware due to aprobe() error not being passed upthrough the driver model. In the course of that, I suggested a separateISA bus might be best; Russell King agreed and suggested this bus coulduse the .match() method for the actual device discovery.
The attached does this. For this old non (generically) discoverable ISAhardware only the driver itself can do discovery so as a difference withthe platform_bus, this isa_bus also distributesmatch() up to thedriver.
As another difference: these devices only exist in the driver model dueto the driver creating them because it might want to drive them, meaningthat all device creation has been made internal as well.
The usage model this provides is nice, and has been acked from the ALSAside by Takashi Iwai and Jaroslav Kysela. The ALSA driver module_init’snow (for oldisa-only drivers) become:
static int __init alsa_card_foo_init(void){ return isa_register_driver(&snd_foo_isa_driver, SNDRV_CARDS);}static void __exit alsa_card_foo_exit(void){ isa_unregister_driver(&snd_foo_isa_driver);}Quite like the other bus models therefore. This removes a lot ofduplicated init code from the ALSA ISA drivers.
The passed in isa_driverstructis the regular driverstructembedding astructdevice_driver, the normal probe/remove/shutdown/suspend/resumecallbacks, and as indicated that .match callback.
The “SNDRV_CARDS” you see being passed in is a “unsigned int ndev”parameter, indicating how many devices to create and call our methodswith.
The platform_driver callbacks are called with a platform_device param;the isa_driver callbacks are being called with astructdevice*dev,unsignedintid pair directly -- with the device creation completelyinternal to the bus it’s much cleaner to not leak isa_dev’s by passingthem in at all. The id is the only thing we ever want other then thestructdevice anyways, and it makes for nicer code in the callbacks aswell.
With this additional .match() callback ISA drivers have all options. IfALSA would want to keep the old non-load behaviour, it could stick allof the old .probe in .match, which would only keep them registered aftereverything was found to be present and accounted for. If it wanted thebehaviour of always loading as it inadvertently did for a bit after thechangeover to platform devices, it could just not provide a .match() anddo everything in .probe() as before.
If it, as Takashi Iwai already suggested earlier as a way of followingthe model from saner buses more closely, wants to load when a later bindcould conceivably succeed, it could use .match() for the prerequisites(such as checking the user wants the card enabled and that port/irq/dmavalues have been passed in) and .probe() for everything else. This isthe nicest model.
To the code...
This exports only two functions; isa_{,un}register_driver().
isa_register_driver() register’s thestructdevice_driver, and thenloops over the passed in ndev creating devices and registering them.This causes the bus match method to be called for them, which is:
int isa_bus_match(struct device *dev, struct device_driver *driver){ struct isa_driver *isa_driver = to_isa_driver(driver); if (dev->platform_data == isa_driver) { if (!isa_driver->match || isa_driver->match(dev, to_isa_dev(dev)->id)) return 1; dev->platform_data = NULL; } return 0;}The first thing this does is check if this device is in fact one of thisdriver’s devices by seeing if the device’s platform_data pointer is setto this driver. Platform devices compare strings, but we don’t need todo that with everything being internal, soisa_register_driver() abusesdev->platform_data as a isa_driver pointer which we can then check here.I believe platform_data is available for this, but if rather not, movingthe isa_driver pointer to the privatestructisa_dev is ofcourse fine aswell.
Then, if the driver did not provide a .match, it matches. If it did,the drivermatch() method is called to determine a match.
If it didnot match, dev->platform_data is reset to indicate this toisa_register_driver which can then unregister the device again.
If during all this, there’s any error, or no devices matched at alleverything is backed out again and the error, or -ENODEV, is returned.
isa_unregister_driver() just unregisters the matched devices and thedriver itself.
module_isa_driver is a helper macro for ISA drivers which do not doanything special in module init/exit. This eliminates a lot ofboilerplate code. Each module may only use this macro once, and callingit replaces module_init and module_exit.
max_num_isa_dev is a macro to determine the maximum possible number ofISA devices which may be registered in the I/O port address space giventhe address extent of the ISA devices.