Skip to contentSkip to conversation

dt-bindings: clk: versaclock5: Add load capacitance properties

RFC In review Adam Ford 5 participants 17 messages Jan 6, 2021 – Jan 13, 2021

Subsystems (3)
lore
Share & tools
lore

Adam Ford

author
#0 lore raw

RFC 1/2 dt-bindings: clk: versaclock5: Add load capacitance properties

There are two registers which can set the load capacitance for XTAL1 and XTAL2. These are optional registers when using an external crystal. Update the bindings to support them.

---
 .../devicetree/bindings/clock/idt,versaclock5.yaml   | 12 ++++++++++++
 1 file changed, 12 insertions(+)
Documentation/devicetree/bindings/clock/idt,versaclock5.yaml +12 -0
index 2ac1131fd922..e5e55ffb266e 100644
@@ -59,6 +59,18 @@ properties:
     minItems: 1
     maxItems: 2
 
+  idt,xtal1-load-femtofarads:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    minimum: 9000
+    maximum: 25000
+    description: Optional loading capacitor for XTAL1
+
+  idt,xtal2-load-femtofarads:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    minimum: 9000
+    maximum: 25000
+    description: Optional loading capacitor for XTAL2
+
 patternProperties:
   "^OUT[1-4]$":
     type: object
Signature · 1 line
2.25.1
author
#1 lore raw

RFC 2/2 clk: vc5: Add support for optional load capacitance

There are two registers which can set the load capacitance for XTAL1 and XTAL2. These are optional registers when using an external crystal. Parse the device tree and set the corresponding registers accordingly.

---
 drivers/clk/clk-versaclock5.c | 64 +++++++++++++++++++++++++++++++++++
 1 file changed, 64 insertions(+)
drivers/clk/clk-versaclock5.c +64 -0
index 43db67337bc0..445abc3731fb 100644
@@ -759,6 +759,63 @@ static int vc5_update_power(struct device_node *np_output,
 	return 0;
 }
 
+static int vc5_map_cap_value(u32 femtofarads)
+{
+	int mapped_value;
+
+	/* The datasheet explicitly states 9000 - 25000 */
+	if ((femtofarads < 9000) || (femtofarads > 25000))
+		return -EINVAL;
+
+	/* The lowest target we can hit is 9430, so exit if it's less */
+	if (femtofarads < 9430)
+		return 0;
+
+	/*
+	 * According to VersaClock 6E Programming Guide, there are 6
+	 * bits which translate to 64 entries in XTAL registers 12 and
+	 * 13. Because bits 0 and 1 increase the capacitance the
+	 * same, some of the values can be repeated.  Plugging this
+	 * into a spreadsheet and generating a trendline, the output
+	 * equation becomes x = (y-9098.29) / 216.44, where 'y' is
+	 * the desired capacitance in femtofarads, and x is the value
+	 * of XTAL[5:0].
+	 * To help with rounding, do fixed point math
+	 */
+	femtofarads *= 100;
+	mapped_value = (femtofarads - 909829) / 21644;
+
+	/*
+	 * The datasheet states, the maximum capacitance is 25000,
+	 * but the programmer guide shows a max value is 22832,
+	 * so values higher values could overflow, so cap it.
+	 */
+	mapped_value = max(mapped_value/100, 0x3f);
+
+	return mapped_value;
+}
+static int vc5_update_cap_load(struct device_node *node, struct vc5_driver_data *vc5)
+{
+	u32 value, mapped_value;
+
+	if (!of_property_read_u32(node, "idt,xtal1-load-femtofarads", &value)) {
+		mapped_value = vc5_map_cap_value(value);
+		if (mapped_value < 0)
+			return mapped_value;
+
+		regmap_write(vc5->regmap, VC5_XTAL_X1_LOAD_CAP, (mapped_value << 2));
+	}
+
+	if (!of_property_read_u32(node, "idt,xtal2-load-femtofarads", &value)) {
+		mapped_value = vc5_map_cap_value(value);
+		if (mapped_value < 0)
+			return mapped_value;
+		regmap_write(vc5->regmap, VC5_XTAL_X2_LOAD_CAP, (mapped_value << 2));
+	}
+
+	return 0;
+}
+
 static int vc5_update_slew(struct device_node *np_output,
 			   struct vc5_out_data *clk_out)
 {
@@ -884,6 +941,13 @@ static int vc5_probe(struct i2c_client *client, const struct i2c_device_id *id)
 		return -EINVAL;
 	}
 
+	/* Configure Optional Loading Capacitance for external XTAL */
+	if (!(vc5->chip_info->flags & VC5_HAS_INTERNAL_XTAL)) {
+		ret = vc5_update_cap_load(client->dev.of_node, vc5);
+		if (ret)
+			goto err_clk_register;
+	}
+
 	init.name = kasprintf(GFP_KERNEL, "%pOFn.mux", client->dev.of_node);
 	init.ops = &vc5_mux_ops;
 	init.flags = 0;
Signature · 1 line
2.25.1
#2 lore raw

Re: [RFC 2/2] clk: vc5: Add support for optional load capacitance

[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]

Hi Adam,

[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on clk/clk-next]
[also build test WARNING on v5.11-rc2 next-20210104]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Adam-Ford/dt-bindings-clk-versaclock5-Add-load-capacitance-properties/20210107-014404
base:   https://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git clk-next
config: x86_64-randconfig-m001-20210106 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0

If you fix the issue, kindly add following tag as appropriate

New smatch warnings:
drivers/clk/clk-versaclock5.c:803 vc5_update_cap_load() warn: unsigned 'mapped_value' is never less than zero.

Old smatch warnings:
drivers/clk/clk-versaclock5.c:811 vc5_update_cap_load() warn: unsigned 'mapped_value' is never less than zero.

vim +/mapped_value +803 drivers/clk/clk-versaclock5.c

761
762 static int vc5_map_cap_value(u32 femtofarads)
763 {
764 int mapped_value;
765
766 /* The datasheet explicitly states 9000 - 25000 */
767 if ((femtofarads < 9000) || (femtofarads > 25000))
768 return -EINVAL;
769
770 /* The lowest target we can hit is 9430, so exit if it's less */
771 if (femtofarads < 9430)
772 return 0;
773
774 /*
775 * According to VersaClock 6E Programming Guide, there are 6
776 * bits which translate to 64 entries in XTAL registers 12 and
777 * 13. Because bits 0 and 1 increase the capacitance the
778 * same, some of the values can be repeated. Plugging this
779 * into a spreadsheet and generating a trendline, the output
780 * equation becomes x = (y-9098.29) / 216.44, where 'y' is
781 * the desired capacitance in femtofarads, and x is the value
782 * of XTAL[5:0].
783 * To help with rounding, do fixed point math
784 */
785 femtofarads *= 100;
786 mapped_value = (femtofarads - 909829) / 21644;
787
788 /*
789 * The datasheet states, the maximum capacitance is 25000,
790 * but the programmer guide shows a max value is 22832,
791 * so values higher values could overflow, so cap it.
792 */
793 mapped_value = max(mapped_value/100, 0x3f);
794
795 return mapped_value;
796 }
797 static int vc5_update_cap_load(struct device_node *node, struct vc5_driver_data *vc5)
798 {
799 u32 value, mapped_value;
800
801 if (!of_property_read_u32(node, "idt,xtal1-load-femtofarads", &value)) {
802 mapped_value = vc5_map_cap_value(value);

 > 803			if (mapped_value < 0)

804 return mapped_value;
805
806 regmap_write(vc5->regmap, VC5_XTAL_X1_LOAD_CAP, (mapped_value << 2));
807 }
808
809 if (!of_property_read_u32(node, "idt,xtal2-load-femtofarads", &value)) {
810 mapped_value = vc5_map_cap_value(value);
811 if (mapped_value < 0)
812 return mapped_value;
813 regmap_write(vc5->regmap, VC5_XTAL_X2_LOAD_CAP, (mapped_value << 2));
814 }
815
816 return 0;
817 }
818

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]

maintainer
#3 lore raw

Re: [RFC 2/2] clk: vc5: Add support for optional load capacitance

