tty: serial: unify TX space reads under altera_jtaguart_tx_space()
TX space reads from the control register are performed in various forms on 4 places in altera_jtaguart. Unify all those and do the read and masking on a single place. The new helper altera_jtaguart_tx_space() uses FIELD_GET(), so we can drop ALTERA_JTAGUART_CONTROL_WSPACE_OFF now. Cc: Tobias Klauser <tklauser@distanz.ch> Signed-off-by: Jiri Slaby <jslaby@suse.cz> Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Acked-by: Tobias Klauser <tklauser@distanz.ch> Link: https://lore.kernel.org/r/20220927111819.18516-3-jslaby@suse.cz Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
ed9bf4aea0
commit
523f54ed3b
@ -9,6 +9,7 @@
|
|||||||
* (C) Copyright 2010, Tobias Klauser <tklauser@distanz.ch>
|
* (C) Copyright 2010, Tobias Klauser <tklauser@distanz.ch>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <linux/bitfield.h>
|
||||||
#include <linux/kernel.h>
|
#include <linux/kernel.h>
|
||||||
#include <linux/init.h>
|
#include <linux/init.h>
|
||||||
#include <linux/interrupt.h>
|
#include <linux/interrupt.h>
|
||||||
@ -48,7 +49,6 @@
|
|||||||
#define ALTERA_JTAGUART_CONTROL_WI_MSK 0x00000200
|
#define ALTERA_JTAGUART_CONTROL_WI_MSK 0x00000200
|
||||||
#define ALTERA_JTAGUART_CONTROL_AC_MSK 0x00000400
|
#define ALTERA_JTAGUART_CONTROL_AC_MSK 0x00000400
|
||||||
#define ALTERA_JTAGUART_CONTROL_WSPACE_MSK 0xFFFF0000
|
#define ALTERA_JTAGUART_CONTROL_WSPACE_MSK 0xFFFF0000
|
||||||
#define ALTERA_JTAGUART_CONTROL_WSPACE_OFF 16
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Local per-uart structure.
|
* Local per-uart structure.
|
||||||
@ -59,10 +59,19 @@ struct altera_jtaguart {
|
|||||||
unsigned long imr; /* Local IMR mirror */
|
unsigned long imr; /* Local IMR mirror */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static unsigned int altera_jtaguart_tx_space(struct uart_port *port, u32 *ctlp)
|
||||||
|
{
|
||||||
|
u32 ctl = readl(port->membase + ALTERA_JTAGUART_CONTROL_REG);
|
||||||
|
|
||||||
|
if (ctlp)
|
||||||
|
*ctlp = ctl;
|
||||||
|
|
||||||
|
return FIELD_GET(ALTERA_JTAGUART_CONTROL_WSPACE_MSK, ctl);
|
||||||
|
}
|
||||||
|
|
||||||
static unsigned int altera_jtaguart_tx_empty(struct uart_port *port)
|
static unsigned int altera_jtaguart_tx_empty(struct uart_port *port)
|
||||||
{
|
{
|
||||||
return (readl(port->membase + ALTERA_JTAGUART_CONTROL_REG) &
|
return altera_jtaguart_tx_space(port, NULL) ? TIOCSER_TEMT : 0;
|
||||||
ALTERA_JTAGUART_CONTROL_WSPACE_MSK) ? TIOCSER_TEMT : 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned int altera_jtaguart_get_mctrl(struct uart_port *port)
|
static unsigned int altera_jtaguart_get_mctrl(struct uart_port *port)
|
||||||
@ -150,9 +159,7 @@ static void altera_jtaguart_tx_chars(struct altera_jtaguart *pp)
|
|||||||
|
|
||||||
pending = uart_circ_chars_pending(xmit);
|
pending = uart_circ_chars_pending(xmit);
|
||||||
if (pending > 0) {
|
if (pending > 0) {
|
||||||
count = (readl(port->membase + ALTERA_JTAGUART_CONTROL_REG) &
|
count = altera_jtaguart_tx_space(port, NULL);
|
||||||
ALTERA_JTAGUART_CONTROL_WSPACE_MSK) >>
|
|
||||||
ALTERA_JTAGUART_CONTROL_WSPACE_OFF;
|
|
||||||
if (count > pending)
|
if (count > pending)
|
||||||
count = pending;
|
count = pending;
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
@ -298,12 +305,11 @@ static struct altera_jtaguart altera_jtaguart_ports[ALTERA_JTAGUART_MAXPORTS];
|
|||||||
#if defined(CONFIG_SERIAL_ALTERA_JTAGUART_CONSOLE_BYPASS)
|
#if defined(CONFIG_SERIAL_ALTERA_JTAGUART_CONSOLE_BYPASS)
|
||||||
static void altera_jtaguart_console_putc(struct uart_port *port, unsigned char c)
|
static void altera_jtaguart_console_putc(struct uart_port *port, unsigned char c)
|
||||||
{
|
{
|
||||||
unsigned long status;
|
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
u32 status;
|
||||||
|
|
||||||
spin_lock_irqsave(&port->lock, flags);
|
spin_lock_irqsave(&port->lock, flags);
|
||||||
while (((status = readl(port->membase + ALTERA_JTAGUART_CONTROL_REG)) &
|
while (!altera_jtaguart_tx_space(port, &status)) {
|
||||||
ALTERA_JTAGUART_CONTROL_WSPACE_MSK) == 0) {
|
|
||||||
if ((status & ALTERA_JTAGUART_CONTROL_AC_MSK) == 0) {
|
if ((status & ALTERA_JTAGUART_CONTROL_AC_MSK) == 0) {
|
||||||
spin_unlock_irqrestore(&port->lock, flags);
|
spin_unlock_irqrestore(&port->lock, flags);
|
||||||
return; /* no connection activity */
|
return; /* no connection activity */
|
||||||
@ -321,8 +327,7 @@ static void altera_jtaguart_console_putc(struct uart_port *port, unsigned char c
|
|||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
|
||||||
spin_lock_irqsave(&port->lock, flags);
|
spin_lock_irqsave(&port->lock, flags);
|
||||||
while ((readl(port->membase + ALTERA_JTAGUART_CONTROL_REG) &
|
while (!altera_jtaguart_tx_space(port, NULL)) {
|
||||||
ALTERA_JTAGUART_CONTROL_WSPACE_MSK) == 0) {
|
|
||||||
spin_unlock_irqrestore(&port->lock, flags);
|
spin_unlock_irqrestore(&port->lock, flags);
|
||||||
cpu_relax();
|
cpu_relax();
|
||||||
spin_lock_irqsave(&port->lock, flags);
|
spin_lock_irqsave(&port->lock, flags);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user