[PATCH 2/8] staging: comedi: adv_pci1710: remove the 'range_codes_*' static arrays

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

 



These static arrays are used to program the range regiser with the
correct values to select the analog input range. The values in the
arrays are incrememntal for the bipolar and unipolar ranges and
have bit 4 set when the range is unipolar.

Modify the (*attach) of the analog input subdevice to find the range
adjustment needed when a unipolar range is selected. Use the adjusment
value in setup_channel_list() when a unipolar range is selected.

Remove the then unnecessary static arrays as well as the 'rangecode_ai'
boardinfo.

Add defines for the magic numbers used for the bits in the range register.

Signed-off-by: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx>
Cc: Ian Abbott <abbotti@xxxxxxxxx>
Cc: Greg Kroah-Hartman <gregk@xxxxxxxxxxxxxxxxxxx>
---
 drivers/staging/comedi/drivers/adv_pci1710.c | 47 +++++++++++++++-------------
 1 file changed, 25 insertions(+), 22 deletions(-)

diff --git a/drivers/staging/comedi/drivers/adv_pci1710.c b/drivers/staging/comedi/drivers/adv_pci1710.c
index 7a2cec2..bd164d5 100644
--- a/drivers/staging/comedi/drivers/adv_pci1710.c
+++ b/drivers/staging/comedi/drivers/adv_pci1710.c
@@ -58,7 +58,9 @@ Configuration options:
 
 #define PCI171x_AD_DATA	 0	/* R:   A/D data */
 #define PCI171x_SOFTTRG	 0	/* W:   soft trigger for A/D */
-#define PCI171x_RANGE	 2	/* W:   A/D gain/range register */
+#define PCI171x_RANGE_REG	0x02	/* W:   A/D gain/range register */
+#define PCI171x_RANGE_UNIPOL	(1 << 4)
+#define PCI171x_RANGE_DIFF	(1 << 5)
 #define PCI171x_MUX	 4	/* W:   A/D multiplexor control */
 #define PCI171x_STATUS	 6	/* R:   status register */
 #define PCI171x_CONTROL	 6	/* W:   control register */
@@ -128,9 +130,6 @@ static const struct comedi_lrange range_pci1710_3 = {
 	}
 };
 
