1 // SPDX-License-Identifier: GPL-2.0+
3 * comedi/drivers/8255.c
6 * COMEDI - Linux Control and Measurement Device Interface
7 * Copyright (C) 1998 David A. Schleef <ds@schleef.org>
12 * Description: generic 8255 support
13 * Devices: [standard] 8255 (8255)
16 * Updated: Fri, 7 Jun 2002 12:56:45 -0700
18 * The classic in digital I/O. The 8255 appears in Comedi as a single
19 * digital I/O subdevice with 24 channels. The channel 0 corresponds
20 * to the 8255's port A, bit 0; channel 23 corresponds to port C, bit
21 * 7. Direction configuration is done in blocks, with channels 0-7,
22 * 8-15, 16-19, and 20-23 making up the 4 blocks. The only 8255 mode
23 * supported is mode 0.
25 * You should enable compilation this driver if you plan to use a board
26 * that has an 8255 chip. For multifunction boards, the main driver will
27 * configure the 8255 subdevice automatically.
29 * This driver also works independently with ISA and PCI cards that
30 * directly map the 8255 registers to I/O ports, including cards with
31 * multiple 8255 chips. To configure the driver for such a card, the
32 * option list should be a list of the I/O port bases for each of the
33 * 8255 chips. For example,
35 * comedi_config /dev/comedi0 8255 0x200,0x204,0x208,0x20c
37 * Note that most PCI 8255 boards do NOT work with this driver, and
38 * need a separate driver as a wrapper. For those that do work, the
39 * I/O port base address can be found in the output of 'lspci -v'.
42 #include <linux/module.h>
43 #include <linux/comedi/comedidev.h>
44 #include <linux/comedi/comedi_8255.h>
46 static int dev_8255_attach(struct comedi_device *dev,
47 struct comedi_devconfig *it)
49 struct comedi_subdevice *s;
54 for (i = 0; i < COMEDI_NDEVCONFOPTS; i++) {
55 iobase = it->options[i];
60 dev_warn(dev->class_dev, "no devices specified\n");
64 ret = comedi_alloc_subdevices(dev, i);
68 for (i = 0; i < dev->n_subdevices; i++) {
69 s = &dev->subdevices[i];
70 iobase = it->options[i];
73 * __comedi_request_region() does not set dev->iobase.
75 * For 8255 devices that are manually attached using
76 * comedi_config, the 'iobase' is the actual I/O port
77 * base address of the chip.
79 ret = __comedi_request_region(dev, iobase, I8255_SIZE);
81 s->type = COMEDI_SUBD_UNUSED;
83 ret = subdev_8255_io_init(dev, s, iobase);
86 * Release the I/O port region here, as the
87 * "detach" handler cannot find it.
89 release_region(iobase, I8255_SIZE);
90 s->type = COMEDI_SUBD_UNUSED;
99 static void dev_8255_detach(struct comedi_device *dev)
101 struct comedi_subdevice *s;
104 for (i = 0; i < dev->n_subdevices; i++) {
105 s = &dev->subdevices[i];
106 if (s->type != COMEDI_SUBD_UNUSED) {
107 unsigned long regbase = subdev_8255_regbase(s);
109 release_region(regbase, I8255_SIZE);
114 static struct comedi_driver dev_8255_driver = {
115 .driver_name = "8255",
116 .module = THIS_MODULE,
117 .attach = dev_8255_attach,
118 .detach = dev_8255_detach,
120 module_comedi_driver(dev_8255_driver);
122 MODULE_AUTHOR("Comedi https://www.comedi.org");
123 MODULE_DESCRIPTION("Comedi driver for standalone 8255 devices");
124 MODULE_LICENSE("GPL");