serial: lpuart: Prepare the driver for DM conversion

Create internal routines which take lpuart's register base as
a parameter, in preparation for driver model conversion.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Acked-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Bin Meng 2016-01-13 19:39:03 -08:00 committed by Simon Glass
parent ed3021af5c
commit 6ca13b1239

View File

@ -50,22 +50,19 @@ DECLARE_GLOBAL_DATA_PTR;
struct lpuart_fsl *base = (struct lpuart_fsl *)LPUART_BASE; struct lpuart_fsl *base = (struct lpuart_fsl *)LPUART_BASE;
#ifndef CONFIG_LPUART_32B_REG #ifndef CONFIG_LPUART_32B_REG
static void lpuart_serial_setbrg(void) static void _lpuart_serial_setbrg(struct lpuart_fsl *base, int baudrate)
{ {
u32 clk = mxc_get_clock(MXC_UART_CLK); u32 clk = mxc_get_clock(MXC_UART_CLK);
u16 sbr; u16 sbr;
if (!gd->baudrate) sbr = (u16)(clk / (16 * baudrate));
gd->baudrate = CONFIG_BAUDRATE;
sbr = (u16)(clk / (16 * gd->baudrate));
/* place adjustment later - n/32 BRFA */ /* place adjustment later - n/32 BRFA */
__raw_writeb(sbr >> 8, &base->ubdh); __raw_writeb(sbr >> 8, &base->ubdh);
__raw_writeb(sbr & 0xff, &base->ubdl); __raw_writeb(sbr & 0xff, &base->ubdl);
} }
static int lpuart_serial_getc(void) static int _lpuart_serial_getc(struct lpuart_fsl *base)
{ {
while (!(__raw_readb(&base->us1) & (US1_RDRF | US1_OR))) while (!(__raw_readb(&base->us1) & (US1_RDRF | US1_OR)))
WATCHDOG_RESET(); WATCHDOG_RESET();
@ -75,10 +72,10 @@ static int lpuart_serial_getc(void)
return __raw_readb(&base->ud); return __raw_readb(&base->ud);
} }
static void lpuart_serial_putc(const char c) static void _lpuart_serial_putc(struct lpuart_fsl *base, const char c)
{ {
if (c == '\n') if (c == '\n')
lpuart_serial_putc('\r'); _lpuart_serial_putc(base, '\r');
while (!(__raw_readb(&base->us1) & US1_TDRE)) while (!(__raw_readb(&base->us1) & US1_TDRE))
WATCHDOG_RESET(); WATCHDOG_RESET();
@ -87,7 +84,7 @@ static void lpuart_serial_putc(const char c)
} }
/* Test whether a character is in the RX buffer */ /* Test whether a character is in the RX buffer */
static int lpuart_serial_tstc(void) static int _lpuart_serial_tstc(struct lpuart_fsl *base)
{ {
if (__raw_readb(&base->urcfifo) == 0) if (__raw_readb(&base->urcfifo) == 0)
return 0; return 0;
@ -99,7 +96,7 @@ static int lpuart_serial_tstc(void)
* Initialise the serial port with the given baudrate. The settings * Initialise the serial port with the given baudrate. The settings
* are always 8 data bits, no parity, 1 stop bit, no start bits. * are always 8 data bits, no parity, 1 stop bit, no start bits.
*/ */
static int lpuart_serial_init(void) static int _lpuart_serial_init(struct lpuart_fsl *base)
{ {
u8 ctrl; u8 ctrl;
@ -118,13 +115,38 @@ static int lpuart_serial_init(void)
__raw_writeb(CFIFO_TXFLUSH | CFIFO_RXFLUSH, &base->ucfifo); __raw_writeb(CFIFO_TXFLUSH | CFIFO_RXFLUSH, &base->ucfifo);
/* provide data bits, parity, stop bit, etc */ /* provide data bits, parity, stop bit, etc */
lpuart_serial_setbrg(); _lpuart_serial_setbrg(base, gd->baudrate);
__raw_writeb(UC2_RE | UC2_TE, &base->uc2); __raw_writeb(UC2_RE | UC2_TE, &base->uc2);
return 0; return 0;
} }
static void lpuart_serial_setbrg(void)
{
_lpuart_serial_setbrg(base, gd->baudrate);
}
static int lpuart_serial_getc(void)
{
return _lpuart_serial_getc(base);
}
static void lpuart_serial_putc(const char c)
{
_lpuart_serial_putc(base, c);
}
static int lpuart_serial_tstc(void)
{
return _lpuart_serial_tstc(base);
}
static int lpuart_serial_init(void)
{
return _lpuart_serial_init(base);
}
static struct serial_device lpuart_serial_drv = { static struct serial_device lpuart_serial_drv = {
.name = "lpuart_serial", .name = "lpuart_serial",
.start = lpuart_serial_init, .start = lpuart_serial_init,
@ -136,21 +158,18 @@ static struct serial_device lpuart_serial_drv = {
.tstc = lpuart_serial_tstc, .tstc = lpuart_serial_tstc,
}; };
#else #else
static void lpuart32_serial_setbrg(void) static void _lpuart32_serial_setbrg(struct lpuart_fsl *base, int baudrate)
{ {
u32 clk = CONFIG_SYS_CLK_FREQ; u32 clk = CONFIG_SYS_CLK_FREQ;
u32 sbr; u32 sbr;
if (!gd->baudrate) sbr = (clk / (16 * baudrate));
gd->baudrate = CONFIG_BAUDRATE;
sbr = (clk / (16 * gd->baudrate));
/* place adjustment later - n/32 BRFA */ /* place adjustment later - n/32 BRFA */
out_be32(&base->baud, sbr); out_be32(&base->baud, sbr);
} }
static int lpuart32_serial_getc(void) static int _lpuart32_serial_getc(struct lpuart_fsl *base)
{ {
u32 stat; u32 stat;
@ -162,10 +181,10 @@ static int lpuart32_serial_getc(void)
return in_be32(&base->data) & 0x3ff; return in_be32(&base->data) & 0x3ff;
} }
static void lpuart32_serial_putc(const char c) static void _lpuart32_serial_putc(struct lpuart_fsl *base, const char c)
{ {
if (c == '\n') if (c == '\n')
lpuart32_serial_putc('\r'); _lpuart32_serial_putc(base, '\r');
while (!(in_be32(&base->stat) & STAT_TDRE)) while (!(in_be32(&base->stat) & STAT_TDRE))
WATCHDOG_RESET(); WATCHDOG_RESET();
@ -174,7 +193,7 @@ static void lpuart32_serial_putc(const char c)
} }
/* Test whether a character is in the RX buffer */ /* Test whether a character is in the RX buffer */
static int lpuart32_serial_tstc(void) static int _lpuart32_serial_tstc(struct lpuart_fsl *base)
{ {
if ((in_be32(&base->water) >> 24) == 0) if ((in_be32(&base->water) >> 24) == 0)
return 0; return 0;
@ -186,7 +205,7 @@ static int lpuart32_serial_tstc(void)
* Initialise the serial port with the given baudrate. The settings * Initialise the serial port with the given baudrate. The settings
* are always 8 data bits, no parity, 1 stop bit, no start bits. * are always 8 data bits, no parity, 1 stop bit, no start bits.
*/ */
static int lpuart32_serial_init(void) static int _lpuart32_serial_init(struct lpuart_fsl *base)
{ {
u8 ctrl; u8 ctrl;
@ -201,13 +220,38 @@ static int lpuart32_serial_init(void)
out_be32(&base->match, 0); out_be32(&base->match, 0);
/* provide data bits, parity, stop bit, etc */ /* provide data bits, parity, stop bit, etc */
lpuart32_serial_setbrg(); _lpuart32_serial_setbrg(base, gd->baudrate);
out_be32(&base->ctrl, CTRL_RE | CTRL_TE); out_be32(&base->ctrl, CTRL_RE | CTRL_TE);
return 0; return 0;
} }
static void lpuart32_serial_setbrg(void)
{
_lpuart32_serial_setbrg(base, gd->baudrate);
}
static int lpuart32_serial_getc(void)
{
return _lpuart32_serial_getc(base);
}
static void lpuart32_serial_putc(const char c)
{
_lpuart32_serial_putc(base, c);
}
static int lpuart32_serial_tstc(void)
{
return _lpuart32_serial_tstc(base);
}
static int lpuart32_serial_init(void)
{
return _lpuart32_serial_init(base);
}
static struct serial_device lpuart32_serial_drv = { static struct serial_device lpuart32_serial_drv = {
.name = "lpuart32_serial", .name = "lpuart32_serial",
.start = lpuart32_serial_init, .start = lpuart32_serial_init,