ni_labpc_pci.c revision 641f064e5df6fb3aaeb6256031a153a5efb16ca6
1/* 2 * comedi/drivers/ni_labpc_pci.c 3 * Driver for National Instruments Lab-PC PCI-1200 4 * Copyright (C) 2001, 2002, 2003 Frank Mori Hess <fmhess@users.sourceforge.net> 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 */ 16 17/* 18 * Driver: ni_labpc_pci 19 * Description: National Instruments Lab-PC PCI-1200 20 * Devices: (National Instruments) PCI-1200 [ni_pci-1200] 21 * Author: Frank Mori Hess <fmhess@users.sourceforge.net> 22 * Status: works 23 * 24 * This is the PCI-specific support split off from the ni_labpc driver. 25 * 26 * Configuration Options: not applicable, uses PCI auto config 27 * 28 * NI manuals: 29 * 340914a (pci-1200) 30 */ 31 32#include <linux/interrupt.h> 33#include <linux/slab.h> 34#include <linux/pci.h> 35 36#include "../comedidev.h" 37 38#include "mite.h" 39#include "ni_labpc.h" 40 41enum labpc_pci_boardid { 42 BOARD_NI_PCI1200, 43}; 44 45static const struct labpc_boardinfo labpc_pci_boards[] = { 46 [BOARD_NI_PCI1200] = { 47 .name = "ni_pci-1200", 48 .ai_range_code = labpc_1200_ai_gain_bits, 49 .ai_speed = 10000, 50 .ai_scan_up = 1, 51 .has_ao = 1, 52 .is_labpc1200 = 1, 53 .has_mmio = 1, 54 }, 55}; 56 57static int labpc_pci_auto_attach(struct comedi_device *dev, 58 unsigned long context) 59{ 60 struct pci_dev *pcidev = comedi_to_pci_dev(dev); 61 const struct labpc_boardinfo *board = NULL; 62 struct labpc_private *devpriv; 63 int ret; 64 65 if (context < ARRAY_SIZE(labpc_pci_boards)) 66 board = &labpc_pci_boards[context]; 67 if (!board) 68 return -ENODEV; 69 dev->board_ptr = board; 70 dev->board_name = board->name; 71 72 ret = comedi_pci_enable(dev); 73 if (ret) 74 return ret; 75 76 devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL); 77 if (!devpriv) 78 return -ENOMEM; 79 dev->private = devpriv; 80 81 devpriv->mite = mite_alloc(pcidev); 82 if (!devpriv->mite) 83 return -ENOMEM; 84 ret = mite_setup(devpriv->mite); 85 if (ret < 0) 86 return ret; 87 dev->iobase = (unsigned long)devpriv->mite->daq_io_addr; 88 89 return labpc_common_attach(dev, mite_irq(devpriv->mite), IRQF_SHARED); 90} 91 92static void labpc_pci_detach(struct comedi_device *dev) 93{ 94 struct labpc_private *devpriv = dev->private; 95 96 labpc_common_detach(dev); 97 98 if (devpriv && devpriv->mite) { 99 mite_unsetup(devpriv->mite); 100 mite_free(devpriv->mite); 101 } 102 if (dev->irq) 103 free_irq(dev->irq, dev); 104 comedi_pci_disable(dev); 105} 106 107static struct comedi_driver labpc_pci_comedi_driver = { 108 .driver_name = "labpc_pci", 109 .module = THIS_MODULE, 110 .auto_attach = labpc_pci_auto_attach, 111 .detach = labpc_pci_detach, 112}; 113 114static DEFINE_PCI_DEVICE_TABLE(labpc_pci_table) = { 115 { PCI_VDEVICE(NI, 0x161), BOARD_NI_PCI1200 }, 116 { 0 } 117}; 118MODULE_DEVICE_TABLE(pci, labpc_pci_table); 119 120static int labpc_pci_probe(struct pci_dev *dev, 121 const struct pci_device_id *id) 122{ 123 return comedi_pci_auto_config(dev, &labpc_pci_comedi_driver, 124 id->driver_data); 125} 126 127static struct pci_driver labpc_pci_driver = { 128 .name = "labpc_pci", 129 .id_table = labpc_pci_table, 130 .probe = labpc_pci_probe, 131 .remove = comedi_pci_auto_unconfig, 132}; 133module_comedi_pci_driver(labpc_pci_comedi_driver, labpc_pci_driver); 134 135MODULE_DESCRIPTION("Comedi: National Instruments Lab-PC PCI-1200 driver"); 136MODULE_AUTHOR("Comedi http://www.comedi.org"); 137MODULE_LICENSE("GPL"); 138