@@ -131,6 +131,11 @@ struct yas5xx;
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.
@@ -147,12 +152,17 @@ struct yas5xx_chip_info {
147
152
u32 scaling_val2 ;
148
153
u16 t_ref ;
149
154
s16 min_temp_x10 ;
155
+ int (* get_measure )(struct yas5xx * yas5xx , s32 * to , s32 * xo , s32 * yo , s32 * zo );
156
+ int (* get_calibration_data )(struct yas5xx * yas5xx );
157
+ void (* dump_calibration )(struct yas5xx * yas5xx );
158
+ int (* measure_offsets )(struct yas5xx * yas5xx );
159
+ int (* power_on )(struct yas5xx * yas5xx );
150
160
};
151
161
152
162
/**
153
163
* struct yas5xx - state container for the YAS5xx driver
154
164
* @dev: parent device pointer
155
- * @chip_info: device-specific data
165
+ * @chip_info: device-specific data and function pointers
156
166
* @version: device version
157
167
* @calibration: calibration settings from the OTP storage
158
168
* @hard_offsets: offsets for each axis measured with initcoil actuated
@@ -461,7 +471,7 @@ static int yas5xx_read_raw(struct iio_dev *indio_dev,
461
471
case IIO_CHAN_INFO_PROCESSED :
462
472
case IIO_CHAN_INFO_RAW :
463
473
pm_runtime_get_sync (yas5xx -> dev );
464
- ret = yas530_get_measure (yas5xx , & t , & x , & y , & z );
474
+ ret = ci -> get_measure (yas5xx , & t , & x , & y , & z );
465
475
pm_runtime_mark_last_busy (yas5xx -> dev );
466
476
pm_runtime_put_autosuspend (yas5xx -> dev );
467
477
if (ret )
@@ -497,11 +507,12 @@ static int yas5xx_read_raw(struct iio_dev *indio_dev,
497
507
static void yas5xx_fill_buffer (struct iio_dev * indio_dev )
498
508
{
499
509
struct yas5xx * yas5xx = iio_priv (indio_dev );
510
+ const struct yas5xx_chip_info * ci = yas5xx -> chip_info ;
500
511
s32 t , x , y , z ;
501
512
int ret ;
502
513
503
514
pm_runtime_get_sync (yas5xx -> dev );
504
- ret = yas530_get_measure (yas5xx , & t , & x , & y , & z );
515
+ ret = ci -> get_measure (yas5xx , & t , & x , & y , & z );
505
516
pm_runtime_mark_last_busy (yas5xx -> dev );
506
517
pm_runtime_put_autosuspend (yas5xx -> dev );
507
518
if (ret ) {
@@ -916,6 +927,11 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = {
916
927
.scaling_val2 = 100000000 , /* picotesla to Gauss */
917
928
.t_ref = 182 , /* counts */
918
929
.min_temp_x10 = -620 , /* 1/10:s degrees Celsius */
930
+ .get_measure = yas530_get_measure ,
931
+ .get_calibration_data = yas530_get_calibration_data ,
932
+ .dump_calibration = yas530_dump_calibration ,
933
+ .measure_offsets = yas530_measure_offsets ,
934
+ .power_on = yas530_power_on ,
919
935
},
920
936
[yas532 ] = {
921
937
.devid = YAS532_DEVICE_ID ,
@@ -926,6 +942,11 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = {
926
942
.scaling_val2 = 100000 , /* nanotesla to Gauss */
927
943
.t_ref = 390 , /* counts */
928
944
.min_temp_x10 = -500 , /* 1/10:s degrees Celsius */
945
+ .get_measure = yas530_get_measure ,
946
+ .get_calibration_data = yas532_get_calibration_data ,
947
+ .dump_calibration = yas530_dump_calibration ,
948
+ .measure_offsets = yas530_measure_offsets ,
949
+ .power_on = yas530_power_on ,
929
950
},
930
951
[yas533 ] = {
931
952
.devid = YAS532_DEVICE_ID ,
@@ -936,6 +957,11 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = {
936
957
.scaling_val2 = 100000 , /* nanotesla to Gauss */
937
958
.t_ref = 390 , /* counts */
938
959
.min_temp_x10 = -500 , /* 1/10:s degrees Celsius */
960
+ .get_measure = yas530_get_measure ,
961
+ .get_calibration_data = yas532_get_calibration_data ,
962
+ .dump_calibration = yas530_dump_calibration ,
963
+ .measure_offsets = yas530_measure_offsets ,
964
+ .power_on = yas530_power_on ,
939
965
},
940
966
};
941
967
@@ -1007,34 +1033,25 @@ static int yas5xx_probe(struct i2c_client *i2c,
1007
1033
goto assert_reset ;
1008
1034
}
1009
1035
1010
- switch (ci -> devid ) {
1011
- case YAS530_DEVICE_ID :
1012
- ret = yas530_get_calibration_data (yas5xx );
1013
- if (ret )
1014
- goto assert_reset ;
1015
- break ;
1016
- case YAS532_DEVICE_ID :
1017
- ret = yas532_get_calibration_data (yas5xx );
1018
- if (ret )
1019
- goto assert_reset ;
1020
- break ;
1021
- default :
1022
- ret = - ENODEV ;
1023
- dev_err (dev , "unhandled device ID %02x\n" , ci -> devid );
1036
+ ret = ci -> get_calibration_data (yas5xx );
1037
+ if (ret )
1024
1038
goto assert_reset ;
1025
- }
1026
1039
1027
1040
dev_info (dev , "detected %s %s\n" , ci -> product_name ,
1028
1041
ci -> version_names [yas5xx -> version ]);
1029
1042
1030
- yas530_dump_calibration (yas5xx );
1031
- ret = yas530_power_on (yas5xx );
1032
- if (ret )
1033
- goto assert_reset ;
1034
- ret = yas530_measure_offsets (yas5xx );
1043
+ ci -> dump_calibration (yas5xx );
1044
+
1045
+ ret = ci -> power_on (yas5xx );
1035
1046
if (ret )
1036
1047
goto assert_reset ;
1037
1048
1049
+ if (ci -> measure_offsets ) {
1050
+ ret = ci -> measure_offsets (yas5xx );
1051
+ if (ret )
1052
+ goto assert_reset ;
1053
+ }
1054
+
1038
1055
indio_dev -> info = & yas5xx_info ;
1039
1056
indio_dev -> available_scan_masks = yas5xx_scan_masks ;
1040
1057
indio_dev -> modes = INDIO_DIRECT_MODE ;
@@ -1114,6 +1131,7 @@ static int yas5xx_runtime_resume(struct device *dev)
1114
1131
{
1115
1132
struct iio_dev * indio_dev = dev_get_drvdata (dev );
1116
1133
struct yas5xx * yas5xx = iio_priv (indio_dev );
1134
+ const struct yas5xx_chip_info * ci = yas5xx -> chip_info ;
1117
1135
int ret ;
1118
1136
1119
1137
ret = regulator_bulk_enable (ARRAY_SIZE (yas5xx -> regs ), yas5xx -> regs );
@@ -1130,7 +1148,7 @@ static int yas5xx_runtime_resume(struct device *dev)
1130
1148
usleep_range (31000 , 40000 );
1131
1149
gpiod_set_value_cansleep (yas5xx -> reset , 0 );
1132
1150
1133
- ret = yas530_power_on (yas5xx );
1151
+ ret = ci -> power_on (yas5xx );
1134
1152
if (ret ) {
1135
1153
dev_err (dev , "cannot power on\n" );
1136
1154
goto out_reset ;
0 commit comments