#include <linux/clk.h>
 #include <linux/clk-provider.h>
+#include <linux/clk/renesas.h>
 #include <linux/device.h>
 #include <linux/init.h>
 #include <linux/mod_devicetable.h>
        unsigned int core_pm_clks[0];
 };
 
+static struct cpg_mssr_clk_domain *cpg_mssr_clk_domain;
+
 static bool cpg_mssr_is_pm_clk(const struct of_phandle_args *clkspec,
                               struct cpg_mssr_clk_domain *pd)
 {
        }
 }
 
-static int cpg_mssr_attach_dev(struct generic_pm_domain *genpd,
-                              struct device *dev)
+int cpg_mssr_attach_dev(struct generic_pm_domain *unused, struct device *dev)
 {
-       struct cpg_mssr_clk_domain *pd =
-               container_of(genpd, struct cpg_mssr_clk_domain, genpd);
+       struct cpg_mssr_clk_domain *pd = cpg_mssr_clk_domain;
        struct device_node *np = dev->of_node;
        struct of_phandle_args clkspec;
        struct clk *clk;
        int i = 0;
        int error;
 
+       if (!pd) {
+               dev_dbg(dev, "CPG/MSSR clock domain not yet available\n");
+               return -EPROBE_DEFER;
+       }
+
        while (!of_parse_phandle_with_args(np, "clocks", "#clock-cells", i,
                                           &clkspec)) {
                if (cpg_mssr_is_pm_clk(&clkspec, pd))
        return error;
 }
 
-static void cpg_mssr_detach_dev(struct generic_pm_domain *genpd,
-                               struct device *dev)
+void cpg_mssr_detach_dev(struct generic_pm_domain *unused, struct device *dev)
 {
        if (!list_empty(&dev->power.subsys_data->clock_list))
                pm_clk_destroy(dev);
        pm_genpd_init(genpd, &simple_qos_governor, false);
        genpd->attach_dev = cpg_mssr_attach_dev;
        genpd->detach_dev = cpg_mssr_detach_dev;
+       cpg_mssr_clk_domain = pd;
 
        of_genpd_add_provider_simple(np, genpd);
        return 0;
 
 #define cpg_mstp_detach_dev    NULL
 #endif
 
+#ifdef CONFIG_CLK_RENESAS_CPG_MSSR
+int cpg_mssr_attach_dev(struct generic_pm_domain *unused, struct device *dev);
+void cpg_mssr_detach_dev(struct generic_pm_domain *unused, struct device *dev);
+#else
+#define cpg_mssr_attach_dev    NULL
+#define cpg_mssr_detach_dev    NULL
+#endif
 #endif