From mboxrd@z Thu Jan 1 00:00:00 1970 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 7C318C41535 for ; Tue, 19 Dec 2023 09:59:23 +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:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=fLGA1PRRXcydjbHeJBKiHn3C3U4RkILbPypBr+FYMEg=; b=L2tG/WsLXp3H9f e9ZnmupF5CZon/ckIZGCtAEFrqYchHwG78w7fka6rZNG2NAnI98lmeJeNqMmjRP1aHVyNPqP0ozgK biWS06fdXP8MQ0jWM6j4sO9t+j1vf4KPfkRpHGliFJ+lUp3NnvDi+V6jo7H3EaUHu3JVaZMjwX2V1 wZWtbUtkkurfwFp0FFEgdpEMzOf2ZJ3wNMUu2lAXd45dyil8tpoYfIO4ZCVRTPgdWanjS/AjQGp5T qhWqQweNSs8XX/eW/uLB714R6Ag23q+/SGxxsSItqprfOc+NtJWgGKJWgF/E6H0KWutxyEOwfUIV0 dTf0ocplTFgB+nuWVkxg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rFWsI-00DWJC-0F; Tue, 19 Dec 2023 09:58:54 +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 1rFWsE-00DWIN-1d for linux-arm-kernel@lists.infradead.org; Tue, 19 Dec 2023 09:58:52 +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=1702979930; x=1734515930; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=ICkzegM7gZOvkNqsWhAjmgW9haK24Yiw2UCFyLlQ4ck=; b=c6I1u6CXbkRLc22i7OLiLcRxF8Vff+vClbR/cxBIJYCebsRclup1qM9I 0ETsRW1Cl7RDTSGO5pGVq2xNHMLhvZokVP1CySjjV7F+FNl0IUtKbdalL phfG0h5lcRYF+MAMAv4s0WbiQBd2rBobrx46GiE/Rlsa9xwwAlmpOCIpL uLYFPxOoD6BMSph2rV2a54oqRa6RLe+1VduDqM8zNOJlebaIHJsMGzffS 0pbZepuR5buYhYhHzHOUhoXLVnMRFpzMavfULK1jE1x3kvUVeF/LmralY V08wXtzFH1d5smIU4fIw2t6SGpvDCY8yObqXgsUYivzoaelhbk+MC2h36 w==; 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> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <87frzyprhq.fsf@geanix.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231219_015850_926036_144EDE3C X-CRM114-Status: GOOD ( 30.97 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel