drivers: sensor: Fix device instance const qualifier loss

It is necessary to wrap the device pointer into data.
Which was done already on most of them when global trigger is enabled.

Fixes #27399

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This commit is contained in:
Tomasz Bursztyka 2020-07-09 09:13:48 +02:00 committed by Carles Cufí
commit d00d86972a
76 changed files with 350 additions and 546 deletions

View file

@ -796,6 +796,8 @@ static int lsm6dso_init(const struct device *dev)
const struct lsm6dso_config * const config = dev->config;
struct lsm6dso_data *data = dev->data;
data->dev = dev;
data->bus = device_get_binding(config->bus_name);
if (!data->bus) {
LOG_DBG("master not found: %s",

View file

@ -138,6 +138,7 @@ struct lsm6dso_tf {
#define LSM6DSO_SHUB_MAX_NUM_SLVS 2
struct lsm6dso_data {
const struct device *dev;
const struct device *bus;
int16_t acc[3];
uint32_t acc_gain;
@ -177,7 +178,6 @@ struct lsm6dso_data {
sensor_trigger_handler_t handler_drdy_acc;
sensor_trigger_handler_t handler_drdy_gyr;
sensor_trigger_handler_t handler_drdy_temp;
const struct device *dev;
#if defined(CONFIG_LSM6DSO_TRIGGER_OWN_THREAD)
K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_LSM6DSO_THREAD_STACK_SIZE);

View file

@ -20,21 +20,19 @@
LOG_MODULE_DECLARE(LSM6DSO, CONFIG_SENSOR_LOG_LEVEL);
static int lsm6dso_i2c_read(const struct device *dev, uint8_t reg_addr,
static int lsm6dso_i2c_read(struct lsm6dso_data *data, uint8_t reg_addr,
uint8_t *value, uint8_t len)
{
struct lsm6dso_data *data = dev->data;
const struct lsm6dso_config *cfg = dev->config;
const struct lsm6dso_config *cfg = data->dev->config;
return i2c_burst_read(data->bus, cfg->i2c_slv_addr,
reg_addr, value, len);
}
static int lsm6dso_i2c_write(const struct device *dev, uint8_t reg_addr,
static int lsm6dso_i2c_write(struct lsm6dso_data *data, uint8_t reg_addr,
uint8_t *value, uint8_t len)
{
struct lsm6dso_data *data = dev->data;
const struct lsm6dso_config *cfg = dev->config;
const struct lsm6dso_config *cfg = data->dev->config;
return i2c_burst_write(data->bus, cfg->i2c_slv_addr,
reg_addr, value, len);
@ -48,7 +46,7 @@ int lsm6dso_i2c_init(const struct device *dev)
data->ctx_i2c.write_reg = (stmdev_write_ptr) lsm6dso_i2c_write,
data->ctx = &data->ctx_i2c;
data->ctx->handle = dev;
data->ctx->handle = data;
return 0;
}

View file

@ -20,11 +20,10 @@
LOG_MODULE_DECLARE(LSM6DSO, CONFIG_SENSOR_LOG_LEVEL);
static int lsm6dso_spi_read(const struct device *dev, uint8_t reg_addr,
static int lsm6dso_spi_read(struct lsm6dso_data *data, uint8_t reg_addr,
uint8_t *value, uint8_t len)
{
struct lsm6dso_data *data = dev->data;
const struct lsm6dso_config *cfg = dev->config;
const struct lsm6dso_config *cfg = data->dev->config;
const struct spi_config *spi_cfg = &cfg->spi_conf;
uint8_t buffer_tx[2] = { reg_addr | LSM6DSO_SPI_READ, 0 };
const struct spi_buf tx_buf = {
@ -62,11 +61,10 @@ static int lsm6dso_spi_read(const struct device *dev, uint8_t reg_addr,
return 0;
}
static int lsm6dso_spi_write(const struct device *dev, uint8_t reg_addr,
static int lsm6dso_spi_write(struct lsm6dso_data *data, uint8_t reg_addr,
uint8_t *value, uint8_t len)
{
struct lsm6dso_data *data = dev->data;
const struct lsm6dso_config *cfg = dev->config;
const struct lsm6dso_config *cfg = data->dev->config;
const struct spi_config *spi_cfg = &cfg->spi_conf;
uint8_t buffer_tx[1] = { reg_addr & ~LSM6DSO_SPI_READ };
const struct spi_buf tx_buf[2] = {
@ -104,7 +102,7 @@ int lsm6dso_spi_init(const struct device *dev)
data->ctx_spi.write_reg = (stmdev_write_ptr) lsm6dso_spi_write,
data->ctx = &data->ctx_spi;
data->ctx->handle = dev;
data->ctx->handle = data;
#if DT_INST_SPI_DEV_HAS_CS_GPIOS(0)
const struct lsm6dso_config *cfg = dev->config;

View file

@ -161,9 +161,8 @@ int lsm6dso_trigger_set(const struct device *dev,
* lsm6dso_handle_interrupt - handle the drdy event
* read data and call handler if registered any
*/
static void lsm6dso_handle_interrupt(void *arg)
static void lsm6dso_handle_interrupt(const struct device *dev)
{
const struct device *dev = arg;
struct lsm6dso_data *lsm6dso = dev->data;
struct sensor_trigger drdy_trigger = {
.type = SENSOR_TRIG_DATA_READY,
@ -224,16 +223,11 @@ static void lsm6dso_gpio_callback(const struct device *dev,
}
#ifdef CONFIG_LSM6DSO_TRIGGER_OWN_THREAD
static void lsm6dso_thread(int dev_ptr, int unused)
static void lsm6dso_thread(struct lsm6dso_data *lsm6dso)
{
const struct device *dev = INT_TO_POINTER(dev_ptr);
struct lsm6dso_data *lsm6dso = dev->data;
ARG_UNUSED(unused);
while (1) {
k_sem_take(&lsm6dso->gpio_sem, K_FOREVER);
lsm6dso_handle_interrupt(dev);
lsm6dso_handle_interrupt(lsm6dso->dev);
}
}
#endif /* CONFIG_LSM6DSO_TRIGGER_OWN_THREAD */
@ -261,15 +255,14 @@ int lsm6dso_init_interrupt(const struct device *dev)
cfg->int_gpio_port);
return -EINVAL;
}
lsm6dso->dev = dev;
#if defined(CONFIG_LSM6DSO_TRIGGER_OWN_THREAD)
k_sem_init(&lsm6dso->gpio_sem, 0, UINT_MAX);
k_thread_create(&lsm6dso->thread, lsm6dso->thread_stack,
CONFIG_LSM6DSO_THREAD_STACK_SIZE,
(k_thread_entry_t)lsm6dso_thread, dev,
0, NULL, K_PRIO_COOP(CONFIG_LSM6DSO_THREAD_PRIORITY),
(k_thread_entry_t)lsm6dso_thread, lsm6dso,
NULL, NULL, K_PRIO_COOP(CONFIG_LSM6DSO_THREAD_PRIORITY),
0, K_NO_WAIT);
#elif defined(CONFIG_LSM6DSO_TRIGGER_GLOBAL_THREAD)
lsm6dso->work.handler = lsm6dso_work_cb;