composite.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // SPDX-License-Identifier: GPL-2.0
  2. //
  3. // Spreadtrum composite clock driver
  4. //
  5. // Copyright (C) 2017 Spreadtrum, Inc.
  6. // Author: Chunyan Zhang <[email protected]>
  7. #include <linux/clk-provider.h>
  8. #include "composite.h"
  9. static long sprd_comp_round_rate(struct clk_hw *hw, unsigned long rate,
  10. unsigned long *parent_rate)
  11. {
  12. struct sprd_comp *cc = hw_to_sprd_comp(hw);
  13. return sprd_div_helper_round_rate(&cc->common, &cc->div,
  14. rate, parent_rate);
  15. }
  16. static unsigned long sprd_comp_recalc_rate(struct clk_hw *hw,
  17. unsigned long parent_rate)
  18. {
  19. struct sprd_comp *cc = hw_to_sprd_comp(hw);
  20. return sprd_div_helper_recalc_rate(&cc->common, &cc->div, parent_rate);
  21. }
  22. static int sprd_comp_set_rate(struct clk_hw *hw, unsigned long rate,
  23. unsigned long parent_rate)
  24. {
  25. struct sprd_comp *cc = hw_to_sprd_comp(hw);
  26. return sprd_div_helper_set_rate(&cc->common, &cc->div,
  27. rate, parent_rate);
  28. }
  29. static u8 sprd_comp_get_parent(struct clk_hw *hw)
  30. {
  31. struct sprd_comp *cc = hw_to_sprd_comp(hw);
  32. return sprd_mux_helper_get_parent(&cc->common, &cc->mux);
  33. }
  34. static int sprd_comp_set_parent(struct clk_hw *hw, u8 index)
  35. {
  36. struct sprd_comp *cc = hw_to_sprd_comp(hw);
  37. return sprd_mux_helper_set_parent(&cc->common, &cc->mux, index);
  38. }
  39. const struct clk_ops sprd_comp_ops = {
  40. .get_parent = sprd_comp_get_parent,
  41. .set_parent = sprd_comp_set_parent,
  42. .round_rate = sprd_comp_round_rate,
  43. .recalc_rate = sprd_comp_recalc_rate,
  44. .set_rate = sprd_comp_set_rate,
  45. };
  46. EXPORT_SYMBOL_GPL(sprd_comp_ops);