summaryrefslogtreecommitdiff
path: root/firmware/target/arm/imx233/emi-imx233.h
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2013-01-10 00:43:08 +0000
committerAmaury Pouly <amaury.pouly@gmail.com>2013-01-10 00:51:35 +0000
commit5aa19f3eeb4e401b2d1ac57131a87b87b6ce55d5 (patch)
treeae54a62a5a4420dff8ec5198f6f5c9418c34151f /firmware/target/arm/imx233/emi-imx233.h
parentb9923df170104320e55bff05ecc2a0105067f9cb (diff)
downloadrockbox-5aa19f3eeb4e401b2d1ac57131a87b87b6ce55d5.tar.gz
rockbox-5aa19f3eeb4e401b2d1ac57131a87b87b6ce55d5.zip
imx233: implement emi frequency scaling (disabled by default)
CPU frequency scaling is basically useless without scaling the memory frequency. On the i.MX233, the EMI (external memory interface) and DRAM blocks are responsable for the DDR settings. This commits implements emi frequency scaling. Only some settings are implemented and the timings values only apply to mDDR (extracted from Sigmatel linux port) and have been checked to work on the Fuze+ and Zen X-Fi2/3. This feature is still disabled by default but I expected some battery life savings by boosting higher to 454MHz and unboosting lower to 64MHz. Note that changing the emi frequency is particularly tricky and to avoid writing it entirely in assembly we rely on the compiler to not use the stack except in the prolog and epilog (because it's in dram which is disabled when doing the change) and to put constant pools in iram which should always be true if the compiler isn't completely dumb and since the code itself is put in iram. If this proves to be insufficient, one can always switch the stack to the irq stack since interrupts are disabled during the change. Change-Id: If6ef5357f7ff091130ca1063e48536c6028f23ba
Diffstat (limited to 'firmware/target/arm/imx233/emi-imx233.h')
-rw-r--r--firmware/target/arm/imx233/emi-imx233.h260
1 files changed, 260 insertions, 0 deletions
diff --git a/firmware/target/arm/imx233/emi-imx233.h b/firmware/target/arm/imx233/emi-imx233.h
new file mode 100644
index 0000000000..8106d27dfe
--- /dev/null
+++ b/firmware/target/arm/imx233/emi-imx233.h
@@ -0,0 +1,260 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2013 by Amaury Pouly
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#ifndef __EMI_IMX233_H__
22#define __EMI_IMX233_H__
23
24#include "cpu.h"
25#include "system.h"
26#include "system-target.h"
27
28#define HW_EMI_BASE 0x80020000
29
30#define HW_EMI_CTRL (*(volatile uint32_t *)(HW_EMI_BASE + 0x0))
31#define HW_EMI_CTRL__DLL_SHIFT_RESET (1 << 25)
32#define HW_EMI_CTRL__DLL_RESET (1 << 24)
33
34/* this register is undocumented but exists, I put the whole doc here */
35#define HW_EMI_STAT (*(volatile uint32_t *)(HW_EMI_BASE + 0x10))
36#define HW_EMI_STAT__DRAM_PRESENT (1 << 31)
37#define HW_EMI_STAT__NOR_PRESENT (1 << 30)
38#define HW_EMI_STAT__LARGE_DRAM_ENABLED (1 << 29)
39#define HW_EMI_STAT__DRAM_HALTED (1 << 1)
40#define HW_EMI_STAT__NOR_BUSY (1 << 0)
41
42/* another undocumented registers (there are some more) */
43#define HW_EMI_TIME (*(volatile uint32_t *)(HW_EMI_BASE + 0x20))
44#define HW_EMI_TIME__THZ_BP 24
45#define HW_EMI_TIME__THZ_BM (0xf << 24)
46#define HW_EMI_TIME__TDH_BP 16
47#define HW_EMI_TIME__TDH_BM (0xf << 16)
48#define HW_EMI_TIME__TDS_BP 8
49#define HW_EMI_TIME__TDS_BM (0x1f << 8)
50#define HW_EMI_TIME__TAS_BP 0
51#define HW_EMI_TIME__TAS_BM (0xf << 0)
52
53/** WARNING: the HW_DRAM_* registers don't have a SCT variant ! */
54#define HW_DRAM_BASE 0x800E0000
55
56#define HW_DRAM_CTLxx(xx) (*(volatile uint32_t *)(HW_DRAM_BASE + 0x4 * (xx)))
57
58#define HW_DRAM_CTL00 (*(volatile uint32_t *)(HW_DRAM_BASE + 0x0))
59#define HW_DRAM_CTL01 (*(volatile uint32_t *)(HW_DRAM_BASE + 0x4))
60#define HW_DRAM_CTL02 (*(volatile uint32_t *)(HW_DRAM_BASE + 0x8))
61#define HW_DRAM_CTL03 (*(volatile uint32_t *)(HW_DRAM_BASE + 0xc))
62
63#define HW_DRAM_CTL04 (*(volatile uint32_t *)(HW_DRAM_BASE + 0x10))
64#define HW_DRAM_CTL04__DLL_BYPASS_MODE (1 << 24)
65#define HW_DRAM_CTL04__DLLLOCKREG (1 << 16)
66
67#define HW_DRAM_CTL05 (*(volatile uint32_t *)(HW_DRAM_BASE + 0x14))
68#define HW_DRAM_CTL05__EN_LOWPOWER_MODE (1 << 0)
69
70#define HW_DRAM_CTL06 (*(volatile uint32_t *)(HW_DRAM_BASE + 0x18))
71#define HW_DRAM_CTL07 (*(volatile uint32_t *)(HW_DRAM_BASE + 0x1c))
72
73#define HW_DRAM_CTL08 (*(volatile uint32_t *)(HW_DRAM_BASE + 0x20))
74#define HW_DRAM_CTL08__SREFRESH (1 << 8)
75
76#define HW_DRAM_CTL09 (*(volatile uint32_t *)(HW_DRAM_BASE + 0x24))
77
78#define HW_DRAM_CTL10 (*(volatile uint32_t *)(HW_DRAM_BASE + 0x28))
79#define HW_DRAM_CTL10__TEMRS_BP 8
80#define HW_DRAM_CTL10__TEMRS_BM (0x3 << 8)
81
82#define HW_DRAM_CTL11 (*(volatile uint32_t *)(HW_DRAM_BASE + 0x2c))
83#define HW_DRAM_CTL11__CASLAT_BP 0
84#define HW_DRAM_CTL11__CASLAT_BM (0x7 << 0)
85
86#define HW_DRAM_CTL12 (*(volatile uint32_t *)(HW_DRAM_BASE + 0x30))
87#define HW_DRAM_CTL12__TCKE_BP 0
88#define HW_DRAM_CTL12__TCKE_BM (0x7 << 0)
89#define HW_DRAM_CTL12__TRRD_BP 16
90#define HW_DRAM_CTL12__TRRD_BM (0x7 << 16)
91#define HW_DRAM_CTL12__TWR_INT_BP 24
92#define HW_DRAM_CTL12__TWR_INT_BM (0x7 << 24)
93
94#define HW_DRAM_CTL13 (*(volatile uint32_t *)(HW_DRAM_BASE + 0x34))
95#define HW_DRAM_CTL13__TWTR_BP 0
96#define HW_DRAM_CTL13__TWTR_BM (0x7 << 0)
97#define HW_DRAM_CTL13__CASLAT_LIN_BP 16
98#define HW_DRAM_CTL13__CASLAT_LIN_BM (0xf << 16)
99#define HW_DRAM_CTL13__CASLAT_LIN_GATE_BP 24
100#define HW_DRAM_CTL13__CASLAT_LIN_GATE_BM (0xf << 24)
101
102#define HW_DRAM_CTL14 (*(volatile uint32_t *)(HW_DRAM_BASE + 0x38))
103
104#define HW_DRAM_CTL15 (*(volatile uint32_t *)(HW_DRAM_BASE + 0x3c))
105#define HW_DRAM_CTL15__TDAL_BP 16
106#define HW_DRAM_CTL15__TDAL_BM (0xf << 16)
107#define HW_DRAM_CTL15__TRP_BP 24
108#define HW_DRAM_CTL15__TRP_BM (0xf << 24)
109
110#define HW_DRAM_CTL16 (*(volatile uint32_t *)(HW_DRAM_BASE + 0x40))
111#define HW_DRAM_CTL16__TMRD_BP 24
112#define HW_DRAM_CTL16__TMRD_BM (0x1f << 24)
113
114#define HW_DRAM_CTL17 (*(volatile uint32_t *)(HW_DRAM_BASE + 0x44))
115#define HW_DRAM_CTL17__TRC_BP 0
116#define HW_DRAM_CTL17__TRC_BM (0x1f << 0)
117#define HW_DRAM_CTL17__DLL_INCREMENT_BP 8
118#define HW_DRAM_CTL17__DLL_INCREMENT_BM (0xff << 0)
119#define HW_DRAM_CTL17__DLL_START_POINT_BP 24
120#define HW_DRAM_CTL17__DLL_START_POINT_BM (0xff << 24)
121
122#define HW_DRAM_CTL18 (*(volatile uint32_t *)(HW_DRAM_BASE + 0x48))
123#define HW_DRAM_CTL17__DLL_DQS_DELAY_0_BP 16
124#define HW_DRAM_CTL17__DLL_DQS_DELAY_0_BM (0x7f << 16)
125#define HW_DRAM_CTL17__DLL_DQS_DELAY_1_BP 24
126#define HW_DRAM_CTL17__DLL_DQS_DELAY_1_BM (0x7f << 24)
127
128#define HW_DRAM_CTL19 (*(volatile uint32_t *)(HW_DRAM_BASE + 0x4c))
129#define HW_DRAM_CTL19__DQS_OUT_SHIFT_BP 16
130#define HW_DRAM_CTL19__DQS_OUT_SHIFT_BM (0x7f << 16)
131
132#define HW_DRAM_CTL20 (*(volatile uint32_t *)(HW_DRAM_BASE + 0x50))
133#define HW_DRAM_CTL20__WR_DQS_SHIFT_BP 0
134#define HW_DRAM_CTL20__WR_DQS_SHIFT_BM (0x7f << 0)
135#define HW_DRAM_CTL20__TRAS_MIN_BP 16
136#define HW_DRAM_CTL20__TRAS_MIN_BM (0xff << 16)
137#define HW_DRAM_CTL20__TRCD_INT_BP 24
138#define HW_DRAM_CTL20__TRCD_INT_BM (0xff << 24)
139
140#define HW_DRAM_CTL21 (*(volatile uint32_t *)(HW_DRAM_BASE + 0x54))
141#define HW_DRAM_CTL21__TRFC_BP 0
142#define HW_DRAM_CTL21__TRFC_BM (0xff << 0)
143
144#define HW_DRAM_CTL22 (*(volatile uint32_t *)(HW_DRAM_BASE + 0x58))
145#define HW_DRAM_CTL23 (*(volatile uint32_t *)(HW_DRAM_BASE + 0x5c))
146#define HW_DRAM_CTL24 (*(volatile uint32_t *)(HW_DRAM_BASE + 0x60))
147#define HW_DRAM_CTL25 (*(volatile uint32_t *)(HW_DRAM_BASE + 0x64))
148
149#define HW_DRAM_CTL26 (*(volatile uint32_t *)(HW_DRAM_BASE + 0x68))
150#define HW_DRAM_CTL26__TREF_BP 0
151#define HW_DRAM_CTL26__TREF_BM (0xfff << 0)
152
153#define HW_DRAM_CTL27 (*(volatile uint32_t *)(HW_DRAM_BASE + 0x6c))
154#define HW_DRAM_CTL28 (*(volatile uint32_t *)(HW_DRAM_BASE + 0x70))
155#define HW_DRAM_CTL29 (*(volatile uint32_t *)(HW_DRAM_BASE + 0x74))
156#define HW_DRAM_CTL30 (*(volatile uint32_t *)(HW_DRAM_BASE + 0x78))
157
158#define HW_DRAM_CTL31 (*(volatile uint32_t *)(HW_DRAM_BASE + 0x7c))
159#define HW_DRAM_CTL31__TDLL_BP 16
160#define HW_DRAM_CTL31__TDLL_BM (0xffff << 16)
161
162#define HW_DRAM_CTL32 (*(volatile uint32_t *)(HW_DRAM_BASE + 0x80))
163#define HW_DRAM_CTL32__TRAS_MAX_BP 0
164#define HW_DRAM_CTL32__TRAS_MAX_BM (0xffff << 0)
165#define HW_DRAM_CTL32__TXSNR_BP 16
166#define HW_DRAM_CTL32__TXSNR_BM (0xffff << 16)
167
168#define HW_DRAM_CTL33 (*(volatile uint32_t *)(HW_DRAM_BASE + 0x84))
169#define HW_DRAM_CTL33__TXSR_BP 0
170#define HW_DRAM_CTL33__TXSR_BM (0xffff << 0)
171
172#define HW_DRAM_CTL34 (*(volatile uint32_t *)(HW_DRAM_BASE + 0x88))
173#define HW_DRAM_CTL34__TINIT_BP 0
174#define HW_DRAM_CTL34__TINIT_BM 0xffffff
175
176#define HW_DRAM_CTL35 (*(volatile uint32_t *)(HW_DRAM_BASE + 0x8c))
177#define HW_DRAM_CTL36 (*(volatile uint32_t *)(HW_DRAM_BASE + 0x90))
178#define HW_DRAM_CTL37 (*(volatile uint32_t *)(HW_DRAM_BASE + 0x94))
179#define HW_DRAM_CTL38 (*(volatile uint32_t *)(HW_DRAM_BASE + 0x98))
180#define HW_DRAM_CTL39 (*(volatile uint32_t *)(HW_DRAM_BASE + 0x9a))
181
182#define HW_DRAM_CTL40 (*(volatile uint32_t *)(HW_DRAM_BASE + 0xa0))
183#define HW_DRAM_CTL40__TPDEX_BP 16
184#define HW_DRAM_CTL40__TPDEX_BM (0xffff << 16)
185
186/** Interesting fields:
187 * - TCKE: CTL12
188 * - TDAL: CTL15
189 * - TDLL: CTL31
190 * - TEMRS: CTL10
191 * - TINIT: CTL34
192 * - TMRD: CTL16
193 * - TPDEX: CTL40
194 * - TRAS_MAX: CTL32
195 * - TRAS_MIN: CTL20
196 * - TRC: CTL17
197 * - TRCD_INT: CTL20
198 * - TREF: CTL26
199 * - TRFC: CTL21
200 * - TRP: CTL15
201 * - TRRD: CTL12
202 * - TWR_INT: CTL12
203 * - TWTR: CTL13
204 * - TXSNR: CTL32
205 * - TXSR: CTL33
206 * - DLL_DQS_DELAY_BYPASS_0
207 * - DLL_DQS_DELAY_BYPASS_1
208 * - DQS_OUT_SHIFT_BYPASS
209 * - WR_DQS_SHIFT_BYPASS
210 * - DLL_INCREMENT: CTL17
211 * - DLL_START_POINT: CTL17
212 * - DLL_DQS_DELAY_0: CTL18
213 * - DLL_DQS_DELAY_1: CTL18
214 * - DQS_OUT_SHIFT: CTL19
215 * - WR_DQS_SHIFT: CTL20
216 * - CAS: CTL11
217 * - DLL_BYPASS_MODE: CTL04
218 * - SREFRESH: CTL08
219 * - CASLAT_LIN: CTL13
220 * - CASLAT_LIN_GATE: CTL13
221 *
222 * Interesting registers:
223 * - CTL04: DLL_BYPASS_MODE
224 * - CTL08: SREFRESH
225 * - CTL10: TEMRS
226 * - CTL11: CASLAT
227 * - CTL12: TCKE TRRD TWR_INT
228 * - CTL13: TWTR CASLAT_LIN CASLAT_LIN_GATE
229 * - CTL15: TDAL TRP
230 * - CTL16: TMRD
231 * - CTL17: TRC DLL_INCREMENT DLL_START_POINT
232 * - CTL18: DLL_DQS_DELAY_0 DLL_DQS_DELAY_1
233 * - CTL19: DQS_OUT_SHIFT
234 * - CTL20: WR_DQS_SHIFT TRAS_MIN TRCD_INT
235 * - CTL21 TRFC
236 * - CTL26: TREF
237 * - CTL31: TDLL
238 * - CTL32: TRAS_MAX TXSNR TXSR: CTL33
239 * - CTL34: TINIT
240 * - CTL40: TPDEX
241
242 * - DLL_DQS_DELAY_BYPASS_0
243 * - DLL_DQS_DELAY_BYPASS_1
244 * - DQS_OUT_SHIFT_BYPASS
245 * - WR_DQS_SHIFT_BYPASS
246 */
247
248/**
249 * Absolute maximum EMI speed: 151.58 MHz (mDDR), 130.91 MHz (DDR)
250 * Intermediate EMI speeds: 130.91 MHz, 120.00 MHz, 64 MHz, 24 MHz
251 * Absolute minimum CPU speed: 24 MHz */
252#define IMX233_EMIFREQ_151_MHz 151580
253#define IMX233_EMIFREQ_130_MHz 130910
254#define IMX233_EMIFREQ_120_MHz 120000
255#define IMX233_EMIFREQ_64_MHz 64000
256#define IMX233_EMIFREQ_24_MHz 24000
257
258void imx233_emi_set_frequency(unsigned long freq);
259
260#endif /* __EMI_IMX233_H__ */