blob: 5d34bc1290286289dbed09b369d93ec4b3f59f2b [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>
Simon Glass3ba929a2020-10-30 21:38:53 -060010#include <asm/global_data.h>
Patrick Wildt8bd56562019-10-03 15:51:50 +020011#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>
Peng Fanaae33562020-05-11 15:16:37 +080017#include <linux/arm-smccc.h>
Patrick Wildt8bd56562019-10-03 15:51:50 +020018
19DECLARE_GLOBAL_DATA_PTR;
20
21static int imx8m_power_domain_request(struct power_domain *power_domain)
22{
23 return 0;
24}
25
26static int imx8m_power_domain_free(struct power_domain *power_domain)
27{
28 return 0;
29}
30
31static int imx8m_power_domain_on(struct power_domain *power_domain)
32{
33 struct udevice *dev = power_domain->dev;
Simon Glassb75b15b2020-12-03 16:55:23 -070034 struct imx8m_power_domain_plat *pdata;
Peng Fanaae33562020-05-11 15:16:37 +080035
Simon Glassfa20e932020-12-03 16:55:20 -070036 pdata = dev_get_plat(dev);
Patrick Wildt8bd56562019-10-03 15:51:50 +020037
38 if (pdata->resource_id < 0)
39 return -EINVAL;
40
41 if (pdata->has_pd)
42 power_domain_on(&pdata->pd);
43
Peng Fanaae33562020-05-11 15:16:37 +080044 arm_smccc_smc(IMX_SIP_GPC, IMX_SIP_GPC_PM_DOMAIN,
45 pdata->resource_id, 1, 0, 0, 0, 0, NULL);
Patrick Wildt8bd56562019-10-03 15:51:50 +020046
47 return 0;
48}
49
50static int imx8m_power_domain_off(struct power_domain *power_domain)
51{
52 struct udevice *dev = power_domain->dev;
Simon Glassb75b15b2020-12-03 16:55:23 -070053 struct imx8m_power_domain_plat *pdata;
Simon Glassfa20e932020-12-03 16:55:20 -070054 pdata = dev_get_plat(dev);
Patrick Wildt8bd56562019-10-03 15:51:50 +020055
56 if (pdata->resource_id < 0)
57 return -EINVAL;
58
Peng Fanaae33562020-05-11 15:16:37 +080059 arm_smccc_smc(IMX_SIP_GPC, IMX_SIP_GPC_PM_DOMAIN,
60 pdata->resource_id, 0, 0, 0, 0, 0, NULL);
Patrick Wildt8bd56562019-10-03 15:51:50 +020061
62 if (pdata->has_pd)
63 power_domain_off(&pdata->pd);
64
65 return 0;
66}
67
68static int imx8m_power_domain_of_xlate(struct power_domain *power_domain,
69 struct ofnode_phandle_args *args)
70{
71 return 0;
72}
73
74static 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
103static int imx8m_power_domain_probe(struct udevice *dev)
104{
105 return 0;
106}
107
Simon Glassaad29ae2020-12-03 16:55:21 -0700108static int imx8m_power_domain_of_to_plat(struct udevice *dev)
Patrick Wildt8bd56562019-10-03 15:51:50 +0200109{
Simon Glassb75b15b2020-12-03 16:55:23 -0700110 struct imx8m_power_domain_plat *pdata = dev_get_plat(dev);
Patrick Wildt8bd56562019-10-03 15:51:50 +0200111
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
121static const struct udevice_id imx8m_power_domain_ids[] = {
122 { .compatible = "fsl,imx8mq-gpc" },
Marek Vasutd72ac582021-04-02 13:32:40 +0200123 { .compatible = "fsl,imx8mm-gpc" },
Marek Vasute95c8dc2021-04-10 00:19:27 +0200124 { .compatible = "fsl,imx8mn-gpc" },
Patrick Wildt8bd56562019-10-03 15:51:50 +0200125 { }
126};
127
128struct power_domain_ops imx8m_power_domain_ops = {
129 .request = imx8m_power_domain_request,
Simon Glass92ed3a32020-02-03 07:35:51 -0700130 .rfree = imx8m_power_domain_free,
Patrick Wildt8bd56562019-10-03 15:51:50 +0200131 .on = imx8m_power_domain_on,
132 .off = imx8m_power_domain_off,
133 .of_xlate = imx8m_power_domain_of_xlate,
134};
135
136U_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,
Simon Glassaad29ae2020-12-03 16:55:21 -0700142 .of_to_plat = imx8m_power_domain_of_to_plat,
Simon Glassb75b15b2020-12-03 16:55:23 -0700143 .plat_auto = sizeof(struct imx8m_power_domain_plat),
Patrick Wildt8bd56562019-10-03 15:51:50 +0200144 .ops = &imx8m_power_domain_ops,
145};