Unverified Commit 91ec7ad7 authored by Stephen Boyd's avatar Stephen Boyd
Browse files

Merge tag 'clk-round-rate-6.18' of https://github.com/masneyb/linux into clk-determine-rate

Pull clk_ops::round_rate conversion to clk_ops::determine_rate() from Brian Masney:

The round_rate() clk ops is deprecated in the clk framework in favor
of the determine_rate() clk ops, so let's go ahead and convert the
various clk drivers using the Coccinelle semantic patch posted below.
I did some minor cosmetic cleanups of the code in some cases.

Coccinelle semantic patch:

    virtual patch

    // Look up the current name of the round_rate function
    @ has_round_rate @
    identifier round_rate_name =~ ".*_round_rate";
    identifier hw_param, rate_param, parent_rate_param;
    @@

    long round_rate_name(struct clk_hw *hw_param, unsigned long rate_param,
                  unsigned long *parent_rate_param)
    {
        ...
    }

    // Rename the route_rate function name to determine_rate()
    @ script:python generate_name depends on has_round_rate @
    round_rate_name << has_round_rate.round_rate_name;
    new_name;
    @@

    coccinelle.new_name = round_rate_name.replace("_round_rate", "_determine_rate")

    // Change rate to req->rate; also change occurrences of 'return XXX'.
    @ chg_rate depends on generate_name @
    identifier has_round_rate.round_rate_name;
    identifier has_round_rate.hw_param;
    identifier has_round_rate.rate_param;
    identifier has_round_rate.parent_rate_param;
    identifier ERR =~ "E.*";
    expression E;
    @@

    long round_rate_name(struct clk_hw *hw_param, unsigned long rate_param,
                  unsigned long *parent_rate_param)
    {
    <...
    (
    -return -ERR;
    +return -ERR;
    |
    - return rate_param;
    + return 0;
    |
    - return E;
    + req->rate = E;
    +
    + return 0;
    |
    - rate_param
    + req->rate
    )
    ...>
    }

    // Coccinelle only transforms the first occurrence of the rate parameter
    // Run a second time. FIXME: Is there a better way to do this?
    @ chg_rate2 depends on generate_name @
    identifier has_round_rate.round_rate_name;
    identifier has_round_rate.hw_param;
    identifier has_round_rate.rate_param;
    identifier has_round_rate.parent_rate_param;
    @@

    long round_rate_name(struct clk_hw *hw_param, unsigned long rate_param,
                  unsigned long *parent_rate_param)
    {
    <...
    - rate_param
    + req->rate
    ...>
    }

    // Change parent_rate to req->best_parent_rate
    @ chg_parent_rate depends on generate_name @
    identifier has_round_rate.round_rate_name;
    identifier has_round_rate.hw_param;
    identifier has_round_rate.rate_param;
    identifier has_round_rate.parent_rate_param;
    @@

    long round_rate_name(struct clk_hw *hw_param, unsigned long rate_param,
                  unsigned long *parent_rate_param)
    {
    <...
    (
    - *parent_rate_param
    + req->best_parent_rate
    |
    - parent_rate_param
    + &req->best_parent_rate
    )
    ...>
    }

    // Convert the function definition from round_rate() to determine_rate()
    @ func_definition depends on chg_rate @
    identifier has_round_rate.round_rate_name;
    identifier has_round_rate.hw_param;
    identifier has_round_rate.rate_param;
    identifier has_round_rate.parent_rate_param;
    identifier generate_name.new_name;
    @@

    - long round_rate_name(struct clk_hw *hw_param, unsigned long rate_param,
    -               unsigned long *parent_rate_param)
    + int new_name(struct clk_hw *hw, struct clk_rate_request *req)
    {
        ...
    }

    // Update the ops from round_rate() to determine_rate()
    @ ops depends on func_definition @
    identifier has_round_rate.round_rate_name;
    identifier generate_name.new_name;
    @@

    {
        ...,
    -   .round_rate = round_rate_name,
    +   .determine_rate = new_name,
        ...,
    }

Note that I used coccinelle 1.2 instead of 1.3 since the newer version
adds unnecessary braces as described in this post.
https://lore.kernel.org/cocci/67642477-5f3e-4b2a-914d-579a54f48cbd@intel.com/

