owl-gate.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // SPDX-License-Identifier: GPL-2.0+
  2. //
  3. // OWL gate clock driver
  4. //
  5. // Copyright (c) 2014 Actions Semi Inc.
  6. // Author: David Liu <[email protected]>
  7. //
  8. // Copyright (c) 2018 Linaro Ltd.
  9. // Author: Manivannan Sadhasivam <[email protected]>
  10. #include <linux/clk-provider.h>
  11. #include <linux/regmap.h>
  12. #include "owl-gate.h"
  13. void owl_gate_set(const struct owl_clk_common *common,
  14. const struct owl_gate_hw *gate_hw, bool enable)
  15. {
  16. int set = gate_hw->gate_flags & CLK_GATE_SET_TO_DISABLE ? 1 : 0;
  17. u32 reg;
  18. set ^= enable;
  19. regmap_read(common->regmap, gate_hw->reg, &reg);
  20. if (set)
  21. reg |= BIT(gate_hw->bit_idx);
  22. else
  23. reg &= ~BIT(gate_hw->bit_idx);
  24. regmap_write(common->regmap, gate_hw->reg, reg);
  25. }
  26. static void owl_gate_disable(struct clk_hw *hw)
  27. {
  28. struct owl_gate *gate = hw_to_owl_gate(hw);
  29. struct owl_clk_common *common = &gate->common;
  30. owl_gate_set(common, &gate->gate_hw, false);
  31. }
  32. static int owl_gate_enable(struct clk_hw *hw)
  33. {
  34. struct owl_gate *gate = hw_to_owl_gate(hw);
  35. struct owl_clk_common *common = &gate->common;
  36. owl_gate_set(common, &gate->gate_hw, true);
  37. return 0;
  38. }
  39. int owl_gate_clk_is_enabled(const struct owl_clk_common *common,
  40. const struct owl_gate_hw *gate_hw)
  41. {
  42. u32 reg;
  43. regmap_read(common->regmap, gate_hw->reg, &reg);
  44. if (gate_hw->gate_flags & CLK_GATE_SET_TO_DISABLE)
  45. reg ^= BIT(gate_hw->bit_idx);
  46. return !!(reg & BIT(gate_hw->bit_idx));
  47. }
  48. static int owl_gate_is_enabled(struct clk_hw *hw)
  49. {
  50. struct owl_gate *gate = hw_to_owl_gate(hw);
  51. struct owl_clk_common *common = &gate->common;
  52. return owl_gate_clk_is_enabled(common, &gate->gate_hw);
  53. }
  54. const struct clk_ops owl_gate_ops = {
  55. .disable = owl_gate_disable,
  56. .enable = owl_gate_enable,
  57. .is_enabled = owl_gate_is_enabled,
  58. };