blob: 3546ce02c6386debc0e86eca30d0095ac36dad9c [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/* Check if a clock is currently enabled. */
Matt Wagantall0625ea02011-07-13 18:51:56 -0700530int rcg_clk_is_enabled(struct clk *clk)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700531{
532 return to_rcg_clk(clk)->enabled;
533}
534
535/* Return a supported rate that's at least the specified rate. */
Matt Wagantall9de3bfb2011-11-03 20:13:12 -0700536long rcg_clk_round_rate(struct clk *c, unsigned long rate)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700537{
538 struct rcg_clk *clk = to_rcg_clk(c);
539 struct clk_freq_tbl *f;
540
541 for (f = clk->freq_tbl; f->freq_hz != FREQ_END; f++)
542 if (f->freq_hz >= rate)
543 return f->freq_hz;
544
545 return -EPERM;
546}
547
548bool local_clk_is_local(struct clk *clk)
549{
550 return true;
551}
552
553/* Return the nth supported frequency for a given clock. */
Matt Wagantall0625ea02011-07-13 18:51:56 -0700554int rcg_clk_list_rate(struct clk *c, unsigned n)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700555{
556 struct rcg_clk *clk = to_rcg_clk(c);
557
558 if (!clk->freq_tbl || clk->freq_tbl->freq_hz == FREQ_END)
559 return -ENXIO;
560
561 return (clk->freq_tbl + n)->freq_hz;
562}
563
Matt Wagantall0625ea02011-07-13 18:51:56 -0700564struct clk *rcg_clk_get_parent(struct clk *clk)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700565{
566 return to_rcg_clk(clk)->current_freq->src_clk;
567}
568
Stephen Boyda52d7e32011-11-10 11:59:00 -0800569/* Disable hw clock gating if not set at boot */
570static void branch_handoff(struct branch *clk, struct clk *c)
571{
572 if (!branch_in_hwcg_mode(clk)) {
573 clk->hwcg_mask = 0;
574 c->flags &= ~CLKFLAG_HWCG;
575 } else {
576 c->flags |= CLKFLAG_HWCG;
577 }
578}
579
580int branch_clk_handoff(struct clk *c)
581{
582 struct branch_clk *clk = to_branch_clk(c);
583 branch_handoff(&clk->b, &clk->c);
584 return 0;
585}
586
Matt Wagantall271a6cd2011-09-20 16:06:31 -0700587int rcg_clk_handoff(struct clk *c)
Matt Wagantall14dc2af2011-08-12 13:16:06 -0700588{
589 struct rcg_clk *clk = to_rcg_clk(c);
590 uint32_t ctl_val, ns_val, md_val, ns_mask;
591 struct clk_freq_tbl *freq;
592
Stephen Boyda52d7e32011-11-10 11:59:00 -0800593 branch_handoff(&clk->b, &clk->c);
594
Matt Wagantall14dc2af2011-08-12 13:16:06 -0700595 ctl_val = readl_relaxed(clk->b.ctl_reg);
596 if (!(ctl_val & clk->root_en_mask))
Matt Wagantall271a6cd2011-09-20 16:06:31 -0700597 return 0;
Matt Wagantall14dc2af2011-08-12 13:16:06 -0700598
Stephen Boydc78d9a72011-07-20 00:46:24 -0700599 if (clk->bank_info) {
600 const struct bank_masks *bank_masks = clk->bank_info;
Matt Wagantall14dc2af2011-08-12 13:16:06 -0700601 const struct bank_mask_info *bank_info;
Stephen Boydc78d9a72011-07-20 00:46:24 -0700602 if (!(ctl_val & bank_masks->bank_sel_mask))
603 bank_info = &bank_masks->bank0_mask;
Matt Wagantall14dc2af2011-08-12 13:16:06 -0700604 else
Stephen Boydc78d9a72011-07-20 00:46:24 -0700605 bank_info = &bank_masks->bank1_mask;
Matt Wagantall14dc2af2011-08-12 13:16:06 -0700606
607 ns_mask = bank_info->ns_mask;
Tianyi Goue46938b2012-01-31 12:30:12 -0800608 md_val = bank_info->md_reg ?
609 readl_relaxed(bank_info->md_reg) : 0;
Matt Wagantall14dc2af2011-08-12 13:16:06 -0700610 } else {
611 ns_mask = clk->ns_mask;
612 md_val = clk->md_reg ? readl_relaxed(clk->md_reg) : 0;
613 }
614
615 ns_val = readl_relaxed(clk->ns_reg) & ns_mask;
616 for (freq = clk->freq_tbl; freq->freq_hz != FREQ_END; freq++) {
617 if ((freq->ns_val & ns_mask) == ns_val &&
Matt Wagantall07c45472012-02-10 23:27:24 -0800618 (!freq->md_val || freq->md_val == md_val)) {
Matt Wagantall14dc2af2011-08-12 13:16:06 -0700619 pr_info("%s rate=%d\n", clk->c.dbg_name, freq->freq_hz);
620 break;
621 }
622 }
623 if (freq->freq_hz == FREQ_END)
Matt Wagantall271a6cd2011-09-20 16:06:31 -0700624 return 0;
Matt Wagantall14dc2af2011-08-12 13:16:06 -0700625
626 clk->current_freq = freq;
Stephen Boyde891ca32012-03-19 12:16:36 -0700627 c->rate = freq->freq_hz;
Matt Wagantall271a6cd2011-09-20 16:06:31 -0700628
629 return 1;
Matt Wagantall14dc2af2011-08-12 13:16:06 -0700630}
631
Vikram Mulukutla31680ae2011-11-04 14:23:55 -0700632int pll_vote_clk_enable(struct clk *clk)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700633{
634 u32 ena;
635 unsigned long flags;
636 struct pll_vote_clk *pll = to_pll_vote_clk(clk);
637
638 spin_lock_irqsave(&local_clock_reg_lock, flags);
639 ena = readl_relaxed(pll->en_reg);
640 ena |= pll->en_mask;
641 writel_relaxed(ena, pll->en_reg);
642 spin_unlock_irqrestore(&local_clock_reg_lock, flags);
643
644 /* Wait until PLL is enabled */
645 while ((readl_relaxed(pll->status_reg) & BIT(16)) == 0)
646 cpu_relax();
647
648 return 0;
649}
650
Vikram Mulukutla31680ae2011-11-04 14:23:55 -0700651void pll_vote_clk_disable(struct clk *clk)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700652{
653 u32 ena;
654 unsigned long flags;
655 struct pll_vote_clk *pll = to_pll_vote_clk(clk);
656
657 spin_lock_irqsave(&local_clock_reg_lock, flags);
658 ena = readl_relaxed(pll->en_reg);
659 ena &= ~(pll->en_mask);
660 writel_relaxed(ena, pll->en_reg);
661 spin_unlock_irqrestore(&local_clock_reg_lock, flags);
662}
663
Vikram Mulukutla31680ae2011-11-04 14:23:55 -0700664struct clk *pll_vote_clk_get_parent(struct clk *clk)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700665{
666 struct pll_vote_clk *pll = to_pll_vote_clk(clk);
667 return pll->parent;
668}
669
Vikram Mulukutla31680ae2011-11-04 14:23:55 -0700670int pll_vote_clk_is_enabled(struct clk *clk)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700671{
672 struct pll_vote_clk *pll = to_pll_vote_clk(clk);
673 return !!(readl_relaxed(pll->status_reg) & BIT(16));
674}
675
676struct clk_ops clk_ops_pll_vote = {
677 .enable = pll_vote_clk_enable,
678 .disable = pll_vote_clk_disable,
Matt Wagantalle3d939d2011-11-06 11:21:37 -0800679 .auto_off = pll_vote_clk_disable,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700680 .is_enabled = pll_vote_clk_is_enabled,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700681 .get_parent = pll_vote_clk_get_parent,
682 .is_local = local_clk_is_local,
683};
684
685static int pll_clk_enable(struct clk *clk)
686{
687 u32 mode;
688 unsigned long flags;
689 struct pll_clk *pll = to_pll_clk(clk);
690
691 spin_lock_irqsave(&local_clock_reg_lock, flags);
692 mode = readl_relaxed(pll->mode_reg);
693 /* Disable PLL bypass mode. */
694 mode |= BIT(1);
695 writel_relaxed(mode, pll->mode_reg);
696
697 /*
698 * H/W requires a 5us delay between disabling the bypass and
699 * de-asserting the reset. Delay 10us just to be safe.
700 */
701 mb();
702 udelay(10);
703
704 /* De-assert active-low PLL reset. */
705 mode |= BIT(2);
706 writel_relaxed(mode, pll->mode_reg);
707
708 /* Wait until PLL is locked. */
709 mb();
710 udelay(50);
711
712 /* Enable PLL output. */
713 mode |= BIT(0);
714 writel_relaxed(mode, pll->mode_reg);
715
716 spin_unlock_irqrestore(&local_clock_reg_lock, flags);
717 return 0;
718}
719
720static void pll_clk_disable(struct clk *clk)
721{
722 u32 mode;
723 unsigned long flags;
724 struct pll_clk *pll = to_pll_clk(clk);
725
726 /*
727 * Disable the PLL output, disable test mode, enable
728 * the bypass mode, and assert the reset.
729 */
730 spin_lock_irqsave(&local_clock_reg_lock, flags);
731 mode = readl_relaxed(pll->mode_reg);
732 mode &= ~BM(3, 0);
733 writel_relaxed(mode, pll->mode_reg);
734 spin_unlock_irqrestore(&local_clock_reg_lock, flags);
735}
736
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700737static struct clk *pll_clk_get_parent(struct clk *clk)
738{
739 struct pll_clk *pll = to_pll_clk(clk);
740 return pll->parent;
741}
742
Vikram Mulukutla489e39e2011-08-31 18:04:05 -0700743int sr_pll_clk_enable(struct clk *clk)
744{
745 u32 mode;
746 unsigned long flags;
747 struct pll_clk *pll = to_pll_clk(clk);
748
749 spin_lock_irqsave(&local_clock_reg_lock, flags);
750 mode = readl_relaxed(pll->mode_reg);
751 /* De-assert active-low PLL reset. */
752 mode |= BIT(2);
753 writel_relaxed(mode, pll->mode_reg);
754
755 /*
756 * H/W requires a 5us delay between disabling the bypass and
757 * de-asserting the reset. Delay 10us just to be safe.
758 */
759 mb();
760 udelay(10);
761
762 /* Disable PLL bypass mode. */
763 mode |= BIT(1);
764 writel_relaxed(mode, pll->mode_reg);
765
766 /* Wait until PLL is locked. */
767 mb();
768 udelay(60);
769
770 /* Enable PLL output. */
771 mode |= BIT(0);
772 writel_relaxed(mode, pll->mode_reg);
773
774 spin_unlock_irqrestore(&local_clock_reg_lock, flags);
775 return 0;
776}
777
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700778struct clk_ops clk_ops_pll = {
779 .enable = pll_clk_enable,
780 .disable = pll_clk_disable,
Matt Wagantalle3d939d2011-11-06 11:21:37 -0800781 .auto_off = pll_clk_disable,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700782 .get_parent = pll_clk_get_parent,
783 .is_local = local_clk_is_local,
784};
785
786struct clk_ops clk_ops_gnd = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700787 .is_local = local_clk_is_local,
788};
789
790struct fixed_clk gnd_clk = {
791 .c = {
792 .dbg_name = "ground_clk",
793 .ops = &clk_ops_gnd,
794 CLK_INIT(gnd_clk.c),
795 },
796};
797
798struct clk_ops clk_ops_measure = {
799 .is_local = local_clk_is_local,
800};
801
802int branch_clk_enable(struct clk *clk)
803{
804 unsigned long flags;
805 struct branch_clk *branch = to_branch_clk(clk);
806
807 spin_lock_irqsave(&local_clock_reg_lock, flags);
808 __branch_clk_enable_reg(&branch->b, branch->c.dbg_name);
809 branch->enabled = true;
810 spin_unlock_irqrestore(&local_clock_reg_lock, flags);
811
812 return 0;
813}
814
815void branch_clk_disable(struct clk *clk)
816{
817 unsigned long flags;
818 struct branch_clk *branch = to_branch_clk(clk);
819
820 spin_lock_irqsave(&local_clock_reg_lock, flags);
821 __branch_clk_disable_reg(&branch->b, branch->c.dbg_name);
822 branch->enabled = false;
823 spin_unlock_irqrestore(&local_clock_reg_lock, flags);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700824}
825
826struct clk *branch_clk_get_parent(struct clk *clk)
827{
828 struct branch_clk *branch = to_branch_clk(clk);
829 return branch->parent;
830}
831
832int branch_clk_set_parent(struct clk *clk, struct clk *parent)
833{
834 /*
835 * We setup the parent pointer at init time in msm_clock_init().
836 * This check is to make sure drivers can't change the parent.
837 */
838 if (parent && list_empty(&clk->siblings)) {
839 list_add(&clk->siblings, &parent->children);
840 return 0;
841 }
842 return -EINVAL;
843}
844
845int branch_clk_is_enabled(struct clk *clk)
846{
847 struct branch_clk *branch = to_branch_clk(clk);
848 return branch->enabled;
849}
850
Stephen Boyda52d7e32011-11-10 11:59:00 -0800851static void branch_enable_hwcg(struct branch *b)
852{
853 unsigned long flags;
854 u32 reg_val;
855
856 spin_lock_irqsave(&local_clock_reg_lock, flags);
857 reg_val = readl_relaxed(b->hwcg_reg);
858 reg_val |= b->hwcg_mask;
859 writel_relaxed(reg_val, b->hwcg_reg);
860 spin_unlock_irqrestore(&local_clock_reg_lock, flags);
861}
862
863static void branch_disable_hwcg(struct branch *b)
864{
865 unsigned long flags;
866 u32 reg_val;
867
868 spin_lock_irqsave(&local_clock_reg_lock, flags);
869 reg_val = readl_relaxed(b->hwcg_reg);
870 reg_val &= ~b->hwcg_mask;
871 writel_relaxed(reg_val, b->hwcg_reg);
872 spin_unlock_irqrestore(&local_clock_reg_lock, flags);
873}
874
875void branch_clk_enable_hwcg(struct clk *clk)
876{
877 struct branch_clk *branch = to_branch_clk(clk);
878 branch_enable_hwcg(&branch->b);
879}
880
881void branch_clk_disable_hwcg(struct clk *clk)
882{
883 struct branch_clk *branch = to_branch_clk(clk);
884 branch_disable_hwcg(&branch->b);
885}
886
Matt Wagantall7e0b6c92012-01-20 18:48:05 -0800887static int branch_set_flags(struct branch *b, unsigned flags)
888{
889 unsigned long irq_flags;
890 u32 reg_val;
891 int ret = 0;
892
893 if (!b->retain_reg)
894 return -EPERM;
895
896 spin_lock_irqsave(&local_clock_reg_lock, irq_flags);
897 reg_val = readl_relaxed(b->retain_reg);
898 switch (flags) {
899 case CLKFLAG_RETAIN:
900 reg_val |= b->retain_mask;
901 break;
902 case CLKFLAG_NORETAIN:
903 reg_val &= ~b->retain_mask;
904 break;
905 default:
906 ret = -EINVAL;
907 }
908 writel_relaxed(reg_val, b->retain_reg);
909 spin_unlock_irqrestore(&local_clock_reg_lock, irq_flags);
910
911 return ret;
912}
913
914int branch_clk_set_flags(struct clk *clk, unsigned flags)
915{
916 return branch_set_flags(&to_branch_clk(clk)->b, flags);
917}
918
Stephen Boyda52d7e32011-11-10 11:59:00 -0800919int branch_clk_in_hwcg_mode(struct clk *c)
920{
921 struct branch_clk *clk = to_branch_clk(c);
922 return branch_in_hwcg_mode(&clk->b);
923}
924
925void rcg_clk_enable_hwcg(struct clk *clk)
926{
927 struct rcg_clk *rcg = to_rcg_clk(clk);
928 branch_enable_hwcg(&rcg->b);
929}
930
931void rcg_clk_disable_hwcg(struct clk *clk)
932{
933 struct rcg_clk *rcg = to_rcg_clk(clk);
934 branch_disable_hwcg(&rcg->b);
935}
936
937int rcg_clk_in_hwcg_mode(struct clk *c)
938{
939 struct rcg_clk *clk = to_rcg_clk(c);
940 return branch_in_hwcg_mode(&clk->b);
941}
942
Matt Wagantall7e0b6c92012-01-20 18:48:05 -0800943int rcg_clk_set_flags(struct clk *clk, unsigned flags)
944{
945 return branch_set_flags(&to_rcg_clk(clk)->b, flags);
946}
947
Stephen Boyda52d7e32011-11-10 11:59:00 -0800948int branch_reset(struct branch *b, enum clk_reset_action action)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700949{
950 int ret = 0;
951 u32 reg_val;
952 unsigned long flags;
953
Stephen Boyda52d7e32011-11-10 11:59:00 -0800954 if (!b->reset_reg)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700955 return -EPERM;
956
Stephen Boyda52d7e32011-11-10 11:59:00 -0800957 /* Disable hw gating when asserting a reset */
958 if (b->hwcg_mask && action == CLK_RESET_ASSERT)
959 branch_disable_hwcg(b);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700960
Stephen Boyda52d7e32011-11-10 11:59:00 -0800961 spin_lock_irqsave(&local_clock_reg_lock, flags);
962 /* Assert/Deassert reset */
963 reg_val = readl_relaxed(b->reset_reg);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700964 switch (action) {
965 case CLK_RESET_ASSERT:
Stephen Boyda52d7e32011-11-10 11:59:00 -0800966 reg_val |= b->reset_mask;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700967 break;
968 case CLK_RESET_DEASSERT:
Stephen Boyda52d7e32011-11-10 11:59:00 -0800969 reg_val &= ~b->reset_mask;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700970 break;
971 default:
972 ret = -EINVAL;
973 }
Stephen Boyda52d7e32011-11-10 11:59:00 -0800974 writel_relaxed(reg_val, b->reset_reg);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700975 spin_unlock_irqrestore(&local_clock_reg_lock, flags);
976
Stephen Boyda52d7e32011-11-10 11:59:00 -0800977 /* Enable hw gating when deasserting a reset */
978 if (b->hwcg_mask && action == CLK_RESET_DEASSERT)
979 branch_enable_hwcg(b);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700980 /* Make sure write is issued before returning. */
981 mb();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700982 return ret;
983}
984
985int branch_clk_reset(struct clk *clk, enum clk_reset_action action)
986{
987 return branch_reset(&to_branch_clk(clk)->b, action);
988}
Stephen Boydb8ad8222011-11-28 12:17:58 -0800989
Stephen Boyd7bf28142011-12-07 00:30:52 -0800990int rcg_clk_reset(struct clk *clk, enum clk_reset_action action)
991{
992 return branch_reset(&to_rcg_clk(clk)->b, action);
993}
994
Stephen Boydb8ad8222011-11-28 12:17:58 -0800995static int cdiv_clk_enable(struct clk *c)
996{
997 unsigned long flags;
998 struct cdiv_clk *clk = to_cdiv_clk(c);
999
1000 spin_lock_irqsave(&local_clock_reg_lock, flags);
1001 __branch_clk_enable_reg(&clk->b, clk->c.dbg_name);
1002 spin_unlock_irqrestore(&local_clock_reg_lock, flags);
1003
1004 return 0;
1005}
1006
1007static void cdiv_clk_disable(struct clk *c)
1008{
1009 unsigned long flags;
1010 struct cdiv_clk *clk = to_cdiv_clk(c);
1011
1012 spin_lock_irqsave(&local_clock_reg_lock, flags);
1013 __branch_clk_disable_reg(&clk->b, clk->c.dbg_name);
1014 spin_unlock_irqrestore(&local_clock_reg_lock, flags);
1015}
1016
1017static int cdiv_clk_set_rate(struct clk *c, unsigned long rate)
1018{
1019 struct cdiv_clk *clk = to_cdiv_clk(c);
1020 u32 reg_val;
1021
1022 if (rate > clk->max_div)
1023 return -EINVAL;
1024 /* Check if frequency is actually changed. */
1025 if (rate == clk->cur_div)
1026 return 0;
1027
1028 spin_lock(&local_clock_reg_lock);
1029 reg_val = readl_relaxed(clk->ns_reg);
1030 reg_val &= ~(clk->ext_mask | (clk->max_div - 1) << clk->div_offset);
1031 /* Non-zero rates mean set a divider, zero means use external input */
1032 if (rate)
1033 reg_val |= (rate - 1) << clk->div_offset;
1034 else
1035 reg_val |= clk->ext_mask;
1036 writel_relaxed(reg_val, clk->ns_reg);
1037 spin_unlock(&local_clock_reg_lock);
1038
1039 clk->cur_div = rate;
1040 return 0;
1041}
1042
1043static unsigned long cdiv_clk_get_rate(struct clk *c)
1044{
1045 struct cdiv_clk *clk = to_cdiv_clk(c);
1046 return clk->cur_div;
1047}
1048
1049static long cdiv_clk_round_rate(struct clk *c, unsigned long rate)
1050{
1051 struct cdiv_clk *clk = to_cdiv_clk(c);
1052 return rate > clk->max_div ? -EPERM : rate;
1053}
1054
1055static int cdiv_clk_list_rate(struct clk *c, unsigned n)
1056{
1057 struct cdiv_clk *clk = to_cdiv_clk(c);
1058 return n > clk->max_div ? -ENXIO : n;
1059}
1060
1061static int cdiv_clk_handoff(struct clk *c)
1062{
1063 struct cdiv_clk *clk = to_cdiv_clk(c);
1064 u32 reg_val;
1065
Stephen Boyda52d7e32011-11-10 11:59:00 -08001066 branch_handoff(&clk->b, &clk->c);
1067
Stephen Boydb8ad8222011-11-28 12:17:58 -08001068 reg_val = readl_relaxed(clk->ns_reg);
1069 if (reg_val & clk->ext_mask) {
1070 clk->cur_div = 0;
1071 } else {
1072 reg_val >>= clk->div_offset;
1073 clk->cur_div = (reg_val & (clk->max_div - 1)) + 1;
1074 }
1075
1076 return 0;
1077}
1078
Stephen Boyda52d7e32011-11-10 11:59:00 -08001079static void cdiv_clk_enable_hwcg(struct clk *c)
1080{
1081 struct cdiv_clk *clk = to_cdiv_clk(c);
1082 branch_enable_hwcg(&clk->b);
1083}
1084
1085static void cdiv_clk_disable_hwcg(struct clk *c)
1086{
1087 struct cdiv_clk *clk = to_cdiv_clk(c);
1088 branch_disable_hwcg(&clk->b);
1089}
1090
1091static int cdiv_clk_in_hwcg_mode(struct clk *c)
1092{
1093 struct cdiv_clk *clk = to_cdiv_clk(c);
1094 return branch_in_hwcg_mode(&clk->b);
1095}
1096
Stephen Boydb8ad8222011-11-28 12:17:58 -08001097struct clk_ops clk_ops_cdiv = {
1098 .enable = cdiv_clk_enable,
1099 .disable = cdiv_clk_disable,
Stephen Boyda52d7e32011-11-10 11:59:00 -08001100 .in_hwcg_mode = cdiv_clk_in_hwcg_mode,
1101 .enable_hwcg = cdiv_clk_enable_hwcg,
1102 .disable_hwcg = cdiv_clk_disable_hwcg,
Stephen Boydb8ad8222011-11-28 12:17:58 -08001103 .auto_off = cdiv_clk_disable,
1104 .handoff = cdiv_clk_handoff,
1105 .set_rate = cdiv_clk_set_rate,
1106 .get_rate = cdiv_clk_get_rate,
1107 .list_rate = cdiv_clk_list_rate,
1108 .round_rate = cdiv_clk_round_rate,
1109 .is_local = local_clk_is_local,
1110};