• Serge Semin's avatar
    tty: max310x: Fix invalid baudrate divisors calculator · 35240ba2
    Serge Semin authored
    Current calculator doesn't do it' job quite correct. First of all the
    max310x baud-rates generator supports the divisor being less than 16.
    In this case the x2/x4 modes can be used to double or quadruple
    the reference frequency. But the current baud-rate setter function
    just filters all these modes out by the first condition and setups
    these modes only if there is a clocks-baud division remainder. The former
    doesn't seem right at all, since enabling the x2/x4 modes causes the line
    noise tolerance reduction and should be only used as a last resort to
    enable a requested too high baud-rate.
    
    Finally the fraction is supposed to be calculated from D = Fref/(c*baud)
    formulae, but not from D % 16, which causes the precision loss. So to speak
    the current baud-rate calculator code works well only if the baud perfectly
    fits to the uart reference input frequency.
    
    Lets fix the calculator by implementing the algo fully compliant with
    the fractional baud-rate generator described in the datasheet:
    D = Fref / (c*baud), where c={16,8,4} is the x1/x2/x4 rate mode
    respectively, Fref - reference input frequency. The divisor fraction is
    calculated from the same formulae, but making sure it is found with a
    resolution of 0.0625 (four bits).
    Signed-off-by: default avatarSerge Semin <fancer.lancer@gmail.com>
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    35240ba2
max310x.c 41.4 KB