2c41dc01275c81a0733bb26ed217fc1cbedb6af1
[openwrt/staging/wigyori.git] / target / linux / brcm2708 / patches-4.19 / 950-0802-regulator-gpio-Allow-nonexclusive-GPIO-access.patch
1 From f6d983b7bc9ae79d0eb4dea7bc30a1ad5ff428a7 Mon Sep 17 00:00:00 2001
2 From: Linus Walleij <linus.walleij@linaro.org>
3 Date: Fri, 12 Oct 2018 14:54:12 +0200
4 Subject: [PATCH 802/806] regulator/gpio: Allow nonexclusive GPIO access
5
6 commit b0ce7b29bfcd090ddba476f45a75ec0a797b048a upstream.
7
8 [ This is a partial cherry-pick, omitting the regulator
9 change which isn't required ]
10
11 This allows nonexclusive (simultaneous) access to a single
12 GPIO line for the fixed regulator enable line. This happens
13 when several regulators use the same GPIO for enabling and
14 disabling a regulator, and all need a handle on their GPIO
15 descriptor.
16
17 This solution with a special flag is not entirely elegant
18 and should ideally be replaced by something more careful as
19 this makes it possible for several consumers to
20 enable/disable the same GPIO line to the left and right
21 without any consistency. The current use inside the regulator
22 core should however be fine as it takes special care to
23 handle this.
24
25 For the state of the GPIO backend, this is still the
26 lesser evil compared to going back to global GPIO
27 numbers.
28
29 Cc: Marek Szyprowski <m.szyprowski@samsung.com>
30 Cc: Jon Hunter <jonathanh@nvidia.com>
31 Fixes: efdfeb079cc3 ("regulator: fixed: Convert to use GPIO descriptor only")
32 Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
33 Tested-by: Jon Hunter <jonathanh@nvidia.com>
34 Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
35 Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
36 Signed-off-by: Mark Brown <broonie@kernel.org>
37 ---
38 drivers/gpio/gpiolib.c | 19 +++++++++++++++++--
39 include/linux/gpio/consumer.h | 1 +
40 2 files changed, 18 insertions(+), 2 deletions(-)
41
42 --- a/drivers/gpio/gpiolib.c
43 +++ b/drivers/gpio/gpiolib.c
44 @@ -3959,8 +3959,23 @@ struct gpio_desc *__must_check gpiod_get
45 * the device name as label
46 */
47 status = gpiod_request(desc, con_id ? con_id : devname);
48 - if (status < 0)
49 - return ERR_PTR(status);
50 + if (status < 0) {
51 + if (status == -EBUSY && flags & GPIOD_FLAGS_BIT_NONEXCLUSIVE) {
52 + /*
53 + * This happens when there are several consumers for
54 + * the same GPIO line: we just return here without
55 + * further initialization. It is a bit if a hack.
56 + * This is necessary to support fixed regulators.
57 + *
58 + * FIXME: Make this more sane and safe.
59 + */
60 + dev_info(dev, "nonexclusive access to GPIO for %s\n",
61 + con_id ? con_id : devname);
62 + return desc;
63 + } else {
64 + return ERR_PTR(status);
65 + }
66 + }
67
68 status = gpiod_configure_flags(desc, con_id, lookupflags, flags);
69 if (status < 0) {
70 --- a/include/linux/gpio/consumer.h
71 +++ b/include/linux/gpio/consumer.h
72 @@ -30,6 +30,7 @@ struct gpio_descs {
73 #define GPIOD_FLAGS_BIT_DIR_OUT BIT(1)
74 #define GPIOD_FLAGS_BIT_DIR_VAL BIT(2)
75 #define GPIOD_FLAGS_BIT_OPEN_DRAIN BIT(3)
76 +#define GPIOD_FLAGS_BIT_NONEXCLUSIVE BIT(4)
77
78 /**
79 * Optional flags that can be passed to one of gpiod_* to configure direction