suniv: add new target
[openwrt/staging/wigyori.git] / package / boot / uboot-suniv / patches / 0010-introduce-and-use-sunxi_gpio_setup_dt_pins.patch
1 From 9a0ca4a595f8129904432b67ad1fb7ee815f3d67 Mon Sep 17 00:00:00 2001
2 From: Andre Przywara <andre.przywara@arm.com>
3 Date: Sun, 12 Feb 2017 14:53:16 +0000
4 Subject: [PATCH 10/29] introduce and use sunxi_gpio_setup_dt_pins()
5
6 ---
7 arch/arm/include/asm/arch-sunxi/gpio.h | 3 ++
8 arch/arm/mach-sunxi/pinmux.c | 61 ++++++++++++++++++++++++++
9 2 files changed, 64 insertions(+)
10
11 diff --git a/arch/arm/include/asm/arch-sunxi/gpio.h b/arch/arm/include/asm/arch-sunxi/gpio.h
12 index 43088e2f54..723c553a8c 100644
13 --- a/arch/arm/include/asm/arch-sunxi/gpio.h
14 +++ b/arch/arm/include/asm/arch-sunxi/gpio.h
15 @@ -250,4 +250,7 @@ int axp_gpio_init(void);
16 static inline int axp_gpio_init(void) { return 0; }
17 #endif
18
19 +int sunxi_gpio_setup_dt_pins(const void * volatile fdt_blob, int node,
20 + const char * mux_name, int mux_sel);
21 +
22 #endif /* _SUNXI_GPIO_H */
23 diff --git a/arch/arm/mach-sunxi/pinmux.c b/arch/arm/mach-sunxi/pinmux.c
24 index 642483f06c..6ffba3910b 100644
25 --- a/arch/arm/mach-sunxi/pinmux.c
26 +++ b/arch/arm/mach-sunxi/pinmux.c
27 @@ -8,6 +8,9 @@
28 #include <common.h>
29 #include <asm/io.h>
30 #include <asm/arch/gpio.h>
31 +#include <fdtdec.h>
32 +#include <fdt_support.h>
33 +#include <dt-bindings/pinctrl/sun4i-a10.h>
34
35 void sunxi_gpio_set_cfgbank(struct sunxi_gpio *pio, int bank_offset, u32 val)
36 {
37 @@ -68,3 +71,61 @@ int sunxi_gpio_set_pull(u32 pin, u32 val)
38
39 return 0;
40 }
41 +
42 +int sunxi_gpio_setup_dt_pins(const void * volatile fdt_blob, int node,
43 + const char * mux_name, int mux_sel)
44 +{
45 + int drive, pull, pin, i;
46 + const char *pin_name;
47 + int offset;
48 +
49 + offset = fdtdec_lookup_phandle(fdt_blob, node, "pinctrl-0");
50 + if (offset < 0)
51 + return offset;
52 +
53 + drive = fdt_getprop_u32_default_node(fdt_blob, offset, 0,
54 + "drive-strength", 0);
55 + if (drive) {
56 + if (drive <= 10)
57 + drive = SUN4I_PINCTRL_10_MA;
58 + else if (drive <= 20)
59 + drive = SUN4I_PINCTRL_20_MA;
60 + else if (drive <= 30)
61 + drive = SUN4I_PINCTRL_30_MA;
62 + else
63 + drive = SUN4I_PINCTRL_40_MA;
64 + } else {
65 + drive = fdt_getprop_u32_default_node(fdt_blob, offset, 0,
66 + "allwinner,drive", 4);
67 + }
68 +
69 + if (fdt_get_property(fdt_blob, offset, "bias-pull-up", NULL))
70 + pull = SUN4I_PINCTRL_PULL_UP;
71 + else if (fdt_get_property(fdt_blob, offset, "bias-disable", NULL))
72 + pull = SUN4I_PINCTRL_NO_PULL;
73 + else if (fdt_get_property(fdt_blob, offset, "bias-pull-down", NULL))
74 + pull = SUN4I_PINCTRL_PULL_DOWN;
75 + else
76 + pull = fdt_getprop_u32_default_node(fdt_blob, offset, 0,
77 + "allwinner,pull", 0);
78 +
79 + for (i = 0; ; i++) {
80 + pin_name = fdt_stringlist_get(fdt_blob, offset,
81 + "allwinner,pins", i, NULL);
82 + if (!pin_name) {
83 + pin_name = fdt_stringlist_get(fdt_blob, offset,
84 + "pins", i, NULL);
85 + if (!pin_name)
86 + break;
87 + }
88 + pin = sunxi_name_to_gpio(pin_name);
89 + if (pin < 0)
90 + continue;
91 +
92 + sunxi_gpio_set_cfgpin(pin, mux_sel);
93 + sunxi_gpio_set_drv(pin, drive);
94 + sunxi_gpio_set_pull(pin, pull);
95 + }
96 +
97 + return i;
98 +}
99 --
100 2.20.1
101