Commit 2b5a9973 authored by Baolin Wang's avatar Baolin Wang Committed by Greg Kroah-Hartman

serial: sprd: Use readable macros instead of magic number

Define readable macros instead of magic number to make code more readable.
Signed-off-by: default avatarBaolin Wang <baolin.wang@linaro.org>
Acked-by: default avatarChunyan Zhang <chunyan.zhang@spreadtrum.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 20464f3a
...@@ -45,6 +45,8 @@ ...@@ -45,6 +45,8 @@
/* data number in TX and RX fifo */ /* data number in TX and RX fifo */
#define SPRD_STS1 0x000C #define SPRD_STS1 0x000C
#define SPRD_RX_FIFO_CNT_MASK GENMASK(7, 0)
#define SPRD_TX_FIFO_CNT_MASK GENMASK(15, 8)
/* interrupt enable register and its BITs */ /* interrupt enable register and its BITs */
#define SPRD_IEN 0x0010 #define SPRD_IEN 0x0010
...@@ -82,11 +84,15 @@ ...@@ -82,11 +84,15 @@
/* fifo threshold register */ /* fifo threshold register */
#define SPRD_CTL2 0x0020 #define SPRD_CTL2 0x0020
#define THLD_TX_EMPTY 0x40 #define THLD_TX_EMPTY 0x40
#define THLD_TX_EMPTY_SHIFT 8
#define THLD_RX_FULL 0x40 #define THLD_RX_FULL 0x40
/* config baud rate register */ /* config baud rate register */
#define SPRD_CLKD0 0x0024 #define SPRD_CLKD0 0x0024
#define SPRD_CLKD0_MASK GENMASK(15, 0)
#define SPRD_CLKD1 0x0028 #define SPRD_CLKD1 0x0028
#define SPRD_CLKD1_MASK GENMASK(20, 16)
#define SPRD_CLKD1_SHIFT 16
/* interrupt mask status register */ /* interrupt mask status register */
#define SPRD_IMSR 0x002C #define SPRD_IMSR 0x002C
...@@ -115,7 +121,7 @@ static inline void serial_out(struct uart_port *port, int offset, int value) ...@@ -115,7 +121,7 @@ static inline void serial_out(struct uart_port *port, int offset, int value)
static unsigned int sprd_tx_empty(struct uart_port *port) static unsigned int sprd_tx_empty(struct uart_port *port)
{ {
if (serial_in(port, SPRD_STS1) & 0xff00) if (serial_in(port, SPRD_STS1) & SPRD_TX_FIFO_CNT_MASK)
return 0; return 0;
else else
return TIOCSER_TEMT; return TIOCSER_TEMT;
...@@ -213,7 +219,8 @@ static inline void sprd_rx(struct uart_port *port) ...@@ -213,7 +219,8 @@ static inline void sprd_rx(struct uart_port *port)
struct tty_port *tty = &port->state->port; struct tty_port *tty = &port->state->port;
unsigned int ch, flag, lsr, max_count = SPRD_TIMEOUT; unsigned int ch, flag, lsr, max_count = SPRD_TIMEOUT;
while ((serial_in(port, SPRD_STS1) & 0x00ff) && max_count--) { while ((serial_in(port, SPRD_STS1) & SPRD_RX_FIFO_CNT_MASK) &&
max_count--) {
lsr = serial_in(port, SPRD_LSR); lsr = serial_in(port, SPRD_LSR);
ch = serial_in(port, SPRD_RXD); ch = serial_in(port, SPRD_RXD);
flag = TTY_NORMAL; flag = TTY_NORMAL;
...@@ -303,16 +310,17 @@ static int sprd_startup(struct uart_port *port) ...@@ -303,16 +310,17 @@ static int sprd_startup(struct uart_port *port)
struct sprd_uart_port *sp; struct sprd_uart_port *sp;
unsigned long flags; unsigned long flags;
serial_out(port, SPRD_CTL2, ((THLD_TX_EMPTY << 8) | THLD_RX_FULL)); serial_out(port, SPRD_CTL2,
THLD_TX_EMPTY << THLD_TX_EMPTY_SHIFT | THLD_RX_FULL);
/* clear rx fifo */ /* clear rx fifo */
timeout = SPRD_TIMEOUT; timeout = SPRD_TIMEOUT;
while (timeout-- && serial_in(port, SPRD_STS1) & 0x00ff) while (timeout-- && serial_in(port, SPRD_STS1) & SPRD_RX_FIFO_CNT_MASK)
serial_in(port, SPRD_RXD); serial_in(port, SPRD_RXD);
/* clear tx fifo */ /* clear tx fifo */
timeout = SPRD_TIMEOUT; timeout = SPRD_TIMEOUT;
while (timeout-- && serial_in(port, SPRD_STS1) & 0xff00) while (timeout-- && serial_in(port, SPRD_STS1) & SPRD_TX_FIFO_CNT_MASK)
cpu_relax(); cpu_relax();
/* clear interrupt */ /* clear interrupt */
...@@ -433,10 +441,11 @@ static void sprd_set_termios(struct uart_port *port, ...@@ -433,10 +441,11 @@ static void sprd_set_termios(struct uart_port *port,
} }
/* clock divider bit0~bit15 */ /* clock divider bit0~bit15 */
serial_out(port, SPRD_CLKD0, quot & 0xffff); serial_out(port, SPRD_CLKD0, quot & SPRD_CLKD0_MASK);
/* clock divider bit16~bit20 */ /* clock divider bit16~bit20 */
serial_out(port, SPRD_CLKD1, (quot & 0x1f0000) >> 16); serial_out(port, SPRD_CLKD1,
(quot & SPRD_CLKD1_MASK) >> SPRD_CLKD1_SHIFT);
serial_out(port, SPRD_LCR, lcr); serial_out(port, SPRD_LCR, lcr);
fc |= RX_TOUT_THLD_DEF | RX_HFC_THLD_DEF; fc |= RX_TOUT_THLD_DEF | RX_HFC_THLD_DEF;
serial_out(port, SPRD_CTL1, fc); serial_out(port, SPRD_CTL1, fc);
...@@ -510,7 +519,7 @@ static void wait_for_xmitr(struct uart_port *port) ...@@ -510,7 +519,7 @@ static void wait_for_xmitr(struct uart_port *port)
if (--tmout == 0) if (--tmout == 0)
break; break;
udelay(1); udelay(1);
} while (status & 0xff00); } while (status & SPRD_TX_FIFO_CNT_MASK);
} }
static void sprd_console_putchar(struct uart_port *port, int ch) static void sprd_console_putchar(struct uart_port *port, int ch)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment