1 // SPDX-License-Identifier: GPL-2.0+
3 * comedi/drivers/ni_labpc_pci.c
4 * Driver for National Instruments Lab-PC PCI-1200
5 * Copyright (C) 2001, 2002, 2003 Frank Mori Hess <fmhess@users.sourceforge.net>
10 * Description: National Instruments Lab-PC PCI-1200
11 * Devices: [National Instruments] PCI-1200 (ni_pci-1200)
12 * Author: Frank Mori Hess <fmhess@users.sourceforge.net>
15 * This is the PCI-specific support split off from the ni_labpc driver.
17 * Configuration Options: not applicable, uses PCI auto config
23 #include <linux/module.h>
24 #include <linux/interrupt.h>
26 #include "../comedi_pci.h"
30 enum labpc_pci_boardid {
34 static const struct labpc_boardinfo labpc_pci_boards[] = {
35 [BOARD_NI_PCI1200] = {
36 .name = "ni_pci-1200",
44 /* ripped from mite.h and mite_setup2() to avoid mite dependency */
45 #define MITE_IODWBSR 0xc0 /* IO Device Window Base Size Register */
46 #define WENAB BIT(7) /* window enable */
48 static int labpc_pci_mite_init(struct pci_dev *pcidev)
50 void __iomem *mite_base;
53 /* ioremap the MITE registers (BAR 0) temporarily */
54 mite_base = pci_ioremap_bar(pcidev, 0);
58 /* set data window to main registers (BAR 1) */
59 main_phys_addr = pci_resource_start(pcidev, 1);
60 writel(main_phys_addr | WENAB, mite_base + MITE_IODWBSR);
62 /* finished with MITE registers */
67 static int labpc_pci_auto_attach(struct comedi_device *dev,
68 unsigned long context)
70 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
71 const struct labpc_boardinfo *board = NULL;
74 if (context < ARRAY_SIZE(labpc_pci_boards))
75 board = &labpc_pci_boards[context];
78 dev->board_ptr = board;
79 dev->board_name = board->name;
81 ret = comedi_pci_enable(dev);
85 ret = labpc_pci_mite_init(pcidev);
89 dev->mmio = pci_ioremap_bar(pcidev, 1);
93 return labpc_common_attach(dev, pcidev->irq, IRQF_SHARED);
96 static void labpc_pci_detach(struct comedi_device *dev)
98 labpc_common_detach(dev);
99 comedi_pci_detach(dev);
102 static struct comedi_driver labpc_pci_comedi_driver = {
103 .driver_name = "labpc_pci",
104 .module = THIS_MODULE,
105 .auto_attach = labpc_pci_auto_attach,
106 .detach = labpc_pci_detach,
109 static const struct pci_device_id labpc_pci_table[] = {
110 { PCI_VDEVICE(NI, 0x161), BOARD_NI_PCI1200 },
113 MODULE_DEVICE_TABLE(pci, labpc_pci_table);
115 static int labpc_pci_probe(struct pci_dev *dev,
116 const struct pci_device_id *id)
118 return comedi_pci_auto_config(dev, &labpc_pci_comedi_driver,
122 static struct pci_driver labpc_pci_driver = {
124 .id_table = labpc_pci_table,
125 .probe = labpc_pci_probe,
126 .remove = comedi_pci_auto_unconfig,
128 module_comedi_pci_driver(labpc_pci_comedi_driver, labpc_pci_driver);
130 MODULE_DESCRIPTION("Comedi: National Instruments Lab-PC PCI-1200 driver");
131 MODULE_AUTHOR("Comedi https://www.comedi.org");
132 MODULE_LICENSE("GPL");