blob: 705599ad3166eb8a612d88057c6c4cd6b30deca5 [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"
Archit Taneja819d8072011-03-01 11:54:00 +053041#include "dss_features.h"
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +020042
43/*#define VERBOSE_IRQ*/
44#define DSI_CATCH_MISSING_TE
45
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +020046struct dsi_reg { u16 idx; };
47
48#define DSI_REG(idx) ((const struct dsi_reg) { idx })
49
50#define DSI_SZ_REGS SZ_1K
51/* DSI Protocol Engine */
52
53#define DSI_REVISION DSI_REG(0x0000)
54#define DSI_SYSCONFIG DSI_REG(0x0010)
55#define DSI_SYSSTATUS DSI_REG(0x0014)
56#define DSI_IRQSTATUS DSI_REG(0x0018)
57#define DSI_IRQENABLE DSI_REG(0x001C)
58#define DSI_CTRL DSI_REG(0x0040)
59#define DSI_COMPLEXIO_CFG1 DSI_REG(0x0048)
60#define DSI_COMPLEXIO_IRQ_STATUS DSI_REG(0x004C)
61#define DSI_COMPLEXIO_IRQ_ENABLE DSI_REG(0x0050)
62#define DSI_CLK_CTRL DSI_REG(0x0054)
63#define DSI_TIMING1 DSI_REG(0x0058)
64#define DSI_TIMING2 DSI_REG(0x005C)
65#define DSI_VM_TIMING1 DSI_REG(0x0060)
66#define DSI_VM_TIMING2 DSI_REG(0x0064)
67#define DSI_VM_TIMING3 DSI_REG(0x0068)
68#define DSI_CLK_TIMING DSI_REG(0x006C)
69#define DSI_TX_FIFO_VC_SIZE DSI_REG(0x0070)
70#define DSI_RX_FIFO_VC_SIZE DSI_REG(0x0074)
71#define DSI_COMPLEXIO_CFG2 DSI_REG(0x0078)
72#define DSI_RX_FIFO_VC_FULLNESS DSI_REG(0x007C)
73#define DSI_VM_TIMING4 DSI_REG(0x0080)
74#define DSI_TX_FIFO_VC_EMPTINESS DSI_REG(0x0084)
75#define DSI_VM_TIMING5 DSI_REG(0x0088)
76#define DSI_VM_TIMING6 DSI_REG(0x008C)
77#define DSI_VM_TIMING7 DSI_REG(0x0090)
78#define DSI_STOPCLK_TIMING DSI_REG(0x0094)
79#define DSI_VC_CTRL(n) DSI_REG(0x0100 + (n * 0x20))
80#define DSI_VC_TE(n) DSI_REG(0x0104 + (n * 0x20))
81#define DSI_VC_LONG_PACKET_HEADER(n) DSI_REG(0x0108 + (n * 0x20))
82#define DSI_VC_LONG_PACKET_PAYLOAD(n) DSI_REG(0x010C + (n * 0x20))
83#define DSI_VC_SHORT_PACKET_HEADER(n) DSI_REG(0x0110 + (n * 0x20))
84#define DSI_VC_IRQSTATUS(n) DSI_REG(0x0118 + (n * 0x20))
85#define DSI_VC_IRQENABLE(n) DSI_REG(0x011C + (n * 0x20))
86
87/* DSIPHY_SCP */
88
89#define DSI_DSIPHY_CFG0 DSI_REG(0x200 + 0x0000)
90#define DSI_DSIPHY_CFG1 DSI_REG(0x200 + 0x0004)
91#define DSI_DSIPHY_CFG2 DSI_REG(0x200 + 0x0008)
92#define DSI_DSIPHY_CFG5 DSI_REG(0x200 + 0x0014)
93
94/* DSI_PLL_CTRL_SCP */
95
96#define DSI_PLL_CONTROL DSI_REG(0x300 + 0x0000)
97#define DSI_PLL_STATUS DSI_REG(0x300 + 0x0004)
98#define DSI_PLL_GO DSI_REG(0x300 + 0x0008)
99#define DSI_PLL_CONFIGURATION1 DSI_REG(0x300 + 0x000C)
100#define DSI_PLL_CONFIGURATION2 DSI_REG(0x300 + 0x0010)
101
102#define REG_GET(idx, start, end) \
103 FLD_GET(dsi_read_reg(idx), start, end)
104
105#define REG_FLD_MOD(idx, val, start, end) \
106 dsi_write_reg(idx, FLD_MOD(dsi_read_reg(idx), val, start, end))
107
108/* Global interrupts */
109#define DSI_IRQ_VC0 (1 << 0)
110#define DSI_IRQ_VC1 (1 << 1)
111#define DSI_IRQ_VC2 (1 << 2)
112#define DSI_IRQ_VC3 (1 << 3)
113#define DSI_IRQ_WAKEUP (1 << 4)
114#define DSI_IRQ_RESYNC (1 << 5)
115#define DSI_IRQ_PLL_LOCK (1 << 7)
116#define DSI_IRQ_PLL_UNLOCK (1 << 8)
117#define DSI_IRQ_PLL_RECALL (1 << 9)
118#define DSI_IRQ_COMPLEXIO_ERR (1 << 10)
119#define DSI_IRQ_HS_TX_TIMEOUT (1 << 14)
120#define DSI_IRQ_LP_RX_TIMEOUT (1 << 15)
121#define DSI_IRQ_TE_TRIGGER (1 << 16)
122#define DSI_IRQ_ACK_TRIGGER (1 << 17)
123#define DSI_IRQ_SYNC_LOST (1 << 18)
124#define DSI_IRQ_LDO_POWER_GOOD (1 << 19)
125#define DSI_IRQ_TA_TIMEOUT (1 << 20)
126#define DSI_IRQ_ERROR_MASK \
127 (DSI_IRQ_HS_TX_TIMEOUT | DSI_IRQ_LP_RX_TIMEOUT | DSI_IRQ_SYNC_LOST | \
128 DSI_IRQ_TA_TIMEOUT)
129#define DSI_IRQ_CHANNEL_MASK 0xf
130
131/* Virtual channel interrupts */
132#define DSI_VC_IRQ_CS (1 << 0)
133#define DSI_VC_IRQ_ECC_CORR (1 << 1)
134#define DSI_VC_IRQ_PACKET_SENT (1 << 2)
135#define DSI_VC_IRQ_FIFO_TX_OVF (1 << 3)
136#define DSI_VC_IRQ_FIFO_RX_OVF (1 << 4)
137#define DSI_VC_IRQ_BTA (1 << 5)
138#define DSI_VC_IRQ_ECC_NO_CORR (1 << 6)
139#define DSI_VC_IRQ_FIFO_TX_UDF (1 << 7)
140#define DSI_VC_IRQ_PP_BUSY_CHANGE (1 << 8)
141#define DSI_VC_IRQ_ERROR_MASK \
142 (DSI_VC_IRQ_CS | DSI_VC_IRQ_ECC_CORR | DSI_VC_IRQ_FIFO_TX_OVF | \
143 DSI_VC_IRQ_FIFO_RX_OVF | DSI_VC_IRQ_ECC_NO_CORR | \
144 DSI_VC_IRQ_FIFO_TX_UDF)
145
146/* ComplexIO interrupts */
147#define DSI_CIO_IRQ_ERRSYNCESC1 (1 << 0)
148#define DSI_CIO_IRQ_ERRSYNCESC2 (1 << 1)
149#define DSI_CIO_IRQ_ERRSYNCESC3 (1 << 2)
150#define DSI_CIO_IRQ_ERRESC1 (1 << 5)
151#define DSI_CIO_IRQ_ERRESC2 (1 << 6)
152#define DSI_CIO_IRQ_ERRESC3 (1 << 7)
153#define DSI_CIO_IRQ_ERRCONTROL1 (1 << 10)
154#define DSI_CIO_IRQ_ERRCONTROL2 (1 << 11)
155#define DSI_CIO_IRQ_ERRCONTROL3 (1 << 12)
156#define DSI_CIO_IRQ_STATEULPS1 (1 << 15)
157#define DSI_CIO_IRQ_STATEULPS2 (1 << 16)
158#define DSI_CIO_IRQ_STATEULPS3 (1 << 17)
159#define DSI_CIO_IRQ_ERRCONTENTIONLP0_1 (1 << 20)
160#define DSI_CIO_IRQ_ERRCONTENTIONLP1_1 (1 << 21)
161#define DSI_CIO_IRQ_ERRCONTENTIONLP0_2 (1 << 22)
162#define DSI_CIO_IRQ_ERRCONTENTIONLP1_2 (1 << 23)
163#define DSI_CIO_IRQ_ERRCONTENTIONLP0_3 (1 << 24)
164#define DSI_CIO_IRQ_ERRCONTENTIONLP1_3 (1 << 25)
165#define DSI_CIO_IRQ_ULPSACTIVENOT_ALL0 (1 << 30)
166#define DSI_CIO_IRQ_ULPSACTIVENOT_ALL1 (1 << 31)
Tomi Valkeinenbbecb502010-05-10 14:35:33 +0300167#define DSI_CIO_IRQ_ERROR_MASK \
168 (DSI_CIO_IRQ_ERRSYNCESC1 | DSI_CIO_IRQ_ERRSYNCESC2 | \
169 DSI_CIO_IRQ_ERRSYNCESC3 | DSI_CIO_IRQ_ERRESC1 | DSI_CIO_IRQ_ERRESC2 | \
170 DSI_CIO_IRQ_ERRESC3 | DSI_CIO_IRQ_ERRCONTROL1 | \
171 DSI_CIO_IRQ_ERRCONTROL2 | DSI_CIO_IRQ_ERRCONTROL3 | \
172 DSI_CIO_IRQ_ERRCONTENTIONLP0_1 | DSI_CIO_IRQ_ERRCONTENTIONLP1_1 | \
173 DSI_CIO_IRQ_ERRCONTENTIONLP0_2 | DSI_CIO_IRQ_ERRCONTENTIONLP1_2 | \
174 DSI_CIO_IRQ_ERRCONTENTIONLP0_3 | DSI_CIO_IRQ_ERRCONTENTIONLP1_3)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200175
176#define DSI_DT_DCS_SHORT_WRITE_0 0x05
177#define DSI_DT_DCS_SHORT_WRITE_1 0x15
178#define DSI_DT_DCS_READ 0x06
179#define DSI_DT_SET_MAX_RET_PKG_SIZE 0x37
180#define DSI_DT_NULL_PACKET 0x09
181#define DSI_DT_DCS_LONG_WRITE 0x39
182
183#define DSI_DT_RX_ACK_WITH_ERR 0x02
184#define DSI_DT_RX_DCS_LONG_READ 0x1c
185#define DSI_DT_RX_SHORT_READ_1 0x21
186#define DSI_DT_RX_SHORT_READ_2 0x22
187
188#define FINT_MAX 2100000
189#define FINT_MIN 750000
190#define REGN_MAX (1 << 7)
191#define REGM_MAX ((1 << 11) - 1)
192#define REGM3_MAX (1 << 4)
193#define REGM4_MAX (1 << 4)
194#define LP_DIV_MAX ((1 << 13) - 1)
195
196enum fifo_size {
197 DSI_FIFO_SIZE_0 = 0,
198 DSI_FIFO_SIZE_32 = 1,
199 DSI_FIFO_SIZE_64 = 2,
200 DSI_FIFO_SIZE_96 = 3,
201 DSI_FIFO_SIZE_128 = 4,
202};
203
204enum dsi_vc_mode {
205 DSI_VC_MODE_L4 = 0,
206 DSI_VC_MODE_VP,
207};
208
209struct dsi_update_region {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200210 u16 x, y, w, h;
211 struct omap_dss_device *device;
212};
213
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200214struct dsi_irq_stats {
215 unsigned long last_reset;
216 unsigned irq_count;
217 unsigned dsi_irqs[32];
218 unsigned vc_irqs[4][32];
219 unsigned cio_irqs[32];
220};
221
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200222static struct
223{
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +0000224 struct platform_device *pdev;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200225 void __iomem *base;
archit tanejaaffe3602011-02-23 08:41:03 +0000226 int irq;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200227
228 struct dsi_clock_info current_cinfo;
229
230 struct regulator *vdds_dsi_reg;
231
232 struct {
233 enum dsi_vc_mode mode;
234 struct omap_dss_device *dssdev;
235 enum fifo_size fifo_size;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200236 } vc[4];
237
238 struct mutex lock;
Tomi Valkeinenb9eb5d72010-01-11 16:33:56 +0200239 struct semaphore bus_lock;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200240
241 unsigned pll_locked;
242
243 struct completion bta_completion;
Tomi Valkeinenab83b142010-06-09 15:31:01 +0300244 void (*bta_callback)(void);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200245
Tomi Valkeinen18946f62010-01-12 14:16:41 +0200246 int update_channel;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200247 struct dsi_update_region update_region;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200248
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200249 bool te_enabled;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200250
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +0300251 struct workqueue_struct *workqueue;
252
Tomi Valkeinen18946f62010-01-12 14:16:41 +0200253 void (*framedone_callback)(int, void *);
254 void *framedone_data;
255
256 struct delayed_work framedone_timeout_work;
257
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200258#ifdef DSI_CATCH_MISSING_TE
259 struct timer_list te_timer;
260#endif
261
262 unsigned long cache_req_pck;
263 unsigned long cache_clk_freq;
264 struct dsi_clock_info cache_cinfo;
265
266 u32 errors;
267 spinlock_t errors_lock;
268#ifdef DEBUG
269 ktime_t perf_setup_time;
270 ktime_t perf_start_time;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200271#endif
272 int debug_read;
273 int debug_write;
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200274
275#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
276 spinlock_t irq_stats_lock;
277 struct dsi_irq_stats irq_stats;
278#endif
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200279} dsi;
280
281#ifdef DEBUG
282static unsigned int dsi_perf;
283module_param_named(dsi_perf, dsi_perf, bool, 0644);
284#endif
285
286static inline void dsi_write_reg(const struct dsi_reg idx, u32 val)
287{
288 __raw_writel(val, dsi.base + idx.idx);
289}
290
291static inline u32 dsi_read_reg(const struct dsi_reg idx)
292{
293 return __raw_readl(dsi.base + idx.idx);
294}
295
296
297void dsi_save_context(void)
298{
299}
300
301void dsi_restore_context(void)
302{
303}
304
305void dsi_bus_lock(void)
306{
Tomi Valkeinenb9eb5d72010-01-11 16:33:56 +0200307 down(&dsi.bus_lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200308}
309EXPORT_SYMBOL(dsi_bus_lock);
310
311void dsi_bus_unlock(void)
312{
Tomi Valkeinenb9eb5d72010-01-11 16:33:56 +0200313 up(&dsi.bus_lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200314}
315EXPORT_SYMBOL(dsi_bus_unlock);
316
Tomi Valkeinen4f765022010-01-18 16:27:52 +0200317static bool dsi_bus_is_locked(void)
318{
Tomi Valkeinenb9eb5d72010-01-11 16:33:56 +0200319 return dsi.bus_lock.count == 0;
Tomi Valkeinen4f765022010-01-18 16:27:52 +0200320}
321
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200322static inline int wait_for_bit_change(const struct dsi_reg idx, int bitnum,
323 int value)
324{
325 int t = 100000;
326
327 while (REG_GET(idx, bitnum, bitnum) != value) {
328 if (--t == 0)
329 return !value;
330 }
331
332 return value;
333}
334
335#ifdef DEBUG
336static void dsi_perf_mark_setup(void)
337{
338 dsi.perf_setup_time = ktime_get();
339}
340
341static void dsi_perf_mark_start(void)
342{
343 dsi.perf_start_time = ktime_get();
344}
345
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200346static void dsi_perf_show(const char *name)
347{
348 ktime_t t, setup_time, trans_time;
349 u32 total_bytes;
350 u32 setup_us, trans_us, total_us;
351
352 if (!dsi_perf)
353 return;
354
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200355 t = ktime_get();
356
357 setup_time = ktime_sub(dsi.perf_start_time, dsi.perf_setup_time);
358 setup_us = (u32)ktime_to_us(setup_time);
359 if (setup_us == 0)
360 setup_us = 1;
361
362 trans_time = ktime_sub(t, dsi.perf_start_time);
363 trans_us = (u32)ktime_to_us(trans_time);
364 if (trans_us == 0)
365 trans_us = 1;
366
367 total_us = setup_us + trans_us;
368
Tomi Valkeinen18946f62010-01-12 14:16:41 +0200369 total_bytes = dsi.update_region.w *
370 dsi.update_region.h *
371 dsi.update_region.device->ctrl.pixel_size / 8;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200372
Tomi Valkeinen1bbb2752010-01-11 16:41:10 +0200373 printk(KERN_INFO "DSI(%s): %u us + %u us = %u us (%uHz), "
374 "%u bytes, %u kbytes/sec\n",
375 name,
376 setup_us,
377 trans_us,
378 total_us,
379 1000*1000 / total_us,
380 total_bytes,
381 total_bytes * 1000 / total_us);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200382}
383#else
384#define dsi_perf_mark_setup()
385#define dsi_perf_mark_start()
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200386#define dsi_perf_show(x)
387#endif
388
389static void print_irq_status(u32 status)
390{
391#ifndef VERBOSE_IRQ
392 if ((status & ~DSI_IRQ_CHANNEL_MASK) == 0)
393 return;
394#endif
395 printk(KERN_DEBUG "DSI IRQ: 0x%x: ", status);
396
397#define PIS(x) \
398 if (status & DSI_IRQ_##x) \
399 printk(#x " ");
400#ifdef VERBOSE_IRQ
401 PIS(VC0);
402 PIS(VC1);
403 PIS(VC2);
404 PIS(VC3);
405#endif
406 PIS(WAKEUP);
407 PIS(RESYNC);
408 PIS(PLL_LOCK);
409 PIS(PLL_UNLOCK);
410 PIS(PLL_RECALL);
411 PIS(COMPLEXIO_ERR);
412 PIS(HS_TX_TIMEOUT);
413 PIS(LP_RX_TIMEOUT);
414 PIS(TE_TRIGGER);
415 PIS(ACK_TRIGGER);
416 PIS(SYNC_LOST);
417 PIS(LDO_POWER_GOOD);
418 PIS(TA_TIMEOUT);
419#undef PIS
420
421 printk("\n");
422}
423
424static void print_irq_status_vc(int channel, u32 status)
425{
426#ifndef VERBOSE_IRQ
427 if ((status & ~DSI_VC_IRQ_PACKET_SENT) == 0)
428 return;
429#endif
430 printk(KERN_DEBUG "DSI VC(%d) IRQ 0x%x: ", channel, status);
431
432#define PIS(x) \
433 if (status & DSI_VC_IRQ_##x) \
434 printk(#x " ");
435 PIS(CS);
436 PIS(ECC_CORR);
437#ifdef VERBOSE_IRQ
438 PIS(PACKET_SENT);
439#endif
440 PIS(FIFO_TX_OVF);
441 PIS(FIFO_RX_OVF);
442 PIS(BTA);
443 PIS(ECC_NO_CORR);
444 PIS(FIFO_TX_UDF);
445 PIS(PP_BUSY_CHANGE);
446#undef PIS
447 printk("\n");
448}
449
450static void print_irq_status_cio(u32 status)
451{
452 printk(KERN_DEBUG "DSI CIO IRQ 0x%x: ", status);
453
454#define PIS(x) \
455 if (status & DSI_CIO_IRQ_##x) \
456 printk(#x " ");
457 PIS(ERRSYNCESC1);
458 PIS(ERRSYNCESC2);
459 PIS(ERRSYNCESC3);
460 PIS(ERRESC1);
461 PIS(ERRESC2);
462 PIS(ERRESC3);
463 PIS(ERRCONTROL1);
464 PIS(ERRCONTROL2);
465 PIS(ERRCONTROL3);
466 PIS(STATEULPS1);
467 PIS(STATEULPS2);
468 PIS(STATEULPS3);
469 PIS(ERRCONTENTIONLP0_1);
470 PIS(ERRCONTENTIONLP1_1);
471 PIS(ERRCONTENTIONLP0_2);
472 PIS(ERRCONTENTIONLP1_2);
473 PIS(ERRCONTENTIONLP0_3);
474 PIS(ERRCONTENTIONLP1_3);
475 PIS(ULPSACTIVENOT_ALL0);
476 PIS(ULPSACTIVENOT_ALL1);
477#undef PIS
478
479 printk("\n");
480}
481
482static int debug_irq;
483
484/* called from dss */
archit tanejaaffe3602011-02-23 08:41:03 +0000485static irqreturn_t omap_dsi_irq_handler(int irq, void *arg)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200486{
487 u32 irqstatus, vcstatus, ciostatus;
488 int i;
489
490 irqstatus = dsi_read_reg(DSI_IRQSTATUS);
491
archit tanejaaffe3602011-02-23 08:41:03 +0000492 /* IRQ is not for us */
493 if (!irqstatus)
494 return IRQ_NONE;
495
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200496#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
497 spin_lock(&dsi.irq_stats_lock);
498 dsi.irq_stats.irq_count++;
499 dss_collect_irq_stats(irqstatus, dsi.irq_stats.dsi_irqs);
500#endif
501
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200502 if (irqstatus & DSI_IRQ_ERROR_MASK) {
503 DSSERR("DSI error, irqstatus %x\n", irqstatus);
504 print_irq_status(irqstatus);
505 spin_lock(&dsi.errors_lock);
506 dsi.errors |= irqstatus & DSI_IRQ_ERROR_MASK;
507 spin_unlock(&dsi.errors_lock);
508 } else if (debug_irq) {
509 print_irq_status(irqstatus);
510 }
511
512#ifdef DSI_CATCH_MISSING_TE
513 if (irqstatus & DSI_IRQ_TE_TRIGGER)
514 del_timer(&dsi.te_timer);
515#endif
516
517 for (i = 0; i < 4; ++i) {
518 if ((irqstatus & (1<<i)) == 0)
519 continue;
520
521 vcstatus = dsi_read_reg(DSI_VC_IRQSTATUS(i));
522
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200523#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
524 dss_collect_irq_stats(vcstatus, dsi.irq_stats.vc_irqs[i]);
525#endif
526
Tomi Valkeinenab83b142010-06-09 15:31:01 +0300527 if (vcstatus & DSI_VC_IRQ_BTA) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200528 complete(&dsi.bta_completion);
529
Tomi Valkeinenab83b142010-06-09 15:31:01 +0300530 if (dsi.bta_callback)
531 dsi.bta_callback();
532 }
533
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200534 if (vcstatus & DSI_VC_IRQ_ERROR_MASK) {
535 DSSERR("DSI VC(%d) error, vc irqstatus %x\n",
536 i, vcstatus);
537 print_irq_status_vc(i, vcstatus);
538 } else if (debug_irq) {
539 print_irq_status_vc(i, vcstatus);
540 }
541
542 dsi_write_reg(DSI_VC_IRQSTATUS(i), vcstatus);
543 /* flush posted write */
544 dsi_read_reg(DSI_VC_IRQSTATUS(i));
545 }
546
547 if (irqstatus & DSI_IRQ_COMPLEXIO_ERR) {
548 ciostatus = dsi_read_reg(DSI_COMPLEXIO_IRQ_STATUS);
549
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200550#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
551 dss_collect_irq_stats(ciostatus, dsi.irq_stats.cio_irqs);
552#endif
553
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200554 dsi_write_reg(DSI_COMPLEXIO_IRQ_STATUS, ciostatus);
555 /* flush posted write */
556 dsi_read_reg(DSI_COMPLEXIO_IRQ_STATUS);
557
Tomi Valkeinenbbecb502010-05-10 14:35:33 +0300558 if (ciostatus & DSI_CIO_IRQ_ERROR_MASK) {
559 DSSERR("DSI CIO error, cio irqstatus %x\n", ciostatus);
560 print_irq_status_cio(ciostatus);
561 } else if (debug_irq) {
562 print_irq_status_cio(ciostatus);
563 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200564 }
565
566 dsi_write_reg(DSI_IRQSTATUS, irqstatus & ~DSI_IRQ_CHANNEL_MASK);
567 /* flush posted write */
568 dsi_read_reg(DSI_IRQSTATUS);
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200569
570#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
571 spin_unlock(&dsi.irq_stats_lock);
572#endif
archit tanejaaffe3602011-02-23 08:41:03 +0000573 return IRQ_HANDLED;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200574}
575
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200576static void _dsi_initialize_irq(void)
577{
578 u32 l;
579 int i;
580
581 /* disable all interrupts */
582 dsi_write_reg(DSI_IRQENABLE, 0);
583 for (i = 0; i < 4; ++i)
584 dsi_write_reg(DSI_VC_IRQENABLE(i), 0);
585 dsi_write_reg(DSI_COMPLEXIO_IRQ_ENABLE, 0);
586
587 /* clear interrupt status */
588 l = dsi_read_reg(DSI_IRQSTATUS);
589 dsi_write_reg(DSI_IRQSTATUS, l & ~DSI_IRQ_CHANNEL_MASK);
590
591 for (i = 0; i < 4; ++i) {
592 l = dsi_read_reg(DSI_VC_IRQSTATUS(i));
593 dsi_write_reg(DSI_VC_IRQSTATUS(i), l);
594 }
595
596 l = dsi_read_reg(DSI_COMPLEXIO_IRQ_STATUS);
597 dsi_write_reg(DSI_COMPLEXIO_IRQ_STATUS, l);
598
599 /* enable error irqs */
600 l = DSI_IRQ_ERROR_MASK;
601#ifdef DSI_CATCH_MISSING_TE
602 l |= DSI_IRQ_TE_TRIGGER;
603#endif
604 dsi_write_reg(DSI_IRQENABLE, l);
605
606 l = DSI_VC_IRQ_ERROR_MASK;
607 for (i = 0; i < 4; ++i)
608 dsi_write_reg(DSI_VC_IRQENABLE(i), l);
609
Tomi Valkeinenbbecb502010-05-10 14:35:33 +0300610 l = DSI_CIO_IRQ_ERROR_MASK;
611 dsi_write_reg(DSI_COMPLEXIO_IRQ_ENABLE, l);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200612}
613
614static u32 dsi_get_errors(void)
615{
616 unsigned long flags;
617 u32 e;
618 spin_lock_irqsave(&dsi.errors_lock, flags);
619 e = dsi.errors;
620 dsi.errors = 0;
621 spin_unlock_irqrestore(&dsi.errors_lock, flags);
622 return e;
623}
624
625static void dsi_vc_enable_bta_irq(int channel)
626{
627 u32 l;
628
629 dsi_write_reg(DSI_VC_IRQSTATUS(channel), DSI_VC_IRQ_BTA);
630
631 l = dsi_read_reg(DSI_VC_IRQENABLE(channel));
632 l |= DSI_VC_IRQ_BTA;
633 dsi_write_reg(DSI_VC_IRQENABLE(channel), l);
634}
635
636static void dsi_vc_disable_bta_irq(int channel)
637{
638 u32 l;
639
640 l = dsi_read_reg(DSI_VC_IRQENABLE(channel));
641 l &= ~DSI_VC_IRQ_BTA;
642 dsi_write_reg(DSI_VC_IRQENABLE(channel), l);
643}
644
645/* DSI func clock. this could also be DSI2_PLL_FCLK */
646static inline void enable_clocks(bool enable)
647{
648 if (enable)
Archit Taneja6af9cd12011-01-31 16:27:44 +0000649 dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200650 else
Archit Taneja6af9cd12011-01-31 16:27:44 +0000651 dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200652}
653
654/* source clock for DSI PLL. this could also be PCLKFREE */
655static inline void dsi_enable_pll_clock(bool enable)
656{
657 if (enable)
Archit Taneja6af9cd12011-01-31 16:27:44 +0000658 dss_clk_enable(DSS_CLK_SYSCK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200659 else
Archit Taneja6af9cd12011-01-31 16:27:44 +0000660 dss_clk_disable(DSS_CLK_SYSCK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200661
662 if (enable && dsi.pll_locked) {
663 if (wait_for_bit_change(DSI_PLL_STATUS, 1, 1) != 1)
664 DSSERR("cannot lock PLL when enabling clocks\n");
665 }
666}
667
668#ifdef DEBUG
669static void _dsi_print_reset_status(void)
670{
671 u32 l;
672
673 if (!dss_debug)
674 return;
675
676 /* A dummy read using the SCP interface to any DSIPHY register is
677 * required after DSIPHY reset to complete the reset of the DSI complex
678 * I/O. */
679 l = dsi_read_reg(DSI_DSIPHY_CFG5);
680
681 printk(KERN_DEBUG "DSI resets: ");
682
683 l = dsi_read_reg(DSI_PLL_STATUS);
684 printk("PLL (%d) ", FLD_GET(l, 0, 0));
685
686 l = dsi_read_reg(DSI_COMPLEXIO_CFG1);
687 printk("CIO (%d) ", FLD_GET(l, 29, 29));
688
689 l = dsi_read_reg(DSI_DSIPHY_CFG5);
690 printk("PHY (%x, %d, %d, %d)\n",
691 FLD_GET(l, 28, 26),
692 FLD_GET(l, 29, 29),
693 FLD_GET(l, 30, 30),
694 FLD_GET(l, 31, 31));
695}
696#else
697#define _dsi_print_reset_status()
698#endif
699
700static inline int dsi_if_enable(bool enable)
701{
702 DSSDBG("dsi_if_enable(%d)\n", enable);
703
704 enable = enable ? 1 : 0;
705 REG_FLD_MOD(DSI_CTRL, enable, 0, 0); /* IF_EN */
706
707 if (wait_for_bit_change(DSI_CTRL, 0, enable) != enable) {
708 DSSERR("Failed to set dsi_if_enable to %d\n", enable);
709 return -EIO;
710 }
711
712 return 0;
713}
714
715unsigned long dsi_get_dsi1_pll_rate(void)
716{
717 return dsi.current_cinfo.dsi1_pll_fclk;
718}
719
720static unsigned long dsi_get_dsi2_pll_rate(void)
721{
722 return dsi.current_cinfo.dsi2_pll_fclk;
723}
724
725static unsigned long dsi_get_txbyteclkhs(void)
726{
727 return dsi.current_cinfo.clkin4ddr / 16;
728}
729
730static unsigned long dsi_fclk_rate(void)
731{
732 unsigned long r;
733
Tomi Valkeinen63cf28a2010-02-23 17:40:00 +0200734 if (dss_get_dsi_clk_source() == DSS_SRC_DSS1_ALWON_FCLK) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200735 /* DSI FCLK source is DSS1_ALWON_FCK, which is dss1_fck */
Archit Taneja6af9cd12011-01-31 16:27:44 +0000736 r = dss_clk_get_rate(DSS_CLK_FCK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200737 } else {
738 /* DSI FCLK source is DSI2_PLL_FCLK */
739 r = dsi_get_dsi2_pll_rate();
740 }
741
742 return r;
743}
744
745static int dsi_set_lp_clk_divisor(struct omap_dss_device *dssdev)
746{
747 unsigned long dsi_fclk;
748 unsigned lp_clk_div;
749 unsigned long lp_clk;
750
751 lp_clk_div = dssdev->phy.dsi.div.lp_clk_div;
752
753 if (lp_clk_div == 0 || lp_clk_div > LP_DIV_MAX)
754 return -EINVAL;
755
756 dsi_fclk = dsi_fclk_rate();
757
758 lp_clk = dsi_fclk / 2 / lp_clk_div;
759
760 DSSDBG("LP_CLK_DIV %u, LP_CLK %lu\n", lp_clk_div, lp_clk);
761 dsi.current_cinfo.lp_clk = lp_clk;
762 dsi.current_cinfo.lp_clk_div = lp_clk_div;
763
764 REG_FLD_MOD(DSI_CLK_CTRL, lp_clk_div, 12, 0); /* LP_CLK_DIVISOR */
765
766 REG_FLD_MOD(DSI_CLK_CTRL, dsi_fclk > 30000000 ? 1 : 0,
767 21, 21); /* LP_RX_SYNCHRO_ENABLE */
768
769 return 0;
770}
771
772
773enum dsi_pll_power_state {
774 DSI_PLL_POWER_OFF = 0x0,
775 DSI_PLL_POWER_ON_HSCLK = 0x1,
776 DSI_PLL_POWER_ON_ALL = 0x2,
777 DSI_PLL_POWER_ON_DIV = 0x3,
778};
779
780static int dsi_pll_power(enum dsi_pll_power_state state)
781{
782 int t = 0;
783
784 REG_FLD_MOD(DSI_CLK_CTRL, state, 31, 30); /* PLL_PWR_CMD */
785
786 /* PLL_PWR_STATUS */
787 while (FLD_GET(dsi_read_reg(DSI_CLK_CTRL), 29, 28) != state) {
Tomi Valkeinen24be78b2010-01-07 14:19:48 +0200788 if (++t > 1000) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200789 DSSERR("Failed to set DSI PLL power mode to %d\n",
790 state);
791 return -ENODEV;
792 }
Tomi Valkeinen24be78b2010-01-07 14:19:48 +0200793 udelay(1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200794 }
795
796 return 0;
797}
798
799/* calculate clock rates using dividers in cinfo */
Sumit Semwalff1b2cd2010-12-02 11:27:11 +0000800static int dsi_calc_clock_rates(struct omap_dss_device *dssdev,
801 struct dsi_clock_info *cinfo)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200802{
803 if (cinfo->regn == 0 || cinfo->regn > REGN_MAX)
804 return -EINVAL;
805
806 if (cinfo->regm == 0 || cinfo->regm > REGM_MAX)
807 return -EINVAL;
808
809 if (cinfo->regm3 > REGM3_MAX)
810 return -EINVAL;
811
812 if (cinfo->regm4 > REGM4_MAX)
813 return -EINVAL;
814
815 if (cinfo->use_dss2_fck) {
Archit Taneja6af9cd12011-01-31 16:27:44 +0000816 cinfo->clkin = dss_clk_get_rate(DSS_CLK_SYSCK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200817 /* XXX it is unclear if highfreq should be used
818 * with DSS2_FCK source also */
819 cinfo->highfreq = 0;
820 } else {
Sumit Semwalff1b2cd2010-12-02 11:27:11 +0000821 cinfo->clkin = dispc_pclk_rate(dssdev->manager->id);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200822
823 if (cinfo->clkin < 32000000)
824 cinfo->highfreq = 0;
825 else
826 cinfo->highfreq = 1;
827 }
828
829 cinfo->fint = cinfo->clkin / (cinfo->regn * (cinfo->highfreq ? 2 : 1));
830
831 if (cinfo->fint > FINT_MAX || cinfo->fint < FINT_MIN)
832 return -EINVAL;
833
834 cinfo->clkin4ddr = 2 * cinfo->regm * cinfo->fint;
835
836 if (cinfo->clkin4ddr > 1800 * 1000 * 1000)
837 return -EINVAL;
838
839 if (cinfo->regm3 > 0)
840 cinfo->dsi1_pll_fclk = cinfo->clkin4ddr / cinfo->regm3;
841 else
842 cinfo->dsi1_pll_fclk = 0;
843
844 if (cinfo->regm4 > 0)
845 cinfo->dsi2_pll_fclk = cinfo->clkin4ddr / cinfo->regm4;
846 else
847 cinfo->dsi2_pll_fclk = 0;
848
849 return 0;
850}
851
852int dsi_pll_calc_clock_div_pck(bool is_tft, unsigned long req_pck,
853 struct dsi_clock_info *dsi_cinfo,
854 struct dispc_clock_info *dispc_cinfo)
855{
856 struct dsi_clock_info cur, best;
857 struct dispc_clock_info best_dispc;
858 int min_fck_per_pck;
859 int match = 0;
Archit Taneja819d8072011-03-01 11:54:00 +0530860 unsigned long dss_clk_fck2, max_dss_fck;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200861
Archit Taneja6af9cd12011-01-31 16:27:44 +0000862 dss_clk_fck2 = dss_clk_get_rate(DSS_CLK_SYSCK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200863
Archit Taneja819d8072011-03-01 11:54:00 +0530864 max_dss_fck = dss_feat_get_max_dss_fck();
865
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200866 if (req_pck == dsi.cache_req_pck &&
867 dsi.cache_cinfo.clkin == dss_clk_fck2) {
868 DSSDBG("DSI clock info found from cache\n");
869 *dsi_cinfo = dsi.cache_cinfo;
870 dispc_find_clk_divs(is_tft, req_pck, dsi_cinfo->dsi1_pll_fclk,
871 dispc_cinfo);
872 return 0;
873 }
874
875 min_fck_per_pck = CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK;
876
877 if (min_fck_per_pck &&
Archit Taneja819d8072011-03-01 11:54:00 +0530878 req_pck * min_fck_per_pck > max_dss_fck) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200879 DSSERR("Requested pixel clock not possible with the current "
880 "OMAP2_DSS_MIN_FCK_PER_PCK setting. Turning "
881 "the constraint off.\n");
882 min_fck_per_pck = 0;
883 }
884
885 DSSDBG("dsi_pll_calc\n");
886
887retry:
888 memset(&best, 0, sizeof(best));
889 memset(&best_dispc, 0, sizeof(best_dispc));
890
891 memset(&cur, 0, sizeof(cur));
892 cur.clkin = dss_clk_fck2;
893 cur.use_dss2_fck = 1;
894 cur.highfreq = 0;
895
896 /* no highfreq: 0.75MHz < Fint = clkin / regn < 2.1MHz */
897 /* highfreq: 0.75MHz < Fint = clkin / (2*regn) < 2.1MHz */
898 /* To reduce PLL lock time, keep Fint high (around 2 MHz) */
899 for (cur.regn = 1; cur.regn < REGN_MAX; ++cur.regn) {
900 if (cur.highfreq == 0)
901 cur.fint = cur.clkin / cur.regn;
902 else
903 cur.fint = cur.clkin / (2 * cur.regn);
904
905 if (cur.fint > FINT_MAX || cur.fint < FINT_MIN)
906 continue;
907
908 /* DSIPHY(MHz) = (2 * regm / regn) * (clkin / (highfreq + 1)) */
909 for (cur.regm = 1; cur.regm < REGM_MAX; ++cur.regm) {
910 unsigned long a, b;
911
912 a = 2 * cur.regm * (cur.clkin/1000);
913 b = cur.regn * (cur.highfreq + 1);
914 cur.clkin4ddr = a / b * 1000;
915
916 if (cur.clkin4ddr > 1800 * 1000 * 1000)
917 break;
918
919 /* DSI1_PLL_FCLK(MHz) = DSIPHY(MHz) / regm3 < 173MHz */
920 for (cur.regm3 = 1; cur.regm3 < REGM3_MAX;
921 ++cur.regm3) {
922 struct dispc_clock_info cur_dispc;
923 cur.dsi1_pll_fclk = cur.clkin4ddr / cur.regm3;
924
925 /* this will narrow down the search a bit,
926 * but still give pixclocks below what was
927 * requested */
928 if (cur.dsi1_pll_fclk < req_pck)
929 break;
930
Archit Taneja819d8072011-03-01 11:54:00 +0530931 if (cur.dsi1_pll_fclk > max_dss_fck)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200932 continue;
933
934 if (min_fck_per_pck &&
935 cur.dsi1_pll_fclk <
936 req_pck * min_fck_per_pck)
937 continue;
938
939 match = 1;
940
941 dispc_find_clk_divs(is_tft, req_pck,
942 cur.dsi1_pll_fclk,
943 &cur_dispc);
944
945 if (abs(cur_dispc.pck - req_pck) <
946 abs(best_dispc.pck - req_pck)) {
947 best = cur;
948 best_dispc = cur_dispc;
949
950 if (cur_dispc.pck == req_pck)
951 goto found;
952 }
953 }
954 }
955 }
956found:
957 if (!match) {
958 if (min_fck_per_pck) {
959 DSSERR("Could not find suitable clock settings.\n"
960 "Turning FCK/PCK constraint off and"
961 "trying again.\n");
962 min_fck_per_pck = 0;
963 goto retry;
964 }
965
966 DSSERR("Could not find suitable clock settings.\n");
967
968 return -EINVAL;
969 }
970
971 /* DSI2_PLL_FCLK (regm4) is not used */
972 best.regm4 = 0;
973 best.dsi2_pll_fclk = 0;
974
975 if (dsi_cinfo)
976 *dsi_cinfo = best;
977 if (dispc_cinfo)
978 *dispc_cinfo = best_dispc;
979
980 dsi.cache_req_pck = req_pck;
981 dsi.cache_clk_freq = 0;
982 dsi.cache_cinfo = best;
983
984 return 0;
985}
986
987int dsi_pll_set_clock_div(struct dsi_clock_info *cinfo)
988{
989 int r = 0;
990 u32 l;
991 int f;
992
993 DSSDBGF();
994
995 dsi.current_cinfo.fint = cinfo->fint;
996 dsi.current_cinfo.clkin4ddr = cinfo->clkin4ddr;
997 dsi.current_cinfo.dsi1_pll_fclk = cinfo->dsi1_pll_fclk;
998 dsi.current_cinfo.dsi2_pll_fclk = cinfo->dsi2_pll_fclk;
999
1000 dsi.current_cinfo.regn = cinfo->regn;
1001 dsi.current_cinfo.regm = cinfo->regm;
1002 dsi.current_cinfo.regm3 = cinfo->regm3;
1003 dsi.current_cinfo.regm4 = cinfo->regm4;
1004
1005 DSSDBG("DSI Fint %ld\n", cinfo->fint);
1006
1007 DSSDBG("clkin (%s) rate %ld, highfreq %d\n",
1008 cinfo->use_dss2_fck ? "dss2_fck" : "pclkfree",
1009 cinfo->clkin,
1010 cinfo->highfreq);
1011
1012 /* DSIPHY == CLKIN4DDR */
1013 DSSDBG("CLKIN4DDR = 2 * %d / %d * %lu / %d = %lu\n",
1014 cinfo->regm,
1015 cinfo->regn,
1016 cinfo->clkin,
1017 cinfo->highfreq + 1,
1018 cinfo->clkin4ddr);
1019
1020 DSSDBG("Data rate on 1 DSI lane %ld Mbps\n",
1021 cinfo->clkin4ddr / 1000 / 1000 / 2);
1022
1023 DSSDBG("Clock lane freq %ld Hz\n", cinfo->clkin4ddr / 4);
1024
1025 DSSDBG("regm3 = %d, dsi1_pll_fclk = %lu\n",
1026 cinfo->regm3, cinfo->dsi1_pll_fclk);
1027 DSSDBG("regm4 = %d, dsi2_pll_fclk = %lu\n",
1028 cinfo->regm4, cinfo->dsi2_pll_fclk);
1029
1030 REG_FLD_MOD(DSI_PLL_CONTROL, 0, 0, 0); /* DSI_PLL_AUTOMODE = manual */
1031
1032 l = dsi_read_reg(DSI_PLL_CONFIGURATION1);
1033 l = FLD_MOD(l, 1, 0, 0); /* DSI_PLL_STOPMODE */
1034 l = FLD_MOD(l, cinfo->regn - 1, 7, 1); /* DSI_PLL_REGN */
1035 l = FLD_MOD(l, cinfo->regm, 18, 8); /* DSI_PLL_REGM */
1036 l = FLD_MOD(l, cinfo->regm3 > 0 ? cinfo->regm3 - 1 : 0,
1037 22, 19); /* DSI_CLOCK_DIV */
1038 l = FLD_MOD(l, cinfo->regm4 > 0 ? cinfo->regm4 - 1 : 0,
1039 26, 23); /* DSIPROTO_CLOCK_DIV */
1040 dsi_write_reg(DSI_PLL_CONFIGURATION1, l);
1041
1042 BUG_ON(cinfo->fint < 750000 || cinfo->fint > 2100000);
1043 if (cinfo->fint < 1000000)
1044 f = 0x3;
1045 else if (cinfo->fint < 1250000)
1046 f = 0x4;
1047 else if (cinfo->fint < 1500000)
1048 f = 0x5;
1049 else if (cinfo->fint < 1750000)
1050 f = 0x6;
1051 else
1052 f = 0x7;
1053
1054 l = dsi_read_reg(DSI_PLL_CONFIGURATION2);
1055 l = FLD_MOD(l, f, 4, 1); /* DSI_PLL_FREQSEL */
1056 l = FLD_MOD(l, cinfo->use_dss2_fck ? 0 : 1,
1057 11, 11); /* DSI_PLL_CLKSEL */
1058 l = FLD_MOD(l, cinfo->highfreq,
1059 12, 12); /* DSI_PLL_HIGHFREQ */
1060 l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */
1061 l = FLD_MOD(l, 0, 14, 14); /* DSIPHY_CLKINEN */
1062 l = FLD_MOD(l, 1, 20, 20); /* DSI_HSDIVBYPASS */
1063 dsi_write_reg(DSI_PLL_CONFIGURATION2, l);
1064
1065 REG_FLD_MOD(DSI_PLL_GO, 1, 0, 0); /* DSI_PLL_GO */
1066
1067 if (wait_for_bit_change(DSI_PLL_GO, 0, 0) != 0) {
1068 DSSERR("dsi pll go bit not going down.\n");
1069 r = -EIO;
1070 goto err;
1071 }
1072
1073 if (wait_for_bit_change(DSI_PLL_STATUS, 1, 1) != 1) {
1074 DSSERR("cannot lock PLL\n");
1075 r = -EIO;
1076 goto err;
1077 }
1078
1079 dsi.pll_locked = 1;
1080
1081 l = dsi_read_reg(DSI_PLL_CONFIGURATION2);
1082 l = FLD_MOD(l, 0, 0, 0); /* DSI_PLL_IDLE */
1083 l = FLD_MOD(l, 0, 5, 5); /* DSI_PLL_PLLLPMODE */
1084 l = FLD_MOD(l, 0, 6, 6); /* DSI_PLL_LOWCURRSTBY */
1085 l = FLD_MOD(l, 0, 7, 7); /* DSI_PLL_TIGHTPHASELOCK */
1086 l = FLD_MOD(l, 0, 8, 8); /* DSI_PLL_DRIFTGUARDEN */
1087 l = FLD_MOD(l, 0, 10, 9); /* DSI_PLL_LOCKSEL */
1088 l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */
1089 l = FLD_MOD(l, 1, 14, 14); /* DSIPHY_CLKINEN */
1090 l = FLD_MOD(l, 0, 15, 15); /* DSI_BYPASSEN */
1091 l = FLD_MOD(l, 1, 16, 16); /* DSS_CLOCK_EN */
1092 l = FLD_MOD(l, 0, 17, 17); /* DSS_CLOCK_PWDN */
1093 l = FLD_MOD(l, 1, 18, 18); /* DSI_PROTO_CLOCK_EN */
1094 l = FLD_MOD(l, 0, 19, 19); /* DSI_PROTO_CLOCK_PWDN */
1095 l = FLD_MOD(l, 0, 20, 20); /* DSI_HSDIVBYPASS */
1096 dsi_write_reg(DSI_PLL_CONFIGURATION2, l);
1097
1098 DSSDBG("PLL config done\n");
1099err:
1100 return r;
1101}
1102
1103int dsi_pll_init(struct omap_dss_device *dssdev, bool enable_hsclk,
1104 bool enable_hsdiv)
1105{
1106 int r = 0;
1107 enum dsi_pll_power_state pwstate;
1108
1109 DSSDBG("PLL init\n");
1110
1111 enable_clocks(1);
1112 dsi_enable_pll_clock(1);
1113
1114 r = regulator_enable(dsi.vdds_dsi_reg);
1115 if (r)
1116 goto err0;
1117
1118 /* XXX PLL does not come out of reset without this... */
1119 dispc_pck_free_enable(1);
1120
1121 if (wait_for_bit_change(DSI_PLL_STATUS, 0, 1) != 1) {
1122 DSSERR("PLL not coming out of reset.\n");
1123 r = -ENODEV;
Ville Syrjälä481dfa02010-04-22 22:50:04 +02001124 dispc_pck_free_enable(0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001125 goto err1;
1126 }
1127
1128 /* XXX ... but if left on, we get problems when planes do not
1129 * fill the whole display. No idea about this */
1130 dispc_pck_free_enable(0);
1131
1132 if (enable_hsclk && enable_hsdiv)
1133 pwstate = DSI_PLL_POWER_ON_ALL;
1134 else if (enable_hsclk)
1135 pwstate = DSI_PLL_POWER_ON_HSCLK;
1136 else if (enable_hsdiv)
1137 pwstate = DSI_PLL_POWER_ON_DIV;
1138 else
1139 pwstate = DSI_PLL_POWER_OFF;
1140
1141 r = dsi_pll_power(pwstate);
1142
1143 if (r)
1144 goto err1;
1145
1146 DSSDBG("PLL init done\n");
1147
1148 return 0;
1149err1:
1150 regulator_disable(dsi.vdds_dsi_reg);
1151err0:
1152 enable_clocks(0);
1153 dsi_enable_pll_clock(0);
1154 return r;
1155}
1156
1157void dsi_pll_uninit(void)
1158{
1159 enable_clocks(0);
1160 dsi_enable_pll_clock(0);
1161
1162 dsi.pll_locked = 0;
1163 dsi_pll_power(DSI_PLL_POWER_OFF);
1164 regulator_disable(dsi.vdds_dsi_reg);
1165 DSSDBG("PLL uninit done\n");
1166}
1167
1168void dsi_dump_clocks(struct seq_file *s)
1169{
1170 int clksel;
1171 struct dsi_clock_info *cinfo = &dsi.current_cinfo;
1172
1173 enable_clocks(1);
1174
1175 clksel = REG_GET(DSI_PLL_CONFIGURATION2, 11, 11);
1176
1177 seq_printf(s, "- DSI PLL -\n");
1178
1179 seq_printf(s, "dsi pll source = %s\n",
1180 clksel == 0 ?
1181 "dss2_alwon_fclk" : "pclkfree");
1182
1183 seq_printf(s, "Fint\t\t%-16luregn %u\n", cinfo->fint, cinfo->regn);
1184
1185 seq_printf(s, "CLKIN4DDR\t%-16luregm %u\n",
1186 cinfo->clkin4ddr, cinfo->regm);
1187
1188 seq_printf(s, "dsi1_pll_fck\t%-16luregm3 %u\t(%s)\n",
1189 cinfo->dsi1_pll_fclk,
1190 cinfo->regm3,
Tomi Valkeinen63cf28a2010-02-23 17:40:00 +02001191 dss_get_dispc_clk_source() == DSS_SRC_DSS1_ALWON_FCLK ?
1192 "off" : "on");
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001193
1194 seq_printf(s, "dsi2_pll_fck\t%-16luregm4 %u\t(%s)\n",
1195 cinfo->dsi2_pll_fclk,
1196 cinfo->regm4,
Tomi Valkeinen63cf28a2010-02-23 17:40:00 +02001197 dss_get_dsi_clk_source() == DSS_SRC_DSS1_ALWON_FCLK ?
1198 "off" : "on");
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001199
1200 seq_printf(s, "- DSI -\n");
1201
1202 seq_printf(s, "dsi fclk source = %s\n",
Tomi Valkeinen63cf28a2010-02-23 17:40:00 +02001203 dss_get_dsi_clk_source() == DSS_SRC_DSS1_ALWON_FCLK ?
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001204 "dss1_alwon_fclk" : "dsi2_pll_fclk");
1205
1206 seq_printf(s, "DSI_FCLK\t%lu\n", dsi_fclk_rate());
1207
1208 seq_printf(s, "DDR_CLK\t\t%lu\n",
1209 cinfo->clkin4ddr / 4);
1210
1211 seq_printf(s, "TxByteClkHS\t%lu\n", dsi_get_txbyteclkhs());
1212
1213 seq_printf(s, "LP_CLK\t\t%lu\n", cinfo->lp_clk);
1214
1215 seq_printf(s, "VP_CLK\t\t%lu\n"
1216 "VP_PCLK\t\t%lu\n",
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00001217 dispc_lclk_rate(OMAP_DSS_CHANNEL_LCD),
1218 dispc_pclk_rate(OMAP_DSS_CHANNEL_LCD));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001219
1220 enable_clocks(0);
1221}
1222
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001223#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
1224void dsi_dump_irqs(struct seq_file *s)
1225{
1226 unsigned long flags;
1227 struct dsi_irq_stats stats;
1228
1229 spin_lock_irqsave(&dsi.irq_stats_lock, flags);
1230
1231 stats = dsi.irq_stats;
1232 memset(&dsi.irq_stats, 0, sizeof(dsi.irq_stats));
1233 dsi.irq_stats.last_reset = jiffies;
1234
1235 spin_unlock_irqrestore(&dsi.irq_stats_lock, flags);
1236
1237 seq_printf(s, "period %u ms\n",
1238 jiffies_to_msecs(jiffies - stats.last_reset));
1239
1240 seq_printf(s, "irqs %d\n", stats.irq_count);
1241#define PIS(x) \
1242 seq_printf(s, "%-20s %10d\n", #x, stats.dsi_irqs[ffs(DSI_IRQ_##x)-1]);
1243
1244 seq_printf(s, "-- DSI interrupts --\n");
1245 PIS(VC0);
1246 PIS(VC1);
1247 PIS(VC2);
1248 PIS(VC3);
1249 PIS(WAKEUP);
1250 PIS(RESYNC);
1251 PIS(PLL_LOCK);
1252 PIS(PLL_UNLOCK);
1253 PIS(PLL_RECALL);
1254 PIS(COMPLEXIO_ERR);
1255 PIS(HS_TX_TIMEOUT);
1256 PIS(LP_RX_TIMEOUT);
1257 PIS(TE_TRIGGER);
1258 PIS(ACK_TRIGGER);
1259 PIS(SYNC_LOST);
1260 PIS(LDO_POWER_GOOD);
1261 PIS(TA_TIMEOUT);
1262#undef PIS
1263
1264#define PIS(x) \
1265 seq_printf(s, "%-20s %10d %10d %10d %10d\n", #x, \
1266 stats.vc_irqs[0][ffs(DSI_VC_IRQ_##x)-1], \
1267 stats.vc_irqs[1][ffs(DSI_VC_IRQ_##x)-1], \
1268 stats.vc_irqs[2][ffs(DSI_VC_IRQ_##x)-1], \
1269 stats.vc_irqs[3][ffs(DSI_VC_IRQ_##x)-1]);
1270
1271 seq_printf(s, "-- VC interrupts --\n");
1272 PIS(CS);
1273 PIS(ECC_CORR);
1274 PIS(PACKET_SENT);
1275 PIS(FIFO_TX_OVF);
1276 PIS(FIFO_RX_OVF);
1277 PIS(BTA);
1278 PIS(ECC_NO_CORR);
1279 PIS(FIFO_TX_UDF);
1280 PIS(PP_BUSY_CHANGE);
1281#undef PIS
1282
1283#define PIS(x) \
1284 seq_printf(s, "%-20s %10d\n", #x, \
1285 stats.cio_irqs[ffs(DSI_CIO_IRQ_##x)-1]);
1286
1287 seq_printf(s, "-- CIO interrupts --\n");
1288 PIS(ERRSYNCESC1);
1289 PIS(ERRSYNCESC2);
1290 PIS(ERRSYNCESC3);
1291 PIS(ERRESC1);
1292 PIS(ERRESC2);
1293 PIS(ERRESC3);
1294 PIS(ERRCONTROL1);
1295 PIS(ERRCONTROL2);
1296 PIS(ERRCONTROL3);
1297 PIS(STATEULPS1);
1298 PIS(STATEULPS2);
1299 PIS(STATEULPS3);
1300 PIS(ERRCONTENTIONLP0_1);
1301 PIS(ERRCONTENTIONLP1_1);
1302 PIS(ERRCONTENTIONLP0_2);
1303 PIS(ERRCONTENTIONLP1_2);
1304 PIS(ERRCONTENTIONLP0_3);
1305 PIS(ERRCONTENTIONLP1_3);
1306 PIS(ULPSACTIVENOT_ALL0);
1307 PIS(ULPSACTIVENOT_ALL1);
1308#undef PIS
1309}
1310#endif
1311
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001312void dsi_dump_regs(struct seq_file *s)
1313{
1314#define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dsi_read_reg(r))
1315
Archit Taneja6af9cd12011-01-31 16:27:44 +00001316 dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001317
1318 DUMPREG(DSI_REVISION);
1319 DUMPREG(DSI_SYSCONFIG);
1320 DUMPREG(DSI_SYSSTATUS);
1321 DUMPREG(DSI_IRQSTATUS);
1322 DUMPREG(DSI_IRQENABLE);
1323 DUMPREG(DSI_CTRL);
1324 DUMPREG(DSI_COMPLEXIO_CFG1);
1325 DUMPREG(DSI_COMPLEXIO_IRQ_STATUS);
1326 DUMPREG(DSI_COMPLEXIO_IRQ_ENABLE);
1327 DUMPREG(DSI_CLK_CTRL);
1328 DUMPREG(DSI_TIMING1);
1329 DUMPREG(DSI_TIMING2);
1330 DUMPREG(DSI_VM_TIMING1);
1331 DUMPREG(DSI_VM_TIMING2);
1332 DUMPREG(DSI_VM_TIMING3);
1333 DUMPREG(DSI_CLK_TIMING);
1334 DUMPREG(DSI_TX_FIFO_VC_SIZE);
1335 DUMPREG(DSI_RX_FIFO_VC_SIZE);
1336 DUMPREG(DSI_COMPLEXIO_CFG2);
1337 DUMPREG(DSI_RX_FIFO_VC_FULLNESS);
1338 DUMPREG(DSI_VM_TIMING4);
1339 DUMPREG(DSI_TX_FIFO_VC_EMPTINESS);
1340 DUMPREG(DSI_VM_TIMING5);
1341 DUMPREG(DSI_VM_TIMING6);
1342 DUMPREG(DSI_VM_TIMING7);
1343 DUMPREG(DSI_STOPCLK_TIMING);
1344
1345 DUMPREG(DSI_VC_CTRL(0));
1346 DUMPREG(DSI_VC_TE(0));
1347 DUMPREG(DSI_VC_LONG_PACKET_HEADER(0));
1348 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(0));
1349 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(0));
1350 DUMPREG(DSI_VC_IRQSTATUS(0));
1351 DUMPREG(DSI_VC_IRQENABLE(0));
1352
1353 DUMPREG(DSI_VC_CTRL(1));
1354 DUMPREG(DSI_VC_TE(1));
1355 DUMPREG(DSI_VC_LONG_PACKET_HEADER(1));
1356 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(1));
1357 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(1));
1358 DUMPREG(DSI_VC_IRQSTATUS(1));
1359 DUMPREG(DSI_VC_IRQENABLE(1));
1360
1361 DUMPREG(DSI_VC_CTRL(2));
1362 DUMPREG(DSI_VC_TE(2));
1363 DUMPREG(DSI_VC_LONG_PACKET_HEADER(2));
1364 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(2));
1365 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(2));
1366 DUMPREG(DSI_VC_IRQSTATUS(2));
1367 DUMPREG(DSI_VC_IRQENABLE(2));
1368
1369 DUMPREG(DSI_VC_CTRL(3));
1370 DUMPREG(DSI_VC_TE(3));
1371 DUMPREG(DSI_VC_LONG_PACKET_HEADER(3));
1372 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(3));
1373 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(3));
1374 DUMPREG(DSI_VC_IRQSTATUS(3));
1375 DUMPREG(DSI_VC_IRQENABLE(3));
1376
1377 DUMPREG(DSI_DSIPHY_CFG0);
1378 DUMPREG(DSI_DSIPHY_CFG1);
1379 DUMPREG(DSI_DSIPHY_CFG2);
1380 DUMPREG(DSI_DSIPHY_CFG5);
1381
1382 DUMPREG(DSI_PLL_CONTROL);
1383 DUMPREG(DSI_PLL_STATUS);
1384 DUMPREG(DSI_PLL_GO);
1385 DUMPREG(DSI_PLL_CONFIGURATION1);
1386 DUMPREG(DSI_PLL_CONFIGURATION2);
1387
Archit Taneja6af9cd12011-01-31 16:27:44 +00001388 dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001389#undef DUMPREG
1390}
1391
1392enum dsi_complexio_power_state {
1393 DSI_COMPLEXIO_POWER_OFF = 0x0,
1394 DSI_COMPLEXIO_POWER_ON = 0x1,
1395 DSI_COMPLEXIO_POWER_ULPS = 0x2,
1396};
1397
1398static int dsi_complexio_power(enum dsi_complexio_power_state state)
1399{
1400 int t = 0;
1401
1402 /* PWR_CMD */
1403 REG_FLD_MOD(DSI_COMPLEXIO_CFG1, state, 28, 27);
1404
1405 /* PWR_STATUS */
1406 while (FLD_GET(dsi_read_reg(DSI_COMPLEXIO_CFG1), 26, 25) != state) {
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02001407 if (++t > 1000) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001408 DSSERR("failed to set complexio power state to "
1409 "%d\n", state);
1410 return -ENODEV;
1411 }
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02001412 udelay(1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001413 }
1414
1415 return 0;
1416}
1417
1418static void dsi_complexio_config(struct omap_dss_device *dssdev)
1419{
1420 u32 r;
1421
1422 int clk_lane = dssdev->phy.dsi.clk_lane;
1423 int data1_lane = dssdev->phy.dsi.data1_lane;
1424 int data2_lane = dssdev->phy.dsi.data2_lane;
1425 int clk_pol = dssdev->phy.dsi.clk_pol;
1426 int data1_pol = dssdev->phy.dsi.data1_pol;
1427 int data2_pol = dssdev->phy.dsi.data2_pol;
1428
1429 r = dsi_read_reg(DSI_COMPLEXIO_CFG1);
1430 r = FLD_MOD(r, clk_lane, 2, 0);
1431 r = FLD_MOD(r, clk_pol, 3, 3);
1432 r = FLD_MOD(r, data1_lane, 6, 4);
1433 r = FLD_MOD(r, data1_pol, 7, 7);
1434 r = FLD_MOD(r, data2_lane, 10, 8);
1435 r = FLD_MOD(r, data2_pol, 11, 11);
1436 dsi_write_reg(DSI_COMPLEXIO_CFG1, r);
1437
1438 /* The configuration of the DSI complex I/O (number of data lanes,
1439 position, differential order) should not be changed while
1440 DSS.DSI_CLK_CRTRL[20] LP_CLK_ENABLE bit is set to 1. In order for
1441 the hardware to take into account a new configuration of the complex
1442 I/O (done in DSS.DSI_COMPLEXIO_CFG1 register), it is recommended to
1443 follow this sequence: First set the DSS.DSI_CTRL[0] IF_EN bit to 1,
1444 then reset the DSS.DSI_CTRL[0] IF_EN to 0, then set
1445 DSS.DSI_CLK_CTRL[20] LP_CLK_ENABLE to 1 and finally set again the
1446 DSS.DSI_CTRL[0] IF_EN bit to 1. If the sequence is not followed, the
1447 DSI complex I/O configuration is unknown. */
1448
1449 /*
1450 REG_FLD_MOD(DSI_CTRL, 1, 0, 0);
1451 REG_FLD_MOD(DSI_CTRL, 0, 0, 0);
1452 REG_FLD_MOD(DSI_CLK_CTRL, 1, 20, 20);
1453 REG_FLD_MOD(DSI_CTRL, 1, 0, 0);
1454 */
1455}
1456
1457static inline unsigned ns2ddr(unsigned ns)
1458{
1459 /* convert time in ns to ddr ticks, rounding up */
1460 unsigned long ddr_clk = dsi.current_cinfo.clkin4ddr / 4;
1461 return (ns * (ddr_clk / 1000 / 1000) + 999) / 1000;
1462}
1463
1464static inline unsigned ddr2ns(unsigned ddr)
1465{
1466 unsigned long ddr_clk = dsi.current_cinfo.clkin4ddr / 4;
1467 return ddr * 1000 * 1000 / (ddr_clk / 1000);
1468}
1469
1470static void dsi_complexio_timings(void)
1471{
1472 u32 r;
1473 u32 ths_prepare, ths_prepare_ths_zero, ths_trail, ths_exit;
1474 u32 tlpx_half, tclk_trail, tclk_zero;
1475 u32 tclk_prepare;
1476
1477 /* calculate timings */
1478
1479 /* 1 * DDR_CLK = 2 * UI */
1480
1481 /* min 40ns + 4*UI max 85ns + 6*UI */
1482 ths_prepare = ns2ddr(70) + 2;
1483
1484 /* min 145ns + 10*UI */
1485 ths_prepare_ths_zero = ns2ddr(175) + 2;
1486
1487 /* min max(8*UI, 60ns+4*UI) */
1488 ths_trail = ns2ddr(60) + 5;
1489
1490 /* min 100ns */
1491 ths_exit = ns2ddr(145);
1492
1493 /* tlpx min 50n */
1494 tlpx_half = ns2ddr(25);
1495
1496 /* min 60ns */
1497 tclk_trail = ns2ddr(60) + 2;
1498
1499 /* min 38ns, max 95ns */
1500 tclk_prepare = ns2ddr(65);
1501
1502 /* min tclk-prepare + tclk-zero = 300ns */
1503 tclk_zero = ns2ddr(260);
1504
1505 DSSDBG("ths_prepare %u (%uns), ths_prepare_ths_zero %u (%uns)\n",
1506 ths_prepare, ddr2ns(ths_prepare),
1507 ths_prepare_ths_zero, ddr2ns(ths_prepare_ths_zero));
1508 DSSDBG("ths_trail %u (%uns), ths_exit %u (%uns)\n",
1509 ths_trail, ddr2ns(ths_trail),
1510 ths_exit, ddr2ns(ths_exit));
1511
1512 DSSDBG("tlpx_half %u (%uns), tclk_trail %u (%uns), "
1513 "tclk_zero %u (%uns)\n",
1514 tlpx_half, ddr2ns(tlpx_half),
1515 tclk_trail, ddr2ns(tclk_trail),
1516 tclk_zero, ddr2ns(tclk_zero));
1517 DSSDBG("tclk_prepare %u (%uns)\n",
1518 tclk_prepare, ddr2ns(tclk_prepare));
1519
1520 /* program timings */
1521
1522 r = dsi_read_reg(DSI_DSIPHY_CFG0);
1523 r = FLD_MOD(r, ths_prepare, 31, 24);
1524 r = FLD_MOD(r, ths_prepare_ths_zero, 23, 16);
1525 r = FLD_MOD(r, ths_trail, 15, 8);
1526 r = FLD_MOD(r, ths_exit, 7, 0);
1527 dsi_write_reg(DSI_DSIPHY_CFG0, r);
1528
1529 r = dsi_read_reg(DSI_DSIPHY_CFG1);
1530 r = FLD_MOD(r, tlpx_half, 22, 16);
1531 r = FLD_MOD(r, tclk_trail, 15, 8);
1532 r = FLD_MOD(r, tclk_zero, 7, 0);
1533 dsi_write_reg(DSI_DSIPHY_CFG1, r);
1534
1535 r = dsi_read_reg(DSI_DSIPHY_CFG2);
1536 r = FLD_MOD(r, tclk_prepare, 7, 0);
1537 dsi_write_reg(DSI_DSIPHY_CFG2, r);
1538}
1539
1540
1541static int dsi_complexio_init(struct omap_dss_device *dssdev)
1542{
1543 int r = 0;
1544
1545 DSSDBG("dsi_complexio_init\n");
1546
1547 /* CIO_CLK_ICG, enable L3 clk to CIO */
1548 REG_FLD_MOD(DSI_CLK_CTRL, 1, 14, 14);
1549
1550 /* A dummy read using the SCP interface to any DSIPHY register is
1551 * required after DSIPHY reset to complete the reset of the DSI complex
1552 * I/O. */
1553 dsi_read_reg(DSI_DSIPHY_CFG5);
1554
1555 if (wait_for_bit_change(DSI_DSIPHY_CFG5, 30, 1) != 1) {
1556 DSSERR("ComplexIO PHY not coming out of reset.\n");
1557 r = -ENODEV;
1558 goto err;
1559 }
1560
1561 dsi_complexio_config(dssdev);
1562
1563 r = dsi_complexio_power(DSI_COMPLEXIO_POWER_ON);
1564
1565 if (r)
1566 goto err;
1567
1568 if (wait_for_bit_change(DSI_COMPLEXIO_CFG1, 29, 1) != 1) {
1569 DSSERR("ComplexIO not coming out of reset.\n");
1570 r = -ENODEV;
1571 goto err;
1572 }
1573
1574 if (wait_for_bit_change(DSI_COMPLEXIO_CFG1, 21, 1) != 1) {
1575 DSSERR("ComplexIO LDO power down.\n");
1576 r = -ENODEV;
1577 goto err;
1578 }
1579
1580 dsi_complexio_timings();
1581
1582 /*
1583 The configuration of the DSI complex I/O (number of data lanes,
1584 position, differential order) should not be changed while
1585 DSS.DSI_CLK_CRTRL[20] LP_CLK_ENABLE bit is set to 1. For the
1586 hardware to recognize a new configuration of the complex I/O (done
1587 in DSS.DSI_COMPLEXIO_CFG1 register), it is recommended to follow
1588 this sequence: First set the DSS.DSI_CTRL[0] IF_EN bit to 1, next
1589 reset the DSS.DSI_CTRL[0] IF_EN to 0, then set DSS.DSI_CLK_CTRL[20]
1590 LP_CLK_ENABLE to 1, and finally, set again the DSS.DSI_CTRL[0] IF_EN
1591 bit to 1. If the sequence is not followed, the DSi complex I/O
1592 configuration is undetermined.
1593 */
1594 dsi_if_enable(1);
1595 dsi_if_enable(0);
1596 REG_FLD_MOD(DSI_CLK_CTRL, 1, 20, 20); /* LP_CLK_ENABLE */
1597 dsi_if_enable(1);
1598 dsi_if_enable(0);
1599
1600 DSSDBG("CIO init done\n");
1601err:
1602 return r;
1603}
1604
1605static void dsi_complexio_uninit(void)
1606{
1607 dsi_complexio_power(DSI_COMPLEXIO_POWER_OFF);
1608}
1609
1610static int _dsi_wait_reset(void)
1611{
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02001612 int t = 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001613
1614 while (REG_GET(DSI_SYSSTATUS, 0, 0) == 0) {
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02001615 if (++t > 5) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001616 DSSERR("soft reset failed\n");
1617 return -ENODEV;
1618 }
1619 udelay(1);
1620 }
1621
1622 return 0;
1623}
1624
1625static int _dsi_reset(void)
1626{
1627 /* Soft reset */
1628 REG_FLD_MOD(DSI_SYSCONFIG, 1, 1, 1);
1629 return _dsi_wait_reset();
1630}
1631
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001632static void dsi_config_tx_fifo(enum fifo_size size1, enum fifo_size size2,
1633 enum fifo_size size3, enum fifo_size size4)
1634{
1635 u32 r = 0;
1636 int add = 0;
1637 int i;
1638
1639 dsi.vc[0].fifo_size = size1;
1640 dsi.vc[1].fifo_size = size2;
1641 dsi.vc[2].fifo_size = size3;
1642 dsi.vc[3].fifo_size = size4;
1643
1644 for (i = 0; i < 4; i++) {
1645 u8 v;
1646 int size = dsi.vc[i].fifo_size;
1647
1648 if (add + size > 4) {
1649 DSSERR("Illegal FIFO configuration\n");
1650 BUG();
1651 }
1652
1653 v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
1654 r |= v << (8 * i);
1655 /*DSSDBG("TX FIFO vc %d: size %d, add %d\n", i, size, add); */
1656 add += size;
1657 }
1658
1659 dsi_write_reg(DSI_TX_FIFO_VC_SIZE, r);
1660}
1661
1662static void dsi_config_rx_fifo(enum fifo_size size1, enum fifo_size size2,
1663 enum fifo_size size3, enum fifo_size size4)
1664{
1665 u32 r = 0;
1666 int add = 0;
1667 int i;
1668
1669 dsi.vc[0].fifo_size = size1;
1670 dsi.vc[1].fifo_size = size2;
1671 dsi.vc[2].fifo_size = size3;
1672 dsi.vc[3].fifo_size = size4;
1673
1674 for (i = 0; i < 4; i++) {
1675 u8 v;
1676 int size = dsi.vc[i].fifo_size;
1677
1678 if (add + size > 4) {
1679 DSSERR("Illegal FIFO configuration\n");
1680 BUG();
1681 }
1682
1683 v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
1684 r |= v << (8 * i);
1685 /*DSSDBG("RX FIFO vc %d: size %d, add %d\n", i, size, add); */
1686 add += size;
1687 }
1688
1689 dsi_write_reg(DSI_RX_FIFO_VC_SIZE, r);
1690}
1691
1692static int dsi_force_tx_stop_mode_io(void)
1693{
1694 u32 r;
1695
1696 r = dsi_read_reg(DSI_TIMING1);
1697 r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
1698 dsi_write_reg(DSI_TIMING1, r);
1699
1700 if (wait_for_bit_change(DSI_TIMING1, 15, 0) != 0) {
1701 DSSERR("TX_STOP bit not going down\n");
1702 return -EIO;
1703 }
1704
1705 return 0;
1706}
1707
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001708static int dsi_vc_enable(int channel, bool enable)
1709{
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +02001710 DSSDBG("dsi_vc_enable channel %d, enable %d\n",
1711 channel, enable);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001712
1713 enable = enable ? 1 : 0;
1714
1715 REG_FLD_MOD(DSI_VC_CTRL(channel), enable, 0, 0);
1716
1717 if (wait_for_bit_change(DSI_VC_CTRL(channel), 0, enable) != enable) {
1718 DSSERR("Failed to set dsi_vc_enable to %d\n", enable);
1719 return -EIO;
1720 }
1721
1722 return 0;
1723}
1724
1725static void dsi_vc_initial_config(int channel)
1726{
1727 u32 r;
1728
1729 DSSDBGF("%d", channel);
1730
1731 r = dsi_read_reg(DSI_VC_CTRL(channel));
1732
1733 if (FLD_GET(r, 15, 15)) /* VC_BUSY */
1734 DSSERR("VC(%d) busy when trying to configure it!\n",
1735 channel);
1736
1737 r = FLD_MOD(r, 0, 1, 1); /* SOURCE, 0 = L4 */
1738 r = FLD_MOD(r, 0, 2, 2); /* BTA_SHORT_EN */
1739 r = FLD_MOD(r, 0, 3, 3); /* BTA_LONG_EN */
1740 r = FLD_MOD(r, 0, 4, 4); /* MODE, 0 = command */
1741 r = FLD_MOD(r, 1, 7, 7); /* CS_TX_EN */
1742 r = FLD_MOD(r, 1, 8, 8); /* ECC_TX_EN */
1743 r = FLD_MOD(r, 0, 9, 9); /* MODE_SPEED, high speed on/off */
1744
1745 r = FLD_MOD(r, 4, 29, 27); /* DMA_RX_REQ_NB = no dma */
1746 r = FLD_MOD(r, 4, 23, 21); /* DMA_TX_REQ_NB = no dma */
1747
1748 dsi_write_reg(DSI_VC_CTRL(channel), r);
1749
1750 dsi.vc[channel].mode = DSI_VC_MODE_L4;
1751}
1752
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03001753static int dsi_vc_config_l4(int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001754{
1755 if (dsi.vc[channel].mode == DSI_VC_MODE_L4)
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03001756 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001757
1758 DSSDBGF("%d", channel);
1759
1760 dsi_vc_enable(channel, 0);
1761
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03001762 /* VC_BUSY */
1763 if (wait_for_bit_change(DSI_VC_CTRL(channel), 15, 0) != 0) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001764 DSSERR("vc(%d) busy when trying to config for L4\n", channel);
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03001765 return -EIO;
1766 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001767
1768 REG_FLD_MOD(DSI_VC_CTRL(channel), 0, 1, 1); /* SOURCE, 0 = L4 */
1769
1770 dsi_vc_enable(channel, 1);
1771
1772 dsi.vc[channel].mode = DSI_VC_MODE_L4;
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03001773
1774 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001775}
1776
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03001777static int dsi_vc_config_vp(int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001778{
1779 if (dsi.vc[channel].mode == DSI_VC_MODE_VP)
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03001780 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001781
1782 DSSDBGF("%d", channel);
1783
1784 dsi_vc_enable(channel, 0);
1785
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03001786 /* VC_BUSY */
1787 if (wait_for_bit_change(DSI_VC_CTRL(channel), 15, 0) != 0) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001788 DSSERR("vc(%d) busy when trying to config for VP\n", channel);
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03001789 return -EIO;
1790 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001791
1792 REG_FLD_MOD(DSI_VC_CTRL(channel), 1, 1, 1); /* SOURCE, 1 = video port */
1793
1794 dsi_vc_enable(channel, 1);
1795
1796 dsi.vc[channel].mode = DSI_VC_MODE_VP;
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03001797
1798 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001799}
1800
1801
Tomi Valkeinen61140c92010-01-12 16:00:30 +02001802void omapdss_dsi_vc_enable_hs(int channel, bool enable)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001803{
1804 DSSDBG("dsi_vc_enable_hs(%d, %d)\n", channel, enable);
1805
Tomi Valkeinen61140c92010-01-12 16:00:30 +02001806 WARN_ON(!dsi_bus_is_locked());
1807
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001808 dsi_vc_enable(channel, 0);
1809 dsi_if_enable(0);
1810
1811 REG_FLD_MOD(DSI_VC_CTRL(channel), enable, 9, 9);
1812
1813 dsi_vc_enable(channel, 1);
1814 dsi_if_enable(1);
1815
1816 dsi_force_tx_stop_mode_io();
1817}
Tomi Valkeinen61140c92010-01-12 16:00:30 +02001818EXPORT_SYMBOL(omapdss_dsi_vc_enable_hs);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001819
1820static void dsi_vc_flush_long_data(int channel)
1821{
1822 while (REG_GET(DSI_VC_CTRL(channel), 20, 20)) {
1823 u32 val;
1824 val = dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel));
1825 DSSDBG("\t\tb1 %#02x b2 %#02x b3 %#02x b4 %#02x\n",
1826 (val >> 0) & 0xff,
1827 (val >> 8) & 0xff,
1828 (val >> 16) & 0xff,
1829 (val >> 24) & 0xff);
1830 }
1831}
1832
1833static void dsi_show_rx_ack_with_err(u16 err)
1834{
1835 DSSERR("\tACK with ERROR (%#x):\n", err);
1836 if (err & (1 << 0))
1837 DSSERR("\t\tSoT Error\n");
1838 if (err & (1 << 1))
1839 DSSERR("\t\tSoT Sync Error\n");
1840 if (err & (1 << 2))
1841 DSSERR("\t\tEoT Sync Error\n");
1842 if (err & (1 << 3))
1843 DSSERR("\t\tEscape Mode Entry Command Error\n");
1844 if (err & (1 << 4))
1845 DSSERR("\t\tLP Transmit Sync Error\n");
1846 if (err & (1 << 5))
1847 DSSERR("\t\tHS Receive Timeout Error\n");
1848 if (err & (1 << 6))
1849 DSSERR("\t\tFalse Control Error\n");
1850 if (err & (1 << 7))
1851 DSSERR("\t\t(reserved7)\n");
1852 if (err & (1 << 8))
1853 DSSERR("\t\tECC Error, single-bit (corrected)\n");
1854 if (err & (1 << 9))
1855 DSSERR("\t\tECC Error, multi-bit (not corrected)\n");
1856 if (err & (1 << 10))
1857 DSSERR("\t\tChecksum Error\n");
1858 if (err & (1 << 11))
1859 DSSERR("\t\tData type not recognized\n");
1860 if (err & (1 << 12))
1861 DSSERR("\t\tInvalid VC ID\n");
1862 if (err & (1 << 13))
1863 DSSERR("\t\tInvalid Transmission Length\n");
1864 if (err & (1 << 14))
1865 DSSERR("\t\t(reserved14)\n");
1866 if (err & (1 << 15))
1867 DSSERR("\t\tDSI Protocol Violation\n");
1868}
1869
1870static u16 dsi_vc_flush_receive_data(int channel)
1871{
1872 /* RX_FIFO_NOT_EMPTY */
1873 while (REG_GET(DSI_VC_CTRL(channel), 20, 20)) {
1874 u32 val;
1875 u8 dt;
1876 val = dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel));
Tomi Valkeinen86a78672010-03-16 16:19:06 +02001877 DSSERR("\trawval %#08x\n", val);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001878 dt = FLD_GET(val, 5, 0);
1879 if (dt == DSI_DT_RX_ACK_WITH_ERR) {
1880 u16 err = FLD_GET(val, 23, 8);
1881 dsi_show_rx_ack_with_err(err);
1882 } else if (dt == DSI_DT_RX_SHORT_READ_1) {
Tomi Valkeinen86a78672010-03-16 16:19:06 +02001883 DSSERR("\tDCS short response, 1 byte: %#x\n",
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001884 FLD_GET(val, 23, 8));
1885 } else if (dt == DSI_DT_RX_SHORT_READ_2) {
Tomi Valkeinen86a78672010-03-16 16:19:06 +02001886 DSSERR("\tDCS short response, 2 byte: %#x\n",
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001887 FLD_GET(val, 23, 8));
1888 } else if (dt == DSI_DT_RX_DCS_LONG_READ) {
Tomi Valkeinen86a78672010-03-16 16:19:06 +02001889 DSSERR("\tDCS long response, len %d\n",
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001890 FLD_GET(val, 23, 8));
1891 dsi_vc_flush_long_data(channel);
1892 } else {
1893 DSSERR("\tunknown datatype 0x%02x\n", dt);
1894 }
1895 }
1896 return 0;
1897}
1898
1899static int dsi_vc_send_bta(int channel)
1900{
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +02001901 if (dsi.debug_write || dsi.debug_read)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001902 DSSDBG("dsi_vc_send_bta %d\n", channel);
1903
Tomi Valkeinen4f765022010-01-18 16:27:52 +02001904 WARN_ON(!dsi_bus_is_locked());
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001905
1906 if (REG_GET(DSI_VC_CTRL(channel), 20, 20)) { /* RX_FIFO_NOT_EMPTY */
1907 DSSERR("rx fifo not empty when sending BTA, dumping data:\n");
1908 dsi_vc_flush_receive_data(channel);
1909 }
1910
1911 REG_FLD_MOD(DSI_VC_CTRL(channel), 1, 6, 6); /* BTA_EN */
1912
1913 return 0;
1914}
1915
1916int dsi_vc_send_bta_sync(int channel)
1917{
1918 int r = 0;
1919 u32 err;
1920
1921 INIT_COMPLETION(dsi.bta_completion);
1922
1923 dsi_vc_enable_bta_irq(channel);
1924
1925 r = dsi_vc_send_bta(channel);
1926 if (r)
1927 goto err;
1928
1929 if (wait_for_completion_timeout(&dsi.bta_completion,
1930 msecs_to_jiffies(500)) == 0) {
1931 DSSERR("Failed to receive BTA\n");
1932 r = -EIO;
1933 goto err;
1934 }
1935
1936 err = dsi_get_errors();
1937 if (err) {
1938 DSSERR("Error while sending BTA: %x\n", err);
1939 r = -EIO;
1940 goto err;
1941 }
1942err:
1943 dsi_vc_disable_bta_irq(channel);
1944
1945 return r;
1946}
1947EXPORT_SYMBOL(dsi_vc_send_bta_sync);
1948
1949static inline void dsi_vc_write_long_header(int channel, u8 data_type,
1950 u16 len, u8 ecc)
1951{
1952 u32 val;
1953 u8 data_id;
1954
Tomi Valkeinen4f765022010-01-18 16:27:52 +02001955 WARN_ON(!dsi_bus_is_locked());
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001956
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02001957 data_id = data_type | channel << 6;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001958
1959 val = FLD_VAL(data_id, 7, 0) | FLD_VAL(len, 23, 8) |
1960 FLD_VAL(ecc, 31, 24);
1961
1962 dsi_write_reg(DSI_VC_LONG_PACKET_HEADER(channel), val);
1963}
1964
1965static inline void dsi_vc_write_long_payload(int channel,
1966 u8 b1, u8 b2, u8 b3, u8 b4)
1967{
1968 u32 val;
1969
1970 val = b4 << 24 | b3 << 16 | b2 << 8 | b1 << 0;
1971
1972/* DSSDBG("\twriting %02x, %02x, %02x, %02x (%#010x)\n",
1973 b1, b2, b3, b4, val); */
1974
1975 dsi_write_reg(DSI_VC_LONG_PACKET_PAYLOAD(channel), val);
1976}
1977
1978static int dsi_vc_send_long(int channel, u8 data_type, u8 *data, u16 len,
1979 u8 ecc)
1980{
1981 /*u32 val; */
1982 int i;
1983 u8 *p;
1984 int r = 0;
1985 u8 b1, b2, b3, b4;
1986
1987 if (dsi.debug_write)
1988 DSSDBG("dsi_vc_send_long, %d bytes\n", len);
1989
1990 /* len + header */
1991 if (dsi.vc[channel].fifo_size * 32 * 4 < len + 4) {
1992 DSSERR("unable to send long packet: packet too long.\n");
1993 return -EINVAL;
1994 }
1995
1996 dsi_vc_config_l4(channel);
1997
1998 dsi_vc_write_long_header(channel, data_type, len, ecc);
1999
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002000 p = data;
2001 for (i = 0; i < len >> 2; i++) {
2002 if (dsi.debug_write)
2003 DSSDBG("\tsending full packet %d\n", i);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002004
2005 b1 = *p++;
2006 b2 = *p++;
2007 b3 = *p++;
2008 b4 = *p++;
2009
2010 dsi_vc_write_long_payload(channel, b1, b2, b3, b4);
2011 }
2012
2013 i = len % 4;
2014 if (i) {
2015 b1 = 0; b2 = 0; b3 = 0;
2016
2017 if (dsi.debug_write)
2018 DSSDBG("\tsending remainder bytes %d\n", i);
2019
2020 switch (i) {
2021 case 3:
2022 b1 = *p++;
2023 b2 = *p++;
2024 b3 = *p++;
2025 break;
2026 case 2:
2027 b1 = *p++;
2028 b2 = *p++;
2029 break;
2030 case 1:
2031 b1 = *p++;
2032 break;
2033 }
2034
2035 dsi_vc_write_long_payload(channel, b1, b2, b3, 0);
2036 }
2037
2038 return r;
2039}
2040
2041static int dsi_vc_send_short(int channel, u8 data_type, u16 data, u8 ecc)
2042{
2043 u32 r;
2044 u8 data_id;
2045
Tomi Valkeinen4f765022010-01-18 16:27:52 +02002046 WARN_ON(!dsi_bus_is_locked());
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002047
2048 if (dsi.debug_write)
2049 DSSDBG("dsi_vc_send_short(ch%d, dt %#x, b1 %#x, b2 %#x)\n",
2050 channel,
2051 data_type, data & 0xff, (data >> 8) & 0xff);
2052
2053 dsi_vc_config_l4(channel);
2054
2055 if (FLD_GET(dsi_read_reg(DSI_VC_CTRL(channel)), 16, 16)) {
2056 DSSERR("ERROR FIFO FULL, aborting transfer\n");
2057 return -EINVAL;
2058 }
2059
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02002060 data_id = data_type | channel << 6;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002061
2062 r = (data_id << 0) | (data << 8) | (ecc << 24);
2063
2064 dsi_write_reg(DSI_VC_SHORT_PACKET_HEADER(channel), r);
2065
2066 return 0;
2067}
2068
2069int dsi_vc_send_null(int channel)
2070{
2071 u8 nullpkg[] = {0, 0, 0, 0};
Tomi Valkeinen397bb3c2009-12-03 13:37:31 +02002072 return dsi_vc_send_long(channel, DSI_DT_NULL_PACKET, nullpkg, 4, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002073}
2074EXPORT_SYMBOL(dsi_vc_send_null);
2075
2076int dsi_vc_dcs_write_nosync(int channel, u8 *data, int len)
2077{
2078 int r;
2079
2080 BUG_ON(len == 0);
2081
2082 if (len == 1) {
2083 r = dsi_vc_send_short(channel, DSI_DT_DCS_SHORT_WRITE_0,
2084 data[0], 0);
2085 } else if (len == 2) {
2086 r = dsi_vc_send_short(channel, DSI_DT_DCS_SHORT_WRITE_1,
2087 data[0] | (data[1] << 8), 0);
2088 } else {
2089 /* 0x39 = DCS Long Write */
2090 r = dsi_vc_send_long(channel, DSI_DT_DCS_LONG_WRITE,
2091 data, len, 0);
2092 }
2093
2094 return r;
2095}
2096EXPORT_SYMBOL(dsi_vc_dcs_write_nosync);
2097
2098int dsi_vc_dcs_write(int channel, u8 *data, int len)
2099{
2100 int r;
2101
2102 r = dsi_vc_dcs_write_nosync(channel, data, len);
2103 if (r)
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002104 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002105
2106 r = dsi_vc_send_bta_sync(channel);
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002107 if (r)
2108 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002109
Tomi Valkeinenb63ac1e2010-04-09 13:20:57 +03002110 if (REG_GET(DSI_VC_CTRL(channel), 20, 20)) { /* RX_FIFO_NOT_EMPTY */
2111 DSSERR("rx fifo not empty after write, dumping data:\n");
2112 dsi_vc_flush_receive_data(channel);
2113 r = -EIO;
2114 goto err;
2115 }
2116
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002117 return 0;
2118err:
2119 DSSERR("dsi_vc_dcs_write(ch %d, cmd 0x%02x, len %d) failed\n",
2120 channel, data[0], len);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002121 return r;
2122}
2123EXPORT_SYMBOL(dsi_vc_dcs_write);
2124
Tomi Valkeinen828c48f2009-12-16 14:53:15 +02002125int dsi_vc_dcs_write_0(int channel, u8 dcs_cmd)
2126{
2127 return dsi_vc_dcs_write(channel, &dcs_cmd, 1);
2128}
2129EXPORT_SYMBOL(dsi_vc_dcs_write_0);
2130
2131int dsi_vc_dcs_write_1(int channel, u8 dcs_cmd, u8 param)
2132{
2133 u8 buf[2];
2134 buf[0] = dcs_cmd;
2135 buf[1] = param;
2136 return dsi_vc_dcs_write(channel, buf, 2);
2137}
2138EXPORT_SYMBOL(dsi_vc_dcs_write_1);
2139
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002140int dsi_vc_dcs_read(int channel, u8 dcs_cmd, u8 *buf, int buflen)
2141{
2142 u32 val;
2143 u8 dt;
2144 int r;
2145
2146 if (dsi.debug_read)
Tomi Valkeinenff90a342009-12-03 13:38:04 +02002147 DSSDBG("dsi_vc_dcs_read(ch%d, dcs_cmd %x)\n", channel, dcs_cmd);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002148
2149 r = dsi_vc_send_short(channel, DSI_DT_DCS_READ, dcs_cmd, 0);
2150 if (r)
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002151 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002152
2153 r = dsi_vc_send_bta_sync(channel);
2154 if (r)
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002155 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002156
2157 /* RX_FIFO_NOT_EMPTY */
2158 if (REG_GET(DSI_VC_CTRL(channel), 20, 20) == 0) {
2159 DSSERR("RX fifo empty when trying to read.\n");
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002160 r = -EIO;
2161 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002162 }
2163
2164 val = dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel));
2165 if (dsi.debug_read)
2166 DSSDBG("\theader: %08x\n", val);
2167 dt = FLD_GET(val, 5, 0);
2168 if (dt == DSI_DT_RX_ACK_WITH_ERR) {
2169 u16 err = FLD_GET(val, 23, 8);
2170 dsi_show_rx_ack_with_err(err);
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002171 r = -EIO;
2172 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002173
2174 } else if (dt == DSI_DT_RX_SHORT_READ_1) {
2175 u8 data = FLD_GET(val, 15, 8);
2176 if (dsi.debug_read)
2177 DSSDBG("\tDCS short response, 1 byte: %02x\n", data);
2178
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002179 if (buflen < 1) {
2180 r = -EIO;
2181 goto err;
2182 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002183
2184 buf[0] = data;
2185
2186 return 1;
2187 } else if (dt == DSI_DT_RX_SHORT_READ_2) {
2188 u16 data = FLD_GET(val, 23, 8);
2189 if (dsi.debug_read)
2190 DSSDBG("\tDCS short response, 2 byte: %04x\n", data);
2191
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002192 if (buflen < 2) {
2193 r = -EIO;
2194 goto err;
2195 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002196
2197 buf[0] = data & 0xff;
2198 buf[1] = (data >> 8) & 0xff;
2199
2200 return 2;
2201 } else if (dt == DSI_DT_RX_DCS_LONG_READ) {
2202 int w;
2203 int len = FLD_GET(val, 23, 8);
2204 if (dsi.debug_read)
2205 DSSDBG("\tDCS long response, len %d\n", len);
2206
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002207 if (len > buflen) {
2208 r = -EIO;
2209 goto err;
2210 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002211
2212 /* two byte checksum ends the packet, not included in len */
2213 for (w = 0; w < len + 2;) {
2214 int b;
2215 val = dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel));
2216 if (dsi.debug_read)
2217 DSSDBG("\t\t%02x %02x %02x %02x\n",
2218 (val >> 0) & 0xff,
2219 (val >> 8) & 0xff,
2220 (val >> 16) & 0xff,
2221 (val >> 24) & 0xff);
2222
2223 for (b = 0; b < 4; ++b) {
2224 if (w < len)
2225 buf[w] = (val >> (b * 8)) & 0xff;
2226 /* we discard the 2 byte checksum */
2227 ++w;
2228 }
2229 }
2230
2231 return len;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002232 } else {
2233 DSSERR("\tunknown datatype 0x%02x\n", dt);
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002234 r = -EIO;
2235 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002236 }
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002237
2238 BUG();
2239err:
2240 DSSERR("dsi_vc_dcs_read(ch %d, cmd 0x%02x) failed\n",
2241 channel, dcs_cmd);
2242 return r;
2243
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002244}
2245EXPORT_SYMBOL(dsi_vc_dcs_read);
2246
Tomi Valkeinen828c48f2009-12-16 14:53:15 +02002247int dsi_vc_dcs_read_1(int channel, u8 dcs_cmd, u8 *data)
2248{
2249 int r;
2250
2251 r = dsi_vc_dcs_read(channel, dcs_cmd, data, 1);
2252
2253 if (r < 0)
2254 return r;
2255
2256 if (r != 1)
2257 return -EIO;
2258
2259 return 0;
2260}
2261EXPORT_SYMBOL(dsi_vc_dcs_read_1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002262
Tomi Valkeinen0c244f72010-06-09 15:19:29 +03002263int dsi_vc_dcs_read_2(int channel, u8 dcs_cmd, u8 *data1, u8 *data2)
Tomi Valkeinen53055aa2010-02-25 11:38:13 +02002264{
Tomi Valkeinen0c244f72010-06-09 15:19:29 +03002265 u8 buf[2];
Tomi Valkeinen53055aa2010-02-25 11:38:13 +02002266 int r;
2267
Tomi Valkeinen0c244f72010-06-09 15:19:29 +03002268 r = dsi_vc_dcs_read(channel, dcs_cmd, buf, 2);
Tomi Valkeinen53055aa2010-02-25 11:38:13 +02002269
2270 if (r < 0)
2271 return r;
2272
2273 if (r != 2)
2274 return -EIO;
2275
Tomi Valkeinen0c244f72010-06-09 15:19:29 +03002276 *data1 = buf[0];
2277 *data2 = buf[1];
2278
Tomi Valkeinen53055aa2010-02-25 11:38:13 +02002279 return 0;
2280}
2281EXPORT_SYMBOL(dsi_vc_dcs_read_2);
2282
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002283int dsi_vc_set_max_rx_packet_size(int channel, u16 len)
2284{
Tomi Valkeinenfa15c792010-05-14 17:42:07 +03002285 return dsi_vc_send_short(channel, DSI_DT_SET_MAX_RET_PKG_SIZE,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002286 len, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002287}
2288EXPORT_SYMBOL(dsi_vc_set_max_rx_packet_size);
2289
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03002290static void dsi_set_lp_rx_timeout(unsigned ticks, bool x4, bool x16)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002291{
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002292 unsigned long fck;
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03002293 unsigned long total_ticks;
2294 u32 r;
2295
2296 BUG_ON(ticks > 0x1fff);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002297
2298 /* ticks in DSI_FCK */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002299 fck = dsi_fclk_rate();
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002300
2301 r = dsi_read_reg(DSI_TIMING2);
2302 r = FLD_MOD(r, 1, 15, 15); /* LP_RX_TO */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03002303 r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* LP_RX_TO_X16 */
2304 r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* LP_RX_TO_X4 */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002305 r = FLD_MOD(r, ticks, 12, 0); /* LP_RX_COUNTER */
2306 dsi_write_reg(DSI_TIMING2, r);
2307
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03002308 total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
2309
2310 DSSDBG("LP_RX_TO %lu ticks (%#x%s%s) = %lu ns\n",
2311 total_ticks,
2312 ticks, x4 ? " x4" : "", x16 ? " x16" : "",
2313 (total_ticks * 1000) / (fck / 1000 / 1000));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002314}
2315
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03002316static void dsi_set_ta_timeout(unsigned ticks, bool x8, bool x16)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002317{
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002318 unsigned long fck;
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03002319 unsigned long total_ticks;
2320 u32 r;
2321
2322 BUG_ON(ticks > 0x1fff);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002323
2324 /* ticks in DSI_FCK */
2325 fck = dsi_fclk_rate();
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002326
2327 r = dsi_read_reg(DSI_TIMING1);
2328 r = FLD_MOD(r, 1, 31, 31); /* TA_TO */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03002329 r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* TA_TO_X16 */
2330 r = FLD_MOD(r, x8 ? 1 : 0, 29, 29); /* TA_TO_X8 */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002331 r = FLD_MOD(r, ticks, 28, 16); /* TA_TO_COUNTER */
2332 dsi_write_reg(DSI_TIMING1, r);
2333
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03002334 total_ticks = ticks * (x16 ? 16 : 1) * (x8 ? 8 : 1);
2335
2336 DSSDBG("TA_TO %lu ticks (%#x%s%s) = %lu ns\n",
2337 total_ticks,
2338 ticks, x8 ? " x8" : "", x16 ? " x16" : "",
2339 (total_ticks * 1000) / (fck / 1000 / 1000));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002340}
2341
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03002342static void dsi_set_stop_state_counter(unsigned ticks, bool x4, bool x16)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002343{
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002344 unsigned long fck;
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03002345 unsigned long total_ticks;
2346 u32 r;
2347
2348 BUG_ON(ticks > 0x1fff);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002349
2350 /* ticks in DSI_FCK */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002351 fck = dsi_fclk_rate();
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002352
2353 r = dsi_read_reg(DSI_TIMING1);
2354 r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03002355 r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* STOP_STATE_X16_IO */
2356 r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* STOP_STATE_X4_IO */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002357 r = FLD_MOD(r, ticks, 12, 0); /* STOP_STATE_COUNTER_IO */
2358 dsi_write_reg(DSI_TIMING1, r);
2359
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03002360 total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
2361
2362 DSSDBG("STOP_STATE_COUNTER %lu ticks (%#x%s%s) = %lu ns\n",
2363 total_ticks,
2364 ticks, x4 ? " x4" : "", x16 ? " x16" : "",
2365 (total_ticks * 1000) / (fck / 1000 / 1000));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002366}
2367
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03002368static void dsi_set_hs_tx_timeout(unsigned ticks, bool x4, bool x16)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002369{
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002370 unsigned long fck;
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03002371 unsigned long total_ticks;
2372 u32 r;
2373
2374 BUG_ON(ticks > 0x1fff);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002375
2376 /* ticks in TxByteClkHS */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002377 fck = dsi_get_txbyteclkhs();
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002378
2379 r = dsi_read_reg(DSI_TIMING2);
2380 r = FLD_MOD(r, 1, 31, 31); /* HS_TX_TO */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03002381 r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* HS_TX_TO_X16 */
2382 r = FLD_MOD(r, x4 ? 1 : 0, 29, 29); /* HS_TX_TO_X8 (4 really) */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002383 r = FLD_MOD(r, ticks, 28, 16); /* HS_TX_TO_COUNTER */
2384 dsi_write_reg(DSI_TIMING2, r);
2385
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03002386 total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
2387
2388 DSSDBG("HS_TX_TO %lu ticks (%#x%s%s) = %lu ns\n",
2389 total_ticks,
2390 ticks, x4 ? " x4" : "", x16 ? " x16" : "",
2391 (total_ticks * 1000) / (fck / 1000 / 1000));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002392}
2393static int dsi_proto_config(struct omap_dss_device *dssdev)
2394{
2395 u32 r;
2396 int buswidth = 0;
2397
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02002398 dsi_config_tx_fifo(DSI_FIFO_SIZE_32,
2399 DSI_FIFO_SIZE_32,
2400 DSI_FIFO_SIZE_32,
2401 DSI_FIFO_SIZE_32);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002402
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02002403 dsi_config_rx_fifo(DSI_FIFO_SIZE_32,
2404 DSI_FIFO_SIZE_32,
2405 DSI_FIFO_SIZE_32,
2406 DSI_FIFO_SIZE_32);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002407
2408 /* XXX what values for the timeouts? */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03002409 dsi_set_stop_state_counter(0x1000, false, false);
2410 dsi_set_ta_timeout(0x1fff, true, true);
2411 dsi_set_lp_rx_timeout(0x1fff, true, true);
2412 dsi_set_hs_tx_timeout(0x1fff, true, true);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002413
2414 switch (dssdev->ctrl.pixel_size) {
2415 case 16:
2416 buswidth = 0;
2417 break;
2418 case 18:
2419 buswidth = 1;
2420 break;
2421 case 24:
2422 buswidth = 2;
2423 break;
2424 default:
2425 BUG();
2426 }
2427
2428 r = dsi_read_reg(DSI_CTRL);
2429 r = FLD_MOD(r, 1, 1, 1); /* CS_RX_EN */
2430 r = FLD_MOD(r, 1, 2, 2); /* ECC_RX_EN */
2431 r = FLD_MOD(r, 1, 3, 3); /* TX_FIFO_ARBITRATION */
2432 r = FLD_MOD(r, 1, 4, 4); /* VP_CLK_RATIO, always 1, see errata*/
2433 r = FLD_MOD(r, buswidth, 7, 6); /* VP_DATA_BUS_WIDTH */
2434 r = FLD_MOD(r, 0, 8, 8); /* VP_CLK_POL */
2435 r = FLD_MOD(r, 2, 13, 12); /* LINE_BUFFER, 2 lines */
2436 r = FLD_MOD(r, 1, 14, 14); /* TRIGGER_RESET_MODE */
2437 r = FLD_MOD(r, 1, 19, 19); /* EOT_ENABLE */
2438 r = FLD_MOD(r, 1, 24, 24); /* DCS_CMD_ENABLE */
2439 r = FLD_MOD(r, 0, 25, 25); /* DCS_CMD_CODE, 1=start, 0=continue */
2440
2441 dsi_write_reg(DSI_CTRL, r);
2442
2443 dsi_vc_initial_config(0);
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02002444 dsi_vc_initial_config(1);
2445 dsi_vc_initial_config(2);
2446 dsi_vc_initial_config(3);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002447
2448 return 0;
2449}
2450
2451static void dsi_proto_timings(struct omap_dss_device *dssdev)
2452{
2453 unsigned tlpx, tclk_zero, tclk_prepare, tclk_trail;
2454 unsigned tclk_pre, tclk_post;
2455 unsigned ths_prepare, ths_prepare_ths_zero, ths_zero;
2456 unsigned ths_trail, ths_exit;
2457 unsigned ddr_clk_pre, ddr_clk_post;
2458 unsigned enter_hs_mode_lat, exit_hs_mode_lat;
2459 unsigned ths_eot;
2460 u32 r;
2461
2462 r = dsi_read_reg(DSI_DSIPHY_CFG0);
2463 ths_prepare = FLD_GET(r, 31, 24);
2464 ths_prepare_ths_zero = FLD_GET(r, 23, 16);
2465 ths_zero = ths_prepare_ths_zero - ths_prepare;
2466 ths_trail = FLD_GET(r, 15, 8);
2467 ths_exit = FLD_GET(r, 7, 0);
2468
2469 r = dsi_read_reg(DSI_DSIPHY_CFG1);
2470 tlpx = FLD_GET(r, 22, 16) * 2;
2471 tclk_trail = FLD_GET(r, 15, 8);
2472 tclk_zero = FLD_GET(r, 7, 0);
2473
2474 r = dsi_read_reg(DSI_DSIPHY_CFG2);
2475 tclk_prepare = FLD_GET(r, 7, 0);
2476
2477 /* min 8*UI */
2478 tclk_pre = 20;
2479 /* min 60ns + 52*UI */
2480 tclk_post = ns2ddr(60) + 26;
2481
2482 /* ths_eot is 2 for 2 datalanes and 4 for 1 datalane */
2483 if (dssdev->phy.dsi.data1_lane != 0 &&
2484 dssdev->phy.dsi.data2_lane != 0)
2485 ths_eot = 2;
2486 else
2487 ths_eot = 4;
2488
2489 ddr_clk_pre = DIV_ROUND_UP(tclk_pre + tlpx + tclk_zero + tclk_prepare,
2490 4);
2491 ddr_clk_post = DIV_ROUND_UP(tclk_post + ths_trail, 4) + ths_eot;
2492
2493 BUG_ON(ddr_clk_pre == 0 || ddr_clk_pre > 255);
2494 BUG_ON(ddr_clk_post == 0 || ddr_clk_post > 255);
2495
2496 r = dsi_read_reg(DSI_CLK_TIMING);
2497 r = FLD_MOD(r, ddr_clk_pre, 15, 8);
2498 r = FLD_MOD(r, ddr_clk_post, 7, 0);
2499 dsi_write_reg(DSI_CLK_TIMING, r);
2500
2501 DSSDBG("ddr_clk_pre %u, ddr_clk_post %u\n",
2502 ddr_clk_pre,
2503 ddr_clk_post);
2504
2505 enter_hs_mode_lat = 1 + DIV_ROUND_UP(tlpx, 4) +
2506 DIV_ROUND_UP(ths_prepare, 4) +
2507 DIV_ROUND_UP(ths_zero + 3, 4);
2508
2509 exit_hs_mode_lat = DIV_ROUND_UP(ths_trail + ths_exit, 4) + 1 + ths_eot;
2510
2511 r = FLD_VAL(enter_hs_mode_lat, 31, 16) |
2512 FLD_VAL(exit_hs_mode_lat, 15, 0);
2513 dsi_write_reg(DSI_VM_TIMING7, r);
2514
2515 DSSDBG("enter_hs_mode_lat %u, exit_hs_mode_lat %u\n",
2516 enter_hs_mode_lat, exit_hs_mode_lat);
2517}
2518
2519
2520#define DSI_DECL_VARS \
2521 int __dsi_cb = 0; u32 __dsi_cv = 0;
2522
2523#define DSI_FLUSH(ch) \
2524 if (__dsi_cb > 0) { \
2525 /*DSSDBG("sending long packet %#010x\n", __dsi_cv);*/ \
2526 dsi_write_reg(DSI_VC_LONG_PACKET_PAYLOAD(ch), __dsi_cv); \
2527 __dsi_cb = __dsi_cv = 0; \
2528 }
2529
2530#define DSI_PUSH(ch, data) \
2531 do { \
2532 __dsi_cv |= (data) << (__dsi_cb * 8); \
2533 /*DSSDBG("cv = %#010x, cb = %d\n", __dsi_cv, __dsi_cb);*/ \
2534 if (++__dsi_cb > 3) \
2535 DSI_FLUSH(ch); \
2536 } while (0)
2537
2538static int dsi_update_screen_l4(struct omap_dss_device *dssdev,
2539 int x, int y, int w, int h)
2540{
2541 /* Note: supports only 24bit colors in 32bit container */
2542 int first = 1;
2543 int fifo_stalls = 0;
2544 int max_dsi_packet_size;
2545 int max_data_per_packet;
2546 int max_pixels_per_packet;
2547 int pixels_left;
2548 int bytespp = dssdev->ctrl.pixel_size / 8;
2549 int scr_width;
2550 u32 __iomem *data;
2551 int start_offset;
2552 int horiz_inc;
2553 int current_x;
2554 struct omap_overlay *ovl;
2555
2556 debug_irq = 0;
2557
2558 DSSDBG("dsi_update_screen_l4 (%d,%d %dx%d)\n",
2559 x, y, w, h);
2560
2561 ovl = dssdev->manager->overlays[0];
2562
2563 if (ovl->info.color_mode != OMAP_DSS_COLOR_RGB24U)
2564 return -EINVAL;
2565
2566 if (dssdev->ctrl.pixel_size != 24)
2567 return -EINVAL;
2568
2569 scr_width = ovl->info.screen_width;
2570 data = ovl->info.vaddr;
2571
2572 start_offset = scr_width * y + x;
2573 horiz_inc = scr_width - w;
2574 current_x = x;
2575
2576 /* We need header(4) + DCSCMD(1) + pixels(numpix*bytespp) bytes
2577 * in fifo */
2578
2579 /* When using CPU, max long packet size is TX buffer size */
2580 max_dsi_packet_size = dsi.vc[0].fifo_size * 32 * 4;
2581
2582 /* we seem to get better perf if we divide the tx fifo to half,
2583 and while the other half is being sent, we fill the other half
2584 max_dsi_packet_size /= 2; */
2585
2586 max_data_per_packet = max_dsi_packet_size - 4 - 1;
2587
2588 max_pixels_per_packet = max_data_per_packet / bytespp;
2589
2590 DSSDBG("max_pixels_per_packet %d\n", max_pixels_per_packet);
2591
2592 pixels_left = w * h;
2593
2594 DSSDBG("total pixels %d\n", pixels_left);
2595
2596 data += start_offset;
2597
2598 while (pixels_left > 0) {
2599 /* 0x2c = write_memory_start */
2600 /* 0x3c = write_memory_continue */
2601 u8 dcs_cmd = first ? 0x2c : 0x3c;
2602 int pixels;
2603 DSI_DECL_VARS;
2604 first = 0;
2605
2606#if 1
2607 /* using fifo not empty */
2608 /* TX_FIFO_NOT_EMPTY */
2609 while (FLD_GET(dsi_read_reg(DSI_VC_CTRL(0)), 5, 5)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002610 fifo_stalls++;
2611 if (fifo_stalls > 0xfffff) {
2612 DSSERR("fifo stalls overflow, pixels left %d\n",
2613 pixels_left);
2614 dsi_if_enable(0);
2615 return -EIO;
2616 }
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02002617 udelay(1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002618 }
2619#elif 1
2620 /* using fifo emptiness */
2621 while ((REG_GET(DSI_TX_FIFO_VC_EMPTINESS, 7, 0)+1)*4 <
2622 max_dsi_packet_size) {
2623 fifo_stalls++;
2624 if (fifo_stalls > 0xfffff) {
2625 DSSERR("fifo stalls overflow, pixels left %d\n",
2626 pixels_left);
2627 dsi_if_enable(0);
2628 return -EIO;
2629 }
2630 }
2631#else
2632 while ((REG_GET(DSI_TX_FIFO_VC_EMPTINESS, 7, 0)+1)*4 == 0) {
2633 fifo_stalls++;
2634 if (fifo_stalls > 0xfffff) {
2635 DSSERR("fifo stalls overflow, pixels left %d\n",
2636 pixels_left);
2637 dsi_if_enable(0);
2638 return -EIO;
2639 }
2640 }
2641#endif
2642 pixels = min(max_pixels_per_packet, pixels_left);
2643
2644 pixels_left -= pixels;
2645
2646 dsi_vc_write_long_header(0, DSI_DT_DCS_LONG_WRITE,
2647 1 + pixels * bytespp, 0);
2648
2649 DSI_PUSH(0, dcs_cmd);
2650
2651 while (pixels-- > 0) {
2652 u32 pix = __raw_readl(data++);
2653
2654 DSI_PUSH(0, (pix >> 16) & 0xff);
2655 DSI_PUSH(0, (pix >> 8) & 0xff);
2656 DSI_PUSH(0, (pix >> 0) & 0xff);
2657
2658 current_x++;
2659 if (current_x == x+w) {
2660 current_x = x;
2661 data += horiz_inc;
2662 }
2663 }
2664
2665 DSI_FLUSH(0);
2666 }
2667
2668 return 0;
2669}
2670
2671static void dsi_update_screen_dispc(struct omap_dss_device *dssdev,
2672 u16 x, u16 y, u16 w, u16 h)
2673{
2674 unsigned bytespp;
2675 unsigned bytespl;
2676 unsigned bytespf;
2677 unsigned total_len;
2678 unsigned packet_payload;
2679 unsigned packet_len;
2680 u32 l;
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03002681 int r;
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002682 const unsigned channel = dsi.update_channel;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002683 /* line buffer is 1024 x 24bits */
2684 /* XXX: for some reason using full buffer size causes considerable TX
2685 * slowdown with update sizes that fill the whole buffer */
2686 const unsigned line_buf_size = 1023 * 3;
2687
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +02002688 DSSDBG("dsi_update_screen_dispc(%d,%d %dx%d)\n",
2689 x, y, w, h);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002690
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002691 dsi_vc_config_vp(channel);
2692
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002693 bytespp = dssdev->ctrl.pixel_size / 8;
2694 bytespl = w * bytespp;
2695 bytespf = bytespl * h;
2696
2697 /* NOTE: packet_payload has to be equal to N * bytespl, where N is
2698 * number of lines in a packet. See errata about VP_CLK_RATIO */
2699
2700 if (bytespf < line_buf_size)
2701 packet_payload = bytespf;
2702 else
2703 packet_payload = (line_buf_size) / bytespl * bytespl;
2704
2705 packet_len = packet_payload + 1; /* 1 byte for DCS cmd */
2706 total_len = (bytespf / packet_payload) * packet_len;
2707
2708 if (bytespf % packet_payload)
2709 total_len += (bytespf % packet_payload) + 1;
2710
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002711 l = FLD_VAL(total_len, 23, 0); /* TE_SIZE */
2712 dsi_write_reg(DSI_VC_TE(channel), l);
2713
2714 dsi_vc_write_long_header(channel, DSI_DT_DCS_LONG_WRITE, packet_len, 0);
2715
Tomi Valkeinen942a91a2010-02-10 17:27:39 +02002716 if (dsi.te_enabled)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002717 l = FLD_MOD(l, 1, 30, 30); /* TE_EN */
2718 else
2719 l = FLD_MOD(l, 1, 31, 31); /* TE_START */
2720 dsi_write_reg(DSI_VC_TE(channel), l);
2721
2722 /* We put SIDLEMODE to no-idle for the duration of the transfer,
2723 * because DSS interrupts are not capable of waking up the CPU and the
2724 * framedone interrupt could be delayed for quite a long time. I think
2725 * the same goes for any DSS interrupts, but for some reason I have not
2726 * seen the problem anywhere else than here.
2727 */
2728 dispc_disable_sidle();
2729
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002730 dsi_perf_mark_start();
2731
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03002732 r = queue_delayed_work(dsi.workqueue, &dsi.framedone_timeout_work,
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002733 msecs_to_jiffies(250));
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03002734 BUG_ON(r == 0);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002735
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002736 dss_start_update(dssdev);
2737
Tomi Valkeinen942a91a2010-02-10 17:27:39 +02002738 if (dsi.te_enabled) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002739 /* disable LP_RX_TO, so that we can receive TE. Time to wait
2740 * for TE is longer than the timer allows */
2741 REG_FLD_MOD(DSI_TIMING2, 0, 15, 15); /* LP_RX_TO */
2742
2743 dsi_vc_send_bta(channel);
2744
2745#ifdef DSI_CATCH_MISSING_TE
2746 mod_timer(&dsi.te_timer, jiffies + msecs_to_jiffies(250));
2747#endif
2748 }
2749}
2750
2751#ifdef DSI_CATCH_MISSING_TE
2752static void dsi_te_timeout(unsigned long arg)
2753{
2754 DSSERR("TE not received for 250ms!\n");
2755}
2756#endif
2757
Tomi Valkeinenab83b142010-06-09 15:31:01 +03002758static void dsi_handle_framedone(int error)
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002759{
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002760 const int channel = dsi.update_channel;
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002761
Tomi Valkeinenab83b142010-06-09 15:31:01 +03002762 cancel_delayed_work(&dsi.framedone_timeout_work);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002763
Tomi Valkeinenab83b142010-06-09 15:31:01 +03002764 dsi_vc_disable_bta_irq(channel);
2765
2766 /* SIDLEMODE back to smart-idle */
2767 dispc_enable_sidle();
2768
2769 dsi.bta_callback = NULL;
2770
2771 if (dsi.te_enabled) {
2772 /* enable LP_RX_TO again after the TE */
2773 REG_FLD_MOD(DSI_TIMING2, 1, 15, 15); /* LP_RX_TO */
2774 }
2775
2776 /* RX_FIFO_NOT_EMPTY */
2777 if (REG_GET(DSI_VC_CTRL(channel), 20, 20)) {
2778 DSSERR("Received error during frame transfer:\n");
2779 dsi_vc_flush_receive_data(channel);
2780 if (!error)
2781 error = -EIO;
2782 }
2783
2784 dsi.framedone_callback(error, dsi.framedone_data);
2785
2786 if (!error)
2787 dsi_perf_show("DISPC");
2788}
2789
2790static void dsi_framedone_timeout_work_callback(struct work_struct *work)
2791{
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03002792 /* XXX While extremely unlikely, we could get FRAMEDONE interrupt after
2793 * 250ms which would conflict with this timeout work. What should be
2794 * done is first cancel the transfer on the HW, and then cancel the
Tomi Valkeinenab83b142010-06-09 15:31:01 +03002795 * possibly scheduled framedone work. However, cancelling the transfer
2796 * on the HW is buggy, and would probably require resetting the whole
2797 * DSI */
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03002798
Tomi Valkeinenab83b142010-06-09 15:31:01 +03002799 DSSERR("Framedone not received for 250ms!\n");
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002800
Tomi Valkeinenab83b142010-06-09 15:31:01 +03002801 dsi_handle_framedone(-ETIMEDOUT);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002802}
2803
Tomi Valkeinenab83b142010-06-09 15:31:01 +03002804static void dsi_framedone_bta_callback(void)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002805{
Tomi Valkeinenab83b142010-06-09 15:31:01 +03002806 dsi_handle_framedone(0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002807
2808#ifdef CONFIG_OMAP2_DSS_FAKE_VSYNC
2809 dispc_fake_vsync_irq();
2810#endif
2811}
2812
Tomi Valkeinenab83b142010-06-09 15:31:01 +03002813static void dsi_framedone_irq_callback(void *data, u32 mask)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002814{
Tomi Valkeinenab83b142010-06-09 15:31:01 +03002815 const int channel = dsi.update_channel;
2816 int r;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002817
Tomi Valkeinenab83b142010-06-09 15:31:01 +03002818 /* Note: We get FRAMEDONE when DISPC has finished sending pixels and
2819 * turns itself off. However, DSI still has the pixels in its buffers,
2820 * and is sending the data.
2821 */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002822
Tomi Valkeinenab83b142010-06-09 15:31:01 +03002823 if (dsi.te_enabled) {
2824 /* enable LP_RX_TO again after the TE */
2825 REG_FLD_MOD(DSI_TIMING2, 1, 15, 15); /* LP_RX_TO */
2826 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002827
Tomi Valkeinenab83b142010-06-09 15:31:01 +03002828 /* Send BTA after the frame. We need this for the TE to work, as TE
2829 * trigger is only sent for BTAs without preceding packet. Thus we need
2830 * to BTA after the pixel packets so that next BTA will cause TE
2831 * trigger.
2832 *
2833 * This is not needed when TE is not in use, but we do it anyway to
2834 * make sure that the transfer has been completed. It would be more
2835 * optimal, but more complex, to wait only just before starting next
2836 * transfer.
2837 *
2838 * Also, as there's no interrupt telling when the transfer has been
2839 * done and the channel could be reconfigured, the only way is to
2840 * busyloop until TE_SIZE is zero. With BTA we can do this
2841 * asynchronously.
2842 * */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002843
Tomi Valkeinenab83b142010-06-09 15:31:01 +03002844 dsi.bta_callback = dsi_framedone_bta_callback;
2845
2846 barrier();
2847
2848 dsi_vc_enable_bta_irq(channel);
2849
2850 r = dsi_vc_send_bta(channel);
2851 if (r) {
2852 DSSERR("BTA after framedone failed\n");
2853 dsi_handle_framedone(-EIO);
2854 }
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002855}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002856
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002857int omap_dsi_prepare_update(struct omap_dss_device *dssdev,
Tomi Valkeinen26a8c252010-06-09 15:31:34 +03002858 u16 *x, u16 *y, u16 *w, u16 *h,
2859 bool enlarge_update_area)
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002860{
2861 u16 dw, dh;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002862
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002863 dssdev->driver->get_resolution(dssdev, &dw, &dh);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002864
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002865 if (*x > dw || *y > dh)
2866 return -EINVAL;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002867
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002868 if (*x + *w > dw)
2869 return -EINVAL;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002870
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002871 if (*y + *h > dh)
2872 return -EINVAL;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002873
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002874 if (*w == 1)
2875 return -EINVAL;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002876
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002877 if (*w == 0 || *h == 0)
2878 return -EINVAL;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002879
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002880 dsi_perf_mark_setup();
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002881
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002882 if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) {
Tomi Valkeinen26a8c252010-06-09 15:31:34 +03002883 dss_setup_partial_planes(dssdev, x, y, w, h,
2884 enlarge_update_area);
Sumit Semwal64ba4f72010-12-02 11:27:10 +00002885 dispc_set_lcd_size(dssdev->manager->id, *w, *h);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002886 }
2887
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002888 return 0;
2889}
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002890EXPORT_SYMBOL(omap_dsi_prepare_update);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002891
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002892int omap_dsi_update(struct omap_dss_device *dssdev,
2893 int channel,
2894 u16 x, u16 y, u16 w, u16 h,
2895 void (*callback)(int, void *), void *data)
2896{
2897 dsi.update_channel = channel;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002898
Tomi Valkeinena6027712010-05-25 17:01:28 +03002899 /* OMAP DSS cannot send updates of odd widths.
2900 * omap_dsi_prepare_update() makes the widths even, but add a BUG_ON
2901 * here to make sure we catch erroneous updates. Otherwise we'll only
2902 * see rather obscure HW error happening, as DSS halts. */
2903 BUG_ON(x % 2 == 1);
2904
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002905 if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) {
2906 dsi.framedone_callback = callback;
2907 dsi.framedone_data = data;
2908
2909 dsi.update_region.x = x;
2910 dsi.update_region.y = y;
2911 dsi.update_region.w = w;
2912 dsi.update_region.h = h;
2913 dsi.update_region.device = dssdev;
2914
2915 dsi_update_screen_dispc(dssdev, x, y, w, h);
2916 } else {
Archit Tanejae9c31af2010-07-14 14:11:50 +02002917 int r;
2918
2919 r = dsi_update_screen_l4(dssdev, x, y, w, h);
2920 if (r)
2921 return r;
2922
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002923 dsi_perf_show("L4");
2924 callback(0, data);
2925 }
2926
2927 return 0;
2928}
2929EXPORT_SYMBOL(omap_dsi_update);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002930
2931/* Display funcs */
2932
2933static int dsi_display_init_dispc(struct omap_dss_device *dssdev)
2934{
2935 int r;
2936
2937 r = omap_dispc_register_isr(dsi_framedone_irq_callback, NULL,
2938 DISPC_IRQ_FRAMEDONE);
2939 if (r) {
2940 DSSERR("can't get FRAMEDONE irq\n");
2941 return r;
2942 }
2943
Sumit Semwal64ba4f72010-12-02 11:27:10 +00002944 dispc_set_lcd_display_type(dssdev->manager->id,
2945 OMAP_DSS_LCD_DISPLAY_TFT);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002946
Sumit Semwal64ba4f72010-12-02 11:27:10 +00002947 dispc_set_parallel_interface_mode(dssdev->manager->id,
2948 OMAP_DSS_PARALLELMODE_DSI);
2949 dispc_enable_fifohandcheck(dssdev->manager->id, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002950
Sumit Semwal64ba4f72010-12-02 11:27:10 +00002951 dispc_set_tft_data_lines(dssdev->manager->id, dssdev->ctrl.pixel_size);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002952
2953 {
2954 struct omap_video_timings timings = {
2955 .hsw = 1,
2956 .hfp = 1,
2957 .hbp = 1,
2958 .vsw = 1,
2959 .vfp = 0,
2960 .vbp = 0,
2961 };
2962
Sumit Semwal64ba4f72010-12-02 11:27:10 +00002963 dispc_set_lcd_timings(dssdev->manager->id, &timings);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002964 }
2965
2966 return 0;
2967}
2968
2969static void dsi_display_uninit_dispc(struct omap_dss_device *dssdev)
2970{
2971 omap_dispc_unregister_isr(dsi_framedone_irq_callback, NULL,
2972 DISPC_IRQ_FRAMEDONE);
2973}
2974
2975static int dsi_configure_dsi_clocks(struct omap_dss_device *dssdev)
2976{
2977 struct dsi_clock_info cinfo;
2978 int r;
2979
2980 /* we always use DSS2_FCK as input clock */
2981 cinfo.use_dss2_fck = true;
2982 cinfo.regn = dssdev->phy.dsi.div.regn;
2983 cinfo.regm = dssdev->phy.dsi.div.regm;
2984 cinfo.regm3 = dssdev->phy.dsi.div.regm3;
2985 cinfo.regm4 = dssdev->phy.dsi.div.regm4;
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00002986 r = dsi_calc_clock_rates(dssdev, &cinfo);
Ville Syrjäläebf0a3f2010-04-22 22:50:05 +02002987 if (r) {
2988 DSSERR("Failed to calc dsi clocks\n");
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002989 return r;
Ville Syrjäläebf0a3f2010-04-22 22:50:05 +02002990 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002991
2992 r = dsi_pll_set_clock_div(&cinfo);
2993 if (r) {
2994 DSSERR("Failed to set dsi clocks\n");
2995 return r;
2996 }
2997
2998 return 0;
2999}
3000
3001static int dsi_configure_dispc_clocks(struct omap_dss_device *dssdev)
3002{
3003 struct dispc_clock_info dispc_cinfo;
3004 int r;
3005 unsigned long long fck;
3006
3007 fck = dsi_get_dsi1_pll_rate();
3008
3009 dispc_cinfo.lck_div = dssdev->phy.dsi.div.lck_div;
3010 dispc_cinfo.pck_div = dssdev->phy.dsi.div.pck_div;
3011
3012 r = dispc_calc_clock_rates(fck, &dispc_cinfo);
3013 if (r) {
3014 DSSERR("Failed to calc dispc clocks\n");
3015 return r;
3016 }
3017
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00003018 r = dispc_set_clock_div(dssdev->manager->id, &dispc_cinfo);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003019 if (r) {
3020 DSSERR("Failed to set dispc clocks\n");
3021 return r;
3022 }
3023
3024 return 0;
3025}
3026
3027static int dsi_display_init_dsi(struct omap_dss_device *dssdev)
3028{
3029 int r;
3030
3031 _dsi_print_reset_status();
3032
3033 r = dsi_pll_init(dssdev, true, true);
3034 if (r)
3035 goto err0;
3036
3037 r = dsi_configure_dsi_clocks(dssdev);
3038 if (r)
3039 goto err1;
3040
Tomi Valkeinen2f18c4d2010-01-08 18:00:36 +02003041 dss_select_dispc_clk_source(DSS_SRC_DSI1_PLL_FCLK);
3042 dss_select_dsi_clk_source(DSS_SRC_DSI2_PLL_FCLK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003043
3044 DSSDBG("PLL OK\n");
3045
3046 r = dsi_configure_dispc_clocks(dssdev);
3047 if (r)
3048 goto err2;
3049
3050 r = dsi_complexio_init(dssdev);
3051 if (r)
3052 goto err2;
3053
3054 _dsi_print_reset_status();
3055
3056 dsi_proto_timings(dssdev);
3057 dsi_set_lp_clk_divisor(dssdev);
3058
3059 if (1)
3060 _dsi_print_reset_status();
3061
3062 r = dsi_proto_config(dssdev);
3063 if (r)
3064 goto err3;
3065
3066 /* enable interface */
3067 dsi_vc_enable(0, 1);
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02003068 dsi_vc_enable(1, 1);
3069 dsi_vc_enable(2, 1);
3070 dsi_vc_enable(3, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003071 dsi_if_enable(1);
3072 dsi_force_tx_stop_mode_io();
3073
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003074 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003075err3:
3076 dsi_complexio_uninit();
3077err2:
Tomi Valkeinen2f18c4d2010-01-08 18:00:36 +02003078 dss_select_dispc_clk_source(DSS_SRC_DSS1_ALWON_FCLK);
3079 dss_select_dsi_clk_source(DSS_SRC_DSS1_ALWON_FCLK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003080err1:
3081 dsi_pll_uninit();
3082err0:
3083 return r;
3084}
3085
3086static void dsi_display_uninit_dsi(struct omap_dss_device *dssdev)
3087{
Ville Syrjäläd7370102010-04-22 22:50:09 +02003088 /* disable interface */
3089 dsi_if_enable(0);
3090 dsi_vc_enable(0, 0);
3091 dsi_vc_enable(1, 0);
3092 dsi_vc_enable(2, 0);
3093 dsi_vc_enable(3, 0);
3094
Tomi Valkeinen2f18c4d2010-01-08 18:00:36 +02003095 dss_select_dispc_clk_source(DSS_SRC_DSS1_ALWON_FCLK);
3096 dss_select_dsi_clk_source(DSS_SRC_DSS1_ALWON_FCLK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003097 dsi_complexio_uninit();
3098 dsi_pll_uninit();
3099}
3100
3101static int dsi_core_init(void)
3102{
3103 /* Autoidle */
3104 REG_FLD_MOD(DSI_SYSCONFIG, 1, 0, 0);
3105
3106 /* ENWAKEUP */
3107 REG_FLD_MOD(DSI_SYSCONFIG, 1, 2, 2);
3108
3109 /* SIDLEMODE smart-idle */
3110 REG_FLD_MOD(DSI_SYSCONFIG, 2, 4, 3);
3111
3112 _dsi_initialize_irq();
3113
3114 return 0;
3115}
3116
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003117int omapdss_dsi_display_enable(struct omap_dss_device *dssdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003118{
3119 int r = 0;
3120
3121 DSSDBG("dsi_display_enable\n");
3122
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003123 WARN_ON(!dsi_bus_is_locked());
3124
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003125 mutex_lock(&dsi.lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003126
3127 r = omap_dss_start_device(dssdev);
3128 if (r) {
3129 DSSERR("failed to start device\n");
3130 goto err0;
3131 }
3132
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003133 enable_clocks(1);
3134 dsi_enable_pll_clock(1);
3135
3136 r = _dsi_reset();
3137 if (r)
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003138 goto err1;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003139
3140 dsi_core_init();
3141
3142 r = dsi_display_init_dispc(dssdev);
3143 if (r)
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003144 goto err1;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003145
3146 r = dsi_display_init_dsi(dssdev);
3147 if (r)
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003148 goto err2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003149
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003150 mutex_unlock(&dsi.lock);
3151
3152 return 0;
3153
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003154err2:
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003155 dsi_display_uninit_dispc(dssdev);
3156err1:
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003157 enable_clocks(0);
3158 dsi_enable_pll_clock(0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003159 omap_dss_stop_device(dssdev);
3160err0:
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003161 mutex_unlock(&dsi.lock);
3162 DSSDBG("dsi_display_enable FAILED\n");
3163 return r;
3164}
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003165EXPORT_SYMBOL(omapdss_dsi_display_enable);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003166
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003167void omapdss_dsi_display_disable(struct omap_dss_device *dssdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003168{
3169 DSSDBG("dsi_display_disable\n");
3170
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003171 WARN_ON(!dsi_bus_is_locked());
3172
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003173 mutex_lock(&dsi.lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003174
3175 dsi_display_uninit_dispc(dssdev);
3176
3177 dsi_display_uninit_dsi(dssdev);
3178
3179 enable_clocks(0);
3180 dsi_enable_pll_clock(0);
3181
3182 omap_dss_stop_device(dssdev);
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003183
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003184 mutex_unlock(&dsi.lock);
3185}
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003186EXPORT_SYMBOL(omapdss_dsi_display_disable);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003187
Tomi Valkeinen225b6502010-01-11 15:11:01 +02003188int omapdss_dsi_enable_te(struct omap_dss_device *dssdev, bool enable)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003189{
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003190 dsi.te_enabled = enable;
Tomi Valkeinen225b6502010-01-11 15:11:01 +02003191 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003192}
Tomi Valkeinen225b6502010-01-11 15:11:01 +02003193EXPORT_SYMBOL(omapdss_dsi_enable_te);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003194
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003195void dsi_get_overlay_fifo_thresholds(enum omap_plane plane,
3196 u32 fifo_size, enum omap_burst_size *burst_size,
3197 u32 *fifo_low, u32 *fifo_high)
3198{
3199 unsigned burst_size_bytes;
3200
3201 *burst_size = OMAP_DSS_BURST_16x32;
3202 burst_size_bytes = 16 * 32 / 8;
3203
3204 *fifo_high = fifo_size - burst_size_bytes;
Tomi Valkeinen36194b42010-05-18 13:35:37 +03003205 *fifo_low = fifo_size - burst_size_bytes * 2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003206}
3207
3208int dsi_init_display(struct omap_dss_device *dssdev)
3209{
3210 DSSDBG("DSI init\n");
3211
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003212 /* XXX these should be figured out dynamically */
3213 dssdev->caps = OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE |
3214 OMAP_DSS_DISPLAY_CAP_TEAR_ELIM;
3215
3216 dsi.vc[0].dssdev = dssdev;
3217 dsi.vc[1].dssdev = dssdev;
3218
Tomi Valkeinen5f42f2c2011-02-22 15:53:46 +02003219 if (dsi.vdds_dsi_reg == NULL) {
3220 struct regulator *vdds_dsi;
3221
3222 vdds_dsi = regulator_get(&dsi.pdev->dev, "vdds_dsi");
3223
3224 if (IS_ERR(vdds_dsi)) {
3225 DSSERR("can't get VDDS_DSI regulator\n");
3226 return PTR_ERR(vdds_dsi);
3227 }
3228
3229 dsi.vdds_dsi_reg = vdds_dsi;
3230 }
3231
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003232 return 0;
3233}
3234
Tomi Valkeinene406f902010-06-09 15:28:12 +03003235void dsi_wait_dsi1_pll_active(void)
3236{
3237 if (wait_for_bit_change(DSI_PLL_STATUS, 7, 1) != 1)
3238 DSSERR("DSI1 PLL clock not active\n");
3239}
3240
3241void dsi_wait_dsi2_pll_active(void)
3242{
3243 if (wait_for_bit_change(DSI_PLL_STATUS, 8, 1) != 1)
3244 DSSERR("DSI2 PLL clock not active\n");
3245}
3246
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00003247static int dsi_init(struct platform_device *pdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003248{
3249 u32 rev;
3250 int r;
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00003251 struct resource *dsi_mem;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003252
3253 spin_lock_init(&dsi.errors_lock);
3254 dsi.errors = 0;
3255
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02003256#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
3257 spin_lock_init(&dsi.irq_stats_lock);
3258 dsi.irq_stats.last_reset = jiffies;
3259#endif
3260
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003261 init_completion(&dsi.bta_completion);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003262
3263 mutex_init(&dsi.lock);
Tomi Valkeinenb9eb5d72010-01-11 16:33:56 +02003264 sema_init(&dsi.bus_lock, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003265
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03003266 dsi.workqueue = create_singlethread_workqueue("dsi");
3267 if (dsi.workqueue == NULL)
3268 return -ENOMEM;
3269
Tomi Valkeinen18946f62010-01-12 14:16:41 +02003270 INIT_DELAYED_WORK_DEFERRABLE(&dsi.framedone_timeout_work,
3271 dsi_framedone_timeout_work_callback);
3272
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003273#ifdef DSI_CATCH_MISSING_TE
3274 init_timer(&dsi.te_timer);
3275 dsi.te_timer.function = dsi_te_timeout;
3276 dsi.te_timer.data = 0;
3277#endif
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00003278 dsi_mem = platform_get_resource(dsi.pdev, IORESOURCE_MEM, 0);
3279 if (!dsi_mem) {
3280 DSSERR("can't get IORESOURCE_MEM DSI\n");
3281 r = -EINVAL;
3282 goto err1;
3283 }
3284 dsi.base = ioremap(dsi_mem->start, resource_size(dsi_mem));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003285 if (!dsi.base) {
3286 DSSERR("can't ioremap DSI\n");
3287 r = -ENOMEM;
3288 goto err1;
3289 }
archit tanejaaffe3602011-02-23 08:41:03 +00003290 dsi.irq = platform_get_irq(dsi.pdev, 0);
3291 if (dsi.irq < 0) {
3292 DSSERR("platform_get_irq failed\n");
3293 r = -ENODEV;
3294 goto err2;
3295 }
3296
3297 r = request_irq(dsi.irq, omap_dsi_irq_handler, IRQF_SHARED,
3298 "OMAP DSI1", dsi.pdev);
3299 if (r < 0) {
3300 DSSERR("request_irq failed\n");
3301 goto err2;
3302 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003303
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003304 enable_clocks(1);
3305
3306 rev = dsi_read_reg(DSI_REVISION);
Sumit Semwala06b62f2011-01-24 06:22:03 +00003307 dev_dbg(&pdev->dev, "OMAP DSI rev %d.%d\n",
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003308 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
3309
3310 enable_clocks(0);
3311
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003312 return 0;
archit tanejaaffe3602011-02-23 08:41:03 +00003313err2:
3314 iounmap(dsi.base);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003315err1:
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03003316 destroy_workqueue(dsi.workqueue);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003317 return r;
3318}
3319
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00003320static void dsi_exit(void)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003321{
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00003322 if (dsi.vdds_dsi_reg != NULL) {
3323 regulator_put(dsi.vdds_dsi_reg);
3324 dsi.vdds_dsi_reg = NULL;
3325 }
3326
archit tanejaaffe3602011-02-23 08:41:03 +00003327 free_irq(dsi.irq, dsi.pdev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003328 iounmap(dsi.base);
3329
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03003330 destroy_workqueue(dsi.workqueue);
3331
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003332 DSSDBG("omap_dsi_exit\n");
3333}
3334
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00003335/* DSI1 HW IP initialisation */
3336static int omap_dsi1hw_probe(struct platform_device *pdev)
3337{
3338 int r;
3339 dsi.pdev = pdev;
3340 r = dsi_init(pdev);
3341 if (r) {
3342 DSSERR("Failed to initialize DSI\n");
3343 goto err_dsi;
3344 }
3345err_dsi:
3346 return r;
3347}
3348
3349static int omap_dsi1hw_remove(struct platform_device *pdev)
3350{
3351 dsi_exit();
3352 return 0;
3353}
3354
3355static struct platform_driver omap_dsi1hw_driver = {
3356 .probe = omap_dsi1hw_probe,
3357 .remove = omap_dsi1hw_remove,
3358 .driver = {
3359 .name = "omapdss_dsi1",
3360 .owner = THIS_MODULE,
3361 },
3362};
3363
3364int dsi_init_platform_driver(void)
3365{
3366 return platform_driver_register(&omap_dsi1hw_driver);
3367}
3368
3369void dsi_uninit_platform_driver(void)
3370{
3371 return platform_driver_unregister(&omap_dsi1hw_driver);
3372}