The gen2_clk_get_sdh_div() function is supposed to look up the
$val value read out of the SDCKCR register in the supplied table
and return the matching divider value. The current implementation
was matching the value from SDCKCR on the divider value in the
table, which is wrong. Fix this and rework the function a bit
to make it more readable.
Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
{ 0, 0 },
};
-static u8 gen2_clk_get_sdh_div(const struct clk_div_table *table, u8 div)
+static u8 gen2_clk_get_sdh_div(const struct clk_div_table *table, u8 val)
{
- while ((*table++).val) {
- if ((*table).div == div)
- return div;
+ for (;;) {
+ if (!(*table).div)
+ return 0xff;
+
+ if ((*table).val == val)
+ return (*table).div;
+
+ table++;
}
- return 0xff;
}
static int gen2_clk_enable(struct clk *clk)