uboot-d1: add bootloader for upcoming d1 target
[openwrt/staging/mans0n.git] / package / boot / uboot-d1 / patches / 0048-gpio-axp-Bind-via-device-tree.patch
1 From a39b1bd1ad0babb355a5cb6f6a3bd8e378433b54 Mon Sep 17 00:00:00 2001
2 From: Samuel Holland <samuel@sholland.org>
3 Date: Fri, 27 Aug 2021 21:43:19 -0500
4 Subject: [PATCH 48/90] gpio: axp: Bind via device tree
5
6 Now that the PMIC has a DM driver and binds device tree subnodes, the
7 GPIO device can be bound that way, instead of from inside board code.
8
9 Since the driver still uses the single set of register definitions from
10 axpXXX.h (as selected by AXPxxx_POWER), it does not differentiate among
11 the supported compatibles.
12
13 Signed-off-by: Samuel Holland <samuel@sholland.org>
14 ---
15 arch/arm/include/asm/arch-sunxi/gpio.h | 6 -----
16 arch/arm/mach-sunxi/Kconfig | 6 -----
17 board/sunxi/board.c | 4 ---
18 drivers/gpio/Kconfig | 8 ++++++
19 drivers/gpio/axp_gpio.c | 34 +++++++++++---------------
20 5 files changed, 22 insertions(+), 36 deletions(-)
21
22 --- a/arch/arm/include/asm/arch-sunxi/gpio.h
23 +++ b/arch/arm/include/asm/arch-sunxi/gpio.h
24 @@ -219,10 +219,4 @@ void sunxi_gpio_set_pull(u32 pin, u32 va
25 void sunxi_gpio_set_pull_bank(struct sunxi_gpio *pio, int bank_offset, u32 val);
26 int sunxi_name_to_gpio(const char *name);
27
28 -#if !defined CONFIG_SPL_BUILD && defined CONFIG_AXP_GPIO
29 -int axp_gpio_init(void);
30 -#else
31 -static inline int axp_gpio_init(void) { return 0; }
32 -#endif
33 -
34 #endif /* _SUNXI_GPIO_H */
35 --- a/arch/arm/mach-sunxi/Kconfig
36 +++ b/arch/arm/mach-sunxi/Kconfig
37 @@ -682,12 +682,6 @@ config R_I2C_ENABLE
38 Set this to y to enable the I2C controller which is part of the PRCM.
39 endif
40
41 -config AXP_GPIO
42 - bool "Enable support for gpio-s on axp PMICs"
43 - depends on AXP_PMIC_BUS
44 - ---help---
45 - Say Y here to enable support for the gpio pins of the axp PMIC ICs.
46 -
47 config AXP_DISABLE_BOOT_ON_POWERON
48 bool "Disable device boot on power plug-in"
49 depends on AXP209_POWER || AXP221_POWER || AXP809_POWER || AXP818_POWER
50 --- a/board/sunxi/board.c
51 +++ b/board/sunxi/board.c
52 @@ -221,10 +221,6 @@ int board_init(void)
53 }
54 #endif /* !CONFIG_ARM64 && !CONFIG_MACH_SUNIV */
55
56 - ret = axp_gpio_init();
57 - if (ret)
58 - return ret;
59 -
60 /* strcmp() would look better, but doesn't get optimised away. */
61 if (CONFIG_SATAPWR[0]) {
62 satapwr_pin = sunxi_name_to_gpio(CONFIG_SATAPWR);
63 --- a/drivers/gpio/Kconfig
64 +++ b/drivers/gpio/Kconfig
65 @@ -104,6 +104,14 @@ config ALTERA_PIO
66 Select this to enable PIO for Altera devices. Please find
67 details on the "Embedded Peripherals IP User Guide" of Altera.
68
69 +config AXP_GPIO
70 + bool "X-Powers AXP PMICs GPIO driver"
71 + depends on DM_GPIO && PMIC_AXP
72 + depends on AXP_PMIC_BUS
73 + help
74 + This driver supports the GPIO pins on
75 + X-Powers AXP152, AXP2xx, and AXP8xx PMICs.
76 +
77 config BCM2835_GPIO
78 bool "BCM2835 GPIO driver"
79 depends on DM_GPIO
80 --- a/drivers/gpio/axp_gpio.c
81 +++ b/drivers/gpio/axp_gpio.c
82 @@ -10,9 +10,6 @@
83 #include <asm/gpio.h>
84 #include <axp_pmic.h>
85 #include <dm.h>
86 -#include <dm/device-internal.h>
87 -#include <dm/lists.h>
88 -#include <dm/root.h>
89 #include <errno.h>
90
91 #define AXP_GPIO_PREFIX "AXP0-"
92 @@ -99,6 +96,11 @@ static const struct dm_gpio_ops axp_gpio
93 static int axp_gpio_probe(struct udevice *dev)
94 {
95 struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
96 + int ret;
97 +
98 + ret = pmic_bus_init();
99 + if (ret)
100 + return ret;
101
102 /* Tell the uclass how many GPIOs we have */
103 uc_priv->bank_name = AXP_GPIO_PREFIX;
104 @@ -107,26 +109,18 @@ static int axp_gpio_probe(struct udevice
105 return 0;
106 }
107
108 +static const struct udevice_id axp_gpio_ids[] = {
109 + { .compatible = "x-powers,axp152-gpio" },
110 + { .compatible = "x-powers,axp209-gpio" },
111 + { .compatible = "x-powers,axp221-gpio" },
112 + { .compatible = "x-powers,axp813-gpio" },
113 + { }
114 +};
115 +
116 U_BOOT_DRIVER(axp_gpio) = {
117 .name = "axp_gpio",
118 .id = UCLASS_GPIO,
119 + .of_match = axp_gpio_ids,
120 .probe = axp_gpio_probe,
121 .ops = &axp_gpio_ops,
122 };
123 -
124 -int axp_gpio_init(void)
125 -{
126 - struct udevice *dev;
127 - int ret;
128 -
129 - ret = pmic_bus_init();
130 - if (ret)
131 - return ret;
132 -
133 - /* There is no devicetree support for the axp yet, so bind directly */
134 - ret = device_bind_driver(dm_root(), "axp_gpio", "AXP-gpio", &dev);
135 - if (ret)
136 - return ret;
137 -
138 - return 0;
139 -}