* tag 'clk-round-rate-6.18' of https://github.com/masneyb/linux: (118 commits)
  clk: scmi: migrate round_rate() to determine_rate()
  clk: ti: fapll: convert from round_rate() to determine_rate()
  clk: ti: dra7-atl: convert from round_rate() to determine_rate()
  clk: ti: divider: convert from round_rate() to determine_rate()
  clk: ti: composite: convert from round_rate() to determine_rate()
  clk: ti: dpll: convert from round_rate() to determine_rate()
  clk: ti: dpll: change error return from ~0 to -EINVAL
  clk: ti: dpll: remove round_rate() in favor of determine_rate()
  clk: tegra: tegra210-emc: convert from round_rate() to determine_rate()
  clk: tegra: super: convert from round_rate() to determine_rate()
  clk: tegra: pll: convert from round_rate() to determine_rate()
  clk: tegra: periph: divider: convert from round_rate() to determine_rate()
  clk: tegra: divider: convert from round_rate() to determine_rate()
  clk: tegra: audio-sync: convert from round_rate() to determine_rate()
  clk: fixed-factor: drop round_rate() clk ops
  clk: divider: remove round_rate() in favor of determine_rate()
  clk: visconti: pll: convert from round_rate() to determine_rate()
  clk: versatile: vexpress-osc: convert from round_rate() to determine_rate()
  clk: versatile: icst: convert from round_rate() to determine_rate()
  clk: versaclock7: convert from round_rate() to determine_rate()
  ...
parents 8f5ae30d 80cb2b6e
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -122,13 +122,13 @@ static int owl_comp_fact_set_rate(struct clk_hw *hw, unsigned long rate,
					rate, parent_rate);
}

static long owl_comp_fix_fact_round_rate(struct clk_hw *hw, unsigned long rate,
			unsigned long *parent_rate)
static int owl_comp_fix_fact_determine_rate(struct clk_hw *hw,
					    struct clk_rate_request *req)
{
	struct owl_composite *comp = hw_to_owl_comp(hw);
	struct clk_fixed_factor *fix_fact_hw = &comp->rate.fix_fact_hw;

	return comp->fix_fact_ops->round_rate(&fix_fact_hw->hw, rate, parent_rate);
	return comp->fix_fact_ops->determine_rate(&fix_fact_hw->hw, req);
}

static unsigned long owl_comp_fix_fact_recalc_rate(struct clk_hw *hw,
@@ -193,7 +193,7 @@ const struct clk_ops owl_comp_fix_fact_ops = {
	.is_enabled	= owl_comp_is_enabled,

	/* fix_fact_ops */
	.round_rate	= owl_comp_fix_fact_round_rate,
	.determine_rate = owl_comp_fix_fact_determine_rate,
	.recalc_rate	= owl_comp_fix_fact_recalc_rate,
	.set_rate	= owl_comp_fix_fact_set_rate,
};
+8 −5
Original line number Diff line number Diff line
@@ -23,13 +23,16 @@ long owl_divider_helper_round_rate(struct owl_clk_common *common,
				  div_hw->div_flags);
}

static long owl_divider_round_rate(struct clk_hw *hw, unsigned long rate,
				unsigned long *parent_rate)
static int owl_divider_determine_rate(struct clk_hw *hw,
				      struct clk_rate_request *req)
{
	struct owl_divider *div = hw_to_owl_divider(hw);

	return owl_divider_helper_round_rate(&div->common, &div->div_hw,
					     rate, parent_rate);
	req->rate = owl_divider_helper_round_rate(&div->common, &div->div_hw,
						  req->rate,
						  &req->best_parent_rate);

	return 0;
}

