Commit 59706334 authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman
Browse files

staging: comedi: mf6x4: A/D converter uses 2's complement coding



According to the user's manual, the A/D converter uses 2's complement
coding. Use the comedi_offset_munge() helper to convert the data to
the offset binary format used by comedi.

Signed-off-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
 drivers/staging/comedi/drivers/mf6x4.c | 5 ++---
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent c9ab3023
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@
#define MF6X4_GPIOC_DACEN	BIT(26)

/* BAR1 registers */
#define MF6X4_ADDATA_R		0x00
#define MF6X4_ADDATA_REG	0x00
#define MF6X4_ADCTRL_REG	0x00
#define MF6X4_ADCTRL_CHAN(x)	BIT(chan)
#define MF6X4_DIN_R		0x10
@@ -134,9 +134,9 @@ static int mf6x4_ai_insn_read(struct comedi_device *dev,
			      unsigned int *data)
{
	unsigned int chan = CR_CHAN(insn->chanspec);
	unsigned int d;
	int ret;
	int i;
	int d;

	/* Set the ADC channel number in the scan list */
	iowrite16(MF6X4_ADCTRL_CHAN(chan), dev->mmio + MF6X4_ADCTRL_REG);
@@ -150,9 +150,10 @@ static int mf6x4_ai_insn_read(struct comedi_device *dev,
			return ret;

		/* Read the actual value */
		d = ioread16(dev->mmio + MF6X4_ADDATA_R);
		d = ioread16(dev->mmio + MF6X4_ADDATA_REG);
		d &= s->maxdata;
		data[i] = d;
		/* munge the 2's complement data to offset binary */
		data[i] = comedi_offset_munge(s, d);
	}

	iowrite16(0x0, dev->mmio + MF6X4_ADCTRL_REG);