2 * linux/drivers/video/omap2/dss/dsi.c
4 * Copyright (C) 2009 Nokia Corporation
5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
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.
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
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/>.
20 #define DSS_SUBSYS_NAME "DSI"
22 #include <linux/kernel.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/semaphore.h>
31 #include <linux/seq_file.h>
32 #include <linux/platform_device.h>
33 #include <linux/regulator/consumer.h>
34 #include <linux/kthread.h>
35 #include <linux/wait.h>
37 #include <plat/display.h>
38 #include <plat/clock.h>
42 /*#define VERBOSE_IRQ*/
43 #define DSI_CATCH_MISSING_TE
45 #define DSI_BASE 0x4804FC00
47 struct dsi_reg
{ u16 idx
; };
49 #define DSI_REG(idx) ((const struct dsi_reg) { idx })
51 #define DSI_SZ_REGS SZ_1K
52 /* DSI Protocol Engine */
54 #define DSI_REVISION DSI_REG(0x0000)
55 #define DSI_SYSCONFIG DSI_REG(0x0010)
56 #define DSI_SYSSTATUS DSI_REG(0x0014)
57 #define DSI_IRQSTATUS DSI_REG(0x0018)
58 #define DSI_IRQENABLE DSI_REG(0x001C)
59 #define DSI_CTRL DSI_REG(0x0040)
60 #define DSI_COMPLEXIO_CFG1 DSI_REG(0x0048)
61 #define DSI_COMPLEXIO_IRQ_STATUS DSI_REG(0x004C)
62 #define DSI_COMPLEXIO_IRQ_ENABLE DSI_REG(0x0050)
63 #define DSI_CLK_CTRL DSI_REG(0x0054)
64 #define DSI_TIMING1 DSI_REG(0x0058)
65 #define DSI_TIMING2 DSI_REG(0x005C)
66 #define DSI_VM_TIMING1 DSI_REG(0x0060)
67 #define DSI_VM_TIMING2 DSI_REG(0x0064)
68 #define DSI_VM_TIMING3 DSI_REG(0x0068)
69 #define DSI_CLK_TIMING DSI_REG(0x006C)
70 #define DSI_TX_FIFO_VC_SIZE DSI_REG(0x0070)
71 #define DSI_RX_FIFO_VC_SIZE DSI_REG(0x0074)
72 #define DSI_COMPLEXIO_CFG2 DSI_REG(0x0078)
73 #define DSI_RX_FIFO_VC_FULLNESS DSI_REG(0x007C)
74 #define DSI_VM_TIMING4 DSI_REG(0x0080)
75 #define DSI_TX_FIFO_VC_EMPTINESS DSI_REG(0x0084)
76 #define DSI_VM_TIMING5 DSI_REG(0x0088)
77 #define DSI_VM_TIMING6 DSI_REG(0x008C)
78 #define DSI_VM_TIMING7 DSI_REG(0x0090)
79 #define DSI_STOPCLK_TIMING DSI_REG(0x0094)
80 #define DSI_VC_CTRL(n) DSI_REG(0x0100 + (n * 0x20))
81 #define DSI_VC_TE(n) DSI_REG(0x0104 + (n * 0x20))
82 #define DSI_VC_LONG_PACKET_HEADER(n) DSI_REG(0x0108 + (n * 0x20))
83 #define DSI_VC_LONG_PACKET_PAYLOAD(n) DSI_REG(0x010C + (n * 0x20))
84 #define DSI_VC_SHORT_PACKET_HEADER(n) DSI_REG(0x0110 + (n * 0x20))
85 #define DSI_VC_IRQSTATUS(n) DSI_REG(0x0118 + (n * 0x20))
86 #define DSI_VC_IRQENABLE(n) DSI_REG(0x011C + (n * 0x20))
90 #define DSI_DSIPHY_CFG0 DSI_REG(0x200 + 0x0000)
91 #define DSI_DSIPHY_CFG1 DSI_REG(0x200 + 0x0004)
92 #define DSI_DSIPHY_CFG2 DSI_REG(0x200 + 0x0008)
93 #define DSI_DSIPHY_CFG5 DSI_REG(0x200 + 0x0014)
95 /* DSI_PLL_CTRL_SCP */
97 #define DSI_PLL_CONTROL DSI_REG(0x300 + 0x0000)
98 #define DSI_PLL_STATUS DSI_REG(0x300 + 0x0004)
99 #define DSI_PLL_GO DSI_REG(0x300 + 0x0008)
100 #define DSI_PLL_CONFIGURATION1 DSI_REG(0x300 + 0x000C)
101 #define DSI_PLL_CONFIGURATION2 DSI_REG(0x300 + 0x0010)
103 #define REG_GET(idx, start, end) \
104 FLD_GET(dsi_read_reg(idx), start, end)
106 #define REG_FLD_MOD(idx, val, start, end) \
107 dsi_write_reg(idx, FLD_MOD(dsi_read_reg(idx), val, start, end))
109 /* Global interrupts */
110 #define DSI_IRQ_VC0 (1 << 0)
111 #define DSI_IRQ_VC1 (1 << 1)
112 #define DSI_IRQ_VC2 (1 << 2)
113 #define DSI_IRQ_VC3 (1 << 3)
114 #define DSI_IRQ_WAKEUP (1 << 4)
115 #define DSI_IRQ_RESYNC (1 << 5)
116 #define DSI_IRQ_PLL_LOCK (1 << 7)
117 #define DSI_IRQ_PLL_UNLOCK (1 << 8)
118 #define DSI_IRQ_PLL_RECALL (1 << 9)
119 #define DSI_IRQ_COMPLEXIO_ERR (1 << 10)
120 #define DSI_IRQ_HS_TX_TIMEOUT (1 << 14)
121 #define DSI_IRQ_LP_RX_TIMEOUT (1 << 15)
122 #define DSI_IRQ_TE_TRIGGER (1 << 16)
123 #define DSI_IRQ_ACK_TRIGGER (1 << 17)
124 #define DSI_IRQ_SYNC_LOST (1 << 18)
125 #define DSI_IRQ_LDO_POWER_GOOD (1 << 19)
126 #define DSI_IRQ_TA_TIMEOUT (1 << 20)
127 #define DSI_IRQ_ERROR_MASK \
128 (DSI_IRQ_HS_TX_TIMEOUT | DSI_IRQ_LP_RX_TIMEOUT | DSI_IRQ_SYNC_LOST | \
130 #define DSI_IRQ_CHANNEL_MASK 0xf
132 /* Virtual channel interrupts */
133 #define DSI_VC_IRQ_CS (1 << 0)
134 #define DSI_VC_IRQ_ECC_CORR (1 << 1)
135 #define DSI_VC_IRQ_PACKET_SENT (1 << 2)
136 #define DSI_VC_IRQ_FIFO_TX_OVF (1 << 3)
137 #define DSI_VC_IRQ_FIFO_RX_OVF (1 << 4)
138 #define DSI_VC_IRQ_BTA (1 << 5)
139 #define DSI_VC_IRQ_ECC_NO_CORR (1 << 6)
140 #define DSI_VC_IRQ_FIFO_TX_UDF (1 << 7)
141 #define DSI_VC_IRQ_PP_BUSY_CHANGE (1 << 8)
142 #define DSI_VC_IRQ_ERROR_MASK \
143 (DSI_VC_IRQ_CS | DSI_VC_IRQ_ECC_CORR | DSI_VC_IRQ_FIFO_TX_OVF | \
144 DSI_VC_IRQ_FIFO_RX_OVF | DSI_VC_IRQ_ECC_NO_CORR | \
145 DSI_VC_IRQ_FIFO_TX_UDF)
147 /* ComplexIO interrupts */
148 #define DSI_CIO_IRQ_ERRSYNCESC1 (1 << 0)
149 #define DSI_CIO_IRQ_ERRSYNCESC2 (1 << 1)
150 #define DSI_CIO_IRQ_ERRSYNCESC3 (1 << 2)
151 #define DSI_CIO_IRQ_ERRESC1 (1 << 5)
152 #define DSI_CIO_IRQ_ERRESC2 (1 << 6)
153 #define DSI_CIO_IRQ_ERRESC3 (1 << 7)
154 #define DSI_CIO_IRQ_ERRCONTROL1 (1 << 10)
155 #define DSI_CIO_IRQ_ERRCONTROL2 (1 << 11)
156 #define DSI_CIO_IRQ_ERRCONTROL3 (1 << 12)
157 #define DSI_CIO_IRQ_STATEULPS1 (1 << 15)
158 #define DSI_CIO_IRQ_STATEULPS2 (1 << 16)
159 #define DSI_CIO_IRQ_STATEULPS3 (1 << 17)
160 #define DSI_CIO_IRQ_ERRCONTENTIONLP0_1 (1 << 20)
161 #define DSI_CIO_IRQ_ERRCONTENTIONLP1_1 (1 << 21)
162 #define DSI_CIO_IRQ_ERRCONTENTIONLP0_2 (1 << 22)
163 #define DSI_CIO_IRQ_ERRCONTENTIONLP1_2 (1 << 23)
164 #define DSI_CIO_IRQ_ERRCONTENTIONLP0_3 (1 << 24)
165 #define DSI_CIO_IRQ_ERRCONTENTIONLP1_3 (1 << 25)
166 #define DSI_CIO_IRQ_ULPSACTIVENOT_ALL0 (1 << 30)
167 #define DSI_CIO_IRQ_ULPSACTIVENOT_ALL1 (1 << 31)
169 #define DSI_DT_DCS_SHORT_WRITE_0 0x05
170 #define DSI_DT_DCS_SHORT_WRITE_1 0x15
171 #define DSI_DT_DCS_READ 0x06
172 #define DSI_DT_SET_MAX_RET_PKG_SIZE 0x37
173 #define DSI_DT_NULL_PACKET 0x09
174 #define DSI_DT_DCS_LONG_WRITE 0x39
176 #define DSI_DT_RX_ACK_WITH_ERR 0x02
177 #define DSI_DT_RX_DCS_LONG_READ 0x1c
178 #define DSI_DT_RX_SHORT_READ_1 0x21
179 #define DSI_DT_RX_SHORT_READ_2 0x22
181 #define FINT_MAX 2100000
182 #define FINT_MIN 750000
183 #define REGN_MAX (1 << 7)
184 #define REGM_MAX ((1 << 11) - 1)
185 #define REGM3_MAX (1 << 4)
186 #define REGM4_MAX (1 << 4)
187 #define LP_DIV_MAX ((1 << 13) - 1)
191 DSI_FIFO_SIZE_32
= 1,
192 DSI_FIFO_SIZE_64
= 2,
193 DSI_FIFO_SIZE_96
= 3,
194 DSI_FIFO_SIZE_128
= 4,
202 struct dsi_update_region
{
205 struct omap_dss_device
*device
;
208 struct dsi_irq_stats
{
209 unsigned long last_reset
;
211 unsigned dsi_irqs
[32];
212 unsigned vc_irqs
[4][32];
213 unsigned cio_irqs
[32];
220 struct dsi_clock_info current_cinfo
;
222 struct regulator
*vdds_dsi_reg
;
225 enum dsi_vc_mode mode
;
226 struct omap_dss_device
*dssdev
;
227 enum fifo_size fifo_size
;
231 struct semaphore bus_lock
;
235 struct completion bta_completion
;
237 struct task_struct
*thread
;
238 wait_queue_head_t waitqueue
;
240 spinlock_t update_lock
;
241 bool framedone_received
;
242 struct dsi_update_region update_region
;
243 struct dsi_update_region active_update_region
;
244 struct completion update_completion
;
246 enum omap_dss_update_mode user_update_mode
;
247 enum omap_dss_update_mode update_mode
;
251 #ifdef DSI_CATCH_MISSING_TE
252 struct timer_list te_timer
;
255 unsigned long cache_req_pck
;
256 unsigned long cache_clk_freq
;
257 struct dsi_clock_info cache_cinfo
;
260 spinlock_t errors_lock
;
262 ktime_t perf_setup_time
;
263 ktime_t perf_start_time
;
268 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
269 spinlock_t irq_stats_lock
;
270 struct dsi_irq_stats irq_stats
;
275 static unsigned int dsi_perf
;
276 module_param_named(dsi_perf
, dsi_perf
, bool, 0644);
279 static inline void dsi_write_reg(const struct dsi_reg idx
, u32 val
)
281 __raw_writel(val
, dsi
.base
+ idx
.idx
);
284 static inline u32
dsi_read_reg(const struct dsi_reg idx
)
286 return __raw_readl(dsi
.base
+ idx
.idx
);
290 void dsi_save_context(void)
294 void dsi_restore_context(void)
298 void dsi_bus_lock(void)
302 EXPORT_SYMBOL(dsi_bus_lock
);
304 void dsi_bus_unlock(void)
308 EXPORT_SYMBOL(dsi_bus_unlock
);
310 static bool dsi_bus_is_locked(void)
312 return dsi
.bus_lock
.count
== 0;
315 static inline int wait_for_bit_change(const struct dsi_reg idx
, int bitnum
,
320 while (REG_GET(idx
, bitnum
, bitnum
) != value
) {
329 static void dsi_perf_mark_setup(void)
331 dsi
.perf_setup_time
= ktime_get();
334 static void dsi_perf_mark_start(void)
336 dsi
.perf_start_time
= ktime_get();
339 static void dsi_perf_show(const char *name
)
341 ktime_t t
, setup_time
, trans_time
;
343 u32 setup_us
, trans_us
, total_us
;
348 if (dsi
.update_mode
== OMAP_DSS_UPDATE_DISABLED
)
353 setup_time
= ktime_sub(dsi
.perf_start_time
, dsi
.perf_setup_time
);
354 setup_us
= (u32
)ktime_to_us(setup_time
);
358 trans_time
= ktime_sub(t
, dsi
.perf_start_time
);
359 trans_us
= (u32
)ktime_to_us(trans_time
);
363 total_us
= setup_us
+ trans_us
;
365 total_bytes
= dsi
.active_update_region
.w
*
366 dsi
.active_update_region
.h
*
367 dsi
.active_update_region
.device
->ctrl
.pixel_size
/ 8;
369 printk(KERN_INFO
"DSI(%s): %u us + %u us = %u us (%uHz), "
370 "%u bytes, %u kbytes/sec\n",
375 1000*1000 / total_us
,
377 total_bytes
* 1000 / total_us
);
380 #define dsi_perf_mark_setup()
381 #define dsi_perf_mark_start()
382 #define dsi_perf_show(x)
385 static void print_irq_status(u32 status
)
388 if ((status
& ~DSI_IRQ_CHANNEL_MASK
) == 0)
391 printk(KERN_DEBUG
"DSI IRQ: 0x%x: ", status
);
394 if (status & DSI_IRQ_##x) \
420 static void print_irq_status_vc(int channel
, u32 status
)
423 if ((status
& ~DSI_VC_IRQ_PACKET_SENT
) == 0)
426 printk(KERN_DEBUG
"DSI VC(%d) IRQ 0x%x: ", channel
, status
);
429 if (status & DSI_VC_IRQ_##x) \
446 static void print_irq_status_cio(u32 status
)
448 printk(KERN_DEBUG
"DSI CIO IRQ 0x%x: ", status
);
451 if (status & DSI_CIO_IRQ_##x) \
465 PIS(ERRCONTENTIONLP0_1
);
466 PIS(ERRCONTENTIONLP1_1
);
467 PIS(ERRCONTENTIONLP0_2
);
468 PIS(ERRCONTENTIONLP1_2
);
469 PIS(ERRCONTENTIONLP0_3
);
470 PIS(ERRCONTENTIONLP1_3
);
471 PIS(ULPSACTIVENOT_ALL0
);
472 PIS(ULPSACTIVENOT_ALL1
);
478 static int debug_irq
;
480 /* called from dss */
481 void dsi_irq_handler(void)
483 u32 irqstatus
, vcstatus
, ciostatus
;
486 irqstatus
= dsi_read_reg(DSI_IRQSTATUS
);
488 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
489 spin_lock(&dsi
.irq_stats_lock
);
490 dsi
.irq_stats
.irq_count
++;
491 dss_collect_irq_stats(irqstatus
, dsi
.irq_stats
.dsi_irqs
);
494 if (irqstatus
& DSI_IRQ_ERROR_MASK
) {
495 DSSERR("DSI error, irqstatus %x\n", irqstatus
);
496 print_irq_status(irqstatus
);
497 spin_lock(&dsi
.errors_lock
);
498 dsi
.errors
|= irqstatus
& DSI_IRQ_ERROR_MASK
;
499 spin_unlock(&dsi
.errors_lock
);
500 } else if (debug_irq
) {
501 print_irq_status(irqstatus
);
504 #ifdef DSI_CATCH_MISSING_TE
505 if (irqstatus
& DSI_IRQ_TE_TRIGGER
)
506 del_timer(&dsi
.te_timer
);
509 for (i
= 0; i
< 4; ++i
) {
510 if ((irqstatus
& (1<<i
)) == 0)
513 vcstatus
= dsi_read_reg(DSI_VC_IRQSTATUS(i
));
515 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
516 dss_collect_irq_stats(vcstatus
, dsi
.irq_stats
.vc_irqs
[i
]);
519 if (vcstatus
& DSI_VC_IRQ_BTA
)
520 complete(&dsi
.bta_completion
);
522 if (vcstatus
& DSI_VC_IRQ_ERROR_MASK
) {
523 DSSERR("DSI VC(%d) error, vc irqstatus %x\n",
525 print_irq_status_vc(i
, vcstatus
);
526 } else if (debug_irq
) {
527 print_irq_status_vc(i
, vcstatus
);
530 dsi_write_reg(DSI_VC_IRQSTATUS(i
), vcstatus
);
531 /* flush posted write */
532 dsi_read_reg(DSI_VC_IRQSTATUS(i
));
535 if (irqstatus
& DSI_IRQ_COMPLEXIO_ERR
) {
536 ciostatus
= dsi_read_reg(DSI_COMPLEXIO_IRQ_STATUS
);
538 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
539 dss_collect_irq_stats(ciostatus
, dsi
.irq_stats
.cio_irqs
);
542 dsi_write_reg(DSI_COMPLEXIO_IRQ_STATUS
, ciostatus
);
543 /* flush posted write */
544 dsi_read_reg(DSI_COMPLEXIO_IRQ_STATUS
);
546 DSSERR("DSI CIO error, cio irqstatus %x\n", ciostatus
);
547 print_irq_status_cio(ciostatus
);
550 dsi_write_reg(DSI_IRQSTATUS
, irqstatus
& ~DSI_IRQ_CHANNEL_MASK
);
551 /* flush posted write */
552 dsi_read_reg(DSI_IRQSTATUS
);
554 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
555 spin_unlock(&dsi
.irq_stats_lock
);
560 static void _dsi_initialize_irq(void)
565 /* disable all interrupts */
566 dsi_write_reg(DSI_IRQENABLE
, 0);
567 for (i
= 0; i
< 4; ++i
)
568 dsi_write_reg(DSI_VC_IRQENABLE(i
), 0);
569 dsi_write_reg(DSI_COMPLEXIO_IRQ_ENABLE
, 0);
571 /* clear interrupt status */
572 l
= dsi_read_reg(DSI_IRQSTATUS
);
573 dsi_write_reg(DSI_IRQSTATUS
, l
& ~DSI_IRQ_CHANNEL_MASK
);
575 for (i
= 0; i
< 4; ++i
) {
576 l
= dsi_read_reg(DSI_VC_IRQSTATUS(i
));
577 dsi_write_reg(DSI_VC_IRQSTATUS(i
), l
);
580 l
= dsi_read_reg(DSI_COMPLEXIO_IRQ_STATUS
);
581 dsi_write_reg(DSI_COMPLEXIO_IRQ_STATUS
, l
);
583 /* enable error irqs */
584 l
= DSI_IRQ_ERROR_MASK
;
585 #ifdef DSI_CATCH_MISSING_TE
586 l
|= DSI_IRQ_TE_TRIGGER
;
588 dsi_write_reg(DSI_IRQENABLE
, l
);
590 l
= DSI_VC_IRQ_ERROR_MASK
;
591 for (i
= 0; i
< 4; ++i
)
592 dsi_write_reg(DSI_VC_IRQENABLE(i
), l
);
594 /* XXX zonda responds incorrectly, causing control error:
595 Exit from LP-ESC mode to LP11 uses wrong transition states on the
596 data lines LP0 and LN0. */
597 dsi_write_reg(DSI_COMPLEXIO_IRQ_ENABLE
,
598 -1 & (~DSI_CIO_IRQ_ERRCONTROL2
));
601 static u32
dsi_get_errors(void)
605 spin_lock_irqsave(&dsi
.errors_lock
, flags
);
608 spin_unlock_irqrestore(&dsi
.errors_lock
, flags
);
612 static void dsi_vc_enable_bta_irq(int channel
)
616 dsi_write_reg(DSI_VC_IRQSTATUS(channel
), DSI_VC_IRQ_BTA
);
618 l
= dsi_read_reg(DSI_VC_IRQENABLE(channel
));
620 dsi_write_reg(DSI_VC_IRQENABLE(channel
), l
);
623 static void dsi_vc_disable_bta_irq(int channel
)
627 l
= dsi_read_reg(DSI_VC_IRQENABLE(channel
));
628 l
&= ~DSI_VC_IRQ_BTA
;
629 dsi_write_reg(DSI_VC_IRQENABLE(channel
), l
);
632 /* DSI func clock. this could also be DSI2_PLL_FCLK */
633 static inline void enable_clocks(bool enable
)
636 dss_clk_enable(DSS_CLK_ICK
| DSS_CLK_FCK1
);
638 dss_clk_disable(DSS_CLK_ICK
| DSS_CLK_FCK1
);
641 /* source clock for DSI PLL. this could also be PCLKFREE */
642 static inline void dsi_enable_pll_clock(bool enable
)
645 dss_clk_enable(DSS_CLK_FCK2
);
647 dss_clk_disable(DSS_CLK_FCK2
);
649 if (enable
&& dsi
.pll_locked
) {
650 if (wait_for_bit_change(DSI_PLL_STATUS
, 1, 1) != 1)
651 DSSERR("cannot lock PLL when enabling clocks\n");
656 static void _dsi_print_reset_status(void)
663 /* A dummy read using the SCP interface to any DSIPHY register is
664 * required after DSIPHY reset to complete the reset of the DSI complex
666 l
= dsi_read_reg(DSI_DSIPHY_CFG5
);
668 printk(KERN_DEBUG
"DSI resets: ");
670 l
= dsi_read_reg(DSI_PLL_STATUS
);
671 printk("PLL (%d) ", FLD_GET(l
, 0, 0));
673 l
= dsi_read_reg(DSI_COMPLEXIO_CFG1
);
674 printk("CIO (%d) ", FLD_GET(l
, 29, 29));
676 l
= dsi_read_reg(DSI_DSIPHY_CFG5
);
677 printk("PHY (%x, %d, %d, %d)\n",
684 #define _dsi_print_reset_status()
687 static inline int dsi_if_enable(bool enable
)
689 DSSDBG("dsi_if_enable(%d)\n", enable
);
691 enable
= enable
? 1 : 0;
692 REG_FLD_MOD(DSI_CTRL
, enable
, 0, 0); /* IF_EN */
694 if (wait_for_bit_change(DSI_CTRL
, 0, enable
) != enable
) {
695 DSSERR("Failed to set dsi_if_enable to %d\n", enable
);
702 unsigned long dsi_get_dsi1_pll_rate(void)
704 return dsi
.current_cinfo
.dsi1_pll_fclk
;
707 static unsigned long dsi_get_dsi2_pll_rate(void)
709 return dsi
.current_cinfo
.dsi2_pll_fclk
;
712 static unsigned long dsi_get_txbyteclkhs(void)
714 return dsi
.current_cinfo
.clkin4ddr
/ 16;
717 static unsigned long dsi_fclk_rate(void)
721 if (dss_get_dsi_clk_source() == DSS_SRC_DSS1_ALWON_FCLK
) {
722 /* DSI FCLK source is DSS1_ALWON_FCK, which is dss1_fck */
723 r
= dss_clk_get_rate(DSS_CLK_FCK1
);
725 /* DSI FCLK source is DSI2_PLL_FCLK */
726 r
= dsi_get_dsi2_pll_rate();
732 static int dsi_set_lp_clk_divisor(struct omap_dss_device
*dssdev
)
734 unsigned long dsi_fclk
;
736 unsigned long lp_clk
;
738 lp_clk_div
= dssdev
->phy
.dsi
.div
.lp_clk_div
;
740 if (lp_clk_div
== 0 || lp_clk_div
> LP_DIV_MAX
)
743 dsi_fclk
= dsi_fclk_rate();
745 lp_clk
= dsi_fclk
/ 2 / lp_clk_div
;
747 DSSDBG("LP_CLK_DIV %u, LP_CLK %lu\n", lp_clk_div
, lp_clk
);
748 dsi
.current_cinfo
.lp_clk
= lp_clk
;
749 dsi
.current_cinfo
.lp_clk_div
= lp_clk_div
;
751 REG_FLD_MOD(DSI_CLK_CTRL
, lp_clk_div
, 12, 0); /* LP_CLK_DIVISOR */
753 REG_FLD_MOD(DSI_CLK_CTRL
, dsi_fclk
> 30000000 ? 1 : 0,
754 21, 21); /* LP_RX_SYNCHRO_ENABLE */
760 enum dsi_pll_power_state
{
761 DSI_PLL_POWER_OFF
= 0x0,
762 DSI_PLL_POWER_ON_HSCLK
= 0x1,
763 DSI_PLL_POWER_ON_ALL
= 0x2,
764 DSI_PLL_POWER_ON_DIV
= 0x3,
767 static int dsi_pll_power(enum dsi_pll_power_state state
)
771 REG_FLD_MOD(DSI_CLK_CTRL
, state
, 31, 30); /* PLL_PWR_CMD */
774 while (FLD_GET(dsi_read_reg(DSI_CLK_CTRL
), 29, 28) != state
) {
776 DSSERR("Failed to set DSI PLL power mode to %d\n",
786 /* calculate clock rates using dividers in cinfo */
787 static int dsi_calc_clock_rates(struct dsi_clock_info
*cinfo
)
789 if (cinfo
->regn
== 0 || cinfo
->regn
> REGN_MAX
)
792 if (cinfo
->regm
== 0 || cinfo
->regm
> REGM_MAX
)
795 if (cinfo
->regm3
> REGM3_MAX
)
798 if (cinfo
->regm4
> REGM4_MAX
)
801 if (cinfo
->use_dss2_fck
) {
802 cinfo
->clkin
= dss_clk_get_rate(DSS_CLK_FCK2
);
803 /* XXX it is unclear if highfreq should be used
804 * with DSS2_FCK source also */
807 cinfo
->clkin
= dispc_pclk_rate();
809 if (cinfo
->clkin
< 32000000)
815 cinfo
->fint
= cinfo
->clkin
/ (cinfo
->regn
* (cinfo
->highfreq
? 2 : 1));
817 if (cinfo
->fint
> FINT_MAX
|| cinfo
->fint
< FINT_MIN
)
820 cinfo
->clkin4ddr
= 2 * cinfo
->regm
* cinfo
->fint
;
822 if (cinfo
->clkin4ddr
> 1800 * 1000 * 1000)
825 if (cinfo
->regm3
> 0)
826 cinfo
->dsi1_pll_fclk
= cinfo
->clkin4ddr
/ cinfo
->regm3
;
828 cinfo
->dsi1_pll_fclk
= 0;
830 if (cinfo
->regm4
> 0)
831 cinfo
->dsi2_pll_fclk
= cinfo
->clkin4ddr
/ cinfo
->regm4
;
833 cinfo
->dsi2_pll_fclk
= 0;
838 int dsi_pll_calc_clock_div_pck(bool is_tft
, unsigned long req_pck
,
839 struct dsi_clock_info
*dsi_cinfo
,
840 struct dispc_clock_info
*dispc_cinfo
)
842 struct dsi_clock_info cur
, best
;
843 struct dispc_clock_info best_dispc
;
846 unsigned long dss_clk_fck2
;
848 dss_clk_fck2
= dss_clk_get_rate(DSS_CLK_FCK2
);
850 if (req_pck
== dsi
.cache_req_pck
&&
851 dsi
.cache_cinfo
.clkin
== dss_clk_fck2
) {
852 DSSDBG("DSI clock info found from cache\n");
853 *dsi_cinfo
= dsi
.cache_cinfo
;
854 dispc_find_clk_divs(is_tft
, req_pck
, dsi_cinfo
->dsi1_pll_fclk
,
859 min_fck_per_pck
= CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK
;
861 if (min_fck_per_pck
&&
862 req_pck
* min_fck_per_pck
> DISPC_MAX_FCK
) {
863 DSSERR("Requested pixel clock not possible with the current "
864 "OMAP2_DSS_MIN_FCK_PER_PCK setting. Turning "
865 "the constraint off.\n");
869 DSSDBG("dsi_pll_calc\n");
872 memset(&best
, 0, sizeof(best
));
873 memset(&best_dispc
, 0, sizeof(best_dispc
));
875 memset(&cur
, 0, sizeof(cur
));
876 cur
.clkin
= dss_clk_fck2
;
877 cur
.use_dss2_fck
= 1;
880 /* no highfreq: 0.75MHz < Fint = clkin / regn < 2.1MHz */
881 /* highfreq: 0.75MHz < Fint = clkin / (2*regn) < 2.1MHz */
882 /* To reduce PLL lock time, keep Fint high (around 2 MHz) */
883 for (cur
.regn
= 1; cur
.regn
< REGN_MAX
; ++cur
.regn
) {
884 if (cur
.highfreq
== 0)
885 cur
.fint
= cur
.clkin
/ cur
.regn
;
887 cur
.fint
= cur
.clkin
/ (2 * cur
.regn
);
889 if (cur
.fint
> FINT_MAX
|| cur
.fint
< FINT_MIN
)
892 /* DSIPHY(MHz) = (2 * regm / regn) * (clkin / (highfreq + 1)) */
893 for (cur
.regm
= 1; cur
.regm
< REGM_MAX
; ++cur
.regm
) {
896 a
= 2 * cur
.regm
* (cur
.clkin
/1000);
897 b
= cur
.regn
* (cur
.highfreq
+ 1);
898 cur
.clkin4ddr
= a
/ b
* 1000;
900 if (cur
.clkin4ddr
> 1800 * 1000 * 1000)
903 /* DSI1_PLL_FCLK(MHz) = DSIPHY(MHz) / regm3 < 173MHz */
904 for (cur
.regm3
= 1; cur
.regm3
< REGM3_MAX
;
906 struct dispc_clock_info cur_dispc
;
907 cur
.dsi1_pll_fclk
= cur
.clkin4ddr
/ cur
.regm3
;
909 /* this will narrow down the search a bit,
910 * but still give pixclocks below what was
912 if (cur
.dsi1_pll_fclk
< req_pck
)
915 if (cur
.dsi1_pll_fclk
> DISPC_MAX_FCK
)
918 if (min_fck_per_pck
&&
920 req_pck
* min_fck_per_pck
)
925 dispc_find_clk_divs(is_tft
, req_pck
,
929 if (abs(cur_dispc
.pck
- req_pck
) <
930 abs(best_dispc
.pck
- req_pck
)) {
932 best_dispc
= cur_dispc
;
934 if (cur_dispc
.pck
== req_pck
)
942 if (min_fck_per_pck
) {
943 DSSERR("Could not find suitable clock settings.\n"
944 "Turning FCK/PCK constraint off and"
950 DSSERR("Could not find suitable clock settings.\n");
955 /* DSI2_PLL_FCLK (regm4) is not used */
957 best
.dsi2_pll_fclk
= 0;
962 *dispc_cinfo
= best_dispc
;
964 dsi
.cache_req_pck
= req_pck
;
965 dsi
.cache_clk_freq
= 0;
966 dsi
.cache_cinfo
= best
;
971 int dsi_pll_set_clock_div(struct dsi_clock_info
*cinfo
)
979 dsi
.current_cinfo
.fint
= cinfo
->fint
;
980 dsi
.current_cinfo
.clkin4ddr
= cinfo
->clkin4ddr
;
981 dsi
.current_cinfo
.dsi1_pll_fclk
= cinfo
->dsi1_pll_fclk
;
982 dsi
.current_cinfo
.dsi2_pll_fclk
= cinfo
->dsi2_pll_fclk
;
984 dsi
.current_cinfo
.regn
= cinfo
->regn
;
985 dsi
.current_cinfo
.regm
= cinfo
->regm
;
986 dsi
.current_cinfo
.regm3
= cinfo
->regm3
;
987 dsi
.current_cinfo
.regm4
= cinfo
->regm4
;
989 DSSDBG("DSI Fint %ld\n", cinfo
->fint
);
991 DSSDBG("clkin (%s) rate %ld, highfreq %d\n",
992 cinfo
->use_dss2_fck
? "dss2_fck" : "pclkfree",
996 /* DSIPHY == CLKIN4DDR */
997 DSSDBG("CLKIN4DDR = 2 * %d / %d * %lu / %d = %lu\n",
1001 cinfo
->highfreq
+ 1,
1004 DSSDBG("Data rate on 1 DSI lane %ld Mbps\n",
1005 cinfo
->clkin4ddr
/ 1000 / 1000 / 2);
1007 DSSDBG("Clock lane freq %ld Hz\n", cinfo
->clkin4ddr
/ 4);
1009 DSSDBG("regm3 = %d, dsi1_pll_fclk = %lu\n",
1010 cinfo
->regm3
, cinfo
->dsi1_pll_fclk
);
1011 DSSDBG("regm4 = %d, dsi2_pll_fclk = %lu\n",
1012 cinfo
->regm4
, cinfo
->dsi2_pll_fclk
);
1014 REG_FLD_MOD(DSI_PLL_CONTROL
, 0, 0, 0); /* DSI_PLL_AUTOMODE = manual */
1016 l
= dsi_read_reg(DSI_PLL_CONFIGURATION1
);
1017 l
= FLD_MOD(l
, 1, 0, 0); /* DSI_PLL_STOPMODE */
1018 l
= FLD_MOD(l
, cinfo
->regn
- 1, 7, 1); /* DSI_PLL_REGN */
1019 l
= FLD_MOD(l
, cinfo
->regm
, 18, 8); /* DSI_PLL_REGM */
1020 l
= FLD_MOD(l
, cinfo
->regm3
> 0 ? cinfo
->regm3
- 1 : 0,
1021 22, 19); /* DSI_CLOCK_DIV */
1022 l
= FLD_MOD(l
, cinfo
->regm4
> 0 ? cinfo
->regm4
- 1 : 0,
1023 26, 23); /* DSIPROTO_CLOCK_DIV */
1024 dsi_write_reg(DSI_PLL_CONFIGURATION1
, l
);
1026 BUG_ON(cinfo
->fint
< 750000 || cinfo
->fint
> 2100000);
1027 if (cinfo
->fint
< 1000000)
1029 else if (cinfo
->fint
< 1250000)
1031 else if (cinfo
->fint
< 1500000)
1033 else if (cinfo
->fint
< 1750000)
1038 l
= dsi_read_reg(DSI_PLL_CONFIGURATION2
);
1039 l
= FLD_MOD(l
, f
, 4, 1); /* DSI_PLL_FREQSEL */
1040 l
= FLD_MOD(l
, cinfo
->use_dss2_fck
? 0 : 1,
1041 11, 11); /* DSI_PLL_CLKSEL */
1042 l
= FLD_MOD(l
, cinfo
->highfreq
,
1043 12, 12); /* DSI_PLL_HIGHFREQ */
1044 l
= FLD_MOD(l
, 1, 13, 13); /* DSI_PLL_REFEN */
1045 l
= FLD_MOD(l
, 0, 14, 14); /* DSIPHY_CLKINEN */
1046 l
= FLD_MOD(l
, 1, 20, 20); /* DSI_HSDIVBYPASS */
1047 dsi_write_reg(DSI_PLL_CONFIGURATION2
, l
);
1049 REG_FLD_MOD(DSI_PLL_GO
, 1, 0, 0); /* DSI_PLL_GO */
1051 if (wait_for_bit_change(DSI_PLL_GO
, 0, 0) != 0) {
1052 DSSERR("dsi pll go bit not going down.\n");
1057 if (wait_for_bit_change(DSI_PLL_STATUS
, 1, 1) != 1) {
1058 DSSERR("cannot lock PLL\n");
1065 l
= dsi_read_reg(DSI_PLL_CONFIGURATION2
);
1066 l
= FLD_MOD(l
, 0, 0, 0); /* DSI_PLL_IDLE */
1067 l
= FLD_MOD(l
, 0, 5, 5); /* DSI_PLL_PLLLPMODE */
1068 l
= FLD_MOD(l
, 0, 6, 6); /* DSI_PLL_LOWCURRSTBY */
1069 l
= FLD_MOD(l
, 0, 7, 7); /* DSI_PLL_TIGHTPHASELOCK */
1070 l
= FLD_MOD(l
, 0, 8, 8); /* DSI_PLL_DRIFTGUARDEN */
1071 l
= FLD_MOD(l
, 0, 10, 9); /* DSI_PLL_LOCKSEL */
1072 l
= FLD_MOD(l
, 1, 13, 13); /* DSI_PLL_REFEN */
1073 l
= FLD_MOD(l
, 1, 14, 14); /* DSIPHY_CLKINEN */
1074 l
= FLD_MOD(l
, 0, 15, 15); /* DSI_BYPASSEN */
1075 l
= FLD_MOD(l
, 1, 16, 16); /* DSS_CLOCK_EN */
1076 l
= FLD_MOD(l
, 0, 17, 17); /* DSS_CLOCK_PWDN */
1077 l
= FLD_MOD(l
, 1, 18, 18); /* DSI_PROTO_CLOCK_EN */
1078 l
= FLD_MOD(l
, 0, 19, 19); /* DSI_PROTO_CLOCK_PWDN */
1079 l
= FLD_MOD(l
, 0, 20, 20); /* DSI_HSDIVBYPASS */
1080 dsi_write_reg(DSI_PLL_CONFIGURATION2
, l
);
1082 DSSDBG("PLL config done\n");
1087 int dsi_pll_init(struct omap_dss_device
*dssdev
, bool enable_hsclk
,
1091 enum dsi_pll_power_state pwstate
;
1093 DSSDBG("PLL init\n");
1096 dsi_enable_pll_clock(1);
1098 r
= regulator_enable(dsi
.vdds_dsi_reg
);
1102 /* XXX PLL does not come out of reset without this... */
1103 dispc_pck_free_enable(1);
1105 if (wait_for_bit_change(DSI_PLL_STATUS
, 0, 1) != 1) {
1106 DSSERR("PLL not coming out of reset.\n");
1111 /* XXX ... but if left on, we get problems when planes do not
1112 * fill the whole display. No idea about this */
1113 dispc_pck_free_enable(0);
1115 if (enable_hsclk
&& enable_hsdiv
)
1116 pwstate
= DSI_PLL_POWER_ON_ALL
;
1117 else if (enable_hsclk
)
1118 pwstate
= DSI_PLL_POWER_ON_HSCLK
;
1119 else if (enable_hsdiv
)
1120 pwstate
= DSI_PLL_POWER_ON_DIV
;
1122 pwstate
= DSI_PLL_POWER_OFF
;
1124 r
= dsi_pll_power(pwstate
);
1129 DSSDBG("PLL init done\n");
1133 regulator_disable(dsi
.vdds_dsi_reg
);
1136 dsi_enable_pll_clock(0);
1140 void dsi_pll_uninit(void)
1143 dsi_enable_pll_clock(0);
1146 dsi_pll_power(DSI_PLL_POWER_OFF
);
1147 regulator_disable(dsi
.vdds_dsi_reg
);
1148 DSSDBG("PLL uninit done\n");
1151 void dsi_dump_clocks(struct seq_file
*s
)
1154 struct dsi_clock_info
*cinfo
= &dsi
.current_cinfo
;
1158 clksel
= REG_GET(DSI_PLL_CONFIGURATION2
, 11, 11);
1160 seq_printf(s
, "- DSI PLL -\n");
1162 seq_printf(s
, "dsi pll source = %s\n",
1164 "dss2_alwon_fclk" : "pclkfree");
1166 seq_printf(s
, "Fint\t\t%-16luregn %u\n", cinfo
->fint
, cinfo
->regn
);
1168 seq_printf(s
, "CLKIN4DDR\t%-16luregm %u\n",
1169 cinfo
->clkin4ddr
, cinfo
->regm
);
1171 seq_printf(s
, "dsi1_pll_fck\t%-16luregm3 %u\t(%s)\n",
1172 cinfo
->dsi1_pll_fclk
,
1174 dss_get_dispc_clk_source() == DSS_SRC_DSS1_ALWON_FCLK
?
1177 seq_printf(s
, "dsi2_pll_fck\t%-16luregm4 %u\t(%s)\n",
1178 cinfo
->dsi2_pll_fclk
,
1180 dss_get_dsi_clk_source() == DSS_SRC_DSS1_ALWON_FCLK
?
1183 seq_printf(s
, "- DSI -\n");
1185 seq_printf(s
, "dsi fclk source = %s\n",
1186 dss_get_dsi_clk_source() == DSS_SRC_DSS1_ALWON_FCLK
?
1187 "dss1_alwon_fclk" : "dsi2_pll_fclk");
1189 seq_printf(s
, "DSI_FCLK\t%lu\n", dsi_fclk_rate());
1191 seq_printf(s
, "DDR_CLK\t\t%lu\n",
1192 cinfo
->clkin4ddr
/ 4);
1194 seq_printf(s
, "TxByteClkHS\t%lu\n", dsi_get_txbyteclkhs());
1196 seq_printf(s
, "LP_CLK\t\t%lu\n", cinfo
->lp_clk
);
1198 seq_printf(s
, "VP_CLK\t\t%lu\n"
1206 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
1207 void dsi_dump_irqs(struct seq_file
*s
)
1209 unsigned long flags
;
1210 struct dsi_irq_stats stats
;
1212 spin_lock_irqsave(&dsi
.irq_stats_lock
, flags
);
1214 stats
= dsi
.irq_stats
;
1215 memset(&dsi
.irq_stats
, 0, sizeof(dsi
.irq_stats
));
1216 dsi
.irq_stats
.last_reset
= jiffies
;
1218 spin_unlock_irqrestore(&dsi
.irq_stats_lock
, flags
);
1220 seq_printf(s
, "period %u ms\n",
1221 jiffies_to_msecs(jiffies
- stats
.last_reset
));
1223 seq_printf(s
, "irqs %d\n", stats
.irq_count
);
1225 seq_printf(s, "%-20s %10d\n", #x, stats.dsi_irqs[ffs(DSI_IRQ_##x)-1]);
1227 seq_printf(s
, "-- DSI interrupts --\n");
1243 PIS(LDO_POWER_GOOD
);
1248 seq_printf(s, "%-20s %10d %10d %10d %10d\n", #x, \
1249 stats.vc_irqs[0][ffs(DSI_VC_IRQ_##x)-1], \
1250 stats.vc_irqs[1][ffs(DSI_VC_IRQ_##x)-1], \
1251 stats.vc_irqs[2][ffs(DSI_VC_IRQ_##x)-1], \
1252 stats.vc_irqs[3][ffs(DSI_VC_IRQ_##x)-1]);
1254 seq_printf(s
, "-- VC interrupts --\n");
1263 PIS(PP_BUSY_CHANGE
);
1267 seq_printf(s, "%-20s %10d\n", #x, \
1268 stats.cio_irqs[ffs(DSI_CIO_IRQ_##x)-1]);
1270 seq_printf(s
, "-- CIO interrupts --\n");
1283 PIS(ERRCONTENTIONLP0_1
);
1284 PIS(ERRCONTENTIONLP1_1
);
1285 PIS(ERRCONTENTIONLP0_2
);
1286 PIS(ERRCONTENTIONLP1_2
);
1287 PIS(ERRCONTENTIONLP0_3
);
1288 PIS(ERRCONTENTIONLP1_3
);
1289 PIS(ULPSACTIVENOT_ALL0
);
1290 PIS(ULPSACTIVENOT_ALL1
);
1295 void dsi_dump_regs(struct seq_file
*s
)
1297 #define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dsi_read_reg(r))
1299 dss_clk_enable(DSS_CLK_ICK
| DSS_CLK_FCK1
);
1301 DUMPREG(DSI_REVISION
);
1302 DUMPREG(DSI_SYSCONFIG
);
1303 DUMPREG(DSI_SYSSTATUS
);
1304 DUMPREG(DSI_IRQSTATUS
);
1305 DUMPREG(DSI_IRQENABLE
);
1307 DUMPREG(DSI_COMPLEXIO_CFG1
);
1308 DUMPREG(DSI_COMPLEXIO_IRQ_STATUS
);
1309 DUMPREG(DSI_COMPLEXIO_IRQ_ENABLE
);
1310 DUMPREG(DSI_CLK_CTRL
);
1311 DUMPREG(DSI_TIMING1
);
1312 DUMPREG(DSI_TIMING2
);
1313 DUMPREG(DSI_VM_TIMING1
);
1314 DUMPREG(DSI_VM_TIMING2
);
1315 DUMPREG(DSI_VM_TIMING3
);
1316 DUMPREG(DSI_CLK_TIMING
);
1317 DUMPREG(DSI_TX_FIFO_VC_SIZE
);
1318 DUMPREG(DSI_RX_FIFO_VC_SIZE
);
1319 DUMPREG(DSI_COMPLEXIO_CFG2
);
1320 DUMPREG(DSI_RX_FIFO_VC_FULLNESS
);
1321 DUMPREG(DSI_VM_TIMING4
);
1322 DUMPREG(DSI_TX_FIFO_VC_EMPTINESS
);
1323 DUMPREG(DSI_VM_TIMING5
);
1324 DUMPREG(DSI_VM_TIMING6
);
1325 DUMPREG(DSI_VM_TIMING7
);
1326 DUMPREG(DSI_STOPCLK_TIMING
);
1328 DUMPREG(DSI_VC_CTRL(0));
1329 DUMPREG(DSI_VC_TE(0));
1330 DUMPREG(DSI_VC_LONG_PACKET_HEADER(0));
1331 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(0));
1332 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(0));
1333 DUMPREG(DSI_VC_IRQSTATUS(0));
1334 DUMPREG(DSI_VC_IRQENABLE(0));
1336 DUMPREG(DSI_VC_CTRL(1));
1337 DUMPREG(DSI_VC_TE(1));
1338 DUMPREG(DSI_VC_LONG_PACKET_HEADER(1));
1339 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(1));
1340 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(1));
1341 DUMPREG(DSI_VC_IRQSTATUS(1));
1342 DUMPREG(DSI_VC_IRQENABLE(1));
1344 DUMPREG(DSI_VC_CTRL(2));
1345 DUMPREG(DSI_VC_TE(2));
1346 DUMPREG(DSI_VC_LONG_PACKET_HEADER(2));
1347 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(2));
1348 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(2));
1349 DUMPREG(DSI_VC_IRQSTATUS(2));
1350 DUMPREG(DSI_VC_IRQENABLE(2));
1352 DUMPREG(DSI_VC_CTRL(3));
1353 DUMPREG(DSI_VC_TE(3));
1354 DUMPREG(DSI_VC_LONG_PACKET_HEADER(3));
1355 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(3));
1356 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(3));
1357 DUMPREG(DSI_VC_IRQSTATUS(3));
1358 DUMPREG(DSI_VC_IRQENABLE(3));
1360 DUMPREG(DSI_DSIPHY_CFG0
);
1361 DUMPREG(DSI_DSIPHY_CFG1
);
1362 DUMPREG(DSI_DSIPHY_CFG2
);
1363 DUMPREG(DSI_DSIPHY_CFG5
);
1365 DUMPREG(DSI_PLL_CONTROL
);
1366 DUMPREG(DSI_PLL_STATUS
);
1367 DUMPREG(DSI_PLL_GO
);
1368 DUMPREG(DSI_PLL_CONFIGURATION1
);
1369 DUMPREG(DSI_PLL_CONFIGURATION2
);
1371 dss_clk_disable(DSS_CLK_ICK
| DSS_CLK_FCK1
);
1375 enum dsi_complexio_power_state
{
1376 DSI_COMPLEXIO_POWER_OFF
= 0x0,
1377 DSI_COMPLEXIO_POWER_ON
= 0x1,
1378 DSI_COMPLEXIO_POWER_ULPS
= 0x2,
1381 static int dsi_complexio_power(enum dsi_complexio_power_state state
)
1386 REG_FLD_MOD(DSI_COMPLEXIO_CFG1
, state
, 28, 27);
1389 while (FLD_GET(dsi_read_reg(DSI_COMPLEXIO_CFG1
), 26, 25) != state
) {
1391 DSSERR("failed to set complexio power state to "
1401 static void dsi_complexio_config(struct omap_dss_device
*dssdev
)
1405 int clk_lane
= dssdev
->phy
.dsi
.clk_lane
;
1406 int data1_lane
= dssdev
->phy
.dsi
.data1_lane
;
1407 int data2_lane
= dssdev
->phy
.dsi
.data2_lane
;
1408 int clk_pol
= dssdev
->phy
.dsi
.clk_pol
;
1409 int data1_pol
= dssdev
->phy
.dsi
.data1_pol
;
1410 int data2_pol
= dssdev
->phy
.dsi
.data2_pol
;
1412 r
= dsi_read_reg(DSI_COMPLEXIO_CFG1
);
1413 r
= FLD_MOD(r
, clk_lane
, 2, 0);
1414 r
= FLD_MOD(r
, clk_pol
, 3, 3);
1415 r
= FLD_MOD(r
, data1_lane
, 6, 4);
1416 r
= FLD_MOD(r
, data1_pol
, 7, 7);
1417 r
= FLD_MOD(r
, data2_lane
, 10, 8);
1418 r
= FLD_MOD(r
, data2_pol
, 11, 11);
1419 dsi_write_reg(DSI_COMPLEXIO_CFG1
, r
);
1421 /* The configuration of the DSI complex I/O (number of data lanes,
1422 position, differential order) should not be changed while
1423 DSS.DSI_CLK_CRTRL[20] LP_CLK_ENABLE bit is set to 1. In order for
1424 the hardware to take into account a new configuration of the complex
1425 I/O (done in DSS.DSI_COMPLEXIO_CFG1 register), it is recommended to
1426 follow this sequence: First set the DSS.DSI_CTRL[0] IF_EN bit to 1,
1427 then reset the DSS.DSI_CTRL[0] IF_EN to 0, then set
1428 DSS.DSI_CLK_CTRL[20] LP_CLK_ENABLE to 1 and finally set again the
1429 DSS.DSI_CTRL[0] IF_EN bit to 1. If the sequence is not followed, the
1430 DSI complex I/O configuration is unknown. */
1433 REG_FLD_MOD(DSI_CTRL, 1, 0, 0);
1434 REG_FLD_MOD(DSI_CTRL, 0, 0, 0);
1435 REG_FLD_MOD(DSI_CLK_CTRL, 1, 20, 20);
1436 REG_FLD_MOD(DSI_CTRL, 1, 0, 0);
1440 static inline unsigned ns2ddr(unsigned ns
)
1442 /* convert time in ns to ddr ticks, rounding up */
1443 unsigned long ddr_clk
= dsi
.current_cinfo
.clkin4ddr
/ 4;
1444 return (ns
* (ddr_clk
/ 1000 / 1000) + 999) / 1000;
1447 static inline unsigned ddr2ns(unsigned ddr
)
1449 unsigned long ddr_clk
= dsi
.current_cinfo
.clkin4ddr
/ 4;
1450 return ddr
* 1000 * 1000 / (ddr_clk
/ 1000);
1453 static void dsi_complexio_timings(void)
1456 u32 ths_prepare
, ths_prepare_ths_zero
, ths_trail
, ths_exit
;
1457 u32 tlpx_half
, tclk_trail
, tclk_zero
;
1460 /* calculate timings */
1462 /* 1 * DDR_CLK = 2 * UI */
1464 /* min 40ns + 4*UI max 85ns + 6*UI */
1465 ths_prepare
= ns2ddr(70) + 2;
1467 /* min 145ns + 10*UI */
1468 ths_prepare_ths_zero
= ns2ddr(175) + 2;
1470 /* min max(8*UI, 60ns+4*UI) */
1471 ths_trail
= ns2ddr(60) + 5;
1474 ths_exit
= ns2ddr(145);
1477 tlpx_half
= ns2ddr(25);
1480 tclk_trail
= ns2ddr(60) + 2;
1482 /* min 38ns, max 95ns */
1483 tclk_prepare
= ns2ddr(65);
1485 /* min tclk-prepare + tclk-zero = 300ns */
1486 tclk_zero
= ns2ddr(260);
1488 DSSDBG("ths_prepare %u (%uns), ths_prepare_ths_zero %u (%uns)\n",
1489 ths_prepare
, ddr2ns(ths_prepare
),
1490 ths_prepare_ths_zero
, ddr2ns(ths_prepare_ths_zero
));
1491 DSSDBG("ths_trail %u (%uns), ths_exit %u (%uns)\n",
1492 ths_trail
, ddr2ns(ths_trail
),
1493 ths_exit
, ddr2ns(ths_exit
));
1495 DSSDBG("tlpx_half %u (%uns), tclk_trail %u (%uns), "
1496 "tclk_zero %u (%uns)\n",
1497 tlpx_half
, ddr2ns(tlpx_half
),
1498 tclk_trail
, ddr2ns(tclk_trail
),
1499 tclk_zero
, ddr2ns(tclk_zero
));
1500 DSSDBG("tclk_prepare %u (%uns)\n",
1501 tclk_prepare
, ddr2ns(tclk_prepare
));
1503 /* program timings */
1505 r
= dsi_read_reg(DSI_DSIPHY_CFG0
);
1506 r
= FLD_MOD(r
, ths_prepare
, 31, 24);
1507 r
= FLD_MOD(r
, ths_prepare_ths_zero
, 23, 16);
1508 r
= FLD_MOD(r
, ths_trail
, 15, 8);
1509 r
= FLD_MOD(r
, ths_exit
, 7, 0);
1510 dsi_write_reg(DSI_DSIPHY_CFG0
, r
);
1512 r
= dsi_read_reg(DSI_DSIPHY_CFG1
);
1513 r
= FLD_MOD(r
, tlpx_half
, 22, 16);
1514 r
= FLD_MOD(r
, tclk_trail
, 15, 8);
1515 r
= FLD_MOD(r
, tclk_zero
, 7, 0);
1516 dsi_write_reg(DSI_DSIPHY_CFG1
, r
);
1518 r
= dsi_read_reg(DSI_DSIPHY_CFG2
);
1519 r
= FLD_MOD(r
, tclk_prepare
, 7, 0);
1520 dsi_write_reg(DSI_DSIPHY_CFG2
, r
);
1524 static int dsi_complexio_init(struct omap_dss_device
*dssdev
)
1528 DSSDBG("dsi_complexio_init\n");
1530 /* CIO_CLK_ICG, enable L3 clk to CIO */
1531 REG_FLD_MOD(DSI_CLK_CTRL
, 1, 14, 14);
1533 /* A dummy read using the SCP interface to any DSIPHY register is
1534 * required after DSIPHY reset to complete the reset of the DSI complex
1536 dsi_read_reg(DSI_DSIPHY_CFG5
);
1538 if (wait_for_bit_change(DSI_DSIPHY_CFG5
, 30, 1) != 1) {
1539 DSSERR("ComplexIO PHY not coming out of reset.\n");
1544 dsi_complexio_config(dssdev
);
1546 r
= dsi_complexio_power(DSI_COMPLEXIO_POWER_ON
);
1551 if (wait_for_bit_change(DSI_COMPLEXIO_CFG1
, 29, 1) != 1) {
1552 DSSERR("ComplexIO not coming out of reset.\n");
1557 if (wait_for_bit_change(DSI_COMPLEXIO_CFG1
, 21, 1) != 1) {
1558 DSSERR("ComplexIO LDO power down.\n");
1563 dsi_complexio_timings();
1566 The configuration of the DSI complex I/O (number of data lanes,
1567 position, differential order) should not be changed while
1568 DSS.DSI_CLK_CRTRL[20] LP_CLK_ENABLE bit is set to 1. For the
1569 hardware to recognize a new configuration of the complex I/O (done
1570 in DSS.DSI_COMPLEXIO_CFG1 register), it is recommended to follow
1571 this sequence: First set the DSS.DSI_CTRL[0] IF_EN bit to 1, next
1572 reset the DSS.DSI_CTRL[0] IF_EN to 0, then set DSS.DSI_CLK_CTRL[20]
1573 LP_CLK_ENABLE to 1, and finally, set again the DSS.DSI_CTRL[0] IF_EN
1574 bit to 1. If the sequence is not followed, the DSi complex I/O
1575 configuration is undetermined.
1579 REG_FLD_MOD(DSI_CLK_CTRL
, 1, 20, 20); /* LP_CLK_ENABLE */
1583 DSSDBG("CIO init done\n");
1588 static void dsi_complexio_uninit(void)
1590 dsi_complexio_power(DSI_COMPLEXIO_POWER_OFF
);
1593 static int _dsi_wait_reset(void)
1597 while (REG_GET(DSI_SYSSTATUS
, 0, 0) == 0) {
1599 DSSERR("soft reset failed\n");
1608 static int _dsi_reset(void)
1611 REG_FLD_MOD(DSI_SYSCONFIG
, 1, 1, 1);
1612 return _dsi_wait_reset();
1615 static void dsi_reset_tx_fifo(int channel
)
1620 /* set fifosize of the channel to 0, then return the old size */
1621 l
= dsi_read_reg(DSI_TX_FIFO_VC_SIZE
);
1623 mask
= FLD_MASK((8 * channel
) + 7, (8 * channel
) + 4);
1624 dsi_write_reg(DSI_TX_FIFO_VC_SIZE
, l
& ~mask
);
1626 dsi_write_reg(DSI_TX_FIFO_VC_SIZE
, l
);
1629 static void dsi_config_tx_fifo(enum fifo_size size1
, enum fifo_size size2
,
1630 enum fifo_size size3
, enum fifo_size size4
)
1636 dsi
.vc
[0].fifo_size
= size1
;
1637 dsi
.vc
[1].fifo_size
= size2
;
1638 dsi
.vc
[2].fifo_size
= size3
;
1639 dsi
.vc
[3].fifo_size
= size4
;
1641 for (i
= 0; i
< 4; i
++) {
1643 int size
= dsi
.vc
[i
].fifo_size
;
1645 if (add
+ size
> 4) {
1646 DSSERR("Illegal FIFO configuration\n");
1650 v
= FLD_VAL(add
, 2, 0) | FLD_VAL(size
, 7, 4);
1652 /*DSSDBG("TX FIFO vc %d: size %d, add %d\n", i, size, add); */
1656 dsi_write_reg(DSI_TX_FIFO_VC_SIZE
, r
);
1659 static void dsi_config_rx_fifo(enum fifo_size size1
, enum fifo_size size2
,
1660 enum fifo_size size3
, enum fifo_size size4
)
1666 dsi
.vc
[0].fifo_size
= size1
;
1667 dsi
.vc
[1].fifo_size
= size2
;
1668 dsi
.vc
[2].fifo_size
= size3
;
1669 dsi
.vc
[3].fifo_size
= size4
;
1671 for (i
= 0; i
< 4; i
++) {
1673 int size
= dsi
.vc
[i
].fifo_size
;
1675 if (add
+ size
> 4) {
1676 DSSERR("Illegal FIFO configuration\n");
1680 v
= FLD_VAL(add
, 2, 0) | FLD_VAL(size
, 7, 4);
1682 /*DSSDBG("RX FIFO vc %d: size %d, add %d\n", i, size, add); */
1686 dsi_write_reg(DSI_RX_FIFO_VC_SIZE
, r
);
1689 static int dsi_force_tx_stop_mode_io(void)
1693 r
= dsi_read_reg(DSI_TIMING1
);
1694 r
= FLD_MOD(r
, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
1695 dsi_write_reg(DSI_TIMING1
, r
);
1697 if (wait_for_bit_change(DSI_TIMING1
, 15, 0) != 0) {
1698 DSSERR("TX_STOP bit not going down\n");
1705 static int dsi_vc_enable(int channel
, bool enable
)
1707 if (dsi
.update_mode
!= OMAP_DSS_UPDATE_AUTO
)
1708 DSSDBG("dsi_vc_enable channel %d, enable %d\n",
1711 enable
= enable
? 1 : 0;
1713 REG_FLD_MOD(DSI_VC_CTRL(channel
), enable
, 0, 0);
1715 if (wait_for_bit_change(DSI_VC_CTRL(channel
), 0, enable
) != enable
) {
1716 DSSERR("Failed to set dsi_vc_enable to %d\n", enable
);
1723 static void dsi_vc_initial_config(int channel
)
1727 DSSDBGF("%d", channel
);
1729 r
= dsi_read_reg(DSI_VC_CTRL(channel
));
1731 if (FLD_GET(r
, 15, 15)) /* VC_BUSY */
1732 DSSERR("VC(%d) busy when trying to configure it!\n",
1735 r
= FLD_MOD(r
, 0, 1, 1); /* SOURCE, 0 = L4 */
1736 r
= FLD_MOD(r
, 0, 2, 2); /* BTA_SHORT_EN */
1737 r
= FLD_MOD(r
, 0, 3, 3); /* BTA_LONG_EN */
1738 r
= FLD_MOD(r
, 0, 4, 4); /* MODE, 0 = command */
1739 r
= FLD_MOD(r
, 1, 7, 7); /* CS_TX_EN */
1740 r
= FLD_MOD(r
, 1, 8, 8); /* ECC_TX_EN */
1741 r
= FLD_MOD(r
, 0, 9, 9); /* MODE_SPEED, high speed on/off */
1743 r
= FLD_MOD(r
, 4, 29, 27); /* DMA_RX_REQ_NB = no dma */
1744 r
= FLD_MOD(r
, 4, 23, 21); /* DMA_TX_REQ_NB = no dma */
1746 dsi_write_reg(DSI_VC_CTRL(channel
), r
);
1748 dsi
.vc
[channel
].mode
= DSI_VC_MODE_L4
;
1751 static void dsi_vc_config_l4(int channel
)
1753 if (dsi
.vc
[channel
].mode
== DSI_VC_MODE_L4
)
1756 DSSDBGF("%d", channel
);
1758 dsi_vc_enable(channel
, 0);
1760 if (REG_GET(DSI_VC_CTRL(channel
), 15, 15)) /* VC_BUSY */
1761 DSSERR("vc(%d) busy when trying to config for L4\n", channel
);
1763 REG_FLD_MOD(DSI_VC_CTRL(channel
), 0, 1, 1); /* SOURCE, 0 = L4 */
1765 dsi_vc_enable(channel
, 1);
1767 dsi
.vc
[channel
].mode
= DSI_VC_MODE_L4
;
1770 static void dsi_vc_config_vp(int channel
)
1772 if (dsi
.vc
[channel
].mode
== DSI_VC_MODE_VP
)
1775 DSSDBGF("%d", channel
);
1777 dsi_vc_enable(channel
, 0);
1779 if (REG_GET(DSI_VC_CTRL(channel
), 15, 15)) /* VC_BUSY */
1780 DSSERR("vc(%d) busy when trying to config for VP\n", channel
);
1782 REG_FLD_MOD(DSI_VC_CTRL(channel
), 1, 1, 1); /* SOURCE, 1 = video port */
1784 dsi_vc_enable(channel
, 1);
1786 dsi
.vc
[channel
].mode
= DSI_VC_MODE_VP
;
1790 void omapdss_dsi_vc_enable_hs(int channel
, bool enable
)
1792 DSSDBG("dsi_vc_enable_hs(%d, %d)\n", channel
, enable
);
1794 WARN_ON(!dsi_bus_is_locked());
1796 dsi_vc_enable(channel
, 0);
1799 REG_FLD_MOD(DSI_VC_CTRL(channel
), enable
, 9, 9);
1801 dsi_vc_enable(channel
, 1);
1804 dsi_force_tx_stop_mode_io();
1806 EXPORT_SYMBOL(omapdss_dsi_vc_enable_hs
);
1808 static void dsi_vc_flush_long_data(int channel
)
1810 while (REG_GET(DSI_VC_CTRL(channel
), 20, 20)) {
1812 val
= dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel
));
1813 DSSDBG("\t\tb1 %#02x b2 %#02x b3 %#02x b4 %#02x\n",
1817 (val
>> 24) & 0xff);
1821 static void dsi_show_rx_ack_with_err(u16 err
)
1823 DSSERR("\tACK with ERROR (%#x):\n", err
);
1825 DSSERR("\t\tSoT Error\n");
1827 DSSERR("\t\tSoT Sync Error\n");
1829 DSSERR("\t\tEoT Sync Error\n");
1831 DSSERR("\t\tEscape Mode Entry Command Error\n");
1833 DSSERR("\t\tLP Transmit Sync Error\n");
1835 DSSERR("\t\tHS Receive Timeout Error\n");
1837 DSSERR("\t\tFalse Control Error\n");
1839 DSSERR("\t\t(reserved7)\n");
1841 DSSERR("\t\tECC Error, single-bit (corrected)\n");
1843 DSSERR("\t\tECC Error, multi-bit (not corrected)\n");
1844 if (err
& (1 << 10))
1845 DSSERR("\t\tChecksum Error\n");
1846 if (err
& (1 << 11))
1847 DSSERR("\t\tData type not recognized\n");
1848 if (err
& (1 << 12))
1849 DSSERR("\t\tInvalid VC ID\n");
1850 if (err
& (1 << 13))
1851 DSSERR("\t\tInvalid Transmission Length\n");
1852 if (err
& (1 << 14))
1853 DSSERR("\t\t(reserved14)\n");
1854 if (err
& (1 << 15))
1855 DSSERR("\t\tDSI Protocol Violation\n");
1858 static u16
dsi_vc_flush_receive_data(int channel
)
1860 /* RX_FIFO_NOT_EMPTY */
1861 while (REG_GET(DSI_VC_CTRL(channel
), 20, 20)) {
1864 val
= dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel
));
1865 DSSDBG("\trawval %#08x\n", val
);
1866 dt
= FLD_GET(val
, 5, 0);
1867 if (dt
== DSI_DT_RX_ACK_WITH_ERR
) {
1868 u16 err
= FLD_GET(val
, 23, 8);
1869 dsi_show_rx_ack_with_err(err
);
1870 } else if (dt
== DSI_DT_RX_SHORT_READ_1
) {
1871 DSSDBG("\tDCS short response, 1 byte: %#x\n",
1872 FLD_GET(val
, 23, 8));
1873 } else if (dt
== DSI_DT_RX_SHORT_READ_2
) {
1874 DSSDBG("\tDCS short response, 2 byte: %#x\n",
1875 FLD_GET(val
, 23, 8));
1876 } else if (dt
== DSI_DT_RX_DCS_LONG_READ
) {
1877 DSSDBG("\tDCS long response, len %d\n",
1878 FLD_GET(val
, 23, 8));
1879 dsi_vc_flush_long_data(channel
);
1881 DSSERR("\tunknown datatype 0x%02x\n", dt
);
1887 static int dsi_vc_send_bta(int channel
)
1889 if (dsi
.update_mode
!= OMAP_DSS_UPDATE_AUTO
&&
1890 (dsi
.debug_write
|| dsi
.debug_read
))
1891 DSSDBG("dsi_vc_send_bta %d\n", channel
);
1893 WARN_ON(!dsi_bus_is_locked());
1895 if (REG_GET(DSI_VC_CTRL(channel
), 20, 20)) { /* RX_FIFO_NOT_EMPTY */
1896 DSSERR("rx fifo not empty when sending BTA, dumping data:\n");
1897 dsi_vc_flush_receive_data(channel
);
1900 REG_FLD_MOD(DSI_VC_CTRL(channel
), 1, 6, 6); /* BTA_EN */
1905 int dsi_vc_send_bta_sync(int channel
)
1910 INIT_COMPLETION(dsi
.bta_completion
);
1912 dsi_vc_enable_bta_irq(channel
);
1914 r
= dsi_vc_send_bta(channel
);
1918 if (wait_for_completion_timeout(&dsi
.bta_completion
,
1919 msecs_to_jiffies(500)) == 0) {
1920 DSSERR("Failed to receive BTA\n");
1925 err
= dsi_get_errors();
1927 DSSERR("Error while sending BTA: %x\n", err
);
1932 dsi_vc_disable_bta_irq(channel
);
1936 EXPORT_SYMBOL(dsi_vc_send_bta_sync
);
1938 static inline void dsi_vc_write_long_header(int channel
, u8 data_type
,
1944 WARN_ON(!dsi_bus_is_locked());
1946 data_id
= data_type
| channel
<< 6;
1948 val
= FLD_VAL(data_id
, 7, 0) | FLD_VAL(len
, 23, 8) |
1949 FLD_VAL(ecc
, 31, 24);
1951 dsi_write_reg(DSI_VC_LONG_PACKET_HEADER(channel
), val
);
1954 static inline void dsi_vc_write_long_payload(int channel
,
1955 u8 b1
, u8 b2
, u8 b3
, u8 b4
)
1959 val
= b4
<< 24 | b3
<< 16 | b2
<< 8 | b1
<< 0;
1961 /* DSSDBG("\twriting %02x, %02x, %02x, %02x (%#010x)\n",
1962 b1, b2, b3, b4, val); */
1964 dsi_write_reg(DSI_VC_LONG_PACKET_PAYLOAD(channel
), val
);
1967 static int dsi_vc_send_long(int channel
, u8 data_type
, u8
*data
, u16 len
,
1976 if (dsi
.debug_write
)
1977 DSSDBG("dsi_vc_send_long, %d bytes\n", len
);
1980 if (dsi
.vc
[channel
].fifo_size
* 32 * 4 < len
+ 4) {
1981 DSSERR("unable to send long packet: packet too long.\n");
1985 dsi_vc_config_l4(channel
);
1987 dsi_vc_write_long_header(channel
, data_type
, len
, ecc
);
1990 for (i
= 0; i
< len
>> 2; i
++) {
1991 if (dsi
.debug_write
)
1992 DSSDBG("\tsending full packet %d\n", i
);
1999 dsi_vc_write_long_payload(channel
, b1
, b2
, b3
, b4
);
2004 b1
= 0; b2
= 0; b3
= 0;
2006 if (dsi
.debug_write
)
2007 DSSDBG("\tsending remainder bytes %d\n", i
);
2024 dsi_vc_write_long_payload(channel
, b1
, b2
, b3
, 0);
2030 static int dsi_vc_send_short(int channel
, u8 data_type
, u16 data
, u8 ecc
)
2035 WARN_ON(!dsi_bus_is_locked());
2037 if (dsi
.debug_write
)
2038 DSSDBG("dsi_vc_send_short(ch%d, dt %#x, b1 %#x, b2 %#x)\n",
2040 data_type
, data
& 0xff, (data
>> 8) & 0xff);
2042 dsi_vc_config_l4(channel
);
2044 if (FLD_GET(dsi_read_reg(DSI_VC_CTRL(channel
)), 16, 16)) {
2045 DSSERR("ERROR FIFO FULL, aborting transfer\n");
2049 data_id
= data_type
| channel
<< 6;
2051 r
= (data_id
<< 0) | (data
<< 8) | (ecc
<< 24);
2053 dsi_write_reg(DSI_VC_SHORT_PACKET_HEADER(channel
), r
);
2058 int dsi_vc_send_null(int channel
)
2060 u8 nullpkg
[] = {0, 0, 0, 0};
2061 return dsi_vc_send_long(channel
, DSI_DT_NULL_PACKET
, nullpkg
, 4, 0);
2063 EXPORT_SYMBOL(dsi_vc_send_null
);
2065 int dsi_vc_dcs_write_nosync(int channel
, u8
*data
, int len
)
2072 r
= dsi_vc_send_short(channel
, DSI_DT_DCS_SHORT_WRITE_0
,
2074 } else if (len
== 2) {
2075 r
= dsi_vc_send_short(channel
, DSI_DT_DCS_SHORT_WRITE_1
,
2076 data
[0] | (data
[1] << 8), 0);
2078 /* 0x39 = DCS Long Write */
2079 r
= dsi_vc_send_long(channel
, DSI_DT_DCS_LONG_WRITE
,
2085 EXPORT_SYMBOL(dsi_vc_dcs_write_nosync
);
2087 int dsi_vc_dcs_write(int channel
, u8
*data
, int len
)
2091 r
= dsi_vc_dcs_write_nosync(channel
, data
, len
);
2095 r
= dsi_vc_send_bta_sync(channel
);
2099 EXPORT_SYMBOL(dsi_vc_dcs_write
);
2101 int dsi_vc_dcs_write_0(int channel
, u8 dcs_cmd
)
2103 return dsi_vc_dcs_write(channel
, &dcs_cmd
, 1);
2105 EXPORT_SYMBOL(dsi_vc_dcs_write_0
);
2107 int dsi_vc_dcs_write_1(int channel
, u8 dcs_cmd
, u8 param
)
2112 return dsi_vc_dcs_write(channel
, buf
, 2);
2114 EXPORT_SYMBOL(dsi_vc_dcs_write_1
);
2116 int dsi_vc_dcs_read(int channel
, u8 dcs_cmd
, u8
*buf
, int buflen
)
2123 DSSDBG("dsi_vc_dcs_read(ch%d, dcs_cmd %x)\n", channel
, dcs_cmd
);
2125 r
= dsi_vc_send_short(channel
, DSI_DT_DCS_READ
, dcs_cmd
, 0);
2129 r
= dsi_vc_send_bta_sync(channel
);
2133 /* RX_FIFO_NOT_EMPTY */
2134 if (REG_GET(DSI_VC_CTRL(channel
), 20, 20) == 0) {
2135 DSSERR("RX fifo empty when trying to read.\n");
2139 val
= dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel
));
2141 DSSDBG("\theader: %08x\n", val
);
2142 dt
= FLD_GET(val
, 5, 0);
2143 if (dt
== DSI_DT_RX_ACK_WITH_ERR
) {
2144 u16 err
= FLD_GET(val
, 23, 8);
2145 dsi_show_rx_ack_with_err(err
);
2148 } else if (dt
== DSI_DT_RX_SHORT_READ_1
) {
2149 u8 data
= FLD_GET(val
, 15, 8);
2151 DSSDBG("\tDCS short response, 1 byte: %02x\n", data
);
2159 } else if (dt
== DSI_DT_RX_SHORT_READ_2
) {
2160 u16 data
= FLD_GET(val
, 23, 8);
2162 DSSDBG("\tDCS short response, 2 byte: %04x\n", data
);
2167 buf
[0] = data
& 0xff;
2168 buf
[1] = (data
>> 8) & 0xff;
2171 } else if (dt
== DSI_DT_RX_DCS_LONG_READ
) {
2173 int len
= FLD_GET(val
, 23, 8);
2175 DSSDBG("\tDCS long response, len %d\n", len
);
2180 /* two byte checksum ends the packet, not included in len */
2181 for (w
= 0; w
< len
+ 2;) {
2183 val
= dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel
));
2185 DSSDBG("\t\t%02x %02x %02x %02x\n",
2189 (val
>> 24) & 0xff);
2191 for (b
= 0; b
< 4; ++b
) {
2193 buf
[w
] = (val
>> (b
* 8)) & 0xff;
2194 /* we discard the 2 byte checksum */
2202 DSSERR("\tunknown datatype 0x%02x\n", dt
);
2206 EXPORT_SYMBOL(dsi_vc_dcs_read
);
2208 int dsi_vc_dcs_read_1(int channel
, u8 dcs_cmd
, u8
*data
)
2212 r
= dsi_vc_dcs_read(channel
, dcs_cmd
, data
, 1);
2222 EXPORT_SYMBOL(dsi_vc_dcs_read_1
);
2224 int dsi_vc_set_max_rx_packet_size(int channel
, u16 len
)
2227 r
= dsi_vc_send_short(channel
, DSI_DT_SET_MAX_RET_PKG_SIZE
,
2233 r
= dsi_vc_send_bta_sync(channel
);
2237 EXPORT_SYMBOL(dsi_vc_set_max_rx_packet_size
);
2239 static void dsi_set_lp_rx_timeout(unsigned long ns
)
2244 unsigned long ticks
;
2246 /* ticks in DSI_FCK */
2248 fck
= dsi_fclk_rate();
2249 ticks
= (fck
/ 1000 / 1000) * ns
/ 1000;
2253 if (ticks
> 0x1fff) {
2254 ticks
= (fck
/ 1000 / 1000) * ns
/ 1000 / 4;
2259 if (ticks
> 0x1fff) {
2260 ticks
= (fck
/ 1000 / 1000) * ns
/ 1000 / 16;
2265 if (ticks
> 0x1fff) {
2266 ticks
= (fck
/ 1000 / 1000) * ns
/ 1000 / (4 * 16);
2271 if (ticks
> 0x1fff) {
2272 DSSWARN("LP_TX_TO over limit, setting it to max\n");
2278 r
= dsi_read_reg(DSI_TIMING2
);
2279 r
= FLD_MOD(r
, 1, 15, 15); /* LP_RX_TO */
2280 r
= FLD_MOD(r
, x16
, 14, 14); /* LP_RX_TO_X16 */
2281 r
= FLD_MOD(r
, x4
, 13, 13); /* LP_RX_TO_X4 */
2282 r
= FLD_MOD(r
, ticks
, 12, 0); /* LP_RX_COUNTER */
2283 dsi_write_reg(DSI_TIMING2
, r
);
2285 DSSDBG("LP_RX_TO %lu ns (%#lx ticks%s%s)\n",
2286 (ticks
* (x16
? 16 : 1) * (x4
? 4 : 1) * 1000) /
2287 (fck
/ 1000 / 1000),
2288 ticks
, x4
? " x4" : "", x16
? " x16" : "");
2291 static void dsi_set_ta_timeout(unsigned long ns
)
2296 unsigned long ticks
;
2298 /* ticks in DSI_FCK */
2299 fck
= dsi_fclk_rate();
2300 ticks
= (fck
/ 1000 / 1000) * ns
/ 1000;
2304 if (ticks
> 0x1fff) {
2305 ticks
= (fck
/ 1000 / 1000) * ns
/ 1000 / 8;
2310 if (ticks
> 0x1fff) {
2311 ticks
= (fck
/ 1000 / 1000) * ns
/ 1000 / 16;
2316 if (ticks
> 0x1fff) {
2317 ticks
= (fck
/ 1000 / 1000) * ns
/ 1000 / (8 * 16);
2322 if (ticks
> 0x1fff) {
2323 DSSWARN("TA_TO over limit, setting it to max\n");
2329 r
= dsi_read_reg(DSI_TIMING1
);
2330 r
= FLD_MOD(r
, 1, 31, 31); /* TA_TO */
2331 r
= FLD_MOD(r
, x16
, 30, 30); /* TA_TO_X16 */
2332 r
= FLD_MOD(r
, x8
, 29, 29); /* TA_TO_X8 */
2333 r
= FLD_MOD(r
, ticks
, 28, 16); /* TA_TO_COUNTER */
2334 dsi_write_reg(DSI_TIMING1
, r
);
2336 DSSDBG("TA_TO %lu ns (%#lx ticks%s%s)\n",
2337 (ticks
* (x16
? 16 : 1) * (x8
? 8 : 1) * 1000) /
2338 (fck
/ 1000 / 1000),
2339 ticks
, x8
? " x8" : "", x16
? " x16" : "");
2342 static void dsi_set_stop_state_counter(unsigned long ns
)
2347 unsigned long ticks
;
2349 /* ticks in DSI_FCK */
2351 fck
= dsi_fclk_rate();
2352 ticks
= (fck
/ 1000 / 1000) * ns
/ 1000;
2356 if (ticks
> 0x1fff) {
2357 ticks
= (fck
/ 1000 / 1000) * ns
/ 1000 / 4;
2362 if (ticks
> 0x1fff) {
2363 ticks
= (fck
/ 1000 / 1000) * ns
/ 1000 / 16;
2368 if (ticks
> 0x1fff) {
2369 ticks
= (fck
/ 1000 / 1000) * ns
/ 1000 / (4 * 16);
2374 if (ticks
> 0x1fff) {
2375 DSSWARN("STOP_STATE_COUNTER_IO over limit, "
2376 "setting it to max\n");
2382 r
= dsi_read_reg(DSI_TIMING1
);
2383 r
= FLD_MOD(r
, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
2384 r
= FLD_MOD(r
, x16
, 14, 14); /* STOP_STATE_X16_IO */
2385 r
= FLD_MOD(r
, x4
, 13, 13); /* STOP_STATE_X4_IO */
2386 r
= FLD_MOD(r
, ticks
, 12, 0); /* STOP_STATE_COUNTER_IO */
2387 dsi_write_reg(DSI_TIMING1
, r
);
2389 DSSDBG("STOP_STATE_COUNTER %lu ns (%#lx ticks%s%s)\n",
2390 (ticks
* (x16
? 16 : 1) * (x4
? 4 : 1) * 1000) /
2391 (fck
/ 1000 / 1000),
2392 ticks
, x4
? " x4" : "", x16
? " x16" : "");
2395 static void dsi_set_hs_tx_timeout(unsigned long ns
)
2400 unsigned long ticks
;
2402 /* ticks in TxByteClkHS */
2404 fck
= dsi_get_txbyteclkhs();
2405 ticks
= (fck
/ 1000 / 1000) * ns
/ 1000;
2409 if (ticks
> 0x1fff) {
2410 ticks
= (fck
/ 1000 / 1000) * ns
/ 1000 / 4;
2415 if (ticks
> 0x1fff) {
2416 ticks
= (fck
/ 1000 / 1000) * ns
/ 1000 / 16;
2421 if (ticks
> 0x1fff) {
2422 ticks
= (fck
/ 1000 / 1000) * ns
/ 1000 / (4 * 16);
2427 if (ticks
> 0x1fff) {
2428 DSSWARN("HS_TX_TO over limit, setting it to max\n");
2434 r
= dsi_read_reg(DSI_TIMING2
);
2435 r
= FLD_MOD(r
, 1, 31, 31); /* HS_TX_TO */
2436 r
= FLD_MOD(r
, x16
, 30, 30); /* HS_TX_TO_X16 */
2437 r
= FLD_MOD(r
, x4
, 29, 29); /* HS_TX_TO_X8 (4 really) */
2438 r
= FLD_MOD(r
, ticks
, 28, 16); /* HS_TX_TO_COUNTER */
2439 dsi_write_reg(DSI_TIMING2
, r
);
2441 DSSDBG("HS_TX_TO %lu ns (%#lx ticks%s%s)\n",
2442 (ticks
* (x16
? 16 : 1) * (x4
? 4 : 1) * 1000) /
2443 (fck
/ 1000 / 1000),
2444 ticks
, x4
? " x4" : "", x16
? " x16" : "");
2446 static int dsi_proto_config(struct omap_dss_device
*dssdev
)
2451 dsi_config_tx_fifo(DSI_FIFO_SIZE_32
,
2456 dsi_config_rx_fifo(DSI_FIFO_SIZE_32
,
2461 /* XXX what values for the timeouts? */
2462 dsi_set_stop_state_counter(1000);
2463 dsi_set_ta_timeout(6400000);
2464 dsi_set_lp_rx_timeout(48000);
2465 dsi_set_hs_tx_timeout(1000000);
2467 switch (dssdev
->ctrl
.pixel_size
) {
2481 r
= dsi_read_reg(DSI_CTRL
);
2482 r
= FLD_MOD(r
, 1, 1, 1); /* CS_RX_EN */
2483 r
= FLD_MOD(r
, 1, 2, 2); /* ECC_RX_EN */
2484 r
= FLD_MOD(r
, 1, 3, 3); /* TX_FIFO_ARBITRATION */
2485 r
= FLD_MOD(r
, 1, 4, 4); /* VP_CLK_RATIO, always 1, see errata*/
2486 r
= FLD_MOD(r
, buswidth
, 7, 6); /* VP_DATA_BUS_WIDTH */
2487 r
= FLD_MOD(r
, 0, 8, 8); /* VP_CLK_POL */
2488 r
= FLD_MOD(r
, 2, 13, 12); /* LINE_BUFFER, 2 lines */
2489 r
= FLD_MOD(r
, 1, 14, 14); /* TRIGGER_RESET_MODE */
2490 r
= FLD_MOD(r
, 1, 19, 19); /* EOT_ENABLE */
2491 r
= FLD_MOD(r
, 1, 24, 24); /* DCS_CMD_ENABLE */
2492 r
= FLD_MOD(r
, 0, 25, 25); /* DCS_CMD_CODE, 1=start, 0=continue */
2494 dsi_write_reg(DSI_CTRL
, r
);
2496 dsi_vc_initial_config(0);
2497 dsi_vc_initial_config(1);
2498 dsi_vc_initial_config(2);
2499 dsi_vc_initial_config(3);
2504 static void dsi_proto_timings(struct omap_dss_device
*dssdev
)
2506 unsigned tlpx
, tclk_zero
, tclk_prepare
, tclk_trail
;
2507 unsigned tclk_pre
, tclk_post
;
2508 unsigned ths_prepare
, ths_prepare_ths_zero
, ths_zero
;
2509 unsigned ths_trail
, ths_exit
;
2510 unsigned ddr_clk_pre
, ddr_clk_post
;
2511 unsigned enter_hs_mode_lat
, exit_hs_mode_lat
;
2515 r
= dsi_read_reg(DSI_DSIPHY_CFG0
);
2516 ths_prepare
= FLD_GET(r
, 31, 24);
2517 ths_prepare_ths_zero
= FLD_GET(r
, 23, 16);
2518 ths_zero
= ths_prepare_ths_zero
- ths_prepare
;
2519 ths_trail
= FLD_GET(r
, 15, 8);
2520 ths_exit
= FLD_GET(r
, 7, 0);
2522 r
= dsi_read_reg(DSI_DSIPHY_CFG1
);
2523 tlpx
= FLD_GET(r
, 22, 16) * 2;
2524 tclk_trail
= FLD_GET(r
, 15, 8);
2525 tclk_zero
= FLD_GET(r
, 7, 0);
2527 r
= dsi_read_reg(DSI_DSIPHY_CFG2
);
2528 tclk_prepare
= FLD_GET(r
, 7, 0);
2532 /* min 60ns + 52*UI */
2533 tclk_post
= ns2ddr(60) + 26;
2535 /* ths_eot is 2 for 2 datalanes and 4 for 1 datalane */
2536 if (dssdev
->phy
.dsi
.data1_lane
!= 0 &&
2537 dssdev
->phy
.dsi
.data2_lane
!= 0)
2542 ddr_clk_pre
= DIV_ROUND_UP(tclk_pre
+ tlpx
+ tclk_zero
+ tclk_prepare
,
2544 ddr_clk_post
= DIV_ROUND_UP(tclk_post
+ ths_trail
, 4) + ths_eot
;
2546 BUG_ON(ddr_clk_pre
== 0 || ddr_clk_pre
> 255);
2547 BUG_ON(ddr_clk_post
== 0 || ddr_clk_post
> 255);
2549 r
= dsi_read_reg(DSI_CLK_TIMING
);
2550 r
= FLD_MOD(r
, ddr_clk_pre
, 15, 8);
2551 r
= FLD_MOD(r
, ddr_clk_post
, 7, 0);
2552 dsi_write_reg(DSI_CLK_TIMING
, r
);
2554 DSSDBG("ddr_clk_pre %u, ddr_clk_post %u\n",
2558 enter_hs_mode_lat
= 1 + DIV_ROUND_UP(tlpx
, 4) +
2559 DIV_ROUND_UP(ths_prepare
, 4) +
2560 DIV_ROUND_UP(ths_zero
+ 3, 4);
2562 exit_hs_mode_lat
= DIV_ROUND_UP(ths_trail
+ ths_exit
, 4) + 1 + ths_eot
;
2564 r
= FLD_VAL(enter_hs_mode_lat
, 31, 16) |
2565 FLD_VAL(exit_hs_mode_lat
, 15, 0);
2566 dsi_write_reg(DSI_VM_TIMING7
, r
);
2568 DSSDBG("enter_hs_mode_lat %u, exit_hs_mode_lat %u\n",
2569 enter_hs_mode_lat
, exit_hs_mode_lat
);
2573 #define DSI_DECL_VARS \
2574 int __dsi_cb = 0; u32 __dsi_cv = 0;
2576 #define DSI_FLUSH(ch) \
2577 if (__dsi_cb > 0) { \
2578 /*DSSDBG("sending long packet %#010x\n", __dsi_cv);*/ \
2579 dsi_write_reg(DSI_VC_LONG_PACKET_PAYLOAD(ch), __dsi_cv); \
2580 __dsi_cb = __dsi_cv = 0; \
2583 #define DSI_PUSH(ch, data) \
2585 __dsi_cv |= (data) << (__dsi_cb * 8); \
2586 /*DSSDBG("cv = %#010x, cb = %d\n", __dsi_cv, __dsi_cb);*/ \
2587 if (++__dsi_cb > 3) \
2591 static int dsi_update_screen_l4(struct omap_dss_device
*dssdev
,
2592 int x
, int y
, int w
, int h
)
2594 /* Note: supports only 24bit colors in 32bit container */
2596 int fifo_stalls
= 0;
2597 int max_dsi_packet_size
;
2598 int max_data_per_packet
;
2599 int max_pixels_per_packet
;
2601 int bytespp
= dssdev
->ctrl
.pixel_size
/ 8;
2607 struct omap_overlay
*ovl
;
2611 DSSDBG("dsi_update_screen_l4 (%d,%d %dx%d)\n",
2614 ovl
= dssdev
->manager
->overlays
[0];
2616 if (ovl
->info
.color_mode
!= OMAP_DSS_COLOR_RGB24U
)
2619 if (dssdev
->ctrl
.pixel_size
!= 24)
2622 scr_width
= ovl
->info
.screen_width
;
2623 data
= ovl
->info
.vaddr
;
2625 start_offset
= scr_width
* y
+ x
;
2626 horiz_inc
= scr_width
- w
;
2629 /* We need header(4) + DCSCMD(1) + pixels(numpix*bytespp) bytes
2632 /* When using CPU, max long packet size is TX buffer size */
2633 max_dsi_packet_size
= dsi
.vc
[0].fifo_size
* 32 * 4;
2635 /* we seem to get better perf if we divide the tx fifo to half,
2636 and while the other half is being sent, we fill the other half
2637 max_dsi_packet_size /= 2; */
2639 max_data_per_packet
= max_dsi_packet_size
- 4 - 1;
2641 max_pixels_per_packet
= max_data_per_packet
/ bytespp
;
2643 DSSDBG("max_pixels_per_packet %d\n", max_pixels_per_packet
);
2645 pixels_left
= w
* h
;
2647 DSSDBG("total pixels %d\n", pixels_left
);
2649 data
+= start_offset
;
2651 while (pixels_left
> 0) {
2652 /* 0x2c = write_memory_start */
2653 /* 0x3c = write_memory_continue */
2654 u8 dcs_cmd
= first
? 0x2c : 0x3c;
2660 /* using fifo not empty */
2661 /* TX_FIFO_NOT_EMPTY */
2662 while (FLD_GET(dsi_read_reg(DSI_VC_CTRL(0)), 5, 5)) {
2664 if (fifo_stalls
> 0xfffff) {
2665 DSSERR("fifo stalls overflow, pixels left %d\n",
2673 /* using fifo emptiness */
2674 while ((REG_GET(DSI_TX_FIFO_VC_EMPTINESS
, 7, 0)+1)*4 <
2675 max_dsi_packet_size
) {
2677 if (fifo_stalls
> 0xfffff) {
2678 DSSERR("fifo stalls overflow, pixels left %d\n",
2685 while ((REG_GET(DSI_TX_FIFO_VC_EMPTINESS
, 7, 0)+1)*4 == 0) {
2687 if (fifo_stalls
> 0xfffff) {
2688 DSSERR("fifo stalls overflow, pixels left %d\n",
2695 pixels
= min(max_pixels_per_packet
, pixels_left
);
2697 pixels_left
-= pixels
;
2699 dsi_vc_write_long_header(0, DSI_DT_DCS_LONG_WRITE
,
2700 1 + pixels
* bytespp
, 0);
2702 DSI_PUSH(0, dcs_cmd
);
2704 while (pixels
-- > 0) {
2705 u32 pix
= __raw_readl(data
++);
2707 DSI_PUSH(0, (pix
>> 16) & 0xff);
2708 DSI_PUSH(0, (pix
>> 8) & 0xff);
2709 DSI_PUSH(0, (pix
>> 0) & 0xff);
2712 if (current_x
== x
+w
) {
2724 static void dsi_update_screen_dispc(struct omap_dss_device
*dssdev
,
2725 u16 x
, u16 y
, u16 w
, u16 h
)
2731 unsigned packet_payload
;
2732 unsigned packet_len
;
2734 bool use_te_trigger
;
2735 const unsigned channel
= 0;
2736 /* line buffer is 1024 x 24bits */
2737 /* XXX: for some reason using full buffer size causes considerable TX
2738 * slowdown with update sizes that fill the whole buffer */
2739 const unsigned line_buf_size
= 1023 * 3;
2741 use_te_trigger
= dsi
.te_enabled
&& !dsi
.use_ext_te
;
2743 if (dsi
.update_mode
!= OMAP_DSS_UPDATE_AUTO
)
2744 DSSDBG("dsi_update_screen_dispc(%d,%d %dx%d)\n",
2747 bytespp
= dssdev
->ctrl
.pixel_size
/ 8;
2748 bytespl
= w
* bytespp
;
2749 bytespf
= bytespl
* h
;
2751 /* NOTE: packet_payload has to be equal to N * bytespl, where N is
2752 * number of lines in a packet. See errata about VP_CLK_RATIO */
2754 if (bytespf
< line_buf_size
)
2755 packet_payload
= bytespf
;
2757 packet_payload
= (line_buf_size
) / bytespl
* bytespl
;
2759 packet_len
= packet_payload
+ 1; /* 1 byte for DCS cmd */
2760 total_len
= (bytespf
/ packet_payload
) * packet_len
;
2762 if (bytespf
% packet_payload
)
2763 total_len
+= (bytespf
% packet_payload
) + 1;
2765 l
= FLD_VAL(total_len
, 23, 0); /* TE_SIZE */
2766 dsi_write_reg(DSI_VC_TE(channel
), l
);
2768 dsi_vc_write_long_header(channel
, DSI_DT_DCS_LONG_WRITE
, packet_len
, 0);
2771 l
= FLD_MOD(l
, 1, 30, 30); /* TE_EN */
2773 l
= FLD_MOD(l
, 1, 31, 31); /* TE_START */
2774 dsi_write_reg(DSI_VC_TE(channel
), l
);
2776 /* We put SIDLEMODE to no-idle for the duration of the transfer,
2777 * because DSS interrupts are not capable of waking up the CPU and the
2778 * framedone interrupt could be delayed for quite a long time. I think
2779 * the same goes for any DSS interrupts, but for some reason I have not
2780 * seen the problem anywhere else than here.
2782 dispc_disable_sidle();
2784 dss_start_update(dssdev
);
2786 if (use_te_trigger
) {
2787 /* disable LP_RX_TO, so that we can receive TE. Time to wait
2788 * for TE is longer than the timer allows */
2789 REG_FLD_MOD(DSI_TIMING2
, 0, 15, 15); /* LP_RX_TO */
2791 dsi_vc_send_bta(channel
);
2793 #ifdef DSI_CATCH_MISSING_TE
2794 mod_timer(&dsi
.te_timer
, jiffies
+ msecs_to_jiffies(250));
2799 #ifdef DSI_CATCH_MISSING_TE
2800 static void dsi_te_timeout(unsigned long arg
)
2802 DSSERR("TE not received for 250ms!\n");
2806 static void dsi_framedone_irq_callback(void *data
, u32 mask
)
2808 /* Note: We get FRAMEDONE when DISPC has finished sending pixels and
2809 * turns itself off. However, DSI still has the pixels in its buffers,
2810 * and is sending the data.
2813 /* SIDLEMODE back to smart-idle */
2814 dispc_enable_sidle();
2816 dsi
.framedone_received
= true;
2817 wake_up(&dsi
.waitqueue
);
2820 static void dsi_set_update_region(struct omap_dss_device
*dssdev
,
2821 u16 x
, u16 y
, u16 w
, u16 h
)
2823 spin_lock(&dsi
.update_lock
);
2824 if (dsi
.update_region
.dirty
) {
2825 dsi
.update_region
.x
= min(x
, dsi
.update_region
.x
);
2826 dsi
.update_region
.y
= min(y
, dsi
.update_region
.y
);
2827 dsi
.update_region
.w
= max(w
, dsi
.update_region
.w
);
2828 dsi
.update_region
.h
= max(h
, dsi
.update_region
.h
);
2830 dsi
.update_region
.x
= x
;
2831 dsi
.update_region
.y
= y
;
2832 dsi
.update_region
.w
= w
;
2833 dsi
.update_region
.h
= h
;
2836 dsi
.update_region
.device
= dssdev
;
2837 dsi
.update_region
.dirty
= true;
2839 spin_unlock(&dsi
.update_lock
);
2843 static int dsi_set_update_mode(struct omap_dss_device
*dssdev
,
2844 enum omap_dss_update_mode mode
)
2849 WARN_ON(!dsi_bus_is_locked());
2851 if (dsi
.update_mode
!= mode
) {
2852 dsi
.update_mode
= mode
;
2854 /* Mark the overlays dirty, and do apply(), so that we get the
2855 * overlays configured properly after update mode change. */
2856 for (i
= 0; i
< omap_dss_get_num_overlays(); ++i
) {
2857 struct omap_overlay
*ovl
;
2858 ovl
= omap_dss_get_overlay(i
);
2859 if (ovl
->manager
== dssdev
->manager
)
2860 ovl
->info_dirty
= true;
2863 r
= dssdev
->manager
->apply(dssdev
->manager
);
2865 if (dssdev
->state
== OMAP_DSS_DISPLAY_ACTIVE
&&
2866 mode
== OMAP_DSS_UPDATE_AUTO
) {
2869 DSSDBG("starting auto update\n");
2871 dssdev
->get_resolution(dssdev
, &w
, &h
);
2873 dsi_set_update_region(dssdev
, 0, 0, w
, h
);
2875 wake_up(&dsi
.waitqueue
);
2882 static int dsi_set_te(struct omap_dss_device
*dssdev
, bool enable
)
2886 if (dssdev
->driver
->enable_te
) {
2887 r
= dssdev
->driver
->enable_te(dssdev
, enable
);
2888 /* XXX for some reason, DSI TE breaks if we don't wait here.
2889 * Panel bug? Needs more studying */
2896 static void dsi_handle_framedone(void)
2899 const int channel
= 0;
2900 bool use_te_trigger
;
2902 use_te_trigger
= dsi
.te_enabled
&& !dsi
.use_ext_te
;
2904 if (dsi
.update_mode
!= OMAP_DSS_UPDATE_AUTO
)
2905 DSSDBG("FRAMEDONE\n");
2907 if (use_te_trigger
) {
2908 /* enable LP_RX_TO again after the TE */
2909 REG_FLD_MOD(DSI_TIMING2
, 1, 15, 15); /* LP_RX_TO */
2912 /* Send BTA after the frame. We need this for the TE to work, as TE
2913 * trigger is only sent for BTAs without preceding packet. Thus we need
2914 * to BTA after the pixel packets so that next BTA will cause TE
2917 * This is not needed when TE is not in use, but we do it anyway to
2918 * make sure that the transfer has been completed. It would be more
2919 * optimal, but more complex, to wait only just before starting next
2921 r
= dsi_vc_send_bta_sync(channel
);
2923 DSSERR("BTA after framedone failed\n");
2925 /* RX_FIFO_NOT_EMPTY */
2926 if (REG_GET(DSI_VC_CTRL(channel
), 20, 20)) {
2927 DSSERR("Received error during frame transfer:\n");
2928 dsi_vc_flush_receive_data(channel
);
2931 #ifdef CONFIG_OMAP2_DSS_FAKE_VSYNC
2932 dispc_fake_vsync_irq();
2936 static int dsi_update_thread(void *data
)
2938 unsigned long timeout
;
2939 struct omap_dss_device
*device
;
2943 wait_event_interruptible(dsi
.waitqueue
,
2944 dsi
.update_mode
== OMAP_DSS_UPDATE_AUTO
||
2945 (dsi
.update_mode
== OMAP_DSS_UPDATE_MANUAL
&&
2946 dsi
.update_region
.dirty
== true) ||
2947 kthread_should_stop());
2949 if (kthread_should_stop())
2954 if (dsi
.update_mode
== OMAP_DSS_UPDATE_DISABLED
||
2955 kthread_should_stop()) {
2960 dsi_perf_mark_setup();
2962 if (dsi
.update_region
.dirty
) {
2963 spin_lock(&dsi
.update_lock
);
2964 dsi
.active_update_region
= dsi
.update_region
;
2965 dsi
.update_region
.dirty
= false;
2966 spin_unlock(&dsi
.update_lock
);
2969 device
= dsi
.active_update_region
.device
;
2970 x
= dsi
.active_update_region
.x
;
2971 y
= dsi
.active_update_region
.y
;
2972 w
= dsi
.active_update_region
.w
;
2973 h
= dsi
.active_update_region
.h
;
2975 if (device
->manager
->caps
& OMAP_DSS_OVL_MGR_CAP_DISPC
) {
2977 if (dsi
.update_mode
== OMAP_DSS_UPDATE_MANUAL
)
2978 dss_setup_partial_planes(device
,
2981 dispc_set_lcd_size(w
, h
);
2984 if (dsi
.active_update_region
.dirty
) {
2985 dsi
.active_update_region
.dirty
= false;
2986 /* XXX TODO we don't need to send the coords, if they
2987 * are the same that are already programmed to the
2988 * panel. That should speed up manual update a bit */
2989 device
->driver
->setup_update(device
, x
, y
, w
, h
);
2992 dsi_perf_mark_start();
2994 if (device
->manager
->caps
& OMAP_DSS_OVL_MGR_CAP_DISPC
) {
2995 dsi_vc_config_vp(0);
2997 if (dsi
.te_enabled
&& dsi
.use_ext_te
)
2998 device
->driver
->wait_for_te(device
);
3000 dsi
.framedone_received
= false;
3002 dsi_update_screen_dispc(device
, x
, y
, w
, h
);
3004 /* wait for framedone */
3005 timeout
= msecs_to_jiffies(1000);
3006 wait_event_timeout(dsi
.waitqueue
,
3007 dsi
.framedone_received
== true,
3010 if (!dsi
.framedone_received
) {
3011 DSSERR("framedone timeout\n");
3012 DSSERR("failed update %d,%d %dx%d\n",
3015 dispc_enable_sidle();
3016 dispc_enable_lcd_out(0);
3018 dsi_reset_tx_fifo(0);
3020 dsi_handle_framedone();
3021 dsi_perf_show("DISPC");
3024 dsi_update_screen_l4(device
, x
, y
, w
, h
);
3025 dsi_perf_show("L4");
3028 complete_all(&dsi
.update_completion
);
3033 DSSDBG("update thread exiting\n");
3042 static int dsi_display_init_dispc(struct omap_dss_device
*dssdev
)
3046 r
= omap_dispc_register_isr(dsi_framedone_irq_callback
, NULL
,
3047 DISPC_IRQ_FRAMEDONE
);
3049 DSSERR("can't get FRAMEDONE irq\n");
3053 dispc_set_lcd_display_type(OMAP_DSS_LCD_DISPLAY_TFT
);
3055 dispc_set_parallel_interface_mode(OMAP_DSS_PARALLELMODE_DSI
);
3056 dispc_enable_fifohandcheck(1);
3058 dispc_set_tft_data_lines(dssdev
->ctrl
.pixel_size
);
3061 struct omap_video_timings timings
= {
3070 dispc_set_lcd_timings(&timings
);
3076 static void dsi_display_uninit_dispc(struct omap_dss_device
*dssdev
)
3078 omap_dispc_unregister_isr(dsi_framedone_irq_callback
, NULL
,
3079 DISPC_IRQ_FRAMEDONE
);
3082 static int dsi_configure_dsi_clocks(struct omap_dss_device
*dssdev
)
3084 struct dsi_clock_info cinfo
;
3087 /* we always use DSS2_FCK as input clock */
3088 cinfo
.use_dss2_fck
= true;
3089 cinfo
.regn
= dssdev
->phy
.dsi
.div
.regn
;
3090 cinfo
.regm
= dssdev
->phy
.dsi
.div
.regm
;
3091 cinfo
.regm3
= dssdev
->phy
.dsi
.div
.regm3
;
3092 cinfo
.regm4
= dssdev
->phy
.dsi
.div
.regm4
;
3093 r
= dsi_calc_clock_rates(&cinfo
);
3097 r
= dsi_pll_set_clock_div(&cinfo
);
3099 DSSERR("Failed to set dsi clocks\n");
3106 static int dsi_configure_dispc_clocks(struct omap_dss_device
*dssdev
)
3108 struct dispc_clock_info dispc_cinfo
;
3110 unsigned long long fck
;
3112 fck
= dsi_get_dsi1_pll_rate();
3114 dispc_cinfo
.lck_div
= dssdev
->phy
.dsi
.div
.lck_div
;
3115 dispc_cinfo
.pck_div
= dssdev
->phy
.dsi
.div
.pck_div
;
3117 r
= dispc_calc_clock_rates(fck
, &dispc_cinfo
);
3119 DSSERR("Failed to calc dispc clocks\n");
3123 r
= dispc_set_clock_div(&dispc_cinfo
);
3125 DSSERR("Failed to set dispc clocks\n");
3132 static int dsi_display_init_dsi(struct omap_dss_device
*dssdev
)
3136 _dsi_print_reset_status();
3138 r
= dsi_pll_init(dssdev
, true, true);
3142 r
= dsi_configure_dsi_clocks(dssdev
);
3146 dss_select_dispc_clk_source(DSS_SRC_DSI1_PLL_FCLK
);
3147 dss_select_dsi_clk_source(DSS_SRC_DSI2_PLL_FCLK
);
3151 r
= dsi_configure_dispc_clocks(dssdev
);
3155 r
= dsi_complexio_init(dssdev
);
3159 _dsi_print_reset_status();
3161 dsi_proto_timings(dssdev
);
3162 dsi_set_lp_clk_divisor(dssdev
);
3165 _dsi_print_reset_status();
3167 r
= dsi_proto_config(dssdev
);
3171 /* enable interface */
3172 dsi_vc_enable(0, 1);
3173 dsi_vc_enable(1, 1);
3174 dsi_vc_enable(2, 1);
3175 dsi_vc_enable(3, 1);
3177 dsi_force_tx_stop_mode_io();
3179 if (dssdev
->driver
->enable
) {
3180 r
= dssdev
->driver
->enable(dssdev
);
3185 /* enable high-speed after initial config */
3186 omapdss_dsi_vc_enable_hs(0, 1);
3192 dsi_complexio_uninit();
3194 dss_select_dispc_clk_source(DSS_SRC_DSS1_ALWON_FCLK
);
3195 dss_select_dsi_clk_source(DSS_SRC_DSS1_ALWON_FCLK
);
3202 static void dsi_display_uninit_dsi(struct omap_dss_device
*dssdev
)
3204 if (dssdev
->driver
->disable
)
3205 dssdev
->driver
->disable(dssdev
);
3207 dss_select_dispc_clk_source(DSS_SRC_DSS1_ALWON_FCLK
);
3208 dss_select_dsi_clk_source(DSS_SRC_DSS1_ALWON_FCLK
);
3209 dsi_complexio_uninit();
3213 static int dsi_core_init(void)
3216 REG_FLD_MOD(DSI_SYSCONFIG
, 1, 0, 0);
3219 REG_FLD_MOD(DSI_SYSCONFIG
, 1, 2, 2);
3221 /* SIDLEMODE smart-idle */
3222 REG_FLD_MOD(DSI_SYSCONFIG
, 2, 4, 3);
3224 _dsi_initialize_irq();
3229 static int dsi_display_enable(struct omap_dss_device
*dssdev
)
3233 DSSDBG("dsi_display_enable\n");
3235 mutex_lock(&dsi
.lock
);
3238 r
= omap_dss_start_device(dssdev
);
3240 DSSERR("failed to start device\n");
3244 if (dssdev
->state
!= OMAP_DSS_DISPLAY_DISABLED
) {
3245 DSSERR("dssdev already enabled\n");
3251 dsi_enable_pll_clock(1);
3259 r
= dsi_display_init_dispc(dssdev
);
3263 r
= dsi_display_init_dsi(dssdev
);
3267 dssdev
->state
= OMAP_DSS_DISPLAY_ACTIVE
;
3269 dsi
.use_ext_te
= dssdev
->phy
.dsi
.ext_te
;
3270 r
= dsi_set_te(dssdev
, dsi
.te_enabled
);
3274 dsi_set_update_mode(dssdev
, dsi
.user_update_mode
);
3277 mutex_unlock(&dsi
.lock
);
3283 dsi_display_uninit_dsi(dssdev
);
3285 dsi_display_uninit_dispc(dssdev
);
3288 dsi_enable_pll_clock(0);
3290 omap_dss_stop_device(dssdev
);
3293 mutex_unlock(&dsi
.lock
);
3294 DSSDBG("dsi_display_enable FAILED\n");
3298 static void dsi_display_disable(struct omap_dss_device
*dssdev
)
3300 DSSDBG("dsi_display_disable\n");
3302 mutex_lock(&dsi
.lock
);
3305 if (dssdev
->state
== OMAP_DSS_DISPLAY_DISABLED
||
3306 dssdev
->state
== OMAP_DSS_DISPLAY_SUSPENDED
)
3309 dsi
.update_mode
= OMAP_DSS_UPDATE_DISABLED
;
3310 dssdev
->state
= OMAP_DSS_DISPLAY_DISABLED
;
3312 dsi_display_uninit_dispc(dssdev
);
3314 dsi_display_uninit_dsi(dssdev
);
3317 dsi_enable_pll_clock(0);
3319 omap_dss_stop_device(dssdev
);
3322 mutex_unlock(&dsi
.lock
);
3325 static int dsi_display_suspend(struct omap_dss_device
*dssdev
)
3327 DSSDBG("dsi_display_suspend\n");
3329 mutex_lock(&dsi
.lock
);
3332 if (dssdev
->state
== OMAP_DSS_DISPLAY_DISABLED
||
3333 dssdev
->state
== OMAP_DSS_DISPLAY_SUSPENDED
)
3336 dsi
.update_mode
= OMAP_DSS_UPDATE_DISABLED
;
3337 dssdev
->state
= OMAP_DSS_DISPLAY_SUSPENDED
;
3339 dsi_display_uninit_dispc(dssdev
);
3341 dsi_display_uninit_dsi(dssdev
);
3344 dsi_enable_pll_clock(0);
3347 mutex_unlock(&dsi
.lock
);
3352 static int dsi_display_resume(struct omap_dss_device
*dssdev
)
3356 DSSDBG("dsi_display_resume\n");
3358 mutex_lock(&dsi
.lock
);
3361 if (dssdev
->state
!= OMAP_DSS_DISPLAY_SUSPENDED
) {
3362 DSSERR("dssdev not suspended\n");
3368 dsi_enable_pll_clock(1);
3376 r
= dsi_display_init_dispc(dssdev
);
3380 r
= dsi_display_init_dsi(dssdev
);
3384 dssdev
->state
= OMAP_DSS_DISPLAY_ACTIVE
;
3386 r
= dsi_set_te(dssdev
, dsi
.te_enabled
);
3390 dsi_set_update_mode(dssdev
, dsi
.user_update_mode
);
3393 mutex_unlock(&dsi
.lock
);
3398 dsi_display_uninit_dispc(dssdev
);
3401 dsi_enable_pll_clock(0);
3404 mutex_unlock(&dsi
.lock
);
3405 DSSDBG("dsi_display_resume FAILED\n");
3409 static int dsi_display_update(struct omap_dss_device
*dssdev
,
3410 u16 x
, u16 y
, u16 w
, u16 h
)
3415 DSSDBG("dsi_display_update(%d,%d %dx%d)\n", x
, y
, w
, h
);
3417 mutex_lock(&dsi
.lock
);
3419 if (dsi
.update_mode
!= OMAP_DSS_UPDATE_MANUAL
)
3422 if (dssdev
->state
!= OMAP_DSS_DISPLAY_ACTIVE
)
3425 dssdev
->get_resolution(dssdev
, &dw
, &dh
);
3427 if (x
> dw
|| y
> dh
)
3436 if (w
== 0 || h
== 0)
3444 dsi_set_update_region(dssdev
, x
, y
, w
, h
);
3446 wake_up(&dsi
.waitqueue
);
3449 mutex_unlock(&dsi
.lock
);
3454 static int dsi_display_sync(struct omap_dss_device
*dssdev
)
3458 DSSDBG("dsi_display_sync()\n");
3460 mutex_lock(&dsi
.lock
);
3463 if (dsi
.update_mode
== OMAP_DSS_UPDATE_MANUAL
&&
3464 dsi
.update_region
.dirty
) {
3465 INIT_COMPLETION(dsi
.update_completion
);
3472 mutex_unlock(&dsi
.lock
);
3475 wait_for_completion_interruptible(&dsi
.update_completion
);
3477 DSSDBG("dsi_display_sync() done\n");
3481 static int dsi_display_set_update_mode(struct omap_dss_device
*dssdev
,
3482 enum omap_dss_update_mode mode
)
3486 DSSDBGF("%d", mode
);
3488 mutex_lock(&dsi
.lock
);
3491 dsi
.user_update_mode
= mode
;
3492 r
= dsi_set_update_mode(dssdev
, mode
);
3495 mutex_unlock(&dsi
.lock
);
3500 static enum omap_dss_update_mode
dsi_display_get_update_mode(
3501 struct omap_dss_device
*dssdev
)
3503 return dsi
.update_mode
;
3507 static int dsi_display_enable_te(struct omap_dss_device
*dssdev
, bool enable
)
3511 DSSDBGF("%d", enable
);
3513 if (!dssdev
->driver
->enable_te
)
3518 dsi
.te_enabled
= enable
;
3520 if (dssdev
->state
!= OMAP_DSS_DISPLAY_ACTIVE
)
3523 r
= dsi_set_te(dssdev
, enable
);
3530 static int dsi_display_get_te(struct omap_dss_device
*dssdev
)
3532 return dsi
.te_enabled
;
3535 static int dsi_display_set_rotate(struct omap_dss_device
*dssdev
, u8 rotate
)
3538 DSSDBGF("%d", rotate
);
3540 if (!dssdev
->driver
->set_rotate
|| !dssdev
->driver
->get_rotate
)
3544 dssdev
->driver
->set_rotate(dssdev
, rotate
);
3545 if (dsi
.update_mode
== OMAP_DSS_UPDATE_AUTO
) {
3547 /* the display dimensions may have changed, so set a new
3549 dssdev
->get_resolution(dssdev
, &w
, &h
);
3550 dsi_set_update_region(dssdev
, 0, 0, w
, h
);
3557 static u8
dsi_display_get_rotate(struct omap_dss_device
*dssdev
)
3559 if (!dssdev
->driver
->set_rotate
|| !dssdev
->driver
->get_rotate
)
3562 return dssdev
->driver
->get_rotate(dssdev
);
3565 static int dsi_display_set_mirror(struct omap_dss_device
*dssdev
, bool mirror
)
3567 DSSDBGF("%d", mirror
);
3569 if (!dssdev
->driver
->set_mirror
|| !dssdev
->driver
->get_mirror
)
3573 dssdev
->driver
->set_mirror(dssdev
, mirror
);
3579 static bool dsi_display_get_mirror(struct omap_dss_device
*dssdev
)
3581 if (!dssdev
->driver
->set_mirror
|| !dssdev
->driver
->get_mirror
)
3584 return dssdev
->driver
->get_mirror(dssdev
);
3587 static int dsi_display_memory_read(struct omap_dss_device
*dssdev
,
3588 void *buf
, size_t size
,
3589 u16 x
, u16 y
, u16 w
, u16 h
)
3595 if (!dssdev
->driver
->memory_read
)
3598 if (dssdev
->state
!= OMAP_DSS_DISPLAY_ACTIVE
)
3603 r
= dssdev
->driver
->memory_read(dssdev
, buf
, size
,
3606 /* Memory read usually changes the update area. This will
3607 * force the next update to re-set the update area */
3608 dsi
.active_update_region
.dirty
= true;
3615 void dsi_get_overlay_fifo_thresholds(enum omap_plane plane
,
3616 u32 fifo_size
, enum omap_burst_size
*burst_size
,
3617 u32
*fifo_low
, u32
*fifo_high
)
3619 unsigned burst_size_bytes
;
3621 *burst_size
= OMAP_DSS_BURST_16x32
;
3622 burst_size_bytes
= 16 * 32 / 8;
3624 *fifo_high
= fifo_size
- burst_size_bytes
;
3625 *fifo_low
= fifo_size
- burst_size_bytes
* 8;
3628 int dsi_init_display(struct omap_dss_device
*dssdev
)
3630 DSSDBG("DSI init\n");
3632 dssdev
->enable
= dsi_display_enable
;
3633 dssdev
->disable
= dsi_display_disable
;
3634 dssdev
->suspend
= dsi_display_suspend
;
3635 dssdev
->resume
= dsi_display_resume
;
3636 dssdev
->update
= dsi_display_update
;
3637 dssdev
->sync
= dsi_display_sync
;
3638 dssdev
->set_update_mode
= dsi_display_set_update_mode
;
3639 dssdev
->get_update_mode
= dsi_display_get_update_mode
;
3640 dssdev
->enable_te
= dsi_display_enable_te
;
3641 dssdev
->get_te
= dsi_display_get_te
;
3643 dssdev
->get_rotate
= dsi_display_get_rotate
;
3644 dssdev
->set_rotate
= dsi_display_set_rotate
;
3646 dssdev
->get_mirror
= dsi_display_get_mirror
;
3647 dssdev
->set_mirror
= dsi_display_set_mirror
;
3649 dssdev
->memory_read
= dsi_display_memory_read
;
3651 /* XXX these should be figured out dynamically */
3652 dssdev
->caps
= OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE
|
3653 OMAP_DSS_DISPLAY_CAP_TEAR_ELIM
;
3655 dsi
.vc
[0].dssdev
= dssdev
;
3656 dsi
.vc
[1].dssdev
= dssdev
;
3661 int dsi_init(struct platform_device
*pdev
)
3665 struct sched_param param
= {
3666 .sched_priority
= MAX_USER_RT_PRIO
-1
3669 spin_lock_init(&dsi
.errors_lock
);
3672 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
3673 spin_lock_init(&dsi
.irq_stats_lock
);
3674 dsi
.irq_stats
.last_reset
= jiffies
;
3677 init_completion(&dsi
.bta_completion
);
3678 init_completion(&dsi
.update_completion
);
3680 dsi
.thread
= kthread_create(dsi_update_thread
, NULL
, "dsi");
3681 if (IS_ERR(dsi
.thread
)) {
3682 DSSERR("cannot create kthread\n");
3683 r
= PTR_ERR(dsi
.thread
);
3686 sched_setscheduler(dsi
.thread
, SCHED_FIFO
, ¶m
);
3688 init_waitqueue_head(&dsi
.waitqueue
);
3689 spin_lock_init(&dsi
.update_lock
);
3691 mutex_init(&dsi
.lock
);
3692 sema_init(&dsi
.bus_lock
, 1);
3694 #ifdef DSI_CATCH_MISSING_TE
3695 init_timer(&dsi
.te_timer
);
3696 dsi
.te_timer
.function
= dsi_te_timeout
;
3697 dsi
.te_timer
.data
= 0;
3700 dsi
.update_mode
= OMAP_DSS_UPDATE_DISABLED
;
3701 dsi
.user_update_mode
= OMAP_DSS_UPDATE_DISABLED
;
3703 dsi
.base
= ioremap(DSI_BASE
, DSI_SZ_REGS
);
3705 DSSERR("can't ioremap DSI\n");
3710 dsi
.vdds_dsi_reg
= dss_get_vdds_dsi();
3711 if (IS_ERR(dsi
.vdds_dsi_reg
)) {
3713 DSSERR("can't get VDDS_DSI regulator\n");
3714 r
= PTR_ERR(dsi
.vdds_dsi_reg
);
3720 rev
= dsi_read_reg(DSI_REVISION
);
3721 printk(KERN_INFO
"OMAP DSI rev %d.%d\n",
3722 FLD_GET(rev
, 7, 4), FLD_GET(rev
, 3, 0));
3726 wake_up_process(dsi
.thread
);
3732 kthread_stop(dsi
.thread
);
3739 kthread_stop(dsi
.thread
);
3743 DSSDBG("omap_dsi_exit\n");