From: Geert Uytterhoeven <geert+renesas@glider.be>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jiri Slaby <jslaby@suse.com>
Cc: Simon Horman <horms+renesas@verge.net.au>,
Magnus Damm <magnus.damm@gmail.com>,
Yoshinori Sato <ysato@users.sourceforge.jp>,
linux-serial@vger.kernel.org, linux-sh@vger.kernel.org,
Geert Uytterhoeven <geert+renesas@glider.be>
Subject: [PATCH 5/5] serial: sh-sci: Add support for SCIFA/SCIFB variable sampling rates
Date: Mon, 04 Jan 2016 13:45:22 +0000 [thread overview]
Message-ID: <1451915122-30219-6-git-send-email-geert+renesas@glider.be> (raw)
In-Reply-To: <1451915122-30219-1-git-send-email-geert+renesas@glider.be>
Add support for sparse variable sampling rates on SCIFA and SCIFB.
According to the datasheet, sampling rate 1/5 needs a small quirk to
avoid corrupting the first byte received.
This increases the range and accuracy of supported baud rates.
E.g. on r8a7791/koelsch:
- Supports now 134, 150, and standard 500000-4000000 bps,
- Perfect match for 134, 150, 500000, 1000000, 2000000, and 4000000
bps,
- Accuracy has increased for most standard bps values.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
Tested on:
- r8a7791/koelsch (Fully tested on SCIFA and SCIFB),
- r8a7740/armadillo (Fully tested on SCIFA and SCIFB),
- sh73a0/kzm9g (Fully tested on SCIFA only, no easy access to SCIFB),
- r8a73a4/ape6evm (SCIFA/FTDI console at 460800 bps, no easy access to
SCIFB).
---
drivers/tty/serial/sh-sci.c | 29 +++++++++++++++++++++++++++--
1 file changed, 27 insertions(+), 2 deletions(-)
diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 17188fc4b1b32439..4f638c480c5b270a 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -89,6 +89,10 @@ enum SCI_CLKS {
#define SCI_SR(x) BIT((x) - 1)
#define SCI_SR_RANGE(x, y) GENMASK((y) - 1, (x) - 1)
+#define SCI_SR_SCIFAB SCI_SR(5) | SCI_SR(7) | SCI_SR(11) | \
+ SCI_SR(13) | SCI_SR(16) | SCI_SR(17) | \
+ SCI_SR(19) | SCI_SR(27)
+
#define min_sr(_port) ffs((_port)->sampling_rate_mask)
#define max_sr(_port) fls((_port)->sampling_rate_mask)
@@ -2206,6 +2210,17 @@ done:
uart_update_timeout(port, termios->c_cflag, baud);
if (best_clk >= 0) {
+ if (port->type = PORT_SCIFA || port->type = PORT_SCIFB)
+ switch (srr + 1) {
+ case 5: smr_val |= SCSMR_SRC_5; break;
+ case 7: smr_val |= SCSMR_SRC_7; break;
+ case 11: smr_val |= SCSMR_SRC_11; break;
+ case 13: smr_val |= SCSMR_SRC_13; break;
+ case 16: smr_val |= SCSMR_SRC_16; break;
+ case 17: smr_val |= SCSMR_SRC_17; break;
+ case 19: smr_val |= SCSMR_SRC_19; break;
+ case 27: smr_val |= SCSMR_SRC_27; break;
+ }
smr_val |= cks;
dev_dbg(port->dev,
"SCR 0x%x SMR 0x%x BRR %u CKS 0x%x DL %u SRR %u\n",
@@ -2254,6 +2269,16 @@ done:
scr_val |= s->cfg->scscr & ~(SCSCR_CKE1 | SCSCR_CKE0);
dev_dbg(port->dev, "SCSCR 0x%x\n", scr_val);
serial_port_out(port, SCSCR, scr_val);
+ if ((srr + 1 = 5) &&
+ (port->type = PORT_SCIFA || port->type = PORT_SCIFB)) {
+ /*
+ * In asynchronous mode, when the sampling rate is 1/5, first
+ * received data may become invalid on some SCIFA and SCIFB.
+ * To avoid this problem wait more than 1 serial data time (1
+ * bit time x serial data number) after setting SCSCR.RE = 1.
+ */
+ udelay(DIV_ROUND_UP(10 * 1000000, baud));
+ }
#ifdef CONFIG_SERIAL_SH_SCI_DMA
/*
@@ -2550,7 +2575,7 @@ static int sci_init_single(struct platform_device *dev,
port->fifosize = 256;
sci_port->overrun_reg = SCxSR;
sci_port->overrun_mask = SCIFA_ORER;
- sci_port->sampling_rate_mask = SCI_SR(16);
+ sci_port->sampling_rate_mask = SCI_SR_SCIFAB;
break;
case PORT_HSCIF:
port->fifosize = 128;
@@ -2562,7 +2587,7 @@ static int sci_init_single(struct platform_device *dev,
port->fifosize = 64;
sci_port->overrun_reg = SCxSR;
sci_port->overrun_mask = SCIFA_ORER;
- sci_port->sampling_rate_mask = SCI_SR(16);
+ sci_port->sampling_rate_mask = SCI_SR_SCIFAB;
break;
case PORT_SCIF:
port->fifosize = 16;
--
1.9.1
prev parent reply other threads:[~2016-01-04 13:45 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-04 13:45 [PATCH 0/5] serial: sh-sci: Add support for SCIFA/SCIFB variable sampling rates Geert Uytterhoeven
2016-01-04 13:45 ` [PATCH 1/5] serial: sh-sci: Add more Serial Mode Register documentation Geert Uytterhoeven
2016-01-04 13:45 ` [PATCH 2/5] serial: sh-sci: Preserve SCIFA/SCIFB bit rate config for serial console Geert Uytterhoeven
2016-01-04 13:45 ` [PATCH 3/5] serial: sh-sci: Use premultiplier to handle half sampling rate Geert Uytterhoeven
2016-01-04 13:45 ` [PATCH 4/5] serial: sh-sci: Use a bitmask to indicate supported sampling rates Geert Uytterhoeven
2016-01-04 13:45 ` Geert Uytterhoeven [this message]
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=1451915122-30219-6-git-send-email-geert+renesas@glider.be \
--to=geert+renesas@glider.be \
--cc=gregkh@linuxfoundation.org \
--cc=horms+renesas@verge.net.au \
--cc=jslaby@suse.com \
--cc=linux-serial@vger.kernel.org \
--cc=linux-sh@vger.kernel.org \
--cc=magnus.damm@gmail.com \
--cc=ysato@users.sourceforge.jp \
/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).