3 comedi routines for voltage ranges
5 COMEDI - Linux Control and Measurement Device Interface
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <linux/uaccess.h>
25 #include "comedidev.h"
28 const struct comedi_lrange range_bipolar10 = { 1, {BIP_RANGE(10)} };
29 EXPORT_SYMBOL(range_bipolar10);
30 const struct comedi_lrange range_bipolar5 = { 1, {BIP_RANGE(5)} };
31 EXPORT_SYMBOL(range_bipolar5);
32 const struct comedi_lrange range_bipolar2_5 = { 1, {BIP_RANGE(2.5)} };
33 EXPORT_SYMBOL(range_bipolar2_5);
34 const struct comedi_lrange range_unipolar10 = { 1, {UNI_RANGE(10)} };
35 EXPORT_SYMBOL(range_unipolar10);
36 const struct comedi_lrange range_unipolar5 = { 1, {UNI_RANGE(5)} };
37 EXPORT_SYMBOL(range_unipolar5);
38 const struct comedi_lrange range_unknown = { 1, {{0, 1000000, UNIT_none} } };
39 EXPORT_SYMBOL(range_unknown);
43 range information ioctl
46 pointer to rangeinfo structure
52 n struct comedi_krange structures to rangeinfo->range_ptr
54 int do_rangeinfo_ioctl(struct comedi_device *dev,
55 struct comedi_rangeinfo __user *arg)
57 struct comedi_rangeinfo it;
59 const struct comedi_lrange *lr;
60 struct comedi_subdevice *s;
62 if (copy_from_user(&it, arg, sizeof(struct comedi_rangeinfo)))
64 subd = (it.range_type >> 24) & 0xf;
65 chan = (it.range_type >> 16) & 0xff;
69 if (subd >= dev->n_subdevices)
71 s = dev->subdevices + subd;
74 } else if (s->range_table_list) {
75 if (chan >= s->n_chan)
77 lr = s->range_table_list[chan];
82 if (RANGE_LENGTH(it.range_type) != lr->length) {
83 DPRINTK("wrong length %d should be %d (0x%08x)\n",
84 RANGE_LENGTH(it.range_type), lr->length, it.range_type);
88 if (copy_to_user(it.range_ptr, lr->range,
89 sizeof(struct comedi_krange) * lr->length))
95 static int aref_invalid(struct comedi_subdevice *s, unsigned int chanspec)
99 /* disable reporting invalid arefs... maybe someday */
102 aref = CR_AREF(chanspec);
105 if (s->subdev_flags & SDF_DIFF)
109 if (s->subdev_flags & SDF_COMMON)
113 if (s->subdev_flags & SDF_GROUND)
117 if (s->subdev_flags & SDF_OTHER)
123 DPRINTK("subdevice does not support aref %i", aref);
128 This function checks each element in a channel/gain list to make
129 make sure it is valid.
131 int comedi_check_chanlist(struct comedi_subdevice *s, int n,
132 unsigned int *chanlist)
137 if (s->range_table) {
138 for (i = 0; i < n; i++)
139 if (CR_CHAN(chanlist[i]) >= s->n_chan ||
140 CR_RANGE(chanlist[i]) >= s->range_table->length
141 || aref_invalid(s, chanlist[i])) {
142 printk(KERN_ERR "bad chanlist[%d]=0x%08x "
143 "in_chan=%d range length=%d\n", i,
144 chanlist[i], s->n_chan,
145 s->range_table->length);
148 } else if (s->range_table_list) {
149 for (i = 0; i < n; i++) {
150 chan = CR_CHAN(chanlist[i]);
151 if (chan >= s->n_chan ||
152 CR_RANGE(chanlist[i]) >=
153 s->range_table_list[chan]->length
154 || aref_invalid(s, chanlist[i])) {
155 printk(KERN_ERR "bad chanlist[%d]=0x%08x\n",
161 printk(KERN_ERR "comedi: (bug) no range type list!\n");
166 EXPORT_SYMBOL(comedi_check_chanlist);