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