aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRicardo Ribalda Delgado <ricardo.ribalda@gmail.com>2014-11-06 03:23:00 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-11-06 18:00:44 -0500
commitbd737f8738b7e15930aa7b47c94c28a8d83148ac (patch)
tree9140a208d4856074a92ffc6543aabcf08a38a762
parenta9c20a9cf3190a517b88d8e08d93157256f97673 (diff)
tty/serial_core: Introduce lock mechanism for RS485
Introduce an homogeneous lock system between setting and using the rs485 data of the uart_port. This patch should not be split into multiple ones in order to avoid leaving the tree in an unstable state. Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com> Reviewed-by: Alan Cox <alan@linux.intel.com> Suggested-by: Alan Cox <alan@linux.intel.com> Cc: Nicolas Ferre <nicolas.ferre@atmel.com> Cc: Jiri Slaby <jslaby@suse.cz> Cc: One Thousand Gnomes <gnomes@lxorguk.ukuu.org.uk> Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/tty/serial/atmel_serial.c10
-rw-r--r--drivers/tty/serial/mcf.c5
-rw-r--r--drivers/tty/serial/omap-serial.c3
-rw-r--r--drivers/tty/serial/serial_core.c13
4 files changed, 17 insertions, 14 deletions
diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
index 80c4bfcff3fa..2cb04137ae78 100644
--- a/drivers/tty/serial/atmel_serial.c
+++ b/drivers/tty/serial/atmel_serial.c
@@ -294,9 +294,6 @@ static int atmel_config_rs485(struct uart_port *port,
294{ 294{
295 struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); 295 struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
296 unsigned int mode; 296 unsigned int mode;
297 unsigned long flags;
298
299 spin_lock_irqsave(&port->lock, flags);
300 297
301 /* Disable interrupts */ 298 /* Disable interrupts */
302 UART_PUT_IDR(port, atmel_port->tx_done_mask); 299 UART_PUT_IDR(port, atmel_port->tx_done_mask);
@@ -327,8 +324,6 @@ static int atmel_config_rs485(struct uart_port *port,
327 /* Enable interrupts */ 324 /* Enable interrupts */
328 UART_PUT_IER(port, atmel_port->tx_done_mask); 325 UART_PUT_IER(port, atmel_port->tx_done_mask);
329 326
330 spin_unlock_irqrestore(&port->lock, flags);
331
332 return 0; 327 return 0;
333} 328}
334 329
@@ -2533,6 +2528,7 @@ static int atmel_serial_probe(struct platform_device *pdev)
2533 struct atmel_uart_data *pdata = dev_get_platdata(&pdev->dev); 2528 struct atmel_uart_data *pdata = dev_get_platdata(&pdev->dev);
2534 void *data; 2529 void *data;
2535 int ret = -ENODEV; 2530 int ret = -ENODEV;
2531 bool rs485_enabled;
2536 2532
2537 BUILD_BUG_ON(ATMEL_SERIAL_RINGSIZE & (ATMEL_SERIAL_RINGSIZE - 1)); 2533 BUILD_BUG_ON(ATMEL_SERIAL_RINGSIZE & (ATMEL_SERIAL_RINGSIZE - 1));
2538 2534
@@ -2580,6 +2576,8 @@ static int atmel_serial_probe(struct platform_device *pdev)
2580 port->rx_ring.buf = data; 2576 port->rx_ring.buf = data;
2581 } 2577 }
2582 2578
2579 rs485_enabled = port->uart.rs485.flags & SER_RS485_ENABLED;
2580
2583 ret = uart_add_one_port(&atmel_uart, &port->uart); 2581 ret = uart_add_one_port(&atmel_uart, &port->uart);
2584 if (ret) 2582 if (ret)
2585 goto err_add_port; 2583 goto err_add_port;
@@ -2598,7 +2596,7 @@ static int atmel_serial_probe(struct platform_device *pdev)
2598 device_init_wakeup(&pdev->dev, 1); 2596 device_init_wakeup(&pdev->dev, 1);
2599 platform_set_drvdata(pdev, port); 2597 platform_set_drvdata(pdev, port);
2600 2598
2601 if (port->uart.rs485.flags & SER_RS485_ENABLED) { 2599 if (rs485_enabled) {
2602 UART_PUT_MR(&port->uart, ATMEL_US_USMODE_NORMAL); 2600 UART_PUT_MR(&port->uart, ATMEL_US_USMODE_NORMAL);
2603 UART_PUT_CR(&port->uart, ATMEL_US_RTSEN); 2601 UART_PUT_CR(&port->uart, ATMEL_US_RTSEN);
2604 } 2602 }
diff --git a/drivers/tty/serial/mcf.c b/drivers/tty/serial/mcf.c
index d7be1f18545b..fdd5c7bd1e8d 100644
--- a/drivers/tty/serial/mcf.c
+++ b/drivers/tty/serial/mcf.c
@@ -257,12 +257,12 @@ static void mcf_set_termios(struct uart_port *port, struct ktermios *termios,
257 mr2 |= MCFUART_MR2_TXCTS; 257 mr2 |= MCFUART_MR2_TXCTS;
258 } 258 }
259 259
260 spin_lock_irqsave(&port->lock, flags);
260 if (port->rs485.flags & SER_RS485_ENABLED) { 261 if (port->rs485.flags & SER_RS485_ENABLED) {
261 dev_dbg(port->dev, "Setting UART to RS485\n"); 262 dev_dbg(port->dev, "Setting UART to RS485\n");
262 mr2 |= MCFUART_MR2_TXRTS; 263 mr2 |= MCFUART_MR2_TXRTS;
263 } 264 }
264 265
265 spin_lock_irqsave(&port->lock, flags);
266 uart_update_timeout(port, termios->c_cflag, baud); 266 uart_update_timeout(port, termios->c_cflag, baud);
267 writeb(MCFUART_UCR_CMDRESETRX, port->membase + MCFUART_UCR); 267 writeb(MCFUART_UCR_CMDRESETRX, port->membase + MCFUART_UCR);
268 writeb(MCFUART_UCR_CMDRESETTX, port->membase + MCFUART_UCR); 268 writeb(MCFUART_UCR_CMDRESETTX, port->membase + MCFUART_UCR);
@@ -442,10 +442,8 @@ static int mcf_verify_port(struct uart_port *port, struct serial_struct *ser)
442static int mcf_config_rs485(struct uart_port *port, struct serial_rs485 *rs485) 442static int mcf_config_rs485(struct uart_port *port, struct serial_rs485 *rs485)
443{ 443{
444 struct mcf_uart *pp = container_of(port, struct mcf_uart, port); 444 struct mcf_uart *pp = container_of(port, struct mcf_uart, port);
445 unsigned long flags;
446 unsigned char mr1, mr2; 445 unsigned char mr1, mr2;
447 446
448 spin_lock_irqsave(&port->lock, flags);
449 /* Get mode registers */ 447 /* Get mode registers */
450 mr1 = readb(port->membase + MCFUART_UMR); 448 mr1 = readb(port->membase + MCFUART_UMR);
451 mr2 = readb(port->membase + MCFUART_UMR); 449 mr2 = readb(port->membase + MCFUART_UMR);
@@ -460,7 +458,6 @@ static int mcf_config_rs485(struct uart_port *port, struct serial_rs485 *rs485)
460 writeb(mr1, port->membase + MCFUART_UMR); 458 writeb(mr1, port->membase + MCFUART_UMR);
461 writeb(mr2, port->membase + MCFUART_UMR); 459 writeb(mr2, port->membase + MCFUART_UMR);
462 port->rs485 = *rs485; 460 port->rs485 = *rs485;
463 spin_unlock_irqrestore(&port->lock, flags);
464 461
465 return 0; 462 return 0;
466} 463}
diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c
index 050d1b5c7b36..e0bec06a5f60 100644
--- a/drivers/tty/serial/omap-serial.c
+++ b/drivers/tty/serial/omap-serial.c
@@ -1360,12 +1360,10 @@ static int
1360serial_omap_config_rs485(struct uart_port *port, struct serial_rs485 *rs485conf) 1360serial_omap_config_rs485(struct uart_port *port, struct serial_rs485 *rs485conf)
1361{ 1361{
1362 struct uart_omap_port *up = to_uart_omap_port(port); 1362 struct uart_omap_port *up = to_uart_omap_port(port);
1363 unsigned long flags;
1364 unsigned int mode; 1363 unsigned int mode;
1365 int val; 1364 int val;
1366 1365
1367 pm_runtime_get_sync(up->dev); 1366 pm_runtime_get_sync(up->dev);
1368 spin_lock_irqsave(&up->port.lock, flags);
1369 1367
1370 /* Disable interrupts from this port */ 1368 /* Disable interrupts from this port */
1371 mode = up->ier; 1369 mode = up->ier;
@@ -1401,7 +1399,6 @@ serial_omap_config_rs485(struct uart_port *port, struct serial_rs485 *rs485conf)
1401 serial_out(up, UART_OMAP_SCR, up->scr); 1399 serial_out(up, UART_OMAP_SCR, up->scr);
1402 } 1400 }
1403 1401
1404 spin_unlock_irqrestore(&up->port.lock, flags);
1405 pm_runtime_mark_last_busy(up->dev); 1402 pm_runtime_mark_last_busy(up->dev);
1406 pm_runtime_put_autosuspend(up->dev); 1403 pm_runtime_put_autosuspend(up->dev);
1407 1404
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 99fcdba0e3e9..5c8b8f50f787 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -1155,8 +1155,16 @@ static int uart_get_icount(struct tty_struct *tty,
1155static int uart_get_rs485_config(struct uart_port *port, 1155static int uart_get_rs485_config(struct uart_port *port,
1156 struct serial_rs485 __user *rs485) 1156 struct serial_rs485 __user *rs485)
1157{ 1157{
1158 if (copy_to_user(rs485, &port->rs485, sizeof(port->rs485))) 1158 unsigned long flags;
1159 struct serial_rs485 aux;
1160
1161 spin_lock_irqsave(&port->lock, flags);
1162 aux = port->rs485;
1163 spin_unlock_irqrestore(&port->lock, flags);
1164
1165 if (copy_to_user(rs485, &aux, sizeof(aux)))
1159 return -EFAULT; 1166 return -EFAULT;
1167
1160 return 0; 1168 return 0;
1161} 1169}
1162 1170
@@ -1165,6 +1173,7 @@ static int uart_set_rs485_config(struct uart_port *port,
1165{ 1173{
1166 struct serial_rs485 rs485; 1174 struct serial_rs485 rs485;
1167 int ret; 1175 int ret;
1176 unsigned long flags;
1168 1177
1169 if (!port->rs485_config) 1178 if (!port->rs485_config)
1170 return -ENOIOCTLCMD; 1179 return -ENOIOCTLCMD;
@@ -1172,7 +1181,9 @@ static int uart_set_rs485_config(struct uart_port *port,
1172 if (copy_from_user(&rs485, rs485_user, sizeof(*rs485_user))) 1181 if (copy_from_user(&rs485, rs485_user, sizeof(*rs485_user)))
1173 return -EFAULT; 1182 return -EFAULT;
1174 1183
1184 spin_lock_irqsave(&port->lock, flags);
1175 ret = port->rs485_config(port, &rs485); 1185 ret = port->rs485_config(port, &rs485);
1186 spin_unlock_irqrestore(&port->lock, flags);
1176 if (ret) 1187 if (ret)
1177 return ret; 1188 return ret;
1178 1189