]>
git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blob - drivers/staging/comedi/drivers/ssv_dnp.c
1 // SPDX-License-Identifier: GPL-2.0+
4 * generic comedi driver for SSV Embedded Systems' DIL/Net-PCs
5 * Copyright (C) 2001 Robert Schwebel <robert@schwebel.de>
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
13 * Description: SSV Embedded Systems DIL/Net-PC
14 * Author: Robert Schwebel <robert@schwebel.de>
15 * Devices: [SSV Embedded Systems] DIL/Net-PC 1486 (dnp-1486)
19 /* include files ----------------------------------------------------------- */
21 #include <linux/module.h>
22 #include "../comedidev.h"
24 /* Some global definitions: the registers of the DNP ----------------------- */
26 /* For port A and B the mode register has bits corresponding to the output */
27 /* pins, where Bit-N = 0 -> input, Bit-N = 1 -> output. Note that bits */
28 /* 4 to 7 correspond to pin 0..3 for port C data register. Ensure that bits */
29 /* 0..3 remain unchanged! For details about Port C Mode Register see */
30 /* the remarks in dnp_insn_config() below. */
32 #define CSCIR 0x22 /* Chip Setup and Control Index Register */
33 #define CSCDR 0x23 /* Chip Setup and Control Data Register */
34 #define PAMR 0xa5 /* Port A Mode Register */
35 #define PADR 0xa9 /* Port A Data Register */
36 #define PBMR 0xa4 /* Port B Mode Register */
37 #define PBDR 0xa8 /* Port B Data Register */
38 #define PCMR 0xa3 /* Port C Mode Register */
39 #define PCDR 0xa7 /* Port C Data Register */
41 static int dnp_dio_insn_bits(struct comedi_device
*dev
,
42 struct comedi_subdevice
*s
,
43 struct comedi_insn
*insn
,
50 * Ports A and B are straight forward: each bit corresponds to an
51 * output pin with the same order. Port C is different: bits 0...3
52 * correspond to bits 4...7 of the output register (PCDR).
55 mask
= comedi_dio_update_state(s
, data
);
58 outb(s
->state
& 0xff, CSCDR
);
61 outb((s
->state
>> 8) & 0xff, CSCDR
);
64 val
= inb(CSCDR
) & 0x0f;
65 outb(((s
->state
>> 12) & 0xf0) | val
, CSCDR
);
71 val
|= (inb(CSCDR
) << 8);
73 val
|= ((inb(CSCDR
) & 0xf0) << 12);
80 static int dnp_dio_insn_config(struct comedi_device
*dev
,
81 struct comedi_subdevice
*s
,
82 struct comedi_insn
*insn
,
85 unsigned int chan
= CR_CHAN(insn
->chanspec
);
90 ret
= comedi_dio_insn_config(dev
, s
, insn
, data
, 0);
94 if (chan
< 8) { /* Port A */
97 } else if (chan
< 16) { /* Port B */
98 mask
= 1 << (chan
- 8);
100 } else { /* Port C */
102 * We have to pay attention with port C.
103 * This is the meaning of PCMR:
104 * Bit in PCMR: 7 6 5 4 3 2 1 0
105 * Corresponding port C pin: d 3 d 2 d 1 d 0 d= don't touch
107 * Multiplication by 2 brings bits into correct position
110 mask
= 1 << ((chan
- 16) * 2);
115 if (data
[0] == COMEDI_OUTPUT
)
124 static int dnp_attach(struct comedi_device
*dev
, struct comedi_devconfig
*it
)
126 struct comedi_subdevice
*s
;
130 * We use I/O ports 0x22, 0x23 and 0xa3-0xa9, which are always
131 * allocated for the primary 8259, so we don't need to allocate
135 ret
= comedi_alloc_subdevices(dev
, 1);
139 s
= &dev
->subdevices
[0];
140 /* digital i/o subdevice */
141 s
->type
= COMEDI_SUBD_DIO
;
142 s
->subdev_flags
= SDF_READABLE
| SDF_WRITABLE
;
145 s
->range_table
= &range_digital
;
146 s
->insn_bits
= dnp_dio_insn_bits
;
147 s
->insn_config
= dnp_dio_insn_config
;
149 /* configure all ports as input (default) */
155 outb((inb(CSCDR
) & 0xAA), CSCDR
);
160 static void dnp_detach(struct comedi_device
*dev
)
167 outb((inb(CSCDR
) & 0xAA), CSCDR
);
170 static struct comedi_driver dnp_driver
= {
171 .driver_name
= "dnp-1486",
172 .module
= THIS_MODULE
,
173 .attach
= dnp_attach
,
174 .detach
= dnp_detach
,
176 module_comedi_driver(dnp_driver
);
178 MODULE_AUTHOR("Comedi http://www.comedi.org");
179 MODULE_DESCRIPTION("Comedi low-level driver");
180 MODULE_LICENSE("GPL");