From patchwork Mon Nov 25 14:21:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Song X-Patchwork-Id: 13884996 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 F4151D58D4D for ; Mon, 25 Nov 2024 14:14:51 +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: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:In-Reply-To:References:List-Owner; bh=Oe5GBovdqjL924qEp5QSrxGfqMHe75Plr89DsawSSu0=; b=jsx+9VgrPUk7g9FLWFj9ldzBx+ MeQaWnZ411pjZQ5Z/sTdpFsEt+F3V3OjWYcdLW2vrs2hRVmLdXc1bQkgZoNW+yUbB+UphTHYICD9S pPF4iwjnyg1Ww9P6F5rrf3uQm9IwIIl5z3Emd2uu/YLZn7WpaMoYET2nHyP/zTVTB2nKy4xCezsT8 pBY6CZHm91rZqI878yresdj8nR0TzfwvA2GMsv2sQPTYgmNTMRLhlcVHRyMUR/MCXK3JGVGRt0q7M eIyvyPakEPEhdX1wZ2AsKGZQ8OPcLg7pe32GhdMAkESAXG15If9+yeW4dhhJtJKQMCckwGW6BA44P qyAcvtoQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tFZrJ-00000008Fdq-0oqH; Mon, 25 Nov 2024 14:14:37 +0000 Received: from mail-vi1eur05on2060c.outbound.protection.outlook.com ([2a01:111:f403:2613::60c] helo=EUR05-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tFZpX-00000008FDv-3DPp for linux-arm-kernel@lists.infradead.org; Mon, 25 Nov 2024 14:12:49 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=TeEqlvqza6B2x7k/pNIxMJPUKdaQCetomuqzIUV+KCiCODnjO/mrvgbsk8EjC7DPV/jpvOnAsddn7n/qHIwGbkWDDWejcqrsaibn9wTibWZJVcXbYFyXDFUDcwug2YTNG3WxHB0A1kesbFEydgQ1Fnk1XYqCFgxunBe/twVHL9BWRO3HPepYiRnEXU40u7DD4M2rST7YW+Z2hzvZJus4QY2NwTt6IUTPwr8G1vtbfw8TcVt44KaRYMegcoUuQZ66owTPlVGS5fBlNbhKJxzGv1rZsKOq8QBMabXsPPZ+ZMNPEMrqHtUn5SKh+7HWg8PcFE896XYWaQuRIzEsEahgHQ== 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=Oe5GBovdqjL924qEp5QSrxGfqMHe75Plr89DsawSSu0=; b=HFd0Nf+l9Z1DWlw7+VlKRhXkMo+7TuM+s5kCAPDk7v1+fwv9Gyyc89yl/VcgofC3zNGoNrWW8DhqCIcjzliCEpMv2ZeQFonnDmj8bYg+qhnzIRcLKU46GFPufmSmBmF57KkZg9EoytNL2/1XZ43LLV7+MZBcLFEkF/InvhLtqNK1xTd6ZL/+s+R/01UrnW/lFT3oir76Yz04GSjbRfGG0at65zYyk4+pjm9kfGT2Z2ANF3ApD6rcNMzrCokfdMcF8tw0oJVGBAftBPRWNdc6VrtwqamwcExksRxjf7cgPhdGE78RRtNx98pIfMmKGaXbMjUIYVAk4n+RGw+5cZpd7Q== 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=Oe5GBovdqjL924qEp5QSrxGfqMHe75Plr89DsawSSu0=; b=i2xNaBwiKT6flOmjb2ZIoyzazJ2iQ4niZ74I+wurvRjY1Qrvkyz33Qb71WucJWfPm14J9jDP/uAEthLqLOS6HMsvC1h981Ro1OUYR1l/qsfwVJRdNmB9B9b0oEQ12mlsXyhkS5r9F3yYRnqAyODValGjJ7DyOySiLzbNJoGtxt50L0DudLxKwNLfsXXIg0oVIEpZfs8X22Z4ojqhpf0VDd+x8Z2bVTJKzkaOUu/39bLS0GMj9CpnX0Cj9N65Fynk69aFpq0WVdbClmXIcVk8Iik7d5kESMhVkTgTBfvAdaLQ1wgJAsheW8/dWdbZIrQkjeSJqAlwt1NaS6G+LWAeNA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM0PR0402MB3937.eurprd04.prod.outlook.com (2603:10a6:208:5::22) by AS5PR04MB10057.eurprd04.prod.outlook.com (2603:10a6:20b:67d::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8182.20; Mon, 25 Nov 2024 14:12:39 +0000 Received: from AM0PR0402MB3937.eurprd04.prod.outlook.com ([fe80::4e37:f56b:8a3e:bff0]) by AM0PR0402MB3937.eurprd04.prod.outlook.com ([fe80::4e37:f56b:8a3e:bff0%4]) with mapi id 15.20.8048.020; Mon, 25 Nov 2024 14:12:39 +0000 From: carlos.song@nxp.com To: o.rempel@pengutronix.de, kernel@pengutronix.de, andi.shyti@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, festevam@gmail.com, frank.li@nxp.com Cc: linux-i2c@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] i2c: imx: make controller available until system suspend_noirq() and from resume_noirq() Date: Mon, 25 Nov 2024 22:21:08 +0800 Message-Id: <20241125142108.1613016-1-carlos.song@nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: BE1P281CA0462.DEUP281.PROD.OUTLOOK.COM (2603:10a6:b10:7f::19) To AM0PR0402MB3937.eurprd04.prod.outlook.com (2603:10a6:208:5::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR0402MB3937:EE_|AS5PR04MB10057:EE_ X-MS-Office365-Filtering-Correlation-Id: 17122bf9-4e57-4d90-ef9c-08dd0d5b37cd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|52116014|7416014|376014|1800799024|366016|38350700014; X-Microsoft-Antispam-Message-Info: vA6Ln+oT6D1Aopb3TGojRIMmksM+vTJKGwxglzvDKU4/alYSMyu/SgyUbdjFlHkiFkFFXrCOLzaDcf8TrmMuFdhbYPX85rRlRHedEjzkSR/lS/W1va/L4TpG12t9p8x5UU/knwuo+MKVPAxyec2tUBFBD1Wl4ABxXZ1c0mIK69nk2OFMQ5t0wHg2NlZWqrZvhmcFfa1FOkXQf5I1Ah52geAb4Ir+clRcRq1hQzXrm9nlpMcJb3wZ1sQJ0Rw1j6AkwJV5cIKzlWZsQ14attTSTd0tl5fprffVUweZULQEbDlgJdbuwHJDDZ6Db4nVtlmtJ+K1Gm6NoIgMcrZzafroDo5eASQOwpMiMwx0Zz18vVw7obHfWHuFp1Kq7V6P3OlQF2/DOJ6BzsLiTaY+m27M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V:NLI;SFV:NSPM;H:AM0PR0402MB3937.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(52116014)(7416014)(376014)(1800799024)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: yOKcVtxZ4X6hGvdVkU2ez5R7DrpbZ4F3wcepzhb/uVNj8YCQ+mtqMLSXIWDIGIMdrD9g9wI3qD5D8fz7GHla1D57+sL871XffHvxlQA10o5d58Eg26BOWefv4YdIR0shEcIxgXbkVqxYm4V/qu9QbrziiLL0yZZXN9fnjVdIltiYra1NN0FC25Su+q249yAAXXrDLtE3APoGqlnzvY9GkU1hkmPdh6Uz3aMja73YC9fJBzgK09uy758Rxi7vcu7NqRY4zNCcMrNZTqRr6/h4b+QENUKJd67aDiO1s2KAt216vbz4WYkoTnUA1ZtuBuqTMx6G2AD2uWPVsfbsITqcy/T3pxsVRoEN+cvaBKuyWyEFWcB75Hws53yf/ikkzTFRh6YPdk5YuLRk++BXt+gtXIng3Wry2RQqUKA2xTQiFa4DQRqwIWnnqYhOcI+VHFiC8JL4rOtXSGBtswrp95GxcAX1Up2Mqt/+jVJATHO8YFZZExxil138v+7RgmpYE6fWQvwyz0aVn0zWDE9EcP1aPfrJZfB3S/G9eUlfC/qnSjvkt9T9FDUmyXltPeOK1H9ThWF5rAmMt1chAQUcAbpdN9TcEE/BRZVbFzlhLkzoWtKE6uCz1hoNu9n/GR7wjjt4IEVMarOKLJiDycp30wvS5q4KBTtCvbFHFBJUqP2tEqpg1jF2QQHzKC5sbOXWZkB96iXcTILQB6Jl/WSzqFx6ZdxIax06S01PE06p4BLjFzEE51lq7fjqh00/yfRhlAOvIHzssLvsZ2QkKE1t5ouTmlPuh6kuJMwIHUoe2O9hpy9FyxZdfUm2O3J7btkRryjQ2mirCm6VdnJz85z72nVCpvU5aT7wBU3gFhTpR+nFymX+67icASZS663f37AGEBDNVSdxbt/yfCQ6mX7uc2En5nD7RUfW/z4/5tRFabdZYsyYHe9/A/Uemx3p/D3VqLXLEz8E+HZHJkyeRnFLAbsNTkSZLH2wkudEi8e6fUMXmJQCaVvIKkJ0fQuu/r2YBynGy7pK9ijKUGNuxWDSQm8ppUN5UAYtPVf4FH9VZWY2nmeKVlTSecf6rjyrQ4wwvq4+KJo1kAv+tbW0bDMR3O4mY7d6/XiVyhQk4crjYcz1GT1GHU3XqFerFvdQeQkv3O9b6eOuJGD4e7su63zTUwHrlNkvk7LACPC0luUwU29d8fwcfhZCsIMyZmokqcSQoFA98qDrR6ftN+Wh0X6+a1XJWhlv7/V+h91qClF11S0JOTMRQZeZD5VfsPHFnkYBOATCqwOL6ZSoFOg8xg4PN84BQvM3dAJmck+cmKX21FwiV4WEcAMgLiRgSp2+0za7YyYZBqZ170Y6HPdo1u5BHJSw++1cHI+XRd1BRP+ZYBXE26tgD55BPiy2XcD9QnBZNZ38hMZ/Ei3MlJaSTc4to1WFOslVfv5v0WU4a2/wl5eqTze8DgJM6jc1LSyHxvwoGPN+FwxOb4k/yHCDeWHfNlHaeGi2sxoV6YNUWCqdutFw8MvAkH3wJHeSlwc+sE4Kn7gGRGZ3+/nJDO9x8KLE8xkErTyoP5c4LAKYMgifHdz2TzCsc6g/d6Mzigk8FDCU3JD7 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 17122bf9-4e57-4d90-ef9c-08dd0d5b37cd X-MS-Exchange-CrossTenant-AuthSource: AM0PR0402MB3937.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Nov 2024 14:12:39.0017 (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: wPkOsGF0ITbJcklU+3+e0PJczIoWZimriBS8m7bHxYG7AKxu2HhrR36+85mFJxuK2cP2BtOAMwIpVCYbpmv/CQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS5PR04MB10057 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241125_061247_809675_71D31BFD X-CRM114-Status: GOOD ( 16.84 ) 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 From: Carlos Song Put runtime pm to resume state between suspend() and suspend_noirq(), resume_noirq() and resume(), because some I2C devices need controller on to do communication during this period. The controller can't be wakeup once runtime pm is disabled and in runtime autosuspended state. The problem can be easily reproduced on the I.MX8MQ platform: PMIC needs to be used to enable regular when the system resumes. When PMIC uses I2C controller, I2C runtime pm has not been enabled, so in i2c xfer(), pm_runtime_resume_and_get() will return error, which causes data transfer failed. Therefore, regulars can not be enabled and hang system resumes. Here is resume error log: [ 53.888902] galcore 38000000.gpu3d: PM: calling genpd_resume_noirq @ 529, parent: platform [ 53.897203] i2c_imx_xfer, pm_runtime_resume_and_get is -13 [ 53.902713] imx-pgc imx-pgc-domain.5: failed to enable regulator: -EACCES [ 53.909518] galcore 38000000.gpu3d: PM: genpd_resume_noirq returned 0 after 12331 usecs [ 53.917545] mxc_hantro 38300000.vpu: PM: calling genpd_resume_noirq @ 529, parent: soc@0 [ 53.925659] i2c_imx_xfer, pm_runtime_resume_and_get is -13 [ 53.931157] imx-pgc imx-pgc-domain.6: failed to enable regulator: -EACCES I.MX8MQ system resume normally after applying the fix. Here is resume log: [ 71.068807] galcore 38000000.gpu3d: PM: calling genpd_resume_noirq @ 530, parent: platform [ 71.077103] i2c_imx_xfer, pm_runtime_resume_and_get is 0 [ 71.083578] galcore 38000000.gpu3d: PM: genpd_resume_noirq returned 0 after 6490 usecs [ 71.091526] mxc_hantro 38300000.vpu: PM: calling genpd_resume_noirq @ 530, parent: soc@0 [ 71.099638] i2c_imx_xfer, pm_runtime_resume_and_get is 0 [ 71.106091] mxc_hantro 38300000.vpu: PM: genpd_resume_noirq returned 0 after 6458 usecs Signed-off-by: Carlos Song Signed-off-by: Haibo Chen Reviewed-by: Frank Li --- drivers/i2c/busses/i2c-imx.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c index ee7070ee9e6e..c35092726465 100644 --- a/drivers/i2c/busses/i2c-imx.c +++ b/drivers/i2c/busses/i2c-imx.c @@ -1770,7 +1770,8 @@ static int i2c_imx_probe(struct platform_device *pdev) goto rpm_disable; /* Request IRQ */ - ret = request_irq(irq, i2c_imx_isr, IRQF_SHARED, pdev->name, i2c_imx); + ret = request_irq(irq, i2c_imx_isr, IRQF_SHARED | IRQF_NO_SUSPEND, + pdev->name, i2c_imx); if (ret) { dev_err(&pdev->dev, "can't claim irq %d\n", irq); goto rpm_disable; @@ -1894,7 +1895,36 @@ static int i2c_imx_runtime_resume(struct device *dev) return ret; } +static int i2c_imx_suspend(struct device *dev) +{ + /* + * Some I2C devices may need I2C controller up during resume_noirq() + * or suspend_noirq(), if the controller is autosuspended, there is + * no way to wakeup it once runtime pm is disabled (in suspend_late()). + * When system resume, I2C controller will be available until runtime pm + * is enabled(in_resume_early()). But it is too late for some devices. + * Wakeup the controller in suspend() callback while runtime pm is enabled, + * I2C controller will be available until suspend_noirq() callback + * (pm_runtime_force_suspend()) is called. During the resume, I2C controller + * can be restored by resume_noirq() callback (pm_runtime_force_resume()). + * Then resume() callback enables autosuspend. It will make I2C controller + * available until system suspend_noirq() and from resume_noirq(). + */ + return pm_runtime_resume_and_get(dev); +} + +static int i2c_imx_resume(struct device *dev) +{ + pm_runtime_mark_last_busy(dev); + pm_runtime_put_autosuspend(dev); + + return 0; +} + static const struct dev_pm_ops i2c_imx_pm_ops = { + NOIRQ_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, + pm_runtime_force_resume) + SYSTEM_SLEEP_PM_OPS(i2c_imx_suspend, i2c_imx_resume) RUNTIME_PM_OPS(i2c_imx_runtime_suspend, i2c_imx_runtime_resume, NULL) };