From patchwork Tue Nov 26 08:25:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Song X-Patchwork-Id: 13885575 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 442FDD5A6F8 for ; Tue, 26 Nov 2024 08:18:13 +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=BcOzQnTn7AAWZdy9i9PoNrBjrynS61XCC3rBCG69hFs=; b=X9vt37OHxXvNxkUO6NFKvjswQo LbhCBvOLvqCXZLwuVO5hL9MYh7Ii+pOklkcAq5sN3LBWbTu/6cqPo4fNx09hYB7F47ZCs9BeveA9g dlm3par7M9YjNIx3zz4/l7fSOZED8oIcKm2yWjdZQIBSmJ7XU4SkXITU/ECX54v+DKKG31On070KR hmZDebz9dpG87L3Phxrb55nTAI8yaeOa0kRSQdxAQ9likrhVLQsXdTAHNAWoBQQgb2iQOQ1bkGlA3 YLBtQYk7n4ZXBukxKWFCViQl5CZFM4YGdLBzdsoQ4FQ7kpeEYbmWTLT0ZkZvxreCYQtxW8MQrkDAN GbPIiTQA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tFqli-00000009wqV-22l2; Tue, 26 Nov 2024 08:17:58 +0000 Received: from mail-am7eur03on2062f.outbound.protection.outlook.com ([2a01:111:f403:260e::62f] helo=EUR03-AM7-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tFqkk-00000009wjM-0sbp for linux-arm-kernel@lists.infradead.org; Tue, 26 Nov 2024 08:16:59 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WFvmmh/HLZkx80tJWb15oma2g+NpcjKFWxI75ibpUCAewCn8pneRe1MWz/wphTKpBiiQgsAffGmp9FIo8HcLxBRNiHUaktLlw6HVoBmSuni+fc+68Rjc2Xn2jPqhkuMFuOknwcekO9+zn4IOF1EZo9u9sXeNXxEf4R1AtZ/4bSJvmxDbUf+szZZ5gFLpUjfGg3X3dgTOsDAx2Xt5WY/V3t62LvjBKsvR8CEoT0u/2CEN7TLEx/qAcreC1gSuj+jDceWxxTxCQkJCWStB5fzovv2fyup16NO2JrEcTmYumoZo8POVcoFlPGinUCYFX6+jxlgSv/z7F1TNNZjabLm3Jg== 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=BcOzQnTn7AAWZdy9i9PoNrBjrynS61XCC3rBCG69hFs=; b=D+ipF+qj5aDw7yhFBvzGpzXbJsJIq1lAJVEz9jeG2avw1WgOnFIXWDPNH9/F4VpnuBnw2ipS+Eh/BFkRUrKdIlehyCPR76j1/+QcM8FT/5myJ61wa9m8VY/V8CU2Zdjk0+GdoM+LHjAWNZljhTVQjCMKNMNkcHMsSHeUdoctSvoZP4+YYVOsXapSPblHFSgqW7CEQy1/H1xMpkUWg/cgrRJSxpnA2jN4/ewGASu3qWhGXh7eHpE4vskiMCOYoGRdaQzKarXmUt5kbJxhRbTmCS4jxkHEUnV02yTQeByePoovQM7XyyG77pzvqdaq4C97JySTVaNQruYzAORJvPHTBg== 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=BcOzQnTn7AAWZdy9i9PoNrBjrynS61XCC3rBCG69hFs=; b=nyHeOYCWrmHxamvgtsWbCuSIfPKtVJRg6dgBP/pmyaK+SU2Eq/EAKve3sv1J65hAOzrY9Ty2OseXrmsDWM48jbSHUBsFI7GYyyYh4vRi0P+yWIg33vDPjZanQOQMhRbmLZYFBbqS34JaMJcRB5B0o0DJwQw7mC7MHVLRR73edJ4PDxfNgLDKf9K7/u2tm6feBnoYR83+h/gsE3EjK8UOt4+shvh3BNcCyw7cPRCcA7hNGaVQWMpJweMSjwyOMgqH6LQ0tcanivUyGLiQ+jxRhKTOq6WxqPSk0o+Rgv/yiYMp7SXiZP8DatM0IU53Tb++SQNGQRkh0UD9x6Ii5A/Ufg== 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 PAXPR04MB8286.eurprd04.prod.outlook.com (2603:10a6:102:1cd::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8182.20; Tue, 26 Nov 2024 08:16:54 +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; Tue, 26 Nov 2024 08:16:54 +0000 From: carlos.song@nxp.com To: frank.li@nxp.com, o.rempel@pengutronix.de, kernel@pengutronix.de, andi.shyti@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, festevam@gmail.com Cc: linux-i2c@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] i2c: imx: support DMA defer probing Date: Tue, 26 Nov 2024 16:25:35 +0800 Message-Id: <20241126082535.1878554-1-carlos.song@nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: BE1P281CA0240.DEUP281.PROD.OUTLOOK.COM (2603:10a6:b10:8c::9) To AM0PR0402MB3937.eurprd04.prod.outlook.com (2603:10a6:208:5::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR0402MB3937:EE_|PAXPR04MB8286:EE_ X-MS-Office365-Filtering-Correlation-Id: f67392e6-bd7d-4e33-9d2e-08dd0df2af9b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|52116014|7416014|1800799024|366016|38350700014; X-Microsoft-Antispam-Message-Info: 0Rd2uWsO8TiC2egotNpRzqBmKbKalVfRMMqn4dKMZaNMun7a5XJ/j+dBrMJ+O0JE8s4F++gSuYdWmPyjSnVlP9aUaaCYYS7M2yZcDrkDBn41aSRyvZNaGnnoDH8sUwRf9qg1dqSzTagi4rSVgIoDuHmARL+gVo8/dBvBvLJNraz7qKRy5/n9r4PD2txomACQHEYFf5JcsxZW7FKGGgW2s+OwbasvHI3RqzKfm70XN+34aM/U2b+YxtZWoI88cyPd8m0kl5e6DG2tAgT3BLpHQW+puOtIx2NX3CIg3IzHMD0kzgX7wg/ZjaDKaqymHdvZFL6dajPsWDqtMrEUagCN+mCi9l9fUvl/285i0RZ4LM1GhYjrzvoU8QdnuxgJxCck4C7HtZfwkMPRn09C1/MaQBz4Q8c2Wf6sM9AfcfpOB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FV:NSPM;H:AM0PR0402MB3937.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(52116014)(7416014)(1800799024)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: EEzm323IYslL6sNsNcuQf0bd2JE7UPW1Q2Oo92JsxAYRvj2zbgthT2RG/yuuHQqgClCtXt3YWTxepWaluQ3mf6JEkoxi30gSVz68yun+IueEdHhE8DPx8MUm04Xodrf3thltwCTV/kF0C+YMBSEY+MUgPvG+JGvpqfSrGnFdZ+bV3bjxkzZ3Qwo6EiLarkGpEAk6z2heFvL7qpgFk56ZExZuf61e7Z/ozNb0D/j//rdk/Vr6+j/1mCwM0lrWX7aAwsqFV0A6SQsDTV2GpUzLVRjWDCFw44XgO0L2aZoV5a1AaV+0xrsZMhhOR7beN3BXAkMKWCaNx0e4fz727T5y3D2LDyEwgWWG012hNB9fOmdYuQB8SkpUYZfTBswIkyecr/EOQA0sGafYvfsk3RyBBL3SWjZStsS3+QCrXC+Gnp90LRzQrmOetsirLCyeMg2uluZycTvKWDg1aLnOKYuqW8ryWv/hwyFYJNlSOC9/sljfK4Adu8FSbpKeDAvl5l4oCeiOgxyB2h17Y+Of2N0mBao7+7mWQxRBeunqbJ2XoFeXypJf0yR6Tt6C3gY3qEEFogje9Y2fcH2ElMuiFZDrshRkAL/o5iQAUb1nFCfdo1l8jNKSbvLTiwuRryqKWaV0uDxuRTIupG3yfVCIykzy6hZwZZGajd5d/FAgAXVQETZlh7JNmtJU42cjqC/DekcNn5YbI5DWeMFEoThJyvCdrdV6FTWv+C8K2D2FqxXdoiMX81FOuOhGLEEYmbBHRdeSJzIS7L/9Yc3wXJgDqVkXapVUeP88SIekUBzGxy3WOeA1zudO9IlwHIy20zra8HQEoVJJ/btYorsps9qVeMha7ya+GW9tHgUYqY/CBZAZqoEVNCaemundvwVao66CBXf8bBugpr1K/iJ9Y+P0gQdZ2xm9ABsuClSLNgkIioPlklwmPM955LNgd/wmmwHoDJy+FwKzwpINqeiJhxKlJfPDAjXylbS+MkMjU+qIOxAJUvxWi3NA0Fg1Yg0iji5fioOob2JMfjfm3OccKJDdJE1CEmihQcmCRuoIldSjziSP2tDko2sg4kuU2l3SNh9o0dKMELZi+XC0HgXtWssV5aOv9+donjIncSniTRictnKNRYLZtX4aihf3sXvwEI270peVMegZ/GIa/wjZp7JICikFD4ukvCFAa/Q7a92tlECRZF0xHpZnQlFiyXu2iUZ73sReh++eOirbijiOp8eMpwQpJt34YqH7Omi8lN/Wt4OjHhlAr9/+xM/Tgrdach8XR5NBkJnq4CRCjtXvT6x/5kQiK53dX4LbkbFbxxroHXGL0quAqtGSahJETWPlmH1B2x0Gvt797yyR0okLF5y9vVO6NJYb5FroIhG7ikrd9SbqKoqAOHQAhJWWNpOrHcD4nhb1BNMtxDSeQKmQQXUuAv7G1otCgb3ZkjoFO5C+weSWtEVq3l3KgJVpogGpTkDimAfiOAlc7Pd9w2BZObyeFKoWz0EjK77VlTETm63p6DxUc0iUTRmPDQojyVtvyHCMOv7v6064eooIwgTZhfsFNgzilWu4QUfpghoukbthGTTA7gt3AMr1p/s4I44Y845bTdQY X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: f67392e6-bd7d-4e33-9d2e-08dd0df2af9b X-MS-Exchange-CrossTenant-AuthSource: AM0PR0402MB3937.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Nov 2024 08:16:54.0955 (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: hUC2TpvhthLcQV0WVImb67/itrlRkicfcSRkFVgk6K4nnixzEyfD8yZD/V3xl882eYb9xsyxafaTCsszDNyGRA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB8286 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241126_001658_250333_D0D9F559 X-CRM114-Status: GOOD ( 16.31 ) 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 Return -EPROBE_DEFER when dma_request_slave_channel() because DMA driver have not ready yet. Move i2c_imx_dma_request() before registering I2C adapter to avoid infinite loop of .probe() calls to the same driver, see "e8c220fac415 Revert "i2c: imx: improve the error handling in i2c_imx_dma_request()"" and "Documentation/driver-api/driver-model/driver.rst". Use CPU mode to avoid stuck registering i2c adapter when DMA resources are unavailable. Signed-off-by: Carlos Song Signed-off-by: Clark Wang --- Change for V2: - According to Frank's comments, wrap at 75 char and Simplify fix code at i2c_imx_dma_request(). - Use strict patch check, fix alignment warning at i2c_imx_dma_request() --- drivers/i2c/busses/i2c-imx.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c index 5ed4cb61e262..4e5633166a1e 100644 --- a/drivers/i2c/busses/i2c-imx.c +++ b/drivers/i2c/busses/i2c-imx.c @@ -397,17 +397,16 @@ static void i2c_imx_reset_regs(struct imx_i2c_struct *i2c_imx) } /* Functions for DMA support */ -static void i2c_imx_dma_request(struct imx_i2c_struct *i2c_imx, - dma_addr_t phy_addr) +static int i2c_imx_dma_request(struct imx_i2c_struct *i2c_imx, dma_addr_t phy_addr) { struct imx_i2c_dma *dma; struct dma_slave_config dma_sconfig; - struct device *dev = &i2c_imx->adapter.dev; + struct device *dev = i2c_imx->adapter.dev.parent; int ret; dma = devm_kzalloc(dev, sizeof(*dma), GFP_KERNEL); if (!dma) - return; + return -ENOMEM; dma->chan_tx = dma_request_chan(dev, "tx"); if (IS_ERR(dma->chan_tx)) { @@ -452,7 +451,7 @@ static void i2c_imx_dma_request(struct imx_i2c_struct *i2c_imx, dev_info(dev, "using %s (tx) and %s (rx) for DMA transfers\n", dma_chan_name(dma->chan_tx), dma_chan_name(dma->chan_rx)); - return; + return 0; fail_rx: dma_release_channel(dma->chan_rx); @@ -460,6 +459,8 @@ static void i2c_imx_dma_request(struct imx_i2c_struct *i2c_imx, dma_release_channel(dma->chan_tx); fail_al: devm_kfree(dev, dma); + + return ret; } static void i2c_imx_dma_callback(void *arg) @@ -1803,6 +1804,13 @@ static int i2c_imx_probe(struct platform_device *pdev) if (ret == -EPROBE_DEFER) goto clk_notifier_unregister; + /* Init DMA config if supported */ + ret = i2c_imx_dma_request(i2c_imx, phy_addr); + if (ret == -EPROBE_DEFER) { + dev_err(&pdev->dev, "DMA not ready, go defer probe!\n"); + goto clk_notifier_unregister; + } + /* Add I2C adapter */ ret = i2c_add_numbered_adapter(&i2c_imx->adapter); if (ret < 0) @@ -1817,9 +1825,6 @@ static int i2c_imx_probe(struct platform_device *pdev) i2c_imx->adapter.name); dev_info(&i2c_imx->adapter.dev, "IMX I2C adapter registered\n"); - /* Init DMA config if supported */ - i2c_imx_dma_request(i2c_imx, phy_addr); - return 0; /* Return OK */ clk_notifier_unregister: