staging: comedi: ni_labpc_common: use comedi_timeout() when writing to eeprom

Use the comedi_timeout() helper to wait for the eeprom to be ready to accept
writes and remove the timeout loop in labpc_eeprom_write().

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:
H Hartley Sweeten 2014-11-20 15:07:36 -07:00 committed by Greg Kroah-Hartman
parent 45c311c438
commit 5f86288fc5

View file

@ -1078,27 +1078,13 @@ static unsigned int labpc_eeprom_read_status(struct comedi_device *dev)
return value;
}
static int labpc_eeprom_write(struct comedi_device *dev,
unsigned int address, unsigned int value)
static void labpc_eeprom_write(struct comedi_device *dev,
unsigned int address, unsigned int value)
{
struct labpc_private *devpriv = dev->private;
const int write_enable_instruction = 0x6;
const int write_instruction = 0x2;
const int write_length = 8; /* 8 bit write lengths to eeprom */
const int write_in_progress_bit = 0x1;
const int timeout = 10000;
int i;
/* make sure there isn't already a write in progress */
for (i = 0; i < timeout; i++) {
if ((labpc_eeprom_read_status(dev) & write_in_progress_bit) ==
0)
break;
}
if (i == timeout) {
dev_err(dev->class_dev, "eeprom write timed out\n");
return -ETIME;
}
/* enable read/write to eeprom */
devpriv->cmd5 &= ~CMD5_EEPROMCS;
@ -1131,8 +1117,6 @@ static int labpc_eeprom_write(struct comedi_device *dev,
devpriv->cmd5 &= ~(CMD5_EEPROMCS | CMD5_WRTPRT);
udelay(1);
devpriv->write_byte(dev, devpriv->cmd5, CMD5_REG);
return 0;
}
/* writes to 8 bit calibration dacs */
@ -1183,6 +1167,20 @@ static int labpc_calib_insn_write(struct comedi_device *dev,
return insn->n;
}
static int labpc_eeprom_ready(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn,
unsigned long context)
{
unsigned int status;
/* make sure there isn't already a write in progress */
status = labpc_eeprom_read_status(dev);
if ((status & 0x1) == 0)
return 0;
return -EBUSY;
}
static int labpc_eeprom_insn_write(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn,
@ -1202,10 +1200,11 @@ static int labpc_eeprom_insn_write(struct comedi_device *dev,
if (insn->n > 0) {
unsigned int val = data[insn->n - 1];
ret = labpc_eeprom_write(dev, chan, val);
ret = comedi_timeout(dev, s, insn, labpc_eeprom_ready, 0);
if (ret)
return ret;
labpc_eeprom_write(dev, chan, val);
s->readback[chan] = val;
}