Skip to contentSkip to conversation

dt-bindings: clock: fixed-clock: Add nvmem support

PATCH In review Mike Looijmans 3 participants 5 messages Jun 5, 2023 – Jun 22, 2023 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): 1b153bce-a66a-45ee-a5c6-963ea6fb1c82.949ef384-8293-46b8-903f-40a477c056ae.2d27bfea-4746-444c-89f4-e5d35cb7de66@emailsignatures365.codetwo.com

#1 lore raw

PATCH v4 1/2 dt-bindings: clock: fixed-clock: Add nvmem support

Add bindings for a fixed-rate clock that retrieves its rate from an NVMEM provider. This allows to store clock settings in EEPROM or EFUSE or similar device.

Component shortages lead to boards being shipped with different clock crystals, based on what was available at the time. The clock frequency was written to EEPROM at production time. Systems can adapt to a wide range of input frequencies using the clock framework, but this required us to patch the devicetree at runtime or use some custom driver. This provides a more generic solution.

---

Changes in v4:
Use proper "if" block and add example dts

Changes in v3:
Modify fixed-clock instead of introducing nvmem-clock

Changes in v2:
Changed "fixed-clock" into "nvmem-clock" in dts example Add minItems:1 to nvmem-cell-names

 .../bindings/clock/fixed-clock.yaml           | 42 ++++++++++++++++++-
 1 file changed, 41 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/clock/fixed-clock.yaml +41 -1
index b0a4fb8256e2..71a5791da438 100644
@@ -12,7 +12,9 @@ maintainers:
 
 properties:
   compatible:
-    const: fixed-clock
+    enum:
+      - fixed-clock
+      - fixed-clock-nvmem
 
   "#clock-cells":
     const: 0
@@ -26,11 +28,41 @@ properties:
   clock-output-names:
     maxItems: 1
 
+  nvmem-cells:
+    minItems: 1
+    maxItems: 2
+    description:
+      Reads clock-frequency and/or clock-accuracy from an NVMEM provider in
+      binary native integer format. The size of the NVMEM cell can be 1, 2, 4
+      or 8 bytes. If the contents of the nvmem are all zeroes or all 0xff, the
+      value reverts to the one given in the property.
+
+  nvmem-cell-names:
+    minItems: 1
+    items:
+      - const: clock-frequency
+      - const: clock-accuracy
+
 required:
   - compatible
   - "#clock-cells"
   - clock-frequency
 
+allOf:
+  - if:
+      properties:
+        compatible:
+          contains:
+            const: fixed-clock-nvmem
+    then:
+      required:
+        - nvmem-cells
+        - nvmem-cell-names
+    else:
+      properties:
+        nvmem-cells: false
+        nvmem-cell-names: false
+
 additionalProperties: false
 
 examples:
@@ -41,4 +73,12 @@ examples:
       clock-frequency = <1000000000>;
       clock-accuracy = <100>;
     };
+  - |
+    clock {
+      compatible = "fixed-clock-nvmem";
+      #clock-cells = <0>;
+      clock-frequency = <48000000>;
+      nvmem-cells = <&efuse_xtal_freq>;
+      nvmem-cell-names = "clock-frequency";
+    };
 ...
Signature · 18 lines
2.17.1


Met vriendelijke groet / kind regards,

Mike Looijmans
System Expert


TOPIC Embedded Products B.V.
Materiaalweg 4, 5681 RJ Best
The Netherlands

T: +31 (0) 499 33 69 69
E: [email protected]
W: www.topic.nl

Please consider the environment before printing this e-mail
#2 lore raw

PATCH v4 2/2 clk: Add fixed-clock-nvmem provider

Adds a fixed-rate clock that retrieves its rate from an NVMEM provider. This allows to store clock settings in EEPROM or EFUSE or similar device.

Component shortages lead to boards being shipped with different clock crystals, based on what was available at the time. The clock frequency was written to EEPROM at production time. Systems can adapt to a wide range of input frequencies using the clock framework, but this required us to patch the devicetree at runtime or use some custom driver. This provides a more generic solution.

Because this clock depends on other hardware (typical NVMEM provider is an I2C EEPROM) it cannot be integrated into clk-fixed which uses CLK_OF_DECLARE to initialize.

---

(no changes since v3)

Changes in v3:
Change compatible to fixed-clock-nvmem

 drivers/clk/Kconfig     |   7 +++
 drivers/clk/Makefile    |   1 +
 drivers/clk/clk-nvmem.c | 113 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 121 insertions(+)
 create mode 100644 drivers/clk/clk-nvmem.c
