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

iio: temperature: mlx90632 Read sampling frequency

Allow users to read sensor sampling frequency to better plan the
application measurement requests.

Signed-off-by: Crt Mori <cmo@melexis.com>
Link: https://lore.kernel.org/r/0bd6d6d665b4bd39e4565f6f44cb1bdc03386e23.1663834141.git.cmo@melexis.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Crt Mori and committed by
Jonathan Cameron
eff07b20 2aebc223

+59
+59
drivers/iio/temperature/mlx90632.c
··· 81 81 #define MLX90632_PWR_STATUS_CONTINUOUS MLX90632_PWR_STATUS(3) /* continuous */ 82 82 83 83 #define MLX90632_EE_RR GENMASK(10, 8) /* Only Refresh Rate bits */ 84 + #define MLX90632_REFRESH_RATE(ee_val) FIELD_GET(MLX90632_EE_RR, ee_val) 85 + /* Extract Refresh Rate from ee register */ 86 + #define MLX90632_REFRESH_RATE_STATUS(refresh_rate) (refresh_rate << 8) 84 87 85 88 /* Measurement types */ 86 89 #define MLX90632_MTYP_MEDICAL 0 ··· 917 914 return ret; 918 915 } 919 916 917 + static int mlx90632_get_refresh_rate(struct mlx90632_data *data, 918 + int *refresh_rate) 919 + { 920 + unsigned int meas1; 921 + int ret; 922 + 923 + ret = regmap_read(data->regmap, MLX90632_EE_MEDICAL_MEAS1, &meas1); 924 + if (ret < 0) 925 + return ret; 926 + 927 + *refresh_rate = MLX90632_REFRESH_RATE(meas1); 928 + 929 + return ret; 930 + } 931 + 932 + static const int mlx90632_freqs[][2] = { 933 + {0, 500000}, 934 + {1, 0}, 935 + {2, 0}, 936 + {4, 0}, 937 + {8, 0}, 938 + {16, 0}, 939 + {32, 0}, 940 + {64, 0} 941 + }; 942 + 920 943 /** 921 944 * mlx90632_pm_interraction_wakeup() - Measure time between user interactions to change powermode 922 945 * @data: pointer to mlx90632_data object containing interaction_ts information ··· 1021 992 *val = data->object_ambient_temperature; 1022 993 ret = IIO_VAL_INT; 1023 994 break; 995 + case IIO_CHAN_INFO_SAMP_FREQ: 996 + ret = mlx90632_get_refresh_rate(data, &cr); 997 + if (ret < 0) 998 + goto mlx90632_read_raw_pm; 999 + 1000 + *val = mlx90632_freqs[cr][0]; 1001 + *val2 = mlx90632_freqs[cr][1]; 1002 + ret = IIO_VAL_INT_PLUS_MICRO; 1003 + break; 1024 1004 default: 1025 1005 ret = -EINVAL; 1026 1006 break; ··· 1063 1025 } 1064 1026 } 1065 1027 1028 + static int mlx90632_read_avail(struct iio_dev *indio_dev, 1029 + struct iio_chan_spec const *chan, 1030 + const int **vals, int *type, int *length, 1031 + long mask) 1032 + { 1033 + switch (mask) { 1034 + case IIO_CHAN_INFO_SAMP_FREQ: 1035 + *vals = (int *)mlx90632_freqs; 1036 + *type = IIO_VAL_INT_PLUS_MICRO; 1037 + *length = 2 * ARRAY_SIZE(mlx90632_freqs); 1038 + return IIO_AVAIL_LIST; 1039 + default: 1040 + return -EINVAL; 1041 + } 1042 + } 1043 + 1066 1044 static const struct iio_chan_spec mlx90632_channels[] = { 1067 1045 { 1068 1046 .type = IIO_TEMP, 1069 1047 .modified = 1, 1070 1048 .channel2 = IIO_MOD_TEMP_AMBIENT, 1071 1049 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), 1050 + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), 1051 + .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_SAMP_FREQ), 1072 1052 }, 1073 1053 { 1074 1054 .type = IIO_TEMP, ··· 1094 1038 .channel2 = IIO_MOD_TEMP_OBJECT, 1095 1039 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | 1096 1040 BIT(IIO_CHAN_INFO_CALIBEMISSIVITY) | BIT(IIO_CHAN_INFO_CALIBAMBIENT), 1041 + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), 1042 + .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_SAMP_FREQ), 1097 1043 }, 1098 1044 }; 1099 1045 1100 1046 static const struct iio_info mlx90632_info = { 1101 1047 .read_raw = mlx90632_read_raw, 1102 1048 .write_raw = mlx90632_write_raw, 1049 + .read_avail = mlx90632_read_avail, 1103 1050 }; 1104 1051 1105 1052 static void mlx90632_sleep(void *_data)