Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0+
0002 /*
0003  * PM MFD driver for Broadcom BCM2835
0004  *
0005  * This driver binds to the PM block and creates the MFD device for
0006  * the WDT and power drivers.
0007  */
0008 
0009 #include <linux/delay.h>
0010 #include <linux/io.h>
0011 #include <linux/mfd/bcm2835-pm.h>
0012 #include <linux/mfd/core.h>
0013 #include <linux/module.h>
0014 #include <linux/of_address.h>
0015 #include <linux/of_platform.h>
0016 #include <linux/platform_device.h>
0017 #include <linux/types.h>
0018 #include <linux/watchdog.h>
0019 
0020 static const struct mfd_cell bcm2835_pm_devs[] = {
0021     { .name = "bcm2835-wdt" },
0022 };
0023 
0024 static const struct mfd_cell bcm2835_power_devs[] = {
0025     { .name = "bcm2835-power" },
0026 };
0027 
0028 static int bcm2835_pm_get_pdata(struct platform_device *pdev,
0029                 struct bcm2835_pm *pm)
0030 {
0031     if (of_find_property(pm->dev->of_node, "reg-names", NULL)) {
0032         struct resource *res;
0033 
0034         pm->base = devm_platform_ioremap_resource_byname(pdev, "pm");
0035         if (IS_ERR(pm->base))
0036             return PTR_ERR(pm->base);
0037 
0038         res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "asb");
0039         if (res) {
0040             pm->asb = devm_ioremap_resource(&pdev->dev, res);
0041             if (IS_ERR(pm->asb))
0042                 pm->asb = NULL;
0043         }
0044 
0045         res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
0046                             "rpivid_asb");
0047         if (res) {
0048             pm->rpivid_asb = devm_ioremap_resource(&pdev->dev, res);
0049             if (IS_ERR(pm->rpivid_asb))
0050                 pm->rpivid_asb = NULL;
0051         }
0052 
0053         return 0;
0054     }
0055 
0056     /* If no 'reg-names' property is found we can assume we're using old DTB. */
0057     pm->base = devm_platform_ioremap_resource(pdev, 0);
0058     if (IS_ERR(pm->base))
0059         return PTR_ERR(pm->base);
0060 
0061     pm->asb = devm_platform_ioremap_resource(pdev, 1);
0062     if (IS_ERR(pm->asb))
0063         pm->asb = NULL;
0064 
0065     pm->rpivid_asb = devm_platform_ioremap_resource(pdev, 2);
0066     if (IS_ERR(pm->rpivid_asb))
0067         pm->rpivid_asb = NULL;
0068 
0069     return 0;
0070 }
0071 
0072 static int bcm2835_pm_probe(struct platform_device *pdev)
0073 {
0074     struct device *dev = &pdev->dev;
0075     struct bcm2835_pm *pm;
0076     int ret;
0077 
0078     pm = devm_kzalloc(dev, sizeof(*pm), GFP_KERNEL);
0079     if (!pm)
0080         return -ENOMEM;
0081     platform_set_drvdata(pdev, pm);
0082 
0083     pm->dev = dev;
0084 
0085     ret = bcm2835_pm_get_pdata(pdev, pm);
0086     if (ret)
0087         return ret;
0088 
0089     ret = devm_mfd_add_devices(dev, -1,
0090                    bcm2835_pm_devs, ARRAY_SIZE(bcm2835_pm_devs),
0091                    NULL, 0, NULL);
0092     if (ret)
0093         return ret;
0094 
0095     /*
0096      * We'll use the presence of the AXI ASB regs in the
0097      * bcm2835-pm binding as the key for whether we can reference
0098      * the full PM register range and support power domains.
0099      */
0100     if (pm->asb)
0101         return devm_mfd_add_devices(dev, -1, bcm2835_power_devs,
0102                         ARRAY_SIZE(bcm2835_power_devs),
0103                         NULL, 0, NULL);
0104     return 0;
0105 }
0106 
0107 static const struct of_device_id bcm2835_pm_of_match[] = {
0108     { .compatible = "brcm,bcm2835-pm-wdt", },
0109     { .compatible = "brcm,bcm2835-pm", },
0110     { .compatible = "brcm,bcm2711-pm", },
0111     {},
0112 };
0113 MODULE_DEVICE_TABLE(of, bcm2835_pm_of_match);
0114 
0115 static struct platform_driver bcm2835_pm_driver = {
0116     .probe      = bcm2835_pm_probe,
0117     .driver = {
0118         .name = "bcm2835-pm",
0119         .of_match_table = bcm2835_pm_of_match,
0120     },
0121 };
0122 module_platform_driver(bcm2835_pm_driver);
0123 
0124 MODULE_AUTHOR("Eric Anholt <eric@anholt.net>");
0125 MODULE_DESCRIPTION("Driver for Broadcom BCM2835 PM MFD");
0126 MODULE_LICENSE("GPL");