Received: by 2002:a05:7412:d002:b0:f9:9049:d2ea with SMTP id bd2csp18551rdb; Wed, 20 Dec 2023 02:39:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IEzEyER0DEIbUATRN9GOr1egJNyQ9SFwpXnMWTb0B8oIvuOLMtJSpdWFVftlgQOtrl0XiyH X-Received: by 2002:a05:6870:2212:b0:203:6406:8524 with SMTP id i18-20020a056870221200b0020364068524mr8527347oaf.73.1703068770073; Wed, 20 Dec 2023 02:39:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703068770; cv=none; d=google.com; s=arc-20160816; b=WrXlrSNFJavM+v88mlzMle2+d9taqgqd9A+gCQR9yF/k3uaug2scx9xv5uwZZns/aA Sfqel+ib+g/3rXjEWl6yqiDy2KF7pFh2PbgPFx+LIOLe1YNSXl5Wqh2N7uZbmxhW36tH ggTGUkPlaHby7U6wOpfa3HCRdyX4YFZYGJwWv5AQTUSr6jLt0+tTLbR8EZgvVjqrlXb+ 2nzIhXPwK18IOTYcboYE0R1X2P9wlC3lJ5Wu3K/L7oETuW0X1lH+HQUFEfr9T6nZBZbP EcqfWobw2LZ0GiicC5siXTDYJpkfCa58mGoK5I3Acv4bqo98/YfnvORS5298A3tAbbwK qFXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:cc:to:from:date:subject:dkim-signature; bh=g+TPrc8PqsX2A6MOEoxOpOrmmDnEXK+JiSxFz/fzK0M=; fh=NjzuQFPgwca8xZW/hcolqNDoBSToMIHj/s2sG9jfLBo=; b=MLu2U+Q7zo+fksqCLN1UdVpiQnNff/Bn3JBpcWH7N7x1vZfHaKQO7jZcyd8mzBpLX0 h07mYA13t11lE8bnBJCJ+zsKuugkRFNW2D6CRcnuEjArwHJdMlmb4mK1YbPIQrwQHrlu FgheV27F+nr5XAV8JD05bYhhYAT9OEgq31NrfLcJwnXq02qK/6dx8u7dCfmM5M9jAkOT 3PdNwT7lp2//D8tMjw9hou8HP1cHtlCsTpUNO0kNLVxdn6+lqq/cbYne1Q1RG9Civfkh zWGv0xWpWQ7SO+RbMR6EZhgOBFwYD4XEgmjMV3fiJib9XD00+Hj8hO8x2UcrD7mHe1sT Y+kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tq-group.com header.s=key1 header.b=qorYyphY; spf=pass (google.com: domain of linux-kernel+bounces-6753-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6753-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 t3-20020aa79383000000b006d9330a9288si2829484pfe.267.2023.12.20.02.39.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 02:39:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-6753-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=qorYyphY; spf=pass (google.com: domain of linux-kernel+bounces-6753-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6753-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 D9CA32831BF for ; Wed, 20 Dec 2023 10:39:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8B257225D3; Wed, 20 Dec 2023 10:37:40 +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="qorYyphY" 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 32FB222303; Wed, 20 Dec 2023 10:37:34 +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=1703068655; x=1734604655; h=date:from:to:cc:message-id:references:mime-version: content-transfer-encoding:in-reply-to:subject; bh=g+TPrc8PqsX2A6MOEoxOpOrmmDnEXK+JiSxFz/fzK0M=; b=qorYyphYsqiyjby+z2kKSOdcHxhL1v8lJdL/OdREpAf2RpxfX8mPAc3f J6zJLY25w1G8vv0SDmv2PbC+jfWv8rCjZMGp1EOMhA/6b3awg+9hvzyqS W+EHSAlYG4AC8UOKtESewiJic6dQ3XpSbsTA9gRo47Ht8qN+yT+h7ycAt I23oFoLSag1Ad04B3Q3m8CxMnGsS8LAP0WDIZJeYHZKQpmLz2MvfG6Drf 2+QLcXaOuvKnEi5YbL7ZpfgG1TmvPLGlJtX212LCORW0z2+U6kYhIHARz YCD7/WcSIduDlIJZve8NKV8qcEuqruMbhI2u4JODVa7uU4TMvZjHQjpD9 w==; X-IronPort-AV: E=Sophos;i="6.04,291,1695679200"; d="scan'208";a="34607338" Subject: Re: Re: [PATCH] i2c: i2c-imx: allow bus recovery on non-muxable pads Received: from vtuxmail01.tq-net.de ([10.115.0.20]) by mx1.tq-group.com with ESMTP; 20 Dec 2023 11:37:27 +0100 Received: from herburgerg-w2 (herburgerg-w2.tq-net.de [10.122.52.145]) by vtuxmail01.tq-net.de (Postfix) with ESMTPA id D2DF5280075; Wed, 20 Dec 2023 11:37:26 +0100 (CET) Date: Wed, 20 Dec 2023 11:37:21 +0100 From: Gregor Herburger To: esben@geanix.com Cc: Oleksij Rempel , Pengutronix Kernel Team , Andi Shyti , Shawn Guo , Sascha Hauer , Fabio Estevam , NXP Linux Team , "linux-i2c@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" , "linux@ew.tq-group.com" Message-ID: References: <20231218-i2c-imx-recovery-v1-1-f69fa85b228c@ew.tq-group.com> <87frzyprhq.fsf@geanix.com> 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-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <87frzyprhq.fsf@geanix.com> Hi Esben, I had another look at your patch and tested it on a LX2160a SoC without pinctrl. I agree that using the generic GPIO recovery you suggested is the better solution. To make your solution work I had to make a small change (see below). On Tue, Dec 19, 2023 at 07:43:21AM +0000, esben@geanix.com wrote: > Why not move to use the generic GPIO recovery instead? Will something > like this be able to cover at least the same scenarios as your change? > > From 7e432496bae8c7ac35c21504bc1cd03f1dfef97f Mon Sep 17 00:00:00 2001 > Message-ID: <7e432496bae8c7ac35c21504bc1cd03f1dfef97f.1702971634.git.esben@geanix.com> > From: Esben Haabendal > Date: Tue, 25 May 2021 11:25:44 +0200 > Subject: [PATCH] i2c: imx: move to generic GPIO recovery > > Starting with > commit 75820314de26 ("i2c: core: add generic I2C GPIO recovery") > GPIO bus recovery is supported by the I2C core, so we can remove the > driver implementation and use that one instead. > > As a nice side-effect, pinctrl becomes optional, allowing bus recovery on > LS1021A, which does not have such luxury, but can be wired up to use extra > fixed GPIO pins. > > Signed-off-by: Esben Haabendal > --- > drivers/i2c/busses/i2c-imx.c | 62 ++++-------------------------------- > 1 file changed, 7 insertions(+), 55 deletions(-) > > diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c > index 1775a79aeba2..824d8bbb9be5 100644 > --- a/drivers/i2c/busses/i2c-imx.c > +++ b/drivers/i2c/busses/i2c-imx.c > @@ -212,10 +212,6 @@ struct imx_i2c_struct { > const struct imx_i2c_hwdata *hwdata; > struct i2c_bus_recovery_info rinfo; > > - struct pinctrl *pinctrl; > - struct pinctrl_state *pinctrl_pins_default; > - struct pinctrl_state *pinctrl_pins_gpio; > - > struct imx_i2c_dma *dma; > struct i2c_client *slave; > enum i2c_slave_event last_slave_event; > @@ -1357,24 +1353,6 @@ static int i2c_imx_xfer_atomic(struct i2c_adapter *adapter, > return result; > } > > -static void i2c_imx_prepare_recovery(struct i2c_adapter *adap) > -{ > - struct imx_i2c_struct *i2c_imx; > - > - i2c_imx = container_of(adap, struct imx_i2c_struct, adapter); > - > - pinctrl_select_state(i2c_imx->pinctrl, i2c_imx->pinctrl_pins_gpio); > -} > - > -static void i2c_imx_unprepare_recovery(struct i2c_adapter *adap) > -{ > - struct imx_i2c_struct *i2c_imx; > - > - i2c_imx = container_of(adap, struct imx_i2c_struct, adapter); > - > - pinctrl_select_state(i2c_imx->pinctrl, i2c_imx->pinctrl_pins_default); > -} > - > /* > * We switch SCL and SDA to their GPIO function and do some bitbanging > * for bus recovery. These alternative pinmux settings can be > @@ -1385,43 +1363,17 @@ static void i2c_imx_unprepare_recovery(struct i2c_adapter *adap) > static int i2c_imx_init_recovery_info(struct imx_i2c_struct *i2c_imx, > struct platform_device *pdev) > { > - struct i2c_bus_recovery_info *rinfo = &i2c_imx->rinfo; > + struct i2c_bus_recovery_info *bri = &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"); > + bri->pinctrl = devm_pinctrl_get(&pdev->dev); > + if (PTR_ERR(bri->pinctrl) == -ENODEV) { > + bri->pinctrl = NULL; > return 0; Should not return here to allow setting of adapter.bus_recovery_info later. > } > - 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_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); > - rinfo->scl_gpiod = devm_gpiod_get(&pdev->dev, "scl", GPIOD_OUT_HIGH_OPEN_DRAIN); > - > - if (PTR_ERR(rinfo->sda_gpiod) == -EPROBE_DEFER || > - PTR_ERR(rinfo->scl_gpiod) == -EPROBE_DEFER) { > - return -EPROBE_DEFER; > - } else if (IS_ERR(rinfo->sda_gpiod) || > - IS_ERR(rinfo->scl_gpiod) || > - IS_ERR(i2c_imx->pinctrl_pins_default) || > - IS_ERR(i2c_imx->pinctrl_pins_gpio)) { > - dev_dbg(&pdev->dev, "recovery information incomplete\n"); > - return 0; > - } > - > - dev_dbg(&pdev->dev, "using scl%s for recovery\n", > - rinfo->sda_gpiod ? ",sda" : ""); > + if (IS_ERR(bri->pinctrl)) > + return PTR_ERR(bri->pinctrl); > > - 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; > + i2c_imx->adapter.bus_recovery_info = bri; > > return 0; > } Best regards, Gregor -- 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/