firmware/psci: Pass given partition number through
[platform/kernel/linux-rpi.git] / drivers / mfd / bcm2835-pm.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * PM MFD driver for Broadcom BCM2835
4  *
5  * This driver binds to the PM block and creates the MFD device for
6  * the WDT and power drivers.
7  */
8
9 #include <linux/delay.h>
10 #include <linux/io.h>
11 #include <linux/mfd/bcm2835-pm.h>
12 #include <linux/mfd/core.h>
13 #include <linux/module.h>
14 #include <linux/of_address.h>
15 #include <linux/of_platform.h>
16 #include <linux/platform_device.h>
17 #include <linux/types.h>
18 #include <linux/watchdog.h>
19
20 static const struct mfd_cell bcm2835_pm_devs[] = {
21         { .name = "bcm2835-wdt" },
22 };
23
24 static const struct mfd_cell bcm2835_power_devs[] = {
25         { .name = "bcm2835-power" },
26 };
27
28 static int bcm2835_pm_get_pdata(struct platform_device *pdev,
29                                 struct bcm2835_pm *pm)
30 {
31         if (of_property_present(pm->dev->of_node, "reg-names")) {
32                 struct resource *res;
33
34                 pm->base = devm_platform_ioremap_resource_byname(pdev, "pm");
35                 if (IS_ERR(pm->base))
36                         return PTR_ERR(pm->base);
37
38                 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "asb");
39                 if (res) {
40                         pm->asb = devm_ioremap_resource(&pdev->dev, res);
41                         if (IS_ERR(pm->asb))
42                                 pm->asb = NULL;
43                 }
44
45                 res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
46                                                     "rpivid_asb");
47                 if (res) {
48                         pm->rpivid_asb = devm_ioremap_resource(&pdev->dev, res);
49                         if (IS_ERR(pm->rpivid_asb))
50                                 pm->rpivid_asb = NULL;
51                 }
52
53                 return 0;
54         }
55
56         /* If no 'reg-names' property is found we can assume we're using old DTB. */
57         pm->base = devm_platform_ioremap_resource(pdev, 0);
58         if (IS_ERR(pm->base))
59                 return PTR_ERR(pm->base);
60
61         pm->asb = devm_platform_ioremap_resource(pdev, 1);
62         if (IS_ERR(pm->asb))
63                 pm->asb = NULL;
64
65         pm->rpivid_asb = devm_platform_ioremap_resource(pdev, 2);
66         if (IS_ERR(pm->rpivid_asb))
67                 pm->rpivid_asb = NULL;
68
69         return 0;
70 }
71
72 static const struct of_device_id bcm2835_pm_of_match[] = {
73         { .compatible = "brcm,bcm2835-pm-wdt", },
74         { .compatible = "brcm,bcm2835-pm", },
75         { .compatible = "brcm,bcm2711-pm", },
76         { .compatible = "brcm,bcm2712-pm", .data = (const void *)1},
77         {},
78 };
79 MODULE_DEVICE_TABLE(of, bcm2835_pm_of_match);
80
81 static int bcm2835_pm_probe(struct platform_device *pdev)
82 {
83         const struct of_device_id *of_id;
84         struct device *dev = &pdev->dev;
85         struct bcm2835_pm *pm;
86         bool is_2712;
87         int ret;
88
89         of_id = of_match_node(bcm2835_pm_of_match, pdev->dev.of_node);
90         if (!of_id) {
91                 dev_err(&pdev->dev, "Failed to match compatible string\n");
92                 return -EINVAL;
93         }
94         is_2712 = !!of_id->data;
95
96         pm = devm_kzalloc(dev, sizeof(*pm), GFP_KERNEL);
97         if (!pm)
98                 return -ENOMEM;
99         platform_set_drvdata(pdev, pm);
100
101         pm->dev = dev;
102
103         ret = bcm2835_pm_get_pdata(pdev, pm);
104         if (ret)
105                 return ret;
106
107         ret = devm_mfd_add_devices(dev, -1,
108                                    bcm2835_pm_devs, ARRAY_SIZE(bcm2835_pm_devs),
109                                    NULL, 0, NULL);
110         if (ret)
111                 return ret;
112
113         /*
114          * We'll use the presence of the AXI ASB regs in the
115          * bcm2835-pm binding as the key for whether we can reference
116          * the full PM register range and support power domains.
117          */
118         if (pm->asb || is_2712)
119                 return devm_mfd_add_devices(dev, -1, bcm2835_power_devs,
120                                             ARRAY_SIZE(bcm2835_power_devs),
121                                             NULL, 0, NULL);
122         return 0;
123 }
124
125 static struct platform_driver bcm2835_pm_driver = {
126         .probe          = bcm2835_pm_probe,
127         .driver = {
128                 .name = "bcm2835-pm",
129                 .of_match_table = bcm2835_pm_of_match,
130         },
131 };
132 module_platform_driver(bcm2835_pm_driver);
133
134 MODULE_AUTHOR("Eric Anholt <eric@anholt.net>");
135 MODULE_DESCRIPTION("Driver for Broadcom BCM2835 PM MFD");