imx: power-domain: Add fsl,imx8mn-gpc compatible string
[platform/kernel/u-boot.git] / drivers / power / domain / imx8m-power-domain.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright 2017 NXP
4  */
5
6 #include <common.h>
7 #include <dm.h>
8 #include <malloc.h>
9 #include <power-domain-uclass.h>
10 #include <asm/global_data.h>
11 #include <asm/io.h>
12 #include <asm/arch/power-domain.h>
13 #include <asm/mach-imx/sys_proto.h>
14 #include <dm/device-internal.h>
15 #include <dm/device.h>
16 #include <imx_sip.h>
17 #include <linux/arm-smccc.h>
18
19 DECLARE_GLOBAL_DATA_PTR;
20
21 static int imx8m_power_domain_request(struct power_domain *power_domain)
22 {
23         return 0;
24 }
25
26 static int imx8m_power_domain_free(struct power_domain *power_domain)
27 {
28         return 0;
29 }
30
31 static int imx8m_power_domain_on(struct power_domain *power_domain)
32 {
33         struct udevice *dev = power_domain->dev;
34         struct imx8m_power_domain_plat *pdata;
35
36         pdata = dev_get_plat(dev);
37
38         if (pdata->resource_id < 0)
39                 return -EINVAL;
40
41         if (pdata->has_pd)
42                 power_domain_on(&pdata->pd);
43
44         arm_smccc_smc(IMX_SIP_GPC, IMX_SIP_GPC_PM_DOMAIN,
45                       pdata->resource_id, 1, 0, 0, 0, 0, NULL);
46
47         return 0;
48 }
49
50 static int imx8m_power_domain_off(struct power_domain *power_domain)
51 {
52         struct udevice *dev = power_domain->dev;
53         struct imx8m_power_domain_plat *pdata;
54         pdata = dev_get_plat(dev);
55
56         if (pdata->resource_id < 0)
57                 return -EINVAL;
58
59         arm_smccc_smc(IMX_SIP_GPC, IMX_SIP_GPC_PM_DOMAIN,
60                       pdata->resource_id, 0, 0, 0, 0, 0, NULL);
61
62         if (pdata->has_pd)
63                 power_domain_off(&pdata->pd);
64
65         return 0;
66 }
67
68 static int imx8m_power_domain_of_xlate(struct power_domain *power_domain,
69                                       struct ofnode_phandle_args *args)
70 {
71         return 0;
72 }
73
74 static int imx8m_power_domain_bind(struct udevice *dev)
75 {
76         int offset;
77         const char *name;
78         int ret = 0;
79
80         offset = dev_of_offset(dev);
81         for (offset = fdt_first_subnode(gd->fdt_blob, offset); offset > 0;
82              offset = fdt_next_subnode(gd->fdt_blob, offset)) {
83                 /* Bind the subnode to this driver */
84                 name = fdt_get_name(gd->fdt_blob, offset, NULL);
85
86                 ret = device_bind_with_driver_data(dev, dev->driver, name,
87                                                    dev->driver_data,
88                                                    offset_to_ofnode(offset),
89                                                    NULL);
90
91                 if (ret == -ENODEV)
92                         printf("Driver '%s' refuses to bind\n",
93                                dev->driver->name);
94
95                 if (ret)
96                         printf("Error binding driver '%s': %d\n",
97                                dev->driver->name, ret);
98         }
99
100         return 0;
101 }
102
103 static int imx8m_power_domain_probe(struct udevice *dev)
104 {
105         return 0;
106 }
107
108 static int imx8m_power_domain_of_to_plat(struct udevice *dev)
109 {
110         struct imx8m_power_domain_plat *pdata = dev_get_plat(dev);
111
112         pdata->resource_id = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
113                                             "reg", -1);
114
115         if (!power_domain_get(dev, &pdata->pd))
116                 pdata->has_pd = 1;
117
118         return 0;
119 }
120
121 static const struct udevice_id imx8m_power_domain_ids[] = {
122         { .compatible = "fsl,imx8mq-gpc" },
123         { .compatible = "fsl,imx8mm-gpc" },
124         { .compatible = "fsl,imx8mn-gpc" },
125         { }
126 };
127
128 struct power_domain_ops imx8m_power_domain_ops = {
129         .request = imx8m_power_domain_request,
130         .rfree = imx8m_power_domain_free,
131         .on = imx8m_power_domain_on,
132         .off = imx8m_power_domain_off,
133         .of_xlate = imx8m_power_domain_of_xlate,
134 };
135
136 U_BOOT_DRIVER(imx8m_power_domain) = {
137         .name = "imx8m_power_domain",
138         .id = UCLASS_POWER_DOMAIN,
139         .of_match = imx8m_power_domain_ids,
140         .bind = imx8m_power_domain_bind,
141         .probe = imx8m_power_domain_probe,
142         .of_to_plat = imx8m_power_domain_of_to_plat,
143         .plat_auto      = sizeof(struct imx8m_power_domain_plat),
144         .ops = &imx8m_power_domain_ops,
145 };