blob: aa75a3c100267942f36b01f2611034427b95f2b8 [file] [log] [blame]
Rajendra Nayak97f67892011-02-25 15:49:01 -07001/*
2 * OMAP4-specific DPLL control functions
3 *
4 * Copyright (C) 2011 Texas Instruments, Inc.
5 * Rajendra Nayak
6 *
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.
10 */
11
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>
17
Tony Lindgrendbc04162012-08-31 10:59:07 -070018#include "soc.h"
Rajendra Nayak97f67892011-02-25 15:49:01 -070019#include "clock.h"
Mike Turquettea1900f22011-10-07 00:52:58 -060020#include "clock44xx.h"
Rajendra Nayak97f67892011-02-25 15:49:01 -070021#include "cm-regbits-44xx.h"
22
23/* Supported only on OMAP4 */
Mike Turquette32cc0022012-11-10 16:58:41 -070024#ifdef CONFIG_COMMON_CLK
25int omap4_dpllmx_gatectrl_read(struct clk_hw_omap *clk)
26#else
Rajendra Nayak97f67892011-02-25 15:49:01 -070027int omap4_dpllmx_gatectrl_read(struct clk *clk)
Mike Turquette32cc0022012-11-10 16:58:41 -070028#endif
Rajendra Nayak97f67892011-02-25 15:49:01 -070029{
30 u32 v;
31 u32 mask;
32
33 if (!clk || !clk->clksel_reg || !cpu_is_omap44xx())
34 return -EINVAL;
35
36 mask = clk->flags & CLOCK_CLKOUTX2 ?
37 OMAP4430_DPLL_CLKOUTX2_GATE_CTRL_MASK :
38 OMAP4430_DPLL_CLKOUT_GATE_CTRL_MASK;
39
40 v = __raw_readl(clk->clksel_reg);
41 v &= mask;
42 v >>= __ffs(mask);
43
44 return v;
45}
46
Mike Turquette32cc0022012-11-10 16:58:41 -070047#ifdef CONFIG_COMMON_CLK
48void omap4_dpllmx_allow_gatectrl(struct clk_hw_omap *clk)
49#else
Rajendra Nayak97f67892011-02-25 15:49:01 -070050void omap4_dpllmx_allow_gatectrl(struct clk *clk)
Mike Turquette32cc0022012-11-10 16:58:41 -070051#endif
Rajendra Nayak97f67892011-02-25 15:49:01 -070052{
53 u32 v;
54 u32 mask;
55
56 if (!clk || !clk->clksel_reg || !cpu_is_omap44xx())
57 return;
58
59 mask = clk->flags & CLOCK_CLKOUTX2 ?
60 OMAP4430_DPLL_CLKOUTX2_GATE_CTRL_MASK :
61 OMAP4430_DPLL_CLKOUT_GATE_CTRL_MASK;
62
63 v = __raw_readl(clk->clksel_reg);
64 /* Clear the bit to allow gatectrl */
65 v &= ~mask;
66 __raw_writel(v, clk->clksel_reg);
67}
68
Mike Turquette32cc0022012-11-10 16:58:41 -070069#ifdef CONFIG_COMMON_CLK
70void omap4_dpllmx_deny_gatectrl(struct clk_hw_omap *clk)
71#else
Rajendra Nayak97f67892011-02-25 15:49:01 -070072void omap4_dpllmx_deny_gatectrl(struct clk *clk)
Mike Turquette32cc0022012-11-10 16:58:41 -070073#endif
Rajendra Nayak97f67892011-02-25 15:49:01 -070074{
75 u32 v;
76 u32 mask;
77
78 if (!clk || !clk->clksel_reg || !cpu_is_omap44xx())
79 return;
80
81 mask = clk->flags & CLOCK_CLKOUTX2 ?
82 OMAP4430_DPLL_CLKOUTX2_GATE_CTRL_MASK :
83 OMAP4430_DPLL_CLKOUT_GATE_CTRL_MASK;
84
85 v = __raw_readl(clk->clksel_reg);
86 /* Set the bit to deny gatectrl */
87 v |= mask;
88 __raw_writel(v, clk->clksel_reg);
89}
Rajendra Nayak70db8a62011-02-25 15:49:02 -070090
Mike Turquette32cc0022012-11-10 16:58:41 -070091#ifdef CONFIG_COMMON_CLK
92const struct clk_hw_omap_ops clkhwops_omap4_dpllmx = {
93 .allow_idle = omap4_dpllmx_allow_gatectrl,
94 .deny_idle = omap4_dpllmx_deny_gatectrl,
95};
96#else
Rajendra Nayak70db8a62011-02-25 15:49:02 -070097const struct clkops clkops_omap4_dpllmx_ops = {
98 .allow_idle = omap4_dpllmx_allow_gatectrl,
99 .deny_idle = omap4_dpllmx_deny_gatectrl,
100};
Mike Turquette32cc0022012-11-10 16:58:41 -0700101#endif
Rajendra Nayak70db8a62011-02-25 15:49:02 -0700102
Mike Turquettea1900f22011-10-07 00:52:58 -0600103/**
104 * omap4_dpll_regm4xen_recalc - compute DPLL rate, considering REGM4XEN bit
105 * @clk: struct clk * of the DPLL to compute the rate for
106 *
107 * Compute the output rate for the OMAP4 DPLL represented by @clk.
108 * Takes the REGM4XEN bit into consideration, which is needed for the
109 * OMAP4 ABE DPLL. Returns the DPLL's output rate (before M-dividers)
110 * upon success, or 0 upon error.
111 */
Mike Turquette32cc0022012-11-10 16:58:41 -0700112#ifdef CONFIG_COMMON_CLK
113unsigned long omap4_dpll_regm4xen_recalc(struct clk_hw *hw,
114 unsigned long parent_rate)
115{
116 struct clk_hw_omap *clk = to_clk_hw_omap(hw);
117#else
Mike Turquettea1900f22011-10-07 00:52:58 -0600118unsigned long omap4_dpll_regm4xen_recalc(struct clk *clk)
119{
Mike Turquette32cc0022012-11-10 16:58:41 -0700120#endif
Mike Turquettea1900f22011-10-07 00:52:58 -0600121 u32 v;
122 unsigned long rate;
123 struct dpll_data *dd;
124
125 if (!clk || !clk->dpll_data)
126 return 0;
127
128 dd = clk->dpll_data;
129
130 rate = omap2_get_dpll_rate(clk);
131
132 /* regm4xen adds a multiplier of 4 to DPLL calculations */
133 v = __raw_readl(dd->control_reg);
134 if (v & OMAP4430_DPLL_REGM4XEN_MASK)
135 rate *= OMAP4430_REGM4XEN_MULT;
136
137 return rate;
138}
139
140/**
141 * omap4_dpll_regm4xen_round_rate - round DPLL rate, considering REGM4XEN bit
142 * @clk: struct clk * of the DPLL to round a rate for
143 * @target_rate: the desired rate of the DPLL
144 *
145 * Compute the rate that would be programmed into the DPLL hardware
146 * for @clk if set_rate() were to be provided with the rate
147 * @target_rate. Takes the REGM4XEN bit into consideration, which is
148 * needed for the OMAP4 ABE DPLL. Returns the rounded rate (before
149 * M-dividers) upon success, -EINVAL if @clk is null or not a DPLL, or
150 * ~0 if an error occurred in omap2_dpll_round_rate().
151 */
Mike Turquette32cc0022012-11-10 16:58:41 -0700152#ifdef CONFIG_COMMON_CLK
153long omap4_dpll_regm4xen_round_rate(struct clk_hw *hw,
154 unsigned long target_rate,
155 unsigned long *parent_rate)
156{
157 struct clk_hw_omap *clk = to_clk_hw_omap(hw);
158#else
Mike Turquettea1900f22011-10-07 00:52:58 -0600159long omap4_dpll_regm4xen_round_rate(struct clk *clk, unsigned long target_rate)
160{
Mike Turquette32cc0022012-11-10 16:58:41 -0700161#endif
Mike Turquettea1900f22011-10-07 00:52:58 -0600162 u32 v;
163 struct dpll_data *dd;
164 long r;
165
166 if (!clk || !clk->dpll_data)
167 return -EINVAL;
168
169 dd = clk->dpll_data;
170
171 /* regm4xen adds a multiplier of 4 to DPLL calculations */
172 v = __raw_readl(dd->control_reg) & OMAP4430_DPLL_REGM4XEN_MASK;
173
174 if (v)
175 target_rate = target_rate / OMAP4430_REGM4XEN_MULT;
176
Mike Turquette32cc0022012-11-10 16:58:41 -0700177#ifdef CONFIG_COMMON_CLK
178 r = omap2_dpll_round_rate(hw, target_rate, NULL);
179#else
Mike Turquettea1900f22011-10-07 00:52:58 -0600180 r = omap2_dpll_round_rate(clk, target_rate);
Mike Turquette32cc0022012-11-10 16:58:41 -0700181#endif
Mike Turquettea1900f22011-10-07 00:52:58 -0600182 if (r == ~0)
183 return r;
184
185 if (v)
186 clk->dpll_data->last_rounded_rate *= OMAP4430_REGM4XEN_MULT;
187
188 return clk->dpll_data->last_rounded_rate;
189}