diff options
author | Michael Hennerich <michael.hennerich@analog.com> | 2011-05-18 09:42:25 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2011-05-19 19:15:03 -0400 |
commit | cc4a48e4cf92776656633aeb895520dc53893f32 (patch) | |
tree | a26a9edacffcf574a2c7e7b07a5427259a682a6e /drivers | |
parent | 5565a450248d827afa949aab157873d4b9be329e (diff) |
staging:iio:adc:AD7298: Use private data space from iio_allocate_device
Use private data space from iio_allocate_device
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/staging/iio/adc/ad7298.h | 5 | ||||
-rw-r--r-- | drivers/staging/iio/adc/ad7298_core.c | 72 | ||||
-rw-r--r-- | drivers/staging/iio/adc/ad7298_ring.c | 8 |
3 files changed, 41 insertions, 44 deletions
diff --git a/drivers/staging/iio/adc/ad7298.h b/drivers/staging/iio/adc/ad7298.h index 718e56af4864..628f5adcf0c9 100644 --- a/drivers/staging/iio/adc/ad7298.h +++ b/drivers/staging/iio/adc/ad7298.h | |||
@@ -36,7 +36,6 @@ struct ad7298_platform_data { | |||
36 | }; | 36 | }; |
37 | 37 | ||
38 | struct ad7298_state { | 38 | struct ad7298_state { |
39 | struct iio_dev *indio_dev; | ||
40 | struct spi_device *spi; | 39 | struct spi_device *spi; |
41 | struct regulator *reg; | 40 | struct regulator *reg; |
42 | size_t d_size; | 41 | size_t d_size; |
@@ -55,11 +54,11 @@ struct ad7298_state { | |||
55 | }; | 54 | }; |
56 | 55 | ||
57 | #ifdef CONFIG_IIO_RING_BUFFER | 56 | #ifdef CONFIG_IIO_RING_BUFFER |
58 | int ad7298_scan_from_ring(struct ad7298_state *st, long ch); | 57 | int ad7298_scan_from_ring(struct iio_dev *indio_dev, long ch); |
59 | int ad7298_register_ring_funcs_and_init(struct iio_dev *indio_dev); | 58 | int ad7298_register_ring_funcs_and_init(struct iio_dev *indio_dev); |
60 | void ad7298_ring_cleanup(struct iio_dev *indio_dev); | 59 | void ad7298_ring_cleanup(struct iio_dev *indio_dev); |
61 | #else /* CONFIG_IIO_RING_BUFFER */ | 60 | #else /* CONFIG_IIO_RING_BUFFER */ |
62 | static inline int ad7298_scan_from_ring(struct ad7298_state *st, long ch) | 61 | static inline int ad7298_scan_from_ring(struct iio_dev *indio_dev, long ch) |
63 | { | 62 | { |
64 | return 0; | 63 | return 0; |
65 | } | 64 | } |
diff --git a/drivers/staging/iio/adc/ad7298_core.c b/drivers/staging/iio/adc/ad7298_core.c index 35a30ae9bbc6..83b3d158353f 100644 --- a/drivers/staging/iio/adc/ad7298_core.c +++ b/drivers/staging/iio/adc/ad7298_core.c | |||
@@ -116,7 +116,7 @@ static int ad7298_read_raw(struct iio_dev *dev_info, | |||
116 | long m) | 116 | long m) |
117 | { | 117 | { |
118 | int ret; | 118 | int ret; |
119 | struct ad7298_state *st = dev_info->dev_data; | 119 | struct ad7298_state *st = iio_priv(dev_info); |
120 | unsigned int scale_uv; | 120 | unsigned int scale_uv; |
121 | 121 | ||
122 | switch (m) { | 122 | switch (m) { |
@@ -126,7 +126,8 @@ static int ad7298_read_raw(struct iio_dev *dev_info, | |||
126 | if (chan->address == AD7298_CH_TEMP) | 126 | if (chan->address == AD7298_CH_TEMP) |
127 | ret = -ENODEV; | 127 | ret = -ENODEV; |
128 | else | 128 | else |
129 | ret = ad7298_scan_from_ring(st, chan->address); | 129 | ret = ad7298_scan_from_ring(dev_info, |
130 | chan->address); | ||
130 | } else { | 131 | } else { |
131 | if (chan->address == AD7298_CH_TEMP) | 132 | if (chan->address == AD7298_CH_TEMP) |
132 | ret = ad7298_scan_temp(st, val); | 133 | ret = ad7298_scan_temp(st, val); |
@@ -159,13 +160,13 @@ static int __devinit ad7298_probe(struct spi_device *spi) | |||
159 | { | 160 | { |
160 | struct ad7298_platform_data *pdata = spi->dev.platform_data; | 161 | struct ad7298_platform_data *pdata = spi->dev.platform_data; |
161 | struct ad7298_state *st; | 162 | struct ad7298_state *st; |
162 | int ret; | 163 | int ret, regdone = 0; |
164 | struct iio_dev *indio_dev = iio_allocate_device(sizeof(*st)); | ||
163 | 165 | ||
164 | st = kzalloc(sizeof(*st), GFP_KERNEL); | 166 | if (indio_dev == NULL) |
165 | if (st == NULL) { | 167 | return -ENOMEM; |
166 | ret = -ENOMEM; | 168 | |
167 | goto error_ret; | 169 | st = iio_priv(indio_dev); |
168 | } | ||
169 | 170 | ||
170 | st->reg = regulator_get(&spi->dev, "vcc"); | 171 | st->reg = regulator_get(&spi->dev, "vcc"); |
171 | if (!IS_ERR(st->reg)) { | 172 | if (!IS_ERR(st->reg)) { |
@@ -174,24 +175,17 @@ static int __devinit ad7298_probe(struct spi_device *spi) | |||
174 | goto error_put_reg; | 175 | goto error_put_reg; |
175 | } | 176 | } |
176 | 177 | ||
177 | spi_set_drvdata(spi, st); | 178 | spi_set_drvdata(spi, indio_dev); |
178 | 179 | ||
179 | st->spi = spi; | 180 | st->spi = spi; |
180 | 181 | ||
181 | st->indio_dev = iio_allocate_device(0); | 182 | indio_dev->name = spi_get_device_id(spi)->name; |
182 | if (st->indio_dev == NULL) { | 183 | indio_dev->dev.parent = &spi->dev; |
183 | ret = -ENOMEM; | 184 | indio_dev->driver_module = THIS_MODULE; |
184 | goto error_disable_reg; | 185 | indio_dev->modes = INDIO_DIRECT_MODE; |
185 | } | 186 | indio_dev->channels = ad7298_channels; |
186 | 187 | indio_dev->num_channels = ARRAY_SIZE(ad7298_channels); | |
187 | st->indio_dev->name = spi_get_device_id(spi)->name; | 188 | indio_dev->read_raw = &ad7298_read_raw; |
188 | st->indio_dev->dev.parent = &spi->dev; | ||
189 | st->indio_dev->dev_data = (void *)(st); | ||
190 | st->indio_dev->driver_module = THIS_MODULE; | ||
191 | st->indio_dev->modes = INDIO_DIRECT_MODE; | ||
192 | st->indio_dev->channels = ad7298_channels; | ||
193 | st->indio_dev->num_channels = ARRAY_SIZE(ad7298_channels); | ||
194 | st->indio_dev->read_raw = &ad7298_read_raw; | ||
195 | 189 | ||
196 | /* Setup default message */ | 190 | /* Setup default message */ |
197 | 191 | ||
@@ -216,41 +210,44 @@ static int __devinit ad7298_probe(struct spi_device *spi) | |||
216 | st->int_vref_mv = AD7298_INTREF_mV; | 210 | st->int_vref_mv = AD7298_INTREF_mV; |
217 | } | 211 | } |
218 | 212 | ||
219 | ret = ad7298_register_ring_funcs_and_init(st->indio_dev); | 213 | ret = ad7298_register_ring_funcs_and_init(indio_dev); |
220 | if (ret) | 214 | if (ret) |
221 | goto error_free_device; | 215 | goto error_disable_reg; |
222 | 216 | ||
223 | ret = iio_device_register(st->indio_dev); | 217 | ret = iio_device_register(indio_dev); |
224 | if (ret) | 218 | if (ret) |
225 | goto error_free_device; | 219 | goto error_disable_reg; |
220 | regdone = 1; | ||
226 | 221 | ||
227 | ret = iio_ring_buffer_register_ex(st->indio_dev->ring, 0, | 222 | ret = iio_ring_buffer_register_ex(indio_dev->ring, 0, |
228 | &ad7298_channels[1], /* skip temp0 */ | 223 | &ad7298_channels[1], /* skip temp0 */ |
229 | ARRAY_SIZE(ad7298_channels) - 1); | 224 | ARRAY_SIZE(ad7298_channels) - 1); |
230 | if (ret) | 225 | if (ret) |
231 | goto error_cleanup_ring; | 226 | goto error_cleanup_ring; |
227 | |||
232 | return 0; | 228 | return 0; |
233 | 229 | ||
234 | error_cleanup_ring: | 230 | error_cleanup_ring: |
235 | ad7298_ring_cleanup(st->indio_dev); | 231 | ad7298_ring_cleanup(indio_dev); |
236 | iio_device_unregister(st->indio_dev); | ||
237 | error_free_device: | ||
238 | iio_free_device(st->indio_dev); | ||
239 | error_disable_reg: | 232 | error_disable_reg: |
240 | if (!IS_ERR(st->reg)) | 233 | if (!IS_ERR(st->reg)) |
241 | regulator_disable(st->reg); | 234 | regulator_disable(st->reg); |
242 | error_put_reg: | 235 | error_put_reg: |
243 | if (!IS_ERR(st->reg)) | 236 | if (!IS_ERR(st->reg)) |
244 | regulator_put(st->reg); | 237 | regulator_put(st->reg); |
245 | kfree(st); | 238 | |
246 | error_ret: | 239 | if (regdone) |
240 | iio_device_unregister(indio_dev); | ||
241 | else | ||
242 | iio_free_device(indio_dev); | ||
243 | |||
247 | return ret; | 244 | return ret; |
248 | } | 245 | } |
249 | 246 | ||
250 | static int __devexit ad7298_remove(struct spi_device *spi) | 247 | static int __devexit ad7298_remove(struct spi_device *spi) |
251 | { | 248 | { |
252 | struct ad7298_state *st = spi_get_drvdata(spi); | 249 | struct iio_dev *indio_dev = spi_get_drvdata(spi); |
253 | struct iio_dev *indio_dev = st->indio_dev; | 250 | struct ad7298_state *st = iio_priv(indio_dev); |
254 | 251 | ||
255 | iio_ring_buffer_unregister(indio_dev->ring); | 252 | iio_ring_buffer_unregister(indio_dev->ring); |
256 | ad7298_ring_cleanup(indio_dev); | 253 | ad7298_ring_cleanup(indio_dev); |
@@ -259,7 +256,8 @@ static int __devexit ad7298_remove(struct spi_device *spi) | |||
259 | regulator_disable(st->reg); | 256 | regulator_disable(st->reg); |
260 | regulator_put(st->reg); | 257 | regulator_put(st->reg); |
261 | } | 258 | } |
262 | kfree(st); | 259 | iio_device_unregister(indio_dev); |
260 | |||
263 | return 0; | 261 | return 0; |
264 | } | 262 | } |
265 | 263 | ||
diff --git a/drivers/staging/iio/adc/ad7298_ring.c b/drivers/staging/iio/adc/ad7298_ring.c index 09b1477c09af..d0a0aeaaf398 100644 --- a/drivers/staging/iio/adc/ad7298_ring.c +++ b/drivers/staging/iio/adc/ad7298_ring.c | |||
@@ -21,9 +21,9 @@ | |||
21 | 21 | ||
22 | #include "ad7298.h" | 22 | #include "ad7298.h" |
23 | 23 | ||
24 | int ad7298_scan_from_ring(struct ad7298_state *st, long ch) | 24 | int ad7298_scan_from_ring(struct iio_dev *dev_info, long ch) |
25 | { | 25 | { |
26 | struct iio_ring_buffer *ring = st->indio_dev->ring; | 26 | struct iio_ring_buffer *ring = dev_info->ring; |
27 | int ret; | 27 | int ret; |
28 | u16 *ring_data; | 28 | u16 *ring_data; |
29 | 29 | ||
@@ -59,7 +59,7 @@ error_ret: | |||
59 | **/ | 59 | **/ |
60 | static int ad7298_ring_preenable(struct iio_dev *indio_dev) | 60 | static int ad7298_ring_preenable(struct iio_dev *indio_dev) |
61 | { | 61 | { |
62 | struct ad7298_state *st = indio_dev->dev_data; | 62 | struct ad7298_state *st = iio_priv(indio_dev); |
63 | struct iio_ring_buffer *ring = indio_dev->ring; | 63 | struct iio_ring_buffer *ring = indio_dev->ring; |
64 | size_t d_size; | 64 | size_t d_size; |
65 | int i, m; | 65 | int i, m; |
@@ -121,7 +121,7 @@ static irqreturn_t ad7298_trigger_handler(int irq, void *p) | |||
121 | { | 121 | { |
122 | struct iio_poll_func *pf = p; | 122 | struct iio_poll_func *pf = p; |
123 | struct iio_dev *indio_dev = pf->private_data; | 123 | struct iio_dev *indio_dev = pf->private_data; |
124 | struct ad7298_state *st = iio_dev_get_devdata(indio_dev); | 124 | struct ad7298_state *st = iio_priv(indio_dev); |
125 | struct iio_ring_buffer *ring = indio_dev->ring; | 125 | struct iio_ring_buffer *ring = indio_dev->ring; |
126 | s64 time_ns; | 126 | s64 time_ns; |
127 | __u16 buf[16]; | 127 | __u16 buf[16]; |