From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6C5F1CD3436 for ; Tue, 5 May 2026 10:07:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=LfmEKuSDebMAxunONx1yWbnk6UZDGWJuV+B1JzN3k24=; b=d6xcmLeyvraOasHZWAf6vGTjz5 jhLUIGNNdyOo5UV+44/KZkCRsqaErQhdamvRgJWOqxwXp1+7sKS4p5lqGv0B/NmD0VzrwBH7759uS n5EtJXoipxVqqIcfP1LmCPVEzdGtiEdBdjzAl67jIHTq+Z/Fj1wXl13I1nQowjd6wEWlhUP19xROc 4fp5fPD5tU0hdksZJuRqwQ/yIOEblCK0dOeCRWcwP2012ETko9OlaCrWwp/ZNnFIuOOCaCR81JNGF EEARkO1CIZgKx+4kQaOrFsF/0FukJdpGePEqJrJjWnpuiccE9LYhoXQfFp6XXYQacqvSbI10Hvi5R mnp8BllQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1wKCgF-0000000FmSS-3LAE; Tue, 05 May 2026 10:07:07 +0000 Received: from mail-swedencentralazlp170130007.outbound.protection.outlook.com ([2a01:111:f403:c202::7] helo=GVXPR05CU001.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1wKCfW-0000000Fkdf-3tmY; Tue, 05 May 2026 10:06:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=G98hC7npOLIMH62MxkJDUAMJRszlDgMXd7xLvb3e1p1ObammOhDIlP5IO0dsrgsR2mgRM+vGL3ZKuRsZct+bXCUeey3tcF1afDIxcWDSBF02MXPlFgbSgjNAtWelPWLIzClTpCkmYwRoKdPNUtqUqBqlEiPNPXIIW9A9JNkWUj/RhwBZ4Xqz/k4BNcqSIQFl3vBE3qaUU1gKuoSNeYg4Kt9Dcy1g4Oiokq9M3zXtjzO6E3Dvhbunq2WcYgtnKWNxJl6YZ4N2bfiOVMeAQ9IN15Jq6FV9LvKQYJWTPVFr0pRJK4tve4sodJm/T0cu3XzhngXvAboUIO43va15NcF0lA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=LfmEKuSDebMAxunONx1yWbnk6UZDGWJuV+B1JzN3k24=; b=eGpmAe7tNXUNj+VmivAv2BWz/oYqER3iVI9HG1oMZPrx0tGDDR/GCbSTcHAWw+6yj7eabe/IfkOQmGc8s3rjy6Redn9gXM0WD53ksx9bC777SAqVZD5NjwLdwsUpcP4hsyQ4hY9tSylT6f3GAAaa+MPRn3IRgZ9h1PYHinAlTqVPdUi/oMqsHLypxDPmXJS/IMd0/KcEQONHquV9YPvAF9LU3OEjKiyALf6e8gRPS3ikrwKOp4TQJdKVrDdRxoq+hE6ufGJB+4WgjohxPYlM2BsGHsMg3+jXbJSPhyy9yzwuFricqG4T99pfe60hKGDNXJffzjKLEOHa/ki99kG8LA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LfmEKuSDebMAxunONx1yWbnk6UZDGWJuV+B1JzN3k24=; b=cNQxRuTNSB1LEy6NBckZ1ok4y+QQHgkQbu9mh1IPhHoiGpW46UY2hrJys7s37ZgYbvas00Mg4K/CTvuBHwfVcq3tlo6wNFAuahYU5f8+rI5SmTeZ1sqIK5k24+G1A/1NOz6q1GZgJnLMaZKKs3d39LgvFTXEQ7yBEPZHSelmZYfdC1shoyvu6xQPjl2aiauJoDOl3DN2vz3sT5LZLBLdbMzIlrlxfy39YBYBAP8QEZhBw+5/N2rvmdI0SrG2aHfjiBhtCUKJaD5THkmHdSfmjc5kipZmZxCL9c0U3LkuMsYPrzWF/bGhbfLGYK0Hwyjof4raKDaEC0LN1nSjvZqVsQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM9PR04MB8585.eurprd04.prod.outlook.com (2603:10a6:20b:438::13) by DB9PR04MB8363.eurprd04.prod.outlook.com (2603:10a6:10:24b::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9846.26; Tue, 5 May 2026 10:06:03 +0000 Received: from AM9PR04MB8585.eurprd04.prod.outlook.com ([fe80::f010:fca8:7ef:62f4]) by AM9PR04MB8585.eurprd04.prod.outlook.com ([fe80::f010:fca8:7ef:62f4%4]) with mapi id 15.20.9870.023; Tue, 5 May 2026 10:06:03 +0000 From: Vladimir Oltean To: linux-phy@lists.infradead.org Cc: Vinod Koul , Neil Armstrong , dri-devel@lists.freedesktop.org, freedreno@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-can@vger.kernel.org, linux-gpio@vger.kernel.org, linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-pci@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-scsi@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, linux-usb@vger.kernel.org, netdev@vger.kernel.org, spacemit@lists.linux.dev, UNGLinuxDriver@microchip.com, Can Guo , "James E.J. Bottomley" , "Martin K. Petersen" , Dmitry Baryshkov , Nitin Rawat , Manivannan Sadhasivam Subject: [PATCH v8 phy-next 13/31] scsi: ufs: qcom: keep separate track of PHY power state Date: Tue, 5 May 2026 13:05:05 +0300 Message-Id: <20260505100523.1922388-14-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260505100523.1922388-1-vladimir.oltean@nxp.com> References: <20260505100523.1922388-1-vladimir.oltean@nxp.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: FRYP281CA0017.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::27) To AM9PR04MB8585.eurprd04.prod.outlook.com (2603:10a6:20b:438::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM9PR04MB8585:EE_|DB9PR04MB8363:EE_ X-MS-Office365-Filtering-Correlation-Id: ed82a3ee-85bc-486b-5dd2-08deaa8dea31 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|19092799006|7416014|366016|22082099003|18002099003|56012099003; X-Microsoft-Antispam-Message-Info: 2ZHidZ2Z9XG1cUXbqmlQK9ajqsxCHl1TDtw5FP0bz1JO9Zif5/lv8mMRG15eqeTY49ycBf8/gOu3aps4JDXGPvvDw2Ji1J6Mr7xrVPatlT2O2Sl4BFGxG49TYFoA43igGaw7Q/oSXTudwWeyP3oTUR8rHdr9UsyGWwvZMRdO6DcwtP1JohNpOd5Eyxtt3kFEXzjbHC2KM5F9BorqJOb7lzVB0OCB5XZoY5oI+kE7EWigMu4ygsHSLIJ6P3ug476hURVhkeBp2C6TFsE05Q3AnLXVNoQEEoTaxihhFmWxTC0LwgAA3nUIMs42I8V0AEGh/ACOqGj9dCaSphO2kDo5meNhFG1IWRjaPbXVuI7k2rK3IN6Bv5waHZfAKYIt4VAazoY9pgMGF6cclacadREjpHCUqCAlMFEZ6LQIrZWp/s+BKaG9zoElPbgnckbvn/H0KJ6lO5r/QFf+DwGXZL/SbfoYbmJlhs4Ms7KMM9byRH8c2Bak1KoVq2CBfgA+kAK5MBlsy1ioHZOqcN9veew2OVn4wdHlAjok1q5nIv8+Ph9xf+QBeEcu8mYSdTBekhsCNbvqENYhOR4uX+I49Spl5Ui5f2hYZhHOXQF4n0WzyarxvtWbuKbP/4fXrY0nPAIL9Zz1SynwZ0feLItB02JM0Q== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM9PR04MB8585.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(1800799024)(19092799006)(7416014)(366016)(22082099003)(18002099003)(56012099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?RTADKoQWT0uoDwOTgZUdxgAVzPb3pml9Qb67ygWFJWHTxcf1hVkLAlgnNM4w?= =?us-ascii?Q?pZ9a2yAjO83adLRx13mhC/togpTw8FNWfJbbhevPkTOsvgKEJ9FLeWn2fB8H?= =?us-ascii?Q?AQL9z5QQtz5kNucwHzBxfirGSsZYnnW631OXNY19Yvcm/1/vxyzm5UxdfqQS?= =?us-ascii?Q?/OPjy2C0AMHDyOnwm5lk4DJyNR59acUY3FmuhXe30HOIhGeG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TmfTLlj3WcQGSHilarH47i6d/vTJZNYRYIHwGiFAvMvvvr?= =?us-ascii?Q?kfTY4GLsWU4+MD+o35REcGKwPh6NhbHe2+FFQURJm/5vLhh4maxj4zW82YWf?= =?us-ascii?Q?pdIjkWy+xM7J7QamxISCgo7o0vupeG6WF70axtWE2a0iHFb8Y6JHMyVY0apY?= =?us-ascii?Q?Iy+Q6c3Veo7qDwIbafjfRO51CM0VwED5qkPTPvnuB6/TdI0Mp3LPjY/0HMUc?= =?us-ascii?Q?iSgA5NGuQUNubQLqAZQC5lx/I9ssHeVkd6ik0yuPfWyFBBzhqmZi89fbC64x?= =?us-ascii?Q?1fAsxhfxPKW4OLxis6MZu4djr4qsSPmqvt06Oa745gtp2Cf0MOZcYSoxuNfb?= =?us-ascii?Q?8Ct1CNrWXQzq5Kg9fuCykaRAywRDRSJcC/YWahFIRxZ6XYjFgka35al68tCX?= =?us-ascii?Q?4OZ2bJ1+NAX2gLuQygttT9PvPbhMj1V4F3aOh13qUYE5OEqt1vH3Jk54zEct?= =?us-ascii?Q?icxEqCXmDzJVGpBFQQfF5FY+vk2/vbcOnnpG5M3EFtrDNiSUTGH3k3yLU+Gy?= =?us-ascii?Q?swP4NtZeTTEHY6ou65ASuvYURP+flZuhRwLvD8khJRn28zmx9ACboKHz4uUj?= =?us-ascii?Q?T1DObpcWUwQJSndzcUostRsLhWCrDLE4+Rb8N3weFV4bOVSapg1iDfi3AClE?= =?us-ascii?Q?d8hNkhYzsQ=3D=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: ed82a3ee-85bc-486b-5dd2-08deaa8dea31 X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8585.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2026 10:06:03.3376 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 74OiZfYv6Q5G0wNXi3L0k9sfGcWt2YDI3PCFJcXjzIj+HvoRn265eWOU1QWM8moWjPOlIxFo+Ja3xrisvCk1+g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB8363 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260505_030623_901192_EF358BC7 X-CRM114-Status: GOOD ( 17.72 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The Generic PHY API needs the following call order: phy_init() -> phy_power_on() -> phy_power_off() -> phy_exit() with a balanced number of phy_init() <-> phy_exit() and phy_power_on() <-> phy_power_off() calls. The UFS framework is not exactly great in helping out with obeying these requirements. For example, the Qualcomm UFS HCD driver insists pairing the PHY power to the clock setup operations. But during driver removal, we have: ufshcd_hba_exit() -> ufshcd_variant_hba_exit() -> ufs_qcom_exit() -> ufshcd_setup_clocks(hba, false) which means that we will underflow the PHY power_count. Adding a "bool power_count" to the driver and checking it before each call helps avoid this issue. Signed-off-by: Vladimir Oltean --- Cc: Can Guo Cc: "James E.J. Bottomley" Cc: "Martin K. Petersen" Cc: Dmitry Baryshkov Cc: Nitin Rawat Cc: Manivannan Sadhasivam v7->v8: patch is new to fix an issue reported by Sashiko https://sashiko.dev/#/patchset/20260430110652.558622-1-vladimir.oltean@nxp.com --- drivers/ufs/host/ufs-qcom.c | 53 ++++++++++++++++++++++++++++--------- drivers/ufs/host/ufs-qcom.h | 1 + 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/drivers/ufs/host/ufs-qcom.c b/drivers/ufs/host/ufs-qcom.c index e28edcfd13a1..c547d8643480 100644 --- a/drivers/ufs/host/ufs-qcom.c +++ b/drivers/ufs/host/ufs-qcom.c @@ -485,6 +485,42 @@ static u32 ufs_qcom_get_hs_gear(struct ufs_hba *hba) return UFS_HS_G3; } +static int ufs_qcom_phy_power_on(struct ufs_qcom_host *host) +{ + int ret; + + if (host->phy_powered_on) + return 0; + + ret = phy_power_on(host->generic_phy); + if (ret) { + dev_err(host->hba->dev, "Failed to power on PHY: %pe\n", + ERR_PTR(ret)); + return ret; + } + + host->phy_powered_on = true; + + return 0; +} + +static void ufs_qcom_phy_power_off(struct ufs_qcom_host *host) +{ + int ret; + + if (!host->phy_powered_on) + return; + + ret = phy_power_off(host->generic_phy); + if (ret) { + dev_warn(host->hba->dev, "Failed to power off PHY: %pe\n", + ERR_PTR(ret)); + return; + } + + host->phy_powered_on = false; +} + static int ufs_qcom_phy_change_mode(struct ufs_hba *hba) { struct ufs_qcom_host *host = ufshcd_get_variant(hba); @@ -1390,7 +1426,6 @@ static int ufs_qcom_setup_clocks(struct ufs_hba *hba, bool on, enum ufs_notify_change_status status) { struct ufs_qcom_host *host = ufshcd_get_variant(hba); - struct phy *phy; int err; /* @@ -1401,8 +1436,6 @@ static int ufs_qcom_setup_clocks(struct ufs_hba *hba, bool on, if (!host) return 0; - phy = host->generic_phy; - switch (status) { case PRE_CHANGE: if (on) { @@ -1420,20 +1453,14 @@ static int ufs_qcom_setup_clocks(struct ufs_hba *hba, bool on, ufs_qcom_dev_ref_clk_ctrl(host, false); } - err = phy_power_off(phy); - if (err) { - dev_err(hba->dev, "phy power off failed, ret=%d\n", err); - return err; - } + ufs_qcom_phy_power_off(host); } break; case POST_CHANGE: if (on) { - err = phy_power_on(phy); - if (err) { - dev_err(hba->dev, "phy power on failed, ret = %d\n", err); + err = ufs_qcom_phy_power_on(host); + if (err) return err; - } /* enable the device ref clock for HS mode*/ if (ufshcd_is_hs_mode(&hba->pwr_info)) @@ -1629,7 +1656,7 @@ static void ufs_qcom_exit(struct ufs_hba *hba) struct ufs_qcom_host *host = ufshcd_get_variant(hba); ufs_qcom_disable_lane_clks(host); - phy_power_off(host->generic_phy); + ufs_qcom_phy_power_off(host); phy_exit(host->generic_phy); } diff --git a/drivers/ufs/host/ufs-qcom.h b/drivers/ufs/host/ufs-qcom.h index 5d083331a7f4..6eafba3c203b 100644 --- a/drivers/ufs/host/ufs-qcom.h +++ b/drivers/ufs/host/ufs-qcom.h @@ -322,6 +322,7 @@ struct ufs_qcom_host { struct clk_bulk_data *clks; u32 num_clks; bool is_lane_clks_enabled; + bool phy_powered_on; struct icc_path *icc_ddr; struct icc_path *icc_cpu; -- 2.34.1