]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blobdiff - drivers/clk/at91/clk-smd.c
Merge tag 'clk-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/clk/linux
[mirror_ubuntu-zesty-kernel.git] / drivers / clk / at91 / clk-smd.c
index f525830ed5a16018fe1e20bed9777e7aa687ebeb..3c04b069d5b8f78975ee6af0b6a40d2fe3367e1a 100644 (file)
@@ -12,8 +12,8 @@
 #include <linux/clkdev.h>
 #include <linux/clk/at91_pmc.h>
 #include <linux/of.h>
-#include <linux/of_address.h>
-#include <linux/io.h>
+#include <linux/mfd/syscon.h>
+#include <linux/regmap.h>
 
 #include "pmc.h"
 
@@ -24,7 +24,7 @@
 
 struct at91sam9x5_clk_smd {
        struct clk_hw hw;
-       struct at91_pmc *pmc;
+       struct regmap *regmap;
 };
 
 #define to_at91sam9x5_clk_smd(hw) \
@@ -33,13 +33,13 @@ struct at91sam9x5_clk_smd {
 static unsigned long at91sam9x5_clk_smd_recalc_rate(struct clk_hw *hw,
                                                    unsigned long parent_rate)
 {
-       u32 tmp;
-       u8 smddiv;
        struct at91sam9x5_clk_smd *smd = to_at91sam9x5_clk_smd(hw);
-       struct at91_pmc *pmc = smd->pmc;
+       unsigned int smdr;
+       u8 smddiv;
+
+       regmap_read(smd->regmap, AT91_PMC_SMD, &smdr);
+       smddiv = (smdr & AT91_PMC_SMD_DIV) >> SMD_DIV_SHIFT;
 
-       tmp = pmc_read(pmc, AT91_PMC_SMD);
-       smddiv = (tmp & AT91_PMC_SMD_DIV) >> SMD_DIV_SHIFT;
        return parent_rate / (smddiv + 1);
 }
 
@@ -67,40 +67,38 @@ static long at91sam9x5_clk_smd_round_rate(struct clk_hw *hw, unsigned long rate,
 
 static int at91sam9x5_clk_smd_set_parent(struct clk_hw *hw, u8 index)
 {
-       u32 tmp;
        struct at91sam9x5_clk_smd *smd = to_at91sam9x5_clk_smd(hw);
-       struct at91_pmc *pmc = smd->pmc;
 
        if (index > 1)
                return -EINVAL;
-       tmp = pmc_read(pmc, AT91_PMC_SMD) & ~AT91_PMC_SMDS;
-       if (index)
-               tmp |= AT91_PMC_SMDS;
-       pmc_write(pmc, AT91_PMC_SMD, tmp);
+
+       regmap_update_bits(smd->regmap, AT91_PMC_SMD, AT91_PMC_SMDS,
+                          index ? AT91_PMC_SMDS : 0);
+
        return 0;
 }
 
 static u8 at91sam9x5_clk_smd_get_parent(struct clk_hw *hw)
 {
        struct at91sam9x5_clk_smd *smd = to_at91sam9x5_clk_smd(hw);
-       struct at91_pmc *pmc = smd->pmc;
+       unsigned int smdr;
 
-       return pmc_read(pmc, AT91_PMC_SMD) & AT91_PMC_SMDS;
+       regmap_read(smd->regmap, AT91_PMC_SMD, &smdr);
+
+       return smdr & AT91_PMC_SMDS;
 }
 
 static int at91sam9x5_clk_smd_set_rate(struct clk_hw *hw, unsigned long rate,
                                       unsigned long parent_rate)
 {
-       u32 tmp;
        struct at91sam9x5_clk_smd *smd = to_at91sam9x5_clk_smd(hw);
-       struct at91_pmc *pmc = smd->pmc;
        unsigned long div = parent_rate / rate;
 
        if (parent_rate % rate || div < 1 || div > (SMD_MAX_DIV + 1))
                return -EINVAL;
-       tmp = pmc_read(pmc, AT91_PMC_SMD) & ~AT91_PMC_SMD_DIV;
-       tmp |= (div - 1) << SMD_DIV_SHIFT;
-       pmc_write(pmc, AT91_PMC_SMD, tmp);
+
+       regmap_update_bits(smd->regmap, AT91_PMC_SMD, AT91_PMC_SMD_DIV,
+                          (div - 1) << SMD_DIV_SHIFT);
 
        return 0;
 }
@@ -114,7 +112,7 @@ static const struct clk_ops at91sam9x5_smd_ops = {
 };
 
 static struct clk * __init
-at91sam9x5_clk_register_smd(struct at91_pmc *pmc, const char *name,
+at91sam9x5_clk_register_smd(struct regmap *regmap, const char *name,
                            const char **parent_names, u8 num_parents)
 {
        struct at91sam9x5_clk_smd *smd;
@@ -132,7 +130,7 @@ at91sam9x5_clk_register_smd(struct at91_pmc *pmc, const char *name,
        init.flags = CLK_SET_RATE_GATE | CLK_SET_PARENT_GATE;
 
        smd->hw.init = &init;
-       smd->pmc = pmc;
+       smd->regmap = regmap;
 
        clk = clk_register(NULL, &smd->hw);
        if (IS_ERR(clk))
@@ -141,13 +139,13 @@ at91sam9x5_clk_register_smd(struct at91_pmc *pmc, const char *name,
        return clk;
 }
 
-void __init of_at91sam9x5_clk_smd_setup(struct device_node *np,
-                                       struct at91_pmc *pmc)
+static void __init of_at91sam9x5_clk_smd_setup(struct device_node *np)
 {
        struct clk *clk;
        unsigned int num_parents;
        const char *parent_names[SMD_SOURCE_MAX];
        const char *name = np->name;
+       struct regmap *regmap;
 
        num_parents = of_clk_get_parent_count(np);
        if (num_parents == 0 || num_parents > SMD_SOURCE_MAX)
@@ -157,10 +155,16 @@ void __init of_at91sam9x5_clk_smd_setup(struct device_node *np,
 
        of_property_read_string(np, "clock-output-names", &name);
 
-       clk = at91sam9x5_clk_register_smd(pmc, name, parent_names,
+       regmap = syscon_node_to_regmap(of_get_parent(np));
+       if (IS_ERR(regmap))
+               return;
+
+       clk = at91sam9x5_clk_register_smd(regmap, name, parent_names,
                                          num_parents);
        if (IS_ERR(clk))
                return;
 
        of_clk_add_provider(np, of_clk_src_simple_get, clk);
 }
+CLK_OF_DECLARE(at91sam9x5_clk_smd, "atmel,at91sam9x5-clk-smd",
+              of_at91sam9x5_clk_smd_setup);