2 * UIO driver fo Humusoft MF614 DAQ card.
3 * Copyright (C) 2010--2011 Rostislav Lisovy <lisovy@gmail.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <linux/init.h>
21 #include <linux/module.h>
22 #include <linux/device.h>
23 #include <linux/pci.h>
24 #include <linux/slab.h>
26 #include <linux/kernel.h>
27 #include <linux/uio_driver.h>
29 #define PCI_VENDOR_ID_HUMUSOFT 0x186c
30 #define PCI_DEVICE_ID_MF614 0x0614
31 #define PCI_SUBVENDOR_ID_HUMUSOFT 0x186c
32 #define PCI_SUBDEVICE_DEVICE 0x0000
34 #define STATUS_REG 0x10
35 #define STATUS_T5INTE (u32) (1 << 19)
36 #define STATUS_T5 (u32) (1 << 3)
37 #define STATUS_CCINTE (u32) (1 << 18)
38 #define STATUS_CC (u32) (1 << 2)
41 static irqreturn_t mf614_irq_handler(int irq, struct uio_info *info)
43 void __iomem *status_reg = info->priv;
44 status_reg = ((u8*) status_reg) + STATUS_REG;
47 if ((ioread32(status_reg) & STATUS_T5INTE)
48 && (ioread32(status_reg) & STATUS_T5))
51 iowrite32(ioread32(status_reg) & ~STATUS_T5INTE, status_reg);
55 if ((ioread32(status_reg) & STATUS_CCINTE)
56 && (ioread32(status_reg) & STATUS_CC))
59 iowrite32(ioread32(status_reg) & ~STATUS_CCINTE, status_reg);
66 static int mf614_irqcontrol(struct uio_info *info, s32 irq_on)
68 void __iomem *status_reg = info->priv;
69 status_reg = ((u8*) status_reg) + STATUS_REG;
72 if (irq_on == 0) { /* Disable interrupts */
73 iowrite32(ioread32(status_reg) & ~STATUS_T5INTE, status_reg);
74 iowrite32(ioread32(status_reg) & ~STATUS_CCINTE, status_reg);
76 else if (irq_on == 1) {
77 iowrite32(ioread32(status_reg) | STATUS_T5INTE, status_reg);
78 iowrite32(ioread32(status_reg) | STATUS_CCINTE, status_reg);
84 static int __devinit mf614_pci_probe(struct pci_dev *dev,
85 const struct pci_device_id *id)
87 struct uio_info *info;
89 info = kzalloc(sizeof(struct uio_info), GFP_KERNEL);
93 if (pci_enable_device(dev))
96 if (pci_request_regions(dev, "mf614"))
100 info->version = "0.0.1";
102 info->port[0].name = "Board programming registers";
103 info->port[0].porttype = UIO_PORT_X86;
104 info->port[0].start = pci_resource_start(dev, 0);
105 if (!info->port[0].start)
107 info->port[0].size = pci_resource_len(dev, 0);
110 info->port[1].name = "OX9162 local configuration registers";
111 info->port[1].porttype = UIO_PORT_X86;
112 info->port[1].start = pci_resource_start(dev, 2);
113 if (!info->port[1].start)
115 info->port[1].size = pci_resource_len(dev, 2);
117 info->priv = pci_iomap(dev, 2, 0);
122 info->mem[0].name = "Board programming registers";
123 info->mem[0].addr = pci_resource_start(dev, 4);
124 if (!info->mem[0].addr)
126 info->mem[0].size = pci_resource_len(dev, 4);
127 info->mem[0].memtype = UIO_MEM_PHYS;
128 info->mem[0].internal_addr = pci_ioremap_bar(dev, 4);
129 if (!info->mem[0].internal_addr)
133 info->mem[1].name = "OX9162 local configuration registers";
134 info->mem[1].addr = pci_resource_start(dev, 3);
135 if (!info->mem[1].addr)
137 info->mem[1].size = pci_resource_len(dev, 3);
138 info->mem[1].memtype = UIO_MEM_PHYS;
139 info->mem[1].internal_addr = pci_ioremap_bar(dev, 3);
140 if (!info->mem[1].internal_addr)
144 info->irq = dev->irq;
145 info->irq_flags = IRQF_SHARED;
146 info->handler = mf614_irq_handler;
148 info->irqcontrol = mf614_irqcontrol;
150 if(uio_register_device(&dev->dev, info))
153 pci_set_drvdata(dev, info);
158 iounmap(info->mem[0].internal_addr);
159 iounmap(info->mem[1].internal_addr);
160 pci_iounmap(dev, info->priv);
162 pci_release_regions(dev);
164 pci_disable_device(dev);
170 static void mf614_pci_remove(struct pci_dev *dev)
172 struct uio_info *info = pci_get_drvdata(dev);
173 void __iomem *status_reg = info->priv;
174 status_reg = ((u8*) status_reg) + STATUS_REG;
176 /* Disable interrupts */
177 iowrite32(ioread32(status_reg) & ~STATUS_T5INTE, status_reg);
178 iowrite32(ioread32(status_reg) & ~STATUS_CCINTE, status_reg);
180 uio_unregister_device(info);
181 pci_release_regions(dev);
182 pci_disable_device(dev);
183 pci_set_drvdata(dev, NULL);
184 pci_iounmap(dev, info->priv);
185 iounmap(info->mem[0].internal_addr);
186 iounmap(info->mem[1].internal_addr);
191 static struct pci_device_id mf614_pci_id[] __devinitdata = {
193 .vendor = PCI_VENDOR_ID_HUMUSOFT,
194 .device = PCI_DEVICE_ID_MF614,
195 .subvendor = PCI_SUBVENDOR_ID_HUMUSOFT,
196 .subdevice = PCI_SUBDEVICE_DEVICE,
200 MODULE_DEVICE_TABLE(pci, mf614_pci_driver);
202 static struct pci_driver mf614_pci_driver = {
204 .id_table = mf614_pci_id,
205 .probe = mf614_pci_probe,
206 .remove = mf614_pci_remove,
209 static int __init mf614_init_module(void)
211 return pci_register_driver(&mf614_pci_driver);
214 static void __exit mf614_exit_module(void)
216 pci_unregister_driver(&mf614_pci_driver);
219 module_init(mf614_init_module);
220 module_exit(mf614_exit_module);
222 MODULE_LICENSE("GPL v2");
223 MODULE_AUTHOR("Rostislav Lisovy <lisovy@gmail.com>");