clk-pxa.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * Marvell PXA family clocks
  3. *
  4. * Copyright (C) 2014 Robert Jarzmik
  5. *
  6. * Common clock code for PXA clocks ("CKEN" type clocks + DT)
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; version 2 of the License.
  11. *
  12. */
  13. #ifndef _CLK_PXA_
  14. #define _CLK_PXA_
  15. #define CLKCFG_TURBO 0x1
  16. #define CLKCFG_FCS 0x2
  17. #define CLKCFG_HALFTURBO 0x4
  18. #define CLKCFG_FASTBUS 0x8
  19. #define PARENTS(name) \
  20. static const char *const name ## _parents[] __initconst
  21. #define MUX_RO_RATE_RO_OPS(name, clk_name) \
  22. static struct clk_hw name ## _mux_hw; \
  23. static struct clk_hw name ## _rate_hw; \
  24. static struct clk_ops name ## _mux_ops = { \
  25. .get_parent = name ## _get_parent, \
  26. .set_parent = dummy_clk_set_parent, \
  27. }; \
  28. static struct clk_ops name ## _rate_ops = { \
  29. .recalc_rate = name ## _get_rate, \
  30. }; \
  31. static struct clk * __init clk_register_ ## name(void) \
  32. { \
  33. return clk_register_composite(NULL, clk_name, \
  34. name ## _parents, \
  35. ARRAY_SIZE(name ## _parents), \
  36. &name ## _mux_hw, &name ## _mux_ops, \
  37. &name ## _rate_hw, &name ## _rate_ops, \
  38. NULL, NULL, CLK_GET_RATE_NOCACHE); \
  39. }
  40. #define RATE_RO_OPS(name, clk_name) \
  41. static struct clk_hw name ## _rate_hw; \
  42. static const struct clk_ops name ## _rate_ops = { \
  43. .recalc_rate = name ## _get_rate, \
  44. }; \
  45. static struct clk * __init clk_register_ ## name(void) \
  46. { \
  47. return clk_register_composite(NULL, clk_name, \
  48. name ## _parents, \
  49. ARRAY_SIZE(name ## _parents), \
  50. NULL, NULL, \
  51. &name ## _rate_hw, &name ## _rate_ops, \
  52. NULL, NULL, CLK_GET_RATE_NOCACHE); \
  53. }
  54. #define RATE_OPS(name, clk_name) \
  55. static struct clk_hw name ## _rate_hw; \
  56. static struct clk_ops name ## _rate_ops = { \
  57. .recalc_rate = name ## _get_rate, \
  58. .set_rate = name ## _set_rate, \
  59. .determine_rate = name ## _determine_rate, \
  60. }; \
  61. static struct clk * __init clk_register_ ## name(void) \
  62. { \
  63. return clk_register_composite(NULL, clk_name, \
  64. name ## _parents, \
  65. ARRAY_SIZE(name ## _parents), \
  66. NULL, NULL, \
  67. &name ## _rate_hw, &name ## _rate_ops, \
  68. NULL, NULL, CLK_GET_RATE_NOCACHE); \
  69. }
  70. #define MUX_OPS(name, clk_name, flags) \
  71. static struct clk_hw name ## _mux_hw; \
  72. static const struct clk_ops name ## _mux_ops = { \
  73. .get_parent = name ## _get_parent, \
  74. .set_parent = name ## _set_parent, \
  75. .determine_rate = name ## _determine_rate, \
  76. }; \
  77. static struct clk * __init clk_register_ ## name(void) \
  78. { \
  79. return clk_register_composite(NULL, clk_name, \
  80. name ## _parents, \
  81. ARRAY_SIZE(name ## _parents), \
  82. &name ## _mux_hw, &name ## _mux_ops, \
  83. NULL, NULL, \
  84. NULL, NULL, \
  85. CLK_GET_RATE_NOCACHE | flags); \
  86. }
  87. /*
  88. * CKEN clock type
  89. * This clock takes it source from 2 possible parents :
  90. * - a low power parent
  91. * - a normal parent
  92. *
  93. * +------------+ +-----------+
  94. * | Low Power | --- | x mult_lp |
  95. * | Clock | | / div_lp |\
  96. * +------------+ +-----------+ \+-----+ +-----------+
  97. * | Mux |---| CKEN gate |
  98. * +------------+ +-----------+ /+-----+ +-----------+
  99. * | High Power | | x mult_hp |/
  100. * | Clock | --- | / div_hp |
  101. * +------------+ +-----------+
  102. */
  103. struct desc_clk_cken {
  104. struct clk_hw hw;
  105. int ckid;
  106. const char *name;
  107. const char *dev_id;
  108. const char *con_id;
  109. const char * const *parent_names;
  110. struct clk_fixed_factor lp;
  111. struct clk_fixed_factor hp;
  112. struct clk_gate gate;
  113. bool (*is_in_low_power)(void);
  114. const unsigned long flags;
  115. };
  116. #define PXA_CKEN(_dev_id, _con_id, _name, parents, _mult_lp, _div_lp, \
  117. _mult_hp, _div_hp, is_lp, _cken_reg, _cken_bit, flag) \
  118. { .ckid = CLK_ ## _name, .name = #_name, \
  119. .dev_id = _dev_id, .con_id = _con_id, .parent_names = parents,\
  120. .lp = { .mult = _mult_lp, .div = _div_lp }, \
  121. .hp = { .mult = _mult_hp, .div = _div_hp }, \
  122. .is_in_low_power = is_lp, \
  123. .gate = { .reg = (void __iomem *)_cken_reg, .bit_idx = _cken_bit }, \
  124. .flags = flag, \
  125. }
  126. #define PXA_CKEN_1RATE(dev_id, con_id, name, parents, cken_reg, \
  127. cken_bit, flag) \
  128. PXA_CKEN(dev_id, con_id, name, parents, 1, 1, 1, 1, \
  129. NULL, cken_reg, cken_bit, flag)
  130. struct pxa2xx_freq {
  131. unsigned long cpll;
  132. unsigned int membus_khz;
  133. unsigned int cccr;
  134. unsigned int div2;
  135. unsigned int clkcfg;
  136. };
  137. static inline int dummy_clk_set_parent(struct clk_hw *hw, u8 index)
  138. {
  139. return 0;
  140. }
  141. extern void clkdev_pxa_register(int ckid, const char *con_id,
  142. const char *dev_id, struct clk *clk);
  143. extern int clk_pxa_cken_init(const struct desc_clk_cken *clks, int nb_clks);
  144. void clk_pxa_dt_common_init(struct device_node *np);
  145. void pxa2xx_core_turbo_switch(bool on);
  146. void pxa2xx_cpll_change(struct pxa2xx_freq *freq,
  147. u32 (*mdrefr_dri)(unsigned int), void __iomem *mdrefr,
  148. void __iomem *cccr);
  149. int pxa2xx_determine_rate(struct clk_rate_request *req,
  150. struct pxa2xx_freq *freqs, int nb_freqs);
  151. #endif