linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sakari Ailus <sakari.ailus@linux.intel.com>
To: linux-media@vger.kernel.org
Cc: devicetree@vger.kernel.org
Subject: [PATCH 3/7] smiapp: Refactor reading NVM page
Date: Tue, 24 Sep 2019 14:23:34 +0300	[thread overview]
Message-ID: <20190924112338.27180-4-sakari.ailus@linux.intel.com> (raw)
In-Reply-To: <20190924112338.27180-1-sakari.ailus@linux.intel.com>

Split out reading a single NVM page into a separate function.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/media/i2c/smiapp/smiapp-core.c | 83 ++++++++++++++------------
 1 file changed, 46 insertions(+), 37 deletions(-)

diff --git a/drivers/media/i2c/smiapp/smiapp-core.c b/drivers/media/i2c/smiapp/smiapp-core.c
index 13f7a6315f39c..5a136068f4d60 100644
--- a/drivers/media/i2c/smiapp/smiapp-core.c
+++ b/drivers/media/i2c/smiapp/smiapp-core.c
@@ -970,56 +970,65 @@ static int smiapp_update_mode(struct smiapp_sensor *sensor)
  * SMIA++ NVM handling
  *
  */
-static int smiapp_read_nvm(struct smiapp_sensor *sensor,
-			   unsigned char *nvm)
+
+static int smiapp_read_nvm_page(struct smiapp_sensor *sensor, u32 p, u8 *nvm)
 {
-	u32 i, s, p, np, v;
-	int rval = 0, rval2;
+	unsigned int i;
+	int rval;
 
-	np = sensor->nvm_size / SMIAPP_NVM_PAGE_SIZE;
-	for (p = 0; p < np; p++) {
-		rval = smiapp_write(
+	rval = smiapp_write(sensor,
+			    SMIAPP_REG_U8_DATA_TRANSFER_IF_1_PAGE_SELECT, p);
+	if (rval)
+		return rval;
+
+	rval = smiapp_write(sensor, SMIAPP_REG_U8_DATA_TRANSFER_IF_1_CTRL,
+			    SMIAPP_DATA_TRANSFER_IF_1_CTRL_EN);
+	if (rval)
+		return rval;
+
+	for (i = 1000; i > 0; i--) {
+		u32 s;
+
+		rval = smiapp_read(
 			sensor,
-			SMIAPP_REG_U8_DATA_TRANSFER_IF_1_PAGE_SELECT, p);
-		if (rval)
-			goto out;
+			SMIAPP_REG_U8_DATA_TRANSFER_IF_1_STATUS, &s);
 
-		rval = smiapp_write(sensor,
-				    SMIAPP_REG_U8_DATA_TRANSFER_IF_1_CTRL,
-				    SMIAPP_DATA_TRANSFER_IF_1_CTRL_EN);
 		if (rval)
-			goto out;
+			return rval;
 
-		for (i = 1000; i > 0; i--) {
-			rval = smiapp_read(
-				sensor,
-				SMIAPP_REG_U8_DATA_TRANSFER_IF_1_STATUS, &s);
+		if (s & SMIAPP_DATA_TRANSFER_IF_1_STATUS_RD_READY)
+			break;
+	}
+	if (!i)
+		return -ETIMEDOUT;
 
-			if (rval)
-				goto out;
+	for (i = 0; i < SMIAPP_NVM_PAGE_SIZE; i++) {
+		u32 v;
 
-			if (s & SMIAPP_DATA_TRANSFER_IF_1_STATUS_RD_READY)
-				break;
+		rval = smiapp_read(sensor,
+				   SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_0 + i,
+				   &v);
+		if (rval)
+			return rval;
 
-		}
-		if (!i) {
-			rval = -ETIMEDOUT;
-			goto out;
-		}
+		*nvm++ = v;
+	}
 
-		for (i = 0; i < SMIAPP_NVM_PAGE_SIZE; i++) {
-			rval = smiapp_read(
-				sensor,
-				SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_0 + i,
-				&v);
-			if (rval)
-				goto out;
+	return 0;
+}
 
-			*nvm++ = v;
-		}
+static int smiapp_read_nvm(struct smiapp_sensor *sensor,
+			   unsigned char *nvm)
+{
+	u32 p, np;
+	int rval = 0, rval2;
+
+	np = sensor->nvm_size / SMIAPP_NVM_PAGE_SIZE;
+	for (p = 0; p < np && !rval; p++) {
+		rval = smiapp_read_nvm_page(sensor, p, nvm);
+		nvm += SMIAPP_NVM_PAGE_SIZE;
 	}
 
-out:
 	rval2 = smiapp_write(sensor, SMIAPP_REG_U8_DATA_TRANSFER_IF_1_CTRL, 0);
 	if (rval < 0)
 		return rval;
-- 
2.20.1


  parent reply	other threads:[~2019-09-24 11:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-24 11:23 [PATCH 0/7] SMIA NVM handling improvements Sakari Ailus
2019-09-24 11:23 ` [PATCH 1/7] smiapp: Use the BIT macro where appropriate, remove useless definition Sakari Ailus
2019-09-24 11:23 ` [PATCH 2/7] smiapp: Fix error handling at NVM reading Sakari Ailus
2019-09-24 11:23 ` Sakari Ailus [this message]
2019-09-24 11:23 ` [PATCH 4/7] smiapp: Add definitions for data transfer if capability bits Sakari Ailus
2019-09-24 11:23 ` [PATCH 5/7] smiapp: Don't poll for NVM ready on devices that don't need it Sakari Ailus
2019-09-24 11:23 ` [PATCH 6/7] smiapp: Support probing NVM size Sakari Ailus
2019-09-24 11:23 ` [PATCH 7/7] dt-bindings: smia: Remove documentation of nokia,nvm-size Sakari Ailus
2019-10-02 14:19   ` Rob Herring

Reply instructions:

You may reply publicly 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=20190924112338.27180-4-sakari.ailus@linux.intel.com \
    --to=sakari.ailus@linux.intel.com \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).