platform/x86: x86-android-tablets: Add x86_android_tablet_get_gpiod() helper
Factor the code to go from a gpiochip label + pin-numer to a gpio_desc out of x86_acpi_irq_helper_get() and make it into a new x86_android_tablet_get_gpiod() helper, as this will be necessary in some x86_dev_info.init() functions too. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Link: https://lore.kernel.org/r/20220205191356.225505-3-hdegoede@redhat.com
This commit is contained in:
@@ -53,13 +53,33 @@ static int gpiochip_find_match_label(struct gpio_chip *gc, void *data)
|
|||||||
return gc->label && !strcmp(gc->label, data);
|
return gc->label && !strcmp(gc->label, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int x86_android_tablet_get_gpiod(char *label, int pin, struct gpio_desc **desc)
|
||||||
|
{
|
||||||
|
struct gpio_desc *gpiod;
|
||||||
|
struct gpio_chip *chip;
|
||||||
|
|
||||||
|
chip = gpiochip_find(label, gpiochip_find_match_label);
|
||||||
|
if (!chip) {
|
||||||
|
pr_err("error cannot find GPIO chip %s\n", label);
|
||||||
|
return -ENODEV;
|
||||||
|
}
|
||||||
|
|
||||||
|
gpiod = gpiochip_get_desc(chip, pin);
|
||||||
|
if (IS_ERR(gpiod)) {
|
||||||
|
pr_err("error %ld getting GPIO %s %d\n", PTR_ERR(gpiod), label, pin);
|
||||||
|
return PTR_ERR(gpiod);
|
||||||
|
}
|
||||||
|
|
||||||
|
*desc = gpiod;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int x86_acpi_irq_helper_get(const struct x86_acpi_irq_data *data)
|
static int x86_acpi_irq_helper_get(const struct x86_acpi_irq_data *data)
|
||||||
{
|
{
|
||||||
struct irq_fwspec fwspec = { };
|
struct irq_fwspec fwspec = { };
|
||||||
struct irq_domain *domain;
|
struct irq_domain *domain;
|
||||||
struct acpi_device *adev;
|
struct acpi_device *adev;
|
||||||
struct gpio_desc *gpiod;
|
struct gpio_desc *gpiod;
|
||||||
struct gpio_chip *chip;
|
|
||||||
unsigned int irq_type;
|
unsigned int irq_type;
|
||||||
acpi_handle handle;
|
acpi_handle handle;
|
||||||
acpi_status status;
|
acpi_status status;
|
||||||
@@ -74,18 +94,9 @@ static int x86_acpi_irq_helper_get(const struct x86_acpi_irq_data *data)
|
|||||||
return irq;
|
return irq;
|
||||||
case X86_ACPI_IRQ_TYPE_GPIOINT:
|
case X86_ACPI_IRQ_TYPE_GPIOINT:
|
||||||
/* Like acpi_dev_gpio_irq_get(), but without parsing ACPI resources */
|
/* Like acpi_dev_gpio_irq_get(), but without parsing ACPI resources */
|
||||||
chip = gpiochip_find(data->chip, gpiochip_find_match_label);
|
ret = x86_android_tablet_get_gpiod(data->chip, data->index, &gpiod);
|
||||||
if (!chip) {
|
if (ret)
|
||||||
pr_err("error cannot find GPIO chip %s\n", data->chip);
|
|
||||||
return -ENODEV;
|
|
||||||
}
|
|
||||||
|
|
||||||
gpiod = gpiochip_get_desc(chip, data->index);
|
|
||||||
if (IS_ERR(gpiod)) {
|
|
||||||
ret = PTR_ERR(gpiod);
|
|
||||||
pr_err("error %d getting GPIO %s %d\n", ret, data->chip, data->index);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
|
||||||
|
|
||||||
irq = gpiod_to_irq(gpiod);
|
irq = gpiod_to_irq(gpiod);
|
||||||
if (irq < 0) {
|
if (irq < 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user