developer | 2186c98 | 2018-11-15 10:07:54 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | /* |
| 3 | * Copyright (C) 2018 MediaTek Inc. |
| 4 | * Author: Ryder Lee <ryder.lee@mediatek.com> |
| 5 | */ |
| 6 | |
| 7 | #ifndef __DRV_CLK_MTK_H |
| 8 | #define __DRV_CLK_MTK_H |
| 9 | |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 10 | #include <linux/bitops.h> |
developer | 2186c98 | 2018-11-15 10:07:54 +0800 | [diff] [blame] | 11 | #define CLK_XTAL 0 |
| 12 | #define MHZ (1000 * 1000) |
| 13 | |
developer | 2dc4caa | 2022-09-09 19:59:59 +0800 | [diff] [blame] | 14 | /* flags in struct mtk_clk_tree */ |
| 15 | |
| 16 | /* clk id == 0 doesn't mean it's xtal clk */ |
| 17 | #define CLK_BYPASS_XTAL BIT(0) |
| 18 | |
developer | 2186c98 | 2018-11-15 10:07:54 +0800 | [diff] [blame] | 19 | #define HAVE_RST_BAR BIT(0) |
| 20 | #define CLK_DOMAIN_SCPSYS BIT(0) |
developer | ba560c7 | 2019-12-31 11:29:21 +0800 | [diff] [blame] | 21 | #define CLK_MUX_SETCLR_UPD BIT(1) |
developer | 2186c98 | 2018-11-15 10:07:54 +0800 | [diff] [blame] | 22 | |
| 23 | #define CLK_GATE_SETCLR BIT(0) |
| 24 | #define CLK_GATE_SETCLR_INV BIT(1) |
| 25 | #define CLK_GATE_NO_SETCLR BIT(2) |
| 26 | #define CLK_GATE_NO_SETCLR_INV BIT(3) |
| 27 | #define CLK_GATE_MASK GENMASK(3, 0) |
| 28 | |
| 29 | #define CLK_PARENT_APMIXED BIT(4) |
| 30 | #define CLK_PARENT_TOPCKGEN BIT(5) |
| 31 | #define CLK_PARENT_MASK GENMASK(5, 4) |
| 32 | |
developer | a588d15 | 2019-07-29 22:17:48 +0800 | [diff] [blame] | 33 | #define ETHSYS_HIFSYS_RST_CTRL_OFS 0x34 |
developer | 0225945 | 2018-12-20 16:12:52 +0800 | [diff] [blame] | 34 | |
developer | 2186c98 | 2018-11-15 10:07:54 +0800 | [diff] [blame] | 35 | /* struct mtk_pll_data - hardware-specific PLLs data */ |
| 36 | struct mtk_pll_data { |
| 37 | const int id; |
| 38 | u32 reg; |
| 39 | u32 pwr_reg; |
| 40 | u32 en_mask; |
| 41 | u32 pd_reg; |
| 42 | int pd_shift; |
| 43 | u32 flags; |
| 44 | u32 rst_bar_mask; |
| 45 | u64 fmax; |
developer | 0b5e5f1 | 2019-12-31 11:29:22 +0800 | [diff] [blame] | 46 | u64 fmin; |
developer | 2186c98 | 2018-11-15 10:07:54 +0800 | [diff] [blame] | 47 | int pcwbits; |
developer | 0b5e5f1 | 2019-12-31 11:29:22 +0800 | [diff] [blame] | 48 | int pcwibits; |
developer | 2186c98 | 2018-11-15 10:07:54 +0800 | [diff] [blame] | 49 | u32 pcw_reg; |
| 50 | int pcw_shift; |
developer | 0b5e5f1 | 2019-12-31 11:29:22 +0800 | [diff] [blame] | 51 | u32 pcw_chg_reg; |
developer | 2186c98 | 2018-11-15 10:07:54 +0800 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | /** |
| 55 | * struct mtk_fixed_clk - fixed clocks |
| 56 | * |
| 57 | * @id: index of clocks |
| 58 | * @parent: index of parnet clocks |
| 59 | * @rate: fixed rate |
| 60 | */ |
| 61 | struct mtk_fixed_clk { |
| 62 | const int id; |
| 63 | const int parent; |
| 64 | unsigned long rate; |
| 65 | }; |
| 66 | |
| 67 | #define FIXED_CLK(_id, _parent, _rate) { \ |
| 68 | .id = _id, \ |
| 69 | .parent = _parent, \ |
| 70 | .rate = _rate, \ |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * struct mtk_fixed_factor - fixed multiplier and divider clocks |
| 75 | * |
| 76 | * @id: index of clocks |
| 77 | * @parent: index of parnet clocks |
| 78 | * @mult: multiplier |
| 79 | * @div: divider |
| 80 | * @flag: hardware-specific flags |
| 81 | */ |
| 82 | struct mtk_fixed_factor { |
| 83 | const int id; |
| 84 | const int parent; |
| 85 | u32 mult; |
| 86 | u32 div; |
| 87 | u32 flags; |
| 88 | }; |
| 89 | |
| 90 | #define FACTOR(_id, _parent, _mult, _div, _flags) { \ |
| 91 | .id = _id, \ |
| 92 | .parent = _parent, \ |
| 93 | .mult = _mult, \ |
| 94 | .div = _div, \ |
| 95 | .flags = _flags, \ |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * struct mtk_composite - aggregate clock of mux, divider and gate clocks |
| 100 | * |
| 101 | * @id: index of clocks |
| 102 | * @parent: index of parnet clocks |
| 103 | * @mux_reg: hardware-specific mux register |
| 104 | * @gate_reg: hardware-specific gate register |
| 105 | * @mux_mask: mask to the mux bit field |
| 106 | * @mux_shift: shift to the mux bit field |
| 107 | * @gate_shift: shift to the gate bit field |
| 108 | * @num_parents: number of parent clocks |
| 109 | * @flags: hardware-specific flags |
| 110 | */ |
| 111 | struct mtk_composite { |
| 112 | const int id; |
| 113 | const int *parent; |
| 114 | u32 mux_reg; |
developer | ba560c7 | 2019-12-31 11:29:21 +0800 | [diff] [blame] | 115 | u32 mux_set_reg; |
| 116 | u32 mux_clr_reg; |
| 117 | u32 upd_reg; |
developer | 2186c98 | 2018-11-15 10:07:54 +0800 | [diff] [blame] | 118 | u32 gate_reg; |
| 119 | u32 mux_mask; |
| 120 | signed char mux_shift; |
developer | ba560c7 | 2019-12-31 11:29:21 +0800 | [diff] [blame] | 121 | signed char upd_shift; |
developer | 2186c98 | 2018-11-15 10:07:54 +0800 | [diff] [blame] | 122 | signed char gate_shift; |
| 123 | signed char num_parents; |
| 124 | u16 flags; |
| 125 | }; |
| 126 | |
| 127 | #define MUX_GATE_FLAGS(_id, _parents, _reg, _shift, _width, _gate, \ |
| 128 | _flags) { \ |
| 129 | .id = _id, \ |
| 130 | .mux_reg = _reg, \ |
| 131 | .mux_shift = _shift, \ |
| 132 | .mux_mask = BIT(_width) - 1, \ |
| 133 | .gate_reg = _reg, \ |
| 134 | .gate_shift = _gate, \ |
| 135 | .parent = _parents, \ |
| 136 | .num_parents = ARRAY_SIZE(_parents), \ |
| 137 | .flags = _flags, \ |
| 138 | } |
| 139 | |
| 140 | #define MUX_GATE(_id, _parents, _reg, _shift, _width, _gate) \ |
| 141 | MUX_GATE_FLAGS(_id, _parents, _reg, _shift, _width, _gate, 0) |
| 142 | |
| 143 | #define MUX(_id, _parents, _reg, _shift, _width) { \ |
| 144 | .id = _id, \ |
| 145 | .mux_reg = _reg, \ |
| 146 | .mux_shift = _shift, \ |
| 147 | .mux_mask = BIT(_width) - 1, \ |
| 148 | .gate_shift = -1, \ |
| 149 | .parent = _parents, \ |
| 150 | .num_parents = ARRAY_SIZE(_parents), \ |
| 151 | .flags = 0, \ |
| 152 | } |
| 153 | |
developer | ba560c7 | 2019-12-31 11:29:21 +0800 | [diff] [blame] | 154 | #define MUX_CLR_SET_UPD_FLAGS(_id, _parents, _mux_ofs, _mux_set_ofs,\ |
| 155 | _mux_clr_ofs, _shift, _width, _gate, \ |
| 156 | _upd_ofs, _upd, _flags) { \ |
| 157 | .id = _id, \ |
| 158 | .mux_reg = _mux_ofs, \ |
| 159 | .mux_set_reg = _mux_set_ofs, \ |
| 160 | .mux_clr_reg = _mux_clr_ofs, \ |
| 161 | .upd_reg = _upd_ofs, \ |
| 162 | .upd_shift = _upd, \ |
| 163 | .mux_shift = _shift, \ |
| 164 | .mux_mask = BIT(_width) - 1, \ |
| 165 | .gate_reg = _mux_ofs, \ |
| 166 | .gate_shift = _gate, \ |
| 167 | .parent = _parents, \ |
| 168 | .num_parents = ARRAY_SIZE(_parents), \ |
| 169 | .flags = _flags, \ |
| 170 | } |
| 171 | |
developer | 2186c98 | 2018-11-15 10:07:54 +0800 | [diff] [blame] | 172 | struct mtk_gate_regs { |
| 173 | u32 sta_ofs; |
| 174 | u32 clr_ofs; |
| 175 | u32 set_ofs; |
| 176 | }; |
| 177 | |
| 178 | /** |
| 179 | * struct mtk_gate - gate clocks |
| 180 | * |
| 181 | * @id: index of gate clocks |
| 182 | * @parent: index of parnet clocks |
| 183 | * @regs: hardware-specific mux register |
| 184 | * @shift: shift to the gate bit field |
| 185 | * @flags: hardware-specific flags |
| 186 | */ |
| 187 | struct mtk_gate { |
| 188 | const int id; |
| 189 | const int parent; |
| 190 | const struct mtk_gate_regs *regs; |
| 191 | int shift; |
| 192 | u32 flags; |
| 193 | }; |
| 194 | |
| 195 | /* struct mtk_clk_tree - clock tree */ |
| 196 | struct mtk_clk_tree { |
| 197 | unsigned long xtal_rate; |
| 198 | unsigned long xtal2_rate; |
| 199 | const int fdivs_offs; |
| 200 | const int muxes_offs; |
| 201 | const struct mtk_pll_data *plls; |
| 202 | const struct mtk_fixed_clk *fclks; |
| 203 | const struct mtk_fixed_factor *fdivs; |
| 204 | const struct mtk_composite *muxes; |
developer | 2dc4caa | 2022-09-09 19:59:59 +0800 | [diff] [blame] | 205 | u32 flags; |
developer | 2186c98 | 2018-11-15 10:07:54 +0800 | [diff] [blame] | 206 | }; |
| 207 | |
| 208 | struct mtk_clk_priv { |
developer | fd47f76 | 2022-09-09 20:00:01 +0800 | [diff] [blame^] | 209 | struct udevice *parent; |
developer | 2186c98 | 2018-11-15 10:07:54 +0800 | [diff] [blame] | 210 | void __iomem *base; |
| 211 | const struct mtk_clk_tree *tree; |
| 212 | }; |
| 213 | |
| 214 | struct mtk_cg_priv { |
developer | fd47f76 | 2022-09-09 20:00:01 +0800 | [diff] [blame^] | 215 | struct udevice *parent; |
developer | 2186c98 | 2018-11-15 10:07:54 +0800 | [diff] [blame] | 216 | void __iomem *base; |
| 217 | const struct mtk_clk_tree *tree; |
| 218 | const struct mtk_gate *gates; |
| 219 | }; |
| 220 | |
| 221 | extern const struct clk_ops mtk_clk_apmixedsys_ops; |
| 222 | extern const struct clk_ops mtk_clk_topckgen_ops; |
| 223 | extern const struct clk_ops mtk_clk_gate_ops; |
| 224 | |
| 225 | int mtk_common_clk_init(struct udevice *dev, |
| 226 | const struct mtk_clk_tree *tree); |
| 227 | int mtk_common_clk_gate_init(struct udevice *dev, |
| 228 | const struct mtk_clk_tree *tree, |
| 229 | const struct mtk_gate *gates); |
| 230 | |
| 231 | #endif /* __DRV_CLK_MTK_H */ |