提交 32068c42 编写于 作者: P Phil Edworthy 提交者: Jagan Teki

spi: cadence_qspi: Fix baud rate calculation

With the existing code, when the requested SPI clock rate is near
to the lowest that can be achieved by the hardware (max divider
of the ref clock is 32), the generated clock rate is wrong.
For example, with a 50MHz ref clock, when asked for anything less
than a 1.5MHz SPI clock, the code sets up the divider to generate
25MHz.

This change fixes the calculation.
Signed-off-by: NPhil Edworthy <phil.edworthy@renesas.com>
Reviewed-by: NJagan Teki <jagan@openedev.com>
上级 cc80a897
......@@ -273,22 +273,12 @@ void cadence_qspi_apb_config_baudrate_div(void *reg_base,
reg = readl(reg_base + CQSPI_REG_CONFIG);
reg &= ~(CQSPI_REG_CONFIG_BAUD_MASK << CQSPI_REG_CONFIG_BAUD_LSB);
div = ref_clk_hz / sclk_hz;
if (div > 32)
div = 32;
/* Check if even number. */
if ((div & 1)) {
div = (div / 2);
} else {
if (ref_clk_hz % sclk_hz)
/* ensure generated SCLK doesn't exceed user
specified sclk_hz */
div = (div / 2);
else
div = (div / 2) - 1;
}
/*
* The baud_div field in the config reg is 4 bits, and the ref clock is
* divided by 2 * (baud_div + 1). Round up the divider to ensure the
* SPI clock rate is less than or equal to the requested clock rate.
*/
div = DIV_ROUND_UP(ref_clk_hz, sclk_hz * 2) - 1;
debug("%s: ref_clk %dHz sclk %dHz Div 0x%x\n", __func__,
ref_clk_hz, sclk_hz, div);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册