clk-pxa.h 4.9 KB

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