Linux-i3c Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Manikandan Muralidharan" <manikandan.m@microchip.com>,
	linux-i3c@lists.infradead.org
Cc: Frank.Li@kernel.org, "Alexandre Belloni" <alexandre.belloni@bootlin.com>
Subject: Re: [PATCH 2/3] i3c: mipi-i3c-hci: add Microchip quirk to derive SCL timings from gclk
Date: Fri, 04 Dec 2026 08:57:42 +0000	[thread overview]
Message-ID: <sashiko-outbox-249447@kernel.org> (raw)
In-Reply-To: <20261204083449.933526-3-manikandan.m@microchip.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] i3c: mipi-i3c-hci: missing hci->io->cleanup() on error in
  i3c_hci_bus_init()
- [Medium] i3c: mchp_cfg_od_pp_timing() violates FM tBUF/tLOW and
  truncates slow counts
- [Medium] i3c: mchp_cfg_od_pp_timing() allows SCL counts below DW
  minimum of 5
--

commit 99cd11959d0217e78c304d9c0456f9fa47ba3f6c
Author: Manikandan Muralidharan <manikandan.m@microchip.com>

i3c: mipi-i3c-hci: add Microchip quirk to derive SCL timings from gclk

This commit adds a Microchip-specific quirk and timing helper to compute
push-pull, open-drain, SDR1..SDR4 extended low count, and bus-free SCL
timings from the gclk rate and bus SCL rates instead of reusing the AMD
hardcoded timing quirk on SAMA7D65.

> diff --git a/drivers/i3c/master/mipi-i3c-hci/core.c b/drivers/i3c/master/mipi-i3c-hci/core.c
> index 23853ca134fbc..bc71871be2f06 100644
> --- a/drivers/i3c/master/mipi-i3c-hci/core.c
> +++ b/drivers/i3c/master/mipi-i3c-hci/core.c
> @@ -183,6 +183,13 @@ static int i3c_hci_bus_init(struct i3c_master_controller *m)
>  	if (hci->quirks & HCI_QUIRK_RESP_BUF_THLD)
>  		amd_set_resp_buf_thld(hci);
>  
> +	/* Configure OD and PP timings once the bus SCL rates are known */
> +	if (hci->quirks & HCI_QUIRK_MCHP_OD_PP_TIMING) {
> +		ret = mchp_cfg_od_pp_timing(hci);
> +		if (ret)
> +			return ret;
> +	}
> +

[Severity: Medium]
Should this error path call hci->io->cleanup(hci) before returning, or
run mchp_cfg_od_pp_timing() before hci->io->init(hci)?

When bus_init() fails, i3c_master_bus_init() skips bus_cleanup(), so a
failure here (for example if clk_get_rate() returns 0) leaves PIO
interrupts and queues enabled after probe failure, or active DMA rings
pointing at freed buffers if DMA mode is ever used with this quirk.

[ ... ]

> diff --git a/drivers/i3c/master/mipi-i3c-hci/hci_quirks_mchp.c b/drivers/i3c/master/mipi-i3c-hci/hci_quirks_mchp.c
> new file mode 100644
> index 0000000000000..dff319d6287f5
> --- /dev/null
> +++ b/drivers/i3c/master/mipi-i3c-hci/hci_quirks_mchp.c

[ ... ]

> +#define MCHP_SCL_CNT_MIN		1
> +#define MCHP_SCL_CNT_MAX		0xff	/* each count field is 8 bits */
> +
> +/*
> + * Cycles for one half of an SCL period.
> + *
> + * @core_rate: I3C peripheral (generic) clock rate
> + * @scl_rate:  target rate for the phase/mode being programmed
> + * @base:      cycles already used by the opposite half of the period
> + *
> + * Returns round_up(core_rate / scl_rate) - base, clamped to a non-zero
> + * 8-bit count. Shared by the PP low, OD high, and SDR1..4 extended low counts.
> + */
> +static u8 mchp_scl_cnt(unsigned long core_rate, unsigned long scl_rate, u8 base)
> +{
> +	u32 period = DIV_ROUND_UP(core_rate, scl_rate);
> +
> +	if (period <= base)
> +		return MCHP_SCL_CNT_MIN;
> +
> +	return min_t(u32, period - base, MCHP_SCL_CNT_MAX);
> +}

[Severity: Medium]
Does the SAMA7D65 I3CC timing block share the DesignWare minimum SCL
count of 5?

