[RFC PATCH 04/10] mtd: mtdcore: Call mtd_execute_tuning during mtd_register

Santhosh Kumar K
2025-08-11T19:33:49Z

Call mtd_execute_tuning() during the mtd_register() which redirects to
the flash specific tuning procedure to run at higher frequencies.

Signed-off-by: Santhosh Kumar K <s-k6@ti.com>
---
drivers/mtd/mtdcore.c | 19 +++++++++++++++++++
drivers/mtd/mtdcore.h | 1 +
2 files changed, 20 insertions(+)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 5ba9a741f5ac..f50cebcdb670 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -1023,6 +1023,22 @@ static int mtd_otp_nvmem_add(struct mtd_info *mtd)
return dev_err_probe(dev, err, "Failed to register OTP NVMEM device\n");
}

+int mtd_execute_tuning(struct mtd_info *mtd)
+{
+ struct mtd_part *part;
+
+ list_for_each_entry(part, &mtd->partitions, node) {
+ struct mtd_info *part_info =
+ container_of(part, struct mtd_info, part);
+ if (part_info->name &&
+ !strcmp(part_info->name, "ospi.phypattern")) {
+ return mtd->_execute_tuning(mtd, part);
+ }
+ }
+
+ return -ENODEV;
+}
+
/**
* mtd_device_parse_register - parse partitions and register an MTD device.
*
@@ -1087,6 +1103,9 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
if (ret)
goto out;

+ if (mtd_execute_tuning(mtd) == -ENODEV)
+ dev_info(&mtd->dev, "PHY pattern partition not found\n");
+
/*
* FIXME: some drivers unfortunately call this function more than once.
* So we have to check if we've already assigned the reboot notifier.
diff --git a/drivers/mtd/mtdcore.h b/drivers/mtd/mtdcore.h
index b014861a06a6..04055fcd2df8 100644
--- a/drivers/mtd/mtdcore.h
+++ b/drivers/mtd/mtdcore.h
@@ -13,6 +13,7 @@ int del_mtd_device(struct mtd_info *mtd);
int add_mtd_partitions(struct mtd_info *, const struct mtd_partition *, int);
int del_mtd_partitions(struct mtd_info *);
void release_mtd_partition(struct mtd_info *mtd);
+int mtd_execute_tuning(struct mtd_info *mtd);

struct mtd_partitions;

--
2.34.1