Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp419230rwd; Wed, 24 May 2023 21:17:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6FfNQzXtcV1DqxiYd/fFENRqYr3PaOv8XeaTtgtRRSWSNUWxvTMH1nt6CtZdtL+WOQq+rT X-Received: by 2002:a05:6a00:1513:b0:623:8592:75c4 with SMTP id q19-20020a056a00151300b00623859275c4mr7173548pfu.29.1684988226557; Wed, 24 May 2023 21:17:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684988226; cv=none; d=google.com; s=arc-20160816; b=X1cwaAbIONviuCe71YGP5hvS1um92jSW5CyDY5kQrepVFEuTU7XZsC59CNk0tjFQox pQKSSVmj0ww3IVsybMw1+nc8upvk899ObpqNcXm8rl7SzBgCZTbAB4gCZclG9WQPx02L +Ro6P/Vra5TgFeMxtW7rCXKMQOYgZb99tPfAAu4XaMEQn1Z8vNM6iUdUAhDpESoRmFU6 i7FuQdylog2e5UGAHjC+zRpsPs/G7YmJkbxFdjjYsmlZs2E5tzQAlhSZ8tuJuX+/hwC4 fQs6Ap3Sa8gIbc92JB/45EBH/HpHdO+NEWsHMar7ntS6lbp8aUXBhUO1HdDSjAkbE2Ay z4YQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:cc:to:from:dkim-signature; bh=oAW87YGFqDuCb1wMiNK8HhUC7h6jxZ7gmJadiuchbuo=; b=cZ+1YE6l9mQwVPT2E7AteSzo3vP5Jnm11vUox/w7npL+CD+MLUp/8NRh6Kd3oyRyqk wuH/NBAZLbsn3CBVNN2S/rBt6wpDTmKSoXoGid+JSGxEWbsrzFjLrZRKAlSHXAmg5SkR 3ktPqg1kRJ+HgpiiXqwTGq/hjzE6FtVhFx0H5OZyFfe/PLHb18pSSDskXfPSnqjIgTDl yh9Dxa73/iwsgfC5sAGzsfCV5zBjyWjscWWVMsFcIz5C7AFOO/61GlECp6KOCoBGNKWd UhlXIMLFtjalqg3txVMeacinYMhDgq+SjMonnJicXLlgUAfEoLikt8xyjetHonpZ4Ucv gQTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@hugovil.com header.s=x header.b=vzd6l2eD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r78-20020a632b51000000b0053eeed3d26asi169208pgr.688.2023.05.24.21.16.52; Wed, 24 May 2023 21:17:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@hugovil.com header.s=x header.b=vzd6l2eD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238623AbjEYEG0 (ORCPT + 99 others); Thu, 25 May 2023 00:06:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238125AbjEYEEh (ORCPT ); Thu, 25 May 2023 00:04:37 -0400 Received: from mail.hugovil.com (mail.hugovil.com [162.243.120.170]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB31A1B5; Wed, 24 May 2023 21:04:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hugovil.com ; s=x; h=Subject:Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=oAW87YGFqDuCb1wMiNK8HhUC7h6jxZ7gmJadiuchbuo=; b=vzd6l2eDsrKJ2VXxs4taDBf9O4 Oc6N48Z1YTxaN2yl0G5InFPkYbU2KEuvAVEzFu++jEqX4jQkU+JNyeovO+Xs2OtA/uUn5I86gLMo9 2FguvfKwHawczsuTTkU5ddA7MzzVFzcfhbVrBWCIk9P430oYf6ei8yAT39I0RbcllF5I=; Received: from modemcable168.174-80-70.mc.videotron.ca ([70.80.174.168]:52970 helo=pettiford.lan) by mail.hugovil.com with esmtpa (Exim 4.92) (envelope-from ) id 1q22DE-0001dB-DC; Thu, 25 May 2023 00:04:28 -0400 From: Hugo Villeneuve To: gregkh@linuxfoundation.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, jirislaby@kernel.org, jringle@gridpoint.com, tomasz.mon@camlingroup.com, l.perczak@camlintechnologies.com Cc: linux-serial@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, hugo@hugovil.com, linux-gpio@vger.kernel.org, Hugo Villeneuve Date: Thu, 25 May 2023 00:03:20 -0400 Message-Id: <20230525040324.3773741-7-hugo@hugovil.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230525040324.3773741-1-hugo@hugovil.com> References: <20230525040324.3773741-1-hugo@hugovil.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 70.80.174.168 X-SA-Exim-Mail-From: hugo@hugovil.com X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Subject: [PATCH v3 06/11] serial: sc16is7xx: fix bug when first setting GPIO direction X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on mail.hugovil.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hugo Villeneuve When we want to configure a pin as an output pin with a value of logic 0, we end up as having a value of logic 1 on the output pin. Setting a logic 0 a second time (or more) after that will correctly output a logic 0 on the output pin. By default, all GPIO pins are configured as inputs. When we enter c16is7xx_gpio_direction_output() for the first time, we first set the desired value in IOSTATE, and then we configure the pin as an output. The datasheet states that writing to IOSTATE register will trigger a transfer of the value to the I/O pin configured as output, so if the pin is configured as an input, nothing will be transferred. Therefore, set the direction first in IODIR, and then set the desired value in IOSTATE. This is what is done in NXP application note AN10587. Fixes: dfeae619d781 ("serial: sc16is7xx") Signed-off-by: Hugo Villeneuve --- drivers/tty/serial/sc16is7xx.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/tty/serial/sc16is7xx.c b/drivers/tty/serial/sc16is7xx.c index 8a2fc6f89d36..a5d8af0f6da0 100644 --- a/drivers/tty/serial/sc16is7xx.c +++ b/drivers/tty/serial/sc16is7xx.c @@ -1343,9 +1343,18 @@ static int sc16is7xx_gpio_direction_output(struct gpio_chip *chip, state |= BIT(offset); else state &= ~BIT(offset); - sc16is7xx_port_write(port, SC16IS7XX_IOSTATE_REG, state); + + /* + * If we write IOSTATE first, and then IODIR, the output value is not + * transferred to the corresponding I/O pin. + * The datasheet states that each register bit will be transferred to + * the corresponding I/O pin programmed as output when writing to + * IOSTATE. Therefore, configure direction first with IODIR, and then + * set value after with IOSTATE. + */ sc16is7xx_port_update(port, SC16IS7XX_IODIR_REG, BIT(offset), BIT(offset)); + sc16is7xx_port_write(port, SC16IS7XX_IOSTATE_REG, state); return 0; } -- 2.30.2