From 58383c78425e4ee1c077253cf297b641c861c02e Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Wed, 4 Nov 2015 09:56:26 +0100 Subject: gpio: change member .dev to .parent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The name .dev in a struct is normally reserved for a struct device that is let us say a superclass to the thing described by the struct. struct gpio_chip stands out by confusingly using a struct device *dev to point to the parent device (such as a platform_device) that represents the hardware. As we want to give gpio_chip:s real devices, this is not working. We need to rename this member to parent. This was done by two coccinelle scripts, I guess it is possible to combine them into one, but I don't know such stuff. They look like this: @@ struct gpio_chip *var; @@ -var->dev +var->parent and: @@ struct gpio_chip var; @@ -var.dev +var.parent and: @@ struct bgpio_chip *var; @@ -var->gc.dev +var->gc.parent Plus a few instances of bgpio that I couldn't figure out how to teach Coccinelle to rewrite. This patch hits all over the place, but I *strongly* prefer this solution to any piecemal approaches that just exercise patch mechanics all over the place. It mainly hits drivers/gpio and drivers/pinctrl which is my own backyard anyway. Cc: Haavard Skinnemoen Cc: Rafał Miłecki Cc: Richard Purdie Cc: Mauro Carvalho Chehab Cc: Alek Du Cc: Jaroslav Kysela Cc: Takashi Iwai Acked-by: Dmitry Torokhov Acked-by: Greg Kroah-Hartman Acked-by: Lee Jones Acked-by: Jiri Kosina Acked-by: Hans-Christian Egtvedt Acked-by: Jacek Anaszewski Signed-off-by: Linus Walleij --- drivers/gpio/gpiolib-acpi.c | 47 ++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 22 deletions(-) (limited to 'drivers/gpio/gpiolib-acpi.c') diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c index 16a7b6816744..e4620e14457f 100644 --- a/drivers/gpio/gpiolib-acpi.c +++ b/drivers/gpio/gpiolib-acpi.c @@ -51,10 +51,10 @@ struct acpi_gpio_chip { static int acpi_gpiochip_find(struct gpio_chip *gc, void *data) { - if (!gc->dev) + if (!gc->parent) return false; - return ACPI_HANDLE(gc->dev) == data; + return ACPI_HANDLE(gc->parent) == data; } #ifdef CONFIG_PINCTRL @@ -184,7 +184,7 @@ static acpi_status acpi_gpiochip_request_interrupt(struct acpi_resource *ares, if (agpio->connection_type != ACPI_RESOURCE_GPIO_TYPE_INT) return AE_OK; - handle = ACPI_HANDLE(chip->dev); + handle = ACPI_HANDLE(chip->parent); pin = agpio->pin_table[0]; if (pin <= 255) { @@ -208,7 +208,7 @@ static acpi_status acpi_gpiochip_request_interrupt(struct acpi_resource *ares, desc = gpiochip_request_own_desc(chip, pin, "ACPI:Event"); if (IS_ERR(desc)) { - dev_err(chip->dev, "Failed to request GPIO\n"); + dev_err(chip->parent, "Failed to request GPIO\n"); return AE_ERROR; } @@ -216,13 +216,13 @@ static acpi_status acpi_gpiochip_request_interrupt(struct acpi_resource *ares, ret = gpiochip_lock_as_irq(chip, pin); if (ret) { - dev_err(chip->dev, "Failed to lock GPIO as interrupt\n"); + dev_err(chip->parent, "Failed to lock GPIO as interrupt\n"); goto fail_free_desc; } irq = gpiod_to_irq(desc); if (irq < 0) { - dev_err(chip->dev, "Failed to translate GPIO to IRQ\n"); + dev_err(chip->parent, "Failed to translate GPIO to IRQ\n"); goto fail_unlock_irq; } @@ -259,7 +259,8 @@ static acpi_status acpi_gpiochip_request_interrupt(struct acpi_resource *ares, ret = request_threaded_irq(event->irq, NULL, handler, irqflags, "ACPI:Event", event); if (ret) { - dev_err(chip->dev, "Failed to setup interrupt handler for %d\n", + dev_err(chip->parent, + "Failed to setup interrupt handler for %d\n", event->irq); goto fail_free_event; } @@ -293,10 +294,10 @@ void acpi_gpiochip_request_interrupts(struct gpio_chip *chip) acpi_handle handle; acpi_status status; - if (!chip->dev || !chip->to_irq) + if (!chip->parent || !chip->to_irq) return; - handle = ACPI_HANDLE(chip->dev); + handle = ACPI_HANDLE(chip->parent); if (!handle) return; @@ -323,10 +324,10 @@ void acpi_gpiochip_free_interrupts(struct gpio_chip *chip) acpi_handle handle; acpi_status status; - if (!chip->dev || !chip->to_irq) + if (!chip->parent || !chip->to_irq) return; - handle = ACPI_HANDLE(chip->dev); + handle = ACPI_HANDLE(chip->parent); if (!handle) return; @@ -748,7 +749,7 @@ out: static void acpi_gpiochip_request_regions(struct acpi_gpio_chip *achip) { struct gpio_chip *chip = achip->chip; - acpi_handle handle = ACPI_HANDLE(chip->dev); + acpi_handle handle = ACPI_HANDLE(chip->parent); acpi_status status; INIT_LIST_HEAD(&achip->conns); @@ -757,20 +758,22 @@ static void acpi_gpiochip_request_regions(struct acpi_gpio_chip *achip) acpi_gpio_adr_space_handler, NULL, achip); if (ACPI_FAILURE(status)) - dev_err(chip->dev, "Failed to install GPIO OpRegion handler\n"); + dev_err(chip->parent, + "Failed to install GPIO OpRegion handler\n"); } static void acpi_gpiochip_free_regions(struct acpi_gpio_chip *achip) { struct gpio_chip *chip = achip->chip; - acpi_handle handle = ACPI_HANDLE(chip->dev); + acpi_handle handle = ACPI_HANDLE(chip->parent); struct acpi_gpio_connection *conn, *tmp; acpi_status status; status = acpi_remove_address_space_handler(handle, ACPI_ADR_SPACE_GPIO, acpi_gpio_adr_space_handler); if (ACPI_FAILURE(status)) { - dev_err(chip->dev, "Failed to remove GPIO OpRegion handler\n"); + dev_err(chip->parent, + "Failed to remove GPIO OpRegion handler\n"); return; } @@ -787,16 +790,16 @@ void acpi_gpiochip_add(struct gpio_chip *chip) acpi_handle handle; acpi_status status; - if (!chip || !chip->dev) + if (!chip || !chip->parent) return; - handle = ACPI_HANDLE(chip->dev); + handle = ACPI_HANDLE(chip->parent); if (!handle) return; acpi_gpio = kzalloc(sizeof(*acpi_gpio), GFP_KERNEL); if (!acpi_gpio) { - dev_err(chip->dev, + dev_err(chip->parent, "Failed to allocate memory for ACPI GPIO chip\n"); return; } @@ -806,7 +809,7 @@ void acpi_gpiochip_add(struct gpio_chip *chip) status = acpi_attach_data(handle, acpi_gpio_chip_dh, acpi_gpio); if (ACPI_FAILURE(status)) { - dev_err(chip->dev, "Failed to attach ACPI GPIO chip\n"); + dev_err(chip->parent, "Failed to attach ACPI GPIO chip\n"); kfree(acpi_gpio); return; } @@ -820,16 +823,16 @@ void acpi_gpiochip_remove(struct gpio_chip *chip) acpi_handle handle; acpi_status status; - if (!chip || !chip->dev) + if (!chip || !chip->parent) return; - handle = ACPI_HANDLE(chip->dev); + handle = ACPI_HANDLE(chip->parent); if (!handle) return; status = acpi_get_data(handle, acpi_gpio_chip_dh, (void **)&acpi_gpio); if (ACPI_FAILURE(status)) { - dev_warn(chip->dev, "Failed to retrieve ACPI GPIO chip\n"); + dev_warn(chip->parent, "Failed to retrieve ACPI GPIO chip\n"); return; } -- cgit From 9c3c9bc9cc980d8981f75109f3921576daf75723 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Wed, 11 Nov 2015 11:45:30 -0800 Subject: gpiolib: tighten up ACPI legacy gpio lookups We should not fall back to the legacy unnamed gpio lookup style if the driver requests gpios with different names, because we'll give out the same gpio twice. Let's keep track of the names that were used for the device and only do the fallback for the first name used. Signed-off-by: Dmitry Torokhov Acked-by: Mika Westerberg Signed-off-by: Linus Walleij --- drivers/gpio/gpiolib-acpi.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'drivers/gpio/gpiolib-acpi.c') diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c index e4620e14457f..07e571a1a377 100644 --- a/drivers/gpio/gpiolib-acpi.c +++ b/drivers/gpio/gpiolib-acpi.c @@ -925,3 +925,46 @@ int acpi_gpio_count(struct device *dev, const char *con_id) } return count; } + +struct acpi_crs_lookup { + struct list_head node; + struct acpi_device *adev; + const char *con_id; +}; + +static DEFINE_MUTEX(acpi_crs_lookup_lock); +static LIST_HEAD(acpi_crs_lookup_list); + +bool acpi_can_fallback_to_crs(struct acpi_device *adev, const char *con_id) +{ + struct acpi_crs_lookup *l, *lookup = NULL; + + /* Never allow fallback if the device has properties */ + if (adev->data.properties || adev->driver_gpios) + return false; + + mutex_lock(&acpi_crs_lookup_lock); + + list_for_each_entry(l, &acpi_crs_lookup_list, node) { + if (l->adev == adev) { + lookup = l; + break; + } + } + + if (!lookup) { + lookup = kmalloc(sizeof(*lookup), GFP_KERNEL); + if (lookup) { + lookup->adev = adev; + lookup->con_id = con_id; + list_add_tail(&lookup->node, &acpi_crs_lookup_list); + } + } + + mutex_unlock(&acpi_crs_lookup_lock); + + return lookup && + ((!lookup->con_id && !con_id) || + (lookup->con_id && con_id && + strcmp(lookup->con_id, con_id) == 0)); +} -- cgit