Linux RTC
 help / color / mirror / Atom feed
From: "Michael Büsch" <m@bues.ch>
To: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Cc: Gregory Hermant <gregory.hermant@calao-systems.com>,
	rtc-linux@googlegroups.com
Subject: [rtc-linux] [PATCH 4/6] rtc-rv3029: Add i2c register update-bits helper
Date: Fri, 4 Mar 2016 19:56:11 +0100	[thread overview]
Message-ID: <20160304195611.48d5177b@wiggum> (raw)
In-Reply-To: <20160304195337.51439645@wiggum>

[-- Attachment #1: Type: text/plain, Size: 3503 bytes --]

This simplifies mask/set operations on device I2C registers.

Signed-off-by: Michael Buesch <m@bues.ch>
---
 drivers/rtc/rtc-rv3029c2.c | 54 ++++++++++++++++++++++++----------------------
 1 file changed, 28 insertions(+), 26 deletions(-)

diff --git a/drivers/rtc/rtc-rv3029c2.c b/drivers/rtc/rtc-rv3029c2.c
index 29cc871..769f73a 100644
--- a/drivers/rtc/rtc-rv3029c2.c
+++ b/drivers/rtc/rtc-rv3029c2.c
@@ -2,6 +2,7 @@
  * Micro Crystal RV-3029 rtc class driver
  *
  * Author: Gregory Hermant <gregory.hermant@calao-systems.com>
+ *         Michael Buesch <m@bues.ch>
  *
  * based on previously existing rtc class drivers
  *
@@ -143,6 +144,24 @@ rv3029_i2c_write_regs(struct i2c_client *client, u8 reg, u8 const buf[],
 }
 
 static int
+rv3029_i2c_update_bits(struct i2c_client *client, u8 reg, u8 mask, u8 set)
+{
+	u8 buf;
+	int ret;
+
+	ret = rv3029_i2c_read_regs(client, reg, &buf, 1);
+	if (ret < 0)
+		return ret;
+	buf &= mask;
+	buf |= set;
+	ret = rv3029_i2c_write_regs(client, reg, &buf, 1);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
+static int
 rv3029_i2c_get_sr(struct i2c_client *client, u8 *buf)
 {
 	int ret = rv3029_i2c_read_regs(client, RV3029_STATUS, buf, 1);
@@ -260,22 +279,13 @@ static int rv3029_rtc_i2c_alarm_set_irq(struct i2c_client *client,
 					int enable)
 {
 	int ret;
-	u8 buf[1];
-
-	/* enable AIE irq */
-	ret = rv3029_i2c_read_regs(client, RV3029_IRQ_CTRL, buf, 1);
-	if (ret < 0) {
-		dev_err(&client->dev, "can't read INT reg\n");
-		return ret;
-	}
-	if (enable)
-		buf[0] |= RV3029_IRQ_CTRL_AIE;
-	else
-		buf[0] &= ~RV3029_IRQ_CTRL_AIE;
 
-	ret = rv3029_i2c_write_regs(client, RV3029_IRQ_CTRL, buf, 1);
+	/* enable/disable AIE irq */
+	ret = rv3029_i2c_update_bits(client, RV3029_IRQ_CTRL,
+				     (u8)~RV3029_IRQ_CTRL_AIE,
+				     (enable ? RV3029_IRQ_CTRL_AIE : 0));
 	if (ret < 0) {
-		dev_err(&client->dev, "can't set INT reg\n");
+		dev_err(&client->dev, "can't update INT reg\n");
 		return ret;
 	}
 
@@ -316,20 +326,11 @@ static int rv3029_rtc_i2c_set_alarm(struct i2c_client *client,
 		return ret;
 
 	if (alarm->enabled) {
-		u8 buf[1];
-
 		/* clear AF flag */
-		ret = rv3029_i2c_read_regs(client, RV3029_IRQ_FLAGS,
-					   buf, 1);
-		if (ret < 0) {
-			dev_err(&client->dev, "can't read alarm flag\n");
-			return ret;
-		}
-		buf[0] &= ~RV3029_IRQ_FLAGS_AF;
-		ret = rv3029_i2c_write_regs(client, RV3029_IRQ_FLAGS,
-					    buf, 1);
+		ret = rv3029_i2c_update_bits(client, RV3029_IRQ_FLAGS,
+					     (u8)~RV3029_IRQ_FLAGS_AF, 0);
 		if (ret < 0) {
-			dev_err(&client->dev, "can't set alarm flag\n");
+			dev_err(&client->dev, "can't clear alarm flag\n");
 			return ret;
 		}
 		/* enable AIE irq */
@@ -454,5 +455,6 @@ static struct i2c_driver rv3029_driver = {
 module_i2c_driver(rv3029_driver);
 
 MODULE_AUTHOR("Gregory Hermant <gregory.hermant@calao-systems.com>");
+MODULE_AUTHOR("Michael Buesch <m@bues.ch>");
 MODULE_DESCRIPTION("Micro Crystal RV3029 RTC driver");
 MODULE_LICENSE("GPL");
-- 
2.7.0

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

  parent reply	other threads:[~2016-03-04 19:03 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-01 20:33 [rtc-linux] [PATCH] rtc-rv3029c2: Add trickle charger Michael Büsch
2016-03-01 21:36 ` [rtc-linux] " Alexandre Belloni
2016-03-01 21:54   ` Michael Büsch
2016-03-01 23:07     ` Alexandre Belloni
2016-03-02  6:26       ` Michael Büsch
2016-03-02 12:00         ` Alexandre Belloni
     [not found]           ` <20160304195337.51439645@wiggum>
2016-03-04 18:54             ` [rtc-linux] [PATCH 1/6] rtc-rv3029: Remove all 'C2' suffixes from identifiers Michael Büsch
2016-03-04 21:38               ` [rtc-linux] [PATCH v3 " Michael Büsch
2016-03-04 18:55             ` [rtc-linux] [PATCH 2/6] rtc-rv3029: Add "rv3029" I2C device id Michael Büsch
2016-03-04 21:39               ` [rtc-linux] [PATCH v3 " Michael Büsch
2016-03-04 18:55             ` [rtc-linux] [PATCH 3/6] rtc-rv3029: Add missing register definitions Michael Büsch
2016-03-04 21:39               ` [rtc-linux] [PATCH v3 " Michael Büsch
2016-03-04 18:56             ` Michael Büsch [this message]
2016-03-04 19:42               ` [rtc-linux] Re: [PATCH 4/6] rtc-rv3029: Add i2c register update-bits helper Alexandre Belloni
2016-03-04 19:46                 ` Michael Büsch
2016-03-04 21:40               ` [rtc-linux] [PATCH v3 " Michael Büsch
2016-03-04 18:56             ` [rtc-linux] [PATCH 5/6] rtc-rv3029: Add functions for EEPROM access Michael Büsch
2016-03-04 21:40               ` [rtc-linux] [PATCH v3 " Michael Büsch
2016-03-04 18:56             ` [rtc-linux] [PATCH 6/6] rtc-rv3029: Add device tree property for trickle charger Michael Büsch
2016-03-04 19:43               ` [rtc-linux] " Alexandre Belloni
2016-03-04 19:49                 ` Michael Büsch
2016-03-04 19:58                   ` Alexandre Belloni
2016-03-04 21:41               ` [rtc-linux] [PATCH v3 " Michael Büsch
2016-03-04 19:02           ` [rtc-linux] [PATCH 0/6] rtc-rv3029: Add " Michael Büsch
2016-03-04 19:39             ` [rtc-linux] " Alexandre Belloni
2016-03-04 21:36             ` [rtc-linux] [PATCH v3 " Michael Büsch
2016-03-05  5:23               ` [rtc-linux] " 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=20160304195611.48d5177b@wiggum \
    --to=m@bues.ch \
    --cc=alexandre.belloni@free-electrons.com \
    --cc=gregory.hermant@calao-systems.com \
    --cc=rtc-linux@googlegroups.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
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