2 * Renesas Clock Pulse Generator / Module Standby and Software Reset
4 * Copyright (C) 2015 Glider bvba
6 * Based on clk-mstp.c, clk-rcar-gen2.c, and clk-rcar-gen3.c
8 * Copyright (C) 2013 Ideas On Board SPRL
9 * Copyright (C) 2015 Renesas Electronics Corp.
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.
16 #include <linux/clk.h>
17 #include <linux/clk-provider.h>
18 #include <linux/clk/renesas.h>
19 #include <linux/delay.h>
20 #include <linux/device.h>
21 #include <linux/init.h>
22 #include <linux/mod_devicetable.h>
23 #include <linux/module.h>
24 #include <linux/of_address.h>
25 #include <linux/of_device.h>
26 #include <linux/platform_device.h>
27 #include <linux/pm_clock.h>
28 #include <linux/pm_domain.h>
29 #include <linux/psci.h>
30 #include <linux/reset-controller.h>
31 #include <linux/slab.h>
33 #include <dt-bindings/clock/renesas-cpg-mssr.h>
35 #include "renesas-cpg-mssr.h"
39 #define WARN_DEBUG(x) WARN_ON(x)
41 #define WARN_DEBUG(x) do { } while (0)
46 * Module Standby and Software Reset register offets.
48 * If the registers exist, these are valid for SH-Mobile, R-Mobile,
49 * R-Car Gen2, R-Car Gen3, and RZ/G1.
50 * These are NOT valid for R-Car Gen1 and RZ/A1!
54 * Module Stop Status Register offsets
57 static const u16 mstpsr
[] = {
58 0x030, 0x038, 0x040, 0x048, 0x04C, 0x03C, 0x1C0, 0x1C4,
59 0x9A0, 0x9A4, 0x9A8, 0x9AC,
62 #define MSTPSR(i) mstpsr[i]
66 * System Module Stop Control Register offsets
69 static const u16 smstpcr
[] = {
70 0x130, 0x134, 0x138, 0x13C, 0x140, 0x144, 0x148, 0x14C,
71 0x990, 0x994, 0x998, 0x99C,
74 #define SMSTPCR(i) smstpcr[i]
78 * Software Reset Register offsets
81 static const u16 srcr
[] = {
82 0x0A0, 0x0A8, 0x0B0, 0x0B8, 0x0BC, 0x0C4, 0x1C8, 0x1CC,
83 0x920, 0x924, 0x928, 0x92C,
86 #define SRCR(i) srcr[i]
89 /* Realtime Module Stop Control Register offsets */
90 #define RMSTPCR(i) (smstpcr[i] - 0x20)
92 /* Modem Module Stop Control Register offsets (r8a73a4) */
93 #define MMSTPCR(i) (smstpcr[i] + 0x20)
95 /* Software Reset Clearing Register offsets */
96 #define SRSTCLR(i) (0x940 + (i) * 4)
100 * Clock Pulse Generator / Module Standby and Software Reset Private Data
102 * @rcdev: Optional reset controller entity
103 * @dev: CPG/MSSR device
104 * @base: CPG/MSSR register block base address
105 * @rmw_lock: protects RMW register accesses
106 * @clks: Array containing all Core and Module Clocks
107 * @num_core_clks: Number of Core Clocks in clks[]
108 * @num_mod_clks: Number of Module Clocks in clks[]
109 * @last_dt_core_clk: ID of the last Core Clock exported to DT
110 * @notifiers: Notifier chain to save/restore clock state for system resume
111 * @smstpcr_saved[].mask: Mask of SMSTPCR[] bits under our control
112 * @smstpcr_saved[].val: Saved values of SMSTPCR[]
114 struct cpg_mssr_priv
{
115 #ifdef CONFIG_RESET_CONTROLLER
116 struct reset_controller_dev rcdev
;
123 unsigned int num_core_clks
;
124 unsigned int num_mod_clks
;
125 unsigned int last_dt_core_clk
;
127 struct raw_notifier_head notifiers
;
131 } smstpcr_saved
[ARRAY_SIZE(smstpcr
)];
136 * struct mstp_clock - MSTP gating clock
137 * @hw: handle between common and hardware-specific interfaces
138 * @index: MSTP clock number
139 * @priv: CPG/MSSR private data
144 struct cpg_mssr_priv
*priv
;
147 #define to_mstp_clock(_hw) container_of(_hw, struct mstp_clock, hw)
149 static int cpg_mstp_clock_endisable(struct clk_hw
*hw
, bool enable
)
151 struct mstp_clock
*clock
= to_mstp_clock(hw
);
152 struct cpg_mssr_priv
*priv
= clock
->priv
;
153 unsigned int reg
= clock
->index
/ 32;
154 unsigned int bit
= clock
->index
% 32;
155 struct device
*dev
= priv
->dev
;
156 u32 bitmask
= BIT(bit
);
161 dev_dbg(dev
, "MSTP %u%02u/%pC %s\n", reg
, bit
, hw
->clk
,
162 enable
? "ON" : "OFF");
163 spin_lock_irqsave(&priv
->rmw_lock
, flags
);
165 value
= readl(priv
->base
+ SMSTPCR(reg
));
170 writel(value
, priv
->base
+ SMSTPCR(reg
));
172 spin_unlock_irqrestore(&priv
->rmw_lock
, flags
);
177 for (i
= 1000; i
> 0; --i
) {
178 if (!(readl(priv
->base
+ MSTPSR(reg
)) & bitmask
))
184 dev_err(dev
, "Failed to enable SMSTP %p[%d]\n",
185 priv
->base
+ SMSTPCR(reg
), bit
);
192 static int cpg_mstp_clock_enable(struct clk_hw
*hw
)
194 return cpg_mstp_clock_endisable(hw
, true);
197 static void cpg_mstp_clock_disable(struct clk_hw
*hw
)
199 cpg_mstp_clock_endisable(hw
, false);
202 static int cpg_mstp_clock_is_enabled(struct clk_hw
*hw
)
204 struct mstp_clock
*clock
= to_mstp_clock(hw
);
205 struct cpg_mssr_priv
*priv
= clock
->priv
;
208 value
= readl(priv
->base
+ MSTPSR(clock
->index
/ 32));
210 return !(value
& BIT(clock
->index
% 32));
213 static const struct clk_ops cpg_mstp_clock_ops
= {
214 .enable
= cpg_mstp_clock_enable
,
215 .disable
= cpg_mstp_clock_disable
,
216 .is_enabled
= cpg_mstp_clock_is_enabled
,
220 struct clk
*cpg_mssr_clk_src_twocell_get(struct of_phandle_args
*clkspec
,
223 unsigned int clkidx
= clkspec
->args
[1];
224 struct cpg_mssr_priv
*priv
= data
;
225 struct device
*dev
= priv
->dev
;
230 switch (clkspec
->args
[0]) {
233 if (clkidx
> priv
->last_dt_core_clk
) {
234 dev_err(dev
, "Invalid %s clock index %u\n", type
,
236 return ERR_PTR(-EINVAL
);
238 clk
= priv
->clks
[clkidx
];
243 idx
= MOD_CLK_PACK(clkidx
);
244 if (clkidx
% 100 > 31 || idx
>= priv
->num_mod_clks
) {
245 dev_err(dev
, "Invalid %s clock index %u\n", type
,
247 return ERR_PTR(-EINVAL
);
249 clk
= priv
->clks
[priv
->num_core_clks
+ idx
];
253 dev_err(dev
, "Invalid CPG clock type %u\n", clkspec
->args
[0]);
254 return ERR_PTR(-EINVAL
);
258 dev_err(dev
, "Cannot get %s clock %u: %ld", type
, clkidx
,
261 dev_dbg(dev
, "clock (%u, %u) is %pC at %lu Hz\n",
262 clkspec
->args
[0], clkspec
->args
[1], clk
,
267 static void __init
cpg_mssr_register_core_clk(const struct cpg_core_clk
*core
,
268 const struct cpg_mssr_info
*info
,
269 struct cpg_mssr_priv
*priv
)
271 struct clk
*clk
= ERR_PTR(-ENOTSUPP
), *parent
;
272 struct device
*dev
= priv
->dev
;
273 unsigned int id
= core
->id
, div
= core
->div
;
274 const char *parent_name
;
276 WARN_DEBUG(id
>= priv
->num_core_clks
);
277 WARN_DEBUG(PTR_ERR(priv
->clks
[id
]) != -ENOENT
);
280 /* Skip NULLified clock */
284 switch (core
->type
) {
286 clk
= of_clk_get_by_name(priv
->dev
->of_node
, core
->name
);
290 case CLK_TYPE_DIV6P1
:
291 case CLK_TYPE_DIV6_RO
:
292 WARN_DEBUG(core
->parent
>= priv
->num_core_clks
);
293 parent
= priv
->clks
[core
->parent
];
294 if (IS_ERR(parent
)) {
299 parent_name
= __clk_get_name(parent
);
301 if (core
->type
== CLK_TYPE_DIV6_RO
)
302 /* Multiply with the DIV6 register value */
303 div
*= (readl(priv
->base
+ core
->offset
) & 0x3f) + 1;
305 if (core
->type
== CLK_TYPE_DIV6P1
) {
306 clk
= cpg_div6_register(core
->name
, 1, &parent_name
,
307 priv
->base
+ core
->offset
,
310 clk
= clk_register_fixed_factor(NULL
, core
->name
,
317 if (info
->cpg_clk_register
)
318 clk
= info
->cpg_clk_register(dev
, core
, info
,
319 priv
->clks
, priv
->base
,
322 dev_err(dev
, "%s has unsupported core clock type %u\n",
323 core
->name
, core
->type
);
327 if (IS_ERR_OR_NULL(clk
))
330 dev_dbg(dev
, "Core clock %pC at %lu Hz\n", clk
, clk_get_rate(clk
));
331 priv
->clks
[id
] = clk
;
335 dev_err(dev
, "Failed to register %s clock %s: %ld\n", "core",
336 core
->name
, PTR_ERR(clk
));
339 static void __init
cpg_mssr_register_mod_clk(const struct mssr_mod_clk
*mod
,
340 const struct cpg_mssr_info
*info
,
341 struct cpg_mssr_priv
*priv
)
343 struct mstp_clock
*clock
= NULL
;
344 struct device
*dev
= priv
->dev
;
345 unsigned int id
= mod
->id
;
346 struct clk_init_data init
;
347 struct clk
*parent
, *clk
;
348 const char *parent_name
;
351 WARN_DEBUG(id
< priv
->num_core_clks
);
352 WARN_DEBUG(id
>= priv
->num_core_clks
+ priv
->num_mod_clks
);
353 WARN_DEBUG(mod
->parent
>= priv
->num_core_clks
+ priv
->num_mod_clks
);
354 WARN_DEBUG(PTR_ERR(priv
->clks
[id
]) != -ENOENT
);
357 /* Skip NULLified clock */
361 parent
= priv
->clks
[mod
->parent
];
362 if (IS_ERR(parent
)) {
367 clock
= kzalloc(sizeof(*clock
), GFP_KERNEL
);
369 clk
= ERR_PTR(-ENOMEM
);
373 init
.name
= mod
->name
;
374 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",
380 init
.flags
|= CLK_IS_CRITICAL
;
384 parent_name
= __clk_get_name(parent
);
385 init
.parent_names
= &parent_name
;
386 init
.num_parents
= 1;
388 clock
->index
= id
- priv
->num_core_clks
;
390 clock
->hw
.init
= &init
;
392 clk
= clk_register(NULL
, &clock
->hw
);
396 dev_dbg(dev
, "Module clock %pC at %lu Hz\n", clk
, clk_get_rate(clk
));
397 priv
->clks
[id
] = clk
;
398 priv
->smstpcr_saved
[clock
->index
/ 32].mask
|= BIT(clock
->index
% 32);
402 dev_err(dev
, "Failed to register %s clock %s: %ld\n", "module",
403 mod
->name
, PTR_ERR(clk
));
407 struct cpg_mssr_clk_domain
{
408 struct generic_pm_domain genpd
;
409 struct device_node
*np
;
410 unsigned int num_core_pm_clks
;
411 unsigned int core_pm_clks
[0];
414 static struct cpg_mssr_clk_domain
*cpg_mssr_clk_domain
;
416 static bool cpg_mssr_is_pm_clk(const struct of_phandle_args
*clkspec
,
417 struct cpg_mssr_clk_domain
*pd
)
421 if (clkspec
->np
!= pd
->np
|| clkspec
->args_count
!= 2)
424 switch (clkspec
->args
[0]) {
426 for (i
= 0; i
< pd
->num_core_pm_clks
; i
++)
427 if (clkspec
->args
[1] == pd
->core_pm_clks
[i
])
439 int cpg_mssr_attach_dev(struct generic_pm_domain
*unused
, struct device
*dev
)
441 struct cpg_mssr_clk_domain
*pd
= cpg_mssr_clk_domain
;
442 struct device_node
*np
= dev
->of_node
;
443 struct of_phandle_args clkspec
;
449 dev_dbg(dev
, "CPG/MSSR clock domain not yet available\n");
450 return -EPROBE_DEFER
;
453 while (!of_parse_phandle_with_args(np
, "clocks", "#clock-cells", i
,
455 if (cpg_mssr_is_pm_clk(&clkspec
, pd
))
458 of_node_put(clkspec
.np
);
465 clk
= of_clk_get_from_provider(&clkspec
);
466 of_node_put(clkspec
.np
);
471 error
= pm_clk_create(dev
);
473 dev_err(dev
, "pm_clk_create failed %d\n", error
);
477 error
= pm_clk_add_clk(dev
, clk
);
479 dev_err(dev
, "pm_clk_add_clk %pC failed %d\n", clk
, error
);
492 void cpg_mssr_detach_dev(struct generic_pm_domain
*unused
, struct device
*dev
)
494 if (!pm_clk_no_clocks(dev
))
498 static int __init
cpg_mssr_add_clk_domain(struct device
*dev
,
499 const unsigned int *core_pm_clks
,
500 unsigned int num_core_pm_clks
)
502 struct device_node
*np
= dev
->of_node
;
503 struct generic_pm_domain
*genpd
;
504 struct cpg_mssr_clk_domain
*pd
;
505 size_t pm_size
= num_core_pm_clks
* sizeof(core_pm_clks
[0]);
507 pd
= devm_kzalloc(dev
, sizeof(*pd
) + pm_size
, GFP_KERNEL
);
512 pd
->num_core_pm_clks
= num_core_pm_clks
;
513 memcpy(pd
->core_pm_clks
, core_pm_clks
, pm_size
);
516 genpd
->name
= np
->name
;
517 genpd
->flags
= GENPD_FLAG_PM_CLK
| GENPD_FLAG_ACTIVE_WAKEUP
;
518 genpd
->attach_dev
= cpg_mssr_attach_dev
;
519 genpd
->detach_dev
= cpg_mssr_detach_dev
;
520 pm_genpd_init(genpd
, &pm_domain_always_on_gov
, false);
521 cpg_mssr_clk_domain
= pd
;
523 of_genpd_add_provider_simple(np
, genpd
);
527 #ifdef CONFIG_RESET_CONTROLLER
529 #define rcdev_to_priv(x) container_of(x, struct cpg_mssr_priv, rcdev)
531 static int cpg_mssr_reset(struct reset_controller_dev
*rcdev
,
534 struct cpg_mssr_priv
*priv
= rcdev_to_priv(rcdev
);
535 unsigned int reg
= id
/ 32;
536 unsigned int bit
= id
% 32;
537 u32 bitmask
= BIT(bit
);
541 dev_dbg(priv
->dev
, "reset %u%02u\n", reg
, bit
);
544 spin_lock_irqsave(&priv
->rmw_lock
, flags
);
545 value
= readl(priv
->base
+ SRCR(reg
));
547 writel(value
, priv
->base
+ SRCR(reg
));
548 spin_unlock_irqrestore(&priv
->rmw_lock
, flags
);
550 /* Wait for at least one cycle of the RCLK clock (@ ca. 32 kHz) */
553 /* Release module from reset state */
554 writel(bitmask
, priv
->base
+ SRSTCLR(reg
));
559 static int cpg_mssr_assert(struct reset_controller_dev
*rcdev
, unsigned long id
)
561 struct cpg_mssr_priv
*priv
= rcdev_to_priv(rcdev
);
562 unsigned int reg
= id
/ 32;
563 unsigned int bit
= id
% 32;
564 u32 bitmask
= BIT(bit
);
568 dev_dbg(priv
->dev
, "assert %u%02u\n", reg
, bit
);
570 spin_lock_irqsave(&priv
->rmw_lock
, flags
);
571 value
= readl(priv
->base
+ SRCR(reg
));
573 writel(value
, priv
->base
+ SRCR(reg
));
574 spin_unlock_irqrestore(&priv
->rmw_lock
, flags
);
578 static int cpg_mssr_deassert(struct reset_controller_dev
*rcdev
,
581 struct cpg_mssr_priv
*priv
= rcdev_to_priv(rcdev
);
582 unsigned int reg
= id
/ 32;
583 unsigned int bit
= id
% 32;
584 u32 bitmask
= BIT(bit
);
586 dev_dbg(priv
->dev
, "deassert %u%02u\n", reg
, bit
);
588 writel(bitmask
, priv
->base
+ SRSTCLR(reg
));
592 static int cpg_mssr_status(struct reset_controller_dev
*rcdev
,
595 struct cpg_mssr_priv
*priv
= rcdev_to_priv(rcdev
);
596 unsigned int reg
= id
/ 32;
597 unsigned int bit
= id
% 32;
598 u32 bitmask
= BIT(bit
);
600 return !!(readl(priv
->base
+ SRCR(reg
)) & bitmask
);
603 static const struct reset_control_ops cpg_mssr_reset_ops
= {
604 .reset
= cpg_mssr_reset
,
605 .assert = cpg_mssr_assert
,
606 .deassert
= cpg_mssr_deassert
,
607 .status
= cpg_mssr_status
,
610 static int cpg_mssr_reset_xlate(struct reset_controller_dev
*rcdev
,
611 const struct of_phandle_args
*reset_spec
)
613 struct cpg_mssr_priv
*priv
= rcdev_to_priv(rcdev
);
614 unsigned int unpacked
= reset_spec
->args
[0];
615 unsigned int idx
= MOD_CLK_PACK(unpacked
);
617 if (unpacked
% 100 > 31 || idx
>= rcdev
->nr_resets
) {
618 dev_err(priv
->dev
, "Invalid reset index %u\n", unpacked
);
625 static int cpg_mssr_reset_controller_register(struct cpg_mssr_priv
*priv
)
627 priv
->rcdev
.ops
= &cpg_mssr_reset_ops
;
628 priv
->rcdev
.of_node
= priv
->dev
->of_node
;
629 priv
->rcdev
.of_reset_n_cells
= 1;
630 priv
->rcdev
.of_xlate
= cpg_mssr_reset_xlate
;
631 priv
->rcdev
.nr_resets
= priv
->num_mod_clks
;
632 return devm_reset_controller_register(priv
->dev
, &priv
->rcdev
);
635 #else /* !CONFIG_RESET_CONTROLLER */
636 static inline int cpg_mssr_reset_controller_register(struct cpg_mssr_priv
*priv
)
640 #endif /* !CONFIG_RESET_CONTROLLER */
643 static const struct of_device_id cpg_mssr_match
[] = {
644 #ifdef CONFIG_CLK_R8A7743
646 .compatible
= "renesas,r8a7743-cpg-mssr",
647 .data
= &r8a7743_cpg_mssr_info
,
650 #ifdef CONFIG_CLK_R8A7745
652 .compatible
= "renesas,r8a7745-cpg-mssr",
653 .data
= &r8a7745_cpg_mssr_info
,
656 #ifdef CONFIG_CLK_R8A77470
658 .compatible
= "renesas,r8a77470-cpg-mssr",
659 .data
= &r8a77470_cpg_mssr_info
,
662 #ifdef CONFIG_CLK_R8A7790
664 .compatible
= "renesas,r8a7790-cpg-mssr",
665 .data
= &r8a7790_cpg_mssr_info
,
668 #ifdef CONFIG_CLK_R8A7791
670 .compatible
= "renesas,r8a7791-cpg-mssr",
671 .data
= &r8a7791_cpg_mssr_info
,
673 /* R-Car M2-N is (almost) identical to R-Car M2-W w.r.t. clocks. */
675 .compatible
= "renesas,r8a7793-cpg-mssr",
676 .data
= &r8a7791_cpg_mssr_info
,
679 #ifdef CONFIG_CLK_R8A7792
681 .compatible
= "renesas,r8a7792-cpg-mssr",
682 .data
= &r8a7792_cpg_mssr_info
,
685 #ifdef CONFIG_CLK_R8A7794
687 .compatible
= "renesas,r8a7794-cpg-mssr",
688 .data
= &r8a7794_cpg_mssr_info
,
691 #ifdef CONFIG_CLK_R8A7795
693 .compatible
= "renesas,r8a7795-cpg-mssr",
694 .data
= &r8a7795_cpg_mssr_info
,
697 #ifdef CONFIG_CLK_R8A7796
699 .compatible
= "renesas,r8a7796-cpg-mssr",
700 .data
= &r8a7796_cpg_mssr_info
,
703 #ifdef CONFIG_CLK_R8A77965
705 .compatible
= "renesas,r8a77965-cpg-mssr",
706 .data
= &r8a77965_cpg_mssr_info
,
709 #ifdef CONFIG_CLK_R8A77970
711 .compatible
= "renesas,r8a77970-cpg-mssr",
712 .data
= &r8a77970_cpg_mssr_info
,
715 #ifdef CONFIG_CLK_R8A77980
717 .compatible
= "renesas,r8a77980-cpg-mssr",
718 .data
= &r8a77980_cpg_mssr_info
,
721 #ifdef CONFIG_CLK_R8A77990
723 .compatible
= "renesas,r8a77990-cpg-mssr",
724 .data
= &r8a77990_cpg_mssr_info
,
727 #ifdef CONFIG_CLK_R8A77995
729 .compatible
= "renesas,r8a77995-cpg-mssr",
730 .data
= &r8a77995_cpg_mssr_info
,
736 static void cpg_mssr_del_clk_provider(void *data
)
738 of_clk_del_provider(data
);
741 #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_ARM_PSCI_FW)
742 static int cpg_mssr_suspend_noirq(struct device
*dev
)
744 struct cpg_mssr_priv
*priv
= dev_get_drvdata(dev
);
747 /* This is the best we can do to check for the presence of PSCI */
748 if (!psci_ops
.cpu_suspend
)
751 /* Save module registers with bits under our control */
752 for (reg
= 0; reg
< ARRAY_SIZE(priv
->smstpcr_saved
); reg
++) {
753 if (priv
->smstpcr_saved
[reg
].mask
)
754 priv
->smstpcr_saved
[reg
].val
=
755 readl(priv
->base
+ SMSTPCR(reg
));
758 /* Save core clocks */
759 raw_notifier_call_chain(&priv
->notifiers
, PM_EVENT_SUSPEND
, NULL
);
764 static int cpg_mssr_resume_noirq(struct device
*dev
)
766 struct cpg_mssr_priv
*priv
= dev_get_drvdata(dev
);
768 u32 mask
, oldval
, newval
;
770 /* This is the best we can do to check for the presence of PSCI */
771 if (!psci_ops
.cpu_suspend
)
774 /* Restore core clocks */
775 raw_notifier_call_chain(&priv
->notifiers
, PM_EVENT_RESUME
, NULL
);
777 /* Restore module clocks */
778 for (reg
= 0; reg
< ARRAY_SIZE(priv
->smstpcr_saved
); reg
++) {
779 mask
= priv
->smstpcr_saved
[reg
].mask
;
783 oldval
= readl(priv
->base
+ SMSTPCR(reg
));
784 newval
= oldval
& ~mask
;
785 newval
|= priv
->smstpcr_saved
[reg
].val
& mask
;
786 if (newval
== oldval
)
789 writel(newval
, priv
->base
+ SMSTPCR(reg
));
791 /* Wait until enabled clocks are really enabled */
792 mask
&= ~priv
->smstpcr_saved
[reg
].val
;
796 for (i
= 1000; i
> 0; --i
) {
797 oldval
= readl(priv
->base
+ MSTPSR(reg
));
798 if (!(oldval
& mask
))
804 dev_warn(dev
, "Failed to enable SMSTP %p[0x%x]\n",
805 priv
->base
+ SMSTPCR(reg
), oldval
& mask
);
811 static const struct dev_pm_ops cpg_mssr_pm
= {
812 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(cpg_mssr_suspend_noirq
,
813 cpg_mssr_resume_noirq
)
815 #define DEV_PM_OPS &cpg_mssr_pm
817 #define DEV_PM_OPS NULL
818 #endif /* CONFIG_PM_SLEEP && CONFIG_ARM_PSCI_FW */
820 static int __init
cpg_mssr_probe(struct platform_device
*pdev
)
822 struct device
*dev
= &pdev
->dev
;
823 struct device_node
*np
= dev
->of_node
;
824 const struct cpg_mssr_info
*info
;
825 struct cpg_mssr_priv
*priv
;
826 unsigned int nclks
, i
;
827 struct resource
*res
;
831 info
= of_device_get_match_data(dev
);
833 error
= info
->init(dev
);
838 priv
= devm_kzalloc(dev
, sizeof(*priv
), GFP_KERNEL
);
843 spin_lock_init(&priv
->rmw_lock
);
845 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
846 priv
->base
= devm_ioremap_resource(dev
, res
);
847 if (IS_ERR(priv
->base
))
848 return PTR_ERR(priv
->base
);
850 nclks
= info
->num_total_core_clks
+ info
->num_hw_mod_clks
;
851 clks
= devm_kmalloc_array(dev
, nclks
, sizeof(*clks
), GFP_KERNEL
);
855 dev_set_drvdata(dev
, priv
);
857 priv
->num_core_clks
= info
->num_total_core_clks
;
858 priv
->num_mod_clks
= info
->num_hw_mod_clks
;
859 priv
->last_dt_core_clk
= info
->last_dt_core_clk
;
860 RAW_INIT_NOTIFIER_HEAD(&priv
->notifiers
);
862 for (i
= 0; i
< nclks
; i
++)
863 clks
[i
] = ERR_PTR(-ENOENT
);
865 for (i
= 0; i
< info
->num_core_clks
; i
++)
866 cpg_mssr_register_core_clk(&info
->core_clks
[i
], info
, priv
);
868 for (i
= 0; i
< info
->num_mod_clks
; i
++)
869 cpg_mssr_register_mod_clk(&info
->mod_clks
[i
], info
, priv
);
871 error
= of_clk_add_provider(np
, cpg_mssr_clk_src_twocell_get
, priv
);
875 error
= devm_add_action_or_reset(dev
,
876 cpg_mssr_del_clk_provider
,
881 error
= cpg_mssr_add_clk_domain(dev
, info
->core_pm_clks
,
882 info
->num_core_pm_clks
);
886 error
= cpg_mssr_reset_controller_register(priv
);
893 static struct platform_driver cpg_mssr_driver
= {
895 .name
= "renesas-cpg-mssr",
896 .of_match_table
= cpg_mssr_match
,
901 static int __init
cpg_mssr_init(void)
903 return platform_driver_probe(&cpg_mssr_driver
, cpg_mssr_probe
);
906 subsys_initcall(cpg_mssr_init
);
908 void __init
cpg_core_nullify_range(struct cpg_core_clk
*core_clks
,
909 unsigned int num_core_clks
,
910 unsigned int first_clk
,
911 unsigned int last_clk
)
915 for (i
= 0; i
< num_core_clks
; i
++)
916 if (core_clks
[i
].id
>= first_clk
&&
917 core_clks
[i
].id
<= last_clk
)
918 core_clks
[i
].name
= NULL
;
921 void __init
mssr_mod_nullify(struct mssr_mod_clk
*mod_clks
,
922 unsigned int num_mod_clks
,
923 const unsigned int *clks
, unsigned int n
)
927 for (i
= 0, j
= 0; i
< num_mod_clks
&& j
< n
; i
++)
928 if (mod_clks
[i
].id
== clks
[j
]) {
929 mod_clks
[i
].name
= NULL
;
934 void __init
mssr_mod_reparent(struct mssr_mod_clk
*mod_clks
,
935 unsigned int num_mod_clks
,
936 const struct mssr_mod_reparent
*clks
,
941 for (i
= 0, j
= 0; i
< num_mod_clks
&& j
< n
; i
++)
942 if (mod_clks
[i
].id
== clks
[j
].clk
) {
943 mod_clks
[i
].parent
= clks
[j
].parent
;
948 MODULE_DESCRIPTION("Renesas CPG/MSSR Driver");
949 MODULE_LICENSE("GPL v2");