blob: 131bd53b6b6d287e19f589f76632f67ba1692722 [file] [log] [blame]
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001/*
2 * linux/drivers/video/omap2/dss/dsi.c
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published by
9 * the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#define DSS_SUBSYS_NAME "DSI"
21
22#include <linux/kernel.h>
23#include <linux/io.h>
24#include <linux/clk.h>
25#include <linux/device.h>
26#include <linux/err.h>
27#include <linux/interrupt.h>
28#include <linux/delay.h>
29#include <linux/mutex.h>
30#include <linux/seq_file.h>
31#include <linux/platform_device.h>
32#include <linux/regulator/consumer.h>
33#include <linux/kthread.h>
34#include <linux/wait.h>
35
36#include <plat/display.h>
37#include <plat/clock.h>
38
39#include "dss.h"
40
41/*#define VERBOSE_IRQ*/
42#define DSI_CATCH_MISSING_TE
43
44#define DSI_BASE 0x4804FC00
45
46struct dsi_reg { u16 idx; };
47
48#define DSI_REG(idx) ((const struct dsi_reg) { idx })
49
50#define DSI_SZ_REGS SZ_1K
51/* DSI Protocol Engine */
52
53#define DSI_REVISION DSI_REG(0x0000)
54#define DSI_SYSCONFIG DSI_REG(0x0010)
55#define DSI_SYSSTATUS DSI_REG(0x0014)
56#define DSI_IRQSTATUS DSI_REG(0x0018)
57#define DSI_IRQENABLE DSI_REG(0x001C)
58#define DSI_CTRL DSI_REG(0x0040)
59#define DSI_COMPLEXIO_CFG1 DSI_REG(0x0048)
60#define DSI_COMPLEXIO_IRQ_STATUS DSI_REG(0x004C)
61#define DSI_COMPLEXIO_IRQ_ENABLE DSI_REG(0x0050)
62#define DSI_CLK_CTRL DSI_REG(0x0054)
63#define DSI_TIMING1 DSI_REG(0x0058)
64#define DSI_TIMING2 DSI_REG(0x005C)
65#define DSI_VM_TIMING1 DSI_REG(0x0060)
66#define DSI_VM_TIMING2 DSI_REG(0x0064)
67#define DSI_VM_TIMING3 DSI_REG(0x0068)
68#define DSI_CLK_TIMING DSI_REG(0x006C)
69#define DSI_TX_FIFO_VC_SIZE DSI_REG(0x0070)
70#define DSI_RX_FIFO_VC_SIZE DSI_REG(0x0074)
71#define DSI_COMPLEXIO_CFG2 DSI_REG(0x0078)
72#define DSI_RX_FIFO_VC_FULLNESS DSI_REG(0x007C)
73#define DSI_VM_TIMING4 DSI_REG(0x0080)
74#define DSI_TX_FIFO_VC_EMPTINESS DSI_REG(0x0084)
75#define DSI_VM_TIMING5 DSI_REG(0x0088)
76#define DSI_VM_TIMING6 DSI_REG(0x008C)
77#define DSI_VM_TIMING7 DSI_REG(0x0090)
78#define DSI_STOPCLK_TIMING DSI_REG(0x0094)
79#define DSI_VC_CTRL(n) DSI_REG(0x0100 + (n * 0x20))
80#define DSI_VC_TE(n) DSI_REG(0x0104 + (n * 0x20))
81#define DSI_VC_LONG_PACKET_HEADER(n) DSI_REG(0x0108 + (n * 0x20))
82#define DSI_VC_LONG_PACKET_PAYLOAD(n) DSI_REG(0x010C + (n * 0x20))
83#define DSI_VC_SHORT_PACKET_HEADER(n) DSI_REG(0x0110 + (n * 0x20))
84#define DSI_VC_IRQSTATUS(n) DSI_REG(0x0118 + (n * 0x20))
85#define DSI_VC_IRQENABLE(n) DSI_REG(0x011C + (n * 0x20))
86
87/* DSIPHY_SCP */
88
89#define DSI_DSIPHY_CFG0 DSI_REG(0x200 + 0x0000)
90#define DSI_DSIPHY_CFG1 DSI_REG(0x200 + 0x0004)
91#define DSI_DSIPHY_CFG2 DSI_REG(0x200 + 0x0008)
92#define DSI_DSIPHY_CFG5 DSI_REG(0x200 + 0x0014)
93
94/* DSI_PLL_CTRL_SCP */
95
96#define DSI_PLL_CONTROL DSI_REG(0x300 + 0x0000)
97#define DSI_PLL_STATUS DSI_REG(0x300 + 0x0004)
98#define DSI_PLL_GO DSI_REG(0x300 + 0x0008)
99#define DSI_PLL_CONFIGURATION1 DSI_REG(0x300 + 0x000C)
100#define DSI_PLL_CONFIGURATION2 DSI_REG(0x300 + 0x0010)
101
102#define REG_GET(idx, start, end) \
103 FLD_GET(dsi_read_reg(idx), start, end)
104
105#define REG_FLD_MOD(idx, val, start, end) \
106 dsi_write_reg(idx, FLD_MOD(dsi_read_reg(idx), val, start, end))
107
108/* Global interrupts */
109#define DSI_IRQ_VC0 (1 << 0)
110#define DSI_IRQ_VC1 (1 << 1)
111#define DSI_IRQ_VC2 (1 << 2)
112#define DSI_IRQ_VC3 (1 << 3)
113#define DSI_IRQ_WAKEUP (1 << 4)
114#define DSI_IRQ_RESYNC (1 << 5)
115#define DSI_IRQ_PLL_LOCK (1 << 7)
116#define DSI_IRQ_PLL_UNLOCK (1 << 8)
117#define DSI_IRQ_PLL_RECALL (1 << 9)
118#define DSI_IRQ_COMPLEXIO_ERR (1 << 10)
119#define DSI_IRQ_HS_TX_TIMEOUT (1 << 14)
120#define DSI_IRQ_LP_RX_TIMEOUT (1 << 15)
121#define DSI_IRQ_TE_TRIGGER (1 << 16)
122#define DSI_IRQ_ACK_TRIGGER (1 << 17)
123#define DSI_IRQ_SYNC_LOST (1 << 18)
124#define DSI_IRQ_LDO_POWER_GOOD (1 << 19)
125#define DSI_IRQ_TA_TIMEOUT (1 << 20)
126#define DSI_IRQ_ERROR_MASK \
127 (DSI_IRQ_HS_TX_TIMEOUT | DSI_IRQ_LP_RX_TIMEOUT | DSI_IRQ_SYNC_LOST | \
128 DSI_IRQ_TA_TIMEOUT)
129#define DSI_IRQ_CHANNEL_MASK 0xf
130
131/* Virtual channel interrupts */
132#define DSI_VC_IRQ_CS (1 << 0)
133#define DSI_VC_IRQ_ECC_CORR (1 << 1)
134#define DSI_VC_IRQ_PACKET_SENT (1 << 2)
135#define DSI_VC_IRQ_FIFO_TX_OVF (1 << 3)
136#define DSI_VC_IRQ_FIFO_RX_OVF (1 << 4)
137#define DSI_VC_IRQ_BTA (1 << 5)
138#define DSI_VC_IRQ_ECC_NO_CORR (1 << 6)
139#define DSI_VC_IRQ_FIFO_TX_UDF (1 << 7)
140#define DSI_VC_IRQ_PP_BUSY_CHANGE (1 << 8)
141#define DSI_VC_IRQ_ERROR_MASK \
142 (DSI_VC_IRQ_CS | DSI_VC_IRQ_ECC_CORR | DSI_VC_IRQ_FIFO_TX_OVF | \
143 DSI_VC_IRQ_FIFO_RX_OVF | DSI_VC_IRQ_ECC_NO_CORR | \
144 DSI_VC_IRQ_FIFO_TX_UDF)
145
146/* ComplexIO interrupts */
147#define DSI_CIO_IRQ_ERRSYNCESC1 (1 << 0)
148#define DSI_CIO_IRQ_ERRSYNCESC2 (1 << 1)
149#define DSI_CIO_IRQ_ERRSYNCESC3 (1 << 2)
150#define DSI_CIO_IRQ_ERRESC1 (1 << 5)
151#define DSI_CIO_IRQ_ERRESC2 (1 << 6)
152#define DSI_CIO_IRQ_ERRESC3 (1 << 7)
153#define DSI_CIO_IRQ_ERRCONTROL1 (1 << 10)
154#define DSI_CIO_IRQ_ERRCONTROL2 (1 << 11)
155#define DSI_CIO_IRQ_ERRCONTROL3 (1 << 12)
156#define DSI_CIO_IRQ_STATEULPS1 (1 << 15)
157#define DSI_CIO_IRQ_STATEULPS2 (1 << 16)
158#define DSI_CIO_IRQ_STATEULPS3 (1 << 17)
159#define DSI_CIO_IRQ_ERRCONTENTIONLP0_1 (1 << 20)
160#define DSI_CIO_IRQ_ERRCONTENTIONLP1_1 (1 << 21)
161#define DSI_CIO_IRQ_ERRCONTENTIONLP0_2 (1 << 22)
162#define DSI_CIO_IRQ_ERRCONTENTIONLP1_2 (1 << 23)
163#define DSI_CIO_IRQ_ERRCONTENTIONLP0_3 (1 << 24)
164#define DSI_CIO_IRQ_ERRCONTENTIONLP1_3 (1 << 25)
165#define DSI_CIO_IRQ_ULPSACTIVENOT_ALL0 (1 << 30)
166#define DSI_CIO_IRQ_ULPSACTIVENOT_ALL1 (1 << 31)
167
168#define DSI_DT_DCS_SHORT_WRITE_0 0x05
169#define DSI_DT_DCS_SHORT_WRITE_1 0x15
170#define DSI_DT_DCS_READ 0x06
171#define DSI_DT_SET_MAX_RET_PKG_SIZE 0x37
172#define DSI_DT_NULL_PACKET 0x09
173#define DSI_DT_DCS_LONG_WRITE 0x39
174
175#define DSI_DT_RX_ACK_WITH_ERR 0x02
176#define DSI_DT_RX_DCS_LONG_READ 0x1c
177#define DSI_DT_RX_SHORT_READ_1 0x21
178#define DSI_DT_RX_SHORT_READ_2 0x22
179
180#define FINT_MAX 2100000
181#define FINT_MIN 750000
182#define REGN_MAX (1 << 7)
183#define REGM_MAX ((1 << 11) - 1)
184#define REGM3_MAX (1 << 4)
185#define REGM4_MAX (1 << 4)
186#define LP_DIV_MAX ((1 << 13) - 1)
187
188enum fifo_size {
189 DSI_FIFO_SIZE_0 = 0,
190 DSI_FIFO_SIZE_32 = 1,
191 DSI_FIFO_SIZE_64 = 2,
192 DSI_FIFO_SIZE_96 = 3,
193 DSI_FIFO_SIZE_128 = 4,
194};
195
196enum dsi_vc_mode {
197 DSI_VC_MODE_L4 = 0,
198 DSI_VC_MODE_VP,
199};
200
201struct dsi_update_region {
202 bool dirty;
203 u16 x, y, w, h;
204 struct omap_dss_device *device;
205};
206
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200207struct dsi_irq_stats {
208 unsigned long last_reset;
209 unsigned irq_count;
210 unsigned dsi_irqs[32];
211 unsigned vc_irqs[4][32];
212 unsigned cio_irqs[32];
213};
214
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200215static struct
216{
217 void __iomem *base;
218
219 struct dsi_clock_info current_cinfo;
220
221 struct regulator *vdds_dsi_reg;
222
223 struct {
224 enum dsi_vc_mode mode;
225 struct omap_dss_device *dssdev;
226 enum fifo_size fifo_size;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200227 } vc[4];
228
229 struct mutex lock;
230 struct mutex bus_lock;
231
232 unsigned pll_locked;
233
234 struct completion bta_completion;
235
236 struct task_struct *thread;
237 wait_queue_head_t waitqueue;
238
239 spinlock_t update_lock;
240 bool framedone_received;
241 struct dsi_update_region update_region;
242 struct dsi_update_region active_update_region;
243 struct completion update_completion;
244
245 enum omap_dss_update_mode user_update_mode;
246 enum omap_dss_update_mode update_mode;
247 bool te_enabled;
248 bool use_ext_te;
249
250#ifdef DSI_CATCH_MISSING_TE
251 struct timer_list te_timer;
252#endif
253
254 unsigned long cache_req_pck;
255 unsigned long cache_clk_freq;
256 struct dsi_clock_info cache_cinfo;
257
258 u32 errors;
259 spinlock_t errors_lock;
260#ifdef DEBUG
261 ktime_t perf_setup_time;
262 ktime_t perf_start_time;
263 ktime_t perf_start_time_auto;
264 int perf_measure_frames;
265#endif
266 int debug_read;
267 int debug_write;
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200268
269#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
270 spinlock_t irq_stats_lock;
271 struct dsi_irq_stats irq_stats;
272#endif
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200273} dsi;
274
275#ifdef DEBUG
276static unsigned int dsi_perf;
277module_param_named(dsi_perf, dsi_perf, bool, 0644);
278#endif
279
280static inline void dsi_write_reg(const struct dsi_reg idx, u32 val)
281{
282 __raw_writel(val, dsi.base + idx.idx);
283}
284
285static inline u32 dsi_read_reg(const struct dsi_reg idx)
286{
287 return __raw_readl(dsi.base + idx.idx);
288}
289
290
291void dsi_save_context(void)
292{
293}
294
295void dsi_restore_context(void)
296{
297}
298
299void dsi_bus_lock(void)
300{
301 mutex_lock(&dsi.bus_lock);
302}
303EXPORT_SYMBOL(dsi_bus_lock);
304
305void dsi_bus_unlock(void)
306{
307 mutex_unlock(&dsi.bus_lock);
308}
309EXPORT_SYMBOL(dsi_bus_unlock);
310
Tomi Valkeinen4f765022010-01-18 16:27:52 +0200311static bool dsi_bus_is_locked(void)
312{
313 return mutex_is_locked(&dsi.bus_lock);
314}
315
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200316static inline int wait_for_bit_change(const struct dsi_reg idx, int bitnum,
317 int value)
318{
319 int t = 100000;
320
321 while (REG_GET(idx, bitnum, bitnum) != value) {
322 if (--t == 0)
323 return !value;
324 }
325
326 return value;
327}
328
329#ifdef DEBUG
330static void dsi_perf_mark_setup(void)
331{
332 dsi.perf_setup_time = ktime_get();
333}
334
335static void dsi_perf_mark_start(void)
336{
337 dsi.perf_start_time = ktime_get();
338}
339
340static void dsi_perf_mark_start_auto(void)
341{
342 dsi.perf_measure_frames = 0;
343 dsi.perf_start_time_auto = ktime_get();
344}
345
346static void dsi_perf_show(const char *name)
347{
348 ktime_t t, setup_time, trans_time;
349 u32 total_bytes;
350 u32 setup_us, trans_us, total_us;
351
352 if (!dsi_perf)
353 return;
354
355 if (dsi.update_mode == OMAP_DSS_UPDATE_DISABLED)
356 return;
357
358 t = ktime_get();
359
360 setup_time = ktime_sub(dsi.perf_start_time, dsi.perf_setup_time);
361 setup_us = (u32)ktime_to_us(setup_time);
362 if (setup_us == 0)
363 setup_us = 1;
364
365 trans_time = ktime_sub(t, dsi.perf_start_time);
366 trans_us = (u32)ktime_to_us(trans_time);
367 if (trans_us == 0)
368 trans_us = 1;
369
370 total_us = setup_us + trans_us;
371
372 total_bytes = dsi.active_update_region.w *
373 dsi.active_update_region.h *
374 dsi.active_update_region.device->ctrl.pixel_size / 8;
375
376 if (dsi.update_mode == OMAP_DSS_UPDATE_AUTO) {
377 static u32 s_total_trans_us, s_total_setup_us;
378 static u32 s_min_trans_us = 0xffffffff, s_min_setup_us;
379 static u32 s_max_trans_us, s_max_setup_us;
380 const int numframes = 100;
381 ktime_t total_time_auto;
382 u32 total_time_auto_us;
383
384 dsi.perf_measure_frames++;
385
386 if (setup_us < s_min_setup_us)
387 s_min_setup_us = setup_us;
388
389 if (setup_us > s_max_setup_us)
390 s_max_setup_us = setup_us;
391
392 s_total_setup_us += setup_us;
393
394 if (trans_us < s_min_trans_us)
395 s_min_trans_us = trans_us;
396
397 if (trans_us > s_max_trans_us)
398 s_max_trans_us = trans_us;
399
400 s_total_trans_us += trans_us;
401
402 if (dsi.perf_measure_frames < numframes)
403 return;
404
405 total_time_auto = ktime_sub(t, dsi.perf_start_time_auto);
406 total_time_auto_us = (u32)ktime_to_us(total_time_auto);
407
408 printk(KERN_INFO "DSI(%s): %u fps, setup %u/%u/%u, "
409 "trans %u/%u/%u\n",
410 name,
411 1000 * 1000 * numframes / total_time_auto_us,
412 s_min_setup_us,
413 s_max_setup_us,
414 s_total_setup_us / numframes,
415 s_min_trans_us,
416 s_max_trans_us,
417 s_total_trans_us / numframes);
418
419 s_total_setup_us = 0;
420 s_min_setup_us = 0xffffffff;
421 s_max_setup_us = 0;
422 s_total_trans_us = 0;
423 s_min_trans_us = 0xffffffff;
424 s_max_trans_us = 0;
425 dsi_perf_mark_start_auto();
426 } else {
427 printk(KERN_INFO "DSI(%s): %u us + %u us = %u us (%uHz), "
428 "%u bytes, %u kbytes/sec\n",
429 name,
430 setup_us,
431 trans_us,
432 total_us,
433 1000*1000 / total_us,
434 total_bytes,
435 total_bytes * 1000 / total_us);
436 }
437}
438#else
439#define dsi_perf_mark_setup()
440#define dsi_perf_mark_start()
441#define dsi_perf_mark_start_auto()
442#define dsi_perf_show(x)
443#endif
444
445static void print_irq_status(u32 status)
446{
447#ifndef VERBOSE_IRQ
448 if ((status & ~DSI_IRQ_CHANNEL_MASK) == 0)
449 return;
450#endif
451 printk(KERN_DEBUG "DSI IRQ: 0x%x: ", status);
452
453#define PIS(x) \
454 if (status & DSI_IRQ_##x) \
455 printk(#x " ");
456#ifdef VERBOSE_IRQ
457 PIS(VC0);
458 PIS(VC1);
459 PIS(VC2);
460 PIS(VC3);
461#endif
462 PIS(WAKEUP);
463 PIS(RESYNC);
464 PIS(PLL_LOCK);
465 PIS(PLL_UNLOCK);
466 PIS(PLL_RECALL);
467 PIS(COMPLEXIO_ERR);
468 PIS(HS_TX_TIMEOUT);
469 PIS(LP_RX_TIMEOUT);
470 PIS(TE_TRIGGER);
471 PIS(ACK_TRIGGER);
472 PIS(SYNC_LOST);
473 PIS(LDO_POWER_GOOD);
474 PIS(TA_TIMEOUT);
475#undef PIS
476
477 printk("\n");
478}
479
480static void print_irq_status_vc(int channel, u32 status)
481{
482#ifndef VERBOSE_IRQ
483 if ((status & ~DSI_VC_IRQ_PACKET_SENT) == 0)
484 return;
485#endif
486 printk(KERN_DEBUG "DSI VC(%d) IRQ 0x%x: ", channel, status);
487
488#define PIS(x) \
489 if (status & DSI_VC_IRQ_##x) \
490 printk(#x " ");
491 PIS(CS);
492 PIS(ECC_CORR);
493#ifdef VERBOSE_IRQ
494 PIS(PACKET_SENT);
495#endif
496 PIS(FIFO_TX_OVF);
497 PIS(FIFO_RX_OVF);
498 PIS(BTA);
499 PIS(ECC_NO_CORR);
500 PIS(FIFO_TX_UDF);
501 PIS(PP_BUSY_CHANGE);
502#undef PIS
503 printk("\n");
504}
505
506static void print_irq_status_cio(u32 status)
507{
508 printk(KERN_DEBUG "DSI CIO IRQ 0x%x: ", status);
509
510#define PIS(x) \
511 if (status & DSI_CIO_IRQ_##x) \
512 printk(#x " ");
513 PIS(ERRSYNCESC1);
514 PIS(ERRSYNCESC2);
515 PIS(ERRSYNCESC3);
516 PIS(ERRESC1);
517 PIS(ERRESC2);
518 PIS(ERRESC3);
519 PIS(ERRCONTROL1);
520 PIS(ERRCONTROL2);
521 PIS(ERRCONTROL3);
522 PIS(STATEULPS1);
523 PIS(STATEULPS2);
524 PIS(STATEULPS3);
525 PIS(ERRCONTENTIONLP0_1);
526 PIS(ERRCONTENTIONLP1_1);
527 PIS(ERRCONTENTIONLP0_2);
528 PIS(ERRCONTENTIONLP1_2);
529 PIS(ERRCONTENTIONLP0_3);
530 PIS(ERRCONTENTIONLP1_3);
531 PIS(ULPSACTIVENOT_ALL0);
532 PIS(ULPSACTIVENOT_ALL1);
533#undef PIS
534
535 printk("\n");
536}
537
538static int debug_irq;
539
540/* called from dss */
541void dsi_irq_handler(void)
542{
543 u32 irqstatus, vcstatus, ciostatus;
544 int i;
545
546 irqstatus = dsi_read_reg(DSI_IRQSTATUS);
547
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200548#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
549 spin_lock(&dsi.irq_stats_lock);
550 dsi.irq_stats.irq_count++;
551 dss_collect_irq_stats(irqstatus, dsi.irq_stats.dsi_irqs);
552#endif
553
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200554 if (irqstatus & DSI_IRQ_ERROR_MASK) {
555 DSSERR("DSI error, irqstatus %x\n", irqstatus);
556 print_irq_status(irqstatus);
557 spin_lock(&dsi.errors_lock);
558 dsi.errors |= irqstatus & DSI_IRQ_ERROR_MASK;
559 spin_unlock(&dsi.errors_lock);
560 } else if (debug_irq) {
561 print_irq_status(irqstatus);
562 }
563
564#ifdef DSI_CATCH_MISSING_TE
565 if (irqstatus & DSI_IRQ_TE_TRIGGER)
566 del_timer(&dsi.te_timer);
567#endif
568
569 for (i = 0; i < 4; ++i) {
570 if ((irqstatus & (1<<i)) == 0)
571 continue;
572
573 vcstatus = dsi_read_reg(DSI_VC_IRQSTATUS(i));
574
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200575#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
576 dss_collect_irq_stats(vcstatus, dsi.irq_stats.vc_irqs[i]);
577#endif
578
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200579 if (vcstatus & DSI_VC_IRQ_BTA)
580 complete(&dsi.bta_completion);
581
582 if (vcstatus & DSI_VC_IRQ_ERROR_MASK) {
583 DSSERR("DSI VC(%d) error, vc irqstatus %x\n",
584 i, vcstatus);
585 print_irq_status_vc(i, vcstatus);
586 } else if (debug_irq) {
587 print_irq_status_vc(i, vcstatus);
588 }
589
590 dsi_write_reg(DSI_VC_IRQSTATUS(i), vcstatus);
591 /* flush posted write */
592 dsi_read_reg(DSI_VC_IRQSTATUS(i));
593 }
594
595 if (irqstatus & DSI_IRQ_COMPLEXIO_ERR) {
596 ciostatus = dsi_read_reg(DSI_COMPLEXIO_IRQ_STATUS);
597
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200598#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
599 dss_collect_irq_stats(ciostatus, dsi.irq_stats.cio_irqs);
600#endif
601
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200602 dsi_write_reg(DSI_COMPLEXIO_IRQ_STATUS, ciostatus);
603 /* flush posted write */
604 dsi_read_reg(DSI_COMPLEXIO_IRQ_STATUS);
605
606 DSSERR("DSI CIO error, cio irqstatus %x\n", ciostatus);
607 print_irq_status_cio(ciostatus);
608 }
609
610 dsi_write_reg(DSI_IRQSTATUS, irqstatus & ~DSI_IRQ_CHANNEL_MASK);
611 /* flush posted write */
612 dsi_read_reg(DSI_IRQSTATUS);
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200613
614#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
615 spin_unlock(&dsi.irq_stats_lock);
616#endif
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200617}
618
619
620static void _dsi_initialize_irq(void)
621{
622 u32 l;
623 int i;
624
625 /* disable all interrupts */
626 dsi_write_reg(DSI_IRQENABLE, 0);
627 for (i = 0; i < 4; ++i)
628 dsi_write_reg(DSI_VC_IRQENABLE(i), 0);
629 dsi_write_reg(DSI_COMPLEXIO_IRQ_ENABLE, 0);
630
631 /* clear interrupt status */
632 l = dsi_read_reg(DSI_IRQSTATUS);
633 dsi_write_reg(DSI_IRQSTATUS, l & ~DSI_IRQ_CHANNEL_MASK);
634
635 for (i = 0; i < 4; ++i) {
636 l = dsi_read_reg(DSI_VC_IRQSTATUS(i));
637 dsi_write_reg(DSI_VC_IRQSTATUS(i), l);
638 }
639
640 l = dsi_read_reg(DSI_COMPLEXIO_IRQ_STATUS);
641 dsi_write_reg(DSI_COMPLEXIO_IRQ_STATUS, l);
642
643 /* enable error irqs */
644 l = DSI_IRQ_ERROR_MASK;
645#ifdef DSI_CATCH_MISSING_TE
646 l |= DSI_IRQ_TE_TRIGGER;
647#endif
648 dsi_write_reg(DSI_IRQENABLE, l);
649
650 l = DSI_VC_IRQ_ERROR_MASK;
651 for (i = 0; i < 4; ++i)
652 dsi_write_reg(DSI_VC_IRQENABLE(i), l);
653
654 /* XXX zonda responds incorrectly, causing control error:
655 Exit from LP-ESC mode to LP11 uses wrong transition states on the
656 data lines LP0 and LN0. */
657 dsi_write_reg(DSI_COMPLEXIO_IRQ_ENABLE,
658 -1 & (~DSI_CIO_IRQ_ERRCONTROL2));
659}
660
661static u32 dsi_get_errors(void)
662{
663 unsigned long flags;
664 u32 e;
665 spin_lock_irqsave(&dsi.errors_lock, flags);
666 e = dsi.errors;
667 dsi.errors = 0;
668 spin_unlock_irqrestore(&dsi.errors_lock, flags);
669 return e;
670}
671
672static void dsi_vc_enable_bta_irq(int channel)
673{
674 u32 l;
675
676 dsi_write_reg(DSI_VC_IRQSTATUS(channel), DSI_VC_IRQ_BTA);
677
678 l = dsi_read_reg(DSI_VC_IRQENABLE(channel));
679 l |= DSI_VC_IRQ_BTA;
680 dsi_write_reg(DSI_VC_IRQENABLE(channel), l);
681}
682
683static void dsi_vc_disable_bta_irq(int channel)
684{
685 u32 l;
686
687 l = dsi_read_reg(DSI_VC_IRQENABLE(channel));
688 l &= ~DSI_VC_IRQ_BTA;
689 dsi_write_reg(DSI_VC_IRQENABLE(channel), l);
690}
691
692/* DSI func clock. this could also be DSI2_PLL_FCLK */
693static inline void enable_clocks(bool enable)
694{
695 if (enable)
696 dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK1);
697 else
698 dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK1);
699}
700
701/* source clock for DSI PLL. this could also be PCLKFREE */
702static inline void dsi_enable_pll_clock(bool enable)
703{
704 if (enable)
705 dss_clk_enable(DSS_CLK_FCK2);
706 else
707 dss_clk_disable(DSS_CLK_FCK2);
708
709 if (enable && dsi.pll_locked) {
710 if (wait_for_bit_change(DSI_PLL_STATUS, 1, 1) != 1)
711 DSSERR("cannot lock PLL when enabling clocks\n");
712 }
713}
714
715#ifdef DEBUG
716static void _dsi_print_reset_status(void)
717{
718 u32 l;
719
720 if (!dss_debug)
721 return;
722
723 /* A dummy read using the SCP interface to any DSIPHY register is
724 * required after DSIPHY reset to complete the reset of the DSI complex
725 * I/O. */
726 l = dsi_read_reg(DSI_DSIPHY_CFG5);
727
728 printk(KERN_DEBUG "DSI resets: ");
729
730 l = dsi_read_reg(DSI_PLL_STATUS);
731 printk("PLL (%d) ", FLD_GET(l, 0, 0));
732
733 l = dsi_read_reg(DSI_COMPLEXIO_CFG1);
734 printk("CIO (%d) ", FLD_GET(l, 29, 29));
735
736 l = dsi_read_reg(DSI_DSIPHY_CFG5);
737 printk("PHY (%x, %d, %d, %d)\n",
738 FLD_GET(l, 28, 26),
739 FLD_GET(l, 29, 29),
740 FLD_GET(l, 30, 30),
741 FLD_GET(l, 31, 31));
742}
743#else
744#define _dsi_print_reset_status()
745#endif
746
747static inline int dsi_if_enable(bool enable)
748{
749 DSSDBG("dsi_if_enable(%d)\n", enable);
750
751 enable = enable ? 1 : 0;
752 REG_FLD_MOD(DSI_CTRL, enable, 0, 0); /* IF_EN */
753
754 if (wait_for_bit_change(DSI_CTRL, 0, enable) != enable) {
755 DSSERR("Failed to set dsi_if_enable to %d\n", enable);
756 return -EIO;
757 }
758
759 return 0;
760}
761
762unsigned long dsi_get_dsi1_pll_rate(void)
763{
764 return dsi.current_cinfo.dsi1_pll_fclk;
765}
766
767static unsigned long dsi_get_dsi2_pll_rate(void)
768{
769 return dsi.current_cinfo.dsi2_pll_fclk;
770}
771
772static unsigned long dsi_get_txbyteclkhs(void)
773{
774 return dsi.current_cinfo.clkin4ddr / 16;
775}
776
777static unsigned long dsi_fclk_rate(void)
778{
779 unsigned long r;
780
781 if (dss_get_dsi_clk_source() == 0) {
782 /* DSI FCLK source is DSS1_ALWON_FCK, which is dss1_fck */
783 r = dss_clk_get_rate(DSS_CLK_FCK1);
784 } else {
785 /* DSI FCLK source is DSI2_PLL_FCLK */
786 r = dsi_get_dsi2_pll_rate();
787 }
788
789 return r;
790}
791
792static int dsi_set_lp_clk_divisor(struct omap_dss_device *dssdev)
793{
794 unsigned long dsi_fclk;
795 unsigned lp_clk_div;
796 unsigned long lp_clk;
797
798 lp_clk_div = dssdev->phy.dsi.div.lp_clk_div;
799
800 if (lp_clk_div == 0 || lp_clk_div > LP_DIV_MAX)
801 return -EINVAL;
802
803 dsi_fclk = dsi_fclk_rate();
804
805 lp_clk = dsi_fclk / 2 / lp_clk_div;
806
807 DSSDBG("LP_CLK_DIV %u, LP_CLK %lu\n", lp_clk_div, lp_clk);
808 dsi.current_cinfo.lp_clk = lp_clk;
809 dsi.current_cinfo.lp_clk_div = lp_clk_div;
810
811 REG_FLD_MOD(DSI_CLK_CTRL, lp_clk_div, 12, 0); /* LP_CLK_DIVISOR */
812
813 REG_FLD_MOD(DSI_CLK_CTRL, dsi_fclk > 30000000 ? 1 : 0,
814 21, 21); /* LP_RX_SYNCHRO_ENABLE */
815
816 return 0;
817}
818
819
820enum dsi_pll_power_state {
821 DSI_PLL_POWER_OFF = 0x0,
822 DSI_PLL_POWER_ON_HSCLK = 0x1,
823 DSI_PLL_POWER_ON_ALL = 0x2,
824 DSI_PLL_POWER_ON_DIV = 0x3,
825};
826
827static int dsi_pll_power(enum dsi_pll_power_state state)
828{
829 int t = 0;
830
831 REG_FLD_MOD(DSI_CLK_CTRL, state, 31, 30); /* PLL_PWR_CMD */
832
833 /* PLL_PWR_STATUS */
834 while (FLD_GET(dsi_read_reg(DSI_CLK_CTRL), 29, 28) != state) {
Tomi Valkeinen24be78b2010-01-07 14:19:48 +0200835 if (++t > 1000) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200836 DSSERR("Failed to set DSI PLL power mode to %d\n",
837 state);
838 return -ENODEV;
839 }
Tomi Valkeinen24be78b2010-01-07 14:19:48 +0200840 udelay(1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200841 }
842
843 return 0;
844}
845
846/* calculate clock rates using dividers in cinfo */
847static int dsi_calc_clock_rates(struct dsi_clock_info *cinfo)
848{
849 if (cinfo->regn == 0 || cinfo->regn > REGN_MAX)
850 return -EINVAL;
851
852 if (cinfo->regm == 0 || cinfo->regm > REGM_MAX)
853 return -EINVAL;
854
855 if (cinfo->regm3 > REGM3_MAX)
856 return -EINVAL;
857
858 if (cinfo->regm4 > REGM4_MAX)
859 return -EINVAL;
860
861 if (cinfo->use_dss2_fck) {
862 cinfo->clkin = dss_clk_get_rate(DSS_CLK_FCK2);
863 /* XXX it is unclear if highfreq should be used
864 * with DSS2_FCK source also */
865 cinfo->highfreq = 0;
866 } else {
867 cinfo->clkin = dispc_pclk_rate();
868
869 if (cinfo->clkin < 32000000)
870 cinfo->highfreq = 0;
871 else
872 cinfo->highfreq = 1;
873 }
874
875 cinfo->fint = cinfo->clkin / (cinfo->regn * (cinfo->highfreq ? 2 : 1));
876
877 if (cinfo->fint > FINT_MAX || cinfo->fint < FINT_MIN)
878 return -EINVAL;
879
880 cinfo->clkin4ddr = 2 * cinfo->regm * cinfo->fint;
881
882 if (cinfo->clkin4ddr > 1800 * 1000 * 1000)
883 return -EINVAL;
884
885 if (cinfo->regm3 > 0)
886 cinfo->dsi1_pll_fclk = cinfo->clkin4ddr / cinfo->regm3;
887 else
888 cinfo->dsi1_pll_fclk = 0;
889
890 if (cinfo->regm4 > 0)
891 cinfo->dsi2_pll_fclk = cinfo->clkin4ddr / cinfo->regm4;
892 else
893 cinfo->dsi2_pll_fclk = 0;
894
895 return 0;
896}
897
898int dsi_pll_calc_clock_div_pck(bool is_tft, unsigned long req_pck,
899 struct dsi_clock_info *dsi_cinfo,
900 struct dispc_clock_info *dispc_cinfo)
901{
902 struct dsi_clock_info cur, best;
903 struct dispc_clock_info best_dispc;
904 int min_fck_per_pck;
905 int match = 0;
906 unsigned long dss_clk_fck2;
907
908 dss_clk_fck2 = dss_clk_get_rate(DSS_CLK_FCK2);
909
910 if (req_pck == dsi.cache_req_pck &&
911 dsi.cache_cinfo.clkin == dss_clk_fck2) {
912 DSSDBG("DSI clock info found from cache\n");
913 *dsi_cinfo = dsi.cache_cinfo;
914 dispc_find_clk_divs(is_tft, req_pck, dsi_cinfo->dsi1_pll_fclk,
915 dispc_cinfo);
916 return 0;
917 }
918
919 min_fck_per_pck = CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK;
920
921 if (min_fck_per_pck &&
922 req_pck * min_fck_per_pck > DISPC_MAX_FCK) {
923 DSSERR("Requested pixel clock not possible with the current "
924 "OMAP2_DSS_MIN_FCK_PER_PCK setting. Turning "
925 "the constraint off.\n");
926 min_fck_per_pck = 0;
927 }
928
929 DSSDBG("dsi_pll_calc\n");
930
931retry:
932 memset(&best, 0, sizeof(best));
933 memset(&best_dispc, 0, sizeof(best_dispc));
934
935 memset(&cur, 0, sizeof(cur));
936 cur.clkin = dss_clk_fck2;
937 cur.use_dss2_fck = 1;
938 cur.highfreq = 0;
939
940 /* no highfreq: 0.75MHz < Fint = clkin / regn < 2.1MHz */
941 /* highfreq: 0.75MHz < Fint = clkin / (2*regn) < 2.1MHz */
942 /* To reduce PLL lock time, keep Fint high (around 2 MHz) */
943 for (cur.regn = 1; cur.regn < REGN_MAX; ++cur.regn) {
944 if (cur.highfreq == 0)
945 cur.fint = cur.clkin / cur.regn;
946 else
947 cur.fint = cur.clkin / (2 * cur.regn);
948
949 if (cur.fint > FINT_MAX || cur.fint < FINT_MIN)
950 continue;
951
952 /* DSIPHY(MHz) = (2 * regm / regn) * (clkin / (highfreq + 1)) */
953 for (cur.regm = 1; cur.regm < REGM_MAX; ++cur.regm) {
954 unsigned long a, b;
955
956 a = 2 * cur.regm * (cur.clkin/1000);
957 b = cur.regn * (cur.highfreq + 1);
958 cur.clkin4ddr = a / b * 1000;
959
960 if (cur.clkin4ddr > 1800 * 1000 * 1000)
961 break;
962
963 /* DSI1_PLL_FCLK(MHz) = DSIPHY(MHz) / regm3 < 173MHz */
964 for (cur.regm3 = 1; cur.regm3 < REGM3_MAX;
965 ++cur.regm3) {
966 struct dispc_clock_info cur_dispc;
967 cur.dsi1_pll_fclk = cur.clkin4ddr / cur.regm3;
968
969 /* this will narrow down the search a bit,
970 * but still give pixclocks below what was
971 * requested */
972 if (cur.dsi1_pll_fclk < req_pck)
973 break;
974
975 if (cur.dsi1_pll_fclk > DISPC_MAX_FCK)
976 continue;
977
978 if (min_fck_per_pck &&
979 cur.dsi1_pll_fclk <
980 req_pck * min_fck_per_pck)
981 continue;
982
983 match = 1;
984
985 dispc_find_clk_divs(is_tft, req_pck,
986 cur.dsi1_pll_fclk,
987 &cur_dispc);
988
989 if (abs(cur_dispc.pck - req_pck) <
990 abs(best_dispc.pck - req_pck)) {
991 best = cur;
992 best_dispc = cur_dispc;
993
994 if (cur_dispc.pck == req_pck)
995 goto found;
996 }
997 }
998 }
999 }
1000found:
1001 if (!match) {
1002 if (min_fck_per_pck) {
1003 DSSERR("Could not find suitable clock settings.\n"
1004 "Turning FCK/PCK constraint off and"
1005 "trying again.\n");
1006 min_fck_per_pck = 0;
1007 goto retry;
1008 }
1009
1010 DSSERR("Could not find suitable clock settings.\n");
1011
1012 return -EINVAL;
1013 }
1014
1015 /* DSI2_PLL_FCLK (regm4) is not used */
1016 best.regm4 = 0;
1017 best.dsi2_pll_fclk = 0;
1018
1019 if (dsi_cinfo)
1020 *dsi_cinfo = best;
1021 if (dispc_cinfo)
1022 *dispc_cinfo = best_dispc;
1023
1024 dsi.cache_req_pck = req_pck;
1025 dsi.cache_clk_freq = 0;
1026 dsi.cache_cinfo = best;
1027
1028 return 0;
1029}
1030
1031int dsi_pll_set_clock_div(struct dsi_clock_info *cinfo)
1032{
1033 int r = 0;
1034 u32 l;
1035 int f;
1036
1037 DSSDBGF();
1038
1039 dsi.current_cinfo.fint = cinfo->fint;
1040 dsi.current_cinfo.clkin4ddr = cinfo->clkin4ddr;
1041 dsi.current_cinfo.dsi1_pll_fclk = cinfo->dsi1_pll_fclk;
1042 dsi.current_cinfo.dsi2_pll_fclk = cinfo->dsi2_pll_fclk;
1043
1044 dsi.current_cinfo.regn = cinfo->regn;
1045 dsi.current_cinfo.regm = cinfo->regm;
1046 dsi.current_cinfo.regm3 = cinfo->regm3;
1047 dsi.current_cinfo.regm4 = cinfo->regm4;
1048
1049 DSSDBG("DSI Fint %ld\n", cinfo->fint);
1050
1051 DSSDBG("clkin (%s) rate %ld, highfreq %d\n",
1052 cinfo->use_dss2_fck ? "dss2_fck" : "pclkfree",
1053 cinfo->clkin,
1054 cinfo->highfreq);
1055
1056 /* DSIPHY == CLKIN4DDR */
1057 DSSDBG("CLKIN4DDR = 2 * %d / %d * %lu / %d = %lu\n",
1058 cinfo->regm,
1059 cinfo->regn,
1060 cinfo->clkin,
1061 cinfo->highfreq + 1,
1062 cinfo->clkin4ddr);
1063
1064 DSSDBG("Data rate on 1 DSI lane %ld Mbps\n",
1065 cinfo->clkin4ddr / 1000 / 1000 / 2);
1066
1067 DSSDBG("Clock lane freq %ld Hz\n", cinfo->clkin4ddr / 4);
1068
1069 DSSDBG("regm3 = %d, dsi1_pll_fclk = %lu\n",
1070 cinfo->regm3, cinfo->dsi1_pll_fclk);
1071 DSSDBG("regm4 = %d, dsi2_pll_fclk = %lu\n",
1072 cinfo->regm4, cinfo->dsi2_pll_fclk);
1073
1074 REG_FLD_MOD(DSI_PLL_CONTROL, 0, 0, 0); /* DSI_PLL_AUTOMODE = manual */
1075
1076 l = dsi_read_reg(DSI_PLL_CONFIGURATION1);
1077 l = FLD_MOD(l, 1, 0, 0); /* DSI_PLL_STOPMODE */
1078 l = FLD_MOD(l, cinfo->regn - 1, 7, 1); /* DSI_PLL_REGN */
1079 l = FLD_MOD(l, cinfo->regm, 18, 8); /* DSI_PLL_REGM */
1080 l = FLD_MOD(l, cinfo->regm3 > 0 ? cinfo->regm3 - 1 : 0,
1081 22, 19); /* DSI_CLOCK_DIV */
1082 l = FLD_MOD(l, cinfo->regm4 > 0 ? cinfo->regm4 - 1 : 0,
1083 26, 23); /* DSIPROTO_CLOCK_DIV */
1084 dsi_write_reg(DSI_PLL_CONFIGURATION1, l);
1085
1086 BUG_ON(cinfo->fint < 750000 || cinfo->fint > 2100000);
1087 if (cinfo->fint < 1000000)
1088 f = 0x3;
1089 else if (cinfo->fint < 1250000)
1090 f = 0x4;
1091 else if (cinfo->fint < 1500000)
1092 f = 0x5;
1093 else if (cinfo->fint < 1750000)
1094 f = 0x6;
1095 else
1096 f = 0x7;
1097
1098 l = dsi_read_reg(DSI_PLL_CONFIGURATION2);
1099 l = FLD_MOD(l, f, 4, 1); /* DSI_PLL_FREQSEL */
1100 l = FLD_MOD(l, cinfo->use_dss2_fck ? 0 : 1,
1101 11, 11); /* DSI_PLL_CLKSEL */
1102 l = FLD_MOD(l, cinfo->highfreq,
1103 12, 12); /* DSI_PLL_HIGHFREQ */
1104 l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */
1105 l = FLD_MOD(l, 0, 14, 14); /* DSIPHY_CLKINEN */
1106 l = FLD_MOD(l, 1, 20, 20); /* DSI_HSDIVBYPASS */
1107 dsi_write_reg(DSI_PLL_CONFIGURATION2, l);
1108
1109 REG_FLD_MOD(DSI_PLL_GO, 1, 0, 0); /* DSI_PLL_GO */
1110
1111 if (wait_for_bit_change(DSI_PLL_GO, 0, 0) != 0) {
1112 DSSERR("dsi pll go bit not going down.\n");
1113 r = -EIO;
1114 goto err;
1115 }
1116
1117 if (wait_for_bit_change(DSI_PLL_STATUS, 1, 1) != 1) {
1118 DSSERR("cannot lock PLL\n");
1119 r = -EIO;
1120 goto err;
1121 }
1122
1123 dsi.pll_locked = 1;
1124
1125 l = dsi_read_reg(DSI_PLL_CONFIGURATION2);
1126 l = FLD_MOD(l, 0, 0, 0); /* DSI_PLL_IDLE */
1127 l = FLD_MOD(l, 0, 5, 5); /* DSI_PLL_PLLLPMODE */
1128 l = FLD_MOD(l, 0, 6, 6); /* DSI_PLL_LOWCURRSTBY */
1129 l = FLD_MOD(l, 0, 7, 7); /* DSI_PLL_TIGHTPHASELOCK */
1130 l = FLD_MOD(l, 0, 8, 8); /* DSI_PLL_DRIFTGUARDEN */
1131 l = FLD_MOD(l, 0, 10, 9); /* DSI_PLL_LOCKSEL */
1132 l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */
1133 l = FLD_MOD(l, 1, 14, 14); /* DSIPHY_CLKINEN */
1134 l = FLD_MOD(l, 0, 15, 15); /* DSI_BYPASSEN */
1135 l = FLD_MOD(l, 1, 16, 16); /* DSS_CLOCK_EN */
1136 l = FLD_MOD(l, 0, 17, 17); /* DSS_CLOCK_PWDN */
1137 l = FLD_MOD(l, 1, 18, 18); /* DSI_PROTO_CLOCK_EN */
1138 l = FLD_MOD(l, 0, 19, 19); /* DSI_PROTO_CLOCK_PWDN */
1139 l = FLD_MOD(l, 0, 20, 20); /* DSI_HSDIVBYPASS */
1140 dsi_write_reg(DSI_PLL_CONFIGURATION2, l);
1141
1142 DSSDBG("PLL config done\n");
1143err:
1144 return r;
1145}
1146
1147int dsi_pll_init(struct omap_dss_device *dssdev, bool enable_hsclk,
1148 bool enable_hsdiv)
1149{
1150 int r = 0;
1151 enum dsi_pll_power_state pwstate;
1152
1153 DSSDBG("PLL init\n");
1154
1155 enable_clocks(1);
1156 dsi_enable_pll_clock(1);
1157
1158 r = regulator_enable(dsi.vdds_dsi_reg);
1159 if (r)
1160 goto err0;
1161
1162 /* XXX PLL does not come out of reset without this... */
1163 dispc_pck_free_enable(1);
1164
1165 if (wait_for_bit_change(DSI_PLL_STATUS, 0, 1) != 1) {
1166 DSSERR("PLL not coming out of reset.\n");
1167 r = -ENODEV;
1168 goto err1;
1169 }
1170
1171 /* XXX ... but if left on, we get problems when planes do not
1172 * fill the whole display. No idea about this */
1173 dispc_pck_free_enable(0);
1174
1175 if (enable_hsclk && enable_hsdiv)
1176 pwstate = DSI_PLL_POWER_ON_ALL;
1177 else if (enable_hsclk)
1178 pwstate = DSI_PLL_POWER_ON_HSCLK;
1179 else if (enable_hsdiv)
1180 pwstate = DSI_PLL_POWER_ON_DIV;
1181 else
1182 pwstate = DSI_PLL_POWER_OFF;
1183
1184 r = dsi_pll_power(pwstate);
1185
1186 if (r)
1187 goto err1;
1188
1189 DSSDBG("PLL init done\n");
1190
1191 return 0;
1192err1:
1193 regulator_disable(dsi.vdds_dsi_reg);
1194err0:
1195 enable_clocks(0);
1196 dsi_enable_pll_clock(0);
1197 return r;
1198}
1199
1200void dsi_pll_uninit(void)
1201{
1202 enable_clocks(0);
1203 dsi_enable_pll_clock(0);
1204
1205 dsi.pll_locked = 0;
1206 dsi_pll_power(DSI_PLL_POWER_OFF);
1207 regulator_disable(dsi.vdds_dsi_reg);
1208 DSSDBG("PLL uninit done\n");
1209}
1210
1211void dsi_dump_clocks(struct seq_file *s)
1212{
1213 int clksel;
1214 struct dsi_clock_info *cinfo = &dsi.current_cinfo;
1215
1216 enable_clocks(1);
1217
1218 clksel = REG_GET(DSI_PLL_CONFIGURATION2, 11, 11);
1219
1220 seq_printf(s, "- DSI PLL -\n");
1221
1222 seq_printf(s, "dsi pll source = %s\n",
1223 clksel == 0 ?
1224 "dss2_alwon_fclk" : "pclkfree");
1225
1226 seq_printf(s, "Fint\t\t%-16luregn %u\n", cinfo->fint, cinfo->regn);
1227
1228 seq_printf(s, "CLKIN4DDR\t%-16luregm %u\n",
1229 cinfo->clkin4ddr, cinfo->regm);
1230
1231 seq_printf(s, "dsi1_pll_fck\t%-16luregm3 %u\t(%s)\n",
1232 cinfo->dsi1_pll_fclk,
1233 cinfo->regm3,
1234 dss_get_dispc_clk_source() == 0 ? "off" : "on");
1235
1236 seq_printf(s, "dsi2_pll_fck\t%-16luregm4 %u\t(%s)\n",
1237 cinfo->dsi2_pll_fclk,
1238 cinfo->regm4,
1239 dss_get_dsi_clk_source() == 0 ? "off" : "on");
1240
1241 seq_printf(s, "- DSI -\n");
1242
1243 seq_printf(s, "dsi fclk source = %s\n",
1244 dss_get_dsi_clk_source() == 0 ?
1245 "dss1_alwon_fclk" : "dsi2_pll_fclk");
1246
1247 seq_printf(s, "DSI_FCLK\t%lu\n", dsi_fclk_rate());
1248
1249 seq_printf(s, "DDR_CLK\t\t%lu\n",
1250 cinfo->clkin4ddr / 4);
1251
1252 seq_printf(s, "TxByteClkHS\t%lu\n", dsi_get_txbyteclkhs());
1253
1254 seq_printf(s, "LP_CLK\t\t%lu\n", cinfo->lp_clk);
1255
1256 seq_printf(s, "VP_CLK\t\t%lu\n"
1257 "VP_PCLK\t\t%lu\n",
1258 dispc_lclk_rate(),
1259 dispc_pclk_rate());
1260
1261 enable_clocks(0);
1262}
1263
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001264#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
1265void dsi_dump_irqs(struct seq_file *s)
1266{
1267 unsigned long flags;
1268 struct dsi_irq_stats stats;
1269
1270 spin_lock_irqsave(&dsi.irq_stats_lock, flags);
1271
1272 stats = dsi.irq_stats;
1273 memset(&dsi.irq_stats, 0, sizeof(dsi.irq_stats));
1274 dsi.irq_stats.last_reset = jiffies;
1275
1276 spin_unlock_irqrestore(&dsi.irq_stats_lock, flags);
1277
1278 seq_printf(s, "period %u ms\n",
1279 jiffies_to_msecs(jiffies - stats.last_reset));
1280
1281 seq_printf(s, "irqs %d\n", stats.irq_count);
1282#define PIS(x) \
1283 seq_printf(s, "%-20s %10d\n", #x, stats.dsi_irqs[ffs(DSI_IRQ_##x)-1]);
1284
1285 seq_printf(s, "-- DSI interrupts --\n");
1286 PIS(VC0);
1287 PIS(VC1);
1288 PIS(VC2);
1289 PIS(VC3);
1290 PIS(WAKEUP);
1291 PIS(RESYNC);
1292 PIS(PLL_LOCK);
1293 PIS(PLL_UNLOCK);
1294 PIS(PLL_RECALL);
1295 PIS(COMPLEXIO_ERR);
1296 PIS(HS_TX_TIMEOUT);
1297 PIS(LP_RX_TIMEOUT);
1298 PIS(TE_TRIGGER);
1299 PIS(ACK_TRIGGER);
1300 PIS(SYNC_LOST);
1301 PIS(LDO_POWER_GOOD);
1302 PIS(TA_TIMEOUT);
1303#undef PIS
1304
1305#define PIS(x) \
1306 seq_printf(s, "%-20s %10d %10d %10d %10d\n", #x, \
1307 stats.vc_irqs[0][ffs(DSI_VC_IRQ_##x)-1], \
1308 stats.vc_irqs[1][ffs(DSI_VC_IRQ_##x)-1], \
1309 stats.vc_irqs[2][ffs(DSI_VC_IRQ_##x)-1], \
1310 stats.vc_irqs[3][ffs(DSI_VC_IRQ_##x)-1]);
1311
1312 seq_printf(s, "-- VC interrupts --\n");
1313 PIS(CS);
1314 PIS(ECC_CORR);
1315 PIS(PACKET_SENT);
1316 PIS(FIFO_TX_OVF);
1317 PIS(FIFO_RX_OVF);
1318 PIS(BTA);
1319 PIS(ECC_NO_CORR);
1320 PIS(FIFO_TX_UDF);
1321 PIS(PP_BUSY_CHANGE);
1322#undef PIS
1323
1324#define PIS(x) \
1325 seq_printf(s, "%-20s %10d\n", #x, \
1326 stats.cio_irqs[ffs(DSI_CIO_IRQ_##x)-1]);
1327
1328 seq_printf(s, "-- CIO interrupts --\n");
1329 PIS(ERRSYNCESC1);
1330 PIS(ERRSYNCESC2);
1331 PIS(ERRSYNCESC3);
1332 PIS(ERRESC1);
1333 PIS(ERRESC2);
1334 PIS(ERRESC3);
1335 PIS(ERRCONTROL1);
1336 PIS(ERRCONTROL2);
1337 PIS(ERRCONTROL3);
1338 PIS(STATEULPS1);
1339 PIS(STATEULPS2);
1340 PIS(STATEULPS3);
1341 PIS(ERRCONTENTIONLP0_1);
1342 PIS(ERRCONTENTIONLP1_1);
1343 PIS(ERRCONTENTIONLP0_2);
1344 PIS(ERRCONTENTIONLP1_2);
1345 PIS(ERRCONTENTIONLP0_3);
1346 PIS(ERRCONTENTIONLP1_3);
1347 PIS(ULPSACTIVENOT_ALL0);
1348 PIS(ULPSACTIVENOT_ALL1);
1349#undef PIS
1350}
1351#endif
1352
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001353void dsi_dump_regs(struct seq_file *s)
1354{
1355#define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dsi_read_reg(r))
1356
1357 dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK1);
1358
1359 DUMPREG(DSI_REVISION);
1360 DUMPREG(DSI_SYSCONFIG);
1361 DUMPREG(DSI_SYSSTATUS);
1362 DUMPREG(DSI_IRQSTATUS);
1363 DUMPREG(DSI_IRQENABLE);
1364 DUMPREG(DSI_CTRL);
1365 DUMPREG(DSI_COMPLEXIO_CFG1);
1366 DUMPREG(DSI_COMPLEXIO_IRQ_STATUS);
1367 DUMPREG(DSI_COMPLEXIO_IRQ_ENABLE);
1368 DUMPREG(DSI_CLK_CTRL);
1369 DUMPREG(DSI_TIMING1);
1370 DUMPREG(DSI_TIMING2);
1371 DUMPREG(DSI_VM_TIMING1);
1372 DUMPREG(DSI_VM_TIMING2);
1373 DUMPREG(DSI_VM_TIMING3);
1374 DUMPREG(DSI_CLK_TIMING);
1375 DUMPREG(DSI_TX_FIFO_VC_SIZE);
1376 DUMPREG(DSI_RX_FIFO_VC_SIZE);
1377 DUMPREG(DSI_COMPLEXIO_CFG2);
1378 DUMPREG(DSI_RX_FIFO_VC_FULLNESS);
1379 DUMPREG(DSI_VM_TIMING4);
1380 DUMPREG(DSI_TX_FIFO_VC_EMPTINESS);
1381 DUMPREG(DSI_VM_TIMING5);
1382 DUMPREG(DSI_VM_TIMING6);
1383 DUMPREG(DSI_VM_TIMING7);
1384 DUMPREG(DSI_STOPCLK_TIMING);
1385
1386 DUMPREG(DSI_VC_CTRL(0));
1387 DUMPREG(DSI_VC_TE(0));
1388 DUMPREG(DSI_VC_LONG_PACKET_HEADER(0));
1389 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(0));
1390 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(0));
1391 DUMPREG(DSI_VC_IRQSTATUS(0));
1392 DUMPREG(DSI_VC_IRQENABLE(0));
1393
1394 DUMPREG(DSI_VC_CTRL(1));
1395 DUMPREG(DSI_VC_TE(1));
1396 DUMPREG(DSI_VC_LONG_PACKET_HEADER(1));
1397 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(1));
1398 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(1));
1399 DUMPREG(DSI_VC_IRQSTATUS(1));
1400 DUMPREG(DSI_VC_IRQENABLE(1));
1401
1402 DUMPREG(DSI_VC_CTRL(2));
1403 DUMPREG(DSI_VC_TE(2));
1404 DUMPREG(DSI_VC_LONG_PACKET_HEADER(2));
1405 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(2));
1406 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(2));
1407 DUMPREG(DSI_VC_IRQSTATUS(2));
1408 DUMPREG(DSI_VC_IRQENABLE(2));
1409
1410 DUMPREG(DSI_VC_CTRL(3));
1411 DUMPREG(DSI_VC_TE(3));
1412 DUMPREG(DSI_VC_LONG_PACKET_HEADER(3));
1413 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(3));
1414 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(3));
1415 DUMPREG(DSI_VC_IRQSTATUS(3));
1416 DUMPREG(DSI_VC_IRQENABLE(3));
1417
1418 DUMPREG(DSI_DSIPHY_CFG0);
1419 DUMPREG(DSI_DSIPHY_CFG1);
1420 DUMPREG(DSI_DSIPHY_CFG2);
1421 DUMPREG(DSI_DSIPHY_CFG5);
1422
1423 DUMPREG(DSI_PLL_CONTROL);
1424 DUMPREG(DSI_PLL_STATUS);
1425 DUMPREG(DSI_PLL_GO);
1426 DUMPREG(DSI_PLL_CONFIGURATION1);
1427 DUMPREG(DSI_PLL_CONFIGURATION2);
1428
1429 dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK1);
1430#undef DUMPREG
1431}
1432
1433enum dsi_complexio_power_state {
1434 DSI_COMPLEXIO_POWER_OFF = 0x0,
1435 DSI_COMPLEXIO_POWER_ON = 0x1,
1436 DSI_COMPLEXIO_POWER_ULPS = 0x2,
1437};
1438
1439static int dsi_complexio_power(enum dsi_complexio_power_state state)
1440{
1441 int t = 0;
1442
1443 /* PWR_CMD */
1444 REG_FLD_MOD(DSI_COMPLEXIO_CFG1, state, 28, 27);
1445
1446 /* PWR_STATUS */
1447 while (FLD_GET(dsi_read_reg(DSI_COMPLEXIO_CFG1), 26, 25) != state) {
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02001448 if (++t > 1000) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001449 DSSERR("failed to set complexio power state to "
1450 "%d\n", state);
1451 return -ENODEV;
1452 }
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02001453 udelay(1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001454 }
1455
1456 return 0;
1457}
1458
1459static void dsi_complexio_config(struct omap_dss_device *dssdev)
1460{
1461 u32 r;
1462
1463 int clk_lane = dssdev->phy.dsi.clk_lane;
1464 int data1_lane = dssdev->phy.dsi.data1_lane;
1465 int data2_lane = dssdev->phy.dsi.data2_lane;
1466 int clk_pol = dssdev->phy.dsi.clk_pol;
1467 int data1_pol = dssdev->phy.dsi.data1_pol;
1468 int data2_pol = dssdev->phy.dsi.data2_pol;
1469
1470 r = dsi_read_reg(DSI_COMPLEXIO_CFG1);
1471 r = FLD_MOD(r, clk_lane, 2, 0);
1472 r = FLD_MOD(r, clk_pol, 3, 3);
1473 r = FLD_MOD(r, data1_lane, 6, 4);
1474 r = FLD_MOD(r, data1_pol, 7, 7);
1475 r = FLD_MOD(r, data2_lane, 10, 8);
1476 r = FLD_MOD(r, data2_pol, 11, 11);
1477 dsi_write_reg(DSI_COMPLEXIO_CFG1, r);
1478
1479 /* The configuration of the DSI complex I/O (number of data lanes,
1480 position, differential order) should not be changed while
1481 DSS.DSI_CLK_CRTRL[20] LP_CLK_ENABLE bit is set to 1. In order for
1482 the hardware to take into account a new configuration of the complex
1483 I/O (done in DSS.DSI_COMPLEXIO_CFG1 register), it is recommended to
1484 follow this sequence: First set the DSS.DSI_CTRL[0] IF_EN bit to 1,
1485 then reset the DSS.DSI_CTRL[0] IF_EN to 0, then set
1486 DSS.DSI_CLK_CTRL[20] LP_CLK_ENABLE to 1 and finally set again the
1487 DSS.DSI_CTRL[0] IF_EN bit to 1. If the sequence is not followed, the
1488 DSI complex I/O configuration is unknown. */
1489
1490 /*
1491 REG_FLD_MOD(DSI_CTRL, 1, 0, 0);
1492 REG_FLD_MOD(DSI_CTRL, 0, 0, 0);
1493 REG_FLD_MOD(DSI_CLK_CTRL, 1, 20, 20);
1494 REG_FLD_MOD(DSI_CTRL, 1, 0, 0);
1495 */
1496}
1497
1498static inline unsigned ns2ddr(unsigned ns)
1499{
1500 /* convert time in ns to ddr ticks, rounding up */
1501 unsigned long ddr_clk = dsi.current_cinfo.clkin4ddr / 4;
1502 return (ns * (ddr_clk / 1000 / 1000) + 999) / 1000;
1503}
1504
1505static inline unsigned ddr2ns(unsigned ddr)
1506{
1507 unsigned long ddr_clk = dsi.current_cinfo.clkin4ddr / 4;
1508 return ddr * 1000 * 1000 / (ddr_clk / 1000);
1509}
1510
1511static void dsi_complexio_timings(void)
1512{
1513 u32 r;
1514 u32 ths_prepare, ths_prepare_ths_zero, ths_trail, ths_exit;
1515 u32 tlpx_half, tclk_trail, tclk_zero;
1516 u32 tclk_prepare;
1517
1518 /* calculate timings */
1519
1520 /* 1 * DDR_CLK = 2 * UI */
1521
1522 /* min 40ns + 4*UI max 85ns + 6*UI */
1523 ths_prepare = ns2ddr(70) + 2;
1524
1525 /* min 145ns + 10*UI */
1526 ths_prepare_ths_zero = ns2ddr(175) + 2;
1527
1528 /* min max(8*UI, 60ns+4*UI) */
1529 ths_trail = ns2ddr(60) + 5;
1530
1531 /* min 100ns */
1532 ths_exit = ns2ddr(145);
1533
1534 /* tlpx min 50n */
1535 tlpx_half = ns2ddr(25);
1536
1537 /* min 60ns */
1538 tclk_trail = ns2ddr(60) + 2;
1539
1540 /* min 38ns, max 95ns */
1541 tclk_prepare = ns2ddr(65);
1542
1543 /* min tclk-prepare + tclk-zero = 300ns */
1544 tclk_zero = ns2ddr(260);
1545
1546 DSSDBG("ths_prepare %u (%uns), ths_prepare_ths_zero %u (%uns)\n",
1547 ths_prepare, ddr2ns(ths_prepare),
1548 ths_prepare_ths_zero, ddr2ns(ths_prepare_ths_zero));
1549 DSSDBG("ths_trail %u (%uns), ths_exit %u (%uns)\n",
1550 ths_trail, ddr2ns(ths_trail),
1551 ths_exit, ddr2ns(ths_exit));
1552
1553 DSSDBG("tlpx_half %u (%uns), tclk_trail %u (%uns), "
1554 "tclk_zero %u (%uns)\n",
1555 tlpx_half, ddr2ns(tlpx_half),
1556 tclk_trail, ddr2ns(tclk_trail),
1557 tclk_zero, ddr2ns(tclk_zero));
1558 DSSDBG("tclk_prepare %u (%uns)\n",
1559 tclk_prepare, ddr2ns(tclk_prepare));
1560
1561 /* program timings */
1562
1563 r = dsi_read_reg(DSI_DSIPHY_CFG0);
1564 r = FLD_MOD(r, ths_prepare, 31, 24);
1565 r = FLD_MOD(r, ths_prepare_ths_zero, 23, 16);
1566 r = FLD_MOD(r, ths_trail, 15, 8);
1567 r = FLD_MOD(r, ths_exit, 7, 0);
1568 dsi_write_reg(DSI_DSIPHY_CFG0, r);
1569
1570 r = dsi_read_reg(DSI_DSIPHY_CFG1);
1571 r = FLD_MOD(r, tlpx_half, 22, 16);
1572 r = FLD_MOD(r, tclk_trail, 15, 8);
1573 r = FLD_MOD(r, tclk_zero, 7, 0);
1574 dsi_write_reg(DSI_DSIPHY_CFG1, r);
1575
1576 r = dsi_read_reg(DSI_DSIPHY_CFG2);
1577 r = FLD_MOD(r, tclk_prepare, 7, 0);
1578 dsi_write_reg(DSI_DSIPHY_CFG2, r);
1579}
1580
1581
1582static int dsi_complexio_init(struct omap_dss_device *dssdev)
1583{
1584 int r = 0;
1585
1586 DSSDBG("dsi_complexio_init\n");
1587
1588 /* CIO_CLK_ICG, enable L3 clk to CIO */
1589 REG_FLD_MOD(DSI_CLK_CTRL, 1, 14, 14);
1590
1591 /* A dummy read using the SCP interface to any DSIPHY register is
1592 * required after DSIPHY reset to complete the reset of the DSI complex
1593 * I/O. */
1594 dsi_read_reg(DSI_DSIPHY_CFG5);
1595
1596 if (wait_for_bit_change(DSI_DSIPHY_CFG5, 30, 1) != 1) {
1597 DSSERR("ComplexIO PHY not coming out of reset.\n");
1598 r = -ENODEV;
1599 goto err;
1600 }
1601
1602 dsi_complexio_config(dssdev);
1603
1604 r = dsi_complexio_power(DSI_COMPLEXIO_POWER_ON);
1605
1606 if (r)
1607 goto err;
1608
1609 if (wait_for_bit_change(DSI_COMPLEXIO_CFG1, 29, 1) != 1) {
1610 DSSERR("ComplexIO not coming out of reset.\n");
1611 r = -ENODEV;
1612 goto err;
1613 }
1614
1615 if (wait_for_bit_change(DSI_COMPLEXIO_CFG1, 21, 1) != 1) {
1616 DSSERR("ComplexIO LDO power down.\n");
1617 r = -ENODEV;
1618 goto err;
1619 }
1620
1621 dsi_complexio_timings();
1622
1623 /*
1624 The configuration of the DSI complex I/O (number of data lanes,
1625 position, differential order) should not be changed while
1626 DSS.DSI_CLK_CRTRL[20] LP_CLK_ENABLE bit is set to 1. For the
1627 hardware to recognize a new configuration of the complex I/O (done
1628 in DSS.DSI_COMPLEXIO_CFG1 register), it is recommended to follow
1629 this sequence: First set the DSS.DSI_CTRL[0] IF_EN bit to 1, next
1630 reset the DSS.DSI_CTRL[0] IF_EN to 0, then set DSS.DSI_CLK_CTRL[20]
1631 LP_CLK_ENABLE to 1, and finally, set again the DSS.DSI_CTRL[0] IF_EN
1632 bit to 1. If the sequence is not followed, the DSi complex I/O
1633 configuration is undetermined.
1634 */
1635 dsi_if_enable(1);
1636 dsi_if_enable(0);
1637 REG_FLD_MOD(DSI_CLK_CTRL, 1, 20, 20); /* LP_CLK_ENABLE */
1638 dsi_if_enable(1);
1639 dsi_if_enable(0);
1640
1641 DSSDBG("CIO init done\n");
1642err:
1643 return r;
1644}
1645
1646static void dsi_complexio_uninit(void)
1647{
1648 dsi_complexio_power(DSI_COMPLEXIO_POWER_OFF);
1649}
1650
1651static int _dsi_wait_reset(void)
1652{
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02001653 int t = 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001654
1655 while (REG_GET(DSI_SYSSTATUS, 0, 0) == 0) {
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02001656 if (++t > 5) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001657 DSSERR("soft reset failed\n");
1658 return -ENODEV;
1659 }
1660 udelay(1);
1661 }
1662
1663 return 0;
1664}
1665
1666static int _dsi_reset(void)
1667{
1668 /* Soft reset */
1669 REG_FLD_MOD(DSI_SYSCONFIG, 1, 1, 1);
1670 return _dsi_wait_reset();
1671}
1672
1673static void dsi_reset_tx_fifo(int channel)
1674{
1675 u32 mask;
1676 u32 l;
1677
1678 /* set fifosize of the channel to 0, then return the old size */
1679 l = dsi_read_reg(DSI_TX_FIFO_VC_SIZE);
1680
1681 mask = FLD_MASK((8 * channel) + 7, (8 * channel) + 4);
1682 dsi_write_reg(DSI_TX_FIFO_VC_SIZE, l & ~mask);
1683
1684 dsi_write_reg(DSI_TX_FIFO_VC_SIZE, l);
1685}
1686
1687static void dsi_config_tx_fifo(enum fifo_size size1, enum fifo_size size2,
1688 enum fifo_size size3, enum fifo_size size4)
1689{
1690 u32 r = 0;
1691 int add = 0;
1692 int i;
1693
1694 dsi.vc[0].fifo_size = size1;
1695 dsi.vc[1].fifo_size = size2;
1696 dsi.vc[2].fifo_size = size3;
1697 dsi.vc[3].fifo_size = size4;
1698
1699 for (i = 0; i < 4; i++) {
1700 u8 v;
1701 int size = dsi.vc[i].fifo_size;
1702
1703 if (add + size > 4) {
1704 DSSERR("Illegal FIFO configuration\n");
1705 BUG();
1706 }
1707
1708 v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
1709 r |= v << (8 * i);
1710 /*DSSDBG("TX FIFO vc %d: size %d, add %d\n", i, size, add); */
1711 add += size;
1712 }
1713
1714 dsi_write_reg(DSI_TX_FIFO_VC_SIZE, r);
1715}
1716
1717static void dsi_config_rx_fifo(enum fifo_size size1, enum fifo_size size2,
1718 enum fifo_size size3, enum fifo_size size4)
1719{
1720 u32 r = 0;
1721 int add = 0;
1722 int i;
1723
1724 dsi.vc[0].fifo_size = size1;
1725 dsi.vc[1].fifo_size = size2;
1726 dsi.vc[2].fifo_size = size3;
1727 dsi.vc[3].fifo_size = size4;
1728
1729 for (i = 0; i < 4; i++) {
1730 u8 v;
1731 int size = dsi.vc[i].fifo_size;
1732
1733 if (add + size > 4) {
1734 DSSERR("Illegal FIFO configuration\n");
1735 BUG();
1736 }
1737
1738 v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
1739 r |= v << (8 * i);
1740 /*DSSDBG("RX FIFO vc %d: size %d, add %d\n", i, size, add); */
1741 add += size;
1742 }
1743
1744 dsi_write_reg(DSI_RX_FIFO_VC_SIZE, r);
1745}
1746
1747static int dsi_force_tx_stop_mode_io(void)
1748{
1749 u32 r;
1750
1751 r = dsi_read_reg(DSI_TIMING1);
1752 r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
1753 dsi_write_reg(DSI_TIMING1, r);
1754
1755 if (wait_for_bit_change(DSI_TIMING1, 15, 0) != 0) {
1756 DSSERR("TX_STOP bit not going down\n");
1757 return -EIO;
1758 }
1759
1760 return 0;
1761}
1762
1763static void dsi_vc_print_status(int channel)
1764{
1765 u32 r;
1766
1767 r = dsi_read_reg(DSI_VC_CTRL(channel));
1768 DSSDBG("vc %d: TX_FIFO_NOT_EMPTY %d, BTA_EN %d, VC_BUSY %d, "
1769 "TX_FIFO_FULL %d, RX_FIFO_NOT_EMPTY %d, ",
1770 channel,
1771 FLD_GET(r, 5, 5),
1772 FLD_GET(r, 6, 6),
1773 FLD_GET(r, 15, 15),
1774 FLD_GET(r, 16, 16),
1775 FLD_GET(r, 20, 20));
1776
1777 r = dsi_read_reg(DSI_TX_FIFO_VC_EMPTINESS);
1778 DSSDBG("EMPTINESS %d\n", (r >> (8 * channel)) & 0xff);
1779}
1780
1781static int dsi_vc_enable(int channel, bool enable)
1782{
1783 if (dsi.update_mode != OMAP_DSS_UPDATE_AUTO)
1784 DSSDBG("dsi_vc_enable channel %d, enable %d\n",
1785 channel, enable);
1786
1787 enable = enable ? 1 : 0;
1788
1789 REG_FLD_MOD(DSI_VC_CTRL(channel), enable, 0, 0);
1790
1791 if (wait_for_bit_change(DSI_VC_CTRL(channel), 0, enable) != enable) {
1792 DSSERR("Failed to set dsi_vc_enable to %d\n", enable);
1793 return -EIO;
1794 }
1795
1796 return 0;
1797}
1798
1799static void dsi_vc_initial_config(int channel)
1800{
1801 u32 r;
1802
1803 DSSDBGF("%d", channel);
1804
1805 r = dsi_read_reg(DSI_VC_CTRL(channel));
1806
1807 if (FLD_GET(r, 15, 15)) /* VC_BUSY */
1808 DSSERR("VC(%d) busy when trying to configure it!\n",
1809 channel);
1810
1811 r = FLD_MOD(r, 0, 1, 1); /* SOURCE, 0 = L4 */
1812 r = FLD_MOD(r, 0, 2, 2); /* BTA_SHORT_EN */
1813 r = FLD_MOD(r, 0, 3, 3); /* BTA_LONG_EN */
1814 r = FLD_MOD(r, 0, 4, 4); /* MODE, 0 = command */
1815 r = FLD_MOD(r, 1, 7, 7); /* CS_TX_EN */
1816 r = FLD_MOD(r, 1, 8, 8); /* ECC_TX_EN */
1817 r = FLD_MOD(r, 0, 9, 9); /* MODE_SPEED, high speed on/off */
1818
1819 r = FLD_MOD(r, 4, 29, 27); /* DMA_RX_REQ_NB = no dma */
1820 r = FLD_MOD(r, 4, 23, 21); /* DMA_TX_REQ_NB = no dma */
1821
1822 dsi_write_reg(DSI_VC_CTRL(channel), r);
1823
1824 dsi.vc[channel].mode = DSI_VC_MODE_L4;
1825}
1826
1827static void dsi_vc_config_l4(int channel)
1828{
1829 if (dsi.vc[channel].mode == DSI_VC_MODE_L4)
1830 return;
1831
1832 DSSDBGF("%d", channel);
1833
1834 dsi_vc_enable(channel, 0);
1835
1836 if (REG_GET(DSI_VC_CTRL(channel), 15, 15)) /* VC_BUSY */
1837 DSSERR("vc(%d) busy when trying to config for L4\n", channel);
1838
1839 REG_FLD_MOD(DSI_VC_CTRL(channel), 0, 1, 1); /* SOURCE, 0 = L4 */
1840
1841 dsi_vc_enable(channel, 1);
1842
1843 dsi.vc[channel].mode = DSI_VC_MODE_L4;
1844}
1845
1846static void dsi_vc_config_vp(int channel)
1847{
1848 if (dsi.vc[channel].mode == DSI_VC_MODE_VP)
1849 return;
1850
1851 DSSDBGF("%d", channel);
1852
1853 dsi_vc_enable(channel, 0);
1854
1855 if (REG_GET(DSI_VC_CTRL(channel), 15, 15)) /* VC_BUSY */
1856 DSSERR("vc(%d) busy when trying to config for VP\n", channel);
1857
1858 REG_FLD_MOD(DSI_VC_CTRL(channel), 1, 1, 1); /* SOURCE, 1 = video port */
1859
1860 dsi_vc_enable(channel, 1);
1861
1862 dsi.vc[channel].mode = DSI_VC_MODE_VP;
1863}
1864
1865
Tomi Valkeinen61140c92010-01-12 16:00:30 +02001866void omapdss_dsi_vc_enable_hs(int channel, bool enable)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001867{
1868 DSSDBG("dsi_vc_enable_hs(%d, %d)\n", channel, enable);
1869
Tomi Valkeinen61140c92010-01-12 16:00:30 +02001870 WARN_ON(!dsi_bus_is_locked());
1871
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001872 dsi_vc_enable(channel, 0);
1873 dsi_if_enable(0);
1874
1875 REG_FLD_MOD(DSI_VC_CTRL(channel), enable, 9, 9);
1876
1877 dsi_vc_enable(channel, 1);
1878 dsi_if_enable(1);
1879
1880 dsi_force_tx_stop_mode_io();
1881}
Tomi Valkeinen61140c92010-01-12 16:00:30 +02001882EXPORT_SYMBOL(omapdss_dsi_vc_enable_hs);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001883
1884static void dsi_vc_flush_long_data(int channel)
1885{
1886 while (REG_GET(DSI_VC_CTRL(channel), 20, 20)) {
1887 u32 val;
1888 val = dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel));
1889 DSSDBG("\t\tb1 %#02x b2 %#02x b3 %#02x b4 %#02x\n",
1890 (val >> 0) & 0xff,
1891 (val >> 8) & 0xff,
1892 (val >> 16) & 0xff,
1893 (val >> 24) & 0xff);
1894 }
1895}
1896
1897static void dsi_show_rx_ack_with_err(u16 err)
1898{
1899 DSSERR("\tACK with ERROR (%#x):\n", err);
1900 if (err & (1 << 0))
1901 DSSERR("\t\tSoT Error\n");
1902 if (err & (1 << 1))
1903 DSSERR("\t\tSoT Sync Error\n");
1904 if (err & (1 << 2))
1905 DSSERR("\t\tEoT Sync Error\n");
1906 if (err & (1 << 3))
1907 DSSERR("\t\tEscape Mode Entry Command Error\n");
1908 if (err & (1 << 4))
1909 DSSERR("\t\tLP Transmit Sync Error\n");
1910 if (err & (1 << 5))
1911 DSSERR("\t\tHS Receive Timeout Error\n");
1912 if (err & (1 << 6))
1913 DSSERR("\t\tFalse Control Error\n");
1914 if (err & (1 << 7))
1915 DSSERR("\t\t(reserved7)\n");
1916 if (err & (1 << 8))
1917 DSSERR("\t\tECC Error, single-bit (corrected)\n");
1918 if (err & (1 << 9))
1919 DSSERR("\t\tECC Error, multi-bit (not corrected)\n");
1920 if (err & (1 << 10))
1921 DSSERR("\t\tChecksum Error\n");
1922 if (err & (1 << 11))
1923 DSSERR("\t\tData type not recognized\n");
1924 if (err & (1 << 12))
1925 DSSERR("\t\tInvalid VC ID\n");
1926 if (err & (1 << 13))
1927 DSSERR("\t\tInvalid Transmission Length\n");
1928 if (err & (1 << 14))
1929 DSSERR("\t\t(reserved14)\n");
1930 if (err & (1 << 15))
1931 DSSERR("\t\tDSI Protocol Violation\n");
1932}
1933
1934static u16 dsi_vc_flush_receive_data(int channel)
1935{
1936 /* RX_FIFO_NOT_EMPTY */
1937 while (REG_GET(DSI_VC_CTRL(channel), 20, 20)) {
1938 u32 val;
1939 u8 dt;
1940 val = dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel));
1941 DSSDBG("\trawval %#08x\n", val);
1942 dt = FLD_GET(val, 5, 0);
1943 if (dt == DSI_DT_RX_ACK_WITH_ERR) {
1944 u16 err = FLD_GET(val, 23, 8);
1945 dsi_show_rx_ack_with_err(err);
1946 } else if (dt == DSI_DT_RX_SHORT_READ_1) {
1947 DSSDBG("\tDCS short response, 1 byte: %#x\n",
1948 FLD_GET(val, 23, 8));
1949 } else if (dt == DSI_DT_RX_SHORT_READ_2) {
1950 DSSDBG("\tDCS short response, 2 byte: %#x\n",
1951 FLD_GET(val, 23, 8));
1952 } else if (dt == DSI_DT_RX_DCS_LONG_READ) {
1953 DSSDBG("\tDCS long response, len %d\n",
1954 FLD_GET(val, 23, 8));
1955 dsi_vc_flush_long_data(channel);
1956 } else {
1957 DSSERR("\tunknown datatype 0x%02x\n", dt);
1958 }
1959 }
1960 return 0;
1961}
1962
1963static int dsi_vc_send_bta(int channel)
1964{
1965 if (dsi.update_mode != OMAP_DSS_UPDATE_AUTO &&
1966 (dsi.debug_write || dsi.debug_read))
1967 DSSDBG("dsi_vc_send_bta %d\n", channel);
1968
Tomi Valkeinen4f765022010-01-18 16:27:52 +02001969 WARN_ON(!dsi_bus_is_locked());
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001970
1971 if (REG_GET(DSI_VC_CTRL(channel), 20, 20)) { /* RX_FIFO_NOT_EMPTY */
1972 DSSERR("rx fifo not empty when sending BTA, dumping data:\n");
1973 dsi_vc_flush_receive_data(channel);
1974 }
1975
1976 REG_FLD_MOD(DSI_VC_CTRL(channel), 1, 6, 6); /* BTA_EN */
1977
1978 return 0;
1979}
1980
1981int dsi_vc_send_bta_sync(int channel)
1982{
1983 int r = 0;
1984 u32 err;
1985
1986 INIT_COMPLETION(dsi.bta_completion);
1987
1988 dsi_vc_enable_bta_irq(channel);
1989
1990 r = dsi_vc_send_bta(channel);
1991 if (r)
1992 goto err;
1993
1994 if (wait_for_completion_timeout(&dsi.bta_completion,
1995 msecs_to_jiffies(500)) == 0) {
1996 DSSERR("Failed to receive BTA\n");
1997 r = -EIO;
1998 goto err;
1999 }
2000
2001 err = dsi_get_errors();
2002 if (err) {
2003 DSSERR("Error while sending BTA: %x\n", err);
2004 r = -EIO;
2005 goto err;
2006 }
2007err:
2008 dsi_vc_disable_bta_irq(channel);
2009
2010 return r;
2011}
2012EXPORT_SYMBOL(dsi_vc_send_bta_sync);
2013
2014static inline void dsi_vc_write_long_header(int channel, u8 data_type,
2015 u16 len, u8 ecc)
2016{
2017 u32 val;
2018 u8 data_id;
2019
Tomi Valkeinen4f765022010-01-18 16:27:52 +02002020 WARN_ON(!dsi_bus_is_locked());
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002021
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02002022 data_id = data_type | channel << 6;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002023
2024 val = FLD_VAL(data_id, 7, 0) | FLD_VAL(len, 23, 8) |
2025 FLD_VAL(ecc, 31, 24);
2026
2027 dsi_write_reg(DSI_VC_LONG_PACKET_HEADER(channel), val);
2028}
2029
2030static inline void dsi_vc_write_long_payload(int channel,
2031 u8 b1, u8 b2, u8 b3, u8 b4)
2032{
2033 u32 val;
2034
2035 val = b4 << 24 | b3 << 16 | b2 << 8 | b1 << 0;
2036
2037/* DSSDBG("\twriting %02x, %02x, %02x, %02x (%#010x)\n",
2038 b1, b2, b3, b4, val); */
2039
2040 dsi_write_reg(DSI_VC_LONG_PACKET_PAYLOAD(channel), val);
2041}
2042
2043static int dsi_vc_send_long(int channel, u8 data_type, u8 *data, u16 len,
2044 u8 ecc)
2045{
2046 /*u32 val; */
2047 int i;
2048 u8 *p;
2049 int r = 0;
2050 u8 b1, b2, b3, b4;
2051
2052 if (dsi.debug_write)
2053 DSSDBG("dsi_vc_send_long, %d bytes\n", len);
2054
2055 /* len + header */
2056 if (dsi.vc[channel].fifo_size * 32 * 4 < len + 4) {
2057 DSSERR("unable to send long packet: packet too long.\n");
2058 return -EINVAL;
2059 }
2060
2061 dsi_vc_config_l4(channel);
2062
2063 dsi_vc_write_long_header(channel, data_type, len, ecc);
2064
2065 /*dsi_vc_print_status(0); */
2066
2067 p = data;
2068 for (i = 0; i < len >> 2; i++) {
2069 if (dsi.debug_write)
2070 DSSDBG("\tsending full packet %d\n", i);
2071 /*dsi_vc_print_status(0); */
2072
2073 b1 = *p++;
2074 b2 = *p++;
2075 b3 = *p++;
2076 b4 = *p++;
2077
2078 dsi_vc_write_long_payload(channel, b1, b2, b3, b4);
2079 }
2080
2081 i = len % 4;
2082 if (i) {
2083 b1 = 0; b2 = 0; b3 = 0;
2084
2085 if (dsi.debug_write)
2086 DSSDBG("\tsending remainder bytes %d\n", i);
2087
2088 switch (i) {
2089 case 3:
2090 b1 = *p++;
2091 b2 = *p++;
2092 b3 = *p++;
2093 break;
2094 case 2:
2095 b1 = *p++;
2096 b2 = *p++;
2097 break;
2098 case 1:
2099 b1 = *p++;
2100 break;
2101 }
2102
2103 dsi_vc_write_long_payload(channel, b1, b2, b3, 0);
2104 }
2105
2106 return r;
2107}
2108
2109static int dsi_vc_send_short(int channel, u8 data_type, u16 data, u8 ecc)
2110{
2111 u32 r;
2112 u8 data_id;
2113
Tomi Valkeinen4f765022010-01-18 16:27:52 +02002114 WARN_ON(!dsi_bus_is_locked());
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002115
2116 if (dsi.debug_write)
2117 DSSDBG("dsi_vc_send_short(ch%d, dt %#x, b1 %#x, b2 %#x)\n",
2118 channel,
2119 data_type, data & 0xff, (data >> 8) & 0xff);
2120
2121 dsi_vc_config_l4(channel);
2122
2123 if (FLD_GET(dsi_read_reg(DSI_VC_CTRL(channel)), 16, 16)) {
2124 DSSERR("ERROR FIFO FULL, aborting transfer\n");
2125 return -EINVAL;
2126 }
2127
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02002128 data_id = data_type | channel << 6;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002129
2130 r = (data_id << 0) | (data << 8) | (ecc << 24);
2131
2132 dsi_write_reg(DSI_VC_SHORT_PACKET_HEADER(channel), r);
2133
2134 return 0;
2135}
2136
2137int dsi_vc_send_null(int channel)
2138{
2139 u8 nullpkg[] = {0, 0, 0, 0};
Tomi Valkeinen397bb3c2009-12-03 13:37:31 +02002140 return dsi_vc_send_long(channel, DSI_DT_NULL_PACKET, nullpkg, 4, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002141}
2142EXPORT_SYMBOL(dsi_vc_send_null);
2143
2144int dsi_vc_dcs_write_nosync(int channel, u8 *data, int len)
2145{
2146 int r;
2147
2148 BUG_ON(len == 0);
2149
2150 if (len == 1) {
2151 r = dsi_vc_send_short(channel, DSI_DT_DCS_SHORT_WRITE_0,
2152 data[0], 0);
2153 } else if (len == 2) {
2154 r = dsi_vc_send_short(channel, DSI_DT_DCS_SHORT_WRITE_1,
2155 data[0] | (data[1] << 8), 0);
2156 } else {
2157 /* 0x39 = DCS Long Write */
2158 r = dsi_vc_send_long(channel, DSI_DT_DCS_LONG_WRITE,
2159 data, len, 0);
2160 }
2161
2162 return r;
2163}
2164EXPORT_SYMBOL(dsi_vc_dcs_write_nosync);
2165
2166int dsi_vc_dcs_write(int channel, u8 *data, int len)
2167{
2168 int r;
2169
2170 r = dsi_vc_dcs_write_nosync(channel, data, len);
2171 if (r)
2172 return r;
2173
2174 r = dsi_vc_send_bta_sync(channel);
2175
2176 return r;
2177}
2178EXPORT_SYMBOL(dsi_vc_dcs_write);
2179
Tomi Valkeinen828c48f2009-12-16 14:53:15 +02002180int dsi_vc_dcs_write_0(int channel, u8 dcs_cmd)
2181{
2182 return dsi_vc_dcs_write(channel, &dcs_cmd, 1);
2183}
2184EXPORT_SYMBOL(dsi_vc_dcs_write_0);
2185
2186int dsi_vc_dcs_write_1(int channel, u8 dcs_cmd, u8 param)
2187{
2188 u8 buf[2];
2189 buf[0] = dcs_cmd;
2190 buf[1] = param;
2191 return dsi_vc_dcs_write(channel, buf, 2);
2192}
2193EXPORT_SYMBOL(dsi_vc_dcs_write_1);
2194
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002195int dsi_vc_dcs_read(int channel, u8 dcs_cmd, u8 *buf, int buflen)
2196{
2197 u32 val;
2198 u8 dt;
2199 int r;
2200
2201 if (dsi.debug_read)
Tomi Valkeinenff90a342009-12-03 13:38:04 +02002202 DSSDBG("dsi_vc_dcs_read(ch%d, dcs_cmd %x)\n", channel, dcs_cmd);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002203
2204 r = dsi_vc_send_short(channel, DSI_DT_DCS_READ, dcs_cmd, 0);
2205 if (r)
2206 return r;
2207
2208 r = dsi_vc_send_bta_sync(channel);
2209 if (r)
2210 return r;
2211
2212 /* RX_FIFO_NOT_EMPTY */
2213 if (REG_GET(DSI_VC_CTRL(channel), 20, 20) == 0) {
2214 DSSERR("RX fifo empty when trying to read.\n");
2215 return -EIO;
2216 }
2217
2218 val = dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel));
2219 if (dsi.debug_read)
2220 DSSDBG("\theader: %08x\n", val);
2221 dt = FLD_GET(val, 5, 0);
2222 if (dt == DSI_DT_RX_ACK_WITH_ERR) {
2223 u16 err = FLD_GET(val, 23, 8);
2224 dsi_show_rx_ack_with_err(err);
2225 return -EIO;
2226
2227 } else if (dt == DSI_DT_RX_SHORT_READ_1) {
2228 u8 data = FLD_GET(val, 15, 8);
2229 if (dsi.debug_read)
2230 DSSDBG("\tDCS short response, 1 byte: %02x\n", data);
2231
2232 if (buflen < 1)
2233 return -EIO;
2234
2235 buf[0] = data;
2236
2237 return 1;
2238 } else if (dt == DSI_DT_RX_SHORT_READ_2) {
2239 u16 data = FLD_GET(val, 23, 8);
2240 if (dsi.debug_read)
2241 DSSDBG("\tDCS short response, 2 byte: %04x\n", data);
2242
2243 if (buflen < 2)
2244 return -EIO;
2245
2246 buf[0] = data & 0xff;
2247 buf[1] = (data >> 8) & 0xff;
2248
2249 return 2;
2250 } else if (dt == DSI_DT_RX_DCS_LONG_READ) {
2251 int w;
2252 int len = FLD_GET(val, 23, 8);
2253 if (dsi.debug_read)
2254 DSSDBG("\tDCS long response, len %d\n", len);
2255
2256 if (len > buflen)
2257 return -EIO;
2258
2259 /* two byte checksum ends the packet, not included in len */
2260 for (w = 0; w < len + 2;) {
2261 int b;
2262 val = dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel));
2263 if (dsi.debug_read)
2264 DSSDBG("\t\t%02x %02x %02x %02x\n",
2265 (val >> 0) & 0xff,
2266 (val >> 8) & 0xff,
2267 (val >> 16) & 0xff,
2268 (val >> 24) & 0xff);
2269
2270 for (b = 0; b < 4; ++b) {
2271 if (w < len)
2272 buf[w] = (val >> (b * 8)) & 0xff;
2273 /* we discard the 2 byte checksum */
2274 ++w;
2275 }
2276 }
2277
2278 return len;
2279
2280 } else {
2281 DSSERR("\tunknown datatype 0x%02x\n", dt);
2282 return -EIO;
2283 }
2284}
2285EXPORT_SYMBOL(dsi_vc_dcs_read);
2286
Tomi Valkeinen828c48f2009-12-16 14:53:15 +02002287int dsi_vc_dcs_read_1(int channel, u8 dcs_cmd, u8 *data)
2288{
2289 int r;
2290
2291 r = dsi_vc_dcs_read(channel, dcs_cmd, data, 1);
2292
2293 if (r < 0)
2294 return r;
2295
2296 if (r != 1)
2297 return -EIO;
2298
2299 return 0;
2300}
2301EXPORT_SYMBOL(dsi_vc_dcs_read_1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002302
2303int dsi_vc_set_max_rx_packet_size(int channel, u16 len)
2304{
2305 int r;
2306 r = dsi_vc_send_short(channel, DSI_DT_SET_MAX_RET_PKG_SIZE,
2307 len, 0);
2308
2309 if (r)
2310 return r;
2311
2312 r = dsi_vc_send_bta_sync(channel);
2313
2314 return r;
2315}
2316EXPORT_SYMBOL(dsi_vc_set_max_rx_packet_size);
2317
2318static void dsi_set_lp_rx_timeout(unsigned long ns)
2319{
2320 u32 r;
2321 unsigned x4, x16;
2322 unsigned long fck;
2323 unsigned long ticks;
2324
2325 /* ticks in DSI_FCK */
2326
2327 fck = dsi_fclk_rate();
2328 ticks = (fck / 1000 / 1000) * ns / 1000;
2329 x4 = 0;
2330 x16 = 0;
2331
2332 if (ticks > 0x1fff) {
2333 ticks = (fck / 1000 / 1000) * ns / 1000 / 4;
2334 x4 = 1;
2335 x16 = 0;
2336 }
2337
2338 if (ticks > 0x1fff) {
2339 ticks = (fck / 1000 / 1000) * ns / 1000 / 16;
2340 x4 = 0;
2341 x16 = 1;
2342 }
2343
2344 if (ticks > 0x1fff) {
2345 ticks = (fck / 1000 / 1000) * ns / 1000 / (4 * 16);
2346 x4 = 1;
2347 x16 = 1;
2348 }
2349
2350 if (ticks > 0x1fff) {
2351 DSSWARN("LP_TX_TO over limit, setting it to max\n");
2352 ticks = 0x1fff;
2353 x4 = 1;
2354 x16 = 1;
2355 }
2356
2357 r = dsi_read_reg(DSI_TIMING2);
2358 r = FLD_MOD(r, 1, 15, 15); /* LP_RX_TO */
2359 r = FLD_MOD(r, x16, 14, 14); /* LP_RX_TO_X16 */
2360 r = FLD_MOD(r, x4, 13, 13); /* LP_RX_TO_X4 */
2361 r = FLD_MOD(r, ticks, 12, 0); /* LP_RX_COUNTER */
2362 dsi_write_reg(DSI_TIMING2, r);
2363
2364 DSSDBG("LP_RX_TO %lu ns (%#lx ticks%s%s)\n",
2365 (ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1) * 1000) /
2366 (fck / 1000 / 1000),
2367 ticks, x4 ? " x4" : "", x16 ? " x16" : "");
2368}
2369
2370static void dsi_set_ta_timeout(unsigned long ns)
2371{
2372 u32 r;
2373 unsigned x8, x16;
2374 unsigned long fck;
2375 unsigned long ticks;
2376
2377 /* ticks in DSI_FCK */
2378 fck = dsi_fclk_rate();
2379 ticks = (fck / 1000 / 1000) * ns / 1000;
2380 x8 = 0;
2381 x16 = 0;
2382
2383 if (ticks > 0x1fff) {
2384 ticks = (fck / 1000 / 1000) * ns / 1000 / 8;
2385 x8 = 1;
2386 x16 = 0;
2387 }
2388
2389 if (ticks > 0x1fff) {
2390 ticks = (fck / 1000 / 1000) * ns / 1000 / 16;
2391 x8 = 0;
2392 x16 = 1;
2393 }
2394
2395 if (ticks > 0x1fff) {
2396 ticks = (fck / 1000 / 1000) * ns / 1000 / (8 * 16);
2397 x8 = 1;
2398 x16 = 1;
2399 }
2400
2401 if (ticks > 0x1fff) {
2402 DSSWARN("TA_TO over limit, setting it to max\n");
2403 ticks = 0x1fff;
2404 x8 = 1;
2405 x16 = 1;
2406 }
2407
2408 r = dsi_read_reg(DSI_TIMING1);
2409 r = FLD_MOD(r, 1, 31, 31); /* TA_TO */
2410 r = FLD_MOD(r, x16, 30, 30); /* TA_TO_X16 */
2411 r = FLD_MOD(r, x8, 29, 29); /* TA_TO_X8 */
2412 r = FLD_MOD(r, ticks, 28, 16); /* TA_TO_COUNTER */
2413 dsi_write_reg(DSI_TIMING1, r);
2414
2415 DSSDBG("TA_TO %lu ns (%#lx ticks%s%s)\n",
2416 (ticks * (x16 ? 16 : 1) * (x8 ? 8 : 1) * 1000) /
2417 (fck / 1000 / 1000),
2418 ticks, x8 ? " x8" : "", x16 ? " x16" : "");
2419}
2420
2421static void dsi_set_stop_state_counter(unsigned long ns)
2422{
2423 u32 r;
2424 unsigned x4, x16;
2425 unsigned long fck;
2426 unsigned long ticks;
2427
2428 /* ticks in DSI_FCK */
2429
2430 fck = dsi_fclk_rate();
2431 ticks = (fck / 1000 / 1000) * ns / 1000;
2432 x4 = 0;
2433 x16 = 0;
2434
2435 if (ticks > 0x1fff) {
2436 ticks = (fck / 1000 / 1000) * ns / 1000 / 4;
2437 x4 = 1;
2438 x16 = 0;
2439 }
2440
2441 if (ticks > 0x1fff) {
2442 ticks = (fck / 1000 / 1000) * ns / 1000 / 16;
2443 x4 = 0;
2444 x16 = 1;
2445 }
2446
2447 if (ticks > 0x1fff) {
2448 ticks = (fck / 1000 / 1000) * ns / 1000 / (4 * 16);
2449 x4 = 1;
2450 x16 = 1;
2451 }
2452
2453 if (ticks > 0x1fff) {
2454 DSSWARN("STOP_STATE_COUNTER_IO over limit, "
2455 "setting it to max\n");
2456 ticks = 0x1fff;
2457 x4 = 1;
2458 x16 = 1;
2459 }
2460
2461 r = dsi_read_reg(DSI_TIMING1);
2462 r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
2463 r = FLD_MOD(r, x16, 14, 14); /* STOP_STATE_X16_IO */
2464 r = FLD_MOD(r, x4, 13, 13); /* STOP_STATE_X4_IO */
2465 r = FLD_MOD(r, ticks, 12, 0); /* STOP_STATE_COUNTER_IO */
2466 dsi_write_reg(DSI_TIMING1, r);
2467
2468 DSSDBG("STOP_STATE_COUNTER %lu ns (%#lx ticks%s%s)\n",
2469 (ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1) * 1000) /
2470 (fck / 1000 / 1000),
2471 ticks, x4 ? " x4" : "", x16 ? " x16" : "");
2472}
2473
2474static void dsi_set_hs_tx_timeout(unsigned long ns)
2475{
2476 u32 r;
2477 unsigned x4, x16;
2478 unsigned long fck;
2479 unsigned long ticks;
2480
2481 /* ticks in TxByteClkHS */
2482
2483 fck = dsi_get_txbyteclkhs();
2484 ticks = (fck / 1000 / 1000) * ns / 1000;
2485 x4 = 0;
2486 x16 = 0;
2487
2488 if (ticks > 0x1fff) {
2489 ticks = (fck / 1000 / 1000) * ns / 1000 / 4;
2490 x4 = 1;
2491 x16 = 0;
2492 }
2493
2494 if (ticks > 0x1fff) {
2495 ticks = (fck / 1000 / 1000) * ns / 1000 / 16;
2496 x4 = 0;
2497 x16 = 1;
2498 }
2499
2500 if (ticks > 0x1fff) {
2501 ticks = (fck / 1000 / 1000) * ns / 1000 / (4 * 16);
2502 x4 = 1;
2503 x16 = 1;
2504 }
2505
2506 if (ticks > 0x1fff) {
2507 DSSWARN("HS_TX_TO over limit, setting it to max\n");
2508 ticks = 0x1fff;
2509 x4 = 1;
2510 x16 = 1;
2511 }
2512
2513 r = dsi_read_reg(DSI_TIMING2);
2514 r = FLD_MOD(r, 1, 31, 31); /* HS_TX_TO */
2515 r = FLD_MOD(r, x16, 30, 30); /* HS_TX_TO_X16 */
2516 r = FLD_MOD(r, x4, 29, 29); /* HS_TX_TO_X8 (4 really) */
2517 r = FLD_MOD(r, ticks, 28, 16); /* HS_TX_TO_COUNTER */
2518 dsi_write_reg(DSI_TIMING2, r);
2519
2520 DSSDBG("HS_TX_TO %lu ns (%#lx ticks%s%s)\n",
2521 (ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1) * 1000) /
2522 (fck / 1000 / 1000),
2523 ticks, x4 ? " x4" : "", x16 ? " x16" : "");
2524}
2525static int dsi_proto_config(struct omap_dss_device *dssdev)
2526{
2527 u32 r;
2528 int buswidth = 0;
2529
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02002530 dsi_config_tx_fifo(DSI_FIFO_SIZE_32,
2531 DSI_FIFO_SIZE_32,
2532 DSI_FIFO_SIZE_32,
2533 DSI_FIFO_SIZE_32);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002534
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02002535 dsi_config_rx_fifo(DSI_FIFO_SIZE_32,
2536 DSI_FIFO_SIZE_32,
2537 DSI_FIFO_SIZE_32,
2538 DSI_FIFO_SIZE_32);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002539
2540 /* XXX what values for the timeouts? */
2541 dsi_set_stop_state_counter(1000);
2542 dsi_set_ta_timeout(6400000);
2543 dsi_set_lp_rx_timeout(48000);
2544 dsi_set_hs_tx_timeout(1000000);
2545
2546 switch (dssdev->ctrl.pixel_size) {
2547 case 16:
2548 buswidth = 0;
2549 break;
2550 case 18:
2551 buswidth = 1;
2552 break;
2553 case 24:
2554 buswidth = 2;
2555 break;
2556 default:
2557 BUG();
2558 }
2559
2560 r = dsi_read_reg(DSI_CTRL);
2561 r = FLD_MOD(r, 1, 1, 1); /* CS_RX_EN */
2562 r = FLD_MOD(r, 1, 2, 2); /* ECC_RX_EN */
2563 r = FLD_MOD(r, 1, 3, 3); /* TX_FIFO_ARBITRATION */
2564 r = FLD_MOD(r, 1, 4, 4); /* VP_CLK_RATIO, always 1, see errata*/
2565 r = FLD_MOD(r, buswidth, 7, 6); /* VP_DATA_BUS_WIDTH */
2566 r = FLD_MOD(r, 0, 8, 8); /* VP_CLK_POL */
2567 r = FLD_MOD(r, 2, 13, 12); /* LINE_BUFFER, 2 lines */
2568 r = FLD_MOD(r, 1, 14, 14); /* TRIGGER_RESET_MODE */
2569 r = FLD_MOD(r, 1, 19, 19); /* EOT_ENABLE */
2570 r = FLD_MOD(r, 1, 24, 24); /* DCS_CMD_ENABLE */
2571 r = FLD_MOD(r, 0, 25, 25); /* DCS_CMD_CODE, 1=start, 0=continue */
2572
2573 dsi_write_reg(DSI_CTRL, r);
2574
2575 dsi_vc_initial_config(0);
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02002576 dsi_vc_initial_config(1);
2577 dsi_vc_initial_config(2);
2578 dsi_vc_initial_config(3);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002579
2580 return 0;
2581}
2582
2583static void dsi_proto_timings(struct omap_dss_device *dssdev)
2584{
2585 unsigned tlpx, tclk_zero, tclk_prepare, tclk_trail;
2586 unsigned tclk_pre, tclk_post;
2587 unsigned ths_prepare, ths_prepare_ths_zero, ths_zero;
2588 unsigned ths_trail, ths_exit;
2589 unsigned ddr_clk_pre, ddr_clk_post;
2590 unsigned enter_hs_mode_lat, exit_hs_mode_lat;
2591 unsigned ths_eot;
2592 u32 r;
2593
2594 r = dsi_read_reg(DSI_DSIPHY_CFG0);
2595 ths_prepare = FLD_GET(r, 31, 24);
2596 ths_prepare_ths_zero = FLD_GET(r, 23, 16);
2597 ths_zero = ths_prepare_ths_zero - ths_prepare;
2598 ths_trail = FLD_GET(r, 15, 8);
2599 ths_exit = FLD_GET(r, 7, 0);
2600
2601 r = dsi_read_reg(DSI_DSIPHY_CFG1);
2602 tlpx = FLD_GET(r, 22, 16) * 2;
2603 tclk_trail = FLD_GET(r, 15, 8);
2604 tclk_zero = FLD_GET(r, 7, 0);
2605
2606 r = dsi_read_reg(DSI_DSIPHY_CFG2);
2607 tclk_prepare = FLD_GET(r, 7, 0);
2608
2609 /* min 8*UI */
2610 tclk_pre = 20;
2611 /* min 60ns + 52*UI */
2612 tclk_post = ns2ddr(60) + 26;
2613
2614 /* ths_eot is 2 for 2 datalanes and 4 for 1 datalane */
2615 if (dssdev->phy.dsi.data1_lane != 0 &&
2616 dssdev->phy.dsi.data2_lane != 0)
2617 ths_eot = 2;
2618 else
2619 ths_eot = 4;
2620
2621 ddr_clk_pre = DIV_ROUND_UP(tclk_pre + tlpx + tclk_zero + tclk_prepare,
2622 4);
2623 ddr_clk_post = DIV_ROUND_UP(tclk_post + ths_trail, 4) + ths_eot;
2624
2625 BUG_ON(ddr_clk_pre == 0 || ddr_clk_pre > 255);
2626 BUG_ON(ddr_clk_post == 0 || ddr_clk_post > 255);
2627
2628 r = dsi_read_reg(DSI_CLK_TIMING);
2629 r = FLD_MOD(r, ddr_clk_pre, 15, 8);
2630 r = FLD_MOD(r, ddr_clk_post, 7, 0);
2631 dsi_write_reg(DSI_CLK_TIMING, r);
2632
2633 DSSDBG("ddr_clk_pre %u, ddr_clk_post %u\n",
2634 ddr_clk_pre,
2635 ddr_clk_post);
2636
2637 enter_hs_mode_lat = 1 + DIV_ROUND_UP(tlpx, 4) +
2638 DIV_ROUND_UP(ths_prepare, 4) +
2639 DIV_ROUND_UP(ths_zero + 3, 4);
2640
2641 exit_hs_mode_lat = DIV_ROUND_UP(ths_trail + ths_exit, 4) + 1 + ths_eot;
2642
2643 r = FLD_VAL(enter_hs_mode_lat, 31, 16) |
2644 FLD_VAL(exit_hs_mode_lat, 15, 0);
2645 dsi_write_reg(DSI_VM_TIMING7, r);
2646
2647 DSSDBG("enter_hs_mode_lat %u, exit_hs_mode_lat %u\n",
2648 enter_hs_mode_lat, exit_hs_mode_lat);
2649}
2650
2651
2652#define DSI_DECL_VARS \
2653 int __dsi_cb = 0; u32 __dsi_cv = 0;
2654
2655#define DSI_FLUSH(ch) \
2656 if (__dsi_cb > 0) { \
2657 /*DSSDBG("sending long packet %#010x\n", __dsi_cv);*/ \
2658 dsi_write_reg(DSI_VC_LONG_PACKET_PAYLOAD(ch), __dsi_cv); \
2659 __dsi_cb = __dsi_cv = 0; \
2660 }
2661
2662#define DSI_PUSH(ch, data) \
2663 do { \
2664 __dsi_cv |= (data) << (__dsi_cb * 8); \
2665 /*DSSDBG("cv = %#010x, cb = %d\n", __dsi_cv, __dsi_cb);*/ \
2666 if (++__dsi_cb > 3) \
2667 DSI_FLUSH(ch); \
2668 } while (0)
2669
2670static int dsi_update_screen_l4(struct omap_dss_device *dssdev,
2671 int x, int y, int w, int h)
2672{
2673 /* Note: supports only 24bit colors in 32bit container */
2674 int first = 1;
2675 int fifo_stalls = 0;
2676 int max_dsi_packet_size;
2677 int max_data_per_packet;
2678 int max_pixels_per_packet;
2679 int pixels_left;
2680 int bytespp = dssdev->ctrl.pixel_size / 8;
2681 int scr_width;
2682 u32 __iomem *data;
2683 int start_offset;
2684 int horiz_inc;
2685 int current_x;
2686 struct omap_overlay *ovl;
2687
2688 debug_irq = 0;
2689
2690 DSSDBG("dsi_update_screen_l4 (%d,%d %dx%d)\n",
2691 x, y, w, h);
2692
2693 ovl = dssdev->manager->overlays[0];
2694
2695 if (ovl->info.color_mode != OMAP_DSS_COLOR_RGB24U)
2696 return -EINVAL;
2697
2698 if (dssdev->ctrl.pixel_size != 24)
2699 return -EINVAL;
2700
2701 scr_width = ovl->info.screen_width;
2702 data = ovl->info.vaddr;
2703
2704 start_offset = scr_width * y + x;
2705 horiz_inc = scr_width - w;
2706 current_x = x;
2707
2708 /* We need header(4) + DCSCMD(1) + pixels(numpix*bytespp) bytes
2709 * in fifo */
2710
2711 /* When using CPU, max long packet size is TX buffer size */
2712 max_dsi_packet_size = dsi.vc[0].fifo_size * 32 * 4;
2713
2714 /* we seem to get better perf if we divide the tx fifo to half,
2715 and while the other half is being sent, we fill the other half
2716 max_dsi_packet_size /= 2; */
2717
2718 max_data_per_packet = max_dsi_packet_size - 4 - 1;
2719
2720 max_pixels_per_packet = max_data_per_packet / bytespp;
2721
2722 DSSDBG("max_pixels_per_packet %d\n", max_pixels_per_packet);
2723
2724 pixels_left = w * h;
2725
2726 DSSDBG("total pixels %d\n", pixels_left);
2727
2728 data += start_offset;
2729
2730 while (pixels_left > 0) {
2731 /* 0x2c = write_memory_start */
2732 /* 0x3c = write_memory_continue */
2733 u8 dcs_cmd = first ? 0x2c : 0x3c;
2734 int pixels;
2735 DSI_DECL_VARS;
2736 first = 0;
2737
2738#if 1
2739 /* using fifo not empty */
2740 /* TX_FIFO_NOT_EMPTY */
2741 while (FLD_GET(dsi_read_reg(DSI_VC_CTRL(0)), 5, 5)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002742 fifo_stalls++;
2743 if (fifo_stalls > 0xfffff) {
2744 DSSERR("fifo stalls overflow, pixels left %d\n",
2745 pixels_left);
2746 dsi_if_enable(0);
2747 return -EIO;
2748 }
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02002749 udelay(1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002750 }
2751#elif 1
2752 /* using fifo emptiness */
2753 while ((REG_GET(DSI_TX_FIFO_VC_EMPTINESS, 7, 0)+1)*4 <
2754 max_dsi_packet_size) {
2755 fifo_stalls++;
2756 if (fifo_stalls > 0xfffff) {
2757 DSSERR("fifo stalls overflow, pixels left %d\n",
2758 pixels_left);
2759 dsi_if_enable(0);
2760 return -EIO;
2761 }
2762 }
2763#else
2764 while ((REG_GET(DSI_TX_FIFO_VC_EMPTINESS, 7, 0)+1)*4 == 0) {
2765 fifo_stalls++;
2766 if (fifo_stalls > 0xfffff) {
2767 DSSERR("fifo stalls overflow, pixels left %d\n",
2768 pixels_left);
2769 dsi_if_enable(0);
2770 return -EIO;
2771 }
2772 }
2773#endif
2774 pixels = min(max_pixels_per_packet, pixels_left);
2775
2776 pixels_left -= pixels;
2777
2778 dsi_vc_write_long_header(0, DSI_DT_DCS_LONG_WRITE,
2779 1 + pixels * bytespp, 0);
2780
2781 DSI_PUSH(0, dcs_cmd);
2782
2783 while (pixels-- > 0) {
2784 u32 pix = __raw_readl(data++);
2785
2786 DSI_PUSH(0, (pix >> 16) & 0xff);
2787 DSI_PUSH(0, (pix >> 8) & 0xff);
2788 DSI_PUSH(0, (pix >> 0) & 0xff);
2789
2790 current_x++;
2791 if (current_x == x+w) {
2792 current_x = x;
2793 data += horiz_inc;
2794 }
2795 }
2796
2797 DSI_FLUSH(0);
2798 }
2799
2800 return 0;
2801}
2802
2803static void dsi_update_screen_dispc(struct omap_dss_device *dssdev,
2804 u16 x, u16 y, u16 w, u16 h)
2805{
2806 unsigned bytespp;
2807 unsigned bytespl;
2808 unsigned bytespf;
2809 unsigned total_len;
2810 unsigned packet_payload;
2811 unsigned packet_len;
2812 u32 l;
2813 bool use_te_trigger;
2814 const unsigned channel = 0;
2815 /* line buffer is 1024 x 24bits */
2816 /* XXX: for some reason using full buffer size causes considerable TX
2817 * slowdown with update sizes that fill the whole buffer */
2818 const unsigned line_buf_size = 1023 * 3;
2819
2820 use_te_trigger = dsi.te_enabled && !dsi.use_ext_te;
2821
2822 if (dsi.update_mode != OMAP_DSS_UPDATE_AUTO)
2823 DSSDBG("dsi_update_screen_dispc(%d,%d %dx%d)\n",
2824 x, y, w, h);
2825
2826 bytespp = dssdev->ctrl.pixel_size / 8;
2827 bytespl = w * bytespp;
2828 bytespf = bytespl * h;
2829
2830 /* NOTE: packet_payload has to be equal to N * bytespl, where N is
2831 * number of lines in a packet. See errata about VP_CLK_RATIO */
2832
2833 if (bytespf < line_buf_size)
2834 packet_payload = bytespf;
2835 else
2836 packet_payload = (line_buf_size) / bytespl * bytespl;
2837
2838 packet_len = packet_payload + 1; /* 1 byte for DCS cmd */
2839 total_len = (bytespf / packet_payload) * packet_len;
2840
2841 if (bytespf % packet_payload)
2842 total_len += (bytespf % packet_payload) + 1;
2843
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002844 l = FLD_VAL(total_len, 23, 0); /* TE_SIZE */
2845 dsi_write_reg(DSI_VC_TE(channel), l);
2846
2847 dsi_vc_write_long_header(channel, DSI_DT_DCS_LONG_WRITE, packet_len, 0);
2848
2849 if (use_te_trigger)
2850 l = FLD_MOD(l, 1, 30, 30); /* TE_EN */
2851 else
2852 l = FLD_MOD(l, 1, 31, 31); /* TE_START */
2853 dsi_write_reg(DSI_VC_TE(channel), l);
2854
2855 /* We put SIDLEMODE to no-idle for the duration of the transfer,
2856 * because DSS interrupts are not capable of waking up the CPU and the
2857 * framedone interrupt could be delayed for quite a long time. I think
2858 * the same goes for any DSS interrupts, but for some reason I have not
2859 * seen the problem anywhere else than here.
2860 */
2861 dispc_disable_sidle();
2862
2863 dss_start_update(dssdev);
2864
2865 if (use_te_trigger) {
2866 /* disable LP_RX_TO, so that we can receive TE. Time to wait
2867 * for TE is longer than the timer allows */
2868 REG_FLD_MOD(DSI_TIMING2, 0, 15, 15); /* LP_RX_TO */
2869
2870 dsi_vc_send_bta(channel);
2871
2872#ifdef DSI_CATCH_MISSING_TE
2873 mod_timer(&dsi.te_timer, jiffies + msecs_to_jiffies(250));
2874#endif
2875 }
2876}
2877
2878#ifdef DSI_CATCH_MISSING_TE
2879static void dsi_te_timeout(unsigned long arg)
2880{
2881 DSSERR("TE not received for 250ms!\n");
2882}
2883#endif
2884
2885static void dsi_framedone_irq_callback(void *data, u32 mask)
2886{
2887 /* Note: We get FRAMEDONE when DISPC has finished sending pixels and
2888 * turns itself off. However, DSI still has the pixels in its buffers,
2889 * and is sending the data.
2890 */
2891
2892 /* SIDLEMODE back to smart-idle */
2893 dispc_enable_sidle();
2894
2895 dsi.framedone_received = true;
2896 wake_up(&dsi.waitqueue);
2897}
2898
2899static void dsi_set_update_region(struct omap_dss_device *dssdev,
2900 u16 x, u16 y, u16 w, u16 h)
2901{
2902 spin_lock(&dsi.update_lock);
2903 if (dsi.update_region.dirty) {
2904 dsi.update_region.x = min(x, dsi.update_region.x);
2905 dsi.update_region.y = min(y, dsi.update_region.y);
2906 dsi.update_region.w = max(w, dsi.update_region.w);
2907 dsi.update_region.h = max(h, dsi.update_region.h);
2908 } else {
2909 dsi.update_region.x = x;
2910 dsi.update_region.y = y;
2911 dsi.update_region.w = w;
2912 dsi.update_region.h = h;
2913 }
2914
2915 dsi.update_region.device = dssdev;
2916 dsi.update_region.dirty = true;
2917
2918 spin_unlock(&dsi.update_lock);
2919
2920}
2921
2922static int dsi_set_update_mode(struct omap_dss_device *dssdev,
2923 enum omap_dss_update_mode mode)
2924{
2925 int r = 0;
2926 int i;
2927
Tomi Valkeinen4f765022010-01-18 16:27:52 +02002928 WARN_ON(!dsi_bus_is_locked());
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002929
2930 if (dsi.update_mode != mode) {
2931 dsi.update_mode = mode;
2932
2933 /* Mark the overlays dirty, and do apply(), so that we get the
2934 * overlays configured properly after update mode change. */
2935 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
2936 struct omap_overlay *ovl;
2937 ovl = omap_dss_get_overlay(i);
2938 if (ovl->manager == dssdev->manager)
2939 ovl->info_dirty = true;
2940 }
2941
2942 r = dssdev->manager->apply(dssdev->manager);
2943
2944 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE &&
2945 mode == OMAP_DSS_UPDATE_AUTO) {
2946 u16 w, h;
2947
2948 DSSDBG("starting auto update\n");
2949
2950 dssdev->get_resolution(dssdev, &w, &h);
2951
2952 dsi_set_update_region(dssdev, 0, 0, w, h);
2953
2954 dsi_perf_mark_start_auto();
2955
2956 wake_up(&dsi.waitqueue);
2957 }
2958 }
2959
2960 return r;
2961}
2962
2963static int dsi_set_te(struct omap_dss_device *dssdev, bool enable)
2964{
Tomi Valkeinen7475e442009-12-08 17:30:24 +02002965 int r = 0;
2966
2967 if (dssdev->driver->enable_te) {
2968 r = dssdev->driver->enable_te(dssdev, enable);
2969 /* XXX for some reason, DSI TE breaks if we don't wait here.
2970 * Panel bug? Needs more studying */
2971 msleep(100);
2972 }
2973
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002974 return r;
2975}
2976
2977static void dsi_handle_framedone(void)
2978{
2979 int r;
2980 const int channel = 0;
2981 bool use_te_trigger;
2982
2983 use_te_trigger = dsi.te_enabled && !dsi.use_ext_te;
2984
2985 if (dsi.update_mode != OMAP_DSS_UPDATE_AUTO)
2986 DSSDBG("FRAMEDONE\n");
2987
2988 if (use_te_trigger) {
2989 /* enable LP_RX_TO again after the TE */
2990 REG_FLD_MOD(DSI_TIMING2, 1, 15, 15); /* LP_RX_TO */
2991 }
2992
2993 /* Send BTA after the frame. We need this for the TE to work, as TE
2994 * trigger is only sent for BTAs without preceding packet. Thus we need
2995 * to BTA after the pixel packets so that next BTA will cause TE
2996 * trigger.
2997 *
2998 * This is not needed when TE is not in use, but we do it anyway to
2999 * make sure that the transfer has been completed. It would be more
3000 * optimal, but more complex, to wait only just before starting next
3001 * transfer. */
3002 r = dsi_vc_send_bta_sync(channel);
3003 if (r)
3004 DSSERR("BTA after framedone failed\n");
3005
3006 /* RX_FIFO_NOT_EMPTY */
3007 if (REG_GET(DSI_VC_CTRL(channel), 20, 20)) {
3008 DSSERR("Received error during frame transfer:\n");
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02003009 dsi_vc_flush_receive_data(channel);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003010 }
3011
3012#ifdef CONFIG_OMAP2_DSS_FAKE_VSYNC
3013 dispc_fake_vsync_irq();
3014#endif
3015}
3016
3017static int dsi_update_thread(void *data)
3018{
3019 unsigned long timeout;
3020 struct omap_dss_device *device;
3021 u16 x, y, w, h;
3022
3023 while (1) {
3024 bool sched;
3025
3026 wait_event_interruptible(dsi.waitqueue,
3027 dsi.update_mode == OMAP_DSS_UPDATE_AUTO ||
3028 (dsi.update_mode == OMAP_DSS_UPDATE_MANUAL &&
3029 dsi.update_region.dirty == true) ||
3030 kthread_should_stop());
3031
3032 if (kthread_should_stop())
3033 break;
3034
3035 dsi_bus_lock();
3036
3037 if (dsi.update_mode == OMAP_DSS_UPDATE_DISABLED ||
3038 kthread_should_stop()) {
3039 dsi_bus_unlock();
3040 break;
3041 }
3042
3043 dsi_perf_mark_setup();
3044
3045 if (dsi.update_region.dirty) {
3046 spin_lock(&dsi.update_lock);
3047 dsi.active_update_region = dsi.update_region;
3048 dsi.update_region.dirty = false;
3049 spin_unlock(&dsi.update_lock);
3050 }
3051
3052 device = dsi.active_update_region.device;
3053 x = dsi.active_update_region.x;
3054 y = dsi.active_update_region.y;
3055 w = dsi.active_update_region.w;
3056 h = dsi.active_update_region.h;
3057
3058 if (device->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) {
3059
3060 if (dsi.update_mode == OMAP_DSS_UPDATE_MANUAL)
3061 dss_setup_partial_planes(device,
3062 &x, &y, &w, &h);
3063
3064 dispc_set_lcd_size(w, h);
3065 }
3066
3067 if (dsi.active_update_region.dirty) {
3068 dsi.active_update_region.dirty = false;
3069 /* XXX TODO we don't need to send the coords, if they
3070 * are the same that are already programmed to the
3071 * panel. That should speed up manual update a bit */
3072 device->driver->setup_update(device, x, y, w, h);
3073 }
3074
3075 dsi_perf_mark_start();
3076
3077 if (device->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) {
3078 dsi_vc_config_vp(0);
3079
3080 if (dsi.te_enabled && dsi.use_ext_te)
3081 device->driver->wait_for_te(device);
3082
3083 dsi.framedone_received = false;
3084
3085 dsi_update_screen_dispc(device, x, y, w, h);
3086
3087 /* wait for framedone */
3088 timeout = msecs_to_jiffies(1000);
3089 wait_event_timeout(dsi.waitqueue,
3090 dsi.framedone_received == true,
3091 timeout);
3092
3093 if (!dsi.framedone_received) {
3094 DSSERR("framedone timeout\n");
3095 DSSERR("failed update %d,%d %dx%d\n",
3096 x, y, w, h);
3097
3098 dispc_enable_sidle();
3099 dispc_enable_lcd_out(0);
3100
3101 dsi_reset_tx_fifo(0);
3102 } else {
3103 dsi_handle_framedone();
3104 dsi_perf_show("DISPC");
3105 }
3106 } else {
3107 dsi_update_screen_l4(device, x, y, w, h);
3108 dsi_perf_show("L4");
3109 }
3110
3111 sched = atomic_read(&dsi.bus_lock.count) < 0;
3112
3113 complete_all(&dsi.update_completion);
3114
3115 dsi_bus_unlock();
3116
3117 /* XXX We need to give others chance to get the bus lock. Is
3118 * there a better way for this? */
3119 if (dsi.update_mode == OMAP_DSS_UPDATE_AUTO && sched)
3120 schedule_timeout_interruptible(1);
3121 }
3122
3123 DSSDBG("update thread exiting\n");
3124
3125 return 0;
3126}
3127
3128
3129
3130/* Display funcs */
3131
3132static int dsi_display_init_dispc(struct omap_dss_device *dssdev)
3133{
3134 int r;
3135
3136 r = omap_dispc_register_isr(dsi_framedone_irq_callback, NULL,
3137 DISPC_IRQ_FRAMEDONE);
3138 if (r) {
3139 DSSERR("can't get FRAMEDONE irq\n");
3140 return r;
3141 }
3142
3143 dispc_set_lcd_display_type(OMAP_DSS_LCD_DISPLAY_TFT);
3144
3145 dispc_set_parallel_interface_mode(OMAP_DSS_PARALLELMODE_DSI);
3146 dispc_enable_fifohandcheck(1);
3147
3148 dispc_set_tft_data_lines(dssdev->ctrl.pixel_size);
3149
3150 {
3151 struct omap_video_timings timings = {
3152 .hsw = 1,
3153 .hfp = 1,
3154 .hbp = 1,
3155 .vsw = 1,
3156 .vfp = 0,
3157 .vbp = 0,
3158 };
3159
3160 dispc_set_lcd_timings(&timings);
3161 }
3162
3163 return 0;
3164}
3165
3166static void dsi_display_uninit_dispc(struct omap_dss_device *dssdev)
3167{
3168 omap_dispc_unregister_isr(dsi_framedone_irq_callback, NULL,
3169 DISPC_IRQ_FRAMEDONE);
3170}
3171
3172static int dsi_configure_dsi_clocks(struct omap_dss_device *dssdev)
3173{
3174 struct dsi_clock_info cinfo;
3175 int r;
3176
3177 /* we always use DSS2_FCK as input clock */
3178 cinfo.use_dss2_fck = true;
3179 cinfo.regn = dssdev->phy.dsi.div.regn;
3180 cinfo.regm = dssdev->phy.dsi.div.regm;
3181 cinfo.regm3 = dssdev->phy.dsi.div.regm3;
3182 cinfo.regm4 = dssdev->phy.dsi.div.regm4;
3183 r = dsi_calc_clock_rates(&cinfo);
3184 if (r)
3185 return r;
3186
3187 r = dsi_pll_set_clock_div(&cinfo);
3188 if (r) {
3189 DSSERR("Failed to set dsi clocks\n");
3190 return r;
3191 }
3192
3193 return 0;
3194}
3195
3196static int dsi_configure_dispc_clocks(struct omap_dss_device *dssdev)
3197{
3198 struct dispc_clock_info dispc_cinfo;
3199 int r;
3200 unsigned long long fck;
3201
3202 fck = dsi_get_dsi1_pll_rate();
3203
3204 dispc_cinfo.lck_div = dssdev->phy.dsi.div.lck_div;
3205 dispc_cinfo.pck_div = dssdev->phy.dsi.div.pck_div;
3206
3207 r = dispc_calc_clock_rates(fck, &dispc_cinfo);
3208 if (r) {
3209 DSSERR("Failed to calc dispc clocks\n");
3210 return r;
3211 }
3212
3213 r = dispc_set_clock_div(&dispc_cinfo);
3214 if (r) {
3215 DSSERR("Failed to set dispc clocks\n");
3216 return r;
3217 }
3218
3219 return 0;
3220}
3221
3222static int dsi_display_init_dsi(struct omap_dss_device *dssdev)
3223{
3224 int r;
3225
3226 _dsi_print_reset_status();
3227
3228 r = dsi_pll_init(dssdev, true, true);
3229 if (r)
3230 goto err0;
3231
3232 r = dsi_configure_dsi_clocks(dssdev);
3233 if (r)
3234 goto err1;
3235
Tomi Valkeinen2f18c4d2010-01-08 18:00:36 +02003236 dss_select_dispc_clk_source(DSS_SRC_DSI1_PLL_FCLK);
3237 dss_select_dsi_clk_source(DSS_SRC_DSI2_PLL_FCLK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003238
3239 DSSDBG("PLL OK\n");
3240
3241 r = dsi_configure_dispc_clocks(dssdev);
3242 if (r)
3243 goto err2;
3244
3245 r = dsi_complexio_init(dssdev);
3246 if (r)
3247 goto err2;
3248
3249 _dsi_print_reset_status();
3250
3251 dsi_proto_timings(dssdev);
3252 dsi_set_lp_clk_divisor(dssdev);
3253
3254 if (1)
3255 _dsi_print_reset_status();
3256
3257 r = dsi_proto_config(dssdev);
3258 if (r)
3259 goto err3;
3260
3261 /* enable interface */
3262 dsi_vc_enable(0, 1);
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02003263 dsi_vc_enable(1, 1);
3264 dsi_vc_enable(2, 1);
3265 dsi_vc_enable(3, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003266 dsi_if_enable(1);
3267 dsi_force_tx_stop_mode_io();
3268
3269 if (dssdev->driver->enable) {
3270 r = dssdev->driver->enable(dssdev);
3271 if (r)
3272 goto err4;
3273 }
3274
3275 /* enable high-speed after initial config */
Tomi Valkeinen61140c92010-01-12 16:00:30 +02003276 omapdss_dsi_vc_enable_hs(0, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003277
3278 return 0;
3279err4:
3280 dsi_if_enable(0);
3281err3:
3282 dsi_complexio_uninit();
3283err2:
Tomi Valkeinen2f18c4d2010-01-08 18:00:36 +02003284 dss_select_dispc_clk_source(DSS_SRC_DSS1_ALWON_FCLK);
3285 dss_select_dsi_clk_source(DSS_SRC_DSS1_ALWON_FCLK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003286err1:
3287 dsi_pll_uninit();
3288err0:
3289 return r;
3290}
3291
3292static void dsi_display_uninit_dsi(struct omap_dss_device *dssdev)
3293{
3294 if (dssdev->driver->disable)
3295 dssdev->driver->disable(dssdev);
3296
Tomi Valkeinen2f18c4d2010-01-08 18:00:36 +02003297 dss_select_dispc_clk_source(DSS_SRC_DSS1_ALWON_FCLK);
3298 dss_select_dsi_clk_source(DSS_SRC_DSS1_ALWON_FCLK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003299 dsi_complexio_uninit();
3300 dsi_pll_uninit();
3301}
3302
3303static int dsi_core_init(void)
3304{
3305 /* Autoidle */
3306 REG_FLD_MOD(DSI_SYSCONFIG, 1, 0, 0);
3307
3308 /* ENWAKEUP */
3309 REG_FLD_MOD(DSI_SYSCONFIG, 1, 2, 2);
3310
3311 /* SIDLEMODE smart-idle */
3312 REG_FLD_MOD(DSI_SYSCONFIG, 2, 4, 3);
3313
3314 _dsi_initialize_irq();
3315
3316 return 0;
3317}
3318
3319static int dsi_display_enable(struct omap_dss_device *dssdev)
3320{
3321 int r = 0;
3322
3323 DSSDBG("dsi_display_enable\n");
3324
3325 mutex_lock(&dsi.lock);
3326 dsi_bus_lock();
3327
3328 r = omap_dss_start_device(dssdev);
3329 if (r) {
3330 DSSERR("failed to start device\n");
3331 goto err0;
3332 }
3333
3334 if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
3335 DSSERR("dssdev already enabled\n");
3336 r = -EINVAL;
3337 goto err1;
3338 }
3339
3340 enable_clocks(1);
3341 dsi_enable_pll_clock(1);
3342
3343 r = _dsi_reset();
3344 if (r)
3345 goto err2;
3346
3347 dsi_core_init();
3348
3349 r = dsi_display_init_dispc(dssdev);
3350 if (r)
3351 goto err2;
3352
3353 r = dsi_display_init_dsi(dssdev);
3354 if (r)
3355 goto err3;
3356
3357 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
3358
3359 dsi.use_ext_te = dssdev->phy.dsi.ext_te;
3360 r = dsi_set_te(dssdev, dsi.te_enabled);
3361 if (r)
3362 goto err4;
3363
3364 dsi_set_update_mode(dssdev, dsi.user_update_mode);
3365
3366 dsi_bus_unlock();
3367 mutex_unlock(&dsi.lock);
3368
3369 return 0;
3370
3371err4:
3372
3373 dsi_display_uninit_dsi(dssdev);
3374err3:
3375 dsi_display_uninit_dispc(dssdev);
3376err2:
3377 enable_clocks(0);
3378 dsi_enable_pll_clock(0);
3379err1:
3380 omap_dss_stop_device(dssdev);
3381err0:
3382 dsi_bus_unlock();
3383 mutex_unlock(&dsi.lock);
3384 DSSDBG("dsi_display_enable FAILED\n");
3385 return r;
3386}
3387
3388static void dsi_display_disable(struct omap_dss_device *dssdev)
3389{
3390 DSSDBG("dsi_display_disable\n");
3391
3392 mutex_lock(&dsi.lock);
3393 dsi_bus_lock();
3394
3395 if (dssdev->state == OMAP_DSS_DISPLAY_DISABLED ||
3396 dssdev->state == OMAP_DSS_DISPLAY_SUSPENDED)
3397 goto end;
3398
3399 dsi.update_mode = OMAP_DSS_UPDATE_DISABLED;
3400 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
3401
3402 dsi_display_uninit_dispc(dssdev);
3403
3404 dsi_display_uninit_dsi(dssdev);
3405
3406 enable_clocks(0);
3407 dsi_enable_pll_clock(0);
3408
3409 omap_dss_stop_device(dssdev);
3410end:
3411 dsi_bus_unlock();
3412 mutex_unlock(&dsi.lock);
3413}
3414
3415static int dsi_display_suspend(struct omap_dss_device *dssdev)
3416{
3417 DSSDBG("dsi_display_suspend\n");
3418
3419 mutex_lock(&dsi.lock);
3420 dsi_bus_lock();
3421
3422 if (dssdev->state == OMAP_DSS_DISPLAY_DISABLED ||
3423 dssdev->state == OMAP_DSS_DISPLAY_SUSPENDED)
3424 goto end;
3425
3426 dsi.update_mode = OMAP_DSS_UPDATE_DISABLED;
3427 dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
3428
3429 dsi_display_uninit_dispc(dssdev);
3430
3431 dsi_display_uninit_dsi(dssdev);
3432
3433 enable_clocks(0);
3434 dsi_enable_pll_clock(0);
3435end:
3436 dsi_bus_unlock();
3437 mutex_unlock(&dsi.lock);
3438
3439 return 0;
3440}
3441
3442static int dsi_display_resume(struct omap_dss_device *dssdev)
3443{
3444 int r;
3445
3446 DSSDBG("dsi_display_resume\n");
3447
3448 mutex_lock(&dsi.lock);
3449 dsi_bus_lock();
3450
3451 if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) {
3452 DSSERR("dssdev not suspended\n");
3453 r = -EINVAL;
3454 goto err0;
3455 }
3456
3457 enable_clocks(1);
3458 dsi_enable_pll_clock(1);
3459
3460 r = _dsi_reset();
3461 if (r)
3462 goto err1;
3463
3464 dsi_core_init();
3465
3466 r = dsi_display_init_dispc(dssdev);
3467 if (r)
3468 goto err1;
3469
3470 r = dsi_display_init_dsi(dssdev);
3471 if (r)
3472 goto err2;
3473
3474 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
3475
3476 r = dsi_set_te(dssdev, dsi.te_enabled);
3477 if (r)
3478 goto err2;
3479
3480 dsi_set_update_mode(dssdev, dsi.user_update_mode);
3481
3482 dsi_bus_unlock();
3483 mutex_unlock(&dsi.lock);
3484
3485 return 0;
3486
3487err2:
3488 dsi_display_uninit_dispc(dssdev);
3489err1:
3490 enable_clocks(0);
3491 dsi_enable_pll_clock(0);
3492err0:
3493 dsi_bus_unlock();
3494 mutex_unlock(&dsi.lock);
3495 DSSDBG("dsi_display_resume FAILED\n");
3496 return r;
3497}
3498
3499static int dsi_display_update(struct omap_dss_device *dssdev,
3500 u16 x, u16 y, u16 w, u16 h)
3501{
3502 int r = 0;
3503 u16 dw, dh;
3504
3505 DSSDBG("dsi_display_update(%d,%d %dx%d)\n", x, y, w, h);
3506
3507 mutex_lock(&dsi.lock);
3508
3509 if (dsi.update_mode != OMAP_DSS_UPDATE_MANUAL)
3510 goto end;
3511
3512 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
3513 goto end;
3514
3515 dssdev->get_resolution(dssdev, &dw, &dh);
3516
3517 if (x > dw || y > dh)
3518 goto end;
3519
3520 if (x + w > dw)
3521 w = dw - x;
3522
3523 if (y + h > dh)
3524 h = dh - y;
3525
3526 if (w == 0 || h == 0)
3527 goto end;
3528
3529 if (w == 1) {
3530 r = -EINVAL;
3531 goto end;
3532 }
3533
3534 dsi_set_update_region(dssdev, x, y, w, h);
3535
3536 wake_up(&dsi.waitqueue);
3537
3538end:
3539 mutex_unlock(&dsi.lock);
3540
3541 return r;
3542}
3543
3544static int dsi_display_sync(struct omap_dss_device *dssdev)
3545{
3546 bool wait;
3547
3548 DSSDBG("dsi_display_sync()\n");
3549
3550 mutex_lock(&dsi.lock);
3551 dsi_bus_lock();
3552
3553 if (dsi.update_mode == OMAP_DSS_UPDATE_MANUAL &&
3554 dsi.update_region.dirty) {
3555 INIT_COMPLETION(dsi.update_completion);
3556 wait = true;
3557 } else {
3558 wait = false;
3559 }
3560
3561 dsi_bus_unlock();
3562 mutex_unlock(&dsi.lock);
3563
3564 if (wait)
3565 wait_for_completion_interruptible(&dsi.update_completion);
3566
3567 DSSDBG("dsi_display_sync() done\n");
3568 return 0;
3569}
3570
3571static int dsi_display_set_update_mode(struct omap_dss_device *dssdev,
3572 enum omap_dss_update_mode mode)
3573{
3574 int r = 0;
3575
3576 DSSDBGF("%d", mode);
3577
3578 mutex_lock(&dsi.lock);
3579 dsi_bus_lock();
3580
3581 dsi.user_update_mode = mode;
3582 r = dsi_set_update_mode(dssdev, mode);
3583
3584 dsi_bus_unlock();
3585 mutex_unlock(&dsi.lock);
3586
3587 return r;
3588}
3589
3590static enum omap_dss_update_mode dsi_display_get_update_mode(
3591 struct omap_dss_device *dssdev)
3592{
3593 return dsi.update_mode;
3594}
3595
3596
3597static int dsi_display_enable_te(struct omap_dss_device *dssdev, bool enable)
3598{
3599 int r = 0;
3600
3601 DSSDBGF("%d", enable);
3602
3603 if (!dssdev->driver->enable_te)
3604 return -ENOENT;
3605
3606 dsi_bus_lock();
3607
3608 dsi.te_enabled = enable;
3609
3610 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
3611 goto end;
3612
3613 r = dsi_set_te(dssdev, enable);
3614end:
3615 dsi_bus_unlock();
3616
3617 return r;
3618}
3619
3620static int dsi_display_get_te(struct omap_dss_device *dssdev)
3621{
3622 return dsi.te_enabled;
3623}
3624
3625static int dsi_display_set_rotate(struct omap_dss_device *dssdev, u8 rotate)
3626{
3627
3628 DSSDBGF("%d", rotate);
3629
3630 if (!dssdev->driver->set_rotate || !dssdev->driver->get_rotate)
3631 return -EINVAL;
3632
3633 dsi_bus_lock();
3634 dssdev->driver->set_rotate(dssdev, rotate);
3635 if (dsi.update_mode == OMAP_DSS_UPDATE_AUTO) {
3636 u16 w, h;
3637 /* the display dimensions may have changed, so set a new
3638 * update region */
3639 dssdev->get_resolution(dssdev, &w, &h);
3640 dsi_set_update_region(dssdev, 0, 0, w, h);
3641 }
3642 dsi_bus_unlock();
3643
3644 return 0;
3645}
3646
3647static u8 dsi_display_get_rotate(struct omap_dss_device *dssdev)
3648{
3649 if (!dssdev->driver->set_rotate || !dssdev->driver->get_rotate)
3650 return 0;
3651
3652 return dssdev->driver->get_rotate(dssdev);
3653}
3654
3655static int dsi_display_set_mirror(struct omap_dss_device *dssdev, bool mirror)
3656{
3657 DSSDBGF("%d", mirror);
3658
3659 if (!dssdev->driver->set_mirror || !dssdev->driver->get_mirror)
3660 return -EINVAL;
3661
3662 dsi_bus_lock();
3663 dssdev->driver->set_mirror(dssdev, mirror);
3664 dsi_bus_unlock();
3665
3666 return 0;
3667}
3668
3669static bool dsi_display_get_mirror(struct omap_dss_device *dssdev)
3670{
3671 if (!dssdev->driver->set_mirror || !dssdev->driver->get_mirror)
3672 return 0;
3673
3674 return dssdev->driver->get_mirror(dssdev);
3675}
3676
3677static int dsi_display_run_test(struct omap_dss_device *dssdev, int test_num)
3678{
3679 int r;
3680
3681 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
3682 return -EIO;
3683
3684 DSSDBGF("%d", test_num);
3685
3686 dsi_bus_lock();
3687
3688 /* run test first in low speed mode */
Tomi Valkeinen61140c92010-01-12 16:00:30 +02003689 omapdss_dsi_vc_enable_hs(0, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003690
3691 if (dssdev->driver->run_test) {
3692 r = dssdev->driver->run_test(dssdev, test_num);
3693 if (r)
3694 goto end;
3695 }
3696
3697 /* then in high speed */
Tomi Valkeinen61140c92010-01-12 16:00:30 +02003698 omapdss_dsi_vc_enable_hs(0, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003699
3700 if (dssdev->driver->run_test) {
3701 r = dssdev->driver->run_test(dssdev, test_num);
3702 if (r)
3703 goto end;
3704 }
3705
3706end:
Tomi Valkeinen61140c92010-01-12 16:00:30 +02003707 omapdss_dsi_vc_enable_hs(0, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003708
3709 dsi_bus_unlock();
3710
3711 return r;
3712}
3713
3714static int dsi_display_memory_read(struct omap_dss_device *dssdev,
3715 void *buf, size_t size,
3716 u16 x, u16 y, u16 w, u16 h)
3717{
3718 int r;
3719
3720 DSSDBGF("");
3721
3722 if (!dssdev->driver->memory_read)
3723 return -EINVAL;
3724
3725 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
3726 return -EIO;
3727
3728 dsi_bus_lock();
3729
3730 r = dssdev->driver->memory_read(dssdev, buf, size,
3731 x, y, w, h);
3732
3733 /* Memory read usually changes the update area. This will
3734 * force the next update to re-set the update area */
3735 dsi.active_update_region.dirty = true;
3736
3737 dsi_bus_unlock();
3738
3739 return r;
3740}
3741
3742void dsi_get_overlay_fifo_thresholds(enum omap_plane plane,
3743 u32 fifo_size, enum omap_burst_size *burst_size,
3744 u32 *fifo_low, u32 *fifo_high)
3745{
3746 unsigned burst_size_bytes;
3747
3748 *burst_size = OMAP_DSS_BURST_16x32;
3749 burst_size_bytes = 16 * 32 / 8;
3750
3751 *fifo_high = fifo_size - burst_size_bytes;
3752 *fifo_low = fifo_size - burst_size_bytes * 8;
3753}
3754
3755int dsi_init_display(struct omap_dss_device *dssdev)
3756{
3757 DSSDBG("DSI init\n");
3758
3759 dssdev->enable = dsi_display_enable;
3760 dssdev->disable = dsi_display_disable;
3761 dssdev->suspend = dsi_display_suspend;
3762 dssdev->resume = dsi_display_resume;
3763 dssdev->update = dsi_display_update;
3764 dssdev->sync = dsi_display_sync;
3765 dssdev->set_update_mode = dsi_display_set_update_mode;
3766 dssdev->get_update_mode = dsi_display_get_update_mode;
3767 dssdev->enable_te = dsi_display_enable_te;
3768 dssdev->get_te = dsi_display_get_te;
3769
3770 dssdev->get_rotate = dsi_display_get_rotate;
3771 dssdev->set_rotate = dsi_display_set_rotate;
3772
3773 dssdev->get_mirror = dsi_display_get_mirror;
3774 dssdev->set_mirror = dsi_display_set_mirror;
3775
3776 dssdev->run_test = dsi_display_run_test;
3777 dssdev->memory_read = dsi_display_memory_read;
3778
3779 /* XXX these should be figured out dynamically */
3780 dssdev->caps = OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE |
3781 OMAP_DSS_DISPLAY_CAP_TEAR_ELIM;
3782
3783 dsi.vc[0].dssdev = dssdev;
3784 dsi.vc[1].dssdev = dssdev;
3785
3786 return 0;
3787}
3788
3789int dsi_init(struct platform_device *pdev)
3790{
3791 u32 rev;
3792 int r;
3793 struct sched_param param = {
3794 .sched_priority = MAX_USER_RT_PRIO-1
3795 };
3796
3797 spin_lock_init(&dsi.errors_lock);
3798 dsi.errors = 0;
3799
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02003800#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
3801 spin_lock_init(&dsi.irq_stats_lock);
3802 dsi.irq_stats.last_reset = jiffies;
3803#endif
3804
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003805 init_completion(&dsi.bta_completion);
3806 init_completion(&dsi.update_completion);
3807
3808 dsi.thread = kthread_create(dsi_update_thread, NULL, "dsi");
3809 if (IS_ERR(dsi.thread)) {
3810 DSSERR("cannot create kthread\n");
3811 r = PTR_ERR(dsi.thread);
3812 goto err0;
3813 }
3814 sched_setscheduler(dsi.thread, SCHED_FIFO, &param);
3815
3816 init_waitqueue_head(&dsi.waitqueue);
3817 spin_lock_init(&dsi.update_lock);
3818
3819 mutex_init(&dsi.lock);
3820 mutex_init(&dsi.bus_lock);
3821
3822#ifdef DSI_CATCH_MISSING_TE
3823 init_timer(&dsi.te_timer);
3824 dsi.te_timer.function = dsi_te_timeout;
3825 dsi.te_timer.data = 0;
3826#endif
3827
3828 dsi.update_mode = OMAP_DSS_UPDATE_DISABLED;
3829 dsi.user_update_mode = OMAP_DSS_UPDATE_DISABLED;
3830
3831 dsi.base = ioremap(DSI_BASE, DSI_SZ_REGS);
3832 if (!dsi.base) {
3833 DSSERR("can't ioremap DSI\n");
3834 r = -ENOMEM;
3835 goto err1;
3836 }
3837
Tomi Valkeinen8a2cfea2010-02-04 17:03:41 +02003838 dsi.vdds_dsi_reg = dss_get_vdds_dsi();
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003839 if (IS_ERR(dsi.vdds_dsi_reg)) {
3840 iounmap(dsi.base);
3841 DSSERR("can't get VDDS_DSI regulator\n");
3842 r = PTR_ERR(dsi.vdds_dsi_reg);
3843 goto err2;
3844 }
3845
3846 enable_clocks(1);
3847
3848 rev = dsi_read_reg(DSI_REVISION);
3849 printk(KERN_INFO "OMAP DSI rev %d.%d\n",
3850 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
3851
3852 enable_clocks(0);
3853
3854 wake_up_process(dsi.thread);
3855
3856 return 0;
3857err2:
3858 iounmap(dsi.base);
3859err1:
3860 kthread_stop(dsi.thread);
3861err0:
3862 return r;
3863}
3864
3865void dsi_exit(void)
3866{
3867 kthread_stop(dsi.thread);
3868
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003869 iounmap(dsi.base);
3870
3871 DSSDBG("omap_dsi_exit\n");
3872}
3873