diff options
author | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-07-20 09:18:08 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-07-20 09:18:08 -0700 |
commit | 2cb7e714229681408e323852bed939989faf6991 (patch) | |
tree | 552b78fa5830a0337594f9fbab5f1dc0306e93cd /drivers/of/platform.c | |
parent | d638d4990bfb99998420e78e8fd4607bca5cf8d0 (diff) | |
parent | 3f23de10f283819bcdc0d2282e8b5b14c2e96d3b (diff) |
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/sfr/ofcons
* 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/sfr/ofcons:
Create drivers/of/platform.c
Create linux/of_platorm.h
[SPARC/64] Rename some functions like PowerPC
Begin consolidation of of_device.h
Begin to consolidate of_device.c
Consolidate of_find_node_by routines
Consolidate of_get_next_child
Consolidate of_get_parent
Consolidate of_find_property
Consolidate of_device_is_compatible
Start split out of common open firmware code
Split out common parts of prom.h
Diffstat (limited to 'drivers/of/platform.c')
-rw-r--r-- | drivers/of/platform.c | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/drivers/of/platform.c b/drivers/of/platform.c new file mode 100644 index 00000000000..864f09fd9f8 --- /dev/null +++ b/drivers/of/platform.c @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2006 Benjamin Herrenschmidt, IBM Corp. + * <benh@kernel.crashing.org> + * and Arnd Bergmann, IBM Corp. + * Merged from powerpc/kernel/of_platform.c and + * sparc{,64}/kernel/of_device.c by Stephen Rothwell + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + * + */ +#include <linux/errno.h> +#include <linux/device.h> +#include <linux/of_device.h> +#include <linux/of_platform.h> + +static int of_platform_bus_match(struct device *dev, struct device_driver *drv) +{ + struct of_device *of_dev = to_of_device(dev); + struct of_platform_driver *of_drv = to_of_platform_driver(drv); + const struct of_device_id *matches = of_drv->match_table; + + if (!matches) + return 0; + + return of_match_device(matches, of_dev) != NULL; +} + +static int of_platform_device_probe(struct device *dev) +{ + int error = -ENODEV; + struct of_platform_driver *drv; + struct of_device *of_dev; + const struct of_device_id *match; + + drv = to_of_platform_driver(dev->driver); + of_dev = to_of_device(dev); + + if (!drv->probe) + return error; + + of_dev_get(of_dev); + + match = of_match_device(drv->match_table, of_dev); + if (match) + error = drv->probe(of_dev, match); + if (error) + of_dev_put(of_dev); + + return error; +} + +static int of_platform_device_remove(struct device *dev) +{ + struct of_device *of_dev = to_of_device(dev); + struct of_platform_driver *drv = to_of_platform_driver(dev->driver); + + if (dev->driver && drv->remove) + drv->remove(of_dev); + return 0; +} + +static int of_platform_device_suspend(struct device *dev, pm_message_t state) +{ + struct of_device *of_dev = to_of_device(dev); + struct of_platform_driver *drv = to_of_platform_driver(dev->driver); + int error = 0; + + if (dev->driver && drv->suspend) + error = drv->suspend(of_dev, state); + return error; +} + +static int of_platform_device_resume(struct device * dev) +{ + struct of_device *of_dev = to_of_device(dev); + struct of_platform_driver *drv = to_of_platform_driver(dev->driver); + int error = 0; + + if (dev->driver && drv->resume) + error = drv->resume(of_dev); + return error; +} + +int of_bus_type_init(struct bus_type *bus, const char *name) +{ + bus->name = name; + bus->match = of_platform_bus_match; + bus->probe = of_platform_device_probe; + bus->remove = of_platform_device_remove; + bus->suspend = of_platform_device_suspend; + bus->resume = of_platform_device_resume; + return bus_register(bus); +} |