drivers/clk/Kconfig +7 -0
index 016814e15536..63f165473481 100644
@@ -447,6 +447,13 @@ config COMMON_CLK_FIXED_MMIO
 	help
 	  Support for Memory Mapped IO Fixed clocks
 
+config COMMON_CLK_NVMEM
+	bool "Clock driver for NVMEM provided frequency"
+	depends on COMMON_CLK && OF
+	help
+	  This driver allows a clock frequency to be provided by NVMEM data, for
+	  example in an EEPROM, by fuses or other non-volatile storage.
+
 config COMMON_CLK_K210
 	bool "Clock driver for the Canaan Kendryte K210 SoC"
 	depends on OF && RISCV && SOC_CANAAN
drivers/clk/Makefile +1 -0
index 0aebef17edc6..aef1361e5085 100644
@@ -52,6 +52,7 @@ obj-$(CONFIG_ARCH_MOXART)		+= clk-moxart.o
 obj-$(CONFIG_ARCH_NOMADIK)		+= clk-nomadik.o
 obj-$(CONFIG_ARCH_NPCM7XX)	    	+= clk-npcm7xx.o
 obj-$(CONFIG_ARCH_NSPIRE)		+= clk-nspire.o
+obj-$(CONFIG_COMMON_CLK_NVMEM)		+= clk-nvmem.o
 obj-$(CONFIG_COMMON_CLK_OXNAS)		+= clk-oxnas.o
 obj-$(CONFIG_COMMON_CLK_PALMAS)		+= clk-palmas.o
 obj-$(CONFIG_CLK_LS1028A_PLLDIG)	+= clk-plldig.o
drivers/clk/clk-nvmem.c new file +113 -0

113 lines not on this page · raw message

Signature · 18 lines
2.17.1


Met vriendelijke groet / kind regards,

Mike Looijmans
System Expert


TOPIC Embedded Products B.V.
Materiaalweg 4, 5681 RJ Best
The Netherlands

T: +31 (0) 499 33 69 69
E: [email protected]
W: www.topic.nl

Please consider the environment before printing this e-mail
Reviewed-by on v4 1/2
#3 lore raw
In reply to Mike Looijmans
Quoted 4 lines · Mike Looijmans

Add bindings for a fixed-rate clock that retrieves its rate from an NVMEM provider. This allows to store clock settings in EEPROM or EFUSE or similar device.

Quoted 9 lines

Component shortages lead to boards being shipped with different clock crystals, based on what was available at the time. The clock frequency was written to EEPROM at production time. Systems can adapt to a wide range of input frequencies using the clock framework, but this required us to patch the devicetree at runtime or use some custom driver. This provides a more generic solution.

Best regards,
Krzysztof

maintainer
#4 lore raw
In reply to Mike Looijmans
Quoted 86 lines · Mike Looijmans

Add bindings for a fixed-rate clock that retrieves its rate from an NVMEM provider. This allows to store clock settings in EEPROM or EFUSE or similar device.

Component shortages lead to boards being shipped with different clock crystals, based on what was available at the time. The clock frequency was written to EEPROM at production time. Systems can adapt to a wide range of input frequencies using the clock framework, but this required us to patch the devicetree at runtime or use some custom driver. This provides a more generic solution.

---

Changes in v4:
Use proper "if" block and add example dts

Changes in v3:
Modify fixed-clock instead of introducing nvmem-clock

Changes in v2:
Changed "fixed-clock" into "nvmem-clock" in dts example Add minItems:1 to nvmem-cell-names

 .../bindings/clock/fixed-clock.yaml           | 42 ++++++++++++++++++-
 1 file changed, 41 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/clock/fixed-clock.yaml +33 -1
index b0a4fb8256e2..71a5791da438 100644
@@ -12,7 +12,9 @@ maintainers:
 
 properties:
   compatible:
-    const: fixed-clock
+    enum:
+      - fixed-clock
+      - fixed-clock-nvmem
 
   "#clock-cells":
     const: 0
@@ -26,11 +28,41 @@ properties:
   clock-output-names:
     maxItems: 1
 
+  nvmem-cells:
+    minItems: 1
+    maxItems: 2
+    description:
+      Reads clock-frequency and/or clock-accuracy from an NVMEM provider in
+      binary native integer format. The size of the NVMEM cell can be 1, 2, 4
+      or 8 bytes. If the contents of the nvmem are all zeroes or all 0xff, the
+      value reverts to the one given in the property.
+
+  nvmem-cell-names:
+    minItems: 1
+    items:
+      - const: clock-frequency
+      - const: clock-accuracy
+
 required:
   - compatible
   - "#clock-cells"
   - clock-frequency
 
