Lines Matching +full:usb2 +full:- +full:phy
1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2016-2022, NVIDIA CORPORATION. All rights reserved.
10 #include <linux/phy/phy.h>
21 #define HS_CURR_LEVEL_PADX_SHIFT(x) ((x) ? (11 + (x - 1) * 6) : 0)
267 writel(value, priv->ao_regs + offset); in ao_writel()
272 return readl(priv->ao_regs + offset); in ao_readl()
281 /* USB 2.0 UTMI PHY support */
286 struct tegra_xusb_usb2_lane *usb2; in tegra186_usb2_lane_probe() local
289 usb2 = kzalloc(sizeof(*usb2), GFP_KERNEL); in tegra186_usb2_lane_probe()
290 if (!usb2) in tegra186_usb2_lane_probe()
291 return ERR_PTR(-ENOMEM); in tegra186_usb2_lane_probe()
293 INIT_LIST_HEAD(&usb2->base.list); in tegra186_usb2_lane_probe()
294 usb2->base.soc = &pad->soc->lanes[index]; in tegra186_usb2_lane_probe()
295 usb2->base.index = index; in tegra186_usb2_lane_probe()
296 usb2->base.pad = pad; in tegra186_usb2_lane_probe()
297 usb2->base.np = np; in tegra186_usb2_lane_probe()
299 err = tegra_xusb_lane_parse_dt(&usb2->base, np); in tegra186_usb2_lane_probe()
301 kfree(usb2); in tegra186_usb2_lane_probe()
305 return &usb2->base; in tegra186_usb2_lane_probe()
310 struct tegra_xusb_usb2_lane *usb2 = to_usb2_lane(lane); in tegra186_usb2_lane_remove() local
312 kfree(usb2); in tegra186_usb2_lane_remove()
318 struct tegra_xusb_padctl *padctl = lane->pad->padctl; in tegra186_utmi_enable_phy_sleepwalk()
320 unsigned int index = lane->index; in tegra186_utmi_enable_phy_sleepwalk()
323 mutex_lock(&padctl->lock); in tegra186_utmi_enable_phy_sleepwalk()
394 * as well as capture the configuration of the USB2.0 pad in tegra186_utmi_enable_phy_sleepwalk()
400 /* setup the pull-ups and pull-downs of the signals during the four in tegra186_utmi_enable_phy_sleepwalk()
411 /* J state: D+/D- = high/low, K state: D+/D- = low/high */ in tegra186_utmi_enable_phy_sleepwalk()
418 /* J state: D+/D- = low/high, K state: D+/D- = high/low */ in tegra186_utmi_enable_phy_sleepwalk()
438 /* switch the electric control of the USB2.0 pad to XUSB_AO */ in tegra186_utmi_enable_phy_sleepwalk()
455 mutex_unlock(&padctl->lock); in tegra186_utmi_enable_phy_sleepwalk()
462 struct tegra_xusb_padctl *padctl = lane->pad->padctl; in tegra186_utmi_disable_phy_sleepwalk()
464 unsigned int index = lane->index; in tegra186_utmi_disable_phy_sleepwalk()
467 mutex_lock(&padctl->lock); in tegra186_utmi_disable_phy_sleepwalk()
474 /* switch the electric control of the USB2.0 pad to XUSB vcore logic */ in tegra186_utmi_disable_phy_sleepwalk()
496 mutex_unlock(&padctl->lock); in tegra186_utmi_disable_phy_sleepwalk()
503 struct tegra_xusb_padctl *padctl = lane->pad->padctl; in tegra186_utmi_enable_phy_wake()
504 unsigned int index = lane->index; in tegra186_utmi_enable_phy_wake()
507 mutex_lock(&padctl->lock); in tegra186_utmi_enable_phy_wake()
521 mutex_unlock(&padctl->lock); in tegra186_utmi_enable_phy_wake()
528 struct tegra_xusb_padctl *padctl = lane->pad->padctl; in tegra186_utmi_disable_phy_wake()
529 unsigned int index = lane->index; in tegra186_utmi_disable_phy_wake()
532 mutex_lock(&padctl->lock); in tegra186_utmi_disable_phy_wake()
546 mutex_unlock(&padctl->lock); in tegra186_utmi_disable_phy_wake()
553 struct tegra_xusb_padctl *padctl = lane->pad->padctl; in tegra186_utmi_phy_remote_wake_detected()
554 unsigned int index = lane->index; in tegra186_utmi_phy_remote_wake_detected()
578 struct device *dev = padctl->dev; in tegra186_utmi_bias_pad_power_on()
582 mutex_lock(&padctl->lock); in tegra186_utmi_bias_pad_power_on()
584 if (priv->bias_pad_enable++ > 0) { in tegra186_utmi_bias_pad_power_on()
585 mutex_unlock(&padctl->lock); in tegra186_utmi_bias_pad_power_on()
589 err = clk_prepare_enable(priv->usb2_trk_clk); in tegra186_utmi_bias_pad_power_on()
591 dev_warn(dev, "failed to enable USB2 trk clock: %d\n", err); in tegra186_utmi_bias_pad_power_on()
603 value |= HS_SQUELCH_LEVEL(priv->calib.hs_squelch); in tegra186_utmi_bias_pad_power_on()
612 mutex_unlock(&padctl->lock); in tegra186_utmi_bias_pad_power_on()
620 mutex_lock(&padctl->lock); in tegra186_utmi_bias_pad_power_off()
622 if (WARN_ON(priv->bias_pad_enable == 0)) { in tegra186_utmi_bias_pad_power_off()
623 mutex_unlock(&padctl->lock); in tegra186_utmi_bias_pad_power_off()
627 if (--priv->bias_pad_enable > 0) { in tegra186_utmi_bias_pad_power_off()
628 mutex_unlock(&padctl->lock); in tegra186_utmi_bias_pad_power_off()
636 clk_disable_unprepare(priv->usb2_trk_clk); in tegra186_utmi_bias_pad_power_off()
638 mutex_unlock(&padctl->lock); in tegra186_utmi_bias_pad_power_off()
641 static void tegra186_utmi_pad_power_on(struct phy *phy) in tegra186_utmi_pad_power_on() argument
643 struct tegra_xusb_lane *lane = phy_get_drvdata(phy); in tegra186_utmi_pad_power_on()
644 struct tegra_xusb_padctl *padctl = lane->pad->padctl; in tegra186_utmi_pad_power_on()
646 struct device *dev = padctl->dev; in tegra186_utmi_pad_power_on()
647 unsigned int index = lane->index; in tegra186_utmi_pad_power_on()
650 if (!phy) in tegra186_utmi_pad_power_on()
655 dev_err(dev, "no port found for USB2 lane %u\n", index); in tegra186_utmi_pad_power_on()
674 static void tegra186_utmi_pad_power_down(struct phy *phy) in tegra186_utmi_pad_power_down() argument
676 struct tegra_xusb_lane *lane = phy_get_drvdata(phy); in tegra186_utmi_pad_power_down()
677 struct tegra_xusb_padctl *padctl = lane->pad->padctl; in tegra186_utmi_pad_power_down()
678 unsigned int index = lane->index; in tegra186_utmi_pad_power_down()
681 if (!phy) in tegra186_utmi_pad_power_down()
684 dev_dbg(padctl->dev, "power down UTMI pad %u\n", index); in tegra186_utmi_pad_power_down()
704 dev_dbg(padctl->dev, "%s vbus override\n", status ? "set" : "clear"); in tegra186_xusb_padctl_vbus_override()
726 dev_dbg(padctl->dev, "%s id override\n", status ? "set" : "clear"); in tegra186_xusb_padctl_id_override()
751 static int tegra186_utmi_phy_set_mode(struct phy *phy, enum phy_mode mode, in tegra186_utmi_phy_set_mode() argument
754 struct tegra_xusb_lane *lane = phy_get_drvdata(phy); in tegra186_utmi_phy_set_mode()
755 struct tegra_xusb_padctl *padctl = lane->pad->padctl; in tegra186_utmi_phy_set_mode()
757 lane->index); in tegra186_utmi_phy_set_mode()
760 mutex_lock(&padctl->lock); in tegra186_utmi_phy_set_mode()
762 dev_dbg(&port->base.dev, "%s: mode %d", __func__, mode); in tegra186_utmi_phy_set_mode()
768 err = regulator_enable(port->supply); in tegra186_utmi_phy_set_mode()
777 if (regulator_is_enabled(port->supply)) in tegra186_utmi_phy_set_mode()
778 regulator_disable(port->supply); in tegra186_utmi_phy_set_mode()
785 mutex_unlock(&padctl->lock); in tegra186_utmi_phy_set_mode()
790 static int tegra186_utmi_phy_power_on(struct phy *phy) in tegra186_utmi_phy_power_on() argument
792 struct tegra_xusb_lane *lane = phy_get_drvdata(phy); in tegra186_utmi_phy_power_on()
793 struct tegra_xusb_usb2_lane *usb2 = to_usb2_lane(lane); in tegra186_utmi_phy_power_on() local
794 struct tegra_xusb_padctl *padctl = lane->pad->padctl; in tegra186_utmi_phy_power_on()
797 unsigned int index = lane->index; in tegra186_utmi_phy_power_on()
798 struct device *dev = padctl->dev; in tegra186_utmi_phy_power_on()
803 dev_err(dev, "no port found for USB2 lane %u\n", index); in tegra186_utmi_phy_power_on()
804 return -ENODEV; in tegra186_utmi_phy_power_on()
815 if (port->mode == USB_DR_MODE_UNKNOWN) in tegra186_utmi_phy_power_on()
817 else if (port->mode == USB_DR_MODE_PERIPHERAL) in tegra186_utmi_phy_power_on()
819 else if (port->mode == USB_DR_MODE_HOST) in tegra186_utmi_phy_power_on()
821 else if (port->mode == USB_DR_MODE_OTG) in tegra186_utmi_phy_power_on()
831 if (usb2->hs_curr_level_offset) { in tegra186_utmi_phy_power_on()
834 hs_current_level = (int)priv->calib.hs_curr_level[index] + in tegra186_utmi_phy_power_on()
835 usb2->hs_curr_level_offset; in tegra186_utmi_phy_power_on()
844 value |= HS_CURR_LEVEL(priv->calib.hs_curr_level[index]); in tegra186_utmi_phy_power_on()
851 value |= TERM_RANGE_ADJ(priv->calib.hs_term_range_adj); in tegra186_utmi_phy_power_on()
853 value |= RPD_CTRL(priv->calib.rpd_ctrl); in tegra186_utmi_phy_power_on()
856 tegra186_utmi_pad_power_on(phy); in tegra186_utmi_phy_power_on()
861 static int tegra186_utmi_phy_power_off(struct phy *phy) in tegra186_utmi_phy_power_off() argument
863 tegra186_utmi_pad_power_down(phy); in tegra186_utmi_phy_power_off()
868 static int tegra186_utmi_phy_init(struct phy *phy) in tegra186_utmi_phy_init() argument
870 struct tegra_xusb_lane *lane = phy_get_drvdata(phy); in tegra186_utmi_phy_init()
871 struct tegra_xusb_padctl *padctl = lane->pad->padctl; in tegra186_utmi_phy_init()
873 unsigned int index = lane->index; in tegra186_utmi_phy_init()
874 struct device *dev = padctl->dev; in tegra186_utmi_phy_init()
879 dev_err(dev, "no port found for USB2 lane %u\n", index); in tegra186_utmi_phy_init()
880 return -ENODEV; in tegra186_utmi_phy_init()
883 if (port->supply && port->mode == USB_DR_MODE_HOST) { in tegra186_utmi_phy_init()
884 err = regulator_enable(port->supply); in tegra186_utmi_phy_init()
895 static int tegra186_utmi_phy_exit(struct phy *phy) in tegra186_utmi_phy_exit() argument
897 struct tegra_xusb_lane *lane = phy_get_drvdata(phy); in tegra186_utmi_phy_exit()
898 struct tegra_xusb_padctl *padctl = lane->pad->padctl; in tegra186_utmi_phy_exit()
900 unsigned int index = lane->index; in tegra186_utmi_phy_exit()
901 struct device *dev = padctl->dev; in tegra186_utmi_phy_exit()
906 dev_err(dev, "no port found for USB2 lane %u\n", index); in tegra186_utmi_phy_exit()
907 return -ENODEV; in tegra186_utmi_phy_exit()
910 if (port->supply && port->mode == USB_DR_MODE_HOST) { in tegra186_utmi_phy_exit()
911 err = regulator_disable(port->supply); in tegra186_utmi_phy_exit()
937 struct tegra_xusb_usb2_pad *usb2; in tegra186_usb2_pad_probe() local
941 usb2 = kzalloc(sizeof(*usb2), GFP_KERNEL); in tegra186_usb2_pad_probe()
942 if (!usb2) in tegra186_usb2_pad_probe()
943 return ERR_PTR(-ENOMEM); in tegra186_usb2_pad_probe()
945 pad = &usb2->base; in tegra186_usb2_pad_probe()
946 pad->ops = &tegra186_usb2_lane_ops; in tegra186_usb2_pad_probe()
947 pad->soc = soc; in tegra186_usb2_pad_probe()
951 kfree(usb2); in tegra186_usb2_pad_probe()
955 priv->usb2_trk_clk = devm_clk_get(&pad->dev, "trk"); in tegra186_usb2_pad_probe()
956 if (IS_ERR(priv->usb2_trk_clk)) { in tegra186_usb2_pad_probe()
957 err = PTR_ERR(priv->usb2_trk_clk); in tegra186_usb2_pad_probe()
958 dev_dbg(&pad->dev, "failed to get usb2 trk clock: %d\n", err); in tegra186_usb2_pad_probe()
966 dev_set_drvdata(&pad->dev, pad); in tegra186_usb2_pad_probe()
971 device_unregister(&pad->dev); in tegra186_usb2_pad_probe()
978 struct tegra_xusb_usb2_pad *usb2 = to_usb2_pad(pad); in tegra186_usb2_pad_remove() local
980 kfree(usb2); in tegra186_usb2_pad_remove()
1004 return tegra_xusb_find_lane(port->padctl, "usb2", port->index); in tegra186_usb2_port_map()
1015 /* SuperSpeed PHY support */
1025 return ERR_PTR(-ENOMEM); in tegra186_usb3_lane_probe()
1027 INIT_LIST_HEAD(&usb3->base.list); in tegra186_usb3_lane_probe()
1028 usb3->base.soc = &pad->soc->lanes[index]; in tegra186_usb3_lane_probe()
1029 usb3->base.index = index; in tegra186_usb3_lane_probe()
1030 usb3->base.pad = pad; in tegra186_usb3_lane_probe()
1031 usb3->base.np = np; in tegra186_usb3_lane_probe()
1033 err = tegra_xusb_lane_parse_dt(&usb3->base, np); in tegra186_usb3_lane_probe()
1039 return &usb3->base; in tegra186_usb3_lane_probe()
1052 struct tegra_xusb_padctl *padctl = lane->pad->padctl; in tegra186_usb3_enable_phy_sleepwalk()
1053 unsigned int index = lane->index; in tegra186_usb3_enable_phy_sleepwalk()
1056 mutex_lock(&padctl->lock); in tegra186_usb3_enable_phy_sleepwalk()
1070 mutex_unlock(&padctl->lock); in tegra186_usb3_enable_phy_sleepwalk()
1077 struct tegra_xusb_padctl *padctl = lane->pad->padctl; in tegra186_usb3_disable_phy_sleepwalk()
1078 unsigned int index = lane->index; in tegra186_usb3_disable_phy_sleepwalk()
1081 mutex_lock(&padctl->lock); in tegra186_usb3_disable_phy_sleepwalk()
1093 mutex_unlock(&padctl->lock); in tegra186_usb3_disable_phy_sleepwalk()
1100 struct tegra_xusb_padctl *padctl = lane->pad->padctl; in tegra186_usb3_enable_phy_wake()
1101 unsigned int index = lane->index; in tegra186_usb3_enable_phy_wake()
1104 mutex_lock(&padctl->lock); in tegra186_usb3_enable_phy_wake()
1118 mutex_unlock(&padctl->lock); in tegra186_usb3_enable_phy_wake()
1125 struct tegra_xusb_padctl *padctl = lane->pad->padctl; in tegra186_usb3_disable_phy_wake()
1126 unsigned int index = lane->index; in tegra186_usb3_disable_phy_wake()
1129 mutex_lock(&padctl->lock); in tegra186_usb3_disable_phy_wake()
1143 mutex_unlock(&padctl->lock); in tegra186_usb3_disable_phy_wake()
1150 struct tegra_xusb_padctl *padctl = lane->pad->padctl; in tegra186_usb3_phy_remote_wake_detected()
1151 unsigned int index = lane->index; in tegra186_usb3_phy_remote_wake_detected()
1183 return tegra_xusb_find_lane(port->padctl, "usb3", port->index); in tegra186_usb3_port_map()
1194 static int tegra186_usb3_phy_power_on(struct phy *phy) in tegra186_usb3_phy_power_on() argument
1196 struct tegra_xusb_lane *lane = phy_get_drvdata(phy); in tegra186_usb3_phy_power_on()
1197 struct tegra_xusb_padctl *padctl = lane->pad->padctl; in tegra186_usb3_phy_power_on()
1199 struct tegra_xusb_usb2_port *usb2; in tegra186_usb3_phy_power_on() local
1200 unsigned int index = lane->index; in tegra186_usb3_phy_power_on()
1201 struct device *dev = padctl->dev; in tegra186_usb3_phy_power_on()
1207 return -ENODEV; in tegra186_usb3_phy_power_on()
1210 usb2 = tegra_xusb_find_usb2_port(padctl, port->port); in tegra186_usb3_phy_power_on()
1211 if (!usb2) { in tegra186_usb3_phy_power_on()
1214 return -ENODEV; in tegra186_usb3_phy_power_on()
1217 mutex_lock(&padctl->lock); in tegra186_usb3_phy_power_on()
1222 if (usb2->mode == USB_DR_MODE_UNKNOWN) in tegra186_usb3_phy_power_on()
1224 else if (usb2->mode == USB_DR_MODE_PERIPHERAL) in tegra186_usb3_phy_power_on()
1226 else if (usb2->mode == USB_DR_MODE_HOST) in tegra186_usb3_phy_power_on()
1228 else if (usb2->mode == USB_DR_MODE_OTG) in tegra186_usb3_phy_power_on()
1233 if (padctl->soc->supports_gen2 && port->disable_gen2) { in tegra186_usb3_phy_power_on()
1258 mutex_unlock(&padctl->lock); in tegra186_usb3_phy_power_on()
1263 static int tegra186_usb3_phy_power_off(struct phy *phy) in tegra186_usb3_phy_power_off() argument
1265 struct tegra_xusb_lane *lane = phy_get_drvdata(phy); in tegra186_usb3_phy_power_off()
1266 struct tegra_xusb_padctl *padctl = lane->pad->padctl; in tegra186_usb3_phy_power_off()
1268 unsigned int index = lane->index; in tegra186_usb3_phy_power_off()
1269 struct device *dev = padctl->dev; in tegra186_usb3_phy_power_off()
1275 return -ENODEV; in tegra186_usb3_phy_power_off()
1278 mutex_lock(&padctl->lock); in tegra186_usb3_phy_power_off()
1296 mutex_unlock(&padctl->lock); in tegra186_usb3_phy_power_off()
1301 static int tegra186_usb3_phy_init(struct phy *phy) in tegra186_usb3_phy_init() argument
1306 static int tegra186_usb3_phy_exit(struct phy *phy) in tegra186_usb3_phy_exit() argument
1330 return ERR_PTR(-ENOMEM); in tegra186_usb3_pad_probe()
1332 pad = &usb3->base; in tegra186_usb3_pad_probe()
1333 pad->ops = &tegra186_usb3_lane_ops; in tegra186_usb3_pad_probe()
1334 pad->soc = soc; in tegra186_usb3_pad_probe()
1346 dev_set_drvdata(&pad->dev, pad); in tegra186_usb3_pad_probe()
1351 device_unregister(&pad->dev); in tegra186_usb3_pad_probe()
1358 struct tegra_xusb_usb2_pad *usb2 = to_usb2_pad(pad); in tegra186_usb3_pad_remove() local
1360 kfree(usb2); in tegra186_usb3_pad_remove()
1375 struct device *dev = padctl->base.dev; in tegra186_xusb_read_fuse_calibration()
1380 count = padctl->base.soc->ports.usb2.count; in tegra186_xusb_read_fuse_calibration()
1384 return -ENOMEM; in tegra186_xusb_read_fuse_calibration()
1397 padctl->calib.hs_curr_level = level; in tegra186_xusb_read_fuse_calibration()
1399 padctl->calib.hs_squelch = (value >> HS_SQUELCH_SHIFT) & in tegra186_xusb_read_fuse_calibration()
1401 padctl->calib.hs_term_range_adj = (value >> HS_TERM_RANGE_ADJ_SHIFT) & in tegra186_xusb_read_fuse_calibration()
1412 padctl->calib.rpd_ctrl = (value >> RPD_CTRL_SHIFT) & RPD_CTRL_MASK; in tegra186_xusb_read_fuse_calibration()
1428 return ERR_PTR(-ENOMEM); in tegra186_xusb_padctl_probe()
1430 priv->base.dev = dev; in tegra186_xusb_padctl_probe()
1431 priv->base.soc = soc; in tegra186_xusb_padctl_probe()
1434 priv->ao_regs = devm_ioremap_resource(dev, res); in tegra186_xusb_padctl_probe()
1435 if (IS_ERR(priv->ao_regs)) in tegra186_xusb_padctl_probe()
1436 return ERR_CAST(priv->ao_regs); in tegra186_xusb_padctl_probe()
1442 return &priv->base; in tegra186_xusb_padctl_probe()
1449 priv->context.vbus_id = padctl_readl(padctl, USB2_VBUS_ID); in tegra186_xusb_padctl_save()
1450 priv->context.usb2_pad_mux = padctl_readl(padctl, XUSB_PADCTL_USB2_PAD_MUX); in tegra186_xusb_padctl_save()
1451 priv->context.usb2_port_cap = padctl_readl(padctl, XUSB_PADCTL_USB2_PORT_CAP); in tegra186_xusb_padctl_save()
1452 priv->context.ss_port_cap = padctl_readl(padctl, XUSB_PADCTL_SS_PORT_CAP); in tegra186_xusb_padctl_save()
1459 padctl_writel(padctl, priv->context.usb2_pad_mux, XUSB_PADCTL_USB2_PAD_MUX); in tegra186_xusb_padctl_restore()
1460 padctl_writel(padctl, priv->context.usb2_port_cap, XUSB_PADCTL_USB2_PORT_CAP); in tegra186_xusb_padctl_restore()
1461 padctl_writel(padctl, priv->context.ss_port_cap, XUSB_PADCTL_SS_PORT_CAP); in tegra186_xusb_padctl_restore()
1462 padctl_writel(padctl, priv->context.vbus_id, USB2_VBUS_ID); in tegra186_xusb_padctl_restore()
1495 "avdd-pll-erefeut",
1496 "avdd-usb",
1497 "vclamp-usb",
1498 "vddio-hsic",
1502 TEGRA186_LANE("usb2-0", 0, 0, 0, usb2),
1503 TEGRA186_LANE("usb2-1", 0, 0, 0, usb2),
1504 TEGRA186_LANE("usb2-2", 0, 0, 0, usb2),
1508 .name = "usb2",
1515 TEGRA186_LANE("usb3-0", 0, 0, 0, usb3),
1516 TEGRA186_LANE("usb3-1", 0, 0, 0, usb3),
1517 TEGRA186_LANE("usb3-2", 0, 0, 0, usb3),
1539 .usb2 = {
1563 "avdd-usb",
1564 "vclamp-usb",
1568 TEGRA186_LANE("usb2-0", 0, 0, 0, usb2),
1569 TEGRA186_LANE("usb2-1", 0, 0, 0, usb2),
1570 TEGRA186_LANE("usb2-2", 0, 0, 0, usb2),
1571 TEGRA186_LANE("usb2-3", 0, 0, 0, usb2),
1575 .name = "usb2",
1582 TEGRA186_LANE("usb3-0", 0, 0, 0, usb3),
1583 TEGRA186_LANE("usb3-1", 0, 0, 0, usb3),
1584 TEGRA186_LANE("usb3-2", 0, 0, 0, usb3),
1585 TEGRA186_LANE("usb3-3", 0, 0, 0, usb3),
1604 .usb2 = {