2 * OMAP4-specific DPLL control functions
4 * Copyright (C) 2011 Texas Instruments, Inc.
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>
16 #include <linux/bitops.h>
20 #include "clock44xx.h"
21 #include "cm-regbits-44xx.h"
23 /* Supported only on OMAP4 */
24 int omap4_dpllmx_gatectrl_read(struct clk *clk)
29 if (!clk || !clk->clksel_reg || !cpu_is_omap44xx())
32 mask = clk->flags & CLOCK_CLKOUTX2 ?
33 OMAP4430_DPLL_CLKOUTX2_GATE_CTRL_MASK :
34 OMAP4430_DPLL_CLKOUT_GATE_CTRL_MASK;
36 v = __raw_readl(clk->clksel_reg);
43 void omap4_dpllmx_allow_gatectrl(struct clk *clk)
48 if (!clk || !clk->clksel_reg || !cpu_is_omap44xx())
51 mask = clk->flags & CLOCK_CLKOUTX2 ?
52 OMAP4430_DPLL_CLKOUTX2_GATE_CTRL_MASK :
53 OMAP4430_DPLL_CLKOUT_GATE_CTRL_MASK;
55 v = __raw_readl(clk->clksel_reg);
56 /* Clear the bit to allow gatectrl */
58 __raw_writel(v, clk->clksel_reg);
61 void omap4_dpllmx_deny_gatectrl(struct clk *clk)
66 if (!clk || !clk->clksel_reg || !cpu_is_omap44xx())
69 mask = clk->flags & CLOCK_CLKOUTX2 ?
70 OMAP4430_DPLL_CLKOUTX2_GATE_CTRL_MASK :
71 OMAP4430_DPLL_CLKOUT_GATE_CTRL_MASK;
73 v = __raw_readl(clk->clksel_reg);
74 /* Set the bit to deny gatectrl */
76 __raw_writel(v, clk->clksel_reg);
79 const struct clkops clkops_omap4_dpllmx_ops = {
80 .allow_idle = omap4_dpllmx_allow_gatectrl,
81 .deny_idle = omap4_dpllmx_deny_gatectrl,
85 * omap4_dpll_regm4xen_recalc - compute DPLL rate, considering REGM4XEN bit
86 * @clk: struct clk * of the DPLL to compute the rate for
88 * Compute the output rate for the OMAP4 DPLL represented by @clk.
89 * Takes the REGM4XEN bit into consideration, which is needed for the
90 * OMAP4 ABE DPLL. Returns the DPLL's output rate (before M-dividers)
91 * upon success, or 0 upon error.
93 unsigned long omap4_dpll_regm4xen_recalc(struct clk *clk)
99 if (!clk || !clk->dpll_data)
104 rate = omap2_get_dpll_rate(clk);
106 /* regm4xen adds a multiplier of 4 to DPLL calculations */
107 v = __raw_readl(dd->control_reg);
108 if (v & OMAP4430_DPLL_REGM4XEN_MASK)
109 rate *= OMAP4430_REGM4XEN_MULT;
115 * omap4_dpll_regm4xen_round_rate - round DPLL rate, considering REGM4XEN bit
116 * @clk: struct clk * of the DPLL to round a rate for
117 * @target_rate: the desired rate of the DPLL
119 * Compute the rate that would be programmed into the DPLL hardware
120 * for @clk if set_rate() were to be provided with the rate
121 * @target_rate. Takes the REGM4XEN bit into consideration, which is
122 * needed for the OMAP4 ABE DPLL. Returns the rounded rate (before
123 * M-dividers) upon success, -EINVAL if @clk is null or not a DPLL, or
124 * ~0 if an error occurred in omap2_dpll_round_rate().
126 long omap4_dpll_regm4xen_round_rate(struct clk *clk, unsigned long target_rate)
129 struct dpll_data *dd;
132 if (!clk || !clk->dpll_data)
137 /* regm4xen adds a multiplier of 4 to DPLL calculations */
138 v = __raw_readl(dd->control_reg) & OMAP4430_DPLL_REGM4XEN_MASK;
141 target_rate = target_rate / OMAP4430_REGM4XEN_MULT;
143 r = omap2_dpll_round_rate(clk, target_rate);
148 clk->dpll_data->last_rounded_rate *= OMAP4430_REGM4XEN_MULT;
150 return clk->dpll_data->last_rounded_rate;