[PATCH 22/26] staging: comedi: ni_labpc: introduce labpc_range_is_unipolar()

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

 



Introduce a helper function to determine if a range selection is
bipolar or unipolar.

This allows removing the static data 'labpc_range_is_unipolar' and
'labpc_plus_is_unipolar' as well as the boardinfo 'ai_range_is_unipolar'.

For consistency, also use the helper in labpc_ao_insn_write() when
checking the range.

Signed-off-by: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx>
Cc: Ian Abbott <abbotti@xxxxxxxxx>
Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
 drivers/staging/comedi/drivers/ni_labpc.c     | 25 +++++++++++++++----------
 drivers/staging/comedi/drivers/ni_labpc.h     |  2 --
 drivers/staging/comedi/drivers/ni_labpc_cs.c  |  1 -
 drivers/staging/comedi/drivers/ni_labpc_isa.c |  8 --------
 drivers/staging/comedi/drivers/ni_labpc_pci.c |  1 -
 5 files changed, 15 insertions(+), 22 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_labpc.c b/drivers/staging/comedi/drivers/ni_labpc.c
index 87dfd36..4c148a7 100644
--- a/drivers/staging/comedi/drivers/ni_labpc.c
+++ b/drivers/staging/comedi/drivers/ni_labpc.c
@@ -185,12 +185,6 @@ enum scan_mode {
 	MODE_MULT_CHAN_DOWN,
 };
 
