composite.c 1.5 KB

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