1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright 2019 NXP
4  */
5 
6 #define DEBUG
7 #include <common.h>
8 #include <dm.h>
9 #include <log.h>
10 #include <malloc.h>
11 #include <power-domain-uclass.h>
12 #include <asm/arch/power-domain.h>
13 #include <asm/arch/sci/sci.h>
14 
imx8_power_domain_request(struct power_domain * power_domain)15 static int imx8_power_domain_request(struct power_domain *power_domain)
16 {
17 	debug("%s(power_domain=%p)\n", __func__, power_domain);
18 
19 	return 0;
20 }
21 
imx8_power_domain_free(struct power_domain * power_domain)22 static int imx8_power_domain_free(struct power_domain *power_domain)
23 {
24 	debug("%s(power_domain=%p)\n", __func__, power_domain);
25 
26 	return 0;
27 }
28 
imx8_power_domain_on(struct power_domain * power_domain)29 static int imx8_power_domain_on(struct power_domain *power_domain)
30 {
31 	u32 resource_id = power_domain->id;
32 	int ret;
33 
34 	debug("%s: resource_id %u\n", __func__, resource_id);
35 
36 	ret = sc_pm_set_resource_power_mode(-1, resource_id, SC_PM_PW_MODE_ON);
37 	if (ret) {
38 		printf("Error: %u Power up failed! (error = %d)\n",
39 		       resource_id, ret);
40 		return ret;
41 	}
42 
43 	return 0;
44 }
45 
imx8_power_domain_off(struct power_domain * power_domain)46 static int imx8_power_domain_off(struct power_domain *power_domain)
47 {
48 	u32 resource_id = power_domain->id;
49 	int ret;
50 
51 	debug("%s: resource_id %u\n", __func__, resource_id);
52 
53 	ret = sc_pm_set_resource_power_mode(-1, resource_id, SC_PM_PW_MODE_OFF);
54 	if (ret) {
55 		printf("Error: %u Power off failed! (error = %d)\n",
56 		       resource_id, ret);
57 		return ret;
58 	}
59 
60 	return 0;
61 }
62 
imx8_power_domain_probe(struct udevice * dev)63 static int imx8_power_domain_probe(struct udevice *dev)
64 {
65 	debug("%s(dev=%s)\n", __func__, dev->name);
66 
67 	return 0;
68 }
69 
70 static const struct udevice_id imx8_power_domain_ids[] = {
71 	{ .compatible = "fsl,imx8qxp-scu-pd" },
72 	{ .compatible = "fsl,scu-pd" },
73 	{ }
74 };
75 
76 struct power_domain_ops imx8_power_domain_ops_v2 = {
77 	.request = imx8_power_domain_request,
78 	.rfree = imx8_power_domain_free,
79 	.on = imx8_power_domain_on,
80 	.off = imx8_power_domain_off,
81 };
82 
83 U_BOOT_DRIVER(imx8_power_domain_v2) = {
84 	.name = "imx8_power_domain_v2",
85 	.id = UCLASS_POWER_DOMAIN,
86 	.of_match = imx8_power_domain_ids,
87 	.probe = imx8_power_domain_probe,
88 	.ops = &imx8_power_domain_ops_v2,
89 };
90