2009-04-01 08:54:48

by Haavard Skinnemoen

[permalink] [raw]
Subject: [PATCH 1/2] avr32: add RTS/CTS/CLK pin selection for the USARTs

From: Peter Ma <[email protected]>

Adds extra parameter to AT32 at32_map_usart(), so as to reserve
RTS/CTS/CLK pins.

All boards under arch/avr32/boards have been updated (trivial change), but
not all have been tested.

Signed-off-by: Peter Ma <[email protected]>
Signed-off-by: Haavard Skinnemoen <[email protected]>
---
This first patch is mostly FYI, as I intend to merge this through the
avr32 tree, but I figured it might help you to do something similar to
enable hardware handshaking on AT91.

I can take the second patch through the avr32 tree as well if someone
ACKs it.

arch/avr32/boards/atngw100/setup.c | 2 +-
arch/avr32/boards/atstk1000/atstk1002.c | 6 ++--
arch/avr32/boards/atstk1000/atstk1003.c | 6 ++--
arch/avr32/boards/atstk1000/atstk1004.c | 6 ++--
arch/avr32/boards/favr-32/setup.c | 2 +-
arch/avr32/boards/hammerhead/setup.c | 2 +-
arch/avr32/boards/mimc200/setup.c | 8 +++---
arch/avr32/mach-at32ap/at32ap700x.c | 30 ++++++++++++++++++--------
arch/avr32/mach-at32ap/include/mach/board.h | 7 +++++-
9 files changed, 43 insertions(+), 26 deletions(-)

diff --git a/arch/avr32/boards/atngw100/setup.c b/arch/avr32/boards/atngw100/setup.c
index feac003..5b022aa 100644
--- a/arch/avr32/boards/atngw100/setup.c
+++ b/arch/avr32/boards/atngw100/setup.c
@@ -118,7 +118,7 @@ static void __init set_hw_addr(struct platform_device *pdev)

void __init setup_board(void)
{
- at32_map_usart(1, 0); /* USART 1: /dev/ttyS0, DB9 */
+ at32_map_usart(1, 0, 0); /* USART 1: /dev/ttyS0, DB9 */
at32_setup_serial_console(0);
}

