public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Joseph Liu <maxdog988@gmail.com>
To: u-boot@lists.denx.de
Subject: [PATCH] gpio: pca953x: add bus option to select the i2c bus.
Date: Tue,  8 Dec 2020 15:32:26 +0800	[thread overview]
Message-ID: <20201208073226.21731-1-maxdog988@gmail.com> (raw)

From: Joseph Liu <kwliu@nuvoton.com>

If DM_I2C is used, the command "i2c dev" will not reassign
gd->cur_i2c_bus.

Add this bus option to change the active I2C bus.

Signed-off-by: Joseph Liu <kwliu@nuvoton.com>
---
 drivers/gpio/pca953x.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/pca953x.c b/drivers/gpio/pca953x.c
index 4ab8cee2d1..b64f6ddcea 100644
--- a/drivers/gpio/pca953x.c
+++ b/drivers/gpio/pca953x.c
@@ -20,6 +20,7 @@
 
 enum {
 	PCA953X_CMD_INFO,
+	PCA953X_CMD_BUS,
 	PCA953X_CMD_DEVICE,
 	PCA953X_CMD_OUTPUT,
 	PCA953X_CMD_INPUT,
@@ -194,6 +195,7 @@ static int pca953x_info(uint8_t chip)
 }
 
 static struct cmd_tbl cmd_pca953x[] = {
+	U_BOOT_CMD_MKENT(bus, 3, 0, (void *)PCA953X_CMD_BUS, "", ""),
 	U_BOOT_CMD_MKENT(device, 3, 0, (void *)PCA953X_CMD_DEVICE, "", ""),
 	U_BOOT_CMD_MKENT(output, 4, 0, (void *)PCA953X_CMD_OUTPUT, "", ""),
 	U_BOOT_CMD_MKENT(input, 3, 0, (void *)PCA953X_CMD_INPUT, "", ""),
@@ -205,6 +207,7 @@ static int do_pca953x(struct cmd_tbl *cmdtp, int flag, int argc,
 		      char *const argv[])
 {
 	static uint8_t chip = CONFIG_SYS_I2C_PCA953X_ADDR;
+	uint8_t bus = 0;
 	int ret = CMD_RET_USAGE, val;
 	ulong ul_arg2 = 0;
 	ulong ul_arg3 = 0;
@@ -214,7 +217,7 @@ static int do_pca953x(struct cmd_tbl *cmdtp, int flag, int argc,
 
 	/* All commands but "device" require 'maxargs' arguments */
 	if (!c || !((argc == (c->maxargs)) ||
-		(((long)c->cmd == PCA953X_CMD_DEVICE) &&
+		((((long)c->cmd == PCA953X_CMD_DEVICE) || ((long)c->cmd == PCA953X_CMD_BUS)) &&
 		 (argc == (c->maxargs - 1))))) {
 		return CMD_RET_USAGE;
 	}
@@ -233,7 +236,14 @@ static int do_pca953x(struct cmd_tbl *cmdtp, int flag, int argc,
 		if (ret)
 			ret = CMD_RET_FAILURE;
 		break;
+	case PCA953X_CMD_BUS:
+		if (argc == 3)
+			i2c_set_bus_num((uint8_t)ul_arg2);
 
+		bus = i2c_get_bus_num();
+		printf("Current i2c bus: 0x%x\n", bus);
+		ret = CMD_RET_SUCCESS;
+		break;
 	case PCA953X_CMD_DEVICE:
 		if (argc == 3)
 			chip = (uint8_t)ul_arg2;
@@ -280,6 +290,8 @@ static int do_pca953x(struct cmd_tbl *cmdtp, int flag, int argc,
 U_BOOT_CMD(
 	pca953x,	5,	1,	do_pca953x,
 	"pca953x gpio access",
+	"bus [num]\n"
+	"	- show or set current i2c bus\n"
 	"device [dev]\n"
 	"	- show or set current device address\n"
 	"pca953x info\n"
-- 
2.17.1

             reply	other threads:[~2020-12-08  7:32 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-08  7:32 Joseph Liu [this message]
2020-12-12 15:39 ` [PATCH] gpio: pca953x: add bus option to select the i2c bus Simon Glass
2020-12-12 18:51   ` Chris Packham
2020-12-14 15:49     ` Simon Glass
2020-12-15  7:31       ` Chris Packham

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201208073226.21731-1-maxdog988@gmail.com \
    --to=maxdog988@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox