All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Boyd <sboyd@kernel.org>
To: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>,
	Dzmitry Sankouski <dsankouski@gmail.com>
Cc: dsankouski@gmail.com, Konrad Dybcio <konrad.dybcio@linaro.org>,
	Bjorn Andersson <andersson@kernel.org>,
	Michael Turquette <mturquette@baylibre.com>,
	linux-arm-msm@vger.kernel.org, linux-clk@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 02/23] gcc-sdm845: Add rates to the GP clocks
Date: Mon, 12 Aug 2024 11:08:14 -0700	[thread overview]
Message-ID: <8b2c1a23fd55c52e56cc875660d1fba9.sboyd@kernel.org> (raw)
In-Reply-To: <20240812151606.1996198-1-dsankouski@gmail.com>

Quoting Dzmitry Sankouski (2024-08-12 08:16:06)
> diff --git a/drivers/clk/qcom/clk-rcg2.c b/drivers/clk/qcom/clk-rcg2.c
> index 30b19bd39d08..44b257481556 100644
> --- a/drivers/clk/qcom/clk-rcg2.c
> +++ b/drivers/clk/qcom/clk-rcg2.c
> @@ -32,6 +32,7 @@
>  
>  #define CFG_REG                        0x4
>  #define CFG_SRC_DIV_SHIFT      0
> +#define CFG_SRC_DIV_LENGTH     8
>  #define CFG_SRC_SEL_SHIFT      8
>  #define CFG_SRC_SEL_MASK       (0x7 << CFG_SRC_SEL_SHIFT)
>  #define CFG_MODE_SHIFT         12
> @@ -393,16 +394,103 @@ static int clk_rcg2_fm_determine_rate(struct clk_hw *hw,
>         return _freq_tbl_fm_determine_rate(hw, rcg->freq_multi_tbl, req);
>  }
>  
> -static int __clk_rcg2_configure(struct clk_rcg2 *rcg, const struct freq_tbl *f,
> -                               u32 *_cfg)
> +static inline u64 find_hcf(u64 a, u64 b)
> +{
> +       while (a != 0 && b != 0) {
> +               if (a > b)
> +                       a %= b;
> +               else
> +                       b %= a;
> +       }
> +       return a + b;

Is this gcd()?

> +}
> +
> +static int clk_calc_mnd(u64 parent_rate, u64 rate, struct freq_tbl *f)
> +{
> +       u64 hcf;
> +       u64 hid_div = 1, n = 1;
> +       int i = 2, count = 0;
> +
> +       hcf = find_hcf(parent_rate, rate);
> +       u64 scaled_rate = rate / hcf;
> +       u64 scaled_parent_rate = parent_rate / hcf;
> +
> +       while (scaled_parent_rate > 1) {
> +               while (scaled_parent_rate % i == 0) {
> +                       scaled_parent_rate /= i;
> +                       if (count % 2 == 0)
> +                               hid_div *= i;
> +                       else
> +                               n *= i;
> +               }
> +               i++;
> +               count++;
> +       }
> +
> +       f->m = scaled_rate;
> +       f->n = n;
> +       f->pre_div = hid_div;
> +
> +       return 0;
> +}
> +
> +static int clk_rcg2_determine_gp_rate(struct clk_hw *hw,
> +                                  struct clk_rate_request *req)
> +{
> +       struct clk_rcg2 *rcg = to_clk_rcg2(hw);
> +       struct freq_tbl *f;
> +       int src = clk_rcg2_get_parent(hw);
> +       int mnd_max = BIT(rcg->mnd_width) - 1;
> +       int hid_max = BIT(rcg->hid_width) - 1;
> +       u64 parent_rate;
> +       int ret;
> +
> +       parent_rate = rcg->freq_tbl[src].freq;
> +       f = kcalloc(MAX_PERF_LEVEL + 1, sizeof(f), GFP_KERNEL);

When is this freed? Determine rate can be called many times. Is that
supposed to be sizeof(*f)? Why so many frequency entries?


> +
> +       if (!f)
> +               return 0;
> +
> +       ret = clk_calc_mnd(parent_rate, req->rate, f);
> +       if (ret)
> +               return 0;
> +
> +
> +       while (f->n - f->m >= mnd_max) {
> +               f->m = f->m >> 1;
> +               f->n = f->n >> 1;
> +       }
> +       while (f->pre_div >= hid_max) {
> +               f->pre_div = f->pre_div >> 1;
> +               f->m = f->m >> 1;
> +       }
> +
> +       req->rate = calc_rate(parent_rate, f->m, f->n, f->n, f->pre_div);
> +
> +       return 0;
> +}
> +
> +static int __clk_rcg2_configure_parent(struct clk_rcg2 *rcg, int src, u32 *_cfg)

