Add driver support for ESWIN EIC7700 HSP clock and reset generator
Xuyang Dong
maintainerv3 cover Add driver support for ESWIN EIC7700 HSP clock and reset generator
Add support for the ESWIN EIC7700 HSP (high-speed peripherals). The drivers provide basic functionality to manage and control the clock and reset signals for EIC7700 HSP, including mmc, USB, ethernet, SATA and DMAC.
The clock and reset registers are mapped to overlapping I/O address ranges. This causes a resource conflict when two drivers attempt to request the same region. Use the auxiliary device framework: the main driver allocates the shared register region and passes it to auxiliary devices, avoiding resource contention and duplicate remapping.
Features:
Implements support for the ESWIN EIC7700 HSP clock and reset controller. Provide API to manage clock and reset signals for the EIC7700 HSP.
Supported chips:
ESWIN EIC7700 series SoC.
Test:
Test this patch on the Sifive HiFive Premier P550 (which used the EIC7700 SoC), include USB and other peripherals. All the drivers of these modules use the clock module and reset module.
This patch depends on ESWIN EIC7700 clock controller patch [1], [2] and [3].
[1] https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?h=next-20260331&id=8add6d87dc69c0620c7e60bdc6be6b3b0092d9fa
[2] https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?h=next-20260331&id=cd44f127c1d42833a32ba0a0965255ee6184f8c1
[3] https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?h=next-20260331&id=858f6273cf003e97c817903a07d8001b483fe40b
Updates:
Changes in v3:
- Bindings:
- Added "Acked-by: Conor Dooley <[email protected]>" for bindings.
- Clock driver:
- Remove 'gate_flags'.
- Add __acquires for eic7700_hsp_regmap_lock() and add __releases for eic7700_hsp_regmap_unlock().
- Move writel(USB_REF_XTAL24M, gate->ref_reg) into enable. Because this is only used for USB gate clock on the enable path. And modify the comments.
- Simplify to: 'return !!(readl(gate->reg) & BIT(gate->bit_idx));'.
- Drop const from eic7700_hsp_regmap_config.
- Declare eic7700_hsp_regmap_config as a regular variable at the top.
- Dropping const will cause a warning when checked with checkpatch.pl.
- Link to v2: https://lore.kernel.org/all/[email protected]/
Changes in v2:
- Bindings:
- Remove "hsp_" from clock-names.
- Replace "eswin,eic7700-clock.yaml" and "eswin,eic7700-hspcrg.yaml" with "eswin,eic7700*".
- Replace "eswin,eic7700-clock.h" and "eswin,eic7700-hspcrg.h" with "eswin,eic7700*".
- Clock driver:
- Use guard(spinlock_irqsave)(gate->lock) instead of spin_lock_irqsave() and remove spin_unlock_irqrestore().
- Remove the newline in function hsp_clk_gate_is_enabled().
- Use struct clk_init_data init = {}.
- Replace 'static struct clk_parent_data' with
'static const struct clk_parent_data'.
- Change '.fw_name' to '.index', because the function eswin_clk_register_fixed_factor() uses .index.
- The structures of clocks should use static struct. When registering a clock, the 'hw' field in the structure will be assigned.
- Remove __force.
- Create the regmap in the clock driver and remove (__force void*)data->base. The reset driver uses dev_get_regmap() to get the regmap from the clock.
- Move 'const struct regmap_config eic7700_hsp_regmap_config' from reset driver to clock driver.
- The USB clock gate (hsp_clk_gate_endisable) and the reset driver both perform read-modify-write cycles on registers 0x800 and 0x900. Use custom regmap lock callbacks so that regmap operations hold data->lock with IRQs disabled, the same lock the clock gate path uses, preventing concurrent RMW races on those shared registers.
- Change to 'ret = eswin_clk_register_fixed_factor(dev, eic7700_hsp_factor_clks,'. The next line will be over 80 characters and under 100 characters.
- Reset driver:
- Remove 'depends on COMMON_CLK_EIC7700_HSP' and 'default COMMON_CLK_EIC7700_HSP'.
- Use regmap_assign_bits() in assert and deassert functions.
- Remove eic7700_hsp_reset_reset().
- The clock driver creates the regmap, and the reset driver uses dev_get_regmap().
- Remove of_reset_n_cells.
- Link to v1: https://lore.kernel.org/all/[email protected]/
Xuyang Dong (3):
dt-bindings: clock: Add ESWIN eic7700 HSP clock and reset generator
clk: eswin: Add eic7700 HSP clock driver
reset: eswin: Add eic7700 HSP reset driver
.../bindings/clock/eswin,eic7700-hspcrg.yaml | 63 +++ MAINTAINERS | 5 +- drivers/clk/eswin/Kconfig | 12 + drivers/clk/eswin/Makefile | 1 + drivers/clk/eswin/clk-eic7700-hsp.c | 384 ++++++++++++++++++ drivers/reset/Kconfig | 11 + drivers/reset/Makefile | 1 + drivers/reset/reset-eic7700-hsp.c | 118 ++++++ .../dt-bindings/clock/eswin,eic7700-hspcrg.h | 33 ++ .../dt-bindings/reset/eswin,eic7700-hspcrg.h | 21 + 10 files changed, 647 insertions(+), 2 deletions(-) create mode 100644 Documentation/devicetree/bindings/clock/eswin,eic7700-hspcrg.yaml create mode 100644 drivers/clk/eswin/clk-eic7700-hsp.c create mode 100644 drivers/reset/reset-eic7700-hsp.c create mode 100644 include/dt-bindings/clock/eswin,eic7700-hspcrg.h create mode 100644 include/dt-bindings/reset/eswin,eic7700-hspcrg.h
--
2.34.1
[email protected]
maintainerPATCH v3 1/3 dt-bindings: clock: Add ESWIN eic7700 HSP clock and reset generator
From: Xuyang Dong <[email protected]>
Add bindings for the high-speed peripherals clock and reset generator on the ESWIN EIC7700 HSP.
--- .../bindings/clock/eswin,eic7700-hspcrg.yaml | 63 +++++++++++++++++++ MAINTAINERS | 5 +- .../dt-bindings/clock/eswin,eic7700-hspcrg.h | 33 ++++++++++ .../dt-bindings/reset/eswin,eic7700-hspcrg.h | 21 +++++++ 4 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 Documentation/devicetree/bindings/clock/eswin,eic7700-hspcrg.yaml create mode 100644 include/dt-bindings/clock/eswin,eic7700-hspcrg.h create mode 100644 include/dt-bindings/reset/eswin,eic7700-hspcrg.h
Documentation/devicetree/bindings/clock/eswin,eic7700-hspcrg.yaml new file +63 -0
@@ -0,0 +1,63 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/clock/eswin,eic7700-hspcrg.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: ESWIN EIC7700 HSP Clock and Reset Generator + +maintainers: + - Xuyang Dong <[email protected]> + +description: + Clock and reset generator for the ESWIN EIC7700 HSP (high-speed peripherals). + +properties: + compatible: + const: eswin,eic7700-hspcrg + + reg: + maxItems: 1 + + clocks: + items: + - description: HSP configuration top clock + - description: MMC top clock + - description: SATA top clock + + clock-names: + items: + - const: cfg + - const: mmc + - const: sata + + '#clock-cells': + const: 1 + description: + See <dt-bindings/clock/eswin,eic7700-hspcrg.h> for valid indices. + + '#reset-cells': + const: 1 + description: + See <dt-bindings/reset/eswin,eic7700-hspcrg.h> for valid indices. + +required: + - compatible + - reg + - clocks + - clock-names + - '#clock-cells' + - '#reset-cells' + +additionalProperties: false + +examples: + - | + clock-controller@50440000 { + compatible = "eswin,eic7700-hspcrg"; + reg = <0x50440000 0x2000>; + clocks = <&clock 171>, <&clock 254>, <&clock 187>; + clock-names = "cfg", "mmc", "sata"; + #clock-cells = <1>; + #reset-cells = <1>; + };
MAINTAINERS +3 -2
@@ -9587,9 +9587,10 @@ 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: Documentation/devicetree/bindings/clock/eswin,eic7700* F: drivers/clk/eswin/ -F: include/dt-bindings/clock/eswin,eic7700-clock.h +F: include/dt-bindings/clock/eswin,eic7700* +F: include/dt-bindings/reset/eswin,eic7700-hspcrg.h ET131X NETWORK DRIVER M: Mark Einon <[email protected]>
include/dt-bindings/clock/eswin,eic7700-hspcrg.h new file +33 -0
@@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */ +/* +* Copyright 2026, Beijing ESWIN Computing Technology Co., Ltd.. +* All rights reserved. +* +* Device Tree binding constants for EIC7700 HSP clock controller. +* +* Authors: Xuyang Dong <[email protected]> +*/ + +#ifndef _DT_BINDINGS_ESWIN_EIC7700_HSPCRG_CLOCK_H_ +#define _DT_BINDINGS_ESWIN_EIC7700_HSPCRG_CLOCK_H_ + +#define EIC7700_HSP_CLK_FAC_CFG_DIV2 0 +#define EIC7700_HSP_CLK_FAC_CFG_DIV4 1 +#define EIC7700_HSP_CLK_FAC_MMC_DIV10 2 +#define EIC7700_HSP_CLK_MUX_EMMC_3MUX1 3 +#define EIC7700_HSP_CLK_MUX_SD0_3MUX1 4 +#define EIC7700_HSP_CLK_MUX_SD1_3MUX1 5 +#define EIC7700_HSP_CLK_MUX_EMMC_CQE_2MUX1 6 +#define EIC7700_HSP_CLK_MUX_SD0_CQE_2MUX1 7 +#define EIC7700_HSP_CLK_MUX_SD1_CQE_2MUX1 8 +#define EIC7700_HSP_CLK_GATE_MSHC0_TMR 9 +#define EIC7700_HSP_CLK_GATE_EMMC 10 +#define EIC7700_HSP_CLK_GATE_MSHC1_TMR 11 +#define EIC7700_HSP_CLK_GATE_SD0 12 +#define EIC7700_HSP_CLK_GATE_MSHC2_TMR 13 +#define EIC7700_HSP_CLK_GATE_SD1 14 +#define EIC7700_HSP_CLK_GATE_USB0 15 +#define EIC7700_HSP_CLK_GATE_USB1 16 +#define EIC7700_HSP_CLK_GATE_SATA 17 + +#endif /* _DT_BINDINGS_ESWIN_EIC7700_HSPCRG_CLOCK_H_ */
include/dt-bindings/reset/eswin,eic7700-hspcrg.h new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */ +/* +* Copyright 2026, Beijing ESWIN Computing Technology Co., Ltd.. +* All rights reserved. +* +* Device Tree binding constants for EIC7700 HSP reset controller. +* +* Authors: Xuyang Dong <[email protected]> +*/ + +#ifndef _DT_BINDINGS_ESWIN_EIC7700_HSPCRG_RESET_H_ +#define _DT_BINDINGS_ESWIN_EIC7700_HSPCRG_RESET_H_ + +#define EIC7700_HSP_RST_SATA_P0 0 +#define EIC7700_HSP_RST_SATA_PHY 1 +#define EIC7700_HSP_RST_USB0 2 +#define EIC7700_HSP_RST_USB1 3 +#define EIC7700_HSP_RST_USB0_PHY 4 +#define EIC7700_HSP_RST_USB1_PHY 5 + +#endif /* _DT_BINDINGS_ESWIN_EIC7700_HSPCRG_RESET_H_ */
Signature · 1 line
2.34.1
[email protected]
maintainerPATCH v3 2/3 clk: eswin: Add eic7700 HSP clock driver
In reply to Xuyang DongFrom: Xuyang Dong <[email protected]>
Add driver for the ESWIN EIC7700 high-speed peripherals system clock controller and register an auxiliary device for system reset controller which is named as "hsp-reset".
--- drivers/clk/eswin/Kconfig | 12 + drivers/clk/eswin/Makefile | 1 + drivers/clk/eswin/clk-eic7700-hsp.c | 384 ++++++++++++++++++++++++++++ 3 files changed, 397 insertions(+) create mode 100644 drivers/clk/eswin/clk-eic7700-hsp.c
drivers/clk/eswin/Kconfig +12 -0
@@ -13,3 +13,15 @@ config COMMON_CLK_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. + +config COMMON_CLK_EIC7700_HSP + tristate "EIC7700 HSP Clock Driver" + depends on ARCH_ESWIN || COMPILE_TEST + select AUXILIARY_BUS + select COMMON_CLK_EIC7700 + select RESET_EIC7700_HSP if RESET_CONTROLLER + help + This driver provides support for clock controller on ESWIN EIC7700 + HSP. The clock controller generates and supplies clocks to high + speed peripherals within the SoC. + Say yes here to support the clock controller on the EIC7700 HSP.
drivers/clk/eswin/Makefile +1 -0
@@ -6,3 +6,4 @@ obj-$(CONFIG_COMMON_CLK_ESWIN) += clk.o obj-$(CONFIG_COMMON_CLK_EIC7700) += clk-eic7700.o +obj-$(CONFIG_COMMON_CLK_EIC7700_HSP) += clk-eic7700-hsp.o
drivers/clk/eswin/clk-eic7700-hsp.c new file +384 -0
384 lines not on this page · raw message
--
2.34.1
[email protected]
maintainerPATCH v3 3/3 reset: eswin: Add eic7700 HSP reset driver
In reply to Xuyang DongFrom: Xuyang Dong <[email protected]>
Add auxiliary driver to support ESWIN EIC7700 high-speed peripherals system. The reset controller is created using the auxiliary device framework and set up in the clock driver.
--- drivers/reset/Kconfig | 11 +++ drivers/reset/Makefile | 1 + drivers/reset/reset-eic7700-hsp.c | 118 ++++++++++++++++++++++++++++++ 3 files changed, 130 insertions(+) create mode 100644 drivers/reset/reset-eic7700-hsp.c
drivers/reset/Kconfig +11 -0
@@ -83,6 +83,17 @@ config RESET_EIC7700 The driver supports eic7700 series chips and provides functionality for asserting and deasserting resets on the chip. +config RESET_EIC7700_HSP + tristate "EIC7700 HSP Reset controller" + depends on ARCH_ESWIN || COMPILE_TEST + select AUXILIARY_BUS + help + This enables the HSP reset controller driver for ESWIN SoCs. This + driver is specific to ESWIN SoCs and should only be enabled if using + such hardware. + The driver supports EIC7700 series chips and provides functionality + for asserting and deasserting resets on the chip. + config RESET_EYEQ bool "Mobileye EyeQ reset controller" depends on EYEQ || COMPILE_TEST
drivers/reset/Makefile +1 -0
@@ -15,6 +15,7 @@ obj-$(CONFIG_RESET_BERLIN) += reset-berlin.o obj-$(CONFIG_RESET_BRCMSTB) += reset-brcmstb.o obj-$(CONFIG_RESET_BRCMSTB_RESCAL) += reset-brcmstb-rescal.o obj-$(CONFIG_RESET_EIC7700) += reset-eic7700.o +obj-$(CONFIG_RESET_EIC7700_HSP) += reset-eic7700-hsp.o obj-$(CONFIG_RESET_EYEQ) += reset-eyeq.o obj-$(CONFIG_RESET_GPIO) += reset-gpio.o obj-$(CONFIG_RESET_HSDK) += reset-hsdk.o
drivers/reset/reset-eic7700-hsp.c new file +118 -0
118 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v3 2/3] clk: eswin: Add eic7700 HSP clock driver
In reply to [email protected]Quoted 7 lines · On Thu, Apr 23, 2026 at 05:11:14PM +0800, [email protected] wrote:
From: Xuyang Dong <[email protected]>
Add driver for the ESWIN EIC7700 high-speed peripherals system clock controller and register an auxiliary device for system reset controller which is named as "hsp-reset".
Signed-off-by Xuyang Dong <[email protected]>
There's one minor bit I am not sure of.
drivers/clk/eswin/clk-eic7700-hsp.c line 67
Quoted 9 lines
drivers/clk/eswin/clk-eic7700-hsp.c new file +9
-0+static void eic7700_hsp_regmap_lock (void *arg) +__acquires(lock_ctx->lock) +{ +struct eic7700_hsp_regmap_lock *const lock_ctx = arg; +unsigned long flags; + +spin_lock_irqsave (lock_ctx->lock, flags); + lock_ctx->flags = flags; +}
I don't know if the __acquires() is accurate syntax. If it needs to be arg, lock_ctx->lock, or ((struct eic7700_hsp_regmap_lock *)arg)->lock.
It looks like this code is triggered with clang, and I tried compiling this driver with:
make LLVM=1 KCFLAGS="-ferror-limit=10000 -DWARN_CONTEXT_ANALYSIS -Wthread-safety" \
drivers/clk/eswin/clk-eic7700-hsp.oI also tried with 'make C=2' and I don't see any locking messages from this driver.
Brian
Re: [PATCH v3 2/3] clk: eswin: Add eic7700 HSP clock driver
In reply to [email protected]Quoted 7 lines · On Thursday, 23 April 2026 at 11:11:14 CEST, [email protected]…
rom: Xuyang Dong <[email protected]>
Add driver for the ESWIN EIC7700 high-speed peripherals system clock controller and register an auxiliary device for system reset controller which is named as "hsp-reset".
Signed-off-by Xuyang Dong <[email protected]>
Best regards,
Signature · 3 lines
Benoît Monin, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Re: [PATCH v3 3/3] reset: eswin: Add eic7700 HSP reset driver
In reply to [email protected]Quoted 103 lines · On Do, 2026-04-23 at 17:12 +0800, [email protected] wrote:
From: Xuyang Dong <[email protected]>
Add auxiliary driver to support ESWIN EIC7700 high-speed peripherals system. The reset controller is created using the auxiliary device framework and set up in the clock driver.
Signed-off-by Xuyang Dong <[email protected]>--- drivers/reset/Kconfig | 11 +++ drivers/reset/Makefile | 1 + drivers/reset/reset-eic7700-hsp.c | 118 ++++++++++++++++++++++++++++++ 3 files changed, 130 insertions(+) create mode 100644 drivers/reset/reset-eic7700-hsp.cdrivers/reset/Kconfig +11
-0@@ -83,6 +83,17 @@ config RESET_EIC7700 The driver supports eic7700 series chips and provides functionality for asserting and deasserting resets on the chip. +config RESET_EIC7700_HSP + tristate "EIC7700 HSP Reset controller" + depends on ARCH_ESWIN || COMPILE_TEST + select AUXILIARY_BUS + help + This enables the HSP reset controller driver for ESWIN SoCs. This + driver is specific to ESWIN SoCs and should only be enabled if using + such hardware. + The driver supports EIC7700 series chips and provides functionality + for asserting and deasserting resets on the chip. + config RESET_EYEQ bool "Mobileye EyeQ reset controller" depends on EYEQ || COMPILE_TESTdrivers/reset/Makefile +1
-0@@ -15,6 +15,7 @@ obj-$(CONFIG_RESET_BERLIN) += reset-berlin.o obj-$(CONFIG_RESET_BRCMSTB) += reset-brcmstb.o obj-$(CONFIG_RESET_BRCMSTB_RESCAL) += reset-brcmstb-rescal.o obj-$(CONFIG_RESET_EIC7700) += reset-eic7700.o +obj-$(CONFIG_RESET_EIC7700_HSP) += reset-eic7700-hsp.o obj-$(CONFIG_RESET_EYEQ) += reset-eyeq.o obj-$(CONFIG_RESET_GPIO) += reset-gpio.o obj-$(CONFIG_RESET_HSDK) += reset-hsdk.odrivers/reset/reset-eic7700-hsp.c new file +49
-0@@ -0,0 +1,118 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright 2026, Beijing ESWIN Computing Technology Co., Ltd.. +* All rights reserved. +* +* ESWIN EIC7700 HSP Reset Driver +* +* Authors: Xuyang Dong <[email protected]> +*/ + +#include <linux/auxiliary_bus.h> +#include <linux/device.h> +#include <linux/regmap.h> +#include <linux/reset-controller.h> + +#include <dt-bindings/reset/eswin,eic7700-hspcrg.h> + +/** +* struct eic7700_hsp_reset_data - reset controller information structure +* @rcdev: reset controller entity +* @regmap: regmap handle containing the memory-mapped reset registers +*/ +struct eic7700_hsp_reset_data { +struct reset_controller_dev rcdev; +struct regmap *regmap; +}; + +struct eic7700_hsp_reg { +u32 reg; +u32 bit; +bool active_low; +}; + +static inline struct eic7700_hsp_reset_data * +to_eic7700_hsp_reset (struct reset_controller_dev *rcdev) +{ + return container_of(rcdev, struct eic7700_hsp_reset_data, rcdev); +} + +static const struct eic7700_hsp_reg eic7700_hsp_reset[] = { + [EIC7700_HSP_RST_SATA_P0 ] = {0x340 ,BIT (0 ), false}, + [EIC7700_HSP_RST_SATA_PHY ] = {0x340 ,BIT (1 ), false}, + [EIC7700_HSP_RST_USB0 ] = {0x800 ,BIT (24 ), true}, + [EIC7700_HSP_RST_USB1 ] = {0x900 ,BIT (24 ), true}, + [EIC7700_HSP_RST_USB0_PHY ] = {0x800 ,BIT (25 ), false}, + [EIC7700_HSP_RST_USB1_PHY ] = {0x900 ,BIT (25 ), false}, +}; + +static int eic7700_hsp_reset_assert(struct reset_controller_dev *rcdev,
drivers/reset/reset-eic7700-hsp.c line 59
Quoted 10 lines
drivers/reset/reset-eic7700-hsp.c new file +10
-0+ unsigned long id) +{ +struct eic7700_hsp_reset_data *data =to_eic7700_hsp_reset (rcdev); +int ret; + + ret =regmap_assign_bits (data->regmap, eic7700_hsp_reset[id].reg, + eic7700_hsp_reset[id].bit, + !eic7700_hsp_reset[id].active_low); + +return ret;
You can drop the temporary variable, just returnregmap_assign_bits(...) directly.
Quoted 23 lines
drivers/reset/reset-eic7700-hsp.c new file +23
-0+} + +static int eic7700_hsp_reset_deassert (struct reset_controller_dev *rcdev, +unsigned long id) +{ +struct eic7700_hsp_reset_data *data =to_eic7700_hsp_reset (rcdev); +int ret; + + ret =regmap_assign_bits (data->regmap, eic7700_hsp_reset[id].reg, + eic7700_hsp_reset[id].bit, + eic7700_hsp_reset[id].active_low); + +return ret; +} + +static const struct reset_control_ops eic7700_hsp_reset_ops = { + .assert = eic7700_hsp_reset_assert, + .deassert = eic7700_hsp_reset_deassert, +}; + +static int eic7700_hsp_reset_probe (struct auxiliary_device *adev, +const struct auxiliary_device_id *id) +{
drivers/reset/reset-eic7700-hsp.c line 92
Quoted 10 lines
drivers/reset/reset-eic7700-hsp.c new file +10
-0+struct eic7700_hsp_reset_data *data; +struct device *dev = &adev->dev; + + data =devm_kzalloc (dev,sizeof (*data),GFP_KERNEL ); +if (!data) +return -ENOMEM ; + + data->regmap =dev_get_regmap (dev->parent,NULL ); +if (!data->regmap) +return dev_err_probe (dev, -EINVAL ,"failed to get regmap!\n" );
-ENODEV seems to be more commonly used for this.
drivers/reset/reset-eic7700-hsp.c line 103
Quoted 11 lines
drivers/reset/reset-eic7700-hsp.c new file +11
-0+ + data->rcdev.owner =THIS_MODULE ; + data->rcdev.ops = &eic7700_hsp_reset_ops; + data->rcdev.of_node = dev->parent->of_node; + data->rcdev.dev = dev; + data->rcdev.nr_resets =ARRAY_SIZE (eic7700_hsp_reset); + +return devm_reset_controller_register (dev, &data->rcdev); +} + +static const struct auxiliary_device_id eic7700_hsp_reset_dt_ids[] = {
Drop the "_dt".
Quoted 5 lines
drivers/reset/reset-eic7700-hsp.c new file +5
-0+ { .name = "clk_eic7700_hsp.hsp-reset", }, + {/* sentinel */ } +}; +MODULE_DEVICE_TABLE (auxiliary, eic7700_hsp_reset_dt_ids); +
drivers/reset/reset-eic7700-hsp.c line 118
Quoted 10 lines
drivers/reset/reset-eic7700-hsp.c new file +10
-0+static struct auxiliary_driver eic7700_hsp_reset_driver = { + .probe = eic7700_hsp_reset_probe, + .id_table = eic7700_hsp_reset_dt_ids, +}; + +module_auxiliary_driver (eic7700_hsp_reset_driver); + +MODULE_LICENSE ("GPL" ); +MODULE_AUTHOR ("Xuyang Dong <[email protected]>" ); +MODULE_DESCRIPTION ("ESWIN EIC7700 HSP Reset Controller Driver" );
With that,
regards
Philipp
Xuyang Dong
maintainerRe: Re: [PATCH v3 2/3] clk: eswin: Add eic7700 HSP clock driver
In reply to Brian MasneyQuoted 24 lines
Quoted 6 lines
Add driver for the ESWIN EIC7700 high-speed peripherals system clock controller and register an auxiliary device for system reset controller which is named as "hsp-reset".
Signed-off-by Xuyang Dong <[email protected]>Reviewed-by Brian Masney <[email protected]>There's one minor bit I am not sure of.
drivers/clk/eswin/clk-eic7700-hsp.c line 67
Quoted 9 lines
drivers/clk/eswin/clk-eic7700-hsp.c new file +9
-0+static void eic7700_hsp_regmap_lock (void *arg) +__acquires(lock_ctx->lock) +{ +struct eic7700_hsp_regmap_lock *const lock_ctx = arg; +unsigned long flags; + +spin_lock_irqsave (lock_ctx->lock, flags); + lock_ctx->flags = flags; +}I don't know if the
__acquires()is accurate syntax. If it needs to be arg,lock_ctx->lock, or ((structeic7700_hsp_regmap_lock*)arg)->lock.
Quoted 9 lines
It looks like this code is triggered with clang, and I tried compiling this driver with:
make LLVM=1 KCFLAGS="-ferror-limit=10000 -DWARN_CONTEXT_ANALYSIS -Wthread-safety" \ drivers/clk/eswin/clk-eic7700-hsp.oI also tried with 'make C=2' and I don't see any locking messages from this driver.
Hi Brian,
Thanks for the feedback. I did some research based on your comments.
lock_ctx is a local variable declared inside the function body. It is not in scope at the attribute site. The attribute expands to __attribute__((acquire_capability(lock_ctx->lock))), and since lock_ctx doesn't exist at the declaration point, clang's analysis cannot resolve it and silently drops the annotation. That's why you see no warnings from make C=2 or -Wthread-safety.
Why -Wthread-safety produces no output
Two reasons:
1. The lock_ctx->lock expression is unresolvable at the attribute site, so clang drops the annotation silently — no acquire/release tracking, no warnings.
2. Even if the expression were resolvable, spinlock_t in this driver is a plain pointer field (spinlock_t *lock) accessed through a void * callback — the analysis can't track lock state through that indirection.
The closest correct expression would be:__acquires(((struct eic7700_hsp_regmap_lock *)arg)->lock) But that also won't work: arg is void *, and clang's thread-safety analysis is type-based. It can't trace through a void pointer cast to determine which spinlock_t instance is being acquired. The analysis would still silently ignore it.
For void * regmap callbacks, there is no clean way to make __acquires() work, because the lock is always hidden behind the opaque pointer. The annotations should be dropped.
Based on the above analysis, I suggest removing the annotations entirely. However, I'd like to hear your thoughts on this approach.
Best regards,
Xuyang Dong
Re: Re: [PATCH v3 2/3] clk: eswin: Add eic7700 HSP clock driver
Quoted 25 lines · Xuyang Dong
Thanks for the feedback. I did some research based on your comments.
lock_ctxis a local variable declared inside the function body. It is not in scope at the attribute site. The attribute expands to __attribute__((acquire_capability(lock_ctx->lock))), and sincelock_ctxdoesn't exist at the declaration point, clang's analysis cannot resolve it and silently drops the annotation. That's why you see no warnings from make C=2 or -Wthread-safety.Why -Wthread-safety produces no output
Two reasons:
1. Thelock_ctx->lockexpression is unresolvable at the attribute site, so clang drops the annotation silently — no acquire/release tracking, no warnings.
2. Even if the expression were resolvable,spinlock_tin this driver is a plain pointer field (spinlock_t*lock) accessed through a void * callback — the analysis can't track lock state through that indirection.The closest correct expression would be:
__acquires(((struct eic7700_hsp_regmap_lock *)arg)->lock)But that also won't work: arg is void *, and clang's thread-safety analysis is type-based. It can't trace through a void pointer cast to determine whichspinlock_tinstance is being acquired. The analysis would still silently ignore it.
Quoted 6 lines
For void * regmap callbacks, there is no clean way to make
__acquires()work, because the lock is always hidden behind the opaque pointer. The annotations should be dropped.Based on the above analysis, I suggest removing the annotations entirely. However, I'd like to hear your thoughts on this approach.
I agree to remove the annotations. Before you post a new version, let's let this series sit out on the list for a week or two, and see if anyone else replies with the proper way to do this.
Brian
Stephen Boyd
maintainerRe: Re: [PATCH v3 2/3] clk: eswin: Add eic7700 HSP clock driver
Quoting Brian Masney (2026-04-24 04:15:46)
Quoted 31 lines
Quoted 29 lines · Xuyang Dong
Thanks for the feedback. I did some research based on your comments.
lock_ctxis a local variable declared inside the function body. It is not in scope at the attribute site. The attribute expands to __attribute__((acquire_capability(lock_ctx->lock))), and sincelock_ctxdoesn't exist at the declaration point, clang's analysis cannot resolve it and silently drops the annotation. That's why you see no warnings from make C=2 or -Wthread-safety.Why -Wthread-safety produces no output
Two reasons:
1. Thelock_ctx->lockexpression is unresolvable at the attribute site, so clang drops the annotation silently — no acquire/release tracking, no warnings.
2. Even if the expression were resolvable,spinlock_tin this driver is a plain pointer field (spinlock_t*lock) accessed through a void * callback — the analysis can't track lock state through that indirection.The closest correct expression would be:
__acquires(((struct eic7700_hsp_regmap_lock *)arg)->lock)But that also won't work: arg is void *, and clang's thread-safety analysis is type-based. It can't trace through a void pointer cast to determine whichspinlock_tinstance is being acquired. The analysis would still silently ignore it.For void * regmap callbacks, there is no clean way to make
__acquires()work, because the lock is always hidden behind the opaque pointer. The annotations should be dropped.
Quoted 7 lines
Quoted 2 lines
Based on the above analysis, I suggest removing the annotations entirely. However, I'd like to hear your thoughts on this approach.
I agree to remove the annotations. Before you post a new version, let's let this series sit out on the list for a week or two, and see if anyone else replies with the proper way to do this.
Why not use a regmap instead? That would enforce locking on registers and then you use the right regmap APIs to update the register under the lock (like regmap_update_bits() or something).
Xuyang Dong
maintainerRe: Re: Re: [PATCH v3 2/3] clk: eswin: Add eic7700 HSP clock driver
Quoted 36 lines
Quoting Brian Masney (2026-04-24 04:15:46)
Quoted 34 lines
Quoted 31 lines · Xuyang Dong
Thanks for the feedback. I did some research based on your comments.
lock_ctxis a local variable declared inside the function body. It is not in scope at the attribute site. The attribute expands to __attribute__((acquire_capability(lock_ctx->lock))), and sincelock_ctxdoesn't exist at the declaration point, clang's analysis cannot resolve it and silently drops the annotation. That's why you see no warnings from make C=2 or -Wthread-safety.Why -Wthread-safety produces no output
Two reasons:
1. Thelock_ctx->lockexpression is unresolvable at the attribute site, so clang drops the annotation silently — no acquire/release tracking, no warnings.
2. Even if the expression were resolvable,spinlock_tin this driver is a plain pointer field (spinlock_t*lock) accessed through a void * callback — the analysis can't track lock state through that indirection.The closest correct expression would be:
__acquires(((struct eic7700_hsp_regmap_lock *)arg)->lock)But that also won't work: arg is void *, and clang's thread-safety analysis is type-based. It can't trace through a void pointer cast to determine whichspinlock_tinstance is being acquired. The analysis would still silently ignore it.For void * regmap callbacks, there is no clean way to make
__acquires()work, because the lock is always hidden behind the opaque pointer. The annotations should be dropped.Based on the above analysis, I suggest removing the annotations entirely. However, I'd like to hear your thoughts on this approach.
Quoted 8 lines
Quoted 4 lines
I agree to remove the annotations. Before you post a new version, let's let this series sit out on the list for a week or two, and see if anyone else replies with the proper way to do this.
Why not use a regmap instead? That would enforce locking on registers and then you use the right regmap APIs to update the register under the lock (like
regmap_update_bits()or something).
Hi Stephen,
The common gate API, the HSP private API, and the reset driver all access the same register space.
Therefore, they need to be protected by the same data->lock.
Best regards,
Xuyang Dong
Re: Re: Re: [PATCH v3 2/3] clk: eswin: Add eic7700 HSP clock driver
Hi Stephen,
Quoted 44 lines · Xuyang Dong
Quoted 35 lines
Quoting Brian Masney (2026-04-24 04:15:46)
Quoted 34 lines
Quoted 31 lines · Xuyang Dong
Thanks for the feedback. I did some research based on your comments.
lock_ctxis a local variable declared inside the function body. It is not in scope at the attribute site. The attribute expands to __attribute__((acquire_capability(lock_ctx->lock))), and sincelock_ctxdoesn't exist at the declaration point, clang's analysis cannot resolve it and silently drops the annotation. That's why you see no warnings from make C=2 or -Wthread-safety.Why -Wthread-safety produces no output
Two reasons:
1. Thelock_ctx->lockexpression is unresolvable at the attribute site, so clang drops the annotation silently — no acquire/release tracking, no warnings.
2. Even if the expression were resolvable,spinlock_tin this driver is a plain pointer field (spinlock_t*lock) accessed through a void * callback — the analysis can't track lock state through that indirection.The closest correct expression would be:
__acquires(((struct eic7700_hsp_regmap_lock *)arg)->lock)But that also won't work: arg is void *, and clang's thread-safety analysis is type-based. It can't trace through a void pointer cast to determine whichspinlock_tinstance is being acquired. The analysis would still silently ignore it.For void * regmap callbacks, there is no clean way to make
__acquires()work, because the lock is always hidden behind the opaque pointer. The annotations should be dropped.Based on the above analysis, I suggest removing the annotations entirely. However, I'd like to hear your thoughts on this approach.
Quoted 8 lines
Quoted 4 lines
I agree to remove the annotations. Before you post a new version, let's let this series sit out on the list for a week or two, and see if anyone else replies with the proper way to do this.
Why not use a regmap instead? That would enforce locking on registers and then you use the right regmap APIs to update the register under the lock (like
regmap_update_bits()or something).
Quoted 5 lines
Hi Stephen,
The common gate API, the HSP private API, and the reset driver all access the same register space.
Therefore, they need to be protected by the samedata->lock.
To add to Xuyang's response: regmap is already used by this driver. These annotations are for the lock and unlock ops on the regmap.
Brian
Stephen Boyd
maintainerRe: Re: Re: [PATCH v3 2/3] clk: eswin: Add eic7700 HSP clock driver
In reply to Xuyang DongQuoting Xuyang Dong (2026-04-28 02:21:03)
Quoted 5 lines
The common gate API, the HSP private API, and the reset driver all access the same register space.
Therefore, they need to be protected by the samedata->lock.
If everything is accessing registers through regmap why aren't we using the builtin lock with struct regmap_config::use_raw_spinlock? I don't understand why we're rolling our own here.
Xuyang Dong
maintainerRe: Re: Re: Re: [PATCH v3 2/3] clk: eswin: Add eic7700 HSP clock driver
Quoted 9 lines
Quoted 5 lines
The common gate API, the HSP private API, and the reset driver all access the same register space.
Therefore, they need to be protected by the samedata->lock.If everything is accessing registers through regmap why aren't we using the builtin lock with struct
regmap_config::use_raw_spinlock? I don't understand why we're rolling our own here.
Hi Stephen,
In the HSP clock driver and reset driver, there are three components that access the HSP register space: a common gate clock, a custom gate clock (i.e., 0x800), and a reset.
1. The common gate uses eswin_clk_register_gate() to register a gate clock via devm_clk_hw_register_gate_parent_data(). It accesses the register using clk_gate_endisable().
static void clk_gate_endisable(struct clk_hw *hw, int enable)
{
struct clk_gate *gate = to_clk_gate(hw);
unsigned long flags;
if (gate->lock)
spin_lock_irqsave(gate->lock, flags);
else
__acquire(gate->lock);
...
if (gate->lock)
spin_unlock_irqrestore(gate->lock, flags);
else
__release(gate->lock);
}The gate->lock in use is the data->lock passed in from the clock driver.
2. The custom gate uses hsp_clk_register_gate() to register a gate clock. It accesses the register using hsp_clk_gate_endisable().
static void hsp_clk_gate_endisable(struct clk_hw *hw, int enable)
{
struct eic7700_hsp_clk_gate *gate = to_gate_clk(hw);
guard(spinlock_irqsave)(gate->lock);...
}
The gate->lock in use is the same data->lock passed in from the clock driver.
3. The reset uses eic7700_hsp_reset_assert() and eic7700_hsp_reset_deassert(), which call regmap_assign_bits() to access the register.
All three methods access the same register space; therefore, they must be protected by the same lock (data->lock).
That's why we introduced eic7700_hsp_regmap_lock/unlock for eic7700_hsp_regmap_config.
eic7700_hsp_regmap_config = {
.lock = eic7700_hsp_regmap_lock,
.unlock = eic7700_hsp_regmap_unlock,
.lock_arg = lock_ctx,
};The 'lock_ctx->lock' in eic7700_hsp_regmap_lock/unlock is the 'data->lock'.
static void eic7700_hsp_regmap_lock(void *arg)
__acquires(lock_ctx->lock)
{
struct eic7700_hsp_regmap_lock *const lock_ctx = arg;
unsigned long flags;
spin_lock_irqsave(lock_ctx->lock, flags);
lock_ctx->flags = flags;
}The similar approach can be found in clk-imx8ulp-sim-lpav.c.
The annotations what we mentioned previously is the above "__acquires(lock_ctx->lock)".
Best regards,
Xuyang Dong
Re: Re: Re: Re: [PATCH v3 2/3] clk: eswin: Add eic7700 HSP clock driver
Hi Xuyang,
Quoted 78 lines · Xuyang Dong
Quoted 9 lines
Quoted 5 lines
The common gate API, the HSP private API, and the reset driver all access the same register space.
Therefore, they need to be protected by the samedata->lock.If everything is accessing registers through regmap why aren't we using the builtin lock with struct
regmap_config::use_raw_spinlock? I don't understand why we're rolling our own here.Hi Stephen,
In the HSP clock driver and reset driver, there are three components that access the HSP register space: a common gate clock, a custom gate clock (i.e.,
0x800), and a reset.1. The common gate uses
eswin_clk_register_gate()to register a gate clock viadevm_clk_hw_register_gate_parent_data(). It accesses the register usingclk_gate_endisable().static void
clk_gate_endisable(struct clk_hw *hw, int enable){ struct clk_gate *gate = to_clk_gate(hw); unsigned long flags; if (gate->lock) spin_lock_irqsave(gate->lock, flags); else __acquire(gate->lock); ... if (gate->lock) spin_unlock_irqrestore(gate->lock, flags); else __release(gate->lock); }The
gate->lockin use is thedata->lockpassed in from the clock driver.2. The custom gate uses
hsp_clk_register_gate()to register a gate clock. It accesses the register usinghsp_clk_gate_endisable().static void
hsp_clk_gate_endisable(struct clk_hw *hw, int enable){ struct eic7700_hsp_clk_gate *gate = to_gate_clk(hw); guard(spinlock_irqsave)(gate->lock);...
}The
gate->lockin use is the samedata->lockpassed in from the clock driver.3. The reset uses
eic7700_hsp_reset_assert()andeic7700_hsp_reset_deassert(), which callregmap_assign_bits()to access the register.All three methods access the same register space; therefore, they must be protected by the same lock (
data->lock).That's why we introduced eic7700_hsp_regmap_lock/unlock for
eic7700_hsp_regmap_config.eic7700_hsp_regmap_config = { .lock = eic7700_hsp_regmap_lock, .unlock = eic7700_hsp_regmap_unlock, .lock_arg = lock_ctx, };The '
lock_ctx->lock' in eic7700_hsp_regmap_lock/unlock is the 'data->lock'.static void eic7700_hsp_regmap_lock(void *arg) __acquires(lock_ctx->lock) { struct eic7700_hsp_regmap_lock *const lock_ctx = arg; unsigned long flags; spin_lock_irqsave(lock_ctx->lock, flags); lock_ctx->flags = flags; }
Quoted 4 lines
The similar approach can be found in
clk-imx8ulp-sim-lpav.c.The annotations what we mentioned previously is the above "
__acquires(lock_ctx->lock)".
I see what Stephen is saying. Take a look at __regmap_init() in drivers/base/regmap/regmap.c. If the lock/unlock ops are not specified, then the final else will automatically setup locking. By default, it'll use a mutex, but there is the ability to use a spinlock.
So you can drop the lock/unlock ops from the driver, and add to the ops:
fast_io: 1, use_raw_spinlock: 1,
Given the critcal nature of clks, I agree with Stephen that a raw spinlock should be used here.
Brian
Xuyang Dong
maintainerRe: Re: Re: Re: Re: [PATCH v3 2/3] clk: eswin: Add eic7700 HSP clock driver
Quoted 90 lines · Xuyang Dong
Quoted 78 lines
Quoted 9 lines
Quoted 5 lines
The common gate API, the HSP private API, and the reset driver all access the same register space.
Therefore, they need to be protected by the samedata->lock.If everything is accessing registers through regmap why aren't we using the builtin lock with struct
regmap_config::use_raw_spinlock? I don't understand why we're rolling our own here.Hi Stephen,
In the HSP clock driver and reset driver, there are three components that access the HSP register space: a common gate clock, a custom gate clock (i.e.,
0x800), and a reset.1. The common gate uses
eswin_clk_register_gate()to register a gate clock viadevm_clk_hw_register_gate_parent_data(). It accesses the register usingclk_gate_endisable().static void
clk_gate_endisable(struct clk_hw *hw, int enable){ struct clk_gate *gate = to_clk_gate(hw); unsigned long flags; if (gate->lock) spin_lock_irqsave(gate->lock, flags); else __acquire(gate->lock); ... if (gate->lock) spin_unlock_irqrestore(gate->lock, flags); else __release(gate->lock); }The
gate->lockin use is thedata->lockpassed in from the clock driver.2. The custom gate uses
hsp_clk_register_gate()to register a gate clock. It accesses the register usinghsp_clk_gate_endisable().static void
hsp_clk_gate_endisable(struct clk_hw *hw, int enable){ struct eic7700_hsp_clk_gate *gate = to_gate_clk(hw); guard(spinlock_irqsave)(gate->lock);...
}The
gate->lockin use is the samedata->lockpassed in from the clock driver.3. The reset uses
eic7700_hsp_reset_assert()andeic7700_hsp_reset_deassert(), which callregmap_assign_bits()to access the register.All three methods access the same register space; therefore, they must be protected by the same lock (
data->lock).That's why we introduced eic7700_hsp_regmap_lock/unlock for
eic7700_hsp_regmap_config.eic7700_hsp_regmap_config = { .lock = eic7700_hsp_regmap_lock, .unlock = eic7700_hsp_regmap_unlock, .lock_arg = lock_ctx, };The '
lock_ctx->lock' in eic7700_hsp_regmap_lock/unlock is the 'data->lock'.static void eic7700_hsp_regmap_lock(void *arg) __acquires(lock_ctx->lock) { struct eic7700_hsp_regmap_lock *const lock_ctx = arg; unsigned long flags; spin_lock_irqsave(lock_ctx->lock, flags); lock_ctx->flags = flags; }Quoted 4 lines
The similar approach can be found in
clk-imx8ulp-sim-lpav.c.The annotations what we mentioned previously is the above "
__acquires(lock_ctx->lock)".I see what Stephen is saying. Take a look at
__regmap_init()indrivers/base/regmap/regmap.c. If the lock/unlock ops are not specified, then the final else will automatically setup locking. By default, it'll use a mutex, but there is the ability to use a spinlock.
Quoted 8 lines
So you can drop the lock/unlock ops from the driver, and add to the ops:
fast_io: 1, use_raw_spinlock: 1,Given the critcal nature of clks, I agree with Stephen that a raw spinlock should be used here.
Hi Stephen and Brian,
In the HSP clock driver, hsp_clk_gate_endisable() only accesses the registers at 0x800/0x900, and reset accesses the same registers as well, which leads to concurrent RMW (read-modify-write) races.
There are two approaches to solve these races.
The first method is the current implementation. All three functions (clk_gate_endisable(), hsp_clk_gate_endisable(),
and eic7700_hsp_reset_assert()) use data->lock to prevent concurrent RMW races.
The second method is as Stephen said. If I understand correctly, it is to change the register read/write operations in hsp_clk_gate_endisable() to use the regmap API and use the same lock (map->raw_spinlock) as reset.
Is the second approach preferable?
Best regards,
Xuyang Dong
Re: Re: Re: Re: Re: [PATCH v3 2/3] clk: eswin: Add eic7700 HSP clock driver
Hi Xuyang,
Quoted 111 lines · Xuyang Dong
Quoted 89 lines · Xuyang Dong
Quoted 78 lines
Quoted 9 lines
Quoted 5 lines
The common gate API, the HSP private API, and the reset driver all access the same register space.
Therefore, they need to be protected by the samedata->lock.If everything is accessing registers through regmap why aren't we using the builtin lock with struct
regmap_config::use_raw_spinlock? I don't understand why we're rolling our own here.Hi Stephen,
In the HSP clock driver and reset driver, there are three components that access the HSP register space: a common gate clock, a custom gate clock (i.e.,
0x800), and a reset.1. The common gate uses
eswin_clk_register_gate()to register a gate clock viadevm_clk_hw_register_gate_parent_data(). It accesses the register usingclk_gate_endisable().static void
clk_gate_endisable(struct clk_hw *hw, int enable){ struct clk_gate *gate = to_clk_gate(hw); unsigned long flags; if (gate->lock) spin_lock_irqsave(gate->lock, flags); else __acquire(gate->lock); ... if (gate->lock) spin_unlock_irqrestore(gate->lock, flags); else __release(gate->lock); }The
gate->lockin use is thedata->lockpassed in from the clock driver.2. The custom gate uses
hsp_clk_register_gate()to register a gate clock. It accesses the register usinghsp_clk_gate_endisable().static void
hsp_clk_gate_endisable(struct clk_hw *hw, int enable){ struct eic7700_hsp_clk_gate *gate = to_gate_clk(hw); guard(spinlock_irqsave)(gate->lock);...
}The
gate->lockin use is the samedata->lockpassed in from the clock driver.3. The reset uses
eic7700_hsp_reset_assert()andeic7700_hsp_reset_deassert(), which callregmap_assign_bits()to access the register.All three methods access the same register space; therefore, they must be protected by the same lock (
data->lock).That's why we introduced eic7700_hsp_regmap_lock/unlock for
eic7700_hsp_regmap_config.eic7700_hsp_regmap_config = { .lock = eic7700_hsp_regmap_lock, .unlock = eic7700_hsp_regmap_unlock, .lock_arg = lock_ctx, };The '
lock_ctx->lock' in eic7700_hsp_regmap_lock/unlock is the 'data->lock'.static void eic7700_hsp_regmap_lock(void *arg) __acquires(lock_ctx->lock) { struct eic7700_hsp_regmap_lock *const lock_ctx = arg; unsigned long flags; spin_lock_irqsave(lock_ctx->lock, flags); lock_ctx->flags = flags; }Quoted 4 lines
The similar approach can be found in
clk-imx8ulp-sim-lpav.c.The annotations what we mentioned previously is the above "
__acquires(lock_ctx->lock)".I see what Stephen is saying. Take a look at
__regmap_init()indrivers/base/regmap/regmap.c. If the lock/unlock ops are not specified, then the final else will automatically setup locking. By default, it'll use a mutex, but there is the ability to use a spinlock.Quoted 8 lines
So you can drop the lock/unlock ops from the driver, and add to the ops:
fast_io: 1, use_raw_spinlock: 1,Given the critcal nature of clks, I agree with Stephen that a raw spinlock should be used here.
Hi Stephen and Brian,
In the HSP clock driver,
hsp_clk_gate_endisable()only accesses the registers at 0x800/0x900, and reset accesses the same registers as well, which leads to concurrent RMW (read-modify-write) races.There are two approaches to solve these races.
The first method is the current implementation. All three functions (
clk_gate_endisable(),hsp_clk_gate_endisable(),
andeic7700_hsp_reset_assert()) usedata->lockto prevent concurrent RMW races.
Quoted 5 lines
The second method is as Stephen said. If I understand correctly, it is to change the register read/write operations in
hsp_clk_gate_endisable()to use the regmap API and use the same lock (map->raw_spinlock) as reset.Is the second approach preferable?
Use the same regmap everywhere. Also you don't have to explicitly define the raw spinlock in your driver since the regmap API will create a raw spinlock for you if you use the fast_io / use_raw_spinlock options I described above.
Brian
Xuyang Dong
maintainerRe: Re: Re: Re: Re: Re: [PATCH v3 2/3] clk: eswin: Add eic7700 HSP clock driver
Quoted 117 lines · Xuyang Dong
Quoted 115 lines
Quoted 89 lines · Xuyang Dong
Quoted 78 lines
Quoted 9 lines
Quoted 5 lines
The common gate API, the HSP private API, and the reset driver all access the same register space.
Therefore, they need to be protected by the samedata->lock.If everything is accessing registers through regmap why aren't we using the builtin lock with struct
regmap_config::use_raw_spinlock? I don't understand why we're rolling our own here.Hi Stephen,
In the HSP clock driver and reset driver, there are three components that access the HSP register space: a common gate clock, a custom gate clock (i.e.,
0x800), and a reset.1. The common gate uses
eswin_clk_register_gate()to register a gate clock viadevm_clk_hw_register_gate_parent_data(). It accesses the register usingclk_gate_endisable().static void
clk_gate_endisable(struct clk_hw *hw, int enable){ struct clk_gate *gate = to_clk_gate(hw); unsigned long flags; if (gate->lock) spin_lock_irqsave(gate->lock, flags); else __acquire(gate->lock); ... if (gate->lock) spin_unlock_irqrestore(gate->lock, flags); else __release(gate->lock); }The
gate->lockin use is thedata->lockpassed in from the clock driver.2. The custom gate uses
hsp_clk_register_gate()to register a gate clock. It accesses the register usinghsp_clk_gate_endisable().static void
hsp_clk_gate_endisable(struct clk_hw *hw, int enable){ struct eic7700_hsp_clk_gate *gate = to_gate_clk(hw); guard(spinlock_irqsave)(gate->lock);...
}The
gate->lockin use is the samedata->lockpassed in from the clock driver.3. The reset uses
eic7700_hsp_reset_assert()andeic7700_hsp_reset_deassert(), which callregmap_assign_bits()to access the register.All three methods access the same register space; therefore, they must be protected by the same lock (
data->lock).That's why we introduced eic7700_hsp_regmap_lock/unlock for
eic7700_hsp_regmap_config.eic7700_hsp_regmap_config = { .lock = eic7700_hsp_regmap_lock, .unlock = eic7700_hsp_regmap_unlock, .lock_arg = lock_ctx, };The '
lock_ctx->lock' in eic7700_hsp_regmap_lock/unlock is the 'data->lock'.static void eic7700_hsp_regmap_lock(void *arg) __acquires(lock_ctx->lock) { struct eic7700_hsp_regmap_lock *const lock_ctx = arg; unsigned long flags; spin_lock_irqsave(lock_ctx->lock, flags); lock_ctx->flags = flags; }Quoted 4 lines
The similar approach can be found in
clk-imx8ulp-sim-lpav.c.The annotations what we mentioned previously is the above "
__acquires(lock_ctx->lock)".I see what Stephen is saying. Take a look at
__regmap_init()indrivers/base/regmap/regmap.c. If the lock/unlock ops are not specified, then the final else will automatically setup locking. By default, it'll use a mutex, but there is the ability to use a spinlock.Quoted 8 lines
So you can drop the lock/unlock ops from the driver, and add to the ops:
fast_io: 1, use_raw_spinlock: 1,Given the critcal nature of clks, I agree with Stephen that a raw spinlock should be used here.
Hi Stephen and Brian,
In the HSP clock driver,
hsp_clk_gate_endisable()only accesses the registers at 0x800/0x900, and reset accesses the same registers as well, which leads to concurrent RMW (read-modify-write) races.There are two approaches to solve these races.
The first method is the current implementation. All three functions (
clk_gate_endisable(),hsp_clk_gate_endisable(),
andeic7700_hsp_reset_assert()) usedata->lockto prevent concurrent RMW races.The second method is as Stephen said. If I understand correctly, it is to change the register read/write operations in
hsp_clk_gate_endisable()to use the regmap API and use the same lock (map->raw_spinlock) as reset.
Quoted 7 lines
Quoted 1 line
Is the second approach preferable?
Use the same regmap everywhere. Also you don't have to explicitly define the raw spinlock in your driver since the regmap API will create a raw spinlock for you if you use the
fast_io/use_raw_spinlockoptions I described above.
Hi Brian,
Thank you for your time and comments. Sorry for the late reply. This will be fixed in the next version.
Best regards,
Xuyang Dong