linux-rtc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] pcf85363: support for quartz-load-femtofarads
@ 2023-02-15  8:18 Javier Carrasco
  2023-02-15  8:18 ` [PATCH v2 1/2] dt-bindings: rtc: nxp,pcf8563: move pcf85263/pcf85363 to a dedicated binding Javier Carrasco
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Javier Carrasco @ 2023-02-15  8:18 UTC (permalink / raw)
  To: linux-rtc, devicetree, linux-kernel
  Cc: Alessandro Zummo, Alexandre Belloni, Rob Herring,
	Krzysztof Kozlowski, Michael Riesch, Javier Carrasco

These patches add support for the quartz-load-femtofarads property in
the pcf85363 device driver and new bindings for the pcf85263 and
pcf85363 Real Time Clocks.

The driver has been tested with a PCF85263ATT RTC and a CTS3-32.768-12.5-20
oscillator that needs a 12.5 pF load capacitor. With no property
support the 7 pF default value leads to at least 2 Hz output frequency
deviations, while setting the right value the deviation decreased to
0.15 Hz. These measurements were made with a high precision oscilloscope
(SIGLENT SDS5104X).

This modification does not affect existing designs where the
quartz-load-femtofarads is not defined because in that case the default
value is used.

Javier Carrasco (2):
  dt-bindings: rtc: nxp,pcf8563: move pcf85263/pcf85363 to a dedicated
    binding
  rtc: pcf85363: add support for the quartz-load-femtofarads property

 .../devicetree/bindings/rtc/nxp,pcf85363.yaml | 60 +++++++++++++++++++
 .../devicetree/bindings/rtc/nxp,pcf8563.yaml  |  2 -
 drivers/rtc/rtc-pcf85363.c                    | 37 +++++++++++-
 3 files changed, 96 insertions(+), 3 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/rtc/nxp,pcf85363.yaml

-- 
2.37.2


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

* [PATCH v2 1/2] dt-bindings: rtc: nxp,pcf8563: move pcf85263/pcf85363 to a dedicated binding
  2023-02-15  8:18 [PATCH v2 0/2] pcf85363: support for quartz-load-femtofarads Javier Carrasco
@ 2023-02-15  8:18 ` Javier Carrasco
  2023-02-15 20:22   ` Krzysztof Kozlowski
  2023-02-15  8:18 ` [PATCH v2 2/2] rtc: pcf85363: add support for the quartz-load-femtofarads property Javier Carrasco
  2023-02-22 14:36 ` [PATCH v2 0/2] pcf85363: support for quartz-load-femtofarads Alexandre Belloni
  2 siblings, 1 reply; 5+ messages in thread
From: Javier Carrasco @ 2023-02-15  8:18 UTC (permalink / raw)
  To: linux-rtc, devicetree, linux-kernel
  Cc: Alessandro Zummo, Alexandre Belloni, Rob Herring,
	Krzysztof Kozlowski, Michael Riesch, Javier Carrasco

These Real Time Clocks are managed by the rtc-pcf85363 device driver,
which now supports the quartz-load-femtofarads property.

Signed-off-by: Javier Carrasco <javier.carrasco@wolfvision.net>
---
v2:
  - create new bindings instead of adding conditional properties to an
    existing one.

 .../devicetree/bindings/rtc/nxp,pcf85363.yaml | 60 +++++++++++++++++++
 .../devicetree/bindings/rtc/nxp,pcf8563.yaml  |  2 -
 2 files changed, 60 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/rtc/nxp,pcf85363.yaml

diff --git a/Documentation/devicetree/bindings/rtc/nxp,pcf85363.yaml b/Documentation/devicetree/bindings/rtc/nxp,pcf85363.yaml
new file mode 100644
index 000000000000..52aa3e2091e9
--- /dev/null
+++ b/Documentation/devicetree/bindings/rtc/nxp,pcf85363.yaml
@@ -0,0 +1,60 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/rtc/nxp,pcf85363.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Philips PCF85263/PCF85363 Real Time Clock
+
+maintainers:
+  - Alexandre Belloni <alexandre.belloni@bootlin.com>
+
+allOf:
+  - $ref: rtc.yaml#
+
+properties:
+  compatible:
+    enum:
+      - nxp,pcf85263
+      - nxp,pcf85363
+
+  reg:
+    maxItems: 1
+
+  "#clock-cells":
+    const: 0
+
+  clock-output-names:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  quartz-load-femtofarads:
+    description:
+      The capacitive load of the quartz(x-tal).
+    enum: [6000, 7000, 12500]
+    default: 7000
+
+  start-year: true
+  wakeup-source: true
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        rtc@51 {
+            compatible = "nxp,pcf85363";
+            reg = <0x51>;
+            #clock-cells = <0>;
+            quartz-load-femtofarads = <12500>;
+        };
+    };
diff --git a/Documentation/devicetree/bindings/rtc/nxp,pcf8563.yaml b/Documentation/devicetree/bindings/rtc/nxp,pcf8563.yaml
index a98b72752349..22909a96123e 100644
--- a/Documentation/devicetree/bindings/rtc/nxp,pcf8563.yaml
+++ b/Documentation/devicetree/bindings/rtc/nxp,pcf8563.yaml
@@ -19,8 +19,6 @@ properties:
       - microcrystal,rv8564
       - nxp,pca8565
       - nxp,pcf8563
-      - nxp,pcf85263
-      - nxp,pcf85363
 
   reg:
     maxItems: 1
-- 
2.37.2


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

* [PATCH v2 2/2] rtc: pcf85363: add support for the quartz-load-femtofarads property
  2023-02-15  8:18 [PATCH v2 0/2] pcf85363: support for quartz-load-femtofarads Javier Carrasco
  2023-02-15  8:18 ` [PATCH v2 1/2] dt-bindings: rtc: nxp,pcf8563: move pcf85263/pcf85363 to a dedicated binding Javier Carrasco
