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
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.
14 #include <linux/errno.h>
15 #include <linux/device.h>
16 #include <linux/of_device.h>
17 #include <linux/of_platform.h>
19 static int of_platform_bus_match(struct device
*dev
, struct device_driver
*drv
)
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
;
28 return of_match_device(matches
, of_dev
) != NULL
;
31 static int of_platform_device_probe(struct device
*dev
)
34 struct of_platform_driver
*drv
;
35 struct of_device
*of_dev
;
36 const struct of_device_id
*match
;
38 drv
= to_of_platform_driver(dev
->driver
);
39 of_dev
= to_of_device(dev
);
46 match
= of_match_device(drv
->match_table
, of_dev
);
48 error
= drv
->probe(of_dev
, match
);
55 static int of_platform_device_remove(struct device
*dev
)
57 struct of_device
*of_dev
= to_of_device(dev
);
58 struct of_platform_driver
*drv
= to_of_platform_driver(dev
->driver
);
60 if (dev
->driver
&& drv
->remove
)
65 static int of_platform_device_suspend(struct device
*dev
, pm_message_t state
)
67 struct of_device
*of_dev
= to_of_device(dev
);
68 struct of_platform_driver
*drv
= to_of_platform_driver(dev
->driver
);
71 if (dev
->driver
&& drv
->suspend
)
72 error
= drv
->suspend(of_dev
, state
);
76 static int of_platform_device_resume(struct device
* dev
)
78 struct of_device
*of_dev
= to_of_device(dev
);
79 struct of_platform_driver
*drv
= to_of_platform_driver(dev
->driver
);
82 if (dev
->driver
&& drv
->resume
)
83 error
= drv
->resume(of_dev
);
87 int of_bus_type_init(struct bus_type
*bus
, const char *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
);