1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Alan Korr
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #ifndef SYSTEM_TARGET_H
22 #define SYSTEM_TARGET_H
25 asm volatile ("trapf")
27 #define or_l(mask, address) \
31 : /* %0 */ "d"(mask), \
32 /* %1 */ "a"(address))
34 #define and_l(mask, address) \
38 : /* %0 */ "d"(mask), \
39 /* %1 */ "a"(address))
41 #define eor_l(mask, address) \
45 : /* %0 */ "d"(mask), \
46 /* %1 */ "a"(address))
48 #define add_l(addend, address) \
52 : /* %0 */ "r"(addend), \
53 /* %1 */ "a"(address))
55 #define EMAC_ROUND 0x10
56 #define EMAC_FRACTIONAL 0x20
57 #define EMAC_UNSIGNED 0x40
58 #define EMAC_SATURATE 0x80
60 static inline void coldfire_set_macsr(unsigned long flags
)
62 asm volatile ("move.l %0, %%macsr" : : "i,r" (flags
));
65 static inline unsigned long coldfire_get_macsr(void)
69 asm volatile ("move.l %%macsr, %0" : "=r" (m
));
73 /* ColdFire IRQ Levels/Priorities in Rockbox summary:
74 * DMA0 - level 6, priority 0 (playback)
75 * DMA1 - level 6, priority 1 (recording)
76 * TIMER1 - level 4, priority 0 (timers)
77 * TIMER0 - level 3, priority 0 (ticks)
78 * GPI0 - level 3, priority 0 (pcf50606 PMU, secondary controller)
80 #define HIGHEST_IRQ_LEVEL (5<<8) /* Disable all but DMA and higher */
81 #define DMA_IRQ_LEVEL (6<<8) /* Disable DMA and lower */
82 #define DISABLE_INTERRUPTS (7<<8) /* Disable all but NMIs */
83 static inline int set_irq_level(int level
)
86 /* Read the old level and set the new one */
88 /* Not volatile - can be removed if oldlevel isn't used */
89 asm ("move.w %%sr, %0" : "=d"(oldlevel
));
90 /* Keep supervisor state set */
91 asm volatile ("move.w %0, %%sr \n" : : "d"(level
| 0x2000));
95 /* Enable all interrupts */
96 static inline void enable_irq(void)
99 /* Using move.w over the compiler's move.l saves 2 bytes per instance */
100 asm volatile ("move.w %1, %0 \n"
102 : "=&d"(tmp
) : "i"(0x2000));
105 /* Disable interrupts up to HIGHEST_IRQ_LEVEL */
106 static inline void disable_irq(void)
109 /* Using move.w over the compiler's move.l saves 2 bytes per instance */
110 asm volatile ("move.w %1, %0 \n"
113 : "i"(0x2000 | HIGHEST_IRQ_LEVEL
));
116 static inline int disable_irq_save(void)
119 /* Using move.w over the compiler's move.l saves 2 bytes per instance */
120 asm volatile ("move.w %%sr, %1 \n"
123 : "=&d"(tmp
), "=d"(oldlevel
)
124 : "i"(0x2000 | HIGHEST_IRQ_LEVEL
));
128 static inline void restore_irq(int oldlevel
)
130 /* Restore the sr value returned by disable_irq_save or
132 asm volatile ("move.w %0, %%sr" : : "d"(oldlevel
));
135 static inline uint16_t swap16(uint16_t value
)
137 result[15..8] = value[ 7..0];
138 result[ 7..0] = value[15..8];
141 return (value
>> 8) | (value
<< 8);
144 static inline uint32_t SWAW32(uint32_t value
)
146 result[31..16] = value[15.. 0];
147 result[15.. 0] = value[31..16];
150 asm ("swap %%0" : "+r"(value
));
154 static inline uint32_t swap32(uint32_t value
)
156 result[31..24] = value[ 7.. 0];
157 result[23..16] = value[15.. 8];
158 result[15.. 8] = value[23..16];
159 result[ 7.. 0] = value[31..24];
162 uint32_t mask
= 0x00FF00FF;
163 asm ( /* val = ABCD */
164 "and.l %[val],%[mask] \n" /* mask = .B.D */
165 "eor.l %[mask],%[val] \n" /* val = A.C. */
166 "lsl.l #8,%[mask] \n" /* mask = B.D. */
167 "lsr.l #8,%[val] \n" /* val = .A.C */
168 "or.l %[mask],%[val] \n" /* val = BADC */
169 "swap %[val] \n" /* val = DCBA */
177 static inline uint32_t swap_odd_even32(uint32_t value
)
180 result[31..24],[15.. 8] = value[23..16],[ 7.. 0]
181 result[23..16],[ 7.. 0] = value[31..24],[15.. 8]
183 uint32_t mask
= 0x00FF00FF;
184 asm ( /* val = ABCD */
185 "and.l %[val],%[mask] \n" /* mask = .B.D */
186 "eor.l %[mask],%[val] \n" /* val = A.C. */
187 "lsl.l #8,%[mask] \n" /* mask = B.D. */
188 "lsr.l #8,%[val] \n" /* val = .A.C */
189 "or.l %[mask],%[val] \n" /* val = BADC */
197 #define HAVE_CPUCACHE_INVALIDATE
199 #define DEFAULT_PLLCR_AUDIO_BITS 0x10400000
200 void coldfire_set_pllcr_audio_bits(long bits
);
202 /* Set DATAINCONTROL without disturbing FIFO reset state */
203 void coldfire_set_dataincontrol(unsigned long value
);
205 #ifndef HAVE_ADJUSTABLE_CPU_FREQ
206 extern void cf_set_cpu_frequency(long frequency
);
210 #define CPUFREQ_DEFAULT_MULT 1
211 #define CPUFREQ_DEFAULT (CPUFREQ_DEFAULT_MULT * CPU_FREQ)
213 #define CPUFREQ_NORMAL_MULT 4
214 #define CPUFREQ_NORMAL (CPUFREQ_NORMAL_MULT * CPU_FREQ)
216 #define CPUFREQ_MAX_MULT 11
217 #define CPUFREQ_MAX (CPUFREQ_MAX_MULT * CPU_FREQ)
219 #endif /* SYSTEM_TARGET_H */