+allOf:
+  - if:
+      properties:
+        compatible:
+          contains:
+            const: fixed-clock-nvmem
+    then:
+      required:
+        - nvmem-cells
+        - nvmem-cell-names
+    else:
+      properties:
+        nvmem-cells: false
+        nvmem-cell-names: false
+
 additionalProperties: false
 
 examples:

Documentation/devicetree/bindings/clock/fixed-clock.yaml examples: · line 80

Quoted 8 lines
Documentation/devicetree/bindings/clock/fixed-clock.yaml +5 -0
@@ -41,4 +73,12 @@ examples:
       clock-frequency = <1000000000>;
       clock-accuracy = <100>;
     };
+  - |
+    clock {
+      compatible = "fixed-clock-nvmem";
+      #clock-cells = <0>;
+      clock-frequency = <48000000>;

If the freq comes from nvmem, why is this needed?

I think this should probably be a separate schema file as the only other thing shared is #clock-cells.

Rob

#5 lore raw
Quoted 85 lines · Rob Herring
Quoted 84 lines · Mike Looijmans

Add bindings for a fixed-rate clock that retrieves its rate from an NVMEM provider. This allows to store clock settings in EEPROM or EFUSE or similar device.

Component shortages lead to boards being shipped with different clock crystals, based on what was available at the time. The clock frequency was written to EEPROM at production time. Systems can adapt to a wide range of input frequencies using the clock framework, but this required us to patch the devicetree at runtime or use some custom driver. This provides a more generic solution.

---

Changes in v4:
Use proper "if" block and add example dts

Changes in v3:
Modify fixed-clock instead of introducing nvmem-clock

Changes in v2:
Changed "fixed-clock" into "nvmem-clock" in dts example Add minItems:1 to nvmem-cell-names

  .../bindings/clock/fixed-clock.yaml           | 42 ++++++++++++++++++-
  1 file changed, 41 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/clock/fixed-clock.yaml +33 -1
index b0a4fb8256e2..71a5791da438 100644
@@ -12,7 +12,9 @@ maintainers:
 
  properties:
    compatible:
-    const: fixed-clock
+    enum:
+      - fixed-clock
+      - fixed-clock-nvmem
 
    "#clock-cells":
      const: 0
@@ -26,11 +28,41 @@ properties:
    clock-output-names:
      maxItems: 1
 
+  nvmem-cells:
+    minItems: 1
+    maxItems: 2
+    description:
+      Reads clock-frequency and/or clock-accuracy from an NVMEM provider in
+      binary native integer format. The size of the NVMEM cell can be 1, 2, 4
+      or 8 bytes. If the contents of the nvmem are all zeroes or all 0xff, the
+      value reverts to the one given in the property.
+
+  nvmem-cell-names:
+    minItems: 1
+    items:
+      - const: clock-frequency
+      - const: clock-accuracy
+
  required:
    - compatible
    - "#clock-cells"
    - clock-frequency
 
+allOf:
+  - if:
+      properties:
+        compatible:
+          contains:
+            const: fixed-clock-nvmem
+    then:
+      required:
+        - nvmem-cells
+        - nvmem-cell-names
+    else:
+      properties:
+        nvmem-cells: false
+        nvmem-cell-names: false
+
  additionalProperties: false
 
Quoted 12 lines

Documentation/devicetree/bindings/clock/fixed-clock.yaml examples: · line 80

Quoted 10 lines
Documentation/devicetree/bindings/clock/fixed-clock.yaml +5 -0
  examples:
@@ -41,4 +73,12 @@ examples:
        clock-frequency = <1000000000>;
        clock-accuracy = <100>;
      };
+  - |
+    clock {
+      compatible = "fixed-clock-nvmem";
+      #clock-cells = <0>;
+      clock-frequency = <48000000>;

If the freq comes from nvmem, why is this needed?

Not needed, but it's a nice default in case the NVMEM is still 'blank'. With a separate schema (see next comment), something like "clock-frequency-default" would be more appropriate.

Quoted 2 lines

I think this should probably be a separate schema file as the only other thing shared is #clock-cells.

Yep, I implemented it this way as suggested by Krysztof.

I don't care much either way, I'll send a v5 with a separate yaml file, if Krysztof agrees.

Signature · 10 lines
Mike Looijmans
System Expert

TOPIC Embedded Products B.V.
Materiaalweg 4, 5681 RJ Best
The Netherlands

T: +31 (0) 499 33 69 69
E: [email protected]
W: www.topic.nl