Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <jahau@rocketmail.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Link: https://lore.kernel.org/r/aeba3877933ba9d2c920b459a9037d9186c15a4f.1660337264.git.jahau@rocketmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Jakob Hauser and committed by
Jonathan Cameron
dd9bd44f a70f60e5

+35 -3
+35 -3
drivers/iio/magnetometer/yamaha-yas530.c
··· 102 102 yas533, 103 103 }; 104 104 105 + static const int yas530_volatile_reg[] = { 106 + YAS530_ACTUATE_INIT_COIL, 107 + YAS530_MEASURE, 108 + }; 109 + 105 110 struct yas5xx_calibration { 106 111 /* Linearization calibration x, y1, y2 */ 107 112 s32 r[3]; ··· 128 123 * @devid: device ID number 129 124 * @product_name: product name of the YAS variant 130 125 * @version_names: version letters or namings 126 + * @volatile_reg: device-specific volatile registers 127 + * @volatile_reg_qty: quantity of device-specific volatile registers 131 128 */ 132 129 struct yas5xx_chip_info { 133 130 unsigned int devid; 134 131 char *product_name; 135 132 char *version_names[2]; 133 + const int *volatile_reg; 134 + int volatile_reg_qty; 136 135 }; 137 136 138 137 /** ··· 625 616 626 617 static bool yas5xx_volatile_reg(struct device *dev, unsigned int reg) 627 618 { 628 - return reg == YAS530_ACTUATE_INIT_COIL || 629 - reg == YAS530_MEASURE || 630 - (reg >= YAS5XX_MEASURE_DATA && reg < YAS5XX_MEASURE_DATA + 8); 619 + struct iio_dev *indio_dev = dev_get_drvdata(dev); 620 + struct yas5xx *yas5xx = iio_priv(indio_dev); 621 + const struct yas5xx_chip_info *ci = yas5xx->chip_info; 622 + int reg_qty; 623 + int i; 624 + 625 + if (reg >= YAS5XX_MEASURE_DATA && reg < YAS5XX_MEASURE_DATA + 8) 626 + return true; 627 + 628 + /* 629 + * YAS versions share different registers on the same address, 630 + * need to differentiate. 631 + */ 632 + reg_qty = ci->volatile_reg_qty; 633 + for (i = 0; i < reg_qty; i++) { 634 + if (reg == ci->volatile_reg[i]) 635 + return true; 636 + } 637 + 638 + return false; 631 639 } 632 640 633 641 /* TODO: enable regmap cache, using mark dirty and sync at runtime resume */ ··· 949 923 .devid = YAS530_DEVICE_ID, 950 924 .product_name = "YAS530 MS-3E", 951 925 .version_names = { "A", "B" }, 926 + .volatile_reg = yas530_volatile_reg, 927 + .volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg), 952 928 }, 953 929 [yas532] = { 954 930 .devid = YAS532_DEVICE_ID, 955 931 .product_name = "YAS532 MS-3R", 956 932 .version_names = { "AB", "AC" }, 933 + .volatile_reg = yas530_volatile_reg, 934 + .volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg), 957 935 }, 958 936 [yas533] = { 959 937 .devid = YAS532_DEVICE_ID, 960 938 .product_name = "YAS533 MS-3F", 961 939 .version_names = { "AB", "AC" }, 940 + .volatile_reg = yas530_volatile_reg, 941 + .volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg), 962 942 }, 963 943 }; 964 944