Add common master API to adapt voltage
We start by setting the voltage in prepare_flash_access() and, if we
were told to probe for a specific chip, before the probing. For now,
we leave the programmer driver's default voltage during the probing,
otherwise.
Once the probing is more bus centric, we can implement a more elabo-
rate scheme. For instance, we can probe at the lowest voltage first
and only increase it if there was no response at all.
Change-Id: I6689813f83abe654ba7a18f2e0537314047bf15f
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.sourcearcade.org/c/flashprog/+/414
diff --git a/flashprog.c b/flashprog.c
index e4151da..fd9cd74 100644
--- a/flashprog.c
+++ b/flashprog.c
@@ -649,6 +649,13 @@
*flash->chip = *chip;
flash->mst.par = &mst->par; /* both `mst` are unions, so we need only one pointer */
+ /* If we probe for a specific chip, we can adapt the voltage early. */
+ if (chip_to_probe && flash->mst.common->adapt_voltage) {
+ if (flash->mst.common->adapt_voltage(flash->mst.common,
+ chip->voltage.min, chip->voltage.max))
+ goto free_chip;
+ }
+
if (flash->chip->prepare_access && flash->chip->prepare_access(flash, PREPARE_PROBE))
goto free_chip;
@@ -1690,6 +1697,12 @@
return 1;
}
+ if (flash->mst.common->adapt_voltage) {
+ if (flash->mst.common->adapt_voltage(flash->mst.common,
+ flash->chip->voltage.min, flash->chip->voltage.max))
+ return 1;
+ }
+
if (flash->chip->prepare_access && flash->chip->prepare_access(flash, PREPARE_FULL))
return 1;