From 5f86288fc54865164e0439ea5d8b64d4ec1ad40e Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Thu, 20 Nov 2014 15:07:36 -0700 Subject: [PATCH] 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 Reviewed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- .../staging/comedi/drivers/ni_labpc_common.c | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/drivers/staging/comedi/drivers/ni_labpc_common.c b/drivers/staging/comedi/drivers/ni_labpc_common.c index 9d26aced0021..d89d5852aeea 100644 --- a/drivers/staging/comedi/drivers/ni_labpc_common.c +++ b/drivers/staging/comedi/drivers/ni_labpc_common.c @@ -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; } -- 2.34.1