From patchwork Thu Jun 1 20:18:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugo Villeneuve X-Patchwork-Id: 102176 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp591158vqr; Thu, 1 Jun 2023 13:20:36 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4xnWTEjwNo3J29meLN9OrhR3ActTuSEx9QfakMEoDDNk3AZXNJ1oNJze0k8CdCtc56/iVe X-Received: by 2002:a17:902:6506:b0:1b0:4bc7:31ee with SMTP id b6-20020a170902650600b001b04bc731eemr451963plk.32.1685650836152; Thu, 01 Jun 2023 13:20:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685650836; cv=none; d=google.com; s=arc-20160816; b=yYe0RxhfEIKXFu1bqylhf3dNhX+BsqSFFJtwzYZw4bkPoYHCEF3Mo70u8dLPyEodEP 0xpYciIS/IiSJRzoQM9HnUEicIbDxov82rqiY2VylUZz4MwkdwaHkW2n0Ixq+wp7tfA5 x9Ef8P3FF5grvj/cACtkIvr/8YuvxUJ5ZrVVvUKvHnyF5p9RdlqcKhxMCvTwL2FBiduF C6zb/lcOm9AP7CMFcoVCVpXqbSHiJxjtD2BJXtfohgyvNfMLtcF1zb56BXx4XDHRgDVZ aQjWV9oX4BUOMoYG7UneUsmsybypsMtsTCH1ZLMXHvcYUcjXB9/OVyuD/fUiJvR/WO7o ZZtA== 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=ZiPCnMO76qB2BYRsvuFD+LhH0HMktcgnm3k8GmGktA0=; b=L0IUNf5GfZWoFFKHVEHI6u07O6XpZUfTYoAGk8XbSakrXp49gXH3MoHwKoFOmhNFe3 svqYav14ssZBpTnLtpvKZVuv+NikjT7todiEeMH+0/CgsJZDL4auHmCYxuVJt+1DAz/n 3bf7MQO94KBB0lsTbDWPZH8ter8pTUfw0VS10piLVxyTDaaw5Kvrv0fJMKQC1HCB6xCN 6i+T0sV3ZRb3jmCj4d785c32zi7EIDpX+hAJugHLjD+58OySzoBI8ZxZ3fOBcb9wvU4Z I6FLr7gmOyWbwFIf2vYv0ecTyHZ5zWWt19xUEc4VHrOua9eqD6OrSHmJfX3dVpDWETHY V5ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@hugovil.com header.s=x header.b=gaQlY1Tp; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d8-20020a170903230800b001aaf5dcd774si3449468plh.173.2023.06.01.13.20.19; Thu, 01 Jun 2023 13:20:36 -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=gaQlY1Tp; 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 S232336AbjFAUT0 (ORCPT + 99 others); Thu, 1 Jun 2023 16:19:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231883AbjFAUTF (ORCPT ); Thu, 1 Jun 2023 16:19:05 -0400 Received: from mail.hugovil.com (mail.hugovil.com [162.243.120.170]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9270318D; Thu, 1 Jun 2023 13:19:03 -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=ZiPCnMO76qB2BYRsvuFD+LhH0HMktcgnm3k8GmGktA0=; b=gaQlY1Tpf826FLJhqZ0W/h8y3Y Q3pcsBMndgOTqToKTrhhmARqESXglDkRjHZogGUTT8eZAm4krxDGtMJbIhDTwZFrusXXAvICE6aTH VWndAG32nz4jnbEQDg/EZ0XEP+1NR1mDkswdczq99+Cp7LNbbMuY3vAJWKPMH279taXU=; Received: from modemcable168.174-80-70.mc.videotron.ca ([70.80.174.168]:39204 helo=pettiford.lan) by mail.hugovil.com with esmtpa (Exim 4.92) (envelope-from ) id 1q4ol6-000686-8C; Thu, 01 Jun 2023 16:18:56 -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 , stable@vger.kernel.org, Lech Perczak Date: Thu, 1 Jun 2023 16:18:41 -0400 Message-Id: <20230601201844.3739926-7-hugo@hugovil.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230601201844.3739926-1-hugo@hugovil.com> References: <20230601201844.3739926-1-hugo@hugovil.com> MIME-Version: 1.0 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 autolearn=ham autolearn_force=no version=3.4.6 Subject: [PATCH v6 6/9] 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767533011504313700?= X-GMAIL-MSGID: =?utf-8?q?1767533011504313700?= From: Hugo Villeneuve When configuring 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 sc16is7xx_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") Cc: Signed-off-by: Hugo Villeneuve Reviewed-by: Lech Perczak Tested-by: Lech Perczak --- 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 ad6b9d613b33..2fa09baf28e3 100644 --- a/drivers/tty/serial/sc16is7xx.c +++ b/drivers/tty/serial/sc16is7xx.c @@ -1340,9 +1340,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; }