stm32-usart.c (c13aca79ff3c4af5fd31a5b2743a90eba6e36a26) | stm32-usart.c (c8a9d043947b4acb19a65f7fac2bd0893e581cd5) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * Copyright (C) Maxime Coquelin 2015 4 * Copyright (C) STMicroelectronics SA 2017 5 * Authors: Maxime Coquelin <mcoquelin.stm32@gmail.com> 6 * Gerald Baeza <gerald.baeza@st.com> 7 * 8 * Inspired by st-asc.c from STMicroelectronics (c) --- 585 unchanged lines hidden (view full) --- 594 if (stm32_port->fifoen) 595 val |= USART_CR1_FIFOEN; 596 stm32_clr_bits(port, ofs->cr1, val); 597 598 dev_pm_clear_wake_irq(port->dev); 599 free_irq(port->irq, port); 600} 601 | 1// SPDX-License-Identifier: GPL-2.0 2/* 3 * Copyright (C) Maxime Coquelin 2015 4 * Copyright (C) STMicroelectronics SA 2017 5 * Authors: Maxime Coquelin <mcoquelin.stm32@gmail.com> 6 * Gerald Baeza <gerald.baeza@st.com> 7 * 8 * Inspired by st-asc.c from STMicroelectronics (c) --- 585 unchanged lines hidden (view full) --- 594 if (stm32_port->fifoen) 595 val |= USART_CR1_FIFOEN; 596 stm32_clr_bits(port, ofs->cr1, val); 597 598 dev_pm_clear_wake_irq(port->dev); 599 free_irq(port->irq, port); 600} 601 |
602unsigned int stm32_get_databits(struct ktermios *termios) 603{ 604 unsigned int bits; 605 606 tcflag_t cflag = termios->c_cflag; 607 608 switch (cflag & CSIZE) { 609 /* 610 * CSIZE settings are not necessarily supported in hardware. 611 * CSIZE unsupported configurations are handled here to set word length 612 * to 8 bits word as default configuration and to print debug message. 613 */ 614 case CS5: 615 bits = 5; 616 break; 617 case CS6: 618 bits = 6; 619 break; 620 case CS7: 621 bits = 7; 622 break; 623 /* default including CS8 */ 624 default: 625 bits = 8; 626 break; 627 } 628 629 return bits; 630} 631 |
|
602static void stm32_set_termios(struct uart_port *port, struct ktermios *termios, 603 struct ktermios *old) 604{ 605 struct stm32_port *stm32_port = to_stm32_port(port); 606 struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 607 struct stm32_usart_config *cfg = &stm32_port->info->cfg; 608 struct serial_rs485 *rs485conf = &port->rs485; | 632static void stm32_set_termios(struct uart_port *port, struct ktermios *termios, 633 struct ktermios *old) 634{ 635 struct stm32_port *stm32_port = to_stm32_port(port); 636 struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; 637 struct stm32_usart_config *cfg = &stm32_port->info->cfg; 638 struct serial_rs485 *rs485conf = &port->rs485; |
609 unsigned int baud; | 639 unsigned int baud, bits; |
610 u32 usartdiv, mantissa, fraction, oversampling; 611 tcflag_t cflag = termios->c_cflag; 612 u32 cr1, cr2, cr3; 613 unsigned long flags; 614 615 if (!stm32_port->hw_flow_control) 616 cflag &= ~CRTSCTS; 617 --- 9 unchanged lines hidden (view full) --- 627 if (stm32_port->fifoen) 628 cr1 |= USART_CR1_FIFOEN; 629 cr2 = 0; 630 cr3 = 0; 631 632 if (cflag & CSTOPB) 633 cr2 |= USART_CR2_STOP_2B; 634 | 640 u32 usartdiv, mantissa, fraction, oversampling; 641 tcflag_t cflag = termios->c_cflag; 642 u32 cr1, cr2, cr3; 643 unsigned long flags; 644 645 if (!stm32_port->hw_flow_control) 646 cflag &= ~CRTSCTS; 647 --- 9 unchanged lines hidden (view full) --- 657 if (stm32_port->fifoen) 658 cr1 |= USART_CR1_FIFOEN; 659 cr2 = 0; 660 cr3 = 0; 661 662 if (cflag & CSTOPB) 663 cr2 |= USART_CR2_STOP_2B; 664 |
665 bits = stm32_get_databits(termios); 666 |
|
635 if (cflag & PARENB) { | 667 if (cflag & PARENB) { |
668 bits++; |
|
636 cr1 |= USART_CR1_PCE; | 669 cr1 |= USART_CR1_PCE; |
637 if ((cflag & CSIZE) == CS8) { 638 if (cfg->has_7bits_data) 639 cr1 |= USART_CR1_M0; 640 else 641 cr1 |= USART_CR1_M; 642 } | |
643 } 644 | 670 } 671 |
672 /* 673 * Word length configuration: 674 * CS8 + parity, 9 bits word aka [M1:M0] = 0b01 675 * CS7 or (CS6 + parity), 7 bits word aka [M1:M0] = 0b10 676 * CS8 or (CS7 + parity), 8 bits word aka [M1:M0] = 0b00 677 * M0 and M1 already cleared by cr1 initialization. 678 */ 679 if (bits == 9) 680 cr1 |= USART_CR1_M0; 681 else if ((bits == 7) && cfg->has_7bits_data) 682 cr1 |= USART_CR1_M1; 683 else if (bits != 8) 684 dev_dbg(port->dev, "Unsupported data bits config: %u bits\n" 685 , bits); 686 |
|
645 if (cflag & PARODD) 646 cr1 |= USART_CR1_PS; 647 648 port->status &= ~(UPSTAT_AUTOCTS | UPSTAT_AUTORTS); 649 if (cflag & CRTSCTS) { 650 port->status |= UPSTAT_AUTOCTS | UPSTAT_AUTORTS; 651 cr3 |= USART_CR3_CTSE | USART_CR3_RTSE; 652 } --- 631 unchanged lines hidden --- | 687 if (cflag & PARODD) 688 cr1 |= USART_CR1_PS; 689 690 port->status &= ~(UPSTAT_AUTOCTS | UPSTAT_AUTORTS); 691 if (cflag & CRTSCTS) { 692 port->status |= UPSTAT_AUTOCTS | UPSTAT_AUTORTS; 693 cr3 |= USART_CR3_CTSE | USART_CR3_RTSE; 694 } --- 631 unchanged lines hidden --- |