diff options
author | Linus Walleij <linus.walleij@linaro.org> | 2016-11-24 04:57:25 -0500 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2016-11-25 09:12:27 -0500 |
commit | d245b3f9bd36f02fd641cba9931d8b4c77126e74 (patch) | |
tree | fa9984376f28c4f6b8883aff8a704178aa68412f /Documentation/gpio | |
parent | 07d9a380680d1c0eb51ef87ff2eab5c994949e69 (diff) |
gpio: simplify adding threaded interrupts
This tries to simplify the use of CONFIG_GPIOLIB_IRQCHIP when
using threaded interrupts: add a new call
gpiochip_irqchip_add_nested() to indicate that we're dealing
with a nested rather than a chained irqchip, then create a
separate gpiochip_set_nested_irqchip() to mirror
the gpiochip_set_chained_irqchip() call to connect the
parent and child interrupts.
In the nested case gpiochip_set_nested_irqchip() does nothing
more than call irq_set_parent() on each valid child interrupt,
which has little semantic effect in the kernel, but this is
probably still formally correct.
Update all drivers using nested interrupts to use
gpiochip_irqchip_add_nested() so we can now see clearly
which these users are.
The DLN2 driver can drop its specific hack with
.irq_not_threaded as we now recognize whether a chip is
threaded or not from its use of gpiochip_irqchip_add_nested()
signature rather than from inspecting .can_sleep.
We rename the .irq_parent to .irq_chained_parent since this
parent IRQ is only really kept around for the chained
interrupt handlers.
Cc: Lars Poeschel <poeschel@lemonage.de>
Cc: Octavian Purdila <octavian.purdila@intel.com>
Cc: Daniel Baluta <daniel.baluta@intel.com>
Cc: Bin Gao <bin.gao@linux.intel.com>
Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: Ajay Thomas <ajay.thomas.david.rajamanickam@intel.com>
Cc: Semen Protsenko <semen.protsenko@globallogic.com>
Cc: Alexander Stein <alexander.stein@systec-electronic.com>
Cc: Phil Reid <preid@electromag.com.au>
Cc: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Cc: Patrice Chotard <patrice.chotard@st.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'Documentation/gpio')
-rw-r--r-- | Documentation/gpio/driver.txt | 62 |
1 files changed, 36 insertions, 26 deletions
diff --git a/Documentation/gpio/driver.txt b/Documentation/gpio/driver.txt index 368d5a294d89..747c721776ed 100644 --- a/Documentation/gpio/driver.txt +++ b/Documentation/gpio/driver.txt | |||
@@ -175,8 +175,8 @@ The IRQ portions of the GPIO block are implemented using an irqchip, using | |||
175 | the header <linux/irq.h>. So basically such a driver is utilizing two sub- | 175 | the header <linux/irq.h>. So basically such a driver is utilizing two sub- |
176 | systems simultaneously: gpio and irq. | 176 | systems simultaneously: gpio and irq. |
177 | 177 | ||
178 | RT_FULL: GPIO driver should not use spinlock_t or any sleepable APIs | 178 | RT_FULL: a realtime compliant GPIO driver should not use spinlock_t or any |
179 | (like PM runtime) as part of its irq_chip implementation on -RT. | 179 | sleepable APIs (like PM runtime) as part of its irq_chip implementation. |
180 | - spinlock_t should be replaced with raw_spinlock_t [1]. | 180 | - spinlock_t should be replaced with raw_spinlock_t [1]. |
181 | - If sleepable APIs have to be used, these can be done from the .irq_bus_lock() | 181 | - If sleepable APIs have to be used, these can be done from the .irq_bus_lock() |
182 | and .irq_bus_unlock() callbacks, as these are the only slowpath callbacks | 182 | and .irq_bus_unlock() callbacks, as these are the only slowpath callbacks |
@@ -185,33 +185,32 @@ RT_FULL: GPIO driver should not use spinlock_t or any sleepable APIs | |||
185 | GPIO irqchips usually fall in one of two categories: | 185 | GPIO irqchips usually fall in one of two categories: |
186 | 186 | ||
187 | * CHAINED GPIO irqchips: these are usually the type that is embedded on | 187 | * CHAINED GPIO irqchips: these are usually the type that is embedded on |
188 | an SoC. This means that there is a fast IRQ handler for the GPIOs that | 188 | an SoC. This means that there is a fast IRQ flow handler for the GPIOs that |
189 | gets called in a chain from the parent IRQ handler, most typically the | 189 | gets called in a chain from the parent IRQ handler, most typically the |
190 | system interrupt controller. This means the GPIO irqchip is registered | 190 | system interrupt controller. This means that the GPIO irqchip handler will |
191 | using irq_set_chained_handler() or the corresponding | 191 | be called immediately from the parent irqchip, while holding the IRQs |
192 | gpiochip_set_chained_irqchip() helper function, and the GPIO irqchip | 192 | disabled. The GPIO irqchip will then end up calling something like this |
193 | handler will be called immediately from the parent irqchip, while | 193 | sequence in its interrupt handler: |
194 | holding the IRQs disabled. The GPIO irqchip will then end up calling | 194 | |
195 | something like this sequence in its interrupt handler: | 195 | static irqreturn_t foo_gpio_irq(int irq, void *data) |
196 | |||
197 | static irqreturn_t tc3589x_gpio_irq(int irq, void *data) | ||
198 | chained_irq_enter(...); | 196 | chained_irq_enter(...); |
199 | generic_handle_irq(...); | 197 | generic_handle_irq(...); |
200 | chained_irq_exit(...); | 198 | chained_irq_exit(...); |
201 | 199 | ||
202 | Chained GPIO irqchips typically can NOT set the .can_sleep flag on | 200 | Chained GPIO irqchips typically can NOT set the .can_sleep flag on |
203 | struct gpio_chip, as everything happens directly in the callbacks. | 201 | struct gpio_chip, as everything happens directly in the callbacks: no |
202 | slow bus traffic like I2C can be used. | ||
204 | 203 | ||
205 | RT_FULL: Note, chained IRQ handlers will not be forced threaded on -RT. | 204 | RT_FULL: Note, chained IRQ handlers will not be forced threaded on -RT. |
206 | As result, spinlock_t or any sleepable APIs (like PM runtime) can't be used | 205 | As result, spinlock_t or any sleepable APIs (like PM runtime) can't be used |
207 | in chained IRQ handler. | 206 | in chained IRQ handler. |
208 | if required (and if it can't be converted to the nested threaded GPIO irqchip) | 207 | If required (and if it can't be converted to the nested threaded GPIO irqchip) |
209 | - chained IRQ handler can be converted to generic irq handler and this way | 208 | a chained IRQ handler can be converted to generic irq handler and this way |
210 | it will be threaded IRQ handler on -RT and hard IRQ handler on non-RT | 209 | it will be a threaded IRQ handler on -RT and a hard IRQ handler on non-RT |
211 | (for example, see [3]). | 210 | (for example, see [3]). |
212 | Know W/A: The generic_handle_irq() is expected to be called with IRQ disabled, | 211 | Know W/A: The generic_handle_irq() is expected to be called with IRQ disabled, |
213 | so IRQ core will complain if it will be called from IRQ handler which is | 212 | so the IRQ core will complain if it is called from an IRQ handler which is |
214 | forced thread. The "fake?" raw lock can be used to W/A this problem: | 213 | forced to a thread. The "fake?" raw lock can be used to W/A this problem: |
215 | 214 | ||
216 | raw_spinlock_t wa_lock; | 215 | raw_spinlock_t wa_lock; |
217 | static irqreturn_t omap_gpio_irq_handler(int irq, void *gpiobank) | 216 | static irqreturn_t omap_gpio_irq_handler(int irq, void *gpiobank) |
@@ -243,7 +242,7 @@ GPIO irqchips usually fall in one of two categories: | |||
243 | by the driver. The hallmark of this driver is to call something like | 242 | by the driver. The hallmark of this driver is to call something like |
244 | this in its interrupt handler: | 243 | this in its interrupt handler: |
245 | 244 | ||
246 | static irqreturn_t tc3589x_gpio_irq(int irq, void *data) | 245 | static irqreturn_t foo_gpio_irq(int irq, void *data) |
247 | ... | 246 | ... |
248 | handle_nested_irq(irq); | 247 | handle_nested_irq(irq); |
249 | 248 | ||
@@ -256,23 +255,31 @@ associated irqdomain and resource allocation callbacks, the gpiolib has | |||
256 | some helpers that can be enabled by selecting the GPIOLIB_IRQCHIP Kconfig | 255 | some helpers that can be enabled by selecting the GPIOLIB_IRQCHIP Kconfig |
257 | symbol: | 256 | symbol: |
258 | 257 | ||
259 | * gpiochip_irqchip_add(): adds an irqchip to a gpiochip. It will pass | 258 | * gpiochip_irqchip_add(): adds a chained irqchip to a gpiochip. It will pass |
260 | the struct gpio_chip* for the chip to all IRQ callbacks, so the callbacks | 259 | the struct gpio_chip* for the chip to all IRQ callbacks, so the callbacks |
261 | need to embed the gpio_chip in its state container and obtain a pointer | 260 | need to embed the gpio_chip in its state container and obtain a pointer |
262 | to the container using container_of(). | 261 | to the container using container_of(). |
263 | (See Documentation/driver-model/design-patterns.txt) | 262 | (See Documentation/driver-model/design-patterns.txt) |
264 | 263 | ||
265 | If there is a need to exclude certain GPIOs from the IRQ domain, one can | 264 | * gpiochip_irqchip_add_nested(): adds a nested irqchip to a gpiochip. |
266 | set .irq_need_valid_mask of the gpiochip before gpiochip_add_data() is | 265 | Apart from that it works exactly like the chained irqchip. |
267 | called. This allocates .irq_valid_mask with as many bits set as there are | ||
268 | GPIOs in the chip. Drivers can exclude GPIOs by clearing bits from this | ||
269 | mask. The mask must be filled in before gpiochip_irqchip_add() is called. | ||
270 | 266 | ||
271 | * gpiochip_set_chained_irqchip(): sets up a chained irq handler for a | 267 | * gpiochip_set_chained_irqchip(): sets up a chained irq handler for a |
272 | gpio_chip from a parent IRQ and passes the struct gpio_chip* as handler | 268 | gpio_chip from a parent IRQ and passes the struct gpio_chip* as handler |
273 | data. (Notice handler data, since the irqchip data is likely used by the | 269 | data. (Notice handler data, since the irqchip data is likely used by the |
274 | parent irqchip!) This is for the chained type of chip. This is also used | 270 | parent irqchip!). |
275 | to set up a nested irqchip if NULL is passed as handler. | 271 | |
272 | * gpiochip_set_nested_irqchip(): sets up a nested irq handler for a | ||
273 | gpio_chip from a parent IRQ. As the parent IRQ has usually been | ||
274 | explicitly requested by the driver, this does very little more than | ||
275 | mark all the child IRQs as having the other IRQ as parent. | ||
276 | |||
277 | If there is a need to exclude certain GPIOs from the IRQ domain, you can | ||
278 | set .irq_need_valid_mask of the gpiochip before gpiochip_add_data() is | ||
279 | called. This allocates an .irq_valid_mask with as many bits set as there | ||
280 | are GPIOs in the chip. Drivers can exclude GPIOs by clearing bits from this | ||
281 | mask. The mask must be filled in before gpiochip_irqchip_add() or | ||
282 | gpiochip_irqchip_add_nested() is called. | ||
276 | 283 | ||
277 | To use the helpers please keep the following in mind: | 284 | To use the helpers please keep the following in mind: |
278 | 285 | ||
@@ -323,6 +330,9 @@ When implementing an irqchip inside a GPIO driver, these two functions should | |||
323 | typically be called in the .startup() and .shutdown() callbacks from the | 330 | typically be called in the .startup() and .shutdown() callbacks from the |
324 | irqchip. | 331 | irqchip. |
325 | 332 | ||
333 | When using the gpiolib irqchip helpers, these callback are automatically | ||
334 | assigned. | ||
335 | |||
326 | Real-Time compliance for GPIO IRQ chips | 336 | Real-Time compliance for GPIO IRQ chips |
327 | --------------------------------------- | 337 | --------------------------------------- |
328 | 338 | ||