aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Breathitt Gray <vilhelm.gray@gmail.com>2016-07-12 09:33:14 -0400
committerJonathan Cameron <jic23@kernel.org>2016-07-24 14:58:43 -0400
commit3b8df5fd526e70e8c89e47e3fcb253b80f6192f6 (patch)
treeb3bf616d827264c64169360d141ac354db064988
parentd02ec00d00a5eb5e0ca8ef6ddf0a3774adb52b6a (diff)
iio: Add IIO support for the Measurement Computing CIO-DAC family
The Measurement Computing CIO-DAC is a family of 16-bit and 12-bit analog output devices. The analog outputs are from AD660BN/AD7237 converters with each output buffered by an OP-27. Voltage ranges are configured via physical jumpers on the device. This driver does not support the devices' simulataneous update mode; the XFER jumper option should be deselected for all analog output channels. This driver provides IIO support for the Measurement Computing CIO-DAC family: CIO-DAC16, CIO-DAC08, and PC104-DAC06. The base port addresses for the devices may be configured via the base array module parameter. Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
-rw-r--r--MAINTAINERS6
-rw-r--r--drivers/iio/dac/Kconfig9
-rw-r--r--drivers/iio/dac/Makefile1
-rw-r--r--drivers/iio/dac/cio-dac.c144
4 files changed, 160 insertions, 0 deletions
diff --git a/MAINTAINERS b/MAINTAINERS
index 345e75744439..b5c802dcf516 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -7318,6 +7318,12 @@ L: linux-iio@vger.kernel.org
7318S: Maintained 7318S: Maintained
7319F: drivers/iio/potentiometer/mcp4531.c 7319F: drivers/iio/potentiometer/mcp4531.c
7320 7320
7321MEASUREMENT COMPUTING CIO-DAC IIO DRIVER
7322M: William Breathitt Gray <vilhelm.gray@gmail.com>
7323L: linux-iio@vger.kernel.org
7324S: Maintained
7325F: drivers/iio/dac/cio-dac.c
7326
7321MEDIA DRIVERS FOR RENESAS - VSP1 7327MEDIA DRIVERS FOR RENESAS - VSP1
7322M: Laurent Pinchart <laurent.pinchart@ideasonboard.com> 7328M: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
7323L: linux-media@vger.kernel.org 7329L: linux-media@vger.kernel.org
diff --git a/drivers/iio/dac/Kconfig b/drivers/iio/dac/Kconfig
index ca814479fadf..b9f044249194 100644
--- a/drivers/iio/dac/Kconfig
+++ b/drivers/iio/dac/Kconfig
@@ -181,6 +181,15 @@ config AD7303
181 To compile this driver as module choose M here: the module will be called 181 To compile this driver as module choose M here: the module will be called
182 ad7303. 182 ad7303.
183 183
184config CIO_DAC
185 tristate "Measurement Computing CIO-DAC IIO driver"
186 depends on X86 && ISA_BUS_API
187 help
188 Say yes here to build support for the Measurement Computing CIO-DAC
189 analog output device family (CIO-DAC16, CIO-DAC08, PC104-DAC06). The
190 base port addresses for the devices may be configured via the base
191 array module parameter.
192
184config LPC18XX_DAC 193config LPC18XX_DAC
185 tristate "NXP LPC18xx DAC driver" 194 tristate "NXP LPC18xx DAC driver"
186 depends on ARCH_LPC18XX || COMPILE_TEST 195 depends on ARCH_LPC18XX || COMPILE_TEST
diff --git a/drivers/iio/dac/Makefile b/drivers/iio/dac/Makefile
index 8b78d5ca9b11..b1a120612462 100644
--- a/drivers/iio/dac/Makefile
+++ b/drivers/iio/dac/Makefile
@@ -20,6 +20,7 @@ obj-$(CONFIG_AD5764) += ad5764.o
20obj-$(CONFIG_AD5791) += ad5791.o 20obj-$(CONFIG_AD5791) += ad5791.o
21obj-$(CONFIG_AD5686) += ad5686.o 21obj-$(CONFIG_AD5686) += ad5686.o
22obj-$(CONFIG_AD7303) += ad7303.o 22obj-$(CONFIG_AD7303) += ad7303.o
23obj-$(CONFIG_CIO_DAC) += cio-dac.o
23obj-$(CONFIG_LPC18XX_DAC) += lpc18xx_dac.o 24obj-$(CONFIG_LPC18XX_DAC) += lpc18xx_dac.o
24obj-$(CONFIG_M62332) += m62332.o 25obj-$(CONFIG_M62332) += m62332.o
25obj-$(CONFIG_MAX517) += max517.o 26obj-$(CONFIG_MAX517) += max517.o
diff --git a/drivers/iio/dac/cio-dac.c b/drivers/iio/dac/cio-dac.c
new file mode 100644
index 000000000000..5a743e2a779d
--- /dev/null
+++ b/drivers/iio/dac/cio-dac.c
@@ -0,0 +1,144 @@
1/*
2 * IIO driver for the Measurement Computing CIO-DAC
3 * Copyright (C) 2016 William Breathitt Gray
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License, version 2, as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * This driver supports the following Measurement Computing devices: CIO-DAC16,
15 * CIO-DAC06, and PC104-DAC06.
16 */
17#include <linux/bitops.h>
18#include <linux/device.h>
19#include <linux/errno.h>
20#include <linux/iio/iio.h>
21#include <linux/iio/types.h>
22#include <linux/io.h>
23#include <linux/ioport.h>
24#include <linux/isa.h>
25#include <linux/module.h>
26#include <linux/moduleparam.h>
27
28#define CIO_DAC_NUM_CHAN 16
29
30#define CIO_DAC_CHAN(chan) { \
31 .type = IIO_VOLTAGE, \
32 .channel = chan, \
33 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
34 .indexed = 1, \
35 .output = 1 \
36}
37
38#define CIO_DAC_EXTENT 32
39
40static unsigned int base[max_num_isa_dev(CIO_DAC_EXTENT)];
41static unsigned int num_cio_dac;
42module_param_array(base, uint, &num_cio_dac, 0);
43MODULE_PARM_DESC(base, "Measurement Computing CIO-DAC base addresses");
44
45/**
46 * struct cio_dac_iio - IIO device private data structure
47 * @chan_out_states: channels' output states
48 * @base: base port address of the IIO device
49 */
50struct cio_dac_iio {
51 int chan_out_states[CIO_DAC_NUM_CHAN];
52 unsigned int base;
53};
54
55static int cio_dac_read_raw(struct iio_dev *indio_dev,
56 struct iio_chan_spec const *chan, int *val, int *val2, long mask)
57{
58 struct cio_dac_iio *const priv = iio_priv(indio_dev);
59
60 if (mask != IIO_CHAN_INFO_RAW)
61 return -EINVAL;
62
63 *val = priv->chan_out_states[chan->channel];
64
65 return IIO_VAL_INT;
66}
67
68static int cio_dac_write_raw(struct iio_dev *indio_dev,
69 struct iio_chan_spec const *chan, int val, int val2, long mask)
70{
71 struct cio_dac_iio *const priv = iio_priv(indio_dev);
72 const unsigned int chan_addr_offset = 2 * chan->channel;
73
74 if (mask != IIO_CHAN_INFO_RAW)
75 return -EINVAL;
76
77 /* DAC can only accept up to a 16-bit value */
78 if ((unsigned int)val > 65535)
79 return -EINVAL;
80
81 priv->chan_out_states[chan->channel] = val;
82 outw(val, priv->base + chan_addr_offset);
83
84 return 0;
85}
86
87static const struct iio_info cio_dac_info = {
88 .driver_module = THIS_MODULE,
89 .read_raw = cio_dac_read_raw,
90 .write_raw = cio_dac_write_raw
91};
92
93static const struct iio_chan_spec cio_dac_channels[CIO_DAC_NUM_CHAN] = {
94 CIO_DAC_CHAN(0), CIO_DAC_CHAN(1), CIO_DAC_CHAN(2), CIO_DAC_CHAN(3),
95 CIO_DAC_CHAN(4), CIO_DAC_CHAN(5), CIO_DAC_CHAN(6), CIO_DAC_CHAN(7),
96 CIO_DAC_CHAN(8), CIO_DAC_CHAN(9), CIO_DAC_CHAN(10), CIO_DAC_CHAN(11),
97 CIO_DAC_CHAN(12), CIO_DAC_CHAN(13), CIO_DAC_CHAN(14), CIO_DAC_CHAN(15)
98};
99
100static int cio_dac_probe(struct device *dev, unsigned int id)
101{
102 struct iio_dev *indio_dev;
103 struct cio_dac_iio *priv;
104 unsigned int i;
105
106 indio_dev = devm_iio_device_alloc(dev, sizeof(*priv));
107 if (!indio_dev)
108 return -ENOMEM;
109
110 if (!devm_request_region(dev, base[id], CIO_DAC_EXTENT,
111 dev_name(dev))) {
112 dev_err(dev, "Unable to request port addresses (0x%X-0x%X)\n",
113 base[id], base[id] + CIO_DAC_EXTENT);
114 return -EBUSY;
115 }
116
117 indio_dev->info = &cio_dac_info;
118 indio_dev->modes = INDIO_DIRECT_MODE;
119 indio_dev->channels = cio_dac_channels;
120 indio_dev->num_channels = CIO_DAC_NUM_CHAN;
121 indio_dev->name = dev_name(dev);
122
123 priv = iio_priv(indio_dev);
124 priv->base = base[id];
125
126 /* initialize DAC outputs to 0V */
127 for (i = 0; i < 32; i += 2)
128 outw(0, base[id] + i);
129
130 return devm_iio_device_register(dev, indio_dev);
131}
132
133static struct isa_driver cio_dac_driver = {
134 .probe = cio_dac_probe,
135 .driver = {
136 .name = "cio-dac"
137 }
138};
139
140module_isa_driver(cio_dac_driver, num_cio_dac);
141
142MODULE_AUTHOR("William Breathitt Gray <vilhelm.gray@gmail.com>");
143MODULE_DESCRIPTION("Measurement Computing CIO-DAC IIO driver");
144MODULE_LICENSE("GPL v2");