pmic: allow dump command for non contiguous register maps
authorMartin Fuzzey <martin.fuzzey@flowbird.group>
Tue, 14 Jan 2020 15:56:18 +0000 (15:56 +0000)
committerTom Rini <trini@konsulko.com>
Tue, 28 Jan 2020 00:54:20 +0000 (19:54 -0500)
Some PMICs (such as the DA9063) have non-contiguous register maps.
Attempting to read the non implemented registers returns an error
rather than a dummy value which causes 'pmic dump' to terminate
prematurely.

Fix this by allowing the PMIC driver to return -ENODATA for such
registers, which will then be displayed as '--' by pmic dump.

Use a single error code rather than any error code so that
we can distinguish between a hardware failure reading the PMIC
and a non implemented register known to the driver.

Signed-off-by: Martin Fuzzey <martin.fuzzey@flowbird.group>
cmd/pmic.c

index e46d813a70b2b75431bec04a7a64d8cc8b1b5564..2400bfb601d9d4d931a171aa94fdd047e76093de 100644 (file)
@@ -95,7 +95,7 @@ static int do_dump(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
        for (reg = 0; reg < pmic_reg_count(dev); reg++) {
                ret = pmic_reg_read(dev, reg);
-               if (ret < 0) {
+               if (ret < 0 && ret != -ENODATA) {
                        printf("Can't read register: %d\n", reg);
                        return failure(ret);
                }
@@ -103,7 +103,15 @@ static int do_dump(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
                if (!(reg % 16))
                        printf("\n0x%02x: ", reg);
 
-               printf(fmt, ret);
+               if (ret == -ENODATA) {
+                       int i;
+
+                       for (i = 0; i < priv->trans_len; i++)
+                               puts("--");
+                       puts(" ");
+               } else {
+                       printf(fmt, ret);
+               }
        }
        printf("\n");