Skip to content

Commit 05e60b1

Browse files
bigguinessgregkh
authored andcommitted
staging: comedi: drivers: introduce comedi_dio_update_state()
The (*insn_bits) functions for DIO and DO subdevices typically use the subdevice 's->state' to hold the current state of the output channels. The 'insn' passed to these functions, INSN_BITS, specifies two parameters passed in the 'data'. data[0] = 'mask', the channels to update data[1] = 'bits', the new state for the channels Introduce a helper function to handle the boilerplate used to update the internal state. Note that the 'mask' is filtered by the 'chanmask' of the channels actually supported by the subdevice. This is used to protect any non-channel related bits that are stored in the subdevice state. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 09567cb commit 05e60b1

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

drivers/staging/comedi/comedidev.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,8 @@ void comedi_buf_memcpy_from(struct comedi_async *async, unsigned int offset,
345345
int comedi_dio_insn_config(struct comedi_device *, struct comedi_subdevice *,
346346
struct comedi_insn *, unsigned int *data,
347347
unsigned int mask);
348+
unsigned int comedi_dio_update_state(struct comedi_subdevice *,
349+
unsigned int *data);
348350

349351
void *comedi_alloc_devpriv(struct comedi_device *, size_t);
350352
int comedi_alloc_subdevices(struct comedi_device *, int);

drivers/staging/comedi/drivers.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,28 @@ int comedi_dio_insn_config(struct comedi_device *dev,
190190
}
191191
EXPORT_SYMBOL_GPL(comedi_dio_insn_config);
192192

193+
/**
194+
* comedi_dio_update_state() - update the internal state of DIO subdevices.
195+
* @s: comedi_subdevice struct
196+
* @data: the channel mask and bits to update
197+
*/
198+
unsigned int comedi_dio_update_state(struct comedi_subdevice *s,
199+
unsigned int *data)
200+
{
201+
unsigned int chanmask = (s->n_chan < 32) ? ((1 << s->n_chan) - 1)
202+
: 0xffffffff;
203+
unsigned int mask = data[0] & chanmask;
204+
unsigned int bits = data[1];
205+
206+
if (mask) {
207+
s->state &= ~mask;
208+
s->state |= (bits & mask);
209+
}
210+
211+
return mask;
212+
}
213+
EXPORT_SYMBOL_GPL(comedi_dio_update_state);
214+
193215
static int insn_rw_emulate_bits(struct comedi_device *dev,
194216
struct comedi_subdevice *s,
195217
struct comedi_insn *insn, unsigned int *data)

0 commit comments

Comments
 (0)