blob: 0ef460df8c2d97911aacd7b184ee3b991f95cffc [file] [log] [blame]
Patrick Wildt8bd56562019-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 Glass9bc15642020-02-03 07:36:16 -07008#include <malloc.h>
Patrick Wildt8bd56562019-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 Fanaae33562020-05-11 15:16:37 +080016#include <linux/arm-smccc.h>
Patrick Wildt8bd56562019-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;
33 struct imx8m_power_domain_platdata *pdata;
Peng Fanaae33562020-05-11 15:16:37 +080034
Patrick Wildt8bd56562019-10-03 15:51:50 +020035 pdata = dev_get_platdata(dev);
36
37 if (pdata->resource_id < 0)
38 return -EINVAL;
39
40 if (pdata->has_pd)
41 power_domain_on(&pdata->pd);
42
Peng Fanaae33562020-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 Wildt8bd56562019-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;
52 struct imx8m_power_domain_platdata *pdata;
53 pdata = dev_get_platdata(dev);
54
55 if (pdata->resource_id < 0)
56 return -EINVAL;
57
Peng Fanaae33562020-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 Wildt8bd56562019-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
107static int imx8m_power_domain_ofdata_to_platdata(struct udevice *dev)
108{
109 struct imx8m_power_domain_platdata *pdata = dev_get_platdata(dev);
110
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 Glass92ed3a32020-02-03 07:35:51 -0700127 .rfree = imx8m_power_domain_free,
Patrick Wildt8bd56562019-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,
139 .ofdata_to_platdata = imx8m_power_domain_ofdata_to_platdata,
140 .platdata_auto_alloc_size = sizeof(struct imx8m_power_domain_platdata),
141 .ops = &imx8m_power_domain_ops,
142};