ccu_gate.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright (C) 2016 Maxime Ripard
  3. * Maxime Ripard <maxime.ripard@free-electrons.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or (at your option) any later version.
  9. */
  10. #include <linux/clk-provider.h>
  11. #include "ccu_gate.h"
  12. void ccu_gate_helper_disable(struct ccu_common *common, u32 gate)
  13. {
  14. unsigned long flags;
  15. u32 reg;
  16. if (!gate)
  17. return;
  18. spin_lock_irqsave(common->lock, flags);
  19. reg = readl(common->base + common->reg);
  20. writel(reg & ~gate, common->base + common->reg);
  21. spin_unlock_irqrestore(common->lock, flags);
  22. }
  23. static void ccu_gate_disable(struct clk_hw *hw)
  24. {
  25. struct ccu_gate *cg = hw_to_ccu_gate(hw);
  26. return ccu_gate_helper_disable(&cg->common, cg->enable);
  27. }
  28. int ccu_gate_helper_enable(struct ccu_common *common, u32 gate)
  29. {
  30. unsigned long flags;
  31. u32 reg;
  32. if (!gate)
  33. return 0;
  34. spin_lock_irqsave(common->lock, flags);
  35. reg = readl(common->base + common->reg);
  36. writel(reg | gate, common->base + common->reg);
  37. spin_unlock_irqrestore(common->lock, flags);
  38. return 0;
  39. }
  40. static int ccu_gate_enable(struct clk_hw *hw)
  41. {
  42. struct ccu_gate *cg = hw_to_ccu_gate(hw);
  43. return ccu_gate_helper_enable(&cg->common, cg->enable);
  44. }
  45. int ccu_gate_helper_is_enabled(struct ccu_common *common, u32 gate)
  46. {
  47. if (!gate)
  48. return 1;
  49. return readl(common->base + common->reg) & gate;
  50. }
  51. static int ccu_gate_is_enabled(struct clk_hw *hw)
  52. {
  53. struct ccu_gate *cg = hw_to_ccu_gate(hw);
  54. return ccu_gate_helper_is_enabled(&cg->common, cg->enable);
  55. }
  56. const struct clk_ops ccu_gate_ops = {
  57. .disable = ccu_gate_disable,
  58. .enable = ccu_gate_enable,
  59. .is_enabled = ccu_gate_is_enabled,
  60. };