Linux-mtd Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Miquel Raynal <miquel.raynal@bootlin.com>
To: James Hilliard <james.hilliard1@gmail.com>
Cc: linux-mtd@lists.infradead.org,  linux-sunxi@lists.linux.dev,
	 Richard Weinberger <richard@nod.at>,
	 Vignesh Raghavendra <vigneshr@ti.com>,
	Chen-Yu Tsai <wens@kernel.org>,
	 Jernej Skrabec <jernej.skrabec@gmail.com>,
	 Samuel Holland <samuel@sholland.org>,
	Richard Genoud <richard.genoud@bootlin.com>,
	 Geert Uytterhoeven <geert+renesas@glider.be>,
	 linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mtd: rawnand: sunxi: fix H6/H616 controller timings
Date: Fri, 17 Jul 2026 13:55:29 +0200	[thread overview]
Message-ID: <87a4rpkez2.fsf@bootlin.com> (raw)
In-Reply-To: <20260715013142.640977-1-james.hilliard1@gmail.com> (James Hilliard's message of "Tue, 14 Jul 2026 19:31:38 -0600")

Hello James,

On 14/07/2026 at 19:31:38 -06, James Hilliard <james.hilliard1@gmail.com> wrote:

> The NAND timing calculation was written for the original A10 NDFC. It
> assumes command and address setup and hold intervals T1-T4, T7 and T11
> are one controller clock and uses the A10 timing-register encodings.
>
> The H6/H616 NDFC instead defines those intervals as two internal clock
> cycles and uses different encodings for tWB, tADL, tWHR and tRHW, as
> documented in the H616 User Manual.
>
> Describe the timing characteristics in the controller capability data
> so the clock solver can select a rate permitted by the NAND SDR timings
> and program valid delay fields. Keep the legacy A10 behavior unchanged.
>
> Fixes: 88fd4e4deae8 ("mtd: rawnand: sunxi: Add support for H616 nand controller")

Cc: stable missing here

> Signed-off-by: James Hilliard <james.hilliard1@gmail.com>

...

> @@ -1667,16 +1681,35 @@ static int sunxi_nfc_hw_ecc_write_oob(struct nand_chip *nand, int page)
>  	return nand_prog_page_end_op(nand);
>  }
>  
> -static const s32 tWB_lut[] = {6, 12, 16, 20};
> -static const s32 tRHW_lut[] = {4, 8, 12, 20};
> +static const struct sunxi_nfc_timings sun4i_a10_nfc_timings = {
> +	.setup_cycles = 1,
> +	.tWB = { 6, 12, 16, 20 },
> +	.tADL = { 7, 15, 23, 31 },
> +	.tWHR = { 7, 15, 23, 31 },
> +	.tRHW = { 4, 8, 12, 20 },
> +};

This patch looks overall correct but must be split. For instance, the
fact that you drop the LUT in favour of you own timing array shall be
done in a preparation patch, without adding new timings, nor adding the
new controller timings.

Then in a second time you could add tADL and tWHR support, etc.

> +
> +static const struct sunxi_nfc_timings sun50i_h6_nfc_timings = {
> +	.setup_cycles = 2,
> +	.tWB = { 28, 44, 60, 76 },
> +	.tADL = { 0, 12, 28, 44 },
> +	.tWHR = { 0, 12, 28, 44 },
> +	.tRHW = { 8, 24, 40, 56 },
> +};
> +
> +static void sunxi_nand_update_min_period(u32 *min_period, u32 duration,
> +					 unsigned int cycles)
> +{
> +	*min_period = max(*min_period, DIV_ROUND_UP(duration, cycles));
> +}
>  
> -static int _sunxi_nand_lookup_timing(const s32 *lut, int lut_size, u32 duration,
> -		u32 clk_period)
> +static int sunxi_nand_lookup_timing(const u8 *lut, u32 duration,
> +				    u32 clk_period)

This change is fine but likely also unrelated and should (maybe) be moved in its
own commit.

>  {
>  	u32 clk_cycles = DIV_ROUND_UP(duration, clk_period);
>  	int i;
>  
> -	for (i = 0; i < lut_size; i++) {
> +	for (i = 0; i < SUNXI_NFC_TIMING_STEPS; i++) {
>  		if (clk_cycles <= lut[i])
>  			return i;
>  	}

...

> @@ -1703,77 +1734,65 @@ static int sunxi_nfc_setup_interface(struct nand_chip *nand, int csline,
>  		return -ENOTSUPP;
>  
>  	/* T1 <=> tCLS */
> -	if (timings->tCLS_min > min_clk_period)
> -		min_clk_period = timings->tCLS_min;
> +	sunxi_nand_update_min_period(&min_clk_period, timings->tCLS_min,
> +				     nfc_timings->setup_cycles);

I am not sure I get the added value of this helper?

>  
>  	/* T2 <=> tCLH */
> -	if (timings->tCLH_min > min_clk_period)
> -		min_clk_period = timings->tCLH_min;
> +	sunxi_nand_update_min_period(&min_clk_period, timings->tCLH_min,
> +				     nfc_timings->setup_cycles);
>  

...

>  
>  static const struct sunxi_nfc_caps sunxi_nfc_h616_caps = {
> @@ -2641,6 +2664,7 @@ static const struct sunxi_nfc_caps sunxi_nfc_h616_caps = {
>  	.nuser_data_tab = ARRAY_SIZE(sunxi_user_data_len_h6),
>  	.max_ecc_steps = 32,
>  	.sram_size = 8192,
> +	.timings = &sun50i_h6_nfc_timings,

And this should be the last change in your series.

BTW would it be relevant to align the various names ? (h6 timings in the
h616 structure).

Thanks,
Miquèl

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

      reply	other threads:[~2026-07-17 11:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-15  1:31 [PATCH] mtd: rawnand: sunxi: fix H6/H616 controller timings James Hilliard
2026-07-17 11:55 ` Miquel Raynal [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=87a4rpkez2.fsf@bootlin.com \
    --to=miquel.raynal@bootlin.com \
    --cc=geert+renesas@glider.be \
    --cc=james.hilliard1@gmail.com \
    --cc=jernej.skrabec@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=richard.genoud@bootlin.com \
    --cc=richard@nod.at \
    --cc=samuel@sholland.org \
    --cc=vigneshr@ti.com \
    --cc=wens@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