From patchwork Thu May 25 04:03:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Hugo Villeneuve X-Patchwork-Id: 98763 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp97428vqr; Wed, 24 May 2023 21:07:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4vcMzevLOFAZDq89aeftdhRPR6b8MCtyDzBkccAH5hiH0ei9fik5Lb6laSAnY6ri9eDGlx X-Received: by 2002:a05:6a20:840a:b0:10b:5347:304 with SMTP id c10-20020a056a20840a00b0010b53470304mr14197185pzd.7.1684987626306; Wed, 24 May 2023 21:07:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684987626; cv=none; d=google.com; s=arc-20160816; b=ZOr2RRCa21/ck0+ORwaQVMVE13ZGacJ+edc0hbKCsuEk2LzpplLOy+OGuGbiz+OGIp X90WMnE0dC68vHJeUXkBf3Qkw4WFewAXsa0iC1CpGFHC4gIxu9Ok+9ozbVKc/006SGEv LTR1Oa52wJ4EXjO3e6sP8DeANb5HJWkfwrF5XzlPSORKTe89NS1ZSGSZmK5v0rmk86X6 muxTj0B9hk0Jrsw+n8OIWR0mEuntt4P+n1N473jx4uNT5T94HxKKYXkvnuyoukugoINq dtVDtiMyANvQEM1NMyOGVon6AXKcKkUNkKA8n9kdM5AXf4A/A8vAKE9vAN+ngOdfIihB Zdzg== 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=4SFt1oa/H6OPqzJ3VF1wAZJc4jROpd4jbbyOx0NJPsU=; b=qq/qJUvaY368MZVBGo1fgxZeMdUC/dwNJ3hbkuCCHcdIIo6eAq8C/OfUqdzHDhcNxk 7/wYxuUH4dOlSJ60gH5TCo0cgTknsXYgNBRnNfheRiCgS8t+0YUjcUvLADxKTPYcGNzo Y3r0JBFxuXuDZqLAwSXYX2l0ma0TKdq8hyYb2AEuioJkgSeotpQW0yb9guzliqzZvmZ3 +OTrSmWzuviSBbAS/G2SrRDZjUV4dtZ0zvgfoLxD/zroguMjhwsG3ShkpGP/JcHjfQwd Q8Q+sPua7EUeAosZaAIRkmtcuw+LuxeGHx2PocugCb/ISiAkQjIX9Q/+bsILkfEV1rmU NGzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@hugovil.com header.s=x header.b=L46caBB8; 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 nu15-20020a17090b1b0f00b00255bc974374si621904pjb.167.2023.05.24.21.06.50; Wed, 24 May 2023 21:07: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=L46caBB8; 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 S238760AbjEYEGW (ORCPT + 99 others); Thu, 25 May 2023 00:06:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238405AbjEYEEg (ORCPT ); Thu, 25 May 2023 00:04:36 -0400 Received: from mail.hugovil.com (mail.hugovil.com [162.243.120.170]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FCB8189; Wed, 24 May 2023 21:04:32 -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=4SFt1oa/H6OPqzJ3VF1wAZJc4jROpd4jbbyOx0NJPsU=; b=L46caBB85Fgkyuiy0LBjfk5OgM 5bgAmFCFhK7Ls5zDU10Iz0J6kzotyu61oy0ueYTsID13mgBwatF+TTVAwpws8dX5IZMXyD0s5cGBr ZFZDYwFmAVhCUR4YmWJGpvB2YoCqSO/CsLjGMW67pQzxGdQWftcTJYXUjCxCnm8IaaVI=; 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 1q22DB-0001dB-VP; Thu, 25 May 2023 00:04:26 -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:19 -0400 Message-Id: <20230525040324.3773741-6-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 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 05/11] serial: sc16is7xx: fix broken port 0 uart init 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?1766837585417952549?= X-GMAIL-MSGID: =?utf-8?q?1766837585417952549?= From: Hugo Villeneuve While experimenting with rs485 configuration on a SC16IS752 dual UART, I found that the sc16is7xx_config_rs485() function was called only for the second port (index 1, channel B), causing initialization problems for the first port. For the sc16is7xx driver, port->membase and port->mapbase are not set, and their default values are 0. And we set port->iobase to the device index. This means that when the first device is registered using the uart_add_one_port() function, the following values will be in the port structure: port->membase = 0 port->mapbase = 0 port->iobase = 0 Therefore, the function uart_configure_port() in serial_core.c will exit early because of the following check: /* * If there isn't a port here, don't do anything further. */ if (!port->iobase && !port->mapbase && !port->membase) return; Typically, I2C and SPI drivers do not set port->membase and port->mapbase. But I found that the max310x driver sets port->membase to ~0 (all ones). By implementing the same change in our driver, uart_configure_port() is now correctly executed. Fixes: dfeae619d781 ("serial: sc16is7xx") Signed-off-by: Hugo Villeneuve Reviewed-by: Ilpo Järvinen --- I am not sure if this change is the best long-term solution to this problem, and maybe uart_configure_port() itself could be modified to take into account the fact that some devices have all three *base values set to zero? Also, many drivers use port->iobase as an index, is it the correct way to use it? For example, for our driver, there was commit 5da6b1c079e6 ("sc16is7xx: Set iobase to device index") with the following explanation: "Set the .iobase value to the relative index within the device to allow infering the order through sysfs." drivers/tty/serial/sc16is7xx.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/tty/serial/sc16is7xx.c b/drivers/tty/serial/sc16is7xx.c index af7e66db54b4..8a2fc6f89d36 100644 --- a/drivers/tty/serial/sc16is7xx.c +++ b/drivers/tty/serial/sc16is7xx.c @@ -1443,6 +1443,7 @@ static int sc16is7xx_probe(struct device *dev, s->p[i].port.fifosize = SC16IS7XX_FIFO_SIZE; s->p[i].port.flags = UPF_FIXED_TYPE | UPF_LOW_LATENCY; s->p[i].port.iobase = i; + s->p[i].port.membase = (void __iomem *)~0; s->p[i].port.iotype = UPIO_PORT; s->p[i].port.uartclk = freq; s->p[i].port.rs485_config = sc16is7xx_config_rs485;