renesas-cpg-mssr.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * Renesas Clock Pulse Generator / Module Standby and Software Reset
  3. *
  4. * Copyright (C) 2015 Glider bvba
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; version 2 of the License.
  9. */
  10. #ifndef __CLK_RENESAS_CPG_MSSR_H__
  11. #define __CLK_RENESAS_CPG_MSSR_H__
  12. /*
  13. * Definitions of CPG Core Clocks
  14. *
  15. * These include:
  16. * - Clock outputs exported to DT
  17. * - External input clocks
  18. * - Internal CPG clocks
  19. */
  20. struct cpg_core_clk {
  21. /* Common */
  22. const char *name;
  23. unsigned int id;
  24. unsigned int type;
  25. /* Depending on type */
  26. unsigned int parent; /* Core Clocks only */
  27. unsigned int div;
  28. unsigned int mult;
  29. unsigned int offset;
  30. };
  31. enum clk_types {
  32. /* Generic */
  33. CLK_TYPE_IN, /* External Clock Input */
  34. CLK_TYPE_FF, /* Fixed Factor Clock */
  35. CLK_TYPE_DIV6P1, /* DIV6 Clock with 1 parent clock */
  36. CLK_TYPE_DIV6_RO, /* DIV6 Clock read only with extra divisor */
  37. /* Custom definitions start here */
  38. CLK_TYPE_CUSTOM,
  39. };
  40. #define DEF_TYPE(_name, _id, _type...) \
  41. { .name = _name, .id = _id, .type = _type }
  42. #define DEF_BASE(_name, _id, _type, _parent...) \
  43. DEF_TYPE(_name, _id, _type, .parent = _parent)
  44. #define DEF_INPUT(_name, _id) \
  45. DEF_TYPE(_name, _id, CLK_TYPE_IN)
  46. #define DEF_FIXED(_name, _id, _parent, _div, _mult) \
  47. DEF_BASE(_name, _id, CLK_TYPE_FF, _parent, .div = _div, .mult = _mult)
  48. #define DEF_DIV6P1(_name, _id, _parent, _offset) \
  49. DEF_BASE(_name, _id, CLK_TYPE_DIV6P1, _parent, .offset = _offset)
  50. #define DEF_DIV6_RO(_name, _id, _parent, _offset, _div) \
  51. DEF_BASE(_name, _id, CLK_TYPE_DIV6_RO, _parent, .offset = _offset, .div = _div, .mult = 1)
  52. /*
  53. * Definitions of Module Clocks
  54. */
  55. struct mssr_mod_clk {
  56. const char *name;
  57. unsigned int id;
  58. unsigned int parent; /* Add MOD_CLK_BASE for Module Clocks */
  59. };
  60. /* Convert from sparse base-100 to packed index space */
  61. #define MOD_CLK_PACK(x) ((x) - ((x) / 100) * (100 - 32))
  62. #define MOD_CLK_ID(x) (MOD_CLK_BASE + MOD_CLK_PACK(x))
  63. #define DEF_MOD(_name, _mod, _parent...) \
  64. { .name = _name, .id = MOD_CLK_ID(_mod), .parent = _parent }
  65. struct device_node;
  66. /**
  67. * SoC-specific CPG/MSSR Description
  68. *
  69. * @core_clks: Array of Core Clock definitions
  70. * @num_core_clks: Number of entries in core_clks[]
  71. * @last_dt_core_clk: ID of the last Core Clock exported to DT
  72. * @num_total_core_clks: Total number of Core Clocks (exported + internal)
  73. *
  74. * @mod_clks: Array of Module Clock definitions
  75. * @num_mod_clks: Number of entries in mod_clks[]
  76. * @num_hw_mod_clks: Number of Module Clocks supported by the hardware
  77. *
  78. * @crit_mod_clks: Array with Module Clock IDs of critical clocks that
  79. * should not be disabled without a knowledgeable driver
  80. * @num_crit_mod_clks: Number of entries in crit_mod_clks[]
  81. *
  82. * @core_pm_clks: Array with IDs of Core Clocks that are suitable for Power
  83. * Management, in addition to Module Clocks
  84. * @num_core_pm_clks: Number of entries in core_pm_clks[]
  85. *
  86. * @init: Optional callback to perform SoC-specific initialization
  87. * @cpg_clk_register: Optional callback to handle special Core Clock types
  88. */
  89. struct cpg_mssr_info {
  90. /* Core Clocks */
  91. const struct cpg_core_clk *core_clks;
  92. unsigned int num_core_clks;
  93. unsigned int last_dt_core_clk;
  94. unsigned int num_total_core_clks;
  95. /* Module Clocks */
  96. const struct mssr_mod_clk *mod_clks;
  97. unsigned int num_mod_clks;
  98. unsigned int num_hw_mod_clks;
  99. /* Critical Module Clocks that should not be disabled */
  100. const unsigned int *crit_mod_clks;
  101. unsigned int num_crit_mod_clks;
  102. /* Core Clocks suitable for PM, in addition to the Module Clocks */
  103. const unsigned int *core_pm_clks;
  104. unsigned int num_core_pm_clks;
  105. /* Callbacks */
  106. int (*init)(struct device *dev);
  107. struct clk *(*cpg_clk_register)(struct device *dev,
  108. const struct cpg_core_clk *core,
  109. const struct cpg_mssr_info *info,
  110. struct clk **clks, void __iomem *base);
  111. };
  112. extern const struct cpg_mssr_info r8a7743_cpg_mssr_info;
  113. extern const struct cpg_mssr_info r8a7745_cpg_mssr_info;
  114. extern const struct cpg_mssr_info r8a7790_cpg_mssr_info;
  115. extern const struct cpg_mssr_info r8a7791_cpg_mssr_info;
  116. extern const struct cpg_mssr_info r8a7792_cpg_mssr_info;
  117. extern const struct cpg_mssr_info r8a7794_cpg_mssr_info;
  118. extern const struct cpg_mssr_info r8a7795_cpg_mssr_info;
  119. extern const struct cpg_mssr_info r8a7796_cpg_mssr_info;
  120. extern const struct cpg_mssr_info r8a77995_cpg_mssr_info;
  121. /*
  122. * Helpers for fixing up clock tables depending on SoC revision
  123. */
  124. struct mssr_mod_reparent {
  125. unsigned int clk, parent;
  126. };
  127. extern void cpg_core_nullify_range(struct cpg_core_clk *core_clks,
  128. unsigned int num_core_clks,
  129. unsigned int first_clk,
  130. unsigned int last_clk);
  131. extern void mssr_mod_nullify(struct mssr_mod_clk *mod_clks,
  132. unsigned int num_mod_clks,
  133. const unsigned int *clks, unsigned int n);
  134. extern void mssr_mod_reparent(struct mssr_mod_clk *mod_clks,
  135. unsigned int num_mod_clks,
  136. const struct mssr_mod_reparent *clks,
  137. unsigned int n);
  138. #endif