Linux-IIO Archive on lore.kernel.org
 help / Atom feed
From: Alexandru Ardelean <alexandru.ardelean@analog.com>
To: <linux-iio@vger.kernel.org>
Cc: Michael Hennerich <michael.hennerich@analog.com>,
	Alexandru Ardelean <alexandru.ardelean@analog.com>
Subject: [PATCH] iio: frequency: ad9523: add eeprom read/write verification
Date: Fri, 17 May 2019 17:19:38 +0300
Message-ID: <20190517141938.10315-1-alexandru.ardelean@analog.com> (raw)

From: Michael Hennerich <michael.hennerich@analog.com>

This change adds a basic verification of the EEPROM by writing a known
value to the customer version ID register, and reading it back.

This validates that the EEPROM & SPI communication are functioning
properly, and the device is ready to use.

Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
 drivers/iio/frequency/ad9523.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/drivers/iio/frequency/ad9523.c b/drivers/iio/frequency/ad9523.c
index 9b9eee27176c..dd159a1237f3 100644
--- a/drivers/iio/frequency/ad9523.c
+++ b/drivers/iio/frequency/ad9523.c
@@ -749,6 +749,30 @@ static int ad9523_reg_access(struct iio_dev *indio_dev,
 	return ret;
 }
 
+static int ad9523_verify_eeprom(struct iio_dev *indio_dev)
+{
+	int ret, id;
+
+	id = ad9523_read(indio_dev, AD9523_EEPROM_CUSTOMER_VERSION_ID);
+	if (id < 0)
+		return id;
+
+	ret = ad9523_write(indio_dev, AD9523_EEPROM_CUSTOMER_VERSION_ID, 0xAD95);
+	if (ret < 0)
+		return ret;
+
+	ret = ad9523_read(indio_dev, AD9523_EEPROM_CUSTOMER_VERSION_ID);
+	if (ret < 0)
+		return ret;
+
+	if (ret != 0xAD95) {
+		dev_err(&indio_dev->dev, "SPI Read Verify failed (0x%X)\n", ret);
+		return -EIO;
+	}
+
+	return ad9523_write(indio_dev, AD9523_EEPROM_CUSTOMER_VERSION_ID, id);
+}
+
 static const struct iio_info ad9523_info = {
 	.read_raw = &ad9523_read_raw,
 	.write_raw = &ad9523_write_raw,
@@ -780,6 +804,10 @@ static int ad9523_setup(struct iio_dev *indio_dev)
 	if (ret < 0)
 		return ret;
 
+	ret = ad9523_verify_eeprom(indio_dev);
+	if (ret < 0)
+		return ret;
+
 	/*
 	 * PLL1 Setup
 	 */
-- 
2.17.1


             reply index

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-17 14:19 Alexandru Ardelean [this message]
2019-05-18 10:00 ` Jonathan Cameron
2019-05-18 19:39   ` Alexandru Ardelean
2019-05-19  8:34     ` Jonathan Cameron

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190517141938.10315-1-alexandru.ardelean@analog.com \
    --to=alexandru.ardelean@analog.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=michael.hennerich@analog.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Linux-IIO Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-iio/0 linux-iio/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-iio linux-iio/ https://lore.kernel.org/linux-iio \
		linux-iio@vger.kernel.org linux-iio@archiver.kernel.org
	public-inbox-index linux-iio


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-iio


AGPL code for this site: git clone https://public-inbox.org/ public-inbox