Skip to content

Commit e0cdb01

Browse files
nixwardcarlescufi
authored andcommitted
drivers: sensor: bmm150: add PM
Add PM Signed-off-by: Nick Ward <[email protected]>
1 parent ce9eb7a commit e0cdb01

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

drivers/sensor/bmm150/bmm150.c

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,40 @@ static int bmm150_init_chip(const struct device *dev)
619619
return -EIO;
620620
}
621621

622+
#ifdef CONFIG_PM_DEVICE
623+
static int pm_action(const struct device *dev, enum pm_device_action action)
624+
{
625+
int ret;
626+
627+
switch (action) {
628+
case PM_DEVICE_ACTION_RESUME:
629+
/* Need to enter sleep mode before setting OpMode to normal */
630+
ret = bmm150_power_control(dev, 1);
631+
if (ret != 0) {
632+
LOG_ERR("failed to enter sleep mode: %d", ret);
633+
}
634+
635+
k_sleep(BMM150_START_UP_TIME);
636+
637+
ret |= bmm150_opmode(dev, BMM150_MODE_NORMAL);
638+
if (ret != 0) {
639+
LOG_ERR("failed to enter normal mode: %d", ret);
640+
}
641+
break;
642+
case PM_DEVICE_ACTION_SUSPEND:
643+
ret = bmm150_power_control(dev, 0); /* Suspend */
644+
if (ret != 0) {
645+
LOG_ERR("failed to enter suspend mode: %d", ret);
646+
}
647+
break;
648+
default:
649+
return -ENOTSUP;
650+
}
651+
652+
return ret;
653+
}
654+
#endif
655+
622656
static int bmm150_init(const struct device *dev)
623657
{
624658
int err = 0;
@@ -661,8 +695,12 @@ static int bmm150_init(const struct device *dev)
661695
static const struct bmm150_config bmm150_config_##inst = { \
662696
BMM150_BUS_CFG(inst) \
663697
}; \
698+
\
699+
PM_DEVICE_DT_INST_DEFINE(inst, pm_action); \
700+
\
664701
SENSOR_DEVICE_DT_INST_DEFINE(inst, \
665-
bmm150_init, NULL, \
702+
bmm150_init, \
703+
PM_DEVICE_DT_INST_GET(inst), \
666704
&bmm150_data_##inst, \
667705
&bmm150_config_##inst, \
668706
POST_KERNEL, \

drivers/sensor/bmm150/bmm150.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ extern const struct bmm150_bus_io bmm150_bus_io_i2c;
6060
#include <zephyr/kernel.h>
6161
#include <zephyr/device.h>
6262
#include <zephyr/drivers/sensor.h>
63+
#include <zephyr/pm/device.h>
6364
#include <zephyr/sys/byteorder.h>
6465
#include <zephyr/sys/__assert.h>
6566
#include <zephyr/drivers/gpio.h>

0 commit comments

Comments
 (0)