Rajendra Nayak | 97f6789 | 2011-02-25 15:49:01 -0700 | [diff] [blame] | 1 | /* |
| 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 Lindgren | dbc0416 | 2012-08-31 10:59:07 -0700 | [diff] [blame] | 18 | #include "soc.h" |
Rajendra Nayak | 97f6789 | 2011-02-25 15:49:01 -0700 | [diff] [blame] | 19 | #include "clock.h" |
Mike Turquette | a1900f2 | 2011-10-07 00:52:58 -0600 | [diff] [blame] | 20 | #include "clock44xx.h" |
Rajendra Nayak | 97f6789 | 2011-02-25 15:49:01 -0700 | [diff] [blame] | 21 | #include "cm-regbits-44xx.h" |
| 22 | |
| 23 | /* Supported only on OMAP4 */ |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame^] | 24 | #ifdef CONFIG_COMMON_CLK |
| 25 | int omap4_dpllmx_gatectrl_read(struct clk_hw_omap *clk) |
| 26 | #else |
Rajendra Nayak | 97f6789 | 2011-02-25 15:49:01 -0700 | [diff] [blame] | 27 | int omap4_dpllmx_gatectrl_read(struct clk *clk) |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame^] | 28 | #endif |
Rajendra Nayak | 97f6789 | 2011-02-25 15:49:01 -0700 | [diff] [blame] | 29 | { |
| 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 Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame^] | 47 | #ifdef CONFIG_COMMON_CLK |
| 48 | void omap4_dpllmx_allow_gatectrl(struct clk_hw_omap *clk) |
| 49 | #else |
Rajendra Nayak | 97f6789 | 2011-02-25 15:49:01 -0700 | [diff] [blame] | 50 | void omap4_dpllmx_allow_gatectrl(struct clk *clk) |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame^] | 51 | #endif |
Rajendra Nayak | 97f6789 | 2011-02-25 15:49:01 -0700 | [diff] [blame] | 52 | { |
| 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 Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame^] | 69 | #ifdef CONFIG_COMMON_CLK |
| 70 | void omap4_dpllmx_deny_gatectrl(struct clk_hw_omap *clk) |
| 71 | #else |
Rajendra Nayak | 97f6789 | 2011-02-25 15:49:01 -0700 | [diff] [blame] | 72 | void omap4_dpllmx_deny_gatectrl(struct clk *clk) |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame^] | 73 | #endif |
Rajendra Nayak | 97f6789 | 2011-02-25 15:49:01 -0700 | [diff] [blame] | 74 | { |
| 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 Nayak | 70db8a6 | 2011-02-25 15:49:02 -0700 | [diff] [blame] | 90 | |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame^] | 91 | #ifdef CONFIG_COMMON_CLK |
| 92 | const 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 Nayak | 70db8a6 | 2011-02-25 15:49:02 -0700 | [diff] [blame] | 97 | const struct clkops clkops_omap4_dpllmx_ops = { |
| 98 | .allow_idle = omap4_dpllmx_allow_gatectrl, |
| 99 | .deny_idle = omap4_dpllmx_deny_gatectrl, |
| 100 | }; |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame^] | 101 | #endif |
Rajendra Nayak | 70db8a6 | 2011-02-25 15:49:02 -0700 | [diff] [blame] | 102 | |
Mike Turquette | a1900f2 | 2011-10-07 00:52:58 -0600 | [diff] [blame] | 103 | /** |
| 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 Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame^] | 112 | #ifdef CONFIG_COMMON_CLK |
| 113 | unsigned 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 Turquette | a1900f2 | 2011-10-07 00:52:58 -0600 | [diff] [blame] | 118 | unsigned long omap4_dpll_regm4xen_recalc(struct clk *clk) |
| 119 | { |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame^] | 120 | #endif |
Mike Turquette | a1900f2 | 2011-10-07 00:52:58 -0600 | [diff] [blame] | 121 | 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 Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame^] | 152 | #ifdef CONFIG_COMMON_CLK |
| 153 | long 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 Turquette | a1900f2 | 2011-10-07 00:52:58 -0600 | [diff] [blame] | 159 | long omap4_dpll_regm4xen_round_rate(struct clk *clk, unsigned long target_rate) |
| 160 | { |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame^] | 161 | #endif |
Mike Turquette | a1900f2 | 2011-10-07 00:52:58 -0600 | [diff] [blame] | 162 | 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 Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame^] | 177 | #ifdef CONFIG_COMMON_CLK |
| 178 | r = omap2_dpll_round_rate(hw, target_rate, NULL); |
| 179 | #else |
Mike Turquette | a1900f2 | 2011-10-07 00:52:58 -0600 | [diff] [blame] | 180 | r = omap2_dpll_round_rate(clk, target_rate); |
Mike Turquette | 32cc002 | 2012-11-10 16:58:41 -0700 | [diff] [blame^] | 181 | #endif |
Mike Turquette | a1900f2 | 2011-10-07 00:52:58 -0600 | [diff] [blame] | 182 | 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 | } |