All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] serial: sh-sci: Updated calculation of bit error rate and bit rate
@ 2014-07-14  7:09 ` Nobuhiro Iwamatsu
  0 siblings, 0 replies; 10+ messages in thread
From: Nobuhiro Iwamatsu @ 2014-07-14  7:09 UTC (permalink / raw)
  To: linux-sh
  Cc: gregkh, linux-serial, horms+renesas, magnus.damm, Nobuhiro Iwamatsu

Currently, the decimal point is discarded calculation of BRR.
Therefore, it can not calculate a value close to the correct value.
This patch fixes this problem by using DIV_ROUND_CLOSEST.

Signed-off-by: Nobuhiro Iwamatsu <nobuhiro.iwamatsu.yj@renesas.com>
---
 drivers/tty/serial/sh-sci.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 88236da..ce80137 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -1796,11 +1796,13 @@ static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq,
 	for (sr = 8; sr <= 32; sr++) {
 		for (c = 0; c <= 3; c++) {
 			/* integerized formulas from HSCIF documentation */
-			br = freq / (sr * (1 << (2 * c + 1)) * bps) - 1;
+			br = DIV_ROUND_CLOSEST(freq, (sr *
+					      (1 << (2 * c + 1)) * bps)) - 1;
 			if (br < 0 || br > 255)
 				continue;
-			err = freq / ((br + 1) * bps * sr *
-			      (1 << (2 * c + 1)) / 1000) - 1000;
+			err = DIV_ROUND_CLOSEST(freq, ((br + 1) * bps * sr *
+					       (1 << (2 * c + 1)) / 1000)) -
+					       1000;
 			if (min_err > err) {
 				min_err = err;
 				*brr = br;
-- 
2.0.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 1/3] serial: sh-sci: Updated calculation of bit error rate and bit rate
@ 2014-07-14  7:09 ` Nobuhiro Iwamatsu
  0 siblings, 0 replies; 10+ messages in thread
From: Nobuhiro Iwamatsu @ 2014-07-14  7:09 UTC (permalink / raw)
  To: linux-sh
  Cc: gregkh, linux-serial, horms+renesas, magnus.damm, Nobuhiro Iwamatsu

Currently, the decimal point is discarded calculation of BRR.
Therefore, it can not calculate a value close to the correct value.
This patch fixes this problem by using DIV_ROUND_CLOSEST.

