aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/tty
diff options
context:
space:
mode:
authorDirk Behme <dirk.behme@googlemail.com>2011-12-22 03:57:52 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2012-01-04 19:30:35 -0500
commit0ad5a81472a9d6a0e826e0c6ebe66d3792932a93 (patch)
tree812d6c7f681da8eeacf6dbdef7cc40d176c1ff2e /drivers/tty
parent20bb8095a467dde88bd09a55ed62c60fada2e5c9 (diff)
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. Signed-off-by: Dirk Behme <dirk.behme@gmail.com> CC: Saleem Abdulrasool <compnerd@compnerd.org> CC: Sascha Hauer <s.hauer@pengutronix.de> CC: Fabio Estevam <festevam@gmail.com> CC: Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de> CC: linux-serial@vger.kernel.org CC: Alan Cox <alan@linux.intel.com> Signed-off-by: Shawn Guo <shawn.guo@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/tty')
-rw-r--r--drivers/tty/serial/imx.c43
1 files changed, 35 insertions, 8 deletions
diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
index 92a5987924cf..225922c7ce99 100644
--- a/drivers/tty/serial/imx.c
+++ b/drivers/tty/serial/imx.c
@@ -207,6 +207,12 @@ struct imx_port {
207 struct imx_uart_data *devdata; 207 struct imx_uart_data *devdata;
208}; 208};
209 209
210struct imx_port_ucrs {
211 unsigned int ucr1;
212 unsigned int ucr2;
213 unsigned int ucr3;
214};
215
210#ifdef CONFIG_IRDA 216#ifdef CONFIG_IRDA
211#define USE_IRDA(sport) ((sport)->use_irda) 217#define USE_IRDA(sport) ((sport)->use_irda)
212#else 218#else
@@ -260,6 +266,27 @@ static inline int is_imx21_uart(struct imx_port *sport)
260} 266}
261 267
262/* 268/*
269 * Save and restore functions for UCR1, UCR2 and UCR3 registers
270 */
271static void imx_port_ucrs_save(struct uart_port *port,
272 struct imx_port_ucrs *ucr)
273{
274 /* save control registers */
275 ucr->ucr1 = readl(port->membase + UCR1);
276 ucr->ucr2 = readl(port->membase + UCR2);
277 ucr->ucr3 = readl(port->membase + UCR3);
278}
279
280static void imx_port_ucrs_restore(struct uart_port *port,
281 struct imx_port_ucrs *ucr)
282{
283 /* restore control registers */
284 writel(ucr->ucr1, port->membase + UCR1);
285 writel(ucr->ucr2, port->membase + UCR2);
286 writel(ucr->ucr3, port->membase + UCR3);
287}
288
289/*
263 * Handle any change of modem status signal since we were last called. 290 * Handle any change of modem status signal since we were last called.
264 */ 291 */
265static void imx_mctrl_check(struct imx_port *sport) 292static void imx_mctrl_check(struct imx_port *sport)
@@ -1121,13 +1148,14 @@ static void
1121imx_console_write(struct console *co, const char *s, unsigned int count) 1148imx_console_write(struct console *co, const char *s, unsigned int count)
1122{ 1149{
1123 struct imx_port *sport = imx_ports[co->index]; 1150 struct imx_port *sport = imx_ports[co->index];
1124 unsigned int old_ucr1, old_ucr2, ucr1; 1151 struct imx_port_ucrs old_ucr;
1152 unsigned int ucr1;
1125 1153
1126 /* 1154 /*
1127 * First, save UCR1/2 and then disable interrupts 1155 * First, save UCR1/2/3 and then disable interrupts
1128 */ 1156 */
1129 ucr1 = old_ucr1 = readl(sport->port.membase + UCR1); 1157 imx_port_ucrs_save(&sport->port, &old_ucr);
1130 old_ucr2 = readl(sport->port.membase + UCR2); 1158 ucr1 = old_ucr.ucr1;
1131 1159
1132 if (is_imx1_uart(sport)) 1160 if (is_imx1_uart(sport))
1133 ucr1 |= IMX1_UCR1_UARTCLKEN; 1161 ucr1 |= IMX1_UCR1_UARTCLKEN;
@@ -1136,18 +1164,17 @@ imx_console_write(struct console *co, const char *s, unsigned int count)
1136 1164
1137 writel(ucr1, sport->port.membase + UCR1); 1165 writel(ucr1, sport->port.membase + UCR1);
1138 1166
1139 writel(old_ucr2 | UCR2_TXEN, sport->port.membase + UCR2); 1167 writel(old_ucr.ucr2 | UCR2_TXEN, sport->port.membase + UCR2);
1140 1168
1141 uart_console_write(&sport->port, s, count, imx_console_putchar); 1169 uart_console_write(&sport->port, s, count, imx_console_putchar);
1142 1170
1143 /* 1171 /*
1144 * Finally, wait for transmitter to become empty 1172 * Finally, wait for transmitter to become empty
1145 * and restore UCR1/2 1173 * and restore UCR1/2/3
1146 */ 1174 */
1147 while (!(readl(sport->port.membase + USR2) & USR2_TXDC)); 1175 while (!(readl(sport->port.membase + USR2) & USR2_TXDC));
1148 1176
1149 writel(old_ucr1, sport->port.membase + UCR1); 1177 imx_port_ucrs_restore(&sport->port, &old_ucr);
1150 writel(old_ucr2, sport->port.membase + UCR2);
1151} 1178}
1152 1179
1153/* 1180/*