In reply to Adam Ford

Hi Adam,

Quoted 4 lines · Adam Ford

There are two registers which can set the load capacitance for XTAL1 and XTAL2. These are optional registers when using an external crystal. Parse the device tree and set the corresponding registers accordingly.

No need to repeat the first 2 sentences, they are already in patch 1.

Quoted 29 lines
---
 drivers/clk/clk-versaclock5.c | 64 +++++++++++++++++++++++++++++++++++
 1 file changed, 64 insertions(+)
drivers/clk/clk-versaclock5.c +15 -0
index 43db67337bc0..445abc3731fb 100644
@@ -759,6 +759,63 @@ static int vc5_update_power(struct device_node *np_output,
 	return 0;
 }
 
+static int vc5_map_cap_value(u32 femtofarads)
+{
+	int mapped_value;
+
+	/* The datasheet explicitly states 9000 - 25000 */
+	if ((femtofarads < 9000) || (femtofarads > 25000))
+		return -EINVAL;
+
+	/* The lowest target we can hit is 9430, so exit if it's less */
+	if (femtofarads < 9430)
+		return 0;
+
+	/*
+	 * According to VersaClock 6E Programming Guide, there are 6
+	 * bits which translate to 64 entries in XTAL registers 12 and

drivers/clk/clk-versaclock5.c static int vc5_update_power(struct device_node *np_output, · line 786

Quoted 10 lines
drivers/clk/clk-versaclock5.c +10 -0
+	 * 13. Because bits 0 and 1 increase the capacitance the
+	 * same, some of the values can be repeated.  Plugging this
+	 * into a spreadsheet and generating a trendline, the output
+	 * equation becomes x = (y-9098.29) / 216.44, where 'y' is
+	 * the desired capacitance in femtofarads, and x is the value
+	 * of XTAL[5:0].
+	 * To help with rounding, do fixed point math
+	 */
+	femtofarads *= 100;
+	mapped_value = (femtofarads - 909829) / 21644;

Thanks for the extensive comment, but I am confused. Not by your code which is very clean and readable, but by the chip documentation (disclaimer: I haven't read it in full depth).

The 5P49V6965 datasheet at page 17 clearly states capacitance can be increased in 0.5 pF steps. The "VersaClock 6E Family Register Descriptions and Programming Guide" at page 18 shows a table that allows 0.43 pF. Can you clarify how the thing works?

drivers/clk/clk-versaclock5.c static int vc5_update_power(struct device_node *np_output, · line 792

Quoted 6 lines
drivers/clk/clk-versaclock5.c +6 -0
+
+	/*
+	 * The datasheet states, the maximum capacitance is 25000,
+	 * but the programmer guide shows a max value is 22832,
+	 * so values higher values could overflow, so cap it.
+	 */

The 22832 limit is if you assume 0.43 pF steps. Assuming 0.5 pF steps leads to 25000. Now I am more confused than before.

drivers/clk/clk-versaclock5.c static int vc5_update_power(struct device_node *np_output, · line 793

Quoted 1 line
drivers/clk/clk-versaclock5.c +1 -0
+	mapped_value = max(mapped_value/100, 0x3f);

Uhm, min()?

Quoted 33 lines
drivers/clk/clk-versaclock5.c +25 -0
+
+	return mapped_value;
+}
+static int vc5_update_cap_load(struct device_node *node, struct vc5_driver_data *vc5)
+{
+	u32 value, mapped_value;
+
+	if (!of_property_read_u32(node, "idt,xtal1-load-femtofarads", &value)) {
+		mapped_value = vc5_map_cap_value(value);
+		if (mapped_value < 0)
+			return mapped_value;
+
+		regmap_write(vc5->regmap, VC5_XTAL_X1_LOAD_CAP, (mapped_value << 2));
+	}
+
+	if (!of_property_read_u32(node, "idt,xtal2-load-femtofarads", &value)) {
+		mapped_value = vc5_map_cap_value(value);
+		if (mapped_value < 0)
+			return mapped_value;
+		regmap_write(vc5->regmap, VC5_XTAL_X2_LOAD_CAP, (mapped_value << 2));
+	}
+
+	return 0;
+}
+
 static int vc5_update_slew(struct device_node *np_output,
 			   struct vc5_out_data *clk_out)
 {
@@ -884,6 +941,13 @@ static int vc5_probe(struct i2c_client *client, const struct i2c_device_id *id)
 		return -EINVAL;
 	}
 

drivers/clk/clk-versaclock5.c static int vc5_probe(struct i2c_client *client, const struct i2c_device_id *id) · line 953

Quoted 10 lines
drivers/clk/clk-versaclock5.c +7 -0
+	/* Configure Optional Loading Capacitance for external XTAL */
+	if (!(vc5->chip_info->flags & VC5_HAS_INTERNAL_XTAL)) {
+		ret = vc5_update_cap_load(client->dev.of_node, vc5);
+		if (ret)
+			goto err_clk_register;
+	}
+
 	init.name = kasprintf(GFP_KERNEL, "%pOFn.mux", client->dev.of_node);
 	init.ops = &vc5_mux_ops;
 	init.flags = 0;

Overall LGTM.

Signature · 1 line
Luca
author
#4 lore raw

Re: [RFC 2/2] clk: vc5: Add support for optional load capacitance

Quoted 10 lines · Luca Ceresoli

Hi Adam,

Quoted 4 lines · Adam Ford

There are two registers which can set the load capacitance for XTAL1 and XTAL2. These are optional registers when using an external crystal. Parse the device tree and set the corresponding registers accordingly.

No need to repeat the first 2 sentences, they are already in patch 1.

The reason I did that was because if someone does a git log on the individual file, they'd see the comment. While it's redundant not, it
might not be as obvious in the future when looking back. Not
everyone reviews the history of the binding, but the source files' git
logs usually have some value. However, if you want me to drop it or
rephrase it, I can do that.

Quoted 36 lines
Quoted 36 lines
---
 drivers/clk/clk-versaclock5.c | 64 +++++++++++++++++++++++++++++++++++
 1 file changed, 64 insertions(+)
drivers/clk/clk-versaclock5.c +21 -0
index 43db67337bc0..445abc3731fb 100644
@@ -759,6 +759,63 @@ static int vc5_update_power(struct device_node *np_output,
      return 0;
 }
 
+static int vc5_map_cap_value(u32 femtofarads)
+{
+     int mapped_value;
+
+     /* The datasheet explicitly states 9000 - 25000 */
+     if ((femtofarads < 9000) || (femtofarads > 25000))
+             return -EINVAL;
+
+     /* The lowest target we can hit is 9430, so exit if it's less */
+     if (femtofarads < 9430)
+             return 0;
+
+     /*
+      * According to VersaClock 6E Programming Guide, there are 6
+      * bits which translate to 64 entries in XTAL registers 12 and
+      * 13. Because bits 0 and 1 increase the capacitance the
+      * same, some of the values can be repeated.  Plugging this
+      * into a spreadsheet and generating a trendline, the output
+      * equation becomes x = (y-9098.29) / 216.44, where 'y' is
+      * the desired capacitance in femtofarads, and x is the value
+      * of XTAL[5:0].
Quoted 8 lines

drivers/clk/clk-versaclock5.c static int vc5_update_power(struct device_node *np_output, · line 786

Quoted 4 lines
drivers/clk/clk-versaclock5.c +4 -0
+      * To help with rounding, do fixed point math
+      */
+     femtofarads *= 100;
+     mapped_value = (femtofarads - 909829) / 21644;

Thanks for the extensive comment, but I am confused. Not by your code which is very clean and readable, but by the chip documentation (disclaimer: I haven't read it in full depth).

I was confused too since the datasheet and programmers manual differ a bit.

Quoted 5 lines

The 5P49V6965 datasheet at page 17 clearly states capacitance can be increased in 0.5 pF steps. The "VersaClock 6E Family Register Descriptions and Programming Guide" at page 18 shows a table that allows 0.43 pF. Can you clarify how the thing works?

I used the Versaclock 6E doc which is based on the following:

BIT 5 - Add 6.92pF
BIT 4 - Add 3.46pF
BIT 3 - Add 1.73pF
BIT 2 - Add 0.86pF
Bit 1 - Add 0.43pF
Bit 0 - Add 0.43pF

Because the Datasheet starts at 9pF, the math I used, assumes these numbers are added to 9pF.
Because the datasheet shows the increments are in .5pF increments, the 430nF seems close. The datasheet shows 9pF - 25pF and based on the programmer table, we could get close to 25pF by enabling all bits and adding 9pF, however the math doesn't quite hit 25pF.

For what it's worth I needed around 11.5pF, and with this patch, the hardware engineer said our ppm went from around 70 ppm to around 4ppm.

Quoted 10 lines

drivers/clk/clk-versaclock5.c static int vc5_update_power(struct device_node *np_output, · line 792

Quoted 7 lines
drivers/clk/clk-versaclock5.c +6 -0
+
+     /*
+      * The datasheet states, the maximum capacitance is 25000,
+      * but the programmer guide shows a max value is 22832,
+      * so values higher values could overflow, so cap it.
+      */

The 22832 limit is if you assume 0.43 pF steps. Assuming 0.5 pF steps leads to 25000. Now I am more confused than before.

I agree. It would be nice to get some clarification from Renesas.

Quoted 4 lines

drivers/clk/clk-versaclock5.c static int vc5_update_power(struct device_node *np_output, · line 793

Quoted 2 lines
drivers/clk/clk-versaclock5.c +1 -0
+     mapped_value = max(mapped_value/100, 0x3f);

Uhm, min()?

Oops! You're absolutely right.

Quoted 33 lines
Quoted 33 lines
drivers/clk/clk-versaclock5.c +25 -0
+
+     return mapped_value;
+}
+static int vc5_update_cap_load(struct device_node *node, struct vc5_driver_data *vc5)
+{
+     u32 value, mapped_value;
+
+     if (!of_property_read_u32(node, "idt,xtal1-load-femtofarads", &value)) {
+             mapped_value = vc5_map_cap_value(value);
+             if (mapped_value < 0)
+                     return mapped_value;
+
+             regmap_write(vc5->regmap, VC5_XTAL_X1_LOAD_CAP, (mapped_value << 2));
+     }
+
+     if (!of_property_read_u32(node, "idt,xtal2-load-femtofarads", &value)) {
+             mapped_value = vc5_map_cap_value(value);
+             if (mapped_value < 0)
+                     return mapped_value;
+             regmap_write(vc5->regmap, VC5_XTAL_X2_LOAD_CAP, (mapped_value << 2));
+     }
+
+     return 0;
+}
+
 static int vc5_update_slew(struct device_node *np_output,
                         struct vc5_out_data *clk_out)
 {
@@ -884,6 +941,13 @@ static int vc5_probe(struct i2c_client *client, const struct i2c_device_id *id)
              return -EINVAL;
      }
 
Quoted 13 lines

drivers/clk/clk-versaclock5.c static int vc5_probe(struct i2c_client *client, const struct i2c_device_id *id) · line 953

Quoted 11 lines
drivers/clk/clk-versaclock5.c +7 -0
+     /* Configure Optional Loading Capacitance for external XTAL */
+     if (!(vc5->chip_info->flags & VC5_HAS_INTERNAL_XTAL)) {
+             ret = vc5_update_cap_load(client->dev.of_node, vc5);
+             if (ret)
+                     goto err_clk_register;
+     }
+
      init.name = kasprintf(GFP_KERNEL, "%pOFn.mux", client->dev.of_node);
      init.ops = &vc5_mux_ops;
      init.flags = 0;

Overall LGTM.

Thanks!

adam

Quoted 3 lines

--
Luca

maintainer
#5 lore raw

Re: [RFC 2/2] clk: vc5: Add support for optional load capacitance

Hi Adam,

Quoted 10 lines · Adam Ford
Quoted 9 lines · Luca Ceresoli

Hi Adam,

Quoted 4 lines · Adam Ford

There are two registers which can set the load capacitance for XTAL1 and XTAL2. These are optional registers when using an external crystal. Parse the device tree and set the corresponding registers accordingly.

Quoted 8 lines
Quoted 1 line

No need to repeat the first 2 sentences, they are already in patch 1.

The reason I did that was because if someone does a git log on the individual file, they'd see the comment. While it's redundant not, it
might not be as obvious in the future when looking back. Not
everyone reviews the history of the binding, but the source files' git
logs usually have some value. However, if you want me to drop it or
rephrase it, I can do that.

Makes sense, I had never considered that before.

Quoted 53 lines
Quoted 21 lines
Quoted 21 lines
drivers/clk/clk-versaclock5.c +21 -0
+static int vc5_map_cap_value(u32 femtofarads)
+{
+     int mapped_value;
+
+     /* The datasheet explicitly states 9000 - 25000 */
+     if ((femtofarads < 9000) || (femtofarads > 25000))
+             return -EINVAL;
+
+     /* The lowest target we can hit is 9430, so exit if it's less */
+     if (femtofarads < 9430)
+             return 0;
+
+     /*
+      * According to VersaClock 6E Programming Guide, there are 6
+      * bits which translate to 64 entries in XTAL registers 12 and
+      * 13. Because bits 0 and 1 increase the capacitance the
+      * same, some of the values can be repeated.  Plugging this
+      * into a spreadsheet and generating a trendline, the output
+      * equation becomes x = (y-9098.29) / 216.44, where 'y' is
+      * the desired capacitance in femtofarads, and x is the value
+      * of XTAL[5:0].
Quoted 8 lines

drivers/clk/clk-versaclock5.c static int vc5_update_power(struct device_node *np_output, · line 786

Quoted 4 lines
drivers/clk/clk-versaclock5.c +4 -0
+      * To help with rounding, do fixed point math
+      */
+     femtofarads *= 100;
+     mapped_value = (femtofarads - 909829) / 21644;

Thanks for the extensive comment, but I am confused. Not by your code which is very clean and readable, but by the chip documentation (disclaimer: I haven't read it in full depth).

I was confused too since the datasheet and programmers manual differ a bit.

Quoted 5 lines

The 5P49V6965 datasheet at page 17 clearly states capacitance can be increased in 0.5 pF steps. The "VersaClock 6E Family Register Descriptions and Programming Guide" at page 18 shows a table that allows 0.43 pF. Can you clarify how the thing works?

I used the Versaclock 6E doc which is based on the following:

BIT 5 - Add 6.92pF
BIT 4 - Add 3.46pF
BIT 3 - Add 1.73pF
BIT 2 - Add 0.86pF
Bit 1 - Add 0.43pF
Bit 0 - Add 0.43pF

Because the Datasheet starts at 9pF, the math I used, assumes these numbers are added to 9pF.
Because the datasheet shows the increments are in .5pF increments, the 430nF seems close. The datasheet shows 9pF - 25pF and based on the programmer table, we could get close to 25pF by enabling all bits and adding 9pF, however the math doesn't quite hit 25pF.

Quoted 2 lines

For what it's worth I needed around 11.5pF, and with this patch, the hardware engineer said our ppm went from around 70 ppm to around 4ppm.

Did he measure what happens if you set the register according to the 0.5 pF interpretation? Does it improve? I understand the difference is probably olwer than the noise, but who knows.

Quoted 11 lines
Quoted 9 lines

drivers/clk/clk-versaclock5.c static int vc5_update_power(struct device_node *np_output, · line 792

Quoted 6 lines
drivers/clk/clk-versaclock5.c +6 -0
+
+     /*
+      * The datasheet states, the maximum capacitance is 25000,
+      * but the programmer guide shows a max value is 22832,
+      * so values higher values could overflow, so cap it.
+      */

The 22832 limit is if you assume 0.43 pF steps. Assuming 0.5 pF steps leads to 25000. Now I am more confused than before.

I agree. It would be nice to get some clarification from Renesas.

Definitely. Do you have access to some support from them? I don't think I have, but I can ask next week.

Regards.

Signature · 1 line
Luca
author
#6 lore raw

Re: [RFC 2/2] clk: vc5: Add support for optional load capacitance

Quoted 92 lines · Luca Ceresoli

Hi Adam,

Quoted 10 lines · Adam Ford
Quoted 9 lines · Luca Ceresoli

Hi Adam,

Quoted 4 lines · Adam Ford

There are two registers which can set the load capacitance for XTAL1 and XTAL2. These are optional registers when using an external crystal. Parse the device tree and set the corresponding registers accordingly.

Quoted 8 lines
Quoted 1 line

No need to repeat the first 2 sentences, they are already in patch 1.

The reason I did that was because if someone does a git log on the individual file, they'd see the comment. While it's redundant not, it
might not be as obvious in the future when looking back. Not
everyone reviews the history of the binding, but the source files' git
logs usually have some value. However, if you want me to drop it or
rephrase it, I can do that.

Makes sense, I had never considered that before.

Quoted 53 lines
Quoted 21 lines
Quoted 21 lines
drivers/clk/clk-versaclock5.c +21 -0
+static int vc5_map_cap_value(u32 femtofarads)
+{
+     int mapped_value;
+
+     /* The datasheet explicitly states 9000 - 25000 */
+     if ((femtofarads < 9000) || (femtofarads > 25000))
+             return -EINVAL;
+
+     /* The lowest target we can hit is 9430, so exit if it's less */
+     if (femtofarads < 9430)
+             return 0;
+
+     /*
+      * According to VersaClock 6E Programming Guide, there are 6
+      * bits which translate to 64 entries in XTAL registers 12 and
+      * 13. Because bits 0 and 1 increase the capacitance the
+      * same, some of the values can be repeated.  Plugging this
+      * into a spreadsheet and generating a trendline, the output
+      * equation becomes x = (y-9098.29) / 216.44, where 'y' is
+      * the desired capacitance in femtofarads, and x is the value
+      * of XTAL[5:0].
Quoted 8 lines

drivers/clk/clk-versaclock5.c static int vc5_update_power(struct device_node *np_output, · line 786

Quoted 4 lines
drivers/clk/clk-versaclock5.c +4 -0
+      * To help with rounding, do fixed point math
+      */
+     femtofarads *= 100;
+     mapped_value = (femtofarads - 909829) / 21644;

Thanks for the extensive comment, but I am confused. Not by your code which is very clean and readable, but by the chip documentation (disclaimer: I haven't read it in full depth).

I was confused too since the datasheet and programmers manual differ a bit.

Quoted 5 lines

The 5P49V6965 datasheet at page 17 clearly states capacitance can be increased in 0.5 pF steps. The "VersaClock 6E Family Register Descriptions and Programming Guide" at page 18 shows a table that allows 0.43 pF. Can you clarify how the thing works?

I used the Versaclock 6E doc which is based on the following:

BIT 5 - Add 6.92pF
BIT 4 - Add 3.46pF
BIT 3 - Add 1.73pF
BIT 2 - Add 0.86pF
Bit 1 - Add 0.43pF
Bit 0 - Add 0.43pF

Because the Datasheet starts at 9pF, the math I used, assumes these numbers are added to 9pF.
Because the datasheet shows the increments are in .5pF increments, the 430nF seems close. The datasheet shows 9pF - 25pF and based on the programmer table, we could get close to 25pF by enabling all bits and adding 9pF, however the math doesn't quite hit 25pF.

Quoted 2 lines

For what it's worth I needed around 11.5pF, and with this patch, the hardware engineer said our ppm went from around 70 ppm to around 4ppm.

Did he measure what happens if you set the register according to the 0.5 pF interpretation? Does it improve? I understand the difference is probably olwer than the noise, but who knows.

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
drivers/clk/clk-versaclock5.c +6 -0
+
+     /*
+      * The datasheet states, the maximum capacitance is 25000,
+      * but the programmer guide shows a max value is 22832,
+      * so values higher values could overflow, so cap it.
+      */
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

The 22832 limit is if you assume 0.43 pF steps. Assuming 0.5 pF steps leads to 25000. Now I am more confused than before.

I agree. It would be nice to get some clarification from Renesas.

Definitely. Do you have access to some support from them?

Luca,

We reached out to Renesas with the following questions:

1)
I'm seeing a discrepancy between the datasheet and programming guide we have for the Versaclock 6e in regard to the crystal load programming registers. The datasheet for the 5P49V6965A000NLGI indicates a 9pF minimum with 0.5pF steps, while the programming guide says that the lower two register bits both add 0.43pF, which would make the equation:

Ci = 9pF + 0.43pF * XTAL[5:1] instead of
Ci = 9pF + 0.5pF * XTAL[5:0] as is published in the datasheet.

2) The programming guide shows that the default setting is 01b, but the note says it's reserved, use D1 D0 = 00. Can you confirm that we should set switch mode to 00 instead of the default 01?

And we got the following answers:

1)
The first one with 0.43pF steps is the correct one. Ci = 9pF +
0.43pF * XTAL[5:1]
0.5pF steps was the design target. When measuring actual
silicon, we found 0.43pF steps.

There are 6 bits reserved for the CL setting but bits 0 and 1
have the same 0.43pF step. So it is actually 5 bits with an extra LSB of 0.43pF.

2)
Please use D1 D0 = 01. The “00” is a typo…..

Based on the above response I think we should always assume XTAL bit 0 is 0, and only use XTAL[5:1] which should make the math go easier, because the desired value in femtofarads would just be offset by 9000 and divided by 430 and that value would be shifted 3 places instead fo two, and the fixed-point math calculation can go away.

In addition to that, I would also need to make sure that D0 is set to 1, so instead of just writing the shifted XTAL value, I would also have to do a logic OR with 1 to set the low bit.

I talked with the hardware guys from work who also suggested that we always write the same value to X1 and X2, so I can remove the X1 and X2 references from the bindings.

Does that work for you?

adam

Quoted 5 lines

I don't think I have, but I can ask next week.

Regards.
--
Luca

maintainer
#7 lore raw

Re: [RFC 2/2] clk: vc5: Add support for optional load capacitance

Hi Adam,

Quoted 127 lines · Adam Ford
Quoted 92 lines · Luca Ceresoli

Hi Adam,

Quoted 10 lines · Adam Ford
Quoted 9 lines · Luca Ceresoli

Hi Adam,

Quoted 4 lines · Adam Ford

There are two registers which can set the load capacitance for XTAL1 and XTAL2. These are optional registers when using an external crystal. Parse the device tree and set the corresponding registers accordingly.

Quoted 8 lines
Quoted 1 line

No need to repeat the first 2 sentences, they are already in patch 1.

The reason I did that was because if someone does a git log on the individual file, they'd see the comment. While it's redundant not, it
might not be as obvious in the future when looking back. Not
everyone reviews the history of the binding, but the source files' git
logs usually have some value. However, if you want me to drop it or
rephrase it, I can do that.

Makes sense, I had never considered that before.

Quoted 53 lines
Quoted 21 lines
Quoted 21 lines
drivers/clk/clk-versaclock5.c +21 -0
+static int vc5_map_cap_value(u32 femtofarads)
+{
+     int mapped_value;
+
+     /* The datasheet explicitly states 9000 - 25000 */
+     if ((femtofarads < 9000) || (femtofarads > 25000))
+             return -EINVAL;
+
+     /* The lowest target we can hit is 9430, so exit if it's less */
+     if (femtofarads < 9430)
+             return 0;
+
+     /*
+      * According to VersaClock 6E Programming Guide, there are 6
+      * bits which translate to 64 entries in XTAL registers 12 and
+      * 13. Because bits 0 and 1 increase the capacitance the
+      * same, some of the values can be repeated.  Plugging this
+      * into a spreadsheet and generating a trendline, the output
+      * equation becomes x = (y-9098.29) / 216.44, where 'y' is
+      * the desired capacitance in femtofarads, and x is the value
+      * of XTAL[5:0].
Quoted 8 lines

drivers/clk/clk-versaclock5.c static int vc5_update_power(struct device_node *np_output, · line 786

Quoted 4 lines
drivers/clk/clk-versaclock5.c +4 -0
+      * To help with rounding, do fixed point math
+      */
+     femtofarads *= 100;
+     mapped_value = (femtofarads - 909829) / 21644;

Thanks for the extensive comment, but I am confused. Not by your code which is very clean and readable, but by the chip documentation (disclaimer: I haven't read it in full depth).

I was confused too since the datasheet and programmers manual differ a bit.

Quoted 5 lines

The 5P49V6965 datasheet at page 17 clearly states capacitance can be increased in 0.5 pF steps. The "VersaClock 6E Family Register Descriptions and Programming Guide" at page 18 shows a table that allows 0.43 pF. Can you clarify how the thing works?

I used the Versaclock 6E doc which is based on the following:

BIT 5 - Add 6.92pF
BIT 4 - Add 3.46pF
BIT 3 - Add 1.73pF
BIT 2 - Add 0.86pF
Bit 1 - Add 0.43pF
Bit 0 - Add 0.43pF

Because the Datasheet starts at 9pF, the math I used, assumes these numbers are added to 9pF.
Because the datasheet shows the increments are in .5pF increments, the 430nF seems close. The datasheet shows 9pF - 25pF and based on the programmer table, we could get close to 25pF by enabling all bits and adding 9pF, however the math doesn't quite hit 25pF.

Quoted 2 lines

For what it's worth I needed around 11.5pF, and with this patch, the hardware engineer said our ppm went from around 70 ppm to around 4ppm.

Did he measure what happens if you set the register according to the 0.5 pF interpretation? Does it improve? I understand the difference is probably olwer than the noise, but who knows.

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
drivers/clk/clk-versaclock5.c +6 -0
+
+     /*
+      * The datasheet states, the maximum capacitance is 25000,
+      * but the programmer guide shows a max value is 22832,
+      * so values higher values could overflow, so cap it.
+      */
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

The 22832 limit is if you assume 0.43 pF steps. Assuming 0.5 pF steps leads to 25000. Now I am more confused than before.

I agree. It would be nice to get some clarification from Renesas.

Definitely. Do you have access to some support from them?

Luca,

We reached out to Renesas with the following questions:

1)
I'm seeing a discrepancy between the datasheet and programming guide we have for the Versaclock 6e in regard to the crystal load programming registers. The datasheet for the 5P49V6965A000NLGI indicates a 9pF minimum with 0.5pF steps, while the programming guide says that the lower two register bits both add 0.43pF, which would make the equation:

Ci = 9pF + 0.43pF * XTAL[5:1] instead of
Ci = 9pF + 0.5pF * XTAL[5:0] as is published in the datasheet.

2) The programming guide shows that the default setting is 01b, but the note says it's reserved, use D1 D0 = 00. Can you confirm that we should set switch mode to 00 instead of the default 01?

And we got the following answers:

1)
The first one with 0.43pF steps is the correct one. Ci = 9pF +
0.43pF * XTAL[5:1]
0.5pF steps was the design target. When measuring actual
silicon, we found 0.43pF steps.

Quoted 6 lines

There are 6 bits reserved for the CL setting but bits 0 and 1
have the same 0.43pF step. So it is actually 5 bits with an extra LSB of 0.43pF.

2)
Please use D1 D0 = 01. The “00” is a typo…..

Great thing you got all those info from Renesas!

Quoted 11 lines

Based on the above response I think we should always assume XTAL bit 0 is 0, and only use XTAL[5:1] which should make the math go easier, because the desired value in femtofarads would just be offset by 9000 and divided by 430 and that value would be shifted 3 places instead fo two, and the fixed-point math calculation can go away.

In addition to that, I would also need to make sure that D0 is set to 1, so instead of just writing the shifted XTAL value, I would also have to do a logic OR with 1 to set the low bit.

Quoted 5 lines

I talked with the hardware guys from work who also suggested that we always write the same value to X1 and X2, so I can remove the X1 and X2 references from the bindings.

Does that work for you?

Yes.

We are only losing the ability to set 9 + (0.43 * 32) pF using all bits. I'm OK with that. Should it be needed in the future we can just add it as a special case, maybe just add a comment saying that, like "XTAL[5:0] = b111111 not supported".

Signature · 1 line
Luca
author
#8 lore raw

Re: [RFC 2/2] clk: vc5: Add support for optional load capacitance

Quoted 155 lines · Luca Ceresoli

Hi Adam,

Quoted 127 lines · Adam Ford
Quoted 92 lines · Luca Ceresoli

Hi Adam,

Quoted 10 lines · Adam Ford
Quoted 9 lines · Luca Ceresoli

Hi Adam,

Quoted 4 lines · Adam Ford

There are two registers which can set the load capacitance for XTAL1 and XTAL2. These are optional registers when using an external crystal. Parse the device tree and set the corresponding registers accordingly.

Quoted 8 lines
Quoted 1 line

No need to repeat the first 2 sentences, they are already in patch 1.

The reason I did that was because if someone does a git log on the individual file, they'd see the comment. While it's redundant not, it
might not be as obvious in the future when looking back. Not
everyone reviews the history of the binding, but the source files' git
logs usually have some value. However, if you want me to drop it or
rephrase it, I can do that.

Makes sense, I had never considered that before.

Quoted 53 lines
Quoted 21 lines
Quoted 21 lines
drivers/clk/clk-versaclock5.c +21 -0
+static int vc5_map_cap_value(u32 femtofarads)
+{
+     int mapped_value;
+
+     /* The datasheet explicitly states 9000 - 25000 */
+     if ((femtofarads < 9000) || (femtofarads > 25000))
+             return -EINVAL;
+
+     /* The lowest target we can hit is 9430, so exit if it's less */
+     if (femtofarads < 9430)
+             return 0;
+
+     /*
+      * According to VersaClock 6E Programming Guide, there are 6
+      * bits which translate to 64 entries in XTAL registers 12 and
+      * 13. Because bits 0 and 1 increase the capacitance the
+      * same, some of the values can be repeated.  Plugging this
+      * into a spreadsheet and generating a trendline, the output
+      * equation becomes x = (y-9098.29) / 216.44, where 'y' is
+      * the desired capacitance in femtofarads, and x is the value
+      * of XTAL[5:0].
Quoted 8 lines

drivers/clk/clk-versaclock5.c static int vc5_update_power(struct device_node *np_output, · line 786

Quoted 4 lines
drivers/clk/clk-versaclock5.c +4 -0
+      * To help with rounding, do fixed point math
+      */
+     femtofarads *= 100;
+     mapped_value = (femtofarads - 909829) / 21644;

Thanks for the extensive comment, but I am confused. Not by your code which is very clean and readable, but by the chip documentation (disclaimer: I haven't read it in full depth).

I was confused too since the datasheet and programmers manual differ a bit.

Quoted 5 lines

The 5P49V6965 datasheet at page 17 clearly states capacitance can be increased in 0.5 pF steps. The "VersaClock 6E Family Register Descriptions and Programming Guide" at page 18 shows a table that allows 0.43 pF. Can you clarify how the thing works?

I used the Versaclock 6E doc which is based on the following:

BIT 5 - Add 6.92pF
BIT 4 - Add 3.46pF
BIT 3 - Add 1.73pF
BIT 2 - Add 0.86pF
Bit 1 - Add 0.43pF
Bit 0 - Add 0.43pF

Because the Datasheet starts at 9pF, the math I used, assumes these numbers are added to 9pF.
Because the datasheet shows the increments are in .5pF increments, the 430nF seems close. The datasheet shows 9pF - 25pF and based on the programmer table, we could get close to 25pF by enabling all bits and adding 9pF, however the math doesn't quite hit 25pF.

Quoted 2 lines

For what it's worth I needed around 11.5pF, and with this patch, the hardware engineer said our ppm went from around 70 ppm to around 4ppm.

Did he measure what happens if you set the register according to the 0.5 pF interpretation? Does it improve? I understand the difference is probably olwer than the noise, but who knows.

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
drivers/clk/clk-versaclock5.c +6 -0
+
+     /*
+      * The datasheet states, the maximum capacitance is 25000,
+      * but the programmer guide shows a max value is 22832,
+      * so values higher values could overflow, so cap it.
+      */
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

The 22832 limit is if you assume 0.43 pF steps. Assuming 0.5 pF steps leads to 25000. Now I am more confused than before.

I agree. It would be nice to get some clarification from Renesas.

Definitely. Do you have access to some support from them?

Luca,

We reached out to Renesas with the following questions:

1)
I'm seeing a discrepancy between the datasheet and programming guide we have for the Versaclock 6e in regard to the crystal load programming registers. The datasheet for the 5P49V6965A000NLGI indicates a 9pF minimum with 0.5pF steps, while the programming guide says that the lower two register bits both add 0.43pF, which would make the equation:

Ci = 9pF + 0.43pF * XTAL[5:1] instead of
Ci = 9pF + 0.5pF * XTAL[5:0] as is published in the datasheet.

2) The programming guide shows that the default setting is 01b, but the note says it's reserved, use D1 D0 = 00. Can you confirm that we should set switch mode to 00 instead of the default 01?

And we got the following answers:

1)
The first one with 0.43pF steps is the correct one. Ci = 9pF +
0.43pF * XTAL[5:1]
0.5pF steps was the design target. When measuring actual
silicon, we found 0.43pF steps.

Quoted 6 lines

There are 6 bits reserved for the CL setting but bits 0 and 1
have the same 0.43pF step. So it is actually 5 bits with an extra LSB of 0.43pF.

2)
Please use D1 D0 = 01. The “00” is a typo…..

Great thing you got all those info from Renesas!

Quoted 15 lines

Based on the above response I think we should always assume XTAL bit 0 is 0, and only use XTAL[5:1] which should make the math go easier, because the desired value in femtofarads would just be offset by 9000 and divided by 430 and that value would be shifted 3 places instead fo two, and the fixed-point math calculation can go away.

In addition to that, I would also need to make sure that D0 is set to 1, so instead of just writing the shifted XTAL value, I would also have to do a logic OR with 1 to set the low bit.

I talked with the hardware guys from work who also suggested that we always write the same value to X1 and X2, so I can remove the X1 and X2 references from the bindings.

Quoted 5 lines
Quoted 1 line

Does that work for you?

Yes.

We are only losing the ability to set 9 + (0.43 * 32) pF using all bits.

We'd be doing this with XTAL[5:1] which mathematically makes more sense.

Quoted 3 lines

I'm OK with that. Should it be needed in the future we can just add it as a special case, maybe just add a comment saying that, like "XTAL[5:0] = b111111 not supported".

XTAL[0] won't be supported at all by my updated algorithm, not just b111111

adam

Quoted 3 lines

--
Luca

maintainer
#9 lore raw

Re: [RFC 2/2] clk: vc5: Add support for optional load capacitance

Hi Adam,

Quoted 162 lines · Adam Ford
Quoted 155 lines · Luca Ceresoli

Hi Adam,

Quoted 127 lines · Adam Ford
Quoted 92 lines · Luca Ceresoli

Hi Adam,

Quoted 10 lines · Adam Ford
Quoted 9 lines · Luca Ceresoli

Hi Adam,

Quoted 4 lines · Adam Ford

There are two registers which can set the load capacitance for XTAL1 and XTAL2. These are optional registers when using an external crystal. Parse the device tree and set the corresponding registers accordingly.

Quoted 8 lines
Quoted 1 line

No need to repeat the first 2 sentences, they are already in patch 1.

The reason I did that was because if someone does a git log on the individual file, they'd see the comment. While it's redundant not, it
might not be as obvious in the future when looking back. Not
everyone reviews the history of the binding, but the source files' git
logs usually have some value. However, if you want me to drop it or
rephrase it, I can do that.

Makes sense, I had never considered that before.

Quoted 53 lines
Quoted 21 lines
Quoted 21 lines
(quoted diff) +21 -0
+static int vc5_map_cap_value(u32 femtofarads)
+{
+     int mapped_value;
+
+     /* The datasheet explicitly states 9000 - 25000 */
+     if ((femtofarads < 9000) || (femtofarads > 25000))
+             return -EINVAL;
+
+     /* The lowest target we can hit is 9430, so exit if it's less */
+     if (femtofarads < 9430)
+             return 0;
+
+     /*
+      * According to VersaClock 6E Programming Guide, there are 6
+      * bits which translate to 64 entries in XTAL registers 12 and
+      * 13. Because bits 0 and 1 increase the capacitance the
+      * same, some of the values can be repeated.  Plugging this
+      * into a spreadsheet and generating a trendline, the output
+      * equation becomes x = (y-9098.29) / 216.44, where 'y' is
+      * the desired capacitance in femtofarads, and x is the value
+      * of XTAL[5:0].
Quoted 8 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+      * To help with rounding, do fixed point math
+      */
+     femtofarads *= 100;
+     mapped_value = (femtofarads - 909829) / 21644;

Thanks for the extensive comment, but I am confused. Not by your code which is very clean and readable, but by the chip documentation (disclaimer: I haven't read it in full depth).

I was confused too since the datasheet and programmers manual differ a bit.

Quoted 5 lines

The 5P49V6965 datasheet at page 17 clearly states capacitance can be increased in 0.5 pF steps. The "VersaClock 6E Family Register Descriptions and Programming Guide" at page 18 shows a table that allows 0.43 pF. Can you clarify how the thing works?

I used the Versaclock 6E doc which is based on the following:

BIT 5 - Add 6.92pF
BIT 4 - Add 3.46pF
BIT 3 - Add 1.73pF
BIT 2 - Add 0.86pF
Bit 1 - Add 0.43pF
Bit 0 - Add 0.43pF

Because the Datasheet starts at 9pF, the math I used, assumes these numbers are added to 9pF.
Because the datasheet shows the increments are in .5pF increments, the 430nF seems close. The datasheet shows 9pF - 25pF and based on the programmer table, we could get close to 25pF by enabling all bits and adding 9pF, however the math doesn't quite hit 25pF.

Quoted 2 lines

For what it's worth I needed around 11.5pF, and with this patch, the hardware engineer said our ppm went from around 70 ppm to around 4ppm.

Did he measure what happens if you set the register according to the 0.5 pF interpretation? Does it improve? I understand the difference is probably olwer than the noise, but who knows.

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
(quoted diff) +6 -0
+
+     /*
+      * The datasheet states, the maximum capacitance is 25000,
+      * but the programmer guide shows a max value is 22832,
+      * so values higher values could overflow, so cap it.
+      */
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

The 22832 limit is if you assume 0.43 pF steps. Assuming 0.5 pF steps leads to 25000. Now I am more confused than before.

I agree. It would be nice to get some clarification from Renesas.

Definitely. Do you have access to some support from them?

Luca,

We reached out to Renesas with the following questions:

1)
I'm seeing a discrepancy between the datasheet and programming guide we have for the Versaclock 6e in regard to the crystal load programming registers. The datasheet for the 5P49V6965A000NLGI indicates a 9pF minimum with 0.5pF steps, while the programming guide says that the lower two register bits both add 0.43pF, which would make the equation:

Ci = 9pF + 0.43pF * XTAL[5:1] instead of
Ci = 9pF + 0.5pF * XTAL[5:0] as is published in the datasheet.

2) The programming guide shows that the default setting is 01b, but the note says it's reserved, use D1 D0 = 00. Can you confirm that we should set switch mode to 00 instead of the default 01?

And we got the following answers:

1)
The first one with 0.43pF steps is the correct one. Ci = 9pF +
0.43pF * XTAL[5:1]
0.5pF steps was the design target. When measuring actual
silicon, we found 0.43pF steps.

Quoted 6 lines

There are 6 bits reserved for the CL setting but bits 0 and 1
have the same 0.43pF step. So it is actually 5 bits with an extra LSB of 0.43pF.

2)
Please use D1 D0 = 01. The “00” is a typo…..

Great thing you got all those info from Renesas!

Quoted 15 lines

Based on the above response I think we should always assume XTAL bit 0 is 0, and only use XTAL[5:1] which should make the math go easier, because the desired value in femtofarads would just be offset by 9000 and divided by 430 and that value would be shifted 3 places instead fo two, and the fixed-point math calculation can go away.

In addition to that, I would also need to make sure that D0 is set to 1, so instead of just writing the shifted XTAL value, I would also have to do a logic OR with 1 to set the low bit.

I talked with the hardware guys from work who also suggested that we always write the same value to X1 and X2, so I can remove the X1 and X2 references from the bindings.

Quoted 5 lines
Quoted 1 line

Does that work for you?

Yes.

We are only losing the ability to set 9 + (0.43 * 32) pF using all bits.

Quoted 7 lines

We'd be doing this with XTAL[5:1] which mathematically makes more sense.

Quoted 3 lines

I'm OK with that. Should it be needed in the future we can just add it as a special case, maybe just add a comment saying that, like "XTAL[5:0] = b111111 not supported".

XTAL[0] won't be supported at all by my updated algorithm, not just b111111

I think we are saying the same thing in two different ways. According to table 28 of the "Regiter description and programming guide", we have:

Ci = 9 + (0.43 * N) pF

where N can be any integer between 0 and 32 (inclusive).

Your proposed implementation is:

reg_0x12 = (N << 3) | 0x1;

i.e. using only XTAL bits [5:1], not [0], so we can have any value in the range [0..31], but not 32. This is OK for me.

Should we need value 32 at some point we can simply augment it as:

if (N == 32)
reg_0x12 = (b111111 << 2) | 0x1;
else
reg_0x12 = (N << 3) | 0x1; // your current proposal

Among all register XTAL values having XTAL[0] == 1, only b111111 is interesting. All other values have an equivalent with XTAL[0] == 0.

Correct?

Signature · 1 line
Luca
maintainer
#10 lore raw

Re: [RFC 2/2] clk: vc5: Add support for optional load capacitance

In reply to Adam Ford

Quoting Adam Ford (2021-01-06 09:39:00)

Quoted 15 lines

There are two registers which can set the load capacitance for XTAL1 and XTAL2. These are optional registers when using an external crystal. Parse the device tree and set the corresponding registers accordingly.

---
 drivers/clk/clk-versaclock5.c | 64 +++++++++++++++++++++++++++++++++++
 1 file changed, 64 insertions(+)
drivers/clk/clk-versaclock5.c +0 -0
index 43db67337bc0..445abc3731fb 100644

drivers/clk/clk-versaclock5.c static int vc5_update_power(struct device_node *np_output, · line 767

Quoted 9 lines
drivers/clk/clk-versaclock5.c +6 -0
@@ -759,6 +759,63 @@ static int vc5_update_power(struct device_node *np_output,
        return 0;
 }
 
+static int vc5_map_cap_value(u32 femtofarads)
+{
+       int mapped_value;
+
+       /* The datasheet explicitly states 9000 - 25000 */
+       if ((femtofarads < 9000) || (femtofarads > 25000))

Please remove useless parenthesis.

Quoted 26 lines
drivers/clk/clk-versaclock5.c +26 -0
+               return -EINVAL;
+
+       /* The lowest target we can hit is 9430, so exit if it's less */
+       if (femtofarads < 9430)
+               return 0;
+
+       /*
+        * According to VersaClock 6E Programming Guide, there are 6
+        * bits which translate to 64 entries in XTAL registers 12 and
+        * 13. Because bits 0 and 1 increase the capacitance the
+        * same, some of the values can be repeated.  Plugging this
+        * into a spreadsheet and generating a trendline, the output
+        * equation becomes x = (y-9098.29) / 216.44, where 'y' is
+        * the desired capacitance in femtofarads, and x is the value
+        * of XTAL[5:0].
+        * To help with rounding, do fixed point math
+        */
+       femtofarads *= 100;
+       mapped_value = (femtofarads - 909829) / 21644;
+
+       /*
+        * The datasheet states, the maximum capacitance is 25000,
+        * but the programmer guide shows a max value is 22832,
+        * so values higher values could overflow, so cap it.
+        */
+       mapped_value = max(mapped_value/100, 0x3f);

drivers/clk/clk-versaclock5.c static int vc5_update_power(struct device_node *np_output, · line 803

Quoted 10 lines
drivers/clk/clk-versaclock5.c +10 -0
+
+       return mapped_value;
+}
+static int vc5_update_cap_load(struct device_node *node, struct vc5_driver_data *vc5)
+{
+       u32 value, mapped_value;
+
+       if (!of_property_read_u32(node, "idt,xtal1-load-femtofarads", &value)) {
+               mapped_value = vc5_map_cap_value(value);
+               if (mapped_value < 0)

How can it be less than 0? It's unsigned.

drivers/clk/clk-versaclock5.c static int vc5_update_power(struct device_node *np_output, · line 811

Quoted 8 lines
drivers/clk/clk-versaclock5.c +8 -0
+                       return mapped_value;
+
+               regmap_write(vc5->regmap, VC5_XTAL_X1_LOAD_CAP, (mapped_value << 2));
+       }
+
+       if (!of_property_read_u32(node, "idt,xtal2-load-femtofarads", &value)) {
+               mapped_value = vc5_map_cap_value(value);
+               if (mapped_value < 0)

Same!

Quoted 10 lines
drivers/clk/clk-versaclock5.c +7 -0
+                       return mapped_value;
+               regmap_write(vc5->regmap, VC5_XTAL_X2_LOAD_CAP, (mapped_value << 2));
+       }
+
+       return 0;
+}
+
 static int vc5_update_slew(struct device_node *np_output,
                           struct vc5_out_data *clk_out)
 {
maintainer
#11 lore raw
In reply to Adam Ford

Hi Adam,

Quoted 14 lines · Adam Ford

There are two registers which can set the load capacitance for XTAL1 and XTAL2. These are optional registers when using an external crystal. Update the bindings to support them.

---
 .../devicetree/bindings/clock/idt,versaclock5.yaml   | 12 ++++++++++++
 1 file changed, 12 insertions(+)
Documentation/devicetree/bindings/clock/idt,versaclock5.yaml +0 -0
index 2ac1131fd922..e5e55ffb266e 100644

Documentation/devicetree/bindings/clock/idt,versaclock5.yaml properties: · line 62

Quoted 4 lines
Documentation/devicetree/bindings/clock/idt,versaclock5.yaml +1 -0
@@ -59,6 +59,18 @@ properties:
     minItems: 1
     maxItems: 2
 
+  idt,xtal1-load-femtofarads:

I wonder whether we should have a common, vendor independent property. In mainline we have xtal-load-pf (ti,cdce925.txt bindings) which has no vendor prefix. However I don't know how much common it is to need different loads for x1 and x2. Any hardware engineer around?

Documentation/devicetree/bindings/clock/idt,versaclock5.yaml properties: · line 66

Quoted 4 lines
Documentation/devicetree/bindings/clock/idt,versaclock5.yaml +4 -0
+    $ref: /schemas/types.yaml#/definitions/uint32
+    minimum: 9000
+    maximum: 25000
+    description: Optional loading capacitor for XTAL1

Nit: I think the common wording is "load capacitor", not "loading capacitor".

Signature · 1 line
Luca
author
#12 lore raw
Quoted 21 lines · Luca Ceresoli

Hi Adam,

Quoted 17 lines · Adam Ford

There are two registers which can set the load capacitance for XTAL1 and XTAL2. These are optional registers when using an external crystal. Update the bindings to support them.

---
 .../devicetree/bindings/clock/idt,versaclock5.yaml   | 12 ++++++++++++
 1 file changed, 12 insertions(+)
Documentation/devicetree/bindings/clock/idt,versaclock5.yaml +0 -0
index 2ac1131fd922..e5e55ffb266e 100644
@@ -59,6 +59,18 @@ properties:
     minItems: 1
     maxItems: 2
 
Quoted 3 lines

Documentation/devicetree/bindings/clock/idt,versaclock5.yaml properties: · line 62

Quoted 1 line
Documentation/devicetree/bindings/clock/idt,versaclock5.yaml +1 -0
+  idt,xtal1-load-femtofarads:

I wonder whether we should have a common, vendor independent property.

That would be nice.

Quoted 2 lines

In mainline we have xtal-load-pf (ti,cdce925.txt bindings) which has no vendor prefix. However I don't know how much common it is to need

rtc-pcf85063.c uses quartz-load-femtofarads, so there is already some discrepancy.

Since the unit of measure here is femtofarads, using pF in the name seems wrong. We need to read the data as a u32, so femtofarads works better than pF, which would require a decimal point.

Quoted 1 line

different loads for x1 and x2. Any hardware engineer around?

I talked to a hardware engineer where I work, and he said it makes sense to keep them the same. I only separated them because there are two registers, and I assumed there might be a reason to have X1 and X2 be different, but I'm ok with reading one value and writing it to two different registers.

adam

Quoted 11 lines

Documentation/devicetree/bindings/clock/idt,versaclock5.yaml properties: · line 66

Quoted 5 lines
Documentation/devicetree/bindings/clock/idt,versaclock5.yaml +4 -0
+    $ref: /schemas/types.yaml#/definitions/uint32
+    minimum: 9000
+    maximum: 25000
+    description: Optional loading capacitor for XTAL1

Nit: I think the common wording is "load capacitor", not "loading capacitor".

--
Luca

maintainer
#13 lore raw

Hi Adam,

Quoted 38 lines · Adam Ford
Quoted 21 lines · Luca Ceresoli

Hi Adam,

Quoted 17 lines · Adam Ford

There are two registers which can set the load capacitance for XTAL1 and XTAL2. These are optional registers when using an external crystal. Update the bindings to support them.

---
 .../devicetree/bindings/clock/idt,versaclock5.yaml   | 12 ++++++++++++
 1 file changed, 12 insertions(+)
Documentation/devicetree/bindings/clock/idt,versaclock5.yaml +0 -0
index 2ac1131fd922..e5e55ffb266e 100644
@@ -59,6 +59,18 @@ properties:
     minItems: 1
     maxItems: 2
 
Quoted 3 lines

Documentation/devicetree/bindings/clock/idt,versaclock5.yaml properties: · line 62

Quoted 1 line
Documentation/devicetree/bindings/clock/idt,versaclock5.yaml +1 -0
+  idt,xtal1-load-femtofarads:

I wonder whether we should have a common, vendor independent property.

That would be nice.

Quoted 2 lines

In mainline we have xtal-load-pf (ti,cdce925.txt bindings) which has no vendor prefix. However I don't know how much common it is to need

rtc-pcf85063.c uses quartz-load-femtofarads, so there is already some discrepancy.

Since the unit of measure here is femtofarads, using pF in the name seems wrong. We need to read the data as a u32, so femtofarads works better than pF, which would require a decimal point.

Quoted 7 lines
Quoted 1 line

different loads for x1 and x2. Any hardware engineer around?

I talked to a hardware engineer where I work, and he said it makes sense to keep them the same. I only separated them because there are two registers, and I assumed there might be a reason to have X1 and X2 be different, but I'm ok with reading one value and writing it to two different registers.

If both your HW engineer and the Renesas docs say setting different values is not useful in real life, and other drivers don't set different values as well, it looks like that is the reasonable way. I think it also increases likelihood of establishing a unique property name to be used for all future chips.

Signature · 1 line
Luca
maintainer
#14 lore raw
In reply to Adam Ford
Quoted 14 lines · Adam Ford

There are two registers which can set the load capacitance for XTAL1 and XTAL2. These are optional registers when using an external crystal. Update the bindings to support them.

---
 .../devicetree/bindings/clock/idt,versaclock5.yaml   | 12 ++++++++++++
 1 file changed, 12 insertions(+)
Documentation/devicetree/bindings/clock/idt,versaclock5.yaml +0 -0
index 2ac1131fd922..e5e55ffb266e 100644

Documentation/devicetree/bindings/clock/idt,versaclock5.yaml properties: · line 63

Quoted 5 lines
Documentation/devicetree/bindings/clock/idt,versaclock5.yaml +2 -0
@@ -59,6 +59,18 @@ properties:
     minItems: 1
     maxItems: 2
 
+  idt,xtal1-load-femtofarads:
+    $ref: /schemas/types.yaml#/definitions/uint32

Already has a type, so you can drop the $ref.

Quoted 16 lines
Documentation/devicetree/bindings/clock/idt,versaclock5.yaml +10 -0
+    minimum: 9000
+    maximum: 25000
+    description: Optional loading capacitor for XTAL1
+
+  idt,xtal2-load-femtofarads:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    minimum: 9000
+    maximum: 25000
+    description: Optional loading capacitor for XTAL2
+
 patternProperties:
   "^OUT[1-4]$":
     type: object
Signature · 1 line
2.25.1
author
#15 lore raw
Quoted 19 lines · Rob Herring
Quoted 17 lines · Adam Ford

There are two registers which can set the load capacitance for XTAL1 and XTAL2. These are optional registers when using an external crystal. Update the bindings to support them.

---
 .../devicetree/bindings/clock/idt,versaclock5.yaml   | 12 ++++++++++++
 1 file changed, 12 insertions(+)
Documentation/devicetree/bindings/clock/idt,versaclock5.yaml +0 -0
index 2ac1131fd922..e5e55ffb266e 100644
@@ -59,6 +59,18 @@ properties:
     minItems: 1
     maxItems: 2
 
Quoted 7 lines

Documentation/devicetree/bindings/clock/idt,versaclock5.yaml properties: · line 63

Quoted 2 lines
Documentation/devicetree/bindings/clock/idt,versaclock5.yaml +2 -0
+  idt,xtal1-load-femtofarads:
+    $ref: /schemas/types.yaml#/definitions/uint32

Already has a type, so you can drop the $ref.

Quoted 2 lines
Documentation/devicetree/bindings/clock/idt,versaclock5.yaml +2 -0
+    minimum: 9000
+    maximum: 25000

Luca,

Do you want the range to the 9000 - 25000 per the datasheet, or should I use the max value based on the programmer guide? Currently, my intent was to cap the value to 11111b, so anyone who writes 23000, 24000, or 25000 will all be the same value based on the feedback I got from Renesas.

adam

Quoted 14 lines
Quoted 14 lines
Documentation/devicetree/bindings/clock/idt,versaclock5.yaml +8 -1
+    description: Optional loading capacitor for XTAL1
+
+  idt,xtal2-load-femtofarads:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    minimum: 9000
+    maximum: 25000
+    description: Optional loading capacitor for XTAL2
+
 patternProperties:
   "^OUT[1-4]$":
     type: object
--

2.25.1

maintainer
#16 lore raw

Hi Adam,

Quoted 28 lines · Adam Ford
Quoted 19 lines · Rob Herring
Quoted 17 lines · Adam Ford

There are two registers which can set the load capacitance for XTAL1 and XTAL2. These are optional registers when using an external crystal. Update the bindings to support them.

---
 .../devicetree/bindings/clock/idt,versaclock5.yaml   | 12 ++++++++++++
 1 file changed, 12 insertions(+)
Documentation/devicetree/bindings/clock/idt,versaclock5.yaml +0 -0
index 2ac1131fd922..e5e55ffb266e 100644
@@ -59,6 +59,18 @@ properties:
     minItems: 1
     maxItems: 2
 
Quoted 7 lines

Documentation/devicetree/bindings/clock/idt,versaclock5.yaml properties: · line 63

Quoted 2 lines
Documentation/devicetree/bindings/clock/idt,versaclock5.yaml +2 -0
+  idt,xtal1-load-femtofarads:
+    $ref: /schemas/types.yaml#/definitions/uint32

Already has a type, so you can drop the $ref.

Quoted 2 lines
Documentation/devicetree/bindings/clock/idt,versaclock5.yaml +2 -0
+    minimum: 9000
+    maximum: 25000
Quoted 7 lines

Luca,

Do you want the range to the 9000 - 25000 per the datasheet, or should I use the max value based on the programmer guide? Currently, my intent was to cap the value to 11111b, so anyone who writes 23000, 24000, or 25000 will all be the same value based on the feedback I got from Renesas.

DT should describe the HW, so I'd use the same range that can be set in hardware, regardless of driver support. Thus it should be:

9000 - [9000 + 430 * 32] = 9000 - 22760

Signature · 1 line
Luca