Commit 12d15e6f authored by Vineet Gupta's avatar Vineet Gupta Committed by Greg Kroah-Hartman
Browse files

serial/arc: Refactor by referencing to uart_port where possible



The ARC UART MMIO helpers would take arc_uart_port and then reference
generic uart_port->membase member. So change them to difrectly refer to
uart_port and fix call sites accordingly.

This removes the need for to_arc_port() converion almost eveeywhere and
makes code a bit easier to read.

Signed-off-by: default avatarVineet Gupta <vgupta@synopsys.com>
Reviewed-by: default avatarRob Herring <robh@kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 3bce1b70
Loading
Loading
Loading
Loading
+69 −86
Original line number Original line Diff line number Diff line
@@ -72,7 +72,7 @@
#define RXOERR  0x02	/* OverFlow Err: Char recv but RXFULL still set */
#define RXOERR  0x02	/* OverFlow Err: Char recv but RXFULL still set */


/* Uart bit fiddling helpers: lowest level */
/* Uart bit fiddling helpers: lowest level */
#define RBASE(uart, reg)      (uart->port.membase + reg)
#define RBASE(port, reg)      (port->membase + reg)
#define UART_REG_SET(u, r, v) writeb((v), RBASE(u, r))
#define UART_REG_SET(u, r, v) writeb((v), RBASE(u, r))
#define UART_REG_GET(u, r)    readb(RBASE(u, r))
#define UART_REG_GET(u, r)    readb(RBASE(u, r))


