brintos

brintos / linux-shallow public Read only

0
0
Text · 5.1 KiB · 3df1b16 Raw
123 lines · plain
1===========2ISA Drivers3===========4 5The following text is adapted from the commit message of the initial6commit of the ISA bus driver authored by Rene Herman.7 8During the recent "isa drivers using platform devices" discussion it was9pointed out that (ALSA) ISA drivers ran into the problem of not having10the option to fail driver load (device registration rather) upon not11finding their hardware due to a probe() error not being passed up12through the driver model. In the course of that, I suggested a separate13ISA bus might be best; Russell King agreed and suggested this bus could14use the .match() method for the actual device discovery.15 16The attached does this. For this old non (generically) discoverable ISA17hardware only the driver itself can do discovery so as a difference with18the platform_bus, this isa_bus also distributes match() up to the19driver.20 21As another difference: these devices only exist in the driver model due22to the driver creating them because it might want to drive them, meaning23that all device creation has been made internal as well.24 25The usage model this provides is nice, and has been acked from the ALSA26side by Takashi Iwai and Jaroslav Kysela. The ALSA driver module_init's27now (for oldisa-only drivers) become::28 29	static int __init alsa_card_foo_init(void)30	{31		return isa_register_driver(&snd_foo_isa_driver, SNDRV_CARDS);32	}33 34	static void __exit alsa_card_foo_exit(void)35	{36		isa_unregister_driver(&snd_foo_isa_driver);37	}38 39Quite like the other bus models therefore. This removes a lot of40duplicated init code from the ALSA ISA drivers.41 42The passed in isa_driver struct is the regular driver struct embedding a43struct device_driver, the normal probe/remove/shutdown/suspend/resume44callbacks, and as indicated that .match callback.45 46The "SNDRV_CARDS" you see being passed in is a "unsigned int ndev"47parameter, indicating how many devices to create and call our methods48with.49 50The platform_driver callbacks are called with a platform_device param;51the isa_driver callbacks are being called with a ``struct device *dev,52unsigned int id`` pair directly -- with the device creation completely53internal to the bus it's much cleaner to not leak isa_dev's by passing54them in at all. The id is the only thing we ever want other then the55struct device anyways, and it makes for nicer code in the callbacks as56well.57 58With this additional .match() callback ISA drivers have all options. If59ALSA would want to keep the old non-load behaviour, it could stick all60of the old .probe in .match, which would only keep them registered after61everything was found to be present and accounted for. If it wanted the62behaviour of always loading as it inadvertently did for a bit after the63changeover to platform devices, it could just not provide a .match() and64do everything in .probe() as before.65 66If it, as Takashi Iwai already suggested earlier as a way of following67the model from saner buses more closely, wants to load when a later bind68could conceivably succeed, it could use .match() for the prerequisites69(such as checking the user wants the card enabled and that port/irq/dma70values have been passed in) and .probe() for everything else. This is71the nicest model.72 73To the code...74 75This exports only two functions; isa_{,un}register_driver().76 77isa_register_driver() register's the struct device_driver, and then78loops over the passed in ndev creating devices and registering them.79This causes the bus match method to be called for them, which is::80 81	int isa_bus_match(struct device *dev, struct device_driver *driver)82	{83		struct isa_driver *isa_driver = to_isa_driver(driver);84 85		if (dev->platform_data == isa_driver) {86			if (!isa_driver->match ||87				isa_driver->match(dev, to_isa_dev(dev)->id))88				return 1;89			dev->platform_data = NULL;90		}91		return 0;92	}93 94The first thing this does is check if this device is in fact one of this95driver's devices by seeing if the device's platform_data pointer is set96to this driver. Platform devices compare strings, but we don't need to97do that with everything being internal, so isa_register_driver() abuses98dev->platform_data as a isa_driver pointer which we can then check here.99I believe platform_data is available for this, but if rather not, moving100the isa_driver pointer to the private struct isa_dev is ofcourse fine as101well.102 103Then, if the driver did not provide a .match, it matches. If it did,104the driver match() method is called to determine a match.105 106If it did **not** match, dev->platform_data is reset to indicate this to107isa_register_driver which can then unregister the device again.108 109If during all this, there's any error, or no devices matched at all110everything is backed out again and the error, or -ENODEV, is returned.111 112isa_unregister_driver() just unregisters the matched devices and the113driver itself.114 115module_isa_driver is a helper macro for ISA drivers which do not do116anything special in module init/exit. This eliminates a lot of117boilerplate code. Each module may only use this macro once, and calling118it replaces module_init and module_exit.119 120max_num_isa_dev is a macro to determine the maximum possible number of121ISA devices which may be registered in the I/O port address space given122the address extent of the ISA devices.123