forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 cde9070d9970eef1f7ec2360586c802a16230ad8
kernel/drivers/tty/serial/8250/8250_port.c
....@@ -15,6 +15,7 @@
1515 #include <linux/moduleparam.h>
1616 #include <linux/ioport.h>
1717 #include <linux/init.h>
18
+#include <linux/irq.h>
1819 #include <linux/console.h>
1920 #include <linux/gpio/consumer.h>
2021 #include <linux/sysrq.h>
....@@ -737,7 +738,7 @@
737738 serial_out(p, UART_EFR, UART_EFR_ECB);
738739 serial_out(p, UART_LCR, 0);
739740 }
740
- serial8250_set_IER(p, sleep ? UART_IERX_SLEEP : 0);
741
+ serial_out(p, UART_IER, sleep ? UART_IERX_SLEEP : 0);
741742 if (p->capabilities & UART_CAP_EFR) {
742743 serial_out(p, UART_LCR, UART_LCR_CONF_MODE_B);
743744 serial_out(p, UART_EFR, efr);
....@@ -1411,7 +1412,7 @@
14111412
14121413 up->ier &= ~(UART_IER_RLSI | UART_IER_RDI);
14131414 up->port.read_status_mask &= ~UART_LSR_DR;
1414
- serial8250_set_IER(up, up->ier);
1415
+ serial_port_out(port, UART_IER, up->ier);
14151416
14161417 serial8250_rpm_put(up);
14171418 }
....@@ -1441,7 +1442,7 @@
14411442 serial8250_clear_and_reinit_fifos(p);
14421443
14431444 p->ier |= UART_IER_RLSI | UART_IER_RDI;
1444
- serial8250_set_IER(p, p->ier);
1445
+ serial_port_out(&p->port, UART_IER, p->ier);
14451446 }
14461447 }
14471448 EXPORT_SYMBOL_GPL(serial8250_em485_stop_tx);
....@@ -1688,7 +1689,7 @@
16881689 mctrl_gpio_disable_ms(up->gpios);
16891690
16901691 up->ier &= ~UART_IER_MSI;
1691
- serial8250_set_IER(up, up->ier);
1692
+ serial_port_out(port, UART_IER, up->ier);
16921693 }
16931694
16941695 static void serial8250_enable_ms(struct uart_port *port)
....@@ -1704,7 +1705,7 @@
17041705 up->ier |= UART_IER_MSI;
17051706
17061707 serial8250_rpm_get(up);
1707
- serial8250_set_IER(up, up->ier);
1708
+ serial_port_out(port, UART_IER, up->ier);
17081709 serial8250_rpm_put(up);
17091710 }
17101711
....@@ -1909,6 +1910,7 @@
19091910 unsigned long flags;
19101911 struct uart_8250_port *up = up_to_u8250p(port);
19111912 #ifndef CONFIG_ARCH_ROCKCHIP
1913
+ struct tty_port *tport = &port->state->port;
19121914 bool skip_rx = false;
19131915 #endif
19141916
....@@ -1944,6 +1946,11 @@
19441946 skip_rx = true;
19451947
19461948 if (status & (UART_LSR_DR | UART_LSR_BI) && !skip_rx) {
1949
+ struct irq_data *d;
1950
+
1951
+ d = irq_get_irq_data(port->irq);
1952
+ if (d && irqd_is_wakeup_set(d))
1953
+ pm_wakeup_event(tport->tty->dev, 0);
19471954 if (!up->dma || handle_rx_dma(up, iir))
19481955 status = serial8250_rx_chars(up, status);
19491956 }
....@@ -2022,19 +2029,25 @@
20222029 static unsigned int serial8250_tx_empty(struct uart_port *port)
20232030 {
20242031 struct uart_8250_port *up = up_to_u8250p(port);
2032
+ unsigned int result = 0;
20252033 unsigned long flags;
20262034 unsigned int lsr;
20272035
20282036 serial8250_rpm_get(up);
20292037
20302038 spin_lock_irqsave(&port->lock, flags);
2031
- lsr = serial_port_in(port, UART_LSR);
2032
- up->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS;
2039
+ if (!serial8250_tx_dma_running(up)) {
2040
+ lsr = serial_port_in(port, UART_LSR);
2041
+ up->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS;
2042
+
2043
+ if ((lsr & BOTH_EMPTY) == BOTH_EMPTY)
2044
+ result = TIOCSER_TEMT;
2045
+ }
20332046 spin_unlock_irqrestore(&port->lock, flags);
20342047
20352048 serial8250_rpm_put(up);
20362049
2037
- return (lsr & BOTH_EMPTY) == BOTH_EMPTY ? TIOCSER_TEMT : 0;
2050
+ return result;
20382051 }
20392052
20402053 unsigned int serial8250_do_get_mctrl(struct uart_port *port)
....@@ -2171,7 +2184,14 @@
21712184 struct uart_8250_port *up = up_to_u8250p(port);
21722185
21732186 serial8250_rpm_get(up);
2174
- ier = serial8250_clear_IER(up);
2187
+ /*
2188
+ * First save the IER then disable the interrupts
2189
+ */
2190
+ ier = serial_port_in(port, UART_IER);
2191
+ if (up->capabilities & UART_CAP_UUE)
2192
+ serial_port_out(port, UART_IER, UART_IER_UUE);
2193
+ else
2194
+ serial_port_out(port, UART_IER, 0);
21752195
21762196 wait_for_xmitr(up, BOTH_EMPTY);
21772197 /*
....@@ -2184,7 +2204,7 @@
21842204 * and restore the IER
21852205 */
21862206 wait_for_xmitr(up, BOTH_EMPTY);
2187
- serial8250_set_IER(up, ier);
2207
+ serial_port_out(port, UART_IER, ier);
21882208 serial8250_rpm_put(up);
21892209 }
21902210
....@@ -2491,7 +2511,7 @@
24912511 */
24922512 spin_lock_irqsave(&port->lock, flags);
24932513 up->ier = 0;
2494
- serial8250_set_IER(up, 0);
2514
+ serial_port_out(port, UART_IER, 0);
24952515 spin_unlock_irqrestore(&port->lock, flags);
24962516
24972517 synchronize_irq(port->irq);
....@@ -2863,7 +2883,7 @@
28632883 if (up->capabilities & UART_CAP_RTOIE)
28642884 up->ier |= UART_IER_RTOIE;
28652885
2866
- serial8250_set_IER(up, up->ier);
2886
+ serial_port_out(port, UART_IER, up->ier);
28672887 #endif
28682888
28692889 if (up->capabilities & UART_CAP_EFR) {
....@@ -2923,7 +2943,7 @@
29232943 if (up->capabilities & UART_CAP_RTOIE)
29242944 up->ier |= UART_IER_RTOIE;
29252945
2926
- serial8250_set_IER(up, up->ier);
2946
+ serial_port_out(port, UART_IER, up->ier);
29272947 #endif
29282948
29292949 spin_unlock_irqrestore(&port->lock, flags);
....@@ -3319,6 +3339,7 @@
33193339 struct uart_port *port = &up->port;
33203340
33213341 spin_lock_init(&port->lock);
3342
+ port->pm = NULL;
33223343 port->ops = &serial8250_pops;
33233344 port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_8250_CONSOLE);
33243345
....@@ -3355,24 +3376,12 @@
33553376
33563377 #ifdef CONFIG_SERIAL_8250_CONSOLE
33573378
3358
-static void serial8250_console_putchar_locked(struct uart_port *port, int ch)
3379
+static void serial8250_console_putchar(struct uart_port *port, int ch)
33593380 {
33603381 struct uart_8250_port *up = up_to_u8250p(port);
33613382
33623383 wait_for_xmitr(up, UART_LSR_THRE);
33633384 serial_port_out(port, UART_TX, ch);
3364
-}
3365
-
3366
-static void serial8250_console_putchar(struct uart_port *port, int ch)
3367
-{
3368
- struct uart_8250_port *up = up_to_u8250p(port);
3369
- unsigned int flags;
3370
-
3371
- wait_for_xmitr(up, UART_LSR_THRE);
3372
-
3373
- console_atomic_lock(&flags);
3374
- serial8250_console_putchar_locked(port, ch);
3375
- console_atomic_unlock(flags);
33763385 }
33773386
33783387 /*
....@@ -3396,32 +3405,6 @@
33963405 serial8250_out_MCR(up, up->mcr | UART_MCR_DTR | UART_MCR_RTS);
33973406 }
33983407
3399
-void serial8250_console_write_atomic(struct uart_8250_port *up,
3400
- const char *s, unsigned int count)
3401
-{
3402
- struct uart_port *port = &up->port;
3403
- unsigned int flags;
3404
- unsigned int ier;
3405
-
3406
- console_atomic_lock(&flags);
3407
-
3408
- touch_nmi_watchdog();
3409
-
3410
- ier = serial8250_clear_IER(up);
3411
-
3412
- if (atomic_fetch_inc(&up->console_printing)) {
3413
- uart_console_write(port, "\n", 1,
3414
- serial8250_console_putchar_locked);
3415
- }
3416
- uart_console_write(port, s, count, serial8250_console_putchar_locked);
3417
- atomic_dec(&up->console_printing);
3418
-
3419
- wait_for_xmitr(up, BOTH_EMPTY);
3420
- serial8250_set_IER(up, ier);
3421
-
3422
- console_atomic_unlock(flags);
3423
-}
3424
-
34253408 /*
34263409 * Print a string to the serial port trying not to disturb
34273410 * any possible real use of the port...
....@@ -3438,12 +3421,24 @@
34383421 struct uart_port *port = &up->port;
34393422 unsigned long flags;
34403423 unsigned int ier;
3424
+ int locked = 1;
34413425
34423426 touch_nmi_watchdog();
34433427
3444
- spin_lock_irqsave(&port->lock, flags);
3428
+ if (oops_in_progress)
3429
+ locked = spin_trylock_irqsave(&port->lock, flags);
3430
+ else
3431
+ spin_lock_irqsave(&port->lock, flags);
34453432
3446
- ier = serial8250_clear_IER(up);
3433
+ /*
3434
+ * First save the IER then disable the interrupts
3435
+ */
3436
+ ier = serial_port_in(port, UART_IER);
3437
+
3438
+ if (up->capabilities & UART_CAP_UUE)
3439
+ serial_port_out(port, UART_IER, UART_IER_UUE);
3440
+ else
3441
+ serial_port_out(port, UART_IER, 0);
34473442
34483443 /* check scratch reg to see if port powered off during system sleep */
34493444 if (up->canary && (up->canary != serial_port_in(port, UART_SCR))) {
....@@ -3457,9 +3452,7 @@
34573452 mdelay(port->rs485.delay_rts_before_send);
34583453 }
34593454
3460
- atomic_inc(&up->console_printing);
34613455 uart_console_write(port, s, count, serial8250_console_putchar);
3462
- atomic_dec(&up->console_printing);
34633456
34643457 /*
34653458 * Finally, wait for transmitter to become empty
....@@ -3472,7 +3465,8 @@
34723465 if (em485->tx_stopped)
34733466 up->rs485_stop_tx(up);
34743467 }
3475
- serial8250_set_IER(up, ier);
3468
+
3469
+ serial_port_out(port, UART_IER, ier);
34763470
34773471 /*
34783472 * The receive handling will happen properly because the
....@@ -3484,7 +3478,8 @@
34843478 if (up->msr_saved_flags)
34853479 serial8250_modem_status(up);
34863480
3487
- spin_unlock_irqrestore(&port->lock, flags);
3481
+ if (locked)
3482
+ spin_unlock_irqrestore(&port->lock, flags);
34883483 }
34893484
34903485 static unsigned int probe_baud(struct uart_port *port)
....@@ -3504,7 +3499,6 @@
35043499
35053500 int serial8250_console_setup(struct uart_port *port, char *options, bool probe)
35063501 {
3507
- struct uart_8250_port *up = up_to_u8250p(port);
35083502 int baud = 9600;
35093503 int bits = 8;
35103504 int parity = 'n';
....@@ -3513,8 +3507,6 @@
35133507
35143508 if (!port->iobase && !port->membase)
35153509 return -ENODEV;
3516
-
3517
- atomic_set(&up->console_printing, 0);
35183510
35193511 if (options)
35203512 uart_parse_options(options, &baud, &parity, &bits, &flow);