From patchwork Thu Nov 28 05:09:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 180367 Delivered-To: patches@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp7062894ilf; Wed, 27 Nov 2019 21:10:05 -0800 (PST) X-Received: by 2002:a17:902:a516:: with SMTP id s22mr7859231plq.295.1574917805694; Wed, 27 Nov 2019 21:10:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574917805; cv=none; d=google.com; s=arc-20160816; b=RSwwmLbdyOxEioRIvGrXSfROTvQwy+BbDUlYZrfRkXkixOll7PpOTYQuQ7RZUhqMoO u5NBClJGbwjjMO4oS9m8vcRmNjV5E8rUQgAZdJW2qejBvqt1pOGRRSonxgGVuaYdrEZP V+Lz3gkEHbdLDX9KvmrMNknpUvq0mCyrcLa3UNyDbzb0RM1Mmm8O189RPePGvbYaLsSo wtbcNjqBxOgP63r0Yf5IjqoWTCYxdhAME9zGy2CEpTBLephn7NASm5dt7ZWUHuYDt6fe wm6OeHHOiBfCQ6bEbrcA80kZMhD64myyMiCxCX8fC3KzKTdD3nBDht/Y+mCm4wydfH92 cIVQ== 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=aunliHLJ3srLOMJtgW8IuzFhUg6R/1++lpEC97Ijw6M=; b=ajxjVyQ2Rxx3rE5rKTK5jiyLo4GMZMeHBiOEdwRwR4r4JeFKTzJSKyC98NyLxDPndT 0Mkb5ekCkCe0/3G3bZIyZlBticmrVFuOfYVHR8OoD5YzIOziPlbsS1rkbhOWKYgBv2QJ SEmYBmexEj1cJZVKulk6PHuvu975yLZQ8DuHGb0zKq+uQpGv0h7gaONMVPeL1AJYxlRx Vt72Mji5kmRLDz68e/4TBOFTPS/C9EcPSdh76TV7EbMQfel2IvjZ0MJ6LEtiA6Z2dmja iYJ5Q8N76oncsJW5nyYJx/xi2NKFKUibX/DcvbxxkxnTQJGjNvR04hn8pIUGjLmKbZiO yK9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QmGm3rav; 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 cu21sor10939904pjb.20.2019.11.27.21.10.05 for (Google Transport Security); Wed, 27 Nov 2019 21:10:05 -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=QmGm3rav; 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=aunliHLJ3srLOMJtgW8IuzFhUg6R/1++lpEC97Ijw6M=; b=QmGm3rav6Pt88H24rGSRwFYVQk0sj0F2NQgmIfQ/dlR6kNB7q4LxjOmyOsr4me+wcn B/2Fp9KmV3u3DeJfIf52NHSXbMS0n7jUQJkJ6ohTX1d74iAziAJtC3j0vfw/TEx6XT6P KvCAK6FxZjsg8BSMcwZYLFbo/9qSjeqDIw4P/WWlU4A1RiR5fvOqc7TY9pGWchIuM6hb lmNqRVf6Ulw0qXY4NoJDy8vjFBg2xngRaOsM8L0DdoLQstq3c/zChwZ07hJ+w4re+KSc m5TbyrEffpshT1CJVddsADIdLF0UW/4pXni7bdkpV91EsLXN9JRX1DppKuX0Et1Cc7k3 oqvQ== 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=aunliHLJ3srLOMJtgW8IuzFhUg6R/1++lpEC97Ijw6M=; b=qCN9jDOrGmA8uqIXYPgVvwq41ho8gzVd+nfsVn9kLw5vvQBp1EshFqHpOkqd494Eg4 xHCJqQUcNn1N9JvcljNqQLJZ/U0a6X8sQgmrt3XiLZXw0quYPNFaFsKEFBMK5SkwPUop P1fha4z0dXtuMihrqSN9lGLf6YZrqvLnOwR/isVu5GCiwZwKGpiGcwItYEXzIwqnU3jp wx4Hr+ScHv84Lh36Rdohc+XDx52aCWfdp86xj/hBswKT5jaO7oqbdEGFpezOmirYGLrz VnKiwn4rwgaPvWhxOT30HmlV6SVvaQWiN/jB3c2KkKzD38BOk7m4RBoiqn6vccWp3qbA GVkQ== X-Gm-Message-State: APjAAAXGjruWeOzy1vK6vam8J27VoQClGynV9Av3trtA9168TfjHnxsL 1MSfNcWkng1k3y2yMADSKI6VVbBG X-Google-Smtp-Source: APXvYqz0Z4wpHbSzIfaPzX349scyfH5Ozj0Y3awgX+JWgeTSfqLIVerj1H3T7IAA44ejhlhu+in7uw== X-Received: by 2002:a17:90a:2569:: with SMTP id j96mr356171pje.79.1574917805201; Wed, 27 Nov 2019 21:10:05 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id j20sm17799838pff.182.2019.11.27.21.10.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2019 21:10:04 -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 , Jack Pham , linux-usb@vger.kernel.org, devicetree@vger.kernel.org, John Stultz Subject: [PATCH v6 1/8] usb: dwc3: Registering a role switch in the DRD code. Date: Thu, 28 Nov 2019 05:09:54 +0000 Message-Id: <20191128051001.18995-2-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191128051001.18995-1-john.stultz@linaro.org> References: <20191128051001.18995-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: 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 Change-Id: Ibd89b7eb3e59688895a2d317f3515e6d2705c6f3 --- 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 --- 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..3b57d2ddda93 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; } +#ifdef 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 Nov 28 05:09:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 180368 Delivered-To: patches@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp7062910ilf; Wed, 27 Nov 2019 21:10:06 -0800 (PST) X-Received: by 2002:a62:5485:: with SMTP id i127mr43447660pfb.186.1574917806780; Wed, 27 Nov 2019 21:10:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574917806; cv=none; d=google.com; s=arc-20160816; b=r/z0m0kA7owNegI0k2ZvRe76F0O01w3lu3bHVU1ev3Wxk04WZ7zYiiS4cxxQOpislT yxiY8QPhDk9wVO1OoeGYpMz0Q0K417oAiznTNQfFyU6H0zFZWAT9BK7/OCs9sqzR8K9n 83i2hKYGqOdpSQ0FnWJn9kwJhv+uO1DyH2Q2FeSHATt6fz+9VG6PsR3moUGt7RX7h1C/ wBASeKP79z7KIUBli9QfUq7Nvl/hqR6lfUZClcAkuSJubo8CVFT1hCkMiCuDV63hEECH jvQ/a0aPnlnsLOQx+NUX7N+8BLatlmlbZK0SBymjHoI+AFmZp1lugM+eHMKEw5spt0+0 9shQ== 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=bijPVAEzb+PpbucEzBhezT3J7OXGruht9k9XHqbXPdY=; b=aMCGAXN04yiVfsHLPCcTqkNb8LxRwCaxYfsnwsNtz5FAPye++v+ksbZMiYGGdTdY54 eM1rx4HQBJhYu5OFqq0b66BDUkv5czdxjFSdtEWxts5SeSBwlXNllIXLms1e2if9yz12 +dNuQsE0NYUGf8Krp8q2a3nMFlYOb0V58FHPXIl7zlrjgHerinR0r0lfbXN/JheNjVvA yCR4yOz1uaPEII6/2PNSGrdduuSkbyh5EF/WVbHYj8DLzUGocIUk0VGkErdv2ZWjTwrq phjvTr6LHtX/wyHhKn8Bu4l3t6rlxGnWFjrbTdxxFGfyQhp3romnn0OJbuxTCbCd48z9 Wukw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BDxr5QZd; 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 z13sor3711361pfa.42.2019.11.27.21.10.06 for (Google Transport Security); Wed, 27 Nov 2019 21:10:06 -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=BDxr5QZd; 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=bijPVAEzb+PpbucEzBhezT3J7OXGruht9k9XHqbXPdY=; b=BDxr5QZdUNok23k8lyxS3y1ZlKHNNc4ELZ+mU2Dn/bzWGvj8AhvFqwxsu93p12BDGR 4IVjdr4gFJQGP1v3zum4XslwjezFAshgm31mNb+w17TCL8R3mrfq/tY8L6AngoTqu+MC ZbBqb7ADtZQpf7DCp+khMqANrkf+mHWNuHe2TGyUKk6rblxP8qyIUQj9Ns4e+Oq7L7EN J3UDzm5ai43a5A0OBKuPqN3Vr8/gk0UtvyJAjNXweZSwjwaxEqIYZt5Bwln4pSm17O2j XXlTKYnsDaoDxjxVS13JBlKb/pMJS6yFyYu/8nvmPlAYzhPyPdr6Vhtej/pYUtOcbUM8 p37Q== 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=bijPVAEzb+PpbucEzBhezT3J7OXGruht9k9XHqbXPdY=; b=ni6SWv+WHdf+2AoJigslNs236vSotrF+JTBk3qScdRfecd0HhqAVZSMWm3kaClI2aP W/5A9tC9DEsVYSpnrFYOgn5trtA/7Rnbeh5AVLM/0AIiC00LvMQFf+GPjSymo3VW197N eD6qTdeosYdeRk2qp0OHdHgZ2HrE1BCaZoi/qhNUzEwlsnbNgndYWftkPt7GowAJk2Kf WmWZL7bjuNELxQAhnBct4y+AZIBlCEsctee7gtGsl8GFHMfK+8JwZVI0ajcb/+z9dTOG IKUAX3fIu8NyHQCIa2XxPg6Q370ZGCV+jhv63LQZbObBbsNIr07tTPFmOPcFWsmGA5x0 pNmw== X-Gm-Message-State: APjAAAW/WwVy7BnlgiPaUoA0loUrnWSlLZ8PrVD2JLYgxyodnATmYw3j hS7SXFcl22pvLPP4aQZkkz0EdjAy X-Google-Smtp-Source: APXvYqyHageaOcP7ZOVXe/q37hqFPzxHmvwOcCaNRfIR6tgS60hDSdNJ+Eg+GXENKnFhjHUG5+LJBQ== X-Received: by 2002:a63:f207:: with SMTP id v7mr9384553pgh.246.1574917806305; Wed, 27 Nov 2019 21:10:06 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id j20sm17799838pff.182.2019.11.27.21.10.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2019 21:10:05 -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 , Jack Pham , linux-usb@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v6 2/8] dt-bindings: usb: generic: Add role-switch-default-mode binding Date: Thu, 28 Nov 2019 05:09:55 +0000 Message-Id: <20191128051001.18995-3-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191128051001.18995-1-john.stultz@linaro.org> References: <20191128051001.18995-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: Jack Pham Cc: linux-usb@vger.kernel.org Cc: devicetree@vger.kernel.org Reviewed-by: Rob Herring Signed-off-by: John Stultz Change-Id: I6ac1d9c56039d76d924148e29a5e4b0bb304ed0f --- 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 Nov 28 05:09:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 180369 Delivered-To: patches@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp7062923ilf; Wed, 27 Nov 2019 21:10:08 -0800 (PST) X-Received: by 2002:a63:36c4:: with SMTP id d187mr9286533pga.108.1574917807854; Wed, 27 Nov 2019 21:10:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574917807; cv=none; d=google.com; s=arc-20160816; b=Hnk5pkvgRVYu1qVM2KtytOwR1Z669rtUUm5cK5K/2oxkWE2C70ux3zVuQU3Pbi49YY vB9/bB28vseMUwD2/antDg2rRq3B/iJ+B4yNgycrjTVgzFKD0M3LklTe3nAQ3iDoB0Vu QYbHKFTLqusf2TZvH68YwHN21HR8IUeC5cY0tzvFdxv0KsBaQVzrTtenoKeGYQdFbjNu Q8sRLKjR+Tku6yZXdN2zUmKizH+Lp6hS+q3bv/kJewvZolw7sO7vM7c8biMaDfB81O6t Y6W27EZqUFx3gkhYuSXSYuGqQJkEKM5Mn3OVuLdJLV+XPslYphsyJ0gdk5rStJA8WGn5 R0KQ== 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=hY1yxqp1ob53DN7ENv/xE/lf8zTH/wjr6NLCwssl4oY=; b=yn7oDfesvtuysnst0QpNo7k60fME6XKM6KVvdWObrczBzCKhTBK3PTq0/+dR3OVhsB OFqTqnWndh+qu0MpfRoE1i0Bez8BuiINRAtTEYTTlhfoU1ZxYqr1w70NOP3dqCTtL3T1 6OlhmPPJJWdFrX34+K8D85iyJGo/PzViwaWhD3D5ja0q0GUBPx9mVTXOPwtQjM/+ItDB zlPi9zhHTFYeeNlYzNIzalrw8E4KfhTG+A+bIpU2+iobHMxyxW+s/Roqc89cZOJzMg/N jnpjZhXP77ogdwLnz9MmUO+WPeRfPK3PmmqRfNv8bhL4TUv0l0g6xH2Wjgm0ukX9M7xq jxPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="hk/1YuwU"; 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 g3sor19187346pfh.13.2019.11.27.21.10.07 for (Google Transport Security); Wed, 27 Nov 2019 21:10:07 -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="hk/1YuwU"; 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=hY1yxqp1ob53DN7ENv/xE/lf8zTH/wjr6NLCwssl4oY=; b=hk/1YuwUWLBKvh0dO8zLMRu2RLO+u7QiynmfRzdky6IluYZ3rZoISwdYcgVYqjuAKB c2saT8VITc79pLh2gNdmweVtiFDppLRTSQuXzGwJEHZPi6jYQUd7qt8kjJeiAHnu0B0E 0rXDvRm3hjS3e2oDpFZMXeHgJ1+lSnwygIG7V/IoRth0FBD6+p/zFQCHiBFo+1ArtZaO rwBvdw6Vzh24lE2ke7YFJfgLUyZea7JVCxOpnRVhd3OdCADgF891H1I9WRyvDFDSai1Y miJesaeILgu5zW+EFX7quCn0EhMO7ypnPVUHr8ByYQJeC38bIb4gAcjMv7cL7XmRxQPk aG/A== 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=hY1yxqp1ob53DN7ENv/xE/lf8zTH/wjr6NLCwssl4oY=; b=KsSUelgRhn8HzTeJ65mZR06nO9lnjD1eSqdtLX8gGtzTisSTx27dT2MFhguE0sZOiX ktYXnspoLcql1ZtAJxhHfDsOtSm7zHroSi+oRkIKbV9wXWzQtzINXzlE2YuPaFRF3Tcj m7cuRLul9RztuCmmgUHpJIjU/ZUkndxLR9wObPaKZpsKPY1D8s+EGKZ3WbPYz6DU+mY6 aF/HcqA8ZXbzWwTH1T+D20UVX2+9ygnwy8tlBLcTUvvm+Mw3YWCx5H2gdP4S5a8lO5yF Bx6BQq0sWbvZSSmfxVJYc3YNlXSK/oMeNsSD+WSue1gdZBCrs4KJPSaAgdj92NukmeIL rcfA== X-Gm-Message-State: APjAAAX4C4qar/T5JQfw2L1P6y7CWo+O8M4A+nBjrhLyTmAMbl30AeWv XGJPzXQgdeeLNtt0UU7oYOj3G4GT X-Google-Smtp-Source: APXvYqxtdbubB1CULYeLwtLpj0mqVpaBXEL493d2O54D9CS4f7ug03/u4xBGT4vrYDGxAA0BXPlX5g== X-Received: by 2002:a62:1dcb:: with SMTP id d194mr21747254pfd.66.1574917807440; Wed, 27 Nov 2019 21:10:07 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id j20sm17799838pff.182.2019.11.27.21.10.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2019 21:10:06 -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 , Jack Pham , linux-usb@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v6 3/8] usb: dwc3: Add support for role-switch-default-mode binding Date: Thu, 28 Nov 2019 05:09:56 +0000 Message-Id: <20191128051001.18995-4-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191128051001.18995-1-john.stultz@linaro.org> References: <20191128051001.18995-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: Jack Pham Cc: linux-usb@vger.kernel.org Cc: devicetree@vger.kernel.org Signed-off-by: John Stultz Change-Id: Ic6e4df1109b350deaecdc69f667d49ce91d599f3 --- 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 Tested-by: Bryan O'Donoghue 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 3b57d2ddda93..865341facece 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 Nov 28 05:09:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 180370 Delivered-To: patches@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp7062949ilf; Wed, 27 Nov 2019 21:10:09 -0800 (PST) X-Received: by 2002:a63:fc13:: with SMTP id j19mr9054747pgi.327.1574917809113; Wed, 27 Nov 2019 21:10:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574917809; cv=none; d=google.com; s=arc-20160816; b=nlb8IiAfhcZta7xQIvl2HsA05gpG+NbR0FyiEtEbMSPgnre/dNxH3QV0xEE8rWdEw3 5lOdBDl6XRZLm+mLCV6r0fitXpbQH2tMeZrSkTwuT9nwxuD5g60074A6lWeXS3lLdINq O/r3gpmOxA4zjl3kMtqwvKOImHoPE4Ayk/B9BZwV+dyiCiEai1vq5yIBdtGx00BCuCpW XJV8hU1VODwKhYJgWD5gNjuCIVBWuzVgtR3FYh6I9o3ZK5cmKq0UTC2pc301bHImqwkv 48qIZ3rZ58aKcACfcxHmxoxHa35Bjoywz3OT5KUVrF25gm9c7OmL5d1O4nhIElwpIBl5 vUuw== 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=ouUtqJi8LGrm8rrsEkCm6pqbpQoOVXeEx8u8OcmIa0k=; b=VzBxs6tgzXvSc0A1nyvwNDaBzBDlOOXyKyVyEg0sidRrwV3o+ASgp8pOAs/o3C0ooJ FFsbwyL7jnmhS4LSI79CBAzLG+iC0QqJcVjS8OvjwOYd82oDtjirl5oOf+2i+q0xCdCZ Rw3NOcHPcH8v4FvVAEU7/aGAghGn1SNP8T7koUFNNW03o39JSE2vb44WZ2aa5SFXXJ0G YM2D+sN+XAvoCE1tniKlc4IRECKBvmwOLrg4/wgxOIrL7dTihQNL1zt2I3LW2++ylCeV qIByTOQeZ2icM8Sx0wV3WDVNTZnnCa7hh4eU/VefT6XL5q/6SYjEIHeDKxrGWA2z99+G 69Ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lRoVK5do; 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 s19sor19059570pfh.23.2019.11.27.21.10.09 for (Google Transport Security); Wed, 27 Nov 2019 21:10:09 -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=lRoVK5do; 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=ouUtqJi8LGrm8rrsEkCm6pqbpQoOVXeEx8u8OcmIa0k=; b=lRoVK5doRSRDbRTAAJnPpfGG0jqnYt4E9nzW5oAevteuhSV0bqeuKhhCkEEhImCFaj iwr9QF0pGo8EWPpe8QBpLIhwIZXaOiK0nZsY+KB8MVcuXVYhlkqNqbIDt3ZBsI5KNVUt UtEADqokuYMdxi0rGQ5jhmt+znDOCaTls1MbNSlLRhn8FIbeTwTwafDs9W6OCCvfwczx slgKI+hQCG1Y/fYUBue5N8LhwXugyZD2KXj75N/7pfpvLc54zw0yPbiYLeHOIJTqVy2k kSqvElS17wUi4JCtzv5IG4E3Ecmw18ALYxd6n7VlK35wVwv3LsaGA/emiZca/U72O6p1 pmCQ== 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=ouUtqJi8LGrm8rrsEkCm6pqbpQoOVXeEx8u8OcmIa0k=; b=jvvaRKZPvYYtm7LjNVutWHXNgSLbAwtU3LwUJaKBh0Y2DHcrqJBHNWwH+FYLc4dPuF 2oHtis44+VCozlqiZ2oCUdEAPVwMzf8Ae6z70ici/phBvLfBpTW3OWfvdyI/3EZpAqFO TGLD0CYdY23TUq6pmmUoo7Sy3JFuMnGU+XtGq8xn0REDqqGX/ImpsbYRa4c5BBvGtgkc GWNrrqhbz3EpPnwbgNx7pA3/o1doZsCOi0iPWrSQbMkQ+R9FQ7u5+o1WecOYTOsShIpB HH8tsBE4vhyuNK+In+uftPk9fr4REvq/nwiFUKLMCpvdnWwtL1zhxtNkccgJYpl4+P12 N3EA== X-Gm-Message-State: APjAAAXW/yDs0TnPrJtRtaS4r9pgauhqzr3safEbuAc95AvccmAhkVtZ halqGJZtTQkr3EedQcFPt2m93esfpdrsug== X-Google-Smtp-Source: APXvYqw3ZxeK1KWVoQYkQZwW5gUw6ZrpY3pVlZhbG3RaFiSUJyRNEgOJwBNo/d4aRPX19W30JLm64g== X-Received: by 2002:aa7:8b1a:: with SMTP id f26mr29781944pfd.81.1574917808709; Wed, 27 Nov 2019 21:10:08 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id j20sm17799838pff.182.2019.11.27.21.10.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2019 21:10:08 -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 , Jack Pham , linux-usb@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v6 4/8] dt-bindings: usb: dwc3: Allow clock list & resets to be more flexible Date: Thu, 28 Nov 2019 05:09:57 +0000 Message-Id: <20191128051001.18995-5-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191128051001.18995-1-john.stultz@linaro.org> References: <20191128051001.18995-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: 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 Change-Id: I0176989314d7b7e6ea586f5036f072442f7e34e1 --- 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 Nov 28 05:09:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 180371 Delivered-To: patches@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp7062970ilf; Wed, 27 Nov 2019 21:10:10 -0800 (PST) X-Received: by 2002:a17:902:142:: with SMTP id 60mr8135925plb.38.1574917810108; Wed, 27 Nov 2019 21:10:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574917810; cv=none; d=google.com; s=arc-20160816; b=VyHbmpgK9Z7aRNAdSKKpK4tvWVo/4ecr8637TQF6FjrlbLMwjF0nulZe3NgGBmty6b 9TdLULUh44GDSwlTJn1rc/ns9pXRX2fvHUkybV8/gJChBkFW7ofATki/O7OHtjidIilN YMSI6xo+LcHw5knAsMQbEaGymi55LLZrlcONk8STic30qTHDF1TAmW8pY+SAXU9VmxdH eTKLybmi7IgBTyWjv0YlKyx+ywdWOTrMLwPD+No4/aoZ1FhBR0PqLSEPzItUgRAp6CeA YFq6YVNGLkqS3/c1E7T1DMqlVbnplTdp8e7/gZdJwsDFuYkBq8VvvXDLkCU+RPlZJJCH xKrA== 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=BvSTajJ0/txDo3oQ9anR2MLYElhTmMiqKohTpjPUH4Y=; b=uojU0BJ+g/SFtLT4AgcoExP5bjnUf8MSr8kCRJf5vr9YVQzP+LMBK+x/n+k7WlBZ9t tI9cP1sVrpi8wWg8xf/kZ548HhD8Zf3pFxC/OCS/SxePNooOQ5HIGW4tqdGpRWlEAaBC JDSHWS6NwyKjcSFVy1/QBxrbQRmhURs27sVhtaxhB3IolV/hKtaNi987CG6jEo/MyW4W A6hCgO2zRObNIILzZozNoF/zgDIYK3ywVrxerUGcsC7FshAp5YlAdYcjYBS4F+l6rb4e wFIgUC6ipvYbZAGjnKjC/8U1eZzeOyIBl6J8oi7Jjm2ninTxgdbzRXs684UyFRdLt/h1 7IiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hEcBgdZf; 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 z13sor3711520pfa.42.2019.11.27.21.10.10 for (Google Transport Security); Wed, 27 Nov 2019 21:10:10 -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=hEcBgdZf; 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=BvSTajJ0/txDo3oQ9anR2MLYElhTmMiqKohTpjPUH4Y=; b=hEcBgdZf62B5VBmMPEBMROUIXTik/BmhILgVyVtvBnFUL+wplH8lMAizJ0o0t3/ng/ iKfkb0yh4LkTNwbo9TqW1UBDse7OefhHp8STTYmoQFwejSusy11WfaIqzr0xEq29Aovr SZXB0JEgIUGPzDtNjE816xl2J45Cm2GSK5ykeQgEZkH5nGJijSLPBkdL4qnvjle75Giy W+JaJPW95XhtAntBeGnN2+nKIFtQCjTVptuFfZTjIdT3FltrfPmPadJ8D9pLtk1nAkXU hWfXB3h/Mjf1HyqlidX7XwaVp3uY5B2UiNZSduoUE4Yc4j9x6jM4LtnvD45MvbkJr0B4 l9Vw== 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=BvSTajJ0/txDo3oQ9anR2MLYElhTmMiqKohTpjPUH4Y=; b=n473A5BRIBSFhmHqV0f/pX2Qgxro7K0enX7DApPH8Obdfos3i/pCWqttN2+y4qHZIF ZpvI0LbAnit5+8ejCUcfjj6PebcnO/7+dyqGt63U85ftrAqe07qCzmAjAWJyXBn0n4Gk hLQw6bjDe/2viGhKjzKBLNjFY6RagYa5JTYb4gdd0kUcP/Fi58QZh2h1cmp5Hb2OiRAK reZzSzlIDAvRLSi5AKNWMq6qHQRz5It9mikvcg0jqPrf42jASCqjFezp28iJyeYVozAj lbV6Ae+dprj0fy6wBC31iCf2vcK1yzOVDRSY7ZZf7y7oT+tnAW+J62IF3HqFERmYyDCg y3aQ== X-Gm-Message-State: APjAAAUw4XxUwFk2JOU7auwx3GUqON/E/7ttORFKGWSkOKji+l4AONCo IggPNbuit5LqqtiCV0rwkLt6mteo X-Google-Smtp-Source: APXvYqyql6x+1lm7cxFqUepsOsRjBk9AfB5o3/t6r/N0vThhH09XFvGWl/xVmQ8NaYF3vh/pvqejmQ== X-Received: by 2002:a62:5e04:: with SMTP id s4mr52193789pfb.63.1574917809693; Wed, 27 Nov 2019 21:10:09 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id j20sm17799838pff.182.2019.11.27.21.10.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2019 21:10:09 -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 , Jack Pham , linux-usb@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v6 5/8] usb: dwc3: Rework clock initialization to be more flexible Date: Thu, 28 Nov 2019 05:09:58 +0000 Message-Id: <20191128051001.18995-6-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191128051001.18995-1-john.stultz@linaro.org> References: <20191128051001.18995-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: Jack Pham Cc: linux-usb@vger.kernel.org Cc: devicetree@vger.kernel.org Suggested-by: Rob Herring Signed-off-by: John Stultz Change-Id: I3319bec8253edc131d772ca66dc9335435b06424 --- 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 Nov 28 05:09:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 180374 Delivered-To: patches@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp7062989ilf; Wed, 27 Nov 2019 21:10:11 -0800 (PST) X-Received: by 2002:a17:902:7892:: with SMTP id q18mr8046989pll.171.1574917811219; Wed, 27 Nov 2019 21:10:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574917811; cv=none; d=google.com; s=arc-20160816; b=CdGSoh3p9Ev6p2Sc1ZcTxYO2uFKrt5Az3VBBtx5EJRbPCS8+OQA0UBH9D/k59Q2Qla QZFefUbnVXC25d+FOxyQd39U94rs0j0EN3W1KNdg+W5LAlsDy4Na3p6R7pNtxBsLbx5R 6ayKIlKNoyhE4YB/CuddtvObEp75zPAUsAVySJwMqCij3W6jvYJ1HJNtOi5o3NtghebW EeHqLRguhN3PfsGqks57GPbxWXDVCeza04rp4ngghQVWPLM3M8itatqhBRSnUUWR7iLz q47/gTEe7ajadlQmF0K0l04tZyTwExLJ2sF3CmEpLrpHZJ264qFB739bfe8MSf59VPTO ZQlw== 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=QO/lP+KDcMBuBF0dCbiBImn3ahE7Jw+zkWapBF57MgQ=; b=S49OTHvcEmRlmRujIwo+PsGQgrtoGZZTl14vV6nNMlAQI635wYk3+qaniU8EwqaTt0 UOb1rxD2mAq0pisRvKs679We3fuR7Nusa/NzD1hXbInbSpCTIsnXKF3hXJRyXOKHWfYR SdUep30q00s2ouq2lmq13VxpJHGipy25wpmGYBoFL5Yqk2xjVggXyPFOdNNS3JUrWM1L WTPJo1vcvx3V8WEs/prk8RPzhpMVvETEKESGsVqvZ+F5G63boeHlHiFimazlQa0BVq5m nDCuWo80VF/t/xzp3j8KIUBWycMcm+rW1hvP2/UKTG+MdIx5zMHGuDUvApdc3nItAJBE Y/cQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jS4vAou0; 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 j10sor12073819pfn.2.2019.11.27.21.10.11 for (Google Transport Security); Wed, 27 Nov 2019 21:10:11 -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=jS4vAou0; 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=QO/lP+KDcMBuBF0dCbiBImn3ahE7Jw+zkWapBF57MgQ=; b=jS4vAou0Kr4VlWLGW46xQ2mOeWEBO9xSfclqVZzZY6prqeXpGcE4q3l3Xx5PLk79oZ yt8FdpGPdNdZ2G8OZY9ofcFQ6RHGR/f2dmna1niRT8P5LRmymIw7yNiS+X9eeNUaSlKM 2+Gs+JwPGWvX/7EfC2IcTHHOGHpS+4ftgU3cqPhiiDhxJSkfTu79VkQa1UQCn5whtfc+ WdfrCLD+xeu9oUM2RU6+TnqnRiKNvRf/UlbT/bVixd63o8ou4RXmjFL54TiWbfOqRbP0 3zICwN84cBLfHoYmUrXv9WU5uVkpPXB1CcpQ3HCpuvkP5D8mwXDwQ75SxOO+wqV2yqcB tXjw== 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=QO/lP+KDcMBuBF0dCbiBImn3ahE7Jw+zkWapBF57MgQ=; b=CFSVTPQ10j+WNt3bm971SLdq3A41cQFVNPk/hePuydHN/yoskhU1D5Q3yLj8ESjdCK qki4Cs0SEyGbr3JOz4A/xaJZdNA7C9QJFKfoKta2XExjpAeu2l5hE3EybBdz5ZeR+zHi Gb+Gae81mZFjVp73v5yrW5H6Dja/hepYdQ9KsoL+3wvwi7ecrG35+HHKVYmBWXDnSACT kZFvHVCWut1UK9rqFZBhR3mz2kOpxTIWpAoJpaKxaBs43Q1jl6duHmbZLbdtFr8K27YJ iDNJVG20FMBpq6Hw3/Aq4ynHTyx9Ty3sBS4jd1xp8AnpNL66rG/SzBXy7lCgszJRMWf8 Fmuw== X-Gm-Message-State: APjAAAU+hK986GsGrsZpuGs2T4j80zIApTl3i2eUCfvf5WIrx3wuCHZM 5hPtomas7sdW7na86VURyH8jDCVq X-Google-Smtp-Source: APXvYqxGPRbiVlZZUV1rk9y+AqcuPPIRI6ejj7HTdsPF3VM9U1EQBetfUhFQXHuhzrFwXyT1lX4LXQ== X-Received: by 2002:a62:1488:: with SMTP id 130mr3242980pfu.238.1574917810740; Wed, 27 Nov 2019 21:10:10 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id j20sm17799838pff.182.2019.11.27.21.10.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2019 21:10:10 -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 , Jack Pham , linux-usb@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v6 6/8] usb: dwc3: Rework resets initialization to be more flexible Date: Thu, 28 Nov 2019 05:09:59 +0000 Message-Id: <20191128051001.18995-7-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191128051001.18995-1-john.stultz@linaro.org> References: <20191128051001.18995-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: Jack Pham Cc: linux-usb@vger.kernel.org Cc: devicetree@vger.kernel.org Suggested-by: Rob Herring Signed-off-by: John Stultz Change-Id: I4a26492f19e857f3f9f29bcdab81458016f70977 --- 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 Nov 28 05:10:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 180372 Delivered-To: patches@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp7063003ilf; Wed, 27 Nov 2019 21:10:12 -0800 (PST) X-Received: by 2002:a62:1447:: with SMTP id 68mr5172018pfu.53.1574917812300; Wed, 27 Nov 2019 21:10:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574917812; cv=none; d=google.com; s=arc-20160816; b=ZpV9P4oIz20SpHbfVR70YEBlKw/Pnro8CyuW2EW+8lyP8FpDmqVVQnoBmO1KXYlwBC KiwTFRqivVaK8oGdRruu4DeFCHjjF16A22wSPCLns2YMH2rfv5ztZvQEHHe0qLV/Ac2x CSMZqMIlfCFmSuTJTJ3a27N7v4gNGvq7Owh9u2hR90gi/quWyTWXz4jglHFvNbLhIyzy 4YsT89LnTdpZpMvaQadjx/WrxDzX2daLHWqC6y3t35YoKgMxI+sjfMhoGajW8FhmAgSR D/bBjm0U0fY5U1LaVCuNTDi2K8X9vppSoUdUq1aLIJ2oTIUMm8aD+SiMk38kJza78vvE iylw== 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=VUmL4qLsieRvwPq6R62FHNU4t8q1oQ82Y1SNhYOmg5k=; b=DQJsXwJ4PWToYeD07f3Au9e7Z3sIX2rpX46vYZ6CWm8ETm5POUjsgdkvsx2iN+T4eS Ge98nnZSYnhlOnQ1189LzFHEgoSlTtlVln+F5grmItbj2GpwZppQdgHDRFaAKxIIhJ6+ UpIuDXCY6oLwjH7DsQ/OP29Wmpynd9o+dKAGLyOZu5LAyRDVobRB607JJSSWk6goCYdc QbzOFNmq+3j9g4Oopv7gZH92mQ5nhaer1kbGZcWaUQz5+tSvmn7awfztY/C/0vKYbXVP pW+BxsXbcD1v/j0udeR1kShTOOJoO3xmW/YYbg7uJv7XZBb/R7I7emija2DJl+/9c4BM jp3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="D/EdEpZq"; 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 fa22sor10932159pjb.0.2019.11.27.21.10.12 for (Google Transport Security); Wed, 27 Nov 2019 21:10:12 -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="D/EdEpZq"; 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=VUmL4qLsieRvwPq6R62FHNU4t8q1oQ82Y1SNhYOmg5k=; b=D/EdEpZqCCtTGiwmEC6gq+PCA/Y+yTDJREnWu59+lBpHibMPIellRcG6NR3zwBZ/xx OLmVSLIv3eX7q3wLN9j+c2n0JjO5XplIw9WMd8uSDYe9OF95xpsuAd8rk29X/Hd+01Tj W77VEvKvNu60Xa6aMADiIWzQknKzchQvsD3dVqfzNqGHNe3VmiYARrwxWMJ4D1w0fl0K YRo62TEYKYB4WuHdY/Xeige/XvQ222CnRfEmh67QgYKqArYKhs+IjP/Xf4D9lvoyCumN HsH+6Y+XfFdBvJGolCgcSWJYxQkhAOebHTwJaN77THPerQMMc+RHJoa0BAYcxkRiZkBZ XZ7w== 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=VUmL4qLsieRvwPq6R62FHNU4t8q1oQ82Y1SNhYOmg5k=; b=gYkESfDNxBjliu0oVycNFmUADyFngLlR+d1XuohbsER36hJC2T3Lqy+xcmr25xe+Il uzEmVGytFj8995XzwuGVKJWVr39tV8Xr2RW+uy7dg0jW50zzkcn7Q1Xw3EXavkqE1sIa T3rWwIIiv1pP3/Tb9OwWp3d3HnV6DapM0u1HVD6cin2z/iHv+ebJ4xv8nGx1h3nNNIKp Ulp14u7A/1HK/UMduRaGcWq/PmteTS7EYi/YE05VIYySydTn1aGcPHXanCExQRgRJRX+ 1yqEXyXENRwfM3zFqWgi2KD1Pa2s230u1jvYXWBHmkwmbnp7AuYNqmS8RmxbRlSS5Fo3 LYmg== X-Gm-Message-State: APjAAAUbMAcpgLeOrIS7c9DyKk3OO0Gekx8eTIweEj8yzZFteqeT16wJ HY4/V8dibwsrsv0qdK1Ccy2aQUPG X-Google-Smtp-Source: APXvYqw1Rx241aQ1QD+PueNp8aW3lcCk1ns7N57sTu49O5IMq1I9NZ4kt+Nn94dM2CeRSzBJKvW8ow== X-Received: by 2002:a17:90a:65cb:: with SMTP id i11mr10354421pjs.23.1574917811857; Wed, 27 Nov 2019 21:10:11 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id j20sm17799838pff.182.2019.11.27.21.10.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2019 21:10:11 -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 , Jack Pham , linux-usb@vger.kernel.org, devicetree@vger.kernel.org, John Stultz Subject: [PATCH v6 7/8] dt-bindings: misc: Add bindings for HiSilicon usb hub and data role switch functionality on HiKey960 Date: Thu, 28 Nov 2019 05:10:00 +0000 Message-Id: <20191128051001.18995-8-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191128051001.18995-1-john.stultz@linaro.org> References: <20191128051001.18995-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: Jack Pham Cc: linux-usb@vger.kernel.org Cc: devicetree@vger.kernel.org Signed-off-by: Yu Chen Signed-off-by: John Stultz Change-Id: I3f111b39b7a982b3489549076412a2f7c3c3d008 --- v3: Reworked as usb-role-switch intermediary --- .../bindings/misc/hisilicon-hikey-usb.txt | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Documentation/devicetree/bindings/misc/hisilicon-hikey-usb.txt -- 2.17.1 diff --git a/Documentation/devicetree/bindings/misc/hisilicon-hikey-usb.txt b/Documentation/devicetree/bindings/misc/hisilicon-hikey-usb.txt new file mode 100644 index 000000000000..1e131b38230d --- /dev/null +++ b/Documentation/devicetree/bindings/misc/hisilicon-hikey-usb.txt @@ -0,0 +1,40 @@ +Support usb hub and usb data role switch of Hisilicon HiKey960 Board. + +----------------------------- + +Required properties: +- compatible: "hisilicon,gpio_hubv1" +- typec-vbus-gpios: gpio to control the vbus of typeC port +- otg-switch-gpios: gpio to switch DP & DM between the hub and typeC port +- hub-vdd33-en-gpios: gpio to enable the power of hub +- pinctrl-names: pin configuration state name ("default") +- pinctrl-0: pinctrl config +- usb-role-switch: flags the driver as a role switch provider +- ports: two endpoints to connect the usb core role switch provider + to the usb-c tcpm driver. + +Example +----- + 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>; + pinctrl-names = "default"; + pinctrl-0 = <&usbhub5734_pmx_func>; + 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 Nov 28 05:10:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 180373 Delivered-To: patches@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp7063011ilf; Wed, 27 Nov 2019 21:10:13 -0800 (PST) X-Received: by 2002:a17:902:34d:: with SMTP id 71mr7780043pld.140.1574917813478; Wed, 27 Nov 2019 21:10:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574917813; cv=none; d=google.com; s=arc-20160816; b=PO8JgCc8zb44m49Kv9ECjLvM1LrhHliYKLjucIb735v/r0c0qSldptGuiPTSOffHul S2nnMZS1nK1mvDKJFl3xnN7tMBRd/1THZzi2Fcg+DCrzl8EWoAEvwWXBBOTmUcfbbHFS AiVjbKaYXglxtC1WZFJHEgmQbOv+pebkh7h0YDEL+HT8pJ3cjILwRK1KNmPltYnWIGjw 0wY1LuFx0uYT0irCxmqJ2P+zsJ+0zpq3l4pIyAU6Ef/BN2NzJRJxm3cjoIa6F7GHfRLK padMUKoOgcTfcTltCmZ+U19EOOJ+BXnhqUQUEJys8crv0x3w6YePJh9KWS3IwxmKklnf cqLA== 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=RTwhiGGQI56EX7zxVFVkZMzvQ6KeYwPMuBINHNN78VE=; b=CN1aA6PsUEn0tld3Aq1SAu2S/2A31heKXjE97L967y86NKQiatA8ZfGT1F7VqwpL5h QvfkSOmC6mR9MXVIGe7Tjk1eId5FNqfcEvEUctBZgAX0D35f1YO1wnyYnEs/0LtT9QKe QmYbut6b9UPtPt4M3u5HvUpHN5zdZL82ALp+YKT+stv/3VPqwIjHq7Cvsu3huBDAwJGt EHT1nKzW5WvT+dX3TPetz31JiqSqAfwqXA8CUN05/ZzMSnWg4jnY97mCgcmglo44lTEX zA0Hj0C8wnFTWxMTMWm72bY0/NB/w5vEqvA7x/zhYAk7Rb2UuR0zWqNlM2SD9i9z8dXU TRmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zP4AQxuY; 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 q20sor18610414pls.69.2019.11.27.21.10.13 for (Google Transport Security); Wed, 27 Nov 2019 21:10:13 -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=zP4AQxuY; 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=RTwhiGGQI56EX7zxVFVkZMzvQ6KeYwPMuBINHNN78VE=; b=zP4AQxuY0FZin5I4kw6zgjYse7QycYQBRbSq6aiiqJQoljrKYOR6UINFvxRqwhq+wh /IRFA0OVHwKkViESNJCu8ixC+FtuDe8KBhuWheSVFlbCZderf+BQcN0JN9iyEEJSrXOv dcdB/czyZyqawpU4TraRtpPYniyRON2GIBd2Q/9j2hsHjwuvAKJd7DTy+wBEXdZWmbGS tNMBKe2xB8kOuBj9Qi+U7GZkQyzMwaVQL4uPo9Y1poUi0pbDJeybiZgIiytIzFoGkP/O 2MlG3Eg+BmkNzNOKa27EXR2nkvALtnmBwL2mdUt3jdY4dPbJNB889UPnZ0grgQdOSKQY meHg== 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=RTwhiGGQI56EX7zxVFVkZMzvQ6KeYwPMuBINHNN78VE=; b=tclm2T0b0KnrfNdBa7s/QgVAXMDrRchJUTk/EjnQavPX1bCagy6eXfP6T4XMQUP4sG yXGBXFZm7gc3RpSGXFFYULJjkY8z8EPYyI/g1M2vMgEU+xOL8smRSHTg9I1EcXatpMGr gojrzNEN9dBCWjbJjr3wXaRtgku7eibICEZVYn2CrChaGLrr8SsFWZVP0AKXz9qW6H7x oWY2t2CBF/A7ggeFhlnu4428gyG1a7s2h/VmiuL5AhP1MjdSE7rrTyHBkT6dXJN/D15a PRTXcrBlD/2y18+47WiiVxKzoUxzfEYrY8uirrGeGkvCaS7bJaSxcUWdDvKqDWiR6Mfr TGTQ== X-Gm-Message-State: APjAAAX6UpEzoIBi2T38vdHGtToGus0AHaDSVNt2Z2go621ELdYs5T8y WnLf9Wl03u7efEGZgGXT+HTufogf X-Google-Smtp-Source: APXvYqyRHkjTZZl+/60KbQcFfgrS+yISYTsqFIRNx0NMCxjA+oFiT4bdf2xXudW1TLILVE9y6hjjJg== X-Received: by 2002:a17:902:a98b:: with SMTP id bh11mr8058652plb.281.1574917812910; Wed, 27 Nov 2019 21:10:12 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id j20sm17799838pff.182.2019.11.27.21.10.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2019 21:10:12 -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 , Jack Pham , linux-usb@vger.kernel.org, devicetree@vger.kernel.org, John Stultz Subject: [PATCH v6 8/8] misc: hisi_hikey_usb: Driver to support usb functionality of Hikey960 Date: Thu, 28 Nov 2019 05:10:01 +0000 Message-Id: <20191128051001.18995-9-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191128051001.18995-1-john.stultz@linaro.org> References: <20191128051001.18995-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 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. NOTE: It was noted that controlling the TYPEC_VBUS_POWER_OFF and TYPEC_VBUS_POWER_ON values here is not reccomended. I'm looking for a way to remove that bit from the logic here, but wanted to still get feedback on this approach. 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: Yu Chen [jstultz: Major rework to make the driver a usb-role-switch intermediary] Signed-off-by: John Stultz Change-Id: Icf381520abd46d083750d01f91e478321560fbf9 --- v3: * Major rework to make the driver a usb-role-switch intermediary rather then trying to do notifier callbacks from the role switch logic --- drivers/misc/Kconfig | 6 ++ drivers/misc/Makefile | 1 + drivers/misc/hisi_hikey_usb.c | 178 ++++++++++++++++++++++++++++++++++ 3 files changed, 185 insertions(+) create mode 100644 drivers/misc/hisi_hikey_usb.c -- 2.17.1 diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index 7f0d48f406e3..1d0279b77a12 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -465,6 +465,12 @@ 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 functionality of HiSilicon Hikey Platform" + depends on OF && GPIOLIB + help + If you say yes here you get support for usb functionality of HiSilicon Hikey Platform. + 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");