Signed-off-by: Nobuhiro Iwamatsu <nobuhiro.iwamatsu.yj@renesas.com>
---
 drivers/tty/serial/sh-sci.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 88236da..ce80137 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -1796,11 +1796,13 @@ static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq,
 	for (sr = 8; sr <= 32; sr++) {
 		for (c = 0; c <= 3; c++) {
 			/* integerized formulas from HSCIF documentation */
-			br = freq / (sr * (1 << (2 * c + 1)) * bps) - 1;
+			br = DIV_ROUND_CLOSEST(freq, (sr *
+					      (1 << (2 * c + 1)) * bps)) - 1;
 			if (br < 0 || br > 255)
 				continue;
-			err = freq / ((br + 1) * bps * sr *
-			      (1 << (2 * c + 1)) / 1000) - 1000;
+			err = DIV_ROUND_CLOSEST(freq, ((br + 1) * bps * sr *
+					       (1 << (2 * c + 1)) / 1000)) -
+					       1000;
 			if (min_err > err) {
 				min_err = err;
 				*brr = br;
-- 
2.0.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/3] serial: sh-sci: Fix range check of bit-rate for HSCIF
  2014-07-14  7:09 ` Nobuhiro Iwamatsu
@ 2014-07-14  7:09   ` Nobuhiro Iwamatsu
  -1 siblings, 0 replies; 10+ messages in thread
From: Nobuhiro Iwamatsu @ 2014-07-14  7:09 UTC (permalink / raw)
  To: linux-sh
  Cc: gregkh, linux-serial, horms+renesas, magnus.damm, Nobuhiro Iwamatsu

If bit-rate calculation result of HSCIF is expect 255 from 0,
driver does not calculate error bit. However, we need to round
the value to calculate error bit in the case of negative value.
This rounds the value of bit-rate using clamp(), and bit-rate is the
case of negative value, it enables the calculation of the error bit.

Signed-off-by: Nobuhiro Iwamatsu <nobuhiro.iwamatsu.yj@renesas.com>
---
 drivers/tty/serial/sh-sci.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index ce80137..7f571a8 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -1798,8 +1798,7 @@ static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq,
 			/* integerized formulas from HSCIF documentation */
 			br = DIV_ROUND_CLOSEST(freq, (sr *
 					      (1 << (2 * c + 1)) * bps)) - 1;
-			if (br < 0 || br > 255)
-				continue;
+			br = clamp(br, 0, 255);
 			err = DIV_ROUND_CLOSEST(freq, ((br + 1) * bps * sr *
 					       (1 << (2 * c + 1)) / 1000)) -
 					       1000;
-- 
2.0.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/3] serial: sh-sci: Fix range check of bit-rate for HSCIF
@ 2014-07-14  7:09   ` Nobuhiro Iwamatsu
  0 siblings, 0 replies; 10+ messages in thread
From: Nobuhiro Iwamatsu @ 2014-07-14  7:09 UTC (permalink / raw)
  To: linux-sh
  Cc: gregkh, linux-serial, horms+renesas, magnus.damm, Nobuhiro Iwamatsu

If bit-rate calculation result of HSCIF is expect 255 from 0,
driver does not calculate error bit. However, we need to round
the value to calculate error bit in the case of negative value.
This rounds the value of bit-rate using clamp(), and bit-rate is the
case of negative value, it enables the calculation of the error bit.

Signed-off-by: Nobuhiro Iwamatsu <nobuhiro.iwamatsu.yj@renesas.com>
---
 drivers/tty/serial/sh-sci.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index ce80137..7f571a8 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -1798,8 +1798,7 @@ static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq,
 			/* integerized formulas from HSCIF documentation */
 			br = DIV_ROUND_CLOSEST(freq, (sr *
 					      (1 << (2 * c + 1)) * bps)) - 1;
-			if (br < 0 || br > 255)
-				continue;
+			br = clamp(br, 0, 255);
 			err = DIV_ROUND_CLOSEST(freq, ((br + 1) * bps * sr *
 					       (1 << (2 * c + 1)) / 1000)) -
 					       1000;
-- 
2.0.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 3/3] serial: sh-sci: Add calculation recive margin for HSCIF
  2014-07-14  7:09 ` Nobuhiro Iwamatsu
@ 2014-07-14  7:10   ` Nobuhiro Iwamatsu
  -1 siblings, 0 replies; 10+ messages in thread
From: Nobuhiro Iwamatsu @ 2014-07-14  7:10 UTC (permalink / raw)
  To: linux-sh
  Cc: gregkh, linux-serial, horms+renesas, magnus.damm, Nobuhiro Iwamatsu

When the error of the same bit rate is detected, we will need to select
the recive margin is large. Current code holds the minimum error, it does
not have to check the recive margin. This adds this calculation.

Signed-off-by: Nobuhiro Iwamatsu <nobuhiro.iwamatsu.yj@renesas.com>
---
 drivers/tty/serial/sh-sci.c | 77 ++++++++++++++++++++++++++++++++++-----------
 1 file changed, 59 insertions(+), 18 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 7f571a8..d879c0c 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -1783,13 +1783,30 @@ static unsigned int sci_scbrr_calc(struct sci_port *s, unsigned int bps,
 	return ((freq + 16 * bps) / (32 * bps) - 1);
 }
 
+/* calculate frame length from SMR */
+static int sci_baud_calc_frame_len(unsigned int smr_val)
+{
+	int len = 10;
+
+	if (smr_val & SCSMR_CHR)
+		len--;
+	if (smr_val & SCSMR_PE)
+		len++;
+	if (smr_val & SCSMR_STOP)
+		len++;
+
+	return len;
+}
+
+
 /* calculate sample rate, BRR, and clock select for HSCIF */
 static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq,
 				int *brr, unsigned int *srr,
-				unsigned int *cks)
+				unsigned int *cks, int frame_len)
 {
-	int sr, c, br, err;
+	int sr, c, br, err, recv_margin;
 	int min_err = 1000; /* 100% */
+	int recv_max_margin = 0;
 
 	/* Find the combination of sample rate and clock select with the
 	   smallest deviation from the desired baud rate. */
@@ -1802,12 +1819,35 @@ static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq,
 			err = DIV_ROUND_CLOSEST(freq, ((br + 1) * bps * sr *
 					       (1 << (2 * c + 1)) / 1000)) -
 					       1000;
+			if (err < 0)
+				continue;
+
+			/* Calc recv margin
+			 * M: Receive margin (%)
+			 * N: Ratio of bit rate to clock (N = sampling rate)
+			 * D: Clock duty (D = 0 to 1.0)
+			 * L: Frame length (L = 9 to 12)
+			 * F: Absolute value of clock frequency deviation
+			 *
+			 *  M = |(0.5 - 1 / 2 * N) - ((L - 0.5) * F) -
+			 *      (|D - 0.5| / N * (1 + F))|
+			 *  NOTE: Usually, treat D for 0.5, F is 0 by this
+			 *        calculation.
+			 */
+			recv_margin = abs((500 -
+					DIV_ROUND_CLOSEST(1000, sr << 1)) / 10);
 			if (min_err > err) {
 				min_err = err;
-				*brr = br;
-				*srr = sr - 1;
-				*cks = c;
-			}
+				recv_max_margin = recv_margin;
+			} else if ((min_err = err) &&
+				   (recv_margin > recv_max_margin))
+				recv_max_margin = recv_margin;
+			else
+				continue;
+
+			*brr = br;
+			*srr = sr - 1;
+			*cks = c;
 		}
 	}
 
@@ -1841,10 +1881,19 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
 {
 	struct sci_port *s = to_sci_port(port);
 	struct plat_sci_reg *reg;
-	unsigned int baud, smr_val, max_baud, cks = 0;
+	unsigned int baud, smr_val = 0, max_baud, cks = 0;
 	int t = -1;
 	unsigned int srr = 15;
 
+	if ((termios->c_cflag & CSIZE) = CS7)
+		smr_val |= SCSMR_CHR;
+	if (termios->c_cflag & PARENB)
+		smr_val |= SCSMR_PE;
+	if (termios->c_cflag & PARODD)
+		smr_val |= SCSMR_PE | SCSMR_ODD;
+	if (termios->c_cflag & CSTOPB)
+		smr_val |= SCSMR_STOP;
+
 	/*
 	 * earlyprintk comes here early on with port->uartclk set to zero.
 	 * the clock framework is not up and running at this point so here
@@ -1858,8 +1907,9 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
 	baud = uart_get_baud_rate(port, termios, old, 0, max_baud);
 	if (likely(baud && port->uartclk)) {
 		if (s->cfg->type = PORT_HSCIF) {
+			int frame_len = sci_baud_calc_frame_len(smr_val);
 			sci_baud_calc_hscif(baud, port->uartclk, &t, &srr,
-					    &cks);
+					    &cks, frame_len);
 		} else {
 			t = sci_scbrr_calc(s, baud, port->uartclk);
 			for (cks = 0; t >= 256 && cks <= 3; cks++)
@@ -1871,16 +1921,7 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
 
 	sci_reset(port);
 
-	smr_val = serial_port_in(port, SCSMR) & 3;
-
-	if ((termios->c_cflag & CSIZE) = CS7)
-		smr_val |= SCSMR_CHR;
-	if (termios->c_cflag & PARENB)
-		smr_val |= SCSMR_PE;
-	if (termios->c_cflag & PARODD)
-		smr_val |= SCSMR_PE | SCSMR_ODD;
-	if (termios->c_cflag & CSTOPB)
-		smr_val |= SCSMR_STOP;
+	smr_val |= serial_port_in(port, SCSMR) & 3;
 
 	uart_update_timeout(port, termios->c_cflag, baud);
 
-- 
2.0.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 3/3] serial: sh-sci: Add calculation recive margin for HSCIF
@ 2014-07-14  7:10   ` Nobuhiro Iwamatsu
  0 siblings, 0 replies; 10+ messages in thread
From: Nobuhiro Iwamatsu @ 2014-07-14  7:10 UTC (permalink / raw)
  To: linux-sh
  Cc: gregkh, linux-serial, horms+renesas, magnus.damm, Nobuhiro Iwamatsu

When the error of the same bit rate is detected, we will need to select
the recive margin is large. Current code holds the minimum error, it does
not have to check the recive margin. This adds this calculation.

Signed-off-by: Nobuhiro Iwamatsu <nobuhiro.iwamatsu.yj@renesas.com>
---
 drivers/tty/serial/sh-sci.c | 77 ++++++++++++++++++++++++++++++++++-----------
 1 file changed, 59 insertions(+), 18 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 7f571a8..d879c0c 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -1783,13 +1783,30 @@ static unsigned int sci_scbrr_calc(struct sci_port *s, unsigned int bps,
 	return ((freq + 16 * bps) / (32 * bps) - 1);
 }
 
+/* calculate frame length from SMR */
+static int sci_baud_calc_frame_len(unsigned int smr_val)
+{
+	int len = 10;
+
+	if (smr_val & SCSMR_CHR)
+		len--;
+	if (smr_val & SCSMR_PE)
+		len++;
+	if (smr_val & SCSMR_STOP)
+		len++;
+
+	return len;
+}
+
+
 /* calculate sample rate, BRR, and clock select for HSCIF */
 static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq,
 				int *brr, unsigned int *srr,
-				unsigned int *cks)
+				unsigned int *cks, int frame_len)
 {
-	int sr, c, br, err;
+	int sr, c, br, err, recv_margin;
 	int min_err = 1000; /* 100% */
+	int recv_max_margin = 0;
 
 	/* Find the combination of sample rate and clock select with the
 	   smallest deviation from the desired baud rate. */
@@ -1802,12 +1819,35 @@ static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq,
 			err = DIV_ROUND_CLOSEST(freq, ((br + 1) * bps * sr *
 					       (1 << (2 * c + 1)) / 1000)) -
 					       1000;
+			if (err < 0)
+				continue;
+
+			/* Calc recv margin
+			 * M: Receive margin (%)
+			 * N: Ratio of bit rate to clock (N = sampling rate)
+			 * D: Clock duty (D = 0 to 1.0)
+			 * L: Frame length (L = 9 to 12)
+			 * F: Absolute value of clock frequency deviation
+			 *
+			 *  M = |(0.5 - 1 / 2 * N) - ((L - 0.5) * F) -
+			 *      (|D - 0.5| / N * (1 + F))|
+			 *  NOTE: Usually, treat D for 0.5, F is 0 by this
+			 *        calculation.
+			 */
+			recv_margin = abs((500 -
+					DIV_ROUND_CLOSEST(1000, sr << 1)) / 10);
 			if (min_err > err) {
 				min_err = err;
-				*brr = br;
-				*srr = sr - 1;
-				*cks = c;
-			}
+				recv_max_margin = recv_margin;
+			} else if ((min_err == err) &&
+				   (recv_margin > recv_max_margin))
+				recv_max_margin = recv_margin;
+			else
+				continue;
+
+			*brr = br;
+			*srr = sr - 1;
+			*cks = c;
 		}
 	}
 
