1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40#include <linux/module.h>
41#include "../comedidev.h"
42
43#define PCMAD_STATUS 0
44#define PCMAD_LSB 1
45#define PCMAD_MSB 2
46#define PCMAD_CONVERT 1
47
48struct pcmad_board_struct {
49 const char *name;
50 unsigned int ai_maxdata;
51};
52
53static const struct pcmad_board_struct pcmad_boards[] = {
54 {
55 .name = "pcmad12",
56 .ai_maxdata = 0x0fff,
57 }, {
58 .name = "pcmad16",
59 .ai_maxdata = 0xffff,
60 },
61};
62
63static int pcmad_ai_eoc(struct comedi_device *dev,
64 struct comedi_subdevice *s,
65 struct comedi_insn *insn,
66 unsigned long context)
67{
68 unsigned int status;
69
70 status = inb(dev->iobase + PCMAD_STATUS);
71 if ((status & 0x3) == 0x3)
72 return 0;
73 return -EBUSY;
74}
75
76static int pcmad_ai_insn_read(struct comedi_device *dev,
77 struct comedi_subdevice *s,
78 struct comedi_insn *insn,
79 unsigned int *data)
80{
81 unsigned int chan = CR_CHAN(insn->chanspec);
82 unsigned int range = CR_RANGE(insn->chanspec);
83 unsigned int val;
84 int ret;
85 int i;
86
87 for (i = 0; i < insn->n; i++) {
88 outb(chan, dev->iobase + PCMAD_CONVERT);
89
90 ret = comedi_timeout(dev, s, insn, pcmad_ai_eoc, 0);
91 if (ret)
92 return ret;
93
94 val = inb(dev->iobase + PCMAD_LSB) |
95 (inb(dev->iobase + PCMAD_MSB) << 8);
96
97
98 if (s->maxdata == 0x0fff)
99 val >>= 4;
100
101 if (comedi_range_is_bipolar(s, range)) {
102
103 val ^= ((s->maxdata + 1) >> 1);
104 }
105
106 data[i] = val;
107 }
108
109 return insn->n;
110}
111
112static int pcmad_attach(struct comedi_device *dev, struct comedi_devconfig *it)
113{
114 const struct pcmad_board_struct *board = dev->board_ptr;
115 struct comedi_subdevice *s;
116 int ret;
117
118 ret = comedi_request_region(dev, it->options[0], 0x04);
119 if (ret)
120 return ret;
121
122 ret = comedi_alloc_subdevices(dev, 1);
123 if (ret)
124 return ret;
125
126 s = &dev->subdevices[0];
127 s->type = COMEDI_SUBD_AI;
128 if (it->options[1]) {
129
130 s->subdev_flags = SDF_READABLE | AREF_DIFF;
131 s->n_chan = 8;
132 } else {
133
134 s->subdev_flags = SDF_READABLE | AREF_GROUND;
135 s->n_chan = 16;
136 }
137 s->len_chanlist = 1;
138 s->maxdata = board->ai_maxdata;
139 s->range_table = it->options[2] ? &range_bipolar10 : &range_unipolar5;
140 s->insn_read = pcmad_ai_insn_read;
141
142 return 0;
143}
144
145static struct comedi_driver pcmad_driver = {
146 .driver_name = "pcmad",
147 .module = THIS_MODULE,
148 .attach = pcmad_attach,
149 .detach = comedi_legacy_detach,
150 .board_name = &pcmad_boards[0].name,
151 .num_names = ARRAY_SIZE(pcmad_boards),
152 .offset = sizeof(pcmad_boards[0]),
153};
154module_comedi_driver(pcmad_driver);
155
156MODULE_AUTHOR("Comedi http://www.comedi.org");
157MODULE_DESCRIPTION("Comedi low-level driver");
158MODULE_LICENSE("GPL");
159