7
7
#include <linux/completion.h>
8
8
#include <linux/delay.h>
9
9
#include <linux/err.h>
10
+ #include <linux/iio/adc/qcom-vadc-common.h>
10
11
#include <linux/iio/iio.h>
11
12
#include <linux/interrupt.h>
12
13
#include <linux/kernel.h>
13
14
#include <linux/log2.h>
14
15
#include <linux/math64.h>
15
16
#include <linux/module.h>
16
17
#include <linux/of.h>
18
+ #include <linux/of_device.h>
17
19
#include <linux/platform_device.h>
18
20
#include <linux/regmap.h>
19
21
#include <linux/slab.h>
20
22
21
23
#include <dt-bindings/iio/qcom,spmi-vadc.h>
22
- #include "qcom-vadc-common.h"
23
24
24
25
#define ADC5_USR_REVISION1 0x0
25
26
#define ADC5_USR_STATUS1 0x8
@@ -154,18 +155,6 @@ struct adc5_chip {
154
155
const struct adc5_data * data ;
155
156
};
156
157
157
- static const struct vadc_prescale_ratio adc5_prescale_ratios [] = {
158
- {.num = 1 , .den = 1 },
159
- {.num = 1 , .den = 3 },
160
- {.num = 1 , .den = 4 },
161
- {.num = 1 , .den = 6 },
162
- {.num = 1 , .den = 20 },
163
- {.num = 1 , .den = 8 },
164
- {.num = 10 , .den = 81 },
165
- {.num = 1 , .den = 10 },
166
- {.num = 1 , .den = 16 }
167
- };
168
-
169
158
static int adc5_read (struct adc5_chip * adc , u16 offset , u8 * data , int len )
170
159
{
171
160
return regmap_bulk_read (adc -> regmap , adc -> base + offset , data , len );
@@ -181,55 +170,6 @@ static int adc5_masked_write(struct adc5_chip *adc, u16 offset, u8 mask, u8 val)
181
170
return regmap_update_bits (adc -> regmap , adc -> base + offset , mask , val );
182
171
}
183
172
184
- static int adc5_prescaling_from_dt (u32 num , u32 den )
185
- {
186
- unsigned int pre ;
187
-
188
- for (pre = 0 ; pre < ARRAY_SIZE (adc5_prescale_ratios ); pre ++ )
189
- if (adc5_prescale_ratios [pre ].num == num &&
190
- adc5_prescale_ratios [pre ].den == den )
191
- break ;
192
-
193
- if (pre == ARRAY_SIZE (adc5_prescale_ratios ))
194
- return - EINVAL ;
195
-
196
- return pre ;
197
- }
198
-
199
- static int adc5_hw_settle_time_from_dt (u32 value ,
200
- const unsigned int * hw_settle )
201
- {
202
- unsigned int i ;
203
-
204
- for (i = 0 ; i < VADC_HW_SETTLE_SAMPLES_MAX ; i ++ ) {
205
- if (value == hw_settle [i ])
206
- return i ;
207
- }
208
-
209
- return - EINVAL ;
210
- }
211
-
212
- static int adc5_avg_samples_from_dt (u32 value )
213
- {
214
- if (!is_power_of_2 (value ) || value > ADC5_AVG_SAMPLES_MAX )
215
- return - EINVAL ;
216
-
217
- return __ffs (value );
218
- }
219
-
220
- static int adc5_decimation_from_dt (u32 value ,
221
- const unsigned int * decimation )
222
- {
223
- unsigned int i ;
224
-
225
- for (i = 0 ; i < ADC5_DECIMATION_SAMPLES_MAX ; i ++ ) {
226
- if (value == decimation [i ])
227
- return i ;
228
- }
229
-
230
- return - EINVAL ;
231
- }
232
-
233
173
static int adc5_read_voltage_data (struct adc5_chip * adc , u16 * data )
234
174
{
235
175
int ret ;
@@ -511,7 +451,7 @@ static int adc_read_raw_common(struct iio_dev *indio_dev,
511
451
return ret ;
512
452
513
453
ret = qcom_adc5_hw_scale (prop -> scale_fn_type ,
514
- & adc5_prescale_ratios [ prop -> prescale ] ,
454
+ prop -> prescale ,
515
455
adc -> data ,
516
456
adc_code_volt , val );
517
457
if (ret )
@@ -717,7 +657,7 @@ static int adc5_get_dt_channel_data(struct adc5_chip *adc,
717
657
718
658
ret = of_property_read_u32 (node , "qcom,decimation" , & value );
719
659
if (!ret ) {
720
- ret = adc5_decimation_from_dt (value , data -> decimation );
660
+ ret = qcom_adc5_decimation_from_dt (value , data -> decimation );
721
661
if (ret < 0 ) {
722
662
dev_err (dev , "%02x invalid decimation %d\n" ,
723
663
chan , value );
@@ -730,7 +670,7 @@ static int adc5_get_dt_channel_data(struct adc5_chip *adc,
730
670
731
671
ret = of_property_read_u32_array (node , "qcom,pre-scaling" , varr , 2 );
732
672
if (!ret ) {
733
- ret = adc5_prescaling_from_dt (varr [0 ], varr [1 ]);
673
+ ret = qcom_adc5_prescaling_from_dt (varr [0 ], varr [1 ]);
734
674
if (ret < 0 ) {
735
675
dev_err (dev , "%02x invalid pre-scaling <%d %d>\n" ,
736
676
chan , varr [0 ], varr [1 ]);
@@ -759,11 +699,9 @@ static int adc5_get_dt_channel_data(struct adc5_chip *adc,
759
699
if ((dig_version [0 ] >= ADC5_HW_SETTLE_DIFF_MINOR &&
760
700
dig_version [1 ] >= ADC5_HW_SETTLE_DIFF_MAJOR ) ||
761
701
adc -> data -> info == & adc7_info )
762
- ret = adc5_hw_settle_time_from_dt (value ,
763
- data -> hw_settle_2 );
702
+ ret = qcom_adc5_hw_settle_time_from_dt (value , data -> hw_settle_2 );
764
703
else
765
- ret = adc5_hw_settle_time_from_dt (value ,
766
- data -> hw_settle_1 );
704
+ ret = qcom_adc5_hw_settle_time_from_dt (value , data -> hw_settle_1 );
767
705
768
706
if (ret < 0 ) {
769
707
dev_err (dev , "%02x invalid hw-settle-time %d us\n" ,
@@ -777,7 +715,7 @@ static int adc5_get_dt_channel_data(struct adc5_chip *adc,
777
715
778
716
ret = of_property_read_u32 (node , "qcom,avg-samples" , & value );
779
717
if (!ret ) {
780
- ret = adc5_avg_samples_from_dt (value );
718
+ ret = qcom_adc5_avg_samples_from_dt (value );
781
719
if (ret < 0 ) {
782
720
dev_err (dev , "%02x invalid avg-samples %d\n" ,
783
721
chan , value );
@@ -870,8 +808,6 @@ static int adc5_get_dt_data(struct adc5_chip *adc, struct device_node *node)
870
808
struct adc5_channel_prop prop , * chan_props ;
871
809
struct device_node * child ;
872
810
unsigned int index = 0 ;
873
- const struct of_device_id * id ;
874
- const struct adc5_data * data ;
875
811
int ret ;
876
812
877
813
adc -> nchannels = of_get_available_child_count (node );
@@ -890,24 +826,21 @@ static int adc5_get_dt_data(struct adc5_chip *adc, struct device_node *node)
890
826
891
827
chan_props = adc -> chan_props ;
892
828
iio_chan = adc -> iio_chans ;
893
- id = of_match_node (adc5_match_table , node );
894
- if (id )
895
- data = id -> data ;
896
- else
897
- data = & adc5_data_pmic ;
898
- adc -> data = data ;
829
+ adc -> data = of_device_get_match_data (adc -> dev );
830
+ if (!adc -> data )
831
+ adc -> data = & adc5_data_pmic ;
899
832
900
833
for_each_available_child_of_node (node , child ) {
901
- ret = adc5_get_dt_channel_data (adc , & prop , child , data );
834
+ ret = adc5_get_dt_channel_data (adc , & prop , child , adc -> data );
902
835
if (ret ) {
903
836
of_node_put (child );
904
837
return ret ;
905
838
}
906
839
907
840
prop .scale_fn_type =
908
- data -> adc_chans [prop .channel ].scale_fn_type ;
841
+ adc -> data -> adc_chans [prop .channel ].scale_fn_type ;
909
842
* chan_props = prop ;
910
- adc_chan = & data -> adc_chans [prop .channel ];
843
+ adc_chan = & adc -> data -> adc_chans [prop .channel ];
911
844
912
845
iio_chan -> channel = prop .channel ;
913
846
iio_chan -> datasheet_name = prop .datasheet_name ;
0 commit comments