owl-factor.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. //
  3. // OWL factor 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. #ifndef _OWL_FACTOR_H_
  11. #define _OWL_FACTOR_H_
  12. #include "owl-common.h"
  13. struct clk_factor_table {
  14. unsigned int val;
  15. unsigned int mul;
  16. unsigned int div;
  17. };
  18. struct owl_factor_hw {
  19. u32 reg;
  20. u8 shift;
  21. u8 width;
  22. u8 fct_flags;
  23. struct clk_factor_table *table;
  24. };
  25. struct owl_factor {
  26. struct owl_factor_hw factor_hw;
  27. struct owl_clk_common common;
  28. };
  29. #define OWL_FACTOR_HW(_reg, _shift, _width, _fct_flags, _table) \
  30. { \
  31. .reg = _reg, \
  32. .shift = _shift, \
  33. .width = _width, \
  34. .fct_flags = _fct_flags, \
  35. .table = _table, \
  36. }
  37. #define OWL_FACTOR(_struct, _name, _parent, _reg, \
  38. _shift, _width, _table, _fct_flags, _flags) \
  39. struct owl_factor _struct = { \
  40. .factor_hw = OWL_FACTOR_HW(_reg, _shift, \
  41. _width, _fct_flags, _table), \
  42. .common = { \
  43. .regmap = NULL, \
  44. .hw.init = CLK_HW_INIT(_name, \
  45. _parent, \
  46. &owl_factor_ops, \
  47. _flags), \
  48. }, \
  49. }
  50. #define div_mask(d) ((1 << ((d)->width)) - 1)
  51. static inline struct owl_factor *hw_to_owl_factor(const struct clk_hw *hw)
  52. {
  53. struct owl_clk_common *common = hw_to_owl_clk_common(hw);
  54. return container_of(common, struct owl_factor, common);
  55. }
  56. long owl_factor_helper_round_rate(struct owl_clk_common *common,
  57. const struct owl_factor_hw *factor_hw,
  58. unsigned long rate,
  59. unsigned long *parent_rate);
  60. unsigned long owl_factor_helper_recalc_rate(struct owl_clk_common *common,
  61. const struct owl_factor_hw *factor_hw,
  62. unsigned long parent_rate);
  63. int owl_factor_helper_set_rate(const struct owl_clk_common *common,
  64. const struct owl_factor_hw *factor_hw,
  65. unsigned long rate,
  66. unsigned long parent_rate);
  67. extern const struct clk_ops owl_factor_ops;
  68. #endif /* _OWL_FACTOR_H_ */