owl-pll.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // SPDX-License-Identifier: GPL-2.0+
  2. //
  3. // OWL pll clock driver
  4. //
  5. // Copyright (c) 2014 Actions Semi Inc.
  6. // Author: David Liu <liuwei@actions-semi.com>
  7. //
  8. // Copyright (c) 2018 Linaro Ltd.
  9. // Author: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
  10. #ifndef _OWL_PLL_H_
  11. #define _OWL_PLL_H_
  12. #include "owl-common.h"
  13. /* last entry should have rate = 0 */
  14. struct clk_pll_table {
  15. unsigned int val;
  16. unsigned long rate;
  17. };
  18. struct owl_pll_hw {
  19. u32 reg;
  20. u32 bfreq;
  21. u8 bit_idx;
  22. u8 shift;
  23. u8 width;
  24. u8 min_mul;
  25. u8 max_mul;
  26. const struct clk_pll_table *table;
  27. };
  28. struct owl_pll {
  29. struct owl_pll_hw pll_hw;
  30. struct owl_clk_common common;
  31. };
  32. #define OWL_PLL_HW(_reg, _bfreq, _bit_idx, _shift, \
  33. _width, _min_mul, _max_mul, _table) \
  34. { \
  35. .reg = _reg, \
  36. .bfreq = _bfreq, \
  37. .bit_idx = _bit_idx, \
  38. .shift = _shift, \
  39. .width = _width, \
  40. .min_mul = _min_mul, \
  41. .max_mul = _max_mul, \
  42. .table = _table, \
  43. }
  44. #define OWL_PLL(_struct, _name, _parent, _reg, _bfreq, _bit_idx, \
  45. _shift, _width, _min_mul, _max_mul, _table, _flags) \
  46. struct owl_pll _struct = { \
  47. .pll_hw = OWL_PLL_HW(_reg, _bfreq, _bit_idx, _shift, \
  48. _width, _min_mul, \
  49. _max_mul, _table), \
  50. .common = { \
  51. .regmap = NULL, \
  52. .hw.init = CLK_HW_INIT(_name, \
  53. _parent, \
  54. &owl_pll_ops, \
  55. _flags), \
  56. }, \
  57. }
  58. #define OWL_PLL_NO_PARENT(_struct, _name, _reg, _bfreq, _bit_idx, \
  59. _shift, _width, _min_mul, _max_mul, _table, _flags) \
  60. struct owl_pll _struct = { \
  61. .pll_hw = OWL_PLL_HW(_reg, _bfreq, _bit_idx, _shift, \
  62. _width, _min_mul, \
  63. _max_mul, _table), \
  64. .common = { \
  65. .regmap = NULL, \
  66. .hw.init = CLK_HW_INIT_NO_PARENT(_name, \
  67. &owl_pll_ops, \
  68. _flags), \
  69. }, \
  70. }
  71. #define mul_mask(m) ((1 << ((m)->width)) - 1)
  72. #define PLL_STABILITY_WAIT_US (50)
  73. static inline struct owl_pll *hw_to_owl_pll(const struct clk_hw *hw)
  74. {
  75. struct owl_clk_common *common = hw_to_owl_clk_common(hw);
  76. return container_of(common, struct owl_pll, common);
  77. }
  78. extern const struct clk_ops owl_pll_ops;
  79. #endif /* _OWL_PLL_H_ */