From: Chunyan Zhang <zhang.lyra@gmail.com>
To: Baolin Wang <baolin.wang@linaro.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
jslaby@suse.com, Orson Zhai <orsonzhai@gmail.com>,
Mark Brown <broonie@kernel.org>,
linux-serial@vger.kernel.org,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/5] serial: sprd: Use readable macros instead of magic number
Date: Tue, 4 Sep 2018 14:54:28 +0800 [thread overview]
Message-ID: <CAAfSe-tQAKN4+cd2uD=KFkt_PPNMdGwZM-3QHBE3x81c5GskMA@mail.gmail.com> (raw)
In-Reply-To: <7b3341ab8778d31bf564bdcbb04b8c6e09fa4d6d.1533950271.git.baolin.wang@linaro.org>
On 11 August 2018 at 09:34, Baolin Wang <baolin.wang@linaro.org> wrote:
> Define readable macros instead of magic number to make code more readable.
>
> Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
Acked-by: Chunyan Zhang <chunyan.zhang@spreadtrum.com>
> ---
> drivers/tty/serial/sprd_serial.c | 25 +++++++++++++++++--------
> 1 file changed, 17 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/tty/serial/sprd_serial.c b/drivers/tty/serial/sprd_serial.c
> index 1b0e3fb..e18d8af 100644
> --- a/drivers/tty/serial/sprd_serial.c
> +++ b/drivers/tty/serial/sprd_serial.c
> @@ -45,6 +45,8 @@
>
> /* data number in TX and RX fifo */
> #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 */
> #define SPRD_IEN 0x0010
> @@ -82,11 +84,15 @@
> /* fifo threshold register */
> #define SPRD_CTL2 0x0020
> #define THLD_TX_EMPTY 0x40
> +#define THLD_TX_EMPTY_SHIFT 8
> #define THLD_RX_FULL 0x40
>
> /* config baud rate register */
> #define SPRD_CLKD0 0x0024
> +#define SPRD_CLKD0_MASK GENMASK(15, 0)
> #define SPRD_CLKD1 0x0028
> +#define SPRD_CLKD1_MASK GENMASK(20, 16)
> +#define SPRD_CLKD1_SHIFT 16
>
> /* interrupt mask status register */
> #define SPRD_IMSR 0x002C
> @@ -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)
> {
> - if (serial_in(port, SPRD_STS1) & 0xff00)
> + if (serial_in(port, SPRD_STS1) & SPRD_TX_FIFO_CNT_MASK)
> return 0;
> else
> return TIOCSER_TEMT;
> @@ -213,7 +219,8 @@ static inline void sprd_rx(struct uart_port *port)
> struct tty_port *tty = &port->state->port;
> 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);
> ch = serial_in(port, SPRD_RXD);
> flag = TTY_NORMAL;
> @@ -303,16 +310,17 @@ static int sprd_startup(struct uart_port *port)
> struct sprd_uart_port *sp;
> 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 */
> 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);
>
> /* clear tx fifo */
> 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();
>
> /* clear interrupt */
> @@ -433,10 +441,11 @@ static void sprd_set_termios(struct uart_port *port,
> }
>
> /* clock divider bit0~bit15 */
> - serial_out(port, SPRD_CLKD0, quot & 0xffff);
> + serial_out(port, SPRD_CLKD0, quot & SPRD_CLKD0_MASK);
>
> /* 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);
> fc |= RX_TOUT_THLD_DEF | RX_HFC_THLD_DEF;
> serial_out(port, SPRD_CTL1, fc);
> @@ -510,7 +519,7 @@ static void wait_for_xmitr(struct uart_port *port)
> if (--tmout == 0)
> break;
> udelay(1);
> - } while (status & 0xff00);
> + } while (status & SPRD_TX_FIFO_CNT_MASK);
> }
>
> static void sprd_console_putchar(struct uart_port *port, int ch)
> --
> 1.9.1
>
next prev parent reply other threads:[~2018-09-04 6:55 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-11 1:34 [PATCH 1/5] serial: sprd: Remove unused structure Baolin Wang
2018-08-11 1:34 ` [PATCH 2/5] serial: sprd: Use readable macros instead of magic number Baolin Wang
2018-09-04 6:54 ` Chunyan Zhang [this message]
2018-08-11 1:34 ` [PATCH 3/5] serial: sprd: Remove unnecessary resource validation Baolin Wang
2018-09-04 6:55 ` Chunyan Zhang
2018-08-11 1:34 ` [PATCH 4/5] serial: sprd: Change 'int' to 'unsigned int' Baolin Wang
2018-09-04 6:55 ` Chunyan Zhang
2018-08-11 1:34 ` [PATCH 5/5] serial: sprd: Fix the indentation issue Baolin Wang
2018-09-04 6:57 ` Chunyan Zhang
2018-09-04 5:34 ` [PATCH 1/5] serial: sprd: Remove unused structure Baolin Wang
2018-09-04 6:52 ` Chunyan Zhang
2018-09-11 6:09 ` Baolin Wang
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='CAAfSe-tQAKN4+cd2uD=KFkt_PPNMdGwZM-3QHBE3x81c5GskMA@mail.gmail.com' \
--to=zhang.lyra@gmail.com \
--cc=baolin.wang@linaro.org \
--cc=broonie@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=jslaby@suse.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=orsonzhai@gmail.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.