Commit f254029b authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

staging: comedi: cb_pcidda: refactor iobase addresses

This driver uses two iobase addresses, found in PCI bars 2 and 3.
Currently, the address in PCI bar 3 is saved in the comedi_device as
the 'iobase' and the one in PCI bar 2 is just passed to subdev_8255_init()
as the 'iobase' parameter.

Save the PCI bar 3 address in the private data as 'daqio' and the
address from PCI bar 2 in the comedi_device as the 'iobase'.

This will help with some cleanup of the 8255 module.
Signed-off-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: default avatarIan Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 49fca95c
......@@ -154,6 +154,7 @@ static const struct cb_pcidda_board cb_pcidda_boards[] = {
};
struct cb_pcidda_private {
unsigned long daqio;
/* bits last written to da calibration register 1 */
unsigned int dac_cal1_bits;
/* current range settings for output channels */
......@@ -164,13 +165,14 @@ struct cb_pcidda_private {
/* lowlevel read from eeprom */
static unsigned int cb_pcidda_serial_in(struct comedi_device *dev)
{
struct cb_pcidda_private *devpriv = dev->private;
unsigned int value = 0;
int i;
const int value_width = 16; /* number of bits wide values are */
for (i = 1; i <= value_width; i++) {
/* read bits most significant bit first */
if (inw_p(dev->iobase + DACALIBRATION1) & SERIAL_OUT_BIT)
if (inw_p(devpriv->daqio + DACALIBRATION1) & SERIAL_OUT_BIT)
value |= 1 << (value_width - i);
}
......@@ -190,7 +192,7 @@ static void cb_pcidda_serial_out(struct comedi_device *dev, unsigned int value,
devpriv->dac_cal1_bits |= SERIAL_IN_BIT;
else
devpriv->dac_cal1_bits &= ~SERIAL_IN_BIT;
outw_p(devpriv->dac_cal1_bits, dev->iobase + DACALIBRATION1);
outw_p(devpriv->dac_cal1_bits, devpriv->daqio + DACALIBRATION1);
}
}
......@@ -198,6 +200,7 @@ static void cb_pcidda_serial_out(struct comedi_device *dev, unsigned int value,
static unsigned int cb_pcidda_read_eeprom(struct comedi_device *dev,
unsigned int address)
{
struct cb_pcidda_private *devpriv = dev->private;
unsigned int i;
unsigned int cal2_bits;
unsigned int value;
......@@ -213,7 +216,7 @@ static unsigned int cb_pcidda_read_eeprom(struct comedi_device *dev,
/* deactivate caldacs (one caldac for every two channels) */
for (i = 0; i < max_num_caldacs; i++)
cal2_bits |= DESELECT_CALDAC_BIT(i);
outw_p(cal2_bits, dev->iobase + DACALIBRATION2);
outw_p(cal2_bits, devpriv->daqio + DACALIBRATION2);
/* tell eeprom we want to read */
cb_pcidda_serial_out(dev, read_instruction, instruction_length);
......@@ -224,7 +227,7 @@ static unsigned int cb_pcidda_read_eeprom(struct comedi_device *dev,
/* deactivate eeprom */
cal2_bits &= ~SELECT_EEPROM_BIT;
outw_p(cal2_bits, dev->iobase + DACALIBRATION2);
outw_p(cal2_bits, devpriv->daqio + DACALIBRATION2);
return value;
}
......@@ -234,6 +237,7 @@ static void cb_pcidda_write_caldac(struct comedi_device *dev,
unsigned int caldac, unsigned int channel,
unsigned int value)
{
struct cb_pcidda_private *devpriv = dev->private;
unsigned int cal2_bits;
unsigned int i;
/* caldacs use 3 bit channel specification */
......@@ -256,10 +260,10 @@ static void cb_pcidda_write_caldac(struct comedi_device *dev,
cal2_bits |= DESELECT_CALDAC_BIT(i);
/* activate the caldac we want */
cal2_bits &= ~DESELECT_CALDAC_BIT(caldac);
outw_p(cal2_bits, dev->iobase + DACALIBRATION2);
outw_p(cal2_bits, devpriv->daqio + DACALIBRATION2);
/* deactivate caldac */
cal2_bits |= DESELECT_CALDAC_BIT(caldac);
outw_p(cal2_bits, dev->iobase + DACALIBRATION2);
outw_p(cal2_bits, devpriv->daqio + DACALIBRATION2);
}
/* set caldacs to eeprom values for given channel and range */
......@@ -324,9 +328,9 @@ static int cb_pcidda_ao_insn_write(struct comedi_device *dev,
if (range > 2)
ctrl |= CB_DDA_DA_CTRL_UNIP;
outw(ctrl, dev->iobase + CB_DDA_DA_CTRL_REG);
outw(ctrl, devpriv->daqio + CB_DDA_DA_CTRL_REG);
outw(data[0], dev->iobase + CB_DDA_DA_DATA_REG(channel));
outw(data[0], devpriv->daqio + CB_DDA_DA_DATA_REG(channel));
return insn->n;
}
......@@ -338,7 +342,6 @@ static int cb_pcidda_auto_attach(struct comedi_device *dev,
const struct cb_pcidda_board *thisboard = NULL;
struct cb_pcidda_private *devpriv;
struct comedi_subdevice *s;
unsigned long iobase_8255;
int i;
int ret;
......@@ -356,8 +359,8 @@ static int cb_pcidda_auto_attach(struct comedi_device *dev,
ret = comedi_pci_enable(dev);
if (ret)
return ret;
dev->iobase = pci_resource_start(pcidev, 3);
iobase_8255 = pci_resource_start(pcidev, 2);
dev->iobase = pci_resource_start(pcidev, 2);
devpriv->daqio = pci_resource_start(pcidev, 3);
ret = comedi_alloc_subdevices(dev, 3);
if (ret)
......@@ -375,7 +378,7 @@ static int cb_pcidda_auto_attach(struct comedi_device *dev,
/* two 8255 digital io subdevices */
for (i = 0; i < 2; i++) {
s = &dev->subdevices[1 + i];
ret = subdev_8255_init(dev, s, NULL, iobase_8255 + (i * 4));
ret = subdev_8255_init(dev, s, NULL, dev->iobase + (i * 4));
if (ret)
return ret;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment