clk: ti: divider: convert to use min,max,mask instead of width
authorTero Kristo <t-kristo@ti.com>
Wed, 2 Oct 2019 12:06:10 +0000 (15:06 +0300)
committerTero Kristo <t-kristo@ti.com>
Thu, 31 Oct 2019 13:32:36 +0000 (15:32 +0200)
commit8ffea6eef4ace7e207fc2fe852d2019d93f51d1a
tree2a85ca80ee3c32c01eacb1aee7f6a9acf73f750f
parenta229965cfeab8ea8bb79086d6f59ac9a57de66fe
clk: ti: divider: convert to use min,max,mask instead of width

The existing width field used to check divider validity does not provide
enough protection against bad values. For example, if max divider value
is 4, the smallest all-1 bitmask that can hold this value is 7, which
allows values higher than 4 to be used. This typically causes
unpredictable results with hardware. So far this issue hasn't been
noticed as most of the dividers actually have maximum values which fit
the whole bitfield, but there are certain clocks for which this is a
problem, like dpll4_m4 divider on omap3 devices.

Thus, convert the whole validity logic to use min,max and mask values
for determining if a specific divider is valid or not. This prevents
the odd cases where bad value would otherwise be written to a divider
config register.

Signed-off-by: Tero Kristo <t-kristo@ti.com>
Tested-by: Adam Ford <aford173@gmail.com>
drivers/clk/ti/clock.h
drivers/clk/ti/divider.c