Message ID | aa1936a9e3687cb9d112232b87db8a9f9e1a7ffa.1659909060.git.jahau@rocketmail.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | Add support for magnetometer Yamaha YAS537 | expand |
On Mon, Aug 8, 2022 at 1:07 AM Jakob Hauser <jahau@rocketmail.com> wrote: > > Add volatile registers to the "chip_info" structure to ease the handling of > different YAS variants. Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> > Signed-off-by: Jakob Hauser <jahau@rocketmail.com> > --- > drivers/iio/magnetometer/yamaha-yas530.c | 37 ++++++++++++++++++++++-- > 1 file changed, 34 insertions(+), 3 deletions(-) > > diff --git a/drivers/iio/magnetometer/yamaha-yas530.c b/drivers/iio/magnetometer/yamaha-yas530.c > index ecc2b61a5c4f..914f7f0a243e 100644 > --- a/drivers/iio/magnetometer/yamaha-yas530.c > +++ b/drivers/iio/magnetometer/yamaha-yas530.c > @@ -114,6 +114,11 @@ static const char * const yas5xx_version_names[][2] = { > [yas533] = { "AB", "AC" }, > }; > > +static const int yas530_volatile_reg[] = { > + YAS530_ACTUATE_INIT_COIL, > + YAS530_MEASURE, > +}; > + > struct yas5xx_calibration { > /* Linearization calibration x, y1, y2 */ > s32 r[3]; > @@ -135,11 +140,15 @@ struct yas5xx; > * @devid: device ID number > * @product_name: product name of the YAS variant > * @version_name: version letter or naming > + * @volatile_reg: device-specific volatile registers > + * @volatile_reg_qty: quantity of device-specific volatile registers > */ > struct yas5xx_chip_info { > unsigned int devid; > const char *product_name; > const char * const *version_name; > + const int *volatile_reg; > + int volatile_reg_qty; > }; > > /** > @@ -626,9 +635,25 @@ static const struct iio_info yas5xx_info = { > > static bool yas5xx_volatile_reg(struct device *dev, unsigned int reg) > { > - return reg == YAS530_ACTUATE_INIT_COIL || > - reg == YAS530_MEASURE || > - (reg >= YAS5XX_MEASURE_DATA && reg < YAS5XX_MEASURE_DATA + 8); > + struct iio_dev *indio_dev = dev_get_drvdata(dev); > + struct yas5xx *yas5xx = iio_priv(indio_dev); > + int reg_qty; > + int i; > + > + if (reg >= YAS5XX_MEASURE_DATA && reg < YAS5XX_MEASURE_DATA + 8) > + return true; > + > + /* > + * YAS versions share different registers on the same address, > + * need to differentiate. > + */ > + reg_qty = yas5xx->chip_info->volatile_reg_qty; > + for (i = 0; i < reg_qty; i++) { > + if (reg == yas5xx->chip_info->volatile_reg[i]) > + return true; > + } > + > + return false; > } > > /* TODO: enable regmap cache, using mark dirty and sync at runtime resume */ > @@ -932,16 +957,22 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = { > .devid = YAS530_DEVICE_ID, > .product_name = yas5xx_product_name[yas530], > .version_name = yas5xx_version_names[yas530], > + .volatile_reg = yas530_volatile_reg, > + .volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg), > }, > [yas532] = { > .devid = YAS532_DEVICE_ID, > .product_name = yas5xx_product_name[yas532], > .version_name = yas5xx_version_names[yas532], > + .volatile_reg = yas530_volatile_reg, > + .volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg), > }, > [yas533] = { > .devid = YAS532_DEVICE_ID, > .product_name = yas5xx_product_name[yas533], > .version_name = yas5xx_version_names[yas533], > + .volatile_reg = yas530_volatile_reg, > + .volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg), > }, > }; > > -- > 2.35.1 >
diff --git a/drivers/iio/magnetometer/yamaha-yas530.c b/drivers/iio/magnetometer/yamaha-yas530.c index ecc2b61a5c4f..914f7f0a243e 100644 --- a/drivers/iio/magnetometer/yamaha-yas530.c +++ b/drivers/iio/magnetometer/yamaha-yas530.c @@ -114,6 +114,11 @@ static const char * const yas5xx_version_names[][2] = { [yas533] = { "AB", "AC" }, }; +static const int yas530_volatile_reg[] = { + YAS530_ACTUATE_INIT_COIL, + YAS530_MEASURE, +}; + struct yas5xx_calibration { /* Linearization calibration x, y1, y2 */ s32 r[3]; @@ -135,11 +140,15 @@ struct yas5xx; * @devid: device ID number * @product_name: product name of the YAS variant * @version_name: version letter or naming + * @volatile_reg: device-specific volatile registers + * @volatile_reg_qty: quantity of device-specific volatile registers */ struct yas5xx_chip_info { unsigned int devid; const char *product_name; const char * const *version_name; + const int *volatile_reg; + int volatile_reg_qty; }; /** @@ -626,9 +635,25 @@ static const struct iio_info yas5xx_info = { static bool yas5xx_volatile_reg(struct device *dev, unsigned int reg) { - return reg == YAS530_ACTUATE_INIT_COIL || - reg == YAS530_MEASURE || - (reg >= YAS5XX_MEASURE_DATA && reg < YAS5XX_MEASURE_DATA + 8); + struct iio_dev *indio_dev = dev_get_drvdata(dev); + struct yas5xx *yas5xx = iio_priv(indio_dev); + int reg_qty; + int i; + + if (reg >= YAS5XX_MEASURE_DATA && reg < YAS5XX_MEASURE_DATA + 8) + return true; + + /* + * YAS versions share different registers on the same address, + * need to differentiate. + */ + reg_qty = yas5xx->chip_info->volatile_reg_qty; + for (i = 0; i < reg_qty; i++) { + if (reg == yas5xx->chip_info->volatile_reg[i]) + return true; + } + + return false; } /* TODO: enable regmap cache, using mark dirty and sync at runtime resume */ @@ -932,16 +957,22 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = { .devid = YAS530_DEVICE_ID, .product_name = yas5xx_product_name[yas530], .version_name = yas5xx_version_names[yas530], + .volatile_reg = yas530_volatile_reg, + .volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg), }, [yas532] = { .devid = YAS532_DEVICE_ID, .product_name = yas5xx_product_name[yas532], .version_name = yas5xx_version_names[yas532], + .volatile_reg = yas530_volatile_reg, + .volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg), }, [yas533] = { .devid = YAS532_DEVICE_ID, .product_name = yas5xx_product_name[yas533], .version_name = yas5xx_version_names[yas533], + .volatile_reg = yas530_volatile_reg, + .volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg), }, };
Add volatile registers to the "chip_info" structure to ease the handling of different YAS variants. Signed-off-by: Jakob Hauser <jahau@rocketmail.com> --- drivers/iio/magnetometer/yamaha-yas530.c | 37 ++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-)