0001
0002
0003
0004
0005
0006 #include <linux/delay.h>
0007 #include <linux/io.h>
0008 #include <linux/mailbox_client.h>
0009 #include <linux/module.h>
0010 #include <linux/of.h>
0011 #include <linux/of_device.h>
0012 #include <linux/phy/phy.h>
0013 #include <linux/phy/tegra/xusb.h>
0014 #include <linux/platform_device.h>
0015 #include <linux/regulator/consumer.h>
0016 #include <linux/reset.h>
0017 #include <linux/slab.h>
0018 #include <linux/workqueue.h>
0019
0020 #include <soc/tegra/fuse.h>
0021
0022 #include "xusb.h"
0023
0024 static struct phy *tegra_xusb_pad_of_xlate(struct device *dev,
0025 struct of_phandle_args *args)
0026 {
0027 struct tegra_xusb_pad *pad = dev_get_drvdata(dev);
0028 struct phy *phy = NULL;
0029 unsigned int i;
0030
0031 if (args->args_count != 0)
0032 return ERR_PTR(-EINVAL);
0033
0034 for (i = 0; i < pad->soc->num_lanes; i++) {
0035 if (!pad->lanes[i])
0036 continue;
0037
0038 if (pad->lanes[i]->dev.of_node == args->np) {
0039 phy = pad->lanes[i];
0040 break;
0041 }
0042 }
0043
0044 if (phy == NULL)
0045 phy = ERR_PTR(-ENODEV);
0046
0047 return phy;
0048 }
0049
0050 static const struct of_device_id tegra_xusb_padctl_of_match[] = {
0051 #if defined(CONFIG_ARCH_TEGRA_124_SOC) || defined(CONFIG_ARCH_TEGRA_132_SOC)
0052 {
0053 .compatible = "nvidia,tegra124-xusb-padctl",
0054 .data = &tegra124_xusb_padctl_soc,
0055 },
0056 #endif
0057 #if defined(CONFIG_ARCH_TEGRA_210_SOC)
0058 {
0059 .compatible = "nvidia,tegra210-xusb-padctl",
0060 .data = &tegra210_xusb_padctl_soc,
0061 },
0062 #endif
0063 #if defined(CONFIG_ARCH_TEGRA_186_SOC)
0064 {
0065 .compatible = "nvidia,tegra186-xusb-padctl",
0066 .data = &tegra186_xusb_padctl_soc,
0067 },
0068 #endif
0069 #if defined(CONFIG_ARCH_TEGRA_194_SOC)
0070 {
0071 .compatible = "nvidia,tegra194-xusb-padctl",
0072 .data = &tegra194_xusb_padctl_soc,
0073 },
0074 #endif
0075 { }
0076 };
0077 MODULE_DEVICE_TABLE(of, tegra_xusb_padctl_of_match);
0078
0079 static struct device_node *
0080 tegra_xusb_find_pad_node(struct tegra_xusb_padctl *padctl, const char *name)
0081 {
0082 struct device_node *pads, *np;
0083
0084 pads = of_get_child_by_name(padctl->dev->of_node, "pads");
0085 if (!pads)
0086 return NULL;
0087
0088 np = of_get_child_by_name(pads, name);
0089 of_node_put(pads);
0090
0091 return np;
0092 }
0093
0094 static struct device_node *
0095 tegra_xusb_pad_find_phy_node(struct tegra_xusb_pad *pad, unsigned int index)
0096 {
0097 struct device_node *np, *lanes;
0098
0099 lanes = of_get_child_by_name(pad->dev.of_node, "lanes");
0100 if (!lanes)
0101 return NULL;
0102
0103 np = of_get_child_by_name(lanes, pad->soc->lanes[index].name);
0104 of_node_put(lanes);
0105
0106 return np;
0107 }
0108
0109 int tegra_xusb_lane_parse_dt(struct tegra_xusb_lane *lane,
0110 struct device_node *np)
0111 {
0112 struct device *dev = &lane->pad->dev;
0113 const char *function;
0114 int err;
0115
0116 err = of_property_read_string(np, "nvidia,function", &function);
0117 if (err < 0)
0118 return err;
0119
0120 err = match_string(lane->soc->funcs, lane->soc->num_funcs, function);
0121 if (err < 0) {
0122 dev_err(dev, "invalid function \"%s\" for lane \"%pOFn\"\n",
0123 function, np);
0124 return err;
0125 }
0126
0127 lane->function = err;
0128
0129 return 0;
0130 }
0131
0132 static void tegra_xusb_lane_destroy(struct phy *phy)
0133 {
0134 if (phy) {
0135 struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
0136
0137 lane->pad->ops->remove(lane);
0138 phy_destroy(phy);
0139 }
0140 }
0141
0142 static void tegra_xusb_pad_release(struct device *dev)
0143 {
0144 struct tegra_xusb_pad *pad = to_tegra_xusb_pad(dev);
0145
0146 pad->soc->ops->remove(pad);
0147 }
0148
0149 static const struct device_type tegra_xusb_pad_type = {
0150 .release = tegra_xusb_pad_release,
0151 };
0152
0153 int tegra_xusb_pad_init(struct tegra_xusb_pad *pad,
0154 struct tegra_xusb_padctl *padctl,
0155 struct device_node *np)
0156 {
0157 int err;
0158
0159 device_initialize(&pad->dev);
0160 INIT_LIST_HEAD(&pad->list);
0161 pad->dev.parent = padctl->dev;
0162 pad->dev.type = &tegra_xusb_pad_type;
0163 pad->dev.of_node = np;
0164 pad->padctl = padctl;
0165
0166 err = dev_set_name(&pad->dev, "%s", pad->soc->name);
0167 if (err < 0)
0168 goto unregister;
0169
0170 err = device_add(&pad->dev);
0171 if (err < 0)
0172 goto unregister;
0173
0174 return 0;
0175
0176 unregister:
0177 device_unregister(&pad->dev);
0178 return err;
0179 }
0180
0181 int tegra_xusb_pad_register(struct tegra_xusb_pad *pad,
0182 const struct phy_ops *ops)
0183 {
0184 struct device_node *children;
0185 struct phy *lane;
0186 unsigned int i;
0187 int err;
0188
0189 children = of_get_child_by_name(pad->dev.of_node, "lanes");
0190 if (!children)
0191 return -ENODEV;
0192
0193 pad->lanes = devm_kcalloc(&pad->dev, pad->soc->num_lanes, sizeof(lane),
0194 GFP_KERNEL);
0195 if (!pad->lanes) {
0196 of_node_put(children);
0197 return -ENOMEM;
0198 }
0199
0200 for (i = 0; i < pad->soc->num_lanes; i++) {
0201 struct device_node *np = tegra_xusb_pad_find_phy_node(pad, i);
0202 struct tegra_xusb_lane *lane;
0203
0204
0205 if (!np || !of_device_is_available(np)) {
0206 of_node_put(np);
0207 continue;
0208 }
0209
0210 pad->lanes[i] = phy_create(&pad->dev, np, ops);
0211 if (IS_ERR(pad->lanes[i])) {
0212 err = PTR_ERR(pad->lanes[i]);
0213 of_node_put(np);
0214 goto remove;
0215 }
0216
0217 lane = pad->ops->probe(pad, np, i);
0218 if (IS_ERR(lane)) {
0219 phy_destroy(pad->lanes[i]);
0220 err = PTR_ERR(lane);
0221 goto remove;
0222 }
0223
0224 list_add_tail(&lane->list, &pad->padctl->lanes);
0225 phy_set_drvdata(pad->lanes[i], lane);
0226 }
0227
0228 pad->provider = of_phy_provider_register_full(&pad->dev, children,
0229 tegra_xusb_pad_of_xlate);
0230 if (IS_ERR(pad->provider)) {
0231 err = PTR_ERR(pad->provider);
0232 goto remove;
0233 }
0234
0235 return 0;
0236
0237 remove:
0238 while (i--)
0239 tegra_xusb_lane_destroy(pad->lanes[i]);
0240
0241 of_node_put(children);
0242
0243 return err;
0244 }
0245
0246 void tegra_xusb_pad_unregister(struct tegra_xusb_pad *pad)
0247 {
0248 unsigned int i = pad->soc->num_lanes;
0249
0250 of_phy_provider_unregister(pad->provider);
0251
0252 while (i--)
0253 tegra_xusb_lane_destroy(pad->lanes[i]);
0254
0255 device_unregister(&pad->dev);
0256 }
0257
0258 static struct tegra_xusb_pad *
0259 tegra_xusb_pad_create(struct tegra_xusb_padctl *padctl,
0260 const struct tegra_xusb_pad_soc *soc)
0261 {
0262 struct tegra_xusb_pad *pad;
0263 struct device_node *np;
0264 int err;
0265
0266 np = tegra_xusb_find_pad_node(padctl, soc->name);
0267 if (!np || !of_device_is_available(np))
0268 return NULL;
0269
0270 pad = soc->ops->probe(padctl, soc, np);
0271 if (IS_ERR(pad)) {
0272 err = PTR_ERR(pad);
0273 dev_err(padctl->dev, "failed to create pad %s: %d\n",
0274 soc->name, err);
0275 return ERR_PTR(err);
0276 }
0277
0278
0279 if (strcmp(soc->name, "pcie") == 0)
0280 padctl->pcie = pad;
0281
0282 if (strcmp(soc->name, "sata") == 0)
0283 padctl->sata = pad;
0284
0285 if (strcmp(soc->name, "usb2") == 0)
0286 padctl->usb2 = pad;
0287
0288 if (strcmp(soc->name, "ulpi") == 0)
0289 padctl->ulpi = pad;
0290
0291 if (strcmp(soc->name, "hsic") == 0)
0292 padctl->hsic = pad;
0293
0294 return pad;
0295 }
0296
0297 static void __tegra_xusb_remove_pads(struct tegra_xusb_padctl *padctl)
0298 {
0299 struct tegra_xusb_pad *pad, *tmp;
0300
0301 list_for_each_entry_safe_reverse(pad, tmp, &padctl->pads, list) {
0302 list_del(&pad->list);
0303 tegra_xusb_pad_unregister(pad);
0304 }
0305 }
0306
0307 static void tegra_xusb_remove_pads(struct tegra_xusb_padctl *padctl)
0308 {
0309 mutex_lock(&padctl->lock);
0310 __tegra_xusb_remove_pads(padctl);
0311 mutex_unlock(&padctl->lock);
0312 }
0313
0314 static void tegra_xusb_lane_program(struct tegra_xusb_lane *lane)
0315 {
0316 struct tegra_xusb_padctl *padctl = lane->pad->padctl;
0317 const struct tegra_xusb_lane_soc *soc = lane->soc;
0318 u32 value;
0319
0320
0321 if (soc->num_funcs < 2)
0322 return;
0323
0324 if (lane->pad->ops->iddq_enable)
0325 lane->pad->ops->iddq_enable(lane);
0326
0327
0328 value = padctl_readl(padctl, soc->offset);
0329 value &= ~(soc->mask << soc->shift);
0330 value |= lane->function << soc->shift;
0331 padctl_writel(padctl, value, soc->offset);
0332
0333 if (lane->pad->ops->iddq_disable)
0334 lane->pad->ops->iddq_disable(lane);
0335 }
0336
0337 static void tegra_xusb_pad_program(struct tegra_xusb_pad *pad)
0338 {
0339 unsigned int i;
0340
0341 for (i = 0; i < pad->soc->num_lanes; i++) {
0342 struct tegra_xusb_lane *lane;
0343
0344 if (pad->lanes[i]) {
0345 lane = phy_get_drvdata(pad->lanes[i]);
0346 tegra_xusb_lane_program(lane);
0347 }
0348 }
0349 }
0350
0351 static int tegra_xusb_setup_pads(struct tegra_xusb_padctl *padctl)
0352 {
0353 struct tegra_xusb_pad *pad;
0354 unsigned int i;
0355
0356 mutex_lock(&padctl->lock);
0357
0358 for (i = 0; i < padctl->soc->num_pads; i++) {
0359 const struct tegra_xusb_pad_soc *soc = padctl->soc->pads[i];
0360 int err;
0361
0362 pad = tegra_xusb_pad_create(padctl, soc);
0363 if (IS_ERR(pad)) {
0364 err = PTR_ERR(pad);
0365 dev_err(padctl->dev, "failed to create pad %s: %d\n",
0366 soc->name, err);
0367 __tegra_xusb_remove_pads(padctl);
0368 mutex_unlock(&padctl->lock);
0369 return err;
0370 }
0371
0372 if (!pad)
0373 continue;
0374
0375 list_add_tail(&pad->list, &padctl->pads);
0376 }
0377
0378 list_for_each_entry(pad, &padctl->pads, list)
0379 tegra_xusb_pad_program(pad);
0380
0381 mutex_unlock(&padctl->lock);
0382 return 0;
0383 }
0384
0385 bool tegra_xusb_lane_check(struct tegra_xusb_lane *lane,
0386 const char *function)
0387 {
0388 const char *func = lane->soc->funcs[lane->function];
0389
0390 return strcmp(function, func) == 0;
0391 }
0392
0393 struct tegra_xusb_lane *tegra_xusb_find_lane(struct tegra_xusb_padctl *padctl,
0394 const char *type,
0395 unsigned int index)
0396 {
0397 struct tegra_xusb_lane *lane, *hit = ERR_PTR(-ENODEV);
0398 char *name;
0399
0400 name = kasprintf(GFP_KERNEL, "%s-%u", type, index);
0401 if (!name)
0402 return ERR_PTR(-ENOMEM);
0403
0404 list_for_each_entry(lane, &padctl->lanes, list) {
0405 if (strcmp(lane->soc->name, name) == 0) {
0406 hit = lane;
0407 break;
0408 }
0409 }
0410
0411 kfree(name);
0412 return hit;
0413 }
0414
0415 struct tegra_xusb_lane *
0416 tegra_xusb_port_find_lane(struct tegra_xusb_port *port,
0417 const struct tegra_xusb_lane_map *map,
0418 const char *function)
0419 {
0420 struct tegra_xusb_lane *lane, *match = ERR_PTR(-ENODEV);
0421
0422 for (; map->type; map++) {
0423 if (port->index != map->port)
0424 continue;
0425
0426 lane = tegra_xusb_find_lane(port->padctl, map->type,
0427 map->index);
0428 if (IS_ERR(lane))
0429 continue;
0430
0431 if (!tegra_xusb_lane_check(lane, function))
0432 continue;
0433
0434 if (!IS_ERR(match))
0435 dev_err(&port->dev, "conflicting match: %s-%u / %s\n",
0436 map->type, map->index, match->soc->name);
0437 else
0438 match = lane;
0439 }
0440
0441 return match;
0442 }
0443
0444 static struct device_node *
0445 tegra_xusb_find_port_node(struct tegra_xusb_padctl *padctl, const char *type,
0446 unsigned int index)
0447 {
0448 struct device_node *ports, *np;
0449 char *name;
0450
0451 ports = of_get_child_by_name(padctl->dev->of_node, "ports");
0452 if (!ports)
0453 return NULL;
0454
0455 name = kasprintf(GFP_KERNEL, "%s-%u", type, index);
0456 if (!name) {
0457 of_node_put(ports);
0458 return NULL;
0459 }
0460 np = of_get_child_by_name(ports, name);
0461 kfree(name);
0462 of_node_put(ports);
0463
0464 return np;
0465 }
0466
0467 struct tegra_xusb_port *
0468 tegra_xusb_find_port(struct tegra_xusb_padctl *padctl, const char *type,
0469 unsigned int index)
0470 {
0471 struct tegra_xusb_port *port;
0472 struct device_node *np;
0473
0474 np = tegra_xusb_find_port_node(padctl, type, index);
0475 if (!np)
0476 return NULL;
0477
0478 list_for_each_entry(port, &padctl->ports, list) {
0479 if (np == port->dev.of_node) {
0480 of_node_put(np);
0481 return port;
0482 }
0483 }
0484
0485 of_node_put(np);
0486
0487 return NULL;
0488 }
0489
0490 struct tegra_xusb_usb2_port *
0491 tegra_xusb_find_usb2_port(struct tegra_xusb_padctl *padctl, unsigned int index)
0492 {
0493 struct tegra_xusb_port *port;
0494
0495 port = tegra_xusb_find_port(padctl, "usb2", index);
0496 if (port)
0497 return to_usb2_port(port);
0498
0499 return NULL;
0500 }
0501
0502 struct tegra_xusb_usb3_port *
0503 tegra_xusb_find_usb3_port(struct tegra_xusb_padctl *padctl, unsigned int index)
0504 {
0505 struct tegra_xusb_port *port;
0506
0507 port = tegra_xusb_find_port(padctl, "usb3", index);
0508 if (port)
0509 return to_usb3_port(port);
0510
0511 return NULL;
0512 }
0513
0514 static void tegra_xusb_port_release(struct device *dev)
0515 {
0516 struct tegra_xusb_port *port = to_tegra_xusb_port(dev);
0517
0518 if (port->ops->release)
0519 port->ops->release(port);
0520 }
0521
0522 static const struct device_type tegra_xusb_port_type = {
0523 .release = tegra_xusb_port_release,
0524 };
0525
0526 static int tegra_xusb_port_init(struct tegra_xusb_port *port,
0527 struct tegra_xusb_padctl *padctl,
0528 struct device_node *np,
0529 const char *name,
0530 unsigned int index)
0531 {
0532 int err;
0533
0534 INIT_LIST_HEAD(&port->list);
0535 port->padctl = padctl;
0536 port->index = index;
0537
0538 device_initialize(&port->dev);
0539 port->dev.type = &tegra_xusb_port_type;
0540 port->dev.of_node = of_node_get(np);
0541 port->dev.parent = padctl->dev;
0542
0543 err = dev_set_name(&port->dev, "%s-%u", name, index);
0544 if (err < 0)
0545 goto unregister;
0546
0547 err = device_add(&port->dev);
0548 if (err < 0)
0549 goto unregister;
0550
0551 return 0;
0552
0553 unregister:
0554 device_unregister(&port->dev);
0555 return err;
0556 }
0557
0558 static void tegra_xusb_port_unregister(struct tegra_xusb_port *port)
0559 {
0560 if (!IS_ERR_OR_NULL(port->usb_role_sw)) {
0561 of_platform_depopulate(&port->dev);
0562 usb_role_switch_unregister(port->usb_role_sw);
0563 cancel_work_sync(&port->usb_phy_work);
0564 usb_remove_phy(&port->usb_phy);
0565 }
0566
0567 if (port->ops->remove)
0568 port->ops->remove(port);
0569
0570 device_unregister(&port->dev);
0571 }
0572
0573 static const char *const modes[] = {
0574 [USB_DR_MODE_UNKNOWN] = "",
0575 [USB_DR_MODE_HOST] = "host",
0576 [USB_DR_MODE_PERIPHERAL] = "peripheral",
0577 [USB_DR_MODE_OTG] = "otg",
0578 };
0579
0580 static const char * const usb_roles[] = {
0581 [USB_ROLE_NONE] = "none",
0582 [USB_ROLE_HOST] = "host",
0583 [USB_ROLE_DEVICE] = "device",
0584 };
0585
0586 static enum usb_phy_events to_usb_phy_event(enum usb_role role)
0587 {
0588 switch (role) {
0589 case USB_ROLE_DEVICE:
0590 return USB_EVENT_VBUS;
0591
0592 case USB_ROLE_HOST:
0593 return USB_EVENT_ID;
0594
0595 default:
0596 return USB_EVENT_NONE;
0597 }
0598 }
0599
0600 static void tegra_xusb_usb_phy_work(struct work_struct *work)
0601 {
0602 struct tegra_xusb_port *port = container_of(work,
0603 struct tegra_xusb_port,
0604 usb_phy_work);
0605 enum usb_role role = usb_role_switch_get_role(port->usb_role_sw);
0606
0607 usb_phy_set_event(&port->usb_phy, to_usb_phy_event(role));
0608
0609 dev_dbg(&port->dev, "%s(): calling notifier for role %s\n", __func__,
0610 usb_roles[role]);
0611
0612 atomic_notifier_call_chain(&port->usb_phy.notifier, 0, &port->usb_phy);
0613 }
0614
0615 static int tegra_xusb_role_sw_set(struct usb_role_switch *sw,
0616 enum usb_role role)
0617 {
0618 struct tegra_xusb_port *port = usb_role_switch_get_drvdata(sw);
0619
0620 dev_dbg(&port->dev, "%s(): role %s\n", __func__, usb_roles[role]);
0621
0622 schedule_work(&port->usb_phy_work);
0623
0624 return 0;
0625 }
0626
0627 static int tegra_xusb_set_peripheral(struct usb_otg *otg,
0628 struct usb_gadget *gadget)
0629 {
0630 struct tegra_xusb_port *port = container_of(otg->usb_phy,
0631 struct tegra_xusb_port,
0632 usb_phy);
0633
0634 if (gadget != NULL)
0635 schedule_work(&port->usb_phy_work);
0636
0637 return 0;
0638 }
0639
0640 static int tegra_xusb_set_host(struct usb_otg *otg, struct usb_bus *host)
0641 {
0642 struct tegra_xusb_port *port = container_of(otg->usb_phy,
0643 struct tegra_xusb_port,
0644 usb_phy);
0645
0646 if (host != NULL)
0647 schedule_work(&port->usb_phy_work);
0648
0649 return 0;
0650 }
0651
0652
0653 static int tegra_xusb_setup_usb_role_switch(struct tegra_xusb_port *port)
0654 {
0655 struct tegra_xusb_lane *lane;
0656 struct usb_role_switch_desc role_sx_desc = {
0657 .fwnode = dev_fwnode(&port->dev),
0658 .set = tegra_xusb_role_sw_set,
0659 };
0660 int err = 0;
0661
0662
0663
0664
0665
0666
0667
0668 port->dev.driver = devm_kzalloc(&port->dev,
0669 sizeof(struct device_driver),
0670 GFP_KERNEL);
0671 port->dev.driver->owner = THIS_MODULE;
0672
0673 port->usb_role_sw = usb_role_switch_register(&port->dev,
0674 &role_sx_desc);
0675 if (IS_ERR(port->usb_role_sw)) {
0676 err = PTR_ERR(port->usb_role_sw);
0677 dev_err(&port->dev, "failed to register USB role switch: %d",
0678 err);
0679 return err;
0680 }
0681
0682 INIT_WORK(&port->usb_phy_work, tegra_xusb_usb_phy_work);
0683 usb_role_switch_set_drvdata(port->usb_role_sw, port);
0684
0685 port->usb_phy.otg = devm_kzalloc(&port->dev, sizeof(struct usb_otg),
0686 GFP_KERNEL);
0687 if (!port->usb_phy.otg)
0688 return -ENOMEM;
0689
0690 lane = tegra_xusb_find_lane(port->padctl, "usb2", port->index);
0691
0692
0693
0694
0695
0696 port->usb_phy.dev = &lane->pad->lanes[port->index]->dev;
0697 port->usb_phy.dev->driver = port->dev.driver;
0698 port->usb_phy.otg->usb_phy = &port->usb_phy;
0699 port->usb_phy.otg->set_peripheral = tegra_xusb_set_peripheral;
0700 port->usb_phy.otg->set_host = tegra_xusb_set_host;
0701
0702 err = usb_add_phy_dev(&port->usb_phy);
0703 if (err < 0) {
0704 dev_err(&port->dev, "Failed to add USB PHY: %d\n", err);
0705 return err;
0706 }
0707
0708
0709 of_platform_populate(port->dev.of_node, NULL, NULL, &port->dev);
0710
0711 return err;
0712 }
0713
0714 static int tegra_xusb_usb2_port_parse_dt(struct tegra_xusb_usb2_port *usb2)
0715 {
0716 struct tegra_xusb_port *port = &usb2->base;
0717 struct device_node *np = port->dev.of_node;
0718 const char *mode;
0719 int err;
0720
0721 usb2->internal = of_property_read_bool(np, "nvidia,internal");
0722
0723 if (!of_property_read_string(np, "mode", &mode)) {
0724 int err = match_string(modes, ARRAY_SIZE(modes), mode);
0725 if (err < 0) {
0726 dev_err(&port->dev, "invalid value %s for \"mode\"\n",
0727 mode);
0728 usb2->mode = USB_DR_MODE_UNKNOWN;
0729 } else {
0730 usb2->mode = err;
0731 }
0732 } else {
0733 usb2->mode = USB_DR_MODE_HOST;
0734 }
0735
0736
0737 if (usb2->mode == USB_DR_MODE_PERIPHERAL ||
0738 usb2->mode == USB_DR_MODE_OTG) {
0739 if (of_property_read_bool(np, "usb-role-switch")) {
0740 err = tegra_xusb_setup_usb_role_switch(port);
0741 if (err < 0)
0742 return err;
0743 } else {
0744 dev_err(&port->dev, "usb-role-switch not found for %s mode",
0745 modes[usb2->mode]);
0746 return -EINVAL;
0747 }
0748 }
0749
0750 usb2->supply = regulator_get(&port->dev, "vbus");
0751 return PTR_ERR_OR_ZERO(usb2->supply);
0752 }
0753
0754 static int tegra_xusb_add_usb2_port(struct tegra_xusb_padctl *padctl,
0755 unsigned int index)
0756 {
0757 struct tegra_xusb_usb2_port *usb2;
0758 struct device_node *np;
0759 int err = 0;
0760
0761
0762
0763
0764
0765 np = tegra_xusb_find_port_node(padctl, "usb2", index);
0766 if (!np || !of_device_is_available(np))
0767 goto out;
0768
0769 usb2 = kzalloc(sizeof(*usb2), GFP_KERNEL);
0770 if (!usb2) {
0771 err = -ENOMEM;
0772 goto out;
0773 }
0774
0775 err = tegra_xusb_port_init(&usb2->base, padctl, np, "usb2", index);
0776 if (err < 0)
0777 goto out;
0778
0779 usb2->base.ops = padctl->soc->ports.usb2.ops;
0780
0781 usb2->base.lane = usb2->base.ops->map(&usb2->base);
0782 if (IS_ERR(usb2->base.lane)) {
0783 err = PTR_ERR(usb2->base.lane);
0784 goto out;
0785 }
0786
0787 err = tegra_xusb_usb2_port_parse_dt(usb2);
0788 if (err < 0) {
0789 tegra_xusb_port_unregister(&usb2->base);
0790 goto out;
0791 }
0792
0793 list_add_tail(&usb2->base.list, &padctl->ports);
0794
0795 out:
0796 of_node_put(np);
0797 return err;
0798 }
0799
0800 void tegra_xusb_usb2_port_release(struct tegra_xusb_port *port)
0801 {
0802 struct tegra_xusb_usb2_port *usb2 = to_usb2_port(port);
0803
0804 kfree(usb2);
0805 }
0806
0807 void tegra_xusb_usb2_port_remove(struct tegra_xusb_port *port)
0808 {
0809 struct tegra_xusb_usb2_port *usb2 = to_usb2_port(port);
0810
0811 regulator_put(usb2->supply);
0812 }
0813
0814 static int tegra_xusb_ulpi_port_parse_dt(struct tegra_xusb_ulpi_port *ulpi)
0815 {
0816 struct tegra_xusb_port *port = &ulpi->base;
0817 struct device_node *np = port->dev.of_node;
0818
0819 ulpi->internal = of_property_read_bool(np, "nvidia,internal");
0820
0821 return 0;
0822 }
0823
0824 static int tegra_xusb_add_ulpi_port(struct tegra_xusb_padctl *padctl,
0825 unsigned int index)
0826 {
0827 struct tegra_xusb_ulpi_port *ulpi;
0828 struct device_node *np;
0829 int err = 0;
0830
0831 np = tegra_xusb_find_port_node(padctl, "ulpi", index);
0832 if (!np || !of_device_is_available(np))
0833 goto out;
0834
0835 ulpi = kzalloc(sizeof(*ulpi), GFP_KERNEL);
0836 if (!ulpi) {
0837 err = -ENOMEM;
0838 goto out;
0839 }
0840
0841 err = tegra_xusb_port_init(&ulpi->base, padctl, np, "ulpi", index);
0842 if (err < 0)
0843 goto out;
0844
0845 ulpi->base.ops = padctl->soc->ports.ulpi.ops;
0846
0847 ulpi->base.lane = ulpi->base.ops->map(&ulpi->base);
0848 if (IS_ERR(ulpi->base.lane)) {
0849 err = PTR_ERR(ulpi->base.lane);
0850 goto out;
0851 }
0852
0853 err = tegra_xusb_ulpi_port_parse_dt(ulpi);
0854 if (err < 0) {
0855 tegra_xusb_port_unregister(&ulpi->base);
0856 goto out;
0857 }
0858
0859 list_add_tail(&ulpi->base.list, &padctl->ports);
0860
0861 out:
0862 of_node_put(np);
0863 return err;
0864 }
0865
0866 void tegra_xusb_ulpi_port_release(struct tegra_xusb_port *port)
0867 {
0868 struct tegra_xusb_ulpi_port *ulpi = to_ulpi_port(port);
0869
0870 kfree(ulpi);
0871 }
0872
0873 static int tegra_xusb_hsic_port_parse_dt(struct tegra_xusb_hsic_port *hsic)
0874 {
0875
0876 return 0;
0877 }
0878
0879 static int tegra_xusb_add_hsic_port(struct tegra_xusb_padctl *padctl,
0880 unsigned int index)
0881 {
0882 struct tegra_xusb_hsic_port *hsic;
0883 struct device_node *np;
0884 int err = 0;
0885
0886 np = tegra_xusb_find_port_node(padctl, "hsic", index);
0887 if (!np || !of_device_is_available(np))
0888 goto out;
0889
0890 hsic = kzalloc(sizeof(*hsic), GFP_KERNEL);
0891 if (!hsic) {
0892 err = -ENOMEM;
0893 goto out;
0894 }
0895
0896 err = tegra_xusb_port_init(&hsic->base, padctl, np, "hsic", index);
0897 if (err < 0)
0898 goto out;
0899
0900 hsic->base.ops = padctl->soc->ports.hsic.ops;
0901
0902 hsic->base.lane = hsic->base.ops->map(&hsic->base);
0903 if (IS_ERR(hsic->base.lane)) {
0904 err = PTR_ERR(hsic->base.lane);
0905 goto out;
0906 }
0907
0908 err = tegra_xusb_hsic_port_parse_dt(hsic);
0909 if (err < 0) {
0910 tegra_xusb_port_unregister(&hsic->base);
0911 goto out;
0912 }
0913
0914 list_add_tail(&hsic->base.list, &padctl->ports);
0915
0916 out:
0917 of_node_put(np);
0918 return err;
0919 }
0920
0921 void tegra_xusb_hsic_port_release(struct tegra_xusb_port *port)
0922 {
0923 struct tegra_xusb_hsic_port *hsic = to_hsic_port(port);
0924
0925 kfree(hsic);
0926 }
0927
0928 static int tegra_xusb_usb3_port_parse_dt(struct tegra_xusb_usb3_port *usb3)
0929 {
0930 struct tegra_xusb_port *port = &usb3->base;
0931 struct device_node *np = port->dev.of_node;
0932 enum usb_device_speed maximum_speed;
0933 u32 value;
0934 int err;
0935
0936 err = of_property_read_u32(np, "nvidia,usb2-companion", &value);
0937 if (err < 0) {
0938 dev_err(&port->dev, "failed to read port: %d\n", err);
0939 return err;
0940 }
0941
0942 usb3->port = value;
0943
0944 usb3->internal = of_property_read_bool(np, "nvidia,internal");
0945
0946 if (device_property_present(&port->dev, "maximum-speed")) {
0947 maximum_speed = usb_get_maximum_speed(&port->dev);
0948 if (maximum_speed == USB_SPEED_SUPER)
0949 usb3->disable_gen2 = true;
0950 else if (maximum_speed == USB_SPEED_SUPER_PLUS)
0951 usb3->disable_gen2 = false;
0952 else
0953 return -EINVAL;
0954 }
0955
0956 usb3->supply = regulator_get(&port->dev, "vbus");
0957 return PTR_ERR_OR_ZERO(usb3->supply);
0958 }
0959
0960 static int tegra_xusb_add_usb3_port(struct tegra_xusb_padctl *padctl,
0961 unsigned int index)
0962 {
0963 struct tegra_xusb_usb3_port *usb3;
0964 struct device_node *np;
0965 int err = 0;
0966
0967
0968
0969
0970
0971
0972 np = tegra_xusb_find_port_node(padctl, "usb3", index);
0973 if (!np || !of_device_is_available(np))
0974 goto out;
0975
0976 usb3 = kzalloc(sizeof(*usb3), GFP_KERNEL);
0977 if (!usb3) {
0978 err = -ENOMEM;
0979 goto out;
0980 }
0981
0982 err = tegra_xusb_port_init(&usb3->base, padctl, np, "usb3", index);
0983 if (err < 0)
0984 goto out;
0985
0986 usb3->base.ops = padctl->soc->ports.usb3.ops;
0987
0988 usb3->base.lane = usb3->base.ops->map(&usb3->base);
0989 if (IS_ERR(usb3->base.lane)) {
0990 err = PTR_ERR(usb3->base.lane);
0991 goto out;
0992 }
0993
0994 err = tegra_xusb_usb3_port_parse_dt(usb3);
0995 if (err < 0) {
0996 tegra_xusb_port_unregister(&usb3->base);
0997 goto out;
0998 }
0999
1000 list_add_tail(&usb3->base.list, &padctl->ports);
1001
1002 out:
1003 of_node_put(np);
1004 return err;
1005 }
1006
1007 void tegra_xusb_usb3_port_release(struct tegra_xusb_port *port)
1008 {
1009 struct tegra_xusb_usb3_port *usb3 = to_usb3_port(port);
1010
1011 kfree(usb3);
1012 }
1013
1014 void tegra_xusb_usb3_port_remove(struct tegra_xusb_port *port)
1015 {
1016 struct tegra_xusb_usb3_port *usb3 = to_usb3_port(port);
1017
1018 regulator_put(usb3->supply);
1019 }
1020
1021 static void __tegra_xusb_remove_ports(struct tegra_xusb_padctl *padctl)
1022 {
1023 struct tegra_xusb_port *port, *tmp;
1024
1025 list_for_each_entry_safe_reverse(port, tmp, &padctl->ports, list) {
1026 list_del(&port->list);
1027 tegra_xusb_port_unregister(port);
1028 }
1029 }
1030
1031 static int tegra_xusb_find_unused_usb3_port(struct tegra_xusb_padctl *padctl)
1032 {
1033 struct device_node *np;
1034 unsigned int i;
1035
1036 for (i = 0; i < padctl->soc->ports.usb3.count; i++) {
1037 np = tegra_xusb_find_port_node(padctl, "usb3", i);
1038 if (!np || !of_device_is_available(np))
1039 return i;
1040 }
1041
1042 return -ENODEV;
1043 }
1044
1045 static bool tegra_xusb_port_is_companion(struct tegra_xusb_usb2_port *usb2)
1046 {
1047 unsigned int i;
1048 struct tegra_xusb_usb3_port *usb3;
1049 struct tegra_xusb_padctl *padctl = usb2->base.padctl;
1050
1051 for (i = 0; i < padctl->soc->ports.usb3.count; i++) {
1052 usb3 = tegra_xusb_find_usb3_port(padctl, i);
1053 if (usb3 && usb3->port == usb2->base.index)
1054 return true;
1055 }
1056
1057 return false;
1058 }
1059
1060 static int tegra_xusb_update_usb3_fake_port(struct tegra_xusb_usb2_port *usb2)
1061 {
1062 int fake;
1063
1064
1065 usb2->usb3_port_fake = -1;
1066
1067 if ((usb2->mode == USB_DR_MODE_OTG ||
1068 usb2->mode == USB_DR_MODE_PERIPHERAL) &&
1069 !tegra_xusb_port_is_companion(usb2)) {
1070 fake = tegra_xusb_find_unused_usb3_port(usb2->base.padctl);
1071 if (fake < 0) {
1072 dev_err(&usb2->base.dev, "no unused USB3 ports available\n");
1073 return -ENODEV;
1074 }
1075
1076 dev_dbg(&usb2->base.dev, "Found unused usb3 port: %d\n", fake);
1077 usb2->usb3_port_fake = fake;
1078 }
1079
1080 return 0;
1081 }
1082
1083 static int tegra_xusb_setup_ports(struct tegra_xusb_padctl *padctl)
1084 {
1085 struct tegra_xusb_port *port;
1086 struct tegra_xusb_usb2_port *usb2;
1087 unsigned int i;
1088 int err = 0;
1089
1090 mutex_lock(&padctl->lock);
1091
1092 for (i = 0; i < padctl->soc->ports.usb2.count; i++) {
1093 err = tegra_xusb_add_usb2_port(padctl, i);
1094 if (err < 0)
1095 goto remove_ports;
1096 }
1097
1098 for (i = 0; i < padctl->soc->ports.ulpi.count; i++) {
1099 err = tegra_xusb_add_ulpi_port(padctl, i);
1100 if (err < 0)
1101 goto remove_ports;
1102 }
1103
1104 for (i = 0; i < padctl->soc->ports.hsic.count; i++) {
1105 err = tegra_xusb_add_hsic_port(padctl, i);
1106 if (err < 0)
1107 goto remove_ports;
1108 }
1109
1110 for (i = 0; i < padctl->soc->ports.usb3.count; i++) {
1111 err = tegra_xusb_add_usb3_port(padctl, i);
1112 if (err < 0)
1113 goto remove_ports;
1114 }
1115
1116 if (padctl->soc->need_fake_usb3_port) {
1117 for (i = 0; i < padctl->soc->ports.usb2.count; i++) {
1118 usb2 = tegra_xusb_find_usb2_port(padctl, i);
1119 if (!usb2)
1120 continue;
1121
1122 err = tegra_xusb_update_usb3_fake_port(usb2);
1123 if (err < 0)
1124 goto remove_ports;
1125 }
1126 }
1127
1128 list_for_each_entry(port, &padctl->ports, list) {
1129 err = port->ops->enable(port);
1130 if (err < 0)
1131 dev_err(padctl->dev, "failed to enable port %s: %d\n",
1132 dev_name(&port->dev), err);
1133 }
1134
1135 goto unlock;
1136
1137 remove_ports:
1138 __tegra_xusb_remove_ports(padctl);
1139 unlock:
1140 mutex_unlock(&padctl->lock);
1141 return err;
1142 }
1143
1144 static void tegra_xusb_remove_ports(struct tegra_xusb_padctl *padctl)
1145 {
1146 mutex_lock(&padctl->lock);
1147 __tegra_xusb_remove_ports(padctl);
1148 mutex_unlock(&padctl->lock);
1149 }
1150
1151 static int tegra_xusb_padctl_probe(struct platform_device *pdev)
1152 {
1153 struct device_node *np = pdev->dev.of_node;
1154 const struct tegra_xusb_padctl_soc *soc;
1155 struct tegra_xusb_padctl *padctl;
1156 const struct of_device_id *match;
1157 int err;
1158
1159
1160 np = of_get_child_by_name(np, "pads");
1161 if (!np) {
1162 dev_warn(&pdev->dev, "deprecated DT, using legacy driver\n");
1163 return tegra_xusb_padctl_legacy_probe(pdev);
1164 }
1165
1166 of_node_put(np);
1167
1168 match = of_match_node(tegra_xusb_padctl_of_match, pdev->dev.of_node);
1169 soc = match->data;
1170
1171 padctl = soc->ops->probe(&pdev->dev, soc);
1172 if (IS_ERR(padctl))
1173 return PTR_ERR(padctl);
1174
1175 platform_set_drvdata(pdev, padctl);
1176 INIT_LIST_HEAD(&padctl->ports);
1177 INIT_LIST_HEAD(&padctl->lanes);
1178 INIT_LIST_HEAD(&padctl->pads);
1179 mutex_init(&padctl->lock);
1180
1181 padctl->regs = devm_platform_ioremap_resource(pdev, 0);
1182 if (IS_ERR(padctl->regs)) {
1183 err = PTR_ERR(padctl->regs);
1184 goto remove;
1185 }
1186
1187 padctl->rst = devm_reset_control_get(&pdev->dev, NULL);
1188 if (IS_ERR(padctl->rst)) {
1189 err = PTR_ERR(padctl->rst);
1190 goto remove;
1191 }
1192
1193 padctl->supplies = devm_kcalloc(&pdev->dev, padctl->soc->num_supplies,
1194 sizeof(*padctl->supplies), GFP_KERNEL);
1195 if (!padctl->supplies) {
1196 err = -ENOMEM;
1197 goto remove;
1198 }
1199
1200 regulator_bulk_set_supply_names(padctl->supplies,
1201 padctl->soc->supply_names,
1202 padctl->soc->num_supplies);
1203
1204 err = devm_regulator_bulk_get(&pdev->dev, padctl->soc->num_supplies,
1205 padctl->supplies);
1206 if (err < 0) {
1207 dev_err_probe(&pdev->dev, err, "failed to get regulators\n");
1208 goto remove;
1209 }
1210
1211 err = reset_control_deassert(padctl->rst);
1212 if (err < 0)
1213 goto remove;
1214
1215 err = regulator_bulk_enable(padctl->soc->num_supplies,
1216 padctl->supplies);
1217 if (err < 0) {
1218 dev_err(&pdev->dev, "failed to enable supplies: %d\n", err);
1219 goto reset;
1220 }
1221
1222 err = tegra_xusb_setup_pads(padctl);
1223 if (err < 0) {
1224 dev_err(&pdev->dev, "failed to setup pads: %d\n", err);
1225 goto power_down;
1226 }
1227
1228 err = tegra_xusb_setup_ports(padctl);
1229 if (err) {
1230 const char *level = KERN_ERR;
1231
1232 if (err == -EPROBE_DEFER)
1233 level = KERN_DEBUG;
1234
1235 dev_printk(level, &pdev->dev,
1236 dev_fmt("failed to setup XUSB ports: %d\n"), err);
1237 goto remove_pads;
1238 }
1239
1240 return 0;
1241
1242 remove_pads:
1243 tegra_xusb_remove_pads(padctl);
1244 power_down:
1245 regulator_bulk_disable(padctl->soc->num_supplies, padctl->supplies);
1246 reset:
1247 reset_control_assert(padctl->rst);
1248 remove:
1249 platform_set_drvdata(pdev, NULL);
1250 soc->ops->remove(padctl);
1251 return err;
1252 }
1253
1254 static int tegra_xusb_padctl_remove(struct platform_device *pdev)
1255 {
1256 struct tegra_xusb_padctl *padctl = platform_get_drvdata(pdev);
1257 int err;
1258
1259 tegra_xusb_remove_ports(padctl);
1260 tegra_xusb_remove_pads(padctl);
1261
1262 err = regulator_bulk_disable(padctl->soc->num_supplies,
1263 padctl->supplies);
1264 if (err < 0)
1265 dev_err(&pdev->dev, "failed to disable supplies: %d\n", err);
1266
1267 err = reset_control_assert(padctl->rst);
1268 if (err < 0)
1269 dev_err(&pdev->dev, "failed to assert reset: %d\n", err);
1270
1271 padctl->soc->ops->remove(padctl);
1272
1273 return err;
1274 }
1275
1276 static __maybe_unused int tegra_xusb_padctl_suspend_noirq(struct device *dev)
1277 {
1278 struct tegra_xusb_padctl *padctl = dev_get_drvdata(dev);
1279
1280 if (padctl->soc && padctl->soc->ops && padctl->soc->ops->suspend_noirq)
1281 return padctl->soc->ops->suspend_noirq(padctl);
1282
1283 return 0;
1284 }
1285
1286 static __maybe_unused int tegra_xusb_padctl_resume_noirq(struct device *dev)
1287 {
1288 struct tegra_xusb_padctl *padctl = dev_get_drvdata(dev);
1289
1290 if (padctl->soc && padctl->soc->ops && padctl->soc->ops->resume_noirq)
1291 return padctl->soc->ops->resume_noirq(padctl);
1292
1293 return 0;
1294 }
1295
1296 static const struct dev_pm_ops tegra_xusb_padctl_pm_ops = {
1297 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(tegra_xusb_padctl_suspend_noirq,
1298 tegra_xusb_padctl_resume_noirq)
1299 };
1300
1301 static struct platform_driver tegra_xusb_padctl_driver = {
1302 .driver = {
1303 .name = "tegra-xusb-padctl",
1304 .of_match_table = tegra_xusb_padctl_of_match,
1305 .pm = &tegra_xusb_padctl_pm_ops,
1306 },
1307 .probe = tegra_xusb_padctl_probe,
1308 .remove = tegra_xusb_padctl_remove,
1309 };
1310 module_platform_driver(tegra_xusb_padctl_driver);
1311
1312 struct tegra_xusb_padctl *tegra_xusb_padctl_get(struct device *dev)
1313 {
1314 struct tegra_xusb_padctl *padctl;
1315 struct platform_device *pdev;
1316 struct device_node *np;
1317
1318 np = of_parse_phandle(dev->of_node, "nvidia,xusb-padctl", 0);
1319 if (!np)
1320 return ERR_PTR(-EINVAL);
1321
1322
1323
1324
1325
1326
1327 pdev = of_find_device_by_node(np);
1328 if (!pdev) {
1329 of_node_put(np);
1330 return ERR_PTR(-ENODEV);
1331 }
1332
1333 of_node_put(np);
1334
1335 padctl = platform_get_drvdata(pdev);
1336 if (!padctl) {
1337 put_device(&pdev->dev);
1338 return ERR_PTR(-EPROBE_DEFER);
1339 }
1340
1341 return padctl;
1342 }
1343 EXPORT_SYMBOL_GPL(tegra_xusb_padctl_get);
1344
1345 void tegra_xusb_padctl_put(struct tegra_xusb_padctl *padctl)
1346 {
1347 if (padctl)
1348 put_device(padctl->dev);
1349 }
1350 EXPORT_SYMBOL_GPL(tegra_xusb_padctl_put);
1351
1352 int tegra_xusb_padctl_usb3_save_context(struct tegra_xusb_padctl *padctl,
1353 unsigned int port)
1354 {
1355 if (padctl->soc->ops->usb3_save_context)
1356 return padctl->soc->ops->usb3_save_context(padctl, port);
1357
1358 return -ENOSYS;
1359 }
1360 EXPORT_SYMBOL_GPL(tegra_xusb_padctl_usb3_save_context);
1361
1362 int tegra_xusb_padctl_hsic_set_idle(struct tegra_xusb_padctl *padctl,
1363 unsigned int port, bool idle)
1364 {
1365 if (padctl->soc->ops->hsic_set_idle)
1366 return padctl->soc->ops->hsic_set_idle(padctl, port, idle);
1367
1368 return -ENOSYS;
1369 }
1370 EXPORT_SYMBOL_GPL(tegra_xusb_padctl_hsic_set_idle);
1371
1372 int tegra_xusb_padctl_enable_phy_sleepwalk(struct tegra_xusb_padctl *padctl, struct phy *phy,
1373 enum usb_device_speed speed)
1374 {
1375 struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
1376
1377 if (lane->pad->ops->enable_phy_sleepwalk)
1378 return lane->pad->ops->enable_phy_sleepwalk(lane, speed);
1379
1380 return -EOPNOTSUPP;
1381 }
1382 EXPORT_SYMBOL_GPL(tegra_xusb_padctl_enable_phy_sleepwalk);
1383
1384 int tegra_xusb_padctl_disable_phy_sleepwalk(struct tegra_xusb_padctl *padctl, struct phy *phy)
1385 {
1386 struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
1387
1388 if (lane->pad->ops->disable_phy_sleepwalk)
1389 return lane->pad->ops->disable_phy_sleepwalk(lane);
1390
1391 return -EOPNOTSUPP;
1392 }
1393 EXPORT_SYMBOL_GPL(tegra_xusb_padctl_disable_phy_sleepwalk);
1394
1395 int tegra_xusb_padctl_enable_phy_wake(struct tegra_xusb_padctl *padctl, struct phy *phy)
1396 {
1397 struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
1398
1399 if (lane->pad->ops->enable_phy_wake)
1400 return lane->pad->ops->enable_phy_wake(lane);
1401
1402 return -EOPNOTSUPP;
1403 }
1404 EXPORT_SYMBOL_GPL(tegra_xusb_padctl_enable_phy_wake);
1405
1406 int tegra_xusb_padctl_disable_phy_wake(struct tegra_xusb_padctl *padctl, struct phy *phy)
1407 {
1408 struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
1409
1410 if (lane->pad->ops->disable_phy_wake)
1411 return lane->pad->ops->disable_phy_wake(lane);
1412
1413 return -EOPNOTSUPP;
1414 }
1415 EXPORT_SYMBOL_GPL(tegra_xusb_padctl_disable_phy_wake);
1416
1417 bool tegra_xusb_padctl_remote_wake_detected(struct tegra_xusb_padctl *padctl, struct phy *phy)
1418 {
1419 struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
1420
1421 if (lane->pad->ops->remote_wake_detected)
1422 return lane->pad->ops->remote_wake_detected(lane);
1423
1424 return false;
1425 }
1426 EXPORT_SYMBOL_GPL(tegra_xusb_padctl_remote_wake_detected);
1427
1428 int tegra_xusb_padctl_usb3_set_lfps_detect(struct tegra_xusb_padctl *padctl,
1429 unsigned int port, bool enable)
1430 {
1431 if (padctl->soc->ops->usb3_set_lfps_detect)
1432 return padctl->soc->ops->usb3_set_lfps_detect(padctl, port,
1433 enable);
1434
1435 return -ENOSYS;
1436 }
1437 EXPORT_SYMBOL_GPL(tegra_xusb_padctl_usb3_set_lfps_detect);
1438
1439 int tegra_xusb_padctl_set_vbus_override(struct tegra_xusb_padctl *padctl,
1440 bool val)
1441 {
1442 if (padctl->soc->ops->vbus_override)
1443 return padctl->soc->ops->vbus_override(padctl, val);
1444
1445 return -ENOTSUPP;
1446 }
1447 EXPORT_SYMBOL_GPL(tegra_xusb_padctl_set_vbus_override);
1448
1449 int tegra_phy_xusb_utmi_port_reset(struct phy *phy)
1450 {
1451 struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
1452 struct tegra_xusb_padctl *padctl = lane->pad->padctl;
1453
1454 if (padctl->soc->ops->utmi_port_reset)
1455 return padctl->soc->ops->utmi_port_reset(phy);
1456
1457 return -ENOTSUPP;
1458 }
1459 EXPORT_SYMBOL_GPL(tegra_phy_xusb_utmi_port_reset);
1460
1461 int tegra_xusb_padctl_get_usb3_companion(struct tegra_xusb_padctl *padctl,
1462 unsigned int port)
1463 {
1464 struct tegra_xusb_usb2_port *usb2;
1465 struct tegra_xusb_usb3_port *usb3;
1466 int i;
1467
1468 usb2 = tegra_xusb_find_usb2_port(padctl, port);
1469 if (!usb2)
1470 return -EINVAL;
1471
1472 for (i = 0; i < padctl->soc->ports.usb3.count; i++) {
1473 usb3 = tegra_xusb_find_usb3_port(padctl, i);
1474 if (usb3 && usb3->port == usb2->base.index)
1475 return usb3->base.index;
1476 }
1477
1478 return -ENODEV;
1479 }
1480 EXPORT_SYMBOL_GPL(tegra_xusb_padctl_get_usb3_companion);
1481
1482 MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>");
1483 MODULE_DESCRIPTION("Tegra XUSB Pad Controller driver");
1484 MODULE_LICENSE("GPL v2");