4 * Copyright (C) 2015 ARM Ltd.
5 * Author: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 #include <linux/acpi.h>
12 #include <linux/irq.h>
13 #include <linux/irqdomain.h>
16 enum acpi_irq_model_id acpi_irq_model;
18 static struct fwnode_handle *acpi_gsi_domain_id;
20 static unsigned int acpi_gsi_get_irq_type(int trigger, int polarity)
24 return trigger == ACPI_EDGE_SENSITIVE ?
25 IRQ_TYPE_EDGE_FALLING :
27 case ACPI_ACTIVE_HIGH:
28 return trigger == ACPI_EDGE_SENSITIVE ?
29 IRQ_TYPE_EDGE_RISING :
31 case ACPI_ACTIVE_BOTH:
32 if (trigger == ACPI_EDGE_SENSITIVE)
33 return IRQ_TYPE_EDGE_BOTH;
40 * acpi_gsi_to_irq() - Retrieve the linux irq number for a given GSI
41 * @gsi: GSI IRQ number to map
42 * @irq: pointer where linux IRQ number is stored
44 * irq location updated with irq value [>0 on success, 0 on failure]
46 * Returns: linux IRQ number on success (>0)
49 int acpi_gsi_to_irq(u32 gsi, unsigned int *irq)
51 struct irq_domain *d = irq_find_matching_fwnode(acpi_gsi_domain_id,
54 *irq = irq_find_mapping(d, gsi);
56 * *irq == 0 means no mapping, that should
57 * be reported as a failure
59 return (*irq > 0) ? *irq : -EINVAL;
61 EXPORT_SYMBOL_GPL(acpi_gsi_to_irq);
64 * acpi_register_gsi() - Map a GSI to a linux IRQ number
65 * @dev: device for which IRQ has to be mapped
66 * @gsi: GSI IRQ number
67 * @trigger: trigger type of the GSI number to be mapped
68 * @polarity: polarity of the GSI to be mapped
70 * Returns: a valid linux IRQ number on success
73 int acpi_register_gsi(struct device *dev, u32 gsi, int trigger,
77 unsigned int irq_type = acpi_gsi_get_irq_type(trigger, polarity);
79 if (acpi_gsi_domain_id) {
80 struct irq_fwspec fwspec;
82 fwspec.fwnode = acpi_gsi_domain_id;
83 fwspec.param[0] = gsi;
84 fwspec.param[1] = irq_type;
85 fwspec.param_count = 2;
87 return irq_create_fwspec_mapping(&fwspec);
89 irq = irq_create_mapping(NULL, gsi);
94 /* Set irq type if specified and different than the current one */
95 if (irq_type != IRQ_TYPE_NONE &&
96 irq_type != irq_get_trigger_type(irq))
97 irq_set_irq_type(irq, irq_type);
100 EXPORT_SYMBOL_GPL(acpi_register_gsi);
103 * acpi_unregister_gsi() - Free a GSI<->linux IRQ number mapping
104 * @gsi: GSI IRQ number
106 void acpi_unregister_gsi(u32 gsi)
108 struct irq_domain *d = irq_find_matching_fwnode(acpi_gsi_domain_id,
110 int irq = irq_find_mapping(d, gsi);
112 irq_dispose_mapping(irq);
114 EXPORT_SYMBOL_GPL(acpi_unregister_gsi);
117 * acpi_set_irq_model - Setup the GSI irqdomain information
118 * @model: the value assigned to acpi_irq_model
119 * @fwnode: the irq_domain identifier for mapping and looking up
122 void __init acpi_set_irq_model(enum acpi_irq_model_id model,
123 struct fwnode_handle *fwnode)
125 acpi_irq_model = model;
126 acpi_gsi_domain_id = fwnode;