Lines Matching +full:up +full:-
1 // SPDX-License-Identifier: GPL-2.0+
3 * Driver for OMAP-UART controller.
16 * this driver as required for the omap-platform.
37 #include <linux/platform_data/serial-omap.h>
78 #define OMAP_UART_DMA_CH_FREE -1
169 static void serial_omap_mdr1_errataset(struct uart_omap_port *up, u8 mdr1);
171 static inline unsigned int serial_in(struct uart_omap_port *up, int offset) in serial_in() argument
173 offset <<= up->port.regshift; in serial_in()
174 return readw(up->port.membase + offset); in serial_in()
177 static inline void serial_out(struct uart_omap_port *up, int offset, int value) in serial_out() argument
179 offset <<= up->port.regshift; in serial_out()
180 writew(value, up->port.membase + offset); in serial_out()
183 static inline void serial_omap_clear_fifos(struct uart_omap_port *up) in serial_omap_clear_fifos() argument
185 serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO); in serial_omap_clear_fifos()
186 serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO | in serial_omap_clear_fifos()
188 serial_out(up, UART_FCR, 0); in serial_omap_clear_fifos()
192 static int serial_omap_get_context_loss_count(struct uart_omap_port *up) in serial_omap_get_context_loss_count() argument
194 struct omap_uart_port_info *pdata = dev_get_platdata(up->dev); in serial_omap_get_context_loss_count()
196 if (!pdata || !pdata->get_context_loss_count) in serial_omap_get_context_loss_count()
197 return -EINVAL; in serial_omap_get_context_loss_count()
199 return pdata->get_context_loss_count(up->dev); in serial_omap_get_context_loss_count()
203 static void serial_omap_enable_wakeup(struct uart_omap_port *up, bool enable) in serial_omap_enable_wakeup() argument
205 struct omap_uart_port_info *pdata = dev_get_platdata(up->dev); in serial_omap_enable_wakeup()
207 if (!pdata || !pdata->enable_wakeup) in serial_omap_enable_wakeup()
210 pdata->enable_wakeup(up->dev, enable); in serial_omap_enable_wakeup()
221 unsigned int n = port->uartclk / (mode * baud); in calculate_baud_abs_diff()
227 abs_diff = baud - (port->uartclk / (mode * n)); in calculate_baud_abs_diff()
229 abs_diff = -abs_diff; in calculate_baud_abs_diff()
235 * serial_omap_baud_is_mode16 - check if baud rate is MODE16X
255 * serial_omap_get_divisor - calculate divisor value
268 return port->uartclk/(mode * baud); in serial_omap_get_divisor()
273 struct uart_omap_port *up = to_uart_omap_port(port); in serial_omap_enable_ms() local
275 dev_dbg(up->port.dev, "serial_omap_enable_ms+%d\n", up->port.line); in serial_omap_enable_ms()
277 pm_runtime_get_sync(up->dev); in serial_omap_enable_ms()
278 up->ier |= UART_IER_MSI; in serial_omap_enable_ms()
279 serial_out(up, UART_IER, up->ier); in serial_omap_enable_ms()
280 pm_runtime_mark_last_busy(up->dev); in serial_omap_enable_ms()
281 pm_runtime_put_autosuspend(up->dev); in serial_omap_enable_ms()
286 struct uart_omap_port *up = to_uart_omap_port(port); in serial_omap_stop_tx() local
289 pm_runtime_get_sync(up->dev); in serial_omap_stop_tx()
291 /* Handle RS-485 */ in serial_omap_stop_tx()
292 if (port->rs485.flags & SER_RS485_ENABLED) { in serial_omap_stop_tx()
293 if (up->scr & OMAP_UART_SCR_TX_EMPTY) { in serial_omap_stop_tx()
298 * disable THR interrupts and toggle the RS-485 GPIO in serial_omap_stop_tx()
301 up->scr &= ~OMAP_UART_SCR_TX_EMPTY; in serial_omap_stop_tx()
302 serial_out(up, UART_OMAP_SCR, up->scr); in serial_omap_stop_tx()
303 res = (port->rs485.flags & SER_RS485_RTS_AFTER_SEND) ? in serial_omap_stop_tx()
305 if (gpiod_get_value(up->rts_gpiod) != res) { in serial_omap_stop_tx()
306 if (port->rs485.delay_rts_after_send > 0) in serial_omap_stop_tx()
308 port->rs485.delay_rts_after_send); in serial_omap_stop_tx()
309 gpiod_set_value(up->rts_gpiod, res); in serial_omap_stop_tx()
320 up->scr |= OMAP_UART_SCR_TX_EMPTY; in serial_omap_stop_tx()
321 serial_out(up, UART_OMAP_SCR, up->scr); in serial_omap_stop_tx()
326 if (up->ier & UART_IER_THRI) { in serial_omap_stop_tx()
327 up->ier &= ~UART_IER_THRI; in serial_omap_stop_tx()
328 serial_out(up, UART_IER, up->ier); in serial_omap_stop_tx()
331 if ((port->rs485.flags & SER_RS485_ENABLED) && in serial_omap_stop_tx()
332 !(port->rs485.flags & SER_RS485_RX_DURING_TX)) { in serial_omap_stop_tx()
335 * received during the half-duplex transmission. in serial_omap_stop_tx()
337 serial_out(up, UART_FCR, up->fcr | UART_FCR_CLEAR_RCVR); in serial_omap_stop_tx()
338 /* Re-enable RX interrupts */ in serial_omap_stop_tx()
339 up->ier |= UART_IER_RLSI | UART_IER_RDI; in serial_omap_stop_tx()
340 up->port.read_status_mask |= UART_LSR_DR; in serial_omap_stop_tx()
341 serial_out(up, UART_IER, up->ier); in serial_omap_stop_tx()
344 pm_runtime_mark_last_busy(up->dev); in serial_omap_stop_tx()
345 pm_runtime_put_autosuspend(up->dev); in serial_omap_stop_tx()
350 struct uart_omap_port *up = to_uart_omap_port(port); in serial_omap_stop_rx() local
352 pm_runtime_get_sync(up->dev); in serial_omap_stop_rx()
353 up->ier &= ~(UART_IER_RLSI | UART_IER_RDI); in serial_omap_stop_rx()
354 up->port.read_status_mask &= ~UART_LSR_DR; in serial_omap_stop_rx()
355 serial_out(up, UART_IER, up->ier); in serial_omap_stop_rx()
356 pm_runtime_mark_last_busy(up->dev); in serial_omap_stop_rx()
357 pm_runtime_put_autosuspend(up->dev); in serial_omap_stop_rx()
360 static void transmit_chars(struct uart_omap_port *up, unsigned int lsr) in transmit_chars() argument
362 struct circ_buf *xmit = &up->port.state->xmit; in transmit_chars()
365 if (up->port.x_char) { in transmit_chars()
366 serial_out(up, UART_TX, up->port.x_char); in transmit_chars()
367 up->port.icount.tx++; in transmit_chars()
368 up->port.x_char = 0; in transmit_chars()
371 if (uart_circ_empty(xmit) || uart_tx_stopped(&up->port)) { in transmit_chars()
372 serial_omap_stop_tx(&up->port); in transmit_chars()
375 count = up->port.fifosize / 4; in transmit_chars()
377 serial_out(up, UART_TX, xmit->buf[xmit->tail]); in transmit_chars()
378 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); in transmit_chars()
379 up->port.icount.tx++; in transmit_chars()
382 } while (--count > 0); in transmit_chars()
385 uart_write_wakeup(&up->port); in transmit_chars()
388 serial_omap_stop_tx(&up->port); in transmit_chars()
391 static inline void serial_omap_enable_ier_thri(struct uart_omap_port *up) in serial_omap_enable_ier_thri() argument
393 if (!(up->ier & UART_IER_THRI)) { in serial_omap_enable_ier_thri()
394 up->ier |= UART_IER_THRI; in serial_omap_enable_ier_thri()
395 serial_out(up, UART_IER, up->ier); in serial_omap_enable_ier_thri()
401 struct uart_omap_port *up = to_uart_omap_port(port); in serial_omap_start_tx() local
404 pm_runtime_get_sync(up->dev); in serial_omap_start_tx()
406 /* Handle RS-485 */ in serial_omap_start_tx()
407 if (port->rs485.flags & SER_RS485_ENABLED) { in serial_omap_start_tx()
409 up->scr &= ~OMAP_UART_SCR_TX_EMPTY; in serial_omap_start_tx()
410 serial_out(up, UART_OMAP_SCR, up->scr); in serial_omap_start_tx()
413 res = (port->rs485.flags & SER_RS485_RTS_ON_SEND) ? 1 : 0; in serial_omap_start_tx()
414 if (gpiod_get_value(up->rts_gpiod) != res) { in serial_omap_start_tx()
415 gpiod_set_value(up->rts_gpiod, res); in serial_omap_start_tx()
416 if (port->rs485.delay_rts_before_send > 0) in serial_omap_start_tx()
417 mdelay(port->rs485.delay_rts_before_send); in serial_omap_start_tx()
421 if ((port->rs485.flags & SER_RS485_ENABLED) && in serial_omap_start_tx()
422 !(port->rs485.flags & SER_RS485_RX_DURING_TX)) in serial_omap_start_tx()
425 serial_omap_enable_ier_thri(up); in serial_omap_start_tx()
426 pm_runtime_mark_last_busy(up->dev); in serial_omap_start_tx()
427 pm_runtime_put_autosuspend(up->dev); in serial_omap_start_tx()
432 struct uart_omap_port *up = to_uart_omap_port(port); in serial_omap_throttle() local
435 pm_runtime_get_sync(up->dev); in serial_omap_throttle()
436 spin_lock_irqsave(&up->port.lock, flags); in serial_omap_throttle()
437 up->ier &= ~(UART_IER_RLSI | UART_IER_RDI); in serial_omap_throttle()
438 serial_out(up, UART_IER, up->ier); in serial_omap_throttle()
439 spin_unlock_irqrestore(&up->port.lock, flags); in serial_omap_throttle()
440 pm_runtime_mark_last_busy(up->dev); in serial_omap_throttle()
441 pm_runtime_put_autosuspend(up->dev); in serial_omap_throttle()
446 struct uart_omap_port *up = to_uart_omap_port(port); in serial_omap_unthrottle() local
449 pm_runtime_get_sync(up->dev); in serial_omap_unthrottle()
450 spin_lock_irqsave(&up->port.lock, flags); in serial_omap_unthrottle()
451 up->ier |= UART_IER_RLSI | UART_IER_RDI; in serial_omap_unthrottle()
452 serial_out(up, UART_IER, up->ier); in serial_omap_unthrottle()
453 spin_unlock_irqrestore(&up->port.lock, flags); in serial_omap_unthrottle()
454 pm_runtime_mark_last_busy(up->dev); in serial_omap_unthrottle()
455 pm_runtime_put_autosuspend(up->dev); in serial_omap_unthrottle()
458 static unsigned int check_modem_status(struct uart_omap_port *up) in check_modem_status() argument
462 status = serial_in(up, UART_MSR); in check_modem_status()
463 status |= up->msr_saved_flags; in check_modem_status()
464 up->msr_saved_flags = 0; in check_modem_status()
468 if (status & UART_MSR_ANY_DELTA && up->ier & UART_IER_MSI && in check_modem_status()
469 up->port.state != NULL) { in check_modem_status()
471 up->port.icount.rng++; in check_modem_status()
473 up->port.icount.dsr++; in check_modem_status()
476 (&up->port, status & UART_MSR_DCD); in check_modem_status()
479 (&up->port, status & UART_MSR_CTS); in check_modem_status()
480 wake_up_interruptible(&up->port.state->port.delta_msr_wait); in check_modem_status()
486 static void serial_omap_rlsi(struct uart_omap_port *up, unsigned int lsr) in serial_omap_rlsi() argument
492 * to the table 23-246 of the omap4 TRM. in serial_omap_rlsi()
495 serial_in(up, UART_RX); in serial_omap_rlsi()
497 up->port.icount.rx++; in serial_omap_rlsi()
503 up->port.icount.brk++; in serial_omap_rlsi()
510 if (uart_handle_break(&up->port)) in serial_omap_rlsi()
517 up->port.icount.parity++; in serial_omap_rlsi()
522 up->port.icount.frame++; in serial_omap_rlsi()
526 up->port.icount.overrun++; in serial_omap_rlsi()
529 if (up->port.line == up->port.cons->index) { in serial_omap_rlsi()
531 lsr |= up->lsr_break_flag; in serial_omap_rlsi()
534 uart_insert_char(&up->port, lsr, UART_LSR_OE, 0, flag); in serial_omap_rlsi()
537 static void serial_omap_rdi(struct uart_omap_port *up, unsigned int lsr) in serial_omap_rdi() argument
545 ch = serial_in(up, UART_RX); in serial_omap_rdi()
547 up->port.icount.rx++; in serial_omap_rdi()
549 if (uart_handle_sysrq_char(&up->port, ch)) in serial_omap_rdi()
552 uart_insert_char(&up->port, lsr, UART_LSR_OE, ch, flag); in serial_omap_rdi()
556 * serial_omap_irq() - This handles the interrupt from one port
562 struct uart_omap_port *up = dev_id; in serial_omap_irq() local
568 spin_lock(&up->port.lock); in serial_omap_irq()
569 pm_runtime_get_sync(up->dev); in serial_omap_irq()
572 iir = serial_in(up, UART_IIR); in serial_omap_irq()
577 lsr = serial_in(up, UART_LSR); in serial_omap_irq()
584 check_modem_status(up); in serial_omap_irq()
587 transmit_chars(up, lsr); in serial_omap_irq()
591 serial_omap_rdi(up, lsr); in serial_omap_irq()
594 serial_omap_rlsi(up, lsr); in serial_omap_irq()
603 } while (max_count--); in serial_omap_irq()
605 spin_unlock(&up->port.lock); in serial_omap_irq()
607 tty_flip_buffer_push(&up->port.state->port); in serial_omap_irq()
609 pm_runtime_mark_last_busy(up->dev); in serial_omap_irq()
610 pm_runtime_put_autosuspend(up->dev); in serial_omap_irq()
611 up->port_activity = jiffies; in serial_omap_irq()
618 struct uart_omap_port *up = to_uart_omap_port(port); in serial_omap_tx_empty() local
622 pm_runtime_get_sync(up->dev); in serial_omap_tx_empty()
623 dev_dbg(up->port.dev, "serial_omap_tx_empty+%d\n", up->port.line); in serial_omap_tx_empty()
624 spin_lock_irqsave(&up->port.lock, flags); in serial_omap_tx_empty()
625 ret = serial_in(up, UART_LSR) & UART_LSR_TEMT ? TIOCSER_TEMT : 0; in serial_omap_tx_empty()
626 spin_unlock_irqrestore(&up->port.lock, flags); in serial_omap_tx_empty()
627 pm_runtime_mark_last_busy(up->dev); in serial_omap_tx_empty()
628 pm_runtime_put_autosuspend(up->dev); in serial_omap_tx_empty()
634 struct uart_omap_port *up = to_uart_omap_port(port); in serial_omap_get_mctrl() local
638 pm_runtime_get_sync(up->dev); in serial_omap_get_mctrl()
639 status = check_modem_status(up); in serial_omap_get_mctrl()
640 pm_runtime_mark_last_busy(up->dev); in serial_omap_get_mctrl()
641 pm_runtime_put_autosuspend(up->dev); in serial_omap_get_mctrl()
643 dev_dbg(up->port.dev, "serial_omap_get_mctrl+%d\n", up->port.line); in serial_omap_get_mctrl()
658 struct uart_omap_port *up = to_uart_omap_port(port); in serial_omap_set_mctrl() local
661 dev_dbg(up->port.dev, "serial_omap_set_mctrl+%d\n", up->port.line); in serial_omap_set_mctrl()
673 pm_runtime_get_sync(up->dev); in serial_omap_set_mctrl()
674 old_mcr = serial_in(up, UART_MCR); in serial_omap_set_mctrl()
677 up->mcr = old_mcr | mcr; in serial_omap_set_mctrl()
678 serial_out(up, UART_MCR, up->mcr); in serial_omap_set_mctrl()
681 lcr = serial_in(up, UART_LCR); in serial_omap_set_mctrl()
682 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); in serial_omap_set_mctrl()
683 if ((mctrl & TIOCM_RTS) && (port->status & UPSTAT_AUTORTS)) in serial_omap_set_mctrl()
684 up->efr |= UART_EFR_RTS; in serial_omap_set_mctrl()
686 up->efr &= ~UART_EFR_RTS; in serial_omap_set_mctrl()
687 serial_out(up, UART_EFR, up->efr); in serial_omap_set_mctrl()
688 serial_out(up, UART_LCR, lcr); in serial_omap_set_mctrl()
690 pm_runtime_mark_last_busy(up->dev); in serial_omap_set_mctrl()
691 pm_runtime_put_autosuspend(up->dev); in serial_omap_set_mctrl()
696 struct uart_omap_port *up = to_uart_omap_port(port); in serial_omap_break_ctl() local
699 dev_dbg(up->port.dev, "serial_omap_break_ctl+%d\n", up->port.line); in serial_omap_break_ctl()
700 pm_runtime_get_sync(up->dev); in serial_omap_break_ctl()
701 spin_lock_irqsave(&up->port.lock, flags); in serial_omap_break_ctl()
702 if (break_state == -1) in serial_omap_break_ctl()
703 up->lcr |= UART_LCR_SBC; in serial_omap_break_ctl()
705 up->lcr &= ~UART_LCR_SBC; in serial_omap_break_ctl()
706 serial_out(up, UART_LCR, up->lcr); in serial_omap_break_ctl()
707 spin_unlock_irqrestore(&up->port.lock, flags); in serial_omap_break_ctl()
708 pm_runtime_mark_last_busy(up->dev); in serial_omap_break_ctl()
709 pm_runtime_put_autosuspend(up->dev); in serial_omap_break_ctl()
714 struct uart_omap_port *up = to_uart_omap_port(port); in serial_omap_startup() local
721 retval = request_irq(up->port.irq, serial_omap_irq, up->port.irqflags, in serial_omap_startup()
722 up->name, up); in serial_omap_startup()
726 /* Optional wake-up IRQ */ in serial_omap_startup()
727 if (up->wakeirq) { in serial_omap_startup()
728 retval = dev_pm_set_dedicated_wake_irq(up->dev, up->wakeirq); in serial_omap_startup()
730 free_irq(up->port.irq, up); in serial_omap_startup()
735 dev_dbg(up->port.dev, "serial_omap_startup+%d\n", up->port.line); in serial_omap_startup()
737 pm_runtime_get_sync(up->dev); in serial_omap_startup()
742 serial_omap_clear_fifos(up); in serial_omap_startup()
747 (void) serial_in(up, UART_LSR); in serial_omap_startup()
748 if (serial_in(up, UART_LSR) & UART_LSR_DR) in serial_omap_startup()
749 (void) serial_in(up, UART_RX); in serial_omap_startup()
750 (void) serial_in(up, UART_IIR); in serial_omap_startup()
751 (void) serial_in(up, UART_MSR); in serial_omap_startup()
756 serial_out(up, UART_LCR, UART_LCR_WLEN8); in serial_omap_startup()
757 spin_lock_irqsave(&up->port.lock, flags); in serial_omap_startup()
761 up->port.mctrl |= TIOCM_OUT2; in serial_omap_startup()
762 serial_omap_set_mctrl(&up->port, up->port.mctrl); in serial_omap_startup()
763 spin_unlock_irqrestore(&up->port.lock, flags); in serial_omap_startup()
765 up->msr_saved_flags = 0; in serial_omap_startup()
771 up->ier = UART_IER_RLSI | UART_IER_RDI; in serial_omap_startup()
772 serial_out(up, UART_IER, up->ier); in serial_omap_startup()
774 /* Enable module level wake up */ in serial_omap_startup()
775 up->wer = OMAP_UART_WER_MOD_WKUP; in serial_omap_startup()
776 if (up->features & OMAP_UART_WER_HAS_TX_WAKEUP) in serial_omap_startup()
777 up->wer |= OMAP_UART_TX_WAKEUP_EN; in serial_omap_startup()
779 serial_out(up, UART_OMAP_WER, up->wer); in serial_omap_startup()
781 pm_runtime_mark_last_busy(up->dev); in serial_omap_startup()
782 pm_runtime_put_autosuspend(up->dev); in serial_omap_startup()
783 up->port_activity = jiffies; in serial_omap_startup()
789 struct uart_omap_port *up = to_uart_omap_port(port); in serial_omap_shutdown() local
792 dev_dbg(up->port.dev, "serial_omap_shutdown+%d\n", up->port.line); in serial_omap_shutdown()
794 pm_runtime_get_sync(up->dev); in serial_omap_shutdown()
798 up->ier = 0; in serial_omap_shutdown()
799 serial_out(up, UART_IER, 0); in serial_omap_shutdown()
801 spin_lock_irqsave(&up->port.lock, flags); in serial_omap_shutdown()
802 up->port.mctrl &= ~TIOCM_OUT2; in serial_omap_shutdown()
803 serial_omap_set_mctrl(&up->port, up->port.mctrl); in serial_omap_shutdown()
804 spin_unlock_irqrestore(&up->port.lock, flags); in serial_omap_shutdown()
809 serial_out(up, UART_LCR, serial_in(up, UART_LCR) & ~UART_LCR_SBC); in serial_omap_shutdown()
810 serial_omap_clear_fifos(up); in serial_omap_shutdown()
815 if (serial_in(up, UART_LSR) & UART_LSR_DR) in serial_omap_shutdown()
816 (void) serial_in(up, UART_RX); in serial_omap_shutdown()
818 pm_runtime_mark_last_busy(up->dev); in serial_omap_shutdown()
819 pm_runtime_put_autosuspend(up->dev); in serial_omap_shutdown()
820 free_irq(up->port.irq, up); in serial_omap_shutdown()
821 dev_pm_clear_wake_irq(up->dev); in serial_omap_shutdown()
826 struct uart_omap_port *up = container_of(work, struct uart_omap_port, in serial_omap_uart_qos_work() local
829 cpu_latency_qos_update_request(&up->pm_qos_request, up->latency); in serial_omap_uart_qos_work()
836 struct uart_omap_port *up = to_uart_omap_port(port); in serial_omap_set_termios() local
841 switch (termios->c_cflag & CSIZE) { in serial_omap_set_termios()
857 if (termios->c_cflag & CSTOPB) in serial_omap_set_termios()
859 if (termios->c_cflag & PARENB) in serial_omap_set_termios()
861 if (!(termios->c_cflag & PARODD)) in serial_omap_set_termios()
863 if (termios->c_cflag & CMSPAR) in serial_omap_set_termios()
870 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/13); in serial_omap_set_termios()
874 up->calc_latency = (USEC_PER_SEC * up->port.fifosize) / (baud / 8); in serial_omap_set_termios()
875 up->latency = up->calc_latency; in serial_omap_set_termios()
876 schedule_work(&up->qos_work); in serial_omap_set_termios()
878 up->dll = quot & 0xff; in serial_omap_set_termios()
879 up->dlh = quot >> 8; in serial_omap_set_termios()
880 up->mdr1 = UART_OMAP_MDR1_DISABLE; in serial_omap_set_termios()
882 up->fcr = UART_FCR_R_TRIG_01 | UART_FCR_T_TRIG_01 | in serial_omap_set_termios()
889 pm_runtime_get_sync(up->dev); in serial_omap_set_termios()
890 spin_lock_irqsave(&up->port.lock, flags); in serial_omap_set_termios()
893 * Update the per-port timeout. in serial_omap_set_termios()
895 uart_update_timeout(port, termios->c_cflag, baud); in serial_omap_set_termios()
897 up->port.read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR; in serial_omap_set_termios()
898 if (termios->c_iflag & INPCK) in serial_omap_set_termios()
899 up->port.read_status_mask |= UART_LSR_FE | UART_LSR_PE; in serial_omap_set_termios()
900 if (termios->c_iflag & (BRKINT | PARMRK)) in serial_omap_set_termios()
901 up->port.read_status_mask |= UART_LSR_BI; in serial_omap_set_termios()
906 up->port.ignore_status_mask = 0; in serial_omap_set_termios()
907 if (termios->c_iflag & IGNPAR) in serial_omap_set_termios()
908 up->port.ignore_status_mask |= UART_LSR_PE | UART_LSR_FE; in serial_omap_set_termios()
909 if (termios->c_iflag & IGNBRK) { in serial_omap_set_termios()
910 up->port.ignore_status_mask |= UART_LSR_BI; in serial_omap_set_termios()
915 if (termios->c_iflag & IGNPAR) in serial_omap_set_termios()
916 up->port.ignore_status_mask |= UART_LSR_OE; in serial_omap_set_termios()
922 if ((termios->c_cflag & CREAD) == 0) in serial_omap_set_termios()
923 up->port.ignore_status_mask |= UART_LSR_DR; in serial_omap_set_termios()
928 up->ier &= ~UART_IER_MSI; in serial_omap_set_termios()
929 if (UART_ENABLE_MS(&up->port, termios->c_cflag)) in serial_omap_set_termios()
930 up->ier |= UART_IER_MSI; in serial_omap_set_termios()
931 serial_out(up, UART_IER, up->ier); in serial_omap_set_termios()
932 serial_out(up, UART_LCR, cval); /* reset DLAB */ in serial_omap_set_termios()
933 up->lcr = cval; in serial_omap_set_termios()
934 up->scr = 0; in serial_omap_set_termios()
942 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A); in serial_omap_set_termios()
943 serial_out(up, UART_DLL, 0); in serial_omap_set_termios()
944 serial_out(up, UART_DLM, 0); in serial_omap_set_termios()
945 serial_out(up, UART_LCR, 0); in serial_omap_set_termios()
947 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); in serial_omap_set_termios()
949 up->efr = serial_in(up, UART_EFR) & ~UART_EFR_ECB; in serial_omap_set_termios()
950 up->efr &= ~UART_EFR_SCD; in serial_omap_set_termios()
951 serial_out(up, UART_EFR, up->efr | UART_EFR_ECB); in serial_omap_set_termios()
953 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A); in serial_omap_set_termios()
954 up->mcr = serial_in(up, UART_MCR) & ~UART_MCR_TCRTLR; in serial_omap_set_termios()
955 serial_out(up, UART_MCR, up->mcr | UART_MCR_TCRTLR); in serial_omap_set_termios()
958 up->scr |= OMAP_UART_SCR_RX_TRIG_GRANU1_MASK; in serial_omap_set_termios()
972 up->fcr &= ~OMAP_UART_FCR_RX_FIFO_TRIG_MASK; in serial_omap_set_termios()
973 up->fcr &= ~OMAP_UART_FCR_TX_FIFO_TRIG_MASK; in serial_omap_set_termios()
974 up->fcr |= UART_FCR6_R_TRIGGER_16 | UART_FCR6_T_TRIGGER_24 | in serial_omap_set_termios()
977 serial_out(up, UART_FCR, up->fcr); in serial_omap_set_termios()
978 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); in serial_omap_set_termios()
980 serial_out(up, UART_OMAP_SCR, up->scr); in serial_omap_set_termios()
983 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A); in serial_omap_set_termios()
984 serial_out(up, UART_MCR, up->mcr); in serial_omap_set_termios()
985 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); in serial_omap_set_termios()
986 serial_out(up, UART_EFR, up->efr); in serial_omap_set_termios()
987 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A); in serial_omap_set_termios()
991 if (up->errata & UART_ERRATA_i202_MDR1_ACCESS) in serial_omap_set_termios()
992 serial_omap_mdr1_errataset(up, up->mdr1); in serial_omap_set_termios()
994 serial_out(up, UART_OMAP_MDR1, up->mdr1); in serial_omap_set_termios()
996 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); in serial_omap_set_termios()
997 serial_out(up, UART_EFR, up->efr | UART_EFR_ECB); in serial_omap_set_termios()
999 serial_out(up, UART_LCR, 0); in serial_omap_set_termios()
1000 serial_out(up, UART_IER, 0); in serial_omap_set_termios()
1001 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); in serial_omap_set_termios()
1003 serial_out(up, UART_DLL, up->dll); /* LS of divisor */ in serial_omap_set_termios()
1004 serial_out(up, UART_DLM, up->dlh); /* MS of divisor */ in serial_omap_set_termios()
1006 serial_out(up, UART_LCR, 0); in serial_omap_set_termios()
1007 serial_out(up, UART_IER, up->ier); in serial_omap_set_termios()
1008 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); in serial_omap_set_termios()
1010 serial_out(up, UART_EFR, up->efr); in serial_omap_set_termios()
1011 serial_out(up, UART_LCR, cval); in serial_omap_set_termios()
1014 up->mdr1 = UART_OMAP_MDR1_13X_MODE; in serial_omap_set_termios()
1016 up->mdr1 = UART_OMAP_MDR1_16X_MODE; in serial_omap_set_termios()
1018 if (up->errata & UART_ERRATA_i202_MDR1_ACCESS) in serial_omap_set_termios()
1019 serial_omap_mdr1_errataset(up, up->mdr1); in serial_omap_set_termios()
1021 serial_out(up, UART_OMAP_MDR1, up->mdr1); in serial_omap_set_termios()
1024 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); in serial_omap_set_termios()
1027 serial_out(up, UART_XON1, termios->c_cc[VSTART]); in serial_omap_set_termios()
1028 serial_out(up, UART_XOFF1, termios->c_cc[VSTOP]); in serial_omap_set_termios()
1031 serial_out(up, UART_EFR, up->efr | UART_EFR_ECB); in serial_omap_set_termios()
1032 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A); in serial_omap_set_termios()
1033 serial_out(up, UART_MCR, up->mcr | UART_MCR_TCRTLR); in serial_omap_set_termios()
1035 serial_out(up, UART_TI752_TCR, OMAP_UART_TCR_TRIG); in serial_omap_set_termios()
1037 up->port.status &= ~(UPSTAT_AUTOCTS | UPSTAT_AUTORTS | UPSTAT_AUTOXOFF); in serial_omap_set_termios()
1039 if (termios->c_cflag & CRTSCTS && up->port.flags & UPF_HARD_FLOW) { in serial_omap_set_termios()
1041 up->port.status |= UPSTAT_AUTOCTS | UPSTAT_AUTORTS; in serial_omap_set_termios()
1042 up->efr |= UART_EFR_CTS; in serial_omap_set_termios()
1045 up->efr &= ~(UART_EFR_CTS | UART_EFR_RTS); in serial_omap_set_termios()
1048 if (up->port.flags & UPF_SOFT_FLOW) { in serial_omap_set_termios()
1050 up->efr &= OMAP_UART_SW_CLR; in serial_omap_set_termios()
1057 if (termios->c_iflag & IXON) in serial_omap_set_termios()
1058 up->efr |= OMAP_UART_SW_RX; in serial_omap_set_termios()
1065 if (termios->c_iflag & IXOFF) { in serial_omap_set_termios()
1066 up->port.status |= UPSTAT_AUTOXOFF; in serial_omap_set_termios()
1067 up->efr |= OMAP_UART_SW_TX; in serial_omap_set_termios()
1076 if (termios->c_iflag & IXANY) in serial_omap_set_termios()
1077 up->mcr |= UART_MCR_XONANY; in serial_omap_set_termios()
1079 up->mcr &= ~UART_MCR_XONANY; in serial_omap_set_termios()
1081 serial_out(up, UART_MCR, up->mcr); in serial_omap_set_termios()
1082 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); in serial_omap_set_termios()
1083 serial_out(up, UART_EFR, up->efr); in serial_omap_set_termios()
1084 serial_out(up, UART_LCR, up->lcr); in serial_omap_set_termios()
1086 serial_omap_set_mctrl(&up->port, up->port.mctrl); in serial_omap_set_termios()
1088 spin_unlock_irqrestore(&up->port.lock, flags); in serial_omap_set_termios()
1089 pm_runtime_mark_last_busy(up->dev); in serial_omap_set_termios()
1090 pm_runtime_put_autosuspend(up->dev); in serial_omap_set_termios()
1091 dev_dbg(up->port.dev, "serial_omap_set_termios+%d\n", up->port.line); in serial_omap_set_termios()
1098 struct uart_omap_port *up = to_uart_omap_port(port); in serial_omap_pm() local
1101 dev_dbg(up->port.dev, "serial_omap_pm+%d\n", up->port.line); in serial_omap_pm()
1103 pm_runtime_get_sync(up->dev); in serial_omap_pm()
1104 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); in serial_omap_pm()
1105 efr = serial_in(up, UART_EFR); in serial_omap_pm()
1106 serial_out(up, UART_EFR, efr | UART_EFR_ECB); in serial_omap_pm()
1107 serial_out(up, UART_LCR, 0); in serial_omap_pm()
1109 serial_out(up, UART_IER, (state != 0) ? UART_IERX_SLEEP : 0); in serial_omap_pm()
1110 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); in serial_omap_pm()
1111 serial_out(up, UART_EFR, efr); in serial_omap_pm()
1112 serial_out(up, UART_LCR, 0); in serial_omap_pm()
1114 pm_runtime_mark_last_busy(up->dev); in serial_omap_pm()
1115 pm_runtime_put_autosuspend(up->dev); in serial_omap_pm()
1120 dev_dbg(port->dev, "serial_omap_release_port+\n"); in serial_omap_release_port()
1125 dev_dbg(port->dev, "serial_omap_request_port+\n"); in serial_omap_request_port()
1131 struct uart_omap_port *up = to_uart_omap_port(port); in serial_omap_config_port() local
1133 dev_dbg(up->port.dev, "serial_omap_config_port+%d\n", in serial_omap_config_port()
1134 up->port.line); in serial_omap_config_port()
1135 up->port.type = PORT_OMAP; in serial_omap_config_port()
1136 up->port.flags |= UPF_SOFT_FLOW | UPF_HARD_FLOW; in serial_omap_config_port()
1143 dev_dbg(port->dev, "serial_omap_verify_port+\n"); in serial_omap_verify_port()
1144 return -EINVAL; in serial_omap_verify_port()
1150 struct uart_omap_port *up = to_uart_omap_port(port); in serial_omap_type() local
1152 dev_dbg(up->port.dev, "serial_omap_type+%d\n", up->port.line); in serial_omap_type()
1153 return up->name; in serial_omap_type()
1158 static void __maybe_unused wait_for_xmitr(struct uart_omap_port *up) in wait_for_xmitr() argument
1162 /* Wait up to 10ms for the character(s) to be sent. */ in wait_for_xmitr()
1164 status = serial_in(up, UART_LSR); in wait_for_xmitr()
1167 up->lsr_break_flag = UART_LSR_BI; in wait_for_xmitr()
1169 if (--tmout == 0) in wait_for_xmitr()
1174 /* Wait up to 1s for flow control if necessary */ in wait_for_xmitr()
1175 if (up->port.flags & UPF_CONS_FLOW) { in wait_for_xmitr()
1177 for (tmout = 1000000; tmout; tmout--) { in wait_for_xmitr()
1178 unsigned int msr = serial_in(up, UART_MSR); in wait_for_xmitr()
1180 up->msr_saved_flags |= msr & MSR_SAVE_FLAGS; in wait_for_xmitr()
1193 struct uart_omap_port *up = to_uart_omap_port(port); in serial_omap_poll_put_char() local
1195 pm_runtime_get_sync(up->dev); in serial_omap_poll_put_char()
1196 wait_for_xmitr(up); in serial_omap_poll_put_char()
1197 serial_out(up, UART_TX, ch); in serial_omap_poll_put_char()
1198 pm_runtime_mark_last_busy(up->dev); in serial_omap_poll_put_char()
1199 pm_runtime_put_autosuspend(up->dev); in serial_omap_poll_put_char()
1204 struct uart_omap_port *up = to_uart_omap_port(port); in serial_omap_poll_get_char() local
1207 pm_runtime_get_sync(up->dev); in serial_omap_poll_get_char()
1208 status = serial_in(up, UART_LSR); in serial_omap_poll_get_char()
1214 status = serial_in(up, UART_RX); in serial_omap_poll_get_char()
1217 pm_runtime_mark_last_busy(up->dev); in serial_omap_poll_get_char()
1218 pm_runtime_put_autosuspend(up->dev); in serial_omap_poll_get_char()
1230 offset <<= port->regshift; in omap_serial_early_in()
1231 return readw(port->membase + offset); in omap_serial_early_in()
1237 offset <<= port->regshift; in omap_serial_early_out()
1238 writew(value, port->membase + offset); in omap_serial_early_out()
1257 struct earlycon_device *device = console->data; in early_omap_serial_write()
1258 struct uart_port *port = &device->port; in early_omap_serial_write()
1266 struct uart_port *port = &device->port; in early_omap_serial_setup()
1268 if (!(device->port.membase || device->port.iobase)) in early_omap_serial_setup()
1269 return -ENODEV; in early_omap_serial_setup()
1271 port->regshift = 2; in early_omap_serial_setup()
1272 device->con->write = early_omap_serial_write; in early_omap_serial_setup()
1276 OF_EARLYCON_DECLARE(omapserial, "ti,omap2-uart", early_omap_serial_setup);
1277 OF_EARLYCON_DECLARE(omapserial, "ti,omap3-uart", early_omap_serial_setup);
1278 OF_EARLYCON_DECLARE(omapserial, "ti,omap4-uart", early_omap_serial_setup);
1287 struct uart_omap_port *up = to_uart_omap_port(port); in serial_omap_console_putchar() local
1289 wait_for_xmitr(up); in serial_omap_console_putchar()
1290 serial_out(up, UART_TX, ch); in serial_omap_console_putchar()
1297 struct uart_omap_port *up = serial_omap_console_ports[co->index]; in serial_omap_console_write() local
1302 pm_runtime_get_sync(up->dev); in serial_omap_console_write()
1305 if (up->port.sysrq) in serial_omap_console_write()
1308 locked = spin_trylock(&up->port.lock); in serial_omap_console_write()
1310 spin_lock(&up->port.lock); in serial_omap_console_write()
1315 ier = serial_in(up, UART_IER); in serial_omap_console_write()
1316 serial_out(up, UART_IER, 0); in serial_omap_console_write()
1318 uart_console_write(&up->port, s, count, serial_omap_console_putchar); in serial_omap_console_write()
1324 wait_for_xmitr(up); in serial_omap_console_write()
1325 serial_out(up, UART_IER, ier); in serial_omap_console_write()
1333 if (up->msr_saved_flags) in serial_omap_console_write()
1334 check_modem_status(up); in serial_omap_console_write()
1336 pm_runtime_mark_last_busy(up->dev); in serial_omap_console_write()
1337 pm_runtime_put_autosuspend(up->dev); in serial_omap_console_write()
1339 spin_unlock(&up->port.lock); in serial_omap_console_write()
1346 struct uart_omap_port *up; in serial_omap_console_setup() local
1352 if (serial_omap_console_ports[co->index] == NULL) in serial_omap_console_setup()
1353 return -ENODEV; in serial_omap_console_setup()
1354 up = serial_omap_console_ports[co->index]; in serial_omap_console_setup()
1359 return uart_set_options(&up->port, co, baud, parity, bits, flow); in serial_omap_console_setup()
1368 .index = -1,
1372 static void serial_omap_add_console_port(struct uart_omap_port *up) in serial_omap_add_console_port() argument
1374 serial_omap_console_ports[up->port.line] = up; in serial_omap_add_console_port()
1383 static inline void serial_omap_add_console_port(struct uart_omap_port *up) in serial_omap_add_console_port() argument
1392 struct uart_omap_port *up = to_uart_omap_port(port); in serial_omap_config_rs485() local
1396 pm_runtime_get_sync(up->dev); in serial_omap_config_rs485()
1399 mode = up->ier; in serial_omap_config_rs485()
1400 up->ier = 0; in serial_omap_config_rs485()
1401 serial_out(up, UART_IER, 0); in serial_omap_config_rs485()
1404 rs485->delay_rts_before_send = min(rs485->delay_rts_before_send, 100U); in serial_omap_config_rs485()
1405 rs485->delay_rts_after_send = min(rs485->delay_rts_after_send, 100U); in serial_omap_config_rs485()
1408 port->rs485 = *rs485; in serial_omap_config_rs485()
1414 if (up->rts_gpiod) { in serial_omap_config_rs485()
1416 val = (port->rs485.flags & SER_RS485_ENABLED) ? in serial_omap_config_rs485()
1418 val = (port->rs485.flags & val) ? 1 : 0; in serial_omap_config_rs485()
1419 gpiod_set_value(up->rts_gpiod, val); in serial_omap_config_rs485()
1421 port->rs485.flags &= ~SER_RS485_ENABLED; in serial_omap_config_rs485()
1424 up->ier = mode; in serial_omap_config_rs485()
1425 serial_out(up, UART_IER, up->ier); in serial_omap_config_rs485()
1427 /* If RS-485 is disabled, make sure the THR interrupt is fired when in serial_omap_config_rs485()
1430 if (!(port->rs485.flags & SER_RS485_ENABLED) && in serial_omap_config_rs485()
1431 (up->scr & OMAP_UART_SCR_TX_EMPTY)) { in serial_omap_config_rs485()
1432 up->scr &= ~OMAP_UART_SCR_TX_EMPTY; in serial_omap_config_rs485()
1433 serial_out(up, UART_OMAP_SCR, up->scr); in serial_omap_config_rs485()
1436 pm_runtime_mark_last_busy(up->dev); in serial_omap_config_rs485()
1437 pm_runtime_put_autosuspend(up->dev); in serial_omap_config_rs485()
1470 .driver_name = "OMAP-SERIAL",
1479 struct uart_omap_port *up = dev_get_drvdata(dev); in serial_omap_prepare() local
1481 up->is_suspending = true; in serial_omap_prepare()
1488 struct uart_omap_port *up = dev_get_drvdata(dev); in serial_omap_complete() local
1490 up->is_suspending = false; in serial_omap_complete()
1495 struct uart_omap_port *up = dev_get_drvdata(dev); in serial_omap_suspend() local
1497 uart_suspend_port(&serial_omap_reg, &up->port); in serial_omap_suspend()
1498 flush_work(&up->qos_work); in serial_omap_suspend()
1501 serial_omap_enable_wakeup(up, true); in serial_omap_suspend()
1503 serial_omap_enable_wakeup(up, false); in serial_omap_suspend()
1510 struct uart_omap_port *up = dev_get_drvdata(dev); in serial_omap_resume() local
1513 serial_omap_enable_wakeup(up, false); in serial_omap_resume()
1515 uart_resume_port(&serial_omap_reg, &up->port); in serial_omap_resume()
1524 static void omap_serial_fill_features_erratas(struct uart_omap_port *up) in omap_serial_fill_features_erratas() argument
1529 mvr = readl(up->port.membase + (UART_OMAP_MVER << up->port.regshift)); in omap_serial_fill_features_erratas()
1549 dev_warn(up->dev, in omap_serial_fill_features_erratas()
1551 up->name); in omap_serial_fill_features_erratas()
1562 up->errata |= (UART_ERRATA_i202_MDR1_ACCESS | in omap_serial_fill_features_erratas()
1566 up->errata |= (UART_ERRATA_i202_MDR1_ACCESS | in omap_serial_fill_features_erratas()
1568 up->features |= OMAP_UART_WER_HAS_TX_WAKEUP; in omap_serial_fill_features_erratas()
1571 up->errata |= UART_ERRATA_i202_MDR1_ACCESS; in omap_serial_fill_features_erratas()
1572 up->features |= OMAP_UART_WER_HAS_TX_WAKEUP; in omap_serial_fill_features_erratas()
1587 of_property_read_u32(dev->of_node, "clock-frequency", in of_get_uart_port_info()
1588 &omap_up_info->uartclk); in of_get_uart_port_info()
1590 omap_up_info->flags = UPF_BOOT_AUTOCONF; in of_get_uart_port_info()
1595 static int serial_omap_probe_rs485(struct uart_omap_port *up, in serial_omap_probe_rs485() argument
1598 struct serial_rs485 *rs485conf = &up->port.rs485; in serial_omap_probe_rs485()
1599 struct device_node *np = dev->of_node; in serial_omap_probe_rs485()
1603 rs485conf->flags = 0; in serial_omap_probe_rs485()
1604 up->rts_gpiod = NULL; in serial_omap_probe_rs485()
1609 ret = uart_get_rs485_mode(&up->port); in serial_omap_probe_rs485()
1613 if (of_property_read_bool(np, "rs485-rts-active-high")) { in serial_omap_probe_rs485()
1614 rs485conf->flags |= SER_RS485_RTS_ON_SEND; in serial_omap_probe_rs485()
1615 rs485conf->flags &= ~SER_RS485_RTS_AFTER_SEND; in serial_omap_probe_rs485()
1617 rs485conf->flags &= ~SER_RS485_RTS_ON_SEND; in serial_omap_probe_rs485()
1618 rs485conf->flags |= SER_RS485_RTS_AFTER_SEND; in serial_omap_probe_rs485()
1622 gflags = rs485conf->flags & SER_RS485_RTS_AFTER_SEND ? in serial_omap_probe_rs485()
1624 up->rts_gpiod = devm_gpiod_get_optional(dev, "rts", gflags); in serial_omap_probe_rs485()
1625 if (IS_ERR(up->rts_gpiod)) { in serial_omap_probe_rs485()
1626 ret = PTR_ERR(up->rts_gpiod); in serial_omap_probe_rs485()
1627 if (ret == -EPROBE_DEFER) in serial_omap_probe_rs485()
1631 * -EPROBE_DEFER and just went on without GPIO. in serial_omap_probe_rs485()
1633 up->rts_gpiod = NULL; in serial_omap_probe_rs485()
1635 gpiod_set_consumer_name(up->rts_gpiod, "omap-serial"); in serial_omap_probe_rs485()
1643 struct omap_uart_port_info *omap_up_info = dev_get_platdata(&pdev->dev); in serial_omap_probe()
1644 struct uart_omap_port *up; in serial_omap_probe() local
1652 if (pdev->dev.of_node) { in serial_omap_probe()
1653 uartirq = irq_of_parse_and_map(pdev->dev.of_node, 0); in serial_omap_probe()
1655 return -EPROBE_DEFER; in serial_omap_probe()
1656 wakeirq = irq_of_parse_and_map(pdev->dev.of_node, 1); in serial_omap_probe()
1657 omap_up_info = of_get_uart_port_info(&pdev->dev); in serial_omap_probe()
1658 pdev->dev.platform_data = omap_up_info; in serial_omap_probe()
1662 return -EPROBE_DEFER; in serial_omap_probe()
1665 up = devm_kzalloc(&pdev->dev, sizeof(*up), GFP_KERNEL); in serial_omap_probe()
1666 if (!up) in serial_omap_probe()
1667 return -ENOMEM; in serial_omap_probe()
1670 base = devm_ioremap_resource(&pdev->dev, mem); in serial_omap_probe()
1674 up->dev = &pdev->dev; in serial_omap_probe()
1675 up->port.dev = &pdev->dev; in serial_omap_probe()
1676 up->port.type = PORT_OMAP; in serial_omap_probe()
1677 up->port.iotype = UPIO_MEM; in serial_omap_probe()
1678 up->port.irq = uartirq; in serial_omap_probe()
1679 up->port.regshift = 2; in serial_omap_probe()
1680 up->port.fifosize = 64; in serial_omap_probe()
1681 up->port.ops = &serial_omap_pops; in serial_omap_probe()
1682 up->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_OMAP_CONSOLE); in serial_omap_probe()
1684 if (pdev->dev.of_node) in serial_omap_probe()
1685 ret = of_alias_get_id(pdev->dev.of_node, "serial"); in serial_omap_probe()
1687 ret = pdev->id; in serial_omap_probe()
1690 dev_err(&pdev->dev, "failed to get alias/pdev id, errno %d\n", in serial_omap_probe()
1694 up->port.line = ret; in serial_omap_probe()
1696 if (up->port.line >= OMAP_MAX_HSUART_PORTS) { in serial_omap_probe()
1697 dev_err(&pdev->dev, "uart ID %d > MAX %d.\n", up->port.line, in serial_omap_probe()
1699 ret = -ENXIO; in serial_omap_probe()
1703 up->wakeirq = wakeirq; in serial_omap_probe()
1704 if (!up->wakeirq) in serial_omap_probe()
1705 dev_info(up->port.dev, "no wakeirq for uart%d\n", in serial_omap_probe()
1706 up->port.line); in serial_omap_probe()
1708 ret = serial_omap_probe_rs485(up, &pdev->dev); in serial_omap_probe()
1712 sprintf(up->name, "OMAP UART%d", up->port.line); in serial_omap_probe()
1713 up->port.mapbase = mem->start; in serial_omap_probe()
1714 up->port.membase = base; in serial_omap_probe()
1715 up->port.flags = omap_up_info->flags; in serial_omap_probe()
1716 up->port.uartclk = omap_up_info->uartclk; in serial_omap_probe()
1717 up->port.rs485_config = serial_omap_config_rs485; in serial_omap_probe()
1718 if (!up->port.uartclk) { in serial_omap_probe()
1719 up->port.uartclk = DEFAULT_CLK_SPEED; in serial_omap_probe()
1720 dev_warn(&pdev->dev, in serial_omap_probe()
1725 up->latency = PM_QOS_CPU_LATENCY_DEFAULT_VALUE; in serial_omap_probe()
1726 up->calc_latency = PM_QOS_CPU_LATENCY_DEFAULT_VALUE; in serial_omap_probe()
1727 cpu_latency_qos_add_request(&up->pm_qos_request, up->latency); in serial_omap_probe()
1728 INIT_WORK(&up->qos_work, serial_omap_uart_qos_work); in serial_omap_probe()
1730 platform_set_drvdata(pdev, up); in serial_omap_probe()
1731 if (omap_up_info->autosuspend_timeout == 0) in serial_omap_probe()
1732 omap_up_info->autosuspend_timeout = -1; in serial_omap_probe()
1734 device_init_wakeup(up->dev, true); in serial_omap_probe()
1735 pm_runtime_use_autosuspend(&pdev->dev); in serial_omap_probe()
1736 pm_runtime_set_autosuspend_delay(&pdev->dev, in serial_omap_probe()
1737 omap_up_info->autosuspend_timeout); in serial_omap_probe()
1739 pm_runtime_irq_safe(&pdev->dev); in serial_omap_probe()
1740 pm_runtime_enable(&pdev->dev); in serial_omap_probe()
1742 pm_runtime_get_sync(&pdev->dev); in serial_omap_probe()
1744 omap_serial_fill_features_erratas(up); in serial_omap_probe()
1746 ui[up->port.line] = up; in serial_omap_probe()
1747 serial_omap_add_console_port(up); in serial_omap_probe()
1749 ret = uart_add_one_port(&serial_omap_reg, &up->port); in serial_omap_probe()
1753 pm_runtime_mark_last_busy(up->dev); in serial_omap_probe()
1754 pm_runtime_put_autosuspend(up->dev); in serial_omap_probe()
1758 pm_runtime_dont_use_autosuspend(&pdev->dev); in serial_omap_probe()
1759 pm_runtime_put_sync(&pdev->dev); in serial_omap_probe()
1760 pm_runtime_disable(&pdev->dev); in serial_omap_probe()
1761 cpu_latency_qos_remove_request(&up->pm_qos_request); in serial_omap_probe()
1762 device_init_wakeup(up->dev, false); in serial_omap_probe()
1770 struct uart_omap_port *up = platform_get_drvdata(dev); in serial_omap_remove() local
1772 pm_runtime_get_sync(up->dev); in serial_omap_remove()
1774 uart_remove_one_port(&serial_omap_reg, &up->port); in serial_omap_remove()
1776 pm_runtime_dont_use_autosuspend(up->dev); in serial_omap_remove()
1777 pm_runtime_put_sync(up->dev); in serial_omap_remove()
1778 pm_runtime_disable(up->dev); in serial_omap_remove()
1779 cpu_latency_qos_remove_request(&up->pm_qos_request); in serial_omap_remove()
1780 device_init_wakeup(&dev->dev, false); in serial_omap_remove()
1794 static void serial_omap_mdr1_errataset(struct uart_omap_port *up, u8 mdr1) in serial_omap_mdr1_errataset() argument
1798 serial_out(up, UART_OMAP_MDR1, mdr1); in serial_omap_mdr1_errataset()
1800 serial_out(up, UART_FCR, up->fcr | UART_FCR_CLEAR_XMIT | in serial_omap_mdr1_errataset()
1806 while (UART_LSR_THRE != (serial_in(up, UART_LSR) & in serial_omap_mdr1_errataset()
1808 timeout--; in serial_omap_mdr1_errataset()
1811 dev_crit(up->dev, "Errata i202: timedout %x\n", in serial_omap_mdr1_errataset()
1812 serial_in(up, UART_LSR)); in serial_omap_mdr1_errataset()
1820 static void serial_omap_restore_context(struct uart_omap_port *up) in serial_omap_restore_context() argument
1822 if (up->errata & UART_ERRATA_i202_MDR1_ACCESS) in serial_omap_restore_context()
1823 serial_omap_mdr1_errataset(up, UART_OMAP_MDR1_DISABLE); in serial_omap_restore_context()
1825 serial_out(up, UART_OMAP_MDR1, UART_OMAP_MDR1_DISABLE); in serial_omap_restore_context()
1827 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); /* Config B mode */ in serial_omap_restore_context()
1828 serial_out(up, UART_EFR, UART_EFR_ECB); in serial_omap_restore_context()
1829 serial_out(up, UART_LCR, 0x0); /* Operational mode */ in serial_omap_restore_context()
1830 serial_out(up, UART_IER, 0x0); in serial_omap_restore_context()
1831 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); /* Config B mode */ in serial_omap_restore_context()
1832 serial_out(up, UART_DLL, up->dll); in serial_omap_restore_context()
1833 serial_out(up, UART_DLM, up->dlh); in serial_omap_restore_context()
1834 serial_out(up, UART_LCR, 0x0); /* Operational mode */ in serial_omap_restore_context()
1835 serial_out(up, UART_IER, up->ier); in serial_omap_restore_context()
1836 serial_out(up, UART_FCR, up->fcr); in serial_omap_restore_context()
1837 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A); in serial_omap_restore_context()
1838 serial_out(up, UART_MCR, up->mcr); in serial_omap_restore_context()
1839 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); /* Config B mode */ in serial_omap_restore_context()
1840 serial_out(up, UART_OMAP_SCR, up->scr); in serial_omap_restore_context()
1841 serial_out(up, UART_EFR, up->efr); in serial_omap_restore_context()
1842 serial_out(up, UART_LCR, up->lcr); in serial_omap_restore_context()
1843 if (up->errata & UART_ERRATA_i202_MDR1_ACCESS) in serial_omap_restore_context()
1844 serial_omap_mdr1_errataset(up, up->mdr1); in serial_omap_restore_context()
1846 serial_out(up, UART_OMAP_MDR1, up->mdr1); in serial_omap_restore_context()
1847 serial_out(up, UART_OMAP_WER, up->wer); in serial_omap_restore_context()
1852 struct uart_omap_port *up = dev_get_drvdata(dev); in serial_omap_runtime_suspend() local
1854 if (!up) in serial_omap_runtime_suspend()
1855 return -EINVAL; in serial_omap_runtime_suspend()
1863 if (up->is_suspending && !console_suspend_enabled && in serial_omap_runtime_suspend()
1864 uart_console(&up->port)) in serial_omap_runtime_suspend()
1865 return -EBUSY; in serial_omap_runtime_suspend()
1867 up->context_loss_cnt = serial_omap_get_context_loss_count(up); in serial_omap_runtime_suspend()
1869 serial_omap_enable_wakeup(up, true); in serial_omap_runtime_suspend()
1871 up->latency = PM_QOS_CPU_LATENCY_DEFAULT_VALUE; in serial_omap_runtime_suspend()
1872 schedule_work(&up->qos_work); in serial_omap_runtime_suspend()
1879 struct uart_omap_port *up = dev_get_drvdata(dev); in serial_omap_runtime_resume() local
1881 int loss_cnt = serial_omap_get_context_loss_count(up); in serial_omap_runtime_resume()
1883 serial_omap_enable_wakeup(up, false); in serial_omap_runtime_resume()
1888 serial_omap_restore_context(up); in serial_omap_runtime_resume()
1889 } else if (up->context_loss_cnt != loss_cnt) { in serial_omap_runtime_resume()
1890 serial_omap_restore_context(up); in serial_omap_runtime_resume()
1892 up->latency = up->calc_latency; in serial_omap_runtime_resume()
1893 schedule_work(&up->qos_work); in serial_omap_runtime_resume()
1909 { .compatible = "ti,omap2-uart" },
1910 { .compatible = "ti,omap3-uart" },
1911 { .compatible = "ti,omap4-uart" },