From patchwork Wed Nov 27 08:38:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Song X-Patchwork-Id: 13886715 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 6B5BED609B0 for ; Wed, 27 Nov 2024 08:31:41 +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=C2klUdBFSAfSWXI7qfPvmxcGEhG1BdT3HM1jmzBV5hs=; b=E29gxcXKIe4d+rlzXKS8PDA3Y2 +5lykpiPxo/1KxfWYao14s8igzwY58wJejn39LreR3adr+eFsS/8LjZe9j21X4UMxw5lu/4Bpw2aV jeWF0HcEg0NYzJuhoSFF65vd6VcNgSbz7uErVDXaxukdBZFg3LofZWuyUlpa/jLxCLd6Jh1MZw71n zAqLG0iELFpgiYK5u439UQg2/woElAX2hc3TMcc/fIllBHay7RfiyL+/hYGN31ccNicZxPXwroRAt vI2qIOAxDi+ol1vJyCZZD8ro6fLI9xr0xEUbgpEi4mGeVQgpgUbsQ8ibKXihjBPrczXlicqGsXcy6 vO8itt6g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tGDSL-0000000CZxu-49fU; Wed, 27 Nov 2024 08:31:29 +0000 Received: from mail-db8eur05on2062a.outbound.protection.outlook.com ([2a01:111:f403:2614::62a] helo=EUR05-DB8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tGDQZ-0000000CZf9-3KOQ for linux-arm-kernel@lists.infradead.org; Wed, 27 Nov 2024 08:29:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=FJbjsLw0cKfbuaqEbABtncSl+4pEK6w5GyU2eI26PcK05fa+k3G6cDOUpptRoGC67m2lVVegIP+cEInubXG5G2HAhGCLuv4hVkq3NSu5MOCdsBMRNbqHPExcs3DS1LLmamQ3264OHFGEEEjY3D6o5vWnOcEzatXrJdHGYQWfDDLGyNx3UFZnBGJcnttzWGjONMuDruwt5NHC7E8m8SkMZCAmsnMBDvv/GQqyq5KubOWZbwf5cEk/9a4fdcmddcP1NhL2veLZ1PqixLmwFIRIy+rbnLRI4pbFZmYi4vcswhFOdLwngebNyNI3i50ivZiCEYZhg4ulaZ1LEehZudzO8g== 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=C2klUdBFSAfSWXI7qfPvmxcGEhG1BdT3HM1jmzBV5hs=; b=owJRkbR+e/NRHA13euLqFwTq7xNPUTupYZ08QTu/PrW4ybMD2o1jp1Vkh4CRHibbuXPzdUJH/GNezcNN4oCNRQOUKsCcUe0gt0eosOvaj4tCh1Lu+DfCOwDbPM8PKV8M8YPT+AL9EsHphIKRoujTtAl0NVY/7FLG4Qkxwufk5x7Yu+r9zpngRuSM8H54AlgVc9sUhS62FCtvLp7TbvzE5XYiAKIDITf63UWw9MS6AQTzTuTJQE/ctsQt4VpjpE1fOi75OJoFTVBzG6GFAa56gLF/6qzfPBY3rzSXbBis8qs6IIOlHEbj4AgMpbWPb0g9/OM+MqJP7gO8eTZOU4vw6g== 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=C2klUdBFSAfSWXI7qfPvmxcGEhG1BdT3HM1jmzBV5hs=; b=jv7xoii6bdmO6j4GWaEdeXGfo4Pa41QuH6+hLwMspjV3VAkwG4I1fdxkdb78sU5fR6t+AI8DfzH5tWJnkL2g8xUfsx0iqaKTM2LnUeh9Pi8QAx08HI81nlXdOMotTAHAJ5RPI4AjsNOHPKnMwu/BCzIkhtQfS7Heo030WBcL5uZVsUxvJekGmTVnY2r/zPhu0hPAOuMXEAe0njb+pO7pjFK1E+536Gm7mD4D0ZBtaLcerBW65HqupeA4scEfwTR93sC6TlwbQa0FAbJhUKgeBGeVuhZ/FBvkFIwEo2VUP/fHaAt/tpeyIAEXa098KFR6GTLuIUF4KGlIDnxelYkhnw== 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 PR3PR04MB7227.eurprd04.prod.outlook.com (2603:10a6:102:82::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8182.21; Wed, 27 Nov 2024 08:29:34 +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; Wed, 27 Nov 2024 08:29:34 +0000 From: carlos.song@nxp.com To: mkl@pengutronix.de, 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 v4] i2c: imx: support DMA defer probing Date: Wed, 27 Nov 2024 16:38:18 +0800 Message-Id: <20241127083818.2108201-1-carlos.song@nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: SGAP274CA0009.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:b6::21) To AM0PR0402MB3937.eurprd04.prod.outlook.com (2603:10a6:208:5::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR0402MB3937:EE_|PR3PR04MB7227:EE_ X-MS-Office365-Filtering-Correlation-Id: 56169ea9-09ae-4ead-711c-08dd0ebd9ecf X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|52116014|376014|366016|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: JwYUQUAUBIFAvbqMnF1eP+xZ4IqhiGim/ba+WQESlYGP/QMzMkku70e6qJiVx23EC0dEU6lcyhgZ/GqE2yG56w5ghiUVorWYKUnkbEQNoUHjTdK1o8dv9lIxc0uQF1hAruEsF1iUkjpWzPJV7KFH0d/r3zjuWk7WQhsD/DnhiCSLkPdRHgHd506ZYMR7M6m5EXyB+WTu359iVOy5iuwFRgd0zlLDjnZlDogdth8sFK2R6Y1xg+YyhEdhZXaG8c0MNJ3Y+ty8XnvERMAuzbh0Pd+XXhYRg4W6Y7Ny9DlAazhv4n/GHtrrSde1yveFI01Vl4lMGoHNFPu6Jpit3KecskfdtdsaV6D4KXqXG7QVVPtM3YkTlHt90+CMu36D+j9BdBd2SKwDril+aJTPzpoE3bWKoDQY5vpuNiFTKef9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PM;H:AM0PR0402MB3937.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(52116014)(376014)(366016)(1800799024)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: JNOdaxHBM3jWIwPBWBV1tQxu2THnVMVXS0hCrejrJ11XzhuNowUUy5gNdlnTxKp3NDklrj1QYUTmw2yPveHBMil9ky0eRlgtr3LfPD/AE2vaiYWk/iCZKVBN4c13y3lhKJzjRbMiA1kjLcaWDhsdWdpP0/NUpWbgAV0BoTBZMMPzVmeioazqc1EfyL4uNc7+XSaH+K4xa6sOZd0TGrlW8CrWGTNVwZpZzuXXKJK0oycM+mDoVfuJmKS7ZuUpQPaAXO9a16r5qCVKhuFbo9oSbQ567aw0ygel/WHB854XeG2E/7aTgabECxMvv8qEhtgDVUos/2DBek5B7lLbw6yGAM40Vf9HAdF6NJ42R3vz6/qIzIgIZgWvXZ9YOv28D77t5suPFO8UQAGx10VD8pDIz34hpOZbdavSDlXdHkn/kGbVWCYkjoMpesM+7GoFEsctgGcvQQ9UxaN3uUtzYysHpE20UcwZBfXmwr3Azpz9oWJkNPV2IfTlLfBBtSU5XWmT2cshWC+TPz9R6g9fHJAVNenqxXNfvIwOUW1futS8kX1GxBLww8aure3BTkG5OBeByCnNNK5xdGLqWJ8DTXZM82vGcIbZp5ugvLMUv6xGaOxmRXUzsKKwXDgYEyp0cgw0BtAaUCnRaq59up3C6Bi5exhsy4apNqZlU3PAJvhwBmSY6/RXveLHYjMlH6a3NpTqKX+WTB30WaXqLXsA3Ulbb1rczYqyNMwz36Ksc8Gzl9RHKC1o2qqrBVAzbPj6kw5KxgeZy3d5ncJsXjO6GG1z1+Kb/zIG3UDBwMpDyZh3bKznKaGqXJq29tiyczW5tQrILr/dIEjuKo7Mgxlo1pA1InZqu+wzbrPTBvv3ubDsSWJvm4UVTB1y5D5btggGP22tCtWxqnTsJmpxILfOcaDuhZjI8eG7owxNx1SKVZJcvVnD/ZIWYaxJiMl+tNQvK7kY0+u7mmc7IzecUYFWPjpsfQ1skAbU8WAa6BlnJHMgCJPgIP7AGkjpfdMd+G2hRUTNCyABbxPgnIrOLFV+ml3glGLxkH4sXBqaSk0Y46s4+m7SZdOdW4gtK7ll+li4FDWIEfDAaDS7j85wvyRJzL+UMucQQJ7ZQawciCXCXUFS4OhZ8ZrPJCtMq3BY3phBSYehkq2wnkUkM1YFFAR3zco3odOzMUd9AkiruZE1AWv6grxGnVWFPLCbvEPXB8rtaRtlRhlfSHxeP6ZpZtNSbu+rrkWpBll3hSBgc/cxvtJIDuXAKGtNNWDhJk3jtgQABIShV3W5O6nyJgHnFkYnRxFUjZ6bXoKaJunqkh3rBwO+knZrl8x8vVRO5ska4MJ1sxe4R/aiKJzxD8KjXx/8OIcRwz10nCtr06kV7WH3KrJriOZJEZJPr/weajCN3ACnxzj9ah5SD7avP2TLKqxA3XAh8KiIaJ5W+bQDWA5B1ly0n7e7x8kCjn/f7KwgPEHYdnv9g1ZxxaXiwt5rudGSXjk5Ab3NjZ56ZaGjZGQfBZofUo5hhz6P+z7a8knVU3eVLQdBGzwRDNStfPZg+ALY5GkNBMV0w6Yv/1O+xiggbMikpir8MamUCKAqAQlK5g+uDWNU X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 56169ea9-09ae-4ead-711c-08dd0ebd9ecf X-MS-Exchange-CrossTenant-AuthSource: AM0PR0402MB3937.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Nov 2024 08:29:34.4392 (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: IyrB9XpM4iJVwnDKpUFZFfTiHmxJPt9SHawFkIYV8ZQ0gALvgceilQcb+jEyQfPqEJy4TrlSUVBnhoXXsOD+pg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR04MB7227 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241127_002939_836579_90CF09B8 X-CRM114-Status: GOOD ( 19.97 ) 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 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 | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c index 5ed4cb61e262..b11d66d56c55 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,23 @@ static int i2c_imx_probe(struct platform_device *pdev) if (ret == -EPROBE_DEFER) goto clk_notifier_unregister; + /* + * Init DMA config if supported, -ENODEV means DMA not enabled at + * this platform, that is not a real error, so just remind "only + * PIO mode is used". If DMA is enabled, but meet error when request + * DMA channel, error should be showed in probe error log. PIO mode + * should be available regardless of 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_probe(&pdev->dev, ret, "Failed to setup DMA, only use PIO mode\n"); + } + /* Add I2C adapter */ ret = i2c_add_numbered_adapter(&i2c_imx->adapter); if (ret < 0) @@ -1817,9 +1835,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: