diff options
author | Andrea Bastoni <bastoni@cs.unc.edu> | 2010-05-30 19:16:45 -0400 |
---|---|---|
committer | Andrea Bastoni <bastoni@cs.unc.edu> | 2010-05-30 19:16:45 -0400 |
commit | ada47b5fe13d89735805b566185f4885f5a3f750 (patch) | |
tree | 644b88f8a71896307d71438e9b3af49126ffb22b /drivers/video/omap2/dss/dss.c | |
parent | 43e98717ad40a4ae64545b5ba047c7b86aa44f4f (diff) | |
parent | 3280f21d43ee541f97f8cda5792150d2dbec20d5 (diff) |
Merge branch 'wip-2.6.34' into old-private-masterarchived-private-master
Diffstat (limited to 'drivers/video/omap2/dss/dss.c')
-rw-r--r-- | drivers/video/omap2/dss/dss.c | 621 |
1 files changed, 621 insertions, 0 deletions
diff --git a/drivers/video/omap2/dss/dss.c b/drivers/video/omap2/dss/dss.c new file mode 100644 index 000000000000..54344184dd73 --- /dev/null +++ b/drivers/video/omap2/dss/dss.c | |||
@@ -0,0 +1,621 @@ | |||
1 | /* | ||
2 | * linux/drivers/video/omap2/dss/dss.c | ||
3 | * | ||
4 | * Copyright (C) 2009 Nokia Corporation | ||
5 | * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com> | ||
6 | * | ||
7 | * Some code and ideas taken from drivers/video/omap/ driver | ||
8 | * by Imre Deak. | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify it | ||
11 | * under the terms of the GNU General Public License version 2 as published by | ||
12 | * the Free Software Foundation. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
17 | * more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License along with | ||
20 | * this program. If not, see <http://www.gnu.org/licenses/>. | ||
21 | */ | ||
22 | |||
23 | #define DSS_SUBSYS_NAME "DSS" | ||
24 | |||
25 | #include <linux/kernel.h> | ||
26 | #include <linux/io.h> | ||
27 | #include <linux/err.h> | ||
28 | #include <linux/delay.h> | ||
29 | #include <linux/interrupt.h> | ||
30 | #include <linux/seq_file.h> | ||
31 | #include <linux/clk.h> | ||
32 | |||
33 | #include <plat/display.h> | ||
34 | #include "dss.h" | ||
35 | |||
36 | #define DSS_BASE 0x48050000 | ||
37 | |||
38 | #define DSS_SZ_REGS SZ_512 | ||
39 | |||
40 | struct dss_reg { | ||
41 | u16 idx; | ||
42 | }; | ||
43 | |||
44 | #define DSS_REG(idx) ((const struct dss_reg) { idx }) | ||
45 | |||
46 | #define DSS_REVISION DSS_REG(0x0000) | ||
47 | #define DSS_SYSCONFIG DSS_REG(0x0010) | ||
48 | #define DSS_SYSSTATUS DSS_REG(0x0014) | ||
49 | #define DSS_IRQSTATUS DSS_REG(0x0018) | ||
50 | #define DSS_CONTROL DSS_REG(0x0040) | ||
51 | #define DSS_SDI_CONTROL DSS_REG(0x0044) | ||
52 | #define DSS_PLL_CONTROL DSS_REG(0x0048) | ||
53 | #define DSS_SDI_STATUS DSS_REG(0x005C) | ||
54 | |||
55 | #define REG_GET(idx, start, end) \ | ||
56 | FLD_GET(dss_read_reg(idx), start, end) | ||
57 | |||
58 | #define REG_FLD_MOD(idx, val, start, end) \ | ||
59 | dss_write_reg(idx, FLD_MOD(dss_read_reg(idx), val, start, end)) | ||
60 | |||
61 | static struct { | ||
62 | void __iomem *base; | ||
63 | |||
64 | struct clk *dpll4_m4_ck; | ||
65 | |||
66 | unsigned long cache_req_pck; | ||
67 | unsigned long cache_prate; | ||
68 | struct dss_clock_info cache_dss_cinfo; | ||
69 | struct dispc_clock_info cache_dispc_cinfo; | ||
70 | |||
71 | enum dss_clk_source dsi_clk_source; | ||
72 | enum dss_clk_source dispc_clk_source; | ||
73 | |||
74 | u32 ctx[DSS_SZ_REGS / sizeof(u32)]; | ||
75 | } dss; | ||
76 | |||
77 | static int _omap_dss_wait_reset(void); | ||
78 | |||
79 | static inline void dss_write_reg(const struct dss_reg idx, u32 val) | ||
80 | { | ||
81 | __raw_writel(val, dss.base + idx.idx); | ||
82 | } | ||
83 | |||
84 | static inline u32 dss_read_reg(const struct dss_reg idx) | ||
85 | { | ||
86 | return __raw_readl(dss.base + idx.idx); | ||
87 | } | ||
88 | |||
89 | #define SR(reg) \ | ||
90 | dss.ctx[(DSS_##reg).idx / sizeof(u32)] = dss_read_reg(DSS_##reg) | ||
91 | #define RR(reg) \ | ||
92 | dss_write_reg(DSS_##reg, dss.ctx[(DSS_##reg).idx / sizeof(u32)]) | ||
93 | |||
94 | void dss_save_context(void) | ||
95 | { | ||
96 | if (cpu_is_omap24xx()) | ||
97 | return; | ||
98 | |||
99 | SR(SYSCONFIG); | ||
100 | SR(CONTROL); | ||
101 | |||
102 | #ifdef CONFIG_OMAP2_DSS_SDI | ||
103 | SR(SDI_CONTROL); | ||
104 | SR(PLL_CONTROL); | ||
105 | #endif | ||
106 | } | ||
107 | |||
108 | void dss_restore_context(void) | ||
109 | { | ||
110 | if (_omap_dss_wait_reset()) | ||
111 | DSSERR("DSS not coming out of reset after sleep\n"); | ||
112 | |||
113 | RR(SYSCONFIG); | ||
114 | RR(CONTROL); | ||
115 | |||
116 | #ifdef CONFIG_OMAP2_DSS_SDI | ||
117 | RR(SDI_CONTROL); | ||
118 | RR(PLL_CONTROL); | ||
119 | #endif | ||
120 | } | ||
121 | |||
122 | #undef SR | ||
123 | #undef RR | ||
124 | |||
125 | void dss_sdi_init(u8 datapairs) | ||
126 | { | ||
127 | u32 l; | ||
128 | |||
129 | BUG_ON(datapairs > 3 || datapairs < 1); | ||
130 | |||
131 | l = dss_read_reg(DSS_SDI_CONTROL); | ||
132 | l = FLD_MOD(l, 0xf, 19, 15); /* SDI_PDIV */ | ||
133 | l = FLD_MOD(l, datapairs-1, 3, 2); /* SDI_PRSEL */ | ||
134 | l = FLD_MOD(l, 2, 1, 0); /* SDI_BWSEL */ | ||
135 | dss_write_reg(DSS_SDI_CONTROL, l); | ||
136 | |||
137 | l = dss_read_reg(DSS_PLL_CONTROL); | ||
138 | l = FLD_MOD(l, 0x7, 25, 22); /* SDI_PLL_FREQSEL */ | ||
139 | l = FLD_MOD(l, 0xb, 16, 11); /* SDI_PLL_REGN */ | ||
140 | l = FLD_MOD(l, 0xb4, 10, 1); /* SDI_PLL_REGM */ | ||
141 | dss_write_reg(DSS_PLL_CONTROL, l); | ||
142 | } | ||
143 | |||
144 | int dss_sdi_enable(void) | ||
145 | { | ||
146 | unsigned long timeout; | ||
147 | |||
148 | dispc_pck_free_enable(1); | ||
149 | |||
150 | /* Reset SDI PLL */ | ||
151 | REG_FLD_MOD(DSS_PLL_CONTROL, 1, 18, 18); /* SDI_PLL_SYSRESET */ | ||
152 | udelay(1); /* wait 2x PCLK */ | ||
153 | |||
154 | /* Lock SDI PLL */ | ||
155 | REG_FLD_MOD(DSS_PLL_CONTROL, 1, 28, 28); /* SDI_PLL_GOBIT */ | ||
156 | |||
157 | /* Waiting for PLL lock request to complete */ | ||
158 | timeout = jiffies + msecs_to_jiffies(500); | ||
159 | while (dss_read_reg(DSS_SDI_STATUS) & (1 << 6)) { | ||
160 | if (time_after_eq(jiffies, timeout)) { | ||
161 | DSSERR("PLL lock request timed out\n"); | ||
162 | goto err1; | ||
163 | } | ||
164 | } | ||
165 | |||
166 | /* Clearing PLL_GO bit */ | ||
167 | REG_FLD_MOD(DSS_PLL_CONTROL, 0, 28, 28); | ||
168 | |||
169 | /* Waiting for PLL to lock */ | ||
170 | timeout = jiffies + msecs_to_jiffies(500); | ||
171 | while (!(dss_read_reg(DSS_SDI_STATUS) & (1 << 5))) { | ||
172 | if (time_after_eq(jiffies, timeout)) { | ||
173 | DSSERR("PLL lock timed out\n"); | ||
174 | goto err1; | ||
175 | } | ||
176 | } | ||
177 | |||
178 | dispc_lcd_enable_signal(1); | ||
179 | |||
180 | /* Waiting for SDI reset to complete */ | ||
181 | timeout = jiffies + msecs_to_jiffies(500); | ||
182 | while (!(dss_read_reg(DSS_SDI_STATUS) & (1 << 2))) { | ||
183 | if (time_after_eq(jiffies, timeout)) { | ||
184 | DSSERR("SDI reset timed out\n"); | ||
185 | goto err2; | ||
186 | } | ||
187 | } | ||
188 | |||
189 | return 0; | ||
190 | |||
191 | err2: | ||
192 | dispc_lcd_enable_signal(0); | ||
193 | err1: | ||
194 | /* Reset SDI PLL */ | ||
195 | REG_FLD_MOD(DSS_PLL_CONTROL, 0, 18, 18); /* SDI_PLL_SYSRESET */ | ||
196 | |||
197 | dispc_pck_free_enable(0); | ||
198 | |||
199 | return -ETIMEDOUT; | ||
200 | } | ||
201 | |||
202 | void dss_sdi_disable(void) | ||
203 | { | ||
204 | dispc_lcd_enable_signal(0); | ||
205 | |||
206 | dispc_pck_free_enable(0); | ||
207 | |||
208 | /* Reset SDI PLL */ | ||
209 | REG_FLD_MOD(DSS_PLL_CONTROL, 0, 18, 18); /* SDI_PLL_SYSRESET */ | ||
210 | } | ||
211 | |||
212 | void dss_dump_clocks(struct seq_file *s) | ||
213 | { | ||
214 | unsigned long dpll4_ck_rate; | ||
215 | unsigned long dpll4_m4_ck_rate; | ||
216 | |||
217 | dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK1); | ||
218 | |||
219 | dpll4_ck_rate = clk_get_rate(clk_get_parent(dss.dpll4_m4_ck)); | ||
220 | dpll4_m4_ck_rate = clk_get_rate(dss.dpll4_m4_ck); | ||
221 | |||
222 | seq_printf(s, "- DSS -\n"); | ||
223 | |||
224 | seq_printf(s, "dpll4_ck %lu\n", dpll4_ck_rate); | ||
225 | |||
226 | seq_printf(s, "dss1_alwon_fclk = %lu / %lu * 2 = %lu\n", | ||
227 | dpll4_ck_rate, | ||
228 | dpll4_ck_rate / dpll4_m4_ck_rate, | ||
229 | dss_clk_get_rate(DSS_CLK_FCK1)); | ||
230 | |||
231 | dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK1); | ||
232 | } | ||
233 | |||
234 | void dss_dump_regs(struct seq_file *s) | ||
235 | { | ||
236 | #define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dss_read_reg(r)) | ||
237 | |||
238 | dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK1); | ||
239 | |||
240 | DUMPREG(DSS_REVISION); | ||
241 | DUMPREG(DSS_SYSCONFIG); | ||
242 | DUMPREG(DSS_SYSSTATUS); | ||
243 | DUMPREG(DSS_IRQSTATUS); | ||
244 | DUMPREG(DSS_CONTROL); | ||
245 | DUMPREG(DSS_SDI_CONTROL); | ||
246 | DUMPREG(DSS_PLL_CONTROL); | ||
247 | DUMPREG(DSS_SDI_STATUS); | ||
248 | |||
249 | dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK1); | ||
250 | #undef DUMPREG | ||
251 | } | ||
252 | |||
253 | void dss_select_dispc_clk_source(enum dss_clk_source clk_src) | ||
254 | { | ||
255 | int b; | ||
256 | |||
257 | BUG_ON(clk_src != DSS_SRC_DSI1_PLL_FCLK && | ||
258 | clk_src != DSS_SRC_DSS1_ALWON_FCLK); | ||
259 | |||
260 | b = clk_src == DSS_SRC_DSS1_ALWON_FCLK ? 0 : 1; | ||
261 | |||
262 | REG_FLD_MOD(DSS_CONTROL, b, 0, 0); /* DISPC_CLK_SWITCH */ | ||
263 | |||
264 | dss.dispc_clk_source = clk_src; | ||
265 | } | ||
266 | |||
267 | void dss_select_dsi_clk_source(enum dss_clk_source clk_src) | ||
268 | { | ||
269 | int b; | ||
270 | |||
271 | BUG_ON(clk_src != DSS_SRC_DSI2_PLL_FCLK && | ||
272 | clk_src != DSS_SRC_DSS1_ALWON_FCLK); | ||
273 | |||
274 | b = clk_src == DSS_SRC_DSS1_ALWON_FCLK ? 0 : 1; | ||
275 | |||
276 | REG_FLD_MOD(DSS_CONTROL, b, 1, 1); /* DSI_CLK_SWITCH */ | ||
277 | |||
278 | dss.dsi_clk_source = clk_src; | ||
279 | } | ||
280 | |||
281 | enum dss_clk_source dss_get_dispc_clk_source(void) | ||
282 | { | ||
283 | return dss.dispc_clk_source; | ||
284 | } | ||
285 | |||
286 | enum dss_clk_source dss_get_dsi_clk_source(void) | ||
287 | { | ||
288 | return dss.dsi_clk_source; | ||
289 | } | ||
290 | |||
291 | /* calculate clock rates using dividers in cinfo */ | ||
292 | int dss_calc_clock_rates(struct dss_clock_info *cinfo) | ||
293 | { | ||
294 | unsigned long prate; | ||
295 | |||
296 | if (cinfo->fck_div > 16 || cinfo->fck_div == 0) | ||
297 | return -EINVAL; | ||
298 | |||
299 | prate = clk_get_rate(clk_get_parent(dss.dpll4_m4_ck)); | ||
300 | |||
301 | cinfo->fck = prate / cinfo->fck_div; | ||
302 | |||
303 | return 0; | ||
304 | } | ||
305 | |||
306 | int dss_set_clock_div(struct dss_clock_info *cinfo) | ||
307 | { | ||
308 | unsigned long prate; | ||
309 | int r; | ||
310 | |||
311 | if (cpu_is_omap34xx()) { | ||
312 | prate = clk_get_rate(clk_get_parent(dss.dpll4_m4_ck)); | ||
313 | DSSDBG("dpll4_m4 = %ld\n", prate); | ||
314 | |||
315 | r = clk_set_rate(dss.dpll4_m4_ck, prate / cinfo->fck_div); | ||
316 | if (r) | ||
317 | return r; | ||
318 | } | ||
319 | |||
320 | DSSDBG("fck = %ld (%d)\n", cinfo->fck, cinfo->fck_div); | ||
321 | |||
322 | return 0; | ||
323 | } | ||
324 | |||
325 | int dss_get_clock_div(struct dss_clock_info *cinfo) | ||
326 | { | ||
327 | cinfo->fck = dss_clk_get_rate(DSS_CLK_FCK1); | ||
328 | |||
329 | if (cpu_is_omap34xx()) { | ||
330 | unsigned long prate; | ||
331 | prate = clk_get_rate(clk_get_parent(dss.dpll4_m4_ck)); | ||
332 | cinfo->fck_div = prate / (cinfo->fck / 2); | ||
333 | } else { | ||
334 | cinfo->fck_div = 0; | ||
335 | } | ||
336 | |||
337 | return 0; | ||
338 | } | ||
339 | |||
340 | unsigned long dss_get_dpll4_rate(void) | ||
341 | { | ||
342 | if (cpu_is_omap34xx()) | ||
343 | return clk_get_rate(clk_get_parent(dss.dpll4_m4_ck)); | ||
344 | else | ||
345 | return 0; | ||
346 | } | ||
347 | |||
348 | int dss_calc_clock_div(bool is_tft, unsigned long req_pck, | ||
349 | struct dss_clock_info *dss_cinfo, | ||
350 | struct dispc_clock_info *dispc_cinfo) | ||
351 | { | ||
352 | unsigned long prate; | ||
353 | struct dss_clock_info best_dss; | ||
354 | struct dispc_clock_info best_dispc; | ||
355 | |||
356 | unsigned long fck; | ||
357 | |||
358 | u16 fck_div; | ||
359 | |||
360 | int match = 0; | ||
361 | int min_fck_per_pck; | ||
362 | |||
363 | prate = dss_get_dpll4_rate(); | ||
364 | |||
365 | fck = dss_clk_get_rate(DSS_CLK_FCK1); | ||
366 | if (req_pck == dss.cache_req_pck && | ||
367 | ((cpu_is_omap34xx() && prate == dss.cache_prate) || | ||
368 | dss.cache_dss_cinfo.fck == fck)) { | ||
369 | DSSDBG("dispc clock info found from cache.\n"); | ||
370 | *dss_cinfo = dss.cache_dss_cinfo; | ||
371 | *dispc_cinfo = dss.cache_dispc_cinfo; | ||
372 | return 0; | ||
373 | } | ||
374 | |||
375 | min_fck_per_pck = CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK; | ||
376 | |||
377 | if (min_fck_per_pck && | ||
378 | req_pck * min_fck_per_pck > DISPC_MAX_FCK) { | ||
379 | DSSERR("Requested pixel clock not possible with the current " | ||
380 | "OMAP2_DSS_MIN_FCK_PER_PCK setting. Turning " | ||
381 | "the constraint off.\n"); | ||
382 | min_fck_per_pck = 0; | ||
383 | } | ||
384 | |||
385 | retry: | ||
386 | memset(&best_dss, 0, sizeof(best_dss)); | ||
387 | memset(&best_dispc, 0, sizeof(best_dispc)); | ||
388 | |||
389 | if (cpu_is_omap24xx()) { | ||
390 | struct dispc_clock_info cur_dispc; | ||
391 | /* XXX can we change the clock on omap2? */ | ||
392 | fck = dss_clk_get_rate(DSS_CLK_FCK1); | ||
393 | fck_div = 1; | ||
394 | |||
395 | dispc_find_clk_divs(is_tft, req_pck, fck, &cur_dispc); | ||
396 | match = 1; | ||
397 | |||
398 | best_dss.fck = fck; | ||
399 | best_dss.fck_div = fck_div; | ||
400 | |||
401 | best_dispc = cur_dispc; | ||
402 | |||
403 | goto found; | ||
404 | } else if (cpu_is_omap34xx()) { | ||
405 | for (fck_div = 16; fck_div > 0; --fck_div) { | ||
406 | struct dispc_clock_info cur_dispc; | ||
407 | |||
408 | fck = prate / fck_div * 2; | ||
409 | |||
410 | if (fck > DISPC_MAX_FCK) | ||
411 | continue; | ||
412 | |||
413 | if (min_fck_per_pck && | ||
414 | fck < req_pck * min_fck_per_pck) | ||
415 | continue; | ||
416 | |||
417 | match = 1; | ||
418 | |||
419 | dispc_find_clk_divs(is_tft, req_pck, fck, &cur_dispc); | ||
420 | |||
421 | if (abs(cur_dispc.pck - req_pck) < | ||
422 | abs(best_dispc.pck - req_pck)) { | ||
423 | |||
424 | best_dss.fck = fck; | ||
425 | best_dss.fck_div = fck_div; | ||
426 | |||
427 | best_dispc = cur_dispc; | ||
428 | |||
429 | if (cur_dispc.pck == req_pck) | ||
430 | goto found; | ||
431 | } | ||
432 | } | ||
433 | } else { | ||
434 | BUG(); | ||
435 | } | ||
436 | |||
437 | found: | ||
438 | if (!match) { | ||
439 | if (min_fck_per_pck) { | ||
440 | DSSERR("Could not find suitable clock settings.\n" | ||
441 | "Turning FCK/PCK constraint off and" | ||
442 | "trying again.\n"); | ||
443 | min_fck_per_pck = 0; | ||
444 | goto retry; | ||
445 | } | ||
446 | |||
447 | DSSERR("Could not find suitable clock settings.\n"); | ||
448 | |||
449 | return -EINVAL; | ||
450 | } | ||
451 | |||
452 | if (dss_cinfo) | ||
453 | *dss_cinfo = best_dss; | ||
454 | if (dispc_cinfo) | ||
455 | *dispc_cinfo = best_dispc; | ||
456 | |||
457 | dss.cache_req_pck = req_pck; | ||
458 | dss.cache_prate = prate; | ||
459 | dss.cache_dss_cinfo = best_dss; | ||
460 | dss.cache_dispc_cinfo = best_dispc; | ||
461 | |||
462 | return 0; | ||
463 | } | ||
464 | |||
465 | |||
466 | |||
467 | static irqreturn_t dss_irq_handler_omap2(int irq, void *arg) | ||
468 | { | ||
469 | dispc_irq_handler(); | ||
470 | |||
471 | return IRQ_HANDLED; | ||
472 | } | ||
473 | |||
474 | static irqreturn_t dss_irq_handler_omap3(int irq, void *arg) | ||
475 | { | ||
476 | u32 irqstatus; | ||
477 | |||
478 | irqstatus = dss_read_reg(DSS_IRQSTATUS); | ||
479 | |||
480 | if (irqstatus & (1<<0)) /* DISPC_IRQ */ | ||
481 | dispc_irq_handler(); | ||
482 | #ifdef CONFIG_OMAP2_DSS_DSI | ||
483 | if (irqstatus & (1<<1)) /* DSI_IRQ */ | ||
484 | dsi_irq_handler(); | ||
485 | #endif | ||
486 | |||
487 | return IRQ_HANDLED; | ||
488 | } | ||
489 | |||
490 | static int _omap_dss_wait_reset(void) | ||
491 | { | ||
492 | int t = 0; | ||
493 | |||
494 | while (REG_GET(DSS_SYSSTATUS, 0, 0) == 0) { | ||
495 | if (++t > 1000) { | ||
496 | DSSERR("soft reset failed\n"); | ||
497 | return -ENODEV; | ||
498 | } | ||
499 | udelay(1); | ||
500 | } | ||
501 | |||
502 | return 0; | ||
503 | } | ||
504 | |||
505 | static int _omap_dss_reset(void) | ||
506 | { | ||
507 | /* Soft reset */ | ||
508 | REG_FLD_MOD(DSS_SYSCONFIG, 1, 1, 1); | ||
509 | return _omap_dss_wait_reset(); | ||
510 | } | ||
511 | |||
512 | void dss_set_venc_output(enum omap_dss_venc_type type) | ||
513 | { | ||
514 | int l = 0; | ||
515 | |||
516 | if (type == OMAP_DSS_VENC_TYPE_COMPOSITE) | ||
517 | l = 0; | ||
518 | else if (type == OMAP_DSS_VENC_TYPE_SVIDEO) | ||
519 | l = 1; | ||
520 | else | ||
521 | BUG(); | ||
522 | |||
523 | /* venc out selection. 0 = comp, 1 = svideo */ | ||
524 | REG_FLD_MOD(DSS_CONTROL, l, 6, 6); | ||
525 | } | ||
526 | |||
527 | void dss_set_dac_pwrdn_bgz(bool enable) | ||
528 | { | ||
529 | REG_FLD_MOD(DSS_CONTROL, enable, 5, 5); /* DAC Power-Down Control */ | ||
530 | } | ||
531 | |||
532 | int dss_init(bool skip_init) | ||
533 | { | ||
534 | int r; | ||
535 | u32 rev; | ||
536 | |||
537 | dss.base = ioremap(DSS_BASE, DSS_SZ_REGS); | ||
538 | if (!dss.base) { | ||
539 | DSSERR("can't ioremap DSS\n"); | ||
540 | r = -ENOMEM; | ||
541 | goto fail0; | ||
542 | } | ||
543 | |||
544 | if (!skip_init) { | ||
545 | /* disable LCD and DIGIT output. This seems to fix the synclost | ||
546 | * problem that we get, if the bootloader starts the DSS and | ||
547 | * the kernel resets it */ | ||
548 | omap_writel(omap_readl(0x48050440) & ~0x3, 0x48050440); | ||
549 | |||
550 | /* We need to wait here a bit, otherwise we sometimes start to | ||
551 | * get synclost errors, and after that only power cycle will | ||
552 | * restore DSS functionality. I have no idea why this happens. | ||
553 | * And we have to wait _before_ resetting the DSS, but after | ||
554 | * enabling clocks. | ||
555 | */ | ||
556 | msleep(50); | ||
557 | |||
558 | _omap_dss_reset(); | ||
559 | } | ||
560 | |||
561 | /* autoidle */ | ||
562 | REG_FLD_MOD(DSS_SYSCONFIG, 1, 0, 0); | ||
563 | |||
564 | /* Select DPLL */ | ||
565 | REG_FLD_MOD(DSS_CONTROL, 0, 0, 0); | ||
566 | |||
567 | #ifdef CONFIG_OMAP2_DSS_VENC | ||
568 | REG_FLD_MOD(DSS_CONTROL, 1, 4, 4); /* venc dac demen */ | ||
569 | REG_FLD_MOD(DSS_CONTROL, 1, 3, 3); /* venc clock 4x enable */ | ||
570 | REG_FLD_MOD(DSS_CONTROL, 0, 2, 2); /* venc clock mode = normal */ | ||
571 | #endif | ||
572 | |||
573 | r = request_irq(INT_24XX_DSS_IRQ, | ||
574 | cpu_is_omap24xx() | ||
575 | ? dss_irq_handler_omap2 | ||
576 | : dss_irq_handler_omap3, | ||
577 | 0, "OMAP DSS", NULL); | ||
578 | |||
579 | if (r < 0) { | ||
580 | DSSERR("omap2 dss: request_irq failed\n"); | ||
581 | goto fail1; | ||
582 | } | ||
583 | |||
584 | if (cpu_is_omap34xx()) { | ||
585 | dss.dpll4_m4_ck = clk_get(NULL, "dpll4_m4_ck"); | ||
586 | if (IS_ERR(dss.dpll4_m4_ck)) { | ||
587 | DSSERR("Failed to get dpll4_m4_ck\n"); | ||
588 | r = PTR_ERR(dss.dpll4_m4_ck); | ||
589 | goto fail2; | ||
590 | } | ||
591 | } | ||
592 | |||
593 | dss.dsi_clk_source = DSS_SRC_DSS1_ALWON_FCLK; | ||
594 | dss.dispc_clk_source = DSS_SRC_DSS1_ALWON_FCLK; | ||
595 | |||
596 | dss_save_context(); | ||
597 | |||
598 | rev = dss_read_reg(DSS_REVISION); | ||
599 | printk(KERN_INFO "OMAP DSS rev %d.%d\n", | ||
600 | FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0)); | ||
601 | |||
602 | return 0; | ||
603 | |||
604 | fail2: | ||
605 | free_irq(INT_24XX_DSS_IRQ, NULL); | ||
606 | fail1: | ||
607 | iounmap(dss.base); | ||
608 | fail0: | ||
609 | return r; | ||
610 | } | ||
611 | |||
612 | void dss_exit(void) | ||
613 | { | ||
614 | if (cpu_is_omap34xx()) | ||
615 | clk_put(dss.dpll4_m4_ck); | ||
616 | |||
617 | free_irq(INT_24XX_DSS_IRQ, NULL); | ||
618 | |||
619 | iounmap(dss.base); | ||
620 | } | ||
621 | |||