From patchwork Mon Nov 25 13:52:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Song X-Patchwork-Id: 13884918 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2076.outbound.protection.outlook.com [40.107.22.76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 156071ADFEA for ; Mon, 25 Nov 2024 13:44:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.22.76 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732542257; cv=fail; b=sz8huFo3Kx178zkc04WPlRZrpl0G3qwYKDfyDhIB7dIykiJ+keEN9/Opx8QSmNfDWNcJGebljxDtLSEpMeVYI8SZ/vYgTeWA3luBbjSIEnRPEntBbh1iHN9Ry7vwkdwQMJrILX6rBIEccmhsbspceBCigCFvqKQ24CB9k/3Zr4A= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732542257; c=relaxed/simple; bh=vvQXOy9RkY4jnMkA7xEKMlhx8rUmN1bK6n6YENzvPM8=; h=From:To:Cc:Subject:Date:Message-Id:Content-Type:MIME-Version; b=kifa99Z14U4Mtzufd1p/q+xa28Mhym+AT/g4jkxNsn3VDcof89GHNLqDcC0HZxhflw3rh4lsQZpSjQUJu3kt2ZxE4vn3XKFN6yV49nLz1dNgqgWIucQm+BqVzBN6bOSJ+2CQMa03edKpFMuFn2NyPfMZ+MMcuqlrhtY1ERDPPv4= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=OHhBLlcc; arc=fail smtp.client-ip=40.107.22.76 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="OHhBLlcc" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=H3pxgxl14NCgjyJMlfQu9/OYjEiis5YgoaUxzNdkOigT+7i+oBEKHAzA81c70hUp27jOeT56uOC0gnD83GDr5PheSC3211RqzGifl0siPeiX2W38SznBIYKvKaClfYlryrFlLh/vUDpHAmAoHohv6ED2T6VcdmB1ztnnHSxPMO9F77sJ9FiYoDI6kpk4FBE/xpp7qyAFUjzeJj7yotV0U9XskCg4Es+vG2b+EJn+5+auIdoI54ACKdhUo+WjKv0mO8u5MdsHg7VZo6csKBgNBJxcS4e5Nbx6VwQoonP88KddkLaWn8W+rYHQOfQ9Wtbe99Ebg2Xr3vgsdE0NEHtFCw== 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=UT0ygFIGNZy8rClncJeTPMnEQilwEgKkNkm99OuKNPU=; b=jL/5gJDq72KHwM9NdBYV+pQEuG+xJD8Q6lIXj0zqjVes+vAmAkawoPTTAopvoXvgRBwJVMsJVadHpKCsoYGSDQ5HEIebCcLllzqlGCx5YuuB5yqud0DJxbywCaCHWf/ayQl8xQ8xyf2ITc+rTg15lFLn6AgDm94bhIHLhie6eVkrlHrrBxWG+iJCj9vbEGRMsuvKR41tl8GTk6Qz5IOCx8sw/iVbsepgDURofsxw9wucOuwLGAcr8CV3ha23PFw89Jkfq7SIbds4aYZa7q127PLtbwmMusE4HlrOHFmKrYpwAM5XUYaz7qidoI373FO7O/gGUdhasHzOzYG7GAvlDQ== 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=UT0ygFIGNZy8rClncJeTPMnEQilwEgKkNkm99OuKNPU=; b=OHhBLlccQaw85Amb3qC/1zztyJ5HgFcIttOXZIPkUe3pqBZuQ315ffNDmd2qdAzb9X8l0f4oo7kUainVUg1+T6GRd5bVjibHMIQfT5kHeFa210LrkNqL3WI+TDuwfwucvQddVo/+ocqMxAeq5CTazv8PUtHA3gwh/IcQCuEQfQ/Gs37pjHN9SQnZNOOPS9LH4d7U+ACepEsdXn/eYruAqOvh9TdHH8TVYIruDnyQ11LGH2LXl/4mOxLKfS/7aEJpy8hgOWQ6rsq0Mjpa2wFh6KPBg45cDh858l4PcuK0aLkwnTg10EhfFm3/eSkQC3xs69Ff4e3yV13A0ZxI7Fis7g== 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 VI1PR04MB10050.eurprd04.prod.outlook.com (2603:10a6:800:1db::18) 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 13:44:10 +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 13:44:10 +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: support DMA defer probing Date: Mon, 25 Nov 2024 21:52:43 +0800 Message-Id: <20241125135243.1612098-1-carlos.song@nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: AS4P250CA0024.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:5e3::17) To AM6PR0402MB3944.eurprd04.prod.outlook.com (2603:10a6:209:1c::19) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR0402MB3937:EE_|VI1PR04MB10050:EE_ X-MS-Office365-Filtering-Correlation-Id: dc6e34d1-3ac5-4243-c8ab-08dd0d573d80 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: VQyl4q7aef7d6S0xjtxLRJE0uDlpNk01mLoT2N+xSB8odbxJo9YSG2BWWq6SmWTjkzJ4CA9/wRRQo3W31boIE51EsGyqtuQezIX4dWveSWOv/V+SfsbeoRQqaxBgfeSBiEzwXs/ix1TuFyj5z5QFJ152GlU/ZoINJyN8qVMZxNIbUgQdYJQWov6dXVXPDB6n+hILR42B26tZHQZYd44k8slEGuFxEwZanxJd1zBxvHhL0sjI9vx+q8lX6lp1e7Hr7hKDvpjS0ZyUXImkhzO0cdCQPhJGC73kjFdx3zxlbhFwqxEMelf0A/5AgvPhvVUruNwfvy8Xf0vFrs/kbfSRrCKD48TXoCzsNVj5/nGQHvqfdYqvn36ArX7h6D+5SafE+vo3vecQXIOefYnuEuxWVC12ru/UQMqeUuPBP+K04t3jyDspFwt1wyxybfB+MrM0tICaDn6WA4tEF72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ee1blYSaOQ63Y1hvLhyiGKVNefzVOI6oppn6UVPdZ1HjNuU9uJ0SdhG2tNT66JkbRGAnX7eppuRzk43yA00jbGPdQvpUT5lZAfOoF3RQopyjonVfbgdW3Fd1lrEM36JM3DBW8m9FH93MHSqngCV3eMwIvHyiF3pKiAd3VMOZ3cOinayZcj1B75FlkjamAJrLETa88f7gjaidsk3V2PIS+f6vorfF72uGfeGf5S2GH2aTg3fXgwU96qwF8NowQTZmvm4Jwxm1k+Y/vuJMZDhRgSiX6cLkFpsT2TS2EXUTZJ8/PnJG7iCIWeqlT968Nh3zV4FyChbkM5VtJhcLVP9CqnulpGtK8Ji0sMNNXNU+t6WYLOeeit7pBkJrTkgpDLv8RQKxJVb2maTTqJ9RXAiYoKxsbUTE6apPvHzVXDbh0m5MtXISEGZAf+p9P2/orPSddz8xmNWp5eyPPFLecydYdgXS/yYEG28QWiAhgeXAsoSB2epUMCEfD1BcUcsIxapY190tazZVqIEmEZn9YTk+bpgpbuZUYSEbnTTjLZ+aFG44WeinAniN81HKMABai+qlafKKt9kTbLnu0LpirZao2VHLi/b7ju3+JmtCItsMWx15RT0NoP+tP7gYoCSijF+67sbKXgXvbWtD0o X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: dc6e34d1-3ac5-4243-c8ab-08dd0d573d80 X-MS-Exchange-CrossTenant-AuthSource: AM6PR0402MB3944.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Nov 2024 13:44:10.5945 (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: ROGi/kM4Y78xhF+fM2ccJiG0xMykGZhmNg/QQLjVcDu3I1LSJQ2PGFNL61XrY8Dsk2P43tTLI/Ug9Bj9SN5qhg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB10050 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 --- 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..ee7070ee9e6e 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 device *dev, dma_addr_t phy_addr) { + struct imx_i2c_struct *i2c_imx = dev_get_drvdata(dev); struct imx_i2c_dma *dma; struct dma_slave_config dma_sconfig; - struct device *dev = &i2c_imx->adapter.dev; 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(&pdev->dev, 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: