5 #include <linux/device.h>
6 #include <linux/kernel.h>
7 #include <linux/slab.h>
8 #include <linux/module.h>
9 #include <linux/init.h>
10 #include <linux/dma-mapping.h>
11 #include <linux/isa.h>
13 static struct device isa_bus
= {
23 #define to_isa_dev(x) container_of((x), struct isa_dev, dev)
25 static int isa_bus_match(struct device
*dev
, struct device_driver
*driver
)
27 struct isa_driver
*isa_driver
= to_isa_driver(driver
);
29 if (dev
->platform_data
== isa_driver
) {
30 if (!isa_driver
->match
||
31 isa_driver
->match(dev
, to_isa_dev(dev
)->id
))
33 dev
->platform_data
= NULL
;
38 static int isa_bus_probe(struct device
*dev
)
40 struct isa_driver
*isa_driver
= dev
->platform_data
;
42 if (isa_driver
&& isa_driver
->probe
)
43 return isa_driver
->probe(dev
, to_isa_dev(dev
)->id
);
48 static int isa_bus_remove(struct device
*dev
)
50 struct isa_driver
*isa_driver
= dev
->platform_data
;
52 if (isa_driver
&& isa_driver
->remove
)
53 return isa_driver
->remove(dev
, to_isa_dev(dev
)->id
);
58 static void isa_bus_shutdown(struct device
*dev
)
60 struct isa_driver
*isa_driver
= dev
->platform_data
;
62 if (isa_driver
&& isa_driver
->shutdown
)
63 isa_driver
->shutdown(dev
, to_isa_dev(dev
)->id
);
66 static int isa_bus_suspend(struct device
*dev
, pm_message_t state
)
68 struct isa_driver
*isa_driver
= dev
->platform_data
;
70 if (isa_driver
&& isa_driver
->suspend
)
71 return isa_driver
->suspend(dev
, to_isa_dev(dev
)->id
, state
);
76 static int isa_bus_resume(struct device
*dev
)
78 struct isa_driver
*isa_driver
= dev
->platform_data
;
80 if (isa_driver
&& isa_driver
->resume
)
81 return isa_driver
->resume(dev
, to_isa_dev(dev
)->id
);
86 static struct bus_type isa_bus_type
= {
88 .match
= isa_bus_match
,
89 .probe
= isa_bus_probe
,
90 .remove
= isa_bus_remove
,
91 .shutdown
= isa_bus_shutdown
,
92 .suspend
= isa_bus_suspend
,
93 .resume
= isa_bus_resume
96 static void isa_dev_release(struct device
*dev
)
98 kfree(to_isa_dev(dev
));
101 void isa_unregister_driver(struct isa_driver
*isa_driver
)
103 struct device
*dev
= isa_driver
->devices
;
106 struct device
*tmp
= to_isa_dev(dev
)->next
;
107 device_unregister(dev
);
110 driver_unregister(&isa_driver
->driver
);
112 EXPORT_SYMBOL_GPL(isa_unregister_driver
);
114 int isa_register_driver(struct isa_driver
*isa_driver
, unsigned int ndev
)
119 isa_driver
->driver
.bus
= &isa_bus_type
;
120 isa_driver
->devices
= NULL
;
122 error
= driver_register(&isa_driver
->driver
);
126 for (id
= 0; id
< ndev
; id
++) {
127 struct isa_dev
*isa_dev
;
129 isa_dev
= kzalloc(sizeof *isa_dev
, GFP_KERNEL
);
135 isa_dev
->dev
.parent
= &isa_bus
;
136 isa_dev
->dev
.bus
= &isa_bus_type
;
138 dev_set_name(&isa_dev
->dev
, "%s.%u",
139 isa_driver
->driver
.name
, id
);
140 isa_dev
->dev
.platform_data
= isa_driver
;
141 isa_dev
->dev
.release
= isa_dev_release
;
144 isa_dev
->dev
.coherent_dma_mask
= DMA_BIT_MASK(24);
145 isa_dev
->dev
.dma_mask
= &isa_dev
->dev
.coherent_dma_mask
;
147 error
= device_register(&isa_dev
->dev
);
149 put_device(&isa_dev
->dev
);
153 if (isa_dev
->dev
.platform_data
) {
154 isa_dev
->next
= isa_driver
->devices
;
155 isa_driver
->devices
= &isa_dev
->dev
;
157 device_unregister(&isa_dev
->dev
);
160 if (!error
&& !isa_driver
->devices
)
164 isa_unregister_driver(isa_driver
);
168 EXPORT_SYMBOL_GPL(isa_register_driver
);
170 static int __init
isa_bus_init(void)
174 error
= bus_register(&isa_bus_type
);
176 error
= device_register(&isa_bus
);
178 bus_unregister(&isa_bus_type
);
183 device_initcall(isa_bus_init
);