From patchwork Tue Dec 24 14:14:32 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 3404201 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id F18149F169 for ; Tue, 24 Dec 2013 16:09:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E47BE20375 for ; Tue, 24 Dec 2013 16:09:02 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id ABB49202EB for ; Tue, 24 Dec 2013 16:09:01 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VvSo6-0003Zx-6W; Tue, 24 Dec 2013 14:18:03 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VvSnW-0005Sx-Gr; Tue, 24 Dec 2013 14:17:26 +0000 Received: from kirsty.vergenet.net ([202.4.237.240]) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VvSlP-00056w-A6 for linux-arm-kernel@lists.infradead.org; Tue, 24 Dec 2013 14:15:18 +0000 Received: from ayumi.isobedori.kobe.vergenet.net (p2020-ipbfp1604kobeminato.hyogo.ocn.ne.jp [114.154.85.20]) by kirsty.vergenet.net (Postfix) with ESMTP id 22D13266CF2; Wed, 25 Dec 2013 01:14:40 +1100 (EST) Received: by ayumi.isobedori.kobe.vergenet.net (Postfix, from userid 7100) id BE1F3EDE008; Tue, 24 Dec 2013 23:14:38 +0900 (JST) From: Simon Horman To: linux-sh@vger.kernel.org Subject: [PATCH 11/11] serial: sh-sci: Rework baud rate calculation Date: Tue, 24 Dec 2013 23:14:32 +0900 Message-Id: X-Mailer: git-send-email 1.8.4 In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131224_091515_887630_8CADDB4A X-CRM114-Status: GOOD ( 17.86 ) X-Spam-Score: -3.1 (---) Cc: Simon Horman , Laurent Pinchart , Magnus Damm , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 From: Laurent Pinchart Computing the baud rate register value requires knowledge of the hardware sampling rate. This information is currently encoded in a baud rate calculation algorithm ID passed through platform data. However, it can be derived from the port type directly in most cases. Compute the sampling rate internally in the driver if the baud rate calculation algorithm ID isn't specified, and allow platforms to override the sampling rate through platform data in special cases (this is only required for SCIFA ports on sh7723 and sh7724, the reason needs to be investigated). Signed-off-by: Laurent Pinchart Acked-by: Greg Kroah-Hartman Signed-off-by: Simon Horman --- drivers/tty/serial/sh-sci.c | 37 ++++++++++++++++++++++++++++++------- include/linux/serial_sci.h | 2 ++ 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index d5239d5..e4bf0e4 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -65,6 +65,7 @@ struct sci_port { struct plat_sci_port *cfg; int overrun_bit; unsigned int error_mask; + unsigned int sampling_rate; /* Break timer */ @@ -1750,10 +1751,13 @@ static void sci_shutdown(struct uart_port *port) sci_free_irq(s); } -static unsigned int sci_scbrr_calc(unsigned int algo_id, unsigned int bps, +static unsigned int sci_scbrr_calc(struct sci_port *s, unsigned int bps, unsigned long freq) { - switch (algo_id) { + if (s->sampling_rate) + return DIV_ROUND_CLOSEST(freq, s->sampling_rate * bps) - 1; + + switch (s->cfg->scbrr_algo_id) { case SCBRR_ALGO_1: return freq / (16 * bps); case SCBRR_ALGO_2: @@ -1843,12 +1847,11 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios, baud = uart_get_baud_rate(port, termios, old, 0, max_baud); if (likely(baud && port->uartclk)) { - if (s->cfg->scbrr_algo_id == SCBRR_ALGO_6) { + if (s->cfg->type == PORT_HSCIF) { sci_baud_calc_hscif(baud, port->uartclk, &t, &srr, &cks); } else { - t = sci_scbrr_calc(s->cfg->scbrr_algo_id, baud, - port->uartclk); + t = sci_scbrr_calc(s, baud, port->uartclk); for (cks = 0; t >= 256 && cks <= 3; cks++) t >>= 2; } @@ -2092,6 +2095,7 @@ static int sci_init_single(struct platform_device *dev, { struct uart_port *port = &sci_port->port; const struct resource *res; + unsigned int sampling_rate; unsigned int i; int ret; @@ -2143,28 +2147,47 @@ static int sci_init_single(struct platform_device *dev, case PORT_SCIFB: port->fifosize = 256; sci_port->overrun_bit = 9; + sampling_rate = 16; break; case PORT_HSCIF: port->fifosize = 128; + sampling_rate = 0; sci_port->overrun_bit = 0; break; case PORT_SCIFA: port->fifosize = 64; sci_port->overrun_bit = 9; + sampling_rate = 16; break; case PORT_SCIF: port->fifosize = 16; - if (p->regtype == SCIx_SH7705_SCIF_REGTYPE) + if (p->regtype == SCIx_SH7705_SCIF_REGTYPE) { sci_port->overrun_bit = 9; - else + sampling_rate = 16; + } else { sci_port->overrun_bit = 0; + sampling_rate = 32; + } break; default: port->fifosize = 1; sci_port->overrun_bit = 5; + sampling_rate = 32; break; } + /* Set the sampling rate if the baud rate calculation algorithm isn't + * specified. + */ + if (p->scbrr_algo_id == SCBRR_ALGO_NONE) { + /* SCIFA on sh7723 and sh7724 need a custom sampling rate that + * doesn't match the SoC datasheet, this should be investigated. + * Let platform data override the sampling rate for now. + */ + sci_port->sampling_rate = p->sampling_rate ? p->sampling_rate + : sampling_rate; + } + if (!early) { sci_port->iclk = clk_get(&dev->dev, "sci_ick"); if (IS_ERR(sci_port->iclk)) { diff --git a/include/linux/serial_sci.h b/include/linux/serial_sci.h index e9c3021..af414e1 100644 --- a/include/linux/serial_sci.h +++ b/include/linux/serial_sci.h @@ -11,6 +11,7 @@ #define SCIx_NOT_SUPPORTED (-1) enum { + SCBRR_ALGO_NONE, /* Compute sampling rate in the driver */ SCBRR_ALGO_1, /* clk / (16 * bps) */ SCBRR_ALGO_2, /* DIV_ROUND_CLOSEST(clk, 32 * bps) - 1 */ SCBRR_ALGO_3, /* clk / (8 * bps) */ @@ -134,6 +135,7 @@ struct plat_sci_port { upf_t flags; /* UPF_* flags */ unsigned long capabilities; /* Port features/capabilities */ + unsigned int sampling_rate; unsigned int scbrr_algo_id; /* SCBRR calculation algo */ unsigned int scscr; /* SCSCR initialization */