]> rtime.felk.cvut.cz Git - mf6xx.git/blobdiff - src/comedi/mf614_simple_driver/kernel/mf614.c
Fixed all errors. Tested. Works. DIN + DOUT only.
[mf6xx.git] / src / comedi / mf614_simple_driver / kernel / mf614.c
index 3cf5dc4737c1b02c37bf0594669ac7a1859d066d..73568dd23b6e6b05df07e0acf1c0c99d6cd5991c 100644 (file)
@@ -4,6 +4,9 @@
 #define PCI_VENDOR_ID_MF614 0x186c
 #define PCI_DEVICE_ID_MF614 0x0614
 
+#define DIN_reg                0x6
+#define DOUT_reg       0x6
+
 
 static struct pci_device_id mf614_pci_table[] __devinitdata = {
        { PCI_VENDOR_ID_MF614, PCI_DEVICE_ID_MF614, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
@@ -36,6 +39,8 @@ static const mf614_board mf614_boards[] = {
        }
 };
 
+static int mf614_attach(struct comedi_device *dev, struct comedi_devconfig *it);
+static int mf614_detach(struct comedi_device *dev);
 static struct comedi_driver driver_mf614 = {
        driver_name:    "mf614",
        module:         THIS_MODULE,
@@ -55,12 +60,17 @@ typedef struct {
        //lsampl_t ao_readback[8];
 } mf614_private;
 
-static int mf614_attach(struct comedi_device *dev, struct comedi_devconfig *it);
-static int mf614_detach(struct comedi_device *dev);
 
 /*
 ==============================================================================
 */
+
+
+static int mf614_do_insn_bits(struct comedi_device *dev, struct comedi_subdevice *s, 
+                             struct comedi_insn *insn, unsigned int *data);
+static int mf614_di_insn_bits(struct comedi_device *dev, struct comedi_subdevice *s, 
+                             struct comedi_insn *insn, unsigned int *data);
+
 #define devpriv                ((mf614_private *) dev->private)
 #define thisboard              ((mf614_board *) dev->board_ptr)
 static int mf614_attach(struct comedi_device *dev, struct comedi_devconfig *it)
@@ -68,7 +78,7 @@ static int mf614_attach(struct comedi_device *dev, struct comedi_devconfig *it)
        struct comedi_subdevice *s;
        struct pci_dev* pcidev;
        //unsigned int channel; 
-       unsigned int status;
+       //unsigned int status;
 
        printk("comedi%d: mf614: ", dev->minor);
 
@@ -88,7 +98,7 @@ static int mf614_attach(struct comedi_device *dev, struct comedi_devconfig *it)
                        continue;
                }
 
-               if(mf614_boards.device_id != pcidev->device) {
+               if(mf614_boards[0].device_id != pcidev->device) {
                        continue;
                }
 
@@ -112,7 +122,7 @@ static int mf614_attach(struct comedi_device *dev, struct comedi_devconfig *it)
 
 found:
        printk("Found %s on bus %i, slot %i\n",  
-               mf614_boards.name, pcidev->bus->number, PCI_SLOT(pcidev->devfn));
+               mf614_boards[0].name, pcidev->bus->number, PCI_SLOT(pcidev->devfn));
 
        /* comedi_pci_enable(struct pci_dev *pdev, const char *res_name) */
        if(pci_enable_device(devpriv->pci_dev)) {
@@ -169,7 +179,7 @@ out_unmap:
 out_release:
        pci_release_regions(devpriv->pci_dev);
 out_disable:
-       pci_disable_device(devpriv->pcidev);
+       pci_disable_device(devpriv->pci_dev);
 out_exit:
        return -ENODEV;
 }
@@ -192,6 +202,37 @@ static int mf614_detach(struct comedi_device *dev)
        return 0;
 }
 
+/* Write digital data */
+static int mf614_do_insn_bits(struct comedi_device *dev, 
+                             struct comedi_subdevice *s, 
+                             struct comedi_insn *insn, unsigned int *data)
+{
+       if(insn->n != 2) {
+               return -EINVAL;
+       }
+
+       if(data[0]) {
+               s->state &= ~data[0];
+               s->state |= data[0] & data[1];
+
+               iowrite8(s->state, devpriv->BAR0_io + DOUT_reg);
+       }
+       return 2;
+}
+
+/* Read digital data */
+static int mf614_di_insn_bits(struct comedi_device *dev, 
+                             struct comedi_subdevice *s, 
+                             struct comedi_insn *insn, unsigned int *data)
+{
+       if(insn->n != 2) {
+               return -EINVAL;
+       }
+
+       data[1] = ioread8(devpriv->BAR0_io + DIN_reg);
+
+       return 2;
+}
 
 /*
 ==============================================================================