From patchwork Mon Dec 18 17:06:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregor Herburger X-Patchwork-Id: 13497294 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 623F5C35274 for ; Mon, 18 Dec 2023 17:06:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Message-Id:MIME-Version:Subject: Date: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=RcylAupXQPCEzKkl0WDPsv4hufXHwXT+ZXR5qK/fmkA=; b=HrX81qZdMNNUMA 5WkaQrpVlEVVRvDa3EJszWAEche5euhc3+X7wyqZ7CaJCn5bCgOC4zhIn+zJL4fm3XQenHfpB6D9y E87fXDu56shBOG2T2U+j/GUN7sZHkuV3SPPXcxcbQYqzpiStexgAOugC1n26rcbbw34WnsEygkNqf uGybQurwsJLR66ggIH9Z0ifpbq/BlwCuQdEUVVoBIHlY32Lyr4hRztsmXsHFSjgFaZpbQJgN+xmQ+ QOu2vZPOvqvNncFIm7TAq9HtcDX4l1EpJEkUAB2vbwm6GSIe70ub49ex4RJzjVwfICtf7vyKqnPXl yizgeNpEvVDFd3jRL3+Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rFH4X-00BZtm-37; Mon, 18 Dec 2023 17:06:29 +0000 Received: from mx1.tq-group.com ([93.104.207.81]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rFH4T-00BZrN-2j for linux-arm-kernel@lists.infradead.org; Mon, 18 Dec 2023 17:06:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tq-group.com; i=@tq-group.com; q=dns/txt; s=key1; t=1702919187; x=1734455187; h=from:date:subject:mime-version:content-transfer-encoding: message-id:to:cc; bh=S2gUuVNTEJ/Mk6mRDuFWFq7L6gFeHwDmMi/57lMUPvo=; b=RcnvZI2Qrt30OnrzY986JZObJNZdmhvSq9gpkFq52SwDBuJjQF6k5KdA 8imDEAEVigrZUuR5qHTX0iLFW/Ft68FU6iQwJgzAUTq3JYNey+uDh4Sls 9gkBeHW0t618Ga2hk30YjCjvu4IitzdFv99XZ8ed7NAA1Ow2mdBLk7lcF /EaN3eYmuyNgohe31fgwBZHhZlDxc+tm/PPAjtr0JYD8iT4394Jm+uDWK 4m9O74X2VDi4HCJ3+zoSQyp1aRN+aqY1w2JPa1puzU4fS1jho+GOI4NxL dbEgDJgukLJwXl3NVK2dqRhYQdu26H9kJ4zyoPjCwsE27IXVFcSDwSsI2 g==; X-IronPort-AV: E=Sophos;i="6.04,286,1695679200"; d="scan'208";a="34568401" Received: from vtuxmail01.tq-net.de ([10.115.0.20]) by mx1.tq-group.com with ESMTP; 18 Dec 2023 18:06:20 +0100 Received: from [127.0.1.1] (herburgerg-w2.tq-net.de [10.122.52.145]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by vtuxmail01.tq-net.de (Postfix) with ESMTPSA id DAC54280075; Mon, 18 Dec 2023 18:06:18 +0100 (CET) From: Gregor Herburger Date: Mon, 18 Dec 2023 18:06:12 +0100 Subject: [PATCH] i2c: i2c-imx: allow bus recovery on non-muxable pads MIME-Version: 1.0 Message-Id: <20231218-i2c-imx-recovery-v1-1-f69fa85b228c@ew.tq-group.com> X-B4-Tracking: v=1; b=H4sIAAN8gGUC/x3MTQqAIBBA4avErBvwB0S6SrQIHWsWaYwQRXj3p OW3eO+FSsJUYRpeELq4cskdehwg7GveCDl2g1HGaqM9sgnIx41CoVwkD7q4OpeU9Tom6NkplPj +l/PS2geIvHk9YgAAAA== To: Oleksij Rempel , Pengutronix Kernel Team , Andi Shyti , Shawn Guo , Sascha Hauer , Fabio Estevam , NXP Linux Team Cc: linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux@ew.tq-group.com, gregor.herburger@ew.tq-group.com X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1702919179; l=3178; i=gregor.herburger@ew.tq-group.com; s=20230829; h=from:subject:message-id; bh=p1iMSV8UId0zezOPOEITodjFEkpmIHiOCQIb5jeSM8I=; b=D966ipN6vH2FDSHYE4txEvdIYmkKeXpnSGCiJ4Y8ODCPVy3W0lbS8OTdF29k37nPuaU6vPtMK bt0QCfb9miWATUVvQOmGapUccEndAugw8Cu/sAzHa/UB0MPKAo7s3iC X-Developer-Key: i=gregor.herburger@ew.tq-group.com; a=ed25519; pk=+eRxwX7ikXwazcRjlOjj2/tbDmfVZdDLoW+xLZbQ4h4= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231218_090626_266476_46E944E6 X-CRM114-Status: GOOD ( 11.68 ) 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 Currently the i2c-imx driver assumes that for bus recovery the i2c pins can be reconfigured as gpio via pinctrl. But bus recovery can also be done with a gpio electrically connected to i2c scl. Modify i2c_imx_init_recovery_info to allow bus recovery on platforms without pinctrl. In this case only use scl-gpio and i2c_generic_scl_recovery. Signed-off-by: Gregor Herburger Signed-off-by: Esben Haabendal --- drivers/i2c/busses/i2c-imx.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) --- base-commit: ceb2fe0d438644e1de06b9a6468a1fb8e2199c70 change-id: 20231218-i2c-imx-recovery-6da66f0381df Best regards, diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c index 1775a79aeba2..7d71accb031b 100644 --- a/drivers/i2c/busses/i2c-imx.c +++ b/drivers/i2c/busses/i2c-imx.c @@ -1388,20 +1388,23 @@ static int i2c_imx_init_recovery_info(struct imx_i2c_struct *i2c_imx, struct i2c_bus_recovery_info *rinfo = &i2c_imx->rinfo; i2c_imx->pinctrl = devm_pinctrl_get(&pdev->dev); - if (!i2c_imx->pinctrl) { - dev_info(&pdev->dev, "pinctrl unavailable, bus recovery not supported\n"); - return 0; - } + + if (PTR_ERR(i2c_imx->pinctrl) == -EPROBE_DEFER) + return -EPROBE_DEFER; + if (IS_ERR(i2c_imx->pinctrl)) { - dev_info(&pdev->dev, "can't get pinctrl, bus recovery not supported\n"); - return PTR_ERR(i2c_imx->pinctrl); + i2c_imx->pinctrl = NULL; + dev_info(&pdev->dev, "can't get pinctrl, trying non-pinctrl gpio recovery.\n"); } - i2c_imx->pinctrl_pins_default = pinctrl_lookup_state(i2c_imx->pinctrl, - PINCTRL_STATE_DEFAULT); - i2c_imx->pinctrl_pins_gpio = pinctrl_lookup_state(i2c_imx->pinctrl, - "gpio"); - rinfo->sda_gpiod = devm_gpiod_get(&pdev->dev, "sda", GPIOD_IN); + if (i2c_imx->pinctrl) { + i2c_imx->pinctrl_pins_default = pinctrl_lookup_state(i2c_imx->pinctrl, + PINCTRL_STATE_DEFAULT); + i2c_imx->pinctrl_pins_gpio = pinctrl_lookup_state(i2c_imx->pinctrl, + "gpio"); + } + + rinfo->sda_gpiod = devm_gpiod_get_optional(&pdev->dev, "sda", GPIOD_IN); rinfo->scl_gpiod = devm_gpiod_get(&pdev->dev, "scl", GPIOD_OUT_HIGH_OPEN_DRAIN); if (PTR_ERR(rinfo->sda_gpiod) == -EPROBE_DEFER || @@ -1415,11 +1418,15 @@ static int i2c_imx_init_recovery_info(struct imx_i2c_struct *i2c_imx, return 0; } - dev_dbg(&pdev->dev, "using scl%s for recovery\n", + if (i2c_imx->pinctrl_pins_default && i2c_imx->pinctrl_pins_gpio) { + rinfo->prepare_recovery = i2c_imx_prepare_recovery; + rinfo->unprepare_recovery = i2c_imx_unprepare_recovery; + } + + dev_dbg(&pdev->dev, "using %sscl%s for recovery\n", + i2c_imx->pinctrl ? "pinctrl " : "", rinfo->sda_gpiod ? ",sda" : ""); - rinfo->prepare_recovery = i2c_imx_prepare_recovery; - rinfo->unprepare_recovery = i2c_imx_unprepare_recovery; rinfo->recover_bus = i2c_generic_scl_recovery; i2c_imx->adapter.bus_recovery_info = rinfo;