Commit 01fca473 authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

staging: comedi: jr3_pci: tidy up jr3_pci_poll_subdevice()

Refactor the function to reduce the indent level.

For aesthetics, rename the subdevice private data pointer from 'p'
to 'spriv'.

Rename the lacal variable used for the channel->full_scale to 'fs'
to reduce the line lengths.

Remove the setting of range[8]. The min,max values are the same as
the ones used when the subdevice private data was allocated and
initialized.

Remove the poll_delay_min_max() that are the same as the default.
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 a448376e
...@@ -429,64 +429,66 @@ static int jr3_download_firmware(struct comedi_device *dev, ...@@ -429,64 +429,66 @@ static int jr3_download_firmware(struct comedi_device *dev,
static struct poll_delay_t jr3_pci_poll_subdevice(struct comedi_subdevice *s) static struct poll_delay_t jr3_pci_poll_subdevice(struct comedi_subdevice *s)
{ {
struct jr3_pci_subdev_private *spriv = s->private;
struct poll_delay_t result = poll_delay_min_max(1000, 2000); struct poll_delay_t result = poll_delay_min_max(1000, 2000);
struct jr3_pci_subdev_private *p = s->private; struct jr3_channel __iomem *channel;
u16 model_no;
u16 serial_no;
int errors;
int i; int i;
if (p) { if (!spriv)
struct jr3_channel __iomem *channel = p->channel; return result;
int errors = get_u16(&channel->errors);
if (errors != p->errors) channel = spriv->channel;
p->errors = errors; errors = get_u16(&channel->errors);
if (errors != spriv->errors)
spriv->errors = errors;
/* Sensor communication lost? force poll mode */
if (errors & (watch_dog | watch_dog2 | sensor_change)) if (errors & (watch_dog | watch_dog2 | sensor_change))
/* Sensor communication lost, force poll mode */ spriv->state = state_jr3_poll;
p->state = state_jr3_poll;
switch (spriv->state) {
case state_jr3_poll:
model_no = get_u16(&channel->model_no);
serial_no = get_u16(&channel->serial_no);
switch (p->state) {
case state_jr3_poll: {
u16 model_no = get_u16(&channel->model_no);
u16 serial_no = get_u16(&channel->serial_no);
if ((errors & (watch_dog | watch_dog2)) || if ((errors & (watch_dog | watch_dog2)) ||
model_no == 0 || serial_no == 0) { model_no == 0 || serial_no == 0) {
/* /*
* Still no sensor, keep on polling. * Still no sensor, keep on polling.
* Since it takes up to 10 seconds * Since it takes up to 10 seconds for offsets to
* for offsets to stabilize, polling * stabilize, polling each second should suffice.
* each second should suffice.
*/ */
result = poll_delay_min_max(1000, 2000);
} else { } else {
p->retries = 0; spriv->retries = 0;
p->state = spriv->state = state_jr3_init_wait_for_offset;
state_jr3_init_wait_for_offset;
result = poll_delay_min_max(1000, 2000);
}
} }
break; break;
case state_jr3_init_wait_for_offset: case state_jr3_init_wait_for_offset:
p->retries++; spriv->retries++;
if (p->retries < 10) { if (spriv->retries < 10) {
/* Wait for offeset to stabilize /*
* (< 10 s according to manual) */ * Wait for offeset to stabilize
result = poll_delay_min_max(1000, 2000); * (< 10 s according to manual)
*/
} else { } else {
struct transform_t transf; struct transform_t transf;
p->model_no = get_u16(&channel->model_no); spriv->model_no = get_u16(&channel->model_no);
p->serial_no = get_u16(&channel->serial_no); spriv->serial_no = get_u16(&channel->serial_no);
/* Transformation all zeros */ /* Transformation all zeros */
for (i = 0; i < ARRAY_SIZE(transf.link); i++) { for (i = 0; i < ARRAY_SIZE(transf.link); i++) {
transf.link[i].link_type = transf.link[i].link_type = (enum link_types)0;
(enum link_types)0;
transf.link[i].link_amount = 0; transf.link[i].link_amount = 0;
} }
set_transforms(channel, transf, 0); set_transforms(channel, transf, 0);
use_transform(channel, 0); use_transform(channel, 0);
p->state = state_jr3_init_transform_complete; spriv->state = state_jr3_init_transform_complete;
/* Allow 20 ms for completion */ /* Allow 20 ms for completion */
result = poll_delay_min_max(20, 100); result = poll_delay_min_max(20, 100);
} }
...@@ -503,8 +505,7 @@ static struct poll_delay_t jr3_pci_poll_subdevice(struct comedi_subdevice *s) ...@@ -503,8 +505,7 @@ static struct poll_delay_t jr3_pci_poll_subdevice(struct comedi_subdevice *s)
max_full_scale = get_max_full_scales(channel); max_full_scale = get_max_full_scales(channel);
set_full_scales(channel, max_full_scale); set_full_scales(channel, max_full_scale);
p->state = spriv->state = state_jr3_init_set_full_scale_complete;
state_jr3_init_set_full_scale_complete;
/* Allow 20 ms for completion */ /* Allow 20 ms for completion */
result = poll_delay_min_max(20, 100); result = poll_delay_min_max(20, 100);
} }
...@@ -513,48 +514,31 @@ static struct poll_delay_t jr3_pci_poll_subdevice(struct comedi_subdevice *s) ...@@ -513,48 +514,31 @@ static struct poll_delay_t jr3_pci_poll_subdevice(struct comedi_subdevice *s)
if (!is_complete(channel)) { if (!is_complete(channel)) {
result = poll_delay_min_max(20, 100); result = poll_delay_min_max(20, 100);
} else { } else {
struct force_array __iomem *full_scale; struct force_array __iomem *fs = &channel->full_scale;
/* Use ranges in kN or we will /* Use ranges in kN or we will overflow around 2000N! */
* overflow around 2000N! */ spriv->range[0].range.min = -get_s16(&fs->fx) * 1000;
full_scale = &channel->full_scale; spriv->range[0].range.max = get_s16(&fs->fx) * 1000;
p->range[0].range.min = spriv->range[1].range.min = -get_s16(&fs->fy) * 1000;
-get_s16(&full_scale->fx) * 1000; spriv->range[1].range.max = get_s16(&fs->fy) * 1000;
p->range[0].range.max = spriv->range[2].range.min = -get_s16(&fs->fz) * 1000;
get_s16(&full_scale->fx) * 1000; spriv->range[2].range.max = get_s16(&fs->fz) * 1000;
p->range[1].range.min = spriv->range[3].range.min = -get_s16(&fs->mx) * 100;
-get_s16(&full_scale->fy) * 1000; spriv->range[3].range.max = get_s16(&fs->mx) * 100;
p->range[1].range.max = spriv->range[4].range.min = -get_s16(&fs->my) * 100;
get_s16(&full_scale->fy) * 1000; spriv->range[4].range.max = get_s16(&fs->my) * 100;
p->range[2].range.min = spriv->range[5].range.min = -get_s16(&fs->mz) * 100;
-get_s16(&full_scale->fz) * 1000; /* the next five are questionable */
p->range[2].range.max = spriv->range[5].range.max = get_s16(&fs->mz) * 100;
get_s16(&full_scale->fz) * 1000; spriv->range[6].range.min = -get_s16(&fs->v1) * 100;
p->range[3].range.min = spriv->range[6].range.max = get_s16(&fs->v1) * 100;
-get_s16(&full_scale->mx) * 100; spriv->range[7].range.min = -get_s16(&fs->v2) * 100;
p->range[3].range.max = spriv->range[7].range.max = get_s16(&fs->v2) * 100;
get_s16(&full_scale->mx) * 100; spriv->range[8].range.min = 0;
p->range[4].range.min = spriv->range[8].range.max = 65535;
-get_s16(&full_scale->my) * 100;
p->range[4].range.max =
get_s16(&full_scale->my) * 100;
p->range[5].range.min =
-get_s16(&full_scale->mz) * 100;
p->range[5].range.max =
get_s16(&full_scale->mz) * 100; /* ?? */
p->range[6].range.min =
-get_s16(&full_scale->v1) * 100;/* ?? */
p->range[6].range.max =
get_s16(&full_scale->v1) * 100; /* ?? */
p->range[7].range.min =
-get_s16(&full_scale->v2) * 100;/* ?? */
p->range[7].range.max =
get_s16(&full_scale->v2) * 100; /* ?? */
p->range[8].range.min = 0;
p->range[8].range.max = 65535;
use_offset(channel, 0); use_offset(channel, 0);
p->state = state_jr3_init_use_offset_complete; spriv->state = state_jr3_init_use_offset_complete;
/* Allow 40 ms for completion */ /* Allow 40 ms for completion */
result = poll_delay_min_max(40, 100); result = poll_delay_min_max(40, 100);
} }
...@@ -572,17 +556,16 @@ static struct poll_delay_t jr3_pci_poll_subdevice(struct comedi_subdevice *s) ...@@ -572,17 +556,16 @@ static struct poll_delay_t jr3_pci_poll_subdevice(struct comedi_subdevice *s)
set_offset(channel); set_offset(channel);
p->state = state_jr3_done; spriv->state = state_jr3_done;
} }
break; break;
case state_jr3_done: case state_jr3_done:
poll_delay_min_max(10000, 20000); result = poll_delay_min_max(10000, 20000);
break; break;
default: default:
poll_delay_min_max(1000, 2000);
break; break;
} }
}
return result; return result;
} }
......
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