-static const char range_codes_pci1710_3[] = { 0x00, 0x01, 0x02, 0x03, 0x04,
-					      0x10, 0x11, 0x12, 0x13 };
-
 static const struct comedi_lrange range_pci1710hg = {
 	12, {
 		BIP_RANGE(5),
@@ -148,10 +147,6 @@ static const struct comedi_lrange range_pci1710hg = {
 	}
 };
 
-static const char range_codes_pci1710hg[] = { 0x00, 0x01, 0x02, 0x03, 0x04,
-					      0x05, 0x06, 0x07, 0x10, 0x11,
-					      0x12, 0x13 };
-
 static const struct comedi_lrange range_pci17x1 = {
 	5, {
 		BIP_RANGE(10),
@@ -162,8 +157,6 @@ static const struct comedi_lrange range_pci17x1 = {
 	}
 };
 
-static const char range_codes_pci17x1[] = { 0x00, 0x01, 0x02, 0x03, 0x04 };
-
 static const struct comedi_lrange range_pci1720 = {
 	4, {
 		UNI_RANGE(5),
@@ -202,7 +195,6 @@ struct boardtype {
 	int ai_maxdata;		/*  resolution of A/D */
 	int ao_maxdata;		/*  resolution of D/A */
 	const struct comedi_lrange *rangelist_ai;	/*  rangelist for A/D */
-	const char *rangecode_ai;	/*  range codes for programming */
 	const struct comedi_lrange *rangelist_ao;	/*  rangelist for D/A */
 	unsigned int ai_ns_min;	/*  max sample speed of card v ns */
 	unsigned int fifo_half_size;	/*  size of FIFO/2 */
@@ -222,7 +214,6 @@ static const struct boardtype boardtypes[] = {
 		.ai_maxdata	= 0x0fff,
 		.ao_maxdata	= 0x0fff,
 		.rangelist_ai	= &range_pci1710_3,
-		.rangecode_ai	= range_codes_pci1710_3,
 		.rangelist_ao	= &range_pci171x_da,
 		.ai_ns_min	= 10000,
 		.fifo_half_size	= 2048,
@@ -240,7 +231,6 @@ static const struct boardtype boardtypes[] = {
 		.ai_maxdata	= 0x0fff,
 		.ao_maxdata	= 0x0fff,
 		.rangelist_ai	= &range_pci1710hg,
-		.rangecode_ai	= range_codes_pci1710hg,
 		.rangelist_ao	= &range_pci171x_da,
 		.ai_ns_min	= 10000,
 		.fifo_half_size	= 2048,
@@ -257,7 +247,6 @@ static const struct boardtype boardtypes[] = {
 		.ai_maxdata	= 0x0fff,
 		.ao_maxdata	= 0x0fff,
 		.rangelist_ai	= &range_pci17x1,
-		.rangecode_ai	= range_codes_pci17x1,
 		.rangelist_ao	= &range_pci171x_da,
 		.ai_ns_min	= 10000,
 		.fifo_half_size	= 512,
@@ -270,7 +259,6 @@ static const struct boardtype boardtypes[] = {
 		.n_aichand	= 16,
 		.ai_maxdata	= 0x0fff,
 		.rangelist_ai	= &range_pci1710_3,
-		.rangecode_ai	= range_codes_pci1710_3,
 		.ai_ns_min	= 10000,
 		.fifo_half_size	= 2048,
 	},
@@ -290,7 +278,6 @@ static const struct boardtype boardtypes[] = {
 		.n_dochan	= 16,
 		.ai_maxdata	= 0x0fff,
 		.rangelist_ai	= &range_pci17x1,
-		.rangecode_ai	= range_codes_pci17x1,
 		.ai_ns_min	= 10000,
 		.fifo_half_size	= 512,
 	},
@@ -312,6 +299,7 @@ struct pci1710_private {
 	unsigned short ao_data[4];	/*  data output buffer */
 	unsigned int cnt0_write_wait;	/* after a write, wait for update of the
 					 * internal state */
+	int uni_range_adj;
 };
 
 static int pci171x_ai_dropout(struct comedi_device *dev,
@@ -405,20 +393,26 @@ static void setup_channel_list(struct comedi_device *dev,
 			       unsigned int *chanlist, unsigned int n_chan,
 			       unsigned int seglen)
 {
-	const struct boardtype *this_board = comedi_board(dev);
 	struct pci1710_private *devpriv = dev->private;
-	unsigned int i, range;
+	unsigned int i;
 
 	for (i = 0; i < seglen; i++) {	/*  store range list to card */
 		unsigned int chan = CR_CHAN(chanlist[i]);
+		unsigned int range = CR_RANGE(chanlist[i]);
+		unsigned int aref = CR_AREF(chanlist[i]);
 
 		/* select channel */
 		outw(chan | (chan << 8), dev->iobase + PCI171x_MUX);
 
-		range = this_board->rangecode_ai[CR_RANGE(chanlist[i])];
-		if (CR_AREF(chanlist[i]) == AREF_DIFF)
-			range |= 0x0020;
-		outw(range, dev->iobase + PCI171x_RANGE); /* select gain */
+		/* set range, uni/bipolar, and aref for the channel */
+		if (comedi_range_is_unipolar(s, range)) {
+			range -= devpriv->uni_range_adj;
+			range |= PCI171x_RANGE_UNIPOL;
+		}
+		if (aref == AREF_DIFF)
+			range |= PCI171x_RANGE_DIFF;
+		outw(range, dev->iobase + PCI171x_RANGE_REG);
+
 		devpriv->act_chanlist[i] = (chan << 12) & 0xf000;
 	}
 	for ( ; i < n_chan; i++) { /* store remainder of channel list */
@@ -1110,6 +1104,7 @@ static int pci1710_auto_attach(struct comedi_device *dev,
 	struct pci1710_private *devpriv;
 	struct comedi_subdevice *s;
 	int ret, subdev, n_subdevices;
+	int i;
 
 	if (context < ARRAY_SIZE(boardtypes))
 		this_board = &boardtypes[context];
@@ -1173,6 +1168,14 @@ static int pci1710_auto_attach(struct comedi_device *dev,
 			s->cancel = pci171x_ai_cancel;
 		}
 		subdev++;
+
+		/* find the first unipolar range in the range_table */
+		for (i = 0; i < s->range_table->length; i++) {
+			if (comedi_range_is_unipolar(s, i)) {
+				devpriv->uni_range_adj = i;
+				break;
+			}
+		}
 	}
 
 	if (this_board->n_aochan) {
-- 
1.9.3

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-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