forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
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,
....@@ -2432,6 +2440,37 @@
24322440 uart_console_write(&dev->port, s, n, pl011_putc);
24332441 }
24342442
2443
+#ifdef CONFIG_CONSOLE_POLL
2444
+static int pl011_getc(struct uart_port *port)
2445
+{
2446
+ if (readl(port->membase + UART01x_FR) & UART01x_FR_RXFE)
2447
+ return NO_POLL_CHAR;
2448
+
2449
+ if (port->iotype == UPIO_MEM32)
2450
+ return readl(port->membase + UART01x_DR);
2451
+ else
2452
+ return readb(port->membase + UART01x_DR);
2453
+}
2454
+
2455
+static int pl011_early_read(struct console *con, char *s, unsigned int n)
2456
+{
2457
+ struct earlycon_device *dev = con->data;
2458
+ int ch, num_read = 0;
2459
+
2460
+ while (num_read < n) {
2461
+ ch = pl011_getc(&dev->port);
2462
+ if (ch == NO_POLL_CHAR)
2463
+ break;
2464
+
2465
+ s[num_read++] = ch;
2466
+ }
2467
+
2468
+ return num_read;
2469
+}
2470
+#else
2471
+#define pl011_early_read NULL
2472
+#endif
2473
+
24352474 /*
24362475 * On non-ACPI systems, earlycon is enabled by specifying
24372476 * "earlycon=pl011,<address>" on the kernel command line.
....@@ -2451,6 +2490,7 @@
24512490 return -ENODEV;
24522491
24532492 device->con->write = pl011_early_write;
2493
+ device->con->read = pl011_early_read;
24542494
24552495 return 0;
24562496 }
....@@ -2569,9 +2609,9 @@
25692609 uap->port.mapbase = mmiobase->start;
25702610 uap->port.membase = base;
25712611 uap->port.fifosize = uap->fifosize;
2612
+ uap->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_AMBA_PL011_CONSOLE);
25722613 uap->port.flags = UPF_BOOT_AUTOCONF;
25732614 uap->port.line = index;
2574
- spin_lock_init(&uap->port.lock);
25752615
25762616 amba_ports[index] = uap;
25772617
....@@ -2642,13 +2682,12 @@
26422682 return pl011_register_port(uap);
26432683 }
26442684
2645
-static int pl011_remove(struct amba_device *dev)
2685
+static void pl011_remove(struct amba_device *dev)
26462686 {
26472687 struct uart_amba_port *uap = amba_get_drvdata(dev);
26482688
26492689 uart_remove_one_port(&amba_reg, &uap->port);
26502690 pl011_unregister_port(uap);
2651
- return 0;
26522691 }
26532692
26542693 #ifdef CONFIG_PM_SLEEP
....@@ -2706,11 +2745,8 @@
27062745 return -ENOMEM;
27072746
27082747 ret = platform_get_irq(pdev, 0);
2709
- if (ret < 0) {
2710
- if (ret != -EPROBE_DEFER)
2711
- dev_err(&pdev->dev, "cannot obtain irq\n");
2748
+ if (ret < 0)
27122749 return ret;
2713
- }
27142750 uap->port.irq = ret;
27152751
27162752 #ifdef CONFIG_ACPI_SPCR_TABLE
....@@ -2767,6 +2803,7 @@
27672803 .remove = sbsa_uart_remove,
27682804 .driver = {
27692805 .name = "sbsa-uart",
2806
+ .pm = &pl011_dev_pm_ops,
27702807 .of_match_table = of_match_ptr(sbsa_uart_of_match),
27712808 .acpi_match_table = ACPI_PTR(sbsa_uart_acpi_match),
27722809 .suppress_bind_attrs = IS_BUILTIN(CONFIG_SERIAL_AMBA_PL011),