clk: Add fixed-clock-nvmem provider
Subsystems (2)
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.1d0217a8-661f-4359-b77b-02222c761b01@emailsignatures365.codetwo.com
PATCH v3 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 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 | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/clock/fixed-clock.yaml +24 -1
@@ -12,7 +12,9 @@ maintainers: properties: compatible: - const: fixed-clock + enum: + - fixed-clock + - fixed-clock-nvmem "#clock-cells": const: 0
@@ -33,6 +35,27 @@ required: additionalProperties: false +if: + properties: + compatible: + contains: + const: fixed-clock-nvmem + +then: + properties: + nvmem-cells: + 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: + items: + - const: clock-frequency + - const: clock-accuracy + examples: - | clock {
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
PATCH v3 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.
---
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
@@ -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
@@ -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
Re: [PATCH v3 1/2] dt-bindings: clock: fixed-clock: Add nvmem support
In reply to Mike LooijmansQuoted 30 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.
Signed-off-by Mike Looijmans <[email protected]>---
Changes in v3:
Modify fixed-clock instead of introducing nvmem-clockChanges in v2:
Changed "fixed-clock" into "nvmem-clock" in dts example Add minItems:1 to nvmem-cell-names.../bindings/clock/fixed-clock.yaml | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)Documentation/devicetree/bindings/clock/fixed-clock.yaml +0
-0
Documentation/devicetree/bindings/clock/fixed-clock.yaml maintainers: · line 17
Quoted 7 lines
Documentation/devicetree/bindings/clock/fixed-clock.yaml +3
-1@@ -12,7 +12,9 @@ maintainers: properties: compatible: - const: fixed-clock + enum: + - fixed-clock + - fixed-clock-nvmem
Do you even need new compatible? Isn't this the same clock from the hardware point of view?
Documentation/devicetree/bindings/clock/fixed-clock.yaml required: · line 37
Quoted 7 lines
Documentation/devicetree/bindings/clock/fixed-clock.yaml +0
-0"#clock-cells": const: 0@@ -33,6 +35,27 @@ required: additionalProperties: false
Put it under allOf. Entire block should be before additionalProperties (just like in example-schema).
Documentation/devicetree/bindings/clock/fixed-clock.yaml required: · line 47
Quoted 10 lines
Documentation/devicetree/bindings/clock/fixed-clock.yaml +10
-0+if: + properties: + compatible: + contains: + const: fixed-clock-nvmem + +then: + properties: + nvmem-cells: + maxItems: 2
Anyway, I don't think you tested it. Provide a DTS user of this. I don't think it works and such user would point to mistakes.
Properties should be defined in top-level properties:, not in allOf:if:then. In allOf:if:then you only narrow them.
Documentation/devicetree/bindings/clock/fixed-clock.yaml required: · line 53
Quoted 6 lines
Documentation/devicetree/bindings/clock/fixed-clock.yaml +6
-0+ 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. +
Best regards,
Krzysztof
Re: [PATCH v3 1/2] dt-bindings: clock: fixed-clock: Add nvmem support
Quoted 32 lines · Krzysztof Kozlowski
Quoted 31 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.
Signed-off-by Mike Looijmans <[email protected]>---
Changes in v3:
Modify fixed-clock instead of introducing nvmem-clockChanges in v2:
Changed "fixed-clock" into "nvmem-clock" in dts example Add minItems:1 to nvmem-cell-names.../bindings/clock/fixed-clock.yaml | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)Documentation/devicetree/bindings/clock/fixed-clock.yaml +0
-0@@ -12,7 +12,9 @@ maintainers:
Quoted 8 lines
Documentation/devicetree/bindings/clock/fixed-clock.yaml maintainers: · line 17
Quoted 6 lines
Documentation/devicetree/bindings/clock/fixed-clock.yaml +3
-1properties: compatible: - const: fixed-clock + enum: + - fixed-clock + - fixed-clock-nvmemDo you even need new compatible? Isn't this the same clock from the hardware point of view?
I need a new compatible because a "fixed-clock" only loads at init time. It registers using CLK_OF_DECLARE, which requires the clock to register early. NVMEM providers are typical devices like I2C EEPROMs that won't be available at that point, hence I needed to create a clock that registers as a regular clock driver and can handle deferral and similar.
Quoted 23 lines
Documentation/devicetree/bindings/clock/fixed-clock.yaml required: · line 37
Quoted 7 lines
Documentation/devicetree/bindings/clock/fixed-clock.yaml +0
-0"#clock-cells": const: 0@@ -33,6 +35,27 @@ required: additionalProperties: falsePut it under allOf. Entire block should be before additionalProperties (just like in example-schema).
Documentation/devicetree/bindings/clock/fixed-clock.yaml required: · line 47
Quoted 10 lines
Documentation/devicetree/bindings/clock/fixed-clock.yaml +10
-0+if: + properties: + compatible: + contains: + const: fixed-clock-nvmem + +then: + properties: + nvmem-cells: + maxItems: 2Anyway, I don't think you tested it. Provide a DTS user of this. I don't think it works and such user would point to mistakes.
Quoted 2 lines
Properties should be defined in top-level properties:, not in allOf:if:then. In allOf:if:then you only narrow them.
Ah, got it. Added an example dts block to the document, this revealed the issues, indeed didn't test the bindings.
Fixed it into an "allOf" to properly narrow the properties.
I'll test and post a v4 in a jiffie.
Quoted 10 lines
Documentation/devicetree/bindings/clock/fixed-clock.yaml required: · line 53
Quoted 7 lines
Documentation/devicetree/bindings/clock/fixed-clock.yaml +6
-0+ 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. +Best regards,
Krzysztof
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
Re: [PATCH v3 1/2] dt-bindings: clock: fixed-clock: Add nvmem support
Quoted 42 lines · Mike Looijmans
Quoted 32 lines · Krzysztof Kozlowski
Quoted 31 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.
Signed-off-by Mike Looijmans <[email protected]>---
Changes in v3:
Modify fixed-clock instead of introducing nvmem-clockChanges in v2:
Changed "fixed-clock" into "nvmem-clock" in dts example Add minItems:1 to nvmem-cell-names.../bindings/clock/fixed-clock.yaml | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)Documentation/devicetree/bindings/clock/fixed-clock.yaml +0
-0@@ -12,7 +12,9 @@ maintainers:Quoted 8 lines
Documentation/devicetree/bindings/clock/fixed-clock.yaml maintainers: · line 17
Quoted 6 lines
Documentation/devicetree/bindings/clock/fixed-clock.yaml +3
-1properties: compatible: - const: fixed-clock + enum: + - fixed-clock + - fixed-clock-nvmemDo you even need new compatible? Isn't this the same clock from the hardware point of view?
Quoted 5 lines
I need a new compatible because a "fixed-clock" only loads at init time. It registers using
CLK_OF_DECLARE, which requires the clock to register early. NVMEM providers are typical devices like I2C EEPROMs that won't be available at that point, hence I needed to create a clock that registers as a regular clock driver and can handle deferral and similar.
Ah, ok.
Quoted 25 lines
Quoted 25 lines
Documentation/devicetree/bindings/clock/fixed-clock.yaml required: · line 37
Quoted 9 lines
Documentation/devicetree/bindings/clock/fixed-clock.yaml +0
-0"#clock-cells": const: 0@@ -33,6 +35,27 @@ required: additionalProperties: falsePut it under allOf. Entire block should be before additionalProperties (just like in example-schema).
Documentation/devicetree/bindings/clock/fixed-clock.yaml required: · line 47
Quoted 10 lines
Documentation/devicetree/bindings/clock/fixed-clock.yaml +10
-0+if: + properties: + compatible: + contains: + const: fixed-clock-nvmem + +then: + properties: + nvmem-cells: + maxItems: 2Anyway, I don't think you tested it. Provide a DTS user of this. I don't think it works and such user would point to mistakes.
Quoted 7 lines
Quoted 2 lines
Properties should be defined in top-level properties:, not in allOf:if:then. In allOf:if:then you only narrow them.
Ah, got it. Added an example dts block to the document, this revealed the issues, indeed didn't test the bindings.
Fixed it into an "allOf" to properly narrow the properties.
The real DTS user would be also welcomed.
Best regards,
Krzysztof
Stephen Boyd
maintainerRe: [PATCH v3 1/2] dt-bindings: clock: fixed-clock: Add nvmem support
In reply to Mike LooijmansQuoting Mike Looijmans (2023-06-05 07:00:16)
Quoted 17 lines · Krzysztof Kozlowski
Quoted 7 lines · Mike Looijmans
Quoted 6 lines
Documentation/devicetree/bindings/clock/fixed-clock.yaml +0
-0@@ -12,7 +12,9 @@ maintainers:Quoted 8 lines
Documentation/devicetree/bindings/clock/fixed-clock.yaml maintainers: · line 17
Quoted 6 lines
Documentation/devicetree/bindings/clock/fixed-clock.yaml +3
-1properties: compatible: - const: fixed-clock + enum: + - fixed-clock + - fixed-clock-nvmemDo you even need new compatible? Isn't this the same clock from the hardware point of view?
Quoted 5 lines
I need a new compatible because a "fixed-clock" only loads at init time. It registers using
CLK_OF_DECLARE, which requires the clock to register early. NVMEM providers are typical devices like I2C EEPROMs that won't be available at that point, hence I needed to create a clock that registers as a regular clock driver and can handle deferral and similar.
What is builtin_platform_driver(of_fixed_clk_driver)?