linux-rtc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Kevin P. Fleming" <kevin+linux@km6g.us>
To: linux-rtc@vger.kernel.org, devicetree@vger.kernel.org
Cc: "Kevin P. Fleming" <kevin+linux@km6g.us>,
	Alessandro Zummo <a.zummo@towertech.it>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	Rob Herring <robh+dt@kernel.org>
Subject: [PATCH 3/3 v3] rtc: abx80x: Add support for autocalibration filter capacitor
Date: Mon, 15 Jun 2020 06:51:14 -0400	[thread overview]
Message-ID: <20200615105113.57770-3-kevin+linux@km6g.us> (raw)
In-Reply-To: <20200615105113.57770-1-kevin+linux@km6g.us>

All of the parts supported by this driver can make use of a
small capacitor to improve the accuracy of the autocalibration
process for their RC oscillators. If a capacitor is connected,
a configuration register must be set to enable its use, so a
new Device Tree property has been added for that purpose.

Signed-off-by: Kevin P. Fleming <kevin+linux@km6g.us>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
Cc: Rob Herring <robh+dt@kernel.org>
To: linux-rtc@vger.kernel.org
To: devicetree@vger.kernel.org
---
v3: corrected failure to initialize variable
 drivers/rtc/rtc-abx80x.c | 36 +++++++++++++++++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/drivers/rtc/rtc-abx80x.c b/drivers/rtc/rtc-abx80x.c
index daa6f27040e61..1b428fe2029ef 100644
--- a/drivers/rtc/rtc-abx80x.c
+++ b/drivers/rtc/rtc-abx80x.c
@@ -77,6 +77,10 @@
 #define ABX8XX_CFG_KEY_OSC	0xa1
 #define ABX8XX_CFG_KEY_MISC	0x9d
 
+#define ABX8XX_REG_AFCTRL	0x26
+#define ABX8XX_AUTOCAL_FILTER_DISABLE	0x00
+#define ABX8XX_AUTOCAL_FILTER_ENABLE	0xa0
+
 #define ABX8XX_REG_ID0		0x28
 
 #define ABX8XX_REG_OUT_CTRL	0x30
@@ -141,6 +145,26 @@ static int abx80x_is_rc_mode(struct i2c_client *client)
 	return (flags & ABX8XX_OSS_OMODE) ? 1 : 0;
 }
 
+static int abx80x_set_autocal_filter(struct i2c_client *client, u8 filter_cfg)
+{
+	int err;
+
+	/*
+	 * Write the configuration key register to enable access to the AFCTRL
+	 * register
+	 */
+	if (abx80x_write_config_key(client, ABX8XX_CFG_KEY_MISC) < 0)
+		return -EIO;
+
+	err = i2c_smbus_write_byte_data(client, ABX8XX_REG_AFCTRL, filter_cfg);
+	if (err < 0) {
+		dev_warn(&client->dev, "Unable to write autocal filter register\n");
+		return -EIO;
+	}
+
+	return 0;
+}
+
 static int abx80x_enable_trickle_charger(struct i2c_client *client,
 					 u8 trickle_cfg)
 {
@@ -678,7 +702,8 @@ static int abx80x_probe(struct i2c_client *client,
 {
 	struct device_node *np = client->dev.of_node;
 	struct abx80x_priv *priv;
-	int i, data, err, trickle_cfg = -EINVAL;
+	int i, data, err, filter_cfg;
+	int trickle_cfg = -EINVAL;
 	char buf[7];
 	unsigned int part = id->driver_data;
 	unsigned int partnumber;
@@ -824,6 +849,15 @@ static int abx80x_probe(struct i2c_client *client,
 			return err;
 	}
 
+	if (of_property_read_u32(np, "abracon,autocal_filter", &filter_cfg) == 0) {
+		err = abx80x_set_autocal_filter(client,
+						filter_cfg ?
+						ABX8XX_AUTOCAL_FILTER_ENABLE :
+						ABX8XX_AUTOCAL_FILTER_DISABLE);
+		if (err)
+			return err;
+	}
+
 	if (client->irq > 0) {
 		dev_info(&client->dev, "IRQ %d supplied\n", client->irq);
 		err = devm_request_threaded_irq(&client->dev, client->irq, NULL,
-- 
2.26.2


  parent reply	other threads:[~2020-06-15 10:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-15 10:51 [PATCH 1/3 v3] dt-bindings: abx80x: Add autocal-filter property Kevin P. Fleming
2020-06-15 10:51 ` [PATCH 2/3] rtc: abx80x: Add utility function for writing configuration key Kevin P. Fleming
2020-06-15 10:51 ` Kevin P. Fleming [this message]
2020-07-13 18:39 ` [PATCH 1/3 v3] dt-bindings: abx80x: Add autocal-filter property Rob Herring
2020-07-13 22:05   ` Kevin P. Fleming
2020-09-15 16:16     ` Alexandre Belloni
2020-07-26 19:40   ` 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=20200615105113.57770-3-kevin+linux@km6g.us \
    --to=kevin+linux@km6g.us \
    --cc=a.zummo@towertech.it \
    --cc=alexandre.belloni@bootlin.com \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=robh+dt@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).