From patchwork Wed Sep 24 07:55:22 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frans Klaver X-Patchwork-Id: 4962101 Return-Path: X-Original-To: patchwork-linux-omap@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 6EFC09F3DF for ; Wed, 24 Sep 2014 07:57:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9E4C020253 for ; Wed, 24 Sep 2014 07:57:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5E21E20268 for ; Wed, 24 Sep 2014 07:57:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753732AbaIXH47 (ORCPT ); Wed, 24 Sep 2014 03:56:59 -0400 Received: from filter1.ibarracuda.nl ([83.247.7.10]:42826 "EHLO filter1.ibarracuda.nl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753379AbaIXHzd (ORCPT ); Wed, 24 Sep 2014 03:55:33 -0400 X-ASG-Debug-ID: 1411545331-0759e7612989fa50002-g9IbbW Received: from XSMCASSVR01.xsens-tech.local (rev-215.116.249.87.virtu.nl [87.249.116.215]) by filter1.ibarracuda.nl with ESMTP id g41M8FqiA6HmFWq8 (version=TLSv1 cipher=AES128-SHA bits=128 verify=NO); Wed, 24 Sep 2014 09:55:31 +0200 (CEST) X-Barracuda-Envelope-From: Frans.Klaver@xsens.com X-Barracuda-AUTH-User: xsenscom X-Barracuda-Apparent-Source-IP: 87.249.116.215 Received: from ci00147.xsens-tech.local (172.16.11.160) by XSMCASSVR01.xsens-tech.local (192.168.0.248) with Microsoft SMTP Server id 14.3.195.1; Wed, 24 Sep 2014 09:55:31 +0200 From: Frans Klaver To: Greg Kroah-Hartman CC: Frans Klaver , Jiri Slaby , , , Subject: [PATCH 2/2] tty: omap-serial: pull out calculation from baud_is_mode16 Date: Wed, 24 Sep 2014 09:55:22 +0200 X-ASG-Orig-Subj: [PATCH 2/2] tty: omap-serial: pull out calculation from baud_is_mode16 Message-ID: <1411545322-22940-3-git-send-email-frans.klaver@xsens.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1411545322-22940-1-git-send-email-frans.klaver@xsens.com> References: <1411545322-22940-1-git-send-email-frans.klaver@xsens.com> MIME-Version: 1.0 X-Originating-IP: [172.16.11.160] X-Barracuda-Connect: rev-215.116.249.87.virtu.nl[87.249.116.215] X-Barracuda-Start-Time: 1411545331 X-Barracuda-Encrypted: AES128-SHA X-Barracuda-URL: http://filter1.ibarracuda.nl:8000/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at ibarracuda.nl X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using per-user scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=5.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.9817 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 To determine the correct divisor, we need to know the difference between the desired baud rate and the actual baud rate. The calculation for this difference is implemented twice within omap_serial_baud_is_mode16(). Pull out the calculation for easier maintenance. While at it, remove the CamelCasing from the variable names. Signed-off-by: Frans Klaver --- drivers/tty/serial/omap-serial.c | 42 +++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c index e454b7c..18c30ca 100644 --- a/drivers/tty/serial/omap-serial.c +++ b/drivers/tty/serial/omap-serial.c @@ -239,6 +239,26 @@ static void serial_omap_enable_wakeup(struct uart_omap_port *up, bool enable) } /* + * Calculate the absolute difference between the desired and actual baud + * rate for the given mode. + */ +static inline int calculate_baud_abs_diff(struct uart_port *port, + unsigned int baud, unsigned int mode) +{ + unsigned int n = port->uartclk / (mode * baud); + int abs_diff; + + if (n == 0) + n = 1; + + abs_diff = baud - (port->uartclk / (mode * n)); + if (abs_diff < 0) + abs_diff = -abs_diff; + + return abs_diff; +} + +/* * serial_omap_baud_is_mode16 - check if baud rate is MODE16X * @port: uart port info * @baud: baudrate for which mode needs to be determined @@ -252,24 +272,10 @@ static void serial_omap_enable_wakeup(struct uart_omap_port *up, bool enable) static bool serial_omap_baud_is_mode16(struct uart_port *port, unsigned int baud) { - unsigned int n13 = port->uartclk / (13 * baud); - unsigned int n16 = port->uartclk / (16 * baud); - int baudAbsDiff13; - int baudAbsDiff16; - - if (n13 == 0) - n13 = 1; - if (n16 == 0) - n16 = 1; - - baudAbsDiff13 = baud - (port->uartclk / (13 * n13)); - baudAbsDiff16 = baud - (port->uartclk / (16 * n16)); - if (baudAbsDiff13 < 0) - baudAbsDiff13 = -baudAbsDiff13; - if (baudAbsDiff16 < 0) - baudAbsDiff16 = -baudAbsDiff16; - - return (baudAbsDiff13 >= baudAbsDiff16); + int abs_diff_13 = calculate_baud_abs_diff(port, baud, 13); + int abs_diff_16 = calculate_baud_abs_diff(port, baud, 16); + + return (abs_diff_13 >= abs_diff_16); } /*