Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp5178792pxb; Sun, 13 Feb 2022 10:33:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJxhuanEEbRy10cyEoN9shTmTUoTLSAjT/tz0sZcbBXtU/yq1ZjG2yFT9qLaA8zcrOhujljU X-Received: by 2002:aa7:dccb:: with SMTP id w11mr2098680edu.146.1644777218867; Sun, 13 Feb 2022 10:33:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644777218; cv=none; d=google.com; s=arc-20160816; b=eBysgl+gY+s4KDCV+QSkOGenlylbR+i88Lf7REGFdUj01e7x81r6pnDfQrSFtGWLo5 BATeb+KQSObYEllqvMFhn1GpkJGSeEEC39b/kLSVBFf5e4uqKswBk6kjOFoJmH7SZ83g jRVsHV26i7Ly/+fXqCP/7jIh2tFY1+QPMj6DXV1KXwquCsElnc3/HO411H6G9WRokN9M 6cpJgt5fH/kQ5YPlongcNGAKD7f0E21pkmug9qZKRtl6cs8n1YL4WbTLDT9ohVDJRJ/d 0ModiW9T6z8uJu8BChM6uGho3wD+bXrQC69AtYNZUNkwbURemNBf2fuaqpyKgJS2lm6W GO8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=fNVtGj2HlwN1t95oRwbX7m9qgYlxgxLGOkN+c8cOGws=; b=VFGpMVqcCm4vBQH2pZ5IpySrqGCjwz5LorQviByF92e8npA6SpNQMn7fDqEGw7jBAI dQ8KHfaqs92qhZ0puITk7vaVH210Tcj8iXlR7dUwuOPZH6IFx26O2CxywajG/hKu5+bc egJnkimr6juBNUC235nhQe81G3vIG+/9oakgpM/x6pmsKq0o8+oiZFG8fjHSoIZYifIC BDCGm4vhFeY5uw4+6gBDkqxrMUuHidl9RSIZChbn1G4tLDpvwXXlL/NrMS00V37PnlWn 8T1ht+bOHnipMn5C4sLlSpGEeesheArO2nCD+x0+K+JuAi/T1wUQeOTUCgNgbP8e2LCl uztQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=PFReLFuS; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h14si21086343edl.217.2022.02.13.10.33.14; Sun, 13 Feb 2022 10:33:38 -0800 (PST) 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=pass header.i=@gmail.com header.s=20210112 header.b=PFReLFuS; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236136AbiBLOg5 (ORCPT + 99 others); Sat, 12 Feb 2022 09:36:57 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:51526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229551AbiBLOg4 (ORCPT ); Sat, 12 Feb 2022 09:36:56 -0500 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0474720F; Sat, 12 Feb 2022 06:36:53 -0800 (PST) Received: by mail-ed1-x530.google.com with SMTP id s7so20571618edd.3; Sat, 12 Feb 2022 06:36:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=fNVtGj2HlwN1t95oRwbX7m9qgYlxgxLGOkN+c8cOGws=; b=PFReLFuS9ZMwPZ3FYSl4edpXkzUzLQtYO8nz/FObDG9k8yQNHvUIKpt8BSKuegk+Qz URLWLVSAthB9vRGw3F1hKQR41+mjgGkdJ/tClO052v4vI7sp1qVwBspsNnn0LNcavv1q 2TPq/tdMi4U4iqLaOi6hC6ChcjUkbhNOnVooIV1273/wseBqAtvnFOEoZVjM9lPlUXNw 9djtWzil1652IT6SVM7VIg5ugD2fOR46xWkoeUZRMNPGhSJi/dglHFopinDR00ElFzDC XWyzzawbTtcQWfG2ylh6u22XtRoGcNvNb/qY4qTwr/xWSPJbo5gV5bseO0+s4Iii+QOj ewaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=fNVtGj2HlwN1t95oRwbX7m9qgYlxgxLGOkN+c8cOGws=; b=iufiu2Dyr+52CC9JRoJjFm9uSETJtn43nc4Idgk8QTpaedgxsNQTVA5Rxy+fSYN9s6 yiW11bSPBPdTvFJhskqP0iPMy/NRJlRW6L3OvUVMEKimWM/Ea/IEusbirGL7ue5Z7c4i Oz2tH3VINgDVmCke6nwr9LP6iB5rauAa7m2tIM6Z1mBPckx80knKtCVvIXGGAZAyRmxs HNylxMNh5Q8TRSruhdjayIT8PVuZ33U2RWoNUgZU3G7e9+4lykXVJY01nO4ef/QH/Ehn SQphUqJhpCwSw+N90ll050n1hE2AqWJIptMsl0bf9q1hPtmCctY2ijSaOHvIDZodT6kY 3FQw== X-Gm-Message-State: AOAM533rkgt7WANAmm5LqiyZ4vAkEvkcjv2V7s6JE9vHLOp3WdlNa3UB aU58lCBrzHN6j6LEzYChVnWaiHMIIbCSejq0d+0= X-Received: by 2002:aa7:c395:: with SMTP id k21mr4401538edq.436.1644676611377; Sat, 12 Feb 2022 06:36:51 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Andy Shevchenko Date: Sat, 12 Feb 2022 16:36:15 +0200 Message-ID: Subject: Re: [PATCH v3 2/2] serial: 8250: Add proper clock handling for OxSemi PCIe devices To: "Maciej W. Rozycki" Cc: Greg Kroah-Hartman , Jiri Slaby , Mike Skoog , Mike Korreng , info@endruntechnologies.com, "open list:SERIAL DRIVERS" , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Feb 12, 2022 at 10:41 AM Maciej W. Rozycki wrote: > > Oxford Semiconductor PCIe (Tornado) 950 serial port devices are driven > by a fixed 62.5MHz clock input derived from the 100MHz PCI Express clock. > > We currently drive the device using its default oversampling rate of 16 > and the clock prescaler disabled, consequently yielding the baud base of > 3906250. This base is inadequate for some of the high-speed baud rates > such as 460800bps, for which the closest rate possible can be obtained > by dividing the baud base by 8, yielding the baud rate of 488281.25bps, > which is off by 5.9638%. This is enough for data communication to break > with the remote end talking actual 460800bps where missed stop bits have > been observed. > > We can do better however, by taking advantage of a reduced oversampling > rate, which can be set to any integer value from 4 to 16 inclusive by > programming the TCR register, and by using the clock prescaler, which > can be set to any value from 1 to 63.875 in increments of 0.125 in the > CPR/CPR2 register pair. The prescaler has to be explicitly enabled > though by setting bit 7 in the MCR or otherwise it is bypassed (in the > enhanced mode that we enable) as if the value of 1 was used. > > Make use of these features then as follows: > > - Set the baud base to 15625000, reflecting the minimum oversampling > rate of 4 with the clock prescaler and divisor both set to 1. > > - Override the `set_mctrl' and set the MCR shadow there so as to have > MCR[7] always set and have the 8250 core propagate this settings; also > make the console restorer use this shadow. > > - Override the `get_divisor' handler and determine a good combination of > parameters by using a lookup table with predetermined value pairs of > the oversampling rate and the clock prescaler and finding a pair that > divides the input clock such that the quotient, when rounded to the > nearest integer, deviates the least from the exact result. Calculate > the clock divisor accordingly. > > Scale the resulting oversampling rate (only by powers of two) if > possible so as to maximise it, reducing the divisor accordingly, and > avoid a divisor overflow for very low baud rates by scaling the > oversampling rate and/or the prescaler even if that causes some > accuracy loss. > > Also handle the historic spd_cust feature so as to allow one to set > all the three parameters manually to arbitrary values, by keeping the > low 16 bits for the divisor and then putting TCR in bits 19:16 and > CPR/CPR2 in bits 28:20, sanitising the bit pattern supplied such as > to clamp CPR/CPR2 values between 0.000 and 0.875 inclusive to 33.875. > This preserves compatibility with any existing setups, that is where > requesting a custom divisor that only has any bits set among the low > 16 the oversampling rate of 16 and the clock prescaler of 33.875 will > be used as with the original 8250. > > Finally abuse the `frac' argument to store the determined bit patterns > for the TCR, CPR and CPR2 registers. > > - Override the `set_divisor' handler so as to set the TCR, CPR and CPR2 > registers from the `frac' value supplied. Set the divisor as usually. > > With the baud base set to 15625000 and the unsigned 16-bit UART_DIV_MAX > limitation imposed by `serial8250_get_baud_rate' standard baud rates > below 300bps become unavailable in the regular way, e.g. the rate of > 200bps requires the baud base to be divided by 78125 and that is beyond > the unsigned 16-bit range. The historic spd_cust feature can still be > used to obtain such rates if so required. > > See Documentation/tty/device_drivers/oxsemi-tornado.rst for more details. ... > + /* Old custom speed handling. */ Exactly and we do not want to see this in the new code. > + if (baud == 38400 && (port->flags & UPF_SPD_MASK) == UPF_SPD_CUST) { > + unsigned int cust_div = port->custom_divisor; > + > + quot = cust_div & UART_DIV_MAX; > + tcr = (cust_div >> 16) & OXSEMI_TORNADO_TCR_MASK; > + cpr = (cust_div >> 20) & OXSEMI_TORNADO_CPR_MASK; > + if (cpr < OXSEMI_TORNADO_CPR_MIN) > + cpr = OXSEMI_TORNADO_CPR_DEF; > + } else { I'll read and comment on the rest later on (hopefully next week). P.S. I still think that overloading 8250_pci with custom quirks is not a good idea. -- With Best Regards, Andy Shevchenko