107 #include <linux/slab.h>
109 #include "../comedidev.h"
114 #define DRIVER_NAME "amplc_pci224"
119 #define PCI_VENDOR_ID_AMPLICON 0x14dc
120 #define PCI_DEVICE_ID_AMPLICON_PCI224 0x0007
121 #define PCI_DEVICE_ID_AMPLICON_PCI234 0x0008
122 #define PCI_DEVICE_ID_INVALID 0xffff
127 #define PCI224_IO1_SIZE 0x20
128 #define PCI224_Z2_CT0 0x14
129 #define PCI224_Z2_CT1 0x15
130 #define PCI224_Z2_CT2 0x16
131 #define PCI224_Z2_CTC 0x17
132 #define PCI224_ZCLK_SCE 0x1A
133 #define PCI224_ZGAT_SCE 0x1D
134 #define PCI224_INT_SCE 0x1E
140 #define PCI224_IO2_SIZE 0x10
141 #define PCI224_DACDATA 0x00
142 #define PCI224_SOFTTRIG 0x00
143 #define PCI224_DACCON 0x02
144 #define PCI224_FIFOSIZ 0x04
145 #define PCI224_DACCEN 0x06
151 #define PCI224_DACCON_TRIG_MASK (7 << 0)
152 #define PCI224_DACCON_TRIG_NONE (0 << 0)
153 #define PCI224_DACCON_TRIG_SW (1 << 0)
154 #define PCI224_DACCON_TRIG_EXTP (2 << 0)
155 #define PCI224_DACCON_TRIG_EXTN (3 << 0)
156 #define PCI224_DACCON_TRIG_Z2CT0 (4 << 0)
157 #define PCI224_DACCON_TRIG_Z2CT1 (5 << 0)
158 #define PCI224_DACCON_TRIG_Z2CT2 (6 << 0)
160 #define PCI224_DACCON_POLAR_MASK (1 << 3)
161 #define PCI224_DACCON_POLAR_UNI (0 << 3)
162 #define PCI224_DACCON_POLAR_BI (1 << 3)
164 #define PCI224_DACCON_VREF_MASK (3 << 4)
165 #define PCI224_DACCON_VREF_1_25 (0 << 4)
166 #define PCI224_DACCON_VREF_2_5 (1 << 4)
167 #define PCI224_DACCON_VREF_5 (2 << 4)
168 #define PCI224_DACCON_VREF_10 (3 << 4)
170 #define PCI224_DACCON_FIFOWRAP (1 << 7)
172 #define PCI224_DACCON_FIFOENAB (1 << 8)
174 #define PCI224_DACCON_FIFOINTR_MASK (7 << 9)
175 #define PCI224_DACCON_FIFOINTR_EMPTY (0 << 9)
176 #define PCI224_DACCON_FIFOINTR_NEMPTY (1 << 9)
177 #define PCI224_DACCON_FIFOINTR_NHALF (2 << 9)
178 #define PCI224_DACCON_FIFOINTR_HALF (3 << 9)
179 #define PCI224_DACCON_FIFOINTR_NFULL (4 << 9)
180 #define PCI224_DACCON_FIFOINTR_FULL (5 << 9)
182 #define PCI224_DACCON_FIFOFL_MASK (7 << 12)
183 #define PCI224_DACCON_FIFOFL_EMPTY (1 << 12)
184 #define PCI224_DACCON_FIFOFL_ONETOHALF (0 << 12)
185 #define PCI224_DACCON_FIFOFL_HALFTOFULL (4 << 12)
186 #define PCI224_DACCON_FIFOFL_FULL (6 << 12)
188 #define PCI224_DACCON_BUSY (1 << 15)
190 #define PCI224_DACCON_FIFORESET (1 << 12)
192 #define PCI224_DACCON_GLOBALRESET (1 << 13)
197 #define PCI224_FIFO_SIZE 4096
204 #define PCI224_FIFO_ROOM_EMPTY PCI224_FIFO_SIZE
205 #define PCI224_FIFO_ROOM_ONETOHALF (PCI224_FIFO_SIZE / 2)
206 #define PCI224_FIFO_ROOM_HALFTOFULL 1
207 #define PCI224_FIFO_ROOM_FULL 0
221 #define CLK_CONFIG(chan, src) ((((chan) & 3) << 3) | ((src) & 7))
223 #define TIMEBASE_10MHZ 100
224 #define TIMEBASE_1MHZ 1000
225 #define TIMEBASE_100KHZ 10000
226 #define TIMEBASE_10KHZ 100000
227 #define TIMEBASE_1KHZ 1000000
235 #define GAT_NOUTNM2 3
237 #define GAT_CONFIG(chan, src) ((((chan) & 3) << 3) | ((src) & 7))
254 #define PCI224_INTR_EXT 0x01
255 #define PCI224_INTR_DAC 0x04
256 #define PCI224_INTR_Z2CT1 0x20
258 #define PCI224_INTR_EDGE_BITS (PCI224_INTR_EXT | PCI224_INTR_Z2CT1)
259 #define PCI224_INTR_LEVEL_BITS PCI224_INTR_DACFIFO
266 #define COMBINE(old, new, mask) (((old) & ~(mask)) | ((new) & (mask)))
269 #define THISCPU smp_processor_id()
272 #define AO_CMD_STARTED 0
293 static const unsigned short hwrange_pci224_internal[8] = {
313 static const unsigned short hwrange_pci224_external[2] = {
337 static const unsigned short hwrange_pci234[1] = {
408 unsigned short mangled;
425 mangled = (
unsigned short)data << (16 - thisboard->
ao_bits);
452 for (i = 0; i < insn->
n; i++)
453 pci224_ao_set_data(dev, chan, range, data[i]);
476 for (i = 0; i < insn->
n; i++)
487 pci224_cascade_ns_to_timer(
int osc_base,
unsigned int *
d1,
unsigned int *
d2,
488 unsigned int *nanosec,
int round_mode)
522 spin_unlock_irqrestore(&devpriv->
ao_spinlock, flags);
525 spin_unlock_irqrestore(&devpriv->
ao_spinlock, flags);
550 pci224_ao_stop(dev, s);
562 spin_unlock_irqrestore(&devpriv->
ao_spinlock, flags);
574 unsigned int num_scans;
576 unsigned short dacstat;
578 unsigned int bytes_per_scan;
584 bytes_per_scan =
sizeof(
short);
602 pci224_ao_stop(dev, s);
620 if (num_scans == 0) {
622 pci224_ao_stop(dev, s);
632 if (num_scans > room)
636 for (n = 0; n < num_scans; n++) {
687 if (s->
async->events)
697 unsigned int trignum)
703 pci224_ao_start(dev, s);
708 #define MAX_SCAN_PERIOD 0xFFFFFFFFU
709 #define MIN_SCAN_PERIOD 2500
710 #define CONVERT_PERIOD 625
730 err |= cfc_check_trigger_src(&cmd->
stop_src,
738 err |= cfc_check_trigger_is_unique(cmd->
start_src);
740 err |= cfc_check_trigger_is_unique(cmd->
stop_src);
863 unsigned int div1,
div2, round;
868 switch (round_mode) {
884 if (div2 <= 0x10000) {
916 enum { range_err = 1, dupchan_err = 2, };
932 if (tmp & (1
U << ch))
933 errors |= dupchan_err;
941 if (errors & dupchan_err) {
944 "entries in chanlist must contain no "
945 "duplicate channels\n", dev->
minor);
947 if (errors & range_err) {
950 "entries in chanlist must all have "
951 "the same range index\n", dev->
minor);
1022 unsigned int div1,
div2, round;
1027 switch (round_mode) {
1043 if (div2 <= 0x10000) {
1109 s->
async->inttrig = &pci224_ao_inttrig_start;
1110 spin_unlock_irqrestore(&devpriv->
ao_spinlock, flags);
1117 spin_unlock_irqrestore(&devpriv->
ao_spinlock, flags);
1130 pci224_ao_stop(dev, s);
1139 void *data,
unsigned int num_bytes,
unsigned int chan_index)
1144 short *array =
data;
1145 unsigned int length = num_bytes /
sizeof(*array);
1151 shift = 16 - thisboard->
ao_bits;
1162 for (i = 0; i <
length; i++)
1163 array[i] = (array[i] << shift) -
offset;
1176 unsigned char intstat, valid_intstat;
1177 unsigned char curenab;
1179 unsigned long flags;
1185 valid_intstat = devpriv->
intsce & intstat;
1187 curenab = devpriv->
intsce & ~intstat;
1191 spin_unlock_irqrestore(&devpriv->
ao_spinlock, flags);
1192 if (valid_intstat != 0) {
1193 cmd = &s->
async->cmd;
1195 devpriv->
intsce &= ~PCI224_INTR_EXT;
1197 pci224_ao_start(dev, s);
1199 pci224_ao_stop(dev, s);
1203 pci224_ao_handle_fifo(dev, s);
1208 if (curenab != devpriv->
intsce) {
1213 spin_unlock_irqrestore(&devpriv->
ao_spinlock, flags);
1226 for (i = 0; i <
ARRAY_SIZE(pci224_boards); i++)
1228 return &pci224_boards[
i];
1236 static struct pci_dev *pci224_find_pci_dev(
struct comedi_device *dev,
1239 const struct pci224_board *thisboard = comedi_board(dev);
1240 struct pci_dev *pci_dev =
NULL;
1246 if (bus != pci_dev->
bus->number ||
1257 board_ptr = pci224_find_pci_board(pci_dev);
1258 if (board_ptr ==
NULL)
1270 "No supported board found! (req. bus %d, slot %d)\n",
1275 static void pci224_report_attach(
struct comedi_device *dev,
unsigned int irq)
1277 struct pci_dev *
pcidev = comedi_to_pci_dev(dev);
1281 snprintf(tmpbuf,
sizeof(tmpbuf),
"irq %u%s", irq,
1282 (dev->
irq ?
"" :
" UNAVAILABLE"));
1284 snprintf(tmpbuf,
sizeof(tmpbuf),
"no irq");
1293 struct pci_dev *pci_dev,
int *
options)
1295 const struct pci224_board *thisboard = comedi_board(dev);
1302 comedi_set_hw_dev(dev, &pci_dev->
dev);
1307 "error! cannot enable PCI device and request regions!\n"
1367 s->
do_cmd = &pci224_ao_cmd;
1369 s->
cancel = &pci224_ao_cancel;
1370 s->
munge = &pci224_ao_munge;
1384 for (n = 2; n < 3 + s->
n_chan; n++) {
1385 if (options[n] < 0 || options[n] > 1) {
1387 ": warning! bad options[%u]=%d\n",
1392 for (n = 0; n < s->
n_chan; n++) {
1394 options[3 + n] == 1) {
1395 if (options[2] == 1)
1396 range_table_list[
n] = &range_pci234_ext;
1401 if (options && options[2] == 1) {
1402 range_table_list[
n] =
1409 devpriv->
hwrange = hwrange_pci234;
1412 if (options && options[2] == 1) {
1414 devpriv->
hwrange = hwrange_pci224_external;
1416 if (options && options[2] != 0) {
1418 ": warning! bad options[2]=%d\n",
1422 devpriv->
hwrange = hwrange_pci224_internal;
1433 "error! unable to allocate irq %u\n", irq);
1440 pci224_report_attach(dev, irq);
1457 pci_dev = pci224_find_pci_dev(dev, it);
1461 return pci224_attach_common(dev, pci_dev, it->
options);
1465 pci224_attach_pci(
struct comedi_device *dev,
struct pci_dev *pci_dev)
1478 dev->
board_ptr = pci224_find_pci_board(pci_dev);
1481 DRIVER_NAME ": BUG! cannot determine board type!\n");
1491 return pci224_attach_common(dev, pci_dev,
NULL);
1497 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
1521 .driver_name =
"amplc_pci224",
1523 .attach = pci224_attach,
1524 .detach = pci224_detach,
1525 .attach_pci = pci224_attach_pci,
1526 .board_name = &pci224_boards[0].
name,
1531 static int __devinit amplc_pci224_pci_probe(
struct pci_dev *dev,
1538 static void __devexit amplc_pci224_pci_remove(
struct pci_dev *dev)
1550 static struct pci_driver amplc_pci224_pci_driver = {
1551 .name =
"amplc_pci224",
1552 .id_table = amplc_pci224_pci_table,
1553 .probe = amplc_pci224_pci_probe,