irq: irq-gpio-switch: add gpio alias name support

Before the patch, we get gpio index(0,1,2..) depends on gpio
fdt node name, such as: gpio0@..., gpio1@..., etc.

But from RK3568, we add gpio alias to indicate gpio index
information and index is removed from gpio node name, ie:
gpio@fdd60000, gpio@fe740000, etc.

Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
Change-Id: I56e45941f9572fbc6a5a5916896e12f6eff9dcf3
This commit is contained in:
Joseph Chen 2020-11-14 03:29:58 +00:00 committed by Jianhong Chen
parent 9d23fbe3b7
commit 8db677370c
1 changed files with 42 additions and 36 deletions

View File

@ -42,6 +42,8 @@ static struct gpio_bank gpio_banks[GPIO_BANK_NUM] = {
#endif #endif
}; };
static const char *gpio_alias[GPIO_BANK_NUM];
static int gpio_is_valid(u32 gpio) static int gpio_is_valid(u32 gpio)
{ {
if ((gpio == EINVAL_GPIO) || if ((gpio == EINVAL_GPIO) ||
@ -80,60 +82,64 @@ static int __hard_gpio_to_irq(u32 gpio)
static int __phandle_gpio_to_irq(u32 gpio_phandle, u32 offset) static int __phandle_gpio_to_irq(u32 gpio_phandle, u32 offset)
{ {
int irq_gpio, bank, ret = EINVAL_GPIO; const void *blob = gd->fdt_blob;
const char *name; const char *gpio_name;
char *name_tok; char alias_name[6];
bool found; int irq, node;
int node; int i, bank;
bool found = false;
node = fdt_node_offset_by_phandle(gd->fdt_blob, gpio_phandle); node = fdt_node_offset_by_phandle(blob, gpio_phandle);
if (node < 0) { if (node < 0) {
IRQ_E("Can't find node by gpio_phandle=%d, ret=%d\n", IRQ_E("No gpio node by phandle(0x%x), ret=%d\n", gpio_phandle, node);
gpio_phandle, node);
return EINVAL_GPIO; return EINVAL_GPIO;
} }
name = fdt_get_name(gd->fdt_blob, node, NULL); gpio_name = fdt_get_name(blob, node, NULL);
if (!name) { if (!gpio_name)
IRQ_E("Can't find gpio bank for phandle=%d\n", gpio_phandle);
return EINVAL_GPIO; return EINVAL_GPIO;
}
name_tok = strdup(name); for (bank = 0; bank < GPIO_BANK_NUM; bank++) {
if (!name_tok) { if (!strstr(gpio_name, gpio_banks[bank].name)) {
IRQ_E("Strdup '%s' failed!\n", name);
return -ENOMEM;
}
name = strtok(name_tok, "@");
if (!name) {
IRQ_E("Can't strtok '@' for '%s'\n", name_tok);
goto out;
}
for (bank = 0; bank < ARRAY_SIZE(gpio_banks); bank++) {
if (!strcmp(gpio_banks[bank].name, name)) {
found = true; found = true;
break; break;
} }
} }
if (!found) { if (!found) {
IRQ_E("GPIO irq framework can't find '%s'\n", name); /* initial getting all gpio alias */
goto out; if (!gpio_alias[0]) {
for (i = 0; i < GPIO_BANK_NUM; i++) {
snprintf(alias_name, 6, "gpio%d", i);
gpio_alias[i] = fdt_get_alias(blob, alias_name);
if (!gpio_alias[i]) {
IRQ_D("No gpio alias %s\n", alias_name);
return EINVAL_GPIO;
}
}
}
/* match alias ? */
for (bank = 0; bank < ARRAY_SIZE(gpio_banks); bank++) {
if (!strstr(gpio_alias[bank], gpio_name)) {
found = true;
break;
}
}
}
if (!found) {
IRQ_E("IRQ Framework can't find: %s\n", gpio_name);
return EINVAL_GPIO;
} }
IRQ_D("%s: gpio%d-%d\n", __func__, bank, offset); IRQ_D("%s: gpio%d-%d\n", __func__, bank, offset);
irq_gpio = RK_IRQ_GPIO(bank, offset);
if (!gpio_is_valid(irq_gpio))
goto out;
free(name_tok); irq = RK_IRQ_GPIO(bank, offset);
return __hard_gpio_to_irq(irq_gpio); if (!gpio_is_valid(irq))
return EINVAL_GPIO;
out: return __hard_gpio_to_irq(irq);
free(name_tok);
return ret;
} }
static int __irq_to_gpio(int irq) static int __irq_to_gpio(int irq)