devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Philipp Zabel <p.zabel@pengutronix.de>
To: Qin Jian <qinjian@cqplus1.com>, robh+dt@kernel.org
Cc: mturquette@baylibre.com, sboyd@kernel.org, tglx@linutronix.de,
	maz@kernel.org, linux@armlinux.org.uk, broonie@kernel.org,
	arnd@arndb.de, linux-arm-kernel@lists.infradead.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-clk@vger.kernel.org, wells.lu@sunplus.com
Subject: Re: [PATCH v5 04/10] reset: Add Sunplus SP7021 reset driver
Date: Tue, 07 Dec 2021 09:35:30 +0100	[thread overview]
Message-ID: <75d34242693a41978fb7c6703dac3fd3a6437172.camel@pengutronix.de> (raw)
In-Reply-To: <5b847375ae9591dfd0551c86141102e02b450479.1638515726.git.qinjian@cqplus1.com>

On Fri, 2021-12-03 at 15:34 +0800, Qin Jian wrote:
[...]
> diff --git a/drivers/reset/reset-sunplus.c b/drivers/reset/reset-sunplus.c
> new file mode 100644
> index 000000000..a1d88dbaf
> --- /dev/null
> +++ b/drivers/reset/reset-sunplus.c
> @@ -0,0 +1,132 @@
> +// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> +/*
> + * SP7021 reset driver
> + *
> + * Copyright (C) Sunplus Technology Co., Ltd.
> + *       All rights reserved.
> + */
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/device.h>
> +#include <linux/err.h>
> +#include <linux/io.h>
> +#include <linux/of.h>
> +#include <linux/platform_device.h>
> +#include <linux/reset-controller.h>
> +#include <linux/reboot.h>
> +
> +/* HIWORD_MASK_REG BITS */
> +#define BITS_PER_HWM_REG	16
> +
> +struct sp_reset_data {
> +	struct reset_controller_dev rcdev;
> +	void __iomem *membase;
> +} *sp_reset;
     ^^^^^^^^^^

I'd prefer if you removed the global sp_reset pointer.

[...]
> +static int sp_restart(struct notifier_block *this, unsigned long mode,
> +		      void *cmd)
> +{

You could embed the sp_restart_nb notifier block in struct sp_reset_data
and use container_of(this, struct sp_reset_data, notifier) to get to the
rcdev here.

> +	sp_reset_assert(&sp_reset->rcdev, 0);
> +	sp_reset_deassert(&sp_reset->rcdev, 0);
> +
> +	return NOTIFY_DONE;
> +}
> +
> +static struct notifier_block sp_restart_nb = {
> +	.notifier_call = sp_restart,
> +	.priority = 192,
> +};
> +
> +static const struct reset_control_ops sp_reset_ops = {
> +	.assert   = sp_reset_assert,
> +	.deassert = sp_reset_deassert,
> +	.status   = sp_reset_status,
> +};
> +
> +static const struct of_device_id sp_reset_dt_ids[] = {
> +	{.compatible = "sunplus,sp7021-reset",},
> +	{ /* sentinel */ },
> +};
> +
> +static int sp_reset_probe(struct platform_device *pdev)
> +{
> +	struct device *dev = &pdev->dev;
> +	void __iomem *membase;
> +	struct resource *res;
> +
> +	sp_reset = devm_kzalloc(&pdev->dev, sizeof(*sp_reset), GFP_KERNEL);
> +	if (!sp_reset)
> +		return -ENOMEM;
> +
> +	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +	membase = devm_ioremap_resource(dev, res);
> +	if (IS_ERR(membase))
> +		return PTR_ERR(membase);
> +
> +	sp_reset->membase = membase;
> +	sp_reset->rcdev.owner = THIS_MODULE;
> +	sp_reset->rcdev.nr_resets = resource_size(res) / 4 * 16;	/* HIWORD_MASK */
> +	sp_reset->rcdev.ops = &sp_reset_ops;
> +	sp_reset->rcdev.of_node = dev->of_node;
> +	register_restart_handler(&sp_restart_nb);

Either do this after devm_reset_controller_register(), which could
theoretically fail with -ENOMEM, or call unregister_restart_handler() in
the error case below.

> +
> +	return devm_reset_controller_register(dev, &sp_reset->rcdev);
> +}
> +
> +static struct platform_driver sp_reset_driver = {
> +	.probe = sp_reset_probe,
> +	.driver = {
> +		   .name = "sunplus-reset",
> +		   .of_match_table = sp_reset_dt_ids,
		^
Please fix the indentation, two tabs here.

		.suppress_bind_attrs = true,

to stop unbinding the driver. Alternatively, add a driver remove
function that unregisters the restart handler.

> +		   },
	^
One tab here.

> +};
> +
> +module_platform_driver(sp_reset_driver);
> +
> +MODULE_AUTHOR("Edwin Chiu <edwin.chiu@sunplus.com>");
> +MODULE_DESCRIPTION("Sunplus Reset Driver");
> +MODULE_LICENSE("GPL v2");

