]>
Commit | Line | Data |
---|---|---|
e184e2be | 1 | // SPDX-License-Identifier: GPL-2.0+ |
fa3cb219 HS |
2 | /* |
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> | |
fa3cb219 HS |
6 | */ |
7 | ||
8 | /* | |
9 | * Driver: ni_labpc_pci | |
10 | * Description: National Instruments Lab-PC PCI-1200 | |
7b8bffe8 | 11 | * Devices: [National Instruments] PCI-1200 (ni_pci-1200) |
fa3cb219 HS |
12 | * Author: Frank Mori Hess <fmhess@users.sourceforge.net> |
13 | * Status: works | |
14 | * | |
15 | * This is the PCI-specific support split off from the ni_labpc driver. | |
16 | * | |
17 | * Configuration Options: not applicable, uses PCI auto config | |
18 | * | |
19 | * NI manuals: | |
20 | * 340914a (pci-1200) | |
21 | */ | |
22 | ||
ce157f80 | 23 | #include <linux/module.h> |
fa3cb219 | 24 | #include <linux/interrupt.h> |
fa3cb219 | 25 | |
fffd65dc | 26 | #include "../comedi_pci.h" |
fa3cb219 | 27 | |
fa3cb219 HS |
28 | #include "ni_labpc.h" |
29 | ||
30 | enum labpc_pci_boardid { | |
31 | BOARD_NI_PCI1200, | |
32 | }; | |
33 | ||
34 | static const struct labpc_boardinfo labpc_pci_boards[] = { | |
35 | [BOARD_NI_PCI1200] = { | |
36 | .name = "ni_pci-1200", | |
63d6ba20 | 37 | .ai_speed = 10000, |
fa3cb219 | 38 | .ai_scan_up = 1, |
63d6ba20 HS |
39 | .has_ao = 1, |
40 | .is_labpc1200 = 1, | |
fa3cb219 HS |
41 | }, |
42 | }; | |
43 | ||
9949595c | 44 | /* ripped from mite.h and mite_setup2() to avoid mite dependency */ |
0edf7b85 HS |
45 | #define MITE_IODWBSR 0xc0 /* IO Device Window Base Size Register */ |
46 | #define WENAB BIT(7) /* window enable */ | |
319a883b HS |
47 | |
48 | static int labpc_pci_mite_init(struct pci_dev *pcidev) | |
49 | { | |
50 | void __iomem *mite_base; | |
51 | u32 main_phys_addr; | |
52 | ||
53 | /* ioremap the MITE registers (BAR 0) temporarily */ | |
54 | mite_base = pci_ioremap_bar(pcidev, 0); | |
55 | if (!mite_base) | |
56 | return -ENOMEM; | |
57 | ||
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); | |
61 | ||
62 | /* finished with MITE registers */ | |
63 | iounmap(mite_base); | |
64 | return 0; | |
65 | } | |
66 | ||
fa3cb219 HS |
67 | static int labpc_pci_auto_attach(struct comedi_device *dev, |
68 | unsigned long context) | |
69 | { | |
70 | struct pci_dev *pcidev = comedi_to_pci_dev(dev); | |
71 | const struct labpc_boardinfo *board = NULL; | |
fa3cb219 HS |
72 | int ret; |
73 | ||
74 | if (context < ARRAY_SIZE(labpc_pci_boards)) | |
75 | board = &labpc_pci_boards[context]; | |
76 | if (!board) | |
77 | return -ENODEV; | |
78 | dev->board_ptr = board; | |
79 | dev->board_name = board->name; | |
80 | ||
81 | ret = comedi_pci_enable(dev); | |
82 | if (ret) | |
83 | return ret; | |
84 | ||
319a883b HS |
85 | ret = labpc_pci_mite_init(pcidev); |
86 | if (ret) | |
87 | return ret; | |
88 | ||
70f72867 HS |
89 | dev->mmio = pci_ioremap_bar(pcidev, 1); |
90 | if (!dev->mmio) | |
fa3cb219 | 91 | return -ENOMEM; |
fa3cb219 | 92 | |
ba9d29fe | 93 | return labpc_common_attach(dev, pcidev->irq, IRQF_SHARED); |
fa3cb219 HS |
94 | } |
95 | ||
c0cfeca1 HS |
96 | static void labpc_pci_detach(struct comedi_device *dev) |
97 | { | |
98 | labpc_common_detach(dev); | |
99 | comedi_pci_detach(dev); | |
100 | } | |
101 | ||
fa3cb219 HS |
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, | |
c0cfeca1 | 106 | .detach = labpc_pci_detach, |
fa3cb219 HS |
107 | }; |
108 | ||
41e043fc | 109 | static const struct pci_device_id labpc_pci_table[] = { |
fa3cb219 HS |
110 | { PCI_VDEVICE(NI, 0x161), BOARD_NI_PCI1200 }, |
111 | { 0 } | |
112 | }; | |
113 | MODULE_DEVICE_TABLE(pci, labpc_pci_table); | |
114 | ||
115 | static int labpc_pci_probe(struct pci_dev *dev, | |
116 | const struct pci_device_id *id) | |
117 | { | |
118 | return comedi_pci_auto_config(dev, &labpc_pci_comedi_driver, | |
119 | id->driver_data); | |
120 | } | |
121 | ||
122 | static struct pci_driver labpc_pci_driver = { | |
123 | .name = "labpc_pci", | |
124 | .id_table = labpc_pci_table, | |
125 | .probe = labpc_pci_probe, | |
126 | .remove = comedi_pci_auto_unconfig, | |
127 | }; | |
128 | module_comedi_pci_driver(labpc_pci_comedi_driver, labpc_pci_driver); | |
129 | ||
130 | MODULE_DESCRIPTION("Comedi: National Instruments Lab-PC PCI-1200 driver"); | |
3659743d | 131 | MODULE_AUTHOR("Comedi https://www.comedi.org"); |
fa3cb219 | 132 | MODULE_LICENSE("GPL"); |