From: Stephen Boyd <sboyd@kernel.org>
To: Daniel Mack <daniel@zonque.org>,
alsa-devel@alsa-project.org, devicetree@vger.kernel.org,
linux-clk@vger.kernel.org, linux-gpio@vger.kernel.org,
linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: mturquette@baylibre.com, robh+dt@kernel.org, broonie@kernel.org,
lee.jones@linaro.org, lars@metafoo.de, pascal.huerst@gmail.com,
Daniel Mack <daniel@zonque.org>
Subject: Re: [PATCH 09/10] clk: Add support for AD242x clock output providers
Date: Mon, 23 Dec 2019 23:46:38 -0800 [thread overview]
Message-ID: <20191224074639.1589220706@mail.kernel.org> (raw)
In-Reply-To: <20191209183511.3576038-11-daniel@zonque.org>
Quoting Daniel Mack (2019-12-09 10:35:10)
> diff --git a/drivers/clk/clk-ad242x.c b/drivers/clk/clk-ad242x.c
> new file mode 100644
> index 000000000000..201789d8f174
> --- /dev/null
> +++ b/drivers/clk/clk-ad242x.c
> @@ -0,0 +1,231 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +#include <linux/module.h>
> +#include <linux/kernel.h>
> +#include <linux/clk.h>
Is this include used?
> +#include <linux/clk-provider.h>
> +#include <linux/err.h>
> +#include <linux/errno.h>
Is this include used?
> +#include <linux/mfd/ad242x.h>
Any way we can avoid this build dependency? Maybe just put defines in
this driver that deals with the clk bits of the device?
> +#include <linux/platform_device.h>
> +#include <linux/regmap.h>
> +
> +#include <dt-bindings/clock/adi,ad242x.h>
> +
> +#define AD242X_NUM_CLKS 2
> +
> +struct ad242x_clk_hw {
> + struct clk_hw hw;
> + struct clk_init_data init;
Do we need to keep around this init data after probe? I'd rather leave
this out.
> + struct ad242x_node *node;
What's the point of this structure? Can we use dev->parent->regmap and
just store the struct regmap pointer here instead of using this custom
struct?
> + u8 reg;
> +};
> +
> +struct ad242x_clk_driver_data {
> + struct ad242x_clk_hw hw[AD242X_NUM_CLKS];
If this is the only drvdata, then I'd prefer just the array and not
another struct so we can have clarity.
> +};
> +
> +static inline struct ad242x_clk_hw *to_ad242x_clk(struct clk_hw *hw)
> +{
> + return container_of(hw, struct ad242x_clk_hw, hw);
> +}
> +
[...]
> +
> +static long ad242x_clk_round_rate(struct clk_hw *hw, unsigned long rate,
> + unsigned long *parent_rate)
> +{
> + unsigned long pll_rate = *parent_rate * 2048UL;
> + unsigned long prediv, div;
> +
> + if (rate > pll_rate / 4 || rate < pll_rate / 1024UL)
> + return -EINVAL;
This callback should round the rate to something valid. If the rate is
larger than pll_rate / 4 then it should clamp to be the highest rate
supported. Likewise for something slow.
> +
> + ad242x_do_div(rate, pll_rate, &prediv, &div);
> +
> + return pll_rate / (prediv * div);
> +}
> +
[...]
> +
> +static struct clk_hw *
> +ad242x_of_clk_get(struct of_phandle_args *clkspec, void *data)
> +{
> + struct ad242x_clk_driver_data *drvdata = data;
> + unsigned int idx = clkspec->args[0];
> +
> + return &drvdata->hw[idx].hw;
It looks quite a bit like of_clk_hw_onecell_get(). Can that be used? Or
at least check for out of bounds and return failure?
> +}
> +
> +static int ad242x_clk_probe(struct platform_device *pdev)
> +{
> + const char *clk_names[AD242X_NUM_CLKS] = { "clkout1", "clkout2" };
> + u8 regs[AD242X_NUM_CLKS] = { AD242X_CLK1CFG, AD242X_CLK2CFG };
> + struct ad242x_clk_driver_data *drvdata;
> + struct device *dev = &pdev->dev;
> + const char *sync_clk_name;
> + struct ad242x_node *node;
> + int i, ret;
> +
> + if (!dev->of_node)
> + return -ENODEV;
Please drop this. It's not useful.
> +
> + drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
> + if (!drvdata)
> + return -ENOMEM;
> +
> + node = dev_get_drvdata(dev->parent);
Add a NULL check on node?
> + sync_clk_name = ad242x_master_get_clk_name(node->master);
> +
> + for (i = 0; i < AD242X_NUM_CLKS; i++) {
> + const char *name;
> +
> + if (of_property_read_string_index(dev->of_node,
> + "clock-output-names",
> + i, &name) == 0)
> + drvdata->hw[i].init.name = name;
> + else
> + drvdata->hw[i].init.name = clk_names[i];
Do you need unique names? Or can you generate psuedo unique names based
on the device name and clk number?
> +
> + drvdata->hw[i].reg = regs[i];
> + drvdata->hw[i].init.ops = &ad242x_clk_ops;
> + drvdata->hw[i].init.num_parents = 1;
> + drvdata->hw[i].init.parent_names = &sync_clk_name;
> + drvdata->hw[i].hw.init = &drvdata->hw[i].init;
> + drvdata->hw[i].node = node;
> +
> + ret = devm_clk_hw_register(dev, &drvdata->hw[i].hw);
> + if (ret < 0)
> + return ret;
> + }
> +
> + return devm_of_clk_add_hw_provider(dev, ad242x_of_clk_get, drvdata);
> +}
next prev parent reply other threads:[~2019-12-24 7:46 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-09 18:35 [PATCH 00/10] mfd: Add support for Analog Devices A2B transceiver Daniel Mack
2019-12-09 18:35 ` [PATCH 01/10] dt-bindings: mfd: Add documentation for ad242x Daniel Mack
2019-12-19 19:29 ` Rob Herring
2019-12-09 18:35 ` [PATCH 02/10] dt-bindings: i2c: Add documentation for ad242x i2c controllers Daniel Mack
2020-01-08 3:45 ` Rob Herring
2019-12-09 18:35 ` [PATCH 03/10] dt-bindings: gpio: Add documentation for ad242x GPIO controllers Daniel Mack
2019-12-09 18:35 ` [PATCH 03/10] dt-bindings: gpio: Add documentation for AD242x " Daniel Mack
2019-12-09 18:35 ` [PATCH 04/10] dt-bindings: clock: Add documentation for AD242x clock providers Daniel Mack
2019-12-24 7:32 ` Stephen Boyd
2019-12-09 18:35 ` [PATCH 05/10] dt-bindings: sound: Add documentation for AD242x codecs Daniel Mack
2019-12-09 18:35 ` [PATCH 06/10] mfd: Add core driver for AD242x A2B transceivers Daniel Mack
2019-12-17 13:39 ` Lee Jones
2019-12-17 13:46 ` Lee Jones
2019-12-17 19:36 ` Daniel Mack
2019-12-17 19:24 ` Daniel Mack
2019-12-18 11:20 ` Luca Ceresoli
2019-12-17 19:16 ` [alsa-devel] " Pierre-Louis Bossart
2019-12-18 9:40 ` Daniel Mack
2019-12-09 18:35 ` [PATCH 07/10] i2c: Add driver for AD242x bus controller Daniel Mack
2019-12-12 16:11 ` Luca Ceresoli
2019-12-12 16:33 ` Wolfram Sang
2019-12-15 20:27 ` Daniel Mack
2019-12-17 8:35 ` Luca Ceresoli
2019-12-17 18:17 ` Daniel Mack
2019-12-09 18:35 ` [PATCH 08/10] gpio: Add driver for AD242x GPIO controllers Daniel Mack
2019-12-09 18:35 ` [PATCH 09/10] clk: Add support for AD242x clock output providers Daniel Mack
2019-12-24 7:46 ` Stephen Boyd [this message]
2019-12-09 18:35 ` [PATCH 10/10] ASoC: Add codec component for AD242x nodes Daniel Mack
2019-12-16 14:23 ` Mark Brown
2019-12-17 19:28 ` [alsa-devel] " Pierre-Louis Bossart
2019-12-18 9:49 ` Daniel Mack
2019-12-18 15:32 ` Pierre-Louis Bossart
2019-12-17 19:29 ` [alsa-devel] [PATCH 00/10] mfd: Add support for Analog Devices A2B transceiver Pierre-Louis Bossart
2019-12-18 9:53 ` Daniel Mack
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=20191224074639.1589220706@mail.kernel.org \
--to=sboyd@kernel.org \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=daniel@zonque.org \
--cc=devicetree@vger.kernel.org \
--cc=lars@metafoo.de \
--cc=lee.jones@linaro.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mturquette@baylibre.com \
--cc=pascal.huerst@gmail.com \
--cc=robh+dt@kernel.org \
/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).