Lines Matching +full:s +full:-
1 // SPDX-License-Identifier: GPL-2.0+
10 * The initial minor number is 209 in the low-density serial port:
89 * (bits 0-7, bits 8-11 are irqs) */
123 static int max3100_do_parity(struct max3100_port *s, u16 c) in max3100_do_parity() argument
127 if (s->parity & MAX3100_PARITY_ODD) in max3100_do_parity()
132 if (s->parity & MAX3100_7BIT) in max3100_do_parity()
141 static int max3100_check_parity(struct max3100_port *s, u16 c) in max3100_check_parity() argument
143 return max3100_do_parity(s, c) == ((c >> 8) & 1); in max3100_check_parity()
146 static void max3100_calc_parity(struct max3100_port *s, u16 *c) in max3100_calc_parity() argument
148 if (s->parity & MAX3100_7BIT) in max3100_calc_parity()
153 if (s->parity & MAX3100_PARITY_ON) in max3100_calc_parity()
154 *c |= max3100_do_parity(s, *c) << 8; in max3100_calc_parity()
157 static int max3100_sr(struct max3100_port *s, u16 tx, u16 *rx) in max3100_sr() argument
171 status = spi_sync(s->spi, &message); in max3100_sr()
173 dev_warn(&s->spi->dev, "error while calling spi_sync\n"); in max3100_sr()
174 return -EIO; in max3100_sr()
177 s->tx_empty = (*rx & MAX3100_T) > 0; in max3100_sr()
178 dev_dbg(&s->spi->dev, "%04x - %04x\n", tx, *rx); in max3100_sr()
182 static int max3100_handlerx_unlocked(struct max3100_port *s, u16 rx) in max3100_handlerx_unlocked() argument
188 if (rx & MAX3100_R && s->rx_enabled) { in max3100_handlerx_unlocked()
189 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_handlerx_unlocked()
190 ch = rx & (s->parity & MAX3100_7BIT ? 0x7f : 0xff); in max3100_handlerx_unlocked()
192 s->port.icount.frame++; in max3100_handlerx_unlocked()
196 if (s->parity & MAX3100_PARITY_ON) { in max3100_handlerx_unlocked()
197 if (max3100_check_parity(s, rx)) { in max3100_handlerx_unlocked()
198 s->port.icount.rx++; in max3100_handlerx_unlocked()
201 s->port.icount.parity++; in max3100_handlerx_unlocked()
206 s->port.icount.rx++; in max3100_handlerx_unlocked()
210 uart_insert_char(&s->port, status, MAX3100_STATUS_OE, ch, flg); in max3100_handlerx_unlocked()
215 if (s->cts != cts) { in max3100_handlerx_unlocked()
216 s->cts = cts; in max3100_handlerx_unlocked()
217 uart_handle_cts_change(&s->port, cts); in max3100_handlerx_unlocked()
223 static int max3100_handlerx(struct max3100_port *s, u16 rx) in max3100_handlerx() argument
228 uart_port_lock_irqsave(&s->port, &flags); in max3100_handlerx()
229 ret = max3100_handlerx_unlocked(s, rx); in max3100_handlerx()
230 uart_port_unlock_irqrestore(&s->port, flags); in max3100_handlerx()
236 struct max3100_port *s = container_of(w, struct max3100_port, work); in max3100_work() local
237 struct tty_port *tport = &s->port.state->port; in max3100_work()
243 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_work()
247 spin_lock(&s->conf_lock); in max3100_work()
248 conf = s->conf; in max3100_work()
249 cconf = s->conf_commit; in max3100_work()
250 s->conf_commit = 0; in max3100_work()
251 cloopback = s->loopback_commit; in max3100_work()
252 s->loopback_commit = 0; in max3100_work()
253 crts = s->rts_commit; in max3100_work()
254 s->rts_commit = 0; in max3100_work()
255 spin_unlock(&s->conf_lock); in max3100_work()
257 max3100_sr(s, MAX3100_WC | conf, &rx); in max3100_work()
259 max3100_sr(s, 0x4001, &rx); in max3100_work()
261 max3100_sr(s, MAX3100_WD | MAX3100_TE | in max3100_work()
262 (s->rts ? MAX3100_RTS : 0), &rx); in max3100_work()
263 rxchars += max3100_handlerx(s, rx); in max3100_work()
266 max3100_sr(s, MAX3100_RD, &rx); in max3100_work()
267 rxchars += max3100_handlerx(s, rx); in max3100_work()
271 if (s->port.x_char) { in max3100_work()
272 tx = s->port.x_char; in max3100_work()
273 s->port.icount.tx++; in max3100_work()
274 s->port.x_char = 0; in max3100_work()
275 } else if (!uart_tx_stopped(&s->port) && in max3100_work()
276 uart_fifo_get(&s->port, &ch)) { in max3100_work()
280 max3100_calc_parity(s, &tx); in max3100_work()
281 tx |= MAX3100_WD | (s->rts ? MAX3100_RTS : 0); in max3100_work()
282 max3100_sr(s, tx, &rx); in max3100_work()
283 rxchars += max3100_handlerx(s, rx); in max3100_work()
288 tty_flip_buffer_push(&s->port.state->port); in max3100_work()
291 if (kfifo_len(&tport->xmit_fifo) < WAKEUP_CHARS) in max3100_work()
292 uart_write_wakeup(&s->port); in max3100_work()
294 } while (!s->force_end_work && in max3100_work()
297 (!kfifo_is_empty(&tport->xmit_fifo) && in max3100_work()
298 !uart_tx_stopped(&s->port)))); in max3100_work()
301 tty_flip_buffer_push(&s->port.state->port); in max3100_work()
304 static void max3100_dowork(struct max3100_port *s) in max3100_dowork() argument
306 if (!s->force_end_work && !freezing(current) && !s->suspending) in max3100_dowork()
307 queue_work(s->workqueue, &s->work); in max3100_dowork()
312 struct max3100_port *s = timer_container_of(s, t, timer); in max3100_timeout() local
314 max3100_dowork(s); in max3100_timeout()
315 mod_timer(&s->timer, jiffies + uart_poll_timeout(&s->port)); in max3100_timeout()
320 struct max3100_port *s = dev_id; in max3100_irq() local
322 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_irq()
324 max3100_dowork(s); in max3100_irq()
330 struct max3100_port *s = to_max3100_port(port); in max3100_enable_ms() local
332 mod_timer(&s->timer, jiffies); in max3100_enable_ms()
333 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_enable_ms()
338 struct max3100_port *s = to_max3100_port(port); in max3100_start_tx() local
340 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_start_tx()
342 max3100_dowork(s); in max3100_start_tx()
347 struct max3100_port *s = to_max3100_port(port); in max3100_stop_rx() local
349 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_stop_rx()
351 s->rx_enabled = 0; in max3100_stop_rx()
352 spin_lock(&s->conf_lock); in max3100_stop_rx()
353 s->conf &= ~MAX3100_RM; in max3100_stop_rx()
354 s->conf_commit = 1; in max3100_stop_rx()
355 spin_unlock(&s->conf_lock); in max3100_stop_rx()
356 max3100_dowork(s); in max3100_stop_rx()
361 struct max3100_port *s = to_max3100_port(port); in max3100_tx_empty() local
363 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_tx_empty()
365 /* may not be truly up-to-date */ in max3100_tx_empty()
366 max3100_dowork(s); in max3100_tx_empty()
367 return s->tx_empty; in max3100_tx_empty()
372 struct max3100_port *s = to_max3100_port(port); in max3100_get_mctrl() local
374 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_get_mctrl()
376 /* may not be truly up-to-date */ in max3100_get_mctrl()
377 max3100_dowork(s); in max3100_get_mctrl()
379 return (s->cts ? TIOCM_CTS : 0) | TIOCM_DSR | TIOCM_CAR; in max3100_get_mctrl()
384 struct max3100_port *s = to_max3100_port(port); in max3100_set_mctrl() local
387 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_set_mctrl()
392 spin_lock(&s->conf_lock); in max3100_set_mctrl()
393 if (s->loopback != loopback) { in max3100_set_mctrl()
394 s->loopback = loopback; in max3100_set_mctrl()
395 s->loopback_commit = 1; in max3100_set_mctrl()
397 if (s->rts != rts) { in max3100_set_mctrl()
398 s->rts = rts; in max3100_set_mctrl()
399 s->rts_commit = 1; in max3100_set_mctrl()
401 if (s->loopback_commit || s->rts_commit) in max3100_set_mctrl()
402 max3100_dowork(s); in max3100_set_mctrl()
403 spin_unlock(&s->conf_lock); in max3100_set_mctrl()
410 struct max3100_port *s = to_max3100_port(port); in max3100_set_termios() local
411 unsigned int baud = port->uartclk / 16; in max3100_set_termios()
416 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_set_termios()
418 cflag = termios->c_cflag; in max3100_set_termios()
422 param_new = s->conf & MAX3100_BAUD; in max3100_set_termios()
426 baud = s->baud; in max3100_set_termios()
461 baud = s->baud; in max3100_set_termios()
464 baud = s->baud; in max3100_set_termios()
467 s->baud = baud; in max3100_set_termios()
502 termios->c_cflag = cflag; in max3100_set_termios()
504 s->port.ignore_status_mask = 0; in max3100_set_termios()
505 if (termios->c_iflag & IGNPAR) in max3100_set_termios()
506 s->port.ignore_status_mask |= in max3100_set_termios()
510 timer_delete_sync(&s->timer); in max3100_set_termios()
511 uart_update_timeout(port, termios->c_cflag, baud); in max3100_set_termios()
513 spin_lock(&s->conf_lock); in max3100_set_termios()
514 s->conf = (s->conf & ~param_mask) | (param_new & param_mask); in max3100_set_termios()
515 s->conf_commit = 1; in max3100_set_termios()
516 s->parity = parity; in max3100_set_termios()
517 spin_unlock(&s->conf_lock); in max3100_set_termios()
518 max3100_dowork(s); in max3100_set_termios()
520 if (UART_ENABLE_MS(&s->port, termios->c_cflag)) in max3100_set_termios()
521 max3100_enable_ms(&s->port); in max3100_set_termios()
526 struct max3100_port *s = to_max3100_port(port); in max3100_shutdown() local
529 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_shutdown()
531 if (s->suspending) in max3100_shutdown()
534 s->force_end_work = 1; in max3100_shutdown()
536 timer_delete_sync(&s->timer); in max3100_shutdown()
538 if (s->workqueue) { in max3100_shutdown()
539 destroy_workqueue(s->workqueue); in max3100_shutdown()
540 s->workqueue = NULL; in max3100_shutdown()
542 if (port->irq) in max3100_shutdown()
543 free_irq(port->irq, s); in max3100_shutdown()
546 max3100_sr(s, MAX3100_WC | MAX3100_SHDN, &rx); in max3100_shutdown()
551 struct max3100_port *s = to_max3100_port(port); in max3100_startup() local
555 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_startup()
557 s->conf = MAX3100_RM; in max3100_startup()
558 s->baud = port->uartclk / 16; in max3100_startup()
559 s->rx_enabled = 1; in max3100_startup()
561 if (s->suspending) in max3100_startup()
564 s->force_end_work = 0; in max3100_startup()
565 s->parity = 0; in max3100_startup()
566 s->rts = 0; in max3100_startup()
568 sprintf(b, "max3100-%d", s->minor); in max3100_startup()
569 s->workqueue = create_freezable_workqueue(b); in max3100_startup()
570 if (!s->workqueue) { in max3100_startup()
571 dev_warn(&s->spi->dev, "cannot create workqueue\n"); in max3100_startup()
572 return -EBUSY; in max3100_startup()
574 INIT_WORK(&s->work, max3100_work); in max3100_startup()
576 ret = request_irq(port->irq, max3100_irq, IRQF_TRIGGER_FALLING, "max3100", s); in max3100_startup()
578 dev_warn(&s->spi->dev, "cannot allocate irq %d\n", port->irq); in max3100_startup()
579 port->irq = 0; in max3100_startup()
580 destroy_workqueue(s->workqueue); in max3100_startup()
581 s->workqueue = NULL; in max3100_startup()
582 return -EBUSY; in max3100_startup()
585 s->conf_commit = 1; in max3100_startup()
586 max3100_dowork(s); in max3100_startup()
590 max3100_enable_ms(&s->port); in max3100_startup()
597 struct max3100_port *s = to_max3100_port(port); in max3100_type() local
599 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_type()
601 return s->port.type == PORT_MAX3100 ? "MAX3100" : NULL; in max3100_type()
606 struct max3100_port *s = to_max3100_port(port); in max3100_release_port() local
608 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_release_port()
613 struct max3100_port *s = to_max3100_port(port); in max3100_config_port() local
615 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_config_port()
618 s->port.type = PORT_MAX3100; in max3100_config_port()
624 struct max3100_port *s = to_max3100_port(port); in max3100_verify_port() local
625 int ret = -EINVAL; in max3100_verify_port()
627 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_verify_port()
629 if (ser->type == PORT_UNKNOWN || ser->type == PORT_MAX3100) in max3100_verify_port()
636 struct max3100_port *s = to_max3100_port(port); in max3100_stop_tx() local
638 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_stop_tx()
643 struct max3100_port *s = to_max3100_port(port); in max3100_request_port() local
645 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_request_port()
651 struct max3100_port *s = to_max3100_port(port); in max3100_break_ctl() local
653 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_break_ctl()
687 struct device *dev = &spi->dev; in max3100_probe()
708 return dev_err_probe(dev, -ENOMEM, "too many MAX3100 chips\n"); in max3100_probe()
714 return -ENOMEM; in max3100_probe()
716 max3100s[i]->spi = spi; in max3100_probe()
717 spin_lock_init(&max3100s[i]->conf_lock); in max3100_probe()
719 max3100s[i]->minor = i; in max3100_probe()
720 timer_setup(&max3100s[i]->timer, max3100_timeout, 0); in max3100_probe()
722 dev_dbg(&spi->dev, "%s: adding port %d\n", __func__, i); in max3100_probe()
723 max3100s[i]->port.irq = spi->irq; in max3100_probe()
724 max3100s[i]->port.fifosize = 16; in max3100_probe()
725 max3100s[i]->port.ops = &max3100_ops; in max3100_probe()
726 max3100s[i]->port.flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF; in max3100_probe()
727 max3100s[i]->port.line = i; in max3100_probe()
728 max3100s[i]->port.type = PORT_MAX3100; in max3100_probe()
729 max3100s[i]->port.dev = &spi->dev; in max3100_probe()
731 /* Read clock frequency from a property, uart_add_one_port() will fail if it's not set */ in max3100_probe()
732 device_property_read_u32(dev, "clock-frequency", &max3100s[i]->port.uartclk); in max3100_probe()
734 retval = uart_add_one_port(&max3100_uart_driver, &max3100s[i]->port); in max3100_probe()
738 /* set shutdown mode to save power. Will be woken-up on open */ in max3100_probe()
746 struct max3100_port *s = spi_get_drvdata(spi); in max3100_remove() local
753 if (max3100s[i] == s) { in max3100_remove()
754 dev_dbg(&spi->dev, "%s: removing port %d\n", __func__, i); in max3100_remove()
755 uart_remove_one_port(&max3100_uart_driver, &max3100s[i]->port); in max3100_remove()
778 struct max3100_port *s = dev_get_drvdata(dev); in max3100_suspend() local
781 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_suspend()
783 disable_irq(s->port.irq); in max3100_suspend()
785 s->suspending = 1; in max3100_suspend()
786 uart_suspend_port(&max3100_uart_driver, &s->port); in max3100_suspend()
789 max3100_sr(s, MAX3100_WC | MAX3100_SHDN, &rx); in max3100_suspend()
795 struct max3100_port *s = dev_get_drvdata(dev); in max3100_resume() local
797 dev_dbg(&s->spi->dev, "%s\n", __func__); in max3100_resume()
799 uart_resume_port(&max3100_uart_driver, &s->port); in max3100_resume()
800 s->suspending = 0; in max3100_resume()
802 enable_irq(s->port.irq); in max3100_resume()
804 s->conf_commit = 1; in max3100_resume()
805 if (s->workqueue) in max3100_resume()
806 max3100_dowork(s); in max3100_resume()