Kuninori Morimoto | 41c4567 | 2018-09-07 02:04:19 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Magnus Damm | a6557eb | 2014-01-15 16:43:08 +0900 | [diff] [blame] | 2 | /* |
| 3 | * R-Car SYSC Power management support |
| 4 | * |
| 5 | * Copyright (C) 2014 Magnus Damm |
Geert Uytterhoeven | afa6f53 | 2017-03-31 11:01:55 +0200 | [diff] [blame] | 6 | * Copyright (C) 2015-2017 Glider bvba |
Magnus Damm | a6557eb | 2014-01-15 16:43:08 +0900 | [diff] [blame] | 7 | */ |
| 8 | |
Geert Uytterhoeven | 1c8c77f | 2016-04-20 14:02:40 +0200 | [diff] [blame] | 9 | #include <linux/clk/renesas.h> |
Magnus Damm | a6557eb | 2014-01-15 16:43:08 +0900 | [diff] [blame] | 10 | #include <linux/delay.h> |
| 11 | #include <linux/err.h> |
| 12 | #include <linux/mm.h> |
Geert Uytterhoeven | dcc09fd | 2016-04-20 14:02:38 +0200 | [diff] [blame] | 13 | #include <linux/of_address.h> |
| 14 | #include <linux/pm_domain.h> |
| 15 | #include <linux/slab.h> |
Magnus Damm | a6557eb | 2014-01-15 16:43:08 +0900 | [diff] [blame] | 16 | #include <linux/spinlock.h> |
Dan Williams | 2584cf8 | 2015-08-10 23:07:05 -0400 | [diff] [blame] | 17 | #include <linux/io.h> |
Geert Uytterhoeven | 56d6fb1 | 2021-01-25 15:26:06 +0100 | [diff] [blame] | 18 | #include <linux/iopoll.h> |
Geert Uytterhoeven | be32bcb | 2016-04-20 14:02:36 +0200 | [diff] [blame] | 19 | #include <linux/soc/renesas/rcar-sysc.h> |
Magnus Damm | a6557eb | 2014-01-15 16:43:08 +0900 | [diff] [blame] | 20 | |
Geert Uytterhoeven | dcc09fd | 2016-04-20 14:02:38 +0200 | [diff] [blame] | 21 | #include "rcar-sysc.h" |
| 22 | |
Geert Uytterhoeven | 577d104 | 2015-06-04 20:22:27 +0200 | [diff] [blame] | 23 | /* SYSC Common */ |
| 24 | #define SYSCSR 0x00 /* SYSC Status Register */ |
| 25 | #define SYSCISR 0x04 /* Interrupt Status Register */ |
| 26 | #define SYSCISCR 0x08 /* Interrupt Status Clear Register */ |
| 27 | #define SYSCIER 0x0c /* Interrupt Enable Register */ |
| 28 | #define SYSCIMR 0x10 /* Interrupt Mask Register */ |
Magnus Damm | a6557eb | 2014-01-15 16:43:08 +0900 | [diff] [blame] | 29 | |
Geert Uytterhoeven | 577d104 | 2015-06-04 20:22:27 +0200 | [diff] [blame] | 30 | /* SYSC Status Register */ |
| 31 | #define SYSCSR_PONENB 1 /* Ready for power resume requests */ |
| 32 | #define SYSCSR_POFFENB 0 /* Ready for power shutoff requests */ |
Magnus Damm | a6557eb | 2014-01-15 16:43:08 +0900 | [diff] [blame] | 33 | |
Geert Uytterhoeven | 577d104 | 2015-06-04 20:22:27 +0200 | [diff] [blame] | 34 | /* |
| 35 | * Power Control Register Offsets inside the register block for each domain |
| 36 | * Note: The "CR" registers for ARM cores exist on H1 only |
Geert Uytterhoeven | dcc09fd | 2016-04-20 14:02:38 +0200 | [diff] [blame] | 37 | * Use WFI to power off, CPG/APMU to resume ARM cores on R-Car Gen2 |
| 38 | * Use PSCI on R-Car Gen3 |
Geert Uytterhoeven | 577d104 | 2015-06-04 20:22:27 +0200 | [diff] [blame] | 39 | */ |
| 40 | #define PWRSR_OFFS 0x00 /* Power Status Register */ |
| 41 | #define PWROFFCR_OFFS 0x04 /* Power Shutoff Control Register */ |
| 42 | #define PWROFFSR_OFFS 0x08 /* Power Shutoff Status Register */ |
| 43 | #define PWRONCR_OFFS 0x0c /* Power Resume Control Register */ |
| 44 | #define PWRONSR_OFFS 0x10 /* Power Resume Status Register */ |
| 45 | #define PWRER_OFFS 0x14 /* Power Shutoff/Resume Error */ |
Magnus Damm | a6557eb | 2014-01-15 16:43:08 +0900 | [diff] [blame] | 46 | |
Geert Uytterhoeven | 577d104 | 2015-06-04 20:22:27 +0200 | [diff] [blame] | 47 | |
Geert Uytterhoeven | 56d6fb1 | 2021-01-25 15:26:06 +0100 | [diff] [blame] | 48 | #define SYSCSR_TIMEOUT 100 |
Geert Uytterhoeven | 577d104 | 2015-06-04 20:22:27 +0200 | [diff] [blame] | 49 | #define SYSCSR_DELAY_US 1 |
| 50 | |
Geert Uytterhoeven | 2f575fc | 2015-06-04 20:22:29 +0200 | [diff] [blame] | 51 | #define PWRER_RETRIES 100 |
| 52 | #define PWRER_DELAY_US 1 |
| 53 | |
Geert Uytterhoeven | 56d6fb1 | 2021-01-25 15:26:06 +0100 | [diff] [blame] | 54 | #define SYSCISR_TIMEOUT 1000 |
Geert Uytterhoeven | 577d104 | 2015-06-04 20:22:27 +0200 | [diff] [blame] | 55 | #define SYSCISR_DELAY_US 1 |
Magnus Damm | a6557eb | 2014-01-15 16:43:08 +0900 | [diff] [blame] | 56 | |
Geert Uytterhoeven | dcc09fd | 2016-04-20 14:02:38 +0200 | [diff] [blame] | 57 | #define RCAR_PD_ALWAYS_ON 32 /* Always-on power area */ |
| 58 | |
Geert Uytterhoeven | 7e8a50d | 2018-05-30 17:25:16 +0200 | [diff] [blame] | 59 | struct rcar_sysc_ch { |
| 60 | u16 chan_offs; |
| 61 | u8 chan_bit; |
| 62 | u8 isr_bit; |
| 63 | }; |
| 64 | |
Magnus Damm | c4ca5d8 | 2014-02-24 14:52:12 +0900 | [diff] [blame] | 65 | static void __iomem *rcar_sysc_base; |
Magnus Damm | a6557eb | 2014-01-15 16:43:08 +0900 | [diff] [blame] | 66 | static DEFINE_SPINLOCK(rcar_sysc_lock); /* SMP CPUs + I/O devices */ |
Geert Uytterhoeven | 44b5100 | 2019-08-28 13:36:12 +0200 | [diff] [blame] | 67 | static u32 rcar_sysc_extmask_offs, rcar_sysc_extmask_val; |
Magnus Damm | a6557eb | 2014-01-15 16:43:08 +0900 | [diff] [blame] | 68 | |
Geert Uytterhoeven | bcb8243 | 2015-06-04 20:22:32 +0200 | [diff] [blame] | 69 | static int rcar_sysc_pwr_on_off(const struct rcar_sysc_ch *sysc_ch, bool on) |
Magnus Damm | a6557eb | 2014-01-15 16:43:08 +0900 | [diff] [blame] | 70 | { |
Geert Uytterhoeven | bcb8243 | 2015-06-04 20:22:32 +0200 | [diff] [blame] | 71 | unsigned int sr_bit, reg_offs; |
Geert Uytterhoeven | 56d6fb1 | 2021-01-25 15:26:06 +0100 | [diff] [blame] | 72 | u32 val; |
| 73 | int ret; |
Magnus Damm | a6557eb | 2014-01-15 16:43:08 +0900 | [diff] [blame] | 74 | |
Geert Uytterhoeven | bcb8243 | 2015-06-04 20:22:32 +0200 | [diff] [blame] | 75 | if (on) { |
| 76 | sr_bit = SYSCSR_PONENB; |
| 77 | reg_offs = PWRONCR_OFFS; |
| 78 | } else { |
| 79 | sr_bit = SYSCSR_POFFENB; |
| 80 | reg_offs = PWROFFCR_OFFS; |
| 81 | } |
| 82 | |
Geert Uytterhoeven | 577d104 | 2015-06-04 20:22:27 +0200 | [diff] [blame] | 83 | /* Wait until SYSC is ready to accept a power request */ |
Geert Uytterhoeven | 56d6fb1 | 2021-01-25 15:26:06 +0100 | [diff] [blame] | 84 | ret = readl_poll_timeout_atomic(rcar_sysc_base + SYSCSR, val, |
| 85 | val & BIT(sr_bit), SYSCSR_DELAY_US, |
| 86 | SYSCSR_TIMEOUT); |
| 87 | if (ret) |
Magnus Damm | a6557eb | 2014-01-15 16:43:08 +0900 | [diff] [blame] | 88 | return -EAGAIN; |
| 89 | |
Geert Uytterhoeven | 577d104 | 2015-06-04 20:22:27 +0200 | [diff] [blame] | 90 | /* Submit power shutoff or power resume request */ |
Geert Uytterhoeven | 21437c5 | 2015-06-04 20:22:31 +0200 | [diff] [blame] | 91 | iowrite32(BIT(sysc_ch->chan_bit), |
Magnus Damm | a6557eb | 2014-01-15 16:43:08 +0900 | [diff] [blame] | 92 | rcar_sysc_base + sysc_ch->chan_offs + reg_offs); |
| 93 | |
| 94 | return 0; |
| 95 | } |
| 96 | |
Geert Uytterhoeven | bcb8243 | 2015-06-04 20:22:32 +0200 | [diff] [blame] | 97 | static int rcar_sysc_power(const struct rcar_sysc_ch *sysc_ch, bool on) |
Magnus Damm | a6557eb | 2014-01-15 16:43:08 +0900 | [diff] [blame] | 98 | { |
Geert Uytterhoeven | 21437c5 | 2015-06-04 20:22:31 +0200 | [diff] [blame] | 99 | unsigned int isr_mask = BIT(sysc_ch->isr_bit); |
| 100 | unsigned int chan_mask = BIT(sysc_ch->chan_bit); |
Geert Uytterhoeven | 56d6fb1 | 2021-01-25 15:26:06 +0100 | [diff] [blame] | 101 | unsigned int status, k; |
Magnus Damm | a6557eb | 2014-01-15 16:43:08 +0900 | [diff] [blame] | 102 | unsigned long flags; |
Geert Uytterhoeven | 56d6fb1 | 2021-01-25 15:26:06 +0100 | [diff] [blame] | 103 | int ret; |
Magnus Damm | a6557eb | 2014-01-15 16:43:08 +0900 | [diff] [blame] | 104 | |
| 105 | spin_lock_irqsave(&rcar_sysc_lock, flags); |
| 106 | |
Geert Uytterhoeven | 7fc4650 | 2018-12-05 16:39:45 +0100 | [diff] [blame] | 107 | /* |
Geert Uytterhoeven | 44b5100 | 2019-08-28 13:36:12 +0200 | [diff] [blame] | 108 | * Mask external power requests for CPU or 3DG domains |
| 109 | */ |
| 110 | if (rcar_sysc_extmask_val) { |
| 111 | iowrite32(rcar_sysc_extmask_val, |
| 112 | rcar_sysc_base + rcar_sysc_extmask_offs); |
| 113 | } |
| 114 | |
| 115 | /* |
Geert Uytterhoeven | 7fc4650 | 2018-12-05 16:39:45 +0100 | [diff] [blame] | 116 | * The interrupt source needs to be enabled, but masked, to prevent the |
| 117 | * CPU from receiving it. |
| 118 | */ |
| 119 | iowrite32(ioread32(rcar_sysc_base + SYSCIMR) | isr_mask, |
| 120 | rcar_sysc_base + SYSCIMR); |
| 121 | iowrite32(ioread32(rcar_sysc_base + SYSCIER) | isr_mask, |
| 122 | rcar_sysc_base + SYSCIER); |
| 123 | |
Magnus Damm | a6557eb | 2014-01-15 16:43:08 +0900 | [diff] [blame] | 124 | iowrite32(isr_mask, rcar_sysc_base + SYSCISCR); |
| 125 | |
Geert Uytterhoeven | 577d104 | 2015-06-04 20:22:27 +0200 | [diff] [blame] | 126 | /* Submit power shutoff or resume request until it was accepted */ |
Geert Uytterhoeven | 2f575fc | 2015-06-04 20:22:29 +0200 | [diff] [blame] | 127 | for (k = 0; k < PWRER_RETRIES; k++) { |
Geert Uytterhoeven | bcb8243 | 2015-06-04 20:22:32 +0200 | [diff] [blame] | 128 | ret = rcar_sysc_pwr_on_off(sysc_ch, on); |
Magnus Damm | a6557eb | 2014-01-15 16:43:08 +0900 | [diff] [blame] | 129 | if (ret) |
| 130 | goto out; |
| 131 | |
| 132 | status = ioread32(rcar_sysc_base + |
| 133 | sysc_ch->chan_offs + PWRER_OFFS); |
Geert Uytterhoeven | 2f575fc | 2015-06-04 20:22:29 +0200 | [diff] [blame] | 134 | if (!(status & chan_mask)) |
| 135 | break; |
| 136 | |
| 137 | udelay(PWRER_DELAY_US); |
| 138 | } |
| 139 | |
| 140 | if (k == PWRER_RETRIES) { |
| 141 | ret = -EIO; |
| 142 | goto out; |
| 143 | } |
Magnus Damm | a6557eb | 2014-01-15 16:43:08 +0900 | [diff] [blame] | 144 | |
Geert Uytterhoeven | 577d104 | 2015-06-04 20:22:27 +0200 | [diff] [blame] | 145 | /* Wait until the power shutoff or resume request has completed * */ |
Geert Uytterhoeven | 56d6fb1 | 2021-01-25 15:26:06 +0100 | [diff] [blame] | 146 | ret = readl_poll_timeout_atomic(rcar_sysc_base + SYSCISR, status, |
| 147 | status & isr_mask, SYSCISR_DELAY_US, |
| 148 | SYSCISR_TIMEOUT); |
| 149 | if (ret) |
Magnus Damm | a6557eb | 2014-01-15 16:43:08 +0900 | [diff] [blame] | 150 | ret = -EIO; |
| 151 | |
| 152 | iowrite32(isr_mask, rcar_sysc_base + SYSCISCR); |
| 153 | |
| 154 | out: |
Geert Uytterhoeven | 44b5100 | 2019-08-28 13:36:12 +0200 | [diff] [blame] | 155 | if (rcar_sysc_extmask_val) |
| 156 | iowrite32(0, rcar_sysc_base + rcar_sysc_extmask_offs); |
| 157 | |
Magnus Damm | a6557eb | 2014-01-15 16:43:08 +0900 | [diff] [blame] | 158 | spin_unlock_irqrestore(&rcar_sysc_lock, flags); |
| 159 | |
Geert Uytterhoeven | 68667ce | 2016-04-20 14:02:37 +0200 | [diff] [blame] | 160 | pr_debug("sysc power %s domain %d: %08x -> %d\n", on ? "on" : "off", |
Magnus Damm | a6557eb | 2014-01-15 16:43:08 +0900 | [diff] [blame] | 161 | sysc_ch->isr_bit, ioread32(rcar_sysc_base + SYSCISR), ret); |
| 162 | return ret; |
| 163 | } |
| 164 | |
Geert Uytterhoeven | 2f024ce | 2016-04-20 14:02:39 +0200 | [diff] [blame] | 165 | static bool rcar_sysc_power_is_off(const struct rcar_sysc_ch *sysc_ch) |
Magnus Damm | a6557eb | 2014-01-15 16:43:08 +0900 | [diff] [blame] | 166 | { |
| 167 | unsigned int st; |
| 168 | |
| 169 | st = ioread32(rcar_sysc_base + sysc_ch->chan_offs + PWRSR_OFFS); |
Geert Uytterhoeven | 21437c5 | 2015-06-04 20:22:31 +0200 | [diff] [blame] | 170 | if (st & BIT(sysc_ch->chan_bit)) |
Magnus Damm | a6557eb | 2014-01-15 16:43:08 +0900 | [diff] [blame] | 171 | return true; |
| 172 | |
| 173 | return false; |
| 174 | } |
| 175 | |
Geert Uytterhoeven | dcc09fd | 2016-04-20 14:02:38 +0200 | [diff] [blame] | 176 | struct rcar_sysc_pd { |
| 177 | struct generic_pm_domain genpd; |
| 178 | struct rcar_sysc_ch ch; |
| 179 | unsigned int flags; |
Geert Uytterhoeven | 0ed0eb0 | 2019-06-17 14:00:56 +0200 | [diff] [blame] | 180 | char name[]; |
Geert Uytterhoeven | dcc09fd | 2016-04-20 14:02:38 +0200 | [diff] [blame] | 181 | }; |
| 182 | |
| 183 | static inline struct rcar_sysc_pd *to_rcar_pd(struct generic_pm_domain *d) |
| 184 | { |
| 185 | return container_of(d, struct rcar_sysc_pd, genpd); |
| 186 | } |
| 187 | |
| 188 | static int rcar_sysc_pd_power_off(struct generic_pm_domain *genpd) |
| 189 | { |
| 190 | struct rcar_sysc_pd *pd = to_rcar_pd(genpd); |
| 191 | |
| 192 | pr_debug("%s: %s\n", __func__, genpd->name); |
Geert Uytterhoeven | 319c840 | 2018-12-05 16:39:43 +0100 | [diff] [blame] | 193 | return rcar_sysc_power(&pd->ch, false); |
Geert Uytterhoeven | dcc09fd | 2016-04-20 14:02:38 +0200 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | static int rcar_sysc_pd_power_on(struct generic_pm_domain *genpd) |
| 197 | { |
| 198 | struct rcar_sysc_pd *pd = to_rcar_pd(genpd); |
| 199 | |
| 200 | pr_debug("%s: %s\n", __func__, genpd->name); |
Geert Uytterhoeven | 319c840 | 2018-12-05 16:39:43 +0100 | [diff] [blame] | 201 | return rcar_sysc_power(&pd->ch, true); |
Geert Uytterhoeven | dcc09fd | 2016-04-20 14:02:38 +0200 | [diff] [blame] | 202 | } |
| 203 | |
Geert Uytterhoeven | 1c8c77f | 2016-04-20 14:02:40 +0200 | [diff] [blame] | 204 | static bool has_cpg_mstp; |
| 205 | |
Geert Uytterhoeven | 977d5ba | 2018-06-05 17:05:15 +0200 | [diff] [blame] | 206 | static int __init rcar_sysc_pd_setup(struct rcar_sysc_pd *pd) |
Geert Uytterhoeven | dcc09fd | 2016-04-20 14:02:38 +0200 | [diff] [blame] | 207 | { |
| 208 | struct generic_pm_domain *genpd = &pd->genpd; |
| 209 | const char *name = pd->genpd.name; |
Geert Uytterhoeven | 977d5ba | 2018-06-05 17:05:15 +0200 | [diff] [blame] | 210 | int error; |
Geert Uytterhoeven | dcc09fd | 2016-04-20 14:02:38 +0200 | [diff] [blame] | 211 | |
| 212 | if (pd->flags & PD_CPU) { |
| 213 | /* |
| 214 | * This domain contains a CPU core and therefore it should |
| 215 | * only be turned off if the CPU is not in use. |
| 216 | */ |
| 217 | pr_debug("PM domain %s contains %s\n", name, "CPU"); |
Geert Uytterhoeven | 980532a | 2017-06-12 11:23:45 +0200 | [diff] [blame] | 218 | genpd->flags |= GENPD_FLAG_ALWAYS_ON; |
Geert Uytterhoeven | dcc09fd | 2016-04-20 14:02:38 +0200 | [diff] [blame] | 219 | } else if (pd->flags & PD_SCU) { |
| 220 | /* |
| 221 | * This domain contains an SCU and cache-controller, and |
| 222 | * therefore it should only be turned off if the CPU cores are |
| 223 | * not in use. |
| 224 | */ |
| 225 | pr_debug("PM domain %s contains %s\n", name, "SCU"); |
Geert Uytterhoeven | 980532a | 2017-06-12 11:23:45 +0200 | [diff] [blame] | 226 | genpd->flags |= GENPD_FLAG_ALWAYS_ON; |
Geert Uytterhoeven | dcc09fd | 2016-04-20 14:02:38 +0200 | [diff] [blame] | 227 | } else if (pd->flags & PD_NO_CR) { |
| 228 | /* |
| 229 | * This domain cannot be turned off. |
| 230 | */ |
Geert Uytterhoeven | 980532a | 2017-06-12 11:23:45 +0200 | [diff] [blame] | 231 | genpd->flags |= GENPD_FLAG_ALWAYS_ON; |
Geert Uytterhoeven | dcc09fd | 2016-04-20 14:02:38 +0200 | [diff] [blame] | 232 | } |
| 233 | |
Geert Uytterhoeven | 1c8c77f | 2016-04-20 14:02:40 +0200 | [diff] [blame] | 234 | if (!(pd->flags & (PD_CPU | PD_SCU))) { |
| 235 | /* Enable Clock Domain for I/O devices */ |
Geert Uytterhoeven | 91c719f | 2017-11-09 14:27:02 +0100 | [diff] [blame] | 236 | genpd->flags |= GENPD_FLAG_PM_CLK | GENPD_FLAG_ACTIVE_WAKEUP; |
Geert Uytterhoeven | 1c8c77f | 2016-04-20 14:02:40 +0200 | [diff] [blame] | 237 | if (has_cpg_mstp) { |
| 238 | genpd->attach_dev = cpg_mstp_attach_dev; |
| 239 | genpd->detach_dev = cpg_mstp_detach_dev; |
| 240 | } else { |
| 241 | genpd->attach_dev = cpg_mssr_attach_dev; |
| 242 | genpd->detach_dev = cpg_mssr_detach_dev; |
| 243 | } |
| 244 | } |
| 245 | |
Geert Uytterhoeven | dcc09fd | 2016-04-20 14:02:38 +0200 | [diff] [blame] | 246 | genpd->power_off = rcar_sysc_pd_power_off; |
| 247 | genpd->power_on = rcar_sysc_pd_power_on; |
| 248 | |
| 249 | if (pd->flags & (PD_CPU | PD_NO_CR)) { |
| 250 | /* Skip CPUs (handled by SMP code) and areas without control */ |
| 251 | pr_debug("%s: Not touching %s\n", __func__, genpd->name); |
| 252 | goto finalize; |
| 253 | } |
| 254 | |
| 255 | if (!rcar_sysc_power_is_off(&pd->ch)) { |
| 256 | pr_debug("%s: %s is already powered\n", __func__, genpd->name); |
| 257 | goto finalize; |
| 258 | } |
| 259 | |
Geert Uytterhoeven | 319c840 | 2018-12-05 16:39:43 +0100 | [diff] [blame] | 260 | rcar_sysc_power(&pd->ch, true); |
Geert Uytterhoeven | dcc09fd | 2016-04-20 14:02:38 +0200 | [diff] [blame] | 261 | |
| 262 | finalize: |
Geert Uytterhoeven | e0e1df6 | 2019-08-09 16:14:32 +0200 | [diff] [blame] | 263 | error = pm_genpd_init(genpd, &simple_qos_governor, false); |
Geert Uytterhoeven | 977d5ba | 2018-06-05 17:05:15 +0200 | [diff] [blame] | 264 | if (error) |
| 265 | pr_err("Failed to init PM domain %s: %d\n", name, error); |
| 266 | |
| 267 | return error; |
Geert Uytterhoeven | dcc09fd | 2016-04-20 14:02:38 +0200 | [diff] [blame] | 268 | } |
| 269 | |
Geert Uytterhoeven | 707aa45 | 2017-12-19 16:54:44 +0100 | [diff] [blame] | 270 | static const struct of_device_id rcar_sysc_matches[] __initconst = { |
Lad Prabhakar | 5b9fa9c | 2020-04-23 22:40:43 +0100 | [diff] [blame] | 271 | #ifdef CONFIG_SYSC_R8A7742 |
| 272 | { .compatible = "renesas,r8a7742-sysc", .data = &r8a7742_sysc_info }, |
| 273 | #endif |
Geert Uytterhoeven | 8be381a | 2017-05-19 10:35:10 +0200 | [diff] [blame] | 274 | #ifdef CONFIG_SYSC_R8A7743 |
Sergei Shtylyov | 603311b | 2016-10-05 14:35:01 -0700 | [diff] [blame] | 275 | { .compatible = "renesas,r8a7743-sysc", .data = &r8a7743_sysc_info }, |
Biju Das | c3299eb | 2018-09-11 11:12:44 +0100 | [diff] [blame] | 276 | /* RZ/G1N is identical to RZ/G2M w.r.t. power domains. */ |
| 277 | { .compatible = "renesas,r8a7744-sysc", .data = &r8a7743_sysc_info }, |
Sergei Shtylyov | 603311b | 2016-10-05 14:35:01 -0700 | [diff] [blame] | 278 | #endif |
Geert Uytterhoeven | 8be381a | 2017-05-19 10:35:10 +0200 | [diff] [blame] | 279 | #ifdef CONFIG_SYSC_R8A7745 |
Sergei Shtylyov | 141723e | 2016-11-05 00:46:13 +0300 | [diff] [blame] | 280 | { .compatible = "renesas,r8a7745-sysc", .data = &r8a7745_sysc_info }, |
| 281 | #endif |
Biju Das | 964f7c0 | 2018-03-28 20:26:09 +0100 | [diff] [blame] | 282 | #ifdef CONFIG_SYSC_R8A77470 |
| 283 | { .compatible = "renesas,r8a77470-sysc", .data = &r8a77470_sysc_info }, |
| 284 | #endif |
Biju Das | 7f0e99c | 2018-08-02 15:53:19 +0100 | [diff] [blame] | 285 | #ifdef CONFIG_SYSC_R8A774A1 |
| 286 | { .compatible = "renesas,r8a774a1-sysc", .data = &r8a774a1_sysc_info }, |
| 287 | #endif |
Biju Das | 6655c56 | 2019-09-23 08:29:40 +0100 | [diff] [blame] | 288 | #ifdef CONFIG_SYSC_R8A774B1 |
| 289 | { .compatible = "renesas,r8a774b1-sysc", .data = &r8a774b1_sysc_info }, |
| 290 | #endif |
Fabrizio Castro | f37d211 | 2018-09-10 15:41:27 +0100 | [diff] [blame] | 291 | #ifdef CONFIG_SYSC_R8A774C0 |
| 292 | { .compatible = "renesas,r8a774c0-sysc", .data = &r8a774c0_sysc_info }, |
| 293 | #endif |
Marian-Cristian Rotariu | f446ade | 2020-07-07 17:18:05 +0100 | [diff] [blame] | 294 | #ifdef CONFIG_SYSC_R8A774E1 |
| 295 | { .compatible = "renesas,r8a774e1-sysc", .data = &r8a774e1_sysc_info }, |
| 296 | #endif |
Geert Uytterhoeven | 8be381a | 2017-05-19 10:35:10 +0200 | [diff] [blame] | 297 | #ifdef CONFIG_SYSC_R8A7779 |
Geert Uytterhoeven | 9b83ea1 | 2016-04-20 14:02:41 +0200 | [diff] [blame] | 298 | { .compatible = "renesas,r8a7779-sysc", .data = &r8a7779_sysc_info }, |
| 299 | #endif |
Geert Uytterhoeven | 8be381a | 2017-05-19 10:35:10 +0200 | [diff] [blame] | 300 | #ifdef CONFIG_SYSC_R8A7790 |
Geert Uytterhoeven | ad7c9db | 2016-04-20 14:02:42 +0200 | [diff] [blame] | 301 | { .compatible = "renesas,r8a7790-sysc", .data = &r8a7790_sysc_info }, |
| 302 | #endif |
Geert Uytterhoeven | 8be381a | 2017-05-19 10:35:10 +0200 | [diff] [blame] | 303 | #ifdef CONFIG_SYSC_R8A7791 |
Geert Uytterhoeven | c5fbb3c | 2016-04-20 14:02:43 +0200 | [diff] [blame] | 304 | { .compatible = "renesas,r8a7791-sysc", .data = &r8a7791_sysc_info }, |
Geert Uytterhoeven | a247eb9 | 2016-04-20 14:02:44 +0200 | [diff] [blame] | 305 | /* R-Car M2-N is identical to R-Car M2-W w.r.t. power domains. */ |
| 306 | { .compatible = "renesas,r8a7793-sysc", .data = &r8a7791_sysc_info }, |
| 307 | #endif |
Geert Uytterhoeven | 8be381a | 2017-05-19 10:35:10 +0200 | [diff] [blame] | 308 | #ifdef CONFIG_SYSC_R8A7792 |
| 309 | { .compatible = "renesas,r8a7792-sysc", .data = &r8a7792_sysc_info }, |
| 310 | #endif |
| 311 | #ifdef CONFIG_SYSC_R8A7794 |
Geert Uytterhoeven | 9af1dbc | 2016-04-20 14:02:45 +0200 | [diff] [blame] | 312 | { .compatible = "renesas,r8a7794-sysc", .data = &r8a7794_sysc_info }, |
| 313 | #endif |
Geert Uytterhoeven | 8be381a | 2017-05-19 10:35:10 +0200 | [diff] [blame] | 314 | #ifdef CONFIG_SYSC_R8A7795 |
Geert Uytterhoeven | 23f1e2e | 2016-04-20 14:02:46 +0200 | [diff] [blame] | 315 | { .compatible = "renesas,r8a7795-sysc", .data = &r8a7795_sysc_info }, |
| 316 | #endif |
Geert Uytterhoeven | f79edb1 | 2019-10-23 14:33:32 +0200 | [diff] [blame] | 317 | #ifdef CONFIG_SYSC_R8A77960 |
| 318 | { .compatible = "renesas,r8a7796-sysc", .data = &r8a77960_sysc_info }, |
Geert Uytterhoeven | e0c98b9 | 2016-05-30 19:05:11 +0200 | [diff] [blame] | 319 | #endif |
Geert Uytterhoeven | bdde3d3 | 2019-10-23 14:33:37 +0200 | [diff] [blame] | 320 | #ifdef CONFIG_SYSC_R8A77961 |
| 321 | { .compatible = "renesas,r8a77961-sysc", .data = &r8a77961_sysc_info }, |
| 322 | #endif |
Jacopo Mondi | a527709 | 2018-02-20 16:12:06 +0100 | [diff] [blame] | 323 | #ifdef CONFIG_SYSC_R8A77965 |
| 324 | { .compatible = "renesas,r8a77965-sysc", .data = &r8a77965_sysc_info }, |
| 325 | #endif |
Sergei Shtylyov | bab9b2a | 2017-09-12 23:37:20 +0300 | [diff] [blame] | 326 | #ifdef CONFIG_SYSC_R8A77970 |
| 327 | { .compatible = "renesas,r8a77970-sysc", .data = &r8a77970_sysc_info }, |
| 328 | #endif |
Sergei Shtylyov | 41d6d8b | 2018-02-16 21:28:02 +0300 | [diff] [blame] | 329 | #ifdef CONFIG_SYSC_R8A77980 |
| 330 | { .compatible = "renesas,r8a77980-sysc", .data = &r8a77980_sysc_info }, |
| 331 | #endif |
Takeshi Kihara | 44b12d4 | 2018-05-15 21:07:38 +0900 | [diff] [blame] | 332 | #ifdef CONFIG_SYSC_R8A77990 |
| 333 | { .compatible = "renesas,r8a77990-sysc", .data = &r8a77990_sysc_info }, |
| 334 | #endif |
Geert Uytterhoeven | eed17c4 | 2017-07-20 14:34:53 +0200 | [diff] [blame] | 335 | #ifdef CONFIG_SYSC_R8A77995 |
| 336 | { .compatible = "renesas,r8a77995-sysc", .data = &r8a77995_sysc_info }, |
| 337 | #endif |
Geert Uytterhoeven | dcc09fd | 2016-04-20 14:02:38 +0200 | [diff] [blame] | 338 | { /* sentinel */ } |
| 339 | }; |
| 340 | |
| 341 | struct rcar_pm_domains { |
| 342 | struct genpd_onecell_data onecell_data; |
| 343 | struct generic_pm_domain *domains[RCAR_PD_ALWAYS_ON + 1]; |
| 344 | }; |
| 345 | |
Geert Uytterhoeven | f2b1d2f | 2018-05-30 17:25:13 +0200 | [diff] [blame] | 346 | static struct genpd_onecell_data *rcar_sysc_onecell_data; |
| 347 | |
Geert Uytterhoeven | dcc09fd | 2016-04-20 14:02:38 +0200 | [diff] [blame] | 348 | static int __init rcar_sysc_pd_init(void) |
| 349 | { |
| 350 | const struct rcar_sysc_info *info; |
| 351 | const struct of_device_id *match; |
| 352 | struct rcar_pm_domains *domains; |
| 353 | struct device_node *np; |
Geert Uytterhoeven | dcc09fd | 2016-04-20 14:02:38 +0200 | [diff] [blame] | 354 | void __iomem *base; |
| 355 | unsigned int i; |
| 356 | int error; |
| 357 | |
| 358 | np = of_find_matching_node_and_match(NULL, rcar_sysc_matches, &match); |
| 359 | if (!np) |
| 360 | return -ENODEV; |
| 361 | |
| 362 | info = match->data; |
| 363 | |
Geert Uytterhoeven | afa6f53 | 2017-03-31 11:01:55 +0200 | [diff] [blame] | 364 | if (info->init) { |
| 365 | error = info->init(); |
| 366 | if (error) |
Nishka Dasgupta | da51ced | 2019-08-15 11:43:54 +0530 | [diff] [blame] | 367 | goto out_put; |
Geert Uytterhoeven | afa6f53 | 2017-03-31 11:01:55 +0200 | [diff] [blame] | 368 | } |
| 369 | |
Geert Uytterhoeven | 1c8c77f | 2016-04-20 14:02:40 +0200 | [diff] [blame] | 370 | has_cpg_mstp = of_find_compatible_node(NULL, NULL, |
| 371 | "renesas,cpg-mstp-clocks"); |
| 372 | |
Geert Uytterhoeven | dcc09fd | 2016-04-20 14:02:38 +0200 | [diff] [blame] | 373 | base = of_iomap(np, 0); |
| 374 | if (!base) { |
Rob Herring | 37c342c | 2017-07-18 16:43:29 -0500 | [diff] [blame] | 375 | pr_warn("%pOF: Cannot map regs\n", np); |
Geert Uytterhoeven | dcc09fd | 2016-04-20 14:02:38 +0200 | [diff] [blame] | 376 | error = -ENOMEM; |
| 377 | goto out_put; |
| 378 | } |
| 379 | |
| 380 | rcar_sysc_base = base; |
| 381 | |
Geert Uytterhoeven | 44b5100 | 2019-08-28 13:36:12 +0200 | [diff] [blame] | 382 | /* Optional External Request Mask Register */ |
| 383 | rcar_sysc_extmask_offs = info->extmask_offs; |
| 384 | rcar_sysc_extmask_val = info->extmask_val; |
| 385 | |
Geert Uytterhoeven | dcc09fd | 2016-04-20 14:02:38 +0200 | [diff] [blame] | 386 | domains = kzalloc(sizeof(*domains), GFP_KERNEL); |
| 387 | if (!domains) { |
| 388 | error = -ENOMEM; |
| 389 | goto out_put; |
| 390 | } |
| 391 | |
| 392 | domains->onecell_data.domains = domains->domains; |
| 393 | domains->onecell_data.num_domains = ARRAY_SIZE(domains->domains); |
Geert Uytterhoeven | f2b1d2f | 2018-05-30 17:25:13 +0200 | [diff] [blame] | 394 | rcar_sysc_onecell_data = &domains->onecell_data; |
Geert Uytterhoeven | dcc09fd | 2016-04-20 14:02:38 +0200 | [diff] [blame] | 395 | |
Geert Uytterhoeven | dcc09fd | 2016-04-20 14:02:38 +0200 | [diff] [blame] | 396 | for (i = 0; i < info->num_areas; i++) { |
| 397 | const struct rcar_sysc_area *area = &info->areas[i]; |
| 398 | struct rcar_sysc_pd *pd; |
Len Baker | 148bcca | 2021-08-08 14:50:11 +0200 | [diff] [blame] | 399 | size_t n; |
Geert Uytterhoeven | dcc09fd | 2016-04-20 14:02:38 +0200 | [diff] [blame] | 400 | |
Geert Uytterhoeven | afa6f53 | 2017-03-31 11:01:55 +0200 | [diff] [blame] | 401 | if (!area->name) { |
| 402 | /* Skip NULLified area */ |
| 403 | continue; |
| 404 | } |
| 405 | |
Len Baker | 148bcca | 2021-08-08 14:50:11 +0200 | [diff] [blame] | 406 | n = strlen(area->name) + 1; |
| 407 | pd = kzalloc(sizeof(*pd) + n, GFP_KERNEL); |
Geert Uytterhoeven | dcc09fd | 2016-04-20 14:02:38 +0200 | [diff] [blame] | 408 | if (!pd) { |
| 409 | error = -ENOMEM; |
| 410 | goto out_put; |
| 411 | } |
| 412 | |
Len Baker | 148bcca | 2021-08-08 14:50:11 +0200 | [diff] [blame] | 413 | memcpy(pd->name, area->name, n); |
Geert Uytterhoeven | dcc09fd | 2016-04-20 14:02:38 +0200 | [diff] [blame] | 414 | pd->genpd.name = pd->name; |
| 415 | pd->ch.chan_offs = area->chan_offs; |
| 416 | pd->ch.chan_bit = area->chan_bit; |
| 417 | pd->ch.isr_bit = area->isr_bit; |
| 418 | pd->flags = area->flags; |
| 419 | |
Geert Uytterhoeven | 977d5ba | 2018-06-05 17:05:15 +0200 | [diff] [blame] | 420 | error = rcar_sysc_pd_setup(pd); |
| 421 | if (error) |
| 422 | goto out_put; |
Geert Uytterhoeven | dcc09fd | 2016-04-20 14:02:38 +0200 | [diff] [blame] | 423 | |
| 424 | domains->domains[area->isr_bit] = &pd->genpd; |
Geert Uytterhoeven | dcc09fd | 2016-04-20 14:02:38 +0200 | [diff] [blame] | 425 | |
Geert Uytterhoeven | 1585124 | 2018-12-05 16:39:44 +0100 | [diff] [blame] | 426 | if (area->parent < 0) |
Geert Uytterhoeven | 977d5ba | 2018-06-05 17:05:15 +0200 | [diff] [blame] | 427 | continue; |
| 428 | |
| 429 | error = pm_genpd_add_subdomain(domains->domains[area->parent], |
Geert Uytterhoeven | 1585124 | 2018-12-05 16:39:44 +0100 | [diff] [blame] | 430 | &pd->genpd); |
| 431 | if (error) { |
Geert Uytterhoeven | 977d5ba | 2018-06-05 17:05:15 +0200 | [diff] [blame] | 432 | pr_warn("Failed to add PM subdomain %s to parent %u\n", |
| 433 | area->name, area->parent); |
Geert Uytterhoeven | 1585124 | 2018-12-05 16:39:44 +0100 | [diff] [blame] | 434 | goto out_put; |
| 435 | } |
Geert Uytterhoeven | 977d5ba | 2018-06-05 17:05:15 +0200 | [diff] [blame] | 436 | } |
| 437 | |
Geert Uytterhoeven | 1023578 | 2016-06-28 16:10:31 +0200 | [diff] [blame] | 438 | error = of_genpd_add_provider_onecell(np, &domains->onecell_data); |
Geert Uytterhoeven | 2dfc564 | 2021-01-28 09:28:47 +0100 | [diff] [blame] | 439 | if (!error) |
| 440 | of_node_set_flag(np, OF_POPULATED); |
Geert Uytterhoeven | dcc09fd | 2016-04-20 14:02:38 +0200 | [diff] [blame] | 441 | |
| 442 | out_put: |
| 443 | of_node_put(np); |
| 444 | return error; |
| 445 | } |
| 446 | early_initcall(rcar_sysc_pd_init); |
Geert Uytterhoeven | b1e5228 | 2016-06-28 16:10:32 +0200 | [diff] [blame] | 447 | |
Geert Uytterhoeven | afa6f53 | 2017-03-31 11:01:55 +0200 | [diff] [blame] | 448 | void __init rcar_sysc_nullify(struct rcar_sysc_area *areas, |
| 449 | unsigned int num_areas, u8 id) |
| 450 | { |
| 451 | unsigned int i; |
| 452 | |
| 453 | for (i = 0; i < num_areas; i++) |
| 454 | if (areas[i].isr_bit == id) { |
| 455 | areas[i].name = NULL; |
| 456 | return; |
| 457 | } |
| 458 | } |
| 459 | |
Geert Uytterhoeven | f2b1d2f | 2018-05-30 17:25:13 +0200 | [diff] [blame] | 460 | #ifdef CONFIG_ARCH_R8A7779 |
| 461 | static int rcar_sysc_power_cpu(unsigned int idx, bool on) |
Geert Uytterhoeven | b1e5228 | 2016-06-28 16:10:32 +0200 | [diff] [blame] | 462 | { |
Geert Uytterhoeven | f2b1d2f | 2018-05-30 17:25:13 +0200 | [diff] [blame] | 463 | struct generic_pm_domain *genpd; |
| 464 | struct rcar_sysc_pd *pd; |
| 465 | unsigned int i; |
Geert Uytterhoeven | ced4273 | 2016-06-28 16:10:34 +0200 | [diff] [blame] | 466 | |
Geert Uytterhoeven | f2b1d2f | 2018-05-30 17:25:13 +0200 | [diff] [blame] | 467 | if (!rcar_sysc_onecell_data) |
| 468 | return -ENODEV; |
Geert Uytterhoeven | b1e5228 | 2016-06-28 16:10:32 +0200 | [diff] [blame] | 469 | |
Geert Uytterhoeven | f2b1d2f | 2018-05-30 17:25:13 +0200 | [diff] [blame] | 470 | for (i = 0; i < rcar_sysc_onecell_data->num_domains; i++) { |
| 471 | genpd = rcar_sysc_onecell_data->domains[i]; |
| 472 | if (!genpd) |
| 473 | continue; |
Geert Uytterhoeven | 0532399 | 2016-06-28 16:10:33 +0200 | [diff] [blame] | 474 | |
Geert Uytterhoeven | f2b1d2f | 2018-05-30 17:25:13 +0200 | [diff] [blame] | 475 | pd = to_rcar_pd(genpd); |
| 476 | if (!(pd->flags & PD_CPU) || pd->ch.chan_bit != idx) |
| 477 | continue; |
Geert Uytterhoeven | ced4273 | 2016-06-28 16:10:34 +0200 | [diff] [blame] | 478 | |
Geert Uytterhoeven | 319c840 | 2018-12-05 16:39:43 +0100 | [diff] [blame] | 479 | return rcar_sysc_power(&pd->ch, on); |
Geert Uytterhoeven | f2b1d2f | 2018-05-30 17:25:13 +0200 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | return -ENOENT; |
Geert Uytterhoeven | b1e5228 | 2016-06-28 16:10:32 +0200 | [diff] [blame] | 483 | } |
Geert Uytterhoeven | f2b1d2f | 2018-05-30 17:25:13 +0200 | [diff] [blame] | 484 | |
| 485 | int rcar_sysc_power_down_cpu(unsigned int cpu) |
| 486 | { |
| 487 | return rcar_sysc_power_cpu(cpu, false); |
| 488 | } |
| 489 | |
| 490 | int rcar_sysc_power_up_cpu(unsigned int cpu) |
| 491 | { |
| 492 | return rcar_sysc_power_cpu(cpu, true); |
| 493 | } |
| 494 | #endif /* CONFIG_ARCH_R8A7779 */ |