1 Backport essential fixes from 3.15
3 From Linux 3.10 on this driver required platform data to load, which makes it
4 unusable in OpenWRT. This commit backports the following fixes:
5 * Move to regulator framework for scaling
6 * Set endianness of the ADC to Big endian
7 * Fix device-removal path
8 This commit should not be moved to newer kernel versions!
10 Signed-off-by: Hartmut Knaack <knaack.h@gmx.de>
12 --- a/drivers/staging/iio/adc/ad799x_core.c
13 +++ b/drivers/staging/iio/adc/ad799x_core.c
14 @@ -179,7 +179,10 @@ static int ad799x_read_raw(struct iio_de
15 RES_MASK(chan->scan_type.realbits);
17 case IIO_CHAN_INFO_SCALE:
18 - *val = st->int_vref_mv;
19 + ret = regulator_get_voltage(st->vref);
23 *val2 = chan->scan_type.realbits;
24 return IIO_VAL_FRACTIONAL_LOG2;
26 @@ -409,7 +412,13 @@ static const struct iio_event_spec ad799
27 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
28 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
29 .scan_index = (_index), \
30 - .scan_type = IIO_ST('u', _realbits, 16, 12 - (_realbits)), \
33 + .realbits = (_realbits), \
34 + .storagebits = 16, \
35 + .shift = 12 - (_realbits), \
36 + .endianness = IIO_BE, \
38 .event_spec = _ev_spec, \
39 .num_event_specs = _num_ev_spec, \
41 @@ -527,7 +536,6 @@ static int ad799x_probe(struct i2c_clien
42 const struct i2c_device_id *id)
45 - struct ad799x_platform_data *pdata = client->dev.platform_data;
46 struct ad799x_state *st;
47 struct iio_dev *indio_dev;
49 @@ -545,17 +553,21 @@ static int ad799x_probe(struct i2c_clien
51 /* TODO: Add pdata options for filtering and bit delay */
56 - st->int_vref_mv = pdata->vref_mv;
58 st->reg = devm_regulator_get(&client->dev, "vcc");
59 - if (!IS_ERR(st->reg)) {
60 - ret = regulator_enable(st->reg);
63 + if (IS_ERR(st->reg))
64 + return PTR_ERR(st->reg);
65 + ret = regulator_enable(st->reg);
68 + st->vref = devm_regulator_get(&client->dev, "vref");
69 + if (IS_ERR(st->vref)) {
70 + ret = PTR_ERR(st->vref);
71 + goto error_disable_reg;
73 + ret = regulator_enable(st->vref);
75 + goto error_disable_reg;
79 indio_dev->dev.parent = &client->dev;
80 @@ -568,7 +580,7 @@ static int ad799x_probe(struct i2c_clien
82 ret = ad799x_register_ring_funcs_and_init(indio_dev);
84 - goto error_disable_reg;
85 + goto error_disable_vref;
87 if (client->irq > 0) {
88 ret = request_threaded_irq(client->irq,
89 @@ -592,9 +604,10 @@ error_free_irq:
90 free_irq(client->irq, indio_dev);
92 ad799x_ring_cleanup(indio_dev);
94 + regulator_disable(st->vref);
96 - if (!IS_ERR(st->reg))
97 - regulator_disable(st->reg);
98 + regulator_disable(st->reg);
102 @@ -609,8 +622,8 @@ static int ad799x_remove(struct i2c_clie
103 free_irq(client->irq, indio_dev);
105 ad799x_ring_cleanup(indio_dev);
106 - if (!IS_ERR(st->reg))
107 - regulator_disable(st->reg);
108 + regulator_disable(st->vref);
109 + regulator_disable(st->reg);
113 --- a/drivers/staging/iio/adc/ad799x.h
114 +++ b/drivers/staging/iio/adc/ad799x.h
115 @@ -95,7 +95,7 @@ struct ad799x_state {
116 struct i2c_client *client;
117 const struct ad799x_chip_info *chip_info;
118 struct regulator *reg;
120 + struct regulator *vref;
124 @@ -103,14 +103,6 @@ struct ad799x_state {
125 unsigned int transfer_size;
129 - * TODO: struct ad799x_platform_data needs to go into include/linux/iio
132 -struct ad799x_platform_data {
136 #ifdef CONFIG_AD799X_RING_BUFFER
137 int ad799x_register_ring_funcs_and_init(struct iio_dev *indio_dev);
138 void ad799x_ring_cleanup(struct iio_dev *indio_dev);