ramips: fix Tenbay T-MB5EU v1 Wireless MAC
[openwrt/staging/wigyori.git] / target / linux / ramips / patches-5.4 / 111-gpio-mmio-introduce-BGPIOF_NO_SET_ON_INPUT.patch
1 From 5d7b644aad721ecca20bd8976b38fb243fdc84f9 Mon Sep 17 00:00:00 2001
2 From: Chuanhong Guo <gch981213@gmail.com>
3 Date: Sun, 15 Mar 2020 20:13:37 +0800
4 Subject: [PATCH] gpio: mmio: introduce BGPIOF_NO_SET_ON_INPUT
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 Some gpio controllers ignores pin value writing when that pin is
10 configured as input mode. As a result, bgpio_dir_out should set
11 pin to output before configuring pin values or gpio pin values
12 can't be set up properly.
13 Introduce two variants of bgpio_dir_out: bgpio_dir_out_val_first
14 and bgpio_dir_out_dir_first, and assign direction_output according
15 to a new flag: BGPIOF_NO_SET_ON_INPUT.
16
17 Signed-off-by: Chuanhong Guo <gch981213@gmail.com>
18 Tested-by: René van Dorst <opensource@vdorst.com>
19 Reviewed-by: Sergio Paracuellos <sergio.paracuellos@gmail.com>
20 Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
21 ---
22 drivers/gpio/gpio-mmio.c | 23 +++++++++++++++++++----
23 include/linux/gpio/driver.h | 1 +
24 2 files changed, 20 insertions(+), 4 deletions(-)
25
26 --- a/drivers/gpio/gpio-mmio.c
27 +++ b/drivers/gpio/gpio-mmio.c
28 @@ -381,12 +381,10 @@ static int bgpio_get_dir(struct gpio_chi
29 return 1;
30 }
31
32 -static int bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
33 +static void bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
34 {
35 unsigned long flags;
36
37 - gc->set(gc, gpio, val);
38 -
39 spin_lock_irqsave(&gc->bgpio_lock, flags);
40
41 gc->bgpio_dir |= bgpio_line2mask(gc, gpio);
42 @@ -397,7 +395,21 @@ static int bgpio_dir_out(struct gpio_chi
43 gc->write_reg(gc->reg_dir_out, gc->bgpio_dir);
44
45 spin_unlock_irqrestore(&gc->bgpio_lock, flags);
46 +}
47
48 +static int bgpio_dir_out_dir_first(struct gpio_chip *gc, unsigned int gpio,
49 + int val)
50 +{
51 + bgpio_dir_out(gc, gpio, val);
52 + gc->set(gc, gpio, val);
53 + return 0;
54 +}
55 +
56 +static int bgpio_dir_out_val_first(struct gpio_chip *gc, unsigned int gpio,
57 + int val)
58 +{
59 + gc->set(gc, gpio, val);
60 + bgpio_dir_out(gc, gpio, val);
61 return 0;
62 }
63
64 @@ -530,7 +542,10 @@ static int bgpio_setup_direction(struct
65 if (dirout || dirin) {
66 gc->reg_dir_out = dirout;
67 gc->reg_dir_in = dirin;
68 - gc->direction_output = bgpio_dir_out;
69 + if (flags & BGPIOF_NO_SET_ON_INPUT)
70 + gc->direction_output = bgpio_dir_out_dir_first;
71 + else
72 + gc->direction_output = bgpio_dir_out_val_first;
73 gc->direction_input = bgpio_dir_in;
74 gc->get_direction = bgpio_get_dir;
75 } else {
76 --- a/include/linux/gpio/driver.h
77 +++ b/include/linux/gpio/driver.h
78 @@ -567,6 +567,7 @@ int bgpio_init(struct gpio_chip *gc, str
79 #define BGPIOF_BIG_ENDIAN_BYTE_ORDER BIT(3)
80 #define BGPIOF_READ_OUTPUT_REG_SET BIT(4) /* reg_set stores output value */
81 #define BGPIOF_NO_OUTPUT BIT(5) /* only input */
82 +#define BGPIOF_NO_SET_ON_INPUT BIT(6)
83
84 int gpiochip_irq_map(struct irq_domain *d, unsigned int irq,
85 irq_hw_number_t hwirq);