Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Allwinner sun4i USB PHY driver |
| 3 | * |
| 4 | * Copyright (C) 2017 Jagan Teki <jagan@amarulasolutions.com> |
| 5 | * Copyright (C) 2015 Hans de Goede <hdegoede@redhat.com> |
| 6 | * Copyright (C) 2014 Roman Byshko <rbyshko@gmail.com> |
| 7 | * |
| 8 | * Modelled arch/arm/mach-sunxi/usb_phy.c to compatible with generic-phy. |
| 9 | * |
| 10 | * SPDX-License-Identifier: GPL-2.0+ |
| 11 | */ |
| 12 | |
Jagan Teki | 0dc3333 | 2018-08-06 12:16:39 +0530 | [diff] [blame] | 13 | #include <clk.h> |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 14 | #include <dm.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 15 | #include <log.h> |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 16 | #include <dm/device.h> |
| 17 | #include <generic-phy.h> |
Jagan Teki | 21fc42d | 2018-05-07 13:03:27 +0530 | [diff] [blame] | 18 | #include <phy-sun4i-usb.h> |
Jagan Teki | 0dc3333 | 2018-08-06 12:16:39 +0530 | [diff] [blame] | 19 | #include <reset.h> |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 20 | #include <asm/gpio.h> |
| 21 | #include <asm/io.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 22 | #include <dm/device_compat.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 23 | #include <linux/bitops.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 24 | #include <linux/delay.h> |
Simon Glass | d66c5f7 | 2020-02-03 07:36:15 -0700 | [diff] [blame] | 25 | #include <linux/err.h> |
Samuel Holland | c70137c | 2021-09-12 09:22:42 -0500 | [diff] [blame] | 26 | #include <power/regulator.h> |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 27 | |
| 28 | #define REG_ISCR 0x00 |
| 29 | #define REG_PHYCTL_A10 0x04 |
| 30 | #define REG_PHYBIST 0x08 |
| 31 | #define REG_PHYTUNE 0x0c |
| 32 | #define REG_PHYCTL_A33 0x10 |
| 33 | #define REG_PHY_OTGCTL 0x20 |
Andre Przywara | 8662e7e | 2022-07-14 23:09:21 -0500 | [diff] [blame] | 34 | |
| 35 | #define REG_HCI_PHY_CTL 0x10 |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 36 | |
| 37 | /* Common Control Bits for Both PHYs */ |
| 38 | #define PHY_PLL_BW 0x03 |
| 39 | #define PHY_RES45_CAL_EN 0x0c |
| 40 | |
| 41 | /* Private Control Bits for Each PHY */ |
| 42 | #define PHY_TX_AMPLITUDE_TUNE 0x20 |
| 43 | #define PHY_TX_SLEWRATE_TUNE 0x22 |
| 44 | #define PHY_DISCON_TH_SEL 0x2a |
Jagan Teki | 37671e1 | 2018-05-07 13:03:37 +0530 | [diff] [blame] | 45 | #define PHY_SQUELCH_DETECT 0x3c |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 46 | |
| 47 | #define PHYCTL_DATA BIT(7) |
| 48 | #define OTGCTL_ROUTE_MUSB BIT(0) |
| 49 | |
| 50 | #define PHY_TX_RATE BIT(4) |
| 51 | #define PHY_TX_MAGNITUDE BIT(2) |
| 52 | #define PHY_TX_AMPLITUDE_LEN 5 |
| 53 | |
| 54 | #define PHY_RES45_CAL_DATA BIT(0) |
| 55 | #define PHY_RES45_CAL_LEN 1 |
| 56 | #define PHY_DISCON_TH_LEN 2 |
| 57 | |
| 58 | #define SUNXI_AHB_ICHR8_EN BIT(10) |
| 59 | #define SUNXI_AHB_INCR4_BURST_EN BIT(9) |
| 60 | #define SUNXI_AHB_INCRX_ALIGN_EN BIT(8) |
| 61 | #define SUNXI_ULPI_BYPASS_EN BIT(0) |
| 62 | |
Jagan Teki | 05a7b9f | 2018-05-07 13:03:30 +0530 | [diff] [blame] | 63 | /* A83T specific control bits for PHY0 */ |
| 64 | #define PHY_CTL_VBUSVLDEXT BIT(5) |
| 65 | #define PHY_CTL_SIDDQ BIT(3) |
Andre Przywara | 8662e7e | 2022-07-14 23:09:21 -0500 | [diff] [blame] | 66 | #define PHY_CTL_H3_SIDDQ BIT(1) |
Jagan Teki | 05a7b9f | 2018-05-07 13:03:30 +0530 | [diff] [blame] | 67 | |
| 68 | /* A83T specific control bits for PHY2 HSIC */ |
| 69 | #define SUNXI_EHCI_HS_FORCE BIT(20) |
| 70 | #define SUNXI_HSIC_CONNECT_INT BIT(16) |
| 71 | #define SUNXI_HSIC BIT(1) |
| 72 | |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 73 | #define MAX_PHYS 4 |
| 74 | |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 75 | struct sun4i_usb_phy_cfg { |
| 76 | int num_phys; |
Andre Przywara | b06b90f | 2023-06-12 00:32:38 +0100 | [diff] [blame] | 77 | int hsic_index; |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 78 | u32 disc_thresh; |
Andre Przywara | 8662e7e | 2022-07-14 23:09:21 -0500 | [diff] [blame] | 79 | u32 hci_phy_ctl_clear; |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 80 | u8 phyctl_offset; |
Jagan Teki | 0dc3333 | 2018-08-06 12:16:39 +0530 | [diff] [blame] | 81 | bool dedicated_clocks; |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 82 | bool phy0_dual_route; |
Andre Przywara | b06b90f | 2023-06-12 00:32:38 +0100 | [diff] [blame] | 83 | bool siddq_in_base; |
Andre Przywara | 720f4e4 | 2023-06-12 00:32:39 +0100 | [diff] [blame] | 84 | bool needs_phy2_siddq; |
Andre Przywara | b2f0f31 | 2019-06-23 15:09:49 +0100 | [diff] [blame] | 85 | int missing_phys; |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | struct sun4i_usb_phy_info { |
| 89 | const char *gpio_vbus; |
| 90 | const char *gpio_vbus_det; |
| 91 | const char *gpio_id_det; |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 92 | } phy_info[] = { |
| 93 | { |
| 94 | .gpio_vbus = CONFIG_USB0_VBUS_PIN, |
| 95 | .gpio_vbus_det = CONFIG_USB0_VBUS_DET, |
| 96 | .gpio_id_det = CONFIG_USB0_ID_DET, |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 97 | }, |
| 98 | { |
| 99 | .gpio_vbus = CONFIG_USB1_VBUS_PIN, |
| 100 | .gpio_vbus_det = NULL, |
| 101 | .gpio_id_det = NULL, |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 102 | }, |
| 103 | { |
| 104 | .gpio_vbus = CONFIG_USB2_VBUS_PIN, |
| 105 | .gpio_vbus_det = NULL, |
| 106 | .gpio_id_det = NULL, |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 107 | }, |
| 108 | { |
| 109 | .gpio_vbus = CONFIG_USB3_VBUS_PIN, |
| 110 | .gpio_vbus_det = NULL, |
| 111 | .gpio_id_det = NULL, |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 112 | }, |
| 113 | }; |
| 114 | |
| 115 | struct sun4i_usb_phy_plat { |
| 116 | void __iomem *pmu; |
Andre Przywara | 3331d22 | 2022-06-07 23:36:18 +0100 | [diff] [blame] | 117 | struct gpio_desc gpio_vbus; |
| 118 | struct gpio_desc gpio_vbus_det; |
| 119 | struct gpio_desc gpio_id_det; |
Jagan Teki | 0dc3333 | 2018-08-06 12:16:39 +0530 | [diff] [blame] | 120 | struct clk clocks; |
Andre Przywara | 720f4e4 | 2023-06-12 00:32:39 +0100 | [diff] [blame] | 121 | struct clk clk2; |
Jagan Teki | 0dc3333 | 2018-08-06 12:16:39 +0530 | [diff] [blame] | 122 | struct reset_ctl resets; |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 123 | int id; |
| 124 | }; |
| 125 | |
| 126 | struct sun4i_usb_phy_data { |
| 127 | void __iomem *base; |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 128 | const struct sun4i_usb_phy_cfg *cfg; |
| 129 | struct sun4i_usb_phy_plat *usb_phy; |
Samuel Holland | c70137c | 2021-09-12 09:22:42 -0500 | [diff] [blame] | 130 | struct udevice *vbus_power_supply; |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 131 | }; |
| 132 | |
| 133 | static int initial_usb_scan_delay = CONFIG_INITIAL_USB_SCAN_DELAY; |
| 134 | |
| 135 | static void sun4i_usb_phy_write(struct phy *phy, u32 addr, u32 data, int len) |
| 136 | { |
| 137 | struct sun4i_usb_phy_data *phy_data = dev_get_priv(phy->dev); |
| 138 | struct sun4i_usb_phy_plat *usb_phy = &phy_data->usb_phy[phy->id]; |
| 139 | u32 temp, usbc_bit = BIT(usb_phy->id * 2); |
| 140 | void __iomem *phyctl = phy_data->base + phy_data->cfg->phyctl_offset; |
| 141 | int i; |
| 142 | |
| 143 | if (phy_data->cfg->phyctl_offset == REG_PHYCTL_A33) { |
| 144 | /* SoCs newer than A33 need us to set phyctl to 0 explicitly */ |
| 145 | writel(0, phyctl); |
| 146 | } |
| 147 | |
| 148 | for (i = 0; i < len; i++) { |
| 149 | temp = readl(phyctl); |
| 150 | |
| 151 | /* clear the address portion */ |
| 152 | temp &= ~(0xff << 8); |
| 153 | |
| 154 | /* set the address */ |
| 155 | temp |= ((addr + i) << 8); |
| 156 | writel(temp, phyctl); |
| 157 | |
| 158 | /* set the data bit and clear usbc bit*/ |
| 159 | temp = readb(phyctl); |
| 160 | if (data & 0x1) |
| 161 | temp |= PHYCTL_DATA; |
| 162 | else |
| 163 | temp &= ~PHYCTL_DATA; |
| 164 | temp &= ~usbc_bit; |
| 165 | writeb(temp, phyctl); |
| 166 | |
| 167 | /* pulse usbc_bit */ |
| 168 | temp = readb(phyctl); |
| 169 | temp |= usbc_bit; |
| 170 | writeb(temp, phyctl); |
| 171 | |
| 172 | temp = readb(phyctl); |
| 173 | temp &= ~usbc_bit; |
| 174 | writeb(temp, phyctl); |
| 175 | |
| 176 | data >>= 1; |
| 177 | } |
| 178 | } |
| 179 | |
Jagan Teki | 05a7b9f | 2018-05-07 13:03:30 +0530 | [diff] [blame] | 180 | static void sun4i_usb_phy_passby(struct phy *phy, bool enable) |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 181 | { |
Jagan Teki | 05a7b9f | 2018-05-07 13:03:30 +0530 | [diff] [blame] | 182 | struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev); |
| 183 | struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id]; |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 184 | u32 bits, reg_value; |
| 185 | |
| 186 | if (!usb_phy->pmu) |
| 187 | return; |
| 188 | |
| 189 | bits = SUNXI_AHB_ICHR8_EN | SUNXI_AHB_INCR4_BURST_EN | |
| 190 | SUNXI_AHB_INCRX_ALIGN_EN | SUNXI_ULPI_BYPASS_EN; |
Jagan Teki | 05a7b9f | 2018-05-07 13:03:30 +0530 | [diff] [blame] | 191 | |
| 192 | /* A83T USB2 is HSIC */ |
Andre Przywara | b06b90f | 2023-06-12 00:32:38 +0100 | [diff] [blame] | 193 | if (data->cfg->hsic_index && usb_phy->id == data->cfg->hsic_index) |
Jagan Teki | 05a7b9f | 2018-05-07 13:03:30 +0530 | [diff] [blame] | 194 | bits |= SUNXI_EHCI_HS_FORCE | SUNXI_HSIC_CONNECT_INT | |
| 195 | SUNXI_HSIC; |
| 196 | |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 197 | reg_value = readl(usb_phy->pmu); |
| 198 | |
| 199 | if (enable) |
| 200 | reg_value |= bits; |
| 201 | else |
| 202 | reg_value &= ~bits; |
| 203 | |
| 204 | writel(reg_value, usb_phy->pmu); |
| 205 | } |
| 206 | |
| 207 | static int sun4i_usb_phy_power_on(struct phy *phy) |
| 208 | { |
| 209 | struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev); |
| 210 | struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id]; |
| 211 | |
| 212 | if (initial_usb_scan_delay) { |
| 213 | mdelay(initial_usb_scan_delay); |
| 214 | initial_usb_scan_delay = 0; |
| 215 | } |
| 216 | |
Samuel Holland | ad99149 | 2022-07-14 22:34:53 -0500 | [diff] [blame] | 217 | /* For phy0 only turn on Vbus if we don't have an ext. Vbus */ |
| 218 | if (phy->id == 0 && sun4i_usb_phy_vbus_detect(phy)) { |
| 219 | dev_warn(phy->dev, "External vbus detected, not enabling our own vbus\n"); |
| 220 | return 0; |
| 221 | } |
| 222 | |
Andre Przywara | 3331d22 | 2022-06-07 23:36:18 +0100 | [diff] [blame] | 223 | if (dm_gpio_is_valid(&usb_phy->gpio_vbus)) |
| 224 | dm_gpio_set_value(&usb_phy->gpio_vbus, 1); |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 225 | |
| 226 | return 0; |
| 227 | } |
| 228 | |
| 229 | static int sun4i_usb_phy_power_off(struct phy *phy) |
| 230 | { |
| 231 | struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev); |
| 232 | struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id]; |
| 233 | |
Andre Przywara | 3331d22 | 2022-06-07 23:36:18 +0100 | [diff] [blame] | 234 | if (dm_gpio_is_valid(&usb_phy->gpio_vbus)) |
| 235 | dm_gpio_set_value(&usb_phy->gpio_vbus, 0); |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 236 | |
| 237 | return 0; |
| 238 | } |
| 239 | |
| 240 | static void sun4i_usb_phy0_reroute(struct sun4i_usb_phy_data *data, bool id_det) |
| 241 | { |
| 242 | u32 regval; |
| 243 | |
| 244 | regval = readl(data->base + REG_PHY_OTGCTL); |
| 245 | if (!id_det) { |
| 246 | /* Host mode. Route phy0 to EHCI/OHCI */ |
| 247 | regval &= ~OTGCTL_ROUTE_MUSB; |
| 248 | } else { |
| 249 | /* Peripheral mode. Route phy0 to MUSB */ |
| 250 | regval |= OTGCTL_ROUTE_MUSB; |
| 251 | } |
| 252 | writel(regval, data->base + REG_PHY_OTGCTL); |
| 253 | } |
| 254 | |
| 255 | static int sun4i_usb_phy_init(struct phy *phy) |
| 256 | { |
| 257 | struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev); |
| 258 | struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id]; |
| 259 | u32 val; |
Jagan Teki | 0dc3333 | 2018-08-06 12:16:39 +0530 | [diff] [blame] | 260 | int ret; |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 261 | |
Jagan Teki | 0dc3333 | 2018-08-06 12:16:39 +0530 | [diff] [blame] | 262 | ret = clk_enable(&usb_phy->clocks); |
| 263 | if (ret) { |
Sean Anderson | e4d3c97 | 2020-09-15 10:45:04 -0400 | [diff] [blame] | 264 | dev_err(phy->dev, "failed to enable usb_%ldphy clock\n", |
| 265 | phy->id); |
Jagan Teki | 0dc3333 | 2018-08-06 12:16:39 +0530 | [diff] [blame] | 266 | return ret; |
| 267 | } |
| 268 | |
| 269 | ret = reset_deassert(&usb_phy->resets); |
| 270 | if (ret) { |
Sean Anderson | e4d3c97 | 2020-09-15 10:45:04 -0400 | [diff] [blame] | 271 | dev_err(phy->dev, "failed to deassert usb_%ldreset reset\n", |
| 272 | phy->id); |
Jagan Teki | 0dc3333 | 2018-08-06 12:16:39 +0530 | [diff] [blame] | 273 | return ret; |
| 274 | } |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 275 | |
Andre Przywara | 720f4e4 | 2023-06-12 00:32:39 +0100 | [diff] [blame] | 276 | /* Some PHYs on some SoCs (the H616) need the help of PHY2 to work. */ |
| 277 | if (data->cfg->needs_phy2_siddq && phy->id != 2) { |
| 278 | struct sun4i_usb_phy_plat *phy2 = &data->usb_phy[2]; |
| 279 | |
| 280 | ret = clk_enable(&phy2->clocks); |
| 281 | if (ret) { |
| 282 | dev_err(phy->dev, "failed to enable aux clock\n"); |
| 283 | return ret; |
| 284 | } |
| 285 | |
| 286 | ret = reset_deassert(&phy2->resets); |
| 287 | if (ret) { |
| 288 | dev_err(phy->dev, "failed to deassert aux reset\n"); |
| 289 | return ret; |
| 290 | } |
| 291 | |
| 292 | /* |
| 293 | * This extra clock is just needed to access the |
| 294 | * REG_HCI_PHY_CTL PMU register for PHY2. |
| 295 | */ |
| 296 | ret = clk_enable(&phy2->clk2); |
| 297 | if (ret) { |
| 298 | dev_err(phy->dev, "failed to enable PHY2 clock\n"); |
| 299 | return ret; |
| 300 | } |
| 301 | |
| 302 | if (phy2->pmu && data->cfg->hci_phy_ctl_clear) { |
| 303 | val = readl(phy2->pmu + REG_HCI_PHY_CTL); |
| 304 | val &= ~data->cfg->hci_phy_ctl_clear; |
| 305 | writel(val, phy2->pmu + REG_HCI_PHY_CTL); |
| 306 | } |
| 307 | |
| 308 | clk_disable(&phy2->clk2); |
| 309 | } |
| 310 | |
Andre Przywara | 8662e7e | 2022-07-14 23:09:21 -0500 | [diff] [blame] | 311 | if (usb_phy->pmu && data->cfg->hci_phy_ctl_clear) { |
| 312 | val = readl(usb_phy->pmu + REG_HCI_PHY_CTL); |
| 313 | val &= ~data->cfg->hci_phy_ctl_clear; |
| 314 | writel(val, usb_phy->pmu + REG_HCI_PHY_CTL); |
| 315 | } |
| 316 | |
Andre Przywara | b06b90f | 2023-06-12 00:32:38 +0100 | [diff] [blame] | 317 | if (data->cfg->siddq_in_base) { |
Jagan Teki | 05a7b9f | 2018-05-07 13:03:30 +0530 | [diff] [blame] | 318 | if (phy->id == 0) { |
| 319 | val = readl(data->base + data->cfg->phyctl_offset); |
| 320 | val |= PHY_CTL_VBUSVLDEXT; |
| 321 | val &= ~PHY_CTL_SIDDQ; |
| 322 | writel(val, data->base + data->cfg->phyctl_offset); |
| 323 | } |
| 324 | } else { |
Jagan Teki | 05a7b9f | 2018-05-07 13:03:30 +0530 | [diff] [blame] | 325 | if (usb_phy->id == 0) |
| 326 | sun4i_usb_phy_write(phy, PHY_RES45_CAL_EN, |
| 327 | PHY_RES45_CAL_DATA, |
| 328 | PHY_RES45_CAL_LEN); |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 329 | |
Jagan Teki | 05a7b9f | 2018-05-07 13:03:30 +0530 | [diff] [blame] | 330 | /* Adjust PHY's magnitude and rate */ |
| 331 | sun4i_usb_phy_write(phy, PHY_TX_AMPLITUDE_TUNE, |
| 332 | PHY_TX_MAGNITUDE | PHY_TX_RATE, |
| 333 | PHY_TX_AMPLITUDE_LEN); |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 334 | |
Jagan Teki | 05a7b9f | 2018-05-07 13:03:30 +0530 | [diff] [blame] | 335 | /* Disconnect threshold adjustment */ |
| 336 | sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL, |
| 337 | data->cfg->disc_thresh, PHY_DISCON_TH_LEN); |
| 338 | } |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 339 | |
Paul Kocialkowski | 2ee0637 | 2019-03-14 10:38:00 +0000 | [diff] [blame] | 340 | #ifdef CONFIG_USB_MUSB_SUNXI |
| 341 | /* Needed for HCI and conflicts with MUSB, keep PHY0 on MUSB */ |
| 342 | if (usb_phy->id != 0) |
| 343 | sun4i_usb_phy_passby(phy, true); |
| 344 | |
| 345 | /* Route PHY0 to MUSB to allow USB gadget */ |
| 346 | if (data->cfg->phy0_dual_route) |
| 347 | sun4i_usb_phy0_reroute(data, true); |
| 348 | #else |
Jagan Teki | b8cbf9d | 2018-07-20 12:34:20 +0530 | [diff] [blame] | 349 | sun4i_usb_phy_passby(phy, true); |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 350 | |
Paul Kocialkowski | 2ee0637 | 2019-03-14 10:38:00 +0000 | [diff] [blame] | 351 | /* Route PHY0 to HCI to allow USB host */ |
| 352 | if (data->cfg->phy0_dual_route) |
| 353 | sun4i_usb_phy0_reroute(data, false); |
| 354 | #endif |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 355 | |
| 356 | return 0; |
| 357 | } |
| 358 | |
| 359 | static int sun4i_usb_phy_exit(struct phy *phy) |
| 360 | { |
| 361 | struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev); |
| 362 | struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id]; |
Jagan Teki | 0dc3333 | 2018-08-06 12:16:39 +0530 | [diff] [blame] | 363 | int ret; |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 364 | |
Jagan Teki | 05a7b9f | 2018-05-07 13:03:30 +0530 | [diff] [blame] | 365 | if (phy->id == 0) { |
Andre Przywara | b06b90f | 2023-06-12 00:32:38 +0100 | [diff] [blame] | 366 | if (data->cfg->siddq_in_base) { |
Jagan Teki | 05a7b9f | 2018-05-07 13:03:30 +0530 | [diff] [blame] | 367 | void __iomem *phyctl = data->base + |
| 368 | data->cfg->phyctl_offset; |
| 369 | |
| 370 | writel(readl(phyctl) | PHY_CTL_SIDDQ, phyctl); |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | sun4i_usb_phy_passby(phy, false); |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 375 | |
Jagan Teki | 0dc3333 | 2018-08-06 12:16:39 +0530 | [diff] [blame] | 376 | ret = clk_disable(&usb_phy->clocks); |
| 377 | if (ret) { |
Sean Anderson | e4d3c97 | 2020-09-15 10:45:04 -0400 | [diff] [blame] | 378 | dev_err(phy->dev, "failed to disable usb_%ldphy clock\n", |
| 379 | phy->id); |
Jagan Teki | 0dc3333 | 2018-08-06 12:16:39 +0530 | [diff] [blame] | 380 | return ret; |
| 381 | } |
| 382 | |
| 383 | ret = reset_assert(&usb_phy->resets); |
| 384 | if (ret) { |
Sean Anderson | e4d3c97 | 2020-09-15 10:45:04 -0400 | [diff] [blame] | 385 | dev_err(phy->dev, "failed to assert usb_%ldreset reset\n", |
| 386 | phy->id); |
Jagan Teki | 0dc3333 | 2018-08-06 12:16:39 +0530 | [diff] [blame] | 387 | return ret; |
| 388 | } |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 389 | |
| 390 | return 0; |
| 391 | } |
| 392 | |
| 393 | static int sun4i_usb_phy_xlate(struct phy *phy, |
| 394 | struct ofnode_phandle_args *args) |
| 395 | { |
| 396 | struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev); |
| 397 | |
Andre Przywara | 6c53de5 | 2023-06-12 00:32:35 +0100 | [diff] [blame] | 398 | if (args->args_count != 1) |
| 399 | return -EINVAL; |
| 400 | |
| 401 | if (args->args[0] >= data->cfg->num_phys) |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 402 | return -EINVAL; |
| 403 | |
Andre Przywara | b2f0f31 | 2019-06-23 15:09:49 +0100 | [diff] [blame] | 404 | if (data->cfg->missing_phys & BIT(args->args[0])) |
| 405 | return -ENODEV; |
| 406 | |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 407 | if (args->args_count) |
| 408 | phy->id = args->args[0]; |
| 409 | else |
| 410 | phy->id = 0; |
| 411 | |
| 412 | debug("%s: phy_id = %ld\n", __func__, phy->id); |
| 413 | return 0; |
| 414 | } |
| 415 | |
Jagan Teki | 21fc42d | 2018-05-07 13:03:27 +0530 | [diff] [blame] | 416 | int sun4i_usb_phy_vbus_detect(struct phy *phy) |
| 417 | { |
| 418 | struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev); |
| 419 | struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id]; |
Samuel Holland | f42dbdf | 2021-09-12 09:22:41 -0500 | [diff] [blame] | 420 | int err = 1, retries = 3; |
Jagan Teki | 21fc42d | 2018-05-07 13:03:27 +0530 | [diff] [blame] | 421 | |
Andre Przywara | 3331d22 | 2022-06-07 23:36:18 +0100 | [diff] [blame] | 422 | if (dm_gpio_is_valid(&usb_phy->gpio_vbus_det)) { |
| 423 | err = dm_gpio_get_value(&usb_phy->gpio_vbus_det); |
Samuel Holland | f42dbdf | 2021-09-12 09:22:41 -0500 | [diff] [blame] | 424 | /* |
| 425 | * Vbus may have been provided by the board and just turned off |
| 426 | * some milliseconds ago on reset. What we're measuring then is |
| 427 | * a residual charge on Vbus. Sleep a bit and try again. |
| 428 | */ |
| 429 | while (err > 0 && retries--) { |
| 430 | mdelay(100); |
Andre Przywara | 3331d22 | 2022-06-07 23:36:18 +0100 | [diff] [blame] | 431 | err = dm_gpio_get_value(&usb_phy->gpio_vbus_det); |
Samuel Holland | f42dbdf | 2021-09-12 09:22:41 -0500 | [diff] [blame] | 432 | } |
Samuel Holland | c70137c | 2021-09-12 09:22:42 -0500 | [diff] [blame] | 433 | } else if (data->vbus_power_supply) { |
| 434 | err = regulator_get_enable(data->vbus_power_supply); |
Jagan Teki | 21fc42d | 2018-05-07 13:03:27 +0530 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | return err; |
| 438 | } |
| 439 | |
| 440 | int sun4i_usb_phy_id_detect(struct phy *phy) |
| 441 | { |
| 442 | struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev); |
| 443 | struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id]; |
| 444 | |
Andre Przywara | 3331d22 | 2022-06-07 23:36:18 +0100 | [diff] [blame] | 445 | if (!dm_gpio_is_valid(&usb_phy->gpio_id_det)) |
| 446 | return -1; |
Jagan Teki | 21fc42d | 2018-05-07 13:03:27 +0530 | [diff] [blame] | 447 | |
Andre Przywara | 3331d22 | 2022-06-07 23:36:18 +0100 | [diff] [blame] | 448 | return dm_gpio_get_value(&usb_phy->gpio_id_det); |
Jagan Teki | 21fc42d | 2018-05-07 13:03:27 +0530 | [diff] [blame] | 449 | } |
| 450 | |
Jagan Teki | 37671e1 | 2018-05-07 13:03:37 +0530 | [diff] [blame] | 451 | void sun4i_usb_phy_set_squelch_detect(struct phy *phy, bool enabled) |
| 452 | { |
| 453 | sun4i_usb_phy_write(phy, PHY_SQUELCH_DETECT, enabled ? 0 : 2, 2); |
| 454 | } |
| 455 | |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 456 | static struct phy_ops sun4i_usb_phy_ops = { |
| 457 | .of_xlate = sun4i_usb_phy_xlate, |
| 458 | .init = sun4i_usb_phy_init, |
| 459 | .power_on = sun4i_usb_phy_power_on, |
| 460 | .power_off = sun4i_usb_phy_power_off, |
| 461 | .exit = sun4i_usb_phy_exit, |
| 462 | }; |
| 463 | |
| 464 | static int sun4i_usb_phy_probe(struct udevice *dev) |
| 465 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 466 | struct sun4i_usb_phy_plat *plat = dev_get_plat(dev); |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 467 | struct sun4i_usb_phy_data *data = dev_get_priv(dev); |
| 468 | int i, ret; |
| 469 | |
| 470 | data->cfg = (const struct sun4i_usb_phy_cfg *)dev_get_driver_data(dev); |
| 471 | if (!data->cfg) |
| 472 | return -EINVAL; |
| 473 | |
Matthias Schiffer | 4733193 | 2023-09-27 15:33:34 +0200 | [diff] [blame] | 474 | data->base = (void __iomem *)dev_read_addr_name_ptr(dev, "phy_ctrl"); |
| 475 | if (!data->base) |
| 476 | return -EINVAL; |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 477 | |
Samuel Holland | c70137c | 2021-09-12 09:22:42 -0500 | [diff] [blame] | 478 | device_get_supply_regulator(dev, "usb0_vbus_power-supply", |
| 479 | &data->vbus_power_supply); |
| 480 | |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 481 | data->usb_phy = plat; |
| 482 | for (i = 0; i < data->cfg->num_phys; i++) { |
| 483 | struct sun4i_usb_phy_plat *phy = &plat[i]; |
| 484 | struct sun4i_usb_phy_info *info = &phy_info[i]; |
| 485 | char name[16]; |
| 486 | |
Andre Przywara | b2f0f31 | 2019-06-23 15:09:49 +0100 | [diff] [blame] | 487 | if (data->cfg->missing_phys & BIT(i)) |
| 488 | continue; |
| 489 | |
Andre Przywara | 3331d22 | 2022-06-07 23:36:18 +0100 | [diff] [blame] | 490 | ret = dm_gpio_lookup_name(info->gpio_vbus, &phy->gpio_vbus); |
| 491 | if (ret == 0) { |
| 492 | ret = dm_gpio_request(&phy->gpio_vbus, "usb_vbus"); |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 493 | if (ret) |
| 494 | return ret; |
Andre Przywara | 3331d22 | 2022-06-07 23:36:18 +0100 | [diff] [blame] | 495 | ret = dm_gpio_set_dir_flags(&phy->gpio_vbus, |
| 496 | GPIOD_IS_OUT); |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 497 | if (ret) |
| 498 | return ret; |
Andre Przywara | 3331d22 | 2022-06-07 23:36:18 +0100 | [diff] [blame] | 499 | ret = dm_gpio_set_value(&phy->gpio_vbus, 0); |
| 500 | if (ret) |
| 501 | return ret; |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 502 | } |
| 503 | |
Andre Przywara | 3331d22 | 2022-06-07 23:36:18 +0100 | [diff] [blame] | 504 | ret = dm_gpio_lookup_name(info->gpio_vbus_det, |
| 505 | &phy->gpio_vbus_det); |
| 506 | if (ret == 0) { |
| 507 | ret = dm_gpio_request(&phy->gpio_vbus_det, |
| 508 | "usb_vbus_det"); |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 509 | if (ret) |
| 510 | return ret; |
Andre Przywara | 3331d22 | 2022-06-07 23:36:18 +0100 | [diff] [blame] | 511 | ret = dm_gpio_set_dir_flags(&phy->gpio_vbus_det, |
| 512 | GPIOD_IS_IN); |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 513 | if (ret) |
| 514 | return ret; |
| 515 | } |
| 516 | |
Andre Przywara | 3331d22 | 2022-06-07 23:36:18 +0100 | [diff] [blame] | 517 | ret = dm_gpio_lookup_name(info->gpio_id_det, &phy->gpio_id_det); |
| 518 | if (ret == 0) { |
| 519 | ret = dm_gpio_request(&phy->gpio_id_det, "usb_id_det"); |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 520 | if (ret) |
| 521 | return ret; |
Andre Przywara | 3331d22 | 2022-06-07 23:36:18 +0100 | [diff] [blame] | 522 | ret = dm_gpio_set_dir_flags(&phy->gpio_id_det, |
| 523 | GPIOD_IS_IN | GPIOD_PULL_UP); |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 524 | if (ret) |
| 525 | return ret; |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 526 | } |
| 527 | |
Jagan Teki | 0dc3333 | 2018-08-06 12:16:39 +0530 | [diff] [blame] | 528 | if (data->cfg->dedicated_clocks) |
| 529 | snprintf(name, sizeof(name), "usb%d_phy", i); |
| 530 | else |
| 531 | strlcpy(name, "usb_phy", sizeof(name)); |
| 532 | |
| 533 | ret = clk_get_by_name(dev, name, &phy->clocks); |
| 534 | if (ret) { |
| 535 | dev_err(dev, "failed to get usb%d_phy clock phandle\n", i); |
| 536 | return ret; |
| 537 | } |
| 538 | |
Andre Przywara | 720f4e4 | 2023-06-12 00:32:39 +0100 | [diff] [blame] | 539 | /* Helper clock from PHY2 for the H616 PHY quirk */ |
| 540 | snprintf(name, sizeof(name), "pmu%d_clk", i); |
| 541 | ret = clk_get_by_name_optional(dev, name, &phy->clk2); |
| 542 | if (ret) { |
| 543 | dev_err(dev, "failed to get pmu%d_clk clock phandle\n", |
| 544 | i); |
| 545 | return ret; |
| 546 | } |
| 547 | |
Jagan Teki | 0dc3333 | 2018-08-06 12:16:39 +0530 | [diff] [blame] | 548 | snprintf(name, sizeof(name), "usb%d_reset", i); |
| 549 | ret = reset_get_by_name(dev, name, &phy->resets); |
| 550 | if (ret) { |
| 551 | dev_err(dev, "failed to get usb%d_reset reset phandle\n", i); |
| 552 | return ret; |
| 553 | } |
| 554 | |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 555 | if (i || data->cfg->phy0_dual_route) { |
| 556 | snprintf(name, sizeof(name), "pmu%d", i); |
Matthias Schiffer | 4733193 | 2023-09-27 15:33:34 +0200 | [diff] [blame] | 557 | phy->pmu = (void __iomem *)dev_read_addr_name_ptr(dev, name); |
| 558 | if (!phy->pmu) |
| 559 | return -EINVAL; |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | phy->id = i; |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 563 | }; |
| 564 | |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 565 | debug("Allwinner Sun4I USB PHY driver loaded\n"); |
| 566 | return 0; |
| 567 | } |
| 568 | |
Jagan Teki | 5a3000f | 2018-05-07 13:03:31 +0530 | [diff] [blame] | 569 | static const struct sun4i_usb_phy_cfg sun4i_a10_cfg = { |
| 570 | .num_phys = 3, |
Jagan Teki | 5a3000f | 2018-05-07 13:03:31 +0530 | [diff] [blame] | 571 | .disc_thresh = 3, |
| 572 | .phyctl_offset = REG_PHYCTL_A10, |
Jagan Teki | 0dc3333 | 2018-08-06 12:16:39 +0530 | [diff] [blame] | 573 | .dedicated_clocks = false, |
Jagan Teki | 5a3000f | 2018-05-07 13:03:31 +0530 | [diff] [blame] | 574 | }; |
| 575 | |
| 576 | static const struct sun4i_usb_phy_cfg sun5i_a13_cfg = { |
| 577 | .num_phys = 2, |
Jagan Teki | 5a3000f | 2018-05-07 13:03:31 +0530 | [diff] [blame] | 578 | .disc_thresh = 2, |
| 579 | .phyctl_offset = REG_PHYCTL_A10, |
Jagan Teki | 0dc3333 | 2018-08-06 12:16:39 +0530 | [diff] [blame] | 580 | .dedicated_clocks = false, |
Jagan Teki | 5a3000f | 2018-05-07 13:03:31 +0530 | [diff] [blame] | 581 | }; |
| 582 | |
Jagan Teki | 1cbc80c | 2018-05-07 13:03:32 +0530 | [diff] [blame] | 583 | static const struct sun4i_usb_phy_cfg sun6i_a31_cfg = { |
| 584 | .num_phys = 3, |
Jagan Teki | 1cbc80c | 2018-05-07 13:03:32 +0530 | [diff] [blame] | 585 | .disc_thresh = 3, |
| 586 | .phyctl_offset = REG_PHYCTL_A10, |
Jagan Teki | 0dc3333 | 2018-08-06 12:16:39 +0530 | [diff] [blame] | 587 | .dedicated_clocks = true, |
Jagan Teki | 1cbc80c | 2018-05-07 13:03:32 +0530 | [diff] [blame] | 588 | }; |
| 589 | |
Jagan Teki | 5a3000f | 2018-05-07 13:03:31 +0530 | [diff] [blame] | 590 | static const struct sun4i_usb_phy_cfg sun7i_a20_cfg = { |
| 591 | .num_phys = 3, |
Jagan Teki | 5a3000f | 2018-05-07 13:03:31 +0530 | [diff] [blame] | 592 | .disc_thresh = 2, |
| 593 | .phyctl_offset = REG_PHYCTL_A10, |
Jagan Teki | 0dc3333 | 2018-08-06 12:16:39 +0530 | [diff] [blame] | 594 | .dedicated_clocks = false, |
Jagan Teki | 5a3000f | 2018-05-07 13:03:31 +0530 | [diff] [blame] | 595 | }; |
| 596 | |
Jagan Teki | 00f9f6b | 2018-05-07 13:03:34 +0530 | [diff] [blame] | 597 | static const struct sun4i_usb_phy_cfg sun8i_a23_cfg = { |
| 598 | .num_phys = 2, |
Jagan Teki | 00f9f6b | 2018-05-07 13:03:34 +0530 | [diff] [blame] | 599 | .disc_thresh = 3, |
| 600 | .phyctl_offset = REG_PHYCTL_A10, |
Jagan Teki | 0dc3333 | 2018-08-06 12:16:39 +0530 | [diff] [blame] | 601 | .dedicated_clocks = true, |
Jagan Teki | 00f9f6b | 2018-05-07 13:03:34 +0530 | [diff] [blame] | 602 | }; |
| 603 | |
Jagan Teki | 0e574bb | 2018-05-07 13:03:33 +0530 | [diff] [blame] | 604 | static const struct sun4i_usb_phy_cfg sun8i_a33_cfg = { |
| 605 | .num_phys = 2, |
Jagan Teki | 0e574bb | 2018-05-07 13:03:33 +0530 | [diff] [blame] | 606 | .disc_thresh = 3, |
| 607 | .phyctl_offset = REG_PHYCTL_A33, |
Jagan Teki | 0dc3333 | 2018-08-06 12:16:39 +0530 | [diff] [blame] | 608 | .dedicated_clocks = true, |
Jagan Teki | 0e574bb | 2018-05-07 13:03:33 +0530 | [diff] [blame] | 609 | }; |
| 610 | |
Jagan Teki | 05a7b9f | 2018-05-07 13:03:30 +0530 | [diff] [blame] | 611 | static const struct sun4i_usb_phy_cfg sun8i_a83t_cfg = { |
| 612 | .num_phys = 3, |
Andre Przywara | b06b90f | 2023-06-12 00:32:38 +0100 | [diff] [blame] | 613 | .hsic_index = 2, |
Jagan Teki | 05a7b9f | 2018-05-07 13:03:30 +0530 | [diff] [blame] | 614 | .phyctl_offset = REG_PHYCTL_A33, |
Jagan Teki | 0dc3333 | 2018-08-06 12:16:39 +0530 | [diff] [blame] | 615 | .dedicated_clocks = true, |
Andre Przywara | b06b90f | 2023-06-12 00:32:38 +0100 | [diff] [blame] | 616 | .siddq_in_base = true, |
Jagan Teki | 05a7b9f | 2018-05-07 13:03:30 +0530 | [diff] [blame] | 617 | }; |
| 618 | |
Jagan Teki | c1b0e5a | 2018-05-07 13:03:28 +0530 | [diff] [blame] | 619 | static const struct sun4i_usb_phy_cfg sun8i_h3_cfg = { |
| 620 | .num_phys = 4, |
Jagan Teki | c1b0e5a | 2018-05-07 13:03:28 +0530 | [diff] [blame] | 621 | .disc_thresh = 3, |
| 622 | .phyctl_offset = REG_PHYCTL_A33, |
Jagan Teki | 0dc3333 | 2018-08-06 12:16:39 +0530 | [diff] [blame] | 623 | .dedicated_clocks = true, |
Andre Przywara | 8662e7e | 2022-07-14 23:09:21 -0500 | [diff] [blame] | 624 | .hci_phy_ctl_clear = PHY_CTL_H3_SIDDQ, |
Jagan Teki | c1b0e5a | 2018-05-07 13:03:28 +0530 | [diff] [blame] | 625 | .phy0_dual_route = true, |
| 626 | }; |
| 627 | |
Andre Przywara | 47d4997 | 2020-01-01 23:44:48 +0000 | [diff] [blame] | 628 | static const struct sun4i_usb_phy_cfg sun8i_r40_cfg = { |
| 629 | .num_phys = 3, |
Andre Przywara | 47d4997 | 2020-01-01 23:44:48 +0000 | [diff] [blame] | 630 | .disc_thresh = 3, |
| 631 | .phyctl_offset = REG_PHYCTL_A33, |
| 632 | .dedicated_clocks = true, |
Andre Przywara | 8662e7e | 2022-07-14 23:09:21 -0500 | [diff] [blame] | 633 | .hci_phy_ctl_clear = PHY_CTL_H3_SIDDQ, |
Andre Przywara | 47d4997 | 2020-01-01 23:44:48 +0000 | [diff] [blame] | 634 | .phy0_dual_route = true, |
| 635 | }; |
| 636 | |
Jagan Teki | ac4bab4 | 2018-05-07 13:03:29 +0530 | [diff] [blame] | 637 | static const struct sun4i_usb_phy_cfg sun8i_v3s_cfg = { |
| 638 | .num_phys = 1, |
Jagan Teki | ac4bab4 | 2018-05-07 13:03:29 +0530 | [diff] [blame] | 639 | .disc_thresh = 3, |
| 640 | .phyctl_offset = REG_PHYCTL_A33, |
Jagan Teki | 0dc3333 | 2018-08-06 12:16:39 +0530 | [diff] [blame] | 641 | .dedicated_clocks = true, |
Andre Przywara | 8662e7e | 2022-07-14 23:09:21 -0500 | [diff] [blame] | 642 | .hci_phy_ctl_clear = PHY_CTL_H3_SIDDQ, |
Jagan Teki | ac4bab4 | 2018-05-07 13:03:29 +0530 | [diff] [blame] | 643 | .phy0_dual_route = true, |
| 644 | }; |
| 645 | |
Samuel Holland | 9f30cce | 2022-07-14 23:09:22 -0500 | [diff] [blame] | 646 | static const struct sun4i_usb_phy_cfg sun20i_d1_cfg = { |
| 647 | .num_phys = 2, |
Samuel Holland | 9f30cce | 2022-07-14 23:09:22 -0500 | [diff] [blame] | 648 | .phyctl_offset = REG_PHYCTL_A33, |
| 649 | .dedicated_clocks = true, |
| 650 | .hci_phy_ctl_clear = PHY_CTL_SIDDQ, |
| 651 | .phy0_dual_route = true, |
Andre Przywara | b06b90f | 2023-06-12 00:32:38 +0100 | [diff] [blame] | 652 | .siddq_in_base = true, |
Samuel Holland | 9f30cce | 2022-07-14 23:09:22 -0500 | [diff] [blame] | 653 | }; |
| 654 | |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 655 | static const struct sun4i_usb_phy_cfg sun50i_a64_cfg = { |
| 656 | .num_phys = 2, |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 657 | .disc_thresh = 3, |
| 658 | .phyctl_offset = REG_PHYCTL_A33, |
Jagan Teki | 0dc3333 | 2018-08-06 12:16:39 +0530 | [diff] [blame] | 659 | .dedicated_clocks = true, |
Andre Przywara | 8662e7e | 2022-07-14 23:09:21 -0500 | [diff] [blame] | 660 | .hci_phy_ctl_clear = PHY_CTL_H3_SIDDQ, |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 661 | .phy0_dual_route = true, |
Andre Przywara | b2f0f31 | 2019-06-23 15:09:49 +0100 | [diff] [blame] | 662 | }; |
| 663 | |
| 664 | static const struct sun4i_usb_phy_cfg sun50i_h6_cfg = { |
| 665 | .num_phys = 4, |
Andre Przywara | b2f0f31 | 2019-06-23 15:09:49 +0100 | [diff] [blame] | 666 | .disc_thresh = 3, |
| 667 | .phyctl_offset = REG_PHYCTL_A33, |
| 668 | .dedicated_clocks = true, |
Andre Przywara | b2f0f31 | 2019-06-23 15:09:49 +0100 | [diff] [blame] | 669 | .phy0_dual_route = true, |
Andre Przywara | b06b90f | 2023-06-12 00:32:38 +0100 | [diff] [blame] | 670 | .siddq_in_base = true, |
Andre Przywara | b2f0f31 | 2019-06-23 15:09:49 +0100 | [diff] [blame] | 671 | .missing_phys = BIT(1) | BIT(2), |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 672 | }; |
| 673 | |
Andre Przywara | 8a3292a | 2023-06-12 00:32:40 +0100 | [diff] [blame] | 674 | static const struct sun4i_usb_phy_cfg sun50i_h616_cfg = { |
| 675 | .num_phys = 4, |
| 676 | .disc_thresh = 3, |
| 677 | .phyctl_offset = REG_PHYCTL_A33, |
| 678 | .dedicated_clocks = true, |
| 679 | .phy0_dual_route = true, |
| 680 | .hci_phy_ctl_clear = PHY_CTL_SIDDQ, |
| 681 | .needs_phy2_siddq = true, |
| 682 | .siddq_in_base = true, |
| 683 | }; |
| 684 | |
Andre Przywara | ab81b0f | 2023-06-12 00:32:36 +0100 | [diff] [blame] | 685 | static const struct sun4i_usb_phy_cfg suniv_f1c100s_cfg = { |
| 686 | .num_phys = 1, |
Andre Przywara | ab81b0f | 2023-06-12 00:32:36 +0100 | [diff] [blame] | 687 | .disc_thresh = 3, |
| 688 | .phyctl_offset = REG_PHYCTL_A10, |
| 689 | .dedicated_clocks = true, |
| 690 | }; |
| 691 | |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 692 | static const struct udevice_id sun4i_usb_phy_ids[] = { |
Jagan Teki | 5a3000f | 2018-05-07 13:03:31 +0530 | [diff] [blame] | 693 | { .compatible = "allwinner,sun4i-a10-usb-phy", .data = (ulong)&sun4i_a10_cfg }, |
| 694 | { .compatible = "allwinner,sun5i-a13-usb-phy", .data = (ulong)&sun5i_a13_cfg }, |
Jagan Teki | 1cbc80c | 2018-05-07 13:03:32 +0530 | [diff] [blame] | 695 | { .compatible = "allwinner,sun6i-a31-usb-phy", .data = (ulong)&sun6i_a31_cfg }, |
Jagan Teki | 5a3000f | 2018-05-07 13:03:31 +0530 | [diff] [blame] | 696 | { .compatible = "allwinner,sun7i-a20-usb-phy", .data = (ulong)&sun7i_a20_cfg }, |
Jagan Teki | 00f9f6b | 2018-05-07 13:03:34 +0530 | [diff] [blame] | 697 | { .compatible = "allwinner,sun8i-a23-usb-phy", .data = (ulong)&sun8i_a23_cfg }, |
Jagan Teki | 0e574bb | 2018-05-07 13:03:33 +0530 | [diff] [blame] | 698 | { .compatible = "allwinner,sun8i-a33-usb-phy", .data = (ulong)&sun8i_a33_cfg }, |
Jagan Teki | 05a7b9f | 2018-05-07 13:03:30 +0530 | [diff] [blame] | 699 | { .compatible = "allwinner,sun8i-a83t-usb-phy", .data = (ulong)&sun8i_a83t_cfg }, |
Jagan Teki | c1b0e5a | 2018-05-07 13:03:28 +0530 | [diff] [blame] | 700 | { .compatible = "allwinner,sun8i-h3-usb-phy", .data = (ulong)&sun8i_h3_cfg }, |
Andre Przywara | 47d4997 | 2020-01-01 23:44:48 +0000 | [diff] [blame] | 701 | { .compatible = "allwinner,sun8i-r40-usb-phy", .data = (ulong)&sun8i_r40_cfg }, |
Jagan Teki | ac4bab4 | 2018-05-07 13:03:29 +0530 | [diff] [blame] | 702 | { .compatible = "allwinner,sun8i-v3s-usb-phy", .data = (ulong)&sun8i_v3s_cfg }, |
Samuel Holland | 9f30cce | 2022-07-14 23:09:22 -0500 | [diff] [blame] | 703 | { .compatible = "allwinner,sun20i-d1-usb-phy", .data = (ulong)&sun20i_d1_cfg }, |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 704 | { .compatible = "allwinner,sun50i-a64-usb-phy", .data = (ulong)&sun50i_a64_cfg}, |
Andre Przywara | b2f0f31 | 2019-06-23 15:09:49 +0100 | [diff] [blame] | 705 | { .compatible = "allwinner,sun50i-h6-usb-phy", .data = (ulong)&sun50i_h6_cfg}, |
Andre Przywara | 8a3292a | 2023-06-12 00:32:40 +0100 | [diff] [blame] | 706 | { .compatible = "allwinner,sun50i-h616-usb-phy", .data = (ulong)&sun50i_h616_cfg }, |
Andre Przywara | ab81b0f | 2023-06-12 00:32:36 +0100 | [diff] [blame] | 707 | { .compatible = "allwinner,suniv-f1c100s-usb-phy", .data = (ulong)&suniv_f1c100s_cfg }, |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 708 | { } |
| 709 | }; |
| 710 | |
| 711 | U_BOOT_DRIVER(sun4i_usb_phy) = { |
| 712 | .name = "sun4i_usb_phy", |
| 713 | .id = UCLASS_PHY, |
| 714 | .of_match = sun4i_usb_phy_ids, |
| 715 | .ops = &sun4i_usb_phy_ops, |
| 716 | .probe = sun4i_usb_phy_probe, |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 717 | .plat_auto = sizeof(struct sun4i_usb_phy_plat[MAX_PHYS]), |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 718 | .priv_auto = sizeof(struct sun4i_usb_phy_data), |
Jagan Teki | d3c3828 | 2018-05-07 13:03:26 +0530 | [diff] [blame] | 719 | }; |