forked from mirrors/linux
		
	ACPI / gpio: Add irq_type when a GPIO is used as an interrupt
When a GPIO is used as an interrupt in ACPI, the irq_type was not available for device driver. Make available polarity and triggering information in acpi_find_gpio by renaming acpi_gpio_info field active_low to polarity and adding triggering field (edge/level). For sanity, in gpiolib.c replace info.active_low by "info.polarity == GPIO_ACTIVE_LOW". Set the irq_type if necessary in acpi_dev_gpio_irq_get. Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com> Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:
		
							parent
							
								
									55a93417c2
								
							
						
					
					
						commit
						52044723cd
					
				
					 3 changed files with 31 additions and 9 deletions
				
			
		| 
						 | 
					@ -417,10 +417,15 @@ static int acpi_find_gpio(struct acpi_resource *ares, void *data)
 | 
				
			||||||
		 * ActiveLow is only specified for GpioInt resource. If
 | 
							 * ActiveLow is only specified for GpioInt resource. If
 | 
				
			||||||
		 * GpioIo is used then the only way to set the flag is
 | 
							 * GpioIo is used then the only way to set the flag is
 | 
				
			||||||
		 * to use _DSD "gpios" property.
 | 
							 * to use _DSD "gpios" property.
 | 
				
			||||||
 | 
							 * Note: we expect here:
 | 
				
			||||||
 | 
							 * - ACPI_ACTIVE_LOW == GPIO_ACTIVE_LOW
 | 
				
			||||||
 | 
							 * - ACPI_ACTIVE_HIGH == GPIO_ACTIVE_HIGH
 | 
				
			||||||
		 */
 | 
							 */
 | 
				
			||||||
		if (lookup->info.gpioint)
 | 
							if (lookup->info.gpioint) {
 | 
				
			||||||
			lookup->info.active_low =
 | 
								lookup->info.polarity = agpio->polarity;
 | 
				
			||||||
				agpio->polarity == ACPI_ACTIVE_LOW;
 | 
								lookup->info.triggering = agpio->triggering;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return 1;
 | 
						return 1;
 | 
				
			||||||
| 
						 | 
					@ -447,7 +452,7 @@ static int acpi_gpio_resource_lookup(struct acpi_gpio_lookup *lookup,
 | 
				
			||||||
	if (info) {
 | 
						if (info) {
 | 
				
			||||||
		*info = lookup->info;
 | 
							*info = lookup->info;
 | 
				
			||||||
		if (lookup->active_low)
 | 
							if (lookup->active_low)
 | 
				
			||||||
			info->active_low = lookup->active_low;
 | 
								info->polarity = lookup->active_low;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -595,6 +600,7 @@ struct gpio_desc *acpi_node_get_gpiod(struct fwnode_handle *fwnode,
 | 
				
			||||||
int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index)
 | 
					int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int idx, i;
 | 
						int idx, i;
 | 
				
			||||||
 | 
						unsigned int irq_flags;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (i = 0, idx = 0; idx <= index; i++) {
 | 
						for (i = 0, idx = 0; idx <= index; i++) {
 | 
				
			||||||
		struct acpi_gpio_info info;
 | 
							struct acpi_gpio_info info;
 | 
				
			||||||
| 
						 | 
					@ -603,8 +609,23 @@ int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index)
 | 
				
			||||||
		desc = acpi_get_gpiod_by_index(adev, NULL, i, &info);
 | 
							desc = acpi_get_gpiod_by_index(adev, NULL, i, &info);
 | 
				
			||||||
		if (IS_ERR(desc))
 | 
							if (IS_ERR(desc))
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		if (info.gpioint && idx++ == index)
 | 
							if (info.gpioint && idx++ == index) {
 | 
				
			||||||
			return gpiod_to_irq(desc);
 | 
								int irq = gpiod_to_irq(desc);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if (irq < 0)
 | 
				
			||||||
 | 
									return irq;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								irq_flags = acpi_dev_get_irq_type(info.triggering,
 | 
				
			||||||
 | 
												  info.polarity);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								/* Set type if specified and different than the current one */
 | 
				
			||||||
 | 
								if (irq_flags != IRQ_TYPE_NONE &&
 | 
				
			||||||
 | 
								    irq_flags != irq_get_trigger_type(irq))
 | 
				
			||||||
 | 
									irq_set_irq_type(irq, irq_flags);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								return irq;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return -ENOENT;
 | 
						return -ENOENT;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1879,7 +1879,7 @@ static struct gpio_desc *acpi_find_gpio(struct device *dev, const char *con_id,
 | 
				
			||||||
			return desc;
 | 
								return desc;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (info.active_low)
 | 
						if (info.polarity == GPIO_ACTIVE_LOW)
 | 
				
			||||||
		*flags |= GPIO_ACTIVE_LOW;
 | 
							*flags |= GPIO_ACTIVE_LOW;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return desc;
 | 
						return desc;
 | 
				
			||||||
| 
						 | 
					@ -2217,7 +2217,7 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		desc = acpi_node_get_gpiod(fwnode, propname, 0, &info);
 | 
							desc = acpi_node_get_gpiod(fwnode, propname, 0, &info);
 | 
				
			||||||
		if (!IS_ERR(desc))
 | 
							if (!IS_ERR(desc))
 | 
				
			||||||
			active_low = info.active_low;
 | 
								active_low = info.polarity == GPIO_ACTIVE_LOW;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (IS_ERR(desc))
 | 
						if (IS_ERR(desc))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -26,7 +26,8 @@ struct acpi_device;
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
struct acpi_gpio_info {
 | 
					struct acpi_gpio_info {
 | 
				
			||||||
	bool gpioint;
 | 
						bool gpioint;
 | 
				
			||||||
	bool active_low;
 | 
						int polarity;
 | 
				
			||||||
 | 
						int triggering;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* gpio suffixes used for ACPI and device tree lookup */
 | 
					/* gpio suffixes used for ACPI and device tree lookup */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue