Commit 5f86288f authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman
Browse files

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: 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 45c311c4
Loading
Loading
Loading
Loading
+18 −19
Original line number Diff line number Diff line
@@ -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,
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;
	}