Hi Ulrich,

On Wed, Apr 4, 2018 at 5:48 PM, Ulrich Hecht
<ulrich.hecht+rene...@gmail.com> wrote:
> HSCIF has facilities that allow moving the RX sampling point by between
> -8 and 7 sampling cycles (one sampling cycles equals 1/15 of a bit
> by default) to improve the error margin in case of slightly mismatched
> bit rates between sender and receiver.
>
> This patch tries to determine if shifting the sampling point can improve
> the error margin and will enable it if so.
>
> Signed-off-by: Ulrich Hecht <ulrich.hecht+rene...@gmail.com>
> ---
> This revision dumps the sysfs interface and works out the optimal shift
> on its own. It also moves setting of the HSSRR register back to its
> original location.

Thanks for the update!

Reviewed-by: Geert Uytterhoeven <geert+rene...@glider.be>

One suggestion for improvement below.

> --- a/drivers/tty/serial/sh-sci.c
> +++ b/drivers/tty/serial/sh-sci.c

> @@ -2406,8 +2427,27 @@ static void sci_set_termios(struct uart_port *port, 
> struct ktermios *termios,
>                 serial_port_out(port, SCSCR, scr_val | s->hscif_tot);
>                 serial_port_out(port, SCSMR, smr_val);
>                 serial_port_out(port, SCBRR, brr);
> -               if (sci_getreg(port, HSSRR)->size)
> -                       serial_port_out(port, HSSRR, srr | HSCIF_SRE);
> +               if (sci_getreg(port, HSSRR)->size) {
> +                       unsigned int hssrr = srr | HSCIF_SRE;
> +                       /* Calculate deviation from intended rate at the
> +                        * center of the last stop bit in sampling clocks.
> +                        */
> +                       int last_stop = bits * 2 - 1;
> +                       int deviation = min_err * srr * last_stop / 2 / baud;

DIV_ROUND_CLOSEST()?

> +
> +                       if (abs(deviation) >= 2) {
> +                               /* At least two sampling clocks off at the
> +                                * last stop bit; we can increase the error
> +                                * margin by shifting the sampling point.
> +                                */
> +                               int shift = min(-8, max(7, deviation / 2));
> +
> +                               hssrr |= (shift << HSCIF_SRHP_SHIFT) &
> +                                        HSCIF_SRHP_MASK;
> +                               hssrr |= HSCIF_SRDE;
> +                       }
> +                       serial_port_out(port, HSSRR, hssrr);
> +               }
>
>                 /* Wait one bit interval */
>                 udelay((1000000 + (baud - 1)) / baud);

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@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

Reply via email to