From patchwork Tue May 5 10:05:05 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 2147 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mxe881.netcup.net (Postfix) with ESMTPS id 454F51C0224 for ; Tue, 5 May 2026 12:28:09 +0200 (CEST) Authentication-Results: mxe881; dkim=pass header.d=nxp.com; spf=pass (sender IP is 172.105.105.114) smtp.mailfrom=linux-sunxi+bounces-23115-noreply=patchwork.local@lists.linux.dev smtp.helo=tor.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.105.105.114 as permitted sender) client-ip=172.105.105.114; envelope-from=linux-sunxi+bounces-23115-noreply=patchwork.local@lists.linux.dev; helo=tor.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1]) by tor.lore.kernel.org (Postfix) with ESMTP id 108FC30A58B6 for ; Tue, 5 May 2026 10:12:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 996C1401A3B; Tue, 5 May 2026 10:06:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="cNQxRuTN" X-Original-To: linux-sunxi@lists.linux.dev Received: from AS8PR04CU009.outbound.protection.outlook.com (mail-westeuropeazon11011057.outbound.protection.outlook.com [52.101.70.57]) (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 40CEE3FBED2; Tue, 5 May 2026 10:06:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.70.57 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777975577; cv=fail; b=a9yoGB/NvcVPZ9WcbHUReK1PaQhcOXTfm68bbxR0bx1IP1qdldb/Hvj94kL5V0QSytFI2NAq0HQmqUpRdq51W2u81ASdzJ0Bjb8OCsaojr6lBimEqC7B+UWh3oV7NEWRLbzZ4JU7cQD7kH7tyZPpEw0u3YqZ2n1GAYsQrRkQ4xg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777975577; c=relaxed/simple; bh=CfXKLF9lqq7BPaGPcDHYGnIaOnUu3XX+cPlKN4w1UDs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=D9AVkx1gG3wPGqJfnc30KG5kbbAa8/U20cZ75d31rPFvZalGKN56breep9xg+xWljRYv5ZjwLeHMhMbqLbmAj5H5E0yPQ5qihq9t4Nwfgmol01j9kOMvrNLbCr789acY3TROkW2RtCSHMKTHtDT+eDbIk8xhx1m+UoTKEcOhfEI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=cNQxRuTN; arc=fail smtp.client-ip=52.101.70.57 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com 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> X-ClientProxiedBy: FRYP281CA0017.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::27) To AM9PR04MB8585.eurprd04.prod.outlook.com (2603:10a6:20b:438::13) Precedence: bulk X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: 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: RTADKoQWT0uoDwOTgZUdxgAVzPb3pml9Qb67ygWFJWHTxcf1hVkLAlgnNM4wpZ9a2yAjO83adLRx13mhC/togpTw8FNWfJbbhevPkTOsvgKEJ9FLeWn2fB8HAQL9z5QQtz5kNucwHzBxfirGSsZYnnW631OXNY19Yvcm/1/vxyzm5UxdfqQS/OPjy2C0AMHDyOnwm5lk4DJyNR59acUY3FmuhXe30HOIhGeGyLtwCZdzby+pyRguK0+vnVmMPHJuCOXEiifxDs8N/4kYtOOsSm611VVQXqyyAypdGB9X1u35wSCYqaao9WFDnzhQJzBvZ0ZkxwJSeuu/6MCnyg7+bSdjslmWs7Re/+zANWOepaF+LCoskwR92LLY5urEyfnS0zrZ0PttNCYVOrSGhmSC5nR5qXgSSCnCZGwb9nejn1AlEzCsTMRmJhHgitgT/d8CF8DJhoazc2JNoWvkfaLYbSyYed7G8QIFJHZO3E2nAaJHS1M3jl2JPWwhHERCcZh/TgPq7ehsOTKCq55ztCw3nBhqVRqb5AaYS3cG3NX8R8R5sFcbxTQLISndhd9RV8hg8WPPSSQhh7S/wG1JITBF2NWOGtcWkGxn2n7kkokZYirSoc5Ztbt0etryoLlDNvNwfRjBR68zQ0XXIQNnqRH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ClEd8hNkhYzsQ== 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-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= 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;