diff --git a/arch/avr32/boards/atstk1000/atstk1002.c b/arch/avr32/boards/atstk1000/atstk1002.c
index 1f33a10..2adc261 100644
--- a/arch/avr32/boards/atstk1000/atstk1002.c
+++ b/arch/avr32/boards/atstk1000/atstk1002.c
@@ -252,12 +252,12 @@ static void __init atstk1002_setup_extdac(void)
void __init setup_board(void)
{
#ifdef CONFIG_BOARD_ATSTK100X_SW2_CUSTOM
- at32_map_usart(0, 1); /* USART 0/B: /dev/ttyS1, IRDA */
+ at32_map_usart(0, 1, 0); /* USART 0/B: /dev/ttyS1, IRDA */
#else
- at32_map_usart(1, 0); /* USART 1/A: /dev/ttyS0, DB9 */
+ at32_map_usart(1, 0, 0); /* USART 1/A: /dev/ttyS0, DB9 */
#endif
/* USART 2/unused: expansion connector */
- at32_map_usart(3, 2); /* USART 3/C: /dev/ttyS2, DB9 */
+ at32_map_usart(3, 2, 0); /* USART 3/C: /dev/ttyS2, DB9 */

at32_setup_serial_console(0);
}
diff --git a/arch/avr32/boards/atstk1000/atstk1003.c b/arch/avr32/boards/atstk1000/atstk1003.c
index b3a23c8..ff7e232 100644
--- a/arch/avr32/boards/atstk1000/atstk1003.c
+++ b/arch/avr32/boards/atstk1000/atstk1003.c
@@ -115,12 +115,12 @@ static void __init atstk1003_setup_extdac(void)
void __init setup_board(void)
{
#ifdef CONFIG_BOARD_ATSTK100X_SW2_CUSTOM
- at32_map_usart(0, 1); /* USART 0/B: /dev/ttyS1, IRDA */
+ at32_map_usart(0, 1, 0); /* USART 0/B: /dev/ttyS1, IRDA */
#else
- at32_map_usart(1, 0); /* USART 1/A: /dev/ttyS0, DB9 */
+ at32_map_usart(1, 0, 0); /* USART 1/A: /dev/ttyS0, DB9 */
#endif
/* USART 2/unused: expansion connector */
- at32_map_usart(3, 2); /* USART 3/C: /dev/ttyS2, DB9 */
+ at32_map_usart(3, 2, 0); /* USART 3/C: /dev/ttyS2, DB9 */

at32_setup_serial_console(0);
}
diff --git a/arch/avr32/boards/atstk1000/atstk1004.c b/arch/avr32/boards/atstk1000/atstk1004.c
index 29b35ac..69a9f0f 100644
--- a/arch/avr32/boards/atstk1000/atstk1004.c
+++ b/arch/avr32/boards/atstk1000/atstk1004.c
@@ -120,12 +120,12 @@ static void __init atstk1004_setup_extdac(void)
void __init setup_board(void)
{
#ifdef CONFIG_BOARD_ATSTK100X_SW2_CUSTOM
- at32_map_usart(0, 1); /* USART 0/B: /dev/ttyS1, IRDA */
+ at32_map_usart(0, 1, 0); /* USART 0/B: /dev/ttyS1, IRDA */
#else
- at32_map_usart(1, 0); /* USART 1/A: /dev/ttyS0, DB9 */
+ at32_map_usart(1, 0, 0); /* USART 1/A: /dev/ttyS0, DB9 */
#endif
/* USART 2/unused: expansion connector */
- at32_map_usart(3, 2); /* USART 3/C: /dev/ttyS2, DB9 */
+ at32_map_usart(3, 2, 0); /* USART 3/C: /dev/ttyS2, DB9 */

at32_setup_serial_console(0);
}
diff --git a/arch/avr32/boards/favr-32/setup.c b/arch/avr32/boards/favr-32/setup.c
index cf6e4e5..46c9b0a 100644
--- a/arch/avr32/boards/favr-32/setup.c
+++ b/arch/avr32/boards/favr-32/setup.c
@@ -250,7 +250,7 @@ static void __init favr32_setup_atmel_pwm_bl(void)

void __init setup_board(void)
{
- at32_map_usart(3, 0); /* USART 3 => /dev/ttyS0 */
+ at32_map_usart(3, 0, 0); /* USART 3 => /dev/ttyS0 */
at32_setup_serial_console(0);
}

diff --git a/arch/avr32/boards/hammerhead/setup.c b/arch/avr32/boards/hammerhead/setup.c
index a5c2da2..dd00987 100644
--- a/arch/avr32/boards/hammerhead/setup.c
+++ b/arch/avr32/boards/hammerhead/setup.c
@@ -165,7 +165,7 @@ static void __init set_hw_addr(struct platform_device *pdev)

void __init setup_board(void)
{
- at32_map_usart(1, 0); /* USART 1: /dev/ttyS0, DB9 */
+ at32_map_usart(1, 0, 0); /* USART 1: /dev/ttyS0, DB9 */
at32_setup_serial_console(0);
}

diff --git a/arch/avr32/boards/mimc200/setup.c b/arch/avr32/boards/mimc200/setup.c
index 2b58d61..c1b2175 100644
--- a/arch/avr32/boards/mimc200/setup.c
+++ b/arch/avr32/boards/mimc200/setup.c
@@ -175,10 +175,10 @@ static void __init set_hw_addr(struct platform_device *pdev)

void __init setup_board(void)
{
- at32_map_usart(0, 0); /* USART 0: /dev/ttyS0 (TTL --> Altera) */
- at32_map_usart(1, 1); /* USART 1: /dev/ttyS1 (RS232) */
- at32_map_usart(2, 2); /* USART 2: /dev/ttyS2 (RS485) */
- at32_map_usart(3, 3); /* USART 3: /dev/ttyS3 (RS422 Multidrop) */
+ at32_map_usart(0, 0, 0); /* USART 0: /dev/ttyS0 (TTL --> Altera) */
+ at32_map_usart(1, 1, 0); /* USART 1: /dev/ttyS1 (RS232) */
+ at32_map_usart(2, 2, 0); /* USART 2: /dev/ttyS2 (RS485) */
+ at32_map_usart(3, 3, 0); /* USART 3: /dev/ttyS3 (RS422 Multidrop) */
}

