uboot-d1: add bootloader for upcoming d1 target
[openwrt/staging/mans0n.git] / package / boot / uboot-d1 / patches / 0045-phy-sun4i-usb-Use-DM_GPIO-for-id-vbus_det-GPIOs.patch
1 From afa281decfbb174f57341897e0ad50ee9ad3564f Mon Sep 17 00:00:00 2001
2 From: Zoltan HERPAI <wigyori@uid0.hu>
3 Date: Tue, 6 Jun 2023 17:59:24 +0000
4 Subject: [PATCH 45/90] phy: sun4i-usb: Use DM_GPIO for id/vbus_det GPIOs
5
6 Now that the sunxi_gpio driver handles pull-up/down via the driver
7 model, we can switch to DM_GPIO for these pins with no loss in
8 functionality. Since the driver now gets its pin configuration from
9 the device tree, we can remove the Kconfig symbols.
10
11 Signed-off-by: Samuel Holland <samuel@sholland.org>
12
13 Signed-off-by: Zoltan HERPAI <wigyori@uid0.hu>
14 ---
15 arch/arm/dts/sun5i-a13-ampe-a76.dts | 6 ++
16 .../sun6i-a31s-yones-toptech-bs1078-v2.dts | 1 +
17 arch/arm/dts/sun8i-a33-sinlinx-sina33.dts | 1 +
18 arch/arm/mach-sunxi/Kconfig | 14 ----
19 drivers/phy/allwinner/phy-sun4i-usb.c | 71 ++++---------------
20 5 files changed, 22 insertions(+), 71 deletions(-)
21
22 --- a/arch/arm/dts/sun5i-a13-ampe-a76.dts
23 +++ b/arch/arm/dts/sun5i-a13-ampe-a76.dts
24 @@ -8,6 +8,8 @@
25 /dts-v1/;
26 #include "sun5i-a13.dtsi"
27
28 +#include <dt-bindings/gpio/gpio.h>
29 +
30 / {
31 model = "Ampe A76";
32 compatible = "ampe,a76", "allwinner,sun5i-a13";
33 @@ -26,3 +28,7 @@
34 pinctrl-0 = <&uart1_pg_pins>;
35 status = "okay";
36 };
37 +
38 +&usbphy {
39 + usb0_id_det-gpios = <&pio 6 2 GPIO_ACTIVE_HIGH>; /* PG2 */
40 +};
41 --- a/arch/arm/dts/sun6i-a31s-yones-toptech-bs1078-v2.dts
42 +++ b/arch/arm/dts/sun6i-a31s-yones-toptech-bs1078-v2.dts
43 @@ -176,6 +176,7 @@
44 };
45
46 &usbphy {
47 + usb0_id_det-gpios = <&pio 0 15 GPIO_ACTIVE_HIGH>; /* PA15 */
48 usb1_vbus-supply = <&reg_dldo1>;
49 usb2_vbus-supply = <&reg_dc1sw>;
50 status = "okay";
51 --- a/arch/arm/dts/sun8i-a33-sinlinx-sina33.dts
52 +++ b/arch/arm/dts/sun8i-a33-sinlinx-sina33.dts
53 @@ -271,5 +271,6 @@
54
55 &usbphy {
56 status = "okay";
57 + usb0_id_det-gpios = <&pio 7 8 GPIO_ACTIVE_HIGH>; /* PH8 */
58 usb1_vbus-supply = <&reg_vcc5v0>; /* USB1 VBUS is always on */
59 };
60 --- a/arch/arm/mach-sunxi/Kconfig
61 +++ b/arch/arm/mach-sunxi/Kconfig
62 @@ -655,20 +655,6 @@ config MMC_SUNXI_SLOT_EXTRA
63 slot or emmc on mmc1 - mmc3. Setting this to 1, 2 or 3 will enable
64 support for this.
65
66 -config USB0_VBUS_DET
67 - string "Vbus detect pin for usb0 (otg)"
68 - default ""
69 - ---help---
70 - Set the Vbus detect pin for usb0 (otg). This takes a string in the
71 - format understood by sunxi_name_to_gpio, e.g. PH1 for pin 1 of port H.
72 -
73 -config USB0_ID_DET
74 - string "ID detect pin for usb0 (otg)"
75 - default ""
76 - ---help---
77 - Set the ID detect pin for usb0 (otg). This takes a string in the
78 - format understood by sunxi_name_to_gpio, e.g. PH1 for pin 1 of port H.
79 -
80 config I2C0_ENABLE
81 bool "Enable I2C/TWI controller 0"
82 default y if MACH_SUN4I || MACH_SUN5I || MACH_SUN7I || MACH_SUN8I_R40
83 --- a/drivers/phy/allwinner/phy-sun4i-usb.c
84 +++ b/drivers/phy/allwinner/phy-sun4i-usb.c
85 @@ -96,32 +96,8 @@ struct sun4i_usb_phy_cfg {
86 int missing_phys;
87 };
88
89 -struct sun4i_usb_phy_info {
90 - const char *gpio_vbus_det;
91 - const char *gpio_id_det;
92 -} phy_info[] = {
93 - {
94 - .gpio_vbus_det = CONFIG_USB0_VBUS_DET,
95 - .gpio_id_det = CONFIG_USB0_ID_DET,
96 - },
97 - {
98 - .gpio_vbus_det = NULL,
99 - .gpio_id_det = NULL,
100 - },
101 - {
102 - .gpio_vbus_det = NULL,
103 - .gpio_id_det = NULL,
104 - },
105 - {
106 - .gpio_vbus_det = NULL,
107 - .gpio_id_det = NULL,
108 - },
109 -};
110 -
111 struct sun4i_usb_phy_plat {
112 void __iomem *pmu;
113 - struct gpio_desc gpio_vbus_det;
114 - struct gpio_desc gpio_id_det;
115 struct clk clocks;
116 struct reset_ctl resets;
117 struct udevice *vbus;
118 @@ -132,6 +108,8 @@ struct sun4i_usb_phy_data {
119 void __iomem *base;
120 const struct sun4i_usb_phy_cfg *cfg;
121 struct sun4i_usb_phy_plat *usb_phy;
122 + struct gpio_desc id_det_gpio;
123 + struct gpio_desc vbus_det_gpio;
124 struct udevice *vbus_power_supply;
125 };
126
127 @@ -393,11 +371,10 @@ static int sun4i_usb_phy_xlate(struct ph
128 int sun4i_usb_phy_vbus_detect(struct phy *phy)
129 {
130 struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
131 - struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id];
132 int err = 1, retries = 3;
133
134 - if (dm_gpio_is_valid(&usb_phy->gpio_vbus_det)) {
135 - err = dm_gpio_get_value(&usb_phy->gpio_vbus_det);
136 + if (dm_gpio_is_valid(&data->vbus_det_gpio)) {
137 + err = dm_gpio_get_value(&data->vbus_det_gpio);
138 /*
139 * Vbus may have been provided by the board and just turned off
140 * some milliseconds ago on reset. What we're measuring then is
141 @@ -405,7 +382,7 @@ int sun4i_usb_phy_vbus_detect(struct phy
142 */
143 while (err > 0 && retries--) {
144 mdelay(100);
145 - err = dm_gpio_get_value(&usb_phy->gpio_vbus_det);
146 + err = dm_gpio_get_value(&data->vbus_det_gpio);
147 }
148 } else if (data->vbus_power_supply) {
149 err = regulator_get_enable(data->vbus_power_supply);
150 @@ -417,12 +394,11 @@ int sun4i_usb_phy_vbus_detect(struct phy
151 int sun4i_usb_phy_id_detect(struct phy *phy)
152 {
153 struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
154 - struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id];
155
156 - if (!dm_gpio_is_valid(&usb_phy->gpio_id_det))
157 - return -1;
158 + if (!dm_gpio_is_valid(&data->id_det_gpio))
159 + return -EOPNOTSUPP;
160
161 - return dm_gpio_get_value(&usb_phy->gpio_id_det);
162 + return dm_gpio_get_value(&data->id_det_gpio);
163 }
164
165 void sun4i_usb_phy_set_squelch_detect(struct phy *phy, bool enabled)
166 @@ -452,13 +428,18 @@ static int sun4i_usb_phy_probe(struct ud
167 if (IS_ERR(data->base))
168 return PTR_ERR(data->base);
169
170 + gpio_request_by_name(dev, "usb0_id_det-gpios", 0, &data->id_det_gpio,
171 + GPIOD_IS_IN | GPIOD_PULL_UP);
172 +
173 + gpio_request_by_name(dev, "usb0_vbus_det-gpios", 0, &data->vbus_det_gpio,
174 + GPIOD_IS_IN);
175 +
176 device_get_supply_regulator(dev, "usb0_vbus_power-supply",
177 &data->vbus_power_supply);
178
179 data->usb_phy = plat;
180 for (i = 0; i < data->cfg->num_phys; i++) {
181 struct sun4i_usb_phy_plat *phy = &plat[i];
182 - struct sun4i_usb_phy_info *info = &phy_info[i];
183 char name[20];
184
185 if (data->cfg->missing_phys & BIT(i))
186 @@ -472,30 +453,6 @@ static int sun4i_usb_phy_probe(struct ud
187 return ret;
188 }
189
190 - ret = dm_gpio_lookup_name(info->gpio_vbus_det,
191 - &phy->gpio_vbus_det);
192 - if (ret == 0) {
193 - ret = dm_gpio_request(&phy->gpio_vbus_det,
194 - "usb_vbus_det");
195 - if (ret)
196 - return ret;
197 - ret = dm_gpio_set_dir_flags(&phy->gpio_vbus_det,
198 - GPIOD_IS_IN);
199 - if (ret)
200 - return ret;
201 - }
202 -
203 - ret = dm_gpio_lookup_name(info->gpio_id_det, &phy->gpio_id_det);
204 - if (ret == 0) {
205 - ret = dm_gpio_request(&phy->gpio_id_det, "usb_id_det");
206 - if (ret)
207 - return ret;
208 - ret = dm_gpio_set_dir_flags(&phy->gpio_id_det,
209 - GPIOD_IS_IN | GPIOD_PULL_UP);
210 - if (ret)
211 - return ret;
212 - }
213 -
214 if (data->cfg->dedicated_clocks)
215 snprintf(name, sizeof(name), "usb%d_phy", i);
216 else