From: Jagan Teki <jagannadh.teki@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 5/7] serial: mxc: Move common baud gen into _mxc_serial_setbrg
Date: Tue, 6 Jun 2017 05:31:49 +0000 [thread overview]
Message-ID: <1496727111-3655-6-git-send-email-jteki@openedev.com> (raw)
In-Reply-To: <1496727111-3655-1-git-send-email-jteki@openedev.com>
From: Jagan Teki <jagan@amarulasolutions.com>
Move the common baud generation code into _mxc_serial_setbrg
so-that dm and non-dm can call this func.
Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>
---
drivers/serial/serial_mxc.c | 50 ++++++++++++++++++++++-----------------------
1 file changed, 24 insertions(+), 26 deletions(-)
diff --git a/drivers/serial/serial_mxc.c b/drivers/serial/serial_mxc.c
index 4b19052..0fd3aaa 100644
--- a/drivers/serial/serial_mxc.c
+++ b/drivers/serial/serial_mxc.c
@@ -108,6 +108,8 @@
#define UTS_TXFULL (1<<4) /* TxFIFO full */
#define UTS_RXFULL (1<<3) /* RxFIFO full */
#define UTS_SOFTRS (1<<0) /* Software reset */
+#define TXTL 2 /* reset default */
+#define RXTL 1 /* reset default */
DECLARE_GLOBAL_DATA_PTR;
@@ -152,6 +154,26 @@ static void _mxc_serial_init(struct mxc_uart *base)
writel(0, &base->ts);
}
+static void _mxc_serial_setbrg(struct mxc_uart *base, unsigned long clk,
+ unsigned long baudrate, bool use_dte)
+{
+ u32 tmp;
+
+ tmp = RFDIV << UFCR_RFDIV_SHF;
+ if (use_dte)
+ tmp |= UFCR_DCEDTE;
+ else
+ tmp |= (TXTL << UFCR_TXTL_SHF) | (RXTL << UFCR_RXTL_SHF);
+ writel(tmp, &base->fcr);
+
+ writel(0xf, &base->bir);
+ writel(clk / (2 * baudrate), &base->bmr);
+
+ writel(UCR2_WS | UCR2_IRTS | UCR2_RXEN | UCR2_TXEN | UCR2_SRST,
+ &base->cr2);
+ writel(UCR1_UARTEN, &base->cr1);
+}
+
#ifndef CONFIG_DM_SERIAL
#ifndef CONFIG_MXC_UART_BASE
@@ -160,9 +182,6 @@ static void _mxc_serial_init(struct mxc_uart *base)
#define mxc_base ((struct mxc_uart *)CONFIG_MXC_UART_BASE)
-#define TXTL 2 /* reset default */
-#define RXTL 1 /* reset default */
-
static void mxc_serial_setbrg(void)
{
u32 clk = imx_get_uartclk();
@@ -170,16 +189,7 @@ static void mxc_serial_setbrg(void)
if (!gd->baudrate)
gd->baudrate = CONFIG_BAUDRATE;
- writel(((RFDIV << UFCR_RFDIV_SHF) |
- (TXTL << UFCR_TXTL_SHF) |
- (RXTL << UFCR_RXTL_SHF)),
- &mxc_base->fcr);
- writel(0xf, &mxc_base->bir);
- writel(clk / (2 * gd->baudrate), &mxc_base->bmr);
-
- writel(UCR2_WS | UCR2_IRTS | UCR2_RXEN | UCR2_TXEN | UCR2_SRST,
- &mxc_base->cr2);
- writel(UCR1_UARTEN, &mxc_base->cr1);
+ _mxc_serial_setbrg(mxc_base, clk, gd->baudrate, false);
}
static int mxc_serial_getc(void)
@@ -254,21 +264,9 @@ __weak struct serial_device *default_serial_console(void)
int mxc_serial_setbrg(struct udevice *dev, int baudrate)
{
struct mxc_serial_platdata *plat = dev->platdata;
- struct mxc_uart *const uart = plat->reg;
u32 clk = imx_get_uartclk();
- u32 tmp;
- tmp = RFDIV << UFCR_RFDIV_SHF;
- if (plat->use_dte)
- tmp |= UFCR_DCEDTE;
- writel(tmp, &uart->fcr);
-
- writel(0xf, &uart->bir);
- writel(clk / (2 * baudrate), &uart->bmr);
-
- writel(UCR2_WS | UCR2_IRTS | UCR2_RXEN | UCR2_TXEN | UCR2_SRST,
- &uart->cr2);
- writel(UCR1_UARTEN, &uart->cr1);
+ _mxc_serial_setbrg(plat->reg, clk, baudrate, plat->use_dte);
return 0;
}
--
1.9.1
next prev parent reply other threads:[~2017-06-06 5:31 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-06 5:31 [U-Boot] [PATCH 0/7] serial: mxc: Add debug uart support Jagan Teki
2017-06-06 5:31 ` [U-Boot] [PATCH 1/7] serial: mxc: Add common mxc_uart reg space Jagan Teki
2017-06-06 21:08 ` Simon Glass
2017-06-29 8:28 ` Stefano Babic
2017-06-06 5:31 ` [U-Boot] [PATCH 2/7] serial: mxc: Use RFDIV in dm-code Jagan Teki
2017-06-06 21:08 ` Simon Glass
2017-06-06 5:31 ` [U-Boot] [PATCH 3/7] serial: mxc: Move cr1 and cr2 write to mxc_serial_setbrg Jagan Teki
2017-06-06 21:09 ` Simon Glass
2017-06-06 5:31 ` [U-Boot] [PATCH 4/7] serial: mxc: Move common init into _mxc_serial_init Jagan Teki
2017-06-06 21:09 ` Simon Glass
2017-06-06 5:31 ` Jagan Teki [this message]
2017-06-06 21:09 ` [U-Boot] [PATCH 5/7] serial: mxc: Move common baud gen into _mxc_serial_setbrg Simon Glass
2017-06-06 5:31 ` [U-Boot] [PATCH 6/7] serial: mxc: Code cleanup Jagan Teki
2017-06-06 21:09 ` Simon Glass
2017-06-06 5:31 ` [U-Boot] [PATCH 7/7] serial: mxc: Add debug uart support Jagan Teki
2017-06-06 21:09 ` Simon Glass
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=1496727111-3655-6-git-send-email-jteki@openedev.com \
--to=jagannadh.teki@gmail.com \
--cc=u-boot@lists.denx.de \
/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