forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 072de836f53be56a70cecf70b43ae43b7ce17376
kernel/drivers/tty/serial/amba-pl011.c
....@@ -16,11 +16,6 @@
1616 * and hooked into this driver.
1717 */
1818
19
-
20
-#if defined(CONFIG_SERIAL_AMBA_PL011_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
21
-#define SUPPORT_SYSRQ
22
-#endif
23
-
2419 #include <linux/module.h>
2520 #include <linux/ioport.h>
2621 #include <linux/init.h>
....@@ -417,7 +412,7 @@
417412 dma_cap_mask_t mask;
418413
419414 uap->dma_probed = true;
420
- chan = dma_request_slave_channel_reason(dev, "tx");
415
+ chan = dma_request_chan(dev, "tx");
421416 if (IS_ERR(chan)) {
422417 if (PTR_ERR(chan) == -EPROBE_DEFER) {
423418 uap->dma_probed = false;
....@@ -1237,10 +1232,6 @@
12371232
12381233 #else
12391234 /* Blank functions if the DMA engine is not available */
1240
-static inline void pl011_dma_probe(struct uart_amba_port *uap)
1241
-{
1242
-}
1243
-
12441235 static inline void pl011_dma_remove(struct uart_amba_port *uap)
12451236 {
12461237 }
....@@ -1333,6 +1324,15 @@
13331324 pl011_write(uap->im, uap, REG_IMSC);
13341325
13351326 pl011_dma_rx_stop(uap);
1327
+}
1328
+
1329
+static void pl011_throttle_rx(struct uart_port *port)
1330
+{
1331
+ unsigned long flags;
1332
+
1333
+ spin_lock_irqsave(&port->lock, flags);
1334
+ pl011_stop_rx(port);
1335
+ spin_unlock_irqrestore(&port->lock, flags);
13361336 }
13371337
13381338 static void pl011_enable_ms(struct uart_port *port)
....@@ -1459,8 +1459,6 @@
14591459
14601460 static void check_apply_cts_event_workaround(struct uart_amba_port *uap)
14611461 {
1462
- unsigned int dummy_read;
1463
-
14641462 if (!uap->vendor->cts_event_workaround)
14651463 return;
14661464
....@@ -1472,8 +1470,8 @@
14721470 * single apb access will incur 2 pclk(133.12Mhz) delay,
14731471 * so add 2 dummy reads
14741472 */
1475
- dummy_read = pl011_read(uap, REG_ICR);
1476
- dummy_read = pl011_read(uap, REG_ICR);
1473
+ pl011_read(uap, REG_ICR);
1474
+ pl011_read(uap, REG_ICR);
14771475 }
14781476
14791477 static irqreturn_t pl011_int(int irq, void *dev_id)
....@@ -1718,7 +1716,7 @@
17181716 {
17191717 pl011_write(uap->im, uap, REG_IMSC);
17201718
1721
- return request_irq(uap->port.irq, pl011_int, 0, "uart-pl011", uap);
1719
+ return request_irq(uap->port.irq, pl011_int, IRQF_SHARED, "uart-pl011", uap);
17221720 }
17231721
17241722 /*
....@@ -1728,9 +1726,10 @@
17281726 */
17291727 static void pl011_enable_interrupts(struct uart_amba_port *uap)
17301728 {
1729
+ unsigned long flags;
17311730 unsigned int i;
17321731
1733
- spin_lock_irq(&uap->port.lock);
1732
+ spin_lock_irqsave(&uap->port.lock, flags);
17341733
17351734 /* Clear out any spuriously appearing RX interrupts */
17361735 pl011_write(UART011_RTIS | UART011_RXIS, uap, REG_ICR);
....@@ -1752,7 +1751,14 @@
17521751 if (!pl011_dma_rx_running(uap))
17531752 uap->im |= UART011_RXIM;
17541753 pl011_write(uap->im, uap, REG_IMSC);
1755
- spin_unlock_irq(&uap->port.lock);
1754
+ spin_unlock_irqrestore(&uap->port.lock, flags);
1755
+}
1756
+
1757
+static void pl011_unthrottle_rx(struct uart_port *port)
1758
+{
1759
+ struct uart_amba_port *uap = container_of(port, struct uart_amba_port, port);
1760
+
1761
+ pl011_enable_interrupts(uap);
17561762 }
17571763
17581764 static int pl011_startup(struct uart_port *port)
....@@ -2127,6 +2133,8 @@
21272133 .stop_tx = pl011_stop_tx,
21282134 .start_tx = pl011_start_tx,
21292135 .stop_rx = pl011_stop_rx,
2136
+ .throttle = pl011_throttle_rx,
2137
+ .unthrottle = pl011_unthrottle_rx,
21302138 .enable_ms = pl011_enable_ms,
21312139 .break_ctl = pl011_break_ctl,
21322140 .startup = pl011_startup,
....@@ -2427,6 +2435,37 @@
24272435 uart_console_write(&dev->port, s, n, pl011_putc);
24282436 }
24292437
2438
+#ifdef CONFIG_CONSOLE_POLL
2439
+static int pl011_getc(struct uart_port *port)
2440
+{
2441
+ if (readl(port->membase + UART01x_FR) & UART01x_FR_RXFE)
2442
+ return NO_POLL_CHAR;
2443
+
2444
+ if (port->iotype == UPIO_MEM32)
2445
+ return readl(port->membase + UART01x_DR);
2446
+ else
2447
+ return readb(port->membase + UART01x_DR);
2448
+}
2449
+
2450
+static int pl011_early_read(struct console *con, char *s, unsigned int n)
2451
+{
2452
+ struct earlycon_device *dev = con->data;
2453
+ int ch, num_read = 0;
2454
+
2455
+ while (num_read < n) {
2456
+ ch = pl011_getc(&dev->port);
2457
+ if (ch == NO_POLL_CHAR)
2458
+ break;
2459
+
2460
+ s[num_read++] = ch;
2461
+ }
2462
+
2463
+ return num_read;
2464
+}
2465
+#else
2466
+#define pl011_early_read NULL
2467
+#endif
2468
+
24302469 /*
24312470 * On non-ACPI systems, earlycon is enabled by specifying
24322471 * "earlycon=pl011,<address>" on the kernel command line.
....@@ -2446,6 +2485,7 @@
24462485 return -ENODEV;
24472486
24482487 device->con->write = pl011_early_write;
2488
+ device->con->read = pl011_early_read;
24492489
24502490 return 0;
24512491 }
....@@ -2564,9 +2604,9 @@
25642604 uap->port.mapbase = mmiobase->start;
25652605 uap->port.membase = base;
25662606 uap->port.fifosize = uap->fifosize;
2607
+ uap->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_AMBA_PL011_CONSOLE);
25672608 uap->port.flags = UPF_BOOT_AUTOCONF;
25682609 uap->port.line = index;
2569
- spin_lock_init(&uap->port.lock);
25702610
25712611 amba_ports[index] = uap;
25722612
....@@ -2637,13 +2677,12 @@
26372677 return pl011_register_port(uap);
26382678 }
26392679
2640
-static int pl011_remove(struct amba_device *dev)
2680
+static void pl011_remove(struct amba_device *dev)
26412681 {
26422682 struct uart_amba_port *uap = amba_get_drvdata(dev);
26432683
26442684 uart_remove_one_port(&amba_reg, &uap->port);
26452685 pl011_unregister_port(uap);
2646
- return 0;
26472686 }
26482687
26492688 #ifdef CONFIG_PM_SLEEP
....@@ -2701,11 +2740,8 @@
27012740 return -ENOMEM;
27022741
27032742 ret = platform_get_irq(pdev, 0);
2704
- if (ret < 0) {
2705
- if (ret != -EPROBE_DEFER)
2706
- dev_err(&pdev->dev, "cannot obtain irq\n");
2743
+ if (ret < 0)
27072744 return ret;
2708
- }
27092745 uap->port.irq = ret;
27102746
27112747 #ifdef CONFIG_ACPI_SPCR_TABLE
....@@ -2762,6 +2798,7 @@
27622798 .remove = sbsa_uart_remove,
27632799 .driver = {
27642800 .name = "sbsa-uart",
2801
+ .pm = &pl011_dev_pm_ops,
27652802 .of_match_table = of_match_ptr(sbsa_uart_of_match),
27662803 .acpi_match_table = ACPI_PTR(sbsa_uart_acpi_match),
27672804 .suppress_bind_attrs = IS_BUILTIN(CONFIG_SERIAL_AMBA_PL011),