.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
---|
1 | 2 | /* |
---|
2 | 3 | * Renesas Clock Pulse Generator / Module Standby and Software Reset |
---|
3 | 4 | * |
---|
.. | .. |
---|
7 | 8 | * |
---|
8 | 9 | * Copyright (C) 2013 Ideas On Board SPRL |
---|
9 | 10 | * Copyright (C) 2015 Renesas Electronics Corp. |
---|
10 | | - * |
---|
11 | | - * This program is free software; you can redistribute it and/or modify |
---|
12 | | - * it under the terms of the GNU General Public License as published by |
---|
13 | | - * the Free Software Foundation; version 2 of the License. |
---|
14 | 11 | */ |
---|
15 | 12 | |
---|
16 | 13 | #include <linux/clk.h> |
---|
.. | .. |
---|
19 | 16 | #include <linux/delay.h> |
---|
20 | 17 | #include <linux/device.h> |
---|
21 | 18 | #include <linux/init.h> |
---|
| 19 | +#include <linux/io.h> |
---|
22 | 20 | #include <linux/mod_devicetable.h> |
---|
23 | 21 | #include <linux/module.h> |
---|
24 | 22 | #include <linux/of_address.h> |
---|
.. | .. |
---|
59 | 57 | 0x9A0, 0x9A4, 0x9A8, 0x9AC, |
---|
60 | 58 | }; |
---|
61 | 59 | |
---|
62 | | -#define MSTPSR(i) mstpsr[i] |
---|
63 | | - |
---|
| 60 | +static const u16 mstpsr_for_v3u[] = { |
---|
| 61 | + 0x2E00, 0x2E04, 0x2E08, 0x2E0C, 0x2E10, 0x2E14, 0x2E18, 0x2E1C, |
---|
| 62 | + 0x2E20, 0x2E24, 0x2E28, 0x2E2C, 0x2E30, 0x2E34, 0x2E38, |
---|
| 63 | +}; |
---|
64 | 64 | |
---|
65 | 65 | /* |
---|
66 | 66 | * System Module Stop Control Register offsets |
---|
.. | .. |
---|
71 | 71 | 0x990, 0x994, 0x998, 0x99C, |
---|
72 | 72 | }; |
---|
73 | 73 | |
---|
74 | | -#define SMSTPCR(i) smstpcr[i] |
---|
| 74 | +static const u16 mstpcr_for_v3u[] = { |
---|
| 75 | + 0x2D00, 0x2D04, 0x2D08, 0x2D0C, 0x2D10, 0x2D14, 0x2D18, 0x2D1C, |
---|
| 76 | + 0x2D20, 0x2D24, 0x2D28, 0x2D2C, 0x2D30, 0x2D34, 0x2D38, |
---|
| 77 | +}; |
---|
75 | 78 | |
---|
| 79 | +/* |
---|
| 80 | + * Standby Control Register offsets (RZ/A) |
---|
| 81 | + * Base address is FRQCR register |
---|
| 82 | + */ |
---|
| 83 | + |
---|
| 84 | +static const u16 stbcr[] = { |
---|
| 85 | + 0xFFFF/*dummy*/, 0x010, 0x014, 0x410, 0x414, 0x418, 0x41C, 0x420, |
---|
| 86 | + 0x424, 0x428, 0x42C, |
---|
| 87 | +}; |
---|
76 | 88 | |
---|
77 | 89 | /* |
---|
78 | 90 | * Software Reset Register offsets |
---|
.. | .. |
---|
83 | 95 | 0x920, 0x924, 0x928, 0x92C, |
---|
84 | 96 | }; |
---|
85 | 97 | |
---|
86 | | -#define SRCR(i) srcr[i] |
---|
87 | | - |
---|
| 98 | +static const u16 srcr_for_v3u[] = { |
---|
| 99 | + 0x2C00, 0x2C04, 0x2C08, 0x2C0C, 0x2C10, 0x2C14, 0x2C18, 0x2C1C, |
---|
| 100 | + 0x2C20, 0x2C24, 0x2C28, 0x2C2C, 0x2C30, 0x2C34, 0x2C38, |
---|
| 101 | +}; |
---|
88 | 102 | |
---|
89 | 103 | /* Realtime Module Stop Control Register offsets */ |
---|
90 | 104 | #define RMSTPCR(i) (smstpcr[i] - 0x20) |
---|
.. | .. |
---|
93 | 107 | #define MMSTPCR(i) (smstpcr[i] + 0x20) |
---|
94 | 108 | |
---|
95 | 109 | /* Software Reset Clearing Register offsets */ |
---|
96 | | -#define SRSTCLR(i) (0x940 + (i) * 4) |
---|
97 | 110 | |
---|
| 111 | +static const u16 srstclr[] = { |
---|
| 112 | + 0x940, 0x944, 0x948, 0x94C, 0x950, 0x954, 0x958, 0x95C, |
---|
| 113 | + 0x960, 0x964, 0x968, 0x96C, |
---|
| 114 | +}; |
---|
| 115 | + |
---|
| 116 | +static const u16 srstclr_for_v3u[] = { |
---|
| 117 | + 0x2C80, 0x2C84, 0x2C88, 0x2C8C, 0x2C90, 0x2C94, 0x2C98, 0x2C9C, |
---|
| 118 | + 0x2CA0, 0x2CA4, 0x2CA8, 0x2CAC, 0x2CB0, 0x2CB4, 0x2CB8, |
---|
| 119 | +}; |
---|
98 | 120 | |
---|
99 | 121 | /** |
---|
100 | 122 | * Clock Pulse Generator / Module Standby and Software Reset Private Data |
---|
.. | .. |
---|
102 | 124 | * @rcdev: Optional reset controller entity |
---|
103 | 125 | * @dev: CPG/MSSR device |
---|
104 | 126 | * @base: CPG/MSSR register block base address |
---|
| 127 | + * @reg_layout: CPG/MSSR register layout |
---|
105 | 128 | * @rmw_lock: protects RMW register accesses |
---|
106 | | - * @clks: Array containing all Core and Module Clocks |
---|
| 129 | + * @np: Device node in DT for this CPG/MSSR module |
---|
107 | 130 | * @num_core_clks: Number of Core Clocks in clks[] |
---|
108 | 131 | * @num_mod_clks: Number of Module Clocks in clks[] |
---|
109 | 132 | * @last_dt_core_clk: ID of the last Core Clock exported to DT |
---|
110 | 133 | * @notifiers: Notifier chain to save/restore clock state for system resume |
---|
| 134 | + * @status_regs: Pointer to status registers array |
---|
| 135 | + * @control_regs: Pointer to control registers array |
---|
| 136 | + * @reset_regs: Pointer to reset registers array |
---|
| 137 | + * @reset_clear_regs: Pointer to reset clearing registers array |
---|
111 | 138 | * @smstpcr_saved[].mask: Mask of SMSTPCR[] bits under our control |
---|
112 | 139 | * @smstpcr_saved[].val: Saved values of SMSTPCR[] |
---|
| 140 | + * @clks: Array containing all Core and Module Clocks |
---|
113 | 141 | */ |
---|
114 | 142 | struct cpg_mssr_priv { |
---|
115 | 143 | #ifdef CONFIG_RESET_CONTROLLER |
---|
.. | .. |
---|
117 | 145 | #endif |
---|
118 | 146 | struct device *dev; |
---|
119 | 147 | void __iomem *base; |
---|
| 148 | + enum clk_reg_layout reg_layout; |
---|
120 | 149 | spinlock_t rmw_lock; |
---|
| 150 | + struct device_node *np; |
---|
121 | 151 | |
---|
122 | | - struct clk **clks; |
---|
123 | 152 | unsigned int num_core_clks; |
---|
124 | 153 | unsigned int num_mod_clks; |
---|
125 | 154 | unsigned int last_dt_core_clk; |
---|
126 | 155 | |
---|
127 | 156 | struct raw_notifier_head notifiers; |
---|
| 157 | + const u16 *status_regs; |
---|
| 158 | + const u16 *control_regs; |
---|
| 159 | + const u16 *reset_regs; |
---|
| 160 | + const u16 *reset_clear_regs; |
---|
128 | 161 | struct { |
---|
129 | 162 | u32 mask; |
---|
130 | 163 | u32 val; |
---|
131 | | - } smstpcr_saved[ARRAY_SIZE(smstpcr)]; |
---|
| 164 | + } smstpcr_saved[ARRAY_SIZE(mstpsr_for_v3u)]; |
---|
| 165 | + |
---|
| 166 | + struct clk *clks[]; |
---|
132 | 167 | }; |
---|
133 | 168 | |
---|
| 169 | +static struct cpg_mssr_priv *cpg_mssr_priv; |
---|
134 | 170 | |
---|
135 | 171 | /** |
---|
136 | 172 | * struct mstp_clock - MSTP gating clock |
---|
.. | .. |
---|
162 | 198 | enable ? "ON" : "OFF"); |
---|
163 | 199 | spin_lock_irqsave(&priv->rmw_lock, flags); |
---|
164 | 200 | |
---|
165 | | - value = readl(priv->base + SMSTPCR(reg)); |
---|
166 | | - if (enable) |
---|
167 | | - value &= ~bitmask; |
---|
168 | | - else |
---|
169 | | - value |= bitmask; |
---|
170 | | - writel(value, priv->base + SMSTPCR(reg)); |
---|
| 201 | + if (priv->reg_layout == CLK_REG_LAYOUT_RZ_A) { |
---|
| 202 | + value = readb(priv->base + priv->control_regs[reg]); |
---|
| 203 | + if (enable) |
---|
| 204 | + value &= ~bitmask; |
---|
| 205 | + else |
---|
| 206 | + value |= bitmask; |
---|
| 207 | + writeb(value, priv->base + priv->control_regs[reg]); |
---|
| 208 | + |
---|
| 209 | + /* dummy read to ensure write has completed */ |
---|
| 210 | + readb(priv->base + priv->control_regs[reg]); |
---|
| 211 | + barrier_data(priv->base + priv->control_regs[reg]); |
---|
| 212 | + } else { |
---|
| 213 | + value = readl(priv->base + priv->control_regs[reg]); |
---|
| 214 | + if (enable) |
---|
| 215 | + value &= ~bitmask; |
---|
| 216 | + else |
---|
| 217 | + value |= bitmask; |
---|
| 218 | + writel(value, priv->base + priv->control_regs[reg]); |
---|
| 219 | + } |
---|
171 | 220 | |
---|
172 | 221 | spin_unlock_irqrestore(&priv->rmw_lock, flags); |
---|
173 | 222 | |
---|
174 | | - if (!enable) |
---|
| 223 | + if (!enable || priv->reg_layout == CLK_REG_LAYOUT_RZ_A) |
---|
175 | 224 | return 0; |
---|
176 | 225 | |
---|
177 | 226 | for (i = 1000; i > 0; --i) { |
---|
178 | | - if (!(readl(priv->base + MSTPSR(reg)) & bitmask)) |
---|
| 227 | + if (!(readl(priv->base + priv->status_regs[reg]) & bitmask)) |
---|
179 | 228 | break; |
---|
180 | 229 | cpu_relax(); |
---|
181 | 230 | } |
---|
182 | 231 | |
---|
183 | 232 | if (!i) { |
---|
184 | 233 | dev_err(dev, "Failed to enable SMSTP %p[%d]\n", |
---|
185 | | - priv->base + SMSTPCR(reg), bit); |
---|
| 234 | + priv->base + priv->control_regs[reg], bit); |
---|
186 | 235 | return -ETIMEDOUT; |
---|
187 | 236 | } |
---|
188 | 237 | |
---|
.. | .. |
---|
205 | 254 | struct cpg_mssr_priv *priv = clock->priv; |
---|
206 | 255 | u32 value; |
---|
207 | 256 | |
---|
208 | | - value = readl(priv->base + MSTPSR(clock->index / 32)); |
---|
| 257 | + if (priv->reg_layout == CLK_REG_LAYOUT_RZ_A) |
---|
| 258 | + value = readb(priv->base + priv->control_regs[clock->index / 32]); |
---|
| 259 | + else |
---|
| 260 | + value = readl(priv->base + priv->status_regs[clock->index / 32]); |
---|
209 | 261 | |
---|
210 | 262 | return !(value & BIT(clock->index % 32)); |
---|
211 | 263 | } |
---|
.. | .. |
---|
226 | 278 | unsigned int idx; |
---|
227 | 279 | const char *type; |
---|
228 | 280 | struct clk *clk; |
---|
| 281 | + int range_check; |
---|
229 | 282 | |
---|
230 | 283 | switch (clkspec->args[0]) { |
---|
231 | 284 | case CPG_CORE: |
---|
.. | .. |
---|
240 | 293 | |
---|
241 | 294 | case CPG_MOD: |
---|
242 | 295 | type = "module"; |
---|
243 | | - idx = MOD_CLK_PACK(clkidx); |
---|
244 | | - if (clkidx % 100 > 31 || idx >= priv->num_mod_clks) { |
---|
| 296 | + if (priv->reg_layout == CLK_REG_LAYOUT_RZ_A) { |
---|
| 297 | + idx = MOD_CLK_PACK_10(clkidx); |
---|
| 298 | + range_check = 7 - (clkidx % 10); |
---|
| 299 | + } else { |
---|
| 300 | + idx = MOD_CLK_PACK(clkidx); |
---|
| 301 | + range_check = 31 - (clkidx % 100); |
---|
| 302 | + } |
---|
| 303 | + if (range_check < 0 || idx >= priv->num_mod_clks) { |
---|
245 | 304 | dev_err(dev, "Invalid %s clock index %u\n", type, |
---|
246 | 305 | clkidx); |
---|
247 | 306 | return ERR_PTR(-EINVAL); |
---|
.. | .. |
---|
283 | 342 | |
---|
284 | 343 | switch (core->type) { |
---|
285 | 344 | case CLK_TYPE_IN: |
---|
286 | | - clk = of_clk_get_by_name(priv->dev->of_node, core->name); |
---|
| 345 | + clk = of_clk_get_by_name(priv->np, core->name); |
---|
287 | 346 | break; |
---|
288 | 347 | |
---|
289 | 348 | case CLK_TYPE_FF: |
---|
.. | .. |
---|
311 | 370 | parent_name, 0, |
---|
312 | 371 | core->mult, div); |
---|
313 | 372 | } |
---|
| 373 | + break; |
---|
| 374 | + |
---|
| 375 | + case CLK_TYPE_FR: |
---|
| 376 | + clk = clk_register_fixed_rate(NULL, core->name, NULL, 0, |
---|
| 377 | + core->mult); |
---|
314 | 378 | break; |
---|
315 | 379 | |
---|
316 | 380 | default: |
---|
.. | .. |
---|
343 | 407 | struct mstp_clock *clock = NULL; |
---|
344 | 408 | struct device *dev = priv->dev; |
---|
345 | 409 | unsigned int id = mod->id; |
---|
346 | | - struct clk_init_data init = {}; |
---|
| 410 | + struct clk_init_data init; |
---|
347 | 411 | struct clk *parent, *clk; |
---|
348 | 412 | const char *parent_name; |
---|
349 | 413 | unsigned int i; |
---|
.. | .. |
---|
372 | 436 | |
---|
373 | 437 | init.name = mod->name; |
---|
374 | 438 | init.ops = &cpg_mstp_clock_ops; |
---|
375 | | - init.flags = CLK_IS_BASIC | CLK_SET_RATE_PARENT; |
---|
376 | | - for (i = 0; i < info->num_crit_mod_clks; i++) |
---|
377 | | - if (id == info->crit_mod_clks[i]) { |
---|
378 | | - dev_dbg(dev, "MSTP %s setting CLK_IS_CRITICAL\n", |
---|
379 | | - mod->name); |
---|
380 | | - init.flags |= CLK_IS_CRITICAL; |
---|
381 | | - break; |
---|
382 | | - } |
---|
383 | | - |
---|
| 439 | + init.flags = CLK_SET_RATE_PARENT; |
---|
384 | 440 | parent_name = __clk_get_name(parent); |
---|
385 | 441 | init.parent_names = &parent_name; |
---|
386 | 442 | init.num_parents = 1; |
---|
.. | .. |
---|
388 | 444 | clock->index = id - priv->num_core_clks; |
---|
389 | 445 | clock->priv = priv; |
---|
390 | 446 | clock->hw.init = &init; |
---|
| 447 | + |
---|
| 448 | + for (i = 0; i < info->num_crit_mod_clks; i++) |
---|
| 449 | + if (id == info->crit_mod_clks[i] && |
---|
| 450 | + cpg_mstp_clock_is_enabled(&clock->hw)) { |
---|
| 451 | + dev_dbg(dev, "MSTP %s setting CLK_IS_CRITICAL\n", |
---|
| 452 | + mod->name); |
---|
| 453 | + init.flags |= CLK_IS_CRITICAL; |
---|
| 454 | + break; |
---|
| 455 | + } |
---|
391 | 456 | |
---|
392 | 457 | clk = clk_register(NULL, &clock->hw); |
---|
393 | 458 | if (IS_ERR(clk)) |
---|
.. | .. |
---|
406 | 471 | |
---|
407 | 472 | struct cpg_mssr_clk_domain { |
---|
408 | 473 | struct generic_pm_domain genpd; |
---|
409 | | - struct device_node *np; |
---|
410 | 474 | unsigned int num_core_pm_clks; |
---|
411 | | - unsigned int core_pm_clks[0]; |
---|
| 475 | + unsigned int core_pm_clks[]; |
---|
412 | 476 | }; |
---|
413 | 477 | |
---|
414 | 478 | static struct cpg_mssr_clk_domain *cpg_mssr_clk_domain; |
---|
.. | .. |
---|
418 | 482 | { |
---|
419 | 483 | unsigned int i; |
---|
420 | 484 | |
---|
421 | | - if (clkspec->np != pd->np || clkspec->args_count != 2) |
---|
| 485 | + if (clkspec->np != pd->genpd.dev.of_node || clkspec->args_count != 2) |
---|
422 | 486 | return false; |
---|
423 | 487 | |
---|
424 | 488 | switch (clkspec->args[0]) { |
---|
.. | .. |
---|
469 | 533 | return PTR_ERR(clk); |
---|
470 | 534 | |
---|
471 | 535 | error = pm_clk_create(dev); |
---|
472 | | - if (error) { |
---|
473 | | - dev_err(dev, "pm_clk_create failed %d\n", error); |
---|
| 536 | + if (error) |
---|
474 | 537 | goto fail_put; |
---|
475 | | - } |
---|
476 | 538 | |
---|
477 | 539 | error = pm_clk_add_clk(dev, clk); |
---|
478 | | - if (error) { |
---|
479 | | - dev_err(dev, "pm_clk_add_clk %pC failed %d\n", clk, error); |
---|
| 540 | + if (error) |
---|
480 | 541 | goto fail_destroy; |
---|
481 | | - } |
---|
482 | 542 | |
---|
483 | 543 | return 0; |
---|
484 | 544 | |
---|
.. | .. |
---|
508 | 568 | if (!pd) |
---|
509 | 569 | return -ENOMEM; |
---|
510 | 570 | |
---|
511 | | - pd->np = np; |
---|
512 | 571 | pd->num_core_pm_clks = num_core_pm_clks; |
---|
513 | 572 | memcpy(pd->core_pm_clks, core_pm_clks, pm_size); |
---|
514 | 573 | |
---|
.. | .. |
---|
540 | 599 | dev_dbg(priv->dev, "reset %u%02u\n", reg, bit); |
---|
541 | 600 | |
---|
542 | 601 | /* Reset module */ |
---|
543 | | - writel(bitmask, priv->base + SRCR(reg)); |
---|
| 602 | + writel(bitmask, priv->base + priv->reset_regs[reg]); |
---|
544 | 603 | |
---|
545 | 604 | /* Wait for at least one cycle of the RCLK clock (@ ca. 32 kHz) */ |
---|
546 | 605 | udelay(35); |
---|
547 | 606 | |
---|
548 | 607 | /* Release module from reset state */ |
---|
549 | | - writel(bitmask, priv->base + SRSTCLR(reg)); |
---|
| 608 | + writel(bitmask, priv->base + priv->reset_clear_regs[reg]); |
---|
550 | 609 | |
---|
551 | 610 | return 0; |
---|
552 | 611 | } |
---|
.. | .. |
---|
560 | 619 | |
---|
561 | 620 | dev_dbg(priv->dev, "assert %u%02u\n", reg, bit); |
---|
562 | 621 | |
---|
563 | | - writel(bitmask, priv->base + SRCR(reg)); |
---|
| 622 | + writel(bitmask, priv->base + priv->reset_regs[reg]); |
---|
564 | 623 | return 0; |
---|
565 | 624 | } |
---|
566 | 625 | |
---|
.. | .. |
---|
574 | 633 | |
---|
575 | 634 | dev_dbg(priv->dev, "deassert %u%02u\n", reg, bit); |
---|
576 | 635 | |
---|
577 | | - writel(bitmask, priv->base + SRSTCLR(reg)); |
---|
| 636 | + writel(bitmask, priv->base + priv->reset_clear_regs[reg]); |
---|
578 | 637 | return 0; |
---|
579 | 638 | } |
---|
580 | 639 | |
---|
.. | .. |
---|
586 | 645 | unsigned int bit = id % 32; |
---|
587 | 646 | u32 bitmask = BIT(bit); |
---|
588 | 647 | |
---|
589 | | - return !!(readl(priv->base + SRCR(reg)) & bitmask); |
---|
| 648 | + return !!(readl(priv->base + priv->reset_regs[reg]) & bitmask); |
---|
590 | 649 | } |
---|
591 | 650 | |
---|
592 | 651 | static const struct reset_control_ops cpg_mssr_reset_ops = { |
---|
.. | .. |
---|
630 | 689 | |
---|
631 | 690 | |
---|
632 | 691 | static const struct of_device_id cpg_mssr_match[] = { |
---|
| 692 | +#ifdef CONFIG_CLK_R7S9210 |
---|
| 693 | + { |
---|
| 694 | + .compatible = "renesas,r7s9210-cpg-mssr", |
---|
| 695 | + .data = &r7s9210_cpg_mssr_info, |
---|
| 696 | + }, |
---|
| 697 | +#endif |
---|
| 698 | +#ifdef CONFIG_CLK_R8A7742 |
---|
| 699 | + { |
---|
| 700 | + .compatible = "renesas,r8a7742-cpg-mssr", |
---|
| 701 | + .data = &r8a7742_cpg_mssr_info, |
---|
| 702 | + }, |
---|
| 703 | +#endif |
---|
633 | 704 | #ifdef CONFIG_CLK_R8A7743 |
---|
634 | 705 | { |
---|
635 | 706 | .compatible = "renesas,r8a7743-cpg-mssr", |
---|
| 707 | + .data = &r8a7743_cpg_mssr_info, |
---|
| 708 | + }, |
---|
| 709 | + /* RZ/G1N is (almost) identical to RZ/G1M w.r.t. clocks. */ |
---|
| 710 | + { |
---|
| 711 | + .compatible = "renesas,r8a7744-cpg-mssr", |
---|
636 | 712 | .data = &r8a7743_cpg_mssr_info, |
---|
637 | 713 | }, |
---|
638 | 714 | #endif |
---|
.. | .. |
---|
646 | 722 | { |
---|
647 | 723 | .compatible = "renesas,r8a77470-cpg-mssr", |
---|
648 | 724 | .data = &r8a77470_cpg_mssr_info, |
---|
| 725 | + }, |
---|
| 726 | +#endif |
---|
| 727 | +#ifdef CONFIG_CLK_R8A774A1 |
---|
| 728 | + { |
---|
| 729 | + .compatible = "renesas,r8a774a1-cpg-mssr", |
---|
| 730 | + .data = &r8a774a1_cpg_mssr_info, |
---|
| 731 | + }, |
---|
| 732 | +#endif |
---|
| 733 | +#ifdef CONFIG_CLK_R8A774B1 |
---|
| 734 | + { |
---|
| 735 | + .compatible = "renesas,r8a774b1-cpg-mssr", |
---|
| 736 | + .data = &r8a774b1_cpg_mssr_info, |
---|
| 737 | + }, |
---|
| 738 | +#endif |
---|
| 739 | +#ifdef CONFIG_CLK_R8A774C0 |
---|
| 740 | + { |
---|
| 741 | + .compatible = "renesas,r8a774c0-cpg-mssr", |
---|
| 742 | + .data = &r8a774c0_cpg_mssr_info, |
---|
| 743 | + }, |
---|
| 744 | +#endif |
---|
| 745 | +#ifdef CONFIG_CLK_R8A774E1 |
---|
| 746 | + { |
---|
| 747 | + .compatible = "renesas,r8a774e1-cpg-mssr", |
---|
| 748 | + .data = &r8a774e1_cpg_mssr_info, |
---|
649 | 749 | }, |
---|
650 | 750 | #endif |
---|
651 | 751 | #ifdef CONFIG_CLK_R8A7790 |
---|
.. | .. |
---|
683 | 783 | .data = &r8a7795_cpg_mssr_info, |
---|
684 | 784 | }, |
---|
685 | 785 | #endif |
---|
686 | | -#ifdef CONFIG_CLK_R8A7796 |
---|
| 786 | +#ifdef CONFIG_CLK_R8A77960 |
---|
687 | 787 | { |
---|
688 | 788 | .compatible = "renesas,r8a7796-cpg-mssr", |
---|
| 789 | + .data = &r8a7796_cpg_mssr_info, |
---|
| 790 | + }, |
---|
| 791 | +#endif |
---|
| 792 | +#ifdef CONFIG_CLK_R8A77961 |
---|
| 793 | + { |
---|
| 794 | + .compatible = "renesas,r8a77961-cpg-mssr", |
---|
689 | 795 | .data = &r8a7796_cpg_mssr_info, |
---|
690 | 796 | }, |
---|
691 | 797 | #endif |
---|
.. | .. |
---|
719 | 825 | .data = &r8a77995_cpg_mssr_info, |
---|
720 | 826 | }, |
---|
721 | 827 | #endif |
---|
| 828 | +#ifdef CONFIG_CLK_R8A779A0 |
---|
| 829 | + { |
---|
| 830 | + .compatible = "renesas,r8a779a0-cpg-mssr", |
---|
| 831 | + .data = &r8a779a0_cpg_mssr_info, |
---|
| 832 | + }, |
---|
| 833 | +#endif |
---|
722 | 834 | { /* sentinel */ } |
---|
723 | 835 | }; |
---|
724 | 836 | |
---|
.. | .. |
---|
741 | 853 | for (reg = 0; reg < ARRAY_SIZE(priv->smstpcr_saved); reg++) { |
---|
742 | 854 | if (priv->smstpcr_saved[reg].mask) |
---|
743 | 855 | priv->smstpcr_saved[reg].val = |
---|
744 | | - readl(priv->base + SMSTPCR(reg)); |
---|
| 856 | + priv->reg_layout == CLK_REG_LAYOUT_RZ_A ? |
---|
| 857 | + readb(priv->base + priv->control_regs[reg]) : |
---|
| 858 | + readl(priv->base + priv->control_regs[reg]); |
---|
745 | 859 | } |
---|
746 | 860 | |
---|
747 | 861 | /* Save core clocks */ |
---|
.. | .. |
---|
769 | 883 | if (!mask) |
---|
770 | 884 | continue; |
---|
771 | 885 | |
---|
772 | | - oldval = readl(priv->base + SMSTPCR(reg)); |
---|
| 886 | + if (priv->reg_layout == CLK_REG_LAYOUT_RZ_A) |
---|
| 887 | + oldval = readb(priv->base + priv->control_regs[reg]); |
---|
| 888 | + else |
---|
| 889 | + oldval = readl(priv->base + priv->control_regs[reg]); |
---|
773 | 890 | newval = oldval & ~mask; |
---|
774 | 891 | newval |= priv->smstpcr_saved[reg].val & mask; |
---|
775 | 892 | if (newval == oldval) |
---|
776 | 893 | continue; |
---|
777 | 894 | |
---|
778 | | - writel(newval, priv->base + SMSTPCR(reg)); |
---|
| 895 | + if (priv->reg_layout == CLK_REG_LAYOUT_RZ_A) { |
---|
| 896 | + writeb(newval, priv->base + priv->control_regs[reg]); |
---|
| 897 | + /* dummy read to ensure write has completed */ |
---|
| 898 | + readb(priv->base + priv->control_regs[reg]); |
---|
| 899 | + barrier_data(priv->base + priv->control_regs[reg]); |
---|
| 900 | + continue; |
---|
| 901 | + } else |
---|
| 902 | + writel(newval, priv->base + priv->control_regs[reg]); |
---|
779 | 903 | |
---|
780 | 904 | /* Wait until enabled clocks are really enabled */ |
---|
781 | 905 | mask &= ~priv->smstpcr_saved[reg].val; |
---|
.. | .. |
---|
783 | 907 | continue; |
---|
784 | 908 | |
---|
785 | 909 | for (i = 1000; i > 0; --i) { |
---|
786 | | - oldval = readl(priv->base + MSTPSR(reg)); |
---|
| 910 | + oldval = readl(priv->base + priv->status_regs[reg]); |
---|
787 | 911 | if (!(oldval & mask)) |
---|
788 | 912 | break; |
---|
789 | 913 | cpu_relax(); |
---|
790 | 914 | } |
---|
791 | 915 | |
---|
792 | 916 | if (!i) |
---|
793 | | - dev_warn(dev, "Failed to enable SMSTP %p[0x%x]\n", |
---|
794 | | - priv->base + SMSTPCR(reg), oldval & mask); |
---|
| 917 | + dev_warn(dev, "Failed to enable SMSTP%u[0x%x]\n", reg, |
---|
| 918 | + oldval & mask); |
---|
795 | 919 | } |
---|
796 | 920 | |
---|
797 | 921 | return 0; |
---|
.. | .. |
---|
806 | 930 | #define DEV_PM_OPS NULL |
---|
807 | 931 | #endif /* CONFIG_PM_SLEEP && CONFIG_ARM_PSCI_FW */ |
---|
808 | 932 | |
---|
809 | | -static int __init cpg_mssr_probe(struct platform_device *pdev) |
---|
| 933 | +static int __init cpg_mssr_common_init(struct device *dev, |
---|
| 934 | + struct device_node *np, |
---|
| 935 | + const struct cpg_mssr_info *info) |
---|
810 | 936 | { |
---|
811 | | - struct device *dev = &pdev->dev; |
---|
812 | | - struct device_node *np = dev->of_node; |
---|
813 | | - const struct cpg_mssr_info *info; |
---|
814 | 937 | struct cpg_mssr_priv *priv; |
---|
815 | 938 | unsigned int nclks, i; |
---|
816 | | - struct resource *res; |
---|
817 | | - struct clk **clks; |
---|
818 | 939 | int error; |
---|
819 | 940 | |
---|
820 | | - info = of_device_get_match_data(dev); |
---|
821 | 941 | if (info->init) { |
---|
822 | 942 | error = info->init(dev); |
---|
823 | 943 | if (error) |
---|
824 | 944 | return error; |
---|
825 | 945 | } |
---|
826 | 946 | |
---|
827 | | - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); |
---|
| 947 | + nclks = info->num_total_core_clks + info->num_hw_mod_clks; |
---|
| 948 | + priv = kzalloc(struct_size(priv, clks, nclks), GFP_KERNEL); |
---|
828 | 949 | if (!priv) |
---|
829 | 950 | return -ENOMEM; |
---|
830 | 951 | |
---|
| 952 | + priv->np = np; |
---|
831 | 953 | priv->dev = dev; |
---|
832 | 954 | spin_lock_init(&priv->rmw_lock); |
---|
833 | 955 | |
---|
834 | | - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
---|
835 | | - priv->base = devm_ioremap_resource(dev, res); |
---|
836 | | - if (IS_ERR(priv->base)) |
---|
837 | | - return PTR_ERR(priv->base); |
---|
| 956 | + priv->base = of_iomap(np, 0); |
---|
| 957 | + if (!priv->base) { |
---|
| 958 | + error = -ENOMEM; |
---|
| 959 | + goto out_err; |
---|
| 960 | + } |
---|
838 | 961 | |
---|
839 | | - nclks = info->num_total_core_clks + info->num_hw_mod_clks; |
---|
840 | | - clks = devm_kmalloc_array(dev, nclks, sizeof(*clks), GFP_KERNEL); |
---|
841 | | - if (!clks) |
---|
842 | | - return -ENOMEM; |
---|
843 | | - |
---|
844 | | - dev_set_drvdata(dev, priv); |
---|
845 | | - priv->clks = clks; |
---|
846 | 962 | priv->num_core_clks = info->num_total_core_clks; |
---|
847 | 963 | priv->num_mod_clks = info->num_hw_mod_clks; |
---|
848 | 964 | priv->last_dt_core_clk = info->last_dt_core_clk; |
---|
849 | 965 | RAW_INIT_NOTIFIER_HEAD(&priv->notifiers); |
---|
| 966 | + priv->reg_layout = info->reg_layout; |
---|
| 967 | + if (priv->reg_layout == CLK_REG_LAYOUT_RCAR_GEN2_AND_GEN3) { |
---|
| 968 | + priv->status_regs = mstpsr; |
---|
| 969 | + priv->control_regs = smstpcr; |
---|
| 970 | + priv->reset_regs = srcr; |
---|
| 971 | + priv->reset_clear_regs = srstclr; |
---|
| 972 | + } else if (priv->reg_layout == CLK_REG_LAYOUT_RZ_A) { |
---|
| 973 | + priv->control_regs = stbcr; |
---|
| 974 | + } else if (priv->reg_layout == CLK_REG_LAYOUT_RCAR_V3U) { |
---|
| 975 | + priv->status_regs = mstpsr_for_v3u; |
---|
| 976 | + priv->control_regs = mstpcr_for_v3u; |
---|
| 977 | + priv->reset_regs = srcr_for_v3u; |
---|
| 978 | + priv->reset_clear_regs = srstclr_for_v3u; |
---|
| 979 | + } else { |
---|
| 980 | + error = -EINVAL; |
---|
| 981 | + goto out_err; |
---|
| 982 | + } |
---|
850 | 983 | |
---|
851 | 984 | for (i = 0; i < nclks; i++) |
---|
852 | | - clks[i] = ERR_PTR(-ENOENT); |
---|
| 985 | + priv->clks[i] = ERR_PTR(-ENOENT); |
---|
| 986 | + |
---|
| 987 | + error = of_clk_add_provider(np, cpg_mssr_clk_src_twocell_get, priv); |
---|
| 988 | + if (error) |
---|
| 989 | + goto out_err; |
---|
| 990 | + |
---|
| 991 | + cpg_mssr_priv = priv; |
---|
| 992 | + |
---|
| 993 | + return 0; |
---|
| 994 | + |
---|
| 995 | +out_err: |
---|
| 996 | + if (priv->base) |
---|
| 997 | + iounmap(priv->base); |
---|
| 998 | + kfree(priv); |
---|
| 999 | + |
---|
| 1000 | + return error; |
---|
| 1001 | +} |
---|
| 1002 | + |
---|
| 1003 | +void __init cpg_mssr_early_init(struct device_node *np, |
---|
| 1004 | + const struct cpg_mssr_info *info) |
---|
| 1005 | +{ |
---|
| 1006 | + int error; |
---|
| 1007 | + int i; |
---|
| 1008 | + |
---|
| 1009 | + error = cpg_mssr_common_init(NULL, np, info); |
---|
| 1010 | + if (error) |
---|
| 1011 | + return; |
---|
| 1012 | + |
---|
| 1013 | + for (i = 0; i < info->num_early_core_clks; i++) |
---|
| 1014 | + cpg_mssr_register_core_clk(&info->early_core_clks[i], info, |
---|
| 1015 | + cpg_mssr_priv); |
---|
| 1016 | + |
---|
| 1017 | + for (i = 0; i < info->num_early_mod_clks; i++) |
---|
| 1018 | + cpg_mssr_register_mod_clk(&info->early_mod_clks[i], info, |
---|
| 1019 | + cpg_mssr_priv); |
---|
| 1020 | + |
---|
| 1021 | +} |
---|
| 1022 | + |
---|
| 1023 | +static int __init cpg_mssr_probe(struct platform_device *pdev) |
---|
| 1024 | +{ |
---|
| 1025 | + struct device *dev = &pdev->dev; |
---|
| 1026 | + struct device_node *np = dev->of_node; |
---|
| 1027 | + const struct cpg_mssr_info *info; |
---|
| 1028 | + struct cpg_mssr_priv *priv; |
---|
| 1029 | + unsigned int i; |
---|
| 1030 | + int error; |
---|
| 1031 | + |
---|
| 1032 | + info = of_device_get_match_data(dev); |
---|
| 1033 | + |
---|
| 1034 | + if (!cpg_mssr_priv) { |
---|
| 1035 | + error = cpg_mssr_common_init(dev, dev->of_node, info); |
---|
| 1036 | + if (error) |
---|
| 1037 | + return error; |
---|
| 1038 | + } |
---|
| 1039 | + |
---|
| 1040 | + priv = cpg_mssr_priv; |
---|
| 1041 | + priv->dev = dev; |
---|
| 1042 | + dev_set_drvdata(dev, priv); |
---|
853 | 1043 | |
---|
854 | 1044 | for (i = 0; i < info->num_core_clks; i++) |
---|
855 | 1045 | cpg_mssr_register_core_clk(&info->core_clks[i], info, priv); |
---|
856 | 1046 | |
---|
857 | 1047 | for (i = 0; i < info->num_mod_clks; i++) |
---|
858 | 1048 | cpg_mssr_register_mod_clk(&info->mod_clks[i], info, priv); |
---|
859 | | - |
---|
860 | | - error = of_clk_add_provider(np, cpg_mssr_clk_src_twocell_get, priv); |
---|
861 | | - if (error) |
---|
862 | | - return error; |
---|
863 | 1049 | |
---|
864 | 1050 | error = devm_add_action_or_reset(dev, |
---|
865 | 1051 | cpg_mssr_del_clk_provider, |
---|
.. | .. |
---|
872 | 1058 | if (error) |
---|
873 | 1059 | return error; |
---|
874 | 1060 | |
---|
| 1061 | + /* Reset Controller not supported for Standby Control SoCs */ |
---|
| 1062 | + if (priv->reg_layout == CLK_REG_LAYOUT_RZ_A) |
---|
| 1063 | + return 0; |
---|
| 1064 | + |
---|
875 | 1065 | error = cpg_mssr_reset_controller_register(priv); |
---|
876 | 1066 | if (error) |
---|
877 | 1067 | return error; |
---|