From patchwork Mon Dec 23 03:44:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Song X-Patchwork-Id: 13918447 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 A32F6E7718B for ; Mon, 23 Dec 2024 03:35:34 +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=DSxvpQl7C19QyYGJlx4cPpXq8hOS52aLc8dOJwA1qO8=; b=ClxYq7Ez0prSG8jfz5oz9JfseU V3Z7cmDFpJeVrZPQkAb528psVWytPfUfw7rvP01XhskymwoBCn/7eY7KNTHsxzAJKXtgwGldOq5Xl tTH70nWfInxHs4k6lH/cdhajpRHucSZLy/6S9kkM708C37bH9hymYvWAHzPYrS9N3U7WMNPSbmIp1 /YLdrDKf7zgWygncLsPzGOgtpmycyag9LppN0N1AyBXI1ZuQa60LYfMnkPbTfZ1PTBnoXSSK+dRKZ ON6F89FNQJoLHrelRjB1KXe+JUAwzL8zMs5IJDZpFP9tytz4TpsZawWnweQ1xJBB/mXJuj7HH4fJI EOOOd36Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tPZE2-00000009GgI-28D1; Mon, 23 Dec 2024 03:35:22 +0000 Received: from mail-vi1eur05on2061a.outbound.protection.outlook.com ([2a01:111:f403:2613::61a] helo=EUR05-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tPZCG-00000009GU0-15oB for linux-arm-kernel@lists.infradead.org; Mon, 23 Dec 2024 03:33:33 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=sRBML0fnLTVwn/+B6BR0QDYFhkYrhnjlbJC6Q8PsWG427mp5ZSRbwQeyc6lC7cctyMTRL1aViMw3yXqkiBV+lXQ17oCAXb6K2HGe98xSnpbc+21iXEhrets9xH0EvzAC+OTPsLrCIf8kGVnMDTG/LMFY+OVNDAmaSb2jdI7856gMQ0MxTo6E0adUb6mHnI5XTtFuuUR6rlHb4GL0BiYiZqqDeUFKuuP4DkgvIkh3FBl5avCB1t2Bd3iJbyqZEmXGtytaZM6JcAwDxWmIoebiSjflv5Y+o4SRLliGFGRWYS19+kqcDOAC+LMVb1z64Uh/VXAxV2wGcAdyM0IB4u6Wbw== 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=DSxvpQl7C19QyYGJlx4cPpXq8hOS52aLc8dOJwA1qO8=; b=pziV7SVqCacsSzvlMynna6AWArWAT0AUagBEL/C89JFFxkuLg7u62ll/mtvoy/JGIqYu3YQqWef1fXGARikXiSISztQLYR5GJVM5pGkzPg0hT1gPbzfRX3KOXcO8X3qeTvqcM+TYmaG3D9wYJlxQsde7H3zcuvwjTNQDwFo2TysYbVoSMgyfZH1I5yHxrFD8wTapVcHxfToQ7zSM7mZOoylCTLlKT94mRb2qxKU6Rhri2Bgdv2vlw7zqtSOwC67JPaTT6GdHqq2b3dOn82muR+ILVzQwEnjCuKJTsZH2tJWAReYZNi23yDmQVCiANaWySFYrDmnH9ELgdehXye7ARw== 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=DSxvpQl7C19QyYGJlx4cPpXq8hOS52aLc8dOJwA1qO8=; b=PbqBmnrchad8DNYlXV9zxx4KaJn5qeXiHSvI0WlsTdEzqkmtypg9vP6yQLJNCm3D6jbRqxfPM7pEd7Rh6V+kDx2TJkMYGCczsbM3G/oDSAK0zQd2aGIQl0ioQl6o/kPpne1FO75Z8reHpUG48ySWh4MWIreI8b5GzSANjQHBoNDG7Z4YF4qo3WaaQLaq5pL+AwHiUHaw8MrbXNOkXRbyjPXb9gG7wdGEVJJE5BJAUYcjZputOrO8EPLOarj9ho33xNSQMHb3cZ+MULhrCXCSbX86llMAYfgKe5ad6UmTX0IT250BQdyM0Yy2jnlaMSBEiblQUxmdkLBf1gwpvgglNQ== 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 AM9PR04MB8905.eurprd04.prod.outlook.com (2603:10a6:20b:408::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8272.20; Mon, 23 Dec 2024 03:33:24 +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; Mon, 23 Dec 2024 03:33:24 +0000 From: Carlos Song To: 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, Carlos Song , Clark Wang , Ahmad Fatoum Subject: [PATCH v6] i2c: imx: support DMA defer probing Date: Mon, 23 Dec 2024 11:44:16 +0800 Message-Id: <20241223034416.544022-1-carlos.song@nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: SG2PR04CA0212.apcprd04.prod.outlook.com (2603:1096:4:187::8) To AM0PR0402MB3937.eurprd04.prod.outlook.com (2603:10a6:208:5::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR0402MB3937:EE_|AM9PR04MB8905:EE_ X-MS-Office365-Filtering-Correlation-Id: 03599ec8-0afe-47bc-6829-08dd23028ea0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|1800799024|52116014|376014|366016|7053199007|38350700014; X-Microsoft-Antispam-Message-Info: 7e7L5/c1EbwCf7LsQ24pwmHDJbVO+Dfcwy5LAVEjjBSlzNQIlbp992c2RTHuLau/qxvsxJ7Bnt/3GkgmsUVsEO/mF0D2IfPZ4nbbRLNueMzK4gj6QcM6O3aAf4RFaCMyKAuq8weX9SuLuPrEp1oeMFH6xGZqlZLjfk+ZVTV2C5AKtn2ScGwfT5IMflnlX1d1ptn9zWJglf6tY//md1IJ6CX5JVoju4+jt0QgUOYtLCOEqLIR4M26QBoa4HyQHD5ZMAdT6XEpuSPeow224ba+0l28xhNvGwqsXSIF6bsFIfRTsgoBp5CX5bG36aOwD03j28bRkpfXVmm0CAUCcvwyLmGLvcPS0f2dnYpw11iDY5e4nhiYPH7OWShiar4PzSZDa7vcBfzPyEhbXk6eifR51ccYplb5BHk1g/pIT8pbD5DtK11aOf8Ox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LI;SFV:NSPM;H:AM0PR0402MB3937.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(1800799024)(52116014)(376014)(366016)(7053199007)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ieNyqVsr91cwAbMd7jF5foMFflRLfSUPwyDOCTWRZ2EKe+LS9n/E3qLh2djK/UvXISf9oKaWhPlvPnZkdvBbmZCb4v0pTsHyfqc/gq+Q/fGOHCzZEN8ML+TkT2AbyvWUcO/YCE3R0a8W9wAq1sB0tF59iHh+w0E8tUboHGde7ObW3vobiVvFDzaq5YAnlStMKQsjC82478UlA79+Ze4PWfqhppxFDSSierNgrryT192d8g3y0LC+rcSZxHNvcHBQbqnwPBqtUCTBa0Mj6LdL2GlnKhhK7F3AuUJpuJxbGH64rZ6SCb014lYRmzg7dLFiYFS+m4f/wHFq//UmWv75EO489I/1TfCMCMTy6ifTJNq8mFMP3oVEHzla5tZic8FvVzZL2wSo7yh1ck9X6vtbY2bfKg7p7ZRJm9ON9/1XNxleYRpdN1PLEnF2CE9X6ZRxBTujZop85dQlcXMlhiWCTbrPkiB4x6YFEcdSON906cRN4Y5nVrp81fukX6in6752xpq5Q++w3YjxmcIun9vGKNpLk6BiSkgAj4OJpHWDdvu5JCARBO+aEd6FmR5b8JZfanks2ljfZkEfRbTn5UGXCkikaO4QBnFn8R/APTMPCxtEt4thdzyzgruhTiis3tNTtG+hHTWVKDENoXvbr5FRjYlEPsgOY3Pg3q2Nz5QMn9xSopCL3xiZX3kGBbf2aMbqGTRvXkiPqOZnrJ96YBMBf5HZuhfvwnl3mmGQcmp2ddCyF14aw+Wrf+FER8aIsbxt0mDJXzIQ/PPHg/iFJ6RKhY+/NEvU397v+CwuNPxn6A2L93AK4M36xSUBK9QXCdtHkySPRig3ou/lh7gow7L/lgzWD7/yyvnHpTrdWxiU6Wy8utTf5RiPiNGfeU9RgvZLrt+WpZHeFUAsOzQ8kX2ZayhYJrpGQ9OJ8IdLkAFHlavCy64aoxKKvGhgsRvGfqWnZDqYN3fFD+92up825v+a3NcvB9QzLh53f2uIjpiIxFePWlkrn6QwkRxmzwRoch1L8uGDMArtUQVQ1omF96JqyADZ6ukSIBxBYtXJjfgSjBCD7Q6/wWNpjuktt2c3FruYGxl/EFEj0kte6g3j/WYwgyqV3OY6KFHlpE/NBCB2AgeGFRSPNK3QTXh2RWxRfNqOtUjTDQ+xrm3i42thvwlX91yhblnAQz2t4c4Vilbq6y7q9agtY6bp4ETTlyfSD6j0vLEldSoFE844v62V420DL2OIGB9grwOl0ZhlV3yDumXVriSDzOYEQkNAtZlibm3jAx2OVS8FjHv7/Ox5iggy9TXhUQwxD37reENlpMC+yVHWComXY9Lyf5hjIm0pQ+amNLGIFoq+bip7YBCQXbkgDyYReFMsmSYEzNVJxlO7XWz6qZpLv29DxIYNKQB/fhEMko9sihKRoYHvlj9cg8GdHvwO1EBTfuY9ci8dEYzUzVcSCEWGWhKbT8qn5SzcjajGP5LRCtWlqzBTMj8HIswTgOOi5QJxCIxEvO0T4guDrsvispAjUv23HIBDm0zZjvvRtzibmhcw/0gBuINuUP1lZwdJMfXhnqcLYpvXM75tqjjD7lxO0V+fEyhx1gTQ+IP/ X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 03599ec8-0afe-47bc-6829-08dd23028ea0 X-MS-Exchange-CrossTenant-AuthSource: AM0PR0402MB3937.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Dec 2024 03:33:24.7948 (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: 7GPNq+LXetnRdZWRIO6ZrV8z8VIGgrDwP11ANi53+y6CfHSMg7u2R97/iL+JaC3dwn9F++cGWqnjck9Dvmx3bQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8905 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241222_193332_336518_5C7B44C7 X-CRM114-Status: GOOD ( 17.87 ) 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 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 | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c index 1f441227bfdc..9ac02640fdff 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,18 @@ static int i2c_imx_probe(struct platform_device *pdev) if (ret == -EPROBE_DEFER) goto clk_notifier_unregister; + /* As we can always fall back to PIO, let's ignore the error setting up DMA. */ + 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_err(&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 +1829,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: