mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: "NG, TZE YEE" <tze.yee.ng@altera.com>
Cc: Minas Harutyunyan <hminas@synopsys.com>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"NG, ADRIAN HO YIN" <adrian.ho.yin.ng@altera.com>
Subject: Re: [PATCH] usb: dwc2: handle OTG HNP SetFeature requests
Date: Wed, 26 Aug 2026 07:49:05 +0200	[thread overview]
Message-ID: <2026082616-prozac-skilled-f487@gregkh> (raw)
In-Reply-To: <e541e9d0-f6d8-43cc-a2bc-5f1c6a139486@altera.com>

On Wed, Aug 26, 2026 at 03:07:50AM +0000, NG, TZE YEE wrote:
> On 17/8/2026 4:00 pm, NG, TZE YEE wrote:
> > From: Adrian Ng Ho Yin <adrian.ho.yin.ng@altera.com>
> > 
> > Without handling for b_hnp_enable, a_hnp_support, and a_alt_hnp_support,
> > HNP cannot be enabled when two OTG controllers are connected.
> > 
> > Handle SetFeature for these OTG selectors, gated on otg_caps.hnp_support.
> > The OTG specification only defines SetFeature for them, so reject
> > ClearFeature with -EINVAL instead of silently accepting it. Use dev_dbg
> > for status updates to avoid noisy logs.
> > 
> > Advertise the core's HNP/SRP capability during gadget init by restoring
> > GUSBCFG_HNPCAP/SRPCAP from otg_caps, mirroring dwc2_gusbcfg_init() on the
> > host side, instead of clearing them unconditionally.
> > 
> > Clear the HNP flags and GOTGCTL_DEVHNPEN on disconnect/reset so OTG state
> > does not leak across sessions.
> > 
> > Signed-off-by: Adrian Ng Ho Yin <adrian.ho.yin.ng@altera.com>
> > Signed-off-by: Tze Yee Ng <tze.yee.ng@altera.com>
> > ---
> >   drivers/usb/dwc2/gadget.c | 51 +++++++++++++++++++++++++++++++++++++--
> >   1 file changed, 49 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
> > index c8b02c27d27d..4d905989c09f 100644
> > --- a/drivers/usb/dwc2/gadget.c
> > +++ b/drivers/usb/dwc2/gadget.c
> > @@ -1780,6 +1780,7 @@ static int dwc2_hsotg_process_req_feature(struct dwc2_hsotg *hsotg,
> >   	struct dwc2_hsotg_ep *ep;
> >   	int ret;
> >   	bool halted;
> > +	u32 otgctl;
> >   	u32 recip;
> >   	u32 wValue;
> >   	u32 wIndex;
> > @@ -1809,6 +1810,36 @@ static int dwc2_hsotg_process_req_feature(struct dwc2_hsotg *hsotg,
> >   
> >   			hsotg->test_mode = wIndex >> 8;
> >   			break;
> > +		case USB_DEVICE_B_HNP_ENABLE:
> > +			if (!hsotg->params.otg_caps.hnp_support)
> > +				return -ENOENT;
> > +			if (!set)
> > +				return -EINVAL;
> > +
> > +			otgctl = dwc2_readl(hsotg, GOTGCTL);
> > +			otgctl |= GOTGCTL_DEVHNPEN;
> > +			dwc2_writel(hsotg, otgctl, GOTGCTL);
> > +			hsotg->gadget.b_hnp_enable = 1;
> > +			dev_dbg(hsotg->dev, "HNP enabled\n");
> > +			break;
> > +		case USB_DEVICE_A_HNP_SUPPORT:
> > +			if (!hsotg->params.otg_caps.hnp_support)
> > +				return -ENOENT;
> > +			if (!set)
> > +				return -EINVAL;
> > +
> > +			hsotg->gadget.a_hnp_support = 1;
> > +			dev_dbg(hsotg->dev, "a_hnp_support set\n");
> > +			break;
> > +		case USB_DEVICE_A_ALT_HNP_SUPPORT:
> > +			if (!hsotg->params.otg_caps.hnp_support)
> > +				return -ENOENT;
> > +			if (!set)
> > +				return -EINVAL;
> > +
> > +			hsotg->gadget.a_alt_hnp_support = 1;
> > +			dev_dbg(hsotg->dev, "a_alt_hnp_support set\n");
> > +			break;
> >   		default:
> >   			return -ENOENT;
> >   		}
> > @@ -3322,6 +3353,13 @@ void dwc2_hsotg_disconnect(struct dwc2_hsotg *hsotg)
> >   	hsotg->connected = 0;
> >   	hsotg->test_mode = 0;
> >   
> > +	if (hsotg->params.otg_caps.hnp_support) {
> > +		hsotg->gadget.b_hnp_enable = 0;
> > +		hsotg->gadget.a_hnp_support = 0;
> > +		hsotg->gadget.a_alt_hnp_support = 0;
> > +		dwc2_clear_bit(hsotg, GOTGCTL, GOTGCTL_DEVHNPEN);
> > +	}
> > +
> >   	/* all endpoints should be shutdown */
> >   	for (ep = 0; ep < hsotg->num_of_eps; ep++) {
> >   		if (hsotg->eps_in[ep])
> > @@ -3416,9 +3454,18 @@ void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *hsotg,
> >   	usbcfg &= ~GUSBCFG_TOUTCAL_MASK;
> >   	usbcfg |= GUSBCFG_TOUTCAL(7);
> >   
> > -	/* remove the HNP/SRP and set the PHY */
> > +	/*
> > +	 * Configure HNP/SRP capability from params (same idea as
> > +	 * dwc2_gusbcfg_init() for host). Unconditionally clearing these
> > +	 * bits leaves an HNP-capable OTG gadget unable to negotiate.
> > +	 */
> >   	usbcfg &= ~(GUSBCFG_SRPCAP | GUSBCFG_HNPCAP);
> > -        dwc2_writel(hsotg, usbcfg, GUSBCFG);
> > +	if (hsotg->params.otg_caps.hnp_support &&
> > +	    hsotg->params.otg_caps.srp_support)
> > +		usbcfg |= GUSBCFG_HNPCAP;
> > +	if (hsotg->params.otg_caps.srp_support)
> > +		usbcfg |= GUSBCFG_SRPCAP;
> > +	dwc2_writel(hsotg, usbcfg, GUSBCFG);
> >   
> >   	dwc2_phy_init(hsotg, true);
> >
> 
> Hi,
> 
> Gentle ping on this patch. It has been over a week with no feedback.

It's the middle of the merge window, nothing can happen with new patches
until -rc1 is out.  If you wish to make the review process go faster,
please help review other pending patches on the list.

thanks,

greg k-h

      reply	other threads:[~2026-08-26  5:50 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-17  8:00 tze.yee.ng
2026-08-26  3:07 ` NG, TZE YEE
2026-08-26  5:49   ` Greg Kroah-Hartman [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=2026082616-prozac-skilled-f487@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=adrian.ho.yin.ng@altera.com \
    --cc=hminas@synopsys.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=tze.yee.ng@altera.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

all inboxes | Powered by JetHome®