From patchwork Fri Sep 21 17:59:59 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 11627 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 42F5619D196 for ; Fri, 21 Sep 2012 18:05:55 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id 85BDFA191B4 for ; Fri, 21 Sep 2012 18:05:54 +0000 (UTC) Received: by ieje10 with SMTP id e10so5555411iej.11 for ; Fri, 21 Sep 2012 11:05:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:mime-version:content-type :x-gm-message-state; bh=lekt01xFaivM4iRs3PqbghcvMmsXxMBNFAThlXI29z8=; b=PdLwPQlgHs1xNzc85kfxTvEjDrf42SEJBuG8CMFgWQIvrtFZvvtF9uFjjztPd5Vi5g gBqxiHgfgsf2d73bV6s6vcl7mFUCnjHbKKQVFyMQPccJk6WtKI5F0LLf3GnbF87l+EQu ORRiJU/ykntwtY5takiLZKmPbXqN8xFNZY24BEOLUGknrAzPz5IWqFyRy+p09bSK+MXW PYvhSvGqpj/pXiTWF1F2y84gWAiHNUq3bcGKsW8tQjvlGGAmeWjOettfga9zeKttSN90 adsw1V/NIv4cST7B8W7L2Ub+YlY/MdUgYFZfG1u+kxUraiLwyIDlJNsOkXqYwg3TDUup cyKw== Received: by 10.42.109.194 with SMTP id m2mr4478880icp.48.1348250753895; Fri, 21 Sep 2012 11:05:53 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.184.232 with SMTP id ex8csp142390igc; Fri, 21 Sep 2012 11:05:52 -0700 (PDT) Received: by 10.204.128.65 with SMTP id j1mr2601099bks.93.1348250752132; Fri, 21 Sep 2012 11:05:52 -0700 (PDT) Received: from eu1sys200aog109.obsmtp.com (eu1sys200aog109.obsmtp.com [207.126.144.127]) by mx.google.com with SMTP id b13si10407969bka.115.2012.09.21.11.04.49 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 21 Sep 2012 11:05:51 -0700 (PDT) Received-SPF: neutral (google.com: 207.126.144.127 is neither permitted nor denied by best guess record for domain of linus.walleij@stericsson.com) client-ip=207.126.144.127; Authentication-Results: mx.google.com; spf=neutral (google.com: 207.126.144.127 is neither permitted nor denied by best guess record for domain of linus.walleij@stericsson.com) smtp.mail=linus.walleij@stericsson.com Received: from beta.dmz-eu.st.com ([164.129.1.35]) (using TLSv1) by eu1sys200aob109.postini.com ([207.126.147.11]) with SMTP ID DSNKUFyrNHlv+TSeyf0HnTcpmJZliyYH6vtA@postini.com; Fri, 21 Sep 2012 18:05:51 UTC Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 71B92212; Fri, 21 Sep 2012 18:00:11 +0000 (GMT) Received: from relay1.stm.gmessaging.net (unknown [10.230.100.17]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id DE0A14EDA; Fri, 21 Sep 2012 18:00:10 +0000 (GMT) Received: from exdcvycastm003.EQ1STM.local (alteon-source-exch [10.230.100.61]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "exdcvycastm003", Issuer "exdcvycastm003" (not verified)) by relay1.stm.gmessaging.net (Postfix) with ESMTPS id 3CF6924C2C0; Fri, 21 Sep 2012 20:00:01 +0200 (CEST) Received: from steludxu4075.lud.stericsson.com (10.230.100.153) by smtp.stericsson.com (10.230.100.1) with Microsoft SMTP Server (TLS) id 8.3.83.0; Fri, 21 Sep 2012 20:00:10 +0200 From: Linus Walleij To: , Greg Kroah-Hartman , Russell King , Alan Cox Cc: , Anmar Oueja , Linus Walleij , Par-Gunnar Hjalmdahl , Guillaume Jaunet , Christophe Arnal , Matthias Locher , Rajanikanth HV Subject: [PATCH] RFC: serial: pl011: allow very high baudrates Date: Fri, 21 Sep 2012 19:59:59 +0200 Message-ID: <1348250399-5651-1-git-send-email-linus.walleij@stericsson.com> X-Mailer: git-send-email 1.7.11.3 MIME-Version: 1.0 X-Gm-Message-State: ALoCoQl53tMeN3eHJqR7gY/BjWwZh6Tw4db1mIIzZPc5A1CzmGb5aWzs+sZHpULpuCsTc20IEeAe From: Linus Walleij The ST Microelectronics variant of the PL011 is capable of supporting very high non-standard baud rates, even above 4 Mbps. Mostly this works, but when we try to use 4050000 baud, the code in tty_termios_encode_baud_rate(), which is called from uart_get_baud_rate() will do some fuzzy matching and "snap" the baudrate to 4000000 baud, which happens to be in the baud_table[]. However there is an encouraging comment from Alan Cox above the tty_termios_input_baud_rate() function stating that device drivers should use ->c_[io]speed directly as they are updated. I tried this, but that requires the driver to handle a few odd cases such as when the ->c_ispeed and ->c_ospeed differs, or when they are both send it as 0 (which happens a lot in the kernel) so that would require pushing a lot of duplicate code into the driver to get the same behaviour. Here I take a middle-ground approach: if the baud rate of ->c_ispeed and ->c_ospeed differs, or if either of them is zero, I still call the uart_get_baud_rate() function, but root the baudrate to what the block can handle at max. Cc: Par-Gunnar Hjalmdahl Signed-off-by: Guillaume Jaunet Signed-off-by: Christophe Arnal Signed-off-by: Matthias Locher Signed-off-by: Rajanikanth HV Signed-off-by: Linus Walleij --- After discussing with Alan and Russell I still don't feel this is the right solution, but it demonstrates Russell's point of how intelligence (here just some checking of ->c_[io]speed, but you get the point) is moved out of the serial/tty core and out into the drivers if we do this. Maybe a new function is needed in the serial core, one that will just call out to serial and tty like this if the c_[io]speed differs or either is zero? --- drivers/tty/serial/amba-pl011.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c index cb9f694..778a6a5 100644 --- a/drivers/tty/serial/amba-pl011.c +++ b/drivers/tty/serial/amba-pl011.c @@ -1492,18 +1492,36 @@ pl011_set_termios(struct uart_port *port, struct ktermios *termios, struct uart_amba_port *uap = (struct uart_amba_port *)port; unsigned int lcr_h, old_cr; unsigned long flags; - unsigned int baud, quot, clkdiv; + unsigned int max_baud, baud, quot; if (uap->vendor->oversampling) - clkdiv = 8; + max_baud = port->uartclk / 8; else - clkdiv = 16; + max_baud = port->uartclk / 16; /* - * Ask the core to calculate the divisor for us. + * For "zero" speeds or in the case where in and output + * speed differs, fall back on using the serial core to + * determine applicable baudrate. */ - baud = uart_get_baud_rate(port, termios, old, 0, - port->uartclk / clkdiv); + if ((termios->c_ispeed != termios->c_ospeed) || + (termios->c_ispeed == 0) || + (termios->c_ospeed == 0)) + baud = uart_get_baud_rate(port, termios, old, 0, + max_baud); + else { + /* + * Else we just use the requested speed from + * termios. But we sanity check it so as not to + * exceed hardware limits. + */ + baud = termios->c_ospeed; + if (baud > max_baud) + baud = max_baud; + } + dev_dbg(uap->port.dev, "c_ispeed: %u, c_ospeed: %u, " + "max_baud: %u, resulting baud rate %u bps\n", + termios->c_ispeed, termios->c_ospeed, max_baud, baud); if (baud > port->uartclk/16) quot = DIV_ROUND_CLOSEST(port->uartclk * 8, baud);