Lines Matching +full:auto +full:- +full:baud
1 // SPDX-License-Identifier: GPL-2.0+
8 * Sorin-Andrei Pistirica <andrei.pistirica@microchip.com>
26 #include <asm/mach-pic32/pic32.h>
29 #define PIC32_DEV_NAME "pic32-uart"
43 /* struct pic32_sport - pic32 serial port descriptor
82 __raw_writel(val, sport->port.membase + reg); in pic32_uart_writel()
87 return __raw_readl(sport->port.membase + reg); in pic32_uart_readl()
166 if (!sport->cts_gpiod) in pic32_uart_get_mctrl()
168 else if (gpiod_get_value(sport->cts_gpiod)) in pic32_uart_get_mctrl()
181 * the status of irq to control the irq-depth.
185 if (en && !sport->enable_tx_irq) { in pic32_uart_irqtxen()
186 enable_irq(sport->irq_tx); in pic32_uart_irqtxen()
187 sport->enable_tx_irq = true; in pic32_uart_irqtxen()
188 } else if (!en && sport->enable_tx_irq) { in pic32_uart_irqtxen()
193 disable_irq_nosync(sport->irq_tx); in pic32_uart_irqtxen()
194 sport->enable_tx_irq = false; in pic32_uart_irqtxen()
233 disable_irq(sport->irq_rx); in pic32_uart_stop_rx()
261 return (port->type == PORT_PIC32) ? PIC32_DEV_NAME : NULL; in pic32_uart_type()
279 tty = &port->state->port; in pic32_uart_do_rx()
293 port->icount.overrun++; in pic32_uart_do_rx()
304 port->icount.rx++; in pic32_uart_do_rx()
313 port->icount.parity++; in pic32_uart_do_rx()
315 port->icount.frame++; in pic32_uart_do_rx()
318 sta_reg &= port->read_status_mask; in pic32_uart_do_rx()
329 if ((sta_reg & port->ignore_status_mask) == 0) in pic32_uart_do_rx()
332 } while (--max_count); in pic32_uart_do_rx()
345 struct tty_port *tport = &port->state->port; in pic32_uart_do_tx()
348 if (port->x_char) { in pic32_uart_do_tx()
349 pic32_uart_writel(sport, PIC32_UART_TX, port->x_char); in pic32_uart_do_tx()
350 port->icount.tx++; in pic32_uart_do_tx()
351 port->x_char = 0; in pic32_uart_do_tx()
360 if (kfifo_is_empty(&tport->xmit_fifo)) in pic32_uart_do_tx()
380 if (--max_count == 0) in pic32_uart_do_tx()
384 if (kfifo_len(&tport->xmit_fifo) < WAKEUP_CHARS) in pic32_uart_do_tx()
387 if (kfifo_is_empty(&tport->xmit_fifo)) in pic32_uart_do_tx()
455 u32 dflt_baud = (port->uartclk / PIC32_UART_DFLT_BRATE / 16) - 1; in pic32_uart_startup()
461 ret = clk_prepare_enable(sport->clk); in pic32_uart_startup()
474 /* set default baud */ in pic32_uart_startup()
485 sport->enable_tx_irq = false; in pic32_uart_startup()
487 sport->irq_fault_name = kasprintf(GFP_KERNEL, "%s%d-fault", in pic32_uart_startup()
489 sport->idx); in pic32_uart_startup()
490 if (!sport->irq_fault_name) { in pic32_uart_startup()
491 dev_err(port->dev, "%s: kasprintf err!", __func__); in pic32_uart_startup()
492 ret = -ENOMEM; in pic32_uart_startup()
495 irq_set_status_flags(sport->irq_fault, IRQ_NOAUTOEN); in pic32_uart_startup()
496 ret = request_irq(sport->irq_fault, pic32_uart_fault_interrupt, in pic32_uart_startup()
497 IRQF_NO_THREAD, sport->irq_fault_name, port); in pic32_uart_startup()
499 dev_err(port->dev, "%s: request irq(%d) err! ret:%d name:%s\n", in pic32_uart_startup()
500 __func__, sport->irq_fault, ret, in pic32_uart_startup()
505 sport->irq_rx_name = kasprintf(GFP_KERNEL, "%s%d-rx", in pic32_uart_startup()
507 sport->idx); in pic32_uart_startup()
508 if (!sport->irq_rx_name) { in pic32_uart_startup()
509 dev_err(port->dev, "%s: kasprintf err!", __func__); in pic32_uart_startup()
510 ret = -ENOMEM; in pic32_uart_startup()
513 irq_set_status_flags(sport->irq_rx, IRQ_NOAUTOEN); in pic32_uart_startup()
514 ret = request_irq(sport->irq_rx, pic32_uart_rx_interrupt, in pic32_uart_startup()
515 IRQF_NO_THREAD, sport->irq_rx_name, port); in pic32_uart_startup()
517 dev_err(port->dev, "%s: request irq(%d) err! ret:%d name:%s\n", in pic32_uart_startup()
518 __func__, sport->irq_rx, ret, in pic32_uart_startup()
523 sport->irq_tx_name = kasprintf(GFP_KERNEL, "%s%d-tx", in pic32_uart_startup()
525 sport->idx); in pic32_uart_startup()
526 if (!sport->irq_tx_name) { in pic32_uart_startup()
527 dev_err(port->dev, "%s: kasprintf err!", __func__); in pic32_uart_startup()
528 ret = -ENOMEM; in pic32_uart_startup()
531 irq_set_status_flags(sport->irq_tx, IRQ_NOAUTOEN); in pic32_uart_startup()
532 ret = request_irq(sport->irq_tx, pic32_uart_tx_interrupt, in pic32_uart_startup()
533 IRQF_NO_THREAD, sport->irq_tx_name, port); in pic32_uart_startup()
535 dev_err(port->dev, "%s: request irq(%d) err! ret:%d name:%s\n", in pic32_uart_startup()
536 __func__, sport->irq_tx, ret, in pic32_uart_startup()
556 enable_irq(sport->irq_rx); in pic32_uart_startup()
561 free_irq(sport->irq_tx, port); in pic32_uart_startup()
562 kfree(sport->irq_tx_name); in pic32_uart_startup()
564 free_irq(sport->irq_rx, port); in pic32_uart_startup()
565 kfree(sport->irq_rx_name); in pic32_uart_startup()
567 free_irq(sport->irq_fault, port); in pic32_uart_startup()
568 kfree(sport->irq_fault_name); in pic32_uart_startup()
570 clk_disable_unprepare(sport->clk); in pic32_uart_startup()
585 clk_disable_unprepare(sport->clk); in pic32_uart_shutdown()
588 free_irq(sport->irq_fault, port); in pic32_uart_shutdown()
589 kfree(sport->irq_fault_name); in pic32_uart_shutdown()
590 free_irq(sport->irq_tx, port); in pic32_uart_shutdown()
591 kfree(sport->irq_tx_name); in pic32_uart_shutdown()
592 free_irq(sport->irq_rx, port); in pic32_uart_shutdown()
593 kfree(sport->irq_rx_name); in pic32_uart_shutdown()
602 unsigned int baud; in pic32_uart_set_termios() local
612 if (new->c_cflag & CSTOPB) in pic32_uart_set_termios()
620 if (new->c_cflag & PARENB) { in pic32_uart_set_termios()
621 if (new->c_cflag & PARODD) { in pic32_uart_set_termios()
638 if ((new->c_cflag & CRTSCTS) && sport->cts_gpiod) { in pic32_uart_set_termios()
656 /* Always 8-bit */ in pic32_uart_set_termios()
657 new->c_cflag |= CS8; in pic32_uart_set_termios()
660 new->c_cflag &= ~CMSPAR; in pic32_uart_set_termios()
662 /* update baud */ in pic32_uart_set_termios()
663 baud = uart_get_baud_rate(port, new, old, 0, port->uartclk / 16); in pic32_uart_set_termios()
664 quot = uart_get_divisor(port, baud) - 1; in pic32_uart_set_termios()
666 uart_update_timeout(port, new->c_cflag, baud); in pic32_uart_set_termios()
669 tty_termios_encode_baud_rate(new, baud, baud); in pic32_uart_set_termios()
680 struct platform_device *pdev = to_platform_device(port->dev); in pic32_uart_request_port()
685 return -EINVAL; in pic32_uart_request_port()
687 if (!request_mem_region(port->mapbase, resource_size(res_mem), in pic32_uart_request_port()
689 return -EBUSY; in pic32_uart_request_port()
691 port->membase = devm_ioremap(port->dev, port->mapbase, in pic32_uart_request_port()
693 if (!port->membase) { in pic32_uart_request_port()
694 dev_err(port->dev, "Unable to map registers\n"); in pic32_uart_request_port()
695 release_mem_region(port->mapbase, resource_size(res_mem)); in pic32_uart_request_port()
696 return -ENOMEM; in pic32_uart_request_port()
705 struct platform_device *pdev = to_platform_device(port->dev); in pic32_uart_release_port()
714 release_mem_region(port->mapbase, res_size); in pic32_uart_release_port()
717 /* serial core request to do any port required auto-configuration */
723 port->type = PORT_PIC32; in pic32_uart_config_port()
731 if (port->type != PORT_PIC32) in pic32_uart_verify_port()
732 return -EINVAL; in pic32_uart_verify_port()
733 if (port->irq != serinfo->irq) in pic32_uart_verify_port()
734 return -EINVAL; in pic32_uart_verify_port()
735 if (port->iotype != serinfo->io_type) in pic32_uart_verify_port()
736 return -EINVAL; in pic32_uart_verify_port()
737 if (port->mapbase != (unsigned long)serinfo->iomem_base) in pic32_uart_verify_port()
738 return -EINVAL; in pic32_uart_verify_port()
784 struct pic32_sport *sport = pic32_sports[co->index]; in pic32_console_write()
787 uart_console_write(&sport->port, s, count, pic32_console_putchar); in pic32_console_write()
796 int baud = 115200; in pic32_console_setup() local
802 if (unlikely(co->index < 0 || co->index >= PIC32_MAX_UARTS)) in pic32_console_setup()
803 return -ENODEV; in pic32_console_setup()
805 sport = pic32_sports[co->index]; in pic32_console_setup()
807 return -ENODEV; in pic32_console_setup()
809 ret = clk_prepare_enable(sport->clk); in pic32_console_setup()
814 uart_parse_options(options, &baud, &parity, &bits, &flow); in pic32_console_setup()
816 return uart_set_options(&sport->port, co, baud, parity, bits, flow); in pic32_console_setup()
826 .index = -1,
865 struct device *dev = &pdev->dev; in pic32_uart_probe()
866 struct device_node *np = dev->of_node; in pic32_uart_probe()
875 return -EINVAL; in pic32_uart_probe()
879 return -EINVAL; in pic32_uart_probe()
881 sport = devm_kzalloc(&pdev->dev, sizeof(*sport), GFP_KERNEL); in pic32_uart_probe()
883 return -ENOMEM; in pic32_uart_probe()
885 sport->idx = uart_idx; in pic32_uart_probe()
886 sport->irq_fault = irq_of_parse_and_map(np, 0); in pic32_uart_probe()
887 sport->irq_rx = irq_of_parse_and_map(np, 1); in pic32_uart_probe()
888 sport->irq_tx = irq_of_parse_and_map(np, 2); in pic32_uart_probe()
889 sport->clk = devm_clk_get(&pdev->dev, NULL); in pic32_uart_probe()
890 if (IS_ERR(sport->clk)) in pic32_uart_probe()
891 return PTR_ERR(sport->clk); in pic32_uart_probe()
892 sport->dev = &pdev->dev; in pic32_uart_probe()
897 sport->cts_gpiod = devm_gpiod_get_optional(dev, "cts", GPIOD_IN); in pic32_uart_probe()
898 if (IS_ERR(sport->cts_gpiod)) in pic32_uart_probe()
899 return dev_err_probe(dev, PTR_ERR(sport->cts_gpiod), "error requesting CTS GPIO\n"); in pic32_uart_probe()
900 gpiod_set_consumer_name(sport->cts_gpiod, "CTS"); in pic32_uart_probe()
903 port = &sport->port; in pic32_uart_probe()
904 port->iotype = UPIO_MEM; in pic32_uart_probe()
905 port->mapbase = res_mem->start; in pic32_uart_probe()
906 port->ops = &pic32_uart_ops; in pic32_uart_probe()
907 port->flags = UPF_BOOT_AUTOCONF; in pic32_uart_probe()
908 port->dev = &pdev->dev; in pic32_uart_probe()
909 port->fifosize = PIC32_UART_TX_FIFO_DEPTH; in pic32_uart_probe()
910 port->uartclk = clk_get_rate(sport->clk); in pic32_uart_probe()
911 port->line = uart_idx; in pic32_uart_probe()
915 port->membase = NULL; in pic32_uart_probe()
916 dev_err(port->dev, "%s: uart add port error!\n", __func__); in pic32_uart_probe()
925 clk_disable_unprepare(sport->clk); in pic32_uart_probe()
931 dev_info(&pdev->dev, "%s: uart(%d) driver initialized.\n", in pic32_uart_probe()
946 clk_disable_unprepare(sport->clk); in pic32_uart_remove()
948 pic32_sports[sport->idx] = NULL; in pic32_uart_remove()
952 { .compatible = "microchip,pic32mzda-uart" },
998 MODULE_AUTHOR("Sorin-Andrei Pistirica <andrei.pistirica@microchip.com>");