Lines Matching +full:port +full:- +full:base
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2014-2022, NVIDIA CORPORATION. All rights reserved.
31 if (args->args_count != 0) in tegra_xusb_pad_of_xlate()
32 return ERR_PTR(-EINVAL); in tegra_xusb_pad_of_xlate()
34 for (i = 0; i < pad->soc->num_lanes; i++) { in tegra_xusb_pad_of_xlate()
35 if (!pad->lanes[i]) in tegra_xusb_pad_of_xlate()
38 if (pad->lanes[i]->dev.of_node == args->np) { in tegra_xusb_pad_of_xlate()
39 phy = pad->lanes[i]; in tegra_xusb_pad_of_xlate()
45 phy = ERR_PTR(-ENODEV); in tegra_xusb_pad_of_xlate()
53 .compatible = "nvidia,tegra124-xusb-padctl",
59 .compatible = "nvidia,tegra210-xusb-padctl",
65 .compatible = "nvidia,tegra186-xusb-padctl",
71 .compatible = "nvidia,tegra194-xusb-padctl",
77 .compatible = "nvidia,tegra234-xusb-padctl",
90 pads = of_get_child_by_name(padctl->dev->of_node, "pads"); in tegra_xusb_find_pad_node()
105 lanes = of_get_child_by_name(pad->dev.of_node, "lanes"); in tegra_xusb_pad_find_phy_node()
109 np = of_get_child_by_name(lanes, pad->soc->lanes[index].name); in tegra_xusb_pad_find_phy_node()
118 struct device *dev = &lane->pad->dev; in tegra_xusb_lane_parse_dt()
126 err = match_string(lane->soc->funcs, lane->soc->num_funcs, function); in tegra_xusb_lane_parse_dt()
133 lane->function = err; in tegra_xusb_lane_parse_dt()
143 lane->pad->ops->remove(lane); in tegra_xusb_lane_destroy()
152 pad->soc->ops->remove(pad); in tegra_xusb_pad_release()
165 device_initialize(&pad->dev); in tegra_xusb_pad_init()
166 INIT_LIST_HEAD(&pad->list); in tegra_xusb_pad_init()
167 pad->dev.parent = padctl->dev; in tegra_xusb_pad_init()
168 pad->dev.type = &tegra_xusb_pad_type; in tegra_xusb_pad_init()
169 pad->dev.of_node = np; in tegra_xusb_pad_init()
170 pad->padctl = padctl; in tegra_xusb_pad_init()
172 err = dev_set_name(&pad->dev, "%s", pad->soc->name); in tegra_xusb_pad_init()
176 err = device_add(&pad->dev); in tegra_xusb_pad_init()
183 device_unregister(&pad->dev); in tegra_xusb_pad_init()
195 children = of_get_child_by_name(pad->dev.of_node, "lanes"); in tegra_xusb_pad_register()
197 return -ENODEV; in tegra_xusb_pad_register()
199 pad->lanes = devm_kcalloc(&pad->dev, pad->soc->num_lanes, sizeof(lane), in tegra_xusb_pad_register()
201 if (!pad->lanes) { in tegra_xusb_pad_register()
203 return -ENOMEM; in tegra_xusb_pad_register()
206 for (i = 0; i < pad->soc->num_lanes; i++) { in tegra_xusb_pad_register()
216 pad->lanes[i] = phy_create(&pad->dev, np, ops); in tegra_xusb_pad_register()
217 if (IS_ERR(pad->lanes[i])) { in tegra_xusb_pad_register()
218 err = PTR_ERR(pad->lanes[i]); in tegra_xusb_pad_register()
223 lane = pad->ops->probe(pad, np, i); in tegra_xusb_pad_register()
225 phy_destroy(pad->lanes[i]); in tegra_xusb_pad_register()
230 list_add_tail(&lane->list, &pad->padctl->lanes); in tegra_xusb_pad_register()
231 phy_set_drvdata(pad->lanes[i], lane); in tegra_xusb_pad_register()
234 pad->provider = of_phy_provider_register_full(&pad->dev, children, in tegra_xusb_pad_register()
236 if (IS_ERR(pad->provider)) { in tegra_xusb_pad_register()
237 err = PTR_ERR(pad->provider); in tegra_xusb_pad_register()
244 while (i--) in tegra_xusb_pad_register()
245 tegra_xusb_lane_destroy(pad->lanes[i]); in tegra_xusb_pad_register()
254 unsigned int i = pad->soc->num_lanes; in tegra_xusb_pad_unregister()
256 of_phy_provider_unregister(pad->provider); in tegra_xusb_pad_unregister()
258 while (i--) in tegra_xusb_pad_unregister()
259 tegra_xusb_lane_destroy(pad->lanes[i]); in tegra_xusb_pad_unregister()
261 device_unregister(&pad->dev); in tegra_xusb_pad_unregister()
272 np = tegra_xusb_find_pad_node(padctl, soc->name); in tegra_xusb_pad_create()
276 pad = soc->ops->probe(padctl, soc, np); in tegra_xusb_pad_create()
279 dev_err(padctl->dev, "failed to create pad %s: %d\n", in tegra_xusb_pad_create()
280 soc->name, err); in tegra_xusb_pad_create()
284 /* XXX move this into ->probe() to avoid string comparison */ in tegra_xusb_pad_create()
285 if (strcmp(soc->name, "pcie") == 0) in tegra_xusb_pad_create()
286 padctl->pcie = pad; in tegra_xusb_pad_create()
288 if (strcmp(soc->name, "sata") == 0) in tegra_xusb_pad_create()
289 padctl->sata = pad; in tegra_xusb_pad_create()
291 if (strcmp(soc->name, "usb2") == 0) in tegra_xusb_pad_create()
292 padctl->usb2 = pad; in tegra_xusb_pad_create()
294 if (strcmp(soc->name, "ulpi") == 0) in tegra_xusb_pad_create()
295 padctl->ulpi = pad; in tegra_xusb_pad_create()
297 if (strcmp(soc->name, "hsic") == 0) in tegra_xusb_pad_create()
298 padctl->hsic = pad; in tegra_xusb_pad_create()
307 list_for_each_entry_safe_reverse(pad, tmp, &padctl->pads, list) { in __tegra_xusb_remove_pads()
308 list_del(&pad->list); in __tegra_xusb_remove_pads()
315 mutex_lock(&padctl->lock); in tegra_xusb_remove_pads()
317 mutex_unlock(&padctl->lock); in tegra_xusb_remove_pads()
322 struct tegra_xusb_padctl *padctl = lane->pad->padctl; in tegra_xusb_lane_program()
323 const struct tegra_xusb_lane_soc *soc = lane->soc; in tegra_xusb_lane_program()
327 if (soc->num_funcs < 2) in tegra_xusb_lane_program()
330 if (lane->pad->ops->iddq_enable) in tegra_xusb_lane_program()
331 lane->pad->ops->iddq_enable(lane); in tegra_xusb_lane_program()
334 value = padctl_readl(padctl, soc->offset); in tegra_xusb_lane_program()
335 value &= ~(soc->mask << soc->shift); in tegra_xusb_lane_program()
336 value |= lane->function << soc->shift; in tegra_xusb_lane_program()
337 padctl_writel(padctl, value, soc->offset); in tegra_xusb_lane_program()
339 if (lane->pad->ops->iddq_disable) in tegra_xusb_lane_program()
340 lane->pad->ops->iddq_disable(lane); in tegra_xusb_lane_program()
347 for (i = 0; i < pad->soc->num_lanes; i++) { in tegra_xusb_pad_program()
350 if (pad->lanes[i]) { in tegra_xusb_pad_program()
351 lane = phy_get_drvdata(pad->lanes[i]); in tegra_xusb_pad_program()
362 mutex_lock(&padctl->lock); in tegra_xusb_setup_pads()
364 for (i = 0; i < padctl->soc->num_pads; i++) { in tegra_xusb_setup_pads()
365 const struct tegra_xusb_pad_soc *soc = padctl->soc->pads[i]; in tegra_xusb_setup_pads()
371 dev_err(padctl->dev, "failed to create pad %s: %d\n", in tegra_xusb_setup_pads()
372 soc->name, err); in tegra_xusb_setup_pads()
374 mutex_unlock(&padctl->lock); in tegra_xusb_setup_pads()
381 list_add_tail(&pad->list, &padctl->pads); in tegra_xusb_setup_pads()
384 list_for_each_entry(pad, &padctl->pads, list) in tegra_xusb_setup_pads()
387 mutex_unlock(&padctl->lock); in tegra_xusb_setup_pads()
394 const char *func = lane->soc->funcs[lane->function]; in tegra_xusb_lane_check()
403 struct tegra_xusb_lane *lane, *hit = ERR_PTR(-ENODEV); in tegra_xusb_find_lane()
406 name = kasprintf(GFP_KERNEL, "%s-%u", type, index); in tegra_xusb_find_lane()
408 return ERR_PTR(-ENOMEM); in tegra_xusb_find_lane()
410 list_for_each_entry(lane, &padctl->lanes, list) { in tegra_xusb_find_lane()
411 if (strcmp(lane->soc->name, name) == 0) { in tegra_xusb_find_lane()
422 tegra_xusb_port_find_lane(struct tegra_xusb_port *port, in tegra_xusb_port_find_lane() argument
426 struct tegra_xusb_lane *lane, *match = ERR_PTR(-ENODEV); in tegra_xusb_port_find_lane()
428 for (; map->type; map++) { in tegra_xusb_port_find_lane()
429 if (port->index != map->port) in tegra_xusb_port_find_lane()
432 lane = tegra_xusb_find_lane(port->padctl, map->type, in tegra_xusb_port_find_lane()
433 map->index); in tegra_xusb_port_find_lane()
441 dev_err(&port->dev, "conflicting match: %s-%u / %s\n", in tegra_xusb_port_find_lane()
442 map->type, map->index, match->soc->name); in tegra_xusb_port_find_lane()
457 ports = of_get_child_by_name(padctl->dev->of_node, "ports"); in tegra_xusb_find_port_node()
461 name = kasprintf(GFP_KERNEL, "%s-%u", type, index); in tegra_xusb_find_port_node()
477 struct tegra_xusb_port *port; in tegra_xusb_find_port() local
484 list_for_each_entry(port, &padctl->ports, list) { in tegra_xusb_find_port()
485 if (np == port->dev.of_node) { in tegra_xusb_find_port()
487 return port; in tegra_xusb_find_port()
499 struct tegra_xusb_port *port; in tegra_xusb_find_usb2_port() local
501 port = tegra_xusb_find_port(padctl, "usb2", index); in tegra_xusb_find_usb2_port()
502 if (port) in tegra_xusb_find_usb2_port()
503 return to_usb2_port(port); in tegra_xusb_find_usb2_port()
511 struct tegra_xusb_port *port; in tegra_xusb_find_usb3_port() local
513 port = tegra_xusb_find_port(padctl, "usb3", index); in tegra_xusb_find_usb3_port()
514 if (port) in tegra_xusb_find_usb3_port()
515 return to_usb3_port(port); in tegra_xusb_find_usb3_port()
522 struct tegra_xusb_port *port = to_tegra_xusb_port(dev); in tegra_xusb_port_release() local
524 if (port->ops->release) in tegra_xusb_port_release()
525 port->ops->release(port); in tegra_xusb_port_release()
532 static int tegra_xusb_port_init(struct tegra_xusb_port *port, in tegra_xusb_port_init() argument
540 INIT_LIST_HEAD(&port->list); in tegra_xusb_port_init()
541 port->padctl = padctl; in tegra_xusb_port_init()
542 port->index = index; in tegra_xusb_port_init()
544 device_initialize(&port->dev); in tegra_xusb_port_init()
545 port->dev.type = &tegra_xusb_port_type; in tegra_xusb_port_init()
546 port->dev.of_node = of_node_get(np); in tegra_xusb_port_init()
547 port->dev.parent = padctl->dev; in tegra_xusb_port_init()
549 err = dev_set_name(&port->dev, "%s-%u", name, index); in tegra_xusb_port_init()
553 err = device_add(&port->dev); in tegra_xusb_port_init()
560 device_unregister(&port->dev); in tegra_xusb_port_init()
564 static void tegra_xusb_port_unregister(struct tegra_xusb_port *port) in tegra_xusb_port_unregister() argument
566 if (!IS_ERR_OR_NULL(port->usb_role_sw)) { in tegra_xusb_port_unregister()
567 of_platform_depopulate(&port->dev); in tegra_xusb_port_unregister()
568 usb_role_switch_unregister(port->usb_role_sw); in tegra_xusb_port_unregister()
569 cancel_work_sync(&port->usb_phy_work); in tegra_xusb_port_unregister()
570 usb_remove_phy(&port->usb_phy); in tegra_xusb_port_unregister()
571 port->usb_phy.dev->driver = NULL; in tegra_xusb_port_unregister()
574 if (port->ops->remove) in tegra_xusb_port_unregister()
575 port->ops->remove(port); in tegra_xusb_port_unregister()
577 device_unregister(&port->dev); in tegra_xusb_port_unregister()
609 struct tegra_xusb_port *port = container_of(work, in tegra_xusb_usb_phy_work() local
612 enum usb_role role = usb_role_switch_get_role(port->usb_role_sw); in tegra_xusb_usb_phy_work()
614 usb_phy_set_event(&port->usb_phy, to_usb_phy_event(role)); in tegra_xusb_usb_phy_work()
616 dev_dbg(&port->dev, "%s(): calling notifier for role %s\n", __func__, in tegra_xusb_usb_phy_work()
619 atomic_notifier_call_chain(&port->usb_phy.notifier, 0, &port->usb_phy); in tegra_xusb_usb_phy_work()
625 struct tegra_xusb_port *port = usb_role_switch_get_drvdata(sw); in tegra_xusb_role_sw_set() local
627 dev_dbg(&port->dev, "%s(): role %s\n", __func__, usb_roles[role]); in tegra_xusb_role_sw_set()
629 schedule_work(&port->usb_phy_work); in tegra_xusb_role_sw_set()
637 struct tegra_xusb_port *port = container_of(otg->usb_phy, in tegra_xusb_set_peripheral() local
642 schedule_work(&port->usb_phy_work); in tegra_xusb_set_peripheral()
649 struct tegra_xusb_port *port = container_of(otg->usb_phy, in tegra_xusb_set_host() local
654 schedule_work(&port->usb_phy_work); in tegra_xusb_set_host()
660 static int tegra_xusb_setup_usb_role_switch(struct tegra_xusb_port *port) in tegra_xusb_setup_usb_role_switch() argument
664 .fwnode = dev_fwnode(&port->dev), in tegra_xusb_setup_usb_role_switch()
672 * suboptimal solution. TODO: Need to revisit this in a follow-up patch in tegra_xusb_setup_usb_role_switch()
676 port->dev.driver = devm_kzalloc(&port->dev, in tegra_xusb_setup_usb_role_switch()
679 if (!port->dev.driver) in tegra_xusb_setup_usb_role_switch()
680 return -ENOMEM; in tegra_xusb_setup_usb_role_switch()
682 port->dev.driver->owner = THIS_MODULE; in tegra_xusb_setup_usb_role_switch()
684 port->usb_role_sw = usb_role_switch_register(&port->dev, in tegra_xusb_setup_usb_role_switch()
686 if (IS_ERR(port->usb_role_sw)) { in tegra_xusb_setup_usb_role_switch()
687 err = PTR_ERR(port->usb_role_sw); in tegra_xusb_setup_usb_role_switch()
688 dev_err(&port->dev, "failed to register USB role switch: %d", in tegra_xusb_setup_usb_role_switch()
693 INIT_WORK(&port->usb_phy_work, tegra_xusb_usb_phy_work); in tegra_xusb_setup_usb_role_switch()
694 usb_role_switch_set_drvdata(port->usb_role_sw, port); in tegra_xusb_setup_usb_role_switch()
696 port->usb_phy.otg = devm_kzalloc(&port->dev, sizeof(struct usb_otg), in tegra_xusb_setup_usb_role_switch()
698 if (!port->usb_phy.otg) in tegra_xusb_setup_usb_role_switch()
699 return -ENOMEM; in tegra_xusb_setup_usb_role_switch()
701 lane = tegra_xusb_find_lane(port->padctl, "usb2", port->index); in tegra_xusb_setup_usb_role_switch()
704 * Assign phy dev to usb-phy dev. Host/device drivers can use phy in tegra_xusb_setup_usb_role_switch()
705 * reference to retrieve usb-phy details. in tegra_xusb_setup_usb_role_switch()
707 port->usb_phy.dev = &lane->pad->lanes[port->index]->dev; in tegra_xusb_setup_usb_role_switch()
708 port->usb_phy.dev->driver = port->dev.driver; in tegra_xusb_setup_usb_role_switch()
709 port->usb_phy.otg->usb_phy = &port->usb_phy; in tegra_xusb_setup_usb_role_switch()
710 port->usb_phy.otg->set_peripheral = tegra_xusb_set_peripheral; in tegra_xusb_setup_usb_role_switch()
711 port->usb_phy.otg->set_host = tegra_xusb_set_host; in tegra_xusb_setup_usb_role_switch()
713 err = usb_add_phy_dev(&port->usb_phy); in tegra_xusb_setup_usb_role_switch()
715 dev_err(&port->dev, "Failed to add USB PHY: %d\n", err); in tegra_xusb_setup_usb_role_switch()
720 of_platform_populate(port->dev.of_node, NULL, NULL, &port->dev); in tegra_xusb_setup_usb_role_switch()
725 static void tegra_xusb_parse_usb_role_default_mode(struct tegra_xusb_port *port) in tegra_xusb_parse_usb_role_default_mode() argument
728 enum usb_dr_mode mode = usb_get_role_switch_default_mode(&port->dev); in tegra_xusb_parse_usb_role_default_mode()
736 usb_role_switch_set_role(port->usb_role_sw, role); in tegra_xusb_parse_usb_role_default_mode()
737 dev_dbg(&port->dev, "usb role default mode is %s", modes[mode]); in tegra_xusb_parse_usb_role_default_mode()
743 struct tegra_xusb_port *port = &usb2->base; in tegra_xusb_usb2_port_parse_dt() local
744 struct device_node *np = port->dev.of_node; in tegra_xusb_usb2_port_parse_dt()
748 usb2->internal = of_property_read_bool(np, "nvidia,internal"); in tegra_xusb_usb2_port_parse_dt()
753 dev_err(&port->dev, "invalid value %s for \"mode\"\n", in tegra_xusb_usb2_port_parse_dt()
755 usb2->mode = USB_DR_MODE_UNKNOWN; in tegra_xusb_usb2_port_parse_dt()
757 usb2->mode = err; in tegra_xusb_usb2_port_parse_dt()
760 usb2->mode = USB_DR_MODE_HOST; in tegra_xusb_usb2_port_parse_dt()
763 /* usb-role-switch property is mandatory for OTG/Peripheral modes */ in tegra_xusb_usb2_port_parse_dt()
764 if (usb2->mode == USB_DR_MODE_PERIPHERAL || in tegra_xusb_usb2_port_parse_dt()
765 usb2->mode == USB_DR_MODE_OTG) { in tegra_xusb_usb2_port_parse_dt()
766 if (of_property_read_bool(np, "usb-role-switch")) { in tegra_xusb_usb2_port_parse_dt()
767 err = tegra_xusb_setup_usb_role_switch(port); in tegra_xusb_usb2_port_parse_dt()
770 tegra_xusb_parse_usb_role_default_mode(port); in tegra_xusb_usb2_port_parse_dt()
772 dev_err(&port->dev, "usb-role-switch not found for %s mode", in tegra_xusb_usb2_port_parse_dt()
773 modes[usb2->mode]); in tegra_xusb_usb2_port_parse_dt()
774 return -EINVAL; in tegra_xusb_usb2_port_parse_dt()
778 usb2->supply = regulator_get(&port->dev, "vbus"); in tegra_xusb_usb2_port_parse_dt()
779 return PTR_ERR_OR_ZERO(usb2->supply); in tegra_xusb_usb2_port_parse_dt()
790 * USB2 ports don't require additional properties, but if the port is in tegra_xusb_add_usb2_port()
799 err = -ENOMEM; in tegra_xusb_add_usb2_port()
803 err = tegra_xusb_port_init(&usb2->base, padctl, np, "usb2", index); in tegra_xusb_add_usb2_port()
807 usb2->base.ops = padctl->soc->ports.usb2.ops; in tegra_xusb_add_usb2_port()
809 usb2->base.lane = usb2->base.ops->map(&usb2->base); in tegra_xusb_add_usb2_port()
810 if (IS_ERR(usb2->base.lane)) { in tegra_xusb_add_usb2_port()
811 err = PTR_ERR(usb2->base.lane); in tegra_xusb_add_usb2_port()
812 tegra_xusb_port_unregister(&usb2->base); in tegra_xusb_add_usb2_port()
818 tegra_xusb_port_unregister(&usb2->base); in tegra_xusb_add_usb2_port()
822 list_add_tail(&usb2->base.list, &padctl->ports); in tegra_xusb_add_usb2_port()
829 void tegra_xusb_usb2_port_release(struct tegra_xusb_port *port) in tegra_xusb_usb2_port_release() argument
831 struct tegra_xusb_usb2_port *usb2 = to_usb2_port(port); in tegra_xusb_usb2_port_release()
836 void tegra_xusb_usb2_port_remove(struct tegra_xusb_port *port) in tegra_xusb_usb2_port_remove() argument
838 struct tegra_xusb_usb2_port *usb2 = to_usb2_port(port); in tegra_xusb_usb2_port_remove()
840 regulator_put(usb2->supply); in tegra_xusb_usb2_port_remove()
845 struct tegra_xusb_port *port = &ulpi->base; in tegra_xusb_ulpi_port_parse_dt() local
846 struct device_node *np = port->dev.of_node; in tegra_xusb_ulpi_port_parse_dt()
848 ulpi->internal = of_property_read_bool(np, "nvidia,internal"); in tegra_xusb_ulpi_port_parse_dt()
866 err = -ENOMEM; in tegra_xusb_add_ulpi_port()
870 err = tegra_xusb_port_init(&ulpi->base, padctl, np, "ulpi", index); in tegra_xusb_add_ulpi_port()
874 ulpi->base.ops = padctl->soc->ports.ulpi.ops; in tegra_xusb_add_ulpi_port()
876 ulpi->base.lane = ulpi->base.ops->map(&ulpi->base); in tegra_xusb_add_ulpi_port()
877 if (IS_ERR(ulpi->base.lane)) { in tegra_xusb_add_ulpi_port()
878 err = PTR_ERR(ulpi->base.lane); in tegra_xusb_add_ulpi_port()
879 tegra_xusb_port_unregister(&ulpi->base); in tegra_xusb_add_ulpi_port()
885 tegra_xusb_port_unregister(&ulpi->base); in tegra_xusb_add_ulpi_port()
889 list_add_tail(&ulpi->base.list, &padctl->ports); in tegra_xusb_add_ulpi_port()
896 void tegra_xusb_ulpi_port_release(struct tegra_xusb_port *port) in tegra_xusb_ulpi_port_release() argument
898 struct tegra_xusb_ulpi_port *ulpi = to_ulpi_port(port); in tegra_xusb_ulpi_port_release()
922 err = -ENOMEM; in tegra_xusb_add_hsic_port()
926 err = tegra_xusb_port_init(&hsic->base, padctl, np, "hsic", index); in tegra_xusb_add_hsic_port()
930 hsic->base.ops = padctl->soc->ports.hsic.ops; in tegra_xusb_add_hsic_port()
932 hsic->base.lane = hsic->base.ops->map(&hsic->base); in tegra_xusb_add_hsic_port()
933 if (IS_ERR(hsic->base.lane)) { in tegra_xusb_add_hsic_port()
934 err = PTR_ERR(hsic->base.lane); in tegra_xusb_add_hsic_port()
940 tegra_xusb_port_unregister(&hsic->base); in tegra_xusb_add_hsic_port()
944 list_add_tail(&hsic->base.list, &padctl->ports); in tegra_xusb_add_hsic_port()
951 void tegra_xusb_hsic_port_release(struct tegra_xusb_port *port) in tegra_xusb_hsic_port_release() argument
953 struct tegra_xusb_hsic_port *hsic = to_hsic_port(port); in tegra_xusb_hsic_port_release()
960 struct tegra_xusb_port *port = &usb3->base; in tegra_xusb_usb3_port_parse_dt() local
961 struct device_node *np = port->dev.of_node; in tegra_xusb_usb3_port_parse_dt()
966 err = of_property_read_u32(np, "nvidia,usb2-companion", &value); in tegra_xusb_usb3_port_parse_dt()
968 dev_err(&port->dev, "failed to read port: %d\n", err); in tegra_xusb_usb3_port_parse_dt()
972 usb3->port = value; in tegra_xusb_usb3_port_parse_dt()
974 usb3->internal = of_property_read_bool(np, "nvidia,internal"); in tegra_xusb_usb3_port_parse_dt()
976 if (device_property_present(&port->dev, "maximum-speed")) { in tegra_xusb_usb3_port_parse_dt()
977 maximum_speed = usb_get_maximum_speed(&port->dev); in tegra_xusb_usb3_port_parse_dt()
979 usb3->disable_gen2 = true; in tegra_xusb_usb3_port_parse_dt()
981 usb3->disable_gen2 = false; in tegra_xusb_usb3_port_parse_dt()
983 return -EINVAL; in tegra_xusb_usb3_port_parse_dt()
998 * port is unusable. But it is valid to configure only a single port, in tegra_xusb_add_usb3_port()
1007 err = -ENOMEM; in tegra_xusb_add_usb3_port()
1011 err = tegra_xusb_port_init(&usb3->base, padctl, np, "usb3", index); in tegra_xusb_add_usb3_port()
1015 usb3->base.ops = padctl->soc->ports.usb3.ops; in tegra_xusb_add_usb3_port()
1017 usb3->base.lane = usb3->base.ops->map(&usb3->base); in tegra_xusb_add_usb3_port()
1018 if (IS_ERR(usb3->base.lane)) { in tegra_xusb_add_usb3_port()
1019 err = PTR_ERR(usb3->base.lane); in tegra_xusb_add_usb3_port()
1025 tegra_xusb_port_unregister(&usb3->base); in tegra_xusb_add_usb3_port()
1029 list_add_tail(&usb3->base.list, &padctl->ports); in tegra_xusb_add_usb3_port()
1036 void tegra_xusb_usb3_port_release(struct tegra_xusb_port *port) in tegra_xusb_usb3_port_release() argument
1038 struct tegra_xusb_usb3_port *usb3 = to_usb3_port(port); in tegra_xusb_usb3_port_release()
1045 struct tegra_xusb_port *port, *tmp; in __tegra_xusb_remove_ports() local
1047 list_for_each_entry_safe_reverse(port, tmp, &padctl->ports, list) { in __tegra_xusb_remove_ports()
1048 list_del(&port->list); in __tegra_xusb_remove_ports()
1049 tegra_xusb_port_unregister(port); in __tegra_xusb_remove_ports()
1058 for (i = 0; i < padctl->soc->ports.usb3.count; i++) { in tegra_xusb_find_unused_usb3_port()
1064 return -ENODEV; in tegra_xusb_find_unused_usb3_port()
1071 struct tegra_xusb_padctl *padctl = usb2->base.padctl; in tegra_xusb_port_is_companion()
1073 for (i = 0; i < padctl->soc->ports.usb3.count; i++) { in tegra_xusb_port_is_companion()
1075 if (usb3 && usb3->port == usb2->base.index) in tegra_xusb_port_is_companion()
1087 usb2->usb3_port_fake = -1; in tegra_xusb_update_usb3_fake_port()
1089 if ((usb2->mode == USB_DR_MODE_OTG || in tegra_xusb_update_usb3_fake_port()
1090 usb2->mode == USB_DR_MODE_PERIPHERAL) && in tegra_xusb_update_usb3_fake_port()
1092 fake = tegra_xusb_find_unused_usb3_port(usb2->base.padctl); in tegra_xusb_update_usb3_fake_port()
1094 dev_err(&usb2->base.dev, "no unused USB3 ports available\n"); in tegra_xusb_update_usb3_fake_port()
1095 return -ENODEV; in tegra_xusb_update_usb3_fake_port()
1098 dev_dbg(&usb2->base.dev, "Found unused usb3 port: %d\n", fake); in tegra_xusb_update_usb3_fake_port()
1099 usb2->usb3_port_fake = fake; in tegra_xusb_update_usb3_fake_port()
1107 struct tegra_xusb_port *port; in tegra_xusb_setup_ports() local
1112 mutex_lock(&padctl->lock); in tegra_xusb_setup_ports()
1114 for (i = 0; i < padctl->soc->ports.usb2.count; i++) { in tegra_xusb_setup_ports()
1120 for (i = 0; i < padctl->soc->ports.ulpi.count; i++) { in tegra_xusb_setup_ports()
1126 for (i = 0; i < padctl->soc->ports.hsic.count; i++) { in tegra_xusb_setup_ports()
1132 for (i = 0; i < padctl->soc->ports.usb3.count; i++) { in tegra_xusb_setup_ports()
1138 if (padctl->soc->need_fake_usb3_port) { in tegra_xusb_setup_ports()
1139 for (i = 0; i < padctl->soc->ports.usb2.count; i++) { in tegra_xusb_setup_ports()
1150 list_for_each_entry(port, &padctl->ports, list) { in tegra_xusb_setup_ports()
1151 err = port->ops->enable(port); in tegra_xusb_setup_ports()
1153 dev_err(padctl->dev, "failed to enable port %s: %d\n", in tegra_xusb_setup_ports()
1154 dev_name(&port->dev), err); in tegra_xusb_setup_ports()
1162 mutex_unlock(&padctl->lock); in tegra_xusb_setup_ports()
1168 mutex_lock(&padctl->lock); in tegra_xusb_remove_ports()
1170 mutex_unlock(&padctl->lock); in tegra_xusb_remove_ports()
1175 struct device_node *np = pdev->dev.of_node; in tegra_xusb_padctl_probe()
1184 dev_warn(&pdev->dev, "deprecated DT, using legacy driver\n"); in tegra_xusb_padctl_probe()
1190 match = of_match_node(tegra_xusb_padctl_of_match, pdev->dev.of_node); in tegra_xusb_padctl_probe()
1191 soc = match->data; in tegra_xusb_padctl_probe()
1193 padctl = soc->ops->probe(&pdev->dev, soc); in tegra_xusb_padctl_probe()
1198 INIT_LIST_HEAD(&padctl->ports); in tegra_xusb_padctl_probe()
1199 INIT_LIST_HEAD(&padctl->lanes); in tegra_xusb_padctl_probe()
1200 INIT_LIST_HEAD(&padctl->pads); in tegra_xusb_padctl_probe()
1201 mutex_init(&padctl->lock); in tegra_xusb_padctl_probe()
1203 padctl->regs = devm_platform_ioremap_resource(pdev, 0); in tegra_xusb_padctl_probe()
1204 if (IS_ERR(padctl->regs)) { in tegra_xusb_padctl_probe()
1205 err = PTR_ERR(padctl->regs); in tegra_xusb_padctl_probe()
1209 padctl->rst = devm_reset_control_get(&pdev->dev, NULL); in tegra_xusb_padctl_probe()
1210 if (IS_ERR(padctl->rst)) { in tegra_xusb_padctl_probe()
1211 err = PTR_ERR(padctl->rst); in tegra_xusb_padctl_probe()
1215 padctl->supplies = devm_kcalloc(&pdev->dev, padctl->soc->num_supplies, in tegra_xusb_padctl_probe()
1216 sizeof(*padctl->supplies), GFP_KERNEL); in tegra_xusb_padctl_probe()
1217 if (!padctl->supplies) { in tegra_xusb_padctl_probe()
1218 err = -ENOMEM; in tegra_xusb_padctl_probe()
1222 regulator_bulk_set_supply_names(padctl->supplies, in tegra_xusb_padctl_probe()
1223 padctl->soc->supply_names, in tegra_xusb_padctl_probe()
1224 padctl->soc->num_supplies); in tegra_xusb_padctl_probe()
1226 err = devm_regulator_bulk_get(&pdev->dev, padctl->soc->num_supplies, in tegra_xusb_padctl_probe()
1227 padctl->supplies); in tegra_xusb_padctl_probe()
1229 dev_err_probe(&pdev->dev, err, "failed to get regulators\n"); in tegra_xusb_padctl_probe()
1233 err = reset_control_deassert(padctl->rst); in tegra_xusb_padctl_probe()
1237 err = regulator_bulk_enable(padctl->soc->num_supplies, in tegra_xusb_padctl_probe()
1238 padctl->supplies); in tegra_xusb_padctl_probe()
1240 dev_err(&pdev->dev, "failed to enable supplies: %d\n", err); in tegra_xusb_padctl_probe()
1246 dev_err(&pdev->dev, "failed to setup pads: %d\n", err); in tegra_xusb_padctl_probe()
1254 if (err == -EPROBE_DEFER) in tegra_xusb_padctl_probe()
1257 dev_printk(level, &pdev->dev, in tegra_xusb_padctl_probe()
1267 regulator_bulk_disable(padctl->soc->num_supplies, padctl->supplies); in tegra_xusb_padctl_probe()
1269 reset_control_assert(padctl->rst); in tegra_xusb_padctl_probe()
1272 soc->ops->remove(padctl); in tegra_xusb_padctl_probe()
1284 err = regulator_bulk_disable(padctl->soc->num_supplies, in tegra_xusb_padctl_remove()
1285 padctl->supplies); in tegra_xusb_padctl_remove()
1287 dev_err(&pdev->dev, "failed to disable supplies: %d\n", err); in tegra_xusb_padctl_remove()
1289 err = reset_control_assert(padctl->rst); in tegra_xusb_padctl_remove()
1291 dev_err(&pdev->dev, "failed to assert reset: %d\n", err); in tegra_xusb_padctl_remove()
1293 padctl->soc->ops->remove(padctl); in tegra_xusb_padctl_remove()
1300 if (padctl->soc && padctl->soc->ops && padctl->soc->ops->suspend_noirq) in tegra_xusb_padctl_suspend_noirq()
1301 return padctl->soc->ops->suspend_noirq(padctl); in tegra_xusb_padctl_suspend_noirq()
1310 if (padctl->soc && padctl->soc->ops && padctl->soc->ops->resume_noirq) in tegra_xusb_padctl_resume_noirq()
1311 return padctl->soc->ops->resume_noirq(padctl); in tegra_xusb_padctl_resume_noirq()
1323 .name = "tegra-xusb-padctl",
1338 np = of_parse_phandle(dev->of_node, "nvidia,xusb-padctl", 0); in tegra_xusb_padctl_get()
1340 return ERR_PTR(-EINVAL); in tegra_xusb_padctl_get()
1350 return ERR_PTR(-ENODEV); in tegra_xusb_padctl_get()
1357 put_device(&pdev->dev); in tegra_xusb_padctl_get()
1358 return ERR_PTR(-EPROBE_DEFER); in tegra_xusb_padctl_get()
1368 put_device(padctl->dev); in tegra_xusb_padctl_put()
1373 unsigned int port) in tegra_xusb_padctl_usb3_save_context() argument
1375 if (padctl->soc->ops->usb3_save_context) in tegra_xusb_padctl_usb3_save_context()
1376 return padctl->soc->ops->usb3_save_context(padctl, port); in tegra_xusb_padctl_usb3_save_context()
1378 return -ENOSYS; in tegra_xusb_padctl_usb3_save_context()
1383 unsigned int port, bool idle) in tegra_xusb_padctl_hsic_set_idle() argument
1385 if (padctl->soc->ops->hsic_set_idle) in tegra_xusb_padctl_hsic_set_idle()
1386 return padctl->soc->ops->hsic_set_idle(padctl, port, idle); in tegra_xusb_padctl_hsic_set_idle()
1388 return -ENOSYS; in tegra_xusb_padctl_hsic_set_idle()
1397 if (lane->pad->ops->enable_phy_sleepwalk) in tegra_xusb_padctl_enable_phy_sleepwalk()
1398 return lane->pad->ops->enable_phy_sleepwalk(lane, speed); in tegra_xusb_padctl_enable_phy_sleepwalk()
1400 return -EOPNOTSUPP; in tegra_xusb_padctl_enable_phy_sleepwalk()
1408 if (lane->pad->ops->disable_phy_sleepwalk) in tegra_xusb_padctl_disable_phy_sleepwalk()
1409 return lane->pad->ops->disable_phy_sleepwalk(lane); in tegra_xusb_padctl_disable_phy_sleepwalk()
1411 return -EOPNOTSUPP; in tegra_xusb_padctl_disable_phy_sleepwalk()
1419 if (lane->pad->ops->enable_phy_wake) in tegra_xusb_padctl_enable_phy_wake()
1420 return lane->pad->ops->enable_phy_wake(lane); in tegra_xusb_padctl_enable_phy_wake()
1422 return -EOPNOTSUPP; in tegra_xusb_padctl_enable_phy_wake()
1430 if (lane->pad->ops->disable_phy_wake) in tegra_xusb_padctl_disable_phy_wake()
1431 return lane->pad->ops->disable_phy_wake(lane); in tegra_xusb_padctl_disable_phy_wake()
1433 return -EOPNOTSUPP; in tegra_xusb_padctl_disable_phy_wake()
1441 if (lane->pad->ops->remote_wake_detected) in tegra_xusb_padctl_remote_wake_detected()
1442 return lane->pad->ops->remote_wake_detected(lane); in tegra_xusb_padctl_remote_wake_detected()
1449 unsigned int port, bool enable) in tegra_xusb_padctl_usb3_set_lfps_detect() argument
1451 if (padctl->soc->ops->usb3_set_lfps_detect) in tegra_xusb_padctl_usb3_set_lfps_detect()
1452 return padctl->soc->ops->usb3_set_lfps_detect(padctl, port, in tegra_xusb_padctl_usb3_set_lfps_detect()
1455 return -ENOSYS; in tegra_xusb_padctl_usb3_set_lfps_detect()
1462 if (padctl->soc->ops->vbus_override) in tegra_xusb_padctl_set_vbus_override()
1463 return padctl->soc->ops->vbus_override(padctl, val); in tegra_xusb_padctl_set_vbus_override()
1465 return -ENOTSUPP; in tegra_xusb_padctl_set_vbus_override()
1472 struct tegra_xusb_padctl *padctl = lane->pad->padctl; in tegra_phy_xusb_utmi_port_reset()
1474 if (padctl->soc->ops->utmi_port_reset) in tegra_phy_xusb_utmi_port_reset()
1475 return padctl->soc->ops->utmi_port_reset(phy); in tegra_phy_xusb_utmi_port_reset()
1477 return -ENOTSUPP; in tegra_phy_xusb_utmi_port_reset()
1490 padctl = lane->pad->padctl; in tegra_phy_xusb_utmi_pad_power_on()
1492 if (padctl->soc->ops->utmi_pad_power_on) in tegra_phy_xusb_utmi_pad_power_on()
1493 padctl->soc->ops->utmi_pad_power_on(phy); in tegra_phy_xusb_utmi_pad_power_on()
1506 padctl = lane->pad->padctl; in tegra_phy_xusb_utmi_pad_power_down()
1508 if (padctl->soc->ops->utmi_pad_power_down) in tegra_phy_xusb_utmi_pad_power_down()
1509 padctl->soc->ops->utmi_pad_power_down(phy); in tegra_phy_xusb_utmi_pad_power_down()
1514 unsigned int port) in tegra_xusb_padctl_get_usb3_companion() argument
1520 usb2 = tegra_xusb_find_usb2_port(padctl, port); in tegra_xusb_padctl_get_usb3_companion()
1522 return -EINVAL; in tegra_xusb_padctl_get_usb3_companion()
1524 for (i = 0; i < padctl->soc->ports.usb3.count; i++) { in tegra_xusb_padctl_get_usb3_companion()
1526 if (usb3 && usb3->port == usb2->base.index) in tegra_xusb_padctl_get_usb3_companion()
1527 return usb3->base.index; in tegra_xusb_padctl_get_usb3_companion()
1530 return -ENODEV; in tegra_xusb_padctl_get_usb3_companion()
1539 return -ENODEV; in tegra_xusb_padctl_get_port_number()
1543 return lane->index; in tegra_xusb_padctl_get_port_number()