Skip to contentSkip to conversation

Some patches for Altera UART driver

PATCH In review Anton Vorontsov 3 participants 21 messages Oct 1, 2010

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover Some patches for Altera UART driver

Hi all,

Here is v2. Changes:

- Addressed comments by Alan Cox and Tobias Klauser;
- In patch 'Add support for getting mapbase and IRQ from resources', added ioremap() return value checking;
- Added a few fixup patches.

Thanks,

Signature · 3 lines
Anton Vorontsov
email: [email protected]
irc://irc.freenode.net/bd2
#1 lore raw

PATCH v2 1/8 serial: Factor out uart_poll_timeout() from 8250 driver

Soon we will use that handy function in the altera_uart driver.

---
 drivers/serial/8250.c       |   14 ++++----------
 include/linux/serial_core.h |    8 ++++++++
 2 files changed, 12 insertions(+), 10 deletions(-)
drivers/serial/8250.c +4 -10
index 24110f6..61e95dd 100644
@@ -1722,12 +1722,6 @@ static void serial_unlink_irq_chain(struct uart_8250_port *up)
 	mutex_unlock(&hash_mutex);
 }
 
-/* Base timer interval for polling */
-static inline int poll_timeout(int timeout)
-{
-	return timeout > 6 ? (timeout / 2 - 2) : 1;
-}
-
 /*
  * This function is used to handle ports that do not have an
  * interrupt.  This doesn't work very well for 16450's, but gives
@@ -1742,7 +1736,7 @@ static void serial8250_timeout(unsigned long data)
 	iir = serial_in(up, UART_IIR);
 	if (!(iir & UART_IIR_NO_INT))
 		serial8250_handle_port(up);
-	mod_timer(&up->timer, jiffies + poll_timeout(up->port.timeout));
+	mod_timer(&up->timer, jiffies + uart_poll_timeout(&up->port));
 }
 
 static void serial8250_backup_timeout(unsigned long data)
@@ -1787,7 +1781,7 @@ static void serial8250_backup_timeout(unsigned long data)
 
 	/* Standard timer interval plus 0.2s to keep the port running */
 	mod_timer(&up->timer,
-		jiffies + poll_timeout(up->port.timeout) + HZ / 5);
+		jiffies + uart_poll_timeout(&up->port) + HZ / 5);
 }
 
 static unsigned int serial8250_tx_empty(struct uart_port *port)
@@ -2069,7 +2063,7 @@ static int serial8250_startup(struct uart_port *port)
 		up->timer.function = serial8250_backup_timeout;
 		up->timer.data = (unsigned long)up;
 		mod_timer(&up->timer, jiffies +
-			  poll_timeout(up->port.timeout) + HZ / 5);
+			uart_poll_timeout(port) + HZ / 5);
 	}
 
 	/*
@@ -2079,7 +2073,7 @@ static int serial8250_startup(struct uart_port *port)
 	 */
 	if (!is_real_interrupt(up->port.irq)) {
 		up->timer.data = (unsigned long)up;
-		mod_timer(&up->timer, jiffies + poll_timeout(up->port.timeout));
+		mod_timer(&up->timer, jiffies + uart_poll_timeout(port));
 	} else {
 		retval = serial_link_irq_chain(up);
 		if (retval)
include/linux/serial_core.h +8 -0
index 563e234..ac48082 100644
@@ -411,6 +411,14 @@ unsigned int uart_get_baud_rate(struct uart_port *port, struct ktermios *termios
 				unsigned int max);
 unsigned int uart_get_divisor(struct uart_port *port, unsigned int baud);
 
+/* Base timer interval for polling */
+static inline int uart_poll_timeout(struct uart_port *port)
+{
+	int timeout = port->timeout;
+
+	return timeout > 6 ? (timeout / 2 - 2) : 1;
+}
+
 /*
  * Console helpers.
  */
Signature · 1 line
1.7.0.5
#2 lore raw

PATCH v2 2/8 altera_uart: Add support for polling mode (IRQ-less)

In reply to Anton Vorontsov

Some Altera UART implementations doesn't route the IRQ line, so we have to work in polling mode.

---
 drivers/serial/altera_uart.c |   23 ++++++++++++++++++++++-
 1 files changed, 22 insertions(+), 1 deletions(-)
drivers/serial/altera_uart.c +22 -1
index f8d8a00..7dd58da 100644
@@ -15,6 +15,7 @@
 
 #include <linux/kernel.h>
 #include <linux/init.h>
+#include <linux/timer.h>
 #include <linux/interrupt.h>
 #include <linux/module.h>
 #include <linux/console.h>
@@ -76,6 +77,7 @@
  */
 struct altera_uart {
 	struct uart_port port;
+	struct timer_list tmr;
 	unsigned int sigs;	/* Local copy of line sigs */
 	unsigned short imr;	/* Local IMR mirror */
 };
@@ -168,6 +170,7 @@ static void altera_uart_set_termios(struct uart_port *port,
 	tty_termios_encode_baud_rate(termios, baud, baud);
 
 	spin_lock_irqsave(&port->lock, flags);
+	uart_update_timeout(port, termios->c_cflag, baud);
 	writel(baudclk, port->membase + ALTERA_UART_DIVISOR_REG);
 	spin_unlock_irqrestore(&port->lock, flags);
 }
@@ -268,6 +271,15 @@ static irqreturn_t altera_uart_interrupt(int irq, void *data)
 	return IRQ_RETVAL(isr);
 }
 
+static void altera_uart_timer(unsigned long data)
+{
+	struct uart_port *port = (void *)data;
+	struct altera_uart *pp = container_of(port, struct altera_uart, port);
+
+	altera_uart_interrupt(0, port);
+	mod_timer(&pp->tmr, jiffies + uart_poll_timeout(port));
+}
+
 static void altera_uart_config_port(struct uart_port *port, int flags)
 {
 	port->type = PORT_ALTERA_UART;
@@ -284,6 +296,12 @@ static int altera_uart_startup(struct uart_port *port)
 	unsigned long flags;
 	int ret;
 
+	if (!port->irq) {
+		setup_timer(&pp->tmr, altera_uart_timer, (unsigned long)port);
+		mod_timer(&pp->tmr, jiffies + uart_poll_timeout(port));
+		return 0;
+	}
+
 	ret = request_irq(port->irq, altera_uart_interrupt, IRQF_DISABLED,
 			DRV_NAME, port);
 	if (ret) {
@@ -316,7 +334,10 @@ static void altera_uart_shutdown(struct uart_port *port)
 
 	spin_unlock_irqrestore(&port->lock, flags);
 
-	free_irq(port->irq, port);
+	if (port->irq)
+		free_irq(port->irq, port);
+	else
+		del_timer_sync(&pp->tmr);
 }
 
 static const char *altera_uart_type(struct uart_port *port)
Signature · 1 line
1.7.0.5
#4 lore raw

PATCH v2 3/8 altera_uart: Add support for getting mapbase and IRQ from resources

In reply to Anton Vorontsov

This makes it much easier to integrate the driver with the rest of the Linux (e.g. MFD subsystem).

The old method is still supported though.

Also, from now on, there is one platform device per port (no changes are needed for the platform code, as no one registers the devices anywhere in-tree yet).

---
 drivers/serial/altera_uart.c |   60 ++++++++++++++++++++++++++---------------
 1 files changed, 38 insertions(+), 22 deletions(-)
drivers/serial/altera_uart.c +38 -22
index 7dd58da..1dfeffa 100644
@@ -498,38 +498,54 @@ static int __devinit altera_uart_probe(struct platform_device *pdev)
 {
 	struct altera_uart_platform_uart *platp = pdev->dev.platform_data;
 	struct uart_port *port;
-	int i;
+	struct resource *res_mem;
+	struct resource *res_irq;
+	int i = pdev->id;
 
-	for (i = 0; i < CONFIG_SERIAL_ALTERA_UART_MAXPORTS && platp[i].mapbase; i++) {
-		port = &altera_uart_ports[i].port;
+	/* -1 emphasizes that the platform must have one port, no .N suffix */
+	if (i == -1)
+		i = 0;
 
-		port->line = i;
-		port->type = PORT_ALTERA_UART;
-		port->mapbase = platp[i].mapbase;
-		port->membase = ioremap(port->mapbase, ALTERA_UART_SIZE);
-		port->iotype = SERIAL_IO_MEM;
-		port->irq = platp[i].irq;
-		port->uartclk = platp[i].uartclk;
-		port->ops = &altera_uart_ops;
-		port->flags = ASYNC_BOOT_AUTOCONF;
+	if (i >= CONFIG_SERIAL_ALTERA_UART_MAXPORTS)
+		return -EINVAL;
 
-		uart_add_one_port(&altera_uart_driver, port);
-	}
+	port = &altera_uart_ports[i].port;
+
+	res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (res_mem)
+		port->mapbase = res_mem->start;
+	else if (platp->mapbase)
+		port->mapbase = platp->mapbase;
+	else
+		return -EINVAL;
+
+	res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
+	if (res_irq)
+		port->irq = res_irq->start;
+	else if (platp->irq)
+		port->irq = platp->irq;
+
+	port->membase = ioremap(port->mapbase, ALTERA_UART_SIZE);
+	if (!port->membase)
+		return -ENOMEM;
+
+	port->line = i;
+	port->type = PORT_ALTERA_UART;
+	port->iotype = SERIAL_IO_MEM;
+	port->uartclk = platp->uartclk;
+	port->ops = &altera_uart_ops;
+	port->flags = ASYNC_BOOT_AUTOCONF;
+
+	uart_add_one_port(&altera_uart_driver, port);
 
 	return 0;
 }
 
 static int __devexit altera_uart_remove(struct platform_device *pdev)
 {
-	struct uart_port *port;
-	int i;
-
-	for (i = 0; i < CONFIG_SERIAL_ALTERA_UART_MAXPORTS; i++) {
-		port = &altera_uart_ports[i].port;
-		if (port)
-			uart_remove_one_port(&altera_uart_driver, port);
-	}
+	struct uart_port *port = &altera_uart_ports[pdev->id].port;
 
+	uart_remove_one_port(&altera_uart_driver, port);
 	return 0;
 }
 
Signature · 1 line
1.7.0.5
#5 lore raw

PATCH v2 4/8 altera_uart: Add support for different address strides

In reply to Anton Vorontsov

Some controllers implement registers with a stride, to support those we must implement the proper IO accessors.

---
 drivers/serial/altera_uart.c |   58 ++++++++++++++++++++++++++---------------
 include/linux/altera_uart.h  |    1 +
 2 files changed, 38 insertions(+), 21 deletions(-)
drivers/serial/altera_uart.c +37 -21
index 1dfeffa..f1985aa 100644
@@ -82,9 +82,23 @@ struct altera_uart {
 	unsigned short imr;	/* Local IMR mirror */
 };
 
+static u32 altera_uart_readl(struct uart_port *port, int reg)
+{
+	struct altera_uart_platform_uart *platp = port->private_data;
+
+	return readl(port->membase + (reg << platp->bus_shift));
+}
+
+static void altera_uart_writel(struct uart_port *port, u32 dat, int reg)
+{
+	struct altera_uart_platform_uart *platp = port->private_data;
+
+	writel(dat, port->membase + (reg << platp->bus_shift));
+}
+
 static unsigned int altera_uart_tx_empty(struct uart_port *port)
 {
-	return (readl(port->membase + ALTERA_UART_STATUS_REG) &
+	return (altera_uart_readl(port, ALTERA_UART_STATUS_REG) &
 		ALTERA_UART_STATUS_TMT_MSK) ? TIOCSER_TEMT : 0;
 }
 
@@ -93,8 +107,7 @@ static unsigned int altera_uart_get_mctrl(struct uart_port *port)
 	struct altera_uart *pp = container_of(port, struct altera_uart, port);
 	unsigned int sigs;
 
-	sigs =
-	    (readl(port->membase + ALTERA_UART_STATUS_REG) &
+	sigs = (altera_uart_readl(port, ALTERA_UART_STATUS_REG) &
 	     ALTERA_UART_STATUS_CTS_MSK) ? TIOCM_CTS : 0;
 	sigs |= (pp->sigs & TIOCM_RTS);
 
@@ -110,7 +123,7 @@ static void altera_uart_set_mctrl(struct uart_port *port, unsigned int sigs)
 		pp->imr |= ALTERA_UART_CONTROL_RTS_MSK;
 	else
 		pp->imr &= ~ALTERA_UART_CONTROL_RTS_MSK;
-	writel(pp->imr, port->membase + ALTERA_UART_CONTROL_REG);
+	altera_uart_writel(port, pp->imr, ALTERA_UART_CONTROL_REG);
 }
 
 static void altera_uart_start_tx(struct uart_port *port)
@@ -118,7 +131,7 @@ static void altera_uart_start_tx(struct uart_port *port)
 	struct altera_uart *pp = container_of(port, struct altera_uart, port);
 
 	pp->imr |= ALTERA_UART_CONTROL_TRDY_MSK;
-	writel(pp->imr, port->membase + ALTERA_UART_CONTROL_REG);
+	altera_uart_writel(port, pp->imr, ALTERA_UART_CONTROL_REG);
 }
 
 static void altera_uart_stop_tx(struct uart_port *port)
@@ -126,7 +139,7 @@ static void altera_uart_stop_tx(struct uart_port *port)
 	struct altera_uart *pp = container_of(port, struct altera_uart, port);
 
 	pp->imr &= ~ALTERA_UART_CONTROL_TRDY_MSK;
-	writel(pp->imr, port->membase + ALTERA_UART_CONTROL_REG);
+	altera_uart_writel(port, pp->imr, ALTERA_UART_CONTROL_REG);
 }
 
 static void altera_uart_stop_rx(struct uart_port *port)
@@ -134,7 +147,7 @@ static void altera_uart_stop_rx(struct uart_port *port)
 	struct altera_uart *pp = container_of(port, struct altera_uart, port);
 
 	pp->imr &= ~ALTERA_UART_CONTROL_RRDY_MSK;
-	writel(pp->imr, port->membase + ALTERA_UART_CONTROL_REG);
+	altera_uart_writel(port, pp->imr, ALTERA_UART_CONTROL_REG);
 }
 
 static void altera_uart_break_ctl(struct uart_port *port, int break_state)
@@ -147,7 +160,7 @@ static void altera_uart_break_ctl(struct uart_port *port, int break_state)
 		pp->imr |= ALTERA_UART_CONTROL_TRBK_MSK;
 	else
 		pp->imr &= ~ALTERA_UART_CONTROL_TRBK_MSK;
-	writel(pp->imr, port->membase + ALTERA_UART_CONTROL_REG);
+	altera_uart_writel(port, pp->imr, ALTERA_UART_CONTROL_REG);
 	spin_unlock_irqrestore(&port->lock, flags);
 }
 
@@ -171,7 +184,7 @@ static void altera_uart_set_termios(struct uart_port *port,
 
 	spin_lock_irqsave(&port->lock, flags);
 	uart_update_timeout(port, termios->c_cflag, baud);
-	writel(baudclk, port->membase + ALTERA_UART_DIVISOR_REG);
+	altera_uart_writel(port, baudclk, ALTERA_UART_DIVISOR_REG);
 	spin_unlock_irqrestore(&port->lock, flags);
 }
 
