u-boot-brain/drivers/clk
Philipp Tomsich beb90a53f3 rockchip: clk: rk3399: fix off-by one during rate calculation in i2c/spi_set_rate
For the RK3399, i2c_set_rate (and by extension: our spi_set_rate,
which had been mindlessly following the template of the i2c_set_rate
implementation) miscalculates the rate returned due to a off-by-one
error resulting from the following sequence of events:
  1. calculates 'src_div := src_freq / target_freq'
  2. stores 'src_div - 1' into the register (the actual divider applied
     in hardware is biased by adding 1)
  3. returns the result of the DIV_RATE(src_freq, src_div) macro, which
     expects the (decremented) divider from the hardware-register and
     implictly adds 1 (i.e. 'DIV_RATE(freq, div) := freq / (div + 1)')

This can be observed with the SPI driver, which sets a rate of 99MHz
based on the GPLL frequency of 594MHz: the hardware generates a clock
of 99MHz (src_div is 6, the bitfield in the register correctly reads 5),
but reports a frequency of 84MHz (594 / 7) on return.

To fix, we have two options:
 * either we bias (i.e. "DIV_RATE(GPLL, src_div - 1)"), which doesn't
   make for a particularily nice read
 * we simply call the i2c/spi_get_rate function (introducing additional
   overhead for the additional register-read), which reads the divider
   from the register and then passes it through the DIV_RATE macro

Given that this code is not time-critical, the more readable solution
(i.e. calling the appropriate get_rate function) is implemented in this
change.

Signed-off-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
Tested-by: Klaus Goger <klaus.goger@theobroma-systems.com>
Acked-by: Simon Glass <sjg@chromium.org>
2017-05-10 13:37:21 -06:00
..
aspeed aspeed: Refactor SCU to use consistent mask & shift 2017-05-08 11:57:35 -04:00
at91 clk: at91: Align the at91 pmc's compatibles 2017-05-09 12:14:15 -06:00
exynos clk: convert API to match reset/mailbox style 2016-06-19 17:05:55 -06:00
rockchip rockchip: clk: rk3399: fix off-by one during rate calculation in i2c/spi_set_rate 2017-05-10 13:37:21 -06:00
tegra clock: implement a driver for the Tegra CAR 2016-09-27 09:11:02 -07:00
uniphier clk: uniphier: fix compatible strings for Pro5, PXs2, LD20 SD clock 2017-01-29 20:59:08 +09:00
clk_boston.c clk: boston: Providea simple driver for Boston board clocks 2016-09-21 15:04:32 +02:00
clk_fixed_rate.c dm: core: Replace of_offset with accessor 2017-02-08 06:12:14 -07:00
clk_pic32.c dm: core: Replace of_offset with accessor 2017-02-08 06:12:14 -07:00
clk_sandbox_test.c clk: convert API to match reset/mailbox style 2016-06-19 17:05:55 -06:00
clk_sandbox.c clk: sandbox: don't check clk ID against 0 2016-06-24 17:24:35 -04:00
clk_stm32f7.c stm32f7: use stm32f7 gpio driver supporting driver model 2017-05-08 11:57:21 -04:00
clk_zynq.c clk: zynq: Add optional ethernet emio clock source support 2017-02-17 10:22:46 +01:00
clk_zynqmp.c clk: zynqmp: Add clock driver support for zynqmp 2017-01-10 10:18:12 +01:00
clk-uclass.c dm: core: Replace of_offset with accessor 2017-02-08 06:12:14 -07:00
Kconfig clk: zynq: Add zynq clock framework driver 2017-02-17 10:22:46 +01:00
Makefile clk: stm32f7: add clock driver for stm32f7 family 2017-03-17 14:15:12 -04:00