File tree Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -619,6 +619,40 @@ static int bmm150_init_chip(const struct device *dev)
619
619
return - EIO ;
620
620
}
621
621
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
+
622
656
static int bmm150_init (const struct device * dev )
623
657
{
624
658
int err = 0 ;
@@ -661,8 +695,12 @@ static int bmm150_init(const struct device *dev)
661
695
static const struct bmm150_config bmm150_config_##inst = { \
662
696
BMM150_BUS_CFG(inst) \
663
697
}; \
698
+ \
699
+ PM_DEVICE_DT_INST_DEFINE(inst, pm_action); \
700
+ \
664
701
SENSOR_DEVICE_DT_INST_DEFINE(inst, \
665
- bmm150_init, NULL, \
702
+ bmm150_init, \
703
+ PM_DEVICE_DT_INST_GET(inst), \
666
704
&bmm150_data_##inst, \
667
705
&bmm150_config_##inst, \
668
706
POST_KERNEL, \
Original file line number Diff line number Diff line change @@ -60,6 +60,7 @@ extern const struct bmm150_bus_io bmm150_bus_io_i2c;
60
60
#include <zephyr/kernel.h>
61
61
#include <zephyr/device.h>
62
62
#include <zephyr/drivers/sensor.h>
63
+ #include <zephyr/pm/device.h>
63
64
#include <zephyr/sys/byteorder.h>
64
65
#include <zephyr/sys/__assert.h>
65
66
#include <zephyr/drivers/gpio.h>
You can’t perform that action at this time.
0 commit comments