clkc.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * Copyright (c) 2015 Endless Mobile, Inc.
  3. * Author: Carlo Caione <carlo@endlessm.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef __CLKC_H
  18. #define __CLKC_H
  19. #define PMASK(width) GENMASK(width - 1, 0)
  20. #define SETPMASK(width, shift) GENMASK(shift + width - 1, shift)
  21. #define CLRPMASK(width, shift) (~SETPMASK(width, shift))
  22. #define PARM_GET(width, shift, reg) \
  23. (((reg) & SETPMASK(width, shift)) >> (shift))
  24. #define PARM_SET(width, shift, reg, val) \
  25. (((reg) & CLRPMASK(width, shift)) | ((val) << (shift)))
  26. #define MESON_PARM_APPLICABLE(p) (!!((p)->width))
  27. struct parm {
  28. u16 reg_off;
  29. u8 shift;
  30. u8 width;
  31. };
  32. struct pll_rate_table {
  33. unsigned long rate;
  34. u16 m;
  35. u16 n;
  36. u16 od;
  37. u16 od2;
  38. u16 frac;
  39. };
  40. #define PLL_RATE(_r, _m, _n, _od) \
  41. { \
  42. .rate = (_r), \
  43. .m = (_m), \
  44. .n = (_n), \
  45. .od = (_od), \
  46. } \
  47. #define PLL_FRAC_RATE(_r, _m, _n, _od, _od2, _frac) \
  48. { \
  49. .rate = (_r), \
  50. .m = (_m), \
  51. .n = (_n), \
  52. .od = (_od), \
  53. .od2 = (_od2), \
  54. .frac = (_frac), \
  55. } \
  56. struct pll_params_table {
  57. unsigned int reg_off;
  58. unsigned int value;
  59. };
  60. #define PLL_PARAM(_reg, _val) \
  61. { \
  62. .reg_off = (_reg), \
  63. .value = (_val), \
  64. }
  65. struct pll_setup_params {
  66. struct pll_params_table *params_table;
  67. unsigned int params_count;
  68. /* Workaround for GP0, do not reset before configuring */
  69. bool no_init_reset;
  70. /* Workaround for GP0, unreset right before checking for lock */
  71. bool clear_reset_for_lock;
  72. /* Workaround for GXL GP0, reset in the lock checking loop */
  73. bool reset_lock_loop;
  74. };
  75. struct meson_clk_pll {
  76. struct clk_hw hw;
  77. void __iomem *base;
  78. struct parm m;
  79. struct parm n;
  80. struct parm frac;
  81. struct parm od;
  82. struct parm od2;
  83. const struct pll_setup_params params;
  84. const struct pll_rate_table *rate_table;
  85. unsigned int rate_count;
  86. spinlock_t *lock;
  87. };
  88. #define to_meson_clk_pll(_hw) container_of(_hw, struct meson_clk_pll, hw)
  89. struct meson_clk_cpu {
  90. struct clk_hw hw;
  91. void __iomem *base;
  92. u16 reg_off;
  93. struct notifier_block clk_nb;
  94. const struct clk_div_table *div_table;
  95. };
  96. int meson_clk_cpu_notifier_cb(struct notifier_block *nb, unsigned long event,
  97. void *data);
  98. struct meson_clk_mpll {
  99. struct clk_hw hw;
  100. void __iomem *base;
  101. struct parm sdm;
  102. struct parm sdm_en;
  103. struct parm n2;
  104. struct parm en;
  105. spinlock_t *lock;
  106. };
  107. struct meson_clk_audio_divider {
  108. struct clk_hw hw;
  109. void __iomem *base;
  110. struct parm div;
  111. u8 flags;
  112. spinlock_t *lock;
  113. };
  114. #define MESON_GATE(_name, _reg, _bit) \
  115. struct clk_gate _name = { \
  116. .reg = (void __iomem *) _reg, \
  117. .bit_idx = (_bit), \
  118. .lock = &clk_lock, \
  119. .hw.init = &(struct clk_init_data) { \
  120. .name = #_name, \
  121. .ops = &clk_gate_ops, \
  122. .parent_names = (const char *[]){ "clk81" }, \
  123. .num_parents = 1, \
  124. .flags = (CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED), \
  125. }, \
  126. };
  127. /* clk_ops */
  128. extern const struct clk_ops meson_clk_pll_ro_ops;
  129. extern const struct clk_ops meson_clk_pll_ops;
  130. extern const struct clk_ops meson_clk_cpu_ops;
  131. extern const struct clk_ops meson_clk_mpll_ro_ops;
  132. extern const struct clk_ops meson_clk_mpll_ops;
  133. extern const struct clk_ops meson_clk_audio_divider_ro_ops;
  134. extern const struct clk_ops meson_clk_audio_divider_ops;
  135. #endif /* __CLKC_H */