]> rtime.felk.cvut.cz Git - mf6xx.git/blobdiff - src/uio/mf624/kernel/mf624.c
Added license and copyright information to most important files.
[mf6xx.git] / src / uio / mf624 / kernel / mf624.c
index 939f290155212163a78fac26a64bb260b1d4e8d4..ebd5fc60ae4f02acb10495d1b7e1455565874c41 100755 (executable)
@@ -1,3 +1,22 @@
+/*
+ * UIO driver fo Humusoft MF624 DAQ card.
+ * Copyright (C) 2011 Rostislav Lisovy <lisovy@gmail.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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/device.h>
@@ -7,6 +26,7 @@
 #include <linux/kernel.h>
 #include <linux/uio_driver.h>
 
+
 #define PCI_VENDOR_ID_HUMUSOFT         0x186c
 #define PCI_DEVICE_ID_MF624            0x0624
 #define PCI_SUBVENDOR_ID_HUMUSOFT      0x186c
 #define INTCSR_ADINT_STATUS            (1 << 2)
 #define INTCSR_CTR4INT_STATUS          (1 << 5)
 
-
 typedef enum {ADC, CTR4, ALL} mf624_interrupt_source_t;
 
+
 void mf624_disable_interrupt(mf624_interrupt_source_t source, struct uio_info *info)
 {
        u32 *INTCSR_reg = ((u32*) info->mem[0].internal_addr) + INTCSR;
 
        switch (source) {
                case ADC:
-                       *INTCSR_reg &= ~(INTCSR_ADINT_ENABLE);
+                       iowrite32(ioread32(INTCSR_reg) & ~(INTCSR_ADINT_ENABLE), 
+                               INTCSR_reg);
                        break;
                case CTR4:
-                       *INTCSR_reg &= ~(INTCSR_CTR4INT_ENABLE);
+                       iowrite32(ioread32(INTCSR_reg) & ~(INTCSR_CTR4INT_ENABLE), 
+                               INTCSR_reg);
                        break;
                case ALL:
-                       *INTCSR_reg &= ~(INTCSR_ADINT_ENABLE | INTCSR_CTR4INT_ENABLE);
+                       iowrite32(ioread32(INTCSR_reg) & ~(INTCSR_ADINT_ENABLE | INTCSR_CTR4INT_ENABLE),
+                               INTCSR_reg);
                        break;
                default:
-                       *INTCSR_reg &= ~(INTCSR_ADINT_ENABLE | INTCSR_CTR4INT_ENABLE);
+                       iowrite32(ioread32(INTCSR_reg) & ~(INTCSR_ADINT_ENABLE | INTCSR_CTR4INT_ENABLE), 
+                               INTCSR_reg);
                        break;
        }
 }
@@ -48,16 +72,20 @@ void mf624_enable_interrupt(mf624_interrupt_source_t source, struct uio_info *in
 
        switch (source) {
                case ADC:
-                       *INTCSR_reg |= (INTCSR_ADINT_ENABLE);
+                       iowrite32(ioread32(INTCSR_reg) | (INTCSR_ADINT_ENABLE), 
+                               INTCSR_reg);
                        break;
                case CTR4:
-                       *INTCSR_reg |= (INTCSR_CTR4INT_ENABLE);
+                       iowrite32(ioread32(INTCSR_reg) | (INTCSR_CTR4INT_ENABLE),
+                               INTCSR_reg);
                        break;
                case ALL:
-                       *INTCSR_reg |= (INTCSR_ADINT_ENABLE | INTCSR_CTR4INT_ENABLE);
+                       iowrite32(ioread32(INTCSR_reg) | (INTCSR_ADINT_ENABLE | INTCSR_CTR4INT_ENABLE),
+                               INTCSR_reg);
                        break;
                default:
-                       *INTCSR_reg |= (INTCSR_ADINT_ENABLE | INTCSR_CTR4INT_ENABLE);
+                       iowrite32(ioread32(INTCSR_reg) | (INTCSR_ADINT_ENABLE | INTCSR_CTR4INT_ENABLE),
+                               INTCSR_reg);
                        break;
        }
 }
@@ -66,14 +94,16 @@ static irqreturn_t mf624_irq_handler(int irq, struct uio_info *info)
 {
        u32 *INTCSR_reg = ((u32*) info->mem[0].internal_addr) + INTCSR;
 
-       if (((*INTCSR_reg & INTCSR_ADINT_ENABLE) > 0) && ((*INTCSR_reg & INTCSR_ADINT_STATUS) > 0))
+       if (((ioread32(INTCSR_reg) & INTCSR_ADINT_ENABLE) > 0) 
+               && ((ioread32(INTCSR_reg) & INTCSR_ADINT_STATUS) > 0))
        {
                //disable interrupt
                mf624_disable_interrupt(ADC, info);
                return IRQ_HANDLED;
        }
 
-       if (((*INTCSR_reg & INTCSR_CTR4INT_ENABLE) > 0) && ((*INTCSR_reg & INTCSR_CTR4INT_STATUS) > 0))
+       if (((ioread32(INTCSR_reg) & INTCSR_CTR4INT_ENABLE) > 0) 
+               && ((ioread32(INTCSR_reg) & INTCSR_CTR4INT_STATUS) > 0))
        {
                //disable interrupt
                mf624_disable_interrupt(CTR4, info);
@@ -85,7 +115,7 @@ static irqreturn_t mf624_irq_handler(int irq, struct uio_info *info)
 
 static int mf624_irqcontrol(struct uio_info *info, s32 irq_on)
 {
-       if (irq_on == 0) { /* Disable interrupts */
+       if (irq_on == 0) { // Disable interrupts
                mf624_disable_interrupt(ALL, info);
        } 
        else if (irq_on == 1) {
@@ -110,9 +140,10 @@ static int __devinit mf624_pci_probe(struct pci_dev *dev,
        if (pci_request_regions(dev, "mf624"))
                goto out_disable;
        
-       info->name = "MF624";
+       info->name = "mf624";
        info->version = "0.0.1";
 
+       // BAR0
        info->mem[0].name = "PCI chipset, interrupts, status bits, special functions";
        info->mem[0].addr = pci_resource_start(dev, 0);
        if (!info->mem[0].addr)
@@ -123,7 +154,8 @@ static int __devinit mf624_pci_probe(struct pci_dev *dev,
        if (!info->mem[0].internal_addr)
                goto out_release;
 
-       
+
+       //BAR2  
        info->mem[1].name = "ADC, DAC, DIO";
        info->mem[1].addr = pci_resource_start(dev, 2);
        if (!info->mem[1].addr)
@@ -135,6 +167,7 @@ static int __devinit mf624_pci_probe(struct pci_dev *dev,
                goto out_release;
 
 
+       //BAR4
        info->mem[2].name = "Counter/timer chip";
        info->mem[2].addr = pci_resource_start(dev, 4);
        if (!info->mem[2].addr)
@@ -183,7 +216,11 @@ static void mf624_pci_remove(struct pci_dev *dev)
        pci_release_regions(dev);
        pci_disable_device(dev);
        pci_set_drvdata(dev, NULL);
-       
+
+       iounmap(info->mem[0].internal_addr);
+       iounmap(info->mem[1].internal_addr);
+       iounmap(info->mem[2].internal_addr);
+
        kfree(info);
 }