public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Nikita Shubin <nikita.shubin@maquefel.me>
Cc: Michael Turquette <mturquette@baylibre.com>,
	Stephen Boyd <sboyd@kernel.org>,
	linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org,
	Arnd Bergmann <arnd@arndb.de>
Subject: Re: [PATCH v6 04/40] clk: ep93xx: add DT support for Cirrus EP93xx
Date: Wed, 13 Dec 2023 19:42:14 +0200	[thread overview]
Message-ID: <ZXns9klLAhuK-Alz@smile.fi.intel.com> (raw)
In-Reply-To: <20231212-ep93xx-v6-4-c307b8ac9aa8@maquefel.me>

On Tue, Dec 12, 2023 at 11:20:21AM +0300, Nikita Shubin wrote:
> Rewrite EP93xx clock driver located in arch/arm/mach-ep93xx/clock.c
> trying to do everything the device tree way:
> 
> - provide clock acces via of
> - drop clk_hw_register_clkdev
> - drop init code and use module_auxiliary_driver

...

> +#define EP93XX_I2SCLKDIV_SDIV		(1 << 16)

BIT() ?

...

> +static u8 ep93xx_mux_get_parent(struct clk_hw *hw)
> +{
> +	struct ep93xx_clk *clk = ep93xx_clk_from(hw);
> +	struct ep93xx_clk_priv *priv = ep93xx_priv_from(clk);
> +	u32 val;
> +
> +	regmap_read(priv->map, clk->reg, &val);
> +
> +	val &= EP93XX_SYSCON_CLKDIV_MASK;
> +
> +	switch (val) {
> +	case EP93XX_SYSCON_CLKDIV_ESEL:
> +		return 1; /* PLL1 */
> +	case EP93XX_SYSCON_CLKDIV_MASK:
> +		return 2; /* PLL2 */

> +	default:
> +		break;
> +	};
> +
> +	return 0; /* XTALI */

You may return directly from default.

> +}

...

> +static int ep93xx_mux_set_parent_lock(struct clk_hw *hw, u8 index)
> +{
> +	struct ep93xx_clk *clk = ep93xx_clk_from(hw);
> +	struct ep93xx_clk_priv *priv = ep93xx_priv_from(clk);
> +	unsigned long flags;
> +	u32 val;
> +
> +	if (index >= 3)
> +		return -EINVAL;

> +	spin_lock_irqsave(&priv->lock, flags);

Why not guard() ?

> +	regmap_read(priv->map, clk->reg, &val);
> +	val &= ~(EP93XX_SYSCON_CLKDIV_MASK);
> +	val |= index > 0 ? EP93XX_SYSCON_CLKDIV_ESEL : 0;
> +	val |= index > 1 ? EP93XX_SYSCON_CLKDIV_PSEL : 0;
> +
> +	ep93xx_clk_write(priv, clk->reg, val);
> +
> +	spin_unlock_irqrestore(&priv->lock, flags);
> +
> +	return 0;
> +}

...

> +static bool is_best(unsigned long rate, unsigned long now,
> +		     unsigned long best)
> +{
> +	return abs_diff(rate, now) < abs_diff(rate, best);

Have you included necessary header for this?

> +}

...

