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