Thomas Gleixner | c942fdd | 2019-05-27 08:55:06 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Paul Burton | ff1930c | 2015-05-24 16:11:36 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Ingenic JZ4740 SoC CGU driver |
| 4 | * |
| 5 | * Copyright (c) 2015 Imagination Technologies |
Paul Burton | fb615d6 | 2017-10-25 17:04:33 -0700 | [diff] [blame] | 6 | * Author: Paul Burton <paul.burton@mips.com> |
Paul Burton | ff1930c | 2015-05-24 16:11:36 +0100 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <linux/clk-provider.h> |
| 10 | #include <linux/delay.h> |
Stephen Boyd | 62e59c4 | 2019-04-18 15:20:22 -0700 | [diff] [blame] | 11 | #include <linux/io.h> |
Paul Burton | ff1930c | 2015-05-24 16:11:36 +0100 | [diff] [blame] | 12 | #include <linux/of.h> |
周琰杰 (Zhou Yanjie) | 9d9cc58 | 2020-05-28 11:15:44 +0800 | [diff] [blame] | 13 | |
Paul Cercueil | c4a11bf | 2021-10-16 14:33:21 +0100 | [diff] [blame] | 14 | #include <dt-bindings/clock/ingenic,jz4740-cgu.h> |
周琰杰 (Zhou Yanjie) | 9d9cc58 | 2020-05-28 11:15:44 +0800 | [diff] [blame] | 15 | |
Paul Burton | ff1930c | 2015-05-24 16:11:36 +0100 | [diff] [blame] | 16 | #include "cgu.h" |
Paul Cercueil | 2ee93e3 | 2019-06-11 20:07:54 +0200 | [diff] [blame] | 17 | #include "pm.h" |
Paul Burton | ff1930c | 2015-05-24 16:11:36 +0100 | [diff] [blame] | 18 | |
| 19 | /* CGU register offsets */ |
| 20 | #define CGU_REG_CPCCR 0x00 |
Paul Burton | 41dd641 | 2015-05-24 16:11:37 +0100 | [diff] [blame] | 21 | #define CGU_REG_LCR 0x04 |
Paul Burton | ff1930c | 2015-05-24 16:11:36 +0100 | [diff] [blame] | 22 | #define CGU_REG_CPPCR 0x10 |
Paul Burton | ed286ca | 2015-05-24 16:11:38 +0100 | [diff] [blame] | 23 | #define CGU_REG_CLKGR 0x20 |
Paul Burton | ff1930c | 2015-05-24 16:11:36 +0100 | [diff] [blame] | 24 | #define CGU_REG_SCR 0x24 |
| 25 | #define CGU_REG_I2SCDR 0x60 |
| 26 | #define CGU_REG_LPCDR 0x64 |
| 27 | #define CGU_REG_MSCCDR 0x68 |
| 28 | #define CGU_REG_UHCCDR 0x6c |
| 29 | #define CGU_REG_SSICDR 0x74 |
| 30 | |
| 31 | /* bits within a PLL control register */ |
| 32 | #define PLLCTL_M_SHIFT 23 |
| 33 | #define PLLCTL_M_MASK (0x1ff << PLLCTL_M_SHIFT) |
| 34 | #define PLLCTL_N_SHIFT 18 |
| 35 | #define PLLCTL_N_MASK (0x1f << PLLCTL_N_SHIFT) |
| 36 | #define PLLCTL_OD_SHIFT 16 |
| 37 | #define PLLCTL_OD_MASK (0x3 << PLLCTL_OD_SHIFT) |
| 38 | #define PLLCTL_STABLE (1 << 10) |
| 39 | #define PLLCTL_BYPASS (1 << 9) |
| 40 | #define PLLCTL_ENABLE (1 << 8) |
| 41 | |
Paul Burton | 41dd641 | 2015-05-24 16:11:37 +0100 | [diff] [blame] | 42 | /* bits within the LCR register */ |
| 43 | #define LCR_SLEEP (1 << 0) |
| 44 | |
Paul Burton | ed286ca | 2015-05-24 16:11:38 +0100 | [diff] [blame] | 45 | /* bits within the CLKGR register */ |
| 46 | #define CLKGR_UDC (1 << 11) |
| 47 | |
Paul Burton | ff1930c | 2015-05-24 16:11:36 +0100 | [diff] [blame] | 48 | static struct ingenic_cgu *cgu; |
| 49 | |
| 50 | static const s8 pll_od_encoding[4] = { |
| 51 | 0x0, 0x1, -1, 0x3, |
| 52 | }; |
| 53 | |
Paul Cercueil | 2a1a703 | 2019-05-02 23:24:59 +0200 | [diff] [blame] | 54 | static const u8 jz4740_cgu_cpccr_div_table[] = { |
| 55 | 1, 2, 3, 4, 6, 8, 12, 16, 24, 32, |
| 56 | }; |
| 57 | |
Paul Cercueil | 568b9de | 2019-07-01 13:36:06 +0200 | [diff] [blame] | 58 | static const u8 jz4740_cgu_pll_half_div_table[] = { |
| 59 | 2, 1, |
| 60 | }; |
| 61 | |
Paul Burton | ff1930c | 2015-05-24 16:11:36 +0100 | [diff] [blame] | 62 | static const struct ingenic_cgu_clk_info jz4740_cgu_clocks[] = { |
| 63 | |
| 64 | /* External clocks */ |
| 65 | |
| 66 | [JZ4740_CLK_EXT] = { "ext", CGU_CLK_EXT }, |
| 67 | [JZ4740_CLK_RTC] = { "rtc", CGU_CLK_EXT }, |
| 68 | |
| 69 | [JZ4740_CLK_PLL] = { |
| 70 | "pll", CGU_CLK_PLL, |
| 71 | .parents = { JZ4740_CLK_EXT, -1, -1, -1 }, |
| 72 | .pll = { |
| 73 | .reg = CGU_REG_CPPCR, |
周琰杰 (Zhou Yanjie) | 9d9cc58 | 2020-05-28 11:15:44 +0800 | [diff] [blame] | 74 | .rate_multiplier = 1, |
Paul Burton | ff1930c | 2015-05-24 16:11:36 +0100 | [diff] [blame] | 75 | .m_shift = 23, |
| 76 | .m_bits = 9, |
| 77 | .m_offset = 2, |
| 78 | .n_shift = 18, |
| 79 | .n_bits = 5, |
| 80 | .n_offset = 2, |
| 81 | .od_shift = 16, |
| 82 | .od_bits = 2, |
| 83 | .od_max = 4, |
| 84 | .od_encoding = pll_od_encoding, |
| 85 | .stable_bit = 10, |
周琰杰 (Zhou Yanjie) | 9d9cc58 | 2020-05-28 11:15:44 +0800 | [diff] [blame] | 86 | .bypass_reg = CGU_REG_CPPCR, |
Paul Burton | ff1930c | 2015-05-24 16:11:36 +0100 | [diff] [blame] | 87 | .bypass_bit = 9, |
| 88 | .enable_bit = 8, |
| 89 | }, |
| 90 | }, |
| 91 | |
| 92 | /* Muxes & dividers */ |
| 93 | |
| 94 | [JZ4740_CLK_PLL_HALF] = { |
| 95 | "pll half", CGU_CLK_DIV, |
| 96 | .parents = { JZ4740_CLK_PLL, -1, -1, -1 }, |
Paul Cercueil | 568b9de | 2019-07-01 13:36:06 +0200 | [diff] [blame] | 97 | .div = { |
Paul Cercueil | 249592b | 2021-05-30 17:49:19 +0100 | [diff] [blame] | 98 | CGU_REG_CPCCR, 21, 1, 1, -1, -1, -1, 0, |
Paul Cercueil | 568b9de | 2019-07-01 13:36:06 +0200 | [diff] [blame] | 99 | jz4740_cgu_pll_half_div_table, |
| 100 | }, |
Paul Burton | ff1930c | 2015-05-24 16:11:36 +0100 | [diff] [blame] | 101 | }, |
| 102 | |
| 103 | [JZ4740_CLK_CCLK] = { |
| 104 | "cclk", CGU_CLK_DIV, |
| 105 | .parents = { JZ4740_CLK_PLL, -1, -1, -1 }, |
Paul Cercueil | 2a1a703 | 2019-05-02 23:24:59 +0200 | [diff] [blame] | 106 | .div = { |
Paul Cercueil | 249592b | 2021-05-30 17:49:19 +0100 | [diff] [blame] | 107 | CGU_REG_CPCCR, 0, 1, 4, 22, -1, -1, 0, |
Paul Cercueil | 2a1a703 | 2019-05-02 23:24:59 +0200 | [diff] [blame] | 108 | jz4740_cgu_cpccr_div_table, |
| 109 | }, |
Paul Burton | ff1930c | 2015-05-24 16:11:36 +0100 | [diff] [blame] | 110 | }, |
| 111 | |
| 112 | [JZ4740_CLK_HCLK] = { |
| 113 | "hclk", CGU_CLK_DIV, |
| 114 | .parents = { JZ4740_CLK_PLL, -1, -1, -1 }, |
Paul Cercueil | 2a1a703 | 2019-05-02 23:24:59 +0200 | [diff] [blame] | 115 | .div = { |
Paul Cercueil | 249592b | 2021-05-30 17:49:19 +0100 | [diff] [blame] | 116 | CGU_REG_CPCCR, 4, 1, 4, 22, -1, -1, 0, |
Paul Cercueil | 2a1a703 | 2019-05-02 23:24:59 +0200 | [diff] [blame] | 117 | jz4740_cgu_cpccr_div_table, |
| 118 | }, |
Paul Burton | ff1930c | 2015-05-24 16:11:36 +0100 | [diff] [blame] | 119 | }, |
| 120 | |
| 121 | [JZ4740_CLK_PCLK] = { |
| 122 | "pclk", CGU_CLK_DIV, |
| 123 | .parents = { JZ4740_CLK_PLL, -1, -1, -1 }, |
Paul Cercueil | 2a1a703 | 2019-05-02 23:24:59 +0200 | [diff] [blame] | 124 | .div = { |
Paul Cercueil | 249592b | 2021-05-30 17:49:19 +0100 | [diff] [blame] | 125 | CGU_REG_CPCCR, 8, 1, 4, 22, -1, -1, 0, |
Paul Cercueil | 2a1a703 | 2019-05-02 23:24:59 +0200 | [diff] [blame] | 126 | jz4740_cgu_cpccr_div_table, |
| 127 | }, |
Paul Burton | ff1930c | 2015-05-24 16:11:36 +0100 | [diff] [blame] | 128 | }, |
| 129 | |
| 130 | [JZ4740_CLK_MCLK] = { |
| 131 | "mclk", CGU_CLK_DIV, |
| 132 | .parents = { JZ4740_CLK_PLL, -1, -1, -1 }, |
Paul Cercueil | 2a1a703 | 2019-05-02 23:24:59 +0200 | [diff] [blame] | 133 | .div = { |
Paul Cercueil | 249592b | 2021-05-30 17:49:19 +0100 | [diff] [blame] | 134 | CGU_REG_CPCCR, 12, 1, 4, 22, -1, -1, 0, |
Paul Cercueil | 2a1a703 | 2019-05-02 23:24:59 +0200 | [diff] [blame] | 135 | jz4740_cgu_cpccr_div_table, |
| 136 | }, |
Paul Burton | ff1930c | 2015-05-24 16:11:36 +0100 | [diff] [blame] | 137 | }, |
| 138 | |
| 139 | [JZ4740_CLK_LCD] = { |
| 140 | "lcd", CGU_CLK_DIV | CGU_CLK_GATE, |
| 141 | .parents = { JZ4740_CLK_PLL_HALF, -1, -1, -1 }, |
Paul Cercueil | 2a1a703 | 2019-05-02 23:24:59 +0200 | [diff] [blame] | 142 | .div = { |
Paul Cercueil | 249592b | 2021-05-30 17:49:19 +0100 | [diff] [blame] | 143 | CGU_REG_CPCCR, 16, 1, 5, 22, -1, -1, 0, |
Paul Cercueil | 2a1a703 | 2019-05-02 23:24:59 +0200 | [diff] [blame] | 144 | jz4740_cgu_cpccr_div_table, |
| 145 | }, |
Paul Burton | ff1930c | 2015-05-24 16:11:36 +0100 | [diff] [blame] | 146 | .gate = { CGU_REG_CLKGR, 10 }, |
| 147 | }, |
| 148 | |
| 149 | [JZ4740_CLK_LCD_PCLK] = { |
| 150 | "lcd_pclk", CGU_CLK_DIV, |
| 151 | .parents = { JZ4740_CLK_PLL_HALF, -1, -1, -1 }, |
Harvey Hunt | 4afe2d1 | 2016-05-09 17:29:52 +0100 | [diff] [blame] | 152 | .div = { CGU_REG_LPCDR, 0, 1, 11, -1, -1, -1 }, |
Paul Burton | ff1930c | 2015-05-24 16:11:36 +0100 | [diff] [blame] | 153 | }, |
| 154 | |
| 155 | [JZ4740_CLK_I2S] = { |
| 156 | "i2s", CGU_CLK_MUX | CGU_CLK_DIV | CGU_CLK_GATE, |
| 157 | .parents = { JZ4740_CLK_EXT, JZ4740_CLK_PLL_HALF, -1, -1 }, |
| 158 | .mux = { CGU_REG_CPCCR, 31, 1 }, |
Paul Cercueil | 574f4e8 | 2018-06-27 14:14:58 +0200 | [diff] [blame] | 159 | .div = { CGU_REG_I2SCDR, 0, 1, 9, -1, -1, -1 }, |
Paul Burton | ff1930c | 2015-05-24 16:11:36 +0100 | [diff] [blame] | 160 | .gate = { CGU_REG_CLKGR, 6 }, |
| 161 | }, |
| 162 | |
| 163 | [JZ4740_CLK_SPI] = { |
| 164 | "spi", CGU_CLK_MUX | CGU_CLK_DIV | CGU_CLK_GATE, |
| 165 | .parents = { JZ4740_CLK_EXT, JZ4740_CLK_PLL, -1, -1 }, |
| 166 | .mux = { CGU_REG_SSICDR, 31, 1 }, |
Harvey Hunt | 4afe2d1 | 2016-05-09 17:29:52 +0100 | [diff] [blame] | 167 | .div = { CGU_REG_SSICDR, 0, 1, 4, -1, -1, -1 }, |
Paul Burton | ff1930c | 2015-05-24 16:11:36 +0100 | [diff] [blame] | 168 | .gate = { CGU_REG_CLKGR, 4 }, |
| 169 | }, |
| 170 | |
| 171 | [JZ4740_CLK_MMC] = { |
| 172 | "mmc", CGU_CLK_DIV | CGU_CLK_GATE, |
| 173 | .parents = { JZ4740_CLK_PLL_HALF, -1, -1, -1 }, |
Harvey Hunt | 4afe2d1 | 2016-05-09 17:29:52 +0100 | [diff] [blame] | 174 | .div = { CGU_REG_MSCCDR, 0, 1, 5, -1, -1, -1 }, |
Paul Burton | ff1930c | 2015-05-24 16:11:36 +0100 | [diff] [blame] | 175 | .gate = { CGU_REG_CLKGR, 7 }, |
| 176 | }, |
| 177 | |
| 178 | [JZ4740_CLK_UHC] = { |
| 179 | "uhc", CGU_CLK_DIV | CGU_CLK_GATE, |
| 180 | .parents = { JZ4740_CLK_PLL_HALF, -1, -1, -1 }, |
Harvey Hunt | 4afe2d1 | 2016-05-09 17:29:52 +0100 | [diff] [blame] | 181 | .div = { CGU_REG_UHCCDR, 0, 1, 4, -1, -1, -1 }, |
Paul Burton | ff1930c | 2015-05-24 16:11:36 +0100 | [diff] [blame] | 182 | .gate = { CGU_REG_CLKGR, 14 }, |
| 183 | }, |
| 184 | |
| 185 | [JZ4740_CLK_UDC] = { |
Paul Cercueil | 2b555a4 | 2018-06-27 14:14:59 +0200 | [diff] [blame] | 186 | "udc", CGU_CLK_MUX | CGU_CLK_DIV | CGU_CLK_GATE, |
Paul Burton | ff1930c | 2015-05-24 16:11:36 +0100 | [diff] [blame] | 187 | .parents = { JZ4740_CLK_EXT, JZ4740_CLK_PLL_HALF, -1, -1 }, |
| 188 | .mux = { CGU_REG_CPCCR, 29, 1 }, |
Harvey Hunt | 4afe2d1 | 2016-05-09 17:29:52 +0100 | [diff] [blame] | 189 | .div = { CGU_REG_CPCCR, 23, 1, 6, -1, -1, -1 }, |
Paul Cercueil | b7e2992 | 2019-01-25 12:34:36 -0300 | [diff] [blame] | 190 | .gate = { CGU_REG_SCR, 6, true }, |
Paul Burton | ff1930c | 2015-05-24 16:11:36 +0100 | [diff] [blame] | 191 | }, |
| 192 | |
| 193 | /* Gate-only clocks */ |
| 194 | |
| 195 | [JZ4740_CLK_UART0] = { |
| 196 | "uart0", CGU_CLK_GATE, |
| 197 | .parents = { JZ4740_CLK_EXT, -1, -1, -1 }, |
| 198 | .gate = { CGU_REG_CLKGR, 0 }, |
| 199 | }, |
| 200 | |
| 201 | [JZ4740_CLK_UART1] = { |
| 202 | "uart1", CGU_CLK_GATE, |
| 203 | .parents = { JZ4740_CLK_EXT, -1, -1, -1 }, |
| 204 | .gate = { CGU_REG_CLKGR, 15 }, |
| 205 | }, |
| 206 | |
| 207 | [JZ4740_CLK_DMA] = { |
| 208 | "dma", CGU_CLK_GATE, |
| 209 | .parents = { JZ4740_CLK_PCLK, -1, -1, -1 }, |
| 210 | .gate = { CGU_REG_CLKGR, 12 }, |
| 211 | }, |
| 212 | |
| 213 | [JZ4740_CLK_IPU] = { |
| 214 | "ipu", CGU_CLK_GATE, |
| 215 | .parents = { JZ4740_CLK_PCLK, -1, -1, -1 }, |
| 216 | .gate = { CGU_REG_CLKGR, 13 }, |
| 217 | }, |
| 218 | |
| 219 | [JZ4740_CLK_ADC] = { |
| 220 | "adc", CGU_CLK_GATE, |
| 221 | .parents = { JZ4740_CLK_EXT, -1, -1, -1 }, |
| 222 | .gate = { CGU_REG_CLKGR, 8 }, |
| 223 | }, |
| 224 | |
| 225 | [JZ4740_CLK_I2C] = { |
| 226 | "i2c", CGU_CLK_GATE, |
| 227 | .parents = { JZ4740_CLK_EXT, -1, -1, -1 }, |
| 228 | .gate = { CGU_REG_CLKGR, 3 }, |
| 229 | }, |
| 230 | |
| 231 | [JZ4740_CLK_AIC] = { |
| 232 | "aic", CGU_CLK_GATE, |
| 233 | .parents = { JZ4740_CLK_EXT, -1, -1, -1 }, |
| 234 | .gate = { CGU_REG_CLKGR, 5 }, |
| 235 | }, |
Paul Cercueil | 73dd11d | 2019-07-24 13:16:10 -0400 | [diff] [blame] | 236 | |
| 237 | [JZ4740_CLK_TCU] = { |
| 238 | "tcu", CGU_CLK_GATE, |
| 239 | .parents = { JZ4740_CLK_EXT, -1, -1, -1 }, |
| 240 | .gate = { CGU_REG_CLKGR, 1 }, |
| 241 | }, |
Paul Burton | ff1930c | 2015-05-24 16:11:36 +0100 | [diff] [blame] | 242 | }; |
| 243 | |
| 244 | static void __init jz4740_cgu_init(struct device_node *np) |
| 245 | { |
| 246 | int retval; |
| 247 | |
| 248 | cgu = ingenic_cgu_new(jz4740_cgu_clocks, |
| 249 | ARRAY_SIZE(jz4740_cgu_clocks), np); |
| 250 | if (!cgu) { |
| 251 | pr_err("%s: failed to initialise CGU\n", __func__); |
| 252 | return; |
| 253 | } |
| 254 | |
| 255 | retval = ingenic_cgu_register_clocks(cgu); |
| 256 | if (retval) |
| 257 | pr_err("%s: failed to register CGU Clocks\n", __func__); |
Paul Cercueil | 2ee93e3 | 2019-06-11 20:07:54 +0200 | [diff] [blame] | 258 | |
| 259 | ingenic_cgu_register_syscore_ops(cgu); |
Paul Burton | ff1930c | 2015-05-24 16:11:36 +0100 | [diff] [blame] | 260 | } |
Paul Cercueil | 03d570e | 2019-08-10 14:36:20 +0200 | [diff] [blame] | 261 | CLK_OF_DECLARE_DRIVER(jz4740_cgu, "ingenic,jz4740-cgu", jz4740_cgu_init); |