clkc.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 meson_clk_pll {
  57. struct clk_hw hw;
  58. void __iomem *base;
  59. struct parm m;
  60. struct parm n;
  61. struct parm frac;
  62. struct parm od;
  63. struct parm od2;
  64. const struct pll_rate_table *rate_table;
  65. unsigned int rate_count;
  66. spinlock_t *lock;
  67. };
  68. #define to_meson_clk_pll(_hw) container_of(_hw, struct meson_clk_pll, hw)
  69. struct meson_clk_cpu {
  70. struct clk_hw hw;
  71. void __iomem *base;
  72. u16 reg_off;
  73. struct notifier_block clk_nb;
  74. const struct clk_div_table *div_table;
  75. };
  76. int meson_clk_cpu_notifier_cb(struct notifier_block *nb, unsigned long event,
  77. void *data);
  78. struct meson_clk_mpll {
  79. struct clk_hw hw;
  80. void __iomem *base;
  81. struct parm sdm;
  82. struct parm n2;
  83. /* FIXME ssen gate control? */
  84. spinlock_t *lock;
  85. };
  86. #define MESON_GATE(_name, _reg, _bit) \
  87. struct clk_gate _name = { \
  88. .reg = (void __iomem *) _reg, \
  89. .bit_idx = (_bit), \
  90. .lock = &clk_lock, \
  91. .hw.init = &(struct clk_init_data) { \
  92. .name = #_name, \
  93. .ops = &clk_gate_ops, \
  94. .parent_names = (const char *[]){ "clk81" }, \
  95. .num_parents = 1, \
  96. .flags = (CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED), \
  97. }, \
  98. };
  99. /* clk_ops */
  100. extern const struct clk_ops meson_clk_pll_ro_ops;
  101. extern const struct clk_ops meson_clk_pll_ops;
  102. extern const struct clk_ops meson_clk_cpu_ops;
  103. extern const struct clk_ops meson_clk_mpll_ro_ops;
  104. #endif /* __CLKC_H */