41506f96917ae95b9f218b69ef88a0eb175eddb2
[openwrt/openwrt.git] / target / linux / generic / patches-3.14 / 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 * Fix device-removal path
7 This commit should not be moved to newer kernel versions!
8
9 Signed-off-by: Hartmut Knaack <knaack.h@gmx.de>
10 ---
11 --- a/drivers/staging/iio/adc/ad799x_core.c
12 +++ b/drivers/staging/iio/adc/ad799x_core.c
13 @@ -179,7 +179,10 @@ static int ad799x_read_raw(struct iio_de
14 RES_MASK(chan->scan_type.realbits);
15 return IIO_VAL_INT;
16 case IIO_CHAN_INFO_SCALE:
17 - *val = st->int_vref_mv;
18 + ret = regulator_get_voltage(st->vref);
19 + if (ret < 0)
20 + return ret;
21 + *val = ret / 1000;
22 *val2 = chan->scan_type.realbits;
23 return IIO_VAL_FRACTIONAL_LOG2;
24 }
25 @@ -533,7 +536,6 @@ static int ad799x_probe(struct i2c_clien
26 const struct i2c_device_id *id)
27 {
28 int ret;
29 - struct ad799x_platform_data *pdata = client->dev.platform_data;
30 struct ad799x_state *st;
31 struct iio_dev *indio_dev;
32
33 @@ -551,17 +553,21 @@ static int ad799x_probe(struct i2c_clien
34
35 /* TODO: Add pdata options for filtering and bit delay */
36
37 - if (!pdata)
38 - return -EINVAL;
39 -
40 - st->int_vref_mv = pdata->vref_mv;
41 -
42 st->reg = devm_regulator_get(&client->dev, "vcc");
43 - if (!IS_ERR(st->reg)) {
44 - ret = regulator_enable(st->reg);
45 - if (ret)
46 - return ret;
47 + if (IS_ERR(st->reg))
48 + return PTR_ERR(st->reg);
49 + ret = regulator_enable(st->reg);
50 + if (ret)
51 + return ret;
52 + st->vref = devm_regulator_get(&client->dev, "vref");
53 + if (IS_ERR(st->vref)) {
54 + ret = PTR_ERR(st->vref);
55 + goto error_disable_reg;
56 }
57 + ret = regulator_enable(st->vref);
58 + if (ret)
59 + goto error_disable_reg;
60 +
61 st->client = client;
62
63 indio_dev->dev.parent = &client->dev;
64 @@ -574,7 +580,7 @@ static int ad799x_probe(struct i2c_clien
65
66 ret = ad799x_register_ring_funcs_and_init(indio_dev);
67 if (ret)
68 - goto error_disable_reg;
69 + goto error_disable_vref;
70
71 if (client->irq > 0) {
72 ret = request_threaded_irq(client->irq,
73 @@ -598,9 +604,10 @@ error_free_irq:
74 free_irq(client->irq, indio_dev);
75 error_cleanup_ring:
76 ad799x_ring_cleanup(indio_dev);
77 +error_disable_vref:
78 + regulator_disable(st->vref);
79 error_disable_reg:
80 - if (!IS_ERR(st->reg))
81 - regulator_disable(st->reg);
82 + regulator_disable(st->reg);
83
84 return ret;
85 }
86 @@ -615,8 +622,8 @@ static int ad799x_remove(struct i2c_clie
87 free_irq(client->irq, indio_dev);
88
89 ad799x_ring_cleanup(indio_dev);
90 - if (!IS_ERR(st->reg))
91 - regulator_disable(st->reg);
92 + regulator_disable(st->vref);
93 + regulator_disable(st->reg);
94 kfree(st->rx_buf);
95
96 return 0;
97 --- a/drivers/staging/iio/adc/ad799x.h
98 +++ b/drivers/staging/iio/adc/ad799x.h
99 @@ -95,7 +95,7 @@ struct ad799x_state {
100 struct i2c_client *client;
101 const struct ad799x_chip_info *chip_info;
102 struct regulator *reg;
103 - u16 int_vref_mv;
104 + struct regulator *vref;
105 unsigned id;
106 u16 config;
107
108 @@ -103,14 +103,6 @@ struct ad799x_state {
109 unsigned int transfer_size;
110 };
111
112 -/*
113 - * TODO: struct ad799x_platform_data needs to go into include/linux/iio
114 - */
115 -
116 -struct ad799x_platform_data {
117 - u16 vref_mv;
118 -};
119 -
120 #ifdef CONFIG_AD799X_RING_BUFFER
121 int ad799x_register_ring_funcs_and_init(struct iio_dev *indio_dev);
122 void ad799x_ring_cleanup(struct iio_dev *indio_dev);