1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Rockchip USBDP Combo PHY with Samsung IP block driver
5 * Copyright (C) 2021 Rockchip Electronics Co., Ltd
11 #include <dm/device_compat.h>
12 #include <dm/devres.h>
15 #include <dm/of_access.h>
16 #include <generic-phy.h>
17 #include <linux/bitfield.h>
18 #include <linux/usb/ch9.h>
19 #include <linux/usb/otg.h>
23 #include <asm/arch-rockchip/clock.h>
25 #include <linux/usb/phy-rockchip-usbdp.h>
27 #define BIT_WRITEABLE_SHIFT 16
31 UDPHY_MODE_USB = BIT(0),
32 UDPHY_MODE_DP = BIT(1),
33 UDPHY_MODE_DP_USB = BIT(1) | BIT(0),
36 struct udphy_grf_reg {
39 unsigned int bitstart;
45 * struct reg_sequence - An individual write from a sequence of writes.
47 * @reg: Register address.
48 * @def: Register value.
49 * @delay_us: Delay to be applied after the register write in microseconds
51 * Register/value pairs for sequences of writes with an optional delay in
52 * microseconds to be applied after each write.
57 unsigned int delay_us;
60 struct udphy_grf_cfg {
62 struct udphy_grf_reg bvalid_phy_con;
63 struct udphy_grf_reg bvalid_grf_con;
66 struct udphy_grf_reg usb3otg0_cfg;
67 struct udphy_grf_reg usb3otg1_cfg;
70 struct udphy_grf_reg low_pwrn;
71 struct udphy_grf_reg rx_lfps;
74 struct rockchip_udphy;
76 struct rockchip_udphy_cfg {
77 unsigned int num_phys;
78 unsigned int phy_ids[2];
79 /* resets to be requested */
80 const char * const *rst_list;
83 struct udphy_grf_cfg grfcfg;
84 int (*combophy_init)(struct rockchip_udphy *udphy);
87 struct rockchip_udphy {
89 struct regmap *pma_regmap;
90 struct regmap *u2phygrf;
91 struct regmap *udphygrf;
92 struct regmap *usbgrf;
95 /* clocks and rests */
96 struct reset_ctl *rsts;
98 /* PHY status management */
104 /* utilized for USB */
105 bool hs; /* flag for high-speed */
107 /* utilized for DP */
108 struct gpio_desc *sbu1_dc_gpio;
109 struct gpio_desc *sbu2_dc_gpio;
116 /* PHY const config */
117 const struct rockchip_udphy_cfg *cfgs;
120 static const struct reg_sequence rk3588_udphy_24m_refclk_cfg[] = {
121 {0x0090, 0x68}, {0x0094, 0x68},
122 {0x0128, 0x24}, {0x012c, 0x44},
123 {0x0130, 0x3f}, {0x0134, 0x44},
124 {0x015c, 0xa9}, {0x0160, 0x71},
125 {0x0164, 0x71}, {0x0168, 0xa9},
126 {0x0174, 0xa9}, {0x0178, 0x71},
127 {0x017c, 0x71}, {0x0180, 0xa9},
128 {0x018c, 0x41}, {0x0190, 0x00},
129 {0x0194, 0x05}, {0x01ac, 0x2a},
130 {0x01b0, 0x17}, {0x01b4, 0x17},
131 {0x01b8, 0x2a}, {0x01c8, 0x04},
132 {0x01cc, 0x08}, {0x01d0, 0x08},
133 {0x01d4, 0x04}, {0x01d8, 0x20},
134 {0x01dc, 0x01}, {0x01e0, 0x09},
135 {0x01e4, 0x03}, {0x01f0, 0x29},
136 {0x01f4, 0x02}, {0x01f8, 0x02},
137 {0x01fc, 0x29}, {0x0208, 0x2a},
138 {0x020c, 0x17}, {0x0210, 0x17},
139 {0x0214, 0x2a}, {0x0224, 0x20},
140 {0x03f0, 0x0d}, {0x03f4, 0x09},
141 {0x03f8, 0x09}, {0x03fc, 0x0d},
142 {0x0404, 0x0e}, {0x0408, 0x14},
143 {0x040c, 0x14}, {0x0410, 0x3b},
144 {0x0ce0, 0x68}, {0x0ce8, 0xd0},
145 {0x0cf0, 0x87}, {0x0cf8, 0x70},
146 {0x0d00, 0x70}, {0x0d08, 0xa9},
147 {0x1ce0, 0x68}, {0x1ce8, 0xd0},
148 {0x1cf0, 0x87}, {0x1cf8, 0x70},
149 {0x1d00, 0x70}, {0x1d08, 0xa9},
150 {0x0a3c, 0xd0}, {0x0a44, 0xd0},
151 {0x0a48, 0x01}, {0x0a4c, 0x0d},
152 {0x0a54, 0xe0}, {0x0a5c, 0xe0},
153 {0x0a64, 0xa8}, {0x1a3c, 0xd0},
154 {0x1a44, 0xd0}, {0x1a48, 0x01},
155 {0x1a4c, 0x0d}, {0x1a54, 0xe0},
156 {0x1a5c, 0xe0}, {0x1a64, 0xa8}
159 static const struct reg_sequence rk3588_udphy_init_sequence[] = {
160 {0x0104, 0x44}, {0x0234, 0xE8},
161 {0x0248, 0x44}, {0x028C, 0x18},
162 {0x081C, 0xE5}, {0x0878, 0x00},
163 {0x0994, 0x1C}, {0x0AF0, 0x00},
164 {0x181C, 0xE5}, {0x1878, 0x00},
165 {0x1994, 0x1C}, {0x1AF0, 0x00},
166 {0x0428, 0x60}, {0x0D58, 0x33},
167 {0x1D58, 0x33}, {0x0990, 0x74},
168 {0x0D64, 0x17}, {0x08C8, 0x13},
169 {0x1990, 0x74}, {0x1D64, 0x17},
170 {0x18C8, 0x13}, {0x0D90, 0x40},
171 {0x0DA8, 0x40}, {0x0DC0, 0x40},
172 {0x0DD8, 0x40}, {0x1D90, 0x40},
173 {0x1DA8, 0x40}, {0x1DC0, 0x40},
174 {0x1DD8, 0x40}, {0x03C0, 0x30},
175 {0x03C4, 0x06}, {0x0E10, 0x00},
176 {0x1E10, 0x00}, {0x043C, 0x0F},
177 {0x0D2C, 0xFF}, {0x1D2C, 0xFF},
178 {0x0D34, 0x0F}, {0x1D34, 0x0F},
179 {0x08FC, 0x2A}, {0x0914, 0x28},
180 {0x0A30, 0x03}, {0x0E38, 0x05},
181 {0x0ECC, 0x27}, {0x0ED0, 0x22},
182 {0x0ED4, 0x26}, {0x18FC, 0x2A},
183 {0x1914, 0x28}, {0x1A30, 0x03},
184 {0x1E38, 0x05}, {0x1ECC, 0x27},
185 {0x1ED0, 0x22}, {0x1ED4, 0x26},
186 {0x0048, 0x0F}, {0x0060, 0x3C},
187 {0x0064, 0xF7}, {0x006C, 0x20},
188 {0x0070, 0x7D}, {0x0074, 0x68},
189 {0x0AF4, 0x1A}, {0x1AF4, 0x1A},
190 {0x0440, 0x3F}, {0x10D4, 0x08},
191 {0x20D4, 0x08}, {0x00D4, 0x30},
195 static inline int grfreg_write(struct regmap *base,
196 const struct udphy_grf_reg *reg, bool en)
200 tmp = en ? reg->enable : reg->disable;
201 mask = GENMASK(reg->bitend, reg->bitstart);
202 val = (tmp << reg->bitstart) | (mask << BIT_WRITEABLE_SHIFT);
204 return regmap_write(base, reg->offset, val);
207 static int __regmap_multi_reg_write(struct regmap *map,
208 const struct reg_sequence *regs,
213 for (i = 0; i < num_regs; i++) {
214 ret = regmap_write(map, regs[i].reg, regs[i].def);
216 if (regs[i].delay_us)
217 udelay(regs[i].delay_us);
223 static int udphy_clk_init(struct rockchip_udphy *udphy, struct udevice *dev)
228 static int udphy_reset_init(struct rockchip_udphy *udphy, struct udevice *dev)
230 const struct rockchip_udphy_cfg *cfg = udphy->cfgs;
234 udphy->rsts = devm_kcalloc(dev, cfg->num_rsts,
235 sizeof(*udphy->rsts), GFP_KERNEL);
239 for (idx = 0; idx < cfg->num_rsts; idx++) {
240 const char *name = cfg->rst_list[idx];
242 ret = reset_get_by_name(dev, name, &udphy->rsts[idx]);
244 dev_err(dev, "failed to get %s reset\n", name);
248 reset_assert(&udphy->rsts[idx]);
254 devm_kfree(dev, udphy->rsts);
258 static int udphy_get_rst_idx(const char * const *list, int num, char *name)
262 for (idx = 0; idx < num; idx++) {
263 if (!strcmp(list[idx], name))
270 static int udphy_reset_assert(struct rockchip_udphy *udphy, char *name)
272 const struct rockchip_udphy_cfg *cfg = udphy->cfgs;
275 idx = udphy_get_rst_idx(cfg->rst_list, cfg->num_rsts, name);
279 return reset_assert(&udphy->rsts[idx]);
282 static int udphy_reset_deassert(struct rockchip_udphy *udphy, char *name)
284 const struct rockchip_udphy_cfg *cfg = udphy->cfgs;
287 idx = udphy_get_rst_idx(cfg->rst_list, cfg->num_rsts, name);
291 return reset_deassert(&udphy->rsts[idx]);
294 static void udphy_u3_port_disable(struct rockchip_udphy *udphy, u8 disable)
296 const struct rockchip_udphy_cfg *cfg = udphy->cfgs;
297 const struct udphy_grf_reg *preg;
299 preg = udphy->id ? &cfg->grfcfg.usb3otg1_cfg : &cfg->grfcfg.usb3otg0_cfg;
300 grfreg_write(udphy->usbgrf, preg, disable);
304 static void udphy_usb_bvalid_enable(struct rockchip_udphy *udphy, u8 enable)
306 const struct rockchip_udphy_cfg *cfg = udphy->cfgs;
308 grfreg_write(udphy->u2phygrf, &cfg->grfcfg.bvalid_phy_con, enable);
309 grfreg_write(udphy->u2phygrf, &cfg->grfcfg.bvalid_grf_con, enable);
313 * In usb/dp combo phy driver, here are 2 ways to mapping lanes.
315 * 1 Type-C Mapping table (DP_Alt_Mode V1.0b remove ABF pin mapping)
316 * ---------------------------------------------------------------------------
317 * Type-C Pin B11-B10 A2-A3 A11-A10 B2-B3
318 * PHY Pad ln0(tx/rx) ln1(tx) ln2(tx/rx) ln3(tx)
319 * C/E(Normal) dpln3 dpln2 dpln0 dpln1
320 * C/E(Flip ) dpln0 dpln1 dpln3 dpln2
321 * D/F(Normal) usbrx usbtx dpln0 dpln1
322 * D/F(Flip ) dpln0 dpln1 usbrx usbtx
323 * A(Normal ) dpln3 dpln1 dpln2 dpln0
324 * A(Flip ) dpln2 dpln0 dpln3 dpln1
325 * B(Normal ) usbrx usbtx dpln1 dpln0
326 * B(Flip ) dpln1 dpln0 usbrx usbtx
327 * ---------------------------------------------------------------------------
329 * 2 Mapping the lanes in dtsi
330 * if all 4 lane assignment for dp function, define rockchip,dp-lane-mux = <x x x x>;
332 * ---------------------------------------------------------------------------
333 * B11-B10 A2-A3 A11-A10 B2-B3
334 * rockchip,dp-lane-mux ln0(tx/rx) ln1(tx) ln2(tx/rx) ln3(tx)
335 * <0 1 2 3> dpln0 dpln1 dpln2 dpln3
336 * <2 3 0 1> dpln2 dpln3 dpln0 dpln1
337 * ---------------------------------------------------------------------------
338 * if 2 lane for dp function, 2 lane for usb function, define rockchip,dp-lane-mux = <x x>;
340 * ---------------------------------------------------------------------------
341 * B11-B10 A2-A3 A11-A10 B2-B3
342 * rockchip,dp-lane-mux ln0(tx/rx) ln1(tx) ln2(tx/rx) ln3(tx)
343 * <0 1> dpln0 dpln1 usbrx usbtx
344 * <2 3> usbrx usbtx dpln0 dpln1
345 * ---------------------------------------------------------------------------
349 static int upphy_set_typec_default_mapping(struct rockchip_udphy *udphy)
352 udphy->dp_lane_sel[0] = 0;
353 udphy->dp_lane_sel[1] = 1;
354 udphy->dp_lane_sel[2] = 3;
355 udphy->dp_lane_sel[3] = 2;
356 udphy->lane_mux_sel[0] = PHY_LANE_MUX_DP;
357 udphy->lane_mux_sel[1] = PHY_LANE_MUX_DP;
358 udphy->lane_mux_sel[2] = PHY_LANE_MUX_USB;
359 udphy->lane_mux_sel[3] = PHY_LANE_MUX_USB;
360 udphy->dp_aux_dout_sel = PHY_AUX_DP_DATA_POL_INVERT;
361 udphy->dp_aux_din_sel = PHY_AUX_DP_DATA_POL_INVERT;
363 udphy->dp_lane_sel[0] = 2;
364 udphy->dp_lane_sel[1] = 3;
365 udphy->dp_lane_sel[2] = 1;
366 udphy->dp_lane_sel[3] = 0;
367 udphy->lane_mux_sel[0] = PHY_LANE_MUX_USB;
368 udphy->lane_mux_sel[1] = PHY_LANE_MUX_USB;
369 udphy->lane_mux_sel[2] = PHY_LANE_MUX_DP;
370 udphy->lane_mux_sel[3] = PHY_LANE_MUX_DP;
371 udphy->dp_aux_dout_sel = PHY_AUX_DP_DATA_POL_NORMAL;
372 udphy->dp_aux_din_sel = PHY_AUX_DP_DATA_POL_NORMAL;
375 udphy->mode = UDPHY_MODE_DP_USB;
380 static int udphy_setup(struct rockchip_udphy *udphy)
382 const struct rockchip_udphy_cfg *cfg = udphy->cfgs;
385 if (cfg->combophy_init) {
386 ret = cfg->combophy_init(udphy);
388 dev_err(udphy->dev, "failed to init usbdp combophy\n");
394 static int udphy_disable(struct rockchip_udphy *udphy)
396 const struct rockchip_udphy_cfg *cfg = udphy->cfgs;
399 for (i = 0; i < cfg->num_rsts; i++)
400 reset_assert(&udphy->rsts[i]);
405 static int udphy_parse_lane_mux_data(struct rockchip_udphy *udphy,
406 const struct device_node *np)
408 struct property *prop;
409 int ret, i, len, num_lanes;
411 prop = of_find_property(np, "rockchip,dp-lane-mux", &len);
414 "failed to find dp lane mux, following dp alt mode\n");
415 udphy->mode = UDPHY_MODE_USB;
419 num_lanes = len / sizeof(u32);
421 if (num_lanes != 2 && num_lanes != 4) {
422 dev_err(udphy->dev, "invalid number of lane mux\n");
426 ret = of_read_u32_array(np, "rockchip,dp-lane-mux", udphy->dp_lane_sel,
429 dev_err(udphy->dev, "get dp lane mux failed\n");
433 for (i = 0; i < num_lanes; i++) {
436 if (udphy->dp_lane_sel[i] > 3) {
438 "lane mux between 0 and 3, exceeding the range\n");
442 udphy->lane_mux_sel[udphy->dp_lane_sel[i]] = PHY_LANE_MUX_DP;
444 for (j = i + 1; j < num_lanes; j++) {
445 if (udphy->dp_lane_sel[i] == udphy->dp_lane_sel[j]) {
447 "set repeat lane mux value\n");
453 udphy->mode = UDPHY_MODE_DP;
455 udphy->mode |= UDPHY_MODE_USB;
460 static int udphy_parse_dt(struct rockchip_udphy *udphy, struct udevice *dev)
462 const struct device_node *np = ofnode_to_np(dev_ofnode(dev));
463 enum usb_device_speed maximum_speed;
466 udphy->u2phygrf = syscon_regmap_lookup_by_phandle(dev,
467 "rockchip,u2phy-grf");
468 if (IS_ERR(udphy->u2phygrf)) {
469 if (PTR_ERR(udphy->u2phygrf) == -ENODEV) {
470 dev_warn(dev, "missing u2phy-grf dt node\n");
471 udphy->u2phygrf = NULL;
473 return PTR_ERR(udphy->u2phygrf);
477 udphy->udphygrf = syscon_regmap_lookup_by_phandle(dev,
478 "rockchip,usbdpphy-grf");
479 if (IS_ERR(udphy->udphygrf)) {
480 if (PTR_ERR(udphy->udphygrf) == -ENODEV) {
481 dev_warn(dev, "missing usbdpphy-grf dt node\n");
482 udphy->udphygrf = NULL;
484 return PTR_ERR(udphy->udphygrf);
488 udphy->usbgrf = syscon_regmap_lookup_by_phandle(dev,
490 if (IS_ERR(udphy->usbgrf)) {
491 if (PTR_ERR(udphy->usbgrf) == -ENODEV) {
492 dev_warn(dev, "missing usb-grf dt node\n");
493 udphy->usbgrf = NULL;
495 return PTR_ERR(udphy->usbgrf);
499 udphy->vogrf = syscon_regmap_lookup_by_phandle(dev, "rockchip,vo-grf");
500 if (IS_ERR(udphy->vogrf)) {
501 if (PTR_ERR(udphy->vogrf) == -ENODEV) {
502 dev_warn(dev, "missing vo-grf dt node\n");
505 return PTR_ERR(udphy->vogrf);
509 ret = udphy_parse_lane_mux_data(udphy, np);
513 if (dev_read_prop(dev, "maximum-speed", NULL)) {
514 maximum_speed = usb_get_maximum_speed(dev_ofnode(dev));
515 udphy->hs = maximum_speed <= USB_SPEED_HIGH ? true : false;
518 ret = udphy_clk_init(udphy, dev);
522 ret = udphy_reset_init(udphy, dev);
529 static int udphy_power_on(struct rockchip_udphy *udphy, u8 mode)
533 if (!(udphy->mode & mode)) {
534 dev_info(udphy->dev, "mode 0x%02x is not support\n", mode);
538 if (udphy->status == UDPHY_MODE_NONE) {
539 udphy->mode_change = false;
540 ret = udphy_setup(udphy);
544 if (udphy->mode & UDPHY_MODE_USB)
545 udphy_u3_port_disable(udphy, false);
546 } else if (udphy->mode_change) {
547 udphy->mode_change = false;
548 udphy->status = UDPHY_MODE_NONE;
549 if (udphy->mode == UDPHY_MODE_DP)
550 udphy_u3_port_disable(udphy, true);
552 ret = udphy_disable(udphy);
555 ret = udphy_setup(udphy);
560 udphy->status |= mode;
565 static int udphy_power_off(struct rockchip_udphy *udphy, u8 mode)
569 if (!(udphy->mode & mode)) {
570 dev_info(udphy->dev, "mode 0x%02x is not supported\n", mode);
577 udphy->status &= ~mode;
579 if (udphy->status == UDPHY_MODE_NONE) {
580 ret = udphy_disable(udphy);
588 static int rockchip_u3phy_init(struct phy *phy)
590 struct udevice *parent = phy->dev->parent;
591 struct rockchip_udphy *udphy = dev_get_priv(parent);
593 /* DP only or high-speed, disable U3 port */
594 if (!(udphy->mode & UDPHY_MODE_USB) || udphy->hs) {
595 udphy_u3_port_disable(udphy, true);
599 return udphy_power_on(udphy, UDPHY_MODE_USB);
602 static int rockchip_u3phy_exit(struct phy *phy)
604 struct udevice *parent = phy->dev->parent;
605 struct rockchip_udphy *udphy = dev_get_priv(parent);
607 /* DP only or high-speed */
608 if (!(udphy->mode & UDPHY_MODE_USB) || udphy->hs)
611 return udphy_power_off(udphy, UDPHY_MODE_USB);
614 static const struct phy_ops rockchip_u3phy_ops = {
615 .init = rockchip_u3phy_init,
616 .exit = rockchip_u3phy_exit,
619 static int rockchip_udphy_probe(struct udevice *dev)
621 struct rockchip_udphy *udphy = dev_get_priv(dev);
622 const struct rockchip_udphy_cfg *phy_cfgs;
628 ret = ofnode_read_u32_index(dev_ofnode(dev), "reg", 0, ®);
630 dev_err(dev, "failed to read reg[0] property\n");
633 if (reg == 0 && dev_read_addr_cells(dev) == 2) {
634 ret = ofnode_read_u32_index(dev_ofnode(dev), "reg", 1, ®);
636 dev_err(dev, "failed to read reg[1] property\n");
641 phy_cfgs = (const struct rockchip_udphy_cfg *)dev_get_driver_data(dev);
643 dev_err(dev, "unable to get phy_cfgs\n");
646 udphy->cfgs = phy_cfgs;
648 /* find the phy-id from the io address */
650 for (id = 0; id < udphy->cfgs->num_phys; id++) {
651 if (reg == udphy->cfgs->phy_ids[id]) {
658 dev_err(dev, "no matching device found\n");
662 ret = regmap_init_mem(dev_ofnode(dev), &udphy->pma_regmap);
665 udphy->pma_regmap->ranges[0].start += UDPHY_PMA;
667 ret = udphy_parse_dt(udphy, dev);
674 static int rockchip_udphy_bind(struct udevice *parent)
676 struct udevice *child;
678 const char *node_name;
681 dev_for_each_subnode(subnode, parent) {
682 if (!ofnode_valid(subnode)) {
683 printf("%s: no subnode for %s", __func__, parent->name);
687 node_name = ofnode_get_name(subnode);
688 debug("%s: subnode %s\n", __func__, node_name);
690 /* if there is no match, continue */
691 if (strcasecmp(node_name, "usb3-port"))
694 /* node name is usb3-port */
695 ret = device_bind_driver_to_node(parent,
696 "rockchip_udphy_u3_port",
697 node_name, subnode, &child);
699 printf("%s: '%s' cannot bind its driver\n",
700 __func__, node_name);
708 static int rk3588_udphy_refclk_set(struct rockchip_udphy *udphy)
710 /* configure phy reference clock */
711 return __regmap_multi_reg_write(udphy->pma_regmap,
712 rk3588_udphy_24m_refclk_cfg,
713 ARRAY_SIZE(rk3588_udphy_24m_refclk_cfg));
716 static int rk3588_udphy_status_check(struct rockchip_udphy *udphy)
721 if (!(udphy->mode & UDPHY_MODE_USB))
725 ret = regmap_read_poll_timeout(udphy->pma_regmap,
726 CMN_ANA_LCPLL_DONE_OFFSET,
727 val, (val & CMN_ANA_LCPLL_AFC_DONE) &&
728 (val & CMN_ANA_LCPLL_LOCK_DONE),
731 dev_err(udphy->dev, "cmn ana lcpll lock timeout\n");
736 ret = regmap_read_poll_timeout(udphy->pma_regmap,
737 TRSV_LN0_MON_RX_CDR_DONE_OFFSET,
739 val & TRSV_LN0_MON_RX_CDR_LOCK_DONE,
742 dev_err(udphy->dev, "trsv ln0 mon rx cdr lock timeout\n");
744 ret = regmap_read_poll_timeout(udphy->pma_regmap,
745 TRSV_LN2_MON_RX_CDR_DONE_OFFSET,
747 val & TRSV_LN2_MON_RX_CDR_LOCK_DONE,
750 dev_err(udphy->dev, "trsv ln2 mon rx cdr lock timeout\n");
756 static int rk3588_udphy_init(struct rockchip_udphy *udphy)
758 const struct rockchip_udphy_cfg *cfg = udphy->cfgs;
761 /* enable rx lfps for usb */
762 if (udphy->mode & UDPHY_MODE_USB)
763 grfreg_write(udphy->udphygrf, &cfg->grfcfg.rx_lfps, true);
765 /* Step 1: power on pma and deassert apb rstn */
766 grfreg_write(udphy->udphygrf, &cfg->grfcfg.low_pwrn, true);
768 udphy_reset_deassert(udphy, "pma_apb");
769 udphy_reset_deassert(udphy, "pcs_apb");
771 /* Step 2: set init sequence and phy refclk */
772 ret = __regmap_multi_reg_write(udphy->pma_regmap,
773 rk3588_udphy_init_sequence,
774 ARRAY_SIZE(rk3588_udphy_init_sequence));
776 dev_err(udphy->dev, "init sequence set error %d\n", ret);
780 ret = rk3588_udphy_refclk_set(udphy);
782 dev_err(udphy->dev, "refclk set error %d\n", ret);
786 /* Step 3: configure lane mux */
787 regmap_update_bits(udphy->pma_regmap, CMN_LANE_MUX_AND_EN_OFFSET,
788 CMN_DP_LANE_MUX_ALL | CMN_DP_LANE_EN_ALL,
789 FIELD_PREP(CMN_DP_LANE_MUX_N(3),
790 udphy->lane_mux_sel[3]) |
791 FIELD_PREP(CMN_DP_LANE_MUX_N(2),
792 udphy->lane_mux_sel[2]) |
793 FIELD_PREP(CMN_DP_LANE_MUX_N(1),
794 udphy->lane_mux_sel[1]) |
795 FIELD_PREP(CMN_DP_LANE_MUX_N(0),
796 udphy->lane_mux_sel[0]) |
797 FIELD_PREP(CMN_DP_LANE_EN_ALL, 0));
799 /* Step 4: deassert init rstn and wait for 200ns from datasheet */
800 if (udphy->mode & UDPHY_MODE_USB)
801 udphy_reset_deassert(udphy, "init");
803 if (udphy->mode & UDPHY_MODE_DP) {
804 regmap_update_bits(udphy->pma_regmap, CMN_DP_RSTN_OFFSET,
806 FIELD_PREP(CMN_DP_INIT_RSTN, 0x1));
811 /* Step 5: deassert cmn/lane rstn */
812 if (udphy->mode & UDPHY_MODE_USB) {
813 udphy_reset_deassert(udphy, "cmn");
814 udphy_reset_deassert(udphy, "lane");
817 /* Step 6: wait for lock done of pll */
818 ret = rk3588_udphy_status_check(udphy);
825 udphy_reset_assert(udphy, "init");
826 udphy_reset_assert(udphy, "cmn");
827 udphy_reset_assert(udphy, "lane");
830 udphy_reset_assert(udphy, "pma_apb");
831 udphy_reset_assert(udphy, "pcs_apb");
836 static const char * const rk3588_udphy_rst_l[] = {
837 "init", "cmn", "lane", "pcs_apb", "pma_apb"
840 static const struct rockchip_udphy_cfg rk3588_udphy_cfgs = {
846 .num_rsts = ARRAY_SIZE(rk3588_udphy_rst_l),
847 .rst_list = rk3588_udphy_rst_l,
850 .bvalid_phy_con = { 0x0008, 1, 0, 0x2, 0x3 },
851 .bvalid_grf_con = { 0x0010, 3, 2, 0x2, 0x3 },
854 .usb3otg0_cfg = { 0x001c, 15, 0, 0x1100, 0x0188 },
855 .usb3otg1_cfg = { 0x0034, 15, 0, 0x1100, 0x0188 },
858 .low_pwrn = { 0x0004, 13, 13, 0, 1 },
859 .rx_lfps = { 0x0004, 14, 14, 0, 1 },
861 .combophy_init = rk3588_udphy_init,
864 static const struct udevice_id rockchip_udphy_dt_match[] = {
866 .compatible = "rockchip,rk3588-usbdp-phy",
867 .data = (ulong)&rk3588_udphy_cfgs
872 U_BOOT_DRIVER(rockchip_udphy_u3_port) = {
873 .name = "rockchip_udphy_u3_port",
875 .ops = &rockchip_u3phy_ops,
878 U_BOOT_DRIVER(rockchip_udphy) = {
879 .name = "rockchip_udphy",
881 .of_match = rockchip_udphy_dt_match,
882 .probe = rockchip_udphy_probe,
883 .bind = rockchip_udphy_bind,
884 .priv_auto = sizeof(struct rockchip_udphy),