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
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.
11 Signed-off-by: Samuel Holland <samuel@sholland.org>
13 Signed-off-by: Zoltan HERPAI <wigyori@uid0.hu>
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(-)
22 --- a/arch/arm/dts/sun5i-a13-ampe-a76.dts
23 +++ b/arch/arm/dts/sun5i-a13-ampe-a76.dts
26 #include "sun5i-a13.dtsi"
28 +#include <dt-bindings/gpio/gpio.h>
32 compatible = "ampe,a76", "allwinner,sun5i-a13";
34 pinctrl-0 = <&uart1_pg_pins>;
39 + usb0_id_det-gpios = <&pio 6 2 GPIO_ACTIVE_HIGH>; /* PG2 */
41 --- a/arch/arm/dts/sun6i-a31s-yones-toptech-bs1078-v2.dts
42 +++ b/arch/arm/dts/sun6i-a31s-yones-toptech-bs1078-v2.dts
47 + usb0_id_det-gpios = <&pio 0 15 GPIO_ACTIVE_HIGH>; /* PA15 */
48 usb1_vbus-supply = <®_dldo1>;
49 usb2_vbus-supply = <®_dc1sw>;
51 --- a/arch/arm/dts/sun8i-a33-sinlinx-sina33.dts
52 +++ b/arch/arm/dts/sun8i-a33-sinlinx-sina33.dts
57 + usb0_id_det-gpios = <&pio 7 8 GPIO_ACTIVE_HIGH>; /* PH8 */
58 usb1_vbus-supply = <®_vcc5v0>; /* USB1 VBUS is always on */
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
67 - string "Vbus detect pin for usb0 (otg)"
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.
74 - string "ID detect pin for usb0 (otg)"
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.
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 {
89 -struct sun4i_usb_phy_info {
90 - const char *gpio_vbus_det;
91 - const char *gpio_id_det;
94 - .gpio_vbus_det = CONFIG_USB0_VBUS_DET,
95 - .gpio_id_det = CONFIG_USB0_ID_DET,
98 - .gpio_vbus_det = NULL,
99 - .gpio_id_det = NULL,
102 - .gpio_vbus_det = NULL,
103 - .gpio_id_det = NULL,
106 - .gpio_vbus_det = NULL,
107 - .gpio_id_det = NULL,
111 struct sun4i_usb_phy_plat {
113 - struct gpio_desc gpio_vbus_det;
114 - struct gpio_desc gpio_id_det;
116 struct reset_ctl resets;
117 struct udevice *vbus;
118 @@ -132,6 +108,8 @@ struct sun4i_usb_phy_data {
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;
127 @@ -393,11 +371,10 @@ static int sun4i_usb_phy_xlate(struct ph
128 int sun4i_usb_phy_vbus_detect(struct phy *phy)
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;
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);
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
143 while (err > 0 && retries--) {
145 - err = dm_gpio_get_value(&usb_phy->gpio_vbus_det);
146 + err = dm_gpio_get_value(&data->vbus_det_gpio);
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)
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];
156 - if (!dm_gpio_is_valid(&usb_phy->gpio_id_det))
158 + if (!dm_gpio_is_valid(&data->id_det_gpio))
159 + return -EOPNOTSUPP;
161 - return dm_gpio_get_value(&usb_phy->gpio_id_det);
162 + return dm_gpio_get_value(&data->id_det_gpio);
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);
170 + gpio_request_by_name(dev, "usb0_id_det-gpios", 0, &data->id_det_gpio,
171 + GPIOD_IS_IN | GPIOD_PULL_UP);
173 + gpio_request_by_name(dev, "usb0_vbus_det-gpios", 0, &data->vbus_det_gpio,
176 device_get_supply_regulator(dev, "usb0_vbus_power-supply",
177 &data->vbus_power_supply);
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];
185 if (data->cfg->missing_phys & BIT(i))
186 @@ -472,30 +453,6 @@ static int sun4i_usb_phy_probe(struct ud
190 - ret = dm_gpio_lookup_name(info->gpio_vbus_det,
191 - &phy->gpio_vbus_det);
193 - ret = dm_gpio_request(&phy->gpio_vbus_det,
197 - ret = dm_gpio_set_dir_flags(&phy->gpio_vbus_det,
203 - ret = dm_gpio_lookup_name(info->gpio_id_det, &phy->gpio_id_det);
205 - ret = dm_gpio_request(&phy->gpio_id_det, "usb_id_det");
208 - ret = dm_gpio_set_dir_flags(&phy->gpio_id_det,
209 - GPIOD_IS_IN | GPIOD_PULL_UP);
214 if (data->cfg->dedicated_clocks)
215 snprintf(name, sizeof(name), "usb%d_phy", i);