From e0f06e23ef43be0fac60f6b54b191f380a9d5a07 Mon Sep 17 00:00:00 2001 From: Armando Visconti Date: Wed, 1 Sep 2021 15:53:46 +0200 Subject: [PATCH] drivers/sensor: lis2ds12: Move range Kconfig property into dts Converts lis2ds12 range options (2g, 4g, 8g, 16g) from Kconfig to Device Tree. Signed-off-by: Armando Visconti --- drivers/sensor/lis2ds12/Kconfig | 13 ------------- drivers/sensor/lis2ds12/lis2ds12.c | 7 +++++-- drivers/sensor/lis2ds12/lis2ds12.h | 1 + dts/bindings/sensor/st,lis2ds12-common.yaml | 13 +++++++++++++ 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/drivers/sensor/lis2ds12/Kconfig b/drivers/sensor/lis2ds12/Kconfig index 6e3aa8a5a72..9fc32c9b25e 100644 --- a/drivers/sensor/lis2ds12/Kconfig +++ b/drivers/sensor/lis2ds12/Kconfig @@ -57,19 +57,6 @@ config LIS2DS12_ENABLE_TEMP menu "Attributes" -config LIS2DS12_FS - int "Accelerometer full-scale range" - default 0 - help - Specify the default accelerometer full-scale range. - An X value for the config represents a range of +/- X G. Valid values - are: - 0: Full Scale selected at runtime - 2: +/- 2g - 4: +/- 4g - 8: +/- 8g - 16: +/- 16g - config LIS2DS12_ODR int "Accelerometer Output data rate frequency" range 0 10 diff --git a/drivers/sensor/lis2ds12/lis2ds12.c b/drivers/sensor/lis2ds12/lis2ds12.c index 61a39849143..bdfc1b38b92 100644 --- a/drivers/sensor/lis2ds12/lis2ds12.c +++ b/drivers/sensor/lis2ds12/lis2ds12.c @@ -258,9 +258,10 @@ static int lis2ds12_init(const struct device *dev) } /* set sensor default scale */ - ret = lis2ds12_set_range(dev, CONFIG_LIS2DS12_FS); + LOG_DBG("%s: range is %d", dev->name, cfg->range); + ret = lis2ds12_set_range(dev, cfg->range); if (ret < 0) { - LOG_ERR("%s: range init error %d", dev->name, CONFIG_LIS2DS12_FS); + LOG_ERR("%s: range init error %d", dev->name, cfg->range); return ret; } @@ -317,6 +318,7 @@ static int lis2ds12_init(const struct device *dev) LIS2DS12_SPI_OPERATION, \ 0), \ }, \ + .range = DT_INST_PROP(inst, range), \ COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, irq_gpios), \ (LIS2DS12_CFG_IRQ(inst)), ()) \ } @@ -338,6 +340,7 @@ static int lis2ds12_init(const struct device *dev) .stmemsc_cfg = { \ .i2c = I2C_DT_SPEC_INST_GET(inst), \ }, \ + .range = DT_INST_PROP(inst, range), \ COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, irq_gpios), \ (LIS2DS12_CFG_IRQ(inst)), ()) \ } diff --git a/drivers/sensor/lis2ds12/lis2ds12.h b/drivers/sensor/lis2ds12/lis2ds12.h index e1aca24492e..c2fc70e164f 100644 --- a/drivers/sensor/lis2ds12/lis2ds12.h +++ b/drivers/sensor/lis2ds12/lis2ds12.h @@ -40,6 +40,7 @@ struct lis2ds12_config { const struct spi_dt_spec spi; #endif } stmemsc_cfg; + uint8_t range; #ifdef CONFIG_LIS2DS12_TRIGGER struct gpio_dt_spec gpio_int; #endif diff --git a/dts/bindings/sensor/st,lis2ds12-common.yaml b/dts/bindings/sensor/st,lis2ds12-common.yaml index 5f3fd933d2a..83c21a2176e 100644 --- a/dts/bindings/sensor/st,lis2ds12-common.yaml +++ b/dts/bindings/sensor/st,lis2ds12-common.yaml @@ -11,3 +11,16 @@ properties: This pin defaults to active high when produced by the sensor. The property value should ensure the flags properly describe the signal that is presented to the driver. + + range: + type: int + required: false + default: 2 + description: | + Range in g. Default is power-up configuration. + + enum: + - 16 # 16g (0.488 mg/LSB) + - 8 # 8g (0.244 mg/LSB) + - 4 # 4g (0.122 mg/LSB) + - 2 # 2g (0.061 mg/LSB)