mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Inochi Amaoto <inochiama@gmail.com>
To: Chen-Yu Yeh <chenyou910331@gmail.com>,
	Vinod Koul <vkoul@kernel.org>,
	 Neil Armstrong <neil.armstrong@linaro.org>,
	Inochi Amaoto <inochiama@gmail.com>,
	 Chen Wang <chen.wang@linux.dev>
Cc: Rob Herring <robh@kernel.org>,
	 Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	 Paul Walmsley <pjw@kernel.org>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	 Albert Ou <aou@eecs.berkeley.edu>,
	Alexandre Ghiti <alex@ghiti.fr>,
	 Hiago De Franco <hfranco@baylibre.com>,
	linux-phy@lists.infradead.org, devicetree@vger.kernel.org,
	 sophgo@lists.linux.dev, linux-riscv@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 0/3] phy: sophgo: Add USB role switch for CV18XX/SG200X
Date: Tue, 10 Nov 2026 15:09:23 +0800	[thread overview]
Message-ID: <avLC68zOj8WKuslb@inochi.infowork> (raw)
In-Reply-To: <20261103085847.338613-1-chenyou910331@gmail.com>

On Tue, Nov 03, 2026 at 04:58:44PM +0800, Chen-Yu Yeh wrote:
> This makes one DTB work as both USB host and USB device on the Milk-V
> Duo 256M, following the discussion in the thread "Milk-V Duo 256M: USB
> peripheral mode works on mainline, how should dr_mode be handled?" on
> the sophgo list. There, Inochi pointed out that a dual-role switch is the
> right way and that the default should match the vendor image.
> 
> The usb-role-switch support in dwc2 hangs on this SoC. It clears B-valid
> through the GOTGCTL session overrides while VBUS is present, and
> GOTGINT.SesEndDet then fires back to back. The vendor kernel writes only
> the ID override in the top syscon and lets dwc2 follow the Connector ID
> change, and this works on mainline too, without any change to dwc2. So
> the role switch lives in the PHY driver, which already owns those bits.
> 
> Test setup
> ==========
> 
> Milk-V Duo 256M, vendor buildroot rootfs, loaded by hand from U-Boot.
> Tree: v7.3-rc5 with these changes, CONFIG_USB_DWC2_DUAL_ROLE=y,
> CONFIG_USB_ETH=y. The series itself is based on current master; the files
> touched by patches 1 and 2 are the same in both trees.
> 
> Tests 1 to 3 ran with CONFIG_USB_DWC2_DEBUG=y and the DT properties
> applied through an overlay. Test 4 ran with debug disabled and the
> board DTS from patch 3.
> 
> In the logs below, 
> R=/sys/class/usb_role/3000000.syscon:phy@48-role-switch
> 
> 1. Default peripheral, bare board on a PC, nothing done after boot
> ------------------------------------------------------------------
> 
>   # ls /sys/class/usb_role/
>   3000000.syscon:phy@48-role-switch
>   # cat $R/role
>   device
>   # devmem 0x03000048 32
>   0x000003C0
>   # cat /sys/class/udc/*/state
>   configured
> 
>   PC$ lsusb | grep 0525
>   Bus 003 Device 009: ID 0525:a4a2 Netchip Technology, Inc. Linux-USB Ethernet/RNDIS Gadget
> 
> 2. Switching at runtime, same setup
> -----------------------------------
> 
>   # echo host > $R/role
>   # cat $R/role
>   host
>   # devmem 0x03000048 32
>   0x00000142
>   # echo device > $R/role
>   # cat $R/role
>   device
>   # devmem 0x03000048 32
>   0x000003C0
>   # cat /sys/class/udc/*/state
>   configured
> 
> The switch was repeated without an interrupt storm, then:
> 
>   # echo none > $R/role
>   # cat $R/role
>   device
>   # devmem 0x03000048 32
>   0x000003C0
> 
> 3. Default host, on the USB & Ethernet IO board, nothing done after boot
> ------------------------------------------------------------------------
> 
> Only role-switch-default-mode differs from patch 3 here.
> 
>   [    3.409672] usb 1-1: new high-speed USB device number 2 using dwc2
>   [    3.666655] hub 1-1:1.0: 4 ports detected
>   [   72.484979] usb 1-1.1: new high-speed USB device number 3 using dwc2
>   [   74.804484]  sda: sda1 sda2 sda3 sda4
> 
> The USB stick was plugged in by hand at about 72 s.
> 
>   # cat $R/role
>   host
>   # devmem 0x03000048 32
>   0x00000142
>   # devmem 0x04340018 32
>   0xF300081E
>   # devmem 0x04340440 32
>   0x00001005
>   # echo none > $R/role
>   # cat $R/role
>   host
>   # ls /dev/sd*
>   /dev/sda  /dev/sda1  /dev/sda2  /dev/sda3  /dev/sda4
> 
> 4. Patch 3 as committed, debug disabled
> ---------------------------------------
> 
> Bare board on a PC, nothing done after boot:
> 
>   # cat $R/role
>   device
> 
>   PC: usb 3-9: New USB device found, idVendor=0525, idProduct=a4a2
>   PC: usb 3-9: Product: RNDIS/Ethernet Gadget
> 
> On the IO board, with a USB stick already plugged in at boot:
> 
>   # cat $R/role
>   device
>   # echo host > $R/role
>   # cat $R/role
>   host
>   # dmesg | grep -E 'usb 1-1'
>   [  415.464739] usb 1-1: new high-speed USB device number 2 using dwc2
>   [  415.940738] usb 1-1.1: new high-speed USB device number 3 using dwc2
> 
> Before this series
> ==================
> 
> With usb-role-switch on the dwc2 node, "echo host" hangs the board in the
> SesEndDet storm, and so does boot without role-switch-default-mode.
> 
> With dr_mode = "otg" and no role switch, writing the ID override by hand
> worked:
> 
>   devmem 0x03000048 32 0x3C0  -> high-speed RNDIS gadget on the PC
>   devmem 0x03000048 32 0x142  -> disconnects from the PC, host side starts
> 
> Three round trips were all correct, and ping over usb0 afterwards was
> 5/5. On the IO board, the hub and USB stick appeared after one toggle,
> but not at boot, because usb_add_hcd() moved the PHY to host after dwc2
> had already set up for device:
> 
>             at boot       after one toggle
>   GINTSTS   0x05000023    0x04200021
>   GINTMSK   0xd0bc3cd4    0xf300081e    (PrtInt masked -> unmasked)
>   HPRT0     0x00021403    0x00001005    (ConnDet pending -> port enabled)
> 
> Test 3 above reaches the right-hand values at boot without a toggle.
> 
> Not tested
> ==========
> 
>  - A USB stick already plugged in at boot in the default host case.
>  - Running on a master based tree: all tests used the v7.3-rc5 tree.
>  - Boards other than the Duo 256M. Nothing changes on them, since the
>    role switch is only registered when the PHY node has usb-role-switch.
> 
> Question
> ========
> 
> With patch 3, the hub on the IO board needs "echo host" after each boot.
> Should the IO board overlay (sg2002-milkv-duo256m-eth.dtso) set
> role-switch-default-mode = "host", or should it stay the same as the
> vendor image?
> 
> 
> Chen-Yu Yeh (3):
>   dt-bindings: phy: sophgo,cv1800b-usb2-phy: Add USB role switch
>     properties
>   phy: sophgo: Add USB role switch support for CV18XX/SG200X
>   riscv: dts: sophgo: sg2002-milkv-duo256m: Enable USB role switch
> 
>  .../bindings/phy/sophgo,cv1800b-usb2-phy.yaml |  11 ++
>  .../boot/dts/sophgo/sg2002-milkv-duo256m.dts  |   7 +-
>  drivers/phy/sophgo/Kconfig                    |   2 +
>  drivers/phy/sophgo/phy-cv1800-usb2.c          | 107 ++++++++++++++++--
>  4 files changed, 119 insertions(+), 8 deletions(-)
> 
> 
> base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
> -- 
> 2.43.0
> 

