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);