staging: comedi: addi_apci_1032: merge in hwdrv_apci1032.c
[firefly-linux-kernel-4.4.55.git] / drivers / staging / comedi / drivers / addi_apci_1032.c
index ab346719671af087d7c657cc6c928a6126c6892c..3d5cbbfc8b327a08c0542cb90f6da2949392958c 100644 (file)
+/*
+ * addi_apci_1032.c
+ * Copyright (C) 2004,2005  ADDI-DATA GmbH for the source code of this module.
+ * Project manager: Eric Stolz
+ *
+ *     ADDI-DATA GmbH
+ *     Dieselstrasse 3
+ *     D-77833 Ottersweier
+ *     Tel: +19(0)7223/9493-0
+ *     Fax: +49(0)7223/9493-92
+ *     http://www.addi-data.com
+ *     info@addi-data.com
+ *
+ * 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.
+ *
+ * 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., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * You should also find the complete GPL in the COPYING file accompanying this
+ * source code.
+ */
+
 #include "../comedidev.h"
 #include "comedi_fc.h"
 #include "amcc_s5933.h"
 
 #include "addi-data/addi_common.h"
 
-#include "addi-data/hwdrv_apci1032.c"
+/*
+ * I/O Register Map
+ */
+#define APCI1032_DI_REG                        0x00
+#define APCI1032_MODE1_REG             0x04
+#define APCI1032_MODE2_REG             0x08
+#define APCI1032_STATUS_REG            0x0c
+#define APCI1032_CTRL_REG              0x10
+#define APCI1032_CTRL_INT_OR           (0 << 1)
+#define APCI1032_CTRL_INT_AND          (1 << 1)
+#define APCI1032_CTRL_INT_ENA          (1 << 2)
+
+/* Digital Input IRQ Function Selection */
+#define ADDIDATA_OR                            0
+#define ADDIDATA_AND                           1
+
+static unsigned int ui_InterruptStatus;
+
+/*
+ * data[0] : 1 Enable  Digital Input Interrupt
+ *           0 Disable Digital Input Interrupt
+ * data[1] : 0 ADDIDATA Interrupt OR LOGIC
+ *         : 1 ADDIDATA Interrupt AND LOGIC
+ * data[2] : Interrupt mask for the mode 1
+ * data[3] : Interrupt mask for the mode 2
+ */
+static int i_APCI1032_ConfigDigitalInput(struct comedi_device *dev,
+                                        struct comedi_subdevice *s,
+                                        struct comedi_insn *insn,
+                                        unsigned int *data)
+{
+       struct addi_private *devpriv = dev->private;
+       unsigned int ui_TmpValue;
+       unsigned int ul_Command1 = 0;
+       unsigned int ul_Command2 = 0;
+
+       devpriv->tsk_Current = current;
+
+  /*******************************/
+       /* Set the digital input logic */
+  /*******************************/
+       if (data[0] == ADDIDATA_ENABLE) {
+               ul_Command1 = ul_Command1 | data[2];
+               ul_Command2 = ul_Command2 | data[3];
+               outl(ul_Command1, dev->iobase + APCI1032_MODE1_REG);
+               outl(ul_Command2, dev->iobase + APCI1032_MODE2_REG);
+               if (data[1] == ADDIDATA_OR) {
+                       outl(APCI1032_CTRL_INT_ENA |
+                            APCI1032_CTRL_INT_OR,
+                            dev->iobase + APCI1032_CTRL_REG);
+                       ui_TmpValue =
+                               inl(dev->iobase + APCI1032_CTRL_REG);
+               }               /* if (data[1] == ADDIDATA_OR) */
+               else
+                       outl(APCI1032_CTRL_INT_ENA |
+                            APCI1032_CTRL_INT_AND,
+                            dev->iobase + APCI1032_CTRL_REG);
+                               /* else if(data[1] == ADDIDATA_OR) */
+       }                       /*  if( data[0] == ADDIDATA_ENABLE) */
+       else {
+               ul_Command1 = ul_Command1 & 0xFFFF0000;
+               ul_Command2 = ul_Command2 & 0xFFFF0000;
+               outl(ul_Command1, dev->iobase + APCI1032_MODE1_REG);
+               outl(ul_Command2, dev->iobase + APCI1032_MODE2_REG);
+               outl(0x0, dev->iobase + APCI1032_CTRL_REG);
+       }                       /* else if  ( data[0] == ADDIDATA_ENABLE) */
+
+       return insn->n;
+}
 
 static irqreturn_t apci1032_interrupt(int irq, void *d)
 {