gpio: tca642x: Add the tca642x gpio expander driver
PATCH 1/2 gpio: tca642x: Add the tca642x gpio expander driver
Add the tca642x gpio expander driver
--- drivers/gpio/Makefile | 1 + drivers/gpio/tca642x.c | 312 ++++++++++++++++++++++++++++++++++++++++++++++++ include/tca642x.h | 64 ++++++++++ 3 files changed, 377 insertions(+) create mode 100644 drivers/gpio/tca642x.c create mode 100644 include/tca642x.h
drivers/gpio/Makefile +1 -0
@@ -49,6 +49,7 @@ COBJS-$(CONFIG_BCM2835_GPIO) += bcm2835_gpio.o COBJS-$(CONFIG_S3C2440_GPIO) += s3c2440_gpio.o COBJS-$(CONFIG_XILINX_GPIO) += xilinx_gpio.o COBJS-$(CONFIG_ADI_GPIO2) += adi_gpio2.o +COBJS-$(CONFIG_TCA642X) += tca642x.o COBJS := $(COBJS-y) SRCS := $(COBJS:.o=.c)
drivers/gpio/tca642x.c new file +312 -0
312 lines not on this page · raw message
include/tca642x.h new file +64 -0
64 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH 2/2 omap5: Configure the tca6424 gpio expander
Configure the tca6424 gpio expander
This allows use of the debug and tri color LEDs.
As well as HDMI PEO signal.
--- board/ti/omap5_uevm/evm.c | 12 ++++++++++++ board/ti/omap5_uevm/mux_data.h | 2 ++ include/configs/omap5_uevm.h | 5 +++++ 3 files changed, 19 insertions(+)
board/ti/omap5_uevm/evm.c +12 -0
@@ -26,6 +26,7 @@#include <palmas.h> #include <asm/arch/sys_proto.h> #include <asm/arch/mmc_host_def.h> +#include <tca642x.h> #include "mux_data.h"
@@ -35,6 +36,15 @@ const struct omap_sysinfo sysinfo = { "Board: OMAP5430 EVM\n" }; +/* Initial states for the GPIO expander +* input reg, output reg, polarity reg, configuration reg +*/ +struct tca642x_bank_info tca642x_init[] = { + {0x00 ,0x04 ,0x00 ,0x80 }, + {0x00 ,0x00 ,0x00 ,0xff }, + {0x00 ,0x00 ,0x00 ,0x40 }, +}; +/** * @brief board_init *
@@ -46,6 +56,8 @@ int board_init(void) gd->bd->bi_arch_number =MACH_TYPE_OMAP5_SEVM ; gd->bd->bi_boot_params = (0x80000000 +0x100 );/* boot param addr */ +tca642x_set_inital_state (CONFIG_SYS_I2C_TCA642X_ADDR , tca642x_init); +return 0 ; }
board/ti/omap5_uevm/mux_data.h +2 -0
@@ -56,6 +56,8 @@ const struct pad_conf_entry core_padconf_array_essential[] = { {USBD0_HS_DP, (IEN | M0)}, /* USBD0_HS_DP */ {USBD0_HS_DM, (IEN | M0)}, /* USBD0_HS_DM */ {USBD0_SS_RX, (IEN | M0)}, /* USBD0_SS_RX */ + {I2C5_SCL, (IEN | M0)}, /* I2C5_SCL */ + {I2C5_SDA, (IEN | M0)}, /* I2C5_SDA */ };
include/configs/omap5_uevm.h +5 -0
@@ -53,6 +53,11 @@#define CONFIG_PARTITION_UUIDS #define CONFIG_CMD_PART +#define CONFIG_TCA642X +#define CONFIG_CMD_TCA642X +#define CONFIG_SYS_I2C_TCA642X_BUS_NUM 4 +#define CONFIG_SYS_I2C_TCA642X_ADDR 0x22 +#define CONFIG_SYS_PROMPT "OMAP5432 uEVM # "#define CONSOLEDEV "ttyO2"
Signature · 1 line
1.7.9.5
PATCH 2/2 omap5: Configure the tca6424 gpio expander
$subject
omap5: uevm
Quoted 3 lines · Dan Murphy
Configure the tca6424 gpio expander
This allows use of the debug and tri color LEDs.
As well as HDMI PEO signal.
we use HDMI in u-boot?
Quoted 21 lines
Signed-off-by Dan Murphy <[email protected]>--- board/ti/omap5_uevm/evm.c | 12 ++++++++++++ board/ti/omap5_uevm/mux_data.h | 2 ++ include/configs/omap5_uevm.h | 5 +++++ 3 files changed, 19 insertions(+)board/ti/omap5_uevm/evm.c +1
-0@@ -26,6 +26,7 @@#include <palmas.h> #include <asm/arch/sys_proto.h> #include <asm/arch/mmc_host_def.h> +#include <tca642x.h> #include "mux_data.h"
board/ti/omap5_uevm/evm.c const struct omap_sysinfo sysinfo = { · line 39
Quoted 4 lines
board/ti/omap5_uevm/evm.c +1
-0@@ -35,6 +36,15 @@ const struct omap_sysinfo sysinfo = { "Board: OMAP5430 EVM\n" }; +/* Initial states for the GPIO expander
Doc comment style.
board/ti/omap5_uevm/evm.c const struct omap_sysinfo sysinfo = { · line 45
Quoted 6 lines
board/ti/omap5_uevm/evm.c +6
-0+* input reg, output reg, polarity reg, configuration reg +*/ +struct tca642x_bank_info tca642x_init[] = { + {0x00 ,0x04 ,0x00 ,0x80 }, + {0x00 ,0x00 ,0x00 ,0xff }, + {0x00 ,0x00 ,0x00 ,0x40 },
could you be explicit and use .input_reg = etc?
btw, why should board know about input_reg, output_reg polarity_reg? is'nt that the job of the driver?
Quoted 44 lines
board/ti/omap5_uevm/evm.c +4
-0+}; +/** * @brief board_init * @@ -46,6 +56,8 @@ int board_init(void) gd->bd->bi_arch_number =MACH_TYPE_OMAP5_SEVM ; gd->bd->bi_boot_params = (0x80000000 +0x100 );/* boot param addr */ +tca642x_set_inital_state (CONFIG_SYS_I2C_TCA642X_ADDR , tca642x_init); +return 0 ; }board/ti/omap5_uevm/mux_data.h +2
-0@@ -56,6 +56,8 @@ const struct pad_conf_entry core_padconf_array_essential[] = { {USBD0_HS_DP, (IEN | M0)}, /* USBD0_HS_DP */ {USBD0_HS_DM, (IEN | M0)}, /* USBD0_HS_DM */ {USBD0_SS_RX, (IEN | M0)}, /* USBD0_SS_RX */ + {I2C5_SCL, (IEN | M0)}, /* I2C5_SCL */ + {I2C5_SDA, (IEN | M0)}, /* I2C5_SDA */ };include/configs/omap5_uevm.h +5
-0@@ -53,6 +53,11 @@#define CONFIG_PARTITION_UUIDS #define CONFIG_CMD_PART +#define CONFIG_TCA642X +#define CONFIG_CMD_TCA642X +#define CONFIG_SYS_I2C_TCA642X_BUS_NUM 4 +#define CONFIG_SYS_I2C_TCA642X_ADDR 0x22 +#define CONFIG_SYS_PROMPT "OMAP5432 uEVM # "#define CONSOLEDEV "ttyO2"
Signature · 2 lines
Regards, Nishanth Menon
PATCH 2/2 omap5: Configure the tca6424 gpio expander
Quoted 2 lines · Nishanth Menon
$subject
Don't know where it went it was in my patch set I submitted.
Quoted 6 lines
omap5: uevm
Quoted 3 lines · Dan Murphy
Configure the tca6424 gpio expander
This allows use of the debug and tri color LEDs.
As well as HDMI PEO signal.we use HDMI in u-boot?
Removed.
Quoted 18 lines
Quoted 18 lines
Signed-off-by Dan Murphy <[email protected]>--- board/ti/omap5_uevm/evm.c | 12 ++++++++++++ board/ti/omap5_uevm/mux_data.h | 2 ++ include/configs/omap5_uevm.h | 5 +++++ 3 files changed, 19 insertions(+)board/ti/omap5_uevm/evm.c +1
-0@@ -26,6 +26,7 @@#include <palmas.h> #include <asm/arch/sys_proto.h> #include <asm/arch/mmc_host_def.h> +#include <tca642x.h>
Quoted 8 lines
board/ti/omap5_uevm/evm.c const struct omap_sysinfo sysinfo = { · line 39
Quoted 7 lines
board/ti/omap5_uevm/evm.c +1
-0#include "mux_data.h" @@ -35,6 +36,15 @@ const struct omap_sysinfo sysinfo = { "Board: OMAP5430 EVM\n" }; +/* Initial states for the GPIO expander Doc comment style.
Will do.
Probably need a patch that fixes all the other interfaces as well.
Quoted 9 lines
board/ti/omap5_uevm/evm.c const struct omap_sysinfo sysinfo = { · line 45
Quoted 6 lines
board/ti/omap5_uevm/evm.c +6
-0+* input reg, output reg, polarity reg, configuration reg +*/ +struct tca642x_bank_info tca642x_init[] = { + {0x00 ,0x04 ,0x00 ,0x80 }, + {0x00 ,0x00 ,0x00 ,0xff }, + {0x00 ,0x00 ,0x00 ,0x40 },could you be explicit and use .input_reg = etc?
btw, why should board know aboutinput_reg,output_regpolarity_reg? is'nt that the job of the driver?
These are the default power up values for the uEVM.
I can add .input_reg = blah. Just thought the bank_info structure was good enough.
Quoted 50 lines
Quoted 48 lines
board/ti/omap5_uevm/evm.c +2
-0+}; +/** * @brief board_init * @@ -46,6 +56,8 @@ int board_init(void) gd->bd->bi_arch_number =MACH_TYPE_OMAP5_SEVM ; gd->bd->bi_boot_params = (0x80000000 +0x100 );/* boot param addr */
+ tca642x_set_inital_state(CONFIG_SYS_I2C_TCA642X_ADDR,
tca642x_init);board/ti/omap5_uevm/evm.c +1
-0+return 0 ; }board/ti/omap5_uevm/mux_data.h +2
-0@@ -56,6 +56,8 @@ const struct pad_conf_entry core_padconf_array_essential[] = { {USBD0_HS_DP , (IEN |M0 )},/* USBD0_HS_DP */ {USBD0_HS_DM , (IEN |M0 )},/* USBD0_HS_DM */ {USBD0_SS_RX , (IEN |M0 )},/* USBD0_SS_RX */ + {I2C5_SCL , (IEN |M0 )},/* I2C5_SCL */ + {I2C5_SDA , (IEN |M0 )},/* I2C5_SDA */ };include/configs/omap5_uevm.h +5
-0@@ -53,6 +53,11 @@#define CONFIG_PARTITION_UUIDS #define CONFIG_CMD_PART +#define CONFIG_TCA642X +#define CONFIG_CMD_TCA642X +#define CONFIG_SYS_I2C_TCA642X_BUS_NUM 4 +#define CONFIG_SYS_I2C_TCA642X_ADDR 0x22 +#define CONFIG_SYS_PROMPT "OMAP5432 uEVM # "#define CONSOLEDEV "ttyO2"
Signature · 2 lines
---------------------------------------------- Dan Murphy
PATCH 1/2 gpio: tca642x: Add the tca642x gpio expander driver
In reply to Dan MurphyQuoted 1 line · Dan Murphy
Add the tca642x gpio expander driver
http://www.ti.com/sitesearch/docs/universalsearch.tsp?searchTerm=tca642&linkId=1
I think there are just TCA6424 ?
giving a link to the product helps I suppose.
Quoted 47 lines
Signed-off-by Dan Murphy <[email protected]>--- drivers/gpio/Makefile | 1 + drivers/gpio/tca642x.c | 312 ++++++++++++++++++++++++++++++++++++++++++++++++ include/tca642x.h | 64 ++++++++++ 3 files changed, 377 insertions(+)create mode 100644
drivers/gpio/tca642x.c
create mode 100644include/tca642x.hdrivers/gpio/Makefile +1
-0@@ -49,6 +49,7 @@ COBJS-$(CONFIG_BCM2835_GPIO) += bcm2835_gpio.o COBJS-$(CONFIG_S3C2440_GPIO) += s3c2440_gpio.o COBJS-$(CONFIG_XILINX_GPIO) += xilinx_gpio.o COBJS-$(CONFIG_ADI_GPIO2) += adi_gpio2.o +COBJS-$(CONFIG_TCA642X) += tca642x.o COBJS := $(COBJS-y) SRCS := $(COBJS:.o=.c)drivers/gpio/tca642x.c new file +19
-0@@ -0,0 +1,312 @@ +/* +* Copyright 2013 Texas Instruments, Inc. +* +* Derived work from the pca953x.c driver +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* Version 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, +* MA 02111-1307 USA +*/
drivers/gpio/tca642x.c line 29
Quoted 10 lines
drivers/gpio/tca642x.c new file +10
-0+ +#include <common.h> +#include <i2c.h> +#include <tca642x.h> + +/* tca642x register address definitions */ +struct tca642x_bank_info tca642x_banks[] = { + {0x00 ,0x04 ,0x08 ,0x0c }, + {0x01 ,0x05 ,0x09 ,0x0d }, + {0x02 ,0x06 ,0x0a ,0x0e },
could we use explicit map of the struct params? helps any future expansion.
drivers/gpio/tca642x.c line 37
Quoted 8 lines
drivers/gpio/tca642x.c new file +8
-0+}; + +/* +* Modify masked bits in register +*/ +static int tca642x_reg_write (uint8_t chip,uint addr,uint mask,uint data) +{ +uint16_t valw;
why not use u8 instead? same for mask and data?
drivers/gpio/tca642x.c line 49
Quoted 12 lines
drivers/gpio/tca642x.c new file +12
-0+int org_bus_num; +int ret; + + org_bus_num =i2c_get_bus_num (); +i2c_set_bus_num (CONFIG_SYS_I2C_TCA642X_BUS_NUM ); + +if (i2c_read (chip, addr,1 , (u8 *)&valw,1 )) { +printf ("Could not read before writing\n" ); + ret =-1 ; + goto error; + } + valw &= ~mask;
data &= mask ?
drivers/gpio/tca642x.c line 57
Quoted 8 lines
drivers/gpio/tca642x.c new file +8
-0+ valw |= data; + + ret =i2c_write (chip, addr,1 , (u8 *)&valw,1 ); + +error: +i2c_set_bus_num (org_bus_num); +return ret; +
extra eol?
drivers/gpio/tca642x.c line 60
Quoted 3 lines
drivers/gpio/tca642x.c new file +3
-0+} + +static int tca642x_reg_read (uint8_t chip,uint addr,uint *data)
same here? addr is u8, data is u8 *?
drivers/gpio/tca642x.c line 62
Quoted 2 lines
drivers/gpio/tca642x.c new file +2
-0+{ +uint16_t valw;
val as u8?
Quoted 16 lines
drivers/gpio/tca642x.c new file +16
-0+int org_bus_num; +int ret =0 ; + + org_bus_num =i2c_get_bus_num (); +i2c_set_bus_num (CONFIG_SYS_I2C_TCA642X_BUS_NUM ); +if (i2c_read (chip, addr,1 , (u8 *)&valw,1 )) { + ret =-1 ; + goto error; + } + + *data = (int )valw; + +error: +i2c_set_bus_num (org_bus_num); +return ret; +}
[...]
Signature · 2 lines
Regards, Nishanth Menon
PATCH 1/2 gpio: tca642x: Add the tca642x gpio expander driver
Nishanth
Thanks for the feedback
Quoted 6 lines · Nishanth Menon
Quoted 1 line · Dan Murphy
Add the tca642x gpio expander driver
http://www.ti.com/sitesearch/docs/universalsearch.tsp?searchTerm=tca642&linkId=1
I think there are just TCA6424 ?
giving a link to the product helps I suppose.
Done. Next patchset
Quoted 52 lines
Quoted 52 lines
Signed-off-by Dan Murphy <[email protected]>--- drivers/gpio/Makefile | 1 + drivers/gpio/tca642x.c | 312 ++++++++++++++++++++++++++++++++++++++++++++++++ include/tca642x.h | 64 ++++++++++ 3 files changed, 377 insertions(+)create mode 100644
drivers/gpio/tca642x.c
create mode 100644include/tca642x.hdrivers/gpio/Makefile +1
-0@@ -49,6 +49,7 @@ COBJS-$(CONFIG_BCM2835_GPIO) += bcm2835_gpio.o COBJS-$(CONFIG_S3C2440_GPIO) += s3c2440_gpio.o COBJS-$(CONFIG_XILINX_GPIO) += xilinx_gpio.o COBJS-$(CONFIG_ADI_GPIO2) += adi_gpio2.o +COBJS-$(CONFIG_TCA642X) += tca642x.o COBJS := $(COBJS-y) SRCS := $(COBJS:.o=.c)drivers/gpio/tca642x.c new file +23
-0@@ -0,0 +1,312 @@ +/* +* Copyright 2013 Texas Instruments, Inc. +* +* Derived work from the pca953x.c driver +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* Version 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, +* MA 02111-1307 USA +*/ + +#include <common.h> +#include <i2c.h> +#include <tca642x.h>
Quoted 9 lines
drivers/gpio/tca642x.c line 29
Quoted 6 lines
drivers/gpio/tca642x.c new file +6
-0+ +/* tca642x register address definitions */ +struct tca642x_bank_info tca642x_banks[] = { + {0x00 ,0x04 ,0x08 ,0x0c }, + {0x01 ,0x05 ,0x09 ,0x0d }, + {0x02 ,0x06 ,0x0a ,0x0e },could we use explicit map of the struct params? helps any future expansion.
Not sure what you are looking for here. These are the register addresses within the chip.
Quoted 10 lines
drivers/gpio/tca642x.c
Quoted 9 lines
drivers/gpio/tca642x.c new file +6
-0+}; + +/* +* Modify masked bits in register +*/ +static int tca642x_reg_write(uint8_t chip, uint addr, uint mask,uint data)
drivers/gpio/tca642x.c new file +2
-0+{ +uint16_t valw;why not use u8 instead? same for mask and data?
Doh. That was carried over from the derivation work. Done. Next patchset
Quoted 5 lines
Quoted 5 lines
drivers/gpio/tca642x.c new file +5
-0+int org_bus_num; +int ret; + + org_bus_num =i2c_get_bus_num (); +i2c_set_bus_num (CONFIG_SYS_I2C_TCA642X_BUS_NUM );
Quoted 8 lines
drivers/gpio/tca642x.c line 49
Quoted 7 lines
drivers/gpio/tca642x.c new file +7
-0+ +if (i2c_read (chip, addr,1 , (u8 *)&valw,1 )) { +printf ("Could not read before writing\n" ); + ret =-1 ; + goto error; + } + valw &= ~mask;data &= mask ?
Well in this case the mask is not being passed in. The bit to flip is being passed and then the actual mask
is created here.
This code should be fine unless others object as well.
Quoted 9 lines
drivers/gpio/tca642x.c line 57
Quoted 8 lines
drivers/gpio/tca642x.c new file +8
-0+ valw |= data; + + ret =i2c_write (chip, addr,1 , (u8 *)&valw,1 ); + +error: +i2c_set_bus_num (org_bus_num); +return ret; +extra eol?
Done. Next patchset
Quoted 4 lines
drivers/gpio/tca642x.c line 60
Quoted 3 lines
drivers/gpio/tca642x.c new file +3
-0+} + +static int tca642x_reg_read (uint8_t chip,uint addr,uint *data)same here? addr is u8, data is u8 *?
Done. Next patchset
Quoted 3 lines
drivers/gpio/tca642x.c
Quoted 2 lines
drivers/gpio/tca642x.c new file +2
-0+{ +uint16_t valw;val as u8?
Done. Next patchset
Quoted 17 lines
Quoted 16 lines
drivers/gpio/tca642x.c new file +16
-0+int org_bus_num; +int ret =0 ; + + org_bus_num =i2c_get_bus_num (); +i2c_set_bus_num (CONFIG_SYS_I2C_TCA642X_BUS_NUM ); +if (i2c_read (chip, addr,1 , (u8 *)&valw,1 )) { + ret =-1 ; + goto error; + } + + *data = (int )valw; + +error: +i2c_set_bus_num (org_bus_num); +return ret; +}[...]
Signature · 2 lines
---------------------------------------------- Dan Murphy
PATCH 1/2 gpio: tca642x: Add the tca642x gpio expander driver
Quoted 2 lines · Dan Murphy
Quoted 1 line · Nishanth Menon
On 07/08/2013 03:53 PM, Dan Murphy wrote:
[...]
Quoted 10 lines
Quoted 8 lines
drivers/gpio/tca642x.c line 29
Quoted 5 lines
drivers/gpio/tca642x.c new file +5
-0+/* tca642x register address definitions */ +struct tca642x_bank_info tca642x_banks[] = { + {0x00 ,0x04 ,0x08 ,0x0c }, + {0x01 ,0x05 ,0x09 ,0x0d }, + {0x02 ,0x06 ,0x0a ,0x0e },could we use explicit map of the struct params? helps any future expansion.
Not sure what you are looking for here. These are the register addresses within the chip.
something like
{.input_reg = 0x00, .polarity_reg = 0x04, ....
It helps readability and future modification to bank_info structure.
[..]
Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
drivers/gpio/tca642x.c new file +5
-0+int org_bus_num; +int ret; + + org_bus_num =i2c_get_bus_num (); +i2c_set_bus_num (CONFIG_SYS_I2C_TCA642X_BUS_NUM );Quoted 8 lines
drivers/gpio/tca642x.c line 49
Quoted 7 lines
drivers/gpio/tca642x.c new file +7
-0+ +if (i2c_read (chip, addr,1 , (u8 *)&valw,1 )) { +printf ("Could not read before writing\n" ); + ret =-1 ; + goto error; + } + valw &= ~mask;data &= mask ?
Quoted 3 lines
Well in this case the mask is not being passed in. The bit to flip is being passed and then the actual mask
is created here.
reg_setbits? instead then? following the standard api convention - maybe make this as a i2c generic api?
Signature · 2 lines
Regards, Nishanth Menon