renesas-cpg-mssr.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. /* Custom definitions start here */
  37. CLK_TYPE_CUSTOM,
  38. };
  39. #define DEF_TYPE(_name, _id, _type...) \
  40. { .name = _name, .id = _id, .type = _type }
  41. #define DEF_BASE(_name, _id, _type, _parent...) \
  42. DEF_TYPE(_name, _id, _type, .parent = _parent)
  43. #define DEF_INPUT(_name, _id) \
  44. DEF_TYPE(_name, _id, CLK_TYPE_IN)
  45. #define DEF_FIXED(_name, _id, _parent, _div, _mult) \
  46. DEF_BASE(_name, _id, CLK_TYPE_FF, _parent, .div = _div, .mult = _mult)
  47. #define DEF_DIV6P1(_name, _id, _parent, _offset) \
  48. DEF_BASE(_name, _id, CLK_TYPE_DIV6P1, _parent, .offset = _offset)
  49. #define DEF_SD(_name, _id, _parent, _offset) \
  50. DEF_BASE(_name, _id, CLK_TYPE_GEN3_SD, _parent, .offset = _offset)
  51. /*
  52. * Definitions of Module Clocks
  53. */
  54. struct mssr_mod_clk {
  55. const char *name;
  56. unsigned int id;
  57. unsigned int parent; /* Add MOD_CLK_BASE for Module Clocks */
  58. };
  59. /* Convert from sparse base-100 to packed index space */
  60. #define MOD_CLK_PACK(x) ((x) - ((x) / 100) * (100 - 32))
  61. #define MOD_CLK_ID(x) (MOD_CLK_BASE + MOD_CLK_PACK(x))
  62. #define DEF_MOD(_name, _mod, _parent...) \
  63. { .name = _name, .id = MOD_CLK_ID(_mod), .parent = _parent }
  64. struct device_node;
  65. /**
  66. * SoC-specific CPG/MSSR Description
  67. *
  68. * @core_clks: Array of Core Clock definitions
  69. * @num_core_clks: Number of entries in core_clks[]
  70. * @last_dt_core_clk: ID of the last Core Clock exported to DT
  71. * @num_total_core_clks: Total number of Core Clocks (exported + internal)
  72. *
  73. * @mod_clks: Array of Module Clock definitions
  74. * @num_mod_clks: Number of entries in mod_clks[]
  75. * @num_hw_mod_clks: Number of Module Clocks supported by the hardware
  76. *
  77. * @crit_mod_clks: Array with Module Clock IDs of critical clocks that
  78. * should not be disabled without a knowledgeable driver
  79. * @num_crit_mod_clks: Number of entries in crit_mod_clks[]
  80. *
  81. * @core_pm_clks: Array with IDs of Core Clocks that are suitable for Power
  82. * Management, in addition to Module Clocks
  83. * @num_core_pm_clks: Number of entries in core_pm_clks[]
  84. *
  85. * @init: Optional callback to perform SoC-specific initialization
  86. * @cpg_clk_register: Optional callback to handle special Core Clock types
  87. */
  88. struct cpg_mssr_info {
  89. /* Core Clocks */
  90. const struct cpg_core_clk *core_clks;
  91. unsigned int num_core_clks;
  92. unsigned int last_dt_core_clk;
  93. unsigned int num_total_core_clks;
  94. /* Module Clocks */
  95. const struct mssr_mod_clk *mod_clks;
  96. unsigned int num_mod_clks;
  97. unsigned int num_hw_mod_clks;
  98. /* Critical Module Clocks that should not be disabled */
  99. const unsigned int *crit_mod_clks;
  100. unsigned int num_crit_mod_clks;
  101. /* Core Clocks suitable for PM, in addition to the Module Clocks */
  102. const unsigned int *core_pm_clks;
  103. unsigned int num_core_pm_clks;
  104. /* Callbacks */
  105. int (*init)(struct device *dev);
  106. struct clk *(*cpg_clk_register)(struct device *dev,
  107. const struct cpg_core_clk *core,
  108. const struct cpg_mssr_info *info,
  109. struct clk **clks, void __iomem *base);
  110. };
  111. extern const struct cpg_mssr_info r8a7795_cpg_mssr_info;
  112. #endif