From patchwork Mon Jan 4 13:45:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 7948161 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id BA5BFBEEE5 for ; Mon, 4 Jan 2016 13:45:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CE1AE2034E for ; Mon, 4 Jan 2016 13:45:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B8AC62034B for ; Mon, 4 Jan 2016 13:45:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753504AbcADNp2 (ORCPT ); Mon, 4 Jan 2016 08:45:28 -0500 Received: from baptiste.telenet-ops.be ([195.130.132.51]:41212 "EHLO baptiste.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751728AbcADNp1 (ORCPT ); Mon, 4 Jan 2016 08:45:27 -0500 Received: from ayla.of.borg ([84.195.106.123]) by baptiste.telenet-ops.be with bizsmtp id 1plQ1s00u2fm56U01plQ6a; Mon, 04 Jan 2016 14:45:26 +0100 Received: from ramsan.of.borg ([192.168.97.29] helo=ramsan) by ayla.of.borg with esmtp (Exim 4.82) (envelope-from ) id 1aG5Rs-0002eO-JF; Mon, 04 Jan 2016 14:45:24 +0100 Received: from geert by ramsan with local (Exim 4.82) (envelope-from ) id 1aG5Ru-0007sJ-Aj; Mon, 04 Jan 2016 14:45:26 +0100 From: Geert Uytterhoeven To: Greg Kroah-Hartman , Jiri Slaby Cc: Simon Horman , Magnus Damm , Yoshinori Sato , linux-serial@vger.kernel.org, linux-sh@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 3/5] serial: sh-sci: Use premultiplier to handle half sampling rate Date: Mon, 4 Jan 2016 14:45:20 +0100 Message-Id: <1451915122-30219-4-git-send-email-geert+renesas@glider.be> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1451915122-30219-1-git-send-email-geert+renesas@glider.be> References: <1451915122-30219-1-git-send-email-geert+renesas@glider.be> Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On SCIx variants different from HSCIF, the bit rate is equal to the sampling clock rate divided by half the sampling rate. Currently this is handled by dividing the sampling rate by two, which was OK as it was always even. Replace halving the sampling rate by premultiplying the base clock frequency by 2, to accommodate odd sampling rates on SCIFA/SCIFB later. Replace the shift value in the BRG divider calculation by a premultiplication of the base clock frequency too, for consistency. Signed-off-by: Geert Uytterhoeven --- drivers/tty/serial/sh-sci.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index e8d6fa77e11208d4..f3c2a89a9550add9 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -1934,9 +1934,11 @@ static int sci_sck_calc(struct sci_port *s, unsigned int bps, unsigned int min_sr, max_sr, sr; int err, min_err = INT_MAX; + if (s->port.type != PORT_HSCIF) + freq *= 2; if (s->sampling_rate) { /* SCI(F) has a fixed sampling rate */ - min_sr = max_sr = s->sampling_rate / 2; + min_sr = max_sr = s->sampling_rate; } else { /* HSCIF has a variable 1/(8..32) sampling rate */ min_sr = 8; @@ -1967,9 +1969,11 @@ static int sci_brg_calc(struct sci_port *s, unsigned int bps, unsigned int min_sr, max_sr, sr, dl; int err, min_err = INT_MAX; + if (s->port.type != PORT_HSCIF) + freq *= 2; if (s->sampling_rate) { /* SCIF has a fixed sampling rate */ - min_sr = max_sr = s->sampling_rate / 2; + min_sr = max_sr = s->sampling_rate; } else { /* HSCIF has a variable 1/(8..32) sampling rate */ min_sr = 8; @@ -2002,18 +2006,18 @@ static int sci_scbrr_calc(struct sci_port *s, unsigned int bps, unsigned int *brr, unsigned int *srr, unsigned int *cks) { - unsigned int min_sr, max_sr, shift, sr, br, prediv, scrate, c; + unsigned int min_sr, max_sr, sr, br, prediv, scrate, c; unsigned long freq = s->clk_rates[SCI_FCK]; int err, min_err = INT_MAX; + if (s->port.type != PORT_HSCIF) + freq *= 2; if (s->sampling_rate) { min_sr = max_sr = s->sampling_rate; - shift = 0; } else { /* HSCIF has a variable sample rate */ min_sr = 8; max_sr = 32; - shift = 1; } /* @@ -2034,7 +2038,7 @@ static int sci_scbrr_calc(struct sci_port *s, unsigned int bps, for (sr = max_sr; sr >= min_sr; sr--) { for (c = 0; c <= 3; c++) { /* integerized formulas from HSCIF documentation */ - prediv = sr * (1 << (2 * c + shift)); + prediv = sr * (1 << (2 * c + 1)); /* * We need to calculate: