More atmel_serial updates
cover More atmel_serial updates
Hi,
Now that Andrew Victor seems to be happy about the renaming (thanks a lot for reviewing, Andrew), here are a few more patches to make atmel_serial usable for AVR32, as well as a general bugfix.
I've dropped the break fix for now, as it doesn't seem to work on my AT91RM9200-EK board. I'll see if I can fix it properly later -- it's not really a showstopper, for me anyway.
There's also a pure AVR32 patch in this set. Feel free to ignore it, but I thought I'd include it so that you can see the whole picture.
Shortlog and diffstat for the whole series follows.
Haavard
Haavard Skinnemoen:
atmel_serial: Pass fixed register mappings through platform_data
atmel_serial: Support AVR32
AVR32: Allow renumbering of serial devices
atmel_serial: Fix roundoff error in atmel_console_get_options
arch/arm/mach-at91rm9200/devices.c | 1 + arch/avr32/boards/atstk1000/atstk1002.c | 16 ++++++++- arch/avr32/kernel/setup.c | 1 + arch/avr32/mach-at32ap/at32ap.c | 3 -- arch/avr32/mach-at32ap/at32ap7000.c | 53 +++++++++++++++++++++---------- drivers/serial/Kconfig | 24 +++++++------- drivers/serial/atmel_serial.c | 17 ++++++++-- include/asm-arm/arch-at91rm9200/board.h | 1 + include/asm-avr32/arch-at32ap/board.h | 6 ++++ include/asm-avr32/arch-at32ap/init.h | 1 + 10 files changed, 85 insertions(+), 38 deletions(-)
PATCH 1/4 atmel_serial: Pass fixed register mappings through platform_data
In order to initialize the serial console early, the atmel_serial driver had to do a hack where it compared the physical address of the port with an address known to be permanently mapped, and used it as a virtual address. This got around the limitation that ioremap() isn't always available when the console is being initalized.
This patch removes that hack and replaces it with a new "regs" field in struct atmel_uart_data that the board-specific code can initialize to a fixed virtual mapping for platform devices where this is possible. It also initializes the DBGU's regs field with the address the driver used to check against.
On AVR32, the "regs" field is initialized from the physical base address when this it can be accessed through a permanently 1:1 mapped segment, i.e. the P4 segment.
If regs is NULL, the console initialization is delayed until the "real" driver is up and running and ioremap() can be used.
--- arch/arm/mach-at91rm9200/devices.c | 1 + arch/avr32/mach-at32ap/at32ap7000.c | 33 +++++++++++++++++++++++++------ drivers/serial/atmel_serial.c | 5 +++-- include/asm-arm/arch-at91rm9200/board.h | 1 + include/asm-avr32/arch-at32ap/board.h | 5 +++++ 5 files changed, 37 insertions(+), 8 deletions(-)
arch/arm/mach-at91rm9200/devices.c +1 -0
@@ -561,6 +561,7 @@ static struct resource dbgu_resources[]static struct atmel_uart_data dbgu_data = { .use_dma_tx =0 , .use_dma_rx =0 ,/* DBGU not capable of receive DMA */ + .regs = (void __iomem *)(AT91_VA_BASE_SYS +AT91_DBGU ), };static struct platform_device at91rm9200_dbgu_device = {
arch/avr32/mach-at32ap/at32ap7000.c +27 -6
@@ -523,32 +523,48 @@ void __init at32_add_system_devices(void* USART * -------------------------------------------------------------------- */ +static struct atmel_uart_data atmel_usart0_data = { + .use_dma_tx =1 , + .use_dma_rx =1 , +};static struct resource atmel_usart0_resource[] = {PBMEM (0xffe00c00 ),IRQ (7 ), }; -DEFINE_DEV (atmel_usart,0 ); +DEFINE_DEV_DATA (atmel_usart,0 );DEV_CLK (usart, atmel_usart0, pba,4 ); +static struct atmel_uart_data atmel_usart1_data = { + .use_dma_tx =1 , + .use_dma_rx =1 , +};static struct resource atmel_usart1_resource[] = {PBMEM (0xffe01000 ),IRQ (7 ), }; -DEFINE_DEV (atmel_usart,1 ); +DEFINE_DEV_DATA (atmel_usart,1 );DEV_CLK (usart, atmel_usart1, pba,4 ); +static struct atmel_uart_data atmel_usart2_data = { + .use_dma_tx =1 , + .use_dma_rx =1 , +};static struct resource atmel_usart2_resource[] = {PBMEM (0xffe01400 ),IRQ (8 ), }; -DEFINE_DEV (atmel_usart,2 ); +DEFINE_DEV_DATA (atmel_usart,2 );DEV_CLK (usart, atmel_usart2, pba,5 ); +static struct atmel_uart_data atmel_usart3_data = { + .use_dma_tx =1 , + .use_dma_rx =1 , +};static struct resource atmel_usart3_resource[] = {PBMEM (0xffe01800 ),IRQ (9 ), }; -DEFINE_DEV (atmel_usart,3 ); +DEFINE_DEV_DATA (atmel_usart,3 );DEV_CLK (usart, atmel_usart3, pba,6 );static inline void configure_usart0_pins (void )
@@ -597,8 +613,13 @@ static struct platform_device *setup_usaconfigure_usart3_pins ();break ;default : - pdev =NULL ; -break ; +return NULL ; + } + +if (PXSEG (pdev->resource[0 ].start) ==P4SEG ) { +/* Addresses in the P4 segment are permanently mapped 1:1 */ +struct atmel_uart_data *data = pdev->dev.platform_data; + data->regs = (void __iomem *)pdev->resource[0 ].start; }return pdev;
drivers/serial/atmel_serial.c +3 -2
@@ -694,8 +694,9 @@ static void __devinit atmel_init_port(st port->mapbase = pdev->resource[0 ].start; port->irq = pdev->resource[1 ].start; -if (port->mapbase ==AT91_VA_BASE_SYS +AT91_DBGU )/* Part of system perpherals - already mapped */ - port->membase = (void __iomem *) port->mapbase; +if (data->regs) +/* Already mapped by setup code */ + port->membase = data->regs;else { port->flags |=UPF_IOREMAP ; port->membase =NULL ;
include/asm-arm/arch-at91rm9200/board.h +1 -0
@@ -103,6 +103,7 @@ extern void __init at91_init_serial(strustruct atmel_uart_data {short use_dma_tx;/* use transmit DMA? */ short use_dma_rx;/* use receive DMA? */ +void __iomem *regs;/* virtual base address, if any */ };extern void __init at91_add_device_serial (void );
include/asm-avr32/arch-at32ap/board.h +5 -0
@@ -12,6 +12,11 @@ void at32_add_system_devices(void);#define ATMEL_MAX_UART 4extern struct platform_device *atmel_default_console_device; +struct atmel_uart_data { +short use_dma_tx;/* use transmit DMA? */ +short use_dma_rx;/* use receive DMA? */ +void __iomem *regs;/* virtual base address, if any */ +};struct platform_device *at32_add_device_usart (unsigned int id);struct eth_platform_data {
Signature · 1 line
1.4.1.1
PATCH 2/4 atmel_serial: Support AVR32
Make CONFIG_SERIAL_ATMEL selectable on AVR32 and #ifdef out some ARM- specific code in the driver.
--- drivers/serial/Kconfig | 24 ++++++++++++------------ drivers/serial/atmel_serial.c | 4 ++++ 2 files changed, 16 insertions(+), 12 deletions(-)
drivers/serial/Kconfig +12 -12
@@ -301,31 +301,31 @@ config SERIAL_AMBA_PL011_CONSOLE config SERIAL_ATMEL bool "AT91 / AT32 on-chip serial port support" - depends on ARM && (ARCH_AT91RM9200 || ARCH_AT91SAM9261) + depends on ARM && (ARCH_AT91RM9200 || ARCH_AT91SAM9261) || AVR32 select SERIAL_CORE help This enables the driver for the on-chip UARTs of the Atmel - AT91RM9200 and AT91SAM926 processor. + AT91RM9200, AT91SAM926 and AT32AP7000 processors. config SERIAL_ATMEL_CONSOLE bool "Support for console on AT91 / AT32 serial port" depends on SERIAL_ATMEL=y select SERIAL_CORE_CONSOLE help - Say Y here if you wish to use a UART on the Atmel AT91RM9200 or - AT91SAM9261 as the system console (the system console is the device - which receives all kernel messages and warnings and which allows - logins in single user mode). + Say Y here if you wish to use a UART on the Atmel AT91RM9200, + AT91SAM9261 or AT32AP7000 as the system console (the system + console is the device which receives all kernel messages and + warnings and which allows logins in single user mode). config SERIAL_ATMEL_TTYAT - bool "Install as device ttyAT0-4 instead of ttyS0-4" + bool "Install as device ttyATn instead of ttySn" depends on SERIAL_ATMEL=y help - Say Y here if you wish to have the five internal AT91RM9200 UARTs - appear as /dev/ttyAT0-4 (major 204, minor 154-158) instead of the - normal /dev/ttyS0-4 (major 4, minor 64-68). This is necessary if - you also want other UARTs, such as external 8250/16C550 compatible - UARTs. + Say Y here if you wish to have the internal AT91 / AT32 UARTs + appear as /dev/ttyATn (major 204, minor starting at 154) + instead of the normal /dev/ttySn (major 4, minor starting at + 64). This is necessary if you also want other UARTs, such as + external 8250/16C550 compatible UARTs. The ttySn nodes are legally reserved for the 8250 serial driver but are often misused by other serial drivers.
drivers/serial/atmel_serial.c +4 -0
@@ -39,8 +39,10 @@ #include <asm/io.h>#include <asm/arch/at91rm9200_pdc.h> #include <asm/mach/serial_at91.h> #include <asm/arch/board.h> +#ifdef CONFIG_ARM #include <asm/arch/system.h> #include <asm/arch/gpio.h> +#endif #include "atmel_serial.h"
@@ -135,6 +137,7 @@ static void atmel_set_mctrl(struct uart_unsigned int control =0 ;unsigned int mode; +#ifdef CONFIG_ARM if (arch_identify () ==ARCH_ID_AT91RM9200 ) {/* * AT91RM9200 Errata #39: RTS0 is not internally connected to PA21.
@@ -147,6 +150,7 @@ static void atmel_set_mctrl(struct uart_ at91_set_gpio_value(AT91_PIN_PA21, 1); } } +#endif if (mctrl &TIOCM_RTS ) control |=ATMEL_US_RTSEN ;
Signature · 1 line
1.4.1.1
PATCH 3/4 AVR32: Allow renumbering of serial devices
Allow the board to remap actual USART peripheral devices to serial devices by calling at32_map_usart(hw_id, serial_line). This ensures that even though ATSTK1002 uses USART1 as the first serial port, it will still have a ttyS0 device.
This also adds a board-specific early setup hook and moves the at32_setup_serial_console() call there from the platform code.
--- arch/avr32/boards/atstk1000/atstk1002.c | 16 +++++++++++++--- arch/avr32/kernel/setup.c | 1 + arch/avr32/mach-at32ap/at32ap.c | 3 --- arch/avr32/mach-at32ap/at32ap7000.c | 22 ++++++++++------------ include/asm-avr32/arch-at32ap/board.h | 1 + include/asm-avr32/arch-at32ap/init.h | 1 + 6 files changed, 26 insertions(+), 18 deletions(-)
arch/avr32/boards/atstk1000/atstk1002.c +13 -3
@@ -10,6 +10,7 @@#include <linux/init.h> #include <asm/arch/board.h> +#include <asm/arch/init.h> struct eth_platform_data __initdata eth0_data = { .valid =1 ,
@@ -20,13 +21,22 @@ struct eth_platform_data __initdata eth0extern struct lcdc_platform_data atstk1000_fb0_data; +void __init setup_board (void ) +{ +at32_map_usart (1 ,0 );/* /dev/ttyS0 */ +at32_map_usart (2 ,1 );/* /dev/ttyS1 */ +at32_map_usart (3 ,2 );/* /dev/ttyS2 */ + +at32_setup_serial_console (0 ); +} +static int __init atstk1002_init (void ) {at32_add_system_devices (); -at32_add_device_usart (1 );/* /dev/ttyS0 */ -at32_add_device_usart (2 );/* /dev/ttyS1 */ -at32_add_device_usart (3 );/* /dev/ttyS2 */ +at32_add_device_usart (0 ); +at32_add_device_usart (1 ); +at32_add_device_usart (2 );at32_add_device_eth (0 , ð0_data);at32_add_device_spi (0 );
arch/avr32/kernel/setup.c +1 -0
@@ -292,6 +292,7 @@ void __init setup_arch (char **cmdline_psetup_processor ();setup_platform (); +setup_board (); cpu_clk =clk_get (NULL ,"cpu" );if (IS_ERR (cpu_clk)) {
arch/avr32/mach-at32ap/at32ap.c +0 -3
@@ -48,9 +48,6 @@ void __init setup_platform(void)at32_sm_init ();at32_clock_init ();at32_portmux_init (); - -/* FIXME: This doesn't belong here */ -at32_setup_serial_console (1 ); }static int __init pdc_probe (struct platform_device *pdev)
arch/avr32/mach-at32ap/at32ap7000.c +10 -12
@@ -591,11 +591,13 @@ static inline void configure_usart3_pinsportmux_set_func (PIOB ,17 ,FUNC_B );/* TXD */ } -static struct platform_device *setup_usart (unsigned int id) +static struct platform_device *at32_usarts[4 ]; + +void __init at32_map_usart (unsigned int hw_id,unsigned int line) {struct platform_device *pdev; -switch (id) { +switch (hw_id) {case 0 : pdev = &atmel_usart0_device;configure_usart0_pins ();
@@ -613,7 +615,7 @@ static struct platform_device *setup_usaconfigure_usart3_pins ();break ;default : -return NULL ; +return ; }if (PXSEG (pdev->resource[0 ].start) ==P4SEG ) {
@@ -622,25 +624,21 @@ static struct platform_device *setup_usa data->regs = (void __iomem *)pdev->resource[0 ].start; } -return pdev; + pdev->id = line; + at32_usarts[line] = pdev; }struct platform_device *__init at32_add_device_usart (unsigned int id) { -struct platform_device *pdev; - - pdev =setup_usart (id); -if (pdev) -platform_device_register (pdev); - -return pdev; +platform_device_register (at32_usarts[id]); +return at32_usarts[id]; }struct platform_device *atmel_default_console_device;void __init at32_setup_serial_console (unsigned int usart_id) { - atmel_default_console_device =setup_usart (usart_id); + atmel_default_console_device = at32_usarts[usart_id]; }/* --------------------------------------------------------------------
include/asm-avr32/arch-at32ap/board.h +1 -0
@@ -17,6 +17,7 @@ struct atmel_uart_data {short use_dma_rx;/* use receive DMA? */ void __iomem *regs;/* virtual base address, if any */ }; +void at32_map_usart (unsigned int hw_id,unsigned int line);struct platform_device *at32_add_device_usart (unsigned int id);struct eth_platform_data {
include/asm-avr32/arch-at32ap/init.h +1 -0
@@ -11,6 +11,7 @@ #ifndef __ASM_AVR32_AT32AP_INIT_H__#define __ASM_AVR32_AT32AP_INIT_H__void setup_platform (void ); +void setup_board (void );/* Called by setup_platform */ void at32_clock_init (void );
Signature · 1 line
1.4.1.1
PATCH 4/4 atmel_serial: Fix roundoff error in atmel_console_get_options
The atmel_console_get_options() function initializes the baud, parity and bits settings from the actual hardware setup, in case it has been initialized by a e.g. boot loader.
The baud rate, however, is not necessarily exactly equal to one of the standard baud rates (115200, etc.) This means that the baud rate calculated by this function may be slightly higher or slightly lower than one of the standard baud rates.
If the baud rate is slightly lower than the target, this causes problems when uart_set_option() tries to match the detected baud rate against the standard baud rate, as it will always select a baud rate that is lower or equal to the target rate. For example if the detected baud rate is slightly lower than 115200, usart_set_options() will select 57600.
This patch fixes the problem by subtracting 1 from the value in BRGR when calculating the baud rate. The detected baud rate will thus always be higher than the nearest standard baud rate, and uart_set_options() will end up doing the right thing.
Tested on ATSTK1000 and AT91RM9200-EK boards. Both are broken without this patch.
--- drivers/serial/atmel_serial.c | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-)
drivers/serial/atmel_serial.c +7 -1
@@ -793,8 +793,14 @@ static void __init atmel_console_get_optelse if (mr ==ATMEL_US_PAR_ODD ) *parity ='o' ; +/* +* The serial core only rounds down when matching this to a +* supported baud rate. Make sure we don't end up slightly +* lower than one of those, as it would make us fall through +* to a much lower baud rate than we really want. +*/ quot =UART_GET_BRGR (port); - *baud = port->uartclk / (16 * (quot)); + *baud = port->uartclk / (16 * (quot -1 )); }static int __init atmel_console_setup (struct console *co,char *options)
Signature · 1 line
1.4.1.1
Re: [PATCH 2/4] atmel_serial: Support AVR32
In reply to Haavard SkinnemoenQuoted 2 lines · On Thu, 28 Sep 2006 15:31:40 +0200 Haavard Skinnemoen <[email protected]>…
Make
CONFIG_SERIAL_ATMELselectable on AVR32 and #ifdef out some ARM- specific code in the driver.
Hmm...the dependency changes I promised to make got left out during the final git-reset/git-am/git-format-patch shuffling. This patch includes them.
Haavard
---
From: Haavard Skinnemoen <[email protected]>
Subject: [PATCH 2/4] atmel_serial: Support AVR32
Make CONFIG_SERIAL_ATMEL selectable on AVR32 and #ifdef out some ARM- specific code in the driver.
Also simplify the ARM dependencies a bit. This driver is usable on all AT91 parts, and ARCH_AT91 implies ARCH_AT91RM9200 || ARCH_AT91SAM9261 as well as any future AT91 parts.
--- drivers/serial/Kconfig | 24 ++++++++++++------------ drivers/serial/atmel_serial.c | 4 ++++ 2 files changed, 16 insertions(+), 12 deletions(-)
drivers/serial/Kconfig +12 -12
@@ -301,31 +301,31 @@ config SERIAL_AMBA_PL011_CONSOLE config SERIAL_ATMEL bool "AT91 / AT32 on-chip serial port support" - depends on ARM && (ARCH_AT91RM9200 || ARCH_AT91SAM9261) + depends on (ARM && ARCH_AT91) || AVR32 select SERIAL_CORE help This enables the driver for the on-chip UARTs of the Atmel - AT91RM9200 and AT91SAM926 processor. + AT91 and AT32 processors. config SERIAL_ATMEL_CONSOLE bool "Support for console on AT91 / AT32 serial port" depends on SERIAL_ATMEL=y select SERIAL_CORE_CONSOLE help - Say Y here if you wish to use a UART on the Atmel AT91RM9200 or - AT91SAM9261 as the system console (the system console is the device - which receives all kernel messages and warnings and which allows - logins in single user mode). + Say Y here if you wish to use an on-chip UART on a Atmel + AT91 or AT32 processor as the system console (the system + console is the device which receives all kernel messages and + warnings and which allows logins in single user mode). config SERIAL_ATMEL_TTYAT - bool "Install as device ttyAT0-4 instead of ttyS0-4" + bool "Install as device ttyATn instead of ttySn" depends on SERIAL_ATMEL=y help - Say Y here if you wish to have the five internal AT91RM9200 UARTs - appear as /dev/ttyAT0-4 (major 204, minor 154-158) instead of the - normal /dev/ttyS0-4 (major 4, minor 64-68). This is necessary if - you also want other UARTs, such as external 8250/16C550 compatible - UARTs. + Say Y here if you wish to have the internal AT91 / AT32 UARTs + appear as /dev/ttyATn (major 204, minor starting at 154) + instead of the normal /dev/ttySn (major 4, minor starting at + 64). This is necessary if you also want other UARTs, such as + external 8250/16C550 compatible UARTs. The ttySn nodes are legally reserved for the 8250 serial driver but are often misused by other serial drivers.
drivers/serial/atmel_serial.c +4 -0
@@ -39,8 +39,10 @@ #include <asm/io.h>#include <asm/arch/at91rm9200_pdc.h> #include <asm/mach/serial_at91.h> #include <asm/arch/board.h> +#ifdef CONFIG_ARM #include <asm/arch/system.h> #include <asm/arch/gpio.h> +#endif #include "atmel_serial.h"
@@ -135,6 +137,7 @@ static void atmel_set_mctrl(struct uart_unsigned int control =0 ;unsigned int mode; +#ifdef CONFIG_ARM if (arch_identify () ==ARCH_ID_AT91RM9200 ) {/* * AT91RM9200 Errata #39: RTS0 is not internally connected to PA21.
@@ -147,6 +150,7 @@ static void atmel_set_mctrl(struct uart_ at91_set_gpio_value(AT91_PIN_PA21, 1); } } +#endif if (mctrl &TIOCM_RTS ) control |=ATMEL_US_RTSEN ;
Signature · 1 line
1.4.1.1