From patchwork Thu Aug 4 15:09:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12936479 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6CDCC25B07 for ; Thu, 4 Aug 2022 15:10:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239801AbiHDPKV (ORCPT ); Thu, 4 Aug 2022 11:10:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239158AbiHDPKD (ORCPT ); Thu, 4 Aug 2022 11:10:03 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFBE35F9B8; Thu, 4 Aug 2022 08:09:57 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 80347B824B9; Thu, 4 Aug 2022 15:09:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1FB1BC433B5; Thu, 4 Aug 2022 15:09:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1659625795; bh=su1qZdfKRKL1PgRyMjnBJaoi0zKc/vCrn+42pIEye6Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I4nrMAiTzXcGOE38UQFzJeLJ0KEjb8TOsucdYwnEHRn6lPP+73Xl2YAA77ps1Amil /TAZDZ4jizpFS+Z+5Iz9YH7rdMvJY1P/UVSZqAUZVoK0si76yDr1BcBzpijIF+IWFt P85p08xAxnPbPZX6ZA2bvOMLwlsXqxKH8AiNiH24wjyXQxyERgp475FP9L6657H3Ge QjqB8fmwrbIKAdwsA+1s3rWDVNp7o9lNBjDX8CLcVD+ChDwU4acLlhcRrBbbTEyQzY qE7JJaQPwiu2I5zW3H/nOKzOxhkWo6F1kapxlYLJpbt8sekO5+bOeWi40ekccp+K5s hdB93JQkp/OSg== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1oJcUK-00069Q-Sm; Thu, 04 Aug 2022 17:10:16 +0200 From: Johan Hovold To: Greg Kroah-Hartman , Felipe Balbi Cc: Rob Herring , Krzysztof Kozlowski , Andy Gross , Bjorn Andersson , Manivannan Sadhasivam , Konrad Dybcio , Krishna Kurapati , Stephen Boyd , Doug Anderson , "Matthias Kaehlcke" , Pavankumar Kondeti , quic_ppratap@quicinc.com, quic_vpulyala@quicinc.com, linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold , stable@vger.kernel.org, Andrew Halaney Subject: [PATCH v2 1/9] usb: dwc3: fix PHY disable sequence Date: Thu, 4 Aug 2022 17:09:53 +0200 Message-Id: <20220804151001.23612-2-johan+linaro@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220804151001.23612-1-johan+linaro@kernel.org> References: <20220804151001.23612-1-johan+linaro@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Generic PHYs must be powered-off before they can be tore down. Similarly, suspending legacy PHYs after having powered them off makes no sense. Fix the dwc3_core_exit() (e.g. called during suspend) and open-coded dwc3_probe() error-path sequences that got this wrong. Note that this makes dwc3_core_exit() match the dwc3_core_init() error path with respect to powering off the PHYs. Fixes: 03c1fd622f72 ("usb: dwc3: core: add phy cleanup for probe error handling") Fixes: c499ff71ff2a ("usb: dwc3: core: re-factor init and exit paths") Cc: stable@vger.kernel.org # 4.8 Reviewed-by: Andrew Halaney Reviewed-by: Matthias Kaehlcke Signed-off-by: Johan Hovold Reviewed-by: Manivannan Sadhasivam --- drivers/usb/dwc3/core.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index c5c238ab3083..16d1f328775f 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -833,15 +833,16 @@ static void dwc3_core_exit(struct dwc3 *dwc) { dwc3_event_buffers_cleanup(dwc); + usb_phy_set_suspend(dwc->usb2_phy, 1); + usb_phy_set_suspend(dwc->usb3_phy, 1); + phy_power_off(dwc->usb2_generic_phy); + phy_power_off(dwc->usb3_generic_phy); + usb_phy_shutdown(dwc->usb2_phy); usb_phy_shutdown(dwc->usb3_phy); phy_exit(dwc->usb2_generic_phy); phy_exit(dwc->usb3_generic_phy); - usb_phy_set_suspend(dwc->usb2_phy, 1); - usb_phy_set_suspend(dwc->usb3_phy, 1); - phy_power_off(dwc->usb2_generic_phy); - phy_power_off(dwc->usb3_generic_phy); dwc3_clk_disable(dwc); reset_control_assert(dwc->reset); } @@ -1879,16 +1880,16 @@ static int dwc3_probe(struct platform_device *pdev) dwc3_debugfs_exit(dwc); dwc3_event_buffers_cleanup(dwc); - usb_phy_shutdown(dwc->usb2_phy); - usb_phy_shutdown(dwc->usb3_phy); - phy_exit(dwc->usb2_generic_phy); - phy_exit(dwc->usb3_generic_phy); - usb_phy_set_suspend(dwc->usb2_phy, 1); usb_phy_set_suspend(dwc->usb3_phy, 1); phy_power_off(dwc->usb2_generic_phy); phy_power_off(dwc->usb3_generic_phy); + usb_phy_shutdown(dwc->usb2_phy); + usb_phy_shutdown(dwc->usb3_phy); + phy_exit(dwc->usb2_generic_phy); + phy_exit(dwc->usb3_generic_phy); + dwc3_ulpi_exit(dwc); err4: From patchwork Thu Aug 4 15:09:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12936474 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE55AC19F2A for ; Thu, 4 Aug 2022 15:10:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239674AbiHDPKJ (ORCPT ); Thu, 4 Aug 2022 11:10:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239442AbiHDPKE (ORCPT ); Thu, 4 Aug 2022 11:10:04 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA2F01CFE0; Thu, 4 Aug 2022 08:09:59 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 6D5DAB82497; Thu, 4 Aug 2022 15:09:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 22423C43470; Thu, 4 Aug 2022 15:09:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1659625795; bh=Oc10iKL8iP3YYDdhgl1EaSJB79hlUqWQiGPijpdOAlg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M/dTJjrnZ7EHr13yxDEuywog5hxIlSiQ0Lvyi3jbZCkrWQAhhS56SXanqaBqgGDiW RKH9LvbPlKRwb4oLKyFIhUJOG2J3YlowoUHej6DjoKM3IGHVpI6Wy7jqpbAJKVjhEl pz+gDs1t6jWr4Y5+A2Bh+wWpKFXjFX2zu9XYC+gocvoYmORsEFZz76Z+950ylSktcA jF5fbPK3i05lG4XDPdeU9d0VsvjcsLEnYaHV06aH6c8JMRBcn85UapeHOJZbN8xFR6 L4y8h9JsEbN9Rs1a3IcTr6a5/gk9TplUYdZeg9flb91vppZTox79xuX56SbN+WC1Pb NhACaAYrdBgEA== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1oJcUK-00069S-VJ; Thu, 04 Aug 2022 17:10:16 +0200 From: Johan Hovold To: Greg Kroah-Hartman , Felipe Balbi Cc: Rob Herring , Krzysztof Kozlowski , Andy Gross , Bjorn Andersson , Manivannan Sadhasivam , Konrad Dybcio , Krishna Kurapati , Stephen Boyd , Doug Anderson , "Matthias Kaehlcke" , Pavankumar Kondeti , quic_ppratap@quicinc.com, quic_vpulyala@quicinc.com, linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH v2 2/9] Revert "usb: dwc3: qcom: Keep power domain on to retain controller status" Date: Thu, 4 Aug 2022 17:09:54 +0200 Message-Id: <20220804151001.23612-3-johan+linaro@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220804151001.23612-1-johan+linaro@kernel.org> References: <20220804151001.23612-1-johan+linaro@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org This reverts commit d9be8d5c5b032e5383ff5c404ff4155e9c705429. Generic power-domain flags must be set before the power-domain is initialised and must specifically not be modified by drivers for devices that happen to be in the domain. To make sure that USB power-domains are left enabled during system suspend when a device in the domain is in the wakeup path, the GENPD_FLAG_ACTIVE_WAKEUP flag should instead be set for the domain unconditionally when it is registered. Note that this also avoids keeping power-domains on during suspend when wakeup has not been enabled (e.g. through sysfs). For the runtime PM case, making sure that the PHYs are not suspended and that they are in the same domain as the controller prevents the domain from being suspended. If there are cases where this is not possible or desirable, the genpd implementation may need to be extended. Fixes: d9be8d5c5b03 ("usb: dwc3: qcom: Keep power domain on to retain controller status") Signed-off-by: Johan Hovold Reviewed-by: Manivannan Sadhasivam --- drivers/usb/dwc3/dwc3-qcom.c | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c index c5e482f53e9d..be2e3dd36440 100644 --- a/drivers/usb/dwc3/dwc3-qcom.c +++ b/drivers/usb/dwc3/dwc3-qcom.c @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include @@ -757,13 +756,12 @@ dwc3_qcom_create_urs_usb_platdev(struct device *dev) static int dwc3_qcom_probe(struct platform_device *pdev) { - struct device_node *np = pdev->dev.of_node; - struct device *dev = &pdev->dev; - struct dwc3_qcom *qcom; - struct resource *res, *parent_res = NULL; - int ret, i; - bool ignore_pipe_clk; - struct generic_pm_domain *genpd; + struct device_node *np = pdev->dev.of_node; + struct device *dev = &pdev->dev; + struct dwc3_qcom *qcom; + struct resource *res, *parent_res = NULL; + int ret, i; + bool ignore_pipe_clk; qcom = devm_kzalloc(&pdev->dev, sizeof(*qcom), GFP_KERNEL); if (!qcom) @@ -772,8 +770,6 @@ static int dwc3_qcom_probe(struct platform_device *pdev) platform_set_drvdata(pdev, qcom); qcom->dev = &pdev->dev; - genpd = pd_to_genpd(qcom->dev->pm_domain); - if (has_acpi_companion(dev)) { qcom->acpi_pdata = acpi_device_get_match_data(dev); if (!qcom->acpi_pdata) { @@ -881,17 +877,7 @@ static int dwc3_qcom_probe(struct platform_device *pdev) if (ret) goto interconnect_exit; - if (device_can_wakeup(&qcom->dwc3->dev)) { - /* - * Setting GENPD_FLAG_ALWAYS_ON flag takes care of keeping - * genpd on in both runtime suspend and system suspend cases. - */ - genpd->flags |= GENPD_FLAG_ALWAYS_ON; - device_init_wakeup(&pdev->dev, true); - } else { - genpd->flags |= GENPD_FLAG_RPM_ALWAYS_ON; - } - + device_init_wakeup(&pdev->dev, 1); qcom->is_suspended = false; pm_runtime_set_active(dev); pm_runtime_enable(dev); From patchwork Thu Aug 4 15:09:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12936476 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F16FC25B06 for ; Thu, 4 Aug 2022 15:10:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239595AbiHDPKH (ORCPT ); Thu, 4 Aug 2022 11:10:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238960AbiHDPJ6 (ORCPT ); Thu, 4 Aug 2022 11:09:58 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE1D95B058; Thu, 4 Aug 2022 08:09:56 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 652A361057; Thu, 4 Aug 2022 15:09:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 32B22C43142; Thu, 4 Aug 2022 15:09:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1659625795; bh=0nUc1cjLgUbATBUp1ygr1cIENQBWWUBee5ocGDk1vTU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mXxS3LEc+dPzhq2PcltfIbLgOrAQaJztAULujM3fxXl18fzgzFsOa0z9OPljyVSYr MmrrmTvAn7e3YxG7KCngHFp9pExxnpmj3I1VWkfm0NHw9+ueICDfIPZfuwEQxxBGZJ MStqsnpqBg9ZkYzpPA1Y3FPO0HBrPTIwrJEzHrqwmuFZ/o4hbJPDhy2HxVcMygbTJU xzOa3ovLsxZkRMlNpAdGADVPuhGrGDb14PxE1OrzfaCfx+biwU7H69JX67QL1m9oSs N9JfzlKCi2AM+pq95yYEYdw008H/7Mymn7qv9RYQROdwqWA9/YvaI4qV4EdVjeduXL lirZsjPzFAgSQ== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1oJcUL-00069U-1Y; Thu, 04 Aug 2022 17:10:17 +0200 From: Johan Hovold To: Greg Kroah-Hartman , Felipe Balbi Cc: Rob Herring , Krzysztof Kozlowski , Andy Gross , Bjorn Andersson , Manivannan Sadhasivam , Konrad Dybcio , Krishna Kurapati , Stephen Boyd , Doug Anderson , "Matthias Kaehlcke" , Pavankumar Kondeti , quic_ppratap@quicinc.com, quic_vpulyala@quicinc.com, linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold , Randy Dunlap Subject: [PATCH v2 3/9] usb: dwc3: qcom: fix gadget-only builds Date: Thu, 4 Aug 2022 17:09:55 +0200 Message-Id: <20220804151001.23612-4-johan+linaro@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220804151001.23612-1-johan+linaro@kernel.org> References: <20220804151001.23612-1-johan+linaro@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org A recent change added a dependency to the USB host stack and broke gadget-only builds of the driver. Fixes: 6895ea55c385 ("usb: dwc3: qcom: Configure wakeup interrupts during suspend") Reported-by: Randy Dunlap Signed-off-by: Johan Hovold Reviewed-by: Randy Dunlap --- Changes in v2 - new patch drivers/usb/dwc3/dwc3-qcom.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c index be2e3dd36440..e9364141661b 100644 --- a/drivers/usb/dwc3/dwc3-qcom.c +++ b/drivers/usb/dwc3/dwc3-qcom.c @@ -310,8 +310,11 @@ static enum usb_device_speed dwc3_qcom_read_usb2_speed(struct dwc3_qcom *qcom) * currently supports only 1 port per controller. So * this is sufficient. */ +#ifdef CONFIG_USB udev = usb_hub_find_child(hcd->self.root_hub, 1); - +#else + udev = NULL; +#endif if (!udev) return USB_SPEED_UNKNOWN; From patchwork Thu Aug 4 15:09:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12936478 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 83B74C25B08 for ; Thu, 4 Aug 2022 15:10:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239736AbiHDPKS (ORCPT ); Thu, 4 Aug 2022 11:10:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239339AbiHDPKE (ORCPT ); Thu, 4 Aug 2022 11:10:04 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3491A5FAC0; Thu, 4 Aug 2022 08:09:58 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id AA537B8256B; Thu, 4 Aug 2022 15:09:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2EB34C4347C; Thu, 4 Aug 2022 15:09:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1659625795; bh=OoTOgjpz5JFq6UJf0u64NVueuER3638cyeEWhnzjxUU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JmfxhuYjg1145GVy3MogH8SsRBxtS78xFJ4D0gFXf0HG7VED0UmQzbIg8L4Z9BH97 6DWXHgCtFwwNlBqEWW+1MKcXr2C/2xyR3Z4ReFw+yzJwbs3uNIOidvnYUxCIINcjD/ mAHM9+y9dqv5gweh6PM+GbMRs9Sjm/nJoUcxR5nAeznBdX0d/K/yhstkzRRjXDcZVX OO4tXahmfeNlTIAdNHRWgiO9pwmIWyJaTuiwm7eShthrwY9MQKXL0yCAxJbHet30+9 0u0LRQX47eCYJylOoWUfcpu4z4ijs8Ddc+QA2lwxcy/Egsbd2e9BRDflZXcbPdqtoh TBRceERd6GN3Q== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1oJcUL-00069W-45; Thu, 04 Aug 2022 17:10:17 +0200 From: Johan Hovold To: Greg Kroah-Hartman , Felipe Balbi Cc: Rob Herring , Krzysztof Kozlowski , Andy Gross , Bjorn Andersson , Manivannan Sadhasivam , Konrad Dybcio , Krishna Kurapati , Stephen Boyd , Doug Anderson , "Matthias Kaehlcke" , Pavankumar Kondeti , quic_ppratap@quicinc.com, quic_vpulyala@quicinc.com, linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold , stable@vger.kernel.org Subject: [PATCH v2 4/9] usb: dwc3: qcom: fix use-after-free on runtime-PM wakeup Date: Thu, 4 Aug 2022 17:09:56 +0200 Message-Id: <20220804151001.23612-5-johan+linaro@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220804151001.23612-1-johan+linaro@kernel.org> References: <20220804151001.23612-1-johan+linaro@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The Qualcomm dwc3 runtime-PM implementation checks the xhci platform-device pointer in the wakeup-interrupt handler to determine whether the controller is in host mode and if so triggers a resume. After a role switch in OTG mode the xhci platform-device would have been freed and the next wakeup from runtime suspend would access the freed memory. Note that role switching is executed from a freezable workqueue, which guarantees that the pointer is stable during suspend. Also note that runtime PM has been broken since commit 2664deb09306 ("usb: dwc3: qcom: Honor wakeup enabled/disabled state"), which incidentally also prevents this issue from being triggered. Fixes: a4333c3a6ba9 ("usb: dwc3: Add Qualcomm DWC3 glue driver") Cc: stable@vger.kernel.org # 4.18 Signed-off-by: Johan Hovold Reviewed-by: Matthias Kaehlcke Reviewed-by: Manivannan Sadhasivam --- Changes in v2 - new patch drivers/usb/dwc3/dwc3-qcom.c | 14 +++++++++++++- drivers/usb/dwc3/host.c | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c index e9364141661b..6884026b9fad 100644 --- a/drivers/usb/dwc3/dwc3-qcom.c +++ b/drivers/usb/dwc3/dwc3-qcom.c @@ -298,6 +298,14 @@ static void dwc3_qcom_interconnect_exit(struct dwc3_qcom *qcom) icc_put(qcom->icc_path_apps); } +/* Only usable in contexts where the role can not change. */ +static bool dwc3_qcom_is_host(struct dwc3_qcom *qcom) +{ + struct dwc3 *dwc = platform_get_drvdata(qcom->dwc3); + + return dwc->xhci; +} + static enum usb_device_speed dwc3_qcom_read_usb2_speed(struct dwc3_qcom *qcom) { struct dwc3 *dwc = platform_get_drvdata(qcom->dwc3); @@ -460,7 +468,11 @@ static irqreturn_t qcom_dwc3_resume_irq(int irq, void *data) if (qcom->pm_suspended) return IRQ_HANDLED; - if (dwc->xhci) + /* + * This is safe as role switching is done from a freezable workqueue + * and the wakeup interrupts are disabled as part of resume. + */ + if (dwc3_qcom_is_host(qcom)) pm_runtime_resume(&dwc->xhci->dev); return IRQ_HANDLED; diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c index f56c30cf151e..f6f13e7f1ba1 100644 --- a/drivers/usb/dwc3/host.c +++ b/drivers/usb/dwc3/host.c @@ -135,4 +135,5 @@ int dwc3_host_init(struct dwc3 *dwc) void dwc3_host_exit(struct dwc3 *dwc) { platform_device_unregister(dwc->xhci); + dwc->xhci = NULL; } From patchwork Thu Aug 4 15:09:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12936472 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3751EC25B0C for ; Thu, 4 Aug 2022 15:10:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239540AbiHDPKF (ORCPT ); Thu, 4 Aug 2022 11:10:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238785AbiHDPJ5 (ORCPT ); Thu, 4 Aug 2022 11:09:57 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6896452FF0; Thu, 4 Aug 2022 08:09:56 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D9E4F6101A; Thu, 4 Aug 2022 15:09:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2BA9BC433D7; Thu, 4 Aug 2022 15:09:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1659625795; bh=Dh5hCxqjDHhUUABQ7LhlclsE5NhFFv8vFrTG0pCapLo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XWsrMp4poB2jekVZPx7jyCTLXFEm4nqGvO+xkxyIGetdEyaqZteI30WdzR0tWbh2q nL+uZQDMO3hLf/uNa/GxPfIyjGlfRW4vkj/tG6qf0cWVftsQSqYml0FvqsjT2BbgOG o1yKjH1gbQ8vKdtVjDsethoEq0Z9+UeAvBFohNGuYpwIG/vYMiJl16NYRn64Tey7bP saEyy08H0yrfeCjPTdRmvBSAMs87ZSWPWS2Ocz/G0h6qloj5HzBVEASvHYsEAAafFz 0PJlFrKw/3zIKtD8Vct2cBwpNM/tpZe+GMz2IBsfIbHuDPhTOTgzgftV+2wn9hsyWW K+l0mCIrrOQqQ== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1oJcUL-00069Y-6e; Thu, 04 Aug 2022 17:10:17 +0200 From: Johan Hovold To: Greg Kroah-Hartman , Felipe Balbi Cc: Rob Herring , Krzysztof Kozlowski , Andy Gross , Bjorn Andersson , Manivannan Sadhasivam , Konrad Dybcio , Krishna Kurapati , Stephen Boyd , Doug Anderson , "Matthias Kaehlcke" , Pavankumar Kondeti , quic_ppratap@quicinc.com, quic_vpulyala@quicinc.com, linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH v2 5/9] usb: dwc3: qcom: fix runtime PM wakeup Date: Thu, 4 Aug 2022 17:09:57 +0200 Message-Id: <20220804151001.23612-6-johan+linaro@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220804151001.23612-1-johan+linaro@kernel.org> References: <20220804151001.23612-1-johan+linaro@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org A device must enable wakeups during runtime suspend regardless of whether it is capable and allowed to wake the system up from system suspend. Fixes: 2664deb09306 ("usb: dwc3: qcom: Honor wakeup enabled/disabled state") Signed-off-by: Johan Hovold Reviewed-by: Matthias Kaehlcke Tested-by: Matthias Kaehlcke Reviewed-by: Manivannan Sadhasivam --- drivers/usb/dwc3/dwc3-qcom.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c index 6884026b9fad..05b4666fde14 100644 --- a/drivers/usb/dwc3/dwc3-qcom.c +++ b/drivers/usb/dwc3/dwc3-qcom.c @@ -397,7 +397,7 @@ static void dwc3_qcom_enable_interrupts(struct dwc3_qcom *qcom) dwc3_qcom_enable_wakeup_irq(qcom->ss_phy_irq, 0); } -static int dwc3_qcom_suspend(struct dwc3_qcom *qcom) +static int dwc3_qcom_suspend(struct dwc3_qcom *qcom, bool wakeup) { u32 val; int i, ret; @@ -416,7 +416,7 @@ static int dwc3_qcom_suspend(struct dwc3_qcom *qcom) if (ret) dev_warn(qcom->dev, "failed to disable interconnect: %d\n", ret); - if (device_may_wakeup(qcom->dev)) { + if (wakeup) { qcom->usb2_speed = dwc3_qcom_read_usb2_speed(qcom); dwc3_qcom_enable_interrupts(qcom); } @@ -426,7 +426,7 @@ static int dwc3_qcom_suspend(struct dwc3_qcom *qcom) return 0; } -static int dwc3_qcom_resume(struct dwc3_qcom *qcom) +static int dwc3_qcom_resume(struct dwc3_qcom *qcom, bool wakeup) { int ret; int i; @@ -434,7 +434,7 @@ static int dwc3_qcom_resume(struct dwc3_qcom *qcom) if (!qcom->is_suspended) return 0; - if (device_may_wakeup(qcom->dev)) + if (wakeup) dwc3_qcom_disable_interrupts(qcom); for (i = 0; i < qcom->num_clocks; i++) { @@ -945,9 +945,11 @@ static int dwc3_qcom_remove(struct platform_device *pdev) static int __maybe_unused dwc3_qcom_pm_suspend(struct device *dev) { struct dwc3_qcom *qcom = dev_get_drvdata(dev); + bool wakeup = device_may_wakeup(dev); int ret = 0; - ret = dwc3_qcom_suspend(qcom); + + ret = dwc3_qcom_suspend(qcom, wakeup); if (!ret) qcom->pm_suspended = true; @@ -957,9 +959,10 @@ static int __maybe_unused dwc3_qcom_pm_suspend(struct device *dev) static int __maybe_unused dwc3_qcom_pm_resume(struct device *dev) { struct dwc3_qcom *qcom = dev_get_drvdata(dev); + bool wakeup = device_may_wakeup(dev); int ret; - ret = dwc3_qcom_resume(qcom); + ret = dwc3_qcom_resume(qcom, wakeup); if (!ret) qcom->pm_suspended = false; @@ -970,14 +973,14 @@ static int __maybe_unused dwc3_qcom_runtime_suspend(struct device *dev) { struct dwc3_qcom *qcom = dev_get_drvdata(dev); - return dwc3_qcom_suspend(qcom); + return dwc3_qcom_suspend(qcom, true); } static int __maybe_unused dwc3_qcom_runtime_resume(struct device *dev) { struct dwc3_qcom *qcom = dev_get_drvdata(dev); - return dwc3_qcom_resume(qcom); + return dwc3_qcom_resume(qcom, true); } static const struct dev_pm_ops dwc3_qcom_dev_pm_ops = { From patchwork Thu Aug 4 15:09:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12936473 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D74B8C3F6B0 for ; Thu, 4 Aug 2022 15:10:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239397AbiHDPKE (ORCPT ); Thu, 4 Aug 2022 11:10:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234093AbiHDPJ5 (ORCPT ); Thu, 4 Aug 2022 11:09:57 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 375A651A00; Thu, 4 Aug 2022 08:09:56 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C65296102A; Thu, 4 Aug 2022 15:09:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1D6A4C433C1; Thu, 4 Aug 2022 15:09:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1659625795; bh=VUaMhxBQV8r/Oni90w/+gnoNx4Bzx7lOs5aOtZB5EB0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GoPRHKvmlGVaXGsNbciqHSCl8N4I00QdRgFPkAwt2VxUrNIQBCbZdqmK2xgwy/9ub tcXmJbbbcOh2MoKfMLqhNfDanyrWIm1u0oDzX1rwY62fgZz97V4KUwWUDkqS+Gssaz EdFiyZOcbyQQIwbk4L0AsuoevmXgvweV/I3uI2cnlLIr1vDjVsDzS9e46KphRlEW4j 4gqIdamg4xfDf0HYTXBM7MddJ+Dy/C5I14aURtVMh6mRuR7KfK7125Tvu5MUcCAve0 oSWqjUpugNeIeoZqPdpwBmhSC10ZHrd+wGi2rZc63K5Z0etGRCe6H2lEIVUUOuT7Lu E1yYdAsAeyr3w== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1oJcUL-00069a-99; Thu, 04 Aug 2022 17:10:17 +0200 From: Johan Hovold To: Greg Kroah-Hartman , Felipe Balbi Cc: Rob Herring , Krzysztof Kozlowski , Andy Gross , Bjorn Andersson , Manivannan Sadhasivam , Konrad Dybcio , Krishna Kurapati , Stephen Boyd , Doug Anderson , "Matthias Kaehlcke" , Pavankumar Kondeti , quic_ppratap@quicinc.com, quic_vpulyala@quicinc.com, linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH v2 6/9] usb: dwc3: qcom: fix peripheral and OTG suspend Date: Thu, 4 Aug 2022 17:09:58 +0200 Message-Id: <20220804151001.23612-7-johan+linaro@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220804151001.23612-1-johan+linaro@kernel.org> References: <20220804151001.23612-1-johan+linaro@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org A recent commit implementing wakeup support in host mode instead broke suspend for peripheral and OTG mode. The hack that was added in the suspend path to determine the speed of any device connected to the USB2 bus not only accesses internal driver data for a child device, but also dereferences a NULL pointer or accesses freed data when the controller is not acting as host. There's no quick fix to the layering violation, but since reverting would leave us with broken suspend in host mode with wakeup triggering immediately, let's keep the hack for now. Fix the immediate issues by only checking the host bus speed and enabling wakeup interrupts when acting as host. Fixes: 6895ea55c385 ("usb: dwc3: qcom: Configure wakeup interrupts during suspend") Signed-off-by: Johan Hovold Reported-by: kernel test robot --- Changes in v2 - disable wakeup completely instead of falling back to the "disconnected" host configuration when not acting as host drivers/usb/dwc3/dwc3-qcom.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c index 05b4666fde14..6ae0b7fc4e2c 100644 --- a/drivers/usb/dwc3/dwc3-qcom.c +++ b/drivers/usb/dwc3/dwc3-qcom.c @@ -309,8 +309,13 @@ static bool dwc3_qcom_is_host(struct dwc3_qcom *qcom) static enum usb_device_speed dwc3_qcom_read_usb2_speed(struct dwc3_qcom *qcom) { struct dwc3 *dwc = platform_get_drvdata(qcom->dwc3); - struct usb_hcd *hcd = platform_get_drvdata(dwc->xhci); struct usb_device *udev; + struct usb_hcd *hcd; + + /* + * FIXME: Fix this layering violation. + */ + hcd = platform_get_drvdata(dwc->xhci); /* * It is possible to query the speed of all children of @@ -416,7 +421,11 @@ static int dwc3_qcom_suspend(struct dwc3_qcom *qcom, bool wakeup) if (ret) dev_warn(qcom->dev, "failed to disable interconnect: %d\n", ret); - if (wakeup) { + /* + * The role is stable during suspend as role switching is done from a + * freezable workqueue. + */ + if (dwc3_qcom_is_host(qcom) && wakeup) { qcom->usb2_speed = dwc3_qcom_read_usb2_speed(qcom); dwc3_qcom_enable_interrupts(qcom); } @@ -434,7 +443,7 @@ static int dwc3_qcom_resume(struct dwc3_qcom *qcom, bool wakeup) if (!qcom->is_suspended) return 0; - if (wakeup) + if (dwc3_qcom_is_host(qcom) && wakeup) dwc3_qcom_disable_interrupts(qcom); for (i = 0; i < qcom->num_clocks; i++) { From patchwork Thu Aug 4 15:09:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12936481 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46D53C25B06 for ; Thu, 4 Aug 2022 15:10:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239864AbiHDPKX (ORCPT ); Thu, 4 Aug 2022 11:10:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239029AbiHDPKD (ORCPT ); Thu, 4 Aug 2022 11:10:03 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6247E5E308; Thu, 4 Aug 2022 08:09:57 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 968526106C; Thu, 4 Aug 2022 15:09:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A548C41679; Thu, 4 Aug 2022 15:09:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1659625795; bh=IO2m3x1jImWrsxZYiJ2BMxGUrpa2LxovXjBMsp4YmCo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QanGkkS4xs9guEML3UUpdfeTWuhqiyq1gKgwPxX0liM7aZuxQKXtTSxuFlR5aBUBU 2JLwKWrkuUxAAMKOH8mLsuGPQ2eYFH7zIT54cDycwqHzjYQXB9rQGG092mY+o0g9AU U0WYe8pYX45Z+mxM25zX5lxAhBml0q91KPnohgt+OUYOPCvTLUZjZpKzY7oyRyV5j0 gVlz7IJJkIhOLCUA1lNgtFbVqIR4XdCK8+Sy2DiNUV18khQlQ8oRrhbTTw+rCTyCjl AIulqYUjJl1RC84pkMhtDJTD0Am4w+NNQgswzBDGUw8NOo1nIxzKGCAvRTWac5j6EZ ovUq+BCe8ycVQ== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1oJcUL-00069c-CT; Thu, 04 Aug 2022 17:10:17 +0200 From: Johan Hovold To: Greg Kroah-Hartman , Felipe Balbi Cc: Rob Herring , Krzysztof Kozlowski , Andy Gross , Bjorn Andersson , Manivannan Sadhasivam , Konrad Dybcio , Krishna Kurapati , Stephen Boyd , Doug Anderson , "Matthias Kaehlcke" , Pavankumar Kondeti , quic_ppratap@quicinc.com, quic_vpulyala@quicinc.com, linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold , Rob Herring Subject: [PATCH v2 7/9] dt-bindings: usb: qcom,dwc3: add wakeup-source property Date: Thu, 4 Aug 2022 17:09:59 +0200 Message-Id: <20220804151001.23612-8-johan+linaro@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220804151001.23612-1-johan+linaro@kernel.org> References: <20220804151001.23612-1-johan+linaro@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Add a wakeup-source property to the binding to describe whether the wakeup interrupts can wake the system from suspend. Acked-by: Rob Herring Signed-off-by: Johan Hovold --- Changes in v2 - disallow 'wakeup-source' in child node (Krzysztof) Documentation/devicetree/bindings/usb/qcom,dwc3.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Documentation/devicetree/bindings/usb/qcom,dwc3.yaml b/Documentation/devicetree/bindings/usb/qcom,dwc3.yaml index fea3e7092ace..d5959bdea63e 100644 --- a/Documentation/devicetree/bindings/usb/qcom,dwc3.yaml +++ b/Documentation/devicetree/bindings/usb/qcom,dwc3.yaml @@ -108,12 +108,17 @@ properties: HS/FS/LS modes are supported. type: boolean + wakeup-source: true + # Required child node: patternProperties: "^usb@[0-9a-f]+$": $ref: snps,dwc3.yaml# + properties: + wakeup-source: false + required: - compatible - reg From patchwork Thu Aug 4 15:10:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12936480 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C957AC3F6B0 for ; Thu, 4 Aug 2022 15:10:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238438AbiHDPKT (ORCPT ); Thu, 4 Aug 2022 11:10:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238914AbiHDPKE (ORCPT ); Thu, 4 Aug 2022 11:10:04 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92DDA1F637; Thu, 4 Aug 2022 08:09:58 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 1EBE4B82521; Thu, 4 Aug 2022 15:09:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5672DC43159; Thu, 4 Aug 2022 15:09:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1659625795; bh=AgrQZfa5kuZZEXO/hg1xFcWJZuBRQIUG8Mw/dSpRsM4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Cw4EtrOYS/wDTxjM9Nm9Nv1EmSHMeT0Fgb0dyICUhwaN/4V4HX6NFPDL/FqMOM6gm HKBL/K2Lzx5t0RQt0Niyxj/RP0uO+LTsFUWtG5PQVpqdAgJTHTFtwTM1fyHJfa+Z/0 oU18S8eJpKHtbCdBrx8NZP44K8e/YNwHyFYOPMarxl8bnePJ51+3nVfiFftbfySnHL nIQTMFr4W7YvKhnhxIz+cOt7o7lUOqSPzIYynUJbVQ9bDtSAOApQ08SI+rJ8nWrH+R EP/U7h/RWE2t7JFCteqFJ+VJPUdqRxRLe9zoFk+Ko/DFY4K8yFmiJNGRr9mlCD1HEJ KTJBW0rmJahEg== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1oJcUL-00069e-Ev; Thu, 04 Aug 2022 17:10:17 +0200 From: Johan Hovold To: Greg Kroah-Hartman , Felipe Balbi Cc: Rob Herring , Krzysztof Kozlowski , Andy Gross , Bjorn Andersson , Manivannan Sadhasivam , Konrad Dybcio , Krishna Kurapati , Stephen Boyd , Doug Anderson , "Matthias Kaehlcke" , Pavankumar Kondeti , quic_ppratap@quicinc.com, quic_vpulyala@quicinc.com, linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH v2 8/9] usb: dwc3: qcom: fix wakeup implementation Date: Thu, 4 Aug 2022 17:10:00 +0200 Message-Id: <20220804151001.23612-9-johan+linaro@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220804151001.23612-1-johan+linaro@kernel.org> References: <20220804151001.23612-1-johan+linaro@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org It is the Qualcomm glue wakeup interrupts that may be able to wake the system from suspend and this can now be described in the devicetree. Move the wakeup-source property handling over from the core driver and instead propagate the capability setting to the core device during probe. This is needed as there is currently no way for the core driver to query the wakeup setting of the glue device, but it is the core driver that manages the PHY power state during suspend. Also don't leave the PHYs enabled when system wakeup has been disabled through sysfs. Fixes: 649f5c842ba3 ("usb: dwc3: core: Host wake up support from system suspend") Signed-off-by: Johan Hovold --- drivers/usb/dwc3/core.c | 5 ++--- drivers/usb/dwc3/dwc3-qcom.c | 6 +++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 16d1f328775f..8c8e32651473 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -1822,7 +1822,6 @@ static int dwc3_probe(struct platform_device *pdev) platform_set_drvdata(pdev, dwc); dwc3_cache_hwparams(dwc); - device_init_wakeup(&pdev->dev, of_property_read_bool(dev->of_node, "wakeup-source")); spin_lock_init(&dwc->lock); mutex_init(&dwc->mutex); @@ -1984,7 +1983,7 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg) dwc3_core_exit(dwc); break; case DWC3_GCTL_PRTCAP_HOST: - if (!PMSG_IS_AUTO(msg) && !device_can_wakeup(dwc->dev)) { + if (!PMSG_IS_AUTO(msg) && !device_may_wakeup(dwc->dev)) { dwc3_core_exit(dwc); break; } @@ -2045,7 +2044,7 @@ static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg) spin_unlock_irqrestore(&dwc->lock, flags); break; case DWC3_GCTL_PRTCAP_HOST: - if (!PMSG_IS_AUTO(msg) && !device_can_wakeup(dwc->dev)) { + if (!PMSG_IS_AUTO(msg) && !device_may_wakeup(dwc->dev)) { ret = dwc3_core_init_for_resume(dwc); if (ret) return ret; diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c index 6ae0b7fc4e2c..b05f67d206d2 100644 --- a/drivers/usb/dwc3/dwc3-qcom.c +++ b/drivers/usb/dwc3/dwc3-qcom.c @@ -786,6 +786,7 @@ static int dwc3_qcom_probe(struct platform_device *pdev) struct resource *res, *parent_res = NULL; int ret, i; bool ignore_pipe_clk; + bool wakeup_source; qcom = devm_kzalloc(&pdev->dev, sizeof(*qcom), GFP_KERNEL); if (!qcom) @@ -901,7 +902,10 @@ static int dwc3_qcom_probe(struct platform_device *pdev) if (ret) goto interconnect_exit; - device_init_wakeup(&pdev->dev, 1); + wakeup_source = of_property_read_bool(dev->of_node, "wakeup-source"); + device_init_wakeup(&pdev->dev, wakeup_source); + device_init_wakeup(&qcom->dwc3->dev, wakeup_source); + qcom->is_suspended = false; pm_runtime_set_active(dev); pm_runtime_enable(dev); From patchwork Thu Aug 4 15:10:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12936477 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A1DEC25B07 for ; Thu, 4 Aug 2022 15:10:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239701AbiHDPKR (ORCPT ); Thu, 4 Aug 2022 11:10:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239001AbiHDPKE (ORCPT ); Thu, 4 Aug 2022 11:10:04 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13CFA5FAEA; Thu, 4 Aug 2022 08:10:01 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 2581EB825BC; Thu, 4 Aug 2022 15:09:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5B390C43161; Thu, 4 Aug 2022 15:09:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1659625795; bh=3866X7xrJmyeXtTJewkoWNkQ2GbChpdJNVta1bNWBdE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tNVUVhhtwsUu0LZ4LRZSN142L83weLjz1PEYYw1M4gV9Q1dohaxD4ij8Udv5tNj75 TAxlGxS8Wf46/W5ueBsWbOwmEW94bDJnseguIKeXJwjX+0CVXGi1dP93PJeje5qbSL BdUeiQrC0h6WvL3MhKW2s9atq2PqkgYJvLesIOIYXCCSuNxr0+anRrbGfqaQtVvi+k cjGdDGjtoYUFtmTLDwdr+hcmhbq/VLEBGCKWZ3i7vh2iskHMBYV83NgTnuADRYNbov XSeeFQ0fjzaO1Zkn3o6YNuMb+I7BEARKNh0+6zK6DeMfyKcQNnEeyPlexeUscelV7h Dj8daAwouwJ3Q== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1oJcUL-00069h-IA; Thu, 04 Aug 2022 17:10:17 +0200 From: Johan Hovold To: Greg Kroah-Hartman , Felipe Balbi Cc: Rob Herring , Krzysztof Kozlowski , Andy Gross , Bjorn Andersson , Manivannan Sadhasivam , Konrad Dybcio , Krishna Kurapati , Stephen Boyd , Doug Anderson , "Matthias Kaehlcke" , Pavankumar Kondeti , quic_ppratap@quicinc.com, quic_vpulyala@quicinc.com, linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH v2 9/9] usb: dwc3: qcom: clean up suspend callbacks Date: Thu, 4 Aug 2022 17:10:01 +0200 Message-Id: <20220804151001.23612-10-johan+linaro@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220804151001.23612-1-johan+linaro@kernel.org> References: <20220804151001.23612-1-johan+linaro@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Clean up the suspend callbacks by separating the error and success paths to improve readability. Also drop a related redundant initialisation. Signed-off-by: Johan Hovold Reviewed-by: Matthias Kaehlcke --- drivers/usb/dwc3/dwc3-qcom.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c index b05f67d206d2..197583ff3f3d 100644 --- a/drivers/usb/dwc3/dwc3-qcom.c +++ b/drivers/usb/dwc3/dwc3-qcom.c @@ -959,14 +959,15 @@ static int __maybe_unused dwc3_qcom_pm_suspend(struct device *dev) { struct dwc3_qcom *qcom = dev_get_drvdata(dev); bool wakeup = device_may_wakeup(dev); - int ret = 0; - + int ret; ret = dwc3_qcom_suspend(qcom, wakeup); - if (!ret) - qcom->pm_suspended = true; + if (ret) + return ret; - return ret; + qcom->pm_suspended = true; + + return 0; } static int __maybe_unused dwc3_qcom_pm_resume(struct device *dev) @@ -976,10 +977,12 @@ static int __maybe_unused dwc3_qcom_pm_resume(struct device *dev) int ret; ret = dwc3_qcom_resume(qcom, wakeup); - if (!ret) - qcom->pm_suspended = false; + if (ret) + return ret; - return ret; + qcom->pm_suspended = false; + + return 0; } static int __maybe_unused dwc3_qcom_runtime_suspend(struct device *dev)