odhcpd: send current hop-limit by default in RAs
[openwrt.git] / target / linux / generic / patches-3.10 / 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 @@ -163,7 +163,6 @@ static int ad799x_read_raw(struct iio_de
15  {
16         int ret;
17         struct ad799x_state *st = iio_priv(indio_dev);
18 -       unsigned int scale_uv;
19  
20         switch (m) {
21         case IIO_CHAN_INFO_RAW:
22 @@ -180,10 +179,12 @@ static int ad799x_read_raw(struct iio_de
23                         RES_MASK(chan->scan_type.realbits);
24                 return IIO_VAL_INT;
25         case IIO_CHAN_INFO_SCALE:
26 -               scale_uv = (st->int_vref_mv * 1000) >> chan->scan_type.realbits;
27 -               *val =  scale_uv / 1000;
28 -               *val2 = (scale_uv % 1000) * 1000;
29 -               return IIO_VAL_INT_PLUS_MICRO;
30 +               ret = regulator_get_voltage(st->vref);
31 +               if (ret < 0)
32 +                       return ret;
33 +               *val =  ret / 1000;
34 +               *val2 = chan->scan_type.realbits;
35 +               return IIO_VAL_FRACTIONAL_LOG2;
36         }
37         return -EINVAL;
38  }
39 @@ -474,7 +475,13 @@ static const struct iio_info ad7993_4_7_
40         .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
41         .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
42         .scan_index = (_index), \
43 -       .scan_type = IIO_ST('u', _realbits, 16, 12 - (_realbits)), \
44 +       .scan_type = { \
45 +               .sign = 'u', \
46 +               .realbits = (_realbits), \
47 +               .storagebits = 16, \
48 +               .shift = 12 - (_realbits), \
49 +               .endianness = IIO_BE, \
50 +               }, \
51         .event_mask = (_evmask), \
52  }
53  
54 @@ -584,7 +591,6 @@ static int ad799x_probe(struct i2c_clien
55                                    const struct i2c_device_id *id)
56  {
57         int ret;
58 -       struct ad799x_platform_data *pdata = client->dev.platform_data;
59         struct ad799x_state *st;
60         struct iio_dev *indio_dev = iio_device_alloc(sizeof(*st));
61  
62 @@ -601,17 +607,21 @@ static int ad799x_probe(struct i2c_clien
63  
64         /* TODO: Add pdata options for filtering and bit delay */
65  
66 -       if (!pdata)
67 -               return -EINVAL;
68 -
69 -       st->int_vref_mv = pdata->vref_mv;
70 -
71 -       st->reg = regulator_get(&client->dev, "vcc");
72 -       if (!IS_ERR(st->reg)) {
73 -               ret = regulator_enable(st->reg);
74 -               if (ret)
75 -                       goto error_put_reg;
76 +       st->reg = devm_regulator_get(&client->dev, "vcc");
77 +       if (IS_ERR(st->reg))
78 +               return PTR_ERR(st->reg);
79 +       ret = regulator_enable(st->reg);
80 +       if (ret)
81 +               return ret;
82 +       st->vref = devm_regulator_get(&client->dev, "vref");
83 +       if (IS_ERR(st->vref)) {
84 +               ret = PTR_ERR(st->vref);
85 +               goto error_disable_reg;
86         }
87 +       ret = regulator_enable(st->vref);
88 +       if (ret)
89 +               goto error_disable_reg;
90 +
91         st->client = client;
92  
93         indio_dev->dev.parent = &client->dev;
94 @@ -624,7 +634,7 @@ static int ad799x_probe(struct i2c_clien
95  
96         ret = ad799x_register_ring_funcs_and_init(indio_dev);
97         if (ret)
98 -               goto error_disable_reg;
99 +               goto error_disable_vref;
100  
101         if (client->irq > 0) {
102                 ret = request_threaded_irq(client->irq,
103 @@ -648,12 +658,10 @@ error_free_irq:
104                 free_irq(client->irq, indio_dev);
105  error_cleanup_ring:
106         ad799x_ring_cleanup(indio_dev);
107 +error_disable_vref:
108 +       regulator_disable(st->vref);
109  error_disable_reg:
110 -       if (!IS_ERR(st->reg))
111 -               regulator_disable(st->reg);
112 -error_put_reg:
113 -       if (!IS_ERR(st->reg))
114 -               regulator_put(st->reg);
115 +       regulator_disable(st->reg);
116         iio_device_free(indio_dev);
117  
118         return ret;
119 @@ -669,10 +677,8 @@ static int ad799x_remove(struct i2c_clie
120                 free_irq(client->irq, indio_dev);
121  
122         ad799x_ring_cleanup(indio_dev);
123 -       if (!IS_ERR(st->reg)) {
124 -               regulator_disable(st->reg);
125 -               regulator_put(st->reg);
126 -       }
127 +       regulator_disable(st->vref);
128 +       regulator_disable(st->reg);
129         kfree(st->rx_buf);
130         iio_device_free(indio_dev);
131  
132 --- a/drivers/staging/iio/adc/ad799x.h
133 +++ b/drivers/staging/iio/adc/ad799x.h
134 @@ -103,7 +103,7 @@ struct ad799x_state {
135         struct i2c_client               *client;
136         const struct ad799x_chip_info   *chip_info;
137         struct regulator                *reg;
138 -       u16                             int_vref_mv;
139 +       struct regulator                *vref;
140         unsigned                        id;
141         u16                             config;
142  
143 @@ -111,14 +111,6 @@ struct ad799x_state {
144         unsigned int                    transfer_size;
145  };
146  
147 -/*
148 - * TODO: struct ad799x_platform_data needs to go into include/linux/iio
149 - */
150 -
151 -struct ad799x_platform_data {
152 -       u16                             vref_mv;
153 -};
154 -
155  #ifdef CONFIG_AD799X_RING_BUFFER
156  int ad799x_register_ring_funcs_and_init(struct iio_dev *indio_dev);
157  void ad799x_ring_cleanup(struct iio_dev *indio_dev);