From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Cc: Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
Subject: [PATCH 2/9] mfd: da9063: added generic reg_update() function
Date: Thu, 12 Apr 2018 09:22:24 +0200 [thread overview]
Message-ID: <20180412072231.31207-3-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20180412072231.31207-1-s.hauer@pengutronix.de>
From: Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
Used to set or clear bits of a register.
The calculation of 'client' might look odd and unnecessary complicated.
But style prepares access to other register banks which is added in
following patches.
Signed-off-by: Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
Tested-by: Stefan Christ <s.christ@phytec.de>
Signed-off-by: Christian Hemp <c.hemp@phytec.de>
---
drivers/mfd/da9063.c | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/drivers/mfd/da9063.c b/drivers/mfd/da9063.c
index 74ad5bfdab..68b0723b61 100644
--- a/drivers/mfd/da9063.c
+++ b/drivers/mfd/da9063.c
@@ -52,6 +52,43 @@ struct da9063 {
#define DA9063_WATCHDOG 0x01
#define DA9063_SHUTDOWN 0x02
+static int da906x_reg_update(struct da9063 *priv, unsigned int reg,
+ uint8_t mask, uint8_t val)
+{
+ struct i2c_client *client;
+ uint8_t tmp;
+ int ret;
+
+ if (reg < 0x100)
+ client = priv->client;
+ else
+ /* this should/can not happen because function is usually
+ * called with a static register number; warn about it
+ * below */
+ client = NULL;
+
+ if (WARN_ON(!client))
+ return -EINVAL;
+
+ ret = i2c_read_reg(client, reg & 0xffu, &tmp, 1);
+ if (ret < 0) {
+ dev_warn(priv->dev, "failed to read reg %02x\n", reg);
+ return ret;
+ }
+
+ tmp &= ~mask;
+ tmp |= val;
+
+ ret = i2c_write_reg(client, reg & 0xffu, &tmp, 1);
+ if (ret < 0) {
+ dev_warn(priv->dev, "failed to write %02x into reg %02x\n",
+ tmp, reg);
+ return ret;
+ }
+
+ return 0;
+}
+
static int da9063_watchdog_ping(struct da9063 *priv)
{
int ret;
--
2.16.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2018-04-12 7:22 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-12 7:22 [PATCH 0/9] Dialog da9063 updates Sascha Hauer
2018-04-12 7:22 ` [PATCH 1/9] mfd: da9063: reset watchdog timer Sascha Hauer
2018-04-12 7:22 ` Sascha Hauer [this message]
2018-04-12 7:22 ` [PATCH 3/9] mfd: da9063: use da906x_reg_update() Sascha Hauer
2018-04-12 7:22 ` [PATCH 4/9] mfd: da9063: add device specific init function Sascha Hauer
2018-04-12 7:22 ` [PATCH 5/9] mfd: da9063: added of_device_id information Sascha Hauer
2018-04-12 7:22 ` [PATCH 6/9] mfd: da9063: read out and report device id Sascha Hauer
2018-04-12 7:22 ` [PATCH 7/9] mfd: da9063: update Kconfig for DA9062 Sascha Hauer
2018-04-12 7:22 ` [PATCH 8/9] ARM: i.MX: phycore-som: added and enabled DA9062 PMIC Sascha Hauer
2018-04-12 7:22 ` [PATCH 9/9] ARM: i.MX: pfla02: set priority of da9063 watchdog Sascha Hauer
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=20180412072231.31207-3-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=enrico.scholz@sigma-chemnitz.de \
/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