Linux-RTC Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 1/2] dt-bindings: abx80x: Add autocal-filter property
@ 2020-05-30 12:48 Kevin P. Fleming
  2020-05-30 12:49 ` [PATCH 2/2] rtc: abx80x: Add support for autocalibration filter capacitor Kevin P. Fleming
  0 siblings, 1 reply; 5+ messages in thread
From: Kevin P. Fleming @ 2020-05-30 12:48 UTC (permalink / raw)
  To: devicetree, linux-rtc
  Cc: Kevin P. Fleming, Alessandro Zummo, Alexandre Belloni, Rob Herring

Add a property to allow control of the autocalibration filter
capacitor.

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
---
 Documentation/devicetree/bindings/rtc/abracon,abx80x.txt | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/Documentation/devicetree/bindings/rtc/abracon,abx80x.txt b/Documentation/devicetree/bindings/rtc/abracon,abx80x.txt
index 2405e35a1bc0..ad5d59ed6f24 100644
--- a/Documentation/devicetree/bindings/rtc/abracon,abx80x.txt
+++ b/Documentation/devicetree/bindings/rtc/abracon,abx80x.txt
@@ -29,3 +29,9 @@ and valid to enable charging:
  - "abracon,tc-diode": should be "standard" (0.6V) or "schottky" (0.3V)
  - "abracon,tc-resistor": should be <0>, <3>, <6> or <11>. 0 disables the output
                           resistor, the other values are in kOhm.
+
+All of the devices can have a 47pf capacitor attached to increase the
+autocalibration accuracy of their RC oscillators. To enable usage of the
+capacitor the following property has to be defined:
+
+ - "abracon,autocal-filter"
-- 
2.26.2


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/2] rtc: abx80x: Add support for autocalibration filter capacitor
  2020-05-30 12:48 [PATCH 1/2] dt-bindings: abx80x: Add autocal-filter property Kevin P. Fleming
@ 2020-05-30 12:49 ` Kevin P. Fleming
  2020-06-10 15:22   ` Alexandre Belloni
  0 siblings, 1 reply; 5+ messages in thread
From: Kevin P. Fleming @ 2020-05-30 12:49 UTC (permalink / raw)
  To: devicetree, linux-rtc
  Cc: Kevin P. Fleming, Alessandro Zummo, Alexandre Belloni, Rob Herring

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
---
 drivers/rtc/rtc-abx80x.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/drivers/rtc/rtc-abx80x.c b/drivers/rtc/rtc-abx80x.c
index 3521d8e8dc38..be5a814e8c0b 100644
--- a/drivers/rtc/rtc-abx80x.c
+++ b/drivers/rtc/rtc-abx80x.c
@@ -76,6 +76,9 @@
 #define ABX8XX_CFG_KEY_OSC	0xa1
 #define ABX8XX_CFG_KEY_MISC	0x9d
 
+#define ABX8XX_REG_AFCTRL	0x26
+#define ABX8XX_AUTOCAL_FILTER_ENABLE	0xa0
+
 #define ABX8XX_REG_ID0		0x28
 
 #define ABX8XX_REG_OUT_CTRL	0x30
@@ -130,6 +133,31 @@ static int abx80x_is_rc_mode(struct i2c_client *client)
 	return (flags & ABX8XX_OSS_OMODE) ? 1 : 0;
 }
 
+static int abx80x_enable_autocal_filter(struct i2c_client *client)
+{
+	int err;
+
+	/*
+	 * Write the configuration key register to enable access to the AFCTRL
+	 * register
+	 */
+	err = i2c_smbus_write_byte_data(client, ABX8XX_REG_CFG_KEY,
+					ABX8XX_CFG_KEY_MISC);
+	if (err < 0) {
+		dev_err(&client->dev, "Unable to write configuration key\n");
+		return -EIO;
+	}
+
+	err = i2c_smbus_write_byte_data(client, ABX8XX_REG_AFCTRL,
+					ABX8XX_AUTOCAL_FILTER_ENABLE);
+	if (err < 0) {
+		dev_err(&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)
 {
@@ -825,6 +853,12 @@ static int abx80x_probe(struct i2c_client *client,
 			return err;
 	}
 
+	if (of_property_read_bool(np, "abracon,autocal_filter")) {
+		err = abx80x_enable_autocal_filter(client);
+		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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] rtc: abx80x: Add support for autocalibration filter capacitor
  2020-05-30 12:49 ` [PATCH 2/2] rtc: abx80x: Add support for autocalibration filter capacitor Kevin P. Fleming
@ 2020-06-10 15:22   ` Alexandre Belloni
  2020-06-12 11:55     ` Kevin P. Fleming
  0 siblings, 1 reply; 5+ messages in thread
From: Alexandre Belloni @ 2020-06-10 15:22 UTC (permalink / raw)
  To: Kevin P. Fleming; +Cc: devicetree, linux-rtc, Alessandro Zummo, Rob Herring

