mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "André Draszik" <andre.draszik@linaro.org>
To: Sebastian Reichel <sre@kernel.org>, Rob Herring <robh@kernel.org>,
	 Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>
Cc: Peter Griffin <peter.griffin@linaro.org>,
	Tudor Ambarus	 <tudor.ambarus@linaro.org>,
	Will McVicker <willmcvicker@google.com>,
	 kernel-team@android.com, linux-pm@vger.kernel.org,
	devicetree@vger.kernel.org, 	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/2] power: reset: syscon-reboot: support different reset modes
Date: Wed, 26 Feb 2025 19:10:02 +0000	[thread overview]
Message-ID: <135bdfc38dad8994b94318174a970fd22dc87f45.camel@linaro.org> (raw)
In-Reply-To: <20250226-syscon-reboot-reset-mode-v2-2-f80886370bb7@linaro.org>

On Wed, 2025-02-26 at 16:44 +0000, André Draszik wrote:
> Linux supports a couple different reset modes, but this driver here
> doesn't distinguish between them and issues the same syscon register
> write irrespective of the reset mode requested by the kernel.
> 
> Update this driver to support most of Linux' reset modes: cold, hard,
> warm, and soft.
> 
> The actions to take for these are taken from DT, and are all new
> optional properties. The property names match the existing properties
> supported but should be prefixed with the reset mode.
> 
> This change is meant to be backwards compatible with existing DTs, and
> if Linux requests a reset mode that this driver doesn't support, or
> that the DT doesn't specify, the reset is triggered using the fallback
> / default entry.
> 
> As an example why this is useful, other than properly supporting the
> Linux reboot= kernel command line option or sysfs entry, this change
> allows platforms to e.g. default to a more secure cold-reset, but
> also to do a warm-reset in case RAM contents needs to be retained
> across the reset.
> 
> Signed-off-by: André Draszik <andre.draszik@linaro.org>
> ---
>  drivers/power/reset/syscon-reboot.c | 88 ++++++++++++++++++++++++++++++++-----
>  1 file changed, 77 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/power/reset/syscon-reboot.c b/drivers/power/reset/syscon-reboot.c
> index d623d77e657e4c233d8ae88bb099bee13c48a9ef..1d3d8a3265ae8005c685b42d3e554bd8bb0047ea 100644
> --- a/drivers/power/reset/syscon-reboot.c
> +++ b/drivers/power/reset/syscon-reboot.c
> @@ -14,11 +14,29 @@
>  #include <linux/reboot.h>
>  #include <linux/regmap.h>
>  
> -struct syscon_reboot_context {
> -	struct regmap *map;
> +/* REBOOT_GPIO doesn't make sense for syscon-reboot */
> +static const struct {
> +	enum reboot_mode mode;
> +	const char *prefix;
> +} prefix_map[] = {
> +	{ .mode = REBOOT_COLD, .prefix = "cold"  },
> +	{ .mode = REBOOT_WARM, .prefix = "warm"  },
> +	{ .mode = REBOOT_HARD, .prefix = "hard"  },
> +	{ .mode = REBOOT_SOFT, .prefix = "soft"  },
> +};
> +
> +struct reboot_mode_bits {
>  	u32 offset;
>  	u32 value;
>  	u32 mask;
> +	bool valid;
> +};
> +
> +struct syscon_reboot_context {
> +	struct regmap *map;
> +
> +	struct reboot_mode_bits mode_bits[REBOOT_SOFT + 1];
> +	struct reboot_mode_bits catchall;
>  	struct notifier_block restart_handler;
>  };
>  
> @@ -28,9 +46,16 @@ static int syscon_restart_handle(struct notifier_block *this,
>  	struct syscon_reboot_context *ctx =
>  			container_of(this, struct syscon_reboot_context,
>  					restart_handler);
> +	const struct reboot_mode_bits *mode_bits;
> +
> +	if (mode < ARRAY_SIZE(ctx->mode_bits) && ctx->mode_bits[mode].valid)
> +		mode_bits = &ctx->mode_bits[mode];
> +	else
> +		mode_bits = &ctx->catchall;
>  
>  	/* Issue the reboot */
> -	regmap_update_bits(ctx->map, ctx->offset, ctx->mask, ctx->value);
> +	regmap_update_bits(ctx->map, mode_bits->offset, mode_bits->mask,
> +			   mode_bits->value);
>  
>  	mdelay(1000);
>  
> @@ -45,6 +70,7 @@ static int syscon_reboot_probe(struct platform_device *pdev)
>  	int mask_err, value_err;
>  	int priority;
>  	int err;
> +	char prop[32];
>  
>  	ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
>  	if (!ctx)
> @@ -60,12 +86,52 @@ static int syscon_reboot_probe(struct platform_device *pdev)
>  	if (of_property_read_s32(pdev->dev.of_node, "priority", &priority))
>  		priority = 192;
>  
> -	if (of_property_read_u32(pdev->dev.of_node, "offset", &ctx->offset))
> -		if (of_property_read_u32(pdev->dev.of_node, "reg", &ctx->offset))
> +	BUILD_BUG_ON(ARRAY_SIZE(prefix_map) != ARRAY_SIZE(ctx->mode_bits));
> +	BUILD_BUG_ON(ARRAY_SIZE(ctx->mode_bits) <= REBOOT_COLD);
> +	BUILD_BUG_ON(ARRAY_SIZE(ctx->mode_bits) <= REBOOT_WARM);
> +	BUILD_BUG_ON(ARRAY_SIZE(ctx->mode_bits) <= REBOOT_HARD);
> +	BUILD_BUG_ON(ARRAY_SIZE(ctx->mode_bits) <= REBOOT_SOFT);
> +
> +	for (int i = 0; i < ARRAY_SIZE(prefix_map); ++i) {
> +		const char * const prefix = prefix_map[i].prefix;
> +		struct reboot_mode_bits * const mode_bits =
> +			&ctx->mode_bits[prefix_map[i].mode];
> +
> +		snprintf(prop, sizeof(prop), "%s-offset", prefix);
> +		if (of_property_read_u32(pdev->dev.of_node, "offset",
> +					 &mode_bits->offset))
> +			continue;

It should also check the %-reg property, and it needs
to use prop instead of "offset" in of_property_read_u32().

A.


      reply	other threads:[~2025-02-26 19:10 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-26 16:44 [PATCH v2 0/2] support Linux reboot modes in syscon-reboot André Draszik
2025-02-26 16:44 ` [PATCH v2 1/2] dt-bindings: reset: syscon-reboot: support reset modes André Draszik
2025-02-26 16:44 ` [PATCH v2 2/2] power: reset: syscon-reboot: support different " André Draszik
2025-02-26 19:10   ` André Draszik [this message]

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=135bdfc38dad8994b94318174a970fd22dc87f45.camel@linaro.org \
    --to=andre.draszik@linaro.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=kernel-team@android.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=peter.griffin@linaro.org \
    --cc=robh@kernel.org \
    --cc=sre@kernel.org \
    --cc=tudor.ambarus@linaro.org \
    --cc=willmcvicker@google.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®