* [PATCH v2 0/3] Add ADXL359 support @ 2022-10-31 10:51 Ramona Bolboaca 2022-10-31 10:51 ` [PATCH v2 1/3] drivers: iio: accel: Use warning if invalid device id is detected Ramona Bolboaca ` (2 more replies) 0 siblings, 3 replies; 6+ messages in thread From: Ramona Bolboaca @ 2022-10-31 10:51 UTC (permalink / raw) To: jic23, robh+dt, krzysztof.kozlowski+dt, linux-iio, devicetree, linux-kernel Cc: Ramona Bolboaca Add support for ADXL359 device in existing ADXL355 driver. The digital output ADXL359 is a low noise density, low 0 g offset drift, low power, 3-axis microelectromechanical system (MEMS) accelerometer with selectable measurement ranges. The ADXL359 supports the ±10 g, ±20 g, and ±40 g ranges. Ramona Bolboaca (3): drivers: iio: accel: Use warning if invalid device id is detected dt-bindings: iio: accel: Add docs for ADXL359 drivers: iio: accel: Add support for ADXL359 device .../bindings/iio/accel/adi,adxl355.yaml | 8 +- drivers/iio/accel/adxl355.h | 21 ++++- drivers/iio/accel/adxl355_core.c | 91 ++++++++++++++----- drivers/iio/accel/adxl355_i2c.c | 22 ++++- drivers/iio/accel/adxl355_spi.c | 19 +++- 5 files changed, 127 insertions(+), 34 deletions(-) -- 2.25.1 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 1/3] drivers: iio: accel: Use warning if invalid device id is detected 2022-10-31 10:51 [PATCH v2 0/3] Add ADXL359 support Ramona Bolboaca @ 2022-10-31 10:51 ` Ramona Bolboaca 2022-10-31 10:51 ` [PATCH v2 2/3] dt-bindings: iio: accel: Add docs for ADXL359 Ramona Bolboaca 2022-10-31 10:51 ` [PATCH v2 3/3] drivers: iio: accel: Add support for ADXL359 device Ramona Bolboaca 2 siblings, 0 replies; 6+ messages in thread From: Ramona Bolboaca @ 2022-10-31 10:51 UTC (permalink / raw) To: jic23, robh+dt, krzysztof.kozlowski+dt, linux-iio, devicetree, linux-kernel Cc: Ramona Bolboaca Use warning instead of failing driver probe if invalid device id is detected for ADXL355 device. Signed-off-by: Ramona Bolboaca <ramona.bolboaca@analog.com> --- changes in v2: - new patch drivers/iio/accel/adxl355_core.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/iio/accel/adxl355_core.c b/drivers/iio/accel/adxl355_core.c index 4bc648eac8b2..dd08253d66d0 100644 --- a/drivers/iio/accel/adxl355_core.c +++ b/drivers/iio/accel/adxl355_core.c @@ -262,10 +262,8 @@ static int adxl355_setup(struct adxl355_data *data) if (ret) return ret; - if (regval != ADXL355_PARTID_VAL) { - dev_err(data->dev, "Invalid DEV ID 0x%02x\n", regval); - return -ENODEV; - } + if (regval != ADXL355_PARTID_VAL) + dev_warn(data->dev, "Invalid DEV ID 0x%02x\n", regval); /* * Perform a software reset to make sure the device is in a consistent -- 2.25.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 2/3] dt-bindings: iio: accel: Add docs for ADXL359 2022-10-31 10:51 [PATCH v2 0/3] Add ADXL359 support Ramona Bolboaca 2022-10-31 10:51 ` [PATCH v2 1/3] drivers: iio: accel: Use warning if invalid device id is detected Ramona Bolboaca @ 2022-10-31 10:51 ` Ramona Bolboaca 2022-11-02 15:58 ` Rob Herring 2022-10-31 10:51 ` [PATCH v2 3/3] drivers: iio: accel: Add support for ADXL359 device Ramona Bolboaca 2 siblings, 1 reply; 6+ messages in thread From: Ramona Bolboaca @ 2022-10-31 10:51 UTC (permalink / raw) To: jic23, robh+dt, krzysztof.kozlowski+dt, linux-iio, devicetree, linux-kernel Cc: Ramona Bolboaca Update ADXL355 existing documentation with documentation for ADXL359 device. Signed-off-by: Ramona Bolboaca <ramona.bolboaca@analog.com> --- changes in v2: - Added missing spaces in subject - Changed Accelerometer to Accelerometers - Fixed dedvice typo in commit message .../devicetree/bindings/iio/accel/adi,adxl355.yaml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Documentation/devicetree/bindings/iio/accel/adi,adxl355.yaml b/Documentation/devicetree/bindings/iio/accel/adi,adxl355.yaml index 14b487088ab4..6b03c4efbb08 100644 --- a/Documentation/devicetree/bindings/iio/accel/adi,adxl355.yaml +++ b/Documentation/devicetree/bindings/iio/accel/adi,adxl355.yaml @@ -4,20 +4,22 @@ $id: http://devicetree.org/schemas/iio/accel/adi,adxl355.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: Analog Devices ADXL355 3-Axis, Low noise MEMS Accelerometer +title: Analog Devices ADXL355 and ADXL359 3-Axis, Low noise MEMS Accelerometers maintainers: - Puranjay Mohan <puranjay12@gmail.com> description: | - Analog Devices ADXL355 3-Axis, Low noise MEMS Accelerometer that supports - both I2C & SPI interfaces + Analog Devices ADXL355 and ADXL359 3-Axis, Low noise MEMS Accelerometers that + support both I2C & SPI interfaces https://www.analog.com/en/products/adxl355.html + https://www.analog.com/en/products/adxl359.html properties: compatible: enum: - adi,adxl355 + - adi,adxl359 reg: maxItems: 1 -- 2.25.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 2/3] dt-bindings: iio: accel: Add docs for ADXL359 2022-10-31 10:51 ` [PATCH v2 2/3] dt-bindings: iio: accel: Add docs for ADXL359 Ramona Bolboaca @ 2022-11-02 15:58 ` Rob Herring 0 siblings, 0 replies; 6+ messages in thread From: Rob Herring @ 2022-11-02 15:58 UTC (permalink / raw) To: Ramona Bolboaca Cc: linux-kernel, jic23, robh+dt, krzysztof.kozlowski+dt, devicetree, linux-iio On Mon, 31 Oct 2022 12:51:28 +0200, Ramona Bolboaca wrote: > Update ADXL355 existing documentation with documentation > for ADXL359 device. > > Signed-off-by: Ramona Bolboaca <ramona.bolboaca@analog.com> > --- > changes in v2: > - Added missing spaces in subject > - Changed Accelerometer to Accelerometers > - Fixed dedvice typo in commit message > .../devicetree/bindings/iio/accel/adi,adxl355.yaml | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > Acked-by: Rob Herring <robh@kernel.org> ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 3/3] drivers: iio: accel: Add support for ADXL359 device 2022-10-31 10:51 [PATCH v2 0/3] Add ADXL359 support Ramona Bolboaca 2022-10-31 10:51 ` [PATCH v2 1/3] drivers: iio: accel: Use warning if invalid device id is detected Ramona Bolboaca 2022-10-31 10:51 ` [PATCH v2 2/3] dt-bindings: iio: accel: Add docs for ADXL359 Ramona Bolboaca @ 2022-10-31 10:51 ` Ramona Bolboaca 2022-11-06 12:56 ` Jonathan Cameron 2 siblings, 1 reply; 6+ messages in thread From: Ramona Bolboaca @ 2022-10-31 10:51 UTC (permalink / raw) To: jic23, robh+dt, krzysztof.kozlowski+dt, linux-iio, devicetree, linux-kernel Cc: Ramona Bolboaca Add support for ADXL359 device in already existing ADXL355 driver. Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/adxl359.pdf Signed-off-by: Ramona Bolboaca <ramona.bolboaca@analog.com> --- changes in v2: - Added missing spaces in subject - Added Datasheet tag in commit message - Removed type field from adxl355_chip_info - Added fields for acceleration scale and temperature offset in adxl355_chip_info structure - Added constant data for acceleration scale and temperature offset specific to each device in adxl35x_chip_info - Moved scale and offset documentation to adxl35x_chip_info definition - Moved device_get_match_data inside if (!chip_data) {} block drivers/iio/accel/adxl355.h | 21 +++++++- drivers/iio/accel/adxl355_core.c | 85 +++++++++++++++++++++++++------- drivers/iio/accel/adxl355_i2c.c | 22 +++++++-- drivers/iio/accel/adxl355_spi.c | 19 +++++-- 4 files changed, 120 insertions(+), 27 deletions(-) diff --git a/drivers/iio/accel/adxl355.h b/drivers/iio/accel/adxl355.h index 6dd49b13e4fd..3a08a1808e86 100644 --- a/drivers/iio/accel/adxl355.h +++ b/drivers/iio/accel/adxl355.h @@ -10,12 +10,31 @@ #include <linux/regmap.h> +enum adxl355_device_type { + ADXL355, + ADXL359, +}; + +struct adxl355_fractional_type { + int integer; + int decimal; +}; + struct device; +struct adxl355_chip_info { + const char *name; + u8 part_id; + struct adxl355_fractional_type accel_scale; + struct adxl355_fractional_type temp_offset; + +}; + extern const struct regmap_access_table adxl355_readable_regs_tbl; extern const struct regmap_access_table adxl355_writeable_regs_tbl; +extern const struct adxl355_chip_info adxl35x_chip_info[]; int adxl355_core_probe(struct device *dev, struct regmap *regmap, - const char *name); + const struct adxl355_chip_info *chip_info); #endif /* _ADXL355_H_ */ diff --git a/drivers/iio/accel/adxl355_core.c b/drivers/iio/accel/adxl355_core.c index dd08253d66d0..c501ad9af631 100644 --- a/drivers/iio/accel/adxl355_core.c +++ b/drivers/iio/accel/adxl355_core.c @@ -60,6 +60,7 @@ #define ADXL355_DEVID_AD_VAL 0xAD #define ADXL355_DEVID_MST_VAL 0x1D #define ADXL355_PARTID_VAL 0xED +#define ADXL359_PARTID_VAL 0xE9 #define ADXL355_RESET_CODE 0x52 static const struct regmap_range adxl355_read_reg_range[] = { @@ -83,6 +84,60 @@ const struct regmap_access_table adxl355_writeable_regs_tbl = { }; EXPORT_SYMBOL_NS_GPL(adxl355_writeable_regs_tbl, IIO_ADXL355); +const struct adxl355_chip_info adxl35x_chip_info[] = { + [ADXL355] = { + .name = "adxl355", + .part_id = ADXL355_PARTID_VAL, + /* + * At +/- 2g with 20-bit resolution, scale is given in datasheet + * as 3.9ug/LSB = 0.0000039 * 9.80665 = 0.00003824593 m/s^2. + */ + .accel_scale = { + .integer = 0, + .decimal = 38245, + }, + /* + * The datasheet defines an intercept of 1885 LSB at 25 degC + * and a slope of -9.05 LSB/C. The following formula can be used + * to find the temperature: + * Temp = ((RAW - 1885)/(-9.05)) + 25 but this doesn't follow + * the format of the IIO which is Temp = (RAW + OFFSET) * SCALE. + * Hence using some rearranging we get the scale as -110.497238 + * and offset as -2111.25. + */ + .temp_offset = { + .integer = -2111, + .decimal = 250000, + }, + }, + [ADXL359] = { + .name = "adxl359", + .part_id = ADXL359_PARTID_VAL, + /* + * At +/- 10g with 20-bit resolution, scale is given in datasheet + * as 19.5ug/LSB = 0.0000195 * 9.80665 = 0.0.00019122967 m/s^2. + */ + .accel_scale = { + .integer = 0, + .decimal = 191229, + }, + /* + * The datasheet defines an intercept of 1852 LSB at 25 degC + * and a slope of -9.05 LSB/C. The following formula can be used + * to find the temperature: + * Temp = ((RAW - 1852)/(-9.05)) + 25 but this doesn't follow + * the format of the IIO which is Temp = (RAW + OFFSET) * SCALE. + * Hence using some rearranging we get the scale as -110.497238 + * and offset as -2079.25. + */ + .temp_offset = { + .integer = -2079, + .decimal = 250000, + }, + }, +}; +EXPORT_SYMBOL_NS_GPL(adxl35x_chip_info, IIO_ADXL355); + enum adxl355_op_mode { ADXL355_MEASUREMENT, ADXL355_STANDBY, @@ -162,6 +217,7 @@ static const struct adxl355_chan_info adxl355_chans[] = { }; struct adxl355_data { + const struct adxl355_chip_info *chip_info; struct regmap *regmap; struct device *dev; struct mutex lock; /* lock to protect op_mode */ @@ -456,33 +512,23 @@ static int adxl355_read_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_SCALE: switch (chan->type) { - /* - * The datasheet defines an intercept of 1885 LSB at 25 degC - * and a slope of -9.05 LSB/C. The following formula can be used - * to find the temperature: - * Temp = ((RAW - 1885)/(-9.05)) + 25 but this doesn't follow - * the format of the IIO which is Temp = (RAW + OFFSET) * SCALE. - * Hence using some rearranging we get the scale as -110.497238 - * and offset as -2111.25. - */ case IIO_TEMP: + /* Temperature scale is -110.497238. + * See the detailed explanation in adxl35x_chip_info definition above. + */ *val = -110; *val2 = 497238; return IIO_VAL_INT_PLUS_MICRO; - /* - * At +/- 2g with 20-bit resolution, scale is given in datasheet - * as 3.9ug/LSB = 0.0000039 * 9.80665 = 0.00003824593 m/s^2. - */ case IIO_ACCEL: - *val = 0; - *val2 = 38245; + *val = data->chip_info->accel_scale.integer; + *val2 = data->chip_info->accel_scale.decimal; return IIO_VAL_INT_PLUS_NANO; default: return -EINVAL; } case IIO_CHAN_INFO_OFFSET: - *val = -2111; - *val2 = 250000; + *val = data->chip_info->temp_offset.integer; + *val2 = data->chip_info->temp_offset.decimal; return IIO_VAL_INT_PLUS_MICRO; case IIO_CHAN_INFO_CALIBBIAS: *val = sign_extend32(data->calibbias[chan->address], 15); @@ -705,7 +751,7 @@ static int adxl355_probe_trigger(struct iio_dev *indio_dev, int irq) } int adxl355_core_probe(struct device *dev, struct regmap *regmap, - const char *name) + const struct adxl355_chip_info *chip_info) { struct adxl355_data *data; struct iio_dev *indio_dev; @@ -720,9 +766,10 @@ int adxl355_core_probe(struct device *dev, struct regmap *regmap, data->regmap = regmap; data->dev = dev; data->op_mode = ADXL355_STANDBY; + data->chip_info = chip_info; mutex_init(&data->lock); - indio_dev->name = name; + indio_dev->name = chip_info->name; indio_dev->info = &adxl355_info; indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->channels = adxl355_channels; diff --git a/drivers/iio/accel/adxl355_i2c.c b/drivers/iio/accel/adxl355_i2c.c index f67d57921c81..6cde5ccac06b 100644 --- a/drivers/iio/accel/adxl355_i2c.c +++ b/drivers/iio/accel/adxl355_i2c.c @@ -23,6 +23,20 @@ static const struct regmap_config adxl355_i2c_regmap_config = { static int adxl355_i2c_probe(struct i2c_client *client) { struct regmap *regmap; + const struct adxl355_chip_info *chip_data; + const struct i2c_device_id *adxl355; + + chip_data = device_get_match_data(&client->dev); + if (!chip_data) { + adxl355 = to_i2c_driver(client->dev.driver)->id_table; + if (!adxl355) + return -EINVAL; + + chip_data = (void *)i2c_match_id(adxl355, client)->driver_data; + + if (!chip_data) + return -EINVAL; + } regmap = devm_regmap_init_i2c(client, &adxl355_i2c_regmap_config); if (IS_ERR(regmap)) { @@ -32,17 +46,19 @@ static int adxl355_i2c_probe(struct i2c_client *client) return PTR_ERR(regmap); } - return adxl355_core_probe(&client->dev, regmap, client->name); + return adxl355_core_probe(&client->dev, regmap, chip_data); } static const struct i2c_device_id adxl355_i2c_id[] = { - { "adxl355", 0 }, + { "adxl355", (kernel_ulong_t)&adxl35x_chip_info[ADXL355] }, + { "adxl359", (kernel_ulong_t)&adxl35x_chip_info[ADXL359] }, { } }; MODULE_DEVICE_TABLE(i2c, adxl355_i2c_id); static const struct of_device_id adxl355_of_match[] = { - { .compatible = "adi,adxl355" }, + { .compatible = "adi,adxl355", .data = &adxl35x_chip_info[ADXL355] }, + { .compatible = "adi,adxl359", .data = &adxl35x_chip_info[ADXL359] }, { } }; MODULE_DEVICE_TABLE(of, adxl355_of_match); diff --git a/drivers/iio/accel/adxl355_spi.c b/drivers/iio/accel/adxl355_spi.c index 5fe986ae03f6..fc99534d91ff 100644 --- a/drivers/iio/accel/adxl355_spi.c +++ b/drivers/iio/accel/adxl355_spi.c @@ -9,6 +9,7 @@ #include <linux/mod_devicetable.h> #include <linux/regmap.h> #include <linux/spi/spi.h> +#include <linux/property.h> #include "adxl355.h" @@ -24,9 +25,17 @@ static const struct regmap_config adxl355_spi_regmap_config = { static int adxl355_spi_probe(struct spi_device *spi) { - const struct spi_device_id *id = spi_get_device_id(spi); + const struct adxl355_chip_info *chip_data; struct regmap *regmap; + chip_data = device_get_match_data(&spi->dev); + if (!chip_data) { + chip_data = (void *)spi_get_device_id(spi)->driver_data; + + if (!chip_data) + return -EINVAL; + } + regmap = devm_regmap_init_spi(spi, &adxl355_spi_regmap_config); if (IS_ERR(regmap)) { dev_err(&spi->dev, "Error initializing spi regmap: %ld\n", @@ -35,17 +44,19 @@ static int adxl355_spi_probe(struct spi_device *spi) return PTR_ERR(regmap); } - return adxl355_core_probe(&spi->dev, regmap, id->name); + return adxl355_core_probe(&spi->dev, regmap, chip_data); } static const struct spi_device_id adxl355_spi_id[] = { - { "adxl355", 0 }, + { "adxl355", (kernel_ulong_t)&adxl35x_chip_info[ADXL355] }, + { "adxl359", (kernel_ulong_t)&adxl35x_chip_info[ADXL359] }, { } }; MODULE_DEVICE_TABLE(spi, adxl355_spi_id); static const struct of_device_id adxl355_of_match[] = { - { .compatible = "adi,adxl355" }, + { .compatible = "adi,adxl355", .data = &adxl35x_chip_info[ADXL355] }, + { .compatible = "adi,adxl359", .data = &adxl35x_chip_info[ADXL359] }, { } }; MODULE_DEVICE_TABLE(of, adxl355_of_match); -- 2.25.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 3/3] drivers: iio: accel: Add support for ADXL359 device 2022-10-31 10:51 ` [PATCH v2 3/3] drivers: iio: accel: Add support for ADXL359 device Ramona Bolboaca @ 2022-11-06 12:56 ` Jonathan Cameron 0 siblings, 0 replies; 6+ messages in thread From: Jonathan Cameron @ 2022-11-06 12:56 UTC (permalink / raw) To: Ramona Bolboaca Cc: robh+dt, krzysztof.kozlowski+dt, linux-iio, devicetree, linux-kernel On Mon, 31 Oct 2022 12:51:29 +0200 Ramona Bolboaca <ramona.bolboaca@analog.com> wrote: > Add support for ADXL359 device in already existing ADXL355 driver. > > Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/adxl359.pdf > Signed-off-by: Ramona Bolboaca <ramona.bolboaca@analog.com> A few really small things I tweaked whilst applying. Series applied to the togreg branch of iio.git and initially pushed out as testing for 0-day to see if it can find anything we missed. Thanks, Jonathan > --- > changes in v2: > - Added missing spaces in subject > - Added Datasheet tag in commit message > - Removed type field from adxl355_chip_info > - Added fields for acceleration scale and temperature offset in > adxl355_chip_info structure > - Added constant data for acceleration scale and temperature offset specific > to each device in adxl35x_chip_info > - Moved scale and offset documentation to adxl35x_chip_info definition > - Moved device_get_match_data inside if (!chip_data) {} block > drivers/iio/accel/adxl355.h | 21 +++++++- > drivers/iio/accel/adxl355_core.c | 85 +++++++++++++++++++++++++------- > drivers/iio/accel/adxl355_i2c.c | 22 +++++++-- > drivers/iio/accel/adxl355_spi.c | 19 +++++-- > 4 files changed, 120 insertions(+), 27 deletions(-) > > diff --git a/drivers/iio/accel/adxl355.h b/drivers/iio/accel/adxl355.h > index 6dd49b13e4fd..3a08a1808e86 100644 > --- a/drivers/iio/accel/adxl355.h > +++ b/drivers/iio/accel/adxl355.h > @@ -10,12 +10,31 @@ > > #include <linux/regmap.h> > > +enum adxl355_device_type { > + ADXL355, > + ADXL359, > +}; > + > +struct adxl355_fractional_type { > + int integer; > + int decimal; > +}; > + > struct device; > > +struct adxl355_chip_info { > + const char *name; > + u8 part_id; > + struct adxl355_fractional_type accel_scale; > + struct adxl355_fractional_type temp_offset; > + No blank line here. > +}; > + > extern const struct regmap_access_table adxl355_readable_regs_tbl; > extern const struct regmap_access_table adxl355_writeable_regs_tbl; > +extern const struct adxl355_chip_info adxl35x_chip_info[]; > > int adxl355_core_probe(struct device *dev, struct regmap *regmap, > - const char *name); > + const struct adxl355_chip_info *chip_info); > > #endif /* _ADXL355_H_ */ > diff --git a/drivers/iio/accel/adxl355_core.c b/drivers/iio/accel/adxl355_core.c > index dd08253d66d0..c501ad9af631 100644 > --- a/drivers/iio/accel/adxl355_core.c > +++ b/drivers/iio/accel/adxl355_core.c > @@ -60,6 +60,7 @@ > #define ADXL355_DEVID_AD_VAL 0xAD > #define ADXL355_DEVID_MST_VAL 0x1D > #define ADXL355_PARTID_VAL 0xED > +#define ADXL359_PARTID_VAL 0xE9 > #define ADXL355_RESET_CODE 0x52 > > static const struct regmap_range adxl355_read_reg_range[] = { > @@ -83,6 +84,60 @@ const struct regmap_access_table adxl355_writeable_regs_tbl = { > }; > EXPORT_SYMBOL_NS_GPL(adxl355_writeable_regs_tbl, IIO_ADXL355); > > +const struct adxl355_chip_info adxl35x_chip_info[] = { > + [ADXL355] = { > + .name = "adxl355", > + .part_id = ADXL355_PARTID_VAL, > + /* > + * At +/- 2g with 20-bit resolution, scale is given in datasheet > + * as 3.9ug/LSB = 0.0000039 * 9.80665 = 0.00003824593 m/s^2. > + */ > + .accel_scale = { > + .integer = 0, > + .decimal = 38245, > + }, > + /* > + * The datasheet defines an intercept of 1885 LSB at 25 degC > + * and a slope of -9.05 LSB/C. The following formula can be used > + * to find the temperature: > + * Temp = ((RAW - 1885)/(-9.05)) + 25 but this doesn't follow > + * the format of the IIO which is Temp = (RAW + OFFSET) * SCALE. > + * Hence using some rearranging we get the scale as -110.497238 > + * and offset as -2111.25. > + */ > + .temp_offset = { > + .integer = -2111, > + .decimal = 250000, > + }, > + }, > + [ADXL359] = { > + .name = "adxl359", > + .part_id = ADXL359_PARTID_VAL, > + /* > + * At +/- 10g with 20-bit resolution, scale is given in datasheet > + * as 19.5ug/LSB = 0.0000195 * 9.80665 = 0.0.00019122967 m/s^2. > + */ > + .accel_scale = { > + .integer = 0, > + .decimal = 191229, > + }, > + /* > + * The datasheet defines an intercept of 1852 LSB at 25 degC > + * and a slope of -9.05 LSB/C. The following formula can be used > + * to find the temperature: > + * Temp = ((RAW - 1852)/(-9.05)) + 25 but this doesn't follow > + * the format of the IIO which is Temp = (RAW + OFFSET) * SCALE. > + * Hence using some rearranging we get the scale as -110.497238 > + * and offset as -2079.25. > + */ > + .temp_offset = { > + .integer = -2079, > + .decimal = 250000, > + }, > + }, > +}; > +EXPORT_SYMBOL_NS_GPL(adxl35x_chip_info, IIO_ADXL355); > + > enum adxl355_op_mode { > ADXL355_MEASUREMENT, > ADXL355_STANDBY, > @@ -162,6 +217,7 @@ static const struct adxl355_chan_info adxl355_chans[] = { > }; > > struct adxl355_data { > + const struct adxl355_chip_info *chip_info; > struct regmap *regmap; > struct device *dev; > struct mutex lock; /* lock to protect op_mode */ > @@ -456,33 +512,23 @@ static int adxl355_read_raw(struct iio_dev *indio_dev, > > case IIO_CHAN_INFO_SCALE: > switch (chan->type) { > - /* > - * The datasheet defines an intercept of 1885 LSB at 25 degC > - * and a slope of -9.05 LSB/C. The following formula can be used > - * to find the temperature: > - * Temp = ((RAW - 1885)/(-9.05)) + 25 but this doesn't follow > - * the format of the IIO which is Temp = (RAW + OFFSET) * SCALE. > - * Hence using some rearranging we get the scale as -110.497238 > - * and offset as -2111.25. > - */ > case IIO_TEMP: > + /* Temperature scale is -110.497238. Wrong comment syntax for IIO... > + * See the detailed explanation in adxl35x_chip_info definition above. > + */ ... > diff --git a/drivers/iio/accel/adxl355_i2c.c b/drivers/iio/accel/adxl355_i2c.c > index f67d57921c81..6cde5ccac06b 100644 > --- a/drivers/iio/accel/adxl355_i2c.c > +++ b/drivers/iio/accel/adxl355_i2c.c > @@ -23,6 +23,20 @@ static const struct regmap_config adxl355_i2c_regmap_config = { > static int adxl355_i2c_probe(struct i2c_client *client) > { > struct regmap *regmap; > + const struct adxl355_chip_info *chip_data; > + const struct i2c_device_id *adxl355; > + > + chip_data = device_get_match_data(&client->dev); > + if (!chip_data) { > + adxl355 = to_i2c_driver(client->dev.driver)->id_table; > + if (!adxl355) > + return -EINVAL; > + > + chip_data = (void *)i2c_match_id(adxl355, client)->driver_data; Will will shortly have a nice function to wrap this up in a similar fashion to done for spi_get_device_id() > + > + if (!chip_data) > + return -EINVAL; > + } ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-11-06 12:57 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2022-10-31 10:51 [PATCH v2 0/3] Add ADXL359 support Ramona Bolboaca 2022-10-31 10:51 ` [PATCH v2 1/3] drivers: iio: accel: Use warning if invalid device id is detected Ramona Bolboaca 2022-10-31 10:51 ` [PATCH v2 2/3] dt-bindings: iio: accel: Add docs for ADXL359 Ramona Bolboaca 2022-11-02 15:58 ` Rob Herring 2022-10-31 10:51 ` [PATCH v2 3/3] drivers: iio: accel: Add support for ADXL359 device Ramona Bolboaca 2022-11-06 12:56 ` Jonathan Cameron
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.