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>
16 #include <linux/arm-smccc.h>
18 DECLARE_GLOBAL_DATA_PTR;
20 static int imx8m_power_domain_request(struct power_domain *power_domain)
25 static int imx8m_power_domain_free(struct power_domain *power_domain)
30 static int imx8m_power_domain_on(struct power_domain *power_domain)
32 struct udevice *dev = power_domain->dev;
33 struct imx8m_power_domain_platdata *pdata;
35 pdata = dev_get_plat(dev);
37 if (pdata->resource_id < 0)
41 power_domain_on(&pdata->pd);
43 arm_smccc_smc(IMX_SIP_GPC, IMX_SIP_GPC_PM_DOMAIN,
44 pdata->resource_id, 1, 0, 0, 0, 0, NULL);
49 static int imx8m_power_domain_off(struct power_domain *power_domain)
51 struct udevice *dev = power_domain->dev;
52 struct imx8m_power_domain_platdata *pdata;
53 pdata = dev_get_plat(dev);
55 if (pdata->resource_id < 0)
58 arm_smccc_smc(IMX_SIP_GPC, IMX_SIP_GPC_PM_DOMAIN,
59 pdata->resource_id, 0, 0, 0, 0, 0, NULL);
62 power_domain_off(&pdata->pd);
67 static int imx8m_power_domain_of_xlate(struct power_domain *power_domain,
68 struct ofnode_phandle_args *args)
73 static int imx8m_power_domain_bind(struct udevice *dev)
79 offset = dev_of_offset(dev);
80 for (offset = fdt_first_subnode(gd->fdt_blob, offset); offset > 0;
81 offset = fdt_next_subnode(gd->fdt_blob, offset)) {
82 /* Bind the subnode to this driver */
83 name = fdt_get_name(gd->fdt_blob, offset, NULL);
85 ret = device_bind_with_driver_data(dev, dev->driver, name,
87 offset_to_ofnode(offset),
91 printf("Driver '%s' refuses to bind\n",
95 printf("Error binding driver '%s': %d\n",
96 dev->driver->name, ret);
102 static int imx8m_power_domain_probe(struct udevice *dev)
107 static int imx8m_power_domain_ofdata_to_platdata(struct udevice *dev)
109 struct imx8m_power_domain_platdata *pdata = dev_get_plat(dev);
111 pdata->resource_id = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
114 if (!power_domain_get(dev, &pdata->pd))
120 static const struct udevice_id imx8m_power_domain_ids[] = {
121 { .compatible = "fsl,imx8mq-gpc" },
125 struct power_domain_ops imx8m_power_domain_ops = {
126 .request = imx8m_power_domain_request,
127 .rfree = imx8m_power_domain_free,
128 .on = imx8m_power_domain_on,
129 .off = imx8m_power_domain_off,
130 .of_xlate = imx8m_power_domain_of_xlate,
133 U_BOOT_DRIVER(imx8m_power_domain) = {
134 .name = "imx8m_power_domain",
135 .id = UCLASS_POWER_DOMAIN,
136 .of_match = imx8m_power_domain_ids,
137 .bind = imx8m_power_domain_bind,
138 .probe = imx8m_power_domain_probe,
139 .ofdata_to_platdata = imx8m_power_domain_ofdata_to_platdata,
140 .plat_auto = sizeof(struct imx8m_power_domain_platdata),
141 .ops = &imx8m_power_domain_ops,