ipq806x: fix 3.18 support
[openwrt/staging/dedeckeh.git] / target / linux / ipq806x / patches-3.18 / 130-clk_mux-Fix-set_parent-doing-the-wrong-thing-when-IN.patch
1 From 6793b3cd5da817c4be218bd8632f07cf4d2b0d26 Mon Sep 17 00:00:00 2001
2 From: Hans de Goede <hdegoede@redhat.com>
3 Date: Wed, 19 Nov 2014 14:48:59 +0100
4 Subject: [PATCH] clk_mux: Fix set_parent doing the wrong thing when INDEX_BIT
5 && index >= 3
6
7 If CLK_MUX_INDEX_BIT is set, then each bit turns on / off a single parent,
8 so theoretically multiple parents could be enabled at the same time, but in
9 practice only one bit should ever be 1. So to select parent 0, set
10 the register (*) to 0x01, to select parent 1 set it 0x02, parent 2, 0x04,
11 parent 3, 0x08, etc.
12
13 But the current code does:
14
15 if (mux->flags & CLK_MUX_INDEX_BIT)
16 index = (1 << ffs(index));
17
18 Which means that:
19
20 For an input index of 0, ffs returns 0, so we set the register
21 to 0x01, ok.
22
23 For an input index of 1, ffs returns 1, so we set the register
24 to 0x02, ok.
25
26 For an input index of 2, ffs returns 2, so we set the register
27 to 0x04, ok.
28
29 For an input index of 3, ffs returns 1, so we set the register
30 to 0x02, not good!
31
32 The code should simply be:
33
34 if (mux->flags & CLK_MUX_INDEX_BIT)
35 index = 1 << index;
36
37 Which always does the right thing, this commit fixes this.
38
39 Signed-off-by: Hans de Goede <hdegoede@redhat.com>
40 Signed-off-by: Michael Turquette <mturquette@linaro.org>
41 ---
42 drivers/clk/clk-mux.c | 2 +-
43 1 file changed, 1 insertion(+), 1 deletion(-)
44
45 --- a/drivers/clk/clk-mux.c
46 +++ b/drivers/clk/clk-mux.c
47 @@ -77,7 +77,7 @@ static int clk_mux_set_parent(struct clk
48
49 else {
50 if (mux->flags & CLK_MUX_INDEX_BIT)
51 - index = (1 << ffs(index));
52 + index = 1 << index;
53
54 if (mux->flags & CLK_MUX_INDEX_ONE)
55 index++;