All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael G. Katzmann" <michaelk@IEEE.org>
To: Johan Hovold <johan@kernel.org>, Charles Yeh <charlesyeh522@gmail.com>
Cc: "Yeh.Charles [葉榮鑫]" <charles-yeh@prolific.com.tw>,
	linux-serial@vger.kernel.org, linux-usb@vger.kernel.org,
	"Joe Abbott" <jabbott@rollanet.org>
Subject: Re: non-standard baud rates with Prolific 2303 USB-serial
Date: Sat, 6 Mar 2021 15:18:45 -0500	[thread overview]
Message-ID: <3c8b6bca-4f8f-f537-7f88-9815715a7b14@IEEE.org> (raw)
In-Reply-To: <YEH7okblCx8+Odxn@hovoldconsulting.com>

On 3/5/21 4:36 AM, Johan Hovold wrote:
> On Fri, Mar 05, 2021 at 05:32:23PM +0800, Charles Yeh wrote:
>> 110 bps is not the standard Baud rate,
>> PL2303TA don't work with the current Linux driver (d5 0e 00 80), It
>> needs to "a8 a6 01 80"
> 
> Ok, thanks for confirming. Then we should be able to fix this up based
> on Michael's findings.
> 
>> Johan Hovold <johan@kernel.org> 於 2021年2月25日 週四 上午1:00寫道:
>>
>>> But can you confirm that your PL2303TA works with the current Linux
>>> driver at 110 Bd (and doesn't need the alternate divisor encoding)?
> 
> Johan
> 

How about... altering the call to pl2303_encode_baud_rate_divisor (adding 'port')
       baud = pl2303_encode_baud_rate_divisor(port, buf, baud);

and checking for model and altering algorithm as below.

I've tested this on the TA version.

Michael



static speed_t pl2303_encode_baud_rate_divisor(struct usb_serial_port *port, unsigned char buf[4],
                                speed_t baud)
{
    unsigned int baseline, mantissa, exponent;
        unsigned int bcdDevice = port->serial->dev->descriptor.bcdDevice;
        unsigned int bcdUSB = port->serial->dev->descriptor.bcdUSB;

        enum model { eUNKNOWN, eHXD, eHXA, eTA } model;

   if ( bcdUSB == 0x0110 ) {
       if( bcdDevice == 0x0400 )
           model = eHXD;
       else if ( bcdDevice == 0x0300 )
           model = eHXA; // PL2303HX(A)/XA ( EOL : PHASED OUT SINCE 2012 )
       else
          model = eUNKNOWN;
    } else if( bcdUSB == 0x200 && bcdDevice == 0x0300 ) {
        model = eTA;
    }
    /*
     * Apparently the formula is:
     *   baudrate = 12M * 32 / (mantissa * 4^exponent)
     * where
     *   mantissa = buf[8:0]
     *   exponent = buf[11:9]
         *
         * TA version has more precision
         *      uses mantissa = buf[bits 10:0 ]
     *           exponent = buf[bits 15:13]
     *  and x2 prescaler enable by buf[bit 16]
     */
    baseline = 12000000 * 32;
    mantissa = baseline / baud;
    if (mantissa == 0)
        mantissa = 1;    /* Avoid dividing by zero if baud > 32*12M. */
    exponent = 0;

    if ( model == eTA ) {
        while (mantissa >= 2048) {
            // n.b. below is speculative for the TA chip and is based on original code
            if (exponent < 15) {   // we are going to divide this by 2 later
                mantissa >>= 1;    // divide by 2
                exponent++;        // currently log2 ... will become log4
            } else {
                /* Exponent is maxed. Trim mantissa and leave. */
                mantissa = 2047 ;
                break;
            }
        }
        buf[2] = exponent & 0x01;  // activate x2 prescaler if needed
        exponent >>= 1;            // now log base 4 (losing LSB)
        buf[1] = (exponent << 5) | (mantissa >> 8);
    } else {
        while (mantissa >= 512) {
            if (exponent < 7) {
                mantissa >>= 2; /* divide by 4 */
                exponent++;
            } else {
                /* Exponent is maxed. Trim mantissa and leave. */
                mantissa = 511;
                break;
           }
        }
        buf[2] = 0;
        buf[1] = exponent << 1 | mantissa >> 8;
    }

    buf[3] = 0x80;
    buf[0] = mantissa & 0xff;

    /* Calculate and return the exact baud rate. */
    baud = (baseline / mantissa / (buf[2] == 0x01 ? 2:1)) >> (exponent << 1);
    return baud;
}




  reply	other threads:[~2021-03-06 20:19 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-21 15:37 non-standard baud rates with Prolific 2303 USB-serial Michael G. Katzmann
2021-02-22  2:15 ` Michael G. Katzmann
2021-02-22  8:52   ` Johan Hovold
2021-02-22 12:39     ` Michael G. Katzmann
2021-02-22 13:18       ` Johan Hovold
     [not found]         ` <fb1489c2-b972-619b-b7ce-4ae8e1d2cc0f@IEEE.org>
2021-02-22 15:34           ` Johan Hovold
2021-02-22 15:42             ` Michael G. Katzmann
2021-02-22 15:50               ` Johan Hovold
2021-02-22 16:37                 ` Michael G. Katzmann
2021-02-22 16:48                   ` Johan Hovold
2021-02-24 23:08                     ` Joe Abbott
2021-02-25  8:44                       ` Johan Hovold
     [not found]                   ` <43da22ced8e14442bbc8babea77e4ed7@MailHC2.prolific.com.tw>
2021-02-23 10:18                     ` Johan Hovold
2021-02-23 13:25                     ` Michael G. Katzmann
2021-02-23 14:58                 ` Michael G. Katzmann
2021-02-23 15:43                   ` Johan Hovold
2021-02-23 15:57                     ` Michael G. Katzmann
2021-02-23 16:14                       ` Johan Hovold
2021-02-23 16:30                         ` Michael G. Katzmann
2021-02-23 16:52                           ` Johan Hovold
2021-02-23 19:15                             ` Michael G. Katzmann
2021-02-24 17:04                               ` Johan Hovold
2021-02-24 18:13                                 ` Michael G. Katzmann
2021-02-25  8:42                                   ` Johan Hovold
2021-04-08 15:35                                     ` Johan Hovold
2021-02-24  7:34                             ` Charles Yeh
2021-02-24 17:00                               ` Johan Hovold
2021-02-24 17:12                                 ` Michael G. Katzmann
2021-03-05  9:32                                 ` Charles Yeh
2021-03-05  9:36                                   ` Johan Hovold
2021-03-06 20:18                                     ` Michael G. Katzmann [this message]
2021-03-07  4:15                                     ` Michael G. Katzmann
2021-03-11 16:08                                       ` Johan Hovold
2021-03-12 13:17                                         ` Michael G. Katzmann
2021-03-12 13:44                                           ` Johan Hovold
2021-03-12 20:29                                             ` Michael G. Katzmann
2021-03-13  1:28                                             ` Michael G. Katzmann
2021-03-15  9:07                                               ` Johan Hovold
2021-03-15 10:07                                                 ` Charles Yeh
2021-03-15 10:24                                                   ` Johan Hovold
2021-02-22  3:57 ` Grant Edwards

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=3c8b6bca-4f8f-f537-7f88-9815715a7b14@IEEE.org \
    --to=michaelk@ieee.org \
    --cc=charles-yeh@prolific.com.tw \
    --cc=charlesyeh522@gmail.com \
    --cc=jabbott@rollanet.org \
    --cc=johan@kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=linux-usb@vger.kernel.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 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.