blob: b45e468756bf4de8b0d5294ef034a372acb7d96b [file] [log] [blame]
Peng Fan5a57b292019-09-02 18:16:32 +08001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright 2019 NXP
4 */
5
6#define DEBUG
7#include <common.h>
8#include <dm.h>
Simon Glass0f2af882020-05-10 11:40:05 -06009#include <log.h>
Simon Glass9bc15642020-02-03 07:36:16 -070010#include <malloc.h>
Peng Fan5a57b292019-09-02 18:16:32 +080011#include <power-domain-uclass.h>
12#include <asm/arch/power-domain.h>
Peng Fan2e0644a2023-04-28 12:08:09 +080013#include <firmware/imx/sci/sci.h>
Peng Fan5a57b292019-09-02 18:16:32 +080014
Peng Fan5a57b292019-09-02 18:16:32 +080015static int imx8_power_domain_on(struct power_domain *power_domain)
16{
17 u32 resource_id = power_domain->id;
18 int ret;
19
20 debug("%s: resource_id %u\n", __func__, resource_id);
21
22 ret = sc_pm_set_resource_power_mode(-1, resource_id, SC_PM_PW_MODE_ON);
23 if (ret) {
24 printf("Error: %u Power up failed! (error = %d)\n",
25 resource_id, ret);
26 return ret;
27 }
28
29 return 0;
30}
31
32static int imx8_power_domain_off(struct power_domain *power_domain)
33{
34 u32 resource_id = power_domain->id;
35 int ret;
36
37 debug("%s: resource_id %u\n", __func__, resource_id);
38
39 ret = sc_pm_set_resource_power_mode(-1, resource_id, SC_PM_PW_MODE_OFF);
40 if (ret) {
41 printf("Error: %u Power off failed! (error = %d)\n",
42 resource_id, ret);
43 return ret;
44 }
45
46 return 0;
47}
48
Peng Fan5a57b292019-09-02 18:16:32 +080049static const struct udevice_id imx8_power_domain_ids[] = {
50 { .compatible = "fsl,imx8qxp-scu-pd" },
51 { .compatible = "fsl,scu-pd" },
52 { }
53};
54
55struct power_domain_ops imx8_power_domain_ops_v2 = {
Peng Fan5a57b292019-09-02 18:16:32 +080056 .on = imx8_power_domain_on,
57 .off = imx8_power_domain_off,
58};
59
60U_BOOT_DRIVER(imx8_power_domain_v2) = {
61 .name = "imx8_power_domain_v2",
62 .id = UCLASS_POWER_DOMAIN,
63 .of_match = imx8_power_domain_ids,
Peng Fan5a57b292019-09-02 18:16:32 +080064 .ops = &imx8_power_domain_ops_v2,
65};