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/wait.h>
35 #include <linux/workqueue.h>
37 #include <plat/display.h>
38 #include <plat/clock.h>
41 #include "dss_features.h"
43 /*#define VERBOSE_IRQ*/
44 #define DSI_CATCH_MISSING_TE
46 struct dsi_reg { u16 idx; };
48 #define DSI_REG(idx) ((const struct dsi_reg) { idx })
50 #define DSI_SZ_REGS SZ_1K
51 /* DSI Protocol Engine */
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))
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)
94 /* DSI_PLL_CTRL_SCP */
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)
102 #define REG_GET(idx, start, end) \
103 FLD_GET(dsi_read_reg(idx), start, end)
105 #define REG_FLD_MOD(idx, val, start, end) \
106 dsi_write_reg(idx, FLD_MOD(dsi_read_reg(idx), val, start, end))
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 | \
129 #define DSI_IRQ_CHANNEL_MASK 0xf
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)
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 #define DSI_CIO_IRQ_ERROR_MASK \
168 (DSI_CIO_IRQ_ERRSYNCESC1 | DSI_CIO_IRQ_ERRSYNCESC2 | \
169 DSI_CIO_IRQ_ERRSYNCESC3 | DSI_CIO_IRQ_ERRESC1 | DSI_CIO_IRQ_ERRESC2 | \
170 DSI_CIO_IRQ_ERRESC3 | DSI_CIO_IRQ_ERRCONTROL1 | \
171 DSI_CIO_IRQ_ERRCONTROL2 | DSI_CIO_IRQ_ERRCONTROL3 | \
172 DSI_CIO_IRQ_ERRCONTENTIONLP0_1 | DSI_CIO_IRQ_ERRCONTENTIONLP1_1 | \
173 DSI_CIO_IRQ_ERRCONTENTIONLP0_2 | DSI_CIO_IRQ_ERRCONTENTIONLP1_2 | \
174 DSI_CIO_IRQ_ERRCONTENTIONLP0_3 | DSI_CIO_IRQ_ERRCONTENTIONLP1_3)
176 #define DSI_DT_DCS_SHORT_WRITE_0 0x05
177 #define DSI_DT_DCS_SHORT_WRITE_1 0x15
178 #define DSI_DT_DCS_READ 0x06
179 #define DSI_DT_SET_MAX_RET_PKG_SIZE 0x37
180 #define DSI_DT_NULL_PACKET 0x09
181 #define DSI_DT_DCS_LONG_WRITE 0x39
183 #define DSI_DT_RX_ACK_WITH_ERR 0x02
184 #define DSI_DT_RX_DCS_LONG_READ 0x1c
185 #define DSI_DT_RX_SHORT_READ_1 0x21
186 #define DSI_DT_RX_SHORT_READ_2 0x22
190 DSI_FIFO_SIZE_32 = 1,
191 DSI_FIFO_SIZE_64 = 2,
192 DSI_FIFO_SIZE_96 = 3,
193 DSI_FIFO_SIZE_128 = 4,
201 struct dsi_update_region {
203 struct omap_dss_device *device;
206 struct dsi_irq_stats {
207 unsigned long last_reset;
209 unsigned dsi_irqs[32];
210 unsigned vc_irqs[4][32];
211 unsigned cio_irqs[32];
216 struct platform_device *pdev;
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;
232 struct semaphore bus_lock;
236 struct completion bta_completion;
237 void (*bta_callback)(void);
240 struct dsi_update_region update_region;
244 struct workqueue_struct *workqueue;
246 void (*framedone_callback)(int, void *);
247 void *framedone_data;
249 struct delayed_work framedone_timeout_work;
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;
272 /* DSI PLL Parameter Ranges */
273 unsigned long regm_max, regn_max;
274 unsigned long regm_dispc_max, regm_dsi_max;
275 unsigned long fint_min, fint_max;
276 unsigned long lpdiv_max;
280 static unsigned int dsi_perf;
281 module_param_named(dsi_perf, dsi_perf, bool, 0644);
284 static inline void dsi_write_reg(const struct dsi_reg idx, u32 val)
286 __raw_writel(val, dsi.base + idx.idx);
289 static inline u32 dsi_read_reg(const struct dsi_reg idx)
291 return __raw_readl(dsi.base + idx.idx);
295 void dsi_save_context(void)
299 void dsi_restore_context(void)
303 void dsi_bus_lock(void)
307 EXPORT_SYMBOL(dsi_bus_lock);
309 void dsi_bus_unlock(void)
313 EXPORT_SYMBOL(dsi_bus_unlock);
315 static bool dsi_bus_is_locked(void)
317 return dsi.bus_lock.count == 0;
320 static inline int wait_for_bit_change(const struct dsi_reg idx, int bitnum,
325 while (REG_GET(idx, bitnum, bitnum) != value) {
334 static void dsi_perf_mark_setup(void)
336 dsi.perf_setup_time = ktime_get();
339 static void dsi_perf_mark_start(void)
341 dsi.perf_start_time = ktime_get();
344 static void dsi_perf_show(const char *name)
346 ktime_t t, setup_time, trans_time;
348 u32 setup_us, trans_us, total_us;
355 setup_time = ktime_sub(dsi.perf_start_time, dsi.perf_setup_time);
356 setup_us = (u32)ktime_to_us(setup_time);
360 trans_time = ktime_sub(t, dsi.perf_start_time);
361 trans_us = (u32)ktime_to_us(trans_time);
365 total_us = setup_us + trans_us;
367 total_bytes = dsi.update_region.w *
368 dsi.update_region.h *
369 dsi.update_region.device->ctrl.pixel_size / 8;
371 printk(KERN_INFO "DSI(%s): %u us + %u us = %u us (%uHz), "
372 "%u bytes, %u kbytes/sec\n",
377 1000*1000 / total_us,
379 total_bytes * 1000 / total_us);
382 #define dsi_perf_mark_setup()
383 #define dsi_perf_mark_start()
384 #define dsi_perf_show(x)
387 static void print_irq_status(u32 status)
390 if ((status & ~DSI_IRQ_CHANNEL_MASK) == 0)
393 printk(KERN_DEBUG "DSI IRQ: 0x%x: ", status);
396 if (status & DSI_IRQ_##x) \
422 static void print_irq_status_vc(int channel, u32 status)
425 if ((status & ~DSI_VC_IRQ_PACKET_SENT) == 0)
428 printk(KERN_DEBUG "DSI VC(%d) IRQ 0x%x: ", channel, status);
431 if (status & DSI_VC_IRQ_##x) \
448 static void print_irq_status_cio(u32 status)
450 printk(KERN_DEBUG "DSI CIO IRQ 0x%x: ", status);
453 if (status & DSI_CIO_IRQ_##x) \
467 PIS(ERRCONTENTIONLP0_1);
468 PIS(ERRCONTENTIONLP1_1);
469 PIS(ERRCONTENTIONLP0_2);
470 PIS(ERRCONTENTIONLP1_2);
471 PIS(ERRCONTENTIONLP0_3);
472 PIS(ERRCONTENTIONLP1_3);
473 PIS(ULPSACTIVENOT_ALL0);
474 PIS(ULPSACTIVENOT_ALL1);
480 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
481 static void dsi_collect_irq_stats(u32 irqstatus, u32 *vcstatus, u32 ciostatus)
485 spin_lock(&dsi.irq_stats_lock);
487 dsi.irq_stats.irq_count++;
488 dss_collect_irq_stats(irqstatus, dsi.irq_stats.dsi_irqs);
490 for (i = 0; i < 4; ++i)
491 dss_collect_irq_stats(vcstatus[i], dsi.irq_stats.vc_irqs[i]);
493 dss_collect_irq_stats(ciostatus, dsi.irq_stats.cio_irqs);
495 spin_unlock(&dsi.irq_stats_lock);
498 #define dsi_collect_irq_stats(irqstatus, vcstatus, ciostatus)
501 static int debug_irq;
503 static void dsi_handle_irq_errors(u32 irqstatus, u32 *vcstatus, u32 ciostatus)
507 if (irqstatus & DSI_IRQ_ERROR_MASK) {
508 DSSERR("DSI error, irqstatus %x\n", irqstatus);
509 print_irq_status(irqstatus);
510 spin_lock(&dsi.errors_lock);
511 dsi.errors |= irqstatus & DSI_IRQ_ERROR_MASK;
512 spin_unlock(&dsi.errors_lock);
513 } else if (debug_irq) {
514 print_irq_status(irqstatus);
517 for (i = 0; i < 4; ++i) {
518 if (vcstatus[i] & DSI_VC_IRQ_ERROR_MASK) {
519 DSSERR("DSI VC(%d) error, vc irqstatus %x\n",
521 print_irq_status_vc(i, vcstatus[i]);
522 } else if (debug_irq) {
523 print_irq_status_vc(i, vcstatus[i]);
527 if (ciostatus & DSI_CIO_IRQ_ERROR_MASK) {
528 DSSERR("DSI CIO error, cio irqstatus %x\n", ciostatus);
529 print_irq_status_cio(ciostatus);
530 } else if (debug_irq) {
531 print_irq_status_cio(ciostatus);
535 static irqreturn_t omap_dsi_irq_handler(int irq, void *arg)
537 u32 irqstatus, vcstatus[4], ciostatus;
540 irqstatus = dsi_read_reg(DSI_IRQSTATUS);
542 /* IRQ is not for us */
546 dsi_write_reg(DSI_IRQSTATUS, irqstatus & ~DSI_IRQ_CHANNEL_MASK);
547 /* flush posted write */
548 dsi_read_reg(DSI_IRQSTATUS);
550 for (i = 0; i < 4; ++i) {
551 if ((irqstatus & (1 << i)) == 0) {
556 vcstatus[i] = dsi_read_reg(DSI_VC_IRQSTATUS(i));
558 dsi_write_reg(DSI_VC_IRQSTATUS(i), vcstatus[i]);
559 /* flush posted write */
560 dsi_read_reg(DSI_VC_IRQSTATUS(i));
563 if (irqstatus & DSI_IRQ_COMPLEXIO_ERR) {
564 ciostatus = dsi_read_reg(DSI_COMPLEXIO_IRQ_STATUS);
566 dsi_write_reg(DSI_COMPLEXIO_IRQ_STATUS, ciostatus);
567 /* flush posted write */
568 dsi_read_reg(DSI_COMPLEXIO_IRQ_STATUS);
573 #ifdef DSI_CATCH_MISSING_TE
574 if (irqstatus & DSI_IRQ_TE_TRIGGER)
575 del_timer(&dsi.te_timer);
578 for (i = 0; i < 4; ++i) {
579 if (vcstatus[i] == 0)
582 if (vcstatus[i] & DSI_VC_IRQ_BTA) {
583 complete(&dsi.bta_completion);
585 if (dsi.bta_callback)
590 dsi_handle_irq_errors(irqstatus, vcstatus, ciostatus);
592 dsi_collect_irq_stats(irqstatus, vcstatus, ciostatus);
597 static void _dsi_initialize_irq(void)
602 /* disable all interrupts */
603 dsi_write_reg(DSI_IRQENABLE, 0);
604 for (i = 0; i < 4; ++i)
605 dsi_write_reg(DSI_VC_IRQENABLE(i), 0);
606 dsi_write_reg(DSI_COMPLEXIO_IRQ_ENABLE, 0);
608 /* clear interrupt status */
609 l = dsi_read_reg(DSI_IRQSTATUS);
610 dsi_write_reg(DSI_IRQSTATUS, l & ~DSI_IRQ_CHANNEL_MASK);
612 for (i = 0; i < 4; ++i) {
613 l = dsi_read_reg(DSI_VC_IRQSTATUS(i));
614 dsi_write_reg(DSI_VC_IRQSTATUS(i), l);
617 l = dsi_read_reg(DSI_COMPLEXIO_IRQ_STATUS);
618 dsi_write_reg(DSI_COMPLEXIO_IRQ_STATUS, l);
620 /* enable error irqs */
621 l = DSI_IRQ_ERROR_MASK;
622 #ifdef DSI_CATCH_MISSING_TE
623 l |= DSI_IRQ_TE_TRIGGER;
625 dsi_write_reg(DSI_IRQENABLE, l);
627 l = DSI_VC_IRQ_ERROR_MASK;
628 for (i = 0; i < 4; ++i)
629 dsi_write_reg(DSI_VC_IRQENABLE(i), l);
631 l = DSI_CIO_IRQ_ERROR_MASK;
632 dsi_write_reg(DSI_COMPLEXIO_IRQ_ENABLE, l);
635 static u32 dsi_get_errors(void)
639 spin_lock_irqsave(&dsi.errors_lock, flags);
642 spin_unlock_irqrestore(&dsi.errors_lock, flags);
646 static void dsi_vc_enable_bta_irq(int channel)
650 dsi_write_reg(DSI_VC_IRQSTATUS(channel), DSI_VC_IRQ_BTA);
652 l = dsi_read_reg(DSI_VC_IRQENABLE(channel));
654 dsi_write_reg(DSI_VC_IRQENABLE(channel), l);
657 static void dsi_vc_disable_bta_irq(int channel)
661 l = dsi_read_reg(DSI_VC_IRQENABLE(channel));
662 l &= ~DSI_VC_IRQ_BTA;
663 dsi_write_reg(DSI_VC_IRQENABLE(channel), l);
666 /* DSI func clock. this could also be dsi_pll_hsdiv_dsi_clk */
667 static inline void enable_clocks(bool enable)
670 dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK);
672 dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK);
675 /* source clock for DSI PLL. this could also be PCLKFREE */
676 static inline void dsi_enable_pll_clock(bool enable)
679 dss_clk_enable(DSS_CLK_SYSCK);
681 dss_clk_disable(DSS_CLK_SYSCK);
683 if (enable && dsi.pll_locked) {
684 if (wait_for_bit_change(DSI_PLL_STATUS, 1, 1) != 1)
685 DSSERR("cannot lock PLL when enabling clocks\n");
690 static void _dsi_print_reset_status(void)
697 /* A dummy read using the SCP interface to any DSIPHY register is
698 * required after DSIPHY reset to complete the reset of the DSI complex
700 l = dsi_read_reg(DSI_DSIPHY_CFG5);
702 printk(KERN_DEBUG "DSI resets: ");
704 l = dsi_read_reg(DSI_PLL_STATUS);
705 printk("PLL (%d) ", FLD_GET(l, 0, 0));
707 l = dsi_read_reg(DSI_COMPLEXIO_CFG1);
708 printk("CIO (%d) ", FLD_GET(l, 29, 29));
710 l = dsi_read_reg(DSI_DSIPHY_CFG5);
711 printk("PHY (%x, %d, %d, %d)\n",
718 #define _dsi_print_reset_status()
721 static inline int dsi_if_enable(bool enable)
723 DSSDBG("dsi_if_enable(%d)\n", enable);
725 enable = enable ? 1 : 0;
726 REG_FLD_MOD(DSI_CTRL, enable, 0, 0); /* IF_EN */
728 if (wait_for_bit_change(DSI_CTRL, 0, enable) != enable) {
729 DSSERR("Failed to set dsi_if_enable to %d\n", enable);
736 unsigned long dsi_get_pll_hsdiv_dispc_rate(void)
738 return dsi.current_cinfo.dsi_pll_hsdiv_dispc_clk;
741 static unsigned long dsi_get_pll_hsdiv_dsi_rate(void)
743 return dsi.current_cinfo.dsi_pll_hsdiv_dsi_clk;
746 static unsigned long dsi_get_txbyteclkhs(void)
748 return dsi.current_cinfo.clkin4ddr / 16;
751 static unsigned long dsi_fclk_rate(void)
755 if (dss_get_dsi_clk_source() == DSS_CLK_SRC_FCK) {
756 /* DSI FCLK source is DSS_CLK_FCK */
757 r = dss_clk_get_rate(DSS_CLK_FCK);
759 /* DSI FCLK source is dsi_pll_hsdiv_dsi_clk */
760 r = dsi_get_pll_hsdiv_dsi_rate();
766 static int dsi_set_lp_clk_divisor(struct omap_dss_device *dssdev)
768 unsigned long dsi_fclk;
770 unsigned long lp_clk;
772 lp_clk_div = dssdev->phy.dsi.div.lp_clk_div;
774 if (lp_clk_div == 0 || lp_clk_div > dsi.lpdiv_max)
777 dsi_fclk = dsi_fclk_rate();
779 lp_clk = dsi_fclk / 2 / lp_clk_div;
781 DSSDBG("LP_CLK_DIV %u, LP_CLK %lu\n", lp_clk_div, lp_clk);
782 dsi.current_cinfo.lp_clk = lp_clk;
783 dsi.current_cinfo.lp_clk_div = lp_clk_div;
785 REG_FLD_MOD(DSI_CLK_CTRL, lp_clk_div, 12, 0); /* LP_CLK_DIVISOR */
787 REG_FLD_MOD(DSI_CLK_CTRL, dsi_fclk > 30000000 ? 1 : 0,
788 21, 21); /* LP_RX_SYNCHRO_ENABLE */
794 enum dsi_pll_power_state {
795 DSI_PLL_POWER_OFF = 0x0,
796 DSI_PLL_POWER_ON_HSCLK = 0x1,
797 DSI_PLL_POWER_ON_ALL = 0x2,
798 DSI_PLL_POWER_ON_DIV = 0x3,
801 static int dsi_pll_power(enum dsi_pll_power_state state)
805 REG_FLD_MOD(DSI_CLK_CTRL, state, 31, 30); /* PLL_PWR_CMD */
808 while (FLD_GET(dsi_read_reg(DSI_CLK_CTRL), 29, 28) != state) {
810 DSSERR("Failed to set DSI PLL power mode to %d\n",
820 /* calculate clock rates using dividers in cinfo */
821 static int dsi_calc_clock_rates(struct omap_dss_device *dssdev,
822 struct dsi_clock_info *cinfo)
824 if (cinfo->regn == 0 || cinfo->regn > dsi.regn_max)
827 if (cinfo->regm == 0 || cinfo->regm > dsi.regm_max)
830 if (cinfo->regm_dispc > dsi.regm_dispc_max)
833 if (cinfo->regm_dsi > dsi.regm_dsi_max)
836 if (cinfo->use_sys_clk) {
837 cinfo->clkin = dss_clk_get_rate(DSS_CLK_SYSCK);
838 /* XXX it is unclear if highfreq should be used
839 * with DSS_SYS_CLK source also */
842 cinfo->clkin = dispc_pclk_rate(dssdev->manager->id);
844 if (cinfo->clkin < 32000000)
850 cinfo->fint = cinfo->clkin / (cinfo->regn * (cinfo->highfreq ? 2 : 1));
852 if (cinfo->fint > dsi.fint_max || cinfo->fint < dsi.fint_min)
855 cinfo->clkin4ddr = 2 * cinfo->regm * cinfo->fint;
857 if (cinfo->clkin4ddr > 1800 * 1000 * 1000)
860 if (cinfo->regm_dispc > 0)
861 cinfo->dsi_pll_hsdiv_dispc_clk =
862 cinfo->clkin4ddr / cinfo->regm_dispc;
864 cinfo->dsi_pll_hsdiv_dispc_clk = 0;
866 if (cinfo->regm_dsi > 0)
867 cinfo->dsi_pll_hsdiv_dsi_clk =
868 cinfo->clkin4ddr / cinfo->regm_dsi;
870 cinfo->dsi_pll_hsdiv_dsi_clk = 0;
875 int dsi_pll_calc_clock_div_pck(bool is_tft, unsigned long req_pck,
876 struct dsi_clock_info *dsi_cinfo,
877 struct dispc_clock_info *dispc_cinfo)
879 struct dsi_clock_info cur, best;
880 struct dispc_clock_info best_dispc;
883 unsigned long dss_sys_clk, max_dss_fck;
885 dss_sys_clk = dss_clk_get_rate(DSS_CLK_SYSCK);
887 max_dss_fck = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK);
889 if (req_pck == dsi.cache_req_pck &&
890 dsi.cache_cinfo.clkin == dss_sys_clk) {
891 DSSDBG("DSI clock info found from cache\n");
892 *dsi_cinfo = dsi.cache_cinfo;
893 dispc_find_clk_divs(is_tft, req_pck,
894 dsi_cinfo->dsi_pll_hsdiv_dispc_clk, dispc_cinfo);
898 min_fck_per_pck = CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK;
900 if (min_fck_per_pck &&
901 req_pck * min_fck_per_pck > max_dss_fck) {
902 DSSERR("Requested pixel clock not possible with the current "
903 "OMAP2_DSS_MIN_FCK_PER_PCK setting. Turning "
904 "the constraint off.\n");
908 DSSDBG("dsi_pll_calc\n");
911 memset(&best, 0, sizeof(best));
912 memset(&best_dispc, 0, sizeof(best_dispc));
914 memset(&cur, 0, sizeof(cur));
915 cur.clkin = dss_sys_clk;
919 /* no highfreq: 0.75MHz < Fint = clkin / regn < 2.1MHz */
920 /* highfreq: 0.75MHz < Fint = clkin / (2*regn) < 2.1MHz */
921 /* To reduce PLL lock time, keep Fint high (around 2 MHz) */
922 for (cur.regn = 1; cur.regn < dsi.regn_max; ++cur.regn) {
923 if (cur.highfreq == 0)
924 cur.fint = cur.clkin / cur.regn;
926 cur.fint = cur.clkin / (2 * cur.regn);
928 if (cur.fint > dsi.fint_max || cur.fint < dsi.fint_min)
931 /* DSIPHY(MHz) = (2 * regm / regn) * (clkin / (highfreq + 1)) */
932 for (cur.regm = 1; cur.regm < dsi.regm_max; ++cur.regm) {
935 a = 2 * cur.regm * (cur.clkin/1000);
936 b = cur.regn * (cur.highfreq + 1);
937 cur.clkin4ddr = a / b * 1000;
939 if (cur.clkin4ddr > 1800 * 1000 * 1000)
942 /* dsi_pll_hsdiv_dispc_clk(MHz) =
943 * DSIPHY(MHz) / regm_dispc < 173MHz/186Mhz */
944 for (cur.regm_dispc = 1; cur.regm_dispc < dsi.regm_dispc_max;
946 struct dispc_clock_info cur_dispc;
947 cur.dsi_pll_hsdiv_dispc_clk =
948 cur.clkin4ddr / cur.regm_dispc;
950 /* this will narrow down the search a bit,
951 * but still give pixclocks below what was
953 if (cur.dsi_pll_hsdiv_dispc_clk < req_pck)
956 if (cur.dsi_pll_hsdiv_dispc_clk > max_dss_fck)
959 if (min_fck_per_pck &&
960 cur.dsi_pll_hsdiv_dispc_clk <
961 req_pck * min_fck_per_pck)
966 dispc_find_clk_divs(is_tft, req_pck,
967 cur.dsi_pll_hsdiv_dispc_clk,
970 if (abs(cur_dispc.pck - req_pck) <
971 abs(best_dispc.pck - req_pck)) {
973 best_dispc = cur_dispc;
975 if (cur_dispc.pck == req_pck)
983 if (min_fck_per_pck) {
984 DSSERR("Could not find suitable clock settings.\n"
985 "Turning FCK/PCK constraint off and"
991 DSSERR("Could not find suitable clock settings.\n");
996 /* dsi_pll_hsdiv_dsi_clk (regm_dsi) is not used */
998 best.dsi_pll_hsdiv_dsi_clk = 0;
1003 *dispc_cinfo = best_dispc;
1005 dsi.cache_req_pck = req_pck;
1006 dsi.cache_clk_freq = 0;
1007 dsi.cache_cinfo = best;
1012 int dsi_pll_set_clock_div(struct dsi_clock_info *cinfo)
1017 u8 regn_start, regn_end, regm_start, regm_end;
1018 u8 regm_dispc_start, regm_dispc_end, regm_dsi_start, regm_dsi_end;
1022 dsi.current_cinfo.fint = cinfo->fint;
1023 dsi.current_cinfo.clkin4ddr = cinfo->clkin4ddr;
1024 dsi.current_cinfo.dsi_pll_hsdiv_dispc_clk =
1025 cinfo->dsi_pll_hsdiv_dispc_clk;
1026 dsi.current_cinfo.dsi_pll_hsdiv_dsi_clk =
1027 cinfo->dsi_pll_hsdiv_dsi_clk;
1029 dsi.current_cinfo.regn = cinfo->regn;
1030 dsi.current_cinfo.regm = cinfo->regm;
1031 dsi.current_cinfo.regm_dispc = cinfo->regm_dispc;
1032 dsi.current_cinfo.regm_dsi = cinfo->regm_dsi;
1034 DSSDBG("DSI Fint %ld\n", cinfo->fint);
1036 DSSDBG("clkin (%s) rate %ld, highfreq %d\n",
1037 cinfo->use_sys_clk ? "dss_sys_clk" : "pclkfree",
1041 /* DSIPHY == CLKIN4DDR */
1042 DSSDBG("CLKIN4DDR = 2 * %d / %d * %lu / %d = %lu\n",
1046 cinfo->highfreq + 1,
1049 DSSDBG("Data rate on 1 DSI lane %ld Mbps\n",
1050 cinfo->clkin4ddr / 1000 / 1000 / 2);
1052 DSSDBG("Clock lane freq %ld Hz\n", cinfo->clkin4ddr / 4);
1054 DSSDBG("regm_dispc = %d, %s (%s) = %lu\n", cinfo->regm_dispc,
1055 dss_get_generic_clk_source_name(DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
1056 dss_feat_get_clk_source_name(DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
1057 cinfo->dsi_pll_hsdiv_dispc_clk);
1058 DSSDBG("regm_dsi = %d, %s (%s) = %lu\n", cinfo->regm_dsi,
1059 dss_get_generic_clk_source_name(DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
1060 dss_feat_get_clk_source_name(DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
1061 cinfo->dsi_pll_hsdiv_dsi_clk);
1063 dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGN, ®n_start, ®n_end);
1064 dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM, ®m_start, ®m_end);
1065 dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM_DISPC, ®m_dispc_start,
1067 dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM_DSI, ®m_dsi_start,
1070 REG_FLD_MOD(DSI_PLL_CONTROL, 0, 0, 0); /* DSI_PLL_AUTOMODE = manual */
1072 l = dsi_read_reg(DSI_PLL_CONFIGURATION1);
1073 l = FLD_MOD(l, 1, 0, 0); /* DSI_PLL_STOPMODE */
1075 l = FLD_MOD(l, cinfo->regn - 1, regn_start, regn_end);
1077 l = FLD_MOD(l, cinfo->regm, regm_start, regm_end);
1079 l = FLD_MOD(l, cinfo->regm_dispc > 0 ? cinfo->regm_dispc - 1 : 0,
1080 regm_dispc_start, regm_dispc_end);
1081 /* DSIPROTO_CLOCK_DIV */
1082 l = FLD_MOD(l, cinfo->regm_dsi > 0 ? cinfo->regm_dsi - 1 : 0,
1083 regm_dsi_start, regm_dsi_end);
1084 dsi_write_reg(DSI_PLL_CONFIGURATION1, l);
1086 BUG_ON(cinfo->fint < dsi.fint_min || cinfo->fint > dsi.fint_max);
1087 if (cinfo->fint < 1000000)
1089 else if (cinfo->fint < 1250000)
1091 else if (cinfo->fint < 1500000)
1093 else if (cinfo->fint < 1750000)
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_sys_clk ? 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);
1109 REG_FLD_MOD(DSI_PLL_GO, 1, 0, 0); /* DSI_PLL_GO */
1111 if (wait_for_bit_change(DSI_PLL_GO, 0, 0) != 0) {
1112 DSSERR("dsi pll go bit not going down.\n");
1117 if (wait_for_bit_change(DSI_PLL_STATUS, 1, 1) != 1) {
1118 DSSERR("cannot lock PLL\n");
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);
1142 DSSDBG("PLL config done\n");
1147 int dsi_pll_init(struct omap_dss_device *dssdev, bool enable_hsclk,
1151 enum dsi_pll_power_state pwstate;
1153 DSSDBG("PLL init\n");
1155 #ifdef CONFIG_OMAP2_DSS_USE_DSI_PLL
1157 * HACK: this is just a quick hack to get the USE_DSI_PLL
1158 * option working. USE_DSI_PLL is itself a big hack, and
1159 * should be removed.
1161 if (dsi.vdds_dsi_reg == NULL) {
1162 struct regulator *vdds_dsi;
1164 vdds_dsi = regulator_get(&dsi.pdev->dev, "vdds_dsi");
1166 if (IS_ERR(vdds_dsi)) {
1167 DSSERR("can't get VDDS_DSI regulator\n");
1168 return PTR_ERR(vdds_dsi);
1171 dsi.vdds_dsi_reg = vdds_dsi;
1176 dsi_enable_pll_clock(1);
1178 r = regulator_enable(dsi.vdds_dsi_reg);
1182 /* XXX PLL does not come out of reset without this... */
1183 dispc_pck_free_enable(1);
1185 if (wait_for_bit_change(DSI_PLL_STATUS, 0, 1) != 1) {
1186 DSSERR("PLL not coming out of reset.\n");
1188 dispc_pck_free_enable(0);
1192 /* XXX ... but if left on, we get problems when planes do not
1193 * fill the whole display. No idea about this */
1194 dispc_pck_free_enable(0);
1196 if (enable_hsclk && enable_hsdiv)
1197 pwstate = DSI_PLL_POWER_ON_ALL;
1198 else if (enable_hsclk)
1199 pwstate = DSI_PLL_POWER_ON_HSCLK;
1200 else if (enable_hsdiv)
1201 pwstate = DSI_PLL_POWER_ON_DIV;
1203 pwstate = DSI_PLL_POWER_OFF;
1205 r = dsi_pll_power(pwstate);
1210 DSSDBG("PLL init done\n");
1214 regulator_disable(dsi.vdds_dsi_reg);
1217 dsi_enable_pll_clock(0);
1221 void dsi_pll_uninit(void)
1224 dsi_enable_pll_clock(0);
1227 dsi_pll_power(DSI_PLL_POWER_OFF);
1228 regulator_disable(dsi.vdds_dsi_reg);
1229 DSSDBG("PLL uninit done\n");
1232 void dsi_dump_clocks(struct seq_file *s)
1235 struct dsi_clock_info *cinfo = &dsi.current_cinfo;
1236 enum dss_clk_source dispc_clk_src, dsi_clk_src;
1238 dispc_clk_src = dss_get_dispc_clk_source();
1239 dsi_clk_src = dss_get_dsi_clk_source();
1243 clksel = REG_GET(DSI_PLL_CONFIGURATION2, 11, 11);
1245 seq_printf(s, "- DSI PLL -\n");
1247 seq_printf(s, "dsi pll source = %s\n",
1249 "dss_sys_clk" : "pclkfree");
1251 seq_printf(s, "Fint\t\t%-16luregn %u\n", cinfo->fint, cinfo->regn);
1253 seq_printf(s, "CLKIN4DDR\t%-16luregm %u\n",
1254 cinfo->clkin4ddr, cinfo->regm);
1256 seq_printf(s, "%s (%s)\t%-16luregm_dispc %u\t(%s)\n",
1257 dss_get_generic_clk_source_name(dispc_clk_src),
1258 dss_feat_get_clk_source_name(dispc_clk_src),
1259 cinfo->dsi_pll_hsdiv_dispc_clk,
1261 dispc_clk_src == DSS_CLK_SRC_FCK ?
1264 seq_printf(s, "%s (%s)\t%-16luregm_dsi %u\t(%s)\n",
1265 dss_get_generic_clk_source_name(dsi_clk_src),
1266 dss_feat_get_clk_source_name(dsi_clk_src),
1267 cinfo->dsi_pll_hsdiv_dsi_clk,
1269 dsi_clk_src == DSS_CLK_SRC_FCK ?
1272 seq_printf(s, "- DSI -\n");
1274 seq_printf(s, "dsi fclk source = %s (%s)\n",
1275 dss_get_generic_clk_source_name(dsi_clk_src),
1276 dss_feat_get_clk_source_name(dsi_clk_src));
1278 seq_printf(s, "DSI_FCLK\t%lu\n", dsi_fclk_rate());
1280 seq_printf(s, "DDR_CLK\t\t%lu\n",
1281 cinfo->clkin4ddr / 4);
1283 seq_printf(s, "TxByteClkHS\t%lu\n", dsi_get_txbyteclkhs());
1285 seq_printf(s, "LP_CLK\t\t%lu\n", cinfo->lp_clk);
1287 seq_printf(s, "VP_CLK\t\t%lu\n"
1289 dispc_lclk_rate(OMAP_DSS_CHANNEL_LCD),
1290 dispc_pclk_rate(OMAP_DSS_CHANNEL_LCD));
1295 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
1296 void dsi_dump_irqs(struct seq_file *s)
1298 unsigned long flags;
1299 struct dsi_irq_stats stats;
1301 spin_lock_irqsave(&dsi.irq_stats_lock, flags);
1303 stats = dsi.irq_stats;
1304 memset(&dsi.irq_stats, 0, sizeof(dsi.irq_stats));
1305 dsi.irq_stats.last_reset = jiffies;
1307 spin_unlock_irqrestore(&dsi.irq_stats_lock, flags);
1309 seq_printf(s, "period %u ms\n",
1310 jiffies_to_msecs(jiffies - stats.last_reset));
1312 seq_printf(s, "irqs %d\n", stats.irq_count);
1314 seq_printf(s, "%-20s %10d\n", #x, stats.dsi_irqs[ffs(DSI_IRQ_##x)-1]);
1316 seq_printf(s, "-- DSI interrupts --\n");
1332 PIS(LDO_POWER_GOOD);
1337 seq_printf(s, "%-20s %10d %10d %10d %10d\n", #x, \
1338 stats.vc_irqs[0][ffs(DSI_VC_IRQ_##x)-1], \
1339 stats.vc_irqs[1][ffs(DSI_VC_IRQ_##x)-1], \
1340 stats.vc_irqs[2][ffs(DSI_VC_IRQ_##x)-1], \
1341 stats.vc_irqs[3][ffs(DSI_VC_IRQ_##x)-1]);
1343 seq_printf(s, "-- VC interrupts --\n");
1352 PIS(PP_BUSY_CHANGE);
1356 seq_printf(s, "%-20s %10d\n", #x, \
1357 stats.cio_irqs[ffs(DSI_CIO_IRQ_##x)-1]);
1359 seq_printf(s, "-- CIO interrupts --\n");
1372 PIS(ERRCONTENTIONLP0_1);
1373 PIS(ERRCONTENTIONLP1_1);
1374 PIS(ERRCONTENTIONLP0_2);
1375 PIS(ERRCONTENTIONLP1_2);
1376 PIS(ERRCONTENTIONLP0_3);
1377 PIS(ERRCONTENTIONLP1_3);
1378 PIS(ULPSACTIVENOT_ALL0);
1379 PIS(ULPSACTIVENOT_ALL1);
1384 void dsi_dump_regs(struct seq_file *s)
1386 #define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dsi_read_reg(r))
1388 dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK);
1390 DUMPREG(DSI_REVISION);
1391 DUMPREG(DSI_SYSCONFIG);
1392 DUMPREG(DSI_SYSSTATUS);
1393 DUMPREG(DSI_IRQSTATUS);
1394 DUMPREG(DSI_IRQENABLE);
1396 DUMPREG(DSI_COMPLEXIO_CFG1);
1397 DUMPREG(DSI_COMPLEXIO_IRQ_STATUS);
1398 DUMPREG(DSI_COMPLEXIO_IRQ_ENABLE);
1399 DUMPREG(DSI_CLK_CTRL);
1400 DUMPREG(DSI_TIMING1);
1401 DUMPREG(DSI_TIMING2);
1402 DUMPREG(DSI_VM_TIMING1);
1403 DUMPREG(DSI_VM_TIMING2);
1404 DUMPREG(DSI_VM_TIMING3);
1405 DUMPREG(DSI_CLK_TIMING);
1406 DUMPREG(DSI_TX_FIFO_VC_SIZE);
1407 DUMPREG(DSI_RX_FIFO_VC_SIZE);
1408 DUMPREG(DSI_COMPLEXIO_CFG2);
1409 DUMPREG(DSI_RX_FIFO_VC_FULLNESS);
1410 DUMPREG(DSI_VM_TIMING4);
1411 DUMPREG(DSI_TX_FIFO_VC_EMPTINESS);
1412 DUMPREG(DSI_VM_TIMING5);
1413 DUMPREG(DSI_VM_TIMING6);
1414 DUMPREG(DSI_VM_TIMING7);
1415 DUMPREG(DSI_STOPCLK_TIMING);
1417 DUMPREG(DSI_VC_CTRL(0));
1418 DUMPREG(DSI_VC_TE(0));
1419 DUMPREG(DSI_VC_LONG_PACKET_HEADER(0));
1420 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(0));
1421 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(0));
1422 DUMPREG(DSI_VC_IRQSTATUS(0));
1423 DUMPREG(DSI_VC_IRQENABLE(0));
1425 DUMPREG(DSI_VC_CTRL(1));
1426 DUMPREG(DSI_VC_TE(1));
1427 DUMPREG(DSI_VC_LONG_PACKET_HEADER(1));
1428 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(1));
1429 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(1));
1430 DUMPREG(DSI_VC_IRQSTATUS(1));
1431 DUMPREG(DSI_VC_IRQENABLE(1));
1433 DUMPREG(DSI_VC_CTRL(2));
1434 DUMPREG(DSI_VC_TE(2));
1435 DUMPREG(DSI_VC_LONG_PACKET_HEADER(2));
1436 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(2));
1437 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(2));
1438 DUMPREG(DSI_VC_IRQSTATUS(2));
1439 DUMPREG(DSI_VC_IRQENABLE(2));
1441 DUMPREG(DSI_VC_CTRL(3));
1442 DUMPREG(DSI_VC_TE(3));
1443 DUMPREG(DSI_VC_LONG_PACKET_HEADER(3));
1444 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(3));
1445 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(3));
1446 DUMPREG(DSI_VC_IRQSTATUS(3));
1447 DUMPREG(DSI_VC_IRQENABLE(3));
1449 DUMPREG(DSI_DSIPHY_CFG0);
1450 DUMPREG(DSI_DSIPHY_CFG1);
1451 DUMPREG(DSI_DSIPHY_CFG2);
1452 DUMPREG(DSI_DSIPHY_CFG5);
1454 DUMPREG(DSI_PLL_CONTROL);
1455 DUMPREG(DSI_PLL_STATUS);
1456 DUMPREG(DSI_PLL_GO);
1457 DUMPREG(DSI_PLL_CONFIGURATION1);
1458 DUMPREG(DSI_PLL_CONFIGURATION2);
1460 dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK);
1464 enum dsi_complexio_power_state {
1465 DSI_COMPLEXIO_POWER_OFF = 0x0,
1466 DSI_COMPLEXIO_POWER_ON = 0x1,
1467 DSI_COMPLEXIO_POWER_ULPS = 0x2,
1470 static int dsi_complexio_power(enum dsi_complexio_power_state state)
1475 REG_FLD_MOD(DSI_COMPLEXIO_CFG1, state, 28, 27);
1478 while (FLD_GET(dsi_read_reg(DSI_COMPLEXIO_CFG1), 26, 25) != state) {
1480 DSSERR("failed to set complexio power state to "
1490 static void dsi_complexio_config(struct omap_dss_device *dssdev)
1494 int clk_lane = dssdev->phy.dsi.clk_lane;
1495 int data1_lane = dssdev->phy.dsi.data1_lane;
1496 int data2_lane = dssdev->phy.dsi.data2_lane;
1497 int clk_pol = dssdev->phy.dsi.clk_pol;
1498 int data1_pol = dssdev->phy.dsi.data1_pol;
1499 int data2_pol = dssdev->phy.dsi.data2_pol;
1501 r = dsi_read_reg(DSI_COMPLEXIO_CFG1);
1502 r = FLD_MOD(r, clk_lane, 2, 0);
1503 r = FLD_MOD(r, clk_pol, 3, 3);
1504 r = FLD_MOD(r, data1_lane, 6, 4);
1505 r = FLD_MOD(r, data1_pol, 7, 7);
1506 r = FLD_MOD(r, data2_lane, 10, 8);
1507 r = FLD_MOD(r, data2_pol, 11, 11);
1508 dsi_write_reg(DSI_COMPLEXIO_CFG1, r);
1510 /* The configuration of the DSI complex I/O (number of data lanes,
1511 position, differential order) should not be changed while
1512 DSS.DSI_CLK_CRTRL[20] LP_CLK_ENABLE bit is set to 1. In order for
1513 the hardware to take into account a new configuration of the complex
1514 I/O (done in DSS.DSI_COMPLEXIO_CFG1 register), it is recommended to
1515 follow this sequence: First set the DSS.DSI_CTRL[0] IF_EN bit to 1,
1516 then reset the DSS.DSI_CTRL[0] IF_EN to 0, then set
1517 DSS.DSI_CLK_CTRL[20] LP_CLK_ENABLE to 1 and finally set again the
1518 DSS.DSI_CTRL[0] IF_EN bit to 1. If the sequence is not followed, the
1519 DSI complex I/O configuration is unknown. */
1522 REG_FLD_MOD(DSI_CTRL, 1, 0, 0);
1523 REG_FLD_MOD(DSI_CTRL, 0, 0, 0);
1524 REG_FLD_MOD(DSI_CLK_CTRL, 1, 20, 20);
1525 REG_FLD_MOD(DSI_CTRL, 1, 0, 0);
1529 static inline unsigned ns2ddr(unsigned ns)
1531 /* convert time in ns to ddr ticks, rounding up */
1532 unsigned long ddr_clk = dsi.current_cinfo.clkin4ddr / 4;
1533 return (ns * (ddr_clk / 1000 / 1000) + 999) / 1000;
1536 static inline unsigned ddr2ns(unsigned ddr)
1538 unsigned long ddr_clk = dsi.current_cinfo.clkin4ddr / 4;
1539 return ddr * 1000 * 1000 / (ddr_clk / 1000);
1542 static void dsi_complexio_timings(void)
1545 u32 ths_prepare, ths_prepare_ths_zero, ths_trail, ths_exit;
1546 u32 tlpx_half, tclk_trail, tclk_zero;
1549 /* calculate timings */
1551 /* 1 * DDR_CLK = 2 * UI */
1553 /* min 40ns + 4*UI max 85ns + 6*UI */
1554 ths_prepare = ns2ddr(70) + 2;
1556 /* min 145ns + 10*UI */
1557 ths_prepare_ths_zero = ns2ddr(175) + 2;
1559 /* min max(8*UI, 60ns+4*UI) */
1560 ths_trail = ns2ddr(60) + 5;
1563 ths_exit = ns2ddr(145);
1566 tlpx_half = ns2ddr(25);
1569 tclk_trail = ns2ddr(60) + 2;
1571 /* min 38ns, max 95ns */
1572 tclk_prepare = ns2ddr(65);
1574 /* min tclk-prepare + tclk-zero = 300ns */
1575 tclk_zero = ns2ddr(260);
1577 DSSDBG("ths_prepare %u (%uns), ths_prepare_ths_zero %u (%uns)\n",
1578 ths_prepare, ddr2ns(ths_prepare),
1579 ths_prepare_ths_zero, ddr2ns(ths_prepare_ths_zero));
1580 DSSDBG("ths_trail %u (%uns), ths_exit %u (%uns)\n",
1581 ths_trail, ddr2ns(ths_trail),
1582 ths_exit, ddr2ns(ths_exit));
1584 DSSDBG("tlpx_half %u (%uns), tclk_trail %u (%uns), "
1585 "tclk_zero %u (%uns)\n",
1586 tlpx_half, ddr2ns(tlpx_half),
1587 tclk_trail, ddr2ns(tclk_trail),
1588 tclk_zero, ddr2ns(tclk_zero));
1589 DSSDBG("tclk_prepare %u (%uns)\n",
1590 tclk_prepare, ddr2ns(tclk_prepare));
1592 /* program timings */
1594 r = dsi_read_reg(DSI_DSIPHY_CFG0);
1595 r = FLD_MOD(r, ths_prepare, 31, 24);
1596 r = FLD_MOD(r, ths_prepare_ths_zero, 23, 16);
1597 r = FLD_MOD(r, ths_trail, 15, 8);
1598 r = FLD_MOD(r, ths_exit, 7, 0);
1599 dsi_write_reg(DSI_DSIPHY_CFG0, r);
1601 r = dsi_read_reg(DSI_DSIPHY_CFG1);
1602 r = FLD_MOD(r, tlpx_half, 22, 16);
1603 r = FLD_MOD(r, tclk_trail, 15, 8);
1604 r = FLD_MOD(r, tclk_zero, 7, 0);
1605 dsi_write_reg(DSI_DSIPHY_CFG1, r);
1607 r = dsi_read_reg(DSI_DSIPHY_CFG2);
1608 r = FLD_MOD(r, tclk_prepare, 7, 0);
1609 dsi_write_reg(DSI_DSIPHY_CFG2, r);
1613 static int dsi_complexio_init(struct omap_dss_device *dssdev)
1617 DSSDBG("dsi_complexio_init\n");
1619 /* CIO_CLK_ICG, enable L3 clk to CIO */
1620 REG_FLD_MOD(DSI_CLK_CTRL, 1, 14, 14);
1622 /* A dummy read using the SCP interface to any DSIPHY register is
1623 * required after DSIPHY reset to complete the reset of the DSI complex
1625 dsi_read_reg(DSI_DSIPHY_CFG5);
1627 if (wait_for_bit_change(DSI_DSIPHY_CFG5, 30, 1) != 1) {
1628 DSSERR("ComplexIO PHY not coming out of reset.\n");
1633 dsi_complexio_config(dssdev);
1635 r = dsi_complexio_power(DSI_COMPLEXIO_POWER_ON);
1640 if (wait_for_bit_change(DSI_COMPLEXIO_CFG1, 29, 1) != 1) {
1641 DSSERR("ComplexIO not coming out of reset.\n");
1646 if (wait_for_bit_change(DSI_COMPLEXIO_CFG1, 21, 1) != 1) {
1647 DSSERR("ComplexIO LDO power down.\n");
1652 dsi_complexio_timings();
1655 The configuration of the DSI complex I/O (number of data lanes,
1656 position, differential order) should not be changed while
1657 DSS.DSI_CLK_CRTRL[20] LP_CLK_ENABLE bit is set to 1. For the
1658 hardware to recognize a new configuration of the complex I/O (done
1659 in DSS.DSI_COMPLEXIO_CFG1 register), it is recommended to follow
1660 this sequence: First set the DSS.DSI_CTRL[0] IF_EN bit to 1, next
1661 reset the DSS.DSI_CTRL[0] IF_EN to 0, then set DSS.DSI_CLK_CTRL[20]
1662 LP_CLK_ENABLE to 1, and finally, set again the DSS.DSI_CTRL[0] IF_EN
1663 bit to 1. If the sequence is not followed, the DSi complex I/O
1664 configuration is undetermined.
1668 REG_FLD_MOD(DSI_CLK_CTRL, 1, 20, 20); /* LP_CLK_ENABLE */
1672 DSSDBG("CIO init done\n");
1677 static void dsi_complexio_uninit(void)
1679 dsi_complexio_power(DSI_COMPLEXIO_POWER_OFF);
1682 static int _dsi_wait_reset(void)
1686 while (REG_GET(DSI_SYSSTATUS, 0, 0) == 0) {
1688 DSSERR("soft reset failed\n");
1697 static int _dsi_reset(void)
1700 REG_FLD_MOD(DSI_SYSCONFIG, 1, 1, 1);
1701 return _dsi_wait_reset();
1704 static void dsi_config_tx_fifo(enum fifo_size size1, enum fifo_size size2,
1705 enum fifo_size size3, enum fifo_size size4)
1711 dsi.vc[0].fifo_size = size1;
1712 dsi.vc[1].fifo_size = size2;
1713 dsi.vc[2].fifo_size = size3;
1714 dsi.vc[3].fifo_size = size4;
1716 for (i = 0; i < 4; i++) {
1718 int size = dsi.vc[i].fifo_size;
1720 if (add + size > 4) {
1721 DSSERR("Illegal FIFO configuration\n");
1725 v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
1727 /*DSSDBG("TX FIFO vc %d: size %d, add %d\n", i, size, add); */
1731 dsi_write_reg(DSI_TX_FIFO_VC_SIZE, r);
1734 static void dsi_config_rx_fifo(enum fifo_size size1, enum fifo_size size2,
1735 enum fifo_size size3, enum fifo_size size4)
1741 dsi.vc[0].fifo_size = size1;
1742 dsi.vc[1].fifo_size = size2;
1743 dsi.vc[2].fifo_size = size3;
1744 dsi.vc[3].fifo_size = size4;
1746 for (i = 0; i < 4; i++) {
1748 int size = dsi.vc[i].fifo_size;
1750 if (add + size > 4) {
1751 DSSERR("Illegal FIFO configuration\n");
1755 v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
1757 /*DSSDBG("RX FIFO vc %d: size %d, add %d\n", i, size, add); */
1761 dsi_write_reg(DSI_RX_FIFO_VC_SIZE, r);
1764 static int dsi_force_tx_stop_mode_io(void)
1768 r = dsi_read_reg(DSI_TIMING1);
1769 r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
1770 dsi_write_reg(DSI_TIMING1, r);
1772 if (wait_for_bit_change(DSI_TIMING1, 15, 0) != 0) {
1773 DSSERR("TX_STOP bit not going down\n");
1780 static int dsi_vc_enable(int channel, bool enable)
1782 DSSDBG("dsi_vc_enable channel %d, enable %d\n",
1785 enable = enable ? 1 : 0;
1787 REG_FLD_MOD(DSI_VC_CTRL(channel), enable, 0, 0);
1789 if (wait_for_bit_change(DSI_VC_CTRL(channel), 0, enable) != enable) {
1790 DSSERR("Failed to set dsi_vc_enable to %d\n", enable);
1797 static void dsi_vc_initial_config(int channel)
1801 DSSDBGF("%d", channel);
1803 r = dsi_read_reg(DSI_VC_CTRL(channel));
1805 if (FLD_GET(r, 15, 15)) /* VC_BUSY */
1806 DSSERR("VC(%d) busy when trying to configure it!\n",
1809 r = FLD_MOD(r, 0, 1, 1); /* SOURCE, 0 = L4 */
1810 r = FLD_MOD(r, 0, 2, 2); /* BTA_SHORT_EN */
1811 r = FLD_MOD(r, 0, 3, 3); /* BTA_LONG_EN */
1812 r = FLD_MOD(r, 0, 4, 4); /* MODE, 0 = command */
1813 r = FLD_MOD(r, 1, 7, 7); /* CS_TX_EN */
1814 r = FLD_MOD(r, 1, 8, 8); /* ECC_TX_EN */
1815 r = FLD_MOD(r, 0, 9, 9); /* MODE_SPEED, high speed on/off */
1817 r = FLD_MOD(r, 4, 29, 27); /* DMA_RX_REQ_NB = no dma */
1818 r = FLD_MOD(r, 4, 23, 21); /* DMA_TX_REQ_NB = no dma */
1820 dsi_write_reg(DSI_VC_CTRL(channel), r);
1823 static int dsi_vc_config_l4(int channel)
1825 if (dsi.vc[channel].mode == DSI_VC_MODE_L4)
1828 DSSDBGF("%d", channel);
1830 dsi_vc_enable(channel, 0);
1833 if (wait_for_bit_change(DSI_VC_CTRL(channel), 15, 0) != 0) {
1834 DSSERR("vc(%d) busy when trying to config for L4\n", channel);
1838 REG_FLD_MOD(DSI_VC_CTRL(channel), 0, 1, 1); /* SOURCE, 0 = L4 */
1840 dsi_vc_enable(channel, 1);
1842 dsi.vc[channel].mode = DSI_VC_MODE_L4;
1847 static int dsi_vc_config_vp(int channel)
1849 if (dsi.vc[channel].mode == DSI_VC_MODE_VP)
1852 DSSDBGF("%d", channel);
1854 dsi_vc_enable(channel, 0);
1857 if (wait_for_bit_change(DSI_VC_CTRL(channel), 15, 0) != 0) {
1858 DSSERR("vc(%d) busy when trying to config for VP\n", channel);
1862 REG_FLD_MOD(DSI_VC_CTRL(channel), 1, 1, 1); /* SOURCE, 1 = video port */
1864 dsi_vc_enable(channel, 1);
1866 dsi.vc[channel].mode = DSI_VC_MODE_VP;
1872 void omapdss_dsi_vc_enable_hs(int channel, bool enable)
1874 DSSDBG("dsi_vc_enable_hs(%d, %d)\n", channel, enable);
1876 WARN_ON(!dsi_bus_is_locked());
1878 dsi_vc_enable(channel, 0);
1881 REG_FLD_MOD(DSI_VC_CTRL(channel), enable, 9, 9);
1883 dsi_vc_enable(channel, 1);
1886 dsi_force_tx_stop_mode_io();
1888 EXPORT_SYMBOL(omapdss_dsi_vc_enable_hs);
1890 static void dsi_vc_flush_long_data(int channel)
1892 while (REG_GET(DSI_VC_CTRL(channel), 20, 20)) {
1894 val = dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel));
1895 DSSDBG("\t\tb1 %#02x b2 %#02x b3 %#02x b4 %#02x\n",
1899 (val >> 24) & 0xff);
1903 static void dsi_show_rx_ack_with_err(u16 err)
1905 DSSERR("\tACK with ERROR (%#x):\n", err);
1907 DSSERR("\t\tSoT Error\n");
1909 DSSERR("\t\tSoT Sync Error\n");
1911 DSSERR("\t\tEoT Sync Error\n");
1913 DSSERR("\t\tEscape Mode Entry Command Error\n");
1915 DSSERR("\t\tLP Transmit Sync Error\n");
1917 DSSERR("\t\tHS Receive Timeout Error\n");
1919 DSSERR("\t\tFalse Control Error\n");
1921 DSSERR("\t\t(reserved7)\n");
1923 DSSERR("\t\tECC Error, single-bit (corrected)\n");
1925 DSSERR("\t\tECC Error, multi-bit (not corrected)\n");
1926 if (err & (1 << 10))
1927 DSSERR("\t\tChecksum Error\n");
1928 if (err & (1 << 11))
1929 DSSERR("\t\tData type not recognized\n");
1930 if (err & (1 << 12))
1931 DSSERR("\t\tInvalid VC ID\n");
1932 if (err & (1 << 13))
1933 DSSERR("\t\tInvalid Transmission Length\n");
1934 if (err & (1 << 14))
1935 DSSERR("\t\t(reserved14)\n");
1936 if (err & (1 << 15))
1937 DSSERR("\t\tDSI Protocol Violation\n");
1940 static u16 dsi_vc_flush_receive_data(int channel)
1942 /* RX_FIFO_NOT_EMPTY */
1943 while (REG_GET(DSI_VC_CTRL(channel), 20, 20)) {
1946 val = dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel));
1947 DSSERR("\trawval %#08x\n", val);
1948 dt = FLD_GET(val, 5, 0);
1949 if (dt == DSI_DT_RX_ACK_WITH_ERR) {
1950 u16 err = FLD_GET(val, 23, 8);
1951 dsi_show_rx_ack_with_err(err);
1952 } else if (dt == DSI_DT_RX_SHORT_READ_1) {
1953 DSSERR("\tDCS short response, 1 byte: %#x\n",
1954 FLD_GET(val, 23, 8));
1955 } else if (dt == DSI_DT_RX_SHORT_READ_2) {
1956 DSSERR("\tDCS short response, 2 byte: %#x\n",
1957 FLD_GET(val, 23, 8));
1958 } else if (dt == DSI_DT_RX_DCS_LONG_READ) {
1959 DSSERR("\tDCS long response, len %d\n",
1960 FLD_GET(val, 23, 8));
1961 dsi_vc_flush_long_data(channel);
1963 DSSERR("\tunknown datatype 0x%02x\n", dt);
1969 static int dsi_vc_send_bta(int channel)
1971 if (dsi.debug_write || dsi.debug_read)
1972 DSSDBG("dsi_vc_send_bta %d\n", channel);
1974 WARN_ON(!dsi_bus_is_locked());
1976 if (REG_GET(DSI_VC_CTRL(channel), 20, 20)) { /* RX_FIFO_NOT_EMPTY */
1977 DSSERR("rx fifo not empty when sending BTA, dumping data:\n");
1978 dsi_vc_flush_receive_data(channel);
1981 REG_FLD_MOD(DSI_VC_CTRL(channel), 1, 6, 6); /* BTA_EN */
1986 int dsi_vc_send_bta_sync(int channel)
1991 INIT_COMPLETION(dsi.bta_completion);
1993 dsi_vc_enable_bta_irq(channel);
1995 r = dsi_vc_send_bta(channel);
1999 if (wait_for_completion_timeout(&dsi.bta_completion,
2000 msecs_to_jiffies(500)) == 0) {
2001 DSSERR("Failed to receive BTA\n");
2006 err = dsi_get_errors();
2008 DSSERR("Error while sending BTA: %x\n", err);
2013 dsi_vc_disable_bta_irq(channel);
2017 EXPORT_SYMBOL(dsi_vc_send_bta_sync);
2019 static inline void dsi_vc_write_long_header(int channel, u8 data_type,
2025 WARN_ON(!dsi_bus_is_locked());
2027 data_id = data_type | dsi.vc[channel].vc_id << 6;
2029 val = FLD_VAL(data_id, 7, 0) | FLD_VAL(len, 23, 8) |
2030 FLD_VAL(ecc, 31, 24);
2032 dsi_write_reg(DSI_VC_LONG_PACKET_HEADER(channel), val);
2035 static inline void dsi_vc_write_long_payload(int channel,
2036 u8 b1, u8 b2, u8 b3, u8 b4)
2040 val = b4 << 24 | b3 << 16 | b2 << 8 | b1 << 0;
2042 /* DSSDBG("\twriting %02x, %02x, %02x, %02x (%#010x)\n",
2043 b1, b2, b3, b4, val); */
2045 dsi_write_reg(DSI_VC_LONG_PACKET_PAYLOAD(channel), val);
2048 static int dsi_vc_send_long(int channel, u8 data_type, u8 *data, u16 len,
2057 if (dsi.debug_write)
2058 DSSDBG("dsi_vc_send_long, %d bytes\n", len);
2061 if (dsi.vc[channel].fifo_size * 32 * 4 < len + 4) {
2062 DSSERR("unable to send long packet: packet too long.\n");
2066 dsi_vc_config_l4(channel);
2068 dsi_vc_write_long_header(channel, data_type, len, ecc);
2071 for (i = 0; i < len >> 2; i++) {
2072 if (dsi.debug_write)
2073 DSSDBG("\tsending full packet %d\n", i);
2080 dsi_vc_write_long_payload(channel, b1, b2, b3, b4);
2085 b1 = 0; b2 = 0; b3 = 0;
2087 if (dsi.debug_write)
2088 DSSDBG("\tsending remainder bytes %d\n", i);
2105 dsi_vc_write_long_payload(channel, b1, b2, b3, 0);
2111 static int dsi_vc_send_short(int channel, u8 data_type, u16 data, u8 ecc)
2116 WARN_ON(!dsi_bus_is_locked());
2118 if (dsi.debug_write)
2119 DSSDBG("dsi_vc_send_short(ch%d, dt %#x, b1 %#x, b2 %#x)\n",
2121 data_type, data & 0xff, (data >> 8) & 0xff);
2123 dsi_vc_config_l4(channel);
2125 if (FLD_GET(dsi_read_reg(DSI_VC_CTRL(channel)), 16, 16)) {
2126 DSSERR("ERROR FIFO FULL, aborting transfer\n");
2130 data_id = data_type | dsi.vc[channel].vc_id << 6;
2132 r = (data_id << 0) | (data << 8) | (ecc << 24);
2134 dsi_write_reg(DSI_VC_SHORT_PACKET_HEADER(channel), r);
2139 int dsi_vc_send_null(int channel)
2141 u8 nullpkg[] = {0, 0, 0, 0};
2142 return dsi_vc_send_long(channel, DSI_DT_NULL_PACKET, nullpkg, 4, 0);
2144 EXPORT_SYMBOL(dsi_vc_send_null);
2146 int dsi_vc_dcs_write_nosync(int channel, u8 *data, int len)
2153 r = dsi_vc_send_short(channel, DSI_DT_DCS_SHORT_WRITE_0,
2155 } else if (len == 2) {
2156 r = dsi_vc_send_short(channel, DSI_DT_DCS_SHORT_WRITE_1,
2157 data[0] | (data[1] << 8), 0);
2159 /* 0x39 = DCS Long Write */
2160 r = dsi_vc_send_long(channel, DSI_DT_DCS_LONG_WRITE,
2166 EXPORT_SYMBOL(dsi_vc_dcs_write_nosync);
2168 int dsi_vc_dcs_write(int channel, u8 *data, int len)
2172 r = dsi_vc_dcs_write_nosync(channel, data, len);
2176 r = dsi_vc_send_bta_sync(channel);
2180 if (REG_GET(DSI_VC_CTRL(channel), 20, 20)) { /* RX_FIFO_NOT_EMPTY */
2181 DSSERR("rx fifo not empty after write, dumping data:\n");
2182 dsi_vc_flush_receive_data(channel);
2189 DSSERR("dsi_vc_dcs_write(ch %d, cmd 0x%02x, len %d) failed\n",
2190 channel, data[0], len);
2193 EXPORT_SYMBOL(dsi_vc_dcs_write);
2195 int dsi_vc_dcs_write_0(int channel, u8 dcs_cmd)
2197 return dsi_vc_dcs_write(channel, &dcs_cmd, 1);
2199 EXPORT_SYMBOL(dsi_vc_dcs_write_0);
2201 int dsi_vc_dcs_write_1(int channel, u8 dcs_cmd, u8 param)
2206 return dsi_vc_dcs_write(channel, buf, 2);
2208 EXPORT_SYMBOL(dsi_vc_dcs_write_1);
2210 int dsi_vc_dcs_read(int channel, u8 dcs_cmd, u8 *buf, int buflen)
2217 DSSDBG("dsi_vc_dcs_read(ch%d, dcs_cmd %x)\n", channel, dcs_cmd);
2219 r = dsi_vc_send_short(channel, DSI_DT_DCS_READ, dcs_cmd, 0);
2223 r = dsi_vc_send_bta_sync(channel);
2227 /* RX_FIFO_NOT_EMPTY */
2228 if (REG_GET(DSI_VC_CTRL(channel), 20, 20) == 0) {
2229 DSSERR("RX fifo empty when trying to read.\n");
2234 val = dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel));
2236 DSSDBG("\theader: %08x\n", val);
2237 dt = FLD_GET(val, 5, 0);
2238 if (dt == DSI_DT_RX_ACK_WITH_ERR) {
2239 u16 err = FLD_GET(val, 23, 8);
2240 dsi_show_rx_ack_with_err(err);
2244 } else if (dt == DSI_DT_RX_SHORT_READ_1) {
2245 u8 data = FLD_GET(val, 15, 8);
2247 DSSDBG("\tDCS short response, 1 byte: %02x\n", data);
2257 } else if (dt == DSI_DT_RX_SHORT_READ_2) {
2258 u16 data = FLD_GET(val, 23, 8);
2260 DSSDBG("\tDCS short response, 2 byte: %04x\n", data);
2267 buf[0] = data & 0xff;
2268 buf[1] = (data >> 8) & 0xff;
2271 } else if (dt == DSI_DT_RX_DCS_LONG_READ) {
2273 int len = FLD_GET(val, 23, 8);
2275 DSSDBG("\tDCS long response, len %d\n", len);
2282 /* two byte checksum ends the packet, not included in len */
2283 for (w = 0; w < len + 2;) {
2285 val = dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel));
2287 DSSDBG("\t\t%02x %02x %02x %02x\n",
2291 (val >> 24) & 0xff);
2293 for (b = 0; b < 4; ++b) {
2295 buf[w] = (val >> (b * 8)) & 0xff;
2296 /* we discard the 2 byte checksum */
2303 DSSERR("\tunknown datatype 0x%02x\n", dt);
2310 DSSERR("dsi_vc_dcs_read(ch %d, cmd 0x%02x) failed\n",
2315 EXPORT_SYMBOL(dsi_vc_dcs_read);
2317 int dsi_vc_dcs_read_1(int channel, u8 dcs_cmd, u8 *data)
2321 r = dsi_vc_dcs_read(channel, dcs_cmd, data, 1);
2331 EXPORT_SYMBOL(dsi_vc_dcs_read_1);
2333 int dsi_vc_dcs_read_2(int channel, u8 dcs_cmd, u8 *data1, u8 *data2)
2338 r = dsi_vc_dcs_read(channel, dcs_cmd, buf, 2);
2351 EXPORT_SYMBOL(dsi_vc_dcs_read_2);
2353 int dsi_vc_set_max_rx_packet_size(int channel, u16 len)
2355 return dsi_vc_send_short(channel, DSI_DT_SET_MAX_RET_PKG_SIZE,
2358 EXPORT_SYMBOL(dsi_vc_set_max_rx_packet_size);
2360 static void dsi_set_lp_rx_timeout(unsigned ticks, bool x4, bool x16)
2363 unsigned long total_ticks;
2366 BUG_ON(ticks > 0x1fff);
2368 /* ticks in DSI_FCK */
2369 fck = dsi_fclk_rate();
2371 r = dsi_read_reg(DSI_TIMING2);
2372 r = FLD_MOD(r, 1, 15, 15); /* LP_RX_TO */
2373 r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* LP_RX_TO_X16 */
2374 r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* LP_RX_TO_X4 */
2375 r = FLD_MOD(r, ticks, 12, 0); /* LP_RX_COUNTER */
2376 dsi_write_reg(DSI_TIMING2, r);
2378 total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
2380 DSSDBG("LP_RX_TO %lu ticks (%#x%s%s) = %lu ns\n",
2382 ticks, x4 ? " x4" : "", x16 ? " x16" : "",
2383 (total_ticks * 1000) / (fck / 1000 / 1000));
2386 static void dsi_set_ta_timeout(unsigned ticks, bool x8, bool x16)
2389 unsigned long total_ticks;
2392 BUG_ON(ticks > 0x1fff);
2394 /* ticks in DSI_FCK */
2395 fck = dsi_fclk_rate();
2397 r = dsi_read_reg(DSI_TIMING1);
2398 r = FLD_MOD(r, 1, 31, 31); /* TA_TO */
2399 r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* TA_TO_X16 */
2400 r = FLD_MOD(r, x8 ? 1 : 0, 29, 29); /* TA_TO_X8 */
2401 r = FLD_MOD(r, ticks, 28, 16); /* TA_TO_COUNTER */
2402 dsi_write_reg(DSI_TIMING1, r);
2404 total_ticks = ticks * (x16 ? 16 : 1) * (x8 ? 8 : 1);
2406 DSSDBG("TA_TO %lu ticks (%#x%s%s) = %lu ns\n",
2408 ticks, x8 ? " x8" : "", x16 ? " x16" : "",
2409 (total_ticks * 1000) / (fck / 1000 / 1000));
2412 static void dsi_set_stop_state_counter(unsigned ticks, bool x4, bool x16)
2415 unsigned long total_ticks;
2418 BUG_ON(ticks > 0x1fff);
2420 /* ticks in DSI_FCK */
2421 fck = dsi_fclk_rate();
2423 r = dsi_read_reg(DSI_TIMING1);
2424 r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
2425 r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* STOP_STATE_X16_IO */
2426 r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* STOP_STATE_X4_IO */
2427 r = FLD_MOD(r, ticks, 12, 0); /* STOP_STATE_COUNTER_IO */
2428 dsi_write_reg(DSI_TIMING1, r);
2430 total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
2432 DSSDBG("STOP_STATE_COUNTER %lu ticks (%#x%s%s) = %lu ns\n",
2434 ticks, x4 ? " x4" : "", x16 ? " x16" : "",
2435 (total_ticks * 1000) / (fck / 1000 / 1000));
2438 static void dsi_set_hs_tx_timeout(unsigned ticks, bool x4, bool x16)
2441 unsigned long total_ticks;
2444 BUG_ON(ticks > 0x1fff);
2446 /* ticks in TxByteClkHS */
2447 fck = dsi_get_txbyteclkhs();
2449 r = dsi_read_reg(DSI_TIMING2);
2450 r = FLD_MOD(r, 1, 31, 31); /* HS_TX_TO */
2451 r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* HS_TX_TO_X16 */
2452 r = FLD_MOD(r, x4 ? 1 : 0, 29, 29); /* HS_TX_TO_X8 (4 really) */
2453 r = FLD_MOD(r, ticks, 28, 16); /* HS_TX_TO_COUNTER */
2454 dsi_write_reg(DSI_TIMING2, r);
2456 total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
2458 DSSDBG("HS_TX_TO %lu ticks (%#x%s%s) = %lu ns\n",
2460 ticks, x4 ? " x4" : "", x16 ? " x16" : "",
2461 (total_ticks * 1000) / (fck / 1000 / 1000));
2463 static int dsi_proto_config(struct omap_dss_device *dssdev)
2468 dsi_config_tx_fifo(DSI_FIFO_SIZE_32,
2473 dsi_config_rx_fifo(DSI_FIFO_SIZE_32,
2478 /* XXX what values for the timeouts? */
2479 dsi_set_stop_state_counter(0x1000, false, false);
2480 dsi_set_ta_timeout(0x1fff, true, true);
2481 dsi_set_lp_rx_timeout(0x1fff, true, true);
2482 dsi_set_hs_tx_timeout(0x1fff, true, true);
2484 switch (dssdev->ctrl.pixel_size) {
2498 r = dsi_read_reg(DSI_CTRL);
2499 r = FLD_MOD(r, 1, 1, 1); /* CS_RX_EN */
2500 r = FLD_MOD(r, 1, 2, 2); /* ECC_RX_EN */
2501 r = FLD_MOD(r, 1, 3, 3); /* TX_FIFO_ARBITRATION */
2502 r = FLD_MOD(r, 1, 4, 4); /* VP_CLK_RATIO, always 1, see errata*/
2503 r = FLD_MOD(r, buswidth, 7, 6); /* VP_DATA_BUS_WIDTH */
2504 r = FLD_MOD(r, 0, 8, 8); /* VP_CLK_POL */
2505 r = FLD_MOD(r, 2, 13, 12); /* LINE_BUFFER, 2 lines */
2506 r = FLD_MOD(r, 1, 14, 14); /* TRIGGER_RESET_MODE */
2507 r = FLD_MOD(r, 1, 19, 19); /* EOT_ENABLE */
2508 r = FLD_MOD(r, 1, 24, 24); /* DCS_CMD_ENABLE */
2509 r = FLD_MOD(r, 0, 25, 25); /* DCS_CMD_CODE, 1=start, 0=continue */
2511 dsi_write_reg(DSI_CTRL, r);
2513 dsi_vc_initial_config(0);
2514 dsi_vc_initial_config(1);
2515 dsi_vc_initial_config(2);
2516 dsi_vc_initial_config(3);
2521 static void dsi_proto_timings(struct omap_dss_device *dssdev)
2523 unsigned tlpx, tclk_zero, tclk_prepare, tclk_trail;
2524 unsigned tclk_pre, tclk_post;
2525 unsigned ths_prepare, ths_prepare_ths_zero, ths_zero;
2526 unsigned ths_trail, ths_exit;
2527 unsigned ddr_clk_pre, ddr_clk_post;
2528 unsigned enter_hs_mode_lat, exit_hs_mode_lat;
2532 r = dsi_read_reg(DSI_DSIPHY_CFG0);
2533 ths_prepare = FLD_GET(r, 31, 24);
2534 ths_prepare_ths_zero = FLD_GET(r, 23, 16);
2535 ths_zero = ths_prepare_ths_zero - ths_prepare;
2536 ths_trail = FLD_GET(r, 15, 8);
2537 ths_exit = FLD_GET(r, 7, 0);
2539 r = dsi_read_reg(DSI_DSIPHY_CFG1);
2540 tlpx = FLD_GET(r, 22, 16) * 2;
2541 tclk_trail = FLD_GET(r, 15, 8);
2542 tclk_zero = FLD_GET(r, 7, 0);
2544 r = dsi_read_reg(DSI_DSIPHY_CFG2);
2545 tclk_prepare = FLD_GET(r, 7, 0);
2549 /* min 60ns + 52*UI */
2550 tclk_post = ns2ddr(60) + 26;
2552 /* ths_eot is 2 for 2 datalanes and 4 for 1 datalane */
2553 if (dssdev->phy.dsi.data1_lane != 0 &&
2554 dssdev->phy.dsi.data2_lane != 0)
2559 ddr_clk_pre = DIV_ROUND_UP(tclk_pre + tlpx + tclk_zero + tclk_prepare,
2561 ddr_clk_post = DIV_ROUND_UP(tclk_post + ths_trail, 4) + ths_eot;
2563 BUG_ON(ddr_clk_pre == 0 || ddr_clk_pre > 255);
2564 BUG_ON(ddr_clk_post == 0 || ddr_clk_post > 255);
2566 r = dsi_read_reg(DSI_CLK_TIMING);
2567 r = FLD_MOD(r, ddr_clk_pre, 15, 8);
2568 r = FLD_MOD(r, ddr_clk_post, 7, 0);
2569 dsi_write_reg(DSI_CLK_TIMING, r);
2571 DSSDBG("ddr_clk_pre %u, ddr_clk_post %u\n",
2575 enter_hs_mode_lat = 1 + DIV_ROUND_UP(tlpx, 4) +
2576 DIV_ROUND_UP(ths_prepare, 4) +
2577 DIV_ROUND_UP(ths_zero + 3, 4);
2579 exit_hs_mode_lat = DIV_ROUND_UP(ths_trail + ths_exit, 4) + 1 + ths_eot;
2581 r = FLD_VAL(enter_hs_mode_lat, 31, 16) |
2582 FLD_VAL(exit_hs_mode_lat, 15, 0);
2583 dsi_write_reg(DSI_VM_TIMING7, r);
2585 DSSDBG("enter_hs_mode_lat %u, exit_hs_mode_lat %u\n",
2586 enter_hs_mode_lat, exit_hs_mode_lat);
2590 #define DSI_DECL_VARS \
2591 int __dsi_cb = 0; u32 __dsi_cv = 0;
2593 #define DSI_FLUSH(ch) \
2594 if (__dsi_cb > 0) { \
2595 /*DSSDBG("sending long packet %#010x\n", __dsi_cv);*/ \
2596 dsi_write_reg(DSI_VC_LONG_PACKET_PAYLOAD(ch), __dsi_cv); \
2597 __dsi_cb = __dsi_cv = 0; \
2600 #define DSI_PUSH(ch, data) \
2602 __dsi_cv |= (data) << (__dsi_cb * 8); \
2603 /*DSSDBG("cv = %#010x, cb = %d\n", __dsi_cv, __dsi_cb);*/ \
2604 if (++__dsi_cb > 3) \
2608 static int dsi_update_screen_l4(struct omap_dss_device *dssdev,
2609 int x, int y, int w, int h)
2611 /* Note: supports only 24bit colors in 32bit container */
2613 int fifo_stalls = 0;
2614 int max_dsi_packet_size;
2615 int max_data_per_packet;
2616 int max_pixels_per_packet;
2618 int bytespp = dssdev->ctrl.pixel_size / 8;
2624 struct omap_overlay *ovl;
2628 DSSDBG("dsi_update_screen_l4 (%d,%d %dx%d)\n",
2631 ovl = dssdev->manager->overlays[0];
2633 if (ovl->info.color_mode != OMAP_DSS_COLOR_RGB24U)
2636 if (dssdev->ctrl.pixel_size != 24)
2639 scr_width = ovl->info.screen_width;
2640 data = ovl->info.vaddr;
2642 start_offset = scr_width * y + x;
2643 horiz_inc = scr_width - w;
2646 /* We need header(4) + DCSCMD(1) + pixels(numpix*bytespp) bytes
2649 /* When using CPU, max long packet size is TX buffer size */
2650 max_dsi_packet_size = dsi.vc[0].fifo_size * 32 * 4;
2652 /* we seem to get better perf if we divide the tx fifo to half,
2653 and while the other half is being sent, we fill the other half
2654 max_dsi_packet_size /= 2; */
2656 max_data_per_packet = max_dsi_packet_size - 4 - 1;
2658 max_pixels_per_packet = max_data_per_packet / bytespp;
2660 DSSDBG("max_pixels_per_packet %d\n", max_pixels_per_packet);
2662 pixels_left = w * h;
2664 DSSDBG("total pixels %d\n", pixels_left);
2666 data += start_offset;
2668 while (pixels_left > 0) {
2669 /* 0x2c = write_memory_start */
2670 /* 0x3c = write_memory_continue */
2671 u8 dcs_cmd = first ? 0x2c : 0x3c;
2677 /* using fifo not empty */
2678 /* TX_FIFO_NOT_EMPTY */
2679 while (FLD_GET(dsi_read_reg(DSI_VC_CTRL(0)), 5, 5)) {
2681 if (fifo_stalls > 0xfffff) {
2682 DSSERR("fifo stalls overflow, pixels left %d\n",
2690 /* using fifo emptiness */
2691 while ((REG_GET(DSI_TX_FIFO_VC_EMPTINESS, 7, 0)+1)*4 <
2692 max_dsi_packet_size) {
2694 if (fifo_stalls > 0xfffff) {
2695 DSSERR("fifo stalls overflow, pixels left %d\n",
2702 while ((REG_GET(DSI_TX_FIFO_VC_EMPTINESS, 7, 0)+1)*4 == 0) {
2704 if (fifo_stalls > 0xfffff) {
2705 DSSERR("fifo stalls overflow, pixels left %d\n",
2712 pixels = min(max_pixels_per_packet, pixels_left);
2714 pixels_left -= pixels;
2716 dsi_vc_write_long_header(0, DSI_DT_DCS_LONG_WRITE,
2717 1 + pixels * bytespp, 0);
2719 DSI_PUSH(0, dcs_cmd);
2721 while (pixels-- > 0) {
2722 u32 pix = __raw_readl(data++);
2724 DSI_PUSH(0, (pix >> 16) & 0xff);
2725 DSI_PUSH(0, (pix >> 8) & 0xff);
2726 DSI_PUSH(0, (pix >> 0) & 0xff);
2729 if (current_x == x+w) {
2741 static void dsi_update_screen_dispc(struct omap_dss_device *dssdev,
2742 u16 x, u16 y, u16 w, u16 h)
2748 unsigned packet_payload;
2749 unsigned packet_len;
2752 const unsigned channel = dsi.update_channel;
2753 /* line buffer is 1024 x 24bits */
2754 /* XXX: for some reason using full buffer size causes considerable TX
2755 * slowdown with update sizes that fill the whole buffer */
2756 const unsigned line_buf_size = 1023 * 3;
2758 DSSDBG("dsi_update_screen_dispc(%d,%d %dx%d)\n",
2761 dsi_vc_config_vp(channel);
2763 bytespp = dssdev->ctrl.pixel_size / 8;
2764 bytespl = w * bytespp;
2765 bytespf = bytespl * h;
2767 /* NOTE: packet_payload has to be equal to N * bytespl, where N is
2768 * number of lines in a packet. See errata about VP_CLK_RATIO */
2770 if (bytespf < line_buf_size)
2771 packet_payload = bytespf;
2773 packet_payload = (line_buf_size) / bytespl * bytespl;
2775 packet_len = packet_payload + 1; /* 1 byte for DCS cmd */
2776 total_len = (bytespf / packet_payload) * packet_len;
2778 if (bytespf % packet_payload)
2779 total_len += (bytespf % packet_payload) + 1;
2781 l = FLD_VAL(total_len, 23, 0); /* TE_SIZE */
2782 dsi_write_reg(DSI_VC_TE(channel), l);
2784 dsi_vc_write_long_header(channel, DSI_DT_DCS_LONG_WRITE, packet_len, 0);
2787 l = FLD_MOD(l, 1, 30, 30); /* TE_EN */
2789 l = FLD_MOD(l, 1, 31, 31); /* TE_START */
2790 dsi_write_reg(DSI_VC_TE(channel), l);
2792 /* We put SIDLEMODE to no-idle for the duration of the transfer,
2793 * because DSS interrupts are not capable of waking up the CPU and the
2794 * framedone interrupt could be delayed for quite a long time. I think
2795 * the same goes for any DSS interrupts, but for some reason I have not
2796 * seen the problem anywhere else than here.
2798 dispc_disable_sidle();
2800 dsi_perf_mark_start();
2802 r = queue_delayed_work(dsi.workqueue, &dsi.framedone_timeout_work,
2803 msecs_to_jiffies(250));
2806 dss_start_update(dssdev);
2808 if (dsi.te_enabled) {
2809 /* disable LP_RX_TO, so that we can receive TE. Time to wait
2810 * for TE is longer than the timer allows */
2811 REG_FLD_MOD(DSI_TIMING2, 0, 15, 15); /* LP_RX_TO */
2813 dsi_vc_send_bta(channel);
2815 #ifdef DSI_CATCH_MISSING_TE
2816 mod_timer(&dsi.te_timer, jiffies + msecs_to_jiffies(250));
2821 #ifdef DSI_CATCH_MISSING_TE
2822 static void dsi_te_timeout(unsigned long arg)
2824 DSSERR("TE not received for 250ms!\n");
2828 static void dsi_handle_framedone(int error)
2830 const int channel = dsi.update_channel;
2832 cancel_delayed_work(&dsi.framedone_timeout_work);
2834 dsi_vc_disable_bta_irq(channel);
2836 /* SIDLEMODE back to smart-idle */
2837 dispc_enable_sidle();
2839 dsi.bta_callback = NULL;
2841 if (dsi.te_enabled) {
2842 /* enable LP_RX_TO again after the TE */
2843 REG_FLD_MOD(DSI_TIMING2, 1, 15, 15); /* LP_RX_TO */
2846 /* RX_FIFO_NOT_EMPTY */
2847 if (REG_GET(DSI_VC_CTRL(channel), 20, 20)) {
2848 DSSERR("Received error during frame transfer:\n");
2849 dsi_vc_flush_receive_data(channel);
2854 dsi.framedone_callback(error, dsi.framedone_data);
2857 dsi_perf_show("DISPC");
2860 static void dsi_framedone_timeout_work_callback(struct work_struct *work)
2862 /* XXX While extremely unlikely, we could get FRAMEDONE interrupt after
2863 * 250ms which would conflict with this timeout work. What should be
2864 * done is first cancel the transfer on the HW, and then cancel the
2865 * possibly scheduled framedone work. However, cancelling the transfer
2866 * on the HW is buggy, and would probably require resetting the whole
2869 DSSERR("Framedone not received for 250ms!\n");
2871 dsi_handle_framedone(-ETIMEDOUT);
2874 static void dsi_framedone_bta_callback(void)
2876 dsi_handle_framedone(0);
2878 #ifdef CONFIG_OMAP2_DSS_FAKE_VSYNC
2879 dispc_fake_vsync_irq();
2883 static void dsi_framedone_irq_callback(void *data, u32 mask)
2885 const int channel = dsi.update_channel;
2888 /* Note: We get FRAMEDONE when DISPC has finished sending pixels and
2889 * turns itself off. However, DSI still has the pixels in its buffers,
2890 * and is sending the data.
2893 if (dsi.te_enabled) {
2894 /* enable LP_RX_TO again after the TE */
2895 REG_FLD_MOD(DSI_TIMING2, 1, 15, 15); /* LP_RX_TO */
2898 /* Send BTA after the frame. We need this for the TE to work, as TE
2899 * trigger is only sent for BTAs without preceding packet. Thus we need
2900 * to BTA after the pixel packets so that next BTA will cause TE
2903 * This is not needed when TE is not in use, but we do it anyway to
2904 * make sure that the transfer has been completed. It would be more
2905 * optimal, but more complex, to wait only just before starting next
2908 * Also, as there's no interrupt telling when the transfer has been
2909 * done and the channel could be reconfigured, the only way is to
2910 * busyloop until TE_SIZE is zero. With BTA we can do this
2914 dsi.bta_callback = dsi_framedone_bta_callback;
2918 dsi_vc_enable_bta_irq(channel);
2920 r = dsi_vc_send_bta(channel);
2922 DSSERR("BTA after framedone failed\n");
2923 dsi_handle_framedone(-EIO);
2927 int omap_dsi_prepare_update(struct omap_dss_device *dssdev,
2928 u16 *x, u16 *y, u16 *w, u16 *h,
2929 bool enlarge_update_area)
2933 dssdev->driver->get_resolution(dssdev, &dw, &dh);
2935 if (*x > dw || *y > dh)
2947 if (*w == 0 || *h == 0)
2950 dsi_perf_mark_setup();
2952 if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) {
2953 dss_setup_partial_planes(dssdev, x, y, w, h,
2954 enlarge_update_area);
2955 dispc_set_lcd_size(dssdev->manager->id, *w, *h);
2960 EXPORT_SYMBOL(omap_dsi_prepare_update);
2962 int omap_dsi_update(struct omap_dss_device *dssdev,
2964 u16 x, u16 y, u16 w, u16 h,
2965 void (*callback)(int, void *), void *data)
2967 dsi.update_channel = channel;
2969 /* OMAP DSS cannot send updates of odd widths.
2970 * omap_dsi_prepare_update() makes the widths even, but add a BUG_ON
2971 * here to make sure we catch erroneous updates. Otherwise we'll only
2972 * see rather obscure HW error happening, as DSS halts. */
2975 if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) {
2976 dsi.framedone_callback = callback;
2977 dsi.framedone_data = data;
2979 dsi.update_region.x = x;
2980 dsi.update_region.y = y;
2981 dsi.update_region.w = w;
2982 dsi.update_region.h = h;
2983 dsi.update_region.device = dssdev;
2985 dsi_update_screen_dispc(dssdev, x, y, w, h);
2989 r = dsi_update_screen_l4(dssdev, x, y, w, h);
2993 dsi_perf_show("L4");
2999 EXPORT_SYMBOL(omap_dsi_update);
3003 static int dsi_display_init_dispc(struct omap_dss_device *dssdev)
3007 r = omap_dispc_register_isr(dsi_framedone_irq_callback, NULL,
3008 DISPC_IRQ_FRAMEDONE);
3010 DSSERR("can't get FRAMEDONE irq\n");
3014 dispc_set_lcd_display_type(dssdev->manager->id,
3015 OMAP_DSS_LCD_DISPLAY_TFT);
3017 dispc_set_parallel_interface_mode(dssdev->manager->id,
3018 OMAP_DSS_PARALLELMODE_DSI);
3019 dispc_enable_fifohandcheck(dssdev->manager->id, 1);
3021 dispc_set_tft_data_lines(dssdev->manager->id, dssdev->ctrl.pixel_size);
3024 struct omap_video_timings timings = {
3033 dispc_set_lcd_timings(dssdev->manager->id, &timings);
3039 static void dsi_display_uninit_dispc(struct omap_dss_device *dssdev)
3041 omap_dispc_unregister_isr(dsi_framedone_irq_callback, NULL,
3042 DISPC_IRQ_FRAMEDONE);
3045 static int dsi_configure_dsi_clocks(struct omap_dss_device *dssdev)
3047 struct dsi_clock_info cinfo;
3050 /* we always use DSS_CLK_SYSCK as input clock */
3051 cinfo.use_sys_clk = true;
3052 cinfo.regn = dssdev->phy.dsi.div.regn;
3053 cinfo.regm = dssdev->phy.dsi.div.regm;
3054 cinfo.regm_dispc = dssdev->phy.dsi.div.regm_dispc;
3055 cinfo.regm_dsi = dssdev->phy.dsi.div.regm_dsi;
3056 r = dsi_calc_clock_rates(dssdev, &cinfo);
3058 DSSERR("Failed to calc dsi clocks\n");
3062 r = dsi_pll_set_clock_div(&cinfo);
3064 DSSERR("Failed to set dsi clocks\n");
3071 static int dsi_configure_dispc_clocks(struct omap_dss_device *dssdev)
3073 struct dispc_clock_info dispc_cinfo;
3075 unsigned long long fck;
3077 fck = dsi_get_pll_hsdiv_dispc_rate();
3079 dispc_cinfo.lck_div = dssdev->phy.dsi.div.lck_div;
3080 dispc_cinfo.pck_div = dssdev->phy.dsi.div.pck_div;
3082 r = dispc_calc_clock_rates(fck, &dispc_cinfo);
3084 DSSERR("Failed to calc dispc clocks\n");
3088 r = dispc_set_clock_div(dssdev->manager->id, &dispc_cinfo);
3090 DSSERR("Failed to set dispc clocks\n");
3097 static int dsi_display_init_dsi(struct omap_dss_device *dssdev)
3101 _dsi_print_reset_status();
3103 r = dsi_pll_init(dssdev, true, true);
3107 r = dsi_configure_dsi_clocks(dssdev);
3111 dss_select_dispc_clk_source(DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC);
3112 dss_select_dsi_clk_source(DSS_CLK_SRC_DSI_PLL_HSDIV_DSI);
3116 r = dsi_configure_dispc_clocks(dssdev);
3120 r = dsi_complexio_init(dssdev);
3124 _dsi_print_reset_status();
3126 dsi_proto_timings(dssdev);
3127 dsi_set_lp_clk_divisor(dssdev);
3130 _dsi_print_reset_status();
3132 r = dsi_proto_config(dssdev);
3136 /* enable interface */
3137 dsi_vc_enable(0, 1);
3138 dsi_vc_enable(1, 1);
3139 dsi_vc_enable(2, 1);
3140 dsi_vc_enable(3, 1);
3142 dsi_force_tx_stop_mode_io();
3146 dsi_complexio_uninit();
3148 dss_select_dispc_clk_source(DSS_CLK_SRC_FCK);
3149 dss_select_dsi_clk_source(DSS_CLK_SRC_FCK);
3156 static void dsi_display_uninit_dsi(struct omap_dss_device *dssdev)
3158 /* disable interface */
3160 dsi_vc_enable(0, 0);
3161 dsi_vc_enable(1, 0);
3162 dsi_vc_enable(2, 0);
3163 dsi_vc_enable(3, 0);
3165 dss_select_dispc_clk_source(DSS_CLK_SRC_FCK);
3166 dss_select_dsi_clk_source(DSS_CLK_SRC_FCK);
3167 dsi_complexio_uninit();
3171 static int dsi_core_init(void)
3174 REG_FLD_MOD(DSI_SYSCONFIG, 1, 0, 0);
3177 REG_FLD_MOD(DSI_SYSCONFIG, 1, 2, 2);
3179 /* SIDLEMODE smart-idle */
3180 REG_FLD_MOD(DSI_SYSCONFIG, 2, 4, 3);
3182 _dsi_initialize_irq();
3187 int omapdss_dsi_display_enable(struct omap_dss_device *dssdev)
3191 DSSDBG("dsi_display_enable\n");
3193 WARN_ON(!dsi_bus_is_locked());
3195 mutex_lock(&dsi.lock);
3197 r = omap_dss_start_device(dssdev);
3199 DSSERR("failed to start device\n");
3204 dsi_enable_pll_clock(1);
3212 r = dsi_display_init_dispc(dssdev);
3216 r = dsi_display_init_dsi(dssdev);
3220 mutex_unlock(&dsi.lock);
3225 dsi_display_uninit_dispc(dssdev);
3228 dsi_enable_pll_clock(0);
3229 omap_dss_stop_device(dssdev);
3231 mutex_unlock(&dsi.lock);
3232 DSSDBG("dsi_display_enable FAILED\n");
3235 EXPORT_SYMBOL(omapdss_dsi_display_enable);
3237 void omapdss_dsi_display_disable(struct omap_dss_device *dssdev)
3239 DSSDBG("dsi_display_disable\n");
3241 WARN_ON(!dsi_bus_is_locked());
3243 mutex_lock(&dsi.lock);
3245 dsi_display_uninit_dispc(dssdev);
3247 dsi_display_uninit_dsi(dssdev);
3250 dsi_enable_pll_clock(0);
3252 omap_dss_stop_device(dssdev);
3254 mutex_unlock(&dsi.lock);
3256 EXPORT_SYMBOL(omapdss_dsi_display_disable);
3258 int omapdss_dsi_enable_te(struct omap_dss_device *dssdev, bool enable)
3260 dsi.te_enabled = enable;
3263 EXPORT_SYMBOL(omapdss_dsi_enable_te);
3265 void dsi_get_overlay_fifo_thresholds(enum omap_plane plane,
3266 u32 fifo_size, enum omap_burst_size *burst_size,
3267 u32 *fifo_low, u32 *fifo_high)
3269 unsigned burst_size_bytes;
3271 *burst_size = OMAP_DSS_BURST_16x32;
3272 burst_size_bytes = 16 * 32 / 8;
3274 *fifo_high = fifo_size - burst_size_bytes;
3275 *fifo_low = fifo_size - burst_size_bytes * 2;
3278 int dsi_init_display(struct omap_dss_device *dssdev)
3280 DSSDBG("DSI init\n");
3282 /* XXX these should be figured out dynamically */
3283 dssdev->caps = OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE |
3284 OMAP_DSS_DISPLAY_CAP_TEAR_ELIM;
3286 if (dsi.vdds_dsi_reg == NULL) {
3287 struct regulator *vdds_dsi;
3289 vdds_dsi = regulator_get(&dsi.pdev->dev, "vdds_dsi");
3291 if (IS_ERR(vdds_dsi)) {
3292 DSSERR("can't get VDDS_DSI regulator\n");
3293 return PTR_ERR(vdds_dsi);
3296 dsi.vdds_dsi_reg = vdds_dsi;
3302 int omap_dsi_request_vc(struct omap_dss_device *dssdev, int *channel)
3306 for (i = 0; i < ARRAY_SIZE(dsi.vc); i++) {
3307 if (!dsi.vc[i].dssdev) {
3308 dsi.vc[i].dssdev = dssdev;
3314 DSSERR("cannot get VC for display %s", dssdev->name);
3317 EXPORT_SYMBOL(omap_dsi_request_vc);
3319 int omap_dsi_set_vc_id(struct omap_dss_device *dssdev, int channel, int vc_id)
3321 if (vc_id < 0 || vc_id > 3) {
3322 DSSERR("VC ID out of range\n");
3326 if (channel < 0 || channel > 3) {
3327 DSSERR("Virtual Channel out of range\n");
3331 if (dsi.vc[channel].dssdev != dssdev) {
3332 DSSERR("Virtual Channel not allocated to display %s\n",
3337 dsi.vc[channel].vc_id = vc_id;
3341 EXPORT_SYMBOL(omap_dsi_set_vc_id);
3343 void omap_dsi_release_vc(struct omap_dss_device *dssdev, int channel)
3345 if ((channel >= 0 && channel <= 3) &&
3346 dsi.vc[channel].dssdev == dssdev) {
3347 dsi.vc[channel].dssdev = NULL;
3348 dsi.vc[channel].vc_id = 0;
3351 EXPORT_SYMBOL(omap_dsi_release_vc);
3353 void dsi_wait_pll_hsdiv_dispc_active(void)
3355 if (wait_for_bit_change(DSI_PLL_STATUS, 7, 1) != 1)
3356 DSSERR("%s (%s) not active\n",
3357 dss_get_generic_clk_source_name(DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
3358 dss_feat_get_clk_source_name(DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC));
3361 void dsi_wait_pll_hsdiv_dsi_active(void)
3363 if (wait_for_bit_change(DSI_PLL_STATUS, 8, 1) != 1)
3364 DSSERR("%s (%s) not active\n",
3365 dss_get_generic_clk_source_name(DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
3366 dss_feat_get_clk_source_name(DSS_CLK_SRC_DSI_PLL_HSDIV_DSI));
3369 static void dsi_calc_clock_param_ranges(void)
3371 dsi.regn_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGN);
3372 dsi.regm_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM);
3373 dsi.regm_dispc_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DISPC);
3374 dsi.regm_dsi_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DSI);
3375 dsi.fint_min = dss_feat_get_param_min(FEAT_PARAM_DSIPLL_FINT);
3376 dsi.fint_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_FINT);
3377 dsi.lpdiv_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_LPDIV);
3380 static int dsi_init(struct platform_device *pdev)
3384 struct resource *dsi_mem;
3386 spin_lock_init(&dsi.errors_lock);
3389 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
3390 spin_lock_init(&dsi.irq_stats_lock);
3391 dsi.irq_stats.last_reset = jiffies;
3394 init_completion(&dsi.bta_completion);
3396 mutex_init(&dsi.lock);
3397 sema_init(&dsi.bus_lock, 1);
3399 dsi.workqueue = create_singlethread_workqueue("dsi");
3400 if (dsi.workqueue == NULL)
3403 INIT_DELAYED_WORK_DEFERRABLE(&dsi.framedone_timeout_work,
3404 dsi_framedone_timeout_work_callback);
3406 #ifdef DSI_CATCH_MISSING_TE
3407 init_timer(&dsi.te_timer);
3408 dsi.te_timer.function = dsi_te_timeout;
3409 dsi.te_timer.data = 0;
3411 dsi_mem = platform_get_resource(dsi.pdev, IORESOURCE_MEM, 0);
3413 DSSERR("can't get IORESOURCE_MEM DSI\n");
3417 dsi.base = ioremap(dsi_mem->start, resource_size(dsi_mem));
3419 DSSERR("can't ioremap DSI\n");
3423 dsi.irq = platform_get_irq(dsi.pdev, 0);
3425 DSSERR("platform_get_irq failed\n");
3430 r = request_irq(dsi.irq, omap_dsi_irq_handler, IRQF_SHARED,
3431 "OMAP DSI1", dsi.pdev);
3433 DSSERR("request_irq failed\n");
3437 /* DSI VCs initialization */
3438 for (i = 0; i < ARRAY_SIZE(dsi.vc); i++) {
3439 dsi.vc[i].mode = DSI_VC_MODE_L4;
3440 dsi.vc[i].dssdev = NULL;
3441 dsi.vc[i].vc_id = 0;
3444 dsi_calc_clock_param_ranges();
3448 rev = dsi_read_reg(DSI_REVISION);
3449 dev_dbg(&pdev->dev, "OMAP DSI rev %d.%d\n",
3450 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
3458 destroy_workqueue(dsi.workqueue);
3462 static void dsi_exit(void)
3464 if (dsi.vdds_dsi_reg != NULL) {
3465 regulator_put(dsi.vdds_dsi_reg);
3466 dsi.vdds_dsi_reg = NULL;
3469 free_irq(dsi.irq, dsi.pdev);
3472 destroy_workqueue(dsi.workqueue);
3474 DSSDBG("omap_dsi_exit\n");
3477 /* DSI1 HW IP initialisation */
3478 static int omap_dsi1hw_probe(struct platform_device *pdev)
3484 DSSERR("Failed to initialize DSI\n");
3491 static int omap_dsi1hw_remove(struct platform_device *pdev)
3497 static struct platform_driver omap_dsi1hw_driver = {
3498 .probe = omap_dsi1hw_probe,
3499 .remove = omap_dsi1hw_remove,
3501 .name = "omapdss_dsi1",
3502 .owner = THIS_MODULE,
3506 int dsi_init_platform_driver(void)
3508 return platform_driver_register(&omap_dsi1hw_driver);
3511 void dsi_uninit_platform_driver(void)
3513 return platform_driver_unregister(&omap_dsi1hw_driver);