Merge tag 'ib-mfd-regulator-clk-v3.19' of git://git.kernel.org/pub/scm/linux/kernel...
[cascardo/linux.git] / drivers / clk / clk-s2mps11.c
index 3757e9e..4f98898 100644 (file)
@@ -23,6 +23,7 @@
 #include <linux/clk-provider.h>
 #include <linux/platform_device.h>
 #include <linux/mfd/samsung/s2mps11.h>
+#include <linux/mfd/samsung/s2mps13.h>
 #include <linux/mfd/samsung/s2mps14.h>
 #include <linux/mfd/samsung/s5m8767.h>
 #include <linux/mfd/samsung/core.h>
@@ -46,7 +47,6 @@ struct s2mps11_clk {
        struct clk *clk;
        struct clk_lookup *lookup;
        u32 mask;
-       bool enabled;
        unsigned int reg;
 };
 
@@ -63,8 +63,6 @@ static int s2mps11_clk_prepare(struct clk_hw *hw)
        ret = regmap_update_bits(s2mps11->iodev->regmap_pmic,
                                 s2mps11->reg,
                                 s2mps11->mask, s2mps11->mask);
-       if (!ret)
-               s2mps11->enabled = true;
 
        return ret;
 }
@@ -76,32 +74,32 @@ static void s2mps11_clk_unprepare(struct clk_hw *hw)
 
        ret = regmap_update_bits(s2mps11->iodev->regmap_pmic, s2mps11->reg,
                           s2mps11->mask, ~s2mps11->mask);
-
-       if (!ret)
-               s2mps11->enabled = false;
 }
 
-static int s2mps11_clk_is_enabled(struct clk_hw *hw)
+static int s2mps11_clk_is_prepared(struct clk_hw *hw)
 {
+       int ret;
+       u32 val;
        struct s2mps11_clk *s2mps11 = to_s2mps11_clk(hw);
 
-       return s2mps11->enabled;
+       ret = regmap_read(s2mps11->iodev->regmap_pmic,
+                               s2mps11->reg, &val);
+       if (ret < 0)
+               return -EINVAL;
+
+       return val & s2mps11->mask;
 }
 
 static unsigned long s2mps11_clk_recalc_rate(struct clk_hw *hw,
                                             unsigned long parent_rate)
 {
-       struct s2mps11_clk *s2mps11 = to_s2mps11_clk(hw);
-       if (s2mps11->enabled)
-               return 32768;
-       else
-               return 0;
+       return 32768;
 }
 
 static struct clk_ops s2mps11_clk_ops = {
        .prepare        = s2mps11_clk_prepare,
        .unprepare      = s2mps11_clk_unprepare,
-       .is_enabled     = s2mps11_clk_is_enabled,
+       .is_prepared    = s2mps11_clk_is_prepared,
        .recalc_rate    = s2mps11_clk_recalc_rate,
 };
 
@@ -123,6 +121,24 @@ static struct clk_init_data s2mps11_clks_init[S2MPS11_CLKS_NUM] = {
        },
 };
 
+static struct clk_init_data s2mps13_clks_init[S2MPS11_CLKS_NUM] = {
+       [S2MPS11_CLK_AP] = {
+               .name = "s2mps13_ap",
+               .ops = &s2mps11_clk_ops,
+               .flags = CLK_IS_ROOT,
+       },
+       [S2MPS11_CLK_CP] = {
+               .name = "s2mps13_cp",
+               .ops = &s2mps11_clk_ops,
+               .flags = CLK_IS_ROOT,
+       },
+       [S2MPS11_CLK_BT] = {
+               .name = "s2mps13_bt",
+               .ops = &s2mps11_clk_ops,
+               .flags = CLK_IS_ROOT,
+       },
+};
+
 static struct clk_init_data s2mps14_clks_init[S2MPS11_CLKS_NUM] = {
        [S2MPS11_CLK_AP] = {
                .name = "s2mps14_ap",
@@ -169,7 +185,6 @@ static int s2mps11_clk_probe(struct platform_device *pdev)
        unsigned int s2mps11_reg;
        struct clk_init_data *clks_init;
        int i, ret = 0;
-       u32 val;
 
        s2mps11_clks = devm_kzalloc(&pdev->dev, sizeof(*s2mps11_clk) *
                                        S2MPS11_CLKS_NUM, GFP_KERNEL);
@@ -188,6 +203,10 @@ static int s2mps11_clk_probe(struct platform_device *pdev)
                s2mps11_reg = S2MPS11_REG_RTC_CTRL;
                clks_init = s2mps11_clks_init;
                break;
+       case S2MPS13X:
+               s2mps11_reg = S2MPS13_REG_RTCCTRL;
+               clks_init = s2mps13_clks_init;
+               break;
        case S2MPS14X:
                s2mps11_reg = S2MPS14_REG_RTCCTRL;
                clks_init = s2mps14_clks_init;
@@ -199,7 +218,7 @@ static int s2mps11_clk_probe(struct platform_device *pdev)
        default:
                dev_err(&pdev->dev, "Invalid device type\n");
                return -EINVAL;
-       };
+       }
 
        /* Store clocks of_node in first element of s2mps11_clks array */
        s2mps11_clks->clk_np = s2mps11_clk_parse_dt(pdev, clks_init);
@@ -214,13 +233,6 @@ static int s2mps11_clk_probe(struct platform_device *pdev)
                s2mps11_clk->mask = 1 << i;
                s2mps11_clk->reg = s2mps11_reg;
 
-               ret = regmap_read(s2mps11_clk->iodev->regmap_pmic,
-                                 s2mps11_clk->reg, &val);
-               if (ret < 0)
-                       goto err_reg;
-
-               s2mps11_clk->enabled = val & s2mps11_clk->mask;
-
                s2mps11_clk->clk = devm_clk_register(&pdev->dev,
                                                        &s2mps11_clk->hw);
                if (IS_ERR(s2mps11_clk->clk)) {
@@ -290,6 +302,7 @@ static int s2mps11_clk_remove(struct platform_device *pdev)
 
 static const struct platform_device_id s2mps11_clk_id[] = {
        { "s2mps11-clk", S2MPS11X},
+       { "s2mps13-clk", S2MPS13X},
        { "s2mps14-clk", S2MPS14X},
        { "s5m8767-clk", S5M8767X},
        { },