Skip to content

Commit

Permalink
staging: comedi: s526: remove struct s526GPCTConfig
Browse files Browse the repository at this point in the history
The enum in this struct is used by the driver to know how the
gpct channels have been configured. Instead of using the private
enum S526_GPCT_APP_CLASS, we can just use the INSN_CONFIG_* value
that was passed in data[0] to the s526_gpct_insn_config().

The data array in this struct in never used. It actually could
cause a BUG since it assumes that the data pointer passed to
s526_gpct_insn_config() always has 6 values but the comments
indicate that there are really only 4 or 5.

Remove the s526GPCTConfig struct and associated S526_GPCT_APP_CLASS
enum and just use and unsigned int array in the private data to
hold the gpct configuration.

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>
  • Loading branch information
H Hartley Sweeten authored and Greg Kroah-Hartman committed Sep 21, 2012
1 parent 5c813bb commit 675f98f
Showing 1 changed file with 9 additions and 37 deletions.
46 changes: 9 additions & 37 deletions drivers/staging/comedi/drivers/s526.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,29 +118,9 @@ union cmReg {
unsigned short value;
};

#define MAX_GPCT_CONFIG_DATA 6

/* Different Application Classes for GPCT Subdevices */
/* The list is not exhaustive and needs discussion! */
enum S526_GPCT_APP_CLASS {
CountingAndTimeMeasurement,
SinglePulseGeneration,
PulseTrainGeneration,
PositionMeasurement,
Miscellaneous
};

/* Config struct for different GPCT subdevice Application Classes and
their options
*/
struct s526GPCTConfig {
enum S526_GPCT_APP_CLASS app;
int data[MAX_GPCT_CONFIG_DATA];
};

struct s526_private {
unsigned int ao_readback[2];
struct s526GPCTConfig s526_gpct_config[4];
unsigned int gpct_config[4];
unsigned short s526_ai_config;
};

Expand Down Expand Up @@ -175,12 +155,8 @@ static int s526_gpct_insn_config(struct comedi_device *dev,
unsigned int chan = CR_CHAN(insn->chanspec);
unsigned long chan_iobase = dev->iobase + chan * 8;
unsigned int val;
int i;
union cmReg cmReg;

for (i = 0; i < MAX_GPCT_CONFIG_DATA; i++)
devpriv->s526_gpct_config[chan].data[i] = data[i];

/* Check what type of Counter the user requested, data[0] contains */
/* the Application type */
switch (data[0]) {
Expand All @@ -191,7 +167,7 @@ static int s526_gpct_insn_config(struct comedi_device *dev,
data[2]: Pre-load Register Value
data[3]: Conter Control Register
*/
devpriv->s526_gpct_config[chan].app = PositionMeasurement;
devpriv->gpct_config[chan] = data[0];

#if 0
/* Example of Counter Application */
Expand Down Expand Up @@ -294,7 +270,7 @@ static int s526_gpct_insn_config(struct comedi_device *dev,
data[3]: Pre-load Register 1 Value
data[4]: Conter Control Register
*/
devpriv->s526_gpct_config[chan].app = SinglePulseGeneration;
devpriv->gpct_config[chan] = data[0];

/* Set Counter Mode Register */
cmReg.value = data[1] & 0xffff;
Expand Down Expand Up @@ -337,7 +313,7 @@ static int s526_gpct_insn_config(struct comedi_device *dev,
data[3]: Pre-load Register 1 Value
data[4]: Conter Control Register
*/
devpriv->s526_gpct_config[chan].app = PulseTrainGeneration;
devpriv->gpct_config[chan] = data[0];

/* Set Counter Mode Register */
cmReg.value = data[1] & 0xffff;
Expand Down Expand Up @@ -392,25 +368,21 @@ static int s526_gpct_winsn(struct comedi_device *dev,
inw(chan_iobase + REG_C0M); /* Is this read required? */

/* Check what Application of Counter this channel is configured for */
switch (devpriv->s526_gpct_config[chan].app) {
case PulseTrainGeneration:
switch (devpriv->gpct_config[chan]) {
case INSN_CONFIG_GPCT_PULSE_TRAIN_GENERATOR:
/* data[0] contains the PULSE_WIDTH
data[1] contains the PULSE_PERIOD
@pre PULSE_PERIOD > PULSE_WIDTH > 0
The above periods must be expressed as a multiple of the
pulse frequency on the selected source
*/
if ((data[1] > data[0]) && (data[0] > 0)) {
devpriv->s526_gpct_config[chan].data[0] = data[0];
devpriv->s526_gpct_config[chan].data[1] = data[1];
} else {
if ((data[1] < data[0]) || !data[0])
return -EINVAL;
}

/* Fall thru to write the PULSE_WIDTH */

case PositionMeasurement:
case SinglePulseGeneration:
case INSN_CONFIG_GPCT_QUADRATURE_ENCODER:
case INSN_CONFIG_GPCT_SINGLE_PULSE_GENERATOR:
outw((data[0] >> 16) & 0xffff, chan_iobase + REG_C0H);
outw(data[0] & 0xffff, chan_iobase + REG_C0L);
break;
Expand Down

0 comments on commit 675f98f

Please sign in to comment.