The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Maxime Ripard <maxime@cerno.tech>
To: Wilken Gottwalt <wilken.gottwalt@posteo.net>
Cc: linux-kernel@vger.kernel.org, Ohad Ben-Cohen <ohad@wizery.com>,
	Bjorn Andersson <bjorn.andersson@linaro.org>,
	Baolin Wang <baolin.wang7@gmail.com>,
	Rob Herring <robh+dt@kernel.org>, Chen-Yu Tsai <wens@csie.org>,
	Jernej Skrabec <jernej.skrabec@siol.net>
Subject: Re: [PATCH v3 2/2] hwspinlock: add sun8i hardware spinlock support
Date: Mon, 7 Dec 2020 17:17:37 +0100	[thread overview]
Message-ID: <20201207161737.z75lsqlkfv65krmm@gilmour> (raw)
In-Reply-To: <296866d054f0373e8af9e3226e59844ebc791a5e.1607353274.git.wilken.gottwalt@posteo.net>

[-- Attachment #1: Type: text/plain, Size: 3615 bytes --]

On Mon, Dec 07, 2020 at 05:05:34PM +0100, Wilken Gottwalt wrote:
> +	io_base = devm_platform_ioremap_resource(pdev, SPINLOCK_BASE_ID);
> +	if (IS_ERR(io_base)) {
> +		err = PTR_ERR(io_base);
> +		dev_err(&pdev->dev, "unable to request MMIO (%d)\n", err);

There's already a message printed by the core if it fails

> +		return err;
> +	}
> +
> +	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
> +	if (!priv)
> +		return -ENOMEM;
> +
> +	err = devm_add_action_or_reset(&pdev->dev, sun8i_hwspinlock_disable, priv);
> +	if (err) {
> +		dev_err(&pdev->dev, "unable to add disable action\n");
> +		return err;
> +	}

If the next call fails, you're going to free some resources that you
haven't taken in the first place.

> +
> +	priv->ahb_clk = devm_clk_get(&pdev->dev, "ahb");
> +	if (IS_ERR(priv->ahb_clk)) {
> +		err = PTR_ERR(priv->ahb_clk);
> +		dev_err(&pdev->dev, "unable to get AHB clock (%d)\n", err);
> +		return err;
> +	}
> +
> +	priv->reset = devm_reset_control_get_optional(&pdev->dev, "ahb");

Your binding has it mandatory, so you don't really need it to be
optional?

> +	if (IS_ERR(priv->reset)) {
> +		return dev_err_probe(&pdev->dev, PTR_ERR(priv->reset),
> +				     "unable to get reset control\n");
> +	}

You shouldn't have braces on a single line return

> +
> +	err = reset_control_deassert(priv->reset);
> +	if (err) {
> +		dev_err(&pdev->dev, "deassert reset control failure (%d)\n", err);
> +		return err;
> +	}
> +
> +	err = clk_prepare_enable(priv->ahb_clk);
> +	if (err) {
> +		dev_err(&pdev->dev, "unable to prepare AHB clk (%d)\n", err);
> +		return err;
> +	}
> +
> +	/*
> +	 * bit 28 and 29 hold the amount of spinlock banks, but at the same time the datasheet
> +	 * says, bit 30 and 31 are reserved while the values can be 0 to 4, which is not reachable
> +	 * by two bits alone, so the reserved bits are also taken into account
> +	 */
> +	num_banks = readl(io_base + SPINLOCK_SYSSTATUS_REG) >> 28;
> +	switch (num_banks) {
> +	case 1 ... 4:
> +		/*
> +		 * 32, 64, 128 and 256 spinlocks are supported by the hardware implementation,
> +		 * though most of the SoCs support 32 spinlocks only
> +		 */
> +		priv->nlocks = 1 << (4 + num_banks);
> +		break;
> +	default:
> +		dev_err(&pdev->dev, "unsupported hwspinlock setup (%d)\n", num_banks);
> +		return -EINVAL;
> +	}
> +
> +	priv->bank = devm_kzalloc(&pdev->dev, struct_size(priv->bank, lock, priv->nlocks),
> +				  GFP_KERNEL);
> +	if (!priv->bank)
> +		return -ENOMEM;
> +
> +	for (i = 0; i < priv->nlocks; ++i) {
> +		hwlock = &priv->bank->lock[i];
> +		hwlock->priv = io_base + SPINLOCK_LOCK_REGN + sizeof(u32) * i;
> +	}
> +
> +	sun8i_hwspinlock_debugfs_init(priv);
> +	platform_set_drvdata(pdev, priv);
> +
> +	return devm_hwspin_lock_register(&pdev->dev, priv->bank, &sun8i_hwspinlock_ops,
> +					 SPINLOCK_BASE_ID, priv->nlocks);
> +}
> +
> +static const struct of_device_id sun8i_hwspinlock_ids[] = {
> +	{ .compatible = "allwinner,sun8i-hwspinlock", },
> +	{},
> +};
> +MODULE_DEVICE_TABLE(of, sun8i_hwspinlock_ids);
> +
> +static struct platform_driver sun8i_hwspinlock_driver = {
> +	.probe	= sun8i_hwspinlock_probe,
> +	.driver	= {
> +		.name		= DRIVER_NAME,
> +		.of_match_table	= sun8i_hwspinlock_ids,
> +	},
> +};
> +
> +static int __init sun8i_hwspinlock_init(void)
> +{
> +	return platform_driver_register(&sun8i_hwspinlock_driver);
> +}
> +module_init(sun8i_hwspinlock_init);
> +
> +static void __exit sun8i_hwspinlock_exit(void)
> +{
> +	platform_driver_unregister(&sun8i_hwspinlock_driver);
> +}
> +module_exit(sun8i_hwspinlock_exit);

This can be replaced by module_platform_driver

Maxime

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

      reply	other threads:[~2020-12-07 16:18 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-07 16:04 [PATCH v3 0/2] hwspinlock: add sun8i hardware spinlock support Wilken Gottwalt
2020-12-07 16:05 ` [PATCH v3 1/2] dt-bindings: hwlock: add sun8i_hwspinlock documentation Wilken Gottwalt
2020-12-07 16:12   ` Maxime Ripard
2020-12-08  3:22     ` Samuel Holland
2020-12-08  5:11       ` Wilken Gottwalt
2020-12-14  0:55         ` Samuel Holland
2020-12-07 16:05 ` [PATCH v3 2/2] hwspinlock: add sun8i hardware spinlock support Wilken Gottwalt
2020-12-07 16:17   ` Maxime Ripard [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=20201207161737.z75lsqlkfv65krmm@gilmour \
    --to=maxime@cerno.tech \
    --cc=baolin.wang7@gmail.com \
    --cc=bjorn.andersson@linaro.org \
    --cc=jernej.skrabec@siol.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ohad@wizery.com \
    --cc=robh+dt@kernel.org \
    --cc=wens@csie.org \
    --cc=wilken.gottwalt@posteo.net \
    /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