From: Philipp Zabel <p.zabel@pengutronix.de>
To: Alex Elder <elder@riscstar.com>,
robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org,
mturquette@baylibre.com, sboyd@kernel.org,
paul.walmsley@sifive.com, palmer@dabbelt.com,
aou@eecs.berkeley.edu, alex@ghiti.fr, dlan@gentoo.org
Cc: heylenay@4d2.org, inochiama@outlook.com, guodong@riscstar.com,
devicetree@vger.kernel.org, linux-clk@vger.kernel.org,
spacemit@lists.linux.dev, linux-riscv@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6 4/6] reset: spacemit: add support for SpacemiT CCU resets
Date: Thu, 08 May 2025 11:01:50 +0200 [thread overview]
Message-ID: <8b5d8045041f2f07b68066e4e541d5e42282fa9b.camel@pengutronix.de> (raw)
In-Reply-To: <20250506210638.2800228-5-elder@riscstar.com>
Hi Alex,
On Di, 2025-05-06 at 16:06 -0500, Alex Elder wrote:
> Implement reset support for SpacemiT CCUs. The code is structured to
> handle SpacemiT resets generically, while defining the set of specific
> reset controllers and their resets in an SoC-specific source file.
Are you confident that future SpacemiT CCUs will be sufficiently
similar for this split to make sense? This feels like it could be a
premature abstraction to me.
> A SpacemiT reset controller device is an auxiliary device associated with
> a clock controller (CCU).
>
> This initial patch defines the reset controllers for the MPMU, APBC, and
> MPMU CCUs, which already defined clock controllers.
>
> Signed-off-by: Alex Elder <elder@riscstar.com>
> ---
> drivers/reset/Kconfig | 1 +
> drivers/reset/Makefile | 1 +
> drivers/reset/spacemit/Kconfig | 12 +++
> drivers/reset/spacemit/Makefile | 7 ++
> drivers/reset/spacemit/core.c | 61 +++++++++++
> drivers/reset/spacemit/core.h | 39 +++++++
> drivers/reset/spacemit/k1.c | 177 ++++++++++++++++++++++++++++++++
> 7 files changed, 298 insertions(+)
> create mode 100644 drivers/reset/spacemit/Kconfig
> create mode 100644 drivers/reset/spacemit/Makefile
> create mode 100644 drivers/reset/spacemit/core.c
> create mode 100644 drivers/reset/spacemit/core.h
> create mode 100644 drivers/reset/spacemit/k1.c
>
> diff --git a/drivers/reset/Kconfig b/drivers/reset/Kconfig
> index 99f6f9784e686..b1f1af50ca10b 100644
> --- a/drivers/reset/Kconfig
> +++ b/drivers/reset/Kconfig
> @@ -354,6 +354,7 @@ source "drivers/reset/amlogic/Kconfig"
> source "drivers/reset/starfive/Kconfig"
> source "drivers/reset/sti/Kconfig"
> source "drivers/reset/hisilicon/Kconfig"
> +source "drivers/reset/spacemit/Kconfig"
> source "drivers/reset/tegra/Kconfig"
>
> endif
> diff --git a/drivers/reset/Makefile b/drivers/reset/Makefile
> index 31f9904d13f9c..6c19fd875ff13 100644
> --- a/drivers/reset/Makefile
> +++ b/drivers/reset/Makefile
> @@ -2,6 +2,7 @@
> obj-y += core.o
> obj-y += amlogic/
> obj-y += hisilicon/
> +obj-y += spacemit/
> obj-y += starfive/
> obj-y += sti/
> obj-y += tegra/
> diff --git a/drivers/reset/spacemit/Kconfig b/drivers/reset/spacemit/Kconfig
> new file mode 100644
> index 0000000000000..4ff3487a99eff
> --- /dev/null
> +++ b/drivers/reset/spacemit/Kconfig
> @@ -0,0 +1,12 @@
> +# SPDX-License-Identifier: GPL-2.0-only
> +
> +config RESET_SPACEMIT
> + bool
> +
> +config RESET_SPACEMIT_K1
> + tristate "SpacemiT K1 reset driver"
> + depends on ARCH_SPACEMIT || COMPILE_TEST
> + select RESET_SPACEMIT
> + default ARCH_SPACEMIT
> + help
> + This enables the reset controller driver for the SpacemiT K1 SoC.
Does the size of the K1 specific parts even warrant this per-SoC
Kconfig option? I suggest to only have a user visible tristate
RESET_SPACEMIT option.
> diff --git a/drivers/reset/spacemit/Makefile b/drivers/reset/spacemit/Makefile
> new file mode 100644
> index 0000000000000..3a064e9d5d6b4
> --- /dev/null
> +++ b/drivers/reset/spacemit/Makefile
> @@ -0,0 +1,7 @@
> +# SPDX-License-Identifier: GPL-2.0
> +
> +obj-$(CONFIG_RESET_SPACEMIT) += reset_spacemit.o
> +
> +reset_spacemit-y := core.o
> +
> +reset_spacemit-$(CONFIG_RESET_SPACEMIT_K1) += k1.o
> diff --git a/drivers/reset/spacemit/core.c b/drivers/reset/spacemit/core.c
> new file mode 100644
> index 0000000000000..5cd981eb3f097
> --- /dev/null
> +++ b/drivers/reset/spacemit/core.c
> @@ -0,0 +1,61 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +
> +/* SpacemiT reset driver core */
> +
> +#include <linux/container_of.h>
> +#include <linux/regmap.h>
> +#include <linux/reset-controller.h>
> +#include <linux/types.h>
> +
> +#include "core.h"
> +
> +static int spacemit_reset_update(struct reset_controller_dev *rcdev,
> + unsigned long id, bool assert)
> +{
> + struct ccu_reset_controller *controller;
> + const struct ccu_reset_data *data;
> + u32 mask;
> + u32 val;
> +
> + controller = container_of(rcdev, struct ccu_reset_controller, rcdev);
> + data = &controller->data->reset_data[id];
> + mask = data->assert_mask | data->deassert_mask;
> + val = assert ? data->assert_mask : data->deassert_mask;
> +
> + return regmap_update_bits(controller->regmap, data->offset, mask, val);
> +}
> +
> +static int spacemit_reset_assert(struct reset_controller_dev *rcdev,
> + unsigned long id)
> +{
> + return spacemit_reset_update(rcdev, id, true);
> +}
> +
> +static int spacemit_reset_deassert(struct reset_controller_dev *rcdev,
> + unsigned long id)
> +{
> + return spacemit_reset_update(rcdev, id, false);
> +}
> +
> +static const struct reset_control_ops spacemit_reset_control_ops = {
> + .assert = spacemit_reset_assert,
> + .deassert = spacemit_reset_deassert,
> +};
> +
> +/**
> + * spacemit_reset_controller_register() - register a reset controller
> + * @dev: Device that's registering the controller
> + * @controller: SpacemiT CCU reset controller structure
> + */
> +int spacemit_reset_controller_register(struct device *dev,
> + struct ccu_reset_controller *controller)
> +{
> + struct reset_controller_dev *rcdev = &controller->rcdev;
> +
> + rcdev->ops = &spacemit_reset_control_ops;
> + rcdev->owner = THIS_MODULE;
> + rcdev->of_node = dev->of_node;
> + rcdev->nr_resets = controller->data->count;
> +
> + return devm_reset_controller_register(dev, &controller->rcdev);
> +}
> diff --git a/drivers/reset/spacemit/core.h b/drivers/reset/spacemit/core.h
> new file mode 100644
> index 0000000000000..a71f835ccb779
> --- /dev/null
> +++ b/drivers/reset/spacemit/core.h
> @@ -0,0 +1,39 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +
> +/* SpacemiT reset driver core */
> +
> +#ifndef __RESET_SPACEMIT_CORE_H__
> +#define __RESET_SPACEMIT_CORE_H__
> +
> +#include <linux/device.h>
This include can be replaced by forward declarations for struct device
and struct regmap.
> +#include <linux/reset-controller.h>
> +#include <linux/types.h>
> +
> +struct ccu_reset_data {
> + u32 offset;
> + u32 assert_mask;
> + u32 deassert_mask;
> +};
> +
> +#define RESET_DATA(_offset, _assert_mask, _deassert_mask) \
> + { \
> + .offset = (_offset), \
> + .assert_mask = (_assert_mask), \
> + .deassert_mask = (_deassert_mask), \
> + }
> +
> +struct ccu_reset_controller_data {
> + const struct ccu_reset_data *reset_data; /* array */
> + size_t count;
> +};
> +
> +struct ccu_reset_controller {
> + struct reset_controller_dev rcdev;
> + const struct ccu_reset_controller_data *data;
> + struct regmap *regmap;
> +};
> +
> +extern int spacemit_reset_controller_register(struct device *dev,
> + struct ccu_reset_controller *controller);
Drop the extern keyword.
> +
> +#endif /* __RESET_SPACEMIT_CORE_H__ */
> diff --git a/drivers/reset/spacemit/k1.c b/drivers/reset/spacemit/k1.c
> new file mode 100644
> index 0000000000000..19a34f151b214
> --- /dev/null
> +++ b/drivers/reset/spacemit/k1.c
> @@ -0,0 +1,177 @@
[...]
> +static int spacemit_k1_reset_probe(struct auxiliary_device *adev,
> + const struct auxiliary_device_id *id)
> +{
> + struct spacemit_ccu_adev *rdev = to_spacemit_ccu_adev(adev);
> + const void *data = (void *)id->driver_data;
> + struct ccu_reset_controller *controller;
> + struct device *dev = &adev->dev;
> +
> + controller = devm_kzalloc(dev, sizeof(*controller), GFP_KERNEL);
> + if (!controller)
> + return -ENODEV;
-ENOMEM, this is a failed memory allocation.
regards
Philipp
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2025-05-08 9:22 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-06 21:06 [PATCH v6 0/6] clk: spacemit: add K1 reset support Alex Elder
2025-05-06 21:06 ` [PATCH v6 1/6] dt-bindings: soc: spacemit: define spacemit,k1-ccu resets Alex Elder
2025-05-07 22:35 ` Yixun Lan
2025-05-08 2:19 ` Alex Elder
2025-05-08 12:02 ` Krzysztof Kozlowski
2025-05-08 12:17 ` Alex Elder
2025-05-08 12:36 ` Krzysztof Kozlowski
2025-05-08 12:42 ` Alex Elder
2025-05-08 12:40 ` Yixun Lan
2025-05-06 21:06 ` [PATCH v6 2/6] soc: spacemit: create a header for clock/reset registers Alex Elder
2025-05-08 4:16 ` Haylen Chu
2025-05-08 11:40 ` Alex Elder
2025-05-06 21:06 ` [PATCH v6 3/6] clk: spacemit: set up reset auxiliary devices Alex Elder
2025-05-08 4:09 ` kernel test robot
2025-05-08 4:46 ` Haylen Chu
2025-05-08 20:04 ` Alex Elder
2025-05-08 20:17 ` Alex Elder
2025-05-06 21:06 ` [PATCH v6 4/6] reset: spacemit: add support for SpacemiT CCU resets Alex Elder
2025-05-08 5:38 ` Haylen Chu
2025-05-08 11:55 ` Alex Elder
2025-05-08 12:47 ` Haylen Chu
2025-05-08 9:01 ` Philipp Zabel [this message]
2025-05-08 12:05 ` Alex Elder
2025-05-06 21:06 ` [PATCH v6 5/6] reset: spacemit: define three more CCUs Alex Elder
2025-05-08 9:11 ` Philipp Zabel
2025-05-08 12:29 ` Alex Elder
2025-05-06 21:06 ` [PATCH v6 6/6] riscv: dts: spacemit: add reset support for the K1 SoC Alex Elder
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=8b5d8045041f2f07b68066e4e541d5e42282fa9b.camel@pengutronix.de \
--to=p.zabel@pengutronix.de \
--cc=alex@ghiti.fr \
--cc=aou@eecs.berkeley.edu \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlan@gentoo.org \
--cc=elder@riscstar.com \
--cc=guodong@riscstar.com \
--cc=heylenay@4d2.org \
--cc=inochiama@outlook.com \
--cc=krzk+dt@kernel.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=mturquette@baylibre.com \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=robh@kernel.org \
--cc=sboyd@kernel.org \
--cc=spacemit@lists.linux.dev \
/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