[PATCH 14/14] staging: comedi: ii_pci20kc: reorder subdevices

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

 



Make the built-on dio subdevice 0 and the three add-on modules
subdevices 1-3. This allows the driver to consistently use the
ii20k_module_iobase() helper to get the base address needed to
access a the registers used by a given subdevice.

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

diff --git a/drivers/staging/comedi/drivers/ii_pci20kc.c b/drivers/staging/comedi/drivers/ii_pci20kc.c
index 954c539..377bf00 100644
--- a/drivers/staging/comedi/drivers/ii_pci20kc.c
+++ b/drivers/staging/comedi/drivers/ii_pci20kc.c
@@ -144,7 +144,7 @@ static void __iomem *ii20k_module_iobase(struct comedi_device *dev,
 {
 	struct ii20k_private *devpriv = dev->private;
 
-	return devpriv->ioaddr + (s->index + 1) * II20K_MOD_OFFSET;
+	return devpriv->ioaddr + (s->index * II20K_MOD_OFFSET);
 }
 
 static int ii20k_ao_insn_read(struct comedi_device *dev,
@@ -283,7 +283,7 @@ static int ii20k_ai_insn_read(struct comedi_device *dev,
 static void ii20k_dio_config(struct comedi_device *dev,
 			     struct comedi_subdevice *s)
 {
-	struct ii20k_private *devpriv = dev->private;
+	void __iomem *iobase = ii20k_module_iobase(dev, s);
 	unsigned char ctrl01 = 0;
 	unsigned char ctrl23 = 0;
 	unsigned char dir_ena = 0;
@@ -340,9 +340,9 @@ static void ii20k_dio_config(struct comedi_device *dev,
 	ctrl23 |= II20K_CTRL23_SET;
 
 	/* order is important */
-	writeb(ctrl01, devpriv->ioaddr + II20K_CTRL01_REG);
-	writeb(ctrl23, devpriv->ioaddr + II20K_CTRL23_REG);
-	writeb(dir_ena, devpriv->ioaddr + II20K_DIR_ENA_REG);
+	writeb(ctrl01, iobase + II20K_CTRL01_REG);
+	writeb(ctrl23, iobase + II20K_CTRL23_REG);
+	writeb(dir_ena, iobase + II20K_DIR_ENA_REG);
 }
 
 static int ii20k_dio_insn_config(struct comedi_device *dev,
@@ -386,7 +386,7 @@ static int ii20k_dio_insn_bits(struct comedi_device *dev,
 			       struct comedi_insn *insn,
 			       unsigned int *data)
 {
-	struct ii20k_private *devpriv = dev->private;
+	void __iomem *iobase = ii20k_module_iobase(dev, s);
 	unsigned int mask = data[0] & s->io_bits;	/* outputs only */
 	unsigned int bits = data[1];
 
@@ -396,22 +396,22 @@ static int ii20k_dio_insn_bits(struct comedi_device *dev,
 
 		if (mask & 0x000000ff)
 			writeb((s->state >> 0) & 0xff,
-			       devpriv->ioaddr + II20K_DIO0_REG);
+			       iobase + II20K_DIO0_REG);
 		if (mask & 0x0000ff00)
 			writeb((s->state >> 8) & 0xff,
-			       devpriv->ioaddr + II20K_DIO1_REG);
+			       iobase + II20K_DIO1_REG);
 		if (mask & 0x00ff0000)
 			writeb((s->state >> 16) & 0xff,
-			       devpriv->ioaddr + II20K_DIO2_REG);
+			       iobase + II20K_DIO2_REG);
 		if (mask & 0xff000000)
 			writeb((s->state >> 24) & 0xff,
-			       devpriv->ioaddr + II20K_DIO3_REG);
+			       iobase + II20K_DIO3_REG);
 	}
 
-	data[1] = readb(devpriv->ioaddr + II20K_DIO0_REG);
-	data[1] |= readb(devpriv->ioaddr + II20K_DIO1_REG) << 8;
-	data[1] |= readb(devpriv->ioaddr + II20K_DIO2_REG) << 16;
-	data[1] |= readb(devpriv->ioaddr + II20K_DIO3_REG) << 24;
+	data[1] = readb(iobase + II20K_DIO0_REG);
+	data[1] |= readb(iobase + II20K_DIO1_REG) << 8;
+	data[1] |= readb(iobase + II20K_DIO2_REG) << 16;
+	data[1] |= readb(iobase + II20K_DIO3_REG) << 24;
 
 	return insn->n;
 }
@@ -487,7 +487,24 @@ static int ii20k_attach(struct comedi_device *dev,
 	if (ret)
 		return ret;
 
+	/* Digital I/O subdevice */
 	s = &dev->subdevices[0];
+	if (has_dio) {
+		s->type		= COMEDI_SUBD_DIO;
+		s->subdev_flags	= SDF_READABLE | SDF_WRITABLE;
+		s->n_chan	= 32;
+		s->maxdata	= 1;
+		s->range_table	= &range_digital;
+		s->insn_bits	= ii20k_dio_insn_bits;
+		s->insn_config	= ii20k_dio_insn_config;
+
+		/* default all channels to input */
+		ii20k_dio_config(dev, s);
+	} else {
+		s->type = COMEDI_SUBD_UNUSED;
+	}
+
+	s = &dev->subdevices[1];
 	if (id & II20K_ID_MOD1_EMPTY) {
 		s->type = COMEDI_SUBD_UNUSED;
 	} else {
@@ -496,7 +513,7 @@ static int ii20k_attach(struct comedi_device *dev,
 			return ret;
 	}
 
-	s = &dev->subdevices[1];
+	s = &dev->subdevices[2];
 	if (id & II20K_ID_MOD2_EMPTY) {
 		s->type = COMEDI_SUBD_UNUSED;
 	} else {
@@ -505,7 +522,7 @@ static int ii20k_attach(struct comedi_device *dev,
 			return ret;
 	}
 
-	s = &dev->subdevices[2];
+	s = &dev->subdevices[3];
 	if (id & II20K_ID_MOD3_EMPTY) {
 		s->type = COMEDI_SUBD_UNUSED;
 	} else {
@@ -514,23 +531,6 @@ static int ii20k_attach(struct comedi_device *dev,
 			return ret;
 	}
 
-	/* Digital I/O subdevice */
-	s = &dev->subdevices[3];
-	if (has_dio) {
-		s->type		= COMEDI_SUBD_DIO;
-		s->subdev_flags	= SDF_READABLE | SDF_WRITABLE;
-		s->n_chan	= 32;
-		s->maxdata	= 1;
-		s->range_table	= &range_digital;
-		s->insn_bits	= ii20k_dio_insn_bits;
-		s->insn_config	= ii20k_dio_insn_config;
-
-		/* default all channels to input */
-		ii20k_dio_config(dev, s);
-	} else {
-		s->type = COMEDI_SUBD_UNUSED;
-	}
-
 	return 0;
 }
 
-- 
1.8.3.2

_______________________________________________
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