130-clk_mux-Fix-set_parent-doing-the-wrong-thing-when-IN.patch 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. If CLK_MUX_INDEX_BIT is set, then each bit turns on / off a single parent,
  7. so theoretically multiple parents could be enabled at the same time, but in
  8. practice only one bit should ever be 1. So to select parent 0, set
  9. the register (*) to 0x01, to select parent 1 set it 0x02, parent 2, 0x04,
  10. parent 3, 0x08, etc.
  11. But the current code does:
  12. if (mux->flags & CLK_MUX_INDEX_BIT)
  13. index = (1 << ffs(index));
  14. Which means that:
  15. For an input index of 0, ffs returns 0, so we set the register
  16. to 0x01, ok.
  17. For an input index of 1, ffs returns 1, so we set the register
  18. to 0x02, ok.
  19. For an input index of 2, ffs returns 2, so we set the register
  20. to 0x04, ok.
  21. For an input index of 3, ffs returns 1, so we set the register
  22. to 0x02, not good!
  23. The code should simply be:
  24. if (mux->flags & CLK_MUX_INDEX_BIT)
  25. index = 1 << index;
  26. Which always does the right thing, this commit fixes this.
  27. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  28. Signed-off-by: Michael Turquette <mturquette@linaro.org>
  29. ---
  30. drivers/clk/clk-mux.c | 2 +-
  31. 1 file changed, 1 insertion(+), 1 deletion(-)
  32. --- a/drivers/clk/clk-mux.c
  33. +++ b/drivers/clk/clk-mux.c
  34. @@ -77,7 +77,7 @@ static int clk_mux_set_parent(struct clk
  35. else {
  36. if (mux->flags & CLK_MUX_INDEX_BIT)
  37. - index = (1 << ffs(index));
  38. + index = 1 << index;
  39. if (mux->flags & CLK_MUX_INDEX_ONE)
  40. index++;