1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * Copyright (c) 2014-2022, NVIDIA CORPORATION. All rights reserved. 4 */ 5 6 #include <linux/delay.h> 7 #include <linux/io.h> 8 #include <linux/mailbox_client.h> 9 #include <linux/module.h> 10 #include <linux/of.h> 11 #include <linux/of_platform.h> 12 #include <linux/phy/phy.h> 13 #include <linux/phy/tegra/xusb.h> 14 #include <linux/platform_device.h> 15 #include <linux/platform_device.h> 16 #include <linux/regulator/consumer.h> 17 #include <linux/reset.h> 18 #include <linux/slab.h> 19 #include <linux/workqueue.h> 20 21 #include <soc/tegra/fuse.h> 22 23 #include "xusb.h" 24 25 static struct phy *tegra_xusb_pad_of_xlate(struct device *dev, 26 struct of_phandle_args *args) 27 { 28 struct tegra_xusb_pad *pad = dev_get_drvdata(dev); 29 struct phy *phy = NULL; 30 unsigned int i; 31 32 if (args->args_count != 0) 33 return ERR_PTR(-EINVAL); 34 35 for (i = 0; i < pad->soc->num_lanes; i++) { 36 if (!pad->lanes[i]) 37 continue; 38 39 if (pad->lanes[i]->dev.of_node == args->np) { 40 phy = pad->lanes[i]; 41 break; 42 } 43 } 44 45 if (phy == NULL) 46 phy = ERR_PTR(-ENODEV); 47 48 return phy; 49 } 50 51 static const struct of_device_id tegra_xusb_padctl_of_match[] = { 52 #if defined(CONFIG_ARCH_TEGRA_124_SOC) || defined(CONFIG_ARCH_TEGRA_132_SOC) 53 { 54 .compatible = "nvidia,tegra124-xusb-padctl", 55 .data = &tegra124_xusb_padctl_soc, 56 }, 57 #endif 58 #if defined(CONFIG_ARCH_TEGRA_210_SOC) 59 { 60 .compatible = "nvidia,tegra210-xusb-padctl", 61 .data = &tegra210_xusb_padctl_soc, 62 }, 63 #endif 64 #if defined(CONFIG_ARCH_TEGRA_186_SOC) 65 { 66 .compatible = "nvidia,tegra186-xusb-padctl", 67 .data = &tegra186_xusb_padctl_soc, 68 }, 69 #endif 70 #if defined(CONFIG_ARCH_TEGRA_194_SOC) 71 { 72 .compatible = "nvidia,tegra194-xusb-padctl", 73 .data = &tegra194_xusb_padctl_soc, 74 }, 75 #endif 76 #if defined(CONFIG_ARCH_TEGRA_234_SOC) 77 { 78 .compatible = "nvidia,tegra234-xusb-padctl", 79 .data = &tegra234_xusb_padctl_soc, 80 }, 81 #endif 82 { } 83 }; 84 MODULE_DEVICE_TABLE(of, tegra_xusb_padctl_of_match); 85 86 static struct device_node * 87 tegra_xusb_find_pad_node(struct tegra_xusb_padctl *padctl, const char *name) 88 { 89 struct device_node *pads, *np; 90 91 pads = of_get_child_by_name(padctl->dev->of_node, "pads"); 92 if (!pads) 93 return NULL; 94 95 np = of_get_child_by_name(pads, name); 96 of_node_put(pads); 97 98 return np; 99 } 100 101 static struct device_node * 102 tegra_xusb_pad_find_phy_node(struct tegra_xusb_pad *pad, unsigned int index) 103 { 104 struct device_node *np, *lanes; 105 106 lanes = of_get_child_by_name(pad->dev.of_node, "lanes"); 107 if (!lanes) 108 return NULL; 109 110 np = of_get_child_by_name(lanes, pad->soc->lanes[index].name); 111 of_node_put(lanes); 112 113 return np; 114 } 115 116 int tegra_xusb_lane_parse_dt(struct tegra_xusb_lane *lane, 117 struct device_node *np) 118 { 119 struct device *dev = &lane->pad->dev; 120 const char *function; 121 int err; 122 123 err = of_property_read_string(np, "nvidia,function", &function); 124 if (err < 0) 125 return err; 126 127 err = match_string(lane->soc->funcs, lane->soc->num_funcs, function); 128 if (err < 0) { 129 dev_err(dev, "invalid function \"%s\" for lane \"%pOFn\"\n", 130 function, np); 131 return err; 132 } 133 134 lane->function = err; 135 136 return 0; 137 } 138 139 static void tegra_xusb_lane_destroy(struct phy *phy) 140 { 141 if (phy) { 142 struct tegra_xusb_lane *lane = phy_get_drvdata(phy); 143 144 lane->pad->ops->remove(lane); 145 phy_destroy(phy); 146 } 147 } 148 149 static void tegra_xusb_pad_release(struct device *dev) 150 { 151 struct tegra_xusb_pad *pad = to_tegra_xusb_pad(dev); 152 153 pad->soc->ops->remove(pad); 154 } 155 156 static const struct device_type tegra_xusb_pad_type = { 157 .release = tegra_xusb_pad_release, 158 }; 159 160 int tegra_xusb_pad_init(struct tegra_xusb_pad *pad, 161 struct tegra_xusb_padctl *padctl, 162 struct device_node *np) 163 { 164 int err; 165 166 device_initialize(&pad->dev); 167 INIT_LIST_HEAD(&pad->list); 168 pad->dev.parent = padctl->dev; 169 pad->dev.type = &tegra_xusb_pad_type; 170 pad->dev.of_node = np; 171 pad->padctl = padctl; 172 173 err = dev_set_name(&pad->dev, "%s", pad->soc->name); 174 if (err < 0) 175 goto unregister; 176 177 err = device_add(&pad->dev); 178 if (err < 0) 179 goto unregister; 180 181 return 0; 182 183 unregister: 184 device_unregister(&pad->dev); 185 return err; 186 } 187 188 int tegra_xusb_pad_register(struct tegra_xusb_pad *pad, 189 const struct phy_ops *ops) 190 { 191 struct device_node *children; 192 struct phy *lane; 193 unsigned int i; 194 int err; 195 196 children = of_get_child_by_name(pad->dev.of_node, "lanes"); 197 if (!children) 198 return -ENODEV; 199 200 pad->lanes = devm_kcalloc(&pad->dev, pad->soc->num_lanes, sizeof(lane), 201 GFP_KERNEL); 202 if (!pad->lanes) { 203 of_node_put(children); 204 return -ENOMEM; 205 } 206 207 for (i = 0; i < pad->soc->num_lanes; i++) { 208 struct device_node *np = tegra_xusb_pad_find_phy_node(pad, i); 209 struct tegra_xusb_lane *lane; 210 211 /* skip disabled lanes */ 212 if (!np || !of_device_is_available(np)) { 213 of_node_put(np); 214 continue; 215 } 216 217 pad->lanes[i] = phy_create(&pad->dev, np, ops); 218 if (IS_ERR(pad->lanes[i])) { 219 err = PTR_ERR(pad->lanes[i]); 220 of_node_put(np); 221 goto remove; 222 } 223 224 lane = pad->ops->probe(pad, np, i); 225 if (IS_ERR(lane)) { 226 phy_destroy(pad->lanes[i]); 227 err = PTR_ERR(lane); 228 goto remove; 229 } 230 231 list_add_tail(&lane->list, &pad->padctl->lanes); 232 phy_set_drvdata(pad->lanes[i], lane); 233 } 234 235 pad->provider = of_phy_provider_register_full(&pad->dev, children, 236 tegra_xusb_pad_of_xlate); 237 if (IS_ERR(pad->provider)) { 238 err = PTR_ERR(pad->provider); 239 goto remove; 240 } 241 242 return 0; 243 244 remove: 245 while (i--) 246 tegra_xusb_lane_destroy(pad->lanes[i]); 247 248 of_node_put(children); 249 250 return err; 251 } 252 253 void tegra_xusb_pad_unregister(struct tegra_xusb_pad *pad) 254 { 255 unsigned int i = pad->soc->num_lanes; 256 257 of_phy_provider_unregister(pad->provider); 258 259 while (i--) 260 tegra_xusb_lane_destroy(pad->lanes[i]); 261 262 device_unregister(&pad->dev); 263 } 264 265 static struct tegra_xusb_pad * 266 tegra_xusb_pad_create(struct tegra_xusb_padctl *padctl, 267 const struct tegra_xusb_pad_soc *soc) 268 { 269 struct tegra_xusb_pad *pad; 270 struct device_node *np; 271 int err; 272 273 np = tegra_xusb_find_pad_node(padctl, soc->name); 274 if (!np || !of_device_is_available(np)) 275 return NULL; 276 277 pad = soc->ops->probe(padctl, soc, np); 278 if (IS_ERR(pad)) { 279 err = PTR_ERR(pad); 280 dev_err(padctl->dev, "failed to create pad %s: %d\n", 281 soc->name, err); 282 return ERR_PTR(err); 283 } 284 285 /* XXX move this into ->probe() to avoid string comparison */ 286 if (strcmp(soc->name, "pcie") == 0) 287 padctl->pcie = pad; 288 289 if (strcmp(soc->name, "sata") == 0) 290 padctl->sata = pad; 291 292 if (strcmp(soc->name, "usb2") == 0) 293 padctl->usb2 = pad; 294 295 if (strcmp(soc->name, "ulpi") == 0) 296 padctl->ulpi = pad; 297 298 if (strcmp(soc->name, "hsic") == 0) 299 padctl->hsic = pad; 300 301 return pad; 302 } 303 304 static void __tegra_xusb_remove_pads(struct tegra_xusb_padctl *padctl) 305 { 306 struct tegra_xusb_pad *pad, *tmp; 307 308 list_for_each_entry_safe_reverse(pad, tmp, &padctl->pads, list) { 309 list_del(&pad->list); 310 tegra_xusb_pad_unregister(pad); 311 } 312 } 313 314 static void tegra_xusb_remove_pads(struct tegra_xusb_padctl *padctl) 315 { 316 mutex_lock(&padctl->lock); 317 __tegra_xusb_remove_pads(padctl); 318 mutex_unlock(&padctl->lock); 319 } 320 321 static void tegra_xusb_lane_program(struct tegra_xusb_lane *lane) 322 { 323 struct tegra_xusb_padctl *padctl = lane->pad->padctl; 324 const struct tegra_xusb_lane_soc *soc = lane->soc; 325 u32 value; 326 327 /* skip single function lanes */ 328 if (soc->num_funcs < 2) 329 return; 330 331 if (lane->pad->ops->iddq_enable) 332 lane->pad->ops->iddq_enable(lane); 333 334 /* choose function */ 335 value = padctl_readl(padctl, soc->offset); 336 value &= ~(soc->mask << soc->shift); 337 value |= lane->function << soc->shift; 338 padctl_writel(padctl, value, soc->offset); 339 340 if (lane->pad->ops->iddq_disable) 341 lane->pad->ops->iddq_disable(lane); 342 } 343 344 static void tegra_xusb_pad_program(struct tegra_xusb_pad *pad) 345 { 346 unsigned int i; 347 348 for (i = 0; i < pad->soc->num_lanes; i++) { 349 struct tegra_xusb_lane *lane; 350 351 if (pad->lanes[i]) { 352 lane = phy_get_drvdata(pad->lanes[i]); 353 tegra_xusb_lane_program(lane); 354 } 355 } 356 } 357 358 static int tegra_xusb_setup_pads(struct tegra_xusb_padctl *padctl) 359 { 360 struct tegra_xusb_pad *pad; 361 unsigned int i; 362 363 mutex_lock(&padctl->lock); 364 365 for (i = 0; i < padctl->soc->num_pads; i++) { 366 const struct tegra_xusb_pad_soc *soc = padctl->soc->pads[i]; 367 int err; 368 369 pad = tegra_xusb_pad_create(padctl, soc); 370 if (IS_ERR(pad)) { 371 err = PTR_ERR(pad); 372 dev_err(padctl->dev, "failed to create pad %s: %d\n", 373 soc->name, err); 374 __tegra_xusb_remove_pads(padctl); 375 mutex_unlock(&padctl->lock); 376 return err; 377 } 378 379 if (!pad) 380 continue; 381 382 list_add_tail(&pad->list, &padctl->pads); 383 } 384 385 list_for_each_entry(pad, &padctl->pads, list) 386 tegra_xusb_pad_program(pad); 387 388 mutex_unlock(&padctl->lock); 389 return 0; 390 } 391 392 bool tegra_xusb_lane_check(struct tegra_xusb_lane *lane, 393 const char *function) 394 { 395 const char *func = lane->soc->funcs[lane->function]; 396 397 return strcmp(function, func) == 0; 398 } 399 400 struct tegra_xusb_lane *tegra_xusb_find_lane(struct tegra_xusb_padctl *padctl, 401 const char *type, 402 unsigned int index) 403 { 404 struct tegra_xusb_lane *lane, *hit = ERR_PTR(-ENODEV); 405 char *name; 406 407 name = kasprintf(GFP_KERNEL, "%s-%u", type, index); 408 if (!name) 409 return ERR_PTR(-ENOMEM); 410 411 list_for_each_entry(lane, &padctl->lanes, list) { 412 if (strcmp(lane->soc->name, name) == 0) { 413 hit = lane; 414 break; 415 } 416 } 417 418 kfree(name); 419 return hit; 420 } 421 422 struct tegra_xusb_lane * 423 tegra_xusb_port_find_lane(struct tegra_xusb_port *port, 424 const struct tegra_xusb_lane_map *map, 425 const char *function) 426 { 427 struct tegra_xusb_lane *lane, *match = ERR_PTR(-ENODEV); 428 429 for (; map->type; map++) { 430 if (port->index != map->port) 431 continue; 432 433 lane = tegra_xusb_find_lane(port->padctl, map->type, 434 map->index); 435 if (IS_ERR(lane)) 436 continue; 437 438 if (!tegra_xusb_lane_check(lane, function)) 439 continue; 440 441 if (!IS_ERR(match)) 442 dev_err(&port->dev, "conflicting match: %s-%u / %s\n", 443 map->type, map->index, match->soc->name); 444 else 445 match = lane; 446 } 447 448 return match; 449 } 450 451 static struct device_node * 452 tegra_xusb_find_port_node(struct tegra_xusb_padctl *padctl, const char *type, 453 unsigned int index) 454 { 455 struct device_node *ports, *np; 456 char *name; 457 458 ports = of_get_child_by_name(padctl->dev->of_node, "ports"); 459 if (!ports) 460 return NULL; 461 462 name = kasprintf(GFP_KERNEL, "%s-%u", type, index); 463 if (!name) { 464 of_node_put(ports); 465 return NULL; 466 } 467 np = of_get_child_by_name(ports, name); 468 kfree(name); 469 of_node_put(ports); 470 471 return np; 472 } 473 474 struct tegra_xusb_port * 475 tegra_xusb_find_port(struct tegra_xusb_padctl *padctl, const char *type, 476 unsigned int index) 477 { 478 struct tegra_xusb_port *port; 479 struct device_node *np; 480 481 np = tegra_xusb_find_port_node(padctl, type, index); 482 if (!np) 483 return NULL; 484 485 list_for_each_entry(port, &padctl->ports, list) { 486 if (np == port->dev.of_node) { 487 of_node_put(np); 488 return port; 489 } 490 } 491 492 of_node_put(np); 493 494 return NULL; 495 } 496 497 struct tegra_xusb_usb2_port * 498 tegra_xusb_find_usb2_port(struct tegra_xusb_padctl *padctl, unsigned int index) 499 { 500 struct tegra_xusb_port *port; 501 502 port = tegra_xusb_find_port(padctl, "usb2", index); 503 if (port) 504 return to_usb2_port(port); 505 506 return NULL; 507 } 508 509 struct tegra_xusb_usb3_port * 510 tegra_xusb_find_usb3_port(struct tegra_xusb_padctl *padctl, unsigned int index) 511 { 512 struct tegra_xusb_port *port; 513 514 port = tegra_xusb_find_port(padctl, "usb3", index); 515 if (port) 516 return to_usb3_port(port); 517 518 return NULL; 519 } 520 521 static void tegra_xusb_port_release(struct device *dev) 522 { 523 struct tegra_xusb_port *port = to_tegra_xusb_port(dev); 524 525 if (port->ops->release) 526 port->ops->release(port); 527 } 528 529 static const struct device_type tegra_xusb_port_type = { 530 .release = tegra_xusb_port_release, 531 }; 532 533 static int tegra_xusb_port_init(struct tegra_xusb_port *port, 534 struct tegra_xusb_padctl *padctl, 535 struct device_node *np, 536 const char *name, 537 unsigned int index) 538 { 539 int err; 540 541 INIT_LIST_HEAD(&port->list); 542 port->padctl = padctl; 543 port->index = index; 544 545 device_initialize(&port->dev); 546 port->dev.type = &tegra_xusb_port_type; 547 port->dev.of_node = of_node_get(np); 548 port->dev.parent = padctl->dev; 549 550 err = dev_set_name(&port->dev, "%s-%u", name, index); 551 if (err < 0) 552 goto unregister; 553 554 err = device_add(&port->dev); 555 if (err < 0) 556 goto unregister; 557 558 return 0; 559 560 unregister: 561 device_unregister(&port->dev); 562 return err; 563 } 564 565 static void tegra_xusb_port_unregister(struct tegra_xusb_port *port) 566 { 567 if (!IS_ERR_OR_NULL(port->usb_role_sw)) { 568 of_platform_depopulate(&port->dev); 569 usb_role_switch_unregister(port->usb_role_sw); 570 cancel_work_sync(&port->usb_phy_work); 571 usb_remove_phy(&port->usb_phy); 572 port->usb_phy.dev->driver = NULL; 573 } 574 575 if (port->ops->remove) 576 port->ops->remove(port); 577 578 device_unregister(&port->dev); 579 } 580 581 static const char *const modes[] = { 582 [USB_DR_MODE_UNKNOWN] = "", 583 [USB_DR_MODE_HOST] = "host", 584 [USB_DR_MODE_PERIPHERAL] = "peripheral", 585 [USB_DR_MODE_OTG] = "otg", 586 }; 587 588 static const char * const usb_roles[] = { 589 [USB_ROLE_NONE] = "none", 590 [USB_ROLE_HOST] = "host", 591 [USB_ROLE_DEVICE] = "device", 592 }; 593 594 static enum usb_phy_events to_usb_phy_event(enum usb_role role) 595 { 596 switch (role) { 597 case USB_ROLE_DEVICE: 598 return USB_EVENT_VBUS; 599 600 case USB_ROLE_HOST: 601 return USB_EVENT_ID; 602 603 default: 604 return USB_EVENT_NONE; 605 } 606 } 607 608 static void tegra_xusb_usb_phy_work(struct work_struct *work) 609 { 610 struct tegra_xusb_port *port = container_of(work, 611 struct tegra_xusb_port, 612 usb_phy_work); 613 enum usb_role role = usb_role_switch_get_role(port->usb_role_sw); 614 615 usb_phy_set_event(&port->usb_phy, to_usb_phy_event(role)); 616 617 dev_dbg(&port->dev, "%s(): calling notifier for role %s\n", __func__, 618 usb_roles[role]); 619 620 atomic_notifier_call_chain(&port->usb_phy.notifier, 0, &port->usb_phy); 621 } 622 623 static int tegra_xusb_role_sw_set(struct usb_role_switch *sw, 624 enum usb_role role) 625 { 626 struct tegra_xusb_port *port = usb_role_switch_get_drvdata(sw); 627 628 dev_dbg(&port->dev, "%s(): role %s\n", __func__, usb_roles[role]); 629 630 schedule_work(&port->usb_phy_work); 631 632 return 0; 633 } 634 635 static int tegra_xusb_set_peripheral(struct usb_otg *otg, 636 struct usb_gadget *gadget) 637 { 638 struct tegra_xusb_port *port = container_of(otg->usb_phy, 639 struct tegra_xusb_port, 640 usb_phy); 641 642 if (gadget != NULL) 643 schedule_work(&port->usb_phy_work); 644 645 return 0; 646 } 647 648 static int tegra_xusb_set_host(struct usb_otg *otg, struct usb_bus *host) 649 { 650 struct tegra_xusb_port *port = container_of(otg->usb_phy, 651 struct tegra_xusb_port, 652 usb_phy); 653 654 if (host != NULL) 655 schedule_work(&port->usb_phy_work); 656 657 return 0; 658 } 659 660 661 static int tegra_xusb_setup_usb_role_switch(struct tegra_xusb_port *port) 662 { 663 struct tegra_xusb_lane *lane; 664 struct usb_role_switch_desc role_sx_desc = { 665 .fwnode = dev_fwnode(&port->dev), 666 .set = tegra_xusb_role_sw_set, 667 .allow_userspace_control = true, 668 }; 669 int err = 0; 670 671 /* 672 * USB role switch driver needs parent driver owner info. This is a 673 * suboptimal solution. TODO: Need to revisit this in a follow-up patch 674 * where an optimal solution is possible with changes to USB role 675 * switch driver. 676 */ 677 port->dev.driver = devm_kzalloc(&port->dev, 678 sizeof(struct device_driver), 679 GFP_KERNEL); 680 if (!port->dev.driver) 681 return -ENOMEM; 682 683 port->dev.driver->owner = THIS_MODULE; 684 685 port->usb_role_sw = usb_role_switch_register(&port->dev, 686 &role_sx_desc); 687 if (IS_ERR(port->usb_role_sw)) { 688 err = PTR_ERR(port->usb_role_sw); 689 dev_err(&port->dev, "failed to register USB role switch: %d", 690 err); 691 return err; 692 } 693 694 INIT_WORK(&port->usb_phy_work, tegra_xusb_usb_phy_work); 695 usb_role_switch_set_drvdata(port->usb_role_sw, port); 696 697 port->usb_phy.otg = devm_kzalloc(&port->dev, sizeof(struct usb_otg), 698 GFP_KERNEL); 699 if (!port->usb_phy.otg) 700 return -ENOMEM; 701 702 lane = tegra_xusb_find_lane(port->padctl, "usb2", port->index); 703 704 /* 705 * Assign phy dev to usb-phy dev. Host/device drivers can use phy 706 * reference to retrieve usb-phy details. 707 */ 708 port->usb_phy.dev = &lane->pad->lanes[port->index]->dev; 709 port->usb_phy.dev->driver = port->dev.driver; 710 port->usb_phy.otg->usb_phy = &port->usb_phy; 711 port->usb_phy.otg->set_peripheral = tegra_xusb_set_peripheral; 712 port->usb_phy.otg->set_host = tegra_xusb_set_host; 713 714 err = usb_add_phy_dev(&port->usb_phy); 715 if (err < 0) { 716 dev_err(&port->dev, "Failed to add USB PHY: %d\n", err); 717 return err; 718 } 719 720 /* populate connector entry */ 721 of_platform_populate(port->dev.of_node, NULL, NULL, &port->dev); 722 723 return err; 724 } 725 726 static void tegra_xusb_parse_usb_role_default_mode(struct tegra_xusb_port *port) 727 { 728 enum usb_role role = USB_ROLE_NONE; 729 enum usb_dr_mode mode = usb_get_role_switch_default_mode(&port->dev); 730 731 if (mode == USB_DR_MODE_HOST) 732 role = USB_ROLE_HOST; 733 else if (mode == USB_DR_MODE_PERIPHERAL) 734 role = USB_ROLE_DEVICE; 735 736 if (role != USB_ROLE_NONE) { 737 usb_role_switch_set_role(port->usb_role_sw, role); 738 dev_dbg(&port->dev, "usb role default mode is %s", modes[mode]); 739 } 740 } 741 742 static int tegra_xusb_usb2_port_parse_dt(struct tegra_xusb_usb2_port *usb2) 743 { 744 struct tegra_xusb_port *port = &usb2->base; 745 struct device_node *np = port->dev.of_node; 746 const char *mode; 747 int err; 748 749 usb2->internal = of_property_read_bool(np, "nvidia,internal"); 750 751 if (!of_property_read_string(np, "mode", &mode)) { 752 int err = match_string(modes, ARRAY_SIZE(modes), mode); 753 if (err < 0) { 754 dev_err(&port->dev, "invalid value %s for \"mode\"\n", 755 mode); 756 usb2->mode = USB_DR_MODE_UNKNOWN; 757 } else { 758 usb2->mode = err; 759 } 760 } else { 761 usb2->mode = USB_DR_MODE_HOST; 762 } 763 764 /* usb-role-switch property is mandatory for OTG/Peripheral modes */ 765 if (usb2->mode == USB_DR_MODE_PERIPHERAL || 766 usb2->mode == USB_DR_MODE_OTG) { 767 if (of_property_read_bool(np, "usb-role-switch")) { 768 err = tegra_xusb_setup_usb_role_switch(port); 769 if (err < 0) 770 return err; 771 tegra_xusb_parse_usb_role_default_mode(port); 772 } else { 773 dev_err(&port->dev, "usb-role-switch not found for %s mode", 774 modes[usb2->mode]); 775 return -EINVAL; 776 } 777 } 778 779 usb2->supply = regulator_get(&port->dev, "vbus"); 780 return PTR_ERR_OR_ZERO(usb2->supply); 781 } 782 783 static int tegra_xusb_add_usb2_port(struct tegra_xusb_padctl *padctl, 784 unsigned int index) 785 { 786 struct tegra_xusb_usb2_port *usb2; 787 struct device_node *np; 788 int err = 0; 789 790 /* 791 * USB2 ports don't require additional properties, but if the port is 792 * marked as disabled there is no reason to register it. 793 */ 794 np = tegra_xusb_find_port_node(padctl, "usb2", index); 795 if (!np || !of_device_is_available(np)) 796 goto out; 797 798 usb2 = kzalloc(sizeof(*usb2), GFP_KERNEL); 799 if (!usb2) { 800 err = -ENOMEM; 801 goto out; 802 } 803 804 err = tegra_xusb_port_init(&usb2->base, padctl, np, "usb2", index); 805 if (err < 0) 806 goto out; 807 808 usb2->base.ops = padctl->soc->ports.usb2.ops; 809 810 usb2->base.lane = usb2->base.ops->map(&usb2->base); 811 if (IS_ERR(usb2->base.lane)) { 812 err = PTR_ERR(usb2->base.lane); 813 tegra_xusb_port_unregister(&usb2->base); 814 goto out; 815 } 816 817 err = tegra_xusb_usb2_port_parse_dt(usb2); 818 if (err < 0) { 819 tegra_xusb_port_unregister(&usb2->base); 820 goto out; 821 } 822 823 list_add_tail(&usb2->base.list, &padctl->ports); 824 825 out: 826 of_node_put(np); 827 return err; 828 } 829 830 void tegra_xusb_usb2_port_release(struct tegra_xusb_port *port) 831 { 832 struct tegra_xusb_usb2_port *usb2 = to_usb2_port(port); 833 834 kfree(usb2); 835 } 836 837 void tegra_xusb_usb2_port_remove(struct tegra_xusb_port *port) 838 { 839 struct tegra_xusb_usb2_port *usb2 = to_usb2_port(port); 840 841 regulator_put(usb2->supply); 842 } 843 844 static int tegra_xusb_ulpi_port_parse_dt(struct tegra_xusb_ulpi_port *ulpi) 845 { 846 struct tegra_xusb_port *port = &ulpi->base; 847 struct device_node *np = port->dev.of_node; 848 849 ulpi->internal = of_property_read_bool(np, "nvidia,internal"); 850 851 return 0; 852 } 853 854 static int tegra_xusb_add_ulpi_port(struct tegra_xusb_padctl *padctl, 855 unsigned int index) 856 { 857 struct tegra_xusb_ulpi_port *ulpi; 858 struct device_node *np; 859 int err = 0; 860 861 np = tegra_xusb_find_port_node(padctl, "ulpi", index); 862 if (!np || !of_device_is_available(np)) 863 goto out; 864 865 ulpi = kzalloc(sizeof(*ulpi), GFP_KERNEL); 866 if (!ulpi) { 867 err = -ENOMEM; 868 goto out; 869 } 870 871 err = tegra_xusb_port_init(&ulpi->base, padctl, np, "ulpi", index); 872 if (err < 0) 873 goto out; 874 875 ulpi->base.ops = padctl->soc->ports.ulpi.ops; 876 877 ulpi->base.lane = ulpi->base.ops->map(&ulpi->base); 878 if (IS_ERR(ulpi->base.lane)) { 879 err = PTR_ERR(ulpi->base.lane); 880 tegra_xusb_port_unregister(&ulpi->base); 881 goto out; 882 } 883 884 err = tegra_xusb_ulpi_port_parse_dt(ulpi); 885 if (err < 0) { 886 tegra_xusb_port_unregister(&ulpi->base); 887 goto out; 888 } 889 890 list_add_tail(&ulpi->base.list, &padctl->ports); 891 892 out: 893 of_node_put(np); 894 return err; 895 } 896 897 void tegra_xusb_ulpi_port_release(struct tegra_xusb_port *port) 898 { 899 struct tegra_xusb_ulpi_port *ulpi = to_ulpi_port(port); 900 901 kfree(ulpi); 902 } 903 904 static int tegra_xusb_hsic_port_parse_dt(struct tegra_xusb_hsic_port *hsic) 905 { 906 /* XXX */ 907 return 0; 908 } 909 910 static int tegra_xusb_add_hsic_port(struct tegra_xusb_padctl *padctl, 911 unsigned int index) 912 { 913 struct tegra_xusb_hsic_port *hsic; 914 struct device_node *np; 915 int err = 0; 916 917 np = tegra_xusb_find_port_node(padctl, "hsic", index); 918 if (!np || !of_device_is_available(np)) 919 goto out; 920 921 hsic = kzalloc(sizeof(*hsic), GFP_KERNEL); 922 if (!hsic) { 923 err = -ENOMEM; 924 goto out; 925 } 926 927 err = tegra_xusb_port_init(&hsic->base, padctl, np, "hsic", index); 928 if (err < 0) 929 goto out; 930 931 hsic->base.ops = padctl->soc->ports.hsic.ops; 932 933 hsic->base.lane = hsic->base.ops->map(&hsic->base); 934 if (IS_ERR(hsic->base.lane)) { 935 err = PTR_ERR(hsic->base.lane); 936 goto out; 937 } 938 939 err = tegra_xusb_hsic_port_parse_dt(hsic); 940 if (err < 0) { 941 tegra_xusb_port_unregister(&hsic->base); 942 goto out; 943 } 944 945 list_add_tail(&hsic->base.list, &padctl->ports); 946 947 out: 948 of_node_put(np); 949 return err; 950 } 951 952 void tegra_xusb_hsic_port_release(struct tegra_xusb_port *port) 953 { 954 struct tegra_xusb_hsic_port *hsic = to_hsic_port(port); 955 956 kfree(hsic); 957 } 958 959 static int tegra_xusb_usb3_port_parse_dt(struct tegra_xusb_usb3_port *usb3) 960 { 961 struct tegra_xusb_port *port = &usb3->base; 962 struct device_node *np = port->dev.of_node; 963 enum usb_device_speed maximum_speed; 964 u32 value; 965 int err; 966 967 err = of_property_read_u32(np, "nvidia,usb2-companion", &value); 968 if (err < 0) { 969 dev_err(&port->dev, "failed to read port: %d\n", err); 970 return err; 971 } 972 973 usb3->port = value; 974 975 usb3->internal = of_property_read_bool(np, "nvidia,internal"); 976 977 if (device_property_present(&port->dev, "maximum-speed")) { 978 maximum_speed = usb_get_maximum_speed(&port->dev); 979 if (maximum_speed == USB_SPEED_SUPER) 980 usb3->disable_gen2 = true; 981 else if (maximum_speed == USB_SPEED_SUPER_PLUS) 982 usb3->disable_gen2 = false; 983 else 984 return -EINVAL; 985 } 986 987 return 0; 988 } 989 990 static int tegra_xusb_add_usb3_port(struct tegra_xusb_padctl *padctl, 991 unsigned int index) 992 { 993 struct tegra_xusb_usb3_port *usb3; 994 struct device_node *np; 995 int err = 0; 996 997 /* 998 * If there is no supplemental configuration in the device tree the 999 * port is unusable. But it is valid to configure only a single port, 1000 * hence return 0 instead of an error to allow ports to be optional. 1001 */ 1002 np = tegra_xusb_find_port_node(padctl, "usb3", index); 1003 if (!np || !of_device_is_available(np)) 1004 goto out; 1005 1006 usb3 = kzalloc(sizeof(*usb3), GFP_KERNEL); 1007 if (!usb3) { 1008 err = -ENOMEM; 1009 goto out; 1010 } 1011 1012 err = tegra_xusb_port_init(&usb3->base, padctl, np, "usb3", index); 1013 if (err < 0) 1014 goto out; 1015 1016 usb3->base.ops = padctl->soc->ports.usb3.ops; 1017 1018 usb3->base.lane = usb3->base.ops->map(&usb3->base); 1019 if (IS_ERR(usb3->base.lane)) { 1020 err = PTR_ERR(usb3->base.lane); 1021 goto out; 1022 } 1023 1024 err = tegra_xusb_usb3_port_parse_dt(usb3); 1025 if (err < 0) { 1026 tegra_xusb_port_unregister(&usb3->base); 1027 goto out; 1028 } 1029 1030 list_add_tail(&usb3->base.list, &padctl->ports); 1031 1032 out: 1033 of_node_put(np); 1034 return err; 1035 } 1036 1037 void tegra_xusb_usb3_port_release(struct tegra_xusb_port *port) 1038 { 1039 struct tegra_xusb_usb3_port *usb3 = to_usb3_port(port); 1040 1041 kfree(usb3); 1042 } 1043 1044 static void __tegra_xusb_remove_ports(struct tegra_xusb_padctl *padctl) 1045 { 1046 struct tegra_xusb_port *port, *tmp; 1047 1048 list_for_each_entry_safe_reverse(port, tmp, &padctl->ports, list) { 1049 list_del(&port->list); 1050 tegra_xusb_port_unregister(port); 1051 } 1052 } 1053 1054 static int tegra_xusb_find_unused_usb3_port(struct tegra_xusb_padctl *padctl) 1055 { 1056 struct device_node *np; 1057 unsigned int i; 1058 1059 for (i = 0; i < padctl->soc->ports.usb3.count; i++) { 1060 np = tegra_xusb_find_port_node(padctl, "usb3", i); 1061 if (!np || !of_device_is_available(np)) 1062 return i; 1063 } 1064 1065 return -ENODEV; 1066 } 1067 1068 static bool tegra_xusb_port_is_companion(struct tegra_xusb_usb2_port *usb2) 1069 { 1070 unsigned int i; 1071 struct tegra_xusb_usb3_port *usb3; 1072 struct tegra_xusb_padctl *padctl = usb2->base.padctl; 1073 1074 for (i = 0; i < padctl->soc->ports.usb3.count; i++) { 1075 usb3 = tegra_xusb_find_usb3_port(padctl, i); 1076 if (usb3 && usb3->port == usb2->base.index) 1077 return true; 1078 } 1079 1080 return false; 1081 } 1082 1083 static int tegra_xusb_update_usb3_fake_port(struct tegra_xusb_usb2_port *usb2) 1084 { 1085 int fake; 1086 1087 /* Disable usb3_port_fake usage by default and assign if needed */ 1088 usb2->usb3_port_fake = -1; 1089 1090 if ((usb2->mode == USB_DR_MODE_OTG || 1091 usb2->mode == USB_DR_MODE_PERIPHERAL) && 1092 !tegra_xusb_port_is_companion(usb2)) { 1093 fake = tegra_xusb_find_unused_usb3_port(usb2->base.padctl); 1094 if (fake < 0) { 1095 dev_err(&usb2->base.dev, "no unused USB3 ports available\n"); 1096 return -ENODEV; 1097 } 1098 1099 dev_dbg(&usb2->base.dev, "Found unused usb3 port: %d\n", fake); 1100 usb2->usb3_port_fake = fake; 1101 } 1102 1103 return 0; 1104 } 1105 1106 static int tegra_xusb_setup_ports(struct tegra_xusb_padctl *padctl) 1107 { 1108 struct tegra_xusb_port *port; 1109 struct tegra_xusb_usb2_port *usb2; 1110 unsigned int i; 1111 int err = 0; 1112 1113 mutex_lock(&padctl->lock); 1114 1115 for (i = 0; i < padctl->soc->ports.usb2.count; i++) { 1116 err = tegra_xusb_add_usb2_port(padctl, i); 1117 if (err < 0) 1118 goto remove_ports; 1119 } 1120 1121 for (i = 0; i < padctl->soc->ports.ulpi.count; i++) { 1122 err = tegra_xusb_add_ulpi_port(padctl, i); 1123 if (err < 0) 1124 goto remove_ports; 1125 } 1126 1127 for (i = 0; i < padctl->soc->ports.hsic.count; i++) { 1128 err = tegra_xusb_add_hsic_port(padctl, i); 1129 if (err < 0) 1130 goto remove_ports; 1131 } 1132 1133 for (i = 0; i < padctl->soc->ports.usb3.count; i++) { 1134 err = tegra_xusb_add_usb3_port(padctl, i); 1135 if (err < 0) 1136 goto remove_ports; 1137 } 1138 1139 if (padctl->soc->need_fake_usb3_port) { 1140 for (i = 0; i < padctl->soc->ports.usb2.count; i++) { 1141 usb2 = tegra_xusb_find_usb2_port(padctl, i); 1142 if (!usb2) 1143 continue; 1144 1145 err = tegra_xusb_update_usb3_fake_port(usb2); 1146 if (err < 0) 1147 goto remove_ports; 1148 } 1149 } 1150 1151 list_for_each_entry(port, &padctl->ports, list) { 1152 err = port->ops->enable(port); 1153 if (err < 0) 1154 dev_err(padctl->dev, "failed to enable port %s: %d\n", 1155 dev_name(&port->dev), err); 1156 } 1157 1158 goto unlock; 1159 1160 remove_ports: 1161 __tegra_xusb_remove_ports(padctl); 1162 unlock: 1163 mutex_unlock(&padctl->lock); 1164 return err; 1165 } 1166 1167 static void tegra_xusb_remove_ports(struct tegra_xusb_padctl *padctl) 1168 { 1169 mutex_lock(&padctl->lock); 1170 __tegra_xusb_remove_ports(padctl); 1171 mutex_unlock(&padctl->lock); 1172 } 1173 1174 static int tegra_xusb_padctl_probe(struct platform_device *pdev) 1175 { 1176 struct device_node *np = pdev->dev.of_node; 1177 const struct tegra_xusb_padctl_soc *soc; 1178 struct tegra_xusb_padctl *padctl; 1179 const struct of_device_id *match; 1180 int err; 1181 1182 /* for backwards compatibility with old device trees */ 1183 np = of_get_child_by_name(np, "pads"); 1184 if (!np) { 1185 dev_warn(&pdev->dev, "deprecated DT, using legacy driver\n"); 1186 return tegra_xusb_padctl_legacy_probe(pdev); 1187 } 1188 1189 of_node_put(np); 1190 1191 match = of_match_node(tegra_xusb_padctl_of_match, pdev->dev.of_node); 1192 soc = match->data; 1193 1194 padctl = soc->ops->probe(&pdev->dev, soc); 1195 if (IS_ERR(padctl)) 1196 return PTR_ERR(padctl); 1197 1198 platform_set_drvdata(pdev, padctl); 1199 INIT_LIST_HEAD(&padctl->ports); 1200 INIT_LIST_HEAD(&padctl->lanes); 1201 INIT_LIST_HEAD(&padctl->pads); 1202 mutex_init(&padctl->lock); 1203 1204 padctl->regs = devm_platform_ioremap_resource(pdev, 0); 1205 if (IS_ERR(padctl->regs)) { 1206 err = PTR_ERR(padctl->regs); 1207 goto remove; 1208 } 1209 1210 padctl->rst = devm_reset_control_get(&pdev->dev, NULL); 1211 if (IS_ERR(padctl->rst)) { 1212 err = PTR_ERR(padctl->rst); 1213 goto remove; 1214 } 1215 1216 padctl->supplies = devm_kcalloc(&pdev->dev, padctl->soc->num_supplies, 1217 sizeof(*padctl->supplies), GFP_KERNEL); 1218 if (!padctl->supplies) { 1219 err = -ENOMEM; 1220 goto remove; 1221 } 1222 1223 regulator_bulk_set_supply_names(padctl->supplies, 1224 padctl->soc->supply_names, 1225 padctl->soc->num_supplies); 1226 1227 err = devm_regulator_bulk_get(&pdev->dev, padctl->soc->num_supplies, 1228 padctl->supplies); 1229 if (err < 0) { 1230 dev_err_probe(&pdev->dev, err, "failed to get regulators\n"); 1231 goto remove; 1232 } 1233 1234 err = reset_control_deassert(padctl->rst); 1235 if (err < 0) 1236 goto remove; 1237 1238 err = regulator_bulk_enable(padctl->soc->num_supplies, 1239 padctl->supplies); 1240 if (err < 0) { 1241 dev_err(&pdev->dev, "failed to enable supplies: %d\n", err); 1242 goto reset; 1243 } 1244 1245 err = tegra_xusb_setup_pads(padctl); 1246 if (err < 0) { 1247 dev_err(&pdev->dev, "failed to setup pads: %d\n", err); 1248 goto power_down; 1249 } 1250 1251 err = tegra_xusb_setup_ports(padctl); 1252 if (err) { 1253 const char *level = KERN_ERR; 1254 1255 if (err == -EPROBE_DEFER) 1256 level = KERN_DEBUG; 1257 1258 dev_printk(level, &pdev->dev, 1259 dev_fmt("failed to setup XUSB ports: %d\n"), err); 1260 goto remove_pads; 1261 } 1262 1263 return 0; 1264 1265 remove_pads: 1266 tegra_xusb_remove_pads(padctl); 1267 power_down: 1268 regulator_bulk_disable(padctl->soc->num_supplies, padctl->supplies); 1269 reset: 1270 reset_control_assert(padctl->rst); 1271 remove: 1272 platform_set_drvdata(pdev, NULL); 1273 soc->ops->remove(padctl); 1274 return err; 1275 } 1276 1277 static void tegra_xusb_padctl_remove(struct platform_device *pdev) 1278 { 1279 struct tegra_xusb_padctl *padctl = platform_get_drvdata(pdev); 1280 int err; 1281 1282 tegra_xusb_remove_ports(padctl); 1283 tegra_xusb_remove_pads(padctl); 1284 1285 err = regulator_bulk_disable(padctl->soc->num_supplies, 1286 padctl->supplies); 1287 if (err < 0) 1288 dev_err(&pdev->dev, "failed to disable supplies: %d\n", err); 1289 1290 err = reset_control_assert(padctl->rst); 1291 if (err < 0) 1292 dev_err(&pdev->dev, "failed to assert reset: %d\n", err); 1293 1294 padctl->soc->ops->remove(padctl); 1295 } 1296 1297 static __maybe_unused int tegra_xusb_padctl_suspend_noirq(struct device *dev) 1298 { 1299 struct tegra_xusb_padctl *padctl = dev_get_drvdata(dev); 1300 1301 if (padctl->soc && padctl->soc->ops && padctl->soc->ops->suspend_noirq) 1302 return padctl->soc->ops->suspend_noirq(padctl); 1303 1304 return 0; 1305 } 1306 1307 static __maybe_unused int tegra_xusb_padctl_resume_noirq(struct device *dev) 1308 { 1309 struct tegra_xusb_padctl *padctl = dev_get_drvdata(dev); 1310 1311 if (padctl->soc && padctl->soc->ops && padctl->soc->ops->resume_noirq) 1312 return padctl->soc->ops->resume_noirq(padctl); 1313 1314 return 0; 1315 } 1316 1317 static const struct dev_pm_ops tegra_xusb_padctl_pm_ops = { 1318 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(tegra_xusb_padctl_suspend_noirq, 1319 tegra_xusb_padctl_resume_noirq) 1320 }; 1321 1322 static struct platform_driver tegra_xusb_padctl_driver = { 1323 .driver = { 1324 .name = "tegra-xusb-padctl", 1325 .of_match_table = tegra_xusb_padctl_of_match, 1326 .pm = &tegra_xusb_padctl_pm_ops, 1327 }, 1328 .probe = tegra_xusb_padctl_probe, 1329 .remove_new = tegra_xusb_padctl_remove, 1330 }; 1331 module_platform_driver(tegra_xusb_padctl_driver); 1332 1333 struct tegra_xusb_padctl *tegra_xusb_padctl_get(struct device *dev) 1334 { 1335 struct tegra_xusb_padctl *padctl; 1336 struct platform_device *pdev; 1337 struct device_node *np; 1338 1339 np = of_parse_phandle(dev->of_node, "nvidia,xusb-padctl", 0); 1340 if (!np) 1341 return ERR_PTR(-EINVAL); 1342 1343 /* 1344 * This is slightly ugly. A better implementation would be to keep a 1345 * registry of pad controllers, but since there will almost certainly 1346 * only ever be one per SoC that would be a little overkill. 1347 */ 1348 pdev = of_find_device_by_node(np); 1349 if (!pdev) { 1350 of_node_put(np); 1351 return ERR_PTR(-ENODEV); 1352 } 1353 1354 of_node_put(np); 1355 1356 padctl = platform_get_drvdata(pdev); 1357 if (!padctl) { 1358 put_device(&pdev->dev); 1359 return ERR_PTR(-EPROBE_DEFER); 1360 } 1361 1362 return padctl; 1363 } 1364 EXPORT_SYMBOL_GPL(tegra_xusb_padctl_get); 1365 1366 void tegra_xusb_padctl_put(struct tegra_xusb_padctl *padctl) 1367 { 1368 if (padctl) 1369 put_device(padctl->dev); 1370 } 1371 EXPORT_SYMBOL_GPL(tegra_xusb_padctl_put); 1372 1373 int tegra_xusb_padctl_usb3_save_context(struct tegra_xusb_padctl *padctl, 1374 unsigned int port) 1375 { 1376 if (padctl->soc->ops->usb3_save_context) 1377 return padctl->soc->ops->usb3_save_context(padctl, port); 1378 1379 return -ENOSYS; 1380 } 1381 EXPORT_SYMBOL_GPL(tegra_xusb_padctl_usb3_save_context); 1382 1383 int tegra_xusb_padctl_hsic_set_idle(struct tegra_xusb_padctl *padctl, 1384 unsigned int port, bool idle) 1385 { 1386 if (padctl->soc->ops->hsic_set_idle) 1387 return padctl->soc->ops->hsic_set_idle(padctl, port, idle); 1388 1389 return -ENOSYS; 1390 } 1391 EXPORT_SYMBOL_GPL(tegra_xusb_padctl_hsic_set_idle); 1392 1393 int tegra_xusb_padctl_enable_phy_sleepwalk(struct tegra_xusb_padctl *padctl, struct phy *phy, 1394 enum usb_device_speed speed) 1395 { 1396 struct tegra_xusb_lane *lane = phy_get_drvdata(phy); 1397 1398 if (lane->pad->ops->enable_phy_sleepwalk) 1399 return lane->pad->ops->enable_phy_sleepwalk(lane, speed); 1400 1401 return -EOPNOTSUPP; 1402 } 1403 EXPORT_SYMBOL_GPL(tegra_xusb_padctl_enable_phy_sleepwalk); 1404 1405 int tegra_xusb_padctl_disable_phy_sleepwalk(struct tegra_xusb_padctl *padctl, struct phy *phy) 1406 { 1407 struct tegra_xusb_lane *lane = phy_get_drvdata(phy); 1408 1409 if (lane->pad->ops->disable_phy_sleepwalk) 1410 return lane->pad->ops->disable_phy_sleepwalk(lane); 1411 1412 return -EOPNOTSUPP; 1413 } 1414 EXPORT_SYMBOL_GPL(tegra_xusb_padctl_disable_phy_sleepwalk); 1415 1416 int tegra_xusb_padctl_enable_phy_wake(struct tegra_xusb_padctl *padctl, struct phy *phy) 1417 { 1418 struct tegra_xusb_lane *lane = phy_get_drvdata(phy); 1419 1420 if (lane->pad->ops->enable_phy_wake) 1421 return lane->pad->ops->enable_phy_wake(lane); 1422 1423 return -EOPNOTSUPP; 1424 } 1425 EXPORT_SYMBOL_GPL(tegra_xusb_padctl_enable_phy_wake); 1426 1427 int tegra_xusb_padctl_disable_phy_wake(struct tegra_xusb_padctl *padctl, struct phy *phy) 1428 { 1429 struct tegra_xusb_lane *lane = phy_get_drvdata(phy); 1430 1431 if (lane->pad->ops->disable_phy_wake) 1432 return lane->pad->ops->disable_phy_wake(lane); 1433 1434 return -EOPNOTSUPP; 1435 } 1436 EXPORT_SYMBOL_GPL(tegra_xusb_padctl_disable_phy_wake); 1437 1438 bool tegra_xusb_padctl_remote_wake_detected(struct tegra_xusb_padctl *padctl, struct phy *phy) 1439 { 1440 struct tegra_xusb_lane *lane = phy_get_drvdata(phy); 1441 1442 if (lane->pad->ops->remote_wake_detected) 1443 return lane->pad->ops->remote_wake_detected(lane); 1444 1445 return false; 1446 } 1447 EXPORT_SYMBOL_GPL(tegra_xusb_padctl_remote_wake_detected); 1448 1449 int tegra_xusb_padctl_usb3_set_lfps_detect(struct tegra_xusb_padctl *padctl, 1450 unsigned int port, bool enable) 1451 { 1452 if (padctl->soc->ops->usb3_set_lfps_detect) 1453 return padctl->soc->ops->usb3_set_lfps_detect(padctl, port, 1454 enable); 1455 1456 return -ENOSYS; 1457 } 1458 EXPORT_SYMBOL_GPL(tegra_xusb_padctl_usb3_set_lfps_detect); 1459 1460 int tegra_xusb_padctl_set_vbus_override(struct tegra_xusb_padctl *padctl, 1461 bool val) 1462 { 1463 if (padctl->soc->ops->vbus_override) 1464 return padctl->soc->ops->vbus_override(padctl, val); 1465 1466 return -ENOTSUPP; 1467 } 1468 EXPORT_SYMBOL_GPL(tegra_xusb_padctl_set_vbus_override); 1469 1470 int tegra_phy_xusb_utmi_port_reset(struct phy *phy) 1471 { 1472 struct tegra_xusb_lane *lane = phy_get_drvdata(phy); 1473 struct tegra_xusb_padctl *padctl = lane->pad->padctl; 1474 1475 if (padctl->soc->ops->utmi_port_reset) 1476 return padctl->soc->ops->utmi_port_reset(phy); 1477 1478 return -ENOTSUPP; 1479 } 1480 EXPORT_SYMBOL_GPL(tegra_phy_xusb_utmi_port_reset); 1481 1482 void tegra_phy_xusb_utmi_pad_power_on(struct phy *phy) 1483 { 1484 struct tegra_xusb_lane *lane; 1485 struct tegra_xusb_padctl *padctl; 1486 1487 if (!phy) 1488 return; 1489 1490 lane = phy_get_drvdata(phy); 1491 padctl = lane->pad->padctl; 1492 1493 if (padctl->soc->ops->utmi_pad_power_on) 1494 padctl->soc->ops->utmi_pad_power_on(phy); 1495 } 1496 EXPORT_SYMBOL_GPL(tegra_phy_xusb_utmi_pad_power_on); 1497 1498 void tegra_phy_xusb_utmi_pad_power_down(struct phy *phy) 1499 { 1500 struct tegra_xusb_lane *lane; 1501 struct tegra_xusb_padctl *padctl; 1502 1503 if (!phy) 1504 return; 1505 1506 lane = phy_get_drvdata(phy); 1507 padctl = lane->pad->padctl; 1508 1509 if (padctl->soc->ops->utmi_pad_power_down) 1510 padctl->soc->ops->utmi_pad_power_down(phy); 1511 } 1512 EXPORT_SYMBOL_GPL(tegra_phy_xusb_utmi_pad_power_down); 1513 1514 int tegra_xusb_padctl_get_usb3_companion(struct tegra_xusb_padctl *padctl, 1515 unsigned int port) 1516 { 1517 struct tegra_xusb_usb2_port *usb2; 1518 struct tegra_xusb_usb3_port *usb3; 1519 int i; 1520 1521 usb2 = tegra_xusb_find_usb2_port(padctl, port); 1522 if (!usb2) 1523 return -EINVAL; 1524 1525 for (i = 0; i < padctl->soc->ports.usb3.count; i++) { 1526 usb3 = tegra_xusb_find_usb3_port(padctl, i); 1527 if (usb3 && usb3->port == usb2->base.index) 1528 return usb3->base.index; 1529 } 1530 1531 return -ENODEV; 1532 } 1533 EXPORT_SYMBOL_GPL(tegra_xusb_padctl_get_usb3_companion); 1534 1535 MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>"); 1536 MODULE_DESCRIPTION("Tegra XUSB Pad Controller driver"); 1537 MODULE_LICENSE("GPL v2"); 1538