Skip to content

Commit 650c8bd

Browse files
diandersandersson
authored andcommitted
serial: qcom_geni_serial: Always use 4 bytes per TX FIFO word
The geni serial driver had a rule that we'd only use 1 byte per FIFO word for the TX FIFO if we were being used for the serial console. This is ugly and a bit of a pain. It's not too hard to fix, so fix it. Acked-by: Greg Kroah-Hartman <[email protected]> Reviewed-by: Evan Green <[email protected]> Signed-off-by: Douglas Anderson <[email protected]> Link: https://lore.kernel.org/r/20200626125844.2.Iabd56347670b9e4e916422773aba5b27943d19ee@changeid Signed-off-by: Bjorn Andersson <[email protected]>
1 parent e42d6c3 commit 650c8bd

File tree

1 file changed

+37
-20
lines changed

1 file changed

+37
-20
lines changed

drivers/tty/serial/qcom_geni_serial.c

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,18 @@
103103
#define DEFAULT_IO_MACRO_IO2_IO3_MASK GENMASK(15, 4)
104104
#define IO_MACRO_IO2_IO3_SWAP 0x4640
105105

106+
/* We always configure 4 bytes per FIFO word */
107+
#define BYTES_PER_FIFO_WORD 4
108+
106109
struct qcom_geni_private_data {
107110
/* NOTE: earlycon port will have NULL here */
108111
struct uart_driver *drv;
109112

110113
u32 poll_cached_bytes;
111114
unsigned int poll_cached_bytes_cnt;
115+
116+
u32 write_cached_bytes;
117+
unsigned int write_cached_bytes_cnt;
112118
};
113119

