return 0;
}
+static int tca642x_get_bank(int pin)
+{
+ int gpio_bank;
+
+ if (pin <= 7) {
+ gpio_bank = 0;
+ } else if ((pin >= 10) && (pin <= 17)) {
+ gpio_bank = 1;
+ } else if ((pin >= 20) && (pin <= 27)) {
+ gpio_bank = 2;
+ } else {
+ printf("Requested pin is not available\n");
+ gpio_bank = -1;
+ }
+
+ return gpio_bank;
+}
+
static struct cmd_tbl cmd_tca642x[] = {
U_BOOT_CMD_MKENT(device, 3, 0, (void *)TCA642X_CMD_DEVICE, "", ""),
U_BOOT_CMD_MKENT(output, 4, 0, (void *)TCA642X_CMD_OUTPUT, "", ""),
{
static uchar chip = CONFIG_SYS_I2C_TCA642X_ADDR;
int ret = CMD_RET_USAGE, val;
- uint8_t gpio_bank = 0;
+ int gpio_bank = 0;
uint8_t bank_shift;
ulong ul_arg2 = 0;
ulong ul_arg3 = 0;
ul_arg2 = simple_strtoul(argv[2], NULL, 10);
/* arg3 used as pin or invert value */
- if (argc > 3) {
+ if (argc > 3)
ul_arg3 = simple_strtoul(argv[3], NULL, 10) & 0x1;
- if (ul_arg2 <= 7) {
- gpio_bank = 0;
- } else if ((ul_arg2 >= 10) && (ul_arg2 <= 17)) {
- gpio_bank = 1;
- } else if ((ul_arg2 >= 20) && (ul_arg2 <= 27)) {
- gpio_bank = 2;
- } else {
- printf("Requested pin is not available\n");
- ret = CMD_RET_FAILURE;
- goto error;
- }
- }
switch ((int)c->cmd) {
case TCA642X_CMD_INFO:
break;
case TCA642X_CMD_INPUT:
+ gpio_bank = tca642x_get_bank(ul_arg2);
+ if (gpio_bank < 0) {
+ ret = CMD_RET_FAILURE;
+ goto error;
+ }
bank_shift = ul_arg2 - (gpio_bank * 10);
ret = tca642x_set_dir(chip, gpio_bank, (1 << bank_shift),
TCA642X_DIR_IN << bank_shift);
break;
case TCA642X_CMD_OUTPUT:
+ gpio_bank = tca642x_get_bank(ul_arg2);
+ if (gpio_bank < 0) {
+ ret = CMD_RET_FAILURE;
+ goto error;
+ }
bank_shift = ul_arg2 - (gpio_bank * 10);
ret = tca642x_set_dir(chip, gpio_bank, (1 << bank_shift),
(TCA642X_DIR_OUT << bank_shift));
break;
case TCA642X_CMD_INVERT:
+ gpio_bank = tca642x_get_bank(ul_arg2);
+ if (gpio_bank < 0) {
+ ret = CMD_RET_FAILURE;
+ goto error;
+ }
bank_shift = ul_arg2 - (gpio_bank * 10);
ret = tca642x_set_pol(chip, gpio_bank, (1 << bank_shift),
(ul_arg3 << bank_shift));