Add driver support for ESWIN eic700 SoC clock controller
Subsystems (3)
[email protected]
maintainerv13 cover Add driver support for ESWIN eic700 SoC clock controller
From: Xuyang Dong <[email protected]>
The link [1] provides the official documentation for the EIC7700. Section 3.2 covers the clock subsystem.
[1] https://www.sifive.com/document-file/eic7700x-datasheet
Updates:
Change in v13:
- Updated driver file
- Modify commit subject from "clock: eswin: Add eic7700 clock driver" to "clk: eswin: Add eic7700 clock driver".
- Use parent rate to calculate PLL clock rate.
- Use GENMASK() to define PLL mask macros and use FIELD_PREP() to simplify bitwise operations.
- Remove shift and width references for pll enable, refdiv, fbdiv, frac and postdiv. (Use only the PLL macros to match the functionality)
- Set postdiv1 and postdiv2 in clk_pll_set_rate function.
- Link to v11: https://lore.kernel.org/all/[email protected]/
Change in v12:
- Updated driver file
- Add CLK_MUX_ROUND_CLOSEST to the mux clocks since they need a more accurate clock frequency.
- Change 'rem' from u64 to u32 for function 'eswin_calc_pll' and function 'clk_pll_recalc_rate'.
- Change 'rate' from u64 to unsigned long for function 'clk_pll_recalc_rate'.
- Fix build error with u64 divisor for function `clk_pll_set_rate'.
- Link to v11: https://lore.kernel.org/all/[email protected]/
Change in v11:
- Updated driver file
- Add "Tested-by: Marcel Ziswiler <[email protected]> # ebc77" tag.
- Fix build error in function eswin_clk_register_clks.
- Link to v10: https://lore.kernel.org/all/[email protected]/
Changes in v10:
- Updated driver file
- Add a private clock divider API named 'eswin_register_clkdiv' to register divider clocks with private flag.
Define 'ESWIN_PRIV_DIV_MIN_2' private flag for registering the clock dividers whose division ratio start from 2.
Implement the private set_rate, recalc_rate, and determine_rate accordingly.
- Add CLK_DIVIDER_ALLOW_ZERO flag to the clock dividers whose division ratio start from 0.
- Replace CONFIG_ARCH_ESWIN with CONFIG_COMMON_CLK_ESWIN in the Makefile.
- Modify the help description of COMMON_CLK_EIC7700.
- Move register offset definitions from 'clk-eic7700.h' to 'clk-eic7700.c' and remove the 'clk-eic7700.h'. Remove '_CTRL' from the offset names.
- Remove all unused headers.
- Use devm_platform_ioremap_resource() instead of devm_of_iomap().
- Export the functions from clk.c as symbols.
- Use readl_poll_timeout().
- Use 'clk_parent_data' and '.hw' instead of string parent names.
- Rename the header file from clk.h to common.h.
- Rename macros from EIC7700_* to ESWIN_* in common.h.
- Add a new function, 'eswin_clk_register_clks', which can register divider, mux, gate, and fixed-factor clocks based on their types.
- Add structure 'eswin_clk_info' to manage the clocks that need to be registered in a specific order.
- Add macros 'ESWIN_*_TYPE' to define divider, mux, gate, and fixed-factor clocks with type. Add enum 'eswin_clk_type' for these types.
- Remove 'eswin_clk_register_mux_tbl'. Use 'eswin_clk_register_mux' to register mux clocks with or without table.
- Add xtal24m as the parent clock of the PLL.
- Change 2025 to 2026 in all files.
- Link to v9: https://lore.kernel.org/all/[email protected]/
Changes in v9:
- Updated driver file
- Checked return values of eswin_clk_register_*() in the probe function.
- Removed binding IDs check from pll functions in clk.c, as these functions were exclusively used by pll clocks and did not require ID validation.
- The PLL structure has been extended with max_rate and min_rate fields to explicitly define the frequency operating range of the PLL. These limits were now utilized by the clk_pll_determine_rate() function.
- Removed __clk_lookup() in clk_pll_set_rate. Added clk_notifier support in clk-eic7700.c.
- Added five previously missing clocks from [1].
- Link to v8: https://lore.kernel.org/all/[email protected]/
Changes in v8:
- Updated YAML file
- Added "Acked-by: Troy Mitchell <[email protected]>"
- Updated driver file
- Changed Kconfig from bool to tristate.
- Updated MAINTAINERS file
- Added "ESWIN SOC SERIES CLOCK DRIVER"
- Link to v7: https://lore.kernel.org/all/[email protected]/
Changes in v7:
- Updated YAML file
- Added "Acked-by: Conor Dooley <[email protected]>" for bindings.
- Updated driver file
- Added description for clk of eswin_calc_pll().
- Added macro EIC7700_MUX_TBL to manage mux clock-tree.
- Added eswin_clk_register_mux_tbl() to register mux clocks with discontinuous parent indexes.
- Link to v6: https://lore.kernel.org/all/[email protected]/
Changes in v6:
- Removed config option patch dependency from cover letter, because the patch was applied.
- Updated YAML file
- Added an oscillator as the clock input, named xtal24m.
- Added clocks property.
- Updated driver file
- Replaced fixed_rate_clk_xtal_24m with xtal24m.
- Dropped fixed_rate_clk_xtal_24m from driver. Because clock xtal24m was registered by fixed-clock as oscillator.
- Link to v5: https://lore.kernel.org/all/[email protected]/
Changes in v5:
- Removed vendor prefix patch dependency from cover letter, because the patch was applied.
- Updated YAML file
- Placed the required after all properties.
- Removed patternProperties. Also removed compatible of eswin,pll-clock, eswin,mux-clock, eswin,divider-clock and eswin,gate-clock as we have moved clock tree from DTS to Linux driver.
- Removed the clock tree from DTS. Used clock-controller to manage all clock. Removed all child nodes in clock-controller.
- Removed '#address-cells' and '#size-cells' properties, because the clock controller did not need to define these properties.
- Removed eic7700-clocks.dtsi.
- Added dt-bindings header for clock IDs. Because used the IDs to register clocks.
- Updated driver file
- Modified the commit for clock driver. Dropped indentation in commit.
- Removed CLK_OF_DECLARE(). Used *clk_hw_register* to register clocks. Used devm_of_clk_add_hw_provider.
- Dropped singletons.
- Checked the value right after obtaining it.
- Removed the definitions of macro frequency in clk.h like CLK_FREQ_24M.
- Modified description of help in Kconfig.
- Added COMPILE_TEST. Added COMMON_CLK_ESWIN for clk.o. And added "select COMMON_CLK_ESWIN" for clk-eic7700.c. Without COMMON_CLK_EIC7700, clk.c could not be compiled.
- Used .determined_rate.
- Added macro definitions of EIC7700_DIV, EIC7700_FIXED, EIC7700_FACTOR, EIC7700_MUX and EIC7700_PLL to manage clock tree.
- Added clk-eic7700.h to place eic7700 SoC clock registers.
- Removed refdiv_val and postdiv1_val from clk_pll_recalc_rate(). Because these values were unused.
- Link to v4: https://lore.kernel.org/all/[email protected]/
Changes in v4:
- Updated YAML file
- Changed name from cpu-default-frequency to cpu-default-freq-hz.
- Dropped $ref of cpu-default-frequency.
- Added cpu-default-frequency for required.
- Removed cpu-default-frequency in updated file, because there was no need to add cpu-default-frequency.
- Moved DIVIDER to DIV.
- Arranged the IDs in order.
- Dropped EIC7700_NR_CLKS.
- Removed dt-bindings eswin,eic7700-clock.h. Because IDs was not used, and used clock device nodes.
- According to the updated driver codes, the YAML has been updated.
- Updated driver file
- Remove undocumented parameters "cpu_no_boost_1_6ghz" and "cpu-default-frequency".
- Modified the comment and used the correct Linux coding style.
- Removed codes of voltage, because it was not the clock driver.
- Updated the formula of clock frequency calculation. Removed the logic that only used register selection.
- Used CLK_OF_DECLARE() to register clocks. Registered pll-clock, mux-clock, divider-clock, and gate-clock in clk-eic7700.c. The specific implementation of clock registration was in clk.c.
- Added eic7700-clocks.dtsi.
- Moved device information to DTS. Put all clocks' node in the eic7700-clocks.dtsi.
- Link to v3: https://lore.kernel.org/all/[email protected]/
Changes in v3:
- Update example, drop child node and add '#clock-cells' to the parent
node.
- Change parent node from sys-crg to clock-controller for this yaml.
- Drop "syscon", "simple-mfd" to clear warnings/errors by using "make dt_binding_check". And these are not necessary.
- Add "cpu-default-frequency" definition in yaml for "undocumented ABI".
- Drop Reviewed-by, this is misunderstanding. We have not received such
an email.
- Link to v2: https://lore.kernel.org/all/[email protected]/
Changes in v2:
- Update example, drop child node.
- Clear warnings/errors for using "make dt_binding_check".
- Change to the correct format.
- Drop some non-stanard code.
- Use dev_err_probe() in probe functions.
- Link to v1: https://lore.kernel.org/all/[email protected]/
Xuyang Dong (3):
dt-bindings: clock: eswin: Documentation for eic7700 SoC
clk: eswin: Add eic7700 clock driver
MAINTAINERS: Add entry for ESWIN EIC7700 clock driver
.../bindings/clock/eswin,eic7700-clock.yaml | 46 + MAINTAINERS | 8 + drivers/clk/Kconfig | 1 + drivers/clk/Makefile | 1 + drivers/clk/eswin/Kconfig | 15 + drivers/clk/eswin/Makefile | 8 + drivers/clk/eswin/clk-eic7700.c | 1357 +++++++++++++++++ drivers/clk/eswin/clk.c | 591 +++++++ drivers/clk/eswin/common.h | 341 +++++ .../dt-bindings/clock/eswin,eic7700-clock.h | 285 ++++ 10 files changed, 2653 insertions(+) create mode 100644 Documentation/devicetree/bindings/clock/eswin,eic7700-clock.yaml create mode 100644 drivers/clk/eswin/Kconfig create mode 100644 drivers/clk/eswin/Makefile create mode 100644 drivers/clk/eswin/clk-eic7700.c create mode 100644 drivers/clk/eswin/clk.c create mode 100644 drivers/clk/eswin/common.h create mode 100644 include/dt-bindings/clock/eswin,eic7700-clock.h
--
2.43.0
[email protected]
maintainerPATCH v13 1/3 dt-bindings: clock: eswin: Documentation for eic7700 SoC
From: Xuyang Dong <[email protected]>
Add device tree binding documentation for the ESWIN eic7700 clock controller module.
--- .../bindings/clock/eswin,eic7700-clock.yaml | 46 +++ .../dt-bindings/clock/eswin,eic7700-clock.h | 285 ++++++++++++++++++ 2 files changed, 331 insertions(+) create mode 100644 Documentation/devicetree/bindings/clock/eswin,eic7700-clock.yaml create mode 100644 include/dt-bindings/clock/eswin,eic7700-clock.h
Documentation/devicetree/bindings/clock/eswin,eic7700-clock.yaml new file +46 -0
@@ -0,0 +1,46 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/clock/eswin,eic7700-clock.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Eswin EIC7700 SoC clock controller + +maintainers: + - Yifeng Huang <[email protected]> + - Xuyang Dong <[email protected]> + +description: + The clock controller generates and supplies clock to all the modules + for eic7700 SoC. + +properties: + compatible: + const: eswin,eic7700-clock + + reg: + maxItems: 1 + + clocks: + items: + - description: External 24MHz oscillator clock + + '#clock-cells': + const: 1 + +required: + - compatible + - reg + - clocks + - '#clock-cells' + +additionalProperties: false + +examples: + - | + clock-controller@51828000 { + compatible = "eswin,eic7700-clock"; + reg = <0x51828000 0x300>; + clocks = <&xtal24m>; + #clock-cells = <1>; + };
include/dt-bindings/clock/eswin,eic7700-clock.h new file +285 -0
285 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
maintainerPATCH v13 2/3 clk: eswin: Add eic7700 clock driver
In reply to [email protected]From: Xuyang Dong <[email protected]>
Add clock drivers for the EIC7700 SoC. The clock controller on the ESWIN EIC7700 provides various clocks to different IP blocks within the SoC.
--- drivers/clk/Kconfig | 1 + drivers/clk/Makefile | 1 + drivers/clk/eswin/Kconfig | 15 + drivers/clk/eswin/Makefile | 8 + drivers/clk/eswin/clk-eic7700.c | 1357 +++++++++++++++++++++++++++++++ drivers/clk/eswin/clk.c | 591 ++++++++++++++ drivers/clk/eswin/common.h | 341 ++++++++ 7 files changed, 2314 insertions(+) create mode 100644 drivers/clk/eswin/Kconfig create mode 100644 drivers/clk/eswin/Makefile create mode 100644 drivers/clk/eswin/clk-eic7700.c create mode 100644 drivers/clk/eswin/clk.c create mode 100644 drivers/clk/eswin/common.h
drivers/clk/Kconfig +1 -0
@@ -504,6 +504,7 @@ source "drivers/clk/analogbits/Kconfig" source "drivers/clk/aspeed/Kconfig" source "drivers/clk/baikal-t1/Kconfig" source "drivers/clk/bcm/Kconfig" +source "drivers/clk/eswin/Kconfig" source "drivers/clk/hisilicon/Kconfig" source "drivers/clk/imgtec/Kconfig" source "drivers/clk/imx/Kconfig"
drivers/clk/Makefile +1 -0
@@ -120,6 +120,7 @@ obj-$(CONFIG_CLK_BAIKAL_T1) += baikal-t1/ obj-y += bcm/ obj-$(CONFIG_ARCH_BERLIN) += berlin/ obj-$(CONFIG_ARCH_DAVINCI) += davinci/ +obj-$(CONFIG_COMMON_CLK_ESWIN) += eswin/ obj-$(CONFIG_ARCH_HISI) += hisilicon/ obj-y += imgtec/ obj-y += imx/
drivers/clk/eswin/Kconfig new file +15 -0
@@ -0,0 +1,15 @@ +# SPDX-License-Identifier: GPL-2.0 + +config COMMON_CLK_ESWIN + bool + +config COMMON_CLK_EIC7700 + tristate "EIC7700 Clock Driver" + depends on ARCH_ESWIN || COMPILE_TEST + select COMMON_CLK_ESWIN + default ARCH_ESWIN + help + This driver provides support for clock controller on ESWIN EIC7700 + SoC. The clock controller generates and supplies clocks to various + peripherals within the SoC. + Say yes here to support the clock controller on the EIC7700 SoC.
drivers/clk/eswin/Makefile new file +8 -0
@@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Eswin Clock specific Makefile +# + +obj-$(CONFIG_COMMON_CLK_ESWIN) += clk.o + +obj-$(CONFIG_COMMON_CLK_EIC7700) += clk-eic7700.o
drivers/clk/eswin/clk-eic7700.c new file +1357 -0
1,357 lines not on this page · raw message
drivers/clk/eswin/clk.c new file +591 -0
591 lines not on this page · raw message
drivers/clk/eswin/common.h new file +341 -0
341 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
maintainerPATCH v13 3/3 MAINTAINERS: Add entry for ESWIN EIC7700 clock driver
In reply to [email protected]From: Xuyang Dong <[email protected]>
Add myself as maintainer of ESWIN EIC7700 clock driver
--- MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
@@ -9500,6 +9500,14 @@ T: git https://github.com/eswincomputing/linux-next.git F: Documentation/devicetree/bindings/riscv/eswin.yaml F: arch/riscv/boot/dts/eswin/ +ESWIN EIC7700 CLOCK DRIVER +M: Yifeng Huang <[email protected]> +M: Xuyang Dong <[email protected]> +S: Maintained +F: Documentation/devicetree/bindings/clock/eswin,eic7700-clock.yaml +F: drivers/clk/eswin/ +F: include/dt-bindings/clock/eswin,eic7700-clock.h + ET131X NETWORK DRIVER M: Mark Einon <[email protected]> S: Odd Fixes
Signature · 1 line
2.43.0
Re: [PATCH v13 2/3] clk: eswin: Add eic7700 clock driver
In reply to [email protected]Hi Xuyang,
Quoted 8 lines · On Sat, Feb 14, 2026 at 06:15:19PM +0800, [email protected] wrote:
From: Xuyang Dong <[email protected]>
Add clock drivers for the EIC7700 SoC. The clock controller on the ESWIN EIC7700 provides various clocks to different IP blocks within the SoC.
Signed-off-by Yifeng Huang <[email protected]>Signed-off-by Xuyang Dong <[email protected]>
Can Marcel retest the new version since some of the logic related to the parent rate changed in the new version? It's probably still fine, however it's good to be sure.
I have some other minor comments / questions below.
[snip]
drivers/clk/eswin/clk-eic7700.c line 1272
Quoted 10 lines
drivers/clk/eswin/clk-eic7700.c new file +10
-0+static int eic7700_clk_probe (struct platform_device *pdev) +{ +struct eswin_clock_data *clk_data; +struct device *dev = &pdev->dev; +struct clk *pll_clk; +int ret; + + clk_data =eswin_clk_init (pdev,EIC7700_NR_CLKS ); +if (!clk_data) +return dev_err_probe (dev, -EAGAIN ,"failed to get clk data!\n" );
Change eswin_clk_init() to return an error code, and return that instead of -EAGAIN. I have more details below inside this function.
Quoted 75 lines
drivers/clk/eswin/clk-eic7700.c new file +75
-0+ + ret =eswin_clk_register_fixed_rate (dev, eic7700_fixed_rate_clks, +ARRAY_SIZE (eic7700_fixed_rate_clks), + clk_data); +if (ret) +return dev_err_probe (dev, ret, +"failed to register fixed rate clock\n" ); + + ret =eswin_clk_register_pll (dev, eic7700_pll_clks, +ARRAY_SIZE (eic7700_pll_clks), + clk_data); +if (ret) +return dev_err_probe (dev, ret, +"failed to register pll clock\n" ); + + pll_clk =devm_clk_hw_get_clk (dev, &eic7700_pll_clks[1 ].hw, +"clk_pll_cpu" ); +if (IS_ERR (pll_clk)) +return dev_err_probe (dev,PTR_ERR (pll_clk), +"failed to get clk_pll_cpu\n" ); + + clk_data->pll_nb.notifier_call = eic7700_clk_pll_cpu_notifier_cb; + ret =devm_clk_notifier_register (dev, pll_clk, &clk_data->pll_nb); +if (ret) +return ret; + + ret =eswin_clk_register_fixed_factor (dev, eic7700_factor_clks, +ARRAY_SIZE (eic7700_factor_clks), + clk_data); +if (ret) +return dev_err_probe (dev, ret, +"failed to register fixed factor clock\n" ); + + ret =eswin_clk_register_divider (dev, eic7700_div_clks, +ARRAY_SIZE (eic7700_div_clks), + clk_data); +if (ret) +return dev_err_probe (dev, ret, +"failed to register divider clock\n" ); + + ret =eswin_clk_register_gate (dev, eic7700_gate_clks, +ARRAY_SIZE (eic7700_gate_clks), clk_data); +if (ret) +return dev_err_probe (dev, ret, +"failed to register gate clock\n" ); + + ret =eswin_clk_register_clks (dev, eic7700_early_clks, +ARRAY_SIZE (eic7700_early_clks), clk_data); +if (ret) +return dev_err_probe (dev, ret,"failed to register clock\n" ); + + ret =eswin_clk_register_mux (dev, eic7700_mux_clks, +ARRAY_SIZE (eic7700_mux_clks), clk_data); +if (ret) +return dev_err_probe (dev, ret, +"failed to register mux clock\n" ); + + ret =eswin_clk_register_clks (dev, eic7700_clks, +ARRAY_SIZE (eic7700_clks), clk_data); +if (ret) +return dev_err_probe (dev, ret,"failed to register clock\n" ); + +return devm_of_clk_add_hw_provider (dev, of_clk_hw_onecell_get, + &clk_data->clk_data); +} + +static const struct of_device_id eic7700_clock_dt_ids[] = { + { .compatible ="eswin,eic7700-clock" , }, + {/* sentinel */ } +}; +MODULE_DEVICE_TABLE (of, eic7700_clock_dt_ids); + +static struct platform_driver eic7700_clock_driver = { + .probe = eic7700_clk_probe, + .driver = {
drivers/clk/eswin/clk-eic7700.c line 1357
Quoted 10 lines
drivers/clk/eswin/clk-eic7700.c new file +10
-0+ .name = "eic7700-clock", + .of_match_table = eic7700_clock_dt_ids, + }, +}; +module_platform_driver (eic7700_clock_driver); + +MODULE_LICENSE ("GPL" ); +MODULE_AUTHOR ("Yifeng Huang<[email protected]>" ); +MODULE_AUTHOR ("Xuyang Dong<[email protected]>" ); +MODULE_DESCRIPTION ("ESWIN EIC7700 clock controller driver" );
MODULE_ALIAS("platform:eic7700-clk")
Quoted 20 lines
drivers/clk/eswin/clk.c new file +14
-0@@ -0,0 +1,591 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright 2026, Beijing ESWIN Computing Technology Co., Ltd.. +* All rights reserved. +* +* Authors: +* Yifeng Huang <[email protected]> +* Xuyang Dong <[email protected]> +*/ + +#include <linux/bitfield.h> +#include <linux/clk-provider.h> +#include <linux/delay.h> +#include <linux/iopoll.h>
drivers/clk/eswin/clk.c line 24
Quoted 10 lines
drivers/clk/eswin/clk.c new file +10
-0+#include <linux/math.h> +#include <linux/platform_device.h> +#include <linux/slab.h> + +#include "common.h" + +#define PLL_EN_MASK GENMASK(1, 0) +#define PLL_REFDIV_MASK GENMASK(17, 12) +#define PLL_FBDIV_MASK GENMASK(31, 20) +#define PLL_FRAC_MASK GENMASK(27, 4)
uu> +#define PLL_POSTDIV1_MASK GENMASK(10, 8)
Quoted 7 lines
drivers/clk/eswin/clk.c new file +7
-0+#define PLL_POSTDIV2_MASK GENMASK(18, 16) + +struct eswin_clock_data *eswin_clk_init (struct platform_device *pdev, +size_t nr_clks) +{ +struct eswin_clock_data *eclk_data; +
drivers/clk/eswin/clk.c line 42
Quoted 10 lines
drivers/clk/eswin/clk.c new file +10
-0+ eclk_data =devm_kzalloc (&pdev->dev, +struct_size (eclk_data, clk_data.hws, nr_clks), +GFP_KERNEL ); +if (!eclk_data) +return NULL ; + + eclk_data->base =devm_platform_ioremap_resource (pdev,0 ); +if (IS_ERR (eclk_data->base)) { +dev_err (&pdev->dev,"failed to map clock registers\n" ); +return NULL ;
The error code is dropped here. Later, when eswin_clk_init() is called, it will return -EAGAIN. Just return an error in this function. You can return -ENOMEM above.
Quoted 39 lines
drivers/clk/eswin/clk.c new file +39
-0+ } + + eclk_data->clk_data.num = nr_clks; +/* Avoid returning NULL for unused id */ +memset_p ((void **)eclk_data->clk_data.hws,ERR_PTR (-ENOENT ), nr_clks); +spin_lock_init (&eclk_data->lock); + +return eclk_data; +} +EXPORT_SYMBOL_GPL (eswin_clk_init); + +/** +* eswin_calc_pll - calculate PLL values +* @frac_val: fractional divider +* @fbdiv_val: feedback divider +* @rate: reference rate +* @parent_rate: parent rate +* +* Calculate PLL values for frac and fbdiv +*/ +static void eswin_calc_pll (u32 *frac_val,u32 *fbdiv_val,unsigned long rate, +unsigned long parent_rate) +{ +u32 rem, tmp1 =0 , tmp2 =0 , tmp_p; +u64 tmp; + +/* fbdiv = rate * 4 / parent_rate */ + tmp = rate *4 ; + tmp_p = parent_rate; + +do_div (tmp, tmp_p); + + *fbdiv_val = (u32 )tmp; + +/* frac = rate * 4 % parent_rate * (2 ^ 24) */ + tmp = rate *4 ; + rem =do_div (tmp,1000 ); +if (rem) + tmp1 = rem;
drivers/clk/eswin/clk.c line 91
Quoted 10 lines
drivers/clk/eswin/clk.c new file +10
-0+ + rem =do_div (tmp,1000 ); +if (rem) + tmp2 = rem; + + rem =do_div (tmp,24 ); + tmp = (u64)(1000 * (1000 * rem + tmp2) + tmp1) <<24 ; +do_div (tmp, tmp_p); + + *frac_val = (u32 )tmp;
Would it be possible to document in more detail what's going on with these formulas?
Quoted 246 lines
drivers/clk/eswin/clk.c new file +246
-0+} + +static inline struct eswin_clk_pll *to_pll_clk (struct clk_hw *hw) +{ + return container_of(hw, struct eswin_clk_pll, hw); +} + +static int clk_pll_set_rate (struct clk_hw *hw,unsigned long rate, +unsigned long parent_rate) +{ +struct eswin_clk_pll *clk =to_pll_clk (hw); +u32 frac_val, fbdiv_val, val, mask; +int ret; + +eswin_calc_pll (&frac_val, &fbdiv_val, rate, parent_rate); + +/* First, disable pll */ + val =readl_relaxed (clk->ctrl_reg0); + val &= ~PLL_EN_MASK ; + val |=FIELD_PREP (PLL_EN_MASK ,0 ); +writel_relaxed (val, clk->ctrl_reg0); + + val =readl_relaxed (clk->ctrl_reg0); + val &= ~(PLL_REFDIV_MASK |PLL_FBDIV_MASK ); + val |=FIELD_PREP (PLL_FBDIV_MASK , fbdiv_val); + val |=FIELD_PREP (PLL_REFDIV_MASK ,1 ); +writel_relaxed (val, clk->ctrl_reg0); + + val =readl_relaxed (clk->ctrl_reg1); + val &= ~PLL_FRAC_MASK ; + val |=FIELD_PREP (PLL_FRAC_MASK , frac_val); +writel_relaxed (val, clk->ctrl_reg1); + + val =readl_relaxed (clk->ctrl_reg2); + val &= ~(PLL_POSTDIV1_MASK |PLL_POSTDIV2_MASK ); + val |=FIELD_PREP (PLL_POSTDIV1_MASK ,1 ); + val |=FIELD_PREP (PLL_POSTDIV2_MASK ,1 ); +writel_relaxed (val, clk->ctrl_reg2); + +/* Last, enable pll */ + val =readl_relaxed (clk->ctrl_reg0); + val &= ~PLL_EN_MASK ; + val |=FIELD_PREP (PLL_EN_MASK ,1 ); +writel_relaxed (val, clk->ctrl_reg0); + +/* Usually the pll will lock in 50us */ + mask =GENMASK (clk->lock_shift + clk->lock_width -1 , clk->lock_shift); + ret =readl_poll_timeout (clk->status_reg, val, val & mask,1 ,50 *2 ); +if (ret) +pr_err ("failed to lock the pll!\n" ); + +return ret; +} + +static unsigned long clk_pll_recalc_rate (struct clk_hw *hw, +unsigned long parent_rate) +{ +struct eswin_clk_pll *clk =to_pll_clk (hw); +u64 fbdiv_val, frac_val, tmp; +u32 rem, val; + + val =readl_relaxed (clk->ctrl_reg0); + val &=PLL_FBDIV_MASK ; + fbdiv_val = (val >> clk->fbdiv_shift); + + val =readl_relaxed (clk->ctrl_reg1); + val &=PLL_FRAC_MASK ; + frac_val = (val >> clk->frac_shift); + +/* rate = 24000000 * (fbdiv + frac / (2 ^ 24)) / 4 */ + tmp = parent_rate * frac_val; + rem =do_div (tmp,BIT (24 )); +if (rem) + tmp = parent_rate * fbdiv_val + tmp +1 ; +else + tmp = parent_rate * fbdiv_val + tmp; + +do_div (tmp,4 ); + +return tmp; +} + +static int clk_pll_determine_rate (struct clk_hw *hw, +struct clk_rate_request *req) +{ +struct eswin_clk_pll *clk =to_pll_clk (hw); + + req->rate =clamp (req->rate, clk->min_rate, clk->max_rate); + req->min_rate = clk->min_rate; + req->max_rate = clk->max_rate; + +return 0 ; +} + +int eswin_clk_register_fixed_rate (struct device *dev, +struct eswin_fixed_rate_clock *clks, +int nums,struct eswin_clock_data *data) +{ +struct clk_hw *clk_hw; +int i; + +for (i =0 ; i < nums; i++) { + clk_hw =devm_clk_hw_register_fixed_rate (dev, clks[i].name, +NULL , clks[i].flags, + clks[i].rate); +if (IS_ERR (clk_hw)) +return PTR_ERR (clk_hw); + + clks[i].hw = *clk_hw; + data->clk_data.hws[clks[i].id] = clk_hw; + } + +return 0 ; +} +EXPORT_SYMBOL_GPL (eswin_clk_register_fixed_rate); + +static const struct clk_ops eswin_clk_pll_ops = { + .set_rate = clk_pll_set_rate, + .recalc_rate = clk_pll_recalc_rate, + .determine_rate = clk_pll_determine_rate, +}; + +int eswin_clk_register_pll (struct device *dev,struct eswin_pll_clock *clks, +int nums,struct eswin_clock_data *data) +{ +struct eswin_clk_pll *p_clk =NULL ; +struct clk_init_data init; +struct clk_hw *clk_hw; +int i, ret; + + p_clk =devm_kzalloc (dev,sizeof (*p_clk) * nums,GFP_KERNEL ); +if (!p_clk) +return -ENOMEM ; + +for (i =0 ; i < nums; i++) { + p_clk->id = clks[i].id; + p_clk->ctrl_reg0 = data->base + clks[i].ctrl_reg0; + p_clk->fbdiv_shift = clks[i].fbdiv_shift; + + p_clk->ctrl_reg1 = data->base + clks[i].ctrl_reg1; + p_clk->frac_shift = clks[i].frac_shift; + + p_clk->ctrl_reg2 = data->base + clks[i].ctrl_reg2; + + p_clk->status_reg = data->base + clks[i].status_reg; + p_clk->lock_shift = clks[i].lock_shift; + p_clk->lock_width = clks[i].lock_width; + + p_clk->max_rate = clks[i].max_rate; + p_clk->min_rate = clks[i].min_rate; + + init.name = clks[i].name; + init.flags =0 ; + init.parent_data = clks[i].parent_data; + init.num_parents =1 ; + init.ops = &eswin_clk_pll_ops; + p_clk->hw.init = &init; + + clk_hw = &p_clk->hw; + + ret =devm_clk_hw_register (dev, clk_hw); +if (ret) +return ret; + + clks[i].hw = *clk_hw; + data->clk_data.hws[clks[i].id] = clk_hw; + p_clk++; + } + +return 0 ; +} +EXPORT_SYMBOL_GPL (eswin_clk_register_pll); + +int eswin_clk_register_fixed_factor (struct device *dev, +struct eswin_fixed_factor_clock *clks, +int nums,struct eswin_clock_data *data) +{ +struct clk_hw *clk_hw; +int i; + +for (i =0 ; i < nums; i++) { + clk_hw =devm_clk_hw_register_fixed_factor_index + (dev, clks[i].name, clks[i].parent_data->index, + clks[i].flags, clks[i].mult, clks[i].div); + +if (IS_ERR (clk_hw)) +return PTR_ERR (clk_hw); + + clks[i].hw = *clk_hw; + data->clk_data.hws[clks[i].id] = clk_hw; + } + +return 0 ; +} +EXPORT_SYMBOL_GPL (eswin_clk_register_fixed_factor); + +int eswin_clk_register_mux (struct device *dev,struct eswin_mux_clock *clks, +int nums,struct eswin_clock_data *data) +{ +struct clk_hw *clk_hw; +int i; + +for (i =0 ; i < nums; i++) { + clk_hw =devm_clk_hw_register_mux_parent_data_table + (dev, clks[i].name, clks[i].parent_data, + clks[i].num_parents, clks[i].flags, + data->base + clks[i].offset, clks[i].shift, + clks[i].width, clks[i].mux_flags, clks[i].table, + &data->lock); + +if (IS_ERR (clk_hw)) +return PTR_ERR (clk_hw); + + clks[i].hw = *clk_hw; + data->clk_data.hws[clks[i].id] = clk_hw; + } + +return 0 ; +} +EXPORT_SYMBOL_GPL (eswin_clk_register_mux); + +static unsigned int _eswin_get_val (unsigned int div,unsigned long flags, +u8 width) +{ +unsigned int maxdiv; + + maxdiv =clk_div_mask (width); + div = div > maxdiv ? maxdiv : div; + +if (flags &ESWIN_PRIV_DIV_MIN_2 ) +return (div <2 ) ?2 : div; + +return div; +} + +static unsigned int eswin_div_get_val (unsigned long rate, +unsigned long parent_rate,u8 width, +unsigned long flags) +{ +unsigned int div; + + div =DIV_ROUND_UP_ULL ((u64 )parent_rate, rate); + +return _eswin_get_val (div, flags, width); +} +
drivers/clk/eswin/clk.c line 347
Quoted 10 lines
drivers/clk/eswin/clk.c new file +10
-0+static inline struct eswin_divider_clock *to_div_clk (struct clk_hw *hw) +{ + return container_of(hw, struct eswin_divider_clock, hw); +} + +static int clk_div_set_rate (struct clk_hw *hw,unsigned long rate, +unsigned long parent_rate) +{ +struct eswin_divider_clock *dclk =to_div_clk (hw); +unsigned long flags =0 ;
No need to initialize flags.
Quoted 126 lines
drivers/clk/eswin/clk.c new file +126
-0+unsigned int value; +u32 val; + + value =eswin_div_get_val (rate, parent_rate, dclk->width, + dclk->priv_flag); + +spin_lock_irqsave (dclk->lock, flags); + + val =readl_relaxed (dclk->reg); + val &= ~(clk_div_mask (dclk->width) << dclk->shift); + val |= (u32 )value << dclk->shift; +writel_relaxed (val, dclk->reg); + +spin_unlock_irqrestore (dclk->lock, flags); + +return 0 ; +} + +static unsigned long clk_div_recalc_rate (struct clk_hw *hw, +unsigned long parent_rate) +{ +struct eswin_divider_clock *dclk =to_div_clk (hw); +unsigned int div, val; + + val =readl_relaxed (dclk->reg) >> dclk->shift; + val &=clk_div_mask (dclk->width); + div =_eswin_get_val (val, dclk->priv_flag, dclk->width); + +return DIV_ROUND_UP_ULL ((u64 )parent_rate, div); +} + +static int eswin_clk_bestdiv (unsigned long rate, +unsigned long best_parent_rate,u8 width, +unsigned long flags) +{ +unsigned long bestdiv, up_rate, down_rate; +int up, down; + +if (!rate) + rate =1 ; + +/* closest round */ + up =DIV_ROUND_UP_ULL ((u64 )best_parent_rate, rate); + down = best_parent_rate / rate; + + up_rate =DIV_ROUND_UP_ULL ((u64 )best_parent_rate, up); + down_rate =DIV_ROUND_UP_ULL ((u64 )best_parent_rate, down); + + bestdiv = (rate - up_rate) <= (down_rate - rate) ? up : down; + +return bestdiv; +} + +static int clk_div_determine_rate (struct clk_hw *hw, +struct clk_rate_request *req) +{ +struct eswin_divider_clock *dclk =to_div_clk (hw); +int div; + + div =eswin_clk_bestdiv (req->rate, req->best_parent_rate, dclk->width, + dclk->priv_flag); + div =_eswin_get_val (div, dclk->priv_flag, dclk->width); + req->rate =DIV_ROUND_UP_ULL ((u64 )req->best_parent_rate, div); + +return 0 ; +} + +static const struct clk_ops eswin_clk_div_ops = { + .set_rate = clk_div_set_rate, + .recalc_rate = clk_div_recalc_rate, + .determine_rate = clk_div_determine_rate, +}; + +struct clk_hw *eswin_register_clkdiv (struct device *dev,unsigned int id, +const char *name, +const struct clk_hw *parent_hw, +unsigned long flags,void __iomem *reg, +u8 shift,u8 width, +unsigned long clk_divider_flags, +unsigned long priv_flag,spinlock_t *lock) +{ +struct eswin_divider_clock *dclk; +struct clk_init_data init; +struct clk_hw *clk_hw; +int ret; + + dclk =devm_kzalloc (dev,sizeof (*dclk),GFP_KERNEL ); +if (!dclk) +return ERR_PTR (-ENOMEM ); + + init.name = name; + init.ops = &eswin_clk_div_ops; + init.flags = flags; + init.parent_hws = &parent_hw; + init.num_parents =1 ; + +/* struct clk_divider assignments */ + dclk->id = id; + dclk->reg = reg; + dclk->shift = shift; + dclk->width = width; + dclk->div_flags = clk_divider_flags; + dclk->priv_flag = priv_flag; + dclk->lock = lock; + dclk->hw.init = &init; + +/* register the clock */ + clk_hw = &dclk->hw; + ret =devm_clk_hw_register (dev, clk_hw); +if (ret) { +dev_err (dev,"failed to register divider clock!\n" ); +return ERR_PTR (ret); + } + +return clk_hw; +} +EXPORT_SYMBOL_GPL (eswin_register_clkdiv); + +int eswin_clk_register_divider (struct device *dev, +struct eswin_divider_clock *clks, +int nums,struct eswin_clock_data *data) +{ +struct clk_hw *clk_hw; +int i; + +for (i =0 ; i < nums; i++) {
drivers/clk/eswin/clk.c line 483
Quoted 10 lines
drivers/clk/eswin/clk.c new file +10
-0+ clk_hw =clk_hw_register_divider_parent_data + (dev, clks[i].name, clks[i].parent_data, + clks[i].flags, data->base + clks[i].offset, + clks[i].shift, clks[i].width, clks[i].div_flags, + &data->lock); + +if (IS_ERR (clk_hw)) { +while (i--) +clk_hw_unregister_divider + (data->clk_data.hws[clks[i].id]);
All of the other places you are using the devm_ variant to automate the cleanup, such as devm_clk_hw_register_gate_parent_data(), devm_clk_hw_register_mux_parent_data_table(), and devm_clk_hw_register_divider_parent_hw(). What do you think about adding a devm_clk_hw_register_divider_parent_data() for consistency?
Quoted 67 lines
drivers/clk/eswin/clk.c new file +67
-0+return PTR_ERR (clk_hw); + } + + clks[i].hw = *clk_hw; + data->clk_data.hws[clks[i].id] = clk_hw; + } + +return 0 ; +} +EXPORT_SYMBOL_GPL (eswin_clk_register_divider); + +int eswin_clk_register_gate (struct device *dev,struct eswin_gate_clock *clks, +int nums,struct eswin_clock_data *data) +{ +struct clk_hw *clk_hw; +int i; + +for (i =0 ; i < nums; i++) { + clk_hw =devm_clk_hw_register_gate_parent_data + (dev, clks[i].name, clks[i].parent_data, + clks[i].flags, data->base + clks[i].offset, + clks[i].bit_idx, clks[i].gate_flags, + &data->lock); + +if (IS_ERR (clk_hw)) +return PTR_ERR (clk_hw); + + clks[i].hw = *clk_hw; + data->clk_data.hws[clks[i].id] = clk_hw; + } + +return 0 ; +} +EXPORT_SYMBOL_GPL (eswin_clk_register_gate); + +int eswin_clk_register_clks (struct device *dev,struct eswin_clk_info *clks, +int nums,struct eswin_clock_data *data) +{ +struct eswin_clk_info *info; +const struct clk_hw *phw =NULL ; +struct clk_hw *hw; +int i; + +for (i =0 ; i < nums; i++) { + info = &clks[i]; +switch (info->type) { +case CLK_FIXED_FACTOR : { +const struct eswin_fixed_factor_clock *factor; + + factor = &info->data.factor; + phw = data->clk_data.hws[info->pid]; + hw =devm_clk_hw_register_fixed_factor_parent_hw + (dev, factor->name, phw, factor->flags, + factor->mult, factor->div); +break ; + } +case CLK_MUX : { +const struct eswin_mux_clock *mux = &info->data.mux; + + hw =devm_clk_hw_register_mux_parent_data_table + (dev, mux->name, mux->parent_data, + mux->num_parents, mux->flags, + data->base + mux->offset, mux->shift, + mux->width, mux->mux_flags, mux->table, + &data->lock); +break ; + }
drivers/clk/eswin/clk.c line 560
Quoted 10 lines
drivers/clk/eswin/clk.c new file +10
-0+case CLK_DIVIDER : { +const struct eswin_divider_clock *div = &info->data.div; + + phw = data->clk_data.hws[info->pid]; +if (div->priv_flag) + hw =eswin_register_clkdiv + (dev, div->id, div->name, phw, + div->flags, data->base + div->offset, + div->shift, div->width, div->div_flags, + div->priv_flag, &data->lock);
You can now go out to 100 characters for the line lengths instead of 80, however, I'm not sure how Stephen feels about that. Personally I think it'd make this block, plus some others in this series a bit cleaner. Taking into account the current indentation, this block could become this with 100 characters as the max:
hw = eswin_register_clkdiv(dev, div->id, div->name, phw,
div->flags, data->base + div->offset,
div->shift, div->width, div->div_flags,
div->priv_flag, &data->lock);Brian
Re: [PATCH v13 2/3] clk: eswin: Add eic7700 clock driver
Quoted 14 lines · Brian Masney
Quoted 13 lines · On Sat, Feb 14, 2026 at 06:15:19PM +0800, [email protected] wrote:
drivers/clk/eswin/clk-eic7700.c new file +13
-0+static const struct of_device_id eic7700_clock_dt_ids[] = { + { .compatible ="eswin,eic7700-clock" , }, + {/* sentinel */ } +}; +MODULE_DEVICE_TABLE (of, eic7700_clock_dt_ids); + +static struct platform_driver eic7700_clock_driver = { + .probe = eic7700_clk_probe, + .driver = { + .name ="eic7700-clock" , + .of_match_table = eic7700_clock_dt_ids, + }, +};
Quoted 8 lines
drivers/clk/eswin/clk-eic7700.c line 1357
Quoted 6 lines
drivers/clk/eswin/clk-eic7700.c new file +6
-0+module_platform_driver (eic7700_clock_driver); + +MODULE_LICENSE ("GPL" ); +MODULE_AUTHOR ("Yifeng Huang<[email protected]>" ); +MODULE_AUTHOR ("Xuyang Dong<[email protected]>" ); +MODULE_DESCRIPTION ("ESWIN EIC7700 clock controller driver" );
MODULE_ALIAS("platform:eic7700-clk")
Ignore the MODULE_ALIAS suggestion from me. The list of aliases will be automatically generated based on what's in MODULE_DEVICE_TABLE(). I verified this with modinfo.
Brian
Re: [PATCH v13 2/3] clk: eswin: Add eic7700 clock driver
In reply to Brian MasneyHi Brian and Xuyang
Quoted 8 lines · Brian Masney
Hi Xuyang,
Quoted 5 lines · On Sat, Feb 14, 2026 at 06:15:19PM +0800, [email protected] wrote:
From: Xuyang Dong <[email protected]>
Add clock drivers for the EIC7700 SoC. The clock controller on the ESWIN EIC7700 provides various clocks to different IP blocks within the SoC.
Quoted 7 lines
Quoted 3 lines
Signed-off-by Yifeng Huang <[email protected]>Signed-off-by Xuyang Dong <[email protected]>Can Marcel retest the new version since some of the logic related to the parent rate changed in the new version? It's probably still fine, however it's good to be sure.
I can confirm that v13 still works as expected. More details available here [1].
Thanks!
[1] https://github.com/riscv/meta-riscv/pull/601
Quoted 1 line
I have some other minor comments / questions below.
[snip]
Cheers
Marcel
Hi ESWIN folks,
I'm testing your patchset on
https://github.com/ganboing/linux-eic77/tree/eic77-integration-test-clk-v13
It's applied on top of Samuel's PMA v3 patshset, plus device-tree patches from your integration test branch. It's pretty similar to what Marcel did, but I just want to have a separate verification. What I found is that the kernel can successfully boot with clk_ignore_unused (eMMC/eth working), but hangs without. It stuck at
[ 3.257141] clk: Disabling unused clocks
I'm pretty sure that some clocks that weren't supposed to get disabled got turned off. Can you validate if that's a bug in the clock driver, or my device-tree just didn't link all clocks. One thing I noticed is that there is no CLK_IS_CRITICAL in your code, so it's highly likely that DDR PLL or others were turned off unintentionally. Not a clock driver expert, but I'd expect the kernel should work fine without clk_ignore_unused.
Bo
Quoted 233 lines · On 2/14/26 02:14, [email protected] wrote:
From: Xuyang Dong <[email protected]>
The link [1] provides the official documentation for the EIC7700. Section 3.2 covers the clock subsystem.
[1] https://www.sifive.com/document-file/eic7700x-datasheet
Updates:
Change in v13:
- Updated driver file
- Modify commit subject from "clock: eswin: Add eic7700 clock driver" to "clk: eswin: Add eic7700 clock driver".
- Use parent rate to calculate PLL clock rate.
- UseGENMASK()to define PLL mask macros and useFIELD_PREP()to simplify bitwise operations.
- Remove shift and width references for pll enable, refdiv, fbdiv, frac and postdiv. (Use only the PLL macros to match the functionality)
- Set postdiv1 and postdiv2 inclk_pll_set_ratefunction.- Link to v11: https://lore.kernel.org/all/[email protected]/
Change in v12:
- Updated driver file
- AddCLK_MUX_ROUND_CLOSESTto the mux clocks since they need a more accurate clock frequency.
- Change 'rem' from u64 to u32 for function 'eswin_calc_pll' and function 'clk_pll_recalc_rate'.
- Change 'rate' from u64 to unsigned long for function 'clk_pll_recalc_rate'.
- Fix build error with u64 divisor for function `clk_pll_set_rate'.Reported-by kernel test robot <[email protected]>- Link to v11: https://lore.kernel.org/all/[email protected]/
Change in v11:
- Updated driver file
- Add "Tested-by: Marcel Ziswiler <[email protected]> # ebc77" tag.
- Fix build error in functioneswin_clk_register_clks.Reported-by kernel test robot <[email protected]>- Link to v10: https://lore.kernel.org/all/[email protected]/
Changes in v10:
- Updated driver file
- Add a private clock divider API named 'eswin_register_clkdiv' to register divider clocks with private flag.
Define 'ESWIN_PRIV_DIV_MIN_2' private flag for registering the clock dividers whose division ratio start from 2.
Implement the privateset_rate,recalc_rate, anddetermine_rateaccordingly.
- AddCLK_DIVIDER_ALLOW_ZEROflag to the clock dividers whose division ratio start from 0.
- ReplaceCONFIG_ARCH_ESWINwithCONFIG_COMMON_CLK_ESWINin theMakefile.
- Modify the help description ofCOMMON_CLK_EIC7700.
- Move register offset definitions from 'clk-eic7700.h' to 'clk-eic7700.c' and remove the 'clk-eic7700.h'. Remove '_CTRL' from the offset names.
- Remove all unused headers.
- Usedevm_platform_ioremap_resource()instead ofdevm_of_iomap().
- Export the functions fromclk.cas symbols.
- Usereadl_poll_timeout().
- Use 'clk_parent_data' and '.hw' instead of string parent names.
- Rename the header file fromclk.htocommon.h.
- Rename macros from EIC7700_* to ESWIN_* incommon.h.
- Add a new function, 'eswin_clk_register_clks', which can register divider, mux, gate, and fixed-factor clocks based on their types.
- Add structure 'eswin_clk_info' to manage the clocks that need to be registered in a specific order.
- Add macros 'ESWIN_*_TYPE' to define divider, mux, gate, and fixed-factor clocks with type. Add enum 'eswin_clk_type' for these types.
- Remove 'eswin_clk_register_mux_tbl'. Use 'eswin_clk_register_mux' to register mux clocks with or without table.
- Add xtal24m as the parent clock of the PLL.
- Change 2025 to 2026 in all files.- Link to v9: https://lore.kernel.org/all/[email protected]/
Changes in v9:
- Updated driver file
- Checked return values of eswin_clk_register_*() in the probe function.
- Removed binding IDs check from pll functions inclk.c, as these functions were exclusively used by pll clocks and did not require ID validation.
- The PLL structure has been extended withmax_rateandmin_ratefields to explicitly define the frequency operating range of the PLL. These limits were now utilized by theclk_pll_determine_rate()function.
- Removed__clk_lookup()inclk_pll_set_rate. Addedclk_notifiersupport inclk-eic7700.c.
- Added five previously missing clocks from [1].- Link to v8: https://lore.kernel.org/all/[email protected]/
Changes in v8:
- Updated YAML file
- Added "Acked-by: Troy Mitchell <[email protected]>"
- Updated driver file
- ChangedKconfigfrom bool to tristate.
- UpdatedMAINTAINERSfile
- Added "ESWIN SOC SERIES CLOCK DRIVER"- Link to v7: https://lore.kernel.org/all/[email protected]/
Changes in v7:
- Updated YAML file
- Added "Acked-by: Conor Dooley <[email protected]>" for bindings.
- Updated driver file
- Added description for clk ofeswin_calc_pll().
- Added macroEIC7700_MUX_TBLto manage mux clock-tree.
- Addedeswin_clk_register_mux_tbl()to register mux clocks with discontinuous parent indexes.- Link to v6: https://lore.kernel.org/all/[email protected]/
Changes in v6:
- Removed config option patch dependency from cover letter, because the patch was applied.
- Updated YAML file
- Added an oscillator as the clock input, named xtal24m.
- Added clocks property.
- Updated driver file
- Replacedfixed_rate_clk_xtal_24mwith xtal24m.
- Droppedfixed_rate_clk_xtal_24mfrom driver. Because clock xtal24m was registered by fixed-clock as oscillator.- Link to v5: https://lore.kernel.org/all/[email protected]/
Changes in v5:
- Removed vendor prefix patch dependency from cover letter, because the patch was applied.
- Updated YAML file
- Placed the required after all properties.
- Removed patternProperties. Also removed compatible of eswin,pll-clock, eswin,mux-clock, eswin,divider-clock and eswin,gate-clock as we have moved clock tree from DTS to Linux driver.
- Removed the clock tree from DTS. Used clock-controller to manage all clock. Removed all child nodes in clock-controller.
- Removed '#address-cells' and '#size-cells' properties, because the clock controller did not need to define these properties.
- Removedeic7700-clocks.dtsi.
- Added dt-bindings header for clock IDs. Because used the IDs to register clocks.
- Updated driver file
- Modified the commit for clock driver. Dropped indentation in commit.
- RemovedCLK_OF_DECLARE(). Used *clk_hw_register* to register clocks. Useddevm_of_clk_add_hw_provider.
- Dropped singletons.
- Checked the value right after obtaining it.
- Removed the definitions of macro frequency inclk.hlikeCLK_FREQ_24M.
- Modified description of help inKconfig.
- AddedCOMPILE_TEST. AddedCOMMON_CLK_ESWINfor clk.o. And added "selectCOMMON_CLK_ESWIN" forclk-eic7700.c. WithoutCOMMON_CLK_EIC7700,clk.ccould not be compiled.
- Used .determined_rate.
- Added macro definitions ofEIC7700_DIV,EIC7700_FIXED,EIC7700_FACTOR,EIC7700_MUXandEIC7700_PLLto manage clock tree.
- Addedclk-eic7700.hto place eic7700 SoC clock registers.
- Removedrefdiv_valandpostdiv1_valfromclk_pll_recalc_rate(). Because these values were unused.- Link to v4: https://lore.kernel.org/all/[email protected]/
Changes in v4:
- Updated YAML file
- Changed name from cpu-default-frequency to cpu-default-freq-hz.
- Dropped $ref of cpu-default-frequency.
- Added cpu-default-frequency for required.
- Removed cpu-default-frequency in updated file, because there was no need to add cpu-default-frequency.
- Moved DIVIDER to DIV.
- Arranged the IDs in order.
- DroppedEIC7700_NR_CLKS.
- Removed dt-bindings eswin,eic7700-clock.h. Because IDs was not used, and used clock device nodes.
- According to the updated driver codes, the YAML has been updated.
- Updated driver file
- Remove undocumented parameters "cpu_no_boost_1_6ghz" and "cpu-default-frequency".
- Modified the comment and used the correct Linux coding style.
- Removed codes of voltage, because it was not the clock driver.
- Updated the formula of clock frequency calculation. Removed the logic that only used register selection.
- UsedCLK_OF_DECLARE()to register clocks. Registered pll-clock, mux-clock, divider-clock, and gate-clock inclk-eic7700.c. The specific implementation of clock registration was inclk.c.
- Addedeic7700-clocks.dtsi.
- Moved device information to DTS. Put all clocks' node in theeic7700-clocks.dtsi.- Link to v3: https://lore.kernel.org/all/[email protected]/
Changes in v3:
- Update example, drop child node and add '#clock-cells' to the parent
node.
- Change parent node from sys-crg to clock-controller for this yaml.
- Drop "syscon", "simple-mfd" to clear warnings/errors by using "makedt_binding_check". And these are not necessary.
- Add "cpu-default-frequency" definition in yaml for "undocumented ABI".
- Drop Reviewed-by, this is misunderstanding. We have not received such
an email.
- Link to v2: https://lore.kernel.org/all/[email protected]/Changes in v2:
- Update example, drop child node.
- Clear warnings/errors for using "makedt_binding_check".
- Change to the correct format.
- Drop some non-stanard code.
- Usedev_err_probe()in probe functions.
- Link to v1: https://lore.kernel.org/all/[email protected]/Xuyang Dong (3):
dt-bindings: clock: eswin: Documentation for eic7700 SoC
clk: eswin: Add eic7700 clock driver
MAINTAINERS: Add entry for ESWIN EIC7700 clock driver.../bindings/clock/eswin,eic7700-clock.yaml | 46 + MAINTAINERS | 8 + drivers/clk/Kconfig | 1 + drivers/clk/Makefile | 1 + drivers/clk/eswin/Kconfig | 15 + drivers/clk/eswin/Makefile | 8 + drivers/clk/eswin/clk-eic7700.c | 1357 +++++++++++++++++ drivers/clk/eswin/clk.c | 591 +++++++ drivers/clk/eswin/common.h | 341 +++++ .../dt-bindings/clock/eswin,eic7700-clock.h | 285 ++++ 10 files changed, 2653 insertions(+)create mode 100644
Documentation/devicetree/bindings/clock/eswin,eic7700-clock.yamlcreate mode 100644drivers/clk/eswin/Kconfig
create mode 100644drivers/clk/eswin/Makefile
create mode 100644drivers/clk/eswin/clk-eic7700.c
create mode 100644drivers/clk/eswin/clk.c
create mode 100644drivers/clk/eswin/common.h
create mode 100644include/dt-bindings/clock/eswin,eic7700-clock.h--
2.43.0
Xuyang Dong
maintainerQuoted 11 lines
Hi ESWIN folks,
I'm testing your patchset on
https://github.com/ganboing/linux-eic77/tree/eic77-integration-test-clk-v13It's applied on top of Samuel's PMA v3 patshset, plus device-tree patches from your integration test branch. It's pretty similar to what Marcel did, but I just want to have a separate verification. What I found is that the kernel can successfully boot with
clk_ignore_unused(eMMC/eth working), but hangs without. It stuck at
Quoted 9 lines
[ 3.257141] clk: Disabling unused clocksI'm pretty sure that some clocks that weren't supposed to get disabled got turned off. Can you validate if that's a bug in the clock driver, or my device-tree just didn't link all clocks. One thing I noticed is that there is no
CLK_IS_CRITICALin your code, so it's highly likely that DDR PLL or others were turned off unintentionally. Not a clock driver expert, but I'd expect the kernel should work fine withoutclk_ignore_unused.
Hi Bo,
Thanks for your reply. I also got the same result without clk_ignore_unused. This is a bug, and I will address it in v14.
Regards,
Xuyang Dong
Hi Xuyang,
Quoted 19 lines · Xuyang Dong
Quoted 9 lines
I'm testing your patchset on
https://github.com/ganboing/linux-eic77/tree/eic77-integration-test-clk-v13It's applied on top of Samuel's PMA v3 patshset, plus device-tree patches from your integration test branch. It's pretty similar to what Marcel did, but I just want to have a separate verification. What I found is that the kernel can successfully boot with
clk_ignore_unused(eMMC/eth working), but hangs without. It stuck atQuoted 9 lines
[ 3.257141] clk: Disabling unused clocksI'm pretty sure that some clocks that weren't supposed to get disabled got turned off. Can you validate if that's a bug in the clock driver, or my device-tree just didn't link all clocks. One thing I noticed is that there is no
CLK_IS_CRITICALin your code, so it's highly likely that DDR PLL or others were turned off unintentionally. Not a clock driver expert, but I'd expect the kernel should work fine withoutclk_ignore_unused.
Quoted 4 lines
Hi Bo,
Thanks for your reply. I also got the same result without
clk_ignore_unused. This is a bug, and I will address it in v14.
In Documentation/driver-api/clk.rst, there is a section titled "Disabling clock gating of unused clocks", along with trace kernel parameters you can add to log which clks are disabled.
Brian
Xuyang Dong
maintainerRe: Re: [PATCH v13 2/3] clk: eswin: Add eic7700 clock driver
In reply to Brian MasneyQuoted 17 lines
Quoted 17 lines
drivers/clk/eswin/clk.c new file +17
-0+ +int eswin_clk_register_divider (struct device *dev, +struct eswin_divider_clock *clks, +int nums,struct eswin_clock_data *data) +{ +struct clk_hw *clk_hw; +int i; + +for (i =0 ; i < nums; i++) { + clk_hw =clk_hw_register_divider_parent_data + (dev, clks[i].name, clks[i].parent_data, + clks[i].flags, data->base + clks[i].offset, + clks[i].shift, clks[i].width, clks[i].div_flags, + &data->lock); + +if (IS_ERR (clk_hw)) { +while (i--)
Quoted 9 lines
drivers/clk/eswin/clk.c line 483
Quoted 2 lines
drivers/clk/eswin/clk.c new file +2
-0+clk_hw_unregister_divider + (data->clk_data.hws[clks[i].id]);All of the other places you are using the
devm_variant to automate the cleanup, such asdevm_clk_hw_register_gate_parent_data(),devm_clk_hw_register_mux_parent_data_table(), anddevm_clk_hw_register_divider_parent_hw(). What do you think about adding adevm_clk_hw_register_divider_parent_data()for consistency?
Hi Brian and Stephen,
Thank you for the suggestions. We agree that implementing devm_clk_hw_register_divider_parent_data() is a good approach.
In v14, we'll add this function in clk-provider.h as a separate preparatory patch. The ESWIN clock driver will then switch to using devm_clk_hw_register_divider_parent_data() instead of clk_hw_register_divider_parent_data(), with the driver patch depending on the former. Does this approach better align with upstream conventions?
Quoted 83 lines
Quoted 67 lines
drivers/clk/eswin/clk.c new file +67
-0+return PTR_ERR (clk_hw); + } + + clks[i].hw = *clk_hw; + data->clk_data.hws[clks[i].id] = clk_hw; + } + +return 0 ; +} +EXPORT_SYMBOL_GPL (eswin_clk_register_divider); + +int eswin_clk_register_gate (struct device *dev,struct eswin_gate_clock *clks, +int nums,struct eswin_clock_data *data) +{ +struct clk_hw *clk_hw; +int i; + +for (i =0 ; i < nums; i++) { + clk_hw =devm_clk_hw_register_gate_parent_data + (dev, clks[i].name, clks[i].parent_data, + clks[i].flags, data->base + clks[i].offset, + clks[i].bit_idx, clks[i].gate_flags, + &data->lock); + +if (IS_ERR (clk_hw)) +return PTR_ERR (clk_hw); + + clks[i].hw = *clk_hw; + data->clk_data.hws[clks[i].id] = clk_hw; + } + +return 0 ; +} +EXPORT_SYMBOL_GPL (eswin_clk_register_gate); + +int eswin_clk_register_clks (struct device *dev,struct eswin_clk_info *clks, +int nums,struct eswin_clock_data *data) +{ +struct eswin_clk_info *info; +const struct clk_hw *phw =NULL ; +struct clk_hw *hw; +int i; + +for (i =0 ; i < nums; i++) { + info = &clks[i]; +switch (info->type) { +case CLK_FIXED_FACTOR : { +const struct eswin_fixed_factor_clock *factor; + + factor = &info->data.factor; + phw = data->clk_data.hws[info->pid]; + hw =devm_clk_hw_register_fixed_factor_parent_hw + (dev, factor->name, phw, factor->flags, + factor->mult, factor->div); +break ; + } +case CLK_MUX : { +const struct eswin_mux_clock *mux = &info->data.mux; + + hw =devm_clk_hw_register_mux_parent_data_table + (dev, mux->name, mux->parent_data, + mux->num_parents, mux->flags, + data->base + mux->offset, mux->shift, + mux->width, mux->mux_flags, mux->table, + &data->lock); +break ; + }drivers/clk/eswin/clk.c line 560
Quoted 10 lines
drivers/clk/eswin/clk.c new file +10
-0+case CLK_DIVIDER : { +const struct eswin_divider_clock *div = &info->data.div; + + phw = data->clk_data.hws[info->pid]; +if (div->priv_flag) + hw =eswin_register_clkdiv + (dev, div->id, div->name, phw, + div->flags, data->base + div->offset, + div->shift, div->width, div->div_flags, + div->priv_flag, &data->lock);You can now go out to 100 characters for the line lengths instead of 80, however, I'm not sure how Stephen feels about that. Personally I think it'd make this block, plus some others in this series a bit cleaner. Taking into account the current indentation, this block could become this with 100 characters as the max:
Quoted 5 lines
hw = eswin_register_clkdiv(dev, div->id, div->name, phw,
div->flags, data->base + div->offset,
div->shift, div->width, div->div_flags,
div->priv_flag, &data->lock);Stephen,
Brian's feedback on line length was very helpful.
For v14, we've kept lines within 80 characters wherever possible. In a few cases, such as function calls with long parameter lists, we've kept slightly longer lines to preserve readability,
but we're happy to rewrap them if preferred.
Does this approach work for the clk subsystem?
Regards,
Xuyang Dong
Re: Re: [PATCH v13 2/3] clk: eswin: Add eic7700 clock driver
Quoted 29 lines · Xuyang Dong
Quoted 17 lines
Quoted 17 lines
drivers/clk/eswin/clk.c new file +17
-0+ +int eswin_clk_register_divider (struct device *dev, +struct eswin_divider_clock *clks, +int nums,struct eswin_clock_data *data) +{ +struct clk_hw *clk_hw; +int i; + +for (i =0 ; i < nums; i++) { + clk_hw =clk_hw_register_divider_parent_data + (dev, clks[i].name, clks[i].parent_data, + clks[i].flags, data->base + clks[i].offset, + clks[i].shift, clks[i].width, clks[i].div_flags, + &data->lock); + +if (IS_ERR (clk_hw)) { +while (i--)Quoted 9 lines
drivers/clk/eswin/clk.c line 483
Quoted 2 lines
drivers/clk/eswin/clk.c new file +2
-0+clk_hw_unregister_divider + (data->clk_data.hws[clks[i].id]);All of the other places you are using the
devm_variant to automate the cleanup, such asdevm_clk_hw_register_gate_parent_data(),devm_clk_hw_register_mux_parent_data_table(), anddevm_clk_hw_register_divider_parent_hw(). What do you think about adding adevm_clk_hw_register_divider_parent_data()for consistency?Hi Brian and Stephen,
Quoted 7 lines
Thank you for the suggestions. We agree that implementing
devm_clk_hw_register_divider_parent_data()is a good approach.
In v14, we'll add this function inclk-provider.has a separate preparatory patch. The ESWIN clock driver will then switch to usingdevm_clk_hw_register_divider_parent_data()instead ofclk_hw_register_divider_parent_data(), with the driver patch depending on the former. Does this approach better align with upstream conventions?
Yes, that sounds good.
Quoted 11 lines
Quoted 10 lines
You can now go out to 100 characters for the line lengths instead of 80, however, I'm not sure how Stephen feels about that. Personally I think it'd make this block, plus some others in this series a bit cleaner. Taking into account the current indentation, this block could become this with 100 characters as the max:
hw = eswin_register_clkdiv(dev, div->id, div->name, phw, div->flags, data->base + div->offset, div->shift, div->width, div->div_flags, div->priv_flag, &data->lock);
Quoted 7 lines
Stephen,
Brian's feedback on line length was very helpful.
For v14, we've kept lines within 80 characters wherever possible. In a few cases, such as function calls with long parameter lists, we've kept slightly longer lines to preserve readability,
but we're happy to rewrap them if preferred.
Does this approach work for the clk subsystem?
I don't know when Stephen will be able to respond. I recommend just posting a new version.
I apologize in advance if he asks you to do the opposite later.
Brian