clk.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. #define CLK_HW_INIT(_name, _parent, _ops, _flags) \
  15. &(struct clk_init_data) { \
  16. .flags = _flags, \
  17. .name = _name, \
  18. .parent_names = (const char *[]) { _parent }, \
  19. .num_parents = 1, \
  20. .ops = _ops, \
  21. }
  22. #define CLK_HW_INIT_PARENTS(_name, _parents, _ops, _flags) \
  23. &(struct clk_init_data) { \
  24. .flags = _flags, \
  25. .name = _name, \
  26. .parent_names = _parents, \
  27. .num_parents = ARRAY_SIZE(_parents), \
  28. .ops = _ops, \
  29. }
  30. struct zx_pll_config {
  31. unsigned long rate;
  32. u32 cfg0;
  33. u32 cfg1;
  34. };
  35. struct clk_zx_pll {
  36. struct clk_hw hw;
  37. void __iomem *reg_base;
  38. const struct zx_pll_config *lookup_table; /* order by rate asc */
  39. int count;
  40. spinlock_t *lock;
  41. u8 pd_bit; /* power down bit */
  42. u8 lock_bit; /* pll lock flag bit */
  43. };
  44. #define PLL_RATE(_rate, _cfg0, _cfg1) \
  45. { \
  46. .rate = _rate, \
  47. .cfg0 = _cfg0, \
  48. .cfg1 = _cfg1, \
  49. }
  50. #define ZX_PLL(_name, _parent, _reg, _table, _pd, _lock) \
  51. { \
  52. .reg_base = (void __iomem *) _reg, \
  53. .lookup_table = _table, \
  54. .count = ARRAY_SIZE(_table), \
  55. .pd_bit = _pd, \
  56. .lock_bit = _lock, \
  57. .hw.init = CLK_HW_INIT(_name, _parent, &zx_pll_ops, \
  58. CLK_GET_RATE_NOCACHE), \
  59. }
  60. #define ZX296718_PLL(_name, _parent, _reg, _table) \
  61. ZX_PLL(_name, _parent, _reg, _table, 0, 30)
  62. struct zx_clk_gate {
  63. struct clk_gate gate;
  64. u16 id;
  65. };
  66. #define GATE(_id, _name, _parent, _reg, _bit, _flag, _gflags) \
  67. { \
  68. .gate = { \
  69. .reg = (void __iomem *) _reg, \
  70. .bit_idx = (_bit), \
  71. .flags = _gflags, \
  72. .lock = &clk_lock, \
  73. .hw.init = CLK_HW_INIT(_name, \
  74. _parent, \
  75. &clk_gate_ops, \
  76. _flag | CLK_IGNORE_UNUSED), \
  77. }, \
  78. .id = _id, \
  79. }
  80. struct zx_clk_fixed_factor {
  81. struct clk_fixed_factor factor;
  82. u16 id;
  83. };
  84. #define FFACTOR(_id, _name, _parent, _mult, _div, _flag) \
  85. { \
  86. .factor = { \
  87. .div = _div, \
  88. .mult = _mult, \
  89. .hw.init = CLK_HW_INIT(_name, \
  90. _parent, \
  91. &clk_fixed_factor_ops, \
  92. _flag), \
  93. }, \
  94. .id = _id, \
  95. }
  96. struct zx_clk_mux {
  97. struct clk_mux mux;
  98. u16 id;
  99. };
  100. #define MUX_F(_id, _name, _parent, _reg, _shift, _width, _flag, _mflag) \
  101. { \
  102. .mux = { \
  103. .reg = (void __iomem *) _reg, \
  104. .mask = BIT(_width) - 1, \
  105. .shift = _shift, \
  106. .flags = _mflag, \
  107. .lock = &clk_lock, \
  108. .hw.init = CLK_HW_INIT_PARENTS(_name, \
  109. _parent, \
  110. &clk_mux_ops, \
  111. _flag), \
  112. }, \
  113. .id = _id, \
  114. }
  115. #define MUX(_id, _name, _parent, _reg, _shift, _width) \
  116. MUX_F(_id, _name, _parent, _reg, _shift, _width, 0, 0)
  117. struct zx_clk_div {
  118. struct clk_divider div;
  119. u16 id;
  120. };
  121. #define DIV_T(_id, _name, _parent, _reg, _shift, _width, _flag, _table) \
  122. { \
  123. .div = { \
  124. .reg = (void __iomem *) _reg, \
  125. .shift = _shift, \
  126. .width = _width, \
  127. .flags = 0, \
  128. .table = _table, \
  129. .lock = &clk_lock, \
  130. .hw.init = CLK_HW_INIT(_name, \
  131. _parent, \
  132. &clk_divider_ops, \
  133. _flag), \
  134. }, \
  135. .id = _id, \
  136. }
  137. struct clk *clk_register_zx_pll(const char *name, const char *parent_name,
  138. unsigned long flags, void __iomem *reg_base,
  139. const struct zx_pll_config *lookup_table, int count, spinlock_t *lock);
  140. struct clk_zx_audio {
  141. struct clk_hw hw;
  142. void __iomem *reg_base;
  143. };
  144. struct clk *clk_register_zx_audio(const char *name,
  145. const char * const parent_name,
  146. unsigned long flags, void __iomem *reg_base);
  147. extern const struct clk_ops zx_pll_ops;
  148. #endif