Skip to content

Commit 666c299

Browse files
committed
mtd: spinand: Enhance the logic when picking a variant
Currently the best variant picked in the first one in the list provided in the manufacturer driver. This worked well while all operations where performed at the same speed, but with the introduction of DTR transfers and per operation maximum frequencies, this no longer works correctly. Let's continue iterating over all the alternatives, even if we find a match, keeping a reference over the theoretically fastest operation. Only at the end we can tell which variant is the best. This logic happening only once at boot, the extra computing needed compared to the previous version is acceptable wrt. the expected improvements. Signed-off-by: Miquel Raynal <[email protected]>
1 parent 7ce0d16 commit 666c299

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

drivers/mtd/nand/spi/core.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,10 +1213,13 @@ spinand_select_op_variant(struct spinand_device *spinand,
12131213
const struct spinand_op_variants *variants)
12141214
{
12151215
struct nand_device *nand = spinand_to_nand(spinand);
1216+
const struct spi_mem_op *best_variant = NULL;
1217+
u64 best_op_duration_ns = ULLONG_MAX;
12161218
unsigned int i;
12171219

12181220
for (i = 0; i < variants->nops; i++) {
12191221
struct spi_mem_op op = variants->ops[i];
1222+
u64 op_duration_ns = 0;
12201223
unsigned int nbytes;
12211224
int ret;
12221225

@@ -1235,13 +1238,17 @@ spinand_select_op_variant(struct spinand_device *spinand,
12351238
break;
12361239

12371240
nbytes -= op.data.nbytes;
1241+
1242+
op_duration_ns += spi_mem_calc_op_duration(&op);
12381243
}
12391244

1240-
if (!nbytes)
1241-
return &variants->ops[i];
1245+
if (!nbytes && op_duration_ns < best_op_duration_ns) {
1246+
best_op_duration_ns = op_duration_ns;
1247+
best_variant = &variants->ops[i];
1248+
}
12421249
}
12431250

1244-
return NULL;
1251+
return best_variant;
12451252
}
12461253

12471254
/**

0 commit comments

Comments
 (0)