]> Pileus Git - ~andy/linux/blobdiff - drivers/clk/clk-gate.c
Merge tag 'fbdev-updates-for-3.5' of git://github.com/schandinat/linux-2.6
[~andy/linux] / drivers / clk / clk-gate.c
index 42a4b941b6e72e6c9e9362f683e2028eee2798c6..578465e04be6b900c37009a7bfe3feb3c7506728 100644 (file)
 
 #define to_clk_gate(_hw) container_of(_hw, struct clk_gate, hw)
 
-static void clk_gate_set_bit(struct clk_gate *gate)
+/*
+ * It works on following logic:
+ *
+ * For enabling clock, enable = 1
+ *     set2dis = 1     -> clear bit    -> set = 0
+ *     set2dis = 0     -> set bit      -> set = 1
+ *
+ * For disabling clock, enable = 0
+ *     set2dis = 1     -> set bit      -> set = 1
+ *     set2dis = 0     -> clear bit    -> set = 0
+ *
+ * So, result is always: enable xor set2dis.
+ */
+static void clk_gate_endisable(struct clk_hw *hw, int enable)
 {
-       u32 reg;
+       struct clk_gate *gate = to_clk_gate(hw);
+       int set = gate->flags & CLK_GATE_SET_TO_DISABLE ? 1 : 0;
        unsigned long flags = 0;
+       u32 reg;
+
+       set ^= enable;
 
        if (gate->lock)
                spin_lock_irqsave(gate->lock, flags);
 
        reg = readl(gate->reg);
-       reg |= BIT(gate->bit_idx);
-       writel(reg, gate->reg);
-
-       if (gate->lock)
-               spin_unlock_irqrestore(gate->lock, flags);
-}
 
-static void clk_gate_clear_bit(struct clk_gate *gate)
-{
-       u32 reg;
-       unsigned long flags = 0;
-
-       if (gate->lock)
-               spin_lock_irqsave(gate->lock, flags);
+       if (set)
+               reg |= BIT(gate->bit_idx);
+       else
+               reg &= ~BIT(gate->bit_idx);
 
-       reg = readl(gate->reg);
-       reg &= ~BIT(gate->bit_idx);
        writel(reg, gate->reg);
 
        if (gate->lock)
@@ -62,24 +68,14 @@ static void clk_gate_clear_bit(struct clk_gate *gate)
 
 static int clk_gate_enable(struct clk_hw *hw)
 {
-       struct clk_gate *gate = to_clk_gate(hw);
-
-       if (gate->flags & CLK_GATE_SET_TO_DISABLE)
-               clk_gate_clear_bit(gate);
-       else
-               clk_gate_set_bit(gate);
+       clk_gate_endisable(hw, 1);
 
        return 0;
 }
 
 static void clk_gate_disable(struct clk_hw *hw)
 {
-       struct clk_gate *gate = to_clk_gate(hw);
-
-       if (gate->flags & CLK_GATE_SET_TO_DISABLE)
-               clk_gate_set_bit(gate);
-       else
-               clk_gate_clear_bit(gate);
+       clk_gate_endisable(hw, 0);
 }
 
 static int clk_gate_is_enabled(struct clk_hw *hw)
@@ -123,6 +119,7 @@ struct clk *clk_register_gate(struct device *dev, const char *name,
 {
        struct clk_gate *gate;
        struct clk *clk;
+       struct clk_init_data init;
 
        /* allocate the gate */
        gate = kzalloc(sizeof(struct clk_gate), GFP_KERNEL);
@@ -131,18 +128,20 @@ struct clk *clk_register_gate(struct device *dev, const char *name,
                return ERR_PTR(-ENOMEM);
        }
 
+       init.name = name;
+       init.ops = &clk_gate_ops;
+       init.flags = flags;
+       init.parent_names = (parent_name ? &parent_name: NULL);
+       init.num_parents = (parent_name ? 1 : 0);
+
        /* struct clk_gate assignments */
        gate->reg = reg;
        gate->bit_idx = bit_idx;
        gate->flags = clk_gate_flags;
        gate->lock = lock;
+       gate->hw.init = &init;
 
-       /* register the clock */
-       clk = clk_register(dev, name,
-                       &clk_gate_ops, &gate->hw,
-                       (parent_name ? &parent_name : NULL),
-                       (parent_name ? 1 : 0),
-                       flags);
+       clk = clk_register(dev, &gate->hw);
 
        if (IS_ERR(clk))
                kfree(gate);