From: Philipp Zabel <p.zabel@pengutronix.de>
To: Yu-Chun Lin <eleanor.lin@realtek.com>,
mturquette@baylibre.com, sboyd@kernel.org, robh@kernel.org,
krzk+dt@kernel.org, conor+dt@kernel.org, cylee12@realtek.com,
jyanchou@realtek.com
Cc: devicetree@vger.kernel.org, linux-clk@vger.kernel.org,
linux-kernel@vger.kernel.org, james.tai@realtek.com,
cy.huang@realtek.com, stanley_chang@realtek.com
Subject: Re: [PATCH v3 2/9] clk: realtek: Add basic reset support
Date: Tue, 10 Mar 2026 11:57:51 +0100 [thread overview]
Message-ID: <c9e71072faea57cff1ef51cbf85121654c74a3aa.camel@pengutronix.de> (raw)
In-Reply-To: <20260122110857.12995-3-eleanor.lin@realtek.com>
On Do, 2026-01-22 at 19:08 +0800, Yu-Chun Lin wrote:
> From: Cheng-Yu Lee <cylee12@realtek.com>
>
> Define the reset operations backed by a regmap-based register
> interface and prepare the reset controller to be registered
> through the reset framework.
>
> Signed-off-by: Cheng-Yu Lee <cylee12@realtek.com>
> Co-developed-by: Yu-Chun Lin <eleanor.lin@realtek.com>
> Signed-off-by: Yu-Chun Lin <eleanor.lin@realtek.com>
> ---
> Changes in v3:
> - Reduced the number of IDs per bank from 256 to 32, eliminating unnecessary
> gaps.
> - Converted macro to static inline function.
> - Removed redundant functions.
> - Used UL() to prevent undefined behavior.
> ---
> MAINTAINERS | 1 +
> drivers/clk/Kconfig | 1 +
> drivers/clk/Makefile | 1 +
> drivers/clk/realtek/Kconfig | 28 +++++++++
> drivers/clk/realtek/Makefile | 4 ++
> drivers/clk/realtek/reset.c | 111 +++++++++++++++++++++++++++++++++++
> drivers/clk/realtek/reset.h | 36 +++++++++++
> 7 files changed, 183 insertions(+)
> create mode 100644 drivers/clk/realtek/Kconfig
> create mode 100644 drivers/clk/realtek/Makefile
> create mode 100644 drivers/clk/realtek/reset.c
> create mode 100644 drivers/clk/realtek/reset.h
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 66c0f4924c1e..de772e0026de 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -21975,6 +21975,7 @@ L: devicetree@vger.kernel.org
> L: linux-clk@vger.kernel.org
> S: Supported
> F: Documentation/devicetree/bindings/clock/realtek*
> +F: drivers/clk/realtek/*
> F: include/dt-bindings/clock/realtek*
>
> REALTEK SPI-NAND
> diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
> index 3a1611008e48..2f2cacf87c38 100644
> --- a/drivers/clk/Kconfig
> +++ b/drivers/clk/Kconfig
> @@ -530,6 +530,7 @@ source "drivers/clk/nuvoton/Kconfig"
> source "drivers/clk/pistachio/Kconfig"
> source "drivers/clk/qcom/Kconfig"
> source "drivers/clk/ralink/Kconfig"
> +source "drivers/clk/realtek/Kconfig"
> source "drivers/clk/renesas/Kconfig"
> source "drivers/clk/rockchip/Kconfig"
> source "drivers/clk/samsung/Kconfig"
> diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
> index 61ec08404442..075a1c410b90 100644
> --- a/drivers/clk/Makefile
> +++ b/drivers/clk/Makefile
> @@ -141,6 +141,7 @@ obj-$(CONFIG_COMMON_CLK_PISTACHIO) += pistachio/
> obj-$(CONFIG_COMMON_CLK_PXA) += pxa/
> obj-$(CONFIG_COMMON_CLK_QCOM) += qcom/
> obj-y += ralink/
> +obj-$(CONFIG_COMMON_CLK_REALTEK) += realtek/
> obj-y += renesas/
> obj-$(CONFIG_ARCH_ROCKCHIP) += rockchip/
> obj-$(CONFIG_COMMON_CLK_SAMSUNG) += samsung/
> diff --git a/drivers/clk/realtek/Kconfig b/drivers/clk/realtek/Kconfig
> new file mode 100644
> index 000000000000..121158f11dd1
> --- /dev/null
> +++ b/drivers/clk/realtek/Kconfig
> @@ -0,0 +1,28 @@
> +# SPDX-License-Identifier: GPL-2.0-only
> +config COMMON_CLK_REALTEK
> + bool "Clock driver for Realtek SoCs"
> + depends on ARCH_REALTEK || COMPILE_TEST
> + select MFD_SYSCON
> + default y
> + help
> + Enable the common clock framework infrastructure for Realtek
> + system-on-chip platforms.
> +
> + This provides the base support required by individual Realtek
> + clock controller drivers to expose clocks to peripheral devices.
> +
> + If you have a Realtek-based platform, say Y.
> +
> +if COMMON_CLK_REALTEK
> +
> +config RTK_CLK_COMMON
> + tristate "Realtek Clock Common"
> + select RESET_CONTROLLER
> + help
> + Common helper code shared by Realtek clock controller drivers.
> +
> + This provides utility functions and data structures used by
> + multiple Realtek clock implementations, and include integration
> + with reset controllers where required.
> +
> +endif
> diff --git a/drivers/clk/realtek/Makefile b/drivers/clk/realtek/Makefile
> new file mode 100644
> index 000000000000..52267de2eef4
> --- /dev/null
> +++ b/drivers/clk/realtek/Makefile
> @@ -0,0 +1,4 @@
> +# SPDX-License-Identifier: GPL-2.0-only
> +obj-$(CONFIG_RTK_CLK_COMMON) += clk-rtk.o
> +
> +clk-rtk-y += reset.o
> diff --git a/drivers/clk/realtek/reset.c b/drivers/clk/realtek/reset.c
> new file mode 100644
> index 000000000000..4d60a73fc335
> --- /dev/null
> +++ b/drivers/clk/realtek/reset.c
> @@ -0,0 +1,111 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Copyright (C) 2019 Realtek Semiconductor Corporation
> + */
> +
> +#include <linux/of.h>
> +#include <linux/device.h>
> +#include "reset.h"
> +
> +#define RTK_RESET_BANK_SHIFT 5
> +#define RTK_RESET_ID_MASK 0x1f
> +
> +static inline struct rtk_reset_data *to_rtk_reset_controller(struct reset_controller_dev *r)
> +{
> + return container_of(r, struct rtk_reset_data, rcdev);
> +}
> +
> +static inline struct rtk_reset_bank *
> +rtk_reset_get_bank(struct rtk_reset_data *data, unsigned long idx)
> +{
> + int bank_id = idx >> RTK_RESET_BANK_SHIFT;
> +
> + return &data->banks[bank_id];
> +}
> +
> +static inline int rtk_reset_get_id(struct rtk_reset_data *data,
Data is unused.
> + unsigned long idx)
> +{
> + return idx & RTK_RESET_ID_MASK;
> +}
> +
> +static int rtk_reset_assert(struct reset_controller_dev *rcdev,
> + unsigned long idx)
> +{
> + struct rtk_reset_data *data = to_rtk_reset_controller(rcdev);
> + struct rtk_reset_bank *bank = rtk_reset_get_bank(data, idx);
> + u32 id = rtk_reset_get_id(data, idx);
Data not used in rtk_reset_get_id().
> + u32 mask = bank->write_en ? (UL(0x3) << id) : BIT(id);
> + u32 val = bank->write_en ? (UL(0x2) << id) : 0;
> +
> + return regmap_update_bits(data->regmap, bank->ofs, mask, val);
> +}
> +
> +static int rtk_reset_deassert(struct reset_controller_dev *rcdev,
> + unsigned long idx)
> +{
> + struct rtk_reset_data *data = to_rtk_reset_controller(rcdev);
> + struct rtk_reset_bank *bank = rtk_reset_get_bank(data, idx);
> + u32 id = rtk_reset_get_id(data, idx);
Same as above.
> + u32 mask = bank->write_en ? (0x3 << id) : BIT(id);
> + u32 val = mask;
> +
> + return regmap_update_bits(data->regmap, bank->ofs, mask, val);
> +}
> +
> +static int rtk_reset_reset(struct reset_controller_dev *rcdev,
> + unsigned long idx)
> +{
> + int ret;
> +
> + ret = rtk_reset_assert(rcdev, idx);
> + if (ret)
> + return ret;
> + return rtk_reset_deassert(rcdev, idx);
> +}
Are there any users of this? Does this work for all consumers, without
any delay between assert and deassert? Don't just implement the .reset
callback for the sake of it.
> +
> +static int rtk_reset_status(struct reset_controller_dev *rcdev,
> + unsigned long idx)
> +{
> + struct rtk_reset_data *data = to_rtk_reset_controller(rcdev);
> + struct rtk_reset_bank *bank = &data->banks[idx >> RTK_RESET_BANK_SHIFT];
> + u32 id = idx & RTK_RESET_ID_MASK;
u32 id = rtk_reset_get_id(idx);
> + u32 val;
> + int ret;
> +
> + ret = regmap_read(data->regmap, bank->ofs, &val);
> + if (ret)
> + return ret;
> +
> + return !((val >> id) & 1);
> +}
> +
> +static const struct reset_control_ops rtk_reset_ops = {
> + .reset = rtk_reset_reset,
> + .assert = rtk_reset_assert,
> + .deassert = rtk_reset_deassert,
> + .status = rtk_reset_status,
> +};
> +
> +int rtk_reset_controller_add(struct device *dev,
> + struct rtk_reset_initdata *initdata)
> +{
> + struct rtk_reset_data *data;
> +
> + data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
> + if (!data)
> + return -ENOMEM;
> +
> + data->dev = dev;
data->dev is unused.
> + data->num_banks = initdata->num_banks;
data->num_banks is unused.
> + data->banks = initdata->banks;
> + data->regmap = initdata->regmap;
> + data->rcdev.owner = THIS_MODULE;
> + data->rcdev.ops = &rtk_reset_ops;
> + data->rcdev.dev = dev;
> + data->rcdev.of_node = dev->of_node;
> + data->rcdev.nr_resets = initdata->num_banks * 32;
> +
> + return devm_reset_controller_register(dev, &data->rcdev);
> +}
> +EXPORT_SYMBOL_GPL(rtk_reset_controller_add);
> diff --git a/drivers/clk/realtek/reset.h b/drivers/clk/realtek/reset.h
> new file mode 100644
> index 000000000000..cd446b098429
> --- /dev/null
> +++ b/drivers/clk/realtek/reset.h
> @@ -0,0 +1,36 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +/*
> + * Copyright (C) 2019 Realtek Semiconductor Corporation
> + * Author: Cheng-Yu Lee <cylee12@realtek.com>
> + */
> +
> +#ifndef __CLK_REALTEK_RESET_H
> +#define __CLK_REALTEK_RESET_H
> +
> +#include <linux/regmap.h>
Instead of including regmap.h, you can forward declare struct regmap.
> +#include <linux/reset-controller.h>
> +#include <linux/hwspinlock.h>
Unused header.
> +
> +struct rtk_reset_bank {
> + u32 ofs;
> + u32 write_en;
> +};
> +
> +struct rtk_reset_data {
> + struct device *dev;
> + struct reset_controller_dev rcdev;
> + struct rtk_reset_bank *banks;
> + u32 num_banks;
> + struct regmap *regmap;
> +};
Why is rtk_reset_data in the header? You can move it into reset.c.
> +
> +struct rtk_reset_initdata {
> + struct rtk_reset_bank *banks;
> + u32 num_banks;
> + struct regmap *regmap;
> +};
> +
> +int rtk_reset_controller_add(struct device *dev,
> + struct rtk_reset_initdata *initdata);
> +
> +#endif /* __CLK_REALTEK_RESET_H */
regards
Philipp
next prev parent reply other threads:[~2026-03-10 10:58 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-22 11:08 [PATCH v3 0/9] clk: realtek: Add RTD1625 Clock Support Yu-Chun Lin
2026-01-22 11:08 ` [PATCH v3 1/9] dt-bindings: clock: Add Realtek RTD1625 Clock & Reset Controller Yu-Chun Lin
2026-01-22 11:08 ` [PATCH v3 2/9] clk: realtek: Add basic reset support Yu-Chun Lin
2026-03-10 10:57 ` Philipp Zabel [this message]
2026-01-22 11:08 ` [PATCH v3 3/9] clk: realtek: Introduce a common probe() Yu-Chun Lin
2026-01-22 11:08 ` [PATCH v3 4/9] clk: realtek: Add support for phase locked loops (PLLs) Yu-Chun Lin
2026-01-22 11:08 ` [PATCH v3 5/9] clk: realtek: Add support for gate clock Yu-Chun Lin
2026-01-22 11:08 ` [PATCH v3 6/9] clk: realtek: Add support for mux clock Yu-Chun Lin
2026-01-22 11:08 ` [PATCH v3 7/9] clk: realtek: Add support for MMC-tuned PLL clocks Yu-Chun Lin
2026-01-22 11:08 ` [PATCH v3 8/9] clk: realtek: Add RTD1625-CRT clock controller driver Yu-Chun Lin
2026-01-22 11:08 ` [PATCH v3 9/9] clk: realtek: Add RTD1625-ISO " Yu-Chun Lin
2026-03-10 10:38 ` [PATCH v3 0/9] clk: realtek: Add RTD1625 Clock Support Yu-Chun Lin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c9e71072faea57cff1ef51cbf85121654c74a3aa.camel@pengutronix.de \
--to=p.zabel@pengutronix.de \
--cc=conor+dt@kernel.org \
--cc=cy.huang@realtek.com \
--cc=cylee12@realtek.com \
--cc=devicetree@vger.kernel.org \
--cc=eleanor.lin@realtek.com \
--cc=james.tai@realtek.com \
--cc=jyanchou@realtek.com \
--cc=krzk+dt@kernel.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mturquette@baylibre.com \
--cc=robh@kernel.org \
--cc=sboyd@kernel.org \
--cc=stanley_chang@realtek.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®