clk: qcom: Add spmi_pmic clock divider support
PATCH v6 1/1 clk: qcom: Add spmi_pmic clock divider support
Clkdiv module provides a clock output on the PMIC with CXO as the source. This clock can be routed through PMIC GPIOs. Add a device driver to configure this clkdiv module.
--- .../bindings/clock/clk-spmi-pmic-div.txt | 59 ++++ drivers/clk/qcom/Kconfig | 9 + drivers/clk/qcom/Makefile | 1 + drivers/clk/qcom/clk-spmi-pmic-div.c | 308 +++++++++++++++++++++ 4 files changed, 377 insertions(+) create mode 100644 Documentation/devicetree/bindings/clock/clk-spmi-pmic-div.txt create mode 100644 drivers/clk/qcom/clk-spmi-pmic-div.c
Documentation/devicetree/bindings/clock/clk-spmi-pmic-div.txt new file +59 -0
@@ -0,0 +1,59 @@ +Qualcomm Technologies, Inc. SPMI PMIC clock divider (clkdiv) + +clkdiv configures the clock frequency of a set of outputs on the PMIC. +These clocks are typically wired through alternate functions on +gpio pins. + +======================= +Properties +======================= + +- compatible + Usage: required + Value type: <string> + Definition: must be "qcom,spmi-clkdiv". + +- reg + Usage: required + Value type: <prop-encoded-array> + Definition: base address of CLKDIV peripherals. + +- qcom,num-clkdivs + Usage: required + Value type: <u32> + Definition: number of CLKDIV peripherals. + +- clocks: + Usage: required + Value type: <prop-encoded-array> + Definition: reference to the xo clock. + +- clock-names: + Usage: required + Value type: <stringlist> + Definition: must be "xo". + +- clock-cells: + Usage: required + Value type: <u32> + Definition: shall contain 1. + +======= +Example +======= + +pm8998_clk_divs: clock-controller@5b00 { + compatible = "qcom,spmi-clkdiv"; + reg = <0x5b00>; + #clock-cells = <1>; + qcom,num-clkdivs = <3>; + clocks = <&xo_board>; + clock-names = "xo"; + + assigned-clocks = <&pm8998_clk_divs 1>, + <&pm8998_clk_divs 2>, + <&pm8998_clk_divs 3>; + assigned-clock-rates = <9600000>, + <9600000>, + <9600000>; +};
drivers/clk/qcom/Kconfig +9 -0
@@ -196,3 +196,12 @@ config MSM_MMCC_8996 Support for the multimedia clock controller on msm8996 devices. Say Y if you want to support multimedia devices such as display, graphics, video encode/decode, camera, etc. + +config SPMI_PMIC_CLKDIV + tristate "SPMI PMIC clkdiv Support" + depends on (COMMON_CLK_QCOM && SPMI) || COMPILE_TEST + help + This driver supports the clkdiv functionality on the Qualcomm + Technologies, Inc. SPMI PMIC. It configures the frequency of + clkdiv outputs of the PMIC. These clocks are typically wired + through alternate functions on GPIO pins.
drivers/clk/qcom/Makefile +1 -0
@@ -34,3 +34,4 @@ obj-$(CONFIG_MSM_MMCC_8974) += mmcc-msm8974.o obj-$(CONFIG_MSM_MMCC_8996) += mmcc-msm8996.o obj-$(CONFIG_QCOM_CLK_RPM) += clk-rpm.o obj-$(CONFIG_QCOM_CLK_SMD_RPM) += clk-smd-rpm.o +obj-$(CONFIG_SPMI_PMIC_CLKDIV) += clk-spmi-pmic-div.o
drivers/clk/qcom/clk-spmi-pmic-div.c new file +308 -0
308 lines not on this page · raw message
Signature · 6 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 6 lines · Tirupathi Reddy
Clkdiv module provides a clock output on the PMIC with CXO as the source. This clock can be routed through PMIC GPIOs. Add a device driver to configure this clkdiv module.
Signed-off-by Tirupathi Reddy <[email protected]>Signed-off-by Stephen Boyd <[email protected]>
Normally your S-o-B would be last.
Quoted 2 lines
--- .../bindings/clock/clk-spmi-pmic-div.txt | 59 ++++
Please split bindings to a separate patch.
Otherwise,
Quoted 6 lines
drivers/clk/qcom/Kconfig | 9 + drivers/clk/qcom/Makefile | 1 + drivers/clk/qcom/clk-spmi-pmic-div.c | 308 +++++++++++++++++++++ 4 files changed, 377 insertions(+) create mode 100644 Documentation/devicetree/bindings/clock/clk-spmi-pmic-div.txt create mode 100644 drivers/clk/qcom/clk-spmi-pmic-div.c
Documentation/devicetree/bindings/clock/clk-spmi-pmic-div.txt
Quoted 5 lines · Tirupathi Reddy
Documentation/devicetree/bindings/clock/clk-spmi-pmic-div.txt new file +0
-0
Please move this to qcom,spmi-clkdiv.txt like other qcom bindings.
Quoted 15 lines
Documentation/devicetree/bindings/clock/clk-spmi-pmic-div.txt new file +14
-0@@ -0,0 +1,59 @@ +Qualcomm Technologies, Inc. SPMI PMIC clock divider (clkdiv) + +clkdiv configures the clock frequency of a set of outputs on the PMIC. +These clocks are typically wired through alternate functions on +gpio pins. + +======================= +Properties +======================= + +- compatible + Usage: required + Value type: <string> + Definition: must be "qcom,spmi-clkdiv".
Documentation/devicetree/bindings/clock/clk-spmi-pmic-div.txt line 24
Quoted 10 lines
Documentation/devicetree/bindings/clock/clk-spmi-pmic-div.txt new file +10
-0+ +- reg + Usage: required + Value type: <prop-encoded-array> + Definition: base address of CLKDIV peripherals. + +- qcom,num-clkdivs + Usage: required + Value type: <u32> + Definition: number of CLKDIV peripherals.
Would it work if we read the registers and looked for the clkdiv subtype ID? If we read something that doesn't match, break and stop adding clks? Or does reading the next "peripheral" cause some sort of crash and burn scenario where the device see an access control violation? Would be interesting to do it that way and avoid needing a new property in DT.
Quoted 8 lines
Documentation/devicetree/bindings/clock/clk-spmi-pmic-div.txt new file +8
-0+ + + parent_name = of_clk_get_parent_name(of_node, 0); + if (!parent_name) { + dev_err(dev, "missing parent clock\n"); + return -ENODEV; + } +
Documentation/devicetree/bindings/clock/clk-spmi-pmic-div.txt line 42
Quoted 10 lines
Documentation/devicetree/bindings/clock/clk-spmi-pmic-div.txt new file +10
-0+ init.parent_names = &parent_name; + init.num_parents = 1; + init.ops = &clk_spmi_pmic_div_ops; + + for (i = 0, clkdiv = cc->clks; i < nclks; i++) { + spin_lock_init(&clkdiv[i].lock); + clkdiv[i].base = start + i * 0x100; + clkdiv[i].regmap = regmap; + clkdiv[i].cxo_period_ns = NSEC_PER_SEC / cxo_hz; + init.name = kasprintf(GFP_KERNEL, "div_clk%d", i + 1);
Hmm. Maybe we should just have this on the stack. 20 characters should be plenty?
Quoted 6 lines
Documentation/devicetree/bindings/clock/clk-spmi-pmic-div.txt new file +6
-0+ clkdiv[i].hw.init = &init; + + ret = devm_clk_hw_register(dev, &clkdiv[i].hw); + kfree(init.name); /* clk framework made a copy */ + if (ret) + return ret;
Documentation/devicetree/bindings/clock/clk-spmi-pmic-div.txt line 58
Quoted 10 lines
Documentation/devicetree/bindings/clock/clk-spmi-pmic-div.txt new file +10
-0+ } + + return of_clk_add_hw_provider(of_node, spmi_pmic_div_clk_hw_get, cc); +} + +static int spmi_pmic_clkdiv_remove(struct platform_device *pdev) +{ + of_clk_del_provider(pdev->dev.of_node); + + return 0;
This can use devm now.
Documentation/devicetree/bindings/clock/clk-spmi-pmic-div.txt
Quoted 6 lines
Documentation/devicetree/bindings/clock/clk-spmi-pmic-div.txt new file +6
-0+} + +static const struct of_device_id spmi_pmic_clkdiv_match_table[] = { + { .compatible = "qcom,spmi-clkdiv" }, + { /* sentinel */ } +};
Nice!
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
Quoted 7 lines · Stephen Boyd
Documentation/devicetree/bindings/clock/clk-spmi-pmic-div.txt
Quoted 5 lines · Tirupathi Reddy
Documentation/devicetree/bindings/clock/clk-spmi-pmic-div.txt new file +0
-0Please move this to qcom,spmi-clkdiv.txt like other qcom bindings.
Addressed in next patch version[7]
Quoted 24 lines
Quoted 24 lines
Documentation/devicetree/bindings/clock/clk-spmi-pmic-div.txt new file +22
-0@@ -0,0 +1,59 @@ +Qualcomm Technologies, Inc. SPMI PMIC clock divider (clkdiv) + +clkdiv configures the clock frequency of a set of outputs on the PMIC. +These clocks are typically wired through alternate functions on +gpio pins. + +======================= +Properties +======================= + +- compatible + Usage: required + Value type: <string> + Definition: must be "qcom,spmi-clkdiv". + +- reg + Usage: required + Value type: <prop-encoded-array> + Definition: base address of CLKDIV peripherals. + +- qcom,num-clkdivs + Usage: required
Quoted 8 lines
Documentation/devicetree/bindings/clock/clk-spmi-pmic-div.txt line 24
Quoted 2 lines
Documentation/devicetree/bindings/clock/clk-spmi-pmic-div.txt new file +2
-0+ Value type: <u32> + Definition: number of CLKDIV peripherals.Would it work if we read the registers and looked for the clkdiv subtype ID? If we read something that doesn't match, break and stop adding clks? Or does reading the next "peripheral" cause some sort of crash and burn scenario where the device see an access control violation? Would be interesting to do it that way and avoid needing a new property in DT.
I feel it is better to go with the current design as we beforehand know the #div-clk peripherals in a PMIC. Reading the next peripheral might result in an unknown failure if there is no real peripheral there (PMIC peripherals are not in contiguous address space).
Quoted 12 lines
Quoted 12 lines
Documentation/devicetree/bindings/clock/clk-spmi-pmic-div.txt new file +12
-0+ + + parent_name = of_clk_get_parent_name(of_node, 0); + if (!parent_name) { + dev_err(dev, "missing parent clock\n"); + return -ENODEV; + } + + init.parent_names = &parent_name; + init.num_parents = 1; + init.ops = &clk_spmi_pmic_div_ops; +
Quoted 8 lines
Documentation/devicetree/bindings/clock/clk-spmi-pmic-div.txt line 42
Quoted 6 lines
Documentation/devicetree/bindings/clock/clk-spmi-pmic-div.txt new file +6
-0+ for (i = 0, clkdiv = cc->clks; i < nclks; i++) { + spin_lock_init(&clkdiv[i].lock); + clkdiv[i].base = start + i * 0x100; + clkdiv[i].regmap = regmap; + clkdiv[i].cxo_period_ns = NSEC_PER_SEC / cxo_hz; + init.name = kasprintf(GFP_KERNEL, "div_clk%d", i + 1);Hmm. Maybe we should just have this on the stack. 20 characters should be plenty?
Addressed in next patch version[7]
Quoted 9 lines
Quoted 9 lines
Documentation/devicetree/bindings/clock/clk-spmi-pmic-div.txt new file +9
-0+ clkdiv[i].hw.init = &init; + + ret = devm_clk_hw_register(dev, &clkdiv[i].hw); + kfree(init.name); /* clk framework made a copy */ + if (ret) + return ret; + } + + return of_clk_add_hw_provider(of_node, spmi_pmic_div_clk_hw_get, cc);
Quoted 8 lines
Documentation/devicetree/bindings/clock/clk-spmi-pmic-div.txt line 58
Quoted 7 lines
Documentation/devicetree/bindings/clock/clk-spmi-pmic-div.txt new file +7
-0+} + +static int spmi_pmic_clkdiv_remove(struct platform_device *pdev) +{ + of_clk_del_provider(pdev->dev.of_node); + + return 0;This can use devm now.
Addressed in next patch version.
Quoted 7 lines
Documentation/devicetree/bindings/clock/clk-spmi-pmic-div.txt
Quoted 6 lines
Documentation/devicetree/bindings/clock/clk-spmi-pmic-div.txt new file +6
-0+} + +static const struct of_device_id spmi_pmic_clkdiv_match_table[] = { + { .compatible = "qcom,spmi-clkdiv" }, + { /* sentinel */ } +};Nice!
Thanks
Quoted 8 lines · Rob Herring
Quoted 6 lines · Tirupathi Reddy
Clkdiv module provides a clock output on the PMIC with CXO as the source. This clock can be routed through PMIC GPIOs. Add a device driver to configure this clkdiv module.
Signed-off-by Tirupathi Reddy <[email protected]>Signed-off-by Stephen Boyd <[email protected]>Normally your S-o-B would be last.
Addressed in next patch version [7]
Quoted 4 lines
Quoted 3 lines
--- .../bindings/clock/clk-spmi-pmic-div.txt | 59 ++++Please split bindings to a separate patch.
Addressed in next patch version [7]
Quoted 11 lines
Otherwise,
Acked-by Rob Herring <[email protected]>Quoted 6 lines
drivers/clk/qcom/Kconfig | 9 + drivers/clk/qcom/Makefile | 1 + drivers/clk/qcom/clk-spmi-pmic-div.c | 308 +++++++++++++++++++++ 4 files changed, 377 insertions(+)create mode 100644
Documentation/devicetree/bindings/clock/clk-spmi-pmic-div.txtcreate mode 100644drivers/clk/qcom/clk-spmi-pmic-div.c