2 * Simple Power-Managed Bus Driver
4 * Copyright (C) 2014-2015 Glider bvba
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
11 #include <linux/module.h>
12 #include <linux/of_platform.h>
13 #include <linux/platform_device.h>
14 #include <linux/pm_runtime.h>
16 static int simple_pm_bus_probe(struct platform_device *pdev)
18 const struct device *dev = &pdev->dev;
19 const struct of_dev_auxdata *lookup = dev_get_platdata(dev);
20 struct device_node *np = dev->of_node;
21 const struct of_device_id *match;
24 * Allow user to use driver_override to bind this driver to a
25 * transparent bus device which has a different compatible string
26 * that's not listed in simple_pm_bus_of_match. We don't want to do any
27 * of the simple-pm-bus tasks for these devices, so return early.
29 if (pdev->driver_override)
32 match = of_match_device(dev->driver->of_match_table, dev);
34 * These are transparent bus devices (not simple-pm-bus matches) that
35 * have their child nodes populated automatically. So, don't need to
36 * do anything more. We only match with the device if this driver is
37 * the most specific match because we don't want to incorrectly bind to
38 * a device that has a more specific driver.
40 if (match && match->data) {
41 if (of_property_match_string(np, "compatible", match->compatible) == 0)
47 dev_dbg(&pdev->dev, "%s\n", __func__);
49 pm_runtime_enable(&pdev->dev);
52 of_platform_populate(np, NULL, lookup, &pdev->dev);
57 static int simple_pm_bus_remove(struct platform_device *pdev)
59 const void *data = of_device_get_match_data(&pdev->dev);
61 if (pdev->driver_override || data)
64 dev_dbg(&pdev->dev, "%s\n", __func__);
66 pm_runtime_disable(&pdev->dev);
70 #define ONLY_BUS ((void *) 1) /* Match if the device is only a bus. */
72 static const struct of_device_id simple_pm_bus_of_match[] = {
73 { .compatible = "simple-pm-bus", },
74 { .compatible = "simple-bus", .data = ONLY_BUS },
75 { .compatible = "simple-mfd", .data = ONLY_BUS },
76 { .compatible = "isa", .data = ONLY_BUS },
77 { .compatible = "arm,amba-bus", .data = ONLY_BUS },
80 MODULE_DEVICE_TABLE(of, simple_pm_bus_of_match);
82 static struct platform_driver simple_pm_bus_driver = {
83 .probe = simple_pm_bus_probe,
84 .remove = simple_pm_bus_remove,
86 .name = "simple-pm-bus",
87 .of_match_table = simple_pm_bus_of_match,
91 module_platform_driver(simple_pm_bus_driver);
93 MODULE_DESCRIPTION("Simple Power-Managed Bus Driver");
94 MODULE_AUTHOR("Geert Uytterhoeven <geert+renesas@glider.be>");
95 MODULE_LICENSE("GPL v2");