From patchwork Sun Jul 4 01:33:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 470147 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E0FDC07E98 for ; Sun, 4 Jul 2021 01:31:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E42316144E for ; Sun, 4 Jul 2021 01:31:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229893AbhGDBeE (ORCPT ); Sat, 3 Jul 2021 21:34:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229829AbhGDBeB (ORCPT ); Sat, 3 Jul 2021 21:34:01 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48541C061765 for ; Sat, 3 Jul 2021 18:31:27 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id t6so7527067wrm.9 for ; Sat, 03 Jul 2021 18:31:27 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=1aCHfqIx1OU8E5Hf81YXPP9hGTpgNLpK3KsMYAAxRMM=; b=O9EZzPB6M2qU0A9VAU4mG3WBkYELV4uRugSz5aFORo7amV1CoOytGeg4iLwXvnhKKC GfIBPOxnBSpeDx8xzu/7N+3fVoZ7keEP63qzIEW13elB7VrFI6ObmkAFsYgrpl5lYG6D P5/SbjZuUtcJirDMb3jIZQ0+cLlQk3FOXU19EnAxf1uHhULn+NTtZoSlw7Xt+2Kl8jUM zU8hE/Nf51H6A9IqreUfGtf1wZjs9Tdpgj1y20A8ZNkxoeTcLxgcxleBYf7tD5bqDsaK vud8DiFCqxhMZNeUvSBmlQlIldwsE/JoS5zgQguP7v9/X6mdyNAAtBYKoXJKfZ1P4XiC +VnQ== 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:mime-version:content-transfer-encoding; bh=1aCHfqIx1OU8E5Hf81YXPP9hGTpgNLpK3KsMYAAxRMM=; b=Mje04rsDv8KvA1cRjPaX5+LfMb8Qm9qrGIBO9T/s5mfRGHKD1FMCX2plyyMqAsEjQv Bdw8qDny/v8jrDhcyhQfKv+Gp+GEv1fpn17lpzf+bYXmiMgoDXwHSUD7PqcYB3Y+xIrN 03rP3G0Z/Lhe0H0389kcQlNW25lopzOFAzQYlpN5lAX+s7DnPIGks863eMloI9VPjfmg 4FPQZZR31l5OTcSy8soHYs1ZFRFNqwIpOF8UAalYC0+p3C/AyvtOYzh4WUo++/hy36sw IrR8Z5uHsbwmQtwuTtjmVnOlm+SdM5CfKcAlG3mPihZlEuE/523Yeo4MJLRcCQtHtrYf JILA== X-Gm-Message-State: AOAM5332bcJTWuu4x2qCGkxS4vNQ4+ZEiW7J1XpIQtxI1iIqPxc/MwQI Ezagyk7Zb7FnRX4/AGswDOSSdQ== X-Google-Smtp-Source: ABdhPJxzKsQOtx1/yTn2mfkNxLDh9GzsX2YrWszklikh6Uqm7cMcelYyJtpQyunkTFqtIJudWF/Rfw== X-Received: by 2002:adf:ec44:: with SMTP id w4mr7843022wrn.200.1625362285794; Sat, 03 Jul 2021 18:31:25 -0700 (PDT) Received: from sagittarius-a.chello.ie (188-141-3-169.dynamic.upc.ie. [188.141.3.169]) by smtp.gmail.com with ESMTPSA id l16sm18026717wmj.47.2021.07.03.18.31.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Jul 2021 18:31:25 -0700 (PDT) From: Bryan O'Donoghue To: balbi@kernel.org, bjorn.andersson@linaro.org, agross@kernel.org, gregkh@linuxfoundation.org, jackp@codeaurora.org, wcheng@codeaurora.org, linux-usb@vger.kernel.org, linux-arm-msm@vger.kernel.org Cc: bryan.odonoghue@linaro.org Subject: [PATCH 1/3] usb: dwc3: dwc3-qcom: Fix typo in the dwc3 vbus override API Date: Sun, 4 Jul 2021 02:33:12 +0100 Message-Id: <20210704013314.200951-2-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210704013314.200951-1-bryan.odonoghue@linaro.org> References: <20210704013314.200951-1-bryan.odonoghue@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Wesley Cheng There was an extra character in the dwc3_qcom_vbus_override_enable() function. Removed the extra character. Signed-off-by: Wesley Cheng Signed-off-by: Bryan O'Donoghue --- drivers/usb/dwc3/dwc3-qcom.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c index 49e6ca94486d..2e61302e3e91 100644 --- a/drivers/usb/dwc3/dwc3-qcom.c +++ b/drivers/usb/dwc3/dwc3-qcom.c @@ -115,7 +115,7 @@ static inline void dwc3_qcom_clrbits(void __iomem *base, u32 offset, u32 val) readl(base + offset); } -static void dwc3_qcom_vbus_overrride_enable(struct dwc3_qcom *qcom, bool enable) +static void dwc3_qcom_vbus_override_enable(struct dwc3_qcom *qcom, bool enable) { if (enable) { dwc3_qcom_setbits(qcom->qscratch_base, QSCRATCH_SS_PHY_CTRL, @@ -136,7 +136,7 @@ static int dwc3_qcom_vbus_notifier(struct notifier_block *nb, struct dwc3_qcom *qcom = container_of(nb, struct dwc3_qcom, vbus_nb); /* enable vbus override for device mode */ - dwc3_qcom_vbus_overrride_enable(qcom, event); + dwc3_qcom_vbus_override_enable(qcom, event); qcom->mode = event ? USB_DR_MODE_PERIPHERAL : USB_DR_MODE_HOST; return NOTIFY_DONE; @@ -148,7 +148,7 @@ static int dwc3_qcom_host_notifier(struct notifier_block *nb, struct dwc3_qcom *qcom = container_of(nb, struct dwc3_qcom, host_nb); /* disable vbus override in host mode */ - dwc3_qcom_vbus_overrride_enable(qcom, !event); + dwc3_qcom_vbus_override_enable(qcom, !event); qcom->mode = event ? USB_DR_MODE_HOST : USB_DR_MODE_PERIPHERAL; return NOTIFY_DONE; @@ -811,7 +811,7 @@ static int dwc3_qcom_probe(struct platform_device *pdev) /* enable vbus override for device mode */ if (qcom->mode == USB_DR_MODE_PERIPHERAL) - dwc3_qcom_vbus_overrride_enable(qcom, true); + dwc3_qcom_vbus_override_enable(qcom, true); /* register extcon to override sw_vbus on Vbus change later */ ret = dwc3_qcom_register_extcon(qcom); From patchwork Sun Jul 4 01:33:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 470026 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp2750724jao; Sat, 3 Jul 2021 18:31:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyPYFPRSrBCt5QByMld39IAShk5173oegY4dCAxgUYBfFRM1UGebRD16aUsGo7dUvYF3g0C X-Received: by 2002:aa7:d78b:: with SMTP id s11mr7756901edq.280.1625362297928; Sat, 03 Jul 2021 18:31:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625362297; cv=none; d=google.com; s=arc-20160816; b=SBD1YlWcmzJRG5/EaoWI4MMzVQ8tiEMHNbz/cFSDW1cyT57jYPGK1xnVM946Ala4tU 9rWUxINty68KuhfbMN8/7Mki/Ri6XPS5ZQl7JhsWaTyrHD6lAHw3vAs1XgoJsx6lBz6m tkXnJdQ12AA7PvVrIpGkEMCGEOR2m7WV7QpGZmUnEYp5A2nva8373aInR7yOIrrVvsDr 6QK/W53gnPzSoRKM65WSKP+blCXO4bZgXgx+V3+wyOOppXf2OLuimryUstncSHGtkJkx 5kN2a139q6Uq9sjiEISv0MGfpNO50EiQtSW0KM+fdaP2DRrJcYFBB0SieIiWG07MAh5b 2V+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=EMD8qfF1dzvm6y6ijOX74BiBQ0mTKe538HfIYXSpB48=; b=K/McmLIdW+m8hE0wT2Ugh9rFo4u+6xtouhgaqYRduMp3SUf0bysj4aUplWmFfNNH8T 3Vk6EakVfkmRe9XHsQe/AeSSMO/9mK3UvGjthVltK3rGXBvmeZOBvP6tUQDTCMs16Ehk tj9pYZJWgXF4TbE5ieEo8deIfs/fni0qQ6fkaRmlT6NWY76vxrMtEBTbnydo0W8l0rGd iz+kMfnBPNajiQDy40e+Q6HJWcp0DgTw+oqbTffsN82MBaHCri0CYh7765g085ypMrx9 Vr4BDfgRcPovSoaikHFff9pavx+LJsIxk+SyPYihs/w4+wYuIlpAh3Dfo4ylvLGq1ITV OFbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=z1NOuv63; spf=pass (google.com: domain of linux-usb-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o14si7191136edc.159.2021.07.03.18.31.37; Sat, 03 Jul 2021 18:31:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-usb-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=z1NOuv63; spf=pass (google.com: domain of linux-usb-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229876AbhGDBeE (ORCPT + 4 others); Sat, 3 Jul 2021 21:34:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229847AbhGDBeC (ORCPT ); Sat, 3 Jul 2021 21:34:02 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18F1FC061762 for ; Sat, 3 Jul 2021 18:31:28 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id u8-20020a7bcb080000b02901e44e9caa2aso8873281wmj.4 for ; Sat, 03 Jul 2021 18:31:28 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=EMD8qfF1dzvm6y6ijOX74BiBQ0mTKe538HfIYXSpB48=; b=z1NOuv63K6os5DFYjSOiLakriNjE+iyW/5Y5PvHWxyvsSrHDaenXPSVKYgDxu5MgGi 3PSqatwIbKY8mbdFI2XZhEkqRbK26lGnwkyjGBxCkO/6G5VzzoBLhYb+LfMLtfs1iYSr MwcaBuB2KApZvFUPNxWwEikVx95pZot3Picw2DSUbiCNOfTe0E0w/VFUgbT5SIlcbWPx 8D3yZcP910ZWa5+Wyh6z7/3XkCZeSdxWUYBwQ/O7hnKv9WZsXR71CRcXGJGdnfaYwJkh ZBzXaz1Jrt97nTscVIIvhnijuL9rkeImbeeqDuTEFEjR8jIGrXslmFDxnFTxqO3HGHvB cHhg== 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:mime-version:content-transfer-encoding; bh=EMD8qfF1dzvm6y6ijOX74BiBQ0mTKe538HfIYXSpB48=; b=WcoFKtcPqQDR7t3vJrqsTMfCaR8PBBSlbHH6jVcBJ34EF5LMptZHtyx4vEOwwB784S zjf0lv+o9CdxBYJuzwqUSxHIeMaCFuWcwgzjBdbgYm6wCwpnRScWchKvEMPlzsIoMsQW mr1EgyJArJ9gK5TibIyTQ53+g/7p4y/YofcsRrsDcnjHinp9FydYiIvokBMs/VUiqrVX tu7ropUADGmBfZEiEW2TzalYVgI1JITckWSO7u0bwzCiCmEGg1onDV4Dr3kKkRL4oXTS 4GVo7ueoI/oWTSPuIXePOVuaU8LUI6E/zKTHamrd2MmK9DuXWIgMmC6IIQt7qN2FcKcp iNUA== X-Gm-Message-State: AOAM532YeGL+RRyQEz8P+T2W/rsKYCeyWbVxfAsIalMBN54ul8N41szj yLAj4sbx11o6lHcHTAunk9f+LA== X-Received: by 2002:a05:600c:14c6:: with SMTP id i6mr7346634wmh.169.1625362286780; Sat, 03 Jul 2021 18:31:26 -0700 (PDT) Received: from sagittarius-a.chello.ie (188-141-3-169.dynamic.upc.ie. [188.141.3.169]) by smtp.gmail.com with ESMTPSA id l16sm18026717wmj.47.2021.07.03.18.31.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Jul 2021 18:31:26 -0700 (PDT) From: Bryan O'Donoghue To: balbi@kernel.org, bjorn.andersson@linaro.org, agross@kernel.org, gregkh@linuxfoundation.org, jackp@codeaurora.org, wcheng@codeaurora.org, linux-usb@vger.kernel.org, linux-arm-msm@vger.kernel.org Cc: bryan.odonoghue@linaro.org Subject: [PATCH 2/3] usb: dwc3: Add role switch relay support Date: Sun, 4 Jul 2021 02:33:13 +0100 Message-Id: <20210704013314.200951-3-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210704013314.200951-1-bryan.odonoghue@linaro.org> References: <20210704013314.200951-1-bryan.odonoghue@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Add the ability to relay a role switch message from the core to the parent device of the controller. This is useful for the qcom-dwc3 wrapper which wants to receive role-switch notifications in order to waggle internal SoC UTMI signals. Having the core trigger the parent wrapper has the advantage of keeping the connector mechanism agnostic from dwc3 wrapper code and means that any other wrapper implementation on any other SoC or architecture need not write custom code to find various types of Type-C role switch mechanisms. Signed-off-by: Bryan O'Donoghue --- drivers/usb/dwc3/core.h | 2 ++ drivers/usb/dwc3/drd.c | 10 ++++++++++ 2 files changed, 12 insertions(+) -- 2.30.1 diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index dccdf13b5f9e..974104cc16f7 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -993,6 +993,7 @@ struct dwc3_scratchpad_array { * - USBPHY_INTERFACE_MODE_UTMI * - USBPHY_INTERFACE_MODE_UTMIW * @role_sw: usb_role_switch handle + * @role_sw_relay: usb_role_switch relay handle * @role_switch_default_mode: default operation mode of controller while * usb role is USB_ROLE_NONE. * @usb_psy: pointer to power supply interface. @@ -1136,6 +1137,7 @@ struct dwc3 { struct notifier_block edev_nb; enum usb_phy_interface hsphy_mode; struct usb_role_switch *role_sw; + struct usb_role_switch *role_sw_relay; enum usb_dr_mode role_switch_default_mode; struct power_supply *usb_psy; diff --git a/drivers/usb/dwc3/drd.c b/drivers/usb/dwc3/drd.c index 8fcbac10510c..74293861bd8f 100644 --- a/drivers/usb/dwc3/drd.c +++ b/drivers/usb/dwc3/drd.c @@ -507,6 +507,9 @@ static int dwc3_usb_role_switch_set(struct usb_role_switch *sw, } dwc3_set_mode(dwc, mode); + if (dwc->role_sw_relay) + usb_role_switch_set_role(dwc->role_sw_relay, role); + return 0; } @@ -563,6 +566,10 @@ static int dwc3_setup_role_switch(struct dwc3 *dwc) if (IS_ERR(dwc->role_sw)) return PTR_ERR(dwc->role_sw); + dwc->role_sw_relay = usb_role_switch_get(dwc->dev); + if (IS_ERR(dwc->role_sw_relay)) + return PTR_ERR(dwc->role_sw_relay); + dwc3_set_mode(dwc, mode); return 0; } @@ -630,6 +637,9 @@ void dwc3_drd_exit(struct dwc3 *dwc) { unsigned long flags; + if (dwc->role_sw_relay) + usb_role_switch_put(dwc->role_sw_relay); + if (dwc->role_sw) usb_role_switch_unregister(dwc->role_sw); From patchwork Sun Jul 4 01:33:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 470027 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp2750734jao; Sat, 3 Jul 2021 18:31:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzIA7Xm1KHAequlvKc5SjY3MRFPOcvM9SrwjdWFzRZF5r/ddfgfgd8oyW7L5Kk0Rrb3HA5K X-Received: by 2002:a50:eb8c:: with SMTP id y12mr7744184edr.191.1625362298763; Sat, 03 Jul 2021 18:31:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625362298; cv=none; d=google.com; s=arc-20160816; b=MukmkiAMTeHUdSOxmZUTQHoUR3BcJ8ZpM9Lfi5b2ACxHPMnbxDVIIGrqXNRqWjMqj6 HlxImhxnaudzykGRxRIIwzyk22dbe50h046luJIGpS6Dsiy0FOmNRs3Hc2vCD6V9WYfa NrKjKjZe5McM+LaB7c0o9u9oenZQItnAJp/GjrochBYW4+KYyv895ivC9QxbzkDvz+J7 x+/Q9ED+AxpRLxbDKWtOauayUm0OgT59vYiT0mL+xyCRaonQ5pYZyO6MzbIGFKClNAlV 90M8ve/ytPRyzm+Z5ZRv4ysTDlkl30ERm3UTKKVDVmwqHcNMQAHK8IBOEjgLPPIczCvr MKMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=FJTWw8Pi2vNY+U/Yk6KX19a+CG+yNBMYeBmGQoKmOCU=; b=SC1T3WR3KWkdV+oWqSZykdzonClxeQkiewtxDAhp+klNo44b0OL2OXr8RBYaEPk8AP 5Qv5O44fsvIopmEBvC2quowLaMWq8HaZiJn840sjbg1RJ05YWoZyiWmZWTKbqm4rJkks R3uk87yFZTF20R9yfMG8cAPM681yJmeJLqZNzU9FS3/d74y3nOFnkN0z+sMD7Z5x4jYw JdLOP1z6gCQAREsgaBHgZ2nrOsvh6nYmCitORqqiEIouFzbSmpFd9wO5DRvBG0I7Bjcf sCflF52Uwj4LhWd/kjsJzRAfZ0glAkVhCB3e3mAawEEd3W+aNiSp88zYOEr6zA1SjV8T Tm5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rqXZU9YR; spf=pass (google.com: domain of linux-usb-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o14si7191136edc.159.2021.07.03.18.31.38; Sat, 03 Jul 2021 18:31:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-usb-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rqXZU9YR; spf=pass (google.com: domain of linux-usb-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229917AbhGDBeF (ORCPT + 4 others); Sat, 3 Jul 2021 21:34:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229865AbhGDBeE (ORCPT ); Sat, 3 Jul 2021 21:34:04 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36AA9C061764 for ; Sat, 3 Jul 2021 18:31:29 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id a5-20020a7bc1c50000b02901e3bbe0939bso8909318wmj.0 for ; Sat, 03 Jul 2021 18:31:29 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=FJTWw8Pi2vNY+U/Yk6KX19a+CG+yNBMYeBmGQoKmOCU=; b=rqXZU9YRXFxZkySDque6oPwZjmqJhZOeR8WiZxDmp2XG/CFk5RYWQkdi1neHe5Dq7r 6aGKn2kUVYRSg48L5OeiAPhspN5USvha5PROuXO3BdMZRUu++SgZswhnHawmWY8/9P92 IS3uLN2iOlSFzz4KP+aoSr7UWnhcAMjOi2eeRdAUNx02ngJ8lH1wBgvr4kObEX+ZyROz gxP1/HgFPI1AfkOeyjjBesPNEKI8xq/XCNCYauIzD0a99WWUhWpl2RdOXVFbwCdSCDKZ YkO1n6ojzAxydTLJq5IHvfKlO1pUdS5j67mtS2/4G10GMpUXki7qPvApqVFdo0bbF5i3 dsOA== 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:mime-version:content-transfer-encoding; bh=FJTWw8Pi2vNY+U/Yk6KX19a+CG+yNBMYeBmGQoKmOCU=; b=NMKlunaYYYwXtMdlYNZmE80ofyY3U6xm9TCnx1F2iJvjSlgO7UvXOXn7Mb32YA8mBv oHmD+FQvTye4Cs1MAxGVRegkE8EcMbYzZ7pZkD19VvAWPON6eQMbIZ7NgNWrUY03TuFD yBPoVf+8lQVWKmxRAAIEPj4Ne1b61qrhGibpyHTsW0dTYBHZA0jyVoANreq6/8ARHsxM u+tA6S6Ugfqm6JQBvJNct7ZcBlJxVJ35K/t3uDuqMGKba+KvgssaUe0Df7NH9Q8rJO31 0bfZ7yylWK57Uek6vlQZufzWUZhkezJ56DhgsxmXqAxNwp1rdL4B+NcY1SN2MQmKTeU/ o3FA== X-Gm-Message-State: AOAM533IAttvFKFQYKW4sKGdWvZhGU379sqE/x3R7hTW97p20mW2X/Z4 y6hThIwnSRW8iThK6QAdNZZCUw== X-Received: by 2002:a1c:35c2:: with SMTP id c185mr7013862wma.126.1625362287881; Sat, 03 Jul 2021 18:31:27 -0700 (PDT) Received: from sagittarius-a.chello.ie (188-141-3-169.dynamic.upc.ie. [188.141.3.169]) by smtp.gmail.com with ESMTPSA id l16sm18026717wmj.47.2021.07.03.18.31.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Jul 2021 18:31:27 -0700 (PDT) From: Bryan O'Donoghue To: balbi@kernel.org, bjorn.andersson@linaro.org, agross@kernel.org, gregkh@linuxfoundation.org, jackp@codeaurora.org, wcheng@codeaurora.org, linux-usb@vger.kernel.org, linux-arm-msm@vger.kernel.org Cc: bryan.odonoghue@linaro.org Subject: [PATCH 3/3] usb: dwc3: dwc3-qcom: Make dwc3-qcom a role-switch signal recipient Date: Sun, 4 Jul 2021 02:33:14 +0100 Message-Id: <20210704013314.200951-4-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210704013314.200951-1-bryan.odonoghue@linaro.org> References: <20210704013314.200951-1-bryan.odonoghue@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org When switching role from host to peripheral or peripheral to host we need to set SoC UTMI signal logic in software since this is not done automatically by the PHY or DWC3 core. We have existing extcon code in dwc3-qcom which already implements the right logic for extcon based systems, however, as we move to USB role-switching we need to similarly facilitate the same UTMI switch notification. Setting the dwc3-qcom wrapper up as a USB role switch signal recipient allows us to replicate the extcon logic with the role-switch API by receiving the set_role() from dwc3-core and calling the existing VBUS extcon code. Signed-off-by: Bryan O'Donoghue --- drivers/usb/dwc3/dwc3-qcom.c | 69 ++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) -- 2.30.1 diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c index 2e61302e3e91..1aec387a8537 100644 --- a/drivers/usb/dwc3/dwc3-qcom.c +++ b/drivers/usb/dwc3/dwc3-qcom.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "core.h" @@ -81,6 +82,7 @@ struct dwc3_qcom { struct extcon_dev *host_edev; struct notifier_block vbus_nb; struct notifier_block host_nb; + struct usb_role_switch *role_sw; const struct dwc3_acpi_pdata *acpi_pdata; @@ -154,6 +156,66 @@ static int dwc3_qcom_host_notifier(struct notifier_block *nb, return NOTIFY_DONE; } +#if IS_ENABLED(CONFIG_USB_ROLE_SWITCH) +static int dwc3_qcom_usb_role_switch_set(struct usb_role_switch *sw, + enum usb_role role) +{ + struct dwc3_qcom *qcom = usb_role_switch_get_drvdata(sw); + bool enable; + + switch (role) { + case USB_ROLE_DEVICE: + qcom->mode = USB_DR_MODE_PERIPHERAL; + enable = true; + break; + case USB_ROLE_HOST: + default: + qcom->mode = USB_DR_MODE_HOST; + enable = false; + break; + } + + dwc3_qcom_vbus_override_enable(qcom, enable); + return 0; +} + +static enum usb_role dwc3_qcom_usb_role_switch_get(struct usb_role_switch *sw) +{ + struct dwc3_qcom *qcom = usb_role_switch_get_drvdata(sw); + enum usb_role role; + + switch (qcom->mode) { + case USB_DR_MODE_PERIPHERAL: + role = USB_ROLE_DEVICE; + break; + case USB_DR_MODE_HOST: + default: + role = USB_ROLE_HOST; + break; + } + + return role; +} + +static int dwc3_qcom_setup_role_switch(struct dwc3_qcom *qcom) +{ + struct usb_role_switch_desc dwc3_qcom_role_switch = {NULL}; + + dwc3_qcom_role_switch.fwnode = dev_fwnode(qcom->dev); + dwc3_qcom_role_switch.set = dwc3_qcom_usb_role_switch_set; + dwc3_qcom_role_switch.get = dwc3_qcom_usb_role_switch_get; + dwc3_qcom_role_switch.driver_data = qcom; + qcom->role_sw = usb_role_switch_register(qcom->dev, + &dwc3_qcom_role_switch); + if (IS_ERR(qcom->role_sw)) + return PTR_ERR(qcom->role_sw); + + return 0; +} +#else +#define dwc3_qcom_setup_role_switch(x) 0 +#endif + static int dwc3_qcom_register_extcon(struct dwc3_qcom *qcom) { struct device *dev = qcom->dev; @@ -818,6 +880,10 @@ static int dwc3_qcom_probe(struct platform_device *pdev) if (ret) goto interconnect_exit; + ret = dwc3_qcom_setup_role_switch(qcom); + if (ret) + goto interconnect_exit; + device_init_wakeup(&pdev->dev, 1); qcom->is_suspended = false; pm_runtime_set_active(dev); @@ -850,6 +916,9 @@ static int dwc3_qcom_remove(struct platform_device *pdev) struct device *dev = &pdev->dev; int i; + if (qcom->role_sw) + usb_role_switch_unregister(qcom->role_sw); + device_remove_software_node(&qcom->dwc3->dev); of_platform_depopulate(dev);