blob: 5b62176745599629628e173336e1049fe4d950c8 [file] [log] [blame]
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001/*
2 * linux/drivers/video/omap2/dss/dsi.c
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published by
9 * the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#define DSS_SUBSYS_NAME "DSI"
21
22#include <linux/kernel.h>
23#include <linux/io.h>
24#include <linux/clk.h>
25#include <linux/device.h>
26#include <linux/err.h>
27#include <linux/interrupt.h>
28#include <linux/delay.h>
29#include <linux/mutex.h>
Tomi Valkeinenb9eb5d72010-01-11 16:33:56 +020030#include <linux/semaphore.h>
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +020031#include <linux/seq_file.h>
32#include <linux/platform_device.h>
33#include <linux/regulator/consumer.h>
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +020034#include <linux/wait.h>
Tomi Valkeinen18946f62010-01-12 14:16:41 +020035#include <linux/workqueue.h>
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +020036
37#include <plat/display.h>
38#include <plat/clock.h>
39
40#include "dss.h"
41
42/*#define VERBOSE_IRQ*/
43#define DSI_CATCH_MISSING_TE
44
45#define DSI_BASE 0x4804FC00
46
47struct dsi_reg { u16 idx; };
48
49#define DSI_REG(idx) ((const struct dsi_reg) { idx })
50
51#define DSI_SZ_REGS SZ_1K
52/* DSI Protocol Engine */
53
54#define DSI_REVISION DSI_REG(0x0000)
55#define DSI_SYSCONFIG DSI_REG(0x0010)
56#define DSI_SYSSTATUS DSI_REG(0x0014)
57#define DSI_IRQSTATUS DSI_REG(0x0018)
58#define DSI_IRQENABLE DSI_REG(0x001C)
59#define DSI_CTRL DSI_REG(0x0040)
60#define DSI_COMPLEXIO_CFG1 DSI_REG(0x0048)
61#define DSI_COMPLEXIO_IRQ_STATUS DSI_REG(0x004C)
62#define DSI_COMPLEXIO_IRQ_ENABLE DSI_REG(0x0050)
63#define DSI_CLK_CTRL DSI_REG(0x0054)
64#define DSI_TIMING1 DSI_REG(0x0058)
65#define DSI_TIMING2 DSI_REG(0x005C)
66#define DSI_VM_TIMING1 DSI_REG(0x0060)
67#define DSI_VM_TIMING2 DSI_REG(0x0064)
68#define DSI_VM_TIMING3 DSI_REG(0x0068)
69#define DSI_CLK_TIMING DSI_REG(0x006C)
70#define DSI_TX_FIFO_VC_SIZE DSI_REG(0x0070)
71#define DSI_RX_FIFO_VC_SIZE DSI_REG(0x0074)
72#define DSI_COMPLEXIO_CFG2 DSI_REG(0x0078)
73#define DSI_RX_FIFO_VC_FULLNESS DSI_REG(0x007C)
74#define DSI_VM_TIMING4 DSI_REG(0x0080)
75#define DSI_TX_FIFO_VC_EMPTINESS DSI_REG(0x0084)
76#define DSI_VM_TIMING5 DSI_REG(0x0088)
77#define DSI_VM_TIMING6 DSI_REG(0x008C)
78#define DSI_VM_TIMING7 DSI_REG(0x0090)
79#define DSI_STOPCLK_TIMING DSI_REG(0x0094)
80#define DSI_VC_CTRL(n) DSI_REG(0x0100 + (n * 0x20))
81#define DSI_VC_TE(n) DSI_REG(0x0104 + (n * 0x20))
82#define DSI_VC_LONG_PACKET_HEADER(n) DSI_REG(0x0108 + (n * 0x20))
83#define DSI_VC_LONG_PACKET_PAYLOAD(n) DSI_REG(0x010C + (n * 0x20))
84#define DSI_VC_SHORT_PACKET_HEADER(n) DSI_REG(0x0110 + (n * 0x20))
85#define DSI_VC_IRQSTATUS(n) DSI_REG(0x0118 + (n * 0x20))
86#define DSI_VC_IRQENABLE(n) DSI_REG(0x011C + (n * 0x20))
87
88/* DSIPHY_SCP */
89
90#define DSI_DSIPHY_CFG0 DSI_REG(0x200 + 0x0000)
91#define DSI_DSIPHY_CFG1 DSI_REG(0x200 + 0x0004)
92#define DSI_DSIPHY_CFG2 DSI_REG(0x200 + 0x0008)
93#define DSI_DSIPHY_CFG5 DSI_REG(0x200 + 0x0014)
94
95/* DSI_PLL_CTRL_SCP */
96
97#define DSI_PLL_CONTROL DSI_REG(0x300 + 0x0000)
98#define DSI_PLL_STATUS DSI_REG(0x300 + 0x0004)
99#define DSI_PLL_GO DSI_REG(0x300 + 0x0008)
100#define DSI_PLL_CONFIGURATION1 DSI_REG(0x300 + 0x000C)
101#define DSI_PLL_CONFIGURATION2 DSI_REG(0x300 + 0x0010)
102
103#define REG_GET(idx, start, end) \
104 FLD_GET(dsi_read_reg(idx), start, end)
105
106#define REG_FLD_MOD(idx, val, start, end) \
107 dsi_write_reg(idx, FLD_MOD(dsi_read_reg(idx), val, start, end))
108
109/* Global interrupts */
110#define DSI_IRQ_VC0 (1 << 0)
111#define DSI_IRQ_VC1 (1 << 1)
112#define DSI_IRQ_VC2 (1 << 2)
113#define DSI_IRQ_VC3 (1 << 3)
114#define DSI_IRQ_WAKEUP (1 << 4)
115#define DSI_IRQ_RESYNC (1 << 5)
116#define DSI_IRQ_PLL_LOCK (1 << 7)
117#define DSI_IRQ_PLL_UNLOCK (1 << 8)
118#define DSI_IRQ_PLL_RECALL (1 << 9)
119#define DSI_IRQ_COMPLEXIO_ERR (1 << 10)
120#define DSI_IRQ_HS_TX_TIMEOUT (1 << 14)
121#define DSI_IRQ_LP_RX_TIMEOUT (1 << 15)
122#define DSI_IRQ_TE_TRIGGER (1 << 16)
123#define DSI_IRQ_ACK_TRIGGER (1 << 17)
124#define DSI_IRQ_SYNC_LOST (1 << 18)
125#define DSI_IRQ_LDO_POWER_GOOD (1 << 19)
126#define DSI_IRQ_TA_TIMEOUT (1 << 20)
127#define DSI_IRQ_ERROR_MASK \
128 (DSI_IRQ_HS_TX_TIMEOUT | DSI_IRQ_LP_RX_TIMEOUT | DSI_IRQ_SYNC_LOST | \
129 DSI_IRQ_TA_TIMEOUT)
130#define DSI_IRQ_CHANNEL_MASK 0xf
131
132/* Virtual channel interrupts */
133#define DSI_VC_IRQ_CS (1 << 0)
134#define DSI_VC_IRQ_ECC_CORR (1 << 1)
135#define DSI_VC_IRQ_PACKET_SENT (1 << 2)
136#define DSI_VC_IRQ_FIFO_TX_OVF (1 << 3)
137#define DSI_VC_IRQ_FIFO_RX_OVF (1 << 4)
138#define DSI_VC_IRQ_BTA (1 << 5)
139#define DSI_VC_IRQ_ECC_NO_CORR (1 << 6)
140#define DSI_VC_IRQ_FIFO_TX_UDF (1 << 7)
141#define DSI_VC_IRQ_PP_BUSY_CHANGE (1 << 8)
142#define DSI_VC_IRQ_ERROR_MASK \
143 (DSI_VC_IRQ_CS | DSI_VC_IRQ_ECC_CORR | DSI_VC_IRQ_FIFO_TX_OVF | \
144 DSI_VC_IRQ_FIFO_RX_OVF | DSI_VC_IRQ_ECC_NO_CORR | \
145 DSI_VC_IRQ_FIFO_TX_UDF)
146
147/* ComplexIO interrupts */
148#define DSI_CIO_IRQ_ERRSYNCESC1 (1 << 0)
149#define DSI_CIO_IRQ_ERRSYNCESC2 (1 << 1)
150#define DSI_CIO_IRQ_ERRSYNCESC3 (1 << 2)
151#define DSI_CIO_IRQ_ERRESC1 (1 << 5)
152#define DSI_CIO_IRQ_ERRESC2 (1 << 6)
153#define DSI_CIO_IRQ_ERRESC3 (1 << 7)
154#define DSI_CIO_IRQ_ERRCONTROL1 (1 << 10)
155#define DSI_CIO_IRQ_ERRCONTROL2 (1 << 11)
156#define DSI_CIO_IRQ_ERRCONTROL3 (1 << 12)
157#define DSI_CIO_IRQ_STATEULPS1 (1 << 15)
158#define DSI_CIO_IRQ_STATEULPS2 (1 << 16)
159#define DSI_CIO_IRQ_STATEULPS3 (1 << 17)
160#define DSI_CIO_IRQ_ERRCONTENTIONLP0_1 (1 << 20)
161#define DSI_CIO_IRQ_ERRCONTENTIONLP1_1 (1 << 21)
162#define DSI_CIO_IRQ_ERRCONTENTIONLP0_2 (1 << 22)
163#define DSI_CIO_IRQ_ERRCONTENTIONLP1_2 (1 << 23)
164#define DSI_CIO_IRQ_ERRCONTENTIONLP0_3 (1 << 24)
165#define DSI_CIO_IRQ_ERRCONTENTIONLP1_3 (1 << 25)
166#define DSI_CIO_IRQ_ULPSACTIVENOT_ALL0 (1 << 30)
167#define DSI_CIO_IRQ_ULPSACTIVENOT_ALL1 (1 << 31)
168
169#define DSI_DT_DCS_SHORT_WRITE_0 0x05
170#define DSI_DT_DCS_SHORT_WRITE_1 0x15
171#define DSI_DT_DCS_READ 0x06
172#define DSI_DT_SET_MAX_RET_PKG_SIZE 0x37
173#define DSI_DT_NULL_PACKET 0x09
174#define DSI_DT_DCS_LONG_WRITE 0x39
175
176#define DSI_DT_RX_ACK_WITH_ERR 0x02
177#define DSI_DT_RX_DCS_LONG_READ 0x1c
178#define DSI_DT_RX_SHORT_READ_1 0x21
179#define DSI_DT_RX_SHORT_READ_2 0x22
180
181#define FINT_MAX 2100000
182#define FINT_MIN 750000
183#define REGN_MAX (1 << 7)
184#define REGM_MAX ((1 << 11) - 1)
185#define REGM3_MAX (1 << 4)
186#define REGM4_MAX (1 << 4)
187#define LP_DIV_MAX ((1 << 13) - 1)
188
189enum fifo_size {
190 DSI_FIFO_SIZE_0 = 0,
191 DSI_FIFO_SIZE_32 = 1,
192 DSI_FIFO_SIZE_64 = 2,
193 DSI_FIFO_SIZE_96 = 3,
194 DSI_FIFO_SIZE_128 = 4,
195};
196
197enum dsi_vc_mode {
198 DSI_VC_MODE_L4 = 0,
199 DSI_VC_MODE_VP,
200};
201
202struct dsi_update_region {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200203 u16 x, y, w, h;
204 struct omap_dss_device *device;
205};
206
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200207struct dsi_irq_stats {
208 unsigned long last_reset;
209 unsigned irq_count;
210 unsigned dsi_irqs[32];
211 unsigned vc_irqs[4][32];
212 unsigned cio_irqs[32];
213};
214
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200215static struct
216{
217 void __iomem *base;
218
219 struct dsi_clock_info current_cinfo;
220
221 struct regulator *vdds_dsi_reg;
222
223 struct {
224 enum dsi_vc_mode mode;
225 struct omap_dss_device *dssdev;
226 enum fifo_size fifo_size;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200227 } vc[4];
228
229 struct mutex lock;
Tomi Valkeinenb9eb5d72010-01-11 16:33:56 +0200230 struct semaphore bus_lock;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200231
232 unsigned pll_locked;
233
234 struct completion bta_completion;
235
Tomi Valkeinen18946f62010-01-12 14:16:41 +0200236 int update_channel;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200237 struct dsi_update_region update_region;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200238
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200239 bool te_enabled;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200240
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +0300241 struct workqueue_struct *workqueue;
242
Tomi Valkeinen18946f62010-01-12 14:16:41 +0200243 struct work_struct framedone_work;
244 void (*framedone_callback)(int, void *);
245 void *framedone_data;
246
247 struct delayed_work framedone_timeout_work;
248
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200249#ifdef DSI_CATCH_MISSING_TE
250 struct timer_list te_timer;
251#endif
252
253 unsigned long cache_req_pck;
254 unsigned long cache_clk_freq;
255 struct dsi_clock_info cache_cinfo;
256
257 u32 errors;
258 spinlock_t errors_lock;
259#ifdef DEBUG
260 ktime_t perf_setup_time;
261 ktime_t perf_start_time;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200262#endif
263 int debug_read;
264 int debug_write;
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200265
266#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
267 spinlock_t irq_stats_lock;
268 struct dsi_irq_stats irq_stats;
269#endif
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200270} dsi;
271
272#ifdef DEBUG
273static unsigned int dsi_perf;
274module_param_named(dsi_perf, dsi_perf, bool, 0644);
275#endif
276
277static inline void dsi_write_reg(const struct dsi_reg idx, u32 val)
278{
279 __raw_writel(val, dsi.base + idx.idx);
280}
281
282static inline u32 dsi_read_reg(const struct dsi_reg idx)
283{
284 return __raw_readl(dsi.base + idx.idx);
285}
286
287
288void dsi_save_context(void)
289{
290}
291
292void dsi_restore_context(void)
293{
294}
295
296void dsi_bus_lock(void)
297{
Tomi Valkeinenb9eb5d72010-01-11 16:33:56 +0200298 down(&dsi.bus_lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200299}
300EXPORT_SYMBOL(dsi_bus_lock);
301
302void dsi_bus_unlock(void)
303{
Tomi Valkeinenb9eb5d72010-01-11 16:33:56 +0200304 up(&dsi.bus_lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200305}
306EXPORT_SYMBOL(dsi_bus_unlock);
307
Tomi Valkeinen4f765022010-01-18 16:27:52 +0200308static bool dsi_bus_is_locked(void)
309{
Tomi Valkeinenb9eb5d72010-01-11 16:33:56 +0200310 return dsi.bus_lock.count == 0;
Tomi Valkeinen4f765022010-01-18 16:27:52 +0200311}
312
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200313static inline int wait_for_bit_change(const struct dsi_reg idx, int bitnum,
314 int value)
315{
316 int t = 100000;
317
318 while (REG_GET(idx, bitnum, bitnum) != value) {
319 if (--t == 0)
320 return !value;
321 }
322
323 return value;
324}
325
326#ifdef DEBUG
327static void dsi_perf_mark_setup(void)
328{
329 dsi.perf_setup_time = ktime_get();
330}
331
332static void dsi_perf_mark_start(void)
333{
334 dsi.perf_start_time = ktime_get();
335}
336
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200337static void dsi_perf_show(const char *name)
338{
339 ktime_t t, setup_time, trans_time;
340 u32 total_bytes;
341 u32 setup_us, trans_us, total_us;
342
343 if (!dsi_perf)
344 return;
345
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200346 t = ktime_get();
347
348 setup_time = ktime_sub(dsi.perf_start_time, dsi.perf_setup_time);
349 setup_us = (u32)ktime_to_us(setup_time);
350 if (setup_us == 0)
351 setup_us = 1;
352
353 trans_time = ktime_sub(t, dsi.perf_start_time);
354 trans_us = (u32)ktime_to_us(trans_time);
355 if (trans_us == 0)
356 trans_us = 1;
357
358 total_us = setup_us + trans_us;
359
Tomi Valkeinen18946f62010-01-12 14:16:41 +0200360 total_bytes = dsi.update_region.w *
361 dsi.update_region.h *
362 dsi.update_region.device->ctrl.pixel_size / 8;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200363
Tomi Valkeinen1bbb2752010-01-11 16:41:10 +0200364 printk(KERN_INFO "DSI(%s): %u us + %u us = %u us (%uHz), "
365 "%u bytes, %u kbytes/sec\n",
366 name,
367 setup_us,
368 trans_us,
369 total_us,
370 1000*1000 / total_us,
371 total_bytes,
372 total_bytes * 1000 / total_us);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200373}
374#else
375#define dsi_perf_mark_setup()
376#define dsi_perf_mark_start()
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200377#define dsi_perf_show(x)
378#endif
379
380static void print_irq_status(u32 status)
381{
382#ifndef VERBOSE_IRQ
383 if ((status & ~DSI_IRQ_CHANNEL_MASK) == 0)
384 return;
385#endif
386 printk(KERN_DEBUG "DSI IRQ: 0x%x: ", status);
387
388#define PIS(x) \
389 if (status & DSI_IRQ_##x) \
390 printk(#x " ");
391#ifdef VERBOSE_IRQ
392 PIS(VC0);
393 PIS(VC1);
394 PIS(VC2);
395 PIS(VC3);
396#endif
397 PIS(WAKEUP);
398 PIS(RESYNC);
399 PIS(PLL_LOCK);
400 PIS(PLL_UNLOCK);
401 PIS(PLL_RECALL);
402 PIS(COMPLEXIO_ERR);
403 PIS(HS_TX_TIMEOUT);
404 PIS(LP_RX_TIMEOUT);
405 PIS(TE_TRIGGER);
406 PIS(ACK_TRIGGER);
407 PIS(SYNC_LOST);
408 PIS(LDO_POWER_GOOD);
409 PIS(TA_TIMEOUT);
410#undef PIS
411
412 printk("\n");
413}
414
415static void print_irq_status_vc(int channel, u32 status)
416{
417#ifndef VERBOSE_IRQ
418 if ((status & ~DSI_VC_IRQ_PACKET_SENT) == 0)
419 return;
420#endif
421 printk(KERN_DEBUG "DSI VC(%d) IRQ 0x%x: ", channel, status);
422
423#define PIS(x) \
424 if (status & DSI_VC_IRQ_##x) \
425 printk(#x " ");
426 PIS(CS);
427 PIS(ECC_CORR);
428#ifdef VERBOSE_IRQ
429 PIS(PACKET_SENT);
430#endif
431 PIS(FIFO_TX_OVF);
432 PIS(FIFO_RX_OVF);
433 PIS(BTA);
434 PIS(ECC_NO_CORR);
435 PIS(FIFO_TX_UDF);
436 PIS(PP_BUSY_CHANGE);
437#undef PIS
438 printk("\n");
439}
440
441static void print_irq_status_cio(u32 status)
442{
443 printk(KERN_DEBUG "DSI CIO IRQ 0x%x: ", status);
444
445#define PIS(x) \
446 if (status & DSI_CIO_IRQ_##x) \
447 printk(#x " ");
448 PIS(ERRSYNCESC1);
449 PIS(ERRSYNCESC2);
450 PIS(ERRSYNCESC3);
451 PIS(ERRESC1);
452 PIS(ERRESC2);
453 PIS(ERRESC3);
454 PIS(ERRCONTROL1);
455 PIS(ERRCONTROL2);
456 PIS(ERRCONTROL3);
457 PIS(STATEULPS1);
458 PIS(STATEULPS2);
459 PIS(STATEULPS3);
460 PIS(ERRCONTENTIONLP0_1);
461 PIS(ERRCONTENTIONLP1_1);
462 PIS(ERRCONTENTIONLP0_2);
463 PIS(ERRCONTENTIONLP1_2);
464 PIS(ERRCONTENTIONLP0_3);
465 PIS(ERRCONTENTIONLP1_3);
466 PIS(ULPSACTIVENOT_ALL0);
467 PIS(ULPSACTIVENOT_ALL1);
468#undef PIS
469
470 printk("\n");
471}
472
473static int debug_irq;
474
475/* called from dss */
476void dsi_irq_handler(void)
477{
478 u32 irqstatus, vcstatus, ciostatus;
479 int i;
480
481 irqstatus = dsi_read_reg(DSI_IRQSTATUS);
482
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200483#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
484 spin_lock(&dsi.irq_stats_lock);
485 dsi.irq_stats.irq_count++;
486 dss_collect_irq_stats(irqstatus, dsi.irq_stats.dsi_irqs);
487#endif
488
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200489 if (irqstatus & DSI_IRQ_ERROR_MASK) {
490 DSSERR("DSI error, irqstatus %x\n", irqstatus);
491 print_irq_status(irqstatus);
492 spin_lock(&dsi.errors_lock);
493 dsi.errors |= irqstatus & DSI_IRQ_ERROR_MASK;
494 spin_unlock(&dsi.errors_lock);
495 } else if (debug_irq) {
496 print_irq_status(irqstatus);
497 }
498
499#ifdef DSI_CATCH_MISSING_TE
500 if (irqstatus & DSI_IRQ_TE_TRIGGER)
501 del_timer(&dsi.te_timer);
502#endif
503
504 for (i = 0; i < 4; ++i) {
505 if ((irqstatus & (1<<i)) == 0)
506 continue;
507
508 vcstatus = dsi_read_reg(DSI_VC_IRQSTATUS(i));
509
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200510#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
511 dss_collect_irq_stats(vcstatus, dsi.irq_stats.vc_irqs[i]);
512#endif
513
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200514 if (vcstatus & DSI_VC_IRQ_BTA)
515 complete(&dsi.bta_completion);
516
517 if (vcstatus & DSI_VC_IRQ_ERROR_MASK) {
518 DSSERR("DSI VC(%d) error, vc irqstatus %x\n",
519 i, vcstatus);
520 print_irq_status_vc(i, vcstatus);
521 } else if (debug_irq) {
522 print_irq_status_vc(i, vcstatus);
523 }
524
525 dsi_write_reg(DSI_VC_IRQSTATUS(i), vcstatus);
526 /* flush posted write */
527 dsi_read_reg(DSI_VC_IRQSTATUS(i));
528 }
529
530 if (irqstatus & DSI_IRQ_COMPLEXIO_ERR) {
531 ciostatus = dsi_read_reg(DSI_COMPLEXIO_IRQ_STATUS);
532
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200533#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
534 dss_collect_irq_stats(ciostatus, dsi.irq_stats.cio_irqs);
535#endif
536
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200537 dsi_write_reg(DSI_COMPLEXIO_IRQ_STATUS, ciostatus);
538 /* flush posted write */
539 dsi_read_reg(DSI_COMPLEXIO_IRQ_STATUS);
540
541 DSSERR("DSI CIO error, cio irqstatus %x\n", ciostatus);
542 print_irq_status_cio(ciostatus);
543 }
544
545 dsi_write_reg(DSI_IRQSTATUS, irqstatus & ~DSI_IRQ_CHANNEL_MASK);
546 /* flush posted write */
547 dsi_read_reg(DSI_IRQSTATUS);
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200548
549#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
550 spin_unlock(&dsi.irq_stats_lock);
551#endif
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200552}
553
554
555static void _dsi_initialize_irq(void)
556{
557 u32 l;
558 int i;
559
560 /* disable all interrupts */
561 dsi_write_reg(DSI_IRQENABLE, 0);
562 for (i = 0; i < 4; ++i)
563 dsi_write_reg(DSI_VC_IRQENABLE(i), 0);
564 dsi_write_reg(DSI_COMPLEXIO_IRQ_ENABLE, 0);
565
566 /* clear interrupt status */
567 l = dsi_read_reg(DSI_IRQSTATUS);
568 dsi_write_reg(DSI_IRQSTATUS, l & ~DSI_IRQ_CHANNEL_MASK);
569
570 for (i = 0; i < 4; ++i) {
571 l = dsi_read_reg(DSI_VC_IRQSTATUS(i));
572 dsi_write_reg(DSI_VC_IRQSTATUS(i), l);
573 }
574
575 l = dsi_read_reg(DSI_COMPLEXIO_IRQ_STATUS);
576 dsi_write_reg(DSI_COMPLEXIO_IRQ_STATUS, l);
577
578 /* enable error irqs */
579 l = DSI_IRQ_ERROR_MASK;
580#ifdef DSI_CATCH_MISSING_TE
581 l |= DSI_IRQ_TE_TRIGGER;
582#endif
583 dsi_write_reg(DSI_IRQENABLE, l);
584
585 l = DSI_VC_IRQ_ERROR_MASK;
586 for (i = 0; i < 4; ++i)
587 dsi_write_reg(DSI_VC_IRQENABLE(i), l);
588
589 /* XXX zonda responds incorrectly, causing control error:
590 Exit from LP-ESC mode to LP11 uses wrong transition states on the
591 data lines LP0 and LN0. */
592 dsi_write_reg(DSI_COMPLEXIO_IRQ_ENABLE,
593 -1 & (~DSI_CIO_IRQ_ERRCONTROL2));
594}
595
596static u32 dsi_get_errors(void)
597{
598 unsigned long flags;
599 u32 e;
600 spin_lock_irqsave(&dsi.errors_lock, flags);
601 e = dsi.errors;
602 dsi.errors = 0;
603 spin_unlock_irqrestore(&dsi.errors_lock, flags);
604 return e;
605}
606
607static void dsi_vc_enable_bta_irq(int channel)
608{
609 u32 l;
610
611 dsi_write_reg(DSI_VC_IRQSTATUS(channel), DSI_VC_IRQ_BTA);
612
613 l = dsi_read_reg(DSI_VC_IRQENABLE(channel));
614 l |= DSI_VC_IRQ_BTA;
615 dsi_write_reg(DSI_VC_IRQENABLE(channel), l);
616}
617
618static void dsi_vc_disable_bta_irq(int channel)
619{
620 u32 l;
621
622 l = dsi_read_reg(DSI_VC_IRQENABLE(channel));
623 l &= ~DSI_VC_IRQ_BTA;
624 dsi_write_reg(DSI_VC_IRQENABLE(channel), l);
625}
626
627/* DSI func clock. this could also be DSI2_PLL_FCLK */
628static inline void enable_clocks(bool enable)
629{
630 if (enable)
631 dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK1);
632 else
633 dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK1);
634}
635
636/* source clock for DSI PLL. this could also be PCLKFREE */
637static inline void dsi_enable_pll_clock(bool enable)
638{
639 if (enable)
640 dss_clk_enable(DSS_CLK_FCK2);
641 else
642 dss_clk_disable(DSS_CLK_FCK2);
643
644 if (enable && dsi.pll_locked) {
645 if (wait_for_bit_change(DSI_PLL_STATUS, 1, 1) != 1)
646 DSSERR("cannot lock PLL when enabling clocks\n");
647 }
648}
649
650#ifdef DEBUG
651static void _dsi_print_reset_status(void)
652{
653 u32 l;
654
655 if (!dss_debug)
656 return;
657
658 /* A dummy read using the SCP interface to any DSIPHY register is
659 * required after DSIPHY reset to complete the reset of the DSI complex
660 * I/O. */
661 l = dsi_read_reg(DSI_DSIPHY_CFG5);
662
663 printk(KERN_DEBUG "DSI resets: ");
664
665 l = dsi_read_reg(DSI_PLL_STATUS);
666 printk("PLL (%d) ", FLD_GET(l, 0, 0));
667
668 l = dsi_read_reg(DSI_COMPLEXIO_CFG1);
669 printk("CIO (%d) ", FLD_GET(l, 29, 29));
670
671 l = dsi_read_reg(DSI_DSIPHY_CFG5);
672 printk("PHY (%x, %d, %d, %d)\n",
673 FLD_GET(l, 28, 26),
674 FLD_GET(l, 29, 29),
675 FLD_GET(l, 30, 30),
676 FLD_GET(l, 31, 31));
677}
678#else
679#define _dsi_print_reset_status()
680#endif
681
682static inline int dsi_if_enable(bool enable)
683{
684 DSSDBG("dsi_if_enable(%d)\n", enable);
685
686 enable = enable ? 1 : 0;
687 REG_FLD_MOD(DSI_CTRL, enable, 0, 0); /* IF_EN */
688
689 if (wait_for_bit_change(DSI_CTRL, 0, enable) != enable) {
690 DSSERR("Failed to set dsi_if_enable to %d\n", enable);
691 return -EIO;
692 }
693
694 return 0;
695}
696
697unsigned long dsi_get_dsi1_pll_rate(void)
698{
699 return dsi.current_cinfo.dsi1_pll_fclk;
700}
701
702static unsigned long dsi_get_dsi2_pll_rate(void)
703{
704 return dsi.current_cinfo.dsi2_pll_fclk;
705}
706
707static unsigned long dsi_get_txbyteclkhs(void)
708{
709 return dsi.current_cinfo.clkin4ddr / 16;
710}
711
712static unsigned long dsi_fclk_rate(void)
713{
714 unsigned long r;
715
Tomi Valkeinen63cf28a2010-02-23 17:40:00 +0200716 if (dss_get_dsi_clk_source() == DSS_SRC_DSS1_ALWON_FCLK) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200717 /* DSI FCLK source is DSS1_ALWON_FCK, which is dss1_fck */
718 r = dss_clk_get_rate(DSS_CLK_FCK1);
719 } else {
720 /* DSI FCLK source is DSI2_PLL_FCLK */
721 r = dsi_get_dsi2_pll_rate();
722 }
723
724 return r;
725}
726
727static int dsi_set_lp_clk_divisor(struct omap_dss_device *dssdev)
728{
729 unsigned long dsi_fclk;
730 unsigned lp_clk_div;
731 unsigned long lp_clk;
732
733 lp_clk_div = dssdev->phy.dsi.div.lp_clk_div;
734
735 if (lp_clk_div == 0 || lp_clk_div > LP_DIV_MAX)
736 return -EINVAL;
737
738 dsi_fclk = dsi_fclk_rate();
739
740 lp_clk = dsi_fclk / 2 / lp_clk_div;
741
742 DSSDBG("LP_CLK_DIV %u, LP_CLK %lu\n", lp_clk_div, lp_clk);
743 dsi.current_cinfo.lp_clk = lp_clk;
744 dsi.current_cinfo.lp_clk_div = lp_clk_div;
745
746 REG_FLD_MOD(DSI_CLK_CTRL, lp_clk_div, 12, 0); /* LP_CLK_DIVISOR */
747
748 REG_FLD_MOD(DSI_CLK_CTRL, dsi_fclk > 30000000 ? 1 : 0,
749 21, 21); /* LP_RX_SYNCHRO_ENABLE */
750
751 return 0;
752}
753
754
755enum dsi_pll_power_state {
756 DSI_PLL_POWER_OFF = 0x0,
757 DSI_PLL_POWER_ON_HSCLK = 0x1,
758 DSI_PLL_POWER_ON_ALL = 0x2,
759 DSI_PLL_POWER_ON_DIV = 0x3,
760};
761
762static int dsi_pll_power(enum dsi_pll_power_state state)
763{
764 int t = 0;
765
766 REG_FLD_MOD(DSI_CLK_CTRL, state, 31, 30); /* PLL_PWR_CMD */
767
768 /* PLL_PWR_STATUS */
769 while (FLD_GET(dsi_read_reg(DSI_CLK_CTRL), 29, 28) != state) {
Tomi Valkeinen24be78b2010-01-07 14:19:48 +0200770 if (++t > 1000) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200771 DSSERR("Failed to set DSI PLL power mode to %d\n",
772 state);
773 return -ENODEV;
774 }
Tomi Valkeinen24be78b2010-01-07 14:19:48 +0200775 udelay(1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200776 }
777
778 return 0;
779}
780
781/* calculate clock rates using dividers in cinfo */
782static int dsi_calc_clock_rates(struct dsi_clock_info *cinfo)
783{
784 if (cinfo->regn == 0 || cinfo->regn > REGN_MAX)
785 return -EINVAL;
786
787 if (cinfo->regm == 0 || cinfo->regm > REGM_MAX)
788 return -EINVAL;
789
790 if (cinfo->regm3 > REGM3_MAX)
791 return -EINVAL;
792
793 if (cinfo->regm4 > REGM4_MAX)
794 return -EINVAL;
795
796 if (cinfo->use_dss2_fck) {
797 cinfo->clkin = dss_clk_get_rate(DSS_CLK_FCK2);
798 /* XXX it is unclear if highfreq should be used
799 * with DSS2_FCK source also */
800 cinfo->highfreq = 0;
801 } else {
802 cinfo->clkin = dispc_pclk_rate();
803
804 if (cinfo->clkin < 32000000)
805 cinfo->highfreq = 0;
806 else
807 cinfo->highfreq = 1;
808 }
809
810 cinfo->fint = cinfo->clkin / (cinfo->regn * (cinfo->highfreq ? 2 : 1));
811
812 if (cinfo->fint > FINT_MAX || cinfo->fint < FINT_MIN)
813 return -EINVAL;
814
815 cinfo->clkin4ddr = 2 * cinfo->regm * cinfo->fint;
816
817 if (cinfo->clkin4ddr > 1800 * 1000 * 1000)
818 return -EINVAL;
819
820 if (cinfo->regm3 > 0)
821 cinfo->dsi1_pll_fclk = cinfo->clkin4ddr / cinfo->regm3;
822 else
823 cinfo->dsi1_pll_fclk = 0;
824
825 if (cinfo->regm4 > 0)
826 cinfo->dsi2_pll_fclk = cinfo->clkin4ddr / cinfo->regm4;
827 else
828 cinfo->dsi2_pll_fclk = 0;
829
830 return 0;
831}
832
833int dsi_pll_calc_clock_div_pck(bool is_tft, unsigned long req_pck,
834 struct dsi_clock_info *dsi_cinfo,
835 struct dispc_clock_info *dispc_cinfo)
836{
837 struct dsi_clock_info cur, best;
838 struct dispc_clock_info best_dispc;
839 int min_fck_per_pck;
840 int match = 0;
841 unsigned long dss_clk_fck2;
842
843 dss_clk_fck2 = dss_clk_get_rate(DSS_CLK_FCK2);
844
845 if (req_pck == dsi.cache_req_pck &&
846 dsi.cache_cinfo.clkin == dss_clk_fck2) {
847 DSSDBG("DSI clock info found from cache\n");
848 *dsi_cinfo = dsi.cache_cinfo;
849 dispc_find_clk_divs(is_tft, req_pck, dsi_cinfo->dsi1_pll_fclk,
850 dispc_cinfo);
851 return 0;
852 }
853
854 min_fck_per_pck = CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK;
855
856 if (min_fck_per_pck &&
857 req_pck * min_fck_per_pck > DISPC_MAX_FCK) {
858 DSSERR("Requested pixel clock not possible with the current "
859 "OMAP2_DSS_MIN_FCK_PER_PCK setting. Turning "
860 "the constraint off.\n");
861 min_fck_per_pck = 0;
862 }
863
864 DSSDBG("dsi_pll_calc\n");
865
866retry:
867 memset(&best, 0, sizeof(best));
868 memset(&best_dispc, 0, sizeof(best_dispc));
869
870 memset(&cur, 0, sizeof(cur));
871 cur.clkin = dss_clk_fck2;
872 cur.use_dss2_fck = 1;
873 cur.highfreq = 0;
874
875 /* no highfreq: 0.75MHz < Fint = clkin / regn < 2.1MHz */
876 /* highfreq: 0.75MHz < Fint = clkin / (2*regn) < 2.1MHz */
877 /* To reduce PLL lock time, keep Fint high (around 2 MHz) */
878 for (cur.regn = 1; cur.regn < REGN_MAX; ++cur.regn) {
879 if (cur.highfreq == 0)
880 cur.fint = cur.clkin / cur.regn;
881 else
882 cur.fint = cur.clkin / (2 * cur.regn);
883
884 if (cur.fint > FINT_MAX || cur.fint < FINT_MIN)
885 continue;
886
887 /* DSIPHY(MHz) = (2 * regm / regn) * (clkin / (highfreq + 1)) */
888 for (cur.regm = 1; cur.regm < REGM_MAX; ++cur.regm) {
889 unsigned long a, b;
890
891 a = 2 * cur.regm * (cur.clkin/1000);
892 b = cur.regn * (cur.highfreq + 1);
893 cur.clkin4ddr = a / b * 1000;
894
895 if (cur.clkin4ddr > 1800 * 1000 * 1000)
896 break;
897
898 /* DSI1_PLL_FCLK(MHz) = DSIPHY(MHz) / regm3 < 173MHz */
899 for (cur.regm3 = 1; cur.regm3 < REGM3_MAX;
900 ++cur.regm3) {
901 struct dispc_clock_info cur_dispc;
902 cur.dsi1_pll_fclk = cur.clkin4ddr / cur.regm3;
903
904 /* this will narrow down the search a bit,
905 * but still give pixclocks below what was
906 * requested */
907 if (cur.dsi1_pll_fclk < req_pck)
908 break;
909
910 if (cur.dsi1_pll_fclk > DISPC_MAX_FCK)
911 continue;
912
913 if (min_fck_per_pck &&
914 cur.dsi1_pll_fclk <
915 req_pck * min_fck_per_pck)
916 continue;
917
918 match = 1;
919
920 dispc_find_clk_divs(is_tft, req_pck,
921 cur.dsi1_pll_fclk,
922 &cur_dispc);
923
924 if (abs(cur_dispc.pck - req_pck) <
925 abs(best_dispc.pck - req_pck)) {
926 best = cur;
927 best_dispc = cur_dispc;
928
929 if (cur_dispc.pck == req_pck)
930 goto found;
931 }
932 }
933 }
934 }
935found:
936 if (!match) {
937 if (min_fck_per_pck) {
938 DSSERR("Could not find suitable clock settings.\n"
939 "Turning FCK/PCK constraint off and"
940 "trying again.\n");
941 min_fck_per_pck = 0;
942 goto retry;
943 }
944
945 DSSERR("Could not find suitable clock settings.\n");
946
947 return -EINVAL;
948 }
949
950 /* DSI2_PLL_FCLK (regm4) is not used */
951 best.regm4 = 0;
952 best.dsi2_pll_fclk = 0;
953
954 if (dsi_cinfo)
955 *dsi_cinfo = best;
956 if (dispc_cinfo)
957 *dispc_cinfo = best_dispc;
958
959 dsi.cache_req_pck = req_pck;
960 dsi.cache_clk_freq = 0;
961 dsi.cache_cinfo = best;
962
963 return 0;
964}
965
966int dsi_pll_set_clock_div(struct dsi_clock_info *cinfo)
967{
968 int r = 0;
969 u32 l;
970 int f;
971
972 DSSDBGF();
973
974 dsi.current_cinfo.fint = cinfo->fint;
975 dsi.current_cinfo.clkin4ddr = cinfo->clkin4ddr;
976 dsi.current_cinfo.dsi1_pll_fclk = cinfo->dsi1_pll_fclk;
977 dsi.current_cinfo.dsi2_pll_fclk = cinfo->dsi2_pll_fclk;
978
979 dsi.current_cinfo.regn = cinfo->regn;
980 dsi.current_cinfo.regm = cinfo->regm;
981 dsi.current_cinfo.regm3 = cinfo->regm3;
982 dsi.current_cinfo.regm4 = cinfo->regm4;
983
984 DSSDBG("DSI Fint %ld\n", cinfo->fint);
985
986 DSSDBG("clkin (%s) rate %ld, highfreq %d\n",
987 cinfo->use_dss2_fck ? "dss2_fck" : "pclkfree",
988 cinfo->clkin,
989 cinfo->highfreq);
990
991 /* DSIPHY == CLKIN4DDR */
992 DSSDBG("CLKIN4DDR = 2 * %d / %d * %lu / %d = %lu\n",
993 cinfo->regm,
994 cinfo->regn,
995 cinfo->clkin,
996 cinfo->highfreq + 1,
997 cinfo->clkin4ddr);
998
999 DSSDBG("Data rate on 1 DSI lane %ld Mbps\n",
1000 cinfo->clkin4ddr / 1000 / 1000 / 2);
1001
1002 DSSDBG("Clock lane freq %ld Hz\n", cinfo->clkin4ddr / 4);
1003
1004 DSSDBG("regm3 = %d, dsi1_pll_fclk = %lu\n",
1005 cinfo->regm3, cinfo->dsi1_pll_fclk);
1006 DSSDBG("regm4 = %d, dsi2_pll_fclk = %lu\n",
1007 cinfo->regm4, cinfo->dsi2_pll_fclk);
1008
1009 REG_FLD_MOD(DSI_PLL_CONTROL, 0, 0, 0); /* DSI_PLL_AUTOMODE = manual */
1010
1011 l = dsi_read_reg(DSI_PLL_CONFIGURATION1);
1012 l = FLD_MOD(l, 1, 0, 0); /* DSI_PLL_STOPMODE */
1013 l = FLD_MOD(l, cinfo->regn - 1, 7, 1); /* DSI_PLL_REGN */
1014 l = FLD_MOD(l, cinfo->regm, 18, 8); /* DSI_PLL_REGM */
1015 l = FLD_MOD(l, cinfo->regm3 > 0 ? cinfo->regm3 - 1 : 0,
1016 22, 19); /* DSI_CLOCK_DIV */
1017 l = FLD_MOD(l, cinfo->regm4 > 0 ? cinfo->regm4 - 1 : 0,
1018 26, 23); /* DSIPROTO_CLOCK_DIV */
1019 dsi_write_reg(DSI_PLL_CONFIGURATION1, l);
1020
1021 BUG_ON(cinfo->fint < 750000 || cinfo->fint > 2100000);
1022 if (cinfo->fint < 1000000)
1023 f = 0x3;
1024 else if (cinfo->fint < 1250000)
1025 f = 0x4;
1026 else if (cinfo->fint < 1500000)
1027 f = 0x5;
1028 else if (cinfo->fint < 1750000)
1029 f = 0x6;
1030 else
1031 f = 0x7;
1032
1033 l = dsi_read_reg(DSI_PLL_CONFIGURATION2);
1034 l = FLD_MOD(l, f, 4, 1); /* DSI_PLL_FREQSEL */
1035 l = FLD_MOD(l, cinfo->use_dss2_fck ? 0 : 1,
1036 11, 11); /* DSI_PLL_CLKSEL */
1037 l = FLD_MOD(l, cinfo->highfreq,
1038 12, 12); /* DSI_PLL_HIGHFREQ */
1039 l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */
1040 l = FLD_MOD(l, 0, 14, 14); /* DSIPHY_CLKINEN */
1041 l = FLD_MOD(l, 1, 20, 20); /* DSI_HSDIVBYPASS */
1042 dsi_write_reg(DSI_PLL_CONFIGURATION2, l);
1043
1044 REG_FLD_MOD(DSI_PLL_GO, 1, 0, 0); /* DSI_PLL_GO */
1045
1046 if (wait_for_bit_change(DSI_PLL_GO, 0, 0) != 0) {
1047 DSSERR("dsi pll go bit not going down.\n");
1048 r = -EIO;
1049 goto err;
1050 }
1051
1052 if (wait_for_bit_change(DSI_PLL_STATUS, 1, 1) != 1) {
1053 DSSERR("cannot lock PLL\n");
1054 r = -EIO;
1055 goto err;
1056 }
1057
1058 dsi.pll_locked = 1;
1059
1060 l = dsi_read_reg(DSI_PLL_CONFIGURATION2);
1061 l = FLD_MOD(l, 0, 0, 0); /* DSI_PLL_IDLE */
1062 l = FLD_MOD(l, 0, 5, 5); /* DSI_PLL_PLLLPMODE */
1063 l = FLD_MOD(l, 0, 6, 6); /* DSI_PLL_LOWCURRSTBY */
1064 l = FLD_MOD(l, 0, 7, 7); /* DSI_PLL_TIGHTPHASELOCK */
1065 l = FLD_MOD(l, 0, 8, 8); /* DSI_PLL_DRIFTGUARDEN */
1066 l = FLD_MOD(l, 0, 10, 9); /* DSI_PLL_LOCKSEL */
1067 l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */
1068 l = FLD_MOD(l, 1, 14, 14); /* DSIPHY_CLKINEN */
1069 l = FLD_MOD(l, 0, 15, 15); /* DSI_BYPASSEN */
1070 l = FLD_MOD(l, 1, 16, 16); /* DSS_CLOCK_EN */
1071 l = FLD_MOD(l, 0, 17, 17); /* DSS_CLOCK_PWDN */
1072 l = FLD_MOD(l, 1, 18, 18); /* DSI_PROTO_CLOCK_EN */
1073 l = FLD_MOD(l, 0, 19, 19); /* DSI_PROTO_CLOCK_PWDN */
1074 l = FLD_MOD(l, 0, 20, 20); /* DSI_HSDIVBYPASS */
1075 dsi_write_reg(DSI_PLL_CONFIGURATION2, l);
1076
1077 DSSDBG("PLL config done\n");
1078err:
1079 return r;
1080}
1081
1082int dsi_pll_init(struct omap_dss_device *dssdev, bool enable_hsclk,
1083 bool enable_hsdiv)
1084{
1085 int r = 0;
1086 enum dsi_pll_power_state pwstate;
1087
1088 DSSDBG("PLL init\n");
1089
1090 enable_clocks(1);
1091 dsi_enable_pll_clock(1);
1092
1093 r = regulator_enable(dsi.vdds_dsi_reg);
1094 if (r)
1095 goto err0;
1096
1097 /* XXX PLL does not come out of reset without this... */
1098 dispc_pck_free_enable(1);
1099
1100 if (wait_for_bit_change(DSI_PLL_STATUS, 0, 1) != 1) {
1101 DSSERR("PLL not coming out of reset.\n");
1102 r = -ENODEV;
1103 goto err1;
1104 }
1105
1106 /* XXX ... but if left on, we get problems when planes do not
1107 * fill the whole display. No idea about this */
1108 dispc_pck_free_enable(0);
1109
1110 if (enable_hsclk && enable_hsdiv)
1111 pwstate = DSI_PLL_POWER_ON_ALL;
1112 else if (enable_hsclk)
1113 pwstate = DSI_PLL_POWER_ON_HSCLK;
1114 else if (enable_hsdiv)
1115 pwstate = DSI_PLL_POWER_ON_DIV;
1116 else
1117 pwstate = DSI_PLL_POWER_OFF;
1118
1119 r = dsi_pll_power(pwstate);
1120
1121 if (r)
1122 goto err1;
1123
1124 DSSDBG("PLL init done\n");
1125
1126 return 0;
1127err1:
1128 regulator_disable(dsi.vdds_dsi_reg);
1129err0:
1130 enable_clocks(0);
1131 dsi_enable_pll_clock(0);
1132 return r;
1133}
1134
1135void dsi_pll_uninit(void)
1136{
1137 enable_clocks(0);
1138 dsi_enable_pll_clock(0);
1139
1140 dsi.pll_locked = 0;
1141 dsi_pll_power(DSI_PLL_POWER_OFF);
1142 regulator_disable(dsi.vdds_dsi_reg);
1143 DSSDBG("PLL uninit done\n");
1144}
1145
1146void dsi_dump_clocks(struct seq_file *s)
1147{
1148 int clksel;
1149 struct dsi_clock_info *cinfo = &dsi.current_cinfo;
1150
1151 enable_clocks(1);
1152
1153 clksel = REG_GET(DSI_PLL_CONFIGURATION2, 11, 11);
1154
1155 seq_printf(s, "- DSI PLL -\n");
1156
1157 seq_printf(s, "dsi pll source = %s\n",
1158 clksel == 0 ?
1159 "dss2_alwon_fclk" : "pclkfree");
1160
1161 seq_printf(s, "Fint\t\t%-16luregn %u\n", cinfo->fint, cinfo->regn);
1162
1163 seq_printf(s, "CLKIN4DDR\t%-16luregm %u\n",
1164 cinfo->clkin4ddr, cinfo->regm);
1165
1166 seq_printf(s, "dsi1_pll_fck\t%-16luregm3 %u\t(%s)\n",
1167 cinfo->dsi1_pll_fclk,
1168 cinfo->regm3,
Tomi Valkeinen63cf28a2010-02-23 17:40:00 +02001169 dss_get_dispc_clk_source() == DSS_SRC_DSS1_ALWON_FCLK ?
1170 "off" : "on");
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001171
1172 seq_printf(s, "dsi2_pll_fck\t%-16luregm4 %u\t(%s)\n",
1173 cinfo->dsi2_pll_fclk,
1174 cinfo->regm4,
Tomi Valkeinen63cf28a2010-02-23 17:40:00 +02001175 dss_get_dsi_clk_source() == DSS_SRC_DSS1_ALWON_FCLK ?
1176 "off" : "on");
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001177
1178 seq_printf(s, "- DSI -\n");
1179
1180 seq_printf(s, "dsi fclk source = %s\n",
Tomi Valkeinen63cf28a2010-02-23 17:40:00 +02001181 dss_get_dsi_clk_source() == DSS_SRC_DSS1_ALWON_FCLK ?
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001182 "dss1_alwon_fclk" : "dsi2_pll_fclk");
1183
1184 seq_printf(s, "DSI_FCLK\t%lu\n", dsi_fclk_rate());
1185
1186 seq_printf(s, "DDR_CLK\t\t%lu\n",
1187 cinfo->clkin4ddr / 4);
1188
1189 seq_printf(s, "TxByteClkHS\t%lu\n", dsi_get_txbyteclkhs());
1190
1191 seq_printf(s, "LP_CLK\t\t%lu\n", cinfo->lp_clk);
1192
1193 seq_printf(s, "VP_CLK\t\t%lu\n"
1194 "VP_PCLK\t\t%lu\n",
1195 dispc_lclk_rate(),
1196 dispc_pclk_rate());
1197
1198 enable_clocks(0);
1199}
1200
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001201#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
1202void dsi_dump_irqs(struct seq_file *s)
1203{
1204 unsigned long flags;
1205 struct dsi_irq_stats stats;
1206
1207 spin_lock_irqsave(&dsi.irq_stats_lock, flags);
1208
1209 stats = dsi.irq_stats;
1210 memset(&dsi.irq_stats, 0, sizeof(dsi.irq_stats));
1211 dsi.irq_stats.last_reset = jiffies;
1212
1213 spin_unlock_irqrestore(&dsi.irq_stats_lock, flags);
1214
1215 seq_printf(s, "period %u ms\n",
1216 jiffies_to_msecs(jiffies - stats.last_reset));
1217
1218 seq_printf(s, "irqs %d\n", stats.irq_count);
1219#define PIS(x) \
1220 seq_printf(s, "%-20s %10d\n", #x, stats.dsi_irqs[ffs(DSI_IRQ_##x)-1]);
1221
1222 seq_printf(s, "-- DSI interrupts --\n");
1223 PIS(VC0);
1224 PIS(VC1);
1225 PIS(VC2);
1226 PIS(VC3);
1227 PIS(WAKEUP);
1228 PIS(RESYNC);
1229 PIS(PLL_LOCK);
1230 PIS(PLL_UNLOCK);
1231 PIS(PLL_RECALL);
1232 PIS(COMPLEXIO_ERR);
1233 PIS(HS_TX_TIMEOUT);
1234 PIS(LP_RX_TIMEOUT);
1235 PIS(TE_TRIGGER);
1236 PIS(ACK_TRIGGER);
1237 PIS(SYNC_LOST);
1238 PIS(LDO_POWER_GOOD);
1239 PIS(TA_TIMEOUT);
1240#undef PIS
1241
1242#define PIS(x) \
1243 seq_printf(s, "%-20s %10d %10d %10d %10d\n", #x, \
1244 stats.vc_irqs[0][ffs(DSI_VC_IRQ_##x)-1], \
1245 stats.vc_irqs[1][ffs(DSI_VC_IRQ_##x)-1], \
1246 stats.vc_irqs[2][ffs(DSI_VC_IRQ_##x)-1], \
1247 stats.vc_irqs[3][ffs(DSI_VC_IRQ_##x)-1]);
1248
1249 seq_printf(s, "-- VC interrupts --\n");
1250 PIS(CS);
1251 PIS(ECC_CORR);
1252 PIS(PACKET_SENT);
1253 PIS(FIFO_TX_OVF);
1254 PIS(FIFO_RX_OVF);
1255 PIS(BTA);
1256 PIS(ECC_NO_CORR);
1257 PIS(FIFO_TX_UDF);
1258 PIS(PP_BUSY_CHANGE);
1259#undef PIS
1260
1261#define PIS(x) \
1262 seq_printf(s, "%-20s %10d\n", #x, \
1263 stats.cio_irqs[ffs(DSI_CIO_IRQ_##x)-1]);
1264
1265 seq_printf(s, "-- CIO interrupts --\n");
1266 PIS(ERRSYNCESC1);
1267 PIS(ERRSYNCESC2);
1268 PIS(ERRSYNCESC3);
1269 PIS(ERRESC1);
1270 PIS(ERRESC2);
1271 PIS(ERRESC3);
1272 PIS(ERRCONTROL1);
1273 PIS(ERRCONTROL2);
1274 PIS(ERRCONTROL3);
1275 PIS(STATEULPS1);
1276 PIS(STATEULPS2);
1277 PIS(STATEULPS3);
1278 PIS(ERRCONTENTIONLP0_1);
1279 PIS(ERRCONTENTIONLP1_1);
1280 PIS(ERRCONTENTIONLP0_2);
1281 PIS(ERRCONTENTIONLP1_2);
1282 PIS(ERRCONTENTIONLP0_3);
1283 PIS(ERRCONTENTIONLP1_3);
1284 PIS(ULPSACTIVENOT_ALL0);
1285 PIS(ULPSACTIVENOT_ALL1);
1286#undef PIS
1287}
1288#endif
1289
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001290void dsi_dump_regs(struct seq_file *s)
1291{
1292#define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dsi_read_reg(r))
1293
1294 dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK1);
1295
1296 DUMPREG(DSI_REVISION);
1297 DUMPREG(DSI_SYSCONFIG);
1298 DUMPREG(DSI_SYSSTATUS);
1299 DUMPREG(DSI_IRQSTATUS);
1300 DUMPREG(DSI_IRQENABLE);
1301 DUMPREG(DSI_CTRL);
1302 DUMPREG(DSI_COMPLEXIO_CFG1);
1303 DUMPREG(DSI_COMPLEXIO_IRQ_STATUS);
1304 DUMPREG(DSI_COMPLEXIO_IRQ_ENABLE);
1305 DUMPREG(DSI_CLK_CTRL);
1306 DUMPREG(DSI_TIMING1);
1307 DUMPREG(DSI_TIMING2);
1308 DUMPREG(DSI_VM_TIMING1);
1309 DUMPREG(DSI_VM_TIMING2);
1310 DUMPREG(DSI_VM_TIMING3);
1311 DUMPREG(DSI_CLK_TIMING);
1312 DUMPREG(DSI_TX_FIFO_VC_SIZE);
1313 DUMPREG(DSI_RX_FIFO_VC_SIZE);
1314 DUMPREG(DSI_COMPLEXIO_CFG2);
1315 DUMPREG(DSI_RX_FIFO_VC_FULLNESS);
1316 DUMPREG(DSI_VM_TIMING4);
1317 DUMPREG(DSI_TX_FIFO_VC_EMPTINESS);
1318 DUMPREG(DSI_VM_TIMING5);
1319 DUMPREG(DSI_VM_TIMING6);
1320 DUMPREG(DSI_VM_TIMING7);
1321 DUMPREG(DSI_STOPCLK_TIMING);
1322
1323 DUMPREG(DSI_VC_CTRL(0));
1324 DUMPREG(DSI_VC_TE(0));
1325 DUMPREG(DSI_VC_LONG_PACKET_HEADER(0));
1326 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(0));
1327 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(0));
1328 DUMPREG(DSI_VC_IRQSTATUS(0));
1329 DUMPREG(DSI_VC_IRQENABLE(0));
1330
1331 DUMPREG(DSI_VC_CTRL(1));
1332 DUMPREG(DSI_VC_TE(1));
1333 DUMPREG(DSI_VC_LONG_PACKET_HEADER(1));
1334 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(1));
1335 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(1));
1336 DUMPREG(DSI_VC_IRQSTATUS(1));
1337 DUMPREG(DSI_VC_IRQENABLE(1));
1338
1339 DUMPREG(DSI_VC_CTRL(2));
1340 DUMPREG(DSI_VC_TE(2));
1341 DUMPREG(DSI_VC_LONG_PACKET_HEADER(2));
1342 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(2));
1343 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(2));
1344 DUMPREG(DSI_VC_IRQSTATUS(2));
1345 DUMPREG(DSI_VC_IRQENABLE(2));
1346
1347 DUMPREG(DSI_VC_CTRL(3));
1348 DUMPREG(DSI_VC_TE(3));
1349 DUMPREG(DSI_VC_LONG_PACKET_HEADER(3));
1350 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(3));
1351 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(3));
1352 DUMPREG(DSI_VC_IRQSTATUS(3));
1353 DUMPREG(DSI_VC_IRQENABLE(3));
1354
1355 DUMPREG(DSI_DSIPHY_CFG0);
1356 DUMPREG(DSI_DSIPHY_CFG1);
1357 DUMPREG(DSI_DSIPHY_CFG2);
1358 DUMPREG(DSI_DSIPHY_CFG5);
1359
1360 DUMPREG(DSI_PLL_CONTROL);
1361 DUMPREG(DSI_PLL_STATUS);
1362 DUMPREG(DSI_PLL_GO);
1363 DUMPREG(DSI_PLL_CONFIGURATION1);
1364 DUMPREG(DSI_PLL_CONFIGURATION2);
1365
1366 dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK1);
1367#undef DUMPREG
1368}
1369
1370enum dsi_complexio_power_state {
1371 DSI_COMPLEXIO_POWER_OFF = 0x0,
1372 DSI_COMPLEXIO_POWER_ON = 0x1,
1373 DSI_COMPLEXIO_POWER_ULPS = 0x2,
1374};
1375
1376static int dsi_complexio_power(enum dsi_complexio_power_state state)
1377{
1378 int t = 0;
1379
1380 /* PWR_CMD */
1381 REG_FLD_MOD(DSI_COMPLEXIO_CFG1, state, 28, 27);
1382
1383 /* PWR_STATUS */
1384 while (FLD_GET(dsi_read_reg(DSI_COMPLEXIO_CFG1), 26, 25) != state) {
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02001385 if (++t > 1000) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001386 DSSERR("failed to set complexio power state to "
1387 "%d\n", state);
1388 return -ENODEV;
1389 }
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02001390 udelay(1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001391 }
1392
1393 return 0;
1394}
1395
1396static void dsi_complexio_config(struct omap_dss_device *dssdev)
1397{
1398 u32 r;
1399
1400 int clk_lane = dssdev->phy.dsi.clk_lane;
1401 int data1_lane = dssdev->phy.dsi.data1_lane;
1402 int data2_lane = dssdev->phy.dsi.data2_lane;
1403 int clk_pol = dssdev->phy.dsi.clk_pol;
1404 int data1_pol = dssdev->phy.dsi.data1_pol;
1405 int data2_pol = dssdev->phy.dsi.data2_pol;
1406
1407 r = dsi_read_reg(DSI_COMPLEXIO_CFG1);
1408 r = FLD_MOD(r, clk_lane, 2, 0);
1409 r = FLD_MOD(r, clk_pol, 3, 3);
1410 r = FLD_MOD(r, data1_lane, 6, 4);
1411 r = FLD_MOD(r, data1_pol, 7, 7);
1412 r = FLD_MOD(r, data2_lane, 10, 8);
1413 r = FLD_MOD(r, data2_pol, 11, 11);
1414 dsi_write_reg(DSI_COMPLEXIO_CFG1, r);
1415
1416 /* The configuration of the DSI complex I/O (number of data lanes,
1417 position, differential order) should not be changed while
1418 DSS.DSI_CLK_CRTRL[20] LP_CLK_ENABLE bit is set to 1. In order for
1419 the hardware to take into account a new configuration of the complex
1420 I/O (done in DSS.DSI_COMPLEXIO_CFG1 register), it is recommended to
1421 follow this sequence: First set the DSS.DSI_CTRL[0] IF_EN bit to 1,
1422 then reset the DSS.DSI_CTRL[0] IF_EN to 0, then set
1423 DSS.DSI_CLK_CTRL[20] LP_CLK_ENABLE to 1 and finally set again the
1424 DSS.DSI_CTRL[0] IF_EN bit to 1. If the sequence is not followed, the
1425 DSI complex I/O configuration is unknown. */
1426
1427 /*
1428 REG_FLD_MOD(DSI_CTRL, 1, 0, 0);
1429 REG_FLD_MOD(DSI_CTRL, 0, 0, 0);
1430 REG_FLD_MOD(DSI_CLK_CTRL, 1, 20, 20);
1431 REG_FLD_MOD(DSI_CTRL, 1, 0, 0);
1432 */
1433}
1434
1435static inline unsigned ns2ddr(unsigned ns)
1436{
1437 /* convert time in ns to ddr ticks, rounding up */
1438 unsigned long ddr_clk = dsi.current_cinfo.clkin4ddr / 4;
1439 return (ns * (ddr_clk / 1000 / 1000) + 999) / 1000;
1440}
1441
1442static inline unsigned ddr2ns(unsigned ddr)
1443{
1444 unsigned long ddr_clk = dsi.current_cinfo.clkin4ddr / 4;
1445 return ddr * 1000 * 1000 / (ddr_clk / 1000);
1446}
1447
1448static void dsi_complexio_timings(void)
1449{
1450 u32 r;
1451 u32 ths_prepare, ths_prepare_ths_zero, ths_trail, ths_exit;
1452 u32 tlpx_half, tclk_trail, tclk_zero;
1453 u32 tclk_prepare;
1454
1455 /* calculate timings */
1456
1457 /* 1 * DDR_CLK = 2 * UI */
1458
1459 /* min 40ns + 4*UI max 85ns + 6*UI */
1460 ths_prepare = ns2ddr(70) + 2;
1461
1462 /* min 145ns + 10*UI */
1463 ths_prepare_ths_zero = ns2ddr(175) + 2;
1464
1465 /* min max(8*UI, 60ns+4*UI) */
1466 ths_trail = ns2ddr(60) + 5;
1467
1468 /* min 100ns */
1469 ths_exit = ns2ddr(145);
1470
1471 /* tlpx min 50n */
1472 tlpx_half = ns2ddr(25);
1473
1474 /* min 60ns */
1475 tclk_trail = ns2ddr(60) + 2;
1476
1477 /* min 38ns, max 95ns */
1478 tclk_prepare = ns2ddr(65);
1479
1480 /* min tclk-prepare + tclk-zero = 300ns */
1481 tclk_zero = ns2ddr(260);
1482
1483 DSSDBG("ths_prepare %u (%uns), ths_prepare_ths_zero %u (%uns)\n",
1484 ths_prepare, ddr2ns(ths_prepare),
1485 ths_prepare_ths_zero, ddr2ns(ths_prepare_ths_zero));
1486 DSSDBG("ths_trail %u (%uns), ths_exit %u (%uns)\n",
1487 ths_trail, ddr2ns(ths_trail),
1488 ths_exit, ddr2ns(ths_exit));
1489
1490 DSSDBG("tlpx_half %u (%uns), tclk_trail %u (%uns), "
1491 "tclk_zero %u (%uns)\n",
1492 tlpx_half, ddr2ns(tlpx_half),
1493 tclk_trail, ddr2ns(tclk_trail),
1494 tclk_zero, ddr2ns(tclk_zero));
1495 DSSDBG("tclk_prepare %u (%uns)\n",
1496 tclk_prepare, ddr2ns(tclk_prepare));
1497
1498 /* program timings */
1499
1500 r = dsi_read_reg(DSI_DSIPHY_CFG0);
1501 r = FLD_MOD(r, ths_prepare, 31, 24);
1502 r = FLD_MOD(r, ths_prepare_ths_zero, 23, 16);
1503 r = FLD_MOD(r, ths_trail, 15, 8);
1504 r = FLD_MOD(r, ths_exit, 7, 0);
1505 dsi_write_reg(DSI_DSIPHY_CFG0, r);
1506
1507 r = dsi_read_reg(DSI_DSIPHY_CFG1);
1508 r = FLD_MOD(r, tlpx_half, 22, 16);
1509 r = FLD_MOD(r, tclk_trail, 15, 8);
1510 r = FLD_MOD(r, tclk_zero, 7, 0);
1511 dsi_write_reg(DSI_DSIPHY_CFG1, r);
1512
1513 r = dsi_read_reg(DSI_DSIPHY_CFG2);
1514 r = FLD_MOD(r, tclk_prepare, 7, 0);
1515 dsi_write_reg(DSI_DSIPHY_CFG2, r);
1516}
1517
1518
1519static int dsi_complexio_init(struct omap_dss_device *dssdev)
1520{
1521 int r = 0;
1522
1523 DSSDBG("dsi_complexio_init\n");
1524
1525 /* CIO_CLK_ICG, enable L3 clk to CIO */
1526 REG_FLD_MOD(DSI_CLK_CTRL, 1, 14, 14);
1527
1528 /* A dummy read using the SCP interface to any DSIPHY register is
1529 * required after DSIPHY reset to complete the reset of the DSI complex
1530 * I/O. */
1531 dsi_read_reg(DSI_DSIPHY_CFG5);
1532
1533 if (wait_for_bit_change(DSI_DSIPHY_CFG5, 30, 1) != 1) {
1534 DSSERR("ComplexIO PHY not coming out of reset.\n");
1535 r = -ENODEV;
1536 goto err;
1537 }
1538
1539 dsi_complexio_config(dssdev);
1540
1541 r = dsi_complexio_power(DSI_COMPLEXIO_POWER_ON);
1542
1543 if (r)
1544 goto err;
1545
1546 if (wait_for_bit_change(DSI_COMPLEXIO_CFG1, 29, 1) != 1) {
1547 DSSERR("ComplexIO not coming out of reset.\n");
1548 r = -ENODEV;
1549 goto err;
1550 }
1551
1552 if (wait_for_bit_change(DSI_COMPLEXIO_CFG1, 21, 1) != 1) {
1553 DSSERR("ComplexIO LDO power down.\n");
1554 r = -ENODEV;
1555 goto err;
1556 }
1557
1558 dsi_complexio_timings();
1559
1560 /*
1561 The configuration of the DSI complex I/O (number of data lanes,
1562 position, differential order) should not be changed while
1563 DSS.DSI_CLK_CRTRL[20] LP_CLK_ENABLE bit is set to 1. For the
1564 hardware to recognize a new configuration of the complex I/O (done
1565 in DSS.DSI_COMPLEXIO_CFG1 register), it is recommended to follow
1566 this sequence: First set the DSS.DSI_CTRL[0] IF_EN bit to 1, next
1567 reset the DSS.DSI_CTRL[0] IF_EN to 0, then set DSS.DSI_CLK_CTRL[20]
1568 LP_CLK_ENABLE to 1, and finally, set again the DSS.DSI_CTRL[0] IF_EN
1569 bit to 1. If the sequence is not followed, the DSi complex I/O
1570 configuration is undetermined.
1571 */
1572 dsi_if_enable(1);
1573 dsi_if_enable(0);
1574 REG_FLD_MOD(DSI_CLK_CTRL, 1, 20, 20); /* LP_CLK_ENABLE */
1575 dsi_if_enable(1);
1576 dsi_if_enable(0);
1577
1578 DSSDBG("CIO init done\n");
1579err:
1580 return r;
1581}
1582
1583static void dsi_complexio_uninit(void)
1584{
1585 dsi_complexio_power(DSI_COMPLEXIO_POWER_OFF);
1586}
1587
1588static int _dsi_wait_reset(void)
1589{
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02001590 int t = 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001591
1592 while (REG_GET(DSI_SYSSTATUS, 0, 0) == 0) {
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02001593 if (++t > 5) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001594 DSSERR("soft reset failed\n");
1595 return -ENODEV;
1596 }
1597 udelay(1);
1598 }
1599
1600 return 0;
1601}
1602
1603static int _dsi_reset(void)
1604{
1605 /* Soft reset */
1606 REG_FLD_MOD(DSI_SYSCONFIG, 1, 1, 1);
1607 return _dsi_wait_reset();
1608}
1609
1610static void dsi_reset_tx_fifo(int channel)
1611{
1612 u32 mask;
1613 u32 l;
1614
1615 /* set fifosize of the channel to 0, then return the old size */
1616 l = dsi_read_reg(DSI_TX_FIFO_VC_SIZE);
1617
1618 mask = FLD_MASK((8 * channel) + 7, (8 * channel) + 4);
1619 dsi_write_reg(DSI_TX_FIFO_VC_SIZE, l & ~mask);
1620
1621 dsi_write_reg(DSI_TX_FIFO_VC_SIZE, l);
1622}
1623
1624static void dsi_config_tx_fifo(enum fifo_size size1, enum fifo_size size2,
1625 enum fifo_size size3, enum fifo_size size4)
1626{
1627 u32 r = 0;
1628 int add = 0;
1629 int i;
1630
1631 dsi.vc[0].fifo_size = size1;
1632 dsi.vc[1].fifo_size = size2;
1633 dsi.vc[2].fifo_size = size3;
1634 dsi.vc[3].fifo_size = size4;
1635
1636 for (i = 0; i < 4; i++) {
1637 u8 v;
1638 int size = dsi.vc[i].fifo_size;
1639
1640 if (add + size > 4) {
1641 DSSERR("Illegal FIFO configuration\n");
1642 BUG();
1643 }
1644
1645 v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
1646 r |= v << (8 * i);
1647 /*DSSDBG("TX FIFO vc %d: size %d, add %d\n", i, size, add); */
1648 add += size;
1649 }
1650
1651 dsi_write_reg(DSI_TX_FIFO_VC_SIZE, r);
1652}
1653
1654static void dsi_config_rx_fifo(enum fifo_size size1, enum fifo_size size2,
1655 enum fifo_size size3, enum fifo_size size4)
1656{
1657 u32 r = 0;
1658 int add = 0;
1659 int i;
1660
1661 dsi.vc[0].fifo_size = size1;
1662 dsi.vc[1].fifo_size = size2;
1663 dsi.vc[2].fifo_size = size3;
1664 dsi.vc[3].fifo_size = size4;
1665
1666 for (i = 0; i < 4; i++) {
1667 u8 v;
1668 int size = dsi.vc[i].fifo_size;
1669
1670 if (add + size > 4) {
1671 DSSERR("Illegal FIFO configuration\n");
1672 BUG();
1673 }
1674
1675 v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
1676 r |= v << (8 * i);
1677 /*DSSDBG("RX FIFO vc %d: size %d, add %d\n", i, size, add); */
1678 add += size;
1679 }
1680
1681 dsi_write_reg(DSI_RX_FIFO_VC_SIZE, r);
1682}
1683
1684static int dsi_force_tx_stop_mode_io(void)
1685{
1686 u32 r;
1687
1688 r = dsi_read_reg(DSI_TIMING1);
1689 r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
1690 dsi_write_reg(DSI_TIMING1, r);
1691
1692 if (wait_for_bit_change(DSI_TIMING1, 15, 0) != 0) {
1693 DSSERR("TX_STOP bit not going down\n");
1694 return -EIO;
1695 }
1696
1697 return 0;
1698}
1699
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001700static int dsi_vc_enable(int channel, bool enable)
1701{
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +02001702 DSSDBG("dsi_vc_enable channel %d, enable %d\n",
1703 channel, enable);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001704
1705 enable = enable ? 1 : 0;
1706
1707 REG_FLD_MOD(DSI_VC_CTRL(channel), enable, 0, 0);
1708
1709 if (wait_for_bit_change(DSI_VC_CTRL(channel), 0, enable) != enable) {
1710 DSSERR("Failed to set dsi_vc_enable to %d\n", enable);
1711 return -EIO;
1712 }
1713
1714 return 0;
1715}
1716
1717static void dsi_vc_initial_config(int channel)
1718{
1719 u32 r;
1720
1721 DSSDBGF("%d", channel);
1722
1723 r = dsi_read_reg(DSI_VC_CTRL(channel));
1724
1725 if (FLD_GET(r, 15, 15)) /* VC_BUSY */
1726 DSSERR("VC(%d) busy when trying to configure it!\n",
1727 channel);
1728
1729 r = FLD_MOD(r, 0, 1, 1); /* SOURCE, 0 = L4 */
1730 r = FLD_MOD(r, 0, 2, 2); /* BTA_SHORT_EN */
1731 r = FLD_MOD(r, 0, 3, 3); /* BTA_LONG_EN */
1732 r = FLD_MOD(r, 0, 4, 4); /* MODE, 0 = command */
1733 r = FLD_MOD(r, 1, 7, 7); /* CS_TX_EN */
1734 r = FLD_MOD(r, 1, 8, 8); /* ECC_TX_EN */
1735 r = FLD_MOD(r, 0, 9, 9); /* MODE_SPEED, high speed on/off */
1736
1737 r = FLD_MOD(r, 4, 29, 27); /* DMA_RX_REQ_NB = no dma */
1738 r = FLD_MOD(r, 4, 23, 21); /* DMA_TX_REQ_NB = no dma */
1739
1740 dsi_write_reg(DSI_VC_CTRL(channel), r);
1741
1742 dsi.vc[channel].mode = DSI_VC_MODE_L4;
1743}
1744
1745static void dsi_vc_config_l4(int channel)
1746{
1747 if (dsi.vc[channel].mode == DSI_VC_MODE_L4)
1748 return;
1749
1750 DSSDBGF("%d", channel);
1751
1752 dsi_vc_enable(channel, 0);
1753
1754 if (REG_GET(DSI_VC_CTRL(channel), 15, 15)) /* VC_BUSY */
1755 DSSERR("vc(%d) busy when trying to config for L4\n", channel);
1756
1757 REG_FLD_MOD(DSI_VC_CTRL(channel), 0, 1, 1); /* SOURCE, 0 = L4 */
1758
1759 dsi_vc_enable(channel, 1);
1760
1761 dsi.vc[channel].mode = DSI_VC_MODE_L4;
1762}
1763
1764static void dsi_vc_config_vp(int channel)
1765{
1766 if (dsi.vc[channel].mode == DSI_VC_MODE_VP)
1767 return;
1768
1769 DSSDBGF("%d", channel);
1770
1771 dsi_vc_enable(channel, 0);
1772
1773 if (REG_GET(DSI_VC_CTRL(channel), 15, 15)) /* VC_BUSY */
1774 DSSERR("vc(%d) busy when trying to config for VP\n", channel);
1775
1776 REG_FLD_MOD(DSI_VC_CTRL(channel), 1, 1, 1); /* SOURCE, 1 = video port */
1777
1778 dsi_vc_enable(channel, 1);
1779
1780 dsi.vc[channel].mode = DSI_VC_MODE_VP;
1781}
1782
1783
Tomi Valkeinen61140c92010-01-12 16:00:30 +02001784void omapdss_dsi_vc_enable_hs(int channel, bool enable)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001785{
1786 DSSDBG("dsi_vc_enable_hs(%d, %d)\n", channel, enable);
1787
Tomi Valkeinen61140c92010-01-12 16:00:30 +02001788 WARN_ON(!dsi_bus_is_locked());
1789
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001790 dsi_vc_enable(channel, 0);
1791 dsi_if_enable(0);
1792
1793 REG_FLD_MOD(DSI_VC_CTRL(channel), enable, 9, 9);
1794
1795 dsi_vc_enable(channel, 1);
1796 dsi_if_enable(1);
1797
1798 dsi_force_tx_stop_mode_io();
1799}
Tomi Valkeinen61140c92010-01-12 16:00:30 +02001800EXPORT_SYMBOL(omapdss_dsi_vc_enable_hs);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001801
1802static void dsi_vc_flush_long_data(int channel)
1803{
1804 while (REG_GET(DSI_VC_CTRL(channel), 20, 20)) {
1805 u32 val;
1806 val = dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel));
1807 DSSDBG("\t\tb1 %#02x b2 %#02x b3 %#02x b4 %#02x\n",
1808 (val >> 0) & 0xff,
1809 (val >> 8) & 0xff,
1810 (val >> 16) & 0xff,
1811 (val >> 24) & 0xff);
1812 }
1813}
1814
1815static void dsi_show_rx_ack_with_err(u16 err)
1816{
1817 DSSERR("\tACK with ERROR (%#x):\n", err);
1818 if (err & (1 << 0))
1819 DSSERR("\t\tSoT Error\n");
1820 if (err & (1 << 1))
1821 DSSERR("\t\tSoT Sync Error\n");
1822 if (err & (1 << 2))
1823 DSSERR("\t\tEoT Sync Error\n");
1824 if (err & (1 << 3))
1825 DSSERR("\t\tEscape Mode Entry Command Error\n");
1826 if (err & (1 << 4))
1827 DSSERR("\t\tLP Transmit Sync Error\n");
1828 if (err & (1 << 5))
1829 DSSERR("\t\tHS Receive Timeout Error\n");
1830 if (err & (1 << 6))
1831 DSSERR("\t\tFalse Control Error\n");
1832 if (err & (1 << 7))
1833 DSSERR("\t\t(reserved7)\n");
1834 if (err & (1 << 8))
1835 DSSERR("\t\tECC Error, single-bit (corrected)\n");
1836 if (err & (1 << 9))
1837 DSSERR("\t\tECC Error, multi-bit (not corrected)\n");
1838 if (err & (1 << 10))
1839 DSSERR("\t\tChecksum Error\n");
1840 if (err & (1 << 11))
1841 DSSERR("\t\tData type not recognized\n");
1842 if (err & (1 << 12))
1843 DSSERR("\t\tInvalid VC ID\n");
1844 if (err & (1 << 13))
1845 DSSERR("\t\tInvalid Transmission Length\n");
1846 if (err & (1 << 14))
1847 DSSERR("\t\t(reserved14)\n");
1848 if (err & (1 << 15))
1849 DSSERR("\t\tDSI Protocol Violation\n");
1850}
1851
1852static u16 dsi_vc_flush_receive_data(int channel)
1853{
1854 /* RX_FIFO_NOT_EMPTY */
1855 while (REG_GET(DSI_VC_CTRL(channel), 20, 20)) {
1856 u32 val;
1857 u8 dt;
1858 val = dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel));
Tomi Valkeinen86a78672010-03-16 16:19:06 +02001859 DSSERR("\trawval %#08x\n", val);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001860 dt = FLD_GET(val, 5, 0);
1861 if (dt == DSI_DT_RX_ACK_WITH_ERR) {
1862 u16 err = FLD_GET(val, 23, 8);
1863 dsi_show_rx_ack_with_err(err);
1864 } else if (dt == DSI_DT_RX_SHORT_READ_1) {
Tomi Valkeinen86a78672010-03-16 16:19:06 +02001865 DSSERR("\tDCS short response, 1 byte: %#x\n",
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001866 FLD_GET(val, 23, 8));
1867 } else if (dt == DSI_DT_RX_SHORT_READ_2) {
Tomi Valkeinen86a78672010-03-16 16:19:06 +02001868 DSSERR("\tDCS short response, 2 byte: %#x\n",
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001869 FLD_GET(val, 23, 8));
1870 } else if (dt == DSI_DT_RX_DCS_LONG_READ) {
Tomi Valkeinen86a78672010-03-16 16:19:06 +02001871 DSSERR("\tDCS long response, len %d\n",
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001872 FLD_GET(val, 23, 8));
1873 dsi_vc_flush_long_data(channel);
1874 } else {
1875 DSSERR("\tunknown datatype 0x%02x\n", dt);
1876 }
1877 }
1878 return 0;
1879}
1880
1881static int dsi_vc_send_bta(int channel)
1882{
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +02001883 if (dsi.debug_write || dsi.debug_read)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001884 DSSDBG("dsi_vc_send_bta %d\n", channel);
1885
Tomi Valkeinen4f765022010-01-18 16:27:52 +02001886 WARN_ON(!dsi_bus_is_locked());
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001887
1888 if (REG_GET(DSI_VC_CTRL(channel), 20, 20)) { /* RX_FIFO_NOT_EMPTY */
1889 DSSERR("rx fifo not empty when sending BTA, dumping data:\n");
1890 dsi_vc_flush_receive_data(channel);
1891 }
1892
1893 REG_FLD_MOD(DSI_VC_CTRL(channel), 1, 6, 6); /* BTA_EN */
1894
1895 return 0;
1896}
1897
1898int dsi_vc_send_bta_sync(int channel)
1899{
1900 int r = 0;
1901 u32 err;
1902
1903 INIT_COMPLETION(dsi.bta_completion);
1904
1905 dsi_vc_enable_bta_irq(channel);
1906
1907 r = dsi_vc_send_bta(channel);
1908 if (r)
1909 goto err;
1910
1911 if (wait_for_completion_timeout(&dsi.bta_completion,
1912 msecs_to_jiffies(500)) == 0) {
1913 DSSERR("Failed to receive BTA\n");
1914 r = -EIO;
1915 goto err;
1916 }
1917
1918 err = dsi_get_errors();
1919 if (err) {
1920 DSSERR("Error while sending BTA: %x\n", err);
1921 r = -EIO;
1922 goto err;
1923 }
1924err:
1925 dsi_vc_disable_bta_irq(channel);
1926
1927 return r;
1928}
1929EXPORT_SYMBOL(dsi_vc_send_bta_sync);
1930
1931static inline void dsi_vc_write_long_header(int channel, u8 data_type,
1932 u16 len, u8 ecc)
1933{
1934 u32 val;
1935 u8 data_id;
1936
Tomi Valkeinen4f765022010-01-18 16:27:52 +02001937 WARN_ON(!dsi_bus_is_locked());
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001938
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02001939 data_id = data_type | channel << 6;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001940
1941 val = FLD_VAL(data_id, 7, 0) | FLD_VAL(len, 23, 8) |
1942 FLD_VAL(ecc, 31, 24);
1943
1944 dsi_write_reg(DSI_VC_LONG_PACKET_HEADER(channel), val);
1945}
1946
1947static inline void dsi_vc_write_long_payload(int channel,
1948 u8 b1, u8 b2, u8 b3, u8 b4)
1949{
1950 u32 val;
1951
1952 val = b4 << 24 | b3 << 16 | b2 << 8 | b1 << 0;
1953
1954/* DSSDBG("\twriting %02x, %02x, %02x, %02x (%#010x)\n",
1955 b1, b2, b3, b4, val); */
1956
1957 dsi_write_reg(DSI_VC_LONG_PACKET_PAYLOAD(channel), val);
1958}
1959
1960static int dsi_vc_send_long(int channel, u8 data_type, u8 *data, u16 len,
1961 u8 ecc)
1962{
1963 /*u32 val; */
1964 int i;
1965 u8 *p;
1966 int r = 0;
1967 u8 b1, b2, b3, b4;
1968
1969 if (dsi.debug_write)
1970 DSSDBG("dsi_vc_send_long, %d bytes\n", len);
1971
1972 /* len + header */
1973 if (dsi.vc[channel].fifo_size * 32 * 4 < len + 4) {
1974 DSSERR("unable to send long packet: packet too long.\n");
1975 return -EINVAL;
1976 }
1977
1978 dsi_vc_config_l4(channel);
1979
1980 dsi_vc_write_long_header(channel, data_type, len, ecc);
1981
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001982 p = data;
1983 for (i = 0; i < len >> 2; i++) {
1984 if (dsi.debug_write)
1985 DSSDBG("\tsending full packet %d\n", i);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001986
1987 b1 = *p++;
1988 b2 = *p++;
1989 b3 = *p++;
1990 b4 = *p++;
1991
1992 dsi_vc_write_long_payload(channel, b1, b2, b3, b4);
1993 }
1994
1995 i = len % 4;
1996 if (i) {
1997 b1 = 0; b2 = 0; b3 = 0;
1998
1999 if (dsi.debug_write)
2000 DSSDBG("\tsending remainder bytes %d\n", i);
2001
2002 switch (i) {
2003 case 3:
2004 b1 = *p++;
2005 b2 = *p++;
2006 b3 = *p++;
2007 break;
2008 case 2:
2009 b1 = *p++;
2010 b2 = *p++;
2011 break;
2012 case 1:
2013 b1 = *p++;
2014 break;
2015 }
2016
2017 dsi_vc_write_long_payload(channel, b1, b2, b3, 0);
2018 }
2019
2020 return r;
2021}
2022
2023static int dsi_vc_send_short(int channel, u8 data_type, u16 data, u8 ecc)
2024{
2025 u32 r;
2026 u8 data_id;
2027
Tomi Valkeinen4f765022010-01-18 16:27:52 +02002028 WARN_ON(!dsi_bus_is_locked());
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002029
2030 if (dsi.debug_write)
2031 DSSDBG("dsi_vc_send_short(ch%d, dt %#x, b1 %#x, b2 %#x)\n",
2032 channel,
2033 data_type, data & 0xff, (data >> 8) & 0xff);
2034
2035 dsi_vc_config_l4(channel);
2036
2037 if (FLD_GET(dsi_read_reg(DSI_VC_CTRL(channel)), 16, 16)) {
2038 DSSERR("ERROR FIFO FULL, aborting transfer\n");
2039 return -EINVAL;
2040 }
2041
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02002042 data_id = data_type | channel << 6;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002043
2044 r = (data_id << 0) | (data << 8) | (ecc << 24);
2045
2046 dsi_write_reg(DSI_VC_SHORT_PACKET_HEADER(channel), r);
2047
2048 return 0;
2049}
2050
2051int dsi_vc_send_null(int channel)
2052{
2053 u8 nullpkg[] = {0, 0, 0, 0};
Tomi Valkeinen397bb3c2009-12-03 13:37:31 +02002054 return dsi_vc_send_long(channel, DSI_DT_NULL_PACKET, nullpkg, 4, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002055}
2056EXPORT_SYMBOL(dsi_vc_send_null);
2057
2058int dsi_vc_dcs_write_nosync(int channel, u8 *data, int len)
2059{
2060 int r;
2061
2062 BUG_ON(len == 0);
2063
2064 if (len == 1) {
2065 r = dsi_vc_send_short(channel, DSI_DT_DCS_SHORT_WRITE_0,
2066 data[0], 0);
2067 } else if (len == 2) {
2068 r = dsi_vc_send_short(channel, DSI_DT_DCS_SHORT_WRITE_1,
2069 data[0] | (data[1] << 8), 0);
2070 } else {
2071 /* 0x39 = DCS Long Write */
2072 r = dsi_vc_send_long(channel, DSI_DT_DCS_LONG_WRITE,
2073 data, len, 0);
2074 }
2075
2076 return r;
2077}
2078EXPORT_SYMBOL(dsi_vc_dcs_write_nosync);
2079
2080int dsi_vc_dcs_write(int channel, u8 *data, int len)
2081{
2082 int r;
2083
2084 r = dsi_vc_dcs_write_nosync(channel, data, len);
2085 if (r)
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002086 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002087
2088 r = dsi_vc_send_bta_sync(channel);
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002089 if (r)
2090 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002091
Tomi Valkeinenb63ac1e2010-04-09 13:20:57 +03002092 if (REG_GET(DSI_VC_CTRL(channel), 20, 20)) { /* RX_FIFO_NOT_EMPTY */
2093 DSSERR("rx fifo not empty after write, dumping data:\n");
2094 dsi_vc_flush_receive_data(channel);
2095 r = -EIO;
2096 goto err;
2097 }
2098
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002099 return 0;
2100err:
2101 DSSERR("dsi_vc_dcs_write(ch %d, cmd 0x%02x, len %d) failed\n",
2102 channel, data[0], len);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002103 return r;
2104}
2105EXPORT_SYMBOL(dsi_vc_dcs_write);
2106
Tomi Valkeinen828c48f2009-12-16 14:53:15 +02002107int dsi_vc_dcs_write_0(int channel, u8 dcs_cmd)
2108{
2109 return dsi_vc_dcs_write(channel, &dcs_cmd, 1);
2110}
2111EXPORT_SYMBOL(dsi_vc_dcs_write_0);
2112
2113int dsi_vc_dcs_write_1(int channel, u8 dcs_cmd, u8 param)
2114{
2115 u8 buf[2];
2116 buf[0] = dcs_cmd;
2117 buf[1] = param;
2118 return dsi_vc_dcs_write(channel, buf, 2);
2119}
2120EXPORT_SYMBOL(dsi_vc_dcs_write_1);
2121
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002122int dsi_vc_dcs_read(int channel, u8 dcs_cmd, u8 *buf, int buflen)
2123{
2124 u32 val;
2125 u8 dt;
2126 int r;
2127
2128 if (dsi.debug_read)
Tomi Valkeinenff90a342009-12-03 13:38:04 +02002129 DSSDBG("dsi_vc_dcs_read(ch%d, dcs_cmd %x)\n", channel, dcs_cmd);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002130
2131 r = dsi_vc_send_short(channel, DSI_DT_DCS_READ, dcs_cmd, 0);
2132 if (r)
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002133 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002134
2135 r = dsi_vc_send_bta_sync(channel);
2136 if (r)
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002137 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002138
2139 /* RX_FIFO_NOT_EMPTY */
2140 if (REG_GET(DSI_VC_CTRL(channel), 20, 20) == 0) {
2141 DSSERR("RX fifo empty when trying to read.\n");
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002142 r = -EIO;
2143 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002144 }
2145
2146 val = dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel));
2147 if (dsi.debug_read)
2148 DSSDBG("\theader: %08x\n", val);
2149 dt = FLD_GET(val, 5, 0);
2150 if (dt == DSI_DT_RX_ACK_WITH_ERR) {
2151 u16 err = FLD_GET(val, 23, 8);
2152 dsi_show_rx_ack_with_err(err);
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002153 r = -EIO;
2154 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002155
2156 } else if (dt == DSI_DT_RX_SHORT_READ_1) {
2157 u8 data = FLD_GET(val, 15, 8);
2158 if (dsi.debug_read)
2159 DSSDBG("\tDCS short response, 1 byte: %02x\n", data);
2160
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002161 if (buflen < 1) {
2162 r = -EIO;
2163 goto err;
2164 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002165
2166 buf[0] = data;
2167
2168 return 1;
2169 } else if (dt == DSI_DT_RX_SHORT_READ_2) {
2170 u16 data = FLD_GET(val, 23, 8);
2171 if (dsi.debug_read)
2172 DSSDBG("\tDCS short response, 2 byte: %04x\n", data);
2173
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002174 if (buflen < 2) {
2175 r = -EIO;
2176 goto err;
2177 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002178
2179 buf[0] = data & 0xff;
2180 buf[1] = (data >> 8) & 0xff;
2181
2182 return 2;
2183 } else if (dt == DSI_DT_RX_DCS_LONG_READ) {
2184 int w;
2185 int len = FLD_GET(val, 23, 8);
2186 if (dsi.debug_read)
2187 DSSDBG("\tDCS long response, len %d\n", len);
2188
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002189 if (len > buflen) {
2190 r = -EIO;
2191 goto err;
2192 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002193
2194 /* two byte checksum ends the packet, not included in len */
2195 for (w = 0; w < len + 2;) {
2196 int b;
2197 val = dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel));
2198 if (dsi.debug_read)
2199 DSSDBG("\t\t%02x %02x %02x %02x\n",
2200 (val >> 0) & 0xff,
2201 (val >> 8) & 0xff,
2202 (val >> 16) & 0xff,
2203 (val >> 24) & 0xff);
2204
2205 for (b = 0; b < 4; ++b) {
2206 if (w < len)
2207 buf[w] = (val >> (b * 8)) & 0xff;
2208 /* we discard the 2 byte checksum */
2209 ++w;
2210 }
2211 }
2212
2213 return len;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002214 } else {
2215 DSSERR("\tunknown datatype 0x%02x\n", dt);
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002216 r = -EIO;
2217 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002218 }
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002219
2220 BUG();
2221err:
2222 DSSERR("dsi_vc_dcs_read(ch %d, cmd 0x%02x) failed\n",
2223 channel, dcs_cmd);
2224 return r;
2225
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002226}
2227EXPORT_SYMBOL(dsi_vc_dcs_read);
2228
Tomi Valkeinen828c48f2009-12-16 14:53:15 +02002229int dsi_vc_dcs_read_1(int channel, u8 dcs_cmd, u8 *data)
2230{
2231 int r;
2232
2233 r = dsi_vc_dcs_read(channel, dcs_cmd, data, 1);
2234
2235 if (r < 0)
2236 return r;
2237
2238 if (r != 1)
2239 return -EIO;
2240
2241 return 0;
2242}
2243EXPORT_SYMBOL(dsi_vc_dcs_read_1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002244
Tomi Valkeinen0c244f72010-06-09 15:19:29 +03002245int dsi_vc_dcs_read_2(int channel, u8 dcs_cmd, u8 *data1, u8 *data2)
Tomi Valkeinen53055aa2010-02-25 11:38:13 +02002246{
Tomi Valkeinen0c244f72010-06-09 15:19:29 +03002247 u8 buf[2];
Tomi Valkeinen53055aa2010-02-25 11:38:13 +02002248 int r;
2249
Tomi Valkeinen0c244f72010-06-09 15:19:29 +03002250 r = dsi_vc_dcs_read(channel, dcs_cmd, buf, 2);
Tomi Valkeinen53055aa2010-02-25 11:38:13 +02002251
2252 if (r < 0)
2253 return r;
2254
2255 if (r != 2)
2256 return -EIO;
2257
Tomi Valkeinen0c244f72010-06-09 15:19:29 +03002258 *data1 = buf[0];
2259 *data2 = buf[1];
2260
Tomi Valkeinen53055aa2010-02-25 11:38:13 +02002261 return 0;
2262}
2263EXPORT_SYMBOL(dsi_vc_dcs_read_2);
2264
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002265int dsi_vc_set_max_rx_packet_size(int channel, u16 len)
2266{
2267 int r;
2268 r = dsi_vc_send_short(channel, DSI_DT_SET_MAX_RET_PKG_SIZE,
2269 len, 0);
2270
2271 if (r)
2272 return r;
2273
2274 r = dsi_vc_send_bta_sync(channel);
2275
2276 return r;
2277}
2278EXPORT_SYMBOL(dsi_vc_set_max_rx_packet_size);
2279
2280static void dsi_set_lp_rx_timeout(unsigned long ns)
2281{
2282 u32 r;
2283 unsigned x4, x16;
2284 unsigned long fck;
2285 unsigned long ticks;
2286
2287 /* ticks in DSI_FCK */
2288
2289 fck = dsi_fclk_rate();
2290 ticks = (fck / 1000 / 1000) * ns / 1000;
2291 x4 = 0;
2292 x16 = 0;
2293
2294 if (ticks > 0x1fff) {
2295 ticks = (fck / 1000 / 1000) * ns / 1000 / 4;
2296 x4 = 1;
2297 x16 = 0;
2298 }
2299
2300 if (ticks > 0x1fff) {
2301 ticks = (fck / 1000 / 1000) * ns / 1000 / 16;
2302 x4 = 0;
2303 x16 = 1;
2304 }
2305
2306 if (ticks > 0x1fff) {
2307 ticks = (fck / 1000 / 1000) * ns / 1000 / (4 * 16);
2308 x4 = 1;
2309 x16 = 1;
2310 }
2311
2312 if (ticks > 0x1fff) {
2313 DSSWARN("LP_TX_TO over limit, setting it to max\n");
2314 ticks = 0x1fff;
2315 x4 = 1;
2316 x16 = 1;
2317 }
2318
2319 r = dsi_read_reg(DSI_TIMING2);
2320 r = FLD_MOD(r, 1, 15, 15); /* LP_RX_TO */
2321 r = FLD_MOD(r, x16, 14, 14); /* LP_RX_TO_X16 */
2322 r = FLD_MOD(r, x4, 13, 13); /* LP_RX_TO_X4 */
2323 r = FLD_MOD(r, ticks, 12, 0); /* LP_RX_COUNTER */
2324 dsi_write_reg(DSI_TIMING2, r);
2325
2326 DSSDBG("LP_RX_TO %lu ns (%#lx ticks%s%s)\n",
2327 (ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1) * 1000) /
2328 (fck / 1000 / 1000),
2329 ticks, x4 ? " x4" : "", x16 ? " x16" : "");
2330}
2331
2332static void dsi_set_ta_timeout(unsigned long ns)
2333{
2334 u32 r;
2335 unsigned x8, x16;
2336 unsigned long fck;
2337 unsigned long ticks;
2338
2339 /* ticks in DSI_FCK */
2340 fck = dsi_fclk_rate();
2341 ticks = (fck / 1000 / 1000) * ns / 1000;
2342 x8 = 0;
2343 x16 = 0;
2344
2345 if (ticks > 0x1fff) {
2346 ticks = (fck / 1000 / 1000) * ns / 1000 / 8;
2347 x8 = 1;
2348 x16 = 0;
2349 }
2350
2351 if (ticks > 0x1fff) {
2352 ticks = (fck / 1000 / 1000) * ns / 1000 / 16;
2353 x8 = 0;
2354 x16 = 1;
2355 }
2356
2357 if (ticks > 0x1fff) {
2358 ticks = (fck / 1000 / 1000) * ns / 1000 / (8 * 16);
2359 x8 = 1;
2360 x16 = 1;
2361 }
2362
2363 if (ticks > 0x1fff) {
2364 DSSWARN("TA_TO over limit, setting it to max\n");
2365 ticks = 0x1fff;
2366 x8 = 1;
2367 x16 = 1;
2368 }
2369
2370 r = dsi_read_reg(DSI_TIMING1);
2371 r = FLD_MOD(r, 1, 31, 31); /* TA_TO */
2372 r = FLD_MOD(r, x16, 30, 30); /* TA_TO_X16 */
2373 r = FLD_MOD(r, x8, 29, 29); /* TA_TO_X8 */
2374 r = FLD_MOD(r, ticks, 28, 16); /* TA_TO_COUNTER */
2375 dsi_write_reg(DSI_TIMING1, r);
2376
2377 DSSDBG("TA_TO %lu ns (%#lx ticks%s%s)\n",
2378 (ticks * (x16 ? 16 : 1) * (x8 ? 8 : 1) * 1000) /
2379 (fck / 1000 / 1000),
2380 ticks, x8 ? " x8" : "", x16 ? " x16" : "");
2381}
2382
2383static void dsi_set_stop_state_counter(unsigned long ns)
2384{
2385 u32 r;
2386 unsigned x4, x16;
2387 unsigned long fck;
2388 unsigned long ticks;
2389
2390 /* ticks in DSI_FCK */
2391
2392 fck = dsi_fclk_rate();
2393 ticks = (fck / 1000 / 1000) * ns / 1000;
2394 x4 = 0;
2395 x16 = 0;
2396
2397 if (ticks > 0x1fff) {
2398 ticks = (fck / 1000 / 1000) * ns / 1000 / 4;
2399 x4 = 1;
2400 x16 = 0;
2401 }
2402
2403 if (ticks > 0x1fff) {
2404 ticks = (fck / 1000 / 1000) * ns / 1000 / 16;
2405 x4 = 0;
2406 x16 = 1;
2407 }
2408
2409 if (ticks > 0x1fff) {
2410 ticks = (fck / 1000 / 1000) * ns / 1000 / (4 * 16);
2411 x4 = 1;
2412 x16 = 1;
2413 }
2414
2415 if (ticks > 0x1fff) {
2416 DSSWARN("STOP_STATE_COUNTER_IO over limit, "
2417 "setting it to max\n");
2418 ticks = 0x1fff;
2419 x4 = 1;
2420 x16 = 1;
2421 }
2422
2423 r = dsi_read_reg(DSI_TIMING1);
2424 r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
2425 r = FLD_MOD(r, x16, 14, 14); /* STOP_STATE_X16_IO */
2426 r = FLD_MOD(r, x4, 13, 13); /* STOP_STATE_X4_IO */
2427 r = FLD_MOD(r, ticks, 12, 0); /* STOP_STATE_COUNTER_IO */
2428 dsi_write_reg(DSI_TIMING1, r);
2429
2430 DSSDBG("STOP_STATE_COUNTER %lu ns (%#lx ticks%s%s)\n",
2431 (ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1) * 1000) /
2432 (fck / 1000 / 1000),
2433 ticks, x4 ? " x4" : "", x16 ? " x16" : "");
2434}
2435
2436static void dsi_set_hs_tx_timeout(unsigned long ns)
2437{
2438 u32 r;
2439 unsigned x4, x16;
2440 unsigned long fck;
2441 unsigned long ticks;
2442
2443 /* ticks in TxByteClkHS */
2444
2445 fck = dsi_get_txbyteclkhs();
2446 ticks = (fck / 1000 / 1000) * ns / 1000;
2447 x4 = 0;
2448 x16 = 0;
2449
2450 if (ticks > 0x1fff) {
2451 ticks = (fck / 1000 / 1000) * ns / 1000 / 4;
2452 x4 = 1;
2453 x16 = 0;
2454 }
2455
2456 if (ticks > 0x1fff) {
2457 ticks = (fck / 1000 / 1000) * ns / 1000 / 16;
2458 x4 = 0;
2459 x16 = 1;
2460 }
2461
2462 if (ticks > 0x1fff) {
2463 ticks = (fck / 1000 / 1000) * ns / 1000 / (4 * 16);
2464 x4 = 1;
2465 x16 = 1;
2466 }
2467
2468 if (ticks > 0x1fff) {
2469 DSSWARN("HS_TX_TO over limit, setting it to max\n");
2470 ticks = 0x1fff;
2471 x4 = 1;
2472 x16 = 1;
2473 }
2474
2475 r = dsi_read_reg(DSI_TIMING2);
2476 r = FLD_MOD(r, 1, 31, 31); /* HS_TX_TO */
2477 r = FLD_MOD(r, x16, 30, 30); /* HS_TX_TO_X16 */
2478 r = FLD_MOD(r, x4, 29, 29); /* HS_TX_TO_X8 (4 really) */
2479 r = FLD_MOD(r, ticks, 28, 16); /* HS_TX_TO_COUNTER */
2480 dsi_write_reg(DSI_TIMING2, r);
2481
2482 DSSDBG("HS_TX_TO %lu ns (%#lx ticks%s%s)\n",
2483 (ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1) * 1000) /
2484 (fck / 1000 / 1000),
2485 ticks, x4 ? " x4" : "", x16 ? " x16" : "");
2486}
2487static int dsi_proto_config(struct omap_dss_device *dssdev)
2488{
2489 u32 r;
2490 int buswidth = 0;
2491
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02002492 dsi_config_tx_fifo(DSI_FIFO_SIZE_32,
2493 DSI_FIFO_SIZE_32,
2494 DSI_FIFO_SIZE_32,
2495 DSI_FIFO_SIZE_32);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002496
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02002497 dsi_config_rx_fifo(DSI_FIFO_SIZE_32,
2498 DSI_FIFO_SIZE_32,
2499 DSI_FIFO_SIZE_32,
2500 DSI_FIFO_SIZE_32);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002501
2502 /* XXX what values for the timeouts? */
2503 dsi_set_stop_state_counter(1000);
2504 dsi_set_ta_timeout(6400000);
2505 dsi_set_lp_rx_timeout(48000);
Tomi Valkeinen5ab8e302010-03-12 15:11:19 +02002506 dsi_set_hs_tx_timeout(8000000);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002507
2508 switch (dssdev->ctrl.pixel_size) {
2509 case 16:
2510 buswidth = 0;
2511 break;
2512 case 18:
2513 buswidth = 1;
2514 break;
2515 case 24:
2516 buswidth = 2;
2517 break;
2518 default:
2519 BUG();
2520 }
2521
2522 r = dsi_read_reg(DSI_CTRL);
2523 r = FLD_MOD(r, 1, 1, 1); /* CS_RX_EN */
2524 r = FLD_MOD(r, 1, 2, 2); /* ECC_RX_EN */
2525 r = FLD_MOD(r, 1, 3, 3); /* TX_FIFO_ARBITRATION */
2526 r = FLD_MOD(r, 1, 4, 4); /* VP_CLK_RATIO, always 1, see errata*/
2527 r = FLD_MOD(r, buswidth, 7, 6); /* VP_DATA_BUS_WIDTH */
2528 r = FLD_MOD(r, 0, 8, 8); /* VP_CLK_POL */
2529 r = FLD_MOD(r, 2, 13, 12); /* LINE_BUFFER, 2 lines */
2530 r = FLD_MOD(r, 1, 14, 14); /* TRIGGER_RESET_MODE */
2531 r = FLD_MOD(r, 1, 19, 19); /* EOT_ENABLE */
2532 r = FLD_MOD(r, 1, 24, 24); /* DCS_CMD_ENABLE */
2533 r = FLD_MOD(r, 0, 25, 25); /* DCS_CMD_CODE, 1=start, 0=continue */
2534
2535 dsi_write_reg(DSI_CTRL, r);
2536
2537 dsi_vc_initial_config(0);
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02002538 dsi_vc_initial_config(1);
2539 dsi_vc_initial_config(2);
2540 dsi_vc_initial_config(3);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002541
2542 return 0;
2543}
2544
2545static void dsi_proto_timings(struct omap_dss_device *dssdev)
2546{
2547 unsigned tlpx, tclk_zero, tclk_prepare, tclk_trail;
2548 unsigned tclk_pre, tclk_post;
2549 unsigned ths_prepare, ths_prepare_ths_zero, ths_zero;
2550 unsigned ths_trail, ths_exit;
2551 unsigned ddr_clk_pre, ddr_clk_post;
2552 unsigned enter_hs_mode_lat, exit_hs_mode_lat;
2553 unsigned ths_eot;
2554 u32 r;
2555
2556 r = dsi_read_reg(DSI_DSIPHY_CFG0);
2557 ths_prepare = FLD_GET(r, 31, 24);
2558 ths_prepare_ths_zero = FLD_GET(r, 23, 16);
2559 ths_zero = ths_prepare_ths_zero - ths_prepare;
2560 ths_trail = FLD_GET(r, 15, 8);
2561 ths_exit = FLD_GET(r, 7, 0);
2562
2563 r = dsi_read_reg(DSI_DSIPHY_CFG1);
2564 tlpx = FLD_GET(r, 22, 16) * 2;
2565 tclk_trail = FLD_GET(r, 15, 8);
2566 tclk_zero = FLD_GET(r, 7, 0);
2567
2568 r = dsi_read_reg(DSI_DSIPHY_CFG2);
2569 tclk_prepare = FLD_GET(r, 7, 0);
2570
2571 /* min 8*UI */
2572 tclk_pre = 20;
2573 /* min 60ns + 52*UI */
2574 tclk_post = ns2ddr(60) + 26;
2575
2576 /* ths_eot is 2 for 2 datalanes and 4 for 1 datalane */
2577 if (dssdev->phy.dsi.data1_lane != 0 &&
2578 dssdev->phy.dsi.data2_lane != 0)
2579 ths_eot = 2;
2580 else
2581 ths_eot = 4;
2582
2583 ddr_clk_pre = DIV_ROUND_UP(tclk_pre + tlpx + tclk_zero + tclk_prepare,
2584 4);
2585 ddr_clk_post = DIV_ROUND_UP(tclk_post + ths_trail, 4) + ths_eot;
2586
2587 BUG_ON(ddr_clk_pre == 0 || ddr_clk_pre > 255);
2588 BUG_ON(ddr_clk_post == 0 || ddr_clk_post > 255);
2589
2590 r = dsi_read_reg(DSI_CLK_TIMING);
2591 r = FLD_MOD(r, ddr_clk_pre, 15, 8);
2592 r = FLD_MOD(r, ddr_clk_post, 7, 0);
2593 dsi_write_reg(DSI_CLK_TIMING, r);
2594
2595 DSSDBG("ddr_clk_pre %u, ddr_clk_post %u\n",
2596 ddr_clk_pre,
2597 ddr_clk_post);
2598
2599 enter_hs_mode_lat = 1 + DIV_ROUND_UP(tlpx, 4) +
2600 DIV_ROUND_UP(ths_prepare, 4) +
2601 DIV_ROUND_UP(ths_zero + 3, 4);
2602
2603 exit_hs_mode_lat = DIV_ROUND_UP(ths_trail + ths_exit, 4) + 1 + ths_eot;
2604
2605 r = FLD_VAL(enter_hs_mode_lat, 31, 16) |
2606 FLD_VAL(exit_hs_mode_lat, 15, 0);
2607 dsi_write_reg(DSI_VM_TIMING7, r);
2608
2609 DSSDBG("enter_hs_mode_lat %u, exit_hs_mode_lat %u\n",
2610 enter_hs_mode_lat, exit_hs_mode_lat);
2611}
2612
2613
2614#define DSI_DECL_VARS \
2615 int __dsi_cb = 0; u32 __dsi_cv = 0;
2616
2617#define DSI_FLUSH(ch) \
2618 if (__dsi_cb > 0) { \
2619 /*DSSDBG("sending long packet %#010x\n", __dsi_cv);*/ \
2620 dsi_write_reg(DSI_VC_LONG_PACKET_PAYLOAD(ch), __dsi_cv); \
2621 __dsi_cb = __dsi_cv = 0; \
2622 }
2623
2624#define DSI_PUSH(ch, data) \
2625 do { \
2626 __dsi_cv |= (data) << (__dsi_cb * 8); \
2627 /*DSSDBG("cv = %#010x, cb = %d\n", __dsi_cv, __dsi_cb);*/ \
2628 if (++__dsi_cb > 3) \
2629 DSI_FLUSH(ch); \
2630 } while (0)
2631
2632static int dsi_update_screen_l4(struct omap_dss_device *dssdev,
2633 int x, int y, int w, int h)
2634{
2635 /* Note: supports only 24bit colors in 32bit container */
2636 int first = 1;
2637 int fifo_stalls = 0;
2638 int max_dsi_packet_size;
2639 int max_data_per_packet;
2640 int max_pixels_per_packet;
2641 int pixels_left;
2642 int bytespp = dssdev->ctrl.pixel_size / 8;
2643 int scr_width;
2644 u32 __iomem *data;
2645 int start_offset;
2646 int horiz_inc;
2647 int current_x;
2648 struct omap_overlay *ovl;
2649
2650 debug_irq = 0;
2651
2652 DSSDBG("dsi_update_screen_l4 (%d,%d %dx%d)\n",
2653 x, y, w, h);
2654
2655 ovl = dssdev->manager->overlays[0];
2656
2657 if (ovl->info.color_mode != OMAP_DSS_COLOR_RGB24U)
2658 return -EINVAL;
2659
2660 if (dssdev->ctrl.pixel_size != 24)
2661 return -EINVAL;
2662
2663 scr_width = ovl->info.screen_width;
2664 data = ovl->info.vaddr;
2665
2666 start_offset = scr_width * y + x;
2667 horiz_inc = scr_width - w;
2668 current_x = x;
2669
2670 /* We need header(4) + DCSCMD(1) + pixels(numpix*bytespp) bytes
2671 * in fifo */
2672
2673 /* When using CPU, max long packet size is TX buffer size */
2674 max_dsi_packet_size = dsi.vc[0].fifo_size * 32 * 4;
2675
2676 /* we seem to get better perf if we divide the tx fifo to half,
2677 and while the other half is being sent, we fill the other half
2678 max_dsi_packet_size /= 2; */
2679
2680 max_data_per_packet = max_dsi_packet_size - 4 - 1;
2681
2682 max_pixels_per_packet = max_data_per_packet / bytespp;
2683
2684 DSSDBG("max_pixels_per_packet %d\n", max_pixels_per_packet);
2685
2686 pixels_left = w * h;
2687
2688 DSSDBG("total pixels %d\n", pixels_left);
2689
2690 data += start_offset;
2691
2692 while (pixels_left > 0) {
2693 /* 0x2c = write_memory_start */
2694 /* 0x3c = write_memory_continue */
2695 u8 dcs_cmd = first ? 0x2c : 0x3c;
2696 int pixels;
2697 DSI_DECL_VARS;
2698 first = 0;
2699
2700#if 1
2701 /* using fifo not empty */
2702 /* TX_FIFO_NOT_EMPTY */
2703 while (FLD_GET(dsi_read_reg(DSI_VC_CTRL(0)), 5, 5)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002704 fifo_stalls++;
2705 if (fifo_stalls > 0xfffff) {
2706 DSSERR("fifo stalls overflow, pixels left %d\n",
2707 pixels_left);
2708 dsi_if_enable(0);
2709 return -EIO;
2710 }
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02002711 udelay(1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002712 }
2713#elif 1
2714 /* using fifo emptiness */
2715 while ((REG_GET(DSI_TX_FIFO_VC_EMPTINESS, 7, 0)+1)*4 <
2716 max_dsi_packet_size) {
2717 fifo_stalls++;
2718 if (fifo_stalls > 0xfffff) {
2719 DSSERR("fifo stalls overflow, pixels left %d\n",
2720 pixels_left);
2721 dsi_if_enable(0);
2722 return -EIO;
2723 }
2724 }
2725#else
2726 while ((REG_GET(DSI_TX_FIFO_VC_EMPTINESS, 7, 0)+1)*4 == 0) {
2727 fifo_stalls++;
2728 if (fifo_stalls > 0xfffff) {
2729 DSSERR("fifo stalls overflow, pixels left %d\n",
2730 pixels_left);
2731 dsi_if_enable(0);
2732 return -EIO;
2733 }
2734 }
2735#endif
2736 pixels = min(max_pixels_per_packet, pixels_left);
2737
2738 pixels_left -= pixels;
2739
2740 dsi_vc_write_long_header(0, DSI_DT_DCS_LONG_WRITE,
2741 1 + pixels * bytespp, 0);
2742
2743 DSI_PUSH(0, dcs_cmd);
2744
2745 while (pixels-- > 0) {
2746 u32 pix = __raw_readl(data++);
2747
2748 DSI_PUSH(0, (pix >> 16) & 0xff);
2749 DSI_PUSH(0, (pix >> 8) & 0xff);
2750 DSI_PUSH(0, (pix >> 0) & 0xff);
2751
2752 current_x++;
2753 if (current_x == x+w) {
2754 current_x = x;
2755 data += horiz_inc;
2756 }
2757 }
2758
2759 DSI_FLUSH(0);
2760 }
2761
2762 return 0;
2763}
2764
2765static void dsi_update_screen_dispc(struct omap_dss_device *dssdev,
2766 u16 x, u16 y, u16 w, u16 h)
2767{
2768 unsigned bytespp;
2769 unsigned bytespl;
2770 unsigned bytespf;
2771 unsigned total_len;
2772 unsigned packet_payload;
2773 unsigned packet_len;
2774 u32 l;
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03002775 int r;
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002776 const unsigned channel = dsi.update_channel;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002777 /* line buffer is 1024 x 24bits */
2778 /* XXX: for some reason using full buffer size causes considerable TX
2779 * slowdown with update sizes that fill the whole buffer */
2780 const unsigned line_buf_size = 1023 * 3;
2781
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +02002782 DSSDBG("dsi_update_screen_dispc(%d,%d %dx%d)\n",
2783 x, y, w, h);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002784
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002785 dsi_vc_config_vp(channel);
2786
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002787 bytespp = dssdev->ctrl.pixel_size / 8;
2788 bytespl = w * bytespp;
2789 bytespf = bytespl * h;
2790
2791 /* NOTE: packet_payload has to be equal to N * bytespl, where N is
2792 * number of lines in a packet. See errata about VP_CLK_RATIO */
2793
2794 if (bytespf < line_buf_size)
2795 packet_payload = bytespf;
2796 else
2797 packet_payload = (line_buf_size) / bytespl * bytespl;
2798
2799 packet_len = packet_payload + 1; /* 1 byte for DCS cmd */
2800 total_len = (bytespf / packet_payload) * packet_len;
2801
2802 if (bytespf % packet_payload)
2803 total_len += (bytespf % packet_payload) + 1;
2804
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002805 l = FLD_VAL(total_len, 23, 0); /* TE_SIZE */
2806 dsi_write_reg(DSI_VC_TE(channel), l);
2807
2808 dsi_vc_write_long_header(channel, DSI_DT_DCS_LONG_WRITE, packet_len, 0);
2809
Tomi Valkeinen942a91a2010-02-10 17:27:39 +02002810 if (dsi.te_enabled)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002811 l = FLD_MOD(l, 1, 30, 30); /* TE_EN */
2812 else
2813 l = FLD_MOD(l, 1, 31, 31); /* TE_START */
2814 dsi_write_reg(DSI_VC_TE(channel), l);
2815
2816 /* We put SIDLEMODE to no-idle for the duration of the transfer,
2817 * because DSS interrupts are not capable of waking up the CPU and the
2818 * framedone interrupt could be delayed for quite a long time. I think
2819 * the same goes for any DSS interrupts, but for some reason I have not
2820 * seen the problem anywhere else than here.
2821 */
2822 dispc_disable_sidle();
2823
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002824 dsi_perf_mark_start();
2825
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03002826 r = queue_delayed_work(dsi.workqueue, &dsi.framedone_timeout_work,
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002827 msecs_to_jiffies(250));
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03002828 BUG_ON(r == 0);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002829
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002830 dss_start_update(dssdev);
2831
Tomi Valkeinen942a91a2010-02-10 17:27:39 +02002832 if (dsi.te_enabled) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002833 /* disable LP_RX_TO, so that we can receive TE. Time to wait
2834 * for TE is longer than the timer allows */
2835 REG_FLD_MOD(DSI_TIMING2, 0, 15, 15); /* LP_RX_TO */
2836
2837 dsi_vc_send_bta(channel);
2838
2839#ifdef DSI_CATCH_MISSING_TE
2840 mod_timer(&dsi.te_timer, jiffies + msecs_to_jiffies(250));
2841#endif
2842 }
2843}
2844
2845#ifdef DSI_CATCH_MISSING_TE
2846static void dsi_te_timeout(unsigned long arg)
2847{
2848 DSSERR("TE not received for 250ms!\n");
2849}
2850#endif
2851
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002852static void dsi_framedone_timeout_work_callback(struct work_struct *work)
2853{
2854 int r;
2855 const int channel = dsi.update_channel;
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002856
2857 DSSERR("Framedone not received for 250ms!\n");
2858
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03002859 /* XXX While extremely unlikely, we could get FRAMEDONE interrupt after
2860 * 250ms which would conflict with this timeout work. What should be
2861 * done is first cancel the transfer on the HW, and then cancel the
2862 * possibly scheduled framedone work */
2863
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002864 /* SIDLEMODE back to smart-idle */
2865 dispc_enable_sidle();
2866
Tomi Valkeinen942a91a2010-02-10 17:27:39 +02002867 if (dsi.te_enabled) {
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002868 /* enable LP_RX_TO again after the TE */
2869 REG_FLD_MOD(DSI_TIMING2, 1, 15, 15); /* LP_RX_TO */
2870 }
2871
2872 /* Send BTA after the frame. We need this for the TE to work, as TE
2873 * trigger is only sent for BTAs without preceding packet. Thus we need
2874 * to BTA after the pixel packets so that next BTA will cause TE
2875 * trigger.
2876 *
2877 * This is not needed when TE is not in use, but we do it anyway to
2878 * make sure that the transfer has been completed. It would be more
2879 * optimal, but more complex, to wait only just before starting next
2880 * transfer. */
2881 r = dsi_vc_send_bta_sync(channel);
2882 if (r)
2883 DSSERR("BTA after framedone failed\n");
2884
2885 /* RX_FIFO_NOT_EMPTY */
2886 if (REG_GET(DSI_VC_CTRL(channel), 20, 20)) {
2887 DSSERR("Received error during frame transfer:\n");
2888 dsi_vc_flush_receive_data(channel);
2889 }
2890
2891 dsi.framedone_callback(-ETIMEDOUT, dsi.framedone_data);
2892}
2893
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002894static void dsi_framedone_irq_callback(void *data, u32 mask)
2895{
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03002896 int r;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002897 /* Note: We get FRAMEDONE when DISPC has finished sending pixels and
2898 * turns itself off. However, DSI still has the pixels in its buffers,
2899 * and is sending the data.
2900 */
2901
2902 /* SIDLEMODE back to smart-idle */
2903 dispc_enable_sidle();
2904
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03002905 r = queue_work(dsi.workqueue, &dsi.framedone_work);
2906 BUG_ON(r == 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002907}
2908
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002909static void dsi_handle_framedone(void)
2910{
2911 int r;
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002912 const int channel = dsi.update_channel;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002913
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +02002914 DSSDBG("FRAMEDONE\n");
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002915
Tomi Valkeinen942a91a2010-02-10 17:27:39 +02002916 if (dsi.te_enabled) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002917 /* enable LP_RX_TO again after the TE */
2918 REG_FLD_MOD(DSI_TIMING2, 1, 15, 15); /* LP_RX_TO */
2919 }
2920
2921 /* Send BTA after the frame. We need this for the TE to work, as TE
2922 * trigger is only sent for BTAs without preceding packet. Thus we need
2923 * to BTA after the pixel packets so that next BTA will cause TE
2924 * trigger.
2925 *
2926 * This is not needed when TE is not in use, but we do it anyway to
2927 * make sure that the transfer has been completed. It would be more
2928 * optimal, but more complex, to wait only just before starting next
2929 * transfer. */
2930 r = dsi_vc_send_bta_sync(channel);
2931 if (r)
2932 DSSERR("BTA after framedone failed\n");
2933
2934 /* RX_FIFO_NOT_EMPTY */
2935 if (REG_GET(DSI_VC_CTRL(channel), 20, 20)) {
2936 DSSERR("Received error during frame transfer:\n");
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02002937 dsi_vc_flush_receive_data(channel);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002938 }
2939
2940#ifdef CONFIG_OMAP2_DSS_FAKE_VSYNC
2941 dispc_fake_vsync_irq();
2942#endif
2943}
2944
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002945static void dsi_framedone_work_callback(struct work_struct *work)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002946{
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002947 DSSDBGF();
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002948
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002949 cancel_delayed_work_sync(&dsi.framedone_timeout_work);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002950
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002951 dsi_handle_framedone();
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002952
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002953 dsi_perf_show("DISPC");
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002954
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002955 dsi.framedone_callback(0, dsi.framedone_data);
2956}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002957
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002958int omap_dsi_prepare_update(struct omap_dss_device *dssdev,
2959 u16 *x, u16 *y, u16 *w, u16 *h)
2960{
2961 u16 dw, dh;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002962
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002963 dssdev->driver->get_resolution(dssdev, &dw, &dh);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002964
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002965 if (*x > dw || *y > dh)
2966 return -EINVAL;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002967
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002968 if (*x + *w > dw)
2969 return -EINVAL;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002970
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002971 if (*y + *h > dh)
2972 return -EINVAL;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002973
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002974 if (*w == 1)
2975 return -EINVAL;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002976
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002977 if (*w == 0 || *h == 0)
2978 return -EINVAL;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002979
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002980 dsi_perf_mark_setup();
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002981
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002982 if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) {
2983 dss_setup_partial_planes(dssdev, x, y, w, h);
2984 dispc_set_lcd_size(*w, *h);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002985 }
2986
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002987 return 0;
2988}
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002989EXPORT_SYMBOL(omap_dsi_prepare_update);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002990
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002991int omap_dsi_update(struct omap_dss_device *dssdev,
2992 int channel,
2993 u16 x, u16 y, u16 w, u16 h,
2994 void (*callback)(int, void *), void *data)
2995{
2996 dsi.update_channel = channel;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002997
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002998 if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) {
2999 dsi.framedone_callback = callback;
3000 dsi.framedone_data = data;
3001
3002 dsi.update_region.x = x;
3003 dsi.update_region.y = y;
3004 dsi.update_region.w = w;
3005 dsi.update_region.h = h;
3006 dsi.update_region.device = dssdev;
3007
3008 dsi_update_screen_dispc(dssdev, x, y, w, h);
3009 } else {
3010 dsi_update_screen_l4(dssdev, x, y, w, h);
3011 dsi_perf_show("L4");
3012 callback(0, data);
3013 }
3014
3015 return 0;
3016}
3017EXPORT_SYMBOL(omap_dsi_update);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003018
3019/* Display funcs */
3020
3021static int dsi_display_init_dispc(struct omap_dss_device *dssdev)
3022{
3023 int r;
3024
3025 r = omap_dispc_register_isr(dsi_framedone_irq_callback, NULL,
3026 DISPC_IRQ_FRAMEDONE);
3027 if (r) {
3028 DSSERR("can't get FRAMEDONE irq\n");
3029 return r;
3030 }
3031
3032 dispc_set_lcd_display_type(OMAP_DSS_LCD_DISPLAY_TFT);
3033
3034 dispc_set_parallel_interface_mode(OMAP_DSS_PARALLELMODE_DSI);
3035 dispc_enable_fifohandcheck(1);
3036
3037 dispc_set_tft_data_lines(dssdev->ctrl.pixel_size);
3038
3039 {
3040 struct omap_video_timings timings = {
3041 .hsw = 1,
3042 .hfp = 1,
3043 .hbp = 1,
3044 .vsw = 1,
3045 .vfp = 0,
3046 .vbp = 0,
3047 };
3048
3049 dispc_set_lcd_timings(&timings);
3050 }
3051
3052 return 0;
3053}
3054
3055static void dsi_display_uninit_dispc(struct omap_dss_device *dssdev)
3056{
3057 omap_dispc_unregister_isr(dsi_framedone_irq_callback, NULL,
3058 DISPC_IRQ_FRAMEDONE);
3059}
3060
3061static int dsi_configure_dsi_clocks(struct omap_dss_device *dssdev)
3062{
3063 struct dsi_clock_info cinfo;
3064 int r;
3065
3066 /* we always use DSS2_FCK as input clock */
3067 cinfo.use_dss2_fck = true;
3068 cinfo.regn = dssdev->phy.dsi.div.regn;
3069 cinfo.regm = dssdev->phy.dsi.div.regm;
3070 cinfo.regm3 = dssdev->phy.dsi.div.regm3;
3071 cinfo.regm4 = dssdev->phy.dsi.div.regm4;
3072 r = dsi_calc_clock_rates(&cinfo);
3073 if (r)
3074 return r;
3075
3076 r = dsi_pll_set_clock_div(&cinfo);
3077 if (r) {
3078 DSSERR("Failed to set dsi clocks\n");
3079 return r;
3080 }
3081
3082 return 0;
3083}
3084
3085static int dsi_configure_dispc_clocks(struct omap_dss_device *dssdev)
3086{
3087 struct dispc_clock_info dispc_cinfo;
3088 int r;
3089 unsigned long long fck;
3090
3091 fck = dsi_get_dsi1_pll_rate();
3092
3093 dispc_cinfo.lck_div = dssdev->phy.dsi.div.lck_div;
3094 dispc_cinfo.pck_div = dssdev->phy.dsi.div.pck_div;
3095
3096 r = dispc_calc_clock_rates(fck, &dispc_cinfo);
3097 if (r) {
3098 DSSERR("Failed to calc dispc clocks\n");
3099 return r;
3100 }
3101
3102 r = dispc_set_clock_div(&dispc_cinfo);
3103 if (r) {
3104 DSSERR("Failed to set dispc clocks\n");
3105 return r;
3106 }
3107
3108 return 0;
3109}
3110
3111static int dsi_display_init_dsi(struct omap_dss_device *dssdev)
3112{
3113 int r;
3114
3115 _dsi_print_reset_status();
3116
3117 r = dsi_pll_init(dssdev, true, true);
3118 if (r)
3119 goto err0;
3120
3121 r = dsi_configure_dsi_clocks(dssdev);
3122 if (r)
3123 goto err1;
3124
Tomi Valkeinen2f18c4d2010-01-08 18:00:36 +02003125 dss_select_dispc_clk_source(DSS_SRC_DSI1_PLL_FCLK);
3126 dss_select_dsi_clk_source(DSS_SRC_DSI2_PLL_FCLK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003127
3128 DSSDBG("PLL OK\n");
3129
3130 r = dsi_configure_dispc_clocks(dssdev);
3131 if (r)
3132 goto err2;
3133
3134 r = dsi_complexio_init(dssdev);
3135 if (r)
3136 goto err2;
3137
3138 _dsi_print_reset_status();
3139
3140 dsi_proto_timings(dssdev);
3141 dsi_set_lp_clk_divisor(dssdev);
3142
3143 if (1)
3144 _dsi_print_reset_status();
3145
3146 r = dsi_proto_config(dssdev);
3147 if (r)
3148 goto err3;
3149
3150 /* enable interface */
3151 dsi_vc_enable(0, 1);
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02003152 dsi_vc_enable(1, 1);
3153 dsi_vc_enable(2, 1);
3154 dsi_vc_enable(3, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003155 dsi_if_enable(1);
3156 dsi_force_tx_stop_mode_io();
3157
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003158 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003159err3:
3160 dsi_complexio_uninit();
3161err2:
Tomi Valkeinen2f18c4d2010-01-08 18:00:36 +02003162 dss_select_dispc_clk_source(DSS_SRC_DSS1_ALWON_FCLK);
3163 dss_select_dsi_clk_source(DSS_SRC_DSS1_ALWON_FCLK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003164err1:
3165 dsi_pll_uninit();
3166err0:
3167 return r;
3168}
3169
3170static void dsi_display_uninit_dsi(struct omap_dss_device *dssdev)
3171{
Tomi Valkeinen2f18c4d2010-01-08 18:00:36 +02003172 dss_select_dispc_clk_source(DSS_SRC_DSS1_ALWON_FCLK);
3173 dss_select_dsi_clk_source(DSS_SRC_DSS1_ALWON_FCLK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003174 dsi_complexio_uninit();
3175 dsi_pll_uninit();
3176}
3177
3178static int dsi_core_init(void)
3179{
3180 /* Autoidle */
3181 REG_FLD_MOD(DSI_SYSCONFIG, 1, 0, 0);
3182
3183 /* ENWAKEUP */
3184 REG_FLD_MOD(DSI_SYSCONFIG, 1, 2, 2);
3185
3186 /* SIDLEMODE smart-idle */
3187 REG_FLD_MOD(DSI_SYSCONFIG, 2, 4, 3);
3188
3189 _dsi_initialize_irq();
3190
3191 return 0;
3192}
3193
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003194int omapdss_dsi_display_enable(struct omap_dss_device *dssdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003195{
3196 int r = 0;
3197
3198 DSSDBG("dsi_display_enable\n");
3199
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003200 WARN_ON(!dsi_bus_is_locked());
3201
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003202 mutex_lock(&dsi.lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003203
3204 r = omap_dss_start_device(dssdev);
3205 if (r) {
3206 DSSERR("failed to start device\n");
3207 goto err0;
3208 }
3209
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003210 enable_clocks(1);
3211 dsi_enable_pll_clock(1);
3212
3213 r = _dsi_reset();
3214 if (r)
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003215 goto err1;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003216
3217 dsi_core_init();
3218
3219 r = dsi_display_init_dispc(dssdev);
3220 if (r)
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003221 goto err1;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003222
3223 r = dsi_display_init_dsi(dssdev);
3224 if (r)
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003225 goto err2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003226
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003227 mutex_unlock(&dsi.lock);
3228
3229 return 0;
3230
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003231err2:
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003232 dsi_display_uninit_dispc(dssdev);
3233err1:
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003234 enable_clocks(0);
3235 dsi_enable_pll_clock(0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003236 omap_dss_stop_device(dssdev);
3237err0:
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003238 mutex_unlock(&dsi.lock);
3239 DSSDBG("dsi_display_enable FAILED\n");
3240 return r;
3241}
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003242EXPORT_SYMBOL(omapdss_dsi_display_enable);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003243
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003244void omapdss_dsi_display_disable(struct omap_dss_device *dssdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003245{
3246 DSSDBG("dsi_display_disable\n");
3247
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003248 WARN_ON(!dsi_bus_is_locked());
3249
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003250 mutex_lock(&dsi.lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003251
3252 dsi_display_uninit_dispc(dssdev);
3253
3254 dsi_display_uninit_dsi(dssdev);
3255
3256 enable_clocks(0);
3257 dsi_enable_pll_clock(0);
3258
3259 omap_dss_stop_device(dssdev);
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003260
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003261 mutex_unlock(&dsi.lock);
3262}
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003263EXPORT_SYMBOL(omapdss_dsi_display_disable);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003264
Tomi Valkeinen225b6502010-01-11 15:11:01 +02003265int omapdss_dsi_enable_te(struct omap_dss_device *dssdev, bool enable)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003266{
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003267 dsi.te_enabled = enable;
Tomi Valkeinen225b6502010-01-11 15:11:01 +02003268 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003269}
Tomi Valkeinen225b6502010-01-11 15:11:01 +02003270EXPORT_SYMBOL(omapdss_dsi_enable_te);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003271
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003272void dsi_get_overlay_fifo_thresholds(enum omap_plane plane,
3273 u32 fifo_size, enum omap_burst_size *burst_size,
3274 u32 *fifo_low, u32 *fifo_high)
3275{
3276 unsigned burst_size_bytes;
3277
3278 *burst_size = OMAP_DSS_BURST_16x32;
3279 burst_size_bytes = 16 * 32 / 8;
3280
3281 *fifo_high = fifo_size - burst_size_bytes;
3282 *fifo_low = fifo_size - burst_size_bytes * 8;
3283}
3284
3285int dsi_init_display(struct omap_dss_device *dssdev)
3286{
3287 DSSDBG("DSI init\n");
3288
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003289 /* XXX these should be figured out dynamically */
3290 dssdev->caps = OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE |
3291 OMAP_DSS_DISPLAY_CAP_TEAR_ELIM;
3292
3293 dsi.vc[0].dssdev = dssdev;
3294 dsi.vc[1].dssdev = dssdev;
3295
3296 return 0;
3297}
3298
3299int dsi_init(struct platform_device *pdev)
3300{
3301 u32 rev;
3302 int r;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003303
3304 spin_lock_init(&dsi.errors_lock);
3305 dsi.errors = 0;
3306
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02003307#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
3308 spin_lock_init(&dsi.irq_stats_lock);
3309 dsi.irq_stats.last_reset = jiffies;
3310#endif
3311
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003312 init_completion(&dsi.bta_completion);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003313
3314 mutex_init(&dsi.lock);
Tomi Valkeinenb9eb5d72010-01-11 16:33:56 +02003315 sema_init(&dsi.bus_lock, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003316
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03003317 dsi.workqueue = create_singlethread_workqueue("dsi");
3318 if (dsi.workqueue == NULL)
3319 return -ENOMEM;
3320
Tomi Valkeinen18946f62010-01-12 14:16:41 +02003321 INIT_WORK(&dsi.framedone_work, dsi_framedone_work_callback);
3322 INIT_DELAYED_WORK_DEFERRABLE(&dsi.framedone_timeout_work,
3323 dsi_framedone_timeout_work_callback);
3324
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003325#ifdef DSI_CATCH_MISSING_TE
3326 init_timer(&dsi.te_timer);
3327 dsi.te_timer.function = dsi_te_timeout;
3328 dsi.te_timer.data = 0;
3329#endif
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003330 dsi.base = ioremap(DSI_BASE, DSI_SZ_REGS);
3331 if (!dsi.base) {
3332 DSSERR("can't ioremap DSI\n");
3333 r = -ENOMEM;
3334 goto err1;
3335 }
3336
Tomi Valkeinen8a2cfea2010-02-04 17:03:41 +02003337 dsi.vdds_dsi_reg = dss_get_vdds_dsi();
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003338 if (IS_ERR(dsi.vdds_dsi_reg)) {
3339 iounmap(dsi.base);
3340 DSSERR("can't get VDDS_DSI regulator\n");
3341 r = PTR_ERR(dsi.vdds_dsi_reg);
3342 goto err2;
3343 }
3344
3345 enable_clocks(1);
3346
3347 rev = dsi_read_reg(DSI_REVISION);
3348 printk(KERN_INFO "OMAP DSI rev %d.%d\n",
3349 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
3350
3351 enable_clocks(0);
3352
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003353 return 0;
3354err2:
3355 iounmap(dsi.base);
3356err1:
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03003357 destroy_workqueue(dsi.workqueue);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003358 return r;
3359}
3360
3361void dsi_exit(void)
3362{
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003363 iounmap(dsi.base);
3364
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03003365 destroy_workqueue(dsi.workqueue);
3366
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003367 DSSDBG("omap_dsi_exit\n");
3368}
3369