Lines Matching +full:hw +full:- +full:settle +full:- +full:time

1 // SPDX-License-Identifier: GPL-2.0+
29 * The initial minor number is 209 in the low-density serial port:
102 * (bits 0-7, bits 8-11 are irqs) */
130 /* poll time (in ms) for ctrl lines */
143 if (s->parity & MAX3100_PARITY_ODD) in max3100_do_parity()
148 if (s->parity & MAX3100_7BIT) in max3100_do_parity()
164 if (s->parity & MAX3100_7BIT) in max3100_calc_parity()
169 if (s->parity & MAX3100_PARITY_ON) in max3100_calc_parity()
177 if (!s->force_end_work && !freezing(current) && !s->suspending) in max3100_dowork()
178 queue_work(s->workqueue, &s->work); in max3100_dowork()
185 if (s->port.state) { in max3100_timeout()
187 mod_timer(&s->timer, jiffies + s->poll_time); in max3100_timeout()
205 status = spi_sync(s->spi, &message); in max3100_sr()
207 dev_warn(&s->spi->dev, "error while calling spi_sync\n"); in max3100_sr()
208 return -EIO; in max3100_sr()
211 s->tx_empty = (*rx & MAX3100_T) > 0; in max3100_sr()
212 dev_dbg(&s->spi->dev, "%04x - %04x\n", tx, *rx); in max3100_sr()
221 if (rx & MAX3100_R && s->rx_enabled) { in max3100_handlerx()
222 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_handlerx()
223 ch = rx & (s->parity & MAX3100_7BIT ? 0x7f : 0xff); in max3100_handlerx()
225 s->port.icount.frame++; in max3100_handlerx()
229 if (s->parity & MAX3100_PARITY_ON) { in max3100_handlerx()
231 s->port.icount.rx++; in max3100_handlerx()
234 s->port.icount.parity++; in max3100_handlerx()
239 s->port.icount.rx++; in max3100_handlerx()
243 uart_insert_char(&s->port, status, MAX3100_STATUS_OE, ch, flg); in max3100_handlerx()
248 if (s->cts != cts) { in max3100_handlerx()
249 s->cts = cts; in max3100_handlerx()
250 uart_handle_cts_change(&s->port, cts ? TIOCM_CTS : 0); in max3100_handlerx()
262 struct circ_buf *xmit = &s->port.state->xmit; in max3100_work()
264 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_work()
268 spin_lock(&s->conf_lock); in max3100_work()
269 conf = s->conf; in max3100_work()
270 cconf = s->conf_commit; in max3100_work()
271 s->conf_commit = 0; in max3100_work()
272 crts = s->rts_commit; in max3100_work()
273 s->rts_commit = 0; in max3100_work()
274 spin_unlock(&s->conf_lock); in max3100_work()
279 (s->rts ? MAX3100_RTS : 0), &rx); in max3100_work()
288 if (s->port.x_char) { in max3100_work()
289 tx = s->port.x_char; in max3100_work()
290 s->port.icount.tx++; in max3100_work()
291 s->port.x_char = 0; in max3100_work()
293 !uart_tx_stopped(&s->port)) { in max3100_work()
294 tx = xmit->buf[xmit->tail]; in max3100_work()
295 xmit->tail = (xmit->tail + 1) & in max3100_work()
296 (UART_XMIT_SIZE - 1); in max3100_work()
297 s->port.icount.tx++; in max3100_work()
301 tx |= MAX3100_WD | (s->rts ? MAX3100_RTS : 0); in max3100_work()
308 tty_flip_buffer_push(&s->port.state->port); in max3100_work()
312 uart_write_wakeup(&s->port); in max3100_work()
314 } while (!s->force_end_work && in max3100_work()
318 !uart_tx_stopped(&s->port)))); in max3100_work()
321 tty_flip_buffer_push(&s->port.state->port); in max3100_work()
328 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_irq()
340 if (s->poll_time > 0) in max3100_enable_ms()
341 mod_timer(&s->timer, jiffies); in max3100_enable_ms()
342 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_enable_ms()
351 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_start_tx()
362 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_stop_rx()
364 s->rx_enabled = 0; in max3100_stop_rx()
365 spin_lock(&s->conf_lock); in max3100_stop_rx()
366 s->conf &= ~MAX3100_RM; in max3100_stop_rx()
367 s->conf_commit = 1; in max3100_stop_rx()
368 spin_unlock(&s->conf_lock); in max3100_stop_rx()
378 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_tx_empty()
380 /* may not be truly up-to-date */ in max3100_tx_empty()
382 return s->tx_empty; in max3100_tx_empty()
391 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_get_mctrl()
393 /* may not be truly up-to-date */ in max3100_get_mctrl()
396 return (s->cts ? TIOCM_CTS : 0) | TIOCM_DSR | TIOCM_CAR; in max3100_get_mctrl()
406 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_set_mctrl()
410 spin_lock(&s->conf_lock); in max3100_set_mctrl()
411 if (s->rts != rts) { in max3100_set_mctrl()
412 s->rts = rts; in max3100_set_mctrl()
413 s->rts_commit = 1; in max3100_set_mctrl()
416 spin_unlock(&s->conf_lock); in max3100_set_mctrl()
430 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_set_termios()
432 cflag = termios->c_cflag; in max3100_set_termios()
436 param_new = s->conf & MAX3100_BAUD; in max3100_set_termios()
439 if (s->crystal) in max3100_set_termios()
440 baud = s->baud; in max3100_set_termios()
445 param_new = 14 + s->crystal; in max3100_set_termios()
448 param_new = 13 + s->crystal; in max3100_set_termios()
451 param_new = 12 + s->crystal; in max3100_set_termios()
454 param_new = 11 + s->crystal; in max3100_set_termios()
457 param_new = 10 + s->crystal; in max3100_set_termios()
460 param_new = 9 + s->crystal; in max3100_set_termios()
463 param_new = 8 + s->crystal; in max3100_set_termios()
466 param_new = 1 + s->crystal; in max3100_set_termios()
469 param_new = 0 + s->crystal; in max3100_set_termios()
472 if (s->crystal) in max3100_set_termios()
475 baud = s->baud; in max3100_set_termios()
478 baud = s->baud; in max3100_set_termios()
481 s->baud = baud; in max3100_set_termios()
516 termios->c_cflag = cflag; in max3100_set_termios()
518 s->port.ignore_status_mask = 0; in max3100_set_termios()
519 if (termios->c_iflag & IGNPAR) in max3100_set_termios()
520 s->port.ignore_status_mask |= in max3100_set_termios()
525 s->port.state->port.low_latency = 1; in max3100_set_termios()
527 if (s->poll_time > 0) in max3100_set_termios()
528 del_timer_sync(&s->timer); in max3100_set_termios()
530 uart_update_timeout(port, termios->c_cflag, baud); in max3100_set_termios()
532 spin_lock(&s->conf_lock); in max3100_set_termios()
533 s->conf = (s->conf & ~param_mask) | (param_new & param_mask); in max3100_set_termios()
534 s->conf_commit = 1; in max3100_set_termios()
535 s->parity = parity; in max3100_set_termios()
536 spin_unlock(&s->conf_lock); in max3100_set_termios()
539 if (UART_ENABLE_MS(&s->port, termios->c_cflag)) in max3100_set_termios()
540 max3100_enable_ms(&s->port); in max3100_set_termios()
549 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_shutdown()
551 if (s->suspending) in max3100_shutdown()
554 s->force_end_work = 1; in max3100_shutdown()
556 if (s->poll_time > 0) in max3100_shutdown()
557 del_timer_sync(&s->timer); in max3100_shutdown()
559 if (s->workqueue) { in max3100_shutdown()
560 flush_workqueue(s->workqueue); in max3100_shutdown()
561 destroy_workqueue(s->workqueue); in max3100_shutdown()
562 s->workqueue = NULL; in max3100_shutdown()
564 if (s->irq) in max3100_shutdown()
565 free_irq(s->irq, s); in max3100_shutdown()
568 if (s->max3100_hw_suspend) in max3100_shutdown()
569 s->max3100_hw_suspend(1); in max3100_shutdown()
585 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_startup()
587 s->conf = MAX3100_RM; in max3100_startup()
588 s->baud = s->crystal ? 230400 : 115200; in max3100_startup()
589 s->rx_enabled = 1; in max3100_startup()
591 if (s->suspending) in max3100_startup()
594 s->force_end_work = 0; in max3100_startup()
595 s->parity = 0; in max3100_startup()
596 s->rts = 0; in max3100_startup()
598 sprintf(b, "max3100-%d", s->minor); in max3100_startup()
599 s->workqueue = create_freezable_workqueue(b); in max3100_startup()
600 if (!s->workqueue) { in max3100_startup()
601 dev_warn(&s->spi->dev, "cannot create workqueue\n"); in max3100_startup()
602 return -EBUSY; in max3100_startup()
604 INIT_WORK(&s->work, max3100_work); in max3100_startup()
606 if (request_irq(s->irq, max3100_irq, in max3100_startup()
608 dev_warn(&s->spi->dev, "cannot allocate irq %d\n", s->irq); in max3100_startup()
609 s->irq = 0; in max3100_startup()
610 destroy_workqueue(s->workqueue); in max3100_startup()
611 s->workqueue = NULL; in max3100_startup()
612 return -EBUSY; in max3100_startup()
615 if (s->loopback) { in max3100_startup()
621 if (s->max3100_hw_suspend) in max3100_startup()
622 s->max3100_hw_suspend(0); in max3100_startup()
623 s->conf_commit = 1; in max3100_startup()
625 /* wait for clock to settle */ in max3100_startup()
628 max3100_enable_ms(&s->port); in max3100_startup()
639 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_type()
641 return s->port.type == PORT_MAX3100 ? "MAX3100" : NULL; in max3100_type()
650 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_release_port()
659 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_config_port()
662 s->port.type = PORT_MAX3100; in max3100_config_port()
671 int ret = -EINVAL; in max3100_verify_port()
673 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_verify_port()
675 if (ser->type == PORT_UNKNOWN || ser->type == PORT_MAX3100) in max3100_verify_port()
686 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_stop_tx()
695 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_request_port()
705 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_break_ctl()
759 dev_warn(&spi->dev, "too many MAX3100 chips\n"); in max3100_probe()
761 return -ENOMEM; in max3100_probe()
766 dev_warn(&spi->dev, in max3100_probe()
769 return -ENOMEM; in max3100_probe()
771 max3100s[i]->spi = spi; in max3100_probe()
772 max3100s[i]->irq = spi->irq; in max3100_probe()
773 spin_lock_init(&max3100s[i]->conf_lock); in max3100_probe()
775 pdata = dev_get_platdata(&spi->dev); in max3100_probe()
776 max3100s[i]->crystal = pdata->crystal; in max3100_probe()
777 max3100s[i]->loopback = pdata->loopback; in max3100_probe()
778 max3100s[i]->poll_time = msecs_to_jiffies(pdata->poll_time); in max3100_probe()
779 if (pdata->poll_time > 0 && max3100s[i]->poll_time == 0) in max3100_probe()
780 max3100s[i]->poll_time = 1; in max3100_probe()
781 max3100s[i]->max3100_hw_suspend = pdata->max3100_hw_suspend; in max3100_probe()
782 max3100s[i]->minor = i; in max3100_probe()
783 timer_setup(&max3100s[i]->timer, max3100_timeout, 0); in max3100_probe()
785 dev_dbg(&spi->dev, "%s: adding port %d\n", __func__, i); in max3100_probe()
786 max3100s[i]->port.irq = max3100s[i]->irq; in max3100_probe()
787 max3100s[i]->port.uartclk = max3100s[i]->crystal ? 3686400 : 1843200; in max3100_probe()
788 max3100s[i]->port.fifosize = 16; in max3100_probe()
789 max3100s[i]->port.ops = &max3100_ops; in max3100_probe()
790 max3100s[i]->port.flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF; in max3100_probe()
791 max3100s[i]->port.line = i; in max3100_probe()
792 max3100s[i]->port.type = PORT_MAX3100; in max3100_probe()
793 max3100s[i]->port.dev = &spi->dev; in max3100_probe()
794 retval = uart_add_one_port(&max3100_uart_driver, &max3100s[i]->port); in max3100_probe()
796 dev_warn(&spi->dev, in max3100_probe()
800 /* set shutdown mode to save power. Will be woken-up on open */ in max3100_probe()
801 if (max3100s[i]->max3100_hw_suspend) in max3100_probe()
802 max3100s[i]->max3100_hw_suspend(1); in max3100_probe()
821 dev_dbg(&spi->dev, "%s: removing port %d\n", __func__, i); in max3100_remove()
822 uart_remove_one_port(&max3100_uart_driver, &max3100s[i]->port); in max3100_remove()
849 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_suspend()
851 disable_irq(s->irq); in max3100_suspend()
853 s->suspending = 1; in max3100_suspend()
854 uart_suspend_port(&max3100_uart_driver, &s->port); in max3100_suspend()
856 if (s->max3100_hw_suspend) in max3100_suspend()
857 s->max3100_hw_suspend(1); in max3100_suspend()
859 /* no HW suspend, so do SW one */ in max3100_suspend()
872 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_resume()
874 if (s->max3100_hw_suspend) in max3100_resume()
875 s->max3100_hw_suspend(0); in max3100_resume()
876 uart_resume_port(&max3100_uart_driver, &s->port); in max3100_resume()
877 s->suspending = 0; in max3100_resume()
879 enable_irq(s->irq); in max3100_resume()
881 s->conf_commit = 1; in max3100_resume()
882 if (s->workqueue) in max3100_resume()