clk: meson: mpll: fix division by zero in rate_from_params
authorMartin Blumenstingl <martin.blumenstingl@googlemail.com>
Sat, 1 Apr 2017 13:02:24 +0000 (15:02 +0200)
committerJerome Brunet <jbrunet@baylibre.com>
Fri, 7 Apr 2017 15:45:21 +0000 (17:45 +0200)
commit88e4ac68ea9a09e105c86070ebfa01ca482ca4c2
treeb593c7e8f91f8fd14ec7e36039cf817d20fb5129
parent7eaa44f6207fb64b1fa4304f83f22486590540e2
clk: meson: mpll: fix division by zero in rate_from_params

According to the public datasheet all register bits in HHI_MPLL_CNTL7,
HHI_MPLL_CNTL8 and HHI_MPLL_CNTL9 default to zero. On all GX SoCs these
seem to be initialized by the bootloader to some default value.
However, on my Meson8 board they are not initialized, leading to a
division by zero in rate_from_params as the math is:
(parent_rate * SDM_DEN) / ((SDM_DEN * 0) + 0)

According to the datasheet, the minimum n2 value is 4. The rate provided
by the clock when n2 is less than this minimum is unpredictable. In such
case, we report an error.

Although the rate_from_params function was only introduced recently the
original bug has been there for much longer. It was only exposed
recently when the MPLL clocks were added to the Meson8b clock driver.

Fixes: 1c50da4f27 ("clk: meson: add mpll support")
Reviewed-by: Neil Armstrong <narmstrong@baylibre.com>
Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
Signed-off-by: Jerome Brunet <jbrunet@baylibre.com>
drivers/clk/meson/clk-mpll.c