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

Miquel Raynal miquel.raynal at bootlin.com
Tue Jun 2 05:18:37 PDT 2026


Hello Santhosh,

>>> +	/*
>>> +	 * 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.

If this is doable, it is clearly the best approach, but on the other
side you might need to know what is the read variant before running the
tuning algorithm, so I am not sure it is feasible. I'll let you dig the
topic and propose the best approach you find!

Thanks,
Miquèl



More information about the linux-mtd mailing list