imx: Add save/restore functions for UART control regs
Subsystems (2)
PATCH 1/2 imx: Add save/restore functions for UART control regs
Factor out the uart save/restore functionality instead of having the same code several times in the driver.
--- drivers/tty/serial/imx.c | 38 +++++++++++++++++++++++++++++++------- 1 files changed, 31 insertions(+), 7 deletions(-)
drivers/tty/serial/imx.c +31 -7
@@ -260,6 +260,31 @@ static inline int is_imx21_uart(struct imx_port *sport) }/* +* Save and restore functions for UCR1, UCR2 and UCR3 registers +*/ +static void imx_console_mode (struct uart_port *port, +unsigned int *ucr1, +unsigned int *ucr2, +unsigned int *ucr3) +{ +/* save control registers */ + *ucr1 =readl (port->membase +UCR1 ); + *ucr2 =readl (port->membase +UCR2 ); + *ucr3 =readl (port->membase +UCR3 ); +} + +static void imx_console_restore (struct uart_port *port, +unsigned int ucr1, +unsigned int ucr2, +unsigned int ucr3) +{ +/* restore control registers */ +writel (ucr1, port->membase +UCR1 ); +writel (ucr2, port->membase +UCR2 ); +writel (ucr3, port->membase +UCR3 ); +} + +/* * Handle any change of modem status signal since we were last called. */ static void imx_mctrl_check (struct imx_port *sport)
@@ -1118,13 +1143,13 @@ static void imx_console_write(struct console *co, const char *s, unsigned int count) { struct imx_port *sport = imx_ports[co->index]; -unsigned int old_ucr1, old_ucr2, ucr1; +unsigned int old_ucr1, old_ucr2, old_ucr3, ucr1;/* -* First, save UCR1/2 and then disable interrupts +* First, save UCR1/2/3 and then disable interrupts */ - ucr1 = old_ucr1 =readl (sport->port.membase +UCR1 ); - old_ucr2 =readl (sport->port.membase +UCR2 ); +imx_console_mode (&sport->port, &old_ucr1, &old_ucr2, &old_ucr3); + ucr1 = old_ucr1;if (is_imx1_uart (sport)) ucr1 |=IMX1_UCR1_UARTCLKEN ;
@@ -1139,12 +1164,11 @@ imx_console_write(struct console *co, const char *s, unsigned int count)/* * Finally, wait for transmitter to become empty -* and restore UCR1/2 +* and restore UCR1/2/3 */ while (!(readl (sport->port.membase +USR2 ) &USR2_TXDC )); -writel (old_ucr1, sport->port.membase +UCR1 ); -writel (old_ucr2, sport->port.membase +UCR2 ); +imx_console_restore (&sport->port, old_ucr1, old_ucr2, old_ucr3); }/*
Signature · 1 line
1.7.7.4
PATCH v2 2/2 imx: add polled io uart methods
From: Saleem Abdulrasool <[email protected]>
These methods are invoked if the iMX uart is used in conjuction with kgdb during early boot. In order to access the UART without the interrupts, the kernel uses the basic polling methods for IO with the device. With these methods implemented, it is now possible to enable kgdb during early boot over serial.
---
Note: Changes in the v2 compared to Saleem's original version:
* Remove volatile form status variable
* Remove blank line
* Factor out imx_console_mode/restore()
drivers/tty/serial/imx.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 66 insertions(+), 0 deletions(-)
drivers/tty/serial/imx.c +66 -0
@@ -102,6 +102,7 @@#define UCR2_STPB (1<<6)/* Stop */ #define UCR2_WS (1<<5)/* Word size */ #define UCR2_RTSEN (1<<4)/* Request to send interrupt enable */ +#define UCR2_ATEN (1<<3)/* Aging Timer Enable */ #define UCR2_TXEN (1<<2)/* Transmitter enabled */ #define UCR2_RXEN (1<<1)/* Receiver enabled */ #define UCR2_SRST (1<<0)/* SW reset */
@@ -1104,6 +1105,66 @@ imx_verify_port(struct uart_port *port, struct serial_struct *ser)return ret; } +#if defined(CONFIG_CONSOLE_POLL ) +static int imx_poll_get_char (struct uart_port *port) +{ +unsigned int status, cr1, cr2, cr3; +unsigned char c; + +/* save control registers */ +imx_console_mode (port, &cr1, &cr2, &cr3); + +/* disable interrupts */ +writel (UCR1_UARTEN , port->membase +UCR1 ); +writel (cr2 & ~(UCR2_ATEN |UCR2_RTSEN |UCR2_ESCI ), + port->membase +UCR2 ); +writel (cr3 & ~(UCR3_DCD |UCR3_RI |UCR3_DTREN ), port->membase +UCR3 ); + +/* poll */ +do { + status =readl (port->membase +USR2 ); + }while (~status &USR2_RDR ); + +/* read */ + c =readl (port->membase +URXD0 ); + +/* restore control registers */ +imx_console_restore (port, cr1, cr2, cr3); + +return c &0xff ; +} + +static void imx_poll_put_char (struct uart_port *port,unsigned char c) +{ +unsigned int status, cr1, cr2, cr3; + +/* save control registers */ +imx_console_mode (port, &cr1, &cr2, &cr3); + +/* disable interrupts */ +writel (UCR1_UARTEN , port->membase +UCR1 ); +writel (cr2 & ~(UCR2_ATEN |UCR2_RTSEN |UCR2_ESCI ), + port->membase +UCR2 ); +writel (cr3 & ~(UCR3_DCD |UCR3_RI |UCR3_DTREN ), port->membase +UCR3 ); + +/* drain */ +do { + status =readl (port->membase +USR1 ); + }while (~status &USR1_TRDY ); + +/* write */ +writel (c, port->membase +URTX0 ); + +/* flush */ +do { + status =readl (port->membase +USR2 ); + }while (~status &USR2_TXDC ); + +/* restore control registers */ +imx_console_restore (port, cr1, cr2, cr3); +} +#endif +static struct uart_ops imx_pops = { .tx_empty = imx_tx_empty, .set_mctrl = imx_set_mctrl,
@@ -1121,6 +1182,11 @@ static struct uart_ops imx_pops = { .request_port = imx_request_port, .config_port = imx_config_port, .verify_port = imx_verify_port, + +#if defined(CONFIG_CONSOLE_POLL ) + .poll_get_char = imx_poll_get_char, + .poll_put_char = imx_poll_put_char, +#endif };static struct imx_port *imx_ports[UART_NR ];
Signature · 1 line
1.7.7.4
PATCH 1/2 imx: Add save/restore functions for UART control regs
In reply to Dirk BehmeQuoted 18 lines · Dirk Behme
Factor out the uart save/restore functionality instead of having the same code several times in the driver.
Signed-off-by Dirk Behme <[email protected]>CC Saleem Abdulrasool <[email protected]>CC Sascha Hauer <[email protected]>CC Fabio Estevam <[email protected]>CC Uwe Kleine-König <[email protected]>--- drivers/tty/serial/imx.c | 38 +++++++++++++++++++++++++++++++------- 1 files changed, 31 insertions(+), 7 deletions(-)drivers/tty/serial/imx.c +0
-0
drivers/tty/serial/imx.c static inline int is_imx21_uart(struct imx_port *sport) · line 265
Quoted 6 lines
drivers/tty/serial/imx.c +3
-0@@ -260,6 +260,31 @@ static inline int is_imx21_uart(struct imx_port *sport) }/* +* Save and restore functions for UCR1, UCR2 and UCR3 registers +*/ +static void imx_console_mode(struct uart_port *port,
Function name imx_console_mode seems not like a couple with imx_console_restore. And I guess something like imx_port_ucrs_save[restore] would be better?
drivers/tty/serial/imx.c static inline int is_imx21_uart(struct imx_port *sport) · line 268
Quoted 3 lines
drivers/tty/serial/imx.c +3
-0+unsigned int *ucr1, + unsigned int *ucr2, + unsigned int *ucr3)
Can we define something like 'struct imx_port_ucrs' to contains these?
Regards,
Shawn
Quoted 57 lines
drivers/tty/serial/imx.c +25
-7+{ +/* save control registers */ + *ucr1 =readl (port->membase +UCR1 ); + *ucr2 =readl (port->membase +UCR2 ); + *ucr3 =readl (port->membase +UCR3 ); +} + +static void imx_console_restore (struct uart_port *port, +unsigned int ucr1, +unsigned int ucr2, +unsigned int ucr3) +{ +/* restore control registers */ +writel (ucr1, port->membase +UCR1 ); +writel (ucr2, port->membase +UCR2 ); +writel (ucr3, port->membase +UCR3 ); +} + +/* * Handle any change of modem status signal since we were last called. */ static void imx_mctrl_check (struct imx_port *sport)@@ -1118,13 +1143,13 @@ static void imx_console_write(struct console *co, const char *s, unsigned int count) { struct imx_port *sport = imx_ports[co->index]; -unsigned int old_ucr1, old_ucr2, ucr1; +unsigned int old_ucr1, old_ucr2, old_ucr3, ucr1;/* -* First, save UCR1/2 and then disable interrupts +* First, save UCR1/2/3 and then disable interrupts */ - ucr1 = old_ucr1 =readl (sport->port.membase +UCR1 ); - old_ucr2 =readl (sport->port.membase +UCR2 ); +imx_console_mode (&sport->port, &old_ucr1, &old_ucr2, &old_ucr3); + ucr1 = old_ucr1;if (is_imx1_uart (sport)) ucr1 |=IMX1_UCR1_UARTCLKEN ;@@ -1139,12 +1164,11 @@ imx_console_write(struct console *co, const char *s, unsigned int count)/* * Finally, wait for transmitter to become empty -* and restore UCR1/2 +* and restore UCR1/2/3 */ while (!(readl (sport->port.membase +USR2 ) &USR2_TXDC )); -writel (old_ucr1, sport->port.membase +UCR1 ); -writel (old_ucr2, sport->port.membase +UCR2 ); +imx_console_restore (&sport->port, old_ucr1, old_ucr2, old_ucr3); }/* Signature · 1 line
1.7.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-serial" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v2 2/2 imx: add polled io uart methods
In reply to Dirk BehmeQuoted 55 lines · Dirk Behme
From: Saleem Abdulrasool <[email protected]>
These methods are invoked if the iMX uart is used in conjuction with kgdb during early boot. In order to access the UART without the interrupts, the kernel uses the basic polling methods for IO with the device. With these methods implemented, it is now possible to enable kgdb during early boot over serial.
Signed-off-by Saleem Abdulrasool <[email protected]>Signed-off-by Dirk Behme <[email protected]>CC Sascha Hauer <[email protected]>CC Fabio Estevam <[email protected]>CC Uwe Kleine-König <[email protected]>---
Note: Changes in the v2 compared to Saleem's original version:
* Remove volatile form status variable
* Remove blank line
* Factor out imx_console_mode/restore()drivers/tty/serial/imx.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 66 insertions(+), 0 deletions(-)drivers/tty/serial/imx.c +18
-0@@ -102,6 +102,7 @@#define UCR2_STPB (1<<6)/* Stop */ #define UCR2_WS (1<<5)/* Word size */ #define UCR2_RTSEN (1<<4)/* Request to send interrupt enable */ +#define UCR2_ATEN (1<<3)/* Aging Timer Enable */ #define UCR2_TXEN (1<<2)/* Transmitter enabled */ #define UCR2_RXEN (1<<1)/* Receiver enabled */ #define UCR2_SRST (1<<0)/* SW reset */ @@ -1104,6 +1105,66 @@ imx_verify_port(struct uart_port *port, struct serial_struct *ser)return ret; } +#if defined(CONFIG_CONSOLE_POLL ) +static int imx_poll_get_char (struct uart_port *port) +{ +unsigned int status, cr1, cr2, cr3; +unsigned char c; + +/* save control registers */ +imx_console_mode (port, &cr1, &cr2, &cr3); + +/* disable interrupts */ +writel (UCR1_UARTEN , port->membase +UCR1 ); +writel (cr2 & ~(UCR2_ATEN |UCR2_RTSEN |UCR2_ESCI ), + port->membase +UCR2 ); +writel (cr3 & ~(UCR3_DCD |UCR3_RI |UCR3_DTREN ), port->membase +UCR3 ); + +/* poll */ + do {
drivers/tty/serial/imx.c imx_verify_port(struct uart_port *port, struct serial_struct *ser) · line 1134
Quoted 10 lines
drivers/tty/serial/imx.c +10
-0+ status =readl (port->membase +USR2 ); + }while (~status &USR2_RDR ); + +/* read */ + c =readl (port->membase +URXD0 ); + +/* restore control registers */ +imx_console_restore (port, cr1, cr2, cr3); + +return c &0xff ;
The 'c' is defined an 'unsigned char'. Do we still need '& 0xff'?
Quoted 37 lines
drivers/tty/serial/imx.c +33
-0+} + +static void imx_poll_put_char (struct uart_port *port,unsigned char c) +{ +unsigned int status, cr1, cr2, cr3; + +/* save control registers */ +imx_console_mode (port, &cr1, &cr2, &cr3); + +/* disable interrupts */ +writel (UCR1_UARTEN , port->membase +UCR1 ); +writel (cr2 & ~(UCR2_ATEN |UCR2_RTSEN |UCR2_ESCI ), + port->membase +UCR2 ); +writel (cr3 & ~(UCR3_DCD |UCR3_RI |UCR3_DTREN ), port->membase +UCR3 ); + +/* drain */ +do { + status =readl (port->membase +USR1 ); + }while (~status &USR1_TRDY ); + +/* write */ +writel (c, port->membase +URTX0 ); + +/* flush */ +do { + status =readl (port->membase +USR2 ); + }while (~status &USR2_TXDC ); + +/* restore control registers */ +imx_console_restore (port, cr1, cr2, cr3); +} +#endif +static struct uart_ops imx_pops = { .tx_empty = imx_tx_empty, .set_mctrl = imx_set_mctrl,
drivers/tty/serial/imx.c static struct uart_ops imx_pops = { · line 1185
Quoted 4 lines
drivers/tty/serial/imx.c +1
-0@@ -1121,6 +1182,11 @@ static struct uart_ops imx_pops = { .request_port = imx_request_port, .config_port = imx_config_port, .verify_port = imx_verify_port, +
Unnecessary blank line?
Regards,
Shawn
Quoted 9 lines
drivers/tty/serial/imx.c +4
-0+#if defined(CONFIG_CONSOLE_POLL ) + .poll_get_char = imx_poll_get_char, + .poll_put_char = imx_poll_put_char, +#endif };static struct imx_port *imx_ports[UART_NR ];Signature · 1 line
1.7.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-serial" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 1/2 imx: Add save/restore functions for UART control regs
In reply to Shawn GuoQuoted 30 lines · Shawn Guo
Quoted 18 lines · Dirk Behme
Factor out the uart save/restore functionality instead of having the same code several times in the driver.
Signed-off-by Dirk Behme<[email protected]>CC Saleem Abdulrasool<[email protected]>CC Sascha Hauer<[email protected]>CC Fabio Estevam<[email protected]>CC Uwe Kleine-K?nig<[email protected]>CC linux-serial at vger.kernel.org--- drivers/tty/serial/imx.c | 38 +++++++++++++++++++++++++++++++------- 1 files changed, 31 insertions(+), 7 deletions(-)drivers/tty/serial/imx.c +0
-0drivers/tty/serial/imx.c static inline int is_imx21_uart(struct imx_port *sport) · line 265
Quoted 6 lines
drivers/tty/serial/imx.c +3
-0@@ -260,6 +260,31 @@ static inline int is_imx21_uart(struct imx_port *sport) }/* +* Save and restore functions for UCR1, UCR2 and UCR3 registers +*/ +static void imx_console_mode(struct uart_port *port,Function name
imx_console_modeseems not like a couple withimx_console_restore. And I guess something like imx_port_ucrs_save[restore] would be better?
Quoted 5 lines
drivers/tty/serial/imx.c static inline int is_imx21_uart(struct imx_port *sport) · line 268
Quoted 3 lines
drivers/tty/serial/imx.c +3
-0+unsigned int *ucr1, + unsigned int *ucr2, + unsigned int *ucr3)Can we define something like 'struct
imx_port_ucrs' to contains these?
Yes, we could have different function names above and use a struct.
I implemented what Sascha asked for in
http://www.spinics.net/lists/arm-kernel/msg144960.html
though:
-- Sascha wrote: --
I'm thinking about:
imx_console_mode(struct uart_port *port, u32 *ucr1, u32 *ucr2, u32 *ucr2); imx_console_restore(struct uart_port *port, u32 ucr1, u32 ucr2, u32 ucr3); -- Sascha end --
It seems Shawn proposes
imx_port_ucrs_save(struct uart_port *port, struct *imx_port_ucrs); imx_port_ucrs_restore(struct uart_port *port, struct *imx_port_ucrs);
(?)
Sascha, Shawn: Could you agree on what we should use?
Once you agreed, I will send an update of both two patches.
Many thanks and best regards
Dirk
PATCH 1/2 imx: Add save/restore functions for UART control regs
Quoted 54 lines · Dirk Behme
Quoted 30 lines · Shawn Guo
Quoted 18 lines · Dirk Behme
Factor out the uart save/restore functionality instead of having the same code several times in the driver.
Signed-off-by Dirk Behme<[email protected]>CC Saleem Abdulrasool<[email protected]>CC Sascha Hauer<[email protected]>CC Fabio Estevam<[email protected]>CC Uwe Kleine-König<[email protected]>--- drivers/tty/serial/imx.c | 38 +++++++++++++++++++++++++++++++------- 1 files changed, 31 insertions(+), 7 deletions(-)drivers/tty/serial/imx.c +0
-0drivers/tty/serial/imx.c static inline int is_imx21_uart(struct imx_port *sport) · line 265
Quoted 6 lines
drivers/tty/serial/imx.c +3
-0@@ -260,6 +260,31 @@ static inline int is_imx21_uart(struct imx_port *sport) }/* +* Save and restore functions for UCR1, UCR2 and UCR3 registers +*/ +static void imx_console_mode(struct uart_port *port,Function name
imx_console_modeseems not like a couple withimx_console_restore. And I guess something like imx_port_ucrs_save[restore] would be better?Quoted 5 lines
drivers/tty/serial/imx.c static inline int is_imx21_uart(struct imx_port *sport) · line 268
Quoted 3 lines
drivers/tty/serial/imx.c +3
-0+unsigned int *ucr1, + unsigned int *ucr2, + unsigned int *ucr3)Can we define something like 'struct
imx_port_ucrs' to contains these?Yes, we could have different function names above and use a struct.
I implemented what Sascha asked for in
http://www.spinics.net/lists/arm-kernel/msg144960.html
though:
-- Sascha wrote: --
I'm thinking about:
imx_console_mode(struct uart_port *port, u32 *ucr1, u32 *ucr2, u32 *ucr2);imx_console_restore(struct uart_port *port, u32 ucr1, u32 ucr2, u32 ucr3); -- Sascha end --It seems Shawn proposes
Quoted 9 lines
imx_port_ucrs_save(struct uart_port *port, struct *imx_port_ucrs);imx_port_ucrs_restore(struct uart_port *port, struct *imx_port_ucrs);(?)
Sascha, Shawn: Could you agree on what we should use?
Once you agreed, I will send an update of both two patches.
Please Cc Alan Cox <[email protected]> for these patches. Though we could possibly send them through arm-soc tree, we need to ask for his ack.
Signature · 7 lines
Regards, Shawn -- To unsubscribe from this list: send the line "unsubscribe linux-serial" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Sascha Hauer
maintainerPATCH 1/2 imx: Add save/restore functions for UART control regs
In reply to Dirk BehmeQuoted 52 lines · Dirk Behme
Quoted 30 lines · Shawn Guo
Quoted 18 lines · Dirk Behme
Factor out the uart save/restore functionality instead of having the same code several times in the driver.
Signed-off-by Dirk Behme<[email protected]>CC Saleem Abdulrasool<[email protected]>CC Sascha Hauer<[email protected]>CC Fabio Estevam<[email protected]>CC Uwe Kleine-K?nig<[email protected]>CC linux-serial at vger.kernel.org--- drivers/tty/serial/imx.c | 38 +++++++++++++++++++++++++++++++------- 1 files changed, 31 insertions(+), 7 deletions(-)drivers/tty/serial/imx.c +0
-0drivers/tty/serial/imx.c static inline int is_imx21_uart(struct imx_port *sport) · line 265
Quoted 6 lines
drivers/tty/serial/imx.c +3
-0@@ -260,6 +260,31 @@ static inline int is_imx21_uart(struct imx_port *sport) }/* +* Save and restore functions for UCR1, UCR2 and UCR3 registers +*/ +static void imx_console_mode(struct uart_port *port,Function name
imx_console_modeseems not like a couple withimx_console_restore. And I guess something like imx_port_ucrs_save[restore] would be better?Quoted 5 lines
drivers/tty/serial/imx.c static inline int is_imx21_uart(struct imx_port *sport) · line 268
Quoted 3 lines
drivers/tty/serial/imx.c +3
-0+unsigned int *ucr1, + unsigned int *ucr2, + unsigned int *ucr3)Can we define something like 'struct
imx_port_ucrs' to contains these?Yes, we could have different function names above and use a struct.
I implemented what Sascha asked for in
http://www.spinics.net/lists/arm-kernel/msg144960.html
though:
-- Sascha wrote: --
I'm thinking about:
imx_console_mode(struct uart_port *port, u32 *ucr1, u32 *ucr2, u32 *ucr2);imx_console_restore(struct uart_port *port, u32 ucr1, u32 ucr2, u32 ucr3); -- Sascha end --
Quoted 8 lines
It seems Shawn proposes
imx_port_ucrs_save(struct uart_port *port, struct *imx_port_ucrs);imx_port_ucrs_restore(struct uart_port *port, struct *imx_port_ucrs);(?)
Sascha, Shawn: Could you agree on what we should use?
I think save/restore are better names.
Maybe I thought about a function which saves the current values *and* sets ucrx to other values. In that case imx_port_ucrs_save() would be the wrong name.
Quoted 2 lines
Once you agreed, I will send an update of both two patches.
+1 for save/restore
Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |