Commit 16a86abe authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

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: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 617cd653
......@@ -194,94 +194,84 @@ static struct six_axis_t get_max_full_scales(struct jr3_channel __iomem
return result;
}
static int jr3_pci_ai_insn_read(struct comedi_device *dev,
static unsigned int jr3_pci_ai_read_chan(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
unsigned int chan)
{
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;
struct jr3_pci_subdev_private *spriv = s->private;
unsigned int val = 0;
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;
if (spriv->state != state_jr3_done)
return 0;
if (chan < 56) {
unsigned int axis = chan % 8;
unsigned filter = chan / 8;
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);
val = get_s16(&spriv->channel->filter[filter].fx);
break;
case 1:
F = get_s16(&p->channel->
filter[filter].fy);
val = get_s16(&spriv->channel->filter[filter].fy);
break;
case 2:
F = get_s16(&p->channel->
filter[filter].fz);
val = get_s16(&spriv->channel->filter[filter].fz);
break;
case 3:
F = get_s16(&p->channel->
filter[filter].mx);
val = get_s16(&spriv->channel->filter[filter].mx);
break;
case 4:
F = get_s16(&p->channel->
filter[filter].my);
val = get_s16(&spriv->channel->filter[filter].my);
break;
case 5:
F = get_s16(&p->channel->
filter[filter].mz);
val = get_s16(&spriv->channel->filter[filter].mz);
break;
case 6:
F = get_s16(&p->channel->
filter[filter].v1);
val = get_s16(&spriv->channel->filter[filter].v1);
break;
case 7:
F = get_s16(&p->channel->
filter[filter].v2);
val = get_s16(&spriv->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);
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 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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment