hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
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;
....@@ -1053,6 +1048,9 @@
10531048 */
10541049 static inline void pl011_dma_rx_stop(struct uart_amba_port *uap)
10551050 {
1051
+ if (!uap->using_rx_dma)
1052
+ return;
1053
+
10561054 /* FIXME. Just disable the DMA enable */
10571055 uap->dmacr &= ~UART011_RXDMAE;
10581056 pl011_write(uap->dmacr, uap, REG_DMACR);
....@@ -1237,10 +1235,6 @@
12371235
12381236 #else
12391237 /* Blank functions if the DMA engine is not available */
1240
-static inline void pl011_dma_probe(struct uart_amba_port *uap)
1241
-{
1242
-}
1243
-
12441238 static inline void pl011_dma_remove(struct uart_amba_port *uap)
12451239 {
12461240 }
....@@ -1333,6 +1327,15 @@
13331327 pl011_write(uap->im, uap, REG_IMSC);
13341328
13351329 pl011_dma_rx_stop(uap);
1330
+}
1331
+
1332
+static void pl011_throttle_rx(struct uart_port *port)
1333
+{
1334
+ unsigned long flags;
1335
+
1336
+ spin_lock_irqsave(&port->lock, flags);
1337
+ pl011_stop_rx(port);
1338
+ spin_unlock_irqrestore(&port->lock, flags);
13361339 }
13371340
13381341 static void pl011_enable_ms(struct uart_port *port)
....@@ -1459,8 +1462,6 @@
14591462
14601463 static void check_apply_cts_event_workaround(struct uart_amba_port *uap)
14611464 {
1462
- unsigned int dummy_read;
1463
-
14641465 if (!uap->vendor->cts_event_workaround)
14651466 return;
14661467
....@@ -1472,8 +1473,8 @@
14721473 * single apb access will incur 2 pclk(133.12Mhz) delay,
14731474 * so add 2 dummy reads
14741475 */
1475
- dummy_read = pl011_read(uap, REG_ICR);
1476
- dummy_read = pl011_read(uap, REG_ICR);
1476
+ pl011_read(uap, REG_ICR);
1477
+ pl011_read(uap, REG_ICR);
14771478 }
14781479
14791480 static irqreturn_t pl011_int(int irq, void *dev_id)
....@@ -1718,7 +1719,7 @@
17181719 {
17191720 pl011_write(uap->im, uap, REG_IMSC);
17201721
1721
- return request_irq(uap->port.irq, pl011_int, 0, "uart-pl011", uap);
1722
+ return request_irq(uap->port.irq, pl011_int, IRQF_SHARED, "uart-pl011", uap);
17221723 }
17231724
17241725 /*
....@@ -1728,9 +1729,10 @@
17281729 */
17291730 static void pl011_enable_interrupts(struct uart_amba_port *uap)
17301731 {
1732
+ unsigned long flags;
17311733 unsigned int i;
17321734
1733
- spin_lock_irq(&uap->port.lock);
1735
+ spin_lock_irqsave(&uap->port.lock, flags);
17341736
17351737 /* Clear out any spuriously appearing RX interrupts */
17361738 pl011_write(UART011_RTIS | UART011_RXIS, uap, REG_ICR);
....@@ -1752,7 +1754,23 @@
17521754 if (!pl011_dma_rx_running(uap))
17531755 uap->im |= UART011_RXIM;
17541756 pl011_write(uap->im, uap, REG_IMSC);
1755
- spin_unlock_irq(&uap->port.lock);
1757
+ spin_unlock_irqrestore(&uap->port.lock, flags);
1758
+}
1759
+
1760
+static void pl011_unthrottle_rx(struct uart_port *port)
1761
+{
1762
+ struct uart_amba_port *uap = container_of(port, struct uart_amba_port, port);
1763
+ unsigned long flags;
1764
+
1765
+ spin_lock_irqsave(&uap->port.lock, flags);
1766
+
1767
+ uap->im = UART011_RTIM;
1768
+ if (!pl011_dma_rx_running(uap))
1769
+ uap->im |= UART011_RXIM;
1770
+
1771
+ pl011_write(uap->im, uap, REG_IMSC);
1772
+
1773
+ spin_unlock_irqrestore(&uap->port.lock, flags);
17561774 }
17571775
17581776 static int pl011_startup(struct uart_port *port)
....@@ -2127,6 +2145,8 @@
21272145 .stop_tx = pl011_stop_tx,
21282146 .start_tx = pl011_start_tx,
21292147 .stop_rx = pl011_stop_rx,
2148
+ .throttle = pl011_throttle_rx,
2149
+ .unthrottle = pl011_unthrottle_rx,
21302150 .enable_ms = pl011_enable_ms,
21312151 .break_ctl = pl011_break_ctl,
21322152 .startup = pl011_startup,
....@@ -2191,24 +2211,18 @@
21912211 {
21922212 struct uart_amba_port *uap = amba_ports[co->index];
21932213 unsigned int old_cr = 0, new_cr;
2194
- unsigned long flags = 0;
2214
+ unsigned long flags;
21952215 int locked = 1;
21962216
21972217 clk_enable(uap->clk);
21982218
2199
- /*
2200
- * local_irq_save(flags);
2201
- *
2202
- * This local_irq_save() is nonsense. If we come in via sysrq
2203
- * handling then interrupts are already disabled. Aside of
2204
- * that the port.sysrq check is racy on SMP regardless.
2205
- */
2219
+ local_irq_save(flags);
22062220 if (uap->port.sysrq)
22072221 locked = 0;
22082222 else if (oops_in_progress)
2209
- locked = spin_trylock_irqsave(&uap->port.lock, flags);
2223
+ locked = spin_trylock(&uap->port.lock);
22102224 else
2211
- spin_lock_irqsave(&uap->port.lock, flags);
2225
+ spin_lock(&uap->port.lock);
22122226
22132227 /*
22142228 * First save the CR then disable the interrupts
....@@ -2234,7 +2248,8 @@
22342248 pl011_write(old_cr, uap, REG_CR);
22352249
22362250 if (locked)
2237
- spin_unlock_irqrestore(&uap->port.lock, flags);
2251
+ spin_unlock(&uap->port.lock);
2252
+ local_irq_restore(flags);
22382253
22392254 clk_disable(uap->clk);
22402255 }
....@@ -2432,6 +2447,37 @@
24322447 uart_console_write(&dev->port, s, n, pl011_putc);
24332448 }
24342449
2450
+#ifdef CONFIG_CONSOLE_POLL
2451
+static int pl011_getc(struct uart_port *port)
2452
+{
2453
+ if (readl(port->membase + UART01x_FR) & UART01x_FR_RXFE)
2454
+ return NO_POLL_CHAR;
2455
+
2456
+ if (port->iotype == UPIO_MEM32)
2457
+ return readl(port->membase + UART01x_DR);
2458
+ else
2459
+ return readb(port->membase + UART01x_DR);
2460
+}
2461
+
2462
+static int pl011_early_read(struct console *con, char *s, unsigned int n)
2463
+{
2464
+ struct earlycon_device *dev = con->data;
2465
+ int ch, num_read = 0;
2466
+
2467
+ while (num_read < n) {
2468
+ ch = pl011_getc(&dev->port);
2469
+ if (ch == NO_POLL_CHAR)
2470
+ break;
2471
+
2472
+ s[num_read++] = ch;
2473
+ }
2474
+
2475
+ return num_read;
2476
+}
2477
+#else
2478
+#define pl011_early_read NULL
2479
+#endif
2480
+
24352481 /*
24362482 * On non-ACPI systems, earlycon is enabled by specifying
24372483 * "earlycon=pl011,<address>" on the kernel command line.
....@@ -2451,6 +2497,7 @@
24512497 return -ENODEV;
24522498
24532499 device->con->write = pl011_early_write;
2500
+ device->con->read = pl011_early_read;
24542501
24552502 return 0;
24562503 }
....@@ -2569,9 +2616,9 @@
25692616 uap->port.mapbase = mmiobase->start;
25702617 uap->port.membase = base;
25712618 uap->port.fifosize = uap->fifosize;
2619
+ uap->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_AMBA_PL011_CONSOLE);
25722620 uap->port.flags = UPF_BOOT_AUTOCONF;
25732621 uap->port.line = index;
2574
- spin_lock_init(&uap->port.lock);
25752622
25762623 amba_ports[index] = uap;
25772624
....@@ -2642,13 +2689,12 @@
26422689 return pl011_register_port(uap);
26432690 }
26442691
2645
-static int pl011_remove(struct amba_device *dev)
2692
+static void pl011_remove(struct amba_device *dev)
26462693 {
26472694 struct uart_amba_port *uap = amba_get_drvdata(dev);
26482695
26492696 uart_remove_one_port(&amba_reg, &uap->port);
26502697 pl011_unregister_port(uap);
2651
- return 0;
26522698 }
26532699
26542700 #ifdef CONFIG_PM_SLEEP
....@@ -2706,11 +2752,8 @@
27062752 return -ENOMEM;
27072753
27082754 ret = platform_get_irq(pdev, 0);
2709
- if (ret < 0) {
2710
- if (ret != -EPROBE_DEFER)
2711
- dev_err(&pdev->dev, "cannot obtain irq\n");
2755
+ if (ret < 0)
27122756 return ret;
2713
- }
27142757 uap->port.irq = ret;
27152758
27162759 #ifdef CONFIG_ACPI_SPCR_TABLE
....@@ -2767,6 +2810,7 @@
27672810 .remove = sbsa_uart_remove,
27682811 .driver = {
27692812 .name = "sbsa-uart",
2813
+ .pm = &pl011_dev_pm_ops,
27702814 .of_match_table = of_match_ptr(sbsa_uart_of_match),
27712815 .acpi_match_table = ACPI_PTR(sbsa_uart_acpi_match),
27722816 .suppress_bind_attrs = IS_BUILTIN(CONFIG_SERIAL_AMBA_PL011),