blob: f232c26a40be204de79f97f1eb2fa4f78a6a0cb8 [file] [log] [blame]
William Breathitt Grayad7afc32016-05-01 18:43:35 -04001ISA Drivers
2-----------
3
4The following text is adapted from the commit message of the initial
5commit of the ISA bus driver authored by Rene Herman.
6
7During the recent "isa drivers using platform devices" discussion it was
8pointed out that (ALSA) ISA drivers ran into the problem of not having
9the option to fail driver load (device registration rather) upon not
10finding their hardware due to a probe() error not being passed up
11through the driver model. In the course of that, I suggested a separate
12ISA bus might be best; Russell King agreed and suggested this bus could
13use the .match() method for the actual device discovery.
14
15The attached does this. For this old non (generically) discoverable ISA
16hardware only the driver itself can do discovery so as a difference with
17the platform_bus, this isa_bus also distributes match() up to the
18driver.
19
20As another difference: these devices only exist in the driver model due
21to the driver creating them because it might want to drive them, meaning
22that all device creation has been made internal as well.
23
24The usage model this provides is nice, and has been acked from the ALSA
25side by Takashi Iwai and Jaroslav Kysela. The ALSA driver module_init's
26now (for oldisa-only drivers) become:
27
28static int __init alsa_card_foo_init(void)
29{
30 return isa_register_driver(&snd_foo_isa_driver, SNDRV_CARDS);
31}
32
33static void __exit alsa_card_foo_exit(void)
34{
35 isa_unregister_driver(&snd_foo_isa_driver);
36}
37
38Quite like the other bus models therefore. This removes a lot of
39duplicated init code from the ALSA ISA drivers.
40
41The passed in isa_driver struct is the regular driver struct embedding a
42struct device_driver, the normal probe/remove/shutdown/suspend/resume
43callbacks, and as indicated that .match callback.
44
45The "SNDRV_CARDS" you see being passed in is a "unsigned int ndev"
46parameter, indicating how many devices to create and call our methods
47with.
48
49The platform_driver callbacks are called with a platform_device param;
50the isa_driver callbacks are being called with a "struct device *dev,
51unsigned int id" pair directly -- with the device creation completely
52internal to the bus it's much cleaner to not leak isa_dev's by passing
53them in at all. The id is the only thing we ever want other then the
54struct device * anyways, and it makes for nicer code in the callbacks as
55well.
56
57With this additional .match() callback ISA drivers have all options. If
58ALSA would want to keep the old non-load behaviour, it could stick all
59of the old .probe in .match, which would only keep them registered after
60everything was found to be present and accounted for. If it wanted the
61behaviour of always loading as it inadvertently did for a bit after the
62changeover to platform devices, it could just not provide a .match() and
63do everything in .probe() as before.
64
65If it, as Takashi Iwai already suggested earlier as a way of following
66the model from saner buses more closely, wants to load when a later bind
67could conceivably succeed, it could use .match() for the prerequisites
68(such as checking the user wants the card enabled and that port/irq/dma
69values have been passed in) and .probe() for everything else. This is
70the nicest model.
71
72To the code...
73
74This exports only two functions; isa_{,un}register_driver().
75
76isa_register_driver() register's the struct device_driver, and then
77loops over the passed in ndev creating devices and registering them.
78This causes the bus match method to be called for them, which is:
79
80int isa_bus_match(struct device *dev, struct device_driver *driver)
81{
82 struct isa_driver *isa_driver = to_isa_driver(driver);
83
84 if (dev->platform_data == isa_driver) {
85 if (!isa_driver->match ||
86 isa_driver->match(dev, to_isa_dev(dev)->id))
87 return 1;
88 dev->platform_data = NULL;
89 }
90 return 0;
91}
92
93The first thing this does is check if this device is in fact one of this
94driver's devices by seeing if the device's platform_data pointer is set
95to this driver. Platform devices compare strings, but we don't need to
96do that with everything being internal, so isa_register_driver() abuses
97dev->platform_data as a isa_driver pointer which we can then check here.
98I believe platform_data is available for this, but if rather not, moving
99the isa_driver pointer to the private struct isa_dev is ofcourse fine as
100well.
101
102Then, if the the driver did not provide a .match, it matches. If it did,
103the driver match() method is called to determine a match.
104
105If it did _not_ match, dev->platform_data is reset to indicate this to
106isa_register_driver which can then unregister the device again.
107
108If during all this, there's any error, or no devices matched at all
109everything is backed out again and the error, or -ENODEV, is returned.
110
111isa_unregister_driver() just unregisters the matched devices and the
112driver itself.
113
114module_isa_driver is a helper macro for ISA drivers which do not do
115anything special in module init/exit. This eliminates a lot of
116boilerplate code. Each module may only use this macro once, and calling
117it replaces module_init and module_exit.
118
119max_num_isa_dev is a macro to determine the maximum possible number of
120ISA devices which may be registered in the I/O port address space given
121the address extent of the ISA devices.