-const int labpc_1200_is_unipolar[] = {
-	0, 0, 0, 0, 0, 0, 0,
-	1, 1, 1, 1, 1, 1, 1,
-};
-EXPORT_SYMBOL_GPL(labpc_1200_is_unipolar);
-
 const int labpc_1200_ai_gain_bits[] = {
 	0x00, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
 	0x00, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
@@ -217,7 +211,6 @@ const struct comedi_lrange range_labpc_1200_ai = {
 };
 EXPORT_SYMBOL_GPL(range_labpc_1200_ai);
 
-#define AO_RANGE_IS_UNIPOLAR 0x1
 static const struct comedi_lrange range_labpc_ao = {
 	2, {
 		BIP_RANGE(5),
@@ -259,6 +252,18 @@ static void labpc_clear_adc_fifo(const struct comedi_device *dev)
 	devpriv->read_byte(dev->iobase + ADC_FIFO_REG);
 }
 
+static bool labpc_range_is_unipolar(struct comedi_subdevice *s,
+				    unsigned int range)
+{
+	const struct comedi_lrange *lrange = s->range_table;
+	const struct comedi_krange *krange = &lrange->range[range];
+
+	if (krange->min < 0)
+		return false;
+	else
+		return true;
+}
+
 static int labpc_ai_insn_read(struct comedi_device *dev,
 			      struct comedi_subdevice *s,
 			      struct comedi_insn *insn,
@@ -301,7 +306,7 @@ static int labpc_ai_insn_read(struct comedi_device *dev,
 		else
 			devpriv->command6_bits &= ~ADC_COMMON_BIT;
 		/* bipolar or unipolar range? */
-		if (thisboard->ai_range_is_unipolar[range])
+		if (labpc_range_is_unipolar(s, range))
 			devpriv->command6_bits |= ADC_UNIP_BIT;
 		else
 			devpriv->command6_bits &= ~ADC_UNIP_BIT;
@@ -828,7 +833,7 @@ static int labpc_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
 		else
 			devpriv->command6_bits &= ~ADC_COMMON_BIT;
 		/*  bipolar or unipolar range? */
-		if (thisboard->ai_range_is_unipolar[range])
+		if (labpc_range_is_unipolar(s, range))
 			devpriv->command6_bits |= ADC_UNIP_BIT;
 		else
 			devpriv->command6_bits &= ~ADC_UNIP_BIT;
@@ -1258,7 +1263,7 @@ static int labpc_ao_insn_write(struct comedi_device *dev,
 	/* set range */
 	if (thisboard->register_layout == labpc_1200_layout) {
 		range = CR_RANGE(insn->chanspec);
-		if (range & AO_RANGE_IS_UNIPOLAR)
+		if (labpc_range_is_unipolar(s, range))
 			devpriv->command6_bits |= DAC_UNIP_BIT(channel);
 		else
 			devpriv->command6_bits &= ~DAC_UNIP_BIT(channel);
diff --git a/drivers/staging/comedi/drivers/ni_labpc.h b/drivers/staging/comedi/drivers/ni_labpc.h
index 89db708..ded33f4 100644
--- a/drivers/staging/comedi/drivers/ni_labpc.h
+++ b/drivers/staging/comedi/drivers/ni_labpc.h
@@ -42,7 +42,6 @@ struct labpc_boardinfo {
 	int has_ao;		/*  has analog output true/false */
 	const struct comedi_lrange *ai_range_table;
 	const int *ai_range_code;
-	const int *ai_range_is_unipolar;
 
 	/*  board can auto scan up in ai channels, not just down */
 	unsigned ai_scan_up:1;
@@ -103,7 +102,6 @@ int labpc_common_attach(struct comedi_device *dev,
 			unsigned int irq, unsigned long irq_flags);
 void labpc_common_detach(struct comedi_device *dev);
 
-extern const int labpc_1200_is_unipolar[];
 extern const int labpc_1200_ai_gain_bits[];
 extern const struct comedi_lrange range_labpc_1200_ai;
 
diff --git a/drivers/staging/comedi/drivers/ni_labpc_cs.c b/drivers/staging/comedi/drivers/ni_labpc_cs.c
index 99f6172..cb76cbf 100644
--- a/drivers/staging/comedi/drivers/ni_labpc_cs.c
+++ b/drivers/staging/comedi/drivers/ni_labpc_cs.c
@@ -62,7 +62,6 @@ static const struct labpc_boardinfo labpc_cs_boards[] = {
 		.has_ao			= 1,
 		.ai_range_table		= &range_labpc_1200_ai,
 		.ai_range_code		= labpc_1200_ai_gain_bits,
-		.ai_range_is_unipolar	= labpc_1200_is_unipolar,
 	},
 };
 
diff --git a/drivers/staging/comedi/drivers/ni_labpc_isa.c b/drivers/staging/comedi/drivers/ni_labpc_isa.c
index 3ce8de7..b2660c6 100644
--- a/drivers/staging/comedi/drivers/ni_labpc_isa.c
+++ b/drivers/staging/comedi/drivers/ni_labpc_isa.c
@@ -50,11 +50,6 @@
 
 #define LABPC_SIZE		32	/* size of io region used by board */
 
-static const int labpc_plus_is_unipolar[] = {
-	0, 0, 0, 0, 0, 0, 0, 0,
-	1, 1, 1, 1, 1, 1, 1, 1,
-};
-
 static const int labpc_plus_ai_gain_bits[] = {
 	0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
 	0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
@@ -89,7 +84,6 @@ static const struct labpc_boardinfo labpc_boards[] = {
 		.has_ao			= 1,
 		.ai_range_table		= &range_labpc_1200_ai,
 		.ai_range_code		= labpc_1200_ai_gain_bits,
-		.ai_range_is_unipolar	= labpc_1200_is_unipolar,
 		.ai_scan_up		= 1,
 	}, {
 		.name			= "lab-pc-1200ai",
@@ -97,7 +91,6 @@ static const struct labpc_boardinfo labpc_boards[] = {
 		.register_layout	= labpc_1200_layout,
 		.ai_range_table		= &range_labpc_1200_ai,
 		.ai_range_code		= labpc_1200_ai_gain_bits,
-		.ai_range_is_unipolar	= labpc_1200_is_unipolar,
 		.ai_scan_up		= 1,
 	}, {
 		.name			= "lab-pc+",
@@ -106,7 +99,6 @@ static const struct labpc_boardinfo labpc_boards[] = {
 		.has_ao			= 1,
 		.ai_range_table		= &range_labpc_plus_ai,
 		.ai_range_code		= labpc_plus_ai_gain_bits,
-		.ai_range_is_unipolar	= labpc_plus_is_unipolar,
 	},
 };
 
diff --git a/drivers/staging/comedi/drivers/ni_labpc_pci.c b/drivers/staging/comedi/drivers/ni_labpc_pci.c
index 784ebfb..8d09b10 100644
--- a/drivers/staging/comedi/drivers/ni_labpc_pci.c
+++ b/drivers/staging/comedi/drivers/ni_labpc_pci.c
@@ -51,7 +51,6 @@ static const struct labpc_boardinfo labpc_pci_boards[] = {
 		.has_ao			= 1,
 		.ai_range_table		= &range_labpc_1200_ai,
 		.ai_range_code		= labpc_1200_ai_gain_bits,
-		.ai_range_is_unipolar	= labpc_1200_is_unipolar,
 		.ai_scan_up		= 1,
 		.has_mmio		= 1,
 	},
-- 
1.8.1.4

_______________________________________________
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