~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise-security

« back to all changes in this revision

Viewing changes to drivers/staging/iio/dds/ad9834.c

  • Committer: Package Import Robot
  • Author(s): Paolo Pisati, Paolo Pisati
  • Date: 2011-12-06 15:56:07 UTC
  • Revision ID: package-import@ubuntu.com-20111206155607-pcf44kv5fmhk564f
Tags: 3.2.0-1401.1
[ Paolo Pisati ]

* Rebased on top of Ubuntu-3.2.0-3.8
* Tilt-tracking @ ef2487af4bb15bdd0689631774b5a5e3a59f74e2
* Delete debian.ti-omap4/control, it shoudln't be tracked
* Fix architecture spelling (s/armel/armhf/)
* [Config] Update configs following 3.2 import
* [Config] Fix compilation: disable CODA and ARCH_OMAP3
* [Config] Fix compilation: disable Ethernet Faraday
* Update series to precise

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
#include <linux/spi/spi.h>
17
17
#include <linux/regulator/consumer.h>
18
18
#include <linux/err.h>
 
19
#include <linux/module.h>
19
20
#include <asm/div64.h>
20
21
 
21
22
#include "../iio.h"
65
66
                const char *buf,
66
67
                size_t len)
67
68
{
68
 
        struct iio_dev *dev_info = dev_get_drvdata(dev);
69
 
        struct ad9834_state *st = dev_info->dev_data;
 
69
        struct iio_dev *indio_dev = dev_get_drvdata(dev);
 
70
        struct ad9834_state *st = iio_priv(indio_dev);
70
71
        struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
71
72
        int ret;
72
73
        long val;
75
76
        if (ret)
76
77
                goto error_ret;
77
78
 
78
 
        mutex_lock(&dev_info->mlock);
 
79
        mutex_lock(&indio_dev->mlock);
79
80
        switch (this_attr->address) {
80
81
        case AD9834_REG_FREQ0:
81
82
        case AD9834_REG_FREQ1:
133
134
        default:
134
135
                ret = -ENODEV;
135
136
        }
136
 
        mutex_unlock(&dev_info->mlock);
 
137
        mutex_unlock(&indio_dev->mlock);
137
138
 
138
139
error_ret:
139
140
        return ret ? ret : len;
144
145
                                 const char *buf,
145
146
                                 size_t len)
146
147
{
147
 
        struct iio_dev *dev_info = dev_get_drvdata(dev);
148
 
        struct ad9834_state *st = dev_info->dev_data;
 
148
        struct iio_dev *indio_dev = dev_get_drvdata(dev);
 
149
        struct ad9834_state *st = iio_priv(indio_dev);
149
150
        struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
150
151
        int ret = 0;
151
152
        bool is_ad9833_7 = (st->devid == ID_AD9833) || (st->devid == ID_AD9837);
152
153
 
153
 
        mutex_lock(&dev_info->mlock);
 
154
        mutex_lock(&indio_dev->mlock);
154
155
 
155
156
        switch (this_attr->address) {
156
157
        case 0:
193
194
                st->data = cpu_to_be16(AD9834_REG_CMD | st->control);
194
195
                ret = spi_sync(st->spi, &st->msg);
195
196
        }
196
 
        mutex_unlock(&dev_info->mlock);
 
197
        mutex_unlock(&indio_dev->mlock);
197
198
 
198
199
        return ret ? ret : len;
199
200
}
202
203
                                                struct device_attribute *attr,
203
204
                                                char *buf)
204
205
{
205
 
        struct iio_dev *dev_info = dev_get_drvdata(dev);
206
 
        struct ad9834_state *st = iio_dev_get_devdata(dev_info);
 
206
        struct iio_dev *indio_dev = dev_get_drvdata(dev);
 
207
        struct ad9834_state *st = iio_priv(indio_dev);
207
208
        char *str;
208
209
 
209
210
        if ((st->devid == ID_AD9833) || (st->devid == ID_AD9837))
224
225
                                                struct device_attribute *attr,
225
226
                                                char *buf)
226
227
{
227
 
        struct iio_dev *dev_info = dev_get_drvdata(dev);
228
 
        struct ad9834_state *st = iio_dev_get_devdata(dev_info);
 
228
        struct iio_dev *indio_dev = dev_get_drvdata(dev);
 
229
        struct ad9834_state *st = iio_priv(indio_dev);
229
230
        char *str;
230
231
 
231
232
        if (st->control & AD9834_MODE)
284
285
                                     struct attribute *attr, int n)
