* [RFC 1/5] usb: chipidea: Add support for Tegra20/30/114/124
2016-05-26 15:40 [RFC 0/5] usb: chipidea: Add support for Tegra20 through Tegra124 Thierry Reding
@ 2016-05-26 15:40 ` Thierry Reding
2016-05-26 21:17 ` Stephen Warren
2016-05-26 15:40 ` [RFC 2/5] ARM: tegra: Enable UDC on TrimSlice Thierry Reding
` (4 subsequent siblings)
5 siblings, 1 reply; 10+ messages in thread
From: Thierry Reding @ 2016-05-26 15:40 UTC (permalink / raw)
To: Peter Chen, Greg Kroah-Hartman
Cc: Stephen Warren, Thierry Reding, Alexandre Courbot, Jon Hunter,
linux-usb, linux-tegra, linux-kernel
From: Thierry Reding <treding@nvidia.com>
All of these Tegra SoC generations have a ChipIdea UDC IP block that can
be used for device mode communication with a host. Implement rudimentary
support that doesn't allow switching between host and device modes.
Signed-off-by: Thierry Reding <treding@nvidia.com>
---
drivers/usb/chipidea/Makefile | 1 +
drivers/usb/chipidea/ci_hdrc_tegra.c | 109 +++++++++++++++++++++++++++++++++++
2 files changed, 110 insertions(+)
create mode 100644 drivers/usb/chipidea/ci_hdrc_tegra.c
diff --git a/drivers/usb/chipidea/Makefile b/drivers/usb/chipidea/Makefile
index 518e445476c3..3532df6561d9 100644
--- a/drivers/usb/chipidea/Makefile
+++ b/drivers/usb/chipidea/Makefile
@@ -10,6 +10,7 @@ ci_hdrc-$(CONFIG_USB_OTG_FSM) += otg_fsm.o
obj-$(CONFIG_USB_CHIPIDEA) += ci_hdrc_usb2.o
obj-$(CONFIG_USB_CHIPIDEA) += ci_hdrc_msm.o
obj-$(CONFIG_USB_CHIPIDEA) += ci_hdrc_zevio.o
+obj-$(CONFIG_USB_CHIPIDEA) += ci_hdrc_tegra.o
obj-$(CONFIG_USB_CHIPIDEA_PCI) += ci_hdrc_pci.o
diff --git a/drivers/usb/chipidea/ci_hdrc_tegra.c b/drivers/usb/chipidea/ci_hdrc_tegra.c
new file mode 100644
index 000000000000..d3cd68441856
--- /dev/null
+++ b/drivers/usb/chipidea/ci_hdrc_tegra.c
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 2016, NVIDIA Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ */
+
+#include <linux/clk.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/reset.h>
+
+#include <linux/usb/chipidea.h>
+
+#include "ci.h"
+
+struct tegra_udc {
+ struct ci_hdrc_platform_data data;
+ struct platform_device *dev;
+
+ struct usb_phy *phy;
+ struct clk *clk;
+};
+
+static const struct of_device_id tegra_udc_of_match[] = {
+ { .compatible = "nvidia,tegra20-udc" },
+ { .compatible = "nvidia,tegra30-udc" },
+ { .compatible = "nvidia,tegra114-udc" },
+ { .compatible = "nvidia,tegra124-udc" },
+ { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, tegra_udc_of_match);
+
+static int tegra_udc_probe(struct platform_device *pdev)
+{
+ struct tegra_udc *udc;
+ int err;
+
+ udc = devm_kzalloc(&pdev->dev, sizeof(*udc), GFP_KERNEL);
+ if (!udc)
+ return -ENOMEM;
+
+ udc->phy = devm_usb_get_phy_by_phandle(&pdev->dev, "nvidia,phy", 0);
+ if (IS_ERR(udc->phy)) {
+ err = PTR_ERR(udc->phy);
+ dev_err(&pdev->dev, "failed to get PHY: %d\n", err);
+ return err;
+ }
+
+ udc->clk = devm_clk_get(&pdev->dev, NULL);
+ if (IS_ERR(udc->clk)) {
+ err = PTR_ERR(udc->clk);
+ dev_err(&pdev->dev, "failed to get clock: %d\n", err);
+ return err;
+ }
+
+ err = clk_prepare_enable(udc->clk);
+ if (err < 0) {
+ dev_err(&pdev->dev, "failed to enable clock: %d\n", err);
+ return err;
+ }
+
+ /* setup and register ChipIdea HDRC device */
+ udc->data.name = "tegra-udc";
+ udc->data.capoffset = DEF_CAPOFFSET;
+ udc->data.flags = 0;
+ udc->data.usb_phy = udc->phy;
+
+ udc->dev = ci_hdrc_add_device(&pdev->dev, pdev->resource,
+ pdev->num_resources, &udc->data);
+ if (IS_ERR(udc->dev)) {
+ err = PTR_ERR(udc->dev);
+ dev_err(&pdev->dev, "failed to add HDRC device: %d\n", err);
+ goto disable_clock;
+ }
+
+ platform_set_drvdata(pdev, udc);
+
+ return 0;
+
+disable_clock:
+ clk_disable_unprepare(udc->clk);
+ return err;
+}
+
+static int tegra_udc_remove(struct platform_device *pdev)
+{
+ struct tegra_udc *udc = platform_get_drvdata(pdev);
+
+ clk_disable_unprepare(udc->clk);
+
+ return 0;
+}
+
+static struct platform_driver tegra_udc_driver = {
+ .driver = {
+ .name = "tegra-udc",
+ .of_match_table = tegra_udc_of_match,
+ },
+ .probe = tegra_udc_probe,
+ .remove = tegra_udc_remove,
+};
+module_platform_driver(tegra_udc_driver);
+
+MODULE_DESCRIPTION("NVIDIA Tegra USB device mode driver");
+MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>");
+MODULE_ALIAS("platform:tegra-udc");
+MODULE_LICENSE("GPL v2");
--
2.8.3
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [RFC 1/5] usb: chipidea: Add support for Tegra20/30/114/124
2016-05-26 15:40 ` [RFC 1/5] usb: chipidea: Add support for Tegra20/30/114/124 Thierry Reding
@ 2016-05-26 21:17 ` Stephen Warren
2016-05-26 21:22 ` Stephen Warren
0 siblings, 1 reply; 10+ messages in thread
From: Stephen Warren @ 2016-05-26 21:17 UTC (permalink / raw)
To: Thierry Reding
Cc: Peter Chen, Greg Kroah-Hartman, Alexandre Courbot, Jon Hunter,
linux-usb, linux-tegra, linux-kernel
On 05/26/2016 09:40 AM, Thierry Reding wrote:
> From: Thierry Reding <treding@nvidia.com>
>
> All of these Tegra SoC generations have a ChipIdea UDC IP block that can
> be used for device mode communication with a host. Implement rudimentary
> support that doesn't allow switching between host and device modes.
Are you sure this is correct for Tegra20? I ask because for the /host/
mode driver, there's a "has_hostpc" flag which is set to false for
Tegra20 and true for all other SoCs. In the U-Boot device mode driver
(if not in the kernel driver; I didn't check), there's a concept of "has
hostpc" too. I might expect that flag to be set the same way for both
drivers. That said, I /think/ the host and device HW are unrelated, so
it's possible has_hostpc might be set differently for them.
Unfortunately, we haven't enabled the device mode driver for any Tegra20
system in U-Boot so I can't tell whether we should enable has_hostpc for
Tegra20's device mode driver.
Still, if this code works then I guess it's likely correct...
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [RFC 1/5] usb: chipidea: Add support for Tegra20/30/114/124
2016-05-26 21:17 ` Stephen Warren
@ 2016-05-26 21:22 ` Stephen Warren
0 siblings, 0 replies; 10+ messages in thread
From: Stephen Warren @ 2016-05-26 21:22 UTC (permalink / raw)
To: Thierry Reding
Cc: Peter Chen, Greg Kroah-Hartman, Alexandre Courbot, Jon Hunter,
linux-usb, linux-tegra, linux-kernel
On 05/26/2016 03:17 PM, Stephen Warren wrote:
> On 05/26/2016 09:40 AM, Thierry Reding wrote:
>> From: Thierry Reding <treding@nvidia.com>
>>
>> All of these Tegra SoC generations have a ChipIdea UDC IP block that can
>> be used for device mode communication with a host. Implement rudimentary
>> support that doesn't allow switching between host and device modes.
>
> Are you sure this is correct for Tegra20? I ask because for the /host/
> mode driver, there's a "has_hostpc" flag which is set to false for
> Tegra20 and true for all other SoCs. In the U-Boot device mode driver
> (if not in the kernel driver; I didn't check), there's a concept of "has
> hostpc" too. I might expect that flag to be set the same way for both
> drivers. That said, I /think/ the host and device HW are unrelated, so
> it's possible has_hostpc might be set differently for them.
> Unfortunately, we haven't enabled the device mode driver for any Tegra20
> system in U-Boot so I can't tell whether we should enable has_hostpc for
> Tegra20's device mode driver.
>
> Still, if this code works then I guess it's likely correct...
On the other hand, it looks like the kernel device mode driver might
auto-detect this; in core.c:hw_device_init(), I see:
reg = hw_read(ci, CAP_HCCPARAMS, HCCPARAMS_LEN) >>
__ffs(HCCPARAMS_LEN);
ci->hw_bank.lpm = reg;
... and in host.c:host_start(), I see:
ehci->has_hostpc = ci->hw_bank.lpm;
^ permalink raw reply [flat|nested] 10+ messages in thread
* [RFC 2/5] ARM: tegra: Enable UDC on TrimSlice
2016-05-26 15:40 [RFC 0/5] usb: chipidea: Add support for Tegra20 through Tegra124 Thierry Reding
2016-05-26 15:40 ` [RFC 1/5] usb: chipidea: Add support for Tegra20/30/114/124 Thierry Reding
@ 2016-05-26 15:40 ` Thierry Reding
2016-05-26 15:40 ` [RFC 3/5] ARM: tegra: Enable UDC on Beaver Thierry Reding
` (3 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: Thierry Reding @ 2016-05-26 15:40 UTC (permalink / raw)
To: Peter Chen, Greg Kroah-Hartman
Cc: Stephen Warren, Thierry Reding, Alexandre Courbot, Jon Hunter,
linux-usb, linux-tegra, linux-kernel
From: Thierry Reding <treding@nvidia.com>
Override the compatible string of the first USB controller to enable
device mode.
Signed-off-by: Thierry Reding <treding@nvidia.com>
---
arch/arm/boot/dts/tegra20-trimslice.dts | 3 +++
1 file changed, 3 insertions(+)
diff --git a/arch/arm/boot/dts/tegra20-trimslice.dts b/arch/arm/boot/dts/tegra20-trimslice.dts
index 4a035f74043a..5496f3dc089c 100644
--- a/arch/arm/boot/dts/tegra20-trimslice.dts
+++ b/arch/arm/boot/dts/tegra20-trimslice.dts
@@ -336,11 +336,14 @@
};
usb@c5000000 {
+ compatible = "nvidia,tegra20-udc";
status = "okay";
+ dr_mode = "otg";
};
usb-phy@c5000000 {
status = "okay";
+ dr_mode = "otg";
vbus-supply = <&vbus_reg>;
};
--
2.8.3
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [RFC 3/5] ARM: tegra: Enable UDC on Beaver
2016-05-26 15:40 [RFC 0/5] usb: chipidea: Add support for Tegra20 through Tegra124 Thierry Reding
2016-05-26 15:40 ` [RFC 1/5] usb: chipidea: Add support for Tegra20/30/114/124 Thierry Reding
2016-05-26 15:40 ` [RFC 2/5] ARM: tegra: Enable UDC on TrimSlice Thierry Reding
@ 2016-05-26 15:40 ` Thierry Reding
2016-05-26 15:40 ` [RFC 4/5] ARM: tegra: Enable UDC on Dalmore Thierry Reding
` (2 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: Thierry Reding @ 2016-05-26 15:40 UTC (permalink / raw)
To: Peter Chen, Greg Kroah-Hartman
Cc: Stephen Warren, Thierry Reding, Alexandre Courbot, Jon Hunter,
linux-usb, linux-tegra, linux-kernel
From: Thierry Reding <treding@nvidia.com>
Override the compatible string of the first USB controller to enable
device mode.
Signed-off-by: Thierry Reding <treding@nvidia.com>
---
arch/arm/boot/dts/tegra30-beaver.dts | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/arch/arm/boot/dts/tegra30-beaver.dts b/arch/arm/boot/dts/tegra30-beaver.dts
index 4ea3ecc10934..5f32bcd96fbc 100644
--- a/arch/arm/boot/dts/tegra30-beaver.dts
+++ b/arch/arm/boot/dts/tegra30-beaver.dts
@@ -1935,6 +1935,17 @@
non-removable;
};
+ usb@7d000000 {
+ compatible = "nvidia,tegra30-udc";
+ status = "okay";
+ dr_mode = "otg";
+ };
+
+ usb-phy@7d000000 {
+ status = "okay";
+ dr_mode = "otg";
+ };
+
usb@7d004000 {
status = "okay";
};
--
2.8.3
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [RFC 4/5] ARM: tegra: Enable UDC on Dalmore
2016-05-26 15:40 [RFC 0/5] usb: chipidea: Add support for Tegra20 through Tegra124 Thierry Reding
` (2 preceding siblings ...)
2016-05-26 15:40 ` [RFC 3/5] ARM: tegra: Enable UDC on Beaver Thierry Reding
@ 2016-05-26 15:40 ` Thierry Reding
2016-05-27 3:18 ` Peter Chen
2016-05-26 15:40 ` [RFC 5/5] ARM: tegra: Enable UDC on Jetson TK1 Thierry Reding
2016-05-27 3:16 ` [RFC 0/5] usb: chipidea: Add support for Tegra20 through Tegra124 Peter Chen
5 siblings, 1 reply; 10+ messages in thread
From: Thierry Reding @ 2016-05-26 15:40 UTC (permalink / raw)
To: Peter Chen, Greg Kroah-Hartman
Cc: Stephen Warren, Thierry Reding, Alexandre Courbot, Jon Hunter,
linux-usb, linux-tegra, linux-kernel
From: Thierry Reding <treding@nvidia.com>
Override the compatible string of the first USB controller to enable
device mode.
Signed-off-by: Thierry Reding <treding@nvidia.com>
---
arch/arm/boot/dts/tegra114-dalmore.dts | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/arch/arm/boot/dts/tegra114-dalmore.dts b/arch/arm/boot/dts/tegra114-dalmore.dts
index c970bf65c74c..53d664f718ff 100644
--- a/arch/arm/boot/dts/tegra114-dalmore.dts
+++ b/arch/arm/boot/dts/tegra114-dalmore.dts
@@ -1122,6 +1122,17 @@
non-removable;
};
+ usb@7d000000 {
+ compatible = "nvidia,tegra114-udc";
+ status = "okay";
+ dr_mode = "otg";
+ };
+
+ usb-phy@7d000000 {
+ status = "okay";
+ dr_mode = "otg";
+ };
+
usb@7d008000 {
status = "okay";
};
--
2.8.3
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [RFC 4/5] ARM: tegra: Enable UDC on Dalmore
2016-05-26 15:40 ` [RFC 4/5] ARM: tegra: Enable UDC on Dalmore Thierry Reding
@ 2016-05-27 3:18 ` Peter Chen
0 siblings, 0 replies; 10+ messages in thread
From: Peter Chen @ 2016-05-27 3:18 UTC (permalink / raw)
To: Thierry Reding
Cc: Peter Chen, Greg Kroah-Hartman, Stephen Warren,
Alexandre Courbot, Jon Hunter, linux-usb, linux-tegra,
linux-kernel
On Thu, May 26, 2016 at 05:40:04PM +0200, Thierry Reding wrote:
> From: Thierry Reding <treding@nvidia.com>
>
> Override the compatible string of the first USB controller to enable
> device mode.
>
> Signed-off-by: Thierry Reding <treding@nvidia.com>
> ---
> arch/arm/boot/dts/tegra114-dalmore.dts | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/arch/arm/boot/dts/tegra114-dalmore.dts b/arch/arm/boot/dts/tegra114-dalmore.dts
> index c970bf65c74c..53d664f718ff 100644
> --- a/arch/arm/boot/dts/tegra114-dalmore.dts
> +++ b/arch/arm/boot/dts/tegra114-dalmore.dts
> @@ -1122,6 +1122,17 @@
> non-removable;
> };
>
> + usb@7d000000 {
> + compatible = "nvidia,tegra114-udc";
> + status = "okay";
> + dr_mode = "otg";
> + };
> +
> + usb-phy@7d000000 {
> + status = "okay";
> + dr_mode = "otg";
> + };
> +
It is a USB PHY node, you don't need to set dr_mode for it.
--
Best Regards,
Peter Chen
^ permalink raw reply [flat|nested] 10+ messages in thread
* [RFC 5/5] ARM: tegra: Enable UDC on Jetson TK1
2016-05-26 15:40 [RFC 0/5] usb: chipidea: Add support for Tegra20 through Tegra124 Thierry Reding
` (3 preceding siblings ...)
2016-05-26 15:40 ` [RFC 4/5] ARM: tegra: Enable UDC on Dalmore Thierry Reding
@ 2016-05-26 15:40 ` Thierry Reding
2016-05-27 3:16 ` [RFC 0/5] usb: chipidea: Add support for Tegra20 through Tegra124 Peter Chen
5 siblings, 0 replies; 10+ messages in thread
From: Thierry Reding @ 2016-05-26 15:40 UTC (permalink / raw)
To: Peter Chen, Greg Kroah-Hartman
Cc: Stephen Warren, Thierry Reding, Alexandre Courbot, Jon Hunter,
linux-usb, linux-tegra, linux-kernel
From: Thierry Reding <treding@nvidia.com>
Override the compatible string of the first USB controller to enable
device mode.
Signed-off-by: Thierry Reding <treding@nvidia.com>
---
arch/arm/boot/dts/tegra124-jetson-tk1.dts | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/arch/arm/boot/dts/tegra124-jetson-tk1.dts b/arch/arm/boot/dts/tegra124-jetson-tk1.dts
index 941f36263c8f..30e92cc85b86 100644
--- a/arch/arm/boot/dts/tegra124-jetson-tk1.dts
+++ b/arch/arm/boot/dts/tegra124-jetson-tk1.dts
@@ -1726,7 +1726,7 @@
lanes {
usb2-0 {
- nvidia,function = "xusb";
+ nvidia,function = "snps";
status = "okay";
};
@@ -1833,6 +1833,17 @@
};
};
+ usb@0,7d000000 {
+ compatible = "nvidia,tegra124-udc";
+ status = "okay";
+ dr_mode = "otg";
+ };
+
+ usb-phy@0,7d000000 {
+ status = "okay";
+ dr_mode = "otg";
+ };
+
/* mini-PCIe USB */
usb@0,7d004000 {
status = "okay";
--
2.8.3
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [RFC 0/5] usb: chipidea: Add support for Tegra20 through Tegra124
2016-05-26 15:40 [RFC 0/5] usb: chipidea: Add support for Tegra20 through Tegra124 Thierry Reding
` (4 preceding siblings ...)
2016-05-26 15:40 ` [RFC 5/5] ARM: tegra: Enable UDC on Jetson TK1 Thierry Reding
@ 2016-05-27 3:16 ` Peter Chen
5 siblings, 0 replies; 10+ messages in thread
From: Peter Chen @ 2016-05-27 3:16 UTC (permalink / raw)
To: Thierry Reding
Cc: Peter Chen, Greg Kroah-Hartman, Stephen Warren,
Alexandre Courbot, Jon Hunter, linux-usb, linux-tegra,
linux-kernel
On Thu, May 26, 2016 at 05:40:00PM +0200, Thierry Reding wrote:
> From: Thierry Reding <treding@nvidia.com>
>
> All Tegra SoC generations from Tegra20 through Tegra124 have a ChipIdea
> USB device controller. This set of patches adds very rudimentary support
> for it to the existing ChipIdea driver and enables them on the set of
> boards that I could easily test on.
>
> I'm sending this out as RFC because I'm not sure yet how to merge this.
> While the driver seems to work fine (tested by exporting a USB driver or
> eMMC via the mass storage function) I don't yet understand how to make
> the driver switch between host and device modes dynamically. It might be
> useful to get this merged before, but I'd like to have some feedback on
> this, because doing so would mean that we need to use device mode on the
> devices where it's enabled and can't use the USBD port in host mode.
>
Chipidea driver supports many ways to switch between host and device
mode. It can support switching with/without disconnecting cable.
Most of cases need to disconnect cable (Micro-AB) to switch between
host and device mode, I just take this as an example:
Using ID pin which is at Micro-B receptacle on the board to determine host (ID = 0)
or device (ID = 1 )mode.
- ID pin connects to CPU, and ID interrupt and value can be get through
register OTGSC.
- ID pin does not connect to CPU, and there is a dedicated GPIO for ID.
--
Best Regards,
Peter Chen
^ permalink raw reply [flat|nested] 10+ messages in thread