1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (C) STMicroelectronics 2022 - All Rights Reserved
4 * Author: Gabriel Fernandez <gabriel.fernandez@foss.st.com> for STMicroelectronics.
7 #include <linux/clk-provider.h>
9 struct stm32_rcc_match_data;
11 struct stm32_mux_cfg {
20 struct stm32_gate_cfg {
26 struct stm32_div_cfg {
32 const struct clk_div_table *table;
35 struct stm32_composite_cfg {
41 #define NO_ID 0xFFFFFFFF
43 #define NO_STM32_MUX 0xFFFF
44 #define NO_STM32_DIV 0xFFFF
45 #define NO_STM32_GATE 0xFFFF
52 struct clk_hw *(*func)(struct device *dev,
53 const struct stm32_rcc_match_data *data,
56 const struct clock_config *cfg);
59 struct clk_stm32_clock_data {
61 const struct stm32_gate_cfg *gates;
62 const struct stm32_mux_cfg *muxes;
63 const struct stm32_div_cfg *dividers;
64 struct clk_hw *(*is_multi_mux)(struct clk_hw *hw);
67 struct stm32_rcc_match_data {
68 struct clk_hw_onecell_data *hw_clks;
69 unsigned int num_clocks;
70 const struct clock_config *tab_clocks;
71 unsigned int maxbinding;
72 struct clk_stm32_clock_data *clock_data;
74 int (*check_security)(void __iomem *base,
75 const struct clock_config *cfg);
76 int (*multi_mux)(void __iomem *base, const struct clock_config *cfg);
79 int stm32_rcc_reset_init(struct device *dev, const struct of_device_id *match,
82 int stm32_rcc_init(struct device *dev, const struct of_device_id *match_data,
86 #define MUX_NO_RDY 0xFF
89 #define DIV_NO_RDY 0xFF
91 /* Definition of clock structure */
92 struct clk_stm32_mux {
96 struct clk_stm32_clock_data *clock_data;
97 spinlock_t *lock; /* spin lock */
100 #define to_clk_stm32_mux(_hw) container_of(_hw, struct clk_stm32_mux, hw)
102 struct clk_stm32_gate {
106 struct clk_stm32_clock_data *clock_data;
107 spinlock_t *lock; /* spin lock */
110 #define to_clk_stm32_gate(_hw) container_of(_hw, struct clk_stm32_gate, hw)
112 struct clk_stm32_div {
116 struct clk_stm32_clock_data *clock_data;
117 spinlock_t *lock; /* spin lock */
120 #define to_clk_stm32_divider(_hw) container_of(_hw, struct clk_stm32_div, hw)
122 struct clk_stm32_composite {
128 struct clk_stm32_clock_data *clock_data;
129 spinlock_t *lock; /* spin lock */
132 #define to_clk_stm32_composite(_hw) container_of(_hw, struct clk_stm32_composite, hw)
134 /* Clock operators */
135 extern const struct clk_ops clk_stm32_mux_ops;
136 extern const struct clk_ops clk_stm32_gate_ops;
137 extern const struct clk_ops clk_stm32_divider_ops;
138 extern const struct clk_ops clk_stm32_composite_ops;
140 /* Clock registering */
141 struct clk_hw *clk_stm32_mux_register(struct device *dev,
142 const struct stm32_rcc_match_data *data,
145 const struct clock_config *cfg);
147 struct clk_hw *clk_stm32_gate_register(struct device *dev,
148 const struct stm32_rcc_match_data *data,
151 const struct clock_config *cfg);
153 struct clk_hw *clk_stm32_div_register(struct device *dev,
154 const struct stm32_rcc_match_data *data,
157 const struct clock_config *cfg);
159 struct clk_hw *clk_stm32_composite_register(struct device *dev,
160 const struct stm32_rcc_match_data *data,
163 const struct clock_config *cfg);
165 #define STM32_CLOCK_CFG(_binding, _clk, _sec_id, _struct, _register)\
168 .sec_id = (_sec_id),\
169 .clock_cfg = (_struct) {_clk},\
170 .func = (_register),\
173 #define STM32_MUX_CFG(_binding, _clk, _sec_id)\
174 STM32_CLOCK_CFG(_binding, &(_clk), _sec_id, struct clk_stm32_mux *,\
175 &clk_stm32_mux_register)
177 #define STM32_GATE_CFG(_binding, _clk, _sec_id)\
178 STM32_CLOCK_CFG(_binding, &(_clk), _sec_id, struct clk_stm32_gate *,\
179 &clk_stm32_gate_register)
181 #define STM32_DIV_CFG(_binding, _clk, _sec_id)\
182 STM32_CLOCK_CFG(_binding, &(_clk), _sec_id, struct clk_stm32_div *,\
183 &clk_stm32_div_register)
185 #define STM32_COMPOSITE_CFG(_binding, _clk, _sec_id)\
186 STM32_CLOCK_CFG(_binding, &(_clk), _sec_id, struct clk_stm32_composite *,\
187 &clk_stm32_composite_register)