diff mbox series

[U-Boot,v2,38/41] pmic: allow dump command for non contiguous register maps

Message ID 7d8b5b058b7ae014934d1872989e979c6f4d039b.1571853833.git.bob.beckett@collabora.com
State Changes Requested
Delegated to: Stefano Babic
Headers show
Series convert GE boards to DM | expand

Commit Message

Robert Beckett Oct. 23, 2019, 6:21 p.m. UTC
From: Martin Fuzzey <martin.fuzzey@flowbird.group>

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>
Signed-off-by: Robert Beckett <bob.beckett@collabora.com>
---
 cmd/pmic.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

Comments

Frieder Schrempf Oct. 30, 2019, 2:02 p.m. UTC | #1
On 23.10.19 20:21, Robert Beckett wrote:
> From: Martin Fuzzey <martin.fuzzey@flowbird.group>
> 
> 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>
> Signed-off-by: Robert Beckett <bob.beckett@collabora.com>

Reviewed-by: Frieder Schrempf <frieder.schrempf@kontron.de>
Tested-by: Frieder Schrempf <frieder.schrempf@kontron.de>

> ---
>   cmd/pmic.c | 12 ++++++++++--
>   1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/cmd/pmic.c b/cmd/pmic.c
> index e46d813a70..2400bfb601 100644
> --- a/cmd/pmic.c
> +++ b/cmd/pmic.c
> @@ -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");
>   
>
diff mbox series

Patch

diff --git a/cmd/pmic.c b/cmd/pmic.c
index e46d813a70..2400bfb601 100644
--- a/cmd/pmic.c
+++ b/cmd/pmic.c
@@ -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");