gpio: pca953x: add bus option to select the i2c bus.
PATCH 1/1 gpio: pca953x: add bus option to select the i2c bus.
From: Joseph Liu <[email protected]>
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.
--- drivers/gpio/pca953x.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/gpio/pca953x.c +13 -1
@@ -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"
Signature · 1 line
2.17.1
PATCH 1/1 gpio: pca953x: add bus option to select the i2c bus.
Hi Joseph,
Quoted 6 lines · Joseph Liu
From: Joseph Liu <[email protected]>
If
DM_I2Cis used, the command "i2c dev" will not reassigngd->cur_i2c_bus.
Quoted 7 lines
Add this bus option to change the active I2C bus.
Signed-off-by Joseph Liu <[email protected]>--- drivers/gpio/pca953x.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
This driver should be converted to driver model.
Regards,
Simon
PATCH 1/1 gpio: pca953x: add bus option to select the i2c bus.
Quoted 11 lines · Simon Glass,
Hi Joseph,
Quoted 8 lines · Joseph Liu
From: Joseph Liu <[email protected]>
If
DM_I2Cis used, the command "i2c dev" will not reassigngd->cur_i2c_bus.Add this bus option to change the active I2C bus.
Quoted 8 lines
Quoted 5 lines
Signed-off-by Joseph Liu <[email protected]>--- 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
PATCH 1/1 gpio: pca953x: add bus option to select the i2c bus.
Hi Chris,
Quoted 22 lines · Chris Packham
Quoted 18 lines · Simon Glass,
Hi Joseph,
Quoted 13 lines · Joseph Liu
From: Joseph Liu <[email protected]>
If
DM_I2Cis used, the command "i2c dev" will not reassigngd->cur_i2c_bus.Add this bus option to change the active I2C bus.
Signed-off-by Joseph Liu <[email protected]>--- drivers/gpio/pca953x.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
Quoted 4 lines
Quoted 1 line
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
PATCH 1/1 gpio: pca953x: add bus option to select the i2c bus.
Quoted 26 lines · Simon Glass
Hi Chris,
Quoted 22 lines · Chris Packham
Quoted 18 lines · Simon Glass,
Hi Joseph,
Quoted 13 lines · Joseph Liu
From: Joseph Liu <[email protected]>
If
DM_I2Cis used, the command "i2c dev" will not reassigngd->cur_i2c_bus.Add this bus option to change the active I2C bus.
Signed-off-by Joseph Liu <[email protected]>--- drivers/gpio/pca953x.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
This driver should be converted to driver model.
It has been. See
drivers/gpio/pca953x_gpio.cI mean that it should use
dm_i2c_read()instead ofi2c_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).