devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Boyd <sboyd@kernel.org>
To: devicetree@vger.kernel.org, f.fainelli@gmail.com,
	jonas.gorski@gmail.com, krzysztof.kozlowski+dt@linaro.org,
	linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org,
	mturquette@baylibre.com, p.zabel@pengutronix.de,
	robh+dt@kernel.org, william.zhang@broadcom.com,
	"Álvaro Fernández Rojas" <noltari@gmail.com>
Cc: "Álvaro Fernández Rojas" <noltari@gmail.com>
Subject: Re: [PATCH v3 4/4] clk: bcm: Add BCM63268 timer clock and reset driver
Date: Tue, 21 Mar 2023 15:57:34 -0700	[thread overview]
Message-ID: <3a1d7b271a42324c056d983e1943b386.sboyd@kernel.org> (raw)
In-Reply-To: <20230321201022.1052743-5-noltari@gmail.com>

Quoting Álvaro Fernández Rojas (2023-03-21 13:10:22)
> diff --git a/drivers/clk/bcm/clk-bcm63268-timer.c b/drivers/clk/bcm/clk-bcm63268-timer.c
> new file mode 100644
> index 000000000000..6a1fdd193cb5
> --- /dev/null
> +++ b/drivers/clk/bcm/clk-bcm63268-timer.c
> @@ -0,0 +1,232 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * BCM63268 Timer Clock and Reset Controller Driver
[...]
> +
> +static inline struct bcm63268_tclkrst_hw *
> +to_bcm63268_timer_reset(struct reset_controller_dev *rcdev)
> +{
> +       return container_of(rcdev, struct bcm63268_tclkrst_hw, rcdev);
> +}
> +
> +static int bcm63268_timer_reset_update(struct reset_controller_dev *rcdev,
> +                               unsigned long id, bool assert)
> +{
> +       struct bcm63268_tclkrst_hw *reset = to_bcm63268_timer_reset(rcdev);
> +       unsigned long flags;
> +       uint32_t val;
> +
> +       spin_lock_irqsave(&reset->lock, flags);
> +       val = __raw_readl(reset->regs);

Use regular ol readl() here, unless you have some need for no barrires
or byte swapping.

> +       if (assert)
> +               val &= ~BIT(id);
> +       else
> +               val |= BIT(id);
> +       __raw_writel(val, reset->regs);

Same.

> +       spin_unlock_irqrestore(&reset->lock, flags);
> +
> +       return 0;
> +}
> +
[...]
> +
> +static int bcm63268_tclk_probe(struct platform_device *pdev)
> +{
> +       struct device *dev = &pdev->dev;
> +       const struct bcm63268_tclk_table_entry *entry, *table;
> +       struct bcm63268_tclkrst_hw *hw;
> +       struct clk_hw *clk;
> +       u8 maxbit = 0;
> +       int i, ret;
> +
> +       table = of_device_get_match_data(dev);

Use device_get_match_data() instead.

> +       if (!table)
> +               return -EINVAL;
> +
> +       for (entry = table; entry->name; entry++)
> +               maxbit = max(maxbit, entry->bit);
> +       maxbit++;
> +
> +       hw = devm_kzalloc(&pdev->dev, struct_size(hw, data.hws, maxbit),
> +                         GFP_KERNEL);
> +       if (!hw)
> +               return -ENOMEM;
> +
> +       platform_set_drvdata(pdev, hw);
> +
> +       spin_lock_init(&hw->lock);
> +
> +       hw->data.num = maxbit;
> +       for (i = 0; i < maxbit; i++)
> +               hw->data.hws[i] = ERR_PTR(-ENODEV);
> +
> +       hw->regs = devm_platform_ioremap_resource(pdev, 0);
> +       if (IS_ERR(hw->regs))
> +               return PTR_ERR(hw->regs);
> +
> +       for (entry = table; entry->name; entry++) {
> +               clk = clk_hw_register_gate(dev, entry->name, NULL, 0,

Use devm?

> +                                          hw->regs, entry->bit,
> +                                          CLK_GATE_BIG_ENDIAN, &hw->lock);
> +               if (IS_ERR(clk)) {
> +                       ret = PTR_ERR(clk);
> +                       goto out_err;
> +               }
> +
> +               hw->data.hws[entry->bit] = clk;
> +       }
> +
> +       ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
> +                                         &hw->data);
> +       if (ret)
> +               return ret;
> +
> +       hw->rcdev.of_node = dev->of_node;
> +       hw->rcdev.ops = &bcm63268_timer_reset_ops;
> +
> +       ret = devm_reset_controller_register(dev, &hw->rcdev);
> +       if (ret)
> +               dev_err(dev, "Failed to register reset controller\n");
> +
> +       return 0;
> +
> +out_err:
> +       for (i = 0; i < hw->data.num; i++) {
> +               if (!IS_ERR(hw->data.hws[i]))
> +                       clk_hw_unregister_gate(hw->data.hws[i]);

And then drop this?

> +       }
> +
> +       return ret;
> +}
> +
> +static const struct of_device_id bcm63268_tclk_dt_ids[] = {
> +       {
> +               .compatible = "brcm,bcm63268-timer-clocks",
> +               .data = &bcm63268_timer_clocks,

Are you planning on adding more SoCs to this driver? The data can
currently be always assumed to be bcm63268_timer_clocks

> +       }, {
> +               /* sentinel */
> +       }
> +};
> +

  reply	other threads:[~2023-03-21 22:57 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-15 12:26 [PATCH v2 0/4] clk: add BCM63268 timer clock and reset Álvaro Fernández Rojas
2021-03-15 12:26 ` [PATCH v2 1/4] dt-bindings: clk: add BCM63268 timer clock definitions Álvaro Fernández Rojas
2021-03-15 12:26 ` [PATCH v2 2/4] dt-bindings: reset: add BCM63268 timer reset definitions Álvaro Fernández Rojas
2021-03-15 12:26 ` [PATCH v2 3/4] dt-bindings: clock: Add BCM63268 timer binding Álvaro Fernández Rojas
2021-03-15 12:26 ` [PATCH v2 4/4] clk: bcm: Add BCM63268 timer clock and reset driver Álvaro Fernández Rojas
2023-03-21 20:10 ` [PATCH v3 0/4] clk: add BCM63268 timer clock and reset Álvaro Fernández Rojas
2023-03-21 20:10   ` [PATCH v3 1/4] dt-bindings: clk: add BCM63268 timer clock definitions Álvaro Fernández Rojas
2023-03-21 20:10   ` [PATCH v3 2/4] dt-bindings: reset: add BCM63268 timer reset definitions Álvaro Fernández Rojas
2023-03-21 20:10   ` [PATCH v3 3/4] dt-bindings: clock: Add BCM63268 timer binding Álvaro Fernández Rojas
2023-03-21 20:10   ` [PATCH v3 4/4] clk: bcm: Add BCM63268 timer clock and reset driver Álvaro Fernández Rojas
2023-03-21 22:57     ` Stephen Boyd [this message]
2023-03-21 23:00       ` Florian Fainelli
2023-03-21 23:06         ` Stephen Boyd
2023-03-21 23:09           ` Florian Fainelli
2023-03-21 23:23             ` Stephen Boyd
2023-03-22 17:17               ` Álvaro Fernández Rojas
2023-03-22 17:18               ` Florian Fainelli
2023-03-21 22:54   ` [PATCH v3 0/4] clk: add BCM63268 timer clock and reset Stephen Boyd
2023-03-22 17:18     ` Álvaro Fernández Rojas

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=3a1d7b271a42324c056d983e1943b386.sboyd@kernel.org \
    --to=sboyd@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=f.fainelli@gmail.com \
    --cc=jonas.gorski@gmail.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=noltari@gmail.com \
    --cc=p.zabel@pengutronix.de \
    --cc=robh+dt@kernel.org \
    --cc=william.zhang@broadcom.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).