Merge tag 'drivers-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/arm...
[linux-2.6.git] / arch / arm / mach-omap2 / dpll44xx.c
blobd28b0f7267151dfdcf2909b1647c9a5b80ba661b
1 /*
2 * OMAP4-specific DPLL control functions
4 * Copyright (C) 2011 Texas Instruments, Inc.
5 * Rajendra Nayak
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 #include <linux/kernel.h>
13 #include <linux/errno.h>
14 #include <linux/clk.h>
15 #include <linux/io.h>
16 #include <linux/bitops.h>
18 #include "soc.h"
19 #include "clock.h"
20 #include "clock44xx.h"
21 #include "cm-regbits-44xx.h"
24 * Maximum DPLL input frequency (FINT) and output frequency (FOUT) that
25 * can supported when using the DPLL low-power mode. Frequencies are
26 * defined in OMAP4430/60 Public TRM section 3.6.3.3.2 "Enable Control,
27 * Status, and Low-Power Operation Mode".
29 #define OMAP4_DPLL_LP_FINT_MAX 1000000
30 #define OMAP4_DPLL_LP_FOUT_MAX 100000000
32 /* Supported only on OMAP4 */
33 int omap4_dpllmx_gatectrl_read(struct clk_hw_omap *clk)
35 u32 v;
36 u32 mask;
38 if (!clk || !clk->clksel_reg || !cpu_is_omap44xx())
39 return -EINVAL;
41 mask = clk->flags & CLOCK_CLKOUTX2 ?
42 OMAP4430_DPLL_CLKOUTX2_GATE_CTRL_MASK :
43 OMAP4430_DPLL_CLKOUT_GATE_CTRL_MASK;
45 v = __raw_readl(clk->clksel_reg);
46 v &= mask;
47 v >>= __ffs(mask);
49 return v;
52 void omap4_dpllmx_allow_gatectrl(struct clk_hw_omap *clk)
54 u32 v;
55 u32 mask;
57 if (!clk || !clk->clksel_reg || !cpu_is_omap44xx())
58 return;
60 mask = clk->flags & CLOCK_CLKOUTX2 ?
61 OMAP4430_DPLL_CLKOUTX2_GATE_CTRL_MASK :
62 OMAP4430_DPLL_CLKOUT_GATE_CTRL_MASK;
64 v = __raw_readl(clk->clksel_reg);
65 /* Clear the bit to allow gatectrl */
66 v &= ~mask;
67 __raw_writel(v, clk->clksel_reg);
70 void omap4_dpllmx_deny_gatectrl(struct clk_hw_omap *clk)
72 u32 v;
73 u32 mask;
75 if (!clk || !clk->clksel_reg || !cpu_is_omap44xx())
76 return;
78 mask = clk->flags & CLOCK_CLKOUTX2 ?
79 OMAP4430_DPLL_CLKOUTX2_GATE_CTRL_MASK :
80 OMAP4430_DPLL_CLKOUT_GATE_CTRL_MASK;
82 v = __raw_readl(clk->clksel_reg);
83 /* Set the bit to deny gatectrl */
84 v |= mask;
85 __raw_writel(v, clk->clksel_reg);
88 const struct clk_hw_omap_ops clkhwops_omap4_dpllmx = {
89 .allow_idle = omap4_dpllmx_allow_gatectrl,
90 .deny_idle = omap4_dpllmx_deny_gatectrl,
93 /**
94 * omap4_dpll_lpmode_recalc - compute DPLL low-power setting
95 * @dd: pointer to the dpll data structure
97 * Calculates if low-power mode can be enabled based upon the last
98 * multiplier and divider values calculated. If low-power mode can be
99 * enabled, then the bit to enable low-power mode is stored in the
100 * last_rounded_lpmode variable. This implementation is based upon the
101 * criteria for enabling low-power mode as described in the OMAP4430/60
102 * Public TRM section 3.6.3.3.2 "Enable Control, Status, and Low-Power
103 * Operation Mode".
105 static void omap4_dpll_lpmode_recalc(struct dpll_data *dd)
107 long fint, fout;
109 fint = __clk_get_rate(dd->clk_ref) / (dd->last_rounded_n + 1);
110 fout = fint * dd->last_rounded_m;
112 if ((fint < OMAP4_DPLL_LP_FINT_MAX) && (fout < OMAP4_DPLL_LP_FOUT_MAX))
113 dd->last_rounded_lpmode = 1;
114 else
115 dd->last_rounded_lpmode = 0;
119 * omap4_dpll_regm4xen_recalc - compute DPLL rate, considering REGM4XEN bit
120 * @clk: struct clk * of the DPLL to compute the rate for
122 * Compute the output rate for the OMAP4 DPLL represented by @clk.
123 * Takes the REGM4XEN bit into consideration, which is needed for the
124 * OMAP4 ABE DPLL. Returns the DPLL's output rate (before M-dividers)
125 * upon success, or 0 upon error.
127 unsigned long omap4_dpll_regm4xen_recalc(struct clk_hw *hw,
128 unsigned long parent_rate)
130 struct clk_hw_omap *clk = to_clk_hw_omap(hw);
131 u32 v;
132 unsigned long rate;
133 struct dpll_data *dd;
135 if (!clk || !clk->dpll_data)
136 return 0;
138 dd = clk->dpll_data;
140 rate = omap2_get_dpll_rate(clk);
142 /* regm4xen adds a multiplier of 4 to DPLL calculations */
143 v = __raw_readl(dd->control_reg);
144 if (v & OMAP4430_DPLL_REGM4XEN_MASK)
145 rate *= OMAP4430_REGM4XEN_MULT;
147 return rate;
151 * omap4_dpll_regm4xen_round_rate - round DPLL rate, considering REGM4XEN bit
152 * @clk: struct clk * of the DPLL to round a rate for
153 * @target_rate: the desired rate of the DPLL
155 * Compute the rate that would be programmed into the DPLL hardware
156 * for @clk if set_rate() were to be provided with the rate
157 * @target_rate. Takes the REGM4XEN bit into consideration, which is
158 * needed for the OMAP4 ABE DPLL. Returns the rounded rate (before
159 * M-dividers) upon success, -EINVAL if @clk is null or not a DPLL, or
160 * ~0 if an error occurred in omap2_dpll_round_rate().
162 long omap4_dpll_regm4xen_round_rate(struct clk_hw *hw,
163 unsigned long target_rate,
164 unsigned long *parent_rate)
166 struct clk_hw_omap *clk = to_clk_hw_omap(hw);
167 struct dpll_data *dd;
168 long r;
170 if (!clk || !clk->dpll_data)
171 return -EINVAL;
173 dd = clk->dpll_data;
175 dd->last_rounded_m4xen = 0;
178 * First try to compute the DPLL configuration for
179 * target rate without using the 4X multiplier.
181 r = omap2_dpll_round_rate(hw, target_rate, NULL);
182 if (r != ~0)
183 goto out;
186 * If we did not find a valid DPLL configuration, try again, but
187 * this time see if using the 4X multiplier can help. Enabling the
188 * 4X multiplier is equivalent to dividing the target rate by 4.
190 r = omap2_dpll_round_rate(hw, target_rate / OMAP4430_REGM4XEN_MULT,
191 NULL);
192 if (r == ~0)
193 return r;
195 dd->last_rounded_rate *= OMAP4430_REGM4XEN_MULT;
196 dd->last_rounded_m4xen = 1;
198 out:
199 omap4_dpll_lpmode_recalc(dd);
201 return dd->last_rounded_rate;