> +static int ep93xx_mux_determine_rate(struct clk_hw *hw,
> +				struct clk_rate_request *req)
> +{
> +	unsigned long best_rate = 0, actual_rate, mclk_rate;
> +	unsigned long rate = req->rate;

> +	struct clk_hw *parent_best = NULL;

Strictly speaking you don't need an assignment here as you can compare the loop
variable value against the maximum. But I don't know how heave the respective
CLk call is and if it has no side-effects due to operations inside the loop body.

> +	unsigned long parent_rate_best;
> +	unsigned long parent_rate;
> +	int div, pdiv;
> +	unsigned int i;
> +
> +	/*
> +	 * Try the two pll's and the external clock

Either comma + 'b' or missing period.

> +	 * Because the valid predividers are 2, 2.5 and 3, we multiply
> +	 * all the clocks by 2 to avoid floating point math.
> +	 *
> +	 * This is based on the algorithm in the ep93xx raster guide:
> +	 * http://be-a-maverick.com/en/pubs/appNote/AN269REV1.pdf
> +	 *
> +	 */
> +	for (i = 0; i < clk_hw_get_num_parents(hw); i++) {
> +		struct clk_hw *parent = clk_hw_get_parent_by_index(hw, i);
> +
> +		parent_rate = clk_hw_get_rate(parent);
> +		mclk_rate = parent_rate * 2;
> +
> +		/* Try each predivider value */
> +		for (pdiv = 4; pdiv <= 6; pdiv++) {
> +			div = DIV_ROUND_CLOSEST(mclk_rate, rate * pdiv);

> +			if (!in_range(div, 1, 127))

Same header as for abs_diff()?

> +				continue;
> +
> +			actual_rate = DIV_ROUND_CLOSEST(mclk_rate, pdiv * div);
> +			if (is_best(rate, actual_rate, best_rate)) {
> +				best_rate = actual_rate;
> +				parent_rate_best = parent_rate;
> +				parent_best = parent;
> +			}
> +		}

(1)

> +	}
> +
> +	if (!parent_best)
> +		return -EINVAL;
> +
> +	req->best_parent_rate = parent_rate_best;
> +	req->best_parent_hw = parent_best;
> +	req->rate = best_rate;
> +
> +	return 0;
> +}

...

> +	mclk_rate = parent_rate * 2;
> +
> +	for (pdiv = 4; pdiv <= 6; pdiv++) {
> +		div = DIV_ROUND_CLOSEST(mclk_rate, rate * pdiv);
> +		if (!in_range(div, 1, 127))
> +			continue;
> +
> +		actual_rate = DIV_ROUND_CLOSEST(mclk_rate, pdiv * div);
> +		if (abs(actual_rate - rate) < rate_err) {
> +			npdiv = pdiv - 3;
> +			ndiv = div;
> +			rate_err = abs(actual_rate - rate);
> +		}
> +	}

Looks very similar to (1). Can be deduplicated?

...

> +	/*
> +	 * Clear old dividers
> +	 * Bit 7 is reserved bit in all ClkDiv registers

Missing periods.

> +	 */

...

> +static unsigned long calc_pll_rate(u64 rate, u32 config_word)
> +{
> +	rate *= ((config_word >> 11) & GENMASK(4, 0)) + 1;	/* X1FBD */
> +	rate *= ((config_word >> 5) & GENMASK(5, 0)) + 1;	/* X2FBD */
> +	do_div(rate, (config_word & GENMASK(4, 0)) + 1);	/* X2IPD */

> +	rate >>= ((config_word >> 16) & GENMASK(1, 0));		/* PS */

Outer parentheses are redundant.

> +	return rate;
> +}

...

> +	/*
> +	 * EP93xx SSP clock rate was doubled in version E2. For more information
> +	 * see:
> +	 *     http://www.cirrus.com/en/pubs/appNote/AN273REV4.pdf

Can you point to the specific section? Like

	 * see section 1.2.3 "Foo bar":

> +	 */

...

> +	/* touchscreen/adc clock */

ADC

...

> +	/*
> +	 * On reset PDIV and VDIV is set to zero, while PDIV zero
> +	 * means clock disable, VDIV shouldn't be zero.
> +	 * So we set both video and is2 dividers to minimum.

i2s?

> +	 * ENA - Enable CLK divider.
> +	 * PDIV - 00 - Disable clock
> +	 * VDIV - at least 2
> +	 */

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2023-12-13 17:42 UTC|newest]

