Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Simple Power-Managed Bus Driver
0003  *
0004  * Copyright (C) 2014-2015 Glider bvba
0005  *
0006  * This file is subject to the terms and conditions of the GNU General Public
0007  * License.  See the file "COPYING" in the main directory of this archive
0008  * for more details.
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      * Allow user to use driver_override to bind this driver to a
0025      * transparent bus device which has a different compatible string
0026      * that's not listed in simple_pm_bus_of_match. We don't want to do any
0027      * of the simple-pm-bus tasks for these devices, so return early.
0028      */
0029     if (pdev->driver_override)
0030         return 0;
0031 
0032     match = of_match_device(dev->driver->of_match_table, dev);
0033     /*
0034      * These are transparent bus devices (not simple-pm-bus matches) that
0035      * have their child nodes populated automatically.  So, don't need to
0036      * do anything more. We only match with the device if this driver is
0037      * the most specific match because we don't want to incorrectly bind to
0038      * a device that has a more specific driver.
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) /* Match if the device is only a bus. */
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     { /* sentinel */ }
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");