diff mbox series

gpio: pca953x: add bus option to select the i2c bus.

Message ID 20201208073226.21731-1-maxdog988@gmail.com
State Rejected
Delegated to: Heiko Schocher
Headers show
Series gpio: pca953x: add bus option to select the i2c bus. | expand

Commit Message

Joseph Liu Dec. 8, 2020, 7:32 a.m. UTC
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(-)

Comments

Simon Glass Dec. 12, 2020, 3:39 p.m. UTC | #1
Hi Joseph,

On Tue, 8 Dec 2020 at 00:32, Joseph Liu <maxdog988@gmail.com> wrote:
>
> 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(-)
>

This driver should be converted to driver model.

Regards,
Simon
Chris Packham Dec. 12, 2020, 6:51 p.m. UTC | #2
On Sun, 13 Dec 2020, 4:44 AM Simon Glass, <sjg@chromium.org> wrote:

> Hi Joseph,
>
> On Tue, 8 Dec 2020 at 00:32, Joseph Liu <maxdog988@gmail.com> wrote:
> >
> > 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(-)
> >
>
> This driver should be converted to driver model.
>

It has been. See drivers/gpio/pca953x_gpio.c
Simon Glass Dec. 14, 2020, 3:49 p.m. UTC | #3
Hi Chris,

On Sat, 12 Dec 2020 at 11:51, Chris Packham <judge.packham@gmail.com> wrote:
>
>
>
> On Sun, 13 Dec 2020, 4:44 AM Simon Glass, <sjg@chromium.org> wrote:
>>
>> Hi Joseph,
>>
>> On Tue, 8 Dec 2020 at 00:32, Joseph Liu <maxdog988@gmail.com> wrote:
>> >
>> > 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(-)
>> >
>>
>> This driver should be converted to driver model.
>
>
> It has been. See drivers/gpio/pca953x_gpio.c

I mean that it should use dm_i2c_read() instead of i2c_read(), so that
the problems of an 'active' i2c bus go away. Also it should use
devicetree.

Regards,
Simon
Chris Packham Dec. 15, 2020, 7:31 a.m. UTC | #4
On Tue, Dec 15, 2020 at 4:49 AM Simon Glass <sjg@chromium.org> wrote:
>
> Hi Chris,
>
> On Sat, 12 Dec 2020 at 11:51, Chris Packham <judge.packham@gmail.com> wrote:
> >
> >
> >
> > On Sun, 13 Dec 2020, 4:44 AM Simon Glass, <sjg@chromium.org> wrote:
> >>
> >> Hi Joseph,
> >>
> >> On Tue, 8 Dec 2020 at 00:32, Joseph Liu <maxdog988@gmail.com> wrote:
> >> >
> >> > 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(-)
> >> >
> >>
> >> This driver should be converted to driver model.
> >
> >
> > It has been. See drivers/gpio/pca953x_gpio.c
>
> I mean that it should use dm_i2c_read() instead of i2c_read(), so that
> the problems of an 'active' i2c bus go away. Also it should use
> devicetree.

That's what I'm saying, the pca953x_gpio.c is the DM version of the
pca953x.c driver. So the boards should be migrating to using the DM
driver and "gpio" commands instead of the old non-DM driver and
"pca953x" commands (not that my opinion counts for anything).
diff mbox series

Patch

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"