From c954f5c8e09ceb69f8effde3976b412af652051a Mon Sep 17 00:00:00 2001 From: Jared Baumann Date: Tue, 9 May 2023 15:17:54 +0000 Subject: [PATCH] drivers: sensor: Fix CXD5605 Reinit Fixed issue where CXD5605 would not reinitialize on power on after power off. Signed-off-by: Jared Baumann --- drivers/sensor/cxd5605/cxd5605.c | 50 ++++++++----------------- include/zephyr/drivers/sensor/cxd5605.h | 6 ++- 2 files changed, 21 insertions(+), 35 deletions(-) diff --git a/drivers/sensor/cxd5605/cxd5605.c b/drivers/sensor/cxd5605/cxd5605.c index ed103f25b6c..08002c577c3 100644 --- a/drivers/sensor/cxd5605/cxd5605.c +++ b/drivers/sensor/cxd5605/cxd5605.c @@ -170,6 +170,12 @@ static int init(const struct device *dev) result = gpio_pin_configure_dt(&cfg->rst_gpio, GPIO_OUTPUT_HIGH); + cxd5605_setup_interrupts(dev); + /* setup shim callbacks */ + cxd5605_lib_init(dev); + cxd5605_register_resp_callback(dev, driver_cxd5605_resp_cb); + cxd5605_register_nmea_callback(dev, driver_cxd5605_nmea_cb); + return result; } @@ -429,11 +435,6 @@ static int cxd5605_attr_set(const struct device *dev, uint8_t min = 0; uint8_t sec = 0; - - const struct cxd5605_config *config = dev->config; - const struct gpio_dt_spec *pwr_gpio = &config->pwr_gpio; - const struct gpio_dt_spec *rst_gpio = &config->rst_gpio; - if (chan != SENSOR_CHAN_AMBIENT_TEMP && chan != SENSOR_CHAN_ALL) { return -ENOTSUP; } @@ -459,6 +460,9 @@ static int cxd5605_attr_set(const struct device *dev, __FILE__, __LINE__, result); return result; } + drv_data->op_mode = val[0].val1; + drv_data->pos_cycle = val[0].val2; + drv_data->sleep_time = val[1].val1; break; case SENSOR_ATTR_CXD5605_PULSE: @@ -508,6 +512,7 @@ static int cxd5605_attr_set(const struct device *dev, __FILE__, __LINE__, result); return result; } + drv_data->selected_sentences = val->val1; break; case SENSOR_ATTR_CXD5605_HOT_START: @@ -580,39 +585,10 @@ static int cxd5605_attr_set(const struct device *dev, } break; - case SENSOR_ATTR_CXD5605_PWR_CTRL: - if (val->val1 == 0) { - result = gpio_pin_configure_dt(pwr_gpio, GPIO_OUTPUT_LOW); - result = gpio_pin_configure_dt(rst_gpio, GPIO_OUTPUT_LOW); - } else { - result = gpio_pin_configure_dt(pwr_gpio, GPIO_OUTPUT_HIGH); - result = gpio_pin_configure_dt(rst_gpio, GPIO_OUTPUT_HIGH); - } - break; - - case SENSOR_ATTR_CXD5605_CALLBACK: - init(dev); - LOG_DBG("Got CXD5605_ALERT_INTERRUPTS\n"); - cxd5605_setup_interrupts(dev); - /* setup shim callbacks */ -#ifdef DEBUG - printf("[driver] register driver callback\n"); -#endif - cxd5605_lib_init(dev); - cxd5605_register_resp_callback(dev, driver_cxd5605_resp_cb); - cxd5605_register_nmea_callback(dev, driver_cxd5605_nmea_cb); - return 0; - default: return -ENOTSUP; } - if (drv_data->cxd5605_cmd != SENSOR_ATTR_CXD5605_PWR_CTRL) { - result = cxd5605_wait_fetch(dev); - if (result < 0) { - return result; - } - } return 0; } @@ -684,6 +660,7 @@ static int cxd5605_driver_pm_action(const struct device *dev, { const struct cxd5605_config *config = dev->config; const struct gpio_dt_spec *rst_gpio = &config->rst_gpio; + struct cxd5605_data *drv_data = dev->data; int result = 0; @@ -699,6 +676,11 @@ static int cxd5605_driver_pm_action(const struct device *dev, if (result < 0) { printk("ERROR: I2C interface not working (CXD5605 driver)\n"); } + if (drv_data->pps_cb) { + cxd5605_pulse(dev, 1); + } + cxd5605_operating_mode(dev, drv_data->op_mode, drv_data->pos_cycle, drv_data->sleep_time); + cxd5605_sentence_select(dev, drv_data->selected_sentences); case PM_DEVICE_ACTION_SUSPEND: cxd5605_sleep(dev, 0); diff --git a/include/zephyr/drivers/sensor/cxd5605.h b/include/zephyr/drivers/sensor/cxd5605.h index b0992cb4b8b..7ac6c9d7248 100644 --- a/include/zephyr/drivers/sensor/cxd5605.h +++ b/include/zephyr/drivers/sensor/cxd5605.h @@ -56,7 +56,6 @@ enum sensor_attribute_cxd5605 { SENSOR_ATTR_CXD5605_SLEEP, SENSOR_ATTR_CXD5605_VERSION, SENSOR_ATTR_CXD5605_ASSIST_GEN_FUNCTION_CONTROL, - SENSOR_ATTR_CXD5605_PWR_CTRL, }; enum gga_nmea_fieldpos_t { @@ -167,6 +166,11 @@ struct cxd5605_data { bool got_data; bool lib_got_data; int command; + + uint32_t op_mode; + uint32_t pos_cycle; + uint32_t sleep_time; + uint32_t selected_sentences; }; /** a mask for the under temp alert bit in the status word*/