Update OF platform & macio driver cores to adapt to device

model changes. Fix refcounting
parent 394edd85
...@@ -15,8 +15,8 @@ ...@@ -15,8 +15,8 @@
* Used by a driver to check whether an of_device present in the * Used by a driver to check whether an of_device present in the
* system is in its list of supported devices. * system is in its list of supported devices.
*/ */
const struct of_match * const struct of_match * of_match_device(const struct of_match *matches,
of_match_device(const struct of_match *matches, const struct of_device *dev) const struct of_device *dev)
{ {
if (!dev->node) if (!dev->node)
return NULL; return NULL;
...@@ -38,8 +38,7 @@ of_match_device(const struct of_match *matches, const struct of_device *dev) ...@@ -38,8 +38,7 @@ of_match_device(const struct of_match *matches, const struct of_device *dev)
return NULL; return NULL;
} }
static int static int of_platform_bus_match(struct device *dev, struct device_driver *drv)
of_platform_bus_match(struct device *dev, struct device_driver *drv)
{ {
struct of_device * of_dev = to_of_device(dev); struct of_device * of_dev = to_of_device(dev);
struct of_platform_driver * of_drv = to_of_platform_driver(drv); struct of_platform_driver * of_drv = to_of_platform_driver(drv);
...@@ -51,21 +50,27 @@ of_platform_bus_match(struct device *dev, struct device_driver *drv) ...@@ -51,21 +50,27 @@ of_platform_bus_match(struct device *dev, struct device_driver *drv)
return of_match_device(matches, of_dev) != NULL; return of_match_device(matches, of_dev) != NULL;
} }
struct bus_type of_platform_bus_type = { struct of_device *of_dev_get(struct of_device *dev)
name: "of_platform", {
match: of_platform_bus_match, struct device *tmp;
};
if (!dev)
return NULL;
tmp = get_device(&dev->dev);
if (tmp)
return to_of_device(tmp);
else
return NULL;
}
static int __init void of_dev_put(struct of_device *dev)
of_bus_driver_init(void)
{ {
return bus_register(&of_platform_bus_type); if (dev)
put_device(&dev->dev);
} }
postcore_initcall(of_bus_driver_init);
static int static int of_device_probe(struct device *dev)
of_device_probe(struct device *dev)
{ {
int error = -ENODEV; int error = -ENODEV;
struct of_platform_driver *drv; struct of_platform_driver *drv;
...@@ -78,22 +83,18 @@ of_device_probe(struct device *dev) ...@@ -78,22 +83,18 @@ of_device_probe(struct device *dev)
if (!drv->probe) if (!drv->probe)
return error; return error;
/* if (!try_module_get(driver->owner)) { of_dev_get(of_dev);
printk(KERN_ERR "Can't get a module reference for %s\n", driver->name);
return error;
}
*/
match = of_match_device(drv->match_table, of_dev); match = of_match_device(drv->match_table, of_dev);
if (match) if (match)
error = drv->probe(of_dev, match); error = drv->probe(of_dev, match);
/* if (error)
module_put(driver->owner); of_dev_put(of_dev);
*/
return error; return error;
} }
static int static int of_device_remove(struct device *dev)
of_device_remove(struct device *dev)
{ {
struct of_device * of_dev = to_of_device(dev); struct of_device * of_dev = to_of_device(dev);
struct of_platform_driver * drv = to_of_platform_driver(of_dev->dev.driver); struct of_platform_driver * drv = to_of_platform_driver(of_dev->dev.driver);
...@@ -103,32 +104,43 @@ of_device_remove(struct device *dev) ...@@ -103,32 +104,43 @@ of_device_remove(struct device *dev)
return 0; return 0;
} }
static int static int of_device_suspend(struct device *dev, u32 state)
of_device_suspend(struct device *dev, u32 state, u32 level)
{ {
struct of_device * of_dev = to_of_device(dev); struct of_device * of_dev = to_of_device(dev);
struct of_platform_driver * drv = to_of_platform_driver(of_dev->dev.driver); struct of_platform_driver * drv = to_of_platform_driver(of_dev->dev.driver);
int error = 0; int error = 0;
if (drv && drv->suspend) if (drv && drv->suspend)
error = drv->suspend(of_dev, state, level); error = drv->suspend(of_dev, state);
return error; return error;
} }
static int static int of_device_resume(struct device * dev)
of_device_resume(struct device * dev, u32 level)
{ {
struct of_device * of_dev = to_of_device(dev); struct of_device * of_dev = to_of_device(dev);
struct of_platform_driver * drv = to_of_platform_driver(of_dev->dev.driver); struct of_platform_driver * drv = to_of_platform_driver(of_dev->dev.driver);
int error = 0; int error = 0;
if (drv && drv->resume) if (drv && drv->resume)
error = drv->resume(of_dev, level); error = drv->resume(of_dev);
return error; return error;
} }
int struct bus_type of_platform_bus_type = {
of_register_driver(struct of_platform_driver *drv) name: "of_platform",
match: of_platform_bus_match,
suspend: of_device_suspend,
resume: of_device_resume,
};
static int __init of_bus_driver_init(void)
{
return bus_register(&of_platform_bus_type);
}
postcore_initcall(of_bus_driver_init);
int of_register_driver(struct of_platform_driver *drv)
{ {
int count = 0; int count = 0;
...@@ -136,8 +148,6 @@ of_register_driver(struct of_platform_driver *drv) ...@@ -136,8 +148,6 @@ of_register_driver(struct of_platform_driver *drv)
drv->driver.name = drv->name; drv->driver.name = drv->name;
drv->driver.bus = &of_platform_bus_type; drv->driver.bus = &of_platform_bus_type;
drv->driver.probe = of_device_probe; drv->driver.probe = of_device_probe;
drv->driver.resume = of_device_resume;
drv->driver.suspend = of_device_suspend;
drv->driver.remove = of_device_remove; drv->driver.remove = of_device_remove;
/* register with core */ /* register with core */
...@@ -145,15 +155,13 @@ of_register_driver(struct of_platform_driver *drv) ...@@ -145,15 +155,13 @@ of_register_driver(struct of_platform_driver *drv)
return count ? count : 1; return count ? count : 1;
} }
void void of_unregister_driver(struct of_platform_driver *drv)
of_unregister_driver(struct of_platform_driver *drv)
{ {
driver_unregister(&drv->driver); driver_unregister(&drv->driver);
} }
static ssize_t static ssize_t dev_show_devspec(struct device *dev, char *buf)
dev_show_devspec(struct device *dev, char *buf)
{ {
struct of_device *ofdev; struct of_device *ofdev;
...@@ -163,8 +171,22 @@ dev_show_devspec(struct device *dev, char *buf) ...@@ -163,8 +171,22 @@ dev_show_devspec(struct device *dev, char *buf)
static DEVICE_ATTR(devspec, S_IRUGO, dev_show_devspec, NULL); static DEVICE_ATTR(devspec, S_IRUGO, dev_show_devspec, NULL);
int /**
of_device_register(struct of_device *ofdev) * of_release_dev - free an of device structure when all users of it are finished.
* @dev: device that's been disconnected
*
* Will be called only by the device core when all users of this of device are
* done.
*/
void of_release_dev(struct device *dev)
{
struct of_device *ofdev;
ofdev = to_of_device(dev);
kfree(ofdev);
}
int of_device_register(struct of_device *ofdev)
{ {
int rc; int rc;
struct of_device **odprop; struct of_device **odprop;
...@@ -197,21 +219,20 @@ of_device_register(struct of_device *ofdev) ...@@ -197,21 +219,20 @@ of_device_register(struct of_device *ofdev)
return 0; return 0;
} }
void void of_device_unregister(struct of_device *ofdev)
of_device_unregister(struct of_device *ofdev)
{ {
struct of_device **odprop; struct of_device **odprop;
device_remove_file(&ofdev->dev, &dev_attr_devspec); device_remove_file(&ofdev->dev, &dev_attr_devspec);
device_unregister(&ofdev->dev);
odprop = (struct of_device **)get_property(ofdev->node, "linux,device", NULL); odprop = (struct of_device **)get_property(ofdev->node, "linux,device", NULL);
if (odprop) if (odprop)
*odprop = NULL; *odprop = NULL;
device_unregister(&ofdev->dev);
} }
struct of_device* struct of_device* of_platform_device_create(struct device_node *np, const char *bus_id)
of_platform_device_create(struct device_node *np, const char *bus_id)
{ {
struct of_device *dev; struct of_device *dev;
u32 *reg; u32 *reg;
...@@ -226,6 +247,7 @@ of_platform_device_create(struct device_node *np, const char *bus_id) ...@@ -226,6 +247,7 @@ of_platform_device_create(struct device_node *np, const char *bus_id)
dev->dev.dma_mask = &dev->dma_mask; dev->dev.dma_mask = &dev->dma_mask;
dev->dev.parent = NULL; dev->dev.parent = NULL;
dev->dev.bus = &of_platform_bus_type; dev->dev.bus = &of_platform_bus_type;
dev->dev.release = of_release_dev;
reg = (u32 *)get_property(np, "reg", NULL); reg = (u32 *)get_property(np, "reg", NULL);
strlcpy(dev->dev.bus_id, bus_id, BUS_ID_SIZE); strlcpy(dev->dev.bus_id, bus_id, BUS_ID_SIZE);
...@@ -244,4 +266,7 @@ EXPORT_SYMBOL(of_register_driver); ...@@ -244,4 +266,7 @@ EXPORT_SYMBOL(of_register_driver);
EXPORT_SYMBOL(of_unregister_driver); EXPORT_SYMBOL(of_unregister_driver);
EXPORT_SYMBOL(of_device_register); EXPORT_SYMBOL(of_device_register);
EXPORT_SYMBOL(of_device_unregister); EXPORT_SYMBOL(of_device_unregister);
EXPORT_SYMBOL(of_dev_get);
EXPORT_SYMBOL(of_dev_put);
EXPORT_SYMBOL(of_platform_device_create); EXPORT_SYMBOL(of_platform_device_create);
EXPORT_SYMBOL(of_release_dev);
This diff is collapsed.
...@@ -42,6 +42,9 @@ struct macio_dev ...@@ -42,6 +42,9 @@ struct macio_dev
#define to_macio_device(d) container_of(d, struct macio_dev, ofdev.dev) #define to_macio_device(d) container_of(d, struct macio_dev, ofdev.dev)
#define of_to_macio_device(d) container_of(d, struct macio_dev, ofdev) #define of_to_macio_device(d) container_of(d, struct macio_dev, ofdev)
extern struct macio_dev *macio_dev_get(struct macio_dev *dev);
extern void macio_dev_put(struct macio_dev *dev);
/* /*
* A driver for a mac-io chip based device * A driver for a mac-io chip based device
*/ */
...@@ -54,8 +57,8 @@ struct macio_driver ...@@ -54,8 +57,8 @@ struct macio_driver
int (*probe)(struct macio_dev* dev, const struct of_match *match); int (*probe)(struct macio_dev* dev, const struct of_match *match);
int (*remove)(struct macio_dev* dev); int (*remove)(struct macio_dev* dev);
int (*suspend)(struct macio_dev* dev, u32 state, u32 level); int (*suspend)(struct macio_dev* dev, u32 state);
int (*resume)(struct macio_dev* dev, u32 level); int (*resume)(struct macio_dev* dev);
int (*shutdown)(struct macio_dev* dev); int (*shutdown)(struct macio_dev* dev);
struct device_driver driver; struct device_driver driver;
......
...@@ -39,6 +39,9 @@ struct of_match ...@@ -39,6 +39,9 @@ struct of_match
extern const struct of_match *of_match_device( extern const struct of_match *of_match_device(
const struct of_match *matches, const struct of_device *dev); const struct of_match *matches, const struct of_device *dev);
extern struct of_device *of_dev_get(struct of_device *dev);
extern void of_dev_put(struct of_device *dev);
/* /*
* An of_platform_driver driver is attached to a basic of_device on * An of_platform_driver driver is attached to a basic of_device on
* the "platform bus" (of_platform_bus_type) * the "platform bus" (of_platform_bus_type)
...@@ -52,8 +55,8 @@ struct of_platform_driver ...@@ -52,8 +55,8 @@ struct of_platform_driver
int (*probe)(struct of_device* dev, const struct of_match *match); int (*probe)(struct of_device* dev, const struct of_match *match);
int (*remove)(struct of_device* dev); int (*remove)(struct of_device* dev);
int (*suspend)(struct of_device* dev, u32 state, u32 level); int (*suspend)(struct of_device* dev, u32 state);
int (*resume)(struct of_device* dev, u32 level); int (*resume)(struct of_device* dev);
int (*shutdown)(struct of_device* dev); int (*shutdown)(struct of_device* dev);
struct device_driver driver; struct device_driver driver;
...@@ -65,6 +68,7 @@ extern void of_unregister_driver(struct of_platform_driver *drv); ...@@ -65,6 +68,7 @@ extern void of_unregister_driver(struct of_platform_driver *drv);
extern int of_device_register(struct of_device *ofdev); extern int of_device_register(struct of_device *ofdev);
extern void of_device_unregister(struct of_device *ofdev); extern void of_device_unregister(struct of_device *ofdev);
extern struct of_device *of_platform_device_create(struct device_node *np, const char *bus_id); extern struct of_device *of_platform_device_create(struct device_node *np, const char *bus_id);
extern void of_release_dev(struct device *dev);
#endif /* __OF_DEVICE_H__ */ #endif /* __OF_DEVICE_H__ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment