Version:  2.0.40 2.2.26 2.4.37 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10 3.11 3.12 3.13 3.14 3.15 3.16

Linux/drivers/staging/comedi/drivers/ni_670x.c

  1 /*
  2     comedi/drivers/ni_670x.c
  3     Hardware driver for NI 670x devices
  4 
  5     COMEDI - Linux Control and Measurement Device Interface
  6     Copyright (C) 1997-2001 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 /*
 19 Driver: ni_670x
 20 Description: National Instruments 670x
 21 Author: Bart Joris <bjoris@advalvas.be>
 22 Updated: Wed, 11 Dec 2002 18:25:35 -0800
 23 Devices: [National Instruments] PCI-6703 (ni_670x), PCI-6704
 24 Status: unknown
 25 
 26 Commands are not supported.
 27 */
 28 
 29 /*
 30         Bart Joris <bjoris@advalvas.be> Last updated on 20/08/2001
 31 
 32         Manuals:
 33 
 34         322110a.pdf     PCI/PXI-6704 User Manual
 35         322110b.pdf     PCI/PXI-6703/6704 User Manual
 36 
 37 */
 38 
 39 #include <linux/module.h>
 40 #include <linux/pci.h>
 41 #include <linux/interrupt.h>
 42 
 43 #include "../comedidev.h"
 44 
 45 #include "mite.h"
 46 
 47 #define AO_VALUE_OFFSET                 0x00
 48 #define AO_CHAN_OFFSET                  0x0c
 49 #define AO_STATUS_OFFSET                0x10
 50 #define AO_CONTROL_OFFSET               0x10
 51 #define DIO_PORT0_DIR_OFFSET    0x20
 52 #define DIO_PORT0_DATA_OFFSET   0x24
 53 #define DIO_PORT1_DIR_OFFSET    0x28
 54 #define DIO_PORT1_DATA_OFFSET   0x2c
 55 #define MISC_STATUS_OFFSET              0x14
 56 #define MISC_CONTROL_OFFSET             0x14
 57 
 58 enum ni_670x_boardid {
 59         BOARD_PCI6703,
 60         BOARD_PXI6704,
 61         BOARD_PCI6704,
 62 };
 63 
 64 struct ni_670x_board {
 65         const char *name;
 66         unsigned short ao_chans;
 67 };
 68 
 69 static const struct ni_670x_board ni_670x_boards[] = {
 70         [BOARD_PCI6703] = {
 71                 .name           = "PCI-6703",
 72                 .ao_chans       = 16,
 73         },
 74         [BOARD_PXI6704] = {
 75                 .name           = "PXI-6704",
 76                 .ao_chans       = 32,
 77         },
 78         [BOARD_PCI6704] = {
 79                 .name           = "PCI-6704",
 80                 .ao_chans       = 32,
 81         },
 82 };
 83 
 84 struct ni_670x_private {
 85 
 86         struct mite_struct *mite;
 87         int boardtype;
 88         int dio;
 89         unsigned int ao_readback[32];
 90 };
 91 
 92 static int ni_670x_ao_winsn(struct comedi_device *dev,
 93                             struct comedi_subdevice *s,
 94                             struct comedi_insn *insn, unsigned int *data)
 95 {
 96         struct ni_670x_private *devpriv = dev->private;
 97         int i;
 98         int chan = CR_CHAN(insn->chanspec);
 99 
100         /* Channel number mapping :
101 
102            NI 6703/ NI 6704     | NI 6704 Only
103            ----------------------------------------------------
104            vch(0)       :       0       | ich(16)       :       1
105            vch(1)       :       2       | ich(17)       :       3
106            .    :       .       |   .                   .
107            .    :       .       |   .                   .
108            .    :       .       |   .                   .
109            vch(15)      :       30      | ich(31)       :       31      */
110 
111         for (i = 0; i < insn->n; i++) {
112                 /* First write in channel register which channel to use */
113                 writel(((chan & 15) << 1) | ((chan & 16) >> 4),
114                        devpriv->mite->daq_io_addr + AO_CHAN_OFFSET);
115                 /* write channel value */
116                 writel(data[i], devpriv->mite->daq_io_addr + AO_VALUE_OFFSET);
117                 devpriv->ao_readback[chan] = data[i];
118         }
119 
120         return i;
121 }
122 
123 static int ni_670x_ao_rinsn(struct comedi_device *dev,
124                             struct comedi_subdevice *s,
125                             struct comedi_insn *insn, unsigned int *data)
126 {
127         struct ni_670x_private *devpriv = dev->private;
128         int i;
129         int chan = CR_CHAN(insn->chanspec);
130 
131         for (i = 0; i < insn->n; i++)
132                 data[i] = devpriv->ao_readback[chan];
133 
134         return i;
135 }
136 
137 static int ni_670x_dio_insn_bits(struct comedi_device *dev,
138                                  struct comedi_subdevice *s,
139                                  struct comedi_insn *insn,
140                                  unsigned int *data)
141 {
142         struct ni_670x_private *devpriv = dev->private;
143         void __iomem *io_addr = devpriv->mite->daq_io_addr +
144                                         DIO_PORT0_DATA_OFFSET;
145 
146         if (comedi_dio_update_state(s, data))
147                 writel(s->state, io_addr);
148 
149         data[1] = readl(io_addr);
150 
151         return insn->n;
152 }
153 
154 static int ni_670x_dio_insn_config(struct comedi_device *dev,
155                                    struct comedi_subdevice *s,
156                                    struct comedi_insn *insn,
157                                    unsigned int *data)
158 {
159         struct ni_670x_private *devpriv = dev->private;
160         int ret;
161 
162         ret = comedi_dio_insn_config(dev, s, insn, data, 0);
163         if (ret)
164                 return ret;
165 
166         writel(s->io_bits, devpriv->mite->daq_io_addr + DIO_PORT0_DIR_OFFSET);
167 
168         return insn->n;
169 }
170 
171 static int ni_670x_auto_attach(struct comedi_device *dev,
172                                unsigned long context)
173 {
174         struct pci_dev *pcidev = comedi_to_pci_dev(dev);
175         const struct ni_670x_board *thisboard = NULL;
176         struct ni_670x_private *devpriv;
177         struct comedi_subdevice *s;
178         int ret;
179         int i;
180 
181         if (context < ARRAY_SIZE(ni_670x_boards))
182                 thisboard = &ni_670x_boards[context];
183         if (!thisboard)
184                 return -ENODEV;
185         dev->board_ptr = thisboard;
186         dev->board_name = thisboard->name;
187 
188         ret = comedi_pci_enable(dev);
189         if (ret)
190                 return ret;
191 
192         devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
193         if (!devpriv)
194                 return -ENOMEM;
195 
196         devpriv->mite = mite_alloc(pcidev);
197         if (!devpriv->mite)
198                 return -ENOMEM;
199 
200         ret = mite_setup(devpriv->mite);
201         if (ret < 0) {
202                 dev_warn(dev->class_dev, "error setting up mite\n");
203                 return ret;
204         }
205 
206         ret = comedi_alloc_subdevices(dev, 2);
207         if (ret)
208                 return ret;
209 
210         s = &dev->subdevices[0];
211         /* analog output subdevice */
212         s->type = COMEDI_SUBD_AO;
213         s->subdev_flags = SDF_WRITABLE;
214         s->n_chan = thisboard->ao_chans;
215         s->maxdata = 0xffff;
216         if (s->n_chan == 32) {
217                 const struct comedi_lrange **range_table_list;
218 
219                 range_table_list = kmalloc(sizeof(struct comedi_lrange *) * 32,
220                                            GFP_KERNEL);
221                 if (!range_table_list)
222                         return -ENOMEM;
223                 s->range_table_list = range_table_list;
224                 for (i = 0; i < 16; i++) {
225                         range_table_list[i] = &range_bipolar10;
226                         range_table_list[16 + i] = &range_0_20mA;
227                 }
228         } else {
229                 s->range_table = &range_bipolar10;
230         }
231         s->insn_write = &ni_670x_ao_winsn;
232         s->insn_read = &ni_670x_ao_rinsn;
233 
234         s = &dev->subdevices[1];
235         /* digital i/o subdevice */
236         s->type = COMEDI_SUBD_DIO;
237         s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
238         s->n_chan = 8;
239         s->maxdata = 1;
240         s->range_table = &range_digital;
241         s->insn_bits = ni_670x_dio_insn_bits;
242         s->insn_config = ni_670x_dio_insn_config;
243 
244         /* Config of misc registers */
245         writel(0x10, devpriv->mite->daq_io_addr + MISC_CONTROL_OFFSET);
246         /* Config of ao registers */
247         writel(0x00, devpriv->mite->daq_io_addr + AO_CONTROL_OFFSET);
248 
249         return 0;
250 }
251 
252 static void ni_670x_detach(struct comedi_device *dev)
253 {
254         struct ni_670x_private *devpriv = dev->private;
255         struct comedi_subdevice *s;
256 
257         if (dev->n_subdevices) {
258                 s = &dev->subdevices[0];
259                 if (s)
260                         kfree(s->range_table_list);
261         }
262         if (devpriv && devpriv->mite) {
263                 mite_unsetup(devpriv->mite);
264                 mite_free(devpriv->mite);
265         }
266         comedi_pci_disable(dev);
267 }
268 
269 static struct comedi_driver ni_670x_driver = {
270         .driver_name    = "ni_670x",
271         .module         = THIS_MODULE,
272         .auto_attach    = ni_670x_auto_attach,
273         .detach         = ni_670x_detach,
274 };
275 
276 static int ni_670x_pci_probe(struct pci_dev *dev,
277                              const struct pci_device_id *id)
278 {
279         return comedi_pci_auto_config(dev, &ni_670x_driver, id->driver_data);
280 }
281 
282 static const struct pci_device_id ni_670x_pci_table[] = {
283         { PCI_VDEVICE(NI, 0x1290), BOARD_PCI6704 },
284         { PCI_VDEVICE(NI, 0x1920), BOARD_PXI6704 },
285         { PCI_VDEVICE(NI, 0x2c90), BOARD_PCI6703 },
286         { 0 }
287 };
288 MODULE_DEVICE_TABLE(pci, ni_670x_pci_table);
289 
290 static struct pci_driver ni_670x_pci_driver = {
291         .name           = "ni_670x",
292         .id_table       = ni_670x_pci_table,
293         .probe          = ni_670x_pci_probe,
294         .remove         = comedi_pci_auto_unconfig,
295 };
296 module_comedi_pci_driver(ni_670x_driver, ni_670x_pci_driver);
297 
298 MODULE_AUTHOR("Comedi http://www.comedi.org");
299 MODULE_DESCRIPTION("Comedi low-level driver");
300 MODULE_LICENSE("GPL");
301 

This page was automatically generated by LXR 0.3.1 (source).  •  Linux is a registered trademark of Linus Torvalds  •  Contact us