linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: linux-rtc@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
	Alexandre Belloni <alexandre.belloni@bootlin.com>
Subject: [PATCH 06/16] rtc: rv3029: get rid of rv3029_get_sr
Date: Sat, 14 Dec 2019 23:10:12 +0100	[thread overview]
Message-ID: <20191214221022.622482-7-alexandre.belloni@bootlin.com> (raw)
In-Reply-To: <20191214221022.622482-1-alexandre.belloni@bootlin.com>

There is no point in having 2 indirections before calling regmap_read,
especially since rv3029_get_sr also changes the return value without any
good reason. Call regmap_read directly.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
 drivers/rtc/rtc-rv3029c2.c | 29 ++++++++++-------------------
 1 file changed, 10 insertions(+), 19 deletions(-)

diff --git a/drivers/rtc/rtc-rv3029c2.c b/drivers/rtc/rtc-rv3029c2.c
index 0e0a10cbfd67..f92fbb4db173 100644
--- a/drivers/rtc/rtc-rv3029c2.c
+++ b/drivers/rtc/rtc-rv3029c2.c
@@ -137,23 +137,13 @@ static int rv3029_write_regs(struct device *dev, u8 reg, u8 const buf[],
 	return regmap_bulk_write(rv3029->regmap, reg, buf, len);
 }
 
-static int rv3029_get_sr(struct device *dev, u8 *buf)
-{
-	int ret = rv3029_read_regs(dev, RV3029_STATUS, buf, 1);
-
-	if (ret < 0)
-		return -EIO;
-	dev_dbg(dev, "status = 0x%.2x (%d)\n", buf[0], buf[0]);
-	return 0;
-}
-
-static int rv3029_eeprom_busywait(struct device *dev)
+static int rv3029_eeprom_busywait(struct rv3029_data *rv3029)
 {
+	unsigned int sr;
 	int i, ret;
-	u8 sr;
 
 	for (i = 100; i > 0; i--) {
-		ret = rv3029_get_sr(dev, &sr);
+		ret = regmap_read(rv3029->regmap, RV3029_STATUS, &sr);
 		if (ret < 0)
 			break;
 		if (!(sr & RV3029_STATUS_EEBUSY))
@@ -161,7 +151,7 @@ static int rv3029_eeprom_busywait(struct device *dev)
 		usleep_range(1000, 10000);
 	}
 	if (i <= 0) {
-		dev_err(dev, "EEPROM busy wait timeout.\n");
+		dev_err(rv3029->dev, "EEPROM busy wait timeout.\n");
 		return -ETIMEDOUT;
 	}
 
@@ -181,11 +171,11 @@ static int rv3029_eeprom_exit(struct device *dev)
 static int rv3029_eeprom_enter(struct device *dev)
 {
 	struct rv3029_data *rv3029 = dev_get_drvdata(dev);
+	unsigned int sr;
 	int ret;
-	u8 sr;
 
 	/* Check whether we are in the allowed voltage range. */
-	ret = rv3029_get_sr(dev, &sr);
+	ret = regmap_read(rv3029->regmap, RV3029_STATUS, &sr);
 	if (ret < 0)
 		return ret;
 	if (sr & (RV3029_STATUS_VLOW1 | RV3029_STATUS_VLOW2)) {
@@ -198,7 +188,7 @@ static int rv3029_eeprom_enter(struct device *dev)
 		if (ret < 0)
 			return ret;
 		usleep_range(1000, 10000);
-		ret = rv3029_get_sr(dev, &sr);
+		ret = regmap_read(rv3029->regmap, RV3029_STATUS, &sr);
 		if (ret < 0)
 			return ret;
 		if (sr & (RV3029_STATUS_VLOW1 | RV3029_STATUS_VLOW2)) {
@@ -215,7 +205,7 @@ static int rv3029_eeprom_enter(struct device *dev)
 		return ret;
 
 	/* Wait for any previous eeprom accesses to finish. */
-	ret = rv3029_eeprom_busywait(dev);
+	ret = rv3029_eeprom_busywait(rv3029);
 	if (ret < 0)
 		rv3029_eeprom_exit(dev);
 
@@ -243,6 +233,7 @@ static int rv3029_eeprom_read(struct device *dev, u8 reg,
 static int rv3029_eeprom_write(struct device *dev, u8 reg,
 			       u8 const buf[], size_t len)
 {
+	struct rv3029_data *rv3029 = dev_get_drvdata(dev);
 	int ret, err;
 	size_t i;
 	u8 tmp;
@@ -260,7 +251,7 @@ static int rv3029_eeprom_write(struct device *dev, u8 reg,
 			if (ret < 0)
 				break;
 		}
-		ret = rv3029_eeprom_busywait(dev);
+		ret = rv3029_eeprom_busywait(rv3029);
 		if (ret < 0)
 			break;
 	}
-- 
2.23.0


  parent reply	other threads:[~2019-12-14 22:11 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-14 22:10 [PATCH 00/16] rtc: rv3029: cleanup and features Alexandre Belloni
2019-12-14 22:10 ` [PATCH 01/16] rtc: rv3029: use proper name for the driver Alexandre Belloni
2019-12-14 22:10 ` [PATCH 02/16] rtc: rv3029: let regmap validate the register ranges Alexandre Belloni
2019-12-14 22:10 ` [PATCH 03/16] rtc: rv3029: remove open coded regmap_update_bits Alexandre Belloni
2019-12-14 22:10 ` [PATCH 04/16] rtc: rv3029: remove race condition when update STATUS Alexandre Belloni
2019-12-14 22:10 ` [PATCH 05/16] rtc: rv3029: avoid reading the status register uselessly Alexandre Belloni
2019-12-14 22:10 ` Alexandre Belloni [this message]
2019-12-14 22:10 ` [PATCH 07/16] rtc: rv3029: simplify rv3029_alarm_irq_enable Alexandre Belloni
2019-12-14 22:10 ` [PATCH 08/16] rtc: rv3029: simplify rv3029_set_alarm Alexandre Belloni
2019-12-14 22:10 ` [PATCH 09/16] rtc: rv3029: drop rv3029_read_regs and rv3029_write_regs Alexandre Belloni
2019-12-14 22:10 ` [PATCH 10/16] rtc: rv3029: add RTC_VL_READ and RTC_VL_CLEAR support Alexandre Belloni
2019-12-14 22:10 ` [PATCH 11/16] rtc: rv3029: correctly handle PON and VLOW2 Alexandre Belloni
2019-12-14 22:10 ` [PATCH 12/16] rtc: rv3029: convert to devm_rtc_allocate_device Alexandre Belloni
2019-12-14 22:10 ` [PATCH 13/16] rtc: rv3029: let the core handle rtc range Alexandre Belloni
2019-12-14 22:10 ` [PATCH 14/16] rtc: rv3029: remove useless error messages Alexandre Belloni
2019-12-14 22:10 ` [PATCH 15/16] rtc: rv3029: annotate init and exit functions Alexandre Belloni
2019-12-14 22:10 ` [PATCH 16/16] rtc: rv3029: add nvram support Alexandre Belloni

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=20191214221022.622482-7-alexandre.belloni@bootlin.com \
    --to=alexandre.belloni@bootlin.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rtc@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).