Commit | Line | Data |
---|---|---|
58e732ee | 1 | /* |
06d4bd51 HS |
2 | * pcmad.c |
3 | * Hardware driver for Winsystems PCM-A/D12 and PCM-A/D16 | |
4 | * | |
5 | * COMEDI - Linux Control and Measurement Device Interface | |
6 | * Copyright (C) 2000,2001 David A. Schleef <ds@schleef.org> | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation; either version 2 of the License, or | |
11 | * (at your option) any later version. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | */ | |
58e732ee | 18 | |
58e732ee | 19 | /* |
06d4bd51 HS |
20 | * Driver: pcmad |
21 | * Description: Winsystems PCM-A/D12, PCM-A/D16 | |
f15ceb48 | 22 | * Devices: [Winsystems] PCM-A/D12 (pcmad12), PCM-A/D16 (pcmad16) |
06d4bd51 HS |
23 | * Author: ds |
24 | * Status: untested | |
25 | * | |
26 | * This driver was written on a bet that I couldn't write a driver | |
27 | * in less than 2 hours. I won the bet, but never got paid. =( | |
28 | * | |
29 | * Configuration options: | |
30 | * [0] - I/O port base | |
31 | * [1] - IRQ (unused) | |
6092e942 HS |
32 | * [2] - Analog input reference (must match jumpers) |
33 | * 0 = single-ended (16 channels) | |
34 | * 1 = differential (8 channels) | |
06d4bd51 | 35 | * [3] - Analog input encoding (must match jumpers) |
7ecc5370 HS |
36 | * 0 = straight binary (0-5V input range) |
37 | * 1 = two's complement (+-10V input range) | |
06d4bd51 | 38 | */ |
58e732ee | 39 | |
ce157f80 | 40 | #include <linux/module.h> |
58e732ee DS |
41 | #include "../comedidev.h" |
42 | ||
58e732ee DS |
43 | #define PCMAD_STATUS 0 |
44 | #define PCMAD_LSB 1 | |
45 | #define PCMAD_MSB 2 | |
46 | #define PCMAD_CONVERT 1 | |
47 | ||
48 | struct pcmad_board_struct { | |
49 | const char *name; | |
d69b55f3 | 50 | unsigned int ai_maxdata; |
58e732ee | 51 | }; |
58e732ee | 52 | |
2a09cba6 HS |
53 | static const struct pcmad_board_struct pcmad_boards[] = { |
54 | { | |
55 | .name = "pcmad12", | |
d69b55f3 | 56 | .ai_maxdata = 0x0fff, |
2a09cba6 HS |
57 | }, { |
58 | .name = "pcmad16", | |
d69b55f3 | 59 | .ai_maxdata = 0xffff, |
2a09cba6 HS |
60 | }, |
61 | }; | |
62 | ||
42946cfc HS |
63 | static int pcmad_ai_eoc(struct comedi_device *dev, |
64 | struct comedi_subdevice *s, | |
65 | struct comedi_insn *insn, | |
66 | unsigned long context) | |
bcc01b4d | 67 | { |
42946cfc | 68 | unsigned int status; |
bcc01b4d | 69 | |
42946cfc HS |
70 | status = inb(dev->iobase + PCMAD_STATUS); |
71 | if ((status & 0x3) == 0x3) | |
72 | return 0; | |
73 | return -EBUSY; | |
bcc01b4d HS |
74 | } |
75 | ||
0a85b6f0 MT |
76 | static int pcmad_ai_insn_read(struct comedi_device *dev, |
77 | struct comedi_subdevice *s, | |
3275b4d3 HS |
78 | struct comedi_insn *insn, |
79 | unsigned int *data) | |
58e732ee | 80 | { |
3275b4d3 | 81 | unsigned int chan = CR_CHAN(insn->chanspec); |
7ecc5370 | 82 | unsigned int range = CR_RANGE(insn->chanspec); |
3275b4d3 | 83 | unsigned int val; |
bcc01b4d | 84 | int ret; |
3275b4d3 | 85 | int i; |
58e732ee | 86 | |
3275b4d3 | 87 | for (i = 0; i < insn->n; i++) { |
58e732ee DS |
88 | outb(chan, dev->iobase + PCMAD_CONVERT); |
89 | ||
42946cfc | 90 | ret = comedi_timeout(dev, s, insn, pcmad_ai_eoc, 0); |
bcc01b4d HS |
91 | if (ret) |
92 | return ret; | |
93 | ||
3275b4d3 HS |
94 | val = inb(dev->iobase + PCMAD_LSB) | |
95 | (inb(dev->iobase + PCMAD_MSB) << 8); | |
58e732ee | 96 | |
3170b256 HS |
97 | /* data is shifted on the pcmad12, fix it */ |
98 | if (s->maxdata == 0x0fff) | |
99 | val >>= 4; | |
100 | ||
43db70a5 | 101 | if (comedi_range_is_bipolar(s, range)) { |
7ecc5370 | 102 | /* munge the two's complement value */ |
3275b4d3 | 103 | val ^= ((s->maxdata + 1) >> 1); |
7ecc5370 | 104 | } |
3275b4d3 HS |
105 | |
106 | data[i] = val; | |
58e732ee DS |
107 | } |
108 | ||
3275b4d3 | 109 | return insn->n; |
58e732ee DS |
110 | } |
111 | ||
da91b269 | 112 | static int pcmad_attach(struct comedi_device *dev, struct comedi_devconfig *it) |
58e732ee | 113 | { |
3230e42a | 114 | const struct pcmad_board_struct *board = dev->board_ptr; |
34c43922 | 115 | struct comedi_subdevice *s; |
3e9b1fca | 116 | int ret; |
58e732ee | 117 | |
624b6530 | 118 | ret = comedi_request_region(dev, it->options[0], 0x04); |
3e9b1fca HS |
119 | if (ret) |
120 | return ret; | |
58e732ee | 121 | |
2f0b9d08 | 122 | ret = comedi_alloc_subdevices(dev, 1); |
8b6c5694 | 123 | if (ret) |
58e732ee | 124 | return ret; |
c3744138 | 125 | |
86bb856a | 126 | s = &dev->subdevices[0]; |
624b6530 | 127 | s->type = COMEDI_SUBD_AI; |
6092e942 HS |
128 | if (it->options[1]) { |
129 | /* 8 differential channels */ | |
130 | s->subdev_flags = SDF_READABLE | AREF_DIFF; | |
131 | s->n_chan = 8; | |
132 | } else { | |
133 | /* 16 single-ended channels */ | |
134 | s->subdev_flags = SDF_READABLE | AREF_GROUND; | |
135 | s->n_chan = 16; | |
136 | } | |
624b6530 | 137 | s->len_chanlist = 1; |
d69b55f3 | 138 | s->maxdata = board->ai_maxdata; |
7ecc5370 | 139 | s->range_table = it->options[2] ? &range_bipolar10 : &range_unipolar5; |
624b6530 | 140 | s->insn_read = pcmad_ai_insn_read; |
58e732ee DS |
141 | |
142 | return 0; | |
143 | } | |
144 | ||
294f930d | 145 | static struct comedi_driver pcmad_driver = { |
3496cb9f HS |
146 | .driver_name = "pcmad", |
147 | .module = THIS_MODULE, | |
148 | .attach = pcmad_attach, | |
3d1fe3f7 | 149 | .detach = comedi_legacy_detach, |
3496cb9f HS |
150 | .board_name = &pcmad_boards[0].name, |
151 | .num_names = ARRAY_SIZE(pcmad_boards), | |
152 | .offset = sizeof(pcmad_boards[0]), | |
153 | }; | |
294f930d | 154 | module_comedi_driver(pcmad_driver); |
3496cb9f | 155 | |
90f703d3 AT |
156 | MODULE_AUTHOR("Comedi http://www.comedi.org"); |
157 | MODULE_DESCRIPTION("Comedi low-level driver"); | |
158 | MODULE_LICENSE("GPL"); |