From patchwork Thu May 25 04:03:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugo Villeneuve X-Patchwork-Id: 98771 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp101866vqr; Wed, 24 May 2023 21:18:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ61925y+V4NE1mANbuALrwnkOZcEzR1B6F7swExmy0xjms+4Z66fmdC+PJkmIItjVX5gnb9 X-Received: by 2002:a17:903:48e:b0:1ae:4248:c7f with SMTP id jj14-20020a170903048e00b001ae42480c7fmr245084plb.48.1684988334439; Wed, 24 May 2023 21:18:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684988334; cv=none; d=google.com; s=arc-20160816; b=fhBcMDaayqvWOaGw+mbTuY/MVMFNAQrqteyjmqi4/Q4aDbohY0UoBE3hwFd1xHnxUk qaWEQRe/vGZ8V8uZWIrMKc27TO/v8kmPWNnHBGcfsfpWn1fQyl9WvctzmP+XK32GO8/K 81DW2dTc5UQdFeKjJfLK8Q+1o2KC/20NiIdDAf8aP+FvCY/gLMLgS80eylXWEGCuK7ot uHk4lC/n9AvhO/o9vibrW70XpxfGdWnh8n1AiMJgIdDBy6Ghkc/y5gQ8WMZPcCVx3CZx ASqrwvPvfi0Zu2iCRvJCSbMIwm9iGMAMqtgF1QicFg+dQ3ThqGL+fzvazp089aKekQuY Nf0Q== 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=wtCZaz+ygLc5odu0jyJWVuukps/nAVPXx7PU+/vrFgM=; b=Yft1I8ab9EaaI7iGAOVRuNyENbgGJ+2rDb3Z1uXGfMpAp7CMkg9EslXw2RB32mv5Hn zrLrA4e7QWdIgaROZ4cYKVtpEVppbFJu2saNLpBas10HNwUPVkwgTOWDXRIYSyDVipea s69CC2ZTd5j4LpnvGnMrVHqg4i+uYYql30T5Pj4prihg00nyNV47Ayy8PYFuBu5/Xj/N DBsvLXjuILjDCad1CXWCijSb7MzpkfCJpiQHStxzSZ2U6kTt0GlPNINAgJ7fIIN48kRv rXut4jldZUQf4K3DSWXCA4E0wT7zHIGUR0ImVz/a1SQ9wDO5cdEAfBlq4oQawmaxtUzs ztpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@hugovil.com header.s=x header.b=Qbt1LRs+; 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 r3-20020a1709028bc300b001a92f0f46fbsi497854plo.436.2023.05.24.21.18.40; Wed, 24 May 2023 21:18:54 -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=Qbt1LRs+; 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 S238271AbjEYEGz (ORCPT + 99 others); Thu, 25 May 2023 00:06:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238226AbjEYEE7 (ORCPT ); Thu, 25 May 2023 00:04:59 -0400 Received: from mail.hugovil.com (mail.hugovil.com [162.243.120.170]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CE62E65; Wed, 24 May 2023 21:04:41 -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=wtCZaz+ygLc5odu0jyJWVuukps/nAVPXx7PU+/vrFgM=; b=Qbt1LRs+4mv0pRnwxJYbf2ZAB6 2UDi3v8PyYf2TGyY8fXk0bcNmATMeSPqqpDWOeKnKRrd+gunR7FhgZ3OSqpe259puDiO1CUxPvgqJ N6+lJEE6ZXipwALuWFPgoMyCXTVOarP2sSNIay4QSLpWLlQzzciypsfiUEOAl8BOyoUE=; 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 1q22DM-0001dB-39; Thu, 25 May 2023 00:04:36 -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:25 -0400 Message-Id: <20230525040324.3773741-12-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 11/11] serial: sc16is7xx: add dump registers function 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?1766838327670044184?= X-GMAIL-MSGID: =?utf-8?q?1766838327670044184?= From: Hugo Villeneuve With this driver, it is very hard to debug the registers using the /sys/kernel/debug/regmap interface. The main reason is that bits 0 and 1 of the register address correspond to the channels bits, so the register address itself starts at bit 2, so we must 'mentally' shift each register address by 2 bits to get its offset. Also, only channels 0 and 1 are supported, so combinations of bits 0 and 1 being 10b and 11b are invalid, and the display of these registers is useless. For example: cat /sys/kernel/debug/regmap/spi0.0/registers 04: 10 -> Port 0, register offset 1 05: 10 -> Port 1, register offset 1 06: 00 -> Port 2, register offset 1 -> invalid 07: 00 -> port 3, register offset 1 -> invalid ... Add a debug module parameter to call a custom dump function for each port registers after the probe phase to help debug. Signed-off-by: Hugo Villeneuve --- drivers/tty/serial/sc16is7xx.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/drivers/tty/serial/sc16is7xx.c b/drivers/tty/serial/sc16is7xx.c index 03d00b144304..693b6cc371f8 100644 --- a/drivers/tty/serial/sc16is7xx.c +++ b/drivers/tty/serial/sc16is7xx.c @@ -347,6 +347,10 @@ struct sc16is7xx_port { struct sc16is7xx_one p[]; }; +static bool debug; +module_param(debug, bool, 0644); +MODULE_PARM_DESC(debug, "enable/disable debug messages"); + static unsigned long sc16is7xx_lines; static struct uart_driver sc16is7xx_uart = { @@ -387,6 +391,28 @@ static void sc16is7xx_port_write(struct uart_port *port, u8 reg, u8 val) regmap_write(s->regmap, (reg << SC16IS7XX_REG_SHIFT) | line, val); } +static int sc16is7xx_port_dump(struct uart_port *port) +{ + int i; + unsigned char *buf; + char name[64]; + const int regs_count_per_port = 16; + + buf = devm_kzalloc(port->dev, regs_count_per_port, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + for (i = 0; i < regs_count_per_port; i++) + buf[i] = sc16is7xx_port_read(port, i); + + snprintf(name, sizeof(name), "sc16is7xx %s%i: dump ", + sc16is7xx_uart.dev_name, port->line); + print_hex_dump(KERN_ERR, name, DUMP_PREFIX_OFFSET, 16, 1, + &((u8 *)buf)[0], regs_count_per_port, 1); + + return 0; +} + static void sc16is7xx_fifo_read(struct uart_port *port, unsigned int rxlen) { struct sc16is7xx_port *s = dev_get_drvdata(port->dev); @@ -1614,6 +1640,10 @@ static int sc16is7xx_probe(struct device *dev, } #endif + if (debug) + for (i = 0; i < devtype->nr_uart; ++i) + sc16is7xx_port_dump(&s->p[i].port); + /* * Setup interrupt. We first try to acquire the IRQ line as level IRQ. * If that succeeds, we can allow sharing the interrupt as well.