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>
36 #include <linux/sched.h>
37 #include <linux/slab.h>
38 #include <linux/debugfs.h>
39 #include <linux/pm_runtime.h>
41 #include <video/omapdss.h>
42 #include <plat/clock.h>
45 #include "dss_features.h"
47 /*#define VERBOSE_IRQ*/
48 #define DSI_CATCH_MISSING_TE
50 struct dsi_reg { u16 idx; };
52 #define DSI_REG(idx) ((const struct dsi_reg) { idx })
54 #define DSI_SZ_REGS SZ_1K
55 /* DSI Protocol Engine */
57 #define DSI_REVISION DSI_REG(0x0000)
58 #define DSI_SYSCONFIG DSI_REG(0x0010)
59 #define DSI_SYSSTATUS DSI_REG(0x0014)
60 #define DSI_IRQSTATUS DSI_REG(0x0018)
61 #define DSI_IRQENABLE DSI_REG(0x001C)
62 #define DSI_CTRL DSI_REG(0x0040)
63 #define DSI_GNQ DSI_REG(0x0044)
64 #define DSI_COMPLEXIO_CFG1 DSI_REG(0x0048)
65 #define DSI_COMPLEXIO_IRQ_STATUS DSI_REG(0x004C)
66 #define DSI_COMPLEXIO_IRQ_ENABLE DSI_REG(0x0050)
67 #define DSI_CLK_CTRL DSI_REG(0x0054)
68 #define DSI_TIMING1 DSI_REG(0x0058)
69 #define DSI_TIMING2 DSI_REG(0x005C)
70 #define DSI_VM_TIMING1 DSI_REG(0x0060)
71 #define DSI_VM_TIMING2 DSI_REG(0x0064)
72 #define DSI_VM_TIMING3 DSI_REG(0x0068)
73 #define DSI_CLK_TIMING DSI_REG(0x006C)
74 #define DSI_TX_FIFO_VC_SIZE DSI_REG(0x0070)
75 #define DSI_RX_FIFO_VC_SIZE DSI_REG(0x0074)
76 #define DSI_COMPLEXIO_CFG2 DSI_REG(0x0078)
77 #define DSI_RX_FIFO_VC_FULLNESS DSI_REG(0x007C)
78 #define DSI_VM_TIMING4 DSI_REG(0x0080)
79 #define DSI_TX_FIFO_VC_EMPTINESS DSI_REG(0x0084)
80 #define DSI_VM_TIMING5 DSI_REG(0x0088)
81 #define DSI_VM_TIMING6 DSI_REG(0x008C)
82 #define DSI_VM_TIMING7 DSI_REG(0x0090)
83 #define DSI_STOPCLK_TIMING DSI_REG(0x0094)
84 #define DSI_VC_CTRL(n) DSI_REG(0x0100 + (n * 0x20))
85 #define DSI_VC_TE(n) DSI_REG(0x0104 + (n * 0x20))
86 #define DSI_VC_LONG_PACKET_HEADER(n) DSI_REG(0x0108 + (n * 0x20))
87 #define DSI_VC_LONG_PACKET_PAYLOAD(n) DSI_REG(0x010C + (n * 0x20))
88 #define DSI_VC_SHORT_PACKET_HEADER(n) DSI_REG(0x0110 + (n * 0x20))
89 #define DSI_VC_IRQSTATUS(n) DSI_REG(0x0118 + (n * 0x20))
90 #define DSI_VC_IRQENABLE(n) DSI_REG(0x011C + (n * 0x20))
94 #define DSI_DSIPHY_CFG0 DSI_REG(0x200 + 0x0000)
95 #define DSI_DSIPHY_CFG1 DSI_REG(0x200 + 0x0004)
96 #define DSI_DSIPHY_CFG2 DSI_REG(0x200 + 0x0008)
97 #define DSI_DSIPHY_CFG5 DSI_REG(0x200 + 0x0014)
98 #define DSI_DSIPHY_CFG10 DSI_REG(0x200 + 0x0028)
100 /* DSI_PLL_CTRL_SCP */
102 #define DSI_PLL_CONTROL DSI_REG(0x300 + 0x0000)
103 #define DSI_PLL_STATUS DSI_REG(0x300 + 0x0004)
104 #define DSI_PLL_GO DSI_REG(0x300 + 0x0008)
105 #define DSI_PLL_CONFIGURATION1 DSI_REG(0x300 + 0x000C)
106 #define DSI_PLL_CONFIGURATION2 DSI_REG(0x300 + 0x0010)
108 #define REG_GET(dsidev, idx, start, end) \
109 FLD_GET(dsi_read_reg(dsidev, idx), start, end)
111 #define REG_FLD_MOD(dsidev, idx, val, start, end) \
112 dsi_write_reg(dsidev, idx, FLD_MOD(dsi_read_reg(dsidev, idx), val, start, end))
114 /* Global interrupts */
115 #define DSI_IRQ_VC0 (1 << 0)
116 #define DSI_IRQ_VC1 (1 << 1)
117 #define DSI_IRQ_VC2 (1 << 2)
118 #define DSI_IRQ_VC3 (1 << 3)
119 #define DSI_IRQ_WAKEUP (1 << 4)
120 #define DSI_IRQ_RESYNC (1 << 5)
121 #define DSI_IRQ_PLL_LOCK (1 << 7)
122 #define DSI_IRQ_PLL_UNLOCK (1 << 8)
123 #define DSI_IRQ_PLL_RECALL (1 << 9)
124 #define DSI_IRQ_COMPLEXIO_ERR (1 << 10)
125 #define DSI_IRQ_HS_TX_TIMEOUT (1 << 14)
126 #define DSI_IRQ_LP_RX_TIMEOUT (1 << 15)
127 #define DSI_IRQ_TE_TRIGGER (1 << 16)
128 #define DSI_IRQ_ACK_TRIGGER (1 << 17)
129 #define DSI_IRQ_SYNC_LOST (1 << 18)
130 #define DSI_IRQ_LDO_POWER_GOOD (1 << 19)
131 #define DSI_IRQ_TA_TIMEOUT (1 << 20)
132 #define DSI_IRQ_ERROR_MASK \
133 (DSI_IRQ_HS_TX_TIMEOUT | DSI_IRQ_LP_RX_TIMEOUT | DSI_IRQ_SYNC_LOST | \
135 #define DSI_IRQ_CHANNEL_MASK 0xf
137 /* Virtual channel interrupts */
138 #define DSI_VC_IRQ_CS (1 << 0)
139 #define DSI_VC_IRQ_ECC_CORR (1 << 1)
140 #define DSI_VC_IRQ_PACKET_SENT (1 << 2)
141 #define DSI_VC_IRQ_FIFO_TX_OVF (1 << 3)
142 #define DSI_VC_IRQ_FIFO_RX_OVF (1 << 4)
143 #define DSI_VC_IRQ_BTA (1 << 5)
144 #define DSI_VC_IRQ_ECC_NO_CORR (1 << 6)
145 #define DSI_VC_IRQ_FIFO_TX_UDF (1 << 7)
146 #define DSI_VC_IRQ_PP_BUSY_CHANGE (1 << 8)
147 #define DSI_VC_IRQ_ERROR_MASK \
148 (DSI_VC_IRQ_CS | DSI_VC_IRQ_ECC_CORR | DSI_VC_IRQ_FIFO_TX_OVF | \
149 DSI_VC_IRQ_FIFO_RX_OVF | DSI_VC_IRQ_ECC_NO_CORR | \
150 DSI_VC_IRQ_FIFO_TX_UDF)
152 /* ComplexIO interrupts */
153 #define DSI_CIO_IRQ_ERRSYNCESC1 (1 << 0)
154 #define DSI_CIO_IRQ_ERRSYNCESC2 (1 << 1)
155 #define DSI_CIO_IRQ_ERRSYNCESC3 (1 << 2)
156 #define DSI_CIO_IRQ_ERRSYNCESC4 (1 << 3)
157 #define DSI_CIO_IRQ_ERRSYNCESC5 (1 << 4)
158 #define DSI_CIO_IRQ_ERRESC1 (1 << 5)
159 #define DSI_CIO_IRQ_ERRESC2 (1 << 6)
160 #define DSI_CIO_IRQ_ERRESC3 (1 << 7)
161 #define DSI_CIO_IRQ_ERRESC4 (1 << 8)
162 #define DSI_CIO_IRQ_ERRESC5 (1 << 9)
163 #define DSI_CIO_IRQ_ERRCONTROL1 (1 << 10)
164 #define DSI_CIO_IRQ_ERRCONTROL2 (1 << 11)
165 #define DSI_CIO_IRQ_ERRCONTROL3 (1 << 12)
166 #define DSI_CIO_IRQ_ERRCONTROL4 (1 << 13)
167 #define DSI_CIO_IRQ_ERRCONTROL5 (1 << 14)
168 #define DSI_CIO_IRQ_STATEULPS1 (1 << 15)
169 #define DSI_CIO_IRQ_STATEULPS2 (1 << 16)
170 #define DSI_CIO_IRQ_STATEULPS3 (1 << 17)
171 #define DSI_CIO_IRQ_STATEULPS4 (1 << 18)
172 #define DSI_CIO_IRQ_STATEULPS5 (1 << 19)
173 #define DSI_CIO_IRQ_ERRCONTENTIONLP0_1 (1 << 20)
174 #define DSI_CIO_IRQ_ERRCONTENTIONLP1_1 (1 << 21)
175 #define DSI_CIO_IRQ_ERRCONTENTIONLP0_2 (1 << 22)
176 #define DSI_CIO_IRQ_ERRCONTENTIONLP1_2 (1 << 23)
177 #define DSI_CIO_IRQ_ERRCONTENTIONLP0_3 (1 << 24)
178 #define DSI_CIO_IRQ_ERRCONTENTIONLP1_3 (1 << 25)
179 #define DSI_CIO_IRQ_ERRCONTENTIONLP0_4 (1 << 26)
180 #define DSI_CIO_IRQ_ERRCONTENTIONLP1_4 (1 << 27)
181 #define DSI_CIO_IRQ_ERRCONTENTIONLP0_5 (1 << 28)
182 #define DSI_CIO_IRQ_ERRCONTENTIONLP1_5 (1 << 29)
183 #define DSI_CIO_IRQ_ULPSACTIVENOT_ALL0 (1 << 30)
184 #define DSI_CIO_IRQ_ULPSACTIVENOT_ALL1 (1 << 31)
185 #define DSI_CIO_IRQ_ERROR_MASK \
186 (DSI_CIO_IRQ_ERRSYNCESC1 | DSI_CIO_IRQ_ERRSYNCESC2 | \
187 DSI_CIO_IRQ_ERRSYNCESC3 | DSI_CIO_IRQ_ERRSYNCESC4 | \
188 DSI_CIO_IRQ_ERRSYNCESC5 | \
189 DSI_CIO_IRQ_ERRESC1 | DSI_CIO_IRQ_ERRESC2 | \
190 DSI_CIO_IRQ_ERRESC3 | DSI_CIO_IRQ_ERRESC4 | \
191 DSI_CIO_IRQ_ERRESC5 | \
192 DSI_CIO_IRQ_ERRCONTROL1 | DSI_CIO_IRQ_ERRCONTROL2 | \
193 DSI_CIO_IRQ_ERRCONTROL3 | DSI_CIO_IRQ_ERRCONTROL4 | \
194 DSI_CIO_IRQ_ERRCONTROL5 | \
195 DSI_CIO_IRQ_ERRCONTENTIONLP0_1 | DSI_CIO_IRQ_ERRCONTENTIONLP1_1 | \
196 DSI_CIO_IRQ_ERRCONTENTIONLP0_2 | DSI_CIO_IRQ_ERRCONTENTIONLP1_2 | \
197 DSI_CIO_IRQ_ERRCONTENTIONLP0_3 | DSI_CIO_IRQ_ERRCONTENTIONLP1_3 | \
198 DSI_CIO_IRQ_ERRCONTENTIONLP0_4 | DSI_CIO_IRQ_ERRCONTENTIONLP1_4 | \
199 DSI_CIO_IRQ_ERRCONTENTIONLP0_5 | DSI_CIO_IRQ_ERRCONTENTIONLP1_5)
201 #define DSI_DT_DCS_SHORT_WRITE_0 0x05
202 #define DSI_DT_DCS_SHORT_WRITE_1 0x15
203 #define DSI_DT_DCS_READ 0x06
204 #define DSI_DT_SET_MAX_RET_PKG_SIZE 0x37
205 #define DSI_DT_NULL_PACKET 0x09
206 #define DSI_DT_DCS_LONG_WRITE 0x39
208 #define DSI_DT_RX_ACK_WITH_ERR 0x02
209 #define DSI_DT_RX_DCS_LONG_READ 0x1c
210 #define DSI_DT_RX_SHORT_READ_1 0x21
211 #define DSI_DT_RX_SHORT_READ_2 0x22
213 typedef void (*omap_dsi_isr_t) (void *arg, u32 mask);
215 #define DSI_MAX_NR_ISRS 2
217 struct dsi_isr_data {
225 DSI_FIFO_SIZE_32 = 1,
226 DSI_FIFO_SIZE_64 = 2,
227 DSI_FIFO_SIZE_96 = 3,
228 DSI_FIFO_SIZE_128 = 4,
239 DSI_DATA1_P = 1 << 2,
240 DSI_DATA1_N = 1 << 3,
241 DSI_DATA2_P = 1 << 4,
242 DSI_DATA2_N = 1 << 5,
243 DSI_DATA3_P = 1 << 6,
244 DSI_DATA3_N = 1 << 7,
245 DSI_DATA4_P = 1 << 8,
246 DSI_DATA4_N = 1 << 9,
249 struct dsi_update_region {
251 struct omap_dss_device *device;
254 struct dsi_irq_stats {
255 unsigned long last_reset;
257 unsigned dsi_irqs[32];
258 unsigned vc_irqs[4][32];
259 unsigned cio_irqs[32];
262 struct dsi_isr_tables {
263 struct dsi_isr_data isr_table[DSI_MAX_NR_ISRS];
264 struct dsi_isr_data isr_table_vc[4][DSI_MAX_NR_ISRS];
265 struct dsi_isr_data isr_table_cio[DSI_MAX_NR_ISRS];
269 struct platform_device *pdev;
277 int (*enable_pads)(int dsi_id, unsigned lane_mask);
278 void (*disable_pads)(int dsi_id, unsigned lane_mask);
280 struct dsi_clock_info current_cinfo;
282 bool vdds_dsi_enabled;
283 struct regulator *vdds_dsi_reg;
286 enum dsi_vc_mode mode;
287 struct omap_dss_device *dssdev;
288 enum fifo_size fifo_size;
293 struct semaphore bus_lock;
298 struct dsi_isr_tables isr_tables;
299 /* space for a copy used by the interrupt handler */
300 struct dsi_isr_tables isr_tables_copy;
303 struct dsi_update_region update_region;
308 void (*framedone_callback)(int, void *);
309 void *framedone_data;
311 struct delayed_work framedone_timeout_work;
313 #ifdef DSI_CATCH_MISSING_TE
314 struct timer_list te_timer;
317 unsigned long cache_req_pck;
318 unsigned long cache_clk_freq;
319 struct dsi_clock_info cache_cinfo;
322 spinlock_t errors_lock;
324 ktime_t perf_setup_time;
325 ktime_t perf_start_time;
330 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
331 spinlock_t irq_stats_lock;
332 struct dsi_irq_stats irq_stats;
334 /* DSI PLL Parameter Ranges */
335 unsigned long regm_max, regn_max;
336 unsigned long regm_dispc_max, regm_dsi_max;
337 unsigned long fint_min, fint_max;
338 unsigned long lpdiv_max;
342 unsigned scp_clk_refcount;
345 struct dsi_packet_sent_handler_data {
346 struct platform_device *dsidev;
347 struct completion *completion;
350 static struct platform_device *dsi_pdev_map[MAX_NUM_DSI];
353 static unsigned int dsi_perf;
354 module_param_named(dsi_perf, dsi_perf, bool, 0644);
357 static inline struct dsi_data *dsi_get_dsidrv_data(struct platform_device *dsidev)
359 return dev_get_drvdata(&dsidev->dev);
362 static inline struct platform_device *dsi_get_dsidev_from_dssdev(struct omap_dss_device *dssdev)
364 return dsi_pdev_map[dssdev->phy.dsi.module];
367 struct platform_device *dsi_get_dsidev_from_id(int module)
369 return dsi_pdev_map[module];
372 static inline int dsi_get_dsidev_id(struct platform_device *dsidev)
377 static inline void dsi_write_reg(struct platform_device *dsidev,
378 const struct dsi_reg idx, u32 val)
380 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
382 __raw_writel(val, dsi->base + idx.idx);
385 static inline u32 dsi_read_reg(struct platform_device *dsidev,
386 const struct dsi_reg idx)
388 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
390 return __raw_readl(dsi->base + idx.idx);
393 void dsi_bus_lock(struct omap_dss_device *dssdev)
395 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
396 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
398 down(&dsi->bus_lock);
400 EXPORT_SYMBOL(dsi_bus_lock);
402 void dsi_bus_unlock(struct omap_dss_device *dssdev)
404 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
405 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
409 EXPORT_SYMBOL(dsi_bus_unlock);
411 static bool dsi_bus_is_locked(struct platform_device *dsidev)
413 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
415 return dsi->bus_lock.count == 0;
418 static void dsi_completion_handler(void *data, u32 mask)
420 complete((struct completion *)data);
423 static inline int wait_for_bit_change(struct platform_device *dsidev,
424 const struct dsi_reg idx, int bitnum, int value)
428 while (REG_GET(dsidev, idx, bitnum, bitnum) != value) {
437 static void dsi_perf_mark_setup(struct platform_device *dsidev)
439 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
440 dsi->perf_setup_time = ktime_get();
443 static void dsi_perf_mark_start(struct platform_device *dsidev)
445 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
446 dsi->perf_start_time = ktime_get();
449 static void dsi_perf_show(struct platform_device *dsidev, const char *name)
451 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
452 ktime_t t, setup_time, trans_time;
454 u32 setup_us, trans_us, total_us;
461 setup_time = ktime_sub(dsi->perf_start_time, dsi->perf_setup_time);
462 setup_us = (u32)ktime_to_us(setup_time);
466 trans_time = ktime_sub(t, dsi->perf_start_time);
467 trans_us = (u32)ktime_to_us(trans_time);
471 total_us = setup_us + trans_us;
473 total_bytes = dsi->update_region.w *
474 dsi->update_region.h *
475 dsi->update_region.device->ctrl.pixel_size / 8;
477 printk(KERN_INFO "DSI(%s): %u us + %u us = %u us (%uHz), "
478 "%u bytes, %u kbytes/sec\n",
483 1000*1000 / total_us,
485 total_bytes * 1000 / total_us);
488 static inline void dsi_perf_mark_setup(struct platform_device *dsidev)
492 static inline void dsi_perf_mark_start(struct platform_device *dsidev)
496 static inline void dsi_perf_show(struct platform_device *dsidev,
502 static void print_irq_status(u32 status)
508 if ((status & ~DSI_IRQ_CHANNEL_MASK) == 0)
511 printk(KERN_DEBUG "DSI IRQ: 0x%x: ", status);
514 if (status & DSI_IRQ_##x) \
540 static void print_irq_status_vc(int channel, u32 status)
546 if ((status & ~DSI_VC_IRQ_PACKET_SENT) == 0)
549 printk(KERN_DEBUG "DSI VC(%d) IRQ 0x%x: ", channel, status);
552 if (status & DSI_VC_IRQ_##x) \
569 static void print_irq_status_cio(u32 status)
574 printk(KERN_DEBUG "DSI CIO IRQ 0x%x: ", status);
577 if (status & DSI_CIO_IRQ_##x) \
591 PIS(ERRCONTENTIONLP0_1);
592 PIS(ERRCONTENTIONLP1_1);
593 PIS(ERRCONTENTIONLP0_2);
594 PIS(ERRCONTENTIONLP1_2);
595 PIS(ERRCONTENTIONLP0_3);
596 PIS(ERRCONTENTIONLP1_3);
597 PIS(ULPSACTIVENOT_ALL0);
598 PIS(ULPSACTIVENOT_ALL1);
604 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
605 static void dsi_collect_irq_stats(struct platform_device *dsidev, u32 irqstatus,
606 u32 *vcstatus, u32 ciostatus)
608 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
611 spin_lock(&dsi->irq_stats_lock);
613 dsi->irq_stats.irq_count++;
614 dss_collect_irq_stats(irqstatus, dsi->irq_stats.dsi_irqs);
616 for (i = 0; i < 4; ++i)
617 dss_collect_irq_stats(vcstatus[i], dsi->irq_stats.vc_irqs[i]);
619 dss_collect_irq_stats(ciostatus, dsi->irq_stats.cio_irqs);
621 spin_unlock(&dsi->irq_stats_lock);
624 #define dsi_collect_irq_stats(dsidev, irqstatus, vcstatus, ciostatus)
627 static int debug_irq;
629 static void dsi_handle_irq_errors(struct platform_device *dsidev, u32 irqstatus,
630 u32 *vcstatus, u32 ciostatus)
632 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
635 if (irqstatus & DSI_IRQ_ERROR_MASK) {
636 DSSERR("DSI error, irqstatus %x\n", irqstatus);
637 print_irq_status(irqstatus);
638 spin_lock(&dsi->errors_lock);
639 dsi->errors |= irqstatus & DSI_IRQ_ERROR_MASK;
640 spin_unlock(&dsi->errors_lock);
641 } else if (debug_irq) {
642 print_irq_status(irqstatus);
645 for (i = 0; i < 4; ++i) {
646 if (vcstatus[i] & DSI_VC_IRQ_ERROR_MASK) {
647 DSSERR("DSI VC(%d) error, vc irqstatus %x\n",
649 print_irq_status_vc(i, vcstatus[i]);
650 } else if (debug_irq) {
651 print_irq_status_vc(i, vcstatus[i]);
655 if (ciostatus & DSI_CIO_IRQ_ERROR_MASK) {
656 DSSERR("DSI CIO error, cio irqstatus %x\n", ciostatus);
657 print_irq_status_cio(ciostatus);
658 } else if (debug_irq) {
659 print_irq_status_cio(ciostatus);
663 static void dsi_call_isrs(struct dsi_isr_data *isr_array,
664 unsigned isr_array_size, u32 irqstatus)
666 struct dsi_isr_data *isr_data;
669 for (i = 0; i < isr_array_size; i++) {
670 isr_data = &isr_array[i];
671 if (isr_data->isr && isr_data->mask & irqstatus)
672 isr_data->isr(isr_data->arg, irqstatus);
676 static void dsi_handle_isrs(struct dsi_isr_tables *isr_tables,
677 u32 irqstatus, u32 *vcstatus, u32 ciostatus)
681 dsi_call_isrs(isr_tables->isr_table,
682 ARRAY_SIZE(isr_tables->isr_table),
685 for (i = 0; i < 4; ++i) {
686 if (vcstatus[i] == 0)
688 dsi_call_isrs(isr_tables->isr_table_vc[i],
689 ARRAY_SIZE(isr_tables->isr_table_vc[i]),
694 dsi_call_isrs(isr_tables->isr_table_cio,
695 ARRAY_SIZE(isr_tables->isr_table_cio),
699 static irqreturn_t omap_dsi_irq_handler(int irq, void *arg)
701 struct platform_device *dsidev;
702 struct dsi_data *dsi;
703 u32 irqstatus, vcstatus[4], ciostatus;
706 dsidev = (struct platform_device *) arg;
707 dsi = dsi_get_dsidrv_data(dsidev);
709 spin_lock(&dsi->irq_lock);
711 irqstatus = dsi_read_reg(dsidev, DSI_IRQSTATUS);
713 /* IRQ is not for us */
715 spin_unlock(&dsi->irq_lock);
719 dsi_write_reg(dsidev, DSI_IRQSTATUS, irqstatus & ~DSI_IRQ_CHANNEL_MASK);
720 /* flush posted write */
721 dsi_read_reg(dsidev, DSI_IRQSTATUS);
723 for (i = 0; i < 4; ++i) {
724 if ((irqstatus & (1 << i)) == 0) {
729 vcstatus[i] = dsi_read_reg(dsidev, DSI_VC_IRQSTATUS(i));
731 dsi_write_reg(dsidev, DSI_VC_IRQSTATUS(i), vcstatus[i]);
732 /* flush posted write */
733 dsi_read_reg(dsidev, DSI_VC_IRQSTATUS(i));
736 if (irqstatus & DSI_IRQ_COMPLEXIO_ERR) {
737 ciostatus = dsi_read_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS);
739 dsi_write_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS, ciostatus);
740 /* flush posted write */
741 dsi_read_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS);
746 #ifdef DSI_CATCH_MISSING_TE
747 if (irqstatus & DSI_IRQ_TE_TRIGGER)
748 del_timer(&dsi->te_timer);
751 /* make a copy and unlock, so that isrs can unregister
753 memcpy(&dsi->isr_tables_copy, &dsi->isr_tables,
754 sizeof(dsi->isr_tables));
756 spin_unlock(&dsi->irq_lock);
758 dsi_handle_isrs(&dsi->isr_tables_copy, irqstatus, vcstatus, ciostatus);
760 dsi_handle_irq_errors(dsidev, irqstatus, vcstatus, ciostatus);
762 dsi_collect_irq_stats(dsidev, irqstatus, vcstatus, ciostatus);
767 /* dsi->irq_lock has to be locked by the caller */
768 static void _omap_dsi_configure_irqs(struct platform_device *dsidev,
769 struct dsi_isr_data *isr_array,
770 unsigned isr_array_size, u32 default_mask,
771 const struct dsi_reg enable_reg,
772 const struct dsi_reg status_reg)
774 struct dsi_isr_data *isr_data;
781 for (i = 0; i < isr_array_size; i++) {
782 isr_data = &isr_array[i];
784 if (isr_data->isr == NULL)
787 mask |= isr_data->mask;
790 old_mask = dsi_read_reg(dsidev, enable_reg);
791 /* clear the irqstatus for newly enabled irqs */
792 dsi_write_reg(dsidev, status_reg, (mask ^ old_mask) & mask);
793 dsi_write_reg(dsidev, enable_reg, mask);
795 /* flush posted writes */
796 dsi_read_reg(dsidev, enable_reg);
797 dsi_read_reg(dsidev, status_reg);
800 /* dsi->irq_lock has to be locked by the caller */
801 static void _omap_dsi_set_irqs(struct platform_device *dsidev)
803 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
804 u32 mask = DSI_IRQ_ERROR_MASK;
805 #ifdef DSI_CATCH_MISSING_TE
806 mask |= DSI_IRQ_TE_TRIGGER;
808 _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table,
809 ARRAY_SIZE(dsi->isr_tables.isr_table), mask,
810 DSI_IRQENABLE, DSI_IRQSTATUS);
813 /* dsi->irq_lock has to be locked by the caller */
814 static void _omap_dsi_set_irqs_vc(struct platform_device *dsidev, int vc)
816 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
818 _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table_vc[vc],
819 ARRAY_SIZE(dsi->isr_tables.isr_table_vc[vc]),
820 DSI_VC_IRQ_ERROR_MASK,
821 DSI_VC_IRQENABLE(vc), DSI_VC_IRQSTATUS(vc));
824 /* dsi->irq_lock has to be locked by the caller */
825 static void _omap_dsi_set_irqs_cio(struct platform_device *dsidev)
827 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
829 _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table_cio,
830 ARRAY_SIZE(dsi->isr_tables.isr_table_cio),
831 DSI_CIO_IRQ_ERROR_MASK,
832 DSI_COMPLEXIO_IRQ_ENABLE, DSI_COMPLEXIO_IRQ_STATUS);
835 static void _dsi_initialize_irq(struct platform_device *dsidev)
837 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
841 spin_lock_irqsave(&dsi->irq_lock, flags);
843 memset(&dsi->isr_tables, 0, sizeof(dsi->isr_tables));
845 _omap_dsi_set_irqs(dsidev);
846 for (vc = 0; vc < 4; ++vc)
847 _omap_dsi_set_irqs_vc(dsidev, vc);
848 _omap_dsi_set_irqs_cio(dsidev);
850 spin_unlock_irqrestore(&dsi->irq_lock, flags);
853 static int _dsi_register_isr(omap_dsi_isr_t isr, void *arg, u32 mask,
854 struct dsi_isr_data *isr_array, unsigned isr_array_size)
856 struct dsi_isr_data *isr_data;
862 /* check for duplicate entry and find a free slot */
864 for (i = 0; i < isr_array_size; i++) {
865 isr_data = &isr_array[i];
867 if (isr_data->isr == isr && isr_data->arg == arg &&
868 isr_data->mask == mask) {
872 if (isr_data->isr == NULL && free_idx == -1)
879 isr_data = &isr_array[free_idx];
882 isr_data->mask = mask;
887 static int _dsi_unregister_isr(omap_dsi_isr_t isr, void *arg, u32 mask,
888 struct dsi_isr_data *isr_array, unsigned isr_array_size)
890 struct dsi_isr_data *isr_data;
893 for (i = 0; i < isr_array_size; i++) {
894 isr_data = &isr_array[i];
895 if (isr_data->isr != isr || isr_data->arg != arg ||
896 isr_data->mask != mask)
899 isr_data->isr = NULL;
900 isr_data->arg = NULL;
909 static int dsi_register_isr(struct platform_device *dsidev, omap_dsi_isr_t isr,
912 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
916 spin_lock_irqsave(&dsi->irq_lock, flags);
918 r = _dsi_register_isr(isr, arg, mask, dsi->isr_tables.isr_table,
919 ARRAY_SIZE(dsi->isr_tables.isr_table));
922 _omap_dsi_set_irqs(dsidev);
924 spin_unlock_irqrestore(&dsi->irq_lock, flags);
929 static int dsi_unregister_isr(struct platform_device *dsidev,
930 omap_dsi_isr_t isr, void *arg, u32 mask)
932 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
936 spin_lock_irqsave(&dsi->irq_lock, flags);
938 r = _dsi_unregister_isr(isr, arg, mask, dsi->isr_tables.isr_table,
939 ARRAY_SIZE(dsi->isr_tables.isr_table));
942 _omap_dsi_set_irqs(dsidev);
944 spin_unlock_irqrestore(&dsi->irq_lock, flags);
949 static int dsi_register_isr_vc(struct platform_device *dsidev, int channel,
950 omap_dsi_isr_t isr, void *arg, u32 mask)
952 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
956 spin_lock_irqsave(&dsi->irq_lock, flags);
958 r = _dsi_register_isr(isr, arg, mask,
959 dsi->isr_tables.isr_table_vc[channel],
960 ARRAY_SIZE(dsi->isr_tables.isr_table_vc[channel]));
963 _omap_dsi_set_irqs_vc(dsidev, channel);
965 spin_unlock_irqrestore(&dsi->irq_lock, flags);
970 static int dsi_unregister_isr_vc(struct platform_device *dsidev, int channel,
971 omap_dsi_isr_t isr, void *arg, u32 mask)
973 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
977 spin_lock_irqsave(&dsi->irq_lock, flags);
979 r = _dsi_unregister_isr(isr, arg, mask,
980 dsi->isr_tables.isr_table_vc[channel],
981 ARRAY_SIZE(dsi->isr_tables.isr_table_vc[channel]));
984 _omap_dsi_set_irqs_vc(dsidev, channel);
986 spin_unlock_irqrestore(&dsi->irq_lock, flags);
991 static int dsi_register_isr_cio(struct platform_device *dsidev,
992 omap_dsi_isr_t isr, void *arg, u32 mask)
994 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
998 spin_lock_irqsave(&dsi->irq_lock, flags);
1000 r = _dsi_register_isr(isr, arg, mask, dsi->isr_tables.isr_table_cio,
1001 ARRAY_SIZE(dsi->isr_tables.isr_table_cio));
1004 _omap_dsi_set_irqs_cio(dsidev);
1006 spin_unlock_irqrestore(&dsi->irq_lock, flags);
1011 static int dsi_unregister_isr_cio(struct platform_device *dsidev,
1012 omap_dsi_isr_t isr, void *arg, u32 mask)
1014 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1015 unsigned long flags;
1018 spin_lock_irqsave(&dsi->irq_lock, flags);
1020 r = _dsi_unregister_isr(isr, arg, mask, dsi->isr_tables.isr_table_cio,
1021 ARRAY_SIZE(dsi->isr_tables.isr_table_cio));
1024 _omap_dsi_set_irqs_cio(dsidev);
1026 spin_unlock_irqrestore(&dsi->irq_lock, flags);
1031 static u32 dsi_get_errors(struct platform_device *dsidev)
1033 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1034 unsigned long flags;
1036 spin_lock_irqsave(&dsi->errors_lock, flags);
1039 spin_unlock_irqrestore(&dsi->errors_lock, flags);
1043 int dsi_runtime_get(struct platform_device *dsidev)
1046 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1048 DSSDBG("dsi_runtime_get\n");
1050 r = pm_runtime_get_sync(&dsi->pdev->dev);
1052 return r < 0 ? r : 0;
1055 void dsi_runtime_put(struct platform_device *dsidev)
1057 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1060 DSSDBG("dsi_runtime_put\n");
1062 r = pm_runtime_put(&dsi->pdev->dev);
1066 /* source clock for DSI PLL. this could also be PCLKFREE */
1067 static inline void dsi_enable_pll_clock(struct platform_device *dsidev,
1070 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1073 clk_enable(dsi->sys_clk);
1075 clk_disable(dsi->sys_clk);
1077 if (enable && dsi->pll_locked) {
1078 if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 1, 1) != 1)
1079 DSSERR("cannot lock PLL when enabling clocks\n");
1084 static void _dsi_print_reset_status(struct platform_device *dsidev)
1092 /* A dummy read using the SCP interface to any DSIPHY register is
1093 * required after DSIPHY reset to complete the reset of the DSI complex
1095 l = dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
1097 printk(KERN_DEBUG "DSI resets: ");
1099 l = dsi_read_reg(dsidev, DSI_PLL_STATUS);
1100 printk("PLL (%d) ", FLD_GET(l, 0, 0));
1102 l = dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1);
1103 printk("CIO (%d) ", FLD_GET(l, 29, 29));
1105 if (dss_has_feature(FEAT_DSI_REVERSE_TXCLKESC)) {
1115 l = dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
1116 printk("PHY (%x%x%x, %d, %d, %d)\n",
1122 FLD_GET(l, 31, 31));
1125 #define _dsi_print_reset_status(x)
1128 static inline int dsi_if_enable(struct platform_device *dsidev, bool enable)
1130 DSSDBG("dsi_if_enable(%d)\n", enable);
1132 enable = enable ? 1 : 0;
1133 REG_FLD_MOD(dsidev, DSI_CTRL, enable, 0, 0); /* IF_EN */
1135 if (wait_for_bit_change(dsidev, DSI_CTRL, 0, enable) != enable) {
1136 DSSERR("Failed to set dsi_if_enable to %d\n", enable);
1143 unsigned long dsi_get_pll_hsdiv_dispc_rate(struct platform_device *dsidev)
1145 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1147 return dsi->current_cinfo.dsi_pll_hsdiv_dispc_clk;
1150 static unsigned long dsi_get_pll_hsdiv_dsi_rate(struct platform_device *dsidev)
1152 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1154 return dsi->current_cinfo.dsi_pll_hsdiv_dsi_clk;
1157 static unsigned long dsi_get_txbyteclkhs(struct platform_device *dsidev)
1159 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1161 return dsi->current_cinfo.clkin4ddr / 16;
1164 static unsigned long dsi_fclk_rate(struct platform_device *dsidev)
1167 int dsi_module = dsi_get_dsidev_id(dsidev);
1168 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1170 if (dss_get_dsi_clk_source(dsi_module) == OMAP_DSS_CLK_SRC_FCK) {
1171 /* DSI FCLK source is DSS_CLK_FCK */
1172 r = clk_get_rate(dsi->dss_clk);
1174 /* DSI FCLK source is dsi_pll_hsdiv_dsi_clk */
1175 r = dsi_get_pll_hsdiv_dsi_rate(dsidev);
1181 static int dsi_set_lp_clk_divisor(struct omap_dss_device *dssdev)
1183 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
1184 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1185 unsigned long dsi_fclk;
1186 unsigned lp_clk_div;
1187 unsigned long lp_clk;
1189 lp_clk_div = dssdev->clocks.dsi.lp_clk_div;
1191 if (lp_clk_div == 0 || lp_clk_div > dsi->lpdiv_max)
1194 dsi_fclk = dsi_fclk_rate(dsidev);
1196 lp_clk = dsi_fclk / 2 / lp_clk_div;
1198 DSSDBG("LP_CLK_DIV %u, LP_CLK %lu\n", lp_clk_div, lp_clk);
1199 dsi->current_cinfo.lp_clk = lp_clk;
1200 dsi->current_cinfo.lp_clk_div = lp_clk_div;
1202 /* LP_CLK_DIVISOR */
1203 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, lp_clk_div, 12, 0);
1205 /* LP_RX_SYNCHRO_ENABLE */
1206 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, dsi_fclk > 30000000 ? 1 : 0, 21, 21);
1211 static void dsi_enable_scp_clk(struct platform_device *dsidev)
1213 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1215 if (dsi->scp_clk_refcount++ == 0)
1216 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 1, 14, 14); /* CIO_CLK_ICG */
1219 static void dsi_disable_scp_clk(struct platform_device *dsidev)
1221 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1223 WARN_ON(dsi->scp_clk_refcount == 0);
1224 if (--dsi->scp_clk_refcount == 0)
1225 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 14, 14); /* CIO_CLK_ICG */
1228 enum dsi_pll_power_state {
1229 DSI_PLL_POWER_OFF = 0x0,
1230 DSI_PLL_POWER_ON_HSCLK = 0x1,
1231 DSI_PLL_POWER_ON_ALL = 0x2,
1232 DSI_PLL_POWER_ON_DIV = 0x3,
1235 static int dsi_pll_power(struct platform_device *dsidev,
1236 enum dsi_pll_power_state state)
1240 /* DSI-PLL power command 0x3 is not working */
1241 if (dss_has_feature(FEAT_DSI_PLL_PWR_BUG) &&
1242 state == DSI_PLL_POWER_ON_DIV)
1243 state = DSI_PLL_POWER_ON_ALL;
1246 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, state, 31, 30);
1248 /* PLL_PWR_STATUS */
1249 while (FLD_GET(dsi_read_reg(dsidev, DSI_CLK_CTRL), 29, 28) != state) {
1251 DSSERR("Failed to set DSI PLL power mode to %d\n",
1261 /* calculate clock rates using dividers in cinfo */
1262 static int dsi_calc_clock_rates(struct omap_dss_device *dssdev,
1263 struct dsi_clock_info *cinfo)
1265 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
1266 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1268 if (cinfo->regn == 0 || cinfo->regn > dsi->regn_max)
1271 if (cinfo->regm == 0 || cinfo->regm > dsi->regm_max)
1274 if (cinfo->regm_dispc > dsi->regm_dispc_max)
1277 if (cinfo->regm_dsi > dsi->regm_dsi_max)
1280 if (cinfo->use_sys_clk) {
1281 cinfo->clkin = clk_get_rate(dsi->sys_clk);
1282 /* XXX it is unclear if highfreq should be used
1283 * with DSS_SYS_CLK source also */
1284 cinfo->highfreq = 0;
1286 cinfo->clkin = dispc_pclk_rate(dssdev->manager->id);
1288 if (cinfo->clkin < 32000000)
1289 cinfo->highfreq = 0;
1291 cinfo->highfreq = 1;
1294 cinfo->fint = cinfo->clkin / (cinfo->regn * (cinfo->highfreq ? 2 : 1));
1296 if (cinfo->fint > dsi->fint_max || cinfo->fint < dsi->fint_min)
1299 cinfo->clkin4ddr = 2 * cinfo->regm * cinfo->fint;
1301 if (cinfo->clkin4ddr > 1800 * 1000 * 1000)
1304 if (cinfo->regm_dispc > 0)
1305 cinfo->dsi_pll_hsdiv_dispc_clk =
1306 cinfo->clkin4ddr / cinfo->regm_dispc;
1308 cinfo->dsi_pll_hsdiv_dispc_clk = 0;
1310 if (cinfo->regm_dsi > 0)
1311 cinfo->dsi_pll_hsdiv_dsi_clk =
1312 cinfo->clkin4ddr / cinfo->regm_dsi;
1314 cinfo->dsi_pll_hsdiv_dsi_clk = 0;
1319 int dsi_pll_calc_clock_div_pck(struct platform_device *dsidev, bool is_tft,
1320 unsigned long req_pck, struct dsi_clock_info *dsi_cinfo,
1321 struct dispc_clock_info *dispc_cinfo)
1323 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1324 struct dsi_clock_info cur, best;
1325 struct dispc_clock_info best_dispc;
1326 int min_fck_per_pck;
1328 unsigned long dss_sys_clk, max_dss_fck;
1330 dss_sys_clk = clk_get_rate(dsi->sys_clk);
1332 max_dss_fck = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK);
1334 if (req_pck == dsi->cache_req_pck &&
1335 dsi->cache_cinfo.clkin == dss_sys_clk) {
1336 DSSDBG("DSI clock info found from cache\n");
1337 *dsi_cinfo = dsi->cache_cinfo;
1338 dispc_find_clk_divs(is_tft, req_pck,
1339 dsi_cinfo->dsi_pll_hsdiv_dispc_clk, dispc_cinfo);
1343 min_fck_per_pck = CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK;
1345 if (min_fck_per_pck &&
1346 req_pck * min_fck_per_pck > max_dss_fck) {
1347 DSSERR("Requested pixel clock not possible with the current "
1348 "OMAP2_DSS_MIN_FCK_PER_PCK setting. Turning "
1349 "the constraint off.\n");
1350 min_fck_per_pck = 0;
1353 DSSDBG("dsi_pll_calc\n");
1356 memset(&best, 0, sizeof(best));
1357 memset(&best_dispc, 0, sizeof(best_dispc));
1359 memset(&cur, 0, sizeof(cur));
1360 cur.clkin = dss_sys_clk;
1361 cur.use_sys_clk = 1;
1364 /* no highfreq: 0.75MHz < Fint = clkin / regn < 2.1MHz */
1365 /* highfreq: 0.75MHz < Fint = clkin / (2*regn) < 2.1MHz */
1366 /* To reduce PLL lock time, keep Fint high (around 2 MHz) */
1367 for (cur.regn = 1; cur.regn < dsi->regn_max; ++cur.regn) {
1368 if (cur.highfreq == 0)
1369 cur.fint = cur.clkin / cur.regn;
1371 cur.fint = cur.clkin / (2 * cur.regn);
1373 if (cur.fint > dsi->fint_max || cur.fint < dsi->fint_min)
1376 /* DSIPHY(MHz) = (2 * regm / regn) * (clkin / (highfreq + 1)) */
1377 for (cur.regm = 1; cur.regm < dsi->regm_max; ++cur.regm) {
1380 a = 2 * cur.regm * (cur.clkin/1000);
1381 b = cur.regn * (cur.highfreq + 1);
1382 cur.clkin4ddr = a / b * 1000;
1384 if (cur.clkin4ddr > 1800 * 1000 * 1000)
1387 /* dsi_pll_hsdiv_dispc_clk(MHz) =
1388 * DSIPHY(MHz) / regm_dispc < 173MHz/186Mhz */
1389 for (cur.regm_dispc = 1; cur.regm_dispc <
1390 dsi->regm_dispc_max; ++cur.regm_dispc) {
1391 struct dispc_clock_info cur_dispc;
1392 cur.dsi_pll_hsdiv_dispc_clk =
1393 cur.clkin4ddr / cur.regm_dispc;
1395 /* this will narrow down the search a bit,
1396 * but still give pixclocks below what was
1398 if (cur.dsi_pll_hsdiv_dispc_clk < req_pck)
1401 if (cur.dsi_pll_hsdiv_dispc_clk > max_dss_fck)
1404 if (min_fck_per_pck &&
1405 cur.dsi_pll_hsdiv_dispc_clk <
1406 req_pck * min_fck_per_pck)
1411 dispc_find_clk_divs(is_tft, req_pck,
1412 cur.dsi_pll_hsdiv_dispc_clk,
1415 if (abs(cur_dispc.pck - req_pck) <
1416 abs(best_dispc.pck - req_pck)) {
1418 best_dispc = cur_dispc;
1420 if (cur_dispc.pck == req_pck)
1428 if (min_fck_per_pck) {
1429 DSSERR("Could not find suitable clock settings.\n"
1430 "Turning FCK/PCK constraint off and"
1432 min_fck_per_pck = 0;
1436 DSSERR("Could not find suitable clock settings.\n");
1441 /* dsi_pll_hsdiv_dsi_clk (regm_dsi) is not used */
1443 best.dsi_pll_hsdiv_dsi_clk = 0;
1448 *dispc_cinfo = best_dispc;
1450 dsi->cache_req_pck = req_pck;
1451 dsi->cache_clk_freq = 0;
1452 dsi->cache_cinfo = best;
1457 int dsi_pll_set_clock_div(struct platform_device *dsidev,
1458 struct dsi_clock_info *cinfo)
1460 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1464 u8 regn_start, regn_end, regm_start, regm_end;
1465 u8 regm_dispc_start, regm_dispc_end, regm_dsi_start, regm_dsi_end;
1469 dsi->current_cinfo.use_sys_clk = cinfo->use_sys_clk;
1470 dsi->current_cinfo.highfreq = cinfo->highfreq;
1472 dsi->current_cinfo.fint = cinfo->fint;
1473 dsi->current_cinfo.clkin4ddr = cinfo->clkin4ddr;
1474 dsi->current_cinfo.dsi_pll_hsdiv_dispc_clk =
1475 cinfo->dsi_pll_hsdiv_dispc_clk;
1476 dsi->current_cinfo.dsi_pll_hsdiv_dsi_clk =
1477 cinfo->dsi_pll_hsdiv_dsi_clk;
1479 dsi->current_cinfo.regn = cinfo->regn;
1480 dsi->current_cinfo.regm = cinfo->regm;
1481 dsi->current_cinfo.regm_dispc = cinfo->regm_dispc;
1482 dsi->current_cinfo.regm_dsi = cinfo->regm_dsi;
1484 DSSDBG("DSI Fint %ld\n", cinfo->fint);
1486 DSSDBG("clkin (%s) rate %ld, highfreq %d\n",
1487 cinfo->use_sys_clk ? "dss_sys_clk" : "pclkfree",
1491 /* DSIPHY == CLKIN4DDR */
1492 DSSDBG("CLKIN4DDR = 2 * %d / %d * %lu / %d = %lu\n",
1496 cinfo->highfreq + 1,
1499 DSSDBG("Data rate on 1 DSI lane %ld Mbps\n",
1500 cinfo->clkin4ddr / 1000 / 1000 / 2);
1502 DSSDBG("Clock lane freq %ld Hz\n", cinfo->clkin4ddr / 4);
1504 DSSDBG("regm_dispc = %d, %s (%s) = %lu\n", cinfo->regm_dispc,
1505 dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
1506 dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
1507 cinfo->dsi_pll_hsdiv_dispc_clk);
1508 DSSDBG("regm_dsi = %d, %s (%s) = %lu\n", cinfo->regm_dsi,
1509 dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
1510 dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
1511 cinfo->dsi_pll_hsdiv_dsi_clk);
1513 dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGN, ®n_start, ®n_end);
1514 dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM, ®m_start, ®m_end);
1515 dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM_DISPC, ®m_dispc_start,
1517 dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM_DSI, ®m_dsi_start,
1520 /* DSI_PLL_AUTOMODE = manual */
1521 REG_FLD_MOD(dsidev, DSI_PLL_CONTROL, 0, 0, 0);
1523 l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION1);
1524 l = FLD_MOD(l, 1, 0, 0); /* DSI_PLL_STOPMODE */
1526 l = FLD_MOD(l, cinfo->regn - 1, regn_start, regn_end);
1528 l = FLD_MOD(l, cinfo->regm, regm_start, regm_end);
1530 l = FLD_MOD(l, cinfo->regm_dispc > 0 ? cinfo->regm_dispc - 1 : 0,
1531 regm_dispc_start, regm_dispc_end);
1532 /* DSIPROTO_CLOCK_DIV */
1533 l = FLD_MOD(l, cinfo->regm_dsi > 0 ? cinfo->regm_dsi - 1 : 0,
1534 regm_dsi_start, regm_dsi_end);
1535 dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION1, l);
1537 BUG_ON(cinfo->fint < dsi->fint_min || cinfo->fint > dsi->fint_max);
1539 if (dss_has_feature(FEAT_DSI_PLL_FREQSEL)) {
1540 f = cinfo->fint < 1000000 ? 0x3 :
1541 cinfo->fint < 1250000 ? 0x4 :
1542 cinfo->fint < 1500000 ? 0x5 :
1543 cinfo->fint < 1750000 ? 0x6 :
1547 l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION2);
1549 if (dss_has_feature(FEAT_DSI_PLL_FREQSEL))
1550 l = FLD_MOD(l, f, 4, 1); /* DSI_PLL_FREQSEL */
1551 l = FLD_MOD(l, cinfo->use_sys_clk ? 0 : 1,
1552 11, 11); /* DSI_PLL_CLKSEL */
1553 l = FLD_MOD(l, cinfo->highfreq,
1554 12, 12); /* DSI_PLL_HIGHFREQ */
1555 l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */
1556 l = FLD_MOD(l, 0, 14, 14); /* DSIPHY_CLKINEN */
1557 l = FLD_MOD(l, 1, 20, 20); /* DSI_HSDIVBYPASS */
1558 dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION2, l);
1560 REG_FLD_MOD(dsidev, DSI_PLL_GO, 1, 0, 0); /* DSI_PLL_GO */
1562 if (wait_for_bit_change(dsidev, DSI_PLL_GO, 0, 0) != 0) {
1563 DSSERR("dsi pll go bit not going down.\n");
1568 if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 1, 1) != 1) {
1569 DSSERR("cannot lock PLL\n");
1574 dsi->pll_locked = 1;
1576 l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION2);
1577 l = FLD_MOD(l, 0, 0, 0); /* DSI_PLL_IDLE */
1578 l = FLD_MOD(l, 0, 5, 5); /* DSI_PLL_PLLLPMODE */
1579 l = FLD_MOD(l, 0, 6, 6); /* DSI_PLL_LOWCURRSTBY */
1580 l = FLD_MOD(l, 0, 7, 7); /* DSI_PLL_TIGHTPHASELOCK */
1581 l = FLD_MOD(l, 0, 8, 8); /* DSI_PLL_DRIFTGUARDEN */
1582 l = FLD_MOD(l, 0, 10, 9); /* DSI_PLL_LOCKSEL */
1583 l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */
1584 l = FLD_MOD(l, 1, 14, 14); /* DSIPHY_CLKINEN */
1585 l = FLD_MOD(l, 0, 15, 15); /* DSI_BYPASSEN */
1586 l = FLD_MOD(l, 1, 16, 16); /* DSS_CLOCK_EN */
1587 l = FLD_MOD(l, 0, 17, 17); /* DSS_CLOCK_PWDN */
1588 l = FLD_MOD(l, 1, 18, 18); /* DSI_PROTO_CLOCK_EN */
1589 l = FLD_MOD(l, 0, 19, 19); /* DSI_PROTO_CLOCK_PWDN */
1590 l = FLD_MOD(l, 0, 20, 20); /* DSI_HSDIVBYPASS */
1591 dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION2, l);
1593 DSSDBG("PLL config done\n");
1598 int dsi_pll_init(struct platform_device *dsidev, bool enable_hsclk,
1601 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1603 enum dsi_pll_power_state pwstate;
1605 DSSDBG("PLL init\n");
1607 if (dsi->vdds_dsi_reg == NULL) {
1608 struct regulator *vdds_dsi;
1610 vdds_dsi = regulator_get(&dsi->pdev->dev, "vdds_dsi");
1612 if (IS_ERR(vdds_dsi)) {
1613 DSSERR("can't get VDDS_DSI regulator\n");
1614 return PTR_ERR(vdds_dsi);
1617 dsi->vdds_dsi_reg = vdds_dsi;
1620 dsi_enable_pll_clock(dsidev, 1);
1622 * Note: SCP CLK is not required on OMAP3, but it is required on OMAP4.
1624 dsi_enable_scp_clk(dsidev);
1626 if (!dsi->vdds_dsi_enabled) {
1627 r = regulator_enable(dsi->vdds_dsi_reg);
1630 dsi->vdds_dsi_enabled = true;
1633 /* XXX PLL does not come out of reset without this... */
1634 dispc_pck_free_enable(1);
1636 if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 0, 1) != 1) {
1637 DSSERR("PLL not coming out of reset.\n");
1639 dispc_pck_free_enable(0);
1643 /* XXX ... but if left on, we get problems when planes do not
1644 * fill the whole display. No idea about this */
1645 dispc_pck_free_enable(0);
1647 if (enable_hsclk && enable_hsdiv)
1648 pwstate = DSI_PLL_POWER_ON_ALL;
1649 else if (enable_hsclk)
1650 pwstate = DSI_PLL_POWER_ON_HSCLK;
1651 else if (enable_hsdiv)
1652 pwstate = DSI_PLL_POWER_ON_DIV;
1654 pwstate = DSI_PLL_POWER_OFF;
1656 r = dsi_pll_power(dsidev, pwstate);
1661 DSSDBG("PLL init done\n");
1665 if (dsi->vdds_dsi_enabled) {
1666 regulator_disable(dsi->vdds_dsi_reg);
1667 dsi->vdds_dsi_enabled = false;
1670 dsi_disable_scp_clk(dsidev);
1671 dsi_enable_pll_clock(dsidev, 0);
1675 void dsi_pll_uninit(struct platform_device *dsidev, bool disconnect_lanes)
1677 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1679 dsi->pll_locked = 0;
1680 dsi_pll_power(dsidev, DSI_PLL_POWER_OFF);
1681 if (disconnect_lanes) {
1682 WARN_ON(!dsi->vdds_dsi_enabled);
1683 regulator_disable(dsi->vdds_dsi_reg);
1684 dsi->vdds_dsi_enabled = false;
1687 dsi_disable_scp_clk(dsidev);
1688 dsi_enable_pll_clock(dsidev, 0);
1690 DSSDBG("PLL uninit done\n");
1693 static void dsi_dump_dsidev_clocks(struct platform_device *dsidev,
1696 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1697 struct dsi_clock_info *cinfo = &dsi->current_cinfo;
1698 enum omap_dss_clk_source dispc_clk_src, dsi_clk_src;
1699 int dsi_module = dsi_get_dsidev_id(dsidev);
1701 dispc_clk_src = dss_get_dispc_clk_source();
1702 dsi_clk_src = dss_get_dsi_clk_source(dsi_module);
1704 if (dsi_runtime_get(dsidev))
1707 seq_printf(s, "- DSI%d PLL -\n", dsi_module + 1);
1709 seq_printf(s, "dsi pll source = %s\n",
1710 cinfo->use_sys_clk ? "dss_sys_clk" : "pclkfree");
1712 seq_printf(s, "Fint\t\t%-16luregn %u\n", cinfo->fint, cinfo->regn);
1714 seq_printf(s, "CLKIN4DDR\t%-16luregm %u\n",
1715 cinfo->clkin4ddr, cinfo->regm);
1717 seq_printf(s, "%s (%s)\t%-16luregm_dispc %u\t(%s)\n",
1718 dss_get_generic_clk_source_name(dispc_clk_src),
1719 dss_feat_get_clk_source_name(dispc_clk_src),
1720 cinfo->dsi_pll_hsdiv_dispc_clk,
1722 dispc_clk_src == OMAP_DSS_CLK_SRC_FCK ?
1725 seq_printf(s, "%s (%s)\t%-16luregm_dsi %u\t(%s)\n",
1726 dss_get_generic_clk_source_name(dsi_clk_src),
1727 dss_feat_get_clk_source_name(dsi_clk_src),
1728 cinfo->dsi_pll_hsdiv_dsi_clk,
1730 dsi_clk_src == OMAP_DSS_CLK_SRC_FCK ?
1733 seq_printf(s, "- DSI%d -\n", dsi_module + 1);
1735 seq_printf(s, "dsi fclk source = %s (%s)\n",
1736 dss_get_generic_clk_source_name(dsi_clk_src),
1737 dss_feat_get_clk_source_name(dsi_clk_src));
1739 seq_printf(s, "DSI_FCLK\t%lu\n", dsi_fclk_rate(dsidev));
1741 seq_printf(s, "DDR_CLK\t\t%lu\n",
1742 cinfo->clkin4ddr / 4);
1744 seq_printf(s, "TxByteClkHS\t%lu\n", dsi_get_txbyteclkhs(dsidev));
1746 seq_printf(s, "LP_CLK\t\t%lu\n", cinfo->lp_clk);
1748 dsi_runtime_put(dsidev);
1751 void dsi_dump_clocks(struct seq_file *s)
1753 struct platform_device *dsidev;
1756 for (i = 0; i < MAX_NUM_DSI; i++) {
1757 dsidev = dsi_get_dsidev_from_id(i);
1759 dsi_dump_dsidev_clocks(dsidev, s);
1763 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
1764 static void dsi_dump_dsidev_irqs(struct platform_device *dsidev,
1767 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1768 unsigned long flags;
1769 struct dsi_irq_stats stats;
1770 int dsi_module = dsi_get_dsidev_id(dsidev);
1772 spin_lock_irqsave(&dsi->irq_stats_lock, flags);
1774 stats = dsi->irq_stats;
1775 memset(&dsi->irq_stats, 0, sizeof(dsi->irq_stats));
1776 dsi->irq_stats.last_reset = jiffies;
1778 spin_unlock_irqrestore(&dsi->irq_stats_lock, flags);
1780 seq_printf(s, "period %u ms\n",
1781 jiffies_to_msecs(jiffies - stats.last_reset));
1783 seq_printf(s, "irqs %d\n", stats.irq_count);
1785 seq_printf(s, "%-20s %10d\n", #x, stats.dsi_irqs[ffs(DSI_IRQ_##x)-1]);
1787 seq_printf(s, "-- DSI%d interrupts --\n", dsi_module + 1);
1803 PIS(LDO_POWER_GOOD);
1808 seq_printf(s, "%-20s %10d %10d %10d %10d\n", #x, \
1809 stats.vc_irqs[0][ffs(DSI_VC_IRQ_##x)-1], \
1810 stats.vc_irqs[1][ffs(DSI_VC_IRQ_##x)-1], \
1811 stats.vc_irqs[2][ffs(DSI_VC_IRQ_##x)-1], \
1812 stats.vc_irqs[3][ffs(DSI_VC_IRQ_##x)-1]);
1814 seq_printf(s, "-- VC interrupts --\n");
1823 PIS(PP_BUSY_CHANGE);
1827 seq_printf(s, "%-20s %10d\n", #x, \
1828 stats.cio_irqs[ffs(DSI_CIO_IRQ_##x)-1]);
1830 seq_printf(s, "-- CIO interrupts --\n");
1843 PIS(ERRCONTENTIONLP0_1);
1844 PIS(ERRCONTENTIONLP1_1);
1845 PIS(ERRCONTENTIONLP0_2);
1846 PIS(ERRCONTENTIONLP1_2);
1847 PIS(ERRCONTENTIONLP0_3);
1848 PIS(ERRCONTENTIONLP1_3);
1849 PIS(ULPSACTIVENOT_ALL0);
1850 PIS(ULPSACTIVENOT_ALL1);
1854 static void dsi1_dump_irqs(struct seq_file *s)
1856 struct platform_device *dsidev = dsi_get_dsidev_from_id(0);
1858 dsi_dump_dsidev_irqs(dsidev, s);
1861 static void dsi2_dump_irqs(struct seq_file *s)
1863 struct platform_device *dsidev = dsi_get_dsidev_from_id(1);
1865 dsi_dump_dsidev_irqs(dsidev, s);
1868 void dsi_create_debugfs_files_irq(struct dentry *debugfs_dir,
1869 const struct file_operations *debug_fops)
1871 struct platform_device *dsidev;
1873 dsidev = dsi_get_dsidev_from_id(0);
1875 debugfs_create_file("dsi1_irqs", S_IRUGO, debugfs_dir,
1876 &dsi1_dump_irqs, debug_fops);
1878 dsidev = dsi_get_dsidev_from_id(1);
1880 debugfs_create_file("dsi2_irqs", S_IRUGO, debugfs_dir,
1881 &dsi2_dump_irqs, debug_fops);
1885 static void dsi_dump_dsidev_regs(struct platform_device *dsidev,
1888 #define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dsi_read_reg(dsidev, r))
1890 if (dsi_runtime_get(dsidev))
1892 dsi_enable_scp_clk(dsidev);
1894 DUMPREG(DSI_REVISION);
1895 DUMPREG(DSI_SYSCONFIG);
1896 DUMPREG(DSI_SYSSTATUS);
1897 DUMPREG(DSI_IRQSTATUS);
1898 DUMPREG(DSI_IRQENABLE);
1900 DUMPREG(DSI_COMPLEXIO_CFG1);
1901 DUMPREG(DSI_COMPLEXIO_IRQ_STATUS);
1902 DUMPREG(DSI_COMPLEXIO_IRQ_ENABLE);
1903 DUMPREG(DSI_CLK_CTRL);
1904 DUMPREG(DSI_TIMING1);
1905 DUMPREG(DSI_TIMING2);
1906 DUMPREG(DSI_VM_TIMING1);
1907 DUMPREG(DSI_VM_TIMING2);
1908 DUMPREG(DSI_VM_TIMING3);
1909 DUMPREG(DSI_CLK_TIMING);
1910 DUMPREG(DSI_TX_FIFO_VC_SIZE);
1911 DUMPREG(DSI_RX_FIFO_VC_SIZE);
1912 DUMPREG(DSI_COMPLEXIO_CFG2);
1913 DUMPREG(DSI_RX_FIFO_VC_FULLNESS);
1914 DUMPREG(DSI_VM_TIMING4);
1915 DUMPREG(DSI_TX_FIFO_VC_EMPTINESS);
1916 DUMPREG(DSI_VM_TIMING5);
1917 DUMPREG(DSI_VM_TIMING6);
1918 DUMPREG(DSI_VM_TIMING7);
1919 DUMPREG(DSI_STOPCLK_TIMING);
1921 DUMPREG(DSI_VC_CTRL(0));
1922 DUMPREG(DSI_VC_TE(0));
1923 DUMPREG(DSI_VC_LONG_PACKET_HEADER(0));
1924 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(0));
1925 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(0));
1926 DUMPREG(DSI_VC_IRQSTATUS(0));
1927 DUMPREG(DSI_VC_IRQENABLE(0));
1929 DUMPREG(DSI_VC_CTRL(1));
1930 DUMPREG(DSI_VC_TE(1));
1931 DUMPREG(DSI_VC_LONG_PACKET_HEADER(1));
1932 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(1));
1933 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(1));
1934 DUMPREG(DSI_VC_IRQSTATUS(1));
1935 DUMPREG(DSI_VC_IRQENABLE(1));
1937 DUMPREG(DSI_VC_CTRL(2));
1938 DUMPREG(DSI_VC_TE(2));
1939 DUMPREG(DSI_VC_LONG_PACKET_HEADER(2));
1940 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(2));
1941 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(2));
1942 DUMPREG(DSI_VC_IRQSTATUS(2));
1943 DUMPREG(DSI_VC_IRQENABLE(2));
1945 DUMPREG(DSI_VC_CTRL(3));
1946 DUMPREG(DSI_VC_TE(3));
1947 DUMPREG(DSI_VC_LONG_PACKET_HEADER(3));
1948 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(3));
1949 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(3));
1950 DUMPREG(DSI_VC_IRQSTATUS(3));
1951 DUMPREG(DSI_VC_IRQENABLE(3));
1953 DUMPREG(DSI_DSIPHY_CFG0);
1954 DUMPREG(DSI_DSIPHY_CFG1);
1955 DUMPREG(DSI_DSIPHY_CFG2);
1956 DUMPREG(DSI_DSIPHY_CFG5);
1958 DUMPREG(DSI_PLL_CONTROL);
1959 DUMPREG(DSI_PLL_STATUS);
1960 DUMPREG(DSI_PLL_GO);
1961 DUMPREG(DSI_PLL_CONFIGURATION1);
1962 DUMPREG(DSI_PLL_CONFIGURATION2);
1964 dsi_disable_scp_clk(dsidev);
1965 dsi_runtime_put(dsidev);
1969 static void dsi1_dump_regs(struct seq_file *s)
1971 struct platform_device *dsidev = dsi_get_dsidev_from_id(0);
1973 dsi_dump_dsidev_regs(dsidev, s);
1976 static void dsi2_dump_regs(struct seq_file *s)
1978 struct platform_device *dsidev = dsi_get_dsidev_from_id(1);
1980 dsi_dump_dsidev_regs(dsidev, s);
1983 void dsi_create_debugfs_files_reg(struct dentry *debugfs_dir,
1984 const struct file_operations *debug_fops)
1986 struct platform_device *dsidev;
1988 dsidev = dsi_get_dsidev_from_id(0);
1990 debugfs_create_file("dsi1_regs", S_IRUGO, debugfs_dir,
1991 &dsi1_dump_regs, debug_fops);
1993 dsidev = dsi_get_dsidev_from_id(1);
1995 debugfs_create_file("dsi2_regs", S_IRUGO, debugfs_dir,
1996 &dsi2_dump_regs, debug_fops);
1998 enum dsi_cio_power_state {
1999 DSI_COMPLEXIO_POWER_OFF = 0x0,
2000 DSI_COMPLEXIO_POWER_ON = 0x1,
2001 DSI_COMPLEXIO_POWER_ULPS = 0x2,
2004 static int dsi_cio_power(struct platform_device *dsidev,
2005 enum dsi_cio_power_state state)
2010 REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG1, state, 28, 27);
2013 while (FLD_GET(dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1),
2016 DSSERR("failed to set complexio power state to "
2026 /* Number of data lanes present on DSI interface */
2027 static inline int dsi_get_num_data_lanes(struct platform_device *dsidev)
2029 /* DSI on OMAP3 doesn't have register DSI_GNQ, set number
2030 * of data lanes as 2 by default */
2031 if (dss_has_feature(FEAT_DSI_GNQ))
2032 return REG_GET(dsidev, DSI_GNQ, 11, 9); /* NB_DATA_LANES */
2037 /* Number of data lanes used by the dss device */
2038 static inline int dsi_get_num_data_lanes_dssdev(struct omap_dss_device *dssdev)
2040 int num_data_lanes = 0;
2042 if (dssdev->phy.dsi.data1_lane != 0)
2044 if (dssdev->phy.dsi.data2_lane != 0)
2046 if (dssdev->phy.dsi.data3_lane != 0)
2048 if (dssdev->phy.dsi.data4_lane != 0)
2051 return num_data_lanes;
2054 static unsigned dsi_get_line_buf_size(struct platform_device *dsidev)
2058 /* line buffer on OMAP3 is 1024 x 24bits */
2059 /* XXX: for some reason using full buffer size causes
2060 * considerable TX slowdown with update sizes that fill the
2062 if (!dss_has_feature(FEAT_DSI_GNQ))
2065 val = REG_GET(dsidev, DSI_GNQ, 14, 12); /* VP1_LINE_BUFFER_SIZE */
2069 return 512 * 3; /* 512x24 bits */
2071 return 682 * 3; /* 682x24 bits */
2073 return 853 * 3; /* 853x24 bits */
2075 return 1024 * 3; /* 1024x24 bits */
2077 return 1194 * 3; /* 1194x24 bits */
2079 return 1365 * 3; /* 1365x24 bits */
2085 static void dsi_set_lane_config(struct omap_dss_device *dssdev)
2087 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
2089 int num_data_lanes_dssdev = dsi_get_num_data_lanes_dssdev(dssdev);
2091 int clk_lane = dssdev->phy.dsi.clk_lane;
2092 int data1_lane = dssdev->phy.dsi.data1_lane;
2093 int data2_lane = dssdev->phy.dsi.data2_lane;
2094 int clk_pol = dssdev->phy.dsi.clk_pol;
2095 int data1_pol = dssdev->phy.dsi.data1_pol;
2096 int data2_pol = dssdev->phy.dsi.data2_pol;
2098 r = dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1);
2099 r = FLD_MOD(r, clk_lane, 2, 0);
2100 r = FLD_MOD(r, clk_pol, 3, 3);
2101 r = FLD_MOD(r, data1_lane, 6, 4);
2102 r = FLD_MOD(r, data1_pol, 7, 7);
2103 r = FLD_MOD(r, data2_lane, 10, 8);
2104 r = FLD_MOD(r, data2_pol, 11, 11);
2105 if (num_data_lanes_dssdev > 2) {
2106 int data3_lane = dssdev->phy.dsi.data3_lane;
2107 int data3_pol = dssdev->phy.dsi.data3_pol;
2109 r = FLD_MOD(r, data3_lane, 14, 12);
2110 r = FLD_MOD(r, data3_pol, 15, 15);
2112 if (num_data_lanes_dssdev > 3) {
2113 int data4_lane = dssdev->phy.dsi.data4_lane;
2114 int data4_pol = dssdev->phy.dsi.data4_pol;
2116 r = FLD_MOD(r, data4_lane, 18, 16);
2117 r = FLD_MOD(r, data4_pol, 19, 19);
2119 dsi_write_reg(dsidev, DSI_COMPLEXIO_CFG1, r);
2121 /* The configuration of the DSI complex I/O (number of data lanes,
2122 position, differential order) should not be changed while
2123 DSS.DSI_CLK_CRTRL[20] LP_CLK_ENABLE bit is set to 1. In order for
2124 the hardware to take into account a new configuration of the complex
2125 I/O (done in DSS.DSI_COMPLEXIO_CFG1 register), it is recommended to
2126 follow this sequence: First set the DSS.DSI_CTRL[0] IF_EN bit to 1,
2127 then reset the DSS.DSI_CTRL[0] IF_EN to 0, then set
2128 DSS.DSI_CLK_CTRL[20] LP_CLK_ENABLE to 1 and finally set again the
2129 DSS.DSI_CTRL[0] IF_EN bit to 1. If the sequence is not followed, the
2130 DSI complex I/O configuration is unknown. */
2133 REG_FLD_MOD(dsidev, DSI_CTRL, 1, 0, 0);
2134 REG_FLD_MOD(dsidev, DSI_CTRL, 0, 0, 0);
2135 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 1, 20, 20);
2136 REG_FLD_MOD(dsidev, DSI_CTRL, 1, 0, 0);
2140 static inline unsigned ns2ddr(struct platform_device *dsidev, unsigned ns)
2142 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2144 /* convert time in ns to ddr ticks, rounding up */
2145 unsigned long ddr_clk = dsi->current_cinfo.clkin4ddr / 4;
2146 return (ns * (ddr_clk / 1000 / 1000) + 999) / 1000;
2149 static inline unsigned ddr2ns(struct platform_device *dsidev, unsigned ddr)
2151 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2153 unsigned long ddr_clk = dsi->current_cinfo.clkin4ddr / 4;
2154 return ddr * 1000 * 1000 / (ddr_clk / 1000);
2157 static void dsi_cio_timings(struct platform_device *dsidev)
2160 u32 ths_prepare, ths_prepare_ths_zero, ths_trail, ths_exit;
2161 u32 tlpx_half, tclk_trail, tclk_zero;
2164 /* calculate timings */
2166 /* 1 * DDR_CLK = 2 * UI */
2168 /* min 40ns + 4*UI max 85ns + 6*UI */
2169 ths_prepare = ns2ddr(dsidev, 70) + 2;
2171 /* min 145ns + 10*UI */
2172 ths_prepare_ths_zero = ns2ddr(dsidev, 175) + 2;
2174 /* min max(8*UI, 60ns+4*UI) */
2175 ths_trail = ns2ddr(dsidev, 60) + 5;
2178 ths_exit = ns2ddr(dsidev, 145);
2181 tlpx_half = ns2ddr(dsidev, 25);
2184 tclk_trail = ns2ddr(dsidev, 60) + 2;
2186 /* min 38ns, max 95ns */
2187 tclk_prepare = ns2ddr(dsidev, 65);
2189 /* min tclk-prepare + tclk-zero = 300ns */
2190 tclk_zero = ns2ddr(dsidev, 260);
2192 DSSDBG("ths_prepare %u (%uns), ths_prepare_ths_zero %u (%uns)\n",
2193 ths_prepare, ddr2ns(dsidev, ths_prepare),
2194 ths_prepare_ths_zero, ddr2ns(dsidev, ths_prepare_ths_zero));
2195 DSSDBG("ths_trail %u (%uns), ths_exit %u (%uns)\n",
2196 ths_trail, ddr2ns(dsidev, ths_trail),
2197 ths_exit, ddr2ns(dsidev, ths_exit));
2199 DSSDBG("tlpx_half %u (%uns), tclk_trail %u (%uns), "
2200 "tclk_zero %u (%uns)\n",
2201 tlpx_half, ddr2ns(dsidev, tlpx_half),
2202 tclk_trail, ddr2ns(dsidev, tclk_trail),
2203 tclk_zero, ddr2ns(dsidev, tclk_zero));
2204 DSSDBG("tclk_prepare %u (%uns)\n",
2205 tclk_prepare, ddr2ns(dsidev, tclk_prepare));
2207 /* program timings */
2209 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0);
2210 r = FLD_MOD(r, ths_prepare, 31, 24);
2211 r = FLD_MOD(r, ths_prepare_ths_zero, 23, 16);
2212 r = FLD_MOD(r, ths_trail, 15, 8);
2213 r = FLD_MOD(r, ths_exit, 7, 0);
2214 dsi_write_reg(dsidev, DSI_DSIPHY_CFG0, r);
2216 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1);
2217 r = FLD_MOD(r, tlpx_half, 22, 16);
2218 r = FLD_MOD(r, tclk_trail, 15, 8);
2219 r = FLD_MOD(r, tclk_zero, 7, 0);
2220 dsi_write_reg(dsidev, DSI_DSIPHY_CFG1, r);
2222 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG2);
2223 r = FLD_MOD(r, tclk_prepare, 7, 0);
2224 dsi_write_reg(dsidev, DSI_DSIPHY_CFG2, r);
2227 static void dsi_cio_enable_lane_override(struct omap_dss_device *dssdev,
2228 enum dsi_lane lanes)
2230 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
2231 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2232 int clk_lane = dssdev->phy.dsi.clk_lane;
2233 int data1_lane = dssdev->phy.dsi.data1_lane;
2234 int data2_lane = dssdev->phy.dsi.data2_lane;
2235 int data3_lane = dssdev->phy.dsi.data3_lane;
2236 int data4_lane = dssdev->phy.dsi.data4_lane;
2237 int clk_pol = dssdev->phy.dsi.clk_pol;
2238 int data1_pol = dssdev->phy.dsi.data1_pol;
2239 int data2_pol = dssdev->phy.dsi.data2_pol;
2240 int data3_pol = dssdev->phy.dsi.data3_pol;
2241 int data4_pol = dssdev->phy.dsi.data4_pol;
2244 u8 lptxscp_start = dsi->num_data_lanes == 2 ? 22 : 26;
2246 if (lanes & DSI_CLK_P)
2247 l |= 1 << ((clk_lane - 1) * 2 + (clk_pol ? 0 : 1));
2248 if (lanes & DSI_CLK_N)
2249 l |= 1 << ((clk_lane - 1) * 2 + (clk_pol ? 1 : 0));
2251 if (lanes & DSI_DATA1_P)
2252 l |= 1 << ((data1_lane - 1) * 2 + (data1_pol ? 0 : 1));
2253 if (lanes & DSI_DATA1_N)
2254 l |= 1 << ((data1_lane - 1) * 2 + (data1_pol ? 1 : 0));
2256 if (lanes & DSI_DATA2_P)
2257 l |= 1 << ((data2_lane - 1) * 2 + (data2_pol ? 0 : 1));
2258 if (lanes & DSI_DATA2_N)
2259 l |= 1 << ((data2_lane - 1) * 2 + (data2_pol ? 1 : 0));
2261 if (lanes & DSI_DATA3_P)
2262 l |= 1 << ((data3_lane - 1) * 2 + (data3_pol ? 0 : 1));
2263 if (lanes & DSI_DATA3_N)
2264 l |= 1 << ((data3_lane - 1) * 2 + (data3_pol ? 1 : 0));
2266 if (lanes & DSI_DATA4_P)
2267 l |= 1 << ((data4_lane - 1) * 2 + (data4_pol ? 0 : 1));
2268 if (lanes & DSI_DATA4_N)
2269 l |= 1 << ((data4_lane - 1) * 2 + (data4_pol ? 1 : 0));
2271 * Bits in REGLPTXSCPDAT4TO0DXDY:
2279 /* Set the lane override configuration */
2281 /* REGLPTXSCPDAT4TO0DXDY */
2282 REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, l, lptxscp_start, 17);
2284 /* Enable lane override */
2287 REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 1, 27, 27);
2290 static void dsi_cio_disable_lane_override(struct platform_device *dsidev)
2292 /* Disable lane override */
2293 REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 0, 27, 27); /* ENLPTXSCPDAT */
2294 /* Reset the lane override configuration */
2295 /* REGLPTXSCPDAT4TO0DXDY */
2296 REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 0, 22, 17);
2299 static int dsi_cio_wait_tx_clk_esc_reset(struct omap_dss_device *dssdev)
2301 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
2306 if (dss_has_feature(FEAT_DSI_REVERSE_TXCLKESC)) {
2320 if (dssdev->phy.dsi.clk_lane != 0)
2321 in_use[dssdev->phy.dsi.clk_lane - 1] = true;
2322 if (dssdev->phy.dsi.data1_lane != 0)
2323 in_use[dssdev->phy.dsi.data1_lane - 1] = true;
2324 if (dssdev->phy.dsi.data2_lane != 0)
2325 in_use[dssdev->phy.dsi.data2_lane - 1] = true;
2333 l = dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
2336 for (i = 0; i < 3; ++i) {
2337 if (!in_use[i] || (l & (1 << bits[i])))
2345 for (i = 0; i < 3; ++i) {
2346 if (!in_use[i] || (l & (1 << bits[i])))
2349 DSSERR("CIO TXCLKESC%d domain not coming " \
2350 "out of reset\n", i);
2359 static unsigned dsi_get_lane_mask(struct omap_dss_device *dssdev)
2363 if (dssdev->phy.dsi.clk_lane != 0)
2364 lanes |= 1 << (dssdev->phy.dsi.clk_lane - 1);
2365 if (dssdev->phy.dsi.data1_lane != 0)
2366 lanes |= 1 << (dssdev->phy.dsi.data1_lane - 1);
2367 if (dssdev->phy.dsi.data2_lane != 0)
2368 lanes |= 1 << (dssdev->phy.dsi.data2_lane - 1);
2369 if (dssdev->phy.dsi.data3_lane != 0)
2370 lanes |= 1 << (dssdev->phy.dsi.data3_lane - 1);
2371 if (dssdev->phy.dsi.data4_lane != 0)
2372 lanes |= 1 << (dssdev->phy.dsi.data4_lane - 1);
2377 static int dsi_cio_init(struct omap_dss_device *dssdev)
2379 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
2380 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2382 int num_data_lanes_dssdev = dsi_get_num_data_lanes_dssdev(dssdev);
2387 r = dsi->enable_pads(dsidev->id, dsi_get_lane_mask(dssdev));
2391 dsi_enable_scp_clk(dsidev);
2393 /* A dummy read using the SCP interface to any DSIPHY register is
2394 * required after DSIPHY reset to complete the reset of the DSI complex
2396 dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
2398 if (wait_for_bit_change(dsidev, DSI_DSIPHY_CFG5, 30, 1) != 1) {
2399 DSSERR("CIO SCP Clock domain not coming out of reset.\n");
2401 goto err_scp_clk_dom;
2404 dsi_set_lane_config(dssdev);
2406 /* set TX STOP MODE timer to maximum for this operation */
2407 l = dsi_read_reg(dsidev, DSI_TIMING1);
2408 l = FLD_MOD(l, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
2409 l = FLD_MOD(l, 1, 14, 14); /* STOP_STATE_X16_IO */
2410 l = FLD_MOD(l, 1, 13, 13); /* STOP_STATE_X4_IO */
2411 l = FLD_MOD(l, 0x1fff, 12, 0); /* STOP_STATE_COUNTER_IO */
2412 dsi_write_reg(dsidev, DSI_TIMING1, l);
2414 if (dsi->ulps_enabled) {
2415 u32 lane_mask = DSI_CLK_P | DSI_DATA1_P | DSI_DATA2_P;
2417 DSSDBG("manual ulps exit\n");
2419 /* ULPS is exited by Mark-1 state for 1ms, followed by
2420 * stop state. DSS HW cannot do this via the normal
2421 * ULPS exit sequence, as after reset the DSS HW thinks
2422 * that we are not in ULPS mode, and refuses to send the
2423 * sequence. So we need to send the ULPS exit sequence
2427 if (num_data_lanes_dssdev > 2)
2428 lane_mask |= DSI_DATA3_P;
2430 if (num_data_lanes_dssdev > 3)
2431 lane_mask |= DSI_DATA4_P;
2433 dsi_cio_enable_lane_override(dssdev, lane_mask);
2436 r = dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_ON);
2440 if (wait_for_bit_change(dsidev, DSI_COMPLEXIO_CFG1, 29, 1) != 1) {
2441 DSSERR("CIO PWR clock domain not coming out of reset.\n");
2443 goto err_cio_pwr_dom;
2446 dsi_if_enable(dsidev, true);
2447 dsi_if_enable(dsidev, false);
2448 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 1, 20, 20); /* LP_CLK_ENABLE */
2450 r = dsi_cio_wait_tx_clk_esc_reset(dssdev);
2452 goto err_tx_clk_esc_rst;
2454 if (dsi->ulps_enabled) {
2455 /* Keep Mark-1 state for 1ms (as per DSI spec) */
2456 ktime_t wait = ns_to_ktime(1000 * 1000);
2457 set_current_state(TASK_UNINTERRUPTIBLE);
2458 schedule_hrtimeout(&wait, HRTIMER_MODE_REL);
2460 /* Disable the override. The lanes should be set to Mark-11
2461 * state by the HW */
2462 dsi_cio_disable_lane_override(dsidev);
2465 /* FORCE_TX_STOP_MODE_IO */
2466 REG_FLD_MOD(dsidev, DSI_TIMING1, 0, 15, 15);
2468 dsi_cio_timings(dsidev);
2470 dsi->ulps_enabled = false;
2472 DSSDBG("CIO init done\n");
2477 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 20, 20); /* LP_CLK_ENABLE */
2479 dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_OFF);
2481 if (dsi->ulps_enabled)
2482 dsi_cio_disable_lane_override(dsidev);
2484 dsi_disable_scp_clk(dsidev);
2485 dsi->disable_pads(dsidev->id, dsi_get_lane_mask(dssdev));
2489 static void dsi_cio_uninit(struct omap_dss_device *dssdev)
2491 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
2492 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2494 dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_OFF);
2495 dsi_disable_scp_clk(dsidev);
2496 dsi->disable_pads(dsidev->id, dsi_get_lane_mask(dssdev));
2499 static void dsi_config_tx_fifo(struct platform_device *dsidev,
2500 enum fifo_size size1, enum fifo_size size2,
2501 enum fifo_size size3, enum fifo_size size4)
2503 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2508 dsi->vc[0].fifo_size = size1;
2509 dsi->vc[1].fifo_size = size2;
2510 dsi->vc[2].fifo_size = size3;
2511 dsi->vc[3].fifo_size = size4;
2513 for (i = 0; i < 4; i++) {
2515 int size = dsi->vc[i].fifo_size;
2517 if (add + size > 4) {
2518 DSSERR("Illegal FIFO configuration\n");
2522 v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
2524 /*DSSDBG("TX FIFO vc %d: size %d, add %d\n", i, size, add); */
2528 dsi_write_reg(dsidev, DSI_TX_FIFO_VC_SIZE, r);
2531 static void dsi_config_rx_fifo(struct platform_device *dsidev,
2532 enum fifo_size size1, enum fifo_size size2,
2533 enum fifo_size size3, enum fifo_size size4)
2535 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2540 dsi->vc[0].fifo_size = size1;
2541 dsi->vc[1].fifo_size = size2;
2542 dsi->vc[2].fifo_size = size3;
2543 dsi->vc[3].fifo_size = size4;
2545 for (i = 0; i < 4; i++) {
2547 int size = dsi->vc[i].fifo_size;
2549 if (add + size > 4) {
2550 DSSERR("Illegal FIFO configuration\n");
2554 v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
2556 /*DSSDBG("RX FIFO vc %d: size %d, add %d\n", i, size, add); */
2560 dsi_write_reg(dsidev, DSI_RX_FIFO_VC_SIZE, r);
2563 static int dsi_force_tx_stop_mode_io(struct platform_device *dsidev)
2567 r = dsi_read_reg(dsidev, DSI_TIMING1);
2568 r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
2569 dsi_write_reg(dsidev, DSI_TIMING1, r);
2571 if (wait_for_bit_change(dsidev, DSI_TIMING1, 15, 0) != 0) {
2572 DSSERR("TX_STOP bit not going down\n");
2579 static bool dsi_vc_is_enabled(struct platform_device *dsidev, int channel)
2581 return REG_GET(dsidev, DSI_VC_CTRL(channel), 0, 0);
2584 static void dsi_packet_sent_handler_vp(void *data, u32 mask)
2586 struct dsi_packet_sent_handler_data *vp_data =
2587 (struct dsi_packet_sent_handler_data *) data;
2588 struct dsi_data *dsi = dsi_get_dsidrv_data(vp_data->dsidev);
2589 const int channel = dsi->update_channel;
2590 u8 bit = dsi->te_enabled ? 30 : 31;
2592 if (REG_GET(vp_data->dsidev, DSI_VC_TE(channel), bit, bit) == 0)
2593 complete(vp_data->completion);
2596 static int dsi_sync_vc_vp(struct platform_device *dsidev, int channel)
2598 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2599 DECLARE_COMPLETION_ONSTACK(completion);
2600 struct dsi_packet_sent_handler_data vp_data = { dsidev, &completion };
2604 bit = dsi->te_enabled ? 30 : 31;
2606 r = dsi_register_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp,
2607 &vp_data, DSI_VC_IRQ_PACKET_SENT);
2611 /* Wait for completion only if TE_EN/TE_START is still set */
2612 if (REG_GET(dsidev, DSI_VC_TE(channel), bit, bit)) {
2613 if (wait_for_completion_timeout(&completion,
2614 msecs_to_jiffies(10)) == 0) {
2615 DSSERR("Failed to complete previous frame transfer\n");
2621 dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp,
2622 &vp_data, DSI_VC_IRQ_PACKET_SENT);
2626 dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp,
2627 &vp_data, DSI_VC_IRQ_PACKET_SENT);
2632 static void dsi_packet_sent_handler_l4(void *data, u32 mask)
2634 struct dsi_packet_sent_handler_data *l4_data =
2635 (struct dsi_packet_sent_handler_data *) data;
2636 struct dsi_data *dsi = dsi_get_dsidrv_data(l4_data->dsidev);
2637 const int channel = dsi->update_channel;
2639 if (REG_GET(l4_data->dsidev, DSI_VC_CTRL(channel), 5, 5) == 0)
2640 complete(l4_data->completion);
2643 static int dsi_sync_vc_l4(struct platform_device *dsidev, int channel)
2645 DECLARE_COMPLETION_ONSTACK(completion);
2646 struct dsi_packet_sent_handler_data l4_data = { dsidev, &completion };
2649 r = dsi_register_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4,
2650 &l4_data, DSI_VC_IRQ_PACKET_SENT);
2654 /* Wait for completion only if TX_FIFO_NOT_EMPTY is still set */
2655 if (REG_GET(dsidev, DSI_VC_CTRL(channel), 5, 5)) {
2656 if (wait_for_completion_timeout(&completion,
2657 msecs_to_jiffies(10)) == 0) {
2658 DSSERR("Failed to complete previous l4 transfer\n");
2664 dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4,
2665 &l4_data, DSI_VC_IRQ_PACKET_SENT);
2669 dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4,
2670 &l4_data, DSI_VC_IRQ_PACKET_SENT);
2675 static int dsi_sync_vc(struct platform_device *dsidev, int channel)
2677 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2679 WARN_ON(!dsi_bus_is_locked(dsidev));
2681 WARN_ON(in_interrupt());
2683 if (!dsi_vc_is_enabled(dsidev, channel))
2686 switch (dsi->vc[channel].mode) {
2687 case DSI_VC_MODE_VP:
2688 return dsi_sync_vc_vp(dsidev, channel);
2689 case DSI_VC_MODE_L4:
2690 return dsi_sync_vc_l4(dsidev, channel);
2696 static int dsi_vc_enable(struct platform_device *dsidev, int channel,
2699 DSSDBG("dsi_vc_enable channel %d, enable %d\n",
2702 enable = enable ? 1 : 0;
2704 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 0, 0);
2706 if (wait_for_bit_change(dsidev, DSI_VC_CTRL(channel),
2707 0, enable) != enable) {
2708 DSSERR("Failed to set dsi_vc_enable to %d\n", enable);
2715 static void dsi_vc_initial_config(struct platform_device *dsidev, int channel)
2719 DSSDBGF("%d", channel);
2721 r = dsi_read_reg(dsidev, DSI_VC_CTRL(channel));
2723 if (FLD_GET(r, 15, 15)) /* VC_BUSY */
2724 DSSERR("VC(%d) busy when trying to configure it!\n",
2727 r = FLD_MOD(r, 0, 1, 1); /* SOURCE, 0 = L4 */
2728 r = FLD_MOD(r, 0, 2, 2); /* BTA_SHORT_EN */
2729 r = FLD_MOD(r, 0, 3, 3); /* BTA_LONG_EN */
2730 r = FLD_MOD(r, 0, 4, 4); /* MODE, 0 = command */
2731 r = FLD_MOD(r, 1, 7, 7); /* CS_TX_EN */
2732 r = FLD_MOD(r, 1, 8, 8); /* ECC_TX_EN */
2733 r = FLD_MOD(r, 0, 9, 9); /* MODE_SPEED, high speed on/off */
2734 if (dss_has_feature(FEAT_DSI_VC_OCP_WIDTH))
2735 r = FLD_MOD(r, 3, 11, 10); /* OCP_WIDTH = 32 bit */
2737 r = FLD_MOD(r, 4, 29, 27); /* DMA_RX_REQ_NB = no dma */
2738 r = FLD_MOD(r, 4, 23, 21); /* DMA_TX_REQ_NB = no dma */
2740 dsi_write_reg(dsidev, DSI_VC_CTRL(channel), r);
2743 static int dsi_vc_config_l4(struct platform_device *dsidev, int channel)
2745 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2747 if (dsi->vc[channel].mode == DSI_VC_MODE_L4)
2750 DSSDBGF("%d", channel);
2752 dsi_sync_vc(dsidev, channel);
2754 dsi_vc_enable(dsidev, channel, 0);
2757 if (wait_for_bit_change(dsidev, DSI_VC_CTRL(channel), 15, 0) != 0) {
2758 DSSERR("vc(%d) busy when trying to config for L4\n", channel);
2762 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 0, 1, 1); /* SOURCE, 0 = L4 */
2764 /* DCS_CMD_ENABLE */
2765 if (dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC))
2766 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 0, 30, 30);
2768 dsi_vc_enable(dsidev, channel, 1);
2770 dsi->vc[channel].mode = DSI_VC_MODE_L4;
2775 static int dsi_vc_config_vp(struct platform_device *dsidev, int channel)
2777 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2779 if (dsi->vc[channel].mode == DSI_VC_MODE_VP)
2782 DSSDBGF("%d", channel);
2784 dsi_sync_vc(dsidev, channel);
2786 dsi_vc_enable(dsidev, channel, 0);
2789 if (wait_for_bit_change(dsidev, DSI_VC_CTRL(channel), 15, 0) != 0) {
2790 DSSERR("vc(%d) busy when trying to config for VP\n", channel);
2794 /* SOURCE, 1 = video port */
2795 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 1, 1, 1);
2797 /* DCS_CMD_ENABLE */
2798 if (dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC))
2799 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 1, 30, 30);
2801 dsi_vc_enable(dsidev, channel, 1);
2803 dsi->vc[channel].mode = DSI_VC_MODE_VP;
2809 void omapdss_dsi_vc_enable_hs(struct omap_dss_device *dssdev, int channel,
2812 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
2814 DSSDBG("dsi_vc_enable_hs(%d, %d)\n", channel, enable);
2816 WARN_ON(!dsi_bus_is_locked(dsidev));
2818 dsi_vc_enable(dsidev, channel, 0);
2819 dsi_if_enable(dsidev, 0);
2821 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 9, 9);
2823 dsi_vc_enable(dsidev, channel, 1);
2824 dsi_if_enable(dsidev, 1);
2826 dsi_force_tx_stop_mode_io(dsidev);
2828 EXPORT_SYMBOL(omapdss_dsi_vc_enable_hs);
2830 static void dsi_vc_flush_long_data(struct platform_device *dsidev, int channel)
2832 while (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
2834 val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel));
2835 DSSDBG("\t\tb1 %#02x b2 %#02x b3 %#02x b4 %#02x\n",
2839 (val >> 24) & 0xff);
2843 static void dsi_show_rx_ack_with_err(u16 err)
2845 DSSERR("\tACK with ERROR (%#x):\n", err);
2847 DSSERR("\t\tSoT Error\n");
2849 DSSERR("\t\tSoT Sync Error\n");
2851 DSSERR("\t\tEoT Sync Error\n");
2853 DSSERR("\t\tEscape Mode Entry Command Error\n");
2855 DSSERR("\t\tLP Transmit Sync Error\n");
2857 DSSERR("\t\tHS Receive Timeout Error\n");
2859 DSSERR("\t\tFalse Control Error\n");
2861 DSSERR("\t\t(reserved7)\n");
2863 DSSERR("\t\tECC Error, single-bit (corrected)\n");
2865 DSSERR("\t\tECC Error, multi-bit (not corrected)\n");
2866 if (err & (1 << 10))
2867 DSSERR("\t\tChecksum Error\n");
2868 if (err & (1 << 11))
2869 DSSERR("\t\tData type not recognized\n");
2870 if (err & (1 << 12))
2871 DSSERR("\t\tInvalid VC ID\n");
2872 if (err & (1 << 13))
2873 DSSERR("\t\tInvalid Transmission Length\n");
2874 if (err & (1 << 14))
2875 DSSERR("\t\t(reserved14)\n");
2876 if (err & (1 << 15))
2877 DSSERR("\t\tDSI Protocol Violation\n");
2880 static u16 dsi_vc_flush_receive_data(struct platform_device *dsidev,
2883 /* RX_FIFO_NOT_EMPTY */
2884 while (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
2887 val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel));
2888 DSSERR("\trawval %#08x\n", val);
2889 dt = FLD_GET(val, 5, 0);
2890 if (dt == DSI_DT_RX_ACK_WITH_ERR) {
2891 u16 err = FLD_GET(val, 23, 8);
2892 dsi_show_rx_ack_with_err(err);
2893 } else if (dt == DSI_DT_RX_SHORT_READ_1) {
2894 DSSERR("\tDCS short response, 1 byte: %#x\n",
2895 FLD_GET(val, 23, 8));
2896 } else if (dt == DSI_DT_RX_SHORT_READ_2) {
2897 DSSERR("\tDCS short response, 2 byte: %#x\n",
2898 FLD_GET(val, 23, 8));
2899 } else if (dt == DSI_DT_RX_DCS_LONG_READ) {
2900 DSSERR("\tDCS long response, len %d\n",
2901 FLD_GET(val, 23, 8));
2902 dsi_vc_flush_long_data(dsidev, channel);
2904 DSSERR("\tunknown datatype 0x%02x\n", dt);
2910 static int dsi_vc_send_bta(struct platform_device *dsidev, int channel)
2912 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2914 if (dsi->debug_write || dsi->debug_read)
2915 DSSDBG("dsi_vc_send_bta %d\n", channel);
2917 WARN_ON(!dsi_bus_is_locked(dsidev));
2919 /* RX_FIFO_NOT_EMPTY */
2920 if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
2921 DSSERR("rx fifo not empty when sending BTA, dumping data:\n");
2922 dsi_vc_flush_receive_data(dsidev, channel);
2925 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 1, 6, 6); /* BTA_EN */
2930 int dsi_vc_send_bta_sync(struct omap_dss_device *dssdev, int channel)
2932 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
2933 DECLARE_COMPLETION_ONSTACK(completion);
2937 r = dsi_register_isr_vc(dsidev, channel, dsi_completion_handler,
2938 &completion, DSI_VC_IRQ_BTA);
2942 r = dsi_register_isr(dsidev, dsi_completion_handler, &completion,
2943 DSI_IRQ_ERROR_MASK);
2947 r = dsi_vc_send_bta(dsidev, channel);
2951 if (wait_for_completion_timeout(&completion,
2952 msecs_to_jiffies(500)) == 0) {
2953 DSSERR("Failed to receive BTA\n");
2958 err = dsi_get_errors(dsidev);
2960 DSSERR("Error while sending BTA: %x\n", err);
2965 dsi_unregister_isr(dsidev, dsi_completion_handler, &completion,
2966 DSI_IRQ_ERROR_MASK);
2968 dsi_unregister_isr_vc(dsidev, channel, dsi_completion_handler,
2969 &completion, DSI_VC_IRQ_BTA);
2973 EXPORT_SYMBOL(dsi_vc_send_bta_sync);
2975 static inline void dsi_vc_write_long_header(struct platform_device *dsidev,
2976 int channel, u8 data_type, u16 len, u8 ecc)
2978 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2982 WARN_ON(!dsi_bus_is_locked(dsidev));
2984 data_id = data_type | dsi->vc[channel].vc_id << 6;
2986 val = FLD_VAL(data_id, 7, 0) | FLD_VAL(len, 23, 8) |
2987 FLD_VAL(ecc, 31, 24);
2989 dsi_write_reg(dsidev, DSI_VC_LONG_PACKET_HEADER(channel), val);
2992 static inline void dsi_vc_write_long_payload(struct platform_device *dsidev,
2993 int channel, u8 b1, u8 b2, u8 b3, u8 b4)
2997 val = b4 << 24 | b3 << 16 | b2 << 8 | b1 << 0;
2999 /* DSSDBG("\twriting %02x, %02x, %02x, %02x (%#010x)\n",
3000 b1, b2, b3, b4, val); */
3002 dsi_write_reg(dsidev, DSI_VC_LONG_PACKET_PAYLOAD(channel), val);
3005 static int dsi_vc_send_long(struct platform_device *dsidev, int channel,
3006 u8 data_type, u8 *data, u16 len, u8 ecc)
3009 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
3015 if (dsi->debug_write)
3016 DSSDBG("dsi_vc_send_long, %d bytes\n", len);
3019 if (dsi->vc[channel].fifo_size * 32 * 4 < len + 4) {
3020 DSSERR("unable to send long packet: packet too long.\n");
3024 dsi_vc_config_l4(dsidev, channel);
3026 dsi_vc_write_long_header(dsidev, channel, data_type, len, ecc);
3029 for (i = 0; i < len >> 2; i++) {
3030 if (dsi->debug_write)
3031 DSSDBG("\tsending full packet %d\n", i);
3038 dsi_vc_write_long_payload(dsidev, channel, b1, b2, b3, b4);
3043 b1 = 0; b2 = 0; b3 = 0;
3045 if (dsi->debug_write)
3046 DSSDBG("\tsending remainder bytes %d\n", i);
3063 dsi_vc_write_long_payload(dsidev, channel, b1, b2, b3, 0);
3069 static int dsi_vc_send_short(struct platform_device *dsidev, int channel,
3070 u8 data_type, u16 data, u8 ecc)
3072 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
3076 WARN_ON(!dsi_bus_is_locked(dsidev));
3078 if (dsi->debug_write)
3079 DSSDBG("dsi_vc_send_short(ch%d, dt %#x, b1 %#x, b2 %#x)\n",
3081 data_type, data & 0xff, (data >> 8) & 0xff);
3083 dsi_vc_config_l4(dsidev, channel);
3085 if (FLD_GET(dsi_read_reg(dsidev, DSI_VC_CTRL(channel)), 16, 16)) {
3086 DSSERR("ERROR FIFO FULL, aborting transfer\n");
3090 data_id = data_type | dsi->vc[channel].vc_id << 6;
3092 r = (data_id << 0) | (data << 8) | (ecc << 24);
3094 dsi_write_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel), r);
3099 int dsi_vc_send_null(struct omap_dss_device *dssdev, int channel)
3101 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
3102 u8 nullpkg[] = {0, 0, 0, 0};
3104 return dsi_vc_send_long(dsidev, channel, DSI_DT_NULL_PACKET, nullpkg,
3107 EXPORT_SYMBOL(dsi_vc_send_null);
3109 int dsi_vc_dcs_write_nosync(struct omap_dss_device *dssdev, int channel,
3112 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
3118 r = dsi_vc_send_short(dsidev, channel, DSI_DT_DCS_SHORT_WRITE_0,
3120 } else if (len == 2) {
3121 r = dsi_vc_send_short(dsidev, channel, DSI_DT_DCS_SHORT_WRITE_1,
3122 data[0] | (data[1] << 8), 0);
3124 /* 0x39 = DCS Long Write */
3125 r = dsi_vc_send_long(dsidev, channel, DSI_DT_DCS_LONG_WRITE,
3131 EXPORT_SYMBOL(dsi_vc_dcs_write_nosync);
3133 int dsi_vc_dcs_write(struct omap_dss_device *dssdev, int channel, u8 *data,
3136 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
3139 r = dsi_vc_dcs_write_nosync(dssdev, channel, data, len);
3143 r = dsi_vc_send_bta_sync(dssdev, channel);
3147 /* RX_FIFO_NOT_EMPTY */
3148 if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
3149 DSSERR("rx fifo not empty after write, dumping data:\n");
3150 dsi_vc_flush_receive_data(dsidev, channel);
3157 DSSERR("dsi_vc_dcs_write(ch %d, cmd 0x%02x, len %d) failed\n",
3158 channel, data[0], len);
3161 EXPORT_SYMBOL(dsi_vc_dcs_write);
3163 int dsi_vc_dcs_write_0(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd)
3165 return dsi_vc_dcs_write(dssdev, channel, &dcs_cmd, 1);
3167 EXPORT_SYMBOL(dsi_vc_dcs_write_0);
3169 int dsi_vc_dcs_write_1(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
3175 return dsi_vc_dcs_write(dssdev, channel, buf, 2);
3177 EXPORT_SYMBOL(dsi_vc_dcs_write_1);
3179 int dsi_vc_dcs_read(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
3180 u8 *buf, int buflen)
3182 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
3183 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
3188 if (dsi->debug_read)
3189 DSSDBG("dsi_vc_dcs_read(ch%d, dcs_cmd %x)\n", channel, dcs_cmd);
3191 r = dsi_vc_send_short(dsidev, channel, DSI_DT_DCS_READ, dcs_cmd, 0);
3195 r = dsi_vc_send_bta_sync(dssdev, channel);
3199 /* RX_FIFO_NOT_EMPTY */
3200 if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20) == 0) {
3201 DSSERR("RX fifo empty when trying to read.\n");
3206 val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel));
3207 if (dsi->debug_read)
3208 DSSDBG("\theader: %08x\n", val);
3209 dt = FLD_GET(val, 5, 0);
3210 if (dt == DSI_DT_RX_ACK_WITH_ERR) {
3211 u16 err = FLD_GET(val, 23, 8);
3212 dsi_show_rx_ack_with_err(err);
3216 } else if (dt == DSI_DT_RX_SHORT_READ_1) {
3217 u8 data = FLD_GET(val, 15, 8);
3218 if (dsi->debug_read)
3219 DSSDBG("\tDCS short response, 1 byte: %02x\n", data);
3229 } else if (dt == DSI_DT_RX_SHORT_READ_2) {
3230 u16 data = FLD_GET(val, 23, 8);
3231 if (dsi->debug_read)
3232 DSSDBG("\tDCS short response, 2 byte: %04x\n", data);
3239 buf[0] = data & 0xff;
3240 buf[1] = (data >> 8) & 0xff;
3243 } else if (dt == DSI_DT_RX_DCS_LONG_READ) {
3245 int len = FLD_GET(val, 23, 8);
3246 if (dsi->debug_read)
3247 DSSDBG("\tDCS long response, len %d\n", len);
3254 /* two byte checksum ends the packet, not included in len */
3255 for (w = 0; w < len + 2;) {
3257 val = dsi_read_reg(dsidev,
3258 DSI_VC_SHORT_PACKET_HEADER(channel));
3259 if (dsi->debug_read)
3260 DSSDBG("\t\t%02x %02x %02x %02x\n",
3264 (val >> 24) & 0xff);
3266 for (b = 0; b < 4; ++b) {
3268 buf[w] = (val >> (b * 8)) & 0xff;
3269 /* we discard the 2 byte checksum */
3276 DSSERR("\tunknown datatype 0x%02x\n", dt);
3283 DSSERR("dsi_vc_dcs_read(ch %d, cmd 0x%02x) failed\n",
3288 EXPORT_SYMBOL(dsi_vc_dcs_read);
3290 int dsi_vc_dcs_read_1(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
3295 r = dsi_vc_dcs_read(dssdev, channel, dcs_cmd, data, 1);
3305 EXPORT_SYMBOL(dsi_vc_dcs_read_1);
3307 int dsi_vc_dcs_read_2(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
3308 u8 *data1, u8 *data2)
3313 r = dsi_vc_dcs_read(dssdev, channel, dcs_cmd, buf, 2);
3326 EXPORT_SYMBOL(dsi_vc_dcs_read_2);
3328 int dsi_vc_set_max_rx_packet_size(struct omap_dss_device *dssdev, int channel,
3331 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
3333 return dsi_vc_send_short(dsidev, channel, DSI_DT_SET_MAX_RET_PKG_SIZE,
3336 EXPORT_SYMBOL(dsi_vc_set_max_rx_packet_size);
3338 static int dsi_enter_ulps(struct platform_device *dsidev)
3340 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
3341 DECLARE_COMPLETION_ONSTACK(completion);
3346 WARN_ON(!dsi_bus_is_locked(dsidev));
3348 WARN_ON(dsi->ulps_enabled);
3350 if (dsi->ulps_enabled)
3353 if (REG_GET(dsidev, DSI_CLK_CTRL, 13, 13)) {
3354 DSSERR("DDR_CLK_ALWAYS_ON enabled when entering ULPS\n");
3358 dsi_sync_vc(dsidev, 0);
3359 dsi_sync_vc(dsidev, 1);
3360 dsi_sync_vc(dsidev, 2);
3361 dsi_sync_vc(dsidev, 3);
3363 dsi_force_tx_stop_mode_io(dsidev);
3365 dsi_vc_enable(dsidev, 0, false);
3366 dsi_vc_enable(dsidev, 1, false);
3367 dsi_vc_enable(dsidev, 2, false);
3368 dsi_vc_enable(dsidev, 3, false);
3370 if (REG_GET(dsidev, DSI_COMPLEXIO_CFG2, 16, 16)) { /* HS_BUSY */
3371 DSSERR("HS busy when enabling ULPS\n");
3375 if (REG_GET(dsidev, DSI_COMPLEXIO_CFG2, 17, 17)) { /* LP_BUSY */
3376 DSSERR("LP busy when enabling ULPS\n");
3380 r = dsi_register_isr_cio(dsidev, dsi_completion_handler, &completion,
3381 DSI_CIO_IRQ_ULPSACTIVENOT_ALL0);
3385 /* Assert TxRequestEsc for data lanes and TxUlpsClk for clk lane */
3386 /* LANEx_ULPS_SIG2 */
3387 REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG2, (1 << 0) | (1 << 1) | (1 << 2),
3390 if (wait_for_completion_timeout(&completion,
3391 msecs_to_jiffies(1000)) == 0) {
3392 DSSERR("ULPS enable timeout\n");
3397 dsi_unregister_isr_cio(dsidev, dsi_completion_handler, &completion,
3398 DSI_CIO_IRQ_ULPSACTIVENOT_ALL0);
3400 /* Reset LANEx_ULPS_SIG2 */
3401 REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG2, (0 << 0) | (0 << 1) | (0 << 2),
3404 dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_ULPS);
3406 dsi_if_enable(dsidev, false);
3408 dsi->ulps_enabled = true;
3413 dsi_unregister_isr_cio(dsidev, dsi_completion_handler, &completion,
3414 DSI_CIO_IRQ_ULPSACTIVENOT_ALL0);
3418 static void dsi_set_lp_rx_timeout(struct platform_device *dsidev,
3419 unsigned ticks, bool x4, bool x16)
3422 unsigned long total_ticks;
3425 BUG_ON(ticks > 0x1fff);
3427 /* ticks in DSI_FCK */
3428 fck = dsi_fclk_rate(dsidev);
3430 r = dsi_read_reg(dsidev, DSI_TIMING2);
3431 r = FLD_MOD(r, 1, 15, 15); /* LP_RX_TO */
3432 r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* LP_RX_TO_X16 */
3433 r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* LP_RX_TO_X4 */
3434 r = FLD_MOD(r, ticks, 12, 0); /* LP_RX_COUNTER */
3435 dsi_write_reg(dsidev, DSI_TIMING2, r);
3437 total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
3439 DSSDBG("LP_RX_TO %lu ticks (%#x%s%s) = %lu ns\n",
3441 ticks, x4 ? " x4" : "", x16 ? " x16" : "",
3442 (total_ticks * 1000) / (fck / 1000 / 1000));
3445 static void dsi_set_ta_timeout(struct platform_device *dsidev, unsigned ticks,
3449 unsigned long total_ticks;
3452 BUG_ON(ticks > 0x1fff);
3454 /* ticks in DSI_FCK */
3455 fck = dsi_fclk_rate(dsidev);
3457 r = dsi_read_reg(dsidev, DSI_TIMING1);
3458 r = FLD_MOD(r, 1, 31, 31); /* TA_TO */
3459 r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* TA_TO_X16 */
3460 r = FLD_MOD(r, x8 ? 1 : 0, 29, 29); /* TA_TO_X8 */
3461 r = FLD_MOD(r, ticks, 28, 16); /* TA_TO_COUNTER */
3462 dsi_write_reg(dsidev, DSI_TIMING1, r);
3464 total_ticks = ticks * (x16 ? 16 : 1) * (x8 ? 8 : 1);
3466 DSSDBG("TA_TO %lu ticks (%#x%s%s) = %lu ns\n",
3468 ticks, x8 ? " x8" : "", x16 ? " x16" : "",
3469 (total_ticks * 1000) / (fck / 1000 / 1000));
3472 static void dsi_set_stop_state_counter(struct platform_device *dsidev,
3473 unsigned ticks, bool x4, bool x16)
3476 unsigned long total_ticks;
3479 BUG_ON(ticks > 0x1fff);
3481 /* ticks in DSI_FCK */
3482 fck = dsi_fclk_rate(dsidev);
3484 r = dsi_read_reg(dsidev, DSI_TIMING1);
3485 r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
3486 r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* STOP_STATE_X16_IO */
3487 r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* STOP_STATE_X4_IO */
3488 r = FLD_MOD(r, ticks, 12, 0); /* STOP_STATE_COUNTER_IO */
3489 dsi_write_reg(dsidev, DSI_TIMING1, r);
3491 total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
3493 DSSDBG("STOP_STATE_COUNTER %lu ticks (%#x%s%s) = %lu ns\n",
3495 ticks, x4 ? " x4" : "", x16 ? " x16" : "",
3496 (total_ticks * 1000) / (fck / 1000 / 1000));
3499 static void dsi_set_hs_tx_timeout(struct platform_device *dsidev,
3500 unsigned ticks, bool x4, bool x16)
3503 unsigned long total_ticks;
3506 BUG_ON(ticks > 0x1fff);
3508 /* ticks in TxByteClkHS */
3509 fck = dsi_get_txbyteclkhs(dsidev);
3511 r = dsi_read_reg(dsidev, DSI_TIMING2);
3512 r = FLD_MOD(r, 1, 31, 31); /* HS_TX_TO */
3513 r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* HS_TX_TO_X16 */
3514 r = FLD_MOD(r, x4 ? 1 : 0, 29, 29); /* HS_TX_TO_X8 (4 really) */
3515 r = FLD_MOD(r, ticks, 28, 16); /* HS_TX_TO_COUNTER */
3516 dsi_write_reg(dsidev, DSI_TIMING2, r);
3518 total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
3520 DSSDBG("HS_TX_TO %lu ticks (%#x%s%s) = %lu ns\n",
3522 ticks, x4 ? " x4" : "", x16 ? " x16" : "",
3523 (total_ticks * 1000) / (fck / 1000 / 1000));
3525 static int dsi_proto_config(struct omap_dss_device *dssdev)
3527 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
3531 dsi_config_tx_fifo(dsidev, DSI_FIFO_SIZE_32,
3536 dsi_config_rx_fifo(dsidev, DSI_FIFO_SIZE_32,
3541 /* XXX what values for the timeouts? */
3542 dsi_set_stop_state_counter(dsidev, 0x1000, false, false);
3543 dsi_set_ta_timeout(dsidev, 0x1fff, true, true);
3544 dsi_set_lp_rx_timeout(dsidev, 0x1fff, true, true);
3545 dsi_set_hs_tx_timeout(dsidev, 0x1fff, true, true);
3547 switch (dssdev->ctrl.pixel_size) {
3561 r = dsi_read_reg(dsidev, DSI_CTRL);
3562 r = FLD_MOD(r, 1, 1, 1); /* CS_RX_EN */
3563 r = FLD_MOD(r, 1, 2, 2); /* ECC_RX_EN */
3564 r = FLD_MOD(r, 1, 3, 3); /* TX_FIFO_ARBITRATION */
3565 r = FLD_MOD(r, 1, 4, 4); /* VP_CLK_RATIO, always 1, see errata*/
3566 r = FLD_MOD(r, buswidth, 7, 6); /* VP_DATA_BUS_WIDTH */
3567 r = FLD_MOD(r, 0, 8, 8); /* VP_CLK_POL */
3568 r = FLD_MOD(r, 2, 13, 12); /* LINE_BUFFER, 2 lines */
3569 r = FLD_MOD(r, 1, 14, 14); /* TRIGGER_RESET_MODE */
3570 r = FLD_MOD(r, 1, 19, 19); /* EOT_ENABLE */
3571 if (!dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC)) {
3572 r = FLD_MOD(r, 1, 24, 24); /* DCS_CMD_ENABLE */
3573 /* DCS_CMD_CODE, 1=start, 0=continue */
3574 r = FLD_MOD(r, 0, 25, 25);
3577 dsi_write_reg(dsidev, DSI_CTRL, r);
3579 dsi_vc_initial_config(dsidev, 0);
3580 dsi_vc_initial_config(dsidev, 1);
3581 dsi_vc_initial_config(dsidev, 2);
3582 dsi_vc_initial_config(dsidev, 3);
3587 static void dsi_proto_timings(struct omap_dss_device *dssdev)
3589 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
3590 unsigned tlpx, tclk_zero, tclk_prepare, tclk_trail;
3591 unsigned tclk_pre, tclk_post;
3592 unsigned ths_prepare, ths_prepare_ths_zero, ths_zero;
3593 unsigned ths_trail, ths_exit;
3594 unsigned ddr_clk_pre, ddr_clk_post;
3595 unsigned enter_hs_mode_lat, exit_hs_mode_lat;
3599 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0);
3600 ths_prepare = FLD_GET(r, 31, 24);
3601 ths_prepare_ths_zero = FLD_GET(r, 23, 16);
3602 ths_zero = ths_prepare_ths_zero - ths_prepare;
3603 ths_trail = FLD_GET(r, 15, 8);
3604 ths_exit = FLD_GET(r, 7, 0);
3606 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1);
3607 tlpx = FLD_GET(r, 22, 16) * 2;
3608 tclk_trail = FLD_GET(r, 15, 8);
3609 tclk_zero = FLD_GET(r, 7, 0);
3611 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG2);
3612 tclk_prepare = FLD_GET(r, 7, 0);
3616 /* min 60ns + 52*UI */
3617 tclk_post = ns2ddr(dsidev, 60) + 26;
3619 ths_eot = DIV_ROUND_UP(4, dsi_get_num_data_lanes_dssdev(dssdev));
3621 ddr_clk_pre = DIV_ROUND_UP(tclk_pre + tlpx + tclk_zero + tclk_prepare,
3623 ddr_clk_post = DIV_ROUND_UP(tclk_post + ths_trail, 4) + ths_eot;
3625 BUG_ON(ddr_clk_pre == 0 || ddr_clk_pre > 255);
3626 BUG_ON(ddr_clk_post == 0 || ddr_clk_post > 255);
3628 r = dsi_read_reg(dsidev, DSI_CLK_TIMING);
3629 r = FLD_MOD(r, ddr_clk_pre, 15, 8);
3630 r = FLD_MOD(r, ddr_clk_post, 7, 0);
3631 dsi_write_reg(dsidev, DSI_CLK_TIMING, r);
3633 DSSDBG("ddr_clk_pre %u, ddr_clk_post %u\n",
3637 enter_hs_mode_lat = 1 + DIV_ROUND_UP(tlpx, 4) +
3638 DIV_ROUND_UP(ths_prepare, 4) +
3639 DIV_ROUND_UP(ths_zero + 3, 4);
3641 exit_hs_mode_lat = DIV_ROUND_UP(ths_trail + ths_exit, 4) + 1 + ths_eot;
3643 r = FLD_VAL(enter_hs_mode_lat, 31, 16) |
3644 FLD_VAL(exit_hs_mode_lat, 15, 0);
3645 dsi_write_reg(dsidev, DSI_VM_TIMING7, r);
3647 DSSDBG("enter_hs_mode_lat %u, exit_hs_mode_lat %u\n",
3648 enter_hs_mode_lat, exit_hs_mode_lat);
3652 #define DSI_DECL_VARS \
3653 int __dsi_cb = 0; u32 __dsi_cv = 0;
3655 #define DSI_FLUSH(dsidev, ch) \
3656 if (__dsi_cb > 0) { \
3657 /*DSSDBG("sending long packet %#010x\n", __dsi_cv);*/ \
3658 dsi_write_reg(dsidev, DSI_VC_LONG_PACKET_PAYLOAD(ch), __dsi_cv); \
3659 __dsi_cb = __dsi_cv = 0; \
3662 #define DSI_PUSH(dsidev, ch, data) \
3664 __dsi_cv |= (data) << (__dsi_cb * 8); \
3665 /*DSSDBG("cv = %#010x, cb = %d\n", __dsi_cv, __dsi_cb);*/ \
3666 if (++__dsi_cb > 3) \
3667 DSI_FLUSH(dsidev, ch); \
3670 static int dsi_update_screen_l4(struct omap_dss_device *dssdev,
3671 int x, int y, int w, int h)
3673 /* Note: supports only 24bit colors in 32bit container */
3674 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
3675 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
3677 int fifo_stalls = 0;
3678 int max_dsi_packet_size;
3679 int max_data_per_packet;
3680 int max_pixels_per_packet;
3682 int bytespp = dssdev->ctrl.pixel_size / 8;
3688 struct omap_overlay *ovl;
3692 DSSDBG("dsi_update_screen_l4 (%d,%d %dx%d)\n",
3695 ovl = dssdev->manager->overlays[0];
3697 if (ovl->info.color_mode != OMAP_DSS_COLOR_RGB24U)
3700 if (dssdev->ctrl.pixel_size != 24)
3703 scr_width = ovl->info.screen_width;
3704 data = ovl->info.vaddr;
3706 start_offset = scr_width * y + x;
3707 horiz_inc = scr_width - w;
3710 /* We need header(4) + DCSCMD(1) + pixels(numpix*bytespp) bytes
3713 /* When using CPU, max long packet size is TX buffer size */
3714 max_dsi_packet_size = dsi->vc[0].fifo_size * 32 * 4;
3716 /* we seem to get better perf if we divide the tx fifo to half,
3717 and while the other half is being sent, we fill the other half
3718 max_dsi_packet_size /= 2; */
3720 max_data_per_packet = max_dsi_packet_size - 4 - 1;
3722 max_pixels_per_packet = max_data_per_packet / bytespp;
3724 DSSDBG("max_pixels_per_packet %d\n", max_pixels_per_packet);
3726 pixels_left = w * h;
3728 DSSDBG("total pixels %d\n", pixels_left);
3730 data += start_offset;
3732 while (pixels_left > 0) {
3733 /* 0x2c = write_memory_start */
3734 /* 0x3c = write_memory_continue */
3735 u8 dcs_cmd = first ? 0x2c : 0x3c;
3741 /* using fifo not empty */
3742 /* TX_FIFO_NOT_EMPTY */
3743 while (FLD_GET(dsi_read_reg(dsidev, DSI_VC_CTRL(0)), 5, 5)) {
3745 if (fifo_stalls > 0xfffff) {
3746 DSSERR("fifo stalls overflow, pixels left %d\n",
3748 dsi_if_enable(dsidev, 0);
3754 /* using fifo emptiness */
3755 while ((REG_GET(dsidev, DSI_TX_FIFO_VC_EMPTINESS, 7, 0)+1)*4 <
3756 max_dsi_packet_size) {
3758 if (fifo_stalls > 0xfffff) {
3759 DSSERR("fifo stalls overflow, pixels left %d\n",
3761 dsi_if_enable(dsidev, 0);
3766 while ((REG_GET(dsidev, DSI_TX_FIFO_VC_EMPTINESS,
3767 7, 0) + 1) * 4 == 0) {
3769 if (fifo_stalls > 0xfffff) {
3770 DSSERR("fifo stalls overflow, pixels left %d\n",
3772 dsi_if_enable(dsidev, 0);
3777 pixels = min(max_pixels_per_packet, pixels_left);
3779 pixels_left -= pixels;
3781 dsi_vc_write_long_header(dsidev, 0, DSI_DT_DCS_LONG_WRITE,
3782 1 + pixels * bytespp, 0);
3784 DSI_PUSH(dsidev, 0, dcs_cmd);
3786 while (pixels-- > 0) {
3787 u32 pix = __raw_readl(data++);
3789 DSI_PUSH(dsidev, 0, (pix >> 16) & 0xff);
3790 DSI_PUSH(dsidev, 0, (pix >> 8) & 0xff);
3791 DSI_PUSH(dsidev, 0, (pix >> 0) & 0xff);
3794 if (current_x == x+w) {
3800 DSI_FLUSH(dsidev, 0);
3806 static void dsi_update_screen_dispc(struct omap_dss_device *dssdev,
3807 u16 x, u16 y, u16 w, u16 h)
3809 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
3810 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
3815 unsigned packet_payload;
3816 unsigned packet_len;
3819 const unsigned channel = dsi->update_channel;
3820 const unsigned line_buf_size = dsi_get_line_buf_size(dsidev);
3822 DSSDBG("dsi_update_screen_dispc(%d,%d %dx%d)\n",
3825 dsi_vc_config_vp(dsidev, channel);
3827 bytespp = dssdev->ctrl.pixel_size / 8;
3828 bytespl = w * bytespp;
3829 bytespf = bytespl * h;
3831 /* NOTE: packet_payload has to be equal to N * bytespl, where N is
3832 * number of lines in a packet. See errata about VP_CLK_RATIO */
3834 if (bytespf < line_buf_size)
3835 packet_payload = bytespf;
3837 packet_payload = (line_buf_size) / bytespl * bytespl;
3839 packet_len = packet_payload + 1; /* 1 byte for DCS cmd */
3840 total_len = (bytespf / packet_payload) * packet_len;
3842 if (bytespf % packet_payload)
3843 total_len += (bytespf % packet_payload) + 1;
3845 l = FLD_VAL(total_len, 23, 0); /* TE_SIZE */
3846 dsi_write_reg(dsidev, DSI_VC_TE(channel), l);
3848 dsi_vc_write_long_header(dsidev, channel, DSI_DT_DCS_LONG_WRITE,
3851 if (dsi->te_enabled)
3852 l = FLD_MOD(l, 1, 30, 30); /* TE_EN */
3854 l = FLD_MOD(l, 1, 31, 31); /* TE_START */
3855 dsi_write_reg(dsidev, DSI_VC_TE(channel), l);
3857 /* We put SIDLEMODE to no-idle for the duration of the transfer,
3858 * because DSS interrupts are not capable of waking up the CPU and the
3859 * framedone interrupt could be delayed for quite a long time. I think
3860 * the same goes for any DSS interrupts, but for some reason I have not
3861 * seen the problem anywhere else than here.
3863 dispc_disable_sidle();
3865 dsi_perf_mark_start(dsidev);
3867 r = schedule_delayed_work(&dsi->framedone_timeout_work,
3868 msecs_to_jiffies(250));
3871 dss_start_update(dssdev);
3873 if (dsi->te_enabled) {
3874 /* disable LP_RX_TO, so that we can receive TE. Time to wait
3875 * for TE is longer than the timer allows */
3876 REG_FLD_MOD(dsidev, DSI_TIMING2, 0, 15, 15); /* LP_RX_TO */
3878 dsi_vc_send_bta(dsidev, channel);
3880 #ifdef DSI_CATCH_MISSING_TE
3881 mod_timer(&dsi->te_timer, jiffies + msecs_to_jiffies(250));
3886 #ifdef DSI_CATCH_MISSING_TE
3887 static void dsi_te_timeout(unsigned long arg)
3889 DSSERR("TE not received for 250ms!\n");
3893 static void dsi_handle_framedone(struct platform_device *dsidev, int error)
3895 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
3897 /* SIDLEMODE back to smart-idle */
3898 dispc_enable_sidle();
3900 if (dsi->te_enabled) {
3901 /* enable LP_RX_TO again after the TE */
3902 REG_FLD_MOD(dsidev, DSI_TIMING2, 1, 15, 15); /* LP_RX_TO */
3905 dsi->framedone_callback(error, dsi->framedone_data);
3908 dsi_perf_show(dsidev, "DISPC");
3911 static void dsi_framedone_timeout_work_callback(struct work_struct *work)
3913 struct dsi_data *dsi = container_of(work, struct dsi_data,
3914 framedone_timeout_work.work);
3915 /* XXX While extremely unlikely, we could get FRAMEDONE interrupt after
3916 * 250ms which would conflict with this timeout work. What should be
3917 * done is first cancel the transfer on the HW, and then cancel the
3918 * possibly scheduled framedone work. However, cancelling the transfer
3919 * on the HW is buggy, and would probably require resetting the whole
3922 DSSERR("Framedone not received for 250ms!\n");
3924 dsi_handle_framedone(dsi->pdev, -ETIMEDOUT);
3927 static void dsi_framedone_irq_callback(void *data, u32 mask)
3929 struct omap_dss_device *dssdev = (struct omap_dss_device *) data;
3930 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
3931 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
3933 /* Note: We get FRAMEDONE when DISPC has finished sending pixels and
3934 * turns itself off. However, DSI still has the pixels in its buffers,
3935 * and is sending the data.
3938 __cancel_delayed_work(&dsi->framedone_timeout_work);
3940 dsi_handle_framedone(dsidev, 0);
3942 #ifdef CONFIG_OMAP2_DSS_FAKE_VSYNC
3943 dispc_fake_vsync_irq();
3947 int omap_dsi_prepare_update(struct omap_dss_device *dssdev,
3948 u16 *x, u16 *y, u16 *w, u16 *h,
3949 bool enlarge_update_area)
3951 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
3954 dssdev->driver->get_resolution(dssdev, &dw, &dh);
3956 if (*x > dw || *y > dh)
3968 if (*w == 0 || *h == 0)
3971 dsi_perf_mark_setup(dsidev);
3973 if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) {
3974 dss_setup_partial_planes(dssdev, x, y, w, h,
3975 enlarge_update_area);
3976 dispc_set_lcd_size(dssdev->manager->id, *w, *h);
3981 EXPORT_SYMBOL(omap_dsi_prepare_update);
3983 int omap_dsi_update(struct omap_dss_device *dssdev,
3985 u16 x, u16 y, u16 w, u16 h,
3986 void (*callback)(int, void *), void *data)
3988 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
3989 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
3991 dsi->update_channel = channel;
3993 /* OMAP DSS cannot send updates of odd widths.
3994 * omap_dsi_prepare_update() makes the widths even, but add a BUG_ON
3995 * here to make sure we catch erroneous updates. Otherwise we'll only
3996 * see rather obscure HW error happening, as DSS halts. */
3999 if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) {
4000 dsi->framedone_callback = callback;
4001 dsi->framedone_data = data;
4003 dsi->update_region.x = x;
4004 dsi->update_region.y = y;
4005 dsi->update_region.w = w;
4006 dsi->update_region.h = h;
4007 dsi->update_region.device = dssdev;
4009 dsi_update_screen_dispc(dssdev, x, y, w, h);
4013 r = dsi_update_screen_l4(dssdev, x, y, w, h);
4017 dsi_perf_show(dsidev, "L4");
4023 EXPORT_SYMBOL(omap_dsi_update);
4027 static int dsi_display_init_dispc(struct omap_dss_device *dssdev)
4032 irq = dssdev->manager->id == OMAP_DSS_CHANNEL_LCD ?
4033 DISPC_IRQ_FRAMEDONE : DISPC_IRQ_FRAMEDONE2;
4035 r = omap_dispc_register_isr(dsi_framedone_irq_callback, (void *) dssdev,
4038 DSSERR("can't get FRAMEDONE irq\n");
4042 dispc_set_lcd_display_type(dssdev->manager->id,
4043 OMAP_DSS_LCD_DISPLAY_TFT);
4045 dispc_set_parallel_interface_mode(dssdev->manager->id,
4046 OMAP_DSS_PARALLELMODE_DSI);
4047 dispc_enable_fifohandcheck(dssdev->manager->id, 1);
4049 dispc_set_tft_data_lines(dssdev->manager->id, dssdev->ctrl.pixel_size);
4052 struct omap_video_timings timings = {
4061 dispc_set_lcd_timings(dssdev->manager->id, &timings);
4067 static void dsi_display_uninit_dispc(struct omap_dss_device *dssdev)
4071 irq = dssdev->manager->id == OMAP_DSS_CHANNEL_LCD ?
4072 DISPC_IRQ_FRAMEDONE : DISPC_IRQ_FRAMEDONE2;
4074 omap_dispc_unregister_isr(dsi_framedone_irq_callback, (void *) dssdev,
4078 static int dsi_configure_dsi_clocks(struct omap_dss_device *dssdev)
4080 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4081 struct dsi_clock_info cinfo;
4084 /* we always use DSS_CLK_SYSCK as input clock */
4085 cinfo.use_sys_clk = true;
4086 cinfo.regn = dssdev->clocks.dsi.regn;
4087 cinfo.regm = dssdev->clocks.dsi.regm;
4088 cinfo.regm_dispc = dssdev->clocks.dsi.regm_dispc;
4089 cinfo.regm_dsi = dssdev->clocks.dsi.regm_dsi;
4090 r = dsi_calc_clock_rates(dssdev, &cinfo);
4092 DSSERR("Failed to calc dsi clocks\n");
4096 r = dsi_pll_set_clock_div(dsidev, &cinfo);
4098 DSSERR("Failed to set dsi clocks\n");
4105 static int dsi_configure_dispc_clocks(struct omap_dss_device *dssdev)
4107 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4108 struct dispc_clock_info dispc_cinfo;
4110 unsigned long long fck;
4112 fck = dsi_get_pll_hsdiv_dispc_rate(dsidev);
4114 dispc_cinfo.lck_div = dssdev->clocks.dispc.channel.lck_div;
4115 dispc_cinfo.pck_div = dssdev->clocks.dispc.channel.pck_div;
4117 r = dispc_calc_clock_rates(fck, &dispc_cinfo);
4119 DSSERR("Failed to calc dispc clocks\n");
4123 r = dispc_set_clock_div(dssdev->manager->id, &dispc_cinfo);
4125 DSSERR("Failed to set dispc clocks\n");
4132 static int dsi_display_init_dsi(struct omap_dss_device *dssdev)
4134 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4135 int dsi_module = dsi_get_dsidev_id(dsidev);
4138 r = dsi_pll_init(dsidev, true, true);
4142 r = dsi_configure_dsi_clocks(dssdev);
4146 dss_select_dispc_clk_source(dssdev->clocks.dispc.dispc_fclk_src);
4147 dss_select_dsi_clk_source(dsi_module, dssdev->clocks.dsi.dsi_fclk_src);
4148 dss_select_lcd_clk_source(dssdev->manager->id,
4149 dssdev->clocks.dispc.channel.lcd_clk_src);
4153 r = dsi_configure_dispc_clocks(dssdev);
4157 r = dsi_cio_init(dssdev);
4161 _dsi_print_reset_status(dsidev);
4163 dsi_proto_timings(dssdev);
4164 dsi_set_lp_clk_divisor(dssdev);
4167 _dsi_print_reset_status(dsidev);
4169 r = dsi_proto_config(dssdev);
4173 /* enable interface */
4174 dsi_vc_enable(dsidev, 0, 1);
4175 dsi_vc_enable(dsidev, 1, 1);
4176 dsi_vc_enable(dsidev, 2, 1);
4177 dsi_vc_enable(dsidev, 3, 1);
4178 dsi_if_enable(dsidev, 1);
4179 dsi_force_tx_stop_mode_io(dsidev);
4183 dsi_cio_uninit(dssdev);
4185 dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK);
4186 dss_select_dsi_clk_source(dsi_module, OMAP_DSS_CLK_SRC_FCK);
4188 dsi_pll_uninit(dsidev, true);
4193 static void dsi_display_uninit_dsi(struct omap_dss_device *dssdev,
4194 bool disconnect_lanes, bool enter_ulps)
4196 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4197 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4198 int dsi_module = dsi_get_dsidev_id(dsidev);
4200 if (enter_ulps && !dsi->ulps_enabled)
4201 dsi_enter_ulps(dsidev);
4203 /* disable interface */
4204 dsi_if_enable(dsidev, 0);
4205 dsi_vc_enable(dsidev, 0, 0);
4206 dsi_vc_enable(dsidev, 1, 0);
4207 dsi_vc_enable(dsidev, 2, 0);
4208 dsi_vc_enable(dsidev, 3, 0);
4210 dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK);
4211 dss_select_dsi_clk_source(dsi_module, OMAP_DSS_CLK_SRC_FCK);
4212 dsi_cio_uninit(dssdev);
4213 dsi_pll_uninit(dsidev, disconnect_lanes);
4216 int omapdss_dsi_display_enable(struct omap_dss_device *dssdev)
4218 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4219 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4222 DSSDBG("dsi_display_enable\n");
4224 WARN_ON(!dsi_bus_is_locked(dsidev));
4226 mutex_lock(&dsi->lock);
4228 if (dssdev->manager == NULL) {
4229 DSSERR("failed to enable display: no manager\n");
4234 r = omap_dss_start_device(dssdev);
4236 DSSERR("failed to start device\n");
4240 r = dsi_runtime_get(dsidev);
4244 dsi_enable_pll_clock(dsidev, 1);
4246 _dsi_initialize_irq(dsidev);
4248 r = dsi_display_init_dispc(dssdev);
4250 goto err_init_dispc;
4252 r = dsi_display_init_dsi(dssdev);
4256 mutex_unlock(&dsi->lock);
4261 dsi_display_uninit_dispc(dssdev);
4263 dsi_enable_pll_clock(dsidev, 0);
4264 dsi_runtime_put(dsidev);
4266 omap_dss_stop_device(dssdev);
4268 mutex_unlock(&dsi->lock);
4269 DSSDBG("dsi_display_enable FAILED\n");
4272 EXPORT_SYMBOL(omapdss_dsi_display_enable);
4274 void omapdss_dsi_display_disable(struct omap_dss_device *dssdev,
4275 bool disconnect_lanes, bool enter_ulps)
4277 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4278 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4280 DSSDBG("dsi_display_disable\n");
4282 WARN_ON(!dsi_bus_is_locked(dsidev));
4284 mutex_lock(&dsi->lock);
4286 dsi_sync_vc(dsidev, 0);
4287 dsi_sync_vc(dsidev, 1);
4288 dsi_sync_vc(dsidev, 2);
4289 dsi_sync_vc(dsidev, 3);
4291 dsi_display_uninit_dispc(dssdev);
4293 dsi_display_uninit_dsi(dssdev, disconnect_lanes, enter_ulps);
4295 dsi_runtime_put(dsidev);
4296 dsi_enable_pll_clock(dsidev, 0);
4298 omap_dss_stop_device(dssdev);
4300 mutex_unlock(&dsi->lock);
4302 EXPORT_SYMBOL(omapdss_dsi_display_disable);
4304 int omapdss_dsi_enable_te(struct omap_dss_device *dssdev, bool enable)
4306 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4307 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4309 dsi->te_enabled = enable;
4312 EXPORT_SYMBOL(omapdss_dsi_enable_te);
4314 void dsi_get_overlay_fifo_thresholds(enum omap_plane plane,
4315 u32 fifo_size, u32 burst_size,
4316 u32 *fifo_low, u32 *fifo_high)
4318 *fifo_high = fifo_size - burst_size;
4319 *fifo_low = fifo_size - burst_size * 2;
4322 int dsi_init_display(struct omap_dss_device *dssdev)
4324 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4325 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4326 int dsi_module = dsi_get_dsidev_id(dsidev);
4328 DSSDBG("DSI init\n");
4330 /* XXX these should be figured out dynamically */
4331 dssdev->caps = OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE |
4332 OMAP_DSS_DISPLAY_CAP_TEAR_ELIM;
4334 if (dsi->vdds_dsi_reg == NULL) {
4335 struct regulator *vdds_dsi;
4337 vdds_dsi = regulator_get(&dsi->pdev->dev, "vdds_dsi");
4339 if (IS_ERR(vdds_dsi)) {
4340 DSSERR("can't get VDDS_DSI regulator\n");
4341 return PTR_ERR(vdds_dsi);
4344 dsi->vdds_dsi_reg = vdds_dsi;
4347 if (dsi_get_num_data_lanes_dssdev(dssdev) > dsi->num_data_lanes) {
4348 DSSERR("DSI%d can't support more than %d data lanes\n",
4349 dsi_module + 1, dsi->num_data_lanes);
4356 int omap_dsi_request_vc(struct omap_dss_device *dssdev, int *channel)
4358 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4359 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4362 for (i = 0; i < ARRAY_SIZE(dsi->vc); i++) {
4363 if (!dsi->vc[i].dssdev) {
4364 dsi->vc[i].dssdev = dssdev;
4370 DSSERR("cannot get VC for display %s", dssdev->name);
4373 EXPORT_SYMBOL(omap_dsi_request_vc);
4375 int omap_dsi_set_vc_id(struct omap_dss_device *dssdev, int channel, int vc_id)
4377 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4378 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4380 if (vc_id < 0 || vc_id > 3) {
4381 DSSERR("VC ID out of range\n");
4385 if (channel < 0 || channel > 3) {
4386 DSSERR("Virtual Channel out of range\n");
4390 if (dsi->vc[channel].dssdev != dssdev) {
4391 DSSERR("Virtual Channel not allocated to display %s\n",
4396 dsi->vc[channel].vc_id = vc_id;
4400 EXPORT_SYMBOL(omap_dsi_set_vc_id);
4402 void omap_dsi_release_vc(struct omap_dss_device *dssdev, int channel)
4404 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4405 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4407 if ((channel >= 0 && channel <= 3) &&
4408 dsi->vc[channel].dssdev == dssdev) {
4409 dsi->vc[channel].dssdev = NULL;
4410 dsi->vc[channel].vc_id = 0;
4413 EXPORT_SYMBOL(omap_dsi_release_vc);
4415 void dsi_wait_pll_hsdiv_dispc_active(struct platform_device *dsidev)
4417 if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 7, 1) != 1)
4418 DSSERR("%s (%s) not active\n",
4419 dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
4420 dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC));
4423 void dsi_wait_pll_hsdiv_dsi_active(struct platform_device *dsidev)
4425 if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 8, 1) != 1)
4426 DSSERR("%s (%s) not active\n",
4427 dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
4428 dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI));
4431 static void dsi_calc_clock_param_ranges(struct platform_device *dsidev)
4433 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4435 dsi->regn_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGN);
4436 dsi->regm_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM);
4437 dsi->regm_dispc_max =
4438 dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DISPC);
4439 dsi->regm_dsi_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DSI);
4440 dsi->fint_min = dss_feat_get_param_min(FEAT_PARAM_DSIPLL_FINT);
4441 dsi->fint_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_FINT);
4442 dsi->lpdiv_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_LPDIV);
4445 static int dsi_get_clocks(struct platform_device *dsidev)
4447 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4450 clk = clk_get(&dsidev->dev, "fck");
4452 DSSERR("can't get fck\n");
4453 return PTR_ERR(clk);
4458 clk = clk_get(&dsidev->dev, "sys_clk");
4460 DSSERR("can't get sys_clk\n");
4461 clk_put(dsi->dss_clk);
4462 dsi->dss_clk = NULL;
4463 return PTR_ERR(clk);
4471 static void dsi_put_clocks(struct platform_device *dsidev)
4473 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4476 clk_put(dsi->dss_clk);
4478 clk_put(dsi->sys_clk);
4481 /* DSI1 HW IP initialisation */
4482 static int omap_dsihw_probe(struct platform_device *dsidev)
4484 struct omap_display_platform_data *dss_plat_data;
4485 struct omap_dss_board_info *board_info;
4487 int r, i, dsi_module = dsi_get_dsidev_id(dsidev);
4488 struct resource *dsi_mem;
4489 struct dsi_data *dsi;
4491 dsi = kzalloc(sizeof(*dsi), GFP_KERNEL);
4498 dsi_pdev_map[dsi_module] = dsidev;
4499 dev_set_drvdata(&dsidev->dev, dsi);
4501 dss_plat_data = dsidev->dev.platform_data;
4502 board_info = dss_plat_data->board_data;
4503 dsi->enable_pads = board_info->dsi_enable_pads;
4504 dsi->disable_pads = board_info->dsi_disable_pads;
4506 spin_lock_init(&dsi->irq_lock);
4507 spin_lock_init(&dsi->errors_lock);
4510 #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
4511 spin_lock_init(&dsi->irq_stats_lock);
4512 dsi->irq_stats.last_reset = jiffies;
4515 mutex_init(&dsi->lock);
4516 sema_init(&dsi->bus_lock, 1);
4518 r = dsi_get_clocks(dsidev);
4522 pm_runtime_enable(&dsidev->dev);
4524 INIT_DELAYED_WORK_DEFERRABLE(&dsi->framedone_timeout_work,
4525 dsi_framedone_timeout_work_callback);
4527 #ifdef DSI_CATCH_MISSING_TE
4528 init_timer(&dsi->te_timer);
4529 dsi->te_timer.function = dsi_te_timeout;
4530 dsi->te_timer.data = 0;
4532 dsi_mem = platform_get_resource(dsi->pdev, IORESOURCE_MEM, 0);
4534 DSSERR("can't get IORESOURCE_MEM DSI\n");
4538 dsi->base = ioremap(dsi_mem->start, resource_size(dsi_mem));
4540 DSSERR("can't ioremap DSI\n");
4544 dsi->irq = platform_get_irq(dsi->pdev, 0);
4546 DSSERR("platform_get_irq failed\n");
4551 r = request_irq(dsi->irq, omap_dsi_irq_handler, IRQF_SHARED,
4552 dev_name(&dsidev->dev), dsi->pdev);
4554 DSSERR("request_irq failed\n");
4558 /* DSI VCs initialization */
4559 for (i = 0; i < ARRAY_SIZE(dsi->vc); i++) {
4560 dsi->vc[i].mode = DSI_VC_MODE_L4;
4561 dsi->vc[i].dssdev = NULL;
4562 dsi->vc[i].vc_id = 0;
4565 dsi_calc_clock_param_ranges(dsidev);
4567 r = dsi_runtime_get(dsidev);
4571 rev = dsi_read_reg(dsidev, DSI_REVISION);
4572 dev_dbg(&dsidev->dev, "OMAP DSI rev %d.%d\n",
4573 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
4575 dsi->num_data_lanes = dsi_get_num_data_lanes(dsidev);
4577 dsi_runtime_put(dsidev);
4582 free_irq(dsi->irq, dsi->pdev);
4586 pm_runtime_disable(&dsidev->dev);
4593 static int omap_dsihw_remove(struct platform_device *dsidev)
4595 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4597 WARN_ON(dsi->scp_clk_refcount > 0);
4599 pm_runtime_disable(&dsidev->dev);
4601 dsi_put_clocks(dsidev);
4603 if (dsi->vdds_dsi_reg != NULL) {
4604 if (dsi->vdds_dsi_enabled) {
4605 regulator_disable(dsi->vdds_dsi_reg);
4606 dsi->vdds_dsi_enabled = false;
4609 regulator_put(dsi->vdds_dsi_reg);
4610 dsi->vdds_dsi_reg = NULL;
4613 free_irq(dsi->irq, dsi->pdev);
4621 static int dsi_runtime_suspend(struct device *dev)
4623 dispc_runtime_put();
4629 static int dsi_runtime_resume(struct device *dev)
4633 r = dss_runtime_get();
4637 r = dispc_runtime_get();
4649 static const struct dev_pm_ops dsi_pm_ops = {
4650 .runtime_suspend = dsi_runtime_suspend,
4651 .runtime_resume = dsi_runtime_resume,
4654 static struct platform_driver omap_dsihw_driver = {
4655 .probe = omap_dsihw_probe,
4656 .remove = omap_dsihw_remove,
4658 .name = "omapdss_dsi",
4659 .owner = THIS_MODULE,
4664 int dsi_init_platform_driver(void)
4666 return platform_driver_register(&omap_dsihw_driver);
4669 void dsi_uninit_platform_driver(void)
4671 return platform_driver_unregister(&omap_dsihw_driver);