staging: comedi: cb_pcidas: fix cb_pcidas_eeprom_insn_read()
The comedi core expects (*insn_read) operations to return insn->n data values. Refactor this function to work like the core expects. For aesthetics, nvram_read() and use the comedi_timeout() helper to handle the busy wait for the eeprom to be "ready". Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
73d38effd1
commit
16ded01b69
@ -466,44 +466,18 @@ static int cb_pcidas_ao_fifo_winsn(struct comedi_device *dev,
|
|||||||
return insn->n;
|
return insn->n;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int wait_for_nvram_ready(unsigned long s5933_base_addr)
|
static int cb_pcidas_eeprom_ready(struct comedi_device *dev,
|
||||||
{
|
struct comedi_subdevice *s,
|
||||||
static const int timeout = 1000;
|
struct comedi_insn *insn,
|
||||||
unsigned int i;
|
unsigned long context)
|
||||||
|
|
||||||
for (i = 0; i < timeout; i++) {
|
|
||||||
if ((inb(s5933_base_addr +
|
|
||||||
AMCC_OP_REG_MCSR_NVCMD) & MCSR_NV_BUSY)
|
|
||||||
== 0)
|
|
||||||
return 0;
|
|
||||||
udelay(1);
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int nvram_read(struct comedi_device *dev, unsigned int address,
|
|
||||||
u8 *data)
|
|
||||||
{
|
{
|
||||||
struct cb_pcidas_private *devpriv = dev->private;
|
struct cb_pcidas_private *devpriv = dev->private;
|
||||||
unsigned long iobase = devpriv->s5933_config;
|
unsigned int status;
|
||||||
|
|
||||||
if (wait_for_nvram_ready(iobase) < 0)
|
status = inb(devpriv->s5933_config + AMCC_OP_REG_MCSR_NVCMD);
|
||||||
return -ETIMEDOUT;
|
if ((status & MCSR_NV_BUSY) == 0)
|
||||||
|
return 0;
|
||||||
outb(MCSR_NV_ENABLE | MCSR_NV_LOAD_LOW_ADDR,
|
return -EBUSY;
|
||||||
iobase + AMCC_OP_REG_MCSR_NVCMD);
|
|
||||||
outb(address & 0xff, iobase + AMCC_OP_REG_MCSR_NVDATA);
|
|
||||||
outb(MCSR_NV_ENABLE | MCSR_NV_LOAD_HIGH_ADDR,
|
|
||||||
iobase + AMCC_OP_REG_MCSR_NVCMD);
|
|
||||||
outb((address >> 8) & 0xff, iobase + AMCC_OP_REG_MCSR_NVDATA);
|
|
||||||
outb(MCSR_NV_ENABLE | MCSR_NV_READ, iobase + AMCC_OP_REG_MCSR_NVCMD);
|
|
||||||
|
|
||||||
if (wait_for_nvram_ready(iobase) < 0)
|
|
||||||
return -ETIMEDOUT;
|
|
||||||
|
|
||||||
*data = inb(iobase + AMCC_OP_REG_MCSR_NVDATA);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cb_pcidas_eeprom_insn_read(struct comedi_device *dev,
|
static int cb_pcidas_eeprom_insn_read(struct comedi_device *dev,
|
||||||
@ -511,16 +485,38 @@ static int cb_pcidas_eeprom_insn_read(struct comedi_device *dev,
|
|||||||
struct comedi_insn *insn,
|
struct comedi_insn *insn,
|
||||||
unsigned int *data)
|
unsigned int *data)
|
||||||
{
|
{
|
||||||
u8 nvram_data;
|
struct cb_pcidas_private *devpriv = dev->private;
|
||||||
int retval;
|
unsigned int chan = CR_CHAN(insn->chanspec);
|
||||||
|
int ret;
|
||||||
|
int i;
|
||||||
|
|
||||||
retval = nvram_read(dev, CR_CHAN(insn->chanspec), &nvram_data);
|
for (i = 0; i < insn->n; i++) {
|
||||||
if (retval < 0)
|
/* make sure eeprom is ready */
|
||||||
return retval;
|
ret = comedi_timeout(dev, s, insn, cb_pcidas_eeprom_ready, 0);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
data[0] = nvram_data;
|
/* set address (chan) and read operation */
|
||||||
|
outb(MCSR_NV_ENABLE | MCSR_NV_LOAD_LOW_ADDR,
|
||||||
|
devpriv->s5933_config + AMCC_OP_REG_MCSR_NVCMD);
|
||||||
|
outb(chan & 0xff,
|
||||||
|
devpriv->s5933_config + AMCC_OP_REG_MCSR_NVDATA);
|
||||||
|
outb(MCSR_NV_ENABLE | MCSR_NV_LOAD_HIGH_ADDR,
|
||||||
|
devpriv->s5933_config + AMCC_OP_REG_MCSR_NVCMD);
|
||||||
|
outb((chan >> 8) & 0xff,
|
||||||
|
devpriv->s5933_config + AMCC_OP_REG_MCSR_NVDATA);
|
||||||
|
outb(MCSR_NV_ENABLE | MCSR_NV_READ,
|
||||||
|
devpriv->s5933_config + AMCC_OP_REG_MCSR_NVCMD);
|
||||||
|
|
||||||
return 1;
|
/* wait for data to be returned */
|
||||||
|
ret = comedi_timeout(dev, s, insn, cb_pcidas_eeprom_ready, 0);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
data[i] = inb(devpriv->s5933_config + AMCC_OP_REG_MCSR_NVDATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
return insn->n;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cb_pcidas_calib_write(struct comedi_device *dev,
|
static void cb_pcidas_calib_write(struct comedi_device *dev,
|
||||||
|
Reference in New Issue
Block a user