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 function pointers to "chip_info"

Add function pointers to the "chip_info" structure to ease the handling of
different YAS variants.

In the function yas5xx_probe(), the function call for "measure_offsets" was
added as a conditional "if (ci->measure_offsets)". This is a preparatory step
for YAS537, as this variant doesn't need an offset measurement.

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/4bd3f96262e0132b7f9720521a801da3c18abd95.1660337264.git.jahau@rocketmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Jakob Hauser and committed by
Jonathan Cameron
059ff0f9 2d6676ec

+42 -24
+42 -24
drivers/iio/magnetometer/yamaha-yas530.c
··· 131 131 * @scaling_val2: scaling value for IIO_CHAN_INFO_SCALE 132 132 * @t_ref: number of counts at reference temperature 20 °C 133 133 * @min_temp_x10: starting point of temperature counting in 1/10:s degrees Celsius 134 + * @get_measure: function pointer to get a measurement 135 + * @get_calibration_data: function pointer to get calibration data 136 + * @dump_calibration: function pointer to dump calibration for debugging 137 + * @measure_offsets: function pointer to measure the offsets 138 + * @power_on: function pointer to power-on procedure 134 139 * 135 140 * The "t_ref" value for YAS532/533 is known from the Android driver. 136 141 * For YAS530 it was approximately measured. ··· 152 147 u32 scaling_val2; 153 148 u16 t_ref; 154 149 s16 min_temp_x10; 150 + int (*get_measure)(struct yas5xx *yas5xx, s32 *to, s32 *xo, s32 *yo, s32 *zo); 151 + int (*get_calibration_data)(struct yas5xx *yas5xx); 152 + void (*dump_calibration)(struct yas5xx *yas5xx); 153 + int (*measure_offsets)(struct yas5xx *yas5xx); 154 + int (*power_on)(struct yas5xx *yas5xx); 155 155 }; 156 156 157 157 /** 158 158 * struct yas5xx - state container for the YAS5xx driver 159 159 * @dev: parent device pointer 160 - * @chip_info: device-specific data 160 + * @chip_info: device-specific data and function pointers 161 161 * @version: device version 162 162 * @calibration: calibration settings from the OTP storage 163 163 * @hard_offsets: offsets for each axis measured with initcoil actuated ··· 471 461 case IIO_CHAN_INFO_PROCESSED: 472 462 case IIO_CHAN_INFO_RAW: 473 463 pm_runtime_get_sync(yas5xx->dev); 474 - ret = yas530_get_measure(yas5xx, &t, &x, &y, &z); 464 + ret = ci->get_measure(yas5xx, &t, &x, &y, &z); 475 465 pm_runtime_mark_last_busy(yas5xx->dev); 476 466 pm_runtime_put_autosuspend(yas5xx->dev); 477 467 if (ret) ··· 507 497 static void yas5xx_fill_buffer(struct iio_dev *indio_dev) 508 498 { 509 499 struct yas5xx *yas5xx = iio_priv(indio_dev); 500 + const struct yas5xx_chip_info *ci = yas5xx->chip_info; 510 501 s32 t, x, y, z; 511 502 int ret; 512 503 513 504 pm_runtime_get_sync(yas5xx->dev); 514 - ret = yas530_get_measure(yas5xx, &t, &x, &y, &z); 505 + ret = ci->get_measure(yas5xx, &t, &x, &y, &z); 515 506 pm_runtime_mark_last_busy(yas5xx->dev); 516 507 pm_runtime_put_autosuspend(yas5xx->dev); 517 508 if (ret) { ··· 927 916 .scaling_val2 = 100000000, /* picotesla to Gauss */ 928 917 .t_ref = 182, /* counts */ 929 918 .min_temp_x10 = -620, /* 1/10:s degrees Celsius */ 919 + .get_measure = yas530_get_measure, 920 + .get_calibration_data = yas530_get_calibration_data, 921 + .dump_calibration = yas530_dump_calibration, 922 + .measure_offsets = yas530_measure_offsets, 923 + .power_on = yas530_power_on, 930 924 }, 931 925 [yas532] = { 932 926 .devid = YAS532_DEVICE_ID, ··· 942 926 .scaling_val2 = 100000, /* nanotesla to Gauss */ 943 927 .t_ref = 390, /* counts */ 944 928 .min_temp_x10 = -500, /* 1/10:s degrees Celsius */ 929 + .get_measure = yas530_get_measure, 930 + .get_calibration_data = yas532_get_calibration_data, 931 + .dump_calibration = yas530_dump_calibration, 932 + .measure_offsets = yas530_measure_offsets, 933 + .power_on = yas530_power_on, 945 934 }, 946 935 [yas533] = { 947 936 .devid = YAS532_DEVICE_ID, ··· 957 936 .scaling_val2 = 100000, /* nanotesla to Gauss */ 958 937 .t_ref = 390, /* counts */ 959 938 .min_temp_x10 = -500, /* 1/10:s degrees Celsius */ 939 + .get_measure = yas530_get_measure, 940 + .get_calibration_data = yas532_get_calibration_data, 941 + .dump_calibration = yas530_dump_calibration, 942 + .measure_offsets = yas530_measure_offsets, 943 + .power_on = yas530_power_on, 960 944 }, 961 945 }; 962 946 ··· 1033 1007 goto assert_reset; 1034 1008 } 1035 1009 1036 - switch (ci->devid) { 1037 - case YAS530_DEVICE_ID: 1038 - ret = yas530_get_calibration_data(yas5xx); 1039 - if (ret) 1040 - goto assert_reset; 1041 - break; 1042 - case YAS532_DEVICE_ID: 1043 - ret = yas532_get_calibration_data(yas5xx); 1044 - if (ret) 1045 - goto assert_reset; 1046 - break; 1047 - default: 1048 - ret = -ENODEV; 1049 - dev_err(dev, "unhandled device ID %02x\n", ci->devid); 1010 + ret = ci->get_calibration_data(yas5xx); 1011 + if (ret) 1050 1012 goto assert_reset; 1051 - } 1052 1013 1053 1014 dev_info(dev, "detected %s %s\n", ci->product_name, 1054 1015 ci->version_names[yas5xx->version]); 1055 1016 1056 - yas530_dump_calibration(yas5xx); 1057 - ret = yas530_power_on(yas5xx); 1017 + ci->dump_calibration(yas5xx); 1018 + 1019 + ret = ci->power_on(yas5xx); 1058 1020 if (ret) 1059 1021 goto assert_reset; 1060 - ret = yas530_measure_offsets(yas5xx); 1061 - if (ret) 1062 - goto assert_reset; 1022 + 1023 + if (ci->measure_offsets) { 1024 + ret = ci->measure_offsets(yas5xx); 1025 + if (ret) 1026 + goto assert_reset; 1027 + } 1063 1028 1064 1029 indio_dev->info = &yas5xx_info; 1065 1030 indio_dev->available_scan_masks = yas5xx_scan_masks; ··· 1131 1114 { 1132 1115 struct iio_dev *indio_dev = dev_get_drvdata(dev); 1133 1116 struct yas5xx *yas5xx = iio_priv(indio_dev); 1117 + const struct yas5xx_chip_info *ci = yas5xx->chip_info; 1134 1118 int ret; 1135 1119 1136 1120 ret = regulator_bulk_enable(ARRAY_SIZE(yas5xx->regs), yas5xx->regs); ··· 1148 1130 usleep_range(31000, 40000); 1149 1131 gpiod_set_value_cansleep(yas5xx->reset, 0); 1150 1132 1151 - ret = yas530_power_on(yas5xx); 1133 + ret = ci->power_on(yas5xx); 1152 1134 if (ret) { 1153 1135 dev_err(dev, "cannot power on\n"); 1154 1136 goto out_reset;