Lines Matching full:ssp
218 * @ssp: pointer to a struct sifive_serial_port record
221 * IP block base, given a pointer @ssp to a struct sifive_serial_port record.
225 static void __ssp_writel(u32 v, u16 offs, struct sifive_serial_port *ssp) in __ssp_writel() argument
227 __ssp_early_writel(v, offs, &ssp->port); in __ssp_writel()
232 * @ssp: pointer to a struct sifive_serial_port record
236 * IP block base, given a pointer @ssp to a struct sifive_serial_port record.
242 static u32 __ssp_readl(struct sifive_serial_port *ssp, u16 offs) in __ssp_readl() argument
244 return __ssp_early_readl(&ssp->port, offs); in __ssp_readl()
249 * @ssp: pointer to a struct sifive_serial_port
258 static int sifive_serial_is_txfifo_full(struct sifive_serial_port *ssp) in sifive_serial_is_txfifo_full() argument
260 return __ssp_readl(ssp, SIFIVE_SERIAL_TXDATA_OFFS) & in sifive_serial_is_txfifo_full()
266 * @ssp: pointer to a struct sifive_serial_port
269 * Enqueue a byte @ch onto the transmit FIFO, given a pointer @ssp to the
275 static void __ssp_transmit_char(struct sifive_serial_port *ssp, int ch) in __ssp_transmit_char() argument
277 __ssp_writel(ch, SIFIVE_SERIAL_TXDATA_OFFS, ssp); in __ssp_transmit_char()
282 * @ssp: pointer to a struct sifive_serial_port
287 * Context: Any context. Expects @ssp->port.lock to be held by caller.
289 static void __ssp_transmit_chars(struct sifive_serial_port *ssp) in __ssp_transmit_chars() argument
293 uart_port_tx_limited(&ssp->port, ch, SIFIVE_TX_FIFO_DEPTH, in __ssp_transmit_chars()
295 __ssp_transmit_char(ssp, ch), in __ssp_transmit_chars()
301 * @ssp: pointer to a struct sifive_serial_port
304 * on the SiFive UART referred to by @ssp.
306 static void __ssp_enable_txwm(struct sifive_serial_port *ssp) in __ssp_enable_txwm() argument
308 if (ssp->ier & SIFIVE_SERIAL_IE_TXWM_MASK) in __ssp_enable_txwm()
311 ssp->ier |= SIFIVE_SERIAL_IE_TXWM_MASK; in __ssp_enable_txwm()
312 __ssp_writel(ssp->ier, SIFIVE_SERIAL_IE_OFFS, ssp); in __ssp_enable_txwm()
317 * @ssp: pointer to a struct sifive_serial_port
320 * on the SiFive UART referred to by @ssp.
322 static void __ssp_enable_rxwm(struct sifive_serial_port *ssp) in __ssp_enable_rxwm() argument
324 if (ssp->ier & SIFIVE_SERIAL_IE_RXWM_MASK) in __ssp_enable_rxwm()
327 ssp->ier |= SIFIVE_SERIAL_IE_RXWM_MASK; in __ssp_enable_rxwm()
328 __ssp_writel(ssp->ier, SIFIVE_SERIAL_IE_OFFS, ssp); in __ssp_enable_rxwm()
333 * @ssp: pointer to a struct sifive_serial_port
336 * on the UART referred to by @ssp.
338 static void __ssp_disable_txwm(struct sifive_serial_port *ssp) in __ssp_disable_txwm() argument
340 if (!(ssp->ier & SIFIVE_SERIAL_IE_TXWM_MASK)) in __ssp_disable_txwm()
343 ssp->ier &= ~SIFIVE_SERIAL_IE_TXWM_MASK; in __ssp_disable_txwm()
344 __ssp_writel(ssp->ier, SIFIVE_SERIAL_IE_OFFS, ssp); in __ssp_disable_txwm()
349 * @ssp: pointer to a struct sifive_serial_port
352 * on the UART referred to by @ssp.
354 static void __ssp_disable_rxwm(struct sifive_serial_port *ssp) in __ssp_disable_rxwm() argument
356 if (!(ssp->ier & SIFIVE_SERIAL_IE_RXWM_MASK)) in __ssp_disable_rxwm()
359 ssp->ier &= ~SIFIVE_SERIAL_IE_RXWM_MASK; in __ssp_disable_rxwm()
360 __ssp_writel(ssp->ier, SIFIVE_SERIAL_IE_OFFS, ssp); in __ssp_disable_rxwm()
365 * @ssp: pointer to a struct sifive_serial_port
369 * @ssp, and to return it. Also returns the RX FIFO empty bit in
375 static char __ssp_receive_char(struct sifive_serial_port *ssp, char *is_empty) in __ssp_receive_char() argument
380 v = __ssp_readl(ssp, SIFIVE_SERIAL_RXDATA_OFFS); in __ssp_receive_char()
396 * @ssp: pointer to a struct sifive_serial_port
399 * to by @ssp and pass them up to the Linux serial layer.
401 * Context: Expects ssp->port.lock to be held by caller.
403 static void __ssp_receive_chars(struct sifive_serial_port *ssp) in __ssp_receive_chars() argument
410 ch = __ssp_receive_char(ssp, &is_empty); in __ssp_receive_chars()
414 ssp->port.icount.rx++; in __ssp_receive_chars()
415 if (!uart_prepare_sysrq_char(&ssp->port, ch)) in __ssp_receive_chars()
416 uart_insert_char(&ssp->port, 0, 0, ch, TTY_NORMAL); in __ssp_receive_chars()
419 tty_flip_buffer_push(&ssp->port.state->port); in __ssp_receive_chars()
424 * @ssp: pointer to a struct sifive_serial_port
427 * and target line rate referred to by @ssp and write it into the
430 static void __ssp_update_div(struct sifive_serial_port *ssp) in __ssp_update_div() argument
434 div = DIV_ROUND_UP(ssp->port.uartclk, ssp->baud_rate) - 1; in __ssp_update_div()
436 __ssp_writel(div, SIFIVE_SERIAL_DIV_OFFS, ssp); in __ssp_update_div()
441 * @ssp: pointer to a struct sifive_serial_port
445 * SiFive UART described by @ssp and program it into the UART. There may
449 static void __ssp_update_baud_rate(struct sifive_serial_port *ssp, in __ssp_update_baud_rate() argument
452 if (ssp->baud_rate == rate) in __ssp_update_baud_rate()
455 ssp->baud_rate = rate; in __ssp_update_baud_rate()
456 __ssp_update_div(ssp); in __ssp_update_baud_rate()
461 * @ssp: pointer to a struct sifive_serial_port
464 * Program the SiFive UART referred to by @ssp to use @nstop stop bits.
466 static void __ssp_set_stop_bits(struct sifive_serial_port *ssp, char nstop) in __ssp_set_stop_bits() argument
475 v = __ssp_readl(ssp, SIFIVE_SERIAL_TXCTRL_OFFS); in __ssp_set_stop_bits()
478 __ssp_writel(v, SIFIVE_SERIAL_TXCTRL_OFFS, ssp); in __ssp_set_stop_bits()
483 * @ssp: pointer to a struct sifive_serial_port
485 * Delay while the UART TX FIFO referred to by @ssp is marked as full.
489 static void __maybe_unused __ssp_wait_for_xmitr(struct sifive_serial_port *ssp) in __ssp_wait_for_xmitr() argument
491 while (sifive_serial_is_txfifo_full(ssp)) in __ssp_wait_for_xmitr()
501 struct sifive_serial_port *ssp = port_to_sifive_serial_port(port); in sifive_serial_stop_tx() local
503 __ssp_disable_txwm(ssp); in sifive_serial_stop_tx()
508 struct sifive_serial_port *ssp = port_to_sifive_serial_port(port); in sifive_serial_stop_rx() local
510 __ssp_disable_rxwm(ssp); in sifive_serial_stop_rx()
515 struct sifive_serial_port *ssp = port_to_sifive_serial_port(port); in sifive_serial_start_tx() local
517 __ssp_enable_txwm(ssp); in sifive_serial_start_tx()
522 struct sifive_serial_port *ssp = dev_id; in sifive_serial_irq() local
525 uart_port_lock(&ssp->port); in sifive_serial_irq()
527 ip = __ssp_readl(ssp, SIFIVE_SERIAL_IP_OFFS); in sifive_serial_irq()
529 uart_port_unlock(&ssp->port); in sifive_serial_irq()
534 __ssp_receive_chars(ssp); in sifive_serial_irq()
536 __ssp_transmit_chars(ssp); in sifive_serial_irq()
538 uart_unlock_and_check_sysrq(&ssp->port); in sifive_serial_irq()
565 struct sifive_serial_port *ssp = port_to_sifive_serial_port(port); in sifive_serial_startup() local
567 __ssp_enable_rxwm(ssp); in sifive_serial_startup()
574 struct sifive_serial_port *ssp = port_to_sifive_serial_port(port); in sifive_serial_shutdown() local
576 __ssp_disable_rxwm(ssp); in sifive_serial_shutdown()
577 __ssp_disable_txwm(ssp); in sifive_serial_shutdown()
597 struct sifive_serial_port *ssp = notifier_to_sifive_serial_port(nb); in sifive_serial_clk_notifier() local
606 __ssp_wait_for_xmitr(ssp); in sifive_serial_clk_notifier()
616 udelay(DIV_ROUND_UP(12 * 1000 * 1000, ssp->baud_rate)); in sifive_serial_clk_notifier()
619 if (event == POST_RATE_CHANGE && ssp->port.uartclk != cnd->new_rate) { in sifive_serial_clk_notifier()
620 ssp->port.uartclk = cnd->new_rate; in sifive_serial_clk_notifier()
621 __ssp_update_div(ssp); in sifive_serial_clk_notifier()
631 struct sifive_serial_port *ssp = port_to_sifive_serial_port(port); in sifive_serial_set_termios() local
638 dev_err_once(ssp->port.dev, "only 8-bit words supported\n"); in sifive_serial_set_termios()
643 dev_err_once(ssp->port.dev, "parity checking not supported\n"); in sifive_serial_set_termios()
645 dev_err_once(ssp->port.dev, "BREAK detection not supported\n"); in sifive_serial_set_termios()
650 __ssp_set_stop_bits(ssp, nstop); in sifive_serial_set_termios()
654 ssp->port.uartclk / 16); in sifive_serial_set_termios()
655 __ssp_update_baud_rate(ssp, rate); in sifive_serial_set_termios()
657 uart_port_lock_irqsave(&ssp->port, &flags); in sifive_serial_set_termios()
662 ssp->port.read_status_mask = 0; in sifive_serial_set_termios()
665 v = __ssp_readl(ssp, SIFIVE_SERIAL_RXCTRL_OFFS); in sifive_serial_set_termios()
672 __ssp_writel(v, SIFIVE_SERIAL_RXCTRL_OFFS, ssp); in sifive_serial_set_termios()
674 uart_port_unlock_irqrestore(&ssp->port, flags); in sifive_serial_set_termios()
688 struct sifive_serial_port *ssp = port_to_sifive_serial_port(port); in sifive_serial_config_port() local
690 ssp->port.type = PORT_SIFIVE_V0; in sifive_serial_config_port()
707 struct sifive_serial_port *ssp = port_to_sifive_serial_port(port); in sifive_serial_poll_get_char() local
710 ch = __ssp_receive_char(ssp, &is_empty); in sifive_serial_poll_get_char()
720 struct sifive_serial_port *ssp = port_to_sifive_serial_port(port); in sifive_serial_poll_put_char() local
722 __ssp_wait_for_xmitr(ssp); in sifive_serial_poll_put_char()
723 __ssp_transmit_char(ssp, c); in sifive_serial_poll_put_char()
778 struct sifive_serial_port *ssp = port_to_sifive_serial_port(port); in sifive_serial_console_putchar() local
780 __ssp_wait_for_xmitr(ssp); in sifive_serial_console_putchar()
781 __ssp_transmit_char(ssp, ch); in sifive_serial_console_putchar()
787 struct sifive_serial_port *ssp = sifive_serial_console_ports[co->index]; in sifive_serial_console_write() local
792 if (!ssp) in sifive_serial_console_write()
796 locked = uart_port_trylock_irqsave(&ssp->port, &flags); in sifive_serial_console_write()
798 uart_port_lock_irqsave(&ssp->port, &flags); in sifive_serial_console_write()
800 ier = __ssp_readl(ssp, SIFIVE_SERIAL_IE_OFFS); in sifive_serial_console_write()
801 __ssp_writel(0, SIFIVE_SERIAL_IE_OFFS, ssp); in sifive_serial_console_write()
803 uart_console_write(&ssp->port, s, count, sifive_serial_console_putchar); in sifive_serial_console_write()
805 __ssp_writel(ier, SIFIVE_SERIAL_IE_OFFS, ssp); in sifive_serial_console_write()
808 uart_port_unlock_irqrestore(&ssp->port, flags); in sifive_serial_console_write()
813 struct sifive_serial_port *ssp; in sifive_serial_console_setup() local
822 ssp = sifive_serial_console_ports[co->index]; in sifive_serial_console_setup()
823 if (!ssp) in sifive_serial_console_setup()
829 return uart_set_options(&ssp->port, co, baud, parity, bits, flow); in sifive_serial_console_setup()
852 static void __ssp_add_console_port(struct sifive_serial_port *ssp) in __ssp_add_console_port() argument
854 sifive_serial_console_ports[ssp->port.line] = ssp; in __ssp_add_console_port()
857 static void __ssp_remove_console_port(struct sifive_serial_port *ssp) in __ssp_remove_console_port() argument
859 sifive_serial_console_ports[ssp->port.line] = NULL; in __ssp_remove_console_port()
868 static void __ssp_add_console_port(struct sifive_serial_port *ssp) in __ssp_add_console_port() argument
870 static void __ssp_remove_console_port(struct sifive_serial_port *ssp) in __ssp_remove_console_port() argument
907 struct sifive_serial_port *ssp; in sifive_serial_probe() local
940 ssp = devm_kzalloc(&pdev->dev, sizeof(*ssp), GFP_KERNEL); in sifive_serial_probe()
941 if (!ssp) in sifive_serial_probe()
944 ssp->port.dev = &pdev->dev; in sifive_serial_probe()
945 ssp->port.type = PORT_SIFIVE_V0; in sifive_serial_probe()
946 ssp->port.iotype = UPIO_MEM; in sifive_serial_probe()
947 ssp->port.irq = irq; in sifive_serial_probe()
948 ssp->port.fifosize = SIFIVE_TX_FIFO_DEPTH; in sifive_serial_probe()
949 ssp->port.ops = &sifive_serial_uops; in sifive_serial_probe()
950 ssp->port.line = id; in sifive_serial_probe()
951 ssp->port.mapbase = mem->start; in sifive_serial_probe()
952 ssp->port.membase = base; in sifive_serial_probe()
953 ssp->dev = &pdev->dev; in sifive_serial_probe()
954 ssp->clk = clk; in sifive_serial_probe()
955 ssp->clk_notifier.notifier_call = sifive_serial_clk_notifier; in sifive_serial_probe()
957 r = clk_notifier_register(ssp->clk, &ssp->clk_notifier); in sifive_serial_probe()
965 ssp->port.uartclk = clk_get_rate(ssp->clk); in sifive_serial_probe()
966 ssp->baud_rate = SIFIVE_DEFAULT_BAUD_RATE; in sifive_serial_probe()
967 __ssp_update_div(ssp); in sifive_serial_probe()
969 platform_set_drvdata(pdev, ssp); in sifive_serial_probe()
974 SIFIVE_SERIAL_TXCTRL_OFFS, ssp); in sifive_serial_probe()
979 SIFIVE_SERIAL_RXCTRL_OFFS, ssp); in sifive_serial_probe()
981 r = request_irq(ssp->port.irq, sifive_serial_irq, ssp->port.irqflags, in sifive_serial_probe()
982 dev_name(&pdev->dev), ssp); in sifive_serial_probe()
988 __ssp_add_console_port(ssp); in sifive_serial_probe()
990 r = uart_add_one_port(&sifive_serial_uart_driver, &ssp->port); in sifive_serial_probe()
999 __ssp_remove_console_port(ssp); in sifive_serial_probe()
1000 free_irq(ssp->port.irq, ssp); in sifive_serial_probe()
1002 clk_notifier_unregister(ssp->clk, &ssp->clk_notifier); in sifive_serial_probe()
1009 struct sifive_serial_port *ssp = platform_get_drvdata(dev); in sifive_serial_remove() local
1011 __ssp_remove_console_port(ssp); in sifive_serial_remove()
1012 uart_remove_one_port(&sifive_serial_uart_driver, &ssp->port); in sifive_serial_remove()
1013 free_irq(ssp->port.irq, ssp); in sifive_serial_remove()
1014 clk_notifier_unregister(ssp->clk, &ssp->clk_notifier); in sifive_serial_remove()
1019 struct sifive_serial_port *ssp = dev_get_drvdata(dev); in sifive_serial_suspend() local
1021 return uart_suspend_port(&sifive_serial_uart_driver, &ssp->port); in sifive_serial_suspend()
1026 struct sifive_serial_port *ssp = dev_get_drvdata(dev); in sifive_serial_resume() local
1028 return uart_resume_port(&sifive_serial_uart_driver, &ssp->port); in sifive_serial_resume()