blob: b6c08a6f2da158cb7209c0c9ef1eab8599cf9709 [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
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200188enum fifo_size {
189 DSI_FIFO_SIZE_0 = 0,
190 DSI_FIFO_SIZE_32 = 1,
191 DSI_FIFO_SIZE_64 = 2,
192 DSI_FIFO_SIZE_96 = 3,
193 DSI_FIFO_SIZE_128 = 4,
194};
195
196enum dsi_vc_mode {
197 DSI_VC_MODE_L4 = 0,
198 DSI_VC_MODE_VP,
199};
200
201struct dsi_update_region {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200202 u16 x, y, w, h;
203 struct omap_dss_device *device;
204};
205
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200206struct dsi_irq_stats {
207 unsigned long last_reset;
208 unsigned irq_count;
209 unsigned dsi_irqs[32];
210 unsigned vc_irqs[4][32];
211 unsigned cio_irqs[32];
212};
213
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200214static struct
215{
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +0000216 struct platform_device *pdev;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200217 void __iomem *base;
archit tanejaaffe3602011-02-23 08:41:03 +0000218 int irq;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200219
220 struct dsi_clock_info current_cinfo;
221
222 struct regulator *vdds_dsi_reg;
223
224 struct {
225 enum dsi_vc_mode mode;
226 struct omap_dss_device *dssdev;
227 enum fifo_size fifo_size;
Archit Taneja5ee3c142011-03-02 12:35:53 +0530228 int vc_id;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200229 } vc[4];
230
231 struct mutex lock;
Tomi Valkeinenb9eb5d72010-01-11 16:33:56 +0200232 struct semaphore bus_lock;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200233
234 unsigned pll_locked;
235
236 struct completion bta_completion;
Tomi Valkeinenab83b142010-06-09 15:31:01 +0300237 void (*bta_callback)(void);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200238
Tomi Valkeinen18946f62010-01-12 14:16:41 +0200239 int update_channel;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200240 struct dsi_update_region update_region;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200241
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200242 bool te_enabled;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200243
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +0300244 struct workqueue_struct *workqueue;
245
Tomi Valkeinen18946f62010-01-12 14:16:41 +0200246 void (*framedone_callback)(int, void *);
247 void *framedone_data;
248
249 struct delayed_work framedone_timeout_work;
250
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200251#ifdef DSI_CATCH_MISSING_TE
252 struct timer_list te_timer;
253#endif
254
255 unsigned long cache_req_pck;
256 unsigned long cache_clk_freq;
257 struct dsi_clock_info cache_cinfo;
258
259 u32 errors;
260 spinlock_t errors_lock;
261#ifdef DEBUG
262 ktime_t perf_setup_time;
263 ktime_t perf_start_time;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200264#endif
265 int debug_read;
266 int debug_write;
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200267
268#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
269 spinlock_t irq_stats_lock;
270 struct dsi_irq_stats irq_stats;
271#endif
Taneja, Archit49641112011-03-14 23:28:23 -0500272 /* DSI PLL Parameter Ranges */
273 unsigned long regm_max, regn_max;
274 unsigned long regm_dispc_max, regm_dsi_max;
275 unsigned long fint_min, fint_max;
276 unsigned long lpdiv_max;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200277} dsi;
278
279#ifdef DEBUG
280static unsigned int dsi_perf;
281module_param_named(dsi_perf, dsi_perf, bool, 0644);
282#endif
283
284static inline void dsi_write_reg(const struct dsi_reg idx, u32 val)
285{
286 __raw_writel(val, dsi.base + idx.idx);
287}
288
289static inline u32 dsi_read_reg(const struct dsi_reg idx)
290{
291 return __raw_readl(dsi.base + idx.idx);
292}
293
294
295void dsi_save_context(void)
296{
297}
298
299void dsi_restore_context(void)
300{
301}
302
303void dsi_bus_lock(void)
304{
Tomi Valkeinenb9eb5d72010-01-11 16:33:56 +0200305 down(&dsi.bus_lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200306}
307EXPORT_SYMBOL(dsi_bus_lock);
308
309void dsi_bus_unlock(void)
310{
Tomi Valkeinenb9eb5d72010-01-11 16:33:56 +0200311 up(&dsi.bus_lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200312}
313EXPORT_SYMBOL(dsi_bus_unlock);
314
Tomi Valkeinen4f765022010-01-18 16:27:52 +0200315static bool dsi_bus_is_locked(void)
316{
Tomi Valkeinenb9eb5d72010-01-11 16:33:56 +0200317 return dsi.bus_lock.count == 0;
Tomi Valkeinen4f765022010-01-18 16:27:52 +0200318}
319
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200320static inline int wait_for_bit_change(const struct dsi_reg idx, int bitnum,
321 int value)
322{
323 int t = 100000;
324
325 while (REG_GET(idx, bitnum, bitnum) != value) {
326 if (--t == 0)
327 return !value;
328 }
329
330 return value;
331}
332
333#ifdef DEBUG
334static void dsi_perf_mark_setup(void)
335{
336 dsi.perf_setup_time = ktime_get();
337}
338
339static void dsi_perf_mark_start(void)
340{
341 dsi.perf_start_time = ktime_get();
342}
343
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200344static void dsi_perf_show(const char *name)
345{
346 ktime_t t, setup_time, trans_time;
347 u32 total_bytes;
348 u32 setup_us, trans_us, total_us;
349
350 if (!dsi_perf)
351 return;
352
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200353 t = ktime_get();
354
355 setup_time = ktime_sub(dsi.perf_start_time, dsi.perf_setup_time);
356 setup_us = (u32)ktime_to_us(setup_time);
357 if (setup_us == 0)
358 setup_us = 1;
359
360 trans_time = ktime_sub(t, dsi.perf_start_time);
361 trans_us = (u32)ktime_to_us(trans_time);
362 if (trans_us == 0)
363 trans_us = 1;
364
365 total_us = setup_us + trans_us;
366
Tomi Valkeinen18946f62010-01-12 14:16:41 +0200367 total_bytes = dsi.update_region.w *
368 dsi.update_region.h *
369 dsi.update_region.device->ctrl.pixel_size / 8;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200370
Tomi Valkeinen1bbb2752010-01-11 16:41:10 +0200371 printk(KERN_INFO "DSI(%s): %u us + %u us = %u us (%uHz), "
372 "%u bytes, %u kbytes/sec\n",
373 name,
374 setup_us,
375 trans_us,
376 total_us,
377 1000*1000 / total_us,
378 total_bytes,
379 total_bytes * 1000 / total_us);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200380}
381#else
382#define dsi_perf_mark_setup()
383#define dsi_perf_mark_start()
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200384#define dsi_perf_show(x)
385#endif
386
387static void print_irq_status(u32 status)
388{
389#ifndef VERBOSE_IRQ
390 if ((status & ~DSI_IRQ_CHANNEL_MASK) == 0)
391 return;
392#endif
393 printk(KERN_DEBUG "DSI IRQ: 0x%x: ", status);
394
395#define PIS(x) \
396 if (status & DSI_IRQ_##x) \
397 printk(#x " ");
398#ifdef VERBOSE_IRQ
399 PIS(VC0);
400 PIS(VC1);
401 PIS(VC2);
402 PIS(VC3);
403#endif
404 PIS(WAKEUP);
405 PIS(RESYNC);
406 PIS(PLL_LOCK);
407 PIS(PLL_UNLOCK);
408 PIS(PLL_RECALL);
409 PIS(COMPLEXIO_ERR);
410 PIS(HS_TX_TIMEOUT);
411 PIS(LP_RX_TIMEOUT);
412 PIS(TE_TRIGGER);
413 PIS(ACK_TRIGGER);
414 PIS(SYNC_LOST);
415 PIS(LDO_POWER_GOOD);
416 PIS(TA_TIMEOUT);
417#undef PIS
418
419 printk("\n");
420}
421
422static void print_irq_status_vc(int channel, u32 status)
423{
424#ifndef VERBOSE_IRQ
425 if ((status & ~DSI_VC_IRQ_PACKET_SENT) == 0)
426 return;
427#endif
428 printk(KERN_DEBUG "DSI VC(%d) IRQ 0x%x: ", channel, status);
429
430#define PIS(x) \
431 if (status & DSI_VC_IRQ_##x) \
432 printk(#x " ");
433 PIS(CS);
434 PIS(ECC_CORR);
435#ifdef VERBOSE_IRQ
436 PIS(PACKET_SENT);
437#endif
438 PIS(FIFO_TX_OVF);
439 PIS(FIFO_RX_OVF);
440 PIS(BTA);
441 PIS(ECC_NO_CORR);
442 PIS(FIFO_TX_UDF);
443 PIS(PP_BUSY_CHANGE);
444#undef PIS
445 printk("\n");
446}
447
448static void print_irq_status_cio(u32 status)
449{
450 printk(KERN_DEBUG "DSI CIO IRQ 0x%x: ", status);
451
452#define PIS(x) \
453 if (status & DSI_CIO_IRQ_##x) \
454 printk(#x " ");
455 PIS(ERRSYNCESC1);
456 PIS(ERRSYNCESC2);
457 PIS(ERRSYNCESC3);
458 PIS(ERRESC1);
459 PIS(ERRESC2);
460 PIS(ERRESC3);
461 PIS(ERRCONTROL1);
462 PIS(ERRCONTROL2);
463 PIS(ERRCONTROL3);
464 PIS(STATEULPS1);
465 PIS(STATEULPS2);
466 PIS(STATEULPS3);
467 PIS(ERRCONTENTIONLP0_1);
468 PIS(ERRCONTENTIONLP1_1);
469 PIS(ERRCONTENTIONLP0_2);
470 PIS(ERRCONTENTIONLP1_2);
471 PIS(ERRCONTENTIONLP0_3);
472 PIS(ERRCONTENTIONLP1_3);
473 PIS(ULPSACTIVENOT_ALL0);
474 PIS(ULPSACTIVENOT_ALL1);
475#undef PIS
476
477 printk("\n");
478}
479
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200480#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
481static void dsi_collect_irq_stats(u32 irqstatus, u32 *vcstatus, u32 ciostatus)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200482{
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200483 int i;
484
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200485 spin_lock(&dsi.irq_stats_lock);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200486
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200487 dsi.irq_stats.irq_count++;
488 dss_collect_irq_stats(irqstatus, dsi.irq_stats.dsi_irqs);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200489
490 for (i = 0; i < 4; ++i)
491 dss_collect_irq_stats(vcstatus[i], dsi.irq_stats.vc_irqs[i]);
492
493 dss_collect_irq_stats(ciostatus, dsi.irq_stats.cio_irqs);
494
495 spin_unlock(&dsi.irq_stats_lock);
496}
497#else
498#define dsi_collect_irq_stats(irqstatus, vcstatus, ciostatus)
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200499#endif
500
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200501static int debug_irq;
502
503static void dsi_handle_irq_errors(u32 irqstatus, u32 *vcstatus, u32 ciostatus)
504{
505 int i;
506
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200507 if (irqstatus & DSI_IRQ_ERROR_MASK) {
508 DSSERR("DSI error, irqstatus %x\n", irqstatus);
509 print_irq_status(irqstatus);
510 spin_lock(&dsi.errors_lock);
511 dsi.errors |= irqstatus & DSI_IRQ_ERROR_MASK;
512 spin_unlock(&dsi.errors_lock);
513 } else if (debug_irq) {
514 print_irq_status(irqstatus);
515 }
516
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200517 for (i = 0; i < 4; ++i) {
518 if (vcstatus[i] & DSI_VC_IRQ_ERROR_MASK) {
519 DSSERR("DSI VC(%d) error, vc irqstatus %x\n",
520 i, vcstatus[i]);
521 print_irq_status_vc(i, vcstatus[i]);
522 } else if (debug_irq) {
523 print_irq_status_vc(i, vcstatus[i]);
524 }
525 }
526
527 if (ciostatus & DSI_CIO_IRQ_ERROR_MASK) {
528 DSSERR("DSI CIO error, cio irqstatus %x\n", ciostatus);
529 print_irq_status_cio(ciostatus);
530 } else if (debug_irq) {
531 print_irq_status_cio(ciostatus);
532 }
533}
534
535static irqreturn_t omap_dsi_irq_handler(int irq, void *arg)
536{
537 u32 irqstatus, vcstatus[4], ciostatus;
538 int i;
539
540 irqstatus = dsi_read_reg(DSI_IRQSTATUS);
541
542 /* IRQ is not for us */
543 if (!irqstatus)
544 return IRQ_NONE;
545
546 dsi_write_reg(DSI_IRQSTATUS, irqstatus & ~DSI_IRQ_CHANNEL_MASK);
547 /* flush posted write */
548 dsi_read_reg(DSI_IRQSTATUS);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200549
550 for (i = 0; i < 4; ++i) {
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200551 if ((irqstatus & (1 << i)) == 0) {
552 vcstatus[i] = 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200553 continue;
Tomi Valkeinenab83b142010-06-09 15:31:01 +0300554 }
555
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200556 vcstatus[i] = dsi_read_reg(DSI_VC_IRQSTATUS(i));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200557
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200558 dsi_write_reg(DSI_VC_IRQSTATUS(i), vcstatus[i]);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200559 /* flush posted write */
560 dsi_read_reg(DSI_VC_IRQSTATUS(i));
561 }
562
563 if (irqstatus & DSI_IRQ_COMPLEXIO_ERR) {
564 ciostatus = dsi_read_reg(DSI_COMPLEXIO_IRQ_STATUS);
565
566 dsi_write_reg(DSI_COMPLEXIO_IRQ_STATUS, ciostatus);
567 /* flush posted write */
568 dsi_read_reg(DSI_COMPLEXIO_IRQ_STATUS);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200569 } else {
570 ciostatus = 0;
571 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200572
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200573#ifdef DSI_CATCH_MISSING_TE
574 if (irqstatus & DSI_IRQ_TE_TRIGGER)
575 del_timer(&dsi.te_timer);
576#endif
577
578 for (i = 0; i < 4; ++i) {
579 if (vcstatus[i] == 0)
580 continue;
581
582 if (vcstatus[i] & DSI_VC_IRQ_BTA) {
583 complete(&dsi.bta_completion);
584
585 if (dsi.bta_callback)
586 dsi.bta_callback();
Tomi Valkeinenbbecb502010-05-10 14:35:33 +0300587 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200588 }
589
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200590 dsi_handle_irq_errors(irqstatus, vcstatus, ciostatus);
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200591
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200592 dsi_collect_irq_stats(irqstatus, vcstatus, ciostatus);
593
archit tanejaaffe3602011-02-23 08:41:03 +0000594 return IRQ_HANDLED;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200595}
596
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200597static void _dsi_initialize_irq(void)
598{
599 u32 l;
600 int i;
601
602 /* disable all interrupts */
603 dsi_write_reg(DSI_IRQENABLE, 0);
604 for (i = 0; i < 4; ++i)
605 dsi_write_reg(DSI_VC_IRQENABLE(i), 0);
606 dsi_write_reg(DSI_COMPLEXIO_IRQ_ENABLE, 0);
607
608 /* clear interrupt status */
609 l = dsi_read_reg(DSI_IRQSTATUS);
610 dsi_write_reg(DSI_IRQSTATUS, l & ~DSI_IRQ_CHANNEL_MASK);
611
612 for (i = 0; i < 4; ++i) {
613 l = dsi_read_reg(DSI_VC_IRQSTATUS(i));
614 dsi_write_reg(DSI_VC_IRQSTATUS(i), l);
615 }
616
617 l = dsi_read_reg(DSI_COMPLEXIO_IRQ_STATUS);
618 dsi_write_reg(DSI_COMPLEXIO_IRQ_STATUS, l);
619
620 /* enable error irqs */
621 l = DSI_IRQ_ERROR_MASK;
622#ifdef DSI_CATCH_MISSING_TE
623 l |= DSI_IRQ_TE_TRIGGER;
624#endif
625 dsi_write_reg(DSI_IRQENABLE, l);
626
627 l = DSI_VC_IRQ_ERROR_MASK;
628 for (i = 0; i < 4; ++i)
629 dsi_write_reg(DSI_VC_IRQENABLE(i), l);
630
Tomi Valkeinenbbecb502010-05-10 14:35:33 +0300631 l = DSI_CIO_IRQ_ERROR_MASK;
632 dsi_write_reg(DSI_COMPLEXIO_IRQ_ENABLE, l);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200633}
634
635static u32 dsi_get_errors(void)
636{
637 unsigned long flags;
638 u32 e;
639 spin_lock_irqsave(&dsi.errors_lock, flags);
640 e = dsi.errors;
641 dsi.errors = 0;
642 spin_unlock_irqrestore(&dsi.errors_lock, flags);
643 return e;
644}
645
646static void dsi_vc_enable_bta_irq(int channel)
647{
648 u32 l;
649
650 dsi_write_reg(DSI_VC_IRQSTATUS(channel), DSI_VC_IRQ_BTA);
651
652 l = dsi_read_reg(DSI_VC_IRQENABLE(channel));
653 l |= DSI_VC_IRQ_BTA;
654 dsi_write_reg(DSI_VC_IRQENABLE(channel), l);
655}
656
657static void dsi_vc_disable_bta_irq(int channel)
658{
659 u32 l;
660
661 l = dsi_read_reg(DSI_VC_IRQENABLE(channel));
662 l &= ~DSI_VC_IRQ_BTA;
663 dsi_write_reg(DSI_VC_IRQENABLE(channel), l);
664}
665
Archit Taneja1bb47832011-02-24 14:17:30 +0530666/* DSI func clock. this could also be dsi_pll_hsdiv_dsi_clk */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200667static inline void enable_clocks(bool enable)
668{
669 if (enable)
Archit Taneja6af9cd12011-01-31 16:27:44 +0000670 dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200671 else
Archit Taneja6af9cd12011-01-31 16:27:44 +0000672 dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200673}
674
675/* source clock for DSI PLL. this could also be PCLKFREE */
676static inline void dsi_enable_pll_clock(bool enable)
677{
678 if (enable)
Archit Taneja6af9cd12011-01-31 16:27:44 +0000679 dss_clk_enable(DSS_CLK_SYSCK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200680 else
Archit Taneja6af9cd12011-01-31 16:27:44 +0000681 dss_clk_disable(DSS_CLK_SYSCK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200682
683 if (enable && dsi.pll_locked) {
684 if (wait_for_bit_change(DSI_PLL_STATUS, 1, 1) != 1)
685 DSSERR("cannot lock PLL when enabling clocks\n");
686 }
687}
688
689#ifdef DEBUG
690static void _dsi_print_reset_status(void)
691{
692 u32 l;
693
694 if (!dss_debug)
695 return;
696
697 /* A dummy read using the SCP interface to any DSIPHY register is
698 * required after DSIPHY reset to complete the reset of the DSI complex
699 * I/O. */
700 l = dsi_read_reg(DSI_DSIPHY_CFG5);
701
702 printk(KERN_DEBUG "DSI resets: ");
703
704 l = dsi_read_reg(DSI_PLL_STATUS);
705 printk("PLL (%d) ", FLD_GET(l, 0, 0));
706
707 l = dsi_read_reg(DSI_COMPLEXIO_CFG1);
708 printk("CIO (%d) ", FLD_GET(l, 29, 29));
709
710 l = dsi_read_reg(DSI_DSIPHY_CFG5);
711 printk("PHY (%x, %d, %d, %d)\n",
712 FLD_GET(l, 28, 26),
713 FLD_GET(l, 29, 29),
714 FLD_GET(l, 30, 30),
715 FLD_GET(l, 31, 31));
716}
717#else
718#define _dsi_print_reset_status()
719#endif
720
721static inline int dsi_if_enable(bool enable)
722{
723 DSSDBG("dsi_if_enable(%d)\n", enable);
724
725 enable = enable ? 1 : 0;
726 REG_FLD_MOD(DSI_CTRL, enable, 0, 0); /* IF_EN */
727
728 if (wait_for_bit_change(DSI_CTRL, 0, enable) != enable) {
729 DSSERR("Failed to set dsi_if_enable to %d\n", enable);
730 return -EIO;
731 }
732
733 return 0;
734}
735
Archit Taneja1bb47832011-02-24 14:17:30 +0530736unsigned long dsi_get_pll_hsdiv_dispc_rate(void)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200737{
Archit Taneja1bb47832011-02-24 14:17:30 +0530738 return dsi.current_cinfo.dsi_pll_hsdiv_dispc_clk;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200739}
740
Archit Taneja1bb47832011-02-24 14:17:30 +0530741static unsigned long dsi_get_pll_hsdiv_dsi_rate(void)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200742{
Archit Taneja1bb47832011-02-24 14:17:30 +0530743 return dsi.current_cinfo.dsi_pll_hsdiv_dsi_clk;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200744}
745
746static unsigned long dsi_get_txbyteclkhs(void)
747{
748 return dsi.current_cinfo.clkin4ddr / 16;
749}
750
751static unsigned long dsi_fclk_rate(void)
752{
753 unsigned long r;
754
Archit Taneja88134fa2011-01-06 10:44:10 +0530755 if (dss_get_dsi_clk_source() == DSS_CLK_SRC_FCK) {
Archit Taneja1bb47832011-02-24 14:17:30 +0530756 /* DSI FCLK source is DSS_CLK_FCK */
Archit Taneja6af9cd12011-01-31 16:27:44 +0000757 r = dss_clk_get_rate(DSS_CLK_FCK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200758 } else {
Archit Taneja1bb47832011-02-24 14:17:30 +0530759 /* DSI FCLK source is dsi_pll_hsdiv_dsi_clk */
760 r = dsi_get_pll_hsdiv_dsi_rate();
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200761 }
762
763 return r;
764}
765
766static int dsi_set_lp_clk_divisor(struct omap_dss_device *dssdev)
767{
768 unsigned long dsi_fclk;
769 unsigned lp_clk_div;
770 unsigned long lp_clk;
771
772 lp_clk_div = dssdev->phy.dsi.div.lp_clk_div;
773
Taneja, Archit49641112011-03-14 23:28:23 -0500774 if (lp_clk_div == 0 || lp_clk_div > dsi.lpdiv_max)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200775 return -EINVAL;
776
777 dsi_fclk = dsi_fclk_rate();
778
779 lp_clk = dsi_fclk / 2 / lp_clk_div;
780
781 DSSDBG("LP_CLK_DIV %u, LP_CLK %lu\n", lp_clk_div, lp_clk);
782 dsi.current_cinfo.lp_clk = lp_clk;
783 dsi.current_cinfo.lp_clk_div = lp_clk_div;
784
785 REG_FLD_MOD(DSI_CLK_CTRL, lp_clk_div, 12, 0); /* LP_CLK_DIVISOR */
786
787 REG_FLD_MOD(DSI_CLK_CTRL, dsi_fclk > 30000000 ? 1 : 0,
788 21, 21); /* LP_RX_SYNCHRO_ENABLE */
789
790 return 0;
791}
792
793
794enum dsi_pll_power_state {
795 DSI_PLL_POWER_OFF = 0x0,
796 DSI_PLL_POWER_ON_HSCLK = 0x1,
797 DSI_PLL_POWER_ON_ALL = 0x2,
798 DSI_PLL_POWER_ON_DIV = 0x3,
799};
800
801static int dsi_pll_power(enum dsi_pll_power_state state)
802{
803 int t = 0;
804
805 REG_FLD_MOD(DSI_CLK_CTRL, state, 31, 30); /* PLL_PWR_CMD */
806
807 /* PLL_PWR_STATUS */
808 while (FLD_GET(dsi_read_reg(DSI_CLK_CTRL), 29, 28) != state) {
Tomi Valkeinen24be78b2010-01-07 14:19:48 +0200809 if (++t > 1000) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200810 DSSERR("Failed to set DSI PLL power mode to %d\n",
811 state);
812 return -ENODEV;
813 }
Tomi Valkeinen24be78b2010-01-07 14:19:48 +0200814 udelay(1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200815 }
816
817 return 0;
818}
819
820/* calculate clock rates using dividers in cinfo */
Sumit Semwalff1b2cd2010-12-02 11:27:11 +0000821static int dsi_calc_clock_rates(struct omap_dss_device *dssdev,
822 struct dsi_clock_info *cinfo)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200823{
Taneja, Archit49641112011-03-14 23:28:23 -0500824 if (cinfo->regn == 0 || cinfo->regn > dsi.regn_max)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200825 return -EINVAL;
826
Taneja, Archit49641112011-03-14 23:28:23 -0500827 if (cinfo->regm == 0 || cinfo->regm > dsi.regm_max)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200828 return -EINVAL;
829
Taneja, Archit49641112011-03-14 23:28:23 -0500830 if (cinfo->regm_dispc > dsi.regm_dispc_max)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200831 return -EINVAL;
832
Taneja, Archit49641112011-03-14 23:28:23 -0500833 if (cinfo->regm_dsi > dsi.regm_dsi_max)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200834 return -EINVAL;
835
Archit Taneja1bb47832011-02-24 14:17:30 +0530836 if (cinfo->use_sys_clk) {
Archit Taneja6af9cd12011-01-31 16:27:44 +0000837 cinfo->clkin = dss_clk_get_rate(DSS_CLK_SYSCK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200838 /* XXX it is unclear if highfreq should be used
Archit Taneja1bb47832011-02-24 14:17:30 +0530839 * with DSS_SYS_CLK source also */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200840 cinfo->highfreq = 0;
841 } else {
Sumit Semwalff1b2cd2010-12-02 11:27:11 +0000842 cinfo->clkin = dispc_pclk_rate(dssdev->manager->id);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200843
844 if (cinfo->clkin < 32000000)
845 cinfo->highfreq = 0;
846 else
847 cinfo->highfreq = 1;
848 }
849
850 cinfo->fint = cinfo->clkin / (cinfo->regn * (cinfo->highfreq ? 2 : 1));
851
Taneja, Archit49641112011-03-14 23:28:23 -0500852 if (cinfo->fint > dsi.fint_max || cinfo->fint < dsi.fint_min)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200853 return -EINVAL;
854
855 cinfo->clkin4ddr = 2 * cinfo->regm * cinfo->fint;
856
857 if (cinfo->clkin4ddr > 1800 * 1000 * 1000)
858 return -EINVAL;
859
Archit Taneja1bb47832011-02-24 14:17:30 +0530860 if (cinfo->regm_dispc > 0)
861 cinfo->dsi_pll_hsdiv_dispc_clk =
862 cinfo->clkin4ddr / cinfo->regm_dispc;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200863 else
Archit Taneja1bb47832011-02-24 14:17:30 +0530864 cinfo->dsi_pll_hsdiv_dispc_clk = 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200865
Archit Taneja1bb47832011-02-24 14:17:30 +0530866 if (cinfo->regm_dsi > 0)
867 cinfo->dsi_pll_hsdiv_dsi_clk =
868 cinfo->clkin4ddr / cinfo->regm_dsi;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200869 else
Archit Taneja1bb47832011-02-24 14:17:30 +0530870 cinfo->dsi_pll_hsdiv_dsi_clk = 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200871
872 return 0;
873}
874
875int dsi_pll_calc_clock_div_pck(bool is_tft, unsigned long req_pck,
876 struct dsi_clock_info *dsi_cinfo,
877 struct dispc_clock_info *dispc_cinfo)
878{
879 struct dsi_clock_info cur, best;
880 struct dispc_clock_info best_dispc;
881 int min_fck_per_pck;
882 int match = 0;
Archit Taneja1bb47832011-02-24 14:17:30 +0530883 unsigned long dss_sys_clk, max_dss_fck;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200884
Archit Taneja1bb47832011-02-24 14:17:30 +0530885 dss_sys_clk = dss_clk_get_rate(DSS_CLK_SYSCK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200886
Taneja, Archit31ef8232011-03-14 23:28:22 -0500887 max_dss_fck = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK);
Archit Taneja819d8072011-03-01 11:54:00 +0530888
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200889 if (req_pck == dsi.cache_req_pck &&
Archit Taneja1bb47832011-02-24 14:17:30 +0530890 dsi.cache_cinfo.clkin == dss_sys_clk) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200891 DSSDBG("DSI clock info found from cache\n");
892 *dsi_cinfo = dsi.cache_cinfo;
Archit Taneja1bb47832011-02-24 14:17:30 +0530893 dispc_find_clk_divs(is_tft, req_pck,
894 dsi_cinfo->dsi_pll_hsdiv_dispc_clk, dispc_cinfo);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200895 return 0;
896 }
897
898 min_fck_per_pck = CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK;
899
900 if (min_fck_per_pck &&
Archit Taneja819d8072011-03-01 11:54:00 +0530901 req_pck * min_fck_per_pck > max_dss_fck) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200902 DSSERR("Requested pixel clock not possible with the current "
903 "OMAP2_DSS_MIN_FCK_PER_PCK setting. Turning "
904 "the constraint off.\n");
905 min_fck_per_pck = 0;
906 }
907
908 DSSDBG("dsi_pll_calc\n");
909
910retry:
911 memset(&best, 0, sizeof(best));
912 memset(&best_dispc, 0, sizeof(best_dispc));
913
914 memset(&cur, 0, sizeof(cur));
Archit Taneja1bb47832011-02-24 14:17:30 +0530915 cur.clkin = dss_sys_clk;
916 cur.use_sys_clk = 1;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200917 cur.highfreq = 0;
918
919 /* no highfreq: 0.75MHz < Fint = clkin / regn < 2.1MHz */
920 /* highfreq: 0.75MHz < Fint = clkin / (2*regn) < 2.1MHz */
921 /* To reduce PLL lock time, keep Fint high (around 2 MHz) */
Taneja, Archit49641112011-03-14 23:28:23 -0500922 for (cur.regn = 1; cur.regn < dsi.regn_max; ++cur.regn) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200923 if (cur.highfreq == 0)
924 cur.fint = cur.clkin / cur.regn;
925 else
926 cur.fint = cur.clkin / (2 * cur.regn);
927
Taneja, Archit49641112011-03-14 23:28:23 -0500928 if (cur.fint > dsi.fint_max || cur.fint < dsi.fint_min)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200929 continue;
930
931 /* DSIPHY(MHz) = (2 * regm / regn) * (clkin / (highfreq + 1)) */
Taneja, Archit49641112011-03-14 23:28:23 -0500932 for (cur.regm = 1; cur.regm < dsi.regm_max; ++cur.regm) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200933 unsigned long a, b;
934
935 a = 2 * cur.regm * (cur.clkin/1000);
936 b = cur.regn * (cur.highfreq + 1);
937 cur.clkin4ddr = a / b * 1000;
938
939 if (cur.clkin4ddr > 1800 * 1000 * 1000)
940 break;
941
Archit Taneja1bb47832011-02-24 14:17:30 +0530942 /* dsi_pll_hsdiv_dispc_clk(MHz) =
943 * DSIPHY(MHz) / regm_dispc < 173MHz/186Mhz */
Taneja, Archit49641112011-03-14 23:28:23 -0500944 for (cur.regm_dispc = 1; cur.regm_dispc < dsi.regm_dispc_max;
Archit Taneja1bb47832011-02-24 14:17:30 +0530945 ++cur.regm_dispc) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200946 struct dispc_clock_info cur_dispc;
Archit Taneja1bb47832011-02-24 14:17:30 +0530947 cur.dsi_pll_hsdiv_dispc_clk =
948 cur.clkin4ddr / cur.regm_dispc;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200949
950 /* this will narrow down the search a bit,
951 * but still give pixclocks below what was
952 * requested */
Archit Taneja1bb47832011-02-24 14:17:30 +0530953 if (cur.dsi_pll_hsdiv_dispc_clk < req_pck)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200954 break;
955
Archit Taneja1bb47832011-02-24 14:17:30 +0530956 if (cur.dsi_pll_hsdiv_dispc_clk > max_dss_fck)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200957 continue;
958
959 if (min_fck_per_pck &&
Archit Taneja1bb47832011-02-24 14:17:30 +0530960 cur.dsi_pll_hsdiv_dispc_clk <
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200961 req_pck * min_fck_per_pck)
962 continue;
963
964 match = 1;
965
966 dispc_find_clk_divs(is_tft, req_pck,
Archit Taneja1bb47832011-02-24 14:17:30 +0530967 cur.dsi_pll_hsdiv_dispc_clk,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200968 &cur_dispc);
969
970 if (abs(cur_dispc.pck - req_pck) <
971 abs(best_dispc.pck - req_pck)) {
972 best = cur;
973 best_dispc = cur_dispc;
974
975 if (cur_dispc.pck == req_pck)
976 goto found;
977 }
978 }
979 }
980 }
981found:
982 if (!match) {
983 if (min_fck_per_pck) {
984 DSSERR("Could not find suitable clock settings.\n"
985 "Turning FCK/PCK constraint off and"
986 "trying again.\n");
987 min_fck_per_pck = 0;
988 goto retry;
989 }
990
991 DSSERR("Could not find suitable clock settings.\n");
992
993 return -EINVAL;
994 }
995
Archit Taneja1bb47832011-02-24 14:17:30 +0530996 /* dsi_pll_hsdiv_dsi_clk (regm_dsi) is not used */
997 best.regm_dsi = 0;
998 best.dsi_pll_hsdiv_dsi_clk = 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200999
1000 if (dsi_cinfo)
1001 *dsi_cinfo = best;
1002 if (dispc_cinfo)
1003 *dispc_cinfo = best_dispc;
1004
1005 dsi.cache_req_pck = req_pck;
1006 dsi.cache_clk_freq = 0;
1007 dsi.cache_cinfo = best;
1008
1009 return 0;
1010}
1011
1012int dsi_pll_set_clock_div(struct dsi_clock_info *cinfo)
1013{
1014 int r = 0;
1015 u32 l;
1016 int f;
Taneja, Archit49641112011-03-14 23:28:23 -05001017 u8 regn_start, regn_end, regm_start, regm_end;
1018 u8 regm_dispc_start, regm_dispc_end, regm_dsi_start, regm_dsi_end;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001019
1020 DSSDBGF();
1021
1022 dsi.current_cinfo.fint = cinfo->fint;
1023 dsi.current_cinfo.clkin4ddr = cinfo->clkin4ddr;
Archit Taneja1bb47832011-02-24 14:17:30 +05301024 dsi.current_cinfo.dsi_pll_hsdiv_dispc_clk =
1025 cinfo->dsi_pll_hsdiv_dispc_clk;
1026 dsi.current_cinfo.dsi_pll_hsdiv_dsi_clk =
1027 cinfo->dsi_pll_hsdiv_dsi_clk;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001028
1029 dsi.current_cinfo.regn = cinfo->regn;
1030 dsi.current_cinfo.regm = cinfo->regm;
Archit Taneja1bb47832011-02-24 14:17:30 +05301031 dsi.current_cinfo.regm_dispc = cinfo->regm_dispc;
1032 dsi.current_cinfo.regm_dsi = cinfo->regm_dsi;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001033
1034 DSSDBG("DSI Fint %ld\n", cinfo->fint);
1035
1036 DSSDBG("clkin (%s) rate %ld, highfreq %d\n",
Archit Taneja1bb47832011-02-24 14:17:30 +05301037 cinfo->use_sys_clk ? "dss_sys_clk" : "pclkfree",
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001038 cinfo->clkin,
1039 cinfo->highfreq);
1040
1041 /* DSIPHY == CLKIN4DDR */
1042 DSSDBG("CLKIN4DDR = 2 * %d / %d * %lu / %d = %lu\n",
1043 cinfo->regm,
1044 cinfo->regn,
1045 cinfo->clkin,
1046 cinfo->highfreq + 1,
1047 cinfo->clkin4ddr);
1048
1049 DSSDBG("Data rate on 1 DSI lane %ld Mbps\n",
1050 cinfo->clkin4ddr / 1000 / 1000 / 2);
1051
1052 DSSDBG("Clock lane freq %ld Hz\n", cinfo->clkin4ddr / 4);
1053
Archit Taneja1bb47832011-02-24 14:17:30 +05301054 DSSDBG("regm_dispc = %d, %s (%s) = %lu\n", cinfo->regm_dispc,
Archit Taneja067a57e2011-03-02 11:57:25 +05301055 dss_get_generic_clk_source_name(DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
1056 dss_feat_get_clk_source_name(DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
Archit Taneja1bb47832011-02-24 14:17:30 +05301057 cinfo->dsi_pll_hsdiv_dispc_clk);
1058 DSSDBG("regm_dsi = %d, %s (%s) = %lu\n", cinfo->regm_dsi,
Archit Taneja067a57e2011-03-02 11:57:25 +05301059 dss_get_generic_clk_source_name(DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
1060 dss_feat_get_clk_source_name(DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
Archit Taneja1bb47832011-02-24 14:17:30 +05301061 cinfo->dsi_pll_hsdiv_dsi_clk);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001062
Taneja, Archit49641112011-03-14 23:28:23 -05001063 dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGN, &regn_start, &regn_end);
1064 dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM, &regm_start, &regm_end);
1065 dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM_DISPC, &regm_dispc_start,
1066 &regm_dispc_end);
1067 dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM_DSI, &regm_dsi_start,
1068 &regm_dsi_end);
1069
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001070 REG_FLD_MOD(DSI_PLL_CONTROL, 0, 0, 0); /* DSI_PLL_AUTOMODE = manual */
1071
1072 l = dsi_read_reg(DSI_PLL_CONFIGURATION1);
1073 l = FLD_MOD(l, 1, 0, 0); /* DSI_PLL_STOPMODE */
Taneja, Archit49641112011-03-14 23:28:23 -05001074 /* DSI_PLL_REGN */
1075 l = FLD_MOD(l, cinfo->regn - 1, regn_start, regn_end);
1076 /* DSI_PLL_REGM */
1077 l = FLD_MOD(l, cinfo->regm, regm_start, regm_end);
1078 /* DSI_CLOCK_DIV */
Archit Taneja1bb47832011-02-24 14:17:30 +05301079 l = FLD_MOD(l, cinfo->regm_dispc > 0 ? cinfo->regm_dispc - 1 : 0,
Taneja, Archit49641112011-03-14 23:28:23 -05001080 regm_dispc_start, regm_dispc_end);
1081 /* DSIPROTO_CLOCK_DIV */
Archit Taneja1bb47832011-02-24 14:17:30 +05301082 l = FLD_MOD(l, cinfo->regm_dsi > 0 ? cinfo->regm_dsi - 1 : 0,
Taneja, Archit49641112011-03-14 23:28:23 -05001083 regm_dsi_start, regm_dsi_end);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001084 dsi_write_reg(DSI_PLL_CONFIGURATION1, l);
1085
Taneja, Archit49641112011-03-14 23:28:23 -05001086 BUG_ON(cinfo->fint < dsi.fint_min || cinfo->fint > dsi.fint_max);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001087 if (cinfo->fint < 1000000)
1088 f = 0x3;
1089 else if (cinfo->fint < 1250000)
1090 f = 0x4;
1091 else if (cinfo->fint < 1500000)
1092 f = 0x5;
1093 else if (cinfo->fint < 1750000)
1094 f = 0x6;
1095 else
1096 f = 0x7;
1097
1098 l = dsi_read_reg(DSI_PLL_CONFIGURATION2);
1099 l = FLD_MOD(l, f, 4, 1); /* DSI_PLL_FREQSEL */
Archit Taneja1bb47832011-02-24 14:17:30 +05301100 l = FLD_MOD(l, cinfo->use_sys_clk ? 0 : 1,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001101 11, 11); /* DSI_PLL_CLKSEL */
1102 l = FLD_MOD(l, cinfo->highfreq,
1103 12, 12); /* DSI_PLL_HIGHFREQ */
1104 l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */
1105 l = FLD_MOD(l, 0, 14, 14); /* DSIPHY_CLKINEN */
1106 l = FLD_MOD(l, 1, 20, 20); /* DSI_HSDIVBYPASS */
1107 dsi_write_reg(DSI_PLL_CONFIGURATION2, l);
1108
1109 REG_FLD_MOD(DSI_PLL_GO, 1, 0, 0); /* DSI_PLL_GO */
1110
1111 if (wait_for_bit_change(DSI_PLL_GO, 0, 0) != 0) {
1112 DSSERR("dsi pll go bit not going down.\n");
1113 r = -EIO;
1114 goto err;
1115 }
1116
1117 if (wait_for_bit_change(DSI_PLL_STATUS, 1, 1) != 1) {
1118 DSSERR("cannot lock PLL\n");
1119 r = -EIO;
1120 goto err;
1121 }
1122
1123 dsi.pll_locked = 1;
1124
1125 l = dsi_read_reg(DSI_PLL_CONFIGURATION2);
1126 l = FLD_MOD(l, 0, 0, 0); /* DSI_PLL_IDLE */
1127 l = FLD_MOD(l, 0, 5, 5); /* DSI_PLL_PLLLPMODE */
1128 l = FLD_MOD(l, 0, 6, 6); /* DSI_PLL_LOWCURRSTBY */
1129 l = FLD_MOD(l, 0, 7, 7); /* DSI_PLL_TIGHTPHASELOCK */
1130 l = FLD_MOD(l, 0, 8, 8); /* DSI_PLL_DRIFTGUARDEN */
1131 l = FLD_MOD(l, 0, 10, 9); /* DSI_PLL_LOCKSEL */
1132 l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */
1133 l = FLD_MOD(l, 1, 14, 14); /* DSIPHY_CLKINEN */
1134 l = FLD_MOD(l, 0, 15, 15); /* DSI_BYPASSEN */
1135 l = FLD_MOD(l, 1, 16, 16); /* DSS_CLOCK_EN */
1136 l = FLD_MOD(l, 0, 17, 17); /* DSS_CLOCK_PWDN */
1137 l = FLD_MOD(l, 1, 18, 18); /* DSI_PROTO_CLOCK_EN */
1138 l = FLD_MOD(l, 0, 19, 19); /* DSI_PROTO_CLOCK_PWDN */
1139 l = FLD_MOD(l, 0, 20, 20); /* DSI_HSDIVBYPASS */
1140 dsi_write_reg(DSI_PLL_CONFIGURATION2, l);
1141
1142 DSSDBG("PLL config done\n");
1143err:
1144 return r;
1145}
1146
1147int dsi_pll_init(struct omap_dss_device *dssdev, bool enable_hsclk,
1148 bool enable_hsdiv)
1149{
1150 int r = 0;
1151 enum dsi_pll_power_state pwstate;
1152
1153 DSSDBG("PLL init\n");
1154
Tomi Valkeinenf2988ab2011-03-02 10:06:48 +02001155#ifdef CONFIG_OMAP2_DSS_USE_DSI_PLL
1156 /*
1157 * HACK: this is just a quick hack to get the USE_DSI_PLL
1158 * option working. USE_DSI_PLL is itself a big hack, and
1159 * should be removed.
1160 */
1161 if (dsi.vdds_dsi_reg == NULL) {
1162 struct regulator *vdds_dsi;
1163
1164 vdds_dsi = regulator_get(&dsi.pdev->dev, "vdds_dsi");
1165
1166 if (IS_ERR(vdds_dsi)) {
1167 DSSERR("can't get VDDS_DSI regulator\n");
1168 return PTR_ERR(vdds_dsi);
1169 }
1170
1171 dsi.vdds_dsi_reg = vdds_dsi;
1172 }
1173#endif
1174
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001175 enable_clocks(1);
1176 dsi_enable_pll_clock(1);
1177
1178 r = regulator_enable(dsi.vdds_dsi_reg);
1179 if (r)
1180 goto err0;
1181
1182 /* XXX PLL does not come out of reset without this... */
1183 dispc_pck_free_enable(1);
1184
1185 if (wait_for_bit_change(DSI_PLL_STATUS, 0, 1) != 1) {
1186 DSSERR("PLL not coming out of reset.\n");
1187 r = -ENODEV;
Ville Syrjälä481dfa02010-04-22 22:50:04 +02001188 dispc_pck_free_enable(0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001189 goto err1;
1190 }
1191
1192 /* XXX ... but if left on, we get problems when planes do not
1193 * fill the whole display. No idea about this */
1194 dispc_pck_free_enable(0);
1195
1196 if (enable_hsclk && enable_hsdiv)
1197 pwstate = DSI_PLL_POWER_ON_ALL;
1198 else if (enable_hsclk)
1199 pwstate = DSI_PLL_POWER_ON_HSCLK;
1200 else if (enable_hsdiv)
1201 pwstate = DSI_PLL_POWER_ON_DIV;
1202 else
1203 pwstate = DSI_PLL_POWER_OFF;
1204
1205 r = dsi_pll_power(pwstate);
1206
1207 if (r)
1208 goto err1;
1209
1210 DSSDBG("PLL init done\n");
1211
1212 return 0;
1213err1:
1214 regulator_disable(dsi.vdds_dsi_reg);
1215err0:
1216 enable_clocks(0);
1217 dsi_enable_pll_clock(0);
1218 return r;
1219}
1220
1221void dsi_pll_uninit(void)
1222{
1223 enable_clocks(0);
1224 dsi_enable_pll_clock(0);
1225
1226 dsi.pll_locked = 0;
1227 dsi_pll_power(DSI_PLL_POWER_OFF);
1228 regulator_disable(dsi.vdds_dsi_reg);
1229 DSSDBG("PLL uninit done\n");
1230}
1231
1232void dsi_dump_clocks(struct seq_file *s)
1233{
1234 int clksel;
1235 struct dsi_clock_info *cinfo = &dsi.current_cinfo;
Archit Taneja067a57e2011-03-02 11:57:25 +05301236 enum dss_clk_source dispc_clk_src, dsi_clk_src;
1237
1238 dispc_clk_src = dss_get_dispc_clk_source();
1239 dsi_clk_src = dss_get_dsi_clk_source();
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001240
1241 enable_clocks(1);
1242
1243 clksel = REG_GET(DSI_PLL_CONFIGURATION2, 11, 11);
1244
1245 seq_printf(s, "- DSI PLL -\n");
1246
1247 seq_printf(s, "dsi pll source = %s\n",
1248 clksel == 0 ?
Archit Taneja1bb47832011-02-24 14:17:30 +05301249 "dss_sys_clk" : "pclkfree");
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001250
1251 seq_printf(s, "Fint\t\t%-16luregn %u\n", cinfo->fint, cinfo->regn);
1252
1253 seq_printf(s, "CLKIN4DDR\t%-16luregm %u\n",
1254 cinfo->clkin4ddr, cinfo->regm);
1255
Archit Taneja1bb47832011-02-24 14:17:30 +05301256 seq_printf(s, "%s (%s)\t%-16luregm_dispc %u\t(%s)\n",
Archit Taneja067a57e2011-03-02 11:57:25 +05301257 dss_get_generic_clk_source_name(dispc_clk_src),
1258 dss_feat_get_clk_source_name(dispc_clk_src),
Archit Taneja1bb47832011-02-24 14:17:30 +05301259 cinfo->dsi_pll_hsdiv_dispc_clk,
1260 cinfo->regm_dispc,
Archit Taneja067a57e2011-03-02 11:57:25 +05301261 dispc_clk_src == DSS_CLK_SRC_FCK ?
Tomi Valkeinen63cf28a2010-02-23 17:40:00 +02001262 "off" : "on");
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001263
Archit Taneja1bb47832011-02-24 14:17:30 +05301264 seq_printf(s, "%s (%s)\t%-16luregm_dsi %u\t(%s)\n",
Archit Taneja067a57e2011-03-02 11:57:25 +05301265 dss_get_generic_clk_source_name(dsi_clk_src),
1266 dss_feat_get_clk_source_name(dsi_clk_src),
Archit Taneja1bb47832011-02-24 14:17:30 +05301267 cinfo->dsi_pll_hsdiv_dsi_clk,
1268 cinfo->regm_dsi,
Archit Taneja067a57e2011-03-02 11:57:25 +05301269 dsi_clk_src == DSS_CLK_SRC_FCK ?
Tomi Valkeinen63cf28a2010-02-23 17:40:00 +02001270 "off" : "on");
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001271
1272 seq_printf(s, "- DSI -\n");
1273
Archit Taneja067a57e2011-03-02 11:57:25 +05301274 seq_printf(s, "dsi fclk source = %s (%s)\n",
1275 dss_get_generic_clk_source_name(dsi_clk_src),
1276 dss_feat_get_clk_source_name(dsi_clk_src));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001277
1278 seq_printf(s, "DSI_FCLK\t%lu\n", dsi_fclk_rate());
1279
1280 seq_printf(s, "DDR_CLK\t\t%lu\n",
1281 cinfo->clkin4ddr / 4);
1282
1283 seq_printf(s, "TxByteClkHS\t%lu\n", dsi_get_txbyteclkhs());
1284
1285 seq_printf(s, "LP_CLK\t\t%lu\n", cinfo->lp_clk);
1286
1287 seq_printf(s, "VP_CLK\t\t%lu\n"
1288 "VP_PCLK\t\t%lu\n",
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00001289 dispc_lclk_rate(OMAP_DSS_CHANNEL_LCD),
1290 dispc_pclk_rate(OMAP_DSS_CHANNEL_LCD));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001291
1292 enable_clocks(0);
1293}
1294
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001295#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
1296void dsi_dump_irqs(struct seq_file *s)
1297{
1298 unsigned long flags;
1299 struct dsi_irq_stats stats;
1300
1301 spin_lock_irqsave(&dsi.irq_stats_lock, flags);
1302
1303 stats = dsi.irq_stats;
1304 memset(&dsi.irq_stats, 0, sizeof(dsi.irq_stats));
1305 dsi.irq_stats.last_reset = jiffies;
1306
1307 spin_unlock_irqrestore(&dsi.irq_stats_lock, flags);
1308
1309 seq_printf(s, "period %u ms\n",
1310 jiffies_to_msecs(jiffies - stats.last_reset));
1311
1312 seq_printf(s, "irqs %d\n", stats.irq_count);
1313#define PIS(x) \
1314 seq_printf(s, "%-20s %10d\n", #x, stats.dsi_irqs[ffs(DSI_IRQ_##x)-1]);
1315
1316 seq_printf(s, "-- DSI interrupts --\n");
1317 PIS(VC0);
1318 PIS(VC1);
1319 PIS(VC2);
1320 PIS(VC3);
1321 PIS(WAKEUP);
1322 PIS(RESYNC);
1323 PIS(PLL_LOCK);
1324 PIS(PLL_UNLOCK);
1325 PIS(PLL_RECALL);
1326 PIS(COMPLEXIO_ERR);
1327 PIS(HS_TX_TIMEOUT);
1328 PIS(LP_RX_TIMEOUT);
1329 PIS(TE_TRIGGER);
1330 PIS(ACK_TRIGGER);
1331 PIS(SYNC_LOST);
1332 PIS(LDO_POWER_GOOD);
1333 PIS(TA_TIMEOUT);
1334#undef PIS
1335
1336#define PIS(x) \
1337 seq_printf(s, "%-20s %10d %10d %10d %10d\n", #x, \
1338 stats.vc_irqs[0][ffs(DSI_VC_IRQ_##x)-1], \
1339 stats.vc_irqs[1][ffs(DSI_VC_IRQ_##x)-1], \
1340 stats.vc_irqs[2][ffs(DSI_VC_IRQ_##x)-1], \
1341 stats.vc_irqs[3][ffs(DSI_VC_IRQ_##x)-1]);
1342
1343 seq_printf(s, "-- VC interrupts --\n");
1344 PIS(CS);
1345 PIS(ECC_CORR);
1346 PIS(PACKET_SENT);
1347 PIS(FIFO_TX_OVF);
1348 PIS(FIFO_RX_OVF);
1349 PIS(BTA);
1350 PIS(ECC_NO_CORR);
1351 PIS(FIFO_TX_UDF);
1352 PIS(PP_BUSY_CHANGE);
1353#undef PIS
1354
1355#define PIS(x) \
1356 seq_printf(s, "%-20s %10d\n", #x, \
1357 stats.cio_irqs[ffs(DSI_CIO_IRQ_##x)-1]);
1358
1359 seq_printf(s, "-- CIO interrupts --\n");
1360 PIS(ERRSYNCESC1);
1361 PIS(ERRSYNCESC2);
1362 PIS(ERRSYNCESC3);
1363 PIS(ERRESC1);
1364 PIS(ERRESC2);
1365 PIS(ERRESC3);
1366 PIS(ERRCONTROL1);
1367 PIS(ERRCONTROL2);
1368 PIS(ERRCONTROL3);
1369 PIS(STATEULPS1);
1370 PIS(STATEULPS2);
1371 PIS(STATEULPS3);
1372 PIS(ERRCONTENTIONLP0_1);
1373 PIS(ERRCONTENTIONLP1_1);
1374 PIS(ERRCONTENTIONLP0_2);
1375 PIS(ERRCONTENTIONLP1_2);
1376 PIS(ERRCONTENTIONLP0_3);
1377 PIS(ERRCONTENTIONLP1_3);
1378 PIS(ULPSACTIVENOT_ALL0);
1379 PIS(ULPSACTIVENOT_ALL1);
1380#undef PIS
1381}
1382#endif
1383
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001384void dsi_dump_regs(struct seq_file *s)
1385{
1386#define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dsi_read_reg(r))
1387
Archit Taneja6af9cd12011-01-31 16:27:44 +00001388 dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001389
1390 DUMPREG(DSI_REVISION);
1391 DUMPREG(DSI_SYSCONFIG);
1392 DUMPREG(DSI_SYSSTATUS);
1393 DUMPREG(DSI_IRQSTATUS);
1394 DUMPREG(DSI_IRQENABLE);
1395 DUMPREG(DSI_CTRL);
1396 DUMPREG(DSI_COMPLEXIO_CFG1);
1397 DUMPREG(DSI_COMPLEXIO_IRQ_STATUS);
1398 DUMPREG(DSI_COMPLEXIO_IRQ_ENABLE);
1399 DUMPREG(DSI_CLK_CTRL);
1400 DUMPREG(DSI_TIMING1);
1401 DUMPREG(DSI_TIMING2);
1402 DUMPREG(DSI_VM_TIMING1);
1403 DUMPREG(DSI_VM_TIMING2);
1404 DUMPREG(DSI_VM_TIMING3);
1405 DUMPREG(DSI_CLK_TIMING);
1406 DUMPREG(DSI_TX_FIFO_VC_SIZE);
1407 DUMPREG(DSI_RX_FIFO_VC_SIZE);
1408 DUMPREG(DSI_COMPLEXIO_CFG2);
1409 DUMPREG(DSI_RX_FIFO_VC_FULLNESS);
1410 DUMPREG(DSI_VM_TIMING4);
1411 DUMPREG(DSI_TX_FIFO_VC_EMPTINESS);
1412 DUMPREG(DSI_VM_TIMING5);
1413 DUMPREG(DSI_VM_TIMING6);
1414 DUMPREG(DSI_VM_TIMING7);
1415 DUMPREG(DSI_STOPCLK_TIMING);
1416
1417 DUMPREG(DSI_VC_CTRL(0));
1418 DUMPREG(DSI_VC_TE(0));
1419 DUMPREG(DSI_VC_LONG_PACKET_HEADER(0));
1420 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(0));
1421 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(0));
1422 DUMPREG(DSI_VC_IRQSTATUS(0));
1423 DUMPREG(DSI_VC_IRQENABLE(0));
1424
1425 DUMPREG(DSI_VC_CTRL(1));
1426 DUMPREG(DSI_VC_TE(1));
1427 DUMPREG(DSI_VC_LONG_PACKET_HEADER(1));
1428 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(1));
1429 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(1));
1430 DUMPREG(DSI_VC_IRQSTATUS(1));
1431 DUMPREG(DSI_VC_IRQENABLE(1));
1432
1433 DUMPREG(DSI_VC_CTRL(2));
1434 DUMPREG(DSI_VC_TE(2));
1435 DUMPREG(DSI_VC_LONG_PACKET_HEADER(2));
1436 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(2));
1437 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(2));
1438 DUMPREG(DSI_VC_IRQSTATUS(2));
1439 DUMPREG(DSI_VC_IRQENABLE(2));
1440
1441 DUMPREG(DSI_VC_CTRL(3));
1442 DUMPREG(DSI_VC_TE(3));
1443 DUMPREG(DSI_VC_LONG_PACKET_HEADER(3));
1444 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(3));
1445 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(3));
1446 DUMPREG(DSI_VC_IRQSTATUS(3));
1447 DUMPREG(DSI_VC_IRQENABLE(3));
1448
1449 DUMPREG(DSI_DSIPHY_CFG0);
1450 DUMPREG(DSI_DSIPHY_CFG1);
1451 DUMPREG(DSI_DSIPHY_CFG2);
1452 DUMPREG(DSI_DSIPHY_CFG5);
1453
1454 DUMPREG(DSI_PLL_CONTROL);
1455 DUMPREG(DSI_PLL_STATUS);
1456 DUMPREG(DSI_PLL_GO);
1457 DUMPREG(DSI_PLL_CONFIGURATION1);
1458 DUMPREG(DSI_PLL_CONFIGURATION2);
1459
Archit Taneja6af9cd12011-01-31 16:27:44 +00001460 dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001461#undef DUMPREG
1462}
1463
1464enum dsi_complexio_power_state {
1465 DSI_COMPLEXIO_POWER_OFF = 0x0,
1466 DSI_COMPLEXIO_POWER_ON = 0x1,
1467 DSI_COMPLEXIO_POWER_ULPS = 0x2,
1468};
1469
1470static int dsi_complexio_power(enum dsi_complexio_power_state state)
1471{
1472 int t = 0;
1473
1474 /* PWR_CMD */
1475 REG_FLD_MOD(DSI_COMPLEXIO_CFG1, state, 28, 27);
1476
1477 /* PWR_STATUS */
1478 while (FLD_GET(dsi_read_reg(DSI_COMPLEXIO_CFG1), 26, 25) != state) {
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02001479 if (++t > 1000) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001480 DSSERR("failed to set complexio power state to "
1481 "%d\n", state);
1482 return -ENODEV;
1483 }
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02001484 udelay(1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001485 }
1486
1487 return 0;
1488}
1489
1490static void dsi_complexio_config(struct omap_dss_device *dssdev)
1491{
1492 u32 r;
1493
1494 int clk_lane = dssdev->phy.dsi.clk_lane;
1495 int data1_lane = dssdev->phy.dsi.data1_lane;
1496 int data2_lane = dssdev->phy.dsi.data2_lane;
1497 int clk_pol = dssdev->phy.dsi.clk_pol;
1498 int data1_pol = dssdev->phy.dsi.data1_pol;
1499 int data2_pol = dssdev->phy.dsi.data2_pol;
1500
1501 r = dsi_read_reg(DSI_COMPLEXIO_CFG1);
1502 r = FLD_MOD(r, clk_lane, 2, 0);
1503 r = FLD_MOD(r, clk_pol, 3, 3);
1504 r = FLD_MOD(r, data1_lane, 6, 4);
1505 r = FLD_MOD(r, data1_pol, 7, 7);
1506 r = FLD_MOD(r, data2_lane, 10, 8);
1507 r = FLD_MOD(r, data2_pol, 11, 11);
1508 dsi_write_reg(DSI_COMPLEXIO_CFG1, r);
1509
1510 /* The configuration of the DSI complex I/O (number of data lanes,
1511 position, differential order) should not be changed while
1512 DSS.DSI_CLK_CRTRL[20] LP_CLK_ENABLE bit is set to 1. In order for
1513 the hardware to take into account a new configuration of the complex
1514 I/O (done in DSS.DSI_COMPLEXIO_CFG1 register), it is recommended to
1515 follow this sequence: First set the DSS.DSI_CTRL[0] IF_EN bit to 1,
1516 then reset the DSS.DSI_CTRL[0] IF_EN to 0, then set
1517 DSS.DSI_CLK_CTRL[20] LP_CLK_ENABLE to 1 and finally set again the
1518 DSS.DSI_CTRL[0] IF_EN bit to 1. If the sequence is not followed, the
1519 DSI complex I/O configuration is unknown. */
1520
1521 /*
1522 REG_FLD_MOD(DSI_CTRL, 1, 0, 0);
1523 REG_FLD_MOD(DSI_CTRL, 0, 0, 0);
1524 REG_FLD_MOD(DSI_CLK_CTRL, 1, 20, 20);
1525 REG_FLD_MOD(DSI_CTRL, 1, 0, 0);
1526 */
1527}
1528
1529static inline unsigned ns2ddr(unsigned ns)
1530{
1531 /* convert time in ns to ddr ticks, rounding up */
1532 unsigned long ddr_clk = dsi.current_cinfo.clkin4ddr / 4;
1533 return (ns * (ddr_clk / 1000 / 1000) + 999) / 1000;
1534}
1535
1536static inline unsigned ddr2ns(unsigned ddr)
1537{
1538 unsigned long ddr_clk = dsi.current_cinfo.clkin4ddr / 4;
1539 return ddr * 1000 * 1000 / (ddr_clk / 1000);
1540}
1541
1542static void dsi_complexio_timings(void)
1543{
1544 u32 r;
1545 u32 ths_prepare, ths_prepare_ths_zero, ths_trail, ths_exit;
1546 u32 tlpx_half, tclk_trail, tclk_zero;
1547 u32 tclk_prepare;
1548
1549 /* calculate timings */
1550
1551 /* 1 * DDR_CLK = 2 * UI */
1552
1553 /* min 40ns + 4*UI max 85ns + 6*UI */
1554 ths_prepare = ns2ddr(70) + 2;
1555
1556 /* min 145ns + 10*UI */
1557 ths_prepare_ths_zero = ns2ddr(175) + 2;
1558
1559 /* min max(8*UI, 60ns+4*UI) */
1560 ths_trail = ns2ddr(60) + 5;
1561
1562 /* min 100ns */
1563 ths_exit = ns2ddr(145);
1564
1565 /* tlpx min 50n */
1566 tlpx_half = ns2ddr(25);
1567
1568 /* min 60ns */
1569 tclk_trail = ns2ddr(60) + 2;
1570
1571 /* min 38ns, max 95ns */
1572 tclk_prepare = ns2ddr(65);
1573
1574 /* min tclk-prepare + tclk-zero = 300ns */
1575 tclk_zero = ns2ddr(260);
1576
1577 DSSDBG("ths_prepare %u (%uns), ths_prepare_ths_zero %u (%uns)\n",
1578 ths_prepare, ddr2ns(ths_prepare),
1579 ths_prepare_ths_zero, ddr2ns(ths_prepare_ths_zero));
1580 DSSDBG("ths_trail %u (%uns), ths_exit %u (%uns)\n",
1581 ths_trail, ddr2ns(ths_trail),
1582 ths_exit, ddr2ns(ths_exit));
1583
1584 DSSDBG("tlpx_half %u (%uns), tclk_trail %u (%uns), "
1585 "tclk_zero %u (%uns)\n",
1586 tlpx_half, ddr2ns(tlpx_half),
1587 tclk_trail, ddr2ns(tclk_trail),
1588 tclk_zero, ddr2ns(tclk_zero));
1589 DSSDBG("tclk_prepare %u (%uns)\n",
1590 tclk_prepare, ddr2ns(tclk_prepare));
1591
1592 /* program timings */
1593
1594 r = dsi_read_reg(DSI_DSIPHY_CFG0);
1595 r = FLD_MOD(r, ths_prepare, 31, 24);
1596 r = FLD_MOD(r, ths_prepare_ths_zero, 23, 16);
1597 r = FLD_MOD(r, ths_trail, 15, 8);
1598 r = FLD_MOD(r, ths_exit, 7, 0);
1599 dsi_write_reg(DSI_DSIPHY_CFG0, r);
1600
1601 r = dsi_read_reg(DSI_DSIPHY_CFG1);
1602 r = FLD_MOD(r, tlpx_half, 22, 16);
1603 r = FLD_MOD(r, tclk_trail, 15, 8);
1604 r = FLD_MOD(r, tclk_zero, 7, 0);
1605 dsi_write_reg(DSI_DSIPHY_CFG1, r);
1606
1607 r = dsi_read_reg(DSI_DSIPHY_CFG2);
1608 r = FLD_MOD(r, tclk_prepare, 7, 0);
1609 dsi_write_reg(DSI_DSIPHY_CFG2, r);
1610}
1611
1612
1613static int dsi_complexio_init(struct omap_dss_device *dssdev)
1614{
1615 int r = 0;
1616
1617 DSSDBG("dsi_complexio_init\n");
1618
1619 /* CIO_CLK_ICG, enable L3 clk to CIO */
1620 REG_FLD_MOD(DSI_CLK_CTRL, 1, 14, 14);
1621
1622 /* A dummy read using the SCP interface to any DSIPHY register is
1623 * required after DSIPHY reset to complete the reset of the DSI complex
1624 * I/O. */
1625 dsi_read_reg(DSI_DSIPHY_CFG5);
1626
1627 if (wait_for_bit_change(DSI_DSIPHY_CFG5, 30, 1) != 1) {
1628 DSSERR("ComplexIO PHY not coming out of reset.\n");
1629 r = -ENODEV;
1630 goto err;
1631 }
1632
1633 dsi_complexio_config(dssdev);
1634
1635 r = dsi_complexio_power(DSI_COMPLEXIO_POWER_ON);
1636
1637 if (r)
1638 goto err;
1639
1640 if (wait_for_bit_change(DSI_COMPLEXIO_CFG1, 29, 1) != 1) {
1641 DSSERR("ComplexIO not coming out of reset.\n");
1642 r = -ENODEV;
1643 goto err;
1644 }
1645
1646 if (wait_for_bit_change(DSI_COMPLEXIO_CFG1, 21, 1) != 1) {
1647 DSSERR("ComplexIO LDO power down.\n");
1648 r = -ENODEV;
1649 goto err;
1650 }
1651
1652 dsi_complexio_timings();
1653
1654 /*
1655 The configuration of the DSI complex I/O (number of data lanes,
1656 position, differential order) should not be changed while
1657 DSS.DSI_CLK_CRTRL[20] LP_CLK_ENABLE bit is set to 1. For the
1658 hardware to recognize a new configuration of the complex I/O (done
1659 in DSS.DSI_COMPLEXIO_CFG1 register), it is recommended to follow
1660 this sequence: First set the DSS.DSI_CTRL[0] IF_EN bit to 1, next
1661 reset the DSS.DSI_CTRL[0] IF_EN to 0, then set DSS.DSI_CLK_CTRL[20]
1662 LP_CLK_ENABLE to 1, and finally, set again the DSS.DSI_CTRL[0] IF_EN
1663 bit to 1. If the sequence is not followed, the DSi complex I/O
1664 configuration is undetermined.
1665 */
1666 dsi_if_enable(1);
1667 dsi_if_enable(0);
1668 REG_FLD_MOD(DSI_CLK_CTRL, 1, 20, 20); /* LP_CLK_ENABLE */
1669 dsi_if_enable(1);
1670 dsi_if_enable(0);
1671
1672 DSSDBG("CIO init done\n");
1673err:
1674 return r;
1675}
1676
1677static void dsi_complexio_uninit(void)
1678{
1679 dsi_complexio_power(DSI_COMPLEXIO_POWER_OFF);
1680}
1681
1682static int _dsi_wait_reset(void)
1683{
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02001684 int t = 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001685
1686 while (REG_GET(DSI_SYSSTATUS, 0, 0) == 0) {
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02001687 if (++t > 5) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001688 DSSERR("soft reset failed\n");
1689 return -ENODEV;
1690 }
1691 udelay(1);
1692 }
1693
1694 return 0;
1695}
1696
1697static int _dsi_reset(void)
1698{
1699 /* Soft reset */
1700 REG_FLD_MOD(DSI_SYSCONFIG, 1, 1, 1);
1701 return _dsi_wait_reset();
1702}
1703
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001704static void dsi_config_tx_fifo(enum fifo_size size1, enum fifo_size size2,
1705 enum fifo_size size3, enum fifo_size size4)
1706{
1707 u32 r = 0;
1708 int add = 0;
1709 int i;
1710
1711 dsi.vc[0].fifo_size = size1;
1712 dsi.vc[1].fifo_size = size2;
1713 dsi.vc[2].fifo_size = size3;
1714 dsi.vc[3].fifo_size = size4;
1715
1716 for (i = 0; i < 4; i++) {
1717 u8 v;
1718 int size = dsi.vc[i].fifo_size;
1719
1720 if (add + size > 4) {
1721 DSSERR("Illegal FIFO configuration\n");
1722 BUG();
1723 }
1724
1725 v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
1726 r |= v << (8 * i);
1727 /*DSSDBG("TX FIFO vc %d: size %d, add %d\n", i, size, add); */
1728 add += size;
1729 }
1730
1731 dsi_write_reg(DSI_TX_FIFO_VC_SIZE, r);
1732}
1733
1734static void dsi_config_rx_fifo(enum fifo_size size1, enum fifo_size size2,
1735 enum fifo_size size3, enum fifo_size size4)
1736{
1737 u32 r = 0;
1738 int add = 0;
1739 int i;
1740
1741 dsi.vc[0].fifo_size = size1;
1742 dsi.vc[1].fifo_size = size2;
1743 dsi.vc[2].fifo_size = size3;
1744 dsi.vc[3].fifo_size = size4;
1745
1746 for (i = 0; i < 4; i++) {
1747 u8 v;
1748 int size = dsi.vc[i].fifo_size;
1749
1750 if (add + size > 4) {
1751 DSSERR("Illegal FIFO configuration\n");
1752 BUG();
1753 }
1754
1755 v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
1756 r |= v << (8 * i);
1757 /*DSSDBG("RX FIFO vc %d: size %d, add %d\n", i, size, add); */
1758 add += size;
1759 }
1760
1761 dsi_write_reg(DSI_RX_FIFO_VC_SIZE, r);
1762}
1763
1764static int dsi_force_tx_stop_mode_io(void)
1765{
1766 u32 r;
1767
1768 r = dsi_read_reg(DSI_TIMING1);
1769 r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
1770 dsi_write_reg(DSI_TIMING1, r);
1771
1772 if (wait_for_bit_change(DSI_TIMING1, 15, 0) != 0) {
1773 DSSERR("TX_STOP bit not going down\n");
1774 return -EIO;
1775 }
1776
1777 return 0;
1778}
1779
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001780static int dsi_vc_enable(int channel, bool enable)
1781{
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +02001782 DSSDBG("dsi_vc_enable channel %d, enable %d\n",
1783 channel, enable);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001784
1785 enable = enable ? 1 : 0;
1786
1787 REG_FLD_MOD(DSI_VC_CTRL(channel), enable, 0, 0);
1788
1789 if (wait_for_bit_change(DSI_VC_CTRL(channel), 0, enable) != enable) {
1790 DSSERR("Failed to set dsi_vc_enable to %d\n", enable);
1791 return -EIO;
1792 }
1793
1794 return 0;
1795}
1796
1797static void dsi_vc_initial_config(int channel)
1798{
1799 u32 r;
1800
1801 DSSDBGF("%d", channel);
1802
1803 r = dsi_read_reg(DSI_VC_CTRL(channel));
1804
1805 if (FLD_GET(r, 15, 15)) /* VC_BUSY */
1806 DSSERR("VC(%d) busy when trying to configure it!\n",
1807 channel);
1808
1809 r = FLD_MOD(r, 0, 1, 1); /* SOURCE, 0 = L4 */
1810 r = FLD_MOD(r, 0, 2, 2); /* BTA_SHORT_EN */
1811 r = FLD_MOD(r, 0, 3, 3); /* BTA_LONG_EN */
1812 r = FLD_MOD(r, 0, 4, 4); /* MODE, 0 = command */
1813 r = FLD_MOD(r, 1, 7, 7); /* CS_TX_EN */
1814 r = FLD_MOD(r, 1, 8, 8); /* ECC_TX_EN */
1815 r = FLD_MOD(r, 0, 9, 9); /* MODE_SPEED, high speed on/off */
1816
1817 r = FLD_MOD(r, 4, 29, 27); /* DMA_RX_REQ_NB = no dma */
1818 r = FLD_MOD(r, 4, 23, 21); /* DMA_TX_REQ_NB = no dma */
1819
1820 dsi_write_reg(DSI_VC_CTRL(channel), r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001821}
1822
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03001823static int dsi_vc_config_l4(int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001824{
1825 if (dsi.vc[channel].mode == DSI_VC_MODE_L4)
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03001826 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001827
1828 DSSDBGF("%d", channel);
1829
1830 dsi_vc_enable(channel, 0);
1831
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03001832 /* VC_BUSY */
1833 if (wait_for_bit_change(DSI_VC_CTRL(channel), 15, 0) != 0) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001834 DSSERR("vc(%d) busy when trying to config for L4\n", channel);
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03001835 return -EIO;
1836 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001837
1838 REG_FLD_MOD(DSI_VC_CTRL(channel), 0, 1, 1); /* SOURCE, 0 = L4 */
1839
1840 dsi_vc_enable(channel, 1);
1841
1842 dsi.vc[channel].mode = DSI_VC_MODE_L4;
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03001843
1844 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001845}
1846
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03001847static int dsi_vc_config_vp(int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001848{
1849 if (dsi.vc[channel].mode == DSI_VC_MODE_VP)
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03001850 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001851
1852 DSSDBGF("%d", channel);
1853
1854 dsi_vc_enable(channel, 0);
1855
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03001856 /* VC_BUSY */
1857 if (wait_for_bit_change(DSI_VC_CTRL(channel), 15, 0) != 0) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001858 DSSERR("vc(%d) busy when trying to config for VP\n", channel);
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03001859 return -EIO;
1860 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001861
1862 REG_FLD_MOD(DSI_VC_CTRL(channel), 1, 1, 1); /* SOURCE, 1 = video port */
1863
1864 dsi_vc_enable(channel, 1);
1865
1866 dsi.vc[channel].mode = DSI_VC_MODE_VP;
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03001867
1868 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001869}
1870
1871
Tomi Valkeinen61140c92010-01-12 16:00:30 +02001872void omapdss_dsi_vc_enable_hs(int channel, bool enable)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001873{
1874 DSSDBG("dsi_vc_enable_hs(%d, %d)\n", channel, enable);
1875
Tomi Valkeinen61140c92010-01-12 16:00:30 +02001876 WARN_ON(!dsi_bus_is_locked());
1877
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001878 dsi_vc_enable(channel, 0);
1879 dsi_if_enable(0);
1880
1881 REG_FLD_MOD(DSI_VC_CTRL(channel), enable, 9, 9);
1882
1883 dsi_vc_enable(channel, 1);
1884 dsi_if_enable(1);
1885
1886 dsi_force_tx_stop_mode_io();
1887}
Tomi Valkeinen61140c92010-01-12 16:00:30 +02001888EXPORT_SYMBOL(omapdss_dsi_vc_enable_hs);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001889
1890static void dsi_vc_flush_long_data(int channel)
1891{
1892 while (REG_GET(DSI_VC_CTRL(channel), 20, 20)) {
1893 u32 val;
1894 val = dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel));
1895 DSSDBG("\t\tb1 %#02x b2 %#02x b3 %#02x b4 %#02x\n",
1896 (val >> 0) & 0xff,
1897 (val >> 8) & 0xff,
1898 (val >> 16) & 0xff,
1899 (val >> 24) & 0xff);
1900 }
1901}
1902
1903static void dsi_show_rx_ack_with_err(u16 err)
1904{
1905 DSSERR("\tACK with ERROR (%#x):\n", err);
1906 if (err & (1 << 0))
1907 DSSERR("\t\tSoT Error\n");
1908 if (err & (1 << 1))
1909 DSSERR("\t\tSoT Sync Error\n");
1910 if (err & (1 << 2))
1911 DSSERR("\t\tEoT Sync Error\n");
1912 if (err & (1 << 3))
1913 DSSERR("\t\tEscape Mode Entry Command Error\n");
1914 if (err & (1 << 4))
1915 DSSERR("\t\tLP Transmit Sync Error\n");
1916 if (err & (1 << 5))
1917 DSSERR("\t\tHS Receive Timeout Error\n");
1918 if (err & (1 << 6))
1919 DSSERR("\t\tFalse Control Error\n");
1920 if (err & (1 << 7))
1921 DSSERR("\t\t(reserved7)\n");
1922 if (err & (1 << 8))
1923 DSSERR("\t\tECC Error, single-bit (corrected)\n");
1924 if (err & (1 << 9))
1925 DSSERR("\t\tECC Error, multi-bit (not corrected)\n");
1926 if (err & (1 << 10))
1927 DSSERR("\t\tChecksum Error\n");
1928 if (err & (1 << 11))
1929 DSSERR("\t\tData type not recognized\n");
1930 if (err & (1 << 12))
1931 DSSERR("\t\tInvalid VC ID\n");
1932 if (err & (1 << 13))
1933 DSSERR("\t\tInvalid Transmission Length\n");
1934 if (err & (1 << 14))
1935 DSSERR("\t\t(reserved14)\n");
1936 if (err & (1 << 15))
1937 DSSERR("\t\tDSI Protocol Violation\n");
1938}
1939
1940static u16 dsi_vc_flush_receive_data(int channel)
1941{
1942 /* RX_FIFO_NOT_EMPTY */
1943 while (REG_GET(DSI_VC_CTRL(channel), 20, 20)) {
1944 u32 val;
1945 u8 dt;
1946 val = dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel));
Tomi Valkeinen86a78672010-03-16 16:19:06 +02001947 DSSERR("\trawval %#08x\n", val);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001948 dt = FLD_GET(val, 5, 0);
1949 if (dt == DSI_DT_RX_ACK_WITH_ERR) {
1950 u16 err = FLD_GET(val, 23, 8);
1951 dsi_show_rx_ack_with_err(err);
1952 } else if (dt == DSI_DT_RX_SHORT_READ_1) {
Tomi Valkeinen86a78672010-03-16 16:19:06 +02001953 DSSERR("\tDCS short response, 1 byte: %#x\n",
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001954 FLD_GET(val, 23, 8));
1955 } else if (dt == DSI_DT_RX_SHORT_READ_2) {
Tomi Valkeinen86a78672010-03-16 16:19:06 +02001956 DSSERR("\tDCS short response, 2 byte: %#x\n",
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001957 FLD_GET(val, 23, 8));
1958 } else if (dt == DSI_DT_RX_DCS_LONG_READ) {
Tomi Valkeinen86a78672010-03-16 16:19:06 +02001959 DSSERR("\tDCS long response, len %d\n",
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001960 FLD_GET(val, 23, 8));
1961 dsi_vc_flush_long_data(channel);
1962 } else {
1963 DSSERR("\tunknown datatype 0x%02x\n", dt);
1964 }
1965 }
1966 return 0;
1967}
1968
1969static int dsi_vc_send_bta(int channel)
1970{
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +02001971 if (dsi.debug_write || dsi.debug_read)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001972 DSSDBG("dsi_vc_send_bta %d\n", channel);
1973
Tomi Valkeinen4f765022010-01-18 16:27:52 +02001974 WARN_ON(!dsi_bus_is_locked());
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001975
1976 if (REG_GET(DSI_VC_CTRL(channel), 20, 20)) { /* RX_FIFO_NOT_EMPTY */
1977 DSSERR("rx fifo not empty when sending BTA, dumping data:\n");
1978 dsi_vc_flush_receive_data(channel);
1979 }
1980
1981 REG_FLD_MOD(DSI_VC_CTRL(channel), 1, 6, 6); /* BTA_EN */
1982
1983 return 0;
1984}
1985
1986int dsi_vc_send_bta_sync(int channel)
1987{
1988 int r = 0;
1989 u32 err;
1990
1991 INIT_COMPLETION(dsi.bta_completion);
1992
1993 dsi_vc_enable_bta_irq(channel);
1994
1995 r = dsi_vc_send_bta(channel);
1996 if (r)
1997 goto err;
1998
1999 if (wait_for_completion_timeout(&dsi.bta_completion,
2000 msecs_to_jiffies(500)) == 0) {
2001 DSSERR("Failed to receive BTA\n");
2002 r = -EIO;
2003 goto err;
2004 }
2005
2006 err = dsi_get_errors();
2007 if (err) {
2008 DSSERR("Error while sending BTA: %x\n", err);
2009 r = -EIO;
2010 goto err;
2011 }
2012err:
2013 dsi_vc_disable_bta_irq(channel);
2014
2015 return r;
2016}
2017EXPORT_SYMBOL(dsi_vc_send_bta_sync);
2018
2019static inline void dsi_vc_write_long_header(int channel, u8 data_type,
2020 u16 len, u8 ecc)
2021{
2022 u32 val;
2023 u8 data_id;
2024
Tomi Valkeinen4f765022010-01-18 16:27:52 +02002025 WARN_ON(!dsi_bus_is_locked());
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002026
Archit Taneja5ee3c142011-03-02 12:35:53 +05302027 data_id = data_type | dsi.vc[channel].vc_id << 6;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002028
2029 val = FLD_VAL(data_id, 7, 0) | FLD_VAL(len, 23, 8) |
2030 FLD_VAL(ecc, 31, 24);
2031
2032 dsi_write_reg(DSI_VC_LONG_PACKET_HEADER(channel), val);
2033}
2034
2035static inline void dsi_vc_write_long_payload(int channel,
2036 u8 b1, u8 b2, u8 b3, u8 b4)
2037{
2038 u32 val;
2039
2040 val = b4 << 24 | b3 << 16 | b2 << 8 | b1 << 0;
2041
2042/* DSSDBG("\twriting %02x, %02x, %02x, %02x (%#010x)\n",
2043 b1, b2, b3, b4, val); */
2044
2045 dsi_write_reg(DSI_VC_LONG_PACKET_PAYLOAD(channel), val);
2046}
2047
2048static int dsi_vc_send_long(int channel, u8 data_type, u8 *data, u16 len,
2049 u8 ecc)
2050{
2051 /*u32 val; */
2052 int i;
2053 u8 *p;
2054 int r = 0;
2055 u8 b1, b2, b3, b4;
2056
2057 if (dsi.debug_write)
2058 DSSDBG("dsi_vc_send_long, %d bytes\n", len);
2059
2060 /* len + header */
2061 if (dsi.vc[channel].fifo_size * 32 * 4 < len + 4) {
2062 DSSERR("unable to send long packet: packet too long.\n");
2063 return -EINVAL;
2064 }
2065
2066 dsi_vc_config_l4(channel);
2067
2068 dsi_vc_write_long_header(channel, data_type, len, ecc);
2069
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002070 p = data;
2071 for (i = 0; i < len >> 2; i++) {
2072 if (dsi.debug_write)
2073 DSSDBG("\tsending full packet %d\n", i);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002074
2075 b1 = *p++;
2076 b2 = *p++;
2077 b3 = *p++;
2078 b4 = *p++;
2079
2080 dsi_vc_write_long_payload(channel, b1, b2, b3, b4);
2081 }
2082
2083 i = len % 4;
2084 if (i) {
2085 b1 = 0; b2 = 0; b3 = 0;
2086
2087 if (dsi.debug_write)
2088 DSSDBG("\tsending remainder bytes %d\n", i);
2089
2090 switch (i) {
2091 case 3:
2092 b1 = *p++;
2093 b2 = *p++;
2094 b3 = *p++;
2095 break;
2096 case 2:
2097 b1 = *p++;
2098 b2 = *p++;
2099 break;
2100 case 1:
2101 b1 = *p++;
2102 break;
2103 }
2104
2105 dsi_vc_write_long_payload(channel, b1, b2, b3, 0);
2106 }
2107
2108 return r;
2109}
2110
2111static int dsi_vc_send_short(int channel, u8 data_type, u16 data, u8 ecc)
2112{
2113 u32 r;
2114 u8 data_id;
2115
Tomi Valkeinen4f765022010-01-18 16:27:52 +02002116 WARN_ON(!dsi_bus_is_locked());
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002117
2118 if (dsi.debug_write)
2119 DSSDBG("dsi_vc_send_short(ch%d, dt %#x, b1 %#x, b2 %#x)\n",
2120 channel,
2121 data_type, data & 0xff, (data >> 8) & 0xff);
2122
2123 dsi_vc_config_l4(channel);
2124
2125 if (FLD_GET(dsi_read_reg(DSI_VC_CTRL(channel)), 16, 16)) {
2126 DSSERR("ERROR FIFO FULL, aborting transfer\n");
2127 return -EINVAL;
2128 }
2129
Archit Taneja5ee3c142011-03-02 12:35:53 +05302130 data_id = data_type | dsi.vc[channel].vc_id << 6;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002131
2132 r = (data_id << 0) | (data << 8) | (ecc << 24);
2133
2134 dsi_write_reg(DSI_VC_SHORT_PACKET_HEADER(channel), r);
2135
2136 return 0;
2137}
2138
2139int dsi_vc_send_null(int channel)
2140{
2141 u8 nullpkg[] = {0, 0, 0, 0};
Tomi Valkeinen397bb3c2009-12-03 13:37:31 +02002142 return dsi_vc_send_long(channel, DSI_DT_NULL_PACKET, nullpkg, 4, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002143}
2144EXPORT_SYMBOL(dsi_vc_send_null);
2145
2146int dsi_vc_dcs_write_nosync(int channel, u8 *data, int len)
2147{
2148 int r;
2149
2150 BUG_ON(len == 0);
2151
2152 if (len == 1) {
2153 r = dsi_vc_send_short(channel, DSI_DT_DCS_SHORT_WRITE_0,
2154 data[0], 0);
2155 } else if (len == 2) {
2156 r = dsi_vc_send_short(channel, DSI_DT_DCS_SHORT_WRITE_1,
2157 data[0] | (data[1] << 8), 0);
2158 } else {
2159 /* 0x39 = DCS Long Write */
2160 r = dsi_vc_send_long(channel, DSI_DT_DCS_LONG_WRITE,
2161 data, len, 0);
2162 }
2163
2164 return r;
2165}
2166EXPORT_SYMBOL(dsi_vc_dcs_write_nosync);
2167
2168int dsi_vc_dcs_write(int channel, u8 *data, int len)
2169{
2170 int r;
2171
2172 r = dsi_vc_dcs_write_nosync(channel, data, len);
2173 if (r)
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002174 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002175
2176 r = dsi_vc_send_bta_sync(channel);
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002177 if (r)
2178 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002179
Tomi Valkeinenb63ac1e2010-04-09 13:20:57 +03002180 if (REG_GET(DSI_VC_CTRL(channel), 20, 20)) { /* RX_FIFO_NOT_EMPTY */
2181 DSSERR("rx fifo not empty after write, dumping data:\n");
2182 dsi_vc_flush_receive_data(channel);
2183 r = -EIO;
2184 goto err;
2185 }
2186
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002187 return 0;
2188err:
2189 DSSERR("dsi_vc_dcs_write(ch %d, cmd 0x%02x, len %d) failed\n",
2190 channel, data[0], len);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002191 return r;
2192}
2193EXPORT_SYMBOL(dsi_vc_dcs_write);
2194
Tomi Valkeinen828c48f2009-12-16 14:53:15 +02002195int dsi_vc_dcs_write_0(int channel, u8 dcs_cmd)
2196{
2197 return dsi_vc_dcs_write(channel, &dcs_cmd, 1);
2198}
2199EXPORT_SYMBOL(dsi_vc_dcs_write_0);
2200
2201int dsi_vc_dcs_write_1(int channel, u8 dcs_cmd, u8 param)
2202{
2203 u8 buf[2];
2204 buf[0] = dcs_cmd;
2205 buf[1] = param;
2206 return dsi_vc_dcs_write(channel, buf, 2);
2207}
2208EXPORT_SYMBOL(dsi_vc_dcs_write_1);
2209
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002210int dsi_vc_dcs_read(int channel, u8 dcs_cmd, u8 *buf, int buflen)
2211{
2212 u32 val;
2213 u8 dt;
2214 int r;
2215
2216 if (dsi.debug_read)
Tomi Valkeinenff90a342009-12-03 13:38:04 +02002217 DSSDBG("dsi_vc_dcs_read(ch%d, dcs_cmd %x)\n", channel, dcs_cmd);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002218
2219 r = dsi_vc_send_short(channel, DSI_DT_DCS_READ, dcs_cmd, 0);
2220 if (r)
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002221 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002222
2223 r = dsi_vc_send_bta_sync(channel);
2224 if (r)
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002225 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002226
2227 /* RX_FIFO_NOT_EMPTY */
2228 if (REG_GET(DSI_VC_CTRL(channel), 20, 20) == 0) {
2229 DSSERR("RX fifo empty when trying to read.\n");
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002230 r = -EIO;
2231 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002232 }
2233
2234 val = dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel));
2235 if (dsi.debug_read)
2236 DSSDBG("\theader: %08x\n", val);
2237 dt = FLD_GET(val, 5, 0);
2238 if (dt == DSI_DT_RX_ACK_WITH_ERR) {
2239 u16 err = FLD_GET(val, 23, 8);
2240 dsi_show_rx_ack_with_err(err);
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002241 r = -EIO;
2242 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002243
2244 } else if (dt == DSI_DT_RX_SHORT_READ_1) {
2245 u8 data = FLD_GET(val, 15, 8);
2246 if (dsi.debug_read)
2247 DSSDBG("\tDCS short response, 1 byte: %02x\n", data);
2248
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002249 if (buflen < 1) {
2250 r = -EIO;
2251 goto err;
2252 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002253
2254 buf[0] = data;
2255
2256 return 1;
2257 } else if (dt == DSI_DT_RX_SHORT_READ_2) {
2258 u16 data = FLD_GET(val, 23, 8);
2259 if (dsi.debug_read)
2260 DSSDBG("\tDCS short response, 2 byte: %04x\n", data);
2261
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002262 if (buflen < 2) {
2263 r = -EIO;
2264 goto err;
2265 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002266
2267 buf[0] = data & 0xff;
2268 buf[1] = (data >> 8) & 0xff;
2269
2270 return 2;
2271 } else if (dt == DSI_DT_RX_DCS_LONG_READ) {
2272 int w;
2273 int len = FLD_GET(val, 23, 8);
2274 if (dsi.debug_read)
2275 DSSDBG("\tDCS long response, len %d\n", len);
2276
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002277 if (len > buflen) {
2278 r = -EIO;
2279 goto err;
2280 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002281
2282 /* two byte checksum ends the packet, not included in len */
2283 for (w = 0; w < len + 2;) {
2284 int b;
2285 val = dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel));
2286 if (dsi.debug_read)
2287 DSSDBG("\t\t%02x %02x %02x %02x\n",
2288 (val >> 0) & 0xff,
2289 (val >> 8) & 0xff,
2290 (val >> 16) & 0xff,
2291 (val >> 24) & 0xff);
2292
2293 for (b = 0; b < 4; ++b) {
2294 if (w < len)
2295 buf[w] = (val >> (b * 8)) & 0xff;
2296 /* we discard the 2 byte checksum */
2297 ++w;
2298 }
2299 }
2300
2301 return len;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002302 } else {
2303 DSSERR("\tunknown datatype 0x%02x\n", dt);
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002304 r = -EIO;
2305 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002306 }
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02002307
2308 BUG();
2309err:
2310 DSSERR("dsi_vc_dcs_read(ch %d, cmd 0x%02x) failed\n",
2311 channel, dcs_cmd);
2312 return r;
2313
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002314}
2315EXPORT_SYMBOL(dsi_vc_dcs_read);
2316
Tomi Valkeinen828c48f2009-12-16 14:53:15 +02002317int dsi_vc_dcs_read_1(int channel, u8 dcs_cmd, u8 *data)
2318{
2319 int r;
2320
2321 r = dsi_vc_dcs_read(channel, dcs_cmd, data, 1);
2322
2323 if (r < 0)
2324 return r;
2325
2326 if (r != 1)
2327 return -EIO;
2328
2329 return 0;
2330}
2331EXPORT_SYMBOL(dsi_vc_dcs_read_1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002332
Tomi Valkeinen0c244f72010-06-09 15:19:29 +03002333int dsi_vc_dcs_read_2(int channel, u8 dcs_cmd, u8 *data1, u8 *data2)
Tomi Valkeinen53055aa2010-02-25 11:38:13 +02002334{
Tomi Valkeinen0c244f72010-06-09 15:19:29 +03002335 u8 buf[2];
Tomi Valkeinen53055aa2010-02-25 11:38:13 +02002336 int r;
2337
Tomi Valkeinen0c244f72010-06-09 15:19:29 +03002338 r = dsi_vc_dcs_read(channel, dcs_cmd, buf, 2);
Tomi Valkeinen53055aa2010-02-25 11:38:13 +02002339
2340 if (r < 0)
2341 return r;
2342
2343 if (r != 2)
2344 return -EIO;
2345
Tomi Valkeinen0c244f72010-06-09 15:19:29 +03002346 *data1 = buf[0];
2347 *data2 = buf[1];
2348
Tomi Valkeinen53055aa2010-02-25 11:38:13 +02002349 return 0;
2350}
2351EXPORT_SYMBOL(dsi_vc_dcs_read_2);
2352
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002353int dsi_vc_set_max_rx_packet_size(int channel, u16 len)
2354{
Tomi Valkeinenfa15c792010-05-14 17:42:07 +03002355 return dsi_vc_send_short(channel, DSI_DT_SET_MAX_RET_PKG_SIZE,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002356 len, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002357}
2358EXPORT_SYMBOL(dsi_vc_set_max_rx_packet_size);
2359
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03002360static void dsi_set_lp_rx_timeout(unsigned ticks, bool x4, bool x16)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002361{
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002362 unsigned long fck;
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03002363 unsigned long total_ticks;
2364 u32 r;
2365
2366 BUG_ON(ticks > 0x1fff);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002367
2368 /* ticks in DSI_FCK */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002369 fck = dsi_fclk_rate();
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002370
2371 r = dsi_read_reg(DSI_TIMING2);
2372 r = FLD_MOD(r, 1, 15, 15); /* LP_RX_TO */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03002373 r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* LP_RX_TO_X16 */
2374 r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* LP_RX_TO_X4 */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002375 r = FLD_MOD(r, ticks, 12, 0); /* LP_RX_COUNTER */
2376 dsi_write_reg(DSI_TIMING2, r);
2377
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03002378 total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
2379
2380 DSSDBG("LP_RX_TO %lu ticks (%#x%s%s) = %lu ns\n",
2381 total_ticks,
2382 ticks, x4 ? " x4" : "", x16 ? " x16" : "",
2383 (total_ticks * 1000) / (fck / 1000 / 1000));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002384}
2385
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03002386static void dsi_set_ta_timeout(unsigned ticks, bool x8, bool x16)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002387{
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002388 unsigned long fck;
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03002389 unsigned long total_ticks;
2390 u32 r;
2391
2392 BUG_ON(ticks > 0x1fff);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002393
2394 /* ticks in DSI_FCK */
2395 fck = dsi_fclk_rate();
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002396
2397 r = dsi_read_reg(DSI_TIMING1);
2398 r = FLD_MOD(r, 1, 31, 31); /* TA_TO */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03002399 r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* TA_TO_X16 */
2400 r = FLD_MOD(r, x8 ? 1 : 0, 29, 29); /* TA_TO_X8 */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002401 r = FLD_MOD(r, ticks, 28, 16); /* TA_TO_COUNTER */
2402 dsi_write_reg(DSI_TIMING1, r);
2403
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03002404 total_ticks = ticks * (x16 ? 16 : 1) * (x8 ? 8 : 1);
2405
2406 DSSDBG("TA_TO %lu ticks (%#x%s%s) = %lu ns\n",
2407 total_ticks,
2408 ticks, x8 ? " x8" : "", x16 ? " x16" : "",
2409 (total_ticks * 1000) / (fck / 1000 / 1000));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002410}
2411
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03002412static void dsi_set_stop_state_counter(unsigned ticks, bool x4, bool x16)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002413{
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002414 unsigned long fck;
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03002415 unsigned long total_ticks;
2416 u32 r;
2417
2418 BUG_ON(ticks > 0x1fff);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002419
2420 /* ticks in DSI_FCK */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002421 fck = dsi_fclk_rate();
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002422
2423 r = dsi_read_reg(DSI_TIMING1);
2424 r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03002425 r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* STOP_STATE_X16_IO */
2426 r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* STOP_STATE_X4_IO */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002427 r = FLD_MOD(r, ticks, 12, 0); /* STOP_STATE_COUNTER_IO */
2428 dsi_write_reg(DSI_TIMING1, r);
2429
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03002430 total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
2431
2432 DSSDBG("STOP_STATE_COUNTER %lu ticks (%#x%s%s) = %lu ns\n",
2433 total_ticks,
2434 ticks, x4 ? " x4" : "", x16 ? " x16" : "",
2435 (total_ticks * 1000) / (fck / 1000 / 1000));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002436}
2437
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03002438static void dsi_set_hs_tx_timeout(unsigned ticks, bool x4, bool x16)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002439{
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002440 unsigned long fck;
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03002441 unsigned long total_ticks;
2442 u32 r;
2443
2444 BUG_ON(ticks > 0x1fff);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002445
2446 /* ticks in TxByteClkHS */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002447 fck = dsi_get_txbyteclkhs();
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002448
2449 r = dsi_read_reg(DSI_TIMING2);
2450 r = FLD_MOD(r, 1, 31, 31); /* HS_TX_TO */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03002451 r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* HS_TX_TO_X16 */
2452 r = FLD_MOD(r, x4 ? 1 : 0, 29, 29); /* HS_TX_TO_X8 (4 really) */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002453 r = FLD_MOD(r, ticks, 28, 16); /* HS_TX_TO_COUNTER */
2454 dsi_write_reg(DSI_TIMING2, r);
2455
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03002456 total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
2457
2458 DSSDBG("HS_TX_TO %lu ticks (%#x%s%s) = %lu ns\n",
2459 total_ticks,
2460 ticks, x4 ? " x4" : "", x16 ? " x16" : "",
2461 (total_ticks * 1000) / (fck / 1000 / 1000));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002462}
2463static int dsi_proto_config(struct omap_dss_device *dssdev)
2464{
2465 u32 r;
2466 int buswidth = 0;
2467
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02002468 dsi_config_tx_fifo(DSI_FIFO_SIZE_32,
2469 DSI_FIFO_SIZE_32,
2470 DSI_FIFO_SIZE_32,
2471 DSI_FIFO_SIZE_32);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002472
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02002473 dsi_config_rx_fifo(DSI_FIFO_SIZE_32,
2474 DSI_FIFO_SIZE_32,
2475 DSI_FIFO_SIZE_32,
2476 DSI_FIFO_SIZE_32);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002477
2478 /* XXX what values for the timeouts? */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03002479 dsi_set_stop_state_counter(0x1000, false, false);
2480 dsi_set_ta_timeout(0x1fff, true, true);
2481 dsi_set_lp_rx_timeout(0x1fff, true, true);
2482 dsi_set_hs_tx_timeout(0x1fff, true, true);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002483
2484 switch (dssdev->ctrl.pixel_size) {
2485 case 16:
2486 buswidth = 0;
2487 break;
2488 case 18:
2489 buswidth = 1;
2490 break;
2491 case 24:
2492 buswidth = 2;
2493 break;
2494 default:
2495 BUG();
2496 }
2497
2498 r = dsi_read_reg(DSI_CTRL);
2499 r = FLD_MOD(r, 1, 1, 1); /* CS_RX_EN */
2500 r = FLD_MOD(r, 1, 2, 2); /* ECC_RX_EN */
2501 r = FLD_MOD(r, 1, 3, 3); /* TX_FIFO_ARBITRATION */
2502 r = FLD_MOD(r, 1, 4, 4); /* VP_CLK_RATIO, always 1, see errata*/
2503 r = FLD_MOD(r, buswidth, 7, 6); /* VP_DATA_BUS_WIDTH */
2504 r = FLD_MOD(r, 0, 8, 8); /* VP_CLK_POL */
2505 r = FLD_MOD(r, 2, 13, 12); /* LINE_BUFFER, 2 lines */
2506 r = FLD_MOD(r, 1, 14, 14); /* TRIGGER_RESET_MODE */
2507 r = FLD_MOD(r, 1, 19, 19); /* EOT_ENABLE */
2508 r = FLD_MOD(r, 1, 24, 24); /* DCS_CMD_ENABLE */
2509 r = FLD_MOD(r, 0, 25, 25); /* DCS_CMD_CODE, 1=start, 0=continue */
2510
2511 dsi_write_reg(DSI_CTRL, r);
2512
2513 dsi_vc_initial_config(0);
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02002514 dsi_vc_initial_config(1);
2515 dsi_vc_initial_config(2);
2516 dsi_vc_initial_config(3);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002517
2518 return 0;
2519}
2520
2521static void dsi_proto_timings(struct omap_dss_device *dssdev)
2522{
2523 unsigned tlpx, tclk_zero, tclk_prepare, tclk_trail;
2524 unsigned tclk_pre, tclk_post;
2525 unsigned ths_prepare, ths_prepare_ths_zero, ths_zero;
2526 unsigned ths_trail, ths_exit;
2527 unsigned ddr_clk_pre, ddr_clk_post;
2528 unsigned enter_hs_mode_lat, exit_hs_mode_lat;
2529 unsigned ths_eot;
2530 u32 r;
2531
2532 r = dsi_read_reg(DSI_DSIPHY_CFG0);
2533 ths_prepare = FLD_GET(r, 31, 24);
2534 ths_prepare_ths_zero = FLD_GET(r, 23, 16);
2535 ths_zero = ths_prepare_ths_zero - ths_prepare;
2536 ths_trail = FLD_GET(r, 15, 8);
2537 ths_exit = FLD_GET(r, 7, 0);
2538
2539 r = dsi_read_reg(DSI_DSIPHY_CFG1);
2540 tlpx = FLD_GET(r, 22, 16) * 2;
2541 tclk_trail = FLD_GET(r, 15, 8);
2542 tclk_zero = FLD_GET(r, 7, 0);
2543
2544 r = dsi_read_reg(DSI_DSIPHY_CFG2);
2545 tclk_prepare = FLD_GET(r, 7, 0);
2546
2547 /* min 8*UI */
2548 tclk_pre = 20;
2549 /* min 60ns + 52*UI */
2550 tclk_post = ns2ddr(60) + 26;
2551
2552 /* ths_eot is 2 for 2 datalanes and 4 for 1 datalane */
2553 if (dssdev->phy.dsi.data1_lane != 0 &&
2554 dssdev->phy.dsi.data2_lane != 0)
2555 ths_eot = 2;
2556 else
2557 ths_eot = 4;
2558
2559 ddr_clk_pre = DIV_ROUND_UP(tclk_pre + tlpx + tclk_zero + tclk_prepare,
2560 4);
2561 ddr_clk_post = DIV_ROUND_UP(tclk_post + ths_trail, 4) + ths_eot;
2562
2563 BUG_ON(ddr_clk_pre == 0 || ddr_clk_pre > 255);
2564 BUG_ON(ddr_clk_post == 0 || ddr_clk_post > 255);
2565
2566 r = dsi_read_reg(DSI_CLK_TIMING);
2567 r = FLD_MOD(r, ddr_clk_pre, 15, 8);
2568 r = FLD_MOD(r, ddr_clk_post, 7, 0);
2569 dsi_write_reg(DSI_CLK_TIMING, r);
2570
2571 DSSDBG("ddr_clk_pre %u, ddr_clk_post %u\n",
2572 ddr_clk_pre,
2573 ddr_clk_post);
2574
2575 enter_hs_mode_lat = 1 + DIV_ROUND_UP(tlpx, 4) +
2576 DIV_ROUND_UP(ths_prepare, 4) +
2577 DIV_ROUND_UP(ths_zero + 3, 4);
2578
2579 exit_hs_mode_lat = DIV_ROUND_UP(ths_trail + ths_exit, 4) + 1 + ths_eot;
2580
2581 r = FLD_VAL(enter_hs_mode_lat, 31, 16) |
2582 FLD_VAL(exit_hs_mode_lat, 15, 0);
2583 dsi_write_reg(DSI_VM_TIMING7, r);
2584
2585 DSSDBG("enter_hs_mode_lat %u, exit_hs_mode_lat %u\n",
2586 enter_hs_mode_lat, exit_hs_mode_lat);
2587}
2588
2589
2590#define DSI_DECL_VARS \
2591 int __dsi_cb = 0; u32 __dsi_cv = 0;
2592
2593#define DSI_FLUSH(ch) \
2594 if (__dsi_cb > 0) { \
2595 /*DSSDBG("sending long packet %#010x\n", __dsi_cv);*/ \
2596 dsi_write_reg(DSI_VC_LONG_PACKET_PAYLOAD(ch), __dsi_cv); \
2597 __dsi_cb = __dsi_cv = 0; \
2598 }
2599
2600#define DSI_PUSH(ch, data) \
2601 do { \
2602 __dsi_cv |= (data) << (__dsi_cb * 8); \
2603 /*DSSDBG("cv = %#010x, cb = %d\n", __dsi_cv, __dsi_cb);*/ \
2604 if (++__dsi_cb > 3) \
2605 DSI_FLUSH(ch); \
2606 } while (0)
2607
2608static int dsi_update_screen_l4(struct omap_dss_device *dssdev,
2609 int x, int y, int w, int h)
2610{
2611 /* Note: supports only 24bit colors in 32bit container */
2612 int first = 1;
2613 int fifo_stalls = 0;
2614 int max_dsi_packet_size;
2615 int max_data_per_packet;
2616 int max_pixels_per_packet;
2617 int pixels_left;
2618 int bytespp = dssdev->ctrl.pixel_size / 8;
2619 int scr_width;
2620 u32 __iomem *data;
2621 int start_offset;
2622 int horiz_inc;
2623 int current_x;
2624 struct omap_overlay *ovl;
2625
2626 debug_irq = 0;
2627
2628 DSSDBG("dsi_update_screen_l4 (%d,%d %dx%d)\n",
2629 x, y, w, h);
2630
2631 ovl = dssdev->manager->overlays[0];
2632
2633 if (ovl->info.color_mode != OMAP_DSS_COLOR_RGB24U)
2634 return -EINVAL;
2635
2636 if (dssdev->ctrl.pixel_size != 24)
2637 return -EINVAL;
2638
2639 scr_width = ovl->info.screen_width;
2640 data = ovl->info.vaddr;
2641
2642 start_offset = scr_width * y + x;
2643 horiz_inc = scr_width - w;
2644 current_x = x;
2645
2646 /* We need header(4) + DCSCMD(1) + pixels(numpix*bytespp) bytes
2647 * in fifo */
2648
2649 /* When using CPU, max long packet size is TX buffer size */
2650 max_dsi_packet_size = dsi.vc[0].fifo_size * 32 * 4;
2651
2652 /* we seem to get better perf if we divide the tx fifo to half,
2653 and while the other half is being sent, we fill the other half
2654 max_dsi_packet_size /= 2; */
2655
2656 max_data_per_packet = max_dsi_packet_size - 4 - 1;
2657
2658 max_pixels_per_packet = max_data_per_packet / bytespp;
2659
2660 DSSDBG("max_pixels_per_packet %d\n", max_pixels_per_packet);
2661
2662 pixels_left = w * h;
2663
2664 DSSDBG("total pixels %d\n", pixels_left);
2665
2666 data += start_offset;
2667
2668 while (pixels_left > 0) {
2669 /* 0x2c = write_memory_start */
2670 /* 0x3c = write_memory_continue */
2671 u8 dcs_cmd = first ? 0x2c : 0x3c;
2672 int pixels;
2673 DSI_DECL_VARS;
2674 first = 0;
2675
2676#if 1
2677 /* using fifo not empty */
2678 /* TX_FIFO_NOT_EMPTY */
2679 while (FLD_GET(dsi_read_reg(DSI_VC_CTRL(0)), 5, 5)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002680 fifo_stalls++;
2681 if (fifo_stalls > 0xfffff) {
2682 DSSERR("fifo stalls overflow, pixels left %d\n",
2683 pixels_left);
2684 dsi_if_enable(0);
2685 return -EIO;
2686 }
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02002687 udelay(1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002688 }
2689#elif 1
2690 /* using fifo emptiness */
2691 while ((REG_GET(DSI_TX_FIFO_VC_EMPTINESS, 7, 0)+1)*4 <
2692 max_dsi_packet_size) {
2693 fifo_stalls++;
2694 if (fifo_stalls > 0xfffff) {
2695 DSSERR("fifo stalls overflow, pixels left %d\n",
2696 pixels_left);
2697 dsi_if_enable(0);
2698 return -EIO;
2699 }
2700 }
2701#else
2702 while ((REG_GET(DSI_TX_FIFO_VC_EMPTINESS, 7, 0)+1)*4 == 0) {
2703 fifo_stalls++;
2704 if (fifo_stalls > 0xfffff) {
2705 DSSERR("fifo stalls overflow, pixels left %d\n",
2706 pixels_left);
2707 dsi_if_enable(0);
2708 return -EIO;
2709 }
2710 }
2711#endif
2712 pixels = min(max_pixels_per_packet, pixels_left);
2713
2714 pixels_left -= pixels;
2715
2716 dsi_vc_write_long_header(0, DSI_DT_DCS_LONG_WRITE,
2717 1 + pixels * bytespp, 0);
2718
2719 DSI_PUSH(0, dcs_cmd);
2720
2721 while (pixels-- > 0) {
2722 u32 pix = __raw_readl(data++);
2723
2724 DSI_PUSH(0, (pix >> 16) & 0xff);
2725 DSI_PUSH(0, (pix >> 8) & 0xff);
2726 DSI_PUSH(0, (pix >> 0) & 0xff);
2727
2728 current_x++;
2729 if (current_x == x+w) {
2730 current_x = x;
2731 data += horiz_inc;
2732 }
2733 }
2734
2735 DSI_FLUSH(0);
2736 }
2737
2738 return 0;
2739}
2740
2741static void dsi_update_screen_dispc(struct omap_dss_device *dssdev,
2742 u16 x, u16 y, u16 w, u16 h)
2743{
2744 unsigned bytespp;
2745 unsigned bytespl;
2746 unsigned bytespf;
2747 unsigned total_len;
2748 unsigned packet_payload;
2749 unsigned packet_len;
2750 u32 l;
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03002751 int r;
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002752 const unsigned channel = dsi.update_channel;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002753 /* line buffer is 1024 x 24bits */
2754 /* XXX: for some reason using full buffer size causes considerable TX
2755 * slowdown with update sizes that fill the whole buffer */
2756 const unsigned line_buf_size = 1023 * 3;
2757
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +02002758 DSSDBG("dsi_update_screen_dispc(%d,%d %dx%d)\n",
2759 x, y, w, h);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002760
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002761 dsi_vc_config_vp(channel);
2762
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002763 bytespp = dssdev->ctrl.pixel_size / 8;
2764 bytespl = w * bytespp;
2765 bytespf = bytespl * h;
2766
2767 /* NOTE: packet_payload has to be equal to N * bytespl, where N is
2768 * number of lines in a packet. See errata about VP_CLK_RATIO */
2769
2770 if (bytespf < line_buf_size)
2771 packet_payload = bytespf;
2772 else
2773 packet_payload = (line_buf_size) / bytespl * bytespl;
2774
2775 packet_len = packet_payload + 1; /* 1 byte for DCS cmd */
2776 total_len = (bytespf / packet_payload) * packet_len;
2777
2778 if (bytespf % packet_payload)
2779 total_len += (bytespf % packet_payload) + 1;
2780
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002781 l = FLD_VAL(total_len, 23, 0); /* TE_SIZE */
2782 dsi_write_reg(DSI_VC_TE(channel), l);
2783
2784 dsi_vc_write_long_header(channel, DSI_DT_DCS_LONG_WRITE, packet_len, 0);
2785
Tomi Valkeinen942a91a2010-02-10 17:27:39 +02002786 if (dsi.te_enabled)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002787 l = FLD_MOD(l, 1, 30, 30); /* TE_EN */
2788 else
2789 l = FLD_MOD(l, 1, 31, 31); /* TE_START */
2790 dsi_write_reg(DSI_VC_TE(channel), l);
2791
2792 /* We put SIDLEMODE to no-idle for the duration of the transfer,
2793 * because DSS interrupts are not capable of waking up the CPU and the
2794 * framedone interrupt could be delayed for quite a long time. I think
2795 * the same goes for any DSS interrupts, but for some reason I have not
2796 * seen the problem anywhere else than here.
2797 */
2798 dispc_disable_sidle();
2799
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002800 dsi_perf_mark_start();
2801
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03002802 r = queue_delayed_work(dsi.workqueue, &dsi.framedone_timeout_work,
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002803 msecs_to_jiffies(250));
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03002804 BUG_ON(r == 0);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002805
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002806 dss_start_update(dssdev);
2807
Tomi Valkeinen942a91a2010-02-10 17:27:39 +02002808 if (dsi.te_enabled) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002809 /* disable LP_RX_TO, so that we can receive TE. Time to wait
2810 * for TE is longer than the timer allows */
2811 REG_FLD_MOD(DSI_TIMING2, 0, 15, 15); /* LP_RX_TO */
2812
2813 dsi_vc_send_bta(channel);
2814
2815#ifdef DSI_CATCH_MISSING_TE
2816 mod_timer(&dsi.te_timer, jiffies + msecs_to_jiffies(250));
2817#endif
2818 }
2819}
2820
2821#ifdef DSI_CATCH_MISSING_TE
2822static void dsi_te_timeout(unsigned long arg)
2823{
2824 DSSERR("TE not received for 250ms!\n");
2825}
2826#endif
2827
Tomi Valkeinenab83b142010-06-09 15:31:01 +03002828static void dsi_handle_framedone(int error)
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002829{
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002830 const int channel = dsi.update_channel;
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002831
Tomi Valkeinenab83b142010-06-09 15:31:01 +03002832 cancel_delayed_work(&dsi.framedone_timeout_work);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002833
Tomi Valkeinenab83b142010-06-09 15:31:01 +03002834 dsi_vc_disable_bta_irq(channel);
2835
2836 /* SIDLEMODE back to smart-idle */
2837 dispc_enable_sidle();
2838
2839 dsi.bta_callback = NULL;
2840
2841 if (dsi.te_enabled) {
2842 /* enable LP_RX_TO again after the TE */
2843 REG_FLD_MOD(DSI_TIMING2, 1, 15, 15); /* LP_RX_TO */
2844 }
2845
2846 /* RX_FIFO_NOT_EMPTY */
2847 if (REG_GET(DSI_VC_CTRL(channel), 20, 20)) {
2848 DSSERR("Received error during frame transfer:\n");
2849 dsi_vc_flush_receive_data(channel);
2850 if (!error)
2851 error = -EIO;
2852 }
2853
2854 dsi.framedone_callback(error, dsi.framedone_data);
2855
2856 if (!error)
2857 dsi_perf_show("DISPC");
2858}
2859
2860static void dsi_framedone_timeout_work_callback(struct work_struct *work)
2861{
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03002862 /* XXX While extremely unlikely, we could get FRAMEDONE interrupt after
2863 * 250ms which would conflict with this timeout work. What should be
2864 * done is first cancel the transfer on the HW, and then cancel the
Tomi Valkeinenab83b142010-06-09 15:31:01 +03002865 * possibly scheduled framedone work. However, cancelling the transfer
2866 * on the HW is buggy, and would probably require resetting the whole
2867 * DSI */
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03002868
Tomi Valkeinenab83b142010-06-09 15:31:01 +03002869 DSSERR("Framedone not received for 250ms!\n");
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002870
Tomi Valkeinenab83b142010-06-09 15:31:01 +03002871 dsi_handle_framedone(-ETIMEDOUT);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002872}
2873
Tomi Valkeinenab83b142010-06-09 15:31:01 +03002874static void dsi_framedone_bta_callback(void)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002875{
Tomi Valkeinenab83b142010-06-09 15:31:01 +03002876 dsi_handle_framedone(0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002877
2878#ifdef CONFIG_OMAP2_DSS_FAKE_VSYNC
2879 dispc_fake_vsync_irq();
2880#endif
2881}
2882
Tomi Valkeinenab83b142010-06-09 15:31:01 +03002883static void dsi_framedone_irq_callback(void *data, u32 mask)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002884{
Tomi Valkeinenab83b142010-06-09 15:31:01 +03002885 const int channel = dsi.update_channel;
2886 int r;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002887
Tomi Valkeinenab83b142010-06-09 15:31:01 +03002888 /* Note: We get FRAMEDONE when DISPC has finished sending pixels and
2889 * turns itself off. However, DSI still has the pixels in its buffers,
2890 * and is sending the data.
2891 */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002892
Tomi Valkeinenab83b142010-06-09 15:31:01 +03002893 if (dsi.te_enabled) {
2894 /* enable LP_RX_TO again after the TE */
2895 REG_FLD_MOD(DSI_TIMING2, 1, 15, 15); /* LP_RX_TO */
2896 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002897
Tomi Valkeinenab83b142010-06-09 15:31:01 +03002898 /* Send BTA after the frame. We need this for the TE to work, as TE
2899 * trigger is only sent for BTAs without preceding packet. Thus we need
2900 * to BTA after the pixel packets so that next BTA will cause TE
2901 * trigger.
2902 *
2903 * This is not needed when TE is not in use, but we do it anyway to
2904 * make sure that the transfer has been completed. It would be more
2905 * optimal, but more complex, to wait only just before starting next
2906 * transfer.
2907 *
2908 * Also, as there's no interrupt telling when the transfer has been
2909 * done and the channel could be reconfigured, the only way is to
2910 * busyloop until TE_SIZE is zero. With BTA we can do this
2911 * asynchronously.
2912 * */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002913
Tomi Valkeinenab83b142010-06-09 15:31:01 +03002914 dsi.bta_callback = dsi_framedone_bta_callback;
2915
2916 barrier();
2917
2918 dsi_vc_enable_bta_irq(channel);
2919
2920 r = dsi_vc_send_bta(channel);
2921 if (r) {
2922 DSSERR("BTA after framedone failed\n");
2923 dsi_handle_framedone(-EIO);
2924 }
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002925}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002926
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002927int omap_dsi_prepare_update(struct omap_dss_device *dssdev,
Tomi Valkeinen26a8c252010-06-09 15:31:34 +03002928 u16 *x, u16 *y, u16 *w, u16 *h,
2929 bool enlarge_update_area)
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002930{
2931 u16 dw, dh;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002932
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002933 dssdev->driver->get_resolution(dssdev, &dw, &dh);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002934
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002935 if (*x > dw || *y > dh)
2936 return -EINVAL;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002937
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002938 if (*x + *w > dw)
2939 return -EINVAL;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002940
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002941 if (*y + *h > dh)
2942 return -EINVAL;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002943
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002944 if (*w == 1)
2945 return -EINVAL;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002946
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002947 if (*w == 0 || *h == 0)
2948 return -EINVAL;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002949
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002950 dsi_perf_mark_setup();
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002951
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002952 if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) {
Tomi Valkeinen26a8c252010-06-09 15:31:34 +03002953 dss_setup_partial_planes(dssdev, x, y, w, h,
2954 enlarge_update_area);
Sumit Semwal64ba4f72010-12-02 11:27:10 +00002955 dispc_set_lcd_size(dssdev->manager->id, *w, *h);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002956 }
2957
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002958 return 0;
2959}
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002960EXPORT_SYMBOL(omap_dsi_prepare_update);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002961
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002962int omap_dsi_update(struct omap_dss_device *dssdev,
2963 int channel,
2964 u16 x, u16 y, u16 w, u16 h,
2965 void (*callback)(int, void *), void *data)
2966{
2967 dsi.update_channel = channel;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002968
Tomi Valkeinena6027712010-05-25 17:01:28 +03002969 /* OMAP DSS cannot send updates of odd widths.
2970 * omap_dsi_prepare_update() makes the widths even, but add a BUG_ON
2971 * here to make sure we catch erroneous updates. Otherwise we'll only
2972 * see rather obscure HW error happening, as DSS halts. */
2973 BUG_ON(x % 2 == 1);
2974
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002975 if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) {
2976 dsi.framedone_callback = callback;
2977 dsi.framedone_data = data;
2978
2979 dsi.update_region.x = x;
2980 dsi.update_region.y = y;
2981 dsi.update_region.w = w;
2982 dsi.update_region.h = h;
2983 dsi.update_region.device = dssdev;
2984
2985 dsi_update_screen_dispc(dssdev, x, y, w, h);
2986 } else {
Archit Tanejae9c31af2010-07-14 14:11:50 +02002987 int r;
2988
2989 r = dsi_update_screen_l4(dssdev, x, y, w, h);
2990 if (r)
2991 return r;
2992
Tomi Valkeinen18946f62010-01-12 14:16:41 +02002993 dsi_perf_show("L4");
2994 callback(0, data);
2995 }
2996
2997 return 0;
2998}
2999EXPORT_SYMBOL(omap_dsi_update);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003000
3001/* Display funcs */
3002
3003static int dsi_display_init_dispc(struct omap_dss_device *dssdev)
3004{
3005 int r;
3006
3007 r = omap_dispc_register_isr(dsi_framedone_irq_callback, NULL,
3008 DISPC_IRQ_FRAMEDONE);
3009 if (r) {
3010 DSSERR("can't get FRAMEDONE irq\n");
3011 return r;
3012 }
3013
Sumit Semwal64ba4f72010-12-02 11:27:10 +00003014 dispc_set_lcd_display_type(dssdev->manager->id,
3015 OMAP_DSS_LCD_DISPLAY_TFT);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003016
Sumit Semwal64ba4f72010-12-02 11:27:10 +00003017 dispc_set_parallel_interface_mode(dssdev->manager->id,
3018 OMAP_DSS_PARALLELMODE_DSI);
3019 dispc_enable_fifohandcheck(dssdev->manager->id, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003020
Sumit Semwal64ba4f72010-12-02 11:27:10 +00003021 dispc_set_tft_data_lines(dssdev->manager->id, dssdev->ctrl.pixel_size);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003022
3023 {
3024 struct omap_video_timings timings = {
3025 .hsw = 1,
3026 .hfp = 1,
3027 .hbp = 1,
3028 .vsw = 1,
3029 .vfp = 0,
3030 .vbp = 0,
3031 };
3032
Sumit Semwal64ba4f72010-12-02 11:27:10 +00003033 dispc_set_lcd_timings(dssdev->manager->id, &timings);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003034 }
3035
3036 return 0;
3037}
3038
3039static void dsi_display_uninit_dispc(struct omap_dss_device *dssdev)
3040{
3041 omap_dispc_unregister_isr(dsi_framedone_irq_callback, NULL,
3042 DISPC_IRQ_FRAMEDONE);
3043}
3044
3045static int dsi_configure_dsi_clocks(struct omap_dss_device *dssdev)
3046{
3047 struct dsi_clock_info cinfo;
3048 int r;
3049
Archit Taneja1bb47832011-02-24 14:17:30 +05303050 /* we always use DSS_CLK_SYSCK as input clock */
3051 cinfo.use_sys_clk = true;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003052 cinfo.regn = dssdev->phy.dsi.div.regn;
3053 cinfo.regm = dssdev->phy.dsi.div.regm;
Archit Taneja1bb47832011-02-24 14:17:30 +05303054 cinfo.regm_dispc = dssdev->phy.dsi.div.regm_dispc;
3055 cinfo.regm_dsi = dssdev->phy.dsi.div.regm_dsi;
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00003056 r = dsi_calc_clock_rates(dssdev, &cinfo);
Ville Syrjäläebf0a3f2010-04-22 22:50:05 +02003057 if (r) {
3058 DSSERR("Failed to calc dsi clocks\n");
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003059 return r;
Ville Syrjäläebf0a3f2010-04-22 22:50:05 +02003060 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003061
3062 r = dsi_pll_set_clock_div(&cinfo);
3063 if (r) {
3064 DSSERR("Failed to set dsi clocks\n");
3065 return r;
3066 }
3067
3068 return 0;
3069}
3070
3071static int dsi_configure_dispc_clocks(struct omap_dss_device *dssdev)
3072{
3073 struct dispc_clock_info dispc_cinfo;
3074 int r;
3075 unsigned long long fck;
3076
Archit Taneja1bb47832011-02-24 14:17:30 +05303077 fck = dsi_get_pll_hsdiv_dispc_rate();
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003078
3079 dispc_cinfo.lck_div = dssdev->phy.dsi.div.lck_div;
3080 dispc_cinfo.pck_div = dssdev->phy.dsi.div.pck_div;
3081
3082 r = dispc_calc_clock_rates(fck, &dispc_cinfo);
3083 if (r) {
3084 DSSERR("Failed to calc dispc clocks\n");
3085 return r;
3086 }
3087
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00003088 r = dispc_set_clock_div(dssdev->manager->id, &dispc_cinfo);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003089 if (r) {
3090 DSSERR("Failed to set dispc clocks\n");
3091 return r;
3092 }
3093
3094 return 0;
3095}
3096
3097static int dsi_display_init_dsi(struct omap_dss_device *dssdev)
3098{
3099 int r;
3100
3101 _dsi_print_reset_status();
3102
3103 r = dsi_pll_init(dssdev, true, true);
3104 if (r)
3105 goto err0;
3106
3107 r = dsi_configure_dsi_clocks(dssdev);
3108 if (r)
3109 goto err1;
3110
Archit Taneja88134fa2011-01-06 10:44:10 +05303111 dss_select_dispc_clk_source(DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC);
3112 dss_select_dsi_clk_source(DSS_CLK_SRC_DSI_PLL_HSDIV_DSI);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003113
3114 DSSDBG("PLL OK\n");
3115
3116 r = dsi_configure_dispc_clocks(dssdev);
3117 if (r)
3118 goto err2;
3119
3120 r = dsi_complexio_init(dssdev);
3121 if (r)
3122 goto err2;
3123
3124 _dsi_print_reset_status();
3125
3126 dsi_proto_timings(dssdev);
3127 dsi_set_lp_clk_divisor(dssdev);
3128
3129 if (1)
3130 _dsi_print_reset_status();
3131
3132 r = dsi_proto_config(dssdev);
3133 if (r)
3134 goto err3;
3135
3136 /* enable interface */
3137 dsi_vc_enable(0, 1);
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02003138 dsi_vc_enable(1, 1);
3139 dsi_vc_enable(2, 1);
3140 dsi_vc_enable(3, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003141 dsi_if_enable(1);
3142 dsi_force_tx_stop_mode_io();
3143
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003144 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003145err3:
3146 dsi_complexio_uninit();
3147err2:
Archit Taneja88134fa2011-01-06 10:44:10 +05303148 dss_select_dispc_clk_source(DSS_CLK_SRC_FCK);
3149 dss_select_dsi_clk_source(DSS_CLK_SRC_FCK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003150err1:
3151 dsi_pll_uninit();
3152err0:
3153 return r;
3154}
3155
3156static void dsi_display_uninit_dsi(struct omap_dss_device *dssdev)
3157{
Ville Syrjäläd7370102010-04-22 22:50:09 +02003158 /* disable interface */
3159 dsi_if_enable(0);
3160 dsi_vc_enable(0, 0);
3161 dsi_vc_enable(1, 0);
3162 dsi_vc_enable(2, 0);
3163 dsi_vc_enable(3, 0);
3164
Archit Taneja88134fa2011-01-06 10:44:10 +05303165 dss_select_dispc_clk_source(DSS_CLK_SRC_FCK);
3166 dss_select_dsi_clk_source(DSS_CLK_SRC_FCK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003167 dsi_complexio_uninit();
3168 dsi_pll_uninit();
3169}
3170
3171static int dsi_core_init(void)
3172{
3173 /* Autoidle */
3174 REG_FLD_MOD(DSI_SYSCONFIG, 1, 0, 0);
3175
3176 /* ENWAKEUP */
3177 REG_FLD_MOD(DSI_SYSCONFIG, 1, 2, 2);
3178
3179 /* SIDLEMODE smart-idle */
3180 REG_FLD_MOD(DSI_SYSCONFIG, 2, 4, 3);
3181
3182 _dsi_initialize_irq();
3183
3184 return 0;
3185}
3186
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003187int omapdss_dsi_display_enable(struct omap_dss_device *dssdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003188{
3189 int r = 0;
3190
3191 DSSDBG("dsi_display_enable\n");
3192
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003193 WARN_ON(!dsi_bus_is_locked());
3194
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003195 mutex_lock(&dsi.lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003196
3197 r = omap_dss_start_device(dssdev);
3198 if (r) {
3199 DSSERR("failed to start device\n");
3200 goto err0;
3201 }
3202
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003203 enable_clocks(1);
3204 dsi_enable_pll_clock(1);
3205
3206 r = _dsi_reset();
3207 if (r)
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003208 goto err1;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003209
3210 dsi_core_init();
3211
3212 r = dsi_display_init_dispc(dssdev);
3213 if (r)
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003214 goto err1;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003215
3216 r = dsi_display_init_dsi(dssdev);
3217 if (r)
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003218 goto err2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003219
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003220 mutex_unlock(&dsi.lock);
3221
3222 return 0;
3223
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003224err2:
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003225 dsi_display_uninit_dispc(dssdev);
3226err1:
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003227 enable_clocks(0);
3228 dsi_enable_pll_clock(0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003229 omap_dss_stop_device(dssdev);
3230err0:
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003231 mutex_unlock(&dsi.lock);
3232 DSSDBG("dsi_display_enable FAILED\n");
3233 return r;
3234}
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003235EXPORT_SYMBOL(omapdss_dsi_display_enable);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003236
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003237void omapdss_dsi_display_disable(struct omap_dss_device *dssdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003238{
3239 DSSDBG("dsi_display_disable\n");
3240
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003241 WARN_ON(!dsi_bus_is_locked());
3242
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003243 mutex_lock(&dsi.lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003244
3245 dsi_display_uninit_dispc(dssdev);
3246
3247 dsi_display_uninit_dsi(dssdev);
3248
3249 enable_clocks(0);
3250 dsi_enable_pll_clock(0);
3251
3252 omap_dss_stop_device(dssdev);
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003253
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003254 mutex_unlock(&dsi.lock);
3255}
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02003256EXPORT_SYMBOL(omapdss_dsi_display_disable);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003257
Tomi Valkeinen225b6502010-01-11 15:11:01 +02003258int omapdss_dsi_enable_te(struct omap_dss_device *dssdev, bool enable)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003259{
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003260 dsi.te_enabled = enable;
Tomi Valkeinen225b6502010-01-11 15:11:01 +02003261 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003262}
Tomi Valkeinen225b6502010-01-11 15:11:01 +02003263EXPORT_SYMBOL(omapdss_dsi_enable_te);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003264
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003265void dsi_get_overlay_fifo_thresholds(enum omap_plane plane,
3266 u32 fifo_size, enum omap_burst_size *burst_size,
3267 u32 *fifo_low, u32 *fifo_high)
3268{
3269 unsigned burst_size_bytes;
3270
3271 *burst_size = OMAP_DSS_BURST_16x32;
3272 burst_size_bytes = 16 * 32 / 8;
3273
3274 *fifo_high = fifo_size - burst_size_bytes;
Tomi Valkeinen36194b42010-05-18 13:35:37 +03003275 *fifo_low = fifo_size - burst_size_bytes * 2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003276}
3277
3278int dsi_init_display(struct omap_dss_device *dssdev)
3279{
3280 DSSDBG("DSI init\n");
3281
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003282 /* XXX these should be figured out dynamically */
3283 dssdev->caps = OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE |
3284 OMAP_DSS_DISPLAY_CAP_TEAR_ELIM;
3285
Tomi Valkeinen5f42f2c2011-02-22 15:53:46 +02003286 if (dsi.vdds_dsi_reg == NULL) {
3287 struct regulator *vdds_dsi;
3288
3289 vdds_dsi = regulator_get(&dsi.pdev->dev, "vdds_dsi");
3290
3291 if (IS_ERR(vdds_dsi)) {
3292 DSSERR("can't get VDDS_DSI regulator\n");
3293 return PTR_ERR(vdds_dsi);
3294 }
3295
3296 dsi.vdds_dsi_reg = vdds_dsi;
3297 }
3298
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003299 return 0;
3300}
3301
Archit Taneja5ee3c142011-03-02 12:35:53 +05303302int omap_dsi_request_vc(struct omap_dss_device *dssdev, int *channel)
3303{
3304 int i;
3305
3306 for (i = 0; i < ARRAY_SIZE(dsi.vc); i++) {
3307 if (!dsi.vc[i].dssdev) {
3308 dsi.vc[i].dssdev = dssdev;
3309 *channel = i;
3310 return 0;
3311 }
3312 }
3313
3314 DSSERR("cannot get VC for display %s", dssdev->name);
3315 return -ENOSPC;
3316}
3317EXPORT_SYMBOL(omap_dsi_request_vc);
3318
3319int omap_dsi_set_vc_id(struct omap_dss_device *dssdev, int channel, int vc_id)
3320{
3321 if (vc_id < 0 || vc_id > 3) {
3322 DSSERR("VC ID out of range\n");
3323 return -EINVAL;
3324 }
3325
3326 if (channel < 0 || channel > 3) {
3327 DSSERR("Virtual Channel out of range\n");
3328 return -EINVAL;
3329 }
3330
3331 if (dsi.vc[channel].dssdev != dssdev) {
3332 DSSERR("Virtual Channel not allocated to display %s\n",
3333 dssdev->name);
3334 return -EINVAL;
3335 }
3336
3337 dsi.vc[channel].vc_id = vc_id;
3338
3339 return 0;
3340}
3341EXPORT_SYMBOL(omap_dsi_set_vc_id);
3342
3343void omap_dsi_release_vc(struct omap_dss_device *dssdev, int channel)
3344{
3345 if ((channel >= 0 && channel <= 3) &&
3346 dsi.vc[channel].dssdev == dssdev) {
3347 dsi.vc[channel].dssdev = NULL;
3348 dsi.vc[channel].vc_id = 0;
3349 }
3350}
3351EXPORT_SYMBOL(omap_dsi_release_vc);
3352
Archit Taneja1bb47832011-02-24 14:17:30 +05303353void dsi_wait_pll_hsdiv_dispc_active(void)
Tomi Valkeinene406f902010-06-09 15:28:12 +03003354{
3355 if (wait_for_bit_change(DSI_PLL_STATUS, 7, 1) != 1)
Archit Taneja067a57e2011-03-02 11:57:25 +05303356 DSSERR("%s (%s) not active\n",
3357 dss_get_generic_clk_source_name(DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
3358 dss_feat_get_clk_source_name(DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC));
Tomi Valkeinene406f902010-06-09 15:28:12 +03003359}
3360
Archit Taneja1bb47832011-02-24 14:17:30 +05303361void dsi_wait_pll_hsdiv_dsi_active(void)
Tomi Valkeinene406f902010-06-09 15:28:12 +03003362{
3363 if (wait_for_bit_change(DSI_PLL_STATUS, 8, 1) != 1)
Archit Taneja067a57e2011-03-02 11:57:25 +05303364 DSSERR("%s (%s) not active\n",
3365 dss_get_generic_clk_source_name(DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
3366 dss_feat_get_clk_source_name(DSS_CLK_SRC_DSI_PLL_HSDIV_DSI));
Tomi Valkeinene406f902010-06-09 15:28:12 +03003367}
3368
Taneja, Archit49641112011-03-14 23:28:23 -05003369static void dsi_calc_clock_param_ranges(void)
3370{
3371 dsi.regn_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGN);
3372 dsi.regm_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM);
3373 dsi.regm_dispc_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DISPC);
3374 dsi.regm_dsi_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DSI);
3375 dsi.fint_min = dss_feat_get_param_min(FEAT_PARAM_DSIPLL_FINT);
3376 dsi.fint_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_FINT);
3377 dsi.lpdiv_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_LPDIV);
3378}
3379
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00003380static int dsi_init(struct platform_device *pdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003381{
3382 u32 rev;
Archit Taneja5ee3c142011-03-02 12:35:53 +05303383 int r, i;
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00003384 struct resource *dsi_mem;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003385
3386 spin_lock_init(&dsi.errors_lock);
3387 dsi.errors = 0;
3388
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02003389#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
3390 spin_lock_init(&dsi.irq_stats_lock);
3391 dsi.irq_stats.last_reset = jiffies;
3392#endif
3393
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003394 init_completion(&dsi.bta_completion);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003395
3396 mutex_init(&dsi.lock);
Tomi Valkeinenb9eb5d72010-01-11 16:33:56 +02003397 sema_init(&dsi.bus_lock, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003398
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03003399 dsi.workqueue = create_singlethread_workqueue("dsi");
3400 if (dsi.workqueue == NULL)
3401 return -ENOMEM;
3402
Tomi Valkeinen18946f62010-01-12 14:16:41 +02003403 INIT_DELAYED_WORK_DEFERRABLE(&dsi.framedone_timeout_work,
3404 dsi_framedone_timeout_work_callback);
3405
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003406#ifdef DSI_CATCH_MISSING_TE
3407 init_timer(&dsi.te_timer);
3408 dsi.te_timer.function = dsi_te_timeout;
3409 dsi.te_timer.data = 0;
3410#endif
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00003411 dsi_mem = platform_get_resource(dsi.pdev, IORESOURCE_MEM, 0);
3412 if (!dsi_mem) {
3413 DSSERR("can't get IORESOURCE_MEM DSI\n");
3414 r = -EINVAL;
3415 goto err1;
3416 }
3417 dsi.base = ioremap(dsi_mem->start, resource_size(dsi_mem));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003418 if (!dsi.base) {
3419 DSSERR("can't ioremap DSI\n");
3420 r = -ENOMEM;
3421 goto err1;
3422 }
archit tanejaaffe3602011-02-23 08:41:03 +00003423 dsi.irq = platform_get_irq(dsi.pdev, 0);
3424 if (dsi.irq < 0) {
3425 DSSERR("platform_get_irq failed\n");
3426 r = -ENODEV;
3427 goto err2;
3428 }
3429
3430 r = request_irq(dsi.irq, omap_dsi_irq_handler, IRQF_SHARED,
3431 "OMAP DSI1", dsi.pdev);
3432 if (r < 0) {
3433 DSSERR("request_irq failed\n");
3434 goto err2;
3435 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003436
Archit Taneja5ee3c142011-03-02 12:35:53 +05303437 /* DSI VCs initialization */
3438 for (i = 0; i < ARRAY_SIZE(dsi.vc); i++) {
3439 dsi.vc[i].mode = DSI_VC_MODE_L4;
3440 dsi.vc[i].dssdev = NULL;
3441 dsi.vc[i].vc_id = 0;
3442 }
3443
Taneja, Archit49641112011-03-14 23:28:23 -05003444 dsi_calc_clock_param_ranges();
3445
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003446 enable_clocks(1);
3447
3448 rev = dsi_read_reg(DSI_REVISION);
Sumit Semwala06b62f2011-01-24 06:22:03 +00003449 dev_dbg(&pdev->dev, "OMAP DSI rev %d.%d\n",
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003450 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
3451
3452 enable_clocks(0);
3453
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003454 return 0;
archit tanejaaffe3602011-02-23 08:41:03 +00003455err2:
3456 iounmap(dsi.base);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003457err1:
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03003458 destroy_workqueue(dsi.workqueue);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003459 return r;
3460}
3461
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00003462static void dsi_exit(void)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003463{
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00003464 if (dsi.vdds_dsi_reg != NULL) {
3465 regulator_put(dsi.vdds_dsi_reg);
3466 dsi.vdds_dsi_reg = NULL;
3467 }
3468
archit tanejaaffe3602011-02-23 08:41:03 +00003469 free_irq(dsi.irq, dsi.pdev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003470 iounmap(dsi.base);
3471
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03003472 destroy_workqueue(dsi.workqueue);
3473
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003474 DSSDBG("omap_dsi_exit\n");
3475}
3476
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00003477/* DSI1 HW IP initialisation */
3478static int omap_dsi1hw_probe(struct platform_device *pdev)
3479{
3480 int r;
3481 dsi.pdev = pdev;
3482 r = dsi_init(pdev);
3483 if (r) {
3484 DSSERR("Failed to initialize DSI\n");
3485 goto err_dsi;
3486 }
3487err_dsi:
3488 return r;
3489}
3490
3491static int omap_dsi1hw_remove(struct platform_device *pdev)
3492{
3493 dsi_exit();
3494 return 0;
3495}
3496
3497static struct platform_driver omap_dsi1hw_driver = {
3498 .probe = omap_dsi1hw_probe,
3499 .remove = omap_dsi1hw_remove,
3500 .driver = {
3501 .name = "omapdss_dsi1",
3502 .owner = THIS_MODULE,
3503 },
3504};
3505
3506int dsi_init_platform_driver(void)
3507{
3508 return platform_driver_register(&omap_dsi1hw_driver);
3509}
3510
3511void dsi_uninit_platform_driver(void)
3512{
3513 return platform_driver_unregister(&omap_dsi1hw_driver);
3514}