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,
....@@ -2191,18 +2199,24 @@
21912199 {
21922200 struct uart_amba_port *uap = amba_ports[co->index];
21932201 unsigned int old_cr = 0, new_cr;
2194
- unsigned long flags;
2202
+ unsigned long flags = 0;
21952203 int locked = 1;
21962204
21972205 clk_enable(uap->clk);
21982206
2199
- local_irq_save(flags);
2207
+ /*
2208
+ * local_irq_save(flags);
2209
+ *
2210
+ * This local_irq_save() is nonsense. If we come in via sysrq
2211
+ * handling then interrupts are already disabled. Aside of
2212
+ * that the port.sysrq check is racy on SMP regardless.
2213
+ */
22002214 if (uap->port.sysrq)
22012215 locked = 0;
22022216 else if (oops_in_progress)
2203
- locked = spin_trylock(&uap->port.lock);
2217
+ locked = spin_trylock_irqsave(&uap->port.lock, flags);
22042218 else
2205
- spin_lock(&uap->port.lock);
2219
+ spin_lock_irqsave(&uap->port.lock, flags);
22062220
22072221 /*
22082222 * First save the CR then disable the interrupts
....@@ -2228,8 +2242,7 @@
22282242 pl011_write(old_cr, uap, REG_CR);
22292243
22302244 if (locked)
2231
- spin_unlock(&uap->port.lock);
2232
- local_irq_restore(flags);
2245
+ spin_unlock_irqrestore(&uap->port.lock, flags);
22332246
22342247 clk_disable(uap->clk);
22352248 }
....@@ -2427,6 +2440,37 @@
24272440 uart_console_write(&dev->port, s, n, pl011_putc);
24282441 }
24292442
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
+
24302474 /*
24312475 * On non-ACPI systems, earlycon is enabled by specifying
24322476 * "earlycon=pl011,<address>" on the kernel command line.
....@@ -2446,6 +2490,7 @@
24462490 return -ENODEV;
24472491
24482492 device->con->write = pl011_early_write;
2493
+ device->con->read = pl011_early_read;
24492494
24502495 return 0;
24512496 }
....@@ -2564,9 +2609,9 @@
25642609 uap->port.mapbase = mmiobase->start;
25652610 uap->port.membase = base;
25662611 uap->port.fifosize = uap->fifosize;
2612
+ uap->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_AMBA_PL011_CONSOLE);
25672613 uap->port.flags = UPF_BOOT_AUTOCONF;
25682614 uap->port.line = index;
2569
- spin_lock_init(&uap->port.lock);
25702615
25712616 amba_ports[index] = uap;
25722617
....@@ -2637,13 +2682,12 @@
26372682 return pl011_register_port(uap);
26382683 }
26392684
2640
-static int pl011_remove(struct amba_device *dev)
2685
+static void pl011_remove(struct amba_device *dev)
26412686 {
26422687 struct uart_amba_port *uap = amba_get_drvdata(dev);
26432688
26442689 uart_remove_one_port(&amba_reg, &uap->port);
26452690 pl011_unregister_port(uap);
2646
- return 0;
26472691 }
26482692
26492693 #ifdef CONFIG_PM_SLEEP
....@@ -2701,11 +2745,8 @@
27012745 return -ENOMEM;
27022746
27032747 ret = platform_get_irq(pdev, 0);
2704
- if (ret < 0) {
2705
- if (ret != -EPROBE_DEFER)
2706
- dev_err(&pdev->dev, "cannot obtain irq\n");
2748
+ if (ret < 0)
27072749 return ret;
2708
- }
27092750 uap->port.irq = ret;
27102751
27112752 #ifdef CONFIG_ACPI_SPCR_TABLE
....@@ -2762,6 +2803,7 @@
27622803 .remove = sbsa_uart_remove,
27632804 .driver = {
27642805 .name = "sbsa-uart",
2806
+ .pm = &pl011_dev_pm_ops,
27652807 .of_match_table = of_match_ptr(sbsa_uart_of_match),
27662808 .acpi_match_table = ACPI_PTR(sbsa_uart_acpi_match),
27672809 .suppress_bind_attrs = IS_BUILTIN(CONFIG_SERIAL_AMBA_PL011),