zephyr/drivers/power_domain/power_domain_intel_adsp.c
Marc Herbert c73e67018d power_domain_intel_adsp.c: revert recent INIT_PRIORITY change
This is a partial revert of one-line from commit 06cfbd4159 ("drivers:
power_domain: Introduce a gpio monitor driver") which not just
introduced a new driver (no problem with that) but also changed the
initialization priority of another, unrelated and existing power domain
driver without even trying to compile it:

https://github.com/zephyrproject-rtos/zephyr/pull/61166#issuecomment-1780959157

```
west config manifest.project-filter -- +sof
west update

west build -b intel_adsp_ace20_lnl modules/audio/sof/app/

ERROR: /soc/ssp@28100 POST_KERNEL 43 < /soc/dfpmccu@71b00/io0_domain  51
ERROR: /soc/ssp@29100 POST_KERNEL 44 < /soc/dfpmccu@71b00/io0_domain  51
ERROR: /soc/ssp@2a100 POST_KERNEL 45 < /soc/dfpmccu@71b00/io0_domain  51
ERROR: /soc/ssp@2b100 POST_KERNEL 46 < /soc/dfpmccu@71b00/io0_domain  51
ERROR: /soc/ssp@2c100 POST_KERNEL 47 < /soc/dfpmccu@71b00/io0_domain  51
ERROR: /soc/ssp@2d100 POST_KERNEL 48 < /soc/dfpmccu@71b00/io0_domain  51
```

Also note a reviewer (@ceolin) expressed concerns about this unrelated
change but it was ignored:
https://github.com/zephyrproject-rtos/zephyr/pull/61166#discussion_r1357908984

Using `CONFIG_KERNEL_INIT_PRIORITY_DEFAULT` here may be "bad" for some
reason(s) and maybe it should be changed in the future, but it's nothing
compared to breaking _compilation_ of code that has been validated for
months and been released in production
(https://github.com/thesofproject/sof-bin/releases/tag/v2023.09)

So the very urgent thing is to very quickly revert to the previous state
to unblock development. Then we can discuss what is the better thing to
do here.

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2023-11-02 08:33:40 +00:00

89 lines
2.3 KiB
C

/*
* Copyright (c) 2022 Intel Corporation.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/kernel.h>
#include <zephyr/pm/device.h>
#include <zephyr/pm/device_runtime.h>
#include <adsp_shim.h>
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(power_domain_intel_adsp, LOG_LEVEL_INF);
struct pg_bits {
uint32_t SPA_bit;
uint32_t CPA_bit;
};
#ifdef CONFIG_PM_DEVICE
static int pd_intel_adsp_set_power_enable(struct pg_bits *bits, bool power_enable)
{
uint16_t SPA_bit_mask = BIT(bits->SPA_bit);
if (power_enable) {
sys_write16(sys_read16((mem_addr_t)&ACE_DfPMCCU.dfpwrctl) | SPA_bit_mask,
(mem_addr_t)&ACE_DfPMCCU.dfpwrctl);
if (!WAIT_FOR(sys_read16((mem_addr_t)&ACE_DfPMCCU.dfpwrsts) & BIT(bits->CPA_bit),
10000, k_busy_wait(1))) {
return -1;
}
} else {
sys_write16(sys_read16((mem_addr_t)&ACE_DfPMCCU.dfpwrctl) & ~(SPA_bit_mask),
(mem_addr_t)&ACE_DfPMCCU.dfpwrctl);
}
return 0;
}
static int pd_intel_adsp_pm_action(const struct device *dev, enum pm_device_action action)
{
struct pg_bits *reg_bits = (struct pg_bits *)dev->data;
int ret = 0;
switch (action) {
case PM_DEVICE_ACTION_RESUME:
ret = pd_intel_adsp_set_power_enable(reg_bits, true);
if (ret == 0) {
pm_device_children_action_run(dev, PM_DEVICE_ACTION_TURN_ON, NULL);
}
break;
case PM_DEVICE_ACTION_SUSPEND:
pm_device_children_action_run(dev, PM_DEVICE_ACTION_TURN_OFF, NULL);
ret = pd_intel_adsp_set_power_enable(reg_bits, false);
break;
case PM_DEVICE_ACTION_TURN_ON:
break;
case PM_DEVICE_ACTION_TURN_OFF:
break;
default:
return -ENOTSUP;
}
return ret;
}
#endif /* CONFIG_PM_DEVICE */
static int pd_intel_adsp_init(const struct device *dev)
{
pm_device_init_suspended(dev);
return pm_device_runtime_enable(dev);
}
#define DT_DRV_COMPAT intel_adsp_power_domain
#define POWER_DOMAIN_DEVICE(id) \
static struct pg_bits pd_pg_reg##id = { \
.SPA_bit = DT_INST_PROP(id, bit_position), \
.CPA_bit = DT_INST_PROP(id, bit_position), \
}; \
PM_DEVICE_DT_INST_DEFINE(id, pd_intel_adsp_pm_action); \
DEVICE_DT_INST_DEFINE(id, pd_intel_adsp_init, PM_DEVICE_DT_INST_GET(id), \
&pd_pg_reg##id, NULL, POST_KERNEL, \
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, NULL);
DT_INST_FOREACH_STATUS_OKAY(POWER_DOMAIN_DEVICE)