From patchwork Thu Dec 26 06:25:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Song X-Patchwork-Id: 13921047 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 A7DA4E77188 for ; Thu, 26 Dec 2024 06:16:06 +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=EysI5icpJCamrUzklDSTcaAAt7p8sc65VdhLuFr3kV4=; b=VOdLb+1rjqBi2lePy0GpXVG/pu EmdNFOVy76K7sQcG1ZETSqUkIa/RRKXO2DXnmTqvd2EMkjjXmO8UcWP+9Dm5guPHr/BYRY+szoIK7 0KoLIZXrdjQ3oE0XJmk4bm+LKXykJ3ibXCBJ/8Tsjvjn1t7uk9LLVs9TWzKrVrFcYsJukMGMPYSFS XEoAEMLWVI214I6rwqk04CvQGWHSkjaSF5VNJ4shrNu6DaPn/ktcHetRHIMo5GaHHWGrx3+i7mSnu GLTMSA3eUPMOGucjmApcVLa4vFmswZOcI+1Gc1X9OXVpZUL009UGVbFxNF3u3qmxUzDIi32r+oeVA VoqxwOew==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tQhA0-0000000FHWe-3orz; Thu, 26 Dec 2024 06:15:52 +0000 Received: from mail-am0eur02on20605.outbound.protection.outlook.com ([2a01:111:f403:2606::605] helo=EUR02-AM0-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tQh8o-0000000FHOu-0rgH for linux-arm-kernel@lists.infradead.org; Thu, 26 Dec 2024 06:14:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=wT6BLRMfgVxC5AwZyf8cd1jJ5Cx9Jh1QLWOBRmsvFWOmFi/susL7D839tKgcjK5NEid4JbruxLHbw6W5KPHEkk5UDllyUktj+Q+7p/Je+hgshpAL3SG0gKfU5uIe1dfLgD3mZ6CjprJMfyjQv38t2UGGB0BmPrIIS3mwvKJFNeSJSmOwhUvr4uzX1yLu6857mGIwogVzLCIm12NRkjet5qChqOPh4ZeyILMGcAtaqCgguYOpI1CuswZCAp18FQSoWPeUFlkEOuXYxgOxbvYz7bGczOor5zL8cwegfSOzBOyCTAnQT7xANqk+sPhRlqlS8cFfgvvMQfh1FJ1x47aNHw== 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=EysI5icpJCamrUzklDSTcaAAt7p8sc65VdhLuFr3kV4=; b=kGRtDec6Jahx6tFSKU0EnY5O2ryKJRb2Qzc8pbrAHyRmEK806ANE3rhedOiT0TBnYadmkgo4Ay/4lF4G7kdmlIS2gZQbaRO9mpNx215DFrRJr7fT17BwBkioRWBy9HchcXx5+JUhiYiwyao9C6K9IPzOMs0OvUaSVMU0uiO0zBF17lFcG97V1oxMmEy26twf6jkOVLZ+c4IoIWaxl2Gon/GZQz7G/gXV2AaPBVYVyqBG0Fb4bgyrb06Qfr7kTH3hfAE2mIX6SN6Sl5wZRO0KEeGsI3uvpmMvY4PKSEWPJadU3eQ5siAZSKCHeMOiNUFpKrG+GFzrhRvWKnHqIWsZSQ== 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=EysI5icpJCamrUzklDSTcaAAt7p8sc65VdhLuFr3kV4=; b=cjRHAvQz5yE6k0eAK7Nttjg2NgCddyEzfe6IQN75FQ0YFPv3V9XgzABJ7AR/zoLREP9CaP5lKQTYKz9KsMpGIFZ793nVQTFiMVeAkmg6HDrsLumTew1NkBeTNrvRDm3O6FKQN8pVgJf2plJ4rXXfydmOV274Udr/szexZknhfhurVuATQnuKLk/7wBouHfcBqmwrn7AKvh2kr8Z5nHoQeZtC0+BmZrPYETg9I7elu97fQZ8J8gx8w3AtXd+i+K1SZyBhbkn+7DqPWVcErZaZpniFbE+0mlaJwmYRUXWct8LAv2NY19XoZ78TzJ773vnifst4y0p+lyNXvVdOSSn6Mg== 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 AM8PR04MB7971.eurprd04.prod.outlook.com (2603:10a6:20b:234::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8293.14; Thu, 26 Dec 2024 06:14:27 +0000 Received: from AM0PR0402MB3937.eurprd04.prod.outlook.com ([fe80::4e37:f56b:8a3e:bff0]) by AM0PR0402MB3937.eurprd04.prod.outlook.com ([fe80::4e37:f56b:8a3e:bff0%5]) with mapi id 15.20.8272.013; Thu, 26 Dec 2024 06:14:25 +0000 From: Carlos Song To: andi.shyti@kernel.org, frank.li@nxp.com, o.rempel@pengutronix.de, kernel@pengutronix.de, 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, Carlos Song , Clark Wang , Ahmad Fatoum Subject: [PATCH v7] i2c: imx: support DMA defer probing Date: Thu, 26 Dec 2024 14:25:21 +0800 Message-Id: <20241226062521.1004809-1-carlos.song@nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: SI1PR02CA0028.apcprd02.prod.outlook.com (2603:1096:4:1f4::6) To AM0PR0402MB3937.eurprd04.prod.outlook.com (2603:10a6:208:5::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR0402MB3937:EE_|AM8PR04MB7971:EE_ X-MS-Office365-Filtering-Correlation-Id: aef94913-295d-4467-0c9b-08dd25748c40 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|52116014|1800799024|366016|38350700014; X-Microsoft-Antispam-Message-Info: hDk5SY9dzAjV3/8+3Wg6M6mE0uhf+OkBItQKUTKdVhibdl5QsYTGamV995ybsLhEu30XHRBXkdTJqIKmB4wMnPov2KwgxvwsXUuGm81jexNVqTr5aN8Kyhp578YCcSe15VEG1wEMrGefPChLiRSE6Ay04fZ/pLndiSGGkWupqYuOFozPcGISQ3OycGGvBbPgvbCJadPOydFxdfFV5h+P9Dku0IjcxImVfr3vS/TbJtGxa8GUjACRp7+fIT08KaCymBCTwpSgrslmNsRI33+5iNXUCxkI5ZUlBFaUteAGOjcGxZbeGZ3qR+yZn9u1LBbSDsaUhJtsI2QlOSB4O8GtjNIiGHlZJjH+LvQTo6shI+x4IOtL+k/6bGotcCeoXogQj3WumlQEFadtCukwMp+WoZOLfIwL4ZG7r8z+IjyGHWJ9Fa6D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ANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR0402MB3937.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(7416014)(52116014)(1800799024)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 3pSRwQ5JFNXuCs4HYqLYrg6k84w6w68lt5YYpC9ISeOqOTjGHiKJL/zlTpEMr6EXy7f/W7x65Lp94BsgJZWxhsNKy0OeNmWkb7MWPIss/ljdJzvurHaoMETCrAU4R9WDIhjz/9DFDbw/xlWprcQOpC+N/JR/3nv5paG7NwBHHdkTLvyJoJ2t+Yr3MMjB96pXh8lrH07ynYZhS7j8ZhcVTuggAHY43S5i4JWuSkUCJS3T8VgMIoeEzCfDF7Z50Xd2D0PP4FUJp4gFcncf/o032nPeuFr+KDGTLnBIP4V7pzWrRAZiJZqN8OAVLeABNvFnVqj41ExwgLY2X7kmUETuSsorPr/HZa3vqcdvdR2CFQn1oExMYz56vU/qVsMjR5qxLi5yqrYFiFviQ2xW7YFFHTY91K9LPVqqImhaJOpa+jWReXXt17bckpDsgwaf3HDxb7KEwwP3A7ZK4n6Z1Ez/CrVVbojFyg+8G4brBqazuWKf0oc63T3LKKd4/QHrX9R7TWYQU7lPxCk5GtkxouMJogsrLD/EotlTH0rybzXAgKJ0L7tdtwv7Q0QCDA3V2W0nyoVjanOJc1Mb0OBH/6eEhgIPQiyyQxTFlwwtQrp7d/1nSOXAx5+ki+ZmWWjZm5w4poFvFLvJXlq/1dv7dk6t+GKrW0LHo6TZ5uL9y5YWfCedt0JFfi3vuYrApauepNBHFfM6JyRbBhJ2/00rMkXsF1QO16gVvpy29T5VgfGcV7eT2VtJMzGWVV82ad1SHCrbvhAV5ytNl4GyTwC2faRkdJNakFEW12tNdak6HzB5B0jIXCVU52FGduPahnbKHd459Nm7pCGCe7DEvVzRRwx/BXOsh1lc7Gb9QIxstPXv0t0HbcJqeQQaAVMrWP/OZy1Vjskbv8pghILnm7EDprtEkLrvfpPy1LXR2CxLie9Kk/D5MqI0OhZtx/2hQyu6ffkD0s2ipZU+BrlsHk668xbP08mXpIDP9IBYXrBo1c9k24ens7PomRy7Ws6O7u7F0+yzS1KH4Mp7Ligi4y9YSvhZFvFWPMcGtq6M5hkTaeJd0eSvXJprpRQ+E4v8CQkMngIN+ahgnNzjVFoD2swTqrh3AXeua7fAvv3ACR4ka8AnJf9MtlTcP2YeMaFAdcQeH4IwGPd2H4icj9Id+HAlndW7bjxnwdCPXXCw70NsgmCt6+aA1GsyQULkx00sWX/Tq4nVpsbaz2vp7gfHVGqkSvGDKDhZFaetoYhWzfWy0dm6IhnZGMCyHIh2ZHGmbqYrRi916jDSO+k8yvpiGhV+YHTXp7vm6bXD4SNRFsp8y60Qw5zJ6sa8DPGrJUSKeSmvIQkOAV28g/j0zMJKXHpJsRqQXihqRty2G7rVn2H10vGK/uvi9uCJ6CS5VhRExHH2NoFlH3DZ0sQEtSq8CxzjH0ORF7Q3Q2Y8mkpHo/HnDiOntWNo7ISeSebZOhgax2TU9p9QFRv+3XQUnFzmoYyD9Jg5vpMXCHNDgRcGkvAtzdcByWQrzB9G5HTHOVX1Mzip/xS+aZp3RWXpw1wQRcacYvNObMObDuPvnQNiHiIxLPKKv2f2/CGPAXyxpnwAFM7BUqJ1 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: aef94913-295d-4467-0c9b-08dd25748c40 X-MS-Exchange-CrossTenant-AuthSource: AM0PR0402MB3937.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Dec 2024 06:14:25.8397 (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: ntrD93eye02JiPuN7uE2Zo6y3+ajmzosGsf0p9av0C8UMDFhurwe4k+BL9pG5Em6BV1GKA80+kOtcaXIcDkFBg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR04MB7971 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241225_221438_257501_8539291E X-CRM114-Status: GOOD ( 19.01 ) 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 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 Acked-by: Ahmad Fatoum Acked-by: Oleksij Rempel --- Change for V7: - According to Andi's comment, use dev_warn to replace dev_err to print warning log in failing setting up DMA path and use a more detailed comment to explain why we decided not to leave when meet DMA error. Change for V6: - According to Ahmad and Oleksij's comment, use dev_err to print error log in failing setting up DMA path and simplify code comment. Change for V5: - Add Ahmad Acked-by. No code change. Change for V4: - Output "Only use PIO mode" log in debug level when no DMA configure. Change for V3: - According to Marc's comment, remove error print when defer probe. Add info log when DMA has not been enabled and add error log when DMA error, both won't stuck the i2c adapter register, just for reminding, i2c adapter is working only in PIO mode. 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 | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c index 1f441227bfdc..ee0d25b498cb 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) @@ -1802,6 +1803,22 @@ static int i2c_imx_probe(struct platform_device *pdev) if (ret == -EPROBE_DEFER) goto clk_notifier_unregister; + /* + * DMA mode should be optional for I2C, when encountering DMA errors, + * no need to exit I2C probe. Only print warning to show DMA error and + * use PIO mode directly to ensure I2C bus available as much as possible. + */ + ret = i2c_imx_dma_request(i2c_imx, phy_addr); + if (ret) { + if (ret == -EPROBE_DEFER) + goto clk_notifier_unregister; + else if (ret == -ENODEV) + dev_dbg(&pdev->dev, "Only use PIO mode\n"); + else + dev_warn(&pdev->dev, "Failed to setup DMA (%pe), only use PIO mode\n", + ERR_PTR(ret)); + } + /* Add I2C adapter */ ret = i2c_add_numbered_adapter(&i2c_imx->adapter); if (ret < 0) @@ -1816,9 +1833,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: