root/drivers/staging/comedi/drivers/fl512.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. fl512_ai_insn_read
  2. fl512_ao_insn_write
  3. fl512_attach

   1 // SPDX-License-Identifier: GPL-2.0+
   2 /*
   3  * fl512.c
   4  * Anders Gnistrup <ex18@kalman.iau.dtu.dk>
   5  *
   6  * COMEDI - Linux Control and Measurement Device Interface
   7  * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
   8  */
   9 
  10 /*
  11  * Driver: fl512
  12  * Description: unknown
  13  * Author: Anders Gnistrup <ex18@kalman.iau.dtu.dk>
  14  * Devices: [unknown] FL512 (fl512)
  15  * Status: unknown
  16  *
  17  * Digital I/O is not supported.
  18  *
  19  * Configuration options:
  20  *   [0] - I/O port base address
  21  */
  22 
  23 #include <linux/module.h>
  24 #include "../comedidev.h"
  25 
  26 #include <linux/delay.h>
  27 
  28 /*
  29  * Register I/O map
  30  */
  31 #define FL512_AI_LSB_REG                0x02
  32 #define FL512_AI_MSB_REG                0x03
  33 #define FL512_AI_MUX_REG                0x02
  34 #define FL512_AI_START_CONV_REG         0x03
  35 #define FL512_AO_DATA_REG(x)            (0x04 + ((x) * 2))
  36 #define FL512_AO_TRIG_REG(x)            (0x04 + ((x) * 2))
  37 
  38 static const struct comedi_lrange range_fl512 = {
  39         4, {
  40                 BIP_RANGE(0.5),
  41                 BIP_RANGE(1),
  42                 BIP_RANGE(5),
  43                 BIP_RANGE(10),
  44                 UNI_RANGE(1),
  45                 UNI_RANGE(5),
  46                 UNI_RANGE(10)
  47         }
  48 };
  49 
  50 static int fl512_ai_insn_read(struct comedi_device *dev,
  51                               struct comedi_subdevice *s,
  52                               struct comedi_insn *insn,
  53                               unsigned int *data)
  54 {
  55         unsigned int chan = CR_CHAN(insn->chanspec);
  56         unsigned int val;
  57         int i;
  58 
  59         outb(chan, dev->iobase + FL512_AI_MUX_REG);
  60 
  61         for (i = 0; i < insn->n; i++) {
  62                 outb(0, dev->iobase + FL512_AI_START_CONV_REG);
  63 
  64                 /* XXX should test "done" flag instead of delay */
  65                 usleep_range(30, 100);
  66 
  67                 val = inb(dev->iobase + FL512_AI_LSB_REG);
  68                 val |= (inb(dev->iobase + FL512_AI_MSB_REG) << 8);
  69                 val &= s->maxdata;
  70 
  71                 data[i] = val;
  72         }
  73 
  74         return insn->n;
  75 }
  76 
  77 static int fl512_ao_insn_write(struct comedi_device *dev,
  78                                struct comedi_subdevice *s,
  79                                struct comedi_insn *insn,
  80                                unsigned int *data)
  81 {
  82         unsigned int chan = CR_CHAN(insn->chanspec);
  83         unsigned int val = s->readback[chan];
  84         int i;
  85 
  86         for (i = 0; i < insn->n; i++) {
  87                 val = data[i];
  88 
  89                 /* write LSB, MSB then trigger conversion */
  90                 outb(val & 0x0ff, dev->iobase + FL512_AO_DATA_REG(chan));
  91                 outb((val >> 8) & 0xf, dev->iobase + FL512_AO_DATA_REG(chan));
  92                 inb(dev->iobase + FL512_AO_TRIG_REG(chan));
  93         }
  94         s->readback[chan] = val;
  95 
  96         return insn->n;
  97 }
  98 
  99 static int fl512_attach(struct comedi_device *dev, struct comedi_devconfig *it)
 100 {
 101         struct comedi_subdevice *s;
 102         int ret;
 103 
 104         ret = comedi_request_region(dev, it->options[0], 0x10);
 105         if (ret)
 106                 return ret;
 107 
 108         ret = comedi_alloc_subdevices(dev, 2);
 109         if (ret)
 110                 return ret;
 111 
 112         /* Analog Input subdevice */
 113         s = &dev->subdevices[0];
 114         s->type         = COMEDI_SUBD_AI;
 115         s->subdev_flags = SDF_READABLE | SDF_GROUND;
 116         s->n_chan       = 16;
 117         s->maxdata      = 0x0fff;
 118         s->range_table  = &range_fl512;
 119         s->insn_read    = fl512_ai_insn_read;
 120 
 121         /* Analog Output subdevice */
 122         s = &dev->subdevices[1];
 123         s->type         = COMEDI_SUBD_AO;
 124         s->subdev_flags = SDF_WRITABLE;
 125         s->n_chan       = 2;
 126         s->maxdata      = 0x0fff;
 127         s->range_table  = &range_fl512;
 128         s->insn_write   = fl512_ao_insn_write;
 129 
 130         return comedi_alloc_subdev_readback(s);
 131 }
 132 
 133 static struct comedi_driver fl512_driver = {
 134         .driver_name    = "fl512",
 135         .module         = THIS_MODULE,
 136         .attach         = fl512_attach,
 137         .detach         = comedi_legacy_detach,
 138 };
 139 module_comedi_driver(fl512_driver);
 140 
 141 MODULE_AUTHOR("Comedi http://www.comedi.org");
 142 MODULE_DESCRIPTION("Comedi low-level driver");
 143 MODULE_LICENSE("GPL");

/* [<][>][^][v][top][bottom][index][help] */