blob: 6735e0c8bdf7237ab58b8c287dea7fd241acbc8f [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 Valkeinen40885ab2010-07-28 15:53:38 +030036#include <linux/sched.h>
Archit Tanejaf1da39d2011-05-12 17:26:27 +053037#include <linux/slab.h>
Archit Taneja5a8b5722011-05-12 17:26:29 +053038#include <linux/debugfs.h>
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030039#include <linux/pm_runtime.h>
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +020040
Tomi Valkeinena0b38cc2011-05-11 14:05:07 +030041#include <video/omapdss.h>
Archit Taneja7a7c48f2011-08-25 18:25:03 +053042#include <video/mipi_display.h>
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +020043#include <plat/clock.h>
44
45#include "dss.h"
Archit Taneja819d8072011-03-01 11:54:00 +053046#include "dss_features.h"
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +020047
48/*#define VERBOSE_IRQ*/
49#define DSI_CATCH_MISSING_TE
50
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +020051struct dsi_reg { u16 idx; };
52
53#define DSI_REG(idx) ((const struct dsi_reg) { idx })
54
55#define DSI_SZ_REGS SZ_1K
56/* DSI Protocol Engine */
57
58#define DSI_REVISION DSI_REG(0x0000)
59#define DSI_SYSCONFIG DSI_REG(0x0010)
60#define DSI_SYSSTATUS DSI_REG(0x0014)
61#define DSI_IRQSTATUS DSI_REG(0x0018)
62#define DSI_IRQENABLE DSI_REG(0x001C)
63#define DSI_CTRL DSI_REG(0x0040)
Archit Taneja75d72472011-05-16 15:17:08 +053064#define DSI_GNQ DSI_REG(0x0044)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +020065#define DSI_COMPLEXIO_CFG1 DSI_REG(0x0048)
66#define DSI_COMPLEXIO_IRQ_STATUS DSI_REG(0x004C)
67#define DSI_COMPLEXIO_IRQ_ENABLE DSI_REG(0x0050)
68#define DSI_CLK_CTRL DSI_REG(0x0054)
69#define DSI_TIMING1 DSI_REG(0x0058)
70#define DSI_TIMING2 DSI_REG(0x005C)
71#define DSI_VM_TIMING1 DSI_REG(0x0060)
72#define DSI_VM_TIMING2 DSI_REG(0x0064)
73#define DSI_VM_TIMING3 DSI_REG(0x0068)
74#define DSI_CLK_TIMING DSI_REG(0x006C)
75#define DSI_TX_FIFO_VC_SIZE DSI_REG(0x0070)
76#define DSI_RX_FIFO_VC_SIZE DSI_REG(0x0074)
77#define DSI_COMPLEXIO_CFG2 DSI_REG(0x0078)
78#define DSI_RX_FIFO_VC_FULLNESS DSI_REG(0x007C)
79#define DSI_VM_TIMING4 DSI_REG(0x0080)
80#define DSI_TX_FIFO_VC_EMPTINESS DSI_REG(0x0084)
81#define DSI_VM_TIMING5 DSI_REG(0x0088)
82#define DSI_VM_TIMING6 DSI_REG(0x008C)
83#define DSI_VM_TIMING7 DSI_REG(0x0090)
84#define DSI_STOPCLK_TIMING DSI_REG(0x0094)
85#define DSI_VC_CTRL(n) DSI_REG(0x0100 + (n * 0x20))
86#define DSI_VC_TE(n) DSI_REG(0x0104 + (n * 0x20))
87#define DSI_VC_LONG_PACKET_HEADER(n) DSI_REG(0x0108 + (n * 0x20))
88#define DSI_VC_LONG_PACKET_PAYLOAD(n) DSI_REG(0x010C + (n * 0x20))
89#define DSI_VC_SHORT_PACKET_HEADER(n) DSI_REG(0x0110 + (n * 0x20))
90#define DSI_VC_IRQSTATUS(n) DSI_REG(0x0118 + (n * 0x20))
91#define DSI_VC_IRQENABLE(n) DSI_REG(0x011C + (n * 0x20))
92
93/* DSIPHY_SCP */
94
95#define DSI_DSIPHY_CFG0 DSI_REG(0x200 + 0x0000)
96#define DSI_DSIPHY_CFG1 DSI_REG(0x200 + 0x0004)
97#define DSI_DSIPHY_CFG2 DSI_REG(0x200 + 0x0008)
98#define DSI_DSIPHY_CFG5 DSI_REG(0x200 + 0x0014)
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +030099#define DSI_DSIPHY_CFG10 DSI_REG(0x200 + 0x0028)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200100
101/* DSI_PLL_CTRL_SCP */
102
103#define DSI_PLL_CONTROL DSI_REG(0x300 + 0x0000)
104#define DSI_PLL_STATUS DSI_REG(0x300 + 0x0004)
105#define DSI_PLL_GO DSI_REG(0x300 + 0x0008)
106#define DSI_PLL_CONFIGURATION1 DSI_REG(0x300 + 0x000C)
107#define DSI_PLL_CONFIGURATION2 DSI_REG(0x300 + 0x0010)
108
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530109#define REG_GET(dsidev, idx, start, end) \
110 FLD_GET(dsi_read_reg(dsidev, idx), start, end)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200111
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530112#define REG_FLD_MOD(dsidev, idx, val, start, end) \
113 dsi_write_reg(dsidev, idx, FLD_MOD(dsi_read_reg(dsidev, idx), val, start, end))
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200114
115/* Global interrupts */
116#define DSI_IRQ_VC0 (1 << 0)
117#define DSI_IRQ_VC1 (1 << 1)
118#define DSI_IRQ_VC2 (1 << 2)
119#define DSI_IRQ_VC3 (1 << 3)
120#define DSI_IRQ_WAKEUP (1 << 4)
121#define DSI_IRQ_RESYNC (1 << 5)
122#define DSI_IRQ_PLL_LOCK (1 << 7)
123#define DSI_IRQ_PLL_UNLOCK (1 << 8)
124#define DSI_IRQ_PLL_RECALL (1 << 9)
125#define DSI_IRQ_COMPLEXIO_ERR (1 << 10)
126#define DSI_IRQ_HS_TX_TIMEOUT (1 << 14)
127#define DSI_IRQ_LP_RX_TIMEOUT (1 << 15)
128#define DSI_IRQ_TE_TRIGGER (1 << 16)
129#define DSI_IRQ_ACK_TRIGGER (1 << 17)
130#define DSI_IRQ_SYNC_LOST (1 << 18)
131#define DSI_IRQ_LDO_POWER_GOOD (1 << 19)
132#define DSI_IRQ_TA_TIMEOUT (1 << 20)
133#define DSI_IRQ_ERROR_MASK \
134 (DSI_IRQ_HS_TX_TIMEOUT | DSI_IRQ_LP_RX_TIMEOUT | DSI_IRQ_SYNC_LOST | \
135 DSI_IRQ_TA_TIMEOUT)
136#define DSI_IRQ_CHANNEL_MASK 0xf
137
138/* Virtual channel interrupts */
139#define DSI_VC_IRQ_CS (1 << 0)
140#define DSI_VC_IRQ_ECC_CORR (1 << 1)
141#define DSI_VC_IRQ_PACKET_SENT (1 << 2)
142#define DSI_VC_IRQ_FIFO_TX_OVF (1 << 3)
143#define DSI_VC_IRQ_FIFO_RX_OVF (1 << 4)
144#define DSI_VC_IRQ_BTA (1 << 5)
145#define DSI_VC_IRQ_ECC_NO_CORR (1 << 6)
146#define DSI_VC_IRQ_FIFO_TX_UDF (1 << 7)
147#define DSI_VC_IRQ_PP_BUSY_CHANGE (1 << 8)
148#define DSI_VC_IRQ_ERROR_MASK \
149 (DSI_VC_IRQ_CS | DSI_VC_IRQ_ECC_CORR | DSI_VC_IRQ_FIFO_TX_OVF | \
150 DSI_VC_IRQ_FIFO_RX_OVF | DSI_VC_IRQ_ECC_NO_CORR | \
151 DSI_VC_IRQ_FIFO_TX_UDF)
152
153/* ComplexIO interrupts */
154#define DSI_CIO_IRQ_ERRSYNCESC1 (1 << 0)
155#define DSI_CIO_IRQ_ERRSYNCESC2 (1 << 1)
156#define DSI_CIO_IRQ_ERRSYNCESC3 (1 << 2)
Tomi Valkeinen67056152011-03-24 16:30:17 +0200157#define DSI_CIO_IRQ_ERRSYNCESC4 (1 << 3)
158#define DSI_CIO_IRQ_ERRSYNCESC5 (1 << 4)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200159#define DSI_CIO_IRQ_ERRESC1 (1 << 5)
160#define DSI_CIO_IRQ_ERRESC2 (1 << 6)
161#define DSI_CIO_IRQ_ERRESC3 (1 << 7)
Tomi Valkeinen67056152011-03-24 16:30:17 +0200162#define DSI_CIO_IRQ_ERRESC4 (1 << 8)
163#define DSI_CIO_IRQ_ERRESC5 (1 << 9)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200164#define DSI_CIO_IRQ_ERRCONTROL1 (1 << 10)
165#define DSI_CIO_IRQ_ERRCONTROL2 (1 << 11)
166#define DSI_CIO_IRQ_ERRCONTROL3 (1 << 12)
Tomi Valkeinen67056152011-03-24 16:30:17 +0200167#define DSI_CIO_IRQ_ERRCONTROL4 (1 << 13)
168#define DSI_CIO_IRQ_ERRCONTROL5 (1 << 14)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200169#define DSI_CIO_IRQ_STATEULPS1 (1 << 15)
170#define DSI_CIO_IRQ_STATEULPS2 (1 << 16)
171#define DSI_CIO_IRQ_STATEULPS3 (1 << 17)
Tomi Valkeinen67056152011-03-24 16:30:17 +0200172#define DSI_CIO_IRQ_STATEULPS4 (1 << 18)
173#define DSI_CIO_IRQ_STATEULPS5 (1 << 19)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200174#define DSI_CIO_IRQ_ERRCONTENTIONLP0_1 (1 << 20)
175#define DSI_CIO_IRQ_ERRCONTENTIONLP1_1 (1 << 21)
176#define DSI_CIO_IRQ_ERRCONTENTIONLP0_2 (1 << 22)
177#define DSI_CIO_IRQ_ERRCONTENTIONLP1_2 (1 << 23)
178#define DSI_CIO_IRQ_ERRCONTENTIONLP0_3 (1 << 24)
179#define DSI_CIO_IRQ_ERRCONTENTIONLP1_3 (1 << 25)
Tomi Valkeinen67056152011-03-24 16:30:17 +0200180#define DSI_CIO_IRQ_ERRCONTENTIONLP0_4 (1 << 26)
181#define DSI_CIO_IRQ_ERRCONTENTIONLP1_4 (1 << 27)
182#define DSI_CIO_IRQ_ERRCONTENTIONLP0_5 (1 << 28)
183#define DSI_CIO_IRQ_ERRCONTENTIONLP1_5 (1 << 29)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200184#define DSI_CIO_IRQ_ULPSACTIVENOT_ALL0 (1 << 30)
185#define DSI_CIO_IRQ_ULPSACTIVENOT_ALL1 (1 << 31)
Tomi Valkeinenbbecb502010-05-10 14:35:33 +0300186#define DSI_CIO_IRQ_ERROR_MASK \
187 (DSI_CIO_IRQ_ERRSYNCESC1 | DSI_CIO_IRQ_ERRSYNCESC2 | \
Tomi Valkeinen67056152011-03-24 16:30:17 +0200188 DSI_CIO_IRQ_ERRSYNCESC3 | DSI_CIO_IRQ_ERRSYNCESC4 | \
189 DSI_CIO_IRQ_ERRSYNCESC5 | \
190 DSI_CIO_IRQ_ERRESC1 | DSI_CIO_IRQ_ERRESC2 | \
191 DSI_CIO_IRQ_ERRESC3 | DSI_CIO_IRQ_ERRESC4 | \
192 DSI_CIO_IRQ_ERRESC5 | \
193 DSI_CIO_IRQ_ERRCONTROL1 | DSI_CIO_IRQ_ERRCONTROL2 | \
194 DSI_CIO_IRQ_ERRCONTROL3 | DSI_CIO_IRQ_ERRCONTROL4 | \
195 DSI_CIO_IRQ_ERRCONTROL5 | \
Tomi Valkeinenbbecb502010-05-10 14:35:33 +0300196 DSI_CIO_IRQ_ERRCONTENTIONLP0_1 | DSI_CIO_IRQ_ERRCONTENTIONLP1_1 | \
197 DSI_CIO_IRQ_ERRCONTENTIONLP0_2 | DSI_CIO_IRQ_ERRCONTENTIONLP1_2 | \
Tomi Valkeinen67056152011-03-24 16:30:17 +0200198 DSI_CIO_IRQ_ERRCONTENTIONLP0_3 | DSI_CIO_IRQ_ERRCONTENTIONLP1_3 | \
199 DSI_CIO_IRQ_ERRCONTENTIONLP0_4 | DSI_CIO_IRQ_ERRCONTENTIONLP1_4 | \
200 DSI_CIO_IRQ_ERRCONTENTIONLP0_5 | DSI_CIO_IRQ_ERRCONTENTIONLP1_5)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200201
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200202typedef void (*omap_dsi_isr_t) (void *arg, u32 mask);
203
204#define DSI_MAX_NR_ISRS 2
205
206struct dsi_isr_data {
207 omap_dsi_isr_t isr;
208 void *arg;
209 u32 mask;
210};
211
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200212enum fifo_size {
213 DSI_FIFO_SIZE_0 = 0,
214 DSI_FIFO_SIZE_32 = 1,
215 DSI_FIFO_SIZE_64 = 2,
216 DSI_FIFO_SIZE_96 = 3,
217 DSI_FIFO_SIZE_128 = 4,
218};
219
220enum dsi_vc_mode {
221 DSI_VC_MODE_L4 = 0,
222 DSI_VC_MODE_VP,
223};
224
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +0300225enum dsi_lane {
226 DSI_CLK_P = 1 << 0,
227 DSI_CLK_N = 1 << 1,
228 DSI_DATA1_P = 1 << 2,
229 DSI_DATA1_N = 1 << 3,
230 DSI_DATA2_P = 1 << 4,
231 DSI_DATA2_N = 1 << 5,
Archit Taneja75d72472011-05-16 15:17:08 +0530232 DSI_DATA3_P = 1 << 6,
233 DSI_DATA3_N = 1 << 7,
234 DSI_DATA4_P = 1 << 8,
235 DSI_DATA4_N = 1 << 9,
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +0300236};
237
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200238struct dsi_update_region {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200239 u16 x, y, w, h;
240 struct omap_dss_device *device;
241};
242
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200243struct dsi_irq_stats {
244 unsigned long last_reset;
245 unsigned irq_count;
246 unsigned dsi_irqs[32];
247 unsigned vc_irqs[4][32];
248 unsigned cio_irqs[32];
249};
250
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200251struct dsi_isr_tables {
252 struct dsi_isr_data isr_table[DSI_MAX_NR_ISRS];
253 struct dsi_isr_data isr_table_vc[4][DSI_MAX_NR_ISRS];
254 struct dsi_isr_data isr_table_cio[DSI_MAX_NR_ISRS];
255};
256
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530257struct dsi_data {
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +0000258 struct platform_device *pdev;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200259 void __iomem *base;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300260
archit tanejaaffe3602011-02-23 08:41:03 +0000261 int irq;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200262
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300263 struct clk *dss_clk;
264 struct clk *sys_clk;
265
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +0300266 int (*enable_pads)(int dsi_id, unsigned lane_mask);
267 void (*disable_pads)(int dsi_id, unsigned lane_mask);
Tomi Valkeinend1f58572010-07-30 11:57:57 +0300268
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200269 struct dsi_clock_info current_cinfo;
270
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +0300271 bool vdds_dsi_enabled;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200272 struct regulator *vdds_dsi_reg;
273
274 struct {
275 enum dsi_vc_mode mode;
276 struct omap_dss_device *dssdev;
277 enum fifo_size fifo_size;
Archit Taneja5ee3c142011-03-02 12:35:53 +0530278 int vc_id;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200279 } vc[4];
280
281 struct mutex lock;
Tomi Valkeinenb9eb5d72010-01-11 16:33:56 +0200282 struct semaphore bus_lock;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200283
284 unsigned pll_locked;
285
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200286 spinlock_t irq_lock;
287 struct dsi_isr_tables isr_tables;
288 /* space for a copy used by the interrupt handler */
289 struct dsi_isr_tables isr_tables_copy;
290
Tomi Valkeinen18946f62010-01-12 14:16:41 +0200291 int update_channel;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200292 struct dsi_update_region update_region;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200293
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200294 bool te_enabled;
Tomi Valkeinen40885ab2010-07-28 15:53:38 +0300295 bool ulps_enabled;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200296
Tomi Valkeinen18946f62010-01-12 14:16:41 +0200297 void (*framedone_callback)(int, void *);
298 void *framedone_data;
299
300 struct delayed_work framedone_timeout_work;
301
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200302#ifdef DSI_CATCH_MISSING_TE
303 struct timer_list te_timer;
304#endif
305
306 unsigned long cache_req_pck;
307 unsigned long cache_clk_freq;
308 struct dsi_clock_info cache_cinfo;
309
310 u32 errors;
311 spinlock_t errors_lock;
312#ifdef DEBUG
313 ktime_t perf_setup_time;
314 ktime_t perf_start_time;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200315#endif
316 int debug_read;
317 int debug_write;
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200318
319#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
320 spinlock_t irq_stats_lock;
321 struct dsi_irq_stats irq_stats;
322#endif
Taneja, Archit49641112011-03-14 23:28:23 -0500323 /* DSI PLL Parameter Ranges */
324 unsigned long regm_max, regn_max;
325 unsigned long regm_dispc_max, regm_dsi_max;
326 unsigned long fint_min, fint_max;
327 unsigned long lpdiv_max;
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +0300328
Archit Taneja75d72472011-05-16 15:17:08 +0530329 int num_data_lanes;
330
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +0300331 unsigned scp_clk_refcount;
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530332};
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200333
Archit Taneja2e868db2011-05-12 17:26:28 +0530334struct dsi_packet_sent_handler_data {
335 struct platform_device *dsidev;
336 struct completion *completion;
337};
338
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530339static struct platform_device *dsi_pdev_map[MAX_NUM_DSI];
340
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200341#ifdef DEBUG
342static unsigned int dsi_perf;
343module_param_named(dsi_perf, dsi_perf, bool, 0644);
344#endif
345
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530346static inline struct dsi_data *dsi_get_dsidrv_data(struct platform_device *dsidev)
347{
348 return dev_get_drvdata(&dsidev->dev);
349}
350
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530351static inline struct platform_device *dsi_get_dsidev_from_dssdev(struct omap_dss_device *dssdev)
352{
353 return dsi_pdev_map[dssdev->phy.dsi.module];
354}
355
356struct platform_device *dsi_get_dsidev_from_id(int module)
357{
358 return dsi_pdev_map[module];
359}
360
Tomi Valkeinen7c68dd92011-08-03 14:00:57 +0300361static inline int dsi_get_dsidev_id(struct platform_device *dsidev)
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530362{
Tomi Valkeinen7c68dd92011-08-03 14:00:57 +0300363 return dsidev->id;
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530364}
365
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530366static inline void dsi_write_reg(struct platform_device *dsidev,
367 const struct dsi_reg idx, u32 val)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200368{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530369 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
370
371 __raw_writel(val, dsi->base + idx.idx);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200372}
373
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530374static inline u32 dsi_read_reg(struct platform_device *dsidev,
375 const struct dsi_reg idx)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200376{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530377 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
378
379 return __raw_readl(dsi->base + idx.idx);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200380}
381
Archit Taneja1ffefe72011-05-12 17:26:24 +0530382void dsi_bus_lock(struct omap_dss_device *dssdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200383{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530384 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
385 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
386
387 down(&dsi->bus_lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200388}
389EXPORT_SYMBOL(dsi_bus_lock);
390
Archit Taneja1ffefe72011-05-12 17:26:24 +0530391void dsi_bus_unlock(struct omap_dss_device *dssdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200392{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530393 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
394 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
395
396 up(&dsi->bus_lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200397}
398EXPORT_SYMBOL(dsi_bus_unlock);
399
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530400static bool dsi_bus_is_locked(struct platform_device *dsidev)
Tomi Valkeinen4f765022010-01-18 16:27:52 +0200401{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530402 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
403
404 return dsi->bus_lock.count == 0;
Tomi Valkeinen4f765022010-01-18 16:27:52 +0200405}
406
Tomi Valkeinenf36a06e2011-03-02 14:48:41 +0200407static void dsi_completion_handler(void *data, u32 mask)
408{
409 complete((struct completion *)data);
410}
411
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530412static inline int wait_for_bit_change(struct platform_device *dsidev,
413 const struct dsi_reg idx, int bitnum, int value)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200414{
415 int t = 100000;
416
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530417 while (REG_GET(dsidev, idx, bitnum, bitnum) != value) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200418 if (--t == 0)
419 return !value;
420 }
421
422 return value;
423}
424
425#ifdef DEBUG
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530426static void dsi_perf_mark_setup(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200427{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530428 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
429 dsi->perf_setup_time = ktime_get();
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200430}
431
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530432static void dsi_perf_mark_start(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200433{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530434 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
435 dsi->perf_start_time = ktime_get();
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200436}
437
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530438static void dsi_perf_show(struct platform_device *dsidev, const char *name)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200439{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530440 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200441 ktime_t t, setup_time, trans_time;
442 u32 total_bytes;
443 u32 setup_us, trans_us, total_us;
444
445 if (!dsi_perf)
446 return;
447
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200448 t = ktime_get();
449
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530450 setup_time = ktime_sub(dsi->perf_start_time, dsi->perf_setup_time);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200451 setup_us = (u32)ktime_to_us(setup_time);
452 if (setup_us == 0)
453 setup_us = 1;
454
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530455 trans_time = ktime_sub(t, dsi->perf_start_time);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200456 trans_us = (u32)ktime_to_us(trans_time);
457 if (trans_us == 0)
458 trans_us = 1;
459
460 total_us = setup_us + trans_us;
461
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530462 total_bytes = dsi->update_region.w *
463 dsi->update_region.h *
464 dsi->update_region.device->ctrl.pixel_size / 8;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200465
Tomi Valkeinen1bbb2752010-01-11 16:41:10 +0200466 printk(KERN_INFO "DSI(%s): %u us + %u us = %u us (%uHz), "
467 "%u bytes, %u kbytes/sec\n",
468 name,
469 setup_us,
470 trans_us,
471 total_us,
472 1000*1000 / total_us,
473 total_bytes,
474 total_bytes * 1000 / total_us);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200475}
476#else
Tomi Valkeinen4a9a5e32011-05-23 16:36:09 +0300477static inline void dsi_perf_mark_setup(struct platform_device *dsidev)
478{
479}
480
481static inline void dsi_perf_mark_start(struct platform_device *dsidev)
482{
483}
484
485static inline void dsi_perf_show(struct platform_device *dsidev,
486 const char *name)
487{
488}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200489#endif
490
491static void print_irq_status(u32 status)
492{
Tomi Valkeinend80d4992011-03-02 15:53:07 +0200493 if (status == 0)
494 return;
495
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200496#ifndef VERBOSE_IRQ
497 if ((status & ~DSI_IRQ_CHANNEL_MASK) == 0)
498 return;
499#endif
500 printk(KERN_DEBUG "DSI IRQ: 0x%x: ", status);
501
502#define PIS(x) \
503 if (status & DSI_IRQ_##x) \
504 printk(#x " ");
505#ifdef VERBOSE_IRQ
506 PIS(VC0);
507 PIS(VC1);
508 PIS(VC2);
509 PIS(VC3);
510#endif
511 PIS(WAKEUP);
512 PIS(RESYNC);
513 PIS(PLL_LOCK);
514 PIS(PLL_UNLOCK);
515 PIS(PLL_RECALL);
516 PIS(COMPLEXIO_ERR);
517 PIS(HS_TX_TIMEOUT);
518 PIS(LP_RX_TIMEOUT);
519 PIS(TE_TRIGGER);
520 PIS(ACK_TRIGGER);
521 PIS(SYNC_LOST);
522 PIS(LDO_POWER_GOOD);
523 PIS(TA_TIMEOUT);
524#undef PIS
525
526 printk("\n");
527}
528
529static void print_irq_status_vc(int channel, u32 status)
530{
Tomi Valkeinend80d4992011-03-02 15:53:07 +0200531 if (status == 0)
532 return;
533
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200534#ifndef VERBOSE_IRQ
535 if ((status & ~DSI_VC_IRQ_PACKET_SENT) == 0)
536 return;
537#endif
538 printk(KERN_DEBUG "DSI VC(%d) IRQ 0x%x: ", channel, status);
539
540#define PIS(x) \
541 if (status & DSI_VC_IRQ_##x) \
542 printk(#x " ");
543 PIS(CS);
544 PIS(ECC_CORR);
545#ifdef VERBOSE_IRQ
546 PIS(PACKET_SENT);
547#endif
548 PIS(FIFO_TX_OVF);
549 PIS(FIFO_RX_OVF);
550 PIS(BTA);
551 PIS(ECC_NO_CORR);
552 PIS(FIFO_TX_UDF);
553 PIS(PP_BUSY_CHANGE);
554#undef PIS
555 printk("\n");
556}
557
558static void print_irq_status_cio(u32 status)
559{
Tomi Valkeinend80d4992011-03-02 15:53:07 +0200560 if (status == 0)
561 return;
562
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200563 printk(KERN_DEBUG "DSI CIO IRQ 0x%x: ", status);
564
565#define PIS(x) \
566 if (status & DSI_CIO_IRQ_##x) \
567 printk(#x " ");
568 PIS(ERRSYNCESC1);
569 PIS(ERRSYNCESC2);
570 PIS(ERRSYNCESC3);
571 PIS(ERRESC1);
572 PIS(ERRESC2);
573 PIS(ERRESC3);
574 PIS(ERRCONTROL1);
575 PIS(ERRCONTROL2);
576 PIS(ERRCONTROL3);
577 PIS(STATEULPS1);
578 PIS(STATEULPS2);
579 PIS(STATEULPS3);
580 PIS(ERRCONTENTIONLP0_1);
581 PIS(ERRCONTENTIONLP1_1);
582 PIS(ERRCONTENTIONLP0_2);
583 PIS(ERRCONTENTIONLP1_2);
584 PIS(ERRCONTENTIONLP0_3);
585 PIS(ERRCONTENTIONLP1_3);
586 PIS(ULPSACTIVENOT_ALL0);
587 PIS(ULPSACTIVENOT_ALL1);
588#undef PIS
589
590 printk("\n");
591}
592
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200593#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530594static void dsi_collect_irq_stats(struct platform_device *dsidev, u32 irqstatus,
595 u32 *vcstatus, u32 ciostatus)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200596{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530597 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200598 int i;
599
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530600 spin_lock(&dsi->irq_stats_lock);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200601
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530602 dsi->irq_stats.irq_count++;
603 dss_collect_irq_stats(irqstatus, dsi->irq_stats.dsi_irqs);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200604
605 for (i = 0; i < 4; ++i)
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530606 dss_collect_irq_stats(vcstatus[i], dsi->irq_stats.vc_irqs[i]);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200607
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530608 dss_collect_irq_stats(ciostatus, dsi->irq_stats.cio_irqs);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200609
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530610 spin_unlock(&dsi->irq_stats_lock);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200611}
612#else
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530613#define dsi_collect_irq_stats(dsidev, irqstatus, vcstatus, ciostatus)
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200614#endif
615
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200616static int debug_irq;
617
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530618static void dsi_handle_irq_errors(struct platform_device *dsidev, u32 irqstatus,
619 u32 *vcstatus, u32 ciostatus)
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200620{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530621 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200622 int i;
623
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200624 if (irqstatus & DSI_IRQ_ERROR_MASK) {
625 DSSERR("DSI error, irqstatus %x\n", irqstatus);
626 print_irq_status(irqstatus);
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530627 spin_lock(&dsi->errors_lock);
628 dsi->errors |= irqstatus & DSI_IRQ_ERROR_MASK;
629 spin_unlock(&dsi->errors_lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200630 } else if (debug_irq) {
631 print_irq_status(irqstatus);
632 }
633
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200634 for (i = 0; i < 4; ++i) {
635 if (vcstatus[i] & DSI_VC_IRQ_ERROR_MASK) {
636 DSSERR("DSI VC(%d) error, vc irqstatus %x\n",
637 i, vcstatus[i]);
638 print_irq_status_vc(i, vcstatus[i]);
639 } else if (debug_irq) {
640 print_irq_status_vc(i, vcstatus[i]);
641 }
642 }
643
644 if (ciostatus & DSI_CIO_IRQ_ERROR_MASK) {
645 DSSERR("DSI CIO error, cio irqstatus %x\n", ciostatus);
646 print_irq_status_cio(ciostatus);
647 } else if (debug_irq) {
648 print_irq_status_cio(ciostatus);
649 }
650}
651
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200652static void dsi_call_isrs(struct dsi_isr_data *isr_array,
653 unsigned isr_array_size, u32 irqstatus)
654{
655 struct dsi_isr_data *isr_data;
656 int i;
657
658 for (i = 0; i < isr_array_size; i++) {
659 isr_data = &isr_array[i];
660 if (isr_data->isr && isr_data->mask & irqstatus)
661 isr_data->isr(isr_data->arg, irqstatus);
662 }
663}
664
665static void dsi_handle_isrs(struct dsi_isr_tables *isr_tables,
666 u32 irqstatus, u32 *vcstatus, u32 ciostatus)
667{
668 int i;
669
670 dsi_call_isrs(isr_tables->isr_table,
671 ARRAY_SIZE(isr_tables->isr_table),
672 irqstatus);
673
674 for (i = 0; i < 4; ++i) {
675 if (vcstatus[i] == 0)
676 continue;
677 dsi_call_isrs(isr_tables->isr_table_vc[i],
678 ARRAY_SIZE(isr_tables->isr_table_vc[i]),
679 vcstatus[i]);
680 }
681
682 if (ciostatus != 0)
683 dsi_call_isrs(isr_tables->isr_table_cio,
684 ARRAY_SIZE(isr_tables->isr_table_cio),
685 ciostatus);
686}
687
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200688static irqreturn_t omap_dsi_irq_handler(int irq, void *arg)
689{
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530690 struct platform_device *dsidev;
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530691 struct dsi_data *dsi;
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200692 u32 irqstatus, vcstatus[4], ciostatus;
693 int i;
694
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530695 dsidev = (struct platform_device *) arg;
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530696 dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530697
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530698 spin_lock(&dsi->irq_lock);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200699
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530700 irqstatus = dsi_read_reg(dsidev, DSI_IRQSTATUS);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200701
702 /* IRQ is not for us */
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200703 if (!irqstatus) {
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530704 spin_unlock(&dsi->irq_lock);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200705 return IRQ_NONE;
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200706 }
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200707
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530708 dsi_write_reg(dsidev, DSI_IRQSTATUS, irqstatus & ~DSI_IRQ_CHANNEL_MASK);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200709 /* flush posted write */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530710 dsi_read_reg(dsidev, DSI_IRQSTATUS);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200711
712 for (i = 0; i < 4; ++i) {
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200713 if ((irqstatus & (1 << i)) == 0) {
714 vcstatus[i] = 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200715 continue;
Tomi Valkeinenab83b142010-06-09 15:31:01 +0300716 }
717
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530718 vcstatus[i] = dsi_read_reg(dsidev, DSI_VC_IRQSTATUS(i));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200719
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530720 dsi_write_reg(dsidev, DSI_VC_IRQSTATUS(i), vcstatus[i]);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200721 /* flush posted write */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530722 dsi_read_reg(dsidev, DSI_VC_IRQSTATUS(i));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200723 }
724
725 if (irqstatus & DSI_IRQ_COMPLEXIO_ERR) {
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530726 ciostatus = dsi_read_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200727
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530728 dsi_write_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS, ciostatus);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200729 /* flush posted write */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530730 dsi_read_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200731 } else {
732 ciostatus = 0;
733 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200734
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200735#ifdef DSI_CATCH_MISSING_TE
736 if (irqstatus & DSI_IRQ_TE_TRIGGER)
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530737 del_timer(&dsi->te_timer);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200738#endif
739
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200740 /* make a copy and unlock, so that isrs can unregister
741 * themselves */
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530742 memcpy(&dsi->isr_tables_copy, &dsi->isr_tables,
743 sizeof(dsi->isr_tables));
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200744
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530745 spin_unlock(&dsi->irq_lock);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200746
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530747 dsi_handle_isrs(&dsi->isr_tables_copy, irqstatus, vcstatus, ciostatus);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200748
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530749 dsi_handle_irq_errors(dsidev, irqstatus, vcstatus, ciostatus);
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200750
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530751 dsi_collect_irq_stats(dsidev, irqstatus, vcstatus, ciostatus);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200752
archit tanejaaffe3602011-02-23 08:41:03 +0000753 return IRQ_HANDLED;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200754}
755
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530756/* dsi->irq_lock has to be locked by the caller */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530757static void _omap_dsi_configure_irqs(struct platform_device *dsidev,
758 struct dsi_isr_data *isr_array,
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200759 unsigned isr_array_size, u32 default_mask,
760 const struct dsi_reg enable_reg,
761 const struct dsi_reg status_reg)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200762{
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200763 struct dsi_isr_data *isr_data;
764 u32 mask;
765 u32 old_mask;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200766 int i;
767
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200768 mask = default_mask;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200769
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200770 for (i = 0; i < isr_array_size; i++) {
771 isr_data = &isr_array[i];
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200772
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200773 if (isr_data->isr == NULL)
774 continue;
775
776 mask |= isr_data->mask;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200777 }
778
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530779 old_mask = dsi_read_reg(dsidev, enable_reg);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200780 /* clear the irqstatus for newly enabled irqs */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530781 dsi_write_reg(dsidev, status_reg, (mask ^ old_mask) & mask);
782 dsi_write_reg(dsidev, enable_reg, mask);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200783
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200784 /* flush posted writes */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530785 dsi_read_reg(dsidev, enable_reg);
786 dsi_read_reg(dsidev, status_reg);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200787}
788
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530789/* dsi->irq_lock has to be locked by the caller */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530790static void _omap_dsi_set_irqs(struct platform_device *dsidev)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200791{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530792 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200793 u32 mask = DSI_IRQ_ERROR_MASK;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200794#ifdef DSI_CATCH_MISSING_TE
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200795 mask |= DSI_IRQ_TE_TRIGGER;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200796#endif
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530797 _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table,
798 ARRAY_SIZE(dsi->isr_tables.isr_table), mask,
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200799 DSI_IRQENABLE, DSI_IRQSTATUS);
800}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200801
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530802/* dsi->irq_lock has to be locked by the caller */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530803static void _omap_dsi_set_irqs_vc(struct platform_device *dsidev, int vc)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200804{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530805 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
806
807 _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table_vc[vc],
808 ARRAY_SIZE(dsi->isr_tables.isr_table_vc[vc]),
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200809 DSI_VC_IRQ_ERROR_MASK,
810 DSI_VC_IRQENABLE(vc), DSI_VC_IRQSTATUS(vc));
811}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200812
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530813/* dsi->irq_lock has to be locked by the caller */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530814static void _omap_dsi_set_irqs_cio(struct platform_device *dsidev)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200815{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530816 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
817
818 _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table_cio,
819 ARRAY_SIZE(dsi->isr_tables.isr_table_cio),
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200820 DSI_CIO_IRQ_ERROR_MASK,
821 DSI_COMPLEXIO_IRQ_ENABLE, DSI_COMPLEXIO_IRQ_STATUS);
822}
823
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530824static void _dsi_initialize_irq(struct platform_device *dsidev)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200825{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530826 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200827 unsigned long flags;
828 int vc;
829
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530830 spin_lock_irqsave(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200831
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530832 memset(&dsi->isr_tables, 0, sizeof(dsi->isr_tables));
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200833
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530834 _omap_dsi_set_irqs(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200835 for (vc = 0; vc < 4; ++vc)
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530836 _omap_dsi_set_irqs_vc(dsidev, vc);
837 _omap_dsi_set_irqs_cio(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200838
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530839 spin_unlock_irqrestore(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200840}
841
842static int _dsi_register_isr(omap_dsi_isr_t isr, void *arg, u32 mask,
843 struct dsi_isr_data *isr_array, unsigned isr_array_size)
844{
845 struct dsi_isr_data *isr_data;
846 int free_idx;
847 int i;
848
849 BUG_ON(isr == NULL);
850
851 /* check for duplicate entry and find a free slot */
852 free_idx = -1;
853 for (i = 0; i < isr_array_size; i++) {
854 isr_data = &isr_array[i];
855
856 if (isr_data->isr == isr && isr_data->arg == arg &&
857 isr_data->mask == mask) {
858 return -EINVAL;
859 }
860
861 if (isr_data->isr == NULL && free_idx == -1)
862 free_idx = i;
863 }
864
865 if (free_idx == -1)
866 return -EBUSY;
867
868 isr_data = &isr_array[free_idx];
869 isr_data->isr = isr;
870 isr_data->arg = arg;
871 isr_data->mask = mask;
872
873 return 0;
874}
875
876static int _dsi_unregister_isr(omap_dsi_isr_t isr, void *arg, u32 mask,
877 struct dsi_isr_data *isr_array, unsigned isr_array_size)
878{
879 struct dsi_isr_data *isr_data;
880 int i;
881
882 for (i = 0; i < isr_array_size; i++) {
883 isr_data = &isr_array[i];
884 if (isr_data->isr != isr || isr_data->arg != arg ||
885 isr_data->mask != mask)
886 continue;
887
888 isr_data->isr = NULL;
889 isr_data->arg = NULL;
890 isr_data->mask = 0;
891
892 return 0;
893 }
894
895 return -EINVAL;
896}
897
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530898static int dsi_register_isr(struct platform_device *dsidev, omap_dsi_isr_t isr,
899 void *arg, u32 mask)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200900{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530901 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200902 unsigned long flags;
903 int r;
904
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530905 spin_lock_irqsave(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200906
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530907 r = _dsi_register_isr(isr, arg, mask, dsi->isr_tables.isr_table,
908 ARRAY_SIZE(dsi->isr_tables.isr_table));
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200909
910 if (r == 0)
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530911 _omap_dsi_set_irqs(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200912
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530913 spin_unlock_irqrestore(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200914
915 return r;
916}
917
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530918static int dsi_unregister_isr(struct platform_device *dsidev,
919 omap_dsi_isr_t isr, void *arg, u32 mask)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200920{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530921 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200922 unsigned long flags;
923 int r;
924
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530925 spin_lock_irqsave(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200926
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530927 r = _dsi_unregister_isr(isr, arg, mask, dsi->isr_tables.isr_table,
928 ARRAY_SIZE(dsi->isr_tables.isr_table));
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200929
930 if (r == 0)
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530931 _omap_dsi_set_irqs(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200932
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530933 spin_unlock_irqrestore(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200934
935 return r;
936}
937
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530938static int dsi_register_isr_vc(struct platform_device *dsidev, int channel,
939 omap_dsi_isr_t isr, void *arg, u32 mask)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200940{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530941 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200942 unsigned long flags;
943 int r;
944
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530945 spin_lock_irqsave(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200946
947 r = _dsi_register_isr(isr, arg, mask,
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530948 dsi->isr_tables.isr_table_vc[channel],
949 ARRAY_SIZE(dsi->isr_tables.isr_table_vc[channel]));
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200950
951 if (r == 0)
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530952 _omap_dsi_set_irqs_vc(dsidev, channel);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200953
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530954 spin_unlock_irqrestore(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200955
956 return r;
957}
958
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530959static int dsi_unregister_isr_vc(struct platform_device *dsidev, int channel,
960 omap_dsi_isr_t isr, void *arg, u32 mask)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200961{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530962 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200963 unsigned long flags;
964 int r;
965
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530966 spin_lock_irqsave(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200967
968 r = _dsi_unregister_isr(isr, arg, mask,
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530969 dsi->isr_tables.isr_table_vc[channel],
970 ARRAY_SIZE(dsi->isr_tables.isr_table_vc[channel]));
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200971
972 if (r == 0)
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530973 _omap_dsi_set_irqs_vc(dsidev, channel);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200974
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530975 spin_unlock_irqrestore(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200976
977 return r;
978}
979
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530980static int dsi_register_isr_cio(struct platform_device *dsidev,
981 omap_dsi_isr_t isr, void *arg, u32 mask)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200982{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530983 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200984 unsigned long flags;
985 int r;
986
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530987 spin_lock_irqsave(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200988
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530989 r = _dsi_register_isr(isr, arg, mask, dsi->isr_tables.isr_table_cio,
990 ARRAY_SIZE(dsi->isr_tables.isr_table_cio));
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200991
992 if (r == 0)
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530993 _omap_dsi_set_irqs_cio(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200994
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530995 spin_unlock_irqrestore(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200996
997 return r;
998}
999
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301000static int dsi_unregister_isr_cio(struct platform_device *dsidev,
1001 omap_dsi_isr_t isr, void *arg, u32 mask)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001002{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301003 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001004 unsigned long flags;
1005 int r;
1006
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301007 spin_lock_irqsave(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001008
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301009 r = _dsi_unregister_isr(isr, arg, mask, dsi->isr_tables.isr_table_cio,
1010 ARRAY_SIZE(dsi->isr_tables.isr_table_cio));
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001011
1012 if (r == 0)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301013 _omap_dsi_set_irqs_cio(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001014
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301015 spin_unlock_irqrestore(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001016
1017 return r;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001018}
1019
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301020static u32 dsi_get_errors(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001021{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301022 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001023 unsigned long flags;
1024 u32 e;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301025 spin_lock_irqsave(&dsi->errors_lock, flags);
1026 e = dsi->errors;
1027 dsi->errors = 0;
1028 spin_unlock_irqrestore(&dsi->errors_lock, flags);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001029 return e;
1030}
1031
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001032int dsi_runtime_get(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001033{
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001034 int r;
1035 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1036
1037 DSSDBG("dsi_runtime_get\n");
1038
1039 r = pm_runtime_get_sync(&dsi->pdev->dev);
1040 WARN_ON(r < 0);
1041 return r < 0 ? r : 0;
1042}
1043
1044void dsi_runtime_put(struct platform_device *dsidev)
1045{
1046 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1047 int r;
1048
1049 DSSDBG("dsi_runtime_put\n");
1050
1051 r = pm_runtime_put(&dsi->pdev->dev);
1052 WARN_ON(r < 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001053}
1054
1055/* source clock for DSI PLL. this could also be PCLKFREE */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301056static inline void dsi_enable_pll_clock(struct platform_device *dsidev,
1057 bool enable)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001058{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301059 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1060
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001061 if (enable)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001062 clk_enable(dsi->sys_clk);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001063 else
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001064 clk_disable(dsi->sys_clk);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001065
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301066 if (enable && dsi->pll_locked) {
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301067 if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 1, 1) != 1)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001068 DSSERR("cannot lock PLL when enabling clocks\n");
1069 }
1070}
1071
1072#ifdef DEBUG
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301073static void _dsi_print_reset_status(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001074{
1075 u32 l;
Tomi Valkeinenc335cbf2010-10-07 13:27:42 +03001076 int b0, b1, b2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001077
1078 if (!dss_debug)
1079 return;
1080
1081 /* A dummy read using the SCP interface to any DSIPHY register is
1082 * required after DSIPHY reset to complete the reset of the DSI complex
1083 * I/O. */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301084 l = dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001085
1086 printk(KERN_DEBUG "DSI resets: ");
1087
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301088 l = dsi_read_reg(dsidev, DSI_PLL_STATUS);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001089 printk("PLL (%d) ", FLD_GET(l, 0, 0));
1090
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301091 l = dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001092 printk("CIO (%d) ", FLD_GET(l, 29, 29));
1093
Tomi Valkeinenc335cbf2010-10-07 13:27:42 +03001094 if (dss_has_feature(FEAT_DSI_REVERSE_TXCLKESC)) {
1095 b0 = 28;
1096 b1 = 27;
1097 b2 = 26;
1098 } else {
1099 b0 = 24;
1100 b1 = 25;
1101 b2 = 26;
1102 }
1103
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301104 l = dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
Tomi Valkeinenc335cbf2010-10-07 13:27:42 +03001105 printk("PHY (%x%x%x, %d, %d, %d)\n",
1106 FLD_GET(l, b0, b0),
1107 FLD_GET(l, b1, b1),
1108 FLD_GET(l, b2, b2),
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001109 FLD_GET(l, 29, 29),
1110 FLD_GET(l, 30, 30),
1111 FLD_GET(l, 31, 31));
1112}
1113#else
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301114#define _dsi_print_reset_status(x)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001115#endif
1116
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301117static inline int dsi_if_enable(struct platform_device *dsidev, bool enable)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001118{
1119 DSSDBG("dsi_if_enable(%d)\n", enable);
1120
1121 enable = enable ? 1 : 0;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301122 REG_FLD_MOD(dsidev, DSI_CTRL, enable, 0, 0); /* IF_EN */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001123
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301124 if (wait_for_bit_change(dsidev, DSI_CTRL, 0, enable) != enable) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001125 DSSERR("Failed to set dsi_if_enable to %d\n", enable);
1126 return -EIO;
1127 }
1128
1129 return 0;
1130}
1131
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301132unsigned long dsi_get_pll_hsdiv_dispc_rate(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001133{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301134 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1135
1136 return dsi->current_cinfo.dsi_pll_hsdiv_dispc_clk;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001137}
1138
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301139static unsigned long dsi_get_pll_hsdiv_dsi_rate(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001140{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301141 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1142
1143 return dsi->current_cinfo.dsi_pll_hsdiv_dsi_clk;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001144}
1145
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301146static unsigned long dsi_get_txbyteclkhs(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001147{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301148 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1149
1150 return dsi->current_cinfo.clkin4ddr / 16;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001151}
1152
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301153static unsigned long dsi_fclk_rate(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001154{
1155 unsigned long r;
Archit Taneja5a8b5722011-05-12 17:26:29 +05301156 int dsi_module = dsi_get_dsidev_id(dsidev);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001157 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001158
Archit Taneja5a8b5722011-05-12 17:26:29 +05301159 if (dss_get_dsi_clk_source(dsi_module) == OMAP_DSS_CLK_SRC_FCK) {
Archit Taneja1bb47832011-02-24 14:17:30 +05301160 /* DSI FCLK source is DSS_CLK_FCK */
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001161 r = clk_get_rate(dsi->dss_clk);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001162 } else {
Archit Taneja1bb47832011-02-24 14:17:30 +05301163 /* DSI FCLK source is dsi_pll_hsdiv_dsi_clk */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301164 r = dsi_get_pll_hsdiv_dsi_rate(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001165 }
1166
1167 return r;
1168}
1169
1170static int dsi_set_lp_clk_divisor(struct omap_dss_device *dssdev)
1171{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301172 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301173 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001174 unsigned long dsi_fclk;
1175 unsigned lp_clk_div;
1176 unsigned long lp_clk;
1177
Tomi Valkeinenc6940a32011-02-22 13:36:10 +02001178 lp_clk_div = dssdev->clocks.dsi.lp_clk_div;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001179
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301180 if (lp_clk_div == 0 || lp_clk_div > dsi->lpdiv_max)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001181 return -EINVAL;
1182
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301183 dsi_fclk = dsi_fclk_rate(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001184
1185 lp_clk = dsi_fclk / 2 / lp_clk_div;
1186
1187 DSSDBG("LP_CLK_DIV %u, LP_CLK %lu\n", lp_clk_div, lp_clk);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301188 dsi->current_cinfo.lp_clk = lp_clk;
1189 dsi->current_cinfo.lp_clk_div = lp_clk_div;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001190
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301191 /* LP_CLK_DIVISOR */
1192 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, lp_clk_div, 12, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001193
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301194 /* LP_RX_SYNCHRO_ENABLE */
1195 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, dsi_fclk > 30000000 ? 1 : 0, 21, 21);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001196
1197 return 0;
1198}
1199
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301200static void dsi_enable_scp_clk(struct platform_device *dsidev)
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +03001201{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301202 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1203
1204 if (dsi->scp_clk_refcount++ == 0)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301205 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 1, 14, 14); /* CIO_CLK_ICG */
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +03001206}
1207
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301208static void dsi_disable_scp_clk(struct platform_device *dsidev)
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +03001209{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301210 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1211
1212 WARN_ON(dsi->scp_clk_refcount == 0);
1213 if (--dsi->scp_clk_refcount == 0)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301214 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 14, 14); /* CIO_CLK_ICG */
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +03001215}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001216
1217enum dsi_pll_power_state {
1218 DSI_PLL_POWER_OFF = 0x0,
1219 DSI_PLL_POWER_ON_HSCLK = 0x1,
1220 DSI_PLL_POWER_ON_ALL = 0x2,
1221 DSI_PLL_POWER_ON_DIV = 0x3,
1222};
1223
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301224static int dsi_pll_power(struct platform_device *dsidev,
1225 enum dsi_pll_power_state state)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001226{
1227 int t = 0;
1228
Tomi Valkeinenc94dfe052011-04-15 10:42:59 +03001229 /* DSI-PLL power command 0x3 is not working */
1230 if (dss_has_feature(FEAT_DSI_PLL_PWR_BUG) &&
1231 state == DSI_PLL_POWER_ON_DIV)
1232 state = DSI_PLL_POWER_ON_ALL;
1233
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301234 /* PLL_PWR_CMD */
1235 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, state, 31, 30);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001236
1237 /* PLL_PWR_STATUS */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301238 while (FLD_GET(dsi_read_reg(dsidev, DSI_CLK_CTRL), 29, 28) != state) {
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02001239 if (++t > 1000) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001240 DSSERR("Failed to set DSI PLL power mode to %d\n",
1241 state);
1242 return -ENODEV;
1243 }
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02001244 udelay(1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001245 }
1246
1247 return 0;
1248}
1249
1250/* calculate clock rates using dividers in cinfo */
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00001251static int dsi_calc_clock_rates(struct omap_dss_device *dssdev,
1252 struct dsi_clock_info *cinfo)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001253{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301254 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
1255 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1256
1257 if (cinfo->regn == 0 || cinfo->regn > dsi->regn_max)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001258 return -EINVAL;
1259
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301260 if (cinfo->regm == 0 || cinfo->regm > dsi->regm_max)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001261 return -EINVAL;
1262
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301263 if (cinfo->regm_dispc > dsi->regm_dispc_max)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001264 return -EINVAL;
1265
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301266 if (cinfo->regm_dsi > dsi->regm_dsi_max)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001267 return -EINVAL;
1268
Archit Taneja1bb47832011-02-24 14:17:30 +05301269 if (cinfo->use_sys_clk) {
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001270 cinfo->clkin = clk_get_rate(dsi->sys_clk);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001271 /* XXX it is unclear if highfreq should be used
Archit Taneja1bb47832011-02-24 14:17:30 +05301272 * with DSS_SYS_CLK source also */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001273 cinfo->highfreq = 0;
1274 } else {
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03001275 cinfo->clkin = dispc_mgr_pclk_rate(dssdev->manager->id);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001276
1277 if (cinfo->clkin < 32000000)
1278 cinfo->highfreq = 0;
1279 else
1280 cinfo->highfreq = 1;
1281 }
1282
1283 cinfo->fint = cinfo->clkin / (cinfo->regn * (cinfo->highfreq ? 2 : 1));
1284
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301285 if (cinfo->fint > dsi->fint_max || cinfo->fint < dsi->fint_min)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001286 return -EINVAL;
1287
1288 cinfo->clkin4ddr = 2 * cinfo->regm * cinfo->fint;
1289
1290 if (cinfo->clkin4ddr > 1800 * 1000 * 1000)
1291 return -EINVAL;
1292
Archit Taneja1bb47832011-02-24 14:17:30 +05301293 if (cinfo->regm_dispc > 0)
1294 cinfo->dsi_pll_hsdiv_dispc_clk =
1295 cinfo->clkin4ddr / cinfo->regm_dispc;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001296 else
Archit Taneja1bb47832011-02-24 14:17:30 +05301297 cinfo->dsi_pll_hsdiv_dispc_clk = 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001298
Archit Taneja1bb47832011-02-24 14:17:30 +05301299 if (cinfo->regm_dsi > 0)
1300 cinfo->dsi_pll_hsdiv_dsi_clk =
1301 cinfo->clkin4ddr / cinfo->regm_dsi;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001302 else
Archit Taneja1bb47832011-02-24 14:17:30 +05301303 cinfo->dsi_pll_hsdiv_dsi_clk = 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001304
1305 return 0;
1306}
1307
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301308int dsi_pll_calc_clock_div_pck(struct platform_device *dsidev, bool is_tft,
1309 unsigned long req_pck, struct dsi_clock_info *dsi_cinfo,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001310 struct dispc_clock_info *dispc_cinfo)
1311{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301312 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001313 struct dsi_clock_info cur, best;
1314 struct dispc_clock_info best_dispc;
1315 int min_fck_per_pck;
1316 int match = 0;
Archit Taneja1bb47832011-02-24 14:17:30 +05301317 unsigned long dss_sys_clk, max_dss_fck;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001318
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001319 dss_sys_clk = clk_get_rate(dsi->sys_clk);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001320
Taneja, Archit31ef8232011-03-14 23:28:22 -05001321 max_dss_fck = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK);
Archit Taneja819d8072011-03-01 11:54:00 +05301322
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301323 if (req_pck == dsi->cache_req_pck &&
1324 dsi->cache_cinfo.clkin == dss_sys_clk) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001325 DSSDBG("DSI clock info found from cache\n");
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301326 *dsi_cinfo = dsi->cache_cinfo;
Archit Taneja1bb47832011-02-24 14:17:30 +05301327 dispc_find_clk_divs(is_tft, req_pck,
1328 dsi_cinfo->dsi_pll_hsdiv_dispc_clk, dispc_cinfo);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001329 return 0;
1330 }
1331
1332 min_fck_per_pck = CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK;
1333
1334 if (min_fck_per_pck &&
Archit Taneja819d8072011-03-01 11:54:00 +05301335 req_pck * min_fck_per_pck > max_dss_fck) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001336 DSSERR("Requested pixel clock not possible with the current "
1337 "OMAP2_DSS_MIN_FCK_PER_PCK setting. Turning "
1338 "the constraint off.\n");
1339 min_fck_per_pck = 0;
1340 }
1341
1342 DSSDBG("dsi_pll_calc\n");
1343
1344retry:
1345 memset(&best, 0, sizeof(best));
1346 memset(&best_dispc, 0, sizeof(best_dispc));
1347
1348 memset(&cur, 0, sizeof(cur));
Archit Taneja1bb47832011-02-24 14:17:30 +05301349 cur.clkin = dss_sys_clk;
1350 cur.use_sys_clk = 1;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001351 cur.highfreq = 0;
1352
1353 /* no highfreq: 0.75MHz < Fint = clkin / regn < 2.1MHz */
1354 /* highfreq: 0.75MHz < Fint = clkin / (2*regn) < 2.1MHz */
1355 /* To reduce PLL lock time, keep Fint high (around 2 MHz) */
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301356 for (cur.regn = 1; cur.regn < dsi->regn_max; ++cur.regn) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001357 if (cur.highfreq == 0)
1358 cur.fint = cur.clkin / cur.regn;
1359 else
1360 cur.fint = cur.clkin / (2 * cur.regn);
1361
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301362 if (cur.fint > dsi->fint_max || cur.fint < dsi->fint_min)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001363 continue;
1364
1365 /* DSIPHY(MHz) = (2 * regm / regn) * (clkin / (highfreq + 1)) */
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301366 for (cur.regm = 1; cur.regm < dsi->regm_max; ++cur.regm) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001367 unsigned long a, b;
1368
1369 a = 2 * cur.regm * (cur.clkin/1000);
1370 b = cur.regn * (cur.highfreq + 1);
1371 cur.clkin4ddr = a / b * 1000;
1372
1373 if (cur.clkin4ddr > 1800 * 1000 * 1000)
1374 break;
1375
Archit Taneja1bb47832011-02-24 14:17:30 +05301376 /* dsi_pll_hsdiv_dispc_clk(MHz) =
1377 * DSIPHY(MHz) / regm_dispc < 173MHz/186Mhz */
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301378 for (cur.regm_dispc = 1; cur.regm_dispc <
1379 dsi->regm_dispc_max; ++cur.regm_dispc) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001380 struct dispc_clock_info cur_dispc;
Archit Taneja1bb47832011-02-24 14:17:30 +05301381 cur.dsi_pll_hsdiv_dispc_clk =
1382 cur.clkin4ddr / cur.regm_dispc;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001383
1384 /* this will narrow down the search a bit,
1385 * but still give pixclocks below what was
1386 * requested */
Archit Taneja1bb47832011-02-24 14:17:30 +05301387 if (cur.dsi_pll_hsdiv_dispc_clk < req_pck)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001388 break;
1389
Archit Taneja1bb47832011-02-24 14:17:30 +05301390 if (cur.dsi_pll_hsdiv_dispc_clk > max_dss_fck)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001391 continue;
1392
1393 if (min_fck_per_pck &&
Archit Taneja1bb47832011-02-24 14:17:30 +05301394 cur.dsi_pll_hsdiv_dispc_clk <
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001395 req_pck * min_fck_per_pck)
1396 continue;
1397
1398 match = 1;
1399
1400 dispc_find_clk_divs(is_tft, req_pck,
Archit Taneja1bb47832011-02-24 14:17:30 +05301401 cur.dsi_pll_hsdiv_dispc_clk,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001402 &cur_dispc);
1403
1404 if (abs(cur_dispc.pck - req_pck) <
1405 abs(best_dispc.pck - req_pck)) {
1406 best = cur;
1407 best_dispc = cur_dispc;
1408
1409 if (cur_dispc.pck == req_pck)
1410 goto found;
1411 }
1412 }
1413 }
1414 }
1415found:
1416 if (!match) {
1417 if (min_fck_per_pck) {
1418 DSSERR("Could not find suitable clock settings.\n"
1419 "Turning FCK/PCK constraint off and"
1420 "trying again.\n");
1421 min_fck_per_pck = 0;
1422 goto retry;
1423 }
1424
1425 DSSERR("Could not find suitable clock settings.\n");
1426
1427 return -EINVAL;
1428 }
1429
Archit Taneja1bb47832011-02-24 14:17:30 +05301430 /* dsi_pll_hsdiv_dsi_clk (regm_dsi) is not used */
1431 best.regm_dsi = 0;
1432 best.dsi_pll_hsdiv_dsi_clk = 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001433
1434 if (dsi_cinfo)
1435 *dsi_cinfo = best;
1436 if (dispc_cinfo)
1437 *dispc_cinfo = best_dispc;
1438
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301439 dsi->cache_req_pck = req_pck;
1440 dsi->cache_clk_freq = 0;
1441 dsi->cache_cinfo = best;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001442
1443 return 0;
1444}
1445
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301446int dsi_pll_set_clock_div(struct platform_device *dsidev,
1447 struct dsi_clock_info *cinfo)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001448{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301449 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001450 int r = 0;
1451 u32 l;
Archit Taneja9613c022011-03-22 06:33:36 -05001452 int f = 0;
Taneja, Archit49641112011-03-14 23:28:23 -05001453 u8 regn_start, regn_end, regm_start, regm_end;
1454 u8 regm_dispc_start, regm_dispc_end, regm_dsi_start, regm_dsi_end;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001455
1456 DSSDBGF();
1457
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301458 dsi->current_cinfo.use_sys_clk = cinfo->use_sys_clk;
1459 dsi->current_cinfo.highfreq = cinfo->highfreq;
Tomi Valkeinenb2765092011-04-07 15:28:47 +03001460
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301461 dsi->current_cinfo.fint = cinfo->fint;
1462 dsi->current_cinfo.clkin4ddr = cinfo->clkin4ddr;
1463 dsi->current_cinfo.dsi_pll_hsdiv_dispc_clk =
Archit Taneja1bb47832011-02-24 14:17:30 +05301464 cinfo->dsi_pll_hsdiv_dispc_clk;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301465 dsi->current_cinfo.dsi_pll_hsdiv_dsi_clk =
Archit Taneja1bb47832011-02-24 14:17:30 +05301466 cinfo->dsi_pll_hsdiv_dsi_clk;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001467
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301468 dsi->current_cinfo.regn = cinfo->regn;
1469 dsi->current_cinfo.regm = cinfo->regm;
1470 dsi->current_cinfo.regm_dispc = cinfo->regm_dispc;
1471 dsi->current_cinfo.regm_dsi = cinfo->regm_dsi;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001472
1473 DSSDBG("DSI Fint %ld\n", cinfo->fint);
1474
1475 DSSDBG("clkin (%s) rate %ld, highfreq %d\n",
Archit Taneja1bb47832011-02-24 14:17:30 +05301476 cinfo->use_sys_clk ? "dss_sys_clk" : "pclkfree",
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001477 cinfo->clkin,
1478 cinfo->highfreq);
1479
1480 /* DSIPHY == CLKIN4DDR */
1481 DSSDBG("CLKIN4DDR = 2 * %d / %d * %lu / %d = %lu\n",
1482 cinfo->regm,
1483 cinfo->regn,
1484 cinfo->clkin,
1485 cinfo->highfreq + 1,
1486 cinfo->clkin4ddr);
1487
1488 DSSDBG("Data rate on 1 DSI lane %ld Mbps\n",
1489 cinfo->clkin4ddr / 1000 / 1000 / 2);
1490
1491 DSSDBG("Clock lane freq %ld Hz\n", cinfo->clkin4ddr / 4);
1492
Archit Taneja1bb47832011-02-24 14:17:30 +05301493 DSSDBG("regm_dispc = %d, %s (%s) = %lu\n", cinfo->regm_dispc,
Archit Taneja89a35e52011-04-12 13:52:23 +05301494 dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
1495 dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
Archit Taneja1bb47832011-02-24 14:17:30 +05301496 cinfo->dsi_pll_hsdiv_dispc_clk);
1497 DSSDBG("regm_dsi = %d, %s (%s) = %lu\n", cinfo->regm_dsi,
Archit Taneja89a35e52011-04-12 13:52:23 +05301498 dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
1499 dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
Archit Taneja1bb47832011-02-24 14:17:30 +05301500 cinfo->dsi_pll_hsdiv_dsi_clk);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001501
Taneja, Archit49641112011-03-14 23:28:23 -05001502 dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGN, &regn_start, &regn_end);
1503 dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM, &regm_start, &regm_end);
1504 dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM_DISPC, &regm_dispc_start,
1505 &regm_dispc_end);
1506 dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM_DSI, &regm_dsi_start,
1507 &regm_dsi_end);
1508
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301509 /* DSI_PLL_AUTOMODE = manual */
1510 REG_FLD_MOD(dsidev, DSI_PLL_CONTROL, 0, 0, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001511
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301512 l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001513 l = FLD_MOD(l, 1, 0, 0); /* DSI_PLL_STOPMODE */
Taneja, Archit49641112011-03-14 23:28:23 -05001514 /* DSI_PLL_REGN */
1515 l = FLD_MOD(l, cinfo->regn - 1, regn_start, regn_end);
1516 /* DSI_PLL_REGM */
1517 l = FLD_MOD(l, cinfo->regm, regm_start, regm_end);
1518 /* DSI_CLOCK_DIV */
Archit Taneja1bb47832011-02-24 14:17:30 +05301519 l = FLD_MOD(l, cinfo->regm_dispc > 0 ? cinfo->regm_dispc - 1 : 0,
Taneja, Archit49641112011-03-14 23:28:23 -05001520 regm_dispc_start, regm_dispc_end);
1521 /* DSIPROTO_CLOCK_DIV */
Archit Taneja1bb47832011-02-24 14:17:30 +05301522 l = FLD_MOD(l, cinfo->regm_dsi > 0 ? cinfo->regm_dsi - 1 : 0,
Taneja, Archit49641112011-03-14 23:28:23 -05001523 regm_dsi_start, regm_dsi_end);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301524 dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION1, l);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001525
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301526 BUG_ON(cinfo->fint < dsi->fint_min || cinfo->fint > dsi->fint_max);
Archit Taneja9613c022011-03-22 06:33:36 -05001527
1528 if (dss_has_feature(FEAT_DSI_PLL_FREQSEL)) {
1529 f = cinfo->fint < 1000000 ? 0x3 :
1530 cinfo->fint < 1250000 ? 0x4 :
1531 cinfo->fint < 1500000 ? 0x5 :
1532 cinfo->fint < 1750000 ? 0x6 :
1533 0x7;
1534 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001535
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301536 l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION2);
Archit Taneja9613c022011-03-22 06:33:36 -05001537
1538 if (dss_has_feature(FEAT_DSI_PLL_FREQSEL))
1539 l = FLD_MOD(l, f, 4, 1); /* DSI_PLL_FREQSEL */
Archit Taneja1bb47832011-02-24 14:17:30 +05301540 l = FLD_MOD(l, cinfo->use_sys_clk ? 0 : 1,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001541 11, 11); /* DSI_PLL_CLKSEL */
1542 l = FLD_MOD(l, cinfo->highfreq,
1543 12, 12); /* DSI_PLL_HIGHFREQ */
1544 l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */
1545 l = FLD_MOD(l, 0, 14, 14); /* DSIPHY_CLKINEN */
1546 l = FLD_MOD(l, 1, 20, 20); /* DSI_HSDIVBYPASS */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301547 dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION2, l);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001548
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301549 REG_FLD_MOD(dsidev, DSI_PLL_GO, 1, 0, 0); /* DSI_PLL_GO */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001550
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301551 if (wait_for_bit_change(dsidev, DSI_PLL_GO, 0, 0) != 0) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001552 DSSERR("dsi pll go bit not going down.\n");
1553 r = -EIO;
1554 goto err;
1555 }
1556
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301557 if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 1, 1) != 1) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001558 DSSERR("cannot lock PLL\n");
1559 r = -EIO;
1560 goto err;
1561 }
1562
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301563 dsi->pll_locked = 1;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001564
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301565 l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION2);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001566 l = FLD_MOD(l, 0, 0, 0); /* DSI_PLL_IDLE */
1567 l = FLD_MOD(l, 0, 5, 5); /* DSI_PLL_PLLLPMODE */
1568 l = FLD_MOD(l, 0, 6, 6); /* DSI_PLL_LOWCURRSTBY */
1569 l = FLD_MOD(l, 0, 7, 7); /* DSI_PLL_TIGHTPHASELOCK */
1570 l = FLD_MOD(l, 0, 8, 8); /* DSI_PLL_DRIFTGUARDEN */
1571 l = FLD_MOD(l, 0, 10, 9); /* DSI_PLL_LOCKSEL */
1572 l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */
1573 l = FLD_MOD(l, 1, 14, 14); /* DSIPHY_CLKINEN */
1574 l = FLD_MOD(l, 0, 15, 15); /* DSI_BYPASSEN */
1575 l = FLD_MOD(l, 1, 16, 16); /* DSS_CLOCK_EN */
1576 l = FLD_MOD(l, 0, 17, 17); /* DSS_CLOCK_PWDN */
1577 l = FLD_MOD(l, 1, 18, 18); /* DSI_PROTO_CLOCK_EN */
1578 l = FLD_MOD(l, 0, 19, 19); /* DSI_PROTO_CLOCK_PWDN */
1579 l = FLD_MOD(l, 0, 20, 20); /* DSI_HSDIVBYPASS */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301580 dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION2, l);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001581
1582 DSSDBG("PLL config done\n");
1583err:
1584 return r;
1585}
1586
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301587int dsi_pll_init(struct platform_device *dsidev, bool enable_hsclk,
1588 bool enable_hsdiv)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001589{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301590 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001591 int r = 0;
1592 enum dsi_pll_power_state pwstate;
1593
1594 DSSDBG("PLL init\n");
1595
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301596 if (dsi->vdds_dsi_reg == NULL) {
Tomi Valkeinenf2988ab2011-03-02 10:06:48 +02001597 struct regulator *vdds_dsi;
1598
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301599 vdds_dsi = regulator_get(&dsi->pdev->dev, "vdds_dsi");
Tomi Valkeinenf2988ab2011-03-02 10:06:48 +02001600
1601 if (IS_ERR(vdds_dsi)) {
1602 DSSERR("can't get VDDS_DSI regulator\n");
1603 return PTR_ERR(vdds_dsi);
1604 }
1605
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301606 dsi->vdds_dsi_reg = vdds_dsi;
Tomi Valkeinenf2988ab2011-03-02 10:06:48 +02001607 }
Tomi Valkeinenf2988ab2011-03-02 10:06:48 +02001608
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301609 dsi_enable_pll_clock(dsidev, 1);
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +03001610 /*
1611 * Note: SCP CLK is not required on OMAP3, but it is required on OMAP4.
1612 */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301613 dsi_enable_scp_clk(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001614
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301615 if (!dsi->vdds_dsi_enabled) {
1616 r = regulator_enable(dsi->vdds_dsi_reg);
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +03001617 if (r)
1618 goto err0;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301619 dsi->vdds_dsi_enabled = true;
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +03001620 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001621
1622 /* XXX PLL does not come out of reset without this... */
1623 dispc_pck_free_enable(1);
1624
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301625 if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 0, 1) != 1) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001626 DSSERR("PLL not coming out of reset.\n");
1627 r = -ENODEV;
Ville Syrjälä481dfa02010-04-22 22:50:04 +02001628 dispc_pck_free_enable(0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001629 goto err1;
1630 }
1631
1632 /* XXX ... but if left on, we get problems when planes do not
1633 * fill the whole display. No idea about this */
1634 dispc_pck_free_enable(0);
1635
1636 if (enable_hsclk && enable_hsdiv)
1637 pwstate = DSI_PLL_POWER_ON_ALL;
1638 else if (enable_hsclk)
1639 pwstate = DSI_PLL_POWER_ON_HSCLK;
1640 else if (enable_hsdiv)
1641 pwstate = DSI_PLL_POWER_ON_DIV;
1642 else
1643 pwstate = DSI_PLL_POWER_OFF;
1644
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301645 r = dsi_pll_power(dsidev, pwstate);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001646
1647 if (r)
1648 goto err1;
1649
1650 DSSDBG("PLL init done\n");
1651
1652 return 0;
1653err1:
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301654 if (dsi->vdds_dsi_enabled) {
1655 regulator_disable(dsi->vdds_dsi_reg);
1656 dsi->vdds_dsi_enabled = false;
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +03001657 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001658err0:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301659 dsi_disable_scp_clk(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301660 dsi_enable_pll_clock(dsidev, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001661 return r;
1662}
1663
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301664void dsi_pll_uninit(struct platform_device *dsidev, bool disconnect_lanes)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001665{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301666 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1667
1668 dsi->pll_locked = 0;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301669 dsi_pll_power(dsidev, DSI_PLL_POWER_OFF);
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +03001670 if (disconnect_lanes) {
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301671 WARN_ON(!dsi->vdds_dsi_enabled);
1672 regulator_disable(dsi->vdds_dsi_reg);
1673 dsi->vdds_dsi_enabled = false;
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +03001674 }
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +03001675
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301676 dsi_disable_scp_clk(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301677 dsi_enable_pll_clock(dsidev, 0);
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +03001678
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001679 DSSDBG("PLL uninit done\n");
1680}
1681
Archit Taneja5a8b5722011-05-12 17:26:29 +05301682static void dsi_dump_dsidev_clocks(struct platform_device *dsidev,
1683 struct seq_file *s)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001684{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301685 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1686 struct dsi_clock_info *cinfo = &dsi->current_cinfo;
Archit Taneja89a35e52011-04-12 13:52:23 +05301687 enum omap_dss_clk_source dispc_clk_src, dsi_clk_src;
Archit Taneja5a8b5722011-05-12 17:26:29 +05301688 int dsi_module = dsi_get_dsidev_id(dsidev);
Archit Taneja067a57e2011-03-02 11:57:25 +05301689
1690 dispc_clk_src = dss_get_dispc_clk_source();
Archit Taneja5a8b5722011-05-12 17:26:29 +05301691 dsi_clk_src = dss_get_dsi_clk_source(dsi_module);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001692
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001693 if (dsi_runtime_get(dsidev))
1694 return;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001695
Archit Taneja5a8b5722011-05-12 17:26:29 +05301696 seq_printf(s, "- DSI%d PLL -\n", dsi_module + 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001697
1698 seq_printf(s, "dsi pll source = %s\n",
Tomi Valkeinena9a65002011-04-04 10:02:53 +03001699 cinfo->use_sys_clk ? "dss_sys_clk" : "pclkfree");
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001700
1701 seq_printf(s, "Fint\t\t%-16luregn %u\n", cinfo->fint, cinfo->regn);
1702
1703 seq_printf(s, "CLKIN4DDR\t%-16luregm %u\n",
1704 cinfo->clkin4ddr, cinfo->regm);
1705
Archit Taneja1bb47832011-02-24 14:17:30 +05301706 seq_printf(s, "%s (%s)\t%-16luregm_dispc %u\t(%s)\n",
Archit Taneja067a57e2011-03-02 11:57:25 +05301707 dss_get_generic_clk_source_name(dispc_clk_src),
1708 dss_feat_get_clk_source_name(dispc_clk_src),
Archit Taneja1bb47832011-02-24 14:17:30 +05301709 cinfo->dsi_pll_hsdiv_dispc_clk,
1710 cinfo->regm_dispc,
Archit Taneja89a35e52011-04-12 13:52:23 +05301711 dispc_clk_src == OMAP_DSS_CLK_SRC_FCK ?
Tomi Valkeinen63cf28a2010-02-23 17:40:00 +02001712 "off" : "on");
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001713
Archit Taneja1bb47832011-02-24 14:17:30 +05301714 seq_printf(s, "%s (%s)\t%-16luregm_dsi %u\t(%s)\n",
Archit Taneja067a57e2011-03-02 11:57:25 +05301715 dss_get_generic_clk_source_name(dsi_clk_src),
1716 dss_feat_get_clk_source_name(dsi_clk_src),
Archit Taneja1bb47832011-02-24 14:17:30 +05301717 cinfo->dsi_pll_hsdiv_dsi_clk,
1718 cinfo->regm_dsi,
Archit Taneja89a35e52011-04-12 13:52:23 +05301719 dsi_clk_src == OMAP_DSS_CLK_SRC_FCK ?
Tomi Valkeinen63cf28a2010-02-23 17:40:00 +02001720 "off" : "on");
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001721
Archit Taneja5a8b5722011-05-12 17:26:29 +05301722 seq_printf(s, "- DSI%d -\n", dsi_module + 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001723
Archit Taneja067a57e2011-03-02 11:57:25 +05301724 seq_printf(s, "dsi fclk source = %s (%s)\n",
1725 dss_get_generic_clk_source_name(dsi_clk_src),
1726 dss_feat_get_clk_source_name(dsi_clk_src));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001727
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301728 seq_printf(s, "DSI_FCLK\t%lu\n", dsi_fclk_rate(dsidev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001729
1730 seq_printf(s, "DDR_CLK\t\t%lu\n",
1731 cinfo->clkin4ddr / 4);
1732
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301733 seq_printf(s, "TxByteClkHS\t%lu\n", dsi_get_txbyteclkhs(dsidev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001734
1735 seq_printf(s, "LP_CLK\t\t%lu\n", cinfo->lp_clk);
1736
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001737 dsi_runtime_put(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001738}
1739
Archit Taneja5a8b5722011-05-12 17:26:29 +05301740void dsi_dump_clocks(struct seq_file *s)
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001741{
Archit Taneja5a8b5722011-05-12 17:26:29 +05301742 struct platform_device *dsidev;
1743 int i;
1744
1745 for (i = 0; i < MAX_NUM_DSI; i++) {
1746 dsidev = dsi_get_dsidev_from_id(i);
1747 if (dsidev)
1748 dsi_dump_dsidev_clocks(dsidev, s);
1749 }
1750}
1751
1752#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
1753static void dsi_dump_dsidev_irqs(struct platform_device *dsidev,
1754 struct seq_file *s)
1755{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301756 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001757 unsigned long flags;
1758 struct dsi_irq_stats stats;
Archit Taneja5a8b5722011-05-12 17:26:29 +05301759 int dsi_module = dsi_get_dsidev_id(dsidev);
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001760
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301761 spin_lock_irqsave(&dsi->irq_stats_lock, flags);
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001762
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301763 stats = dsi->irq_stats;
1764 memset(&dsi->irq_stats, 0, sizeof(dsi->irq_stats));
1765 dsi->irq_stats.last_reset = jiffies;
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001766
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301767 spin_unlock_irqrestore(&dsi->irq_stats_lock, flags);
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001768
1769 seq_printf(s, "period %u ms\n",
1770 jiffies_to_msecs(jiffies - stats.last_reset));
1771
1772 seq_printf(s, "irqs %d\n", stats.irq_count);
1773#define PIS(x) \
1774 seq_printf(s, "%-20s %10d\n", #x, stats.dsi_irqs[ffs(DSI_IRQ_##x)-1]);
1775
Archit Taneja5a8b5722011-05-12 17:26:29 +05301776 seq_printf(s, "-- DSI%d interrupts --\n", dsi_module + 1);
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001777 PIS(VC0);
1778 PIS(VC1);
1779 PIS(VC2);
1780 PIS(VC3);
1781 PIS(WAKEUP);
1782 PIS(RESYNC);
1783 PIS(PLL_LOCK);
1784 PIS(PLL_UNLOCK);
1785 PIS(PLL_RECALL);
1786 PIS(COMPLEXIO_ERR);
1787 PIS(HS_TX_TIMEOUT);
1788 PIS(LP_RX_TIMEOUT);
1789 PIS(TE_TRIGGER);
1790 PIS(ACK_TRIGGER);
1791 PIS(SYNC_LOST);
1792 PIS(LDO_POWER_GOOD);
1793 PIS(TA_TIMEOUT);
1794#undef PIS
1795
1796#define PIS(x) \
1797 seq_printf(s, "%-20s %10d %10d %10d %10d\n", #x, \
1798 stats.vc_irqs[0][ffs(DSI_VC_IRQ_##x)-1], \
1799 stats.vc_irqs[1][ffs(DSI_VC_IRQ_##x)-1], \
1800 stats.vc_irqs[2][ffs(DSI_VC_IRQ_##x)-1], \
1801 stats.vc_irqs[3][ffs(DSI_VC_IRQ_##x)-1]);
1802
1803 seq_printf(s, "-- VC interrupts --\n");
1804 PIS(CS);
1805 PIS(ECC_CORR);
1806 PIS(PACKET_SENT);
1807 PIS(FIFO_TX_OVF);
1808 PIS(FIFO_RX_OVF);
1809 PIS(BTA);
1810 PIS(ECC_NO_CORR);
1811 PIS(FIFO_TX_UDF);
1812 PIS(PP_BUSY_CHANGE);
1813#undef PIS
1814
1815#define PIS(x) \
1816 seq_printf(s, "%-20s %10d\n", #x, \
1817 stats.cio_irqs[ffs(DSI_CIO_IRQ_##x)-1]);
1818
1819 seq_printf(s, "-- CIO interrupts --\n");
1820 PIS(ERRSYNCESC1);
1821 PIS(ERRSYNCESC2);
1822 PIS(ERRSYNCESC3);
1823 PIS(ERRESC1);
1824 PIS(ERRESC2);
1825 PIS(ERRESC3);
1826 PIS(ERRCONTROL1);
1827 PIS(ERRCONTROL2);
1828 PIS(ERRCONTROL3);
1829 PIS(STATEULPS1);
1830 PIS(STATEULPS2);
1831 PIS(STATEULPS3);
1832 PIS(ERRCONTENTIONLP0_1);
1833 PIS(ERRCONTENTIONLP1_1);
1834 PIS(ERRCONTENTIONLP0_2);
1835 PIS(ERRCONTENTIONLP1_2);
1836 PIS(ERRCONTENTIONLP0_3);
1837 PIS(ERRCONTENTIONLP1_3);
1838 PIS(ULPSACTIVENOT_ALL0);
1839 PIS(ULPSACTIVENOT_ALL1);
1840#undef PIS
1841}
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001842
Archit Taneja5a8b5722011-05-12 17:26:29 +05301843static void dsi1_dump_irqs(struct seq_file *s)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001844{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301845 struct platform_device *dsidev = dsi_get_dsidev_from_id(0);
1846
Archit Taneja5a8b5722011-05-12 17:26:29 +05301847 dsi_dump_dsidev_irqs(dsidev, s);
1848}
1849
1850static void dsi2_dump_irqs(struct seq_file *s)
1851{
1852 struct platform_device *dsidev = dsi_get_dsidev_from_id(1);
1853
1854 dsi_dump_dsidev_irqs(dsidev, s);
1855}
1856
1857void dsi_create_debugfs_files_irq(struct dentry *debugfs_dir,
1858 const struct file_operations *debug_fops)
1859{
1860 struct platform_device *dsidev;
1861
1862 dsidev = dsi_get_dsidev_from_id(0);
1863 if (dsidev)
1864 debugfs_create_file("dsi1_irqs", S_IRUGO, debugfs_dir,
1865 &dsi1_dump_irqs, debug_fops);
1866
1867 dsidev = dsi_get_dsidev_from_id(1);
1868 if (dsidev)
1869 debugfs_create_file("dsi2_irqs", S_IRUGO, debugfs_dir,
1870 &dsi2_dump_irqs, debug_fops);
1871}
1872#endif
1873
1874static void dsi_dump_dsidev_regs(struct platform_device *dsidev,
1875 struct seq_file *s)
1876{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301877#define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dsi_read_reg(dsidev, r))
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001878
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001879 if (dsi_runtime_get(dsidev))
1880 return;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301881 dsi_enable_scp_clk(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001882
1883 DUMPREG(DSI_REVISION);
1884 DUMPREG(DSI_SYSCONFIG);
1885 DUMPREG(DSI_SYSSTATUS);
1886 DUMPREG(DSI_IRQSTATUS);
1887 DUMPREG(DSI_IRQENABLE);
1888 DUMPREG(DSI_CTRL);
1889 DUMPREG(DSI_COMPLEXIO_CFG1);
1890 DUMPREG(DSI_COMPLEXIO_IRQ_STATUS);
1891 DUMPREG(DSI_COMPLEXIO_IRQ_ENABLE);
1892 DUMPREG(DSI_CLK_CTRL);
1893 DUMPREG(DSI_TIMING1);
1894 DUMPREG(DSI_TIMING2);
1895 DUMPREG(DSI_VM_TIMING1);
1896 DUMPREG(DSI_VM_TIMING2);
1897 DUMPREG(DSI_VM_TIMING3);
1898 DUMPREG(DSI_CLK_TIMING);
1899 DUMPREG(DSI_TX_FIFO_VC_SIZE);
1900 DUMPREG(DSI_RX_FIFO_VC_SIZE);
1901 DUMPREG(DSI_COMPLEXIO_CFG2);
1902 DUMPREG(DSI_RX_FIFO_VC_FULLNESS);
1903 DUMPREG(DSI_VM_TIMING4);
1904 DUMPREG(DSI_TX_FIFO_VC_EMPTINESS);
1905 DUMPREG(DSI_VM_TIMING5);
1906 DUMPREG(DSI_VM_TIMING6);
1907 DUMPREG(DSI_VM_TIMING7);
1908 DUMPREG(DSI_STOPCLK_TIMING);
1909
1910 DUMPREG(DSI_VC_CTRL(0));
1911 DUMPREG(DSI_VC_TE(0));
1912 DUMPREG(DSI_VC_LONG_PACKET_HEADER(0));
1913 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(0));
1914 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(0));
1915 DUMPREG(DSI_VC_IRQSTATUS(0));
1916 DUMPREG(DSI_VC_IRQENABLE(0));
1917
1918 DUMPREG(DSI_VC_CTRL(1));
1919 DUMPREG(DSI_VC_TE(1));
1920 DUMPREG(DSI_VC_LONG_PACKET_HEADER(1));
1921 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(1));
1922 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(1));
1923 DUMPREG(DSI_VC_IRQSTATUS(1));
1924 DUMPREG(DSI_VC_IRQENABLE(1));
1925
1926 DUMPREG(DSI_VC_CTRL(2));
1927 DUMPREG(DSI_VC_TE(2));
1928 DUMPREG(DSI_VC_LONG_PACKET_HEADER(2));
1929 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(2));
1930 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(2));
1931 DUMPREG(DSI_VC_IRQSTATUS(2));
1932 DUMPREG(DSI_VC_IRQENABLE(2));
1933
1934 DUMPREG(DSI_VC_CTRL(3));
1935 DUMPREG(DSI_VC_TE(3));
1936 DUMPREG(DSI_VC_LONG_PACKET_HEADER(3));
1937 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(3));
1938 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(3));
1939 DUMPREG(DSI_VC_IRQSTATUS(3));
1940 DUMPREG(DSI_VC_IRQENABLE(3));
1941
1942 DUMPREG(DSI_DSIPHY_CFG0);
1943 DUMPREG(DSI_DSIPHY_CFG1);
1944 DUMPREG(DSI_DSIPHY_CFG2);
1945 DUMPREG(DSI_DSIPHY_CFG5);
1946
1947 DUMPREG(DSI_PLL_CONTROL);
1948 DUMPREG(DSI_PLL_STATUS);
1949 DUMPREG(DSI_PLL_GO);
1950 DUMPREG(DSI_PLL_CONFIGURATION1);
1951 DUMPREG(DSI_PLL_CONFIGURATION2);
1952
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301953 dsi_disable_scp_clk(dsidev);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001954 dsi_runtime_put(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001955#undef DUMPREG
1956}
1957
Archit Taneja5a8b5722011-05-12 17:26:29 +05301958static void dsi1_dump_regs(struct seq_file *s)
1959{
1960 struct platform_device *dsidev = dsi_get_dsidev_from_id(0);
1961
1962 dsi_dump_dsidev_regs(dsidev, s);
1963}
1964
1965static void dsi2_dump_regs(struct seq_file *s)
1966{
1967 struct platform_device *dsidev = dsi_get_dsidev_from_id(1);
1968
1969 dsi_dump_dsidev_regs(dsidev, s);
1970}
1971
1972void dsi_create_debugfs_files_reg(struct dentry *debugfs_dir,
1973 const struct file_operations *debug_fops)
1974{
1975 struct platform_device *dsidev;
1976
1977 dsidev = dsi_get_dsidev_from_id(0);
1978 if (dsidev)
1979 debugfs_create_file("dsi1_regs", S_IRUGO, debugfs_dir,
1980 &dsi1_dump_regs, debug_fops);
1981
1982 dsidev = dsi_get_dsidev_from_id(1);
1983 if (dsidev)
1984 debugfs_create_file("dsi2_regs", S_IRUGO, debugfs_dir,
1985 &dsi2_dump_regs, debug_fops);
1986}
Tomi Valkeinencc5c1852010-10-06 15:18:13 +03001987enum dsi_cio_power_state {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001988 DSI_COMPLEXIO_POWER_OFF = 0x0,
1989 DSI_COMPLEXIO_POWER_ON = 0x1,
1990 DSI_COMPLEXIO_POWER_ULPS = 0x2,
1991};
1992
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301993static int dsi_cio_power(struct platform_device *dsidev,
1994 enum dsi_cio_power_state state)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001995{
1996 int t = 0;
1997
1998 /* PWR_CMD */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301999 REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG1, state, 28, 27);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002000
2001 /* PWR_STATUS */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302002 while (FLD_GET(dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1),
2003 26, 25) != state) {
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02002004 if (++t > 1000) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002005 DSSERR("failed to set complexio power state to "
2006 "%d\n", state);
2007 return -ENODEV;
2008 }
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02002009 udelay(1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002010 }
2011
2012 return 0;
2013}
2014
Archit Taneja75d72472011-05-16 15:17:08 +05302015/* Number of data lanes present on DSI interface */
2016static inline int dsi_get_num_data_lanes(struct platform_device *dsidev)
2017{
2018 /* DSI on OMAP3 doesn't have register DSI_GNQ, set number
2019 * of data lanes as 2 by default */
2020 if (dss_has_feature(FEAT_DSI_GNQ))
2021 return REG_GET(dsidev, DSI_GNQ, 11, 9); /* NB_DATA_LANES */
2022 else
2023 return 2;
2024}
2025
2026/* Number of data lanes used by the dss device */
2027static inline int dsi_get_num_data_lanes_dssdev(struct omap_dss_device *dssdev)
2028{
2029 int num_data_lanes = 0;
2030
2031 if (dssdev->phy.dsi.data1_lane != 0)
2032 num_data_lanes++;
2033 if (dssdev->phy.dsi.data2_lane != 0)
2034 num_data_lanes++;
2035 if (dssdev->phy.dsi.data3_lane != 0)
2036 num_data_lanes++;
2037 if (dssdev->phy.dsi.data4_lane != 0)
2038 num_data_lanes++;
2039
2040 return num_data_lanes;
2041}
2042
Archit Taneja0c656222011-05-16 15:17:09 +05302043static unsigned dsi_get_line_buf_size(struct platform_device *dsidev)
2044{
2045 int val;
2046
2047 /* line buffer on OMAP3 is 1024 x 24bits */
2048 /* XXX: for some reason using full buffer size causes
2049 * considerable TX slowdown with update sizes that fill the
2050 * whole buffer */
2051 if (!dss_has_feature(FEAT_DSI_GNQ))
2052 return 1023 * 3;
2053
2054 val = REG_GET(dsidev, DSI_GNQ, 14, 12); /* VP1_LINE_BUFFER_SIZE */
2055
2056 switch (val) {
2057 case 1:
2058 return 512 * 3; /* 512x24 bits */
2059 case 2:
2060 return 682 * 3; /* 682x24 bits */
2061 case 3:
2062 return 853 * 3; /* 853x24 bits */
2063 case 4:
2064 return 1024 * 3; /* 1024x24 bits */
2065 case 5:
2066 return 1194 * 3; /* 1194x24 bits */
2067 case 6:
2068 return 1365 * 3; /* 1365x24 bits */
2069 default:
2070 BUG();
2071 }
2072}
2073
Tomi Valkeinencc5c1852010-10-06 15:18:13 +03002074static void dsi_set_lane_config(struct omap_dss_device *dssdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002075{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302076 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002077 u32 r;
Archit Taneja75d72472011-05-16 15:17:08 +05302078 int num_data_lanes_dssdev = dsi_get_num_data_lanes_dssdev(dssdev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002079
2080 int clk_lane = dssdev->phy.dsi.clk_lane;
2081 int data1_lane = dssdev->phy.dsi.data1_lane;
2082 int data2_lane = dssdev->phy.dsi.data2_lane;
2083 int clk_pol = dssdev->phy.dsi.clk_pol;
2084 int data1_pol = dssdev->phy.dsi.data1_pol;
2085 int data2_pol = dssdev->phy.dsi.data2_pol;
2086
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302087 r = dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002088 r = FLD_MOD(r, clk_lane, 2, 0);
2089 r = FLD_MOD(r, clk_pol, 3, 3);
2090 r = FLD_MOD(r, data1_lane, 6, 4);
2091 r = FLD_MOD(r, data1_pol, 7, 7);
2092 r = FLD_MOD(r, data2_lane, 10, 8);
2093 r = FLD_MOD(r, data2_pol, 11, 11);
Archit Taneja75d72472011-05-16 15:17:08 +05302094 if (num_data_lanes_dssdev > 2) {
2095 int data3_lane = dssdev->phy.dsi.data3_lane;
2096 int data3_pol = dssdev->phy.dsi.data3_pol;
2097
2098 r = FLD_MOD(r, data3_lane, 14, 12);
2099 r = FLD_MOD(r, data3_pol, 15, 15);
2100 }
2101 if (num_data_lanes_dssdev > 3) {
2102 int data4_lane = dssdev->phy.dsi.data4_lane;
2103 int data4_pol = dssdev->phy.dsi.data4_pol;
2104
2105 r = FLD_MOD(r, data4_lane, 18, 16);
2106 r = FLD_MOD(r, data4_pol, 19, 19);
2107 }
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302108 dsi_write_reg(dsidev, DSI_COMPLEXIO_CFG1, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002109
2110 /* The configuration of the DSI complex I/O (number of data lanes,
2111 position, differential order) should not be changed while
2112 DSS.DSI_CLK_CRTRL[20] LP_CLK_ENABLE bit is set to 1. In order for
2113 the hardware to take into account a new configuration of the complex
2114 I/O (done in DSS.DSI_COMPLEXIO_CFG1 register), it is recommended to
2115 follow this sequence: First set the DSS.DSI_CTRL[0] IF_EN bit to 1,
2116 then reset the DSS.DSI_CTRL[0] IF_EN to 0, then set
2117 DSS.DSI_CLK_CTRL[20] LP_CLK_ENABLE to 1 and finally set again the
2118 DSS.DSI_CTRL[0] IF_EN bit to 1. If the sequence is not followed, the
2119 DSI complex I/O configuration is unknown. */
2120
2121 /*
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302122 REG_FLD_MOD(dsidev, DSI_CTRL, 1, 0, 0);
2123 REG_FLD_MOD(dsidev, DSI_CTRL, 0, 0, 0);
2124 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 1, 20, 20);
2125 REG_FLD_MOD(dsidev, DSI_CTRL, 1, 0, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002126 */
2127}
2128
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302129static inline unsigned ns2ddr(struct platform_device *dsidev, unsigned ns)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002130{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302131 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2132
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002133 /* convert time in ns to ddr ticks, rounding up */
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302134 unsigned long ddr_clk = dsi->current_cinfo.clkin4ddr / 4;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002135 return (ns * (ddr_clk / 1000 / 1000) + 999) / 1000;
2136}
2137
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302138static inline unsigned ddr2ns(struct platform_device *dsidev, unsigned ddr)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002139{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302140 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2141
2142 unsigned long ddr_clk = dsi->current_cinfo.clkin4ddr / 4;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002143 return ddr * 1000 * 1000 / (ddr_clk / 1000);
2144}
2145
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302146static void dsi_cio_timings(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002147{
2148 u32 r;
2149 u32 ths_prepare, ths_prepare_ths_zero, ths_trail, ths_exit;
2150 u32 tlpx_half, tclk_trail, tclk_zero;
2151 u32 tclk_prepare;
2152
2153 /* calculate timings */
2154
2155 /* 1 * DDR_CLK = 2 * UI */
2156
2157 /* min 40ns + 4*UI max 85ns + 6*UI */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302158 ths_prepare = ns2ddr(dsidev, 70) + 2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002159
2160 /* min 145ns + 10*UI */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302161 ths_prepare_ths_zero = ns2ddr(dsidev, 175) + 2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002162
2163 /* min max(8*UI, 60ns+4*UI) */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302164 ths_trail = ns2ddr(dsidev, 60) + 5;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002165
2166 /* min 100ns */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302167 ths_exit = ns2ddr(dsidev, 145);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002168
2169 /* tlpx min 50n */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302170 tlpx_half = ns2ddr(dsidev, 25);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002171
2172 /* min 60ns */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302173 tclk_trail = ns2ddr(dsidev, 60) + 2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002174
2175 /* min 38ns, max 95ns */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302176 tclk_prepare = ns2ddr(dsidev, 65);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002177
2178 /* min tclk-prepare + tclk-zero = 300ns */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302179 tclk_zero = ns2ddr(dsidev, 260);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002180
2181 DSSDBG("ths_prepare %u (%uns), ths_prepare_ths_zero %u (%uns)\n",
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302182 ths_prepare, ddr2ns(dsidev, ths_prepare),
2183 ths_prepare_ths_zero, ddr2ns(dsidev, ths_prepare_ths_zero));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002184 DSSDBG("ths_trail %u (%uns), ths_exit %u (%uns)\n",
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302185 ths_trail, ddr2ns(dsidev, ths_trail),
2186 ths_exit, ddr2ns(dsidev, ths_exit));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002187
2188 DSSDBG("tlpx_half %u (%uns), tclk_trail %u (%uns), "
2189 "tclk_zero %u (%uns)\n",
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302190 tlpx_half, ddr2ns(dsidev, tlpx_half),
2191 tclk_trail, ddr2ns(dsidev, tclk_trail),
2192 tclk_zero, ddr2ns(dsidev, tclk_zero));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002193 DSSDBG("tclk_prepare %u (%uns)\n",
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302194 tclk_prepare, ddr2ns(dsidev, tclk_prepare));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002195
2196 /* program timings */
2197
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302198 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002199 r = FLD_MOD(r, ths_prepare, 31, 24);
2200 r = FLD_MOD(r, ths_prepare_ths_zero, 23, 16);
2201 r = FLD_MOD(r, ths_trail, 15, 8);
2202 r = FLD_MOD(r, ths_exit, 7, 0);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302203 dsi_write_reg(dsidev, DSI_DSIPHY_CFG0, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002204
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302205 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002206 r = FLD_MOD(r, tlpx_half, 22, 16);
2207 r = FLD_MOD(r, tclk_trail, 15, 8);
2208 r = FLD_MOD(r, tclk_zero, 7, 0);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302209 dsi_write_reg(dsidev, DSI_DSIPHY_CFG1, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002210
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302211 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG2);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002212 r = FLD_MOD(r, tclk_prepare, 7, 0);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302213 dsi_write_reg(dsidev, DSI_DSIPHY_CFG2, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002214}
2215
Tomi Valkeinencc5c1852010-10-06 15:18:13 +03002216static void dsi_cio_enable_lane_override(struct omap_dss_device *dssdev,
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002217 enum dsi_lane lanes)
2218{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302219 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Taneja75d72472011-05-16 15:17:08 +05302220 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002221 int clk_lane = dssdev->phy.dsi.clk_lane;
2222 int data1_lane = dssdev->phy.dsi.data1_lane;
2223 int data2_lane = dssdev->phy.dsi.data2_lane;
Archit Taneja75d72472011-05-16 15:17:08 +05302224 int data3_lane = dssdev->phy.dsi.data3_lane;
2225 int data4_lane = dssdev->phy.dsi.data4_lane;
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002226 int clk_pol = dssdev->phy.dsi.clk_pol;
2227 int data1_pol = dssdev->phy.dsi.data1_pol;
2228 int data2_pol = dssdev->phy.dsi.data2_pol;
Archit Taneja75d72472011-05-16 15:17:08 +05302229 int data3_pol = dssdev->phy.dsi.data3_pol;
2230 int data4_pol = dssdev->phy.dsi.data4_pol;
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002231
2232 u32 l = 0;
Archit Taneja75d72472011-05-16 15:17:08 +05302233 u8 lptxscp_start = dsi->num_data_lanes == 2 ? 22 : 26;
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002234
2235 if (lanes & DSI_CLK_P)
2236 l |= 1 << ((clk_lane - 1) * 2 + (clk_pol ? 0 : 1));
2237 if (lanes & DSI_CLK_N)
2238 l |= 1 << ((clk_lane - 1) * 2 + (clk_pol ? 1 : 0));
2239
2240 if (lanes & DSI_DATA1_P)
2241 l |= 1 << ((data1_lane - 1) * 2 + (data1_pol ? 0 : 1));
2242 if (lanes & DSI_DATA1_N)
2243 l |= 1 << ((data1_lane - 1) * 2 + (data1_pol ? 1 : 0));
2244
2245 if (lanes & DSI_DATA2_P)
2246 l |= 1 << ((data2_lane - 1) * 2 + (data2_pol ? 0 : 1));
2247 if (lanes & DSI_DATA2_N)
2248 l |= 1 << ((data2_lane - 1) * 2 + (data2_pol ? 1 : 0));
2249
Archit Taneja75d72472011-05-16 15:17:08 +05302250 if (lanes & DSI_DATA3_P)
2251 l |= 1 << ((data3_lane - 1) * 2 + (data3_pol ? 0 : 1));
2252 if (lanes & DSI_DATA3_N)
2253 l |= 1 << ((data3_lane - 1) * 2 + (data3_pol ? 1 : 0));
2254
2255 if (lanes & DSI_DATA4_P)
2256 l |= 1 << ((data4_lane - 1) * 2 + (data4_pol ? 0 : 1));
2257 if (lanes & DSI_DATA4_N)
2258 l |= 1 << ((data4_lane - 1) * 2 + (data4_pol ? 1 : 0));
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002259 /*
2260 * Bits in REGLPTXSCPDAT4TO0DXDY:
2261 * 17: DY0 18: DX0
2262 * 19: DY1 20: DX1
2263 * 21: DY2 22: DX2
Archit Taneja75d72472011-05-16 15:17:08 +05302264 * 23: DY3 24: DX3
2265 * 25: DY4 26: DX4
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002266 */
2267
2268 /* Set the lane override configuration */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302269
2270 /* REGLPTXSCPDAT4TO0DXDY */
Archit Taneja75d72472011-05-16 15:17:08 +05302271 REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, l, lptxscp_start, 17);
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002272
2273 /* Enable lane override */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302274
2275 /* ENLPTXSCPDAT */
2276 REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 1, 27, 27);
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002277}
2278
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302279static void dsi_cio_disable_lane_override(struct platform_device *dsidev)
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002280{
2281 /* Disable lane override */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302282 REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 0, 27, 27); /* ENLPTXSCPDAT */
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002283 /* Reset the lane override configuration */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302284 /* REGLPTXSCPDAT4TO0DXDY */
2285 REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 0, 22, 17);
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002286}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002287
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002288static int dsi_cio_wait_tx_clk_esc_reset(struct omap_dss_device *dssdev)
2289{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302290 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002291 int t;
2292 int bits[3];
2293 bool in_use[3];
2294
2295 if (dss_has_feature(FEAT_DSI_REVERSE_TXCLKESC)) {
2296 bits[0] = 28;
2297 bits[1] = 27;
2298 bits[2] = 26;
2299 } else {
2300 bits[0] = 24;
2301 bits[1] = 25;
2302 bits[2] = 26;
2303 }
2304
2305 in_use[0] = false;
2306 in_use[1] = false;
2307 in_use[2] = false;
2308
2309 if (dssdev->phy.dsi.clk_lane != 0)
2310 in_use[dssdev->phy.dsi.clk_lane - 1] = true;
2311 if (dssdev->phy.dsi.data1_lane != 0)
2312 in_use[dssdev->phy.dsi.data1_lane - 1] = true;
2313 if (dssdev->phy.dsi.data2_lane != 0)
2314 in_use[dssdev->phy.dsi.data2_lane - 1] = true;
2315
2316 t = 100000;
2317 while (true) {
2318 u32 l;
2319 int i;
2320 int ok;
2321
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302322 l = dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002323
2324 ok = 0;
2325 for (i = 0; i < 3; ++i) {
2326 if (!in_use[i] || (l & (1 << bits[i])))
2327 ok++;
2328 }
2329
2330 if (ok == 3)
2331 break;
2332
2333 if (--t == 0) {
2334 for (i = 0; i < 3; ++i) {
2335 if (!in_use[i] || (l & (1 << bits[i])))
2336 continue;
2337
2338 DSSERR("CIO TXCLKESC%d domain not coming " \
2339 "out of reset\n", i);
2340 }
2341 return -EIO;
2342 }
2343 }
2344
2345 return 0;
2346}
2347
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03002348static unsigned dsi_get_lane_mask(struct omap_dss_device *dssdev)
2349{
2350 unsigned lanes = 0;
2351
2352 if (dssdev->phy.dsi.clk_lane != 0)
2353 lanes |= 1 << (dssdev->phy.dsi.clk_lane - 1);
2354 if (dssdev->phy.dsi.data1_lane != 0)
2355 lanes |= 1 << (dssdev->phy.dsi.data1_lane - 1);
2356 if (dssdev->phy.dsi.data2_lane != 0)
2357 lanes |= 1 << (dssdev->phy.dsi.data2_lane - 1);
2358 if (dssdev->phy.dsi.data3_lane != 0)
2359 lanes |= 1 << (dssdev->phy.dsi.data3_lane - 1);
2360 if (dssdev->phy.dsi.data4_lane != 0)
2361 lanes |= 1 << (dssdev->phy.dsi.data4_lane - 1);
2362
2363 return lanes;
2364}
2365
Tomi Valkeinencc5c1852010-10-06 15:18:13 +03002366static int dsi_cio_init(struct omap_dss_device *dssdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002367{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302368 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302369 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002370 int r;
Archit Taneja75d72472011-05-16 15:17:08 +05302371 int num_data_lanes_dssdev = dsi_get_num_data_lanes_dssdev(dssdev);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002372 u32 l;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002373
Tomi Valkeinencc5c1852010-10-06 15:18:13 +03002374 DSSDBGF();
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002375
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03002376 r = dsi->enable_pads(dsidev->id, dsi_get_lane_mask(dssdev));
2377 if (r)
2378 return r;
Tomi Valkeinend1f58572010-07-30 11:57:57 +03002379
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302380 dsi_enable_scp_clk(dsidev);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002381
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002382 /* A dummy read using the SCP interface to any DSIPHY register is
2383 * required after DSIPHY reset to complete the reset of the DSI complex
2384 * I/O. */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302385 dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002386
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302387 if (wait_for_bit_change(dsidev, DSI_DSIPHY_CFG5, 30, 1) != 1) {
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002388 DSSERR("CIO SCP Clock domain not coming out of reset.\n");
2389 r = -EIO;
2390 goto err_scp_clk_dom;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002391 }
2392
Tomi Valkeinencc5c1852010-10-06 15:18:13 +03002393 dsi_set_lane_config(dssdev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002394
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002395 /* set TX STOP MODE timer to maximum for this operation */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302396 l = dsi_read_reg(dsidev, DSI_TIMING1);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002397 l = FLD_MOD(l, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
2398 l = FLD_MOD(l, 1, 14, 14); /* STOP_STATE_X16_IO */
2399 l = FLD_MOD(l, 1, 13, 13); /* STOP_STATE_X4_IO */
2400 l = FLD_MOD(l, 0x1fff, 12, 0); /* STOP_STATE_COUNTER_IO */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302401 dsi_write_reg(dsidev, DSI_TIMING1, l);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002402
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302403 if (dsi->ulps_enabled) {
Archit Taneja75d72472011-05-16 15:17:08 +05302404 u32 lane_mask = DSI_CLK_P | DSI_DATA1_P | DSI_DATA2_P;
2405
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002406 DSSDBG("manual ulps exit\n");
2407
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002408 /* ULPS is exited by Mark-1 state for 1ms, followed by
2409 * stop state. DSS HW cannot do this via the normal
2410 * ULPS exit sequence, as after reset the DSS HW thinks
2411 * that we are not in ULPS mode, and refuses to send the
2412 * sequence. So we need to send the ULPS exit sequence
2413 * manually.
2414 */
2415
Archit Taneja75d72472011-05-16 15:17:08 +05302416 if (num_data_lanes_dssdev > 2)
2417 lane_mask |= DSI_DATA3_P;
2418
2419 if (num_data_lanes_dssdev > 3)
2420 lane_mask |= DSI_DATA4_P;
2421
2422 dsi_cio_enable_lane_override(dssdev, lane_mask);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002423 }
2424
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302425 r = dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_ON);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002426 if (r)
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002427 goto err_cio_pwr;
2428
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302429 if (wait_for_bit_change(dsidev, DSI_COMPLEXIO_CFG1, 29, 1) != 1) {
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002430 DSSERR("CIO PWR clock domain not coming out of reset.\n");
2431 r = -ENODEV;
2432 goto err_cio_pwr_dom;
2433 }
2434
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302435 dsi_if_enable(dsidev, true);
2436 dsi_if_enable(dsidev, false);
2437 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 1, 20, 20); /* LP_CLK_ENABLE */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002438
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002439 r = dsi_cio_wait_tx_clk_esc_reset(dssdev);
2440 if (r)
2441 goto err_tx_clk_esc_rst;
2442
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302443 if (dsi->ulps_enabled) {
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002444 /* Keep Mark-1 state for 1ms (as per DSI spec) */
2445 ktime_t wait = ns_to_ktime(1000 * 1000);
2446 set_current_state(TASK_UNINTERRUPTIBLE);
2447 schedule_hrtimeout(&wait, HRTIMER_MODE_REL);
2448
2449 /* Disable the override. The lanes should be set to Mark-11
2450 * state by the HW */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302451 dsi_cio_disable_lane_override(dsidev);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002452 }
2453
2454 /* FORCE_TX_STOP_MODE_IO */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302455 REG_FLD_MOD(dsidev, DSI_TIMING1, 0, 15, 15);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002456
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302457 dsi_cio_timings(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002458
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302459 dsi->ulps_enabled = false;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002460
2461 DSSDBG("CIO init done\n");
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002462
2463 return 0;
2464
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002465err_tx_clk_esc_rst:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302466 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 20, 20); /* LP_CLK_ENABLE */
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002467err_cio_pwr_dom:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302468 dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_OFF);
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002469err_cio_pwr:
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302470 if (dsi->ulps_enabled)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302471 dsi_cio_disable_lane_override(dsidev);
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002472err_scp_clk_dom:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302473 dsi_disable_scp_clk(dsidev);
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03002474 dsi->disable_pads(dsidev->id, dsi_get_lane_mask(dssdev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002475 return r;
2476}
2477
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03002478static void dsi_cio_uninit(struct omap_dss_device *dssdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002479{
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03002480 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302481 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2482
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302483 dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_OFF);
2484 dsi_disable_scp_clk(dsidev);
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03002485 dsi->disable_pads(dsidev->id, dsi_get_lane_mask(dssdev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002486}
2487
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302488static void dsi_config_tx_fifo(struct platform_device *dsidev,
2489 enum fifo_size size1, enum fifo_size size2,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002490 enum fifo_size size3, enum fifo_size size4)
2491{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302492 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002493 u32 r = 0;
2494 int add = 0;
2495 int i;
2496
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302497 dsi->vc[0].fifo_size = size1;
2498 dsi->vc[1].fifo_size = size2;
2499 dsi->vc[2].fifo_size = size3;
2500 dsi->vc[3].fifo_size = size4;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002501
2502 for (i = 0; i < 4; i++) {
2503 u8 v;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302504 int size = dsi->vc[i].fifo_size;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002505
2506 if (add + size > 4) {
2507 DSSERR("Illegal FIFO configuration\n");
2508 BUG();
2509 }
2510
2511 v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
2512 r |= v << (8 * i);
2513 /*DSSDBG("TX FIFO vc %d: size %d, add %d\n", i, size, add); */
2514 add += size;
2515 }
2516
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302517 dsi_write_reg(dsidev, DSI_TX_FIFO_VC_SIZE, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002518}
2519
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302520static void dsi_config_rx_fifo(struct platform_device *dsidev,
2521 enum fifo_size size1, enum fifo_size size2,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002522 enum fifo_size size3, enum fifo_size size4)
2523{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302524 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002525 u32 r = 0;
2526 int add = 0;
2527 int i;
2528
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302529 dsi->vc[0].fifo_size = size1;
2530 dsi->vc[1].fifo_size = size2;
2531 dsi->vc[2].fifo_size = size3;
2532 dsi->vc[3].fifo_size = size4;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002533
2534 for (i = 0; i < 4; i++) {
2535 u8 v;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302536 int size = dsi->vc[i].fifo_size;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002537
2538 if (add + size > 4) {
2539 DSSERR("Illegal FIFO configuration\n");
2540 BUG();
2541 }
2542
2543 v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
2544 r |= v << (8 * i);
2545 /*DSSDBG("RX FIFO vc %d: size %d, add %d\n", i, size, add); */
2546 add += size;
2547 }
2548
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302549 dsi_write_reg(dsidev, DSI_RX_FIFO_VC_SIZE, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002550}
2551
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302552static int dsi_force_tx_stop_mode_io(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002553{
2554 u32 r;
2555
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302556 r = dsi_read_reg(dsidev, DSI_TIMING1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002557 r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302558 dsi_write_reg(dsidev, DSI_TIMING1, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002559
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302560 if (wait_for_bit_change(dsidev, DSI_TIMING1, 15, 0) != 0) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002561 DSSERR("TX_STOP bit not going down\n");
2562 return -EIO;
2563 }
2564
2565 return 0;
2566}
2567
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302568static bool dsi_vc_is_enabled(struct platform_device *dsidev, int channel)
Archit Tanejacf398fb2011-03-23 09:59:34 +00002569{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302570 return REG_GET(dsidev, DSI_VC_CTRL(channel), 0, 0);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002571}
2572
2573static void dsi_packet_sent_handler_vp(void *data, u32 mask)
2574{
Archit Taneja2e868db2011-05-12 17:26:28 +05302575 struct dsi_packet_sent_handler_data *vp_data =
2576 (struct dsi_packet_sent_handler_data *) data;
2577 struct dsi_data *dsi = dsi_get_dsidrv_data(vp_data->dsidev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302578 const int channel = dsi->update_channel;
2579 u8 bit = dsi->te_enabled ? 30 : 31;
Archit Tanejacf398fb2011-03-23 09:59:34 +00002580
Archit Taneja2e868db2011-05-12 17:26:28 +05302581 if (REG_GET(vp_data->dsidev, DSI_VC_TE(channel), bit, bit) == 0)
2582 complete(vp_data->completion);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002583}
2584
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302585static int dsi_sync_vc_vp(struct platform_device *dsidev, int channel)
Archit Tanejacf398fb2011-03-23 09:59:34 +00002586{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302587 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Taneja2e868db2011-05-12 17:26:28 +05302588 DECLARE_COMPLETION_ONSTACK(completion);
2589 struct dsi_packet_sent_handler_data vp_data = { dsidev, &completion };
Archit Tanejacf398fb2011-03-23 09:59:34 +00002590 int r = 0;
2591 u8 bit;
2592
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302593 bit = dsi->te_enabled ? 30 : 31;
Archit Tanejacf398fb2011-03-23 09:59:34 +00002594
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302595 r = dsi_register_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp,
Archit Taneja2e868db2011-05-12 17:26:28 +05302596 &vp_data, DSI_VC_IRQ_PACKET_SENT);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002597 if (r)
2598 goto err0;
2599
2600 /* Wait for completion only if TE_EN/TE_START is still set */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302601 if (REG_GET(dsidev, DSI_VC_TE(channel), bit, bit)) {
Archit Tanejacf398fb2011-03-23 09:59:34 +00002602 if (wait_for_completion_timeout(&completion,
2603 msecs_to_jiffies(10)) == 0) {
2604 DSSERR("Failed to complete previous frame transfer\n");
2605 r = -EIO;
2606 goto err1;
2607 }
2608 }
2609
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302610 dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp,
Archit Taneja2e868db2011-05-12 17:26:28 +05302611 &vp_data, DSI_VC_IRQ_PACKET_SENT);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002612
2613 return 0;
2614err1:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302615 dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp,
Archit Taneja2e868db2011-05-12 17:26:28 +05302616 &vp_data, DSI_VC_IRQ_PACKET_SENT);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002617err0:
2618 return r;
2619}
2620
2621static void dsi_packet_sent_handler_l4(void *data, u32 mask)
2622{
Archit Taneja2e868db2011-05-12 17:26:28 +05302623 struct dsi_packet_sent_handler_data *l4_data =
2624 (struct dsi_packet_sent_handler_data *) data;
2625 struct dsi_data *dsi = dsi_get_dsidrv_data(l4_data->dsidev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302626 const int channel = dsi->update_channel;
Archit Tanejacf398fb2011-03-23 09:59:34 +00002627
Archit Taneja2e868db2011-05-12 17:26:28 +05302628 if (REG_GET(l4_data->dsidev, DSI_VC_CTRL(channel), 5, 5) == 0)
2629 complete(l4_data->completion);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002630}
2631
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302632static int dsi_sync_vc_l4(struct platform_device *dsidev, int channel)
Archit Tanejacf398fb2011-03-23 09:59:34 +00002633{
Archit Taneja2e868db2011-05-12 17:26:28 +05302634 DECLARE_COMPLETION_ONSTACK(completion);
2635 struct dsi_packet_sent_handler_data l4_data = { dsidev, &completion };
Archit Tanejacf398fb2011-03-23 09:59:34 +00002636 int r = 0;
2637
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302638 r = dsi_register_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4,
Archit Taneja2e868db2011-05-12 17:26:28 +05302639 &l4_data, DSI_VC_IRQ_PACKET_SENT);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002640 if (r)
2641 goto err0;
2642
2643 /* Wait for completion only if TX_FIFO_NOT_EMPTY is still set */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302644 if (REG_GET(dsidev, DSI_VC_CTRL(channel), 5, 5)) {
Archit Tanejacf398fb2011-03-23 09:59:34 +00002645 if (wait_for_completion_timeout(&completion,
2646 msecs_to_jiffies(10)) == 0) {
2647 DSSERR("Failed to complete previous l4 transfer\n");
2648 r = -EIO;
2649 goto err1;
2650 }
2651 }
2652
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302653 dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4,
Archit Taneja2e868db2011-05-12 17:26:28 +05302654 &l4_data, DSI_VC_IRQ_PACKET_SENT);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002655
2656 return 0;
2657err1:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302658 dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4,
Archit Taneja2e868db2011-05-12 17:26:28 +05302659 &l4_data, DSI_VC_IRQ_PACKET_SENT);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002660err0:
2661 return r;
2662}
2663
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302664static int dsi_sync_vc(struct platform_device *dsidev, int channel)
Archit Tanejacf398fb2011-03-23 09:59:34 +00002665{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302666 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2667
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302668 WARN_ON(!dsi_bus_is_locked(dsidev));
Archit Tanejacf398fb2011-03-23 09:59:34 +00002669
2670 WARN_ON(in_interrupt());
2671
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302672 if (!dsi_vc_is_enabled(dsidev, channel))
Archit Tanejacf398fb2011-03-23 09:59:34 +00002673 return 0;
2674
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302675 switch (dsi->vc[channel].mode) {
Archit Tanejacf398fb2011-03-23 09:59:34 +00002676 case DSI_VC_MODE_VP:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302677 return dsi_sync_vc_vp(dsidev, channel);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002678 case DSI_VC_MODE_L4:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302679 return dsi_sync_vc_l4(dsidev, channel);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002680 default:
2681 BUG();
2682 }
2683}
2684
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302685static int dsi_vc_enable(struct platform_device *dsidev, int channel,
2686 bool enable)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002687{
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +02002688 DSSDBG("dsi_vc_enable channel %d, enable %d\n",
2689 channel, enable);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002690
2691 enable = enable ? 1 : 0;
2692
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302693 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 0, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002694
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302695 if (wait_for_bit_change(dsidev, DSI_VC_CTRL(channel),
2696 0, enable) != enable) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002697 DSSERR("Failed to set dsi_vc_enable to %d\n", enable);
2698 return -EIO;
2699 }
2700
2701 return 0;
2702}
2703
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302704static void dsi_vc_initial_config(struct platform_device *dsidev, int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002705{
2706 u32 r;
2707
2708 DSSDBGF("%d", channel);
2709
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302710 r = dsi_read_reg(dsidev, DSI_VC_CTRL(channel));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002711
2712 if (FLD_GET(r, 15, 15)) /* VC_BUSY */
2713 DSSERR("VC(%d) busy when trying to configure it!\n",
2714 channel);
2715
2716 r = FLD_MOD(r, 0, 1, 1); /* SOURCE, 0 = L4 */
2717 r = FLD_MOD(r, 0, 2, 2); /* BTA_SHORT_EN */
2718 r = FLD_MOD(r, 0, 3, 3); /* BTA_LONG_EN */
2719 r = FLD_MOD(r, 0, 4, 4); /* MODE, 0 = command */
2720 r = FLD_MOD(r, 1, 7, 7); /* CS_TX_EN */
2721 r = FLD_MOD(r, 1, 8, 8); /* ECC_TX_EN */
2722 r = FLD_MOD(r, 0, 9, 9); /* MODE_SPEED, high speed on/off */
Archit Taneja9613c022011-03-22 06:33:36 -05002723 if (dss_has_feature(FEAT_DSI_VC_OCP_WIDTH))
2724 r = FLD_MOD(r, 3, 11, 10); /* OCP_WIDTH = 32 bit */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002725
2726 r = FLD_MOD(r, 4, 29, 27); /* DMA_RX_REQ_NB = no dma */
2727 r = FLD_MOD(r, 4, 23, 21); /* DMA_TX_REQ_NB = no dma */
2728
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302729 dsi_write_reg(dsidev, DSI_VC_CTRL(channel), r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002730}
2731
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302732static int dsi_vc_config_l4(struct platform_device *dsidev, int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002733{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302734 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2735
2736 if (dsi->vc[channel].mode == DSI_VC_MODE_L4)
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03002737 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002738
2739 DSSDBGF("%d", channel);
2740
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302741 dsi_sync_vc(dsidev, channel);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002742
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302743 dsi_vc_enable(dsidev, channel, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002744
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03002745 /* VC_BUSY */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302746 if (wait_for_bit_change(dsidev, DSI_VC_CTRL(channel), 15, 0) != 0) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002747 DSSERR("vc(%d) busy when trying to config for L4\n", channel);
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03002748 return -EIO;
2749 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002750
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302751 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 0, 1, 1); /* SOURCE, 0 = L4 */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002752
Archit Taneja9613c022011-03-22 06:33:36 -05002753 /* DCS_CMD_ENABLE */
2754 if (dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC))
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302755 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 0, 30, 30);
Archit Taneja9613c022011-03-22 06:33:36 -05002756
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302757 dsi_vc_enable(dsidev, channel, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002758
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302759 dsi->vc[channel].mode = DSI_VC_MODE_L4;
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03002760
2761 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002762}
2763
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302764static int dsi_vc_config_vp(struct platform_device *dsidev, int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002765{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302766 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2767
2768 if (dsi->vc[channel].mode == DSI_VC_MODE_VP)
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03002769 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002770
2771 DSSDBGF("%d", channel);
2772
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302773 dsi_sync_vc(dsidev, channel);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002774
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302775 dsi_vc_enable(dsidev, channel, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002776
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03002777 /* VC_BUSY */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302778 if (wait_for_bit_change(dsidev, DSI_VC_CTRL(channel), 15, 0) != 0) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002779 DSSERR("vc(%d) busy when trying to config for VP\n", channel);
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03002780 return -EIO;
2781 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002782
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302783 /* SOURCE, 1 = video port */
2784 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 1, 1, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002785
Archit Taneja9613c022011-03-22 06:33:36 -05002786 /* DCS_CMD_ENABLE */
2787 if (dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC))
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302788 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 1, 30, 30);
Archit Taneja9613c022011-03-22 06:33:36 -05002789
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302790 dsi_vc_enable(dsidev, channel, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002791
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302792 dsi->vc[channel].mode = DSI_VC_MODE_VP;
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03002793
2794 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002795}
2796
2797
Archit Taneja1ffefe72011-05-12 17:26:24 +05302798void omapdss_dsi_vc_enable_hs(struct omap_dss_device *dssdev, int channel,
2799 bool enable)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002800{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302801 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
2802
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002803 DSSDBG("dsi_vc_enable_hs(%d, %d)\n", channel, enable);
2804
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302805 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen61140c92010-01-12 16:00:30 +02002806
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302807 dsi_vc_enable(dsidev, channel, 0);
2808 dsi_if_enable(dsidev, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002809
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302810 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 9, 9);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002811
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302812 dsi_vc_enable(dsidev, channel, 1);
2813 dsi_if_enable(dsidev, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002814
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302815 dsi_force_tx_stop_mode_io(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002816}
Tomi Valkeinen61140c92010-01-12 16:00:30 +02002817EXPORT_SYMBOL(omapdss_dsi_vc_enable_hs);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002818
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302819static void dsi_vc_flush_long_data(struct platform_device *dsidev, int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002820{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302821 while (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002822 u32 val;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302823 val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002824 DSSDBG("\t\tb1 %#02x b2 %#02x b3 %#02x b4 %#02x\n",
2825 (val >> 0) & 0xff,
2826 (val >> 8) & 0xff,
2827 (val >> 16) & 0xff,
2828 (val >> 24) & 0xff);
2829 }
2830}
2831
2832static void dsi_show_rx_ack_with_err(u16 err)
2833{
2834 DSSERR("\tACK with ERROR (%#x):\n", err);
2835 if (err & (1 << 0))
2836 DSSERR("\t\tSoT Error\n");
2837 if (err & (1 << 1))
2838 DSSERR("\t\tSoT Sync Error\n");
2839 if (err & (1 << 2))
2840 DSSERR("\t\tEoT Sync Error\n");
2841 if (err & (1 << 3))
2842 DSSERR("\t\tEscape Mode Entry Command Error\n");
2843 if (err & (1 << 4))
2844 DSSERR("\t\tLP Transmit Sync Error\n");
2845 if (err & (1 << 5))
2846 DSSERR("\t\tHS Receive Timeout Error\n");
2847 if (err & (1 << 6))
2848 DSSERR("\t\tFalse Control Error\n");
2849 if (err & (1 << 7))
2850 DSSERR("\t\t(reserved7)\n");
2851 if (err & (1 << 8))
2852 DSSERR("\t\tECC Error, single-bit (corrected)\n");
2853 if (err & (1 << 9))
2854 DSSERR("\t\tECC Error, multi-bit (not corrected)\n");
2855 if (err & (1 << 10))
2856 DSSERR("\t\tChecksum Error\n");
2857 if (err & (1 << 11))
2858 DSSERR("\t\tData type not recognized\n");
2859 if (err & (1 << 12))
2860 DSSERR("\t\tInvalid VC ID\n");
2861 if (err & (1 << 13))
2862 DSSERR("\t\tInvalid Transmission Length\n");
2863 if (err & (1 << 14))
2864 DSSERR("\t\t(reserved14)\n");
2865 if (err & (1 << 15))
2866 DSSERR("\t\tDSI Protocol Violation\n");
2867}
2868
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302869static u16 dsi_vc_flush_receive_data(struct platform_device *dsidev,
2870 int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002871{
2872 /* RX_FIFO_NOT_EMPTY */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302873 while (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002874 u32 val;
2875 u8 dt;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302876 val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel));
Tomi Valkeinen86a78672010-03-16 16:19:06 +02002877 DSSERR("\trawval %#08x\n", val);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002878 dt = FLD_GET(val, 5, 0);
Archit Taneja7a7c48f2011-08-25 18:25:03 +05302879 if (dt == MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002880 u16 err = FLD_GET(val, 23, 8);
2881 dsi_show_rx_ack_with_err(err);
Archit Taneja7a7c48f2011-08-25 18:25:03 +05302882 } else if (dt == MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE) {
Tomi Valkeinen86a78672010-03-16 16:19:06 +02002883 DSSERR("\tDCS short response, 1 byte: %#x\n",
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002884 FLD_GET(val, 23, 8));
Archit Taneja7a7c48f2011-08-25 18:25:03 +05302885 } else if (dt == MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE) {
Tomi Valkeinen86a78672010-03-16 16:19:06 +02002886 DSSERR("\tDCS short response, 2 byte: %#x\n",
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002887 FLD_GET(val, 23, 8));
Archit Taneja7a7c48f2011-08-25 18:25:03 +05302888 } else if (dt == MIPI_DSI_RX_DCS_LONG_READ_RESPONSE) {
Tomi Valkeinen86a78672010-03-16 16:19:06 +02002889 DSSERR("\tDCS long response, len %d\n",
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002890 FLD_GET(val, 23, 8));
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302891 dsi_vc_flush_long_data(dsidev, channel);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002892 } else {
2893 DSSERR("\tunknown datatype 0x%02x\n", dt);
2894 }
2895 }
2896 return 0;
2897}
2898
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302899static int dsi_vc_send_bta(struct platform_device *dsidev, int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002900{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302901 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2902
2903 if (dsi->debug_write || dsi->debug_read)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002904 DSSDBG("dsi_vc_send_bta %d\n", channel);
2905
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302906 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002907
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302908 /* RX_FIFO_NOT_EMPTY */
2909 if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002910 DSSERR("rx fifo not empty when sending BTA, dumping data:\n");
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302911 dsi_vc_flush_receive_data(dsidev, channel);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002912 }
2913
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302914 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 1, 6, 6); /* BTA_EN */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002915
2916 return 0;
2917}
2918
Archit Taneja1ffefe72011-05-12 17:26:24 +05302919int dsi_vc_send_bta_sync(struct omap_dss_device *dssdev, int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002920{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302921 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Tomi Valkeinenf36a06e2011-03-02 14:48:41 +02002922 DECLARE_COMPLETION_ONSTACK(completion);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002923 int r = 0;
2924 u32 err;
2925
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302926 r = dsi_register_isr_vc(dsidev, channel, dsi_completion_handler,
Tomi Valkeinenf36a06e2011-03-02 14:48:41 +02002927 &completion, DSI_VC_IRQ_BTA);
2928 if (r)
2929 goto err0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002930
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302931 r = dsi_register_isr(dsidev, dsi_completion_handler, &completion,
Tomi Valkeinen773b30b2010-10-08 16:15:25 +03002932 DSI_IRQ_ERROR_MASK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002933 if (r)
Tomi Valkeinenf36a06e2011-03-02 14:48:41 +02002934 goto err1;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002935
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302936 r = dsi_vc_send_bta(dsidev, channel);
Tomi Valkeinen773b30b2010-10-08 16:15:25 +03002937 if (r)
2938 goto err2;
2939
Tomi Valkeinenf36a06e2011-03-02 14:48:41 +02002940 if (wait_for_completion_timeout(&completion,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002941 msecs_to_jiffies(500)) == 0) {
2942 DSSERR("Failed to receive BTA\n");
2943 r = -EIO;
Tomi Valkeinen773b30b2010-10-08 16:15:25 +03002944 goto err2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002945 }
2946
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302947 err = dsi_get_errors(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002948 if (err) {
2949 DSSERR("Error while sending BTA: %x\n", err);
2950 r = -EIO;
Tomi Valkeinen773b30b2010-10-08 16:15:25 +03002951 goto err2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002952 }
Tomi Valkeinen773b30b2010-10-08 16:15:25 +03002953err2:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302954 dsi_unregister_isr(dsidev, dsi_completion_handler, &completion,
Tomi Valkeinen773b30b2010-10-08 16:15:25 +03002955 DSI_IRQ_ERROR_MASK);
Tomi Valkeinenf36a06e2011-03-02 14:48:41 +02002956err1:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302957 dsi_unregister_isr_vc(dsidev, channel, dsi_completion_handler,
Tomi Valkeinenf36a06e2011-03-02 14:48:41 +02002958 &completion, DSI_VC_IRQ_BTA);
2959err0:
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002960 return r;
2961}
2962EXPORT_SYMBOL(dsi_vc_send_bta_sync);
2963
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302964static inline void dsi_vc_write_long_header(struct platform_device *dsidev,
2965 int channel, u8 data_type, u16 len, u8 ecc)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002966{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302967 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002968 u32 val;
2969 u8 data_id;
2970
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302971 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002972
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302973 data_id = data_type | dsi->vc[channel].vc_id << 6;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002974
2975 val = FLD_VAL(data_id, 7, 0) | FLD_VAL(len, 23, 8) |
2976 FLD_VAL(ecc, 31, 24);
2977
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302978 dsi_write_reg(dsidev, DSI_VC_LONG_PACKET_HEADER(channel), val);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002979}
2980
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302981static inline void dsi_vc_write_long_payload(struct platform_device *dsidev,
2982 int channel, u8 b1, u8 b2, u8 b3, u8 b4)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002983{
2984 u32 val;
2985
2986 val = b4 << 24 | b3 << 16 | b2 << 8 | b1 << 0;
2987
2988/* DSSDBG("\twriting %02x, %02x, %02x, %02x (%#010x)\n",
2989 b1, b2, b3, b4, val); */
2990
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302991 dsi_write_reg(dsidev, DSI_VC_LONG_PACKET_PAYLOAD(channel), val);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002992}
2993
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302994static int dsi_vc_send_long(struct platform_device *dsidev, int channel,
2995 u8 data_type, u8 *data, u16 len, u8 ecc)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002996{
2997 /*u32 val; */
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302998 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002999 int i;
3000 u8 *p;
3001 int r = 0;
3002 u8 b1, b2, b3, b4;
3003
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303004 if (dsi->debug_write)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003005 DSSDBG("dsi_vc_send_long, %d bytes\n", len);
3006
3007 /* len + header */
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303008 if (dsi->vc[channel].fifo_size * 32 * 4 < len + 4) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003009 DSSERR("unable to send long packet: packet too long.\n");
3010 return -EINVAL;
3011 }
3012
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303013 dsi_vc_config_l4(dsidev, channel);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003014
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303015 dsi_vc_write_long_header(dsidev, channel, data_type, len, ecc);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003016
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003017 p = data;
3018 for (i = 0; i < len >> 2; i++) {
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303019 if (dsi->debug_write)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003020 DSSDBG("\tsending full packet %d\n", i);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003021
3022 b1 = *p++;
3023 b2 = *p++;
3024 b3 = *p++;
3025 b4 = *p++;
3026
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303027 dsi_vc_write_long_payload(dsidev, channel, b1, b2, b3, b4);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003028 }
3029
3030 i = len % 4;
3031 if (i) {
3032 b1 = 0; b2 = 0; b3 = 0;
3033
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303034 if (dsi->debug_write)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003035 DSSDBG("\tsending remainder bytes %d\n", i);
3036
3037 switch (i) {
3038 case 3:
3039 b1 = *p++;
3040 b2 = *p++;
3041 b3 = *p++;
3042 break;
3043 case 2:
3044 b1 = *p++;
3045 b2 = *p++;
3046 break;
3047 case 1:
3048 b1 = *p++;
3049 break;
3050 }
3051
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303052 dsi_vc_write_long_payload(dsidev, channel, b1, b2, b3, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003053 }
3054
3055 return r;
3056}
3057
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303058static int dsi_vc_send_short(struct platform_device *dsidev, int channel,
3059 u8 data_type, u16 data, u8 ecc)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003060{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303061 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003062 u32 r;
3063 u8 data_id;
3064
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303065 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003066
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303067 if (dsi->debug_write)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003068 DSSDBG("dsi_vc_send_short(ch%d, dt %#x, b1 %#x, b2 %#x)\n",
3069 channel,
3070 data_type, data & 0xff, (data >> 8) & 0xff);
3071
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303072 dsi_vc_config_l4(dsidev, channel);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003073
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303074 if (FLD_GET(dsi_read_reg(dsidev, DSI_VC_CTRL(channel)), 16, 16)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003075 DSSERR("ERROR FIFO FULL, aborting transfer\n");
3076 return -EINVAL;
3077 }
3078
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303079 data_id = data_type | dsi->vc[channel].vc_id << 6;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003080
3081 r = (data_id << 0) | (data << 8) | (ecc << 24);
3082
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303083 dsi_write_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel), r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003084
3085 return 0;
3086}
3087
Archit Taneja1ffefe72011-05-12 17:26:24 +05303088int dsi_vc_send_null(struct omap_dss_device *dssdev, int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003089{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303090 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003091 u8 nullpkg[] = {0, 0, 0, 0};
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303092
Archit Taneja7a7c48f2011-08-25 18:25:03 +05303093 return dsi_vc_send_long(dsidev, channel, MIPI_DSI_NULL_PACKET, nullpkg,
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303094 4, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003095}
3096EXPORT_SYMBOL(dsi_vc_send_null);
3097
Archit Taneja1ffefe72011-05-12 17:26:24 +05303098int dsi_vc_dcs_write_nosync(struct omap_dss_device *dssdev, int channel,
3099 u8 *data, int len)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003100{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303101 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003102 int r;
3103
3104 BUG_ON(len == 0);
3105
3106 if (len == 1) {
Archit Taneja7a7c48f2011-08-25 18:25:03 +05303107 r = dsi_vc_send_short(dsidev, channel,
3108 MIPI_DSI_DCS_SHORT_WRITE, data[0], 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003109 } else if (len == 2) {
Archit Taneja7a7c48f2011-08-25 18:25:03 +05303110 r = dsi_vc_send_short(dsidev, channel,
3111 MIPI_DSI_DCS_SHORT_WRITE_PARAM,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003112 data[0] | (data[1] << 8), 0);
3113 } else {
3114 /* 0x39 = DCS Long Write */
Archit Taneja7a7c48f2011-08-25 18:25:03 +05303115 r = dsi_vc_send_long(dsidev, channel, MIPI_DSI_DCS_LONG_WRITE,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003116 data, len, 0);
3117 }
3118
3119 return r;
3120}
3121EXPORT_SYMBOL(dsi_vc_dcs_write_nosync);
3122
Archit Taneja1ffefe72011-05-12 17:26:24 +05303123int dsi_vc_dcs_write(struct omap_dss_device *dssdev, int channel, u8 *data,
3124 int len)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003125{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303126 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003127 int r;
3128
Archit Taneja1ffefe72011-05-12 17:26:24 +05303129 r = dsi_vc_dcs_write_nosync(dssdev, channel, data, len);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003130 if (r)
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003131 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003132
Archit Taneja1ffefe72011-05-12 17:26:24 +05303133 r = dsi_vc_send_bta_sync(dssdev, channel);
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003134 if (r)
3135 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003136
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303137 /* RX_FIFO_NOT_EMPTY */
3138 if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
Tomi Valkeinenb63ac1e2010-04-09 13:20:57 +03003139 DSSERR("rx fifo not empty after write, dumping data:\n");
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303140 dsi_vc_flush_receive_data(dsidev, channel);
Tomi Valkeinenb63ac1e2010-04-09 13:20:57 +03003141 r = -EIO;
3142 goto err;
3143 }
3144
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003145 return 0;
3146err:
3147 DSSERR("dsi_vc_dcs_write(ch %d, cmd 0x%02x, len %d) failed\n",
3148 channel, data[0], len);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003149 return r;
3150}
3151EXPORT_SYMBOL(dsi_vc_dcs_write);
3152
Archit Taneja1ffefe72011-05-12 17:26:24 +05303153int dsi_vc_dcs_write_0(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd)
Tomi Valkeinen828c48f2009-12-16 14:53:15 +02003154{
Archit Taneja1ffefe72011-05-12 17:26:24 +05303155 return dsi_vc_dcs_write(dssdev, channel, &dcs_cmd, 1);
Tomi Valkeinen828c48f2009-12-16 14:53:15 +02003156}
3157EXPORT_SYMBOL(dsi_vc_dcs_write_0);
3158
Archit Taneja1ffefe72011-05-12 17:26:24 +05303159int dsi_vc_dcs_write_1(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
3160 u8 param)
Tomi Valkeinen828c48f2009-12-16 14:53:15 +02003161{
3162 u8 buf[2];
3163 buf[0] = dcs_cmd;
3164 buf[1] = param;
Archit Taneja1ffefe72011-05-12 17:26:24 +05303165 return dsi_vc_dcs_write(dssdev, channel, buf, 2);
Tomi Valkeinen828c48f2009-12-16 14:53:15 +02003166}
3167EXPORT_SYMBOL(dsi_vc_dcs_write_1);
3168
Archit Taneja1ffefe72011-05-12 17:26:24 +05303169int dsi_vc_dcs_read(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
3170 u8 *buf, int buflen)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003171{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303172 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303173 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003174 u32 val;
3175 u8 dt;
3176 int r;
3177
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303178 if (dsi->debug_read)
Tomi Valkeinenff90a342009-12-03 13:38:04 +02003179 DSSDBG("dsi_vc_dcs_read(ch%d, dcs_cmd %x)\n", channel, dcs_cmd);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003180
Archit Taneja7a7c48f2011-08-25 18:25:03 +05303181 r = dsi_vc_send_short(dsidev, channel, MIPI_DSI_DCS_READ, dcs_cmd, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003182 if (r)
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003183 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003184
Archit Taneja1ffefe72011-05-12 17:26:24 +05303185 r = dsi_vc_send_bta_sync(dssdev, channel);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003186 if (r)
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003187 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003188
3189 /* RX_FIFO_NOT_EMPTY */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303190 if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20) == 0) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003191 DSSERR("RX fifo empty when trying to read.\n");
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003192 r = -EIO;
3193 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003194 }
3195
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303196 val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel));
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303197 if (dsi->debug_read)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003198 DSSDBG("\theader: %08x\n", val);
3199 dt = FLD_GET(val, 5, 0);
Archit Taneja7a7c48f2011-08-25 18:25:03 +05303200 if (dt == MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003201 u16 err = FLD_GET(val, 23, 8);
3202 dsi_show_rx_ack_with_err(err);
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003203 r = -EIO;
3204 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003205
Archit Taneja7a7c48f2011-08-25 18:25:03 +05303206 } else if (dt == MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003207 u8 data = FLD_GET(val, 15, 8);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303208 if (dsi->debug_read)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003209 DSSDBG("\tDCS short response, 1 byte: %02x\n", data);
3210
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003211 if (buflen < 1) {
3212 r = -EIO;
3213 goto err;
3214 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003215
3216 buf[0] = data;
3217
3218 return 1;
Archit Taneja7a7c48f2011-08-25 18:25:03 +05303219 } else if (dt == MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003220 u16 data = FLD_GET(val, 23, 8);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303221 if (dsi->debug_read)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003222 DSSDBG("\tDCS short response, 2 byte: %04x\n", data);
3223
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003224 if (buflen < 2) {
3225 r = -EIO;
3226 goto err;
3227 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003228
3229 buf[0] = data & 0xff;
3230 buf[1] = (data >> 8) & 0xff;
3231
3232 return 2;
Archit Taneja7a7c48f2011-08-25 18:25:03 +05303233 } else if (dt == MIPI_DSI_RX_DCS_LONG_READ_RESPONSE) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003234 int w;
3235 int len = FLD_GET(val, 23, 8);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303236 if (dsi->debug_read)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003237 DSSDBG("\tDCS long response, len %d\n", len);
3238
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003239 if (len > buflen) {
3240 r = -EIO;
3241 goto err;
3242 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003243
3244 /* two byte checksum ends the packet, not included in len */
3245 for (w = 0; w < len + 2;) {
3246 int b;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303247 val = dsi_read_reg(dsidev,
3248 DSI_VC_SHORT_PACKET_HEADER(channel));
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303249 if (dsi->debug_read)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003250 DSSDBG("\t\t%02x %02x %02x %02x\n",
3251 (val >> 0) & 0xff,
3252 (val >> 8) & 0xff,
3253 (val >> 16) & 0xff,
3254 (val >> 24) & 0xff);
3255
3256 for (b = 0; b < 4; ++b) {
3257 if (w < len)
3258 buf[w] = (val >> (b * 8)) & 0xff;
3259 /* we discard the 2 byte checksum */
3260 ++w;
3261 }
3262 }
3263
3264 return len;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003265 } else {
3266 DSSERR("\tunknown datatype 0x%02x\n", dt);
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003267 r = -EIO;
3268 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003269 }
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003270
3271 BUG();
3272err:
3273 DSSERR("dsi_vc_dcs_read(ch %d, cmd 0x%02x) failed\n",
3274 channel, dcs_cmd);
3275 return r;
3276
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003277}
3278EXPORT_SYMBOL(dsi_vc_dcs_read);
3279
Archit Taneja1ffefe72011-05-12 17:26:24 +05303280int dsi_vc_dcs_read_1(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
3281 u8 *data)
Tomi Valkeinen828c48f2009-12-16 14:53:15 +02003282{
3283 int r;
3284
Archit Taneja1ffefe72011-05-12 17:26:24 +05303285 r = dsi_vc_dcs_read(dssdev, channel, dcs_cmd, data, 1);
Tomi Valkeinen828c48f2009-12-16 14:53:15 +02003286
3287 if (r < 0)
3288 return r;
3289
3290 if (r != 1)
3291 return -EIO;
3292
3293 return 0;
3294}
3295EXPORT_SYMBOL(dsi_vc_dcs_read_1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003296
Archit Taneja1ffefe72011-05-12 17:26:24 +05303297int dsi_vc_dcs_read_2(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
3298 u8 *data1, u8 *data2)
Tomi Valkeinen53055aa2010-02-25 11:38:13 +02003299{
Tomi Valkeinen0c244f72010-06-09 15:19:29 +03003300 u8 buf[2];
Tomi Valkeinen53055aa2010-02-25 11:38:13 +02003301 int r;
3302
Archit Taneja1ffefe72011-05-12 17:26:24 +05303303 r = dsi_vc_dcs_read(dssdev, channel, dcs_cmd, buf, 2);
Tomi Valkeinen53055aa2010-02-25 11:38:13 +02003304
3305 if (r < 0)
3306 return r;
3307
3308 if (r != 2)
3309 return -EIO;
3310
Tomi Valkeinen0c244f72010-06-09 15:19:29 +03003311 *data1 = buf[0];
3312 *data2 = buf[1];
3313
Tomi Valkeinen53055aa2010-02-25 11:38:13 +02003314 return 0;
3315}
3316EXPORT_SYMBOL(dsi_vc_dcs_read_2);
3317
Archit Taneja1ffefe72011-05-12 17:26:24 +05303318int dsi_vc_set_max_rx_packet_size(struct omap_dss_device *dssdev, int channel,
3319 u16 len)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003320{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303321 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
3322
Archit Taneja7a7c48f2011-08-25 18:25:03 +05303323 return dsi_vc_send_short(dsidev, channel,
3324 MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE, len, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003325}
3326EXPORT_SYMBOL(dsi_vc_set_max_rx_packet_size);
3327
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303328static int dsi_enter_ulps(struct platform_device *dsidev)
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003329{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303330 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003331 DECLARE_COMPLETION_ONSTACK(completion);
3332 int r;
3333
3334 DSSDBGF();
3335
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303336 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003337
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303338 WARN_ON(dsi->ulps_enabled);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003339
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303340 if (dsi->ulps_enabled)
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003341 return 0;
3342
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303343 if (REG_GET(dsidev, DSI_CLK_CTRL, 13, 13)) {
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003344 DSSERR("DDR_CLK_ALWAYS_ON enabled when entering ULPS\n");
3345 return -EIO;
3346 }
3347
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303348 dsi_sync_vc(dsidev, 0);
3349 dsi_sync_vc(dsidev, 1);
3350 dsi_sync_vc(dsidev, 2);
3351 dsi_sync_vc(dsidev, 3);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003352
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303353 dsi_force_tx_stop_mode_io(dsidev);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003354
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303355 dsi_vc_enable(dsidev, 0, false);
3356 dsi_vc_enable(dsidev, 1, false);
3357 dsi_vc_enable(dsidev, 2, false);
3358 dsi_vc_enable(dsidev, 3, false);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003359
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303360 if (REG_GET(dsidev, DSI_COMPLEXIO_CFG2, 16, 16)) { /* HS_BUSY */
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003361 DSSERR("HS busy when enabling ULPS\n");
3362 return -EIO;
3363 }
3364
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303365 if (REG_GET(dsidev, DSI_COMPLEXIO_CFG2, 17, 17)) { /* LP_BUSY */
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003366 DSSERR("LP busy when enabling ULPS\n");
3367 return -EIO;
3368 }
3369
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303370 r = dsi_register_isr_cio(dsidev, dsi_completion_handler, &completion,
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003371 DSI_CIO_IRQ_ULPSACTIVENOT_ALL0);
3372 if (r)
3373 return r;
3374
3375 /* Assert TxRequestEsc for data lanes and TxUlpsClk for clk lane */
3376 /* LANEx_ULPS_SIG2 */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303377 REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG2, (1 << 0) | (1 << 1) | (1 << 2),
3378 7, 5);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003379
3380 if (wait_for_completion_timeout(&completion,
3381 msecs_to_jiffies(1000)) == 0) {
3382 DSSERR("ULPS enable timeout\n");
3383 r = -EIO;
3384 goto err;
3385 }
3386
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303387 dsi_unregister_isr_cio(dsidev, dsi_completion_handler, &completion,
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003388 DSI_CIO_IRQ_ULPSACTIVENOT_ALL0);
3389
Tomi Valkeinen8ef0e612011-05-31 16:55:47 +03003390 /* Reset LANEx_ULPS_SIG2 */
3391 REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG2, (0 << 0) | (0 << 1) | (0 << 2),
3392 7, 5);
3393
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303394 dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_ULPS);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003395
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303396 dsi_if_enable(dsidev, false);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003397
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303398 dsi->ulps_enabled = true;
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003399
3400 return 0;
3401
3402err:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303403 dsi_unregister_isr_cio(dsidev, dsi_completion_handler, &completion,
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003404 DSI_CIO_IRQ_ULPSACTIVENOT_ALL0);
3405 return r;
3406}
3407
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303408static void dsi_set_lp_rx_timeout(struct platform_device *dsidev,
3409 unsigned ticks, bool x4, bool x16)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003410{
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003411 unsigned long fck;
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003412 unsigned long total_ticks;
3413 u32 r;
3414
3415 BUG_ON(ticks > 0x1fff);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003416
3417 /* ticks in DSI_FCK */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303418 fck = dsi_fclk_rate(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003419
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303420 r = dsi_read_reg(dsidev, DSI_TIMING2);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003421 r = FLD_MOD(r, 1, 15, 15); /* LP_RX_TO */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003422 r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* LP_RX_TO_X16 */
3423 r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* LP_RX_TO_X4 */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003424 r = FLD_MOD(r, ticks, 12, 0); /* LP_RX_COUNTER */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303425 dsi_write_reg(dsidev, DSI_TIMING2, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003426
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003427 total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
3428
3429 DSSDBG("LP_RX_TO %lu ticks (%#x%s%s) = %lu ns\n",
3430 total_ticks,
3431 ticks, x4 ? " x4" : "", x16 ? " x16" : "",
3432 (total_ticks * 1000) / (fck / 1000 / 1000));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003433}
3434
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303435static void dsi_set_ta_timeout(struct platform_device *dsidev, unsigned ticks,
3436 bool x8, bool x16)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003437{
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003438 unsigned long fck;
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003439 unsigned long total_ticks;
3440 u32 r;
3441
3442 BUG_ON(ticks > 0x1fff);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003443
3444 /* ticks in DSI_FCK */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303445 fck = dsi_fclk_rate(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003446
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303447 r = dsi_read_reg(dsidev, DSI_TIMING1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003448 r = FLD_MOD(r, 1, 31, 31); /* TA_TO */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003449 r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* TA_TO_X16 */
3450 r = FLD_MOD(r, x8 ? 1 : 0, 29, 29); /* TA_TO_X8 */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003451 r = FLD_MOD(r, ticks, 28, 16); /* TA_TO_COUNTER */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303452 dsi_write_reg(dsidev, DSI_TIMING1, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003453
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003454 total_ticks = ticks * (x16 ? 16 : 1) * (x8 ? 8 : 1);
3455
3456 DSSDBG("TA_TO %lu ticks (%#x%s%s) = %lu ns\n",
3457 total_ticks,
3458 ticks, x8 ? " x8" : "", x16 ? " x16" : "",
3459 (total_ticks * 1000) / (fck / 1000 / 1000));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003460}
3461
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303462static void dsi_set_stop_state_counter(struct platform_device *dsidev,
3463 unsigned ticks, bool x4, bool x16)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003464{
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003465 unsigned long fck;
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003466 unsigned long total_ticks;
3467 u32 r;
3468
3469 BUG_ON(ticks > 0x1fff);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003470
3471 /* ticks in DSI_FCK */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303472 fck = dsi_fclk_rate(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003473
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303474 r = dsi_read_reg(dsidev, DSI_TIMING1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003475 r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003476 r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* STOP_STATE_X16_IO */
3477 r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* STOP_STATE_X4_IO */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003478 r = FLD_MOD(r, ticks, 12, 0); /* STOP_STATE_COUNTER_IO */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303479 dsi_write_reg(dsidev, DSI_TIMING1, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003480
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003481 total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
3482
3483 DSSDBG("STOP_STATE_COUNTER %lu ticks (%#x%s%s) = %lu ns\n",
3484 total_ticks,
3485 ticks, x4 ? " x4" : "", x16 ? " x16" : "",
3486 (total_ticks * 1000) / (fck / 1000 / 1000));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003487}
3488
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303489static void dsi_set_hs_tx_timeout(struct platform_device *dsidev,
3490 unsigned ticks, bool x4, bool x16)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003491{
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003492 unsigned long fck;
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003493 unsigned long total_ticks;
3494 u32 r;
3495
3496 BUG_ON(ticks > 0x1fff);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003497
3498 /* ticks in TxByteClkHS */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303499 fck = dsi_get_txbyteclkhs(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003500
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303501 r = dsi_read_reg(dsidev, DSI_TIMING2);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003502 r = FLD_MOD(r, 1, 31, 31); /* HS_TX_TO */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003503 r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* HS_TX_TO_X16 */
3504 r = FLD_MOD(r, x4 ? 1 : 0, 29, 29); /* HS_TX_TO_X8 (4 really) */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003505 r = FLD_MOD(r, ticks, 28, 16); /* HS_TX_TO_COUNTER */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303506 dsi_write_reg(dsidev, DSI_TIMING2, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003507
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003508 total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
3509
3510 DSSDBG("HS_TX_TO %lu ticks (%#x%s%s) = %lu ns\n",
3511 total_ticks,
3512 ticks, x4 ? " x4" : "", x16 ? " x16" : "",
3513 (total_ticks * 1000) / (fck / 1000 / 1000));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003514}
3515static int dsi_proto_config(struct omap_dss_device *dssdev)
3516{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303517 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003518 u32 r;
3519 int buswidth = 0;
3520
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303521 dsi_config_tx_fifo(dsidev, DSI_FIFO_SIZE_32,
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02003522 DSI_FIFO_SIZE_32,
3523 DSI_FIFO_SIZE_32,
3524 DSI_FIFO_SIZE_32);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003525
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303526 dsi_config_rx_fifo(dsidev, DSI_FIFO_SIZE_32,
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02003527 DSI_FIFO_SIZE_32,
3528 DSI_FIFO_SIZE_32,
3529 DSI_FIFO_SIZE_32);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003530
3531 /* XXX what values for the timeouts? */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303532 dsi_set_stop_state_counter(dsidev, 0x1000, false, false);
3533 dsi_set_ta_timeout(dsidev, 0x1fff, true, true);
3534 dsi_set_lp_rx_timeout(dsidev, 0x1fff, true, true);
3535 dsi_set_hs_tx_timeout(dsidev, 0x1fff, true, true);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003536
3537 switch (dssdev->ctrl.pixel_size) {
3538 case 16:
3539 buswidth = 0;
3540 break;
3541 case 18:
3542 buswidth = 1;
3543 break;
3544 case 24:
3545 buswidth = 2;
3546 break;
3547 default:
3548 BUG();
3549 }
3550
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303551 r = dsi_read_reg(dsidev, DSI_CTRL);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003552 r = FLD_MOD(r, 1, 1, 1); /* CS_RX_EN */
3553 r = FLD_MOD(r, 1, 2, 2); /* ECC_RX_EN */
3554 r = FLD_MOD(r, 1, 3, 3); /* TX_FIFO_ARBITRATION */
3555 r = FLD_MOD(r, 1, 4, 4); /* VP_CLK_RATIO, always 1, see errata*/
3556 r = FLD_MOD(r, buswidth, 7, 6); /* VP_DATA_BUS_WIDTH */
3557 r = FLD_MOD(r, 0, 8, 8); /* VP_CLK_POL */
3558 r = FLD_MOD(r, 2, 13, 12); /* LINE_BUFFER, 2 lines */
3559 r = FLD_MOD(r, 1, 14, 14); /* TRIGGER_RESET_MODE */
3560 r = FLD_MOD(r, 1, 19, 19); /* EOT_ENABLE */
Archit Taneja9613c022011-03-22 06:33:36 -05003561 if (!dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC)) {
3562 r = FLD_MOD(r, 1, 24, 24); /* DCS_CMD_ENABLE */
3563 /* DCS_CMD_CODE, 1=start, 0=continue */
3564 r = FLD_MOD(r, 0, 25, 25);
3565 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003566
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303567 dsi_write_reg(dsidev, DSI_CTRL, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003568
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303569 dsi_vc_initial_config(dsidev, 0);
3570 dsi_vc_initial_config(dsidev, 1);
3571 dsi_vc_initial_config(dsidev, 2);
3572 dsi_vc_initial_config(dsidev, 3);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003573
3574 return 0;
3575}
3576
3577static void dsi_proto_timings(struct omap_dss_device *dssdev)
3578{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303579 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003580 unsigned tlpx, tclk_zero, tclk_prepare, tclk_trail;
3581 unsigned tclk_pre, tclk_post;
3582 unsigned ths_prepare, ths_prepare_ths_zero, ths_zero;
3583 unsigned ths_trail, ths_exit;
3584 unsigned ddr_clk_pre, ddr_clk_post;
3585 unsigned enter_hs_mode_lat, exit_hs_mode_lat;
3586 unsigned ths_eot;
3587 u32 r;
3588
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303589 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003590 ths_prepare = FLD_GET(r, 31, 24);
3591 ths_prepare_ths_zero = FLD_GET(r, 23, 16);
3592 ths_zero = ths_prepare_ths_zero - ths_prepare;
3593 ths_trail = FLD_GET(r, 15, 8);
3594 ths_exit = FLD_GET(r, 7, 0);
3595
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303596 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003597 tlpx = FLD_GET(r, 22, 16) * 2;
3598 tclk_trail = FLD_GET(r, 15, 8);
3599 tclk_zero = FLD_GET(r, 7, 0);
3600
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303601 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG2);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003602 tclk_prepare = FLD_GET(r, 7, 0);
3603
3604 /* min 8*UI */
3605 tclk_pre = 20;
3606 /* min 60ns + 52*UI */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303607 tclk_post = ns2ddr(dsidev, 60) + 26;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003608
Archit Taneja75d72472011-05-16 15:17:08 +05303609 ths_eot = DIV_ROUND_UP(4, dsi_get_num_data_lanes_dssdev(dssdev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003610
3611 ddr_clk_pre = DIV_ROUND_UP(tclk_pre + tlpx + tclk_zero + tclk_prepare,
3612 4);
3613 ddr_clk_post = DIV_ROUND_UP(tclk_post + ths_trail, 4) + ths_eot;
3614
3615 BUG_ON(ddr_clk_pre == 0 || ddr_clk_pre > 255);
3616 BUG_ON(ddr_clk_post == 0 || ddr_clk_post > 255);
3617
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303618 r = dsi_read_reg(dsidev, DSI_CLK_TIMING);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003619 r = FLD_MOD(r, ddr_clk_pre, 15, 8);
3620 r = FLD_MOD(r, ddr_clk_post, 7, 0);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303621 dsi_write_reg(dsidev, DSI_CLK_TIMING, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003622
3623 DSSDBG("ddr_clk_pre %u, ddr_clk_post %u\n",
3624 ddr_clk_pre,
3625 ddr_clk_post);
3626
3627 enter_hs_mode_lat = 1 + DIV_ROUND_UP(tlpx, 4) +
3628 DIV_ROUND_UP(ths_prepare, 4) +
3629 DIV_ROUND_UP(ths_zero + 3, 4);
3630
3631 exit_hs_mode_lat = DIV_ROUND_UP(ths_trail + ths_exit, 4) + 1 + ths_eot;
3632
3633 r = FLD_VAL(enter_hs_mode_lat, 31, 16) |
3634 FLD_VAL(exit_hs_mode_lat, 15, 0);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303635 dsi_write_reg(dsidev, DSI_VM_TIMING7, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003636
3637 DSSDBG("enter_hs_mode_lat %u, exit_hs_mode_lat %u\n",
3638 enter_hs_mode_lat, exit_hs_mode_lat);
3639}
3640
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003641static void dsi_update_screen_dispc(struct omap_dss_device *dssdev,
3642 u16 x, u16 y, u16 w, u16 h)
3643{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303644 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303645 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003646 unsigned bytespp;
3647 unsigned bytespl;
3648 unsigned bytespf;
3649 unsigned total_len;
3650 unsigned packet_payload;
3651 unsigned packet_len;
3652 u32 l;
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03003653 int r;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303654 const unsigned channel = dsi->update_channel;
Archit Taneja0c656222011-05-16 15:17:09 +05303655 const unsigned line_buf_size = dsi_get_line_buf_size(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003656
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +02003657 DSSDBG("dsi_update_screen_dispc(%d,%d %dx%d)\n",
3658 x, y, w, h);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003659
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303660 dsi_vc_config_vp(dsidev, channel);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02003661
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003662 bytespp = dssdev->ctrl.pixel_size / 8;
3663 bytespl = w * bytespp;
3664 bytespf = bytespl * h;
3665
3666 /* NOTE: packet_payload has to be equal to N * bytespl, where N is
3667 * number of lines in a packet. See errata about VP_CLK_RATIO */
3668
3669 if (bytespf < line_buf_size)
3670 packet_payload = bytespf;
3671 else
3672 packet_payload = (line_buf_size) / bytespl * bytespl;
3673
3674 packet_len = packet_payload + 1; /* 1 byte for DCS cmd */
3675 total_len = (bytespf / packet_payload) * packet_len;
3676
3677 if (bytespf % packet_payload)
3678 total_len += (bytespf % packet_payload) + 1;
3679
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003680 l = FLD_VAL(total_len, 23, 0); /* TE_SIZE */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303681 dsi_write_reg(dsidev, DSI_VC_TE(channel), l);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003682
Archit Taneja7a7c48f2011-08-25 18:25:03 +05303683 dsi_vc_write_long_header(dsidev, channel, MIPI_DSI_DCS_LONG_WRITE,
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303684 packet_len, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003685
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303686 if (dsi->te_enabled)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003687 l = FLD_MOD(l, 1, 30, 30); /* TE_EN */
3688 else
3689 l = FLD_MOD(l, 1, 31, 31); /* TE_START */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303690 dsi_write_reg(dsidev, DSI_VC_TE(channel), l);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003691
3692 /* We put SIDLEMODE to no-idle for the duration of the transfer,
3693 * because DSS interrupts are not capable of waking up the CPU and the
3694 * framedone interrupt could be delayed for quite a long time. I think
3695 * the same goes for any DSS interrupts, but for some reason I have not
3696 * seen the problem anywhere else than here.
3697 */
3698 dispc_disable_sidle();
3699
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303700 dsi_perf_mark_start(dsidev);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02003701
Archit Taneja49dbf582011-05-16 15:17:07 +05303702 r = schedule_delayed_work(&dsi->framedone_timeout_work,
3703 msecs_to_jiffies(250));
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03003704 BUG_ON(r == 0);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02003705
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003706 dss_start_update(dssdev);
3707
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303708 if (dsi->te_enabled) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003709 /* disable LP_RX_TO, so that we can receive TE. Time to wait
3710 * for TE is longer than the timer allows */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303711 REG_FLD_MOD(dsidev, DSI_TIMING2, 0, 15, 15); /* LP_RX_TO */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003712
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303713 dsi_vc_send_bta(dsidev, channel);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003714
3715#ifdef DSI_CATCH_MISSING_TE
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303716 mod_timer(&dsi->te_timer, jiffies + msecs_to_jiffies(250));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003717#endif
3718 }
3719}
3720
3721#ifdef DSI_CATCH_MISSING_TE
3722static void dsi_te_timeout(unsigned long arg)
3723{
3724 DSSERR("TE not received for 250ms!\n");
3725}
3726#endif
3727
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303728static void dsi_handle_framedone(struct platform_device *dsidev, int error)
Tomi Valkeinen18946f62010-01-12 14:16:41 +02003729{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303730 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
3731
Tomi Valkeinenab83b142010-06-09 15:31:01 +03003732 /* SIDLEMODE back to smart-idle */
3733 dispc_enable_sidle();
3734
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303735 if (dsi->te_enabled) {
Tomi Valkeinenab83b142010-06-09 15:31:01 +03003736 /* enable LP_RX_TO again after the TE */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303737 REG_FLD_MOD(dsidev, DSI_TIMING2, 1, 15, 15); /* LP_RX_TO */
Tomi Valkeinenab83b142010-06-09 15:31:01 +03003738 }
3739
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303740 dsi->framedone_callback(error, dsi->framedone_data);
Tomi Valkeinenab83b142010-06-09 15:31:01 +03003741
3742 if (!error)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303743 dsi_perf_show(dsidev, "DISPC");
Tomi Valkeinenab83b142010-06-09 15:31:01 +03003744}
3745
3746static void dsi_framedone_timeout_work_callback(struct work_struct *work)
3747{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303748 struct dsi_data *dsi = container_of(work, struct dsi_data,
3749 framedone_timeout_work.work);
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03003750 /* XXX While extremely unlikely, we could get FRAMEDONE interrupt after
3751 * 250ms which would conflict with this timeout work. What should be
3752 * done is first cancel the transfer on the HW, and then cancel the
Tomi Valkeinenab83b142010-06-09 15:31:01 +03003753 * possibly scheduled framedone work. However, cancelling the transfer
3754 * on the HW is buggy, and would probably require resetting the whole
3755 * DSI */
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03003756
Tomi Valkeinenab83b142010-06-09 15:31:01 +03003757 DSSERR("Framedone not received for 250ms!\n");
Tomi Valkeinen18946f62010-01-12 14:16:41 +02003758
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303759 dsi_handle_framedone(dsi->pdev, -ETIMEDOUT);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02003760}
3761
Tomi Valkeinenab83b142010-06-09 15:31:01 +03003762static void dsi_framedone_irq_callback(void *data, u32 mask)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003763{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303764 struct omap_dss_device *dssdev = (struct omap_dss_device *) data;
3765 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303766 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
3767
Tomi Valkeinenab83b142010-06-09 15:31:01 +03003768 /* Note: We get FRAMEDONE when DISPC has finished sending pixels and
3769 * turns itself off. However, DSI still has the pixels in its buffers,
3770 * and is sending the data.
3771 */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003772
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303773 __cancel_delayed_work(&dsi->framedone_timeout_work);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003774
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303775 dsi_handle_framedone(dsidev, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003776
Archit Tanejacf398fb2011-03-23 09:59:34 +00003777#ifdef CONFIG_OMAP2_DSS_FAKE_VSYNC
3778 dispc_fake_vsync_irq();
3779#endif
Tomi Valkeinen18946f62010-01-12 14:16:41 +02003780}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003781
Tomi Valkeinen18946f62010-01-12 14:16:41 +02003782int omap_dsi_prepare_update(struct omap_dss_device *dssdev,
Tomi Valkeinen26a8c252010-06-09 15:31:34 +03003783 u16 *x, u16 *y, u16 *w, u16 *h,
3784 bool enlarge_update_area)
Tomi Valkeinen18946f62010-01-12 14:16:41 +02003785{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303786 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02003787 u16 dw, dh;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003788
Tomi Valkeinen18946f62010-01-12 14:16:41 +02003789 dssdev->driver->get_resolution(dssdev, &dw, &dh);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003790
Tomi Valkeinen18946f62010-01-12 14:16:41 +02003791 if (*x > dw || *y > dh)
3792 return -EINVAL;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003793
Tomi Valkeinen18946f62010-01-12 14:16:41 +02003794 if (*x + *w > dw)
3795 return -EINVAL;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003796
Tomi Valkeinen18946f62010-01-12 14:16:41 +02003797 if (*y + *h > dh)
3798 return -EINVAL;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003799
Tomi Valkeinen18946f62010-01-12 14:16:41 +02003800 if (*w == 1)
3801 return -EINVAL;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003802
Tomi Valkeinen18946f62010-01-12 14:16:41 +02003803 if (*w == 0 || *h == 0)
3804 return -EINVAL;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003805
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303806 dsi_perf_mark_setup(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003807
Tomi Valkeinen4a9e78a2011-08-15 11:22:21 +03003808 dss_setup_partial_planes(dssdev, x, y, w, h,
3809 enlarge_update_area);
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003810 dispc_mgr_set_lcd_size(dssdev->manager->id, *w, *h);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003811
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003812 return 0;
3813}
Tomi Valkeinen18946f62010-01-12 14:16:41 +02003814EXPORT_SYMBOL(omap_dsi_prepare_update);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003815
Tomi Valkeinen18946f62010-01-12 14:16:41 +02003816int omap_dsi_update(struct omap_dss_device *dssdev,
3817 int channel,
3818 u16 x, u16 y, u16 w, u16 h,
3819 void (*callback)(int, void *), void *data)
3820{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303821 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303822 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303823
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303824 dsi->update_channel = channel;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003825
Tomi Valkeinena6027712010-05-25 17:01:28 +03003826 /* OMAP DSS cannot send updates of odd widths.
3827 * omap_dsi_prepare_update() makes the widths even, but add a BUG_ON
3828 * here to make sure we catch erroneous updates. Otherwise we'll only
3829 * see rather obscure HW error happening, as DSS halts. */
3830 BUG_ON(x % 2 == 1);
3831
Tomi Valkeinen4a9e78a2011-08-15 11:22:21 +03003832 dsi->framedone_callback = callback;
3833 dsi->framedone_data = data;
Tomi Valkeinen18946f62010-01-12 14:16:41 +02003834
Tomi Valkeinen4a9e78a2011-08-15 11:22:21 +03003835 dsi->update_region.x = x;
3836 dsi->update_region.y = y;
3837 dsi->update_region.w = w;
3838 dsi->update_region.h = h;
3839 dsi->update_region.device = dssdev;
Tomi Valkeinen18946f62010-01-12 14:16:41 +02003840
Tomi Valkeinen4a9e78a2011-08-15 11:22:21 +03003841 dsi_update_screen_dispc(dssdev, x, y, w, h);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02003842
3843 return 0;
3844}
3845EXPORT_SYMBOL(omap_dsi_update);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003846
3847/* Display funcs */
3848
3849static int dsi_display_init_dispc(struct omap_dss_device *dssdev)
3850{
3851 int r;
Archit Taneja5a8b5722011-05-12 17:26:29 +05303852 u32 irq;
3853
3854 irq = dssdev->manager->id == OMAP_DSS_CHANNEL_LCD ?
3855 DISPC_IRQ_FRAMEDONE : DISPC_IRQ_FRAMEDONE2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003856
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303857 r = omap_dispc_register_isr(dsi_framedone_irq_callback, (void *) dssdev,
Archit Taneja5a8b5722011-05-12 17:26:29 +05303858 irq);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003859 if (r) {
3860 DSSERR("can't get FRAMEDONE irq\n");
3861 return r;
3862 }
3863
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003864 dispc_mgr_set_lcd_display_type(dssdev->manager->id,
Sumit Semwal64ba4f72010-12-02 11:27:10 +00003865 OMAP_DSS_LCD_DISPLAY_TFT);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003866
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003867 dispc_mgr_set_parallel_interface_mode(dssdev->manager->id,
Sumit Semwal64ba4f72010-12-02 11:27:10 +00003868 OMAP_DSS_PARALLELMODE_DSI);
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003869 dispc_mgr_enable_fifohandcheck(dssdev->manager->id, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003870
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003871 dispc_mgr_set_tft_data_lines(dssdev->manager->id,
3872 dssdev->ctrl.pixel_size);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003873
3874 {
3875 struct omap_video_timings timings = {
3876 .hsw = 1,
3877 .hfp = 1,
3878 .hbp = 1,
3879 .vsw = 1,
3880 .vfp = 0,
3881 .vbp = 0,
3882 };
3883
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003884 dispc_mgr_set_lcd_timings(dssdev->manager->id, &timings);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003885 }
3886
3887 return 0;
3888}
3889
3890static void dsi_display_uninit_dispc(struct omap_dss_device *dssdev)
3891{
Archit Taneja5a8b5722011-05-12 17:26:29 +05303892 u32 irq;
3893
3894 irq = dssdev->manager->id == OMAP_DSS_CHANNEL_LCD ?
3895 DISPC_IRQ_FRAMEDONE : DISPC_IRQ_FRAMEDONE2;
3896
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303897 omap_dispc_unregister_isr(dsi_framedone_irq_callback, (void *) dssdev,
Archit Taneja5a8b5722011-05-12 17:26:29 +05303898 irq);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003899}
3900
3901static int dsi_configure_dsi_clocks(struct omap_dss_device *dssdev)
3902{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303903 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003904 struct dsi_clock_info cinfo;
3905 int r;
3906
Archit Taneja1bb47832011-02-24 14:17:30 +05303907 /* we always use DSS_CLK_SYSCK as input clock */
3908 cinfo.use_sys_clk = true;
Tomi Valkeinenc6940a32011-02-22 13:36:10 +02003909 cinfo.regn = dssdev->clocks.dsi.regn;
3910 cinfo.regm = dssdev->clocks.dsi.regm;
3911 cinfo.regm_dispc = dssdev->clocks.dsi.regm_dispc;
3912 cinfo.regm_dsi = dssdev->clocks.dsi.regm_dsi;
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00003913 r = dsi_calc_clock_rates(dssdev, &cinfo);
Ville Syrjäläebf0a3f2010-04-22 22:50:05 +02003914 if (r) {
3915 DSSERR("Failed to calc dsi clocks\n");
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003916 return r;
Ville Syrjäläebf0a3f2010-04-22 22:50:05 +02003917 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003918
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303919 r = dsi_pll_set_clock_div(dsidev, &cinfo);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003920 if (r) {
3921 DSSERR("Failed to set dsi clocks\n");
3922 return r;
3923 }
3924
3925 return 0;
3926}
3927
3928static int dsi_configure_dispc_clocks(struct omap_dss_device *dssdev)
3929{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303930 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003931 struct dispc_clock_info dispc_cinfo;
3932 int r;
3933 unsigned long long fck;
3934
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303935 fck = dsi_get_pll_hsdiv_dispc_rate(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003936
Archit Tanejae8881662011-04-12 13:52:24 +05303937 dispc_cinfo.lck_div = dssdev->clocks.dispc.channel.lck_div;
3938 dispc_cinfo.pck_div = dssdev->clocks.dispc.channel.pck_div;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003939
3940 r = dispc_calc_clock_rates(fck, &dispc_cinfo);
3941 if (r) {
3942 DSSERR("Failed to calc dispc clocks\n");
3943 return r;
3944 }
3945
Tomi Valkeinen26d9dd02011-08-16 13:45:15 +03003946 r = dispc_mgr_set_clock_div(dssdev->manager->id, &dispc_cinfo);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003947 if (r) {
3948 DSSERR("Failed to set dispc clocks\n");
3949 return r;
3950 }
3951
3952 return 0;
3953}
3954
3955static int dsi_display_init_dsi(struct omap_dss_device *dssdev)
3956{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303957 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Taneja5a8b5722011-05-12 17:26:29 +05303958 int dsi_module = dsi_get_dsidev_id(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003959 int r;
3960
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303961 r = dsi_pll_init(dsidev, true, true);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003962 if (r)
3963 goto err0;
3964
3965 r = dsi_configure_dsi_clocks(dssdev);
3966 if (r)
3967 goto err1;
3968
Archit Tanejae8881662011-04-12 13:52:24 +05303969 dss_select_dispc_clk_source(dssdev->clocks.dispc.dispc_fclk_src);
Archit Taneja5a8b5722011-05-12 17:26:29 +05303970 dss_select_dsi_clk_source(dsi_module, dssdev->clocks.dsi.dsi_fclk_src);
Archit Taneja9613c022011-03-22 06:33:36 -05003971 dss_select_lcd_clk_source(dssdev->manager->id,
Archit Tanejae8881662011-04-12 13:52:24 +05303972 dssdev->clocks.dispc.channel.lcd_clk_src);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003973
3974 DSSDBG("PLL OK\n");
3975
3976 r = dsi_configure_dispc_clocks(dssdev);
3977 if (r)
3978 goto err2;
3979
Tomi Valkeinencc5c1852010-10-06 15:18:13 +03003980 r = dsi_cio_init(dssdev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003981 if (r)
3982 goto err2;
3983
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303984 _dsi_print_reset_status(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003985
3986 dsi_proto_timings(dssdev);
3987 dsi_set_lp_clk_divisor(dssdev);
3988
3989 if (1)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303990 _dsi_print_reset_status(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003991
3992 r = dsi_proto_config(dssdev);
3993 if (r)
3994 goto err3;
3995
3996 /* enable interface */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303997 dsi_vc_enable(dsidev, 0, 1);
3998 dsi_vc_enable(dsidev, 1, 1);
3999 dsi_vc_enable(dsidev, 2, 1);
4000 dsi_vc_enable(dsidev, 3, 1);
4001 dsi_if_enable(dsidev, 1);
4002 dsi_force_tx_stop_mode_io(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004003
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004004 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004005err3:
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03004006 dsi_cio_uninit(dssdev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004007err2:
Archit Taneja89a35e52011-04-12 13:52:23 +05304008 dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK);
Archit Taneja5a8b5722011-05-12 17:26:29 +05304009 dss_select_dsi_clk_source(dsi_module, OMAP_DSS_CLK_SRC_FCK);
Tomi Valkeinen5e785092011-08-10 11:25:36 +03004010 dss_select_lcd_clk_source(dssdev->manager->id, OMAP_DSS_CLK_SRC_FCK);
4011
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004012err1:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304013 dsi_pll_uninit(dsidev, true);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004014err0:
4015 return r;
4016}
4017
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +03004018static void dsi_display_uninit_dsi(struct omap_dss_device *dssdev,
Tomi Valkeinen22d6d672010-10-11 11:33:30 +03004019 bool disconnect_lanes, bool enter_ulps)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004020{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304021 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304022 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Taneja5a8b5722011-05-12 17:26:29 +05304023 int dsi_module = dsi_get_dsidev_id(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304024
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304025 if (enter_ulps && !dsi->ulps_enabled)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304026 dsi_enter_ulps(dsidev);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03004027
Ville Syrjäläd7370102010-04-22 22:50:09 +02004028 /* disable interface */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304029 dsi_if_enable(dsidev, 0);
4030 dsi_vc_enable(dsidev, 0, 0);
4031 dsi_vc_enable(dsidev, 1, 0);
4032 dsi_vc_enable(dsidev, 2, 0);
4033 dsi_vc_enable(dsidev, 3, 0);
Ville Syrjäläd7370102010-04-22 22:50:09 +02004034
Archit Taneja89a35e52011-04-12 13:52:23 +05304035 dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK);
Archit Taneja5a8b5722011-05-12 17:26:29 +05304036 dss_select_dsi_clk_source(dsi_module, OMAP_DSS_CLK_SRC_FCK);
Tomi Valkeinen5e785092011-08-10 11:25:36 +03004037 dss_select_lcd_clk_source(dssdev->manager->id, OMAP_DSS_CLK_SRC_FCK);
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03004038 dsi_cio_uninit(dssdev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304039 dsi_pll_uninit(dsidev, disconnect_lanes);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004040}
4041
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02004042int omapdss_dsi_display_enable(struct omap_dss_device *dssdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004043{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304044 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304045 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004046 int r = 0;
4047
4048 DSSDBG("dsi_display_enable\n");
4049
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304050 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02004051
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304052 mutex_lock(&dsi->lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004053
Tomi Valkeinen05e1d602011-06-23 16:38:21 +03004054 if (dssdev->manager == NULL) {
4055 DSSERR("failed to enable display: no manager\n");
4056 r = -ENODEV;
4057 goto err_start_dev;
4058 }
4059
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004060 r = omap_dss_start_device(dssdev);
4061 if (r) {
4062 DSSERR("failed to start device\n");
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004063 goto err_start_dev;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004064 }
4065
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004066 r = dsi_runtime_get(dsidev);
4067 if (r)
4068 goto err_get_dsi;
4069
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304070 dsi_enable_pll_clock(dsidev, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004071
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004072 _dsi_initialize_irq(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004073
4074 r = dsi_display_init_dispc(dssdev);
4075 if (r)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004076 goto err_init_dispc;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004077
4078 r = dsi_display_init_dsi(dssdev);
4079 if (r)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004080 goto err_init_dsi;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004081
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304082 mutex_unlock(&dsi->lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004083
4084 return 0;
4085
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004086err_init_dsi:
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02004087 dsi_display_uninit_dispc(dssdev);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004088err_init_dispc:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304089 dsi_enable_pll_clock(dsidev, 0);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004090 dsi_runtime_put(dsidev);
4091err_get_dsi:
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004092 omap_dss_stop_device(dssdev);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004093err_start_dev:
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304094 mutex_unlock(&dsi->lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004095 DSSDBG("dsi_display_enable FAILED\n");
4096 return r;
4097}
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02004098EXPORT_SYMBOL(omapdss_dsi_display_enable);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004099
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +03004100void omapdss_dsi_display_disable(struct omap_dss_device *dssdev,
Tomi Valkeinen22d6d672010-10-11 11:33:30 +03004101 bool disconnect_lanes, bool enter_ulps)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004102{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304103 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304104 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304105
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004106 DSSDBG("dsi_display_disable\n");
4107
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304108 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02004109
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304110 mutex_lock(&dsi->lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004111
Tomi Valkeinen15ffa1d2011-06-16 14:34:06 +03004112 dsi_sync_vc(dsidev, 0);
4113 dsi_sync_vc(dsidev, 1);
4114 dsi_sync_vc(dsidev, 2);
4115 dsi_sync_vc(dsidev, 3);
4116
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004117 dsi_display_uninit_dispc(dssdev);
4118
Tomi Valkeinen22d6d672010-10-11 11:33:30 +03004119 dsi_display_uninit_dsi(dssdev, disconnect_lanes, enter_ulps);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004120
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004121 dsi_runtime_put(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304122 dsi_enable_pll_clock(dsidev, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004123
4124 omap_dss_stop_device(dssdev);
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02004125
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304126 mutex_unlock(&dsi->lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004127}
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02004128EXPORT_SYMBOL(omapdss_dsi_display_disable);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004129
Tomi Valkeinen225b6502010-01-11 15:11:01 +02004130int omapdss_dsi_enable_te(struct omap_dss_device *dssdev, bool enable)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004131{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304132 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4133 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4134
4135 dsi->te_enabled = enable;
Tomi Valkeinen225b6502010-01-11 15:11:01 +02004136 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004137}
Tomi Valkeinen225b6502010-01-11 15:11:01 +02004138EXPORT_SYMBOL(omapdss_dsi_enable_te);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004139
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004140void dsi_get_overlay_fifo_thresholds(enum omap_plane plane,
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03004141 u32 fifo_size, u32 burst_size,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004142 u32 *fifo_low, u32 *fifo_high)
4143{
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +03004144 *fifo_high = fifo_size - burst_size;
4145 *fifo_low = fifo_size - burst_size * 2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004146}
4147
4148int dsi_init_display(struct omap_dss_device *dssdev)
4149{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304150 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4151 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Taneja75d72472011-05-16 15:17:08 +05304152 int dsi_module = dsi_get_dsidev_id(dsidev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304153
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004154 DSSDBG("DSI init\n");
4155
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004156 /* XXX these should be figured out dynamically */
4157 dssdev->caps = OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE |
4158 OMAP_DSS_DISPLAY_CAP_TEAR_ELIM;
4159
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304160 if (dsi->vdds_dsi_reg == NULL) {
Tomi Valkeinen5f42f2ce2011-02-22 15:53:46 +02004161 struct regulator *vdds_dsi;
4162
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304163 vdds_dsi = regulator_get(&dsi->pdev->dev, "vdds_dsi");
Tomi Valkeinen5f42f2ce2011-02-22 15:53:46 +02004164
4165 if (IS_ERR(vdds_dsi)) {
4166 DSSERR("can't get VDDS_DSI regulator\n");
4167 return PTR_ERR(vdds_dsi);
4168 }
4169
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304170 dsi->vdds_dsi_reg = vdds_dsi;
Tomi Valkeinen5f42f2ce2011-02-22 15:53:46 +02004171 }
4172
Archit Taneja75d72472011-05-16 15:17:08 +05304173 if (dsi_get_num_data_lanes_dssdev(dssdev) > dsi->num_data_lanes) {
4174 DSSERR("DSI%d can't support more than %d data lanes\n",
4175 dsi_module + 1, dsi->num_data_lanes);
4176 return -EINVAL;
4177 }
4178
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004179 return 0;
4180}
4181
Archit Taneja5ee3c142011-03-02 12:35:53 +05304182int omap_dsi_request_vc(struct omap_dss_device *dssdev, int *channel)
4183{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304184 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4185 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Taneja5ee3c142011-03-02 12:35:53 +05304186 int i;
4187
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304188 for (i = 0; i < ARRAY_SIZE(dsi->vc); i++) {
4189 if (!dsi->vc[i].dssdev) {
4190 dsi->vc[i].dssdev = dssdev;
Archit Taneja5ee3c142011-03-02 12:35:53 +05304191 *channel = i;
4192 return 0;
4193 }
4194 }
4195
4196 DSSERR("cannot get VC for display %s", dssdev->name);
4197 return -ENOSPC;
4198}
4199EXPORT_SYMBOL(omap_dsi_request_vc);
4200
4201int omap_dsi_set_vc_id(struct omap_dss_device *dssdev, int channel, int vc_id)
4202{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304203 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4204 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4205
Archit Taneja5ee3c142011-03-02 12:35:53 +05304206 if (vc_id < 0 || vc_id > 3) {
4207 DSSERR("VC ID out of range\n");
4208 return -EINVAL;
4209 }
4210
4211 if (channel < 0 || channel > 3) {
4212 DSSERR("Virtual Channel out of range\n");
4213 return -EINVAL;
4214 }
4215
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304216 if (dsi->vc[channel].dssdev != dssdev) {
Archit Taneja5ee3c142011-03-02 12:35:53 +05304217 DSSERR("Virtual Channel not allocated to display %s\n",
4218 dssdev->name);
4219 return -EINVAL;
4220 }
4221
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304222 dsi->vc[channel].vc_id = vc_id;
Archit Taneja5ee3c142011-03-02 12:35:53 +05304223
4224 return 0;
4225}
4226EXPORT_SYMBOL(omap_dsi_set_vc_id);
4227
4228void omap_dsi_release_vc(struct omap_dss_device *dssdev, int channel)
4229{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304230 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4231 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4232
Archit Taneja5ee3c142011-03-02 12:35:53 +05304233 if ((channel >= 0 && channel <= 3) &&
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304234 dsi->vc[channel].dssdev == dssdev) {
4235 dsi->vc[channel].dssdev = NULL;
4236 dsi->vc[channel].vc_id = 0;
Archit Taneja5ee3c142011-03-02 12:35:53 +05304237 }
4238}
4239EXPORT_SYMBOL(omap_dsi_release_vc);
4240
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304241void dsi_wait_pll_hsdiv_dispc_active(struct platform_device *dsidev)
Tomi Valkeinene406f902010-06-09 15:28:12 +03004242{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304243 if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 7, 1) != 1)
Archit Taneja067a57e2011-03-02 11:57:25 +05304244 DSSERR("%s (%s) not active\n",
Archit Taneja89a35e52011-04-12 13:52:23 +05304245 dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
4246 dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC));
Tomi Valkeinene406f902010-06-09 15:28:12 +03004247}
4248
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304249void dsi_wait_pll_hsdiv_dsi_active(struct platform_device *dsidev)
Tomi Valkeinene406f902010-06-09 15:28:12 +03004250{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304251 if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 8, 1) != 1)
Archit Taneja067a57e2011-03-02 11:57:25 +05304252 DSSERR("%s (%s) not active\n",
Archit Taneja89a35e52011-04-12 13:52:23 +05304253 dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
4254 dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI));
Tomi Valkeinene406f902010-06-09 15:28:12 +03004255}
4256
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304257static void dsi_calc_clock_param_ranges(struct platform_device *dsidev)
Taneja, Archit49641112011-03-14 23:28:23 -05004258{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304259 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4260
4261 dsi->regn_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGN);
4262 dsi->regm_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM);
4263 dsi->regm_dispc_max =
4264 dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DISPC);
4265 dsi->regm_dsi_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DSI);
4266 dsi->fint_min = dss_feat_get_param_min(FEAT_PARAM_DSIPLL_FINT);
4267 dsi->fint_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_FINT);
4268 dsi->lpdiv_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_LPDIV);
Taneja, Archit49641112011-03-14 23:28:23 -05004269}
4270
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004271static int dsi_get_clocks(struct platform_device *dsidev)
4272{
4273 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4274 struct clk *clk;
4275
4276 clk = clk_get(&dsidev->dev, "fck");
4277 if (IS_ERR(clk)) {
4278 DSSERR("can't get fck\n");
4279 return PTR_ERR(clk);
4280 }
4281
4282 dsi->dss_clk = clk;
4283
Tomi Valkeinenbfe4f8d2011-08-04 11:22:54 +03004284 clk = clk_get(&dsidev->dev, "sys_clk");
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004285 if (IS_ERR(clk)) {
4286 DSSERR("can't get sys_clk\n");
4287 clk_put(dsi->dss_clk);
4288 dsi->dss_clk = NULL;
4289 return PTR_ERR(clk);
4290 }
4291
4292 dsi->sys_clk = clk;
4293
4294 return 0;
4295}
4296
4297static void dsi_put_clocks(struct platform_device *dsidev)
4298{
4299 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4300
4301 if (dsi->dss_clk)
4302 clk_put(dsi->dss_clk);
4303 if (dsi->sys_clk)
4304 clk_put(dsi->sys_clk);
4305}
4306
Tomi Valkeinenb98482e2011-05-16 13:52:51 +03004307/* DSI1 HW IP initialisation */
Tomi Valkeinen7c68dd92011-08-03 14:00:57 +03004308static int omap_dsihw_probe(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004309{
Tomi Valkeinend1f58572010-07-30 11:57:57 +03004310 struct omap_display_platform_data *dss_plat_data;
4311 struct omap_dss_board_info *board_info;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004312 u32 rev;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304313 int r, i, dsi_module = dsi_get_dsidev_id(dsidev);
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00004314 struct resource *dsi_mem;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304315 struct dsi_data *dsi;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004316
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304317 dsi = kzalloc(sizeof(*dsi), GFP_KERNEL);
4318 if (!dsi) {
4319 r = -ENOMEM;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004320 goto err_alloc;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304321 }
4322
4323 dsi->pdev = dsidev;
4324 dsi_pdev_map[dsi_module] = dsidev;
4325 dev_set_drvdata(&dsidev->dev, dsi);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304326
4327 dss_plat_data = dsidev->dev.platform_data;
Tomi Valkeinend1f58572010-07-30 11:57:57 +03004328 board_info = dss_plat_data->board_data;
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03004329 dsi->enable_pads = board_info->dsi_enable_pads;
4330 dsi->disable_pads = board_info->dsi_disable_pads;
Tomi Valkeinend1f58572010-07-30 11:57:57 +03004331
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304332 spin_lock_init(&dsi->irq_lock);
4333 spin_lock_init(&dsi->errors_lock);
4334 dsi->errors = 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004335
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02004336#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304337 spin_lock_init(&dsi->irq_stats_lock);
4338 dsi->irq_stats.last_reset = jiffies;
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02004339#endif
4340
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304341 mutex_init(&dsi->lock);
4342 sema_init(&dsi->bus_lock, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004343
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004344 r = dsi_get_clocks(dsidev);
4345 if (r)
4346 goto err_get_clk;
4347
4348 pm_runtime_enable(&dsidev->dev);
4349
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304350 INIT_DELAYED_WORK_DEFERRABLE(&dsi->framedone_timeout_work,
4351 dsi_framedone_timeout_work_callback);
4352
4353#ifdef DSI_CATCH_MISSING_TE
4354 init_timer(&dsi->te_timer);
4355 dsi->te_timer.function = dsi_te_timeout;
4356 dsi->te_timer.data = 0;
4357#endif
4358 dsi_mem = platform_get_resource(dsi->pdev, IORESOURCE_MEM, 0);
4359 if (!dsi_mem) {
4360 DSSERR("can't get IORESOURCE_MEM DSI\n");
4361 r = -EINVAL;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004362 goto err_ioremap;
archit tanejaaffe3602011-02-23 08:41:03 +00004363 }
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304364 dsi->base = ioremap(dsi_mem->start, resource_size(dsi_mem));
4365 if (!dsi->base) {
4366 DSSERR("can't ioremap DSI\n");
4367 r = -ENOMEM;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004368 goto err_ioremap;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304369 }
4370 dsi->irq = platform_get_irq(dsi->pdev, 0);
4371 if (dsi->irq < 0) {
4372 DSSERR("platform_get_irq failed\n");
4373 r = -ENODEV;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004374 goto err_get_irq;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304375 }
archit tanejaaffe3602011-02-23 08:41:03 +00004376
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304377 r = request_irq(dsi->irq, omap_dsi_irq_handler, IRQF_SHARED,
4378 dev_name(&dsidev->dev), dsi->pdev);
archit tanejaaffe3602011-02-23 08:41:03 +00004379 if (r < 0) {
4380 DSSERR("request_irq failed\n");
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004381 goto err_get_irq;
archit tanejaaffe3602011-02-23 08:41:03 +00004382 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004383
Archit Taneja5ee3c142011-03-02 12:35:53 +05304384 /* DSI VCs initialization */
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304385 for (i = 0; i < ARRAY_SIZE(dsi->vc); i++) {
4386 dsi->vc[i].mode = DSI_VC_MODE_L4;
4387 dsi->vc[i].dssdev = NULL;
4388 dsi->vc[i].vc_id = 0;
Archit Taneja5ee3c142011-03-02 12:35:53 +05304389 }
4390
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304391 dsi_calc_clock_param_ranges(dsidev);
Taneja, Archit49641112011-03-14 23:28:23 -05004392
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004393 r = dsi_runtime_get(dsidev);
4394 if (r)
4395 goto err_get_dsi;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004396
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304397 rev = dsi_read_reg(dsidev, DSI_REVISION);
4398 dev_dbg(&dsidev->dev, "OMAP DSI rev %d.%d\n",
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004399 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
4400
Archit Taneja75d72472011-05-16 15:17:08 +05304401 dsi->num_data_lanes = dsi_get_num_data_lanes(dsidev);
4402
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004403 dsi_runtime_put(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004404
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004405 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004406
4407err_get_dsi:
4408 free_irq(dsi->irq, dsi->pdev);
4409err_get_irq:
Archit Taneja49dbf582011-05-16 15:17:07 +05304410 iounmap(dsi->base);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004411err_ioremap:
4412 pm_runtime_disable(&dsidev->dev);
4413err_get_clk:
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304414 kfree(dsi);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004415err_alloc:
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004416 return r;
4417}
4418
Tomi Valkeinen7c68dd92011-08-03 14:00:57 +03004419static int omap_dsihw_remove(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004420{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304421 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4422
Tomi Valkeinenb98482e2011-05-16 13:52:51 +03004423 WARN_ON(dsi->scp_clk_refcount > 0);
4424
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004425 pm_runtime_disable(&dsidev->dev);
4426
4427 dsi_put_clocks(dsidev);
4428
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304429 if (dsi->vdds_dsi_reg != NULL) {
4430 if (dsi->vdds_dsi_enabled) {
4431 regulator_disable(dsi->vdds_dsi_reg);
4432 dsi->vdds_dsi_enabled = false;
Tomi Valkeinen88257b22010-12-20 16:26:22 +02004433 }
4434
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304435 regulator_put(dsi->vdds_dsi_reg);
4436 dsi->vdds_dsi_reg = NULL;
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00004437 }
4438
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304439 free_irq(dsi->irq, dsi->pdev);
4440 iounmap(dsi->base);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004441
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304442 kfree(dsi);
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03004443
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00004444 return 0;
4445}
4446
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004447static int dsi_runtime_suspend(struct device *dev)
4448{
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004449 dispc_runtime_put();
4450 dss_runtime_put();
4451
4452 return 0;
4453}
4454
4455static int dsi_runtime_resume(struct device *dev)
4456{
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004457 int r;
4458
4459 r = dss_runtime_get();
4460 if (r)
4461 goto err_get_dss;
4462
4463 r = dispc_runtime_get();
4464 if (r)
4465 goto err_get_dispc;
4466
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004467 return 0;
4468
4469err_get_dispc:
4470 dss_runtime_put();
4471err_get_dss:
4472 return r;
4473}
4474
4475static const struct dev_pm_ops dsi_pm_ops = {
4476 .runtime_suspend = dsi_runtime_suspend,
4477 .runtime_resume = dsi_runtime_resume,
4478};
4479
Tomi Valkeinen7c68dd92011-08-03 14:00:57 +03004480static struct platform_driver omap_dsihw_driver = {
4481 .probe = omap_dsihw_probe,
4482 .remove = omap_dsihw_remove,
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00004483 .driver = {
Tomi Valkeinen7c68dd92011-08-03 14:00:57 +03004484 .name = "omapdss_dsi",
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00004485 .owner = THIS_MODULE,
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004486 .pm = &dsi_pm_ops,
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00004487 },
4488};
4489
4490int dsi_init_platform_driver(void)
4491{
Tomi Valkeinen7c68dd92011-08-03 14:00:57 +03004492 return platform_driver_register(&omap_dsihw_driver);
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00004493}
4494
4495void dsi_uninit_platform_driver(void)
4496{
Tomi Valkeinen7c68dd92011-08-03 14:00:57 +03004497 return platform_driver_unregister(&omap_dsihw_driver);
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00004498}