Lines Matching +full:usb2 +full:- +full:phy
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2014-2022, NVIDIA CORPORATION. All rights reserved.
12 #include <linux/phy/phy.h>
13 #include <linux/phy/tegra/xusb.h>
24 static struct phy *tegra_xusb_pad_of_xlate(struct device *dev, in tegra_xusb_pad_of_xlate()
28 struct phy *phy = NULL; in tegra_xusb_pad_of_xlate() local
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()
44 if (phy == NULL) in tegra_xusb_pad_of_xlate()
45 phy = ERR_PTR(-ENODEV); in tegra_xusb_pad_of_xlate()
47 return phy; 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",
84 pads = of_get_child_by_name(padctl->dev->of_node, "pads"); in tegra_xusb_find_pad_node()
99 lanes = of_get_child_by_name(pad->dev.of_node, "lanes"); in tegra_xusb_pad_find_phy_node()
103 np = of_get_child_by_name(lanes, pad->soc->lanes[index].name); in tegra_xusb_pad_find_phy_node()
112 struct device *dev = &lane->pad->dev; in tegra_xusb_lane_parse_dt()
120 err = match_string(lane->soc->funcs, lane->soc->num_funcs, function); in tegra_xusb_lane_parse_dt()
127 lane->function = err; in tegra_xusb_lane_parse_dt()
132 static void tegra_xusb_lane_destroy(struct phy *phy) in tegra_xusb_lane_destroy() argument
134 if (phy) { in tegra_xusb_lane_destroy()
135 struct tegra_xusb_lane *lane = phy_get_drvdata(phy); in tegra_xusb_lane_destroy()
137 lane->pad->ops->remove(lane); in tegra_xusb_lane_destroy()
138 phy_destroy(phy); in tegra_xusb_lane_destroy()
146 pad->soc->ops->remove(pad); in tegra_xusb_pad_release()
159 device_initialize(&pad->dev); in tegra_xusb_pad_init()
160 INIT_LIST_HEAD(&pad->list); in tegra_xusb_pad_init()
161 pad->dev.parent = padctl->dev; in tegra_xusb_pad_init()
162 pad->dev.type = &tegra_xusb_pad_type; in tegra_xusb_pad_init()
163 pad->dev.of_node = np; in tegra_xusb_pad_init()
164 pad->padctl = padctl; in tegra_xusb_pad_init()
166 err = dev_set_name(&pad->dev, "%s", pad->soc->name); in tegra_xusb_pad_init()
170 err = device_add(&pad->dev); in tegra_xusb_pad_init()
177 device_unregister(&pad->dev); in tegra_xusb_pad_init()
185 struct phy *lane; in tegra_xusb_pad_register()
189 children = of_get_child_by_name(pad->dev.of_node, "lanes"); in tegra_xusb_pad_register()
191 return -ENODEV; in tegra_xusb_pad_register()
193 pad->lanes = devm_kcalloc(&pad->dev, pad->soc->num_lanes, sizeof(lane), in tegra_xusb_pad_register()
195 if (!pad->lanes) { in tegra_xusb_pad_register()
197 return -ENOMEM; in tegra_xusb_pad_register()
200 for (i = 0; i < pad->soc->num_lanes; i++) { in tegra_xusb_pad_register()
210 pad->lanes[i] = phy_create(&pad->dev, np, ops); in tegra_xusb_pad_register()
211 if (IS_ERR(pad->lanes[i])) { in tegra_xusb_pad_register()
212 err = PTR_ERR(pad->lanes[i]); in tegra_xusb_pad_register()
217 lane = pad->ops->probe(pad, np, i); in tegra_xusb_pad_register()
219 phy_destroy(pad->lanes[i]); in tegra_xusb_pad_register()
224 list_add_tail(&lane->list, &pad->padctl->lanes); in tegra_xusb_pad_register()
225 phy_set_drvdata(pad->lanes[i], lane); in tegra_xusb_pad_register()
228 pad->provider = of_phy_provider_register_full(&pad->dev, children, in tegra_xusb_pad_register()
230 if (IS_ERR(pad->provider)) { in tegra_xusb_pad_register()
231 err = PTR_ERR(pad->provider); in tegra_xusb_pad_register()
238 while (i--) in tegra_xusb_pad_register()
239 tegra_xusb_lane_destroy(pad->lanes[i]); in tegra_xusb_pad_register()
248 unsigned int i = pad->soc->num_lanes; in tegra_xusb_pad_unregister()
250 of_phy_provider_unregister(pad->provider); in tegra_xusb_pad_unregister()
252 while (i--) in tegra_xusb_pad_unregister()
253 tegra_xusb_lane_destroy(pad->lanes[i]); in tegra_xusb_pad_unregister()
255 device_unregister(&pad->dev); in tegra_xusb_pad_unregister()
266 np = tegra_xusb_find_pad_node(padctl, soc->name); in tegra_xusb_pad_create()
270 pad = soc->ops->probe(padctl, soc, np); in tegra_xusb_pad_create()
273 dev_err(padctl->dev, "failed to create pad %s: %d\n", in tegra_xusb_pad_create()
274 soc->name, err); in tegra_xusb_pad_create()
278 /* XXX move this into ->probe() to avoid string comparison */ in tegra_xusb_pad_create()
279 if (strcmp(soc->name, "pcie") == 0) in tegra_xusb_pad_create()
280 padctl->pcie = pad; in tegra_xusb_pad_create()
282 if (strcmp(soc->name, "sata") == 0) in tegra_xusb_pad_create()
283 padctl->sata = pad; in tegra_xusb_pad_create()
285 if (strcmp(soc->name, "usb2") == 0) in tegra_xusb_pad_create()
286 padctl->usb2 = pad; in tegra_xusb_pad_create()
288 if (strcmp(soc->name, "ulpi") == 0) in tegra_xusb_pad_create()
289 padctl->ulpi = pad; in tegra_xusb_pad_create()
291 if (strcmp(soc->name, "hsic") == 0) in tegra_xusb_pad_create()
292 padctl->hsic = pad; in tegra_xusb_pad_create()
301 list_for_each_entry_safe_reverse(pad, tmp, &padctl->pads, list) { in __tegra_xusb_remove_pads()
302 list_del(&pad->list); in __tegra_xusb_remove_pads()
309 mutex_lock(&padctl->lock); in tegra_xusb_remove_pads()
311 mutex_unlock(&padctl->lock); in tegra_xusb_remove_pads()
316 struct tegra_xusb_padctl *padctl = lane->pad->padctl; in tegra_xusb_lane_program()
317 const struct tegra_xusb_lane_soc *soc = lane->soc; in tegra_xusb_lane_program()
321 if (soc->num_funcs < 2) in tegra_xusb_lane_program()
324 if (lane->pad->ops->iddq_enable) in tegra_xusb_lane_program()
325 lane->pad->ops->iddq_enable(lane); in tegra_xusb_lane_program()
328 value = padctl_readl(padctl, soc->offset); in tegra_xusb_lane_program()
329 value &= ~(soc->mask << soc->shift); in tegra_xusb_lane_program()
330 value |= lane->function << soc->shift; in tegra_xusb_lane_program()
331 padctl_writel(padctl, value, soc->offset); in tegra_xusb_lane_program()
333 if (lane->pad->ops->iddq_disable) in tegra_xusb_lane_program()
334 lane->pad->ops->iddq_disable(lane); in tegra_xusb_lane_program()
341 for (i = 0; i < pad->soc->num_lanes; i++) { in tegra_xusb_pad_program()
344 if (pad->lanes[i]) { in tegra_xusb_pad_program()
345 lane = phy_get_drvdata(pad->lanes[i]); in tegra_xusb_pad_program()
356 mutex_lock(&padctl->lock); in tegra_xusb_setup_pads()
358 for (i = 0; i < padctl->soc->num_pads; i++) { in tegra_xusb_setup_pads()
359 const struct tegra_xusb_pad_soc *soc = padctl->soc->pads[i]; in tegra_xusb_setup_pads()
365 dev_err(padctl->dev, "failed to create pad %s: %d\n", in tegra_xusb_setup_pads()
366 soc->name, err); in tegra_xusb_setup_pads()
368 mutex_unlock(&padctl->lock); in tegra_xusb_setup_pads()
375 list_add_tail(&pad->list, &padctl->pads); in tegra_xusb_setup_pads()
378 list_for_each_entry(pad, &padctl->pads, list) in tegra_xusb_setup_pads()
381 mutex_unlock(&padctl->lock); in tegra_xusb_setup_pads()
388 const char *func = lane->soc->funcs[lane->function]; in tegra_xusb_lane_check()
397 struct tegra_xusb_lane *lane, *hit = ERR_PTR(-ENODEV); in tegra_xusb_find_lane()
400 name = kasprintf(GFP_KERNEL, "%s-%u", type, index); in tegra_xusb_find_lane()
402 return ERR_PTR(-ENOMEM); in tegra_xusb_find_lane()
404 list_for_each_entry(lane, &padctl->lanes, list) { in tegra_xusb_find_lane()
405 if (strcmp(lane->soc->name, name) == 0) { in tegra_xusb_find_lane()
420 struct tegra_xusb_lane *lane, *match = ERR_PTR(-ENODEV); in tegra_xusb_port_find_lane()
422 for (; map->type; map++) { in tegra_xusb_port_find_lane()
423 if (port->index != map->port) in tegra_xusb_port_find_lane()
426 lane = tegra_xusb_find_lane(port->padctl, map->type, in tegra_xusb_port_find_lane()
427 map->index); in tegra_xusb_port_find_lane()
435 dev_err(&port->dev, "conflicting match: %s-%u / %s\n", in tegra_xusb_port_find_lane()
436 map->type, map->index, match->soc->name); in tegra_xusb_port_find_lane()
451 ports = of_get_child_by_name(padctl->dev->of_node, "ports"); in tegra_xusb_find_port_node()
455 name = kasprintf(GFP_KERNEL, "%s-%u", type, index); in tegra_xusb_find_port_node()
478 list_for_each_entry(port, &padctl->ports, list) { in tegra_xusb_find_port()
479 if (np == port->dev.of_node) { in tegra_xusb_find_port()
495 port = tegra_xusb_find_port(padctl, "usb2", index); in tegra_xusb_find_usb2_port()
518 if (port->ops->release) in tegra_xusb_port_release()
519 port->ops->release(port); in tegra_xusb_port_release()
534 INIT_LIST_HEAD(&port->list); in tegra_xusb_port_init()
535 port->padctl = padctl; in tegra_xusb_port_init()
536 port->index = index; in tegra_xusb_port_init()
538 device_initialize(&port->dev); in tegra_xusb_port_init()
539 port->dev.type = &tegra_xusb_port_type; in tegra_xusb_port_init()
540 port->dev.of_node = of_node_get(np); in tegra_xusb_port_init()
541 port->dev.parent = padctl->dev; in tegra_xusb_port_init()
543 err = dev_set_name(&port->dev, "%s-%u", name, index); in tegra_xusb_port_init()
547 err = device_add(&port->dev); in tegra_xusb_port_init()
554 device_unregister(&port->dev); in tegra_xusb_port_init()
560 if (!IS_ERR_OR_NULL(port->usb_role_sw)) { in tegra_xusb_port_unregister()
561 of_platform_depopulate(&port->dev); in tegra_xusb_port_unregister()
562 usb_role_switch_unregister(port->usb_role_sw); in tegra_xusb_port_unregister()
563 cancel_work_sync(&port->usb_phy_work); in tegra_xusb_port_unregister()
564 usb_remove_phy(&port->usb_phy); in tegra_xusb_port_unregister()
567 if (port->ops->remove) in tegra_xusb_port_unregister()
568 port->ops->remove(port); in tegra_xusb_port_unregister()
570 device_unregister(&port->dev); in tegra_xusb_port_unregister()
605 enum usb_role role = usb_role_switch_get_role(port->usb_role_sw); in tegra_xusb_usb_phy_work()
607 usb_phy_set_event(&port->usb_phy, to_usb_phy_event(role)); in tegra_xusb_usb_phy_work()
609 dev_dbg(&port->dev, "%s(): calling notifier for role %s\n", __func__, in tegra_xusb_usb_phy_work()
612 atomic_notifier_call_chain(&port->usb_phy.notifier, 0, &port->usb_phy); in tegra_xusb_usb_phy_work()
620 dev_dbg(&port->dev, "%s(): role %s\n", __func__, usb_roles[role]); in tegra_xusb_role_sw_set()
622 schedule_work(&port->usb_phy_work); in tegra_xusb_role_sw_set()
630 struct tegra_xusb_port *port = container_of(otg->usb_phy, in tegra_xusb_set_peripheral()
635 schedule_work(&port->usb_phy_work); in tegra_xusb_set_peripheral()
642 struct tegra_xusb_port *port = container_of(otg->usb_phy, in tegra_xusb_set_host()
647 schedule_work(&port->usb_phy_work); in tegra_xusb_set_host()
657 .fwnode = dev_fwnode(&port->dev), in tegra_xusb_setup_usb_role_switch()
665 * suboptimal solution. TODO: Need to revisit this in a follow-up patch in tegra_xusb_setup_usb_role_switch()
669 port->dev.driver = devm_kzalloc(&port->dev, in tegra_xusb_setup_usb_role_switch()
672 port->dev.driver->owner = THIS_MODULE; in tegra_xusb_setup_usb_role_switch()
674 port->usb_role_sw = usb_role_switch_register(&port->dev, in tegra_xusb_setup_usb_role_switch()
676 if (IS_ERR(port->usb_role_sw)) { in tegra_xusb_setup_usb_role_switch()
677 err = PTR_ERR(port->usb_role_sw); in tegra_xusb_setup_usb_role_switch()
678 dev_err(&port->dev, "failed to register USB role switch: %d", in tegra_xusb_setup_usb_role_switch()
683 INIT_WORK(&port->usb_phy_work, tegra_xusb_usb_phy_work); in tegra_xusb_setup_usb_role_switch()
684 usb_role_switch_set_drvdata(port->usb_role_sw, port); in tegra_xusb_setup_usb_role_switch()
686 port->usb_phy.otg = devm_kzalloc(&port->dev, sizeof(struct usb_otg), in tegra_xusb_setup_usb_role_switch()
688 if (!port->usb_phy.otg) in tegra_xusb_setup_usb_role_switch()
689 return -ENOMEM; in tegra_xusb_setup_usb_role_switch()
691 lane = tegra_xusb_find_lane(port->padctl, "usb2", port->index); in tegra_xusb_setup_usb_role_switch()
694 * Assign phy dev to usb-phy dev. Host/device drivers can use phy in tegra_xusb_setup_usb_role_switch()
695 * reference to retrieve usb-phy details. in tegra_xusb_setup_usb_role_switch()
697 port->usb_phy.dev = &lane->pad->lanes[port->index]->dev; in tegra_xusb_setup_usb_role_switch()
698 port->usb_phy.dev->driver = port->dev.driver; in tegra_xusb_setup_usb_role_switch()
699 port->usb_phy.otg->usb_phy = &port->usb_phy; in tegra_xusb_setup_usb_role_switch()
700 port->usb_phy.otg->set_peripheral = tegra_xusb_set_peripheral; in tegra_xusb_setup_usb_role_switch()
701 port->usb_phy.otg->set_host = tegra_xusb_set_host; in tegra_xusb_setup_usb_role_switch()
703 err = usb_add_phy_dev(&port->usb_phy); in tegra_xusb_setup_usb_role_switch()
705 dev_err(&port->dev, "Failed to add USB PHY: %d\n", err); in tegra_xusb_setup_usb_role_switch()
710 of_platform_populate(port->dev.of_node, NULL, NULL, &port->dev); in tegra_xusb_setup_usb_role_switch()
715 static int tegra_xusb_usb2_port_parse_dt(struct tegra_xusb_usb2_port *usb2) in tegra_xusb_usb2_port_parse_dt() argument
717 struct tegra_xusb_port *port = &usb2->base; in tegra_xusb_usb2_port_parse_dt()
718 struct device_node *np = port->dev.of_node; in tegra_xusb_usb2_port_parse_dt()
722 usb2->internal = of_property_read_bool(np, "nvidia,internal"); in tegra_xusb_usb2_port_parse_dt()
727 dev_err(&port->dev, "invalid value %s for \"mode\"\n", in tegra_xusb_usb2_port_parse_dt()
729 usb2->mode = USB_DR_MODE_UNKNOWN; in tegra_xusb_usb2_port_parse_dt()
731 usb2->mode = err; in tegra_xusb_usb2_port_parse_dt()
734 usb2->mode = USB_DR_MODE_HOST; in tegra_xusb_usb2_port_parse_dt()
737 /* usb-role-switch property is mandatory for OTG/Peripheral modes */ in tegra_xusb_usb2_port_parse_dt()
738 if (usb2->mode == USB_DR_MODE_PERIPHERAL || in tegra_xusb_usb2_port_parse_dt()
739 usb2->mode == USB_DR_MODE_OTG) { in tegra_xusb_usb2_port_parse_dt()
740 if (of_property_read_bool(np, "usb-role-switch")) { in tegra_xusb_usb2_port_parse_dt()
745 dev_err(&port->dev, "usb-role-switch not found for %s mode", in tegra_xusb_usb2_port_parse_dt()
746 modes[usb2->mode]); in tegra_xusb_usb2_port_parse_dt()
747 return -EINVAL; in tegra_xusb_usb2_port_parse_dt()
751 usb2->supply = regulator_get(&port->dev, "vbus"); in tegra_xusb_usb2_port_parse_dt()
752 return PTR_ERR_OR_ZERO(usb2->supply); in tegra_xusb_usb2_port_parse_dt()
758 struct tegra_xusb_usb2_port *usb2; in tegra_xusb_add_usb2_port() local
763 * USB2 ports don't require additional properties, but if the port is in tegra_xusb_add_usb2_port()
766 np = tegra_xusb_find_port_node(padctl, "usb2", index); in tegra_xusb_add_usb2_port()
770 usb2 = kzalloc(sizeof(*usb2), GFP_KERNEL); in tegra_xusb_add_usb2_port()
771 if (!usb2) { in tegra_xusb_add_usb2_port()
772 err = -ENOMEM; in tegra_xusb_add_usb2_port()
776 err = tegra_xusb_port_init(&usb2->base, padctl, np, "usb2", index); in tegra_xusb_add_usb2_port()
780 usb2->base.ops = padctl->soc->ports.usb2.ops; in tegra_xusb_add_usb2_port()
782 usb2->base.lane = usb2->base.ops->map(&usb2->base); in tegra_xusb_add_usb2_port()
783 if (IS_ERR(usb2->base.lane)) { in tegra_xusb_add_usb2_port()
784 err = PTR_ERR(usb2->base.lane); in tegra_xusb_add_usb2_port()
788 err = tegra_xusb_usb2_port_parse_dt(usb2); in tegra_xusb_add_usb2_port()
790 tegra_xusb_port_unregister(&usb2->base); in tegra_xusb_add_usb2_port()
794 list_add_tail(&usb2->base.list, &padctl->ports); in tegra_xusb_add_usb2_port()
803 struct tegra_xusb_usb2_port *usb2 = to_usb2_port(port); in tegra_xusb_usb2_port_release() local
805 kfree(usb2); in tegra_xusb_usb2_port_release()
810 struct tegra_xusb_usb2_port *usb2 = to_usb2_port(port); in tegra_xusb_usb2_port_remove() local
812 regulator_put(usb2->supply); in tegra_xusb_usb2_port_remove()
817 struct tegra_xusb_port *port = &ulpi->base; in tegra_xusb_ulpi_port_parse_dt()
818 struct device_node *np = port->dev.of_node; in tegra_xusb_ulpi_port_parse_dt()
820 ulpi->internal = of_property_read_bool(np, "nvidia,internal"); in tegra_xusb_ulpi_port_parse_dt()
838 err = -ENOMEM; in tegra_xusb_add_ulpi_port()
842 err = tegra_xusb_port_init(&ulpi->base, padctl, np, "ulpi", index); in tegra_xusb_add_ulpi_port()
846 ulpi->base.ops = padctl->soc->ports.ulpi.ops; in tegra_xusb_add_ulpi_port()
848 ulpi->base.lane = ulpi->base.ops->map(&ulpi->base); in tegra_xusb_add_ulpi_port()
849 if (IS_ERR(ulpi->base.lane)) { in tegra_xusb_add_ulpi_port()
850 err = PTR_ERR(ulpi->base.lane); in tegra_xusb_add_ulpi_port()
856 tegra_xusb_port_unregister(&ulpi->base); in tegra_xusb_add_ulpi_port()
860 list_add_tail(&ulpi->base.list, &padctl->ports); in tegra_xusb_add_ulpi_port()
893 err = -ENOMEM; in tegra_xusb_add_hsic_port()
897 err = tegra_xusb_port_init(&hsic->base, padctl, np, "hsic", index); in tegra_xusb_add_hsic_port()
901 hsic->base.ops = padctl->soc->ports.hsic.ops; in tegra_xusb_add_hsic_port()
903 hsic->base.lane = hsic->base.ops->map(&hsic->base); in tegra_xusb_add_hsic_port()
904 if (IS_ERR(hsic->base.lane)) { in tegra_xusb_add_hsic_port()
905 err = PTR_ERR(hsic->base.lane); in tegra_xusb_add_hsic_port()
911 tegra_xusb_port_unregister(&hsic->base); in tegra_xusb_add_hsic_port()
915 list_add_tail(&hsic->base.list, &padctl->ports); in tegra_xusb_add_hsic_port()
931 struct tegra_xusb_port *port = &usb3->base; in tegra_xusb_usb3_port_parse_dt()
932 struct device_node *np = port->dev.of_node; in tegra_xusb_usb3_port_parse_dt()
937 err = of_property_read_u32(np, "nvidia,usb2-companion", &value); in tegra_xusb_usb3_port_parse_dt()
939 dev_err(&port->dev, "failed to read port: %d\n", err); in tegra_xusb_usb3_port_parse_dt()
943 usb3->port = value; in tegra_xusb_usb3_port_parse_dt()
945 usb3->internal = of_property_read_bool(np, "nvidia,internal"); in tegra_xusb_usb3_port_parse_dt()
947 if (device_property_present(&port->dev, "maximum-speed")) { in tegra_xusb_usb3_port_parse_dt()
948 maximum_speed = usb_get_maximum_speed(&port->dev); in tegra_xusb_usb3_port_parse_dt()
950 usb3->disable_gen2 = true; in tegra_xusb_usb3_port_parse_dt()
952 usb3->disable_gen2 = false; in tegra_xusb_usb3_port_parse_dt()
954 return -EINVAL; in tegra_xusb_usb3_port_parse_dt()
957 usb3->supply = regulator_get(&port->dev, "vbus"); in tegra_xusb_usb3_port_parse_dt()
958 return PTR_ERR_OR_ZERO(usb3->supply); in tegra_xusb_usb3_port_parse_dt()
979 err = -ENOMEM; in tegra_xusb_add_usb3_port()
983 err = tegra_xusb_port_init(&usb3->base, padctl, np, "usb3", index); in tegra_xusb_add_usb3_port()
987 usb3->base.ops = padctl->soc->ports.usb3.ops; in tegra_xusb_add_usb3_port()
989 usb3->base.lane = usb3->base.ops->map(&usb3->base); in tegra_xusb_add_usb3_port()
990 if (IS_ERR(usb3->base.lane)) { in tegra_xusb_add_usb3_port()
991 err = PTR_ERR(usb3->base.lane); in tegra_xusb_add_usb3_port()
997 tegra_xusb_port_unregister(&usb3->base); in tegra_xusb_add_usb3_port()
1001 list_add_tail(&usb3->base.list, &padctl->ports); in tegra_xusb_add_usb3_port()
1019 regulator_put(usb3->supply); in tegra_xusb_usb3_port_remove()
1026 list_for_each_entry_safe_reverse(port, tmp, &padctl->ports, list) { in __tegra_xusb_remove_ports()
1027 list_del(&port->list); in __tegra_xusb_remove_ports()
1037 for (i = 0; i < padctl->soc->ports.usb3.count; i++) { in tegra_xusb_find_unused_usb3_port()
1043 return -ENODEV; in tegra_xusb_find_unused_usb3_port()
1046 static bool tegra_xusb_port_is_companion(struct tegra_xusb_usb2_port *usb2) in tegra_xusb_port_is_companion() argument
1050 struct tegra_xusb_padctl *padctl = usb2->base.padctl; in tegra_xusb_port_is_companion()
1052 for (i = 0; i < padctl->soc->ports.usb3.count; i++) { in tegra_xusb_port_is_companion()
1054 if (usb3 && usb3->port == usb2->base.index) in tegra_xusb_port_is_companion()
1061 static int tegra_xusb_update_usb3_fake_port(struct tegra_xusb_usb2_port *usb2) in tegra_xusb_update_usb3_fake_port() argument
1066 usb2->usb3_port_fake = -1; in tegra_xusb_update_usb3_fake_port()
1068 if ((usb2->mode == USB_DR_MODE_OTG || in tegra_xusb_update_usb3_fake_port()
1069 usb2->mode == USB_DR_MODE_PERIPHERAL) && in tegra_xusb_update_usb3_fake_port()
1070 !tegra_xusb_port_is_companion(usb2)) { in tegra_xusb_update_usb3_fake_port()
1071 fake = tegra_xusb_find_unused_usb3_port(usb2->base.padctl); in tegra_xusb_update_usb3_fake_port()
1073 dev_err(&usb2->base.dev, "no unused USB3 ports available\n"); in tegra_xusb_update_usb3_fake_port()
1074 return -ENODEV; in tegra_xusb_update_usb3_fake_port()
1077 dev_dbg(&usb2->base.dev, "Found unused usb3 port: %d\n", fake); in tegra_xusb_update_usb3_fake_port()
1078 usb2->usb3_port_fake = fake; in tegra_xusb_update_usb3_fake_port()
1087 struct tegra_xusb_usb2_port *usb2; in tegra_xusb_setup_ports() local
1091 mutex_lock(&padctl->lock); in tegra_xusb_setup_ports()
1093 for (i = 0; i < padctl->soc->ports.usb2.count; i++) { in tegra_xusb_setup_ports()
1099 for (i = 0; i < padctl->soc->ports.ulpi.count; i++) { in tegra_xusb_setup_ports()
1105 for (i = 0; i < padctl->soc->ports.hsic.count; i++) { in tegra_xusb_setup_ports()
1111 for (i = 0; i < padctl->soc->ports.usb3.count; i++) { in tegra_xusb_setup_ports()
1117 if (padctl->soc->need_fake_usb3_port) { in tegra_xusb_setup_ports()
1118 for (i = 0; i < padctl->soc->ports.usb2.count; i++) { in tegra_xusb_setup_ports()
1119 usb2 = tegra_xusb_find_usb2_port(padctl, i); in tegra_xusb_setup_ports()
1120 if (!usb2) in tegra_xusb_setup_ports()
1123 err = tegra_xusb_update_usb3_fake_port(usb2); in tegra_xusb_setup_ports()
1129 list_for_each_entry(port, &padctl->ports, list) { in tegra_xusb_setup_ports()
1130 err = port->ops->enable(port); in tegra_xusb_setup_ports()
1132 dev_err(padctl->dev, "failed to enable port %s: %d\n", in tegra_xusb_setup_ports()
1133 dev_name(&port->dev), err); in tegra_xusb_setup_ports()
1141 mutex_unlock(&padctl->lock); in tegra_xusb_setup_ports()
1147 mutex_lock(&padctl->lock); in tegra_xusb_remove_ports()
1149 mutex_unlock(&padctl->lock); in tegra_xusb_remove_ports()
1154 struct device_node *np = pdev->dev.of_node; in tegra_xusb_padctl_probe()
1163 dev_warn(&pdev->dev, "deprecated DT, using legacy driver\n"); in tegra_xusb_padctl_probe()
1169 match = of_match_node(tegra_xusb_padctl_of_match, pdev->dev.of_node); in tegra_xusb_padctl_probe()
1170 soc = match->data; in tegra_xusb_padctl_probe()
1172 padctl = soc->ops->probe(&pdev->dev, soc); in tegra_xusb_padctl_probe()
1177 INIT_LIST_HEAD(&padctl->ports); in tegra_xusb_padctl_probe()
1178 INIT_LIST_HEAD(&padctl->lanes); in tegra_xusb_padctl_probe()
1179 INIT_LIST_HEAD(&padctl->pads); in tegra_xusb_padctl_probe()
1180 mutex_init(&padctl->lock); in tegra_xusb_padctl_probe()
1182 padctl->regs = devm_platform_ioremap_resource(pdev, 0); in tegra_xusb_padctl_probe()
1183 if (IS_ERR(padctl->regs)) { in tegra_xusb_padctl_probe()
1184 err = PTR_ERR(padctl->regs); in tegra_xusb_padctl_probe()
1188 padctl->rst = devm_reset_control_get(&pdev->dev, NULL); in tegra_xusb_padctl_probe()
1189 if (IS_ERR(padctl->rst)) { in tegra_xusb_padctl_probe()
1190 err = PTR_ERR(padctl->rst); in tegra_xusb_padctl_probe()
1194 padctl->supplies = devm_kcalloc(&pdev->dev, padctl->soc->num_supplies, in tegra_xusb_padctl_probe()
1195 sizeof(*padctl->supplies), GFP_KERNEL); in tegra_xusb_padctl_probe()
1196 if (!padctl->supplies) { in tegra_xusb_padctl_probe()
1197 err = -ENOMEM; in tegra_xusb_padctl_probe()
1201 regulator_bulk_set_supply_names(padctl->supplies, in tegra_xusb_padctl_probe()
1202 padctl->soc->supply_names, in tegra_xusb_padctl_probe()
1203 padctl->soc->num_supplies); in tegra_xusb_padctl_probe()
1205 err = devm_regulator_bulk_get(&pdev->dev, padctl->soc->num_supplies, in tegra_xusb_padctl_probe()
1206 padctl->supplies); in tegra_xusb_padctl_probe()
1208 dev_err_probe(&pdev->dev, err, "failed to get regulators\n"); in tegra_xusb_padctl_probe()
1212 err = reset_control_deassert(padctl->rst); in tegra_xusb_padctl_probe()
1216 err = regulator_bulk_enable(padctl->soc->num_supplies, in tegra_xusb_padctl_probe()
1217 padctl->supplies); in tegra_xusb_padctl_probe()
1219 dev_err(&pdev->dev, "failed to enable supplies: %d\n", err); in tegra_xusb_padctl_probe()
1225 dev_err(&pdev->dev, "failed to setup pads: %d\n", err); in tegra_xusb_padctl_probe()
1233 if (err == -EPROBE_DEFER) in tegra_xusb_padctl_probe()
1236 dev_printk(level, &pdev->dev, in tegra_xusb_padctl_probe()
1246 regulator_bulk_disable(padctl->soc->num_supplies, padctl->supplies); in tegra_xusb_padctl_probe()
1248 reset_control_assert(padctl->rst); in tegra_xusb_padctl_probe()
1251 soc->ops->remove(padctl); in tegra_xusb_padctl_probe()
1263 err = regulator_bulk_disable(padctl->soc->num_supplies, in tegra_xusb_padctl_remove()
1264 padctl->supplies); in tegra_xusb_padctl_remove()
1266 dev_err(&pdev->dev, "failed to disable supplies: %d\n", err); in tegra_xusb_padctl_remove()
1268 err = reset_control_assert(padctl->rst); in tegra_xusb_padctl_remove()
1270 dev_err(&pdev->dev, "failed to assert reset: %d\n", err); in tegra_xusb_padctl_remove()
1272 padctl->soc->ops->remove(padctl); in tegra_xusb_padctl_remove()
1281 if (padctl->soc && padctl->soc->ops && padctl->soc->ops->suspend_noirq) in tegra_xusb_padctl_suspend_noirq()
1282 return padctl->soc->ops->suspend_noirq(padctl); in tegra_xusb_padctl_suspend_noirq()
1291 if (padctl->soc && padctl->soc->ops && padctl->soc->ops->resume_noirq) in tegra_xusb_padctl_resume_noirq()
1292 return padctl->soc->ops->resume_noirq(padctl); in tegra_xusb_padctl_resume_noirq()
1304 .name = "tegra-xusb-padctl",
1319 np = of_parse_phandle(dev->of_node, "nvidia,xusb-padctl", 0); in tegra_xusb_padctl_get()
1321 return ERR_PTR(-EINVAL); in tegra_xusb_padctl_get()
1331 return ERR_PTR(-ENODEV); in tegra_xusb_padctl_get()
1338 put_device(&pdev->dev); in tegra_xusb_padctl_get()
1339 return ERR_PTR(-EPROBE_DEFER); in tegra_xusb_padctl_get()
1349 put_device(padctl->dev); in tegra_xusb_padctl_put()
1356 if (padctl->soc->ops->usb3_save_context) in tegra_xusb_padctl_usb3_save_context()
1357 return padctl->soc->ops->usb3_save_context(padctl, port); in tegra_xusb_padctl_usb3_save_context()
1359 return -ENOSYS; in tegra_xusb_padctl_usb3_save_context()
1366 if (padctl->soc->ops->hsic_set_idle) in tegra_xusb_padctl_hsic_set_idle()
1367 return padctl->soc->ops->hsic_set_idle(padctl, port, idle); in tegra_xusb_padctl_hsic_set_idle()
1369 return -ENOSYS; in tegra_xusb_padctl_hsic_set_idle()
1373 int tegra_xusb_padctl_enable_phy_sleepwalk(struct tegra_xusb_padctl *padctl, struct phy *phy, in tegra_xusb_padctl_enable_phy_sleepwalk() argument
1376 struct tegra_xusb_lane *lane = phy_get_drvdata(phy); in tegra_xusb_padctl_enable_phy_sleepwalk()
1378 if (lane->pad->ops->enable_phy_sleepwalk) in tegra_xusb_padctl_enable_phy_sleepwalk()
1379 return lane->pad->ops->enable_phy_sleepwalk(lane, speed); in tegra_xusb_padctl_enable_phy_sleepwalk()
1381 return -EOPNOTSUPP; in tegra_xusb_padctl_enable_phy_sleepwalk()
1385 int tegra_xusb_padctl_disable_phy_sleepwalk(struct tegra_xusb_padctl *padctl, struct phy *phy) in tegra_xusb_padctl_disable_phy_sleepwalk() argument
1387 struct tegra_xusb_lane *lane = phy_get_drvdata(phy); in tegra_xusb_padctl_disable_phy_sleepwalk()
1389 if (lane->pad->ops->disable_phy_sleepwalk) in tegra_xusb_padctl_disable_phy_sleepwalk()
1390 return lane->pad->ops->disable_phy_sleepwalk(lane); in tegra_xusb_padctl_disable_phy_sleepwalk()
1392 return -EOPNOTSUPP; in tegra_xusb_padctl_disable_phy_sleepwalk()
1396 int tegra_xusb_padctl_enable_phy_wake(struct tegra_xusb_padctl *padctl, struct phy *phy) in tegra_xusb_padctl_enable_phy_wake() argument
1398 struct tegra_xusb_lane *lane = phy_get_drvdata(phy); in tegra_xusb_padctl_enable_phy_wake()
1400 if (lane->pad->ops->enable_phy_wake) in tegra_xusb_padctl_enable_phy_wake()
1401 return lane->pad->ops->enable_phy_wake(lane); in tegra_xusb_padctl_enable_phy_wake()
1403 return -EOPNOTSUPP; in tegra_xusb_padctl_enable_phy_wake()
1407 int tegra_xusb_padctl_disable_phy_wake(struct tegra_xusb_padctl *padctl, struct phy *phy) in tegra_xusb_padctl_disable_phy_wake() argument
1409 struct tegra_xusb_lane *lane = phy_get_drvdata(phy); in tegra_xusb_padctl_disable_phy_wake()
1411 if (lane->pad->ops->disable_phy_wake) in tegra_xusb_padctl_disable_phy_wake()
1412 return lane->pad->ops->disable_phy_wake(lane); in tegra_xusb_padctl_disable_phy_wake()
1414 return -EOPNOTSUPP; in tegra_xusb_padctl_disable_phy_wake()
1418 bool tegra_xusb_padctl_remote_wake_detected(struct tegra_xusb_padctl *padctl, struct phy *phy) in tegra_xusb_padctl_remote_wake_detected() argument
1420 struct tegra_xusb_lane *lane = phy_get_drvdata(phy); in tegra_xusb_padctl_remote_wake_detected()
1422 if (lane->pad->ops->remote_wake_detected) in tegra_xusb_padctl_remote_wake_detected()
1423 return lane->pad->ops->remote_wake_detected(lane); in tegra_xusb_padctl_remote_wake_detected()
1432 if (padctl->soc->ops->usb3_set_lfps_detect) in tegra_xusb_padctl_usb3_set_lfps_detect()
1433 return padctl->soc->ops->usb3_set_lfps_detect(padctl, port, in tegra_xusb_padctl_usb3_set_lfps_detect()
1436 return -ENOSYS; in tegra_xusb_padctl_usb3_set_lfps_detect()
1443 if (padctl->soc->ops->vbus_override) in tegra_xusb_padctl_set_vbus_override()
1444 return padctl->soc->ops->vbus_override(padctl, val); in tegra_xusb_padctl_set_vbus_override()
1446 return -ENOTSUPP; in tegra_xusb_padctl_set_vbus_override()
1450 int tegra_phy_xusb_utmi_port_reset(struct phy *phy) in tegra_phy_xusb_utmi_port_reset() argument
1452 struct tegra_xusb_lane *lane = phy_get_drvdata(phy); in tegra_phy_xusb_utmi_port_reset()
1453 struct tegra_xusb_padctl *padctl = lane->pad->padctl; in tegra_phy_xusb_utmi_port_reset()
1455 if (padctl->soc->ops->utmi_port_reset) in tegra_phy_xusb_utmi_port_reset()
1456 return padctl->soc->ops->utmi_port_reset(phy); in tegra_phy_xusb_utmi_port_reset()
1458 return -ENOTSUPP; in tegra_phy_xusb_utmi_port_reset()
1462 void tegra_phy_xusb_utmi_pad_power_on(struct phy *phy) in tegra_phy_xusb_utmi_pad_power_on() argument
1467 if (!phy) in tegra_phy_xusb_utmi_pad_power_on()
1470 lane = phy_get_drvdata(phy); in tegra_phy_xusb_utmi_pad_power_on()
1471 padctl = lane->pad->padctl; in tegra_phy_xusb_utmi_pad_power_on()
1473 if (padctl->soc->ops->utmi_pad_power_on) in tegra_phy_xusb_utmi_pad_power_on()
1474 padctl->soc->ops->utmi_pad_power_on(phy); in tegra_phy_xusb_utmi_pad_power_on()
1478 void tegra_phy_xusb_utmi_pad_power_down(struct phy *phy) in tegra_phy_xusb_utmi_pad_power_down() argument
1483 if (!phy) in tegra_phy_xusb_utmi_pad_power_down()
1486 lane = phy_get_drvdata(phy); in tegra_phy_xusb_utmi_pad_power_down()
1487 padctl = lane->pad->padctl; in tegra_phy_xusb_utmi_pad_power_down()
1489 if (padctl->soc->ops->utmi_pad_power_down) in tegra_phy_xusb_utmi_pad_power_down()
1490 padctl->soc->ops->utmi_pad_power_down(phy); in tegra_phy_xusb_utmi_pad_power_down()
1497 struct tegra_xusb_usb2_port *usb2; in tegra_xusb_padctl_get_usb3_companion() local
1501 usb2 = tegra_xusb_find_usb2_port(padctl, port); in tegra_xusb_padctl_get_usb3_companion()
1502 if (!usb2) in tegra_xusb_padctl_get_usb3_companion()
1503 return -EINVAL; in tegra_xusb_padctl_get_usb3_companion()
1505 for (i = 0; i < padctl->soc->ports.usb3.count; i++) { in tegra_xusb_padctl_get_usb3_companion()
1507 if (usb3 && usb3->port == usb2->base.index) in tegra_xusb_padctl_get_usb3_companion()
1508 return usb3->base.index; in tegra_xusb_padctl_get_usb3_companion()
1511 return -ENODEV; in tegra_xusb_padctl_get_usb3_companion()