18ffdff6aSGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0+
28ffdff6aSGreg Kroah-Hartman /*
38ffdff6aSGreg Kroah-Hartman * das6402.c
48ffdff6aSGreg Kroah-Hartman * Comedi driver for DAS6402 compatible boards
58ffdff6aSGreg Kroah-Hartman * Copyright(c) 2014 H Hartley Sweeten <hsweeten@visionengravers.com>
68ffdff6aSGreg Kroah-Hartman *
78ffdff6aSGreg Kroah-Hartman * Rewrite of an experimental driver by:
88ffdff6aSGreg Kroah-Hartman * Copyright (C) 1999 Oystein Svendsen <svendsen@pvv.org>
98ffdff6aSGreg Kroah-Hartman */
108ffdff6aSGreg Kroah-Hartman
118ffdff6aSGreg Kroah-Hartman /*
128ffdff6aSGreg Kroah-Hartman * Driver: das6402
138ffdff6aSGreg Kroah-Hartman * Description: Keithley Metrabyte DAS6402 (& compatibles)
148ffdff6aSGreg Kroah-Hartman * Devices: [Keithley Metrabyte] DAS6402-12 (das6402-12),
158ffdff6aSGreg Kroah-Hartman * DAS6402-16 (das6402-16)
168ffdff6aSGreg Kroah-Hartman * Author: H Hartley Sweeten <hsweeten@visionengravers.com>
178ffdff6aSGreg Kroah-Hartman * Updated: Fri, 14 Mar 2014 10:18:43 -0700
188ffdff6aSGreg Kroah-Hartman * Status: unknown
198ffdff6aSGreg Kroah-Hartman *
208ffdff6aSGreg Kroah-Hartman * Configuration Options:
218ffdff6aSGreg Kroah-Hartman * [0] - I/O base address
228ffdff6aSGreg Kroah-Hartman * [1] - IRQ (optional, needed for async command support)
238ffdff6aSGreg Kroah-Hartman */
248ffdff6aSGreg Kroah-Hartman
258ffdff6aSGreg Kroah-Hartman #include <linux/module.h>
268ffdff6aSGreg Kroah-Hartman #include <linux/interrupt.h>
27df0e68c1SIan Abbott #include <linux/comedi/comedidev.h>
2844fb7affSIan Abbott #include <linux/comedi/comedi_8254.h>
298ffdff6aSGreg Kroah-Hartman
308ffdff6aSGreg Kroah-Hartman /*
318ffdff6aSGreg Kroah-Hartman * Register I/O map
328ffdff6aSGreg Kroah-Hartman */
338ffdff6aSGreg Kroah-Hartman #define DAS6402_AI_DATA_REG 0x00
348ffdff6aSGreg Kroah-Hartman #define DAS6402_AI_MUX_REG 0x02
358ffdff6aSGreg Kroah-Hartman #define DAS6402_AI_MUX_LO(x) (((x) & 0x3f) << 0)
368ffdff6aSGreg Kroah-Hartman #define DAS6402_AI_MUX_HI(x) (((x) & 0x3f) << 8)
378ffdff6aSGreg Kroah-Hartman #define DAS6402_DI_DO_REG 0x03
388ffdff6aSGreg Kroah-Hartman #define DAS6402_AO_DATA_REG(x) (0x04 + ((x) * 2))
398ffdff6aSGreg Kroah-Hartman #define DAS6402_AO_LSB_REG(x) (0x04 + ((x) * 2))
408ffdff6aSGreg Kroah-Hartman #define DAS6402_AO_MSB_REG(x) (0x05 + ((x) * 2))
418ffdff6aSGreg Kroah-Hartman #define DAS6402_STATUS_REG 0x08
428ffdff6aSGreg Kroah-Hartman #define DAS6402_STATUS_FFNE BIT(0)
438ffdff6aSGreg Kroah-Hartman #define DAS6402_STATUS_FHALF BIT(1)
448ffdff6aSGreg Kroah-Hartman #define DAS6402_STATUS_FFULL BIT(2)
458ffdff6aSGreg Kroah-Hartman #define DAS6402_STATUS_XINT BIT(3)
468ffdff6aSGreg Kroah-Hartman #define DAS6402_STATUS_INT BIT(4)
478ffdff6aSGreg Kroah-Hartman #define DAS6402_STATUS_XTRIG BIT(5)
488ffdff6aSGreg Kroah-Hartman #define DAS6402_STATUS_INDGT BIT(6)
498ffdff6aSGreg Kroah-Hartman #define DAS6402_STATUS_10MHZ BIT(7)
508ffdff6aSGreg Kroah-Hartman #define DAS6402_STATUS_W_CLRINT BIT(0)
518ffdff6aSGreg Kroah-Hartman #define DAS6402_STATUS_W_CLRXTR BIT(1)
528ffdff6aSGreg Kroah-Hartman #define DAS6402_STATUS_W_CLRXIN BIT(2)
538ffdff6aSGreg Kroah-Hartman #define DAS6402_STATUS_W_EXTEND BIT(4)
548ffdff6aSGreg Kroah-Hartman #define DAS6402_STATUS_W_ARMED BIT(5)
558ffdff6aSGreg Kroah-Hartman #define DAS6402_STATUS_W_POSTMODE BIT(6)
568ffdff6aSGreg Kroah-Hartman #define DAS6402_STATUS_W_10MHZ BIT(7)
578ffdff6aSGreg Kroah-Hartman #define DAS6402_CTRL_REG 0x09
588ffdff6aSGreg Kroah-Hartman #define DAS6402_CTRL_TRIG(x) ((x) << 0)
598ffdff6aSGreg Kroah-Hartman #define DAS6402_CTRL_SOFT_TRIG DAS6402_CTRL_TRIG(0)
608ffdff6aSGreg Kroah-Hartman #define DAS6402_CTRL_EXT_FALL_TRIG DAS6402_CTRL_TRIG(1)
618ffdff6aSGreg Kroah-Hartman #define DAS6402_CTRL_EXT_RISE_TRIG DAS6402_CTRL_TRIG(2)
628ffdff6aSGreg Kroah-Hartman #define DAS6402_CTRL_PACER_TRIG DAS6402_CTRL_TRIG(3)
638ffdff6aSGreg Kroah-Hartman #define DAS6402_CTRL_BURSTEN BIT(2)
648ffdff6aSGreg Kroah-Hartman #define DAS6402_CTRL_XINTE BIT(3)
658ffdff6aSGreg Kroah-Hartman #define DAS6402_CTRL_IRQ(x) ((x) << 4)
668ffdff6aSGreg Kroah-Hartman #define DAS6402_CTRL_INTE BIT(7)
678ffdff6aSGreg Kroah-Hartman #define DAS6402_TRIG_REG 0x0a
688ffdff6aSGreg Kroah-Hartman #define DAS6402_TRIG_TGEN BIT(0)
698ffdff6aSGreg Kroah-Hartman #define DAS6402_TRIG_TGSEL BIT(1)
708ffdff6aSGreg Kroah-Hartman #define DAS6402_TRIG_TGPOL BIT(2)
718ffdff6aSGreg Kroah-Hartman #define DAS6402_TRIG_PRETRIG BIT(3)
728ffdff6aSGreg Kroah-Hartman #define DAS6402_AO_RANGE(_chan, _range) ((_range) << ((_chan) ? 6 : 4))
738ffdff6aSGreg Kroah-Hartman #define DAS6402_AO_RANGE_MASK(_chan) (3 << ((_chan) ? 6 : 4))
748ffdff6aSGreg Kroah-Hartman #define DAS6402_MODE_REG 0x0b
758ffdff6aSGreg Kroah-Hartman #define DAS6402_MODE_RANGE(x) ((x) << 2)
768ffdff6aSGreg Kroah-Hartman #define DAS6402_MODE_POLLED DAS6402_MODE_RANGE(0)
778ffdff6aSGreg Kroah-Hartman #define DAS6402_MODE_FIFONEPTY DAS6402_MODE_RANGE(1)
788ffdff6aSGreg Kroah-Hartman #define DAS6402_MODE_FIFOHFULL DAS6402_MODE_RANGE(2)
798ffdff6aSGreg Kroah-Hartman #define DAS6402_MODE_EOB DAS6402_MODE_RANGE(3)
808ffdff6aSGreg Kroah-Hartman #define DAS6402_MODE_ENHANCED BIT(4)
818ffdff6aSGreg Kroah-Hartman #define DAS6402_MODE_SE BIT(5)
828ffdff6aSGreg Kroah-Hartman #define DAS6402_MODE_UNI BIT(6)
838ffdff6aSGreg Kroah-Hartman #define DAS6402_MODE_DMA(x) ((x) << 7)
848ffdff6aSGreg Kroah-Hartman #define DAS6402_MODE_DMA1 DAS6402_MODE_DMA(0)
858ffdff6aSGreg Kroah-Hartman #define DAS6402_MODE_DMA3 DAS6402_MODE_DMA(1)
868ffdff6aSGreg Kroah-Hartman #define DAS6402_TIMER_BASE 0x0c
878ffdff6aSGreg Kroah-Hartman
888ffdff6aSGreg Kroah-Hartman static const struct comedi_lrange das6402_ai_ranges = {
898ffdff6aSGreg Kroah-Hartman 8, {
908ffdff6aSGreg Kroah-Hartman BIP_RANGE(10),
918ffdff6aSGreg Kroah-Hartman BIP_RANGE(5),
928ffdff6aSGreg Kroah-Hartman BIP_RANGE(2.5),
938ffdff6aSGreg Kroah-Hartman BIP_RANGE(1.25),
948ffdff6aSGreg Kroah-Hartman UNI_RANGE(10),
958ffdff6aSGreg Kroah-Hartman UNI_RANGE(5),
968ffdff6aSGreg Kroah-Hartman UNI_RANGE(2.5),
978ffdff6aSGreg Kroah-Hartman UNI_RANGE(1.25)
988ffdff6aSGreg Kroah-Hartman }
998ffdff6aSGreg Kroah-Hartman };
1008ffdff6aSGreg Kroah-Hartman
1018ffdff6aSGreg Kroah-Hartman /*
1028ffdff6aSGreg Kroah-Hartman * Analog output ranges are programmable on the DAS6402/12.
1038ffdff6aSGreg Kroah-Hartman * For the DAS6402/16 the range bits have no function, the
1048ffdff6aSGreg Kroah-Hartman * DAC ranges are selected by switches on the board.
1058ffdff6aSGreg Kroah-Hartman */
1068ffdff6aSGreg Kroah-Hartman static const struct comedi_lrange das6402_ao_ranges = {
1078ffdff6aSGreg Kroah-Hartman 4, {
1088ffdff6aSGreg Kroah-Hartman BIP_RANGE(5),
1098ffdff6aSGreg Kroah-Hartman BIP_RANGE(10),
1108ffdff6aSGreg Kroah-Hartman UNI_RANGE(5),
1118ffdff6aSGreg Kroah-Hartman UNI_RANGE(10)
1128ffdff6aSGreg Kroah-Hartman }
1138ffdff6aSGreg Kroah-Hartman };
1148ffdff6aSGreg Kroah-Hartman
1158ffdff6aSGreg Kroah-Hartman struct das6402_boardinfo {
1168ffdff6aSGreg Kroah-Hartman const char *name;
1178ffdff6aSGreg Kroah-Hartman unsigned int maxdata;
1188ffdff6aSGreg Kroah-Hartman };
1198ffdff6aSGreg Kroah-Hartman
1208ffdff6aSGreg Kroah-Hartman static struct das6402_boardinfo das6402_boards[] = {
1218ffdff6aSGreg Kroah-Hartman {
1228ffdff6aSGreg Kroah-Hartman .name = "das6402-12",
1238ffdff6aSGreg Kroah-Hartman .maxdata = 0x0fff,
1248ffdff6aSGreg Kroah-Hartman }, {
1258ffdff6aSGreg Kroah-Hartman .name = "das6402-16",
1268ffdff6aSGreg Kroah-Hartman .maxdata = 0xffff,
1278ffdff6aSGreg Kroah-Hartman },
1288ffdff6aSGreg Kroah-Hartman };
1298ffdff6aSGreg Kroah-Hartman
1308ffdff6aSGreg Kroah-Hartman struct das6402_private {
1318ffdff6aSGreg Kroah-Hartman unsigned int irq;
1328ffdff6aSGreg Kroah-Hartman unsigned int ao_range;
1338ffdff6aSGreg Kroah-Hartman };
1348ffdff6aSGreg Kroah-Hartman
das6402_set_mode(struct comedi_device * dev,unsigned int mode)1358ffdff6aSGreg Kroah-Hartman static void das6402_set_mode(struct comedi_device *dev,
1368ffdff6aSGreg Kroah-Hartman unsigned int mode)
1378ffdff6aSGreg Kroah-Hartman {
1388ffdff6aSGreg Kroah-Hartman outb(DAS6402_MODE_ENHANCED | mode, dev->iobase + DAS6402_MODE_REG);
1398ffdff6aSGreg Kroah-Hartman }
1408ffdff6aSGreg Kroah-Hartman
das6402_set_extended(struct comedi_device * dev,unsigned int val)1418ffdff6aSGreg Kroah-Hartman static void das6402_set_extended(struct comedi_device *dev,
1428ffdff6aSGreg Kroah-Hartman unsigned int val)
1438ffdff6aSGreg Kroah-Hartman {
1448ffdff6aSGreg Kroah-Hartman outb(DAS6402_STATUS_W_EXTEND, dev->iobase + DAS6402_STATUS_REG);
1458ffdff6aSGreg Kroah-Hartman outb(DAS6402_STATUS_W_EXTEND | val, dev->iobase + DAS6402_STATUS_REG);
1468ffdff6aSGreg Kroah-Hartman outb(val, dev->iobase + DAS6402_STATUS_REG);
1478ffdff6aSGreg Kroah-Hartman }
1488ffdff6aSGreg Kroah-Hartman
das6402_clear_all_interrupts(struct comedi_device * dev)1498ffdff6aSGreg Kroah-Hartman static void das6402_clear_all_interrupts(struct comedi_device *dev)
1508ffdff6aSGreg Kroah-Hartman {
1518ffdff6aSGreg Kroah-Hartman outb(DAS6402_STATUS_W_CLRINT |
1528ffdff6aSGreg Kroah-Hartman DAS6402_STATUS_W_CLRXTR |
1538ffdff6aSGreg Kroah-Hartman DAS6402_STATUS_W_CLRXIN, dev->iobase + DAS6402_STATUS_REG);
1548ffdff6aSGreg Kroah-Hartman }
1558ffdff6aSGreg Kroah-Hartman
das6402_ai_clear_eoc(struct comedi_device * dev)1568ffdff6aSGreg Kroah-Hartman static void das6402_ai_clear_eoc(struct comedi_device *dev)
1578ffdff6aSGreg Kroah-Hartman {
1588ffdff6aSGreg Kroah-Hartman outb(DAS6402_STATUS_W_CLRINT, dev->iobase + DAS6402_STATUS_REG);
1598ffdff6aSGreg Kroah-Hartman }
1608ffdff6aSGreg Kroah-Hartman
das6402_ai_read_sample(struct comedi_device * dev,struct comedi_subdevice * s)1618ffdff6aSGreg Kroah-Hartman static unsigned int das6402_ai_read_sample(struct comedi_device *dev,
1628ffdff6aSGreg Kroah-Hartman struct comedi_subdevice *s)
1638ffdff6aSGreg Kroah-Hartman {
1648ffdff6aSGreg Kroah-Hartman unsigned int val;
1658ffdff6aSGreg Kroah-Hartman
1668ffdff6aSGreg Kroah-Hartman val = inw(dev->iobase + DAS6402_AI_DATA_REG);
1678ffdff6aSGreg Kroah-Hartman if (s->maxdata == 0x0fff)
1688ffdff6aSGreg Kroah-Hartman val >>= 4;
1698ffdff6aSGreg Kroah-Hartman return val;
1708ffdff6aSGreg Kroah-Hartman }
1718ffdff6aSGreg Kroah-Hartman
das6402_interrupt(int irq,void * d)1728ffdff6aSGreg Kroah-Hartman static irqreturn_t das6402_interrupt(int irq, void *d)
1738ffdff6aSGreg Kroah-Hartman {
1748ffdff6aSGreg Kroah-Hartman struct comedi_device *dev = d;
1758ffdff6aSGreg Kroah-Hartman struct comedi_subdevice *s = dev->read_subdev;
1768ffdff6aSGreg Kroah-Hartman struct comedi_async *async = s->async;
1778ffdff6aSGreg Kroah-Hartman struct comedi_cmd *cmd = &async->cmd;
1788ffdff6aSGreg Kroah-Hartman unsigned int status;
1798ffdff6aSGreg Kroah-Hartman
1808ffdff6aSGreg Kroah-Hartman status = inb(dev->iobase + DAS6402_STATUS_REG);
1818ffdff6aSGreg Kroah-Hartman if ((status & DAS6402_STATUS_INT) == 0)
1828ffdff6aSGreg Kroah-Hartman return IRQ_NONE;
1838ffdff6aSGreg Kroah-Hartman
1848ffdff6aSGreg Kroah-Hartman if (status & DAS6402_STATUS_FFULL) {
1858ffdff6aSGreg Kroah-Hartman async->events |= COMEDI_CB_OVERFLOW;
1868ffdff6aSGreg Kroah-Hartman } else if (status & DAS6402_STATUS_FFNE) {
1878ffdff6aSGreg Kroah-Hartman unsigned short val;
1888ffdff6aSGreg Kroah-Hartman
1898ffdff6aSGreg Kroah-Hartman val = das6402_ai_read_sample(dev, s);
1908ffdff6aSGreg Kroah-Hartman comedi_buf_write_samples(s, &val, 1);
1918ffdff6aSGreg Kroah-Hartman
1928ffdff6aSGreg Kroah-Hartman if (cmd->stop_src == TRIG_COUNT &&
1938ffdff6aSGreg Kroah-Hartman async->scans_done >= cmd->stop_arg)
1948ffdff6aSGreg Kroah-Hartman async->events |= COMEDI_CB_EOA;
1958ffdff6aSGreg Kroah-Hartman }
1968ffdff6aSGreg Kroah-Hartman
1978ffdff6aSGreg Kroah-Hartman das6402_clear_all_interrupts(dev);
1988ffdff6aSGreg Kroah-Hartman
1998ffdff6aSGreg Kroah-Hartman comedi_handle_events(dev, s);
2008ffdff6aSGreg Kroah-Hartman
2018ffdff6aSGreg Kroah-Hartman return IRQ_HANDLED;
2028ffdff6aSGreg Kroah-Hartman }
2038ffdff6aSGreg Kroah-Hartman
das6402_ai_set_mode(struct comedi_device * dev,struct comedi_subdevice * s,unsigned int chanspec,unsigned int mode)2048ffdff6aSGreg Kroah-Hartman static void das6402_ai_set_mode(struct comedi_device *dev,
2058ffdff6aSGreg Kroah-Hartman struct comedi_subdevice *s,
2068ffdff6aSGreg Kroah-Hartman unsigned int chanspec,
2078ffdff6aSGreg Kroah-Hartman unsigned int mode)
2088ffdff6aSGreg Kroah-Hartman {
2098ffdff6aSGreg Kroah-Hartman unsigned int range = CR_RANGE(chanspec);
2108ffdff6aSGreg Kroah-Hartman unsigned int aref = CR_AREF(chanspec);
2118ffdff6aSGreg Kroah-Hartman
2128ffdff6aSGreg Kroah-Hartman mode |= DAS6402_MODE_RANGE(range);
2138ffdff6aSGreg Kroah-Hartman if (aref == AREF_GROUND)
2148ffdff6aSGreg Kroah-Hartman mode |= DAS6402_MODE_SE;
2158ffdff6aSGreg Kroah-Hartman if (comedi_range_is_unipolar(s, range))
2168ffdff6aSGreg Kroah-Hartman mode |= DAS6402_MODE_UNI;
2178ffdff6aSGreg Kroah-Hartman
2188ffdff6aSGreg Kroah-Hartman das6402_set_mode(dev, mode);
2198ffdff6aSGreg Kroah-Hartman }
2208ffdff6aSGreg Kroah-Hartman
das6402_ai_cmd(struct comedi_device * dev,struct comedi_subdevice * s)2218ffdff6aSGreg Kroah-Hartman static int das6402_ai_cmd(struct comedi_device *dev,
2228ffdff6aSGreg Kroah-Hartman struct comedi_subdevice *s)
2238ffdff6aSGreg Kroah-Hartman {
2248ffdff6aSGreg Kroah-Hartman struct das6402_private *devpriv = dev->private;
2258ffdff6aSGreg Kroah-Hartman struct comedi_cmd *cmd = &s->async->cmd;
2268ffdff6aSGreg Kroah-Hartman unsigned int chan_lo = CR_CHAN(cmd->chanlist[0]);
2278ffdff6aSGreg Kroah-Hartman unsigned int chan_hi = CR_CHAN(cmd->chanlist[cmd->chanlist_len - 1]);
2288ffdff6aSGreg Kroah-Hartman
2298ffdff6aSGreg Kroah-Hartman das6402_ai_set_mode(dev, s, cmd->chanlist[0], DAS6402_MODE_FIFONEPTY);
2308ffdff6aSGreg Kroah-Hartman
2318ffdff6aSGreg Kroah-Hartman /* load the mux for chanlist conversion */
2328ffdff6aSGreg Kroah-Hartman outw(DAS6402_AI_MUX_HI(chan_hi) | DAS6402_AI_MUX_LO(chan_lo),
2338ffdff6aSGreg Kroah-Hartman dev->iobase + DAS6402_AI_MUX_REG);
2348ffdff6aSGreg Kroah-Hartman
2358ffdff6aSGreg Kroah-Hartman comedi_8254_update_divisors(dev->pacer);
2368ffdff6aSGreg Kroah-Hartman comedi_8254_pacer_enable(dev->pacer, 1, 2, true);
2378ffdff6aSGreg Kroah-Hartman
2388ffdff6aSGreg Kroah-Hartman /* enable interrupt and pacer trigger */
2398ffdff6aSGreg Kroah-Hartman outb(DAS6402_CTRL_INTE |
2408ffdff6aSGreg Kroah-Hartman DAS6402_CTRL_IRQ(devpriv->irq) |
2418ffdff6aSGreg Kroah-Hartman DAS6402_CTRL_PACER_TRIG, dev->iobase + DAS6402_CTRL_REG);
2428ffdff6aSGreg Kroah-Hartman
2438ffdff6aSGreg Kroah-Hartman return 0;
2448ffdff6aSGreg Kroah-Hartman }
2458ffdff6aSGreg Kroah-Hartman
das6402_ai_check_chanlist(struct comedi_device * dev,struct comedi_subdevice * s,struct comedi_cmd * cmd)2468ffdff6aSGreg Kroah-Hartman static int das6402_ai_check_chanlist(struct comedi_device *dev,
2478ffdff6aSGreg Kroah-Hartman struct comedi_subdevice *s,
2488ffdff6aSGreg Kroah-Hartman struct comedi_cmd *cmd)
2498ffdff6aSGreg Kroah-Hartman {
2508ffdff6aSGreg Kroah-Hartman unsigned int chan0 = CR_CHAN(cmd->chanlist[0]);
2518ffdff6aSGreg Kroah-Hartman unsigned int range0 = CR_RANGE(cmd->chanlist[0]);
2528ffdff6aSGreg Kroah-Hartman unsigned int aref0 = CR_AREF(cmd->chanlist[0]);
2538ffdff6aSGreg Kroah-Hartman int i;
2548ffdff6aSGreg Kroah-Hartman
2558ffdff6aSGreg Kroah-Hartman for (i = 1; i < cmd->chanlist_len; i++) {
2568ffdff6aSGreg Kroah-Hartman unsigned int chan = CR_CHAN(cmd->chanlist[i]);
2578ffdff6aSGreg Kroah-Hartman unsigned int range = CR_RANGE(cmd->chanlist[i]);
2588ffdff6aSGreg Kroah-Hartman unsigned int aref = CR_AREF(cmd->chanlist[i]);
2598ffdff6aSGreg Kroah-Hartman
2608ffdff6aSGreg Kroah-Hartman if (chan != chan0 + i) {
2618ffdff6aSGreg Kroah-Hartman dev_dbg(dev->class_dev,
2628ffdff6aSGreg Kroah-Hartman "chanlist must be consecutive\n");
2638ffdff6aSGreg Kroah-Hartman return -EINVAL;
2648ffdff6aSGreg Kroah-Hartman }
2658ffdff6aSGreg Kroah-Hartman
2668ffdff6aSGreg Kroah-Hartman if (range != range0) {
2678ffdff6aSGreg Kroah-Hartman dev_dbg(dev->class_dev,
2688ffdff6aSGreg Kroah-Hartman "chanlist must have the same range\n");
2698ffdff6aSGreg Kroah-Hartman return -EINVAL;
2708ffdff6aSGreg Kroah-Hartman }
2718ffdff6aSGreg Kroah-Hartman
2728ffdff6aSGreg Kroah-Hartman if (aref != aref0) {
2738ffdff6aSGreg Kroah-Hartman dev_dbg(dev->class_dev,
2748ffdff6aSGreg Kroah-Hartman "chanlist must have the same reference\n");
2758ffdff6aSGreg Kroah-Hartman return -EINVAL;
2768ffdff6aSGreg Kroah-Hartman }
2778ffdff6aSGreg Kroah-Hartman
2788ffdff6aSGreg Kroah-Hartman if (aref0 == AREF_DIFF && chan > (s->n_chan / 2)) {
2798ffdff6aSGreg Kroah-Hartman dev_dbg(dev->class_dev,
2808ffdff6aSGreg Kroah-Hartman "chanlist differential channel too large\n");
2818ffdff6aSGreg Kroah-Hartman return -EINVAL;
2828ffdff6aSGreg Kroah-Hartman }
2838ffdff6aSGreg Kroah-Hartman }
2848ffdff6aSGreg Kroah-Hartman return 0;
2858ffdff6aSGreg Kroah-Hartman }
2868ffdff6aSGreg Kroah-Hartman
das6402_ai_cmdtest(struct comedi_device * dev,struct comedi_subdevice * s,struct comedi_cmd * cmd)2878ffdff6aSGreg Kroah-Hartman static int das6402_ai_cmdtest(struct comedi_device *dev,
2888ffdff6aSGreg Kroah-Hartman struct comedi_subdevice *s,
2898ffdff6aSGreg Kroah-Hartman struct comedi_cmd *cmd)
2908ffdff6aSGreg Kroah-Hartman {
2918ffdff6aSGreg Kroah-Hartman int err = 0;
2928ffdff6aSGreg Kroah-Hartman unsigned int arg;
2938ffdff6aSGreg Kroah-Hartman
2948ffdff6aSGreg Kroah-Hartman /* Step 1 : check if triggers are trivially valid */
2958ffdff6aSGreg Kroah-Hartman
2968ffdff6aSGreg Kroah-Hartman err |= comedi_check_trigger_src(&cmd->start_src, TRIG_NOW);
2978ffdff6aSGreg Kroah-Hartman err |= comedi_check_trigger_src(&cmd->scan_begin_src, TRIG_FOLLOW);
2988ffdff6aSGreg Kroah-Hartman err |= comedi_check_trigger_src(&cmd->convert_src, TRIG_TIMER);
2998ffdff6aSGreg Kroah-Hartman err |= comedi_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
3008ffdff6aSGreg Kroah-Hartman err |= comedi_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
3018ffdff6aSGreg Kroah-Hartman
3028ffdff6aSGreg Kroah-Hartman if (err)
3038ffdff6aSGreg Kroah-Hartman return 1;
3048ffdff6aSGreg Kroah-Hartman
3058ffdff6aSGreg Kroah-Hartman /* Step 2a : make sure trigger sources are unique */
3068ffdff6aSGreg Kroah-Hartman
3078ffdff6aSGreg Kroah-Hartman err |= comedi_check_trigger_is_unique(cmd->stop_src);
3088ffdff6aSGreg Kroah-Hartman
3098ffdff6aSGreg Kroah-Hartman /* Step 2b : and mutually compatible */
3108ffdff6aSGreg Kroah-Hartman
3118ffdff6aSGreg Kroah-Hartman if (err)
3128ffdff6aSGreg Kroah-Hartman return 2;
3138ffdff6aSGreg Kroah-Hartman
3148ffdff6aSGreg Kroah-Hartman /* Step 3: check if arguments are trivially valid */
3158ffdff6aSGreg Kroah-Hartman
3168ffdff6aSGreg Kroah-Hartman err |= comedi_check_trigger_arg_is(&cmd->start_arg, 0);
3178ffdff6aSGreg Kroah-Hartman err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, 0);
3188ffdff6aSGreg Kroah-Hartman err |= comedi_check_trigger_arg_min(&cmd->convert_arg, 10000);
3198ffdff6aSGreg Kroah-Hartman err |= comedi_check_trigger_arg_min(&cmd->chanlist_len, 1);
3208ffdff6aSGreg Kroah-Hartman err |= comedi_check_trigger_arg_is(&cmd->scan_end_arg,
3218ffdff6aSGreg Kroah-Hartman cmd->chanlist_len);
3228ffdff6aSGreg Kroah-Hartman
3238ffdff6aSGreg Kroah-Hartman if (cmd->stop_src == TRIG_COUNT)
3248ffdff6aSGreg Kroah-Hartman err |= comedi_check_trigger_arg_min(&cmd->stop_arg, 1);
3258ffdff6aSGreg Kroah-Hartman else /* TRIG_NONE */
3268ffdff6aSGreg Kroah-Hartman err |= comedi_check_trigger_arg_is(&cmd->stop_arg, 0);
3278ffdff6aSGreg Kroah-Hartman
3288ffdff6aSGreg Kroah-Hartman if (err)
3298ffdff6aSGreg Kroah-Hartman return 3;
3308ffdff6aSGreg Kroah-Hartman
3318ffdff6aSGreg Kroah-Hartman /* step 4: fix up any arguments */
3328ffdff6aSGreg Kroah-Hartman
3338ffdff6aSGreg Kroah-Hartman arg = cmd->convert_arg;
3348ffdff6aSGreg Kroah-Hartman comedi_8254_cascade_ns_to_timer(dev->pacer, &arg, cmd->flags);
3358ffdff6aSGreg Kroah-Hartman err |= comedi_check_trigger_arg_is(&cmd->convert_arg, arg);
3368ffdff6aSGreg Kroah-Hartman
3378ffdff6aSGreg Kroah-Hartman if (err)
3388ffdff6aSGreg Kroah-Hartman return 4;
3398ffdff6aSGreg Kroah-Hartman
3408ffdff6aSGreg Kroah-Hartman /* Step 5: check channel list if it exists */
3418ffdff6aSGreg Kroah-Hartman if (cmd->chanlist && cmd->chanlist_len > 0)
3428ffdff6aSGreg Kroah-Hartman err |= das6402_ai_check_chanlist(dev, s, cmd);
3438ffdff6aSGreg Kroah-Hartman
3448ffdff6aSGreg Kroah-Hartman if (err)
3458ffdff6aSGreg Kroah-Hartman return 5;
3468ffdff6aSGreg Kroah-Hartman
3478ffdff6aSGreg Kroah-Hartman return 0;
3488ffdff6aSGreg Kroah-Hartman }
3498ffdff6aSGreg Kroah-Hartman
das6402_ai_cancel(struct comedi_device * dev,struct comedi_subdevice * s)3508ffdff6aSGreg Kroah-Hartman static int das6402_ai_cancel(struct comedi_device *dev,
3518ffdff6aSGreg Kroah-Hartman struct comedi_subdevice *s)
3528ffdff6aSGreg Kroah-Hartman {
3538ffdff6aSGreg Kroah-Hartman outb(DAS6402_CTRL_SOFT_TRIG, dev->iobase + DAS6402_CTRL_REG);
3548ffdff6aSGreg Kroah-Hartman
3558ffdff6aSGreg Kroah-Hartman return 0;
3568ffdff6aSGreg Kroah-Hartman }
3578ffdff6aSGreg Kroah-Hartman
das6402_ai_soft_trig(struct comedi_device * dev)3588ffdff6aSGreg Kroah-Hartman static void das6402_ai_soft_trig(struct comedi_device *dev)
3598ffdff6aSGreg Kroah-Hartman {
3608ffdff6aSGreg Kroah-Hartman outw(0, dev->iobase + DAS6402_AI_DATA_REG);
3618ffdff6aSGreg Kroah-Hartman }
3628ffdff6aSGreg Kroah-Hartman
das6402_ai_eoc(struct comedi_device * dev,struct comedi_subdevice * s,struct comedi_insn * insn,unsigned long context)3638ffdff6aSGreg Kroah-Hartman static int das6402_ai_eoc(struct comedi_device *dev,
3648ffdff6aSGreg Kroah-Hartman struct comedi_subdevice *s,
3658ffdff6aSGreg Kroah-Hartman struct comedi_insn *insn,
3668ffdff6aSGreg Kroah-Hartman unsigned long context)
3678ffdff6aSGreg Kroah-Hartman {
3688ffdff6aSGreg Kroah-Hartman unsigned int status;
3698ffdff6aSGreg Kroah-Hartman
3708ffdff6aSGreg Kroah-Hartman status = inb(dev->iobase + DAS6402_STATUS_REG);
3718ffdff6aSGreg Kroah-Hartman if (status & DAS6402_STATUS_FFNE)
3728ffdff6aSGreg Kroah-Hartman return 0;
3738ffdff6aSGreg Kroah-Hartman return -EBUSY;
3748ffdff6aSGreg Kroah-Hartman }
3758ffdff6aSGreg Kroah-Hartman
das6402_ai_insn_read(struct comedi_device * dev,struct comedi_subdevice * s,struct comedi_insn * insn,unsigned int * data)3768ffdff6aSGreg Kroah-Hartman static int das6402_ai_insn_read(struct comedi_device *dev,
3778ffdff6aSGreg Kroah-Hartman struct comedi_subdevice *s,
3788ffdff6aSGreg Kroah-Hartman struct comedi_insn *insn,
3798ffdff6aSGreg Kroah-Hartman unsigned int *data)
3808ffdff6aSGreg Kroah-Hartman {
3818ffdff6aSGreg Kroah-Hartman unsigned int chan = CR_CHAN(insn->chanspec);
3828ffdff6aSGreg Kroah-Hartman unsigned int aref = CR_AREF(insn->chanspec);
3838ffdff6aSGreg Kroah-Hartman int ret;
3848ffdff6aSGreg Kroah-Hartman int i;
3858ffdff6aSGreg Kroah-Hartman
3868ffdff6aSGreg Kroah-Hartman if (aref == AREF_DIFF && chan > (s->n_chan / 2))
3878ffdff6aSGreg Kroah-Hartman return -EINVAL;
3888ffdff6aSGreg Kroah-Hartman
3898ffdff6aSGreg Kroah-Hartman /* enable software conversion trigger */
3908ffdff6aSGreg Kroah-Hartman outb(DAS6402_CTRL_SOFT_TRIG, dev->iobase + DAS6402_CTRL_REG);
3918ffdff6aSGreg Kroah-Hartman
3928ffdff6aSGreg Kroah-Hartman das6402_ai_set_mode(dev, s, insn->chanspec, DAS6402_MODE_POLLED);
3938ffdff6aSGreg Kroah-Hartman
3948ffdff6aSGreg Kroah-Hartman /* load the mux for single channel conversion */
3958ffdff6aSGreg Kroah-Hartman outw(DAS6402_AI_MUX_HI(chan) | DAS6402_AI_MUX_LO(chan),
3968ffdff6aSGreg Kroah-Hartman dev->iobase + DAS6402_AI_MUX_REG);
3978ffdff6aSGreg Kroah-Hartman
3988ffdff6aSGreg Kroah-Hartman for (i = 0; i < insn->n; i++) {
3998ffdff6aSGreg Kroah-Hartman das6402_ai_clear_eoc(dev);
4008ffdff6aSGreg Kroah-Hartman das6402_ai_soft_trig(dev);
4018ffdff6aSGreg Kroah-Hartman
4028ffdff6aSGreg Kroah-Hartman ret = comedi_timeout(dev, s, insn, das6402_ai_eoc, 0);
4038ffdff6aSGreg Kroah-Hartman if (ret)
4048ffdff6aSGreg Kroah-Hartman break;
4058ffdff6aSGreg Kroah-Hartman
4068ffdff6aSGreg Kroah-Hartman data[i] = das6402_ai_read_sample(dev, s);
4078ffdff6aSGreg Kroah-Hartman }
4088ffdff6aSGreg Kroah-Hartman
4098ffdff6aSGreg Kroah-Hartman das6402_ai_clear_eoc(dev);
4108ffdff6aSGreg Kroah-Hartman
4118ffdff6aSGreg Kroah-Hartman return insn->n;
4128ffdff6aSGreg Kroah-Hartman }
4138ffdff6aSGreg Kroah-Hartman
das6402_ao_insn_write(struct comedi_device * dev,struct comedi_subdevice * s,struct comedi_insn * insn,unsigned int * data)4148ffdff6aSGreg Kroah-Hartman static int das6402_ao_insn_write(struct comedi_device *dev,
4158ffdff6aSGreg Kroah-Hartman struct comedi_subdevice *s,
4168ffdff6aSGreg Kroah-Hartman struct comedi_insn *insn,
4178ffdff6aSGreg Kroah-Hartman unsigned int *data)
4188ffdff6aSGreg Kroah-Hartman {
4198ffdff6aSGreg Kroah-Hartman struct das6402_private *devpriv = dev->private;
4208ffdff6aSGreg Kroah-Hartman unsigned int chan = CR_CHAN(insn->chanspec);
4218ffdff6aSGreg Kroah-Hartman unsigned int range = CR_RANGE(insn->chanspec);
4228ffdff6aSGreg Kroah-Hartman unsigned int val;
4238ffdff6aSGreg Kroah-Hartman int i;
4248ffdff6aSGreg Kroah-Hartman
4258ffdff6aSGreg Kroah-Hartman /* set the range for this channel */
4268ffdff6aSGreg Kroah-Hartman val = devpriv->ao_range;
4278ffdff6aSGreg Kroah-Hartman val &= ~DAS6402_AO_RANGE_MASK(chan);
4288ffdff6aSGreg Kroah-Hartman val |= DAS6402_AO_RANGE(chan, range);
4298ffdff6aSGreg Kroah-Hartman if (val != devpriv->ao_range) {
4308ffdff6aSGreg Kroah-Hartman devpriv->ao_range = val;
4318ffdff6aSGreg Kroah-Hartman outb(val, dev->iobase + DAS6402_TRIG_REG);
4328ffdff6aSGreg Kroah-Hartman }
4338ffdff6aSGreg Kroah-Hartman
4348ffdff6aSGreg Kroah-Hartman /*
4358ffdff6aSGreg Kroah-Hartman * The DAS6402/16 has a jumper to select either individual
4368ffdff6aSGreg Kroah-Hartman * update (UPDATE) or simultaneous updating (XFER) of both
4378ffdff6aSGreg Kroah-Hartman * DAC's. In UPDATE mode, when the MSB is written, that DAC
4388ffdff6aSGreg Kroah-Hartman * is updated. In XFER mode, after both DAC's are loaded,
4398ffdff6aSGreg Kroah-Hartman * a read cycle of any DAC register will update both DAC's
4408ffdff6aSGreg Kroah-Hartman * simultaneously.
4418ffdff6aSGreg Kroah-Hartman *
4428ffdff6aSGreg Kroah-Hartman * If you have XFER mode enabled a (*insn_read) will need
4438ffdff6aSGreg Kroah-Hartman * to be performed in order to update the DAC's with the
4448ffdff6aSGreg Kroah-Hartman * last value written.
4458ffdff6aSGreg Kroah-Hartman */
4468ffdff6aSGreg Kroah-Hartman for (i = 0; i < insn->n; i++) {
4478ffdff6aSGreg Kroah-Hartman val = data[i];
4488ffdff6aSGreg Kroah-Hartman
4498ffdff6aSGreg Kroah-Hartman s->readback[chan] = val;
4508ffdff6aSGreg Kroah-Hartman
4518ffdff6aSGreg Kroah-Hartman if (s->maxdata == 0x0fff) {
4528ffdff6aSGreg Kroah-Hartman /*
4538ffdff6aSGreg Kroah-Hartman * DAS6402/12 has the two 8-bit DAC registers, left
4548ffdff6aSGreg Kroah-Hartman * justified (the 4 LSB bits are don't care). Data
4558ffdff6aSGreg Kroah-Hartman * can be written as one word.
4568ffdff6aSGreg Kroah-Hartman */
4578ffdff6aSGreg Kroah-Hartman val <<= 4;
4588ffdff6aSGreg Kroah-Hartman outw(val, dev->iobase + DAS6402_AO_DATA_REG(chan));
4598ffdff6aSGreg Kroah-Hartman } else {
4608ffdff6aSGreg Kroah-Hartman /*
4618ffdff6aSGreg Kroah-Hartman * DAS6402/16 uses both 8-bit DAC registers and needs
4628ffdff6aSGreg Kroah-Hartman * to be written LSB then MSB.
4638ffdff6aSGreg Kroah-Hartman */
4648ffdff6aSGreg Kroah-Hartman outb(val & 0xff,
4658ffdff6aSGreg Kroah-Hartman dev->iobase + DAS6402_AO_LSB_REG(chan));
4668ffdff6aSGreg Kroah-Hartman outb((val >> 8) & 0xff,
4678ffdff6aSGreg Kroah-Hartman dev->iobase + DAS6402_AO_LSB_REG(chan));
4688ffdff6aSGreg Kroah-Hartman }
4698ffdff6aSGreg Kroah-Hartman }
4708ffdff6aSGreg Kroah-Hartman
4718ffdff6aSGreg Kroah-Hartman return insn->n;
4728ffdff6aSGreg Kroah-Hartman }
4738ffdff6aSGreg Kroah-Hartman
das6402_ao_insn_read(struct comedi_device * dev,struct comedi_subdevice * s,struct comedi_insn * insn,unsigned int * data)4748ffdff6aSGreg Kroah-Hartman static int das6402_ao_insn_read(struct comedi_device *dev,
4758ffdff6aSGreg Kroah-Hartman struct comedi_subdevice *s,
4768ffdff6aSGreg Kroah-Hartman struct comedi_insn *insn,
4778ffdff6aSGreg Kroah-Hartman unsigned int *data)
4788ffdff6aSGreg Kroah-Hartman {
4798ffdff6aSGreg Kroah-Hartman unsigned int chan = CR_CHAN(insn->chanspec);
4808ffdff6aSGreg Kroah-Hartman
4818ffdff6aSGreg Kroah-Hartman /*
4828ffdff6aSGreg Kroah-Hartman * If XFER mode is enabled, reading any DAC register
4838ffdff6aSGreg Kroah-Hartman * will update both DAC's simultaneously.
4848ffdff6aSGreg Kroah-Hartman */
4858ffdff6aSGreg Kroah-Hartman inw(dev->iobase + DAS6402_AO_LSB_REG(chan));
4868ffdff6aSGreg Kroah-Hartman
4878ffdff6aSGreg Kroah-Hartman return comedi_readback_insn_read(dev, s, insn, data);
4888ffdff6aSGreg Kroah-Hartman }
4898ffdff6aSGreg Kroah-Hartman
das6402_di_insn_bits(struct comedi_device * dev,struct comedi_subdevice * s,struct comedi_insn * insn,unsigned int * data)4908ffdff6aSGreg Kroah-Hartman static int das6402_di_insn_bits(struct comedi_device *dev,
4918ffdff6aSGreg Kroah-Hartman struct comedi_subdevice *s,
4928ffdff6aSGreg Kroah-Hartman struct comedi_insn *insn,
4938ffdff6aSGreg Kroah-Hartman unsigned int *data)
4948ffdff6aSGreg Kroah-Hartman {
4958ffdff6aSGreg Kroah-Hartman data[1] = inb(dev->iobase + DAS6402_DI_DO_REG);
4968ffdff6aSGreg Kroah-Hartman
4978ffdff6aSGreg Kroah-Hartman return insn->n;
4988ffdff6aSGreg Kroah-Hartman }
4998ffdff6aSGreg Kroah-Hartman
das6402_do_insn_bits(struct comedi_device * dev,struct comedi_subdevice * s,struct comedi_insn * insn,unsigned int * data)5008ffdff6aSGreg Kroah-Hartman static int das6402_do_insn_bits(struct comedi_device *dev,
5018ffdff6aSGreg Kroah-Hartman struct comedi_subdevice *s,
5028ffdff6aSGreg Kroah-Hartman struct comedi_insn *insn,
5038ffdff6aSGreg Kroah-Hartman unsigned int *data)
5048ffdff6aSGreg Kroah-Hartman {
5058ffdff6aSGreg Kroah-Hartman if (comedi_dio_update_state(s, data))
5068ffdff6aSGreg Kroah-Hartman outb(s->state, dev->iobase + DAS6402_DI_DO_REG);
5078ffdff6aSGreg Kroah-Hartman
5088ffdff6aSGreg Kroah-Hartman data[1] = s->state;
5098ffdff6aSGreg Kroah-Hartman
5108ffdff6aSGreg Kroah-Hartman return insn->n;
5118ffdff6aSGreg Kroah-Hartman }
5128ffdff6aSGreg Kroah-Hartman
das6402_reset(struct comedi_device * dev)5138ffdff6aSGreg Kroah-Hartman static void das6402_reset(struct comedi_device *dev)
5148ffdff6aSGreg Kroah-Hartman {
5158ffdff6aSGreg Kroah-Hartman struct das6402_private *devpriv = dev->private;
5168ffdff6aSGreg Kroah-Hartman
5178ffdff6aSGreg Kroah-Hartman /* enable "Enhanced" mode */
5188ffdff6aSGreg Kroah-Hartman outb(DAS6402_MODE_ENHANCED, dev->iobase + DAS6402_MODE_REG);
5198ffdff6aSGreg Kroah-Hartman
5208ffdff6aSGreg Kroah-Hartman /* enable 10MHz pacer clock */
5218ffdff6aSGreg Kroah-Hartman das6402_set_extended(dev, DAS6402_STATUS_W_10MHZ);
5228ffdff6aSGreg Kroah-Hartman
5238ffdff6aSGreg Kroah-Hartman /* enable software conversion trigger */
5248ffdff6aSGreg Kroah-Hartman outb(DAS6402_CTRL_SOFT_TRIG, dev->iobase + DAS6402_CTRL_REG);
5258ffdff6aSGreg Kroah-Hartman
5268ffdff6aSGreg Kroah-Hartman /* default ADC to single-ended unipolar 10V inputs */
5278ffdff6aSGreg Kroah-Hartman das6402_set_mode(dev, DAS6402_MODE_RANGE(0) |
5288ffdff6aSGreg Kroah-Hartman DAS6402_MODE_POLLED |
5298ffdff6aSGreg Kroah-Hartman DAS6402_MODE_SE |
5308ffdff6aSGreg Kroah-Hartman DAS6402_MODE_UNI);
5318ffdff6aSGreg Kroah-Hartman
5328ffdff6aSGreg Kroah-Hartman /* default mux for single channel conversion (channel 0) */
5338ffdff6aSGreg Kroah-Hartman outw(DAS6402_AI_MUX_HI(0) | DAS6402_AI_MUX_LO(0),
5348ffdff6aSGreg Kroah-Hartman dev->iobase + DAS6402_AI_MUX_REG);
5358ffdff6aSGreg Kroah-Hartman
5368ffdff6aSGreg Kroah-Hartman /* set both DAC's for unipolar 5V output range */
5378ffdff6aSGreg Kroah-Hartman devpriv->ao_range = DAS6402_AO_RANGE(0, 2) | DAS6402_AO_RANGE(1, 2);
5388ffdff6aSGreg Kroah-Hartman outb(devpriv->ao_range, dev->iobase + DAS6402_TRIG_REG);
5398ffdff6aSGreg Kroah-Hartman
5408ffdff6aSGreg Kroah-Hartman /* set both DAC's to 0V */
5418ffdff6aSGreg Kroah-Hartman outw(0, dev->iobase + DAS6402_AO_DATA_REG(0));
5428ffdff6aSGreg Kroah-Hartman outw(0, dev->iobase + DAS6402_AO_DATA_REG(0));
5438ffdff6aSGreg Kroah-Hartman inw(dev->iobase + DAS6402_AO_LSB_REG(0));
5448ffdff6aSGreg Kroah-Hartman
5458ffdff6aSGreg Kroah-Hartman /* set all digital outputs low */
5468ffdff6aSGreg Kroah-Hartman outb(0, dev->iobase + DAS6402_DI_DO_REG);
5478ffdff6aSGreg Kroah-Hartman
5488ffdff6aSGreg Kroah-Hartman das6402_clear_all_interrupts(dev);
5498ffdff6aSGreg Kroah-Hartman }
5508ffdff6aSGreg Kroah-Hartman
das6402_attach(struct comedi_device * dev,struct comedi_devconfig * it)5518ffdff6aSGreg Kroah-Hartman static int das6402_attach(struct comedi_device *dev,
5528ffdff6aSGreg Kroah-Hartman struct comedi_devconfig *it)
5538ffdff6aSGreg Kroah-Hartman {
5548ffdff6aSGreg Kroah-Hartman const struct das6402_boardinfo *board = dev->board_ptr;
5558ffdff6aSGreg Kroah-Hartman struct das6402_private *devpriv;
5568ffdff6aSGreg Kroah-Hartman struct comedi_subdevice *s;
5578ffdff6aSGreg Kroah-Hartman int ret;
5588ffdff6aSGreg Kroah-Hartman
5598ffdff6aSGreg Kroah-Hartman devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
5608ffdff6aSGreg Kroah-Hartman if (!devpriv)
5618ffdff6aSGreg Kroah-Hartman return -ENOMEM;
5628ffdff6aSGreg Kroah-Hartman
5638ffdff6aSGreg Kroah-Hartman ret = comedi_request_region(dev, it->options[0], 0x10);
5648ffdff6aSGreg Kroah-Hartman if (ret)
5658ffdff6aSGreg Kroah-Hartman return ret;
5668ffdff6aSGreg Kroah-Hartman
5678ffdff6aSGreg Kroah-Hartman das6402_reset(dev);
5688ffdff6aSGreg Kroah-Hartman
5698ffdff6aSGreg Kroah-Hartman /* IRQs 2,3,5,6,7, 10,11,15 are valid for "enhanced" mode */
5708ffdff6aSGreg Kroah-Hartman if ((1 << it->options[1]) & 0x8cec) {
5718ffdff6aSGreg Kroah-Hartman ret = request_irq(it->options[1], das6402_interrupt, 0,
5728ffdff6aSGreg Kroah-Hartman dev->board_name, dev);
5738ffdff6aSGreg Kroah-Hartman if (ret == 0) {
5748ffdff6aSGreg Kroah-Hartman dev->irq = it->options[1];
5758ffdff6aSGreg Kroah-Hartman
5768ffdff6aSGreg Kroah-Hartman switch (dev->irq) {
5778ffdff6aSGreg Kroah-Hartman case 10:
5788ffdff6aSGreg Kroah-Hartman devpriv->irq = 4;
5798ffdff6aSGreg Kroah-Hartman break;
5808ffdff6aSGreg Kroah-Hartman case 11:
5818ffdff6aSGreg Kroah-Hartman devpriv->irq = 1;
5828ffdff6aSGreg Kroah-Hartman break;
5838ffdff6aSGreg Kroah-Hartman case 15:
5848ffdff6aSGreg Kroah-Hartman devpriv->irq = 6;
5858ffdff6aSGreg Kroah-Hartman break;
5868ffdff6aSGreg Kroah-Hartman default:
5878ffdff6aSGreg Kroah-Hartman devpriv->irq = dev->irq;
5888ffdff6aSGreg Kroah-Hartman break;
5898ffdff6aSGreg Kroah-Hartman }
5908ffdff6aSGreg Kroah-Hartman }
5918ffdff6aSGreg Kroah-Hartman }
5928ffdff6aSGreg Kroah-Hartman
593*fade5e5bSIan Abbott dev->pacer = comedi_8254_io_alloc(dev->iobase + DAS6402_TIMER_BASE,
5948ffdff6aSGreg Kroah-Hartman I8254_OSC_BASE_10MHZ, I8254_IO8, 0);
595*fade5e5bSIan Abbott if (IS_ERR(dev->pacer))
596*fade5e5bSIan Abbott return PTR_ERR(dev->pacer);
5978ffdff6aSGreg Kroah-Hartman
5988ffdff6aSGreg Kroah-Hartman ret = comedi_alloc_subdevices(dev, 4);
5998ffdff6aSGreg Kroah-Hartman if (ret)
6008ffdff6aSGreg Kroah-Hartman return ret;
6018ffdff6aSGreg Kroah-Hartman
6028ffdff6aSGreg Kroah-Hartman /* Analog Input subdevice */
6038ffdff6aSGreg Kroah-Hartman s = &dev->subdevices[0];
6048ffdff6aSGreg Kroah-Hartman s->type = COMEDI_SUBD_AI;
6058ffdff6aSGreg Kroah-Hartman s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF;
6068ffdff6aSGreg Kroah-Hartman s->n_chan = 64;
6078ffdff6aSGreg Kroah-Hartman s->maxdata = board->maxdata;
6088ffdff6aSGreg Kroah-Hartman s->range_table = &das6402_ai_ranges;
6098ffdff6aSGreg Kroah-Hartman s->insn_read = das6402_ai_insn_read;
6108ffdff6aSGreg Kroah-Hartman if (dev->irq) {
6118ffdff6aSGreg Kroah-Hartman dev->read_subdev = s;
6128ffdff6aSGreg Kroah-Hartman s->subdev_flags |= SDF_CMD_READ;
6138ffdff6aSGreg Kroah-Hartman s->len_chanlist = s->n_chan;
6148ffdff6aSGreg Kroah-Hartman s->do_cmdtest = das6402_ai_cmdtest;
6158ffdff6aSGreg Kroah-Hartman s->do_cmd = das6402_ai_cmd;
6168ffdff6aSGreg Kroah-Hartman s->cancel = das6402_ai_cancel;
6178ffdff6aSGreg Kroah-Hartman }
6188ffdff6aSGreg Kroah-Hartman
6198ffdff6aSGreg Kroah-Hartman /* Analog Output subdevice */
6208ffdff6aSGreg Kroah-Hartman s = &dev->subdevices[1];
6218ffdff6aSGreg Kroah-Hartman s->type = COMEDI_SUBD_AO;
6228ffdff6aSGreg Kroah-Hartman s->subdev_flags = SDF_WRITABLE;
6238ffdff6aSGreg Kroah-Hartman s->n_chan = 2;
6248ffdff6aSGreg Kroah-Hartman s->maxdata = board->maxdata;
6258ffdff6aSGreg Kroah-Hartman s->range_table = &das6402_ao_ranges;
6268ffdff6aSGreg Kroah-Hartman s->insn_write = das6402_ao_insn_write;
6278ffdff6aSGreg Kroah-Hartman s->insn_read = das6402_ao_insn_read;
6288ffdff6aSGreg Kroah-Hartman
6298ffdff6aSGreg Kroah-Hartman ret = comedi_alloc_subdev_readback(s);
6308ffdff6aSGreg Kroah-Hartman if (ret)
6318ffdff6aSGreg Kroah-Hartman return ret;
6328ffdff6aSGreg Kroah-Hartman
6338ffdff6aSGreg Kroah-Hartman /* Digital Input subdevice */
6348ffdff6aSGreg Kroah-Hartman s = &dev->subdevices[2];
6358ffdff6aSGreg Kroah-Hartman s->type = COMEDI_SUBD_DI;
6368ffdff6aSGreg Kroah-Hartman s->subdev_flags = SDF_READABLE;
6378ffdff6aSGreg Kroah-Hartman s->n_chan = 8;
6388ffdff6aSGreg Kroah-Hartman s->maxdata = 1;
6398ffdff6aSGreg Kroah-Hartman s->range_table = &range_digital;
6408ffdff6aSGreg Kroah-Hartman s->insn_bits = das6402_di_insn_bits;
6418ffdff6aSGreg Kroah-Hartman
6428ffdff6aSGreg Kroah-Hartman /* Digital Input subdevice */
6438ffdff6aSGreg Kroah-Hartman s = &dev->subdevices[3];
6448ffdff6aSGreg Kroah-Hartman s->type = COMEDI_SUBD_DO;
6458ffdff6aSGreg Kroah-Hartman s->subdev_flags = SDF_WRITABLE;
6468ffdff6aSGreg Kroah-Hartman s->n_chan = 8;
6478ffdff6aSGreg Kroah-Hartman s->maxdata = 1;
6488ffdff6aSGreg Kroah-Hartman s->range_table = &range_digital;
6498ffdff6aSGreg Kroah-Hartman s->insn_bits = das6402_do_insn_bits;
6508ffdff6aSGreg Kroah-Hartman
6518ffdff6aSGreg Kroah-Hartman return 0;
6528ffdff6aSGreg Kroah-Hartman }
6538ffdff6aSGreg Kroah-Hartman
6548ffdff6aSGreg Kroah-Hartman static struct comedi_driver das6402_driver = {
6558ffdff6aSGreg Kroah-Hartman .driver_name = "das6402",
6568ffdff6aSGreg Kroah-Hartman .module = THIS_MODULE,
6578ffdff6aSGreg Kroah-Hartman .attach = das6402_attach,
6588ffdff6aSGreg Kroah-Hartman .detach = comedi_legacy_detach,
6598ffdff6aSGreg Kroah-Hartman .board_name = &das6402_boards[0].name,
6608ffdff6aSGreg Kroah-Hartman .num_names = ARRAY_SIZE(das6402_boards),
6618ffdff6aSGreg Kroah-Hartman .offset = sizeof(struct das6402_boardinfo),
6628ffdff6aSGreg Kroah-Hartman };
6638ffdff6aSGreg Kroah-Hartman module_comedi_driver(das6402_driver)
6648ffdff6aSGreg Kroah-Hartman
6658ffdff6aSGreg Kroah-Hartman MODULE_AUTHOR("H Hartley Sweeten <hsweeten@visionengravers.com>");
6668ffdff6aSGreg Kroah-Hartman MODULE_DESCRIPTION("Comedi driver for DAS6402 compatible boards");
6678ffdff6aSGreg Kroah-Hartman MODULE_LICENSE("GPL");
668