Back to home page

OSCL-LXR

 
 

    


0001 ===========
0002 ISA Drivers
0003 ===========
0004 
0005 The following text is adapted from the commit message of the initial
0006 commit of the ISA bus driver authored by Rene Herman.
0007 
0008 During the recent "isa drivers using platform devices" discussion it was
0009 pointed out that (ALSA) ISA drivers ran into the problem of not having
0010 the option to fail driver load (device registration rather) upon not
0011 finding their hardware due to a probe() error not being passed up
0012 through the driver model. In the course of that, I suggested a separate
0013 ISA bus might be best; Russell King agreed and suggested this bus could
0014 use the .match() method for the actual device discovery.
0015 
0016 The attached does this. For this old non (generically) discoverable ISA
0017 hardware only the driver itself can do discovery so as a difference with
0018 the platform_bus, this isa_bus also distributes match() up to the
0019 driver.
0020 
0021 As another difference: these devices only exist in the driver model due
0022 to the driver creating them because it might want to drive them, meaning
0023 that all device creation has been made internal as well.
0024 
0025 The usage model this provides is nice, and has been acked from the ALSA
0026 side by Takashi Iwai and Jaroslav Kysela. The ALSA driver module_init's
0027 now (for oldisa-only drivers) become::
0028 
0029         static int __init alsa_card_foo_init(void)
0030         {
0031                 return isa_register_driver(&snd_foo_isa_driver, SNDRV_CARDS);
0032         }
0033 
0034         static void __exit alsa_card_foo_exit(void)
0035         {
0036                 isa_unregister_driver(&snd_foo_isa_driver);
0037         }
0038 
0039 Quite like the other bus models therefore. This removes a lot of
0040 duplicated init code from the ALSA ISA drivers.
0041 
0042 The passed in isa_driver struct is the regular driver struct embedding a
0043 struct device_driver, the normal probe/remove/shutdown/suspend/resume
0044 callbacks, and as indicated that .match callback.
0045 
0046 The "SNDRV_CARDS" you see being passed in is a "unsigned int ndev"
0047 parameter, indicating how many devices to create and call our methods
0048 with.
0049 
0050 The platform_driver callbacks are called with a platform_device param;
0051 the isa_driver callbacks are being called with a ``struct device *dev,
0052 unsigned int id`` pair directly -- with the device creation completely
0053 internal to the bus it's much cleaner to not leak isa_dev's by passing
0054 them in at all. The id is the only thing we ever want other then the
0055 struct device anyways, and it makes for nicer code in the callbacks as
0056 well.
0057 
0058 With this additional .match() callback ISA drivers have all options. If
0059 ALSA would want to keep the old non-load behaviour, it could stick all
0060 of the old .probe in .match, which would only keep them registered after
0061 everything was found to be present and accounted for. If it wanted the
0062 behaviour of always loading as it inadvertently did for a bit after the
0063 changeover to platform devices, it could just not provide a .match() and
0064 do everything in .probe() as before.
0065 
0066 If it, as Takashi Iwai already suggested earlier as a way of following
0067 the model from saner buses more closely, wants to load when a later bind
0068 could conceivably succeed, it could use .match() for the prerequisites
0069 (such as checking the user wants the card enabled and that port/irq/dma
0070 values have been passed in) and .probe() for everything else. This is
0071 the nicest model.
0072 
0073 To the code...
0074 
0075 This exports only two functions; isa_{,un}register_driver().
0076 
0077 isa_register_driver() register's the struct device_driver, and then
0078 loops over the passed in ndev creating devices and registering them.
0079 This causes the bus match method to be called for them, which is::
0080 
0081         int isa_bus_match(struct device *dev, struct device_driver *driver)
0082         {
0083                 struct isa_driver *isa_driver = to_isa_driver(driver);
0084 
0085                 if (dev->platform_data == isa_driver) {
0086                         if (!isa_driver->match ||
0087                                 isa_driver->match(dev, to_isa_dev(dev)->id))
0088                                 return 1;
0089                         dev->platform_data = NULL;
0090                 }
0091                 return 0;
0092         }
0093 
0094 The first thing this does is check if this device is in fact one of this
0095 driver's devices by seeing if the device's platform_data pointer is set
0096 to this driver. Platform devices compare strings, but we don't need to
0097 do that with everything being internal, so isa_register_driver() abuses
0098 dev->platform_data as a isa_driver pointer which we can then check here.
0099 I believe platform_data is available for this, but if rather not, moving
0100 the isa_driver pointer to the private struct isa_dev is ofcourse fine as
0101 well.
0102 
0103 Then, if the the driver did not provide a .match, it matches. If it did,
0104 the driver match() method is called to determine a match.
0105 
0106 If it did **not** match, dev->platform_data is reset to indicate this to
0107 isa_register_driver which can then unregister the device again.
0108 
0109 If during all this, there's any error, or no devices matched at all
0110 everything is backed out again and the error, or -ENODEV, is returned.
0111 
0112 isa_unregister_driver() just unregisters the matched devices and the
0113 driver itself.
0114 
0115 module_isa_driver is a helper macro for ISA drivers which do not do
0116 anything special in module init/exit. This eliminates a lot of
0117 boilerplate code. Each module may only use this macro once, and calling
0118 it replaces module_init and module_exit.
0119 
0120 max_num_isa_dev is a macro to determine the maximum possible number of
0121 ISA devices which may be registered in the I/O port address space given
0122 the address extent of the ISA devices.