]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - drivers/staging/comedi/drivers/ni_labpc.c
Merge 3.10-rc3 into staging-next
[karo-tx-linux.git] / drivers / staging / comedi / drivers / ni_labpc.c
index 77a7bb63258034ae0dd2b88bd692a0b6da9fe317..a918b7ffbe22d28d58ecd00d9c8a339398c80eca 100644 (file)
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 /*
@@ -88,7 +84,7 @@
 #define CMD1_REG               0x00    /* W: Command 1 reg */
 #define CMD1_MA(x)             (((x) & 0x7) << 0)
 #define CMD1_TWOSCMP           (1 << 3)
-#define CMD1_GAIN_MASK         (7 << 4)
+#define CMD1_GAIN(x)           (((x) & 0x7) << 4)
 #define CMD1_SCANEN            (1 << 7)
 #define CMD2_REG               0x01    /* W: Command 2 reg */
 #define CMD2_PRETRIG           (1 << 0)
@@ -153,11 +149,6 @@ enum scan_mode {
        MODE_MULT_CHAN_DOWN,
 };
 
-static const int labpc_plus_ai_gain_bits[] = {
-       0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
-       0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
-};
-
 static const struct comedi_lrange range_labpc_plus_ai = {
        16, {
                BIP_RANGE(5),
@@ -179,13 +170,7 @@ static const struct comedi_lrange range_labpc_plus_ai = {
        }
 };
 
-const int labpc_1200_ai_gain_bits[] = {
-       0x00, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
-       0x00, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
-};
-EXPORT_SYMBOL_GPL(labpc_1200_ai_gain_bits);
-
-const struct comedi_lrange range_labpc_1200_ai = {
+static const struct comedi_lrange range_labpc_1200_ai = {
        14, {
                BIP_RANGE(5),
                BIP_RANGE(2.5),
@@ -203,7 +188,6 @@ const struct comedi_lrange range_labpc_1200_ai = {
                UNI_RANGE(0.1)
        }
 };
-EXPORT_SYMBOL_GPL(range_labpc_1200_ai);
 
 static const struct comedi_lrange range_labpc_ao = {
        2, {
@@ -239,25 +223,18 @@ static const struct labpc_boardinfo labpc_boards[] = {
        {
                .name                   = "lab-pc-1200",
                .ai_speed               = 10000,
-               .register_layout        = labpc_1200_layout,
-               .has_ao                 = 1,
-               .ai_range_table         = &range_labpc_1200_ai,
-               .ai_range_code          = labpc_1200_ai_gain_bits,
                .ai_scan_up             = 1,
+               .has_ao                 = 1,
+               .is_labpc1200           = 1,
        }, {
                .name                   = "lab-pc-1200ai",
                .ai_speed               = 10000,
-               .register_layout        = labpc_1200_layout,
-               .ai_range_table         = &range_labpc_1200_ai,
-               .ai_range_code          = labpc_1200_ai_gain_bits,
                .ai_scan_up             = 1,
+               .is_labpc1200           = 1,
        }, {
                .name                   = "lab-pc+",
                .ai_speed               = 12000,
-               .register_layout        = labpc_plus_layout,
                .has_ao                 = 1,
-               .ai_range_table         = &range_labpc_plus_ai,
-               .ai_range_code          = labpc_plus_ai_gain_bits,
        },
 };
 #endif
@@ -326,12 +303,21 @@ static void labpc_ai_set_chan_and_gain(struct comedi_device *dev,
        const struct labpc_boardinfo *board = comedi_board(dev);
        struct labpc_private *devpriv = dev->private;
 
+       if (board->is_labpc1200) {
+               /*
+                * The LabPC-1200 boards do not have a gain
+                * of '0x10'. Skip the range values that would
+                * result in this gain.
+                */
+               range += (range > 0) + (range > 7);
+       }
+
        /* munge channel bits for differential/scan disabled mode */
        if ((mode == MODE_SINGLE_CHAN || mode == MODE_SINGLE_CHAN_INTERVAL) &&
            aref == AREF_DIFF)
                chan *= 2;
        devpriv->cmd1 = CMD1_MA(chan);
-       devpriv->cmd1 |= board->ai_range_code[range];
+       devpriv->cmd1 |= CMD1_GAIN(range);
 
        devpriv->write_byte(devpriv->cmd1, dev->iobase + CMD1_REG);
 }
@@ -347,7 +333,7 @@ static void labpc_setup_cmd6_reg(struct comedi_device *dev,
        const struct labpc_boardinfo *board = comedi_board(dev);
        struct labpc_private *devpriv = dev->private;
 
-       if (board->register_layout != labpc_1200_layout)
+       if (!board->is_labpc1200)
                return;
 
        /* reference inputs to ground or common? */
@@ -759,7 +745,7 @@ static int labpc_ai_cmdtest(struct comedi_device *dev,
        err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
 
        stop_mask = TRIG_COUNT | TRIG_NONE;
-       if (board->register_layout == labpc_1200_layout)
+       if (board->is_labpc1200)
                stop_mask |= TRIG_EXT;
        err |= cfc_check_trigger_src(&cmd->stop_src, stop_mask);
 
@@ -895,7 +881,7 @@ static int labpc_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
                /* pc-plus has no fifo-half full interrupt */
        } else
 #endif
-       if (board->register_layout == labpc_1200_layout &&
+       if (board->is_labpc1200 &&
                   /*  wake-end-of-scan should interrupt on fifo not empty */
                   (cmd->flags & TRIG_WAKE_EOS) == 0 &&
                   /*  make sure we are taking more than just a few points */
@@ -1175,7 +1161,7 @@ static irqreturn_t labpc_interrupt(int irq, void *d)
 
        /* read board status */
        devpriv->stat1 = devpriv->read_byte(dev->iobase + STAT1_REG);
-       if (board->register_layout == labpc_1200_layout)
+       if (board->is_labpc1200)
                devpriv->stat2 = devpriv->read_byte(dev->iobase + STAT2_REG);
 
        if ((devpriv->stat1 & (STAT1_GATA0 | STAT1_CNTINT | STAT1_OVERFLOW |
@@ -1201,8 +1187,7 @@ static irqreturn_t labpc_interrupt(int irq, void *d)
                 * has occurred
                 */
                if (devpriv->stat1 & STAT1_GATA0 ||
-                   (board->register_layout == labpc_1200_layout
-                    && devpriv->stat2 & STAT2_OUTA1)) {
+                   (board->is_labpc1200 && devpriv->stat2 & STAT2_OUTA1)) {
                        handle_isa_dma(dev);
                }
        } else
@@ -1266,7 +1251,7 @@ static int labpc_ao_insn_write(struct comedi_device *dev,
        spin_unlock_irqrestore(&dev->spinlock, flags);
 
        /* set range */
-       if (board->register_layout == labpc_1200_layout) {
+       if (board->is_labpc1200) {
                range = CR_RANGE(insn->chanspec);
                if (labpc_range_is_unipolar(s, range))
                        devpriv->cmd6 |= CMD6_DACUNI(channel);
@@ -1603,7 +1588,7 @@ int labpc_common_attach(struct comedi_device *dev,
        devpriv->write_byte(devpriv->cmd2, dev->iobase + CMD2_REG);
        devpriv->write_byte(devpriv->cmd3, dev->iobase + CMD3_REG);
        devpriv->write_byte(devpriv->cmd4, dev->iobase + CMD4_REG);
-       if (board->register_layout == labpc_1200_layout) {
+       if (board->is_labpc1200) {
                devpriv->write_byte(devpriv->cmd5, dev->iobase + CMD5_REG);
                devpriv->write_byte(devpriv->cmd6, dev->iobase + CMD6_REG);
        }
@@ -1626,7 +1611,8 @@ int labpc_common_attach(struct comedi_device *dev,
        s->n_chan       = 8;
        s->len_chanlist = 8;
        s->maxdata      = 0x0fff;
-       s->range_table  = board->ai_range_table;
+       s->range_table  = board->is_labpc1200
+                               ? &range_labpc_1200_ai : &range_labpc_plus_ai;
        s->insn_read    = labpc_ai_insn_read;
        if (dev->irq) {
                dev->read_subdev = s;
@@ -1671,7 +1657,7 @@ int labpc_common_attach(struct comedi_device *dev,
 
        /*  calibration subdevices for boards that have one */
        s = &dev->subdevices[3];
-       if (board->register_layout == labpc_1200_layout) {
+       if (board->is_labpc1200) {
                s->type         = COMEDI_SUBD_CALIB;
                s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL;
                s->n_chan       = 16;
@@ -1686,7 +1672,7 @@ int labpc_common_attach(struct comedi_device *dev,
 
        /* EEPROM */
        s = &dev->subdevices[4];
-       if (board->register_layout == labpc_1200_layout) {
+       if (board->is_labpc1200) {
                s->type         = COMEDI_SUBD_MEMORY;
                s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL;
                s->n_chan       = EEPROM_SIZE;