Skip to content

Commit 3b8df5f

Browse files
William Breathitt Grayjic23
authored andcommitted
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 <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent d02ec00 commit 3b8df5f

File tree

4 files changed

+160
-0
lines changed

4 files changed

+160
-0
lines changed

MAINTAINERS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7318,6 +7318,12 @@ L: [email protected]
73187318
S: Maintained
73197319
F: drivers/iio/potentiometer/mcp4531.c
73207320

7321+
MEASUREMENT COMPUTING CIO-DAC IIO DRIVER
7322+
M: William Breathitt Gray <[email protected]>
7323+
7324+
S: Maintained
7325+
F: drivers/iio/dac/cio-dac.c
7326+
73217327
MEDIA DRIVERS FOR RENESAS - VSP1
73227328
M: Laurent Pinchart <[email protected]>
73237329

drivers/iio/dac/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,15 @@ config AD7303
181181
To compile this driver as module choose M here: the module will be called
182182
ad7303.
183183

184+
config 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+
184193
config LPC18XX_DAC
185194
tristate "NXP LPC18xx DAC driver"
186195
depends on ARCH_LPC18XX || COMPILE_TEST

drivers/iio/dac/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ obj-$(CONFIG_AD5764) += ad5764.o
2020
obj-$(CONFIG_AD5791) += ad5791.o
2121
obj-$(CONFIG_AD5686) += ad5686.o
2222
obj-$(CONFIG_AD7303) += ad7303.o
23+
obj-$(CONFIG_CIO_DAC) += cio-dac.o
2324
obj-$(CONFIG_LPC18XX_DAC) += lpc18xx_dac.o
2425
obj-$(CONFIG_M62332) += m62332.o
2526
obj-$(CONFIG_MAX517) += max517.o

drivers/iio/dac/cio-dac.c

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
40+
static unsigned int base[max_num_isa_dev(CIO_DAC_EXTENT)];
41+
static unsigned int num_cio_dac;
42+
module_param_array(base, uint, &num_cio_dac, 0);
43+
MODULE_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+
*/
50+
struct cio_dac_iio {
51+
int chan_out_states[CIO_DAC_NUM_CHAN];
52+
unsigned int base;
53+
};
54+
55+
static 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+
68+
static 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+
87+
static 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+
93+
static 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+
100+
static 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+
133+
static struct isa_driver cio_dac_driver = {
134+
.probe = cio_dac_probe,
135+
.driver = {
136+
.name = "cio-dac"
137+
}
138+
};
139+
140+
module_isa_driver(cio_dac_driver, num_cio_dac);
141+
142+
MODULE_AUTHOR("William Breathitt Gray <[email protected]>");
143+
MODULE_DESCRIPTION("Measurement Computing CIO-DAC IIO driver");
144+
MODULE_LICENSE("GPL v2");

0 commit comments

Comments
 (0)