|
|
|
@ -8,6 +8,7 @@
@@ -8,6 +8,7 @@
|
|
|
|
|
|
|
|
|
|
#include <stdio.h> |
|
|
|
|
#include <device.h> |
|
|
|
|
#include <pm/device.h> |
|
|
|
|
#include <init.h> |
|
|
|
|
#include <kernel.h> |
|
|
|
|
#include <settings/settings.h> |
|
|
|
@ -32,9 +33,6 @@ struct ext_power_generic_data {
@@ -32,9 +33,6 @@ struct ext_power_generic_data {
|
|
|
|
|
#if IS_ENABLED(CONFIG_SETTINGS) |
|
|
|
|
bool settings_init; |
|
|
|
|
#endif |
|
|
|
|
#ifdef CONFIG_PM_DEVICE |
|
|
|
|
uint32_t pm_state; |
|
|
|
|
#endif |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
#if IS_ENABLED(CONFIG_SETTINGS) |
|
|
|
@ -94,7 +92,7 @@ static int ext_power_settings_set(const char *name, size_t len, settings_read_cb
@@ -94,7 +92,7 @@ static int ext_power_settings_set(const char *name, size_t len, settings_read_cb
|
|
|
|
|
int rc; |
|
|
|
|
|
|
|
|
|
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; |
|
|
|
|
|
|
|
|
|
if (len != sizeof(data->status)) { |
|
|
|
@ -142,10 +140,6 @@ static int ext_power_generic_init(const struct device *dev) {
@@ -142,10 +140,6 @@ static int ext_power_generic_init(const struct device *dev) {
|
|
|
|
|
return -EIO; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_PM_DEVICE |
|
|
|
|
data->pm_state = DEVICE_PM_ACTIVE_STATE; |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#if IS_ENABLED(CONFIG_SETTINGS) |
|
|
|
|
settings_subsys_init(); |
|
|
|
|
|
|
|
|
@ -179,35 +173,17 @@ static int ext_power_generic_init(const struct device *dev) {
@@ -179,35 +173,17 @@ static int ext_power_generic_init(const struct device *dev) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_PM_DEVICE |
|
|
|
|
static int ext_power_generic_pm_control(const struct device *dev, uint32_t ctrl_command, |
|
|
|
|
void *context, device_pm_cb cb, void *arg) { |
|
|
|
|
int rc; |
|
|
|
|
struct ext_power_generic_data *data = dev->data; |
|
|
|
|
|
|
|
|
|
switch (ctrl_command) { |
|
|
|
|
case DEVICE_PM_SET_POWER_STATE: |
|
|
|
|
if (*((uint32_t *)context) == DEVICE_PM_ACTIVE_STATE) { |
|
|
|
|
data->pm_state = DEVICE_PM_ACTIVE_STATE; |
|
|
|
|
rc = 0; |
|
|
|
|
} else { |
|
|
|
|
static int ext_power_generic_pm_action(const struct device *dev, enum pm_device_action action) { |
|
|
|
|
switch (action) { |
|
|
|
|
case PM_DEVICE_ACTION_TURN_ON: |
|
|
|
|
ext_power_generic_enable(dev); |
|
|
|
|
return 0; |
|
|
|
|
case PM_DEVICE_ACTION_TURN_OFF: |
|
|
|
|
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; |
|
|
|
|
return 0; |
|
|
|
|
default: |
|
|
|
|
rc = -EINVAL; |
|
|
|
|
return -ENOTSUP; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (cb != NULL) { |
|
|
|
|
cb(dev, rc, context, arg); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return rc; |
|
|
|
|
} |
|
|
|
|
#endif /* CONFIG_PM_DEVICE */ |
|
|
|
|
|
|
|
|
@ -230,7 +206,8 @@ static const struct ext_power_api api = {.enable = ext_power_generic_enable,
@@ -230,7 +206,8 @@ static const struct ext_power_api api = {.enable = ext_power_generic_enable,
|
|
|
|
|
|
|
|
|
|
#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); |
|
|
|
|
|
|
|
|
|
#endif /* DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) */ |
|
|
|
|