Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp748299pxj; Thu, 10 Jun 2021 11:42:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxdLdGSF9anIGMmxxCxRVeS6c7GBfmzCqZ0DDtWydwl949lJHHIUqfLaAT4T2gkxZQfkx3F X-Received: by 2002:a17:906:22c6:: with SMTP id q6mr37129eja.275.1623350530265; Thu, 10 Jun 2021 11:42:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623350530; cv=none; d=google.com; s=arc-20160816; b=pZcMWDIoNbNxhoLbrr8XijseaQXROzL6MGz4mJnHdOz+IulMVkkjuuTdS5UD+mKYnh CGylTS6wWTmQgfv1ld6q5tmufcs4eCRZGTuKskmVVYeLeJeuktKLUjVpX/nOheET8gLU 9BpTvggLY9Qvr7sSAnzfChDySyaAKw+nNxLnL9O5tTRMHfy7Hz/9FaXZnDUA+iON63KE pWTAJLyiBsXUQqQX+M3NHlqr+fsj5L1g4AB0tIhDlW7PxIvkgz/ieymmhGAHgzc54k4e bPMkKcFjWbRNPEHXRaPo18/EQZXKEHYpK3TbOaW1Qwq2bboV/Rzc1zeKCtX8OKOllYfJ ooCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date; bh=08hgeK7OrKCes3W+UCrDqkbOQzo/F1Gi3EpXucsHH/M=; b=0DqK84Wi3h4TOAvi3v8aw15KNvKVSZy2X8JGoHNnBczQWF8WnZdTbiy/KamWHUL9cw UOEiULAHDmCdznD872OwoT0tBI3BmDROPFZZz7Sm3sKhqTMmWqT2cnecc/7GUzYlERSM 4jXCRsOvxTp+lsnkflFyq4doHvJYaAA5oIBp0/aoXkI1Ci7nsCeSpMpSfTBCXHYsQSjE xXetO/nQaXJpkqKwgyY1BrWGffkIS64UXXgxKktHM7ekchtjiAVjmW06BsmmdMou+1+D W4X8hVy9U265EcutjT2+Vv//ta4Hvpmp5obnr8geqRv9OX+YATqs8Mr1Ujm78E3FSinB wQ0Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 4si2931825ejm.546.2021.06.10.11.41.46; Thu, 10 Jun 2021 11:42:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230166AbhFJSke (ORCPT + 99 others); Thu, 10 Jun 2021 14:40:34 -0400 Received: from angie.orcam.me.uk ([78.133.224.34]:41632 "EHLO angie.orcam.me.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230481AbhFJSkc (ORCPT ); Thu, 10 Jun 2021 14:40:32 -0400 Received: by angie.orcam.me.uk (Postfix, from userid 500) id 1FBF79200BB; Thu, 10 Jun 2021 20:38:34 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id 19DB59200B4; Thu, 10 Jun 2021 20:38:34 +0200 (CEST) Date: Thu, 10 Jun 2021 20:38:34 +0200 (CEST) From: "Maciej W. Rozycki" To: Greg Kroah-Hartman , Jiri Slaby , Thomas Bogendoerfer cc: linux-mips@vger.kernel.org, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/5] serial: 8250: Actually allow UPF_MAGIC_MULTIPLIER baud rates In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Support for magic baud rate divisors of 32770 and 32769 used with SMSC Super I/O chips for extra baud rates of 230400 and 460800 respectively where base rate is 115200[1] has been added around Linux 2.5.64, which predates our repo history, but the origin could be identified as commit 2a717aad772f ("Merge with Linux 2.5.64.") with the old MIPS/Linux repo also at: . Code that is now in `serial8250_do_get_divisor' was added back then to `serial8250_get_divisor', but that code would only ever trigger if one of the higher baud rates was actually requested, and that cannot ever happen, because the earlier call to `serial8250_get_baud_rate' never returns them. This is because it calls `uart_get_baud_rate' with the maximum requested being the base rate, that is clk/16 or 115200 for SMSC chips at their nominal clock rate. Fix it then and allow UPF_MAGIC_MULTIPLIER baud rates to be selected, by requesting the maximum baud rate of clk/4 rather than clk/16 if the flag has been set. Also correct the minimum baud rate, observing that these ports only support actual (non-magic) divisors of up to 32767 only. References: [1] "FDC37M81x, PC98/99 Compliant Enhanced Super I/O Controller with Keyboard/Mouse Wake-Up", Standard Microsystems Corporation, Rev. 03/27/2000, Table 31 - "Baud Rates", p. 77 Signed-off-by: Maciej W. Rozycki Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") --- drivers/tty/serial/8250/8250_port.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) linux-serial-8250-magic-multiplier-baud-rate.diff Index: linux-malta-cbus-uart/drivers/tty/serial/8250/8250_port.c =================================================================== --- linux-malta-cbus-uart.orig/drivers/tty/serial/8250/8250_port.c +++ linux-malta-cbus-uart/drivers/tty/serial/8250/8250_port.c @@ -2659,6 +2659,21 @@ static unsigned int serial8250_get_baud_ struct ktermios *old) { unsigned int tolerance = port->uartclk / 100; + unsigned int min; + unsigned int max; + + /* + * Handle magic divisors for baud rates above baud_base on SMSC + * Super I/O chips. Enable custom rates of clk/4 and clk/8, but + * disable divisor values beyond 32767, which are unavailable. + */ + if (port->flags & UPF_MAGIC_MULTIPLIER) { + min = port->uartclk / 16 / UART_DIV_MAX >> 1; + max = (port->uartclk + tolerance) / 4; + } else { + min = port->uartclk / 16 / UART_DIV_MAX; + max = (port->uartclk + tolerance) / 16; + } /* * Ask the core to calculate the divisor for us. @@ -2666,9 +2681,7 @@ static unsigned int serial8250_get_baud_ * slower than nominal still match standard baud rates without * causing transmission errors. */ - return uart_get_baud_rate(port, termios, old, - port->uartclk / 16 / UART_DIV_MAX, - (port->uartclk + tolerance) / 16); + return uart_get_baud_rate(port, termios, old, min, max); } /*