diff options
| -rw-r--r-- | Documentation/driver-api/gpio/driver.rst (renamed from Documentation/gpio/driver.txt) | 80 | ||||
| -rw-r--r-- | Documentation/driver-api/gpio/index.rst | 1 | ||||
| -rw-r--r-- | Documentation/gpio/00-INDEX | 2 |
3 files changed, 42 insertions, 41 deletions
diff --git a/Documentation/gpio/driver.txt b/Documentation/driver-api/gpio/driver.rst index 3392a0fd4c23..505ee906d7d9 100644 --- a/Documentation/gpio/driver.txt +++ b/Documentation/driver-api/gpio/driver.rst | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | ================================ | ||
| 1 | GPIO Descriptor Driver Interface | 2 | GPIO Descriptor Driver Interface |
| 2 | ================================ | 3 | ================================ |
| 3 | 4 | ||
| @@ -53,9 +54,9 @@ common to each controller of that type: | |||
| 53 | 54 | ||
| 54 | The code implementing a gpio_chip should support multiple instances of the | 55 | The code implementing a gpio_chip should support multiple instances of the |
| 55 | controller, possibly using the driver model. That code will configure each | 56 | controller, possibly using the driver model. That code will configure each |
| 56 | gpio_chip and issue gpiochip_add[_data]() or devm_gpiochip_add_data(). | 57 | gpio_chip and issue ``gpiochip_add[_data]()`` or ``devm_gpiochip_add_data()``. |
| 57 | Removing a GPIO controller should be rare; use [devm_]gpiochip_remove() when | 58 | Removing a GPIO controller should be rare; use ``[devm_]gpiochip_remove()`` |
| 58 | it is unavoidable. | 59 | when it is unavoidable. |
| 59 | 60 | ||
| 60 | Often a gpio_chip is part of an instance-specific structure with states not | 61 | Often a gpio_chip is part of an instance-specific structure with states not |
| 61 | exposed by the GPIO interfaces, such as addressing, power management, and more. | 62 | exposed by the GPIO interfaces, such as addressing, power management, and more. |
| @@ -115,7 +116,7 @@ GPIOs with open drain/source support | |||
| 115 | 116 | ||
| 116 | Open drain (CMOS) or open collector (TTL) means the line is not actively driven | 117 | Open drain (CMOS) or open collector (TTL) means the line is not actively driven |
| 117 | high: instead you provide the drain/collector as output, so when the transistor | 118 | high: instead you provide the drain/collector as output, so when the transistor |
| 118 | is not open, it will present a high-impedance (tristate) to the external rail. | 119 | is not open, it will present a high-impedance (tristate) to the external rail:: |
| 119 | 120 | ||
| 120 | 121 | ||
| 121 | CMOS CONFIGURATION TTL CONFIGURATION | 122 | CMOS CONFIGURATION TTL CONFIGURATION |
| @@ -148,19 +149,19 @@ level-shift to the higher VDD. | |||
| 148 | Integrated electronics often have an output driver stage in the form of a CMOS | 149 | Integrated electronics often have an output driver stage in the form of a CMOS |
| 149 | "totem-pole" with one N-MOS and one P-MOS transistor where one of them drives | 150 | "totem-pole" with one N-MOS and one P-MOS transistor where one of them drives |
| 150 | the line high and one of them drives the line low. This is called a push-pull | 151 | the line high and one of them drives the line low. This is called a push-pull |
| 151 | output. The "totem-pole" looks like so: | 152 | output. The "totem-pole" looks like so:: |
| 152 | 153 | ||
| 153 | VDD | 154 | VDD |
| 154 | | | 155 | | |
| 155 | OD ||--+ | 156 | OD ||--+ |
| 156 | +--/ ---o|| P-MOS-FET | 157 | +--/ ---o|| P-MOS-FET |
| 157 | | ||--+ | 158 | | ||--+ |
| 158 | IN --+ +----- out | 159 | IN --+ +----- out |
| 159 | | ||--+ | 160 | | ||--+ |
| 160 | +--/ ----|| N-MOS-FET | 161 | +--/ ----|| N-MOS-FET |
| 161 | OS ||--+ | 162 | OS ||--+ |
| 162 | | | 163 | | |
| 163 | GND | 164 | GND |
| 164 | 165 | ||
| 165 | The desired output signal (e.g. coming directly from some GPIO output register) | 166 | The desired output signal (e.g. coming directly from some GPIO output register) |
| 166 | arrives at IN. The switches named "OD" and "OS" are normally closed, creating | 167 | arrives at IN. The switches named "OD" and "OS" are normally closed, creating |
| @@ -219,8 +220,9 @@ systems simultaneously: gpio and irq. | |||
| 219 | 220 | ||
| 220 | RT_FULL: a realtime compliant GPIO driver should not use spinlock_t or any | 221 | RT_FULL: a realtime compliant GPIO driver should not use spinlock_t or any |
| 221 | sleepable APIs (like PM runtime) as part of its irq_chip implementation. | 222 | sleepable APIs (like PM runtime) as part of its irq_chip implementation. |
| 222 | - spinlock_t should be replaced with raw_spinlock_t [1]. | 223 | |
| 223 | - If sleepable APIs have to be used, these can be done from the .irq_bus_lock() | 224 | * spinlock_t should be replaced with raw_spinlock_t [1]. |
| 225 | * If sleepable APIs have to be used, these can be done from the .irq_bus_lock() | ||
| 224 | and .irq_bus_unlock() callbacks, as these are the only slowpath callbacks | 226 | and .irq_bus_unlock() callbacks, as these are the only slowpath callbacks |
| 225 | on an irqchip. Create the callbacks if needed [2]. | 227 | on an irqchip. Create the callbacks if needed [2]. |
| 226 | 228 | ||
| @@ -232,12 +234,12 @@ GPIO irqchips usually fall in one of two categories: | |||
| 232 | system interrupt controller. This means that the GPIO irqchip handler will | 234 | system interrupt controller. This means that the GPIO irqchip handler will |
| 233 | be called immediately from the parent irqchip, while holding the IRQs | 235 | be called immediately from the parent irqchip, while holding the IRQs |
| 234 | disabled. The GPIO irqchip will then end up calling something like this | 236 | disabled. The GPIO irqchip will then end up calling something like this |
| 235 | sequence in its interrupt handler: | 237 | sequence in its interrupt handler:: |
| 236 | 238 | ||
| 237 | static irqreturn_t foo_gpio_irq(int irq, void *data) | 239 | static irqreturn_t foo_gpio_irq(int irq, void *data) |
| 238 | chained_irq_enter(...); | 240 | chained_irq_enter(...); |
| 239 | generic_handle_irq(...); | 241 | generic_handle_irq(...); |
| 240 | chained_irq_exit(...); | 242 | chained_irq_exit(...); |
| 241 | 243 | ||
| 242 | Chained GPIO irqchips typically can NOT set the .can_sleep flag on | 244 | Chained GPIO irqchips typically can NOT set the .can_sleep flag on |
| 243 | struct gpio_chip, as everything happens directly in the callbacks: no | 245 | struct gpio_chip, as everything happens directly in the callbacks: no |
| @@ -252,7 +254,7 @@ GPIO irqchips usually fall in one of two categories: | |||
| 252 | (for example, see [3]). | 254 | (for example, see [3]). |
| 253 | Know W/A: The generic_handle_irq() is expected to be called with IRQ disabled, | 255 | Know W/A: The generic_handle_irq() is expected to be called with IRQ disabled, |
| 254 | so the IRQ core will complain if it is called from an IRQ handler which is | 256 | so the IRQ core will complain if it is called from an IRQ handler which is |
| 255 | forced to a thread. The "fake?" raw lock can be used to W/A this problem: | 257 | forced to a thread. The "fake?" raw lock can be used to W/A this problem:: |
| 256 | 258 | ||
| 257 | raw_spinlock_t wa_lock; | 259 | raw_spinlock_t wa_lock; |
| 258 | static irqreturn_t omap_gpio_irq_handler(int irq, void *gpiobank) | 260 | static irqreturn_t omap_gpio_irq_handler(int irq, void *gpiobank) |
| @@ -265,11 +267,11 @@ GPIO irqchips usually fall in one of two categories: | |||
| 265 | but chained IRQ handlers are not used. Instead GPIO IRQs dispatching is | 267 | but chained IRQ handlers are not used. Instead GPIO IRQs dispatching is |
| 266 | performed by generic IRQ handler which is configured using request_irq(). | 268 | performed by generic IRQ handler which is configured using request_irq(). |
| 267 | The GPIO irqchip will then end up calling something like this sequence in | 269 | The GPIO irqchip will then end up calling something like this sequence in |
| 268 | its interrupt handler: | 270 | its interrupt handler:: |
| 269 | 271 | ||
| 270 | static irqreturn_t gpio_rcar_irq_handler(int irq, void *dev_id) | 272 | static irqreturn_t gpio_rcar_irq_handler(int irq, void *dev_id) |
| 271 | for each detected GPIO IRQ | 273 | for each detected GPIO IRQ |
| 272 | generic_handle_irq(...); | 274 | generic_handle_irq(...); |
| 273 | 275 | ||
| 274 | RT_FULL: Such kind of handlers will be forced threaded on -RT, as result IRQ | 276 | RT_FULL: Such kind of handlers will be forced threaded on -RT, as result IRQ |
| 275 | core will complain that generic_handle_irq() is called with IRQ enabled and | 277 | core will complain that generic_handle_irq() is called with IRQ enabled and |
| @@ -282,11 +284,11 @@ GPIO irqchips usually fall in one of two categories: | |||
| 282 | in a quick IRQ handler with IRQs disabled. Instead they need to spawn a | 284 | in a quick IRQ handler with IRQs disabled. Instead they need to spawn a |
| 283 | thread and then mask the parent IRQ line until the interrupt is handled | 285 | thread and then mask the parent IRQ line until the interrupt is handled |
| 284 | by the driver. The hallmark of this driver is to call something like | 286 | by the driver. The hallmark of this driver is to call something like |
| 285 | this in its interrupt handler: | 287 | this in its interrupt handler:: |
| 286 | 288 | ||
| 287 | static irqreturn_t foo_gpio_irq(int irq, void *data) | 289 | static irqreturn_t foo_gpio_irq(int irq, void *data) |
| 288 | ... | 290 | ... |
| 289 | handle_nested_irq(irq); | 291 | handle_nested_irq(irq); |
| 290 | 292 | ||
| 291 | The hallmark of threaded GPIO irqchips is that they set the .can_sleep | 293 | The hallmark of threaded GPIO irqchips is that they set the .can_sleep |
| 292 | flag on struct gpio_chip to true, indicating that this chip may sleep | 294 | flag on struct gpio_chip to true, indicating that this chip may sleep |
| @@ -359,12 +361,12 @@ below exists. | |||
| 359 | Locking IRQ usage | 361 | Locking IRQ usage |
| 360 | ----------------- | 362 | ----------------- |
| 361 | Input GPIOs can be used as IRQ signals. When this happens, a driver is requested | 363 | Input GPIOs can be used as IRQ signals. When this happens, a driver is requested |
| 362 | to mark the GPIO as being used as an IRQ: | 364 | to mark the GPIO as being used as an IRQ:: |
| 363 | 365 | ||
| 364 | int gpiochip_lock_as_irq(struct gpio_chip *chip, unsigned int offset) | 366 | int gpiochip_lock_as_irq(struct gpio_chip *chip, unsigned int offset) |
| 365 | 367 | ||
| 366 | This will prevent the use of non-irq related GPIO APIs until the GPIO IRQ lock | 368 | This will prevent the use of non-irq related GPIO APIs until the GPIO IRQ lock |
| 367 | is released: | 369 | is released:: |
| 368 | 370 | ||
| 369 | void gpiochip_unlock_as_irq(struct gpio_chip *chip, unsigned int offset) | 371 | void gpiochip_unlock_as_irq(struct gpio_chip *chip, unsigned int offset) |
| 370 | 372 | ||
| @@ -408,7 +410,7 @@ Sometimes it is useful to allow a GPIO chip driver to request its own GPIO | |||
| 408 | descriptors through the gpiolib API. Using gpio_request() for this purpose | 410 | descriptors through the gpiolib API. Using gpio_request() for this purpose |
| 409 | does not help since it pins the module to the kernel forever (it calls | 411 | does not help since it pins the module to the kernel forever (it calls |
| 410 | try_module_get()). A GPIO driver can use the following functions instead | 412 | try_module_get()). A GPIO driver can use the following functions instead |
| 411 | to request and free descriptors without being pinned to the kernel forever. | 413 | to request and free descriptors without being pinned to the kernel forever:: |
| 412 | 414 | ||
| 413 | struct gpio_desc *gpiochip_request_own_desc(struct gpio_desc *desc, | 415 | struct gpio_desc *gpiochip_request_own_desc(struct gpio_desc *desc, |
| 414 | const char *label) | 416 | const char *label) |
| @@ -422,6 +424,6 @@ These functions must be used with care since they do not affect module use | |||
| 422 | count. Do not use the functions to request gpio descriptors not owned by the | 424 | count. Do not use the functions to request gpio descriptors not owned by the |
| 423 | calling driver. | 425 | calling driver. |
| 424 | 426 | ||
| 425 | [1] http://www.spinics.net/lists/linux-omap/msg120425.html | 427 | * [1] http://www.spinics.net/lists/linux-omap/msg120425.html |
| 426 | [2] https://lkml.org/lkml/2015/9/25/494 | 428 | * [2] https://lkml.org/lkml/2015/9/25/494 |
| 427 | [3] https://lkml.org/lkml/2015/9/25/495 | 429 | * [3] https://lkml.org/lkml/2015/9/25/495 |
diff --git a/Documentation/driver-api/gpio/index.rst b/Documentation/driver-api/gpio/index.rst index db47d845f473..e1fbc5408cf6 100644 --- a/Documentation/driver-api/gpio/index.rst +++ b/Documentation/driver-api/gpio/index.rst | |||
| @@ -8,6 +8,7 @@ Contents: | |||
| 8 | :maxdepth: 2 | 8 | :maxdepth: 2 |
| 9 | 9 | ||
| 10 | intro | 10 | intro |
| 11 | driver | ||
| 11 | 12 | ||
| 12 | Core | 13 | Core |
| 13 | ==== | 14 | ==== |
diff --git a/Documentation/gpio/00-INDEX b/Documentation/gpio/00-INDEX index 52fe0fa6c964..06c25fb7604c 100644 --- a/Documentation/gpio/00-INDEX +++ b/Documentation/gpio/00-INDEX | |||
| @@ -2,8 +2,6 @@ | |||
| 2 | - This file | 2 | - This file |
| 3 | consumer.txt | 3 | consumer.txt |
| 4 | - How to obtain and use GPIOs in a driver | 4 | - How to obtain and use GPIOs in a driver |
| 5 | driver.txt | ||
| 6 | - How to write a GPIO driver | ||
| 7 | drivers-on-gpio.txt: | 5 | drivers-on-gpio.txt: |
| 8 | - Drivers in other subsystems that can use GPIO to provide more | 6 | - Drivers in other subsystems that can use GPIO to provide more |
| 9 | complex functionality. | 7 | complex functionality. |
