mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Andrey Smirnov <andrew.smirnov@gmail.com>
To: barebox@lists.infradead.org
Cc: Andrey Smirnov <andrew.smirnov@gmail.com>
Subject: [PATCH 3/8] i.MX: serial: Add baud rate calculation convenience functions
Date: Sat,  2 May 2015 19:26:15 -0700	[thread overview]
Message-ID: <1430619980-26243-4-git-send-email-andrew.smirnov@gmail.com> (raw)
In-Reply-To: <1430619980-26243-1-git-send-email-andrew.smirnov@gmail.com>

Add two functions to calculate values for UBMR and UBIR
registers. This way both early serial initalization code and
serial_imx.c can use them and not duplicate the code.

Singed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 arch/arm/mach-imx/include/mach/serial.h | 9 +++++++++
 drivers/serial/serial_imx.c             | 4 ++--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-imx/include/mach/serial.h b/arch/arm/mach-imx/include/mach/serial.h
index 3890fd5..212eeeb 100644
--- a/arch/arm/mach-imx/include/mach/serial.h
+++ b/arch/arm/mach-imx/include/mach/serial.h
@@ -115,5 +115,14 @@
 #define  UTS_RXFULL 	 (1<<3)	 /* RxFIFO full */
 #define  UTS_SOFTRST	 (1<<0)	 /* Software reset */

+static inline int baudrate_to_ubir(int baudrate)
+{
+	return baudrate / 100 - 1;
+}
+
+static inline int refclock_to_ubmr(int clock_hz)
+{
+	return clock_hz / 1600 - 1;
+}

 #endif	/* __MACH_SERIAL_H__ */
diff --git a/drivers/serial/serial_imx.c b/drivers/serial/serial_imx.c
index e197be8..8c4e829 100644
--- a/drivers/serial/serial_imx.c
+++ b/drivers/serial/serial_imx.c
@@ -178,9 +178,9 @@ static int imx_serial_setbaudrate(struct console_device *cdev, int baudrate)
 	writel(val, regs + UCR1);

 	/* Set the numerator value minus one of the BRM ratio */
-	writel((baudrate / 100) - 1, regs + UBIR);
+	writel(baudrate_to_ubir(baudrate), regs + UBIR);
 	/* Set the denominator value minus one of the BRM ratio    */
-	writel((imx_serial_reffreq(priv) / 1600) - 1, regs + UBMR);
+	writel(refclock_to_ubmr(imx_serial_reffreq(priv)), regs + UBMR);

 	writel(ucr1, regs + UCR1);

--
2.1.4

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2015-05-03  2:27 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-03  2:26 [RFC, PATCH] i.MX: Add provisions to boot from IRAM Andrey Smirnov
2015-05-03  2:26 ` [PATCH 1/8] i.MX: Move UART definitions into a separate file Andrey Smirnov
2015-05-04  7:08   ` Sascha Hauer
2015-05-03  2:26 ` [PATCH 2/8] i.MX: serial: Add constants for UART clock divisor Andrey Smirnov
2015-05-03  2:26 ` Andrey Smirnov [this message]
2015-05-03  2:26 ` [PATCH 4/8] i.MX51: babbage: Implement CONFIG_DEBUG_LL Andrey Smirnov
2015-05-04  6:43   ` Sascha Hauer
2015-05-03  2:26 ` [PATCH 5/8] i.MX: serial: Add setup_uart_ll function Andrey Smirnov
2015-05-04  6:53   ` Sascha Hauer
2015-05-03  2:26 ` [PATCH 6/8] i.MX: serial: Convert i.MX51 and i.MX6 to use 'setup_uart_ll' Andrey Smirnov
2015-05-04  6:57   ` Sascha Hauer
2015-05-03  2:26 ` [PATCH 7/8] i.MX: serial: Distil common clock ungating code Andrey Smirnov
2015-05-04  7:01   ` Sascha Hauer
2015-05-04 18:04     ` Andrey Smirnov
2015-05-04 19:52       ` Sascha Hauer
2015-05-03  2:26 ` [PATCH 8/8] Makefile.lib: Make 'check_file_size' more flexible Andrey Smirnov
2015-05-04  7:14 ` [RFC, PATCH] i.MX: Add provisions to boot from IRAM Sascha Hauer

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=1430619980-26243-4-git-send-email-andrew.smirnov@gmail.com \
    --to=andrew.smirnov@gmail.com \
    --cc=barebox@lists.infradead.org \
    /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