@@ -129,19 +129,15 @@ static struct uart_driver arc_uart_driver = {


static void arc_serial_stop_rx(struct uart_port *port)
static void arc_serial_stop_rx(struct uart_port *port)
{
{
	struct arc_uart_port *uart = to_arc_port(port);
	UART_RX_IRQ_DISABLE(port);

	UART_RX_IRQ_DISABLE(uart);
}
}


static void arc_serial_stop_tx(struct uart_port *port)
static void arc_serial_stop_tx(struct uart_port *port)
{
{
	struct arc_uart_port *uart = to_arc_port(port);
	while (!(UART_GET_STATUS(port) & TXEMPTY))

	while (!(UART_GET_STATUS(uart) & TXEMPTY))
		cpu_relax();
		cpu_relax();


	UART_TX_IRQ_DISABLE(uart);
	UART_TX_IRQ_DISABLE(port);
}
}


/*
/*
@@ -149,10 +145,9 @@ static void arc_serial_stop_tx(struct uart_port *port)
 */
 */
static unsigned int arc_serial_tx_empty(struct uart_port *port)
static unsigned int arc_serial_tx_empty(struct uart_port *port)
{
{
	struct arc_uart_port *uart = to_arc_port(port);
	unsigned int stat;
	unsigned int stat;


	stat = UART_GET_STATUS(uart);
	stat = UART_GET_STATUS(port);
	if (stat & TXEMPTY)
	if (stat & TXEMPTY)
		return TIOCSER_TEMT;
		return TIOCSER_TEMT;


@@ -166,24 +161,24 @@ static unsigned int arc_serial_tx_empty(struct uart_port *port)
 *     = by uart_start( ) before calling us
 *     = by uart_start( ) before calling us
 *     = tx_ist checks that too before calling
 *     = tx_ist checks that too before calling
 */
 */
static void arc_serial_tx_chars(struct arc_uart_port *uart)
static void arc_serial_tx_chars(struct uart_port *port)
{
{
	struct circ_buf *xmit = &uart->port.state->xmit;
	struct circ_buf *xmit = &port->state->xmit;
	int sent = 0;
	int sent = 0;
	unsigned char ch;
	unsigned char ch;


	if (unlikely(uart->port.x_char)) {
	if (unlikely(port->x_char)) {
		UART_SET_DATA(uart, uart->port.x_char);
		UART_SET_DATA(port, port->x_char);
		uart->port.icount.tx++;
		port->icount.tx++;
		uart->port.x_char = 0;
		port->x_char = 0;
		sent = 1;
		sent = 1;
	} else if (xmit->tail != xmit->head) {	/* TODO: uart_circ_empty */
	} else if (xmit->tail != xmit->head) {	/* TODO: uart_circ_empty */
		ch = xmit->buf[xmit->tail];
		ch = xmit->buf[xmit->tail];
		xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
		xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
		uart->port.icount.tx++;
		port->icount.tx++;
		while (!(UART_GET_STATUS(uart) & TXEMPTY))
		while (!(UART_GET_STATUS(port) & TXEMPTY))
			cpu_relax();
			cpu_relax();
		UART_SET_DATA(uart, ch);
		UART_SET_DATA(port, ch);
		sent = 1;
		sent = 1;
	}
	}


@@ -192,10 +187,10 @@ static void arc_serial_tx_chars(struct arc_uart_port *uart)
	 * By Hard ISR to schedule processing in software interrupt part
	 * By Hard ISR to schedule processing in software interrupt part
	 */
	 */
	if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
	if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
		uart_write_wakeup(&uart->port);
		uart_write_wakeup(port);


	if (sent)
	if (sent)
		UART_TX_IRQ_ENABLE(uart);
		UART_TX_IRQ_ENABLE(port);
}
}


/*
/*
@@ -204,12 +199,10 @@ static void arc_serial_tx_chars(struct arc_uart_port *uart)
 */
 */
static void arc_serial_start_tx(struct uart_port *port)
static void arc_serial_start_tx(struct uart_port *port)
{
{
	struct arc_uart_port *uart = to_arc_port(port);
	arc_serial_tx_chars(port);

	arc_serial_tx_chars(uart);
}
}


static void arc_serial_rx_chars(struct arc_uart_port *uart, unsigned int status)
static void arc_serial_rx_chars(struct uart_port *port, unsigned int status)
{
{
	unsigned int ch, flg = 0;
	unsigned int ch, flg = 0;


@@ -229,15 +222,15 @@ static void arc_serial_rx_chars(struct arc_uart_port *uart, unsigned int status)
		 */
		 */
		if (unlikely(status & (RXOERR | RXFERR))) {
		if (unlikely(status & (RXOERR | RXFERR))) {
			if (status & RXOERR) {
			if (status & RXOERR) {
				uart->port.icount.overrun++;
				port->icount.overrun++;
				flg = TTY_OVERRUN;
				flg = TTY_OVERRUN;
				UART_CLR_STATUS(uart, RXOERR);
				UART_CLR_STATUS(port, RXOERR);
			}
			}


			if (status & RXFERR) {
			if (status & RXFERR) {
				uart->port.icount.frame++;
				port->icount.frame++;
				flg = TTY_FRAME;
				flg = TTY_FRAME;
				UART_CLR_STATUS(uart, RXFERR);
				UART_CLR_STATUS(port, RXFERR);
			}
			}
		} else
		} else
			flg = TTY_NORMAL;
			flg = TTY_NORMAL;
@@ -245,16 +238,16 @@ static void arc_serial_rx_chars(struct arc_uart_port *uart, unsigned int status)
		if (status & RXEMPTY)
		if (status & RXEMPTY)
			continue;
			continue;


		ch = UART_GET_DATA(uart);
		ch = UART_GET_DATA(port);
		uart->port.icount.rx++;
		port->icount.rx++;


		if (!(uart_handle_sysrq_char(&uart->port, ch)))
		if (!(uart_handle_sysrq_char(port, ch)))
			uart_insert_char(&uart->port, status, RXOERR, ch, flg);
			uart_insert_char(port, status, RXOERR, ch, flg);


		spin_unlock(&uart->port.lock);
		spin_unlock(&port->lock);
		tty_flip_buffer_push(&uart->port.state->port);
		tty_flip_buffer_push(&port->state->port);
		spin_lock(&uart->port.lock);
		spin_lock(&port->lock);
	} while (!((status = UART_GET_STATUS(uart)) & RXEMPTY));
	} while (!((status = UART_GET_STATUS(port)) & RXEMPTY));
}
}


/*
/*
@@ -287,10 +280,10 @@ static void arc_serial_rx_chars(struct arc_uart_port *uart, unsigned int status)


static irqreturn_t arc_serial_isr(int irq, void *dev_id)
static irqreturn_t arc_serial_isr(int irq, void *dev_id)
{
{
	struct arc_uart_port *uart = dev_id;
	struct uart_port *port = dev_id;
	unsigned int status;
	unsigned int status;


	status = UART_GET_STATUS(uart);
	status = UART_GET_STATUS(port);


	/*
	/*
	 * Single IRQ for both Rx (data available) Tx (room available) Interrupt
	 * Single IRQ for both Rx (data available) Tx (room available) Interrupt
@@ -300,9 +293,9 @@ static irqreturn_t arc_serial_isr(int irq, void *dev_id)
	if (status & RXIENB) {
	if (status & RXIENB) {


		/* already in ISR, no need of xx_irqsave */
		/* already in ISR, no need of xx_irqsave */
		spin_lock(&uart->port.lock);
		spin_lock(&port->lock);
		arc_serial_rx_chars(uart, status);
		arc_serial_rx_chars(port, status);
		spin_unlock(&uart->port.lock);
		spin_unlock(&port->lock);
	}
	}


	if ((status & TXIENB) && (status & TXEMPTY)) {
	if ((status & TXIENB) && (status & TXEMPTY)) {
@@ -310,14 +303,14 @@ static irqreturn_t arc_serial_isr(int irq, void *dev_id)
		/* Unconditionally disable further Tx-Interrupts.
		/* Unconditionally disable further Tx-Interrupts.
		 * will be enabled by tx_chars() if needed.
		 * will be enabled by tx_chars() if needed.
		 */
		 */
		UART_TX_IRQ_DISABLE(uart);
		UART_TX_IRQ_DISABLE(port);


		spin_lock(&uart->port.lock);
		spin_lock(&port->lock);


		if (!uart_tx_stopped(&uart->port))
		if (!uart_tx_stopped(port))
			arc_serial_tx_chars(uart);
			arc_serial_tx_chars(port);


		spin_unlock(&uart->port.lock);
		spin_unlock(&port->lock);
	}
	}


	return IRQ_HANDLED;
	return IRQ_HANDLED;
