2 * SDRC register values for Nokia boards
4 * Copyright (C) 2008, 2010 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 <plat/common.h>
22 #include <plat/clock.h>
23 #include <plat/sdrc.h>
25 #include "sdram-nokia.h"
27 /* In picoseconds, except for tREF (ns), tXP, tCKE, tWTR (clks) */
28 struct sdram_timings
{
47 static const struct sdram_timings nokia_97dot6mhz_timings
[] = {
68 static const struct sdram_timings nokia_166mhz_timings
[] = {
89 static const struct sdram_timings nokia_195dot2mhz_timings
[] = {
110 static const struct {
112 struct sdram_timings
const *data
;
113 } nokia_timings
[] = {
114 { 83000000, nokia_166mhz_timings
},
115 { 97600000, nokia_97dot6mhz_timings
},
116 { 166000000, nokia_166mhz_timings
},
117 { 195200000, nokia_195dot2mhz_timings
},
119 static struct omap_sdrc_params nokia_sdrc_params
[ARRAY_SIZE(nokia_timings
) + 1];
121 static unsigned long sdrc_get_fclk_period(long rate
)
124 return 1000000000 / rate
;
127 static unsigned int sdrc_ps_to_ticks(unsigned int time_ps
, long rate
)
129 unsigned long tick_ps
;
131 /* Calculate in picosecs to yield more exact results */
132 tick_ps
= sdrc_get_fclk_period(rate
);
134 return (time_ps
+ tick_ps
- 1) / tick_ps
;
138 static int set_sdrc_timing_regval(u32
*regval
, int st_bit
, int end_bit
,
139 int ticks
, long rate
, const char *name
)
141 static int set_sdrc_timing_regval(u32
*regval
, int st_bit
, int end_bit
,
147 nr_bits
= end_bit
- st_bit
+ 1;
148 if (ticks
>= 1 << nr_bits
)
150 mask
= (1 << nr_bits
) - 1;
151 *regval
&= ~(mask
<< st_bit
);
152 *regval
|= ticks
<< st_bit
;
154 printk(KERN_INFO
"SDRC %s: %i ticks %i ns\n", name
, ticks
,
155 (unsigned int)sdrc_get_fclk_period(rate
) * ticks
/
163 #define SDRC_SET_ONE(reg, st, end, field, rate) \
164 if (set_sdrc_timing_regval((reg), (st), (end), \
165 memory_timings->field, (rate), #field) < 0) \
168 #define SDRC_SET_ONE(reg, st, end, field, rate) \
169 if (set_sdrc_timing_regval((reg), (st), (end), \
170 memory_timings->field) < 0) \
175 static int set_sdrc_timing_regval_ps(u32
*regval
, int st_bit
, int end_bit
,
176 int time
, long rate
, const char *name
)
178 static int set_sdrc_timing_regval_ps(u32
*regval
, int st_bit
, int end_bit
,
188 ticks
= sdrc_ps_to_ticks(time
, rate
);
191 ret
= set_sdrc_timing_regval(regval
, st_bit
, end_bit
, ticks
,
194 ret
= set_sdrc_timing_regval(regval
, st_bit
, end_bit
, ticks
);
201 #define SDRC_SET_ONE_PS(reg, st, end, field, rate) \
202 if (set_sdrc_timing_regval_ps((reg), (st), (end), \
203 memory_timings->field, \
204 (rate), #field) < 0) \
208 #define SDRC_SET_ONE_PS(reg, st, end, field, rate) \
209 if (set_sdrc_timing_regval_ps((reg), (st), (end), \
210 memory_timings->field, (rate)) < 0) \
214 static int sdrc_timings(int id
, long rate
,
215 const struct sdram_timings
*memory_timings
)
219 u32 actim_ctrla
= 0, actim_ctrlb
= 0;
222 long l3_rate
= rate
/ 1000;
224 SDRC_SET_ONE_PS(&actim_ctrla
, 0, 4, tDAL
, l3_rate
);
225 SDRC_SET_ONE_PS(&actim_ctrla
, 6, 8, tDPL
, l3_rate
);
226 SDRC_SET_ONE_PS(&actim_ctrla
, 9, 11, tRRD
, l3_rate
);
227 SDRC_SET_ONE_PS(&actim_ctrla
, 12, 14, tRCD
, l3_rate
);
228 SDRC_SET_ONE_PS(&actim_ctrla
, 15, 17, tRP
, l3_rate
);
229 SDRC_SET_ONE_PS(&actim_ctrla
, 18, 21, tRAS
, l3_rate
);
230 SDRC_SET_ONE_PS(&actim_ctrla
, 22, 26, tRC
, l3_rate
);
231 SDRC_SET_ONE_PS(&actim_ctrla
, 27, 31, tRFC
, l3_rate
);
233 SDRC_SET_ONE_PS(&actim_ctrlb
, 0, 7, tXSR
, l3_rate
);
235 SDRC_SET_ONE(&actim_ctrlb
, 8, 10, tXP
, l3_rate
);
236 SDRC_SET_ONE(&actim_ctrlb
, 12, 14, tCKE
, l3_rate
);
237 SDRC_SET_ONE(&actim_ctrlb
, 16, 17, tWTR
, l3_rate
);
239 ticks_per_ms
= l3_rate
;
240 rfr
= memory_timings
[0].tREF
* ticks_per_ms
/ 1000000;
241 if (rfr
> 65535 + 50)
247 printk(KERN_INFO
"SDRC tREF: %i ticks\n", rfr
);
251 rfr_ctrl
= l
| 0x1; /* autorefresh, reload counter with 1xARCV */
253 nokia_sdrc_params
[id
].rate
= rate
;
254 nokia_sdrc_params
[id
].actim_ctrla
= actim_ctrla
;
255 nokia_sdrc_params
[id
].actim_ctrlb
= actim_ctrlb
;
256 nokia_sdrc_params
[id
].rfr_ctrl
= rfr_ctrl
;
257 nokia_sdrc_params
[id
].mr
= 0x32;
259 nokia_sdrc_params
[id
+ 1].rate
= 0;
264 struct omap_sdrc_params
*nokia_get_sdram_timings(void)
269 for (i
= 0; i
< ARRAY_SIZE(nokia_timings
); i
++) {
270 err
|= sdrc_timings(i
, nokia_timings
[i
].rate
,
271 nokia_timings
[i
].data
);
273 pr_err("%s: error with rate %ld: %d\n", __func__
,
274 nokia_timings
[i
].rate
, err
);
277 return err
? NULL
: nokia_sdrc_params
;