diff options
author | H Hartley Sweeten <hsweeten@visionengravers.com> | 2014-03-07 20:41:03 (GMT) |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2014-03-17 19:38:53 (GMT) |
commit | 16a86abea711d9ea5893cd60a6cd608393f9698c (patch) | |
tree | 91a27b80016378b8521475f46cac26ebd48ac9c9 /drivers | |
parent | 617cd65312a651d20c8c252b1465dfdec1a03ac4 (diff) | |
download | linux-16a86abea711d9ea5893cd60a6cd608393f9698c.tar.xz |
staging: comedi: jr3_pci: tidy up jr3_pci_ai_insn_read()
Refactor this function to make it clearer.
The channel does not need to be validated. The comedi core does that for us.
Exit early if the subdevice private data is invalid.
Exit early if the subdevice 'state' is not done or there is an error.
Factor out the code that actually reads the channel data to reduce the
indent level.
Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/staging/comedi/drivers/jr3_pci.c | 156 |
1 files changed, 73 insertions, 83 deletions
diff --git a/drivers/staging/comedi/drivers/jr3_pci.c b/drivers/staging/comedi/drivers/jr3_pci.c index 83f2f8b..f80bfcb 100644 --- a/drivers/staging/comedi/drivers/jr3_pci.c +++ b/drivers/staging/comedi/drivers/jr3_pci.c @@ -194,94 +194,84 @@ static struct six_axis_t get_max_full_scales(struct jr3_channel __iomem return result; } +static unsigned int jr3_pci_ai_read_chan(struct comedi_device *dev, + struct comedi_subdevice *s, + unsigned int chan) +{ + struct jr3_pci_subdev_private *spriv = s->private; + unsigned int val = 0; + + if (spriv->state != state_jr3_done) + return 0; + + if (chan < 56) { + unsigned int axis = chan % 8; + unsigned filter = chan / 8; + + switch (axis) { + case 0: + val = get_s16(&spriv->channel->filter[filter].fx); + break; + case 1: + val = get_s16(&spriv->channel->filter[filter].fy); + break; + case 2: + val = get_s16(&spriv->channel->filter[filter].fz); + break; + case 3: + val = get_s16(&spriv->channel->filter[filter].mx); + break; + case 4: + val = get_s16(&spriv->channel->filter[filter].my); + break; + case 5: + val = get_s16(&spriv->channel->filter[filter].mz); + break; + case 6: + val = get_s16(&spriv->channel->filter[filter].v1); + break; + case 7: + val = get_s16(&spriv->channel->filter[filter].v2); + break; + } + val += 0x4000; + } else if (chan == 56) { + val = get_u16(&spriv->channel->model_no); + } else if (chan == 57) { + val = get_u16(&spriv->channel->serial_no); + } + + return val; +} + static int jr3_pci_ai_insn_read(struct comedi_device *dev, struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) + struct comedi_insn *insn, + unsigned int *data) { - int result; - struct jr3_pci_subdev_private *p; - int channel; - - p = s->private; - channel = CR_CHAN(insn->chanspec); - if (p == NULL || channel > 57) { - result = -EINVAL; - } else { - int i; - - result = insn->n; - if (p->state != state_jr3_done || - (get_u16(&p->channel->errors) & (watch_dog | watch_dog2 | - sensor_change))) { - /* No sensor or sensor changed */ - if (p->state == state_jr3_done) { - /* Restart polling */ - p->state = state_jr3_poll; - } - result = -EAGAIN; - } - for (i = 0; i < insn->n; i++) { - if (channel < 56) { - int axis, filter; - - axis = channel % 8; - filter = channel / 8; - if (p->state != state_jr3_done) { - data[i] = 0; - } else { - int F = 0; - switch (axis) { - case 0: - F = get_s16(&p->channel-> - filter[filter].fx); - break; - case 1: - F = get_s16(&p->channel-> - filter[filter].fy); - break; - case 2: - F = get_s16(&p->channel-> - filter[filter].fz); - break; - case 3: - F = get_s16(&p->channel-> - filter[filter].mx); - break; - case 4: - F = get_s16(&p->channel-> - filter[filter].my); - break; - case 5: - F = get_s16(&p->channel-> - filter[filter].mz); - break; - case 6: - F = get_s16(&p->channel-> - filter[filter].v1); - break; - case 7: - F = get_s16(&p->channel-> - filter[filter].v2); - break; - } - data[i] = F + 0x4000; - } - } else if (channel == 56) { - if (p->state != state_jr3_done) - data[i] = 0; - else - data[i] = - get_u16(&p->channel->model_no); - } else if (channel == 57) { - if (p->state != state_jr3_done) - data[i] = 0; - else - data[i] = - get_u16(&p->channel->serial_no); - } + struct jr3_pci_subdev_private *spriv = s->private; + unsigned int chan = CR_CHAN(insn->chanspec); + u16 errors; + int i; + + if (!spriv) + return -EINVAL; + + errors = get_u16(&spriv->channel->errors); + if (spriv->state != state_jr3_done || + (errors & (watch_dog | watch_dog2 | sensor_change))) { + /* No sensor or sensor changed */ + if (spriv->state == state_jr3_done) { + /* Restart polling */ + spriv->state = state_jr3_poll; } + return -EAGAIN; } - return result; + + for (i = 0; i < insn->n; i++) + data[i] = jr3_pci_ai_read_chan(dev, s, chan); + + return insn->n; } static int jr3_pci_open(struct comedi_device *dev) |