0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <linux/module.h>
0012 #include <linux/of_platform.h>
0013 #include <linux/platform_device.h>
0014 #include <linux/pm_runtime.h>
0015
0016 static int simple_pm_bus_probe(struct platform_device *pdev)
0017 {
0018 const struct device *dev = &pdev->dev;
0019 const struct of_dev_auxdata *lookup = dev_get_platdata(dev);
0020 struct device_node *np = dev->of_node;
0021 const struct of_device_id *match;
0022
0023
0024
0025
0026
0027
0028
0029 if (pdev->driver_override)
0030 return 0;
0031
0032 match = of_match_device(dev->driver->of_match_table, dev);
0033
0034
0035
0036
0037
0038
0039
0040 if (match && match->data) {
0041 if (of_property_match_string(np, "compatible", match->compatible) == 0)
0042 return 0;
0043 else
0044 return -ENODEV;
0045 }
0046
0047 dev_dbg(&pdev->dev, "%s\n", __func__);
0048
0049 pm_runtime_enable(&pdev->dev);
0050
0051 if (np)
0052 of_platform_populate(np, NULL, lookup, &pdev->dev);
0053
0054 return 0;
0055 }
0056
0057 static int simple_pm_bus_remove(struct platform_device *pdev)
0058 {
0059 const void *data = of_device_get_match_data(&pdev->dev);
0060
0061 if (pdev->driver_override || data)
0062 return 0;
0063
0064 dev_dbg(&pdev->dev, "%s\n", __func__);
0065
0066 pm_runtime_disable(&pdev->dev);
0067 return 0;
0068 }
0069
0070 #define ONLY_BUS ((void *) 1)
0071
0072 static const struct of_device_id simple_pm_bus_of_match[] = {
0073 { .compatible = "simple-pm-bus", },
0074 { .compatible = "simple-bus", .data = ONLY_BUS },
0075 { .compatible = "simple-mfd", .data = ONLY_BUS },
0076 { .compatible = "isa", .data = ONLY_BUS },
0077 { .compatible = "arm,amba-bus", .data = ONLY_BUS },
0078 { }
0079 };
0080 MODULE_DEVICE_TABLE(of, simple_pm_bus_of_match);
0081
0082 static struct platform_driver simple_pm_bus_driver = {
0083 .probe = simple_pm_bus_probe,
0084 .remove = simple_pm_bus_remove,
0085 .driver = {
0086 .name = "simple-pm-bus",
0087 .of_match_table = simple_pm_bus_of_match,
0088 },
0089 };
0090
0091 module_platform_driver(simple_pm_bus_driver);
0092
0093 MODULE_DESCRIPTION("Simple Power-Managed Bus Driver");
0094 MODULE_AUTHOR("Geert Uytterhoeven <geert+renesas@glider.be>");
0095 MODULE_LICENSE("GPL v2");