renesas-cpg-mssr.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Renesas RCar Gen3 CPG MSSR driver
  4. *
  5. * Copyright (C) 2017-2018 Marek Vasut <marek.vasut@gmail.com>
  6. *
  7. * Based on the following driver from Linux kernel:
  8. * r8a7796 Clock Pulse Generator / Module Standby and Software Reset
  9. *
  10. * Copyright (C) 2016 Glider bvba
  11. */
  12. #ifndef __DRIVERS_CLK_RENESAS_CPG_MSSR__
  13. #define __DRIVERS_CLK_RENESAS_CPG_MSSR__
  14. struct cpg_mssr_info {
  15. const struct cpg_core_clk *core_clk;
  16. unsigned int core_clk_size;
  17. const struct mssr_mod_clk *mod_clk;
  18. unsigned int mod_clk_size;
  19. const struct mstp_stop_table *mstp_table;
  20. unsigned int mstp_table_size;
  21. const char *reset_node;
  22. const char *extalr_node;
  23. const char *extal_usb_node;
  24. unsigned int mod_clk_base;
  25. unsigned int clk_extal_id;
  26. unsigned int clk_extalr_id;
  27. unsigned int clk_extal_usb_id;
  28. unsigned int pll0_div;
  29. const void *(*get_pll_config)(const u32 cpg_mode);
  30. };
  31. /*
  32. * Definitions of CPG Core Clocks
  33. *
  34. * These include:
  35. * - Clock outputs exported to DT
  36. * - External input clocks
  37. * - Internal CPG clocks
  38. */
  39. struct cpg_core_clk {
  40. /* Common */
  41. const char *name;
  42. unsigned int id;
  43. unsigned int type;
  44. /* Depending on type */
  45. unsigned int parent; /* Core Clocks only */
  46. unsigned int div;
  47. unsigned int mult;
  48. unsigned int offset;
  49. };
  50. enum clk_types {
  51. /* Generic */
  52. CLK_TYPE_IN, /* External Clock Input */
  53. CLK_TYPE_FF, /* Fixed Factor Clock */
  54. CLK_TYPE_DIV6P1, /* DIV6 Clock with 1 parent clock */
  55. CLK_TYPE_DIV6_RO, /* DIV6 Clock read only with extra divisor */
  56. /* Custom definitions start here */
  57. CLK_TYPE_CUSTOM,
  58. };
  59. #define DEF_TYPE(_name, _id, _type...) \
  60. { .name = _name, .id = _id, .type = _type }
  61. #define DEF_BASE(_name, _id, _type, _parent...) \
  62. DEF_TYPE(_name, _id, _type, .parent = _parent)
  63. #define DEF_INPUT(_name, _id) \
  64. DEF_TYPE(_name, _id, CLK_TYPE_IN)
  65. #define DEF_FIXED(_name, _id, _parent, _div, _mult) \
  66. DEF_BASE(_name, _id, CLK_TYPE_FF, _parent, .div = _div, .mult = _mult)
  67. #define DEF_DIV6P1(_name, _id, _parent, _offset) \
  68. DEF_BASE(_name, _id, CLK_TYPE_DIV6P1, _parent, .offset = _offset)
  69. #define DEF_DIV6_RO(_name, _id, _parent, _offset, _div) \
  70. DEF_BASE(_name, _id, CLK_TYPE_DIV6_RO, _parent, .offset = _offset, .div = _div, .mult = 1)
  71. /*
  72. * Definitions of Module Clocks
  73. */
  74. struct mssr_mod_clk {
  75. const char *name;
  76. unsigned int id;
  77. unsigned int parent; /* Add MOD_CLK_BASE for Module Clocks */
  78. };
  79. /* Convert from sparse base-100 to packed index space */
  80. #define MOD_CLK_PACK(x) ((x) - ((x) / 100) * (100 - 32))
  81. #define MOD_CLK_ID(x) (MOD_CLK_BASE + MOD_CLK_PACK(x))
  82. #define DEF_MOD(_name, _mod, _parent...) \
  83. { .name = _name, .id = MOD_CLK_ID(_mod), .parent = _parent }
  84. struct mstp_stop_table {
  85. u32 sdis;
  86. u32 sen;
  87. u32 rdis;
  88. u32 ren;
  89. };
  90. #define TSTR0 0x04
  91. #define TSTR0_STR0 BIT(0)
  92. bool renesas_clk_is_mod(struct clk *clk);
  93. int renesas_clk_get_mod(struct clk *clk, struct cpg_mssr_info *info,
  94. const struct mssr_mod_clk **mssr);
  95. int renesas_clk_get_core(struct clk *clk, struct cpg_mssr_info *info,
  96. const struct cpg_core_clk **core);
  97. int renesas_clk_get_parent(struct clk *clk, struct cpg_mssr_info *info,
  98. struct clk *parent);
  99. int renesas_clk_endisable(struct clk *clk, void __iomem *base, bool enable);
  100. int renesas_clk_remove(void __iomem *base, struct cpg_mssr_info *info);
  101. #endif /* __DRIVERS_CLK_RENESAS_CPG_MSSR__ */