@@ -344,18 +344,16 @@ static DEVICE_API(sensor, lis2dh_driver_api) = {
344
344
.channel_get = lis2dh_channel_get ,
345
345
};
346
346
347
- int lis2dh_init (const struct device * dev )
347
+ int lis2dh_init_chip (const struct device * dev )
348
348
{
349
349
struct lis2dh_data * lis2dh = dev -> data ;
350
350
const struct lis2dh_config * cfg = dev -> config ;
351
351
int status ;
352
352
uint8_t id ;
353
353
uint8_t raw [6 ];
354
354
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 ));
359
357
360
358
status = lis2dh -> hw_tf -> read_reg (dev , LIS2DH_REG_WAI , & id );
361
359
if (status < 0 ) {
@@ -446,15 +444,17 @@ int lis2dh_init(const struct device *dev)
446
444
LIS2DH_ODR_BITS );
447
445
}
448
446
449
- #ifdef CONFIG_PM_DEVICE
450
447
static int lis2dh_pm_action (const struct device * dev ,
451
448
enum pm_device_action action )
452
449
{
453
- int status ;
450
+ int status = 0 ;
454
451
struct lis2dh_data * lis2dh = dev -> data ;
455
452
uint8_t regdata ;
456
453
457
454
switch (action ) {
455
+ case PM_DEVICE_ACTION_TURN_ON :
456
+ status = lis2dh_init_chip (dev );
457
+ break ;
458
458
case PM_DEVICE_ACTION_RESUME :
459
459
/* read REFERENCE register (see datasheet rev 6 section 8.9 footnote 1) */
460
460
status = lis2dh -> hw_tf -> read_reg (dev , LIS2DH_REG_REFERENCE , & regdata );
@@ -486,13 +486,28 @@ static int lis2dh_pm_action(const struct device *dev,
486
486
return status ;
487
487
}
488
488
break ;
489
+ case PM_DEVICE_ACTION_TURN_OFF :
490
+ break ;
489
491
default :
490
492
return - ENOTSUP ;
491
493
}
492
494
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 );
494
510
}
495
- #endif /* CONFIG_PM_DEVICE */
496
511
497
512
#if DT_NUM_INST_STATUS_OKAY (DT_DRV_COMPAT ) == 0
498
513
#warning "LIS2DH driver enabled without any devices"
0 commit comments