From: Roger Quadros <rogerq@kernel.org>
To: Siddharth Vadapalli <s-vadapalli@ti.com>
Cc: vigneshr@ti.com, bb@ti.com, trini@konsulko.com, marex@denx.de,
hnagalla@ti.com, mkorpershoek@baylibre.com,
caleb.connolly@linaro.org, neil.armstrong@linaro.org,
jan.kiszka@siemens.com, jonas@kwiboo.se, j-humphreys@ti.com,
nm@ti.com, devarsht@ti.com, ilias.apalodimas@linaro.org,
u-boot@lists.denx.de, srk@ti.com
Subject: Re: [PATCH 1/2] usb: dwc3-generic: set "mode" based on caller of dwc3_generic_probe()
Date: Mon, 2 Dec 2024 16:09:15 +0200 [thread overview]
Message-ID: <2b705d26-2ff0-47a2-8db6-d8561a24b567@kernel.org> (raw)
In-Reply-To: <i7kcsazysfv5brn5bzgh5yypgr7hl2qndd5aqdrgbkb6ztmvxo@qwuxqa7vm2nt>
On 02/12/2024 07:42, Siddharth Vadapalli wrote:
> On Fri, Nov 29, 2024 at 02:28:36PM +0200, Roger Quadros wrote:
>>
>>
>> On 28/11/2024 19:20, Siddharth Vadapalli wrote:
>
> [...]
>
>>> USB DFU boot utilizes this driver when the "dr_mode" is set to "otg" in
>>> the device-tree for AM62A. This driver is invoked both for the host and
>>> device commands corresponding to USB. I came up with this patch while
>>> trying to enable USB DFU boot on AM62A with "dr_mode" as "otg" in the
>>> device-tree. Additionally, USB DFU boot works on AM62A with the change
>>> made by this patch and it doesn't work without this change. I have
>>> traced the call sequence to see that the driver is probed and have come
>>> up with the change performed in this patch on the basis of this observation.
>>>
>>
>> Although the glue driver portion of the dwc3-generic driver is not used by AM62
>> it still uses the generic_probe() portion via
>> U_BOOT_DRIVER(dwc3_generic_host) and U_BOOT_DRIVER(dwc3_generic_peripheral)
>>
>> here is the dm tree output on am62-sk after executing "usb start" command.
>>
>>
>> simple_bus 5 [ + ] dwc3-am62 | |-- dwc3-usb@f900000
>> usb_gadget 0 [ ] dwc3-generic-periphe | | |-- usb@31000000
>> usb 0 [ + ] xhci-dwc3 | | `-- usb@31000000
>> usb_hub 0 [ + ] usb_hub | | `-- usb_hub
>> simple_bus 6 [ + ] dwc3-am62 | |-- dwc3-usb@f910000
>> usb 1 [ ] dwc3-generic-host | | |-- usb@31100000
>> usb 1 [ + ] xhci-dwc3 | | `-- usb@31100000
>> usb_hub 1 [ + ] usb_hub | | `-- usb_hub
>>
>> what is strange is that even though usb@31000000 is configured as
>> "peripheral" (in k3-am625-sk-u-boot.dtsi), xhci-dwc3 and usb_hub drivers
>> are still initialized for it.
>
> CONFIG_OF_UPSTREAM is enabled in am62x_evm_a53_defconfig. So dr_mode
> might be "otg" as specified in:
> dts/upstream/src/arm64/ti/k3-am62-main.dtsi
Not it is not "otg". it is "peripheral". I verified from the generated
u-boot.dtb
Isn't k3-am625-sk-u-boot.dtsi still used even if it is CONFIG_OF_UPSTREAM?
> I'm not sure about this however. Additionally, this series isn't required
> for AM62. DFU Boot works on AM62 without this series as well. This series
> is required for AM62A.
It works on am62-sk because USB mode is forced to "peripheral" in
k3-am625-sk-u-boot.dtsi.
That hack can be removed once your series fixes it the right way.
>
> [...]
>
>>> I didn't test the case where both are used. I validated that peripheral
>>> mode works across various stages of boot with "otg" mode via USB DFU
>>> boot. This isn't the case without this patch.
>>>
>>> If we forget the reason that this patch is introduced and take a moment
>>> to analyze the existing code prior to this patch, we see that:
>>> 1. Both dwc3_generic_peripheral_probe() and dwc3_generic_host_probe()
>>> invoke dwc3_generic_probe().
>>> 2. dwc3_generic_probe() sets the role based on the role specified in the/
>>> device-tree and not what the caller wants the role to be.
>>> This seems to be strange to me considering that dwc3_generic_probe()
>>> simply proceeds to configure without comparing the role supported by the
>>> platform with the role requested by the caller.
>>>
>>> So even if we entirely forget the "otg" fix being attempted by this
>>> patch, the same patch is fixing something else i.e. ensuring that
>>> dwc3_generic_probe() does what the caller wants it to do by using the
>>> role that the caller expects. Isn't it incorrect that the existing code
>>> might end up with:
>>> a) Caller being dwc3_generic_host_probe() with dr_mode being set to
>>> "peripheral" within dwc3_generic_probe() based on the device-tree and
>>> proceeding to configure the controller
>>
>> Maye this is the reason why host controller is initialized for peripheral
>> only port in the dm tree output I listed above. This needs to be fixed.
>
> Sure, I will post a patch to do the following:
> If dr_mode specified in device-tree is "host" then return -EINVAL within
> dwc3_generic_probe() if the caller is "dwc3_generic_peripheral_probe()".
> Similarly, if dr_mode specified in the device-tree is "peripheral" then
> return -EINVAL within dwc3_generic_probe() if the caller is
> "dwc3_generic_host_probe()". When dr_mode is specified as "otg" in the
> device-tree, then configure the mode based on the caller of
> dwc3_generic_probe().
>
> Please let me know if the above implementation is acceptable.
Looks OK to me.
>
>>> b) Caller being dwc3_generic_peripheral_probe() with dr_mode being set
>>> to "host" within dwc3_generic_probe() based on the device-tree and
>>> proceeding to configure the controller.
>>
>> This too needs to be fixed.
>>
>>> Shouldn't this inconsistency be fixed? This patch fixes that by setting
>>> dr_mode to what the caller expects. However, based on your suggestion, I
>>> agree that there should have been a check within dwc3_generic_probe() to
>>> ensure that the platform supports what the caller is requesting. I will
>>> update this patch by adding the check.
>>
>> Apart from the platform supported mode check when not "otg", if platform
>> supports "otg" we need to check and prevent role setting if hardware is
>> not in the correct state based on connected USB cable.
>> i.e. if host mode cable is used then prevent it from running as a peripheral.
>> if peripheral mode cable is used then prevent it from running as a host.
>> (based on ID status?)
>
> Yes, I agree that using the ID status to determine the role is accurate.
> At the same time, I think that in addition to this, if the user runs a
> command corresponding to "peripheral" mode of operation with the ID
> status indicating "host", then it will be better to take this
> inconsistency into account and error out rather than simply proceeding
> to configure on the basis of the ID status. If you have any feedback,
> kindly let me know.
The approach looks OK to me.
--
cheers,
-roger
next prev parent reply other threads:[~2024-12-02 14:09 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-26 12:03 [PATCH 0/2] AM62A DWC3: Add support for USB DFU boot in OTG mode Siddharth Vadapalli
2024-11-26 12:03 ` [PATCH 1/2] usb: dwc3-generic: set "mode" based on caller of dwc3_generic_probe() Siddharth Vadapalli
2024-11-28 13:10 ` Roger Quadros
2024-11-28 17:20 ` Siddharth Vadapalli
2024-11-29 12:28 ` Roger Quadros
2024-12-02 5:42 ` Siddharth Vadapalli
2024-12-02 14:09 ` Roger Quadros [this message]
2024-12-04 22:24 ` Roger Quadros
2024-12-13 19:45 ` Marek Vasut
2024-11-26 12:03 ` [PATCH 2/2] board: ti: am62ax: env: include environment for DFU Siddharth Vadapalli
2024-12-04 22:25 ` Roger Quadros
2024-11-28 12:45 ` [PATCH 0/2] AM62A DWC3: Add support for USB DFU boot in OTG mode Roger Quadros
2024-11-28 16:47 ` Siddharth Vadapalli
2024-12-13 23:16 ` Tom Rini
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=2b705d26-2ff0-47a2-8db6-d8561a24b567@kernel.org \
--to=rogerq@kernel.org \
--cc=bb@ti.com \
--cc=caleb.connolly@linaro.org \
--cc=devarsht@ti.com \
--cc=hnagalla@ti.com \
--cc=ilias.apalodimas@linaro.org \
--cc=j-humphreys@ti.com \
--cc=jan.kiszka@siemens.com \
--cc=jonas@kwiboo.se \
--cc=marex@denx.de \
--cc=mkorpershoek@baylibre.com \
--cc=neil.armstrong@linaro.org \
--cc=nm@ti.com \
--cc=s-vadapalli@ti.com \
--cc=srk@ti.com \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
--cc=vigneshr@ti.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