From: Stephen Boyd <sboyd@kernel.org>
To: "Alvin Šipraga" <alvin@pqrs.dk>,
"Andi Shyti" <andi.shyti@kernel.org>,
"Bartosz Golaszewski" <brgl@bgdev.pl>,
"Conor Dooley" <conor+dt@kernel.org>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Jaroslav Kysela" <perex@perex.cz>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Liam Girdwood" <lgirdwood@gmail.com>,
"Linus Walleij" <linus.walleij@linaro.org>,
"Mark Brown" <broonie@kernel.org>,
"Michael Turquette" <mturquette@baylibre.com>,
"Rafael J. Wysocki" <rafael@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Saravana Kannan" <saravanak@google.com>,
"Takashi Iwai" <tiwai@suse.com>
Cc: "Emil Svendsen" <emas@bang-olufsen.dk>,
linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
linux-gpio@vger.kernel.org, linux-sound@vger.kernel.org,
linux-clk@vger.kernel.org, linux-i2c@vger.kernel.org,
"Alvin Šipraga" <alsi@bang-olufsen.dk>
Subject: Re: [PATCH 08/13] clk: add AD24xx clock driver
Date: Mon, 03 Jun 2024 17:10:25 -0700 [thread overview]
Message-ID: <8e6fcde41671b0a1e8365214e6df4ec2.sboyd@kernel.org> (raw)
In-Reply-To: <20240517-a2b-v1-8-b8647554c67b@bang-olufsen.dk>
Quoting Alvin Šipraga (2024-05-17 06:02:15)
> diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
> index 3e9099504fad..a3d54b077e68 100644
> --- a/drivers/clk/Kconfig
> +++ b/drivers/clk/Kconfig
> @@ -257,6 +257,13 @@ config COMMON_CLK_LAN966X
> LAN966X SoC. GCK generates and supplies clock to various peripherals
> within the SoC.
>
> +config COMMON_CLK_AD24XX
> + bool "Clock driver for Analog Devices Inc. AD24xx"
tristate
> + depends on A2B_AD24XX_NODE
Please make it be COMPILE_TESTed as well?
> + help
> + This driver supports the clock output functionality of AD24xx series
> + A2B transceiver chips.
> +
> config COMMON_CLK_ASPEED
> bool "Clock driver for Aspeed BMC SoCs"
> depends on ARCH_ASPEED || COMPILE_TEST
> diff --git a/drivers/clk/clk-ad24xx.c b/drivers/clk/clk-ad24xx.c
> new file mode 100644
> index 000000000000..ed227c317faa
> --- /dev/null
> +++ b/drivers/clk/clk-ad24xx.c
> @@ -0,0 +1,341 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * AD24xx clock driver
> + *
> + * Copyright (c) 2023 Alvin Šipraga <alsi@bang-olufsen.dk>
> + */
> +
> +#include <linux/a2b/a2b.h>
> +#include <linux/a2b/ad24xx.h>
> +#include <linux/clk-provider.h>
> +#include <linux/module.h>
> +#include <linux/regmap.h>
Include header for static_assert() at least. There's probably more that
are needed, please check.
> +
> +#define AD24XX_NUM_CLKS 2
> +
> +/* Define some safe macros to make the code more readable */
> +#define A2B_CLKCFG(_idx) (!(_idx) ? A2B_CLK1CFG : A2B_CLK2CFG)
> +
> +#define A2B_CLKCFG_DIV_SHIFT A2B_CLK1CFG_CLK1DIV_SHIFT
> +#define A2B_CLKCFG_PDIV_SHIFT A2B_CLK1CFG_CLK1PDIV_SHIFT
> +
> +#define A2B_CLKCFG_DIV_MASK A2B_CLK1CFG_CLK1DIV_MASK
> +#define A2B_CLKCFG_PDIV_MASK A2B_CLK1CFG_CLK1PDIV_MASK
> +#define A2B_CLKCFG_INV_MASK A2B_CLK1CFG_CLK1INV_MASK
> +#define A2B_CLKCFG_EN_MASK A2B_CLK1CFG_CLK1EN_MASK
> +
> +static_assert(A2B_CLK1CFG_CLK1DIV_MASK == A2B_CLK2CFG_CLK2DIV_MASK);
> +static_assert(A2B_CLK1CFG_CLK1PDIV_MASK == A2B_CLK2CFG_CLK2PDIV_MASK);
> +static_assert(A2B_CLK1CFG_CLK1INV_MASK == A2B_CLK2CFG_CLK2INV_MASK);
> +static_assert(A2B_CLK1CFG_CLK1EN_MASK == A2B_CLK2CFG_CLK2EN_MASK);
> +
> +struct ad24xx_clkout {
> + struct clk_hw hw;
> + unsigned int idx;
> + bool registered;
> +};
> +
> +struct ad24xx_clk {
> + struct device *dev;
Is this used?
> + struct a2b_func *func;
Is this used?
> + struct a2b_node *node;
Is this used?
> + struct regmap *regmap;
> + struct clk_hw *pll_hw;
Is this used outside of probe?
> + struct ad24xx_clkout clkouts[AD24XX_NUM_CLKS];
> +};
> +
[..]
> +
> +static const struct regmap_config ad24xx_clk_regmap_config = {
> + .reg_bits = 8,
> + .val_bits = 8,
> + .cache_type = REGCACHE_RBTREE,
No max_register?
> +};
> +
> +static struct clk_hw *ad24xx_clk_of_get(struct of_phandle_args *clkspec, void *data)
> +{
> + struct ad24xx_clk *adclk = data;
> + unsigned int idx = clkspec->args[0];
> +
> + if (idx >= AD24XX_NUM_CLKS)
> + return ERR_PTR(-EINVAL);
> +
> + if (!adclk->clkouts[idx].registered)
> + return ERR_PTR(-ENOENT);
> +
> + return &adclk->clkouts[idx].hw;
> +}
> +
> +static int ad24xx_clk_probe(struct device *dev)
> +{
> + struct a2b_func *func = to_a2b_func(dev);
> + struct a2b_node *node = func->node;
> + struct device_node *np = dev->of_node;
> + char *pll_name;
> + const char *sync_clk_name;
> + struct ad24xx_clk *adclk;
> + int num_clks;
> + int ret;
> + int i;
> +
> + /*
> + * Older series AD240x and AD241x chips have a single discrete
> + * A2B_CLKCFG register that behaves differently to the A2B_CLKnCFG
> + * registers of the later AD242x series. This driver only supports the
> + * latter right now.
> + */
> + if (!(node->chip_info->caps & A2B_CHIP_CAP_CLKOUT))
> + return -ENODEV;
Maybe print a warning message to make it more obvious.
> +
> + adclk = devm_kzalloc(dev, sizeof(*adclk), GFP_KERNEL);
> + if (!adclk)
> + return -ENOMEM;
> +
> + adclk->regmap =
> + devm_regmap_init_a2b_func(func, &ad24xx_clk_regmap_config);
Put it on one line please .
> + if (IS_ERR(adclk->regmap))
> + return PTR_ERR(adclk->regmap);
> +
> + adclk->dev = dev;
> + adclk->func = func;
> + adclk->node = node;
> + dev_set_drvdata(dev, adclk);
> +
> + num_clks = of_property_count_strings(np, "clock-output-names");
> + if (num_clks < 0 || num_clks > AD24XX_NUM_CLKS)
> + return -EINVAL;
Please register all the clks provided by this chip.
> +
> + /*
> + * Register the PLL internally to use it as the parent of the CLKOUTs.
> + * The PLL runs at 2048 times the SYNC clock rate.
> + */
> + pll_name =
> + devm_kasprintf(dev, GFP_KERNEL, "%s_pll", dev_name(&node->dev));
> + if (!pll_name)
> + return -ENOMEM;
> + sync_clk_name = __clk_get_name(a2b_node_get_sync_clk(func->node));
> + adclk->pll_hw = devm_clk_hw_register_fixed_factor(
> + dev, pll_name, sync_clk_name, 0, 2048, 1);
I think this should be devm_clk_hw_register_fixed_factor_fwname().
> + if (IS_ERR(adclk->pll_hw))
> + return PTR_ERR(adclk->pll_hw);
> +
> + for (i = 0; i < num_clks; i++) {
> + struct clk_init_data init = { };
> + const char *parent_names = clk_hw_get_name(adclk->pll_hw);
Please use struct clk_parent_data instead of strings to describe
topology.
> + unsigned int idx = i;
> +
> + /* Clock outputs can be skipped with the clock-indices property */
> + of_property_read_u32_index(np, "clock-indices", i, &idx);
> + if (idx > AD24XX_NUM_CLKS)
> + return -EINVAL;
> +
> + ret = of_property_read_string_index(np, "clock-output-names", i,
> + &init.name);
The name should only be for debug purposes. Please don't use
clock-output-names DT property. If you need to make it unique perhaps
you can add in the device name or something like that?
> + if (ret)
> + return ret;
> +
> + init.ops = &ad24xx_clk_ops;
> + init.parent_names = &parent_names;
> + init.num_parents = 1;
> +
> + adclk->clkouts[idx].hw.init = &init;
> + adclk->clkouts[idx].idx = idx;
> + adclk->clkouts[idx].registered = true;
> +
> + ret = devm_clk_hw_register(dev, &adclk->clkouts[idx].hw);
> + if (ret)
> + return ret;
> + }
> +
> + ret = devm_of_clk_add_hw_provider(dev, ad24xx_clk_of_get, adclk);
> + if (ret)
> + return ret;
> +
> + return 0;
Please just return devm_of_clk_add_hw_provider(...) to prevent the
cleanup crews from sending a followup patch.
> +}
> +
> +static const struct of_device_id ad24xx_clk_of_match_table[] = {
> + { .compatible = "adi,ad2420-clk" },
> + { .compatible = "adi,ad2421-clk" },
> + { .compatible = "adi,ad2422-clk" },
> + { .compatible = "adi,ad2425-clk" },
> + { .compatible = "adi,ad2426-clk" },
> + { .compatible = "adi,ad2427-clk" },
> + { .compatible = "adi,ad2428-clk" },
> + { .compatible = "adi,ad2429-clk" },
> + { /* sentinel */ }
> +};
> +MODULE_DEVICE_TABLE(of, ad24xx_clk_of_match_table);
> +
> +static struct a2b_driver ad24xx_clk_driver = {
I guess because this isn't a platform driver I can't merge this through
the clk tree? Is there any difference from the platform bus?
> + .driver = {
> + .name = "ad24xx-clk",
> + .of_match_table = ad24xx_clk_of_match_table,
> + .probe_type = PROBE_PREFER_ASYNCHRONOUS,
> + },
> + .probe = ad24xx_clk_probe,
> +};
> +module_a2b_driver(ad24xx_clk_driver);
next prev parent reply other threads:[~2024-06-04 0:10 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-17 12:57 [PATCH 00/13] Analog Devices Inc. Automotive Audio Bus (A2B) support Alvin Šipraga
2024-05-17 12:57 ` [PATCH 01/13] a2b: add A2B driver core Alvin Šipraga
2024-05-18 12:46 ` kernel test robot
2024-05-19 7:15 ` Markus Elfring
2024-05-19 7:33 ` Markus Elfring
2024-05-19 8:38 ` Markus Elfring
2024-05-21 7:11 ` Alvin Šipraga
2024-05-21 7:33 ` Markus Elfring
2024-05-21 7:37 ` Greg Kroah-Hartman
2024-05-19 11:18 ` Markus Elfring
2024-05-17 12:58 ` [PATCH 02/13] regmap: add A2B support Alvin Šipraga
2024-05-17 14:42 ` Mark Brown
2024-05-21 6:27 ` Alvin Šipraga
2024-05-21 10:43 ` Mark Brown
2024-05-17 12:58 ` [PATCH 03/13] dt-bindings: a2b: Analog Devices AD24xx devices Alvin Šipraga
2024-05-19 11:40 ` Krzysztof Kozlowski
2024-05-19 11:44 ` Krzysztof Kozlowski
2024-05-21 7:24 ` Alvin Šipraga
2024-05-21 7:47 ` Krzysztof Kozlowski
2024-05-17 12:58 ` [PATCH 04/13] a2b: add AD24xx I2C interface driver Alvin Šipraga
2024-05-17 14:49 ` Wolfram Sang
2024-05-21 8:31 ` Alvin Šipraga
2024-05-18 12:56 ` kernel test robot
2024-05-18 15:02 ` kernel test robot
2024-05-17 12:58 ` [PATCH 05/13] a2b: add AD24xx node driver Alvin Šipraga
2024-05-17 12:58 ` [PATCH 06/13] gpio: add AD24xx GPIO driver Alvin Šipraga
2024-05-22 15:31 ` Bartosz Golaszewski
2024-05-28 12:13 ` Linus Walleij
2024-05-28 20:02 ` Andy Shevchenko
2024-05-17 12:58 ` [PATCH 07/13] ASoC: codecs: add AD24xx codec driver Alvin Šipraga
2024-05-17 15:03 ` Mark Brown
2024-05-21 6:46 ` Alvin Šipraga
2024-05-21 7:08 ` Alvin Šipraga
2024-05-21 10:49 ` Mark Brown
2024-05-17 13:02 ` [PATCH 08/13] clk: add AD24xx clock driver Alvin Šipraga
2024-06-04 0:10 ` Stephen Boyd [this message]
2024-05-17 13:02 ` [PATCH 09/13] i2c: add AD24xx I2C controller driver Alvin Šipraga
2024-05-17 13:02 ` [PATCH 10/13] dt-bindings: vendor-prefixes: add Bang & Olufsen a/s Alvin Šipraga
2024-05-19 11:40 ` Krzysztof Kozlowski
2024-05-17 13:02 ` [PATCH 11/13] dt-bindings: a2b: add compatible string for Beosound Shape node Alvin Šipraga
2024-05-19 11:41 ` Krzysztof Kozlowski
2024-05-21 7:12 ` Alvin Šipraga
2024-05-21 7:32 ` Krzysztof Kozlowski
2024-05-17 13:02 ` [PATCH 12/13] a2b: add Beosound Shape node driver Alvin Šipraga
2024-05-17 13:02 ` [PATCH 13/13] MAINTAINERS: add maintainership for A2B drivers Alvin Šipraga
2024-05-17 14:57 ` [PATCH 00/13] Analog Devices Inc. Automotive Audio Bus (A2B) support Wolfram Sang
2024-05-21 7:08 ` Alvin Šipraga
2024-05-19 6:44 ` Markus Elfring
[not found] <20240517-a2b-v1-0-7e776c784e02@bang-olufsen.dk>
2024-05-17 13:02 ` [PATCH 08/13] clk: add AD24xx clock driver Alvin Šipraga
2024-05-17 13:18 ` Alvin Šipraga
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=8e6fcde41671b0a1e8365214e6df4ec2.sboyd@kernel.org \
--to=sboyd@kernel.org \
--cc=alsi@bang-olufsen.dk \
--cc=alvin@pqrs.dk \
--cc=andi.shyti@kernel.org \
--cc=brgl@bgdev.pl \
--cc=broonie@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=emas@bang-olufsen.dk \
--cc=gregkh@linuxfoundation.org \
--cc=krzk+dt@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linus.walleij@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=linux-sound@vger.kernel.org \
--cc=mturquette@baylibre.com \
--cc=perex@perex.cz \
--cc=rafael@kernel.org \
--cc=robh@kernel.org \
--cc=saravanak@google.com \
--cc=tiwai@suse.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).