Heiko Stübner | a245fec | 2014-07-03 01:58:39 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014 MundoReader S.L. |
| 3 | * Author: Heiko Stuebner <heiko@sntech.de> |
| 4 | * |
Xing Zheng | 9c4d6e55 | 2015-11-05 15:33:57 +0800 | [diff] [blame] | 5 | * Copyright (c) 2015 Rockchip Electronics Co. Ltd. |
| 6 | * Author: Xing Zheng <zhengxing@rock-chips.com> |
| 7 | * |
Heiko Stübner | a245fec | 2014-07-03 01:58:39 +0200 | [diff] [blame] | 8 | * based on |
| 9 | * |
| 10 | * samsung/clk.h |
| 11 | * Copyright (c) 2013 Samsung Electronics Co., Ltd. |
| 12 | * Copyright (c) 2013 Linaro Ltd. |
| 13 | * Author: Thomas Abraham <thomas.ab@samsung.com> |
| 14 | * |
| 15 | * This program is free software; you can redistribute it and/or modify |
| 16 | * it under the terms of the GNU General Public License as published by |
| 17 | * the Free Software Foundation; either version 2 of the License, or |
| 18 | * (at your option) any later version. |
| 19 | * |
| 20 | * This program is distributed in the hope that it will be useful, |
| 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 | * GNU General Public License for more details. |
| 24 | */ |
| 25 | |
| 26 | #ifndef CLK_ROCKCHIP_CLK_H |
| 27 | #define CLK_ROCKCHIP_CLK_H |
| 28 | |
| 29 | #include <linux/io.h> |
Xing Zheng | ef1d9fe | 2016-03-09 10:37:04 +0800 | [diff] [blame] | 30 | #include <linux/clk-provider.h> |
Stephen Boyd | f684ff8 | 2015-06-19 15:00:46 -0700 | [diff] [blame] | 31 | |
| 32 | struct clk; |
Heiko Stübner | a245fec | 2014-07-03 01:58:39 +0200 | [diff] [blame] | 33 | |
| 34 | #define HIWORD_UPDATE(val, mask, shift) \ |
| 35 | ((val) << (shift) | (mask) << ((shift) + 16)) |
| 36 | |
Jeffy Chen | 307a2e9 | 2015-12-11 09:30:50 +0800 | [diff] [blame] | 37 | /* register positions shared by RK2928, RK3036, RK3066, RK3188 and RK3228 */ |
Heiko Stuebner | 2d7884a | 2015-06-18 16:18:30 +0200 | [diff] [blame] | 38 | #define RK2928_PLL_CON(x) ((x) * 0x4) |
Heiko Stübner | a245fec | 2014-07-03 01:58:39 +0200 | [diff] [blame] | 39 | #define RK2928_MODE_CON 0x40 |
Heiko Stuebner | 2d7884a | 2015-06-18 16:18:30 +0200 | [diff] [blame] | 40 | #define RK2928_CLKSEL_CON(x) ((x) * 0x4 + 0x44) |
| 41 | #define RK2928_CLKGATE_CON(x) ((x) * 0x4 + 0xd0) |
Heiko Stübner | a245fec | 2014-07-03 01:58:39 +0200 | [diff] [blame] | 42 | #define RK2928_GLB_SRST_FST 0x100 |
| 43 | #define RK2928_GLB_SRST_SND 0x104 |
Heiko Stuebner | 2d7884a | 2015-06-18 16:18:30 +0200 | [diff] [blame] | 44 | #define RK2928_SOFTRST_CON(x) ((x) * 0x4 + 0x110) |
Heiko Stübner | a245fec | 2014-07-03 01:58:39 +0200 | [diff] [blame] | 45 | #define RK2928_MISC_CON 0x134 |
| 46 | |
Xing Zheng | 5190c08 | 2015-11-05 15:33:58 +0800 | [diff] [blame] | 47 | #define RK3036_SDMMC_CON0 0x144 |
| 48 | #define RK3036_SDMMC_CON1 0x148 |
| 49 | #define RK3036_SDIO_CON0 0x14c |
| 50 | #define RK3036_SDIO_CON1 0x150 |
| 51 | #define RK3036_EMMC_CON0 0x154 |
| 52 | #define RK3036_EMMC_CON1 0x158 |
| 53 | |
Jeffy Chen | 307a2e9 | 2015-12-11 09:30:50 +0800 | [diff] [blame] | 54 | #define RK3228_GLB_SRST_FST 0x1f0 |
| 55 | #define RK3228_GLB_SRST_SND 0x1f4 |
| 56 | #define RK3228_SDMMC_CON0 0x1c0 |
| 57 | #define RK3228_SDMMC_CON1 0x1c4 |
| 58 | #define RK3228_SDIO_CON0 0x1c8 |
| 59 | #define RK3228_SDIO_CON1 0x1cc |
| 60 | #define RK3228_EMMC_CON0 0x1d8 |
| 61 | #define RK3228_EMMC_CON1 0x1dc |
| 62 | |
Heiko Stübner | b9e4ba5 | 2014-07-03 02:02:37 +0200 | [diff] [blame] | 63 | #define RK3288_PLL_CON(x) RK2928_PLL_CON(x) |
| 64 | #define RK3288_MODE_CON 0x50 |
Heiko Stuebner | 2d7884a | 2015-06-18 16:18:30 +0200 | [diff] [blame] | 65 | #define RK3288_CLKSEL_CON(x) ((x) * 0x4 + 0x60) |
| 66 | #define RK3288_CLKGATE_CON(x) ((x) * 0x4 + 0x160) |
Heiko Stübner | b9e4ba5 | 2014-07-03 02:02:37 +0200 | [diff] [blame] | 67 | #define RK3288_GLB_SRST_FST 0x1b0 |
| 68 | #define RK3288_GLB_SRST_SND 0x1b4 |
Heiko Stuebner | 2d7884a | 2015-06-18 16:18:30 +0200 | [diff] [blame] | 69 | #define RK3288_SOFTRST_CON(x) ((x) * 0x4 + 0x1b8) |
Heiko Stübner | b9e4ba5 | 2014-07-03 02:02:37 +0200 | [diff] [blame] | 70 | #define RK3288_MISC_CON 0x1e8 |
Alexandru M Stan | 89bf26c | 2014-11-26 17:30:27 -0800 | [diff] [blame] | 71 | #define RK3288_SDMMC_CON0 0x200 |
| 72 | #define RK3288_SDMMC_CON1 0x204 |
| 73 | #define RK3288_SDIO0_CON0 0x208 |
| 74 | #define RK3288_SDIO0_CON1 0x20c |
| 75 | #define RK3288_SDIO1_CON0 0x210 |
| 76 | #define RK3288_SDIO1_CON1 0x214 |
| 77 | #define RK3288_EMMC_CON0 0x218 |
| 78 | #define RK3288_EMMC_CON1 0x21c |
Heiko Stübner | b9e4ba5 | 2014-07-03 02:02:37 +0200 | [diff] [blame] | 79 | |
Heiko Stuebner | 3536c97 | 2015-07-05 11:00:20 +0200 | [diff] [blame] | 80 | #define RK3368_PLL_CON(x) RK2928_PLL_CON(x) |
| 81 | #define RK3368_CLKSEL_CON(x) ((x) * 0x4 + 0x100) |
| 82 | #define RK3368_CLKGATE_CON(x) ((x) * 0x4 + 0x200) |
| 83 | #define RK3368_GLB_SRST_FST 0x280 |
| 84 | #define RK3368_GLB_SRST_SND 0x284 |
| 85 | #define RK3368_SOFTRST_CON(x) ((x) * 0x4 + 0x300) |
| 86 | #define RK3368_MISC_CON 0x380 |
| 87 | #define RK3368_SDMMC_CON0 0x400 |
| 88 | #define RK3368_SDMMC_CON1 0x404 |
| 89 | #define RK3368_SDIO0_CON0 0x408 |
| 90 | #define RK3368_SDIO0_CON1 0x40c |
| 91 | #define RK3368_SDIO1_CON0 0x410 |
| 92 | #define RK3368_SDIO1_CON1 0x414 |
| 93 | #define RK3368_EMMC_CON0 0x418 |
| 94 | #define RK3368_EMMC_CON1 0x41c |
| 95 | |
Heiko Stübner | 90c5902 | 2014-07-03 01:59:10 +0200 | [diff] [blame] | 96 | enum rockchip_pll_type { |
Xing Zheng | 9c4d6e55 | 2015-11-05 15:33:57 +0800 | [diff] [blame] | 97 | pll_rk3036, |
Heiko Stübner | 90c5902 | 2014-07-03 01:59:10 +0200 | [diff] [blame] | 98 | pll_rk3066, |
Xing Zheng | b40bacc | 2016-03-10 11:47:01 +0800 | [diff] [blame^] | 99 | pll_rk3399, |
Heiko Stübner | 90c5902 | 2014-07-03 01:59:10 +0200 | [diff] [blame] | 100 | }; |
| 101 | |
Xing Zheng | 9c4d6e55 | 2015-11-05 15:33:57 +0800 | [diff] [blame] | 102 | #define RK3036_PLL_RATE(_rate, _refdiv, _fbdiv, _postdiv1, \ |
| 103 | _postdiv2, _dsmpd, _frac) \ |
| 104 | { \ |
| 105 | .rate = _rate##U, \ |
| 106 | .fbdiv = _fbdiv, \ |
| 107 | .postdiv1 = _postdiv1, \ |
| 108 | .refdiv = _refdiv, \ |
| 109 | .postdiv2 = _postdiv2, \ |
| 110 | .dsmpd = _dsmpd, \ |
| 111 | .frac = _frac, \ |
| 112 | } |
| 113 | |
Heiko Stübner | 90c5902 | 2014-07-03 01:59:10 +0200 | [diff] [blame] | 114 | #define RK3066_PLL_RATE(_rate, _nr, _nf, _no) \ |
| 115 | { \ |
| 116 | .rate = _rate##U, \ |
| 117 | .nr = _nr, \ |
| 118 | .nf = _nf, \ |
| 119 | .no = _no, \ |
Douglas Anderson | 2bbfe00 | 2015-07-21 13:41:23 -0700 | [diff] [blame] | 120 | .nb = ((_nf) < 2) ? 1 : (_nf) >> 1, \ |
Heiko Stübner | 90c5902 | 2014-07-03 01:59:10 +0200 | [diff] [blame] | 121 | } |
| 122 | |
Douglas Anderson | 2bbfe00 | 2015-07-21 13:41:23 -0700 | [diff] [blame] | 123 | #define RK3066_PLL_RATE_NB(_rate, _nr, _nf, _no, _nb) \ |
Kever Yang | 49ed9ee | 2014-10-09 22:23:57 -0700 | [diff] [blame] | 124 | { \ |
| 125 | .rate = _rate##U, \ |
| 126 | .nr = _nr, \ |
| 127 | .nf = _nf, \ |
| 128 | .no = _no, \ |
Douglas Anderson | 2bbfe00 | 2015-07-21 13:41:23 -0700 | [diff] [blame] | 129 | .nb = _nb, \ |
Kever Yang | 49ed9ee | 2014-10-09 22:23:57 -0700 | [diff] [blame] | 130 | } |
| 131 | |
Xing Zheng | ef1d9fe | 2016-03-09 10:37:04 +0800 | [diff] [blame] | 132 | /** |
| 133 | * struct rockchip_clk_provider: information about clock provider |
| 134 | * @reg_base: virtual address for the register base. |
| 135 | * @clk_data: holds clock related data like clk* and number of clocks. |
| 136 | * @cru_node: device-node of the clock-provider |
| 137 | * @grf: regmap of the general-register-files syscon |
| 138 | * @lock: maintains exclusion between callbacks for a given clock-provider. |
| 139 | */ |
| 140 | struct rockchip_clk_provider { |
| 141 | void __iomem *reg_base; |
| 142 | struct clk_onecell_data clk_data; |
| 143 | struct device_node *cru_node; |
| 144 | struct regmap *grf; |
| 145 | spinlock_t lock; |
| 146 | }; |
| 147 | |
Heiko Stübner | 90c5902 | 2014-07-03 01:59:10 +0200 | [diff] [blame] | 148 | struct rockchip_pll_rate_table { |
| 149 | unsigned long rate; |
| 150 | unsigned int nr; |
| 151 | unsigned int nf; |
| 152 | unsigned int no; |
Douglas Anderson | 2bbfe00 | 2015-07-21 13:41:23 -0700 | [diff] [blame] | 153 | unsigned int nb; |
Xing Zheng | b40bacc | 2016-03-10 11:47:01 +0800 | [diff] [blame^] | 154 | /* for RK3036/RK3399 */ |
Xing Zheng | 9c4d6e55 | 2015-11-05 15:33:57 +0800 | [diff] [blame] | 155 | unsigned int fbdiv; |
| 156 | unsigned int postdiv1; |
| 157 | unsigned int refdiv; |
| 158 | unsigned int postdiv2; |
| 159 | unsigned int dsmpd; |
| 160 | unsigned int frac; |
Heiko Stübner | 90c5902 | 2014-07-03 01:59:10 +0200 | [diff] [blame] | 161 | }; |
| 162 | |
| 163 | /** |
| 164 | * struct rockchip_pll_clock: information about pll clock |
| 165 | * @id: platform specific id of the clock. |
| 166 | * @name: name of this pll clock. |
| 167 | * @parent_name: name of the parent clock. |
| 168 | * @flags: optional flags for basic clock. |
| 169 | * @con_offset: offset of the register for configuring the PLL. |
| 170 | * @mode_offset: offset of the register for configuring the PLL-mode. |
| 171 | * @mode_shift: offset inside the mode-register for the mode of this pll. |
| 172 | * @lock_shift: offset inside the lock register for the lock status. |
| 173 | * @type: Type of PLL to be registered. |
Heiko Stuebner | 4f8a7c5 | 2014-11-20 20:38:50 +0100 | [diff] [blame] | 174 | * @pll_flags: hardware-specific flags |
Heiko Stübner | 90c5902 | 2014-07-03 01:59:10 +0200 | [diff] [blame] | 175 | * @rate_table: Table of usable pll rates |
Heiko Stuebner | 0bb66d3 | 2014-11-20 20:38:52 +0100 | [diff] [blame] | 176 | * |
| 177 | * Flags: |
| 178 | * ROCKCHIP_PLL_SYNC_RATE - check rate parameters to match against the |
| 179 | * rate_table parameters and ajust them if necessary. |
Heiko Stübner | 90c5902 | 2014-07-03 01:59:10 +0200 | [diff] [blame] | 180 | */ |
| 181 | struct rockchip_pll_clock { |
| 182 | unsigned int id; |
| 183 | const char *name; |
Uwe Kleine-König | 4a1caed | 2015-05-28 10:45:51 +0200 | [diff] [blame] | 184 | const char *const *parent_names; |
Heiko Stübner | 90c5902 | 2014-07-03 01:59:10 +0200 | [diff] [blame] | 185 | u8 num_parents; |
| 186 | unsigned long flags; |
| 187 | int con_offset; |
| 188 | int mode_offset; |
| 189 | int mode_shift; |
| 190 | int lock_shift; |
| 191 | enum rockchip_pll_type type; |
Heiko Stuebner | 4f8a7c5 | 2014-11-20 20:38:50 +0100 | [diff] [blame] | 192 | u8 pll_flags; |
Heiko Stübner | 90c5902 | 2014-07-03 01:59:10 +0200 | [diff] [blame] | 193 | struct rockchip_pll_rate_table *rate_table; |
| 194 | }; |
| 195 | |
Heiko Stuebner | 0bb66d3 | 2014-11-20 20:38:52 +0100 | [diff] [blame] | 196 | #define ROCKCHIP_PLL_SYNC_RATE BIT(0) |
| 197 | |
Heiko Stübner | 90c5902 | 2014-07-03 01:59:10 +0200 | [diff] [blame] | 198 | #define PLL(_type, _id, _name, _pnames, _flags, _con, _mode, _mshift, \ |
Heiko Stuebner | 4f8a7c5 | 2014-11-20 20:38:50 +0100 | [diff] [blame] | 199 | _lshift, _pflags, _rtable) \ |
Heiko Stübner | 90c5902 | 2014-07-03 01:59:10 +0200 | [diff] [blame] | 200 | { \ |
| 201 | .id = _id, \ |
| 202 | .type = _type, \ |
| 203 | .name = _name, \ |
| 204 | .parent_names = _pnames, \ |
| 205 | .num_parents = ARRAY_SIZE(_pnames), \ |
| 206 | .flags = CLK_GET_RATE_NOCACHE | _flags, \ |
| 207 | .con_offset = _con, \ |
| 208 | .mode_offset = _mode, \ |
| 209 | .mode_shift = _mshift, \ |
| 210 | .lock_shift = _lshift, \ |
Heiko Stuebner | 4f8a7c5 | 2014-11-20 20:38:50 +0100 | [diff] [blame] | 211 | .pll_flags = _pflags, \ |
Heiko Stübner | 90c5902 | 2014-07-03 01:59:10 +0200 | [diff] [blame] | 212 | .rate_table = _rtable, \ |
| 213 | } |
| 214 | |
Xing Zheng | ef1d9fe | 2016-03-09 10:37:04 +0800 | [diff] [blame] | 215 | struct clk *rockchip_clk_register_pll(struct rockchip_clk_provider *ctx, |
| 216 | enum rockchip_pll_type pll_type, |
Uwe Kleine-König | 4a1caed | 2015-05-28 10:45:51 +0200 | [diff] [blame] | 217 | const char *name, const char *const *parent_names, |
Xing Zheng | ef1d9fe | 2016-03-09 10:37:04 +0800 | [diff] [blame] | 218 | u8 num_parents, int con_offset, int grf_lock_offset, |
| 219 | int lock_shift, int mode_offset, int mode_shift, |
| 220 | struct rockchip_pll_rate_table *rate_table, |
| 221 | u8 clk_pll_flags); |
Heiko Stübner | 90c5902 | 2014-07-03 01:59:10 +0200 | [diff] [blame] | 222 | |
Heiko Stuebner | f6fba5f | 2014-09-04 22:10:43 +0200 | [diff] [blame] | 223 | struct rockchip_cpuclk_clksel { |
| 224 | int reg; |
| 225 | u32 val; |
| 226 | }; |
| 227 | |
| 228 | #define ROCKCHIP_CPUCLK_NUM_DIVIDERS 2 |
| 229 | struct rockchip_cpuclk_rate_table { |
| 230 | unsigned long prate; |
| 231 | struct rockchip_cpuclk_clksel divs[ROCKCHIP_CPUCLK_NUM_DIVIDERS]; |
| 232 | }; |
| 233 | |
| 234 | /** |
| 235 | * struct rockchip_cpuclk_reg_data: describes register offsets and masks of the cpuclock |
| 236 | * @core_reg: register offset of the core settings register |
| 237 | * @div_core_shift: core divider offset used to divide the pll value |
| 238 | * @div_core_mask: core divider mask |
Xing Zheng | 268aeba | 2016-03-09 10:37:03 +0800 | [diff] [blame] | 239 | * @mux_core_alt: mux value to select alternate parent |
| 240 | * @mux_core_main: mux value to select main parent of core |
Heiko Stuebner | f6fba5f | 2014-09-04 22:10:43 +0200 | [diff] [blame] | 241 | * @mux_core_shift: offset of the core multiplexer |
Xing Zheng | 268aeba | 2016-03-09 10:37:03 +0800 | [diff] [blame] | 242 | * @mux_core_mask: core multiplexer mask |
Heiko Stuebner | f6fba5f | 2014-09-04 22:10:43 +0200 | [diff] [blame] | 243 | */ |
| 244 | struct rockchip_cpuclk_reg_data { |
| 245 | int core_reg; |
| 246 | u8 div_core_shift; |
| 247 | u32 div_core_mask; |
| 248 | int mux_core_reg; |
Xing Zheng | 268aeba | 2016-03-09 10:37:03 +0800 | [diff] [blame] | 249 | u8 mux_core_alt; |
| 250 | u8 mux_core_main; |
Heiko Stuebner | f6fba5f | 2014-09-04 22:10:43 +0200 | [diff] [blame] | 251 | u8 mux_core_shift; |
Xing Zheng | 268aeba | 2016-03-09 10:37:03 +0800 | [diff] [blame] | 252 | u32 mux_core_mask; |
Heiko Stuebner | f6fba5f | 2014-09-04 22:10:43 +0200 | [diff] [blame] | 253 | }; |
| 254 | |
| 255 | struct clk *rockchip_clk_register_cpuclk(const char *name, |
Uwe Kleine-König | 4a1caed | 2015-05-28 10:45:51 +0200 | [diff] [blame] | 256 | const char *const *parent_names, u8 num_parents, |
Heiko Stuebner | f6fba5f | 2014-09-04 22:10:43 +0200 | [diff] [blame] | 257 | const struct rockchip_cpuclk_reg_data *reg_data, |
| 258 | const struct rockchip_cpuclk_rate_table *rates, |
| 259 | int nrates, void __iomem *reg_base, spinlock_t *lock); |
| 260 | |
Alexandru M Stan | 89bf26c | 2014-11-26 17:30:27 -0800 | [diff] [blame] | 261 | struct clk *rockchip_clk_register_mmc(const char *name, |
Uwe Kleine-König | 4a1caed | 2015-05-28 10:45:51 +0200 | [diff] [blame] | 262 | const char *const *parent_names, u8 num_parents, |
Alexandru M Stan | 89bf26c | 2014-11-26 17:30:27 -0800 | [diff] [blame] | 263 | void __iomem *reg, int shift); |
| 264 | |
Heiko Stuebner | 8a76f44 | 2015-07-05 11:00:14 +0200 | [diff] [blame] | 265 | #define ROCKCHIP_INVERTER_HIWORD_MASK BIT(0) |
| 266 | |
| 267 | struct clk *rockchip_clk_register_inverter(const char *name, |
| 268 | const char *const *parent_names, u8 num_parents, |
| 269 | void __iomem *reg, int shift, int flags, |
| 270 | spinlock_t *lock); |
| 271 | |
Uwe Kleine-König | 4a1caed | 2015-05-28 10:45:51 +0200 | [diff] [blame] | 272 | #define PNAME(x) static const char *const x[] __initconst |
Heiko Stübner | a245fec | 2014-07-03 01:58:39 +0200 | [diff] [blame] | 273 | |
| 274 | enum rockchip_clk_branch_type { |
| 275 | branch_composite, |
| 276 | branch_mux, |
| 277 | branch_divider, |
| 278 | branch_fraction_divider, |
| 279 | branch_gate, |
Alexandru M Stan | 89bf26c | 2014-11-26 17:30:27 -0800 | [diff] [blame] | 280 | branch_mmc, |
Heiko Stuebner | 8a76f44 | 2015-07-05 11:00:14 +0200 | [diff] [blame] | 281 | branch_inverter, |
Heiko Stuebner | 29a30c2 | 2015-06-20 13:08:57 +0200 | [diff] [blame] | 282 | branch_factor, |
Heiko Stübner | a245fec | 2014-07-03 01:58:39 +0200 | [diff] [blame] | 283 | }; |
| 284 | |
| 285 | struct rockchip_clk_branch { |
| 286 | unsigned int id; |
| 287 | enum rockchip_clk_branch_type branch_type; |
| 288 | const char *name; |
Uwe Kleine-König | 4a1caed | 2015-05-28 10:45:51 +0200 | [diff] [blame] | 289 | const char *const *parent_names; |
Heiko Stübner | a245fec | 2014-07-03 01:58:39 +0200 | [diff] [blame] | 290 | u8 num_parents; |
| 291 | unsigned long flags; |
| 292 | int muxdiv_offset; |
| 293 | u8 mux_shift; |
| 294 | u8 mux_width; |
| 295 | u8 mux_flags; |
| 296 | u8 div_shift; |
| 297 | u8 div_width; |
| 298 | u8 div_flags; |
| 299 | struct clk_div_table *div_table; |
| 300 | int gate_offset; |
| 301 | u8 gate_shift; |
| 302 | u8 gate_flags; |
Heiko Stuebner | 8ca1ca8 | 2015-12-22 22:27:59 +0100 | [diff] [blame] | 303 | struct rockchip_clk_branch *child; |
Heiko Stübner | a245fec | 2014-07-03 01:58:39 +0200 | [diff] [blame] | 304 | }; |
| 305 | |
| 306 | #define COMPOSITE(_id, cname, pnames, f, mo, ms, mw, mf, ds, dw,\ |
| 307 | df, go, gs, gf) \ |
| 308 | { \ |
| 309 | .id = _id, \ |
| 310 | .branch_type = branch_composite, \ |
| 311 | .name = cname, \ |
| 312 | .parent_names = pnames, \ |
| 313 | .num_parents = ARRAY_SIZE(pnames), \ |
| 314 | .flags = f, \ |
| 315 | .muxdiv_offset = mo, \ |
| 316 | .mux_shift = ms, \ |
| 317 | .mux_width = mw, \ |
| 318 | .mux_flags = mf, \ |
| 319 | .div_shift = ds, \ |
| 320 | .div_width = dw, \ |
| 321 | .div_flags = df, \ |
| 322 | .gate_offset = go, \ |
| 323 | .gate_shift = gs, \ |
| 324 | .gate_flags = gf, \ |
| 325 | } |
| 326 | |
| 327 | #define COMPOSITE_NOMUX(_id, cname, pname, f, mo, ds, dw, df, \ |
| 328 | go, gs, gf) \ |
| 329 | { \ |
| 330 | .id = _id, \ |
| 331 | .branch_type = branch_composite, \ |
| 332 | .name = cname, \ |
| 333 | .parent_names = (const char *[]){ pname }, \ |
| 334 | .num_parents = 1, \ |
| 335 | .flags = f, \ |
| 336 | .muxdiv_offset = mo, \ |
| 337 | .div_shift = ds, \ |
| 338 | .div_width = dw, \ |
| 339 | .div_flags = df, \ |
| 340 | .gate_offset = go, \ |
| 341 | .gate_shift = gs, \ |
| 342 | .gate_flags = gf, \ |
| 343 | } |
| 344 | |
| 345 | #define COMPOSITE_NOMUX_DIVTBL(_id, cname, pname, f, mo, ds, dw,\ |
| 346 | df, dt, go, gs, gf) \ |
| 347 | { \ |
| 348 | .id = _id, \ |
| 349 | .branch_type = branch_composite, \ |
| 350 | .name = cname, \ |
| 351 | .parent_names = (const char *[]){ pname }, \ |
| 352 | .num_parents = 1, \ |
| 353 | .flags = f, \ |
| 354 | .muxdiv_offset = mo, \ |
| 355 | .div_shift = ds, \ |
| 356 | .div_width = dw, \ |
| 357 | .div_flags = df, \ |
| 358 | .div_table = dt, \ |
| 359 | .gate_offset = go, \ |
| 360 | .gate_shift = gs, \ |
| 361 | .gate_flags = gf, \ |
| 362 | } |
| 363 | |
| 364 | #define COMPOSITE_NODIV(_id, cname, pnames, f, mo, ms, mw, mf, \ |
| 365 | go, gs, gf) \ |
| 366 | { \ |
| 367 | .id = _id, \ |
| 368 | .branch_type = branch_composite, \ |
| 369 | .name = cname, \ |
| 370 | .parent_names = pnames, \ |
| 371 | .num_parents = ARRAY_SIZE(pnames), \ |
| 372 | .flags = f, \ |
| 373 | .muxdiv_offset = mo, \ |
| 374 | .mux_shift = ms, \ |
| 375 | .mux_width = mw, \ |
| 376 | .mux_flags = mf, \ |
| 377 | .gate_offset = go, \ |
| 378 | .gate_shift = gs, \ |
| 379 | .gate_flags = gf, \ |
| 380 | } |
| 381 | |
| 382 | #define COMPOSITE_NOGATE(_id, cname, pnames, f, mo, ms, mw, mf, \ |
| 383 | ds, dw, df) \ |
| 384 | { \ |
| 385 | .id = _id, \ |
| 386 | .branch_type = branch_composite, \ |
| 387 | .name = cname, \ |
| 388 | .parent_names = pnames, \ |
| 389 | .num_parents = ARRAY_SIZE(pnames), \ |
| 390 | .flags = f, \ |
| 391 | .muxdiv_offset = mo, \ |
| 392 | .mux_shift = ms, \ |
| 393 | .mux_width = mw, \ |
| 394 | .mux_flags = mf, \ |
| 395 | .div_shift = ds, \ |
| 396 | .div_width = dw, \ |
| 397 | .div_flags = df, \ |
| 398 | .gate_offset = -1, \ |
| 399 | } |
| 400 | |
Heiko Stuebner | 6f08507 | 2015-06-18 16:18:31 +0200 | [diff] [blame] | 401 | #define COMPOSITE_NOGATE_DIVTBL(_id, cname, pnames, f, mo, ms, \ |
| 402 | mw, mf, ds, dw, df, dt) \ |
| 403 | { \ |
| 404 | .id = _id, \ |
| 405 | .branch_type = branch_composite, \ |
| 406 | .name = cname, \ |
| 407 | .parent_names = pnames, \ |
| 408 | .num_parents = ARRAY_SIZE(pnames), \ |
| 409 | .flags = f, \ |
| 410 | .muxdiv_offset = mo, \ |
| 411 | .mux_shift = ms, \ |
| 412 | .mux_width = mw, \ |
| 413 | .mux_flags = mf, \ |
| 414 | .div_shift = ds, \ |
| 415 | .div_width = dw, \ |
| 416 | .div_flags = df, \ |
| 417 | .div_table = dt, \ |
| 418 | .gate_offset = -1, \ |
| 419 | } |
| 420 | |
Heiko Stübner | a245fec | 2014-07-03 01:58:39 +0200 | [diff] [blame] | 421 | #define COMPOSITE_FRAC(_id, cname, pname, f, mo, df, go, gs, gf)\ |
| 422 | { \ |
| 423 | .id = _id, \ |
| 424 | .branch_type = branch_fraction_divider, \ |
| 425 | .name = cname, \ |
| 426 | .parent_names = (const char *[]){ pname }, \ |
| 427 | .num_parents = 1, \ |
| 428 | .flags = f, \ |
| 429 | .muxdiv_offset = mo, \ |
| 430 | .div_shift = 16, \ |
| 431 | .div_width = 16, \ |
| 432 | .div_flags = df, \ |
| 433 | .gate_offset = go, \ |
| 434 | .gate_shift = gs, \ |
| 435 | .gate_flags = gf, \ |
| 436 | } |
| 437 | |
Heiko Stuebner | 8ca1ca8 | 2015-12-22 22:27:59 +0100 | [diff] [blame] | 438 | #define COMPOSITE_FRACMUX(_id, cname, pname, f, mo, df, go, gs, gf, ch) \ |
| 439 | { \ |
| 440 | .id = _id, \ |
| 441 | .branch_type = branch_fraction_divider, \ |
| 442 | .name = cname, \ |
| 443 | .parent_names = (const char *[]){ pname }, \ |
| 444 | .num_parents = 1, \ |
| 445 | .flags = f, \ |
| 446 | .muxdiv_offset = mo, \ |
| 447 | .div_shift = 16, \ |
| 448 | .div_width = 16, \ |
| 449 | .div_flags = df, \ |
| 450 | .gate_offset = go, \ |
| 451 | .gate_shift = gs, \ |
| 452 | .gate_flags = gf, \ |
Heiko Stübner | 5b73840 | 2015-12-26 14:07:15 +0100 | [diff] [blame] | 453 | .child = ch, \ |
Heiko Stuebner | 8ca1ca8 | 2015-12-22 22:27:59 +0100 | [diff] [blame] | 454 | } |
| 455 | |
Xing Zheng | 9387bfd | 2016-03-09 10:43:31 +0800 | [diff] [blame] | 456 | #define COMPOSITE_FRACMUX_NOGATE(_id, cname, pname, f, mo, df, ch) \ |
| 457 | { \ |
| 458 | .id = _id, \ |
| 459 | .branch_type = branch_fraction_divider, \ |
| 460 | .name = cname, \ |
| 461 | .parent_names = (const char *[]){ pname }, \ |
| 462 | .num_parents = 1, \ |
| 463 | .flags = f, \ |
| 464 | .muxdiv_offset = mo, \ |
| 465 | .div_shift = 16, \ |
| 466 | .div_width = 16, \ |
| 467 | .div_flags = df, \ |
| 468 | .gate_offset = -1, \ |
| 469 | .child = ch, \ |
| 470 | } |
| 471 | |
Heiko Stübner | a245fec | 2014-07-03 01:58:39 +0200 | [diff] [blame] | 472 | #define MUX(_id, cname, pnames, f, o, s, w, mf) \ |
| 473 | { \ |
| 474 | .id = _id, \ |
| 475 | .branch_type = branch_mux, \ |
| 476 | .name = cname, \ |
| 477 | .parent_names = pnames, \ |
| 478 | .num_parents = ARRAY_SIZE(pnames), \ |
| 479 | .flags = f, \ |
| 480 | .muxdiv_offset = o, \ |
| 481 | .mux_shift = s, \ |
| 482 | .mux_width = w, \ |
| 483 | .mux_flags = mf, \ |
| 484 | .gate_offset = -1, \ |
| 485 | } |
| 486 | |
| 487 | #define DIV(_id, cname, pname, f, o, s, w, df) \ |
| 488 | { \ |
| 489 | .id = _id, \ |
| 490 | .branch_type = branch_divider, \ |
| 491 | .name = cname, \ |
| 492 | .parent_names = (const char *[]){ pname }, \ |
| 493 | .num_parents = 1, \ |
| 494 | .flags = f, \ |
| 495 | .muxdiv_offset = o, \ |
| 496 | .div_shift = s, \ |
| 497 | .div_width = w, \ |
| 498 | .div_flags = df, \ |
| 499 | .gate_offset = -1, \ |
| 500 | } |
| 501 | |
| 502 | #define DIVTBL(_id, cname, pname, f, o, s, w, df, dt) \ |
| 503 | { \ |
| 504 | .id = _id, \ |
| 505 | .branch_type = branch_divider, \ |
| 506 | .name = cname, \ |
| 507 | .parent_names = (const char *[]){ pname }, \ |
| 508 | .num_parents = 1, \ |
| 509 | .flags = f, \ |
| 510 | .muxdiv_offset = o, \ |
| 511 | .div_shift = s, \ |
| 512 | .div_width = w, \ |
| 513 | .div_flags = df, \ |
| 514 | .div_table = dt, \ |
| 515 | } |
| 516 | |
| 517 | #define GATE(_id, cname, pname, f, o, b, gf) \ |
| 518 | { \ |
| 519 | .id = _id, \ |
| 520 | .branch_type = branch_gate, \ |
| 521 | .name = cname, \ |
| 522 | .parent_names = (const char *[]){ pname }, \ |
| 523 | .num_parents = 1, \ |
| 524 | .flags = f, \ |
| 525 | .gate_offset = o, \ |
| 526 | .gate_shift = b, \ |
| 527 | .gate_flags = gf, \ |
| 528 | } |
| 529 | |
Alexandru M Stan | 89bf26c | 2014-11-26 17:30:27 -0800 | [diff] [blame] | 530 | #define MMC(_id, cname, pname, offset, shift) \ |
| 531 | { \ |
| 532 | .id = _id, \ |
| 533 | .branch_type = branch_mmc, \ |
| 534 | .name = cname, \ |
| 535 | .parent_names = (const char *[]){ pname }, \ |
| 536 | .num_parents = 1, \ |
| 537 | .muxdiv_offset = offset, \ |
| 538 | .div_shift = shift, \ |
| 539 | } |
Heiko Stübner | a245fec | 2014-07-03 01:58:39 +0200 | [diff] [blame] | 540 | |
Heiko Stuebner | 8a76f44 | 2015-07-05 11:00:14 +0200 | [diff] [blame] | 541 | #define INVERTER(_id, cname, pname, io, is, if) \ |
| 542 | { \ |
| 543 | .id = _id, \ |
| 544 | .branch_type = branch_inverter, \ |
| 545 | .name = cname, \ |
| 546 | .parent_names = (const char *[]){ pname }, \ |
| 547 | .num_parents = 1, \ |
| 548 | .muxdiv_offset = io, \ |
| 549 | .div_shift = is, \ |
| 550 | .div_flags = if, \ |
| 551 | } |
| 552 | |
Heiko Stuebner | 29a30c2 | 2015-06-20 13:08:57 +0200 | [diff] [blame] | 553 | #define FACTOR(_id, cname, pname, f, fm, fd) \ |
| 554 | { \ |
| 555 | .id = _id, \ |
| 556 | .branch_type = branch_factor, \ |
| 557 | .name = cname, \ |
| 558 | .parent_names = (const char *[]){ pname }, \ |
| 559 | .num_parents = 1, \ |
| 560 | .flags = f, \ |
| 561 | .div_shift = fm, \ |
| 562 | .div_width = fd, \ |
| 563 | } |
| 564 | |
| 565 | #define FACTOR_GATE(_id, cname, pname, f, fm, fd, go, gb, gf) \ |
| 566 | { \ |
| 567 | .id = _id, \ |
| 568 | .branch_type = branch_factor, \ |
| 569 | .name = cname, \ |
| 570 | .parent_names = (const char *[]){ pname }, \ |
| 571 | .num_parents = 1, \ |
| 572 | .flags = f, \ |
| 573 | .div_shift = fm, \ |
| 574 | .div_width = fd, \ |
| 575 | .gate_offset = go, \ |
| 576 | .gate_shift = gb, \ |
| 577 | .gate_flags = gf, \ |
| 578 | } |
| 579 | |
Xing Zheng | ef1d9fe | 2016-03-09 10:37:04 +0800 | [diff] [blame] | 580 | struct rockchip_clk_provider *rockchip_clk_init(struct device_node *np, |
| 581 | void __iomem *base, unsigned long nr_clks); |
| 582 | void rockchip_clk_of_add_provider(struct device_node *np, |
| 583 | struct rockchip_clk_provider *ctx); |
| 584 | struct regmap *rockchip_clk_get_grf(struct rockchip_clk_provider *ctx); |
| 585 | void rockchip_clk_add_lookup(struct rockchip_clk_provider *ctx, |
| 586 | struct clk *clk, unsigned int id); |
| 587 | void rockchip_clk_register_branches(struct rockchip_clk_provider *ctx, |
| 588 | struct rockchip_clk_branch *list, |
Heiko Stübner | a245fec | 2014-07-03 01:58:39 +0200 | [diff] [blame] | 589 | unsigned int nr_clk); |
Xing Zheng | ef1d9fe | 2016-03-09 10:37:04 +0800 | [diff] [blame] | 590 | void rockchip_clk_register_plls(struct rockchip_clk_provider *ctx, |
| 591 | struct rockchip_pll_clock *pll_list, |
Heiko Stübner | 90c5902 | 2014-07-03 01:59:10 +0200 | [diff] [blame] | 592 | unsigned int nr_pll, int grf_lock_offset); |
Xing Zheng | ef1d9fe | 2016-03-09 10:37:04 +0800 | [diff] [blame] | 593 | void rockchip_clk_register_armclk(struct rockchip_clk_provider *ctx, |
| 594 | unsigned int lookup_id, const char *name, |
Uwe Kleine-König | 4a1caed | 2015-05-28 10:45:51 +0200 | [diff] [blame] | 595 | const char *const *parent_names, u8 num_parents, |
Heiko Stuebner | f6fba5f | 2014-09-04 22:10:43 +0200 | [diff] [blame] | 596 | const struct rockchip_cpuclk_reg_data *reg_data, |
| 597 | const struct rockchip_cpuclk_rate_table *rates, |
| 598 | int nrates); |
Uwe Kleine-König | 692d832 | 2015-02-18 10:59:45 +0100 | [diff] [blame] | 599 | void rockchip_clk_protect_critical(const char *const clocks[], int nclocks); |
Xing Zheng | ef1d9fe | 2016-03-09 10:37:04 +0800 | [diff] [blame] | 600 | void rockchip_register_restart_notifier(struct rockchip_clk_provider *ctx, |
| 601 | unsigned int reg, void (*cb)(void)); |
Heiko Stübner | a245fec | 2014-07-03 01:58:39 +0200 | [diff] [blame] | 602 | |
Heiko Stübner | 85fa0c7 | 2014-07-03 01:59:39 +0200 | [diff] [blame] | 603 | #define ROCKCHIP_SOFTRST_HIWORD_MASK BIT(0) |
| 604 | |
| 605 | #ifdef CONFIG_RESET_CONTROLLER |
| 606 | void rockchip_register_softrst(struct device_node *np, |
| 607 | unsigned int num_regs, |
| 608 | void __iomem *base, u8 flags); |
| 609 | #else |
| 610 | static inline void rockchip_register_softrst(struct device_node *np, |
| 611 | unsigned int num_regs, |
| 612 | void __iomem *base, u8 flags) |
| 613 | { |
| 614 | } |
| 615 | #endif |
| 616 | |
Heiko Stübner | a245fec | 2014-07-03 01:58:39 +0200 | [diff] [blame] | 617 | #endif |