omap: remove old kernel versions
[openwrt/staging/dedeckeh.git] / target / linux / generic / patches-3.13 / 065-iio_ad799x_backport_fixes.patch
1 Backport essential fixes from 3.15
2
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!
9
10 Signed-off-by: Hartmut Knaack <knaack.h@gmx.de>
11 ---
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);
16 return IIO_VAL_INT;
17 case IIO_CHAN_INFO_SCALE:
18 - *val = st->int_vref_mv;
19 + ret = regulator_get_voltage(st->vref);
20 + if (ret < 0)
21 + return ret;
22 + *val = ret / 1000;
23 *val2 = chan->scan_type.realbits;
24 return IIO_VAL_FRACTIONAL_LOG2;
25 }
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)), \
31 + .scan_type = { \
32 + .sign = 'u', \
33 + .realbits = (_realbits), \
34 + .storagebits = 16, \
35 + .shift = 12 - (_realbits), \
36 + .endianness = IIO_BE, \
37 + }, \
38 .event_spec = _ev_spec, \
39 .num_event_specs = _num_ev_spec, \
40 }
41 @@ -527,7 +536,6 @@ static int ad799x_probe(struct i2c_clien
42 const struct i2c_device_id *id)
43 {
44 int ret;
45 - struct ad799x_platform_data *pdata = client->dev.platform_data;
46 struct ad799x_state *st;
47 struct iio_dev *indio_dev;
48
49 @@ -545,17 +553,21 @@ static int ad799x_probe(struct i2c_clien
50
51 /* TODO: Add pdata options for filtering and bit delay */
52
53 - if (!pdata)
54 - return -EINVAL;
55 -
56 - st->int_vref_mv = pdata->vref_mv;
57 -
58 st->reg = devm_regulator_get(&client->dev, "vcc");
59 - if (!IS_ERR(st->reg)) {
60 - ret = regulator_enable(st->reg);
61 - if (ret)
62 - return ret;
63 + if (IS_ERR(st->reg))
64 + return PTR_ERR(st->reg);
65 + ret = regulator_enable(st->reg);
66 + if (ret)
67 + return ret;
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;
72 }
73 + ret = regulator_enable(st->vref);
74 + if (ret)
75 + goto error_disable_reg;
76 +
77 st->client = client;
78
79 indio_dev->dev.parent = &client->dev;
80 @@ -568,7 +580,7 @@ static int ad799x_probe(struct i2c_clien
81
82 ret = ad799x_register_ring_funcs_and_init(indio_dev);
83 if (ret)
84 - goto error_disable_reg;
85 + goto error_disable_vref;
86
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);
91 error_cleanup_ring:
92 ad799x_ring_cleanup(indio_dev);
93 +error_disable_vref:
94 + regulator_disable(st->vref);
95 error_disable_reg:
96 - if (!IS_ERR(st->reg))
97 - regulator_disable(st->reg);
98 + regulator_disable(st->reg);
99
100 return ret;
101 }
102 @@ -609,8 +622,8 @@ static int ad799x_remove(struct i2c_clie
103 free_irq(client->irq, indio_dev);
104
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);
110 kfree(st->rx_buf);
111
112 return 0;
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;
119 - u16 int_vref_mv;
120 + struct regulator *vref;
121 unsigned id;
122 u16 config;
123
124 @@ -103,14 +103,6 @@ struct ad799x_state {
125 unsigned int transfer_size;
126 };
127
128 -/*
129 - * TODO: struct ad799x_platform_data needs to go into include/linux/iio
130 - */
131 -
132 -struct ad799x_platform_data {
133 - u16 vref_mv;
134 -};
135 -
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);