Received: by 2002:a05:7412:8d06:b0:f9:332d:97f1 with SMTP id bj6csp69302rdb; Mon, 18 Dec 2023 09:07:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IGUaGc8n92Fe3L3s8yEtEhbpiB20eZOj01oAkMrhCnLQrZsfN0+KPpmGT/gZoQjC7Od2AQS X-Received: by 2002:a17:902:e842:b0:1d3:d7ca:2a27 with SMTP id t2-20020a170902e84200b001d3d7ca2a27mr201900plg.135.1702919244186; Mon, 18 Dec 2023 09:07:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702919244; cv=none; d=google.com; s=arc-20160816; b=OICtmC0weYtDriwpwBCTuZLc7mLIbmM6cd7UEtMwOzK1mF9ug8dGY0JumsbV5q2Y01 DLHQzYO5TnYQSqQziNgX5Qh+HSN2zi5am3JpOP57W01wKW2E1ssZuETe0gt8aYxtcYu9 dY51jFRCz21lL+/earSVxSX/Wd3+/Vja4dm5Rg6scxUQXWMM4GE+KUHyLCMaUmtt5+wk 6EEfWmaKAFsz7wY4yPtHNXmqfJI7gdmg4R+Af8IVV5ReTb5ImTnOUMDjT4r17UNuXLH/ //fE8hrOQPJ4w4/M3k5WQ3zU4mhbf1nHVZZSYsDerBNkjMOSLfyrecBYT2vJ1GH2VXmt 291A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:message-id:content-transfer-encoding:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:subject:date :from:dkim-signature; bh=S2gUuVNTEJ/Mk6mRDuFWFq7L6gFeHwDmMi/57lMUPvo=; fh=o5Fsor+J6gRsma5hRBsxvngL998gEWy0y1oPNQ5++vk=; b=xHfY6Y1aV4fXtq3/2aRBf2JfsOpDPmrBvvReQiKCvYO2yuzzB8Aibp2UpvtJxEhJfV a+xgZtcT/OZ6UH4iDU6FT3OFes/iFJyK3Wq1zJDx4oDjxpftSrS4dYqGEhLz8rTFlru+ IHfjYAZ0FkAk9nOnzt8NHN6vQGYrMQuHqBqz0XwGWNc+2yt5fS+wdcjJ5ViTRHZz7bEs 0DJH27k5PgLSnw2rn9y7hrUAYUAWxcDi7z92BV7UthJ/qM2c67IleFdMQsIJdRReppBq cMvlJQrDf7Q+43GD3XuzYaBIGFA1kZVY7DufVjfrr2SnAtQRAfwOUQo9FjPoLMW6mY/k laYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tq-group.com header.s=key1 header.b=WSxQJaxt; spf=pass (google.com: domain of linux-kernel+bounces-4126-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4126-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=tq-group.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id c37-20020a630d25000000b005c65fe43747si17694954pgl.279.2023.12.18.09.07.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 09:07:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-4126-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@tq-group.com header.s=key1 header.b=WSxQJaxt; spf=pass (google.com: domain of linux-kernel+bounces-4126-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4126-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=tq-group.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 6A374284E4A for ; Mon, 18 Dec 2023 17:07:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8055F5BFBB; Mon, 18 Dec 2023 17:06:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tq-group.com header.i=@tq-group.com header.b="WSxQJaxt" X-Original-To: linux-kernel@vger.kernel.org Received: from mx1.tq-group.com (mx1.tq-group.com [93.104.207.81]) (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 990CD4FF9F; Mon, 18 Dec 2023 17:06:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ew.tq-group.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ew.tq-group.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tq-group.com; i=@tq-group.com; q=dns/txt; s=key1; t=1702919188; x=1734455188; h=from:date:subject:mime-version:content-transfer-encoding: message-id:to:cc; bh=S2gUuVNTEJ/Mk6mRDuFWFq7L6gFeHwDmMi/57lMUPvo=; b=WSxQJaxtn0F3E44xUeWHhoHg0gwcWWcHU6/kCEzAVN24tR23irbSYMj1 pJ+jqNOx+5TWQqnuTORMzzv6BkUDVLJSIMfu/qYtw+TqrWjppqeNq6vak YfZdmYR6bOJdlI0EmS2qo8dPX9zC40aR7b6puMnxLNVYSKALuJvxKBrgY K3OFY1H1dAaRDYHmFuLAUIN/DajVyrhX7BlRwkY5AZfSisQ42Ix7d4hQs PjyRExhmEkN/uucN7px2Ko0JiQKsrdDIpatrXx0sqvq09v2aC6k1X6jcH QjCJ/5xkUe1pLIM2aFe8A9YuFjaQ9AEXOSLE6UdxcNKjl3zM2LrVlX4eq w==; 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit 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= 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 --- drivers/i2c/busses/i2c-imx.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) 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; --- base-commit: ceb2fe0d438644e1de06b9a6468a1fb8e2199c70 change-id: 20231218-i2c-imx-recovery-6da66f0381df Best regards, -- TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany Amtsgericht München, HRB 105018 Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider https://www.tq-group.com/