blob: de3fdab46f389e562a252f5d2a356d77477286fa [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 Valkeinen5d68e032010-02-26 11:32:56 +02002092 return 0;
2093err:
2094 DSSERR("dsi_vc_dcs_write(ch %d, cmd 0x%02x, len %d) failed\n",
2095 channel, data[0], len);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002096 return r;
2097}
2098EXPORT_SYMBOL(dsi_vc_dcs_write);
2099
Tomi Valkeinen828c48f2009-12-16 14:53:15 +02002100int dsi_vc_dcs_write_0(int channel, u8 dcs_cmd)
2101{
2102 return dsi_vc_dcs_write(channel, &dcs_cmd, 1);
2103}
2104EXPORT_SYMBOL(dsi_vc_dcs_write_0);
2105
2106int dsi_vc_dcs_write_1(int channel, u8 dcs_cmd, u8 param)
2107{
2108 u8 buf[2];
2109 buf[0] = dcs_cmd;
2110 buf[1] = param;
2111 return dsi_vc_dcs_write(channel, buf, 2);
2112}
2113EXPORT_SYMBOL(dsi_vc_dcs_write_1);
2114
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002115int dsi_vc_dcs_read(int channel, u8 dcs_cmd, u8 *buf, int buflen)
2116{
2117 u32 val;
2118 u8 dt;
2119 int r;
2120
2121 if (dsi.debug_read)
Tomi Valkeinenff90a342009-12-03 13:38:04 +02002122 DSSDBG("dsi_vc_dcs_read(ch%d, dcs_cmd %x)\n", channel, dcs_cmd);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002123
2124 r = dsi_vc_send_short(channel, DSI_DT_DCS_READ, dcs_cmd, 0);
2125 if (r)
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002126 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002127
2128 r = dsi_vc_send_bta_sync(channel);
2129 if (r)
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002130 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002131
2132 /* RX_FIFO_NOT_EMPTY */
2133 if (REG_GET(DSI_VC_CTRL(channel), 20, 20) == 0) {
2134 DSSERR("RX fifo empty when trying to read.\n");
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002135 r = -EIO;
2136 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002137 }
2138
2139 val = dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel));
2140 if (dsi.debug_read)
2141 DSSDBG("\theader: %08x\n", val);
2142 dt = FLD_GET(val, 5, 0);
2143 if (dt == DSI_DT_RX_ACK_WITH_ERR) {
2144 u16 err = FLD_GET(val, 23, 8);
2145 dsi_show_rx_ack_with_err(err);
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002146 r = -EIO;
2147 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002148
2149 } else if (dt == DSI_DT_RX_SHORT_READ_1) {
2150 u8 data = FLD_GET(val, 15, 8);
2151 if (dsi.debug_read)
2152 DSSDBG("\tDCS short response, 1 byte: %02x\n", data);
2153
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002154 if (buflen < 1) {
2155 r = -EIO;
2156 goto err;
2157 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002158
2159 buf[0] = data;
2160
2161 return 1;
2162 } else if (dt == DSI_DT_RX_SHORT_READ_2) {
2163 u16 data = FLD_GET(val, 23, 8);
2164 if (dsi.debug_read)
2165 DSSDBG("\tDCS short response, 2 byte: %04x\n", data);
2166
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002167 if (buflen < 2) {
2168 r = -EIO;
2169 goto err;
2170 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002171
2172 buf[0] = data & 0xff;
2173 buf[1] = (data >> 8) & 0xff;
2174
2175 return 2;
2176 } else if (dt == DSI_DT_RX_DCS_LONG_READ) {
2177 int w;
2178 int len = FLD_GET(val, 23, 8);
2179 if (dsi.debug_read)
2180 DSSDBG("\tDCS long response, len %d\n", len);
2181
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002182 if (len > buflen) {
2183 r = -EIO;
2184 goto err;
2185 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002186
2187 /* two byte checksum ends the packet, not included in len */
2188 for (w = 0; w < len + 2;) {
2189 int b;
2190 val = dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel));
2191 if (dsi.debug_read)
2192 DSSDBG("\t\t%02x %02x %02x %02x\n",
2193 (val >> 0) & 0xff,
2194 (val >> 8) & 0xff,
2195 (val >> 16) & 0xff,
2196 (val >> 24) & 0xff);
2197
2198 for (b = 0; b < 4; ++b) {
2199 if (w < len)
2200 buf[w] = (val >> (b * 8)) & 0xff;
2201 /* we discard the 2 byte checksum */
2202 ++w;
2203 }
2204 }
2205
2206 return len;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002207 } else {
2208 DSSERR("\tunknown datatype 0x%02x\n", dt);
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002209 r = -EIO;
2210 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002211 }
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002212
2213 BUG();
2214err:
2215 DSSERR("dsi_vc_dcs_read(ch %d, cmd 0x%02x) failed\n",
2216 channel, dcs_cmd);
2217 return r;
2218
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002219}
2220EXPORT_SYMBOL(dsi_vc_dcs_read);
2221
Tomi Valkeinen828c48f2009-12-16 14:53:15 +02002222int dsi_vc_dcs_read_1(int channel, u8 dcs_cmd, u8 *data)
2223{
2224 int r;
2225
2226 r = dsi_vc_dcs_read(channel, dcs_cmd, data, 1);
2227
2228 if (r < 0)
2229 return r;
2230
2231 if (r != 1)
2232 return -EIO;
2233
2234 return 0;
2235}
2236EXPORT_SYMBOL(dsi_vc_dcs_read_1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002237
Tomi Valkeinen53055aa2010-02-25 11:38:13 +02002238int dsi_vc_dcs_read_2(int channel, u8 dcs_cmd, u16 *data)
2239{
2240 int r;
2241
2242 r = dsi_vc_dcs_read(channel, dcs_cmd, (u8 *)data, 2);
2243
2244 if (r < 0)
2245 return r;
2246
2247 if (r != 2)
2248 return -EIO;
2249
2250 return 0;
2251}
2252EXPORT_SYMBOL(dsi_vc_dcs_read_2);
2253
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002254int dsi_vc_set_max_rx_packet_size(int channel, u16 len)
2255{
2256 int r;
2257 r = dsi_vc_send_short(channel, DSI_DT_SET_MAX_RET_PKG_SIZE,
2258 len, 0);
2259
2260 if (r)
2261 return r;
2262
2263 r = dsi_vc_send_bta_sync(channel);
2264
2265 return r;
2266}
2267EXPORT_SYMBOL(dsi_vc_set_max_rx_packet_size);
2268
2269static void dsi_set_lp_rx_timeout(unsigned long ns)
2270{
2271 u32 r;
2272 unsigned x4, x16;
2273 unsigned long fck;
2274 unsigned long ticks;
2275
2276 /* ticks in DSI_FCK */
2277
2278 fck = dsi_fclk_rate();
2279 ticks = (fck / 1000 / 1000) * ns / 1000;
2280 x4 = 0;
2281 x16 = 0;
2282
2283 if (ticks > 0x1fff) {
2284 ticks = (fck / 1000 / 1000) * ns / 1000 / 4;
2285 x4 = 1;
2286 x16 = 0;
2287 }
2288
2289 if (ticks > 0x1fff) {
2290 ticks = (fck / 1000 / 1000) * ns / 1000 / 16;
2291 x4 = 0;
2292 x16 = 1;
2293 }
2294
2295 if (ticks > 0x1fff) {
2296 ticks = (fck / 1000 / 1000) * ns / 1000 / (4 * 16);
2297 x4 = 1;
2298 x16 = 1;
2299 }
2300
2301 if (ticks > 0x1fff) {
2302 DSSWARN("LP_TX_TO over limit, setting it to max\n");
2303 ticks = 0x1fff;
2304 x4 = 1;
2305 x16 = 1;
2306 }
2307
2308 r = dsi_read_reg(DSI_TIMING2);
2309 r = FLD_MOD(r, 1, 15, 15); /* LP_RX_TO */
2310 r = FLD_MOD(r, x16, 14, 14); /* LP_RX_TO_X16 */
2311 r = FLD_MOD(r, x4, 13, 13); /* LP_RX_TO_X4 */
2312 r = FLD_MOD(r, ticks, 12, 0); /* LP_RX_COUNTER */
2313 dsi_write_reg(DSI_TIMING2, r);
2314
2315 DSSDBG("LP_RX_TO %lu ns (%#lx ticks%s%s)\n",
2316 (ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1) * 1000) /
2317 (fck / 1000 / 1000),
2318 ticks, x4 ? " x4" : "", x16 ? " x16" : "");
2319}
2320
2321static void dsi_set_ta_timeout(unsigned long ns)
2322{
2323 u32 r;
2324 unsigned x8, x16;
2325 unsigned long fck;
2326 unsigned long ticks;
2327
2328 /* ticks in DSI_FCK */
2329 fck = dsi_fclk_rate();
2330 ticks = (fck / 1000 / 1000) * ns / 1000;
2331 x8 = 0;
2332 x16 = 0;
2333
2334 if (ticks > 0x1fff) {
2335 ticks = (fck / 1000 / 1000) * ns / 1000 / 8;
2336 x8 = 1;
2337 x16 = 0;
2338 }
2339
2340 if (ticks > 0x1fff) {
2341 ticks = (fck / 1000 / 1000) * ns / 1000 / 16;
2342 x8 = 0;
2343 x16 = 1;
2344 }
2345
2346 if (ticks > 0x1fff) {
2347 ticks = (fck / 1000 / 1000) * ns / 1000 / (8 * 16);
2348 x8 = 1;
2349 x16 = 1;
2350 }
2351
2352 if (ticks > 0x1fff) {
2353 DSSWARN("TA_TO over limit, setting it to max\n");
2354 ticks = 0x1fff;
2355 x8 = 1;
2356 x16 = 1;
2357 }
2358
2359 r = dsi_read_reg(DSI_TIMING1);
2360 r = FLD_MOD(r, 1, 31, 31); /* TA_TO */
2361 r = FLD_MOD(r, x16, 30, 30); /* TA_TO_X16 */
2362 r = FLD_MOD(r, x8, 29, 29); /* TA_TO_X8 */
2363 r = FLD_MOD(r, ticks, 28, 16); /* TA_TO_COUNTER */
2364 dsi_write_reg(DSI_TIMING1, r);
2365
2366 DSSDBG("TA_TO %lu ns (%#lx ticks%s%s)\n",
2367 (ticks * (x16 ? 16 : 1) * (x8 ? 8 : 1) * 1000) /
2368 (fck / 1000 / 1000),
2369 ticks, x8 ? " x8" : "", x16 ? " x16" : "");
2370}
2371
2372static void dsi_set_stop_state_counter(unsigned long ns)
2373{
2374 u32 r;
2375 unsigned x4, x16;
2376 unsigned long fck;
2377 unsigned long ticks;
2378
2379 /* ticks in DSI_FCK */
2380
2381 fck = dsi_fclk_rate();
2382 ticks = (fck / 1000 / 1000) * ns / 1000;
2383 x4 = 0;
2384 x16 = 0;
2385
2386 if (ticks > 0x1fff) {
2387 ticks = (fck / 1000 / 1000) * ns / 1000 / 4;
2388 x4 = 1;
2389 x16 = 0;
2390 }
2391
2392 if (ticks > 0x1fff) {
2393 ticks = (fck / 1000 / 1000) * ns / 1000 / 16;
2394 x4 = 0;
2395 x16 = 1;
2396 }
2397
2398 if (ticks > 0x1fff) {
2399 ticks = (fck / 1000 / 1000) * ns / 1000 / (4 * 16);
2400 x4 = 1;
2401 x16 = 1;
2402 }
2403
2404 if (ticks > 0x1fff) {
2405 DSSWARN("STOP_STATE_COUNTER_IO over limit, "
2406 "setting it to max\n");
2407 ticks = 0x1fff;
2408 x4 = 1;
2409 x16 = 1;
2410 }
2411
2412 r = dsi_read_reg(DSI_TIMING1);
2413 r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
2414 r = FLD_MOD(r, x16, 14, 14); /* STOP_STATE_X16_IO */
2415 r = FLD_MOD(r, x4, 13, 13); /* STOP_STATE_X4_IO */
2416 r = FLD_MOD(r, ticks, 12, 0); /* STOP_STATE_COUNTER_IO */
2417 dsi_write_reg(DSI_TIMING1, r);
2418
2419 DSSDBG("STOP_STATE_COUNTER %lu ns (%#lx ticks%s%s)\n",
2420 (ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1) * 1000) /
2421 (fck / 1000 / 1000),
2422 ticks, x4 ? " x4" : "", x16 ? " x16" : "");
2423}
2424
2425static void dsi_set_hs_tx_timeout(unsigned long ns)
2426{
2427 u32 r;
2428 unsigned x4, x16;
2429 unsigned long fck;
2430 unsigned long ticks;
2431
2432 /* ticks in TxByteClkHS */
2433
2434 fck = dsi_get_txbyteclkhs();
2435 ticks = (fck / 1000 / 1000) * ns / 1000;
2436 x4 = 0;
2437 x16 = 0;
2438
2439 if (ticks > 0x1fff) {
2440 ticks = (fck / 1000 / 1000) * ns / 1000 / 4;
2441 x4 = 1;
2442 x16 = 0;
2443 }
2444
2445 if (ticks > 0x1fff) {
2446 ticks = (fck / 1000 / 1000) * ns / 1000 / 16;
2447 x4 = 0;
2448 x16 = 1;
2449 }
2450
2451 if (ticks > 0x1fff) {
2452 ticks = (fck / 1000 / 1000) * ns / 1000 / (4 * 16);
2453 x4 = 1;
2454 x16 = 1;
2455 }
2456
2457 if (ticks > 0x1fff) {
2458 DSSWARN("HS_TX_TO over limit, setting it to max\n");
2459 ticks = 0x1fff;
2460 x4 = 1;
2461 x16 = 1;
2462 }
2463
2464 r = dsi_read_reg(DSI_TIMING2);
2465 r = FLD_MOD(r, 1, 31, 31); /* HS_TX_TO */
2466 r = FLD_MOD(r, x16, 30, 30); /* HS_TX_TO_X16 */
2467 r = FLD_MOD(r, x4, 29, 29); /* HS_TX_TO_X8 (4 really) */
2468 r = FLD_MOD(r, ticks, 28, 16); /* HS_TX_TO_COUNTER */
2469 dsi_write_reg(DSI_TIMING2, r);
2470
2471 DSSDBG("HS_TX_TO %lu ns (%#lx ticks%s%s)\n",
2472 (ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1) * 1000) /
2473 (fck / 1000 / 1000),
2474 ticks, x4 ? " x4" : "", x16 ? " x16" : "");
2475}
2476static int dsi_proto_config(struct omap_dss_device *dssdev)
2477{
2478 u32 r;
2479 int buswidth = 0;
2480
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02002481 dsi_config_tx_fifo(DSI_FIFO_SIZE_32,
2482 DSI_FIFO_SIZE_32,
2483 DSI_FIFO_SIZE_32,
2484 DSI_FIFO_SIZE_32);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002485
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02002486 dsi_config_rx_fifo(DSI_FIFO_SIZE_32,
2487 DSI_FIFO_SIZE_32,
2488 DSI_FIFO_SIZE_32,
2489 DSI_FIFO_SIZE_32);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002490
2491 /* XXX what values for the timeouts? */
2492 dsi_set_stop_state_counter(1000);
2493 dsi_set_ta_timeout(6400000);
2494 dsi_set_lp_rx_timeout(48000);
Tomi Valkeinen5ab8e302010-03-12 15:11:19 +02002495 dsi_set_hs_tx_timeout(8000000);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002496
2497 switch (dssdev->ctrl.pixel_size) {
2498 case 16:
2499 buswidth = 0;
2500 break;
2501 case 18:
2502 buswidth = 1;
2503 break;
2504 case 24:
2505 buswidth = 2;
2506 break;
2507 default:
2508 BUG();
2509 }
2510
2511 r = dsi_read_reg(DSI_CTRL);
2512 r = FLD_MOD(r, 1, 1, 1); /* CS_RX_EN */
2513 r = FLD_MOD(r, 1, 2, 2); /* ECC_RX_EN */
2514 r = FLD_MOD(r, 1, 3, 3); /* TX_FIFO_ARBITRATION */
2515 r = FLD_MOD(r, 1, 4, 4); /* VP_CLK_RATIO, always 1, see errata*/
2516 r = FLD_MOD(r, buswidth, 7, 6); /* VP_DATA_BUS_WIDTH */
2517 r = FLD_MOD(r, 0, 8, 8); /* VP_CLK_POL */
2518 r = FLD_MOD(r, 2, 13, 12); /* LINE_BUFFER, 2 lines */
2519 r = FLD_MOD(r, 1, 14, 14); /* TRIGGER_RESET_MODE */
2520 r = FLD_MOD(r, 1, 19, 19); /* EOT_ENABLE */
2521 r = FLD_MOD(r, 1, 24, 24); /* DCS_CMD_ENABLE */
2522 r = FLD_MOD(r, 0, 25, 25); /* DCS_CMD_CODE, 1=start, 0=continue */
2523
2524 dsi_write_reg(DSI_CTRL, r);
2525
2526 dsi_vc_initial_config(0);
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02002527 dsi_vc_initial_config(1);
2528 dsi_vc_initial_config(2);
2529 dsi_vc_initial_config(3);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002530
2531 return 0;
2532}
2533
2534static void dsi_proto_timings(struct omap_dss_device *dssdev)
2535{
2536 unsigned tlpx, tclk_zero, tclk_prepare, tclk_trail;
2537 unsigned tclk_pre, tclk_post;
2538 unsigned ths_prepare, ths_prepare_ths_zero, ths_zero;
2539 unsigned ths_trail, ths_exit;
2540 unsigned ddr_clk_pre, ddr_clk_post;
2541 unsigned enter_hs_mode_lat, exit_hs_mode_lat;
2542 unsigned ths_eot;
2543 u32 r;
2544
2545 r = dsi_read_reg(DSI_DSIPHY_CFG0);
2546 ths_prepare = FLD_GET(r, 31, 24);
2547 ths_prepare_ths_zero = FLD_GET(r, 23, 16);
2548 ths_zero = ths_prepare_ths_zero - ths_prepare;
2549 ths_trail = FLD_GET(r, 15, 8);
2550 ths_exit = FLD_GET(r, 7, 0);
2551
2552 r = dsi_read_reg(DSI_DSIPHY_CFG1);
2553 tlpx = FLD_GET(r, 22, 16) * 2;
2554 tclk_trail = FLD_GET(r, 15, 8);
2555 tclk_zero = FLD_GET(r, 7, 0);
2556
2557 r = dsi_read_reg(DSI_DSIPHY_CFG2);
2558 tclk_prepare = FLD_GET(r, 7, 0);
2559
2560 /* min 8*UI */
2561 tclk_pre = 20;
2562 /* min 60ns + 52*UI */
2563 tclk_post = ns2ddr(60) + 26;
2564
2565 /* ths_eot is 2 for 2 datalanes and 4 for 1 datalane */
2566 if (dssdev->phy.dsi.data1_lane != 0 &&
2567 dssdev->phy.dsi.data2_lane != 0)
2568 ths_eot = 2;
2569 else
2570 ths_eot = 4;
2571
2572 ddr_clk_pre = DIV_ROUND_UP(tclk_pre + tlpx + tclk_zero + tclk_prepare,
2573 4);
2574 ddr_clk_post = DIV_ROUND_UP(tclk_post + ths_trail, 4) + ths_eot;
2575
2576 BUG_ON(ddr_clk_pre == 0 || ddr_clk_pre > 255);
2577 BUG_ON(ddr_clk_post == 0 || ddr_clk_post > 255);
2578
2579 r = dsi_read_reg(DSI_CLK_TIMING);
2580 r = FLD_MOD(r, ddr_clk_pre, 15, 8);
2581 r = FLD_MOD(r, ddr_clk_post, 7, 0);
2582 dsi_write_reg(DSI_CLK_TIMING, r);
2583
2584 DSSDBG("ddr_clk_pre %u, ddr_clk_post %u\n",
2585 ddr_clk_pre,
2586 ddr_clk_post);
2587
2588 enter_hs_mode_lat = 1 + DIV_ROUND_UP(tlpx, 4) +
2589 DIV_ROUND_UP(ths_prepare, 4) +
2590 DIV_ROUND_UP(ths_zero + 3, 4);
2591
2592 exit_hs_mode_lat = DIV_ROUND_UP(ths_trail + ths_exit, 4) + 1 + ths_eot;
2593
2594 r = FLD_VAL(enter_hs_mode_lat, 31, 16) |
2595 FLD_VAL(exit_hs_mode_lat, 15, 0);
2596 dsi_write_reg(DSI_VM_TIMING7, r);
2597
2598 DSSDBG("enter_hs_mode_lat %u, exit_hs_mode_lat %u\n",
2599 enter_hs_mode_lat, exit_hs_mode_lat);
2600}
2601
2602
2603#define DSI_DECL_VARS \
2604 int __dsi_cb = 0; u32 __dsi_cv = 0;
2605
2606#define DSI_FLUSH(ch) \
2607 if (__dsi_cb > 0) { \
2608 /*DSSDBG("sending long packet %#010x\n", __dsi_cv);*/ \
2609 dsi_write_reg(DSI_VC_LONG_PACKET_PAYLOAD(ch), __dsi_cv); \
2610 __dsi_cb = __dsi_cv = 0; \
2611 }
2612
2613#define DSI_PUSH(ch, data) \
2614 do { \
2615 __dsi_cv |= (data) << (__dsi_cb * 8); \
2616 /*DSSDBG("cv = %#010x, cb = %d\n", __dsi_cv, __dsi_cb);*/ \
2617 if (++__dsi_cb > 3) \
2618 DSI_FLUSH(ch); \
2619 } while (0)
2620
2621static int dsi_update_screen_l4(struct omap_dss_device *dssdev,
2622 int x, int y, int w, int h)
2623{
2624 /* Note: supports only 24bit colors in 32bit container */
2625 int first = 1;
2626 int fifo_stalls = 0;
2627 int max_dsi_packet_size;
2628 int max_data_per_packet;
2629 int max_pixels_per_packet;
2630 int pixels_left;
2631 int bytespp = dssdev->ctrl.pixel_size / 8;
2632 int scr_width;
2633 u32 __iomem *data;
2634 int start_offset;
2635 int horiz_inc;
2636 int current_x;
2637 struct omap_overlay *ovl;
2638
2639 debug_irq = 0;
2640
2641 DSSDBG("dsi_update_screen_l4 (%d,%d %dx%d)\n",
2642 x, y, w, h);
2643
2644 ovl = dssdev->manager->overlays[0];
2645
2646 if (ovl->info.color_mode != OMAP_DSS_COLOR_RGB24U)
2647 return -EINVAL;
2648
2649 if (dssdev->ctrl.pixel_size != 24)
2650 return -EINVAL;
2651
2652 scr_width = ovl->info.screen_width;
2653 data = ovl->info.vaddr;
2654
2655 start_offset = scr_width * y + x;
2656 horiz_inc = scr_width - w;
2657 current_x = x;
2658
2659 /* We need header(4) + DCSCMD(1) + pixels(numpix*bytespp) bytes
2660 * in fifo */
2661
2662 /* When using CPU, max long packet size is TX buffer size */
2663 max_dsi_packet_size = dsi.vc[0].fifo_size * 32 * 4;
2664
2665 /* we seem to get better perf if we divide the tx fifo to half,
2666 and while the other half is being sent, we fill the other half
2667 max_dsi_packet_size /= 2; */
2668
2669 max_data_per_packet = max_dsi_packet_size - 4 - 1;
2670
2671 max_pixels_per_packet = max_data_per_packet / bytespp;
2672
2673 DSSDBG("max_pixels_per_packet %d\n", max_pixels_per_packet);
2674
2675 pixels_left = w * h;
2676
2677 DSSDBG("total pixels %d\n", pixels_left);
2678
2679 data += start_offset;
2680
2681 while (pixels_left > 0) {
2682 /* 0x2c = write_memory_start */
2683 /* 0x3c = write_memory_continue */
2684 u8 dcs_cmd = first ? 0x2c : 0x3c;
2685 int pixels;
2686 DSI_DECL_VARS;
2687 first = 0;
2688
2689#if 1
2690 /* using fifo not empty */
2691 /* TX_FIFO_NOT_EMPTY */
2692 while (FLD_GET(dsi_read_reg(DSI_VC_CTRL(0)), 5, 5)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002693 fifo_stalls++;
2694 if (fifo_stalls > 0xfffff) {
2695 DSSERR("fifo stalls overflow, pixels left %d\n",
2696 pixels_left);
2697 dsi_if_enable(0);
2698 return -EIO;
2699 }
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02002700 udelay(1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002701 }
2702#elif 1
2703 /* using fifo emptiness */
2704 while ((REG_GET(DSI_TX_FIFO_VC_EMPTINESS, 7, 0)+1)*4 <
2705 max_dsi_packet_size) {
2706 fifo_stalls++;
2707 if (fifo_stalls > 0xfffff) {
2708 DSSERR("fifo stalls overflow, pixels left %d\n",
2709 pixels_left);
2710 dsi_if_enable(0);
2711 return -EIO;
2712 }
2713 }
2714#else
2715 while ((REG_GET(DSI_TX_FIFO_VC_EMPTINESS, 7, 0)+1)*4 == 0) {
2716 fifo_stalls++;
2717 if (fifo_stalls > 0xfffff) {
2718 DSSERR("fifo stalls overflow, pixels left %d\n",
2719 pixels_left);
2720 dsi_if_enable(0);
2721 return -EIO;
2722 }
2723 }
2724#endif
2725 pixels = min(max_pixels_per_packet, pixels_left);
2726
2727 pixels_left -= pixels;
2728
2729 dsi_vc_write_long_header(0, DSI_DT_DCS_LONG_WRITE,
2730 1 + pixels * bytespp, 0);
2731
2732 DSI_PUSH(0, dcs_cmd);
2733
2734 while (pixels-- > 0) {
2735 u32 pix = __raw_readl(data++);
2736
2737 DSI_PUSH(0, (pix >> 16) & 0xff);
2738 DSI_PUSH(0, (pix >> 8) & 0xff);
2739 DSI_PUSH(0, (pix >> 0) & 0xff);
2740
2741 current_x++;
2742 if (current_x == x+w) {
2743 current_x = x;
2744 data += horiz_inc;
2745 }
2746 }
2747
2748 DSI_FLUSH(0);
2749 }
2750
2751 return 0;
2752}
2753
2754static void dsi_update_screen_dispc(struct omap_dss_device *dssdev,
2755 u16 x, u16 y, u16 w, u16 h)
2756{
2757 unsigned bytespp;
2758 unsigned bytespl;
2759 unsigned bytespf;
2760 unsigned total_len;
2761 unsigned packet_payload;
2762 unsigned packet_len;
2763 u32 l;
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03002764 int r;
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002765 const unsigned channel = dsi.update_channel;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002766 /* line buffer is 1024 x 24bits */
2767 /* XXX: for some reason using full buffer size causes considerable TX
2768 * slowdown with update sizes that fill the whole buffer */
2769 const unsigned line_buf_size = 1023 * 3;
2770
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +02002771 DSSDBG("dsi_update_screen_dispc(%d,%d %dx%d)\n",
2772 x, y, w, h);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002773
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002774 dsi_vc_config_vp(channel);
2775
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002776 bytespp = dssdev->ctrl.pixel_size / 8;
2777 bytespl = w * bytespp;
2778 bytespf = bytespl * h;
2779
2780 /* NOTE: packet_payload has to be equal to N * bytespl, where N is
2781 * number of lines in a packet. See errata about VP_CLK_RATIO */
2782
2783 if (bytespf < line_buf_size)
2784 packet_payload = bytespf;
2785 else
2786 packet_payload = (line_buf_size) / bytespl * bytespl;
2787
2788 packet_len = packet_payload + 1; /* 1 byte for DCS cmd */
2789 total_len = (bytespf / packet_payload) * packet_len;
2790
2791 if (bytespf % packet_payload)
2792 total_len += (bytespf % packet_payload) + 1;
2793
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002794 l = FLD_VAL(total_len, 23, 0); /* TE_SIZE */
2795 dsi_write_reg(DSI_VC_TE(channel), l);
2796
2797 dsi_vc_write_long_header(channel, DSI_DT_DCS_LONG_WRITE, packet_len, 0);
2798
Tomi Valkeinen942a91a2010-02-10 17:27:39 +02002799 if (dsi.te_enabled)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002800 l = FLD_MOD(l, 1, 30, 30); /* TE_EN */
2801 else
2802 l = FLD_MOD(l, 1, 31, 31); /* TE_START */
2803 dsi_write_reg(DSI_VC_TE(channel), l);
2804
2805 /* We put SIDLEMODE to no-idle for the duration of the transfer,
2806 * because DSS interrupts are not capable of waking up the CPU and the
2807 * framedone interrupt could be delayed for quite a long time. I think
2808 * the same goes for any DSS interrupts, but for some reason I have not
2809 * seen the problem anywhere else than here.
2810 */
2811 dispc_disable_sidle();
2812
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002813 dsi_perf_mark_start();
2814
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03002815 r = queue_delayed_work(dsi.workqueue, &dsi.framedone_timeout_work,
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002816 msecs_to_jiffies(250));
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03002817 BUG_ON(r == 0);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002818
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002819 dss_start_update(dssdev);
2820
Tomi Valkeinen942a91a2010-02-10 17:27:39 +02002821 if (dsi.te_enabled) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002822 /* disable LP_RX_TO, so that we can receive TE. Time to wait
2823 * for TE is longer than the timer allows */
2824 REG_FLD_MOD(DSI_TIMING2, 0, 15, 15); /* LP_RX_TO */
2825
2826 dsi_vc_send_bta(channel);
2827
2828#ifdef DSI_CATCH_MISSING_TE
2829 mod_timer(&dsi.te_timer, jiffies + msecs_to_jiffies(250));
2830#endif
2831 }
2832}
2833
2834#ifdef DSI_CATCH_MISSING_TE
2835static void dsi_te_timeout(unsigned long arg)
2836{
2837 DSSERR("TE not received for 250ms!\n");
2838}
2839#endif
2840
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002841static void dsi_framedone_timeout_work_callback(struct work_struct *work)
2842{
2843 int r;
2844 const int channel = dsi.update_channel;
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002845
2846 DSSERR("Framedone not received for 250ms!\n");
2847
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03002848 /* XXX While extremely unlikely, we could get FRAMEDONE interrupt after
2849 * 250ms which would conflict with this timeout work. What should be
2850 * done is first cancel the transfer on the HW, and then cancel the
2851 * possibly scheduled framedone work */
2852
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002853 /* SIDLEMODE back to smart-idle */
2854 dispc_enable_sidle();
2855
Tomi Valkeinen942a91a2010-02-10 17:27:39 +02002856 if (dsi.te_enabled) {
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002857 /* enable LP_RX_TO again after the TE */
2858 REG_FLD_MOD(DSI_TIMING2, 1, 15, 15); /* LP_RX_TO */
2859 }
2860
2861 /* Send BTA after the frame. We need this for the TE to work, as TE
2862 * trigger is only sent for BTAs without preceding packet. Thus we need
2863 * to BTA after the pixel packets so that next BTA will cause TE
2864 * trigger.
2865 *
2866 * This is not needed when TE is not in use, but we do it anyway to
2867 * make sure that the transfer has been completed. It would be more
2868 * optimal, but more complex, to wait only just before starting next
2869 * transfer. */
2870 r = dsi_vc_send_bta_sync(channel);
2871 if (r)
2872 DSSERR("BTA after framedone failed\n");
2873
2874 /* RX_FIFO_NOT_EMPTY */
2875 if (REG_GET(DSI_VC_CTRL(channel), 20, 20)) {
2876 DSSERR("Received error during frame transfer:\n");
2877 dsi_vc_flush_receive_data(channel);
2878 }
2879
2880 dsi.framedone_callback(-ETIMEDOUT, dsi.framedone_data);
2881}
2882
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002883static void dsi_framedone_irq_callback(void *data, u32 mask)
2884{
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03002885 int r;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002886 /* Note: We get FRAMEDONE when DISPC has finished sending pixels and
2887 * turns itself off. However, DSI still has the pixels in its buffers,
2888 * and is sending the data.
2889 */
2890
2891 /* SIDLEMODE back to smart-idle */
2892 dispc_enable_sidle();
2893
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03002894 r = queue_work(dsi.workqueue, &dsi.framedone_work);
2895 BUG_ON(r == 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002896}
2897
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002898static void dsi_handle_framedone(void)
2899{
2900 int r;
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002901 const int channel = dsi.update_channel;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002902
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +02002903 DSSDBG("FRAMEDONE\n");
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002904
Tomi Valkeinen942a91a2010-02-10 17:27:39 +02002905 if (dsi.te_enabled) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002906 /* enable LP_RX_TO again after the TE */
2907 REG_FLD_MOD(DSI_TIMING2, 1, 15, 15); /* LP_RX_TO */
2908 }
2909
2910 /* Send BTA after the frame. We need this for the TE to work, as TE
2911 * trigger is only sent for BTAs without preceding packet. Thus we need
2912 * to BTA after the pixel packets so that next BTA will cause TE
2913 * trigger.
2914 *
2915 * This is not needed when TE is not in use, but we do it anyway to
2916 * make sure that the transfer has been completed. It would be more
2917 * optimal, but more complex, to wait only just before starting next
2918 * transfer. */
2919 r = dsi_vc_send_bta_sync(channel);
2920 if (r)
2921 DSSERR("BTA after framedone failed\n");
2922
2923 /* RX_FIFO_NOT_EMPTY */
2924 if (REG_GET(DSI_VC_CTRL(channel), 20, 20)) {
2925 DSSERR("Received error during frame transfer:\n");
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02002926 dsi_vc_flush_receive_data(channel);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002927 }
2928
2929#ifdef CONFIG_OMAP2_DSS_FAKE_VSYNC
2930 dispc_fake_vsync_irq();
2931#endif
2932}
2933
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002934static void dsi_framedone_work_callback(struct work_struct *work)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002935{
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002936 DSSDBGF();
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002937
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002938 cancel_delayed_work_sync(&dsi.framedone_timeout_work);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002939
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002940 dsi_handle_framedone();
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002941
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002942 dsi_perf_show("DISPC");
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002943
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002944 dsi.framedone_callback(0, dsi.framedone_data);
2945}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002946
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002947int omap_dsi_prepare_update(struct omap_dss_device *dssdev,
2948 u16 *x, u16 *y, u16 *w, u16 *h)
2949{
2950 u16 dw, dh;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002951
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002952 dssdev->driver->get_resolution(dssdev, &dw, &dh);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002953
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002954 if (*x > dw || *y > dh)
2955 return -EINVAL;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002956
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002957 if (*x + *w > dw)
2958 return -EINVAL;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002959
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002960 if (*y + *h > dh)
2961 return -EINVAL;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002962
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002963 if (*w == 1)
2964 return -EINVAL;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002965
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002966 if (*w == 0 || *h == 0)
2967 return -EINVAL;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002968
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002969 dsi_perf_mark_setup();
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002970
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002971 if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) {
2972 dss_setup_partial_planes(dssdev, x, y, w, h);
2973 dispc_set_lcd_size(*w, *h);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002974 }
2975
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002976 return 0;
2977}
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002978EXPORT_SYMBOL(omap_dsi_prepare_update);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002979
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002980int omap_dsi_update(struct omap_dss_device *dssdev,
2981 int channel,
2982 u16 x, u16 y, u16 w, u16 h,
2983 void (*callback)(int, void *), void *data)
2984{
2985 dsi.update_channel = channel;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002986
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002987 if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) {
2988 dsi.framedone_callback = callback;
2989 dsi.framedone_data = data;
2990
2991 dsi.update_region.x = x;
2992 dsi.update_region.y = y;
2993 dsi.update_region.w = w;
2994 dsi.update_region.h = h;
2995 dsi.update_region.device = dssdev;
2996
2997 dsi_update_screen_dispc(dssdev, x, y, w, h);
2998 } else {
2999 dsi_update_screen_l4(dssdev, x, y, w, h);
3000 dsi_perf_show("L4");
3001 callback(0, data);
3002 }
3003
3004 return 0;
3005}
3006EXPORT_SYMBOL(omap_dsi_update);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003007
3008/* Display funcs */
3009
3010static int dsi_display_init_dispc(struct omap_dss_device *dssdev)
3011{
3012 int r;
3013
3014 r = omap_dispc_register_isr(dsi_framedone_irq_callback, NULL,
3015 DISPC_IRQ_FRAMEDONE);
3016 if (r) {
3017 DSSERR("can't get FRAMEDONE irq\n");
3018 return r;
3019 }
3020
3021 dispc_set_lcd_display_type(OMAP_DSS_LCD_DISPLAY_TFT);
3022
3023 dispc_set_parallel_interface_mode(OMAP_DSS_PARALLELMODE_DSI);
3024 dispc_enable_fifohandcheck(1);
3025
3026 dispc_set_tft_data_lines(dssdev->ctrl.pixel_size);
3027
3028 {
3029 struct omap_video_timings timings = {
3030 .hsw = 1,
3031 .hfp = 1,
3032 .hbp = 1,
3033 .vsw = 1,
3034 .vfp = 0,
3035 .vbp = 0,
3036 };
3037
3038 dispc_set_lcd_timings(&timings);
3039 }
3040
3041 return 0;
3042}
3043
3044static void dsi_display_uninit_dispc(struct omap_dss_device *dssdev)
3045{
3046 omap_dispc_unregister_isr(dsi_framedone_irq_callback, NULL,
3047 DISPC_IRQ_FRAMEDONE);
3048}
3049
3050static int dsi_configure_dsi_clocks(struct omap_dss_device *dssdev)
3051{
3052 struct dsi_clock_info cinfo;
3053 int r;
3054
3055 /* we always use DSS2_FCK as input clock */
3056 cinfo.use_dss2_fck = true;
3057 cinfo.regn = dssdev->phy.dsi.div.regn;
3058 cinfo.regm = dssdev->phy.dsi.div.regm;
3059 cinfo.regm3 = dssdev->phy.dsi.div.regm3;
3060 cinfo.regm4 = dssdev->phy.dsi.div.regm4;
3061 r = dsi_calc_clock_rates(&cinfo);
3062 if (r)
3063 return r;
3064
3065 r = dsi_pll_set_clock_div(&cinfo);
3066 if (r) {
3067 DSSERR("Failed to set dsi clocks\n");
3068 return r;
3069 }
3070
3071 return 0;
3072}
3073
3074static int dsi_configure_dispc_clocks(struct omap_dss_device *dssdev)
3075{
3076 struct dispc_clock_info dispc_cinfo;
3077 int r;
3078 unsigned long long fck;
3079
3080 fck = dsi_get_dsi1_pll_rate();
3081
3082 dispc_cinfo.lck_div = dssdev->phy.dsi.div.lck_div;
3083 dispc_cinfo.pck_div = dssdev->phy.dsi.div.pck_div;
3084
3085 r = dispc_calc_clock_rates(fck, &dispc_cinfo);
3086 if (r) {
3087 DSSERR("Failed to calc dispc clocks\n");
3088 return r;
3089 }
3090
3091 r = dispc_set_clock_div(&dispc_cinfo);
3092 if (r) {
3093 DSSERR("Failed to set dispc clocks\n");
3094 return r;
3095 }
3096
3097 return 0;
3098}
3099
3100static int dsi_display_init_dsi(struct omap_dss_device *dssdev)
3101{
3102 int r;
3103
3104 _dsi_print_reset_status();
3105
3106 r = dsi_pll_init(dssdev, true, true);
3107 if (r)
3108 goto err0;
3109
3110 r = dsi_configure_dsi_clocks(dssdev);
3111 if (r)
3112 goto err1;
3113
Tomi Valkeinen2f18c4d2010-01-08 18:00:36 +02003114 dss_select_dispc_clk_source(DSS_SRC_DSI1_PLL_FCLK);
3115 dss_select_dsi_clk_source(DSS_SRC_DSI2_PLL_FCLK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003116
3117 DSSDBG("PLL OK\n");
3118
3119 r = dsi_configure_dispc_clocks(dssdev);
3120 if (r)
3121 goto err2;
3122
3123 r = dsi_complexio_init(dssdev);
3124 if (r)
3125 goto err2;
3126
3127 _dsi_print_reset_status();
3128
3129 dsi_proto_timings(dssdev);
3130 dsi_set_lp_clk_divisor(dssdev);
3131
3132 if (1)
3133 _dsi_print_reset_status();
3134
3135 r = dsi_proto_config(dssdev);
3136 if (r)
3137 goto err3;
3138
3139 /* enable interface */
3140 dsi_vc_enable(0, 1);
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02003141 dsi_vc_enable(1, 1);
3142 dsi_vc_enable(2, 1);
3143 dsi_vc_enable(3, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003144 dsi_if_enable(1);
3145 dsi_force_tx_stop_mode_io();
3146
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003147 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003148err3:
3149 dsi_complexio_uninit();
3150err2:
Tomi Valkeinen2f18c4d2010-01-08 18:00:36 +02003151 dss_select_dispc_clk_source(DSS_SRC_DSS1_ALWON_FCLK);
3152 dss_select_dsi_clk_source(DSS_SRC_DSS1_ALWON_FCLK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003153err1:
3154 dsi_pll_uninit();
3155err0:
3156 return r;
3157}
3158
3159static void dsi_display_uninit_dsi(struct omap_dss_device *dssdev)
3160{
Tomi Valkeinen2f18c4d2010-01-08 18:00:36 +02003161 dss_select_dispc_clk_source(DSS_SRC_DSS1_ALWON_FCLK);
3162 dss_select_dsi_clk_source(DSS_SRC_DSS1_ALWON_FCLK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003163 dsi_complexio_uninit();
3164 dsi_pll_uninit();
3165}
3166
3167static int dsi_core_init(void)
3168{
3169 /* Autoidle */
3170 REG_FLD_MOD(DSI_SYSCONFIG, 1, 0, 0);
3171
3172 /* ENWAKEUP */
3173 REG_FLD_MOD(DSI_SYSCONFIG, 1, 2, 2);
3174
3175 /* SIDLEMODE smart-idle */
3176 REG_FLD_MOD(DSI_SYSCONFIG, 2, 4, 3);
3177
3178 _dsi_initialize_irq();
3179
3180 return 0;
3181}
3182
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003183int omapdss_dsi_display_enable(struct omap_dss_device *dssdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003184{
3185 int r = 0;
3186
3187 DSSDBG("dsi_display_enable\n");
3188
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003189 WARN_ON(!dsi_bus_is_locked());
3190
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003191 mutex_lock(&dsi.lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003192
3193 r = omap_dss_start_device(dssdev);
3194 if (r) {
3195 DSSERR("failed to start device\n");
3196 goto err0;
3197 }
3198
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003199 enable_clocks(1);
3200 dsi_enable_pll_clock(1);
3201
3202 r = _dsi_reset();
3203 if (r)
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003204 goto err1;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003205
3206 dsi_core_init();
3207
3208 r = dsi_display_init_dispc(dssdev);
3209 if (r)
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003210 goto err1;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003211
3212 r = dsi_display_init_dsi(dssdev);
3213 if (r)
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003214 goto err2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003215
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003216 mutex_unlock(&dsi.lock);
3217
3218 return 0;
3219
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003220err2:
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003221 dsi_display_uninit_dispc(dssdev);
3222err1:
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003223 enable_clocks(0);
3224 dsi_enable_pll_clock(0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003225 omap_dss_stop_device(dssdev);
3226err0:
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003227 mutex_unlock(&dsi.lock);
3228 DSSDBG("dsi_display_enable FAILED\n");
3229 return r;
3230}
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003231EXPORT_SYMBOL(omapdss_dsi_display_enable);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003232
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003233void omapdss_dsi_display_disable(struct omap_dss_device *dssdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003234{
3235 DSSDBG("dsi_display_disable\n");
3236
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003237 WARN_ON(!dsi_bus_is_locked());
3238
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003239 mutex_lock(&dsi.lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003240
3241 dsi_display_uninit_dispc(dssdev);
3242
3243 dsi_display_uninit_dsi(dssdev);
3244
3245 enable_clocks(0);
3246 dsi_enable_pll_clock(0);
3247
3248 omap_dss_stop_device(dssdev);
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003249
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003250 mutex_unlock(&dsi.lock);
3251}
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003252EXPORT_SYMBOL(omapdss_dsi_display_disable);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003253
Tomi Valkeinen225b6502010-01-11 15:11:01 +02003254int omapdss_dsi_enable_te(struct omap_dss_device *dssdev, bool enable)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003255{
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003256 dsi.te_enabled = enable;
Tomi Valkeinen225b6502010-01-11 15:11:01 +02003257 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003258}
Tomi Valkeinen225b6502010-01-11 15:11:01 +02003259EXPORT_SYMBOL(omapdss_dsi_enable_te);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003260
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003261void dsi_get_overlay_fifo_thresholds(enum omap_plane plane,
3262 u32 fifo_size, enum omap_burst_size *burst_size,
3263 u32 *fifo_low, u32 *fifo_high)
3264{
3265 unsigned burst_size_bytes;
3266
3267 *burst_size = OMAP_DSS_BURST_16x32;
3268 burst_size_bytes = 16 * 32 / 8;
3269
3270 *fifo_high = fifo_size - burst_size_bytes;
3271 *fifo_low = fifo_size - burst_size_bytes * 8;
3272}
3273
3274int dsi_init_display(struct omap_dss_device *dssdev)
3275{
3276 DSSDBG("DSI init\n");
3277
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003278 /* XXX these should be figured out dynamically */
3279 dssdev->caps = OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE |
3280 OMAP_DSS_DISPLAY_CAP_TEAR_ELIM;
3281
3282 dsi.vc[0].dssdev = dssdev;
3283 dsi.vc[1].dssdev = dssdev;
3284
3285 return 0;
3286}
3287
3288int dsi_init(struct platform_device *pdev)
3289{
3290 u32 rev;
3291 int r;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003292
3293 spin_lock_init(&dsi.errors_lock);
3294 dsi.errors = 0;
3295
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02003296#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
3297 spin_lock_init(&dsi.irq_stats_lock);
3298 dsi.irq_stats.last_reset = jiffies;
3299#endif
3300
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003301 init_completion(&dsi.bta_completion);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003302
3303 mutex_init(&dsi.lock);
Tomi Valkeinenb9eb5d72010-01-11 16:33:56 +02003304 sema_init(&dsi.bus_lock, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003305
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03003306 dsi.workqueue = create_singlethread_workqueue("dsi");
3307 if (dsi.workqueue == NULL)
3308 return -ENOMEM;
3309
Tomi Valkeinen18946f62010-01-12 14:16:41 +02003310 INIT_WORK(&dsi.framedone_work, dsi_framedone_work_callback);
3311 INIT_DELAYED_WORK_DEFERRABLE(&dsi.framedone_timeout_work,
3312 dsi_framedone_timeout_work_callback);
3313
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003314#ifdef DSI_CATCH_MISSING_TE
3315 init_timer(&dsi.te_timer);
3316 dsi.te_timer.function = dsi_te_timeout;
3317 dsi.te_timer.data = 0;
3318#endif
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003319 dsi.base = ioremap(DSI_BASE, DSI_SZ_REGS);
3320 if (!dsi.base) {
3321 DSSERR("can't ioremap DSI\n");
3322 r = -ENOMEM;
3323 goto err1;
3324 }
3325
Tomi Valkeinen8a2cfea2010-02-04 17:03:41 +02003326 dsi.vdds_dsi_reg = dss_get_vdds_dsi();
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003327 if (IS_ERR(dsi.vdds_dsi_reg)) {
3328 iounmap(dsi.base);
3329 DSSERR("can't get VDDS_DSI regulator\n");
3330 r = PTR_ERR(dsi.vdds_dsi_reg);
3331 goto err2;
3332 }
3333
3334 enable_clocks(1);
3335
3336 rev = dsi_read_reg(DSI_REVISION);
3337 printk(KERN_INFO "OMAP DSI rev %d.%d\n",
3338 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
3339
3340 enable_clocks(0);
3341
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003342 return 0;
3343err2:
3344 iounmap(dsi.base);
3345err1:
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03003346 destroy_workqueue(dsi.workqueue);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003347 return r;
3348}
3349
3350void dsi_exit(void)
3351{
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003352 iounmap(dsi.base);
3353
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03003354 destroy_workqueue(dsi.workqueue);
3355
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003356 DSSDBG("omap_dsi_exit\n");
3357}
3358