From: Frans Klaver <frans.klaver@xsens.com>
To: Felipe Balbi <balbi@ti.com>
Cc: Frans Klaver <frans.klaver@xsens.com>,
Tony Lindgren <tony@atomide.com>,
Rob Herring <robh+dt@kernel.org>, Pawel Moll <pawel.moll@arm.com>,
Mark Rutland <mark.rutland@arm.com>,
Ian Campbell <ijc+devicetree@hellion.org.uk>,
Kumar Gala <galak@codeaurora.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Alexey Pelykh <alexey.pelykh@gmail.com>,
Jiri Slaby <jslaby@suse.cz>, Frans Klaver <fransklaver@gmail.com>,
<linux-serial@vger.kernel.org>, <linux-omap@vger.kernel.org>,
<devicetree@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>
Subject: [PATCH 1/4] tty: omap-serial: pull out calculation from baud_is_mode16
Date: Tue, 19 Aug 2014 14:14:45 +0200 [thread overview]
Message-ID: <1408450488-4083-2-git-send-email-frans.klaver@xsens.com> (raw)
In-Reply-To: <1408450488-4083-1-git-send-email-frans.klaver@xsens.com>
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.
Signed-off-by: Frans Klaver <frans.klaver@xsens.com>
---
drivers/tty/serial/omap-serial.c | 26 ++++++++++++++++++--------
1 file changed, 18 insertions(+), 8 deletions(-)
diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c
index d017cec..ae935ce 100644
--- a/drivers/tty/serial/omap-serial.c
+++ b/drivers/tty/serial/omap-serial.c
@@ -239,6 +239,22 @@ 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 = 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,14 +268,8 @@ 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 = baud - (port->uartclk / (13 * n13));
- int baudAbsDiff16 = baud - (port->uartclk / (16 * n16));
- if (baudAbsDiff13 < 0)
- baudAbsDiff13 = -baudAbsDiff13;
- if (baudAbsDiff16 < 0)
- baudAbsDiff16 = -baudAbsDiff16;
+ int baudAbsDiff13 = calculate_baud_abs_diff(port, baud, 13);
+ int baudAbsDiff16 = calculate_baud_abs_diff(port, baud, 16);
return (baudAbsDiff13 >= baudAbsDiff16);
}
--
1.9.3
next prev parent reply other threads:[~2014-08-19 12:15 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-29 14:52 [RFC PATCH 0/3] omap-serial high-speed fixes/improvements Frans Klaver
[not found] ` <1406645577-18620-2-git-send-email-frans.klaver@xsens.com>
2014-07-29 15:00 ` [PATCH 1/3] tty: omap-serial: prevent division by zero Frans Klaver
2014-07-29 15:02 ` [RFC PATCH 0/3] omap-serial high-speed fixes/improvements Frans Klaver
2014-07-29 15:02 ` [PATCH 1/3] tty: omap-serial: prevent division by zero Frans Klaver
2014-07-29 15:02 ` [PATCH 2/3] tty: omap-serial: use threaded interrupt handler Frans Klaver
2014-07-29 15:02 ` [PATCH 3/3] tty: omap-serial: support setting of hardware flow control in dts Frans Klaver
2014-08-11 10:09 ` [RFC PATCH 0/3] omap-serial high-speed fixes/improvements Frans Klaver
2014-08-18 13:45 ` Felipe Balbi
2014-08-18 14:45 ` Frans Klaver
2014-08-19 12:14 ` [RFC PATCHv2 0/4] " Frans Klaver
2014-08-19 12:14 ` Frans Klaver [this message]
2014-08-19 12:14 ` [PATCH 2/4] tty: omap-serial: prevent division by zero Frans Klaver
2014-08-19 12:14 ` [RFC PATCH 3/4] tty: omap-serial: use threaded interrupt handler Frans Klaver
2014-08-19 18:57 ` Felipe Balbi
2014-08-20 6:40 ` Frans Klaver
2014-08-20 16:06 ` Felipe Balbi
2014-08-21 21:41 ` Frans Klaver
2014-08-21 21:48 ` Felipe Balbi
2014-08-21 22:07 ` Frans Klaver
2014-08-22 14:02 ` Frans Klaver
2014-08-19 12:14 ` [PATCH 4/4] tty: omap-serial: support setting of hardware flow control in dts Frans Klaver
2014-09-15 14:00 [PATCH v3 0/4] omap-serial high-speed fixes/improvements Frans Klaver
2014-09-15 14:00 ` [PATCH 1/4] tty: omap-serial: pull out calculation from baud_is_mode16 Frans Klaver
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1408450488-4083-2-git-send-email-frans.klaver@xsens.com \
--to=frans.klaver@xsens.com \
--cc=alexey.pelykh@gmail.com \
--cc=balbi@ti.com \
--cc=devicetree@vger.kernel.org \
--cc=fransklaver@gmail.com \
--cc=galak@codeaurora.org \
--cc=gregkh@linuxfoundation.org \
--cc=ijc+devicetree@hellion.org.uk \
--cc=jslaby@suse.cz \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=pawel.moll@arm.com \
--cc=robh+dt@kernel.org \
--cc=tony@atomide.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®