@ 2023-02-15  8:18 ` Javier Carrasco
  2023-02-22 14:36 ` [PATCH v2 0/2] pcf85363: support for quartz-load-femtofarads Alexandre Belloni
  2 siblings, 0 replies; 5+ messages in thread
From: Javier Carrasco @ 2023-02-15  8:18 UTC (permalink / raw)
  To: linux-rtc, devicetree, linux-kernel
  Cc: Alessandro Zummo, Alexandre Belloni, Rob Herring,
	Krzysztof Kozlowski, Michael Riesch, Javier Carrasco

The quartz oscillator load capacitance of the PCF85263 and PCF85363 can
be adjusted to 6 pF, 7 pF (default) and 12.5 pF with the CL[1:0] bits in
the oscillator control register (address 25h).

Signed-off-by: Javier Carrasco <javier.carrasco@wolfvision.net>
---
v2:
  - simple assignment operator instead of |= for the "value" variable.

 drivers/rtc/rtc-pcf85363.c | 37 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/drivers/rtc/rtc-pcf85363.c b/drivers/rtc/rtc-pcf85363.c
index c05b722f0060..219fbca8c47f 100644
--- a/drivers/rtc/rtc-pcf85363.c
+++ b/drivers/rtc/rtc-pcf85363.c
@@ -101,6 +101,10 @@
 #define PIN_IO_INTA_OUT	2
 #define PIN_IO_INTA_HIZ	3
 
+#define OSC_CAP_SEL	GENMASK(1, 0)
+#define OSC_CAP_6000	0x01
+#define OSC_CAP_12500	0x02
+
 #define STOP_EN_STOP	BIT(0)
 
 #define RESET_CPR	0xa4
@@ -117,6 +121,32 @@ struct pcf85x63_config {
 	unsigned int num_nvram;
 };
 
+static int pcf85363_load_capacitance(struct pcf85363 *pcf85363, struct device_node *node)
+{
+	u32 load = 7000;
+	u8 value = 0;
+
+	of_property_read_u32(node, "quartz-load-femtofarads", &load);
+
+	switch (load) {
+	default:
+		dev_warn(&pcf85363->rtc->dev, "Unknown quartz-load-femtofarads value: %d. Assuming 7000",
+			 load);
+		fallthrough;
+	case 7000:
+		break;
+	case 6000:
+		value = OSC_CAP_6000;
+		break;
+	case 12500:
+		value = OSC_CAP_12500;
+		break;
+	}
+
+	return regmap_update_bits(pcf85363->regmap, CTRL_OSCILLATOR,
+				  OSC_CAP_SEL, value);
+}
+
 static int pcf85363_rtc_read_time(struct device *dev, struct rtc_time *tm)
 {
 	struct pcf85363 *pcf85363 = dev_get_drvdata(dev);
@@ -372,7 +402,7 @@ static int pcf85363_probe(struct i2c_client *client)
 			.reg_write = pcf85363_nvram_write,
 		},
 	};
-	int ret, i;
+	int ret, i, err;
 
 	if (data)
 		config = data;
@@ -394,6 +424,11 @@ static int pcf85363_probe(struct i2c_client *client)
 	if (IS_ERR(pcf85363->rtc))
 		return PTR_ERR(pcf85363->rtc);
 
+	err = pcf85363_load_capacitance(pcf85363, client->dev.of_node);
+	if (err < 0)
+		dev_warn(&client->dev, "failed to set xtal load capacitance: %d",
+			 err);
+
 	pcf85363->rtc->ops = &rtc_ops;
 	pcf85363->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
 	pcf85363->rtc->range_max = RTC_TIMESTAMP_END_2099;
-- 
2.37.2


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

