fix(power): Fix ext power generic driver.
* Adjust for device API changes to fetch ext power driver instance from settings callback. * New PM action callback API.
This commit is contained in:
parent
4eb8f8cd23
commit
917c6a0660
1 changed files with 13 additions and 36 deletions
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <device.h>
|
#include <device.h>
|
||||||
|
#include <pm/device.h>
|
||||||
#include <init.h>
|
#include <init.h>
|
||||||
#include <kernel.h>
|
#include <kernel.h>
|
||||||
#include <settings/settings.h>
|
#include <settings/settings.h>
|
||||||
|
@ -32,9 +33,6 @@ struct ext_power_generic_data {
|
||||||
#if IS_ENABLED(CONFIG_SETTINGS)
|
#if IS_ENABLED(CONFIG_SETTINGS)
|
||||||
bool settings_init;
|
bool settings_init;
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_PM_DEVICE
|
|
||||||
uint32_t pm_state;
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#if IS_ENABLED(CONFIG_SETTINGS)
|
#if IS_ENABLED(CONFIG_SETTINGS)
|
||||||
|
@ -94,7 +92,7 @@ static int ext_power_settings_set(const char *name, size_t len, settings_read_cb
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if (settings_name_steq(name, DT_INST_LABEL(0), &next) && !next) {
|
if (settings_name_steq(name, DT_INST_LABEL(0), &next) && !next) {
|
||||||
const struct device *ext_power = device_get_binding(DT_INST_LABEL(0));
|
const struct device *ext_power = DEVICE_DT_GET(DT_DRV_INST(0));
|
||||||
struct ext_power_generic_data *data = ext_power->data;
|
struct ext_power_generic_data *data = ext_power->data;
|
||||||
|
|
||||||
if (len != sizeof(data->status)) {
|
if (len != sizeof(data->status)) {
|
||||||
|
@ -142,10 +140,6 @@ static int ext_power_generic_init(const struct device *dev) {
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_PM_DEVICE
|
|
||||||
data->pm_state = DEVICE_PM_ACTIVE_STATE;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if IS_ENABLED(CONFIG_SETTINGS)
|
#if IS_ENABLED(CONFIG_SETTINGS)
|
||||||
settings_subsys_init();
|
settings_subsys_init();
|
||||||
|
|
||||||
|
@ -179,35 +173,17 @@ static int ext_power_generic_init(const struct device *dev) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_PM_DEVICE
|
#ifdef CONFIG_PM_DEVICE
|
||||||
static int ext_power_generic_pm_control(const struct device *dev, uint32_t ctrl_command,
|
static int ext_power_generic_pm_action(const struct device *dev, enum pm_device_action action) {
|
||||||
void *context, device_pm_cb cb, void *arg) {
|
switch (action) {
|
||||||
int rc;
|
case PM_DEVICE_ACTION_TURN_ON:
|
||||||
struct ext_power_generic_data *data = dev->data;
|
ext_power_generic_enable(dev);
|
||||||
|
return 0;
|
||||||
switch (ctrl_command) {
|
case PM_DEVICE_ACTION_TURN_OFF:
|
||||||
case DEVICE_PM_SET_POWER_STATE:
|
ext_power_generic_disable(dev);
|
||||||
if (*((uint32_t *)context) == DEVICE_PM_ACTIVE_STATE) {
|
return 0;
|
||||||
data->pm_state = DEVICE_PM_ACTIVE_STATE;
|
|
||||||
rc = 0;
|
|
||||||
} else {
|
|
||||||
ext_power_generic_disable(dev);
|
|
||||||
data->pm_state = DEVICE_PM_LOW_POWER_STATE;
|
|
||||||
rc = 0;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case DEVICE_PM_GET_POWER_STATE:
|
|
||||||
*((uint32_t *)context) = data->pm_state;
|
|
||||||
rc = 0;
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
rc = -EINVAL;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cb != NULL) {
|
|
||||||
cb(dev, rc, context, arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_PM_DEVICE */
|
#endif /* CONFIG_PM_DEVICE */
|
||||||
|
|
||||||
|
@ -230,7 +206,8 @@ static const struct ext_power_api api = {.enable = ext_power_generic_enable,
|
||||||
|
|
||||||
#define ZMK_EXT_POWER_INIT_PRIORITY 81
|
#define ZMK_EXT_POWER_INIT_PRIORITY 81
|
||||||
|
|
||||||
DEVICE_DT_INST_DEFINE(0, ext_power_generic_init, &ext_power_generic_pm_control, &data, &config,
|
PM_DEVICE_DT_INST_DEFINE(0, ext_power_generic_pm_action);
|
||||||
|
DEVICE_DT_INST_DEFINE(0, ext_power_generic_init, PM_DEVICE_DT_INST_GET(0), &data, &config,
|
||||||
POST_KERNEL, ZMK_EXT_POWER_INIT_PRIORITY, &api);
|
POST_KERNEL, ZMK_EXT_POWER_INIT_PRIORITY, &api);
|
||||||
|
|
||||||
#endif /* DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) */
|
#endif /* DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) */
|
||||||
|
|
Loading…
Reference in a new issue