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

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * AD9834 SPI DAC driver
3
 
 *
4
 
 * Copyright 2010 Analog Devices Inc.
5
 
 *
6
 
 * Licensed under the GPL-2 or later.
 
2
 * AD9833/AD9834/AD9837/AD9838 SPI DDS driver
 
3
 *
 
4
 * Copyright 2010-2011 Analog Devices Inc.
 
5
 *
 
6
 * Licensed under the GPL-2.
7
7
 */
8
8
 
9
9
#include <linux/interrupt.h>
47
47
                                       (AD9834_FREQ_BITS / 2)) &
48
48
                                       RES_MASK(AD9834_FREQ_BITS / 2)));
49
49
 
50
 
        return spi_sync(st->spi, &st->freq_msg);;
 
50
        return spi_sync(st->spi, &st->freq_msg);
51
51
}
52
52
 
53
53
static int ad9834_write_phase(struct ad9834_state *st,
148
148
        struct ad9834_state *st = dev_info->dev_data;
149
149
        struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
150
150
        int ret = 0;
151
 
        bool is_ad9833 = st->devid == ID_AD9833;
 
151
        bool is_ad9833_7 = (st->devid == ID_AD9833) || (st->devid == ID_AD9837);
152
152
 
153
153
        mutex_lock(&dev_info->mlock);
154
154
 
156
156
        case 0:
157
157
                if (sysfs_streq(buf, "sine")) {
158
158
                        st->control &= ~AD9834_MODE;
159
 
                        if (is_ad9833)
 
159
                        if (is_ad9833_7)
160
160
                                st->control &= ~AD9834_OPBITEN;
161
161
                } else if (sysfs_streq(buf, "triangle")) {
162
 
                        if (is_ad9833) {
 
162
                        if (is_ad9833_7) {
163
163
                                st->control &= ~AD9834_OPBITEN;
164
164
                                st->control |= AD9834_MODE;
165
165
                        } else if (st->control & AD9834_OPBITEN) {
167
167
                        } else {
168
168
                                st->control |= AD9834_MODE;
169
169
                        }
170
 
                } else if (is_ad9833 && sysfs_streq(buf, "square")) {
 
170
                } else if (is_ad9833_7 && sysfs_streq(buf, "square")) {
171
171
                        st->control &= ~AD9834_MODE;
172
172
                        st->control |= AD9834_OPBITEN;
173
173
                } else {
198
198
        return ret ? ret : len;
199
199
}
200
200
 
201
 
static ssize_t ad9834_show_name(struct device *dev,
202
 
                                 struct device_attribute *attr,
203
 
                                 char *buf)
204
 
{
205
 
        struct iio_dev *dev_info = dev_get_drvdata(dev);
206
 
        struct ad9834_state *st = iio_dev_get_devdata(dev_info);
207
 
 
208
 
        return sprintf(buf, "%s\n", spi_get_device_id(st->spi)->name);
209
 
}
210
 
static IIO_DEVICE_ATTR(name, S_IRUGO, ad9834_show_name, NULL, 0);
211
 
 
212
201
static ssize_t ad9834_show_out0_wavetype_available(struct device *dev,
213
202
                                                struct device_attribute *attr,
214
203
                                                char *buf)
217
206
        struct ad9834_state *st = iio_dev_get_devdata(dev_info);
218
207
        char *str;
219
208
 
220
 
        if (st->devid == ID_AD9833)
 
209
        if ((st->devid == ID_AD9833) || (st->devid == ID_AD9837))
221
210
                str = "sine triangle square";
222
211
        else if (st->control & AD9834_OPBITEN)
223
212
                str = "sine";
288
277
        &iio_dev_attr_dds0_out1_wavetype.dev_attr.attr,
289
278
        &iio_dev_attr_dds0_out0_wavetype_available.dev_attr.attr,
290
279
        &iio_dev_attr_dds0_out1_wavetype_available.dev_attr.attr,
291
 
        &iio_dev_attr_name.dev_attr.attr,
292
280
        NULL,
293
281
};
294
282
 
301
289
 
302
290
        mode_t mode = attr->mode;
303
291
 
304
 
        if (st->devid == ID_AD9834)
305
 
                return mode;
306
 
 
307
 
        if ((attr == &iio_dev_attr_dds0_out1_enable.dev_attr.attr) ||
 
292
        if (((st->devid == ID_AD9833) || (st->devid == ID_AD9837)) &&
 
293
                ((attr == &iio_dev_attr_dds0_out1_enable.dev_attr.attr) ||
308
294
                (attr == &iio_dev_attr_dds0_out1_wavetype.dev_attr.attr) ||
309
295
                (attr ==
310
 
                &iio_dev_attr_dds0_out1_wavetype_available.dev_attr.attr))
 
296
                &iio_dev_attr_dds0_out1_wavetype_available.dev_attr.attr) ||
 
297
                (attr == &iio_dev_attr_dds0_pincontrol_en.dev_attr.attr)))
311
298
                mode = 0;
312
299
 
313
300
        return mode;
318
305
        .is_visible = ad9834_attr_is_visible,
319
306
};
320
307
 
 
308
static const struct iio_info ad9834_info = {
 
309
        .attrs = &ad9834_attribute_group,
 
310
        .driver_module = THIS_MODULE,
 
311
};
 
312
 
321
313
static int __devinit ad9834_probe(struct spi_device *spi)
322
314
{
323
315
        struct ad9834_platform_data *pdata = spi->dev.platform_data;
349
341
        st->spi = spi;
350
342
        st->devid = spi_get_device_id(spi)->driver_data;
351
343
 
352
 
        st->indio_dev = iio_allocate_device();
 
344
        st->indio_dev = iio_allocate_device(0);
353
345
        if (st->indio_dev == NULL) {
354
346
                ret = -ENOMEM;
355
347
                goto error_disable_reg;
356
348
        }
357
349
 
358
350
        st->indio_dev->dev.parent = &spi->dev;
359
 
        st->indio_dev->attrs = &ad9834_attribute_group;
 
351
        st->indio_dev->name = spi_get_device_id(spi)->name;
 
352
        st->indio_dev->info = &ad9834_info;
360
353
        st->indio_dev->dev_data = (void *) st;
361
 
        st->indio_dev->driver_module = THIS_MODULE;
362
354
        st->indio_dev->modes = INDIO_DIRECT_MODE;
363
355
 
364
356
        /* Setup default messages */
445
437
static const struct spi_device_id ad9834_id[] = {
446
438
        {"ad9833", ID_AD9833},
447
439
        {"ad9834", ID_AD9834},
 
440
        {"ad9837", ID_AD9837},
 
441
        {"ad9838", ID_AD9838},
448
442
        {}
449
443
};
450
444
 
472
466
module_exit(ad9834_exit);
473
467
 
474
468
MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
475
 
MODULE_DESCRIPTION("Analog Devices AD9833/AD9834 DDS");
 
469
MODULE_DESCRIPTION("Analog Devices AD9833/AD9834/AD9837/AD9838 DDS");
476
470
MODULE_LICENSE("GPL v2");
477
471
MODULE_ALIAS("spi:ad9834");