diff options
| author | Linus Walleij <linus.walleij@linaro.org> | 2016-08-22 05:19:33 -0400 |
|---|---|---|
| committer | Stephen Boyd <sboyd@codeaurora.org> | 2016-08-25 16:03:52 -0400 |
| commit | 5e23c593057520db45b089644863989d4b21e31f (patch) | |
| tree | 3add6d733e30531e73e756a55584901abe85016b /drivers/clk/versatile | |
| parent | 50581cc4f14f0f704b967cd4664a34d7644be816 (diff) | |
clk: versatile/icst: add Integrator core module clocks
The Integrator/AP and Integrator/CP have special derivatives
of the ICST525 control registers, where some bits have been
hardwired but others are possible to adjust, resulting in a
control register that makes it possible to set an even,
desired megahertz value.
The Integrator/AP and Integrator/CP have slightly different
layout so we support them using different compatible
strings.
After adding these clocks, the Integrator-specific cpufreq
driver can be switched over to use the generic operating
point device tree cpufreq driver.
Instead of simply writing a value to the oscillator control
register we switch to the more elaborate method of providing
a bitmask and use regmap_update_bits() to poke the right bits
for the desired frequency, this is needed since these control
registers sometimes control more than one clock.
Cc: Russell King <linux@armlinux.org.uk>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
Diffstat (limited to 'drivers/clk/versatile')
| -rw-r--r-- | drivers/clk/versatile/clk-icst.c | 174 |
1 files changed, 160 insertions, 14 deletions
diff --git a/drivers/clk/versatile/clk-icst.c b/drivers/clk/versatile/clk-icst.c index 5e9b65278e4c..8f06473b72ff 100644 --- a/drivers/clk/versatile/clk-icst.c +++ b/drivers/clk/versatile/clk-icst.c | |||
| @@ -27,6 +27,21 @@ | |||
| 27 | /* Magic unlocking token used on all Versatile boards */ | 27 | /* Magic unlocking token used on all Versatile boards */ |
| 28 | #define VERSATILE_LOCK_VAL 0xA05F | 28 | #define VERSATILE_LOCK_VAL 0xA05F |
| 29 | 29 | ||
| 30 | #define VERSATILE_AUX_OSC_BITS 0x7FFFF | ||
| 31 | #define INTEGRATOR_AP_CM_BITS 0xFF | ||
| 32 | #define INTEGRATOR_CP_CM_CORE_BITS 0x7FF | ||
| 33 | #define INTEGRATOR_CP_CM_MEM_BITS 0x7FF000 | ||
| 34 | |||
| 35 | /** | ||
| 36 | * enum icst_control_type - the type of ICST control register | ||
| 37 | */ | ||
| 38 | enum icst_control_type { | ||
| 39 | ICST_VERSATILE, /* The standard type, all control bits available */ | ||
| 40 | ICST_INTEGRATOR_AP_CM, /* Only 8 bits of VDW available */ | ||
| 41 | ICST_INTEGRATOR_CP_CM_CORE, /* Only 8 bits of VDW and 3 bits of OD */ | ||
| 42 | ICST_INTEGRATOR_CP_CM_MEM, /* Only 8 bits of VDW and 3 bits of OD */ | ||
| 43 | }; | ||
| 44 | |||
| 30 | /** | 45 | /** |
| 31 | * struct clk_icst - ICST VCO clock wrapper | 46 | * struct clk_icst - ICST VCO clock wrapper |
| 32 | * @hw: corresponding clock hardware entry | 47 | * @hw: corresponding clock hardware entry |
| @@ -34,6 +49,7 @@ | |||
| 34 | * @lockreg: VCO lock register address | 49 | * @lockreg: VCO lock register address |
| 35 | * @params: parameters for this ICST instance | 50 | * @params: parameters for this ICST instance |
| 36 | * @rate: current rate | 51 | * @rate: current rate |
| 52 | * @ctype: the type of control register for the ICST | ||
| 37 | */ | 53 | */ |
| 38 | struct clk_icst { | 54 | struct clk_icst { |
| 39 | struct clk_hw hw; | 55 | struct clk_hw hw; |
| @@ -42,6 +58,7 @@ struct clk_icst { | |||
| 42 | u32 lockreg_off; | 58 | u32 lockreg_off; |
| 43 | struct icst_params *params; | 59 | struct icst_params *params; |
| 44 | unsigned long rate; | 60 | unsigned long rate; |
| 61 | enum icst_control_type ctype; | ||
| 45 | }; | 62 | }; |
| 46 | 63 | ||
| 47 | #define to_icst(_hw) container_of(_hw, struct clk_icst, hw) | 64 | #define to_icst(_hw) container_of(_hw, struct clk_icst, hw) |
| @@ -59,6 +76,44 @@ static int vco_get(struct clk_icst *icst, struct icst_vco *vco) | |||
| 59 | ret = regmap_read(icst->map, icst->vcoreg_off, &val); | 76 | ret = regmap_read(icst->map, icst->vcoreg_off, &val); |
| 60 | if (ret) | 77 | if (ret) |
| 61 | return ret; | 78 | return ret; |
| 79 | |||
| 80 | /* | ||
| 81 | * The Integrator/AP core clock can only access the low eight | ||
| 82 | * bits of the v PLL divider. Bit 8 is tied low and always zero, | ||
| 83 | * r is hardwired to 22 and output divider s is hardwired to 1 | ||
| 84 | * (divide by 2) according to the document | ||
| 85 | * "Integrator CM926EJ-S, CM946E-S, CM966E-S, CM1026EJ-S and | ||
| 86 | * CM1136JF-S User Guide" ARM DUI 0138E, page 3-13 thru 3-14. | ||
| 87 | */ | ||
| 88 | if (icst->ctype == ICST_INTEGRATOR_AP_CM) { | ||
| 89 | vco->v = val & INTEGRATOR_AP_CM_BITS; | ||
| 90 | vco->r = 22; | ||
| 91 | vco->s = 1; | ||
| 92 | return 0; | ||
| 93 | } | ||
| 94 | |||
| 95 | /* | ||
| 96 | * The Integrator/CP core clock can access the low eight bits | ||
| 97 | * of the v PLL divider. Bit 8 is tied low and always zero, | ||
| 98 | * r is hardwired to 22 and the output divider s is accessible | ||
| 99 | * in bits 8 thru 10 according to the document | ||
| 100 | * "Integrator/CM940T, CM920T, CM740T, and CM720T User Guide" | ||
| 101 | * ARM DUI 0157A, page 3-20 thru 3-23 and 4-10. | ||
| 102 | */ | ||
| 103 | if (icst->ctype == ICST_INTEGRATOR_CP_CM_CORE) { | ||
| 104 | vco->v = val & 0xFF; | ||
| 105 | vco->r = 22; | ||
| 106 | vco->s = (val >> 8) & 7; | ||
| 107 | return 0; | ||
| 108 | } | ||
| 109 | |||
| 110 | if (icst->ctype == ICST_INTEGRATOR_CP_CM_MEM) { | ||
| 111 | vco->v = (val >> 12) & 0xFF; | ||
| 112 | vco->r = 22; | ||
| 113 | vco->s = (val >> 20) & 7; | ||
| 114 | return 0; | ||
| 115 | } | ||
| 116 | |||
| 62 | vco->v = val & 0x1ff; | 117 | vco->v = val & 0x1ff; |
| 63 | vco->r = (val >> 9) & 0x7f; | 118 | vco->r = (val >> 9) & 0x7f; |
| 64 | vco->s = (val >> 16) & 03; | 119 | vco->s = (val >> 16) & 03; |
| @@ -72,22 +127,52 @@ static int vco_get(struct clk_icst *icst, struct icst_vco *vco) | |||
| 72 | */ | 127 | */ |
| 73 | static int vco_set(struct clk_icst *icst, struct icst_vco vco) | 128 | static int vco_set(struct clk_icst *icst, struct icst_vco vco) |
| 74 | { | 129 | { |
| 130 | u32 mask; | ||
| 75 | u32 val; | 131 | u32 val; |
| 76 | int ret; | 132 | int ret; |
| 77 | 133 | ||
| 78 | ret = regmap_read(icst->map, icst->vcoreg_off, &val); | 134 | /* Mask the bits used by the VCO */ |
| 79 | if (ret) | 135 | switch (icst->ctype) { |
| 80 | return ret; | 136 | case ICST_INTEGRATOR_AP_CM: |
| 137 | mask = INTEGRATOR_AP_CM_BITS; | ||
| 138 | val = vco.v & 0xFF; | ||
| 139 | if (vco.v & 0x100) | ||
| 140 | pr_err("ICST error: tried to set bit 8 of VDW\n"); | ||
| 141 | if (vco.s != 1) | ||
| 142 | pr_err("ICST error: tried to use VOD != 1\n"); | ||
| 143 | if (vco.r != 22) | ||
| 144 | pr_err("ICST error: tried to use RDW != 22\n"); | ||
| 145 | break; | ||
| 146 | case ICST_INTEGRATOR_CP_CM_CORE: | ||
| 147 | mask = INTEGRATOR_CP_CM_CORE_BITS; /* Uses 12 bits */ | ||
| 148 | val = (vco.v & 0xFF) | vco.s << 8; | ||
| 149 | if (vco.v & 0x100) | ||
| 150 | pr_err("ICST error: tried to set bit 8 of VDW\n"); | ||
| 151 | if (vco.r != 22) | ||
| 152 | pr_err("ICST error: tried to use RDW != 22\n"); | ||
| 153 | break; | ||
| 154 | case ICST_INTEGRATOR_CP_CM_MEM: | ||
| 155 | mask = INTEGRATOR_CP_CM_MEM_BITS; /* Uses 12 bits */ | ||
| 156 | val = ((vco.v & 0xFF) << 12) | (vco.s << 20); | ||
| 157 | if (vco.v & 0x100) | ||
| 158 | pr_err("ICST error: tried to set bit 8 of VDW\n"); | ||
| 159 | if (vco.r != 22) | ||
| 160 | pr_err("ICST error: tried to use RDW != 22\n"); | ||
| 161 | break; | ||
| 162 | default: | ||
| 163 | /* Regular auxilary oscillator */ | ||
| 164 | mask = VERSATILE_AUX_OSC_BITS; | ||
| 165 | val = vco.v | (vco.r << 9) | (vco.s << 16); | ||
| 166 | break; | ||
| 167 | } | ||
| 81 | 168 | ||
| 82 | /* Mask the 18 bits used by the VCO */ | 169 | pr_debug("ICST: new val = 0x%08x\n", val); |
| 83 | val &= ~0x7ffff; | ||
| 84 | val |= vco.v | (vco.r << 9) | (vco.s << 16); | ||
| 85 | 170 | ||
| 86 | /* This magic unlocks the VCO so it can be controlled */ | 171 | /* This magic unlocks the VCO so it can be controlled */ |
| 87 | ret = regmap_write(icst->map, icst->lockreg_off, VERSATILE_LOCK_VAL); | 172 | ret = regmap_write(icst->map, icst->lockreg_off, VERSATILE_LOCK_VAL); |
| 88 | if (ret) | 173 | if (ret) |
| 89 | return ret; | 174 | return ret; |
| 90 | ret = regmap_write(icst->map, icst->vcoreg_off, val); | 175 | ret = regmap_update_bits(icst->map, icst->vcoreg_off, mask, val); |
| 91 | if (ret) | 176 | if (ret) |
| 92 | return ret; | 177 | return ret; |
| 93 | /* This locks the VCO again */ | 178 | /* This locks the VCO again */ |
| @@ -121,6 +206,25 @@ static long icst_round_rate(struct clk_hw *hw, unsigned long rate, | |||
| 121 | struct clk_icst *icst = to_icst(hw); | 206 | struct clk_icst *icst = to_icst(hw); |
| 122 | struct icst_vco vco; | 207 | struct icst_vco vco; |
| 123 | 208 | ||
| 209 | if (icst->ctype == ICST_INTEGRATOR_AP_CM || | ||
| 210 | icst->ctype == ICST_INTEGRATOR_CP_CM_CORE) { | ||
| 211 | if (rate <= 12000000) | ||
| 212 | return 12000000; | ||
| 213 | if (rate >= 160000000) | ||
| 214 | return 160000000; | ||
| 215 | /* Slam to closest megahertz */ | ||
| 216 | return DIV_ROUND_CLOSEST(rate, 1000000) * 1000000; | ||
| 217 | } | ||
| 218 | |||
| 219 | if (icst->ctype == ICST_INTEGRATOR_CP_CM_MEM) { | ||
| 220 | if (rate <= 6000000) | ||
| 221 | return 6000000; | ||
| 222 | if (rate >= 66000000) | ||
| 223 | return 66000000; | ||
| 224 | /* Slam to closest 0.5 megahertz */ | ||
| 225 | return DIV_ROUND_CLOSEST(rate, 500000) * 500000; | ||
| 226 | } | ||
| 227 | |||
| 124 | vco = icst_hz_to_vco(icst->params, rate); | 228 | vco = icst_hz_to_vco(icst->params, rate); |
| 125 | return icst_hz(icst->params, vco); | 229 | return icst_hz(icst->params, vco); |
| 126 | } | 230 | } |
| @@ -148,7 +252,8 @@ static struct clk *icst_clk_setup(struct device *dev, | |||
| 148 | const struct clk_icst_desc *desc, | 252 | const struct clk_icst_desc *desc, |
| 149 | const char *name, | 253 | const char *name, |
| 150 | const char *parent_name, | 254 | const char *parent_name, |
| 151 | struct regmap *map) | 255 | struct regmap *map, |
| 256 | enum icst_control_type ctype) | ||
| 152 | { | 257 | { |
| 153 | struct clk *clk; | 258 | struct clk *clk; |
| 154 | struct clk_icst *icst; | 259 | struct clk_icst *icst; |
| @@ -178,6 +283,7 @@ static struct clk *icst_clk_setup(struct device *dev, | |||
| 178 | icst->params = pclone; | 283 | icst->params = pclone; |
| 179 | icst->vcoreg_off = desc->vco_offset; | 284 | icst->vcoreg_off = desc->vco_offset; |
| 180 | icst->lockreg_off = desc->lock_offset; | 285 | icst->lockreg_off = desc->lock_offset; |
| 286 | icst->ctype = ctype; | ||
| 181 | 287 | ||
| 182 | clk = clk_register(dev, &icst->hw); | 288 | clk = clk_register(dev, &icst->hw); |
| 183 | if (IS_ERR(clk)) { | 289 | if (IS_ERR(clk)) { |
| @@ -206,7 +312,8 @@ struct clk *icst_clk_register(struct device *dev, | |||
| 206 | pr_err("could not initialize ICST regmap\n"); | 312 | pr_err("could not initialize ICST regmap\n"); |
| 207 | return ERR_CAST(map); | 313 | return ERR_CAST(map); |
| 208 | } | 314 | } |
| 209 | return icst_clk_setup(dev, desc, name, parent_name, map); | 315 | return icst_clk_setup(dev, desc, name, parent_name, map, |
| 316 | ICST_VERSATILE); | ||
| 210 | } | 317 | } |
| 211 | EXPORT_SYMBOL_GPL(icst_clk_register); | 318 | EXPORT_SYMBOL_GPL(icst_clk_register); |
| 212 | 319 | ||
| @@ -239,6 +346,28 @@ static const struct icst_params icst307_params = { | |||
| 239 | .idx2s = icst307_idx2s, | 346 | .idx2s = icst307_idx2s, |
| 240 | }; | 347 | }; |
| 241 | 348 | ||
| 349 | /** | ||
| 350 | * The core modules on the Integrator/AP and Integrator/CP have | ||
| 351 | * especially crippled ICST525 control. | ||
| 352 | */ | ||
| 353 | static const struct icst_params icst525_apcp_cm_params = { | ||
| 354 | .vco_max = ICST525_VCO_MAX_5V, | ||
| 355 | .vco_min = ICST525_VCO_MIN, | ||
| 356 | /* Minimum 12 MHz, VDW = 4 */ | ||
| 357 | .vd_min = 12, | ||
| 358 | /* | ||
| 359 | * Maximum 160 MHz, VDW = 152 for all core modules, but | ||
| 360 | * CM926EJ-S, CM1026EJ-S and CM1136JF-S can actually | ||
| 361 | * go to 200 MHz (max VDW = 192). | ||
| 362 | */ | ||
| 363 | .vd_max = 192, | ||
| 364 | /* r is hardcoded to 22 and this is the actual divisor, +2 */ | ||
| 365 | .rd_min = 24, | ||
| 366 | .rd_max = 24, | ||
| 367 | .s2div = icst525_s2div, | ||
| 368 | .idx2s = icst525_idx2s, | ||
| 369 | }; | ||
| 370 | |||
| 242 | static void __init of_syscon_icst_setup(struct device_node *np) | 371 | static void __init of_syscon_icst_setup(struct device_node *np) |
| 243 | { | 372 | { |
| 244 | struct device_node *parent; | 373 | struct device_node *parent; |
| @@ -247,6 +376,7 @@ static void __init of_syscon_icst_setup(struct device_node *np) | |||
| 247 | const char *name = np->name; | 376 | const char *name = np->name; |
| 248 | const char *parent_name; | 377 | const char *parent_name; |
| 249 | struct clk *regclk; | 378 | struct clk *regclk; |
| 379 | enum icst_control_type ctype; | ||
| 250 | 380 | ||
| 251 | /* We do not release this reference, we are using it perpetually */ | 381 | /* We do not release this reference, we are using it perpetually */ |
| 252 | parent = of_get_parent(np); | 382 | parent = of_get_parent(np); |
| @@ -269,11 +399,22 @@ static void __init of_syscon_icst_setup(struct device_node *np) | |||
| 269 | return; | 399 | return; |
| 270 | } | 400 | } |
| 271 | 401 | ||
| 272 | if (of_device_is_compatible(np, "arm,syscon-icst525")) | 402 | if (of_device_is_compatible(np, "arm,syscon-icst525")) { |
| 273 | icst_desc.params = &icst525_params; | 403 | icst_desc.params = &icst525_params; |
| 274 | else if (of_device_is_compatible(np, "arm,syscon-icst307")) | 404 | ctype = ICST_VERSATILE; |
| 405 | } else if (of_device_is_compatible(np, "arm,syscon-icst307")) { | ||
| 275 | icst_desc.params = &icst307_params; | 406 | icst_desc.params = &icst307_params; |
| 276 | else { | 407 | ctype = ICST_VERSATILE; |
| 408 | } else if (of_device_is_compatible(np, "arm,syscon-icst525-integratorap-cm")) { | ||
| 409 | icst_desc.params = &icst525_apcp_cm_params; | ||
| 410 | ctype = ICST_INTEGRATOR_AP_CM; | ||
| 411 | } else if (of_device_is_compatible(np, "arm,syscon-icst525-integratorcp-cm-core")) { | ||
| 412 | icst_desc.params = &icst525_apcp_cm_params; | ||
| 413 | ctype = ICST_INTEGRATOR_CP_CM_CORE; | ||
| 414 | } else if (of_device_is_compatible(np, "arm,syscon-icst525-integratorcp-cm-mem")) { | ||
| 415 | icst_desc.params = &icst525_apcp_cm_params; | ||
| 416 | ctype = ICST_INTEGRATOR_CP_CM_MEM; | ||
| 417 | } else { | ||
| 277 | pr_err("unknown ICST clock %s\n", name); | 418 | pr_err("unknown ICST clock %s\n", name); |
| 278 | return; | 419 | return; |
| 279 | } | 420 | } |
| @@ -281,7 +422,7 @@ static void __init of_syscon_icst_setup(struct device_node *np) | |||
| 281 | /* Parent clock name is not the same as node parent */ | 422 | /* Parent clock name is not the same as node parent */ |
| 282 | parent_name = of_clk_get_parent_name(np, 0); | 423 | parent_name = of_clk_get_parent_name(np, 0); |
| 283 | 424 | ||
| 284 | regclk = icst_clk_setup(NULL, &icst_desc, name, parent_name, map); | 425 | regclk = icst_clk_setup(NULL, &icst_desc, name, parent_name, map, ctype); |
| 285 | if (IS_ERR(regclk)) { | 426 | if (IS_ERR(regclk)) { |
| 286 | pr_err("error setting up syscon ICST clock %s\n", name); | 427 | pr_err("error setting up syscon ICST clock %s\n", name); |
| 287 | return; | 428 | return; |
| @@ -294,5 +435,10 @@ CLK_OF_DECLARE(arm_syscon_icst525_clk, | |||
| 294 | "arm,syscon-icst525", of_syscon_icst_setup); | 435 | "arm,syscon-icst525", of_syscon_icst_setup); |
| 295 | CLK_OF_DECLARE(arm_syscon_icst307_clk, | 436 | CLK_OF_DECLARE(arm_syscon_icst307_clk, |
| 296 | "arm,syscon-icst307", of_syscon_icst_setup); | 437 | "arm,syscon-icst307", of_syscon_icst_setup); |
| 297 | 438 | CLK_OF_DECLARE(arm_syscon_integratorap_cm_clk, | |
| 439 | "arm,syscon-icst525-integratorap-cm", of_syscon_icst_setup); | ||
| 440 | CLK_OF_DECLARE(arm_syscon_integratorcp_cm_core_clk, | ||
| 441 | "arm,syscon-icst525-integratorcp-cm-core", of_syscon_icst_setup); | ||
| 442 | CLK_OF_DECLARE(arm_syscon_integratorcp_cm_mem_clk, | ||
| 443 | "arm,syscon-icst525-integratorcp-cm-mem", of_syscon_icst_setup); | ||
| 298 | #endif | 444 | #endif |
