From patchwork Wed Nov 27 07:44:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Song X-Patchwork-Id: 13886648 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 9BB4ED609AA for ; Wed, 27 Nov 2024 07:37:31 +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=ByBN8BrOkPzMFGJ3n4z/y6uvKLhJ0B/TDBa89ZBhtGM=; b=4DJyL6PXuInZsAQ+zoz5Dxzgnt 2hMOAoXXqQTRupoLe9tVjL+A2t1lgHKaqc2m2n2w9Hyywiq5UfTO/Q3B14TRqrPBTAeXngp4XAuRh p6JoUgvRKPrVu1sqyJTO+vWR3tgTCcxR/FQiukLZYVSJLcEIJbPdGYWJnRwH36h2x8yxi+8yxYdXx z3iaVt5xC2wYQ4at4OvKKUMHYNhH81rFAB7c39mxiDvfhUsEsXe0P3rlZdW8S5jLhfEgAlmOHzga7 pcUyEGZLb2p+EQlh0+II8jOY5gD8fnlKoaByAEcY4m81Qar+IO0SxJ2NKNaqJT3SXm+5ukeZUwpX6 WsqEx8ZA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tGCbv-0000000CSGe-48o7; Wed, 27 Nov 2024 07:37:19 +0000 Received: from mail-am0eur02on20627.outbound.protection.outlook.com ([2a01:111:f403:2606::627] helo=EUR02-AM0-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tGCax-0000000CS3L-1aaz for linux-arm-kernel@lists.infradead.org; Wed, 27 Nov 2024 07:36:20 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=uwCBzss6qvtEIZPQIDx7EMw4x/Sl7khbIuepZmeVrEfbnjtGD0nKwLQen8HUezTXiY6TYqilbSRvmInhSrjCAIY3eA4JQ9DtD9k9MdabaJ3uLJ864OBhq4gczFmWaDQOeZYqnP4ntAPCpMItvacO82BLqq+1J/rjB0+sZbsO4kyODo0CLflwGCuO+LgkdVCxHIVbe/JZPa75wTS22uVBkXU/AI5NLDyg+RbWvQ8mRp8RAqqNI1NIUzINYAp0QcZG01/ejtseajkXIPhRWrdxqL1I0XGJ7Nri/6fM/KhE9h+p+7IvnvqGBlubPZsLXzh9wDXtoK0HxRIFvT02Uh5EiQ== 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=ByBN8BrOkPzMFGJ3n4z/y6uvKLhJ0B/TDBa89ZBhtGM=; b=aP/LATGrauvE66B926OJNQLxccf6ztDo03U/7Nl9+skLBrSetWtCVRzKPQ76IF36qawG587n2F+N8Zo3Q+pEq//dCfoX8LQ0s+3zdqKYTQl3FaObqm9lLmtRxrGPuRu/8DlmCt6gvm5Z5n+soRcZSYMeyqu68JwIRNSvjcZr1EFx39wLg5cV0IQwDWHKWuFEstPR/fhLvzb9qRhQx9CzXPsoGQ9woEiG157J18rYqWr5BT9qNwknYJ96o+8YD/foDMBPkWtm39njKPoUp1Ozo3UQW+TeTanxaliClEr6Vd+5jMY2/nEO8V3YP8sJfL670WSo9dKRTTZRWct7ZeEELQ== 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=ByBN8BrOkPzMFGJ3n4z/y6uvKLhJ0B/TDBa89ZBhtGM=; b=N/smPCD3dZaUVHSCDIhOc/ZYj+RLamtoQSEfbKU/y6S6cUtfJLVNweVO0uZNVNcHV/LXAukFtBrRr3etlXRuX4sfdggDNLSzdBTEkfq4YsgrVV9WirEu65nec0Hi+QxNcds+2SKtVeqfD69wr7FPEqkft9+1LcRSBQPR0nv1i4am/4F3FbeVFeQsX5xX8lIihLMkbn1MtTzznN9fxsiGQN89qqfasx0Ku3XXnO+gT/LIsSDBEffz7WPOmXWcvBmf9y+HbZBEOo9NtlXE/+5VT4J8UxPfNJwYqyZyaGHPGP+GnrAmtoXuY4aUqntQidNqCIencjXVS4roKJ5lOgqwSw== 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 DU2PR04MB9081.eurprd04.prod.outlook.com (2603:10a6:10:2f0::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8182.20; Wed, 27 Nov 2024 07:36:15 +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 07:36:15 +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 v3] i2c: imx: support DMA defer probing Date: Wed, 27 Nov 2024 15:44:58 +0800 Message-Id: <20241127074458.2102112-1-carlos.song@nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: SI2PR02CA0042.apcprd02.prod.outlook.com (2603:1096:4:196::19) To AM0PR0402MB3937.eurprd04.prod.outlook.com (2603:10a6:208:5::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR0402MB3937:EE_|DU2PR04MB9081:EE_ X-MS-Office365-Filtering-Correlation-Id: ba2f76f9-a9ca-43f1-deaa-08dd0eb62c4f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|52116014|7416014|366016|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: nYipz2uSaufNSfFIu0ZykatBT9HCpAEHUVKrRLuaUhFfriSgbe8diJCRDb/OLxLRhXwFI2nWkY/fgTuzXHmDp43Oh5hWSTWBWAXwkC3usEnoRyQfJwIzCDAx1Hrrx/C6z75Hzbkx9/SpSDW/OdtQOTpsNfeWJ551BMp5njKDntmEUlfPNSczva7y+5X1WbRuo1oyCBWKuNV+gqHobkLLjuaKgegDIA7dZ+qz0UtSqrwUHQxByoEZaniO/9edRjoNWrjS8Qtp6Bk+77OoiOFTHzysyRNqgnGceOz2yTESdpgDXki7rEZDz+gnohSPPhLYlyniJA2GTSJhRR6Wot8y6nfwpr22Yr94vceJVXouSgJaI13aozUmNg98em+SO5GSLsCBI4eV1ERFJbvGxGvAGlELYysLDLWoFIX+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eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(52116014)(7416014)(366016)(1800799024)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: emSZ5bnQD1cHdC3F6jruviFD3Fh7lCbjqFUyLyNoSeHX0BNgQ4HS/CAD5pn+4oII/fYUCLiEk3UNc1iIPrdH2ZtlAHXIxTIMnYNkl0VyPb8AVAJzoWq9KtjDydb4AZ2WOdM5QRTzLrW7P4jJgehRQbDOsXmxgw4Ij1KH/NC+ZELG2OHc0jqcE6lc5z4YFpEOHnaMUb5dnlLsTY8AKVmtSGZzUMklojhPVodbn94o5pjeVoXpatlNs60M1lCPFBfH3VKU2t/X9ku0q8pSbUTzv42A9NA0uYXRDxkO4ZddDON+eiLtN1eiBUElmvFUMk/jPJs6L8OGOn0aGzQHINywKwTfMM4OcfpBp6Jd4to69x45JeEKKXmZjtI54EFXlrvXAiTpdag91DreQ5Lbf4FxMsG5WQPIOTFpYdyUdBmLtEP52ii44IO8w7941rqBmyFBZVN6psqb7MTsbY7jNLXPzW99CZ0/fjv4N1piMebFi2uXtyFUyLUtsm4r2SnrlGyhCjTLn+EgAWVnNzl4FOA/Om06uy/aVtN2EevCiQAMUrMVdrvBpuOwyloFOtT2CVUjOfWpljzAZ9R5oSDFGkhIXl8o7dLAImJ4q4A8IFBZKsyq7+ydKREMsNC9fSevo6+cgRwmrqfbKj4Uz5CV4VlTzU/E0psFwVHKRF/SacoMpfVLqcPHUZ8baEQHUHi32OTr7z9lRHFSXqT4rlwUm5TVsCEwTHG76KBmVaWr0wyFwUQkxH7jvz1zADN3XINwrKKVeECCGyfVzXFqUhBAZp23qkQyoFVX3Cey+l3dw9zw7StSRTB3esz3uc+sA0h3R0CLH81LSSCrltC86kpXewxgNWwZpx3gfEa8oeNSJB/Sjn6iheWWgti9kagGTivaURsaF/hNlbjDx2aF0/95+KdNjwVqCsq3IFmO2CFf57YuF+2g8xbJu0e2r6QPxEGpir3ZoVzNUzLSA+q0fDM/OS2uMBMP3d/ihtAffR7gR67BxDB5+qv0Ju1QWcEfgtxD7j2+Yoqk+QjEH6cMp2/ir8x5Fa/uS57rjdK+JqvG3pN/YYxZ201QRu0BCxCBkjzttqP1Sh963WLqvyx7xN5bXfeiq5irlixAdOI0xj18BqfJ8i+1RosrZfuCRHr3YJ4Wxt6FkwnrLEfZDw6pY//AXoc8lnLtqiqoX67kk0eLc6ZBoHhvQA7uLNcuTQBn7M8FV7dfXlbwetg2NKIbQB+241edv1geY3CQKIg2n0QmK+PvD+ROPPKQ7itB5QASGISznw/+QsUJ1p5OOv3/qqHAwxFYGEIzfXjZ4JE/Gj+1Db75euxYoWBf1f6i6GNenY9ojUeu09+lLE7sqQS3511KwKXhEeLnO6TOxDg+nHkPqNgdVX6QBAekIN+1yt963soAwwoO2teENeajzWnjjLWPdfERD1HPkB5jTINUaYaV9Aunrye75lBxwy2fCP4AUe1ktlLprLxu6gePZC6XAN8sVnL83dVqYKHovUBap9EoaG131+BIPX9RcGLVzlgIf05BKcIbb+hX++LNDIWyNhM3AqmPI5hAhKMxVjgtGilXxgkLP8lSWos9bLcY+Ws1ZQzNxjFG X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: ba2f76f9-a9ca-43f1-deaa-08dd0eb62c4f X-MS-Exchange-CrossTenant-AuthSource: AM0PR0402MB3937.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Nov 2024 07:36:14.9381 (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: X6tk9N+KEhphhEjWoxNaxiBqm+nf85IJ/q74SAhfY6FPwcnt8KZBs5n9ROJL0w1ZJoxY4uYT4UJU8qdEXHfgUw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB9081 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241126_233619_430610_8AC14302 X-CRM114-Status: GOOD ( 19.73 ) 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 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..47112a38d034 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_info(&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: