• Julius Werner's avatar
    spi/rockchip: Round up clock rate divisor to err on the safe side · 754ec43c
    Julius Werner authored
    The Rockchip SPI driver currently calculates its clock rate divisor by
    integer dividing the parent rate by the target rate, and then rounding
    the result up to the next even number (since the divisor must be
    even).
    
    Clock rate divisors should always be rounded up, so that the resulting
    frequency is lower or equal to the target. This is correctly done in the
    second step here but not in the first, so we still have a risk of
    exceeding the desired target frequency (e.g. setting spi-max-frequency
    to 40000000 with a parent clock of 99000000 could lead to a divisor of
    99000000 / 40000000 == 2 (which is even) that then results in an
    effective frequency of 99000000 / 2 == 49500000 (potentially exceeding
    the flash chip's specifications).
    
    This patch changes the division to round up to fix this problem.
    Signed-off-by: default avatarJulius Werner <jwerner@chromium.org>
    Signed-off-by: default avatarMark Brown <broonie@kernel.org>
    754ec43c
spi-rockchip.c 20.1 KB