* Re: [PATCH v2 1/2] dt-bindings: rtc: nxp,pcf8563: move pcf85263/pcf85363 to a dedicated binding
  2023-02-15  8:18 ` [PATCH v2 1/2] dt-bindings: rtc: nxp,pcf8563: move pcf85263/pcf85363 to a dedicated binding Javier Carrasco
@ 2023-02-15 20:22   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 5+ messages in thread
From: Krzysztof Kozlowski @ 2023-02-15 20:22 UTC (permalink / raw)
  To: Javier Carrasco, linux-rtc, devicetree, linux-kernel
  Cc: Alessandro Zummo, Alexandre Belloni, Rob Herring,
	Krzysztof Kozlowski, Michael Riesch

On 15/02/2023 09:18, Javier Carrasco wrote:
> These Real Time Clocks are managed by the rtc-pcf85363 device driver,
> which now supports the quartz-load-femtofarads property.
> 
> Signed-off-by: Javier Carrasco <javier.carrasco@wolfvision.net>
> ---
> v2:
>   - create new bindings instead of adding conditional properties to an
>     existing one.
> 
>  .../devicetree/bindings/rtc/nxp,pcf85363.yaml | 60 +++++++++++++++++++
>  .../devicetree/bindings/rtc/nxp,pcf8563.yaml  |  2 -
>  2 files changed, 60 insertions(+), 2 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/rtc/nxp,pcf85363.yaml
> 
> diff --git a/Documentation/devicetree/bindings/rtc/nxp,pcf85363.yaml b/Documentation/devicetree/bindings/rtc/nxp,pcf85363.yaml
> new file mode 100644
> index 000000000000..52aa3e2091e9
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/rtc/nxp,pcf85363.yaml
> @@ -0,0 +1,60 @@
> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/rtc/nxp,pcf85363.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: Philips PCF85263/PCF85363 Real Time Clock
> +
> +maintainers:
> +  - Alexandre Belloni <alexandre.belloni@bootlin.com>
> +
> +allOf:
> +  - $ref: rtc.yaml#
> +
> +properties:
> +  compatible:
> +    enum:
> +      - nxp,pcf85263
> +      - nxp,pcf85363
> +
> +  reg:
> +    maxItems: 1
> +
> +  "#clock-cells":
> +    const: 0
> +
> +  clock-output-names:
> +    maxItems: 1
> +
> +  interrupts:
> +    maxItems: 1
> +
> +  quartz-load-femtofarads:
> +    description:
> +      The capacitive load of the quartz(x-tal).
> +    enum: [6000, 7000, 12500]
> +    default: 7000
> +
> +  start-year: true
> +  wakeup-source: true

You could drop these two and use "unevaluatedProperties: false" instead
of additionalProp - less coding and binding already will be prepared for
any new RTC common properties. But it is fine for me as is.

Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

Best regards,
Krzysztof


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

* Re: [PATCH v2 0/2] pcf85363: support for quartz-load-femtofarads
  2023-02-15  8:18 [PATCH v2 0/2] pcf85363: support for quartz-load-femtofarads Javier Carrasco
  2023-02-15  8:18 ` [PATCH v2 1/2] dt-bindings: rtc: nxp,pcf8563: move pcf85263/pcf85363 to a dedicated binding Javier Carrasco
  2023-02-15  8:18 ` [PATCH v2 2/2] rtc: pcf85363: add support for the quartz-load-femtofarads property Javier Carrasco
@ 2023-02-22 14:36 ` Alexandre Belloni
  2 siblings, 0 replies; 5+ messages in thread
From: Alexandre Belloni @ 2023-02-22 14:36 UTC (permalink / raw)
  To: linux-rtc, devicetree, linux-kernel, Javier Carrasco
  Cc: Alessandro Zummo, Rob Herring, Krzysztof Kozlowski, Michael Riesch


On Wed, 15 Feb 2023 09:18:13 +0100, Javier Carrasco wrote:
> These patches add support for the quartz-load-femtofarads property in
> the pcf85363 device driver and new bindings for the pcf85263 and
> pcf85363 Real Time Clocks.
> 
> The driver has been tested with a PCF85263ATT RTC and a CTS3-32.768-12.5-20
> oscillator that needs a 12.5 pF load capacitor. With no property
> support the 7 pF default value leads to at least 2 Hz output frequency
> deviations, while setting the right value the deviation decreased to
> 0.15 Hz. These measurements were made with a high precision oscilloscope
> (SIGLENT SDS5104X).
> 
> [...]

Applied, thanks!

[1/2] dt-bindings: rtc: nxp,pcf8563: move pcf85263/pcf85363 to a dedicated binding
      commit: 1b2f85a8bac67b9909f2ee4be1bc11548a7aeaf3
[2/2] rtc: pcf85363: add support for the quartz-load-femtofarads property
      commit: fd9a6a13949af81062f4cd04f2c1b28ca5311e71

Best regards,

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

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

end of thread, other threads:[~2023-02-22 14:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-15  8:18 [PATCH v2 0/2] pcf85363: support for quartz-load-femtofarads Javier Carrasco
2023-02-15  8:18 ` [PATCH v2 1/2] dt-bindings: rtc: nxp,pcf8563: move pcf85263/pcf85363 to a dedicated binding Javier Carrasco
2023-02-15 20:22   ` Krzysztof Kozlowski
2023-02-15  8:18 ` [PATCH v2 2/2] rtc: pcf85363: add support for the quartz-load-femtofarads property Javier Carrasco
2023-02-22 14:36 ` [PATCH v2 0/2] pcf85363: support for quartz-load-femtofarads Alexandre Belloni

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).