Lines Matching +full:- +full:s

1 // SPDX-License-Identifier: GPL-2.0+
10 * The initial minor number is 209 in the low-density serial port:
88 * (bits 0-7, bits 8-11 are irqs) */
122 static int max3100_do_parity(struct max3100_port *s, u16 c) in max3100_do_parity() argument
126 if (s->parity & MAX3100_PARITY_ODD) in max3100_do_parity()
131 if (s->parity & MAX3100_7BIT) in max3100_do_parity()
140 static int max3100_check_parity(struct max3100_port *s, u16 c) in max3100_check_parity() argument
142 return max3100_do_parity(s, c) == ((c >> 8) & 1); in max3100_check_parity()
145 static void max3100_calc_parity(struct max3100_port *s, u16 *c) in max3100_calc_parity() argument
147 if (s->parity & MAX3100_7BIT) in max3100_calc_parity()
152 if (s->parity & MAX3100_PARITY_ON) in max3100_calc_parity()
153 *c |= max3100_do_parity(s, *c) << 8; in max3100_calc_parity()
156 static int max3100_sr(struct max3100_port *s, u16 tx, u16 *rx) in max3100_sr() argument
170 status = spi_sync(s->spi, &message); in max3100_sr()
172 dev_warn(&s->spi->dev, "error while calling spi_sync\n"); in max3100_sr()
173 return -EIO; in max3100_sr()
176 s->tx_empty = (*rx & MAX3100_T) > 0; in max3100_sr()
177 dev_dbg(&s->spi->dev, "%04x - %04x\n", tx, *rx); in max3100_sr()
181 static int max3100_handlerx_unlocked(struct max3100_port *s, u16 rx) in max3100_handlerx_unlocked() argument
187 if (rx & MAX3100_R && s->rx_enabled) { in max3100_handlerx_unlocked()
188 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_handlerx_unlocked()
189 ch = rx & (s->parity & MAX3100_7BIT ? 0x7f : 0xff); in max3100_handlerx_unlocked()
191 s->port.icount.frame++; in max3100_handlerx_unlocked()
195 if (s->parity & MAX3100_PARITY_ON) { in max3100_handlerx_unlocked()
196 if (max3100_check_parity(s, rx)) { in max3100_handlerx_unlocked()
197 s->port.icount.rx++; in max3100_handlerx_unlocked()
200 s->port.icount.parity++; in max3100_handlerx_unlocked()
205 s->port.icount.rx++; in max3100_handlerx_unlocked()
209 uart_insert_char(&s->port, status, MAX3100_STATUS_OE, ch, flg); in max3100_handlerx_unlocked()
214 if (s->cts != cts) { in max3100_handlerx_unlocked()
215 s->cts = cts; in max3100_handlerx_unlocked()
216 uart_handle_cts_change(&s->port, cts); in max3100_handlerx_unlocked()
222 static int max3100_handlerx(struct max3100_port *s, u16 rx) in max3100_handlerx() argument
227 uart_port_lock_irqsave(&s->port, &flags); in max3100_handlerx()
228 ret = max3100_handlerx_unlocked(s, rx); in max3100_handlerx()
229 uart_port_unlock_irqrestore(&s->port, flags); in max3100_handlerx()
235 struct max3100_port *s = container_of(w, struct max3100_port, work); in max3100_work() local
236 struct tty_port *tport = &s->port.state->port; in max3100_work()
242 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_work()
246 spin_lock(&s->conf_lock); in max3100_work()
247 conf = s->conf; in max3100_work()
248 cconf = s->conf_commit; in max3100_work()
249 s->conf_commit = 0; in max3100_work()
250 cloopback = s->loopback_commit; in max3100_work()
251 s->loopback_commit = 0; in max3100_work()
252 crts = s->rts_commit; in max3100_work()
253 s->rts_commit = 0; in max3100_work()
254 spin_unlock(&s->conf_lock); in max3100_work()
256 max3100_sr(s, MAX3100_WC | conf, &rx); in max3100_work()
258 max3100_sr(s, 0x4001, &rx); in max3100_work()
260 max3100_sr(s, MAX3100_WD | MAX3100_TE | in max3100_work()
261 (s->rts ? MAX3100_RTS : 0), &rx); in max3100_work()
262 rxchars += max3100_handlerx(s, rx); in max3100_work()
265 max3100_sr(s, MAX3100_RD, &rx); in max3100_work()
266 rxchars += max3100_handlerx(s, rx); in max3100_work()
270 if (s->port.x_char) { in max3100_work()
271 tx = s->port.x_char; in max3100_work()
272 s->port.icount.tx++; in max3100_work()
273 s->port.x_char = 0; in max3100_work()
274 } else if (!uart_tx_stopped(&s->port) && in max3100_work()
275 uart_fifo_get(&s->port, &ch)) { in max3100_work()
279 max3100_calc_parity(s, &tx); in max3100_work()
280 tx |= MAX3100_WD | (s->rts ? MAX3100_RTS : 0); in max3100_work()
281 max3100_sr(s, tx, &rx); in max3100_work()
282 rxchars += max3100_handlerx(s, rx); in max3100_work()
287 tty_flip_buffer_push(&s->port.state->port); in max3100_work()
290 if (kfifo_len(&tport->xmit_fifo) < WAKEUP_CHARS) in max3100_work()
291 uart_write_wakeup(&s->port); in max3100_work()
293 } while (!s->force_end_work && in max3100_work()
296 (!kfifo_is_empty(&tport->xmit_fifo) && in max3100_work()
297 !uart_tx_stopped(&s->port)))); in max3100_work()
300 tty_flip_buffer_push(&s->port.state->port); in max3100_work()
303 static void max3100_dowork(struct max3100_port *s) in max3100_dowork() argument
305 if (!s->force_end_work && !freezing(current) && !s->suspending) in max3100_dowork()
306 queue_work(s->workqueue, &s->work); in max3100_dowork()
311 struct max3100_port *s = from_timer(s, t, timer); in max3100_timeout() local
313 max3100_dowork(s); in max3100_timeout()
314 mod_timer(&s->timer, jiffies + uart_poll_timeout(&s->port)); in max3100_timeout()
319 struct max3100_port *s = dev_id; in max3100_irq() local
321 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_irq()
323 max3100_dowork(s); in max3100_irq()
329 struct max3100_port *s = to_max3100_port(port); in max3100_enable_ms() local
331 mod_timer(&s->timer, jiffies); in max3100_enable_ms()
332 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_enable_ms()
337 struct max3100_port *s = to_max3100_port(port); in max3100_start_tx() local
339 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_start_tx()
341 max3100_dowork(s); in max3100_start_tx()
346 struct max3100_port *s = to_max3100_port(port); in max3100_stop_rx() local
348 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_stop_rx()
350 s->rx_enabled = 0; in max3100_stop_rx()
351 spin_lock(&s->conf_lock); in max3100_stop_rx()
352 s->conf &= ~MAX3100_RM; in max3100_stop_rx()
353 s->conf_commit = 1; in max3100_stop_rx()
354 spin_unlock(&s->conf_lock); in max3100_stop_rx()
355 max3100_dowork(s); in max3100_stop_rx()
360 struct max3100_port *s = to_max3100_port(port); in max3100_tx_empty() local
362 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_tx_empty()
364 /* may not be truly up-to-date */ in max3100_tx_empty()
365 max3100_dowork(s); in max3100_tx_empty()
366 return s->tx_empty; in max3100_tx_empty()
371 struct max3100_port *s = to_max3100_port(port); in max3100_get_mctrl() local
373 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_get_mctrl()
375 /* may not be truly up-to-date */ in max3100_get_mctrl()
376 max3100_dowork(s); in max3100_get_mctrl()
378 return (s->cts ? TIOCM_CTS : 0) | TIOCM_DSR | TIOCM_CAR; in max3100_get_mctrl()
383 struct max3100_port *s = to_max3100_port(port); in max3100_set_mctrl() local
386 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_set_mctrl()
391 spin_lock(&s->conf_lock); in max3100_set_mctrl()
392 if (s->loopback != loopback) { in max3100_set_mctrl()
393 s->loopback = loopback; in max3100_set_mctrl()
394 s->loopback_commit = 1; in max3100_set_mctrl()
396 if (s->rts != rts) { in max3100_set_mctrl()
397 s->rts = rts; in max3100_set_mctrl()
398 s->rts_commit = 1; in max3100_set_mctrl()
400 if (s->loopback_commit || s->rts_commit) in max3100_set_mctrl()
401 max3100_dowork(s); in max3100_set_mctrl()
402 spin_unlock(&s->conf_lock); in max3100_set_mctrl()
409 struct max3100_port *s = to_max3100_port(port); in max3100_set_termios() local
410 unsigned int baud = port->uartclk / 16; in max3100_set_termios()
415 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_set_termios()
417 cflag = termios->c_cflag; in max3100_set_termios()
421 param_new = s->conf & MAX3100_BAUD; in max3100_set_termios()
425 baud = s->baud; in max3100_set_termios()
460 baud = s->baud; in max3100_set_termios()
463 baud = s->baud; in max3100_set_termios()
466 s->baud = baud; in max3100_set_termios()
501 termios->c_cflag = cflag; in max3100_set_termios()
503 s->port.ignore_status_mask = 0; in max3100_set_termios()
504 if (termios->c_iflag & IGNPAR) in max3100_set_termios()
505 s->port.ignore_status_mask |= in max3100_set_termios()
509 del_timer_sync(&s->timer); in max3100_set_termios()
510 uart_update_timeout(port, termios->c_cflag, baud); in max3100_set_termios()
512 spin_lock(&s->conf_lock); in max3100_set_termios()
513 s->conf = (s->conf & ~param_mask) | (param_new & param_mask); in max3100_set_termios()
514 s->conf_commit = 1; in max3100_set_termios()
515 s->parity = parity; in max3100_set_termios()
516 spin_unlock(&s->conf_lock); in max3100_set_termios()
517 max3100_dowork(s); in max3100_set_termios()
519 if (UART_ENABLE_MS(&s->port, termios->c_cflag)) in max3100_set_termios()
520 max3100_enable_ms(&s->port); in max3100_set_termios()
525 struct max3100_port *s = to_max3100_port(port); in max3100_shutdown() local
528 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_shutdown()
530 if (s->suspending) in max3100_shutdown()
533 s->force_end_work = 1; in max3100_shutdown()
535 del_timer_sync(&s->timer); in max3100_shutdown()
537 if (s->workqueue) { in max3100_shutdown()
538 destroy_workqueue(s->workqueue); in max3100_shutdown()
539 s->workqueue = NULL; in max3100_shutdown()
541 if (port->irq) in max3100_shutdown()
542 free_irq(port->irq, s); in max3100_shutdown()
545 max3100_sr(s, MAX3100_WC | MAX3100_SHDN, &rx); in max3100_shutdown()
550 struct max3100_port *s = to_max3100_port(port); in max3100_startup() local
554 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_startup()
556 s->conf = MAX3100_RM; in max3100_startup()
557 s->baud = port->uartclk / 16; in max3100_startup()
558 s->rx_enabled = 1; in max3100_startup()
560 if (s->suspending) in max3100_startup()
563 s->force_end_work = 0; in max3100_startup()
564 s->parity = 0; in max3100_startup()
565 s->rts = 0; in max3100_startup()
567 sprintf(b, "max3100-%d", s->minor); in max3100_startup()
568 s->workqueue = create_freezable_workqueue(b); in max3100_startup()
569 if (!s->workqueue) { in max3100_startup()
570 dev_warn(&s->spi->dev, "cannot create workqueue\n"); in max3100_startup()
571 return -EBUSY; in max3100_startup()
573 INIT_WORK(&s->work, max3100_work); in max3100_startup()
575 ret = request_irq(port->irq, max3100_irq, IRQF_TRIGGER_FALLING, "max3100", s); in max3100_startup()
577 dev_warn(&s->spi->dev, "cannot allocate irq %d\n", port->irq); in max3100_startup()
578 port->irq = 0; in max3100_startup()
579 destroy_workqueue(s->workqueue); in max3100_startup()
580 s->workqueue = NULL; in max3100_startup()
581 return -EBUSY; in max3100_startup()
584 s->conf_commit = 1; in max3100_startup()
585 max3100_dowork(s); in max3100_startup()
589 max3100_enable_ms(&s->port); in max3100_startup()
596 struct max3100_port *s = to_max3100_port(port); in max3100_type() local
598 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_type()
600 return s->port.type == PORT_MAX3100 ? "MAX3100" : NULL; in max3100_type()
605 struct max3100_port *s = to_max3100_port(port); in max3100_release_port() local
607 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_release_port()
612 struct max3100_port *s = to_max3100_port(port); in max3100_config_port() local
614 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_config_port()
617 s->port.type = PORT_MAX3100; in max3100_config_port()
623 struct max3100_port *s = to_max3100_port(port); in max3100_verify_port() local
624 int ret = -EINVAL; in max3100_verify_port()
626 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_verify_port()
628 if (ser->type == PORT_UNKNOWN || ser->type == PORT_MAX3100) in max3100_verify_port()
635 struct max3100_port *s = to_max3100_port(port); in max3100_stop_tx() local
637 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_stop_tx()
642 struct max3100_port *s = to_max3100_port(port); in max3100_request_port() local
644 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_request_port()
650 struct max3100_port *s = to_max3100_port(port); in max3100_break_ctl() local
652 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_break_ctl()
686 struct device *dev = &spi->dev; in max3100_probe()
707 return dev_err_probe(dev, -ENOMEM, "too many MAX3100 chips\n"); in max3100_probe()
713 return -ENOMEM; in max3100_probe()
715 max3100s[i]->spi = spi; in max3100_probe()
716 spin_lock_init(&max3100s[i]->conf_lock); in max3100_probe()
718 max3100s[i]->minor = i; in max3100_probe()
719 timer_setup(&max3100s[i]->timer, max3100_timeout, 0); in max3100_probe()
721 dev_dbg(&spi->dev, "%s: adding port %d\n", __func__, i); in max3100_probe()
722 max3100s[i]->port.irq = spi->irq; in max3100_probe()
723 max3100s[i]->port.fifosize = 16; in max3100_probe()
724 max3100s[i]->port.ops = &max3100_ops; in max3100_probe()
725 max3100s[i]->port.flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF; in max3100_probe()
726 max3100s[i]->port.line = i; in max3100_probe()
727 max3100s[i]->port.type = PORT_MAX3100; in max3100_probe()
728 max3100s[i]->port.dev = &spi->dev; in max3100_probe()
730 /* Read clock frequency from a property, uart_add_one_port() will fail if it's not set */ in max3100_probe()
731 device_property_read_u32(dev, "clock-frequency", &max3100s[i]->port.uartclk); in max3100_probe()
733 retval = uart_add_one_port(&max3100_uart_driver, &max3100s[i]->port); in max3100_probe()
737 /* set shutdown mode to save power. Will be woken-up on open */ in max3100_probe()
745 struct max3100_port *s = spi_get_drvdata(spi); in max3100_remove() local
752 if (max3100s[i] == s) { in max3100_remove()
753 dev_dbg(&spi->dev, "%s: removing port %d\n", __func__, i); in max3100_remove()
754 uart_remove_one_port(&max3100_uart_driver, &max3100s[i]->port); in max3100_remove()
777 struct max3100_port *s = dev_get_drvdata(dev); in max3100_suspend() local
780 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_suspend()
782 disable_irq(s->port.irq); in max3100_suspend()
784 s->suspending = 1; in max3100_suspend()
785 uart_suspend_port(&max3100_uart_driver, &s->port); in max3100_suspend()
788 max3100_sr(s, MAX3100_WC | MAX3100_SHDN, &rx); in max3100_suspend()
794 struct max3100_port *s = dev_get_drvdata(dev); in max3100_resume() local
796 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_resume()
798 uart_resume_port(&max3100_uart_driver, &s->port); in max3100_resume()
799 s->suspending = 0; in max3100_resume()
801 enable_irq(s->port.irq); in max3100_resume()
803 s->conf_commit = 1; in max3100_resume()
804 if (s->workqueue) in max3100_resume()
805 max3100_dowork(s); in max3100_resume()