@@ -1841,10 +1881,19 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
 {
 	struct sci_port *s = to_sci_port(port);
 	struct plat_sci_reg *reg;
-	unsigned int baud, smr_val, max_baud, cks = 0;
+	unsigned int baud, smr_val = 0, max_baud, cks = 0;
 	int t = -1;
 	unsigned int srr = 15;
 
+	if ((termios->c_cflag & CSIZE) == CS7)
+		smr_val |= SCSMR_CHR;
+	if (termios->c_cflag & PARENB)
+		smr_val |= SCSMR_PE;
+	if (termios->c_cflag & PARODD)
+		smr_val |= SCSMR_PE | SCSMR_ODD;
+	if (termios->c_cflag & CSTOPB)
+		smr_val |= SCSMR_STOP;
+
 	/*
 	 * earlyprintk comes here early on with port->uartclk set to zero.
 	 * the clock framework is not up and running at this point so here
@@ -1858,8 +1907,9 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
 	baud = uart_get_baud_rate(port, termios, old, 0, max_baud);
 	if (likely(baud && port->uartclk)) {
 		if (s->cfg->type == PORT_HSCIF) {
+			int frame_len = sci_baud_calc_frame_len(smr_val);
 			sci_baud_calc_hscif(baud, port->uartclk, &t, &srr,
-					    &cks);
+					    &cks, frame_len);
 		} else {
 			t = sci_scbrr_calc(s, baud, port->uartclk);
 			for (cks = 0; t >= 256 && cks <= 3; cks++)
@@ -1871,16 +1921,7 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
 
 	sci_reset(port);
 
-	smr_val = serial_port_in(port, SCSMR) & 3;
-
-	if ((termios->c_cflag & CSIZE) == CS7)
-		smr_val |= SCSMR_CHR;
-	if (termios->c_cflag & PARENB)
-		smr_val |= SCSMR_PE;
-	if (termios->c_cflag & PARODD)
-		smr_val |= SCSMR_PE | SCSMR_ODD;
-	if (termios->c_cflag & CSTOPB)
-		smr_val |= SCSMR_STOP;
+	smr_val |= serial_port_in(port, SCSMR) & 3;
 
 	uart_update_timeout(port, termios->c_cflag, baud);
 
-- 
2.0.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/3] serial: sh-sci: Updated calculation of bit error rate and bit rate
  2014-07-14  7:09 ` Nobuhiro Iwamatsu
@ 2014-07-22  1:37   ` Simon Horman
  -1 siblings, 0 replies; 10+ messages in thread
From: Simon Horman @ 2014-07-22  1:37 UTC (permalink / raw)
  To: Nobuhiro Iwamatsu; +Cc: linux-sh, gregkh, linux-serial, magnus.damm

On Mon, Jul 14, 2014 at 04:09:58PM +0900, Nobuhiro Iwamatsu wrote:
> Currently, the decimal point is discarded calculation of BRR.
> Therefore, it can not calculate a value close to the correct value.
> This patch fixes this problem by using DIV_ROUND_CLOSEST.
> 
> Signed-off-by: Nobuhiro Iwamatsu <nobuhiro.iwamatsu.yj@renesas.com>

All three patches:

Acked-by: Simon Horman <horms+renesas@verge.net.au>

> ---
>  drivers/tty/serial/sh-sci.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
> index 88236da..ce80137 100644
> --- a/drivers/tty/serial/sh-sci.c
> +++ b/drivers/tty/serial/sh-sci.c
> @@ -1796,11 +1796,13 @@ static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq,
>  	for (sr = 8; sr <= 32; sr++) {
>  		for (c = 0; c <= 3; c++) {
>  			/* integerized formulas from HSCIF documentation */
> -			br = freq / (sr * (1 << (2 * c + 1)) * bps) - 1;
> +			br = DIV_ROUND_CLOSEST(freq, (sr *
> +					      (1 << (2 * c + 1)) * bps)) - 1;
>  			if (br < 0 || br > 255)
>  				continue;
> -			err = freq / ((br + 1) * bps * sr *
> -			      (1 << (2 * c + 1)) / 1000) - 1000;
> +			err = DIV_ROUND_CLOSEST(freq, ((br + 1) * bps * sr *
> +					       (1 << (2 * c + 1)) / 1000)) -
> +					       1000;
>  			if (min_err > err) {
>  				min_err = err;
>  				*brr = br;
> -- 
> 2.0.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-sh" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/3] serial: sh-sci: Updated calculation of bit error rate and bit rate
@ 2014-07-22  1:37   ` Simon Horman
  0 siblings, 0 replies; 10+ messages in thread
From: Simon Horman @ 2014-07-22  1:37 UTC (permalink / raw)
  To: Nobuhiro Iwamatsu; +Cc: linux-sh, gregkh, linux-serial, magnus.damm

On Mon, Jul 14, 2014 at 04:09:58PM +0900, Nobuhiro Iwamatsu wrote:
> Currently, the decimal point is discarded calculation of BRR.
> Therefore, it can not calculate a value close to the correct value.
> This patch fixes this problem by using DIV_ROUND_CLOSEST.
> 
> Signed-off-by: Nobuhiro Iwamatsu <nobuhiro.iwamatsu.yj@renesas.com>

All three patches:

Acked-by: Simon Horman <horms+renesas@verge.net.au>

> ---
>  drivers/tty/serial/sh-sci.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
> index 88236da..ce80137 100644
> --- a/drivers/tty/serial/sh-sci.c
> +++ b/drivers/tty/serial/sh-sci.c
> @@ -1796,11 +1796,13 @@ static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq,
>  	for (sr = 8; sr <= 32; sr++) {
>  		for (c = 0; c <= 3; c++) {
>  			/* integerized formulas from HSCIF documentation */
> -			br = freq / (sr * (1 << (2 * c + 1)) * bps) - 1;
> +			br = DIV_ROUND_CLOSEST(freq, (sr *
> +					      (1 << (2 * c + 1)) * bps)) - 1;
>  			if (br < 0 || br > 255)
>  				continue;
> -			err = freq / ((br + 1) * bps * sr *
> -			      (1 << (2 * c + 1)) / 1000) - 1000;
> +			err = DIV_ROUND_CLOSEST(freq, ((br + 1) * bps * sr *
> +					       (1 << (2 * c + 1)) / 1000)) -
> +					       1000;
>  			if (min_err > err) {
>  				min_err = err;
>  				*brr = br;
> -- 
> 2.0.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-sh" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 3/3] serial: sh-sci: Add calculation recive margin for HSCIF
  2014-07-14  7:10   ` Nobuhiro Iwamatsu
@ 2015-11-02 13:56     ` Geert Uytterhoeven
  -1 siblings, 0 replies; 10+ messages in thread
From: Geert Uytterhoeven @ 2015-11-02 13:56 UTC (permalink / raw)
  To: Nobuhiro Iwamatsu
  Cc: Linux-sh list, Greg KH, linux-serial, Simon Horman, Magnus Damm

Hi Iwamatsu-san,

On Mon, Jul 14, 2014 at 9:10 AM, Nobuhiro Iwamatsu
<nobuhiro.iwamatsu.yj@renesas.com> wrote:
> When the error of the same bit rate is detected, we will need to select
> the recive margin is large. Current code holds the minimum error, it does
> not have to check the recive margin. This adds this calculation.
>
> Signed-off-by: Nobuhiro Iwamatsu <nobuhiro.iwamatsu.yj@renesas.com>

I know this patch was applied a while ago.

> ---
>  drivers/tty/serial/sh-sci.c | 77 ++++++++++++++++++++++++++++++++++-----------
>  1 file changed, 59 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
> index 7f571a8..d879c0c 100644
> --- a/drivers/tty/serial/sh-sci.c
> +++ b/drivers/tty/serial/sh-sci.c
> @@ -1783,13 +1783,30 @@ static unsigned int sci_scbrr_calc(struct sci_port *s, unsigned int bps,
>         return ((freq + 16 * bps) / (32 * bps) - 1);
>  }
>
> +/* calculate frame length from SMR */
> +static int sci_baud_calc_frame_len(unsigned int smr_val)
> +{
> +       int len = 10;
> +
> +       if (smr_val & SCSMR_CHR)
> +               len--;
> +       if (smr_val & SCSMR_PE)
> +               len++;
> +       if (smr_val & SCSMR_STOP)
> +               len++;
> +
> +       return len;
> +}

The above function isn't needed...

>  /* calculate sample rate, BRR, and clock select for HSCIF */
>  static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq,
>                                 int *brr, unsigned int *srr,
> -                               unsigned int *cks)
> +                               unsigned int *cks, int frame_len)

... because the new "frame_len" parameter is unused...

> @@ -1858,8 +1907,9 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
>         baud = uart_get_baud_rate(port, termios, old, 0, max_baud);
>         if (likely(baud && port->uartclk)) {
>                 if (s->cfg->type = PORT_HSCIF) {
> +                       int frame_len = sci_baud_calc_frame_len(smr_val);

... hence calculating this isn't needed.

>                         sci_baud_calc_hscif(baud, port->uartclk, &t, &srr,
> -                                           &cks);
> +                                           &cks, frame_len);
>                 } else {
>                         t = sci_scbrr_calc(s, baud, port->uartclk);
>                         for (cks = 0; t >= 256 && cks <= 3; cks++)

Is there some follow-up patch missing?

Thanks!

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 3/3] serial: sh-sci: Add calculation recive margin for HSCIF
@ 2015-11-02 13:56     ` Geert Uytterhoeven
  0 siblings, 0 replies; 10+ messages in thread
From: Geert Uytterhoeven @ 2015-11-02 13:56 UTC (permalink / raw)
  To: Nobuhiro Iwamatsu
  Cc: Linux-sh list, Greg KH, linux-serial, Simon Horman, Magnus Damm

Hi Iwamatsu-san,

On Mon, Jul 14, 2014 at 9:10 AM, Nobuhiro Iwamatsu
<nobuhiro.iwamatsu.yj@renesas.com> wrote:
> When the error of the same bit rate is detected, we will need to select
> the recive margin is large. Current code holds the minimum error, it does
> not have to check the recive margin. This adds this calculation.
>
> Signed-off-by: Nobuhiro Iwamatsu <nobuhiro.iwamatsu.yj@renesas.com>

I know this patch was applied a while ago.

> ---
>  drivers/tty/serial/sh-sci.c | 77 ++++++++++++++++++++++++++++++++++-----------
>  1 file changed, 59 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
> index 7f571a8..d879c0c 100644
> --- a/drivers/tty/serial/sh-sci.c
> +++ b/drivers/tty/serial/sh-sci.c
> @@ -1783,13 +1783,30 @@ static unsigned int sci_scbrr_calc(struct sci_port *s, unsigned int bps,
>         return ((freq + 16 * bps) / (32 * bps) - 1);
>  }
>
> +/* calculate frame length from SMR */
> +static int sci_baud_calc_frame_len(unsigned int smr_val)
> +{
> +       int len = 10;
> +
> +       if (smr_val & SCSMR_CHR)
> +               len--;
> +       if (smr_val & SCSMR_PE)
> +               len++;
> +       if (smr_val & SCSMR_STOP)
> +               len++;
> +
> +       return len;
> +}

The above function isn't needed...

>  /* calculate sample rate, BRR, and clock select for HSCIF */
>  static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq,
>                                 int *brr, unsigned int *srr,
> -                               unsigned int *cks)
> +                               unsigned int *cks, int frame_len)

