blob: e8dcc057fee0071b43dc3792ec65d0ce87ec2b76 [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
Peng Fan5a57b292019-09-02 18:16:32 +08007#include <dm.h>
Simon Glass0f2af882020-05-10 11:40:05 -06008#include <log.h>
Simon Glass9bc15642020-02-03 07:36:16 -07009#include <malloc.h>
Peng Fan5a57b292019-09-02 18:16:32 +080010#include <power-domain-uclass.h>
11#include <asm/arch/power-domain.h>
Peng Fan2e0644a2023-04-28 12:08:09 +080012#include <firmware/imx/sci/sci.h>
Peng Fan5a57b292019-09-02 18:16:32 +080013
Peng Fan5a57b292019-09-02 18:16:32 +080014static int imx8_power_domain_on(struct power_domain *power_domain)
15{
16 u32 resource_id = power_domain->id;
17 int ret;
18
19 debug("%s: resource_id %u\n", __func__, resource_id);
20
21 ret = sc_pm_set_resource_power_mode(-1, resource_id, SC_PM_PW_MODE_ON);
22 if (ret) {
23 printf("Error: %u Power up failed! (error = %d)\n",
24 resource_id, ret);
25 return ret;
26 }
27
28 return 0;
29}
30
31static int imx8_power_domain_off(struct power_domain *power_domain)
32{
33 u32 resource_id = power_domain->id;
34 int ret;
35
36 debug("%s: resource_id %u\n", __func__, resource_id);
37
38 ret = sc_pm_set_resource_power_mode(-1, resource_id, SC_PM_PW_MODE_OFF);
39 if (ret) {
40 printf("Error: %u Power off failed! (error = %d)\n",
41 resource_id, ret);
42 return ret;
43 }
44
45 return 0;
46}
47
Peng Fan5a57b292019-09-02 18:16:32 +080048static const struct udevice_id imx8_power_domain_ids[] = {
49 { .compatible = "fsl,imx8qxp-scu-pd" },
50 { .compatible = "fsl,scu-pd" },
51 { }
52};
53
54struct power_domain_ops imx8_power_domain_ops_v2 = {
Peng Fan5a57b292019-09-02 18:16:32 +080055 .on = imx8_power_domain_on,
56 .off = imx8_power_domain_off,
57};
58
59U_BOOT_DRIVER(imx8_power_domain_v2) = {
60 .name = "imx8_power_domain_v2",
61 .id = UCLASS_POWER_DOMAIN,
62 .of_match = imx8_power_domain_ids,
Peng Fan5a57b292019-09-02 18:16:32 +080063 .ops = &imx8_power_domain_ops_v2,
64};