1 // SPDX-License-Identifier: GPL-2.0
9 #include <power-domain-uclass.h>
11 #include <asm/arch/power-domain.h>
12 #include <asm/mach-imx/sys_proto.h>
13 #include <dm/device-internal.h>
14 #include <dm/device.h>
17 DECLARE_GLOBAL_DATA_PTR;
19 static int imx8m_power_domain_request(struct power_domain *power_domain)
24 static int imx8m_power_domain_free(struct power_domain *power_domain)
29 static int imx8m_power_domain_on(struct power_domain *power_domain)
31 struct udevice *dev = power_domain->dev;
32 struct imx8m_power_domain_platdata *pdata;
33 pdata = dev_get_platdata(dev);
35 if (pdata->resource_id < 0)
39 power_domain_on(&pdata->pd);
41 call_imx_sip(IMX_SIP_GPC, IMX_SIP_GPC_PM_DOMAIN,
42 pdata->resource_id, 1, 0);
47 static int imx8m_power_domain_off(struct power_domain *power_domain)
49 struct udevice *dev = power_domain->dev;
50 struct imx8m_power_domain_platdata *pdata;
51 pdata = dev_get_platdata(dev);
53 if (pdata->resource_id < 0)
56 call_imx_sip(IMX_SIP_GPC, IMX_SIP_GPC_PM_DOMAIN,
57 pdata->resource_id, 0, 0);
60 power_domain_off(&pdata->pd);
65 static int imx8m_power_domain_of_xlate(struct power_domain *power_domain,
66 struct ofnode_phandle_args *args)
71 static int imx8m_power_domain_bind(struct udevice *dev)
77 offset = dev_of_offset(dev);
78 for (offset = fdt_first_subnode(gd->fdt_blob, offset); offset > 0;
79 offset = fdt_next_subnode(gd->fdt_blob, offset)) {
80 /* Bind the subnode to this driver */
81 name = fdt_get_name(gd->fdt_blob, offset, NULL);
83 ret = device_bind_with_driver_data(dev, dev->driver, name,
85 offset_to_ofnode(offset),
89 printf("Driver '%s' refuses to bind\n",
93 printf("Error binding driver '%s': %d\n",
94 dev->driver->name, ret);
100 static int imx8m_power_domain_probe(struct udevice *dev)
105 static int imx8m_power_domain_ofdata_to_platdata(struct udevice *dev)
107 struct imx8m_power_domain_platdata *pdata = dev_get_platdata(dev);
109 pdata->resource_id = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
112 if (!power_domain_get(dev, &pdata->pd))
118 static const struct udevice_id imx8m_power_domain_ids[] = {
119 { .compatible = "fsl,imx8mq-gpc" },
123 struct power_domain_ops imx8m_power_domain_ops = {
124 .request = imx8m_power_domain_request,
125 .rfree = imx8m_power_domain_free,
126 .on = imx8m_power_domain_on,
127 .off = imx8m_power_domain_off,
128 .of_xlate = imx8m_power_domain_of_xlate,
131 U_BOOT_DRIVER(imx8m_power_domain) = {
132 .name = "imx8m_power_domain",
133 .id = UCLASS_POWER_DOMAIN,
134 .of_match = imx8m_power_domain_ids,
135 .bind = imx8m_power_domain_bind,
136 .probe = imx8m_power_domain_probe,
137 .ofdata_to_platdata = imx8m_power_domain_ofdata_to_platdata,
138 .platdata_auto_alloc_size = sizeof(struct imx8m_power_domain_platdata),
139 .ops = &imx8m_power_domain_ops,