... because the new "frame_len" parameter is unused...

> @@ -1858,8 +1907,9 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
>         baud = uart_get_baud_rate(port, termios, old, 0, max_baud);
>         if (likely(baud && port->uartclk)) {
>                 if (s->cfg->type == PORT_HSCIF) {
> +                       int frame_len = sci_baud_calc_frame_len(smr_val);

... hence calculating this isn't needed.

>                         sci_baud_calc_hscif(baud, port->uartclk, &t, &srr,
> -                                           &cks);
> +                                           &cks, frame_len);
>                 } else {
>                         t = sci_scbrr_calc(s, baud, port->uartclk);
>                         for (cks = 0; t >= 256 && cks <= 3; cks++)

Is there some follow-up patch missing?

Thanks!

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2015-11-02 13:56 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-14  7:09 [PATCH 1/3] serial: sh-sci: Updated calculation of bit error rate and bit rate Nobuhiro Iwamatsu
2014-07-14  7:09 ` Nobuhiro Iwamatsu
2014-07-14  7:09 ` [PATCH 2/3] serial: sh-sci: Fix range check of bit-rate for HSCIF Nobuhiro Iwamatsu
2014-07-14  7:09   ` Nobuhiro Iwamatsu
2014-07-14  7:10 ` [PATCH 3/3] serial: sh-sci: Add calculation recive margin " Nobuhiro Iwamatsu
2014-07-14  7:10   ` Nobuhiro Iwamatsu
2015-11-02 13:56   ` Geert Uytterhoeven
2015-11-02 13:56     ` Geert Uytterhoeven
2014-07-22  1:37 ` [PATCH 1/3] serial: sh-sci: Updated calculation of bit error rate and bit rate Simon Horman
2014-07-22  1:37   ` Simon Horman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.