From: Andrew Jones <ajones@ventanamicro.com>
To: opensbi@lists.infradead.org
Subject: [PATCH 3/4] lib: serial: Clean up coding style in sifive-uart.c
Date: Mon, 18 Jul 2022 19:20:27 +0200 [thread overview]
Message-ID: <20220718172028.2006166-4-ajones@ventanamicro.com> (raw)
In-Reply-To: <20220718172028.2006166-1-ajones@ventanamicro.com>
Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
---
lib/utils/serial/sifive-uart.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/lib/utils/serial/sifive-uart.c b/lib/utils/serial/sifive-uart.c
index 9478a77f8054..7078611a5274 100644
--- a/lib/utils/serial/sifive-uart.c
+++ b/lib/utils/serial/sifive-uart.c
@@ -48,12 +48,12 @@ static inline unsigned int uart_min_clk_divisor(uint64_t in_freq,
uint64_t max_target_hz)
{
uint64_t quotient = (in_freq + max_target_hz - 1) / (max_target_hz);
+
/* Avoid underflow */
- if (quotient == 0) {
+ if (quotient == 0)
return 0;
- } else {
+ else
return quotient - 1;
- }
}
static u32 get_reg(u32 num)
@@ -77,8 +77,10 @@ static void sifive_uart_putc(char ch)
static int sifive_uart_getc(void)
{
u32 ret = get_reg(UART_REG_RXFIFO);
+
if (!(ret & UART_RXFIFO_EMPTY))
return ret & UART_RXFIFO_DATA;
+
return -1;
}
@@ -97,10 +99,13 @@ int sifive_uart_init(unsigned long base, u32 in_freq, u32 baudrate)
/* Configure baudrate */
if (in_freq)
set_reg(UART_REG_DIV, uart_min_clk_divisor(in_freq, baudrate));
+
/* Disable interrupts */
set_reg(UART_REG_IE, 0);
+
/* Enable TX */
set_reg(UART_REG_TXCTRL, UART_TXCTRL_TXEN);
+
/* Enable Rx */
set_reg(UART_REG_RXCTRL, UART_RXCTRL_RXEN);
--
2.36.1
next prev parent reply other threads:[~2022-07-18 17:20 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-18 17:20 [PATCH 0/4] lib: utils/serial: Collection of UART code improvements Andrew Jones
2022-07-18 17:20 ` [PATCH 1/4] lib: utils/fdt: Factor out common uart node code Andrew Jones
2022-07-30 5:24 ` Anup Patel
2022-07-30 10:19 ` Anup Patel
2022-07-18 17:20 ` [PATCH 2/4] lib: utils/serial: Initialize platform_uart_data to zero Andrew Jones
2022-07-18 17:42 ` Jessica Clarke
2022-07-18 18:35 ` Andrew Jones
2022-07-18 18:39 ` Jessica Clarke
2022-07-19 10:30 ` Andrew Jones
2022-07-30 5:25 ` Anup Patel
2022-07-30 10:20 ` Anup Patel
2022-07-18 17:20 ` Andrew Jones [this message]
2022-07-20 15:13 ` [PATCH 3/4] lib: serial: Clean up coding style in sifive-uart.c Xiang W
2022-07-30 5:27 ` Anup Patel
2022-07-30 10:20 ` Anup Patel
2022-07-18 17:20 ` [PATCH 4/4] lib: utils/serial: Ensure baudrate is non-zero before using Andrew Jones
2022-07-20 15:12 ` Xiang W
2022-07-20 17:16 ` Andrew Jones
2022-07-20 17:25 ` Xiang W
2022-07-21 5:35 ` Andrew Jones
2022-07-30 5:31 ` Anup Patel
2022-07-30 10:21 ` Anup Patel
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=20220718172028.2006166-4-ajones@ventanamicro.com \
--to=ajones@ventanamicro.com \
--cc=opensbi@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