Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp878121ybl; Fri, 13 Dec 2019 06:05:32 -0800 (PST) X-Google-Smtp-Source: APXvYqw/xW2Oe+e1Kn8Lzku9N6e4t0y6l7xemtoHC7I7r6N25p2n5FEFmaIV1RYuLucICVvNccIF X-Received: by 2002:aca:cf50:: with SMTP id f77mr7178503oig.60.1576245932240; Fri, 13 Dec 2019 06:05:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576245932; cv=none; d=google.com; s=arc-20160816; b=Zs2Hq+g263ZydomAk8YSDN13QnfrZBNaa8PsOMBeH9ODCkXcKmGsGN71I255W5l8EW Ju5BLACPpQQ6EfBIVNlbBnhjyIdx4zCSjpE6N3uhk3eaDD6+K9ae+2/lwXBAV90pEiHR 8ZzOPia4o+q4VN5MFlMlE9BAOpieYC1NycWJKRxoi+A0Ehxg5bKvI5VbJbZZreUbjq1J KrYZgkIj7h5+Pg6thXUDlqrgu3HayiSkwHfee4aBsnxNmixO/mW+R5p1DOWSMn5oOQN8 uegLPyH/Wo3I0wtWlzKlyeD7OIOuMG/f+PSht9a57mCNWwcnCofj3V2Tld/8sMPHI7rS hmPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=7ytVgQvEAT2ZtJ7DcAUIa+sUAuh/eVmeeA4r2IuC9Rw=; b=zfuI2y18jz5hxlnD1n5InHFBVImEGbblHNePfOml/fuMf6a96nwsDoF1teK2uWzRK+ QYXZrqC8FLjxh4M6syX7mTN/SOzsESXnbjMItjf5MDWbFSKzpH0YNh613opRo91lxgoE Yg61cL8jZTmXqIxjgYZGm4lHBF4YF4usq6Ib3lt6RA9oRtzdsSpiM1F6GihFA172svpH zHE528YBH0VNP4JsJLWbDVjTvKL8aGRr+hYHJP/AW+hz205Vpd8XKnGS+i/VlHLHok6m pXWvSNdj1aSRMJkBqTaRB3eyt1a+25VYGIWAe0xIYKhLP+zVtHr+N/662RGPN6T5JUGQ xOEA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v21si5258599otj.282.2019.12.13.06.05.15; Fri, 13 Dec 2019 06:05:32 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727569AbfLMOES (ORCPT + 99 others); Fri, 13 Dec 2019 09:04:18 -0500 Received: from mail.sysgo.com ([176.9.12.79]:58710 "EHLO mail.sysgo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726524AbfLMOES (ORCPT ); Fri, 13 Dec 2019 09:04:18 -0500 From: David Engraf To: richard.genoud@gmail.com, gregkh@linuxfoundation.org, jslaby@suse.com, nicolas.ferre@microchip.com, alexandre.belloni@bootlin.com, ludovic.desroches@microchip.com Cc: linux-serial@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, David Engraf Subject: [PATCH v2] tty/serial: atmel: fix out of range clock divider handling Date: Fri, 13 Dec 2019 15:03:01 +0100 Message-Id: <20191213140301.16490-1-david.engraf@sysgo.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <1e2e3f63-84db-4b38-1bf1-85916116e0a2@sysgo.com> References: <1e2e3f63-84db-4b38-1bf1-85916116e0a2@sysgo.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use MCK_DIV8 when the clock divider is > 65535. Unfortunately the mode register was already written thus the clock selection is ignored. Fix by doing the baud rate calulation before setting the mode. Fixes: 5bf5635ac170 ("tty/serial: atmel: add fractional baud rate support") Signed-off-by: David Engraf --- drivers/tty/serial/atmel_serial.c | 43 ++++++++++++++++--------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c index a8dc8af83f39..1ba9bc667e13 100644 --- a/drivers/tty/serial/atmel_serial.c +++ b/drivers/tty/serial/atmel_serial.c @@ -2270,27 +2270,6 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios *termios, mode |= ATMEL_US_USMODE_NORMAL; } - /* set the mode, clock divisor, parity, stop bits and data size */ - atmel_uart_writel(port, ATMEL_US_MR, mode); - - /* - * when switching the mode, set the RTS line state according to the - * new mode, otherwise keep the former state - */ - if ((old_mode & ATMEL_US_USMODE) != (mode & ATMEL_US_USMODE)) { - unsigned int rts_state; - - if ((mode & ATMEL_US_USMODE) == ATMEL_US_USMODE_HWHS) { - /* let the hardware control the RTS line */ - rts_state = ATMEL_US_RTSDIS; - } else { - /* force RTS line to low level */ - rts_state = ATMEL_US_RTSEN; - } - - atmel_uart_writel(port, ATMEL_US_CR, rts_state); - } - /* * Set the baud rate: * Fractional baudrate allows to setup output frequency more @@ -2317,6 +2296,28 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios *termios, if (!(port->iso7816.flags & SER_ISO7816_ENABLED)) atmel_uart_writel(port, ATMEL_US_BRGR, quot); + + /* set the mode, clock divisor, parity, stop bits and data size */ + atmel_uart_writel(port, ATMEL_US_MR, mode); + + /* + * when switching the mode, set the RTS line state according to the + * new mode, otherwise keep the former state + */ + if ((old_mode & ATMEL_US_USMODE) != (mode & ATMEL_US_USMODE)) { + unsigned int rts_state; + + if ((mode & ATMEL_US_USMODE) == ATMEL_US_USMODE_HWHS) { + /* let the hardware control the RTS line */ + rts_state = ATMEL_US_RTSDIS; + } else { + /* force RTS line to low level */ + rts_state = ATMEL_US_RTSEN; + } + + atmel_uart_writel(port, ATMEL_US_CR, rts_state); + } + atmel_uart_writel(port, ATMEL_US_CR, ATMEL_US_RSTSTA | ATMEL_US_RSTRX); atmel_uart_writel(port, ATMEL_US_CR, ATMEL_US_TXEN | ATMEL_US_RXEN); atmel_port->tx_stopped = false; -- 2.17.1