From patchwork Sun Oct 4 09:16:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Codrin Ciubotariu X-Patchwork-Id: 11815567 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7ECB1112E for ; Sun, 4 Oct 2020 09:18:49 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 40E70206A1 for ; Sun, 4 Oct 2020 09:18:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="fGMpS3IW"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="SW/of13z" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 40E70206A1 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=microchip.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To: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=IlMwPBbjh6shptUgyGrliWIjS+PxCQT9rLPnRgn0BaE=; b=fGMpS3IWvzlzkQ8YhC7cQzJIEt PKsmBc1ax5mJA5GPaoc1VFjdDIIxLqnFrfa8uKPIJRx0W5YR2Oo2/BpySKSkDn804wiCC+sjfYbx2 Ds8TKiNiTJ3xOTocMn2Ij6E+VXN/qvQIN1bwngiEbVN+ijNDDtPPXXjrs08P7n/++/BuiTAKnytFB uImeE5Us40QiMycF7xlVz07IfD2RK7uu0qbLjF9ttn1qOQcEDXl4keHMTQ44H922V2p4KyzKEWezt maX5yepaqW/6dMM0c0IE9zoSFhTIhxviHYzgTvntdaWzOO/haBjmysfI1m/tMq5le25wmcenLRojE qnskKstw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kP0A6-0002mI-CJ; Sun, 04 Oct 2020 09:18:34 +0000 Received: from esa6.microchip.iphmx.com ([216.71.154.253]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kP0A1-0002lh-GC for linux-arm-kernel@lists.infradead.org; Sun, 04 Oct 2020 09:18:31 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1601803109; x=1633339109; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=mJB4PM3W0XuShCHCsKFfKvn4aRYMv9WtYMDh2EN4KAQ=; b=SW/of13z8s1ZWQwjLMzBFELJVBTBgu605ATl5VydeiPWt3QoiH0lqwUo gNOJ3+rAIqvoAEgfg5iq1Bd7CpJdyiYE4kHN1k9wy32IZ7+9vKDV0FaDJ T/K8WazGln/JjpEkiRWttB8mAeKHWegpK8W55dbZYkn4HyVkQW7klXxTM QT7Wgb9IhHhbtg+PVK2XZ8nD4uLuUQljzH94Z3uCYnhMps0X7Qu6bwC6Q S9d7sjKBtrwNlr73EUKRoqa20hHLpC4C60ri409KwbOoLoLSiU9hmL6Ho nHVF0kq9mOu94YIv72NXr9nEJPou/4csRRkf2KCAaRpW01PCBzUvJYhYo w==; IronPort-SDR: QLQWuDl11RWXHKKAGVpBcDJOOYMq4XVZsRb0kIxvXe5q3AyqeGPjZYYfZHmnC+S/1lDdC/8KcM cSEfw8FLzs+EFYOQTqduCXe8PnOdZoToxb8qyYC313yfIXjNFSC69KoABxX0WRku9UlAJ16PYw rYhs/BIFzOf51iqfC15GgJKm9cB6udGFKXk62CwKwgJML+Yu9NKTbtwIMeVzMPGzYhPq4x2vm6 9gqp/eZQc24hSWcV6ic9eBY5BtUOY6pd/Bnzqljp0C0bFbs6AO7p/Ty4CeAQtqxcieFn8q8UDM VKc= X-IronPort-AV: E=Sophos;i="5.77,335,1596524400"; d="scan'208";a="28646518" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa6.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 04 Oct 2020 02:18:27 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Sun, 4 Oct 2020 02:17:39 -0700 Received: from rob-ult-m19940.amer.actel.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.1979.3 via Frontend Transport; Sun, 4 Oct 2020 02:18:22 -0700 From: Codrin Ciubotariu To: , , Subject: [PATCH v2] i2c: pxa: move to generic GPIO recovery Date: Sun, 4 Oct 2020 12:16:56 +0300 Message-ID: <20201004091656.1004575-1-codrin.ciubotariu@microchip.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201004_051829_736777_67373601 X-CRM114-Status: GOOD ( 16.65 ) X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [216.71.154.253 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [216.71.154.253 listed in wl.mailspike.net] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: wsa@kernel.org, rmk+kernel@armlinux.org.uk, Codrin Ciubotariu , alpawi@amazon.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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. Signed-off-by: Codrin Ciubotariu --- This patch is not tested. Changes in v2: - readded the pinctrl state change to default from the unprepare_recovery callback; drivers/i2c/busses/i2c-pxa.c | 73 +++--------------------------------- 1 file changed, 6 insertions(+), 67 deletions(-) diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c index 35ca2c02c9b9..006cc1d5931f 100644 --- a/drivers/i2c/busses/i2c-pxa.c +++ b/drivers/i2c/busses/i2c-pxa.c @@ -264,9 +264,6 @@ struct pxa_i2c { u32 hs_mask; struct i2c_bus_recovery_info recovery; - struct pinctrl *pinctrl; - struct pinctrl_state *pinctrl_default; - struct pinctrl_state *pinctrl_recovery; }; #define _IBMR(i2c) ((i2c)->reg_ibmr) @@ -1305,8 +1302,6 @@ static void i2c_pxa_prepare_recovery(struct i2c_adapter *adap) */ gpiod_set_value(i2c->recovery.scl_gpiod, ibmr & IBMR_SCLS); gpiod_set_value(i2c->recovery.sda_gpiod, ibmr & IBMR_SDAS); - - WARN_ON(pinctrl_select_state(i2c->pinctrl, i2c->pinctrl_recovery)); } static void i2c_pxa_unprepare_recovery(struct i2c_adapter *adap) @@ -1347,76 +1342,20 @@ static int i2c_pxa_init_recovery(struct pxa_i2c *i2c) if (IS_ENABLED(CONFIG_I2C_PXA_SLAVE)) return 0; - i2c->pinctrl = devm_pinctrl_get(dev); - if (PTR_ERR(i2c->pinctrl) == -ENODEV) - i2c->pinctrl = NULL; - if (IS_ERR(i2c->pinctrl)) - return PTR_ERR(i2c->pinctrl); - - if (!i2c->pinctrl) - return 0; - - i2c->pinctrl_default = pinctrl_lookup_state(i2c->pinctrl, - PINCTRL_STATE_DEFAULT); - i2c->pinctrl_recovery = pinctrl_lookup_state(i2c->pinctrl, "recovery"); - - if (IS_ERR(i2c->pinctrl_default) || IS_ERR(i2c->pinctrl_recovery)) { - dev_info(dev, "missing pinmux recovery information: %ld %ld\n", - PTR_ERR(i2c->pinctrl_default), - PTR_ERR(i2c->pinctrl_recovery)); - return 0; - } - - /* - * Claiming GPIOs can influence the pinmux state, and may glitch the - * I2C bus. Do this carefully. - */ - bri->scl_gpiod = devm_gpiod_get(dev, "scl", GPIOD_OUT_HIGH_OPEN_DRAIN); - if (bri->scl_gpiod == ERR_PTR(-EPROBE_DEFER)) - return -EPROBE_DEFER; - if (IS_ERR(bri->scl_gpiod)) { - dev_info(dev, "missing scl gpio recovery information: %pe\n", - bri->scl_gpiod); - return 0; - } - - /* - * We have SCL. Pull SCL low and wait a bit so that SDA glitches - * have no effect. - */ - gpiod_direction_output(bri->scl_gpiod, 0); - udelay(10); - bri->sda_gpiod = devm_gpiod_get(dev, "sda", GPIOD_OUT_HIGH_OPEN_DRAIN); - - /* Wait a bit in case of a SDA glitch, and then release SCL. */ - udelay(10); - gpiod_direction_output(bri->scl_gpiod, 1); - - if (bri->sda_gpiod == ERR_PTR(-EPROBE_DEFER)) - return -EPROBE_DEFER; - - if (IS_ERR(bri->sda_gpiod)) { - dev_info(dev, "missing sda gpio recovery information: %pe\n", - bri->sda_gpiod); + bri->pinctrl = devm_pinctrl_get(dev); + if (PTR_ERR(bri->pinctrl) == -ENODEV) { + bri->pinctrl = NULL; return 0; } + if (IS_ERR(bri->pinctrl)) + return PTR_ERR(bri->pinctrl); bri->prepare_recovery = i2c_pxa_prepare_recovery; bri->unprepare_recovery = i2c_pxa_unprepare_recovery; - bri->recover_bus = i2c_generic_scl_recovery; i2c->adap.bus_recovery_info = bri; - /* - * Claiming GPIOs can change the pinmux state, which confuses the - * pinctrl since pinctrl's idea of the current setting is unaffected - * by the pinmux change caused by claiming the GPIO. Work around that - * by switching pinctrl to the GPIO state here. We do it this way to - * avoid glitching the I2C bus. - */ - pinctrl_select_state(i2c->pinctrl, i2c->pinctrl_recovery); - - return pinctrl_select_state(i2c->pinctrl, i2c->pinctrl_default); + return 0; } static int i2c_pxa_probe(struct platform_device *dev)