114120
struct qcom_geni_serial_port {
@@ -121,8 +127,6 @@ struct qcom_geni_serial_port {
121127
bool setup;
122128
int (*handle_rx)(struct uart_port *uport, u32 bytes, bool drop);
123129
unsigned int baud;
124-
unsigned int tx_bytes_pw;
125-
unsigned int rx_bytes_pw;
126130
void *rx_fifo;
127131
u32 loopback;
128132
bool brk;
@@ -390,13 +394,25 @@ static void qcom_geni_serial_poll_put_char(struct uart_port *uport,
390394
#ifdef CONFIG_SERIAL_QCOM_GENI_CONSOLE
391395
static void qcom_geni_serial_wr_char(struct uart_port *uport, int ch)
392396
{
393-
writel(ch, uport->membase + SE_GENI_TX_FIFOn);
397+
struct qcom_geni_private_data *private_data = uport->private_data;
398+
399+
private_data->write_cached_bytes =
400+
(private_data->write_cached_bytes >> 8) | (ch << 24);
401+
private_data->write_cached_bytes_cnt++;
402+
403+
if (private_data->write_cached_bytes_cnt == BYTES_PER_FIFO_WORD) {
404+
writel(private_data->write_cached_bytes,
405+
uport->membase + SE_GENI_TX_FIFOn);
406+
private_data->write_cached_bytes_cnt = 0;
407+
}
394408
}
395409

396410
static void
397411
__qcom_geni_serial_console_write(struct uart_port *uport, const char *s,
398412
unsigned int count)
399413
{
414+
struct qcom_geni_private_data *private_data = uport->private_data;
415+
400416
int i;
401417
u32 bytes_to_send = count;
402418

@@ -431,6 +447,15 @@ __qcom_geni_serial_console_write(struct uart_port *uport, const char *s,
431447
SE_GENI_M_IRQ_CLEAR);
432448
i += chars_to_write;
433449
}
450+
451+
if (private_data->write_cached_bytes_cnt) {
452+
private_data->write_cached_bytes >>= BITS_PER_BYTE *
453+
(BYTES_PER_FIFO_WORD - private_data->write_cached_bytes_cnt);
454+
writel(private_data->write_cached_bytes,
455+
uport->membase + SE_GENI_TX_FIFOn);
456+
private_data->write_cached_bytes_cnt = 0;
457+
}
458+
434459
qcom_geni_serial_poll_tx_done(uport);
435460
}
436461

@@ -503,7 +528,7 @@ static int handle_rx_console(struct uart_port *uport, u32 bytes, bool drop)
503528
tport = &uport->state->port;
504529
for (i = 0; i < bytes; ) {
505530
int c;
506-
int chunk = min_t(int, bytes - i, port->rx_bytes_pw);
531+
int chunk = min_t(int, bytes - i, BYTES_PER_FIFO_WORD);
507532

508533
ioread32_rep(uport->membase + SE_GENI_RX_FIFOn, buf, 1);
509534
i += chunk;
@@ -683,11 +708,11 @@ static void qcom_geni_serial_handle_rx(struct uart_port *uport, bool drop)
683708

684709
if (!word_cnt)
685710
return;
686-
total_bytes = port->rx_bytes_pw * (word_cnt - 1);
711+
total_bytes = BYTES_PER_FIFO_WORD * (word_cnt - 1);
687712
if (last_word_partial && last_word_byte_cnt)
688713
total_bytes += last_word_byte_cnt;
689714
else
690-
total_bytes += port->rx_bytes_pw;
715+
total_bytes += BYTES_PER_FIFO_WORD;
691716
port->handle_rx(uport, total_bytes, drop);
692717
}
693718

@@ -720,7 +745,7 @@ static void qcom_geni_serial_handle_tx(struct uart_port *uport, bool done,
720745
}
721746

722747
avail = port->tx_fifo_depth - (status & TX_FIFO_WC);
723-
avail *= port->tx_bytes_pw;
748+
avail *= BYTES_PER_FIFO_WORD;
724749

725750
tail = xmit->tail;
726751
chunk = min(avail, pending);
@@ -744,7 +769,7 @@ static void qcom_geni_serial_handle_tx(struct uart_port *uport, bool done,
744769
int c;
745770

746771
memset(buf, 0, ARRAY_SIZE(buf));
747-
tx_bytes = min_t(size_t, remaining, port->tx_bytes_pw);
772+
tx_bytes = min_t(size_t, remaining, BYTES_PER_FIFO_WORD);
748773

749774
for (c = 0; c < tx_bytes ; c++) {
750775
buf[c] = xmit->buf[tail++];
@@ -861,12 +886,6 @@ static int qcom_geni_serial_port_setup(struct uart_port *uport)
861886
u32 proto;
862887
u32 pin_swap;
863888

864-
if (uart_console(uport))
865-
port->tx_bytes_pw = 1;
866-
else
867-
port->tx_bytes_pw = 4;
868-
port->rx_bytes_pw = 4;
869-
870889
proto = geni_se_read_proto(&port->se);
871890
if (proto != GENI_SE_UART) {
872891
dev_err(uport->dev, "Invalid FW loaded, proto: %d\n", proto);
@@ -898,10 +917,8 @@ static int qcom_geni_serial_port_setup(struct uart_port *uport)
898917
*/
899918
if (uart_console(uport))
900919
qcom_geni_serial_poll_tx_done(uport);
901-
geni_se_config_packing(&port->se, BITS_PER_BYTE, port->tx_bytes_pw,
902-
false, true, false);
903-
geni_se_config_packing(&port->se, BITS_PER_BYTE, port->rx_bytes_pw,
904-
false, false, true);
920+
geni_se_config_packing(&port->se, BITS_PER_BYTE, BYTES_PER_FIFO_WORD,
921+
false, true, true);
905922
geni_se_init(&port->se, UART_RX_WM, port->rx_fifo_depth - 2);
906923
geni_se_select_mode(&port->se, GENI_SE_FIFO);
907924
port->setup = true;
@@ -1197,8 +1214,8 @@ static int __init qcom_geni_serial_earlycon_setup(struct earlycon_device *dev,
11971214
*/
11981215
qcom_geni_serial_poll_tx_done(uport);
11991216
qcom_geni_serial_abort_rx(uport);
1200-
geni_se_config_packing(&se, BITS_PER_BYTE, 1, false, true, false);
1201-
geni_se_config_packing(&se, BITS_PER_BYTE, 4, false, false, true);
1217+
geni_se_config_packing(&se, BITS_PER_BYTE, BYTES_PER_FIFO_WORD,
1218+
false, true, true);
12021219
geni_se_init(&se, DEF_FIFO_DEPTH_WORDS / 2, DEF_FIFO_DEPTH_WORDS - 2);
12031220
geni_se_select_mode(&se, GENI_SE_FIFO);
12041221

0 commit comments

Comments
 (0)