| 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * comedi/drivers/ni_labpc.c |
| 4 | * Driver for National Instruments Lab-PC series boards and compatibles |
| 5 | * Copyright (C) 2001-2003 Frank Mori Hess <fmhess@users.sourceforge.net> |
| 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * Driver: ni_labpc |
| 10 | * Description: National Instruments Lab-PC (& compatibles) |
| 11 | * Devices: [National Instruments] Lab-PC-1200 (lab-pc-1200), |
| 12 | * Lab-PC-1200AI (lab-pc-1200ai), Lab-PC+ (lab-pc+) |
| 13 | * Author: Frank Mori Hess <fmhess@users.sourceforge.net> |
| 14 | * Status: works |
| 15 | * |
| 16 | * Configuration options - ISA boards: |
| 17 | * [0] - I/O port base address |
| 18 | * [1] - IRQ (optional, required for timed or externally triggered |
| 19 | * conversions) |
| 20 | * [2] - DMA channel (optional) |
| 21 | * |
| 22 | * Tested with lab-pc-1200. For the older Lab-PC+, not all input |
| 23 | * ranges and analog references will work, the available ranges/arefs |
| 24 | * will depend on how you have configured the jumpers on your board |
| 25 | * (see your owner's manual). |
| 26 | * |
| 27 | * Kernel-level ISA plug-and-play support for the lab-pc-1200 boards |
| 28 | * has not yet been added to the driver, mainly due to the fact that |
| 29 | * I don't know the device id numbers. If you have one of these boards, |
| 30 | * please file a bug report at https://comedi.org/ so I can get the |
| 31 | * necessary information from you. |
| 32 | * |
| 33 | * The 1200 series boards have onboard calibration dacs for correcting |
| 34 | * analog input/output offsets and gains. The proper settings for these |
| 35 | * caldacs are stored on the board's eeprom. To read the caldac values |
| 36 | * from the eeprom and store them into a file that can be then be used |
| 37 | * by comedilib, use the comedi_calibrate program. |
| 38 | * |
| 39 | * The Lab-pc+ has quirky chanlist requirements when scanning multiple |
| 40 | * channels. Multiple channel scan sequence must start at highest channel, |
| 41 | * then decrement down to channel 0. The rest of the cards can scan down |
| 42 | * like lab-pc+ or scan up from channel zero. Chanlists consisting of all |
| 43 | * one channel are also legal, and allow you to pace conversions in bursts. |
| 44 | * |
| 45 | * NI manuals: |
| 46 | * 341309a (labpc-1200 register manual) |
| 47 | * 320502b (lab-pc+) |
| 48 | */ |
| 49 | |
| 50 | #include <linux/module.h> |
| 51 | #include <linux/comedi/comedidev.h> |
| 52 | |
| 53 | #include "ni_labpc.h" |
| 54 | #include "ni_labpc_isadma.h" |
| 55 | |
| 56 | static const struct labpc_boardinfo labpc_boards[] = { |
| 57 | { |
| 58 | .name = "lab-pc-1200" , |
| 59 | .ai_speed = 10000, |
| 60 | .ai_scan_up = 1, |
| 61 | .has_ao = 1, |
| 62 | .is_labpc1200 = 1, |
| 63 | }, { |
| 64 | .name = "lab-pc-1200ai" , |
| 65 | .ai_speed = 10000, |
| 66 | .ai_scan_up = 1, |
| 67 | .is_labpc1200 = 1, |
| 68 | }, { |
| 69 | .name = "lab-pc+" , |
| 70 | .ai_speed = 12000, |
| 71 | .has_ao = 1, |
| 72 | }, |
| 73 | }; |
| 74 | |
| 75 | static int labpc_attach(struct comedi_device *dev, struct comedi_devconfig *it) |
| 76 | { |
| 77 | unsigned int irq = it->options[1]; |
| 78 | unsigned int dma_chan = it->options[2]; |
| 79 | int ret; |
| 80 | |
| 81 | ret = comedi_request_region(dev, start: it->options[0], len: 0x20); |
| 82 | if (ret) |
| 83 | return ret; |
| 84 | |
| 85 | ret = labpc_common_attach(dev, irq, isr_flags: 0); |
| 86 | if (ret) |
| 87 | return ret; |
| 88 | |
| 89 | if (dev->irq) |
| 90 | labpc_init_dma_chan(dev, dma_chan); |
| 91 | |
| 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | static void labpc_detach(struct comedi_device *dev) |
| 96 | { |
| 97 | labpc_free_dma_chan(dev); |
| 98 | labpc_common_detach(dev); |
| 99 | comedi_legacy_detach(dev); |
| 100 | } |
| 101 | |
| 102 | static struct comedi_driver labpc_driver = { |
| 103 | .driver_name = "ni_labpc" , |
| 104 | .module = THIS_MODULE, |
| 105 | .attach = labpc_attach, |
| 106 | .detach = labpc_detach, |
| 107 | .num_names = ARRAY_SIZE(labpc_boards), |
| 108 | .board_name = &labpc_boards[0].name, |
| 109 | .offset = sizeof(struct labpc_boardinfo), |
| 110 | }; |
| 111 | module_comedi_driver(labpc_driver); |
| 112 | |
| 113 | MODULE_AUTHOR("Comedi https://www.comedi.org" ); |
| 114 | MODULE_DESCRIPTION("Comedi driver for NI Lab-PC ISA boards" ); |
| 115 | MODULE_LICENSE("GPL" ); |
| 116 | |