Skip to content

Commit 910ef43

Browse files
jognessgregkh
authored andcommitted
serial: 8250: Provide flag for IER toggling for RS485
For RS485 mode, if SER_RS485_RX_DURING_TX is not available, the console ->write() callback needs to enable/disable Tx. It does this by calling the ->rs485_start_tx() and ->rs485_stop_tx() callbacks. However, some of these callbacks also disable/enable interrupts and makes power management calls. This causes 2 problems for console writing: 1. A console write can occur in contexts that are illegal for pm_runtime_*(). It is not even necessary for console writing to use pm_runtime_*() because a console already does this in serial8250_console_setup() and serial8250_console_exit(). 2. The console ->write() callback already handles disabling/enabling the interrupts by properly restoring the previous IER value. Add an argument @toggle_ier to the ->rs485_start_tx() and ->rs485_stop_tx() callbacks to specify if they may disable/enable receive interrupts while using pm_runtime_*(). Console writing will not allow the toggling. For all call sites other than console writing there is no functional change. Signed-off-by: John Ogness <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 95a1b40 commit 910ef43

File tree

5 files changed

+22
-18
lines changed

5 files changed

+22
-18
lines changed

drivers/tty/serial/8250/8250.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ void serial8250_rpm_put_tx(struct uart_8250_port *p);
231231

232232
int serial8250_em485_config(struct uart_port *port, struct ktermios *termios,
233233
struct serial_rs485 *rs485);
234-
void serial8250_em485_start_tx(struct uart_8250_port *p);
235-
void serial8250_em485_stop_tx(struct uart_8250_port *p);
234+
void serial8250_em485_start_tx(struct uart_8250_port *p, bool toggle_ier);
235+
void serial8250_em485_stop_tx(struct uart_8250_port *p, bool toggle_ier);
236236
void serial8250_em485_destroy(struct uart_8250_port *p);
237237
extern struct serial_rs485 serial8250_em485_supported;
238238

drivers/tty/serial/8250/8250_bcm2835aux.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct bcm2835aux_data {
4646
u32 cntl;
4747
};
4848

