Skip to content

Commit c954f5c

Browse files
committed
drivers: sensor: Fix CXD5605 Reinit
Fixed issue where CXD5605 would not reinitialize on power on after power off. Signed-off-by: Jared Baumann <[email protected]>
1 parent abf4670 commit c954f5c

File tree

2 files changed

+21
-35
lines changed

2 files changed

+21
-35
lines changed

drivers/sensor/cxd5605/cxd5605.c

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ static int init(const struct device *dev)
170170

171171
result = gpio_pin_configure_dt(&cfg->rst_gpio, GPIO_OUTPUT_HIGH);
172172

173+
cxd5605_setup_interrupts(dev);
174+
/* setup shim callbacks */
175+
cxd5605_lib_init(dev);
176+
cxd5605_register_resp_callback(dev, driver_cxd5605_resp_cb);
177+
cxd5605_register_nmea_callback(dev, driver_cxd5605_nmea_cb);
178+
173179
return result;
174180
}
175181

@@ -429,11 +435,6 @@ static int cxd5605_attr_set(const struct device *dev,
429435
uint8_t min = 0;
430436
uint8_t sec = 0;
431437

432-
433-
const struct cxd5605_config *config = dev->config;
434-
const struct gpio_dt_spec *pwr_gpio = &config->pwr_gpio;
435-
const struct gpio_dt_spec *rst_gpio = &config->rst_gpio;
436-
437438
if (chan != SENSOR_CHAN_AMBIENT_TEMP && chan != SENSOR_CHAN_ALL) {
438439
return -ENOTSUP;
439440
}
@@ -459,6 +460,9 @@ static int cxd5605_attr_set(const struct device *dev,
459460
__FILE__, __LINE__, result);
460461
return result;
461462
}
463+
drv_data->op_mode = val[0].val1;
464+
drv_data->pos_cycle = val[0].val2;
465+
drv_data->sleep_time = val[1].val1;
462466
break;
463467

464468
case SENSOR_ATTR_CXD5605_PULSE:
@@ -508,6 +512,7 @@ static int cxd5605_attr_set(const struct device *dev,
508512
__FILE__, __LINE__, result);
509513
return result;
510514
}
515+
drv_data->selected_sentences = val->val1;
511516
break;
512517

513518
case SENSOR_ATTR_CXD5605_HOT_START:
@@ -580,39 +585,10 @@ static int cxd5605_attr_set(const struct device *dev,
580585
}
581586
break;
582587

583-
case SENSOR_ATTR_CXD5605_PWR_CTRL:
584-
if (val->val1 == 0) {
585-
result = gpio_pin_configure_dt(pwr_gpio, GPIO_OUTPUT_LOW);
586-
result = gpio_pin_configure_dt(rst_gpio, GPIO_OUTPUT_LOW);
587-
} else {
588-
result = gpio_pin_configure_dt(pwr_gpio, GPIO_OUTPUT_HIGH);
589-
result = gpio_pin_configure_dt(rst_gpio, GPIO_OUTPUT_HIGH);
590-
}
591-
break;
592-
593-
case SENSOR_ATTR_CXD5605_CALLBACK:
594-
init(dev);
595-
LOG_DBG("Got CXD5605_ALERT_INTERRUPTS\n");
596-
cxd5605_setup_interrupts(dev);
597-
/* setup shim callbacks */
598-
#ifdef DEBUG
599-
printf("[driver] register driver callback\n");
600-
#endif
601-
cxd5605_lib_init(dev);
602-
cxd5605_register_resp_callback(dev, driver_cxd5605_resp_cb);
603-
cxd5605_register_nmea_callback(dev, driver_cxd5605_nmea_cb);
604-
return 0;
605-
606588
default:
607589
return -ENOTSUP;
608590
}
609591

610-
if (drv_data->cxd5605_cmd != SENSOR_ATTR_CXD5605_PWR_CTRL) {
611-
result = cxd5605_wait_fetch(dev);
612-
if (result < 0) {
613-
return result;
614-
}
615-
}
616592

617593
return 0;
618594
}
@@ -684,6 +660,7 @@ static int cxd5605_driver_pm_action(const struct device *dev,
684660
{
685661
const struct cxd5605_config *config = dev->config;
686662
const struct gpio_dt_spec *rst_gpio = &config->rst_gpio;
663+
struct cxd5605_data *drv_data = dev->data;
687664

688665
int result = 0;
689666

@@ -699,6 +676,11 @@ static int cxd5605_driver_pm_action(const struct device *dev,
699676
if (result < 0) {
700677
printk("ERROR: I2C interface not working (CXD5605 driver)\n");
701678
}
679+
if (drv_data->pps_cb) {
680+
cxd5605_pulse(dev, 1);
681+
}
682+
cxd5605_operating_mode(dev, drv_data->op_mode, drv_data->pos_cycle, drv_data->sleep_time);
683+
cxd5605_sentence_select(dev, drv_data->selected_sentences);
702684

703685
case PM_DEVICE_ACTION_SUSPEND:
704686
cxd5605_sleep(dev, 0);

include/zephyr/drivers/sensor/cxd5605.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ enum sensor_attribute_cxd5605 {
5656
SENSOR_ATTR_CXD5605_SLEEP,
5757
SENSOR_ATTR_CXD5605_VERSION,
5858
SENSOR_ATTR_CXD5605_ASSIST_GEN_FUNCTION_CONTROL,
59-
SENSOR_ATTR_CXD5605_PWR_CTRL,
6059
};
6160

6261
enum gga_nmea_fieldpos_t {
@@ -167,6 +166,11 @@ struct cxd5605_data {
167166
bool got_data;
168167
bool lib_got_data;
169168
int command;
169+
170+
uint32_t op_mode;
171+
uint32_t pos_cycle;
172+
uint32_t sleep_time;
173+
uint32_t selected_sentences;
170174
};
171175

172176
/** a mask for the under temp alert bit in the status word*/

0 commit comments

Comments
 (0)