[PATCH 4/4] staging: comedi: ni_labpc: remove *_ai_gain_bits tables

Greg Kroah-Hartman gregkh at linuxfoundation.org
Mon May 13 21:27:35 UTC 2013


On Wed, Apr 24, 2013 at 11:36:02AM -0500, H Hartley Sweeten wrote:
> On Wednesday, April 24, 2013 2:09 AM, Ian Abbott wrote:
> > On 2013-04-23 20:58, H Hartley Sweeten wrote:
> >> The bits needed to set the analog input gain can be simply calculated
> >> based on the 'range'.
> >>
> >> The LabPC versions of the board do not have the '0x10' gain that the
> >> LabPC+ board supports. By incrementing the range appropriately the
> >> correct gain bits can still be calculated.
> >>
> >> This allows removing the two gain tables, as well as the export, along
> >> with the 'ai_range_code' data in the boardinfo.
> >>
> >> Signed-off-by: H Hartley Sweeten <hsweeten at visionengravers.com>
> >> Cc: Ian Abbott <abbbotti at mev.co.uk>
> >> Cc: Greg Kroah-Hartman <gregkh at linuxfoundation.org>
> >> ---
> >>   drivers/staging/comedi/drivers/ni_labpc.c     | 30 +++++++++++++--------------
> >>   drivers/staging/comedi/drivers/ni_labpc.h     |  3 ---
> >>   drivers/staging/comedi/drivers/ni_labpc_cs.c  |  1 -
> >>   drivers/staging/comedi/drivers/ni_labpc_pci.c |  1 -
> >>   4 files changed, 14 insertions(+), 21 deletions(-)
> >>
> >> diff --git a/drivers/staging/comedi/drivers/ni_labpc.c b/drivers/staging/comedi/drivers/ni_labpc.c
> >> index 5ed9a6f..773368d 100644
> >> --- a/drivers/staging/comedi/drivers/ni_labpc.c
> >> +++ b/drivers/staging/comedi/drivers/ni_labpc.c
> >> @@ -88,7 +88,7 @@
> >>   #define CMD1_REG		0x00	/* W: Command 1 reg */
> >>   #define CMD1_MA(x)		(((x) & 0x7) << 0)
> >>   #define CMD1_TWOSCMP		(1 << 3)
> >> -#define CMD1_GAIN_MASK		(7 << 4)
> >> +#define CMD1_GAIN(x)		(((x) & 0x7) << 4)
> >>   #define CMD1_SCANEN		(1 << 7)
> >>   #define CMD2_REG		0x01	/* W: Command 2 reg */
> >>   #define CMD2_PRETRIG		(1 << 0)
> >> @@ -153,11 +153,6 @@ enum scan_mode {
> >>   	MODE_MULT_CHAN_DOWN,
> >>   };
> >>
> >> -static const int labpc_plus_ai_gain_bits[] = {
> >> -	0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
> >> -	0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
> >> -};
> >> -
> >>   static const struct comedi_lrange range_labpc_plus_ai = {
> >>   	16, {
> >>   		BIP_RANGE(5),
> >> @@ -179,12 +174,6 @@ static const struct comedi_lrange range_labpc_plus_ai = {
> >>   	}
> >>   };
> >>
> >> -const int labpc_1200_ai_gain_bits[] = {
> >> -	0x00, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
> >> -	0x00, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
> >> -};
> >> -EXPORT_SYMBOL_GPL(labpc_1200_ai_gain_bits);
> >> -
> >>   static const struct comedi_lrange range_labpc_1200_ai = {
> >>   	14, {
> >>   		BIP_RANGE(5),
> >> @@ -237,20 +226,17 @@ static inline void labpc_writeb(unsigned int byte, unsigned long address)
> >>   static const struct labpc_boardinfo labpc_boards[] = {
> >>   	{
> >>   		.name			= "lab-pc-1200",
> >> -		.ai_range_code		= labpc_1200_ai_gain_bits,
> >>   		.ai_speed		= 10000,
> >>   		.ai_scan_up		= 1,
> >>   		.has_ao			= 1,
> >>   		.is_labpc1200		= 1,
> >>   	}, {
> >>   		.name			= "lab-pc-1200ai",
> >> -		.ai_range_code		= labpc_1200_ai_gain_bits,
> >>   		.ai_speed		= 10000,
> >>   		.ai_scan_up		= 1,
> >>   		.is_labpc1200		= 1,
> >>   	}, {
> >>   		.name			= "lab-pc+",
> >> -		.ai_range_code		= labpc_plus_ai_gain_bits,
> >>   		.ai_speed		= 12000,
> >>   		.has_ao			= 1,
> >>   	},
> >> @@ -321,12 +307,24 @@ static void labpc_ai_set_chan_and_gain(struct comedi_device *dev,
> >>   	const struct labpc_boardinfo *board = comedi_board(dev);
> >>   	struct labpc_private *devpriv = dev->private;
> >>
> >> +	if (board->is_labpc1200) {
> >> +		/*
> >> +		 * The LabPC-1200 boards do not have a gain
> >> +		 * of '0x10'. Skip the range values that would
> >> +		 * result in this gain.
> >> +		 */
> >> +		if (range > 1)
> >> +			range++;
> >> +		if (range > 8)
> >> +			range++;
> >
> > Off-by one error.  That would change the sequence 0 to 13 to the following:
> >
> >	0, 1, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15
> >
> > I think you meant:
> >
> >		if (range > 0)
> >			range++;
> >		if (range > 8)
> >			range++;
> >
> > which maps the sequence 0 to 13 to the following:
> >
> >	0, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15
> 
> Ugh.. You are correct. Brain fart with that.
> 
> > You could also use:
> >
> >		range += (range > 0) + (range > 7);
> >
> > which I think is easier to understand (and doesn't need the curly braces).
> 
> I like that one better. I'll update the patch.
> 
> Greg,
> 
> Do you want all four patchs again as v2 or just an update of this one?

Just an updated this one, I've applied the other 3.

thanks,

greg k-h



More information about the devel mailing list