From patchwork Thu Dec 12 01:42:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 181373 Delivered-To: patches@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp280329ile; Wed, 11 Dec 2019 17:42:37 -0800 (PST) X-Received: by 2002:a63:4b24:: with SMTP id y36mr7642384pga.176.1576114957360; Wed, 11 Dec 2019 17:42:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576114957; cv=none; d=google.com; s=arc-20160816; b=Bfefm1VZuqwHlKqDfu7DwwSi1Q4AD4Kpu6q7F22UdYUJDCGLIZ+oef9MHBLe95v+zq DGYY1N1TzetXE5C345S31XC7qj4mft/aNLpIv2LtKj4aaG4qtNrVyY2XR6ADBZSu1/h4 eFEk7Bgx7Z1wQH8mzIAUes59hDMvf9Mt/opv+hRU+vPyFuhotXwMgLRTZ9vRxfxRqHJY FM94kphC9VCjEIHnoTTPCXI4ovZGXEhOUBPS6ks/Ms71y+t6Qt+FJdtm/j4wc6JVpHwM CefuyTGsNfJb3QayK0sHpArxk9foPtkUe8/tEs/3oKOoJFOD8Rg21VhnKIDToXMGPibW 1drQ== 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=Ml1LjDh4MXlYnFnFE/FtxHnraLrSz8z9onh0HzsL760=; b=vvNARogKTz4AqA+/UjqPJWjLy7frhH1e6GrviB4HCTYxNySjxJK2RVgKYUWGQDlTEx c5Gd5wUkjNxYGsdNZ6uZMi+p0H49O87NC2F8EAHs3uv1QRtyR4rzJHnWkT2ODm8IbiM4 +tmVpoGHuW86JpX84c6zGISW2ufeiEgqAeS/hfFjBx1IK+Tl2nawBIJkNly/fmMRPtBO Um4Po4XL6eIP9EvuJV8H3jmhCkqboGvFmBP2zksL9mMpR/nvRKv5HCtrpFlOekl0xqy/ j3dv5INYfOGTzK3JVt7y9FBRc5qwcruqsRsBS/KyuBFDw/SFULp/DKw3wreJoWQPe3BX 3+Fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hMpTmiIn; 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 m14sor4150477pgb.52.2019.12.11.17.42.37 for (Google Transport Security); Wed, 11 Dec 2019 17:42:37 -0800 (PST) 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=hMpTmiIn; 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=Ml1LjDh4MXlYnFnFE/FtxHnraLrSz8z9onh0HzsL760=; b=hMpTmiInIBymA2Q22Jm1fo58ppcLh0yU84O6ZMaompS+uew7ESCc6RQ/Z+KExCCCeq 1OIAAeu41gf7hcC+ncpsq/RBaqmO4vNJYxNNWcXIx6X0TmrcqevlJsSnOSjAKus/7P1K rovkRah8SrYcnnymkRABNxuseu+5fOqmI3Hhp7Gk8gJ25SCA4MANpT7auNqELLLs9ytW LdBssxJwlThBIAhGQ8iHaRonxhWYpSOTZbGBXZ7k8istps/jXfocrwu3lJD5Bzi1bCPo 4LGqtBYHvB1IBEVKpYB8OEplt6O/hkn1Mtgzi4FPhIi2MpNnazl/XsV6vjD6zUds3zSl AngQ== 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=Ml1LjDh4MXlYnFnFE/FtxHnraLrSz8z9onh0HzsL760=; b=PV3zF/mSWZEv+KfBoNQ86GKSyL3hi4X/vayDqkFu9ZRRm2l7kZbKWNR9zimubEGSVF a5feGxY6g4chPYY0654bH8i8hz54JbKP2qw7ormrH+TqMY07NyBnPR1W8Wnl+N/2kYEA KupkMIJmOZcBzBaTQkXYtx1V2MVfKvddTXV9TVFTJagcV6JZvNzj/dvx6FKB7L191eZA 4g4e5ASARHpeVnBuHmvbAFKHBvt6PknROOcgiXnCfwOc03Kp/xPfL/BJ6BYpKDD+p8qR 0FmFqjkwoTIV8KuH97mbvZEhKTrHyHrBmCciOA/zKJRIM4ntwhKvE4qBPQ2RNmalIQB0 HMAg== X-Gm-Message-State: APjAAAUSmfzGeX0a3DArtxwazR6sg/2luAUPFyVziVBB5+EH1E9aCPC/ UR/SdhmQom3dqUtvdG8fG2a1qwUQ X-Google-Smtp-Source: APXvYqxHjCHCFrFsgxnWqrYumB5psG22m+Be/hnjF4m6nET2BX6Fx5pTV4teAFcB6L2y+7CzAlmjZg== X-Received: by 2002:a63:d62:: with SMTP id 34mr7941909pgn.268.1576114956964; Wed, 11 Dec 2019 17:42:36 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id p16sm4217996pgi.50.2019.12.11.17.42.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2019 17:42:36 -0800 (PST) From: John Stultz To: lkml Cc: Yu Chen , Greg Kroah-Hartman , Rob Herring , Mark Rutland , ShuFan Lee , Heikki Krogerus , Suzuki K Poulose , Chunfeng Yun , Felipe Balbi , Hans de Goede , Andy Shevchenko , Jun Li , Valentin Schneider , Guillaume Gardet , Jack Pham , linux-usb@vger.kernel.org, devicetree@vger.kernel.org, John Stultz Subject: [PATCH v7 1/8] usb: dwc3: Registering a role switch in the DRD code. Date: Thu, 12 Dec 2019 01:42:26 +0000 Message-Id: <20191212014233.32799-2-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191212014233.32799-1-john.stultz@linaro.org> References: <20191212014233.32799-1-john.stultz@linaro.org> From: Yu Chen The Type-C drivers use USB role switch API to inform the system about the negotiated data role, so registering a role switch in the DRD code in order to support platforms with USB Type-C connectors. 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: Guillaume Gardet Cc: Jack Pham Cc: linux-usb@vger.kernel.org Cc: devicetree@vger.kernel.org Suggested-by: Heikki Krogerus Signed-off-by: Yu Chen Signed-off-by: John Stultz --- v2: Fix role_sw and role_switch_default_mode descriptions as reported by kbuild test robot v3: Split out the role-switch-default-host logic into its own patch v5: Drop selecting CONFIG_USB_ROLE_SWITCH & ifdef dependent code v6: Fix build issue Reported-by: kbuild test robot v7: Minor fix for CONFIG_USB_ROLE_SWITCH=m case not building the role switch handling code, reported by Guillaume Gardet --- drivers/usb/dwc3/core.h | 3 ++ drivers/usb/dwc3/drd.c | 77 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 79 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 1c8b349379af..6f19e9891767 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -951,6 +952,7 @@ struct dwc3_scratchpad_array { * @hsphy_mode: UTMI phy mode, one of following: * - USBPHY_INTERFACE_MODE_UTMI * - USBPHY_INTERFACE_MODE_UTMIW + * @role_sw: usb_role_switch handle * @usb2_phy: pointer to USB2 PHY * @usb3_phy: pointer to USB3 PHY * @usb2_generic_phy: pointer to USB2 PHY @@ -1084,6 +1086,7 @@ struct dwc3 { struct extcon_dev *edev; struct notifier_block edev_nb; enum usb_phy_interface hsphy_mode; + struct usb_role_switch *role_sw; u32 fladj; u32 irq_gadget; diff --git a/drivers/usb/dwc3/drd.c b/drivers/usb/dwc3/drd.c index c946d64142ad..331c6e997f0c 100644 --- a/drivers/usb/dwc3/drd.c +++ b/drivers/usb/dwc3/drd.c @@ -476,6 +476,73 @@ static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc) return edev; } +#if IS_ENABLED(CONFIG_USB_ROLE_SWITCH) +#define ROLE_SWITCH 1 +static int dwc3_usb_role_switch_set(struct device *dev, enum usb_role role) +{ + struct dwc3 *dwc = dev_get_drvdata(dev); + u32 mode; + + switch (role) { + case USB_ROLE_HOST: + mode = DWC3_GCTL_PRTCAP_HOST; + break; + case USB_ROLE_DEVICE: + mode = DWC3_GCTL_PRTCAP_DEVICE; + break; + default: + mode = DWC3_GCTL_PRTCAP_DEVICE; + break; + } + + dwc3_set_mode(dwc, mode); + return 0; +} + +static enum usb_role dwc3_usb_role_switch_get(struct device *dev) +{ + struct dwc3 *dwc = dev_get_drvdata(dev); + unsigned long flags; + enum usb_role role; + + spin_lock_irqsave(&dwc->lock, flags); + switch (dwc->current_dr_role) { + case DWC3_GCTL_PRTCAP_HOST: + role = USB_ROLE_HOST; + break; + case DWC3_GCTL_PRTCAP_DEVICE: + role = USB_ROLE_DEVICE; + break; + case DWC3_GCTL_PRTCAP_OTG: + role = dwc->current_otg_role; + break; + default: + role = USB_ROLE_DEVICE; + break; + } + spin_unlock_irqrestore(&dwc->lock, flags); + return role; +} + +static int dwc3_setup_role_switch(struct dwc3 *dwc) +{ + struct usb_role_switch_desc dwc3_role_switch = {NULL}; + + 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; + dwc->role_sw = usb_role_switch_register(dwc->dev, &dwc3_role_switch); + if (IS_ERR(dwc->role_sw)) + return PTR_ERR(dwc->role_sw); + + dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE); + return 0; +} +#else +#define ROLE_SWITCH 0 +#define dwc3_setup_role_switch(x) 0 +#endif + int dwc3_drd_init(struct dwc3 *dwc) { int ret, irq; @@ -484,7 +551,12 @@ int dwc3_drd_init(struct dwc3 *dwc) if (IS_ERR(dwc->edev)) return PTR_ERR(dwc->edev); - if (dwc->edev) { + if (ROLE_SWITCH && + device_property_read_bool(dwc->dev, "usb-role-switch")) { + ret = dwc3_setup_role_switch(dwc); + if (ret < 0) + return ret; + } else if (dwc->edev) { dwc->edev_nb.notifier_call = dwc3_drd_notifier; ret = extcon_register_notifier(dwc->edev, EXTCON_USB_HOST, &dwc->edev_nb); @@ -531,6 +603,9 @@ void dwc3_drd_exit(struct dwc3 *dwc) { unsigned long flags; + if (dwc->role_sw) + usb_role_switch_unregister(dwc->role_sw); + if (dwc->edev) extcon_unregister_notifier(dwc->edev, EXTCON_USB_HOST, &dwc->edev_nb); From patchwork Thu Dec 12 01:42:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 181374 Delivered-To: patches@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp280350ile; Wed, 11 Dec 2019 17:42:38 -0800 (PST) X-Received: by 2002:a62:4d87:: with SMTP id a129mr7097886pfb.116.1576114958579; Wed, 11 Dec 2019 17:42:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576114958; cv=none; d=google.com; s=arc-20160816; b=jocGYdAx2I5XpuJYQWU+UVXB3KzE+Tw7fr3VZ7yIOJmBtrlj9Cc081bA4omRjIL2BN meZdho0/NHdwhtUGqblP0eOXX1EY9xB4KjzWlsgHxdnzbUNgcuEdJXu+VCViBac3gbvI +ZBg/iCXgFsshsmUasIQlCx/lIgpr7x/nYnn8MSXFHzcznE0lciBOvcTwpayppdjXzWG /sx9bIhe4nxE9ytxOUYpZv0woDBd9dyBKQHaQyfbhOCzgnXditaRecsUrhzYvM57Rh4o fvTjZW6oEZOhVMinKHRUT4bjZtag5CqmtswTZZhHfFZtXmPWZastllSUq3FAVLGBrfLK gUmg== 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=X9Kc7R9+KeUY27tDEV+sMDYPQg0vMU8CdEEpsw9B7eY=; b=AaHJm/THV0aefs96jJ5NyP8+YCoaIbNstqkBbe9NpLESeeuUjW7ZK9SVx2h9zfINcH kI+mxLd+LmaaDt2DgbErf/cM7NIdoSVpQ396QKupC+rb7CNE/9c8OdI/ZloDgN95wWjf j87sjDc3Bsr7NKCmFhBkTC3MJ8yI6BhlMCjRTDrNAiMZt35HKfwRHbawiIwVwizCnHeQ XAG6FOup9nz76UIM48Fh/ZL39MeCzjJWyWyJTr6MB9yL45CbUDaLneRF1g5FxaPOTX+7 jsHwagHr3KhptfxPiSTUO+f7gKjW6aY2ndCD95GW2LkRt/1gb5/tgS7xVvNAMOeGMIBA uHJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=V0PrWbfK; 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 s7sor4905700pfe.61.2019.12.11.17.42.38 for (Google Transport Security); Wed, 11 Dec 2019 17:42:38 -0800 (PST) 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=V0PrWbfK; 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=X9Kc7R9+KeUY27tDEV+sMDYPQg0vMU8CdEEpsw9B7eY=; b=V0PrWbfKF6yh5jnUesdINqEzgHzMsX3X/h8mQRQt7abSsm8BD1zIM3mTyuJAm4y3kP fjCqZ+MT657YUqC5fFq+USYJQkg/nwLbiZzbLc1ZZ/+AH1ZY2o/P7I/ogmVWFT2eoKVD VvmvB8Nw8+/gE6DnMtNB+4sghteYtNdFYbeM6Q+B1VJiUIlyNXEbJbs1yHD/dUMged95 pH+vBbrBuz/G5kKvVuB1H/0Z3wWaXELPX8OJC9XBveAInCMPrFPLT1Ygauyjsf5HBtMl 4jvvIt4F9HQcgkLnmCLBWh5/bnO15j/5DUAR1SOnmrY3lzfgR/SF7SyOLeNBzoM7XasI kbWQ== 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=X9Kc7R9+KeUY27tDEV+sMDYPQg0vMU8CdEEpsw9B7eY=; b=XCuSS1lmONv25RY6OxvKxspIUB0gYs9SsS0kor9ISSJZkvRhPq2mUwrFaBKZBl4/oN oWcSwHmnoN0dcz5HzgQT8Ai4gjdZw/CJpqEDh32o67poiTjdXCL1eNKM1DKkUFY/Vkgg gDlf6BM75JPdtn5ubmQ3UlvoyDPrb5Jrrg/CYSpTjLQYhzOZTZAVzVikstHGLIvCj+5Q EzOVFtSHXAMMZul0/bjWcsj88GWTbB6ESkdgrSrT6DwmUgSiGe2Pz+31wA0O5gBCDjLD mnWsobXVYmVecTc+3GrgiZbqim8ySd1QP4/k2RNosBO2WY4QPufvcZGZnzltlDyPVAn5 vWtw== X-Gm-Message-State: APjAAAVPCNdCCiAZzPk08j4q72PWisvalH1YrYgta5H+f5tNjbt+vh4u MdwNYuY4FDKbsFc5JYkD2MYmR1+W X-Google-Smtp-Source: APXvYqy0BVmYHRBfzJOVdXEzf35ykOhMUK6HJkBTVjdR49V2P5zoAJ4NwvOkopcghcK3+EabZw/nPQ== X-Received: by 2002:a62:f842:: with SMTP id c2mr7196663pfm.104.1576114958243; Wed, 11 Dec 2019 17:42:38 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id p16sm4217996pgi.50.2019.12.11.17.42.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2019 17:42:37 -0800 (PST) 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 , Guillaume Gardet , Jack Pham , linux-usb@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v7 2/8] dt-bindings: usb: generic: Add role-switch-default-mode binding Date: Thu, 12 Dec 2019 01:42:27 +0000 Message-Id: <20191212014233.32799-3-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191212014233.32799-1-john.stultz@linaro.org> References: <20191212014233.32799-1-john.stultz@linaro.org> Add binding to configure the default role the controller assumes is host mode when the usb role is USB_ROLE_NONE. 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: Guillaume Gardet Cc: Jack Pham Cc: linux-usb@vger.kernel.org Cc: devicetree@vger.kernel.org Reviewed-by: Rob Herring Signed-off-by: John Stultz --- v5: Switch to string rather then a bool --- Documentation/devicetree/bindings/usb/generic.txt | 6 ++++++ 1 file changed, 6 insertions(+) -- 2.17.1 diff --git a/Documentation/devicetree/bindings/usb/generic.txt b/Documentation/devicetree/bindings/usb/generic.txt index cf5a1ad456e6..dd733fa81fad 100644 --- a/Documentation/devicetree/bindings/usb/generic.txt +++ b/Documentation/devicetree/bindings/usb/generic.txt @@ -34,6 +34,12 @@ Optional properties: the USB data role (USB host or USB device) for a given USB connector, such as Type-C, Type-B(micro). see connector/usb-connector.txt. + - role-switch-default-mode: indicating if usb-role-switch is enabled, the + device default operation mode of controller while usb + role is USB_ROLE_NONE. Valid arguments are "host" and + "peripheral". Defaults to "peripheral" if not + specified. + This is an attribute to a USB controller such as: From patchwork Thu Dec 12 01:42:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 181375 Delivered-To: patches@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp280365ile; Wed, 11 Dec 2019 17:42:39 -0800 (PST) X-Received: by 2002:a62:b402:: with SMTP id h2mr7055884pfn.55.1576114959668; Wed, 11 Dec 2019 17:42:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576114959; cv=none; d=google.com; s=arc-20160816; b=0ANx2ihVmHCafxNYog+v/FGaZnGfrfDwIFcfeOUh+A2YspPJlz2mLsK3j/BVkkB2pX q8XJM/ml3xyQkaVQtt3jxAXTO4zDlB8kURZUqOl7klijfz5bv6QAt5chjNco0xvWsMvj J3Y83ox5W0aKkEGefYrXETtxS0yAt1eU0nNh0Qd3eWUieJM9EAIsjFiuHypisfcMeJ98 k3I9gZpOh6lSvTvtWnam7CAHwjQYwhK7SQXRK1kMtBrgH6+OGOGq5Y6XMDGRoMCS1Pbs h6VvjNHBhd6wgKmZFk9i4qM+HSCDYYzJReqjwKInTV/YFtUOZmemHnS9X0nJFTARSo06 EV5A== 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=32ma7jm/USpVtHg7Ie1n8hF+znRzdCi92DyYoi4rfjo=; b=uqsu+jobEEyQZfUbvuBcIi3jU51n+J0mvTdEG+Ughuss9GlvJZ99lX4V4H3hQQ0wOK P2asr3UWmf5llII7VYhPOxWhqnSm6kUWBa6qiAIAAaCe1tgWs/iBWyqOd/qhnz1Jpc6Q jvoCF56SKY9bU7SE75vaq1vaO531acffkx4CPeKCGY4uoz2IMqBi2DqAvqFdUdwv3ylb r3p6boqqjGpCC0muGX3p56N9QaHk7WIWDIQsLK3CylsvYJTA9CXSizuIrOVVmRZgClJ2 GEZoWuX99R5w6RWv7PhiX+BaCkpOWKpnfMOIsHx6P0DVzRZzzc13o5JvOBY1gR4Fs+c6 wV9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=m+mTiQrt; 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 o3sor4447535plk.35.2019.12.11.17.42.39 for (Google Transport Security); Wed, 11 Dec 2019 17:42:39 -0800 (PST) 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=m+mTiQrt; 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=32ma7jm/USpVtHg7Ie1n8hF+znRzdCi92DyYoi4rfjo=; b=m+mTiQrtpDWGf8kluPe58Em+efx6c+lCdtucq14oYvmCpsKuuTM8BUXaasXe14TZYn H6Tnrvxy9hRKBqwKqGUVUHcktLAxzgl9bnPjC8dOQLAG3TIGOMTMTPOJlsQX82RKIZYF 85UTwtwfUMAhZO3fAj9PeUoGJnIbRz8p0F/qD4JkkvXymwEMZpMxeoE2fIoC6Uhehbol gpfVQ/T/xagGQllRGVpT0qupuDtYnGHiin1ia/ZG0K7GT7qJtCqlNxw4hmwts5Cxw1uM o7ZzXtR961PKot2SEb2q/gyGr3a+13GlAP7UAD8VjGNexQXecbDhcglCwtYzWsp+2s2g RC0A== 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=32ma7jm/USpVtHg7Ie1n8hF+znRzdCi92DyYoi4rfjo=; b=eq2dSgdONiO8iSMhtoF3AWyPyURiDzMIASWDk4nQUBOMNz0eruRQDLmRH53fqLlbd7 isbNKvFWRksBN3GWt58MOezcaubMHKWvcPJSfTQFaMRYA3EF+zDPqQpFBFnouZsm7q1P dKzIq6CJxc7qzlvkz/c/AnxnqU9Qr1RXuV9Abpq+j/gHCga7lUrKV5D4hPdZ3iMQ9QF1 0SxeoDVfUV2QTgjdlStHfQVHWxvsLoIIhLf1sIc6tfsqvU8QKvJ0sl7z5iQ1V17t4ymc UzK0NzgG9pY94BzEkdIsoz/AAhJMQGROnAvtZJ9pi1U1HPT+8WeQnkP27Eb4pFEuzTE0 JL2A== X-Gm-Message-State: APjAAAVdGQ9YUdKWeKftQnnX466O5a/yJYEqKjIXxkARsywo+hxE1TmM V6NyetLOSF/WgbvMEdMXSf5MiQns X-Google-Smtp-Source: APXvYqxwMBPmGhcRAfOeLiir9tLLli4TVTdqLolBlxPaPpfE7Ngtm6Agj9aoLb0yUwDUnflxYeyX5g== X-Received: by 2002:a17:902:d204:: with SMTP id t4mr6880334ply.167.1576114959256; Wed, 11 Dec 2019 17:42:39 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id p16sm4217996pgi.50.2019.12.11.17.42.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2019 17:42:38 -0800 (PST) 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 , Guillaume Gardet , Jack Pham , linux-usb@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v7 3/8] usb: dwc3: Add support for role-switch-default-mode binding Date: Thu, 12 Dec 2019 01:42:28 +0000 Message-Id: <20191212014233.32799-4-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191212014233.32799-1-john.stultz@linaro.org> References: <20191212014233.32799-1-john.stultz@linaro.org> Support the new role-switch-default-mode binding for configuring the default role the controller assumes as 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: Guillaume Gardet 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 v5: Reworked to use string based role-switch-default-mode --- drivers/usb/dwc3/core.h | 3 +++ drivers/usb/dwc3/drd.c | 25 ++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 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 331c6e997f0c..db68d48c2267 100644 --- a/drivers/usb/dwc3/drd.c +++ b/drivers/usb/dwc3/drd.c @@ -491,7 +491,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; } @@ -517,7 +520,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); @@ -527,6 +533,19 @@ static enum usb_role dwc3_usb_role_switch_get(struct device *dev) static int dwc3_setup_role_switch(struct dwc3 *dwc) { struct usb_role_switch_desc dwc3_role_switch = {NULL}; + const char *str; + u32 mode; + int ret; + + ret = device_property_read_string(dwc->dev, "role-switch-default-mode", + &str); + if (ret >= 0 && !strncmp(str, "host", strlen("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; @@ -535,7 +554,7 @@ static int dwc3_setup_role_switch(struct dwc3 *dwc) if (IS_ERR(dwc->role_sw)) return PTR_ERR(dwc->role_sw); - dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE); + dwc3_set_mode(dwc, mode); return 0; } #else From patchwork Thu Dec 12 01:42:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 181376 Delivered-To: patches@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp280386ile; Wed, 11 Dec 2019 17:42:41 -0800 (PST) X-Received: by 2002:a17:90b:8d6:: with SMTP id ds22mr7192936pjb.100.1576114961058; Wed, 11 Dec 2019 17:42:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576114961; cv=none; d=google.com; s=arc-20160816; b=M40mhA+pysCFdA+AZOwDJ0rDymWHUWrqxWW08PvilOripJrBpwIfceXW11IR1EEIwH scGVR1tDQLpKr+K/3c8EwvX5/H7OCSmBIxFeL7g9Gnfs0QMUEWTRfWlAugmpe/aAcYxm rNoUv/GGekzERIC4AB+f8SEnL2d8rer3DGmfquS6q8lPjUQJzgUF0SjonfAVs+szWFd9 r34FfZhT4Rse+Y8+i/o1Lt2I3InmfTwxRjJN4KaxxjWC8WAbIZQ2UWLRaF6oU3iz0kl8 WA6EpiJzKXD3B5i7+6KlwThAoZYIskhATaYCfGU+1w6WNmHmt5SMtchqtTPuhKjcF11o dTXQ== 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=jz3XZ9gPuD/g+1P6LY7Aq8wTOFKwQIrTyqi7Mx3AGIU=; b=pl2SZJSaFyiGtEhHc4v+uD9NZrqP/qaMtH0aClmKUa1dDT0Y4S0EmCd5Eu4684X7Nj M9bpPhhg3XPj7eotbLBF/+jkxo199deU2eO9T/kxB7asXiBcltloQ2/fYFWxW3Md+Tlb rn/vfqdpivcYF7H2b05ItZD8nNsdHZpicRStFAr5XkKbkqE8pTjZ5uHwR5W87Isrh+mT mtDCEf5x6E0ZICJSibW++50LKsKqqsgOlN05mV8jdyc6ezt/LqcHDxjZuddICzfbNpSi HjyajvjJxVg0s61+dR2QUL4eu2VMvBnN9KODwDhGZl1uYh4uu1smlFuD11qxBSC6Fiop WNRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ADWf++LN; 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 r4sor4440969plo.60.2019.12.11.17.42.40 for (Google Transport Security); Wed, 11 Dec 2019 17:42:41 -0800 (PST) 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=ADWf++LN; 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=jz3XZ9gPuD/g+1P6LY7Aq8wTOFKwQIrTyqi7Mx3AGIU=; b=ADWf++LNikL2sGcTcPh38acVlVtjYE212k4TEnvD+Rlztp08dFU+PiVdolU95yghh6 if+zoAeLlhz35y8sJOpcVWTpgCkbiTRdT7UVFZ8NunPzp3KQLHiuLU72mrPDlXlgSFzF Qg76tZUqRmSr54W87h1n0CZgA6NFZHf0PBE/vqGlb5jKzdYrpuWrOVyOJEBBJG/+wKbG AjkTYbw+imyPgYY5IOoJieUH9yT/QpO6cub+CG/cQiNynfS9eC9OgqL54UdE51EvzMYi I1BjdPjZYGckxWevF0rkr1EtzpTBv6ZZjAcidkSpzf8uiRC9c/6TSiuLBHGL6on42fkM pptw== 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=jz3XZ9gPuD/g+1P6LY7Aq8wTOFKwQIrTyqi7Mx3AGIU=; b=pPOG2XKUEDdRNOt/dfKI9QRuIAPes89o0F0U+dDTSoBZYdmeppjZHCTYFszlH0E2rH tPvEp6PSrqf5m5L/DAtu1+4tqvIGj1Em9b8JGQYEzFRz3TKD2Wd0+L7i7NNWhE0/n6Hh P6Sdqm2ZsqIANU+GYtGm0d4Ts1Ldoovm32ieqkDGakXxQyOqwyZcvTs66iyrPmJLBnrm /jdAF+Lmr9EQ3Wae9TS0lEzUly2uFMNP0Hf4zeISStZuHdQNiyeg6FegqqxgE6yNISSv Gq+7GBQT20K/pYL82P1lXoRMTIfUzZ4IOQyJZBCppwqSZZMFHIQKLPmnDikC55A5lE6t ALAA== X-Gm-Message-State: APjAAAU0n0JpOfUPUxniOaKYxdo06KET1IbzNFTPcUS6sawEXBjKi6du XC1WNq3wcfqDQwWPTTkyCZt0ki/w X-Google-Smtp-Source: APXvYqz745Iom7BCnhPJbNjWnLV0N315h5uwmC47BUMzZV6zx6EdHy7BP/H0GGZcWSHDGlWW5rf7jA== X-Received: by 2002:a17:902:8608:: with SMTP id f8mr6851979plo.106.1576114960549; Wed, 11 Dec 2019 17:42:40 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id p16sm4217996pgi.50.2019.12.11.17.42.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2019 17:42:39 -0800 (PST) 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 , Guillaume Gardet , Jack Pham , linux-usb@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v7 4/8] dt-bindings: usb: dwc3: Allow clock list & resets to be more flexible Date: Thu, 12 Dec 2019 01:42:29 +0000 Message-Id: <20191212014233.32799-5-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191212014233.32799-1-john.stultz@linaro.org> References: <20191212014233.32799-1-john.stultz@linaro.org> Rather then adding another device specific binding to support hikey960, Rob Herring suggested we expand the current dwc3 binding to allow for variable numbers of clocks and resets. 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: Guillaume Gardet Cc: Jack Pham Cc: linux-usb@vger.kernel.org Cc: devicetree@vger.kernel.org Suggested-by: Rob Herring Reviewed-by: Rob Herring Signed-off-by: John Stultz --- Documentation/devicetree/bindings/usb/dwc3.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) -- 2.17.1 diff --git a/Documentation/devicetree/bindings/usb/dwc3.txt b/Documentation/devicetree/bindings/usb/dwc3.txt index 66780a47ad85..29768b0ca923 100644 --- a/Documentation/devicetree/bindings/usb/dwc3.txt +++ b/Documentation/devicetree/bindings/usb/dwc3.txt @@ -7,7 +7,8 @@ Required properties: - compatible: must be "snps,dwc3" - reg : Address and length of the register set for the device - interrupts: Interrupts used by the dwc3 controller. - - clock-names: should contain "ref", "bus_early", "suspend" + - clock-names: list of clock names. Ideally should be "ref", + "bus_early", "suspend" but may be less or more. - clocks: list of phandle and clock specifier pairs corresponding to entries in the clock-names property. @@ -36,7 +37,7 @@ Optional properties: - phys: from the *Generic PHY* bindings - phy-names: from the *Generic PHY* bindings; supported names are "usb2-phy" or "usb3-phy". - - resets: a single pair of phandle and reset specifier + - resets: set of phandle and reset specifier pairs - snps,usb2-lpm-disable: indicate if we don't want to enable USB2 HW LPM - snps,usb3_lpm_capable: determines if platform is USB3 LPM capable - snps,dis-start-transfer-quirk: when set, disable isoc START TRANSFER command From patchwork Thu Dec 12 01:42:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 181377 Delivered-To: patches@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp280401ile; Wed, 11 Dec 2019 17:42:42 -0800 (PST) X-Received: by 2002:a17:902:9a49:: with SMTP id x9mr6595149plv.331.1576114962000; Wed, 11 Dec 2019 17:42:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576114961; cv=none; d=google.com; s=arc-20160816; b=gDztEpQGdWmf1D4dwcEmUEk4dfFUqkdXIBilSn1G6eRiyF73LqFg19pW2ChKFdPdXC /zOoUGlkaXz1+32sn2BNZ4lx4VKqrn94FiJP6c6slNYaZtzsqZ6K7bN0TPamLjTX+xiR 6SBYw8i6RzaCSP85UCDUAlARx4OXEgj8rMQcZcMegDcS2fvbI9c8O4yhv4zYSDXkQC++ IAw8OAvo9UuKTW5b7Qb4IjX78tZUspJf3Rva0q+ISUWro6V7UB4Zh6wj7H2szKFUVU0y ljw6ZUfqA0CR5cO2+1UVwR+ceGDc+q2pc6xD3JLYTeZ2Xg2JW66QTqmSgTBYokvykBdI TlcA== 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=G6kjJoovlC6cVfetXCubnmxNfzySZyzH70fmpOskqm8=; b=ajTRqGqYXdW+uM88N+PqTCNdvrikDJQQ/dLhoG9s68t+JPiCww++FbFMQOAoaTF+Cp 5oVCuP++N2P7r0pe9xYOcsG0l0fZZf7km6oYEAEufF3f8QxqaYXuwNZLUSf9GHbcuJrV D0KJXMNpcm/uWfMd89Z5rvnDn3zvq4hkahD2EsCBTBp3tLss5Gq3qEMaCcfHUBzhPcXS rP6QkBnvOusFmN366Ydv3H1OPEhgryuuo9z5omVVXpeeXOs0li9gwRHs2mzp3tHCwQ1z GsMYhKAVszs4TqLNn2cUrEQJcQs74bEC33rUEOtMkrUJG7Cejb2Zlq8xiN5NtJtu/fhb oS8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cGOZzqU1; 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 e190sor4968288pfe.32.2019.12.11.17.42.41 for (Google Transport Security); Wed, 11 Dec 2019 17:42:41 -0800 (PST) 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=cGOZzqU1; 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=G6kjJoovlC6cVfetXCubnmxNfzySZyzH70fmpOskqm8=; b=cGOZzqU13JOBPam+xdKigkTIGiAjbtkPvBYtjMIcRGUuLi4JiP7MUinvcn6DCHl3if FfTvBb4dk8U5AMVmF2CjA3dX++wBfx3pTTGhYpwAXjF+gVP7q2lyOJ71aGuUEDGgLDk+ TMnP3JbWjTdAvowKhz6F66lifrsJQu8cJUerpX+PE5lpkYRjgLc7ZYnOaB5FZFDeXZLZ 4XTD82pAK9BsC4PJHfrpswrG46E7SuRpdj1/clKJtXJ/dD0FqdjFwSmynLis5GtK1lV7 /4QvRxBrdkNP0ceSSZ49Ot9qJNQWbR+IUoA7OE66lecnIgheFt5rQQ4O7VaQtW+J/H3+ w9Gw== 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=G6kjJoovlC6cVfetXCubnmxNfzySZyzH70fmpOskqm8=; b=Iw82u+SE1ljWIzONknlKib5FQFEODRHUX1SxqmyApVZoYUAsxDwlw5KbWnRW0MWsBr YZcUyhu/R7lWghotUlibPGR/Yeu4MAi0O1tlFEPx8NnORznPjRollQvmKlS9gULEIiyN kGAzPi2MxZtHSgo+aKriWf3HoUEjNA9hxInPNmYrKERYmi3Grm7dtfpZmJNKm076IqTG sTrCN74tqQ6ICkEnXEbk24Zn/YGsEqCpACnCrR4FR3NBxVVjfsQSWwPbLSOcx19BCtgA kzLHvcGnbdEzFjJCtncFGXTJgcriYTXv3OmoVkTOn+8FfA87Ybmr04FyOZ2CDn4NW0EV Xhdw== X-Gm-Message-State: APjAAAXImB4psE60RZ8oP844/Mb0NFLP62N6lBh/kBrjSviCUIvdViZZ GKDY1UCbU+m/PuCA+MQJDdrJCQ+C X-Google-Smtp-Source: APXvYqwpqM70vNZbKae/RwdZ2CYgbgIkvtbmpvMV4ONBua+4aE8gJ9REa97neloI95Wm/o50zRSkzw== X-Received: by 2002:a62:1a97:: with SMTP id a145mr7398556pfa.244.1576114961674; Wed, 11 Dec 2019 17:42:41 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id p16sm4217996pgi.50.2019.12.11.17.42.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2019 17:42:41 -0800 (PST) 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 , Guillaume Gardet , Jack Pham , linux-usb@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v7 5/8] usb: dwc3: Rework clock initialization to be more flexible Date: Thu, 12 Dec 2019 01:42:30 +0000 Message-Id: <20191212014233.32799-6-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191212014233.32799-1-john.stultz@linaro.org> References: <20191212014233.32799-1-john.stultz@linaro.org> The dwc3 core binding specifies three clocks: ref, bus_early, and suspend which are all controlled in the driver together. However some variants of the hardware my not have all three clks, or some may have more. Usually this was handled by using the dwc3-of-simple glue driver, but that resulted in a proliferation of bindings for for every variant, when the only difference was the clocks and resets lists. So this patch reworks the reading of the clks from the dts to use devm_clk_bulk_get_all() will will fetch all the clocks specified in the dts together. This patch was recommended by Rob Herring as an alternative to creating multiple bindings for each variant of hardware. 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: Guillaume Gardet Cc: Jack Pham Cc: linux-usb@vger.kernel.org Cc: devicetree@vger.kernel.org Suggested-by: Rob Herring Signed-off-by: John Stultz --- v3: Rework dwc3 core rather then adding another dwc-of-simple binding. v6: Re-introduce this patch, on Rob's suggestion --- drivers/usb/dwc3/core.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) -- 2.17.1 diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index f561c6c9e8a9..c6316d4b7593 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -289,12 +289,6 @@ static int dwc3_core_soft_reset(struct dwc3 *dwc) return 0; } -static const struct clk_bulk_data dwc3_core_clks[] = { - { .id = "ref" }, - { .id = "bus_early" }, - { .id = "suspend" }, -}; - /* * dwc3_frame_length_adjustment - Adjusts frame length if required * @dwc3: Pointer to our controller context structure @@ -1438,11 +1432,6 @@ static int dwc3_probe(struct platform_device *pdev) if (!dwc) return -ENOMEM; - dwc->clks = devm_kmemdup(dev, dwc3_core_clks, sizeof(dwc3_core_clks), - GFP_KERNEL); - if (!dwc->clks) - return -ENOMEM; - dwc->dev = dev; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); @@ -1478,17 +1467,18 @@ static int dwc3_probe(struct platform_device *pdev) return PTR_ERR(dwc->reset); if (dev->of_node) { - dwc->num_clks = ARRAY_SIZE(dwc3_core_clks); - - ret = devm_clk_bulk_get(dev, dwc->num_clks, dwc->clks); + ret = devm_clk_bulk_get_all(dev, &dwc->clks); if (ret == -EPROBE_DEFER) return ret; /* * Clocks are optional, but new DT platforms should support all * clocks as required by the DT-binding. */ - if (ret) + if (ret < 0) dwc->num_clks = 0; + else + dwc->num_clks = ret; + } ret = reset_control_deassert(dwc->reset); From patchwork Thu Dec 12 01:42:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 181378 Delivered-To: patches@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp280417ile; Wed, 11 Dec 2019 17:42:43 -0800 (PST) X-Received: by 2002:a63:c250:: with SMTP id l16mr7457684pgg.38.1576114963150; Wed, 11 Dec 2019 17:42:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576114963; cv=none; d=google.com; s=arc-20160816; b=WjEUrlsZiHzPaaL1yYs/M+t0WPcx1kL1s3B9QRDQgdpfksyXvFNksy1ol4GpgP6lwZ /GHo+zNXLkrrhCQlq7h2Mkx6JM2BXkCriDqbgIJ7IOxy0woRF0feSX3q7Qn+I7oU8kA3 wsD66oZI0FLpd3XetXIJk4evyRDjLmbyd3FNYtVr7DD/Kn4W3qtKRXYVLuoMTZ9CPWjE SU5EiIAAtR3mmm8NGuDokuTTMEzs1XsTWE8F7HGk03bvlTW4QA3llPwfy2DOgH0a5wIW 2mq6mj8vDaQKFXxpd0/VHjQBJ4VOVuXYE60s/2piPoRkchHa7ObAVbW/1oHj/vSyzqPD CTzA== 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=lzv7sY1flH0+P+bTRde+D/HgFmOOUcTmct5WYnIY1iE=; b=vFhKshyJHAvaavHvX2rQIvpx/ohDUu7np9R1STpXVEgm2eJ85A52dVcF4ClEvw26Ey 3iRajj4/s5TwesV4wfuEGRkKysphucpKPT4Hn4kMQ37xgockMjbfwJHA+f1l/4wovNnU AIDPJdq9jLf0TCQo1VFLC9U6+uHSO3yzp+5dFnXYkAktwtQY02l0ANnoMK8SBwNsbdsO XStAgalDnlw9q9pVnkF+T4PQ+JgCHVqGu286WRIaveOZaufninywvS9acW1wE5S9xw7K pT7DwHZk+cR7/W5XtfKjhfFOhtTIYkUALOyXosIKkrYScgumLN7FcfzselWeRF1f6OHm mLvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="UZw/F1Ml"; 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 91sor4546273plc.12.2019.12.11.17.42.43 for (Google Transport Security); Wed, 11 Dec 2019 17:42:43 -0800 (PST) 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="UZw/F1Ml"; 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=lzv7sY1flH0+P+bTRde+D/HgFmOOUcTmct5WYnIY1iE=; b=UZw/F1MlTuPlHpKe4kDgjY8F/v9Xiz+1gFoJAVS8UHhspGP2Fpw30FdQGna543kbZg NbdJ1yCDvKj06pyzxBU0LtWEiCOyPP2nEnN5BQp2LQPpQQh1psGtyt854LkbViLnC/lZ zz5LUJ5yIGZ2v/n8y29ac7682PdEVLzC0fdyMrtdayTHw7t725nH9/M9yyMuNfvE9asz LvvbKS5ncKH2sjpaV1y6oNpbpM55xotDt0IKntm3jKD+mR2Cbrs0sG1O55wRIIcJcdVc haJ/fBVgZw5PBDj5189st+r/ZpQMkoJcgE/UEqyhv/NtKX4ai4J9wrizbLIRKyjvs6vz 8YTw== 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=lzv7sY1flH0+P+bTRde+D/HgFmOOUcTmct5WYnIY1iE=; b=r721xurgcNW3tbcKFHhIYtmXFmrYdEy7HLko0/GfG6qwsTBi4JIMJwt6cXsL4qCL+s sQAQltoELbtVk1AT3mTjhDPoKvND8a4n+O755PEpKooLBEcTBQxOE2NS6JOEhI4cWrJW +AB3VZwrK60HJGoZGDAv32qyVPq0zQKtCXlZFb7nfJmOH3yRcNo/33vx/STJPCLNCLzk RmtuLgpMPBN5zcFPZ9Wiu0MxYby1Axe2fIVndPe5eOmyykwlRK53YHJbw4EB1eW7XrmW HmvwTcMEpGT2GW62c+ML5yliKskLQfmYzSoxjN6FA8Z5D3gS9ORMOtidALnkXoUevAue 31Fg== X-Gm-Message-State: APjAAAU4nlWDAahbtA0lh96FaCAIDpiFAIRYtAOT9N9PcX6mEaPDF/iU R4NSF4DFYTPW4rzXDiwstpWIxtK6 X-Google-Smtp-Source: APXvYqz1y2cw7lalEK+SC8etwGXhPJDXQAo5rWmg0AyCI1cAqs37h6s3jVRWoE17CI7K8C0/J8/9lQ== X-Received: by 2002:a17:902:43:: with SMTP id 61mr6924104pla.88.1576114962763; Wed, 11 Dec 2019 17:42:42 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id p16sm4217996pgi.50.2019.12.11.17.42.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2019 17:42:42 -0800 (PST) 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 , Guillaume Gardet , Jack Pham , linux-usb@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v7 6/8] usb: dwc3: Rework resets initialization to be more flexible Date: Thu, 12 Dec 2019 01:42:31 +0000 Message-Id: <20191212014233.32799-7-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191212014233.32799-1-john.stultz@linaro.org> References: <20191212014233.32799-1-john.stultz@linaro.org> The dwc3 core binding specifies one reset. However some variants of the hardware may have more. Previously this was handled by using the dwc3-of-simple glue driver, but that resulted in a proliferation of bindings for for every variant, when the only difference was the clocks and resets lists. So this patch reworks the reading of the resets to fetch all the resets specified in the dts together. This patch was recommended by Rob Herring as an alternative to creating multiple bindings for each variant of hardware. 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: Guillaume Gardet Cc: Jack Pham Cc: linux-usb@vger.kernel.org Cc: devicetree@vger.kernel.org Suggested-by: Rob Herring Signed-off-by: John Stultz --- v3: Rework dwc3 core rather then adding another dwc-of-simple binding. v6: Re-introduce this patch, on Rob's suggestion --- drivers/usb/dwc3/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.17.1 diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index c6316d4b7593..19504b907476 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -1462,7 +1462,7 @@ static int dwc3_probe(struct platform_device *pdev) dwc3_get_properties(dwc); - dwc->reset = devm_reset_control_get_optional_shared(dev, NULL); + dwc->reset = devm_reset_control_array_get(dev, true, true); if (IS_ERR(dwc->reset)) return PTR_ERR(dwc->reset); From patchwork Thu Dec 12 01:42:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 181379 Delivered-To: patches@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp280432ile; Wed, 11 Dec 2019 17:42:44 -0800 (PST) X-Received: by 2002:a63:cc02:: with SMTP id x2mr7770890pgf.114.1576114964316; Wed, 11 Dec 2019 17:42:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576114964; cv=none; d=google.com; s=arc-20160816; b=UOOvw7r+7mMCB8mXPEOwZxxlKCbfKT8G4kE5uxQ24hjsgoDQozSvrDMSvPdtVm/kq9 Y/5h8NfXUkNTiKtMc3tjX+H2ojQCAPjQvKQcQoxCaQvAYpEv1ZTsVxtD5/ufvFPtderK rfRW6U3Mf5pHSf38k0tTizeVEymL8btpVnRB+jdejOvrD3FfzmP6KtijonVCzeqVwgdZ wec1VyvDmK2yONxt3SFo+36MOnWDpSCmQoCiubL7e0G3zjcwVgQOpHIb5KnsmNtnN4Qw cvabx7GCcjLSllvtfWIJgG2DzcMzug0avZR+XLI1VMBqgxFClS+9gpjhJnpHSTCmuy2R K6NA== 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=d5IhBp23ryMELmIbYMLe3sqyK/4LNM7fr/2bl3WTuCg=; b=UvXBYzluNxpsE2Xb8UnuEK/52RSJ3L5o3nyE3Jdv3WEmWWHV2Hw3oKPtbC/V2Nm+69 cjbhveElqsuViIL0/FpeDIoxnDKnwBxh4UBVwJVhLCE1tInN2ekOFYN7LYmQ5gVHYhPi IABlWdq4lmC1GLRdrfFD66QrYaL29cpny98WoKzLapaakQ1NB8YDy74Gn0JMtNIYziCv Sy9I/jIRrdLcLM8ZcTxeQeTswcXspiQUQ51x82gQ0WypRq1gTYdbSWhDf/IjDS+KUWg/ MhI1C6CnDfSz9KWmt4XiUXWjt+SjGjOA5fDn1yczhWtH3mocMtFeG4Tj3NuwfGDGbtDw xL9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=raMTtuMO; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.41 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-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id 91sor4546329plc.12.2019.12.11.17.42.44 for (Google Transport Security); Wed, 11 Dec 2019 17:42:44 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=raMTtuMO; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.41 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=d5IhBp23ryMELmIbYMLe3sqyK/4LNM7fr/2bl3WTuCg=; b=raMTtuMOBRn5KhhTiB2f+cKZAxr9j94dux8XwBg+AdQkCEszcB2OukPcmMasMfVQ06 obOieKjaUu1K6HpjLXsqBa8lKtiiUbw9JKGzh1vTkCJR9L4im0LQY6BuNMr5ET9fqipd NbyMlxiNyOUaan4utvYpFBN4yr7w+UxPKgbkXFLyK6HxJnuutbTleFouaTh9nevPuXUQ nbIlbU5Wc6+YzMdLxUN01dtD7Z6Zs0TwmqTLfw+zQx8+mWebDDRTS93U/2fmuBPbC0Gy A9F5wrvWUQDpg+Ixnzo0cMRkcfHHIALCeLm/WJUdzdL0BkxyF7vkJgeRMyh+5iuytXHU 09Ew== 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=d5IhBp23ryMELmIbYMLe3sqyK/4LNM7fr/2bl3WTuCg=; b=DyPPm/8FEQhit1JNWT2sXdF/VvGZrmzDqcokIpeWaTaPNAuQ0DYqqGWElDgHT8lofy 0Nzq4WVgmAmilEIjLdVjevbo1LI8INkFz9iglCywSevrpIM+8Mkh9I1xrJjRd8vBZY6G 8KNm8W68e5tQA6YbPFYpRPAHsN/SWt/6R1Aq8mngjVnrPQZMYU9eW/QciU1GpoXG+n6o z8QcDxgWx1bNveelsasVNxmYlkH9cGtQ9hw+ZvexwOfFc5ES0oPomM5DksCNvyNT0UUB zT/pvJSNFLhFJ7JxEPbZGcY6Rj9rdVTTY6DnY5Ygt/SKn+HLJ2AsdRJxGb+Ib7+lkG0y XdZg== X-Gm-Message-State: APjAAAUbAtUO1AH+79O1A1HM/x5Jhok8geok/K0XwJm124QNvm2tisfO sH2qrjm5OffBVZmZh/eF7BttJvMS X-Google-Smtp-Source: APXvYqx4StIFuAQtmNTyT3ogARV1ggychWzi6oW+9zl7DfM3kHg2TvXG6rV3Qqhf7Sfk/eBtLVc2yw== X-Received: by 2002:a17:902:d883:: with SMTP id b3mr6353801plz.231.1576114963862; Wed, 11 Dec 2019 17:42:43 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id p16sm4217996pgi.50.2019.12.11.17.42.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2019 17:42:43 -0800 (PST) From: John Stultz To: lkml Cc: Yu Chen , Greg Kroah-Hartman , Rob Herring , Mark Rutland , ShuFan Lee , Heikki Krogerus , Suzuki K Poulose , Chunfeng Yun , Felipe Balbi , Hans de Goede , Andy Shevchenko , Jun Li , Valentin Schneider , Guillaume Gardet , Jack Pham , linux-usb@vger.kernel.org, devicetree@vger.kernel.org, John Stultz Subject: [PATCH v7 7/8] dt-bindings: misc: Add bindings for HiSilicon usb hub and data role switch functionality on HiKey960 Date: Thu, 12 Dec 2019 01:42:32 +0000 Message-Id: <20191212014233.32799-8-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191212014233.32799-1-john.stultz@linaro.org> References: <20191212014233.32799-1-john.stultz@linaro.org> From: Yu Chen This patch adds binding documentation to support usb hub and usb data role switch of Hisilicon HiKey960 Board. 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: Guillaume Gardet Cc: Jack Pham Cc: linux-usb@vger.kernel.org Cc: devicetree@vger.kernel.org Signed-off-by: Yu Chen Signed-off-by: John Stultz --- v3: Reworked as usb-role-switch intermediary v7: Switched over to YAML dt binding description --- .../bindings/misc/hisilicon-hikey-usb.yaml | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 Documentation/devicetree/bindings/misc/hisilicon-hikey-usb.yaml -- 2.17.1 diff --git a/Documentation/devicetree/bindings/misc/hisilicon-hikey-usb.yaml b/Documentation/devicetree/bindings/misc/hisilicon-hikey-usb.yaml new file mode 100644 index 000000000000..1fc3b198ef73 --- /dev/null +++ b/Documentation/devicetree/bindings/misc/hisilicon-hikey-usb.yaml @@ -0,0 +1,85 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +# Copyright 2019 Linaro Ltd. +%YAML 1.2 +--- +$id: "http://devicetree.org/schemas/misc/hisilicon-hikey-usb.yaml#" +$schema: "http://devicetree.org/meta-schemas/core.yaml#" + +title: HiKey960 onboard USB GPIO Hub + +maintainers: + - John Stultz + +description: | + Supports the onboard HiKey960 USB GPIO hub, which acts as a + role-switch intermediary to detect the state of the USB-C + port, to switch the hub into dual-role USB-C or host mode, + which enables the onboard USB-A host ports. + + Schematics about the hub can be found here: + https://github.com/96boards/documentation/raw/master/consumer/hikey/hikey960/hardware-docs/HiKey960_Schematics.pdf + +properties: + compatible: + items: + - const: hisilicon,gpio_hubv1 + + typec-vbus-gpios: + $ref: /schemas/types.yaml#/definitions/phandle + description: phandle to the typec-vbus gpio + + otg-switch-gpios: + $ref: /schemas/types.yaml#/definitions/phandle + description: phandle to the otg-switch gpio + + hub-vdd33-en-gpios: + $ref: /schemas/types.yaml#/definitions/phandle + description: phandle to the hub 3.3v power enablement gpio + + usb-role-switch: + $ref: /schemas/types.yaml#/definitions/flag + description: Support role switch. + + port: + description: | + any connector to the data bus of this controller should be modelled + using the OF graph bindings specified, if the "usb-role-switch" + property is used. Note for this driver, two ports are supported, + the first being the endpoint that will be notified by this driver, + and the second being the endpoint that notifies this driver of a + role switch. + + +required: + - compatible + - typec-vbus-gpios + - otg-switch-gpios + - hub-vdd33-en-gpios + - usb-role-switch + - port + +additionalProperties: false + +examples: + - | + hisi_hikey_usb: hisi_hikey_usb { + compatible = "hisilicon,gpio_hubv1"; + typec-vbus-gpios = <&gpio25 2 GPIO_ACTIVE_HIGH>; + otg-switch-gpios = <&gpio25 6 GPIO_ACTIVE_HIGH>; + hub-vdd33-en-gpios = <&gpio5 6 GPIO_ACTIVE_HIGH>; + usb-role-switch; + + port { + #address-cells = <1>; + #size-cells = <0>; + + hikey_usb_ep0: endpoint@0 { + reg = <0>; + remote-endpoint = <&dwc3_role_switch>; + }; + hikey_usb_ep1: endpoint@1 { + reg = <1>; + remote-endpoint = <&rt1711h_ep>; + }; + }; + }; From patchwork Thu Dec 12 01:42:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 181380 Delivered-To: patches@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp280443ile; Wed, 11 Dec 2019 17:42:45 -0800 (PST) X-Received: by 2002:a17:90a:a48c:: with SMTP id z12mr7128640pjp.38.1576114965429; Wed, 11 Dec 2019 17:42:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576114965; cv=none; d=google.com; s=arc-20160816; b=kD0SSS1qq0e2+6g8qc0uOcSze7LC4sg78Qc3iwXXhpU0yDY8vqB83N3PIGN6u7fjGJ tvhxtIoBXs+HsCpcZaXkvUWc0JXvHJSxr9QhQzHxeHCQtAW8ToBEQxoCXjyKTJHbXCCf oHZdq48grf5oFolkb+InT878g98RWIlT3DgFYRRIQhD+3asxMdPJ6CJmt19G+YrCdPmd J0vzS3CQZ+aVnv3GwGIKt2YDMpUOkDHCmCIOeAFmVPvIBVrHwhK2sec4c7U1fR9tFYKC p/3kYne9ol+MrgwJ0kSqUE6WPvzQcMbUGp0hxgYTlLytWW5EJI0fR7hXHRBTFon+kNGy vTXw== 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=okKeUrpGRdRMM1YttfPu++dPsYz1GD2rw9QI6vDbyQ4=; b=Wh6bBxXgP8D+vjTJacHC2E9QZQfH+uXQdPfEIgbyCR8Gb9if49cB3hpn/h/qSB3wD5 oJ+sE9CccXss5nOQ9K3rvzYYbQGt2JRBimVw5/M3ph3lH5EcXWj3mB5sRWUPkSb5rDTx xD1oUKMnp0T2nbUosH47zWbUvd4WZQxU3zgkKCu/vruW+A06FXlUdNjSNOEvXbrqS8aK 1DP4YbcZo9fQoIUXiC/3usao3k3bthjXjFwLNbzIIbBi+Jeai0z+XQO+/T2WDuqpvuR5 g13sd1oOh9SCRBjBft19jWeMiaSYV6M6QBASiIHu70O4+MNZfNuUAbHFlIV42WwTJikT 5+HA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fEiCjzD2; 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 v20sor4472142pjn.1.2019.12.11.17.42.45 for (Google Transport Security); Wed, 11 Dec 2019 17:42:45 -0800 (PST) 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=fEiCjzD2; 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=okKeUrpGRdRMM1YttfPu++dPsYz1GD2rw9QI6vDbyQ4=; b=fEiCjzD2vzN0vq5Yvk8MuiJWXuVxsYSs8Ohm9vcxVt4HuVC115y9PZl/iP6JFB87sD Z06vMHEE4ybMVnm6B7L+3RrKBdtDVBRTp84+7MFNLZHJpf8NsRBH0Z0Ed5sO4PoNfUnU Oegr5NAMSpg2elSJ82GKbecEiWSG67wATl7KVgPJjgAfBDc30uzZVDRG0FGo37OymIkV 9LPlAT8nhgXDqo63ZA58CJVNCEwElFMH/L39Iu2X/xYrkdv8WghJTFXi5h2PfVcfnToh UNY9DiOlKpZvUi6F+TJqBofFvhYrN6pA1HqcBuu/rTDjYvn+/wbILUCT8RP+m+RnKhf4 0fCA== 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=okKeUrpGRdRMM1YttfPu++dPsYz1GD2rw9QI6vDbyQ4=; b=P2/S74JfC8bbpFLf30p4c48V3d9tr+HBWzplDpJmYMx+Ajdm1WJdF5wr+49A7u5MNO dTgszEUoR5056iU7JtVuTGO+5e7nuYXGc3kcNo2319e6ONkzmC88hXmEZY/laZYpzISF 61aBKzBIU/CbA166NFXYp2/uStqNjBb7CZl6DXQ1Jmej9JGvYJqxE45+9YNI24/OusVe ZsNdqIx8jo45EdEFGEFy0iGnKIxo3z4iYO8XIBxP8q4WKGFosIpPGVxfp6ZMuTA5nJhf 3tU1FpbqodU3rzOb2iMYrLschGwDUiCFlpRbVg6eIJ7GKg/phb7sKs2Q96UjUPsc6roW zlwQ== X-Gm-Message-State: APjAAAUH86FhQxbz6t1ocRNZ0ZfOSTMkyyJadbjkv07VTNqzzsO9HCG8 ZzIxu8MDGT4MsWuysF5BAV3g9j+Q X-Google-Smtp-Source: APXvYqxvESeTDKX7aFK/kefdrKXspH/aC5ujQXlsEEpZCgVR9C5X2KaPnz+m0r/s83c6Ales87cUNQ== X-Received: by 2002:a17:90a:250a:: with SMTP id j10mr7112628pje.134.1576114965024; Wed, 11 Dec 2019 17:42:45 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id p16sm4217996pgi.50.2019.12.11.17.42.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2019 17:42:44 -0800 (PST) From: John Stultz To: lkml Cc: Yu Chen , Greg Kroah-Hartman , Rob Herring , Mark Rutland , ShuFan Lee , Heikki Krogerus , Suzuki K Poulose , Chunfeng Yun , Felipe Balbi , Hans de Goede , Andy Shevchenko , Jun Li , Valentin Schneider , Guillaume Gardet , Jack Pham , linux-usb@vger.kernel.org, devicetree@vger.kernel.org, John Stultz Subject: [PATCH v7 8/8] misc: hisi_hikey_usb: Driver to support onboard USB gpio hub on Hikey960 Date: Thu, 12 Dec 2019 01:42:33 +0000 Message-Id: <20191212014233.32799-9-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191212014233.32799-1-john.stultz@linaro.org> References: <20191212014233.32799-1-john.stultz@linaro.org> From: Yu Chen The HiKey960 has a fairly complex USB configuration due to it needing to support a USB-C port for host/device mode and multiple USB-A ports in host mode, all using a single USB controller. See schematics here: https://github.com/96boards/documentation/raw/master/consumer/hikey/hikey960/hardware-docs/HiKey960_Schematics.pdf This driver acts as a usb-role-switch intermediary, intercepting the role switch notifications from the tcpm code, and passing them on to the dwc3 core. In doing so, it also controls the onboard hub and power gpios in order to properly route the data lines between the USB-C port and the onboard hub to the USB-A ports. 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: Guillaume Gardet Cc: Jack Pham Cc: linux-usb@vger.kernel.org Cc: devicetree@vger.kernel.org Signed-off-by: Yu Chen [jstultz: Major rework to make the driver a usb-role-switch intermediary] Signed-off-by: John Stultz --- v3: * Major rework to make the driver a usb-role-switch intermediary rather then trying to do notifier callbacks from the role switch logic v7: * Add MAINTAINERS entry and more verbose Kconfig description --- MAINTAINERS | 7 ++ drivers/misc/Kconfig | 9 ++ drivers/misc/Makefile | 1 + drivers/misc/hisi_hikey_usb.c | 178 ++++++++++++++++++++++++++++++++++ 4 files changed, 195 insertions(+) create mode 100644 drivers/misc/hisi_hikey_usb.c -- 2.17.1 diff --git a/MAINTAINERS b/MAINTAINERS index bd5847e802de..ae5bebc2b3e5 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -7422,6 +7422,13 @@ F: include/uapi/linux/if_hippi.h F: net/802/hippi.c F: drivers/net/hippi/ +HIKEY960 ONBOARD USB GPIO HUB DRIVER +M: John Stultz +L: linux-kernel@vger.kernel.org +S: Maintained +F: drivers/misc/hisi_hikey_usb.c +F: Documentation/devicetree/bindings/misc/hisilicon-hikey-usb.yaml + HISILICON SECURITY ENGINE V2 DRIVER (SEC2) M: Zaibo Xu L: linux-crypto@vger.kernel.org diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index 7f0d48f406e3..563492f67be3 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -465,6 +465,15 @@ config PVPANIC a paravirtualized device provided by QEMU; it lets a virtual machine (guest) communicate panic events to the host. +config HISI_HIKEY_USB + tristate "USB GPIO Hub on HiSilicon Hikey960 Platform" + depends on OF && GPIOLIB + help + If you say yes here this adds support for the on-board USB gpio hub + found on the HiKey960, which is necssary to support switching between + the dual-role USB-C port and the USB-A host ports using only one USB + controller. + source "drivers/misc/c2port/Kconfig" source "drivers/misc/eeprom/Kconfig" source "drivers/misc/cb710/Kconfig" diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index c1860d35dc7e..e5e85ad0dd57 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -57,3 +57,4 @@ obj-y += cardreader/ obj-$(CONFIG_PVPANIC) += pvpanic.o obj-$(CONFIG_HABANA_AI) += habanalabs/ obj-$(CONFIG_XILINX_SDFEC) += xilinx_sdfec.o +obj-$(CONFIG_HISI_HIKEY_USB) += hisi_hikey_usb.o diff --git a/drivers/misc/hisi_hikey_usb.c b/drivers/misc/hisi_hikey_usb.c new file mode 100644 index 000000000000..32015bc9ccf6 --- /dev/null +++ b/drivers/misc/hisi_hikey_usb.c @@ -0,0 +1,178 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Support for usb functionality of Hikey series boards + * based on Hisilicon Kirin Soc. + * + * Copyright (C) 2017-2018 Hilisicon Electronics Co., Ltd. + * http://www.huawei.com + * + * Authors: Yu Chen + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define DEVICE_DRIVER_NAME "hisi_hikey_usb" + +#define HUB_VBUS_POWER_ON 1 +#define HUB_VBUS_POWER_OFF 0 +#define USB_SWITCH_TO_HUB 1 +#define USB_SWITCH_TO_TYPEC 0 +#define TYPEC_VBUS_POWER_ON 1 +#define TYPEC_VBUS_POWER_OFF 0 + +struct hisi_hikey_usb { + struct gpio_desc *otg_switch; + struct gpio_desc *typec_vbus; + struct gpio_desc *hub_vbus; + + struct usb_role_switch *hub_role_sw; + struct usb_role_switch *dev_role_sw; + struct notifier_block nb; +}; + +static void hub_power_ctrl(struct hisi_hikey_usb *hisi_hikey_usb, int value) +{ + gpiod_set_value_cansleep(hisi_hikey_usb->hub_vbus, value); +} + +static void usb_switch_ctrl(struct hisi_hikey_usb *hisi_hikey_usb, + int switch_to) +{ + gpiod_set_value_cansleep(hisi_hikey_usb->otg_switch, switch_to); +} + +static void usb_typec_power_ctrl(struct hisi_hikey_usb *hisi_hikey_usb, + int value) +{ + gpiod_set_value_cansleep(hisi_hikey_usb->typec_vbus, value); +} + +static int hub_usb_role_switch_set(struct device *dev, enum usb_role role) +{ + struct hisi_hikey_usb *hisi_hikey_usb = dev_get_drvdata(dev); + + if (!hisi_hikey_usb || !hisi_hikey_usb->dev_role_sw) + return -EINVAL; + + switch (role) { + case USB_ROLE_NONE: + usb_typec_power_ctrl(hisi_hikey_usb, TYPEC_VBUS_POWER_OFF); + usb_switch_ctrl(hisi_hikey_usb, USB_SWITCH_TO_HUB); + hub_power_ctrl(hisi_hikey_usb, HUB_VBUS_POWER_ON); + break; + case USB_ROLE_HOST: + hub_power_ctrl(hisi_hikey_usb, HUB_VBUS_POWER_OFF); + usb_switch_ctrl(hisi_hikey_usb, USB_SWITCH_TO_TYPEC); + usb_typec_power_ctrl(hisi_hikey_usb, TYPEC_VBUS_POWER_ON); + break; + case USB_ROLE_DEVICE: + hub_power_ctrl(hisi_hikey_usb, HUB_VBUS_POWER_OFF); + usb_typec_power_ctrl(hisi_hikey_usb, TYPEC_VBUS_POWER_OFF); + usb_switch_ctrl(hisi_hikey_usb, USB_SWITCH_TO_TYPEC); + break; + default: + break; + } + + return usb_role_switch_set_role(hisi_hikey_usb->dev_role_sw, role); +} + +static enum usb_role hub_usb_role_switch_get(struct device *dev) +{ + struct hisi_hikey_usb *hisi_hikey_usb = dev_get_drvdata(dev); + + if (!hisi_hikey_usb || !hisi_hikey_usb->dev_role_sw) + return -EINVAL; + + return usb_role_switch_get_role(hisi_hikey_usb->dev_role_sw); +} + +static int hisi_hikey_usb_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct hisi_hikey_usb *hisi_hikey_usb; + struct usb_role_switch_desc hub_role_switch = {NULL}; + + hisi_hikey_usb = devm_kzalloc(dev, sizeof(*hisi_hikey_usb), GFP_KERNEL); + if (!hisi_hikey_usb) + return -ENOMEM; + + hisi_hikey_usb->typec_vbus = devm_gpiod_get(dev, "typec-vbus", + GPIOD_OUT_LOW); + if (IS_ERR(hisi_hikey_usb->typec_vbus)) + return PTR_ERR(hisi_hikey_usb->typec_vbus); + + hisi_hikey_usb->otg_switch = devm_gpiod_get(dev, "otg-switch", + GPIOD_OUT_HIGH); + if (IS_ERR(hisi_hikey_usb->otg_switch)) + return PTR_ERR(hisi_hikey_usb->otg_switch); + + /* hub-vdd33-en is optional */ + hisi_hikey_usb->hub_vbus = devm_gpiod_get_optional(dev, "hub-vdd33-en", + GPIOD_OUT_HIGH); + if (IS_ERR(hisi_hikey_usb->hub_vbus)) + return PTR_ERR(hisi_hikey_usb->hub_vbus); + + hisi_hikey_usb->dev_role_sw = usb_role_switch_get(dev); + if (!hisi_hikey_usb->dev_role_sw) + return -EPROBE_DEFER; + if (IS_ERR(hisi_hikey_usb->dev_role_sw)) + return PTR_ERR(hisi_hikey_usb->dev_role_sw); + + hub_role_switch.fwnode = dev_fwnode(dev); + hub_role_switch.set = hub_usb_role_switch_set; + hub_role_switch.get = hub_usb_role_switch_get; + hisi_hikey_usb->hub_role_sw = usb_role_switch_register(dev, + &hub_role_switch); + + if (IS_ERR(hisi_hikey_usb->hub_role_sw)) { + usb_role_switch_put(hisi_hikey_usb->dev_role_sw); + return PTR_ERR(hisi_hikey_usb->hub_role_sw); + } + + platform_set_drvdata(pdev, hisi_hikey_usb); + + return 0; +} + +static int hisi_hikey_usb_remove(struct platform_device *pdev) +{ + struct hisi_hikey_usb *hisi_hikey_usb = platform_get_drvdata(pdev); + + if (hisi_hikey_usb->hub_role_sw) + usb_role_switch_unregister(hisi_hikey_usb->hub_role_sw); + + if (hisi_hikey_usb->dev_role_sw) + usb_role_switch_put(hisi_hikey_usb->dev_role_sw); + + return 0; +} + +static const struct of_device_id id_table_hisi_hikey_usb[] = { + {.compatible = "hisilicon,gpio_hubv1"}, + {} +}; +MODULE_DEVICE_TABLE(of, id_table_hisi_hikey_usb); + +static struct platform_driver hisi_hikey_usb_driver = { + .probe = hisi_hikey_usb_probe, + .remove = hisi_hikey_usb_remove, + .driver = { + .name = DEVICE_DRIVER_NAME, + .of_match_table = id_table_hisi_hikey_usb, + }, +}; + +module_platform_driver(hisi_hikey_usb_driver); + +MODULE_AUTHOR("Yu Chen "); +MODULE_DESCRIPTION("Driver Support for USB functionality of Hikey"); +MODULE_LICENSE("GPL v2");