From 50c808df2c20bee7953b773301659989fe38d97e Mon Sep 17 00:00:00 2001 From: Hector Martin Date: Fri, 5 May 2023 12:39:26 +0900 Subject: [PATCH] pmgr: Power up parents before children Signed-off-by: Hector Martin --- src/pmgr.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/pmgr.c b/src/pmgr.c index b37ca5aa..514a4873 100644 --- a/src/pmgr.c +++ b/src/pmgr.c @@ -121,23 +121,30 @@ static int pmgr_set_mode_recursive(u8 die, u16 id, u8 target_mode, bool recurse) if (pmgr_find_device(id, &device)) return -1; - if (!(device->flags & PMGR_FLAG_VIRTUAL)) { + if (target_mode == 0 && !(device->flags & PMGR_FLAG_VIRTUAL)) { uintptr_t addr = pmgr_device_get_addr(die, device); if (!addr) return -1; if (pmgr_set_mode(addr, target_mode)) return -1; } - if (!recurse) - return 0; - for (int i = 0; i < 2; i++) { - if (device->parent[i]) { - u16 parent = FIELD_GET(PMGR_DEVICE_ID, device->parent[i]); - int ret = pmgr_set_mode_recursive(die, parent, target_mode, true); - if (ret < 0) - return ret; + if (recurse) + for (int i = 0; i < 2; i++) { + if (device->parent[i]) { + u16 parent = FIELD_GET(PMGR_DEVICE_ID, device->parent[i]); + int ret = pmgr_set_mode_recursive(die, parent, target_mode, true); + if (ret < 0) + return ret; + } } + + if (target_mode != 0 && !(device->flags & PMGR_FLAG_VIRTUAL)) { + uintptr_t addr = pmgr_device_get_addr(die, device); + if (!addr) + return -1; + if (pmgr_set_mode(addr, target_mode)) + return -1; } return 0;