linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alex Elder <elder@linaro.org>
To: gregkh@linuxfoundation.org
Cc: heikki.krogerus@linux.intel.com, david.daney@cavium.com,
	loic.poulain@intel.com, linux-serial@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH] serial: 8250_dw: support high baudrates if possible
Date: Fri, 27 Jun 2014 12:25:20 -0500	[thread overview]
Message-ID: <1403889920-1127-1-git-send-email-elder@linaro.org> (raw)

Currently the Synopsys DesignWare 8250 driver assumes its UART clock
runs at a fixed rate.  If a "real" clock was set up using the common
clock framework, and that clock's rate is adjustable, it may be
possible to support a wider range of baud rates by changing the
UART clock rate.

This is done by setting up a uart_port->set_termios method that
requests a clock rate change if a different rate might make it
more likely to achieve a specified baud.

Signed-off-by: Alex Elder <elder@linaro.org>
---
This patch is also available here:
    http://git.linaro.org/landing-teams/working/broadcom/kernel.git
    Branch review/dw8250_clock

 drivers/tty/serial/8250/8250_dw.c | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c
index 51b307a..013aa9b 100644
--- a/drivers/tty/serial/8250/8250_dw.c
+++ b/drivers/tty/serial/8250/8250_dw.c
@@ -242,6 +242,43 @@ dw8250_do_pm(struct uart_port *port, unsigned int state, unsigned int old)
 		pm_runtime_put_sync_suspend(port->dev);
 }
 
+/*
+ * If our clock was configured through the common clock framework we
+ * might be able to support a wider range of baud rates by changing
+ * its frequency.  For the "traditional" baud rates (115200 or
+ * less), request the conventional 1.8432 MHz clock.  The clock
+ * frequency needs to be at least 16 times the baud rate, so
+ * use 16 times the requested rate for those higher than 115200.
+ */
+static void
+dw8250_set_termios(struct uart_port *p, struct ktermios *new,
+			struct ktermios *old)
+{
+	struct dw8250_data *data = p->private_data;
+
+	if (!IS_ERR(data->clk)) {
+		speed_t baud;
+		unsigned int rate;
+
+		baud = tty_termios_baud_rate(new);
+		BUG_ON(baud > (speed_t)UINT_MAX);
+		rate = 16 * max(115200U, (unsigned int)baud);
+
+		/*
+		 * Request a different clock rate if necessary, and
+		 * record it if successful.
+		 */
+		if (rate != p->uartclk) {
+			BUG_ON(!data->clk);
+			if (!clk_set_rate(data->clk, (unsigned long)rate))
+				p->uartclk = rate;
+		}
+	}
+
+	/* The standard code does most of the work. */
+	serial8250_do_set_termios(p, new, old);
+}
+
 static bool dw8250_dma_filter(struct dma_chan *chan, void *param)
 {
 	struct dw8250_data *data = param;
@@ -417,6 +454,7 @@ static int dw8250_probe(struct platform_device *pdev)
 	uart.port.iotype = UPIO_MEM;
 	uart.port.serial_in = dw8250_serial_in;
 	uart.port.serial_out = dw8250_serial_out;
+	uart.port.set_termios = dw8250_set_termios;
 	uart.port.private_data = data;
 
 	if (pdev->dev.of_node) {
-- 
1.9.1


             reply	other threads:[~2014-06-27 17:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-27 17:25 Alex Elder [this message]
2014-06-28 15:36 ` [PATCH] serial: 8250_dw: support high baudrates if possible One Thousand Gnomes
2014-06-28 20:15   ` Alex Elder
2014-07-01 22:02     ` One Thousand Gnomes
2014-07-02  0:15       ` Alex Elder

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1403889920-1127-1-git-send-email-elder@linaro.org \
    --to=elder@linaro.org \
    --cc=david.daney@cavium.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=loic.poulain@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).