clk-cv18xx-pll.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2023 Inochi Amaoto <inochiama@outlook.com>
  4. */
  5. #ifndef _CLK_SOPHGO_CV1800_PLL_H_
  6. #define _CLK_SOPHGO_CV1800_PLL_H_
  7. #include "clk-cv18xx-common.h"
  8. struct cv1800_clk_pll_limit {
  9. struct {
  10. u8 min;
  11. u8 max;
  12. } pre_div, div, post_div, ictrl, mode;
  13. };
  14. #define _CV1800_PLL_LIMIT(_min, _max) \
  15. { \
  16. .min = _min, \
  17. .max = _max, \
  18. } \
  19. #define for_each_pll_limit_range(_var, _restrict) \
  20. for (_var = (_restrict)->min; _var <= (_restrict)->max; _var++)
  21. struct cv1800_clk_pll_synthesizer {
  22. struct cv1800_clk_regbit en;
  23. struct cv1800_clk_regbit clk_half;
  24. u32 ctrl;
  25. u32 set;
  26. };
  27. #define _PLL_PRE_DIV_SEL_FIELD GENMASK(6, 0)
  28. #define _PLL_POST_DIV_SEL_FIELD GENMASK(14, 8)
  29. #define _PLL_SEL_MODE_FIELD GENMASK(16, 15)
  30. #define _PLL_DIV_SEL_FIELD GENMASK(23, 17)
  31. #define _PLL_ICTRL_FIELD GENMASK(26, 24)
  32. #define _PLL_ALL_FIELD_MASK \
  33. (_PLL_PRE_DIV_SEL_FIELD | \
  34. _PLL_POST_DIV_SEL_FIELD | \
  35. _PLL_SEL_MODE_FIELD | \
  36. _PLL_DIV_SEL_FIELD | \
  37. _PLL_ICTRL_FIELD)
  38. #define PLL_COPY_REG(_dest, _src) \
  39. (((_dest) & (~_PLL_ALL_FIELD_MASK)) | ((_src) & _PLL_ALL_FIELD_MASK))
  40. #define PLL_GET_PRE_DIV_SEL(_reg) \
  41. FIELD_GET(_PLL_PRE_DIV_SEL_FIELD, (_reg))
  42. #define PLL_GET_POST_DIV_SEL(_reg) \
  43. FIELD_GET(_PLL_POST_DIV_SEL_FIELD, (_reg))
  44. #define PLL_GET_SEL_MODE(_reg) \
  45. FIELD_GET(_PLL_SEL_MODE_FIELD, (_reg))
  46. #define PLL_GET_DIV_SEL(_reg) \
  47. FIELD_GET(_PLL_DIV_SEL_FIELD, (_reg))
  48. #define PLL_GET_ICTRL(_reg) \
  49. FIELD_GET(_PLL_ICTRL_FIELD, (_reg))
  50. #define PLL_SET_PRE_DIV_SEL(_reg, _val) \
  51. _CV1800_SET_FIELD((_reg), (_val), _PLL_PRE_DIV_SEL_FIELD)
  52. #define PLL_SET_POST_DIV_SEL(_reg, _val) \
  53. _CV1800_SET_FIELD((_reg), (_val), _PLL_POST_DIV_SEL_FIELD)
  54. #define PLL_SET_SEL_MODE(_reg, _val) \
  55. _CV1800_SET_FIELD((_reg), (_val), _PLL_SEL_MODE_FIELD)
  56. #define PLL_SET_DIV_SEL(_reg, _val) \
  57. _CV1800_SET_FIELD((_reg), (_val), _PLL_DIV_SEL_FIELD)
  58. #define PLL_SET_ICTRL(_reg, _val) \
  59. _CV1800_SET_FIELD((_reg), (_val), _PLL_ICTRL_FIELD)
  60. struct cv1800_clk_pll {
  61. struct cv1800_clk_common common;
  62. u32 pll_reg;
  63. struct cv1800_clk_regbit pll_pwd;
  64. struct cv1800_clk_regbit pll_status;
  65. const struct cv1800_clk_pll_limit *pll_limit;
  66. struct cv1800_clk_pll_synthesizer *pll_syn;
  67. };
  68. #define CV1800_INTEGRAL_PLL(_name, _parent, _pll_reg, \
  69. _pll_pwd_reg, _pll_pwd_shift, \
  70. _pll_status_reg, _pll_status_shift, \
  71. _pll_limit, _flags) \
  72. struct cv1800_clk_pll _name = { \
  73. .common = CV1800_CLK_COMMON(#_name, _parent, \
  74. &cv1800_clk_ipll_ops,\
  75. _flags), \
  76. .pll_reg = _pll_reg, \
  77. .pll_pwd = CV1800_CLK_BIT(_pll_pwd_reg, \
  78. _pll_pwd_shift), \
  79. .pll_status = CV1800_CLK_BIT(_pll_status_reg, \
  80. _pll_status_shift), \
  81. .pll_limit = _pll_limit, \
  82. .pll_syn = NULL, \
  83. }
  84. #define CV1800_FACTIONAL_PLL(_name, _parent, _pll_reg, \
  85. _pll_pwd_reg, _pll_pwd_shift, \
  86. _pll_status_reg, _pll_status_shift, \
  87. _pll_limit, _pll_syn, _flags) \
  88. struct cv1800_clk_pll _name = { \
  89. .common = CV1800_CLK_COMMON(#_name, _parent, \
  90. &cv1800_clk_fpll_ops,\
  91. _flags), \
  92. .pll_reg = _pll_reg, \
  93. .pll_pwd = CV1800_CLK_BIT(_pll_pwd_reg, \
  94. _pll_pwd_shift), \
  95. .pll_status = CV1800_CLK_BIT(_pll_status_reg, \
  96. _pll_status_shift), \
  97. .pll_limit = _pll_limit, \
  98. .pll_syn = _pll_syn, \
  99. }
  100. extern const struct clk_ops cv1800_clk_ipll_ops;
  101. extern const struct clk_ops cv1800_clk_fpll_ops;
  102. #endif // _CLK_SOPHGO_CV1800_PLL_H_