mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andi Shyti <andi.shyti@kernel.org>
To: John Crispin <john@phrozen.org>
Cc: Stefan Roese <sr@denx.de>, Rob Herring <robh@kernel.org>,
	 Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	 Matthias Brugger <matthias.bgg@gmail.com>,
	 AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>,
	Philipp Zabel <p.zabel@pengutronix.de>,
	 Christian Marangi <ansuelsmth@gmail.com>,
	devicetree@vger.kernel.org, lei.dong@airoha.com,
	 Linqi.zhang@airoha.com, linux-arm-kernel@lists.infradead.org,
	linux-i2c@vger.kernel.org,  linux-kernel@vger.kernel.org,
	linux-mediatek@lists.infradead.org, Rajeev.kumar@airoha.com,
	 upstream@airoha.com, Weifeng.xu@airoha.com,
	zhengping.zhang@airoha.com
Subject: Re: [PATCH v3 3/3] i2c: mt7621: add support for Airoha AN7589
Date: Tue, 1 Dec 2026 15:04:36 +0100	[thread overview]
Message-ID: <aw7RHNwER6VvW7Is@zenone.zhora.eu> (raw)
In-Reply-To: <20261116175343.344425-4-john@phrozen.org>

Hi John,

>  static void mtk_i2c_init(struct mtk_i2c *i2c)
>  {
> -	i2c->clk_div = clk_get_rate(i2c->clk) / i2c->bus_freq - 1;
> -	if (i2c->clk_div < 99)
> -		i2c->clk_div = 99;
> -	if (i2c->clk_div > SM0CTL0_CLK_DIV_MAX)
> -		i2c->clk_div = SM0CTL0_CLK_DIV_MAX;
> +	unsigned long rate = clk_get_rate(i2c->clk);

Please do not do important assignments during declaration. I
would defensively check for !rate, it's a possibility and we
should check for it.

> +	u32 bus_freq = i2c->bus_freq;
> +
> +	if (i2c->soc->ext_clk_div) {
> +		bus_freq = min(bus_freq, I2C_MAX_FAST_MODE_PLUS_FREQ);
> +		i2c->clk_div = min(rate / bus_freq - 1,
> +				   FIELD_MAX(SM0CTL2_CLK_DIV_EXT));

DIV_ROUND_UP_ULL()?

Andi

> +	} else {
> +		i2c->clk_div = clamp(rate / bus_freq - 1, 99,
> +				     SM0CTL0_CLK_DIV_MAX);
> +	}

      reply	other threads:[~2026-12-01 14:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 17:53 [PATCH v3 0/3] i2c: mt7621: add Airoha AN7589 support John Crispin
2026-11-16 17:53 ` [PATCH v3 1/3] i2c: mt7621: assert and deassert the reset line John Crispin
2026-11-16 17:53 ` [PATCH v3 2/3] dt-bindings: i2c: mt7621: add Airoha AN7589 John Crispin
2026-11-16 17:53 ` [PATCH v3 3/3] i2c: mt7621: add support for " John Crispin
2026-12-01 14:04   ` Andi Shyti [this message]

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=aw7RHNwER6VvW7Is@zenone.zhora.eu \
    --to=andi.shyti@kernel.org \
    --cc=Linqi.zhang@airoha.com \
    --cc=Rajeev.kumar@airoha.com \
    --cc=Weifeng.xu@airoha.com \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=ansuelsmth@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=john@phrozen.org \
    --cc=krzk+dt@kernel.org \
    --cc=lei.dong@airoha.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=matthias.bgg@gmail.com \
    --cc=p.zabel@pengutronix.de \
    --cc=robh@kernel.org \
    --cc=sr@denx.de \
    --cc=upstream@airoha.com \
    --cc=zhengping.zhang@airoha.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

all inboxes | Powered by JetHome®