OSDN Git Service

gpio: Make it possible for consumers to enforce open drain
authorLinus Walleij <linus.walleij@linaro.org>
Sun, 10 Sep 2017 17:26:22 +0000 (19:26 +0200)
committerLinus Walleij <linus.walleij@linaro.org>
Mon, 30 Oct 2017 07:42:31 +0000 (08:42 +0100)
commitf926dfc112bc6cf41d7068ee5e3f261e13a5bec8
tree07ed8f8beb6804d1623c0686d33335584ba04217
parentb2e63555592f81331c8da3afaa607d8cf83e8138
gpio: Make it possible for consumers to enforce open drain

Some busses, like I2C, strictly need to have the line handled
as open drain, i.e. not actively driven high. For this reason
the i2c-gpio.c bit-banged I2C driver is reimplementing open
drain handling outside of gpiolib.

This is not very optimal. Instead make it possible for a
consumer to explcitly express that the line must be handled
as open drain instead of allowing local hacks papering over
this issue.

The descriptor tables, whether DT, ACPI or board files, should
of course have flagged these lines as open drain. E.g.:
enum gpio_lookup_flags GPIO_OPEN_DRAIN for a board file, or
gpios = <&foo 42 GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN>; in a
device tree using <dt-bindings/gpio/gpio.h>

But more often than not, these descriptors are wrong. So
we need to make it possible for consumers to enforce this
open drain behaviour.

We now have two new enumerated GPIO descriptor config flags:
GPIOD_OUT_LOW_OPEN_DRAIN and GPIOD_OUT_HIGH_OPEN_DRAIN
that will set up the lined enforced as open drain as output
low or high, using open drain (if the driver supports it)
or using open drain emulation (setting the line as input
to drive it high) from the gpiolib core.

Cc: linux-gpio@vger.kernel.org
Tested-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
drivers/gpio/gpiolib.c
include/linux/gpio/consumer.h