Skip to content

Commit e523c6c

Browse files
bigguinessgregkh
authored andcommitted
staging: comedi: drivers: introduce comedi_dio_insn_config()
DIO subdevices always handle the INSN_CONFIG_DIO_{INPUT,OUTPUT} instructions to configure the DIO channels. They also always handle the INSN_CONFIG_DIO_QUERY instruction to query the configuration of a DIO channel. Introduce a helper function to handle the (*insn_config) boilerplate for comedi DIO subdevices. This function has the same paramters as (*insn_config) functions with an additional parameter to allow the caller to pass a 'mask' value for grouped DIO channels. This function returns: 0 if the instruction was successful but requires additional handling by the caller (INSN_CONFIG_DIO_{INPUT,OUTPUT} insn->n if the instruction was handled (INSN_CONFIG_DIO_QUERY) -EINVAL for all unhandled instructions The caller is responsible for actually configuring the hardware based on the configuration (s->io_bits). Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 987f3c8 commit e523c6c

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

drivers/staging/comedi/comedidev.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,10 @@ void comedi_buf_memcpy_from(struct comedi_async *async, unsigned int offset,
342342

343343
/* drivers.c - general comedi driver functions */
344344

345+
int comedi_dio_insn_config(struct comedi_device *, struct comedi_subdevice *,
346+
struct comedi_insn *, unsigned int *data,
347+
unsigned int mask);
348+
345349
void *comedi_alloc_devpriv(struct comedi_device *, size_t);
346350
int comedi_alloc_subdevices(struct comedi_device *, int);
347351

drivers/staging/comedi/drivers.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,46 @@ int insn_inval(struct comedi_device *dev, struct comedi_subdevice *s,
150150
return -EINVAL;
151151
}
152152

153+
/**
154+
* comedi_dio_insn_config() - boilerplate (*insn_config) for DIO subdevices.
155+
* @dev: comedi_device struct
156+
* @s: comedi_subdevice struct
157+
* @insn: comedi_insn struct
158+
* @data: parameters for the @insn
159+
* @mask: io_bits mask for grouped channels
160+
*/
161+
int comedi_dio_insn_config(struct comedi_device *dev,
162+
struct comedi_subdevice *s,
163+
struct comedi_insn *insn,
164+
unsigned int *data,
165+
unsigned int mask)
166+
{
167+
unsigned int chan_mask = 1 << CR_CHAN(insn->chanspec);
168+
169+
if (!mask)
170+
mask = chan_mask;
171+
172+
switch (data[0]) {
173+
case INSN_CONFIG_DIO_INPUT:
174+
s->io_bits &= ~mask;
175+
break;
176+
177+
case INSN_CONFIG_DIO_OUTPUT:
178+
s->io_bits |= mask;
179+
break;
180+
181+
case INSN_CONFIG_DIO_QUERY:
182+
data[1] = (s->io_bits & mask) ? COMEDI_OUTPUT : COMEDI_INPUT;
183+
return insn->n;
184+
185+
default:
186+
return -EINVAL;
187+
}
188+
189+
return 0;
190+
}
191+
EXPORT_SYMBOL_GPL(comedi_dio_insn_config);
192+
153193
static int insn_rw_emulate_bits(struct comedi_device *dev,
154194
struct comedi_subdevice *s,
155195
struct comedi_insn *insn, unsigned int *data)

0 commit comments

Comments
 (0)