The vendor timing registers match drivers/i3c/master/dw-i3c-master.c
shifted by 0x160, where SCL_I3C_TIMING_CNT_MIN is 5.  With
MCHP_SCL_CNT_MIN at 1, a 100 MHz gclk at the default 12.5 MHz I3C SCL
rate computes hcnt = 4 and lcnt = 4, which can violate that minimum.

If MCHP_SCL_CNT_MIN is raised above 1, mchp_scl_cnt() also needs to
clamp period - base against MCHP_SCL_CNT_MIN rather than only checking
period <= base.

[ ... ]

> +	hcnt = clamp_t(u32, DIV_ROUND_UP_ULL((u64)I3C_BUS_THIGH_MIXED_MAX_NS * core_rate,
> +					     NSEC_PER_SEC) - 1,
> +		       MCHP_SCL_CNT_MIN, MCHP_SCL_CNT_MAX);
> +	lcnt = mchp_scl_cnt(core_rate, bus->scl_rate.i3c, hcnt);
> +	reg_write(HCI_SCL_I3C_PP_TIMING,
> +		  FIELD_PREP(SCL_I3C_TIMING_HCNT, hcnt) |
> +		  FIELD_PREP(SCL_I3C_TIMING_LCNT, lcnt));

[ ... ]

> +	/* Open-drain timing, ~50% duty derived from the I2C SCL rate */
> +	lcnt = mchp_scl_cnt(core_rate, 2 * i2c_rate, 0);
> +	hcnt = mchp_scl_cnt(core_rate, i2c_rate, lcnt);
> +	reg_write(HCI_SCL_I3C_OD_TIMING,
> +		  FIELD_PREP(SCL_I3C_TIMING_HCNT, hcnt) |
> +		  FIELD_PREP(SCL_I3C_TIMING_LCNT, lcnt));
> +
> +	/* Bus-free time matches the open-drain low period */
> +	reg_write(MCHP_BUS_FREE_TIMING, FIELD_PREP(MCHP_BUS_I3C_MST_FREE, lcnt));

[Severity: Medium]
Can this open-drain and bus-free timing calculation violate the I2C
Fast-Mode tLOW/tBUF minimum and silently overclock slower bus modes?

On a mixed bus with a 400 kHz Fast-Mode I2C device, a 50% duty cycle
gives an open-drain low and bus-free period of 1250 ns (1256 ns at
125 MHz gclk).  That is below the 1300 ns I2C Fast-Mode tLOW and
I3C_BUS_TBUF_MIXED_FM_MIN_NS minimums and can cause I2C bus errors.

At 100 kHz Standard Mode and 125 MHz gclk, mchp_scl_cnt() silently clamps
both lcnt and hcnt to 0xff (~245 kHz) and writes that 8-bit lcnt to the
16-bit MCHP_BUS_I3C_MST_FREE field (2040 ns vs 4700 ns tBUF).

In I3C_BUS_MODE_MIXED_SLOW at 400 kHz and 125 MHz gclk, push-pull lcnt is
similarly clamped to 0xff (~481 kHz instead of <= 400 kHz).

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204083449.933526-1-manikandan.m@microchip.com?part=2

-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

  reply	other threads:[~2026-12-04  8:57 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  8:34 [PATCH 0/3] i3c: mipi-i3c-hci: derive SAMA7D65 SCL timings from gclk Manikandan Muralidharan
2026-12-04  8:34 ` [PATCH 1/3] i3c: mipi-i3c-hci: move shared SCL timing register offsets to hci.h Manikandan Muralidharan
2026-12-04 20:22   ` Frank Li
2026-12-04  8:34 ` [PATCH 2/3] i3c: mipi-i3c-hci: add Microchip quirk to derive SCL timings from gclk Manikandan Muralidharan
2026-12-04  8:57   ` sashiko-bot [this message]
2026-12-04 20:30     ` Frank Li
2026-12-04 20:29   ` Frank Li
2026-12-04  8:34 ` [PATCH 3/3] i3c: mipi-i3c-hci: add Microchip quirk to set response buffer threshold Manikandan Muralidharan
2026-12-04  8:48   ` sashiko-bot
2026-12-04 20:34   ` Frank Li

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=sashiko-outbox-249447@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=alexandre.belloni@bootlin.com \
    --cc=linux-i3c@lists.infradead.org \
    --cc=manikandan.m@microchip.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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