From patchwork Mon Oct 28 21:59:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 177976 Delivered-To: patches@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp3978445ill; Mon, 28 Oct 2019 14:59:34 -0700 (PDT) X-Received: by 2002:a63:5b56:: with SMTP id l22mr24044498pgm.52.1572299974713; Mon, 28 Oct 2019 14:59:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572299974; cv=none; d=google.com; s=arc-20160816; b=vfT5y83ZXFTVclj1a3OF7L8G17qC0tgP2YZhx0rheJZ+cpy5Um7yFQZzMx+DeIPPPv jYtv2G1+pK/khdNv1qcLiEqzTFjHyhhxFK2c9gj4t0t89WBHcXJ3+YVbfYSP8ebrRBLD OVupKRgG/UbwtC30CUW70RvqXKA8w55bvpyCefwSshybHMSbyzKvgkfJXacZDWorvsp5 Y6yyrvdsZMaTVehCfmYFB2JH4QdluBrc5JCagfh4xgYNr1YTXg1vJSd5UMTcb5NGAi/+ NhVHS41P6tPevhEu5NNVHRCMyVnkHVnKLCI8L+jH+JyfE7ra4Hh9HEzC63zpJCzrWmnd J2fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9P5p/4dcNs8ql4OyOSsDmP/Eo0cfZOKgwuYqI45wfJg=; b=YXDNAA9tGbRKZ6bzA7qP0Qrze5PJNXG0ywbYXSwM5B2e42PBAGhyjAYhgn7EUUW7V9 i6oxAYtll7h5vELPJYFsB+9qP7OXlx4dNVXtSF/CGY8uL9eB0YgeXjGTgzRku4SoyDn3 cIx9+5K1OJ/5xNykCXd4h+etEJ8kBLFjVRRPKa5/8rhXTb7v8N/i/vkDXG0qxqO5Ubkg 0W17uBUuFjdUWKLG1724aZrQDaDz0EuKj0dXemmJLiYTN0zS/qy0XWQMooF70dpsdpAQ uXjfzfw1HxfaelXLQmpsWrzK7EebW38gefcMt/PTODS8koetbGWmwdXezFJyv5nx3rtf c5Jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ks8Q41j1; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id c17sor1179670pjo.0.2019.10.28.14.59.34 for (Google Transport Security); Mon, 28 Oct 2019 14:59:34 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ks8Q41j1; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=9P5p/4dcNs8ql4OyOSsDmP/Eo0cfZOKgwuYqI45wfJg=; b=ks8Q41j1ZqA/QKFHT472CH12EK/nGPhBNjUH0WKFQdpFsYiFWCGlWyyocdHfUnLMFa ilBT83QeApQCioM8MCcBVzcBTr7L16ZzSYSrlsZ3svQz3Qbmu5mSay4FCb/9m1XsUVU2 c1YR0FZ10+gBGjO9pUj9XMLVRV8DYgv7q+bju8Xop7n6vZQ9f1jfJDxhERBpjloaB6fy zHrBQ6YHV8IMq095CL+xzpfQDJxCaC6+b2Lj4lm6/v2LPLFB/3kHTtdPCO9b075ZTy59 KdY31qCinVxER1+Qe5BFmn6E1SYTIZ5dzMigy+dADU7kWpKK4lDLBXZWyamHz7NfObM5 BpUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=9P5p/4dcNs8ql4OyOSsDmP/Eo0cfZOKgwuYqI45wfJg=; b=aX4lHGO3p5UXFrn6a4sg5wOJ20dLcHRDGTMz7i6QaK/mT7XiEVjEjdJ+YsSXHn2BHI 2k+Sh27633q0RcZSBDgFTqae/BGLp5RVf0H42C6J5xTWRuDICKQuR5svTvkCBT7phNkE URoM+EQETGNPN9CvjJSxeLFsyE5LDLdOC0vw2tvy73p4XsCyNnUsStWUwr1EkOpBYYsh St7Lk61+qI+bbDVeqYExr1yYlLSNvK1ZP89fPWNmN/iF28JUdzovzt9IitYIhmDk/KhH 1D0tp74w7FmJYfIniJxp9q0n9+ys6UfRrx4uax6EOcDDxQ6tgBevE7L+X3aQ1zmIXvvg q1rw== X-Gm-Message-State: APjAAAU4le6MuAXqHem94VWuUahtyLC96ITu3qIpKLkST0qHkmz8+xWh /IInS4n5+DHVdbR4VzJIY5Bw+adz X-Google-Smtp-Source: APXvYqyzWZOig+RfCXgpnHo7l5IBFBeACyeBjNjdSXrji1GSa9dz+HugwTGG5QUBsQUIQSVHRSs/1A== X-Received: by 2002:a17:90a:1050:: with SMTP id y16mr1902116pjd.59.1572299974196; Mon, 28 Oct 2019 14:59:34 -0700 (PDT) Return-Path: Received: from localhost.localdomain (c-67-170-172-113.hsd1.or.comcast.net. [67.170.172.113]) by smtp.gmail.com with ESMTPSA id f12sm10880612pfn.152.2019.10.28.14.59.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2019 14:59:33 -0700 (PDT) From: John Stultz To: lkml Cc: John Stultz , Greg Kroah-Hartman , Rob Herring , Mark Rutland , ShuFan Lee , Heikki Krogerus , Suzuki K Poulose , Chunfeng Yun , Yu Chen , Felipe Balbi , Hans de Goede , Andy Shevchenko , Jun Li , Valentin Schneider , Jack Pham , linux-usb@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v4 9/9] usb: dwc3: Add host-mode as default support Date: Mon, 28 Oct 2019 21:59:19 +0000 Message-Id: <20191028215919.83697-10-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191028215919.83697-1-john.stultz@linaro.org> References: <20191028215919.83697-1-john.stultz@linaro.org> Support configuring the default role the controller assumes as host mode when the usb role is USB_ROLE_NONE This patch was split out from a larger patch originally by Yu Chen Cc: Greg Kroah-Hartman Cc: Rob Herring Cc: Mark Rutland CC: ShuFan Lee Cc: Heikki Krogerus Cc: Suzuki K Poulose Cc: Chunfeng Yun Cc: Yu Chen Cc: Felipe Balbi Cc: Hans de Goede Cc: Andy Shevchenko Cc: Jun Li Cc: Valentin Schneider Cc: Jack Pham Cc: linux-usb@vger.kernel.org Cc: devicetree@vger.kernel.org Signed-off-by: John Stultz --- v3: Split this patch out from addition of usb-role-switch handling --- drivers/usb/dwc3/core.h | 3 +++ drivers/usb/dwc3/drd.c | 20 ++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) -- 2.17.1 diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 6f19e9891767..3c879c9ab1aa 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -953,6 +953,8 @@ struct dwc3_scratchpad_array { * - USBPHY_INTERFACE_MODE_UTMI * - USBPHY_INTERFACE_MODE_UTMIW * @role_sw: usb_role_switch handle + * @role_switch_default_mode: default operation mode of controller while + * usb role is USB_ROLE_NONE. * @usb2_phy: pointer to USB2 PHY * @usb3_phy: pointer to USB3 PHY * @usb2_generic_phy: pointer to USB2 PHY @@ -1087,6 +1089,7 @@ struct dwc3 { struct notifier_block edev_nb; enum usb_phy_interface hsphy_mode; struct usb_role_switch *role_sw; + enum usb_dr_mode role_switch_default_mode; u32 fladj; u32 irq_gadget; diff --git a/drivers/usb/dwc3/drd.c b/drivers/usb/dwc3/drd.c index 61d4fd8aead4..0e3466fe5ac4 100644 --- a/drivers/usb/dwc3/drd.c +++ b/drivers/usb/dwc3/drd.c @@ -489,7 +489,10 @@ static int dwc3_usb_role_switch_set(struct device *dev, enum usb_role role) mode = DWC3_GCTL_PRTCAP_DEVICE; break; default: - mode = DWC3_GCTL_PRTCAP_DEVICE; + if (dwc->role_switch_default_mode == USB_DR_MODE_HOST) + mode = DWC3_GCTL_PRTCAP_HOST; + else + mode = DWC3_GCTL_PRTCAP_DEVICE; break; } @@ -515,7 +518,10 @@ static enum usb_role dwc3_usb_role_switch_get(struct device *dev) role = dwc->current_otg_role; break; default: - role = USB_ROLE_DEVICE; + if (dwc->role_switch_default_mode == USB_DR_MODE_HOST) + role = USB_ROLE_HOST; + else + role = USB_ROLE_DEVICE; break; } spin_unlock_irqrestore(&dwc->lock, flags); @@ -534,8 +540,14 @@ int dwc3_drd_init(struct dwc3 *dwc) struct usb_role_switch_desc dwc3_role_switch = {NULL}; u32 mode; - mode = DWC3_GCTL_PRTCAP_DEVICE; - + if (device_property_read_bool(dwc->dev, + "role-switch-default-host")) { + dwc->role_switch_default_mode = USB_DR_MODE_HOST; + mode = DWC3_GCTL_PRTCAP_HOST; + } else { + dwc->role_switch_default_mode = USB_DR_MODE_PERIPHERAL; + mode = DWC3_GCTL_PRTCAP_DEVICE; + } dwc3_role_switch.fwnode = dev_fwnode(dwc->dev); dwc3_role_switch.set = dwc3_usb_role_switch_set; dwc3_role_switch.get = dwc3_usb_role_switch_get;