Lines Matching +full:lgm +full:- +full:clk
1 // SPDX-License-Identifier: GPL-2.0
12 #include <linux/clk.h>
111 struct clk *freqclk;
113 struct clk *clk; member
144 u32 fstat = __raw_readl(port->membase + LTQ_ASC_FSTAT); in lqasc_tx_ready()
155 spin_lock_irqsave(<q_port->lock, flags); in lqasc_start_tx()
157 spin_unlock_irqrestore(<q_port->lock, flags); in lqasc_start_tx()
164 __raw_writel(ASCWHBSTATE_CLRREN, port->membase + LTQ_ASC_WHBSTATE); in lqasc_stop_rx()
170 struct tty_port *tport = &port->state->port; in lqasc_rx_chars()
173 fifocnt = __raw_readl(port->membase + LTQ_ASC_FSTAT) & in lqasc_rx_chars()
175 while (fifocnt--) { in lqasc_rx_chars()
177 ch = readb(port->membase + LTQ_ASC_RBUF); in lqasc_rx_chars()
178 rsr = (__raw_readl(port->membase + LTQ_ASC_STATE) in lqasc_rx_chars()
181 port->icount.rx++; in lqasc_rx_chars()
189 port->icount.parity++; in lqasc_rx_chars()
191 port->membase + LTQ_ASC_WHBSTATE); in lqasc_rx_chars()
193 port->icount.frame++; in lqasc_rx_chars()
195 port->membase + LTQ_ASC_WHBSTATE); in lqasc_rx_chars()
198 port->icount.overrun++; in lqasc_rx_chars()
200 port->membase + LTQ_ASC_WHBSTATE); in lqasc_rx_chars()
203 rsr &= port->read_status_mask; in lqasc_rx_chars()
211 if ((rsr & port->ignore_status_mask) == 0) in lqasc_rx_chars()
232 struct circ_buf *xmit = &port->state->xmit; in lqasc_tx_chars()
239 if (port->x_char) { in lqasc_tx_chars()
240 writeb(port->x_char, port->membase + LTQ_ASC_TBUF); in lqasc_tx_chars()
241 port->icount.tx++; in lqasc_tx_chars()
242 port->x_char = 0; in lqasc_tx_chars()
249 writeb(port->state->xmit.buf[port->state->xmit.tail], in lqasc_tx_chars()
250 port->membase + LTQ_ASC_TBUF); in lqasc_tx_chars()
251 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); in lqasc_tx_chars()
252 port->icount.tx++; in lqasc_tx_chars()
266 spin_lock_irqsave(<q_port->lock, flags); in lqasc_tx_int()
267 __raw_writel(ASC_IRNCR_TIR, port->membase + LTQ_ASC_IRNCR); in lqasc_tx_int()
268 spin_unlock_irqrestore(<q_port->lock, flags); in lqasc_tx_int()
280 spin_lock_irqsave(<q_port->lock, flags); in lqasc_err_int()
283 ASCWHBSTATE_CLRROE, port->membase + LTQ_ASC_WHBSTATE); in lqasc_err_int()
284 spin_unlock_irqrestore(<q_port->lock, flags); in lqasc_err_int()
295 spin_lock_irqsave(<q_port->lock, flags); in lqasc_rx_int()
296 __raw_writel(ASC_IRNCR_RIR, port->membase + LTQ_ASC_IRNCR); in lqasc_rx_int()
298 spin_unlock_irqrestore(<q_port->lock, flags); in lqasc_rx_int()
309 spin_lock_irqsave(<q_port->lock, flags); in lqasc_irq()
310 stat = readl(port->membase + LTQ_ASC_IRNCR); in lqasc_irq()
311 spin_unlock_irqrestore(<q_port->lock, flags); in lqasc_irq()
331 status = __raw_readl(port->membase + LTQ_ASC_FSTAT) & in lqasc_tx_empty()
359 if (!IS_ERR(ltq_port->clk)) in lqasc_startup()
360 clk_prepare_enable(ltq_port->clk); in lqasc_startup()
361 port->uartclk = clk_get_rate(ltq_port->freqclk); in lqasc_startup()
363 spin_lock_irqsave(<q_port->lock, flags); in lqasc_startup()
365 port->membase + LTQ_ASC_CLC); in lqasc_startup()
367 __raw_writel(0, port->membase + LTQ_ASC_PISEL); in lqasc_startup()
371 port->membase + LTQ_ASC_TXFCON); in lqasc_startup()
375 port->membase + LTQ_ASC_RXFCON); in lqasc_startup()
381 ASCCON_ROEN, port->membase + LTQ_ASC_CON); in lqasc_startup()
383 spin_unlock_irqrestore(<q_port->lock, flags); in lqasc_startup()
385 retval = ltq_port->soc->request_irq(port); in lqasc_startup()
390 port->membase + LTQ_ASC_IRNREN); in lqasc_startup()
400 ltq_port->soc->free_irq(port); in lqasc_shutdown()
402 spin_lock_irqsave(<q_port->lock, flags); in lqasc_shutdown()
403 __raw_writel(0, port->membase + LTQ_ASC_CON); in lqasc_shutdown()
405 port->membase + LTQ_ASC_RXFCON); in lqasc_shutdown()
407 port->membase + LTQ_ASC_TXFCON); in lqasc_shutdown()
408 spin_unlock_irqrestore(<q_port->lock, flags); in lqasc_shutdown()
409 if (!IS_ERR(ltq_port->clk)) in lqasc_shutdown()
410 clk_disable_unprepare(ltq_port->clk); in lqasc_shutdown()
425 cflag = new->c_cflag; in lqasc_set_termios()
426 iflag = new->c_iflag; in lqasc_set_termios()
436 new->c_cflag &= ~ CSIZE; in lqasc_set_termios()
437 new->c_cflag |= CS8; in lqasc_set_termios()
454 port->read_status_mask = ASCSTATE_ROE; in lqasc_set_termios()
456 port->read_status_mask |= ASCSTATE_FE | ASCSTATE_PE; in lqasc_set_termios()
458 port->ignore_status_mask = 0; in lqasc_set_termios()
460 port->ignore_status_mask |= ASCSTATE_FE | ASCSTATE_PE; in lqasc_set_termios()
468 port->ignore_status_mask |= ASCSTATE_ROE; in lqasc_set_termios()
472 port->ignore_status_mask |= UART_DUMMY_UER_RX; in lqasc_set_termios()
474 /* set error signals - framing, parity and overrun, enable receiver */ in lqasc_set_termios()
477 spin_lock_irqsave(<q_port->lock, flags); in lqasc_set_termios()
480 asc_update_bits(0, con, port->membase + LTQ_ASC_CON); in lqasc_set_termios()
482 /* Set baud rate - take a divider of 2 into account */ in lqasc_set_termios()
483 baud = uart_get_baud_rate(port, new, old, 0, port->uartclk / 16); in lqasc_set_termios()
485 divisor = divisor / 2 - 1; in lqasc_set_termios()
488 asc_update_bits(ASCCON_R, 0, port->membase + LTQ_ASC_CON); in lqasc_set_termios()
491 asc_update_bits(ASCCON_FDE, 0, port->membase + LTQ_ASC_CON); in lqasc_set_termios()
494 asc_update_bits(ASCCON_BRS, 0, port->membase + LTQ_ASC_CON); in lqasc_set_termios()
497 __raw_writel(divisor, port->membase + LTQ_ASC_BG); in lqasc_set_termios()
500 asc_update_bits(0, ASCCON_R, port->membase + LTQ_ASC_CON); in lqasc_set_termios()
503 __raw_writel(ASCWHBSTATE_SETREN, port->membase + LTQ_ASC_WHBSTATE); in lqasc_set_termios()
505 spin_unlock_irqrestore(<q_port->lock, flags); in lqasc_set_termios()
517 if (port->type == PORT_LTQ_ASC) in lqasc_type()
526 struct platform_device *pdev = to_platform_device(port->dev); in lqasc_release_port()
528 if (port->flags & UPF_IOREMAP) { in lqasc_release_port()
529 devm_iounmap(&pdev->dev, port->membase); in lqasc_release_port()
530 port->membase = NULL; in lqasc_release_port()
537 struct platform_device *pdev = to_platform_device(port->dev); in lqasc_request_port()
543 dev_err(&pdev->dev, "cannot obtain I/O memory region"); in lqasc_request_port()
544 return -ENODEV; in lqasc_request_port()
548 res = devm_request_mem_region(&pdev->dev, res->start, in lqasc_request_port()
549 size, dev_name(&pdev->dev)); in lqasc_request_port()
551 dev_err(&pdev->dev, "cannot request I/O memory region"); in lqasc_request_port()
552 return -EBUSY; in lqasc_request_port()
555 if (port->flags & UPF_IOREMAP) { in lqasc_request_port()
556 port->membase = devm_ioremap(&pdev->dev, in lqasc_request_port()
557 port->mapbase, size); in lqasc_request_port()
558 if (port->membase == NULL) in lqasc_request_port()
559 return -ENOMEM; in lqasc_request_port()
568 port->type = PORT_LTQ_ASC; in lqasc_config_port()
578 if (ser->type != PORT_UNKNOWN && ser->type != PORT_LTQ_ASC) in lqasc_verify_port()
579 ret = -EINVAL; in lqasc_verify_port()
580 if (ser->irq < 0 || ser->irq >= NR_IRQS) in lqasc_verify_port()
581 ret = -EINVAL; in lqasc_verify_port()
582 if (ser->baud_base < 9600) in lqasc_verify_port()
583 ret = -EINVAL; in lqasc_verify_port()
609 if (!port->membase) in lqasc_console_putchar()
615 writeb(ch, port->membase + LTQ_ASC_TBUF); in lqasc_console_putchar()
630 if (co->index >= MAXPORTS) in lqasc_console_write()
633 ltq_port = lqasc_port[co->index]; in lqasc_console_write()
637 spin_lock_irqsave(<q_port->lock, flags); in lqasc_console_write()
638 lqasc_serial_port_write(<q_port->port, s, count); in lqasc_console_write()
639 spin_unlock_irqrestore(<q_port->lock, flags); in lqasc_console_write()
652 if (co->index >= MAXPORTS) in lqasc_console_setup()
653 return -ENODEV; in lqasc_console_setup()
655 ltq_port = lqasc_port[co->index]; in lqasc_console_setup()
657 return -ENODEV; in lqasc_console_setup()
659 port = <q_port->port; in lqasc_console_setup()
661 if (!IS_ERR(ltq_port->clk)) in lqasc_console_setup()
662 clk_prepare_enable(ltq_port->clk); in lqasc_console_setup()
664 port->uartclk = clk_get_rate(ltq_port->freqclk); in lqasc_console_setup()
677 .index = -1,
693 struct earlycon_device *dev = co->data; in lqasc_serial_early_console_write()
695 lqasc_serial_port_write(&dev->port, s, count); in lqasc_serial_early_console_write()
702 if (!device->port.membase) in lqasc_serial_early_console_setup()
703 return -ENODEV; in lqasc_serial_early_console_setup()
705 device->con->write = lqasc_serial_early_console_write; in lqasc_serial_early_console_setup()
709 OF_EARLYCON_DECLARE(lantiq, "intel,lgm-asc", lqasc_serial_early_console_setup);
731 struct uart_port *port = <q_port->port; in fetch_irq_lantiq()
738 ltq_port->tx_irq = irq; in fetch_irq_lantiq()
742 ltq_port->rx_irq = irq; in fetch_irq_lantiq()
746 ltq_port->err_irq = irq; in fetch_irq_lantiq()
748 port->irq = ltq_port->tx_irq; in fetch_irq_lantiq()
758 retval = request_irq(ltq_port->tx_irq, lqasc_tx_int, in request_irq_lantiq()
761 dev_err(port->dev, "failed to request asc_tx\n"); in request_irq_lantiq()
765 retval = request_irq(ltq_port->rx_irq, lqasc_rx_int, in request_irq_lantiq()
768 dev_err(port->dev, "failed to request asc_rx\n"); in request_irq_lantiq()
772 retval = request_irq(ltq_port->err_irq, lqasc_err_int, in request_irq_lantiq()
775 dev_err(port->dev, "failed to request asc_err\n"); in request_irq_lantiq()
781 free_irq(ltq_port->rx_irq, port); in request_irq_lantiq()
783 free_irq(ltq_port->tx_irq, port); in request_irq_lantiq()
791 free_irq(ltq_port->tx_irq, port); in free_irq_lantiq()
792 free_irq(ltq_port->rx_irq, port); in free_irq_lantiq()
793 free_irq(ltq_port->err_irq, port); in free_irq_lantiq()
798 struct uart_port *port = <q_port->port; in fetch_irq_intel()
806 ltq_port->common_irq = ret; in fetch_irq_intel()
807 port->irq = ret; in fetch_irq_intel()
817 retval = request_irq(ltq_port->common_irq, lqasc_irq, 0, in request_irq_intel()
820 dev_err(port->dev, "failed to request asc_irq\n"); in request_irq_intel()
829 free_irq(ltq_port->common_irq, port); in free_irq_intel()
834 struct device_node *node = pdev->dev.of_node; in lqasc_probe()
843 dev_err(&pdev->dev, in lqasc_probe()
845 return -ENODEV; in lqasc_probe()
848 ltq_port = devm_kzalloc(&pdev->dev, sizeof(struct ltq_uart_port), in lqasc_probe()
851 return -ENOMEM; in lqasc_probe()
853 port = <q_port->port; in lqasc_probe()
855 ltq_port->soc = of_device_get_match_data(&pdev->dev); in lqasc_probe()
856 ret = ltq_port->soc->fetch_irq(&pdev->dev, ltq_port); in lqasc_probe()
864 if (mmres->start == CPHYSADDR(LTQ_EARLY_ASC)) in lqasc_probe()
869 dev_err(&pdev->dev, "failed to get alias id, errno %d\n", in lqasc_probe()
876 dev_err(&pdev->dev, "port %d already allocated\n", line); in lqasc_probe()
877 return -EBUSY; in lqasc_probe()
880 port->iotype = SERIAL_IO_MEM; in lqasc_probe()
881 port->flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP; in lqasc_probe()
882 port->ops = &lqasc_pops; in lqasc_probe()
883 port->fifosize = 16; in lqasc_probe()
884 port->type = PORT_LTQ_ASC; in lqasc_probe()
885 port->line = line; in lqasc_probe()
886 port->dev = &pdev->dev; in lqasc_probe()
887 /* unused, just to be backward-compatible */ in lqasc_probe()
888 port->mapbase = mmres->start; in lqasc_probe()
891 ltq_port->freqclk = clk_get_fpi(); in lqasc_probe()
893 ltq_port->freqclk = devm_clk_get(&pdev->dev, "freq"); in lqasc_probe()
896 if (IS_ERR(ltq_port->freqclk)) { in lqasc_probe()
897 pr_err("failed to get fpi clk\n"); in lqasc_probe()
898 return -ENOENT; in lqasc_probe()
903 ltq_port->clk = clk_get(&pdev->dev, NULL); in lqasc_probe()
905 ltq_port->clk = devm_clk_get(&pdev->dev, "asc"); in lqasc_probe()
907 spin_lock_init(<q_port->lock); in lqasc_probe()
937 { .compatible = "intel,lgm-asc", .data = &soc_data_intel },