+/*
+ * 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>
#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;
}
}
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;
}
}
{
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);
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) {
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)
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)
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)
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);
}