aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/tty
diff options
context:
space:
mode:
authorFrans Klaver <frans.klaver@xsens.com>2014-09-24 03:55:22 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-09-28 21:24:06 -0400
commit13d6ceb4c4fe1e9688e19b15b123b1830c596cf1 (patch)
treea3e3669c6295641831a9b31e3bd52c8340ec85a1 /drivers/tty
parentdc3187564e61260f49eceb21a4e7eb5e4428e90a (diff)
tty: omap-serial: pull out calculation from baud_is_mode16
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 <frans.klaver@xsens.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/tty')
-rw-r--r--drivers/tty/serial/omap-serial.c42
1 files changed, 24 insertions, 18 deletions
diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c
index e454b7c2ecd9..18c30cabe27f 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)
239} 239}
240 240
241/* 241/*
242 * Calculate the absolute difference between the desired and actual baud
243 * rate for the given mode.
244 */
245static inline int calculate_baud_abs_diff(struct uart_port *port,
246 unsigned int baud, unsigned int mode)
247{
248 unsigned int n = port->uartclk / (mode * baud);
249 int abs_diff;
250
251 if (n == 0)
252 n = 1;
253
254 abs_diff = baud - (port->uartclk / (mode * n));
255 if (abs_diff < 0)
256 abs_diff = -abs_diff;
257
258 return abs_diff;
259}
260
261/*
242 * serial_omap_baud_is_mode16 - check if baud rate is MODE16X 262 * serial_omap_baud_is_mode16 - check if baud rate is MODE16X
243 * @port: uart port info 263 * @port: uart port info
244 * @baud: baudrate for which mode needs to be determined 264 * @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)
252static bool 272static bool
253serial_omap_baud_is_mode16(struct uart_port *port, unsigned int baud) 273serial_omap_baud_is_mode16(struct uart_port *port, unsigned int baud)
254{ 274{
255 unsigned int n13 = port->uartclk / (13 * baud); 275 int abs_diff_13 = calculate_baud_abs_diff(port, baud, 13);
256 unsigned int n16 = port->uartclk / (16 * baud); 276 int abs_diff_16 = calculate_baud_abs_diff(port, baud, 16);
257 int baudAbsDiff13; 277
258 int baudAbsDiff16; 278 return (abs_diff_13 >= abs_diff_16);
259
260 if (n13 == 0)
261 n13 = 1;
262 if (n16 == 0)
263 n16 = 1;
264
265 baudAbsDiff13 = baud - (port->uartclk / (13 * n13));
266 baudAbsDiff16 = baud - (port->uartclk / (16 * n16));
267 if (baudAbsDiff13 < 0)
268 baudAbsDiff13 = -baudAbsDiff13;
269 if (baudAbsDiff16 < 0)
270 baudAbsDiff16 = -baudAbsDiff16;
271
272 return (baudAbsDiff13 >= baudAbsDiff16);
273} 279}
274 280
275/* 281/*