2006-03-18 21:29:17 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 by Linus Nielsen Feltzing
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "config.h"
|
|
|
|
#include "cpu.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "power.h"
|
|
|
|
#include "timer.h"
|
2006-10-25 06:27:40 +00:00
|
|
|
#include "pcf50606.h"
|
2006-03-18 21:29:17 +00:00
|
|
|
|
|
|
|
#define MAX_REFRESH_TIMER 59
|
|
|
|
#define NORMAL_REFRESH_TIMER 21
|
|
|
|
#define DEFAULT_REFRESH_TIMER 4
|
|
|
|
|
2006-10-25 06:10:22 +00:00
|
|
|
#define RECALC_DELAYS(f) \
|
|
|
|
pcf50606_i2c_recalc_delay(f)
|
|
|
|
|
2006-03-18 21:29:17 +00:00
|
|
|
void set_cpu_frequency (long) __attribute__ ((section (".icode")));
|
|
|
|
void set_cpu_frequency(long frequency)
|
|
|
|
{
|
|
|
|
switch(frequency)
|
|
|
|
{
|
|
|
|
case CPUFREQ_MAX:
|
|
|
|
DCR = (0x8200 | DEFAULT_REFRESH_TIMER);
|
|
|
|
/* Refresh timer for bypass frequency */
|
|
|
|
PLLCR &= ~1; /* Bypass mode */
|
|
|
|
timers_adjust_prescale(CPUFREQ_DEFAULT_MULT, false);
|
2006-10-25 06:10:22 +00:00
|
|
|
RECALC_DELAYS(CPUFREQ_MAX);
|
2006-11-06 18:07:30 +00:00
|
|
|
PLLCR = 0x03042045 | (PLLCR & 0x70C00000);
|
2006-03-18 21:29:17 +00:00
|
|
|
CSCR0 = 0x00001180; /* Flash: 4 wait states */
|
|
|
|
CSCR1 = 0x00000980; /* LCD: 2 wait states */
|
|
|
|
while(!(PLLCR & 0x80000000)) {}; /* Wait until the PLL has locked.
|
|
|
|
This may take up to 10ms! */
|
|
|
|
timers_adjust_prescale(CPUFREQ_MAX_MULT, true);
|
|
|
|
DCR = (0x8200 | MAX_REFRESH_TIMER); /* Refresh timer */
|
|
|
|
cpu_frequency = CPUFREQ_MAX;
|
|
|
|
IDECONFIG1 = 0x106000 | (5 << 10); /* BUFEN2 enable + CS2Pre/CS2Post */
|
|
|
|
IDECONFIG2 = 0x40000 | (1 << 8); /* TA enable + CS2wait */
|
|
|
|
break;
|
2006-10-25 06:10:22 +00:00
|
|
|
|
2006-03-18 21:29:17 +00:00
|
|
|
case CPUFREQ_NORMAL:
|
|
|
|
DCR = (DCR & ~0x01ff) | DEFAULT_REFRESH_TIMER;
|
|
|
|
/* Refresh timer for bypass frequency */
|
|
|
|
PLLCR &= ~1; /* Bypass mode */
|
|
|
|
timers_adjust_prescale(CPUFREQ_DEFAULT_MULT, false);
|
2006-10-25 06:10:22 +00:00
|
|
|
RECALC_DELAYS(CPUFREQ_NORMAL);
|
2006-11-06 18:07:30 +00:00
|
|
|
PLLCR = 0x06030045 | (PLLCR & 0x70C00000);
|
2006-03-18 21:29:17 +00:00
|
|
|
CSCR0 = 0x00000580; /* Flash: 1 wait state */
|
|
|
|
CSCR1 = 0x00000180; /* LCD: 0 wait states */
|
|
|
|
while(!(PLLCR & 0x80000000)) {}; /* Wait until the PLL has locked.
|
|
|
|
This may take up to 10ms! */
|
|
|
|
timers_adjust_prescale(CPUFREQ_NORMAL_MULT, true);
|
|
|
|
DCR = (0x8000 | NORMAL_REFRESH_TIMER); /* Refresh timer */
|
|
|
|
cpu_frequency = CPUFREQ_NORMAL;
|
|
|
|
IDECONFIG1 = 0x106000 | (5 << 10); /* BUFEN2 enable + CS2Pre/CS2Post */
|
|
|
|
IDECONFIG2 = 0x40000 | (0 << 8); /* TA enable + CS2wait */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
DCR = (DCR & ~0x01ff) | DEFAULT_REFRESH_TIMER;
|
|
|
|
/* Refresh timer for bypass frequency */
|
|
|
|
PLLCR &= ~1; /* Bypass mode */
|
|
|
|
timers_adjust_prescale(CPUFREQ_DEFAULT_MULT, true);
|
2006-10-25 06:10:22 +00:00
|
|
|
RECALC_DELAYS(CPUFREQ_DEFAULT);
|
2006-11-06 18:07:30 +00:00
|
|
|
/* Power down PLL, but keep CLSEL and CRSEL */
|
|
|
|
PLLCR = 0x00000200 | (PLLCR & 0x70C00000);
|
2006-03-18 21:29:17 +00:00
|
|
|
CSCR0 = 0x00000180; /* Flash: 0 wait states */
|
|
|
|
CSCR1 = 0x00000180; /* LCD: 0 wait states */
|
|
|
|
DCR = (0x8000 | DEFAULT_REFRESH_TIMER); /* Refresh timer */
|
|
|
|
cpu_frequency = CPUFREQ_DEFAULT;
|
|
|
|
IDECONFIG1 = 0x106000 | (1 << 10); /* BUFEN2 enable + CS2Pre/CS2Post */
|
|
|
|
IDECONFIG2 = 0x40000 | (0 << 8); /* TA enable + CS2wait */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|