Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp7887480pxb; Fri, 19 Feb 2021 01:46:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJxGmR69avDohUJnhLjurtzpyAd1B2Q8bzgtdc7vlJjY3SnX/11Rl/xrpKKCBiLYQzCN2AaS X-Received: by 2002:a17:906:5e59:: with SMTP id b25mr4398324eju.74.1613727960330; Fri, 19 Feb 2021 01:46:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613727960; cv=none; d=google.com; s=arc-20160816; b=V7efczVl21P+OhOHWqfyZflDCmdOwR07bwDqUL/cIeFke5sPChAWdaGFWT2CNrn+8w 1HJ6TVoiidUbld38YDV1wqcOPV9wza2la3VUCJUmjoIpL8Mo58629WcvvVNT41BpMH1h v9XiRK5xoJh8KWw4Voa3w9O3qpL3qsZRnticNSQDZLgQL9PYQKoTcTcjeNYMEArL3C02 CfjgG4Cx7ve0svwxt3q4GcNPz8wv7+yQsa9qL1cSovaOYrAXhyy/TuJDdPFahbkKU6xt DKM2hJ/1Puw9ADItQIaPJUoIOMmWZ5QJ2OCyKshz4OWWzkZ4vBuRmhPiO5b+aD3pNfyp oI3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=NuBGqICC+95wAYpH1uDMaRfEyp5FKDDvT+kNTfJaJ7Q=; b=r8ez30vVDJfYiOz9Mx5csifoxCQxkP08zEN25mq7qwFXpmOFmF6/k+c3L1FfzMXgnu JYYpyGmIadKE/zgtZEb+6v7akdosml7hEofamHmLsaZEhWFkqJpEMYqI4IU6o1qZlTW8 W2zJP1muwaNHwRsXCnh5vUJeRJIts8k5uadvEr4oJ2dwkNKZky6GSS/X9FD3c6oUDuRC ++EmhkLzmuFMAuclpYOUJuK7GlGo8A+8Q635qHVG0IJi0vClfcsbaPzvLrBav+ucLMA8 uYxTa2QAG+pmxseIfwia2b06kCFIp4JYe3fFDvAMlbCwZ6qP15wwPwEtSOB7zze4mA2v NSpg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s14si5712033edr.75.2021.02.19.01.45.36; Fri, 19 Feb 2021 01:46:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230106AbhBSJoM (ORCPT + 99 others); Fri, 19 Feb 2021 04:44:12 -0500 Received: from mail-ed1-f46.google.com ([209.85.208.46]:45463 "EHLO mail-ed1-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229726AbhBSJoH (ORCPT ); Fri, 19 Feb 2021 04:44:07 -0500 Received: by mail-ed1-f46.google.com with SMTP id p2so8623115edm.12; Fri, 19 Feb 2021 01:43:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=NuBGqICC+95wAYpH1uDMaRfEyp5FKDDvT+kNTfJaJ7Q=; b=keVzVcVlWw43UX9iy9CKMUSXLQ/1BNT5uvVB8ucgQRSQzcMeBSBInD5zw06OyDXdQO TJAVmpFM8Vgg/+MjAJNwdMUqRtow2kOOV39Z0gk7C+h6+Px4qoTziGxo51g/3CD1j7+V iLVEbR/rsUPVPTMydvN5QQ6QKt8AmA814u9Dx95gI2bxmqwe2wO1rijtHpK54CgEWMZo TStpQ/Y/+TJexXK2Tk+cPWvP5jlvXgHrw5OuQ6vbtbDH/ErT88fOjYV1bCli4eVdGfOm iJ9K+uT9WmXIPFLYu52kpDU47jmQ24lREsP0BbbX72PJhWhakBh1PX2fIFIH+EhMm2rs autA== X-Gm-Message-State: AOAM5338sOHtAIm2SEc11+dJrJJCSl11a+rb2IPQHfl1hh+lzQXgD93z 3RUwZhx3aUfH86xb+PlqCZQ= X-Received: by 2002:a05:6402:50ce:: with SMTP id h14mr8216082edb.283.1613727803314; Fri, 19 Feb 2021 01:43:23 -0800 (PST) Received: from ?IPv6:2a0b:e7c0:0:107::49? ([2a0b:e7c0:0:107::49]) by smtp.gmail.com with ESMTPSA id y11sm2071075edw.18.2021.02.19.01.43.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 19 Feb 2021 01:43:22 -0800 (PST) Subject: Re: [PATCH v3 2/2] serial: 8250: Add new 8250-core based Broadcom STB driver To: Al Cooper , linux-kernel@vger.kernel.org Cc: bcm-kernel-feedback-list@broadcom.com, devicetree@vger.kernel.org, Greg Kroah-Hartman , linux-serial@vger.kernel.org, linux-usb@vger.kernel.org, Masahiro Yamada , Rob Herring References: <20210212195736.45328-1-alcooperx@gmail.com> <20210212195736.45328-3-alcooperx@gmail.com> From: Jiri Slaby Message-ID: Date: Fri, 19 Feb 2021 10:43:21 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: <20210212195736.45328-3-alcooperx@gmail.com> Content-Type: text/plain; charset=iso-8859-2; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12. 02. 21, 20:57, Al Cooper wrote: > Add a UART driver for the new Broadcom 8250 based STB UART. The new > UART is backward compatible with the standard 8250, but has some > additional features. The new features include a high accuracy baud > rate clock system and DMA support. > > The driver will use the new optional BAUD MUX clock to select the best > one of the four master clocks (81MHz, 108MHz, 64MHz and 48MHz) to feed > the baud rate selection logic for any requested baud rate. This allows > for more accurate BAUD rates when high speed baud rates are selected. ... > --- /dev/null > +++ b/drivers/tty/serial/8250/8250_bcm7271.c ... > +static void brcmuart_rx_isr(struct uart_port *up, u32 rx_isr) > +{ > + struct brcmuart_priv *priv = up->private_data; > + struct device *dev = up->dev; > + u32 rx_done_isr; > + u32 check_isr; > + char seq_err[] = "RX buffer ready out of sequence, restarting RX DMA\n"; What's the purpose of this on-stack variable? > +static void init_real_clk_rates(struct device *dev, struct brcmuart_priv *priv) > +{ > + int x; > + int rc; > + > + priv->default_mux_rate = clk_get_rate(priv->baud_mux_clk); > + dev_dbg(dev, "Default BAUD MUX Clock rate is %lu\n", > + priv->default_mux_rate); > + > + for (x = 0; x < ARRAY_SIZE(priv->real_rates); x++) { > + if (priv->rate_table[x] == 0) { > + priv->real_rates[x] = 0; > + continue; > + } > + rc = clk_set_rate(priv->baud_mux_clk, priv->rate_table[x]); > + if (rc) { > + dev_err(dev, "Error selecting BAUD MUX clock for %u\n", > + priv->rate_table[x]); > + priv->real_rates[x] = priv->rate_table[x]; > + } else { > + priv->real_rates[x] = clk_get_rate(priv->baud_mux_clk); > + } > + } > + clk_set_rate(priv->baud_mux_clk, priv->default_mux_rate); This is only weirdly indented. > +} > + > +static void set_clock_mux(struct uart_port *up, struct brcmuart_priv *priv, > + u32 baud) > +{ > + u32 percent; > + u32 best_percent = UINT_MAX; > + u32 quot; > + u32 best_quot = 1; > + u32 rate; > + int best_index = -1; > + u64 hires_rate; > + u64 hires_baud; > + u64 hires_err; > + int rc; > + int i; > + int real_baud; > + > + /* If the Baud Mux Clock was not specified, just return */ > + if (priv->baud_mux_clk == NULL) > + return; > + > + /* Find the closest match for specified baud */ > + for (i = 0; i < ARRAY_SIZE(priv->real_rates); i++) { > + if (priv->real_rates[i] == 0) > + continue; > + rate = priv->real_rates[i] / 16; > + quot = DIV_ROUND_CLOSEST(rate, baud); > + if (!quot) > + continue; > + > + /* increase resolution to get xx.xx percent */ > + hires_rate = (u64)rate * 10000; > + hires_baud = (u64)baud * 10000; > + > + hires_err = div_u64(hires_rate, (u64)quot); > + > + /* get the delta */ > + if (hires_err > hires_baud) > + hires_err = (hires_err - hires_baud); > + else > + hires_err = (hires_baud - hires_err); > + > + percent = (unsigned long)DIV_ROUND_CLOSEST_ULL(hires_err, baud); > + dev_dbg(up->dev, > + "Baud rate: %u, MUX Clk: %u, Error: %u.%u%%\n", > + baud, priv->real_rates[i], percent / 100, > + percent % 100); > + if (percent < best_percent) { > + best_percent = percent; > + best_index = i; > + best_quot = quot; > + } > + } > + if (best_index == -1) { > + dev_err(up->dev, "Error, %d BAUD rate is too fast.\n", baud); > + return; > + } > + rate = priv->real_rates[best_index]; > + rc = clk_set_rate(priv->baud_mux_clk, rate); > + if (rc) > + dev_err(up->dev, "Error selecting BAUD MUX clock\n"); > + > + /* Error over 3 percent will cause data errors */ > + if (best_percent > 300) > + dev_err(up->dev, "Error, baud: %d has %u.%u%% error\n", > + baud, percent / 100, percent % 100); > + > + real_baud = rate / 16 / best_quot; > + dev_dbg(up->dev, "Selecting BAUD MUX rate: %u\n", rate); > + dev_dbg(up->dev, "Requested baud: %u, Actual baud: %u\n", > + baud, real_baud); > + > + /* calc nanoseconds for 1.5 characters time at the given baud rate */ > + i = 1000000000 / real_baud / 10; NSEC_PER_SEC here? > + i += (i / 2); > + priv->char_wait = ns_to_ktime(i); > + > + up->uartclk = rate; > +} ... > +static int __maybe_unused brcmuart_resume(struct device *dev) > +{ > + struct brcmuart_priv *priv = dev_get_drvdata(dev); > + int ret; > + > + ret = clk_prepare_enable(priv->baud_mux_clk); > + if (ret) > + dev_err(dev, "Error enabling BAUD MUX clock\n"); > + > + /* > + * The hardware goes back to it's default after suspend > + * so get the "clk" back in sync. > + */ > + ret = clk_set_rate(priv->baud_mux_clk, priv->default_mux_rate); > + if (ret) > + dev_err(dev, "Error restoring default BAUD MUX clock\n"); > + if (priv->dma_enabled) { > + brcmuart_arbitration(priv, 1); > + brcmuart_init_dma_hardware(priv); > + start_rx_dma(serial8250_get_port(priv->line)); > + } > + serial8250_resume_port(priv->line); All these cannot fail? Or the above can, so does proceeding further without an error make sense? > + return 0; > +} .... > --- a/drivers/tty/serial/8250/Kconfig > +++ b/drivers/tty/serial/8250/Kconfig > @@ -501,6 +501,7 @@ config SERIAL_8250_PXA > applicable to both devicetree and legacy boards, and early console is > part of its support. > > + Why adding a newline here? > config SERIAL_8250_TEGRA > tristate "8250 support for Tegra serial ports" > default SERIAL_8250 regards, -- js suse labs