Skip to content

Commit 20cc0dd

Browse files
committed
Merge remote-tracking branch 'iio-thermal-5.11-rc1/ib-iio-thermal-5.11-rc1' into testing
2 parents c13636b + 24a7dc6 commit 20cc0dd

File tree

8 files changed

+240
-207
lines changed

8 files changed

+240
-207
lines changed

drivers/iio/adc/qcom-pm8xxx-xoadc.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* Author: Linus Walleij <[email protected]>
1111
*/
1212

13+
#include <linux/iio/adc/qcom-vadc-common.h>
1314
#include <linux/iio/iio.h>
1415
#include <linux/iio/sysfs.h>
1516
#include <linux/module.h>
@@ -21,8 +22,6 @@
2122
#include <linux/interrupt.h>
2223
#include <linux/regulator/consumer.h>
2324

24-
#include "qcom-vadc-common.h"
25-
2625
/*
2726
* Definitions for the "user processor" registers lifted from the v3.4
2827
* Qualcomm tree. Their kernel has two out-of-tree drivers for the ADC:

drivers/iio/adc/qcom-spmi-adc5.c

Lines changed: 14 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,20 @@
77
#include <linux/completion.h>
88
#include <linux/delay.h>
99
#include <linux/err.h>
10+
#include <linux/iio/adc/qcom-vadc-common.h>
1011
#include <linux/iio/iio.h>
1112
#include <linux/interrupt.h>
1213
#include <linux/kernel.h>
1314
#include <linux/log2.h>
1415
#include <linux/math64.h>
1516
#include <linux/module.h>
1617
#include <linux/of.h>
18+
#include <linux/of_device.h>
1719
#include <linux/platform_device.h>
1820
#include <linux/regmap.h>
1921
#include <linux/slab.h>
2022

2123
#include <dt-bindings/iio/qcom,spmi-vadc.h>
22-
#include "qcom-vadc-common.h"
2324

2425
#define ADC5_USR_REVISION1 0x0
2526
#define ADC5_USR_STATUS1 0x8
@@ -154,18 +155,6 @@ struct adc5_chip {
154155
const struct adc5_data *data;
155156
};
156157

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-
169158
static int adc5_read(struct adc5_chip *adc, u16 offset, u8 *data, int len)
170159
{
171160
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)
181170
return regmap_update_bits(adc->regmap, adc->base + offset, mask, val);
182171
}
183172

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-
233173
static int adc5_read_voltage_data(struct adc5_chip *adc, u16 *data)
234174
{
235175
int ret;
@@ -511,7 +451,7 @@ static int adc_read_raw_common(struct iio_dev *indio_dev,
511451
return ret;
512452

513453
ret = qcom_adc5_hw_scale(prop->scale_fn_type,
514-
&adc5_prescale_ratios[prop->prescale],
454+
prop->prescale,
515455
adc->data,
516456
adc_code_volt, val);
517457
if (ret)
@@ -717,7 +657,7 @@ static int adc5_get_dt_channel_data(struct adc5_chip *adc,
717657

718658
ret = of_property_read_u32(node, "qcom,decimation", &value);
719659
if (!ret) {
720-
ret = adc5_decimation_from_dt(value, data->decimation);
660+
ret = qcom_adc5_decimation_from_dt(value, data->decimation);
721661
if (ret < 0) {
722662
dev_err(dev, "%02x invalid decimation %d\n",
723663
chan, value);
@@ -730,7 +670,7 @@ static int adc5_get_dt_channel_data(struct adc5_chip *adc,
730670

731671
ret = of_property_read_u32_array(node, "qcom,pre-scaling", varr, 2);
732672
if (!ret) {
733-
ret = adc5_prescaling_from_dt(varr[0], varr[1]);
673+
ret = qcom_adc5_prescaling_from_dt(varr[0], varr[1]);
734674
if (ret < 0) {
735675
dev_err(dev, "%02x invalid pre-scaling <%d %d>\n",
736676
chan, varr[0], varr[1]);
@@ -759,11 +699,9 @@ static int adc5_get_dt_channel_data(struct adc5_chip *adc,
759699
if ((dig_version[0] >= ADC5_HW_SETTLE_DIFF_MINOR &&
760700
dig_version[1] >= ADC5_HW_SETTLE_DIFF_MAJOR) ||
761701
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);
764703
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);
767705

768706
if (ret < 0) {
769707
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,
777715

778716
ret = of_property_read_u32(node, "qcom,avg-samples", &value);
779717
if (!ret) {
780-
ret = adc5_avg_samples_from_dt(value);
718+
ret = qcom_adc5_avg_samples_from_dt(value);
781719
if (ret < 0) {
782720
dev_err(dev, "%02x invalid avg-samples %d\n",
783721
chan, value);
@@ -870,8 +808,6 @@ static int adc5_get_dt_data(struct adc5_chip *adc, struct device_node *node)
870808
struct adc5_channel_prop prop, *chan_props;
871809
struct device_node *child;
872810
unsigned int index = 0;
873-
const struct of_device_id *id;
874-
const struct adc5_data *data;
875811
int ret;
876812

877813
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)
890826

891827
chan_props = adc->chan_props;
892828
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;
899832

900833
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);
902835
if (ret) {
903836
of_node_put(child);
904837
return ret;
905838
}
906839

907840
prop.scale_fn_type =
908-
data->adc_chans[prop.channel].scale_fn_type;
841+
adc->data->adc_chans[prop.channel].scale_fn_type;
909842
*chan_props = prop;
910-
adc_chan = &data->adc_chans[prop.channel];
843+
adc_chan = &adc->data->adc_chans[prop.channel];
911844

912845
iio_chan->channel = prop.channel;
913846
iio_chan->datasheet_name = prop.datasheet_name;

drivers/iio/adc/qcom-spmi-vadc.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <linux/completion.h>
88
#include <linux/delay.h>
99
#include <linux/err.h>
10+
#include <linux/iio/adc/qcom-vadc-common.h>
1011
#include <linux/iio/iio.h>
1112
#include <linux/interrupt.h>
1213
#include <linux/kernel.h>
@@ -20,8 +21,6 @@
2021

2122
#include <dt-bindings/iio/qcom,spmi-vadc.h>
2223

23-
#include "qcom-vadc-common.h"
24-
2524
/* VADC register and bit definitions */
2625
#define VADC_REVISION2 0x1
2726
#define VADC_REVISION2_SUPPORTED_VADC 1

0 commit comments

Comments
 (0)