ni_labpc_pci.c revision b876e985c2273b7bd2d5539f2147ef69f7701129
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/module.h>
33#include <linux/interrupt.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_speed		= 10000,
49		.ai_scan_up		= 1,
50		.has_ao			= 1,
51		.is_labpc1200		= 1,
52		.has_mmio		= 1,
53	},
54};
55
56static int labpc_pci_auto_attach(struct comedi_device *dev,
57				 unsigned long context)
58{
59	struct pci_dev *pcidev = comedi_to_pci_dev(dev);
60	const struct labpc_boardinfo *board = NULL;
61	struct labpc_private *devpriv;
62	int ret;
63
64	if (context < ARRAY_SIZE(labpc_pci_boards))
65		board = &labpc_pci_boards[context];
66	if (!board)
67		return -ENODEV;
68	dev->board_ptr = board;
69	dev->board_name = board->name;
70
71	ret = comedi_pci_enable(dev);
72	if (ret)
73		return ret;
74
75	devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
76	if (!devpriv)
77		return -ENOMEM;
78
79	devpriv->mite = mite_alloc(pcidev);
80	if (!devpriv->mite)
81		return -ENOMEM;
82	ret = mite_setup(devpriv->mite);
83	if (ret < 0)
84		return ret;
85	dev->iobase = (unsigned long)devpriv->mite->daq_io_addr;
86
87	return labpc_common_attach(dev, pcidev->irq, IRQF_SHARED);
88}
89
90static void labpc_pci_detach(struct comedi_device *dev)
91{
92	struct labpc_private *devpriv = dev->private;
93
94	if (devpriv)
95		mite_detach(devpriv->mite);
96	if (dev->irq)
97		free_irq(dev->irq, dev);
98	comedi_pci_disable(dev);
99}
100
101static struct comedi_driver labpc_pci_comedi_driver = {
102	.driver_name	= "labpc_pci",
103	.module		= THIS_MODULE,
104	.auto_attach	= labpc_pci_auto_attach,
105	.detach		= labpc_pci_detach,
106};
107
108static const struct pci_device_id labpc_pci_table[] = {
109	{ PCI_VDEVICE(NI, 0x161), BOARD_NI_PCI1200 },
110	{ 0 }
111};
112MODULE_DEVICE_TABLE(pci, labpc_pci_table);
113
114static int labpc_pci_probe(struct pci_dev *dev,
115			   const struct pci_device_id *id)
116{
117	return comedi_pci_auto_config(dev, &labpc_pci_comedi_driver,
118				      id->driver_data);
119}
120
121static struct pci_driver labpc_pci_driver = {
122	.name		= "labpc_pci",
123	.id_table	= labpc_pci_table,
124	.probe		= labpc_pci_probe,
125	.remove		= comedi_pci_auto_unconfig,
126};
127module_comedi_pci_driver(labpc_pci_comedi_driver, labpc_pci_driver);
128
129MODULE_DESCRIPTION("Comedi: National Instruments Lab-PC PCI-1200 driver");
130MODULE_AUTHOR("Comedi http://www.comedi.org");
131MODULE_LICENSE("GPL");
132