Thread overview: 77+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-12  8:20 [PATCH v6 00/40] ep93xx device tree conversion Nikita Shubin via B4 Relay
2023-12-12  8:20 ` [PATCH v6 01/40] ARM: ep93xx: Add terminator to gpiod_lookup_table Nikita Shubin via B4 Relay
2023-12-13 17:24   ` Andy Shevchenko
2023-12-12  8:20 ` [PATCH v6 02/40] gpio: ep93xx: split device in multiple Nikita Shubin via B4 Relay
2023-12-12  8:20 ` [PATCH v6 03/40] ARM: ep93xx: add regmap aux_dev Nikita Shubin via B4 Relay
2023-12-13 17:28   ` Andy Shevchenko
2023-12-12  8:20 ` [PATCH v6 04/40] clk: ep93xx: add DT support for Cirrus EP93xx Nikita Shubin via B4 Relay
2023-12-13 17:42   ` Andy Shevchenko [this message]
2023-12-23  8:35     ` Nikita Shubin
2023-12-12  8:20 ` [PATCH v6 05/40] pinctrl: add a Cirrus ep93xx SoC pin controller Nikita Shubin via B4 Relay
2023-12-13 17:51   ` Andy Shevchenko
2023-12-23  8:55     ` Nikita Shubin
2023-12-12  8:20 ` [PATCH v6 06/40] power: reset: Add a driver for the ep93xx reset Nikita Shubin via B4 Relay
2023-12-13 17:54   ` Andy Shevchenko
2023-12-12  8:20 ` [PATCH v6 07/40] dt-bindings: soc: Add Cirrus EP93xx Nikita Shubin via B4 Relay
2023-12-13  6:53   ` Krzysztof Kozlowski
2023-12-12  8:20 ` [PATCH v6 08/40] soc: Add SoC driver for Cirrus ep93xx Nikita Shubin via B4 Relay
2023-12-13 18:37   ` Andy Shevchenko
2023-12-23 10:06     ` Nikita Shubin
2023-12-23 11:32       ` Arnd Bergmann
2023-12-12  8:20 ` [PATCH v6 09/40] dt-bindings: dma: Add Cirrus EP93xx Nikita Shubin via B4 Relay
2023-12-12  8:20 ` [PATCH v6 10/40] dma: cirrus: Convert to DT for " Nikita Shubin via B4 Relay
2023-12-13 18:28   ` Andy Shevchenko
2023-12-12  8:20 ` [PATCH v6 11/40] dt-bindings: watchdog: Add Cirrus EP93x Nikita Shubin via B4 Relay
2023-12-12  8:20 ` [PATCH v6 12/40] watchdog: ep93xx: add DT support for Cirrus EP93xx Nikita Shubin via B4 Relay
2023-12-13 17:56   ` Andy Shevchenko
2023-12-12  8:20 ` [PATCH v6 13/40] dt-bindings: pwm: Add " Nikita Shubin via B4 Relay
2023-12-12  8:20 ` [PATCH v6 14/40] pwm: ep93xx: add DT support for " Nikita Shubin via B4 Relay
2023-12-13 17:56   ` Andy Shevchenko
2023-12-12  8:20 ` [PATCH v6 15/40] dt-bindings: spi: Add " Nikita Shubin via B4 Relay
2023-12-12  8:20 ` [PATCH v6 16/40] spi: ep93xx: add DT support for " Nikita Shubin via B4 Relay
2023-12-13 18:13   ` Andy Shevchenko
2023-12-12  8:20 ` [PATCH v6 17/40] dt-bindings: net: Add " Nikita Shubin via B4 Relay
2023-12-12  8:20 ` [PATCH v6 18/40] net: cirrus: add DT support for " Nikita Shubin via B4 Relay
2023-12-13 18:39   ` Andy Shevchenko
2023-12-12  8:20 ` [PATCH v6 19/40] dt-bindings: mtd: Add ts7200 nand-controller Nikita Shubin via B4 Relay
2023-12-12  8:20 ` [PATCH v6 20/40] mtd: rawnand: add support for ts72xx Nikita Shubin via B4 Relay
2023-12-12  8:30   ` Greg Kroah-Hartman
2023-12-12  8:35     ` Nikita Shubin
2023-12-12 14:05       ` Miquel Raynal
2023-12-15 10:16   ` Miquel Raynal
2023-12-15 12:11     ` Nikita Shubin
2023-12-15 12:27       ` Miquel Raynal
2023-12-12  8:20 ` [PATCH v6 21/40] dt-bindings: ata: Add Cirrus EP93xx Nikita Shubin via B4 Relay
2023-12-12  8:20 ` [PATCH v6 22/40] ata: pata_ep93xx: add device tree support Nikita Shubin via B4 Relay
2023-12-13 18:19   ` Andy Shevchenko
2023-12-12  8:20 ` [PATCH v6 23/40] dt-bindings: input: Add Cirrus EP93xx keypad Nikita Shubin via B4 Relay
2023-12-12  8:20 ` [PATCH v6 24/40] input: keypad: ep93xx: add DT support for Cirrus EP93xx Nikita Shubin via B4 Relay
2023-12-13 18:41   ` Andy Shevchenko
2023-12-12  8:20 ` [PATCH v6 25/40] dt-bindings: wdt: Add ts72xx Nikita Shubin via B4 Relay
2023-12-12 15:03   ` Guenter Roeck
2023-12-12  8:20 ` [PATCH v6 26/40] wdt: ts72xx: add DT support for ts72xx Nikita Shubin via B4 Relay
2023-12-13 18:10   ` Andy Shevchenko
2023-12-12  8:20 ` [PATCH v6 27/40] gpio: ep93xx: add DT support for gpio-ep93xx Nikita Shubin via B4 Relay
2023-12-12  8:20 ` [PATCH v6 28/40] ASoC: dt-bindings: ep93xx: Document DMA support Nikita Shubin via B4 Relay
2023-12-12  8:20 ` [PATCH v6 29/40] ASoC: dt-bindings: ep93xx: Document Audio Port support Nikita Shubin via B4 Relay
2023-12-12  8:20 ` [PATCH v6 30/40] ASoC: ep93xx: Drop legacy DMA support Nikita Shubin via B4 Relay
2023-12-12  8:20 ` [PATCH v6 31/40] ARM: dts: add Cirrus EP93XX SoC .dtsi Nikita Shubin via B4 Relay
2023-12-12  8:20 ` [PATCH v6 32/40] ARM: dts: ep93xx: add ts7250 board Nikita Shubin via B4 Relay
2023-12-12  8:20 ` [PATCH v6 33/40] ARM: dts: ep93xx: Add EDB9302 DT Nikita Shubin via B4 Relay
2023-12-12  8:20 ` [PATCH v6 34/40] ARM: ep93xx: DT for the Cirrus ep93xx SoC platforms Nikita Shubin via B4 Relay
2023-12-12  8:20 ` [PATCH v6 35/40] pwm: ep93xx: drop legacy pinctrl Nikita Shubin via B4 Relay
2023-12-12  8:20 ` [PATCH v6 36/40] ata: pata_ep93xx: remove legacy pinctrl use Nikita Shubin via B4 Relay
2023-12-13 18:16   ` Andy Shevchenko
2023-12-13 18:33     ` Uwe Kleine-König
2023-12-13 18:48       ` Andy Shevchenko
2023-12-14 10:26         ` Uwe Kleine-König
2023-12-12  8:20 ` [PATCH v6 37/40] ARM: ep93xx: delete all boardfiles Nikita Shubin via B4 Relay
2023-12-12  8:20 ` [PATCH v6 38/40] ARM: ep93xx: soc: drop defines Nikita Shubin via B4 Relay
2023-12-12  8:20 ` [PATCH v6 39/40] ASoC: cirrus: edb93xx: Delete driver Nikita Shubin via B4 Relay
2023-12-12  8:20 ` [PATCH v6 40/40] dma: cirrus: remove platform code Nikita Shubin via B4 Relay
2023-12-13 18:30   ` Andy Shevchenko
2023-12-23  9:49     ` Nikita Shubin
2023-12-12 11:53 ` [PATCH v6 00/40] ep93xx device tree conversion Uwe Kleine-König
2023-12-13 17:59 ` Andy Shevchenko
2023-12-23  9:12   ` Nikita Shubin
2023-12-25 19:55     ` Andy Shevchenko

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=ZXns9klLAhuK-Alz@smile.fi.intel.com \
    --to=andriy.shevchenko@intel.com \
    --cc=arnd@arndb.de \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=nikita.shubin@maquefel.me \
    --cc=sboyd@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