blob: 928b5e44a3dd686d706983dc50434f7ed5053791 [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
Tomi Valkeinen63cf28a2010-02-23 17:40:00 +0200781 if (dss_get_dsi_clk_source() == DSS_SRC_DSS1_ALWON_FCLK) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200782 /* 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,
Tomi Valkeinen63cf28a2010-02-23 17:40:00 +02001234 dss_get_dispc_clk_source() == DSS_SRC_DSS1_ALWON_FCLK ?
1235 "off" : "on");
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001236
1237 seq_printf(s, "dsi2_pll_fck\t%-16luregm4 %u\t(%s)\n",
1238 cinfo->dsi2_pll_fclk,
1239 cinfo->regm4,
Tomi Valkeinen63cf28a2010-02-23 17:40:00 +02001240 dss_get_dsi_clk_source() == DSS_SRC_DSS1_ALWON_FCLK ?
1241 "off" : "on");
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001242
1243 seq_printf(s, "- DSI -\n");
1244
1245 seq_printf(s, "dsi fclk source = %s\n",
Tomi Valkeinen63cf28a2010-02-23 17:40:00 +02001246 dss_get_dsi_clk_source() == DSS_SRC_DSS1_ALWON_FCLK ?
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001247 "dss1_alwon_fclk" : "dsi2_pll_fclk");
1248
1249 seq_printf(s, "DSI_FCLK\t%lu\n", dsi_fclk_rate());
1250
1251 seq_printf(s, "DDR_CLK\t\t%lu\n",
1252 cinfo->clkin4ddr / 4);
1253
1254 seq_printf(s, "TxByteClkHS\t%lu\n", dsi_get_txbyteclkhs());
1255
1256 seq_printf(s, "LP_CLK\t\t%lu\n", cinfo->lp_clk);
1257
1258 seq_printf(s, "VP_CLK\t\t%lu\n"
1259 "VP_PCLK\t\t%lu\n",
1260 dispc_lclk_rate(),
1261 dispc_pclk_rate());
1262
1263 enable_clocks(0);
1264}
1265
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001266#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
1267void dsi_dump_irqs(struct seq_file *s)
1268{
1269 unsigned long flags;
1270 struct dsi_irq_stats stats;
1271
1272 spin_lock_irqsave(&dsi.irq_stats_lock, flags);
1273
1274 stats = dsi.irq_stats;
1275 memset(&dsi.irq_stats, 0, sizeof(dsi.irq_stats));
1276 dsi.irq_stats.last_reset = jiffies;
1277
1278 spin_unlock_irqrestore(&dsi.irq_stats_lock, flags);
1279
1280 seq_printf(s, "period %u ms\n",
1281 jiffies_to_msecs(jiffies - stats.last_reset));
1282
1283 seq_printf(s, "irqs %d\n", stats.irq_count);
1284#define PIS(x) \
1285 seq_printf(s, "%-20s %10d\n", #x, stats.dsi_irqs[ffs(DSI_IRQ_##x)-1]);
1286
1287 seq_printf(s, "-- DSI interrupts --\n");
1288 PIS(VC0);
1289 PIS(VC1);
1290 PIS(VC2);
1291 PIS(VC3);
1292 PIS(WAKEUP);
1293 PIS(RESYNC);
1294 PIS(PLL_LOCK);
1295 PIS(PLL_UNLOCK);
1296 PIS(PLL_RECALL);
1297 PIS(COMPLEXIO_ERR);
1298 PIS(HS_TX_TIMEOUT);
1299 PIS(LP_RX_TIMEOUT);
1300 PIS(TE_TRIGGER);
1301 PIS(ACK_TRIGGER);
1302 PIS(SYNC_LOST);
1303 PIS(LDO_POWER_GOOD);
1304 PIS(TA_TIMEOUT);
1305#undef PIS
1306
1307#define PIS(x) \
1308 seq_printf(s, "%-20s %10d %10d %10d %10d\n", #x, \
1309 stats.vc_irqs[0][ffs(DSI_VC_IRQ_##x)-1], \
1310 stats.vc_irqs[1][ffs(DSI_VC_IRQ_##x)-1], \
1311 stats.vc_irqs[2][ffs(DSI_VC_IRQ_##x)-1], \
1312 stats.vc_irqs[3][ffs(DSI_VC_IRQ_##x)-1]);
1313
1314 seq_printf(s, "-- VC interrupts --\n");
1315 PIS(CS);
1316 PIS(ECC_CORR);
1317 PIS(PACKET_SENT);
1318 PIS(FIFO_TX_OVF);
1319 PIS(FIFO_RX_OVF);
1320 PIS(BTA);
1321 PIS(ECC_NO_CORR);
1322 PIS(FIFO_TX_UDF);
1323 PIS(PP_BUSY_CHANGE);
1324#undef PIS
1325
1326#define PIS(x) \
1327 seq_printf(s, "%-20s %10d\n", #x, \
1328 stats.cio_irqs[ffs(DSI_CIO_IRQ_##x)-1]);
1329
1330 seq_printf(s, "-- CIO interrupts --\n");
1331 PIS(ERRSYNCESC1);
1332 PIS(ERRSYNCESC2);
1333 PIS(ERRSYNCESC3);
1334 PIS(ERRESC1);
1335 PIS(ERRESC2);
1336 PIS(ERRESC3);
1337 PIS(ERRCONTROL1);
1338 PIS(ERRCONTROL2);
1339 PIS(ERRCONTROL3);
1340 PIS(STATEULPS1);
1341 PIS(STATEULPS2);
1342 PIS(STATEULPS3);
1343 PIS(ERRCONTENTIONLP0_1);
1344 PIS(ERRCONTENTIONLP1_1);
1345 PIS(ERRCONTENTIONLP0_2);
1346 PIS(ERRCONTENTIONLP1_2);
1347 PIS(ERRCONTENTIONLP0_3);
1348 PIS(ERRCONTENTIONLP1_3);
1349 PIS(ULPSACTIVENOT_ALL0);
1350 PIS(ULPSACTIVENOT_ALL1);
1351#undef PIS
1352}
1353#endif
1354
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001355void dsi_dump_regs(struct seq_file *s)
1356{
1357#define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dsi_read_reg(r))
1358
1359 dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK1);
1360
1361 DUMPREG(DSI_REVISION);
1362 DUMPREG(DSI_SYSCONFIG);
1363 DUMPREG(DSI_SYSSTATUS);
1364 DUMPREG(DSI_IRQSTATUS);
1365 DUMPREG(DSI_IRQENABLE);
1366 DUMPREG(DSI_CTRL);
1367 DUMPREG(DSI_COMPLEXIO_CFG1);
1368 DUMPREG(DSI_COMPLEXIO_IRQ_STATUS);
1369 DUMPREG(DSI_COMPLEXIO_IRQ_ENABLE);
1370 DUMPREG(DSI_CLK_CTRL);
1371 DUMPREG(DSI_TIMING1);
1372 DUMPREG(DSI_TIMING2);
1373 DUMPREG(DSI_VM_TIMING1);
1374 DUMPREG(DSI_VM_TIMING2);
1375 DUMPREG(DSI_VM_TIMING3);
1376 DUMPREG(DSI_CLK_TIMING);
1377 DUMPREG(DSI_TX_FIFO_VC_SIZE);
1378 DUMPREG(DSI_RX_FIFO_VC_SIZE);
1379 DUMPREG(DSI_COMPLEXIO_CFG2);
1380 DUMPREG(DSI_RX_FIFO_VC_FULLNESS);
1381 DUMPREG(DSI_VM_TIMING4);
1382 DUMPREG(DSI_TX_FIFO_VC_EMPTINESS);
1383 DUMPREG(DSI_VM_TIMING5);
1384 DUMPREG(DSI_VM_TIMING6);
1385 DUMPREG(DSI_VM_TIMING7);
1386 DUMPREG(DSI_STOPCLK_TIMING);
1387
1388 DUMPREG(DSI_VC_CTRL(0));
1389 DUMPREG(DSI_VC_TE(0));
1390 DUMPREG(DSI_VC_LONG_PACKET_HEADER(0));
1391 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(0));
1392 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(0));
1393 DUMPREG(DSI_VC_IRQSTATUS(0));
1394 DUMPREG(DSI_VC_IRQENABLE(0));
1395
1396 DUMPREG(DSI_VC_CTRL(1));
1397 DUMPREG(DSI_VC_TE(1));
1398 DUMPREG(DSI_VC_LONG_PACKET_HEADER(1));
1399 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(1));
1400 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(1));
1401 DUMPREG(DSI_VC_IRQSTATUS(1));
1402 DUMPREG(DSI_VC_IRQENABLE(1));
1403
1404 DUMPREG(DSI_VC_CTRL(2));
1405 DUMPREG(DSI_VC_TE(2));
1406 DUMPREG(DSI_VC_LONG_PACKET_HEADER(2));
1407 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(2));
1408 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(2));
1409 DUMPREG(DSI_VC_IRQSTATUS(2));
1410 DUMPREG(DSI_VC_IRQENABLE(2));
1411
1412 DUMPREG(DSI_VC_CTRL(3));
1413 DUMPREG(DSI_VC_TE(3));
1414 DUMPREG(DSI_VC_LONG_PACKET_HEADER(3));
1415 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(3));
1416 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(3));
1417 DUMPREG(DSI_VC_IRQSTATUS(3));
1418 DUMPREG(DSI_VC_IRQENABLE(3));
1419
1420 DUMPREG(DSI_DSIPHY_CFG0);
1421 DUMPREG(DSI_DSIPHY_CFG1);
1422 DUMPREG(DSI_DSIPHY_CFG2);
1423 DUMPREG(DSI_DSIPHY_CFG5);
1424
1425 DUMPREG(DSI_PLL_CONTROL);
1426 DUMPREG(DSI_PLL_STATUS);
1427 DUMPREG(DSI_PLL_GO);
1428 DUMPREG(DSI_PLL_CONFIGURATION1);
1429 DUMPREG(DSI_PLL_CONFIGURATION2);
1430
1431 dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK1);
1432#undef DUMPREG
1433}
1434
1435enum dsi_complexio_power_state {
1436 DSI_COMPLEXIO_POWER_OFF = 0x0,
1437 DSI_COMPLEXIO_POWER_ON = 0x1,
1438 DSI_COMPLEXIO_POWER_ULPS = 0x2,
1439};
1440
1441static int dsi_complexio_power(enum dsi_complexio_power_state state)
1442{
1443 int t = 0;
1444
1445 /* PWR_CMD */
1446 REG_FLD_MOD(DSI_COMPLEXIO_CFG1, state, 28, 27);
1447
1448 /* PWR_STATUS */
1449 while (FLD_GET(dsi_read_reg(DSI_COMPLEXIO_CFG1), 26, 25) != state) {
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02001450 if (++t > 1000) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001451 DSSERR("failed to set complexio power state to "
1452 "%d\n", state);
1453 return -ENODEV;
1454 }
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02001455 udelay(1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001456 }
1457
1458 return 0;
1459}
1460
1461static void dsi_complexio_config(struct omap_dss_device *dssdev)
1462{
1463 u32 r;
1464
1465 int clk_lane = dssdev->phy.dsi.clk_lane;
1466 int data1_lane = dssdev->phy.dsi.data1_lane;
1467 int data2_lane = dssdev->phy.dsi.data2_lane;
1468 int clk_pol = dssdev->phy.dsi.clk_pol;
1469 int data1_pol = dssdev->phy.dsi.data1_pol;
1470 int data2_pol = dssdev->phy.dsi.data2_pol;
1471
1472 r = dsi_read_reg(DSI_COMPLEXIO_CFG1);
1473 r = FLD_MOD(r, clk_lane, 2, 0);
1474 r = FLD_MOD(r, clk_pol, 3, 3);
1475 r = FLD_MOD(r, data1_lane, 6, 4);
1476 r = FLD_MOD(r, data1_pol, 7, 7);
1477 r = FLD_MOD(r, data2_lane, 10, 8);
1478 r = FLD_MOD(r, data2_pol, 11, 11);
1479 dsi_write_reg(DSI_COMPLEXIO_CFG1, r);
1480
1481 /* The configuration of the DSI complex I/O (number of data lanes,
1482 position, differential order) should not be changed while
1483 DSS.DSI_CLK_CRTRL[20] LP_CLK_ENABLE bit is set to 1. In order for
1484 the hardware to take into account a new configuration of the complex
1485 I/O (done in DSS.DSI_COMPLEXIO_CFG1 register), it is recommended to
1486 follow this sequence: First set the DSS.DSI_CTRL[0] IF_EN bit to 1,
1487 then reset the DSS.DSI_CTRL[0] IF_EN to 0, then set
1488 DSS.DSI_CLK_CTRL[20] LP_CLK_ENABLE to 1 and finally set again the
1489 DSS.DSI_CTRL[0] IF_EN bit to 1. If the sequence is not followed, the
1490 DSI complex I/O configuration is unknown. */
1491
1492 /*
1493 REG_FLD_MOD(DSI_CTRL, 1, 0, 0);
1494 REG_FLD_MOD(DSI_CTRL, 0, 0, 0);
1495 REG_FLD_MOD(DSI_CLK_CTRL, 1, 20, 20);
1496 REG_FLD_MOD(DSI_CTRL, 1, 0, 0);
1497 */
1498}
1499
1500static inline unsigned ns2ddr(unsigned ns)
1501{
1502 /* convert time in ns to ddr ticks, rounding up */
1503 unsigned long ddr_clk = dsi.current_cinfo.clkin4ddr / 4;
1504 return (ns * (ddr_clk / 1000 / 1000) + 999) / 1000;
1505}
1506
1507static inline unsigned ddr2ns(unsigned ddr)
1508{
1509 unsigned long ddr_clk = dsi.current_cinfo.clkin4ddr / 4;
1510 return ddr * 1000 * 1000 / (ddr_clk / 1000);
1511}
1512
1513static void dsi_complexio_timings(void)
1514{
1515 u32 r;
1516 u32 ths_prepare, ths_prepare_ths_zero, ths_trail, ths_exit;
1517 u32 tlpx_half, tclk_trail, tclk_zero;
1518 u32 tclk_prepare;
1519
1520 /* calculate timings */
1521
1522 /* 1 * DDR_CLK = 2 * UI */
1523
1524 /* min 40ns + 4*UI max 85ns + 6*UI */
1525 ths_prepare = ns2ddr(70) + 2;
1526
1527 /* min 145ns + 10*UI */
1528 ths_prepare_ths_zero = ns2ddr(175) + 2;
1529
1530 /* min max(8*UI, 60ns+4*UI) */
1531 ths_trail = ns2ddr(60) + 5;
1532
1533 /* min 100ns */
1534 ths_exit = ns2ddr(145);
1535
1536 /* tlpx min 50n */
1537 tlpx_half = ns2ddr(25);
1538
1539 /* min 60ns */
1540 tclk_trail = ns2ddr(60) + 2;
1541
1542 /* min 38ns, max 95ns */
1543 tclk_prepare = ns2ddr(65);
1544
1545 /* min tclk-prepare + tclk-zero = 300ns */
1546 tclk_zero = ns2ddr(260);
1547
1548 DSSDBG("ths_prepare %u (%uns), ths_prepare_ths_zero %u (%uns)\n",
1549 ths_prepare, ddr2ns(ths_prepare),
1550 ths_prepare_ths_zero, ddr2ns(ths_prepare_ths_zero));
1551 DSSDBG("ths_trail %u (%uns), ths_exit %u (%uns)\n",
1552 ths_trail, ddr2ns(ths_trail),
1553 ths_exit, ddr2ns(ths_exit));
1554
1555 DSSDBG("tlpx_half %u (%uns), tclk_trail %u (%uns), "
1556 "tclk_zero %u (%uns)\n",
1557 tlpx_half, ddr2ns(tlpx_half),
1558 tclk_trail, ddr2ns(tclk_trail),
1559 tclk_zero, ddr2ns(tclk_zero));
1560 DSSDBG("tclk_prepare %u (%uns)\n",
1561 tclk_prepare, ddr2ns(tclk_prepare));
1562
1563 /* program timings */
1564
1565 r = dsi_read_reg(DSI_DSIPHY_CFG0);
1566 r = FLD_MOD(r, ths_prepare, 31, 24);
1567 r = FLD_MOD(r, ths_prepare_ths_zero, 23, 16);
1568 r = FLD_MOD(r, ths_trail, 15, 8);
1569 r = FLD_MOD(r, ths_exit, 7, 0);
1570 dsi_write_reg(DSI_DSIPHY_CFG0, r);
1571
1572 r = dsi_read_reg(DSI_DSIPHY_CFG1);
1573 r = FLD_MOD(r, tlpx_half, 22, 16);
1574 r = FLD_MOD(r, tclk_trail, 15, 8);
1575 r = FLD_MOD(r, tclk_zero, 7, 0);
1576 dsi_write_reg(DSI_DSIPHY_CFG1, r);
1577
1578 r = dsi_read_reg(DSI_DSIPHY_CFG2);
1579 r = FLD_MOD(r, tclk_prepare, 7, 0);
1580 dsi_write_reg(DSI_DSIPHY_CFG2, r);
1581}
1582
1583
1584static int dsi_complexio_init(struct omap_dss_device *dssdev)
1585{
1586 int r = 0;
1587
1588 DSSDBG("dsi_complexio_init\n");
1589
1590 /* CIO_CLK_ICG, enable L3 clk to CIO */
1591 REG_FLD_MOD(DSI_CLK_CTRL, 1, 14, 14);
1592
1593 /* A dummy read using the SCP interface to any DSIPHY register is
1594 * required after DSIPHY reset to complete the reset of the DSI complex
1595 * I/O. */
1596 dsi_read_reg(DSI_DSIPHY_CFG5);
1597
1598 if (wait_for_bit_change(DSI_DSIPHY_CFG5, 30, 1) != 1) {
1599 DSSERR("ComplexIO PHY not coming out of reset.\n");
1600 r = -ENODEV;
1601 goto err;
1602 }
1603
1604 dsi_complexio_config(dssdev);
1605
1606 r = dsi_complexio_power(DSI_COMPLEXIO_POWER_ON);
1607
1608 if (r)
1609 goto err;
1610
1611 if (wait_for_bit_change(DSI_COMPLEXIO_CFG1, 29, 1) != 1) {
1612 DSSERR("ComplexIO not coming out of reset.\n");
1613 r = -ENODEV;
1614 goto err;
1615 }
1616
1617 if (wait_for_bit_change(DSI_COMPLEXIO_CFG1, 21, 1) != 1) {
1618 DSSERR("ComplexIO LDO power down.\n");
1619 r = -ENODEV;
1620 goto err;
1621 }
1622
1623 dsi_complexio_timings();
1624
1625 /*
1626 The configuration of the DSI complex I/O (number of data lanes,
1627 position, differential order) should not be changed while
1628 DSS.DSI_CLK_CRTRL[20] LP_CLK_ENABLE bit is set to 1. For the
1629 hardware to recognize a new configuration of the complex I/O (done
1630 in DSS.DSI_COMPLEXIO_CFG1 register), it is recommended to follow
1631 this sequence: First set the DSS.DSI_CTRL[0] IF_EN bit to 1, next
1632 reset the DSS.DSI_CTRL[0] IF_EN to 0, then set DSS.DSI_CLK_CTRL[20]
1633 LP_CLK_ENABLE to 1, and finally, set again the DSS.DSI_CTRL[0] IF_EN
1634 bit to 1. If the sequence is not followed, the DSi complex I/O
1635 configuration is undetermined.
1636 */
1637 dsi_if_enable(1);
1638 dsi_if_enable(0);
1639 REG_FLD_MOD(DSI_CLK_CTRL, 1, 20, 20); /* LP_CLK_ENABLE */
1640 dsi_if_enable(1);
1641 dsi_if_enable(0);
1642
1643 DSSDBG("CIO init done\n");
1644err:
1645 return r;
1646}
1647
1648static void dsi_complexio_uninit(void)
1649{
1650 dsi_complexio_power(DSI_COMPLEXIO_POWER_OFF);
1651}
1652
1653static int _dsi_wait_reset(void)
1654{
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02001655 int t = 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001656
1657 while (REG_GET(DSI_SYSSTATUS, 0, 0) == 0) {
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02001658 if (++t > 5) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001659 DSSERR("soft reset failed\n");
1660 return -ENODEV;
1661 }
1662 udelay(1);
1663 }
1664
1665 return 0;
1666}
1667
1668static int _dsi_reset(void)
1669{
1670 /* Soft reset */
1671 REG_FLD_MOD(DSI_SYSCONFIG, 1, 1, 1);
1672 return _dsi_wait_reset();
1673}
1674
1675static void dsi_reset_tx_fifo(int channel)
1676{
1677 u32 mask;
1678 u32 l;
1679
1680 /* set fifosize of the channel to 0, then return the old size */
1681 l = dsi_read_reg(DSI_TX_FIFO_VC_SIZE);
1682
1683 mask = FLD_MASK((8 * channel) + 7, (8 * channel) + 4);
1684 dsi_write_reg(DSI_TX_FIFO_VC_SIZE, l & ~mask);
1685
1686 dsi_write_reg(DSI_TX_FIFO_VC_SIZE, l);
1687}
1688
1689static void dsi_config_tx_fifo(enum fifo_size size1, enum fifo_size size2,
1690 enum fifo_size size3, enum fifo_size size4)
1691{
1692 u32 r = 0;
1693 int add = 0;
1694 int i;
1695
1696 dsi.vc[0].fifo_size = size1;
1697 dsi.vc[1].fifo_size = size2;
1698 dsi.vc[2].fifo_size = size3;
1699 dsi.vc[3].fifo_size = size4;
1700
1701 for (i = 0; i < 4; i++) {
1702 u8 v;
1703 int size = dsi.vc[i].fifo_size;
1704
1705 if (add + size > 4) {
1706 DSSERR("Illegal FIFO configuration\n");
1707 BUG();
1708 }
1709
1710 v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
1711 r |= v << (8 * i);
1712 /*DSSDBG("TX FIFO vc %d: size %d, add %d\n", i, size, add); */
1713 add += size;
1714 }
1715
1716 dsi_write_reg(DSI_TX_FIFO_VC_SIZE, r);
1717}
1718
1719static void dsi_config_rx_fifo(enum fifo_size size1, enum fifo_size size2,
1720 enum fifo_size size3, enum fifo_size size4)
1721{
1722 u32 r = 0;
1723 int add = 0;
1724 int i;
1725
1726 dsi.vc[0].fifo_size = size1;
1727 dsi.vc[1].fifo_size = size2;
1728 dsi.vc[2].fifo_size = size3;
1729 dsi.vc[3].fifo_size = size4;
1730
1731 for (i = 0; i < 4; i++) {
1732 u8 v;
1733 int size = dsi.vc[i].fifo_size;
1734
1735 if (add + size > 4) {
1736 DSSERR("Illegal FIFO configuration\n");
1737 BUG();
1738 }
1739
1740 v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
1741 r |= v << (8 * i);
1742 /*DSSDBG("RX FIFO vc %d: size %d, add %d\n", i, size, add); */
1743 add += size;
1744 }
1745
1746 dsi_write_reg(DSI_RX_FIFO_VC_SIZE, r);
1747}
1748
1749static int dsi_force_tx_stop_mode_io(void)
1750{
1751 u32 r;
1752
1753 r = dsi_read_reg(DSI_TIMING1);
1754 r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
1755 dsi_write_reg(DSI_TIMING1, r);
1756
1757 if (wait_for_bit_change(DSI_TIMING1, 15, 0) != 0) {
1758 DSSERR("TX_STOP bit not going down\n");
1759 return -EIO;
1760 }
1761
1762 return 0;
1763}
1764
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001765static int dsi_vc_enable(int channel, bool enable)
1766{
1767 if (dsi.update_mode != OMAP_DSS_UPDATE_AUTO)
1768 DSSDBG("dsi_vc_enable channel %d, enable %d\n",
1769 channel, enable);
1770
1771 enable = enable ? 1 : 0;
1772
1773 REG_FLD_MOD(DSI_VC_CTRL(channel), enable, 0, 0);
1774
1775 if (wait_for_bit_change(DSI_VC_CTRL(channel), 0, enable) != enable) {
1776 DSSERR("Failed to set dsi_vc_enable to %d\n", enable);
1777 return -EIO;
1778 }
1779
1780 return 0;
1781}
1782
1783static void dsi_vc_initial_config(int channel)
1784{
1785 u32 r;
1786
1787 DSSDBGF("%d", channel);
1788
1789 r = dsi_read_reg(DSI_VC_CTRL(channel));
1790
1791 if (FLD_GET(r, 15, 15)) /* VC_BUSY */
1792 DSSERR("VC(%d) busy when trying to configure it!\n",
1793 channel);
1794
1795 r = FLD_MOD(r, 0, 1, 1); /* SOURCE, 0 = L4 */
1796 r = FLD_MOD(r, 0, 2, 2); /* BTA_SHORT_EN */
1797 r = FLD_MOD(r, 0, 3, 3); /* BTA_LONG_EN */
1798 r = FLD_MOD(r, 0, 4, 4); /* MODE, 0 = command */
1799 r = FLD_MOD(r, 1, 7, 7); /* CS_TX_EN */
1800 r = FLD_MOD(r, 1, 8, 8); /* ECC_TX_EN */
1801 r = FLD_MOD(r, 0, 9, 9); /* MODE_SPEED, high speed on/off */
1802
1803 r = FLD_MOD(r, 4, 29, 27); /* DMA_RX_REQ_NB = no dma */
1804 r = FLD_MOD(r, 4, 23, 21); /* DMA_TX_REQ_NB = no dma */
1805
1806 dsi_write_reg(DSI_VC_CTRL(channel), r);
1807
1808 dsi.vc[channel].mode = DSI_VC_MODE_L4;
1809}
1810
1811static void dsi_vc_config_l4(int channel)
1812{
1813 if (dsi.vc[channel].mode == DSI_VC_MODE_L4)
1814 return;
1815
1816 DSSDBGF("%d", channel);
1817
1818 dsi_vc_enable(channel, 0);
1819
1820 if (REG_GET(DSI_VC_CTRL(channel), 15, 15)) /* VC_BUSY */
1821 DSSERR("vc(%d) busy when trying to config for L4\n", channel);
1822
1823 REG_FLD_MOD(DSI_VC_CTRL(channel), 0, 1, 1); /* SOURCE, 0 = L4 */
1824
1825 dsi_vc_enable(channel, 1);
1826
1827 dsi.vc[channel].mode = DSI_VC_MODE_L4;
1828}
1829
1830static void dsi_vc_config_vp(int channel)
1831{
1832 if (dsi.vc[channel].mode == DSI_VC_MODE_VP)
1833 return;
1834
1835 DSSDBGF("%d", channel);
1836
1837 dsi_vc_enable(channel, 0);
1838
1839 if (REG_GET(DSI_VC_CTRL(channel), 15, 15)) /* VC_BUSY */
1840 DSSERR("vc(%d) busy when trying to config for VP\n", channel);
1841
1842 REG_FLD_MOD(DSI_VC_CTRL(channel), 1, 1, 1); /* SOURCE, 1 = video port */
1843
1844 dsi_vc_enable(channel, 1);
1845
1846 dsi.vc[channel].mode = DSI_VC_MODE_VP;
1847}
1848
1849
Tomi Valkeinen61140c92010-01-12 16:00:30 +02001850void omapdss_dsi_vc_enable_hs(int channel, bool enable)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001851{
1852 DSSDBG("dsi_vc_enable_hs(%d, %d)\n", channel, enable);
1853
Tomi Valkeinen61140c92010-01-12 16:00:30 +02001854 WARN_ON(!dsi_bus_is_locked());
1855
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001856 dsi_vc_enable(channel, 0);
1857 dsi_if_enable(0);
1858
1859 REG_FLD_MOD(DSI_VC_CTRL(channel), enable, 9, 9);
1860
1861 dsi_vc_enable(channel, 1);
1862 dsi_if_enable(1);
1863
1864 dsi_force_tx_stop_mode_io();
1865}
Tomi Valkeinen61140c92010-01-12 16:00:30 +02001866EXPORT_SYMBOL(omapdss_dsi_vc_enable_hs);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001867
1868static void dsi_vc_flush_long_data(int channel)
1869{
1870 while (REG_GET(DSI_VC_CTRL(channel), 20, 20)) {
1871 u32 val;
1872 val = dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel));
1873 DSSDBG("\t\tb1 %#02x b2 %#02x b3 %#02x b4 %#02x\n",
1874 (val >> 0) & 0xff,
1875 (val >> 8) & 0xff,
1876 (val >> 16) & 0xff,
1877 (val >> 24) & 0xff);
1878 }
1879}
1880
1881static void dsi_show_rx_ack_with_err(u16 err)
1882{
1883 DSSERR("\tACK with ERROR (%#x):\n", err);
1884 if (err & (1 << 0))
1885 DSSERR("\t\tSoT Error\n");
1886 if (err & (1 << 1))
1887 DSSERR("\t\tSoT Sync Error\n");
1888 if (err & (1 << 2))
1889 DSSERR("\t\tEoT Sync Error\n");
1890 if (err & (1 << 3))
1891 DSSERR("\t\tEscape Mode Entry Command Error\n");
1892 if (err & (1 << 4))
1893 DSSERR("\t\tLP Transmit Sync Error\n");
1894 if (err & (1 << 5))
1895 DSSERR("\t\tHS Receive Timeout Error\n");
1896 if (err & (1 << 6))
1897 DSSERR("\t\tFalse Control Error\n");
1898 if (err & (1 << 7))
1899 DSSERR("\t\t(reserved7)\n");
1900 if (err & (1 << 8))
1901 DSSERR("\t\tECC Error, single-bit (corrected)\n");
1902 if (err & (1 << 9))
1903 DSSERR("\t\tECC Error, multi-bit (not corrected)\n");
1904 if (err & (1 << 10))
1905 DSSERR("\t\tChecksum Error\n");
1906 if (err & (1 << 11))
1907 DSSERR("\t\tData type not recognized\n");
1908 if (err & (1 << 12))
1909 DSSERR("\t\tInvalid VC ID\n");
1910 if (err & (1 << 13))
1911 DSSERR("\t\tInvalid Transmission Length\n");
1912 if (err & (1 << 14))
1913 DSSERR("\t\t(reserved14)\n");
1914 if (err & (1 << 15))
1915 DSSERR("\t\tDSI Protocol Violation\n");
1916}
1917
1918static u16 dsi_vc_flush_receive_data(int channel)
1919{
1920 /* RX_FIFO_NOT_EMPTY */
1921 while (REG_GET(DSI_VC_CTRL(channel), 20, 20)) {
1922 u32 val;
1923 u8 dt;
1924 val = dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel));
1925 DSSDBG("\trawval %#08x\n", val);
1926 dt = FLD_GET(val, 5, 0);
1927 if (dt == DSI_DT_RX_ACK_WITH_ERR) {
1928 u16 err = FLD_GET(val, 23, 8);
1929 dsi_show_rx_ack_with_err(err);
1930 } else if (dt == DSI_DT_RX_SHORT_READ_1) {
1931 DSSDBG("\tDCS short response, 1 byte: %#x\n",
1932 FLD_GET(val, 23, 8));
1933 } else if (dt == DSI_DT_RX_SHORT_READ_2) {
1934 DSSDBG("\tDCS short response, 2 byte: %#x\n",
1935 FLD_GET(val, 23, 8));
1936 } else if (dt == DSI_DT_RX_DCS_LONG_READ) {
1937 DSSDBG("\tDCS long response, len %d\n",
1938 FLD_GET(val, 23, 8));
1939 dsi_vc_flush_long_data(channel);
1940 } else {
1941 DSSERR("\tunknown datatype 0x%02x\n", dt);
1942 }
1943 }
1944 return 0;
1945}
1946
1947static int dsi_vc_send_bta(int channel)
1948{
1949 if (dsi.update_mode != OMAP_DSS_UPDATE_AUTO &&
1950 (dsi.debug_write || dsi.debug_read))
1951 DSSDBG("dsi_vc_send_bta %d\n", channel);
1952
Tomi Valkeinen4f765022010-01-18 16:27:52 +02001953 WARN_ON(!dsi_bus_is_locked());
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001954
1955 if (REG_GET(DSI_VC_CTRL(channel), 20, 20)) { /* RX_FIFO_NOT_EMPTY */
1956 DSSERR("rx fifo not empty when sending BTA, dumping data:\n");
1957 dsi_vc_flush_receive_data(channel);
1958 }
1959
1960 REG_FLD_MOD(DSI_VC_CTRL(channel), 1, 6, 6); /* BTA_EN */
1961
1962 return 0;
1963}
1964
1965int dsi_vc_send_bta_sync(int channel)
1966{
1967 int r = 0;
1968 u32 err;
1969
1970 INIT_COMPLETION(dsi.bta_completion);
1971
1972 dsi_vc_enable_bta_irq(channel);
1973
1974 r = dsi_vc_send_bta(channel);
1975 if (r)
1976 goto err;
1977
1978 if (wait_for_completion_timeout(&dsi.bta_completion,
1979 msecs_to_jiffies(500)) == 0) {
1980 DSSERR("Failed to receive BTA\n");
1981 r = -EIO;
1982 goto err;
1983 }
1984
1985 err = dsi_get_errors();
1986 if (err) {
1987 DSSERR("Error while sending BTA: %x\n", err);
1988 r = -EIO;
1989 goto err;
1990 }
1991err:
1992 dsi_vc_disable_bta_irq(channel);
1993
1994 return r;
1995}
1996EXPORT_SYMBOL(dsi_vc_send_bta_sync);
1997
1998static inline void dsi_vc_write_long_header(int channel, u8 data_type,
1999 u16 len, u8 ecc)
2000{
2001 u32 val;
2002 u8 data_id;
2003
Tomi Valkeinen4f765022010-01-18 16:27:52 +02002004 WARN_ON(!dsi_bus_is_locked());
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002005
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02002006 data_id = data_type | channel << 6;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002007
2008 val = FLD_VAL(data_id, 7, 0) | FLD_VAL(len, 23, 8) |
2009 FLD_VAL(ecc, 31, 24);
2010
2011 dsi_write_reg(DSI_VC_LONG_PACKET_HEADER(channel), val);
2012}
2013
2014static inline void dsi_vc_write_long_payload(int channel,
2015 u8 b1, u8 b2, u8 b3, u8 b4)
2016{
2017 u32 val;
2018
2019 val = b4 << 24 | b3 << 16 | b2 << 8 | b1 << 0;
2020
2021/* DSSDBG("\twriting %02x, %02x, %02x, %02x (%#010x)\n",
2022 b1, b2, b3, b4, val); */
2023
2024 dsi_write_reg(DSI_VC_LONG_PACKET_PAYLOAD(channel), val);
2025}
2026
2027static int dsi_vc_send_long(int channel, u8 data_type, u8 *data, u16 len,
2028 u8 ecc)
2029{
2030 /*u32 val; */
2031 int i;
2032 u8 *p;
2033 int r = 0;
2034 u8 b1, b2, b3, b4;
2035
2036 if (dsi.debug_write)
2037 DSSDBG("dsi_vc_send_long, %d bytes\n", len);
2038
2039 /* len + header */
2040 if (dsi.vc[channel].fifo_size * 32 * 4 < len + 4) {
2041 DSSERR("unable to send long packet: packet too long.\n");
2042 return -EINVAL;
2043 }
2044
2045 dsi_vc_config_l4(channel);
2046
2047 dsi_vc_write_long_header(channel, data_type, len, ecc);
2048
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002049 p = data;
2050 for (i = 0; i < len >> 2; i++) {
2051 if (dsi.debug_write)
2052 DSSDBG("\tsending full packet %d\n", i);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002053
2054 b1 = *p++;
2055 b2 = *p++;
2056 b3 = *p++;
2057 b4 = *p++;
2058
2059 dsi_vc_write_long_payload(channel, b1, b2, b3, b4);
2060 }
2061
2062 i = len % 4;
2063 if (i) {
2064 b1 = 0; b2 = 0; b3 = 0;
2065
2066 if (dsi.debug_write)
2067 DSSDBG("\tsending remainder bytes %d\n", i);
2068
2069 switch (i) {
2070 case 3:
2071 b1 = *p++;
2072 b2 = *p++;
2073 b3 = *p++;
2074 break;
2075 case 2:
2076 b1 = *p++;
2077 b2 = *p++;
2078 break;
2079 case 1:
2080 b1 = *p++;
2081 break;
2082 }
2083
2084 dsi_vc_write_long_payload(channel, b1, b2, b3, 0);
2085 }
2086
2087 return r;
2088}
2089
2090static int dsi_vc_send_short(int channel, u8 data_type, u16 data, u8 ecc)
2091{
2092 u32 r;
2093 u8 data_id;
2094
Tomi Valkeinen4f765022010-01-18 16:27:52 +02002095 WARN_ON(!dsi_bus_is_locked());
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002096
2097 if (dsi.debug_write)
2098 DSSDBG("dsi_vc_send_short(ch%d, dt %#x, b1 %#x, b2 %#x)\n",
2099 channel,
2100 data_type, data & 0xff, (data >> 8) & 0xff);
2101
2102 dsi_vc_config_l4(channel);
2103
2104 if (FLD_GET(dsi_read_reg(DSI_VC_CTRL(channel)), 16, 16)) {
2105 DSSERR("ERROR FIFO FULL, aborting transfer\n");
2106 return -EINVAL;
2107 }
2108
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02002109 data_id = data_type | channel << 6;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002110
2111 r = (data_id << 0) | (data << 8) | (ecc << 24);
2112
2113 dsi_write_reg(DSI_VC_SHORT_PACKET_HEADER(channel), r);
2114
2115 return 0;
2116}
2117
2118int dsi_vc_send_null(int channel)
2119{
2120 u8 nullpkg[] = {0, 0, 0, 0};
Tomi Valkeinen397bb3c2009-12-03 13:37:31 +02002121 return dsi_vc_send_long(channel, DSI_DT_NULL_PACKET, nullpkg, 4, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002122}
2123EXPORT_SYMBOL(dsi_vc_send_null);
2124
2125int dsi_vc_dcs_write_nosync(int channel, u8 *data, int len)
2126{
2127 int r;
2128
2129 BUG_ON(len == 0);
2130
2131 if (len == 1) {
2132 r = dsi_vc_send_short(channel, DSI_DT_DCS_SHORT_WRITE_0,
2133 data[0], 0);
2134 } else if (len == 2) {
2135 r = dsi_vc_send_short(channel, DSI_DT_DCS_SHORT_WRITE_1,
2136 data[0] | (data[1] << 8), 0);
2137 } else {
2138 /* 0x39 = DCS Long Write */
2139 r = dsi_vc_send_long(channel, DSI_DT_DCS_LONG_WRITE,
2140 data, len, 0);
2141 }
2142
2143 return r;
2144}
2145EXPORT_SYMBOL(dsi_vc_dcs_write_nosync);
2146
2147int dsi_vc_dcs_write(int channel, u8 *data, int len)
2148{
2149 int r;
2150
2151 r = dsi_vc_dcs_write_nosync(channel, data, len);
2152 if (r)
2153 return r;
2154
2155 r = dsi_vc_send_bta_sync(channel);
2156
2157 return r;
2158}
2159EXPORT_SYMBOL(dsi_vc_dcs_write);
2160
Tomi Valkeinen828c48f2009-12-16 14:53:15 +02002161int dsi_vc_dcs_write_0(int channel, u8 dcs_cmd)
2162{
2163 return dsi_vc_dcs_write(channel, &dcs_cmd, 1);
2164}
2165EXPORT_SYMBOL(dsi_vc_dcs_write_0);
2166
2167int dsi_vc_dcs_write_1(int channel, u8 dcs_cmd, u8 param)
2168{
2169 u8 buf[2];
2170 buf[0] = dcs_cmd;
2171 buf[1] = param;
2172 return dsi_vc_dcs_write(channel, buf, 2);
2173}
2174EXPORT_SYMBOL(dsi_vc_dcs_write_1);
2175
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002176int dsi_vc_dcs_read(int channel, u8 dcs_cmd, u8 *buf, int buflen)
2177{
2178 u32 val;
2179 u8 dt;
2180 int r;
2181
2182 if (dsi.debug_read)
Tomi Valkeinenff90a342009-12-03 13:38:04 +02002183 DSSDBG("dsi_vc_dcs_read(ch%d, dcs_cmd %x)\n", channel, dcs_cmd);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002184
2185 r = dsi_vc_send_short(channel, DSI_DT_DCS_READ, dcs_cmd, 0);
2186 if (r)
2187 return r;
2188
2189 r = dsi_vc_send_bta_sync(channel);
2190 if (r)
2191 return r;
2192
2193 /* RX_FIFO_NOT_EMPTY */
2194 if (REG_GET(DSI_VC_CTRL(channel), 20, 20) == 0) {
2195 DSSERR("RX fifo empty when trying to read.\n");
2196 return -EIO;
2197 }
2198
2199 val = dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel));
2200 if (dsi.debug_read)
2201 DSSDBG("\theader: %08x\n", val);
2202 dt = FLD_GET(val, 5, 0);
2203 if (dt == DSI_DT_RX_ACK_WITH_ERR) {
2204 u16 err = FLD_GET(val, 23, 8);
2205 dsi_show_rx_ack_with_err(err);
2206 return -EIO;
2207
2208 } else if (dt == DSI_DT_RX_SHORT_READ_1) {
2209 u8 data = FLD_GET(val, 15, 8);
2210 if (dsi.debug_read)
2211 DSSDBG("\tDCS short response, 1 byte: %02x\n", data);
2212
2213 if (buflen < 1)
2214 return -EIO;
2215
2216 buf[0] = data;
2217
2218 return 1;
2219 } else if (dt == DSI_DT_RX_SHORT_READ_2) {
2220 u16 data = FLD_GET(val, 23, 8);
2221 if (dsi.debug_read)
2222 DSSDBG("\tDCS short response, 2 byte: %04x\n", data);
2223
2224 if (buflen < 2)
2225 return -EIO;
2226
2227 buf[0] = data & 0xff;
2228 buf[1] = (data >> 8) & 0xff;
2229
2230 return 2;
2231 } else if (dt == DSI_DT_RX_DCS_LONG_READ) {
2232 int w;
2233 int len = FLD_GET(val, 23, 8);
2234 if (dsi.debug_read)
2235 DSSDBG("\tDCS long response, len %d\n", len);
2236
2237 if (len > buflen)
2238 return -EIO;
2239
2240 /* two byte checksum ends the packet, not included in len */
2241 for (w = 0; w < len + 2;) {
2242 int b;
2243 val = dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel));
2244 if (dsi.debug_read)
2245 DSSDBG("\t\t%02x %02x %02x %02x\n",
2246 (val >> 0) & 0xff,
2247 (val >> 8) & 0xff,
2248 (val >> 16) & 0xff,
2249 (val >> 24) & 0xff);
2250
2251 for (b = 0; b < 4; ++b) {
2252 if (w < len)
2253 buf[w] = (val >> (b * 8)) & 0xff;
2254 /* we discard the 2 byte checksum */
2255 ++w;
2256 }
2257 }
2258
2259 return len;
2260
2261 } else {
2262 DSSERR("\tunknown datatype 0x%02x\n", dt);
2263 return -EIO;
2264 }
2265}
2266EXPORT_SYMBOL(dsi_vc_dcs_read);
2267
Tomi Valkeinen828c48f2009-12-16 14:53:15 +02002268int dsi_vc_dcs_read_1(int channel, u8 dcs_cmd, u8 *data)
2269{
2270 int r;
2271
2272 r = dsi_vc_dcs_read(channel, dcs_cmd, data, 1);
2273
2274 if (r < 0)
2275 return r;
2276
2277 if (r != 1)
2278 return -EIO;
2279
2280 return 0;
2281}
2282EXPORT_SYMBOL(dsi_vc_dcs_read_1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002283
2284int dsi_vc_set_max_rx_packet_size(int channel, u16 len)
2285{
2286 int r;
2287 r = dsi_vc_send_short(channel, DSI_DT_SET_MAX_RET_PKG_SIZE,
2288 len, 0);
2289
2290 if (r)
2291 return r;
2292
2293 r = dsi_vc_send_bta_sync(channel);
2294
2295 return r;
2296}
2297EXPORT_SYMBOL(dsi_vc_set_max_rx_packet_size);
2298
2299static void dsi_set_lp_rx_timeout(unsigned long ns)
2300{
2301 u32 r;
2302 unsigned x4, x16;
2303 unsigned long fck;
2304 unsigned long ticks;
2305
2306 /* ticks in DSI_FCK */
2307
2308 fck = dsi_fclk_rate();
2309 ticks = (fck / 1000 / 1000) * ns / 1000;
2310 x4 = 0;
2311 x16 = 0;
2312
2313 if (ticks > 0x1fff) {
2314 ticks = (fck / 1000 / 1000) * ns / 1000 / 4;
2315 x4 = 1;
2316 x16 = 0;
2317 }
2318
2319 if (ticks > 0x1fff) {
2320 ticks = (fck / 1000 / 1000) * ns / 1000 / 16;
2321 x4 = 0;
2322 x16 = 1;
2323 }
2324
2325 if (ticks > 0x1fff) {
2326 ticks = (fck / 1000 / 1000) * ns / 1000 / (4 * 16);
2327 x4 = 1;
2328 x16 = 1;
2329 }
2330
2331 if (ticks > 0x1fff) {
2332 DSSWARN("LP_TX_TO over limit, setting it to max\n");
2333 ticks = 0x1fff;
2334 x4 = 1;
2335 x16 = 1;
2336 }
2337
2338 r = dsi_read_reg(DSI_TIMING2);
2339 r = FLD_MOD(r, 1, 15, 15); /* LP_RX_TO */
2340 r = FLD_MOD(r, x16, 14, 14); /* LP_RX_TO_X16 */
2341 r = FLD_MOD(r, x4, 13, 13); /* LP_RX_TO_X4 */
2342 r = FLD_MOD(r, ticks, 12, 0); /* LP_RX_COUNTER */
2343 dsi_write_reg(DSI_TIMING2, r);
2344
2345 DSSDBG("LP_RX_TO %lu ns (%#lx ticks%s%s)\n",
2346 (ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1) * 1000) /
2347 (fck / 1000 / 1000),
2348 ticks, x4 ? " x4" : "", x16 ? " x16" : "");
2349}
2350
2351static void dsi_set_ta_timeout(unsigned long ns)
2352{
2353 u32 r;
2354 unsigned x8, x16;
2355 unsigned long fck;
2356 unsigned long ticks;
2357
2358 /* ticks in DSI_FCK */
2359 fck = dsi_fclk_rate();
2360 ticks = (fck / 1000 / 1000) * ns / 1000;
2361 x8 = 0;
2362 x16 = 0;
2363
2364 if (ticks > 0x1fff) {
2365 ticks = (fck / 1000 / 1000) * ns / 1000 / 8;
2366 x8 = 1;
2367 x16 = 0;
2368 }
2369
2370 if (ticks > 0x1fff) {
2371 ticks = (fck / 1000 / 1000) * ns / 1000 / 16;
2372 x8 = 0;
2373 x16 = 1;
2374 }
2375
2376 if (ticks > 0x1fff) {
2377 ticks = (fck / 1000 / 1000) * ns / 1000 / (8 * 16);
2378 x8 = 1;
2379 x16 = 1;
2380 }
2381
2382 if (ticks > 0x1fff) {
2383 DSSWARN("TA_TO over limit, setting it to max\n");
2384 ticks = 0x1fff;
2385 x8 = 1;
2386 x16 = 1;
2387 }
2388
2389 r = dsi_read_reg(DSI_TIMING1);
2390 r = FLD_MOD(r, 1, 31, 31); /* TA_TO */
2391 r = FLD_MOD(r, x16, 30, 30); /* TA_TO_X16 */
2392 r = FLD_MOD(r, x8, 29, 29); /* TA_TO_X8 */
2393 r = FLD_MOD(r, ticks, 28, 16); /* TA_TO_COUNTER */
2394 dsi_write_reg(DSI_TIMING1, r);
2395
2396 DSSDBG("TA_TO %lu ns (%#lx ticks%s%s)\n",
2397 (ticks * (x16 ? 16 : 1) * (x8 ? 8 : 1) * 1000) /
2398 (fck / 1000 / 1000),
2399 ticks, x8 ? " x8" : "", x16 ? " x16" : "");
2400}
2401
2402static void dsi_set_stop_state_counter(unsigned long ns)
2403{
2404 u32 r;
2405 unsigned x4, x16;
2406 unsigned long fck;
2407 unsigned long ticks;
2408
2409 /* ticks in DSI_FCK */
2410
2411 fck = dsi_fclk_rate();
2412 ticks = (fck / 1000 / 1000) * ns / 1000;
2413 x4 = 0;
2414 x16 = 0;
2415
2416 if (ticks > 0x1fff) {
2417 ticks = (fck / 1000 / 1000) * ns / 1000 / 4;
2418 x4 = 1;
2419 x16 = 0;
2420 }
2421
2422 if (ticks > 0x1fff) {
2423 ticks = (fck / 1000 / 1000) * ns / 1000 / 16;
2424 x4 = 0;
2425 x16 = 1;
2426 }
2427
2428 if (ticks > 0x1fff) {
2429 ticks = (fck / 1000 / 1000) * ns / 1000 / (4 * 16);
2430 x4 = 1;
2431 x16 = 1;
2432 }
2433
2434 if (ticks > 0x1fff) {
2435 DSSWARN("STOP_STATE_COUNTER_IO over limit, "
2436 "setting it to max\n");
2437 ticks = 0x1fff;
2438 x4 = 1;
2439 x16 = 1;
2440 }
2441
2442 r = dsi_read_reg(DSI_TIMING1);
2443 r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
2444 r = FLD_MOD(r, x16, 14, 14); /* STOP_STATE_X16_IO */
2445 r = FLD_MOD(r, x4, 13, 13); /* STOP_STATE_X4_IO */
2446 r = FLD_MOD(r, ticks, 12, 0); /* STOP_STATE_COUNTER_IO */
2447 dsi_write_reg(DSI_TIMING1, r);
2448
2449 DSSDBG("STOP_STATE_COUNTER %lu ns (%#lx ticks%s%s)\n",
2450 (ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1) * 1000) /
2451 (fck / 1000 / 1000),
2452 ticks, x4 ? " x4" : "", x16 ? " x16" : "");
2453}
2454
2455static void dsi_set_hs_tx_timeout(unsigned long ns)
2456{
2457 u32 r;
2458 unsigned x4, x16;
2459 unsigned long fck;
2460 unsigned long ticks;
2461
2462 /* ticks in TxByteClkHS */
2463
2464 fck = dsi_get_txbyteclkhs();
2465 ticks = (fck / 1000 / 1000) * ns / 1000;
2466 x4 = 0;
2467 x16 = 0;
2468
2469 if (ticks > 0x1fff) {
2470 ticks = (fck / 1000 / 1000) * ns / 1000 / 4;
2471 x4 = 1;
2472 x16 = 0;
2473 }
2474
2475 if (ticks > 0x1fff) {
2476 ticks = (fck / 1000 / 1000) * ns / 1000 / 16;
2477 x4 = 0;
2478 x16 = 1;
2479 }
2480
2481 if (ticks > 0x1fff) {
2482 ticks = (fck / 1000 / 1000) * ns / 1000 / (4 * 16);
2483 x4 = 1;
2484 x16 = 1;
2485 }
2486
2487 if (ticks > 0x1fff) {
2488 DSSWARN("HS_TX_TO over limit, setting it to max\n");
2489 ticks = 0x1fff;
2490 x4 = 1;
2491 x16 = 1;
2492 }
2493
2494 r = dsi_read_reg(DSI_TIMING2);
2495 r = FLD_MOD(r, 1, 31, 31); /* HS_TX_TO */
2496 r = FLD_MOD(r, x16, 30, 30); /* HS_TX_TO_X16 */
2497 r = FLD_MOD(r, x4, 29, 29); /* HS_TX_TO_X8 (4 really) */
2498 r = FLD_MOD(r, ticks, 28, 16); /* HS_TX_TO_COUNTER */
2499 dsi_write_reg(DSI_TIMING2, r);
2500
2501 DSSDBG("HS_TX_TO %lu ns (%#lx ticks%s%s)\n",
2502 (ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1) * 1000) /
2503 (fck / 1000 / 1000),
2504 ticks, x4 ? " x4" : "", x16 ? " x16" : "");
2505}
2506static int dsi_proto_config(struct omap_dss_device *dssdev)
2507{
2508 u32 r;
2509 int buswidth = 0;
2510
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02002511 dsi_config_tx_fifo(DSI_FIFO_SIZE_32,
2512 DSI_FIFO_SIZE_32,
2513 DSI_FIFO_SIZE_32,
2514 DSI_FIFO_SIZE_32);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002515
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02002516 dsi_config_rx_fifo(DSI_FIFO_SIZE_32,
2517 DSI_FIFO_SIZE_32,
2518 DSI_FIFO_SIZE_32,
2519 DSI_FIFO_SIZE_32);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002520
2521 /* XXX what values for the timeouts? */
2522 dsi_set_stop_state_counter(1000);
2523 dsi_set_ta_timeout(6400000);
2524 dsi_set_lp_rx_timeout(48000);
2525 dsi_set_hs_tx_timeout(1000000);
2526
2527 switch (dssdev->ctrl.pixel_size) {
2528 case 16:
2529 buswidth = 0;
2530 break;
2531 case 18:
2532 buswidth = 1;
2533 break;
2534 case 24:
2535 buswidth = 2;
2536 break;
2537 default:
2538 BUG();
2539 }
2540
2541 r = dsi_read_reg(DSI_CTRL);
2542 r = FLD_MOD(r, 1, 1, 1); /* CS_RX_EN */
2543 r = FLD_MOD(r, 1, 2, 2); /* ECC_RX_EN */
2544 r = FLD_MOD(r, 1, 3, 3); /* TX_FIFO_ARBITRATION */
2545 r = FLD_MOD(r, 1, 4, 4); /* VP_CLK_RATIO, always 1, see errata*/
2546 r = FLD_MOD(r, buswidth, 7, 6); /* VP_DATA_BUS_WIDTH */
2547 r = FLD_MOD(r, 0, 8, 8); /* VP_CLK_POL */
2548 r = FLD_MOD(r, 2, 13, 12); /* LINE_BUFFER, 2 lines */
2549 r = FLD_MOD(r, 1, 14, 14); /* TRIGGER_RESET_MODE */
2550 r = FLD_MOD(r, 1, 19, 19); /* EOT_ENABLE */
2551 r = FLD_MOD(r, 1, 24, 24); /* DCS_CMD_ENABLE */
2552 r = FLD_MOD(r, 0, 25, 25); /* DCS_CMD_CODE, 1=start, 0=continue */
2553
2554 dsi_write_reg(DSI_CTRL, r);
2555
2556 dsi_vc_initial_config(0);
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02002557 dsi_vc_initial_config(1);
2558 dsi_vc_initial_config(2);
2559 dsi_vc_initial_config(3);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002560
2561 return 0;
2562}
2563
2564static void dsi_proto_timings(struct omap_dss_device *dssdev)
2565{
2566 unsigned tlpx, tclk_zero, tclk_prepare, tclk_trail;
2567 unsigned tclk_pre, tclk_post;
2568 unsigned ths_prepare, ths_prepare_ths_zero, ths_zero;
2569 unsigned ths_trail, ths_exit;
2570 unsigned ddr_clk_pre, ddr_clk_post;
2571 unsigned enter_hs_mode_lat, exit_hs_mode_lat;
2572 unsigned ths_eot;
2573 u32 r;
2574
2575 r = dsi_read_reg(DSI_DSIPHY_CFG0);
2576 ths_prepare = FLD_GET(r, 31, 24);
2577 ths_prepare_ths_zero = FLD_GET(r, 23, 16);
2578 ths_zero = ths_prepare_ths_zero - ths_prepare;
2579 ths_trail = FLD_GET(r, 15, 8);
2580 ths_exit = FLD_GET(r, 7, 0);
2581
2582 r = dsi_read_reg(DSI_DSIPHY_CFG1);
2583 tlpx = FLD_GET(r, 22, 16) * 2;
2584 tclk_trail = FLD_GET(r, 15, 8);
2585 tclk_zero = FLD_GET(r, 7, 0);
2586
2587 r = dsi_read_reg(DSI_DSIPHY_CFG2);
2588 tclk_prepare = FLD_GET(r, 7, 0);
2589
2590 /* min 8*UI */
2591 tclk_pre = 20;
2592 /* min 60ns + 52*UI */
2593 tclk_post = ns2ddr(60) + 26;
2594
2595 /* ths_eot is 2 for 2 datalanes and 4 for 1 datalane */
2596 if (dssdev->phy.dsi.data1_lane != 0 &&
2597 dssdev->phy.dsi.data2_lane != 0)
2598 ths_eot = 2;
2599 else
2600 ths_eot = 4;
2601
2602 ddr_clk_pre = DIV_ROUND_UP(tclk_pre + tlpx + tclk_zero + tclk_prepare,
2603 4);
2604 ddr_clk_post = DIV_ROUND_UP(tclk_post + ths_trail, 4) + ths_eot;
2605
2606 BUG_ON(ddr_clk_pre == 0 || ddr_clk_pre > 255);
2607 BUG_ON(ddr_clk_post == 0 || ddr_clk_post > 255);
2608
2609 r = dsi_read_reg(DSI_CLK_TIMING);
2610 r = FLD_MOD(r, ddr_clk_pre, 15, 8);
2611 r = FLD_MOD(r, ddr_clk_post, 7, 0);
2612 dsi_write_reg(DSI_CLK_TIMING, r);
2613
2614 DSSDBG("ddr_clk_pre %u, ddr_clk_post %u\n",
2615 ddr_clk_pre,
2616 ddr_clk_post);
2617
2618 enter_hs_mode_lat = 1 + DIV_ROUND_UP(tlpx, 4) +
2619 DIV_ROUND_UP(ths_prepare, 4) +
2620 DIV_ROUND_UP(ths_zero + 3, 4);
2621
2622 exit_hs_mode_lat = DIV_ROUND_UP(ths_trail + ths_exit, 4) + 1 + ths_eot;
2623
2624 r = FLD_VAL(enter_hs_mode_lat, 31, 16) |
2625 FLD_VAL(exit_hs_mode_lat, 15, 0);
2626 dsi_write_reg(DSI_VM_TIMING7, r);
2627
2628 DSSDBG("enter_hs_mode_lat %u, exit_hs_mode_lat %u\n",
2629 enter_hs_mode_lat, exit_hs_mode_lat);
2630}
2631
2632
2633#define DSI_DECL_VARS \
2634 int __dsi_cb = 0; u32 __dsi_cv = 0;
2635
2636#define DSI_FLUSH(ch) \
2637 if (__dsi_cb > 0) { \
2638 /*DSSDBG("sending long packet %#010x\n", __dsi_cv);*/ \
2639 dsi_write_reg(DSI_VC_LONG_PACKET_PAYLOAD(ch), __dsi_cv); \
2640 __dsi_cb = __dsi_cv = 0; \
2641 }
2642
2643#define DSI_PUSH(ch, data) \
2644 do { \
2645 __dsi_cv |= (data) << (__dsi_cb * 8); \
2646 /*DSSDBG("cv = %#010x, cb = %d\n", __dsi_cv, __dsi_cb);*/ \
2647 if (++__dsi_cb > 3) \
2648 DSI_FLUSH(ch); \
2649 } while (0)
2650
2651static int dsi_update_screen_l4(struct omap_dss_device *dssdev,
2652 int x, int y, int w, int h)
2653{
2654 /* Note: supports only 24bit colors in 32bit container */
2655 int first = 1;
2656 int fifo_stalls = 0;
2657 int max_dsi_packet_size;
2658 int max_data_per_packet;
2659 int max_pixels_per_packet;
2660 int pixels_left;
2661 int bytespp = dssdev->ctrl.pixel_size / 8;
2662 int scr_width;
2663 u32 __iomem *data;
2664 int start_offset;
2665 int horiz_inc;
2666 int current_x;
2667 struct omap_overlay *ovl;
2668
2669 debug_irq = 0;
2670
2671 DSSDBG("dsi_update_screen_l4 (%d,%d %dx%d)\n",
2672 x, y, w, h);
2673
2674 ovl = dssdev->manager->overlays[0];
2675
2676 if (ovl->info.color_mode != OMAP_DSS_COLOR_RGB24U)
2677 return -EINVAL;
2678
2679 if (dssdev->ctrl.pixel_size != 24)
2680 return -EINVAL;
2681
2682 scr_width = ovl->info.screen_width;
2683 data = ovl->info.vaddr;
2684
2685 start_offset = scr_width * y + x;
2686 horiz_inc = scr_width - w;
2687 current_x = x;
2688
2689 /* We need header(4) + DCSCMD(1) + pixels(numpix*bytespp) bytes
2690 * in fifo */
2691
2692 /* When using CPU, max long packet size is TX buffer size */
2693 max_dsi_packet_size = dsi.vc[0].fifo_size * 32 * 4;
2694
2695 /* we seem to get better perf if we divide the tx fifo to half,
2696 and while the other half is being sent, we fill the other half
2697 max_dsi_packet_size /= 2; */
2698
2699 max_data_per_packet = max_dsi_packet_size - 4 - 1;
2700
2701 max_pixels_per_packet = max_data_per_packet / bytespp;
2702
2703 DSSDBG("max_pixels_per_packet %d\n", max_pixels_per_packet);
2704
2705 pixels_left = w * h;
2706
2707 DSSDBG("total pixels %d\n", pixels_left);
2708
2709 data += start_offset;
2710
2711 while (pixels_left > 0) {
2712 /* 0x2c = write_memory_start */
2713 /* 0x3c = write_memory_continue */
2714 u8 dcs_cmd = first ? 0x2c : 0x3c;
2715 int pixels;
2716 DSI_DECL_VARS;
2717 first = 0;
2718
2719#if 1
2720 /* using fifo not empty */
2721 /* TX_FIFO_NOT_EMPTY */
2722 while (FLD_GET(dsi_read_reg(DSI_VC_CTRL(0)), 5, 5)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002723 fifo_stalls++;
2724 if (fifo_stalls > 0xfffff) {
2725 DSSERR("fifo stalls overflow, pixels left %d\n",
2726 pixels_left);
2727 dsi_if_enable(0);
2728 return -EIO;
2729 }
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02002730 udelay(1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002731 }
2732#elif 1
2733 /* using fifo emptiness */
2734 while ((REG_GET(DSI_TX_FIFO_VC_EMPTINESS, 7, 0)+1)*4 <
2735 max_dsi_packet_size) {
2736 fifo_stalls++;
2737 if (fifo_stalls > 0xfffff) {
2738 DSSERR("fifo stalls overflow, pixels left %d\n",
2739 pixels_left);
2740 dsi_if_enable(0);
2741 return -EIO;
2742 }
2743 }
2744#else
2745 while ((REG_GET(DSI_TX_FIFO_VC_EMPTINESS, 7, 0)+1)*4 == 0) {
2746 fifo_stalls++;
2747 if (fifo_stalls > 0xfffff) {
2748 DSSERR("fifo stalls overflow, pixels left %d\n",
2749 pixels_left);
2750 dsi_if_enable(0);
2751 return -EIO;
2752 }
2753 }
2754#endif
2755 pixels = min(max_pixels_per_packet, pixels_left);
2756
2757 pixels_left -= pixels;
2758
2759 dsi_vc_write_long_header(0, DSI_DT_DCS_LONG_WRITE,
2760 1 + pixels * bytespp, 0);
2761
2762 DSI_PUSH(0, dcs_cmd);
2763
2764 while (pixels-- > 0) {
2765 u32 pix = __raw_readl(data++);
2766
2767 DSI_PUSH(0, (pix >> 16) & 0xff);
2768 DSI_PUSH(0, (pix >> 8) & 0xff);
2769 DSI_PUSH(0, (pix >> 0) & 0xff);
2770
2771 current_x++;
2772 if (current_x == x+w) {
2773 current_x = x;
2774 data += horiz_inc;
2775 }
2776 }
2777
2778 DSI_FLUSH(0);
2779 }
2780
2781 return 0;
2782}
2783
2784static void dsi_update_screen_dispc(struct omap_dss_device *dssdev,
2785 u16 x, u16 y, u16 w, u16 h)
2786{
2787 unsigned bytespp;
2788 unsigned bytespl;
2789 unsigned bytespf;
2790 unsigned total_len;
2791 unsigned packet_payload;
2792 unsigned packet_len;
2793 u32 l;
2794 bool use_te_trigger;
2795 const unsigned channel = 0;
2796 /* line buffer is 1024 x 24bits */
2797 /* XXX: for some reason using full buffer size causes considerable TX
2798 * slowdown with update sizes that fill the whole buffer */
2799 const unsigned line_buf_size = 1023 * 3;
2800
2801 use_te_trigger = dsi.te_enabled && !dsi.use_ext_te;
2802
2803 if (dsi.update_mode != OMAP_DSS_UPDATE_AUTO)
2804 DSSDBG("dsi_update_screen_dispc(%d,%d %dx%d)\n",
2805 x, y, w, h);
2806
2807 bytespp = dssdev->ctrl.pixel_size / 8;
2808 bytespl = w * bytespp;
2809 bytespf = bytespl * h;
2810
2811 /* NOTE: packet_payload has to be equal to N * bytespl, where N is
2812 * number of lines in a packet. See errata about VP_CLK_RATIO */
2813
2814 if (bytespf < line_buf_size)
2815 packet_payload = bytespf;
2816 else
2817 packet_payload = (line_buf_size) / bytespl * bytespl;
2818
2819 packet_len = packet_payload + 1; /* 1 byte for DCS cmd */
2820 total_len = (bytespf / packet_payload) * packet_len;
2821
2822 if (bytespf % packet_payload)
2823 total_len += (bytespf % packet_payload) + 1;
2824
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002825 l = FLD_VAL(total_len, 23, 0); /* TE_SIZE */
2826 dsi_write_reg(DSI_VC_TE(channel), l);
2827
2828 dsi_vc_write_long_header(channel, DSI_DT_DCS_LONG_WRITE, packet_len, 0);
2829
2830 if (use_te_trigger)
2831 l = FLD_MOD(l, 1, 30, 30); /* TE_EN */
2832 else
2833 l = FLD_MOD(l, 1, 31, 31); /* TE_START */
2834 dsi_write_reg(DSI_VC_TE(channel), l);
2835
2836 /* We put SIDLEMODE to no-idle for the duration of the transfer,
2837 * because DSS interrupts are not capable of waking up the CPU and the
2838 * framedone interrupt could be delayed for quite a long time. I think
2839 * the same goes for any DSS interrupts, but for some reason I have not
2840 * seen the problem anywhere else than here.
2841 */
2842 dispc_disable_sidle();
2843
2844 dss_start_update(dssdev);
2845
2846 if (use_te_trigger) {
2847 /* disable LP_RX_TO, so that we can receive TE. Time to wait
2848 * for TE is longer than the timer allows */
2849 REG_FLD_MOD(DSI_TIMING2, 0, 15, 15); /* LP_RX_TO */
2850
2851 dsi_vc_send_bta(channel);
2852
2853#ifdef DSI_CATCH_MISSING_TE
2854 mod_timer(&dsi.te_timer, jiffies + msecs_to_jiffies(250));
2855#endif
2856 }
2857}
2858
2859#ifdef DSI_CATCH_MISSING_TE
2860static void dsi_te_timeout(unsigned long arg)
2861{
2862 DSSERR("TE not received for 250ms!\n");
2863}
2864#endif
2865
2866static void dsi_framedone_irq_callback(void *data, u32 mask)
2867{
2868 /* Note: We get FRAMEDONE when DISPC has finished sending pixels and
2869 * turns itself off. However, DSI still has the pixels in its buffers,
2870 * and is sending the data.
2871 */
2872
2873 /* SIDLEMODE back to smart-idle */
2874 dispc_enable_sidle();
2875
2876 dsi.framedone_received = true;
2877 wake_up(&dsi.waitqueue);
2878}
2879
2880static void dsi_set_update_region(struct omap_dss_device *dssdev,
2881 u16 x, u16 y, u16 w, u16 h)
2882{
2883 spin_lock(&dsi.update_lock);
2884 if (dsi.update_region.dirty) {
2885 dsi.update_region.x = min(x, dsi.update_region.x);
2886 dsi.update_region.y = min(y, dsi.update_region.y);
2887 dsi.update_region.w = max(w, dsi.update_region.w);
2888 dsi.update_region.h = max(h, dsi.update_region.h);
2889 } else {
2890 dsi.update_region.x = x;
2891 dsi.update_region.y = y;
2892 dsi.update_region.w = w;
2893 dsi.update_region.h = h;
2894 }
2895
2896 dsi.update_region.device = dssdev;
2897 dsi.update_region.dirty = true;
2898
2899 spin_unlock(&dsi.update_lock);
2900
2901}
2902
2903static int dsi_set_update_mode(struct omap_dss_device *dssdev,
2904 enum omap_dss_update_mode mode)
2905{
2906 int r = 0;
2907 int i;
2908
Tomi Valkeinen4f765022010-01-18 16:27:52 +02002909 WARN_ON(!dsi_bus_is_locked());
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002910
2911 if (dsi.update_mode != mode) {
2912 dsi.update_mode = mode;
2913
2914 /* Mark the overlays dirty, and do apply(), so that we get the
2915 * overlays configured properly after update mode change. */
2916 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
2917 struct omap_overlay *ovl;
2918 ovl = omap_dss_get_overlay(i);
2919 if (ovl->manager == dssdev->manager)
2920 ovl->info_dirty = true;
2921 }
2922
2923 r = dssdev->manager->apply(dssdev->manager);
2924
2925 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE &&
2926 mode == OMAP_DSS_UPDATE_AUTO) {
2927 u16 w, h;
2928
2929 DSSDBG("starting auto update\n");
2930
2931 dssdev->get_resolution(dssdev, &w, &h);
2932
2933 dsi_set_update_region(dssdev, 0, 0, w, h);
2934
2935 dsi_perf_mark_start_auto();
2936
2937 wake_up(&dsi.waitqueue);
2938 }
2939 }
2940
2941 return r;
2942}
2943
2944static int dsi_set_te(struct omap_dss_device *dssdev, bool enable)
2945{
Tomi Valkeinen7475e442009-12-08 17:30:24 +02002946 int r = 0;
2947
2948 if (dssdev->driver->enable_te) {
2949 r = dssdev->driver->enable_te(dssdev, enable);
2950 /* XXX for some reason, DSI TE breaks if we don't wait here.
2951 * Panel bug? Needs more studying */
2952 msleep(100);
2953 }
2954
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002955 return r;
2956}
2957
2958static void dsi_handle_framedone(void)
2959{
2960 int r;
2961 const int channel = 0;
2962 bool use_te_trigger;
2963
2964 use_te_trigger = dsi.te_enabled && !dsi.use_ext_te;
2965
2966 if (dsi.update_mode != OMAP_DSS_UPDATE_AUTO)
2967 DSSDBG("FRAMEDONE\n");
2968
2969 if (use_te_trigger) {
2970 /* enable LP_RX_TO again after the TE */
2971 REG_FLD_MOD(DSI_TIMING2, 1, 15, 15); /* LP_RX_TO */
2972 }
2973
2974 /* Send BTA after the frame. We need this for the TE to work, as TE
2975 * trigger is only sent for BTAs without preceding packet. Thus we need
2976 * to BTA after the pixel packets so that next BTA will cause TE
2977 * trigger.
2978 *
2979 * This is not needed when TE is not in use, but we do it anyway to
2980 * make sure that the transfer has been completed. It would be more
2981 * optimal, but more complex, to wait only just before starting next
2982 * transfer. */
2983 r = dsi_vc_send_bta_sync(channel);
2984 if (r)
2985 DSSERR("BTA after framedone failed\n");
2986
2987 /* RX_FIFO_NOT_EMPTY */
2988 if (REG_GET(DSI_VC_CTRL(channel), 20, 20)) {
2989 DSSERR("Received error during frame transfer:\n");
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02002990 dsi_vc_flush_receive_data(channel);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002991 }
2992
2993#ifdef CONFIG_OMAP2_DSS_FAKE_VSYNC
2994 dispc_fake_vsync_irq();
2995#endif
2996}
2997
2998static int dsi_update_thread(void *data)
2999{
3000 unsigned long timeout;
3001 struct omap_dss_device *device;
3002 u16 x, y, w, h;
3003
3004 while (1) {
3005 bool sched;
3006
3007 wait_event_interruptible(dsi.waitqueue,
3008 dsi.update_mode == OMAP_DSS_UPDATE_AUTO ||
3009 (dsi.update_mode == OMAP_DSS_UPDATE_MANUAL &&
3010 dsi.update_region.dirty == true) ||
3011 kthread_should_stop());
3012
3013 if (kthread_should_stop())
3014 break;
3015
3016 dsi_bus_lock();
3017
3018 if (dsi.update_mode == OMAP_DSS_UPDATE_DISABLED ||
3019 kthread_should_stop()) {
3020 dsi_bus_unlock();
3021 break;
3022 }
3023
3024 dsi_perf_mark_setup();
3025
3026 if (dsi.update_region.dirty) {
3027 spin_lock(&dsi.update_lock);
3028 dsi.active_update_region = dsi.update_region;
3029 dsi.update_region.dirty = false;
3030 spin_unlock(&dsi.update_lock);
3031 }
3032
3033 device = dsi.active_update_region.device;
3034 x = dsi.active_update_region.x;
3035 y = dsi.active_update_region.y;
3036 w = dsi.active_update_region.w;
3037 h = dsi.active_update_region.h;
3038
3039 if (device->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) {
3040
3041 if (dsi.update_mode == OMAP_DSS_UPDATE_MANUAL)
3042 dss_setup_partial_planes(device,
3043 &x, &y, &w, &h);
3044
3045 dispc_set_lcd_size(w, h);
3046 }
3047
3048 if (dsi.active_update_region.dirty) {
3049 dsi.active_update_region.dirty = false;
3050 /* XXX TODO we don't need to send the coords, if they
3051 * are the same that are already programmed to the
3052 * panel. That should speed up manual update a bit */
3053 device->driver->setup_update(device, x, y, w, h);
3054 }
3055
3056 dsi_perf_mark_start();
3057
3058 if (device->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) {
3059 dsi_vc_config_vp(0);
3060
3061 if (dsi.te_enabled && dsi.use_ext_te)
3062 device->driver->wait_for_te(device);
3063
3064 dsi.framedone_received = false;
3065
3066 dsi_update_screen_dispc(device, x, y, w, h);
3067
3068 /* wait for framedone */
3069 timeout = msecs_to_jiffies(1000);
3070 wait_event_timeout(dsi.waitqueue,
3071 dsi.framedone_received == true,
3072 timeout);
3073
3074 if (!dsi.framedone_received) {
3075 DSSERR("framedone timeout\n");
3076 DSSERR("failed update %d,%d %dx%d\n",
3077 x, y, w, h);
3078
3079 dispc_enable_sidle();
3080 dispc_enable_lcd_out(0);
3081
3082 dsi_reset_tx_fifo(0);
3083 } else {
3084 dsi_handle_framedone();
3085 dsi_perf_show("DISPC");
3086 }
3087 } else {
3088 dsi_update_screen_l4(device, x, y, w, h);
3089 dsi_perf_show("L4");
3090 }
3091
3092 sched = atomic_read(&dsi.bus_lock.count) < 0;
3093
3094 complete_all(&dsi.update_completion);
3095
3096 dsi_bus_unlock();
3097
3098 /* XXX We need to give others chance to get the bus lock. Is
3099 * there a better way for this? */
3100 if (dsi.update_mode == OMAP_DSS_UPDATE_AUTO && sched)
3101 schedule_timeout_interruptible(1);
3102 }
3103
3104 DSSDBG("update thread exiting\n");
3105
3106 return 0;
3107}
3108
3109
3110
3111/* Display funcs */
3112
3113static int dsi_display_init_dispc(struct omap_dss_device *dssdev)
3114{
3115 int r;
3116
3117 r = omap_dispc_register_isr(dsi_framedone_irq_callback, NULL,
3118 DISPC_IRQ_FRAMEDONE);
3119 if (r) {
3120 DSSERR("can't get FRAMEDONE irq\n");
3121 return r;
3122 }
3123
3124 dispc_set_lcd_display_type(OMAP_DSS_LCD_DISPLAY_TFT);
3125
3126 dispc_set_parallel_interface_mode(OMAP_DSS_PARALLELMODE_DSI);
3127 dispc_enable_fifohandcheck(1);
3128
3129 dispc_set_tft_data_lines(dssdev->ctrl.pixel_size);
3130
3131 {
3132 struct omap_video_timings timings = {
3133 .hsw = 1,
3134 .hfp = 1,
3135 .hbp = 1,
3136 .vsw = 1,
3137 .vfp = 0,
3138 .vbp = 0,
3139 };
3140
3141 dispc_set_lcd_timings(&timings);
3142 }
3143
3144 return 0;
3145}
3146
3147static void dsi_display_uninit_dispc(struct omap_dss_device *dssdev)
3148{
3149 omap_dispc_unregister_isr(dsi_framedone_irq_callback, NULL,
3150 DISPC_IRQ_FRAMEDONE);
3151}
3152
3153static int dsi_configure_dsi_clocks(struct omap_dss_device *dssdev)
3154{
3155 struct dsi_clock_info cinfo;
3156 int r;
3157
3158 /* we always use DSS2_FCK as input clock */
3159 cinfo.use_dss2_fck = true;
3160 cinfo.regn = dssdev->phy.dsi.div.regn;
3161 cinfo.regm = dssdev->phy.dsi.div.regm;
3162 cinfo.regm3 = dssdev->phy.dsi.div.regm3;
3163 cinfo.regm4 = dssdev->phy.dsi.div.regm4;
3164 r = dsi_calc_clock_rates(&cinfo);
3165 if (r)
3166 return r;
3167
3168 r = dsi_pll_set_clock_div(&cinfo);
3169 if (r) {
3170 DSSERR("Failed to set dsi clocks\n");
3171 return r;
3172 }
3173
3174 return 0;
3175}
3176
3177static int dsi_configure_dispc_clocks(struct omap_dss_device *dssdev)
3178{
3179 struct dispc_clock_info dispc_cinfo;
3180 int r;
3181 unsigned long long fck;
3182
3183 fck = dsi_get_dsi1_pll_rate();
3184
3185 dispc_cinfo.lck_div = dssdev->phy.dsi.div.lck_div;
3186 dispc_cinfo.pck_div = dssdev->phy.dsi.div.pck_div;
3187
3188 r = dispc_calc_clock_rates(fck, &dispc_cinfo);
3189 if (r) {
3190 DSSERR("Failed to calc dispc clocks\n");
3191 return r;
3192 }
3193
3194 r = dispc_set_clock_div(&dispc_cinfo);
3195 if (r) {
3196 DSSERR("Failed to set dispc clocks\n");
3197 return r;
3198 }
3199
3200 return 0;
3201}
3202
3203static int dsi_display_init_dsi(struct omap_dss_device *dssdev)
3204{
3205 int r;
3206
3207 _dsi_print_reset_status();
3208
3209 r = dsi_pll_init(dssdev, true, true);
3210 if (r)
3211 goto err0;
3212
3213 r = dsi_configure_dsi_clocks(dssdev);
3214 if (r)
3215 goto err1;
3216
Tomi Valkeinen2f18c4d2010-01-08 18:00:36 +02003217 dss_select_dispc_clk_source(DSS_SRC_DSI1_PLL_FCLK);
3218 dss_select_dsi_clk_source(DSS_SRC_DSI2_PLL_FCLK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003219
3220 DSSDBG("PLL OK\n");
3221
3222 r = dsi_configure_dispc_clocks(dssdev);
3223 if (r)
3224 goto err2;
3225
3226 r = dsi_complexio_init(dssdev);
3227 if (r)
3228 goto err2;
3229
3230 _dsi_print_reset_status();
3231
3232 dsi_proto_timings(dssdev);
3233 dsi_set_lp_clk_divisor(dssdev);
3234
3235 if (1)
3236 _dsi_print_reset_status();
3237
3238 r = dsi_proto_config(dssdev);
3239 if (r)
3240 goto err3;
3241
3242 /* enable interface */
3243 dsi_vc_enable(0, 1);
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02003244 dsi_vc_enable(1, 1);
3245 dsi_vc_enable(2, 1);
3246 dsi_vc_enable(3, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003247 dsi_if_enable(1);
3248 dsi_force_tx_stop_mode_io();
3249
3250 if (dssdev->driver->enable) {
3251 r = dssdev->driver->enable(dssdev);
3252 if (r)
3253 goto err4;
3254 }
3255
3256 /* enable high-speed after initial config */
Tomi Valkeinen61140c92010-01-12 16:00:30 +02003257 omapdss_dsi_vc_enable_hs(0, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003258
3259 return 0;
3260err4:
3261 dsi_if_enable(0);
3262err3:
3263 dsi_complexio_uninit();
3264err2:
Tomi Valkeinen2f18c4d2010-01-08 18:00:36 +02003265 dss_select_dispc_clk_source(DSS_SRC_DSS1_ALWON_FCLK);
3266 dss_select_dsi_clk_source(DSS_SRC_DSS1_ALWON_FCLK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003267err1:
3268 dsi_pll_uninit();
3269err0:
3270 return r;
3271}
3272
3273static void dsi_display_uninit_dsi(struct omap_dss_device *dssdev)
3274{
3275 if (dssdev->driver->disable)
3276 dssdev->driver->disable(dssdev);
3277
Tomi Valkeinen2f18c4d2010-01-08 18:00:36 +02003278 dss_select_dispc_clk_source(DSS_SRC_DSS1_ALWON_FCLK);
3279 dss_select_dsi_clk_source(DSS_SRC_DSS1_ALWON_FCLK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003280 dsi_complexio_uninit();
3281 dsi_pll_uninit();
3282}
3283
3284static int dsi_core_init(void)
3285{
3286 /* Autoidle */
3287 REG_FLD_MOD(DSI_SYSCONFIG, 1, 0, 0);
3288
3289 /* ENWAKEUP */
3290 REG_FLD_MOD(DSI_SYSCONFIG, 1, 2, 2);
3291
3292 /* SIDLEMODE smart-idle */
3293 REG_FLD_MOD(DSI_SYSCONFIG, 2, 4, 3);
3294
3295 _dsi_initialize_irq();
3296
3297 return 0;
3298}
3299
3300static int dsi_display_enable(struct omap_dss_device *dssdev)
3301{
3302 int r = 0;
3303
3304 DSSDBG("dsi_display_enable\n");
3305
3306 mutex_lock(&dsi.lock);
3307 dsi_bus_lock();
3308
3309 r = omap_dss_start_device(dssdev);
3310 if (r) {
3311 DSSERR("failed to start device\n");
3312 goto err0;
3313 }
3314
3315 if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
3316 DSSERR("dssdev already enabled\n");
3317 r = -EINVAL;
3318 goto err1;
3319 }
3320
3321 enable_clocks(1);
3322 dsi_enable_pll_clock(1);
3323
3324 r = _dsi_reset();
3325 if (r)
3326 goto err2;
3327
3328 dsi_core_init();
3329
3330 r = dsi_display_init_dispc(dssdev);
3331 if (r)
3332 goto err2;
3333
3334 r = dsi_display_init_dsi(dssdev);
3335 if (r)
3336 goto err3;
3337
3338 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
3339
3340 dsi.use_ext_te = dssdev->phy.dsi.ext_te;
3341 r = dsi_set_te(dssdev, dsi.te_enabled);
3342 if (r)
3343 goto err4;
3344
3345 dsi_set_update_mode(dssdev, dsi.user_update_mode);
3346
3347 dsi_bus_unlock();
3348 mutex_unlock(&dsi.lock);
3349
3350 return 0;
3351
3352err4:
3353
3354 dsi_display_uninit_dsi(dssdev);
3355err3:
3356 dsi_display_uninit_dispc(dssdev);
3357err2:
3358 enable_clocks(0);
3359 dsi_enable_pll_clock(0);
3360err1:
3361 omap_dss_stop_device(dssdev);
3362err0:
3363 dsi_bus_unlock();
3364 mutex_unlock(&dsi.lock);
3365 DSSDBG("dsi_display_enable FAILED\n");
3366 return r;
3367}
3368
3369static void dsi_display_disable(struct omap_dss_device *dssdev)
3370{
3371 DSSDBG("dsi_display_disable\n");
3372
3373 mutex_lock(&dsi.lock);
3374 dsi_bus_lock();
3375
3376 if (dssdev->state == OMAP_DSS_DISPLAY_DISABLED ||
3377 dssdev->state == OMAP_DSS_DISPLAY_SUSPENDED)
3378 goto end;
3379
3380 dsi.update_mode = OMAP_DSS_UPDATE_DISABLED;
3381 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
3382
3383 dsi_display_uninit_dispc(dssdev);
3384
3385 dsi_display_uninit_dsi(dssdev);
3386
3387 enable_clocks(0);
3388 dsi_enable_pll_clock(0);
3389
3390 omap_dss_stop_device(dssdev);
3391end:
3392 dsi_bus_unlock();
3393 mutex_unlock(&dsi.lock);
3394}
3395
3396static int dsi_display_suspend(struct omap_dss_device *dssdev)
3397{
3398 DSSDBG("dsi_display_suspend\n");
3399
3400 mutex_lock(&dsi.lock);
3401 dsi_bus_lock();
3402
3403 if (dssdev->state == OMAP_DSS_DISPLAY_DISABLED ||
3404 dssdev->state == OMAP_DSS_DISPLAY_SUSPENDED)
3405 goto end;
3406
3407 dsi.update_mode = OMAP_DSS_UPDATE_DISABLED;
3408 dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
3409
3410 dsi_display_uninit_dispc(dssdev);
3411
3412 dsi_display_uninit_dsi(dssdev);
3413
3414 enable_clocks(0);
3415 dsi_enable_pll_clock(0);
3416end:
3417 dsi_bus_unlock();
3418 mutex_unlock(&dsi.lock);
3419
3420 return 0;
3421}
3422
3423static int dsi_display_resume(struct omap_dss_device *dssdev)
3424{
3425 int r;
3426
3427 DSSDBG("dsi_display_resume\n");
3428
3429 mutex_lock(&dsi.lock);
3430 dsi_bus_lock();
3431
3432 if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) {
3433 DSSERR("dssdev not suspended\n");
3434 r = -EINVAL;
3435 goto err0;
3436 }
3437
3438 enable_clocks(1);
3439 dsi_enable_pll_clock(1);
3440
3441 r = _dsi_reset();
3442 if (r)
3443 goto err1;
3444
3445 dsi_core_init();
3446
3447 r = dsi_display_init_dispc(dssdev);
3448 if (r)
3449 goto err1;
3450
3451 r = dsi_display_init_dsi(dssdev);
3452 if (r)
3453 goto err2;
3454
3455 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
3456
3457 r = dsi_set_te(dssdev, dsi.te_enabled);
3458 if (r)
3459 goto err2;
3460
3461 dsi_set_update_mode(dssdev, dsi.user_update_mode);
3462
3463 dsi_bus_unlock();
3464 mutex_unlock(&dsi.lock);
3465
3466 return 0;
3467
3468err2:
3469 dsi_display_uninit_dispc(dssdev);
3470err1:
3471 enable_clocks(0);
3472 dsi_enable_pll_clock(0);
3473err0:
3474 dsi_bus_unlock();
3475 mutex_unlock(&dsi.lock);
3476 DSSDBG("dsi_display_resume FAILED\n");
3477 return r;
3478}
3479
3480static int dsi_display_update(struct omap_dss_device *dssdev,
3481 u16 x, u16 y, u16 w, u16 h)
3482{
3483 int r = 0;
3484 u16 dw, dh;
3485
3486 DSSDBG("dsi_display_update(%d,%d %dx%d)\n", x, y, w, h);
3487
3488 mutex_lock(&dsi.lock);
3489
3490 if (dsi.update_mode != OMAP_DSS_UPDATE_MANUAL)
3491 goto end;
3492
3493 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
3494 goto end;
3495
3496 dssdev->get_resolution(dssdev, &dw, &dh);
3497
3498 if (x > dw || y > dh)
3499 goto end;
3500
3501 if (x + w > dw)
3502 w = dw - x;
3503
3504 if (y + h > dh)
3505 h = dh - y;
3506
3507 if (w == 0 || h == 0)
3508 goto end;
3509
3510 if (w == 1) {
3511 r = -EINVAL;
3512 goto end;
3513 }
3514
3515 dsi_set_update_region(dssdev, x, y, w, h);
3516
3517 wake_up(&dsi.waitqueue);
3518
3519end:
3520 mutex_unlock(&dsi.lock);
3521
3522 return r;
3523}
3524
3525static int dsi_display_sync(struct omap_dss_device *dssdev)
3526{
3527 bool wait;
3528
3529 DSSDBG("dsi_display_sync()\n");
3530
3531 mutex_lock(&dsi.lock);
3532 dsi_bus_lock();
3533
3534 if (dsi.update_mode == OMAP_DSS_UPDATE_MANUAL &&
3535 dsi.update_region.dirty) {
3536 INIT_COMPLETION(dsi.update_completion);
3537 wait = true;
3538 } else {
3539 wait = false;
3540 }
3541
3542 dsi_bus_unlock();
3543 mutex_unlock(&dsi.lock);
3544
3545 if (wait)
3546 wait_for_completion_interruptible(&dsi.update_completion);
3547
3548 DSSDBG("dsi_display_sync() done\n");
3549 return 0;
3550}
3551
3552static int dsi_display_set_update_mode(struct omap_dss_device *dssdev,
3553 enum omap_dss_update_mode mode)
3554{
3555 int r = 0;
3556
3557 DSSDBGF("%d", mode);
3558
3559 mutex_lock(&dsi.lock);
3560 dsi_bus_lock();
3561
3562 dsi.user_update_mode = mode;
3563 r = dsi_set_update_mode(dssdev, mode);
3564
3565 dsi_bus_unlock();
3566 mutex_unlock(&dsi.lock);
3567
3568 return r;
3569}
3570
3571static enum omap_dss_update_mode dsi_display_get_update_mode(
3572 struct omap_dss_device *dssdev)
3573{
3574 return dsi.update_mode;
3575}
3576
3577
3578static int dsi_display_enable_te(struct omap_dss_device *dssdev, bool enable)
3579{
3580 int r = 0;
3581
3582 DSSDBGF("%d", enable);
3583
3584 if (!dssdev->driver->enable_te)
3585 return -ENOENT;
3586
3587 dsi_bus_lock();
3588
3589 dsi.te_enabled = enable;
3590
3591 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
3592 goto end;
3593
3594 r = dsi_set_te(dssdev, enable);
3595end:
3596 dsi_bus_unlock();
3597
3598 return r;
3599}
3600
3601static int dsi_display_get_te(struct omap_dss_device *dssdev)
3602{
3603 return dsi.te_enabled;
3604}
3605
3606static int dsi_display_set_rotate(struct omap_dss_device *dssdev, u8 rotate)
3607{
3608
3609 DSSDBGF("%d", rotate);
3610
3611 if (!dssdev->driver->set_rotate || !dssdev->driver->get_rotate)
3612 return -EINVAL;
3613
3614 dsi_bus_lock();
3615 dssdev->driver->set_rotate(dssdev, rotate);
3616 if (dsi.update_mode == OMAP_DSS_UPDATE_AUTO) {
3617 u16 w, h;
3618 /* the display dimensions may have changed, so set a new
3619 * update region */
3620 dssdev->get_resolution(dssdev, &w, &h);
3621 dsi_set_update_region(dssdev, 0, 0, w, h);
3622 }
3623 dsi_bus_unlock();
3624
3625 return 0;
3626}
3627
3628static u8 dsi_display_get_rotate(struct omap_dss_device *dssdev)
3629{
3630 if (!dssdev->driver->set_rotate || !dssdev->driver->get_rotate)
3631 return 0;
3632
3633 return dssdev->driver->get_rotate(dssdev);
3634}
3635
3636static int dsi_display_set_mirror(struct omap_dss_device *dssdev, bool mirror)
3637{
3638 DSSDBGF("%d", mirror);
3639
3640 if (!dssdev->driver->set_mirror || !dssdev->driver->get_mirror)
3641 return -EINVAL;
3642
3643 dsi_bus_lock();
3644 dssdev->driver->set_mirror(dssdev, mirror);
3645 dsi_bus_unlock();
3646
3647 return 0;
3648}
3649
3650static bool dsi_display_get_mirror(struct omap_dss_device *dssdev)
3651{
3652 if (!dssdev->driver->set_mirror || !dssdev->driver->get_mirror)
3653 return 0;
3654
3655 return dssdev->driver->get_mirror(dssdev);
3656}
3657
3658static int dsi_display_run_test(struct omap_dss_device *dssdev, int test_num)
3659{
3660 int r;
3661
3662 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
3663 return -EIO;
3664
3665 DSSDBGF("%d", test_num);
3666
3667 dsi_bus_lock();
3668
3669 /* run test first in low speed mode */
Tomi Valkeinen61140c92010-01-12 16:00:30 +02003670 omapdss_dsi_vc_enable_hs(0, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003671
3672 if (dssdev->driver->run_test) {
3673 r = dssdev->driver->run_test(dssdev, test_num);
3674 if (r)
3675 goto end;
3676 }
3677
3678 /* then in high speed */
Tomi Valkeinen61140c92010-01-12 16:00:30 +02003679 omapdss_dsi_vc_enable_hs(0, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003680
3681 if (dssdev->driver->run_test) {
3682 r = dssdev->driver->run_test(dssdev, test_num);
3683 if (r)
3684 goto end;
3685 }
3686
3687end:
Tomi Valkeinen61140c92010-01-12 16:00:30 +02003688 omapdss_dsi_vc_enable_hs(0, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003689
3690 dsi_bus_unlock();
3691
3692 return r;
3693}
3694
3695static int dsi_display_memory_read(struct omap_dss_device *dssdev,
3696 void *buf, size_t size,
3697 u16 x, u16 y, u16 w, u16 h)
3698{
3699 int r;
3700
3701 DSSDBGF("");
3702
3703 if (!dssdev->driver->memory_read)
3704 return -EINVAL;
3705
3706 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
3707 return -EIO;
3708
3709 dsi_bus_lock();
3710
3711 r = dssdev->driver->memory_read(dssdev, buf, size,
3712 x, y, w, h);
3713
3714 /* Memory read usually changes the update area. This will
3715 * force the next update to re-set the update area */
3716 dsi.active_update_region.dirty = true;
3717
3718 dsi_bus_unlock();
3719
3720 return r;
3721}
3722
3723void dsi_get_overlay_fifo_thresholds(enum omap_plane plane,
3724 u32 fifo_size, enum omap_burst_size *burst_size,
3725 u32 *fifo_low, u32 *fifo_high)
3726{
3727 unsigned burst_size_bytes;
3728
3729 *burst_size = OMAP_DSS_BURST_16x32;
3730 burst_size_bytes = 16 * 32 / 8;
3731
3732 *fifo_high = fifo_size - burst_size_bytes;
3733 *fifo_low = fifo_size - burst_size_bytes * 8;
3734}
3735
3736int dsi_init_display(struct omap_dss_device *dssdev)
3737{
3738 DSSDBG("DSI init\n");
3739
3740 dssdev->enable = dsi_display_enable;
3741 dssdev->disable = dsi_display_disable;
3742 dssdev->suspend = dsi_display_suspend;
3743 dssdev->resume = dsi_display_resume;
3744 dssdev->update = dsi_display_update;
3745 dssdev->sync = dsi_display_sync;
3746 dssdev->set_update_mode = dsi_display_set_update_mode;
3747 dssdev->get_update_mode = dsi_display_get_update_mode;
3748 dssdev->enable_te = dsi_display_enable_te;
3749 dssdev->get_te = dsi_display_get_te;
3750
3751 dssdev->get_rotate = dsi_display_get_rotate;
3752 dssdev->set_rotate = dsi_display_set_rotate;
3753
3754 dssdev->get_mirror = dsi_display_get_mirror;
3755 dssdev->set_mirror = dsi_display_set_mirror;
3756
3757 dssdev->run_test = dsi_display_run_test;
3758 dssdev->memory_read = dsi_display_memory_read;
3759
3760 /* XXX these should be figured out dynamically */
3761 dssdev->caps = OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE |
3762 OMAP_DSS_DISPLAY_CAP_TEAR_ELIM;
3763
3764 dsi.vc[0].dssdev = dssdev;
3765 dsi.vc[1].dssdev = dssdev;
3766
3767 return 0;
3768}
3769
3770int dsi_init(struct platform_device *pdev)
3771{
3772 u32 rev;
3773 int r;
3774 struct sched_param param = {
3775 .sched_priority = MAX_USER_RT_PRIO-1
3776 };
3777
3778 spin_lock_init(&dsi.errors_lock);
3779 dsi.errors = 0;
3780
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02003781#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
3782 spin_lock_init(&dsi.irq_stats_lock);
3783 dsi.irq_stats.last_reset = jiffies;
3784#endif
3785
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003786 init_completion(&dsi.bta_completion);
3787 init_completion(&dsi.update_completion);
3788
3789 dsi.thread = kthread_create(dsi_update_thread, NULL, "dsi");
3790 if (IS_ERR(dsi.thread)) {
3791 DSSERR("cannot create kthread\n");
3792 r = PTR_ERR(dsi.thread);
3793 goto err0;
3794 }
3795 sched_setscheduler(dsi.thread, SCHED_FIFO, &param);
3796
3797 init_waitqueue_head(&dsi.waitqueue);
3798 spin_lock_init(&dsi.update_lock);
3799
3800 mutex_init(&dsi.lock);
3801 mutex_init(&dsi.bus_lock);
3802
3803#ifdef DSI_CATCH_MISSING_TE
3804 init_timer(&dsi.te_timer);
3805 dsi.te_timer.function = dsi_te_timeout;
3806 dsi.te_timer.data = 0;
3807#endif
3808
3809 dsi.update_mode = OMAP_DSS_UPDATE_DISABLED;
3810 dsi.user_update_mode = OMAP_DSS_UPDATE_DISABLED;
3811
3812 dsi.base = ioremap(DSI_BASE, DSI_SZ_REGS);
3813 if (!dsi.base) {
3814 DSSERR("can't ioremap DSI\n");
3815 r = -ENOMEM;
3816 goto err1;
3817 }
3818
Tomi Valkeinen8a2cfea2010-02-04 17:03:41 +02003819 dsi.vdds_dsi_reg = dss_get_vdds_dsi();
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003820 if (IS_ERR(dsi.vdds_dsi_reg)) {
3821 iounmap(dsi.base);
3822 DSSERR("can't get VDDS_DSI regulator\n");
3823 r = PTR_ERR(dsi.vdds_dsi_reg);
3824 goto err2;
3825 }
3826
3827 enable_clocks(1);
3828
3829 rev = dsi_read_reg(DSI_REVISION);
3830 printk(KERN_INFO "OMAP DSI rev %d.%d\n",
3831 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
3832
3833 enable_clocks(0);
3834
3835 wake_up_process(dsi.thread);
3836
3837 return 0;
3838err2:
3839 iounmap(dsi.base);
3840err1:
3841 kthread_stop(dsi.thread);
3842err0:
3843 return r;
3844}
3845
3846void dsi_exit(void)
3847{
3848 kthread_stop(dsi.thread);
3849
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003850 iounmap(dsi.base);
3851
3852 DSSDBG("omap_dsi_exit\n");
3853}
3854