blob: 4f68fb495f94611a38303e2e9bbc8a6889c38134 [file] [log] [blame]
Matt Wagantallab1adce2012-01-24 14:57:24 -08001/* Copyright (c) 2009-2012, Code Aurora Forum. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 */
13
14#define pr_fmt(fmt) "%s: " fmt, __func__
15
16#include <linux/kernel.h>
17#include <linux/init.h>
18#include <linux/err.h>
19#include <linux/ctype.h>
20#include <linux/bitops.h>
21#include <linux/io.h>
22#include <linux/spinlock.h>
23#include <linux/delay.h>
24#include <linux/clk.h>
25
26#include <mach/msm_iomap.h>
27#include <mach/clk.h>
28#include <mach/scm-io.h>
29
30#include "clock.h"
31#include "clock-local.h"
32
33#ifdef CONFIG_MSM_SECURE_IO
34#undef readl_relaxed
35#undef writel_relaxed
36#define readl_relaxed secure_readl
37#define writel_relaxed secure_writel
38#endif
39
40/*
41 * When enabling/disabling a clock, check the halt bit up to this number
42 * number of times (with a 1 us delay in between) before continuing.
43 */
Stephen Boyd138da0e2011-08-05 13:25:57 -070044#define HALT_CHECK_MAX_LOOPS 200
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070045/* For clock without halt checking, wait this long after enables/disables. */
46#define HALT_CHECK_DELAY_US 10
47
48DEFINE_SPINLOCK(local_clock_reg_lock);
Matt Wagantall84f43fd2011-08-16 23:28:38 -070049struct clk_freq_tbl rcg_dummy_freq = F_END;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070050
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070051/*
52 * Common Set-Rate Functions
53 */
54
55/* For clocks with MND dividers. */
56void set_rate_mnd(struct rcg_clk *clk, struct clk_freq_tbl *nf)
57{
58 uint32_t ns_reg_val, ctl_reg_val;
59
60 /* Assert MND reset. */
61 ns_reg_val = readl_relaxed(clk->ns_reg);
62 ns_reg_val |= BIT(7);
63 writel_relaxed(ns_reg_val, clk->ns_reg);
64
65 /* Program M and D values. */
66 writel_relaxed(nf->md_val, clk->md_reg);
67
68 /* If the clock has a separate CC register, program it. */
69 if (clk->ns_reg != clk->b.ctl_reg) {
70 ctl_reg_val = readl_relaxed(clk->b.ctl_reg);
71 ctl_reg_val &= ~(clk->ctl_mask);
72 ctl_reg_val |= nf->ctl_val;
73 writel_relaxed(ctl_reg_val, clk->b.ctl_reg);
74 }
75
76 /* Deassert MND reset. */
77 ns_reg_val &= ~BIT(7);
78 writel_relaxed(ns_reg_val, clk->ns_reg);
79}
80
81void set_rate_nop(struct rcg_clk *clk, struct clk_freq_tbl *nf)
82{
83 /*
84 * Nothing to do for fixed-rate or integer-divider clocks. Any settings
85 * in NS registers are applied in the enable path, since power can be
86 * saved by leaving an un-clocked or slowly-clocked source selected
87 * until the clock is enabled.
88 */
89}
90
91void set_rate_mnd_8(struct rcg_clk *clk, struct clk_freq_tbl *nf)
92{
93 uint32_t ctl_reg_val;
94
95 /* Assert MND reset. */
96 ctl_reg_val = readl_relaxed(clk->b.ctl_reg);
97 ctl_reg_val |= BIT(8);
98 writel_relaxed(ctl_reg_val, clk->b.ctl_reg);
99
100 /* Program M and D values. */
101 writel_relaxed(nf->md_val, clk->md_reg);
102
103 /* Program MN counter Enable and Mode. */
104 ctl_reg_val &= ~(clk->ctl_mask);
105 ctl_reg_val |= nf->ctl_val;
106 writel_relaxed(ctl_reg_val, clk->b.ctl_reg);
107
108 /* Deassert MND reset. */
109 ctl_reg_val &= ~BIT(8);
110 writel_relaxed(ctl_reg_val, clk->b.ctl_reg);
111}
112
113void set_rate_mnd_banked(struct rcg_clk *clk, struct clk_freq_tbl *nf)
114{
Stephen Boydc78d9a72011-07-20 00:46:24 -0700115 struct bank_masks *banks = clk->bank_info;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700116 const struct bank_mask_info *new_bank_masks;
117 const struct bank_mask_info *old_bank_masks;
118 uint32_t ns_reg_val, ctl_reg_val;
119 uint32_t bank_sel;
120
121 /*
122 * Determine active bank and program the other one. If the clock is
123 * off, program the active bank since bank switching won't work if
124 * both banks aren't running.
125 */
126 ctl_reg_val = readl_relaxed(clk->b.ctl_reg);
127 bank_sel = !!(ctl_reg_val & banks->bank_sel_mask);
128 /* If clock isn't running, don't switch banks. */
129 bank_sel ^= (!clk->enabled || clk->current_freq->freq_hz == 0);
130 if (bank_sel == 0) {
131 new_bank_masks = &banks->bank1_mask;
132 old_bank_masks = &banks->bank0_mask;
133 } else {
134 new_bank_masks = &banks->bank0_mask;
135 old_bank_masks = &banks->bank1_mask;
136 }
137
138 ns_reg_val = readl_relaxed(clk->ns_reg);
139
140 /* Assert bank MND reset. */
141 ns_reg_val |= new_bank_masks->rst_mask;
142 writel_relaxed(ns_reg_val, clk->ns_reg);
143
144 /*
145 * Program NS only if the clock is enabled, since the NS will be set
146 * as part of the enable procedure and should remain with a low-power
147 * MUX input selected until then.
148 */
149 if (clk->enabled) {
150 ns_reg_val &= ~(new_bank_masks->ns_mask);
151 ns_reg_val |= (nf->ns_val & new_bank_masks->ns_mask);
152 writel_relaxed(ns_reg_val, clk->ns_reg);
153 }
154
155 writel_relaxed(nf->md_val, new_bank_masks->md_reg);
156
157 /* Enable counter only if clock is enabled. */
158 if (clk->enabled)
159 ctl_reg_val |= new_bank_masks->mnd_en_mask;
160 else
161 ctl_reg_val &= ~(new_bank_masks->mnd_en_mask);
162
163 ctl_reg_val &= ~(new_bank_masks->mode_mask);
164 ctl_reg_val |= (nf->ctl_val & new_bank_masks->mode_mask);
165 writel_relaxed(ctl_reg_val, clk->b.ctl_reg);
166
167 /* Deassert bank MND reset. */
168 ns_reg_val &= ~(new_bank_masks->rst_mask);
169 writel_relaxed(ns_reg_val, clk->ns_reg);
170
171 /*
172 * Switch to the new bank if clock is running. If it isn't, then
173 * no switch is necessary since we programmed the active bank.
174 */
175 if (clk->enabled && clk->current_freq->freq_hz) {
176 ctl_reg_val ^= banks->bank_sel_mask;
177 writel_relaxed(ctl_reg_val, clk->b.ctl_reg);
178 /*
179 * Wait at least 6 cycles of slowest bank's clock
180 * for the glitch-free MUX to fully switch sources.
181 */
182 mb();
183 udelay(1);
184
185 /* Disable old bank's MN counter. */
186 ctl_reg_val &= ~(old_bank_masks->mnd_en_mask);
187 writel_relaxed(ctl_reg_val, clk->b.ctl_reg);
188
189 /* Program old bank to a low-power source and divider. */
190 ns_reg_val &= ~(old_bank_masks->ns_mask);
191 ns_reg_val |= (clk->freq_tbl->ns_val & old_bank_masks->ns_mask);
192 writel_relaxed(ns_reg_val, clk->ns_reg);
193 }
194
Matt Wagantall07c45472012-02-10 23:27:24 -0800195 /* Update the MND_EN and NS masks to match the current bank. */
196 clk->mnd_en_mask = new_bank_masks->mnd_en_mask;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700197 clk->ns_mask = new_bank_masks->ns_mask;
198}
199
200void set_rate_div_banked(struct rcg_clk *clk, struct clk_freq_tbl *nf)
201{
Stephen Boydc78d9a72011-07-20 00:46:24 -0700202 struct bank_masks *banks = clk->bank_info;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700203 const struct bank_mask_info *new_bank_masks;
204 const struct bank_mask_info *old_bank_masks;
205 uint32_t ns_reg_val, bank_sel;
206
207 /*
208 * Determine active bank and program the other one. If the clock is
209 * off, program the active bank since bank switching won't work if
210 * both banks aren't running.
211 */
212 ns_reg_val = readl_relaxed(clk->ns_reg);
213 bank_sel = !!(ns_reg_val & banks->bank_sel_mask);
214 /* If clock isn't running, don't switch banks. */
215 bank_sel ^= (!clk->enabled || clk->current_freq->freq_hz == 0);
216 if (bank_sel == 0) {
217 new_bank_masks = &banks->bank1_mask;
218 old_bank_masks = &banks->bank0_mask;
219 } else {
220 new_bank_masks = &banks->bank0_mask;
221 old_bank_masks = &banks->bank1_mask;
222 }
223
224 /*
225 * Program NS only if the clock is enabled, since the NS will be set
226 * as part of the enable procedure and should remain with a low-power
227 * MUX input selected until then.
228 */
229 if (clk->enabled) {
230 ns_reg_val &= ~(new_bank_masks->ns_mask);
231 ns_reg_val |= (nf->ns_val & new_bank_masks->ns_mask);
232 writel_relaxed(ns_reg_val, clk->ns_reg);
233 }
234
235 /*
236 * Switch to the new bank if clock is running. If it isn't, then
237 * no switch is necessary since we programmed the active bank.
238 */
239 if (clk->enabled && clk->current_freq->freq_hz) {
240 ns_reg_val ^= banks->bank_sel_mask;
241 writel_relaxed(ns_reg_val, clk->ns_reg);
242 /*
243 * Wait at least 6 cycles of slowest bank's clock
244 * for the glitch-free MUX to fully switch sources.
245 */
246 mb();
247 udelay(1);
248
249 /* Program old bank to a low-power source and divider. */
250 ns_reg_val &= ~(old_bank_masks->ns_mask);
251 ns_reg_val |= (clk->freq_tbl->ns_val & old_bank_masks->ns_mask);
252 writel_relaxed(ns_reg_val, clk->ns_reg);
253 }
254
255 /* Update the NS mask to match the current bank. */
256 clk->ns_mask = new_bank_masks->ns_mask;
257}
258
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700259/*
260 * Clock enable/disable functions
261 */
262
263/* Return non-zero if a clock status registers shows the clock is halted. */
264static int branch_clk_is_halted(const struct branch *clk)
265{
266 int invert = (clk->halt_check == ENABLE);
267 int status_bit = readl_relaxed(clk->halt_reg) & BIT(clk->halt_bit);
268 return invert ? !status_bit : status_bit;
269}
270
Stephen Boyda52d7e32011-11-10 11:59:00 -0800271int branch_in_hwcg_mode(const struct branch *b)
272{
273 if (!b->hwcg_mask)
274 return 0;
275
276 return !!(readl_relaxed(b->hwcg_reg) & b->hwcg_mask);
277}
278
Stephen Boyd092fd182011-10-21 15:56:30 -0700279void __branch_clk_enable_reg(const struct branch *clk, const char *name)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700280{
281 u32 reg_val;
282
283 if (clk->en_mask) {
284 reg_val = readl_relaxed(clk->ctl_reg);
285 reg_val |= clk->en_mask;
286 writel_relaxed(reg_val, clk->ctl_reg);
287 }
288
289 /*
290 * Use a memory barrier since some halt status registers are
291 * not within the same 1K segment as the branch/root enable
292 * registers. It's also needed in the udelay() case to ensure
293 * the delay starts after the branch enable.
294 */
295 mb();
296
Stephen Boyda52d7e32011-11-10 11:59:00 -0800297 /* Skip checking halt bit if the clock is in hardware gated mode */
298 if (branch_in_hwcg_mode(clk))
299 return;
300
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700301 /* Wait for clock to enable before returning. */
302 if (clk->halt_check == DELAY)
303 udelay(HALT_CHECK_DELAY_US);
304 else if (clk->halt_check == ENABLE || clk->halt_check == HALT
305 || clk->halt_check == ENABLE_VOTED
306 || clk->halt_check == HALT_VOTED) {
307 int count;
308
309 /* Wait up to HALT_CHECK_MAX_LOOPS for clock to enable. */
310 for (count = HALT_CHECK_MAX_LOOPS; branch_clk_is_halted(clk)
311 && count > 0; count--)
312 udelay(1);
313 WARN(count == 0, "%s status stuck at 'off'", name);
314 }
315}
316
317/* Perform any register operations required to enable the clock. */
Matt Wagantall0625ea02011-07-13 18:51:56 -0700318static void __rcg_clk_enable_reg(struct rcg_clk *clk)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700319{
320 u32 reg_val;
321 void __iomem *const reg = clk->b.ctl_reg;
322
Matt Wagantall84f43fd2011-08-16 23:28:38 -0700323 WARN(clk->current_freq == &rcg_dummy_freq,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700324 "Attempting to enable %s before setting its rate. "
325 "Set the rate first!\n", clk->c.dbg_name);
326
327 /*
328 * Program the NS register, if applicable. NS registers are not
329 * set in the set_rate path because power can be saved by deferring
330 * the selection of a clocked source until the clock is enabled.
331 */
332 if (clk->ns_mask) {
333 reg_val = readl_relaxed(clk->ns_reg);
334 reg_val &= ~(clk->ns_mask);
335 reg_val |= (clk->current_freq->ns_val & clk->ns_mask);
336 writel_relaxed(reg_val, clk->ns_reg);
337 }
338
339 /* Enable MN counter, if applicable. */
340 reg_val = readl_relaxed(reg);
Matt Wagantall07c45472012-02-10 23:27:24 -0800341 if (clk->current_freq->md_val) {
342 reg_val |= clk->mnd_en_mask;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700343 writel_relaxed(reg_val, reg);
344 }
345 /* Enable root. */
346 if (clk->root_en_mask) {
347 reg_val |= clk->root_en_mask;
348 writel_relaxed(reg_val, reg);
349 }
350 __branch_clk_enable_reg(&clk->b, clk->c.dbg_name);
351}
352
353/* Perform any register operations required to disable the branch. */
Stephen Boyd092fd182011-10-21 15:56:30 -0700354u32 __branch_clk_disable_reg(const struct branch *clk, const char *name)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700355{
356 u32 reg_val;
357
358 reg_val = readl_relaxed(clk->ctl_reg);
359 if (clk->en_mask) {
360 reg_val &= ~(clk->en_mask);
361 writel_relaxed(reg_val, clk->ctl_reg);
362 }
363
364 /*
365 * Use a memory barrier since some halt status registers are
366 * not within the same K segment as the branch/root enable
367 * registers. It's also needed in the udelay() case to ensure
368 * the delay starts after the branch disable.
369 */
370 mb();
371
Stephen Boyda52d7e32011-11-10 11:59:00 -0800372 /* Skip checking halt bit if the clock is in hardware gated mode */
373 if (branch_in_hwcg_mode(clk))
374 return reg_val;
375
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700376 /* Wait for clock to disable before continuing. */
377 if (clk->halt_check == DELAY || clk->halt_check == ENABLE_VOTED
378 || clk->halt_check == HALT_VOTED)
379 udelay(HALT_CHECK_DELAY_US);
380 else if (clk->halt_check == ENABLE || clk->halt_check == HALT) {
381 int count;
382
383 /* Wait up to HALT_CHECK_MAX_LOOPS for clock to disable. */
384 for (count = HALT_CHECK_MAX_LOOPS; !branch_clk_is_halted(clk)
385 && count > 0; count--)
386 udelay(1);
387 WARN(count == 0, "%s status stuck at 'on'", name);
388 }
389
390 return reg_val;
391}
392
393/* Perform any register operations required to disable the generator. */
Matt Wagantall0625ea02011-07-13 18:51:56 -0700394static void __rcg_clk_disable_reg(struct rcg_clk *clk)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700395{
396 void __iomem *const reg = clk->b.ctl_reg;
397 uint32_t reg_val;
398
399 reg_val = __branch_clk_disable_reg(&clk->b, clk->c.dbg_name);
400 /* Disable root. */
401 if (clk->root_en_mask) {
402 reg_val &= ~(clk->root_en_mask);
403 writel_relaxed(reg_val, reg);
404 }
405 /* Disable MN counter, if applicable. */
Matt Wagantall07c45472012-02-10 23:27:24 -0800406 if (clk->current_freq->md_val) {
407 reg_val &= ~(clk->mnd_en_mask);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700408 writel_relaxed(reg_val, reg);
409 }
410 /*
411 * Program NS register to low-power value with an un-clocked or
412 * slowly-clocked source selected.
413 */
414 if (clk->ns_mask) {
415 reg_val = readl_relaxed(clk->ns_reg);
416 reg_val &= ~(clk->ns_mask);
417 reg_val |= (clk->freq_tbl->ns_val & clk->ns_mask);
418 writel_relaxed(reg_val, clk->ns_reg);
419 }
420}
421
Matt Wagantalle18bbc82011-10-06 10:07:28 -0700422/* Enable a rate-settable clock. */
423int rcg_clk_enable(struct clk *c)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700424{
425 unsigned long flags;
Matt Wagantalle18bbc82011-10-06 10:07:28 -0700426 struct rcg_clk *clk = to_rcg_clk(c);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700427
428 spin_lock_irqsave(&local_clock_reg_lock, flags);
Matt Wagantall0625ea02011-07-13 18:51:56 -0700429 __rcg_clk_enable_reg(clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700430 clk->enabled = true;
431 spin_unlock_irqrestore(&local_clock_reg_lock, flags);
Matt Wagantalle18bbc82011-10-06 10:07:28 -0700432
433 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700434}
435
Matt Wagantalle18bbc82011-10-06 10:07:28 -0700436/* Disable a rate-settable clock. */
437void rcg_clk_disable(struct clk *c)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700438{
439 unsigned long flags;
Matt Wagantalle18bbc82011-10-06 10:07:28 -0700440 struct rcg_clk *clk = to_rcg_clk(c);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700441
442 spin_lock_irqsave(&local_clock_reg_lock, flags);
Matt Wagantall0625ea02011-07-13 18:51:56 -0700443 __rcg_clk_disable_reg(clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700444 clk->enabled = false;
445 spin_unlock_irqrestore(&local_clock_reg_lock, flags);
446}
447
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700448/*
449 * Frequency-related functions
450 */
451
Matt Wagantallab1adce2012-01-24 14:57:24 -0800452/* Set a clock to an exact rate. */
453int rcg_clk_set_rate(struct clk *c, unsigned long rate)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700454{
Matt Wagantallab1adce2012-01-24 14:57:24 -0800455 struct rcg_clk *clk = to_rcg_clk(c);
456 struct clk_freq_tbl *nf, *cf;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700457 struct clk *chld;
Matt Wagantallab1adce2012-01-24 14:57:24 -0800458 int rc = 0;
459
460 for (nf = clk->freq_tbl; nf->freq_hz != FREQ_END
461 && nf->freq_hz != rate; nf++)
462 ;
463
464 if (nf->freq_hz == FREQ_END)
465 return -EINVAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700466
467 /* Check if frequency is actually changed. */
468 cf = clk->current_freq;
469 if (nf == cf)
Matt Wagantalle18bbc82011-10-06 10:07:28 -0700470 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700471
472 if (clk->enabled) {
Matt Wagantalle18bbc82011-10-06 10:07:28 -0700473 /* Enable source clock dependency for the new freq. */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700474 rc = clk_enable(nf->src_clk);
Matt Wagantalle18bbc82011-10-06 10:07:28 -0700475 if (rc)
476 return rc;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700477 }
478
479 spin_lock(&local_clock_reg_lock);
480
481 /* Disable branch if clock isn't dual-banked with a glitch-free MUX. */
Stephen Boydc78d9a72011-07-20 00:46:24 -0700482 if (!clk->bank_info) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700483 /* Disable all branches to prevent glitches. */
484 list_for_each_entry(chld, &clk->c.children, siblings) {
485 struct branch_clk *x = to_branch_clk(chld);
486 /*
487 * We don't need to grab the child's lock because
488 * we hold the local_clock_reg_lock and 'enabled' is
489 * only modified within lock.
490 */
491 if (x->enabled)
492 __branch_clk_disable_reg(&x->b, x->c.dbg_name);
493 }
494 if (clk->enabled)
Matt Wagantall0625ea02011-07-13 18:51:56 -0700495 __rcg_clk_disable_reg(clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700496 }
497
498 /* Perform clock-specific frequency switch operations. */
499 BUG_ON(!clk->set_rate);
500 clk->set_rate(clk, nf);
501
502 /*
Matt Wagantall0625ea02011-07-13 18:51:56 -0700503 * Current freq must be updated before __rcg_clk_enable_reg()
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700504 * is called to make sure the MNCNTR_EN bit is set correctly.
505 */
506 clk->current_freq = nf;
507
508 /* Enable any clocks that were disabled. */
Stephen Boydc78d9a72011-07-20 00:46:24 -0700509 if (!clk->bank_info) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700510 if (clk->enabled)
Matt Wagantall0625ea02011-07-13 18:51:56 -0700511 __rcg_clk_enable_reg(clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700512 /* Enable only branches that were ON before. */
513 list_for_each_entry(chld, &clk->c.children, siblings) {
514 struct branch_clk *x = to_branch_clk(chld);
515 if (x->enabled)
516 __branch_clk_enable_reg(&x->b, x->c.dbg_name);
517 }
518 }
519
520 spin_unlock(&local_clock_reg_lock);
521
Matt Wagantalle18bbc82011-10-06 10:07:28 -0700522 /* Release source requirements of the old freq. */
523 if (clk->enabled)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700524 clk_disable(cf->src_clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700525
526 return rc;
527}
528
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700529/* Get the currently-set rate of a clock in Hz. */
Matt Wagantall9de3bfb2011-11-03 20:13:12 -0700530unsigned long rcg_clk_get_rate(struct clk *c)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700531{
532 struct rcg_clk *clk = to_rcg_clk(c);
533 unsigned long flags;
534 unsigned ret = 0;
535
536 spin_lock_irqsave(&local_clock_reg_lock, flags);
537 ret = clk->current_freq->freq_hz;
538 spin_unlock_irqrestore(&local_clock_reg_lock, flags);
539
540 /*
541 * Return 0 if the rate has never been set. Might not be correct,
542 * but it's good enough.
543 */
544 if (ret == FREQ_END)
545 ret = 0;
546
547 return ret;
548}
549
550/* Check if a clock is currently enabled. */
Matt Wagantall0625ea02011-07-13 18:51:56 -0700551int rcg_clk_is_enabled(struct clk *clk)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700552{
553 return to_rcg_clk(clk)->enabled;
554}
555
556/* Return a supported rate that's at least the specified rate. */
Matt Wagantall9de3bfb2011-11-03 20:13:12 -0700557long rcg_clk_round_rate(struct clk *c, unsigned long rate)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700558{
559 struct rcg_clk *clk = to_rcg_clk(c);
560 struct clk_freq_tbl *f;
561
562 for (f = clk->freq_tbl; f->freq_hz != FREQ_END; f++)
563 if (f->freq_hz >= rate)
564 return f->freq_hz;
565
566 return -EPERM;
567}
568
569bool local_clk_is_local(struct clk *clk)
570{
571 return true;
572}
573
574/* Return the nth supported frequency for a given clock. */
Matt Wagantall0625ea02011-07-13 18:51:56 -0700575int rcg_clk_list_rate(struct clk *c, unsigned n)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700576{
577 struct rcg_clk *clk = to_rcg_clk(c);
578
579 if (!clk->freq_tbl || clk->freq_tbl->freq_hz == FREQ_END)
580 return -ENXIO;
581
582 return (clk->freq_tbl + n)->freq_hz;
583}
584
Matt Wagantall0625ea02011-07-13 18:51:56 -0700585struct clk *rcg_clk_get_parent(struct clk *clk)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700586{
587 return to_rcg_clk(clk)->current_freq->src_clk;
588}
589
Stephen Boyda52d7e32011-11-10 11:59:00 -0800590/* Disable hw clock gating if not set at boot */
591static void branch_handoff(struct branch *clk, struct clk *c)
592{
593 if (!branch_in_hwcg_mode(clk)) {
594 clk->hwcg_mask = 0;
595 c->flags &= ~CLKFLAG_HWCG;
596 } else {
597 c->flags |= CLKFLAG_HWCG;
598 }
599}
600
601int branch_clk_handoff(struct clk *c)
602{
603 struct branch_clk *clk = to_branch_clk(c);
604 branch_handoff(&clk->b, &clk->c);
605 return 0;
606}
607
Matt Wagantall271a6cd2011-09-20 16:06:31 -0700608int rcg_clk_handoff(struct clk *c)
Matt Wagantall14dc2af2011-08-12 13:16:06 -0700609{
610 struct rcg_clk *clk = to_rcg_clk(c);
611 uint32_t ctl_val, ns_val, md_val, ns_mask;
612 struct clk_freq_tbl *freq;
613
Stephen Boyda52d7e32011-11-10 11:59:00 -0800614 branch_handoff(&clk->b, &clk->c);
615
Matt Wagantall14dc2af2011-08-12 13:16:06 -0700616 ctl_val = readl_relaxed(clk->b.ctl_reg);
617 if (!(ctl_val & clk->root_en_mask))
Matt Wagantall271a6cd2011-09-20 16:06:31 -0700618 return 0;
Matt Wagantall14dc2af2011-08-12 13:16:06 -0700619
Stephen Boydc78d9a72011-07-20 00:46:24 -0700620 if (clk->bank_info) {
621 const struct bank_masks *bank_masks = clk->bank_info;
Matt Wagantall14dc2af2011-08-12 13:16:06 -0700622 const struct bank_mask_info *bank_info;
Stephen Boydc78d9a72011-07-20 00:46:24 -0700623 if (!(ctl_val & bank_masks->bank_sel_mask))
624 bank_info = &bank_masks->bank0_mask;
Matt Wagantall14dc2af2011-08-12 13:16:06 -0700625 else
Stephen Boydc78d9a72011-07-20 00:46:24 -0700626 bank_info = &bank_masks->bank1_mask;
Matt Wagantall14dc2af2011-08-12 13:16:06 -0700627
628 ns_mask = bank_info->ns_mask;
Tianyi Goue46938b2012-01-31 12:30:12 -0800629 md_val = bank_info->md_reg ?
630 readl_relaxed(bank_info->md_reg) : 0;
Matt Wagantall14dc2af2011-08-12 13:16:06 -0700631 } else {
632 ns_mask = clk->ns_mask;
633 md_val = clk->md_reg ? readl_relaxed(clk->md_reg) : 0;
634 }
635
636 ns_val = readl_relaxed(clk->ns_reg) & ns_mask;
637 for (freq = clk->freq_tbl; freq->freq_hz != FREQ_END; freq++) {
638 if ((freq->ns_val & ns_mask) == ns_val &&
Matt Wagantall07c45472012-02-10 23:27:24 -0800639 (!freq->md_val || freq->md_val == md_val)) {
Matt Wagantall14dc2af2011-08-12 13:16:06 -0700640 pr_info("%s rate=%d\n", clk->c.dbg_name, freq->freq_hz);
641 break;
642 }
643 }
644 if (freq->freq_hz == FREQ_END)
Matt Wagantall271a6cd2011-09-20 16:06:31 -0700645 return 0;
Matt Wagantall14dc2af2011-08-12 13:16:06 -0700646
647 clk->current_freq = freq;
Matt Wagantall271a6cd2011-09-20 16:06:31 -0700648
649 return 1;
Matt Wagantall14dc2af2011-08-12 13:16:06 -0700650}
651
Vikram Mulukutla31680ae2011-11-04 14:23:55 -0700652int pll_vote_clk_enable(struct clk *clk)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700653{
654 u32 ena;
655 unsigned long flags;
656 struct pll_vote_clk *pll = to_pll_vote_clk(clk);
657
658 spin_lock_irqsave(&local_clock_reg_lock, flags);
659 ena = readl_relaxed(pll->en_reg);
660 ena |= pll->en_mask;
661 writel_relaxed(ena, pll->en_reg);
662 spin_unlock_irqrestore(&local_clock_reg_lock, flags);
663
664 /* Wait until PLL is enabled */
665 while ((readl_relaxed(pll->status_reg) & BIT(16)) == 0)
666 cpu_relax();
667
668 return 0;
669}
670
Vikram Mulukutla31680ae2011-11-04 14:23:55 -0700671void pll_vote_clk_disable(struct clk *clk)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700672{
673 u32 ena;
674 unsigned long flags;
675 struct pll_vote_clk *pll = to_pll_vote_clk(clk);
676
677 spin_lock_irqsave(&local_clock_reg_lock, flags);
678 ena = readl_relaxed(pll->en_reg);
679 ena &= ~(pll->en_mask);
680 writel_relaxed(ena, pll->en_reg);
681 spin_unlock_irqrestore(&local_clock_reg_lock, flags);
682}
683
Vikram Mulukutla31680ae2011-11-04 14:23:55 -0700684struct clk *pll_vote_clk_get_parent(struct clk *clk)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700685{
686 struct pll_vote_clk *pll = to_pll_vote_clk(clk);
687 return pll->parent;
688}
689
Vikram Mulukutla31680ae2011-11-04 14:23:55 -0700690int pll_vote_clk_is_enabled(struct clk *clk)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700691{
692 struct pll_vote_clk *pll = to_pll_vote_clk(clk);
693 return !!(readl_relaxed(pll->status_reg) & BIT(16));
694}
695
696struct clk_ops clk_ops_pll_vote = {
697 .enable = pll_vote_clk_enable,
698 .disable = pll_vote_clk_disable,
Matt Wagantalle3d939d2011-11-06 11:21:37 -0800699 .auto_off = pll_vote_clk_disable,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700700 .is_enabled = pll_vote_clk_is_enabled,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700701 .get_parent = pll_vote_clk_get_parent,
702 .is_local = local_clk_is_local,
703};
704
705static int pll_clk_enable(struct clk *clk)
706{
707 u32 mode;
708 unsigned long flags;
709 struct pll_clk *pll = to_pll_clk(clk);
710
711 spin_lock_irqsave(&local_clock_reg_lock, flags);
712 mode = readl_relaxed(pll->mode_reg);
713 /* Disable PLL bypass mode. */
714 mode |= BIT(1);
715 writel_relaxed(mode, pll->mode_reg);
716
717 /*
718 * H/W requires a 5us delay between disabling the bypass and
719 * de-asserting the reset. Delay 10us just to be safe.
720 */
721 mb();
722 udelay(10);
723
724 /* De-assert active-low PLL reset. */
725 mode |= BIT(2);
726 writel_relaxed(mode, pll->mode_reg);
727
728 /* Wait until PLL is locked. */
729 mb();
730 udelay(50);
731
732 /* Enable PLL output. */
733 mode |= BIT(0);
734 writel_relaxed(mode, pll->mode_reg);
735
736 spin_unlock_irqrestore(&local_clock_reg_lock, flags);
737 return 0;
738}
739
740static void pll_clk_disable(struct clk *clk)
741{
742 u32 mode;
743 unsigned long flags;
744 struct pll_clk *pll = to_pll_clk(clk);
745
746 /*
747 * Disable the PLL output, disable test mode, enable
748 * the bypass mode, and assert the reset.
749 */
750 spin_lock_irqsave(&local_clock_reg_lock, flags);
751 mode = readl_relaxed(pll->mode_reg);
752 mode &= ~BM(3, 0);
753 writel_relaxed(mode, pll->mode_reg);
754 spin_unlock_irqrestore(&local_clock_reg_lock, flags);
755}
756
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700757static struct clk *pll_clk_get_parent(struct clk *clk)
758{
759 struct pll_clk *pll = to_pll_clk(clk);
760 return pll->parent;
761}
762
Vikram Mulukutla489e39e2011-08-31 18:04:05 -0700763int sr_pll_clk_enable(struct clk *clk)
764{
765 u32 mode;
766 unsigned long flags;
767 struct pll_clk *pll = to_pll_clk(clk);
768
769 spin_lock_irqsave(&local_clock_reg_lock, flags);
770 mode = readl_relaxed(pll->mode_reg);
771 /* De-assert active-low PLL reset. */
772 mode |= BIT(2);
773 writel_relaxed(mode, pll->mode_reg);
774
775 /*
776 * H/W requires a 5us delay between disabling the bypass and
777 * de-asserting the reset. Delay 10us just to be safe.
778 */
779 mb();
780 udelay(10);
781
782 /* Disable PLL bypass mode. */
783 mode |= BIT(1);
784 writel_relaxed(mode, pll->mode_reg);
785
786 /* Wait until PLL is locked. */
787 mb();
788 udelay(60);
789
790 /* Enable PLL output. */
791 mode |= BIT(0);
792 writel_relaxed(mode, pll->mode_reg);
793
794 spin_unlock_irqrestore(&local_clock_reg_lock, flags);
795 return 0;
796}
797
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700798struct clk_ops clk_ops_pll = {
799 .enable = pll_clk_enable,
800 .disable = pll_clk_disable,
Matt Wagantalle3d939d2011-11-06 11:21:37 -0800801 .auto_off = pll_clk_disable,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700802 .get_parent = pll_clk_get_parent,
803 .is_local = local_clk_is_local,
804};
805
806struct clk_ops clk_ops_gnd = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700807 .is_local = local_clk_is_local,
808};
809
810struct fixed_clk gnd_clk = {
811 .c = {
812 .dbg_name = "ground_clk",
813 .ops = &clk_ops_gnd,
814 CLK_INIT(gnd_clk.c),
815 },
816};
817
818struct clk_ops clk_ops_measure = {
819 .is_local = local_clk_is_local,
820};
821
822int branch_clk_enable(struct clk *clk)
823{
824 unsigned long flags;
825 struct branch_clk *branch = to_branch_clk(clk);
826
827 spin_lock_irqsave(&local_clock_reg_lock, flags);
828 __branch_clk_enable_reg(&branch->b, branch->c.dbg_name);
829 branch->enabled = true;
830 spin_unlock_irqrestore(&local_clock_reg_lock, flags);
831
832 return 0;
833}
834
835void branch_clk_disable(struct clk *clk)
836{
837 unsigned long flags;
838 struct branch_clk *branch = to_branch_clk(clk);
839
840 spin_lock_irqsave(&local_clock_reg_lock, flags);
841 __branch_clk_disable_reg(&branch->b, branch->c.dbg_name);
842 branch->enabled = false;
843 spin_unlock_irqrestore(&local_clock_reg_lock, flags);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700844}
845
846struct clk *branch_clk_get_parent(struct clk *clk)
847{
848 struct branch_clk *branch = to_branch_clk(clk);
849 return branch->parent;
850}
851
852int branch_clk_set_parent(struct clk *clk, struct clk *parent)
853{
854 /*
855 * We setup the parent pointer at init time in msm_clock_init().
856 * This check is to make sure drivers can't change the parent.
857 */
858 if (parent && list_empty(&clk->siblings)) {
859 list_add(&clk->siblings, &parent->children);
860 return 0;
861 }
862 return -EINVAL;
863}
864
865int branch_clk_is_enabled(struct clk *clk)
866{
867 struct branch_clk *branch = to_branch_clk(clk);
868 return branch->enabled;
869}
870
Stephen Boyda52d7e32011-11-10 11:59:00 -0800871static void branch_enable_hwcg(struct branch *b)
872{
873 unsigned long flags;
874 u32 reg_val;
875
876 spin_lock_irqsave(&local_clock_reg_lock, flags);
877 reg_val = readl_relaxed(b->hwcg_reg);
878 reg_val |= b->hwcg_mask;
879 writel_relaxed(reg_val, b->hwcg_reg);
880 spin_unlock_irqrestore(&local_clock_reg_lock, flags);
881}
882
883static void branch_disable_hwcg(struct branch *b)
884{
885 unsigned long flags;
886 u32 reg_val;
887
888 spin_lock_irqsave(&local_clock_reg_lock, flags);
889 reg_val = readl_relaxed(b->hwcg_reg);
890 reg_val &= ~b->hwcg_mask;
891 writel_relaxed(reg_val, b->hwcg_reg);
892 spin_unlock_irqrestore(&local_clock_reg_lock, flags);
893}
894
895void branch_clk_enable_hwcg(struct clk *clk)
896{
897 struct branch_clk *branch = to_branch_clk(clk);
898 branch_enable_hwcg(&branch->b);
899}
900
901void branch_clk_disable_hwcg(struct clk *clk)
902{
903 struct branch_clk *branch = to_branch_clk(clk);
904 branch_disable_hwcg(&branch->b);
905}
906
Matt Wagantall7e0b6c92012-01-20 18:48:05 -0800907static int branch_set_flags(struct branch *b, unsigned flags)
908{
909 unsigned long irq_flags;
910 u32 reg_val;
911 int ret = 0;
912
913 if (!b->retain_reg)
914 return -EPERM;
915
916 spin_lock_irqsave(&local_clock_reg_lock, irq_flags);
917 reg_val = readl_relaxed(b->retain_reg);
918 switch (flags) {
919 case CLKFLAG_RETAIN:
920 reg_val |= b->retain_mask;
921 break;
922 case CLKFLAG_NORETAIN:
923 reg_val &= ~b->retain_mask;
924 break;
925 default:
926 ret = -EINVAL;
927 }
928 writel_relaxed(reg_val, b->retain_reg);
929 spin_unlock_irqrestore(&local_clock_reg_lock, irq_flags);
930
931 return ret;
932}
933
934int branch_clk_set_flags(struct clk *clk, unsigned flags)
935{
936 return branch_set_flags(&to_branch_clk(clk)->b, flags);
937}
938
Stephen Boyda52d7e32011-11-10 11:59:00 -0800939int branch_clk_in_hwcg_mode(struct clk *c)
940{
941 struct branch_clk *clk = to_branch_clk(c);
942 return branch_in_hwcg_mode(&clk->b);
943}
944
945void rcg_clk_enable_hwcg(struct clk *clk)
946{
947 struct rcg_clk *rcg = to_rcg_clk(clk);
948 branch_enable_hwcg(&rcg->b);
949}
950
951void rcg_clk_disable_hwcg(struct clk *clk)
952{
953 struct rcg_clk *rcg = to_rcg_clk(clk);
954 branch_disable_hwcg(&rcg->b);
955}
956
957int rcg_clk_in_hwcg_mode(struct clk *c)
958{
959 struct rcg_clk *clk = to_rcg_clk(c);
960 return branch_in_hwcg_mode(&clk->b);
961}
962
Matt Wagantall7e0b6c92012-01-20 18:48:05 -0800963int rcg_clk_set_flags(struct clk *clk, unsigned flags)
964{
965 return branch_set_flags(&to_rcg_clk(clk)->b, flags);
966}
967
Stephen Boyda52d7e32011-11-10 11:59:00 -0800968int branch_reset(struct branch *b, enum clk_reset_action action)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700969{
970 int ret = 0;
971 u32 reg_val;
972 unsigned long flags;
973
Stephen Boyda52d7e32011-11-10 11:59:00 -0800974 if (!b->reset_reg)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700975 return -EPERM;
976
Stephen Boyda52d7e32011-11-10 11:59:00 -0800977 /* Disable hw gating when asserting a reset */
978 if (b->hwcg_mask && action == CLK_RESET_ASSERT)
979 branch_disable_hwcg(b);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700980
Stephen Boyda52d7e32011-11-10 11:59:00 -0800981 spin_lock_irqsave(&local_clock_reg_lock, flags);
982 /* Assert/Deassert reset */
983 reg_val = readl_relaxed(b->reset_reg);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700984 switch (action) {
985 case CLK_RESET_ASSERT:
Stephen Boyda52d7e32011-11-10 11:59:00 -0800986 reg_val |= b->reset_mask;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700987 break;
988 case CLK_RESET_DEASSERT:
Stephen Boyda52d7e32011-11-10 11:59:00 -0800989 reg_val &= ~b->reset_mask;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700990 break;
991 default:
992 ret = -EINVAL;
993 }
Stephen Boyda52d7e32011-11-10 11:59:00 -0800994 writel_relaxed(reg_val, b->reset_reg);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700995 spin_unlock_irqrestore(&local_clock_reg_lock, flags);
996
Stephen Boyda52d7e32011-11-10 11:59:00 -0800997 /* Enable hw gating when deasserting a reset */
998 if (b->hwcg_mask && action == CLK_RESET_DEASSERT)
999 branch_enable_hwcg(b);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001000 /* Make sure write is issued before returning. */
1001 mb();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001002 return ret;
1003}
1004
1005int branch_clk_reset(struct clk *clk, enum clk_reset_action action)
1006{
1007 return branch_reset(&to_branch_clk(clk)->b, action);
1008}
Stephen Boydb8ad8222011-11-28 12:17:58 -08001009
Stephen Boyd7bf28142011-12-07 00:30:52 -08001010int rcg_clk_reset(struct clk *clk, enum clk_reset_action action)
1011{
1012 return branch_reset(&to_rcg_clk(clk)->b, action);
1013}
1014
Stephen Boydb8ad8222011-11-28 12:17:58 -08001015static int cdiv_clk_enable(struct clk *c)
1016{
1017 unsigned long flags;
1018 struct cdiv_clk *clk = to_cdiv_clk(c);
1019
1020 spin_lock_irqsave(&local_clock_reg_lock, flags);
1021 __branch_clk_enable_reg(&clk->b, clk->c.dbg_name);
1022 spin_unlock_irqrestore(&local_clock_reg_lock, flags);
1023
1024 return 0;
1025}
1026
1027static void cdiv_clk_disable(struct clk *c)
1028{
1029 unsigned long flags;
1030 struct cdiv_clk *clk = to_cdiv_clk(c);
1031
1032 spin_lock_irqsave(&local_clock_reg_lock, flags);
1033 __branch_clk_disable_reg(&clk->b, clk->c.dbg_name);
1034 spin_unlock_irqrestore(&local_clock_reg_lock, flags);
1035}
1036
1037static int cdiv_clk_set_rate(struct clk *c, unsigned long rate)
1038{
1039 struct cdiv_clk *clk = to_cdiv_clk(c);
1040 u32 reg_val;
1041
1042 if (rate > clk->max_div)
1043 return -EINVAL;
1044 /* Check if frequency is actually changed. */
1045 if (rate == clk->cur_div)
1046 return 0;
1047
1048 spin_lock(&local_clock_reg_lock);
1049 reg_val = readl_relaxed(clk->ns_reg);
1050 reg_val &= ~(clk->ext_mask | (clk->max_div - 1) << clk->div_offset);
1051 /* Non-zero rates mean set a divider, zero means use external input */
1052 if (rate)
1053 reg_val |= (rate - 1) << clk->div_offset;
1054 else
1055 reg_val |= clk->ext_mask;
1056 writel_relaxed(reg_val, clk->ns_reg);
1057 spin_unlock(&local_clock_reg_lock);
1058
1059 clk->cur_div = rate;
1060 return 0;
1061}
1062
1063static unsigned long cdiv_clk_get_rate(struct clk *c)
1064{
1065 struct cdiv_clk *clk = to_cdiv_clk(c);
1066 return clk->cur_div;
1067}
1068
1069static long cdiv_clk_round_rate(struct clk *c, unsigned long rate)
1070{
1071 struct cdiv_clk *clk = to_cdiv_clk(c);
1072 return rate > clk->max_div ? -EPERM : rate;
1073}
1074
1075static int cdiv_clk_list_rate(struct clk *c, unsigned n)
1076{
1077 struct cdiv_clk *clk = to_cdiv_clk(c);
1078 return n > clk->max_div ? -ENXIO : n;
1079}
1080
1081static int cdiv_clk_handoff(struct clk *c)
1082{
1083 struct cdiv_clk *clk = to_cdiv_clk(c);
1084 u32 reg_val;
1085
Stephen Boyda52d7e32011-11-10 11:59:00 -08001086 branch_handoff(&clk->b, &clk->c);
1087
Stephen Boydb8ad8222011-11-28 12:17:58 -08001088 reg_val = readl_relaxed(clk->ns_reg);
1089 if (reg_val & clk->ext_mask) {
1090 clk->cur_div = 0;
1091 } else {
1092 reg_val >>= clk->div_offset;
1093 clk->cur_div = (reg_val & (clk->max_div - 1)) + 1;
1094 }
1095
1096 return 0;
1097}
1098
Stephen Boyda52d7e32011-11-10 11:59:00 -08001099static void cdiv_clk_enable_hwcg(struct clk *c)
1100{
1101 struct cdiv_clk *clk = to_cdiv_clk(c);
1102 branch_enable_hwcg(&clk->b);
1103}
1104
1105static void cdiv_clk_disable_hwcg(struct clk *c)
1106{
1107 struct cdiv_clk *clk = to_cdiv_clk(c);
1108 branch_disable_hwcg(&clk->b);
1109}
1110
1111static int cdiv_clk_in_hwcg_mode(struct clk *c)
1112{
1113 struct cdiv_clk *clk = to_cdiv_clk(c);
1114 return branch_in_hwcg_mode(&clk->b);
1115}
1116
Stephen Boydb8ad8222011-11-28 12:17:58 -08001117struct clk_ops clk_ops_cdiv = {
1118 .enable = cdiv_clk_enable,
1119 .disable = cdiv_clk_disable,
Stephen Boyda52d7e32011-11-10 11:59:00 -08001120 .in_hwcg_mode = cdiv_clk_in_hwcg_mode,
1121 .enable_hwcg = cdiv_clk_enable_hwcg,
1122 .disable_hwcg = cdiv_clk_disable_hwcg,
Stephen Boydb8ad8222011-11-28 12:17:58 -08001123 .auto_off = cdiv_clk_disable,
1124 .handoff = cdiv_clk_handoff,
1125 .set_rate = cdiv_clk_set_rate,
1126 .get_rate = cdiv_clk_get_rate,
1127 .list_rate = cdiv_clk_list_rate,
1128 .round_rate = cdiv_clk_round_rate,
1129 .is_local = local_clk_is_local,
1130};