[PATCH v3 11/13] mtd: spinand: run PHY tuning after init and update dirmap frequencies

Santhosh Kumar K s-k6 at ti.com
Mon Jun 1 02:16:44 PDT 2026


Hello Miquel,

On 28/05/26 14:57, Miquel Raynal wrote:
> Hi Santhosh,
> 
> On 27/05/2026 at 23:25:25 +0530, Santhosh Kumar K <s-k6 at ti.com> wrote:
> 
>> Run spi_mem_execute_tuning() in spinand_probe() after spinand_init()
>> completes. The read and write op templates are copied into persistent
>> fields in spinand_device so the controller can write the validated
>> frequency directly back into them. On success, propagate that frequency
>> to every dirmap's primary and secondary op templates. Updating the
>> secondary template ensures continuous-read dirmaps also benefit from
>> the validated speed, not just the primary read path.
>>
>> Signed-off-by: Santhosh Kumar K <s-k6 at ti.com>
>> ---
>>   drivers/mtd/nand/spi/core.c | 35 +++++++++++++++++++++++++++++++++++
>>   include/linux/mtd/spinand.h |  4 ++++
>>   2 files changed, 39 insertions(+)
>>
>> diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
>> index f1084d5e04b9..9b54e4607cfe 100644
>> --- a/drivers/mtd/nand/spi/core.c
>> +++ b/drivers/mtd/nand/spi/core.c
>> @@ -2030,6 +2030,41 @@ static int spinand_probe(struct spi_mem *mem)
>>   	if (ret)
>>   		return ret;
>>   
>> +	/*
>> +	 * Copy the read and write op templates into persistent fields so
>> +	 * execute_tuning can write the validated frequency back into them.
>> +	 * Tuning failure is non-fatal; the device operates at base speed.
>> +	 */
>> +	spinand->max_read_op = *spinand->op_templates->read_cache;
>> +	spinand->max_write_op = *spinand->op_templates->write_cache;
>> +
>> +	ret = spi_mem_execute_tuning(mem, &spinand->max_read_op,
>> +				     &spinand->max_write_op);
>> +	if (ret && ret != -EOPNOTSUPP)
>> +		dev_warn(&mem->spi->dev, "Failed to execute PHY tuning: %d\n",
>> +			 ret);
>> +
>> +	/*
>> +	 * Dirmaps were set up in spinand_init() before tuning ran; update
>> +	 * their op templates to use the validated frequency.
>> +	 */
>> +	if (!ret) {
>> +		struct nand_device *nand = spinand_to_nand(spinand);
>> +		int i;
>> +
>> +		for (i = 0; i < nand->memorg.planes_per_lun; i++) {
>> +			if (spinand->dirmaps[i].rdesc) {
>> +				spinand->dirmaps[i].rdesc->info.primary_op_tmpl.max_freq =
>> +					spinand->max_read_op.max_freq;
>> +				spinand->dirmaps[i].rdesc->info.secondary_op_tmpl.max_freq =
>> +					spinand->max_read_op.max_freq;
>> +			}
>> +			if (spinand->dirmaps[i].wdesc)
>> +				spinand->dirmaps[i].wdesc->info.primary_op_tmpl.max_freq =
>> +					spinand->max_write_op.max_freq;
>> +		}
>> +	}
> 
> Unfortunately, hot fixing the dirmaps is invalid. When we take the best
> variant, we select a maximum speed that may be lower than the tuned PHY
> speed. We cannot just overwrite that value without consequence, because
> depending on the boundaries we cross, extra dummy cycles may be
> required.
> 
> I believe spinand_select_op_variant() shall be aware of the different
> possible speeds. It should look for the max_speed_hz capability and not
> for the base_speed_hz, and fallback to base_speed_hz in case of
> issue.
> 
> Or otherwise, maybe we could go through the whole I/O variant
> selection again after tuning, with the actual maximum speed set.

Good catch. Updating the dirmap templates after they have already been
created is indeed not correct, as the operation selection may depend on
the final frequency and associated parameters such as dummy cycles.

Instead of patching the dirmaps after tuning, I'll move the
_execute_tuning() call before dirmap creation. This way, the validated
frequency can be written back into the selected read/write variant, and
the dirmaps will then be created using the final ops.

I'll rework the flow accordingly and let you know the results once I've
tested it.

Thanks,
Santhosh.

> 
> 
> Thanks,
> Miquèl




More information about the linux-mtd mailing list