Linus Nielsen Feltzing | 169cd33 | 2006-03-18 21:29:17 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2006 by Linus Nielsen Feltzing |
| 11 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame^] | 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License |
| 14 | * as published by the Free Software Foundation; either version 2 |
| 15 | * of the License, or (at your option) any later version. |
Linus Nielsen Feltzing | 169cd33 | 2006-03-18 21:29:17 +0000 | [diff] [blame] | 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | ****************************************************************************/ |
| 21 | #include "config.h" |
| 22 | #include "cpu.h" |
| 23 | #include "kernel.h" |
| 24 | #include "system.h" |
| 25 | #include "power.h" |
| 26 | #include "timer.h" |
Michael Sevakis | 34751f0 | 2006-10-25 06:27:40 +0000 | [diff] [blame] | 27 | #include "pcf50606.h" |
Linus Nielsen Feltzing | 169cd33 | 2006-03-18 21:29:17 +0000 | [diff] [blame] | 28 | |
Jens Arnold | c49d5dd | 2007-04-21 09:29:01 +0000 | [diff] [blame] | 29 | /* Settings for all possible clock frequencies (with properly working timers) |
| 30 | * |
| 31 | * xxx_REFRESH_TIMER below |
| 32 | * system.h, CPUFREQ_xxx_MULT | |
| 33 | * | | |
| 34 | * V V |
| 35 | * PLLCR & Rftim. IDECONFIG1/IDECONFIG2 |
| 36 | * CPUCLK/Hz MULT ~0x70c00000 16MB CSCR0 CSCR1 CS2Pre CS2Post CS2Wait |
| 37 | * ------------------------------------------------------------------------- |
| 38 | * 11289600 1 0x00000200 4 0x0180 0x0180 1 1 0 |
| 39 | * 22579200 2 0x05028049 10 0x0180 0x0180 1 1 0 |
| 40 | * 33868800 3 0x03024049 15 0x0180 0x0180 1 1 0 |
| 41 | * 45158400 4 0x05028045 21 0x0180 0x0180 1 1 0 |
| 42 | * 56448000 5 0x02028049 26 0x0580 0x0580 2 1 0 |
| 43 | * 67737600 6 0x03024045 32 0x0580 0x0980 2 1 0 |
| 44 | * 79027200 7 0x0302a045 37 0x0580 0x0d80 2 1 0 |
| 45 | * 90316800 8 0x03030045 43 0x0980 0x0d80 2 1 0 |
| 46 | * 101606400 9 0x01024049 48 0x0980 0x1180 2 1 0 |
| 47 | * 112896000 10 0x01028049 54 0x0980 0x1580 3 1 0 |
| 48 | * 124185600 11 0x0102c049 59 0x0980 0x1180 3 1 1 |
| 49 | */ |
| 50 | |
Linus Nielsen Feltzing | 169cd33 | 2006-03-18 21:29:17 +0000 | [diff] [blame] | 51 | #define MAX_REFRESH_TIMER 59 |
| 52 | #define NORMAL_REFRESH_TIMER 21 |
| 53 | #define DEFAULT_REFRESH_TIMER 4 |
| 54 | |
Michael Sevakis | b26e396 | 2006-10-25 06:10:22 +0000 | [diff] [blame] | 55 | #define RECALC_DELAYS(f) \ |
| 56 | pcf50606_i2c_recalc_delay(f) |
| 57 | |
Steve Bavin | c90c18e | 2007-10-02 07:54:50 +0000 | [diff] [blame] | 58 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ |
Linus Nielsen Feltzing | 169cd33 | 2006-03-18 21:29:17 +0000 | [diff] [blame] | 59 | void set_cpu_frequency (long) __attribute__ ((section (".icode"))); |
| 60 | void set_cpu_frequency(long frequency) |
Steve Bavin | c90c18e | 2007-10-02 07:54:50 +0000 | [diff] [blame] | 61 | #else |
| 62 | void cf_set_cpu_frequency (long) __attribute__ ((section (".icode"))); |
| 63 | void cf_set_cpu_frequency(long frequency) |
| 64 | #endif |
Linus Nielsen Feltzing | 169cd33 | 2006-03-18 21:29:17 +0000 | [diff] [blame] | 65 | { |
| 66 | switch(frequency) |
| 67 | { |
| 68 | case CPUFREQ_MAX: |
| 69 | DCR = (0x8200 | DEFAULT_REFRESH_TIMER); |
| 70 | /* Refresh timer for bypass frequency */ |
| 71 | PLLCR &= ~1; /* Bypass mode */ |
| 72 | timers_adjust_prescale(CPUFREQ_DEFAULT_MULT, false); |
Michael Sevakis | b26e396 | 2006-10-25 06:10:22 +0000 | [diff] [blame] | 73 | RECALC_DELAYS(CPUFREQ_MAX); |
Jens Arnold | c49d5dd | 2007-04-21 09:29:01 +0000 | [diff] [blame] | 74 | PLLCR = 0x0102c049 | (PLLCR & 0x70C00000); |
Linus Nielsen Feltzing | 169cd33 | 2006-03-18 21:29:17 +0000 | [diff] [blame] | 75 | CSCR0 = 0x00001180; /* Flash: 4 wait states */ |
Jens Arnold | b85b6be | 2007-10-15 21:16:50 +0000 | [diff] [blame] | 76 | CSCR1 = 0x00001180; /* LCD: 4 wait states */ |
Linus Nielsen Feltzing | 169cd33 | 2006-03-18 21:29:17 +0000 | [diff] [blame] | 77 | while(!(PLLCR & 0x80000000)) {}; /* Wait until the PLL has locked. |
| 78 | This may take up to 10ms! */ |
| 79 | timers_adjust_prescale(CPUFREQ_MAX_MULT, true); |
| 80 | DCR = (0x8200 | MAX_REFRESH_TIMER); /* Refresh timer */ |
| 81 | cpu_frequency = CPUFREQ_MAX; |
Jens Arnold | c49d5dd | 2007-04-21 09:29:01 +0000 | [diff] [blame] | 82 | IDECONFIG1 = 0x100000 | (1 << 13) | (3 << 10); |
| 83 | /* BUFEN2 enable | CS2Post | CS2Pre */ |
Linus Nielsen Feltzing | 169cd33 | 2006-03-18 21:29:17 +0000 | [diff] [blame] | 84 | IDECONFIG2 = 0x40000 | (1 << 8); /* TA enable + CS2wait */ |
| 85 | break; |
Michael Sevakis | b26e396 | 2006-10-25 06:10:22 +0000 | [diff] [blame] | 86 | |
Linus Nielsen Feltzing | 169cd33 | 2006-03-18 21:29:17 +0000 | [diff] [blame] | 87 | case CPUFREQ_NORMAL: |
| 88 | DCR = (DCR & ~0x01ff) | DEFAULT_REFRESH_TIMER; |
| 89 | /* Refresh timer for bypass frequency */ |
| 90 | PLLCR &= ~1; /* Bypass mode */ |
| 91 | timers_adjust_prescale(CPUFREQ_DEFAULT_MULT, false); |
Michael Sevakis | b26e396 | 2006-10-25 06:10:22 +0000 | [diff] [blame] | 92 | RECALC_DELAYS(CPUFREQ_NORMAL); |
Jens Arnold | c49d5dd | 2007-04-21 09:29:01 +0000 | [diff] [blame] | 93 | PLLCR = 0x05028045 | (PLLCR & 0x70C00000); |
Linus Nielsen Feltzing | 169cd33 | 2006-03-18 21:29:17 +0000 | [diff] [blame] | 94 | CSCR0 = 0x00000580; /* Flash: 1 wait state */ |
| 95 | CSCR1 = 0x00000180; /* LCD: 0 wait states */ |
| 96 | while(!(PLLCR & 0x80000000)) {}; /* Wait until the PLL has locked. |
| 97 | This may take up to 10ms! */ |
| 98 | timers_adjust_prescale(CPUFREQ_NORMAL_MULT, true); |
| 99 | DCR = (0x8000 | NORMAL_REFRESH_TIMER); /* Refresh timer */ |
| 100 | cpu_frequency = CPUFREQ_NORMAL; |
Jens Arnold | c49d5dd | 2007-04-21 09:29:01 +0000 | [diff] [blame] | 101 | IDECONFIG1 = 0x100000 | (1 << 13) | (1 << 10); |
| 102 | /* BUFEN2 enable | CS2Post | CS2Pre */ |
Linus Nielsen Feltzing | 169cd33 | 2006-03-18 21:29:17 +0000 | [diff] [blame] | 103 | IDECONFIG2 = 0x40000 | (0 << 8); /* TA enable + CS2wait */ |
| 104 | break; |
| 105 | default: |
| 106 | DCR = (DCR & ~0x01ff) | DEFAULT_REFRESH_TIMER; |
| 107 | /* Refresh timer for bypass frequency */ |
| 108 | PLLCR &= ~1; /* Bypass mode */ |
| 109 | timers_adjust_prescale(CPUFREQ_DEFAULT_MULT, true); |
Michael Sevakis | b26e396 | 2006-10-25 06:10:22 +0000 | [diff] [blame] | 110 | RECALC_DELAYS(CPUFREQ_DEFAULT); |
Michael Sevakis | 0f5cb94 | 2006-11-06 18:07:30 +0000 | [diff] [blame] | 111 | /* Power down PLL, but keep CLSEL and CRSEL */ |
| 112 | PLLCR = 0x00000200 | (PLLCR & 0x70C00000); |
Linus Nielsen Feltzing | 169cd33 | 2006-03-18 21:29:17 +0000 | [diff] [blame] | 113 | CSCR0 = 0x00000180; /* Flash: 0 wait states */ |
| 114 | CSCR1 = 0x00000180; /* LCD: 0 wait states */ |
| 115 | DCR = (0x8000 | DEFAULT_REFRESH_TIMER); /* Refresh timer */ |
| 116 | cpu_frequency = CPUFREQ_DEFAULT; |
Jens Arnold | c49d5dd | 2007-04-21 09:29:01 +0000 | [diff] [blame] | 117 | IDECONFIG1 = 0x100000 | (1 << 13) | (1 << 10); |
| 118 | /* BUFEN2 enable | CS2Post | CS2Pre */ |
Linus Nielsen Feltzing | 169cd33 | 2006-03-18 21:29:17 +0000 | [diff] [blame] | 119 | IDECONFIG2 = 0x40000 | (0 << 8); /* TA enable + CS2wait */ |
| 120 | break; |
| 121 | } |
| 122 | } |