diff options
author | Stephen Rothwell <sfr@canb.auug.org.au> | 2007-05-02 12:38:57 -0400 |
---|---|---|
committer | Stephen Rothwell <sfr@canb.auug.org.au> | 2007-07-20 00:25:51 -0400 |
commit | 3f23de10f283819bcdc0d2282e8b5b14c2e96d3b (patch) | |
tree | 49c64fc622953e4ffc3af665bdc380fd37079e14 /drivers | |
parent | b41912ca345e6de8ec8469d57cd585881271e2b9 (diff) |
Create drivers/of/platform.c
and populate it with the common parts from PowerPC and Sparc[64].
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
Acked-by: Paul Mackerras <paulus@samba.org>
Acked-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/of/Makefile | 2 | ||||
-rw-r--r-- | drivers/of/platform.c | 96 |
2 files changed, 97 insertions, 1 deletions
diff --git a/drivers/of/Makefile b/drivers/of/Makefile index c46d998e367b..ab9be5d5255b 100644 --- a/drivers/of/Makefile +++ b/drivers/of/Makefile | |||
@@ -1,2 +1,2 @@ | |||
1 | obj-y = base.o | 1 | obj-y = base.o |
2 | obj-$(CONFIG_OF_DEVICE) += device.o | 2 | obj-$(CONFIG_OF_DEVICE) += device.o platform.o |
diff --git a/drivers/of/platform.c b/drivers/of/platform.c new file mode 100644 index 000000000000..864f09fd9f86 --- /dev/null +++ b/drivers/of/platform.c | |||
@@ -0,0 +1,96 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2006 Benjamin Herrenschmidt, IBM Corp. | ||
3 | * <benh@kernel.crashing.org> | ||
4 | * and Arnd Bergmann, IBM Corp. | ||
5 | * Merged from powerpc/kernel/of_platform.c and | ||
6 | * sparc{,64}/kernel/of_device.c by Stephen Rothwell | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU General Public License | ||
10 | * as published by the Free Software Foundation; either version | ||
11 | * 2 of the License, or (at your option) any later version. | ||
12 | * | ||
13 | */ | ||
14 | #include <linux/errno.h> | ||
15 | #include <linux/device.h> | ||
16 | #include <linux/of_device.h> | ||
17 | #include <linux/of_platform.h> | ||
18 | |||
19 | static int of_platform_bus_match(struct device *dev, struct device_driver *drv) | ||
20 | { | ||
21 | struct of_device *of_dev = to_of_device(dev); | ||
22 | struct of_platform_driver *of_drv = to_of_platform_driver(drv); | ||
23 | const struct of_device_id *matches = of_drv->match_table; | ||
24 | |||
25 | if (!matches) | ||
26 | return 0; | ||
27 | |||
28 | return of_match_device(matches, of_dev) != NULL; | ||
29 | } | ||
30 | |||
31 | static int of_platform_device_probe(struct device *dev) | ||
32 | { | ||
33 | int error = -ENODEV; | ||
34 | struct of_platform_driver *drv; | ||
35 | struct of_device *of_dev; | ||
36 | const struct of_device_id *match; | ||
37 | |||
38 | drv = to_of_platform_driver(dev->driver); | ||
39 | of_dev = to_of_device(dev); | ||
40 | |||
41 | if (!drv->probe) | ||
42 | return error; | ||
43 | |||
44 | of_dev_get(of_dev); | ||
45 | |||
46 | match = of_match_device(drv->match_table, of_dev); | ||
47 | if (match) | ||
48 | error = drv->probe(of_dev, match); | ||
49 | if (error) | ||
50 | of_dev_put(of_dev); | ||
51 | |||
52 | return error; | ||
53 | } | ||
54 | |||
55 | static int of_platform_device_remove(struct device *dev) | ||
56 | { | ||
57 | struct of_device *of_dev = to_of_device(dev); | ||
58 | struct of_platform_driver *drv = to_of_platform_driver(dev->driver); | ||
59 | |||
60 | if (dev->driver && drv->remove) | ||
61 | drv->remove(of_dev); | ||
62 | return 0; | ||
63 | } | ||
64 | |||
65 | static int of_platform_device_suspend(struct device *dev, pm_message_t state) | ||
66 | { | ||
67 | struct of_device *of_dev = to_of_device(dev); | ||
68 | struct of_platform_driver *drv = to_of_platform_driver(dev->driver); | ||
69 | int error = 0; | ||
70 | |||
71 | if (dev->driver && drv->suspend) | ||
72 | error = drv->suspend(of_dev, state); | ||
73 | return error; | ||
74 | } | ||
75 | |||
76 | static int of_platform_device_resume(struct device * dev) | ||
77 | { | ||
78 | struct of_device *of_dev = to_of_device(dev); | ||
79 | struct of_platform_driver *drv = to_of_platform_driver(dev->driver); | ||
80 | int error = 0; | ||
81 | |||
82 | if (dev->driver && drv->resume) | ||
83 | error = drv->resume(of_dev); | ||
84 | return error; | ||
85 | } | ||
86 | |||
87 | int of_bus_type_init(struct bus_type *bus, const char *name) | ||
88 | { | ||
89 | bus->name = name; | ||
90 | bus->match = of_platform_bus_match; | ||
91 | bus->probe = of_platform_device_probe; | ||
92 | bus->remove = of_platform_device_remove; | ||
93 | bus->suspend = of_platform_device_suspend; | ||
94 | bus->resume = of_platform_device_resume; | ||
95 | return bus_register(bus); | ||
96 | } | ||