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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxxxxx>
Cc: Ian Abbott <abbbotti@xxxxxxxxx>
Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
  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

You could also use:

		range += (range > 0) + (range > 7);

which I think is easier to understand (and doesn't need the curly braces).

Probably harder to understand, and possibly not as efficient, but this also works:

		range = (((range + 6) * 8) / 7) - 6;

Take your pick. :)

--
-=( Ian Abbott @ MEV Ltd.    E-mail: <abbotti@xxxxxxxxx>        )=-
-=( Tel: +44 (0)161 477 1898   FAX: +44 (0)161 718 3587         )=-
_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/devel




[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux