serial: Add driver for the Altera JTAG UART
Tobias Klauser
maintainerPATCH 1/2 serial: Add driver for the Altera JTAG UART
Add an UART driver for the JTAG UART component available as a SOPC (System on Programmable Chip) component for Altera FPGAs.
--- drivers/serial/Kconfig | 22 ++ drivers/serial/Makefile | 1 + drivers/serial/altera_jtaguart.c | 500 ++++++++++++++++++++++++++++++++++++++ include/linux/altera_jtaguart.h | 16 ++ include/linux/serial_core.h | 3 + 5 files changed, 542 insertions(+), 0 deletions(-) create mode 100644 drivers/serial/altera_jtaguart.c create mode 100644 include/linux/altera_jtaguart.h
drivers/serial/Kconfig +22 -0
@@ -1490,4 +1490,26 @@ config SERIAL_GRLIB_GAISLER_APBUART_CONSOLE help Support for running a console on the GRLIB APBUART +config SERIAL_ALTERA_JTAGUART + bool "Altera JTAG UART support" + depends on EMBEDDED + select SERIAL_CORE + help + This driver supports the Altera JTAG UART port. + +config SERIAL_ALTERA_JTAGUART_CONSOLE + bool "Altera JTAG UART console support" + depends on SERIAL_ALTERA_JTAGUART + select SERIAL_CORE_CONSOLE + help + Enable a Altera JTAG UART port to be the system console. + +config SERIAL_ALTERA_JTAGUART_CONSOLE_BYPASS + bool "Bypass output when no connection" + depends on SERIAL_ALTERA_JTAGUART_CONSOLE + select SERIAL_CORE_CONSOLE + help + Bypass console output and keep going even if there is no + JTAG terminal connection with the host. + endmenu
drivers/serial/Makefile +1 -0
@@ -82,3 +82,4 @@ obj-$(CONFIG_KGDB_SERIAL_CONSOLE) += kgdboc.o obj-$(CONFIG_SERIAL_QE) += ucc_uart.o obj-$(CONFIG_SERIAL_TIMBERDALE) += timbuart.o obj-$(CONFIG_SERIAL_GRLIB_GAISLER_APBUART) += apbuart.o +obj-$(CONFIG_SERIAL_ALTERA_JTAGUART) += altera_jtaguart.o
drivers/serial/altera_jtaguart.c new file +500 -0
500 lines not on this page · raw message
include/linux/altera_jtaguart.h new file +16 -0
@@ -0,0 +1,16 @@ +/* +* altera_jtaguart.h -- Altera JTAG UART driver defines. +*/ + +#ifndef __ALTJUART_H +#define __ALTJUART_H + +#define ALTERA_JTAGUART_MAJOR 204 +#define ALTERA_JTAGUART_MINOR 186 + +struct altera_jtaguart_platform_uart { +unsigned long mapbase;/* Physical address base */ +unsigned int irq;/* Interrupt vector */ +}; + +#endif /* __ALTJUART_H */
include/linux/serial_core.h +3 -0
@@ -182,6 +182,9 @@/* Aeroflex Gaisler GRLIB APBUART */ #define PORT_APBUART 90 +/* Altera UARTs */ +#define PORT_ALTERA_JTAGUART 91 +#ifdef __KERNEL__#include <linux/compiler.h>
Signature · 1 line
1.6.3.3
Tobias Klauser
maintainerPATCH 2/2 serial: Add driver for the Altera UART
Add an UART driver for the UART component available as a SOPC (System on Programmable Chip) component for Altera FPGAs.
--- drivers/serial/Kconfig | 32 ++++++++++++++++++++++++++++++++ drivers/serial/Makefile | 1 + include/linux/serial_core.h | 1 + 3 files changed, 34 insertions(+), 0 deletions(-)
drivers/serial/Kconfig +32 -0
@@ -1512,4 +1512,36 @@ config SERIAL_ALTERA_JTAGUART_CONSOLE_BYPASS Bypass console output and keep going even if there is no JTAG terminal connection with the host. +config SERIAL_ALTERA_UART + bool "Altera UART support" + depends on EMBEDDED + select SERIAL_CORE + help + This driver supports the Altera softcore UART port. + +config SERIAL_ALTERA_UART_MAXPORTS + int "Maximum number of Altera UART ports" + depends on SERIAL_ALTERA_UART + default 4 + help + This setting lets you define the maximum number of the Altera + UART ports. The usual default varies from board to board, and + this setting is a way of catering for that. + +config SERIAL_ALTERA_UART_BAUDRATE + int "Default baudrate for Altera UART ports" + depends on SERIAL_ALTERA_UART + default 115200 + help + This setting lets you define what the default baudrate is for the + Altera UART ports. The usual default varies from board to board, + and this setting is a way of catering for that. + +config SERIAL_ALTERA_UART_CONSOLE + bool "Altera UART console support" + depends on SERIAL_ALTERA_UART + select SERIAL_CORE_CONSOLE + help + Enable a Altera UART port to be the system console. + endmenu
drivers/serial/Makefile +1 -0
@@ -83,3 +83,4 @@ obj-$(CONFIG_SERIAL_QE) += ucc_uart.o obj-$(CONFIG_SERIAL_TIMBERDALE) += timbuart.o obj-$(CONFIG_SERIAL_GRLIB_GAISLER_APBUART) += apbuart.o obj-$(CONFIG_SERIAL_ALTERA_JTAGUART) += altera_jtaguart.o +obj-$(CONFIG_SERIAL_ALTERA_UART) += altera_uart.o
include/linux/serial_core.h +1 -0
@@ -184,6 +184,7 @@/* Altera UARTs */ #define PORT_ALTERA_JTAGUART 91 +#define PORT_ALTERA_UART 92#ifdef __KERNEL__
Signature · 1 line
1.6.3.3
Tobias Klauser
maintainerPATCH RESEND 2/2 serial: Add driver for the Altera UART
In reply to Tobias KlauserSorry, the previous patch was wrong and did not contain the actual driver. This is the corrected patch.
Add an UART driver for the UART component available as a SOPC (System on Programmable Chip) component for Altera FPGAs.
--- drivers/serial/Kconfig | 32 +++ drivers/serial/Makefile | 1 + drivers/serial/altera_uart.c | 585 ++++++++++++++++++++++++++++++++++++++++++ include/linux/altera_uart.h | 14 + include/linux/serial_core.h | 1 + 5 files changed, 633 insertions(+), 0 deletions(-) create mode 100644 drivers/serial/altera_uart.c create mode 100644 include/linux/altera_uart.h
drivers/serial/Kconfig +32 -0
@@ -1512,4 +1512,36 @@ config SERIAL_ALTERA_JTAGUART_CONSOLE_BYPASS Bypass console output and keep going even if there is no JTAG terminal connection with the host. +config SERIAL_ALTERA_UART + bool "Altera UART support" + depends on EMBEDDED + select SERIAL_CORE + help + This driver supports the Altera softcore UART port. + +config SERIAL_ALTERA_UART_MAXPORTS + int "Maximum number of Altera UART ports" + depends on SERIAL_ALTERA_UART + default 4 + help + This setting lets you define the maximum number of the Altera + UART ports. The usual default varies from board to board, and + this setting is a way of catering for that. + +config SERIAL_ALTERA_UART_BAUDRATE + int "Default baudrate for Altera UART ports" + depends on SERIAL_ALTERA_UART + default 115200 + help + This setting lets you define what the default baudrate is for the + Altera UART ports. The usual default varies from board to board, + and this setting is a way of catering for that. + +config SERIAL_ALTERA_UART_CONSOLE + bool "Altera UART console support" + depends on SERIAL_ALTERA_UART + select SERIAL_CORE_CONSOLE + help + Enable a Altera UART port to be the system console. + endmenu
drivers/serial/Makefile +1 -0
@@ -83,3 +83,4 @@ obj-$(CONFIG_SERIAL_QE) += ucc_uart.o obj-$(CONFIG_SERIAL_TIMBERDALE) += timbuart.o obj-$(CONFIG_SERIAL_GRLIB_GAISLER_APBUART) += apbuart.o obj-$(CONFIG_SERIAL_ALTERA_JTAGUART) += altera_jtaguart.o +obj-$(CONFIG_SERIAL_ALTERA_UART) += altera_uart.o
drivers/serial/altera_uart.c new file +585 -0
585 lines not on this page · raw message
include/linux/altera_uart.h new file +14 -0
@@ -0,0 +1,14 @@ +/* +* altera_uart.h -- Altera UART driver defines. +*/ + +#ifndef __ALTUART_H +#define __ALTUART_H + +struct altera_uart_platform_uart { +unsigned long mapbase;/* Physical address base */ +unsigned int irq;/* Interrupt vector */ +unsigned int uartclk;/* UART clock rate */ +}; + +#endif /* __ALTUART_H */
include/linux/serial_core.h +1 -0
@@ -184,6 +184,7 @@/* Altera UARTs */ #define PORT_ALTERA_JTAGUART 91 +#define PORT_ALTERA_UART 92#ifdef __KERNEL__
Signature · 1 line
1.6.3.3
Re: [RESEND PATCH 2/2] serial: Add driver for the Altera UART
A couple smatch complaints.
drivers/serial/altera_jtaguart.c
380 if (co->index >= 0 && co->index <= ALTERA_JTAGUART_MAXPORTS)
381 co->index = 0;
382 port = &altera_jtaguart_ports[co->index].port;
This test seems backward. co->index == -1 would be a buffer underflow.
drivers/serial/altera_uart.c
455 if ((co->index >= 0)
456 && (co->index <= CONFIG_SERIAL_ALTERA_UART_MAXPORTS))
457 co->index = 0;
458 port = &altera_uart_ports[co->index].port;
Same here.
regards,
dan carpenter
Tobias Klauser
maintainerRe: [RESEND PATCH 2/2] serial: Add driver for the Altera UART
Quoted 9 lines · Dan Carpenter
A couple smatch complaints.
drivers/serial/altera_jtaguart.c
380 if (co->index>= 0 &&co->index<=ALTERA_JTAGUART_MAXPORTS)381 co->index = 0; 382 port = &altera_jtaguart_ports[co->index].port;This test seems backward.
co->index== -1 would be a buffer underflow.
Quoted 7 lines
drivers/serial/altera_uart.c
455 if ((co->index>= 0)
456 && (co->index<=CONFIG_SERIAL_ALTERA_UART_MAXPORTS))457 co->index = 0; 458 port = &altera_uart_ports[co->index].port;Same here.
Yep, those look completely wrong. I'll post an updated patch (including the other changes suggested by Alan and Peter) later on.
Thanks,
Tobias
drivers/serial/altera_jtaguart.c line 119
Quoted 5 lines
drivers/serial/altera_jtaguart.c new file +5
-0+static void altera_jtaguart_set_termios (struct uart_port *port, +struct ktermios *termios, +struct ktermios *old) +{ +}
Erm no .. it may be wrong in the code you are copying but please don't further that. The requirement is that the termios handed back reflects the actual settings not the requested ones.
Use tty_termios_copy_hw() to copy the old termios hardware settings back so that the caller sees it cannot set them.
Quoted 9 lines
drivers/serial/altera_jtaguart.c new file +9
-0+ +static void altera_jtaguart_rx_chars (struct altera_jtaguart *pp) +{ +struct uart_port *port = &pp->port; +unsigned char ch, flag; +unsigned long status; + +while ((status =readl (port->membase +ALTERA_JTAGUART_DATA_REG )) & +ALTERA_JTAGUART_DATA_RVALID_MSK ) {
drivers/serial/altera_jtaguart.c line 138
Quoted 10 lines
drivers/serial/altera_jtaguart.c new file +10
-0+ ch = status &ALTERA_JTAGUART_DATA_DATA_MSK ; + flag =TTY_NORMAL ; + port->icount.rx++; + +if (uart_handle_sysrq_char (port, ch)) +continue ; +uart_insert_char (port,0 ,0 , ch, flag); + } + +tty_flip_buffer_push (port->state->port.tty);
port.tty needs to be protected here - you might race an unplug/hangup as far as I can see - I think you need to take the lock over a bigger area
[I'm working on switching this to krefs in all the drivers currently so that will end up cleaner]
Basically fine other than that. The proposed UART number clashes with some other pending patches but that will get sorted out when they get merged
Tobias Klauser
maintainerQuoted 10 lines · Alan Cox
drivers/serial/altera_jtaguart.c line 119
Quoted 5 lines
drivers/serial/altera_jtaguart.c new file +5
-0+static void altera_jtaguart_set_termios (struct uart_port *port, +struct ktermios *termios, +struct ktermios *old) +{ +}Erm no .. it may be wrong in the code you are copying but please don't further that. The requirement is that the termios handed back reflects the actual settings not the requested ones.
Quoted 2 lines
Use
tty_termios_copy_hw()to copy the old termios hardware settings back so that the caller sees it cannot set them.
Would the following be sufficient?
if (old)
tty_termios_copy_hw(termios, old);Quoted 13 lines
Quoted 13 lines
drivers/serial/altera_jtaguart.c new file +13
-0+static void altera_jtaguart_rx_chars (struct altera_jtaguart *pp) +{ +struct uart_port *port = &pp->port; +unsigned char ch, flag; +unsigned long status; + +while ((status =readl (port->membase +ALTERA_JTAGUART_DATA_REG )) & +ALTERA_JTAGUART_DATA_RVALID_MSK ) { + ch = status &ALTERA_JTAGUART_DATA_DATA_MSK ; + flag =TTY_NORMAL ; + port->icount.rx++; + +if (uart_handle_sysrq_char (port, ch))
Quoted 8 lines
drivers/serial/altera_jtaguart.c line 138
Quoted 5 lines
drivers/serial/altera_jtaguart.c new file +5
-0+continue ; +uart_insert_char (port,0 ,0 , ch, flag); + } + +tty_flip_buffer_push (port->state->port.tty);port.tty needs to be protected here - you might race an unplug/hangup as far as I can see - I think you need to take the lock over a bigger area
So should we take port->lock in altera_jtaguart_interrupt already, something like the following?
spin_lock(&port->lock);
if (isr & ALTERA_JTAGUART_CONTROL_RE_MSK)
altera_jtaguart_rx_chars(pp);
if (isr & ALTERA_JTAGUART_CONTROL_WE_MSK)
altera_jtaguart_tx_chars(pp);
spin_unlock(&port->lock);And of course remove the lock/unlock from altera_jtaguart_tx_chars.
Quoted 6 lines
[I'm working on switching this to krefs in all the drivers currently so that will end up cleaner]
Basically fine other than that. The proposed UART number clashes with some other pending patches but that will get sorted out when they get merged
Thanks a lot for your review.
Tobias
Quoted 7 lines
Quoted 2 lines
Use
tty_termios_copy_hw()to copy the old termios hardware settings back so that the caller sees it cannot set them.Would the following be sufficient?
if (old) tty_termios_copy_hw(termios, old);
That will do the trick yes.
Quoted 8 lines
spin_lock(&port->lock);
if (isr & ALTERA_JTAGUART_CONTROL_RE_MSK)
altera_jtaguart_rx_chars(pp);
if (isr & ALTERA_JTAGUART_CONTROL_WE_MSK)
altera_jtaguart_tx_chars(pp);
spin_unlock(&port->lock);Yes - that stops ->tty becoming NULL while your handler is running
Alan
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Tobias" == Tobias Klauser <[email protected]> writes:
Tobias> Add an UART driver for the JTAG UART component available as a SOPC Tobias> (System on Programmable Chip) component for Altera FPGAs.
Tobias> Signed-off-by: Tobias Klauser <[email protected]>
Tobias> +config SERIAL_ALTERA_JTAGUART
Tobias> + bool "Altera JTAG UART support"
Tobias> + depends on EMBEDDED
Don't depend on EMBEDDED - There's embedded devices not using CONFIG_EMBEDDED and kernel configs for PCs using it.
Signature · 1 line
Bye, Peter Korsgaard
Tobias Klauser
maintainerQuoted 5 lines · Peter Korsgaard
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Tobias" == Tobias Klauser <[email protected]> writes:
Tobias> Add an UART driver for the JTAG UART component available as a SOPC Tobias> (System on Programmable Chip) component for Altera FPGAs.
Quoted 8 lines
Tobias> Signed-off-by: Tobias Klauser <[email protected]>
Tobias> +config
SERIAL_ALTERA_JTAGUART
Tobias> + bool "Altera JTAG UART support"
Tobias> + depends on EMBEDDEDDon't depend on EMBEDDED - There's embedded devices not using
CONFIG_EMBEDDEDand kernel configs for PCs using it.
I'll remove the dependency for bot altera_jtaguart and altera_uart.
Thanks a lot,
Tobias