forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/drivers/tty/serial/8250/8250_omap.c
....@@ -8,6 +8,7 @@
88 *
99 */
1010
11
+#include <linux/clk.h>
1112 #include <linux/device.h>
1213 #include <linux/io.h>
1314 #include <linux/module.h>
....@@ -26,6 +27,7 @@
2627 #include <linux/pm_qos.h>
2728 #include <linux/pm_wakeirq.h>
2829 #include <linux/dma-mapping.h>
30
+#include <linux/sys_soc.h>
2931
3032 #include "8250.h"
3133
....@@ -39,6 +41,9 @@
3941 * The same errata is applicable to AM335x and DRA7x processors too.
4042 */
4143 #define UART_ERRATA_CLOCK_DISABLE (1 << 3)
44
+#define UART_HAS_EFR2 BIT(4)
45
+#define UART_HAS_RHR_IT_DIS BIT(5)
46
+#define UART_RX_TIMEOUT_QUIRK BIT(6)
4247
4348 #define OMAP_UART_FCR_RX_TRIG 6
4449 #define OMAP_UART_FCR_TX_TRIG 4
....@@ -92,6 +97,17 @@
9297 #define OMAP_UART_REV_52 0x0502
9398 #define OMAP_UART_REV_63 0x0603
9499
100
+/* Interrupt Enable Register 2 */
101
+#define UART_OMAP_IER2 0x1B
102
+#define UART_OMAP_IER2_RHR_IT_DIS BIT(2)
103
+
104
+/* Enhanced features register 2 */
105
+#define UART_OMAP_EFR2 0x23
106
+#define UART_OMAP_EFR2_TIMEOUT_BEHAVE BIT(6)
107
+
108
+/* RX FIFO occupancy indicator */
109
+#define UART_OMAP_RX_LVL 0x19
110
+
95111 struct omap8250_priv {
96112 int line;
97113 u8 habit;
....@@ -104,6 +120,8 @@
104120 u8 delayed_restore;
105121 u16 quot;
106122
123
+ u8 tx_trigger;
124
+ u8 rx_trigger;
107125 bool is_suspending;
108126 int wakeirq;
109127 int wakeups_enabled;
....@@ -117,6 +135,17 @@
117135 bool throttled;
118136 };
119137
138
+struct omap8250_dma_params {
139
+ u32 rx_size;
140
+ u8 rx_trigger;
141
+ u8 tx_trigger;
142
+};
143
+
144
+struct omap8250_platdata {
145
+ struct omap8250_dma_params *dma_params;
146
+ u8 habit;
147
+};
148
+
120149 #ifdef CONFIG_SERIAL_8250_DMA
121150 static void omap_8250_rx_dma_flush(struct uart_8250_port *p);
122151 #else
....@@ -128,7 +157,11 @@
128157 return readl(up->port.membase + (reg << up->port.regshift));
129158 }
130159
131
-static void omap8250_set_mctrl(struct uart_port *port, unsigned int mctrl)
160
+/*
161
+ * Called on runtime PM resume path from omap8250_restore_regs(), and
162
+ * omap8250_set_mctrl().
163
+ */
164
+static void __omap8250_set_mctrl(struct uart_port *port, unsigned int mctrl)
132165 {
133166 struct uart_8250_port *up = up_to_u8250p(port);
134167 struct omap8250_priv *priv = up->port.private_data;
....@@ -136,18 +169,34 @@
136169
137170 serial8250_do_set_mctrl(port, mctrl);
138171
139
- /*
140
- * Turn off autoRTS if RTS is lowered and restore autoRTS setting
141
- * if RTS is raised
142
- */
143
- lcr = serial_in(up, UART_LCR);
144
- serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
145
- if ((mctrl & TIOCM_RTS) && (port->status & UPSTAT_AUTORTS))
146
- priv->efr |= UART_EFR_RTS;
147
- else
148
- priv->efr &= ~UART_EFR_RTS;
149
- serial_out(up, UART_EFR, priv->efr);
150
- serial_out(up, UART_LCR, lcr);
172
+ if (!mctrl_gpio_to_gpiod(up->gpios, UART_GPIO_RTS)) {
173
+ /*
174
+ * Turn off autoRTS if RTS is lowered and restore autoRTS
175
+ * setting if RTS is raised
176
+ */
177
+ lcr = serial_in(up, UART_LCR);
178
+ serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
179
+ if ((mctrl & TIOCM_RTS) && (port->status & UPSTAT_AUTORTS))
180
+ priv->efr |= UART_EFR_RTS;
181
+ else
182
+ priv->efr &= ~UART_EFR_RTS;
183
+ serial_out(up, UART_EFR, priv->efr);
184
+ serial_out(up, UART_LCR, lcr);
185
+ }
186
+}
187
+
188
+static void omap8250_set_mctrl(struct uart_port *port, unsigned int mctrl)
189
+{
190
+ int err;
191
+
192
+ err = pm_runtime_resume_and_get(port->dev);
193
+ if (err)
194
+ return;
195
+
196
+ __omap8250_set_mctrl(port, mctrl);
197
+
198
+ pm_runtime_mark_last_busy(port->dev);
199
+ pm_runtime_put_autosuspend(port->dev);
151200 }
152201
153202 /*
....@@ -162,27 +211,10 @@
162211 static void omap_8250_mdr1_errataset(struct uart_8250_port *up,
163212 struct omap8250_priv *priv)
164213 {
165
- u8 timeout = 255;
166
-
167214 serial_out(up, UART_OMAP_MDR1, priv->mdr1);
168215 udelay(2);
169216 serial_out(up, UART_FCR, up->fcr | UART_FCR_CLEAR_XMIT |
170217 UART_FCR_CLEAR_RCVR);
171
- /*
172
- * Wait for FIFO to empty: when empty, RX_FIFO_E bit is 0 and
173
- * TX_FIFO_E bit is 1.
174
- */
175
- while (UART_LSR_THRE != (serial_in(up, UART_LSR) &
176
- (UART_LSR_THRE | UART_LSR_DR))) {
177
- timeout--;
178
- if (!timeout) {
179
- /* Should *never* happen. we warn and carry on */
180
- dev_crit(up->port.dev, "Errata i202: timedout %x\n",
181
- serial_in(up, UART_LSR));
182
- break;
183
- }
184
- udelay(1);
185
- }
186218 }
187219
188220 static void omap_8250_get_divisor(struct uart_port *port, unsigned int baud,
....@@ -261,6 +293,7 @@
261293 {
262294 struct omap8250_priv *priv = up->port.private_data;
263295 struct uart_8250_dma *dma = up->dma;
296
+ u8 mcr = serial8250_in_MCR(up);
264297
265298 if (dma && dma->tx_running) {
266299 /*
....@@ -277,7 +310,7 @@
277310 serial_out(up, UART_EFR, UART_EFR_ECB);
278311
279312 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A);
280
- serial8250_out_MCR(up, UART_MCR_TCRTLR);
313
+ serial8250_out_MCR(up, mcr | UART_MCR_TCRTLR);
281314 serial_out(up, UART_FCR, up->fcr);
282315
283316 omap8250_update_scr(up, priv);
....@@ -287,13 +320,14 @@
287320 serial_out(up, UART_TI752_TCR, OMAP_UART_TCR_RESTORE(16) |
288321 OMAP_UART_TCR_HALT(52));
289322 serial_out(up, UART_TI752_TLR,
290
- TRIGGER_TLR_MASK(TX_TRIGGER) << UART_TI752_TLR_TX |
291
- TRIGGER_TLR_MASK(RX_TRIGGER) << UART_TI752_TLR_RX);
323
+ TRIGGER_TLR_MASK(priv->tx_trigger) << UART_TI752_TLR_TX |
324
+ TRIGGER_TLR_MASK(priv->rx_trigger) << UART_TI752_TLR_RX);
292325
293326 serial_out(up, UART_LCR, 0);
294327
295328 /* drop TCR + TLR access, we setup XON/XOFF later */
296
- serial8250_out_MCR(up, up->mcr);
329
+ serial8250_out_MCR(up, mcr);
330
+
297331 serial_out(up, UART_IER, up->ier);
298332
299333 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
....@@ -310,7 +344,10 @@
310344
311345 omap8250_update_mdr1(up, priv);
312346
313
- up->port.ops->set_mctrl(&up->port, up->port.mctrl);
347
+ __omap8250_set_mctrl(&up->port, up->port.mctrl);
348
+
349
+ if (up->port.rs485.flags & SER_RS485_ENABLED)
350
+ serial8250_em485_stop_tx(up);
314351 }
315352
316353 /*
....@@ -427,8 +464,8 @@
427464 * This is because threshold and trigger values are the same.
428465 */
429466 up->fcr = UART_FCR_ENABLE_FIFO;
430
- up->fcr |= TRIGGER_FCR_MASK(TX_TRIGGER) << OMAP_UART_FCR_TX_TRIG;
431
- up->fcr |= TRIGGER_FCR_MASK(RX_TRIGGER) << OMAP_UART_FCR_RX_TRIG;
467
+ up->fcr |= TRIGGER_FCR_MASK(priv->tx_trigger) << OMAP_UART_FCR_TX_TRIG;
468
+ up->fcr |= TRIGGER_FCR_MASK(priv->rx_trigger) << OMAP_UART_FCR_RX_TRIG;
432469
433470 priv->scr = OMAP_UART_SCR_RX_TRIG_GRANU1_MASK | OMAP_UART_SCR_TX_EMPTY |
434471 OMAP_UART_SCR_TX_TRIG_GRANU1_MASK;
....@@ -443,7 +480,9 @@
443480 priv->efr = 0;
444481 up->port.status &= ~(UPSTAT_AUTOCTS | UPSTAT_AUTORTS | UPSTAT_AUTOXOFF);
445482
446
- if (termios->c_cflag & CRTSCTS && up->port.flags & UPF_HARD_FLOW) {
483
+ if (termios->c_cflag & CRTSCTS && up->port.flags & UPF_HARD_FLOW &&
484
+ !mctrl_gpio_to_gpiod(up->gpios, UART_GPIO_RTS) &&
485
+ !mctrl_gpio_to_gpiod(up->gpios, UART_GPIO_CTS)) {
447486 /* Enable AUTOCTS (autoRTS is enabled when RTS is raised) */
448487 up->port.status |= UPSTAT_AUTOCTS | UPSTAT_AUTORTS;
449488 priv->efr |= UART_EFR_CTS;
....@@ -505,6 +544,11 @@
505544 static void omap_serial_fill_features_erratas(struct uart_8250_port *up,
506545 struct omap8250_priv *priv)
507546 {
547
+ const struct soc_device_attribute k3_soc_devices[] = {
548
+ { .family = "AM65X", },
549
+ { .family = "J721E", .revision = "SR1.0" },
550
+ { /* sentinel */ }
551
+ };
508552 u32 mvr, scheme;
509553 u16 revision, major, minor;
510554
....@@ -552,6 +596,14 @@
552596 default:
553597 break;
554598 }
599
+
600
+ /*
601
+ * AM65x SR1.0, AM65x SR2.0 and J721e SR1.0 don't
602
+ * don't have RHR_IT_DIS bit in IER2 register. So drop to flag
603
+ * to enable errata workaround.
604
+ */
605
+ if (soc_device_match(k3_soc_devices))
606
+ priv->habit &= ~UART_HAS_RHR_IT_DIS;
555607 }
556608
557609 static void omap8250_uart_qos_work(struct work_struct *work)
....@@ -559,7 +611,7 @@
559611 struct omap8250_priv *priv;
560612
561613 priv = container_of(work, struct omap8250_priv, qos_work);
562
- pm_qos_update_request(&priv->pm_qos_request, priv->latency);
614
+ cpu_latency_qos_update_request(&priv->pm_qos_request, priv->latency);
563615 }
564616
565617 #ifdef CONFIG_SERIAL_8250_DMA
....@@ -569,8 +621,9 @@
569621 static irqreturn_t omap8250_irq(int irq, void *dev_id)
570622 {
571623 struct uart_port *port = dev_id;
624
+ struct omap8250_priv *priv = port->private_data;
572625 struct uart_8250_port *up = up_to_u8250p(port);
573
- unsigned int iir;
626
+ unsigned int iir, lsr;
574627 int ret;
575628
576629 #ifdef CONFIG_SERIAL_8250_DMA
....@@ -581,8 +634,42 @@
581634 #endif
582635
583636 serial8250_rpm_get(up);
637
+ lsr = serial_port_in(port, UART_LSR);
584638 iir = serial_port_in(port, UART_IIR);
585639 ret = serial8250_handle_irq(port, iir);
640
+
641
+ /*
642
+ * On K3 SoCs, it is observed that RX TIMEOUT is signalled after
643
+ * FIFO has been drained, in which case a dummy read of RX FIFO
644
+ * is required to clear RX TIMEOUT condition.
645
+ */
646
+ if (priv->habit & UART_RX_TIMEOUT_QUIRK &&
647
+ (iir & UART_IIR_RX_TIMEOUT) == UART_IIR_RX_TIMEOUT &&
648
+ serial_port_in(port, UART_OMAP_RX_LVL) == 0) {
649
+ serial_port_in(port, UART_RX);
650
+ }
651
+
652
+ /* Stop processing interrupts on input overrun */
653
+ if ((lsr & UART_LSR_OE) && up->overrun_backoff_time_ms > 0) {
654
+ unsigned long delay;
655
+
656
+ /* Synchronize UART_IER access against the console. */
657
+ spin_lock(&port->lock);
658
+ up->ier = port->serial_in(port, UART_IER);
659
+ if (up->ier & (UART_IER_RLSI | UART_IER_RDI)) {
660
+ port->ops->stop_rx(port);
661
+ } else {
662
+ /* Keep restarting the timer until
663
+ * the input overrun subsides.
664
+ */
665
+ cancel_delayed_work(&up->overrun_backoff);
666
+ }
667
+ spin_unlock(&port->lock);
668
+
669
+ delay = msecs_to_jiffies(up->overrun_backoff_time_ms);
670
+ schedule_delayed_work(&up->overrun_backoff, delay);
671
+ }
672
+
586673 serial8250_rpm_put(up);
587674
588675 return IRQ_RETVAL(ret);
....@@ -602,7 +689,6 @@
602689
603690 pm_runtime_get_sync(port->dev);
604691
605
- up->mcr = 0;
606692 serial_out(up, UART_FCR, UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT);
607693
608694 serial_out(up, UART_LCR, UART_LCR_WLEN8);
....@@ -641,7 +727,7 @@
641727 priv->wer |= OMAP_UART_TX_WAKEUP_EN;
642728 serial_out(up, UART_OMAP_WER, priv->wer);
643729
644
- if (up->dma)
730
+ if (up->dma && !(priv->habit & UART_HAS_EFR2))
645731 up->dma->rx_dma(up);
646732
647733 pm_runtime_mark_last_busy(port->dev);
....@@ -666,6 +752,8 @@
666752 pm_runtime_get_sync(port->dev);
667753
668754 serial_out(up, UART_OMAP_WER, 0);
755
+ if (priv->habit & UART_HAS_EFR2)
756
+ serial_out(up, UART_OMAP_EFR2, 0x0);
669757
670758 up->ier = 0;
671759 serial_out(up, UART_IER, 0);
....@@ -689,49 +777,17 @@
689777 static void omap_8250_throttle(struct uart_port *port)
690778 {
691779 struct omap8250_priv *priv = port->private_data;
692
- struct uart_8250_port *up = up_to_u8250p(port);
693780 unsigned long flags;
694781
695782 pm_runtime_get_sync(port->dev);
696783
697784 spin_lock_irqsave(&port->lock, flags);
698
- up->ier &= ~(UART_IER_RLSI | UART_IER_RDI);
699
- serial_out(up, UART_IER, up->ier);
785
+ port->ops->stop_rx(port);
700786 priv->throttled = true;
701787 spin_unlock_irqrestore(&port->lock, flags);
702788
703789 pm_runtime_mark_last_busy(port->dev);
704790 pm_runtime_put_autosuspend(port->dev);
705
-}
706
-
707
-static int omap_8250_rs485_config(struct uart_port *port,
708
- struct serial_rs485 *rs485)
709
-{
710
- struct uart_8250_port *up = up_to_u8250p(port);
711
-
712
- /* Clamp the delays to [0, 100ms] */
713
- rs485->delay_rts_before_send = min(rs485->delay_rts_before_send, 100U);
714
- rs485->delay_rts_after_send = min(rs485->delay_rts_after_send, 100U);
715
-
716
- port->rs485 = *rs485;
717
-
718
- /*
719
- * Both serial8250_em485_init and serial8250_em485_destroy
720
- * are idempotent
721
- */
722
- if (rs485->flags & SER_RS485_ENABLED) {
723
- int ret = serial8250_em485_init(up);
724
-
725
- if (ret) {
726
- rs485->flags &= ~SER_RS485_ENABLED;
727
- port->rs485.flags &= ~SER_RS485_ENABLED;
728
- }
729
- return ret;
730
- }
731
-
732
- serial8250_em485_destroy(up);
733
-
734
- return 0;
735791 }
736792
737793 static void omap_8250_unthrottle(struct uart_port *port)
....@@ -747,6 +803,7 @@
747803 if (up->dma)
748804 up->dma->rx_dma(up);
749805 up->ier |= UART_IER_RLSI | UART_IER_RDI;
806
+ port->read_status_mask |= UART_LSR_DR;
750807 serial_out(up, UART_IER, up->ier);
751808 spin_unlock_irqrestore(&port->lock, flags);
752809
....@@ -757,35 +814,60 @@
757814 #ifdef CONFIG_SERIAL_8250_DMA
758815 static int omap_8250_rx_dma(struct uart_8250_port *p);
759816
817
+/* Must be called while priv->rx_dma_lock is held */
760818 static void __dma_rx_do_complete(struct uart_8250_port *p)
761819 {
762
- struct omap8250_priv *priv = p->port.private_data;
763820 struct uart_8250_dma *dma = p->dma;
764821 struct tty_port *tty_port = &p->port.state->port;
822
+ struct omap8250_priv *priv = p->port.private_data;
823
+ struct dma_chan *rxchan = dma->rxchan;
824
+ dma_cookie_t cookie;
765825 struct dma_tx_state state;
766826 int count;
767
- unsigned long flags;
768827 int ret;
769
-
770
- spin_lock_irqsave(&priv->rx_dma_lock, flags);
828
+ u32 reg;
771829
772830 if (!dma->rx_running)
773
- goto unlock;
831
+ goto out;
774832
833
+ cookie = dma->rx_cookie;
775834 dma->rx_running = 0;
776
- dmaengine_tx_status(dma->rxchan, dma->rx_cookie, &state);
777835
778
- count = dma->rx_size - state.residue;
779
- if (count < dma->rx_size)
780
- dmaengine_terminate_async(dma->rxchan);
836
+ /* Re-enable RX FIFO interrupt now that transfer is complete */
837
+ if (priv->habit & UART_HAS_RHR_IT_DIS) {
838
+ reg = serial_in(p, UART_OMAP_IER2);
839
+ reg &= ~UART_OMAP_IER2_RHR_IT_DIS;
840
+ serial_out(p, UART_OMAP_IER2, UART_OMAP_IER2_RHR_IT_DIS);
841
+ }
842
+
843
+ dmaengine_tx_status(rxchan, cookie, &state);
844
+
845
+ count = dma->rx_size - state.residue + state.in_flight_bytes;
846
+ if (count < dma->rx_size) {
847
+ dmaengine_terminate_async(rxchan);
848
+
849
+ /*
850
+ * Poll for teardown to complete which guarantees in
851
+ * flight data is drained.
852
+ */
853
+ if (state.in_flight_bytes) {
854
+ int poll_count = 25;
855
+
856
+ while (dmaengine_tx_status(rxchan, cookie, NULL) &&
857
+ poll_count--)
858
+ cpu_relax();
859
+
860
+ if (poll_count == -1)
861
+ dev_err(p->port.dev, "teardown incomplete\n");
862
+ }
863
+ }
781864 if (!count)
782
- goto unlock;
865
+ goto out;
783866 ret = tty_insert_flip_string(tty_port, dma->rx_buf, count);
784867
785868 p->port.icount.rx += ret;
786869 p->port.icount.buf_overrun += count - ret;
787
-unlock:
788
- spin_unlock_irqrestore(&priv->rx_dma_lock, flags);
870
+out:
789871
790872 tty_flip_buffer_push(tty_port);
791873 }
....@@ -811,8 +893,12 @@
811893 return;
812894 }
813895 __dma_rx_do_complete(p);
814
- if (!priv->throttled)
815
- omap_8250_rx_dma(p);
896
+ if (!priv->throttled) {
897
+ p->ier |= UART_IER_RLSI | UART_IER_RDI;
898
+ serial_out(p, UART_IER, p->ier);
899
+ if (!(priv->habit & UART_HAS_EFR2))
900
+ omap_8250_rx_dma(p);
901
+ }
816902
817903 spin_unlock_irqrestore(&p->port.lock, flags);
818904 }
....@@ -838,9 +924,8 @@
838924 if (WARN_ON_ONCE(ret))
839925 priv->rx_dma_broken = true;
840926 }
841
- spin_unlock_irqrestore(&priv->rx_dma_lock, flags);
842
-
843927 __dma_rx_do_complete(p);
928
+ spin_unlock_irqrestore(&priv->rx_dma_lock, flags);
844929 }
845930
846931 static int omap_8250_rx_dma(struct uart_8250_port *p)
....@@ -850,14 +935,27 @@
850935 int err = 0;
851936 struct dma_async_tx_descriptor *desc;
852937 unsigned long flags;
938
+ u32 reg;
853939
854940 if (priv->rx_dma_broken)
855941 return -EINVAL;
856942
857943 spin_lock_irqsave(&priv->rx_dma_lock, flags);
858944
859
- if (dma->rx_running)
945
+ if (dma->rx_running) {
946
+ enum dma_status state;
947
+
948
+ state = dmaengine_tx_status(dma->rxchan, dma->rx_cookie, NULL);
949
+ if (state == DMA_COMPLETE) {
950
+ /*
951
+ * Disable RX interrupts to allow RX DMA completion
952
+ * callback to run.
953
+ */
954
+ p->ier &= ~(UART_IER_RLSI | UART_IER_RDI);
955
+ serial_out(p, UART_IER, p->ier);
956
+ }
860957 goto out;
958
+ }
861959
862960 desc = dmaengine_prep_slave_single(dma->rxchan, dma->rx_addr,
863961 dma->rx_size, DMA_DEV_TO_MEM,
....@@ -872,6 +970,17 @@
872970 desc->callback_param = p;
873971
874972 dma->rx_cookie = dmaengine_submit(desc);
973
+
974
+ /*
975
+ * Disable RX FIFO interrupt while RX DMA is enabled, else
976
+ * spurious interrupt may be raised when data is in the RX FIFO
977
+ * but is yet to be drained by DMA.
978
+ */
979
+ if (priv->habit & UART_HAS_RHR_IT_DIS) {
980
+ reg = serial_in(p, UART_OMAP_IER2);
981
+ reg |= UART_OMAP_IER2_RHR_IT_DIS;
982
+ serial_out(p, UART_OMAP_IER2, UART_OMAP_IER2_RHR_IT_DIS);
983
+ }
875984
876985 dma_async_issue_pending(dma->rxchan);
877986 out:
....@@ -915,15 +1024,13 @@
9151024 ret = omap_8250_tx_dma(p);
9161025 if (ret)
9171026 en_thri = true;
918
-
9191027 } else if (p->capabilities & UART_CAP_RPM) {
9201028 en_thri = true;
9211029 }
9221030
9231031 if (en_thri) {
9241032 dma->tx_err = 1;
925
- p->ier |= UART_IER_THRI;
926
- serial_port_out(&p->port, UART_IER, p->ier);
1033
+ serial8250_set_THRI(p);
9271034 }
9281035
9291036 spin_unlock_irqrestore(&p->port.lock, flags);
....@@ -951,10 +1058,7 @@
9511058 ret = -EBUSY;
9521059 goto err;
9531060 }
954
- if (p->ier & UART_IER_THRI) {
955
- p->ier &= ~UART_IER_THRI;
956
- serial_out(p, UART_IER, p->ier);
957
- }
1061
+ serial8250_clear_THRI(p);
9581062 return 0;
9591063 }
9601064
....@@ -1012,10 +1116,7 @@
10121116 if (dma->tx_err)
10131117 dma->tx_err = 0;
10141118
1015
- if (p->ier & UART_IER_THRI) {
1016
- p->ier &= ~UART_IER_THRI;
1017
- serial_out(p, UART_IER, p->ier);
1018
- }
1119
+ serial8250_clear_THRI(p);
10191120 if (skip_byte)
10201121 serial_out(p, UART_TX, xmit->buf[xmit->tail]);
10211122 return 0;
....@@ -1036,6 +1137,46 @@
10361137 return omap_8250_rx_dma(up);
10371138 }
10381139
1140
+static unsigned char omap_8250_handle_rx_dma(struct uart_8250_port *up,
1141
+ u8 iir, unsigned char status)
1142
+{
1143
+ if ((status & (UART_LSR_DR | UART_LSR_BI)) &&
1144
+ (iir & UART_IIR_RDI)) {
1145
+ if (handle_rx_dma(up, iir)) {
1146
+ status = serial8250_rx_chars(up, status);
1147
+ omap_8250_rx_dma(up);
1148
+ }
1149
+ }
1150
+
1151
+ return status;
1152
+}
1153
+
1154
+static void am654_8250_handle_rx_dma(struct uart_8250_port *up, u8 iir,
1155
+ unsigned char status)
1156
+{
1157
+ /*
1158
+ * Queue a new transfer if FIFO has data.
1159
+ */
1160
+ if ((status & (UART_LSR_DR | UART_LSR_BI)) &&
1161
+ (up->ier & UART_IER_RDI)) {
1162
+ omap_8250_rx_dma(up);
1163
+ serial_out(up, UART_OMAP_EFR2, UART_OMAP_EFR2_TIMEOUT_BEHAVE);
1164
+ } else if ((iir & 0x3f) == UART_IIR_RX_TIMEOUT) {
1165
+ /*
1166
+ * Disable RX timeout, read IIR to clear
1167
+ * current timeout condition, clear EFR2 to
1168
+ * periodic timeouts, re-enable interrupts.
1169
+ */
1170
+ up->ier &= ~(UART_IER_RLSI | UART_IER_RDI);
1171
+ serial_out(up, UART_IER, up->ier);
1172
+ omap_8250_rx_dma_flush(up);
1173
+ serial_in(up, UART_IIR);
1174
+ serial_out(up, UART_OMAP_EFR2, 0x0);
1175
+ up->ier |= UART_IER_RLSI | UART_IER_RDI;
1176
+ serial_out(up, UART_IER, up->ier);
1177
+ }
1178
+}
1179
+
10391180 /*
10401181 * This is mostly serial8250_handle_irq(). We have a slightly different DMA
10411182 * hoook for RX/TX and need different logic for them in the ISR. Therefore we
....@@ -1044,6 +1185,7 @@
10441185 static int omap_8250_dma_handle_irq(struct uart_port *port)
10451186 {
10461187 struct uart_8250_port *up = up_to_u8250p(port);
1188
+ struct omap8250_priv *priv = up->port.private_data;
10471189 unsigned char status;
10481190 unsigned long flags;
10491191 u8 iir;
....@@ -1053,19 +1195,18 @@
10531195 iir = serial_port_in(port, UART_IIR);
10541196 if (iir & UART_IIR_NO_INT) {
10551197 serial8250_rpm_put(up);
1056
- return 0;
1198
+ return IRQ_HANDLED;
10571199 }
10581200
10591201 spin_lock_irqsave(&port->lock, flags);
10601202
10611203 status = serial_port_in(port, UART_LSR);
10621204
1063
- if (status & (UART_LSR_DR | UART_LSR_BI)) {
1064
- if (handle_rx_dma(up, iir)) {
1065
- status = serial8250_rx_chars(up, status);
1066
- omap_8250_rx_dma(up);
1067
- }
1068
- }
1205
+ if (priv->habit & UART_HAS_EFR2)
1206
+ am654_8250_handle_rx_dma(up, iir, status);
1207
+ else
1208
+ status = omap_8250_handle_rx_dma(up, iir, status);
1209
+
10691210 serial8250_modem_status(up);
10701211 if (status & UART_LSR_THRE && up->dma->tx_err) {
10711212 if (uart_tx_stopped(&up->port) ||
....@@ -1082,7 +1223,7 @@
10821223 }
10831224 }
10841225
1085
- spin_unlock_irqrestore(&port->lock, flags);
1226
+ uart_unlock_and_check_sysrq(port, flags);
10861227 serial8250_rpm_put(up);
10871228 return 1;
10881229 }
....@@ -1107,33 +1248,63 @@
11071248 return 0;
11081249 }
11091250
1110
-static const u8 omap4_habit = UART_ERRATA_CLOCK_DISABLE;
1111
-static const u8 am3352_habit = OMAP_DMA_TX_KICK | UART_ERRATA_CLOCK_DISABLE;
1112
-static const u8 dra742_habit = UART_ERRATA_CLOCK_DISABLE;
1251
+static struct omap8250_dma_params am654_dma = {
1252
+ .rx_size = SZ_2K,
1253
+ .rx_trigger = 1,
1254
+ .tx_trigger = TX_TRIGGER,
1255
+};
1256
+
1257
+static struct omap8250_dma_params am33xx_dma = {
1258
+ .rx_size = RX_TRIGGER,
1259
+ .rx_trigger = RX_TRIGGER,
1260
+ .tx_trigger = TX_TRIGGER,
1261
+};
1262
+
1263
+static struct omap8250_platdata am654_platdata = {
1264
+ .dma_params = &am654_dma,
1265
+ .habit = UART_HAS_EFR2 | UART_HAS_RHR_IT_DIS |
1266
+ UART_RX_TIMEOUT_QUIRK,
1267
+};
1268
+
1269
+static struct omap8250_platdata am33xx_platdata = {
1270
+ .dma_params = &am33xx_dma,
1271
+ .habit = OMAP_DMA_TX_KICK | UART_ERRATA_CLOCK_DISABLE,
1272
+};
1273
+
1274
+static struct omap8250_platdata omap4_platdata = {
1275
+ .dma_params = &am33xx_dma,
1276
+ .habit = UART_ERRATA_CLOCK_DISABLE,
1277
+};
11131278
11141279 static const struct of_device_id omap8250_dt_ids[] = {
1115
- { .compatible = "ti,am654-uart" },
1280
+ { .compatible = "ti,am654-uart", .data = &am654_platdata, },
11161281 { .compatible = "ti,omap2-uart" },
11171282 { .compatible = "ti,omap3-uart" },
1118
- { .compatible = "ti,omap4-uart", .data = &omap4_habit, },
1119
- { .compatible = "ti,am3352-uart", .data = &am3352_habit, },
1120
- { .compatible = "ti,am4372-uart", .data = &am3352_habit, },
1121
- { .compatible = "ti,dra742-uart", .data = &dra742_habit, },
1283
+ { .compatible = "ti,omap4-uart", .data = &omap4_platdata, },
1284
+ { .compatible = "ti,am3352-uart", .data = &am33xx_platdata, },
1285
+ { .compatible = "ti,am4372-uart", .data = &am33xx_platdata, },
1286
+ { .compatible = "ti,dra742-uart", .data = &omap4_platdata, },
11221287 {},
11231288 };
11241289 MODULE_DEVICE_TABLE(of, omap8250_dt_ids);
11251290
11261291 static int omap8250_probe(struct platform_device *pdev)
11271292 {
1128
- struct resource *regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1129
- struct resource *irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1293
+ struct device_node *np = pdev->dev.of_node;
11301294 struct omap8250_priv *priv;
1295
+ const struct omap8250_platdata *pdata;
11311296 struct uart_8250_port up;
1132
- int ret;
1297
+ struct resource *regs;
11331298 void __iomem *membase;
1299
+ int irq, ret;
11341300
1135
- if (!regs || !irq) {
1136
- dev_err(&pdev->dev, "missing registers or irq\n");
1301
+ irq = platform_get_irq(pdev, 0);
1302
+ if (irq < 0)
1303
+ return irq;
1304
+
1305
+ regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1306
+ if (!regs) {
1307
+ dev_err(&pdev->dev, "missing registers\n");
11371308 return -EINVAL;
11381309 }
11391310
....@@ -1141,7 +1312,7 @@
11411312 if (!priv)
11421313 return -ENOMEM;
11431314
1144
- membase = devm_ioremap_nocache(&pdev->dev, regs->start,
1315
+ membase = devm_ioremap(&pdev->dev, regs->start,
11451316 resource_size(regs));
11461317 if (!membase)
11471318 return -ENODEV;
....@@ -1150,7 +1321,7 @@
11501321 up.port.dev = &pdev->dev;
11511322 up.port.mapbase = regs->start;
11521323 up.port.membase = membase;
1153
- up.port.irq = irq->start;
1324
+ up.port.irq = irq;
11541325 /*
11551326 * It claims to be 16C750 compatible however it is a little different.
11561327 * It has EFR and has no FCR7_64byte bit. The AFE (which it claims to
....@@ -1185,28 +1356,39 @@
11851356 up.port.shutdown = omap_8250_shutdown;
11861357 up.port.throttle = omap_8250_throttle;
11871358 up.port.unthrottle = omap_8250_unthrottle;
1188
- up.port.rs485_config = omap_8250_rs485_config;
1359
+ up.port.rs485_config = serial8250_em485_config;
1360
+ up.rs485_start_tx = serial8250_em485_start_tx;
1361
+ up.rs485_stop_tx = serial8250_em485_stop_tx;
1362
+ up.port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_8250_CONSOLE);
11891363
1190
- if (pdev->dev.of_node) {
1191
- const struct of_device_id *id;
1192
-
1193
- ret = of_alias_get_id(pdev->dev.of_node, "serial");
1194
-
1195
- of_property_read_u32(pdev->dev.of_node, "clock-frequency",
1196
- &up.port.uartclk);
1197
- priv->wakeirq = irq_of_parse_and_map(pdev->dev.of_node, 1);
1198
-
1199
- id = of_match_device(of_match_ptr(omap8250_dt_ids), &pdev->dev);
1200
- if (id && id->data)
1201
- priv->habit |= *(u8 *)id->data;
1202
- } else {
1203
- ret = pdev->id;
1204
- }
1364
+ ret = of_alias_get_id(np, "serial");
12051365 if (ret < 0) {
1206
- dev_err(&pdev->dev, "failed to get alias/pdev id\n");
1366
+ dev_err(&pdev->dev, "failed to get alias\n");
12071367 return ret;
12081368 }
12091369 up.port.line = ret;
1370
+
1371
+ if (of_property_read_u32(np, "clock-frequency", &up.port.uartclk)) {
1372
+ struct clk *clk;
1373
+
1374
+ clk = devm_clk_get(&pdev->dev, NULL);
1375
+ if (IS_ERR(clk)) {
1376
+ if (PTR_ERR(clk) == -EPROBE_DEFER)
1377
+ return -EPROBE_DEFER;
1378
+ } else {
1379
+ up.port.uartclk = clk_get_rate(clk);
1380
+ }
1381
+ }
1382
+
1383
+ if (of_property_read_u32(np, "overrun-throttle-ms",
1384
+ &up.overrun_backoff_time_ms) != 0)
1385
+ up.overrun_backoff_time_ms = 0;
1386
+
1387
+ priv->wakeirq = irq_of_parse_and_map(np, 1);
1388
+
1389
+ pdata = of_device_get_match_data(&pdev->dev);
1390
+ if (pdata)
1391
+ priv->habit |= pdata->habit;
12101392
12111393 if (!up.port.uartclk) {
12121394 up.port.uartclk = DEFAULT_CLK_SPEED;
....@@ -1215,10 +1397,9 @@
12151397 DEFAULT_CLK_SPEED);
12161398 }
12171399
1218
- priv->latency = PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE;
1219
- priv->calc_latency = PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE;
1220
- pm_qos_add_request(&priv->pm_qos_request, PM_QOS_CPU_DMA_LATENCY,
1221
- priv->latency);
1400
+ priv->latency = PM_QOS_CPU_LATENCY_DEFAULT_VALUE;
1401
+ priv->calc_latency = PM_QOS_CPU_LATENCY_DEFAULT_VALUE;
1402
+ cpu_latency_qos_add_request(&priv->pm_qos_request, priv->latency);
12221403 INIT_WORK(&priv->qos_work, omap8250_uart_qos_work);
12231404
12241405 spin_lock_init(&priv->rx_dma_lock);
....@@ -1226,7 +1407,16 @@
12261407 device_init_wakeup(&pdev->dev, true);
12271408 pm_runtime_enable(&pdev->dev);
12281409 pm_runtime_use_autosuspend(&pdev->dev);
1229
- pm_runtime_set_autosuspend_delay(&pdev->dev, -1);
1410
+
1411
+ /*
1412
+ * Disable runtime PM until autosuspend delay unless specifically
1413
+ * enabled by the user via sysfs. This is the historic way to
1414
+ * prevent an unsafe default policy with lossy characters on wake-up.
1415
+ * For serdev devices this is not needed, the policy can be managed by
1416
+ * the serdev driver.
1417
+ */
1418
+ if (!of_get_available_child_count(pdev->dev.of_node))
1419
+ pm_runtime_set_autosuspend_delay(&pdev->dev, -1);
12301420
12311421 pm_runtime_irq_safe(&pdev->dev);
12321422
....@@ -1234,25 +1424,38 @@
12341424
12351425 omap_serial_fill_features_erratas(&up, priv);
12361426 up.port.handle_irq = omap8250_no_handle_irq;
1427
+ priv->rx_trigger = RX_TRIGGER;
1428
+ priv->tx_trigger = TX_TRIGGER;
12371429 #ifdef CONFIG_SERIAL_8250_DMA
1238
- if (pdev->dev.of_node) {
1239
- /*
1240
- * Oh DMA support. If there are no DMA properties in the DT then
1241
- * we will fall back to a generic DMA channel which does not
1242
- * really work here. To ensure that we do not get a generic DMA
1243
- * channel assigned, we have the the_no_dma_filter_fn() here.
1244
- * To avoid "failed to request DMA" messages we check for DMA
1245
- * properties in DT.
1246
- */
1247
- ret = of_property_count_strings(pdev->dev.of_node, "dma-names");
1248
- if (ret == 2) {
1249
- up.dma = &priv->omap8250_dma;
1250
- priv->omap8250_dma.fn = the_no_dma_filter_fn;
1251
- priv->omap8250_dma.tx_dma = omap_8250_tx_dma;
1252
- priv->omap8250_dma.rx_dma = omap_8250_rx_dma;
1253
- priv->omap8250_dma.rx_size = RX_TRIGGER;
1254
- priv->omap8250_dma.rxconf.src_maxburst = RX_TRIGGER;
1255
- priv->omap8250_dma.txconf.dst_maxburst = TX_TRIGGER;
1430
+ /*
1431
+ * Oh DMA support. If there are no DMA properties in the DT then
1432
+ * we will fall back to a generic DMA channel which does not
1433
+ * really work here. To ensure that we do not get a generic DMA
1434
+ * channel assigned, we have the the_no_dma_filter_fn() here.
1435
+ * To avoid "failed to request DMA" messages we check for DMA
1436
+ * properties in DT.
1437
+ */
1438
+ ret = of_property_count_strings(np, "dma-names");
1439
+ if (ret == 2) {
1440
+ struct omap8250_dma_params *dma_params = NULL;
1441
+
1442
+ up.dma = &priv->omap8250_dma;
1443
+ up.dma->fn = the_no_dma_filter_fn;
1444
+ up.dma->tx_dma = omap_8250_tx_dma;
1445
+ up.dma->rx_dma = omap_8250_rx_dma;
1446
+ if (pdata)
1447
+ dma_params = pdata->dma_params;
1448
+
1449
+ if (dma_params) {
1450
+ up.dma->rx_size = dma_params->rx_size;
1451
+ up.dma->rxconf.src_maxburst = dma_params->rx_trigger;
1452
+ up.dma->txconf.dst_maxburst = dma_params->tx_trigger;
1453
+ priv->rx_trigger = dma_params->rx_trigger;
1454
+ priv->tx_trigger = dma_params->tx_trigger;
1455
+ } else {
1456
+ up.dma->rx_size = RX_TRIGGER;
1457
+ up.dma->rxconf.src_maxburst = RX_TRIGGER;
1458
+ up.dma->txconf.dst_maxburst = TX_TRIGGER;
12561459 }
12571460 }
12581461 #endif
....@@ -1269,19 +1472,27 @@
12691472 err:
12701473 pm_runtime_dont_use_autosuspend(&pdev->dev);
12711474 pm_runtime_put_sync(&pdev->dev);
1475
+ flush_work(&priv->qos_work);
12721476 pm_runtime_disable(&pdev->dev);
1477
+ cpu_latency_qos_remove_request(&priv->pm_qos_request);
12731478 return ret;
12741479 }
12751480
12761481 static int omap8250_remove(struct platform_device *pdev)
12771482 {
12781483 struct omap8250_priv *priv = platform_get_drvdata(pdev);
1484
+ int err;
1485
+
1486
+ err = pm_runtime_resume_and_get(&pdev->dev);
1487
+ if (err)
1488
+ return err;
12791489
12801490 pm_runtime_dont_use_autosuspend(&pdev->dev);
12811491 pm_runtime_put_sync(&pdev->dev);
1492
+ flush_work(&priv->qos_work);
12821493 pm_runtime_disable(&pdev->dev);
12831494 serial8250_unregister_port(priv->line);
1284
- pm_qos_remove_request(&priv->pm_qos_request);
1495
+ cpu_latency_qos_remove_request(&priv->pm_qos_request);
12851496 device_init_wakeup(&pdev->dev, false);
12861497 return 0;
12871498 }
....@@ -1310,25 +1521,35 @@
13101521 {
13111522 struct omap8250_priv *priv = dev_get_drvdata(dev);
13121523 struct uart_8250_port *up = serial8250_get_port(priv->line);
1524
+ int err;
13131525
13141526 serial8250_suspend_port(priv->line);
13151527
1316
- pm_runtime_get_sync(dev);
1528
+ err = pm_runtime_resume_and_get(dev);
1529
+ if (err)
1530
+ return err;
13171531 if (!device_may_wakeup(dev))
13181532 priv->wer = 0;
13191533 serial_out(up, UART_OMAP_WER, priv->wer);
1320
- pm_runtime_mark_last_busy(dev);
1321
- pm_runtime_put_autosuspend(dev);
1322
-
1534
+ err = pm_runtime_force_suspend(dev);
13231535 flush_work(&priv->qos_work);
1324
- return 0;
1536
+
1537
+ return err;
13251538 }
13261539
13271540 static int omap8250_resume(struct device *dev)
13281541 {
13291542 struct omap8250_priv *priv = dev_get_drvdata(dev);
1543
+ int err;
13301544
1545
+ err = pm_runtime_force_resume(dev);
1546
+ if (err)
1547
+ return err;
13311548 serial8250_resume_port(priv->line);
1549
+ /* Paired with pm_runtime_resume_and_get() in omap8250_suspend() */
1550
+ pm_runtime_mark_last_busy(dev);
1551
+ pm_runtime_put_autosuspend(dev);
1552
+
13321553 return 0;
13331554 }
13341555 #else
....@@ -1431,7 +1652,7 @@
14311652 if (up->dma && up->dma->rxchan)
14321653 omap_8250_rx_dma_flush(up);
14331654
1434
- priv->latency = PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE;
1655
+ priv->latency = PM_QOS_CPU_LATENCY_DEFAULT_VALUE;
14351656 schedule_work(&priv->qos_work);
14361657
14371658 return 0;
....@@ -1451,7 +1672,7 @@
14511672 if (omap8250_lost_context(up))
14521673 omap8250_restore_regs(up);
14531674
1454
- if (up->dma && up->dma->rxchan)
1675
+ if (up->dma && up->dma->rxchan && !(priv->habit & UART_HAS_EFR2))
14551676 omap_8250_rx_dma(up);
14561677
14571678 priv->latency = priv->calc_latency;