Peng Fan | 5a57b29 | 2019-09-02 18:16:32 +0800 | [diff] [blame] | 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> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 10 | #include <malloc.h> |
Peng Fan | 5a57b29 | 2019-09-02 18:16:32 +0800 | [diff] [blame] | 11 | #include <power-domain-uclass.h> |
| 12 | #include <asm/arch/power-domain.h> |
Peng Fan | 2e0644a | 2023-04-28 12:08:09 +0800 | [diff] [blame] | 13 | #include <firmware/imx/sci/sci.h> |
Peng Fan | 5a57b29 | 2019-09-02 18:16:32 +0800 | [diff] [blame] | 14 | |
Peng Fan | 5a57b29 | 2019-09-02 18:16:32 +0800 | [diff] [blame] | 15 | static 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 | |
| 32 | static 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 Fan | 5a57b29 | 2019-09-02 18:16:32 +0800 | [diff] [blame] | 49 | static const struct udevice_id imx8_power_domain_ids[] = { |
| 50 | { .compatible = "fsl,imx8qxp-scu-pd" }, |
| 51 | { .compatible = "fsl,scu-pd" }, |
| 52 | { } |
| 53 | }; |
| 54 | |
| 55 | struct power_domain_ops imx8_power_domain_ops_v2 = { |
Peng Fan | 5a57b29 | 2019-09-02 18:16:32 +0800 | [diff] [blame] | 56 | .on = imx8_power_domain_on, |
| 57 | .off = imx8_power_domain_off, |
| 58 | }; |
| 59 | |
| 60 | U_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 Fan | 5a57b29 | 2019-09-02 18:16:32 +0800 | [diff] [blame] | 64 | .ops = &imx8_power_domain_ops_v2, |
| 65 | }; |