1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
|
From 9ada9a3247ca02a0dddeae24a07a2744690aeb51 Mon Sep 17 00:00:00 2001
From: Andy Green <andy@openmoko.com>
Date: Fri, 25 Jul 2008 23:06:15 +0100
Subject: [PATCH] fix-glamo-suspend-resume-dram-and-engines.patch
Two issues... we never took care to take down engines in suspend
and bring them back in resume. This was part of the display
corruption that could be seen briefly on resume. The other issue
that made the "noise" corruption was bad ordering of resume steps.
This patch simplifies (removing needless re-init) resume actions
and makes explicit the suspend and resume steps. It also adds
code to track which engines are up and push them down in suspend
and bring them back in resume.
The result is no more corruption of display buffer in suspend, it
comes back completely clean.
Signed-off-by: Andy Green <andy@openmoko.com>
---
drivers/mfd/glamo/glamo-core.c | 269 +++++++++++++++++++---------------------
drivers/mfd/glamo/glamo-core.h | 2 +
drivers/mfd/glamo/glamo-regs.h | 6 +-
3 files changed, 137 insertions(+), 140 deletions(-)
diff --git a/drivers/mfd/glamo/glamo-core.c b/drivers/mfd/glamo/glamo-core.c
index d4b526d..ee33901 100644
--- a/drivers/mfd/glamo/glamo-core.c
+++ b/drivers/mfd/glamo/glamo-core.c
@@ -54,6 +54,8 @@
#define RESSIZE(ressource) (((ressource)->end - (ressource)->start)+1)
+#define GLAMO_MEM_REFRESH_COUNT 0x100
+
static struct glamo_core *glamo_handle;
static inline void __reg_write(struct glamo_core *glamo,
@@ -381,9 +383,8 @@ out_unlock:
* 'engine' support
***********************************************************************/
-int glamo_engine_enable(struct glamo_core *glamo, enum glamo_engine engine)
+int __glamo_engine_enable(struct glamo_core *glamo, enum glamo_engine engine)
{
- spin_lock(&glamo->lock);
switch (engine) {
case GLAMO_ENGINE_LCD:
__reg_set_bit_mask(glamo, GLAMO_REG_CLOCK_LCD,
@@ -432,27 +433,59 @@ int glamo_engine_enable(struct glamo_core *glamo, enum glamo_engine engine)
default:
break;
}
- spin_unlock(&glamo->lock);
+
+ glamo->engine_enabled_bitfield |= 1 << engine;
return 0;
}
-EXPORT_SYMBOL_GPL(glamo_engine_enable);
-int glamo_engine_disable(struct glamo_core *glamo, enum glamo_engine engine)
+int glamo_engine_enable(struct glamo_core *glamo, enum glamo_engine engine)
{
+ int ret;
+
spin_lock(&glamo->lock);
+
+ ret = __glamo_engine_enable(glamo, engine);
+
+ spin_unlock(&glamo->lock);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(glamo_engine_enable);
+
+int __glamo_engine_disable(struct glamo_core *glamo, enum glamo_engine engine)
+{
switch (engine) {
+ case GLAMO_ENGINE_LCD:
+ /* remove pixel clock to LCM */
+ __reg_set_bit_mask(glamo, GLAMO_REG_CLOCK_LCD,
+ GLAMO_CLOCK_LCD_EN_DCLK, 0);
+ __reg_set_bit_mask(glamo, GLAMO_REG_CLOCK_LCD,
+ GLAMO_CLOCK_LCD_EN_DHCLK |
+ GLAMO_CLOCK_LCD_EN_DMCLK, 0);
+ /* kill memory clock */
+ __reg_set_bit_mask(glamo, GLAMO_REG_CLOCK_LCD,
+ GLAMO_CLOCK_LCD_EN_M5CLK, 0);
+ /* stop dividing the clocks */
+ __reg_set_bit_mask(glamo, GLAMO_REG_CLOCK_GEN5_1,
+ GLAMO_CLOCK_GEN51_EN_DIV_DHCLK |
+ GLAMO_CLOCK_GEN51_EN_DIV_DMCLK |
+ GLAMO_CLOCK_GEN51_EN_DIV_DCLK, 0);
+ __reg_set_bit_mask(glamo, GLAMO_REG_HOSTBUS(2),
+ GLAMO_HOSTBUS2_MMIO_EN_LCD, 0);
+ break;
+
case GLAMO_ENGINE_MMC:
__reg_set_bit_mask(glamo, GLAMO_REG_CLOCK_MMC, 0,
GLAMO_CLOCK_MMC_EN_M9CLK |
GLAMO_CLOCK_MMC_EN_TCLK |
GLAMO_CLOCK_MMC_DG_M9CLK |
GLAMO_CLOCK_MMC_DG_TCLK);
- __reg_set_bit_mask(glamo, GLAMO_REG_HOSTBUS(2), 0,
- GLAMO_HOSTBUS2_MMIO_EN_MMC);
/* disable the TCLK divider clk input */
__reg_set_bit_mask(glamo, GLAMO_REG_CLOCK_GEN5_1, 0,
GLAMO_CLOCK_GEN51_EN_DIV_TCLK);
+ __reg_set_bit_mask(glamo, GLAMO_REG_HOSTBUS(2), 0,
+ GLAMO_HOSTBUS2_MMIO_EN_MMC);
/* good idea to hold the thing in reset when we power it off? */
/* writew(readw(glamo->base + GLAMO_REG_CLOCK_MMC) |
GLAMO_CLOCK_MMC_RESET, glamo->base + GLAMO_REG_CLOCK_MMC);
@@ -461,10 +494,23 @@ int glamo_engine_disable(struct glamo_core *glamo, enum glamo_engine engine)
default:
break;
}
- spin_unlock(&glamo->lock);
+
+ glamo->engine_enabled_bitfield &= ~(1 << engine);
return 0;
}
+int glamo_engine_disable(struct glamo_core *glamo, enum glamo_engine engine)
+{
+ int ret;
+
+ spin_lock(&glamo->lock);
+
+ ret = __glamo_engine_disable(glamo, engine);
+
+ spin_unlock(&glamo->lock);
+
+ return ret;
+}
EXPORT_SYMBOL_GPL(glamo_engine_disable);
struct glamo_script reset_regs[] = {
@@ -618,7 +664,7 @@ int glamo_run_script(struct glamo_core *glamo, struct glamo_script *script,
if (may_sleep)
msleep(line->val);
else
- mdelay(line->val);
+ mdelay(line->val * 4);
break;
case 0xfffd:
/* spin until PLLs lock */
@@ -717,111 +763,17 @@ static struct glamo_script glamo_init_script[] = {
{ GLAMO_REG_CLOCK_MEMORY, 0x000b },
};
-static struct glamo_script glamo_resume_script[] = {
- { GLAMO_REG_IRQ_ENABLE, 0x01ff },
- { GLAMO_REG_CLOCK_GEN6, 0x2000 },
- { GLAMO_REG_CLOCK_GEN7, 0x0001 }, /* 0101 */
- { GLAMO_REG_CLOCK_GEN8, 0x0100 },
- { GLAMO_REG_CLOCK_HOST, 0x000d },
- { 0x200, 0x0ef0 },
- { 0x202, 0x07ff },
- { 0x212, 0x0000 },
- { 0x214, 0x4000 },
- { 0x216, 0xf00e },
- { GLAMO_REG_MEM_TYPE, 0x0874 }, /* 8MB, 16 word pg wr+rd */
- { GLAMO_REG_MEM_GEN, 0xafaf }, /* 63 grants min + max */
-
- { GLAMO_REG_MEM_TIMING1, 0x0108 },
- { GLAMO_REG_MEM_TIMING2, 0x0010 }, /* Taa = 3 MCLK */
- { GLAMO_REG_MEM_TIMING3, 0x0000 },
- { GLAMO_REG_MEM_TIMING4, 0x0000 }, /* CE1# delay fall/rise */
- { GLAMO_REG_MEM_TIMING5, 0x0000 }, /* UB# LB# */
- { GLAMO_REG_MEM_TIMING6, 0x0000 }, /* OE# */
- { GLAMO_REG_MEM_TIMING7, 0x0000 }, /* WE# */
- { GLAMO_REG_MEM_TIMING8, 0x1002 }, /* MCLK delay, was 0x1000 */
- { GLAMO_REG_MEM_TIMING9, 0x6006 },
- { GLAMO_REG_MEM_TIMING10, 0x00ff },
- { GLAMO_REG_MEM_TIMING11, 0x0001 },
- { GLAMO_REG_MEM_POWER1, 0x0020 },
- { GLAMO_REG_MEM_POWER2, 0x0000 },
- { GLAMO_REG_MEM_DRAM1, 0x0000 },
- { 0xfffe, 1 },
- { GLAMO_REG_MEM_DRAM1, 0xc100 },
- { 0xfffe, 1 },
- { GLAMO_REG_MEM_DRAM1, 0xe100 },
- { GLAMO_REG_MEM_DRAM2, 0x01d6 },
- { GLAMO_REG_CLOCK_MEMORY, 0x000b },
-};
-
-#if 0 /* MM370 */
-static const struct glamo_script regs_vram_2mb = {
- { GLAMO_REG_CLOCK_MEMORY, 0x3aaa },
- { 0xfffe, 50 },
- { GLAMO_REG_CLOCK_MEMORY, 0x0aaa },
- { 0xfffe, 3 },
- { GLAMO_REG_MEM_POWER1, 0x0020 },
- { 0x033a, 0x0000 },
- { 0x033c, 0x0000 },
- { 0x033e, 0x0000 },
- { 0x0340, 0x0000 },
- { 0x0342, 0x0000 },
- { 0x0344, 0x0000 },
- { 0x0346, 0x0240 },
- { GLAMO_REG_MEM_TIMING8, 0x1016 },
- { GLAMO_REG_MEM_TIMING9, 0x6067 },
- { GLAMO_REG_MEM_TIMING10, 0x00ff },
- { GLAMO_REG_MEM_TIMING11, 0x0030 },
- { GLAMO_REG_MEM_GEN, 0x3fff },
- { GLAMO_REG_MEM_GEN, 0xafaf },
- { GLAMO_REG_MEM_TIMING1, 0x0108 },
- { GLAMO_REG_MEM_TIMING2, 0x0010 },
- { GLAMO_REG_MEM_DRAM1, 0x0a00 },
- { 0xfffe, 3 },
- { GLAMO_REG_MEM_DRAM1, 0xe200 },
- { 0xfffe, 1 },
-};
-
-static const struct glamo_script regs_vram_8mb = {
- { GLAMO_REG_CLOCK_MEMORY, 0x3aaa },
- { 0xfffe, 50 },
- { GLAMO_REG_CLOCK_MEMORY, 0x0aaa },
- { 0xfffe, 3 },
- { GLAMO_REG_MEM_POWER1, 0x0020 },
- { 0x033a, 0x45cf },
- { 0x033c, 0x4240 },
- { 0x033e, 0x53e0 },
- { 0x0340, 0x1401 },
- { 0x0342, 0x0c44 },
- { 0x0344, 0x1d0b },
- { 0x0346, 0x25ac },
- { 0x0348, 0x1953 },
- { 0xfffe, 1 },
- { GLAMO_REG_MEM_TYPE, 0x087a },
- { GLAMO_REG_MEM_DRAM2, 0x01d6 },
- { GLAMO_REG_MEM_TIMING8, 0x1060 },
- { GLAMO_REG_MEM_TIMING9, 0x6067 },
- { GLAMO_REG_MEM_TIMING10, 0x00ff },
- { GLAMO_REG_MEM_TIMING11, 0x0030 },
- { GLAMO_REG_MEM_GEN, 0x3fff },
- { GLAMO_REG_MEM_GEN, 0xafaf },
- { GLAMO_REG_MEM_TIMING1, 0x3108 },
- { GLAMO_REG_MEM_TIMING2, 0x0010 },
- { GLAMO_REG_MEM_DRAM1, 0x0a00 },
- { 0xfffe, 3 },
- { GLAMO_REG_MEM_DRAM1, 0xe200 },
- { 0xfffe, 1 },
-};
-#endif
enum glamo_power {
GLAMO_POWER_ON,
- GLAMO_POWER_STANDBY,
GLAMO_POWER_SUSPEND,
};
static void glamo_power(struct glamo_core *glamo,
enum glamo_power new_state)
{
+ int n;
+
spin_lock(&glamo->lock);
dev_dbg(&glamo->pdev->dev, "***** glamo_power -> %d\n", new_state);
@@ -836,37 +788,76 @@ static void glamo_power(struct glamo_core *glamo,
while ((__reg_read(glamo, GLAMO_REG_PLL_GEN5) & 3) != 3)
;
- /* enable memory clock and get it out of deep pwrdown */
- __reg_set_bit_mask(glamo, GLAMO_REG_CLOCK_MEMORY,
- GLAMO_CLOCK_MEM_EN_MOCACLK, 0xffff);
- __reg_set_bit_mask(glamo, GLAMO_REG_MEM_DRAM2,
- GLAMO_MEM_DRAM2_DEEP_PWRDOWN, 0x0000);
- __reg_set_bit_mask(glamo, GLAMO_REG_MEM_DRAM1,
- GLAMO_MEM_DRAM1_SELF_REFRESH, 0x0000);
-
- glamo_run_script(glamo, glamo_resume_script,
- ARRAY_SIZE(glamo_resume_script), 0);
-
- break;
-
- case GLAMO_POWER_STANDBY:
- /* enable memory self-refresh */
- __reg_set_bit_mask(glamo, GLAMO_REG_MEM_DRAM1,
- GLAMO_MEM_DRAM1_SELF_REFRESH, 0xffff);
- /* stop memory clock */
- __reg_set_bit_mask(glamo, GLAMO_REG_CLOCK_MEMORY,
- GLAMO_CLOCK_MEM_EN_MOCACLK, 0x0000);
- /* power down PLL2 and then PLL1 */
- __reg_set_bit_mask(glamo, GLAMO_REG_PLL_GEN3, 0x2000, 0xffff);
- __reg_set_bit_mask(glamo, GLAMO_REG_DFT_GEN5, 0x0001, 0xffff);
+ /* Get memory out of deep powerdown */
+
+ __reg_write(glamo, GLAMO_REG_MEM_DRAM2,
+ (7 << 6) | /* tRC */
+ (1 << 4) | /* tRP */
+ (1 << 2) | /* tRCD */
+ 2); /* CAS latency */
+
+ /* Stop self-refresh */
+
+ __reg_write(glamo, GLAMO_REG_MEM_DRAM1,
+ GLAMO_MEM_DRAM1_EN_DRAM_REFRESH |
+ GLAMO_MEM_DRAM1_EN_GATE_CKE |
+ GLAMO_MEM_REFRESH_COUNT);
+ __reg_write(glamo, GLAMO_REG_MEM_DRAM1,
+ GLAMO_MEM_DRAM1_EN_MODEREG_SET |
+ GLAMO_MEM_DRAM1_EN_DRAM_REFRESH |
+ GLAMO_MEM_DRAM1_EN_GATE_CKE |
+ GLAMO_MEM_REFRESH_COUNT);
+
+ /* re-enable clocks to memory */
+
+ __reg_write(glamo, GLAMO_REG_CLOCK_MEMORY,
+ GLAMO_CLOCK_MEM_EN_MOCACLK |
+ GLAMO_CLOCK_MEM_EN_M1CLK |
+ GLAMO_CLOCK_MEM_DG_M1CLK);
+
+ /* restore each engine that was up before suspend */
+ for (n = 0; n < __NUM_GLAMO_ENGINES; n++)
+ if (glamo->engine_enabled_bitfield_suspend & (1 << n))
+ __glamo_engine_enable(glamo, n);
break;
case GLAMO_POWER_SUSPEND:
- __reg_set_bit_mask(glamo, GLAMO_REG_MEM_DRAM2,
- GLAMO_MEM_DRAM2_DEEP_PWRDOWN, 0xffff);
- /* stop memory clock */
- __reg_set_bit_mask(glamo, GLAMO_REG_CLOCK_MEMORY,
- GLAMO_CLOCK_MEM_EN_MOCACLK, 0x0000);
+ /* stash a copy of which engines were running */
+ glamo->engine_enabled_bitfield_suspend =
+ glamo->engine_enabled_bitfield;
+
+ /* take down each engine before we kill mem and pll */
+ for (n = 0; n < __NUM_GLAMO_ENGINES; n++)
+ if (glamo->engine_enabled_bitfield & (1 << n))
+ __glamo_engine_disable(glamo, n);
+
+ /* enable self-refresh */
+
+ __reg_write(glamo, GLAMO_REG_MEM_DRAM1,
+ GLAMO_MEM_DRAM1_EN_DRAM_REFRESH |
+ GLAMO_MEM_DRAM1_EN_GATE_CKE |
+ GLAMO_MEM_DRAM1_SELF_REFRESH |
+ GLAMO_MEM_REFRESH_COUNT);
+ __reg_write(glamo, GLAMO_REG_MEM_DRAM1,
+ GLAMO_MEM_DRAM1_EN_MODEREG_SET |
+ GLAMO_MEM_DRAM1_EN_DRAM_REFRESH |
+ GLAMO_MEM_DRAM1_EN_GATE_CKE |
+ GLAMO_MEM_DRAM1_SELF_REFRESH |
+ GLAMO_MEM_REFRESH_COUNT);
+
+ /* force RAM into deep powerdown */
+
+ __reg_write(glamo, GLAMO_REG_MEM_DRAM2,
+ GLAMO_MEM_DRAM2_DEEP_PWRDOWN |
+ (7 << 6) | /* tRC */
+ (1 << 4) | /* tRP */
+ (1 << 2) | /* tRCD */
+ 2); /* CAS latency */
+
+ /* kill clocks to memory */
+
+ __reg_write(glamo, GLAMO_REG_CLOCK_MEMORY, 0);
+
/* power down PLL2 and then PLL1 */
__reg_set_bit_mask(glamo, GLAMO_REG_PLL_GEN3, 0x2000, 0xffff);
__reg_set_bit_mask(glamo, GLAMO_REG_DFT_GEN5, 0x0001, 0xffff);
@@ -1016,15 +1007,15 @@ static ssize_t regs_read(struct device *dev, struct device_attribute *attr,
char * name;
};
struct reg_range reg_range[] = {
-/* { 0x0000, 0x200, "General" },
- { 0x0200, 0x100, "Host Bus" },
- { 0x0300, 0x100, "Memory" },
- { 0x0400, 0x100, "Sensor" },
+ { 0x0000, 0x76, "General" },
+/* { 0x0200, 0x100, "Host Bus" },
+*/ { 0x0300, 0x38, "Memory" },
+/* { 0x0400, 0x100, "Sensor" },
{ 0x0500, 0x300, "ISP" },
{ 0x0800, 0x400, "JPEG" },
{ 0x0c00, 0x500, "MPEG" },
*/
- { 0x1100, 0x400, "LCD" },
+ { 0x1100, 0x88, "LCD" },
/*
{ 0x1500, 0x080, "MPU 0" },
{ 0x1580, 0x080, "MPU 1" },
@@ -1039,7 +1030,7 @@ static ssize_t regs_read(struct device *dev, struct device_attribute *attr,
for (r = 0; r < ARRAY_SIZE(reg_range); r++) {
n1 = 0;
- end += sprintf(end, "\n%s\n\n", reg_range[r].name);
+ end += sprintf(end, "\n%s\n", reg_range[r].name);
for (n = reg_range[r].start;
n < reg_range[r].start + reg_range[r].count; n += 2) {
if (((n1++) & 7) == 0)
diff --git a/drivers/mfd/glamo/glamo-core.h b/drivers/mfd/glamo/glamo-core.h
index b1531b3..c89f810 100644
--- a/drivers/mfd/glamo/glamo-core.h
+++ b/drivers/mfd/glamo/glamo-core.h
@@ -30,6 +30,8 @@ struct glamo_core {
u_int16_t revision;
spinlock_t lock;
struct resume_dependency resume_dependency;
+ u32 engine_enabled_bitfield;
+ u32 engine_enabled_bitfield_suspend;
};
struct glamo_script {
diff --git a/drivers/mfd/glamo/glamo-regs.h b/drivers/mfd/glamo/glamo-regs.h
index 32411e3..2328b8a 100644
--- a/drivers/mfd/glamo/glamo-regs.h
+++ b/drivers/mfd/glamo/glamo-regs.h
@@ -142,8 +142,12 @@ enum glamo_register_mem {
#define GLAMO_MEM_TYPE_MASK 0x03
enum glamo_reg_mem_dram1 {
- GLAMO_MEM_DRAM1_EN_SDRAM_CLK = (1 << 11),
+ /* b0 - b10 == refresh period, 1 -> 2048 clocks */
+ GLAMO_MEM_DRAM1_EN_GATE_CLK = (1 << 11),
GLAMO_MEM_DRAM1_SELF_REFRESH = (1 << 12),
+ GLAMO_MEM_DRAM1_EN_GATE_CKE = (1 << 13),
+ GLAMO_MEM_DRAM1_EN_DRAM_REFRESH = (1 << 14),
+ GLAMO_MEM_DRAM1_EN_MODEREG_SET = (1 << 15),
};
enum glamo_reg_mem_dram2 {
--
1.5.6.3
|