@@ -181,14 +194,15 @@ static void altera_uart_rx_chars(struct altera_uart *pp)
 	unsigned char ch, flag;
 	unsigned short status;
 
-	while ((status = readl(port->membase + ALTERA_UART_STATUS_REG)) &
+	while ((status = altera_uart_readl(port, ALTERA_UART_STATUS_REG)) &
 	       ALTERA_UART_STATUS_RRDY_MSK) {
-		ch = readl(port->membase + ALTERA_UART_RXDATA_REG);
+		ch = altera_uart_readl(port, ALTERA_UART_RXDATA_REG);
 		flag = TTY_NORMAL;
 		port->icount.rx++;
 
 		if (status & ALTERA_UART_STATUS_E_MSK) {
-			writel(status, port->membase + ALTERA_UART_STATUS_REG);
+			altera_uart_writel(port, status,
+					   ALTERA_UART_STATUS_REG);
 
 			if (status & ALTERA_UART_STATUS_BRK_MSK) {
 				port->icount.brk++;
@@ -228,18 +242,18 @@ static void altera_uart_tx_chars(struct altera_uart *pp)
 
 	if (port->x_char) {
 		/* Send special char - probably flow control */
-		writel(port->x_char, port->membase + ALTERA_UART_TXDATA_REG);
+		altera_uart_writel(port, port->x_char, ALTERA_UART_TXDATA_REG);
 		port->x_char = 0;
 		port->icount.tx++;
 		return;
 	}
 
-	while (readl(port->membase + ALTERA_UART_STATUS_REG) &
+	while (altera_uart_readl(port, ALTERA_UART_STATUS_REG) &
 	       ALTERA_UART_STATUS_TRDY_MSK) {
 		if (xmit->head == xmit->tail)
 			break;
-		writel(xmit->buf[xmit->tail],
-		       port->membase + ALTERA_UART_TXDATA_REG);
+		altera_uart_writel(port, xmit->buf[xmit->tail],
+		       ALTERA_UART_TXDATA_REG);
 		xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
 		port->icount.tx++;
 	}
@@ -249,7 +263,7 @@ static void altera_uart_tx_chars(struct altera_uart *pp)
 
 	if (xmit->head == xmit->tail) {
 		pp->imr &= ~ALTERA_UART_CONTROL_TRDY_MSK;
-		writel(pp->imr, port->membase + ALTERA_UART_CONTROL_REG);
+		altera_uart_writel(port, pp->imr, ALTERA_UART_CONTROL_REG);
 	}
 }
 
@@ -259,7 +273,7 @@ static irqreturn_t altera_uart_interrupt(int irq, void *data)
 	struct altera_uart *pp = container_of(port, struct altera_uart, port);
 	unsigned int isr;
 
-	isr = readl(port->membase + ALTERA_UART_STATUS_REG) & pp->imr;
+	isr = altera_uart_readl(port, ALTERA_UART_STATUS_REG) & pp->imr;
 
 	spin_lock(&port->lock);
 	if (isr & ALTERA_UART_STATUS_RRDY_MSK)
@@ -285,9 +299,9 @@ static void altera_uart_config_port(struct uart_port *port, int flags)
 	port->type = PORT_ALTERA_UART;
 
 	/* Clear mask, so no surprise interrupts. */
-	writel(0, port->membase + ALTERA_UART_CONTROL_REG);
+	altera_uart_writel(port, 0, ALTERA_UART_CONTROL_REG);
 	/* Clear status register */
-	writel(0, port->membase + ALTERA_UART_STATUS_REG);
+	altera_uart_writel(port, 0, ALTERA_UART_STATUS_REG);
 }
 
 static int altera_uart_startup(struct uart_port *port)
@@ -407,6 +421,7 @@ int __init early_altera_uart_setup(struct altera_uart_platform_uart *platp)
 		port->uartclk = platp[i].uartclk;
 		port->flags = ASYNC_BOOT_AUTOCONF;
 		port->ops = &altera_uart_ops;
+		port->private_data = platp;
 	}
 
 	return 0;
@@ -414,7 +429,7 @@ int __init early_altera_uart_setup(struct altera_uart_platform_uart *platp)
 
 static void altera_uart_console_putc(struct uart_port *port, const char c)
 {
-	while (!(readl(port->membase + ALTERA_UART_STATUS_REG) &
+	while (!(altera_uart_readl(port, ALTERA_UART_STATUS_REG) &
 		 ALTERA_UART_STATUS_TRDY_MSK))
 		cpu_relax();
 
@@ -535,6 +550,7 @@ static int __devinit altera_uart_probe(struct platform_device *pdev)
 	port->uartclk = platp->uartclk;
 	port->ops = &altera_uart_ops;
 	port->flags = ASYNC_BOOT_AUTOCONF;
+	port->private_data = platp;
 
 	uart_add_one_port(&altera_uart_driver, port);
 
include/linux/altera_uart.h +1 -0
index 8d44106..c022c82 100644
@@ -9,6 +9,7 @@ struct altera_uart_platform_uart {
 	unsigned long mapbase;	/* Physical address base */
 	unsigned int irq;	/* Interrupt vector */
 	unsigned int uartclk;	/* UART clock rate */
+	unsigned int bus_shift;	/* Bus shift (address stride) */
 };
 
 #endif /* __ALTUART_H */
Signature · 1 line
1.7.0.5
#7 lore raw

PATCH v2 5/8 altera_uart: Make it possible to use Altera UART and 8250 ports together

In reply to Anton Vorontsov

This fixes tty name and major number conflicts. The major number 204 is used across many platform-specific serial drivers, so we use that.

---
 drivers/serial/altera_uart.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)
drivers/serial/altera_uart.c +5 -3
index f1985aa..99e007f 100644
@@ -28,6 +28,7 @@
 #include <linux/altera_uart.h>
 
 #define DRV_NAME "altera_uart"
+#define SERIAL_ALTERA_MAJOR 204
 
 /*
  * Altera UART register definitions according to the Nios UART datasheet:
@@ -471,7 +472,7 @@ static int __init altera_uart_console_setup(struct console *co, char *options)
 static struct uart_driver altera_uart_driver;
 
 static struct console altera_uart_console = {
-	.name	= "ttyS",
+	.name	= "ttyAL",
 	.write	= altera_uart_console_write,
 	.device	= uart_console_device,
 	.setup	= altera_uart_console_setup,
@@ -502,8 +503,8 @@ console_initcall(altera_uart_console_init);
 static struct uart_driver altera_uart_driver = {
 	.owner		= THIS_MODULE,
 	.driver_name	= DRV_NAME,
-	.dev_name	= "ttyS",
-	.major		= TTY_MAJOR,
+	.dev_name	= "ttyAL",
+	.major		= SERIAL_ALTERA_MAJOR,
 	.minor		= 64,
 	.nr		= CONFIG_SERIAL_ALTERA_UART_MAXPORTS,
 	.cons		= ALTERA_UART_CONSOLE,
@@ -603,3 +604,4 @@ MODULE_DESCRIPTION("Altera UART driver");
 MODULE_AUTHOR("Thomas Chou <[email protected]>");
 MODULE_LICENSE("GPL");
 MODULE_ALIAS("platform:" DRV_NAME);
+MODULE_ALIAS_CHARDEV_MAJOR(SERIAL_ALTERA_MAJOR);
Signature · 1 line
1.7.0.5
#15 lore raw

PATCH v2 6/8 altera_uart: Fixup type usage of port flags

In reply to Anton Vorontsov

port->flags is of type upf_t, which corresponds to UPF_* flags.

ASYNC_BOOT_AUTOCONF is an unsigned integer, which happen to be the same as UPF_BOOT_AUTOCONF.

---
 drivers/serial/altera_uart.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/serial/altera_uart.c +2 -2
index 99e007f..304181c 100644
@@ -420,7 +420,7 @@ int __init early_altera_uart_setup(struct altera_uart_platform_uart *platp)
 		port->iotype = SERIAL_IO_MEM;
 		port->irq = platp[i].irq;
 		port->uartclk = platp[i].uartclk;
-		port->flags = ASYNC_BOOT_AUTOCONF;
+		port->flags = UPF_BOOT_AUTOCONF;
 		port->ops = &altera_uart_ops;
 		port->private_data = platp;
 	}
@@ -550,7 +550,7 @@ static int __devinit altera_uart_probe(struct platform_device *pdev)
 	port->iotype = SERIAL_IO_MEM;
 	port->uartclk = platp->uartclk;
 	port->ops = &altera_uart_ops;
-	port->flags = ASYNC_BOOT_AUTOCONF;
+	port->flags = UPF_BOOT_AUTOCONF;
 	port->private_data = platp;
 
 	uart_add_one_port(&altera_uart_driver, port);
Signature · 1 line
1.7.0.5
#17 lore raw

PATCH v2 7/8 altera_uart: Fix missing prototype for registering an early console

In reply to Anton Vorontsov

Simply add an early_altera_uart_setup() prototype declaration, otherwise platform code have to do it in .c files, which is ugly.

---
 include/linux/altera_uart.h |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
include/linux/altera_uart.h +4 -0
index c022c82..a10a907 100644
@@ -5,6 +5,8 @@
 #ifndef	__ALTUART_H
 #define	__ALTUART_H
 
+#include <linux/init.h>
+
 struct altera_uart_platform_uart {
 	unsigned long mapbase;	/* Physical address base */
 	unsigned int irq;	/* Interrupt vector */
@@ -12,4 +14,6 @@ struct altera_uart_platform_uart {
 	unsigned int bus_shift;	/* Bus shift (address stride) */
 };
 
+int __init early_altera_uart_setup(struct altera_uart_platform_uart *platp);
+
 #endif /* __ALTUART_H */
Signature · 1 line
1.7.0.5
#19 lore raw

PATCH v2 8/8 altera_uart: Don't use plain integer as NULL pointer

In reply to Anton Vorontsov

Fixes sparse warning.

---
 drivers/serial/altera_uart.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/serial/altera_uart.c +1 -1
index 304181c..f50097e 100644
@@ -460,7 +460,7 @@ static int __init altera_uart_console_setup(struct console *co, char *options)
 	if (co->index < 0 || co->index >= CONFIG_SERIAL_ALTERA_UART_MAXPORTS)
 		return -EINVAL;
 	port = &altera_uart_ports[co->index].port;
-	if (port->membase == 0)
+	if (!port->membase)
 		return -ENODEV;
 
 	if (options)
Signature · 1 line
1.7.0.5
#8 lore raw

Re: [PATCH 5/8] altera_uart: Make it possible to use Altera UART and 8250 ports together

In reply to Anton Vorontsov
Quoted 3 lines · On Fri, 1 Oct 2010 17:22:07 +0400 Anton Vorontsov <[email protected]>…

This fixes tty name and major number conflicts. The major number 204 is used across many platform-specific serial drivers, so we use that.

204 is allocated in small chunks to specific low volume devices so you need a proper minor allocation

At this point that would be 204,213 for whatever tiny range you need.

Please send me a patch for devices.txt and update accordingly, otherwise no objections.

Alan

#9 lore raw

Re: [PATCH 5/8] altera_uart: Make it possible to use Altera UART and 8250 ports together

In reply to Alan Cox
Quoted 7 lines · Alan Cox
Quoted 3 lines · On Fri, 1 Oct 2010 17:22:07 +0400 Anton Vorontsov <[email protected]>…

This fixes tty name and major number conflicts. The major number 204 is used across many platform-specific serial drivers, so we use that.

Quoted 7 lines

204 is allocated in small chunks to specific low volume devices so you need a proper minor allocation

At this point that would be 204,213 for whatever tiny range you need.

Please send me a patch for devices.txt and update accordingly, otherwise no objections.

Sure thing. Will this work?

Thanks!

- - -
From: Anton Vorontsov <[email protected]>
Subject: lanana: Assign a device name and numbering for Altera UART

Note that Altera UART is usually found on an FPGA solutions, so there could be quite a lot of ports (expanded as needed).

I guess the sane maximum number of ports would be 8, but it is still possible to do hundreds of them.

---
 Documentation/devices.txt |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
Documentation/devices.txt +3 -0
index d0d1df6..984cf24 100644
@@ -2805,6 +2805,9 @@ Your cooperation is appreciated.
 		 210 = /dev/ttyMAX1		MAX3100 serial port 1
 		 211 = /dev/ttyMAX2		MAX3100 serial port 2
 		 212 = /dev/ttyMAX3		MAX3100 serial port 3
+		 213 = /dev/ttyAL0		Altera UART port 0
+		    ...
+		 221 = /dev/ttyAL7		Altera UART port 7
 
 205 char	Low-density serial ports (alternate device)
 		  0 = /dev/culu0		Callout device for ttyLU0
Signature · 1 line
1.7.0.5
#14 lore raw

PATCH v3 5/8 altera_uart: Make it possible to use Altera UART and 8250 ports together

In reply to Anton Vorontsov

This fixes tty name, major and minor numbers. The major number 204 is used across many platform-specific serial drivers, so we use that.

---

Now minor is set to 213.

 drivers/serial/altera_uart.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)
drivers/serial/altera_uart.c +7 -4
index f1985aa..fbc8f8e 100644
@@ -28,6 +28,8 @@
 #include <linux/altera_uart.h>
 
 #define DRV_NAME "altera_uart"
+#define SERIAL_ALTERA_MAJOR 204
+#define SERIAL_ALTERA_MINOR 213
 
 /*
  * Altera UART register definitions according to the Nios UART datasheet:
@@ -471,7 +473,7 @@ static int __init altera_uart_console_setup(struct console *co, char *options)
 static struct uart_driver altera_uart_driver;
 
 static struct console altera_uart_console = {
-	.name	= "ttyS",
+	.name	= "ttyAL",
 	.write	= altera_uart_console_write,
 	.device	= uart_console_device,
 	.setup	= altera_uart_console_setup,
@@ -502,9 +504,9 @@ console_initcall(altera_uart_console_init);
 static struct uart_driver altera_uart_driver = {
 	.owner		= THIS_MODULE,
 	.driver_name	= DRV_NAME,
-	.dev_name	= "ttyS",
-	.major		= TTY_MAJOR,
-	.minor		= 64,
+	.dev_name	= "ttyAL",
+	.major		= SERIAL_ALTERA_MAJOR,
+	.minor		= SERIAL_ALTERA_MINOR,
 	.nr		= CONFIG_SERIAL_ALTERA_UART_MAXPORTS,
 	.cons		= ALTERA_UART_CONSOLE,
 };
@@ -603,3 +605,4 @@ MODULE_DESCRIPTION("Altera UART driver");
 MODULE_AUTHOR("Thomas Chou <[email protected]>");
 MODULE_LICENSE("GPL");
 MODULE_ALIAS("platform:" DRV_NAME);
+MODULE_ALIAS_CHARDEV_MAJOR(SERIAL_ALTERA_MAJOR);
Signature · 1 line
1.7.0.5
#10 lore raw

Re: [PATCH 5/8] altera_uart: Make it possible to use Altera UART and 8250 ports together

In reply to Anton Vorontsov
Quoted 2 lines

I guess the sane maximum number of ports would be 8, but it is still possible to do hundreds of them.

In that case you may just want to allocate a dynamic major instead - or do you actually need a fixed major/minor for your boot up ?

#11 lore raw

Re: [PATCH 5/8] altera_uart: Make it possible to use Altera UART and 8250 ports together

Quoted 5 lines · Alan Cox
Quoted 2 lines

I guess the sane maximum number of ports would be 8, but it is still possible to do hundreds of them.

In that case you may just want to allocate a dynamic major instead - or do you actually need a fixed major/minor for your boot up ?

I don't need it, but someone might.

Plus, it doesn't solve anything as there are only 256 minor numbers. ;-) If we ever want to support the insane number of Altera UARTs, we'll have to solve it very differently. For now, I'd vote for keeping it simple.

Thanks,

Signature · 3 lines
Anton Vorontsov
email: [email protected]
irc://irc.freenode.net/bd2
#12 lore raw

Re: [PATCH 5/8] altera_uart: Make it possible to use Altera UART and 8250 ports together

Quoted 1 line

I don't need it, but someone might.

Why ?

Quoted 4 lines

Plus, it doesn't solve anything as there are only 256 minor numbers. ;-) If we ever want to support the insane number of Altera UARTs, we'll have to solve it very differently. For now, I'd vote for keeping it simple.

We got past the 256/256 limit some time ago.

Alan

#13 lore raw

Re: [PATCH 5/8] altera_uart: Make it possible to use Altera UART and 8250 ports together

Quoted 3 lines · Alan Cox
Quoted 1 line

I don't need it, but someone might.

Why ?

No idea. But why you asked in the first place? :-) I thought you have had some scenario when static major number is necessary.

Quoted 6 lines
Quoted 4 lines

Plus, it doesn't solve anything as there are only 256 minor numbers. ;-) If we ever want to support the insane number of Altera UARTs, we'll have to solve it very differently. For now, I'd vote for keeping it simple.

We got past the 256/256 limit some time ago.

Oh? Then using dynamic major makes a lot of sense, thanks!

Signature · 3 lines
Anton Vorontsov
email: [email protected]
irc://irc.freenode.net/bd2