forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
kernel/drivers/tty/serial/8250/8250_core.c
....@@ -14,6 +14,7 @@
1414 * serial8250_register_8250_port() ports
1515 */
1616
17
+#include <linux/acpi.h>
1718 #include <linux/module.h>
1819 #include <linux/moduleparam.h>
1920 #include <linux/ioport.h>
....@@ -22,6 +23,7 @@
2223 #include <linux/sysrq.h>
2324 #include <linux/delay.h>
2425 #include <linux/platform_device.h>
26
+#include <linux/pm_runtime.h>
2527 #include <linux/tty.h>
2628 #include <linux/ratelimit.h>
2729 #include <linux/tty_flip.h>
....@@ -130,12 +132,8 @@
130132
131133 l = l->next;
132134
133
- if (l == i->head && pass_counter++ > PASS_LIMIT) {
134
- /* If we hit this, we're dead. */
135
- printk_ratelimited(KERN_ERR
136
- "serial8250: too much work for irq%d\n", irq);
135
+ if (l == i->head && pass_counter++ > PASS_LIMIT)
137136 break;
138
- }
139137 } while (l != end);
140138
141139 spin_unlock(&i->lock);
....@@ -277,10 +275,8 @@
277275 * Must disable interrupts or else we risk racing with the interrupt
278276 * based handler.
279277 */
280
- if (up->port.irq) {
281
- ier = serial_in(up, UART_IER);
282
- serial_out(up, UART_IER, 0);
283
- }
278
+ if (up->port.irq)
279
+ ier = serial8250_clear_IER(up);
284280
285281 iir = serial_in(up, UART_IIR);
286282
....@@ -303,7 +299,7 @@
303299 serial8250_tx_chars(up);
304300
305301 if (up->port.irq)
306
- serial_out(up, UART_IER, ier);
302
+ serial8250_set_IER(up, ier);
307303
308304 spin_unlock_irqrestore(&up->port.lock, flags);
309305
....@@ -334,9 +330,9 @@
334330 * hardware interrupt, we use a timer-based system. The original
335331 * driver used to do this with IRQ0.
336332 */
337
- if (!port->irq) {
333
+ if (!port->irq)
338334 mod_timer(&up->timer, jiffies + uart_poll_timeout(port));
339
- } else
335
+ else
340336 retval = serial_link_irq_chain(up);
341337
342338 return retval;
....@@ -575,6 +571,9 @@
575571
576572 up->port.dev = dev;
577573
574
+ if (uart_console_enabled(&up->port))
575
+ pm_runtime_get_sync(up->port.dev);
576
+
578577 serial8250_apply_quirks(up);
579578 uart_add_one_port(drv, &up->port);
580579 }
....@@ -582,6 +581,14 @@
582581 }
583582
584583 #ifdef CONFIG_SERIAL_8250_CONSOLE
584
+
585
+static void univ8250_console_write_atomic(struct console *co, const char *s,
586
+ unsigned int count)
587
+{
588
+ struct uart_8250_port *up = &serial8250_ports[co->index];
589
+
590
+ serial8250_console_write_atomic(up, s, count);
591
+}
585592
586593 static void univ8250_console_write(struct console *co, const char *s,
587594 unsigned int count)
....@@ -611,6 +618,14 @@
611618 if (retval != 0)
612619 port->cons = NULL;
613620 return retval;
621
+}
622
+
623
+static int univ8250_console_exit(struct console *co)
624
+{
625
+ struct uart_port *port;
626
+
627
+ port = &serial8250_ports[co->index].port;
628
+ return serial8250_console_exit(port);
614629 }
615630
616631 /**
....@@ -668,9 +683,11 @@
668683
669684 static struct console univ8250_console = {
670685 .name = "ttyS",
686
+ .write_atomic = univ8250_console_write_atomic,
671687 .write = univ8250_console_write,
672688 .device = uart_console_device,
673689 .setup = univ8250_console_setup,
690
+ .exit = univ8250_console_exit,
674691 .match = univ8250_console_match,
675692 .flags = CON_PRINTBUFFER | CON_ANYTIME,
676693 .index = -1,
....@@ -758,6 +775,7 @@
758775 if (!console_suspend_enabled && uart_console(port) &&
759776 port->type != PORT_8250) {
760777 unsigned char canary = 0xa5;
778
+
761779 serial_out(up, UART_SCR, canary);
762780 if (serial_in(up, UART_SCR) == canary)
763781 up->canary = canary;
....@@ -820,6 +838,7 @@
820838 uart.port.flags = p->flags;
821839 uart.port.mapbase = p->mapbase;
822840 uart.port.hub6 = p->hub6;
841
+ uart.port.has_sysrq = p->has_sysrq;
823842 uart.port.private_data = p->private_data;
824843 uart.port.type = p->type;
825844 uart.port.serial_in = p->serial_in;
....@@ -987,6 +1006,8 @@
9871006
9881007 uart = serial8250_find_match_or_unused(&up->port);
9891008 if (uart && uart->port.type != PORT_8250_CIR) {
1009
+ struct mctrl_gpios *gpios;
1010
+
9901011 if (uart->port.dev)
9911012 uart_remove_one_port(&serial8250_reg, &uart->port);
9921013
....@@ -1009,6 +1030,8 @@
10091030 uart->port.unthrottle = up->port.unthrottle;
10101031 uart->port.rs485_config = up->port.rs485_config;
10111032 uart->port.rs485 = up->port.rs485;
1033
+ uart->rs485_start_tx = up->rs485_start_tx;
1034
+ uart->rs485_stop_tx = up->rs485_stop_tx;
10121035 uart->dma = up->dma;
10131036 #ifdef CONFIG_ARCH_ROCKCHIP
10141037 uart->port.line = up->port.line;
....@@ -1017,12 +1040,30 @@
10171040 if (uart->port.fifosize && !uart->tx_loadsz)
10181041 uart->tx_loadsz = uart->port.fifosize;
10191042
1020
- if (up->port.dev)
1043
+ if (up->port.dev) {
10211044 uart->port.dev = up->port.dev;
1045
+ ret = uart_get_rs485_mode(&uart->port);
1046
+ if (ret)
1047
+ goto err;
1048
+ }
10221049
10231050 if (up->port.flags & UPF_FIXED_TYPE)
10241051 uart->port.type = up->port.type;
10251052
1053
+ /*
1054
+ * Only call mctrl_gpio_init(), if the device has no ACPI
1055
+ * companion device
1056
+ */
1057
+ if (!has_acpi_companion(uart->port.dev)) {
1058
+ gpios = mctrl_gpio_init(&uart->port, 0);
1059
+ if (IS_ERR(gpios)) {
1060
+ ret = PTR_ERR(gpios);
1061
+ goto err;
1062
+ } else {
1063
+ uart->gpios = gpios;
1064
+ }
1065
+ }
1066
+
10261067 serial8250_set_defaults(uart);
10271068
10281069 /* Possibly override default I/O functions. */