u8 src? Good to keep types consistent.

>  {
> -       u32 cfg, mask, d_val, not2d_val, n_minus_m;
>         struct clk_hw *hw = &rcg->clkr.hw;
> -       int ret, index = qcom_find_src_index(hw, rcg->parent_map, f->src);
> +       u32 mask = CFG_SRC_SEL_MASK;
> +       int index = qcom_find_src_index(hw, rcg->parent_map, src);
>  
>         if (index < 0)
>                 return index;
>  
> +       *_cfg &= ~mask;
> +       *_cfg |= rcg->parent_map[index].cfg << CFG_SRC_SEL_SHIFT;
> +
> +       return 0;
> +}
> +
> +static int __clk_rcg2_configure_mnd(struct clk_rcg2 *rcg, const struct freq_tbl *f,
> +                               u32 *_cfg)
> +{
> +       u32 cfg, mask, d_val, not2d_val, n_minus_m;
> +       int ret;
> +
>         if (rcg->mnd_width && f->n) {
>                 mask = BIT(rcg->mnd_width) - 1;
>                 ret = regmap_update_bits(rcg->clkr.regmap,
> @@ -431,9 +519,8 @@ static int __clk_rcg2_configure(struct clk_rcg2 *rcg, const struct freq_tbl *f,
>         }
>  
>         mask = BIT(rcg->hid_width) - 1;
> -       mask |= CFG_SRC_SEL_MASK | CFG_MODE_MASK | CFG_HW_CLK_CTRL_MASK;
> +       mask |= CFG_MODE_MASK | CFG_HW_CLK_CTRL_MASK;
>         cfg = f->pre_div << CFG_SRC_DIV_SHIFT;
> -       cfg |= rcg->parent_map[index].cfg << CFG_SRC_SEL_SHIFT;
>         if (rcg->mnd_width && f->n && (f->m != f->n))
>                 cfg |= CFG_MODE_DUAL_EDGE;
>         if (rcg->hw_clk_ctrl)
> @@ -445,6 +532,22 @@ static int __clk_rcg2_configure(struct clk_rcg2 *rcg, const struct freq_tbl *f,
>         return 0;
>  }
>  
> +static int __clk_rcg2_configure(struct clk_rcg2 *rcg, const struct freq_tbl *f,
> +                               u32 *_cfg)
> +{
> +       int ret;
> +
> +       ret = __clk_rcg2_configure_parent(rcg, f->src, _cfg);
> +       if (ret)
> +               return ret;
> +
> +       ret = __clk_rcg2_configure_mnd(rcg, f, _cfg);
> +       if (ret)
> +               return ret;
> +
> +       return 0;
> +}
> +
>  static int clk_rcg2_configure(struct clk_rcg2 *rcg, const struct freq_tbl *f)
>  {
>         u32 cfg;
> @@ -465,6 +568,26 @@ static int clk_rcg2_configure(struct clk_rcg2 *rcg, const struct freq_tbl *f)
>         return update_config(rcg);
>  }
>  
> +static int clk_rcg2_configure_gp(struct clk_rcg2 *rcg, const struct freq_tbl *f)
> +{
> +       u32 cfg;
> +       int ret;
> +
> +       ret = regmap_read(rcg->clkr.regmap, RCG_CFG_OFFSET(rcg), &cfg);
> +       if (ret)
> +               return ret;
> +
> +       ret = __clk_rcg2_configure_mnd(rcg, f, &cfg);
> +       if (ret)
> +               return ret;
> +
> +       ret = regmap_write(rcg->clkr.regmap, RCG_CFG_OFFSET(rcg), cfg);
> +       if (ret)
> +               return ret;
> +
> +       return update_config(rcg);
> +}
> +
>  static int __clk_rcg2_set_rate(struct clk_hw *hw, unsigned long rate,
>                                enum freq_policy policy)
>  {
> @@ -518,6 +641,22 @@ static int clk_rcg2_set_rate(struct clk_hw *hw, unsigned long rate,
>         return __clk_rcg2_set_rate(hw, rate, CEIL);
>  }
>  
> +static int clk_rcg2_set_gp_rate(struct clk_hw *hw, unsigned long rate,
> +                           unsigned long parent_rate)
> +{
> +       struct clk_rcg2 *rcg = to_clk_rcg2(hw);
> +       struct freq_tbl *f;
> +
> +       f = kcalloc(MAX_PERF_LEVEL + 1, sizeof(*f), GFP_KERNEL);

When is this freed?

> +
> +       if (!f)
> +               return -ENOMEM;
> +
> +       clk_calc_mnd(parent_rate, rate, f);
> +
> +       return clk_rcg2_configure_gp(rcg, f);
> +}
> +
>  static int clk_rcg2_set_floor_rate(struct clk_hw *hw, unsigned long rate,
>                                    unsigned long parent_rate)
>  {
> @@ -645,6 +784,17 @@ const struct clk_ops clk_rcg2_ops = {
>  };
>  EXPORT_SYMBOL_GPL(clk_rcg2_ops);
>  
> +const struct clk_ops clk_rcg2_gp_ops = {
> +       .is_enabled = clk_rcg2_is_enabled,
> +       .get_parent = clk_rcg2_get_parent,
> +       .set_parent = clk_rcg2_set_parent,
> +       .determine_rate = clk_rcg2_determine_gp_rate,
> +       .set_rate = clk_rcg2_set_gp_rate,
> +       .get_duty_cycle = clk_rcg2_get_duty_cycle,
> +       .set_duty_cycle = clk_rcg2_set_duty_cycle,
> +};
> +EXPORT_SYMBOL_GPL(clk_rcg2_gp_ops);
> +
>  const struct clk_ops clk_rcg2_floor_ops = {
>         .is_enabled = clk_rcg2_is_enabled,
>         .get_parent = clk_rcg2_get_parent,
> diff --git a/drivers/pwm/pwm-clk.c b/drivers/pwm/pwm-clk.c
> index c19a482d7e28..1bfc7870e3aa 100644
> --- a/drivers/pwm/pwm-clk.c
> +++ b/drivers/pwm/pwm-clk.c
> @@ -25,6 +25,7 @@
>  #include <linux/of.h>
>  #include <linux/platform_device.h>
>  #include <linux/clk.h>
> +#include <linux/clk/clk-conf.h>
>  #include <linux/pwm.h>
>  
>  struct pwm_clk_chip {
> @@ -87,6 +88,10 @@ static int pwm_clk_probe(struct platform_device *pdev)
>         struct pwm_clk_chip *pcchip;
>         int ret;
>  
> +       ret = of_clk_set_defaults(pdev->dev.of_node, false);
> +       if (ret < 0)
> +               return -EINVAL;
> +

What is this? Debug code?

>         chip = devm_pwmchip_alloc(&pdev->dev, 1, sizeof(*pcchip));
>         if (IS_ERR(chip))
>                 return PTR_ERR(chip);
> -- 
> 2.39.2
> 
>

  reply	other threads:[~2024-08-12 18:08 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-18 13:59 [PATCH v3 00/23] This is continued work on Samsung S9(SM-9600) starqltechn Dzmitry Sankouski
2024-06-18 13:59 ` [PATCH v3 01/23] power: supply: add undervoltage health status property Dzmitry Sankouski
2024-06-18 13:59 ` [PATCH v3 02/23] gcc-sdm845: Add rates to the GP clocks Dzmitry Sankouski
2024-06-18 17:50   ` Dmitry Baryshkov
2024-06-18 18:50     ` Konrad Dybcio
2024-06-18 18:55       ` Dmitry Baryshkov
2024-06-18 19:11         ` Konrad Dybcio
2024-06-19  6:31           ` Dmitry Baryshkov
2024-08-12 15:16             ` Dzmitry Sankouski
2024-08-12 18:08               ` Stephen Boyd [this message]
2024-07-19  9:01           ` Dzmitry Sankouski
2024-06-18 13:59 ` [PATCH v3 03/23] dt-bindings: panel: add Samsung s6e3ha8 Dzmitry Sankouski
2024-06-20 15:44   ` Krzysztof Kozlowski
2024-06-18 13:59 ` [PATCH v3 04/23] dt-bindings: mfd: add maxim,max77705 Dzmitry Sankouski
2024-06-18 16:53   ` Rob Herring (Arm)
2024-06-20 15:45   ` Krzysztof Kozlowski
2024-09-13 14:51     ` Dzmitry Sankouski
2024-09-13 16:47       ` Conor Dooley
2024-06-18 13:59 ` [PATCH v3 05/23] dt-bindings: input: add maxim,max77705-haptic Dzmitry Sankouski
2024-06-20 15:47   ` Krzysztof Kozlowski
2024-06-18 13:59 ` [PATCH v3 06/23] dt-bindings: power: supply: add maxim,max77705 charger Dzmitry Sankouski
2024-06-20 15:47   ` Krzysztof Kozlowski
2024-06-18 13:59 ` [PATCH v3 07/23] dt-bindings: power: supply: add maxim,max77705 Dzmitry Sankouski
2024-06-18 16:53   ` Rob Herring (Arm)
2024-06-20 16:14   ` Krzysztof Kozlowski
2024-06-18 13:59 ` [PATCH v3 08/23] dt-bindings: led: add maxim,max77705-leds Dzmitry Sankouski
2024-06-18 13:59 ` [PATCH v3 09/23] dt-bindings: mfd: add samsung,s2dos05 Dzmitry Sankouski
2024-06-18 16:53   ` Rob Herring (Arm)
2024-06-20 15:49   ` Krzysztof Kozlowski
2024-06-18 13:59 ` [PATCH v3 10/23] dt-bindings: regulator: " Dzmitry Sankouski
2024-06-20 15:51   ` Krzysztof Kozlowski
2024-06-18 13:59 ` [PATCH v3 11/23] drm/panel: Add support for S6E3HA8 panel driver Dzmitry Sankouski
2024-06-18 18:39   ` Dmitry Baryshkov
2024-06-19 13:27     ` Dzmitry Sankouski
2024-06-20 20:13       ` Dmitry Baryshkov
2024-06-18 13:59 ` [PATCH v3 12/23] mfd: Add new driver for MAX77705 PMIC Dzmitry Sankouski
2024-06-20 16:02   ` Krzysztof Kozlowski
2024-06-21 16:16   ` kernel test robot
2024-06-21 23:51   ` kernel test robot
2024-06-18 13:59 ` [PATCH v3 13/23] input: add max77705 haptic driver Dzmitry Sankouski
2024-06-20 16:04   ` Krzysztof Kozlowski
2024-06-18 13:59 ` [PATCH v3 14/23] power: supply: max77705: Add charger driver for Maxim 77705 Dzmitry Sankouski
2024-06-20 16:06   ` Krzysztof Kozlowski
2024-06-18 13:59 ` [PATCH v3 15/23] power: supply: max77705: Add fuel gauge " Dzmitry Sankouski
2024-06-18 13:59 ` [PATCH v3 16/23] leds: max77705: Add LEDs support Dzmitry Sankouski
2024-06-20 20:14   ` Krzysztof Kozlowski
2024-06-18 13:59 ` [PATCH v3 17/23] mfd: add s2dos series core driver Dzmitry Sankouski
2024-06-20 16:07   ` Krzysztof Kozlowski
2024-06-21 20:33   ` kernel test robot
2024-06-18 13:59 ` [PATCH v3 18/23] regulator: add s2dos05 regulator support Dzmitry Sankouski
2024-06-18 14:08   ` Mark Brown
2024-06-19 15:49     ` Dzmitry Sankouski
2024-06-19 15:52       ` Mark Brown
2024-06-19 13:26   ` kernel test robot
2024-06-20 16:08   ` Krzysztof Kozlowski
2024-06-18 13:59 ` [PATCH v3 19/23] power: supply: s2dos05: Add fuel gauge driver for s2dos05 Dzmitry Sankouski
2024-06-20 16:11   ` Krzysztof Kozlowski
2024-06-18 13:59 ` [PATCH v3 20/23] arm64: dts: qcom: starqltechn: remove wifi Dzmitry Sankouski
2024-06-18 14:06   ` Konrad Dybcio
2024-06-18 13:59 ` [PATCH v3 21/23] arm64: dts: qcom: starqltechn: remove framebuffer Dzmitry Sankouski
2024-06-18 14:06   ` Konrad Dybcio
2024-06-18 13:59 ` [PATCH v3 22/23] arm64: dts: qcom: starqltechn: fix usb regulator mistake Dzmitry Sankouski
2024-06-18 14:07   ` Konrad Dybcio
2024-06-18 14:16     ` Dzmitry Sankouski
2024-06-18 13:59 ` [PATCH v3 23/23] arm64: dts: qcom: starqltechn: add new features Dzmitry Sankouski
2024-06-18 14:12   ` Konrad Dybcio
2024-07-08 15:54     ` Dzmitry Sankouski
2024-07-08 18:08       ` Konrad Dybcio

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=8b2c1a23fd55c52e56cc875660d1fba9.sboyd@kernel.org \
    --to=sboyd@kernel.org \
    --cc=andersson@kernel.org \
    --cc=dmitry.baryshkov@linaro.org \
    --cc=dsankouski@gmail.com \
    --cc=konrad.dybcio@linaro.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mturquette@baylibre.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.