Merge branch 'for-2.6.31' of git://git.linux-nfs.org/projects/trondmy/nfs-2.6
[pandora-kernel.git] / drivers / staging / comedi / kcomedilib / data.c
1 /*
2     kcomedilib/data.c
3     implements comedi_data_*() functions
4
5     COMEDI - Linux Control and Measurement Device Interface
6     Copyright (C) 2000 David A. Schleef <ds@schleef.org>
7
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.
12
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.
17
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.
21
22 */
23
24 #include "../comedi.h"
25 #include "../comedilib.h"
26 #include "../comedidev.h"
27
28 #include <linux/string.h>
29 #include <linux/delay.h>
30
31 int comedi_data_write(void *dev, unsigned int subdev, unsigned int chan,
32         unsigned int range, unsigned int aref, unsigned int data)
33 {
34         struct comedi_insn insn;
35
36         memset(&insn, 0, sizeof(insn));
37         insn.insn = INSN_WRITE;
38         insn.n = 1;
39         insn.data = &data;
40         insn.subdev = subdev;
41         insn.chanspec = CR_PACK(chan, range, aref);
42
43         return comedi_do_insn(dev, &insn);
44 }
45
46 int comedi_data_read(void *dev, unsigned int subdev, unsigned int chan,
47         unsigned int range, unsigned int aref, unsigned int *data)
48 {
49         struct comedi_insn insn;
50
51         memset(&insn, 0, sizeof(insn));
52         insn.insn = INSN_READ;
53         insn.n = 1;
54         insn.data = data;
55         insn.subdev = subdev;
56         insn.chanspec = CR_PACK(chan, range, aref);
57
58         return comedi_do_insn(dev, &insn);
59 }
60
61 int comedi_data_read_hint(void *dev, unsigned int subdev,
62         unsigned int chan, unsigned int range, unsigned int aref)
63 {
64         struct comedi_insn insn;
65         unsigned int dummy_data;
66
67         memset(&insn, 0, sizeof(insn));
68         insn.insn = INSN_READ;
69         insn.n = 0;
70         insn.data = &dummy_data;
71         insn.subdev = subdev;
72         insn.chanspec = CR_PACK(chan, range, aref);
73
74         return comedi_do_insn(dev, &insn);
75 }
76
77 int comedi_data_read_delayed(void *dev, unsigned int subdev,
78         unsigned int chan, unsigned int range, unsigned int aref,
79         unsigned int *data, unsigned int nano_sec)
80 {
81         int retval;
82
83         retval = comedi_data_read_hint(dev, subdev, chan, range, aref);
84         if (retval < 0)
85                 return retval;
86
87         udelay((nano_sec + 999) / 1000);
88
89         return comedi_data_read(dev, subdev, chan, range, aref, data);
90 }