MAINTAINERS: Add INTEL MERRIFIELD GPIO entry
[cascardo/linux.git] / drivers / staging / comedi / drivers / ni_tiocmd.c
index 823e479..9007c57 100644 (file)
@@ -1,19 +1,18 @@
 /*
-  comedi/drivers/ni_tiocmd.c
-  Command support for NI general purpose counters
-
-  Copyright (C) 2006 Frank Mori Hess <fmhess@users.sourceforge.net>
-
-  This program is free software; you can redistribute it and/or modify
-  it under the terms of the GNU General Public License as published by
-  the Free Software Foundation; either version 2 of the License, or
-  (at your option) any later version.
-
-  This program is distributed in the hope that it will be useful,
-  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.
-*/
+ * Command support for NI general purpose counters
+ *
+ * Copyright (C) 2006 Frank Mori Hess <fmhess@users.sourceforge.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * 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.
+ */
 
 /*
  * Module: ni_tiocmd
  * DAQ 660x Register-Level Programmer Manual  (NI 370505A-01)
  * DAQ 6601/6602 User Manual (NI 322137B-01)
  * 340934b.pdf  DAQ-STC reference manual
+ *
+ * TODO: Support use of both banks X and Y
  */
 
-/*
-TODO:
-       Support use of both banks X and Y
-*/
-
 #include <linux/module.h>
 #include "ni_tio_internal.h"
 #include "mite.h"
@@ -51,9 +47,9 @@ static void ni_tio_configure_dma(struct ni_gpct *counter,
                                 bool enable, bool read)
 {
        struct ni_gpct_device *counter_dev = counter->counter_dev;
-       unsigned cidx = counter->counter_index;
-       unsigned mask;
-       unsigned bits;
+       unsigned int cidx = counter->counter_index;
+       unsigned int mask;
+       unsigned int bits;
 
        mask = GI_READ_ACKS_IRQ | GI_WRITE_ACKS_IRQ;
        bits = 0;
@@ -103,7 +99,7 @@ static int ni_tio_input_inttrig(struct comedi_device *dev,
        spin_unlock_irqrestore(&counter->lock, flags);
        if (ret < 0)
                return ret;
-       ret = ni_tio_arm(counter, 1, NI_GPCT_ARM_IMMEDIATE);
+       ret = ni_tio_arm(counter, true, NI_GPCT_ARM_IMMEDIATE);
        s->async->inttrig = NULL;
 
        return ret;
@@ -113,7 +109,7 @@ static int ni_tio_input_cmd(struct comedi_subdevice *s)
 {
        struct ni_gpct *counter = s->private;
        struct ni_gpct_device *counter_dev = counter->counter_dev;
-       unsigned cidx = counter->counter_index;
+       unsigned int cidx = counter->counter_index;
        struct comedi_async *async = s->async;
        struct comedi_cmd *cmd = &async->cmd;
        int ret = 0;
@@ -129,9 +125,6 @@ static int ni_tio_input_cmd(struct comedi_subdevice *s)
        case ni_gpct_variant_e_series:
                mite_prep_dma(counter->mite_chan, 16, 32);
                break;
-       default:
-               BUG();
-               break;
        }
        ni_tio_set_bits(counter, NITIO_CMD_REG(cidx), GI_SAVE_TRACE, 0);
        ni_tio_configure_dma(counter, true, true);
@@ -143,9 +136,9 @@ static int ni_tio_input_cmd(struct comedi_subdevice *s)
                mite_dma_arm(counter->mite_chan);
 
                if (cmd->start_src == TRIG_NOW)
-                       ret = ni_tio_arm(counter, 1, NI_GPCT_ARM_IMMEDIATE);
+                       ret = ni_tio_arm(counter, true, NI_GPCT_ARM_IMMEDIATE);
                else if (cmd->start_src == TRIG_EXT)
-                       ret = ni_tio_arm(counter, 1, cmd->start_arg);
+                       ret = ni_tio_arm(counter, true, cmd->start_arg);
        }
        return ret;
 }
