Jagan Teki | 70e882f | 2020-05-26 11:33:44 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | /* |
| 3 | * Rockchip USB2.0 PHY with Innosilicon IP block driver |
| 4 | * |
| 5 | * Copyright (C) 2016 Fuzhou Rockchip Electronics Co., Ltd |
| 6 | * Copyright (C) 2020 Amarula Solutions(India) |
| 7 | */ |
| 8 | |
| 9 | #include <common.h> |
Xavier Drudis Ferran | c3dd061 | 2023-06-05 17:05:53 +0200 | [diff] [blame] | 10 | #include <clk-uclass.h> |
Jagan Teki | 70e882f | 2020-05-26 11:33:44 +0800 | [diff] [blame] | 11 | #include <dm.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 12 | #include <asm/global_data.h> |
Jagan Teki | 70e882f | 2020-05-26 11:33:44 +0800 | [diff] [blame] | 13 | #include <dm/device_compat.h> |
Xavier Drudis Ferran | c3dd061 | 2023-06-05 17:05:53 +0200 | [diff] [blame] | 14 | #include <dm/device-internal.h> |
Jagan Teki | 70e882f | 2020-05-26 11:33:44 +0800 | [diff] [blame] | 15 | #include <dm/lists.h> |
| 16 | #include <generic-phy.h> |
| 17 | #include <reset.h> |
| 18 | #include <syscon.h> |
| 19 | #include <asm/gpio.h> |
| 20 | #include <asm/io.h> |
| 21 | #include <linux/iopoll.h> |
| 22 | #include <asm/arch-rockchip/clock.h> |
| 23 | |
| 24 | DECLARE_GLOBAL_DATA_PTR; |
| 25 | |
| 26 | #define usleep_range(a, b) udelay((b)) |
| 27 | #define BIT_WRITEABLE_SHIFT 16 |
| 28 | |
| 29 | enum rockchip_usb2phy_port_id { |
| 30 | USB2PHY_PORT_OTG, |
| 31 | USB2PHY_PORT_HOST, |
| 32 | USB2PHY_NUM_PORTS, |
| 33 | }; |
| 34 | |
| 35 | struct usb2phy_reg { |
| 36 | unsigned int offset; |
| 37 | unsigned int bitend; |
| 38 | unsigned int bitstart; |
| 39 | unsigned int disable; |
| 40 | unsigned int enable; |
| 41 | }; |
| 42 | |
| 43 | struct rockchip_usb2phy_port_cfg { |
| 44 | struct usb2phy_reg phy_sus; |
| 45 | struct usb2phy_reg bvalid_det_en; |
| 46 | struct usb2phy_reg bvalid_det_st; |
| 47 | struct usb2phy_reg bvalid_det_clr; |
| 48 | struct usb2phy_reg ls_det_en; |
| 49 | struct usb2phy_reg ls_det_st; |
| 50 | struct usb2phy_reg ls_det_clr; |
| 51 | struct usb2phy_reg utmi_avalid; |
| 52 | struct usb2phy_reg utmi_bvalid; |
| 53 | struct usb2phy_reg utmi_ls; |
| 54 | struct usb2phy_reg utmi_hstdet; |
| 55 | }; |
| 56 | |
| 57 | struct rockchip_usb2phy_cfg { |
| 58 | unsigned int reg; |
Xavier Drudis Ferran | 1ef4777 | 2023-06-05 17:06:57 +0200 | [diff] [blame] | 59 | struct usb2phy_reg clkout_ctl; |
Jagan Teki | 70e882f | 2020-05-26 11:33:44 +0800 | [diff] [blame] | 60 | const struct rockchip_usb2phy_port_cfg port_cfgs[USB2PHY_NUM_PORTS]; |
| 61 | }; |
| 62 | |
| 63 | struct rockchip_usb2phy { |
| 64 | void *reg_base; |
| 65 | struct clk phyclk; |
| 66 | const struct rockchip_usb2phy_cfg *phy_cfg; |
| 67 | }; |
| 68 | |
| 69 | static inline int property_enable(void *reg_base, |
| 70 | const struct usb2phy_reg *reg, bool en) |
| 71 | { |
| 72 | unsigned int val, mask, tmp; |
| 73 | |
| 74 | tmp = en ? reg->enable : reg->disable; |
| 75 | mask = GENMASK(reg->bitend, reg->bitstart); |
| 76 | val = (tmp << reg->bitstart) | (mask << BIT_WRITEABLE_SHIFT); |
| 77 | |
| 78 | return writel(val, reg_base + reg->offset); |
| 79 | } |
| 80 | |
Xavier Drudis Ferran | 1ef4777 | 2023-06-05 17:06:57 +0200 | [diff] [blame] | 81 | static inline bool property_enabled(void *reg_base, |
| 82 | const struct usb2phy_reg *reg) |
| 83 | { |
| 84 | unsigned int tmp, orig; |
| 85 | unsigned int mask = GENMASK(reg->bitend, reg->bitstart); |
| 86 | |
| 87 | orig = readl(reg_base + reg->offset); |
| 88 | |
| 89 | tmp = (orig & mask) >> reg->bitstart; |
| 90 | return tmp != reg->disable; |
| 91 | } |
| 92 | |
Jagan Teki | 70e882f | 2020-05-26 11:33:44 +0800 | [diff] [blame] | 93 | static const |
| 94 | struct rockchip_usb2phy_port_cfg *us2phy_get_port(struct phy *phy) |
| 95 | { |
| 96 | struct udevice *parent = dev_get_parent(phy->dev); |
| 97 | struct rockchip_usb2phy *priv = dev_get_priv(parent); |
| 98 | const struct rockchip_usb2phy_cfg *phy_cfg = priv->phy_cfg; |
| 99 | |
| 100 | return &phy_cfg->port_cfgs[phy->id]; |
| 101 | } |
| 102 | |
| 103 | static int rockchip_usb2phy_power_on(struct phy *phy) |
| 104 | { |
| 105 | struct udevice *parent = dev_get_parent(phy->dev); |
| 106 | struct rockchip_usb2phy *priv = dev_get_priv(parent); |
| 107 | const struct rockchip_usb2phy_port_cfg *port_cfg = us2phy_get_port(phy); |
| 108 | |
| 109 | property_enable(priv->reg_base, &port_cfg->phy_sus, false); |
| 110 | |
| 111 | /* waiting for the utmi_clk to become stable */ |
| 112 | usleep_range(1500, 2000); |
| 113 | |
| 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | static int rockchip_usb2phy_power_off(struct phy *phy) |
| 118 | { |
| 119 | struct udevice *parent = dev_get_parent(phy->dev); |
| 120 | struct rockchip_usb2phy *priv = dev_get_priv(parent); |
| 121 | const struct rockchip_usb2phy_port_cfg *port_cfg = us2phy_get_port(phy); |
| 122 | |
| 123 | property_enable(priv->reg_base, &port_cfg->phy_sus, true); |
| 124 | |
| 125 | return 0; |
| 126 | } |
| 127 | |
| 128 | static int rockchip_usb2phy_init(struct phy *phy) |
| 129 | { |
| 130 | struct udevice *parent = dev_get_parent(phy->dev); |
| 131 | struct rockchip_usb2phy *priv = dev_get_priv(parent); |
| 132 | const struct rockchip_usb2phy_port_cfg *port_cfg = us2phy_get_port(phy); |
| 133 | int ret; |
| 134 | |
| 135 | ret = clk_enable(&priv->phyclk); |
John Keeping | 86cd834 | 2022-12-06 12:48:55 +0000 | [diff] [blame] | 136 | if (ret && ret != -ENOSYS) { |
Jagan Teki | 70e882f | 2020-05-26 11:33:44 +0800 | [diff] [blame] | 137 | dev_err(phy->dev, "failed to enable phyclk (ret=%d)\n", ret); |
| 138 | return ret; |
| 139 | } |
| 140 | |
| 141 | if (phy->id == USB2PHY_PORT_OTG) { |
| 142 | property_enable(priv->reg_base, &port_cfg->bvalid_det_clr, true); |
| 143 | property_enable(priv->reg_base, &port_cfg->bvalid_det_en, true); |
| 144 | } else if (phy->id == USB2PHY_PORT_HOST) { |
| 145 | property_enable(priv->reg_base, &port_cfg->bvalid_det_clr, true); |
| 146 | property_enable(priv->reg_base, &port_cfg->bvalid_det_en, true); |
| 147 | } |
| 148 | |
| 149 | return 0; |
| 150 | } |
| 151 | |
| 152 | static int rockchip_usb2phy_exit(struct phy *phy) |
| 153 | { |
| 154 | struct udevice *parent = dev_get_parent(phy->dev); |
| 155 | struct rockchip_usb2phy *priv = dev_get_priv(parent); |
| 156 | |
| 157 | clk_disable(&priv->phyclk); |
| 158 | |
| 159 | return 0; |
| 160 | } |
| 161 | |
| 162 | static int rockchip_usb2phy_of_xlate(struct phy *phy, |
| 163 | struct ofnode_phandle_args *args) |
| 164 | { |
| 165 | const char *name = phy->dev->name; |
| 166 | |
| 167 | if (!strcasecmp(name, "host-port")) |
| 168 | phy->id = USB2PHY_PORT_HOST; |
| 169 | else if (!strcasecmp(name, "otg-port")) |
| 170 | phy->id = USB2PHY_PORT_OTG; |
| 171 | else |
| 172 | dev_err(phy->dev, "improper %s device\n", name); |
| 173 | |
| 174 | return 0; |
| 175 | } |
| 176 | |
| 177 | static struct phy_ops rockchip_usb2phy_ops = { |
| 178 | .init = rockchip_usb2phy_init, |
| 179 | .exit = rockchip_usb2phy_exit, |
| 180 | .power_on = rockchip_usb2phy_power_on, |
| 181 | .power_off = rockchip_usb2phy_power_off, |
| 182 | .of_xlate = rockchip_usb2phy_of_xlate, |
| 183 | }; |
| 184 | |
Xavier Drudis Ferran | 1ef4777 | 2023-06-05 17:06:57 +0200 | [diff] [blame] | 185 | /** |
| 186 | * round_rate() - Adjust a rate to the exact rate a clock can provide. |
| 187 | * @clk: The clock to manipulate. |
| 188 | * @rate: Desidered clock rate in Hz. |
| 189 | * |
| 190 | * Return: rounded rate in Hz, or -ve error code. |
| 191 | */ |
| 192 | ulong rockchip_usb2phy_clk_round_rate(struct clk *clk, ulong rate) |
| 193 | { |
| 194 | return 480000000; |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * enable() - Enable a clock. |
| 199 | * @clk: The clock to manipulate. |
| 200 | * |
| 201 | * Return: zero on success, or -ve error code. |
| 202 | */ |
| 203 | int rockchip_usb2phy_clk_enable(struct clk *clk) |
| 204 | { |
| 205 | struct udevice *parent = dev_get_parent(clk->dev); |
| 206 | struct rockchip_usb2phy *priv = dev_get_priv(parent); |
| 207 | const struct rockchip_usb2phy_cfg *phy_cfg = priv->phy_cfg; |
| 208 | |
| 209 | /* turn on 480m clk output if it is off */ |
| 210 | if (!property_enabled(priv->reg_base, &phy_cfg->clkout_ctl)) { |
| 211 | property_enable(priv->reg_base, &phy_cfg->clkout_ctl, true); |
| 212 | |
| 213 | /* waiting for the clk become stable */ |
| 214 | usleep_range(1200, 1300); |
| 215 | } |
| 216 | |
| 217 | return 0; |
| 218 | } |
| 219 | |
| 220 | /** |
| 221 | * disable() - Disable a clock. |
| 222 | * @clk: The clock to manipulate. |
| 223 | * |
| 224 | * Return: zero on success, or -ve error code. |
| 225 | */ |
| 226 | int rockchip_usb2phy_clk_disable(struct clk *clk) |
| 227 | { |
| 228 | struct udevice *parent = dev_get_parent(clk->dev); |
| 229 | struct rockchip_usb2phy *priv = dev_get_priv(parent); |
| 230 | const struct rockchip_usb2phy_cfg *phy_cfg = priv->phy_cfg; |
| 231 | |
| 232 | /* turn off 480m clk output */ |
| 233 | property_enable(priv->reg_base, &phy_cfg->clkout_ctl, false); |
| 234 | |
| 235 | return 0; |
| 236 | } |
| 237 | |
Xavier Drudis Ferran | c3dd061 | 2023-06-05 17:05:53 +0200 | [diff] [blame] | 238 | static struct clk_ops rockchip_usb2phy_clk_ops = { |
Xavier Drudis Ferran | 1ef4777 | 2023-06-05 17:06:57 +0200 | [diff] [blame] | 239 | .enable = rockchip_usb2phy_clk_enable, |
| 240 | .disable = rockchip_usb2phy_clk_disable, |
| 241 | .round_rate = rockchip_usb2phy_clk_round_rate |
Xavier Drudis Ferran | c3dd061 | 2023-06-05 17:05:53 +0200 | [diff] [blame] | 242 | }; |
| 243 | |
Jagan Teki | 70e882f | 2020-05-26 11:33:44 +0800 | [diff] [blame] | 244 | static int rockchip_usb2phy_probe(struct udevice *dev) |
| 245 | { |
| 246 | struct rockchip_usb2phy *priv = dev_get_priv(dev); |
| 247 | const struct rockchip_usb2phy_cfg *phy_cfgs; |
| 248 | unsigned int reg; |
| 249 | int index, ret; |
| 250 | |
| 251 | priv->reg_base = syscon_get_first_range(ROCKCHIP_SYSCON_GRF); |
| 252 | if (IS_ERR(priv->reg_base)) |
| 253 | return PTR_ERR(priv->reg_base); |
| 254 | |
Jagan Teki | 1b79951 | 2023-02-17 17:28:39 +0530 | [diff] [blame] | 255 | ret = ofnode_read_u32_index(dev_ofnode(dev), "reg", 0, ®); |
Jagan Teki | 70e882f | 2020-05-26 11:33:44 +0800 | [diff] [blame] | 256 | if (ret) { |
| 257 | dev_err(dev, "failed to read reg property (ret = %d)\n", ret); |
| 258 | return ret; |
| 259 | } |
| 260 | |
Jagan Teki | 1b79951 | 2023-02-17 17:28:39 +0530 | [diff] [blame] | 261 | /* support address_cells=2 */ |
Eugen Hristev | 2712516 | 2023-05-22 11:39:58 +0300 | [diff] [blame] | 262 | if (dev_read_addr_cells(dev) == 2 && reg == 0) { |
Jagan Teki | 1b79951 | 2023-02-17 17:28:39 +0530 | [diff] [blame] | 263 | if (ofnode_read_u32_index(dev_ofnode(dev), "reg", 1, ®)) { |
| 264 | dev_err(dev, "%s must have reg[1]\n", |
| 265 | ofnode_get_name(dev_ofnode(dev))); |
| 266 | return -EINVAL; |
| 267 | } |
| 268 | } |
| 269 | |
Jagan Teki | 70e882f | 2020-05-26 11:33:44 +0800 | [diff] [blame] | 270 | phy_cfgs = (const struct rockchip_usb2phy_cfg *) |
| 271 | dev_get_driver_data(dev); |
| 272 | if (!phy_cfgs) |
| 273 | return -EINVAL; |
| 274 | |
| 275 | /* find out a proper config which can be matched with dt. */ |
| 276 | index = 0; |
Eugen Hristev | 3364226 | 2023-05-15 12:59:49 +0300 | [diff] [blame] | 277 | do { |
Jagan Teki | 70e882f | 2020-05-26 11:33:44 +0800 | [diff] [blame] | 278 | if (phy_cfgs[index].reg == reg) { |
| 279 | priv->phy_cfg = &phy_cfgs[index]; |
| 280 | break; |
| 281 | } |
| 282 | |
| 283 | ++index; |
Eugen Hristev | 3364226 | 2023-05-15 12:59:49 +0300 | [diff] [blame] | 284 | } while (phy_cfgs[index].reg); |
Jagan Teki | 70e882f | 2020-05-26 11:33:44 +0800 | [diff] [blame] | 285 | |
| 286 | if (!priv->phy_cfg) { |
| 287 | dev_err(dev, "failed find proper phy-cfg\n"); |
| 288 | return -EINVAL; |
| 289 | } |
| 290 | |
| 291 | ret = clk_get_by_name(dev, "phyclk", &priv->phyclk); |
| 292 | if (ret) { |
| 293 | dev_err(dev, "failed to get the phyclk (ret=%d)\n", ret); |
| 294 | return ret; |
| 295 | } |
| 296 | |
| 297 | return 0; |
| 298 | } |
| 299 | |
| 300 | static int rockchip_usb2phy_bind(struct udevice *dev) |
| 301 | { |
| 302 | struct udevice *usb2phy_dev; |
| 303 | ofnode node; |
| 304 | const char *name; |
| 305 | int ret = 0; |
| 306 | |
| 307 | dev_for_each_subnode(node, dev) { |
| 308 | if (!ofnode_valid(node)) { |
| 309 | dev_info(dev, "subnode %s not found\n", dev->name); |
Xavier Drudis Ferran | c3dd061 | 2023-06-05 17:05:53 +0200 | [diff] [blame] | 310 | ret = -ENXIO; |
| 311 | goto bind_fail; |
Jagan Teki | 70e882f | 2020-05-26 11:33:44 +0800 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | name = ofnode_get_name(node); |
| 315 | dev_dbg(dev, "subnode %s\n", name); |
| 316 | |
| 317 | ret = device_bind_driver_to_node(dev, "rockchip_usb2phy_port", |
| 318 | name, node, &usb2phy_dev); |
| 319 | if (ret) { |
| 320 | dev_err(dev, |
| 321 | "'%s' cannot bind 'rockchip_usb2phy_port'\n", name); |
Xavier Drudis Ferran | c3dd061 | 2023-06-05 17:05:53 +0200 | [diff] [blame] | 322 | goto bind_fail; |
Jagan Teki | 70e882f | 2020-05-26 11:33:44 +0800 | [diff] [blame] | 323 | } |
| 324 | } |
| 325 | |
Xavier Drudis Ferran | c3dd061 | 2023-06-05 17:05:53 +0200 | [diff] [blame] | 326 | node = dev_ofnode(dev); |
Xavier Drudis Ferran | 1ef4777 | 2023-06-05 17:06:57 +0200 | [diff] [blame] | 327 | name = "clk_usbphy_480m"; |
| 328 | dev_read_string_index(dev, "clock-output-names", 0, &name); |
| 329 | |
| 330 | dev_dbg(dev, "clk %s for node %s\n", name, ofnode_get_name(node)); |
| 331 | |
Xavier Drudis Ferran | c3dd061 | 2023-06-05 17:05:53 +0200 | [diff] [blame] | 332 | ret = device_bind_driver_to_node(dev, "rockchip_usb2phy_clock", |
| 333 | name, node, &usb2phy_dev); |
| 334 | if (ret) { |
| 335 | dev_err(dev, |
| 336 | "'%s' cannot bind 'rockchip_usb2phy_clock'\n", name); |
| 337 | goto bind_fail; |
| 338 | } |
| 339 | |
| 340 | return 0; |
| 341 | |
| 342 | bind_fail: |
| 343 | device_chld_unbind(dev, NULL); |
| 344 | |
Jagan Teki | 70e882f | 2020-05-26 11:33:44 +0800 | [diff] [blame] | 345 | return ret; |
| 346 | } |
| 347 | |
| 348 | static const struct rockchip_usb2phy_cfg rk3399_usb2phy_cfgs[] = { |
| 349 | { |
| 350 | .reg = 0xe450, |
Xavier Drudis Ferran | 1ef4777 | 2023-06-05 17:06:57 +0200 | [diff] [blame] | 351 | .clkout_ctl = { 0xe450, 4, 4, 1, 0 }, |
Jagan Teki | 70e882f | 2020-05-26 11:33:44 +0800 | [diff] [blame] | 352 | .port_cfgs = { |
| 353 | [USB2PHY_PORT_OTG] = { |
| 354 | .phy_sus = { 0xe454, 1, 0, 2, 1 }, |
| 355 | .bvalid_det_en = { 0xe3c0, 3, 3, 0, 1 }, |
| 356 | .bvalid_det_st = { 0xe3e0, 3, 3, 0, 1 }, |
| 357 | .bvalid_det_clr = { 0xe3d0, 3, 3, 0, 1 }, |
| 358 | .utmi_avalid = { 0xe2ac, 7, 7, 0, 1 }, |
| 359 | .utmi_bvalid = { 0xe2ac, 12, 12, 0, 1 }, |
| 360 | }, |
| 361 | [USB2PHY_PORT_HOST] = { |
| 362 | .phy_sus = { 0xe458, 1, 0, 0x2, 0x1 }, |
| 363 | .ls_det_en = { 0xe3c0, 6, 6, 0, 1 }, |
| 364 | .ls_det_st = { 0xe3e0, 6, 6, 0, 1 }, |
| 365 | .ls_det_clr = { 0xe3d0, 6, 6, 0, 1 }, |
| 366 | .utmi_ls = { 0xe2ac, 22, 21, 0, 1 }, |
| 367 | .utmi_hstdet = { 0xe2ac, 23, 23, 0, 1 } |
| 368 | } |
| 369 | }, |
| 370 | }, |
| 371 | { |
| 372 | .reg = 0xe460, |
Xavier Drudis Ferran | 1ef4777 | 2023-06-05 17:06:57 +0200 | [diff] [blame] | 373 | .clkout_ctl = { 0xe460, 4, 4, 1, 0 }, |
Jagan Teki | 70e882f | 2020-05-26 11:33:44 +0800 | [diff] [blame] | 374 | .port_cfgs = { |
| 375 | [USB2PHY_PORT_OTG] = { |
| 376 | .phy_sus = { 0xe464, 1, 0, 2, 1 }, |
| 377 | .bvalid_det_en = { 0xe3c0, 8, 8, 0, 1 }, |
| 378 | .bvalid_det_st = { 0xe3e0, 8, 8, 0, 1 }, |
| 379 | .bvalid_det_clr = { 0xe3d0, 8, 8, 0, 1 }, |
| 380 | .utmi_avalid = { 0xe2ac, 10, 10, 0, 1 }, |
| 381 | .utmi_bvalid = { 0xe2ac, 16, 16, 0, 1 }, |
| 382 | }, |
| 383 | [USB2PHY_PORT_HOST] = { |
| 384 | .phy_sus = { 0xe468, 1, 0, 0x2, 0x1 }, |
| 385 | .ls_det_en = { 0xe3c0, 11, 11, 0, 1 }, |
| 386 | .ls_det_st = { 0xe3e0, 11, 11, 0, 1 }, |
| 387 | .ls_det_clr = { 0xe3d0, 11, 11, 0, 1 }, |
| 388 | .utmi_ls = { 0xe2ac, 26, 25, 0, 1 }, |
| 389 | .utmi_hstdet = { 0xe2ac, 27, 27, 0, 1 } |
| 390 | } |
| 391 | }, |
| 392 | }, |
| 393 | { /* sentinel */ } |
| 394 | }; |
| 395 | |
Manoj Sai | 3a11167 | 2023-02-17 17:28:40 +0530 | [diff] [blame] | 396 | static const struct rockchip_usb2phy_cfg rk3568_phy_cfgs[] = { |
| 397 | { |
| 398 | .reg = 0xfe8a0000, |
Xavier Drudis Ferran | 1ef4777 | 2023-06-05 17:06:57 +0200 | [diff] [blame] | 399 | .clkout_ctl = { 0x0008, 4, 4, 1, 0 }, |
Manoj Sai | 3a11167 | 2023-02-17 17:28:40 +0530 | [diff] [blame] | 400 | .port_cfgs = { |
| 401 | [USB2PHY_PORT_OTG] = { |
| 402 | .phy_sus = { 0x0000, 8, 0, 0x052, 0x1d1 }, |
| 403 | .bvalid_det_en = { 0x0080, 2, 2, 0, 1 }, |
| 404 | .bvalid_det_st = { 0x0084, 2, 2, 0, 1 }, |
| 405 | .bvalid_det_clr = { 0x0088, 2, 2, 0, 1 }, |
| 406 | .ls_det_en = { 0x0080, 0, 0, 0, 1 }, |
| 407 | .ls_det_st = { 0x0084, 0, 0, 0, 1 }, |
| 408 | .ls_det_clr = { 0x0088, 0, 0, 0, 1 }, |
| 409 | .utmi_avalid = { 0x00c0, 10, 10, 0, 1 }, |
| 410 | .utmi_bvalid = { 0x00c0, 9, 9, 0, 1 }, |
| 411 | .utmi_ls = { 0x00c0, 5, 4, 0, 1 }, |
| 412 | }, |
| 413 | [USB2PHY_PORT_HOST] = { |
| 414 | .phy_sus = { 0x0004, 8, 0, 0x1d2, 0x1d1 }, |
| 415 | .ls_det_en = { 0x0080, 1, 1, 0, 1 }, |
| 416 | .ls_det_st = { 0x0084, 1, 1, 0, 1 }, |
| 417 | .ls_det_clr = { 0x0088, 1, 1, 0, 1 }, |
| 418 | .utmi_ls = { 0x00c0, 17, 16, 0, 1 }, |
| 419 | .utmi_hstdet = { 0x00c0, 19, 19, 0, 1 } |
| 420 | } |
| 421 | }, |
| 422 | }, |
| 423 | { |
| 424 | .reg = 0xfe8b0000, |
Xavier Drudis Ferran | 1ef4777 | 2023-06-05 17:06:57 +0200 | [diff] [blame] | 425 | .clkout_ctl = { 0x0008, 4, 4, 1, 0 }, |
Manoj Sai | 3a11167 | 2023-02-17 17:28:40 +0530 | [diff] [blame] | 426 | .port_cfgs = { |
| 427 | [USB2PHY_PORT_OTG] = { |
| 428 | .phy_sus = { 0x0000, 8, 0, 0x1d2, 0x1d1 }, |
| 429 | .ls_det_en = { 0x0080, 0, 0, 0, 1 }, |
| 430 | .ls_det_st = { 0x0084, 0, 0, 0, 1 }, |
| 431 | .ls_det_clr = { 0x0088, 0, 0, 0, 1 }, |
| 432 | .utmi_ls = { 0x00c0, 5, 4, 0, 1 }, |
| 433 | .utmi_hstdet = { 0x00c0, 7, 7, 0, 1 } |
| 434 | }, |
| 435 | [USB2PHY_PORT_HOST] = { |
| 436 | .phy_sus = { 0x0004, 8, 0, 0x1d2, 0x1d1 }, |
| 437 | .ls_det_en = { 0x0080, 1, 1, 0, 1 }, |
| 438 | .ls_det_st = { 0x0084, 1, 1, 0, 1 }, |
| 439 | .ls_det_clr = { 0x0088, 1, 1, 0, 1 }, |
| 440 | .utmi_ls = { 0x00c0, 17, 16, 0, 1 }, |
| 441 | .utmi_hstdet = { 0x00c0, 19, 19, 0, 1 } |
| 442 | } |
| 443 | }, |
| 444 | }, |
Eugen Hristev | 3364226 | 2023-05-15 12:59:49 +0300 | [diff] [blame] | 445 | { /* sentinel */ } |
| 446 | }; |
| 447 | |
| 448 | static const struct rockchip_usb2phy_cfg rk3588_phy_cfgs[] = { |
| 449 | { |
| 450 | .reg = 0x0000, |
| 451 | .port_cfgs = { |
| 452 | [USB2PHY_PORT_OTG] = { |
| 453 | .phy_sus = { 0x000c, 11, 11, 0, 1 }, |
| 454 | .ls_det_en = { 0x0080, 0, 0, 0, 1 }, |
| 455 | .ls_det_st = { 0x0084, 0, 0, 0, 1 }, |
| 456 | .ls_det_clr = { 0x0088, 0, 0, 0, 1 }, |
| 457 | .utmi_ls = { 0x00c0, 10, 9, 0, 1 }, |
| 458 | } |
| 459 | }, |
| 460 | }, |
| 461 | { |
| 462 | .reg = 0x4000, |
| 463 | .port_cfgs = { |
| 464 | [USB2PHY_PORT_OTG] = { |
| 465 | .phy_sus = { 0x000c, 11, 11, 0, 0 }, |
| 466 | .ls_det_en = { 0x0080, 0, 0, 0, 1 }, |
| 467 | .ls_det_st = { 0x0084, 0, 0, 0, 1 }, |
| 468 | .ls_det_clr = { 0x0088, 0, 0, 0, 1 }, |
| 469 | .utmi_ls = { 0x00c0, 10, 9, 0, 1 }, |
| 470 | } |
| 471 | }, |
| 472 | }, |
| 473 | { |
| 474 | .reg = 0x8000, |
| 475 | .port_cfgs = { |
| 476 | [USB2PHY_PORT_HOST] = { |
| 477 | .phy_sus = { 0x0008, 2, 2, 0, 1 }, |
| 478 | .ls_det_en = { 0x0080, 0, 0, 0, 1 }, |
| 479 | .ls_det_st = { 0x0084, 0, 0, 0, 1 }, |
| 480 | .ls_det_clr = { 0x0088, 0, 0, 0, 1 }, |
| 481 | .utmi_ls = { 0x00c0, 10, 9, 0, 1 }, |
| 482 | } |
| 483 | }, |
| 484 | }, |
| 485 | { |
| 486 | .reg = 0xc000, |
| 487 | .port_cfgs = { |
| 488 | [USB2PHY_PORT_HOST] = { |
| 489 | .phy_sus = { 0x0008, 2, 2, 0, 1 }, |
| 490 | .ls_det_en = { 0x0080, 0, 0, 0, 1 }, |
| 491 | .ls_det_st = { 0x0084, 0, 0, 0, 1 }, |
| 492 | .ls_det_clr = { 0x0088, 0, 0, 0, 1 }, |
| 493 | .utmi_ls = { 0x00c0, 10, 9, 0, 1 }, |
| 494 | } |
| 495 | }, |
| 496 | }, |
Manoj Sai | 3a11167 | 2023-02-17 17:28:40 +0530 | [diff] [blame] | 497 | { /* sentinel */ } |
| 498 | }; |
| 499 | |
Jagan Teki | 70e882f | 2020-05-26 11:33:44 +0800 | [diff] [blame] | 500 | static const struct udevice_id rockchip_usb2phy_ids[] = { |
| 501 | { |
| 502 | .compatible = "rockchip,rk3399-usb2phy", |
| 503 | .data = (ulong)&rk3399_usb2phy_cfgs, |
| 504 | }, |
Manoj Sai | 3a11167 | 2023-02-17 17:28:40 +0530 | [diff] [blame] | 505 | { |
| 506 | .compatible = "rockchip,rk3568-usb2phy", |
| 507 | .data = (ulong)&rk3568_phy_cfgs, |
| 508 | }, |
Eugen Hristev | 3364226 | 2023-05-15 12:59:49 +0300 | [diff] [blame] | 509 | { |
| 510 | .compatible = "rockchip,rk3588-usb2phy", |
| 511 | .data = (ulong)&rk3588_phy_cfgs, |
| 512 | }, |
Jagan Teki | 70e882f | 2020-05-26 11:33:44 +0800 | [diff] [blame] | 513 | { /* sentinel */ } |
| 514 | }; |
| 515 | |
| 516 | U_BOOT_DRIVER(rockchip_usb2phy_port) = { |
| 517 | .name = "rockchip_usb2phy_port", |
| 518 | .id = UCLASS_PHY, |
| 519 | .ops = &rockchip_usb2phy_ops, |
| 520 | }; |
| 521 | |
Xavier Drudis Ferran | c3dd061 | 2023-06-05 17:05:53 +0200 | [diff] [blame] | 522 | U_BOOT_DRIVER(rockchip_usb2phy_clock) = { |
| 523 | .name = "rockchip_usb2phy_clock", |
| 524 | .id = UCLASS_CLK, |
| 525 | .ops = &rockchip_usb2phy_clk_ops, |
| 526 | }; |
| 527 | |
Jagan Teki | 70e882f | 2020-05-26 11:33:44 +0800 | [diff] [blame] | 528 | U_BOOT_DRIVER(rockchip_usb2phy) = { |
| 529 | .name = "rockchip_usb2phy", |
| 530 | .id = UCLASS_PHY, |
| 531 | .of_match = rockchip_usb2phy_ids, |
| 532 | .probe = rockchip_usb2phy_probe, |
| 533 | .bind = rockchip_usb2phy_bind, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 534 | .priv_auto = sizeof(struct rockchip_usb2phy), |
Jagan Teki | 70e882f | 2020-05-26 11:33:44 +0800 | [diff] [blame] | 535 | }; |