Skip to content

Commit dd9bd44

Browse files
Jakko3jic23
authored andcommitted
iio: magnetometer: yas530: Add volatile registers to "chip_info"
Add volatile registers to the "chip_info" structure to ease the handling of different YAS variants. Signed-off-by: Jakob Hauser <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Reviewed-by: Linus Walleij <[email protected]> Link: https://lore.kernel.org/r/aeba3877933ba9d2c920b459a9037d9186c15a4f.1660337264.git.jahau@rocketmail.com Signed-off-by: Jonathan Cameron <[email protected]>
1 parent a70f60e commit dd9bd44

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

drivers/iio/magnetometer/yamaha-yas530.c

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ enum chip_ids {
102102
yas533,
103103
};
104104

105+
static const int yas530_volatile_reg[] = {
106+
YAS530_ACTUATE_INIT_COIL,
107+
YAS530_MEASURE,
108+
};
109+
105110
struct yas5xx_calibration {
106111
/* Linearization calibration x, y1, y2 */
107112
s32 r[3];
@@ -123,11 +128,15 @@ struct yas5xx;
123128
* @devid: device ID number
124129
* @product_name: product name of the YAS variant
125130
* @version_names: version letters or namings
131+
* @volatile_reg: device-specific volatile registers
132+
* @volatile_reg_qty: quantity of device-specific volatile registers
126133
*/
127134
struct yas5xx_chip_info {
128135
unsigned int devid;
129136
char *product_name;
130137
char *version_names[2];
138+
const int *volatile_reg;
139+
int volatile_reg_qty;
131140
};
132141

133142
/**
@@ -616,9 +625,26 @@ static const struct iio_info yas5xx_info = {
616625

617626
static bool yas5xx_volatile_reg(struct device *dev, unsigned int reg)
618627
{
619-
return reg == YAS530_ACTUATE_INIT_COIL ||
620-
reg == YAS530_MEASURE ||
621-
(reg >= YAS5XX_MEASURE_DATA && reg < YAS5XX_MEASURE_DATA + 8);
628+
struct iio_dev *indio_dev = dev_get_drvdata(dev);
629+
struct yas5xx *yas5xx = iio_priv(indio_dev);
630+
const struct yas5xx_chip_info *ci = yas5xx->chip_info;
631+
int reg_qty;
632+
int i;
633+
634+
if (reg >= YAS5XX_MEASURE_DATA && reg < YAS5XX_MEASURE_DATA + 8)
635+
return true;
636+
637+
/*
638+
* YAS versions share different registers on the same address,
639+
* need to differentiate.
640+
*/
641+
reg_qty = ci->volatile_reg_qty;
642+
for (i = 0; i < reg_qty; i++) {
643+
if (reg == ci->volatile_reg[i])
644+
return true;
645+
}
646+
647+
return false;
622648
}
623649

624650
/* TODO: enable regmap cache, using mark dirty and sync at runtime resume */
@@ -923,16 +949,22 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = {
923949
.devid = YAS530_DEVICE_ID,
924950
.product_name = "YAS530 MS-3E",
925951
.version_names = { "A", "B" },
952+
.volatile_reg = yas530_volatile_reg,
953+
.volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg),
926954
},
927955
[yas532] = {
928956
.devid = YAS532_DEVICE_ID,
929957
.product_name = "YAS532 MS-3R",
930958
.version_names = { "AB", "AC" },
959+
.volatile_reg = yas530_volatile_reg,
960+
.volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg),
931961
},
932962
[yas533] = {
933963
.devid = YAS532_DEVICE_ID,
934964
.product_name = "YAS533 MS-3F",
935965
.version_names = { "AB", "AC" },
966+
.volatile_reg = yas530_volatile_reg,
967+
.volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg),
936968
},
937969
};
938970

0 commit comments

Comments
 (0)