Documentation: gpio: fix typo and unclear legacy API section

The "Interacting With the Legacy GPIO Subsystem" of the documentation
was unclear at best, and even included a sentence that seems to say the
opposite of what it should say about the lifetime of the return value of
the conversion functions.

Try to clarify things a bit and hopefully make that section more
readable.

Reported-by: Andy Shevchenko <andy.shevchenko@gmail.com>
BugLink: https://stackoverflow.com/q/64455505/2511795
Signed-off-by: Alexandre Courbot <gnurou@gmail.com>
Link: https://lore.kernel.org/r/20201122092548.61979-1-gnurou@gmail.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
This commit is contained in:
Alexandre Courbot 2020-11-22 18:25:48 +09:00 коммит произвёл Linus Walleij
Родитель 105e051f1a
Коммит a0de695819
1 изменённых файлов: 10 добавлений и 8 удалений

Просмотреть файл

@ -440,18 +440,20 @@ For details refer to Documentation/firmware-guide/acpi/gpio-properties.rst
Interacting With the Legacy GPIO Subsystem Interacting With the Legacy GPIO Subsystem
========================================== ==========================================
Many kernel subsystems still handle GPIOs using the legacy integer-based Many kernel subsystems and drivers still handle GPIOs using the legacy
interface. Although it is strongly encouraged to upgrade them to the safer integer-based interface. It is strongly recommended to update these to the new
descriptor-based API, the following two functions allow you to convert a GPIO gpiod interface. For cases where both interfaces need to be used, the following
descriptor into the GPIO integer namespace and vice-versa:: two functions allow to convert a GPIO descriptor into the GPIO integer namespace
and vice-versa::
int desc_to_gpio(const struct gpio_desc *desc) int desc_to_gpio(const struct gpio_desc *desc)
struct gpio_desc *gpio_to_desc(unsigned gpio) struct gpio_desc *gpio_to_desc(unsigned gpio)
The GPIO number returned by desc_to_gpio() can be safely used as long as the The GPIO number returned by desc_to_gpio() can safely be used as a parameter of
GPIO descriptor has not been freed. All the same, a GPIO number passed to the gpio\_*() functions for as long as the GPIO descriptor `desc` is not freed.
gpio_to_desc() must have been properly acquired, and usage of the returned GPIO All the same, a GPIO number passed to gpio_to_desc() must first be properly
descriptor is only possible after the GPIO number has been released. acquired using e.g. gpio_request_one(), and the returned GPIO descriptor is only
considered valid until that GPIO number is released using gpio_free().
Freeing a GPIO obtained by one API with the other API is forbidden and an Freeing a GPIO obtained by one API with the other API is forbidden and an
unchecked error. unchecked error.