Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5106836ybl; Tue, 4 Feb 2020 07:50:58 -0800 (PST) X-Google-Smtp-Source: APXvYqzfwK5IIV0cU4Puetw2Ubh2h+9ymHoGLLU9NJpyxozwUXWTn6z1FEmJkQfX3XbIAIKTulYI X-Received: by 2002:aca:220c:: with SMTP id b12mr3719685oic.55.1580831457806; Tue, 04 Feb 2020 07:50:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580831457; cv=none; d=google.com; s=arc-20160816; b=jDkk5kOOH5klc1Mm7vy7e9rg94eCfsc1GNHxk0sTqPTX6x4u1QcUaHocX6aSN8nVZ7 ilcArAnmFE/WG6qNwT6M9j/HgALegW0yXF38Fy0S6Rxo4DqRl9PqvKFZfWFc3JDWcn3m QCuWJL9xqAfFm77BR5z1Bjc4RLlo0myakqtb7afyUYdFJTtypuswkYsxJxoXeFqOTAWr P8zOk+m7HUklDDjD6rm29u2ssq7HDCb97ouE95462ELrhoIfqmZx/k6mSOqZU7PTiHpq GfdVaeoLtCbViLG+jbpgnEZr48ANP9QNnt2cpWBlhMRDNfzwsYK4StyZk8B7i4YridKw uGhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=BCdvwgEIvLavwKgXgiW4fr4Lb89HM8+hPWO6GLgNnK0=; b=vBBGHnh5ZrzywtSKDINGtXfSzlODaHk5sIlh8B9L1afPcEtENG+exVea6HhGipZCcp 9gwLD3cu9Ue9oWDbTl0hnoWYj9oP0Qm/bBYMjgrQTlgwKgM4jlRvF+juKYexJjkUZ7cU vrtZ0qRVplX9mYGFB6nbcNyBsUdU25xFzldcRBKDqZXxJxQ+IR+DmuwriV1EaStNOdTL PKmJBBlvkPxaELE2jPUKmw+Nar7gdRxBjY1rQDBecYyMI0+25oI67euZMQmiXw6n4MYj /jR3nnny1DwMPpVdIr1Ixddawqjuy6TfNtkz82OujwQscR7VnHTICZPG14fp759sXKdE fYHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@metanate.com header.s=stronger header.b=A0XINnLp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=metanate.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e13si11548818otr.167.2020.02.04.07.50.44; Tue, 04 Feb 2020 07:50:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail (test mode) header.i=@metanate.com header.s=stronger header.b=A0XINnLp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=metanate.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727357AbgBDPtQ (ORCPT + 99 others); Tue, 4 Feb 2020 10:49:16 -0500 Received: from dougal.metanate.com ([90.155.101.14]:30752 "EHLO metanate.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727311AbgBDPtQ (ORCPT ); Tue, 4 Feb 2020 10:49:16 -0500 X-Greylist: delayed 1165 seconds by postgrey-1.27 at vger.kernel.org; Tue, 04 Feb 2020 10:49:16 EST DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=simple/simple; d=metanate.com; s=stronger; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject :Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=OvOkKA8YrVohxNFd6lUTWVLJe0uQSPQYn+QRHOVtyyg=; b=A0XINnLprZlnob0BQI7yIkZXrD 6BmMJ+A9vN6KR/V+r/RVNTpKxjZ9Uoo9JKQKPQqhoR/VRLpCUPcdjjR/IIxImfkQ7U6NkdveRJH9Z gU4Lziw/cgQe9/KnV7CIl4n3Jii2nXs+dcXi5S0q5hBgTqE7zaksrO+ZEJ/dLDCDpsUfaDrASTC+L N1Zt6uoZzS3yESED2vZgW5GvgA0AHfhFfrA5tCOItSDD7bOr4CaDorGP2ynnZz3gzIHadS1NJ97jy l7zTHytXkeYjD4fcrA8XG08FfM7XjitHYtbFVIIHlw/fNWajkG7HfaprM/ypGmwb6m7cSqeEzL84W HuuKav6Q==; Received: from dougal.metanate.com ([192.168.88.1] helo=donbot.metanate.com) by email.metanate.com with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1iz095-0002mK-9X; Tue, 04 Feb 2020 15:29:47 +0000 From: John Keeping To: Minas Harutyunyan Cc: Felipe Balbi , John Keeping , Greg Kroah-Hartman , linux-usb@vger.kernel.org (open list:DESIGNWARE USB2 DRD IP DRIVER), linux-kernel@vger.kernel.org (open list) Subject: [PATCH] usb: dwc2: Implement set_selfpowered() Date: Tue, 4 Feb 2020 15:29:33 +0000 Message-Id: <20200204152933.2216615-1-john@metanate.com> X-Mailer: git-send-email 2.25.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Authenticated: YES Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org dwc2 always reports as self-powered in response to a device status request. Implement the set_selfpowered() operations so that the gadget can report as bus-powered when appropriate. This is modelled on the dwc3 implementation. Signed-off-by: John Keeping --- drivers/usb/dwc2/gadget.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c index 2717f4401b97..76c0a5242175 100644 --- a/drivers/usb/dwc2/gadget.c +++ b/drivers/usb/dwc2/gadget.c @@ -1646,7 +1646,8 @@ static int dwc2_hsotg_process_req_status(struct dwc2_hsotg *hsotg, switch (ctrl->bRequestType & USB_RECIP_MASK) { case USB_RECIP_DEVICE: - status = 1 << USB_DEVICE_SELF_POWERED; + status = hsotg->gadget.is_selfpowered << + USB_DEVICE_SELF_POWERED; status |= hsotg->remote_wakeup_allowed << USB_DEVICE_REMOTE_WAKEUP; reply = cpu_to_le16(status); @@ -4530,6 +4531,26 @@ static int dwc2_hsotg_gadget_getframe(struct usb_gadget *gadget) return dwc2_hsotg_read_frameno(to_hsotg(gadget)); } +/** + * dwc2_hsotg_set_selfpowered - set if device is self/bus powered + * @gadget: The usb gadget state + * @is_selfpowered: Whether the device is self-powered + * + * Set if the device is self or bus powered. + */ +static int dwc2_hsotg_set_selfpowered(struct usb_gadget *gadget, + int is_selfpowered) +{ + struct dwc2_hsotg *hsotg = to_hsotg(gadget); + unsigned long flags; + + spin_lock_irqsave(&hsotg->lock, flags); + gadget->is_selfpowered = !!is_selfpowered; + spin_unlock_irqrestore(&hsotg->lock, flags); + + return 0; +} + /** * dwc2_hsotg_pullup - connect/disconnect the USB PHY * @gadget: The usb gadget state @@ -4621,6 +4642,7 @@ static int dwc2_hsotg_vbus_draw(struct usb_gadget *gadget, unsigned int mA) static const struct usb_gadget_ops dwc2_hsotg_gadget_ops = { .get_frame = dwc2_hsotg_gadget_getframe, + .set_selfpowered = dwc2_hsotg_set_selfpowered, .udc_start = dwc2_hsotg_udc_start, .udc_stop = dwc2_hsotg_udc_stop, .pullup = dwc2_hsotg_pullup, -- 2.25.0