Lines Matching +full:auto +full:- +full:baud
1 // SPDX-License-Identifier: GPL-2.0+
8 * Sorin-Andrei Pistirica <andrei.pistirica@microchip.com>
27 #include <asm/mach-pic32/pic32.h>
31 #define PIC32_DEV_NAME "pic32-uart"
47 int ret = clk_prepare_enable(sport->clk); in pic32_enable_clock()
52 sport->ref_clk++; in pic32_enable_clock()
58 sport->ref_clk--; in pic32_disable_clock()
59 clk_disable_unprepare(sport->clk); in pic32_disable_clock()
89 if (gpio_is_valid(sport->cts_gpio)) in get_cts_state()
90 return !gpio_get_value(sport->cts_gpio); in get_cts_state()
101 if (!sport->hw_flow_ctrl) in pic32_uart_get_mctrl()
116 * the status of irq to control the irq-depth.
121 enable_irq(sport->irq_tx); in pic32_uart_irqtxen()
128 disable_irq_nosync(sport->irq_tx); in pic32_uart_irqtxen()
168 disable_irq(sport->irq_rx); in pic32_uart_stop_rx()
181 spin_lock_irqsave(&port->lock, flags); in pic32_uart_break_ctl()
190 spin_unlock_irqrestore(&port->lock, flags); in pic32_uart_break_ctl()
196 return (port->type == PORT_PIC32) ? PIC32_DEV_NAME : NULL; in pic32_uart_type()
212 spin_lock(&port->lock); in pic32_uart_do_rx()
214 tty = &port->state->port; in pic32_uart_do_rx()
228 port->icount.overrun++; in pic32_uart_do_rx()
239 port->icount.rx++; in pic32_uart_do_rx()
248 port->icount.parity++; in pic32_uart_do_rx()
250 port->icount.frame++; in pic32_uart_do_rx()
253 sta_reg &= port->read_status_mask; in pic32_uart_do_rx()
264 if ((sta_reg & port->ignore_status_mask) == 0) in pic32_uart_do_rx()
267 } while (--max_count); in pic32_uart_do_rx()
269 spin_unlock(&port->lock); in pic32_uart_do_rx()
280 struct circ_buf *xmit = &port->state->xmit; in pic32_uart_do_tx()
283 if (port->x_char) { in pic32_uart_do_tx()
284 pic32_uart_writel(sport, PIC32_UART_TX, port->x_char); in pic32_uart_do_tx()
285 port->icount.tx++; in pic32_uart_do_tx()
286 port->x_char = 0; in pic32_uart_do_tx()
309 unsigned int c = xmit->buf[xmit->tail]; in pic32_uart_do_tx()
313 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); in pic32_uart_do_tx()
314 port->icount.tx++; in pic32_uart_do_tx()
317 if (--max_count == 0) in pic32_uart_do_tx()
349 spin_lock_irqsave(&port->lock, flags); in pic32_uart_tx_interrupt()
351 spin_unlock_irqrestore(&port->lock, flags); in pic32_uart_tx_interrupt()
392 u32 dflt_baud = (port->uartclk / PIC32_UART_DFLT_BRATE / 16) - 1; in pic32_uart_startup()
411 /* set default baud */ in pic32_uart_startup()
424 sport->irq_fault_name = kasprintf(GFP_KERNEL, "%s%d-fault", in pic32_uart_startup()
426 sport->idx); in pic32_uart_startup()
427 if (!sport->irq_fault_name) { in pic32_uart_startup()
428 dev_err(port->dev, "%s: kasprintf err!", __func__); in pic32_uart_startup()
429 ret = -ENOMEM; in pic32_uart_startup()
432 irq_set_status_flags(sport->irq_fault, IRQ_NOAUTOEN); in pic32_uart_startup()
433 ret = request_irq(sport->irq_fault, pic32_uart_fault_interrupt, in pic32_uart_startup()
434 sport->irqflags_fault, sport->irq_fault_name, port); in pic32_uart_startup()
436 dev_err(port->dev, "%s: request irq(%d) err! ret:%d name:%s\n", in pic32_uart_startup()
437 __func__, sport->irq_fault, ret, in pic32_uart_startup()
442 sport->irq_rx_name = kasprintf(GFP_KERNEL, "%s%d-rx", in pic32_uart_startup()
444 sport->idx); in pic32_uart_startup()
445 if (!sport->irq_rx_name) { in pic32_uart_startup()
446 dev_err(port->dev, "%s: kasprintf err!", __func__); in pic32_uart_startup()
447 ret = -ENOMEM; in pic32_uart_startup()
450 irq_set_status_flags(sport->irq_rx, IRQ_NOAUTOEN); in pic32_uart_startup()
451 ret = request_irq(sport->irq_rx, pic32_uart_rx_interrupt, in pic32_uart_startup()
452 sport->irqflags_rx, sport->irq_rx_name, port); in pic32_uart_startup()
454 dev_err(port->dev, "%s: request irq(%d) err! ret:%d name:%s\n", in pic32_uart_startup()
455 __func__, sport->irq_rx, ret, in pic32_uart_startup()
460 sport->irq_tx_name = kasprintf(GFP_KERNEL, "%s%d-tx", in pic32_uart_startup()
462 sport->idx); in pic32_uart_startup()
463 if (!sport->irq_tx_name) { in pic32_uart_startup()
464 dev_err(port->dev, "%s: kasprintf err!", __func__); in pic32_uart_startup()
465 ret = -ENOMEM; in pic32_uart_startup()
468 irq_set_status_flags(sport->irq_tx, IRQ_NOAUTOEN); in pic32_uart_startup()
469 ret = request_irq(sport->irq_tx, pic32_uart_tx_interrupt, in pic32_uart_startup()
470 sport->irqflags_tx, sport->irq_tx_name, port); in pic32_uart_startup()
472 dev_err(port->dev, "%s: request irq(%d) err! ret:%d name:%s\n", in pic32_uart_startup()
473 __func__, sport->irq_tx, ret, in pic32_uart_startup()
491 enable_irq(sport->irq_rx); in pic32_uart_startup()
496 kfree(sport->irq_tx_name); in pic32_uart_startup()
497 free_irq(sport->irq_tx, port); in pic32_uart_startup()
499 kfree(sport->irq_rx_name); in pic32_uart_startup()
500 free_irq(sport->irq_rx, port); in pic32_uart_startup()
502 kfree(sport->irq_fault_name); in pic32_uart_startup()
503 free_irq(sport->irq_fault, port); in pic32_uart_startup()
515 spin_lock_irqsave(&port->lock, flags); in pic32_uart_shutdown()
517 spin_unlock_irqrestore(&port->lock, flags); in pic32_uart_shutdown()
521 free_irq(sport->irq_fault, port); in pic32_uart_shutdown()
522 free_irq(sport->irq_tx, port); in pic32_uart_shutdown()
523 free_irq(sport->irq_rx, port); in pic32_uart_shutdown()
532 unsigned int baud; in pic32_uart_set_termios() local
536 spin_lock_irqsave(&port->lock, flags); in pic32_uart_set_termios()
542 if (new->c_cflag & CSTOPB) in pic32_uart_set_termios()
550 if (new->c_cflag & PARENB) { in pic32_uart_set_termios()
551 if (new->c_cflag & PARODD) { in pic32_uart_set_termios()
568 if ((new->c_cflag & CRTSCTS) && sport->hw_flow_ctrl) { in pic32_uart_set_termios()
586 /* Always 8-bit */ in pic32_uart_set_termios()
587 new->c_cflag |= CS8; in pic32_uart_set_termios()
590 new->c_cflag &= ~CMSPAR; in pic32_uart_set_termios()
592 /* update baud */ in pic32_uart_set_termios()
593 baud = uart_get_baud_rate(port, new, old, 0, port->uartclk / 16); in pic32_uart_set_termios()
594 quot = uart_get_divisor(port, baud) - 1; in pic32_uart_set_termios()
596 uart_update_timeout(port, new->c_cflag, baud); in pic32_uart_set_termios()
599 tty_termios_encode_baud_rate(new, baud, baud); in pic32_uart_set_termios()
604 spin_unlock_irqrestore(&port->lock, flags); in pic32_uart_set_termios()
610 struct platform_device *pdev = to_platform_device(port->dev); in pic32_uart_request_port()
615 return -EINVAL; in pic32_uart_request_port()
617 if (!request_mem_region(port->mapbase, resource_size(res_mem), in pic32_uart_request_port()
619 return -EBUSY; in pic32_uart_request_port()
621 port->membase = devm_ioremap(port->dev, port->mapbase, in pic32_uart_request_port()
623 if (!port->membase) { in pic32_uart_request_port()
624 dev_err(port->dev, "Unable to map registers\n"); in pic32_uart_request_port()
625 release_mem_region(port->mapbase, resource_size(res_mem)); in pic32_uart_request_port()
626 return -ENOMEM; in pic32_uart_request_port()
635 struct platform_device *pdev = to_platform_device(port->dev); in pic32_uart_release_port()
644 release_mem_region(port->mapbase, res_size); in pic32_uart_release_port()
647 /* serial core request to do any port required auto-configuration */
653 port->type = PORT_PIC32; in pic32_uart_config_port()
661 if (port->type != PORT_PIC32) in pic32_uart_verify_port()
662 return -EINVAL; in pic32_uart_verify_port()
663 if (port->irq != serinfo->irq) in pic32_uart_verify_port()
664 return -EINVAL; in pic32_uart_verify_port()
665 if (port->iotype != serinfo->io_type) in pic32_uart_verify_port()
666 return -EINVAL; in pic32_uart_verify_port()
667 if (port->mapbase != (unsigned long)serinfo->iomem_base) in pic32_uart_verify_port()
668 return -EINVAL; in pic32_uart_verify_port()
714 struct pic32_sport *sport = pic32_sports[co->index]; in pic32_console_write()
728 int baud = 115200; in pic32_console_setup() local
734 if (unlikely(co->index < 0 || co->index >= PIC32_MAX_UARTS)) in pic32_console_setup()
735 return -ENODEV; in pic32_console_setup()
737 sport = pic32_sports[co->index]; in pic32_console_setup()
739 return -ENODEV; in pic32_console_setup()
747 uart_parse_options(options, &baud, &parity, &bits, &flow); in pic32_console_setup()
749 return uart_set_options(port, co, baud, parity, bits, flow); in pic32_console_setup()
759 .index = -1,
798 struct device_node *np = pdev->dev.of_node; in pic32_uart_probe()
807 return -EINVAL; in pic32_uart_probe()
811 return -EINVAL; in pic32_uart_probe()
813 sport = devm_kzalloc(&pdev->dev, sizeof(*sport), GFP_KERNEL); in pic32_uart_probe()
815 return -ENOMEM; in pic32_uart_probe()
817 sport->idx = uart_idx; in pic32_uart_probe()
818 sport->irq_fault = irq_of_parse_and_map(np, 0); in pic32_uart_probe()
819 sport->irqflags_fault = IRQF_NO_THREAD; in pic32_uart_probe()
820 sport->irq_rx = irq_of_parse_and_map(np, 1); in pic32_uart_probe()
821 sport->irqflags_rx = IRQF_NO_THREAD; in pic32_uart_probe()
822 sport->irq_tx = irq_of_parse_and_map(np, 2); in pic32_uart_probe()
823 sport->irqflags_tx = IRQF_NO_THREAD; in pic32_uart_probe()
824 sport->clk = devm_clk_get(&pdev->dev, NULL); in pic32_uart_probe()
825 sport->cts_gpio = -EINVAL; in pic32_uart_probe()
826 sport->dev = &pdev->dev; in pic32_uart_probe()
831 sport->hw_flow_ctrl = false; in pic32_uart_probe()
832 sport->cts_gpio = of_get_named_gpio(np, "cts-gpios", 0); in pic32_uart_probe()
833 if (gpio_is_valid(sport->cts_gpio)) { in pic32_uart_probe()
834 sport->hw_flow_ctrl = true; in pic32_uart_probe()
836 ret = devm_gpio_request(sport->dev, in pic32_uart_probe()
837 sport->cts_gpio, "CTS"); in pic32_uart_probe()
839 dev_err(&pdev->dev, in pic32_uart_probe()
844 ret = gpio_direction_input(sport->cts_gpio); in pic32_uart_probe()
846 dev_err(&pdev->dev, "error setting CTS GPIO\n"); in pic32_uart_probe()
852 port = &sport->port; in pic32_uart_probe()
854 port->iotype = UPIO_MEM; in pic32_uart_probe()
855 port->mapbase = res_mem->start; in pic32_uart_probe()
856 port->ops = &pic32_uart_ops; in pic32_uart_probe()
857 port->flags = UPF_BOOT_AUTOCONF; in pic32_uart_probe()
858 port->dev = &pdev->dev; in pic32_uart_probe()
859 port->fifosize = PIC32_UART_TX_FIFO_DEPTH; in pic32_uart_probe()
860 port->uartclk = clk_get_rate(sport->clk); in pic32_uart_probe()
861 port->line = uart_idx; in pic32_uart_probe()
865 port->membase = NULL; in pic32_uart_probe()
866 dev_err(port->dev, "%s: uart add port error!\n", __func__); in pic32_uart_probe()
881 dev_info(&pdev->dev, "%s: uart(%d) driver initialized.\n", in pic32_uart_probe()
898 pic32_sports[sport->idx] = NULL; in pic32_uart_remove()
905 { .compatible = "microchip,pic32mzda-uart" },
951 MODULE_AUTHOR("Sorin-Andrei Pistirica <andrei.pistirica@microchip.com>");