Received: by 2002:a05:7412:8598:b0:f9:33c2:5753 with SMTP id n24csp391567rdh; Tue, 19 Dec 2023 01:59:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IGCcE0OA2KdTx3NowPRMwbENy2WB85KCwi1lq8X02Q11UVLk9QhKO0KTie9Kq89IL20DCM7 X-Received: by 2002:a05:6512:4023:b0:50e:2494:d315 with SMTP id br35-20020a056512402300b0050e2494d315mr3562765lfb.126.1702979951681; Tue, 19 Dec 2023 01:59:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702979951; cv=none; d=google.com; s=arc-20160816; b=Y9L7jSHeIaBvcMhjJYd98MUHTvFqT0UvZG6xvY8bmrlC21El5PNdsgAd0azvYDH4Ku YS7zJaTPvHpvj7a3DgtBzvqjv/N4pkVyeel9mZdsedMzp89UiUkIgKDc7SFA1Ca3wev1 GSqyUA/kRkyxd97UEVRMvU8ZqkQ9YWIA4J3y0kzZxbIvatsWhLzMI0yhZYWtkORUV0N2 eIXnCZOi5yCcDodM6Kjk7+rp9KPiHflNvzY2noSg+BTOr7ZxIf/Ssu6Bdi6ss1qD8LyZ PRA6O4aIRjy36AEJbNaiHGjcFGY3axu6y/9RGp7b8xmAY4Jp/lsKUrFh10T1T9T6xCX7 QIFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=ICkzegM7gZOvkNqsWhAjmgW9haK24Yiw2UCFyLlQ4ck=; fh=NjzuQFPgwca8xZW/hcolqNDoBSToMIHj/s2sG9jfLBo=; b=O1V4LWJ98BPhme5Zi+6PzYGCOjDdEA/akrWAHqoSl9TD5nYwTeCUuynb9uXfIZiwHE Gd8jcqDBXpxFwDngplQXrt62ga9QqTK1TVsgMXL0lB6gp0kTFgo5Vt78GDghjo2U8Qea 2LkSLhWw21wIKuEtP+z7zb5xwtagcV4u7jP50gsYJwgggUrw6XpSys5eokpVhsIc84/9 Xq09i2oT2Eum7a0oNeepQmgGKZS9uEFgBkhvzPm10CsSY20Fa2XAJga08bXgw2mUtDrE q9b7fcTpoR4a8KqKLplUUBY7VafiQhXjZufchjOHR6RE9L6ru07eaqHMrAGbXvQKE93L U5Ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tq-group.com header.s=key1 header.b=AGZkkQLN; spf=pass (google.com: domain of linux-kernel+bounces-4991-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4991-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 am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id m9-20020a056402510900b0054cb9717a33si10728047edd.205.2023.12.19.01.59.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 01:59:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-4991-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@tq-group.com header.s=key1 header.b=AGZkkQLN; spf=pass (google.com: domain of linux-kernel+bounces-4991-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4991-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 427971F24D62 for ; Tue, 19 Dec 2023 09:59:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AD04E14265; Tue, 19 Dec 2023 09:59:00 +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="AGZkkQLN" 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 1E14F1426D; Tue, 19 Dec 2023 09:58:55 +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=1702979936; x=1734515936; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=ICkzegM7gZOvkNqsWhAjmgW9haK24Yiw2UCFyLlQ4ck=; b=AGZkkQLNpCPEbsEuWJX078qOEHqdbsvbuobJBmeIef2SetgU7oPq03tg DuWyGNmZpeM4rimR0mvSfpjp/iEZ+M17jDkMtFyEzR9JxkLdbQpviclO7 idIg7aHCvvajZJEwOYBm8W5GRnhYMxLylTGhSkghBq8pGdH7Hs3khcGMJ 8ZehVJx/hmE87kXM6uetlzF1V5Dk9X25Imp7DPbhdMGYJZmQB5vRAN0hR r2yHtQqEO48g3Jj+qG3ONtdfQuF3qYNJNBI5Gt3zVJTU1cfre51CXHwQI Cki7nV8M6AJ6OkCaG4BEXLAYVSKzKwyzmaHgVadiyLv8v6S67pezp2B0a g==; X-IronPort-AV: E=Sophos;i="6.04,287,1695679200"; d="scan'208";a="34582001" Received: from vtuxmail01.tq-net.de ([10.115.0.20]) by mx1.tq-group.com with ESMTP; 19 Dec 2023 10:58:48 +0100 Received: from herburgerg-w2 (herburgerg-w2.tq-net.de [10.122.52.145]) by vtuxmail01.tq-net.de (Postfix) with ESMTPA id 483E3280075; Tue, 19 Dec 2023 10:58:48 +0100 (CET) Date: Tue, 19 Dec 2023 10:58:42 +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" Subject: Re: Re: [PATCH] i2c: i2c-imx: allow bus recovery on non-muxable pads 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=us-ascii Content-Disposition: inline In-Reply-To: <87frzyprhq.fsf@geanix.com> Hi Esben, On Tue, Dec 19, 2023 at 07:43:21AM +0000, esben@geanix.com wrote: > Gregor Herburger writes: > > > 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. > > 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? I was not aware of the generic GPIO recovery functions. At a first glance I think your solution should work. I will give it a try and test it on hardware. > > 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; > } > - 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; > } > -- > 2.43.0 > > > /Esben >