Version:  2.0.40 2.2.26 2.4.37 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 3.17

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 #include <linux/slab.h>
 43 
 44 #include "../comedidev.h"
 45 
 46 #define AO_VALUE_OFFSET                 0x00
 47 #define AO_CHAN_OFFSET                  0x0c
 48 #define AO_STATUS_OFFSET                0x10
 49 #define AO_CONTROL_OFFSET               0x10
 50 #define DIO_PORT0_DIR_OFFSET    0x20
 51 #define DIO_PORT0_DATA_OFFSET   0x24
 52 #define DIO_PORT1_DIR_OFFSET    0x28
 53 #define DIO_PORT1_DATA_OFFSET   0x2c
 54 #define MISC_STATUS_OFFSET              0x14
 55 #define MISC_CONTROL_OFFSET             0x14
 56 
 57 enum ni_670x_boardid {
 58         BOARD_PCI6703,
 59         BOARD_PXI6704,
 60         BOARD_PCI6704,
 61 };
 62 
 63 struct ni_670x_board {
 64         const char *name;
 65         unsigned short ao_chans;
 66 };
 67 
 68 static const struct ni_670x_board ni_670x_boards[] = {
 69         [BOARD_PCI6703] = {
 70                 .name           = "PCI-6703",
 71                 .ao_chans       = 16,
 72         },
 73         [BOARD_PXI6704] = {
 74                 .name           = "PXI-6704",
 75                 .ao_chans       = 32,
 76         },
 77         [BOARD_PCI6704] = {
 78                 .name           = "PCI-6704",
 79                 .ao_chans       = 32,
 80         },
 81 };
 82 
 83 struct ni_670x_private {
 84         int boardtype;
 85         int dio;
 86         unsigned int ao_readback[32];
 87 };
 88 
 89 static int ni_670x_ao_winsn(struct comedi_device *dev,
 90                             struct comedi_subdevice *s,
 91                             struct comedi_insn *insn, unsigned int *data)
 92 {
 93         struct ni_670x_private *devpriv = dev->private;
 94         int i;
 95         int chan = CR_CHAN(insn->chanspec);
 96 
 97         /* Channel number mapping :
 98 
 99            NI 6703/ NI 6704     | NI 6704 Only
100            ----------------------------------------------------
101            vch(0)       :       0       | ich(16)       :       1
102            vch(1)       :       2       | ich(17)       :       3
103            .    :       .       |   .                   .
104            .    :       .       |   .                   .
105            .    :       .       |   .                   .
106            vch(15)      :       30      | ich(31)       :       31      */
107 
108         for (i = 0; i < insn->n; i++) {
109                 /* First write in channel register which channel to use */
110                 writel(((chan & 15) << 1) | ((chan & 16) >> 4),
111                        dev->mmio + AO_CHAN_OFFSET);
112                 /* write channel value */
113                 writel(data[i], dev->mmio + AO_VALUE_OFFSET);
114                 devpriv->ao_readback[chan] = data[i];
115         }
116 
117         return i;
118 }
119 
120 static int ni_670x_ao_rinsn(struct comedi_device *dev,
121                             struct comedi_subdevice *s,
122                             struct comedi_insn *insn, unsigned int *data)
123 {
124         struct ni_670x_private *devpriv = dev->private;
125         int i;
126         int chan = CR_CHAN(insn->chanspec);
127 
128         for (i = 0; i < insn->n; i++)
129                 data[i] = devpriv->ao_readback[chan];
130 
131         return i;
132 }
133 
134 static int ni_670x_dio_insn_bits(struct comedi_device *dev,
135                                  struct comedi_subdevice *s,
136                                  struct comedi_insn *insn,
137                                  unsigned int *data)
138 {
139         if (comedi_dio_update_state(s, data))
140                 writel(s->state, dev->mmio + DIO_PORT0_DATA_OFFSET);
141 
142         data[1] = readl(dev->mmio + DIO_PORT0_DATA_OFFSET);
143 
144         return insn->n;
145 }
146 
147 static int ni_670x_dio_insn_config(struct comedi_device *dev,
148                                    struct comedi_subdevice *s,
149                                    struct comedi_insn *insn,
150                                    unsigned int *data)
151 {
152         int ret;
153 
154         ret = comedi_dio_insn_config(dev, s, insn, data, 0);
155         if (ret)
156                 return ret;
157 
158         writel(s->io_bits, dev->mmio + DIO_PORT0_DIR_OFFSET);
159 
160         return insn->n;
161 }
162 
163 /* ripped from mite.h and mite_setup2() to avoid mite dependancy */
164 #define MITE_IODWBSR    0xc0     /* IO Device Window Base Size Register */
165 #define WENAB           (1 << 7) /* window enable */
166 
167 static int ni_670x_mite_init(struct pci_dev *pcidev)
168 {
169         void __iomem *mite_base;
170         u32 main_phys_addr;
171 
172         /* ioremap the MITE registers (BAR 0) temporarily */
173         mite_base = pci_ioremap_bar(pcidev, 0);
174         if (!mite_base)
175                 return -ENOMEM;
176 
177         /* set data window to main registers (BAR 1) */
178         main_phys_addr = pci_resource_start(pcidev, 1);
179         writel(main_phys_addr | WENAB, mite_base + MITE_IODWBSR);
180 
181         /* finished with MITE registers */
182         iounmap(mite_base);
183         return 0;
184 }
185 
186 static int ni_670x_auto_attach(struct comedi_device *dev,
187                                unsigned long context)
188 {
189         struct pci_dev *pcidev = comedi_to_pci_dev(dev);
190         const struct ni_670x_board *thisboard = NULL;
191         struct ni_670x_private *devpriv;
192         struct comedi_subdevice *s;
193         int ret;
194         int i;
195 
196         if (context < ARRAY_SIZE(ni_670x_boards))
197                 thisboard = &ni_670x_boards[context];
198         if (!thisboard)
199                 return -ENODEV;
200         dev->board_ptr = thisboard;
201         dev->board_name = thisboard->name;
202 
203         ret = comedi_pci_enable(dev);
204         if (ret)
205                 return ret;
206 
207         devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
208         if (!devpriv)
209                 return -ENOMEM;
210 
211         ret = ni_670x_mite_init(pcidev);
212         if (ret)
213                 return ret;
214 
215         dev->mmio = pci_ioremap_bar(pcidev, 1);
216         if (!dev->mmio)
217                 return -ENOMEM;
218 
219         ret = comedi_alloc_subdevices(dev, 2);
220         if (ret)
221                 return ret;
222 
223         s = &dev->subdevices[0];
224         /* analog output subdevice */
225         s->type = COMEDI_SUBD_AO;
226         s->subdev_flags = SDF_WRITABLE;
227         s->n_chan = thisboard->ao_chans;
228         s->maxdata = 0xffff;
229         if (s->n_chan == 32) {
230                 const struct comedi_lrange **range_table_list;
231 
232                 range_table_list = kmalloc(sizeof(struct comedi_lrange *) * 32,
233                                            GFP_KERNEL);
234                 if (!range_table_list)
235                         return -ENOMEM;
236                 s->range_table_list = range_table_list;
237                 for (i = 0; i < 16; i++) {
238                         range_table_list[i] = &range_bipolar10;
239                         range_table_list[16 + i] = &range_0_20mA;
240                 }
241         } else {
242                 s->range_table = &range_bipolar10;
243         }
244         s->insn_write = &ni_670x_ao_winsn;
245         s->insn_read = &ni_670x_ao_rinsn;
246 
247         s = &dev->subdevices[1];
248         /* digital i/o subdevice */
249         s->type = COMEDI_SUBD_DIO;
250         s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
251         s->n_chan = 8;
252         s->maxdata = 1;
253         s->range_table = &range_digital;
254         s->insn_bits = ni_670x_dio_insn_bits;
255         s->insn_config = ni_670x_dio_insn_config;
256 
257         /* Config of misc registers */
258         writel(0x10, dev->mmio + MISC_CONTROL_OFFSET);
259         /* Config of ao registers */
260         writel(0x00, dev->mmio + AO_CONTROL_OFFSET);
261 
262         return 0;
263 }
264 
265 static void ni_670x_detach(struct comedi_device *dev)
266 {
267         struct comedi_subdevice *s;
268 
269         if (dev->n_subdevices) {
270                 s = &dev->subdevices[0];
271                 if (s)
272                         kfree(s->range_table_list);
273         }
274         if (dev->mmio)
275                 iounmap(dev->mmio);
276         comedi_pci_disable(dev);
277 }
278 
279 static struct comedi_driver ni_670x_driver = {
280         .driver_name    = "ni_670x",
281         .module         = THIS_MODULE,
282         .auto_attach    = ni_670x_auto_attach,
283         .detach         = ni_670x_detach,
284 };
285 
286 static int ni_670x_pci_probe(struct pci_dev *dev,
287                              const struct pci_device_id *id)
288 {
289         return comedi_pci_auto_config(dev, &ni_670x_driver, id->driver_data);
290 }
291 
292 static const struct pci_device_id ni_670x_pci_table[] = {
293         { PCI_VDEVICE(NI, 0x1290), BOARD_PCI6704 },
294         { PCI_VDEVICE(NI, 0x1920), BOARD_PXI6704 },
295         { PCI_VDEVICE(NI, 0x2c90), BOARD_PCI6703 },
296         { 0 }
297 };
298 MODULE_DEVICE_TABLE(pci, ni_670x_pci_table);
299 
300 static struct pci_driver ni_670x_pci_driver = {
301         .name           = "ni_670x",
302         .id_table       = ni_670x_pci_table,
303         .probe          = ni_670x_pci_probe,
304         .remove         = comedi_pci_auto_unconfig,
305 };
306 module_comedi_pci_driver(ni_670x_driver, ni_670x_pci_driver);
307 
308 MODULE_AUTHOR("Comedi http://www.comedi.org");
309 MODULE_DESCRIPTION("Comedi low-level driver");
310 MODULE_LICENSE("GPL");
311 

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