@@ -344,18 +344,16 @@ static DEVICE_API(sensor, lis2dh_driver_api) = {
344344 .channel_get = lis2dh_channel_get ,
345345};
346346
347- int lis2dh_init (const struct device * dev )
347+ int lis2dh_init_chip (const struct device * dev )
348348{
349349 struct lis2dh_data * lis2dh = dev -> data ;
350350 const struct lis2dh_config * cfg = dev -> config ;
351351 int status ;
352352 uint8_t id ;
353353 uint8_t raw [6 ];
354354
355- status = cfg -> bus_init (dev );
356- if (status < 0 ) {
357- return status ;
358- }
355+ /* AN5005: LIS2DH needs 5ms delay to boot */
356+ k_sleep (K_MSEC (LIS2DH_POR_WAIT_MS ));
359357
360358 status = lis2dh -> hw_tf -> read_reg (dev , LIS2DH_REG_WAI , & id );
361359 if (status < 0 ) {
@@ -446,15 +444,17 @@ int lis2dh_init(const struct device *dev)
446444 LIS2DH_ODR_BITS );
447445}
448446
449- #ifdef CONFIG_PM_DEVICE
450447static int lis2dh_pm_action (const struct device * dev ,
451448 enum pm_device_action action )
452449{
453- int status ;
450+ int status = 0 ;
454451 struct lis2dh_data * lis2dh = dev -> data ;
455452 uint8_t regdata ;
456453
457454 switch (action ) {
455+ case PM_DEVICE_ACTION_TURN_ON :
456+ status = lis2dh_init_chip (dev );
457+ break ;
458458 case PM_DEVICE_ACTION_RESUME :
459459 /* read REFERENCE register (see datasheet rev 6 section 8.9 footnote 1) */
460460 status = lis2dh -> hw_tf -> read_reg (dev , LIS2DH_REG_REFERENCE , & regdata );
@@ -486,13 +486,28 @@ static int lis2dh_pm_action(const struct device *dev,
486486 return status ;
487487 }
488488 break ;
489+ case PM_DEVICE_ACTION_TURN_OFF :
490+ break ;
489491 default :
490492 return - ENOTSUP ;
491493 }
492494
493- return 0 ;
495+ return status ;
496+ }
497+
498+ static int lis2dh_init (const struct device * dev )
499+ {
500+ const struct lis2dh_config * cfg = dev -> config ;
501+ int status ;
502+
503+ status = cfg -> bus_init (dev );
504+ if (status < 0 ) {
505+ LOG_ERR ("Failed to initialize the bus." );
506+ return status ;
507+ }
508+
509+ return pm_device_driver_init (dev , lis2dh_pm_action );
494510}
495- #endif /* CONFIG_PM_DEVICE */
496511
497512#if DT_NUM_INST_STATUS_OKAY (DT_DRV_COMPAT ) == 0
498513#warning "LIS2DH driver enabled without any devices"
0 commit comments