@@ -163,9 +156,9 @@ static int ni_tio_cmd_setup(struct comedi_subdevice *s)
 {
        struct comedi_cmd *cmd = &s->async->cmd;
        struct ni_gpct *counter = s->private;
-       unsigned cidx = counter->counter_index;
+       unsigned int cidx = counter->counter_index;
        int set_gate_source = 0;
-       unsigned gate_source;
+       unsigned int gate_source;
        int retval = 0;
 
        if (cmd->scan_begin_src == TRIG_EXT) {
@@ -289,10 +282,10 @@ EXPORT_SYMBOL_GPL(ni_tio_cmdtest);
 
 int ni_tio_cancel(struct ni_gpct *counter)
 {
-       unsigned cidx = counter->counter_index;
+       unsigned int cidx = counter->counter_index;
        unsigned long flags;
 
-       ni_tio_arm(counter, 0, 0);
+       ni_tio_arm(counter, false, 0);
        spin_lock_irqsave(&counter->lock, flags);
        if (counter->mite_chan)
                mite_dma_disarm(counter->mite_chan);
@@ -305,9 +298,6 @@ int ni_tio_cancel(struct ni_gpct *counter)
 }
 EXPORT_SYMBOL_GPL(ni_tio_cancel);
 
-       /* During buffered input counter operation for e-series, the gate
-          interrupt is acked automatically by the dma controller, due to the
-          Gi_Read/Write_Acknowledges_IRQ bits in the input select register.  */
 static int should_ack_gate(struct ni_gpct *counter)
 {
        unsigned long flags;
@@ -315,12 +305,19 @@ static int should_ack_gate(struct ni_gpct *counter)
 
        switch (counter->counter_dev->variant) {
        case ni_gpct_variant_m_series:
-       /*  not sure if 660x really supports gate
-           interrupts (the bits are not listed
-           in register-level manual) */
        case ni_gpct_variant_660x:
+               /*
+                * not sure if 660x really supports gate interrupts
+                * (the bits are not listed in register-level manual)
+                */
                return 1;
        case ni_gpct_variant_e_series:
+               /*
+                * During buffered input counter operation for e-series,
+                * the gate interrupt is acked automatically by the dma
+                * controller, due to the Gi_Read/Write_Acknowledges_IRQ
+                * bits in the input select register.
+                */
                spin_lock_irqsave(&counter->lock, flags);
                {
                        if (!counter->mite_chan ||
@@ -338,15 +335,14 @@ static int should_ack_gate(struct ni_gpct *counter)
 static void ni_tio_acknowledge_and_confirm(struct ni_gpct *counter,
                                           int *gate_error,
                                           int *tc_error,
-                                          int *perm_stale_data,
-                                          int *stale_data)
+                                          int *perm_stale_data)
 {
-       unsigned cidx = counter->counter_index;
-       const unsigned short gxx_status = read_register(counter,
+       unsigned int cidx = counter->counter_index;
+       const unsigned short gxx_status = ni_tio_read(counter,
                                                NITIO_SHARED_STATUS_REG(cidx));
-       const unsigned short gi_status = read_register(counter,
+       const unsigned short gi_status = ni_tio_read(counter,
                                                NITIO_STATUS_REG(cidx));
-       unsigned ack = 0;
+       unsigned int ack = 0;
 
        if (gate_error)
                *gate_error = 0;
@@ -354,15 +350,15 @@ static void ni_tio_acknowledge_and_confirm(struct ni_gpct *counter,
                *tc_error = 0;
        if (perm_stale_data)
                *perm_stale_data = 0;
-       if (stale_data)
-               *stale_data = 0;
 
        if (gxx_status & GI_GATE_ERROR(cidx)) {
                ack |= GI_GATE_ERROR_CONFIRM(cidx);
                if (gate_error) {
-                       /*660x don't support automatic acknowledgment
-                         of gate interrupt via dma read/write
-                          and report bogus gate errors */
+                       /*
+                        * 660x don't support automatic acknowledgment
+                        * of gate interrupt via dma read/write
+                        * and report bogus gate errors
+                        */
                        if (counter->counter_dev->variant !=
                            ni_gpct_variant_660x)
                                *gate_error = 1;
@@ -380,14 +376,10 @@ static void ni_tio_acknowledge_and_confirm(struct ni_gpct *counter,
                        ack |= GI_GATE_INTERRUPT_ACK;
        }
        if (ack)
-               write_register(counter, ack, NITIO_INT_ACK_REG(cidx));
+               ni_tio_write(counter, ack, NITIO_INT_ACK_REG(cidx));
        if (ni_tio_get_soft_copy(counter, NITIO_MODE_REG(cidx)) &
            GI_LOADING_ON_GATE) {
-               if (gxx_status & GI_STALE_DATA(cidx)) {
-                       if (stale_data)
-                               *stale_data = 1;
-               }
-               if (read_register(counter, NITIO_STATUS2_REG(cidx)) &
+               if (ni_tio_read(counter, NITIO_STATUS2_REG(cidx)) &
                    GI_PERMANENT_STALE(cidx)) {
                        dev_info(counter->counter_dev->dev->class_dev,
                                 "%s: Gi_Permanent_Stale_Data detected.\n",
@@ -400,22 +392,21 @@ static void ni_tio_acknowledge_and_confirm(struct ni_gpct *counter,
 
 void ni_tio_acknowledge(struct ni_gpct *counter)
 {
-       ni_tio_acknowledge_and_confirm(counter, NULL, NULL, NULL, NULL);
+       ni_tio_acknowledge_and_confirm(counter, NULL, NULL, NULL);
 }
 EXPORT_SYMBOL_GPL(ni_tio_acknowledge);
 
 void ni_tio_handle_interrupt(struct ni_gpct *counter,
                             struct comedi_subdevice *s)
 {
-       unsigned cidx = counter->counter_index;
-       unsigned gpct_mite_status;
+       unsigned int cidx = counter->counter_index;
        unsigned long flags;
        int gate_error;
        int tc_error;
        int perm_stale_data;
 
        ni_tio_acknowledge_and_confirm(counter, &gate_error, &tc_error,
-                                      &perm_stale_data, NULL);
+                                      &perm_stale_data);
        if (gate_error) {
                dev_notice(counter->counter_dev->dev->class_dev,
                           "%s: Gi_Gate_Error detected.\n", __func__);
@@ -426,7 +417,7 @@ void ni_tio_handle_interrupt(struct ni_gpct *counter,
        switch (counter->counter_dev->variant) {
        case ni_gpct_variant_m_series:
        case ni_gpct_variant_660x:
-               if (read_register(counter, NITIO_DMA_STATUS_REG(cidx)) &
+               if (ni_tio_read(counter, NITIO_DMA_STATUS_REG(cidx)) &
                    GI_DRQ_ERROR) {
                        dev_notice(counter->counter_dev->dev->class_dev,
                                   "%s: Gi_DRQ_Error detected.\n", __func__);
@@ -437,16 +428,8 @@ void ni_tio_handle_interrupt(struct ni_gpct *counter,
                break;
        }
        spin_lock_irqsave(&counter->lock, flags);
-       if (!counter->mite_chan) {
-               spin_unlock_irqrestore(&counter->lock, flags);
-               return;
-       }
-       gpct_mite_status = mite_get_status(counter->mite_chan);
-       if (gpct_mite_status & CHSR_LINKC)
-               writel(CHOR_CLRLC,
-                      counter->mite_chan->mite->mite_io_addr +
-                      MITE_CHOR(counter->mite_chan->channel));
-       mite_sync_input_dma(counter->mite_chan, s);
+       if (counter->mite_chan)
+               mite_ack_linkc(counter->mite_chan, s, true);
        spin_unlock_irqrestore(&counter->lock, flags);
 }
 EXPORT_SYMBOL_GPL(ni_tio_handle_interrupt);