15 #include <linux/kernel.h>
21 #include <plat/clock.h>
46 static const struct sdram_timings nokia_97dot6mhz_timings[] = {
88 static const struct sdram_timings nokia_195dot2mhz_timings[] = {
130 static const struct {
133 } nokia_timings[] = {
134 { 83000000, nokia_166mhz_timings },
135 { 97600000, nokia_97dot6mhz_timings },
136 { 100000000, nokia_200mhz_timings },
137 { 166000000, nokia_166mhz_timings },
138 { 195200000, nokia_195dot2mhz_timings },
139 { 200000000, nokia_200mhz_timings },
143 static unsigned long sdrc_get_fclk_period(
long rate)
146 return 1000000000 /
rate;
149 static unsigned int sdrc_ps_to_ticks(
unsigned int time_ps,
long rate)
151 unsigned long tick_ps;
154 tick_ps = sdrc_get_fclk_period(rate);
156 return (time_ps + tick_ps - 1) / tick_ps;
160 static int set_sdrc_timing_regval(
u32 *
regval,
int st_bit,
int end_bit,
163 static int set_sdrc_timing_regval(
u32 *regval,
int st_bit,
int end_bit,
169 nr_bits = end_bit - st_bit + 1;
170 if (ticks >= 1 << nr_bits)
172 mask = (1 << nr_bits) - 1;
173 *regval &= ~(mask << st_bit);
174 *regval |= ticks << st_bit;
177 (
unsigned int)sdrc_get_fclk_period(rate) * ticks /
185 #define SDRC_SET_ONE(reg, st, end, field, rate) \
186 if (set_sdrc_timing_regval((reg), (st), (end), \
187 memory_timings->field, (rate), #field) < 0) \
190 #define SDRC_SET_ONE(reg, st, end, field, rate) \
191 if (set_sdrc_timing_regval((reg), (st), (end), \
192 memory_timings->field) < 0) \
197 static int set_sdrc_timing_regval_ps(
u32 *regval,
int st_bit,
int end_bit,
198 int time,
long rate,
const char *name)
200 static int set_sdrc_timing_regval_ps(
u32 *regval,
int st_bit,
int end_bit,
210 ticks = sdrc_ps_to_ticks(time, rate);
213 ret = set_sdrc_timing_regval(regval, st_bit, end_bit, ticks,
216 ret = set_sdrc_timing_regval(regval, st_bit, end_bit, ticks);
223 #define SDRC_SET_ONE_PS(reg, st, end, field, rate) \
224 if (set_sdrc_timing_regval_ps((reg), (st), (end), \
225 memory_timings->field, \
226 (rate), #field) < 0) \
230 #define SDRC_SET_ONE_PS(reg, st, end, field, rate) \
231 if (set_sdrc_timing_regval_ps((reg), (st), (end), \
232 memory_timings->field, (rate)) < 0) \
236 static int sdrc_timings(
int id,
long rate,
244 long l3_rate = rate / 1000;
261 ticks_per_ms = l3_rate;
262 rfr = memory_timings[0].
tREF * ticks_per_ms / 1000000;
263 if (rfr > 65535 + 50)
275 nokia_sdrc_params[
id].rate =
rate;
279 nokia_sdrc_params[
id].mr = 0x32;
281 nokia_sdrc_params[
id + 1].rate = 0;
291 for (i = 0; i <
ARRAY_SIZE(nokia_timings); i++) {
292 err |= sdrc_timings(i, nokia_timings[i].rate,
293 nokia_timings[i].
data);
295 pr_err(
"%s: error with rate %ld: %d\n", __func__,
296 nokia_timings[i].rate, err);
299 return err ?
NULL : nokia_sdrc_params;