| .. | .. |
|---|
| 7 | 7 | #include <linux/bitops.h> |
|---|
| 8 | 8 | #include <linux/clk-provider.h> |
|---|
| 9 | 9 | #include <linux/delay.h> |
|---|
| 10 | +#include <linux/io.h> |
|---|
| 10 | 11 | #include <linux/of.h> |
|---|
| 11 | | -#include <linux/syscore_ops.h> |
|---|
| 12 | + |
|---|
| 12 | 13 | #include <dt-bindings/clock/jz4770-cgu.h> |
|---|
| 14 | + |
|---|
| 13 | 15 | #include "cgu.h" |
|---|
| 16 | +#include "pm.h" |
|---|
| 14 | 17 | |
|---|
| 15 | 18 | /* |
|---|
| 16 | 19 | * CPM registers offset address definition |
|---|
| .. | .. |
|---|
| 36 | 39 | #define CGU_REG_MSC1CDR 0xA4 |
|---|
| 37 | 40 | #define CGU_REG_MSC2CDR 0xA8 |
|---|
| 38 | 41 | #define CGU_REG_BCHCDR 0xAC |
|---|
| 39 | | - |
|---|
| 40 | | -/* bits within the LCR register */ |
|---|
| 41 | | -#define LCR_LPM BIT(0) /* Low Power Mode */ |
|---|
| 42 | 42 | |
|---|
| 43 | 43 | /* bits within the OPCR register */ |
|---|
| 44 | 44 | #define OPCR_SPENDH BIT(5) /* UHC PHY suspend */ |
|---|
| .. | .. |
|---|
| 86 | 86 | 0x0, 0x1, -1, 0x2, -1, -1, -1, 0x3, |
|---|
| 87 | 87 | }; |
|---|
| 88 | 88 | |
|---|
| 89 | +static const u8 jz4770_cgu_cpccr_div_table[] = { |
|---|
| 90 | + 1, 2, 3, 4, 6, 8, 12, |
|---|
| 91 | +}; |
|---|
| 92 | + |
|---|
| 89 | 93 | static const struct ingenic_cgu_clk_info jz4770_cgu_clocks[] = { |
|---|
| 90 | 94 | |
|---|
| 91 | 95 | /* External clocks */ |
|---|
| .. | .. |
|---|
| 100 | 104 | .parents = { JZ4770_CLK_EXT }, |
|---|
| 101 | 105 | .pll = { |
|---|
| 102 | 106 | .reg = CGU_REG_CPPCR0, |
|---|
| 107 | + .rate_multiplier = 1, |
|---|
| 103 | 108 | .m_shift = 24, |
|---|
| 104 | 109 | .m_bits = 7, |
|---|
| 105 | 110 | .m_offset = 1, |
|---|
| .. | .. |
|---|
| 110 | 115 | .od_bits = 2, |
|---|
| 111 | 116 | .od_max = 8, |
|---|
| 112 | 117 | .od_encoding = pll_od_encoding, |
|---|
| 118 | + .bypass_reg = CGU_REG_CPPCR0, |
|---|
| 113 | 119 | .bypass_bit = 9, |
|---|
| 114 | 120 | .enable_bit = 8, |
|---|
| 115 | 121 | .stable_bit = 10, |
|---|
| .. | .. |
|---|
| 122 | 128 | .parents = { JZ4770_CLK_EXT }, |
|---|
| 123 | 129 | .pll = { |
|---|
| 124 | 130 | .reg = CGU_REG_CPPCR1, |
|---|
| 131 | + .rate_multiplier = 1, |
|---|
| 125 | 132 | .m_shift = 24, |
|---|
| 126 | 133 | .m_bits = 7, |
|---|
| 127 | 134 | .m_offset = 1, |
|---|
| .. | .. |
|---|
| 132 | 139 | .od_bits = 2, |
|---|
| 133 | 140 | .od_max = 8, |
|---|
| 134 | 141 | .od_encoding = pll_od_encoding, |
|---|
| 142 | + .bypass_reg = CGU_REG_CPPCR1, |
|---|
| 143 | + .no_bypass_bit = true, |
|---|
| 135 | 144 | .enable_bit = 7, |
|---|
| 136 | 145 | .stable_bit = 6, |
|---|
| 137 | | - .no_bypass_bit = true, |
|---|
| 138 | 146 | }, |
|---|
| 139 | 147 | }, |
|---|
| 140 | 148 | |
|---|
| .. | .. |
|---|
| 143 | 151 | [JZ4770_CLK_CCLK] = { |
|---|
| 144 | 152 | "cclk", CGU_CLK_DIV, |
|---|
| 145 | 153 | .parents = { JZ4770_CLK_PLL0, }, |
|---|
| 146 | | - .div = { CGU_REG_CPCCR, 0, 1, 4, 22, -1, -1 }, |
|---|
| 154 | + .div = { |
|---|
| 155 | + CGU_REG_CPCCR, 0, 1, 4, 22, -1, -1, |
|---|
| 156 | + jz4770_cgu_cpccr_div_table, |
|---|
| 157 | + }, |
|---|
| 147 | 158 | }, |
|---|
| 148 | 159 | [JZ4770_CLK_H0CLK] = { |
|---|
| 149 | 160 | "h0clk", CGU_CLK_DIV, |
|---|
| 150 | 161 | .parents = { JZ4770_CLK_PLL0, }, |
|---|
| 151 | | - .div = { CGU_REG_CPCCR, 4, 1, 4, 22, -1, -1 }, |
|---|
| 162 | + .div = { |
|---|
| 163 | + CGU_REG_CPCCR, 4, 1, 4, 22, -1, -1, |
|---|
| 164 | + jz4770_cgu_cpccr_div_table, |
|---|
| 165 | + }, |
|---|
| 152 | 166 | }, |
|---|
| 153 | 167 | [JZ4770_CLK_H1CLK] = { |
|---|
| 154 | 168 | "h1clk", CGU_CLK_DIV | CGU_CLK_GATE, |
|---|
| 155 | 169 | .parents = { JZ4770_CLK_PLL0, }, |
|---|
| 156 | | - .div = { CGU_REG_CPCCR, 24, 1, 4, 22, -1, -1 }, |
|---|
| 170 | + .div = { |
|---|
| 171 | + CGU_REG_CPCCR, 24, 1, 4, 22, -1, -1, |
|---|
| 172 | + jz4770_cgu_cpccr_div_table, |
|---|
| 173 | + }, |
|---|
| 157 | 174 | .gate = { CGU_REG_CLKGR1, 7 }, |
|---|
| 158 | 175 | }, |
|---|
| 159 | 176 | [JZ4770_CLK_H2CLK] = { |
|---|
| 160 | 177 | "h2clk", CGU_CLK_DIV, |
|---|
| 161 | 178 | .parents = { JZ4770_CLK_PLL0, }, |
|---|
| 162 | | - .div = { CGU_REG_CPCCR, 16, 1, 4, 22, -1, -1 }, |
|---|
| 179 | + .div = { |
|---|
| 180 | + CGU_REG_CPCCR, 16, 1, 4, 22, -1, -1, |
|---|
| 181 | + jz4770_cgu_cpccr_div_table, |
|---|
| 182 | + }, |
|---|
| 163 | 183 | }, |
|---|
| 164 | 184 | [JZ4770_CLK_C1CLK] = { |
|---|
| 165 | 185 | "c1clk", CGU_CLK_DIV | CGU_CLK_GATE, |
|---|
| 166 | 186 | .parents = { JZ4770_CLK_PLL0, }, |
|---|
| 167 | | - .div = { CGU_REG_CPCCR, 12, 1, 4, 22, -1, -1 }, |
|---|
| 187 | + .div = { |
|---|
| 188 | + CGU_REG_CPCCR, 12, 1, 4, 22, -1, -1, |
|---|
| 189 | + jz4770_cgu_cpccr_div_table, |
|---|
| 190 | + }, |
|---|
| 168 | 191 | .gate = { CGU_REG_OPCR, 31, true }, // disable CCLK stop on idle |
|---|
| 169 | 192 | }, |
|---|
| 170 | 193 | [JZ4770_CLK_PCLK] = { |
|---|
| 171 | 194 | "pclk", CGU_CLK_DIV, |
|---|
| 172 | 195 | .parents = { JZ4770_CLK_PLL0, }, |
|---|
| 173 | | - .div = { CGU_REG_CPCCR, 8, 1, 4, 22, -1, -1 }, |
|---|
| 196 | + .div = { |
|---|
| 197 | + CGU_REG_CPCCR, 8, 1, 4, 22, -1, -1, |
|---|
| 198 | + jz4770_cgu_cpccr_div_table, |
|---|
| 199 | + }, |
|---|
| 174 | 200 | }, |
|---|
| 175 | 201 | |
|---|
| 176 | 202 | /* Those divided clocks can connect to PLL0 or PLL1 */ |
|---|
| .. | .. |
|---|
| 406 | 432 | }, |
|---|
| 407 | 433 | }; |
|---|
| 408 | 434 | |
|---|
| 409 | | -#if IS_ENABLED(CONFIG_PM_SLEEP) |
|---|
| 410 | | -static int jz4770_cgu_pm_suspend(void) |
|---|
| 411 | | -{ |
|---|
| 412 | | - u32 val; |
|---|
| 413 | | - |
|---|
| 414 | | - val = readl(cgu->base + CGU_REG_LCR); |
|---|
| 415 | | - writel(val | LCR_LPM, cgu->base + CGU_REG_LCR); |
|---|
| 416 | | - return 0; |
|---|
| 417 | | -} |
|---|
| 418 | | - |
|---|
| 419 | | -static void jz4770_cgu_pm_resume(void) |
|---|
| 420 | | -{ |
|---|
| 421 | | - u32 val; |
|---|
| 422 | | - |
|---|
| 423 | | - val = readl(cgu->base + CGU_REG_LCR); |
|---|
| 424 | | - writel(val & ~LCR_LPM, cgu->base + CGU_REG_LCR); |
|---|
| 425 | | -} |
|---|
| 426 | | - |
|---|
| 427 | | -static struct syscore_ops jz4770_cgu_pm_ops = { |
|---|
| 428 | | - .suspend = jz4770_cgu_pm_suspend, |
|---|
| 429 | | - .resume = jz4770_cgu_pm_resume, |
|---|
| 430 | | -}; |
|---|
| 431 | | -#endif /* CONFIG_PM_SLEEP */ |
|---|
| 432 | | - |
|---|
| 433 | 435 | static void __init jz4770_cgu_init(struct device_node *np) |
|---|
| 434 | 436 | { |
|---|
| 435 | 437 | int retval; |
|---|
| .. | .. |
|---|
| 445 | 447 | if (retval) |
|---|
| 446 | 448 | pr_err("%s: failed to register CGU Clocks\n", __func__); |
|---|
| 447 | 449 | |
|---|
| 448 | | -#if IS_ENABLED(CONFIG_PM_SLEEP) |
|---|
| 449 | | - register_syscore_ops(&jz4770_cgu_pm_ops); |
|---|
| 450 | | -#endif |
|---|
| 450 | + ingenic_cgu_register_syscore_ops(cgu); |
|---|
| 451 | 451 | } |
|---|
| 452 | 452 | |
|---|
| 453 | 453 | /* We only probe via devicetree, no need for a platform driver */ |
|---|
| 454 | | -CLK_OF_DECLARE(jz4770_cgu, "ingenic,jz4770-cgu", jz4770_cgu_init); |
|---|
| 454 | +CLK_OF_DECLARE_DRIVER(jz4770_cgu, "ingenic,jz4770-cgu", jz4770_cgu_init); |
|---|