| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * R-Car SYSC Power management support |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2014 Magnus Damm |
|---|
| 5 | 6 | * Copyright (C) 2015-2017 Glider bvba |
|---|
| 6 | | - * |
|---|
| 7 | | - * This file is subject to the terms and conditions of the GNU General Public |
|---|
| 8 | | - * License. See the file "COPYING" in the main directory of this archive |
|---|
| 9 | | - * for more details. |
|---|
| 10 | 7 | */ |
|---|
| 11 | 8 | |
|---|
| 12 | 9 | #include <linux/clk/renesas.h> |
|---|
| .. | .. |
|---|
| 66 | 63 | |
|---|
| 67 | 64 | static void __iomem *rcar_sysc_base; |
|---|
| 68 | 65 | static DEFINE_SPINLOCK(rcar_sysc_lock); /* SMP CPUs + I/O devices */ |
|---|
| 66 | +static u32 rcar_sysc_extmask_offs, rcar_sysc_extmask_val; |
|---|
| 69 | 67 | |
|---|
| 70 | 68 | static int rcar_sysc_pwr_on_off(const struct rcar_sysc_ch *sysc_ch, bool on) |
|---|
| 71 | 69 | { |
|---|
| .. | .. |
|---|
| 108 | 106 | |
|---|
| 109 | 107 | spin_lock_irqsave(&rcar_sysc_lock, flags); |
|---|
| 110 | 108 | |
|---|
| 109 | + /* |
|---|
| 110 | + * Mask external power requests for CPU or 3DG domains |
|---|
| 111 | + */ |
|---|
| 112 | + if (rcar_sysc_extmask_val) { |
|---|
| 113 | + iowrite32(rcar_sysc_extmask_val, |
|---|
| 114 | + rcar_sysc_base + rcar_sysc_extmask_offs); |
|---|
| 115 | + } |
|---|
| 116 | + |
|---|
| 117 | + /* |
|---|
| 118 | + * The interrupt source needs to be enabled, but masked, to prevent the |
|---|
| 119 | + * CPU from receiving it. |
|---|
| 120 | + */ |
|---|
| 121 | + iowrite32(ioread32(rcar_sysc_base + SYSCIMR) | isr_mask, |
|---|
| 122 | + rcar_sysc_base + SYSCIMR); |
|---|
| 123 | + iowrite32(ioread32(rcar_sysc_base + SYSCIER) | isr_mask, |
|---|
| 124 | + rcar_sysc_base + SYSCIER); |
|---|
| 125 | + |
|---|
| 111 | 126 | iowrite32(isr_mask, rcar_sysc_base + SYSCISCR); |
|---|
| 112 | 127 | |
|---|
| 113 | 128 | /* Submit power shutoff or resume request until it was accepted */ |
|---|
| .. | .. |
|---|
| 142 | 157 | iowrite32(isr_mask, rcar_sysc_base + SYSCISCR); |
|---|
| 143 | 158 | |
|---|
| 144 | 159 | out: |
|---|
| 160 | + if (rcar_sysc_extmask_val) |
|---|
| 161 | + iowrite32(0, rcar_sysc_base + rcar_sysc_extmask_offs); |
|---|
| 162 | + |
|---|
| 145 | 163 | spin_unlock_irqrestore(&rcar_sysc_lock, flags); |
|---|
| 146 | 164 | |
|---|
| 147 | 165 | pr_debug("sysc power %s domain %d: %08x -> %d\n", on ? "on" : "off", |
|---|
| 148 | 166 | sysc_ch->isr_bit, ioread32(rcar_sysc_base + SYSCISR), ret); |
|---|
| 149 | 167 | return ret; |
|---|
| 150 | | -} |
|---|
| 151 | | - |
|---|
| 152 | | -static int rcar_sysc_power_down(const struct rcar_sysc_ch *sysc_ch) |
|---|
| 153 | | -{ |
|---|
| 154 | | - return rcar_sysc_power(sysc_ch, false); |
|---|
| 155 | | -} |
|---|
| 156 | | - |
|---|
| 157 | | -static int rcar_sysc_power_up(const struct rcar_sysc_ch *sysc_ch) |
|---|
| 158 | | -{ |
|---|
| 159 | | - return rcar_sysc_power(sysc_ch, true); |
|---|
| 160 | 168 | } |
|---|
| 161 | 169 | |
|---|
| 162 | 170 | static bool rcar_sysc_power_is_off(const struct rcar_sysc_ch *sysc_ch) |
|---|
| .. | .. |
|---|
| 174 | 182 | struct generic_pm_domain genpd; |
|---|
| 175 | 183 | struct rcar_sysc_ch ch; |
|---|
| 176 | 184 | unsigned int flags; |
|---|
| 177 | | - char name[0]; |
|---|
| 185 | + char name[]; |
|---|
| 178 | 186 | }; |
|---|
| 179 | 187 | |
|---|
| 180 | 188 | static inline struct rcar_sysc_pd *to_rcar_pd(struct generic_pm_domain *d) |
|---|
| .. | .. |
|---|
| 187 | 195 | struct rcar_sysc_pd *pd = to_rcar_pd(genpd); |
|---|
| 188 | 196 | |
|---|
| 189 | 197 | pr_debug("%s: %s\n", __func__, genpd->name); |
|---|
| 190 | | - return rcar_sysc_power_down(&pd->ch); |
|---|
| 198 | + return rcar_sysc_power(&pd->ch, false); |
|---|
| 191 | 199 | } |
|---|
| 192 | 200 | |
|---|
| 193 | 201 | static int rcar_sysc_pd_power_on(struct generic_pm_domain *genpd) |
|---|
| .. | .. |
|---|
| 195 | 203 | struct rcar_sysc_pd *pd = to_rcar_pd(genpd); |
|---|
| 196 | 204 | |
|---|
| 197 | 205 | pr_debug("%s: %s\n", __func__, genpd->name); |
|---|
| 198 | | - return rcar_sysc_power_up(&pd->ch); |
|---|
| 206 | + return rcar_sysc_power(&pd->ch, true); |
|---|
| 199 | 207 | } |
|---|
| 200 | 208 | |
|---|
| 201 | 209 | static bool has_cpg_mstp; |
|---|
| .. | .. |
|---|
| 204 | 212 | { |
|---|
| 205 | 213 | struct generic_pm_domain *genpd = &pd->genpd; |
|---|
| 206 | 214 | const char *name = pd->genpd.name; |
|---|
| 207 | | - struct dev_power_governor *gov = &simple_qos_governor; |
|---|
| 208 | 215 | int error; |
|---|
| 209 | 216 | |
|---|
| 210 | 217 | if (pd->flags & PD_CPU) { |
|---|
| .. | .. |
|---|
| 255 | 262 | goto finalize; |
|---|
| 256 | 263 | } |
|---|
| 257 | 264 | |
|---|
| 258 | | - rcar_sysc_power_up(&pd->ch); |
|---|
| 265 | + rcar_sysc_power(&pd->ch, true); |
|---|
| 259 | 266 | |
|---|
| 260 | 267 | finalize: |
|---|
| 261 | | - error = pm_genpd_init(genpd, gov, false); |
|---|
| 268 | + error = pm_genpd_init(genpd, &simple_qos_governor, false); |
|---|
| 262 | 269 | if (error) |
|---|
| 263 | 270 | pr_err("Failed to init PM domain %s: %d\n", name, error); |
|---|
| 264 | 271 | |
|---|
| .. | .. |
|---|
| 266 | 273 | } |
|---|
| 267 | 274 | |
|---|
| 268 | 275 | static const struct of_device_id rcar_sysc_matches[] __initconst = { |
|---|
| 276 | +#ifdef CONFIG_SYSC_R8A7742 |
|---|
| 277 | + { .compatible = "renesas,r8a7742-sysc", .data = &r8a7742_sysc_info }, |
|---|
| 278 | +#endif |
|---|
| 269 | 279 | #ifdef CONFIG_SYSC_R8A7743 |
|---|
| 270 | 280 | { .compatible = "renesas,r8a7743-sysc", .data = &r8a7743_sysc_info }, |
|---|
| 281 | + /* RZ/G1N is identical to RZ/G2M w.r.t. power domains. */ |
|---|
| 282 | + { .compatible = "renesas,r8a7744-sysc", .data = &r8a7743_sysc_info }, |
|---|
| 271 | 283 | #endif |
|---|
| 272 | 284 | #ifdef CONFIG_SYSC_R8A7745 |
|---|
| 273 | 285 | { .compatible = "renesas,r8a7745-sysc", .data = &r8a7745_sysc_info }, |
|---|
| 274 | 286 | #endif |
|---|
| 275 | 287 | #ifdef CONFIG_SYSC_R8A77470 |
|---|
| 276 | 288 | { .compatible = "renesas,r8a77470-sysc", .data = &r8a77470_sysc_info }, |
|---|
| 289 | +#endif |
|---|
| 290 | +#ifdef CONFIG_SYSC_R8A774A1 |
|---|
| 291 | + { .compatible = "renesas,r8a774a1-sysc", .data = &r8a774a1_sysc_info }, |
|---|
| 292 | +#endif |
|---|
| 293 | +#ifdef CONFIG_SYSC_R8A774B1 |
|---|
| 294 | + { .compatible = "renesas,r8a774b1-sysc", .data = &r8a774b1_sysc_info }, |
|---|
| 295 | +#endif |
|---|
| 296 | +#ifdef CONFIG_SYSC_R8A774C0 |
|---|
| 297 | + { .compatible = "renesas,r8a774c0-sysc", .data = &r8a774c0_sysc_info }, |
|---|
| 298 | +#endif |
|---|
| 299 | +#ifdef CONFIG_SYSC_R8A774E1 |
|---|
| 300 | + { .compatible = "renesas,r8a774e1-sysc", .data = &r8a774e1_sysc_info }, |
|---|
| 277 | 301 | #endif |
|---|
| 278 | 302 | #ifdef CONFIG_SYSC_R8A7779 |
|---|
| 279 | 303 | { .compatible = "renesas,r8a7779-sysc", .data = &r8a7779_sysc_info }, |
|---|
| .. | .. |
|---|
| 295 | 319 | #ifdef CONFIG_SYSC_R8A7795 |
|---|
| 296 | 320 | { .compatible = "renesas,r8a7795-sysc", .data = &r8a7795_sysc_info }, |
|---|
| 297 | 321 | #endif |
|---|
| 298 | | -#ifdef CONFIG_SYSC_R8A7796 |
|---|
| 299 | | - { .compatible = "renesas,r8a7796-sysc", .data = &r8a7796_sysc_info }, |
|---|
| 322 | +#ifdef CONFIG_SYSC_R8A77960 |
|---|
| 323 | + { .compatible = "renesas,r8a7796-sysc", .data = &r8a77960_sysc_info }, |
|---|
| 324 | +#endif |
|---|
| 325 | +#ifdef CONFIG_SYSC_R8A77961 |
|---|
| 326 | + { .compatible = "renesas,r8a77961-sysc", .data = &r8a77961_sysc_info }, |
|---|
| 300 | 327 | #endif |
|---|
| 301 | 328 | #ifdef CONFIG_SYSC_R8A77965 |
|---|
| 302 | 329 | { .compatible = "renesas,r8a77965-sysc", .data = &r8a77965_sysc_info }, |
|---|
| .. | .. |
|---|
| 329 | 356 | const struct of_device_id *match; |
|---|
| 330 | 357 | struct rcar_pm_domains *domains; |
|---|
| 331 | 358 | struct device_node *np; |
|---|
| 332 | | - u32 syscier, syscimr; |
|---|
| 333 | 359 | void __iomem *base; |
|---|
| 334 | 360 | unsigned int i; |
|---|
| 335 | 361 | int error; |
|---|
| .. | .. |
|---|
| 343 | 369 | if (info->init) { |
|---|
| 344 | 370 | error = info->init(); |
|---|
| 345 | 371 | if (error) |
|---|
| 346 | | - return error; |
|---|
| 372 | + goto out_put; |
|---|
| 347 | 373 | } |
|---|
| 348 | 374 | |
|---|
| 349 | 375 | has_cpg_mstp = of_find_compatible_node(NULL, NULL, |
|---|
| .. | .. |
|---|
| 358 | 384 | |
|---|
| 359 | 385 | rcar_sysc_base = base; |
|---|
| 360 | 386 | |
|---|
| 387 | + /* Optional External Request Mask Register */ |
|---|
| 388 | + rcar_sysc_extmask_offs = info->extmask_offs; |
|---|
| 389 | + rcar_sysc_extmask_val = info->extmask_val; |
|---|
| 390 | + |
|---|
| 361 | 391 | domains = kzalloc(sizeof(*domains), GFP_KERNEL); |
|---|
| 362 | 392 | if (!domains) { |
|---|
| 363 | 393 | error = -ENOMEM; |
|---|
| .. | .. |
|---|
| 368 | 398 | domains->onecell_data.num_domains = ARRAY_SIZE(domains->domains); |
|---|
| 369 | 399 | rcar_sysc_onecell_data = &domains->onecell_data; |
|---|
| 370 | 400 | |
|---|
| 371 | | - for (i = 0, syscier = 0; i < info->num_areas; i++) |
|---|
| 372 | | - syscier |= BIT(info->areas[i].isr_bit); |
|---|
| 373 | | - |
|---|
| 374 | | - /* |
|---|
| 375 | | - * Mask all interrupt sources to prevent the CPU from receiving them. |
|---|
| 376 | | - * Make sure not to clear reserved bits that were set before. |
|---|
| 377 | | - */ |
|---|
| 378 | | - syscimr = ioread32(base + SYSCIMR); |
|---|
| 379 | | - syscimr |= syscier; |
|---|
| 380 | | - pr_debug("%pOF: syscimr = 0x%08x\n", np, syscimr); |
|---|
| 381 | | - iowrite32(syscimr, base + SYSCIMR); |
|---|
| 382 | | - |
|---|
| 383 | | - /* |
|---|
| 384 | | - * SYSC needs all interrupt sources enabled to control power. |
|---|
| 385 | | - */ |
|---|
| 386 | | - pr_debug("%pOF: syscier = 0x%08x\n", np, syscier); |
|---|
| 387 | | - iowrite32(syscier, base + SYSCIER); |
|---|
| 388 | | - |
|---|
| 389 | | - /* |
|---|
| 390 | | - * First, create all PM domains |
|---|
| 391 | | - */ |
|---|
| 392 | 401 | for (i = 0; i < info->num_areas; i++) { |
|---|
| 393 | 402 | const struct rcar_sysc_area *area = &info->areas[i]; |
|---|
| 394 | 403 | struct rcar_sysc_pd *pd; |
|---|
| .. | .. |
|---|
| 416 | 425 | goto out_put; |
|---|
| 417 | 426 | |
|---|
| 418 | 427 | domains->domains[area->isr_bit] = &pd->genpd; |
|---|
| 419 | | - } |
|---|
| 420 | 428 | |
|---|
| 421 | | - /* |
|---|
| 422 | | - * Second, link all PM domains to their parents |
|---|
| 423 | | - */ |
|---|
| 424 | | - for (i = 0; i < info->num_areas; i++) { |
|---|
| 425 | | - const struct rcar_sysc_area *area = &info->areas[i]; |
|---|
| 426 | | - |
|---|
| 427 | | - if (!area->name || area->parent < 0) |
|---|
| 429 | + if (area->parent < 0) |
|---|
| 428 | 430 | continue; |
|---|
| 429 | 431 | |
|---|
| 430 | 432 | error = pm_genpd_add_subdomain(domains->domains[area->parent], |
|---|
| 431 | | - domains->domains[area->isr_bit]); |
|---|
| 432 | | - if (error) |
|---|
| 433 | + &pd->genpd); |
|---|
| 434 | + if (error) { |
|---|
| 433 | 435 | pr_warn("Failed to add PM subdomain %s to parent %u\n", |
|---|
| 434 | 436 | area->name, area->parent); |
|---|
| 437 | + goto out_put; |
|---|
| 438 | + } |
|---|
| 435 | 439 | } |
|---|
| 436 | 440 | |
|---|
| 437 | 441 | error = of_genpd_add_provider_onecell(np, &domains->onecell_data); |
|---|
| .. | .. |
|---|
| 473 | 477 | if (!(pd->flags & PD_CPU) || pd->ch.chan_bit != idx) |
|---|
| 474 | 478 | continue; |
|---|
| 475 | 479 | |
|---|
| 476 | | - return on ? rcar_sysc_power_up(&pd->ch) |
|---|
| 477 | | - : rcar_sysc_power_down(&pd->ch); |
|---|
| 480 | + return rcar_sysc_power(&pd->ch, on); |
|---|
| 478 | 481 | } |
|---|
| 479 | 482 | |
|---|
| 480 | 483 | return -ENOENT; |
|---|