@@ -347,18 +340,15 @@ static void arc_serial_break_ctl(struct uart_port *port, int break_state)


static int arc_serial_startup(struct uart_port *port)
static int arc_serial_startup(struct uart_port *port)
{
{
	struct arc_uart_port *uart = to_arc_port(port);

	/* Before we hook up the ISR, Disable all UART Interrupts */
	/* Before we hook up the ISR, Disable all UART Interrupts */
	UART_ALL_IRQ_DISABLE(uart);
	UART_ALL_IRQ_DISABLE(port);


	if (request_irq(uart->port.irq, arc_serial_isr, 0, "arc uart rx-tx",
	if (request_irq(port->irq, arc_serial_isr, 0, "arc uart rx-tx", port)) {
			uart)) {
		dev_warn(port->dev, "Unable to attach ARC UART intr\n");
		dev_warn(uart->port.dev, "Unable to attach ARC UART intr\n");
		return -EBUSY;
		return -EBUSY;
	}
	}


	UART_RX_IRQ_ENABLE(uart); /* Only Rx IRQ enabled to begin with */
	UART_RX_IRQ_ENABLE(port); /* Only Rx IRQ enabled to begin with */


	return 0;
	return 0;
}
}
@@ -366,8 +356,7 @@ static int arc_serial_startup(struct uart_port *port)
/* This is not really needed */
/* This is not really needed */
static void arc_serial_shutdown(struct uart_port *port)
static void arc_serial_shutdown(struct uart_port *port)
{
{
	struct arc_uart_port *uart = to_arc_port(port);
	free_irq(port->irq, port);
	free_irq(uart->port.irq, uart);
}
}


