From: Dmitry Osipenko <digetx@gmail.com>
To: Peter Chen <peter.chen@nxp.com>
Cc: Thierry Reding <thierry.reding@gmail.com>,
Jonathan Hunter <jonathanh@nvidia.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Alan Stern <stern@rowland.harvard.edu>,
Felipe Balbi <balbi@kernel.org>,
Matt Merhar <mattmerhar@protonmail.com>,
Nicolas Chauvet <kwizart@gmail.com>,
Peter Geis <pgwipeout@gmail.com>,
"linux-tegra@vger.kernel.org" <linux-tegra@vger.kernel.org>,
"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v1 5/8] usb: chipidea: tegra: Support host mode
Date: Wed, 16 Dec 2020 12:07:40 +0300 [thread overview]
Message-ID: <bb617167-e6a4-221e-5e3b-c9d7a1b50c87@gmail.com> (raw)
In-Reply-To: <20201216060732.GB5595@b29397-desktop>
16.12.2020 09:08, Peter Chen пишет:
> On 20-12-15 23:21:10, Dmitry Osipenko wrote:
>> From: Peter Geis <pgwipeout@gmail.com>
>>
>> struct tegra_usb_soc_info {
>> unsigned long flags;
>> + unsigned int txfifothresh;
>> + enum usb_dr_mode dr_mode;
>> +};
>> +
>> +static const struct tegra_usb_soc_info tegra20_ehci_soc_info = {
>> + .flags = CI_HDRC_REQUIRES_ALIGNED_DMA |
>> + CI_HDRC_OVERRIDE_PHY_CONTROL,
>> + .dr_mode = USB_DR_MODE_HOST,
>> + .txfifothresh = 10,
>> +};
>> +
>> +static const struct tegra_usb_soc_info tegra30_ehci_soc_info = {
>> + .flags = CI_HDRC_REQUIRES_ALIGNED_DMA |
>> + CI_HDRC_OVERRIDE_PHY_CONTROL
>> + .dr_mode = USB_DR_MODE_HOST,
>> + .txfifothresh = 16,
>> };
>>
>> static const struct tegra_usb_soc_info tegra_udc_soc_info = {
>> - .flags = CI_HDRC_REQUIRES_ALIGNED_DMA,
>> + .flags = CI_HDRC_REQUIRES_ALIGNED_DMA |
>> + CI_HDRC_OVERRIDE_PHY_CONTROL,
>> + .dr_mode = USB_DR_MODE_UNKNOWN,
>> };
>
> What's the usage for this dr_mode? Does these three SoCs only supports
> single mode, it usually sets dr_mode at board dts file to indicate
> USB role for this board.
All Tegra SoCs have three USB controllers. Only one of these three
controllers supports peripheral / OTG modes, the other two controllers
are fixed to the host mode and device trees do not specify the dr_mode
for the host controllers.
Hence we need to enforce the dr_mode=host for the host-mode controllers.
For UDC the default mode is "unknown" because actual mode comes from a
board's device tree.
>> static const struct of_device_id tegra_usb_of_match[] = {
>> {
>> + .compatible = "nvidia,tegra20-ehci",
>> + .data = &tegra20_ehci_soc_info,
>> + }, {
>> + .compatible = "nvidia,tegra30-ehci",
>> + .data = &tegra30_ehci_soc_info,
>> + }, {
>> .compatible = "nvidia,tegra20-udc",
>> .data = &tegra_udc_soc_info,
>
> Your compatible indicates this controller is single USB role, is it
> on purpose?
Yes, the "tegra20/30-ehci" controllers are fixed to the host-mode in
hardware.
...
>> +static int tegra_usb_internal_port_reset(struct ehci_hcd *ehci,
>> + u32 __iomem *portsc_reg,
>> + unsigned long *flags)
>> +{
>> + u32 saved_usbintr, temp;
>> + unsigned int i, tries;
>> + int retval = 0;
>> +
>> + saved_usbintr = ehci_readl(ehci, &ehci->regs->intr_enable);
>> + /* disable USB interrupt */
>> + ehci_writel(ehci, 0, &ehci->regs->intr_enable);
>> + spin_unlock_irqrestore(&ehci->lock, *flags);
>> +
>> + /*
>> + * Here we have to do Port Reset at most twice for
>> + * Port Enable bit to be set.
>> + */
>> + for (i = 0; i < 2; i++) {
>> + temp = ehci_readl(ehci, portsc_reg);
>> + temp |= PORT_RESET;
>> + ehci_writel(ehci, temp, portsc_reg);
>> + mdelay(10);
>
> Needs accurate delay? How about usleep_range?
To be hones I don't know for sure whether hub_control() could be used
from interrupt context. This mdelay is borrowed from the older
ehci-tegra driver.
Are you suggesting that it should be safe to sleep here?
...
>> static int tegra_usb_probe(struct platform_device *pdev)
>> {
>> const struct tegra_usb_soc_info *soc;
>> @@ -83,24 +292,49 @@ static int tegra_usb_probe(struct platform_device *pdev)
>> return err;
>> }
>>
>> + if (device_property_present(&pdev->dev, "nvidia,needs-double-reset"))
>> + usb->needs_double_reset = true;
>> +
>> + err = tegra_usb_reset_controller(&pdev->dev);
>> + if (err) {
>> + dev_err(&pdev->dev, "failed to reset controller: %d\n", err);
>> + goto fail_power_off;
>> + }
>> +
>> + /*
>> + * USB controller registers shan't be touched before PHY is
>
> %s/shan't/shouldn't
ok
...
>> static int ehci_ci_portpower(struct usb_hcd *hcd, int portnum, bool enable)
>> {
>> struct ehci_hcd *ehci = hcd_to_ehci(hcd);
>> @@ -160,14 +166,14 @@ static int host_start(struct ci_hdrc *ci)
>> pinctrl_select_state(ci->platdata->pctl,
>> ci->platdata->pins_host);
>>
>> + ci->hcd = hcd;
>> +
>> ret = usb_add_hcd(hcd, 0, 0);
>> if (ret) {
>> goto disable_reg;
>> } else {
>> struct usb_otg *otg = &ci->otg;
>>
>> - ci->hcd = hcd;
>> -
>
> Why this changed?
The ci->hcd is used by tegra_usb_notify_event() to handle reset event
and the reset happens once usb_add_hcd() is invoked. Hence we need to
pre-assign the hcd pointer, otherwise there will be a NULL dereference.
next prev parent reply other threads:[~2020-12-16 9:08 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-15 20:21 [PATCH v1 0/8] Support Runtime PM and host mode by Tegra ChipIdea USB driver Dmitry Osipenko
2020-12-15 20:21 ` [PATCH v1 1/8] usb: phy: tegra: Add delay after power up Dmitry Osipenko
2020-12-16 8:51 ` Sergei Shtylyov
2020-12-16 9:09 ` Dmitry Osipenko
2020-12-15 20:21 ` [PATCH v1 2/8] usb: phy: tegra: Support waking up from a low power mode Dmitry Osipenko
2020-12-15 20:21 ` [PATCH v1 3/8] usb: chipidea: tegra: Remove MODULE_ALIAS Dmitry Osipenko
2020-12-16 17:58 ` Thierry Reding
2020-12-16 18:06 ` Dmitry Osipenko
2020-12-15 20:21 ` [PATCH v1 4/8] usb: chipidea: tegra: Rename UDC to USB Dmitry Osipenko
2020-12-15 20:21 ` [PATCH v1 5/8] usb: chipidea: tegra: Support host mode Dmitry Osipenko
2020-12-16 6:08 ` Peter Chen
2020-12-16 9:07 ` Dmitry Osipenko [this message]
2020-12-16 9:22 ` Dmitry Osipenko
2020-12-16 9:32 ` Peter Chen
2020-12-16 9:53 ` Dmitry Osipenko
2020-12-16 15:56 ` Dmitry Osipenko
2020-12-15 20:21 ` [PATCH v1 6/8] usb: chipidea: tegra: Support runtime PM Dmitry Osipenko
2020-12-15 20:21 ` [PATCH v1 7/8] usb: host: ehci-tegra: Remove the driver Dmitry Osipenko
2020-12-16 16:45 ` Alan Stern
2020-12-16 17:09 ` Dmitry Osipenko
2020-12-16 17:22 ` Alan Stern
2020-12-16 17:28 ` Dmitry Osipenko
2020-12-15 20:21 ` [PATCH v1 8/8] ARM: tegra_defconfig: Enable USB_CHIPIDEA and remove USB_EHCI_TEGRA Dmitry Osipenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bb617167-e6a4-221e-5e3b-c9d7a1b50c87@gmail.com \
--to=digetx@gmail.com \
--cc=balbi@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=jonathanh@nvidia.com \
--cc=kwizart@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mattmerhar@protonmail.com \
--cc=peter.chen@nxp.com \
--cc=pgwipeout@gmail.com \
--cc=stern@rowland.harvard.edu \
--cc=thierry.reding@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox