Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3489803pxp; Tue, 8 Mar 2022 15:47:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJzrPQiPSxX5qnwc9ta3IFBM+sgMm9Vj7laxMDRe3CiK240yevDqGA/hr2DVddo3EZLpl0fJ X-Received: by 2002:a05:6a00:890:b0:4f6:686e:a8a9 with SMTP id q16-20020a056a00089000b004f6686ea8a9mr20500512pfj.83.1646783233100; Tue, 08 Mar 2022 15:47:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646783233; cv=none; d=google.com; s=arc-20160816; b=nbwNVrJn1ur5sAtWizyqj1y7EDcJV8AjOlO93fdDIjZILc4wTaHur9sSSYXoA5B8P4 0fpyomWShZLn6bRx7tYfZN+GoIG4Ta2LsWqEocjxVUEuE4QVChy0qeeC7EhPPTfbv5h+ UxP2Lb1ejG4gyanOe03HEb26rKJgs6J/jsM3hwnnDcS0Ns+8xkm/EnkjDbvOliSpUXf0 zttnuTUV6eX18n5eIQoYjpR+XyKlMY69DrYdRlLF7Nb5kDyKwmRV6RYl0cZyZMAtnKcu 8jk3KUSALUcdYSf4tSh4EVyKKMr5H4cQScb4uXtSKWN2SM37cGxG84FoA9Jdk3yT0UIa Ivpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:dkim-signature:message-id:date:subject:cc:to :from; bh=N0dy6kEUIr+y8NTXo2YidNyYvMmDq2e/8v2xzNF9rqo=; b=GBdVSw0V3TGEEDEwH80q7IJGM5yOQhEvZsxOP7k5HQpZQ+xvmk3RrQ0gvEQ8wLBmWT StcmOKvWWMX7SWA3oIY0pSs6vglZdUmn3lXLYskNmAMoL7cvOrDcJIWdkc5LzMSSMrSC Qo2+s5L4JcMDpsXiNlLVDY8b0PvxG6J4cXSZPPbkRFP6dWMDaIJKefQ8UkxP3SYZl730 uEn9ug6gAFoesTGXMs5e20P007dFjL3SofUMjs512MN9IqftK5ydZjoLmskSfOBvUjDA tX+WcvqWMxKsQYBJWDFB35ORTIdqrLNhAxiSAbYo+w+H7FEiia5zDSlnwvvqftP6OQJ6 8IFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embeddedTS.com header.s=mailanyone20220121 header.b=Kjm18paC; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=embeddedts.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id q2-20020a170902e30200b00151d1f360e2si283513plc.614.2022.03.08.15.47.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 15:47:13 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@embeddedTS.com header.s=mailanyone20220121 header.b=Kjm18paC; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=embeddedts.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DD3A7C2E76; Tue, 8 Mar 2022 15:28:13 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349485AbiCHSUI (ORCPT + 99 others); Tue, 8 Mar 2022 13:20:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239485AbiCHSUH (ORCPT ); Tue, 8 Mar 2022 13:20:07 -0500 Received: from smtp-out3.electric.net (smtp-out3.electric.net [208.70.128.178]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FE033700A; Tue, 8 Mar 2022 10:19:10 -0800 (PST) Received: from 1nReQO-000BTc-Tx by out3b.electric.net with emc1-ok (Exim 4.94.2) (envelope-from ) id 1nReQP-000BWq-Ui; Tue, 08 Mar 2022 10:19:09 -0800 Received: by emcmailer; Tue, 08 Mar 2022 10:19:09 -0800 Received: from [66.210.251.27] (helo=mail.embeddedts.com) by out3b.electric.net with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nReQO-000BTc-Tx; Tue, 08 Mar 2022 10:19:08 -0800 Received: from tsdebian.Massive (unknown [75.164.75.221]) by mail.embeddedts.com (Postfix) with ESMTPSA id 8B65E3ED7C; Tue, 8 Mar 2022 11:19:07 -0700 (MST) From: Kris Bahnsen To: Linus Walleij , Bartosz Golaszewski , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Mark Featherston , Kris Bahnsen Subject: [PATCH v2] gpio: ts4900: Do not set DAT and OE together Date: Tue, 8 Mar 2022 10:18:47 -0800 Message-Id: <20220308181847.3276-1-kris@embeddedTS.com> X-Mailer: git-send-email 2.11.0 X-Outbound-IP: 66.210.251.27 X-Env-From: kris@embeddedTS.com X-Proto: esmtps X-Revdns: wsip-66-210-251-27.ph.ph.cox.net X-HELO: mail.embeddedts.com X-TLS: TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256 X-Authenticated_ID: X-Virus-Status: Scanned by VirusSMART (c) X-Virus-Status: Scanned by VirusSMART (b) X-FM-Delivery-Delay: 15749372,23518412 X-PolicySMART: 13164782, 15749372, 26810492 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=embeddedTS.com; s=mailanyone20220121;h=Message-Id:Date:To:From; bh=N0dy6kEUIr+y8NTXo2YidNyYvMmDq2e/8v2xzNF9rqo=;b=Kjm18paC+Ml+ybk1X5KtljH52gXwoEU9JMML+juB/d6LTPUtNg59zwpVfZ2TOYufwRGYN4Py6lfkDA8NjOcWm+eMp771RjylEYt6DSW38/YGqmy1A6zyLM344PtXtkWxa+J4Y1jc18ELLCDxUF/infUNu36vrxQbpsr3SSxTce8c2E7/pANG5Tt33x7yZmRfUA/MpBIlKiNou2M8yp5MOwhSR0qevlIKSDbkat/Mls4OHHi1KOv63umc2ImeM2ha0UESOZB+DhuxTOiROJ8JVemeR9e8Qb9H4gY0CzpfZioTuqsLqEc2gsfvOj4gOJ0TmTWV3CdSurO0whsD1QVjTQ==; X-FM-Delivery-Delay: 15749372,23518412 X-PolicySMART: 13164782, 15749372, 26810492 X-FM-Delivery-Delay: 15749372,23518412 X-PolicySMART: 13164782, 15749372, 26810492 X-FM-Delivery-Delay: 15749372,23518412 X-PolicySMART: 13164782, 15749372, 26810492 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mark Featherston This works around an issue with the hardware where both OE and DAT are exposed in the same register. If both are updated simultaneously, the harware makes no guarantees that OE or DAT will actually change in any given order and may result in a glitch of a few ns on a GPIO pin when changing direction and value in a single write. Setting direction to input now only affects OE bit. Setting direction to output updates DAT first, then OE. Fixes: 9c6686322d74 ("gpio: add Technologic I2C-FPGA gpio support") Signed-off-by: Mark Featherston Signed-off-by: Kris Bahnsen --- V1 -> V2: Add Fixes tag drivers/gpio/gpio-ts4900.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/drivers/gpio/gpio-ts4900.c b/drivers/gpio/gpio-ts4900.c index d885032cf814..fbabfca030c0 100644 --- a/drivers/gpio/gpio-ts4900.c +++ b/drivers/gpio/gpio-ts4900.c @@ -1,7 +1,8 @@ +// SPDX-License-Identifier: GPL-2.0 /* * Digital I/O driver for Technologic Systems I2C FPGA Core * - * Copyright (C) 2015 Technologic Systems + * Copyright (C) 2015-2018 Technologic Systems * Copyright (C) 2016 Savoir-Faire Linux * * This program is free software; you can redistribute it and/or @@ -55,19 +56,33 @@ static int ts4900_gpio_direction_input(struct gpio_chip *chip, { struct ts4900_gpio_priv *priv = gpiochip_get_data(chip); - /* - * This will clear the output enable bit, the other bits are - * dontcare when this is cleared + /* Only clear the OE bit here, requires a RMW. Prevents potential issue + * with OE and data getting to the physical pin at different times. */ - return regmap_write(priv->regmap, offset, 0); + return regmap_update_bits(priv->regmap, offset, TS4900_GPIO_OE, 0); } static int ts4900_gpio_direction_output(struct gpio_chip *chip, unsigned int offset, int value) { struct ts4900_gpio_priv *priv = gpiochip_get_data(chip); + unsigned int reg; int ret; + /* If changing from an input to an output, we need to first set the + * proper data bit to what is requested and then set OE bit. This + * prevents a glitch that can occur on the IO line + */ + regmap_read(priv->regmap, offset, ®); + if (!(reg & TS4900_GPIO_OE)) { + if (value) + reg = TS4900_GPIO_OUT; + else + reg &= ~TS4900_GPIO_OUT; + + regmap_write(priv->regmap, offset, reg); + } + if (value) ret = regmap_write(priv->regmap, offset, TS4900_GPIO_OE | TS4900_GPIO_OUT); -- 2.11.0