1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#undef DEBUG
16
17#include <linux/module.h>
18#include <linux/kernel.h>
19#include <linux/device.h>
20#include <linux/list.h>
21#include <linux/errno.h>
22#include <linux/delay.h>
23#include <linux/clk.h>
24#include <linux/io.h>
25
26#include <plat/common.h>
27#include <plat/clock.h>
28#include <plat/sram.h>
29
30#include <plat/sdrc.h>
31#include "sdrc.h"
32
33static struct omap_sdrc_params *sdrc_init_params_cs0, *sdrc_init_params_cs1;
34
35void __iomem *omap2_sdrc_base;
36void __iomem *omap2_sms_base;
37
38struct omap2_sms_regs {
39 u32 sms_sysconfig;
40};
41
42static struct omap2_sms_regs sms_context;
43
44
45#define SDRC_POWER_EXTCLKDIS_SHIFT 3
46#define SDRC_POWER_PWDENA_SHIFT 2
47#define SDRC_POWER_PAGEPOLICY_SHIFT 0
48
49
50
51
52
53
54void omap2_sms_save_context(void)
55{
56 sms_context.sms_sysconfig = sms_read_reg(SMS_SYSCONFIG);
57}
58
59
60
61
62
63
64void omap2_sms_restore_context(void)
65{
66 sms_write_reg(sms_context.sms_sysconfig, SMS_SYSCONFIG);
67}
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91int omap2_sdrc_get_params(unsigned long r,
92 struct omap_sdrc_params **sdrc_cs0,
93 struct omap_sdrc_params **sdrc_cs1)
94{
95 struct omap_sdrc_params *sp0, *sp1;
96
97 if (!sdrc_init_params_cs0)
98 return -1;
99
100 sp0 = sdrc_init_params_cs0;
101 sp1 = sdrc_init_params_cs1;
102
103 while (sp0->rate && sp0->rate != r) {
104 sp0++;
105 if (sdrc_init_params_cs1)
106 sp1++;
107 }
108
109 if (!sp0->rate)
110 return -1;
111
112 *sdrc_cs0 = sp0;
113 *sdrc_cs1 = sp1;
114 return 0;
115}
116
117
118void __init omap2_set_globals_sdrc(struct omap_globals *omap2_globals)
119{
120
121 if (omap2_globals->sdrc) {
122 omap2_sdrc_base = ioremap(omap2_globals->sdrc, SZ_64K);
123 WARN_ON(!omap2_sdrc_base);
124 }
125 if (omap2_globals->sms) {
126 omap2_sms_base = ioremap(omap2_globals->sms, SZ_64K);
127 WARN_ON(!omap2_sms_base);
128 }
129}
130
131
132
133
134
135
136
137
138
139
140void __init omap2_sdrc_init(struct omap_sdrc_params *sdrc_cs0,
141 struct omap_sdrc_params *sdrc_cs1)
142{
143 u32 l;
144
145 l = sms_read_reg(SMS_SYSCONFIG);
146 l &= ~(0x3 << 3);
147 l |= (0x2 << 3);
148 sms_write_reg(l, SMS_SYSCONFIG);
149
150 l = sdrc_read_reg(SDRC_SYSCONFIG);
151 l &= ~(0x3 << 3);
152 l |= (0x2 << 3);
153 sdrc_write_reg(l, SDRC_SYSCONFIG);
154
155 sdrc_init_params_cs0 = sdrc_cs0;
156 sdrc_init_params_cs1 = sdrc_cs1;
157
158
159
160
161
162
163 l = (1 << SDRC_POWER_EXTCLKDIS_SHIFT) |
164 (1 << SDRC_POWER_PAGEPOLICY_SHIFT);
165 sdrc_write_reg(l, SDRC_POWER);
166 omap2_sms_save_context();
167}
168
169void omap2_sms_write_rot_control(u32 val, unsigned ctx)
170{
171 sms_write_reg(val, SMS_ROT_CONTROL(ctx));
172}
173
174void omap2_sms_write_rot_size(u32 val, unsigned ctx)
175{
176 sms_write_reg(val, SMS_ROT_SIZE(ctx));
177}
178
179void omap2_sms_write_rot_physical_ba(u32 val, unsigned ctx)
180{
181 sms_write_reg(val, SMS_ROT_PHYSICAL_BA(ctx));
182}
183
184