static struct i2c_gpio_platform_data i2c_gpio_data = {
diff --git a/arch/avr32/mach-at32ap/at32ap700x.c b/arch/avr32/mach-at32ap/at32ap700x.c
index 62501d6..7cc6537 100644
--- a/arch/avr32/mach-at32ap/at32ap700x.c
+++ b/arch/avr32/mach-at32ap/at32ap700x.c
@@ -966,56 +966,68 @@ static struct resource atmel_usart3_resource[] = {
DEFINE_DEV_DATA(atmel_usart, 3);
DEV_CLK(usart, atmel_usart3, pba, 6);

-static inline void configure_usart0_pins(void)
+static inline void configure_usart0_pins(int flags)
{
u32 pin_mask = (1 << 8) | (1 << 9); /* RXD & TXD */
+ if (flags & ATMEL_USART_RTS) pin_mask |= (1 << 6);
+ if (flags & ATMEL_USART_CTS) pin_mask |= (1 << 7);
+ if (flags & ATMEL_USART_CLK) pin_mask |= (1 << 10);

select_peripheral(PIOA, pin_mask, PERIPH_B, AT32_GPIOF_PULLUP);
}

-static inline void configure_usart1_pins(void)
+static inline void configure_usart1_pins(int flags)
{
u32 pin_mask = (1 << 17) | (1 << 18); /* RXD & TXD */
+ if (flags & ATMEL_USART_RTS) pin_mask |= (1 << 19);
+ if (flags & ATMEL_USART_CTS) pin_mask |= (1 << 20);
+ if (flags & ATMEL_USART_CLK) pin_mask |= (1 << 16);

select_peripheral(PIOA, pin_mask, PERIPH_A, AT32_GPIOF_PULLUP);
}

-static inline void configure_usart2_pins(void)
+static inline void configure_usart2_pins(int flags)
{
u32 pin_mask = (1 << 26) | (1 << 27); /* RXD & TXD */
+ if (flags & ATMEL_USART_RTS) pin_mask |= (1 << 30);
+ if (flags & ATMEL_USART_CTS) pin_mask |= (1 << 29);
+ if (flags & ATMEL_USART_CLK) pin_mask |= (1 << 28);

select_peripheral(PIOB, pin_mask, PERIPH_B, AT32_GPIOF_PULLUP);
}

-static inline void configure_usart3_pins(void)
+static inline void configure_usart3_pins(int flags)
{
u32 pin_mask = (1 << 18) | (1 << 17); /* RXD & TXD */
+ if (flags & ATMEL_USART_RTS) pin_mask |= (1 << 16);
+ if (flags & ATMEL_USART_CTS) pin_mask |= (1 << 15);
+ if (flags & ATMEL_USART_CLK) pin_mask |= (1 << 19);

select_peripheral(PIOB, pin_mask, PERIPH_B, AT32_GPIOF_PULLUP);
}

static struct platform_device *__initdata at32_usarts[4];

-void __init at32_map_usart(unsigned int hw_id, unsigned int line)
+void __init at32_map_usart(unsigned int hw_id, unsigned int line, int flags)
{
struct platform_device *pdev;

switch (hw_id) {
case 0:
pdev = &atmel_usart0_device;
- configure_usart0_pins();
+ configure_usart0_pins(flags);
break;
case 1:
pdev = &atmel_usart1_device;
- configure_usart1_pins();
+ configure_usart1_pins(flags);
break;
case 2:
pdev = &atmel_usart2_device;
- configure_usart2_pins();
+ configure_usart2_pins(flags);
break;
case 3:
pdev = &atmel_usart3_device;
- configure_usart3_pins();
+ configure_usart3_pins(flags);
break;
default:
return;
diff --git a/arch/avr32/mach-at32ap/include/mach/board.h b/arch/avr32/mach-at32ap/include/mach/board.h
index b363b06..0b81642 100644
--- a/arch/avr32/mach-at32ap/include/mach/board.h
+++ b/arch/avr32/mach-at32ap/include/mach/board.h
@@ -26,12 +26,17 @@ static inline void __deprecated at32_add_system_devices(void)
#define ATMEL_MAX_UART 4
extern struct platform_device *atmel_default_console_device;

+/* Flags for selecting USART extra pins */
+#define ATMEL_USART_RTS 0x01
+#define ATMEL_USART_CTS 0x02
+#define ATMEL_USART_CLK 0x03
+
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 */
};
-void at32_map_usart(unsigned int hw_id, unsigned int line);
+void at32_map_usart(unsigned int hw_id, unsigned int line, int flags);
struct platform_device *at32_add_device_usart(unsigned int id);

struct eth_platform_data {
--
1.6.0.4


2009-04-01 08:54:34

by Haavard Skinnemoen

[permalink] [raw]
Subject: [PATCH 2/2] avr32: add hardware handshake support to atmel_serial

From: Peter Ma <[email protected]>

Adds Hardware Handshake (aka RTS/CTS flow-control) support to
atmel_serial driver, as a termios flag.

For this to actually work, the platform code needs to configure the RTS
and CTS pins for use by the USART. This has been done for AVR32 as a
separate patch.

Signed-off-by: Peter Ma <[email protected]>
Signed-off-by: Haavard Skinnemoen <[email protected]>
---
drivers/serial/atmel_serial.c | 9 ++++++++-
1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/drivers/serial/atmel_serial.c b/drivers/serial/atmel_serial.c
index 8f58f7f..b3497d7 100644
--- a/drivers/serial/atmel_serial.c
+++ b/drivers/serial/atmel_serial.c
@@ -1020,7 +1020,8 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios *termios,

/* Get current mode register */
mode = UART_GET_MR(port) & ~(ATMEL_US_USCLKS | ATMEL_US_CHRL
- | ATMEL_US_NBSTOP | ATMEL_US_PAR);
+ | ATMEL_US_NBSTOP | ATMEL_US_PAR
+ | ATMEL_US_USMODE);

baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk / 16);
quot = uart_get_divisor(port, baud);
@@ -1065,6 +1066,12 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios *termios,
} else
mode |= ATMEL_US_PAR_NONE;

+ /* hardware handshake (RTS/CTS) */
+ if (termios->c_cflag & CRTSCTS)
+ mode |= ATMEL_US_USMODE_HWHS;
+ else
+ mode |= ATMEL_US_USMODE_NORMAL;
+
spin_lock_irqsave(&port->lock, flags);

port->read_status_mask = ATMEL_US_OVRE;
--
1.6.0.4

2009-04-01 09:14:26

by Alan

[permalink] [raw]
Subject: Re: [PATCH 2/2] avr32: add hardware handshake support to atmel_serial

On Wed, 1 Apr 2009 10:53:58 +0200
Haavard Skinnemoen <[email protected]> wrote:

> From: Peter Ma <[email protected]>
>
> Adds Hardware Handshake (aka RTS/CTS flow-control) support to
> atmel_serial driver, as a termios flag.
>
> For this to actually work, the platform code needs to configure the RTS
> and CTS pins for use by the USART. This has been done for AVR32 as a
> separate patch.

Acked-by: Alan Cox <[email protected]>

Looks fine to me from the tty side. I assume it will go via the atmel
tree to keep the patches together nicely ?

2009-04-01 09:22:30

by Haavard Skinnemoen

[permalink] [raw]
Subject: Re: [PATCH 2/2] avr32: add hardware handshake support to atmel_serial

Alan Cox wrote:
> On Wed, 1 Apr 2009 10:53:58 +0200
> Haavard Skinnemoen <[email protected]> wrote:
>
> > From: Peter Ma <[email protected]>
> >
> > Adds Hardware Handshake (aka RTS/CTS flow-control) support to
> > atmel_serial driver, as a termios flag.
> >
> > For this to actually work, the platform code needs to configure the RTS
> > and CTS pins for use by the USART. This has been done for AVR32 as a
> > separate patch.
>
> Acked-by: Alan Cox <[email protected]>
>
> Looks fine to me from the tty side. I assume it will go via the atmel
> tree to keep the patches together nicely ?

Thanks. I'll merge both through the avr32 tree.

Haavard