clk-stm32-core.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) STMicroelectronics 2022 - All Rights Reserved
  4. * Author: Gabriel Fernandez <gabriel.fernandez@foss.st.com> for STMicroelectronics.
  5. */
  6. #include <linux/clk-provider.h>
  7. struct stm32_rcc_match_data;
  8. struct stm32_mux_cfg {
  9. u16 offset;
  10. u8 shift;
  11. u8 width;
  12. u8 flags;
  13. u32 *table;
  14. u8 ready;
  15. };
  16. struct stm32_gate_cfg {
  17. u16 offset;
  18. u8 bit_idx;
  19. u8 set_clr;
  20. };
  21. struct stm32_div_cfg {
  22. u16 offset;
  23. u8 shift;
  24. u8 width;
  25. u8 flags;
  26. u8 ready;
  27. const struct clk_div_table *table;
  28. };
  29. struct stm32_composite_cfg {
  30. int mux;
  31. int gate;
  32. int div;
  33. };
  34. #define NO_ID 0xFFFFFFFF
  35. #define NO_STM32_MUX 0xFFFF
  36. #define NO_STM32_DIV 0xFFFF
  37. #define NO_STM32_GATE 0xFFFF
  38. struct clock_config {
  39. unsigned long id;
  40. int sec_id;
  41. void *clock_cfg;
  42. struct clk_hw *(*func)(struct device *dev,
  43. const struct stm32_rcc_match_data *data,
  44. void __iomem *base,
  45. spinlock_t *lock,
  46. const struct clock_config *cfg);
  47. };
  48. struct clk_stm32_clock_data {
  49. u16 *gate_cpt;
  50. const struct stm32_gate_cfg *gates;
  51. const struct stm32_mux_cfg *muxes;
  52. const struct stm32_div_cfg *dividers;
  53. struct clk_hw *(*is_multi_mux)(struct clk_hw *hw);
  54. };
  55. struct stm32_rcc_match_data {
  56. struct clk_hw_onecell_data *hw_clks;
  57. unsigned int num_clocks;
  58. const struct clock_config *tab_clocks;
  59. unsigned int maxbinding;
  60. struct clk_stm32_clock_data *clock_data;
  61. struct clk_stm32_reset_data *reset_data;
  62. int (*check_security)(struct device_node *np, void __iomem *base,
  63. const struct clock_config *cfg);
  64. int (*multi_mux)(void __iomem *base, const struct clock_config *cfg);
  65. };
  66. int stm32_rcc_init(struct device *dev, const struct of_device_id *match_data,
  67. void __iomem *base);
  68. /* MUX define */
  69. #define MUX_NO_RDY 0xFF
  70. #define MUX_SAFE BIT(7)
  71. /* DIV define */
  72. #define DIV_NO_RDY 0xFF
  73. /* Definition of clock structure */
  74. struct clk_stm32_mux {
  75. u16 mux_id;
  76. struct clk_hw hw;
  77. void __iomem *base;
  78. struct clk_stm32_clock_data *clock_data;
  79. spinlock_t *lock; /* spin lock */
  80. };
  81. #define to_clk_stm32_mux(_hw) container_of(_hw, struct clk_stm32_mux, hw)
  82. struct clk_stm32_gate {
  83. u16 gate_id;
  84. struct clk_hw hw;
  85. void __iomem *base;
  86. struct clk_stm32_clock_data *clock_data;
  87. spinlock_t *lock; /* spin lock */
  88. };
  89. #define to_clk_stm32_gate(_hw) container_of(_hw, struct clk_stm32_gate, hw)
  90. struct clk_stm32_div {
  91. u16 div_id;
  92. struct clk_hw hw;
  93. void __iomem *base;
  94. struct clk_stm32_clock_data *clock_data;
  95. spinlock_t *lock; /* spin lock */
  96. };
  97. #define to_clk_stm32_divider(_hw) container_of(_hw, struct clk_stm32_div, hw)
  98. struct clk_stm32_composite {
  99. u16 gate_id;
  100. u16 mux_id;
  101. u16 div_id;
  102. struct clk_hw hw;
  103. void __iomem *base;
  104. struct clk_stm32_clock_data *clock_data;
  105. spinlock_t *lock; /* spin lock */
  106. };
  107. #define to_clk_stm32_composite(_hw) container_of(_hw, struct clk_stm32_composite, hw)
  108. /* Clock operators */
  109. extern const struct clk_ops clk_stm32_mux_ops;
  110. extern const struct clk_ops clk_stm32_gate_ops;
  111. extern const struct clk_ops clk_stm32_divider_ops;
  112. extern const struct clk_ops clk_stm32_composite_ops;
  113. /* Clock registering */
  114. struct clk_hw *clk_stm32_mux_register(struct device *dev,
  115. const struct stm32_rcc_match_data *data,
  116. void __iomem *base,
  117. spinlock_t *lock,
  118. const struct clock_config *cfg);
  119. struct clk_hw *clk_stm32_gate_register(struct device *dev,
  120. const struct stm32_rcc_match_data *data,
  121. void __iomem *base,
  122. spinlock_t *lock,
  123. const struct clock_config *cfg);
  124. struct clk_hw *clk_stm32_div_register(struct device *dev,
  125. const struct stm32_rcc_match_data *data,
  126. void __iomem *base,
  127. spinlock_t *lock,
  128. const struct clock_config *cfg);
  129. struct clk_hw *clk_stm32_composite_register(struct device *dev,
  130. const struct stm32_rcc_match_data *data,
  131. void __iomem *base,
  132. spinlock_t *lock,
  133. const struct clock_config *cfg);
  134. #define STM32_CLOCK_CFG(_binding, _clk, _sec_id, _struct, _register)\
  135. {\
  136. .id = (_binding),\
  137. .sec_id = (_sec_id),\
  138. .clock_cfg = (_struct) {_clk},\
  139. .func = (_register),\
  140. }
  141. #define STM32_MUX_CFG(_binding, _clk, _sec_id)\
  142. STM32_CLOCK_CFG(_binding, &(_clk), _sec_id, struct clk_stm32_mux *,\
  143. &clk_stm32_mux_register)
  144. #define STM32_GATE_CFG(_binding, _clk, _sec_id)\
  145. STM32_CLOCK_CFG(_binding, &(_clk), _sec_id, struct clk_stm32_gate *,\
  146. &clk_stm32_gate_register)
  147. #define STM32_DIV_CFG(_binding, _clk, _sec_id)\
  148. STM32_CLOCK_CFG(_binding, &(_clk), _sec_id, struct clk_stm32_div *,\
  149. &clk_stm32_div_register)
  150. #define STM32_COMPOSITE_CFG(_binding, _clk, _sec_id)\
  151. STM32_CLOCK_CFG(_binding, &(_clk), _sec_id, struct clk_stm32_composite *,\
  152. &clk_stm32_composite_register)