Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1 | /* |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2 | * arch/arm/mach-tegra/tegra20_clocks.c |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2010 Google, Inc. |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 5 | * Copyright (c) 2010-2012 NVIDIA CORPORATION. All rights reserved. |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 6 | * |
| 7 | * Author: |
| 8 | * Colin Cross <ccross@google.com> |
| 9 | * |
| 10 | * This software is licensed under the terms of the GNU General Public |
| 11 | * License version 2, as published by the Free Software Foundation, and |
| 12 | * may be copied, distributed, and modified under those terms. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | #include <linux/kernel.h> |
| 22 | #include <linux/module.h> |
| 23 | #include <linux/list.h> |
| 24 | #include <linux/spinlock.h> |
| 25 | #include <linux/delay.h> |
| 26 | #include <linux/io.h> |
Jean-Christop PLAGNIOL-VILLARD | 6d803ba | 2010-11-17 10:04:33 +0100 | [diff] [blame] | 27 | #include <linux/clkdev.h> |
Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 28 | #include <linux/clk.h> |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 29 | |
| 30 | #include <mach/iomap.h> |
Colin Cross | 2ea67fd | 2010-10-04 08:49:49 -0700 | [diff] [blame] | 31 | #include <mach/suspend.h> |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 32 | |
| 33 | #include "clock.h" |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 34 | #include "fuse.h" |
Colin Cross | 6d29682 | 2010-11-22 18:37:54 -0800 | [diff] [blame] | 35 | #include "tegra2_emc.h" |
Joseph Lo | dab403e | 2012-08-16 17:31:48 +0800 | [diff] [blame^] | 36 | #include "tegra_cpu_car.h" |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 37 | |
| 38 | #define RST_DEVICES 0x004 |
| 39 | #define RST_DEVICES_SET 0x300 |
| 40 | #define RST_DEVICES_CLR 0x304 |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 41 | #define RST_DEVICES_NUM 3 |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 42 | |
| 43 | #define CLK_OUT_ENB 0x010 |
| 44 | #define CLK_OUT_ENB_SET 0x320 |
| 45 | #define CLK_OUT_ENB_CLR 0x324 |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 46 | #define CLK_OUT_ENB_NUM 3 |
| 47 | |
| 48 | #define CLK_MASK_ARM 0x44 |
| 49 | #define MISC_CLK_ENB 0x48 |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 50 | |
| 51 | #define OSC_CTRL 0x50 |
| 52 | #define OSC_CTRL_OSC_FREQ_MASK (3<<30) |
| 53 | #define OSC_CTRL_OSC_FREQ_13MHZ (0<<30) |
| 54 | #define OSC_CTRL_OSC_FREQ_19_2MHZ (1<<30) |
| 55 | #define OSC_CTRL_OSC_FREQ_12MHZ (2<<30) |
| 56 | #define OSC_CTRL_OSC_FREQ_26MHZ (3<<30) |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 57 | #define OSC_CTRL_MASK (0x3f2 | OSC_CTRL_OSC_FREQ_MASK) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 58 | |
| 59 | #define OSC_FREQ_DET 0x58 |
| 60 | #define OSC_FREQ_DET_TRIG (1<<31) |
| 61 | |
| 62 | #define OSC_FREQ_DET_STATUS 0x5C |
| 63 | #define OSC_FREQ_DET_BUSY (1<<31) |
| 64 | #define OSC_FREQ_DET_CNT_MASK 0xFFFF |
| 65 | |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 66 | #define PERIPH_CLK_SOURCE_I2S1 0x100 |
| 67 | #define PERIPH_CLK_SOURCE_EMC 0x19c |
| 68 | #define PERIPH_CLK_SOURCE_OSC 0x1fc |
| 69 | #define PERIPH_CLK_SOURCE_NUM \ |
| 70 | ((PERIPH_CLK_SOURCE_OSC - PERIPH_CLK_SOURCE_I2S1) / 4) |
| 71 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 72 | #define PERIPH_CLK_SOURCE_MASK (3<<30) |
| 73 | #define PERIPH_CLK_SOURCE_SHIFT 30 |
Simon Que | bb1dccf | 2011-12-16 20:11:22 +0100 | [diff] [blame] | 74 | #define PERIPH_CLK_SOURCE_PWM_MASK (7<<28) |
| 75 | #define PERIPH_CLK_SOURCE_PWM_SHIFT 28 |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 76 | #define PERIPH_CLK_SOURCE_ENABLE (1<<28) |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 77 | #define PERIPH_CLK_SOURCE_DIVU71_MASK 0xFF |
| 78 | #define PERIPH_CLK_SOURCE_DIVU16_MASK 0xFFFF |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 79 | #define PERIPH_CLK_SOURCE_DIV_SHIFT 0 |
| 80 | |
Colin Cross | 9743b38 | 2011-02-12 18:24:32 -0800 | [diff] [blame] | 81 | #define SDMMC_CLK_INT_FB_SEL (1 << 23) |
| 82 | #define SDMMC_CLK_INT_FB_DLY_SHIFT 16 |
| 83 | #define SDMMC_CLK_INT_FB_DLY_MASK (0xF << SDMMC_CLK_INT_FB_DLY_SHIFT) |
| 84 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 85 | #define PLL_BASE 0x0 |
| 86 | #define PLL_BASE_BYPASS (1<<31) |
| 87 | #define PLL_BASE_ENABLE (1<<30) |
| 88 | #define PLL_BASE_REF_ENABLE (1<<29) |
| 89 | #define PLL_BASE_OVERRIDE (1<<28) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 90 | #define PLL_BASE_DIVP_MASK (0x7<<20) |
| 91 | #define PLL_BASE_DIVP_SHIFT 20 |
| 92 | #define PLL_BASE_DIVN_MASK (0x3FF<<8) |
| 93 | #define PLL_BASE_DIVN_SHIFT 8 |
| 94 | #define PLL_BASE_DIVM_MASK (0x1F) |
| 95 | #define PLL_BASE_DIVM_SHIFT 0 |
| 96 | |
| 97 | #define PLL_OUT_RATIO_MASK (0xFF<<8) |
| 98 | #define PLL_OUT_RATIO_SHIFT 8 |
| 99 | #define PLL_OUT_OVERRIDE (1<<2) |
| 100 | #define PLL_OUT_CLKEN (1<<1) |
| 101 | #define PLL_OUT_RESET_DISABLE (1<<0) |
| 102 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 103 | #define PLL_MISC(c) (((c)->flags & PLL_ALT_MISC_REG) ? 0x4 : 0xc) |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 104 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 105 | #define PLL_MISC_DCCON_SHIFT 20 |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 106 | #define PLL_MISC_CPCON_SHIFT 8 |
| 107 | #define PLL_MISC_CPCON_MASK (0xF<<PLL_MISC_CPCON_SHIFT) |
| 108 | #define PLL_MISC_LFCON_SHIFT 4 |
| 109 | #define PLL_MISC_LFCON_MASK (0xF<<PLL_MISC_LFCON_SHIFT) |
| 110 | #define PLL_MISC_VCOCON_SHIFT 0 |
| 111 | #define PLL_MISC_VCOCON_MASK (0xF<<PLL_MISC_VCOCON_SHIFT) |
| 112 | |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 113 | #define PLLU_BASE_POST_DIV (1<<20) |
| 114 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 115 | #define PLLD_MISC_CLKENABLE (1<<30) |
| 116 | #define PLLD_MISC_DIV_RST (1<<23) |
| 117 | #define PLLD_MISC_DCCON_SHIFT 12 |
| 118 | |
Mike Rapoport | 8d685bc | 2010-09-27 11:26:32 +0200 | [diff] [blame] | 119 | #define PLLE_MISC_READY (1 << 15) |
| 120 | |
Colin Cross | f151961 | 2011-02-12 16:05:31 -0800 | [diff] [blame] | 121 | #define PERIPH_CLK_TO_ENB_REG(c) ((c->u.periph.clk_num / 32) * 4) |
| 122 | #define PERIPH_CLK_TO_ENB_SET_REG(c) ((c->u.periph.clk_num / 32) * 8) |
| 123 | #define PERIPH_CLK_TO_ENB_BIT(c) (1 << (c->u.periph.clk_num % 32)) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 124 | |
| 125 | #define SUPER_CLK_MUX 0x00 |
| 126 | #define SUPER_STATE_SHIFT 28 |
| 127 | #define SUPER_STATE_MASK (0xF << SUPER_STATE_SHIFT) |
| 128 | #define SUPER_STATE_STANDBY (0x0 << SUPER_STATE_SHIFT) |
| 129 | #define SUPER_STATE_IDLE (0x1 << SUPER_STATE_SHIFT) |
| 130 | #define SUPER_STATE_RUN (0x2 << SUPER_STATE_SHIFT) |
| 131 | #define SUPER_STATE_IRQ (0x3 << SUPER_STATE_SHIFT) |
| 132 | #define SUPER_STATE_FIQ (0x4 << SUPER_STATE_SHIFT) |
| 133 | #define SUPER_SOURCE_MASK 0xF |
| 134 | #define SUPER_FIQ_SOURCE_SHIFT 12 |
| 135 | #define SUPER_IRQ_SOURCE_SHIFT 8 |
| 136 | #define SUPER_RUN_SOURCE_SHIFT 4 |
| 137 | #define SUPER_IDLE_SOURCE_SHIFT 0 |
| 138 | |
| 139 | #define SUPER_CLK_DIVIDER 0x04 |
| 140 | |
| 141 | #define BUS_CLK_DISABLE (1<<3) |
| 142 | #define BUS_CLK_DIV_MASK 0x3 |
| 143 | |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 144 | #define PMC_CTRL 0x0 |
| 145 | #define PMC_CTRL_BLINK_ENB (1 << 7) |
| 146 | |
| 147 | #define PMC_DPD_PADS_ORIDE 0x1c |
| 148 | #define PMC_DPD_PADS_ORIDE_BLINK_ENB (1 << 20) |
| 149 | |
| 150 | #define PMC_BLINK_TIMER_DATA_ON_SHIFT 0 |
| 151 | #define PMC_BLINK_TIMER_DATA_ON_MASK 0x7fff |
| 152 | #define PMC_BLINK_TIMER_ENB (1 << 15) |
| 153 | #define PMC_BLINK_TIMER_DATA_OFF_SHIFT 16 |
| 154 | #define PMC_BLINK_TIMER_DATA_OFF_MASK 0xffff |
| 155 | |
Joseph Lo | dab403e | 2012-08-16 17:31:48 +0800 | [diff] [blame^] | 156 | /* Tegra CPU clock and reset control regs */ |
| 157 | #define TEGRA_CLK_RST_CONTROLLER_CLK_CPU_CMPLX 0x4c |
| 158 | #define TEGRA_CLK_RST_CONTROLLER_RST_CPU_CMPLX_SET 0x340 |
| 159 | #define TEGRA_CLK_RST_CONTROLLER_RST_CPU_CMPLX_CLR 0x344 |
| 160 | |
| 161 | #define CPU_CLOCK(cpu) (0x1 << (8 + cpu)) |
| 162 | #define CPU_RESET(cpu) (0x1111ul << (cpu)) |
| 163 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 164 | static void __iomem *reg_clk_base = IO_ADDRESS(TEGRA_CLK_RESET_BASE); |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 165 | static void __iomem *reg_pmc_base = IO_ADDRESS(TEGRA_PMC_BASE); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 166 | |
Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 167 | /* |
| 168 | * Some clocks share a register with other clocks. Any clock op that |
| 169 | * non-atomically modifies a register used by another clock must lock |
| 170 | * clock_register_lock first. |
| 171 | */ |
| 172 | static DEFINE_SPINLOCK(clock_register_lock); |
| 173 | |
Colin Cross | 78f379b | 2010-10-20 19:19:58 -0700 | [diff] [blame] | 174 | /* |
| 175 | * Some peripheral clocks share an enable bit, so refcount the enable bits |
| 176 | * in registers CLK_ENABLE_L, CLK_ENABLE_H, and CLK_ENABLE_U |
| 177 | */ |
| 178 | static int tegra_periph_clk_enable_refcount[3 * 32]; |
| 179 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 180 | #define clk_writel(value, reg) \ |
Olof Johansson | d395935 | 2011-09-08 17:56:59 -0700 | [diff] [blame] | 181 | __raw_writel(value, reg_clk_base + (reg)) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 182 | #define clk_readl(reg) \ |
Olof Johansson | d395935 | 2011-09-08 17:56:59 -0700 | [diff] [blame] | 183 | __raw_readl(reg_clk_base + (reg)) |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 184 | #define pmc_writel(value, reg) \ |
Olof Johansson | d395935 | 2011-09-08 17:56:59 -0700 | [diff] [blame] | 185 | __raw_writel(value, reg_pmc_base + (reg)) |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 186 | #define pmc_readl(reg) \ |
Olof Johansson | d395935 | 2011-09-08 17:56:59 -0700 | [diff] [blame] | 187 | __raw_readl(reg_pmc_base + (reg)) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 188 | |
Peter De Schrijver | 8e4fab2 | 2011-12-14 17:03:16 +0200 | [diff] [blame] | 189 | static unsigned long clk_measure_input_freq(void) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 190 | { |
| 191 | u32 clock_autodetect; |
| 192 | clk_writel(OSC_FREQ_DET_TRIG | 1, OSC_FREQ_DET); |
| 193 | do {} while (clk_readl(OSC_FREQ_DET_STATUS) & OSC_FREQ_DET_BUSY); |
| 194 | clock_autodetect = clk_readl(OSC_FREQ_DET_STATUS); |
| 195 | if (clock_autodetect >= 732 - 3 && clock_autodetect <= 732 + 3) { |
| 196 | return 12000000; |
| 197 | } else if (clock_autodetect >= 794 - 3 && clock_autodetect <= 794 + 3) { |
| 198 | return 13000000; |
| 199 | } else if (clock_autodetect >= 1172 - 3 && clock_autodetect <= 1172 + 3) { |
| 200 | return 19200000; |
| 201 | } else if (clock_autodetect >= 1587 - 3 && clock_autodetect <= 1587 + 3) { |
| 202 | return 26000000; |
| 203 | } else { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 204 | pr_err("%s: Unexpected clock autodetect value %d", |
| 205 | __func__, clock_autodetect); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 206 | BUG(); |
| 207 | return 0; |
| 208 | } |
| 209 | } |
| 210 | |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 211 | static int clk_div71_get_divider(unsigned long parent_rate, unsigned long rate) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 212 | { |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 213 | s64 divider_u71 = parent_rate * 2; |
| 214 | divider_u71 += rate - 1; |
| 215 | do_div(divider_u71, rate); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 216 | |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 217 | if (divider_u71 - 2 < 0) |
| 218 | return 0; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 219 | |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 220 | if (divider_u71 - 2 > 255) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 221 | return -EINVAL; |
| 222 | |
| 223 | return divider_u71 - 2; |
| 224 | } |
| 225 | |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 226 | static int clk_div16_get_divider(unsigned long parent_rate, unsigned long rate) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 227 | { |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 228 | s64 divider_u16; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 229 | |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 230 | divider_u16 = parent_rate; |
| 231 | divider_u16 += rate - 1; |
| 232 | do_div(divider_u16, rate); |
| 233 | |
| 234 | if (divider_u16 - 1 < 0) |
| 235 | return 0; |
| 236 | |
Stephen Warren | eb70e1b | 2012-07-24 15:48:12 -0600 | [diff] [blame] | 237 | if (divider_u16 - 1 > 0xFFFF) |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 238 | return -EINVAL; |
| 239 | |
| 240 | return divider_u16 - 1; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 241 | } |
| 242 | |
Joseph Lo | b78c030 | 2012-08-17 14:51:21 +0800 | [diff] [blame] | 243 | static unsigned long tegra_clk_fixed_recalc_rate(struct clk_hw *hw, |
| 244 | unsigned long parent_rate) |
| 245 | { |
| 246 | return to_clk_tegra(hw)->fixed_rate; |
| 247 | } |
| 248 | |
| 249 | struct clk_ops tegra_clk_32k_ops = { |
| 250 | .recalc_rate = tegra_clk_fixed_recalc_rate, |
| 251 | }; |
| 252 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 253 | /* clk_m functions */ |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 254 | static unsigned long tegra20_clk_m_recalc_rate(struct clk_hw *hw, |
| 255 | unsigned long prate) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 256 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 257 | if (!to_clk_tegra(hw)->fixed_rate) |
| 258 | to_clk_tegra(hw)->fixed_rate = clk_measure_input_freq(); |
| 259 | return to_clk_tegra(hw)->fixed_rate; |
| 260 | } |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 261 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 262 | static void tegra20_clk_m_init(struct clk_hw *hw) |
| 263 | { |
| 264 | struct clk_tegra *c = to_clk_tegra(hw); |
| 265 | u32 osc_ctrl = clk_readl(OSC_CTRL); |
| 266 | u32 auto_clock_control = osc_ctrl & ~OSC_CTRL_OSC_FREQ_MASK; |
| 267 | |
| 268 | switch (c->fixed_rate) { |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 269 | case 12000000: |
| 270 | auto_clock_control |= OSC_CTRL_OSC_FREQ_12MHZ; |
| 271 | break; |
| 272 | case 13000000: |
| 273 | auto_clock_control |= OSC_CTRL_OSC_FREQ_13MHZ; |
| 274 | break; |
| 275 | case 19200000: |
| 276 | auto_clock_control |= OSC_CTRL_OSC_FREQ_19_2MHZ; |
| 277 | break; |
| 278 | case 26000000: |
| 279 | auto_clock_control |= OSC_CTRL_OSC_FREQ_26MHZ; |
| 280 | break; |
| 281 | default: |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 282 | BUG(); |
| 283 | } |
| 284 | clk_writel(auto_clock_control, OSC_CTRL); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 285 | } |
| 286 | |
Prashant Gaikwad | 86edb87 | 2012-08-06 11:57:40 +0530 | [diff] [blame] | 287 | struct clk_ops tegra_clk_m_ops = { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 288 | .init = tegra20_clk_m_init, |
| 289 | .recalc_rate = tegra20_clk_m_recalc_rate, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 290 | }; |
| 291 | |
| 292 | /* super clock functions */ |
| 293 | /* "super clocks" on tegra have two-stage muxes and a clock skipping |
| 294 | * super divider. We will ignore the clock skipping divider, since we |
| 295 | * can't lower the voltage when using the clock skip, but we can if we |
| 296 | * lower the PLL frequency. |
| 297 | */ |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 298 | static int tegra20_super_clk_is_enabled(struct clk_hw *hw) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 299 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 300 | struct clk_tegra *c = to_clk_tegra(hw); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 301 | u32 val; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 302 | |
| 303 | val = clk_readl(c->reg + SUPER_CLK_MUX); |
| 304 | BUG_ON(((val & SUPER_STATE_MASK) != SUPER_STATE_RUN) && |
| 305 | ((val & SUPER_STATE_MASK) != SUPER_STATE_IDLE)); |
| 306 | c->state = ON; |
| 307 | return c->state; |
| 308 | } |
| 309 | |
| 310 | static int tegra20_super_clk_enable(struct clk_hw *hw) |
| 311 | { |
| 312 | struct clk_tegra *c = to_clk_tegra(hw); |
| 313 | clk_writel(0, c->reg + SUPER_CLK_DIVIDER); |
| 314 | return 0; |
| 315 | } |
| 316 | |
| 317 | static void tegra20_super_clk_disable(struct clk_hw *hw) |
| 318 | { |
| 319 | pr_debug("%s on clock %s\n", __func__, __clk_get_name(hw->clk)); |
| 320 | |
| 321 | /* oops - don't disable the CPU clock! */ |
| 322 | BUG(); |
| 323 | } |
| 324 | |
| 325 | static u8 tegra20_super_clk_get_parent(struct clk_hw *hw) |
| 326 | { |
| 327 | struct clk_tegra *c = to_clk_tegra(hw); |
| 328 | int val = clk_readl(c->reg + SUPER_CLK_MUX); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 329 | int source; |
| 330 | int shift; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 331 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 332 | BUG_ON(((val & SUPER_STATE_MASK) != SUPER_STATE_RUN) && |
| 333 | ((val & SUPER_STATE_MASK) != SUPER_STATE_IDLE)); |
| 334 | shift = ((val & SUPER_STATE_MASK) == SUPER_STATE_IDLE) ? |
| 335 | SUPER_IDLE_SOURCE_SHIFT : SUPER_RUN_SOURCE_SHIFT; |
| 336 | source = (val >> shift) & SUPER_SOURCE_MASK; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 337 | return source; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 338 | } |
| 339 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 340 | static int tegra20_super_clk_set_parent(struct clk_hw *hw, u8 index) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 341 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 342 | struct clk_tegra *c = to_clk_tegra(hw); |
| 343 | u32 val = clk_readl(c->reg + SUPER_CLK_MUX); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 344 | int shift; |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 345 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 346 | BUG_ON(((val & SUPER_STATE_MASK) != SUPER_STATE_RUN) && |
| 347 | ((val & SUPER_STATE_MASK) != SUPER_STATE_IDLE)); |
| 348 | shift = ((val & SUPER_STATE_MASK) == SUPER_STATE_IDLE) ? |
| 349 | SUPER_IDLE_SOURCE_SHIFT : SUPER_RUN_SOURCE_SHIFT; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 350 | val &= ~(SUPER_SOURCE_MASK << shift); |
| 351 | val |= index << shift; |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 352 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 353 | clk_writel(val, c->reg); |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 354 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 355 | return 0; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 356 | } |
| 357 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 358 | /* FIX ME: Need to switch parents to change the source PLL rate */ |
| 359 | static unsigned long tegra20_super_clk_recalc_rate(struct clk_hw *hw, |
| 360 | unsigned long prate) |
Colin Cross | 9c7dc56 | 2011-02-12 21:25:23 -0800 | [diff] [blame] | 361 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 362 | return prate; |
Colin Cross | 9c7dc56 | 2011-02-12 21:25:23 -0800 | [diff] [blame] | 363 | } |
| 364 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 365 | static long tegra20_super_clk_round_rate(struct clk_hw *hw, unsigned long rate, |
| 366 | unsigned long *prate) |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 367 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 368 | return *prate; |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 369 | } |
| 370 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 371 | static int tegra20_super_clk_set_rate(struct clk_hw *hw, unsigned long rate, |
| 372 | unsigned long parent_rate) |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 373 | { |
| 374 | return 0; |
| 375 | } |
| 376 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 377 | struct clk_ops tegra_super_ops = { |
| 378 | .is_enabled = tegra20_super_clk_is_enabled, |
| 379 | .enable = tegra20_super_clk_enable, |
| 380 | .disable = tegra20_super_clk_disable, |
| 381 | .set_parent = tegra20_super_clk_set_parent, |
| 382 | .get_parent = tegra20_super_clk_get_parent, |
| 383 | .set_rate = tegra20_super_clk_set_rate, |
| 384 | .round_rate = tegra20_super_clk_round_rate, |
| 385 | .recalc_rate = tegra20_super_clk_recalc_rate, |
| 386 | }; |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 387 | |
Prashant Gaikwad | b4350f4 | 2012-09-13 15:04:33 +0530 | [diff] [blame] | 388 | static unsigned long tegra20_twd_clk_recalc_rate(struct clk_hw *hw, |
| 389 | unsigned long parent_rate) |
| 390 | { |
| 391 | struct clk_tegra *c = to_clk_tegra(hw); |
| 392 | u64 rate = parent_rate; |
| 393 | |
| 394 | if (c->mul != 0 && c->div != 0) { |
| 395 | rate *= c->mul; |
| 396 | rate += c->div - 1; /* round up */ |
| 397 | do_div(rate, c->div); |
| 398 | } |
| 399 | |
| 400 | return rate; |
| 401 | } |
| 402 | |
| 403 | struct clk_ops tegra_twd_ops = { |
| 404 | .recalc_rate = tegra20_twd_clk_recalc_rate, |
| 405 | }; |
| 406 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 407 | static u8 tegra20_cop_clk_get_parent(struct clk_hw *hw) |
| 408 | { |
| 409 | return 0; |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 410 | } |
| 411 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 412 | struct clk_ops tegra_cop_ops = { |
| 413 | .get_parent = tegra20_cop_clk_get_parent, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 414 | }; |
| 415 | |
Colin Cross | 9c7dc56 | 2011-02-12 21:25:23 -0800 | [diff] [blame] | 416 | /* virtual cop clock functions. Used to acquire the fake 'cop' clock to |
| 417 | * reset the COP block (i.e. AVP) */ |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 418 | void tegra2_cop_clk_reset(struct clk_hw *hw, bool assert) |
Colin Cross | 9c7dc56 | 2011-02-12 21:25:23 -0800 | [diff] [blame] | 419 | { |
| 420 | unsigned long reg = assert ? RST_DEVICES_SET : RST_DEVICES_CLR; |
| 421 | |
| 422 | pr_debug("%s %s\n", __func__, assert ? "assert" : "deassert"); |
| 423 | clk_writel(1 << 1, reg); |
| 424 | } |
| 425 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 426 | /* bus clock functions */ |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 427 | static int tegra20_bus_clk_is_enabled(struct clk_hw *hw) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 428 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 429 | struct clk_tegra *c = to_clk_tegra(hw); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 430 | u32 val = clk_readl(c->reg); |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 431 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 432 | c->state = ((val >> c->reg_shift) & BUS_CLK_DISABLE) ? OFF : ON; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 433 | return c->state; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 434 | } |
| 435 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 436 | static int tegra20_bus_clk_enable(struct clk_hw *hw) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 437 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 438 | struct clk_tegra *c = to_clk_tegra(hw); |
Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 439 | unsigned long flags; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 440 | u32 val; |
Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 441 | |
| 442 | spin_lock_irqsave(&clock_register_lock, flags); |
| 443 | |
| 444 | val = clk_readl(c->reg); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 445 | val &= ~(BUS_CLK_DISABLE << c->reg_shift); |
| 446 | clk_writel(val, c->reg); |
Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 447 | |
| 448 | spin_unlock_irqrestore(&clock_register_lock, flags); |
| 449 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 450 | return 0; |
| 451 | } |
| 452 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 453 | static void tegra20_bus_clk_disable(struct clk_hw *hw) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 454 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 455 | struct clk_tegra *c = to_clk_tegra(hw); |
Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 456 | unsigned long flags; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 457 | u32 val; |
Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 458 | |
| 459 | spin_lock_irqsave(&clock_register_lock, flags); |
| 460 | |
| 461 | val = clk_readl(c->reg); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 462 | val |= BUS_CLK_DISABLE << c->reg_shift; |
| 463 | clk_writel(val, c->reg); |
Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 464 | |
| 465 | spin_unlock_irqrestore(&clock_register_lock, flags); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 466 | } |
| 467 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 468 | static unsigned long tegra20_bus_clk_recalc_rate(struct clk_hw *hw, |
| 469 | unsigned long prate) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 470 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 471 | struct clk_tegra *c = to_clk_tegra(hw); |
| 472 | u32 val = clk_readl(c->reg); |
| 473 | u64 rate = prate; |
| 474 | |
| 475 | c->div = ((val >> c->reg_shift) & BUS_CLK_DIV_MASK) + 1; |
| 476 | c->mul = 1; |
| 477 | |
| 478 | if (c->mul != 0 && c->div != 0) { |
| 479 | rate *= c->mul; |
| 480 | rate += c->div - 1; /* round up */ |
| 481 | do_div(rate, c->div); |
| 482 | } |
| 483 | return rate; |
| 484 | } |
| 485 | |
| 486 | static int tegra20_bus_clk_set_rate(struct clk_hw *hw, unsigned long rate, |
| 487 | unsigned long parent_rate) |
| 488 | { |
| 489 | struct clk_tegra *c = to_clk_tegra(hw); |
Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 490 | int ret = -EINVAL; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 491 | unsigned long flags; |
| 492 | u32 val; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 493 | int i; |
Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 494 | |
| 495 | spin_lock_irqsave(&clock_register_lock, flags); |
| 496 | |
| 497 | val = clk_readl(c->reg); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 498 | for (i = 1; i <= 4; i++) { |
| 499 | if (rate == parent_rate / i) { |
| 500 | val &= ~(BUS_CLK_DIV_MASK << c->reg_shift); |
| 501 | val |= (i - 1) << c->reg_shift; |
| 502 | clk_writel(val, c->reg); |
| 503 | c->div = i; |
| 504 | c->mul = 1; |
Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 505 | ret = 0; |
| 506 | break; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 507 | } |
| 508 | } |
Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 509 | |
| 510 | spin_unlock_irqrestore(&clock_register_lock, flags); |
| 511 | |
| 512 | return ret; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 513 | } |
| 514 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 515 | static long tegra20_bus_clk_round_rate(struct clk_hw *hw, unsigned long rate, |
| 516 | unsigned long *prate) |
| 517 | { |
| 518 | unsigned long parent_rate = *prate; |
| 519 | s64 divider; |
| 520 | |
| 521 | if (rate >= parent_rate) |
| 522 | return rate; |
| 523 | |
| 524 | divider = parent_rate; |
| 525 | divider += rate - 1; |
| 526 | do_div(divider, rate); |
| 527 | |
| 528 | if (divider < 0) |
| 529 | return divider; |
| 530 | |
| 531 | if (divider > 4) |
| 532 | divider = 4; |
| 533 | do_div(parent_rate, divider); |
| 534 | |
| 535 | return parent_rate; |
| 536 | } |
| 537 | |
Prashant Gaikwad | 86edb87 | 2012-08-06 11:57:40 +0530 | [diff] [blame] | 538 | struct clk_ops tegra_bus_ops = { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 539 | .is_enabled = tegra20_bus_clk_is_enabled, |
| 540 | .enable = tegra20_bus_clk_enable, |
| 541 | .disable = tegra20_bus_clk_disable, |
| 542 | .set_rate = tegra20_bus_clk_set_rate, |
| 543 | .round_rate = tegra20_bus_clk_round_rate, |
| 544 | .recalc_rate = tegra20_bus_clk_recalc_rate, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 545 | }; |
| 546 | |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 547 | /* Blink output functions */ |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 548 | static int tegra20_blink_clk_is_enabled(struct clk_hw *hw) |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 549 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 550 | struct clk_tegra *c = to_clk_tegra(hw); |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 551 | u32 val; |
| 552 | |
| 553 | val = pmc_readl(PMC_CTRL); |
| 554 | c->state = (val & PMC_CTRL_BLINK_ENB) ? ON : OFF; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 555 | return c->state; |
| 556 | } |
| 557 | |
| 558 | static unsigned long tegra20_blink_clk_recalc_rate(struct clk_hw *hw, |
| 559 | unsigned long prate) |
| 560 | { |
| 561 | struct clk_tegra *c = to_clk_tegra(hw); |
| 562 | u64 rate = prate; |
| 563 | u32 val; |
| 564 | |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 565 | c->mul = 1; |
| 566 | val = pmc_readl(c->reg); |
| 567 | |
| 568 | if (val & PMC_BLINK_TIMER_ENB) { |
| 569 | unsigned int on_off; |
| 570 | |
| 571 | on_off = (val >> PMC_BLINK_TIMER_DATA_ON_SHIFT) & |
| 572 | PMC_BLINK_TIMER_DATA_ON_MASK; |
| 573 | val >>= PMC_BLINK_TIMER_DATA_OFF_SHIFT; |
| 574 | val &= PMC_BLINK_TIMER_DATA_OFF_MASK; |
| 575 | on_off += val; |
| 576 | /* each tick in the blink timer is 4 32KHz clocks */ |
| 577 | c->div = on_off * 4; |
| 578 | } else { |
| 579 | c->div = 1; |
| 580 | } |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 581 | |
| 582 | if (c->mul != 0 && c->div != 0) { |
| 583 | rate *= c->mul; |
| 584 | rate += c->div - 1; /* round up */ |
| 585 | do_div(rate, c->div); |
| 586 | } |
| 587 | return rate; |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 588 | } |
| 589 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 590 | static int tegra20_blink_clk_enable(struct clk_hw *hw) |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 591 | { |
| 592 | u32 val; |
| 593 | |
| 594 | val = pmc_readl(PMC_DPD_PADS_ORIDE); |
| 595 | pmc_writel(val | PMC_DPD_PADS_ORIDE_BLINK_ENB, PMC_DPD_PADS_ORIDE); |
| 596 | |
| 597 | val = pmc_readl(PMC_CTRL); |
| 598 | pmc_writel(val | PMC_CTRL_BLINK_ENB, PMC_CTRL); |
| 599 | |
| 600 | return 0; |
| 601 | } |
| 602 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 603 | static void tegra20_blink_clk_disable(struct clk_hw *hw) |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 604 | { |
| 605 | u32 val; |
| 606 | |
| 607 | val = pmc_readl(PMC_CTRL); |
| 608 | pmc_writel(val & ~PMC_CTRL_BLINK_ENB, PMC_CTRL); |
| 609 | |
| 610 | val = pmc_readl(PMC_DPD_PADS_ORIDE); |
| 611 | pmc_writel(val & ~PMC_DPD_PADS_ORIDE_BLINK_ENB, PMC_DPD_PADS_ORIDE); |
| 612 | } |
| 613 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 614 | static int tegra20_blink_clk_set_rate(struct clk_hw *hw, unsigned long rate, |
| 615 | unsigned long parent_rate) |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 616 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 617 | struct clk_tegra *c = to_clk_tegra(hw); |
| 618 | |
Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 619 | if (rate >= parent_rate) { |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 620 | c->div = 1; |
| 621 | pmc_writel(0, c->reg); |
| 622 | } else { |
| 623 | unsigned int on_off; |
| 624 | u32 val; |
| 625 | |
Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 626 | on_off = DIV_ROUND_UP(parent_rate / 8, rate); |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 627 | c->div = on_off * 8; |
| 628 | |
| 629 | val = (on_off & PMC_BLINK_TIMER_DATA_ON_MASK) << |
| 630 | PMC_BLINK_TIMER_DATA_ON_SHIFT; |
| 631 | on_off &= PMC_BLINK_TIMER_DATA_OFF_MASK; |
| 632 | on_off <<= PMC_BLINK_TIMER_DATA_OFF_SHIFT; |
| 633 | val |= on_off; |
| 634 | val |= PMC_BLINK_TIMER_ENB; |
| 635 | pmc_writel(val, c->reg); |
| 636 | } |
| 637 | |
| 638 | return 0; |
| 639 | } |
| 640 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 641 | static long tegra20_blink_clk_round_rate(struct clk_hw *hw, unsigned long rate, |
| 642 | unsigned long *prate) |
| 643 | { |
| 644 | int div; |
| 645 | int mul; |
| 646 | long round_rate = *prate; |
| 647 | |
| 648 | mul = 1; |
| 649 | |
| 650 | if (rate >= *prate) { |
| 651 | div = 1; |
| 652 | } else { |
| 653 | div = DIV_ROUND_UP(*prate / 8, rate); |
| 654 | div *= 8; |
| 655 | } |
| 656 | |
| 657 | round_rate *= mul; |
| 658 | round_rate += div - 1; |
| 659 | do_div(round_rate, div); |
| 660 | |
| 661 | return round_rate; |
| 662 | } |
| 663 | |
Prashant Gaikwad | 86edb87 | 2012-08-06 11:57:40 +0530 | [diff] [blame] | 664 | struct clk_ops tegra_blink_clk_ops = { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 665 | .is_enabled = tegra20_blink_clk_is_enabled, |
| 666 | .enable = tegra20_blink_clk_enable, |
| 667 | .disable = tegra20_blink_clk_disable, |
| 668 | .set_rate = tegra20_blink_clk_set_rate, |
| 669 | .round_rate = tegra20_blink_clk_round_rate, |
| 670 | .recalc_rate = tegra20_blink_clk_recalc_rate, |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 671 | }; |
| 672 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 673 | /* PLL Functions */ |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 674 | static int tegra20_pll_clk_wait_for_lock(struct clk_tegra *c) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 675 | { |
Colin Cross | f151961 | 2011-02-12 16:05:31 -0800 | [diff] [blame] | 676 | udelay(c->u.pll.lock_delay); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 677 | return 0; |
| 678 | } |
| 679 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 680 | static int tegra20_pll_clk_is_enabled(struct clk_hw *hw) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 681 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 682 | struct clk_tegra *c = to_clk_tegra(hw); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 683 | u32 val = clk_readl(c->reg + PLL_BASE); |
| 684 | |
| 685 | c->state = (val & PLL_BASE_ENABLE) ? ON : OFF; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 686 | return c->state; |
| 687 | } |
| 688 | |
| 689 | static unsigned long tegra20_pll_clk_recalc_rate(struct clk_hw *hw, |
| 690 | unsigned long prate) |
| 691 | { |
| 692 | struct clk_tegra *c = to_clk_tegra(hw); |
| 693 | u32 val = clk_readl(c->reg + PLL_BASE); |
| 694 | u64 rate = prate; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 695 | |
| 696 | if (c->flags & PLL_FIXED && !(val & PLL_BASE_OVERRIDE)) { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 697 | const struct clk_pll_freq_table *sel; |
| 698 | for (sel = c->u.pll.freq_table; sel->input_rate != 0; sel++) { |
| 699 | if (sel->input_rate == prate && |
| 700 | sel->output_rate == c->u.pll.fixed_rate) { |
| 701 | c->mul = sel->n; |
| 702 | c->div = sel->m * sel->p; |
| 703 | break; |
| 704 | } |
| 705 | } |
| 706 | pr_err("Clock %s has unknown fixed frequency\n", |
| 707 | __clk_get_name(hw->clk)); |
| 708 | BUG(); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 709 | } else if (val & PLL_BASE_BYPASS) { |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 710 | c->mul = 1; |
| 711 | c->div = 1; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 712 | } else { |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 713 | c->mul = (val & PLL_BASE_DIVN_MASK) >> PLL_BASE_DIVN_SHIFT; |
| 714 | c->div = (val & PLL_BASE_DIVM_MASK) >> PLL_BASE_DIVM_SHIFT; |
| 715 | if (c->flags & PLLU) |
| 716 | c->div *= (val & PLLU_BASE_POST_DIV) ? 1 : 2; |
| 717 | else |
| 718 | c->div *= (val & PLL_BASE_DIVP_MASK) ? 2 : 1; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 719 | } |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 720 | |
| 721 | if (c->mul != 0 && c->div != 0) { |
| 722 | rate *= c->mul; |
| 723 | rate += c->div - 1; /* round up */ |
| 724 | do_div(rate, c->div); |
| 725 | } |
| 726 | return rate; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 727 | } |
| 728 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 729 | static int tegra20_pll_clk_enable(struct clk_hw *hw) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 730 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 731 | struct clk_tegra *c = to_clk_tegra(hw); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 732 | u32 val; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 733 | pr_debug("%s on clock %s\n", __func__, __clk_get_name(hw->clk)); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 734 | |
| 735 | val = clk_readl(c->reg + PLL_BASE); |
| 736 | val &= ~PLL_BASE_BYPASS; |
| 737 | val |= PLL_BASE_ENABLE; |
| 738 | clk_writel(val, c->reg + PLL_BASE); |
| 739 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 740 | tegra20_pll_clk_wait_for_lock(c); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 741 | |
| 742 | return 0; |
| 743 | } |
| 744 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 745 | static void tegra20_pll_clk_disable(struct clk_hw *hw) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 746 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 747 | struct clk_tegra *c = to_clk_tegra(hw); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 748 | u32 val; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 749 | pr_debug("%s on clock %s\n", __func__, __clk_get_name(hw->clk)); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 750 | |
| 751 | val = clk_readl(c->reg); |
| 752 | val &= ~(PLL_BASE_BYPASS | PLL_BASE_ENABLE); |
| 753 | clk_writel(val, c->reg); |
| 754 | } |
| 755 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 756 | static int tegra20_pll_clk_set_rate(struct clk_hw *hw, unsigned long rate, |
| 757 | unsigned long parent_rate) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 758 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 759 | struct clk_tegra *c = to_clk_tegra(hw); |
| 760 | unsigned long input_rate = parent_rate; |
Colin Cross | f151961 | 2011-02-12 16:05:31 -0800 | [diff] [blame] | 761 | const struct clk_pll_freq_table *sel; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 762 | u32 val; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 763 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 764 | pr_debug("%s: %s %lu\n", __func__, __clk_get_name(hw->clk), rate); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 765 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 766 | if (c->flags & PLL_FIXED) { |
| 767 | int ret = 0; |
| 768 | if (rate != c->u.pll.fixed_rate) { |
| 769 | pr_err("%s: Can not change %s fixed rate %lu to %lu\n", |
| 770 | __func__, __clk_get_name(hw->clk), |
| 771 | c->u.pll.fixed_rate, rate); |
| 772 | ret = -EINVAL; |
| 773 | } |
| 774 | return ret; |
| 775 | } |
| 776 | |
Colin Cross | f151961 | 2011-02-12 16:05:31 -0800 | [diff] [blame] | 777 | for (sel = c->u.pll.freq_table; sel->input_rate != 0; sel++) { |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 778 | if (sel->input_rate == input_rate && sel->output_rate == rate) { |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 779 | c->mul = sel->n; |
| 780 | c->div = sel->m * sel->p; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 781 | |
| 782 | val = clk_readl(c->reg + PLL_BASE); |
| 783 | if (c->flags & PLL_FIXED) |
| 784 | val |= PLL_BASE_OVERRIDE; |
| 785 | val &= ~(PLL_BASE_DIVP_MASK | PLL_BASE_DIVN_MASK | |
| 786 | PLL_BASE_DIVM_MASK); |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 787 | val |= (sel->m << PLL_BASE_DIVM_SHIFT) | |
| 788 | (sel->n << PLL_BASE_DIVN_SHIFT); |
| 789 | BUG_ON(sel->p < 1 || sel->p > 2); |
| 790 | if (c->flags & PLLU) { |
| 791 | if (sel->p == 1) |
| 792 | val |= PLLU_BASE_POST_DIV; |
| 793 | } else { |
| 794 | if (sel->p == 2) |
| 795 | val |= 1 << PLL_BASE_DIVP_SHIFT; |
| 796 | } |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 797 | clk_writel(val, c->reg + PLL_BASE); |
| 798 | |
| 799 | if (c->flags & PLL_HAS_CPCON) { |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 800 | val = clk_readl(c->reg + PLL_MISC(c)); |
| 801 | val &= ~PLL_MISC_CPCON_MASK; |
| 802 | val |= sel->cpcon << PLL_MISC_CPCON_SHIFT; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 803 | clk_writel(val, c->reg + PLL_MISC(c)); |
| 804 | } |
| 805 | |
| 806 | if (c->state == ON) |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 807 | tegra20_pll_clk_enable(hw); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 808 | return 0; |
| 809 | } |
| 810 | } |
| 811 | return -EINVAL; |
| 812 | } |
| 813 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 814 | static long tegra20_pll_clk_round_rate(struct clk_hw *hw, unsigned long rate, |
| 815 | unsigned long *prate) |
| 816 | { |
| 817 | struct clk_tegra *c = to_clk_tegra(hw); |
| 818 | const struct clk_pll_freq_table *sel; |
| 819 | unsigned long input_rate = *prate; |
Stephen Warren | 7a74a44 | 2012-09-10 17:02:45 -0600 | [diff] [blame] | 820 | u64 output_rate = *prate; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 821 | int mul; |
| 822 | int div; |
| 823 | |
| 824 | if (c->flags & PLL_FIXED) |
| 825 | return c->u.pll.fixed_rate; |
| 826 | |
| 827 | for (sel = c->u.pll.freq_table; sel->input_rate != 0; sel++) |
| 828 | if (sel->input_rate == input_rate && sel->output_rate == rate) { |
| 829 | mul = sel->n; |
| 830 | div = sel->m * sel->p; |
| 831 | break; |
| 832 | } |
| 833 | |
| 834 | if (sel->input_rate == 0) |
| 835 | return -EINVAL; |
| 836 | |
| 837 | output_rate *= mul; |
| 838 | output_rate += div - 1; /* round up */ |
| 839 | do_div(output_rate, div); |
| 840 | |
| 841 | return output_rate; |
| 842 | } |
| 843 | |
Prashant Gaikwad | 86edb87 | 2012-08-06 11:57:40 +0530 | [diff] [blame] | 844 | struct clk_ops tegra_pll_ops = { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 845 | .is_enabled = tegra20_pll_clk_is_enabled, |
| 846 | .enable = tegra20_pll_clk_enable, |
| 847 | .disable = tegra20_pll_clk_disable, |
| 848 | .set_rate = tegra20_pll_clk_set_rate, |
| 849 | .recalc_rate = tegra20_pll_clk_recalc_rate, |
| 850 | .round_rate = tegra20_pll_clk_round_rate, |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 851 | }; |
| 852 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 853 | static void tegra20_pllx_clk_init(struct clk_hw *hw) |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 854 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 855 | struct clk_tegra *c = to_clk_tegra(hw); |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 856 | |
Olof Johansson | 9a1086d | 2011-10-13 00:31:20 -0700 | [diff] [blame] | 857 | if (tegra_sku_id == 7) |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 858 | c->max_rate = 750000000; |
| 859 | } |
| 860 | |
Prashant Gaikwad | 86edb87 | 2012-08-06 11:57:40 +0530 | [diff] [blame] | 861 | struct clk_ops tegra_pllx_ops = { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 862 | .init = tegra20_pllx_clk_init, |
| 863 | .is_enabled = tegra20_pll_clk_is_enabled, |
| 864 | .enable = tegra20_pll_clk_enable, |
| 865 | .disable = tegra20_pll_clk_disable, |
| 866 | .set_rate = tegra20_pll_clk_set_rate, |
| 867 | .recalc_rate = tegra20_pll_clk_recalc_rate, |
| 868 | .round_rate = tegra20_pll_clk_round_rate, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 869 | }; |
| 870 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 871 | static int tegra20_plle_clk_enable(struct clk_hw *hw) |
Mike Rapoport | 8d685bc | 2010-09-27 11:26:32 +0200 | [diff] [blame] | 872 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 873 | struct clk_tegra *c = to_clk_tegra(hw); |
Mike Rapoport | 8d685bc | 2010-09-27 11:26:32 +0200 | [diff] [blame] | 874 | u32 val; |
| 875 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 876 | pr_debug("%s on clock %s\n", __func__, __clk_get_name(hw->clk)); |
Mike Rapoport | 8d685bc | 2010-09-27 11:26:32 +0200 | [diff] [blame] | 877 | |
| 878 | mdelay(1); |
| 879 | |
| 880 | val = clk_readl(c->reg + PLL_BASE); |
| 881 | if (!(val & PLLE_MISC_READY)) |
| 882 | return -EBUSY; |
| 883 | |
| 884 | val = clk_readl(c->reg + PLL_BASE); |
| 885 | val |= PLL_BASE_ENABLE | PLL_BASE_BYPASS; |
| 886 | clk_writel(val, c->reg + PLL_BASE); |
| 887 | |
| 888 | return 0; |
| 889 | } |
| 890 | |
Prashant Gaikwad | 86edb87 | 2012-08-06 11:57:40 +0530 | [diff] [blame] | 891 | struct clk_ops tegra_plle_ops = { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 892 | .is_enabled = tegra20_pll_clk_is_enabled, |
| 893 | .enable = tegra20_plle_clk_enable, |
| 894 | .set_rate = tegra20_pll_clk_set_rate, |
| 895 | .recalc_rate = tegra20_pll_clk_recalc_rate, |
| 896 | .round_rate = tegra20_pll_clk_round_rate, |
Mike Rapoport | 8d685bc | 2010-09-27 11:26:32 +0200 | [diff] [blame] | 897 | }; |
| 898 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 899 | /* Clock divider ops */ |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 900 | static int tegra20_pll_div_clk_is_enabled(struct clk_hw *hw) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 901 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 902 | struct clk_tegra *c = to_clk_tegra(hw); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 903 | u32 val = clk_readl(c->reg); |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 904 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 905 | val >>= c->reg_shift; |
| 906 | c->state = (val & PLL_OUT_CLKEN) ? ON : OFF; |
| 907 | if (!(val & PLL_OUT_RESET_DISABLE)) |
| 908 | c->state = OFF; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 909 | return c->state; |
| 910 | } |
| 911 | |
| 912 | static unsigned long tegra20_pll_div_clk_recalc_rate(struct clk_hw *hw, |
| 913 | unsigned long prate) |
| 914 | { |
| 915 | struct clk_tegra *c = to_clk_tegra(hw); |
| 916 | u64 rate = prate; |
| 917 | u32 val = clk_readl(c->reg); |
| 918 | u32 divu71; |
| 919 | |
| 920 | val >>= c->reg_shift; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 921 | |
| 922 | if (c->flags & DIV_U71) { |
| 923 | divu71 = (val & PLL_OUT_RATIO_MASK) >> PLL_OUT_RATIO_SHIFT; |
| 924 | c->div = (divu71 + 2); |
| 925 | c->mul = 2; |
| 926 | } else if (c->flags & DIV_2) { |
| 927 | c->div = 2; |
| 928 | c->mul = 1; |
| 929 | } else { |
| 930 | c->div = 1; |
| 931 | c->mul = 1; |
| 932 | } |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 933 | |
| 934 | rate *= c->mul; |
| 935 | rate += c->div - 1; /* round up */ |
| 936 | do_div(rate, c->div); |
| 937 | |
| 938 | return rate; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 939 | } |
| 940 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 941 | static int tegra20_pll_div_clk_enable(struct clk_hw *hw) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 942 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 943 | struct clk_tegra *c = to_clk_tegra(hw); |
Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 944 | unsigned long flags; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 945 | u32 new_val; |
| 946 | u32 val; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 947 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 948 | pr_debug("%s: %s\n", __func__, __clk_get_name(hw->clk)); |
| 949 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 950 | if (c->flags & DIV_U71) { |
Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 951 | spin_lock_irqsave(&clock_register_lock, flags); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 952 | val = clk_readl(c->reg); |
| 953 | new_val = val >> c->reg_shift; |
| 954 | new_val &= 0xFFFF; |
| 955 | |
| 956 | new_val |= PLL_OUT_CLKEN | PLL_OUT_RESET_DISABLE; |
| 957 | |
| 958 | val &= ~(0xFFFF << c->reg_shift); |
| 959 | val |= new_val << c->reg_shift; |
| 960 | clk_writel(val, c->reg); |
Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 961 | spin_unlock_irqrestore(&clock_register_lock, flags); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 962 | return 0; |
| 963 | } else if (c->flags & DIV_2) { |
| 964 | BUG_ON(!(c->flags & PLLD)); |
Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 965 | spin_lock_irqsave(&clock_register_lock, flags); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 966 | val = clk_readl(c->reg); |
| 967 | val &= ~PLLD_MISC_DIV_RST; |
| 968 | clk_writel(val, c->reg); |
Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 969 | spin_unlock_irqrestore(&clock_register_lock, flags); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 970 | return 0; |
| 971 | } |
| 972 | return -EINVAL; |
| 973 | } |
| 974 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 975 | static void tegra20_pll_div_clk_disable(struct clk_hw *hw) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 976 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 977 | struct clk_tegra *c = to_clk_tegra(hw); |
Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 978 | unsigned long flags; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 979 | u32 new_val; |
| 980 | u32 val; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 981 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 982 | pr_debug("%s: %s\n", __func__, __clk_get_name(hw->clk)); |
| 983 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 984 | if (c->flags & DIV_U71) { |
Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 985 | spin_lock_irqsave(&clock_register_lock, flags); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 986 | val = clk_readl(c->reg); |
| 987 | new_val = val >> c->reg_shift; |
| 988 | new_val &= 0xFFFF; |
| 989 | |
| 990 | new_val &= ~(PLL_OUT_CLKEN | PLL_OUT_RESET_DISABLE); |
| 991 | |
| 992 | val &= ~(0xFFFF << c->reg_shift); |
| 993 | val |= new_val << c->reg_shift; |
| 994 | clk_writel(val, c->reg); |
Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 995 | spin_unlock_irqrestore(&clock_register_lock, flags); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 996 | } else if (c->flags & DIV_2) { |
| 997 | BUG_ON(!(c->flags & PLLD)); |
Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 998 | spin_lock_irqsave(&clock_register_lock, flags); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 999 | val = clk_readl(c->reg); |
| 1000 | val |= PLLD_MISC_DIV_RST; |
| 1001 | clk_writel(val, c->reg); |
Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 1002 | spin_unlock_irqrestore(&clock_register_lock, flags); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1003 | } |
| 1004 | } |
| 1005 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1006 | static int tegra20_pll_div_clk_set_rate(struct clk_hw *hw, unsigned long rate, |
| 1007 | unsigned long parent_rate) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1008 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1009 | struct clk_tegra *c = to_clk_tegra(hw); |
Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 1010 | unsigned long flags; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1011 | int divider_u71; |
| 1012 | u32 new_val; |
| 1013 | u32 val; |
Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 1014 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1015 | pr_debug("%s: %s %lu\n", __func__, __clk_get_name(hw->clk), rate); |
| 1016 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1017 | if (c->flags & DIV_U71) { |
Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 1018 | divider_u71 = clk_div71_get_divider(parent_rate, rate); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1019 | if (divider_u71 >= 0) { |
Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 1020 | spin_lock_irqsave(&clock_register_lock, flags); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1021 | val = clk_readl(c->reg); |
| 1022 | new_val = val >> c->reg_shift; |
| 1023 | new_val &= 0xFFFF; |
| 1024 | if (c->flags & DIV_U71_FIXED) |
| 1025 | new_val |= PLL_OUT_OVERRIDE; |
| 1026 | new_val &= ~PLL_OUT_RATIO_MASK; |
| 1027 | new_val |= divider_u71 << PLL_OUT_RATIO_SHIFT; |
| 1028 | |
| 1029 | val &= ~(0xFFFF << c->reg_shift); |
| 1030 | val |= new_val << c->reg_shift; |
| 1031 | clk_writel(val, c->reg); |
| 1032 | c->div = divider_u71 + 2; |
| 1033 | c->mul = 2; |
Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 1034 | spin_unlock_irqrestore(&clock_register_lock, flags); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1035 | return 0; |
| 1036 | } |
| 1037 | } else if (c->flags & DIV_2) { |
Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 1038 | if (parent_rate == rate * 2) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1039 | return 0; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1040 | } |
| 1041 | return -EINVAL; |
| 1042 | } |
| 1043 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1044 | static long tegra20_pll_div_clk_round_rate(struct clk_hw *hw, unsigned long rate, |
| 1045 | unsigned long *prate) |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1046 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1047 | struct clk_tegra *c = to_clk_tegra(hw); |
| 1048 | unsigned long parent_rate = *prate; |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1049 | int divider; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1050 | |
| 1051 | pr_debug("%s: %s %lu\n", __func__, __clk_get_name(hw->clk), rate); |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1052 | |
| 1053 | if (c->flags & DIV_U71) { |
Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 1054 | divider = clk_div71_get_divider(parent_rate, rate); |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1055 | if (divider < 0) |
| 1056 | return divider; |
Colin Cross | 421186e | 2011-02-12 18:21:47 -0800 | [diff] [blame] | 1057 | return DIV_ROUND_UP(parent_rate * 2, divider + 2); |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1058 | } else if (c->flags & DIV_2) { |
Colin Cross | 421186e | 2011-02-12 18:21:47 -0800 | [diff] [blame] | 1059 | return DIV_ROUND_UP(parent_rate, 2); |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1060 | } |
| 1061 | return -EINVAL; |
| 1062 | } |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1063 | |
Prashant Gaikwad | 86edb87 | 2012-08-06 11:57:40 +0530 | [diff] [blame] | 1064 | struct clk_ops tegra_pll_div_ops = { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1065 | .is_enabled = tegra20_pll_div_clk_is_enabled, |
| 1066 | .enable = tegra20_pll_div_clk_enable, |
| 1067 | .disable = tegra20_pll_div_clk_disable, |
| 1068 | .set_rate = tegra20_pll_div_clk_set_rate, |
| 1069 | .round_rate = tegra20_pll_div_clk_round_rate, |
| 1070 | .recalc_rate = tegra20_pll_div_clk_recalc_rate, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1071 | }; |
| 1072 | |
| 1073 | /* Periph clk ops */ |
| 1074 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1075 | static int tegra20_periph_clk_is_enabled(struct clk_hw *hw) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1076 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1077 | struct clk_tegra *c = to_clk_tegra(hw); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1078 | |
| 1079 | c->state = ON; |
Colin Cross | 1be3d05 | 2011-02-21 16:44:07 -0800 | [diff] [blame] | 1080 | |
| 1081 | if (!c->u.periph.clk_num) |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1082 | goto out; |
Colin Cross | 1be3d05 | 2011-02-21 16:44:07 -0800 | [diff] [blame] | 1083 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1084 | if (!(clk_readl(CLK_OUT_ENB + PERIPH_CLK_TO_ENB_REG(c)) & |
| 1085 | PERIPH_CLK_TO_ENB_BIT(c))) |
| 1086 | c->state = OFF; |
Colin Cross | 1be3d05 | 2011-02-21 16:44:07 -0800 | [diff] [blame] | 1087 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1088 | if (!(c->flags & PERIPH_NO_RESET)) |
| 1089 | if (clk_readl(RST_DEVICES + PERIPH_CLK_TO_ENB_REG(c)) & |
| 1090 | PERIPH_CLK_TO_ENB_BIT(c)) |
| 1091 | c->state = OFF; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1092 | |
| 1093 | out: |
| 1094 | return c->state; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1095 | } |
| 1096 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1097 | static int tegra20_periph_clk_enable(struct clk_hw *hw) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1098 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1099 | struct clk_tegra *c = to_clk_tegra(hw); |
Colin Cross | 78f379b | 2010-10-20 19:19:58 -0700 | [diff] [blame] | 1100 | unsigned long flags; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1101 | u32 val; |
| 1102 | |
| 1103 | pr_debug("%s on clock %s\n", __func__, __clk_get_name(hw->clk)); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1104 | |
Colin Cross | 1be3d05 | 2011-02-21 16:44:07 -0800 | [diff] [blame] | 1105 | if (!c->u.periph.clk_num) |
| 1106 | return 0; |
| 1107 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1108 | tegra_periph_clk_enable_refcount[c->u.periph.clk_num]++; |
| 1109 | if (tegra_periph_clk_enable_refcount[c->u.periph.clk_num] > 1) |
| 1110 | return 0; |
| 1111 | |
Colin Cross | 78f379b | 2010-10-20 19:19:58 -0700 | [diff] [blame] | 1112 | spin_lock_irqsave(&clock_register_lock, flags); |
| 1113 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1114 | clk_writel(PERIPH_CLK_TO_ENB_BIT(c), |
| 1115 | CLK_OUT_ENB_SET + PERIPH_CLK_TO_ENB_SET_REG(c)); |
| 1116 | if (!(c->flags & PERIPH_NO_RESET) && !(c->flags & PERIPH_MANUAL_RESET)) |
| 1117 | clk_writel(PERIPH_CLK_TO_ENB_BIT(c), |
| 1118 | RST_DEVICES_CLR + PERIPH_CLK_TO_ENB_SET_REG(c)); |
| 1119 | if (c->flags & PERIPH_EMC_ENB) { |
| 1120 | /* The EMC peripheral clock has 2 extra enable bits */ |
| 1121 | /* FIXME: Do they need to be disabled? */ |
| 1122 | val = clk_readl(c->reg); |
| 1123 | val |= 0x3 << 24; |
| 1124 | clk_writel(val, c->reg); |
| 1125 | } |
Colin Cross | 78f379b | 2010-10-20 19:19:58 -0700 | [diff] [blame] | 1126 | |
Colin Cross | 78f379b | 2010-10-20 19:19:58 -0700 | [diff] [blame] | 1127 | spin_unlock_irqrestore(&clock_register_lock, flags); |
| 1128 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1129 | return 0; |
| 1130 | } |
| 1131 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1132 | static void tegra20_periph_clk_disable(struct clk_hw *hw) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1133 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1134 | struct clk_tegra *c = to_clk_tegra(hw); |
Colin Cross | 78f379b | 2010-10-20 19:19:58 -0700 | [diff] [blame] | 1135 | unsigned long flags; |
| 1136 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1137 | pr_debug("%s on clock %s\n", __func__, __clk_get_name(hw->clk)); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1138 | |
Colin Cross | 1be3d05 | 2011-02-21 16:44:07 -0800 | [diff] [blame] | 1139 | if (!c->u.periph.clk_num) |
| 1140 | return; |
| 1141 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1142 | tegra_periph_clk_enable_refcount[c->u.periph.clk_num]--; |
| 1143 | |
| 1144 | if (tegra_periph_clk_enable_refcount[c->u.periph.clk_num] > 0) |
| 1145 | return; |
| 1146 | |
Colin Cross | 78f379b | 2010-10-20 19:19:58 -0700 | [diff] [blame] | 1147 | spin_lock_irqsave(&clock_register_lock, flags); |
| 1148 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1149 | clk_writel(PERIPH_CLK_TO_ENB_BIT(c), |
| 1150 | CLK_OUT_ENB_CLR + PERIPH_CLK_TO_ENB_SET_REG(c)); |
Colin Cross | 78f379b | 2010-10-20 19:19:58 -0700 | [diff] [blame] | 1151 | |
| 1152 | spin_unlock_irqrestore(&clock_register_lock, flags); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1153 | } |
| 1154 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1155 | void tegra2_periph_clk_reset(struct clk_hw *hw, bool assert) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1156 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1157 | struct clk_tegra *c = to_clk_tegra(hw); |
Dima Zavin | 2b84cb4f | 2010-09-02 19:11:11 -0700 | [diff] [blame] | 1158 | unsigned long base = assert ? RST_DEVICES_SET : RST_DEVICES_CLR; |
| 1159 | |
| 1160 | pr_debug("%s %s on clock %s\n", __func__, |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1161 | assert ? "assert" : "deassert", __clk_get_name(hw->clk)); |
Colin Cross | 1be3d05 | 2011-02-21 16:44:07 -0800 | [diff] [blame] | 1162 | |
| 1163 | BUG_ON(!c->u.periph.clk_num); |
| 1164 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1165 | if (!(c->flags & PERIPH_NO_RESET)) |
| 1166 | clk_writel(PERIPH_CLK_TO_ENB_BIT(c), |
Dima Zavin | 2b84cb4f | 2010-09-02 19:11:11 -0700 | [diff] [blame] | 1167 | base + PERIPH_CLK_TO_ENB_SET_REG(c)); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1168 | } |
| 1169 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1170 | static int tegra20_periph_clk_set_parent(struct clk_hw *hw, u8 index) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1171 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1172 | struct clk_tegra *c = to_clk_tegra(hw); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1173 | u32 val; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1174 | u32 mask; |
| 1175 | u32 shift; |
Simon Que | bb1dccf | 2011-12-16 20:11:22 +0100 | [diff] [blame] | 1176 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1177 | pr_debug("%s: %s %d\n", __func__, __clk_get_name(hw->clk), index); |
Simon Que | bb1dccf | 2011-12-16 20:11:22 +0100 | [diff] [blame] | 1178 | |
| 1179 | if (c->flags & MUX_PWM) { |
| 1180 | shift = PERIPH_CLK_SOURCE_PWM_SHIFT; |
| 1181 | mask = PERIPH_CLK_SOURCE_PWM_MASK; |
| 1182 | } else { |
| 1183 | shift = PERIPH_CLK_SOURCE_SHIFT; |
| 1184 | mask = PERIPH_CLK_SOURCE_MASK; |
| 1185 | } |
| 1186 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1187 | val = clk_readl(c->reg); |
| 1188 | val &= ~mask; |
| 1189 | val |= (index) << shift; |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1190 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1191 | clk_writel(val, c->reg); |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1192 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1193 | return 0; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1194 | } |
| 1195 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1196 | static u8 tegra20_periph_clk_get_parent(struct clk_hw *hw) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1197 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1198 | struct clk_tegra *c = to_clk_tegra(hw); |
| 1199 | u32 val = clk_readl(c->reg); |
| 1200 | u32 mask; |
| 1201 | u32 shift; |
| 1202 | |
| 1203 | if (c->flags & MUX_PWM) { |
| 1204 | shift = PERIPH_CLK_SOURCE_PWM_SHIFT; |
| 1205 | mask = PERIPH_CLK_SOURCE_PWM_MASK; |
| 1206 | } else { |
| 1207 | shift = PERIPH_CLK_SOURCE_SHIFT; |
| 1208 | mask = PERIPH_CLK_SOURCE_MASK; |
| 1209 | } |
| 1210 | |
| 1211 | if (c->flags & MUX) |
| 1212 | return (val & mask) >> shift; |
| 1213 | else |
| 1214 | return 0; |
| 1215 | } |
| 1216 | |
| 1217 | static unsigned long tegra20_periph_clk_recalc_rate(struct clk_hw *hw, |
| 1218 | unsigned long prate) |
| 1219 | { |
| 1220 | struct clk_tegra *c = to_clk_tegra(hw); |
| 1221 | unsigned long rate = prate; |
| 1222 | u32 val = clk_readl(c->reg); |
| 1223 | |
| 1224 | if (c->flags & DIV_U71) { |
| 1225 | u32 divu71 = val & PERIPH_CLK_SOURCE_DIVU71_MASK; |
| 1226 | c->div = divu71 + 2; |
| 1227 | c->mul = 2; |
| 1228 | } else if (c->flags & DIV_U16) { |
| 1229 | u32 divu16 = val & PERIPH_CLK_SOURCE_DIVU16_MASK; |
| 1230 | c->div = divu16 + 1; |
| 1231 | c->mul = 1; |
| 1232 | } else { |
| 1233 | c->div = 1; |
| 1234 | c->mul = 1; |
| 1235 | return rate; |
| 1236 | } |
| 1237 | |
| 1238 | if (c->mul != 0 && c->div != 0) { |
| 1239 | rate *= c->mul; |
| 1240 | rate += c->div - 1; /* round up */ |
| 1241 | do_div(rate, c->div); |
| 1242 | } |
| 1243 | |
| 1244 | return rate; |
| 1245 | } |
| 1246 | |
| 1247 | static int tegra20_periph_clk_set_rate(struct clk_hw *hw, unsigned long rate, |
| 1248 | unsigned long parent_rate) |
| 1249 | { |
| 1250 | struct clk_tegra *c = to_clk_tegra(hw); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1251 | u32 val; |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1252 | int divider; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1253 | |
| 1254 | val = clk_readl(c->reg); |
Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 1255 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1256 | if (c->flags & DIV_U71) { |
Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 1257 | divider = clk_div71_get_divider(parent_rate, rate); |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1258 | |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1259 | if (divider >= 0) { |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1260 | val = clk_readl(c->reg); |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1261 | val &= ~PERIPH_CLK_SOURCE_DIVU71_MASK; |
| 1262 | val |= divider; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1263 | clk_writel(val, c->reg); |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1264 | c->div = divider + 2; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1265 | c->mul = 2; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1266 | return 0; |
| 1267 | } |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1268 | } else if (c->flags & DIV_U16) { |
Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 1269 | divider = clk_div16_get_divider(parent_rate, rate); |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1270 | if (divider >= 0) { |
| 1271 | val = clk_readl(c->reg); |
| 1272 | val &= ~PERIPH_CLK_SOURCE_DIVU16_MASK; |
| 1273 | val |= divider; |
| 1274 | clk_writel(val, c->reg); |
| 1275 | c->div = divider + 1; |
| 1276 | c->mul = 1; |
| 1277 | return 0; |
| 1278 | } |
Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 1279 | } else if (parent_rate <= rate) { |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1280 | c->div = 1; |
| 1281 | c->mul = 1; |
| 1282 | return 0; |
| 1283 | } |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1284 | |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1285 | return -EINVAL; |
| 1286 | } |
| 1287 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1288 | static long tegra20_periph_clk_round_rate(struct clk_hw *hw, |
| 1289 | unsigned long rate, unsigned long *prate) |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1290 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1291 | struct clk_tegra *c = to_clk_tegra(hw); |
| 1292 | unsigned long parent_rate = __clk_get_rate(__clk_get_parent(hw->clk)); |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1293 | int divider; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1294 | |
| 1295 | pr_debug("%s: %s %lu\n", __func__, __clk_get_name(hw->clk), rate); |
| 1296 | |
| 1297 | if (prate) |
| 1298 | parent_rate = *prate; |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1299 | |
| 1300 | if (c->flags & DIV_U71) { |
Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 1301 | divider = clk_div71_get_divider(parent_rate, rate); |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1302 | if (divider < 0) |
| 1303 | return divider; |
| 1304 | |
Colin Cross | 421186e | 2011-02-12 18:21:47 -0800 | [diff] [blame] | 1305 | return DIV_ROUND_UP(parent_rate * 2, divider + 2); |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1306 | } else if (c->flags & DIV_U16) { |
Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 1307 | divider = clk_div16_get_divider(parent_rate, rate); |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1308 | if (divider < 0) |
| 1309 | return divider; |
Colin Cross | 421186e | 2011-02-12 18:21:47 -0800 | [diff] [blame] | 1310 | return DIV_ROUND_UP(parent_rate, divider + 1); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1311 | } |
| 1312 | return -EINVAL; |
| 1313 | } |
| 1314 | |
Prashant Gaikwad | 86edb87 | 2012-08-06 11:57:40 +0530 | [diff] [blame] | 1315 | struct clk_ops tegra_periph_clk_ops = { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1316 | .is_enabled = tegra20_periph_clk_is_enabled, |
| 1317 | .enable = tegra20_periph_clk_enable, |
| 1318 | .disable = tegra20_periph_clk_disable, |
| 1319 | .set_parent = tegra20_periph_clk_set_parent, |
| 1320 | .get_parent = tegra20_periph_clk_get_parent, |
| 1321 | .set_rate = tegra20_periph_clk_set_rate, |
| 1322 | .round_rate = tegra20_periph_clk_round_rate, |
| 1323 | .recalc_rate = tegra20_periph_clk_recalc_rate, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1324 | }; |
| 1325 | |
Colin Cross | 6d29682 | 2010-11-22 18:37:54 -0800 | [diff] [blame] | 1326 | /* External memory controller clock ops */ |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1327 | static void tegra20_emc_clk_init(struct clk_hw *hw) |
Colin Cross | 6d29682 | 2010-11-22 18:37:54 -0800 | [diff] [blame] | 1328 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1329 | struct clk_tegra *c = to_clk_tegra(hw); |
| 1330 | c->max_rate = __clk_get_rate(hw->clk); |
Colin Cross | 6d29682 | 2010-11-22 18:37:54 -0800 | [diff] [blame] | 1331 | } |
| 1332 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1333 | static long tegra20_emc_clk_round_rate(struct clk_hw *hw, unsigned long rate, |
| 1334 | unsigned long *prate) |
Colin Cross | 6d29682 | 2010-11-22 18:37:54 -0800 | [diff] [blame] | 1335 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1336 | struct clk_tegra *c = to_clk_tegra(hw); |
Stephen Warren | e186ad7 | 2012-02-06 17:09:15 -0800 | [diff] [blame] | 1337 | long emc_rate; |
| 1338 | long clk_rate; |
Colin Cross | 6d29682 | 2010-11-22 18:37:54 -0800 | [diff] [blame] | 1339 | |
Stephen Warren | e186ad7 | 2012-02-06 17:09:15 -0800 | [diff] [blame] | 1340 | /* |
| 1341 | * The slowest entry in the EMC clock table that is at least as |
| 1342 | * fast as rate. |
| 1343 | */ |
| 1344 | emc_rate = tegra_emc_round_rate(rate); |
| 1345 | if (emc_rate < 0) |
Colin Cross | 6d29682 | 2010-11-22 18:37:54 -0800 | [diff] [blame] | 1346 | return c->max_rate; |
| 1347 | |
Stephen Warren | e186ad7 | 2012-02-06 17:09:15 -0800 | [diff] [blame] | 1348 | /* |
| 1349 | * The fastest rate the PLL will generate that is at most the |
| 1350 | * requested rate. |
| 1351 | */ |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1352 | clk_rate = tegra20_periph_clk_round_rate(hw, emc_rate, NULL); |
Colin Cross | 6d29682 | 2010-11-22 18:37:54 -0800 | [diff] [blame] | 1353 | |
Stephen Warren | e186ad7 | 2012-02-06 17:09:15 -0800 | [diff] [blame] | 1354 | /* |
| 1355 | * If this fails, and emc_rate > clk_rate, it's because the maximum |
| 1356 | * rate in the EMC tables is larger than the maximum rate of the EMC |
| 1357 | * clock. The EMC clock's max rate is the rate it was running when the |
| 1358 | * kernel booted. Such a mismatch is probably due to using the wrong |
| 1359 | * BCT, i.e. using a Tegra20 BCT with an EMC table written for Tegra25. |
| 1360 | */ |
| 1361 | WARN_ONCE(emc_rate != clk_rate, |
| 1362 | "emc_rate %ld != clk_rate %ld", |
| 1363 | emc_rate, clk_rate); |
| 1364 | |
| 1365 | return emc_rate; |
Colin Cross | 6d29682 | 2010-11-22 18:37:54 -0800 | [diff] [blame] | 1366 | } |
| 1367 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1368 | static int tegra20_emc_clk_set_rate(struct clk_hw *hw, unsigned long rate, |
| 1369 | unsigned long parent_rate) |
Colin Cross | 6d29682 | 2010-11-22 18:37:54 -0800 | [diff] [blame] | 1370 | { |
| 1371 | int ret; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1372 | |
Colin Cross | 6d29682 | 2010-11-22 18:37:54 -0800 | [diff] [blame] | 1373 | /* |
| 1374 | * The Tegra2 memory controller has an interlock with the clock |
| 1375 | * block that allows memory shadowed registers to be updated, |
| 1376 | * and then transfer them to the main registers at the same |
| 1377 | * time as the clock update without glitches. |
| 1378 | */ |
| 1379 | ret = tegra_emc_set_rate(rate); |
| 1380 | if (ret < 0) |
| 1381 | return ret; |
| 1382 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1383 | ret = tegra20_periph_clk_set_rate(hw, rate, parent_rate); |
Colin Cross | 6d29682 | 2010-11-22 18:37:54 -0800 | [diff] [blame] | 1384 | udelay(1); |
| 1385 | |
| 1386 | return ret; |
| 1387 | } |
| 1388 | |
Prashant Gaikwad | 86edb87 | 2012-08-06 11:57:40 +0530 | [diff] [blame] | 1389 | struct clk_ops tegra_emc_clk_ops = { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1390 | .init = tegra20_emc_clk_init, |
| 1391 | .is_enabled = tegra20_periph_clk_is_enabled, |
| 1392 | .enable = tegra20_periph_clk_enable, |
| 1393 | .disable = tegra20_periph_clk_disable, |
| 1394 | .set_parent = tegra20_periph_clk_set_parent, |
| 1395 | .get_parent = tegra20_periph_clk_get_parent, |
| 1396 | .set_rate = tegra20_emc_clk_set_rate, |
| 1397 | .round_rate = tegra20_emc_clk_round_rate, |
| 1398 | .recalc_rate = tegra20_periph_clk_recalc_rate, |
Colin Cross | 6d29682 | 2010-11-22 18:37:54 -0800 | [diff] [blame] | 1399 | }; |
| 1400 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1401 | /* Clock doubler ops */ |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1402 | static int tegra20_clk_double_is_enabled(struct clk_hw *hw) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1403 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1404 | struct clk_tegra *c = to_clk_tegra(hw); |
| 1405 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1406 | c->state = ON; |
Colin Cross | 1be3d05 | 2011-02-21 16:44:07 -0800 | [diff] [blame] | 1407 | |
| 1408 | if (!c->u.periph.clk_num) |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1409 | goto out; |
Colin Cross | 1be3d05 | 2011-02-21 16:44:07 -0800 | [diff] [blame] | 1410 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1411 | if (!(clk_readl(CLK_OUT_ENB + PERIPH_CLK_TO_ENB_REG(c)) & |
| 1412 | PERIPH_CLK_TO_ENB_BIT(c))) |
| 1413 | c->state = OFF; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1414 | |
| 1415 | out: |
| 1416 | return c->state; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1417 | }; |
| 1418 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1419 | static unsigned long tegra20_clk_double_recalc_rate(struct clk_hw *hw, |
| 1420 | unsigned long prate) |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1421 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1422 | struct clk_tegra *c = to_clk_tegra(hw); |
| 1423 | u64 rate = prate; |
| 1424 | |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1425 | c->mul = 2; |
| 1426 | c->div = 1; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1427 | |
| 1428 | rate *= c->mul; |
| 1429 | rate += c->div - 1; /* round up */ |
| 1430 | do_div(rate, c->div); |
| 1431 | |
| 1432 | return rate; |
| 1433 | } |
| 1434 | |
| 1435 | static long tegra20_clk_double_round_rate(struct clk_hw *hw, unsigned long rate, |
| 1436 | unsigned long *prate) |
| 1437 | { |
| 1438 | unsigned long output_rate = *prate; |
| 1439 | |
| 1440 | do_div(output_rate, 2); |
| 1441 | return output_rate; |
| 1442 | } |
| 1443 | |
| 1444 | static int tegra20_clk_double_set_rate(struct clk_hw *hw, unsigned long rate, |
| 1445 | unsigned long parent_rate) |
| 1446 | { |
| 1447 | if (rate != 2 * parent_rate) |
| 1448 | return -EINVAL; |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1449 | return 0; |
| 1450 | } |
| 1451 | |
Prashant Gaikwad | 86edb87 | 2012-08-06 11:57:40 +0530 | [diff] [blame] | 1452 | struct clk_ops tegra_clk_double_ops = { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1453 | .is_enabled = tegra20_clk_double_is_enabled, |
| 1454 | .enable = tegra20_periph_clk_enable, |
| 1455 | .disable = tegra20_periph_clk_disable, |
| 1456 | .set_rate = tegra20_clk_double_set_rate, |
| 1457 | .recalc_rate = tegra20_clk_double_recalc_rate, |
| 1458 | .round_rate = tegra20_clk_double_round_rate, |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1459 | }; |
| 1460 | |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 1461 | /* Audio sync clock ops */ |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1462 | static int tegra20_audio_sync_clk_is_enabled(struct clk_hw *hw) |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1463 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1464 | struct clk_tegra *c = to_clk_tegra(hw); |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1465 | u32 val = clk_readl(c->reg); |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1466 | |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1467 | c->state = (val & (1<<4)) ? OFF : ON; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1468 | return c->state; |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1469 | } |
| 1470 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1471 | static int tegra20_audio_sync_clk_enable(struct clk_hw *hw) |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1472 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1473 | struct clk_tegra *c = to_clk_tegra(hw); |
| 1474 | |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1475 | clk_writel(0, c->reg); |
| 1476 | return 0; |
| 1477 | } |
| 1478 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1479 | static void tegra20_audio_sync_clk_disable(struct clk_hw *hw) |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1480 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1481 | struct clk_tegra *c = to_clk_tegra(hw); |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1482 | clk_writel(1, c->reg); |
| 1483 | } |
| 1484 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1485 | static u8 tegra20_audio_sync_clk_get_parent(struct clk_hw *hw) |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1486 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1487 | struct clk_tegra *c = to_clk_tegra(hw); |
| 1488 | u32 val = clk_readl(c->reg); |
| 1489 | int source; |
| 1490 | |
| 1491 | source = val & 0xf; |
| 1492 | return source; |
| 1493 | } |
| 1494 | |
| 1495 | static int tegra20_audio_sync_clk_set_parent(struct clk_hw *hw, u8 index) |
| 1496 | { |
| 1497 | struct clk_tegra *c = to_clk_tegra(hw); |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1498 | u32 val; |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1499 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1500 | val = clk_readl(c->reg); |
| 1501 | val &= ~0xf; |
| 1502 | val |= index; |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1503 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1504 | clk_writel(val, c->reg); |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1505 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1506 | return 0; |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1507 | } |
| 1508 | |
Prashant Gaikwad | 86edb87 | 2012-08-06 11:57:40 +0530 | [diff] [blame] | 1509 | struct clk_ops tegra_audio_sync_clk_ops = { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1510 | .is_enabled = tegra20_audio_sync_clk_is_enabled, |
| 1511 | .enable = tegra20_audio_sync_clk_enable, |
| 1512 | .disable = tegra20_audio_sync_clk_disable, |
| 1513 | .set_parent = tegra20_audio_sync_clk_set_parent, |
| 1514 | .get_parent = tegra20_audio_sync_clk_get_parent, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1515 | }; |
| 1516 | |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 1517 | /* cdev1 and cdev2 (dap_mclk1 and dap_mclk2) ops */ |
| 1518 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1519 | static int tegra20_cdev_clk_is_enabled(struct clk_hw *hw) |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 1520 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1521 | struct clk_tegra *c = to_clk_tegra(hw); |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 1522 | /* We could un-tristate the cdev1 or cdev2 pingroup here; this is |
| 1523 | * currently done in the pinmux code. */ |
| 1524 | c->state = ON; |
Colin Cross | 1be3d05 | 2011-02-21 16:44:07 -0800 | [diff] [blame] | 1525 | |
| 1526 | BUG_ON(!c->u.periph.clk_num); |
| 1527 | |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 1528 | if (!(clk_readl(CLK_OUT_ENB + PERIPH_CLK_TO_ENB_REG(c)) & |
| 1529 | PERIPH_CLK_TO_ENB_BIT(c))) |
| 1530 | c->state = OFF; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1531 | return c->state; |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 1532 | } |
| 1533 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1534 | static int tegra20_cdev_clk_enable(struct clk_hw *hw) |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 1535 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1536 | struct clk_tegra *c = to_clk_tegra(hw); |
Colin Cross | 1be3d05 | 2011-02-21 16:44:07 -0800 | [diff] [blame] | 1537 | BUG_ON(!c->u.periph.clk_num); |
| 1538 | |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 1539 | clk_writel(PERIPH_CLK_TO_ENB_BIT(c), |
| 1540 | CLK_OUT_ENB_SET + PERIPH_CLK_TO_ENB_SET_REG(c)); |
| 1541 | return 0; |
| 1542 | } |
| 1543 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1544 | static void tegra20_cdev_clk_disable(struct clk_hw *hw) |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 1545 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1546 | struct clk_tegra *c = to_clk_tegra(hw); |
Colin Cross | 1be3d05 | 2011-02-21 16:44:07 -0800 | [diff] [blame] | 1547 | BUG_ON(!c->u.periph.clk_num); |
| 1548 | |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 1549 | clk_writel(PERIPH_CLK_TO_ENB_BIT(c), |
| 1550 | CLK_OUT_ENB_CLR + PERIPH_CLK_TO_ENB_SET_REG(c)); |
| 1551 | } |
| 1552 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1553 | static unsigned long tegra20_cdev_recalc_rate(struct clk_hw *hw, |
| 1554 | unsigned long prate) |
| 1555 | { |
| 1556 | return to_clk_tegra(hw)->fixed_rate; |
| 1557 | } |
| 1558 | |
Prashant Gaikwad | 86edb87 | 2012-08-06 11:57:40 +0530 | [diff] [blame] | 1559 | struct clk_ops tegra_cdev_clk_ops = { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1560 | .is_enabled = tegra20_cdev_clk_is_enabled, |
| 1561 | .enable = tegra20_cdev_clk_enable, |
| 1562 | .disable = tegra20_cdev_clk_disable, |
| 1563 | .recalc_rate = tegra20_cdev_recalc_rate, |
Colin Cross | 310992c | 2011-02-12 16:14:03 -0800 | [diff] [blame] | 1564 | }; |
Joseph Lo | dab403e | 2012-08-16 17:31:48 +0800 | [diff] [blame^] | 1565 | |
| 1566 | /* Tegra20 CPU clock and reset control functions */ |
| 1567 | static void tegra20_wait_cpu_in_reset(u32 cpu) |
| 1568 | { |
| 1569 | unsigned int reg; |
| 1570 | |
| 1571 | do { |
| 1572 | reg = readl(reg_clk_base + |
| 1573 | TEGRA_CLK_RST_CONTROLLER_RST_CPU_CMPLX_SET); |
| 1574 | cpu_relax(); |
| 1575 | } while (!(reg & (1 << cpu))); /* check CPU been reset or not */ |
| 1576 | |
| 1577 | return; |
| 1578 | } |
| 1579 | |
| 1580 | static void tegra20_put_cpu_in_reset(u32 cpu) |
| 1581 | { |
| 1582 | writel(CPU_RESET(cpu), |
| 1583 | reg_clk_base + TEGRA_CLK_RST_CONTROLLER_RST_CPU_CMPLX_SET); |
| 1584 | dmb(); |
| 1585 | } |
| 1586 | |
| 1587 | static void tegra20_cpu_out_of_reset(u32 cpu) |
| 1588 | { |
| 1589 | writel(CPU_RESET(cpu), |
| 1590 | reg_clk_base + TEGRA_CLK_RST_CONTROLLER_RST_CPU_CMPLX_CLR); |
| 1591 | wmb(); |
| 1592 | } |
| 1593 | |
| 1594 | static void tegra20_enable_cpu_clock(u32 cpu) |
| 1595 | { |
| 1596 | unsigned int reg; |
| 1597 | |
| 1598 | reg = readl(reg_clk_base + TEGRA_CLK_RST_CONTROLLER_CLK_CPU_CMPLX); |
| 1599 | writel(reg & ~CPU_CLOCK(cpu), |
| 1600 | reg_clk_base + TEGRA_CLK_RST_CONTROLLER_CLK_CPU_CMPLX); |
| 1601 | barrier(); |
| 1602 | reg = readl(reg_clk_base + TEGRA_CLK_RST_CONTROLLER_CLK_CPU_CMPLX); |
| 1603 | } |
| 1604 | |
| 1605 | static void tegra20_disable_cpu_clock(u32 cpu) |
| 1606 | { |
| 1607 | unsigned int reg; |
| 1608 | |
| 1609 | reg = readl(reg_clk_base + TEGRA_CLK_RST_CONTROLLER_CLK_CPU_CMPLX); |
| 1610 | writel(reg | CPU_CLOCK(cpu), |
| 1611 | reg_clk_base + TEGRA_CLK_RST_CONTROLLER_CLK_CPU_CMPLX); |
| 1612 | } |
| 1613 | |
| 1614 | static struct tegra_cpu_car_ops tegra20_cpu_car_ops = { |
| 1615 | .wait_for_reset = tegra20_wait_cpu_in_reset, |
| 1616 | .put_in_reset = tegra20_put_cpu_in_reset, |
| 1617 | .out_of_reset = tegra20_cpu_out_of_reset, |
| 1618 | .enable_clock = tegra20_enable_cpu_clock, |
| 1619 | .disable_clock = tegra20_disable_cpu_clock, |
| 1620 | }; |
| 1621 | |
| 1622 | void __init tegra20_cpu_car_ops_init(void) |
| 1623 | { |
| 1624 | tegra_cpu_car_ops = &tegra20_cpu_car_ops; |
| 1625 | } |