1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2010 by Michael Sevakis
12 * i.MX31 DVFS and DPTC drivers
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
22 ****************************************************************************/
27 #include "iomuxc-imx31.h"
28 #include "ccm-imx31.h"
29 #include "avic-imx31.h"
30 #include "dvfs_dptc-imx31.h"
31 #include "dvfs_dptc_tables-target.h"
33 /* Most of the code in here is based upon the Linux BSP provided by Freescale
34 * Copyright 2004-2008 Freescale Semiconductor, Inc. All Rights Reserved. */
36 /* The current DVFS index level */
37 static volatile unsigned int dvfs_level
= DVFS_LEVEL_DEFAULT
;
38 /* The current DPTC working point */
39 static volatile unsigned int dptc_wp
= DPTC_WP_DEFAULT
;
42 static void update_dptc_counts(unsigned int level
, unsigned int wp
)
44 int oldlevel
= disable_irq_save();
45 const struct dptc_dcvr_table_entry
*entry
= &dptc_dcvr_table
[level
][wp
];
47 CCM_DCVR0
= entry
->dcvr0
;
48 CCM_DCVR1
= entry
->dcvr1
;
49 CCM_DCVR2
= entry
->dcvr2
;
50 CCM_DCVR3
= entry
->dcvr3
;
52 restore_irq(oldlevel
);
56 static uint32_t check_regulator_setting(uint32_t setting
)
58 /* Simply a safety check *in case* table gets scrambled */
59 if (setting
< VOLTAGE_SETTING_MIN
)
60 setting
= VOLTAGE_SETTING_MIN
;
61 else if (setting
> VOLTAGE_SETTING_MAX
)
62 setting
= VOLTAGE_SETTING_MAX
;
69 static bool dvfs_running
= false; /* Has driver enabled DVFS? */
71 /* Request tracking since boot */
72 unsigned int dvfs_nr_dn
= 0;
73 unsigned int dvfs_nr_up
= 0;
74 unsigned int dvfs_nr_pnc
= 0;
75 unsigned int dvfs_nr_no
= 0;
78 /* Wait for the UPDTEN flag to be set so that all bits may be written */
79 static inline void wait_for_dvfs_update_en(void)
81 while (!(CCM_PMCR0
& CCM_PMCR0_UPDTEN
));
85 static void do_dvfs_update(unsigned int level
, bool in_isr
)
87 const struct dvfs_clock_table_entry
*setting
= &dvfs_clock_table
[level
];
88 unsigned long pmcr0
= CCM_PMCR0
;
90 if (pmcr0
& CCM_PMCR0_DPTEN
)
92 /* Ignore voltage change request from DPTC. Voltage is *not* valid. */
93 pmcr0
&= ~CCM_PMCR0_DPVCR
;
96 pmcr0
&= ~CCM_PMCR0_VSCNT
;
98 if (level
< ((pmcr0
& CCM_PMCR0_DVSUP
) >> CCM_PMCR0_DVSUP_POS
))
100 pmcr0
|= CCM_PMCR0_UDSC
; /* Up scaling, increase */
101 pmcr0
|= setting
->vscnt
<< CCM_PMCR0_VSCNT_POS
;
105 pmcr0
&= ~CCM_PMCR0_UDSC
; /* Down scaling, decrease */
106 pmcr0
|= 0x1 << CCM_PMCR0_VSCNT_POS
;
109 /* DVSUP (new frequency index) setup */
110 pmcr0
= (pmcr0
& ~CCM_PMCR0_DVSUP
) | (level
<< CCM_PMCR0_DVSUP_POS
);
114 if ((setting
->pll_num
<< CCM_PMCR0_DFSUP_MCUPLL_POS
) ^
115 (pmcr0
& CCM_PMCR0_DFSUP_MCUPLL
))
117 /* Update pll and post-dividers. */
118 pmcr0
^= CCM_PMCR0_DFSUP_MCUPLL
;
119 pmcr0
&= ~CCM_PMCR0_DFSUP_POST_DIVIDERS
;
123 /* Post-dividers update only */
124 pmcr0
|= CCM_PMCR0_DFSUP_POST_DIVIDERS
;
128 /* Note: changes to frequency with ints unmaked seem to cause spurious
129 * DVFS interrupts with value CCM_PMCR0_FSVAI_NO_INT. These aren't
130 * supposed to happen. Only do the lengthy delay with them enabled iff
131 * called from the IRQ handler. */
134 udelay(100); /* Software wait for voltage ramp-up */
137 CCM_PDR0
= setting
->pdr_val
;
139 if (!(pmcr0
& CCM_PMCR0_DFSUP_POST_DIVIDERS
))
141 /* Update the PLL settings */
142 if (pmcr0
& CCM_PMCR0_DFSUP_MCUPLL
)
143 CCM_MPCTL
= setting
->pll_val
;
145 CCM_SPCTL
= setting
->pll_val
;
148 cpu_frequency
= ccm_get_mcu_clk();
150 if (pmcr0
& CCM_PMCR0_DPTEN
)
152 update_dptc_counts(level
, dptc_wp
);
153 /* Enable DPTC to request voltage changes. Voltage is valid. */
154 CCM_PMCR0
|= CCM_PMCR0_DPVCR
;
156 CCM_PMCR0
|= CCM_PMCR0_DPVV
;
161 /* Start DVFS, change the set point and stop it */
162 static void set_current_dvfs_level(unsigned int level
)
164 int oldlevel
= disable_irq_save();
166 CCM_PMCR0
|= CCM_PMCR0_DVFEN
;
168 wait_for_dvfs_update_en();
170 do_dvfs_update(level
, false);
172 wait_for_dvfs_update_en();
174 CCM_PMCR0
&= ~CCM_PMCR0_DVFEN
;
176 restore_irq(oldlevel
);
180 /* DVFS Interrupt handler */
181 static void __attribute__((used
)) dvfs_int(void)
183 unsigned long pmcr0
= CCM_PMCR0
;
184 unsigned long fsvai
= pmcr0
& CCM_PMCR0_FSVAI
;
185 unsigned int level
= (pmcr0
& CCM_PMCR0_DVSUP
) >> CCM_PMCR0_DVSUP_POS
;
187 if (pmcr0
& CCM_PMCR0_FSVAIM
)
188 return; /* Do nothing. DVFS interrupt is masked. */
190 if (!(pmcr0
& CCM_PMCR0_UPDTEN
))
191 return; /* Do nothing. DVFS didn't finish previous flow update. */
195 case CCM_PMCR0_FSVAI_DECREASE
:
196 if (level
>= DVFS_NUM_LEVELS
- 1)
197 return; /* DVFS already at lowest level */
199 /* Upon the DECREASE event, the frequency will be changed to the next
200 * higher state index. */
201 while (((1u << ++level
) & DVFS_LEVEL_MASK
) == 0);
206 /* Single-step frequency increase */
207 case CCM_PMCR0_FSVAI_INCREASE
:
209 return; /* DVFS already at highest level */
211 /* Upon the INCREASE event, the frequency will be changed to the next
212 * lower state index. */
213 while (((1u << --level
) & DVFS_LEVEL_MASK
) == 0);
218 /* Right to highest if panic */
219 case CCM_PMCR0_FSVAI_INCREASE_NOW
:
221 return; /* DVFS already at highest level */
223 /* Upon the INCREASE_NOW event, the frequency will be increased to
224 * the maximum (index 0). */
229 case CCM_PMCR0_FSVAI_NO_INT
:
231 return; /* Do nothing. Freq change is not required */
234 do_dvfs_update(level
, true);
238 /* Interrupt vector for DVFS */
239 static __attribute__((naked
, interrupt("IRQ"))) void CCM_DVFS_HANDLER(void)
241 /* Audio can glitch with the long udelay if nested IRQ isn't allowed. */
242 AVIC_NESTED_NI_CALL_PROLOGUE(INT_PRIO_DVFS
, 32*4);
243 asm volatile ("bl dvfs_int");
244 AVIC_NESTED_NI_CALL_EPILOGUE(32*4);
248 /* Initialize the DVFS hardware */
249 static void INIT_ATTR
dvfs_init(void)
251 if (CCM_PMCR0
& CCM_PMCR0_DVFEN
)
253 /* Turn it off first. Really, shouldn't happen though. */
258 /* Combine SW1A and SW1B DVS pins for a possible five DVS levels
259 * per working point. Four, MAXIMUM, are actually used, one for each
261 mc13783_set(MC13783_ARBITRATION_SWITCHERS
, MC13783_SW1ABDVS
);
263 /* Set DVS speed to 25mV every 4us. */
264 mc13783_write_masked(MC13783_SWITCHERS4
, MC13783_SW1ADVSSPEED_4US
,
265 MC13783_SW1ADVSSPEED
);
267 /* Set DVFS pins to functional outputs. Input mode and pad setting is
268 * fixed in hardware. */
269 iomuxc_set_pin_mux(IOMUXC_DVFS0
,
270 IOMUXC_MUX_OUT_FUNCTIONAL
| IOMUXC_MUX_IN_NONE
);
271 iomuxc_set_pin_mux(IOMUXC_DVFS1
,
272 IOMUXC_MUX_OUT_FUNCTIONAL
| IOMUXC_MUX_IN_NONE
);
274 #ifndef DVFS_NO_PWRRDY
275 /* Configure PWRRDY signal pin. */
276 bitclr32(&GPIO1_GDIR
, (1 << 5));
277 iomuxc_set_pin_mux(IOMUXC_GPIO1_5
,
278 IOMUXC_MUX_OUT_FUNCTIONAL
| IOMUXC_MUX_IN_FUNCTIONAL
);
281 /* GP load bits disabled */
282 bitclr32(&CCM_PMCR1
, 0xf);
284 /* Initialize DVFS signal weights and detection modes. */
286 for (i
= 0; i
< 16; i
++)
288 dvfs_set_lt_weight(i
, lt_signals
[i
].weight
);
289 dvfs_set_lt_detect(i
, lt_signals
[i
].detect
);
294 DVFS_UPTHR
<< CCM_LTR0_UPTHR_POS
|
295 DVFS_DNTHR
<< CCM_LTR0_DNTHR_POS
|
296 DVFS_DIV3CK
<< CCM_LTR0_DIV3CK_POS
,
297 CCM_LTR0_UPTHR
| CCM_LTR0_DNTHR
| CCM_LTR0_DIV3CK
);
301 DVFS_DNCNT
<< CCM_LTR1_DNCNT_POS
|
302 DVFS_UPCNT
<< CCM_LTR1_UPCNT_POS
|
303 DVFS_PNCTHR
<< CCM_LTR1_PNCTHR_POS
|
305 CCM_LTR1_DNCNT
| CCM_LTR1_UPCNT
|
306 CCM_LTR1_PNCTHR
| CCM_LTR1_LTBRSR
);
308 /* Set up LTR2-- EMA configuration. */
309 bitmod32(&CCM_LTR2
, DVFS_EMAC
<< CCM_LTR2_EMAC_POS
, CCM_LTR2_EMAC
);
311 /* DVFS interrupt goes to MCU. Mask load buffer full interrupt. */
312 bitset32(&CCM_PMCR0
, CCM_PMCR0_DVFIS
| CCM_PMCR0_LBMI
);
314 /* Initialize current core PLL and dividers for default level. Assumes
315 * clocking scheme has been set up appropriately in other init code. */
316 ccm_set_mcupll_and_pdr(dvfs_clock_table
[DVFS_LEVEL_DEFAULT
].pll_val
,
317 dvfs_clock_table
[DVFS_LEVEL_DEFAULT
].pdr_val
);
319 /* Set initial level and working point. */
320 set_current_dvfs_level(DVFS_LEVEL_DEFAULT
);
322 logf("DVFS: Initialized");
327 /* Request tracking since boot */
328 static bool dptc_running
= false; /* Has driver enabled DPTC? */
330 unsigned int dptc_nr_dn
= 0;
331 unsigned int dptc_nr_up
= 0;
332 unsigned int dptc_nr_pnc
= 0;
333 unsigned int dptc_nr_no
= 0;
335 static struct spi_transfer_desc dptc_pmic_xfer
; /* Transfer descriptor */
336 static const unsigned char dptc_pmic_regs
[2] = /* Register subaddresses */
337 { MC13783_SWITCHERS0
, MC13783_SWITCHERS1
};
338 static uint32_t dptc_reg_shadows
[2]; /* shadow regs */
339 static uint32_t dptc_regs_buf
[2]; /* buffer for async write */
342 /* Enable DPTC and unmask interrupt. */
343 static void enable_dptc(void)
345 int oldlevel
= disable_irq_save();
347 /* Enable DPTC, assert voltage change request. */
348 CCM_PMCR0
= (CCM_PMCR0
& ~CCM_PMCR0_PTVAIM
) | CCM_PMCR0_DPTEN
|
353 /* Set voltage valid *after* setting change request */
354 CCM_PMCR0
|= CCM_PMCR0_DPVV
;
356 restore_irq(oldlevel
);
360 /* Called after asynchronous PMIC write is completed */
361 static void dptc_transfer_done_callback(struct spi_transfer_desc
*xfer
)
363 if (xfer
->count
!= 0)
366 update_dptc_counts(dvfs_level
, dptc_wp
);
373 /* Handle the DPTC interrupt and sometimes the manual setting */
374 static void dptc_int(unsigned long pmcr0
)
376 const union dvfs_dptc_voltage_table_entry
*entry
;
377 uint32_t sw1a
, sw1advs
, sw1bdvs
, sw1bstby
;
378 uint32_t switchers0
, switchers1
;
382 /* Mask DPTC interrupt and disable DPTC until the change request is
384 CCM_PMCR0
= (pmcr0
& ~CCM_PMCR0_DPTEN
) | CCM_PMCR0_PTVAIM
;
386 switch (pmcr0
& CCM_PMCR0_PTVAI
)
388 case CCM_PMCR0_PTVAI_DECREASE
:
393 case CCM_PMCR0_PTVAI_INCREASE
:
398 case CCM_PMCR0_PTVAI_INCREASE_NOW
:
399 if (--wp
> DPTC_WP_PANIC
)
404 case CCM_PMCR0_PTVAI_NO_INT
:
405 break; /* Just maintain at global level */
410 else if (wp
>= DPTC_NUM_WP
)
411 wp
= DPTC_NUM_WP
- 1;
413 entry
= &dvfs_dptc_voltage_table
[wp
];
415 sw1a
= check_regulator_setting(entry
->sw1a
);
416 sw1advs
= check_regulator_setting(entry
->sw1advs
);
417 sw1bdvs
= check_regulator_setting(entry
->sw1bdvs
);
418 sw1bstby
= check_regulator_setting(entry
->sw1bstby
);
420 switchers0
= dptc_reg_shadows
[0] & ~(MC13783_SW1A
| MC13783_SW1ADVS
);
421 dptc_regs_buf
[0] = switchers0
|
422 sw1a
<< MC13783_SW1A_POS
| /* SW1A */
423 sw1advs
<< MC13783_SW1ADVS_POS
; /* SW1ADVS */
424 switchers1
= dptc_reg_shadows
[1] & ~(MC13783_SW1BDVS
| MC13783_SW1BSTBY
);
425 dptc_regs_buf
[1] = switchers1
|
426 sw1bdvs
<< MC13783_SW1BDVS_POS
| /* SW1BDVS */
427 sw1bstby
<< MC13783_SW1BSTBY_POS
; /* SW1BSTBY */
431 mc13783_write_async(&dptc_pmic_xfer
, dptc_pmic_regs
,
432 dptc_regs_buf
, 2, dptc_transfer_done_callback
);
436 static void dptc_new_wp(unsigned int wp
)
439 /* "NO_INT" so the working point isn't incremented, just set. */
440 dptc_int((CCM_PMCR0
& ~CCM_PMCR0_PTVAI
) | CCM_PMCR0_PTVAI_NO_INT
);
444 /* Interrupt vector for DPTC */
445 static __attribute__((interrupt("IRQ"))) void CCM_CLK_HANDLER(void)
447 unsigned long pmcr0
= CCM_PMCR0
;
449 if ((pmcr0
& CCM_PMCR0_PTVAI
) == CCM_PMCR0_PTVAI_NO_INT
)
456 /* Initialize the DPTC hardware */
457 static void INIT_ATTR
dptc_init(void)
459 /* Force DPTC off if running for some reason. */
460 bitmod32(&CCM_PMCR0
, CCM_PMCR0_PTVAIM
,
461 CCM_PMCR0_PTVAIM
| CCM_PMCR0_DPTEN
);
463 /* Shadow the regulator registers */
464 mc13783_read_regs(dptc_pmic_regs
, dptc_reg_shadows
, 2);
466 /* Set default, safe working point. */
467 dptc_new_wp(DPTC_WP_DEFAULT
);
469 /* Interrupt goes to MCU, specified reference circuits enabled when
471 bitset32(&CCM_PMCR0
, CCM_PMCR0_PTVIS
);
473 bitmod32(&CCM_PMCR0
, DPTC_DRCE_MASK
,
474 CCM_PMCR0_DRCE0
| CCM_PMCR0_DRCE1
|
475 CCM_PMCR0_DRCE2
| CCM_PMCR0_DRCE3
);
477 /* DPTC counting range = 256 system clocks */
478 bitclr32(&CCM_PMCR0
, CCM_PMCR0_DCR
);
480 logf("DPTC: Initialized");
484 /** Main module interface **/
486 /* Initialize DVFS and DPTC */
487 void INIT_ATTR
dvfs_dptc_init(void)
494 /* Start DVFS and DPTC */
495 void dvfs_dptc_start(void)
502 /* Stop DVFS and DPTC */
503 void dvfs_dptc_stop(void)
509 /* Start the DVFS hardware */
510 void dvfs_start(void)
514 /* Have to wait at least 3 div3 clocks before enabling after being
518 oldlevel
= disable_irq_save();
524 /* Unmask DVFS interrupt source and enable DVFS. */
525 avic_enable_int(INT_CCM_DVFS
, INT_TYPE_IRQ
, INT_PRIO_DVFS
,
528 CCM_PMCR0
= (CCM_PMCR0
& ~CCM_PMCR0_FSVAIM
) | CCM_PMCR0_DVFEN
;
531 restore_irq(oldlevel
);
533 logf("DVFS: started");
537 /* Stop the DVFS hardware and return to default frequency */
540 int oldlevel
= disable_irq_save();
544 /* Mask DVFS interrupts. */
545 CCM_PMCR0
|= CCM_PMCR0_FSVAIM
| CCM_PMCR0_LBMI
;
546 avic_disable_int(INT_CCM_DVFS
);
548 if (((CCM_PMCR0
& CCM_PMCR0_DVSUP
) >> CCM_PMCR0_DVSUP_POS
) !=
551 /* Set default frequency level */
552 wait_for_dvfs_update_en();
553 do_dvfs_update(DVFS_LEVEL_DEFAULT
, false);
554 wait_for_dvfs_update_en();
558 CCM_PMCR0
&= ~CCM_PMCR0_DVFEN
;
559 dvfs_running
= false;
562 restore_irq(oldlevel
);
564 logf("DVFS: stopped");
568 /* Mask the DVFS interrupt without affecting running status */
569 void dvfs_int_mask(bool mask
)
573 /* Just disable, not running = already disabled */
574 avic_mask_int(INT_CCM_DVFS
);
576 else if (dvfs_running
)
578 /* DVFS is running; unmask it */
579 avic_unmask_int(INT_CCM_DVFS
);
584 /* Set a signal load tracking weight */
585 void dvfs_set_lt_weight(enum DVFS_LT_SIGS index
, unsigned long value
)
587 volatile unsigned long *reg_p
= &CCM_LTR2
;
588 unsigned int shift
= 3 * index
;
593 shift
+= 5; /* Bits 7:5, 10:8 ... 31:29 */
597 shift
-= 16; /* Bits 13:11, 16:14 ... 31:29 */
600 bitmod32(reg_p
, value
<< shift
, 0x7 << shift
);
604 /* Return a signal load tracking weight */
605 unsigned long dvfs_get_lt_weight(enum DVFS_LT_SIGS index
)
607 volatile unsigned long *reg_p
= &CCM_LTR2
;
608 unsigned int shift
= 3 * index
;
613 shift
+= 5; /* Bits 7:5, 10:8 ... 31:29 */
617 shift
-= 16; /* Bits 13:11, 16:14 ... 31:29 */
620 return (*reg_p
& (0x7 << shift
)) >> shift
;
624 /* Set a signal load detection mode */
625 void dvfs_set_lt_detect(enum DVFS_LT_SIGS index
, bool edge
)
627 unsigned long bit
= 0;
629 if ((unsigned)index
< 13)
630 bit
= 1ul << (index
+ 3);
631 else if ((unsigned)index
< 16)
632 bit
= 1ul << (index
+ 29);
634 bitmod32(&CCM_LTR0
, edge
? bit
: 0, bit
);
638 /* Returns a signal load detection mode */
639 bool dvfs_get_lt_detect(enum DVFS_LT_SIGS index
)
641 unsigned int shift
= 32;
643 if ((unsigned)index
< 13)
645 else if ((unsigned)index
< 16)
648 return !!((CCM_LTR0
& (1ul << shift
)) >> shift
);
652 /* Set/clear the general-purpose load tracking bit */
653 void dvfs_set_gp_bit(enum DVFS_DVGPS dvgp
, bool assert)
655 if ((unsigned)dvgp
<= 3)
657 unsigned long bit
= 1ul << dvgp
;
658 bitmod32(&CCM_PMCR1
, assert ? bit
: 0, bit
);
663 /* Return the general-purpose load tracking bit */
664 bool dvfs_get_gp_bit(enum DVFS_DVGPS dvgp
)
666 if ((unsigned)dvgp
<= 3)
667 return (CCM_PMCR1
& (1ul << dvgp
)) != 0;
672 /* Set GP load tracking by code.
677 * gte 28=highest load
679 * b[3:0]: 1=LTn edge detect, 0=LTn level detect
681 void dvfs_set_gp_sense(int level_code
, unsigned long detect_mask
)
685 for (i
= 0; i
<= 3; i
++)
687 int ltsig_num
= DVFS_LT_SIG_DVGP0
+ i
;
688 int gpw_num
= DVFS_DVGP_0
+ i
;
689 unsigned long weight
;
698 weight
= lt_signals
[ltsig_num
].weight
;
699 edge
= lt_signals
[ltsig_num
].detect
!= 0;
703 weight
= MIN(level_code
, 7);
704 edge
= !!(detect_mask
& 1);
712 dvfs_set_lt_weight(ltsig_num
, weight
); /* set weight */
713 dvfs_set_lt_detect(ltsig_num
, edge
); /* set detect mode */
714 dvfs_set_gp_bit(gpw_num
, assert); /* set activity */
718 /* Return GP weight settings */
719 void dvfs_get_gp_sense(int *level_code
, unsigned long *detect_mask
)
723 unsigned long mask
= 0;
725 for (i
= DVFS_LT_SIG_DVGP0
; i
<= DVFS_LT_SIG_DVGP3
; i
++)
727 code
+= dvfs_get_lt_weight(i
);
728 mask
= (mask
<< 1) | (dvfs_get_lt_detect(i
) ? 1 : 0);
739 /* Turn the wait-for-interrupt monitoring on or off */
740 void dvfs_wfi_monitor(bool on
)
742 bitmod32(&CCM_PMCR0
, on
? 0 : CCM_PMCR0_WFIM
, CCM_PMCR0_WFIM
);
746 /* Obtain the current core voltage setting, in millivolts 8-) */
747 unsigned int dvfs_dptc_get_voltage(void)
751 int oldlevel
= disable_irq_save();
752 v
= dvfs_dptc_voltage_table
[dptc_wp
].sw
[dvfs_level
];
753 restore_irq(oldlevel
);
755 /* 25mV steps from 0.900V to 1.675V */
760 /* Get the current DVFS level */
761 unsigned int dvfs_get_level(void)
767 /* Is DVFS enabled? */
768 bool dvfs_enabled(void)
774 /* Get bitmask of levels supported */
775 unsigned int dvfs_level_mask(void)
777 return DVFS_LEVEL_MASK
;
781 /* If DVFS is disabled, set the level explicitly */
782 void dvfs_set_level(unsigned int level
)
784 int oldlevel
= disable_irq_save();
786 if (!dvfs_running
&& level
< DVFS_NUM_LEVELS
)
788 unsigned int currlevel
=
789 (CCM_PMCR0
& CCM_PMCR0_DVSUP
) >> CCM_PMCR0_DVSUP_POS
;
790 if (level
!= currlevel
&& ((1 << level
) & DVFS_LEVEL_MASK
))
791 set_current_dvfs_level(level
);
794 restore_irq(oldlevel
);
798 /* Start DPTC module */
799 void dptc_start(void)
801 int oldlevel
= disable_irq_save();
807 /* Enable DPTC and unmask interrupt. */
808 avic_enable_int(INT_CCM_CLK
, INT_TYPE_IRQ
, INT_PRIO_DPTC
,
811 update_dptc_counts(dvfs_level
, dptc_wp
);
815 restore_irq(oldlevel
);
817 logf("DPTC: started");
821 /* Stop the DPTC hardware if running and go back to default working point */
824 int oldlevel
= disable_irq_save();
828 dptc_running
= false;
830 /* Disable DPTC and mask interrupt. */
831 CCM_PMCR0
= (CCM_PMCR0
& ~CCM_PMCR0_DPTEN
) | CCM_PMCR0_PTVAIM
;
832 avic_disable_int(INT_CCM_CLK
);
834 /* Go back to default working point. */
835 dptc_new_wp(DPTC_WP_DEFAULT
);
838 restore_irq(oldlevel
);
840 logf("DPTC: stopped");
844 /* Get the current DPTC working point */
845 unsigned int dptc_get_wp(void)
851 /* Is DPTC enabled? */
852 bool dptc_enabled(void)
858 /* If DPTC is not running, set the working point explicitly */
859 void dptc_set_wp(unsigned int wp
)
861 int oldlevel
= disable_irq_save();
863 if (!dptc_running
&& wp
< DPTC_NUM_WP
)
866 restore_irq(oldlevel
);