unsigned long owl_divider_helper_recalc_rate(struct owl_clk_common *common,
@@ -89,6 +92,6 @@ static int owl_divider_set_rate(struct clk_hw *hw, unsigned long rate,

const struct clk_ops owl_divider_ops = {
	.recalc_rate = owl_divider_recalc_rate,
	.round_rate = owl_divider_round_rate,
	.determine_rate = owl_divider_determine_rate,
	.set_rate = owl_divider_set_rate,
};
+7 −5
Original line number Diff line number Diff line
@@ -130,14 +130,16 @@ long owl_factor_helper_round_rate(struct owl_clk_common *common,
	return *parent_rate * mul / div;
}

static long owl_factor_round_rate(struct clk_hw *hw, unsigned long rate,
			unsigned long *parent_rate)
static int owl_factor_determine_rate(struct clk_hw *hw,
				     struct clk_rate_request *req)
{
	struct owl_factor *factor = hw_to_owl_factor(hw);
	struct owl_factor_hw *factor_hw = &factor->factor_hw;

	return owl_factor_helper_round_rate(&factor->common, factor_hw,
					rate, parent_rate);
	req->rate = owl_factor_helper_round_rate(&factor->common, factor_hw,
						 req->rate, &req->best_parent_rate);

	return 0;
}

unsigned long owl_factor_helper_recalc_rate(struct owl_clk_common *common,
@@ -214,7 +216,7 @@ static int owl_factor_set_rate(struct clk_hw *hw, unsigned long rate,
}

const struct clk_ops owl_factor_ops = {
	.round_rate	= owl_factor_round_rate,
	.determine_rate = owl_factor_determine_rate,
	.recalc_rate	= owl_factor_recalc_rate,
	.set_rate	= owl_factor_set_rate,
};
+16 −9
Original line number Diff line number Diff line
@@ -56,8 +56,8 @@ static const struct clk_pll_table *_get_pll_table(
	return table;
}

static long owl_pll_round_rate(struct clk_hw *hw, unsigned long rate,
		unsigned long *parent_rate)
static int owl_pll_determine_rate(struct clk_hw *hw,
				  struct clk_rate_request *req)
{
	struct owl_pll *pll = hw_to_owl_pll(hw);
	struct owl_pll_hw *pll_hw = &pll->pll_hw;
@@ -65,17 +65,24 @@ static long owl_pll_round_rate(struct clk_hw *hw, unsigned long rate,
	u32 mul;

	if (pll_hw->table) {
		clkt = _get_pll_table(pll_hw->table, rate);
		return clkt->rate;
		clkt = _get_pll_table(pll_hw->table, req->rate);
		req->rate = clkt->rate;

		return 0;
	}

	/* fixed frequency */
	if (pll_hw->width == 0)
		return pll_hw->bfreq;
	if (pll_hw->width == 0) {
		req->rate = pll_hw->bfreq;

	mul = owl_pll_calculate_mul(pll_hw, rate);
		return 0;
	}

	mul = owl_pll_calculate_mul(pll_hw, req->rate);

	return pll_hw->bfreq * mul;
	req->rate = pll_hw->bfreq * mul;

	return 0;
}

static unsigned long owl_pll_recalc_rate(struct clk_hw *hw,
@@ -188,7 +195,7 @@ const struct clk_ops owl_pll_ops = {
	.enable = owl_pll_enable,
	.disable = owl_pll_disable,
	.is_enabled = owl_pll_is_enabled,
	.round_rate = owl_pll_round_rate,
	.determine_rate = owl_pll_determine_rate,
	.recalc_rate = owl_pll_recalc_rate,
	.set_rate = owl_pll_set_rate,
};
+23 −19
Original line number Diff line number Diff line
@@ -270,8 +270,8 @@ static int clk_audio_pll_frac_determine_rate(struct clk_hw *hw,
	return 0;
}

static long clk_audio_pll_pad_round_rate(struct clk_hw *hw, unsigned long rate,
					 unsigned long *parent_rate)
static int clk_audio_pll_pad_determine_rate(struct clk_hw *hw,
					    struct clk_rate_request *req)
{
	struct clk_hw *pclk = clk_hw_get_parent(hw);
	long best_rate = -EINVAL;
@@ -283,7 +283,7 @@ static long clk_audio_pll_pad_round_rate(struct clk_hw *hw, unsigned long rate,
	int best_diff = -1;

	pr_debug("A PLL/PAD: %s, rate = %lu (parent_rate = %lu)\n", __func__,
		 rate, *parent_rate);
		 req->rate, req->best_parent_rate);

	/*
	 * Rate divisor is actually made of two different divisors, multiplied
@@ -304,12 +304,12 @@ static long clk_audio_pll_pad_round_rate(struct clk_hw *hw, unsigned long rate,
				continue;

			best_parent_rate = clk_hw_round_rate(pclk,
							rate * tmp_qd * div);
							req->rate * tmp_qd * div);
			tmp_rate = best_parent_rate / (div * tmp_qd);
			tmp_diff = abs(rate - tmp_rate);
			tmp_diff = abs(req->rate - tmp_rate);

			if (best_diff < 0 || best_diff > tmp_diff) {
				*parent_rate = best_parent_rate;
				req->best_parent_rate = best_parent_rate;
				best_rate = tmp_rate;
				best_diff = tmp_diff;
			}
@@ -318,11 +318,13 @@ static long clk_audio_pll_pad_round_rate(struct clk_hw *hw, unsigned long rate,
	pr_debug("A PLL/PAD: %s, best_rate = %ld, best_parent_rate = %lu\n",
		 __func__, best_rate, best_parent_rate);

	return best_rate;
	req->rate = best_rate;

	return 0;
}

static long clk_audio_pll_pmc_round_rate(struct clk_hw *hw, unsigned long rate,
					 unsigned long *parent_rate)
static int clk_audio_pll_pmc_determine_rate(struct clk_hw *hw,
					    struct clk_rate_request *req)
{
	struct clk_hw *pclk = clk_hw_get_parent(hw);
	long best_rate = -EINVAL;
@@ -333,20 +335,20 @@ static long clk_audio_pll_pmc_round_rate(struct clk_hw *hw, unsigned long rate,
	int best_diff = -1;

	pr_debug("A PLL/PMC: %s, rate = %lu (parent_rate = %lu)\n", __func__,
		 rate, *parent_rate);
		 req->rate, req->best_parent_rate);

	if (!rate)
	if (!req->rate)
		return 0;

	best_parent_rate = clk_round_rate(pclk->clk, 1);
	div = max(best_parent_rate / rate, 1UL);
	div = max(best_parent_rate / req->rate, 1UL);
	for (; div <= AUDIO_PLL_QDPMC_MAX; div++) {
		best_parent_rate = clk_round_rate(pclk->clk, rate * div);
		best_parent_rate = clk_round_rate(pclk->clk, req->rate * div);
		tmp_rate = best_parent_rate / div;
		tmp_diff = abs(rate - tmp_rate);
		tmp_diff = abs(req->rate - tmp_rate);

		if (best_diff < 0 || best_diff > tmp_diff) {
			*parent_rate = best_parent_rate;
			req->best_parent_rate = best_parent_rate;
			best_rate = tmp_rate;
			best_diff = tmp_diff;
			tmp_qd = div;
@@ -356,9 +358,11 @@ static long clk_audio_pll_pmc_round_rate(struct clk_hw *hw, unsigned long rate,
	}

	pr_debug("A PLL/PMC: %s, best_rate = %ld, best_parent_rate = %lu (qd = %d)\n",
		 __func__, best_rate, *parent_rate, tmp_qd - 1);
		 __func__, best_rate, req->best_parent_rate, tmp_qd - 1);

	return best_rate;
	req->rate = best_rate;

	return 0;
}

static int clk_audio_pll_frac_set_rate(struct clk_hw *hw, unsigned long rate,
@@ -436,7 +440,7 @@ static const struct clk_ops audio_pll_pad_ops = {
	.enable = clk_audio_pll_pad_enable,
	.disable = clk_audio_pll_pad_disable,
	.recalc_rate = clk_audio_pll_pad_recalc_rate,
	.round_rate = clk_audio_pll_pad_round_rate,
	.determine_rate = clk_audio_pll_pad_determine_rate,
	.set_rate = clk_audio_pll_pad_set_rate,
};

@@ -444,7 +448,7 @@ static const struct clk_ops audio_pll_pmc_ops = {
	.enable = clk_audio_pll_pmc_enable,
	.disable = clk_audio_pll_pmc_disable,
	.recalc_rate = clk_audio_pll_pmc_recalc_rate,
	.round_rate = clk_audio_pll_pmc_round_rate,
	.determine_rate = clk_audio_pll_pmc_determine_rate,
	.set_rate = clk_audio_pll_pmc_set_rate,
};

Loading