static void
static void
@@ -404,12 +393,12 @@ arc_serial_set_termios(struct uart_port *port, struct ktermios *new,


	spin_lock_irqsave(&port->lock, flags);
	spin_lock_irqsave(&port->lock, flags);


	UART_ALL_IRQ_DISABLE(uart);
	UART_ALL_IRQ_DISABLE(port);


	UART_SET_BAUDL(uart, uartl);
	UART_SET_BAUDL(port, uartl);
	UART_SET_BAUDH(uart, uarth);
	UART_SET_BAUDH(port, uarth);


	UART_RX_IRQ_ENABLE(uart);
	UART_RX_IRQ_ENABLE(port);


	/*
	/*
	 * UART doesn't support Parity/Hardware Flow Control;
	 * UART doesn't support Parity/Hardware Flow Control;
@@ -432,9 +421,7 @@ arc_serial_set_termios(struct uart_port *port, struct ktermios *new,


static const char *arc_serial_type(struct uart_port *port)
static const char *arc_serial_type(struct uart_port *port)
{
{
	struct arc_uart_port *uart = to_arc_port(port);
	return port->type == PORT_ARC ? DRIVER_NAME : NULL;

	return uart->port.type == PORT_ARC ? DRIVER_NAME : NULL;
}
}


static void arc_serial_release_port(struct uart_port *port)
static void arc_serial_release_port(struct uart_port *port)
@@ -463,35 +450,30 @@ arc_serial_verify_port(struct uart_port *port, struct serial_struct *ser)
 */
 */
static void arc_serial_config_port(struct uart_port *port, int flags)
static void arc_serial_config_port(struct uart_port *port, int flags)
{
{
	struct arc_uart_port *uart = to_arc_port(port);

	if (flags & UART_CONFIG_TYPE)
	if (flags & UART_CONFIG_TYPE)
		uart->port.type = PORT_ARC;
		port->type = PORT_ARC;
}
}


#if defined(CONFIG_CONSOLE_POLL) || defined(CONFIG_SERIAL_ARC_CONSOLE)
#if defined(CONFIG_CONSOLE_POLL) || defined(CONFIG_SERIAL_ARC_CONSOLE)


static void arc_serial_poll_putchar(struct uart_port *port, int chr)
static void arc_serial_poll_putchar(struct uart_port *port, int chr)
{
{
	struct arc_uart_port *uart = to_arc_port(port);
	while (!(UART_GET_STATUS(port) & TXEMPTY))

	while (!(UART_GET_STATUS(uart) & TXEMPTY))
		cpu_relax();
		cpu_relax();


	UART_SET_DATA(uart, (unsigned char)chr);
	UART_SET_DATA(port, (unsigned char)chr);
}
}
#endif
#endif


#ifdef CONFIG_CONSOLE_POLL
#ifdef CONFIG_CONSOLE_POLL
static int arc_serial_poll_getchar(struct uart_port *port)
static int arc_serial_poll_getchar(struct uart_port *port)
{
{
	struct arc_uart_port *uart = to_arc_port(port);
	unsigned char chr;
	unsigned char chr;


	while (!(UART_GET_STATUS(uart) & RXEMPTY))
	while (!(UART_GET_STATUS(port) & RXEMPTY))
		cpu_relax();
		cpu_relax();


	chr = UART_GET_DATA(uart);
	chr = UART_GET_DATA(port);
	return chr;
	return chr;
}
}
#endif
#endif
@@ -524,6 +506,7 @@ arc_uart_init_one(struct platform_device *pdev, int dev_id)
	struct resource *res, *res2;
	struct resource *res, *res2;
	unsigned long *plat_data;
	unsigned long *plat_data;
	struct arc_uart_port *uart = &arc_uart_ports[dev_id];
	struct arc_uart_port *uart = &arc_uart_ports[dev_id];
	struct uart_port *port = &uart->port;


	plat_data = dev_get_platdata(&pdev->dev);
	plat_data = dev_get_platdata(&pdev->dev);
	if (!plat_data)
	if (!plat_data)
@@ -532,7 +515,7 @@ arc_uart_init_one(struct platform_device *pdev, int dev_id)
	uart->is_emulated = !!plat_data[0];	/* workaround ISS bug */
	uart->is_emulated = !!plat_data[0];	/* workaround ISS bug */


	if (is_early_platform_device(pdev)) {
	if (is_early_platform_device(pdev)) {
		uart->port.uartclk = plat_data[1];
		port->uartclk = plat_data[1];
		uart->baud = plat_data[2];
		uart->baud = plat_data[2];
	} else {
	} else {
		struct device_node *np = pdev->dev.of_node;
		struct device_node *np = pdev->dev.of_node;
@@ -542,7 +525,7 @@ arc_uart_init_one(struct platform_device *pdev, int dev_id)
			dev_err(&pdev->dev, "clock-frequency property NOTset\n");
			dev_err(&pdev->dev, "clock-frequency property NOTset\n");
			return -EINVAL;
			return -EINVAL;
		}
		}
		uart->port.uartclk = val;
		port->uartclk = val;


		if (of_property_read_u32(np, "current-speed", &val)) {
		if (of_property_read_u32(np, "current-speed", &val)) {
			dev_err(&pdev->dev, "current-speed property NOT set\n");
			dev_err(&pdev->dev, "current-speed property NOT set\n");
@@ -559,26 +542,26 @@ arc_uart_init_one(struct platform_device *pdev, int dev_id)
	if (!res2)
	if (!res2)
		return -ENODEV;
		return -ENODEV;


	uart->port.mapbase = res->start;
	port->mapbase = res->start;
	uart->port.membase = ioremap_nocache(res->start, resource_size(res));
	port->membase = ioremap_nocache(res->start, resource_size(res));
	if (!uart->port.membase)
	if (!port->membase)
		/* No point of dev_err since UART itself is hosed here */
		/* No point of dev_err since UART itself is hosed here */
		return -ENXIO;
		return -ENXIO;


	uart->port.irq = res2->start;
	port->irq = res2->start;
	uart->port.dev = &pdev->dev;
	port->dev = &pdev->dev;
	uart->port.iotype = UPIO_MEM;
	port->iotype = UPIO_MEM;
	uart->port.flags = UPF_BOOT_AUTOCONF;
	port->flags = UPF_BOOT_AUTOCONF;
	uart->port.line = dev_id;
	port->line = dev_id;
	uart->port.ops = &arc_serial_pops;
	port->ops = &arc_serial_pops;


	uart->port.fifosize = ARC_UART_TX_FIFO_SIZE;
	port->fifosize = ARC_UART_TX_FIFO_SIZE;


	/*
	/*
	 * uart_insert_char( ) uses it in decideding whether to ignore a
	 * uart_insert_char( ) uses it in decideding whether to ignore a
	 * char or not. Explicitly setting it here, removes the subtelty
	 * char or not. Explicitly setting it here, removes the subtelty
	 */
	 */
	uart->port.ignore_status_mask = 0;
	port->ignore_status_mask = 0;


	return 0;
	return 0;
}
}