clk.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * Copyright 2015 Linaro Ltd.
  3. * Copyright (C) 2014 ZTE Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. */
  9. #ifndef __ZTE_CLK_H
  10. #define __ZTE_CLK_H
  11. #include <linux/clk-provider.h>
  12. #include <linux/spinlock.h>
  13. #define PNAME(x) static const char *x[]
  14. struct zx_pll_config {
  15. unsigned long rate;
  16. u32 cfg0;
  17. u32 cfg1;
  18. };
  19. struct clk_zx_pll {
  20. struct clk_hw hw;
  21. void __iomem *reg_base;
  22. const struct zx_pll_config *lookup_table; /* order by rate asc */
  23. int count;
  24. spinlock_t *lock;
  25. u8 pd_bit; /* power down bit */
  26. u8 lock_bit; /* pll lock flag bit */
  27. };
  28. #define PLL_RATE(_rate, _cfg0, _cfg1) \
  29. { \
  30. .rate = _rate, \
  31. .cfg0 = _cfg0, \
  32. .cfg1 = _cfg1, \
  33. }
  34. #define ZX_PLL(_name, _parent, _reg, _table, _pd, _lock) \
  35. { \
  36. .reg_base = (void __iomem *) _reg, \
  37. .lookup_table = _table, \
  38. .count = ARRAY_SIZE(_table), \
  39. .pd_bit = _pd, \
  40. .lock_bit = _lock, \
  41. .hw.init = CLK_HW_INIT(_name, _parent, &zx_pll_ops, \
  42. CLK_GET_RATE_NOCACHE), \
  43. }
  44. /*
  45. * The pd_bit is not available on ZX296718, so let's pass something
  46. * bigger than 31, e.g. 0xff, to indicate that.
  47. */
  48. #define ZX296718_PLL(_name, _parent, _reg, _table) \
  49. ZX_PLL(_name, _parent, _reg, _table, 0xff, 30)
  50. struct zx_clk_gate {
  51. struct clk_gate gate;
  52. u16 id;
  53. };
  54. #define GATE(_id, _name, _parent, _reg, _bit, _flag, _gflags) \
  55. { \
  56. .gate = { \
  57. .reg = (void __iomem *) _reg, \
  58. .bit_idx = (_bit), \
  59. .flags = _gflags, \
  60. .lock = &clk_lock, \
  61. .hw.init = CLK_HW_INIT(_name, \
  62. _parent, \
  63. &clk_gate_ops, \
  64. _flag | CLK_IGNORE_UNUSED), \
  65. }, \
  66. .id = _id, \
  67. }
  68. struct zx_clk_fixed_factor {
  69. struct clk_fixed_factor factor;
  70. u16 id;
  71. };
  72. #define FFACTOR(_id, _name, _parent, _mult, _div, _flag) \
  73. { \
  74. .factor = { \
  75. .div = _div, \
  76. .mult = _mult, \
  77. .hw.init = CLK_HW_INIT(_name, \
  78. _parent, \
  79. &clk_fixed_factor_ops, \
  80. _flag), \
  81. }, \
  82. .id = _id, \
  83. }
  84. struct zx_clk_mux {
  85. struct clk_mux mux;
  86. u16 id;
  87. };
  88. #define MUX_F(_id, _name, _parent, _reg, _shift, _width, _flag, _mflag) \
  89. { \
  90. .mux = { \
  91. .reg = (void __iomem *) _reg, \
  92. .mask = BIT(_width) - 1, \
  93. .shift = _shift, \
  94. .flags = _mflag, \
  95. .lock = &clk_lock, \
  96. .hw.init = CLK_HW_INIT_PARENTS(_name, \
  97. _parent, \
  98. &clk_mux_ops, \
  99. _flag), \
  100. }, \
  101. .id = _id, \
  102. }
  103. #define MUX(_id, _name, _parent, _reg, _shift, _width) \
  104. MUX_F(_id, _name, _parent, _reg, _shift, _width, 0, 0)
  105. struct zx_clk_div {
  106. struct clk_divider div;
  107. u16 id;
  108. };
  109. #define DIV_T(_id, _name, _parent, _reg, _shift, _width, _flag, _table) \
  110. { \
  111. .div = { \
  112. .reg = (void __iomem *) _reg, \
  113. .shift = _shift, \
  114. .width = _width, \
  115. .flags = 0, \
  116. .table = _table, \
  117. .lock = &clk_lock, \
  118. .hw.init = CLK_HW_INIT(_name, \
  119. _parent, \
  120. &clk_divider_ops, \
  121. _flag), \
  122. }, \
  123. .id = _id, \
  124. }
  125. struct clk_zx_audio_divider {
  126. struct clk_hw hw;
  127. void __iomem *reg_base;
  128. unsigned int rate_count;
  129. spinlock_t *lock;
  130. u16 id;
  131. };
  132. #define AUDIO_DIV(_id, _name, _parent, _reg) \
  133. { \
  134. .reg_base = (void __iomem *) _reg, \
  135. .lock = &clk_lock, \
  136. .hw.init = CLK_HW_INIT(_name, \
  137. _parent, \
  138. &zx_audio_div_ops, \
  139. 0), \
  140. .id = _id, \
  141. }
  142. struct clk *clk_register_zx_pll(const char *name, const char *parent_name,
  143. unsigned long flags, void __iomem *reg_base,
  144. const struct zx_pll_config *lookup_table, int count, spinlock_t *lock);
  145. struct clk_zx_audio {
  146. struct clk_hw hw;
  147. void __iomem *reg_base;
  148. };
  149. struct clk *clk_register_zx_audio(const char *name,
  150. const char * const parent_name,
  151. unsigned long flags, void __iomem *reg_base);
  152. extern const struct clk_ops zx_pll_ops;
  153. extern const struct clk_ops zx_audio_div_ops;
  154. #endif