On 30/05/2020 08:49:00-0400, Kevin P. Fleming wrote:
> 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
> ---
>  drivers/rtc/rtc-abx80x.c | 34 ++++++++++++++++++++++++++++++++++
>  1 file changed, 34 insertions(+)
> 
> diff --git a/drivers/rtc/rtc-abx80x.c b/drivers/rtc/rtc-abx80x.c
> index 3521d8e8dc38..be5a814e8c0b 100644
> --- a/drivers/rtc/rtc-abx80x.c
> +++ b/drivers/rtc/rtc-abx80x.c
> @@ -76,6 +76,9 @@
>  #define ABX8XX_CFG_KEY_OSC	0xa1
>  #define ABX8XX_CFG_KEY_MISC	0x9d
>  
> +#define ABX8XX_REG_AFCTRL	0x26
> +#define ABX8XX_AUTOCAL_FILTER_ENABLE	0xa0
> +
>  #define ABX8XX_REG_ID0		0x28
>  
>  #define ABX8XX_REG_OUT_CTRL	0x30
> @@ -130,6 +133,31 @@ static int abx80x_is_rc_mode(struct i2c_client *client)
>  	return (flags & ABX8XX_OSS_OMODE) ? 1 : 0;
>  }
>  
> +static int abx80x_enable_autocal_filter(struct i2c_client *client)
> +{
> +	int err;
> +
> +	/*
> +	 * Write the configuration key register to enable access to the AFCTRL
> +	 * register
> +	 */
> +	err = i2c_smbus_write_byte_data(client, ABX8XX_REG_CFG_KEY,
> +					ABX8XX_CFG_KEY_MISC);
> +	if (err < 0) {
> +		dev_err(&client->dev, "Unable to write configuration key\n");
> +		return -EIO;
> +	}

I'd like to avoid having more error messages in the driver (and whole
subsystem). Can you move the ABX8XX_REG_CFG_KEY setting earlier in
abx80x_probe so you don't have to do it here and avoid duplication the
error message?

This would also make the separate function superfluous.

> +
> +	err = i2c_smbus_write_byte_data(client, ABX8XX_REG_AFCTRL,
> +					ABX8XX_AUTOCAL_FILTER_ENABLE);
> +	if (err < 0) {
> +		dev_err(&client->dev, "Unable to write autocal filter register\n");
> +		return -EIO;

The RTC can still work if this fails and the rror is transient, maybe
just warn and continue. It will be set on the next probe.


> +	}
> +
> +	return 0;
> +}
> +
>  static int abx80x_enable_trickle_charger(struct i2c_client *client,
>  					 u8 trickle_cfg)
>  {
> @@ -825,6 +853,12 @@ static int abx80x_probe(struct i2c_client *client,
>  			return err;
>  	}
>  
> +	if (of_property_read_bool(np, "abracon,autocal_filter")) {
> +		err = abx80x_enable_autocal_filter(client);
> +		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
> 

-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] rtc: abx80x: Add support for autocalibration filter capacitor
  2020-06-10 15:22   ` Alexandre Belloni
@ 2020-06-12 11:55     ` Kevin P. Fleming
  2020-06-12 16:31       ` Alexandre Belloni
  0 siblings, 1 reply; 5+ messages in thread
From: Kevin P. Fleming @ 2020-06-12 11:55 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: Kevin P. Fleming, devicetree, linux-rtc, Alessandro Zummo, Rob Herring

On Wed, Jun 10, 2020 at 11:22 AM Alexandre Belloni
<alexandre.belloni@bootlin.com> wrote:
> I'd like to avoid having more error messages in the driver (and whole
> subsystem). Can you move the ABX8XX_REG_CFG_KEY setting earlier in
> abx80x_probe so you don't have to do it here and avoid duplication the
> error message?
>

Based on my reading of the app manual this won't work properly, as
setting the configuration key only allows writing to one register, and
then the key is reset. It has to be set to allow enabling the trickle
charger, and also to allow enabling the autocalibration filter
capacitor.

> The RTC can still work if this fails and the rror is transient, maybe
> just warn and continue. It will be set on the next probe.

Will fix in the next version of the patch.

Thanks for the review!

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] rtc: abx80x: Add support for autocalibration filter capacitor
  2020-06-12 11:55     ` Kevin P. Fleming
@ 2020-06-12 16:31       ` Alexandre Belloni
  0 siblings, 0 replies; 5+ messages in thread
From: Alexandre Belloni @ 2020-06-12 16:31 UTC (permalink / raw)
  To: Kevin P. Fleming; +Cc: devicetree, linux-rtc, Alessandro Zummo, Rob Herring

On 12/06/2020 07:55:53-0400, Kevin P. Fleming wrote:
> On Wed, Jun 10, 2020 at 11:22 AM Alexandre Belloni
> <alexandre.belloni@bootlin.com> wrote:
> > I'd like to avoid having more error messages in the driver (and whole
> > subsystem). Can you move the ABX8XX_REG_CFG_KEY setting earlier in
> > abx80x_probe so you don't have to do it here and avoid duplication the
> > error message?
> >
> 
> Based on my reading of the app manual this won't work properly, as
> setting the configuration key only allows writing to one register, and
> then the key is reset. It has to be set to allow enabling the trickle
> charger, and also to allow enabling the autocalibration filter
> capacitor.
> 

That is correct and I forgot about that. Can you move just setting the
key to a function as a preliminary patch?

> > The RTC can still work if this fails and the rror is transient, maybe
> > just warn and continue. It will be set on the next probe.
> 
> Will fix in the next version of the patch.
> 
> Thanks for the review!

-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, back to index

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-30 12:48 [PATCH 1/2] dt-bindings: abx80x: Add autocal-filter property Kevin P. Fleming
2020-05-30 12:49 ` [PATCH 2/2] rtc: abx80x: Add support for autocalibration filter capacitor Kevin P. Fleming
2020-06-10 15:22   ` Alexandre Belloni
2020-06-12 11:55     ` Kevin P. Fleming
2020-06-12 16:31       ` Alexandre Belloni

Linux-RTC Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-rtc/0 linux-rtc/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-rtc linux-rtc/ https://lore.kernel.org/linux-rtc \
		linux-rtc@vger.kernel.org
	public-inbox-index linux-rtc

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-rtc


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git