staging: comedi: comedi_test: rename waveform members
[deliverable/linux.git] / drivers / staging / comedi / drivers / 8255_pci.c
CommitLineData
bb71f8b3 1/*
f7c22868
HS
2 * COMEDI driver for generic PCI based 8255 digital i/o boards
3 * Copyright (C) 2012 H Hartley Sweeten <hsweeten@visionengravers.com>
4 *
5 * Based on the tested adl_pci7296 driver written by:
6 * Jon Grierson <jd@renko.co.uk>
df1a3f87
HS
7 * and the experimental cb_pcidio driver written by:
8 * Yoshiya Matsuzaka
32bb1544
HS
9 *
10 * COMEDI - Linux Control and Measurement Device Interface
11 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
32bb1544 22 */
bb71f8b3 23
bb71f8b3 24/*
1308a487
IA
25 * Driver: 8255_pci
26 * Description: Generic PCI based 8255 Digital I/O boards
27 * Devices: [ADLink] PCI-7224 (adl_pci-7224), PCI-7248 (adl_pci-7248),
28 * PCI-7296 (adl_pci-7296),
29 * [Measurement Computing] PCI-DIO24 (cb_pci-dio24),
30 * PCI-DIO24H (cb_pci-dio24h), PCI-DIO48H (cb_pci-dio48h),
31 * PCI-DIO96H (cb_pci-dio96h),
32 * [National Instruments] PCI-DIO-96 (ni_pci-dio-96),
33 * PCI-DIO-96B (ni_pci-dio-96b), PXI-6508 (ni_pxi-6508),
34 * PCI-6503 (ni_pci-6503), PCI-6503B (ni_pci-6503b),
35 * PCI-6503X (ni_pci-6503x), PXI-6503 (ni_pxi-6503)
36 * Author: H Hartley Sweeten <hsweeten@visionengravers.com>
37 * Updated: Wed, 12 Sep 2012 11:52:01 -0700
38 * Status: untested
39 *
40 * These boards have one or more 8255 digital I/O chips, each of which
41 * is supported as a separate 24-channel DIO subdevice.
42 *
43 * Boards with 24 DIO channels (1 DIO subdevice):
44 *
45 * PCI-7224, PCI-DIO24, PCI-DIO24H, PCI-6503, PCI-6503B, PCI-6503X,
46 * PXI-6503
47 *
48 * Boards with 48 DIO channels (2 DIO subdevices):
49 *
50 * PCI-7248, PCI-DIO48H
51 *
52 * Boards with 96 DIO channels (4 DIO subdevices):
53 *
54 * PCI-7296, PCI-DIO96H, PCI-DIO-96, PCI-DIO-96B, PXI-6508
55 *
56 * Some of these boards also have an 8254 programmable timer/counter
57 * chip. This chip is not currently supported by this driver.
58 *
59 * Interrupt support for these boards is also not currently supported.
60 *
61 * Configuration Options: not applicable, uses PCI auto config.
62 */
bb71f8b3 63
ce157f80 64#include <linux/module.h>
33782dd5 65
7215a284 66#include "../comedi_pci.h"
bb71f8b3 67
bb71f8b3 68#include "8255.h"
bb71f8b3 69
af48bd8c
HS
70enum pci_8255_boardid {
71 BOARD_ADLINK_PCI7224,
72 BOARD_ADLINK_PCI7248,
73 BOARD_ADLINK_PCI7296,
74 BOARD_CB_PCIDIO24,
75 BOARD_CB_PCIDIO24H,
0283f7a1
IA
76 BOARD_CB_PCIDIO48H_OLD,
77 BOARD_CB_PCIDIO48H_NEW,
af48bd8c
HS
78 BOARD_CB_PCIDIO96H,
79 BOARD_NI_PCIDIO96,
80 BOARD_NI_PCIDIO96B,
81 BOARD_NI_PXI6508,
82 BOARD_NI_PCI6503,
83 BOARD_NI_PCI6503B,
84 BOARD_NI_PCI6503X,
85 BOARD_NI_PXI_6503,
86};
b37c1aee 87
f7c22868 88struct pci_8255_boardinfo {
32bb1544 89 const char *name;
df1a3f87 90 int dio_badr;
f7c22868 91 int n_8255;
268d1e79 92 unsigned int has_mite:1;
32bb1544 93};
bb71f8b3 94
f7c22868 95static const struct pci_8255_boardinfo pci_8255_boards[] = {
af48bd8c 96 [BOARD_ADLINK_PCI7224] = {
f7c22868 97 .name = "adl_pci-7224",
df1a3f87 98 .dio_badr = 2,
f7c22868 99 .n_8255 = 1,
af48bd8c
HS
100 },
101 [BOARD_ADLINK_PCI7248] = {
f7c22868 102 .name = "adl_pci-7248",
df1a3f87 103 .dio_badr = 2,
f7c22868 104 .n_8255 = 2,
af48bd8c
HS
105 },
106 [BOARD_ADLINK_PCI7296] = {
f7c22868 107 .name = "adl_pci-7296",
df1a3f87 108 .dio_badr = 2,
f7c22868 109 .n_8255 = 4,
af48bd8c
HS
110 },
111 [BOARD_CB_PCIDIO24] = {
df1a3f87 112 .name = "cb_pci-dio24",
df1a3f87
HS
113 .dio_badr = 2,
114 .n_8255 = 1,
af48bd8c
HS
115 },
116 [BOARD_CB_PCIDIO24H] = {
df1a3f87 117 .name = "cb_pci-dio24h",
df1a3f87
HS
118 .dio_badr = 2,
119 .n_8255 = 1,
af48bd8c 120 },
0283f7a1 121 [BOARD_CB_PCIDIO48H_OLD] = {
df1a3f87 122 .name = "cb_pci-dio48h",
df1a3f87
HS
123 .dio_badr = 1,
124 .n_8255 = 2,
af48bd8c 125 },
0283f7a1
IA
126 [BOARD_CB_PCIDIO48H_NEW] = {
127 .name = "cb_pci-dio48h",
128 .dio_badr = 2,
129 .n_8255 = 2,
130 },
af48bd8c 131 [BOARD_CB_PCIDIO96H] = {
606b0470 132 .name = "cb_pci-dio96h",
606b0470
HS
133 .dio_badr = 2,
134 .n_8255 = 4,
af48bd8c
HS
135 },
136 [BOARD_NI_PCIDIO96] = {
b37c1aee 137 .name = "ni_pci-dio-96",
b37c1aee 138 .dio_badr = 1,
b37c1aee 139 .n_8255 = 4,
268d1e79 140 .has_mite = 1,
af48bd8c
HS
141 },
142 [BOARD_NI_PCIDIO96B] = {
b37c1aee 143 .name = "ni_pci-dio-96b",
b37c1aee 144 .dio_badr = 1,
b37c1aee 145 .n_8255 = 4,
268d1e79 146 .has_mite = 1,
af48bd8c
HS
147 },
148 [BOARD_NI_PXI6508] = {
b37c1aee 149 .name = "ni_pxi-6508",
b37c1aee 150 .dio_badr = 1,
b37c1aee 151 .n_8255 = 4,
268d1e79 152 .has_mite = 1,
af48bd8c
HS
153 },
154 [BOARD_NI_PCI6503] = {
b37c1aee 155 .name = "ni_pci-6503",
b37c1aee 156 .dio_badr = 1,
b37c1aee 157 .n_8255 = 1,
268d1e79 158 .has_mite = 1,
af48bd8c
HS
159 },
160 [BOARD_NI_PCI6503B] = {
b37c1aee 161 .name = "ni_pci-6503b",
b37c1aee 162 .dio_badr = 1,
b37c1aee 163 .n_8255 = 1,
268d1e79 164 .has_mite = 1,
af48bd8c
HS
165 },
166 [BOARD_NI_PCI6503X] = {
b37c1aee 167 .name = "ni_pci-6503x",
b37c1aee 168 .dio_badr = 1,
b37c1aee 169 .n_8255 = 1,
268d1e79 170 .has_mite = 1,
af48bd8c
HS
171 },
172 [BOARD_NI_PXI_6503] = {
b37c1aee 173 .name = "ni_pxi-6503",
b37c1aee 174 .dio_badr = 1,
b37c1aee 175 .n_8255 = 1,
268d1e79 176 .has_mite = 1,
32bb1544
HS
177 },
178};
bb71f8b3 179
9949595c 180/* ripped from mite.h and mite_setup2() to avoid mite dependency */
1da66175
HS
181#define MITE_IODWBSR 0xc0 /* IO Device Window Base Size Register */
182#define WENAB BIT(7) /* window enable */
e2f1036a 183
268d1e79
IA
184static int pci_8255_mite_init(struct pci_dev *pcidev)
185{
186 void __iomem *mite_base;
187 u32 main_phys_addr;
188
189 /* ioremap the MITE registers (BAR 0) temporarily */
190 mite_base = pci_ioremap_bar(pcidev, 0);
191 if (!mite_base)
192 return -ENOMEM;
193
194 /* set data window to main registers (BAR 1) */
195 main_phys_addr = pci_resource_start(pcidev, 1);
196 writel(main_phys_addr | WENAB, mite_base + MITE_IODWBSR);
197
198 /* finished with MITE registers */
199 iounmap(mite_base);
200 return 0;
201}
202
a690b7e5 203static int pci_8255_auto_attach(struct comedi_device *dev,
af48bd8c 204 unsigned long context)
bb71f8b3 205{
750af5e5 206 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
af48bd8c 207 const struct pci_8255_boardinfo *board = NULL;
34c43922 208 struct comedi_subdevice *s;
bb71f8b3 209 int ret;
32bb1544 210 int i;
bb71f8b3 211
af48bd8c
HS
212 if (context < ARRAY_SIZE(pci_8255_boards))
213 board = &pci_8255_boards[context];
32bb1544
HS
214 if (!board)
215 return -ENODEV;
216 dev->board_ptr = board;
217 dev->board_name = board->name;
bb71f8b3 218
818f569f 219 ret = comedi_pci_enable(dev);
8b6c5694
HS
220 if (ret)
221 return ret;
77f17d37 222
268d1e79
IA
223 if (board->has_mite) {
224 ret = pci_8255_mite_init(pcidev);
225 if (ret)
226 return ret;
227 }
228
5c19084b 229 if ((pci_resource_flags(pcidev, board->dio_badr) & IORESOURCE_MEM)) {
78b46938
HS
230 dev->mmio = pci_ioremap_bar(pcidev, board->dio_badr);
231 if (!dev->mmio)
77f17d37 232 return -ENOMEM;
43535526
HS
233 } else {
234 dev->iobase = pci_resource_start(pcidev, board->dio_badr);
77f17d37 235 }
262ea0d4 236
32bb1544
HS
237 /*
238 * One, two, or four subdevices are setup by this driver depending
239 * on the number of channels provided by the board. Each subdevice
240 * has 24 channels supported by the 8255 module.
241 */
f7c22868 242 ret = comedi_alloc_subdevices(dev, board->n_8255);
32bb1544 243 if (ret)
262ea0d4
HS
244 return ret;
245
f7c22868 246 for (i = 0; i < board->n_8255; i++) {
630b713b 247 s = &dev->subdevices[i];
5c19084b 248 if (dev->mmio)
f0162091 249 ret = subdev_8255_mm_init(dev, s, NULL, i * I8255_SIZE);
4085e93b 250 else
f0162091 251 ret = subdev_8255_init(dev, s, NULL, i * I8255_SIZE);
32bb1544
HS
252 if (ret)
253 return ret;
254 }
262ea0d4 255
262ea0d4 256 return 0;
bb71f8b3
JG
257}
258
f7c22868
HS
259static struct comedi_driver pci_8255_driver = {
260 .driver_name = "8255_pci",
db0eaeed 261 .module = THIS_MODULE,
750af5e5 262 .auto_attach = pci_8255_auto_attach,
aac307f9 263 .detach = comedi_pci_detach,
db0eaeed
HS
264};
265
a690b7e5 266static int pci_8255_pci_probe(struct pci_dev *dev,
b8f4ac23 267 const struct pci_device_id *id)
727b286b 268{
b8f4ac23 269 return comedi_pci_auto_config(dev, &pci_8255_driver, id->driver_data);
727b286b
AT
270}
271
41e043fc 272static const struct pci_device_id pci_8255_pci_table[] = {
af48bd8c
HS
273 { PCI_VDEVICE(ADLINK, 0x7224), BOARD_ADLINK_PCI7224 },
274 { PCI_VDEVICE(ADLINK, 0x7248), BOARD_ADLINK_PCI7248 },
275 { PCI_VDEVICE(ADLINK, 0x7296), BOARD_ADLINK_PCI7296 },
276 { PCI_VDEVICE(CB, 0x0028), BOARD_CB_PCIDIO24 },
277 { PCI_VDEVICE(CB, 0x0014), BOARD_CB_PCIDIO24H },
0283f7a1
IA
278 { PCI_DEVICE_SUB(PCI_VENDOR_ID_CB, 0x000b, 0x0000, 0x0000),
279 .driver_data = BOARD_CB_PCIDIO48H_OLD },
280 { PCI_DEVICE_SUB(PCI_VENDOR_ID_CB, 0x000b, PCI_VENDOR_ID_CB, 0x000b),
281 .driver_data = BOARD_CB_PCIDIO48H_NEW },
af48bd8c
HS
282 { PCI_VDEVICE(CB, 0x0017), BOARD_CB_PCIDIO96H },
283 { PCI_VDEVICE(NI, 0x0160), BOARD_NI_PCIDIO96 },
284 { PCI_VDEVICE(NI, 0x1630), BOARD_NI_PCIDIO96B },
285 { PCI_VDEVICE(NI, 0x13c0), BOARD_NI_PXI6508 },
286 { PCI_VDEVICE(NI, 0x0400), BOARD_NI_PCI6503 },
287 { PCI_VDEVICE(NI, 0x1250), BOARD_NI_PCI6503B },
288 { PCI_VDEVICE(NI, 0x17d0), BOARD_NI_PCI6503X },
289 { PCI_VDEVICE(NI, 0x1800), BOARD_NI_PXI_6503 },
75e6301b 290 { 0 }
db0eaeed 291};
f7c22868 292MODULE_DEVICE_TABLE(pci, pci_8255_pci_table);
db0eaeed 293
f7c22868
HS
294static struct pci_driver pci_8255_pci_driver = {
295 .name = "8255_pci",
296 .id_table = pci_8255_pci_table,
297 .probe = pci_8255_pci_probe,
9901a4d7 298 .remove = comedi_pci_auto_unconfig,
727b286b 299};
f7c22868 300module_comedi_pci_driver(pci_8255_driver, pci_8255_pci_driver);
90f703d3 301
f7c22868 302MODULE_DESCRIPTION("COMEDI - Generic PCI based 8255 Digital I/O boards");
90f703d3 303MODULE_AUTHOR("Comedi http://www.comedi.org");
90f703d3 304MODULE_LICENSE("GPL");
This page took 0.827885 seconds and 5 git commands to generate.