49-
static void bcm2835aux_rs485_start_tx(struct uart_8250_port *up)
49+
static void bcm2835aux_rs485_start_tx(struct uart_8250_port *up, bool toggle_ier)
5050
{
5151
if (!(up->port.rs485.flags & SER_RS485_RX_DURING_TX)) {
5252
struct bcm2835aux_data *data = dev_get_drvdata(up->port.dev);
@@ -65,7 +65,7 @@ static void bcm2835aux_rs485_start_tx(struct uart_8250_port *up)
6565
serial8250_out_MCR(up, UART_MCR_RTS);
6666
}
6767

68-
static void bcm2835aux_rs485_stop_tx(struct uart_8250_port *up)
68+
static void bcm2835aux_rs485_stop_tx(struct uart_8250_port *up, bool toggle_ier)
6969
{
7070
if (up->port.rs485.flags & SER_RS485_RTS_AFTER_SEND)
7171
serial8250_out_MCR(up, 0);

drivers/tty/serial/8250/8250_omap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ static void omap8250_restore_regs(struct uart_8250_port *up)
365365

366366
if (up->port.rs485.flags & SER_RS485_ENABLED &&
367367
up->port.rs485_config == serial8250_em485_config)
368-
serial8250_em485_stop_tx(up);
368+
serial8250_em485_stop_tx(up, true);
369369
}
370370

371371
/*

drivers/tty/serial/8250/8250_port.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ static int serial8250_em485_init(struct uart_8250_port *p)
578578

579579
deassert_rts:
580580
if (p->em485->tx_stopped)
581-
p->rs485_stop_tx(p);
581+
p->rs485_stop_tx(p, true);
582582

583583
return 0;
584584
}
@@ -1398,10 +1398,11 @@ static void serial8250_stop_rx(struct uart_port *port)
13981398
/**
13991399
* serial8250_em485_stop_tx() - generic ->rs485_stop_tx() callback
14001400
* @p: uart 8250 port
1401+
* @toggle_ier: true to allow enabling receive interrupts
14011402
*
14021403
* Generic callback usable by 8250 uart drivers to stop rs485 transmission.
14031404
*/
1404-
void serial8250_em485_stop_tx(struct uart_8250_port *p)
1405+
void serial8250_em485_stop_tx(struct uart_8250_port *p, bool toggle_ier)
14051406
{
14061407
unsigned char mcr = serial8250_in_MCR(p);
14071408

@@ -1422,8 +1423,10 @@ void serial8250_em485_stop_tx(struct uart_8250_port *p)
14221423
if (!(p->port.rs485.flags & SER_RS485_RX_DURING_TX)) {
14231424
serial8250_clear_and_reinit_fifos(p);
14241425

1425-
p->ier |= UART_IER_RLSI | UART_IER_RDI;
1426-
serial_port_out(&p->port, UART_IER, p->ier);
1426+
if (toggle_ier) {
1427+
p->ier |= UART_IER_RLSI | UART_IER_RDI;
1428+
serial_port_out(&p->port, UART_IER, p->ier);
1429+
}
14271430
}
14281431
}
14291432
EXPORT_SYMBOL_GPL(serial8250_em485_stop_tx);
@@ -1438,7 +1441,7 @@ static enum hrtimer_restart serial8250_em485_handle_stop_tx(struct hrtimer *t)
14381441
serial8250_rpm_get(p);
14391442
uart_port_lock_irqsave(&p->port, &flags);
14401443
if (em485->active_timer == &em485->stop_tx_timer) {
1441-
p->rs485_stop_tx(p);
1444+
p->rs485_stop_tx(p, true);
14421445
em485->active_timer = NULL;
14431446
em485->tx_stopped = true;
14441447
}
@@ -1470,7 +1473,7 @@ static void __stop_tx_rs485(struct uart_8250_port *p, u64 stop_delay)
14701473
em485->active_timer = &em485->stop_tx_timer;
14711474
hrtimer_start(&em485->stop_tx_timer, ns_to_ktime(stop_delay), HRTIMER_MODE_REL);
14721475
} else {
1473-
p->rs485_stop_tx(p);
1476+
p->rs485_stop_tx(p, true);
14741477
em485->active_timer = NULL;
14751478
em485->tx_stopped = true;
14761479
}
@@ -1559,18 +1562,19 @@ static inline void __start_tx(struct uart_port *port)
15591562
/**
15601563
* serial8250_em485_start_tx() - generic ->rs485_start_tx() callback
15611564
* @up: uart 8250 port
1565+
* @toggle_ier: true to allow disabling receive interrupts
15621566
*
15631567
* Generic callback usable by 8250 uart drivers to start rs485 transmission.
15641568
* Assumes that setting the RTS bit in the MCR register means RTS is high.
15651569
* (Some chips use inverse semantics.) Further assumes that reception is
15661570
* stoppable by disabling the UART_IER_RDI interrupt. (Some chips set the
15671571
* UART_LSR_DR bit even when UART_IER_RDI is disabled, foiling this approach.)
15681572
*/
1569-
void serial8250_em485_start_tx(struct uart_8250_port *up)
1573+
void serial8250_em485_start_tx(struct uart_8250_port *up, bool toggle_ier)
15701574
{
15711575
unsigned char mcr = serial8250_in_MCR(up);
15721576

1573-
if (!(up->port.rs485.flags & SER_RS485_RX_DURING_TX))
1577+
if (!(up->port.rs485.flags & SER_RS485_RX_DURING_TX) && toggle_ier)
15741578
serial8250_stop_rx(&up->port);
15751579

15761580
if (up->port.rs485.flags & SER_RS485_RTS_ON_SEND)
@@ -1604,7 +1608,7 @@ static bool start_tx_rs485(struct uart_port *port)
16041608
if (em485->tx_stopped) {
16051609
em485->tx_stopped = false;
16061610

1607-
up->rs485_start_tx(up);
1611+
up->rs485_start_tx(up, true);
16081612

16091613
if (up->port.rs485.delay_rts_before_send > 0) {
16101614
em485->active_timer = &em485->start_tx_timer;
@@ -3424,7 +3428,7 @@ void serial8250_console_write(struct uart_8250_port *up, const char *s,
34243428

34253429
if (em485) {
34263430
if (em485->tx_stopped)
3427-
up->rs485_start_tx(up);
3431+
up->rs485_start_tx(up, false);
34283432
mdelay(port->rs485.delay_rts_before_send);
34293433
}
34303434

@@ -3462,7 +3466,7 @@ void serial8250_console_write(struct uart_8250_port *up, const char *s,
34623466
if (em485) {
34633467
mdelay(port->rs485.delay_rts_after_send);
34643468
if (em485->tx_stopped)
3465-
up->rs485_stop_tx(up);
3469+
up->rs485_stop_tx(up, false);
34663470
}
34673471

34683472
serial_port_out(port, UART_IER, ier);

include/linux/serial_8250.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ struct uart_8250_port {
161161
void (*dl_write)(struct uart_8250_port *up, u32 value);
162162

163163
struct uart_8250_em485 *em485;
164-
void (*rs485_start_tx)(struct uart_8250_port *);
165-
void (*rs485_stop_tx)(struct uart_8250_port *);
164+
void (*rs485_start_tx)(struct uart_8250_port *up, bool toggle_ier);
165+
void (*rs485_stop_tx)(struct uart_8250_port *up, bool toggle_ier);
166166

167167
/* Serial port overrun backoff */
168168
struct delayed_work overrun_backoff;

0 commit comments

Comments
 (0)