Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
fl512.c
Go to the documentation of this file.
1 /*
2  comedi/drivers/fl512.c
3  Anders Gnistrup <[email protected]>
4 */
5 
6 /*
7 Driver: fl512
8 Description: unknown
9 Author: Anders Gnistrup <[email protected]>
10 Devices: [unknown] FL512 (fl512)
11 Status: unknown
12 
13 Digital I/O is not supported.
14 
15 Configuration options:
16  [0] - I/O port base address
17 */
18 
19 #define DEBUG 0
20 
21 #include "../comedidev.h"
22 
23 #include <linux/delay.h>
24 #include <linux/ioport.h>
25 
26 #define FL512_SIZE 16 /* the size of the used memory */
27 struct fl512_private {
28 
29  short ao_readback[2];
30 };
31 
32 #define devpriv ((struct fl512_private *) dev->private)
33 
34 static const struct comedi_lrange range_fl512 = { 4, {
35  BIP_RANGE(0.5),
36  BIP_RANGE(1),
37  BIP_RANGE(5),
38  BIP_RANGE(10),
39  UNI_RANGE(1),
40  UNI_RANGE(5),
41  UNI_RANGE(10),
42  }
43 };
44 
45 /*
46  * fl512_ai_insn : this is the analog input function
47  */
48 static int fl512_ai_insn(struct comedi_device *dev,
49  struct comedi_subdevice *s, struct comedi_insn *insn,
50  unsigned int *data)
51 {
52  int n;
53  unsigned int lo_byte, hi_byte;
54  char chan = CR_CHAN(insn->chanspec);
55  unsigned long iobase = dev->iobase;
56 
57  for (n = 0; n < insn->n; n++) { /* sample n times on selected channel */
58  /* XXX probably can move next step out of for() loop -- will
59  * make AI a little bit faster. */
60  outb(chan, iobase + 2); /* select chan */
61  outb(0, iobase + 3); /* start conversion */
62  /* XXX should test "done" flag instead of delay */
63  udelay(30); /* sleep 30 usec */
64  lo_byte = inb(iobase + 2); /* low 8 byte */
65  hi_byte = inb(iobase + 3) & 0xf; /* high 4 bit and mask */
66  data[n] = lo_byte + (hi_byte << 8);
67  }
68  return n;
69 }
70 
71 /*
72  * fl512_ao_insn : used to write to a DA port n times
73  */
74 static int fl512_ao_insn(struct comedi_device *dev,
75  struct comedi_subdevice *s, struct comedi_insn *insn,
76  unsigned int *data)
77 {
78  int n;
79  int chan = CR_CHAN(insn->chanspec); /* get chan to write */
80  unsigned long iobase = dev->iobase; /* get base address */
81 
82  for (n = 0; n < insn->n; n++) { /* write n data set */
83  /* write low byte */
84  outb(data[n] & 0x0ff, iobase + 4 + 2 * chan);
85  /* write high byte */
86  outb((data[n] & 0xf00) >> 8, iobase + 4 + 2 * chan);
87  inb(iobase + 4 + 2 * chan); /* trig */
88 
89  devpriv->ao_readback[chan] = data[n];
90  }
91  return n;
92 }
93 
94 /*
95  * fl512_ao_insn_readback : used to read previous values written to
96  * DA port
97  */
98 static int fl512_ao_insn_readback(struct comedi_device *dev,
99  struct comedi_subdevice *s,
100  struct comedi_insn *insn, unsigned int *data)
101 {
102  int n;
103  int chan = CR_CHAN(insn->chanspec);
104 
105  for (n = 0; n < insn->n; n++)
106  data[n] = devpriv->ao_readback[chan];
107 
108  return n;
109 }
110 
111 static int fl512_attach(struct comedi_device *dev, struct comedi_devconfig *it)
112 {
113  unsigned long iobase;
114  int ret;
115 
116  /* pointer to the subdevice: Analog in, Analog out,
117  (not made ->and Digital IO) */
118  struct comedi_subdevice *s;
119 
120  iobase = it->options[0];
121  printk(KERN_INFO "comedi:%d fl512: 0x%04lx", dev->minor, iobase);
122  if (!request_region(iobase, FL512_SIZE, "fl512")) {
123  printk(KERN_WARNING " I/O port conflict\n");
124  return -EIO;
125  }
126  dev->iobase = iobase;
127  dev->board_name = "fl512";
128  if (alloc_private(dev, sizeof(struct fl512_private)) < 0)
129  return -ENOMEM;
130 
131 #if DEBUG
132  printk(KERN_DEBUG "malloc ok\n");
133 #endif
134 
135  ret = comedi_alloc_subdevices(dev, 2);
136  if (ret)
137  return ret;
138 
139  /*
140  * this if the definitions of the supdevices, 2 have been defined
141  */
142  /* Analog indput */
143  s = &dev->subdevices[0];
144  /* define subdevice as Analog In */
145  s->type = COMEDI_SUBD_AI;
146  /* you can read it from userspace */
148  /* Number of Analog input channels */
149  s->n_chan = 16;
150  /* accept only 12 bits of data */
151  s->maxdata = 0x0fff;
152  /* device use one of the ranges */
153  s->range_table = &range_fl512;
154  /* function to call when read AD */
155  s->insn_read = fl512_ai_insn;
156  printk(KERN_INFO "comedi: fl512: subdevice 0 initialized\n");
157 
158  /* Analog output */
159  s = &dev->subdevices[1];
160  /* define subdevice as Analog OUT */
161  s->type = COMEDI_SUBD_AO;
162  /* you can write it from userspace */
164  /* Number of Analog output channels */
165  s->n_chan = 2;
166  /* accept only 12 bits of data */
167  s->maxdata = 0x0fff;
168  /* device use one of the ranges */
169  s->range_table = &range_fl512;
170  /* function to call when write DA */
171  s->insn_write = fl512_ao_insn;
172  /* function to call when reading DA */
173  s->insn_read = fl512_ao_insn_readback;
174  printk(KERN_INFO "comedi: fl512: subdevice 1 initialized\n");
175 
176  return 1;
177 }
178 
179 static void fl512_detach(struct comedi_device *dev)
180 {
181  if (dev->iobase)
183 }
184 
185 static struct comedi_driver fl512_driver = {
186  .driver_name = "fl512",
187  .module = THIS_MODULE,
188  .attach = fl512_attach,
189  .detach = fl512_detach,
190 };
191 module_comedi_driver(fl512_driver);
192 
193 MODULE_AUTHOR("Comedi http://www.comedi.org");
194 MODULE_DESCRIPTION("Comedi low-level driver");
195 MODULE_LICENSE("GPL");