285
286
{
286
287
        struct device *dev = container_of(kobj, struct device, kobj);
287
 
        struct iio_dev *dev_info = dev_get_drvdata(dev);
288
 
        struct ad9834_state *st = iio_dev_get_devdata(dev_info);
 
288
        struct iio_dev *indio_dev = dev_get_drvdata(dev);
 
289
        struct ad9834_state *st = iio_priv(indio_dev);
289
290
 
290
291
        mode_t mode = attr->mode;
291
292
 
314
315
{
315
316
        struct ad9834_platform_data *pdata = spi->dev.platform_data;
316
317
        struct ad9834_state *st;
 
318
        struct iio_dev *indio_dev;
 
319
        struct regulator *reg;
317
320
        int ret;
318
321
 
319
322
        if (!pdata) {
321
324
                return -ENODEV;
322
325
        }
323
326
 
324
 
        st = kzalloc(sizeof(*st), GFP_KERNEL);
325
 
        if (st == NULL) {
326
 
                ret = -ENOMEM;
327
 
                goto error_ret;
328
 
        }
329
 
 
330
 
        st->reg = regulator_get(&spi->dev, "vcc");
331
 
        if (!IS_ERR(st->reg)) {
332
 
                ret = regulator_enable(st->reg);
 
327
        reg = regulator_get(&spi->dev, "vcc");
 
328
        if (!IS_ERR(reg)) {
 
329
                ret = regulator_enable(reg);
333
330
                if (ret)
334
331
                        goto error_put_reg;
335
332
        }
336
333
 
 
334
        indio_dev = iio_allocate_device(sizeof(*st));
 
335
        if (indio_dev == NULL) {
 
336
                ret = -ENOMEM;
 
337
                goto error_disable_reg;
 
338
        }
 
339
        spi_set_drvdata(spi, indio_dev);
 
340
        st = iio_priv(indio_dev);
337
341
        st->mclk = pdata->mclk;
338
 
 
339
 
        spi_set_drvdata(spi, st);
340
 
 
341
342
        st->spi = spi;
342
343
        st->devid = spi_get_device_id(spi)->driver_data;
343
 
 
344
 
        st->indio_dev = iio_allocate_device(0);
345
 
        if (st->indio_dev == NULL) {
346
 
                ret = -ENOMEM;
347
 
                goto error_disable_reg;
348
 
        }
349
 
 
350
 
        st->indio_dev->dev.parent = &spi->dev;
351
 
        st->indio_dev->name = spi_get_device_id(spi)->name;
352
 
        st->indio_dev->info = &ad9834_info;
353
 
        st->indio_dev->dev_data = (void *) st;
354
 
        st->indio_dev->modes = INDIO_DIRECT_MODE;
 
344
        st->reg = reg;
 
345
        indio_dev->dev.parent = &spi->dev;
 
346
        indio_dev->name = spi_get_device_id(spi)->name;
 
347
        indio_dev->info = &ad9834_info;
 
348
        indio_dev->modes = INDIO_DIRECT_MODE;
355
349
 
356
350
        /* Setup default messages */
357
351
 
402
396
        if (ret)
403
397
                goto error_free_device;
404
398
 
405
 
        ret = iio_device_register(st->indio_dev);
 
399
        ret = iio_device_register(indio_dev);
406
400
        if (ret)
407
401
                goto error_free_device;
408
402
 
409
403
        return 0;
410
404
 
411
405
error_free_device:
412
 
        iio_free_device(st->indio_dev);
 
406
        iio_free_device(indio_dev);
413
407
error_disable_reg:
414
 
        if (!IS_ERR(st->reg))
415
 
                regulator_disable(st->reg);
 
408
        if (!IS_ERR(reg))
 
409
                regulator_disable(reg);
416
410
error_put_reg:
417
 
        if (!IS_ERR(st->reg))
418
 
                regulator_put(st->reg);
419
 
        kfree(st);
420
 
error_ret:
 
411
        if (!IS_ERR(reg))
 
412
                regulator_put(reg);
421
413
        return ret;
422
414
}
423
415
 
424
416
static int __devexit ad9834_remove(struct spi_device *spi)
425
417
{
426
 
        struct ad9834_state *st = spi_get_drvdata(spi);
 
418
        struct iio_dev *indio_dev = spi_get_drvdata(spi);
 
419
        struct ad9834_state *st = iio_priv(indio_dev);
427
420
 
428
 
        iio_device_unregister(st->indio_dev);
 
421
        iio_device_unregister(indio_dev);
429
422
        if (!IS_ERR(st->reg)) {
430
423
                regulator_disable(st->reg);
431
424
                regulator_put(st->reg);
432
425
        }
433
 
        kfree(st);
 
426
        iio_free_device(indio_dev);
 
427
 
434
428
        return 0;
435
429
}
436
430