From patchwork Tue Dec 10 17:13:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Th=C3=A9o_Lebrun?= X-Patchwork-Id: 849701 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 734FA23026D; Tue, 10 Dec 2024 17:13:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.200 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733850826; cv=none; b=edBanwJnS9r3pK/xvqZTzWhiXyPrNQ2ydz4+qKruBYO5NwXcFHFRGXjE2jO7KqgpH2lnmaF/aQScffCKtM/Xf+X3uL1s5FO6i/NO7k0URwjpdTOxEfa3yke/SDHRii69BDG0jNIrndlF+jAXCy4Ej415+RTcme0PIjzw9FZTRVs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733850826; c=relaxed/simple; bh=P2ybhwiaAEo5zqDnmO0bfMMdOZU6kC+tTJbq97Bs7SE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=t1548ygmMrjpXMW/6VHWwYnCxB0zfJsxBwN1u11YPQnQwjpxg5n2scafEJJUvj4WEdQuh4FaUgxCVlozOzr51ILnW8qCLvXZTxio7T+4VHIIMXkNxuSC6VTakUG2rOt5GLCTVg5MuDw+61tzvIqBbBnqoBS/67/ThIWT77nqS9g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=M2uVttoR; arc=none smtp.client-ip=217.70.183.200 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="M2uVttoR" Received: by mail.gandi.net (Postfix) with ESMTPSA id A556520007; Tue, 10 Dec 2024 17:13:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1733850817; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/tR8jxZL7KCmAOaMVEX6FEebB34Nu9WebzBzDww28IY=; b=M2uVttoRZYAVWJPMsGmDwIJGH6F32U8iMZ+urTehHOQOjN6uraIcC1kuDDmtLQoi7Jo55q gPcA2Jnva2Qx0eIVDoQScJmpNGxzpatt3Xl6bB7DnLhMnzMXwkkcFat4Rt/M+R0qR23QHC 7vjUcuGzVbIuPldYTiUY8GeSQjB94lsMPWbHnnB8n83w9B8YhdEQJx4kAuiwch2krmOoa8 c3Zp27WOtFHdSbrV6XSigR7My0WV3Wb43c3UKM7mUFH4ZxVQWZdI4Ps9PPRTCQV5y1nBmi 4Jqrbvf/Ml5dNTpK/LD7vsgHjjU0mJze2lmyWW6yHgSx3Al6C7blXP3bqkVHpQ== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Tue, 10 Dec 2024 18:13:35 +0100 Subject: [PATCH v6 1/5] usb: cdns3-ti: move reg writes to separate function Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241210-s2r-cdns-v6-1-28a17f9715a2@bootlin.com> References: <20241210-s2r-cdns-v6-0-28a17f9715a2@bootlin.com> In-Reply-To: <20241210-s2r-cdns-v6-0-28a17f9715a2@bootlin.com> To: Peter Chen , Pawel Laszczak , Roger Quadros , Greg Kroah-Hartman , Mathias Nyman Cc: =?utf-8?q?Gr=C3=A9gory_Clement?= , Thomas Petazzoni , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Th=C3=A9o_Lebrun?= X-Mailer: b4 0.14.2 X-GND-Sasl: theo.lebrun@bootlin.com The device probe function mixes management code and hardware initialisation code. Extract the latter into an explicitly named cdns_ti_reset_and_init_hw() function to clarify intent. It also will allow easier transition to using runtime PM for triggering HW init. Signed-off-by: Théo Lebrun Reviewed-by: Roger Quadros --- drivers/usb/cdns3/cdns3-ti.c | 84 ++++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 38 deletions(-) diff --git a/drivers/usb/cdns3/cdns3-ti.c b/drivers/usb/cdns3/cdns3-ti.c index 040bb91e9c017d8298a7e251fd0e192a336e8a52..d704eb39820ad08a8774be7f00aa473c3ff267c0 100644 --- a/drivers/usb/cdns3/cdns3-ti.c +++ b/drivers/usb/cdns3/cdns3-ti.c @@ -58,6 +58,7 @@ struct cdns_ti { unsigned vbus_divider:1; struct clk *usb2_refclk; struct clk *lpm_clk; + int usb2_refclk_rate_code; }; static const int cdns_ti_rate_table[] = { /* in KHZ */ @@ -98,15 +99,52 @@ static const struct of_dev_auxdata cdns_ti_auxdata[] = { {}, }; +static void cdns_ti_reset_and_init_hw(struct cdns_ti *data) +{ + u32 reg; + + /* assert RESET */ + reg = cdns_ti_readl(data, USBSS_W1); + reg &= ~USBSS_W1_PWRUP_RST; + cdns_ti_writel(data, USBSS_W1, reg); + + /* set static config */ + reg = cdns_ti_readl(data, USBSS_STATIC_CONFIG); + reg &= ~USBSS1_STATIC_PLL_REF_SEL_MASK; + reg |= data->usb2_refclk_rate_code << USBSS1_STATIC_PLL_REF_SEL_SHIFT; + + reg &= ~USBSS1_STATIC_VBUS_SEL_MASK; + + if (data->vbus_divider) + reg |= 1 << USBSS1_STATIC_VBUS_SEL_SHIFT; + + cdns_ti_writel(data, USBSS_STATIC_CONFIG, reg); + reg = cdns_ti_readl(data, USBSS_STATIC_CONFIG); + + /* set USB2_ONLY mode if requested */ + reg = cdns_ti_readl(data, USBSS_W1); + + if (data->usb2_only) + reg |= USBSS_W1_USB2_ONLY; + + /* set default modestrap */ + reg |= USBSS_W1_MODESTRAP_SEL; + reg &= ~USBSS_W1_MODESTRAP_MASK; + reg |= USBSS_MODESTRAP_MODE_NONE << USBSS_W1_MODESTRAP_SHIFT; + cdns_ti_writel(data, USBSS_W1, reg); + + /* de-assert RESET */ + reg |= USBSS_W1_PWRUP_RST; + cdns_ti_writel(data, USBSS_W1, reg); +} + static int cdns_ti_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct device_node *node = pdev->dev.of_node; struct cdns_ti *data; - int error; - u32 reg; - int rate_code, i; unsigned long rate; + int error, i; data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); if (!data) @@ -146,7 +184,11 @@ static int cdns_ti_probe(struct platform_device *pdev) return -EINVAL; } - rate_code = i; + data->usb2_refclk_rate_code = i; + data->vbus_divider = device_property_read_bool(dev, "ti,vbus-divider"); + data->usb2_only = device_property_read_bool(dev, "ti,usb2-only"); + + cdns_ti_reset_and_init_hw(data); pm_runtime_enable(dev); error = pm_runtime_get_sync(dev); @@ -155,40 +197,6 @@ static int cdns_ti_probe(struct platform_device *pdev) goto err; } - /* assert RESET */ - reg = cdns_ti_readl(data, USBSS_W1); - reg &= ~USBSS_W1_PWRUP_RST; - cdns_ti_writel(data, USBSS_W1, reg); - - /* set static config */ - reg = cdns_ti_readl(data, USBSS_STATIC_CONFIG); - reg &= ~USBSS1_STATIC_PLL_REF_SEL_MASK; - reg |= rate_code << USBSS1_STATIC_PLL_REF_SEL_SHIFT; - - reg &= ~USBSS1_STATIC_VBUS_SEL_MASK; - data->vbus_divider = device_property_read_bool(dev, "ti,vbus-divider"); - if (data->vbus_divider) - reg |= 1 << USBSS1_STATIC_VBUS_SEL_SHIFT; - - cdns_ti_writel(data, USBSS_STATIC_CONFIG, reg); - reg = cdns_ti_readl(data, USBSS_STATIC_CONFIG); - - /* set USB2_ONLY mode if requested */ - reg = cdns_ti_readl(data, USBSS_W1); - data->usb2_only = device_property_read_bool(dev, "ti,usb2-only"); - if (data->usb2_only) - reg |= USBSS_W1_USB2_ONLY; - - /* set default modestrap */ - reg |= USBSS_W1_MODESTRAP_SEL; - reg &= ~USBSS_W1_MODESTRAP_MASK; - reg |= USBSS_MODESTRAP_MODE_NONE << USBSS_W1_MODESTRAP_SHIFT; - cdns_ti_writel(data, USBSS_W1, reg); - - /* de-assert RESET */ - reg |= USBSS_W1_PWRUP_RST; - cdns_ti_writel(data, USBSS_W1, reg); - error = of_platform_populate(node, NULL, cdns_ti_auxdata, dev); if (error) { dev_err(dev, "failed to create children: %d\n", error); From patchwork Tue Dec 10 17:13:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Th=C3=A9o_Lebrun?= X-Patchwork-Id: 849098 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 69641230267; Tue, 10 Dec 2024 17:13:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.200 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733850826; cv=none; b=YeXIajJ7qhnREyuX2W5QhRErxixih76BJreVSg6Ona+It4YD00K1zH+sZ6W1ro1hXRlE1dQqcAmlHV2sNTv9KiauuofXr5/TmQNT7pYJJn3ZuDfQqPL7NT6MaMCAlSK3G3t7AaUsAMISgQdl6qtP0dm9JvGOAM7b/6H4Sf8IOrM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733850826; c=relaxed/simple; bh=yXVDYOaFNfqyTkNQE0fHYz5+EtCSfCYIRXZ7RoLTbas=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=d4kWJ1pp4bcAJBzil2EKj0NzIDmWs0BfIEzJihzRQe5ZAKV/yaAYMD4do/DnXjanbMTVTMxhqbW6kN9r89R5bJbY/0OBGoHEvpjg9MnERaIBbs4onOK/+H/yzZ6icGGhp99vNZGoNt1qLFKj3+WhjEyfxcUq5XUj9XTB8JUlz74= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=YqVBcQyo; arc=none smtp.client-ip=217.70.183.200 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="YqVBcQyo" Received: by mail.gandi.net (Postfix) with ESMTPSA id 429B72000C; Tue, 10 Dec 2024 17:13:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1733850817; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SXXuJ7wjA+iPshQUOOp+J39ONzwVePGwpts3g/T0ovA=; b=YqVBcQyoYn7xBCN0Cy6z0YgVsDD5jX0PT/xOUz/vhOwpe25Zxt9LKLlTneWzidOsOOo/j5 Gj102J+1nrVaUo/bvL4AMoDEVEBmzota6FVlnLvlCPktpUoNk9+k3HhSuZNVqZfzsLehS/ 5jlVEkvOTxNdhRv+BXnmvDBCjKHLJ5iNQUSxbxc7nrIXuhAq1K0f65E22JZ5TBLCg4m6zK 0Pwzs3qBDyVxNJ0GMok63n++Ue7CwK4DfY460DU0LumcGEuEaIedMeE5GiYZHYSZDeb+88 m2V92uMa3MXeAbQNbAudMQmH3II9/leCsG4H7Y3OmrhNsKVWkwqqUszvVsZt8g== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Tue, 10 Dec 2024 18:13:36 +0100 Subject: [PATCH v6 2/5] usb: cdns3-ti: run HW init at resume() if HW was reset Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241210-s2r-cdns-v6-2-28a17f9715a2@bootlin.com> References: <20241210-s2r-cdns-v6-0-28a17f9715a2@bootlin.com> In-Reply-To: <20241210-s2r-cdns-v6-0-28a17f9715a2@bootlin.com> To: Peter Chen , Pawel Laszczak , Roger Quadros , Greg Kroah-Hartman , Mathias Nyman Cc: =?utf-8?q?Gr=C3=A9gory_Clement?= , Thomas Petazzoni , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Th=C3=A9o_Lebrun?= X-Mailer: b4 0.14.2 X-GND-Sasl: theo.lebrun@bootlin.com At runtime_resume(), read the W1 (Wrapper Register 1) register to detect if an hardware reset occurred. If it did, run the hardware init sequence. This callback will be called at system-wide resume. Previously, if a reset occurred during suspend, we would crash. The wrapper config had not been written, leading to invalid register accesses inside cdns3. Signed-off-by: Théo Lebrun --- drivers/usb/cdns3/cdns3-ti.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/usb/cdns3/cdns3-ti.c b/drivers/usb/cdns3/cdns3-ti.c index d704eb39820ad08a8774be7f00aa473c3ff267c0..d35be7db7616ef5e5bed7dbd53b78a094809f7cc 100644 --- a/drivers/usb/cdns3/cdns3-ti.c +++ b/drivers/usb/cdns3/cdns3-ti.c @@ -188,6 +188,12 @@ static int cdns_ti_probe(struct platform_device *pdev) data->vbus_divider = device_property_read_bool(dev, "ti,vbus-divider"); data->usb2_only = device_property_read_bool(dev, "ti,usb2-only"); + /* + * The call below to pm_runtime_get_sync() MIGHT reset hardware, if it + * detects it as uninitialised. We want to enforce a reset at probe, + * and so do it manually here. This means the first runtime_resume() + * will be a no-op. + */ cdns_ti_reset_and_init_hw(data); pm_runtime_enable(dev); @@ -232,6 +238,24 @@ static void cdns_ti_remove(struct platform_device *pdev) platform_set_drvdata(pdev, NULL); } +static int cdns_ti_runtime_resume(struct device *dev) +{ + const u32 mask = USBSS_W1_PWRUP_RST | USBSS_W1_MODESTRAP_SEL; + struct cdns_ti *data = dev_get_drvdata(dev); + u32 w1; + + w1 = cdns_ti_readl(data, USBSS_W1); + if ((w1 & mask) != mask) + cdns_ti_reset_and_init_hw(data); + + return 0; +} + +static const struct dev_pm_ops cdns_ti_pm_ops = { + RUNTIME_PM_OPS(NULL, cdns_ti_runtime_resume, NULL) + SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume) +}; + static const struct of_device_id cdns_ti_of_match[] = { { .compatible = "ti,j721e-usb", }, { .compatible = "ti,am64-usb", }, @@ -245,6 +269,7 @@ static struct platform_driver cdns_ti_driver = { .driver = { .name = "cdns3-ti", .of_match_table = cdns_ti_of_match, + .pm = pm_ptr(&cdns_ti_pm_ops), }, }; From patchwork Tue Dec 10 17:13:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Th=C3=A9o_Lebrun?= X-Patchwork-Id: 849097 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 42EF3230270; Tue, 10 Dec 2024 17:13:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.200 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733850827; cv=none; b=l3xKdIVUtMbH+E5YDExtUlpclbMIRc8RqE37wVo41pe/hE7kd5QVa2dNWIiQbgMDkyGbvh4puxovsGeismwfcCSgm6leky7l0Wp4L1xl/1LbbU0bcg5ZUEeFODBkbVP+rK7dut6+/6kyaXGvHJ4BPRqaW0FTs8X7ldEGzoBjof0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733850827; c=relaxed/simple; bh=mdJ4Yl47PnEzv9c2hypcphFiiwdt7zCFBGbUseQ4OSY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ApYvaIAA3hxR1WV7zIbPcMDdsxRwc3eDNdyEbrI86F1NIa9tXIFHgWuAKljgX7UmAP5ij547lYY7ZIrJZtqrsxhFhLmGX+qet+25wEeje8kpdTgLBkBBEBgmKzIBkqSCVHzrVQt+X33sgnSEaJfTXqRmvQISl0oNvrkTNKUED7A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=hwotXmKx; arc=none smtp.client-ip=217.70.183.200 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="hwotXmKx" Received: by mail.gandi.net (Postfix) with ESMTPSA id AF5E22000D; Tue, 10 Dec 2024 17:13:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1733850818; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4QOmrfIdw5tljAsHY3LWcjFY4d7/dE+fB5Plerk04QQ=; b=hwotXmKxcHubbrw+/mwJjp9xXtP+TIE4y3J2xJ6/TjbpdcCyPpMXoVaMJWLSrreMpiyCfc QAzGD8A9D7ngLZ33jWRnVL5e8pbdS/rnEg32Kzo8i7kAZNrvJ4LGoauyelux++SBHtEPS4 ujPWRroGbqA4s0WitecLd/XrfD0UXT3wyqtEGPp1JXEso/qXqZCuwt4ysQQ2sKeExVgsZU DRaN8vtYoocZO7/VnDPgKxyH17ZmOMr2f4+xTSNW0sd1r758HSANwP2E29MqSh7jtbXLcj FJFDcWMgYy+X9jauwVxq8cCjxC7KCbg4dfPzIqaHMD8z9aoF7lnLRRr47oeGng== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Tue, 10 Dec 2024 18:13:37 +0100 Subject: [PATCH v6 3/5] usb: cdns3: rename hibernated argument of role->resume() to lost_power Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241210-s2r-cdns-v6-3-28a17f9715a2@bootlin.com> References: <20241210-s2r-cdns-v6-0-28a17f9715a2@bootlin.com> In-Reply-To: <20241210-s2r-cdns-v6-0-28a17f9715a2@bootlin.com> To: Peter Chen , Pawel Laszczak , Roger Quadros , Greg Kroah-Hartman , Mathias Nyman Cc: =?utf-8?q?Gr=C3=A9gory_Clement?= , Thomas Petazzoni , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Th=C3=A9o_Lebrun?= X-Mailer: b4 0.14.2 X-GND-Sasl: theo.lebrun@bootlin.com The cdns_role_driver->resume() callback takes a second boolean argument named `hibernated` in its implementations. This is mistaken; the only potential caller is: int cdns_resume(struct cdns *cdns) { /* ... */ if (cdns->roles[cdns->role]->resume) cdns->roles[cdns->role]->resume(cdns, cdns_power_is_lost(cdns)); return 0; } The argument can be true in cases outside of return from hibernation. Reflect the true meaning by renaming both arguments to `lost_power`. Signed-off-by: Théo Lebrun --- drivers/usb/cdns3/cdns3-gadget.c | 4 ++-- drivers/usb/cdns3/cdnsp-gadget.c | 2 +- drivers/usb/cdns3/core.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/usb/cdns3/cdns3-gadget.c b/drivers/usb/cdns3/cdns3-gadget.c index fd1beb10bba726cef258e7438d642f31d6567dfe..694aa14577390b6e9a98ce8c4685ac8f56e43ad4 100644 --- a/drivers/usb/cdns3/cdns3-gadget.c +++ b/drivers/usb/cdns3/cdns3-gadget.c @@ -3468,7 +3468,7 @@ __must_hold(&cdns->lock) return 0; } -static int cdns3_gadget_resume(struct cdns *cdns, bool hibernated) +static int cdns3_gadget_resume(struct cdns *cdns, bool lost_power) { struct cdns3_device *priv_dev = cdns->gadget_dev; @@ -3476,7 +3476,7 @@ static int cdns3_gadget_resume(struct cdns *cdns, bool hibernated) return 0; cdns3_gadget_config(priv_dev); - if (hibernated) + if (lost_power) writel(USB_CONF_DEVEN, &priv_dev->regs->usb_conf); return 0; diff --git a/drivers/usb/cdns3/cdnsp-gadget.c b/drivers/usb/cdns3/cdnsp-gadget.c index 4a3f0f95825698f0524cace5c06bfcf27f763149..7d05180442fb94c5d1aab3d8ef766e365685f454 100644 --- a/drivers/usb/cdns3/cdnsp-gadget.c +++ b/drivers/usb/cdns3/cdnsp-gadget.c @@ -1973,7 +1973,7 @@ static int cdnsp_gadget_suspend(struct cdns *cdns, bool do_wakeup) return 0; } -static int cdnsp_gadget_resume(struct cdns *cdns, bool hibernated) +static int cdnsp_gadget_resume(struct cdns *cdns, bool lost_power) { struct cdnsp_device *pdev = cdns->gadget_dev; enum usb_device_speed max_speed; diff --git a/drivers/usb/cdns3/core.h b/drivers/usb/cdns3/core.h index 57d47348dc193b1060f4543c2ef22905f464293b..921cccf1ca9db27a66b06c7c7873b13537c74b05 100644 --- a/drivers/usb/cdns3/core.h +++ b/drivers/usb/cdns3/core.h @@ -30,7 +30,7 @@ struct cdns_role_driver { int (*start)(struct cdns *cdns); void (*stop)(struct cdns *cdns); int (*suspend)(struct cdns *cdns, bool do_wakeup); - int (*resume)(struct cdns *cdns, bool hibernated); + int (*resume)(struct cdns *cdns, bool lost_power); const char *name; #define CDNS_ROLE_STATE_INACTIVE 0 #define CDNS_ROLE_STATE_ACTIVE 1 From patchwork Tue Dec 10 17:13:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Th=C3=A9o_Lebrun?= X-Patchwork-Id: 849700 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 42F2E230273; Tue, 10 Dec 2024 17:13:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.200 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733850827; cv=none; b=mDroX5hcZSbaLV0KNddeVR7w7+uOgRV1G5+kzuITmTv7GdlQTXu2Vt66L9r3gKrZ+dxbreMGIDg5lb2r7uFLUXkhBvaA22KULpxa8bwBgsE7m2yb1hT/NgiZct7b4lQv3fNolc0x6MXA0tUPr5DsALQYjzJZKuns/DPKRHBTsKM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733850827; c=relaxed/simple; bh=RZTHxmapeucOexmFPnmzZCVbnuq6HB5uGQZRbjl6/7Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YRGNeMBI9HbDGoCqETveJJRRS8okOUnfkgsZiXkAMMndb0Ok+i68E3MVg4b4pP3qF4gm9Ev3maE5UBpKLgxornIJJDtTf0yFh4oEcyBtzEPH4hMxPTRWtcE0uVXD3XP29348RhAO+888kC/8FMEzbbRSToXdo5gLqylBBEYfRbA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=nQPlrBap; arc=none smtp.client-ip=217.70.183.200 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="nQPlrBap" Received: by mail.gandi.net (Postfix) with ESMTPSA id 401CE20004; Tue, 10 Dec 2024 17:13:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1733850818; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HTIBfuiAvxsPW2OOJUD1BM9AQyXTmQykYBAwFkvsm3w=; b=nQPlrBapthHzpSb79T7d+w6sDG1BUKV9X6/Gv2R6DkzACxHSgYKLCKWoGsaoX3CPIemkP6 cboCh/y/6YpSCaipSNfsrPipJWiOdId2HJplgvaAgAwjfupA0JKKm97RpsaiSr4PyyEQJS YoqyazlxJPgznwBL8NPYsP7oMFdssHO651D/GHPHikk17saoPnpKqMwr7Vxb7FJqfxjFoZ 2nzuOlT5OsHKSWHLdwK0XUW/qDKeScU/+KYC2MRvKoBE8uvbl0S2e8XXYRzTBEs1/BZX8S hWN0LTiNKgW/kexg2YGrRdUTEYBeHtllqIPvLCwaQ+hr5kTMj82UXWihglf5LQ== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Tue, 10 Dec 2024 18:13:38 +0100 Subject: [PATCH v6 4/5] xhci: introduce xhci->lost_power flag Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241210-s2r-cdns-v6-4-28a17f9715a2@bootlin.com> References: <20241210-s2r-cdns-v6-0-28a17f9715a2@bootlin.com> In-Reply-To: <20241210-s2r-cdns-v6-0-28a17f9715a2@bootlin.com> To: Peter Chen , Pawel Laszczak , Roger Quadros , Greg Kroah-Hartman , Mathias Nyman Cc: =?utf-8?q?Gr=C3=A9gory_Clement?= , Thomas Petazzoni , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Th=C3=A9o_Lebrun?= X-Mailer: b4 0.14.2 X-GND-Sasl: theo.lebrun@bootlin.com The XHCI_RESET_ON_RESUME quirk allows wrappers to signal that they expect a reset after resume. It is also used by some to enforce a XHCI reset on resume (see needs-reset-on-resume DT prop). Some wrappers are unsure beforehands if they will reset. Add a mechanism to signal *at resume* if power has been lost. Parent devices can set this flag, that defaults to false. The XHCI_RESET_ON_RESUME quirk still triggers a runtime_pm_get() on the controller. This is required as we do not know if a suspend will trigger a reset, so the best guess is to avoid runtime PM. Signed-off-by: Théo Lebrun --- drivers/usb/host/xhci.c | 3 ++- drivers/usb/host/xhci.h | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 5ebde8cae4fc44cdb997b0f61314e309bda56c0d..ae2c8daa206a87da24d58a62b0a0485ebf68cdd6 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -1017,7 +1017,8 @@ int xhci_resume(struct xhci_hcd *xhci, pm_message_t msg) spin_lock_irq(&xhci->lock); - if (hibernated || xhci->quirks & XHCI_RESET_ON_RESUME || xhci->broken_suspend) + if (hibernated || xhci->quirks & XHCI_RESET_ON_RESUME || + xhci->broken_suspend || xhci->lost_power) reinit_xhc = true; if (!reinit_xhc) { diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 4914f0a10cff42dbc1448dcf7908534d582c848e..32526df75925989d40cbe7d59a187c945f498a30 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1645,6 +1645,12 @@ struct xhci_hcd { unsigned broken_suspend:1; /* Indicates that omitting hcd is supported if root hub has no ports */ unsigned allow_single_roothub:1; + /* + * Signal from upper stacks that we lost power during system-wide + * suspend. Its default value is based on XHCI_RESET_ON_RESUME, meaning + * it is safe for wrappers to not modify lost_power at resume. + */ + unsigned lost_power:1; /* cached extended protocol port capabilities */ struct xhci_port_cap *port_caps; unsigned int num_port_caps; From patchwork Tue Dec 10 17:13:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Th=C3=A9o_Lebrun?= X-Patchwork-Id: 849096 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BCDC423027A; Tue, 10 Dec 2024 17:13:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.200 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733850828; cv=none; b=KI3RECW27QJw8GCHzKYuEpH9TO/K3SVaesECDUOMogdPjup4Svfv0xdJBrbyxulbosnRxAla1ZsTbXd5dUjrdWY1Ehh68atnJJigLCUhdLkGpIEOWpkW0gXyC+82E4Nmf1zd0I8dfejMSqcwBU1nXYqvoMUG+QOpvk2d9YWhUs4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733850828; c=relaxed/simple; bh=9UworTV+MS2F0uSh6HanIBJMieYjtOPqmcELQRuAOVY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tzyXkC4/LrlTAOJHAvU7PMuNdPw8fzEdjKBaSypY4Z9+yE4HzGBKQa/cc8CO8P6MQCYNi7I82/64XAeTNqRYqs+gWsNIXPZjeoMfhQ5WfkGZU4yn2cZ2HWMjPj4nela+zVcbvDAoHpyEcVFYzj3JSJBb3ZCDIEwQPUF82NXgTvg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=TGrBid1D; arc=none smtp.client-ip=217.70.183.200 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="TGrBid1D" Received: by mail.gandi.net (Postfix) with ESMTPSA id B86C02000E; Tue, 10 Dec 2024 17:13:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1733850819; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XbbIr+l87r3GthSaZw6V9C5/nV0qXTuiEhfkpu/VVQc=; b=TGrBid1DB4hY47GDZhFwerb5YK19J+jimSLkvBYdsxe/UU8cx7N/KYmeP9P9+UC7fA7+2p MmyYFqKIrwHfgfYItFEQW8a3V1bQlzjh7tlIuQEwc+BZITlDg5povEMNqGsXqTGD6Zldq+ kp/0uzP5ffFmd0kLjCnPi/Cc2TRxIUjlsmKR8vGmCwron/n1LMjlbb7etJ4vSAEvlYBKNs VHXgcrDJ19S7ylH7yKtQ+b4aYqajd7cOPmnWOo1ZzrTGVYVZgJUsTrKfteV+sXQ+9gstqd shmZeEoQ3xP02jiIYsKlpch6pgXgjkxFFOO0iRTZT8akGN1x3D7aHk8pjdZEXQ== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Tue, 10 Dec 2024 18:13:39 +0100 Subject: [PATCH v6 5/5] usb: cdns3: host: transmit lost_power signal from wrapper to XHCI Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241210-s2r-cdns-v6-5-28a17f9715a2@bootlin.com> References: <20241210-s2r-cdns-v6-0-28a17f9715a2@bootlin.com> In-Reply-To: <20241210-s2r-cdns-v6-0-28a17f9715a2@bootlin.com> To: Peter Chen , Pawel Laszczak , Roger Quadros , Greg Kroah-Hartman , Mathias Nyman Cc: =?utf-8?q?Gr=C3=A9gory_Clement?= , Thomas Petazzoni , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Th=C3=A9o_Lebrun?= X-Mailer: b4 0.14.2 X-GND-Sasl: theo.lebrun@bootlin.com cdns_role_driver->resume() receives the information if power was lost across suspend (ie if a reset occurred). Transmit that to the XHCI core using the newly introduced lost_power flag. Signed-off-by: Théo Lebrun --- drivers/usb/cdns3/host.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/usb/cdns3/host.c b/drivers/usb/cdns3/host.c index 7ba760ee62e3310e9c678d269d7675c9cb952ec6..01a3d6aad12886096ab2833a7bc276467f08cb1a 100644 --- a/drivers/usb/cdns3/host.c +++ b/drivers/usb/cdns3/host.c @@ -138,6 +138,15 @@ static void cdns_host_exit(struct cdns *cdns) cdns_drd_host_off(cdns); } +static int cdns_host_resume(struct cdns *cdns, bool lost_power) +{ + struct usb_hcd *hcd = platform_get_drvdata(cdns->host_dev); + struct xhci_hcd *xhci = hcd_to_xhci(hcd); + + xhci->lost_power = lost_power; + return 0; +} + int cdns_host_init(struct cdns *cdns) { struct cdns_role_driver *rdrv; @@ -148,6 +157,7 @@ int cdns_host_init(struct cdns *cdns) rdrv->start = __cdns_host_init; rdrv->stop = cdns_host_exit; + rdrv->resume = cdns_host_resume; rdrv->state = CDNS_ROLE_STATE_INACTIVE; rdrv->name = "host";