Lines Matching +full:conf +full:- +full:rx

1 // SPDX-License-Identifier: GPL-2.0+
8 * writing conf clears FIFO buffer and we cannot have this interrupt
29 * The initial minor number is 209 in the low-density serial port:
104 int conf; /* configuration for the MAX31000 member
105 * (bits 0-7, bits 8-11 are irqs) */
114 int rx_enabled; /* if we should rx chars */
146 if (s->parity & MAX3100_PARITY_ODD) in max3100_do_parity()
151 if (s->parity & MAX3100_7BIT) in max3100_do_parity()
167 if (s->parity & MAX3100_7BIT) in max3100_calc_parity()
172 if (s->parity & MAX3100_PARITY_ON) in max3100_calc_parity()
180 if (!s->force_end_work && !freezing(current) && !s->suspending) in max3100_dowork()
181 queue_work(s->workqueue, &s->work); in max3100_dowork()
188 if (s->port.state) { in max3100_timeout()
190 mod_timer(&s->timer, jiffies + s->poll_time); in max3100_timeout()
194 static int max3100_sr(struct max3100_port *s, u16 tx, u16 *rx) in max3100_sr() argument
208 status = spi_sync(s->spi, &message); in max3100_sr()
210 dev_warn(&s->spi->dev, "error while calling spi_sync\n"); in max3100_sr()
211 return -EIO; in max3100_sr()
213 *rx = be16_to_cpu(erx); in max3100_sr()
214 s->tx_empty = (*rx & MAX3100_T) > 0; in max3100_sr()
215 dev_dbg(&s->spi->dev, "%04x - %04x\n", tx, *rx); in max3100_sr()
219 static int max3100_handlerx_unlocked(struct max3100_port *s, u16 rx) in max3100_handlerx_unlocked() argument
225 if (rx & MAX3100_R && s->rx_enabled) { in max3100_handlerx_unlocked()
226 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_handlerx_unlocked()
227 ch = rx & (s->parity & MAX3100_7BIT ? 0x7f : 0xff); in max3100_handlerx_unlocked()
228 if (rx & MAX3100_RAFE) { in max3100_handlerx_unlocked()
229 s->port.icount.frame++; in max3100_handlerx_unlocked()
233 if (s->parity & MAX3100_PARITY_ON) { in max3100_handlerx_unlocked()
234 if (max3100_check_parity(s, rx)) { in max3100_handlerx_unlocked()
235 s->port.icount.rx++; in max3100_handlerx_unlocked()
238 s->port.icount.parity++; in max3100_handlerx_unlocked()
243 s->port.icount.rx++; in max3100_handlerx_unlocked()
247 uart_insert_char(&s->port, status, MAX3100_STATUS_OE, ch, flg); in max3100_handlerx_unlocked()
251 cts = (rx & MAX3100_CTS) > 0; in max3100_handlerx_unlocked()
252 if (s->cts != cts) { in max3100_handlerx_unlocked()
253 s->cts = cts; in max3100_handlerx_unlocked()
254 uart_handle_cts_change(&s->port, cts); in max3100_handlerx_unlocked()
260 static int max3100_handlerx(struct max3100_port *s, u16 rx) in max3100_handlerx() argument
265 uart_port_lock_irqsave(&s->port, &flags); in max3100_handlerx()
266 ret = max3100_handlerx_unlocked(s, rx); in max3100_handlerx()
267 uart_port_unlock_irqrestore(&s->port, flags); in max3100_handlerx()
275 u16 tx, rx; in max3100_work() local
276 int conf, cconf, crts; in max3100_work() local
277 struct circ_buf *xmit = &s->port.state->xmit; in max3100_work()
279 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_work()
283 spin_lock(&s->conf_lock); in max3100_work()
284 conf = s->conf; in max3100_work()
285 cconf = s->conf_commit; in max3100_work()
286 s->conf_commit = 0; in max3100_work()
287 crts = s->rts_commit; in max3100_work()
288 s->rts_commit = 0; in max3100_work()
289 spin_unlock(&s->conf_lock); in max3100_work()
291 max3100_sr(s, MAX3100_WC | conf, &rx); in max3100_work()
294 (s->rts ? MAX3100_RTS : 0), &rx); in max3100_work()
295 rxchars += max3100_handlerx(s, rx); in max3100_work()
298 max3100_sr(s, MAX3100_RD, &rx); in max3100_work()
299 rxchars += max3100_handlerx(s, rx); in max3100_work()
301 if (rx & MAX3100_T) { in max3100_work()
303 if (s->port.x_char) { in max3100_work()
304 tx = s->port.x_char; in max3100_work()
305 s->port.icount.tx++; in max3100_work()
306 s->port.x_char = 0; in max3100_work()
308 !uart_tx_stopped(&s->port)) { in max3100_work()
309 tx = xmit->buf[xmit->tail]; in max3100_work()
310 uart_xmit_advance(&s->port, 1); in max3100_work()
314 tx |= MAX3100_WD | (s->rts ? MAX3100_RTS : 0); in max3100_work()
315 max3100_sr(s, tx, &rx); in max3100_work()
316 rxchars += max3100_handlerx(s, rx); in max3100_work()
321 tty_flip_buffer_push(&s->port.state->port); in max3100_work()
325 uart_write_wakeup(&s->port); in max3100_work()
327 } while (!s->force_end_work && in max3100_work()
329 ((rx & MAX3100_R) || in max3100_work()
331 !uart_tx_stopped(&s->port)))); in max3100_work()
334 tty_flip_buffer_push(&s->port.state->port); in max3100_work()
341 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_irq()
353 if (s->poll_time > 0) in max3100_enable_ms()
354 mod_timer(&s->timer, jiffies); in max3100_enable_ms()
355 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_enable_ms()
364 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_start_tx()
375 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_stop_rx()
377 s->rx_enabled = 0; in max3100_stop_rx()
378 spin_lock(&s->conf_lock); in max3100_stop_rx()
379 s->conf &= ~MAX3100_RM; in max3100_stop_rx()
380 s->conf_commit = 1; in max3100_stop_rx()
381 spin_unlock(&s->conf_lock); in max3100_stop_rx()
391 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_tx_empty()
393 /* may not be truly up-to-date */ in max3100_tx_empty()
395 return s->tx_empty; in max3100_tx_empty()
404 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_get_mctrl()
406 /* may not be truly up-to-date */ in max3100_get_mctrl()
409 return (s->cts ? TIOCM_CTS : 0) | TIOCM_DSR | TIOCM_CAR; in max3100_get_mctrl()
419 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_set_mctrl()
423 spin_lock(&s->conf_lock); in max3100_set_mctrl()
424 if (s->rts != rts) { in max3100_set_mctrl()
425 s->rts = rts; in max3100_set_mctrl()
426 s->rts_commit = 1; in max3100_set_mctrl()
429 spin_unlock(&s->conf_lock); in max3100_set_mctrl()
443 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_set_termios()
445 cflag = termios->c_cflag; in max3100_set_termios()
449 param_new = s->conf & MAX3100_BAUD; in max3100_set_termios()
452 if (s->crystal) in max3100_set_termios()
453 baud = s->baud; in max3100_set_termios()
458 param_new = 14 + s->crystal; in max3100_set_termios()
461 param_new = 13 + s->crystal; in max3100_set_termios()
464 param_new = 12 + s->crystal; in max3100_set_termios()
467 param_new = 11 + s->crystal; in max3100_set_termios()
470 param_new = 10 + s->crystal; in max3100_set_termios()
473 param_new = 9 + s->crystal; in max3100_set_termios()
476 param_new = 8 + s->crystal; in max3100_set_termios()
479 param_new = 1 + s->crystal; in max3100_set_termios()
482 param_new = 0 + s->crystal; in max3100_set_termios()
485 if (s->crystal) in max3100_set_termios()
488 baud = s->baud; in max3100_set_termios()
491 baud = s->baud; in max3100_set_termios()
494 s->baud = baud; in max3100_set_termios()
529 termios->c_cflag = cflag; in max3100_set_termios()
531 s->port.ignore_status_mask = 0; in max3100_set_termios()
532 if (termios->c_iflag & IGNPAR) in max3100_set_termios()
533 s->port.ignore_status_mask |= in max3100_set_termios()
537 if (s->poll_time > 0) in max3100_set_termios()
538 del_timer_sync(&s->timer); in max3100_set_termios()
540 uart_update_timeout(port, termios->c_cflag, baud); in max3100_set_termios()
542 spin_lock(&s->conf_lock); in max3100_set_termios()
543 s->conf = (s->conf & ~param_mask) | (param_new & param_mask); in max3100_set_termios()
544 s->conf_commit = 1; in max3100_set_termios()
545 s->parity = parity; in max3100_set_termios()
546 spin_unlock(&s->conf_lock); in max3100_set_termios()
549 if (UART_ENABLE_MS(&s->port, termios->c_cflag)) in max3100_set_termios()
550 max3100_enable_ms(&s->port); in max3100_set_termios()
559 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_shutdown()
561 if (s->suspending) in max3100_shutdown()
564 s->force_end_work = 1; in max3100_shutdown()
566 if (s->poll_time > 0) in max3100_shutdown()
567 del_timer_sync(&s->timer); in max3100_shutdown()
569 if (s->workqueue) { in max3100_shutdown()
570 destroy_workqueue(s->workqueue); in max3100_shutdown()
571 s->workqueue = NULL; in max3100_shutdown()
573 if (s->irq) in max3100_shutdown()
574 free_irq(s->irq, s); in max3100_shutdown()
577 if (s->max3100_hw_suspend) in max3100_shutdown()
578 s->max3100_hw_suspend(1); in max3100_shutdown()
580 u16 tx, rx; in max3100_shutdown() local
583 max3100_sr(s, tx, &rx); in max3100_shutdown()
594 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_startup()
596 s->conf = MAX3100_RM; in max3100_startup()
597 s->baud = s->crystal ? 230400 : 115200; in max3100_startup()
598 s->rx_enabled = 1; in max3100_startup()
600 if (s->suspending) in max3100_startup()
603 s->force_end_work = 0; in max3100_startup()
604 s->parity = 0; in max3100_startup()
605 s->rts = 0; in max3100_startup()
607 sprintf(b, "max3100-%d", s->minor); in max3100_startup()
608 s->workqueue = create_freezable_workqueue(b); in max3100_startup()
609 if (!s->workqueue) { in max3100_startup()
610 dev_warn(&s->spi->dev, "cannot create workqueue\n"); in max3100_startup()
611 return -EBUSY; in max3100_startup()
613 INIT_WORK(&s->work, max3100_work); in max3100_startup()
615 if (request_irq(s->irq, max3100_irq, in max3100_startup()
617 dev_warn(&s->spi->dev, "cannot allocate irq %d\n", s->irq); in max3100_startup()
618 s->irq = 0; in max3100_startup()
619 destroy_workqueue(s->workqueue); in max3100_startup()
620 s->workqueue = NULL; in max3100_startup()
621 return -EBUSY; in max3100_startup()
624 if (s->loopback) { in max3100_startup()
625 u16 tx, rx; in max3100_startup() local
627 max3100_sr(s, tx, &rx); in max3100_startup()
630 if (s->max3100_hw_suspend) in max3100_startup()
631 s->max3100_hw_suspend(0); in max3100_startup()
632 s->conf_commit = 1; in max3100_startup()
637 max3100_enable_ms(&s->port); in max3100_startup()
648 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_type()
650 return s->port.type == PORT_MAX3100 ? "MAX3100" : NULL; in max3100_type()
659 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_release_port()
668 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_config_port()
671 s->port.type = PORT_MAX3100; in max3100_config_port()
680 int ret = -EINVAL; in max3100_verify_port()
682 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_verify_port()
684 if (ser->type == PORT_UNKNOWN || ser->type == PORT_MAX3100) in max3100_verify_port()
695 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_stop_tx()
704 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_request_port()
714 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_break_ctl()
750 u16 tx, rx; in max3100_probe() local
769 dev_warn(&spi->dev, "too many MAX3100 chips\n"); in max3100_probe()
771 return -ENOMEM; in max3100_probe()
776 dev_warn(&spi->dev, in max3100_probe()
779 return -ENOMEM; in max3100_probe()
781 max3100s[i]->spi = spi; in max3100_probe()
782 max3100s[i]->irq = spi->irq; in max3100_probe()
783 spin_lock_init(&max3100s[i]->conf_lock); in max3100_probe()
785 pdata = dev_get_platdata(&spi->dev); in max3100_probe()
786 max3100s[i]->crystal = pdata->crystal; in max3100_probe()
787 max3100s[i]->loopback = pdata->loopback; in max3100_probe()
788 max3100s[i]->poll_time = msecs_to_jiffies(pdata->poll_time); in max3100_probe()
789 if (pdata->poll_time > 0 && max3100s[i]->poll_time == 0) in max3100_probe()
790 max3100s[i]->poll_time = 1; in max3100_probe()
791 max3100s[i]->max3100_hw_suspend = pdata->max3100_hw_suspend; in max3100_probe()
792 max3100s[i]->minor = i; in max3100_probe()
793 timer_setup(&max3100s[i]->timer, max3100_timeout, 0); in max3100_probe()
795 dev_dbg(&spi->dev, "%s: adding port %d\n", __func__, i); in max3100_probe()
796 max3100s[i]->port.irq = max3100s[i]->irq; in max3100_probe()
797 max3100s[i]->port.uartclk = max3100s[i]->crystal ? 3686400 : 1843200; in max3100_probe()
798 max3100s[i]->port.fifosize = 16; in max3100_probe()
799 max3100s[i]->port.ops = &max3100_ops; in max3100_probe()
800 max3100s[i]->port.flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF; in max3100_probe()
801 max3100s[i]->port.line = i; in max3100_probe()
802 max3100s[i]->port.type = PORT_MAX3100; in max3100_probe()
803 max3100s[i]->port.dev = &spi->dev; in max3100_probe()
804 retval = uart_add_one_port(&max3100_uart_driver, &max3100s[i]->port); in max3100_probe()
806 dev_warn(&spi->dev, in max3100_probe()
810 /* set shutdown mode to save power. Will be woken-up on open */ in max3100_probe()
811 if (max3100s[i]->max3100_hw_suspend) in max3100_probe()
812 max3100s[i]->max3100_hw_suspend(1); in max3100_probe()
815 max3100_sr(max3100s[i], tx, &rx); in max3100_probe()
831 dev_dbg(&spi->dev, "%s: removing port %d\n", __func__, i); in max3100_remove()
832 uart_remove_one_port(&max3100_uart_driver, &max3100s[i]->port); in max3100_remove()
859 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_suspend()
861 disable_irq(s->irq); in max3100_suspend()
863 s->suspending = 1; in max3100_suspend()
864 uart_suspend_port(&max3100_uart_driver, &s->port); in max3100_suspend()
866 if (s->max3100_hw_suspend) in max3100_suspend()
867 s->max3100_hw_suspend(1); in max3100_suspend()
870 u16 tx, rx; in max3100_suspend() local
873 max3100_sr(s, tx, &rx); in max3100_suspend()
882 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_resume()
884 if (s->max3100_hw_suspend) in max3100_resume()
885 s->max3100_hw_suspend(0); in max3100_resume()
886 uart_resume_port(&max3100_uart_driver, &s->port); in max3100_resume()
887 s->suspending = 0; in max3100_resume()
889 enable_irq(s->irq); in max3100_resume()
891 s->conf_commit = 1; in max3100_resume()
892 if (s->workqueue) in max3100_resume()