linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johan Hovold <johan@kernel.org>
To: michaelk@IEEE.org
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH 1/1] USB: serial: pl2303: TA & TB alternate divider
Date: Tue, 16 Mar 2021 16:55:36 +0100	[thread overview]
Message-ID: <YFDU+De/mTMnRZQR@hovoldconsulting.com> (raw)
In-Reply-To: <20210316120620.888110-1-michaelk@IEEE.org>

On Tue, Mar 16, 2021 at 08:06:20AM -0400, michaelk@IEEE.org wrote:
> From: Michael Katzmann <michaelk@IEEE.org>
> 
> Use an alternate clock divider algorithm and bit ordering for the TA and
> TB versions of the pl2303. It was discovered that these variants do not
> produce the correct baud rates with the existing scheme.
> 
> see https://lore.kernel.org/r/3aee5708-7961-f464-8c5f-6685d96920d6@IEEE.org
> 
> Signed-off-by: Michael G. Katzmann <michaelk@IEEE.org>
> ---
>  drivers/usb/serial/pl2303.c | 45 +++++++++++++++++++++++++++++++++++++
>  1 file changed, 45 insertions(+)
 
> +static speed_t pl2303_encode_baud_rate_divisor_alt(unsigned char buf[4],
> +                                                                speed_t baud)
> +{
> +        unsigned int baseline, mantissa, exponent;
> +
> +        /*
> +         * Apparently, for the TA version the formula is:
> +         *   baudrate = 12M * 32 / (mantissa * 2^exponent)
> +         * where
> +         *   mantissa = buf[10:0]
> +         *   exponent = buf[15:13 16]
> +         */
> +        baseline = 12000000 * 32;
> +        mantissa = baseline / baud;
> +        if (mantissa == 0)
> +                mantissa = 1;   /* Avoid dividing by zero if baud > 32*12M. */
> +        exponent = 0;
> +        while (mantissa >= 2048) {
> +                if (exponent < 15) {
> +                        mantissa >>= 1; /* divide by 2 */
> +                        exponent++;
> +                } else {
> +                        /* Exponent is maxed. Trim mantissa and leave. */
> +                        mantissa = 2047;
> +                        break;
> +                }
> +        }
> +
> +        buf[3] = 0x80;
> +        buf[2] = exponent & 0x01;
> +        buf[1] = (exponent & ~0x01) << 4 | mantissa >> 8;
> +        buf[0] = mantissa & 0xff;
> +
> +        /* Calculate and return the exact baud rate. */
> +        baud = (baseline / mantissa) >> exponent;
> +
> +        return baud;
> +}

The code above is still indented using spaces rather than tabs.

> +
> +
>  static void pl2303_encode_baud_rate(struct tty_struct *tty,
>  					struct usb_serial_port *port,
>  					u8 buf[4])
> @@ -645,6 +688,8 @@ static void pl2303_encode_baud_rate(struct tty_struct *tty,
>  
>  	if (baud == baud_sup)
>  		baud = pl2303_encode_baud_rate_direct(buf, baud);
> +	else if (spriv->type->alt_divisors) 
> +                baud = pl2303_encode_baud_rate_divisor_alt(buf, baud);

Same here.

>  	else
>  		baud = pl2303_encode_baud_rate_divisor(buf, baud);

Please include a revision in the subject prefix when resending (e.g.
this would be "[PATCH v2]: USB: ...", generally there should be a
matching short changelog below the '---' cut-off line as well).

Johan

  reply	other threads:[~2021-03-16 15:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-16 12:06 [PATCH 1/1] USB: serial: pl2303: TA & TB alternate divider michaelk
2021-03-16 15:55 ` Johan Hovold [this message]
  -- strict thread matches above, loose matches on Subject: below --
2021-03-16  1:42 michaelk
2021-03-16  7:19 ` Greg KH
2021-03-16  9:19   ` Johan Hovold

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=YFDU+De/mTMnRZQR@hovoldconsulting.com \
    --to=johan@kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=michaelk@IEEE.org \
    /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).