diff options
Diffstat (limited to 'Documentation/gpio/driver.txt')
-rw-r--r-- | Documentation/gpio/driver.txt | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/Documentation/gpio/driver.txt b/Documentation/gpio/driver.txt index f73cc7b5dc85..fa9a0a8b3734 100644 --- a/Documentation/gpio/driver.txt +++ b/Documentation/gpio/driver.txt | |||
@@ -73,6 +73,65 @@ The IRQ portions of the GPIO block are implemented using an irqchip, using | |||
73 | the header <linux/irq.h>. So basically such a driver is utilizing two sub- | 73 | the header <linux/irq.h>. So basically such a driver is utilizing two sub- |
74 | systems simultaneously: gpio and irq. | 74 | systems simultaneously: gpio and irq. |
75 | 75 | ||
76 | GPIO irqchips usually fall in one of two categories: | ||
77 | |||
78 | * CHAINED GPIO irqchips: these are usually the type that is embedded on | ||
79 | an SoC. This means that there is a fast IRQ handler for the GPIOs that | ||
80 | gets called in a chain from the parent IRQ handler, most typically the | ||
81 | system interrupt controller. This means the GPIO irqchip is registered | ||
82 | using irq_set_chained_handler() or the corresponding | ||
83 | gpiochip_set_chained_irqchip() helper function, and the GPIO irqchip | ||
84 | handler will be called immediately from the parent irqchip, while | ||
85 | holding the IRQs disabled. The GPIO irqchip will then end up calling | ||
86 | something like this sequence in its interrupt handler: | ||
87 | |||
88 | static irqreturn_t tc3589x_gpio_irq(int irq, void *data) | ||
89 | chained_irq_enter(...); | ||
90 | generic_handle_irq(...); | ||
91 | chained_irq_exit(...); | ||
92 | |||
93 | Chained GPIO irqchips typically can NOT set the .can_sleep flag on | ||
94 | struct gpio_chip, as everything happens directly in the callbacks. | ||
95 | |||
96 | * NESTED THREADED GPIO irqchips: these are off-chip GPIO expanders and any | ||
97 | other GPIO irqchip residing on the other side of a sleeping bus. Of course | ||
98 | such drivers that need slow bus traffic to read out IRQ status and similar, | ||
99 | traffic which may in turn incur other IRQs to happen, cannot be handled | ||
100 | in a quick IRQ handler with IRQs disabled. Instead they need to spawn a | ||
101 | thread and then mask the parent IRQ line until the interrupt is handled | ||
102 | by the driver. The hallmark of this driver is to call something like | ||
103 | this in its interrupt handler: | ||
104 | |||
105 | static irqreturn_t tc3589x_gpio_irq(int irq, void *data) | ||
106 | ... | ||
107 | handle_nested_irq(irq); | ||
108 | |||
109 | The hallmark of threaded GPIO irqchips is that they set the .can_sleep | ||
110 | flag on struct gpio_chip to true, indicating that this chip may sleep | ||
111 | when accessing the GPIOs. | ||
112 | |||
113 | To help out in handling the set-up and management of GPIO irqchips and the | ||
114 | associated irqdomain and resource allocation callbacks, the gpiolib has | ||
115 | some helpers that can be enabled by selecting the GPIOLIB_IRQCHIP Kconfig | ||
116 | symbol: | ||
117 | |||
118 | * gpiochip_irqchip_add(): adds an irqchip to a gpiochip. It will pass | ||
119 | the struct gpio_chip* for the chip to all IRQ callbacks, so the callbacks | ||
120 | need to embed the gpio_chip in its state container and obtain a pointer | ||
121 | to the container using container_of(). | ||
122 | (See Documentation/driver-model/design-patterns.txt) | ||
123 | |||
124 | * gpiochip_set_chained_irqchip(): sets up a chained irq handler for a | ||
125 | gpio_chip from a parent IRQ and passes the struct gpio_chip* as handler | ||
126 | data. (Notice handler data, since the irqchip data is likely used by the | ||
127 | parent irqchip!) This is for the chained type of chip. | ||
128 | |||
129 | To use the helpers please keep the following in mind: | ||
130 | |||
131 | - Make sure to assign all relevant members of the struct gpio_chip so that | ||
132 | the irqchip can initialize. E.g. .dev and .can_sleep shall be set up | ||
133 | properly. | ||
134 | |||
76 | It is legal for any IRQ consumer to request an IRQ from any irqchip no matter | 135 | It is legal for any IRQ consumer to request an IRQ from any irqchip no matter |
77 | if that is a combined GPIO+IRQ driver. The basic premise is that gpio_chip and | 136 | if that is a combined GPIO+IRQ driver. The basic premise is that gpio_chip and |
78 | irq_chip are orthogonal, and offering their services independent of each | 137 | irq_chip are orthogonal, and offering their services independent of each |