2 * SDRC register values for Nokia boards
4 * Copyright (C) 2008, 2010-2011 Nokia Corporation
6 * Lauri Leukkunen <lauri.leukkunen@nokia.com>
8 * Original code by Juha Yrjola <juha.yrjola@solidboot.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
15 #include <linux/kernel.h>
16 #include <linux/clk.h>
17 #include <linux/err.h>
21 #include "sdram-nokia.h"
24 /* In picoseconds, except for tREF (ns), tXP, tCKE, tWTR (clks) */
25 struct sdram_timings
{
44 static const struct sdram_timings nokia_97dot6mhz_timings
[] = {
65 static const struct sdram_timings nokia_166mhz_timings
[] = {
86 static const struct sdram_timings nokia_195dot2mhz_timings
[] = {
107 static const struct sdram_timings nokia_200mhz_timings
[] = {
128 static const struct {
130 struct sdram_timings
const *data
;
131 } nokia_timings
[] = {
132 { 83000000, nokia_166mhz_timings
},
133 { 97600000, nokia_97dot6mhz_timings
},
134 { 100000000, nokia_200mhz_timings
},
135 { 166000000, nokia_166mhz_timings
},
136 { 195200000, nokia_195dot2mhz_timings
},
137 { 200000000, nokia_200mhz_timings
},
139 static struct omap_sdrc_params nokia_sdrc_params
[ARRAY_SIZE(nokia_timings
) + 1];
141 static unsigned long sdrc_get_fclk_period(long rate
)
144 return 1000000000 / rate
;
147 static unsigned int sdrc_ps_to_ticks(unsigned int time_ps
, long rate
)
149 unsigned long tick_ps
;
151 /* Calculate in picosecs to yield more exact results */
152 tick_ps
= sdrc_get_fclk_period(rate
);
154 return (time_ps
+ tick_ps
- 1) / tick_ps
;
158 static int set_sdrc_timing_regval(u32
*regval
, int st_bit
, int end_bit
,
159 int ticks
, long rate
, const char *name
)
161 static int set_sdrc_timing_regval(u32
*regval
, int st_bit
, int end_bit
,
167 nr_bits
= end_bit
- st_bit
+ 1;
168 if (ticks
>= 1 << nr_bits
)
170 mask
= (1 << nr_bits
) - 1;
171 *regval
&= ~(mask
<< st_bit
);
172 *regval
|= ticks
<< st_bit
;
174 printk(KERN_INFO
"SDRC %s: %i ticks %i ns\n", name
, ticks
,
175 (unsigned int)sdrc_get_fclk_period(rate
) * ticks
/
183 #define SDRC_SET_ONE(reg, st, end, field, rate) \
184 if (set_sdrc_timing_regval((reg), (st), (end), \
185 memory_timings->field, (rate), #field) < 0) \
188 #define SDRC_SET_ONE(reg, st, end, field, rate) \
189 if (set_sdrc_timing_regval((reg), (st), (end), \
190 memory_timings->field) < 0) \
195 static int set_sdrc_timing_regval_ps(u32
*regval
, int st_bit
, int end_bit
,
196 int time
, long rate
, const char *name
)
198 static int set_sdrc_timing_regval_ps(u32
*regval
, int st_bit
, int end_bit
,
208 ticks
= sdrc_ps_to_ticks(time
, rate
);
211 ret
= set_sdrc_timing_regval(regval
, st_bit
, end_bit
, ticks
,
214 ret
= set_sdrc_timing_regval(regval
, st_bit
, end_bit
, ticks
);
221 #define SDRC_SET_ONE_PS(reg, st, end, field, rate) \
222 if (set_sdrc_timing_regval_ps((reg), (st), (end), \
223 memory_timings->field, \
224 (rate), #field) < 0) \
228 #define SDRC_SET_ONE_PS(reg, st, end, field, rate) \
229 if (set_sdrc_timing_regval_ps((reg), (st), (end), \
230 memory_timings->field, (rate)) < 0) \
234 static int sdrc_timings(int id
, long rate
,
235 const struct sdram_timings
*memory_timings
)
239 u32 actim_ctrla
= 0, actim_ctrlb
= 0;
242 long l3_rate
= rate
/ 1000;
244 SDRC_SET_ONE_PS(&actim_ctrla
, 0, 4, tDAL
, l3_rate
);
245 SDRC_SET_ONE_PS(&actim_ctrla
, 6, 8, tDPL
, l3_rate
);
246 SDRC_SET_ONE_PS(&actim_ctrla
, 9, 11, tRRD
, l3_rate
);
247 SDRC_SET_ONE_PS(&actim_ctrla
, 12, 14, tRCD
, l3_rate
);
248 SDRC_SET_ONE_PS(&actim_ctrla
, 15, 17, tRP
, l3_rate
);
249 SDRC_SET_ONE_PS(&actim_ctrla
, 18, 21, tRAS
, l3_rate
);
250 SDRC_SET_ONE_PS(&actim_ctrla
, 22, 26, tRC
, l3_rate
);
251 SDRC_SET_ONE_PS(&actim_ctrla
, 27, 31, tRFC
, l3_rate
);
253 SDRC_SET_ONE_PS(&actim_ctrlb
, 0, 7, tXSR
, l3_rate
);
255 SDRC_SET_ONE(&actim_ctrlb
, 8, 10, tXP
, l3_rate
);
256 SDRC_SET_ONE(&actim_ctrlb
, 12, 14, tCKE
, l3_rate
);
257 SDRC_SET_ONE(&actim_ctrlb
, 16, 17, tWTR
, l3_rate
);
259 ticks_per_ms
= l3_rate
;
260 rfr
= memory_timings
[0].tREF
* ticks_per_ms
/ 1000000;
261 if (rfr
> 65535 + 50)
267 printk(KERN_INFO
"SDRC tREF: %i ticks\n", rfr
);
271 rfr_ctrl
= l
| 0x1; /* autorefresh, reload counter with 1xARCV */
273 nokia_sdrc_params
[id
].rate
= rate
;
274 nokia_sdrc_params
[id
].actim_ctrla
= actim_ctrla
;
275 nokia_sdrc_params
[id
].actim_ctrlb
= actim_ctrlb
;
276 nokia_sdrc_params
[id
].rfr_ctrl
= rfr_ctrl
;
277 nokia_sdrc_params
[id
].mr
= 0x32;
279 nokia_sdrc_params
[id
+ 1].rate
= 0;
284 struct omap_sdrc_params
*nokia_get_sdram_timings(void)
289 for (i
= 0; i
< ARRAY_SIZE(nokia_timings
); i
++) {
290 err
|= sdrc_timings(i
, nokia_timings
[i
].rate
,
291 nokia_timings
[i
].data
);
293 pr_err("%s: error with rate %ld: %d\n", __func__
,
294 nokia_timings
[i
].rate
, err
);
297 return err
? NULL
: nokia_sdrc_params
;