diff options
author | Grygorii Strashko <grygorii.strashko@ti.com> | 2015-10-20 10:22:15 -0400 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2015-10-27 06:13:42 -0400 |
commit | c307b002548590c5d8c32b964831de671ad4affe (patch) | |
tree | fee666462ff81cc0327e8827d7dff429917c48fe /Documentation/gpio/driver.txt | |
parent | 4aa50b87f1e99164a93314c25ed3a827c24bc54f (diff) |
gpio: add a real time compliance notes
Put in a compliance checklist.
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'Documentation/gpio/driver.txt')
-rw-r--r-- | Documentation/gpio/driver.txt | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/Documentation/gpio/driver.txt b/Documentation/gpio/driver.txt index 90d0f6aba7a6..12a61948ec91 100644 --- a/Documentation/gpio/driver.txt +++ b/Documentation/gpio/driver.txt | |||
@@ -62,6 +62,11 @@ Any debugfs dump method should normally ignore signals which haven't been | |||
62 | requested as GPIOs. They can use gpiochip_is_requested(), which returns either | 62 | requested as GPIOs. They can use gpiochip_is_requested(), which returns either |
63 | NULL or the label associated with that GPIO when it was requested. | 63 | NULL or the label associated with that GPIO when it was requested. |
64 | 64 | ||
65 | RT_FULL: GPIO driver should not use spinlock_t or any sleepable APIs | ||
66 | (like PM runtime) in its gpio_chip implementation (.get/.set and direction | ||
67 | control callbacks) if it is expected to call GPIO APIs from atomic context | ||
68 | on -RT (inside hard IRQ handlers and similar contexts). Normally this should | ||
69 | not be required. | ||
65 | 70 | ||
66 | GPIO drivers providing IRQs | 71 | GPIO drivers providing IRQs |
67 | --------------------------- | 72 | --------------------------- |
@@ -73,6 +78,13 @@ 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- | 78 | the header <linux/irq.h>. So basically such a driver is utilizing two sub- |
74 | systems simultaneously: gpio and irq. | 79 | systems simultaneously: gpio and irq. |
75 | 80 | ||
81 | RT_FULL: GPIO driver should not use spinlock_t or any sleepable APIs | ||
82 | (like PM runtime) as part of its irq_chip implementation on -RT. | ||
83 | - spinlock_t should be replaced with raw_spinlock_t [1]. | ||
84 | - If sleepable APIs have to be used, these can be done from the .irq_bus_lock() | ||
85 | and .irq_bus_unlock() callbacks, as these are the only slowpath callbacks | ||
86 | on an irqchip. Create the callbacks if needed [2]. | ||
87 | |||
76 | GPIO irqchips usually fall in one of two categories: | 88 | GPIO irqchips usually fall in one of two categories: |
77 | 89 | ||
78 | * CHAINED GPIO irqchips: these are usually the type that is embedded on | 90 | * CHAINED GPIO irqchips: these are usually the type that is embedded on |
@@ -93,6 +105,38 @@ GPIO irqchips usually fall in one of two categories: | |||
93 | Chained GPIO irqchips typically can NOT set the .can_sleep flag on | 105 | Chained GPIO irqchips typically can NOT set the .can_sleep flag on |
94 | struct gpio_chip, as everything happens directly in the callbacks. | 106 | struct gpio_chip, as everything happens directly in the callbacks. |
95 | 107 | ||
108 | RT_FULL: Note, chained IRQ handlers will not be forced threaded on -RT. | ||
109 | As result, spinlock_t or any sleepable APIs (like PM runtime) can't be used | ||
110 | in chained IRQ handler. | ||
111 | if required (and if it can't be converted to the nested threaded GPIO irqchip) | ||
112 | - chained IRQ handler can be converted to generic irq handler and this way | ||
113 | it will be threaded IRQ handler on -RT and hard IRQ handler on non-RT | ||
114 | (for example, see [3]). | ||
115 | Know W/A: The generic_handle_irq() is expected to be called with IRQ disabled, | ||
116 | so IRQ core will complain if it will be called from IRQ handler wich is forced | ||
117 | thread. The "fake?" raw lock can be used to W/A this problem: | ||
118 | |||
119 | raw_spinlock_t wa_lock; | ||
120 | static irqreturn_t omap_gpio_irq_handler(int irq, void *gpiobank) | ||
121 | unsigned long wa_lock_flags; | ||
122 | raw_spin_lock_irqsave(&bank->wa_lock, wa_lock_flags); | ||
123 | generic_handle_irq(irq_find_mapping(bank->chip.irqdomain, bit)); | ||
124 | raw_spin_unlock_irqrestore(&bank->wa_lock, wa_lock_flags); | ||
125 | |||
126 | * GENERIC CHAINED GPIO irqchips: these are the same as "CHAINED GPIO irqchips", | ||
127 | but chained IRQ handlers are not used. Instead GPIO IRQs dispatching is | ||
128 | performed by generic IRQ handler which is configured using request_irq(). | ||
129 | The GPIO irqchip will then end up calling something like this sequence in | ||
130 | its interrupt handler: | ||
131 | |||
132 | static irqreturn_t gpio_rcar_irq_handler(int irq, void *dev_id) | ||
133 | for each detected GPIO IRQ | ||
134 | generic_handle_irq(...); | ||
135 | |||
136 | RT_FULL: Such kind of handlers will be forced threaded on -RT, as result IRQ | ||
137 | core will complain that generic_handle_irq() is called with IRQ enabled and | ||
138 | the same W/A as for "CHAINED GPIO irqchips" can be applied. | ||
139 | |||
96 | * NESTED THREADED GPIO irqchips: these are off-chip GPIO expanders and any | 140 | * 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 | 141 | 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, | 142 | such drivers that need slow bus traffic to read out IRQ status and similar, |
@@ -133,6 +177,13 @@ To use the helpers please keep the following in mind: | |||
133 | the irqchip can initialize. E.g. .dev and .can_sleep shall be set up | 177 | the irqchip can initialize. E.g. .dev and .can_sleep shall be set up |
134 | properly. | 178 | properly. |
135 | 179 | ||
180 | - Nominally set all handlers to handle_bad_irq() in the setup call and pass | ||
181 | handle_bad_irq() as flow handler parameter in gpiochip_irqchip_add() if it is | ||
182 | expected for GPIO driver that irqchip .set_type() callback have to be called | ||
183 | before using/enabling GPIO IRQ. Then set the handler to handle_level_irq() | ||
184 | and/or handle_edge_irq() in the irqchip .set_type() callback depending on | ||
185 | what your controller supports. | ||
186 | |||
136 | It is legal for any IRQ consumer to request an IRQ from any irqchip no matter | 187 | It is legal for any IRQ consumer to request an IRQ from any irqchip no matter |
137 | if that is a combined GPIO+IRQ driver. The basic premise is that gpio_chip and | 188 | if that is a combined GPIO+IRQ driver. The basic premise is that gpio_chip and |
138 | irq_chip are orthogonal, and offering their services independent of each | 189 | irq_chip are orthogonal, and offering their services independent of each |
@@ -169,6 +220,31 @@ When implementing an irqchip inside a GPIO driver, these two functions should | |||
169 | typically be called in the .startup() and .shutdown() callbacks from the | 220 | typically be called in the .startup() and .shutdown() callbacks from the |
170 | irqchip. | 221 | irqchip. |
171 | 222 | ||
223 | Real-Time compliance for GPIO IRQ chips | ||
224 | --------------------------------------- | ||
225 | |||
226 | Any provider of irqchips needs to be carefully tailored to support Real Time | ||
227 | preemption. It is desireable that all irqchips in the GPIO subsystem keep this | ||
228 | in mind and does the proper testing to assure they are real time-enabled. | ||
229 | So, pay attention on above " RT_FULL:" notes, please. | ||
230 | The following is a checklist to follow when preparing a driver for real | ||
231 | time-compliance: | ||
232 | |||
233 | - ensure spinlock_t is not used as part irq_chip implementation; | ||
234 | - ensure that sleepable APIs are not used as part irq_chip implementation. | ||
235 | If sleepable APIs have to be used, these can be done from the .irq_bus_lock() | ||
236 | and .irq_bus_unlock() callbacks; | ||
237 | - Chained GPIO irqchips: ensure spinlock_t or any sleepable APIs are not used | ||
238 | from chained IRQ handler; | ||
239 | - Generic chained GPIO irqchips: take care about generic_handle_irq() calls and | ||
240 | apply corresponding W/A; | ||
241 | - Chained GPIO irqchips: get rid of chained IRQ handler and use generic irq | ||
242 | handler if possible :) | ||
243 | - regmap_mmio: Sry, but you are in trouble :( if MMIO regmap is used as for | ||
244 | GPIO IRQ chip implementation; | ||
245 | - Test your driver with the appropriate in-kernel real time test cases for both | ||
246 | level and edge IRQs. | ||
247 | |||
172 | 248 | ||
173 | Requesting self-owned GPIO pins | 249 | Requesting self-owned GPIO pins |
174 | ------------------------------- | 250 | ------------------------------- |
@@ -190,3 +266,7 @@ gpiochip_free_own_desc(). | |||
190 | These functions must be used with care since they do not affect module use | 266 | These functions must be used with care since they do not affect module use |
191 | count. Do not use the functions to request gpio descriptors not owned by the | 267 | count. Do not use the functions to request gpio descriptors not owned by the |
192 | calling driver. | 268 | calling driver. |
269 | |||
270 | [1] http://www.spinics.net/lists/linux-omap/msg120425.html | ||
271 | [2] https://lkml.org/lkml/2015/9/25/494 | ||
272 | [3] https://lkml.org/lkml/2015/9/25/495 | ||