Lines Matching +full:usb2 +full:- +full:phy

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2014-2016, 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()
325 value = padctl_readl(padctl, soc->offset); in tegra_xusb_lane_program()
326 value &= ~(soc->mask << soc->shift); in tegra_xusb_lane_program()
327 value |= lane->function << soc->shift; in tegra_xusb_lane_program()
328 padctl_writel(padctl, value, soc->offset); in tegra_xusb_lane_program()
335 for (i = 0; i < pad->soc->num_lanes; i++) { in tegra_xusb_pad_program()
338 if (pad->lanes[i]) { in tegra_xusb_pad_program()
339 lane = phy_get_drvdata(pad->lanes[i]); in tegra_xusb_pad_program()
350 mutex_lock(&padctl->lock); in tegra_xusb_setup_pads()
352 for (i = 0; i < padctl->soc->num_pads; i++) { in tegra_xusb_setup_pads()
353 const struct tegra_xusb_pad_soc *soc = padctl->soc->pads[i]; in tegra_xusb_setup_pads()
359 dev_err(padctl->dev, "failed to create pad %s: %d\n", in tegra_xusb_setup_pads()
360 soc->name, err); in tegra_xusb_setup_pads()
362 mutex_unlock(&padctl->lock); in tegra_xusb_setup_pads()
369 list_add_tail(&pad->list, &padctl->pads); in tegra_xusb_setup_pads()
372 list_for_each_entry(pad, &padctl->pads, list) in tegra_xusb_setup_pads()
375 mutex_unlock(&padctl->lock); in tegra_xusb_setup_pads()
382 const char *func = lane->soc->funcs[lane->function]; in tegra_xusb_lane_check()
391 struct tegra_xusb_lane *lane, *hit = ERR_PTR(-ENODEV); in tegra_xusb_find_lane()
394 name = kasprintf(GFP_KERNEL, "%s-%u", type, index); in tegra_xusb_find_lane()
396 return ERR_PTR(-ENOMEM); in tegra_xusb_find_lane()
398 list_for_each_entry(lane, &padctl->lanes, list) { in tegra_xusb_find_lane()
399 if (strcmp(lane->soc->name, name) == 0) { in tegra_xusb_find_lane()
414 struct tegra_xusb_lane *lane, *match = ERR_PTR(-ENODEV); in tegra_xusb_port_find_lane()
416 for (; map->type; map++) { in tegra_xusb_port_find_lane()
417 if (port->index != map->port) in tegra_xusb_port_find_lane()
420 lane = tegra_xusb_find_lane(port->padctl, map->type, in tegra_xusb_port_find_lane()
421 map->index); in tegra_xusb_port_find_lane()
429 dev_err(&port->dev, "conflicting match: %s-%u / %s\n", in tegra_xusb_port_find_lane()
430 map->type, map->index, match->soc->name); in tegra_xusb_port_find_lane()
445 ports = of_get_child_by_name(padctl->dev->of_node, "ports"); in tegra_xusb_find_port_node()
449 name = kasprintf(GFP_KERNEL, "%s-%u", type, index); in tegra_xusb_find_port_node()
452 return ERR_PTR(-ENOMEM); in tegra_xusb_find_port_node()
472 list_for_each_entry(port, &padctl->ports, list) { in tegra_xusb_find_port()
473 if (np == port->dev.of_node) { in tegra_xusb_find_port()
489 port = tegra_xusb_find_port(padctl, "usb2", index); in tegra_xusb_find_usb2_port()
512 if (port->ops->release) in tegra_xusb_port_release()
513 port->ops->release(port); in tegra_xusb_port_release()
528 INIT_LIST_HEAD(&port->list); in tegra_xusb_port_init()
529 port->padctl = padctl; in tegra_xusb_port_init()
530 port->index = index; in tegra_xusb_port_init()
532 device_initialize(&port->dev); in tegra_xusb_port_init()
533 port->dev.type = &tegra_xusb_port_type; in tegra_xusb_port_init()
534 port->dev.of_node = of_node_get(np); in tegra_xusb_port_init()
535 port->dev.parent = padctl->dev; in tegra_xusb_port_init()
537 err = dev_set_name(&port->dev, "%s-%u", name, index); in tegra_xusb_port_init()
541 err = device_add(&port->dev); in tegra_xusb_port_init()
548 device_unregister(&port->dev); in tegra_xusb_port_init()
554 if (!IS_ERR_OR_NULL(port->usb_role_sw)) { in tegra_xusb_port_unregister()
555 of_platform_depopulate(&port->dev); in tegra_xusb_port_unregister()
556 usb_role_switch_unregister(port->usb_role_sw); in tegra_xusb_port_unregister()
557 cancel_work_sync(&port->usb_phy_work); in tegra_xusb_port_unregister()
558 usb_remove_phy(&port->usb_phy); in tegra_xusb_port_unregister()
561 if (port->ops->remove) in tegra_xusb_port_unregister()
562 port->ops->remove(port); in tegra_xusb_port_unregister()
564 device_unregister(&port->dev); in tegra_xusb_port_unregister()
599 enum usb_role role = usb_role_switch_get_role(port->usb_role_sw); in tegra_xusb_usb_phy_work()
601 usb_phy_set_event(&port->usb_phy, to_usb_phy_event(role)); in tegra_xusb_usb_phy_work()
603 dev_dbg(&port->dev, "%s(): calling notifier for role %s\n", __func__, in tegra_xusb_usb_phy_work()
606 atomic_notifier_call_chain(&port->usb_phy.notifier, 0, &port->usb_phy); in tegra_xusb_usb_phy_work()
614 dev_dbg(&port->dev, "%s(): role %s\n", __func__, usb_roles[role]); in tegra_xusb_role_sw_set()
616 schedule_work(&port->usb_phy_work); in tegra_xusb_role_sw_set()
624 struct tegra_xusb_port *port = container_of(otg->usb_phy, in tegra_xusb_set_peripheral()
629 schedule_work(&port->usb_phy_work); in tegra_xusb_set_peripheral()
636 struct tegra_xusb_port *port = container_of(otg->usb_phy, in tegra_xusb_set_host()
641 schedule_work(&port->usb_phy_work); in tegra_xusb_set_host()
651 .fwnode = dev_fwnode(&port->dev), in tegra_xusb_setup_usb_role_switch()
658 * suboptimal solution. TODO: Need to revisit this in a follow-up patch in tegra_xusb_setup_usb_role_switch()
662 port->dev.driver = devm_kzalloc(&port->dev, in tegra_xusb_setup_usb_role_switch()
665 port->dev.driver->owner = THIS_MODULE; in tegra_xusb_setup_usb_role_switch()
667 port->usb_role_sw = usb_role_switch_register(&port->dev, in tegra_xusb_setup_usb_role_switch()
669 if (IS_ERR(port->usb_role_sw)) { in tegra_xusb_setup_usb_role_switch()
670 err = PTR_ERR(port->usb_role_sw); in tegra_xusb_setup_usb_role_switch()
671 dev_err(&port->dev, "failed to register USB role switch: %d", in tegra_xusb_setup_usb_role_switch()
676 INIT_WORK(&port->usb_phy_work, tegra_xusb_usb_phy_work); in tegra_xusb_setup_usb_role_switch()
677 usb_role_switch_set_drvdata(port->usb_role_sw, port); in tegra_xusb_setup_usb_role_switch()
679 port->usb_phy.otg = devm_kzalloc(&port->dev, sizeof(struct usb_otg), in tegra_xusb_setup_usb_role_switch()
681 if (!port->usb_phy.otg) in tegra_xusb_setup_usb_role_switch()
682 return -ENOMEM; in tegra_xusb_setup_usb_role_switch()
684 lane = tegra_xusb_find_lane(port->padctl, "usb2", port->index); in tegra_xusb_setup_usb_role_switch()
687 * Assign phy dev to usb-phy dev. Host/device drivers can use phy in tegra_xusb_setup_usb_role_switch()
688 * reference to retrieve usb-phy details. in tegra_xusb_setup_usb_role_switch()
690 port->usb_phy.dev = &lane->pad->lanes[port->index]->dev; in tegra_xusb_setup_usb_role_switch()
691 port->usb_phy.dev->driver = port->padctl->dev->driver; in tegra_xusb_setup_usb_role_switch()
692 port->usb_phy.otg->usb_phy = &port->usb_phy; in tegra_xusb_setup_usb_role_switch()
693 port->usb_phy.otg->set_peripheral = tegra_xusb_set_peripheral; in tegra_xusb_setup_usb_role_switch()
694 port->usb_phy.otg->set_host = tegra_xusb_set_host; in tegra_xusb_setup_usb_role_switch()
696 err = usb_add_phy_dev(&port->usb_phy); in tegra_xusb_setup_usb_role_switch()
698 dev_err(&port->dev, "Failed to add USB PHY: %d\n", err); in tegra_xusb_setup_usb_role_switch()
703 of_platform_populate(port->dev.of_node, NULL, NULL, &port->dev); in tegra_xusb_setup_usb_role_switch()
708 static int tegra_xusb_usb2_port_parse_dt(struct tegra_xusb_usb2_port *usb2) in tegra_xusb_usb2_port_parse_dt() argument
710 struct tegra_xusb_port *port = &usb2->base; in tegra_xusb_usb2_port_parse_dt()
711 struct device_node *np = port->dev.of_node; in tegra_xusb_usb2_port_parse_dt()
715 usb2->internal = of_property_read_bool(np, "nvidia,internal"); in tegra_xusb_usb2_port_parse_dt()
720 dev_err(&port->dev, "invalid value %s for \"mode\"\n", in tegra_xusb_usb2_port_parse_dt()
722 usb2->mode = USB_DR_MODE_UNKNOWN; in tegra_xusb_usb2_port_parse_dt()
724 usb2->mode = err; in tegra_xusb_usb2_port_parse_dt()
727 usb2->mode = USB_DR_MODE_HOST; in tegra_xusb_usb2_port_parse_dt()
730 /* usb-role-switch property is mandatory for OTG/Peripheral modes */ in tegra_xusb_usb2_port_parse_dt()
731 if (usb2->mode == USB_DR_MODE_PERIPHERAL || in tegra_xusb_usb2_port_parse_dt()
732 usb2->mode == USB_DR_MODE_OTG) { in tegra_xusb_usb2_port_parse_dt()
733 if (of_property_read_bool(np, "usb-role-switch")) { in tegra_xusb_usb2_port_parse_dt()
738 dev_err(&port->dev, "usb-role-switch not found for %s mode", in tegra_xusb_usb2_port_parse_dt()
739 modes[usb2->mode]); in tegra_xusb_usb2_port_parse_dt()
740 return -EINVAL; in tegra_xusb_usb2_port_parse_dt()
744 usb2->supply = regulator_get(&port->dev, "vbus"); in tegra_xusb_usb2_port_parse_dt()
745 return PTR_ERR_OR_ZERO(usb2->supply); in tegra_xusb_usb2_port_parse_dt()
751 struct tegra_xusb_usb2_port *usb2; in tegra_xusb_add_usb2_port() local
756 * USB2 ports don't require additional properties, but if the port is in tegra_xusb_add_usb2_port()
759 np = tegra_xusb_find_port_node(padctl, "usb2", index); in tegra_xusb_add_usb2_port()
763 usb2 = kzalloc(sizeof(*usb2), GFP_KERNEL); in tegra_xusb_add_usb2_port()
764 if (!usb2) { in tegra_xusb_add_usb2_port()
765 err = -ENOMEM; in tegra_xusb_add_usb2_port()
769 err = tegra_xusb_port_init(&usb2->base, padctl, np, "usb2", index); in tegra_xusb_add_usb2_port()
773 usb2->base.ops = padctl->soc->ports.usb2.ops; in tegra_xusb_add_usb2_port()
775 usb2->base.lane = usb2->base.ops->map(&usb2->base); in tegra_xusb_add_usb2_port()
776 if (IS_ERR(usb2->base.lane)) { in tegra_xusb_add_usb2_port()
777 err = PTR_ERR(usb2->base.lane); in tegra_xusb_add_usb2_port()
781 err = tegra_xusb_usb2_port_parse_dt(usb2); in tegra_xusb_add_usb2_port()
783 tegra_xusb_port_unregister(&usb2->base); in tegra_xusb_add_usb2_port()
787 list_add_tail(&usb2->base.list, &padctl->ports); in tegra_xusb_add_usb2_port()
796 struct tegra_xusb_usb2_port *usb2 = to_usb2_port(port); in tegra_xusb_usb2_port_release() local
798 kfree(usb2); in tegra_xusb_usb2_port_release()
803 struct tegra_xusb_usb2_port *usb2 = to_usb2_port(port); in tegra_xusb_usb2_port_remove() local
805 regulator_put(usb2->supply); in tegra_xusb_usb2_port_remove()
810 struct tegra_xusb_port *port = &ulpi->base; in tegra_xusb_ulpi_port_parse_dt()
811 struct device_node *np = port->dev.of_node; in tegra_xusb_ulpi_port_parse_dt()
813 ulpi->internal = of_property_read_bool(np, "nvidia,internal"); in tegra_xusb_ulpi_port_parse_dt()
831 err = -ENOMEM; in tegra_xusb_add_ulpi_port()
835 err = tegra_xusb_port_init(&ulpi->base, padctl, np, "ulpi", index); in tegra_xusb_add_ulpi_port()
839 ulpi->base.ops = padctl->soc->ports.ulpi.ops; in tegra_xusb_add_ulpi_port()
841 ulpi->base.lane = ulpi->base.ops->map(&ulpi->base); in tegra_xusb_add_ulpi_port()
842 if (IS_ERR(ulpi->base.lane)) { in tegra_xusb_add_ulpi_port()
843 err = PTR_ERR(ulpi->base.lane); in tegra_xusb_add_ulpi_port()
849 tegra_xusb_port_unregister(&ulpi->base); in tegra_xusb_add_ulpi_port()
853 list_add_tail(&ulpi->base.list, &padctl->ports); in tegra_xusb_add_ulpi_port()
886 err = -ENOMEM; in tegra_xusb_add_hsic_port()
890 err = tegra_xusb_port_init(&hsic->base, padctl, np, "hsic", index); in tegra_xusb_add_hsic_port()
894 hsic->base.ops = padctl->soc->ports.hsic.ops; in tegra_xusb_add_hsic_port()
896 hsic->base.lane = hsic->base.ops->map(&hsic->base); in tegra_xusb_add_hsic_port()
897 if (IS_ERR(hsic->base.lane)) { in tegra_xusb_add_hsic_port()
898 err = PTR_ERR(hsic->base.lane); in tegra_xusb_add_hsic_port()
904 tegra_xusb_port_unregister(&hsic->base); in tegra_xusb_add_hsic_port()
908 list_add_tail(&hsic->base.list, &padctl->ports); in tegra_xusb_add_hsic_port()
924 struct tegra_xusb_port *port = &usb3->base; in tegra_xusb_usb3_port_parse_dt()
925 struct device_node *np = port->dev.of_node; in tegra_xusb_usb3_port_parse_dt()
930 err = of_property_read_u32(np, "nvidia,usb2-companion", &value); in tegra_xusb_usb3_port_parse_dt()
932 dev_err(&port->dev, "failed to read port: %d\n", err); in tegra_xusb_usb3_port_parse_dt()
936 usb3->port = value; in tegra_xusb_usb3_port_parse_dt()
938 usb3->internal = of_property_read_bool(np, "nvidia,internal"); in tegra_xusb_usb3_port_parse_dt()
940 if (device_property_present(&port->dev, "maximum-speed")) { in tegra_xusb_usb3_port_parse_dt()
941 maximum_speed = usb_get_maximum_speed(&port->dev); in tegra_xusb_usb3_port_parse_dt()
943 usb3->disable_gen2 = true; in tegra_xusb_usb3_port_parse_dt()
945 usb3->disable_gen2 = false; in tegra_xusb_usb3_port_parse_dt()
947 return -EINVAL; in tegra_xusb_usb3_port_parse_dt()
950 usb3->supply = regulator_get(&port->dev, "vbus"); in tegra_xusb_usb3_port_parse_dt()
951 return PTR_ERR_OR_ZERO(usb3->supply); in tegra_xusb_usb3_port_parse_dt()
972 err = -ENOMEM; in tegra_xusb_add_usb3_port()
976 err = tegra_xusb_port_init(&usb3->base, padctl, np, "usb3", index); in tegra_xusb_add_usb3_port()
980 usb3->base.ops = padctl->soc->ports.usb3.ops; in tegra_xusb_add_usb3_port()
982 usb3->base.lane = usb3->base.ops->map(&usb3->base); in tegra_xusb_add_usb3_port()
983 if (IS_ERR(usb3->base.lane)) { in tegra_xusb_add_usb3_port()
984 err = PTR_ERR(usb3->base.lane); in tegra_xusb_add_usb3_port()
990 tegra_xusb_port_unregister(&usb3->base); in tegra_xusb_add_usb3_port()
994 list_add_tail(&usb3->base.list, &padctl->ports); in tegra_xusb_add_usb3_port()
1012 regulator_put(usb3->supply); in tegra_xusb_usb3_port_remove()
1019 list_for_each_entry_safe_reverse(port, tmp, &padctl->ports, list) { in __tegra_xusb_remove_ports()
1020 list_del(&port->list); in __tegra_xusb_remove_ports()
1030 for (i = 0; i < padctl->soc->ports.usb3.count; i++) { in tegra_xusb_find_unused_usb3_port()
1036 return -ENODEV; in tegra_xusb_find_unused_usb3_port()
1039 static bool tegra_xusb_port_is_companion(struct tegra_xusb_usb2_port *usb2) in tegra_xusb_port_is_companion() argument
1043 struct tegra_xusb_padctl *padctl = usb2->base.padctl; in tegra_xusb_port_is_companion()
1045 for (i = 0; i < padctl->soc->ports.usb3.count; i++) { in tegra_xusb_port_is_companion()
1047 if (usb3 && usb3->port == usb2->base.index) in tegra_xusb_port_is_companion()
1054 static int tegra_xusb_update_usb3_fake_port(struct tegra_xusb_usb2_port *usb2) in tegra_xusb_update_usb3_fake_port() argument
1059 usb2->usb3_port_fake = -1; in tegra_xusb_update_usb3_fake_port()
1061 if ((usb2->mode == USB_DR_MODE_OTG || in tegra_xusb_update_usb3_fake_port()
1062 usb2->mode == USB_DR_MODE_PERIPHERAL) && in tegra_xusb_update_usb3_fake_port()
1063 !tegra_xusb_port_is_companion(usb2)) { in tegra_xusb_update_usb3_fake_port()
1064 fake = tegra_xusb_find_unused_usb3_port(usb2->base.padctl); in tegra_xusb_update_usb3_fake_port()
1066 dev_err(&usb2->base.dev, "no unused USB3 ports available\n"); in tegra_xusb_update_usb3_fake_port()
1067 return -ENODEV; in tegra_xusb_update_usb3_fake_port()
1070 dev_dbg(&usb2->base.dev, "Found unused usb3 port: %d\n", fake); in tegra_xusb_update_usb3_fake_port()
1071 usb2->usb3_port_fake = fake; in tegra_xusb_update_usb3_fake_port()
1080 struct tegra_xusb_usb2_port *usb2; in tegra_xusb_setup_ports() local
1084 mutex_lock(&padctl->lock); in tegra_xusb_setup_ports()
1086 for (i = 0; i < padctl->soc->ports.usb2.count; i++) { in tegra_xusb_setup_ports()
1092 for (i = 0; i < padctl->soc->ports.ulpi.count; i++) { in tegra_xusb_setup_ports()
1098 for (i = 0; i < padctl->soc->ports.hsic.count; i++) { in tegra_xusb_setup_ports()
1104 for (i = 0; i < padctl->soc->ports.usb3.count; i++) { in tegra_xusb_setup_ports()
1110 if (padctl->soc->need_fake_usb3_port) { in tegra_xusb_setup_ports()
1111 for (i = 0; i < padctl->soc->ports.usb2.count; i++) { in tegra_xusb_setup_ports()
1112 usb2 = tegra_xusb_find_usb2_port(padctl, i); in tegra_xusb_setup_ports()
1113 if (!usb2) in tegra_xusb_setup_ports()
1116 err = tegra_xusb_update_usb3_fake_port(usb2); in tegra_xusb_setup_ports()
1122 list_for_each_entry(port, &padctl->ports, list) { in tegra_xusb_setup_ports()
1123 err = port->ops->enable(port); in tegra_xusb_setup_ports()
1125 dev_err(padctl->dev, "failed to enable port %s: %d\n", in tegra_xusb_setup_ports()
1126 dev_name(&port->dev), err); in tegra_xusb_setup_ports()
1134 mutex_unlock(&padctl->lock); in tegra_xusb_setup_ports()
1140 mutex_lock(&padctl->lock); in tegra_xusb_remove_ports()
1142 mutex_unlock(&padctl->lock); in tegra_xusb_remove_ports()
1147 struct device_node *np = pdev->dev.of_node; in tegra_xusb_padctl_probe()
1157 dev_warn(&pdev->dev, "deprecated DT, using legacy driver\n"); in tegra_xusb_padctl_probe()
1163 match = of_match_node(tegra_xusb_padctl_of_match, pdev->dev.of_node); in tegra_xusb_padctl_probe()
1164 soc = match->data; in tegra_xusb_padctl_probe()
1166 padctl = soc->ops->probe(&pdev->dev, soc); in tegra_xusb_padctl_probe()
1171 INIT_LIST_HEAD(&padctl->ports); in tegra_xusb_padctl_probe()
1172 INIT_LIST_HEAD(&padctl->lanes); in tegra_xusb_padctl_probe()
1173 INIT_LIST_HEAD(&padctl->pads); in tegra_xusb_padctl_probe()
1174 mutex_init(&padctl->lock); in tegra_xusb_padctl_probe()
1177 padctl->regs = devm_ioremap_resource(&pdev->dev, res); in tegra_xusb_padctl_probe()
1178 if (IS_ERR(padctl->regs)) { in tegra_xusb_padctl_probe()
1179 err = PTR_ERR(padctl->regs); in tegra_xusb_padctl_probe()
1183 padctl->rst = devm_reset_control_get(&pdev->dev, NULL); in tegra_xusb_padctl_probe()
1184 if (IS_ERR(padctl->rst)) { in tegra_xusb_padctl_probe()
1185 err = PTR_ERR(padctl->rst); in tegra_xusb_padctl_probe()
1189 padctl->supplies = devm_kcalloc(&pdev->dev, padctl->soc->num_supplies, in tegra_xusb_padctl_probe()
1190 sizeof(*padctl->supplies), GFP_KERNEL); in tegra_xusb_padctl_probe()
1191 if (!padctl->supplies) { in tegra_xusb_padctl_probe()
1192 err = -ENOMEM; in tegra_xusb_padctl_probe()
1196 regulator_bulk_set_supply_names(padctl->supplies, in tegra_xusb_padctl_probe()
1197 padctl->soc->supply_names, in tegra_xusb_padctl_probe()
1198 padctl->soc->num_supplies); in tegra_xusb_padctl_probe()
1200 err = devm_regulator_bulk_get(&pdev->dev, padctl->soc->num_supplies, in tegra_xusb_padctl_probe()
1201 padctl->supplies); in tegra_xusb_padctl_probe()
1203 dev_err(&pdev->dev, "failed to get regulators: %d\n", err); in tegra_xusb_padctl_probe()
1207 err = reset_control_deassert(padctl->rst); in tegra_xusb_padctl_probe()
1211 err = regulator_bulk_enable(padctl->soc->num_supplies, in tegra_xusb_padctl_probe()
1212 padctl->supplies); in tegra_xusb_padctl_probe()
1214 dev_err(&pdev->dev, "failed to enable supplies: %d\n", err); in tegra_xusb_padctl_probe()
1220 dev_err(&pdev->dev, "failed to setup pads: %d\n", err); in tegra_xusb_padctl_probe()
1228 if (err == -EPROBE_DEFER) in tegra_xusb_padctl_probe()
1231 dev_printk(level, &pdev->dev, in tegra_xusb_padctl_probe()
1241 regulator_bulk_disable(padctl->soc->num_supplies, padctl->supplies); in tegra_xusb_padctl_probe()
1243 reset_control_assert(padctl->rst); in tegra_xusb_padctl_probe()
1246 soc->ops->remove(padctl); in tegra_xusb_padctl_probe()
1258 err = regulator_bulk_disable(padctl->soc->num_supplies, in tegra_xusb_padctl_remove()
1259 padctl->supplies); in tegra_xusb_padctl_remove()
1261 dev_err(&pdev->dev, "failed to disable supplies: %d\n", err); in tegra_xusb_padctl_remove()
1263 err = reset_control_assert(padctl->rst); in tegra_xusb_padctl_remove()
1265 dev_err(&pdev->dev, "failed to assert reset: %d\n", err); in tegra_xusb_padctl_remove()
1267 padctl->soc->ops->remove(padctl); in tegra_xusb_padctl_remove()
1274 .name = "tegra-xusb-padctl",
1288 np = of_parse_phandle(dev->of_node, "nvidia,xusb-padctl", 0); in tegra_xusb_padctl_get()
1290 return ERR_PTR(-EINVAL); in tegra_xusb_padctl_get()
1300 return ERR_PTR(-ENODEV); in tegra_xusb_padctl_get()
1307 put_device(&pdev->dev); in tegra_xusb_padctl_get()
1308 return ERR_PTR(-EPROBE_DEFER); in tegra_xusb_padctl_get()
1318 put_device(padctl->dev); in tegra_xusb_padctl_put()
1325 if (padctl->soc->ops->usb3_save_context) in tegra_xusb_padctl_usb3_save_context()
1326 return padctl->soc->ops->usb3_save_context(padctl, port); in tegra_xusb_padctl_usb3_save_context()
1328 return -ENOSYS; in tegra_xusb_padctl_usb3_save_context()
1335 if (padctl->soc->ops->hsic_set_idle) in tegra_xusb_padctl_hsic_set_idle()
1336 return padctl->soc->ops->hsic_set_idle(padctl, port, idle); in tegra_xusb_padctl_hsic_set_idle()
1338 return -ENOSYS; in tegra_xusb_padctl_hsic_set_idle()
1345 if (padctl->soc->ops->usb3_set_lfps_detect) in tegra_xusb_padctl_usb3_set_lfps_detect()
1346 return padctl->soc->ops->usb3_set_lfps_detect(padctl, port, in tegra_xusb_padctl_usb3_set_lfps_detect()
1349 return -ENOSYS; in tegra_xusb_padctl_usb3_set_lfps_detect()
1356 if (padctl->soc->ops->vbus_override) in tegra_xusb_padctl_set_vbus_override()
1357 return padctl->soc->ops->vbus_override(padctl, val); in tegra_xusb_padctl_set_vbus_override()
1359 return -ENOTSUPP; in tegra_xusb_padctl_set_vbus_override()
1363 int tegra_phy_xusb_utmi_port_reset(struct phy *phy) in tegra_phy_xusb_utmi_port_reset() argument
1365 struct tegra_xusb_lane *lane = phy_get_drvdata(phy); in tegra_phy_xusb_utmi_port_reset()
1366 struct tegra_xusb_padctl *padctl = lane->pad->padctl; in tegra_phy_xusb_utmi_port_reset()
1368 if (padctl->soc->ops->utmi_port_reset) in tegra_phy_xusb_utmi_port_reset()
1369 return padctl->soc->ops->utmi_port_reset(phy); in tegra_phy_xusb_utmi_port_reset()
1371 return -ENOTSUPP; in tegra_phy_xusb_utmi_port_reset()
1378 struct tegra_xusb_usb2_port *usb2; in tegra_xusb_padctl_get_usb3_companion() local
1382 usb2 = tegra_xusb_find_usb2_port(padctl, port); in tegra_xusb_padctl_get_usb3_companion()
1383 if (!usb2) in tegra_xusb_padctl_get_usb3_companion()
1384 return -EINVAL; in tegra_xusb_padctl_get_usb3_companion()
1386 for (i = 0; i < padctl->soc->ports.usb3.count; i++) { in tegra_xusb_padctl_get_usb3_companion()
1388 if (usb3 && usb3->port == usb2->base.index) in tegra_xusb_padctl_get_usb3_companion()
1389 return usb3->base.index; in tegra_xusb_padctl_get_usb3_companion()
1392 return -ENODEV; in tegra_xusb_padctl_get_usb3_companion()