[PATCH 6/8] staging: comedi: adv_pci1710: simplify pci1720 reset

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

 



The Analog Output channels on the PCI-1720 board are all set to 0V when
the board is 'reset'. Instead of setting the output ranges to bipolar 5V
and having to deal with the two's complement values, set them to unipolar
5V (which is the power-on default).

For aesthetics, redefine the register map for the analog output registers,

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 | 28 +++++++++++++---------------
 1 file changed, 13 insertions(+), 15 deletions(-)

diff --git a/drivers/staging/comedi/drivers/adv_pci1710.c b/drivers/staging/comedi/drivers/adv_pci1710.c
index c2c5b34..6229983 100644
--- a/drivers/staging/comedi/drivers/adv_pci1710.c
+++ b/drivers/staging/comedi/drivers/adv_pci1710.c
@@ -105,10 +105,7 @@ Configuration options:
 #define Counter_SC1     0x0080	/* be used, 00 for CNT0,
 				 * 11 for read-back command */
 
-#define PCI1720_DA0	 0	/* W:   D/A register 0 */
-#define PCI1720_DA1	 2	/* W:   D/A register 1 */
-#define PCI1720_DA2	 4	/* W:   D/A register 2 */
-#define PCI1720_DA3	 6	/* W:   D/A register 3 */
+#define PCI1720_AO_REG(x)	(0x00 + ((x) * 2))
 #define PCI1720_RANGE	 8	/* R/W: D/A range register */
 #define PCI1720_SYNCOUT	 9	/* W:   D/A synchronized output register */
 #define PCI1720_SYNCONT	15	/* R/W: D/A synchronized control */
@@ -702,7 +699,7 @@ static int pci1720_insn_write_ao(struct comedi_device *dev,
 		if (comedi_range_is_bipolar(s, range))
 			val = comedi_offset_munge(s, val);
 
-		outw(val, dev->iobase + PCI1720_DA0 + (chan << 1));
+		outw(val, dev->iobase + PCI1720_AO_REG(chan));
 		outb(0, dev->iobase + PCI1720_SYNCOUT);	/*  update outputs */
 	}
 
@@ -1072,19 +1069,20 @@ static int pci171x_reset(struct comedi_device *dev)
 static int pci1720_reset(struct comedi_device *dev)
 {
 	struct pci1710_private *devpriv = dev->private;
+	int i;
 
 	outb(Syncont_SC0, dev->iobase + PCI1720_SYNCONT);	/*  set synchronous output mode */
-	devpriv->da_ranges = 0xAA;
-	outb(devpriv->da_ranges, dev->iobase + PCI1720_RANGE);	/*  set all ranges to +/-5V */
-	outw(0x0800, dev->iobase + PCI1720_DA0);	/*  set outputs to 0V */
-	outw(0x0800, dev->iobase + PCI1720_DA1);
-	outw(0x0800, dev->iobase + PCI1720_DA2);
-	outw(0x0800, dev->iobase + PCI1720_DA3);
+
+	/* set all ranges to unipolar 5V */
+	devpriv->da_ranges = 0;
+	outb(devpriv->da_ranges, dev->iobase + PCI1720_RANGE);
+	/* set all outputs to 0V */
+	for (i = 0; i < 4; i++) {
+		devpriv->ao_data[i] = 0;
+		outw(devpriv->ao_data[i], dev->iobase + PCI1720_AO_REG(i));
+	}
 	outb(0, dev->iobase + PCI1720_SYNCOUT);	/*  update outputs */
-	devpriv->ao_data[0] = 0x0800;
-	devpriv->ao_data[1] = 0x0800;
-	devpriv->ao_data[2] = 0x0800;
-	devpriv->ao_data[3] = 0x0800;
+
 	return 0;
 }
 
-- 
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