]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - drivers/staging/comedi/drivers/adl_pci6208.c
staging/comedi: Use comedi_pci_auto_unconfig directly for pci_driver.remove
[mirror_ubuntu-hirsute-kernel.git] / drivers / staging / comedi / drivers / adl_pci6208.c
CommitLineData
8b93f903 1/*
2 comedi/drivers/adl_pci6208.c
3
4 Hardware driver for ADLink 6208 series cards:
5 card | voltage output | current output
6 -------------+-------------------+---------------
7 PCI-6208V | 8 channels | -
8 PCI-6216V | 16 channels | -
9 PCI-6208A | 8 channels | 8 channels
10
11 COMEDI - Linux Control and Measurement Device Interface
12 Copyright (C) 2000 David A. Schleef <ds@schleef.org>
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27*/
28/*
29Driver: adl_pci6208
0a1e6c1f
HS
30Description: ADLink PCI-6208/6216 Series Multi-channel Analog Output Cards
31Devices: (ADLink) PCI-6208 [adl_pci6208]
32 (ADLink) PCI-6216 [adl_pci6216]
8b93f903 33Author: nsyeow <nsyeow@pd.jaring.my>
34Updated: Fri, 30 Jan 2004 14:44:27 +0800
35Status: untested
36
744a8398 37Configuration Options: not applicable, uses PCI auto config
8b93f903 38
39References:
40 - ni_660x.c
41 - adl_pci9111.c copied the entire pci setup section
42 - adl_pci9118.c
43*/
a7c6de4c 44
8b93f903 45#include "../comedidev.h"
8b93f903 46
0a1e6c1f
HS
47/*
48 * ADLINK PCI Device ID's supported by this driver
49 */
50#define PCI_DEVICE_ID_PCI6208 0x6208
51#define PCI_DEVICE_ID_PCI6216 0x6216
52
7b6afad1
HS
53/*
54 * PCI-6208/6216-GL register map
55 */
56#define PCI6208_AO_CONTROL(x) (0x00 + (2 * (x)))
57#define PCI6208_AO_STATUS 0x00
58#define PCI6208_AO_STATUS_DATA_SEND (1 << 0)
59#define PCI6208_DIO 0x40
60#define PCI6208_DIO_DO_MASK (0x0f)
61#define PCI6208_DIO_DO_SHIFT (0)
62#define PCI6208_DIO_DI_MASK (0xf0)
63#define PCI6208_DIO_DI_SHIFT (4)
64
0a1e6c1f 65#define PCI6208_MAX_AO_CHANNELS 16
5c67df8b 66
c1b31c44 67struct pci6208_board {
8b93f903 68 const char *name;
a7c6de4c 69 unsigned short dev_id;
8b93f903 70 int ao_chans;
c1b31c44
BP
71};
72
73static const struct pci6208_board pci6208_boards[] = {
8b93f903 74 {
0a1e6c1f
HS
75 .name = "adl_pci6208",
76 .dev_id = PCI_DEVICE_ID_PCI6208,
dcff1681 77 .ao_chans = 8,
0a1e6c1f
HS
78 }, {
79 .name = "adl_pci6216",
80 .dev_id = PCI_DEVICE_ID_PCI6216,
81 .ao_chans = 16,
dcff1681 82 },
8b93f903 83};
84
3d393c86 85struct pci6208_private {
5c67df8b 86 unsigned int ao_readback[PCI6208_MAX_AO_CHANNELS];
3d393c86 87};
8b93f903 88
0a85b6f0
MT
89static int pci6208_ao_winsn(struct comedi_device *dev,
90 struct comedi_subdevice *s,
91 struct comedi_insn *insn, unsigned int *data)
8b93f903 92{
949a18d3 93 struct pci6208_private *devpriv = dev->private;
8366404b 94 int chan = CR_CHAN(insn->chanspec);
8b93f903 95 unsigned long invert = 1 << (16 - 1);
8366404b
HS
96 unsigned long value = 0;
97 unsigned short status;
98 int i;
a7c6de4c 99
8b93f903 100 for (i = 0; i < insn->n; i++) {
8366404b
HS
101 value = data[i] ^ invert;
102
8b93f903 103 do {
8366404b
HS
104 status = inw(dev->iobase + PCI6208_AO_STATUS);
105 } while (status & PCI6208_AO_STATUS_DATA_SEND);
106
107 outw(value, dev->iobase + PCI6208_AO_CONTROL(chan));
8b93f903 108 }
8366404b 109 devpriv->ao_readback[chan] = value;
8b93f903 110
8366404b 111 return insn->n;
8b93f903 112}
113
0a85b6f0
MT
114static int pci6208_ao_rinsn(struct comedi_device *dev,
115 struct comedi_subdevice *s,
116 struct comedi_insn *insn, unsigned int *data)
8b93f903 117{
949a18d3 118 struct pci6208_private *devpriv = dev->private;
8b93f903 119 int chan = CR_CHAN(insn->chanspec);
7c1e5bc7 120 int i;
8b93f903 121
122 for (i = 0; i < insn->n; i++)
123 data[i] = devpriv->ao_readback[chan];
124
7c1e5bc7 125 return insn->n;
8b93f903 126}
127
270809a8
HS
128static int pci6208_di_insn_bits(struct comedi_device *dev,
129 struct comedi_subdevice *s,
130 struct comedi_insn *insn,
131 unsigned int *data)
fc2536fd 132{
270809a8
HS
133 unsigned int val;
134
135 val = inw(dev->iobase + PCI6208_DIO);
136 val = (val & PCI6208_DIO_DI_MASK) >> PCI6208_DIO_DI_SHIFT;
137
138 data[1] = val;
139
140 return insn->n;
141}
142
143static int pci6208_do_insn_bits(struct comedi_device *dev,
144 struct comedi_subdevice *s,
145 struct comedi_insn *insn,
146 unsigned int *data)
147{
148 unsigned int mask = data[0];
fc2536fd
HS
149 unsigned int bits = data[1];
150
151 if (mask) {
152 s->state &= ~mask;
270809a8 153 s->state |= (bits & mask);
fc2536fd
HS
154
155 outw(s->state, dev->iobase + PCI6208_DIO);
156 }
157
fc2536fd
HS
158 data[1] = s->state;
159
160 return insn->n;
161}
162
744a8398
HS
163static const void *pci6208_find_boardinfo(struct comedi_device *dev,
164 struct pci_dev *pcidev)
8b93f903 165{
744a8398 166 const struct pci6208_board *boardinfo;
8b93f903 167 int i;
168
744a8398
HS
169 for (i = 0; i < ARRAY_SIZE(pci6208_boards); i++) {
170 boardinfo = &pci6208_boards[i];
171 if (boardinfo->dev_id == pcidev->device)
172 return boardinfo;
8b93f903 173 }
cde6f08a 174 return NULL;
8b93f903 175}
176
a690b7e5 177static int pci6208_auto_attach(struct comedi_device *dev,
750af5e5 178 unsigned long context_unused)
c8d87bcc 179{
750af5e5 180 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
744a8398 181 const struct pci6208_board *boardinfo;
949a18d3 182 struct pci6208_private *devpriv;
c8d87bcc 183 struct comedi_subdevice *s;
270809a8 184 unsigned int val;
9d639b6b 185 int ret;
c8d87bcc 186
744a8398
HS
187 boardinfo = pci6208_find_boardinfo(dev, pcidev);
188 if (!boardinfo)
189 return -ENODEV;
190 dev->board_ptr = boardinfo;
191 dev->board_name = boardinfo->name;
192
c34fa261
HS
193 devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
194 if (!devpriv)
195 return -ENOMEM;
196 dev->private = devpriv;
c8d87bcc 197
3cf05ddb
HS
198 ret = comedi_pci_enable(pcidev, dev->board_name);
199 if (ret)
9d639b6b 200 return ret;
f8ec6392 201 dev->iobase = pci_resource_start(pcidev, 2);
c8d87bcc 202
270809a8 203 ret = comedi_alloc_subdevices(dev, 3);
9d639b6b
HS
204 if (ret)
205 return ret;
c8d87bcc 206
1f6115a4 207 s = &dev->subdevices[0];
c8d87bcc 208 /* analog output subdevice */
111b62e4
HS
209 s->type = COMEDI_SUBD_AO;
210 s->subdev_flags = SDF_WRITABLE;
744a8398 211 s->n_chan = boardinfo->ao_chans;
111b62e4
HS
212 s->maxdata = 0xffff;
213 s->range_table = &range_bipolar10;
214 s->insn_write = pci6208_ao_winsn;
215 s->insn_read = pci6208_ao_rinsn;
c8d87bcc 216
1f6115a4 217 s = &dev->subdevices[1];
270809a8
HS
218 /* digital input subdevice */
219 s->type = COMEDI_SUBD_DI;
220 s->subdev_flags = SDF_READABLE;
221 s->n_chan = 4;
111b62e4
HS
222 s->maxdata = 1;
223 s->range_table = &range_digital;
270809a8 224 s->insn_bits = pci6208_di_insn_bits;
111b62e4 225
1f6115a4 226 s = &dev->subdevices[2];
270809a8
HS
227 /* digital output subdevice */
228 s->type = COMEDI_SUBD_DO;
229 s->subdev_flags = SDF_WRITABLE;
230 s->n_chan = 4;
231 s->maxdata = 1;
232 s->range_table = &range_digital;
233 s->insn_bits = pci6208_do_insn_bits;
234
235 /*
236 * Get the read back signals from the digital outputs
237 * and save it as the initial state for the subdevice.
238 */
239 val = inw(dev->iobase + PCI6208_DIO);
240 val = (val & PCI6208_DIO_DO_MASK) >> PCI6208_DIO_DO_SHIFT;
241 s->state = val;
111b62e4 242 s->io_bits = 0x0f;
c8d87bcc 243
b4dda059
HS
244 dev_info(dev->class_dev, "%s: %s, I/O base=0x%04lx\n",
245 dev->driver->driver_name, dev->board_name, dev->iobase);
c8d87bcc 246
98bcf911 247 return 0;
c8d87bcc
HS
248}
249
484ecc95 250static void pci6208_detach(struct comedi_device *dev)
c8d87bcc 251{
f8ec6392 252 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
949a18d3 253
f8ec6392 254 if (pcidev) {
c8d87bcc 255 if (dev->iobase)
f8ec6392 256 comedi_pci_disable(pcidev);
c8d87bcc 257 }
c8d87bcc
HS
258}
259
75e6301b
HS
260static struct comedi_driver adl_pci6208_driver = {
261 .driver_name = "adl_pci6208",
c8d87bcc 262 .module = THIS_MODULE,
750af5e5 263 .auto_attach = pci6208_auto_attach,
c8d87bcc
HS
264 .detach = pci6208_detach,
265};
266
a690b7e5 267static int adl_pci6208_pci_probe(struct pci_dev *dev,
75e6301b 268 const struct pci_device_id *ent)
c8d87bcc 269{
75e6301b 270 return comedi_pci_auto_config(dev, &adl_pci6208_driver);
c8d87bcc
HS
271}
272
75e6301b 273static DEFINE_PCI_DEVICE_TABLE(adl_pci6208_pci_table) = {
0a1e6c1f
HS
274 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI6208) },
275 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI6216) },
c8d87bcc
HS
276 { 0 }
277};
75e6301b 278MODULE_DEVICE_TABLE(pci, adl_pci6208_pci_table);
c8d87bcc 279
75e6301b
HS
280static struct pci_driver adl_pci6208_pci_driver = {
281 .name = "adl_pci6208",
282 .id_table = adl_pci6208_pci_table,
283 .probe = adl_pci6208_pci_probe,
9901a4d7 284 .remove = comedi_pci_auto_unconfig,
c8d87bcc 285};
75e6301b 286module_comedi_pci_driver(adl_pci6208_driver, adl_pci6208_pci_driver);
c8d87bcc 287
90f703d3
AT
288MODULE_AUTHOR("Comedi http://www.comedi.org");
289MODULE_DESCRIPTION("Comedi low-level driver");
290MODULE_LICENSE("GPL");