]>
git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blob - drivers/clk/sunxi-ng/ccu_gate.c
2 * Copyright (C) 2016 Maxime Ripard
3 * Maxime Ripard <maxime.ripard@free-electrons.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of
8 * the License, or (at your option) any later version.
11 #include <linux/clk-provider.h>
16 void ccu_gate_helper_disable(struct ccu_common
*common
, u32 gate
)
24 spin_lock_irqsave(common
->lock
, flags
);
26 reg
= readl(common
->base
+ common
->reg
);
27 writel(reg
& ~gate
, common
->base
+ common
->reg
);
29 spin_unlock_irqrestore(common
->lock
, flags
);
32 static void ccu_gate_disable(struct clk_hw
*hw
)
34 struct ccu_gate
*cg
= hw_to_ccu_gate(hw
);
36 return ccu_gate_helper_disable(&cg
->common
, cg
->enable
);
39 int ccu_gate_helper_enable(struct ccu_common
*common
, u32 gate
)
47 spin_lock_irqsave(common
->lock
, flags
);
49 reg
= readl(common
->base
+ common
->reg
);
50 writel(reg
| gate
, common
->base
+ common
->reg
);
52 spin_unlock_irqrestore(common
->lock
, flags
);
57 static int ccu_gate_enable(struct clk_hw
*hw
)
59 struct ccu_gate
*cg
= hw_to_ccu_gate(hw
);
61 return ccu_gate_helper_enable(&cg
->common
, cg
->enable
);
64 int ccu_gate_helper_is_enabled(struct ccu_common
*common
, u32 gate
)
69 return readl(common
->base
+ common
->reg
) & gate
;
72 static int ccu_gate_is_enabled(struct clk_hw
*hw
)
74 struct ccu_gate
*cg
= hw_to_ccu_gate(hw
);
76 return ccu_gate_helper_is_enabled(&cg
->common
, cg
->enable
);
79 static unsigned long ccu_gate_recalc_rate(struct clk_hw
*hw
,
80 unsigned long parent_rate
)
82 struct ccu_gate
*cg
= hw_to_ccu_gate(hw
);
83 unsigned long rate
= parent_rate
;
85 if (cg
->common
.features
& CCU_FEATURE_ALL_PREDIV
)
86 rate
/= cg
->common
.prediv
;
91 static long ccu_gate_round_rate(struct clk_hw
*hw
, unsigned long rate
,
94 struct ccu_gate
*cg
= hw_to_ccu_gate(hw
);
97 if (cg
->common
.features
& CCU_FEATURE_ALL_PREDIV
)
98 div
= cg
->common
.prediv
;
100 if (clk_hw_get_flags(hw
) & CLK_SET_RATE_PARENT
) {
101 unsigned long best_parent
= rate
;
103 if (cg
->common
.features
& CCU_FEATURE_ALL_PREDIV
)
105 *prate
= clk_hw_round_rate(clk_hw_get_parent(hw
), best_parent
);
111 static int ccu_gate_set_rate(struct clk_hw
*hw
, unsigned long rate
,
112 unsigned long parent_rate
)
115 * We must report success but we can do so unconditionally because
116 * clk_factor_round_rate returns values that ensure this call is a
123 const struct clk_ops ccu_gate_ops
= {
124 .disable
= ccu_gate_disable
,
125 .enable
= ccu_gate_enable
,
126 .is_enabled
= ccu_gate_is_enabled
,
127 .round_rate
= ccu_gate_round_rate
,
128 .set_rate
= ccu_gate_set_rate
,
129 .recalc_rate
= ccu_gate_recalc_rate
,