Lines Matching refs:ssp
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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 uart_insert_char(&ssp->port, 0, 0, ch, TTY_NORMAL); in __ssp_receive_chars()
418 tty_flip_buffer_push(&ssp->port.state->port); in __ssp_receive_chars()
429 static void __ssp_update_div(struct sifive_serial_port *ssp) in __ssp_update_div() argument
433 div = DIV_ROUND_UP(ssp->port.uartclk, ssp->baud_rate) - 1; in __ssp_update_div()
435 __ssp_writel(div, SIFIVE_SERIAL_DIV_OFFS, ssp); in __ssp_update_div()
448 static void __ssp_update_baud_rate(struct sifive_serial_port *ssp, in __ssp_update_baud_rate() argument
451 if (ssp->baud_rate == rate) in __ssp_update_baud_rate()
454 ssp->baud_rate = rate; in __ssp_update_baud_rate()
455 __ssp_update_div(ssp); in __ssp_update_baud_rate()
465 static void __ssp_set_stop_bits(struct sifive_serial_port *ssp, char nstop) in __ssp_set_stop_bits() argument
474 v = __ssp_readl(ssp, SIFIVE_SERIAL_TXCTRL_OFFS); in __ssp_set_stop_bits()
477 __ssp_writel(v, SIFIVE_SERIAL_TXCTRL_OFFS, ssp); in __ssp_set_stop_bits()
488 static void __maybe_unused __ssp_wait_for_xmitr(struct sifive_serial_port *ssp) in __ssp_wait_for_xmitr() argument
490 while (sifive_serial_is_txfifo_full(ssp)) in __ssp_wait_for_xmitr()
500 struct sifive_serial_port *ssp = port_to_sifive_serial_port(port); in sifive_serial_stop_tx() local
502 __ssp_disable_txwm(ssp); in sifive_serial_stop_tx()
507 struct sifive_serial_port *ssp = port_to_sifive_serial_port(port); in sifive_serial_stop_rx() local
509 __ssp_disable_rxwm(ssp); in sifive_serial_stop_rx()
514 struct sifive_serial_port *ssp = port_to_sifive_serial_port(port); in sifive_serial_start_tx() local
516 __ssp_enable_txwm(ssp); in sifive_serial_start_tx()
521 struct sifive_serial_port *ssp = dev_id; in sifive_serial_irq() local
524 spin_lock(&ssp->port.lock); in sifive_serial_irq()
526 ip = __ssp_readl(ssp, SIFIVE_SERIAL_IP_OFFS); in sifive_serial_irq()
528 spin_unlock(&ssp->port.lock); in sifive_serial_irq()
533 __ssp_receive_chars(ssp); in sifive_serial_irq()
535 __ssp_transmit_chars(ssp); in sifive_serial_irq()
537 spin_unlock(&ssp->port.lock); in sifive_serial_irq()
564 struct sifive_serial_port *ssp = port_to_sifive_serial_port(port); in sifive_serial_startup() local
566 __ssp_enable_rxwm(ssp); in sifive_serial_startup()
573 struct sifive_serial_port *ssp = port_to_sifive_serial_port(port); in sifive_serial_shutdown() local
575 __ssp_disable_rxwm(ssp); in sifive_serial_shutdown()
576 __ssp_disable_txwm(ssp); in sifive_serial_shutdown()
596 struct sifive_serial_port *ssp = notifier_to_sifive_serial_port(nb); in sifive_serial_clk_notifier() local
605 __ssp_wait_for_xmitr(ssp); in sifive_serial_clk_notifier()
615 udelay(DIV_ROUND_UP(12 * 1000 * 1000, ssp->baud_rate)); in sifive_serial_clk_notifier()
618 if (event == POST_RATE_CHANGE && ssp->port.uartclk != cnd->new_rate) { in sifive_serial_clk_notifier()
619 ssp->port.uartclk = cnd->new_rate; in sifive_serial_clk_notifier()
620 __ssp_update_div(ssp); in sifive_serial_clk_notifier()
630 struct sifive_serial_port *ssp = port_to_sifive_serial_port(port); in sifive_serial_set_termios() local
637 dev_err_once(ssp->port.dev, "only 8-bit words supported\n"); in sifive_serial_set_termios()
642 dev_err_once(ssp->port.dev, "parity checking not supported\n"); in sifive_serial_set_termios()
644 dev_err_once(ssp->port.dev, "BREAK detection not supported\n"); in sifive_serial_set_termios()
649 __ssp_set_stop_bits(ssp, nstop); in sifive_serial_set_termios()
653 ssp->port.uartclk / 16); in sifive_serial_set_termios()
654 __ssp_update_baud_rate(ssp, rate); in sifive_serial_set_termios()
656 spin_lock_irqsave(&ssp->port.lock, flags); in sifive_serial_set_termios()
661 ssp->port.read_status_mask = 0; in sifive_serial_set_termios()
664 v = __ssp_readl(ssp, SIFIVE_SERIAL_RXCTRL_OFFS); in sifive_serial_set_termios()
671 __ssp_writel(v, SIFIVE_SERIAL_RXCTRL_OFFS, ssp); in sifive_serial_set_termios()
673 spin_unlock_irqrestore(&ssp->port.lock, flags); in sifive_serial_set_termios()
687 struct sifive_serial_port *ssp = port_to_sifive_serial_port(port); in sifive_serial_config_port() local
689 ssp->port.type = PORT_SIFIVE_V0; in sifive_serial_config_port()
706 struct sifive_serial_port *ssp = port_to_sifive_serial_port(port); in sifive_serial_poll_get_char() local
709 ch = __ssp_receive_char(ssp, &is_empty); in sifive_serial_poll_get_char()
719 struct sifive_serial_port *ssp = port_to_sifive_serial_port(port); in sifive_serial_poll_put_char() local
721 __ssp_wait_for_xmitr(ssp); in sifive_serial_poll_put_char()
722 __ssp_transmit_char(ssp, c); in sifive_serial_poll_put_char()
777 struct sifive_serial_port *ssp = port_to_sifive_serial_port(port); in sifive_serial_console_putchar() local
779 __ssp_wait_for_xmitr(ssp); in sifive_serial_console_putchar()
780 __ssp_transmit_char(ssp, ch); in sifive_serial_console_putchar()
786 struct sifive_serial_port *ssp = sifive_serial_console_ports[co->index]; in sifive_serial_console_write() local
791 if (!ssp) in sifive_serial_console_write()
795 if (ssp->port.sysrq) in sifive_serial_console_write()
798 locked = spin_trylock(&ssp->port.lock); in sifive_serial_console_write()
800 spin_lock(&ssp->port.lock); in sifive_serial_console_write()
802 ier = __ssp_readl(ssp, SIFIVE_SERIAL_IE_OFFS); in sifive_serial_console_write()
803 __ssp_writel(0, SIFIVE_SERIAL_IE_OFFS, ssp); in sifive_serial_console_write()
805 uart_console_write(&ssp->port, s, count, sifive_serial_console_putchar); in sifive_serial_console_write()
807 __ssp_writel(ier, SIFIVE_SERIAL_IE_OFFS, ssp); in sifive_serial_console_write()
810 spin_unlock(&ssp->port.lock); in sifive_serial_console_write()
816 struct sifive_serial_port *ssp; in sifive_serial_console_setup() local
825 ssp = sifive_serial_console_ports[co->index]; in sifive_serial_console_setup()
826 if (!ssp) in sifive_serial_console_setup()
832 return uart_set_options(&ssp->port, co, baud, parity, bits, flow); in sifive_serial_console_setup()
855 static void __ssp_add_console_port(struct sifive_serial_port *ssp) in __ssp_add_console_port() argument
857 sifive_serial_console_ports[ssp->port.line] = ssp; in __ssp_add_console_port()
860 static void __ssp_remove_console_port(struct sifive_serial_port *ssp) in __ssp_remove_console_port() argument
862 sifive_serial_console_ports[ssp->port.line] = NULL; in __ssp_remove_console_port()
871 static void __ssp_add_console_port(struct sifive_serial_port *ssp) in __ssp_add_console_port() argument
873 static void __ssp_remove_console_port(struct sifive_serial_port *ssp) in __ssp_remove_console_port() argument
910 struct sifive_serial_port *ssp; in sifive_serial_probe() local
943 ssp = devm_kzalloc(&pdev->dev, sizeof(*ssp), GFP_KERNEL); in sifive_serial_probe()
944 if (!ssp) in sifive_serial_probe()
947 ssp->port.dev = &pdev->dev; in sifive_serial_probe()
948 ssp->port.type = PORT_SIFIVE_V0; in sifive_serial_probe()
949 ssp->port.iotype = UPIO_MEM; in sifive_serial_probe()
950 ssp->port.irq = irq; in sifive_serial_probe()
951 ssp->port.fifosize = SIFIVE_TX_FIFO_DEPTH; in sifive_serial_probe()
952 ssp->port.ops = &sifive_serial_uops; in sifive_serial_probe()
953 ssp->port.line = id; in sifive_serial_probe()
954 ssp->port.mapbase = mem->start; in sifive_serial_probe()
955 ssp->port.membase = base; in sifive_serial_probe()
956 ssp->dev = &pdev->dev; in sifive_serial_probe()
957 ssp->clk = clk; in sifive_serial_probe()
958 ssp->clk_notifier.notifier_call = sifive_serial_clk_notifier; in sifive_serial_probe()
960 r = clk_notifier_register(ssp->clk, &ssp->clk_notifier); in sifive_serial_probe()
968 ssp->port.uartclk = clk_get_rate(ssp->clk); in sifive_serial_probe()
969 ssp->baud_rate = SIFIVE_DEFAULT_BAUD_RATE; in sifive_serial_probe()
970 __ssp_update_div(ssp); in sifive_serial_probe()
972 platform_set_drvdata(pdev, ssp); in sifive_serial_probe()
977 SIFIVE_SERIAL_TXCTRL_OFFS, ssp); in sifive_serial_probe()
982 SIFIVE_SERIAL_RXCTRL_OFFS, ssp); in sifive_serial_probe()
984 r = request_irq(ssp->port.irq, sifive_serial_irq, ssp->port.irqflags, in sifive_serial_probe()
985 dev_name(&pdev->dev), ssp); in sifive_serial_probe()
991 __ssp_add_console_port(ssp); in sifive_serial_probe()
993 r = uart_add_one_port(&sifive_serial_uart_driver, &ssp->port); in sifive_serial_probe()
1002 __ssp_remove_console_port(ssp); in sifive_serial_probe()
1003 free_irq(ssp->port.irq, ssp); in sifive_serial_probe()
1005 clk_notifier_unregister(ssp->clk, &ssp->clk_notifier); in sifive_serial_probe()
1012 struct sifive_serial_port *ssp = platform_get_drvdata(dev); in sifive_serial_remove() local
1014 __ssp_remove_console_port(ssp); in sifive_serial_remove()
1015 uart_remove_one_port(&sifive_serial_uart_driver, &ssp->port); in sifive_serial_remove()
1016 free_irq(ssp->port.irq, ssp); in sifive_serial_remove()
1017 clk_notifier_unregister(ssp->clk, &ssp->clk_notifier); in sifive_serial_remove()
1024 struct sifive_serial_port *ssp = dev_get_drvdata(dev); in sifive_serial_suspend() local
1026 return uart_suspend_port(&sifive_serial_uart_driver, &ssp->port); in sifive_serial_suspend()
1031 struct sifive_serial_port *ssp = dev_get_drvdata(dev); in sifive_serial_resume() local
1033 return uart_resume_port(&sifive_serial_uart_driver, &ssp->port); in sifive_serial_resume()