aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGrant Likely <grant.likely@secretlab.ca>2010-04-13 19:13:01 -0400
committerGrant Likely <grant.likely@secretlab.ca>2010-05-22 02:10:40 -0400
commit597b9d1e44e9ba69f2454a5318bbe7a6d5e6930a (patch)
tree373f1f1387143b0ea8811ca6e2a6812f0a86d933
parent173b3a7a059a6998a6c0733710818c473cc0de4c (diff)
drivercore: Add of_match_table to the common device drivers
OF-style matching can be available to any device, on any type of bus. This patch allows any driver to provide an OF match table when CONFIG_OF is enabled so that drivers can be bound against devices described in the device tree. Signed-off-by: Grant Likely <grant.likely@secretlab.ca> Acked-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r--arch/powerpc/kernel/ibmebus.c5
-rw-r--r--drivers/macintosh/macio_asic.c5
-rw-r--r--drivers/of/platform.c7
-rw-r--r--include/linux/device.h4
4 files changed, 14 insertions, 7 deletions
diff --git a/arch/powerpc/kernel/ibmebus.c b/arch/powerpc/kernel/ibmebus.c
index a9f31631a293..355257bb149d 100644
--- a/arch/powerpc/kernel/ibmebus.c
+++ b/arch/powerpc/kernel/ibmebus.c
@@ -201,8 +201,11 @@ static int ibmebus_create_devices(const struct of_device_id *matches)
201 201
202int ibmebus_register_driver(struct of_platform_driver *drv) 202int ibmebus_register_driver(struct of_platform_driver *drv)
203{ 203{
204 if (!drv->driver.of_match_table)
205 drv->driver.of_match_table = drv->match_table;
206
204 /* If the driver uses devices that ibmebus doesn't know, add them */ 207 /* If the driver uses devices that ibmebus doesn't know, add them */
205 ibmebus_create_devices(drv->match_table); 208 ibmebus_create_devices(drv->driver.of_match_table);
206 209
207 return of_register_driver(drv, &ibmebus_bus_type); 210 return of_register_driver(drv, &ibmebus_bus_type);
208} 211}
diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
index 48a5f0406865..e3ba1d8001a3 100644
--- a/drivers/macintosh/macio_asic.c
+++ b/drivers/macintosh/macio_asic.c
@@ -40,8 +40,7 @@ static struct macio_chip *macio_on_hold;
40static int macio_bus_match(struct device *dev, struct device_driver *drv) 40static int macio_bus_match(struct device *dev, struct device_driver *drv)
41{ 41{
42 struct macio_dev * macio_dev = to_macio_device(dev); 42 struct macio_dev * macio_dev = to_macio_device(dev);
43 struct macio_driver * macio_drv = to_macio_driver(drv); 43 const struct of_device_id * matches = drv->of_match_table;
44 const struct of_device_id * matches = macio_drv->match_table;
45 44
46 if (!matches) 45 if (!matches)
47 return 0; 46 return 0;
@@ -84,7 +83,7 @@ static int macio_device_probe(struct device *dev)
84 83
85 macio_dev_get(macio_dev); 84 macio_dev_get(macio_dev);
86 85
87 match = of_match_device(drv->match_table, &macio_dev->ofdev); 86 match = of_match_device(drv->driver.of_match_table, &macio_dev->ofdev);
88 if (match) 87 if (match)
89 error = drv->probe(macio_dev, match); 88 error = drv->probe(macio_dev, match);
90 if (error) 89 if (error)
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index d58ade170c4b..9fd7f7d0a0d1 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -22,8 +22,7 @@ extern struct device_attribute of_platform_device_attrs[];
22static int of_platform_bus_match(struct device *dev, struct device_driver *drv) 22static int of_platform_bus_match(struct device *dev, struct device_driver *drv)
23{ 23{
24 struct of_device *of_dev = to_of_device(dev); 24 struct of_device *of_dev = to_of_device(dev);
25 struct of_platform_driver *of_drv = to_of_platform_driver(drv); 25 const struct of_device_id *matches = drv->of_match_table;
26 const struct of_device_id *matches = of_drv->match_table;
27 26
28 if (!matches) 27 if (!matches)
29 return 0; 28 return 0;
@@ -46,7 +45,7 @@ static int of_platform_device_probe(struct device *dev)
46 45
47 of_dev_get(of_dev); 46 of_dev_get(of_dev);
48 47
49 match = of_match_device(drv->match_table, of_dev); 48 match = of_match_device(drv->driver.of_match_table, of_dev);
50 if (match) 49 if (match)
51 error = drv->probe(of_dev, match); 50 error = drv->probe(of_dev, match);
52 if (error) 51 if (error)
@@ -391,6 +390,8 @@ int of_register_driver(struct of_platform_driver *drv, struct bus_type *bus)
391 drv->driver.name = drv->name; 390 drv->driver.name = drv->name;
392 if (!drv->driver.owner) 391 if (!drv->driver.owner)
393 drv->driver.owner = drv->owner; 392 drv->driver.owner = drv->owner;
393 if (!drv->driver.of_match_table)
394 drv->driver.of_match_table = drv->match_table;
394 drv->driver.bus = bus; 395 drv->driver.bus = bus;
395 396
396 /* register with core */ 397 /* register with core */
diff --git a/include/linux/device.h b/include/linux/device.h
index 7a968bdb02e2..cd7534cc42ab 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -129,6 +129,10 @@ struct device_driver {
129 129
130 bool suppress_bind_attrs; /* disables bind/unbind via sysfs */ 130 bool suppress_bind_attrs; /* disables bind/unbind via sysfs */
131 131
132#if defined(CONFIG_OF)
133 const struct of_device_id *of_match_table;
134#endif
135
132 int (*probe) (struct device *dev); 136 int (*probe) (struct device *dev);
133 int (*remove) (struct device *dev); 137 int (*remove) (struct device *dev);
134 void (*shutdown) (struct device *dev); 138 void (*shutdown) (struct device *dev);