NAK on this patch, I do not think fix phy is the right way for a
controller problem. See my new patch:

https://lore.kernel.org/linux-usb/20261110070627.217946-1-inochiama@gmail.com

Regards,
Inochi

      parent reply	other threads:[~2026-11-10  7:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03  8:58 Chen-Yu Yeh
2026-11-03  8:58 ` [PATCH 1/3] dt-bindings: phy: sophgo,cv1800b-usb2-phy: Add USB role switch properties Chen-Yu Yeh
2026-11-03  8:58 ` [PATCH 2/3] phy: sophgo: Add USB role switch support for CV18XX/SG200X Chen-Yu Yeh
2026-11-03  8:58 ` [PATCH 3/3] riscv: dts: sophgo: sg2002-milkv-duo256m: Enable USB role switch Chen-Yu Yeh
2026-11-10  7:09 ` Inochi Amaoto [this message]

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=avLC68zOj8WKuslb@inochi.infowork \
    --to=inochiama@gmail.com \
    --cc=alex@ghiti.fr \
    --cc=aou@eecs.berkeley.edu \
    --cc=chen.wang@linux.dev \
    --cc=chenyou910331@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=hfranco@baylibre.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-phy@lists.infradead.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=neil.armstrong@linaro.org \
    --cc=palmer@dabbelt.com \
    --cc=pjw@kernel.org \
    --cc=robh@kernel.org \
    --cc=sophgo@lists.linux.dev \
    --cc=vkoul@kernel.org \
    /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

all inboxes | Powered by JetHome®