2 * Copyright (c) 2014-2015, NVIDIA CORPORATION. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 #include <linux/delay.h>
16 #include <linux/mailbox_client.h>
17 #include <linux/module.h>
19 #include <linux/of_device.h>
20 #include <linux/phy/phy.h>
21 #include <linux/phy/tegra/xusb.h>
22 #include <linux/platform_device.h>
23 #include <linux/regulator/consumer.h>
24 #include <linux/reset.h>
25 #include <linux/slab.h>
26 #include <linux/workqueue.h>
28 #include <soc/tegra/fuse.h>
32 static struct phy
*tegra_xusb_pad_of_xlate(struct device
*dev
,
33 struct of_phandle_args
*args
)
35 struct tegra_xusb_pad
*pad
= dev_get_drvdata(dev
);
36 struct phy
*phy
= NULL
;
39 if (args
->args_count
!= 0)
40 return ERR_PTR(-EINVAL
);
42 for (i
= 0; i
< pad
->soc
->num_lanes
; i
++) {
46 if (pad
->lanes
[i
]->dev
.of_node
== args
->np
) {
53 phy
= ERR_PTR(-ENODEV
);
58 static const struct of_device_id tegra_xusb_padctl_of_match
[] = {
59 #if defined(CONFIG_ARCH_TEGRA_124_SOC) || defined(CONFIG_ARCH_TEGRA_132_SOC)
61 .compatible
= "nvidia,tegra124-xusb-padctl",
62 .data
= &tegra124_xusb_padctl_soc
,
65 #if defined(CONFIG_ARCH_TEGRA_210_SOC)
67 .compatible
= "nvidia,tegra210-xusb-padctl",
68 .data
= &tegra210_xusb_padctl_soc
,
73 MODULE_DEVICE_TABLE(of
, tegra_xusb_padctl_of_match
);
75 static struct device_node
*
76 tegra_xusb_find_pad_node(struct tegra_xusb_padctl
*padctl
, const char *name
)
78 struct device_node
*pads
, *np
;
80 pads
= of_get_child_by_name(padctl
->dev
->of_node
, "pads");
84 np
= of_get_child_by_name(pads
, name
);
90 static struct device_node
*
91 tegra_xusb_pad_find_phy_node(struct tegra_xusb_pad
*pad
, unsigned int index
)
93 struct device_node
*np
, *lanes
;
95 lanes
= of_get_child_by_name(pad
->dev
.of_node
, "lanes");
99 np
= of_get_child_by_name(lanes
, pad
->soc
->lanes
[index
].name
);
105 int tegra_xusb_lane_parse_dt(struct tegra_xusb_lane
*lane
,
106 struct device_node
*np
)
108 struct device
*dev
= &lane
->pad
->dev
;
109 const char *function
;
112 err
= of_property_read_string(np
, "nvidia,function", &function
);
116 err
= match_string(lane
->soc
->funcs
, lane
->soc
->num_funcs
, function
);
118 dev_err(dev
, "invalid function \"%s\" for lane \"%pOFn\"\n",
123 lane
->function
= err
;
128 static void tegra_xusb_lane_destroy(struct phy
*phy
)
131 struct tegra_xusb_lane
*lane
= phy_get_drvdata(phy
);
133 lane
->pad
->ops
->remove(lane
);
138 static void tegra_xusb_pad_release(struct device
*dev
)
140 struct tegra_xusb_pad
*pad
= to_tegra_xusb_pad(dev
);
142 pad
->soc
->ops
->remove(pad
);
145 static struct device_type tegra_xusb_pad_type
= {
146 .release
= tegra_xusb_pad_release
,
149 int tegra_xusb_pad_init(struct tegra_xusb_pad
*pad
,
150 struct tegra_xusb_padctl
*padctl
,
151 struct device_node
*np
)
155 device_initialize(&pad
->dev
);
156 INIT_LIST_HEAD(&pad
->list
);
157 pad
->dev
.parent
= padctl
->dev
;
158 pad
->dev
.type
= &tegra_xusb_pad_type
;
159 pad
->dev
.of_node
= np
;
160 pad
->padctl
= padctl
;
162 err
= dev_set_name(&pad
->dev
, "%s", pad
->soc
->name
);
166 err
= device_add(&pad
->dev
);
173 device_unregister(&pad
->dev
);
177 int tegra_xusb_pad_register(struct tegra_xusb_pad
*pad
,
178 const struct phy_ops
*ops
)
180 struct device_node
*children
;
185 children
= of_get_child_by_name(pad
->dev
.of_node
, "lanes");
189 pad
->lanes
= devm_kcalloc(&pad
->dev
, pad
->soc
->num_lanes
, sizeof(lane
),
192 of_node_put(children
);
196 for (i
= 0; i
< pad
->soc
->num_lanes
; i
++) {
197 struct device_node
*np
= tegra_xusb_pad_find_phy_node(pad
, i
);
198 struct tegra_xusb_lane
*lane
;
200 /* skip disabled lanes */
201 if (!np
|| !of_device_is_available(np
)) {
206 pad
->lanes
[i
] = phy_create(&pad
->dev
, np
, ops
);
207 if (IS_ERR(pad
->lanes
[i
])) {
208 err
= PTR_ERR(pad
->lanes
[i
]);
213 lane
= pad
->ops
->probe(pad
, np
, i
);
215 phy_destroy(pad
->lanes
[i
]);
220 list_add_tail(&lane
->list
, &pad
->padctl
->lanes
);
221 phy_set_drvdata(pad
->lanes
[i
], lane
);
224 pad
->provider
= of_phy_provider_register_full(&pad
->dev
, children
,
225 tegra_xusb_pad_of_xlate
);
226 if (IS_ERR(pad
->provider
)) {
227 err
= PTR_ERR(pad
->provider
);
235 tegra_xusb_lane_destroy(pad
->lanes
[i
]);
237 of_node_put(children
);
242 void tegra_xusb_pad_unregister(struct tegra_xusb_pad
*pad
)
244 unsigned int i
= pad
->soc
->num_lanes
;
246 of_phy_provider_unregister(pad
->provider
);
249 tegra_xusb_lane_destroy(pad
->lanes
[i
]);
251 device_unregister(&pad
->dev
);
254 static struct tegra_xusb_pad
*
255 tegra_xusb_pad_create(struct tegra_xusb_padctl
*padctl
,
256 const struct tegra_xusb_pad_soc
*soc
)
258 struct tegra_xusb_pad
*pad
;
259 struct device_node
*np
;
262 np
= tegra_xusb_find_pad_node(padctl
, soc
->name
);
263 if (!np
|| !of_device_is_available(np
))
266 pad
= soc
->ops
->probe(padctl
, soc
, np
);
269 dev_err(padctl
->dev
, "failed to create pad %s: %d\n",
274 /* XXX move this into ->probe() to avoid string comparison */
275 if (strcmp(soc
->name
, "pcie") == 0)
278 if (strcmp(soc
->name
, "sata") == 0)
281 if (strcmp(soc
->name
, "usb2") == 0)
284 if (strcmp(soc
->name
, "ulpi") == 0)
287 if (strcmp(soc
->name
, "hsic") == 0)
293 static void __tegra_xusb_remove_pads(struct tegra_xusb_padctl
*padctl
)
295 struct tegra_xusb_pad
*pad
, *tmp
;
297 list_for_each_entry_safe_reverse(pad
, tmp
, &padctl
->pads
, list
) {
298 list_del(&pad
->list
);
299 tegra_xusb_pad_unregister(pad
);
303 static void tegra_xusb_remove_pads(struct tegra_xusb_padctl
*padctl
)
305 mutex_lock(&padctl
->lock
);
306 __tegra_xusb_remove_pads(padctl
);
307 mutex_unlock(&padctl
->lock
);
310 static void tegra_xusb_lane_program(struct tegra_xusb_lane
*lane
)
312 struct tegra_xusb_padctl
*padctl
= lane
->pad
->padctl
;
313 const struct tegra_xusb_lane_soc
*soc
= lane
->soc
;
316 /* choose function */
317 value
= padctl_readl(padctl
, soc
->offset
);
318 value
&= ~(soc
->mask
<< soc
->shift
);
319 value
|= lane
->function
<< soc
->shift
;
320 padctl_writel(padctl
, value
, soc
->offset
);
323 static void tegra_xusb_pad_program(struct tegra_xusb_pad
*pad
)
327 for (i
= 0; i
< pad
->soc
->num_lanes
; i
++) {
328 struct tegra_xusb_lane
*lane
;
331 lane
= phy_get_drvdata(pad
->lanes
[i
]);
332 tegra_xusb_lane_program(lane
);
337 static int tegra_xusb_setup_pads(struct tegra_xusb_padctl
*padctl
)
339 struct tegra_xusb_pad
*pad
;
342 mutex_lock(&padctl
->lock
);
344 for (i
= 0; i
< padctl
->soc
->num_pads
; i
++) {
345 const struct tegra_xusb_pad_soc
*soc
= padctl
->soc
->pads
[i
];
348 pad
= tegra_xusb_pad_create(padctl
, soc
);
351 dev_err(padctl
->dev
, "failed to create pad %s: %d\n",
353 __tegra_xusb_remove_pads(padctl
);
354 mutex_unlock(&padctl
->lock
);
361 list_add_tail(&pad
->list
, &padctl
->pads
);
364 list_for_each_entry(pad
, &padctl
->pads
, list
)
365 tegra_xusb_pad_program(pad
);
367 mutex_unlock(&padctl
->lock
);
371 static bool tegra_xusb_lane_check(struct tegra_xusb_lane
*lane
,
372 const char *function
)
374 const char *func
= lane
->soc
->funcs
[lane
->function
];
376 return strcmp(function
, func
) == 0;
379 struct tegra_xusb_lane
*tegra_xusb_find_lane(struct tegra_xusb_padctl
*padctl
,
383 struct tegra_xusb_lane
*lane
, *hit
= ERR_PTR(-ENODEV
);
386 name
= kasprintf(GFP_KERNEL
, "%s-%u", type
, index
);
388 return ERR_PTR(-ENOMEM
);
390 list_for_each_entry(lane
, &padctl
->lanes
, list
) {
391 if (strcmp(lane
->soc
->name
, name
) == 0) {
401 struct tegra_xusb_lane
*
402 tegra_xusb_port_find_lane(struct tegra_xusb_port
*port
,
403 const struct tegra_xusb_lane_map
*map
,
404 const char *function
)
406 struct tegra_xusb_lane
*lane
, *match
= ERR_PTR(-ENODEV
);
408 for (; map
->type
; map
++) {
409 if (port
->index
!= map
->port
)
412 lane
= tegra_xusb_find_lane(port
->padctl
, map
->type
,
417 if (!tegra_xusb_lane_check(lane
, function
))
421 dev_err(&port
->dev
, "conflicting match: %s-%u / %s\n",
422 map
->type
, map
->index
, match
->soc
->name
);
430 static struct device_node
*
431 tegra_xusb_find_port_node(struct tegra_xusb_padctl
*padctl
, const char *type
,
434 struct device_node
*ports
, *np
;
437 ports
= of_get_child_by_name(padctl
->dev
->of_node
, "ports");
441 name
= kasprintf(GFP_KERNEL
, "%s-%u", type
, index
);
444 return ERR_PTR(-ENOMEM
);
446 np
= of_get_child_by_name(ports
, name
);
453 struct tegra_xusb_port
*
454 tegra_xusb_find_port(struct tegra_xusb_padctl
*padctl
, const char *type
,
457 struct tegra_xusb_port
*port
;
458 struct device_node
*np
;
460 np
= tegra_xusb_find_port_node(padctl
, type
, index
);
464 list_for_each_entry(port
, &padctl
->ports
, list
) {
465 if (np
== port
->dev
.of_node
) {
476 struct tegra_xusb_usb2_port
*
477 tegra_xusb_find_usb2_port(struct tegra_xusb_padctl
*padctl
, unsigned int index
)
479 struct tegra_xusb_port
*port
;
481 port
= tegra_xusb_find_port(padctl
, "usb2", index
);
483 return to_usb2_port(port
);
488 struct tegra_xusb_usb3_port
*
489 tegra_xusb_find_usb3_port(struct tegra_xusb_padctl
*padctl
, unsigned int index
)
491 struct tegra_xusb_port
*port
;
493 port
= tegra_xusb_find_port(padctl
, "usb3", index
);
495 return to_usb3_port(port
);
500 static void tegra_xusb_port_release(struct device
*dev
)
504 static struct device_type tegra_xusb_port_type
= {
505 .release
= tegra_xusb_port_release
,
508 static int tegra_xusb_port_init(struct tegra_xusb_port
*port
,
509 struct tegra_xusb_padctl
*padctl
,
510 struct device_node
*np
,
516 INIT_LIST_HEAD(&port
->list
);
517 port
->padctl
= padctl
;
520 device_initialize(&port
->dev
);
521 port
->dev
.type
= &tegra_xusb_port_type
;
522 port
->dev
.of_node
= of_node_get(np
);
523 port
->dev
.parent
= padctl
->dev
;
525 err
= dev_set_name(&port
->dev
, "%s-%u", name
, index
);
529 err
= device_add(&port
->dev
);
536 device_unregister(&port
->dev
);
540 static void tegra_xusb_port_unregister(struct tegra_xusb_port
*port
)
542 device_unregister(&port
->dev
);
545 static int tegra_xusb_usb2_port_parse_dt(struct tegra_xusb_usb2_port
*usb2
)
547 struct tegra_xusb_port
*port
= &usb2
->base
;
548 struct device_node
*np
= port
->dev
.of_node
;
550 usb2
->internal
= of_property_read_bool(np
, "nvidia,internal");
552 usb2
->supply
= devm_regulator_get(&port
->dev
, "vbus");
553 return PTR_ERR_OR_ZERO(usb2
->supply
);
556 static int tegra_xusb_add_usb2_port(struct tegra_xusb_padctl
*padctl
,
559 struct tegra_xusb_usb2_port
*usb2
;
560 struct device_node
*np
;
564 * USB2 ports don't require additional properties, but if the port is
565 * marked as disabled there is no reason to register it.
567 np
= tegra_xusb_find_port_node(padctl
, "usb2", index
);
568 if (!np
|| !of_device_is_available(np
))
571 usb2
= devm_kzalloc(padctl
->dev
, sizeof(*usb2
), GFP_KERNEL
);
577 err
= tegra_xusb_port_init(&usb2
->base
, padctl
, np
, "usb2", index
);
581 usb2
->base
.ops
= padctl
->soc
->ports
.usb2
.ops
;
583 usb2
->base
.lane
= usb2
->base
.ops
->map(&usb2
->base
);
584 if (IS_ERR(usb2
->base
.lane
)) {
585 err
= PTR_ERR(usb2
->base
.lane
);
589 err
= tegra_xusb_usb2_port_parse_dt(usb2
);
591 tegra_xusb_port_unregister(&usb2
->base
);
595 list_add_tail(&usb2
->base
.list
, &padctl
->ports
);
602 static int tegra_xusb_ulpi_port_parse_dt(struct tegra_xusb_ulpi_port
*ulpi
)
604 struct tegra_xusb_port
*port
= &ulpi
->base
;
605 struct device_node
*np
= port
->dev
.of_node
;
607 ulpi
->internal
= of_property_read_bool(np
, "nvidia,internal");
612 static int tegra_xusb_add_ulpi_port(struct tegra_xusb_padctl
*padctl
,
615 struct tegra_xusb_ulpi_port
*ulpi
;
616 struct device_node
*np
;
619 np
= tegra_xusb_find_port_node(padctl
, "ulpi", index
);
620 if (!np
|| !of_device_is_available(np
))
623 ulpi
= devm_kzalloc(padctl
->dev
, sizeof(*ulpi
), GFP_KERNEL
);
629 err
= tegra_xusb_port_init(&ulpi
->base
, padctl
, np
, "ulpi", index
);
633 ulpi
->base
.ops
= padctl
->soc
->ports
.ulpi
.ops
;
635 ulpi
->base
.lane
= ulpi
->base
.ops
->map(&ulpi
->base
);
636 if (IS_ERR(ulpi
->base
.lane
)) {
637 err
= PTR_ERR(ulpi
->base
.lane
);
641 err
= tegra_xusb_ulpi_port_parse_dt(ulpi
);
643 tegra_xusb_port_unregister(&ulpi
->base
);
647 list_add_tail(&ulpi
->base
.list
, &padctl
->ports
);
654 static int tegra_xusb_hsic_port_parse_dt(struct tegra_xusb_hsic_port
*hsic
)
660 static int tegra_xusb_add_hsic_port(struct tegra_xusb_padctl
*padctl
,
663 struct tegra_xusb_hsic_port
*hsic
;
664 struct device_node
*np
;
667 np
= tegra_xusb_find_port_node(padctl
, "hsic", index
);
668 if (!np
|| !of_device_is_available(np
))
671 hsic
= devm_kzalloc(padctl
->dev
, sizeof(*hsic
), GFP_KERNEL
);
677 err
= tegra_xusb_port_init(&hsic
->base
, padctl
, np
, "hsic", index
);
681 hsic
->base
.ops
= padctl
->soc
->ports
.hsic
.ops
;
683 hsic
->base
.lane
= hsic
->base
.ops
->map(&hsic
->base
);
684 if (IS_ERR(hsic
->base
.lane
)) {
685 err
= PTR_ERR(hsic
->base
.lane
);
689 err
= tegra_xusb_hsic_port_parse_dt(hsic
);
691 tegra_xusb_port_unregister(&hsic
->base
);
695 list_add_tail(&hsic
->base
.list
, &padctl
->ports
);
702 static int tegra_xusb_usb3_port_parse_dt(struct tegra_xusb_usb3_port
*usb3
)
704 struct tegra_xusb_port
*port
= &usb3
->base
;
705 struct device_node
*np
= port
->dev
.of_node
;
709 err
= of_property_read_u32(np
, "nvidia,usb2-companion", &value
);
711 dev_err(&port
->dev
, "failed to read port: %d\n", err
);
717 usb3
->internal
= of_property_read_bool(np
, "nvidia,internal");
719 usb3
->supply
= devm_regulator_get(&port
->dev
, "vbus");
720 return PTR_ERR_OR_ZERO(usb3
->supply
);
723 static int tegra_xusb_add_usb3_port(struct tegra_xusb_padctl
*padctl
,
726 struct tegra_xusb_usb3_port
*usb3
;
727 struct device_node
*np
;
731 * If there is no supplemental configuration in the device tree the
732 * port is unusable. But it is valid to configure only a single port,
733 * hence return 0 instead of an error to allow ports to be optional.
735 np
= tegra_xusb_find_port_node(padctl
, "usb3", index
);
736 if (!np
|| !of_device_is_available(np
))
739 usb3
= devm_kzalloc(padctl
->dev
, sizeof(*usb3
), GFP_KERNEL
);
745 err
= tegra_xusb_port_init(&usb3
->base
, padctl
, np
, "usb3", index
);
749 usb3
->base
.ops
= padctl
->soc
->ports
.usb3
.ops
;
751 usb3
->base
.lane
= usb3
->base
.ops
->map(&usb3
->base
);
752 if (IS_ERR(usb3
->base
.lane
)) {
753 err
= PTR_ERR(usb3
->base
.lane
);
757 err
= tegra_xusb_usb3_port_parse_dt(usb3
);
759 tegra_xusb_port_unregister(&usb3
->base
);
763 list_add_tail(&usb3
->base
.list
, &padctl
->ports
);
770 static void __tegra_xusb_remove_ports(struct tegra_xusb_padctl
*padctl
)
772 struct tegra_xusb_port
*port
, *tmp
;
774 list_for_each_entry_safe_reverse(port
, tmp
, &padctl
->ports
, list
) {
775 list_del(&port
->list
);
776 tegra_xusb_port_unregister(port
);
780 static int tegra_xusb_setup_ports(struct tegra_xusb_padctl
*padctl
)
782 struct tegra_xusb_port
*port
;
786 mutex_lock(&padctl
->lock
);
788 for (i
= 0; i
< padctl
->soc
->ports
.usb2
.count
; i
++) {
789 err
= tegra_xusb_add_usb2_port(padctl
, i
);
794 for (i
= 0; i
< padctl
->soc
->ports
.ulpi
.count
; i
++) {
795 err
= tegra_xusb_add_ulpi_port(padctl
, i
);
800 for (i
= 0; i
< padctl
->soc
->ports
.hsic
.count
; i
++) {
801 err
= tegra_xusb_add_hsic_port(padctl
, i
);
806 for (i
= 0; i
< padctl
->soc
->ports
.usb3
.count
; i
++) {
807 err
= tegra_xusb_add_usb3_port(padctl
, i
);
812 list_for_each_entry(port
, &padctl
->ports
, list
) {
813 err
= port
->ops
->enable(port
);
815 dev_err(padctl
->dev
, "failed to enable port %s: %d\n",
816 dev_name(&port
->dev
), err
);
822 __tegra_xusb_remove_ports(padctl
);
824 mutex_unlock(&padctl
->lock
);
828 static void tegra_xusb_remove_ports(struct tegra_xusb_padctl
*padctl
)
830 mutex_lock(&padctl
->lock
);
831 __tegra_xusb_remove_ports(padctl
);
832 mutex_unlock(&padctl
->lock
);
835 static int tegra_xusb_padctl_probe(struct platform_device
*pdev
)
837 struct device_node
*np
= pdev
->dev
.of_node
;
838 const struct tegra_xusb_padctl_soc
*soc
;
839 struct tegra_xusb_padctl
*padctl
;
840 const struct of_device_id
*match
;
841 struct resource
*res
;
844 /* for backwards compatibility with old device trees */
845 np
= of_get_child_by_name(np
, "pads");
847 dev_warn(&pdev
->dev
, "deprecated DT, using legacy driver\n");
848 return tegra_xusb_padctl_legacy_probe(pdev
);
853 match
= of_match_node(tegra_xusb_padctl_of_match
, pdev
->dev
.of_node
);
856 padctl
= soc
->ops
->probe(&pdev
->dev
, soc
);
858 return PTR_ERR(padctl
);
860 platform_set_drvdata(pdev
, padctl
);
861 INIT_LIST_HEAD(&padctl
->ports
);
862 INIT_LIST_HEAD(&padctl
->lanes
);
863 INIT_LIST_HEAD(&padctl
->pads
);
864 mutex_init(&padctl
->lock
);
866 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
867 padctl
->regs
= devm_ioremap_resource(&pdev
->dev
, res
);
868 if (IS_ERR(padctl
->regs
)) {
869 err
= PTR_ERR(padctl
->regs
);
873 padctl
->rst
= devm_reset_control_get(&pdev
->dev
, NULL
);
874 if (IS_ERR(padctl
->rst
)) {
875 err
= PTR_ERR(padctl
->rst
);
879 err
= reset_control_deassert(padctl
->rst
);
883 err
= tegra_xusb_setup_pads(padctl
);
885 dev_err(&pdev
->dev
, "failed to setup pads: %d\n", err
);
889 err
= tegra_xusb_setup_ports(padctl
);
891 dev_err(&pdev
->dev
, "failed to setup XUSB ports: %d\n", err
);
898 tegra_xusb_remove_pads(padctl
);
900 reset_control_assert(padctl
->rst
);
902 soc
->ops
->remove(padctl
);
906 static int tegra_xusb_padctl_remove(struct platform_device
*pdev
)
908 struct tegra_xusb_padctl
*padctl
= platform_get_drvdata(pdev
);
911 tegra_xusb_remove_ports(padctl
);
912 tegra_xusb_remove_pads(padctl
);
914 err
= reset_control_assert(padctl
->rst
);
916 dev_err(&pdev
->dev
, "failed to assert reset: %d\n", err
);
918 padctl
->soc
->ops
->remove(padctl
);
923 static struct platform_driver tegra_xusb_padctl_driver
= {
925 .name
= "tegra-xusb-padctl",
926 .of_match_table
= tegra_xusb_padctl_of_match
,
928 .probe
= tegra_xusb_padctl_probe
,
929 .remove
= tegra_xusb_padctl_remove
,
931 module_platform_driver(tegra_xusb_padctl_driver
);
933 struct tegra_xusb_padctl
*tegra_xusb_padctl_get(struct device
*dev
)
935 struct tegra_xusb_padctl
*padctl
;
936 struct platform_device
*pdev
;
937 struct device_node
*np
;
939 np
= of_parse_phandle(dev
->of_node
, "nvidia,xusb-padctl", 0);
941 return ERR_PTR(-EINVAL
);
944 * This is slightly ugly. A better implementation would be to keep a
945 * registry of pad controllers, but since there will almost certainly
946 * only ever be one per SoC that would be a little overkill.
948 pdev
= of_find_device_by_node(np
);
951 return ERR_PTR(-ENODEV
);
956 padctl
= platform_get_drvdata(pdev
);
958 put_device(&pdev
->dev
);
959 return ERR_PTR(-EPROBE_DEFER
);
964 EXPORT_SYMBOL_GPL(tegra_xusb_padctl_get
);
966 void tegra_xusb_padctl_put(struct tegra_xusb_padctl
*padctl
)
969 put_device(padctl
->dev
);
971 EXPORT_SYMBOL_GPL(tegra_xusb_padctl_put
);
973 int tegra_xusb_padctl_usb3_save_context(struct tegra_xusb_padctl
*padctl
,
976 if (padctl
->soc
->ops
->usb3_save_context
)
977 return padctl
->soc
->ops
->usb3_save_context(padctl
, port
);
981 EXPORT_SYMBOL_GPL(tegra_xusb_padctl_usb3_save_context
);
983 int tegra_xusb_padctl_hsic_set_idle(struct tegra_xusb_padctl
*padctl
,
984 unsigned int port
, bool idle
)
986 if (padctl
->soc
->ops
->hsic_set_idle
)
987 return padctl
->soc
->ops
->hsic_set_idle(padctl
, port
, idle
);
991 EXPORT_SYMBOL_GPL(tegra_xusb_padctl_hsic_set_idle
);
993 int tegra_xusb_padctl_usb3_set_lfps_detect(struct tegra_xusb_padctl
*padctl
,
994 unsigned int port
, bool enable
)
996 if (padctl
->soc
->ops
->usb3_set_lfps_detect
)
997 return padctl
->soc
->ops
->usb3_set_lfps_detect(padctl
, port
,
1002 EXPORT_SYMBOL_GPL(tegra_xusb_padctl_usb3_set_lfps_detect
);
1004 MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>");
1005 MODULE_DESCRIPTION("Tegra XUSB Pad Controller driver");
1006 MODULE_LICENSE("GPL v2");