From: Antoni Pokusinski <apokusinski01@gmail.com>
To: alexandre.belloni@bootlin.com, robh@kernel.org,
krzk+dt@kernel.org, conor+dt@kernel.org
Cc: linux-rtc@vger.kernel.org, devicetree@vger.kernel.org,
Antoni Pokusinski <apokusinski01@gmail.com>
Subject: [PATCH 4/6] rtc: abx80x: replace read-modify-write pattern with regmap helpers
Date: Wed, 22 Jul 2026 21:58:12 +0200 [thread overview]
Message-ID: <20260722195814.298552-5-apokusinski01@gmail.com> (raw)
In-Reply-To: <20260722195814.298552-1-apokusinski01@gmail.com>
Before introducing the regmap usage in the driver, updating specific
bits of a register was performed using the read-modify-write pattern.
Now, the functions regmap_update_bits() and regmap_write_bits() can
be used to simplify the code.
Signed-off-by: Antoni Pokusinski <apokusinski01@gmail.com>
---
drivers/rtc/rtc-abx80x.c | 105 +++++++++++----------------------------
1 file changed, 28 insertions(+), 77 deletions(-)
diff --git a/drivers/rtc/rtc-abx80x.c b/drivers/rtc/rtc-abx80x.c
index e5ba821a6768..7761cb353994 100644
--- a/drivers/rtc/rtc-abx80x.c
+++ b/drivers/rtc/rtc-abx80x.c
@@ -222,7 +222,7 @@ static int abx80x_rtc_set_time(struct device *dev, struct rtc_time *tm)
{
struct abx80x_priv *priv = dev_get_drvdata(dev);
unsigned char buf[8];
- int err, flags;
+ int err;
if (tm->tm_year < 100)
return -EINVAL;
@@ -244,18 +244,11 @@ static int abx80x_rtc_set_time(struct device *dev, struct rtc_time *tm)
}
/* Clear the OF bit of Oscillator Status Register */
- err = regmap_read(priv->regmap, ABX8XX_REG_OSS, &flags);
+ err = regmap_update_bits(priv->regmap, ABX8XX_REG_OSS, ABX8XX_OSS_OF, 0);
if (err < 0)
- return err;
-
- err = regmap_write(priv->regmap, ABX8XX_REG_OSS,
- flags & ~ABX8XX_OSS_OF);
- if (err < 0) {
dev_err(dev, "Unable to write oscillator status register\n");
- return err;
- }
- return 0;
+ return err;
}
static irqreturn_t abx80x_handle_irq(int irq, void *dev_id)
@@ -352,7 +345,7 @@ static int abx80x_rtc_set_autocalibration(struct device *dev,
int autocalibration)
{
struct abx80x_priv *priv = dev_get_drvdata(dev);
- int retval, flags = 0;
+ int flags = 0;
if ((autocalibration != 0) && (autocalibration != 1024) &&
(autocalibration != 512)) {
@@ -360,10 +353,6 @@ static int abx80x_rtc_set_autocalibration(struct device *dev,
return -EINVAL;
}
- retval = regmap_read(priv->regmap, ABX8XX_REG_OSC, &flags);
- if (retval < 0)
- return retval;
-
if (autocalibration == 0) {
flags &= ~(ABX8XX_OSC_ACAL_512 | ABX8XX_OSC_ACAL_1024);
} else if (autocalibration == 1024) {
@@ -379,9 +368,9 @@ static int abx80x_rtc_set_autocalibration(struct device *dev,
if (abx80x_write_config_key(dev, ABX8XX_CFG_KEY_OSC) < 0)
return -EIO;
- retval = regmap_write(priv->regmap, ABX8XX_REG_OSC, flags);
-
- return retval;
+ return regmap_write_bits(priv->regmap, ABX8XX_REG_OSC,
+ ABX8XX_OSC_ACAL_1024 | ABX8XX_OSC_ACAL_512,
+ flags);
}
static int abx80x_rtc_get_autocalibration(struct device *dev)
@@ -443,7 +432,7 @@ static ssize_t oscillator_store(struct device *dev,
const char *buf, size_t count)
{
struct abx80x_priv *priv = dev_get_drvdata(dev->parent);
- int retval, flags, rc_mode = 0;
+ int retval, rc_mode = 0;
if (strncmp(buf, "rc", 2) == 0) {
rc_mode = 1;
@@ -454,24 +443,14 @@ static ssize_t oscillator_store(struct device *dev,
return -EINVAL;
}
- retval = regmap_read(priv->regmap, ABX8XX_REG_OSC, &flags);
- if (retval < 0)
- return retval;
-
- if (rc_mode == 0)
- flags &= ~(ABX8XX_OSC_OSEL);
- else
- flags |= (ABX8XX_OSC_OSEL);
-
/* Unlock write access on Oscillator Control register */
if (abx80x_write_config_key(dev->parent, ABX8XX_CFG_KEY_OSC) < 0)
return -EIO;
- retval = regmap_write(priv->regmap, ABX8XX_REG_OSC, flags);
- if (retval < 0) {
+ retval = regmap_write_bits(priv->regmap, ABX8XX_REG_OSC, ABX8XX_OSC_OSEL,
+ rc_mode == 0 ? 0 : (ABX8XX_OSC_OSEL));
+ if (retval < 0)
dev_err(dev, "Failed to write Oscillator Control register\n");
- return retval;
- }
return retval ? retval : count;
}
@@ -537,17 +516,8 @@ static int abx80x_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
return put_user(tmp, (unsigned int __user *)arg);
case RTC_VL_CLR:
- err = regmap_read(priv->regmap, ABX8XX_REG_STATUS, &status);
- if (err < 0)
- return err;
-
- status &= ~ABX8XX_STATUS_BLF;
-
- err = regmap_write(priv->regmap, ABX8XX_REG_STATUS, status);
- if (err < 0)
- return err;
-
- return 0;
+ return regmap_update_bits(priv->regmap, ABX8XX_REG_STATUS,
+ ABX8XX_STATUS_BLF, 0);
default:
return -ENOIOCTLCMD;
@@ -799,7 +769,7 @@ static int abx80x_probe(struct i2c_client *client)
struct regmap *regmap;
struct device_node *np = client->dev.of_node;
struct abx80x_priv *priv;
- int i, data, err, trickle_cfg = -EINVAL;
+ int i, err, trickle_cfg = -EINVAL;
char buf[7];
unsigned int part = (uintptr_t)i2c_get_match_data(client);
unsigned int partnumber;
@@ -846,14 +816,9 @@ static int abx80x_probe(struct i2c_client *client)
dev_info(&client->dev, "model %04x, revision %u.%u, lot %x, wafer %x, uid %x\n",
partnumber, majrev, minrev, lot, wafer, uid);
- err = regmap_read(regmap, ABX8XX_REG_CTRL1, &data);
- if (err < 0) {
- dev_err(&client->dev, "Unable to read control register\n");
- return -EIO;
- }
-
- err = regmap_write(regmap, ABX8XX_REG_CTRL1,
- (data & ~(ABX8XX_CTRL_12_24 | ABX8XX_CTRL_ARST)) | ABX8XX_CTRL_WRITE);
+ err = regmap_update_bits(regmap, ABX8XX_REG_CTRL1,
+ ABX8XX_CTRL_12_24 | ABX8XX_CTRL_ARST | ABX8XX_CTRL_WRITE,
+ ABX8XX_CTRL_WRITE);
if (err < 0) {
dev_err(&client->dev, "Unable to write control register\n");
return -EIO;
@@ -867,30 +832,10 @@ static int abx80x_probe(struct i2c_client *client)
* register is set. RV-1805-C3 datasheet indicates that
* the bit should be cleared in section 11h - Control2.
*/
- err = regmap_read(regmap, ABX8XX_REG_CTRL2, &data);
- if (err < 0) {
- dev_err(&client->dev,
- "Unable to read control2 register\n");
- return -EIO;
- }
-
- err = regmap_write(regmap, ABX8XX_REG_CTRL2,
- data & ~ABX8XX_CTRL2_RSVD);
- if (err < 0) {
- dev_err(&client->dev,
- "Unable to write control2 register\n");
- return -EIO;
- }
-
- /*
- * Avoid extra power leakage. The RV1805 uses smaller
- * 10pin package and the EXTI input is not present.
- * Disable it to avoid leakage.
- */
- err = regmap_read(regmap, ABX8XX_REG_OUT_CTRL, &data);
+ err = regmap_update_bits(regmap, ABX8XX_REG_CTRL2,
+ ABX8XX_CTRL2_RSVD, 0);
if (err < 0) {
- dev_err(&client->dev,
- "Unable to read output control register\n");
+ dev_err(&client->dev, "Unable to write control2 register\n");
return -EIO;
}
@@ -901,8 +846,14 @@ static int abx80x_probe(struct i2c_client *client)
if (abx80x_write_config_key(&client->dev, ABX8XX_CFG_KEY_MISC) < 0)
return -EIO;
- err = regmap_write(regmap, ABX8XX_REG_OUT_CTRL,
- data | ABX8XX_OUT_CTRL_EXDS);
+ /*
+ * Avoid extra power leakage. The RV1805 uses smaller
+ * 10pin package and the EXTI input is not present.
+ * Disable it to avoid leakage.
+ */
+ err = regmap_write_bits(regmap, ABX8XX_REG_OUT_CTRL,
+ ABX8XX_OUT_CTRL_EXDS,
+ ABX8XX_OUT_CTRL_EXDS);
if (err < 0) {
dev_err(&client->dev,
"Unable to write output control register\n");
--
2.55.0
next prev parent reply other threads:[~2026-07-22 20:00 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-22 19:58 [PATCH 0/6] rtc: abx80x: add support for ABX81X Antoni Pokusinski
2026-07-22 19:58 ` [PATCH 1/6] dt-bindings: rtc: abx80x: document ABX81X RTCs Antoni Pokusinski
2026-07-22 20:09 ` sashiko-bot
2026-07-22 19:58 ` [PATCH 2/6] rtc: abx80x: add irq to struct abx80x_priv Antoni Pokusinski
2026-07-22 20:13 ` sashiko-bot
2026-07-22 19:58 ` [PATCH 3/6] rtc: abx80x: use regmap instead of I2C specific API Antoni Pokusinski
2026-07-22 20:16 ` sashiko-bot
2026-07-22 19:58 ` Antoni Pokusinski [this message]
2026-07-22 20:11 ` [PATCH 4/6] rtc: abx80x: replace read-modify-write pattern with regmap helpers sashiko-bot
2026-07-22 19:58 ` [PATCH 5/6] rtc: abx80x: create abx80x_i2c_probe() Antoni Pokusinski
2026-07-22 20:10 ` sashiko-bot
2026-07-22 19:58 ` [PATCH 6/6] rtc: abx80x: add support for ABX81X Antoni Pokusinski
2026-07-22 20:09 ` sashiko-bot
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=20260722195814.298552-5-apokusinski01@gmail.com \
--to=apokusinski01@gmail.com \
--cc=alexandre.belloni@bootlin.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-rtc@vger.kernel.org \
--cc=robh@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