regards
Philipp

  reply	other threads:[~2021-12-07  8:35 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-03  7:34 [PATCH v5 00/10] Add Sunplus SP7021 SoC Support Qin Jian
2021-12-03  7:34 ` [PATCH v5 01/10] dt-bindings: vendor-prefixes: Add Sunplus Qin Jian
2021-12-03  7:34 ` [PATCH v5 02/10] dt-bindings: arm: sunplus: Add bindings for Sunplus SP7021 SoC boards Qin Jian
2021-12-03  7:34 ` [PATCH v5 03/10] dt-bindings: reset: Add bindings for SP7021 reset driver Qin Jian
2021-12-03  7:34 ` [PATCH v5 04/10] reset: Add Sunplus " Qin Jian
2021-12-07  8:35   ` Philipp Zabel [this message]
2021-12-03  7:34 ` [PATCH v5 05/10] dt-bindings: clock: Add bindings for SP7021 clock driver Qin Jian
2021-12-16  6:43   ` Stephen Boyd
2021-12-03  7:34 ` [PATCH v5 06/10] clk: Add Sunplus " Qin Jian
2021-12-16  6:42   ` Stephen Boyd
2021-12-03  7:34 ` [PATCH v5 07/10] dt-bindings: interrupt-controller: Add bindings for SP7021 interrupt controller Qin Jian
2021-12-03  7:34 ` [PATCH v5 08/10] irqchip: Add Sunplus SP7021 interrupt controller driver Qin Jian
2021-12-07  9:02   ` Marc Zyngier
2021-12-08  7:15     ` qinjian[覃健]
2021-12-08  7:45       ` Marc Zyngier
2021-12-08  9:28         ` qinjian[覃健]
2021-12-08 16:02           ` Marc Zyngier
2021-12-03  7:34 ` [PATCH v5 09/10] ARM: sunplus: Add initial support for Sunplus SP7021 SoC Qin Jian
2021-12-03 12:59   ` Arnd Bergmann
2021-12-07  7:21     ` qinjian[覃健]
2021-12-07  9:11       ` Arnd Bergmann
2021-12-09  8:49         ` qinjian[覃健]
2021-12-09  9:58           ` Arnd Bergmann
2021-12-09 10:12             ` Ard Biesheuvel
2021-12-03  7:34 ` [PATCH v5 10/10] ARM: sp7021_defconfig: Add Sunplus SP7021 defconfig Qin Jian
2021-12-03 12:49   ` Arnd Bergmann

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=75d34242693a41978fb7c6703dac3fd3a6437172.camel@pengutronix.de \
    --to=p.zabel@pengutronix.de \
    --cc=arnd@arndb.de \
    --cc=broonie@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=maz@kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=qinjian@cqplus1.com \
    --cc=robh+dt@kernel.org \
    --cc=sboyd@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=wells.lu@sunplus.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;
as well as URLs for NNTP newsgroup(s).