blob: 341c83b1365bc0a585c0bb4ae2a4231632669ded [file] [log] [blame]
Patrick Wildtd08a1942019-10-03 15:51:50 +02001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright 2017 NXP
4 */
5
6#include <common.h>
7#include <dm.h>
Simon Glass336d4612020-02-03 07:36:16 -07008#include <malloc.h>
Patrick Wildtd08a1942019-10-03 15:51:50 +02009#include <power-domain-uclass.h>
10#include <asm/io.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>
15#include <imx_sip.h>
Peng Fan4b8f22d2020-05-11 15:16:37 +080016#include <linux/arm-smccc.h>
Patrick Wildtd08a1942019-10-03 15:51:50 +020017
18DECLARE_GLOBAL_DATA_PTR;
19
20static int imx8m_power_domain_request(struct power_domain *power_domain)
21{
22 return 0;
23}
24
25static int imx8m_power_domain_free(struct power_domain *power_domain)
26{
27 return 0;
28}
29
30static int imx8m_power_domain_on(struct power_domain *power_domain)
31{
32 struct udevice *dev = power_domain->dev;
Simon Glass8a8d24b2020-12-03 16:55:23 -070033 struct imx8m_power_domain_plat *pdata;
Peng Fan4b8f22d2020-05-11 15:16:37 +080034
Simon Glassc69cda22020-12-03 16:55:20 -070035 pdata = dev_get_plat(dev);
Patrick Wildtd08a1942019-10-03 15:51:50 +020036
37 if (pdata->resource_id < 0)
38 return -EINVAL;
39
40 if (pdata->has_pd)
41 power_domain_on(&pdata->pd);
42
Peng Fan4b8f22d2020-05-11 15:16:37 +080043 arm_smccc_smc(IMX_SIP_GPC, IMX_SIP_GPC_PM_DOMAIN,
44 pdata->resource_id, 1, 0, 0, 0, 0, NULL);
Patrick Wildtd08a1942019-10-03 15:51:50 +020045
46 return 0;
47}
48
49static int imx8m_power_domain_off(struct power_domain *power_domain)
50{
51 struct udevice *dev = power_domain->dev;
Simon Glass8a8d24b2020-12-03 16:55:23 -070052 struct imx8m_power_domain_plat *pdata;
Simon Glassc69cda22020-12-03 16:55:20 -070053 pdata = dev_get_plat(dev);
Patrick Wildtd08a1942019-10-03 15:51:50 +020054
55 if (pdata->resource_id < 0)
56 return -EINVAL;
57
Peng Fan4b8f22d2020-05-11 15:16:37 +080058 arm_smccc_smc(IMX_SIP_GPC, IMX_SIP_GPC_PM_DOMAIN,
59 pdata->resource_id, 0, 0, 0, 0, 0, NULL);
Patrick Wildtd08a1942019-10-03 15:51:50 +020060
61 if (pdata->has_pd)
62 power_domain_off(&pdata->pd);
63
64 return 0;
65}
66
67static int imx8m_power_domain_of_xlate(struct power_domain *power_domain,
68 struct ofnode_phandle_args *args)
69{
70 return 0;
71}
72
73static int imx8m_power_domain_bind(struct udevice *dev)
74{
75 int offset;
76 const char *name;
77 int ret = 0;
78
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);
84
85 ret = device_bind_with_driver_data(dev, dev->driver, name,
86 dev->driver_data,
87 offset_to_ofnode(offset),
88 NULL);
89
90 if (ret == -ENODEV)
91 printf("Driver '%s' refuses to bind\n",
92 dev->driver->name);
93
94 if (ret)
95 printf("Error binding driver '%s': %d\n",
96 dev->driver->name, ret);
97 }
98
99 return 0;
100}
101
102static int imx8m_power_domain_probe(struct udevice *dev)
103{
104 return 0;
105}
106
Simon Glassd1998a92020-12-03 16:55:21 -0700107static int imx8m_power_domain_of_to_plat(struct udevice *dev)
Patrick Wildtd08a1942019-10-03 15:51:50 +0200108{
Simon Glass8a8d24b2020-12-03 16:55:23 -0700109 struct imx8m_power_domain_plat *pdata = dev_get_plat(dev);
Patrick Wildtd08a1942019-10-03 15:51:50 +0200110
111 pdata->resource_id = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
112 "reg", -1);
113
114 if (!power_domain_get(dev, &pdata->pd))
115 pdata->has_pd = 1;
116
117 return 0;
118}
119
120static const struct udevice_id imx8m_power_domain_ids[] = {
121 { .compatible = "fsl,imx8mq-gpc" },
122 { }
123};
124
125struct power_domain_ops imx8m_power_domain_ops = {
126 .request = imx8m_power_domain_request,
Simon Glass4f511882020-02-03 07:35:51 -0700127 .rfree = imx8m_power_domain_free,
Patrick Wildtd08a1942019-10-03 15:51:50 +0200128 .on = imx8m_power_domain_on,
129 .off = imx8m_power_domain_off,
130 .of_xlate = imx8m_power_domain_of_xlate,
131};
132
133U_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,
Simon Glassd1998a92020-12-03 16:55:21 -0700139 .of_to_plat = imx8m_power_domain_of_to_plat,
Simon Glass8a8d24b2020-12-03 16:55:23 -0700140 .plat_auto = sizeof(struct imx8m_power_domain_plat),
Patrick Wildtd08a1942019-10-03 15:51:50 +0200141 .ops = &imx8m_power_domain_ops,
142};