blob: 0c3afc2b4696ff1b61de0f4c41b165fdadc5dba0 [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>
Paul Gortmaker355b2002011-07-03 16:17:28 -040030#include <linux/module.h>
Tomi Valkeinenb9eb5d72010-01-11 16:33:56 +020031#include <linux/semaphore.h>
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +020032#include <linux/seq_file.h>
33#include <linux/platform_device.h>
34#include <linux/regulator/consumer.h>
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +020035#include <linux/wait.h>
Tomi Valkeinen18946f62010-01-12 14:16:41 +020036#include <linux/workqueue.h>
Tomi Valkeinen40885ab2010-07-28 15:53:38 +030037#include <linux/sched.h>
Archit Tanejaf1da39d2011-05-12 17:26:27 +053038#include <linux/slab.h>
Archit Taneja5a8b5722011-05-12 17:26:29 +053039#include <linux/debugfs.h>
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030040#include <linux/pm_runtime.h>
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +020041
Tomi Valkeinena0b38cc2011-05-11 14:05:07 +030042#include <video/omapdss.h>
Archit Taneja7a7c48f2011-08-25 18:25:03 +053043#include <video/mipi_display.h>
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +020044
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 | \
Archit Taneja8af6ff02011-09-05 16:48:27 +0530135 DSI_IRQ_TA_TIMEOUT | DSI_IRQ_SYNC_LOST)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200136#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
Tomi Valkeinen739a7f42011-10-13 11:22:06 +0300205#define DSI_MAX_NR_LANES 5
206
207enum dsi_lane_function {
208 DSI_LANE_UNUSED = 0,
209 DSI_LANE_CLK,
210 DSI_LANE_DATA1,
211 DSI_LANE_DATA2,
212 DSI_LANE_DATA3,
213 DSI_LANE_DATA4,
214};
215
216struct dsi_lane_config {
217 enum dsi_lane_function function;
218 u8 polarity;
219};
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200220
221struct dsi_isr_data {
222 omap_dsi_isr_t isr;
223 void *arg;
224 u32 mask;
225};
226
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200227enum fifo_size {
228 DSI_FIFO_SIZE_0 = 0,
229 DSI_FIFO_SIZE_32 = 1,
230 DSI_FIFO_SIZE_64 = 2,
231 DSI_FIFO_SIZE_96 = 3,
232 DSI_FIFO_SIZE_128 = 4,
233};
234
Archit Tanejad6049142011-08-22 11:58:08 +0530235enum dsi_vc_source {
236 DSI_VC_SOURCE_L4 = 0,
237 DSI_VC_SOURCE_VP,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200238};
239
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200240struct dsi_irq_stats {
241 unsigned long last_reset;
242 unsigned irq_count;
243 unsigned dsi_irqs[32];
244 unsigned vc_irqs[4][32];
245 unsigned cio_irqs[32];
246};
247
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200248struct dsi_isr_tables {
249 struct dsi_isr_data isr_table[DSI_MAX_NR_ISRS];
250 struct dsi_isr_data isr_table_vc[4][DSI_MAX_NR_ISRS];
251 struct dsi_isr_data isr_table_cio[DSI_MAX_NR_ISRS];
252};
253
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530254struct dsi_data {
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +0000255 struct platform_device *pdev;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200256 void __iomem *base;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300257
Tomi Valkeinen11ee9602012-03-09 16:07:39 +0200258 int module_id;
259
archit tanejaaffe3602011-02-23 08:41:03 +0000260 int irq;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200261
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300262 struct clk *dss_clk;
263 struct clk *sys_clk;
264
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200265 struct dsi_clock_info current_cinfo;
266
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +0300267 bool vdds_dsi_enabled;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200268 struct regulator *vdds_dsi_reg;
269
270 struct {
Archit Tanejad6049142011-08-22 11:58:08 +0530271 enum dsi_vc_source source;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200272 struct omap_dss_device *dssdev;
273 enum fifo_size fifo_size;
Archit Taneja5ee3c142011-03-02 12:35:53 +0530274 int vc_id;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200275 } vc[4];
276
277 struct mutex lock;
Tomi Valkeinenb9eb5d72010-01-11 16:33:56 +0200278 struct semaphore bus_lock;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200279
280 unsigned pll_locked;
281
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200282 spinlock_t irq_lock;
283 struct dsi_isr_tables isr_tables;
284 /* space for a copy used by the interrupt handler */
285 struct dsi_isr_tables isr_tables_copy;
286
Tomi Valkeinen18946f62010-01-12 14:16:41 +0200287 int update_channel;
Tomi Valkeinen5476e742011-11-03 16:34:20 +0200288#ifdef DEBUG
289 unsigned update_bytes;
290#endif
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200291
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200292 bool te_enabled;
Tomi Valkeinen40885ab2010-07-28 15:53:38 +0300293 bool ulps_enabled;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200294
Tomi Valkeinen18946f62010-01-12 14:16:41 +0200295 void (*framedone_callback)(int, void *);
296 void *framedone_data;
297
298 struct delayed_work framedone_timeout_work;
299
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200300#ifdef DSI_CATCH_MISSING_TE
301 struct timer_list te_timer;
302#endif
303
304 unsigned long cache_req_pck;
305 unsigned long cache_clk_freq;
306 struct dsi_clock_info cache_cinfo;
307
308 u32 errors;
309 spinlock_t errors_lock;
310#ifdef DEBUG
311 ktime_t perf_setup_time;
312 ktime_t perf_start_time;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200313#endif
314 int debug_read;
315 int debug_write;
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200316
317#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
318 spinlock_t irq_stats_lock;
319 struct dsi_irq_stats irq_stats;
320#endif
Taneja, Archit49641112011-03-14 23:28:23 -0500321 /* DSI PLL Parameter Ranges */
322 unsigned long regm_max, regn_max;
323 unsigned long regm_dispc_max, regm_dsi_max;
324 unsigned long fint_min, fint_max;
325 unsigned long lpdiv_max;
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +0300326
Tomi Valkeinend9820852011-10-12 15:05:59 +0300327 unsigned num_lanes_supported;
Archit Taneja75d72472011-05-16 15:17:08 +0530328
Tomi Valkeinen739a7f42011-10-13 11:22:06 +0300329 struct dsi_lane_config lanes[DSI_MAX_NR_LANES];
330 unsigned num_lanes_used;
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +0300331
332 unsigned scp_clk_refcount;
Archit Taneja7d2572f2012-06-29 14:31:07 +0530333
334 struct dss_lcd_mgr_config mgr_config;
Archit Tanejae67458a2012-08-13 14:17:30 +0530335 struct omap_video_timings timings;
Archit Taneja02c39602012-08-10 15:01:33 +0530336 enum omap_dss_dsi_pixel_format pix_fmt;
Archit Tanejadca2b152012-08-16 18:02:00 +0530337 enum omap_dss_dsi_mode mode;
Archit Taneja0b3ffe32012-08-13 22:13:39 +0530338 struct omap_dss_dsi_videomode_timings vm_timings;
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530339};
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200340
Archit Taneja2e868db2011-05-12 17:26:28 +0530341struct dsi_packet_sent_handler_data {
342 struct platform_device *dsidev;
343 struct completion *completion;
344};
345
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530346static struct platform_device *dsi_pdev_map[MAX_NUM_DSI];
347
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200348#ifdef DEBUG
Rusty Russell90ab5ee2012-01-13 09:32:20 +1030349static bool dsi_perf;
350module_param(dsi_perf, bool, 0644);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200351#endif
352
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530353static inline struct dsi_data *dsi_get_dsidrv_data(struct platform_device *dsidev)
354{
355 return dev_get_drvdata(&dsidev->dev);
356}
357
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530358static inline struct platform_device *dsi_get_dsidev_from_dssdev(struct omap_dss_device *dssdev)
359{
360 return dsi_pdev_map[dssdev->phy.dsi.module];
361}
362
363struct platform_device *dsi_get_dsidev_from_id(int module)
364{
365 return dsi_pdev_map[module];
366}
367
368static inline void dsi_write_reg(struct platform_device *dsidev,
369 const struct dsi_reg idx, u32 val)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200370{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530371 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
372
373 __raw_writel(val, dsi->base + idx.idx);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200374}
375
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530376static inline u32 dsi_read_reg(struct platform_device *dsidev,
377 const struct dsi_reg idx)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200378{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530379 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
380
381 return __raw_readl(dsi->base + idx.idx);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200382}
383
Archit Taneja1ffefe72011-05-12 17:26:24 +0530384void dsi_bus_lock(struct omap_dss_device *dssdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200385{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530386 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
387 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
388
389 down(&dsi->bus_lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200390}
391EXPORT_SYMBOL(dsi_bus_lock);
392
Archit Taneja1ffefe72011-05-12 17:26:24 +0530393void dsi_bus_unlock(struct omap_dss_device *dssdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200394{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530395 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
396 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
397
398 up(&dsi->bus_lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200399}
400EXPORT_SYMBOL(dsi_bus_unlock);
401
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530402static bool dsi_bus_is_locked(struct platform_device *dsidev)
Tomi Valkeinen4f765022010-01-18 16:27:52 +0200403{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530404 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
405
406 return dsi->bus_lock.count == 0;
Tomi Valkeinen4f765022010-01-18 16:27:52 +0200407}
408
Tomi Valkeinenf36a06e2011-03-02 14:48:41 +0200409static void dsi_completion_handler(void *data, u32 mask)
410{
411 complete((struct completion *)data);
412}
413
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530414static inline int wait_for_bit_change(struct platform_device *dsidev,
415 const struct dsi_reg idx, int bitnum, int value)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200416{
Tomi Valkeinen3b984092011-10-13 19:06:49 +0300417 unsigned long timeout;
418 ktime_t wait;
419 int t;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200420
Tomi Valkeinen3b984092011-10-13 19:06:49 +0300421 /* first busyloop to see if the bit changes right away */
422 t = 100;
423 while (t-- > 0) {
424 if (REG_GET(dsidev, idx, bitnum, bitnum) == value)
425 return value;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200426 }
427
Tomi Valkeinen3b984092011-10-13 19:06:49 +0300428 /* then loop for 500ms, sleeping for 1ms in between */
429 timeout = jiffies + msecs_to_jiffies(500);
430 while (time_before(jiffies, timeout)) {
431 if (REG_GET(dsidev, idx, bitnum, bitnum) == value)
432 return value;
433
434 wait = ns_to_ktime(1000 * 1000);
435 set_current_state(TASK_UNINTERRUPTIBLE);
436 schedule_hrtimeout(&wait, HRTIMER_MODE_REL);
437 }
438
439 return !value;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200440}
441
Archit Tanejaa3b3cc22011-09-08 18:42:16 +0530442u8 dsi_get_pixel_size(enum omap_dss_dsi_pixel_format fmt)
443{
444 switch (fmt) {
445 case OMAP_DSS_DSI_FMT_RGB888:
446 case OMAP_DSS_DSI_FMT_RGB666:
447 return 24;
448 case OMAP_DSS_DSI_FMT_RGB666_PACKED:
449 return 18;
450 case OMAP_DSS_DSI_FMT_RGB565:
451 return 16;
452 default:
453 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300454 return 0;
Archit Tanejaa3b3cc22011-09-08 18:42:16 +0530455 }
456}
457
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200458#ifdef DEBUG
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530459static void dsi_perf_mark_setup(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200460{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530461 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
462 dsi->perf_setup_time = ktime_get();
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200463}
464
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530465static void dsi_perf_mark_start(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200466{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530467 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
468 dsi->perf_start_time = ktime_get();
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200469}
470
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530471static void dsi_perf_show(struct platform_device *dsidev, const char *name)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200472{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530473 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200474 ktime_t t, setup_time, trans_time;
475 u32 total_bytes;
476 u32 setup_us, trans_us, total_us;
477
478 if (!dsi_perf)
479 return;
480
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200481 t = ktime_get();
482
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530483 setup_time = ktime_sub(dsi->perf_start_time, dsi->perf_setup_time);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200484 setup_us = (u32)ktime_to_us(setup_time);
485 if (setup_us == 0)
486 setup_us = 1;
487
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530488 trans_time = ktime_sub(t, dsi->perf_start_time);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200489 trans_us = (u32)ktime_to_us(trans_time);
490 if (trans_us == 0)
491 trans_us = 1;
492
493 total_us = setup_us + trans_us;
494
Tomi Valkeinen5476e742011-11-03 16:34:20 +0200495 total_bytes = dsi->update_bytes;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200496
Tomi Valkeinen1bbb2752010-01-11 16:41:10 +0200497 printk(KERN_INFO "DSI(%s): %u us + %u us = %u us (%uHz), "
498 "%u bytes, %u kbytes/sec\n",
499 name,
500 setup_us,
501 trans_us,
502 total_us,
503 1000*1000 / total_us,
504 total_bytes,
505 total_bytes * 1000 / total_us);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200506}
507#else
Tomi Valkeinen4a9a5e32011-05-23 16:36:09 +0300508static inline void dsi_perf_mark_setup(struct platform_device *dsidev)
509{
510}
511
512static inline void dsi_perf_mark_start(struct platform_device *dsidev)
513{
514}
515
516static inline void dsi_perf_show(struct platform_device *dsidev,
517 const char *name)
518{
519}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200520#endif
521
522static void print_irq_status(u32 status)
523{
Tomi Valkeinend80d4992011-03-02 15:53:07 +0200524 if (status == 0)
525 return;
526
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200527#ifndef VERBOSE_IRQ
528 if ((status & ~DSI_IRQ_CHANNEL_MASK) == 0)
529 return;
530#endif
531 printk(KERN_DEBUG "DSI IRQ: 0x%x: ", status);
532
533#define PIS(x) \
534 if (status & DSI_IRQ_##x) \
535 printk(#x " ");
536#ifdef VERBOSE_IRQ
537 PIS(VC0);
538 PIS(VC1);
539 PIS(VC2);
540 PIS(VC3);
541#endif
542 PIS(WAKEUP);
543 PIS(RESYNC);
544 PIS(PLL_LOCK);
545 PIS(PLL_UNLOCK);
546 PIS(PLL_RECALL);
547 PIS(COMPLEXIO_ERR);
548 PIS(HS_TX_TIMEOUT);
549 PIS(LP_RX_TIMEOUT);
550 PIS(TE_TRIGGER);
551 PIS(ACK_TRIGGER);
552 PIS(SYNC_LOST);
553 PIS(LDO_POWER_GOOD);
554 PIS(TA_TIMEOUT);
555#undef PIS
556
557 printk("\n");
558}
559
560static void print_irq_status_vc(int channel, u32 status)
561{
Tomi Valkeinend80d4992011-03-02 15:53:07 +0200562 if (status == 0)
563 return;
564
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200565#ifndef VERBOSE_IRQ
566 if ((status & ~DSI_VC_IRQ_PACKET_SENT) == 0)
567 return;
568#endif
569 printk(KERN_DEBUG "DSI VC(%d) IRQ 0x%x: ", channel, status);
570
571#define PIS(x) \
572 if (status & DSI_VC_IRQ_##x) \
573 printk(#x " ");
574 PIS(CS);
575 PIS(ECC_CORR);
576#ifdef VERBOSE_IRQ
577 PIS(PACKET_SENT);
578#endif
579 PIS(FIFO_TX_OVF);
580 PIS(FIFO_RX_OVF);
581 PIS(BTA);
582 PIS(ECC_NO_CORR);
583 PIS(FIFO_TX_UDF);
584 PIS(PP_BUSY_CHANGE);
585#undef PIS
586 printk("\n");
587}
588
589static void print_irq_status_cio(u32 status)
590{
Tomi Valkeinend80d4992011-03-02 15:53:07 +0200591 if (status == 0)
592 return;
593
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200594 printk(KERN_DEBUG "DSI CIO IRQ 0x%x: ", status);
595
596#define PIS(x) \
597 if (status & DSI_CIO_IRQ_##x) \
598 printk(#x " ");
599 PIS(ERRSYNCESC1);
600 PIS(ERRSYNCESC2);
601 PIS(ERRSYNCESC3);
602 PIS(ERRESC1);
603 PIS(ERRESC2);
604 PIS(ERRESC3);
605 PIS(ERRCONTROL1);
606 PIS(ERRCONTROL2);
607 PIS(ERRCONTROL3);
608 PIS(STATEULPS1);
609 PIS(STATEULPS2);
610 PIS(STATEULPS3);
611 PIS(ERRCONTENTIONLP0_1);
612 PIS(ERRCONTENTIONLP1_1);
613 PIS(ERRCONTENTIONLP0_2);
614 PIS(ERRCONTENTIONLP1_2);
615 PIS(ERRCONTENTIONLP0_3);
616 PIS(ERRCONTENTIONLP1_3);
617 PIS(ULPSACTIVENOT_ALL0);
618 PIS(ULPSACTIVENOT_ALL1);
619#undef PIS
620
621 printk("\n");
622}
623
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200624#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530625static void dsi_collect_irq_stats(struct platform_device *dsidev, u32 irqstatus,
626 u32 *vcstatus, u32 ciostatus)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200627{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530628 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200629 int i;
630
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530631 spin_lock(&dsi->irq_stats_lock);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200632
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530633 dsi->irq_stats.irq_count++;
634 dss_collect_irq_stats(irqstatus, dsi->irq_stats.dsi_irqs);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200635
636 for (i = 0; i < 4; ++i)
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530637 dss_collect_irq_stats(vcstatus[i], dsi->irq_stats.vc_irqs[i]);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200638
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530639 dss_collect_irq_stats(ciostatus, dsi->irq_stats.cio_irqs);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200640
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530641 spin_unlock(&dsi->irq_stats_lock);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200642}
643#else
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530644#define dsi_collect_irq_stats(dsidev, irqstatus, vcstatus, ciostatus)
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200645#endif
646
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200647static int debug_irq;
648
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530649static void dsi_handle_irq_errors(struct platform_device *dsidev, u32 irqstatus,
650 u32 *vcstatus, u32 ciostatus)
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200651{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530652 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200653 int i;
654
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200655 if (irqstatus & DSI_IRQ_ERROR_MASK) {
656 DSSERR("DSI error, irqstatus %x\n", irqstatus);
657 print_irq_status(irqstatus);
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530658 spin_lock(&dsi->errors_lock);
659 dsi->errors |= irqstatus & DSI_IRQ_ERROR_MASK;
660 spin_unlock(&dsi->errors_lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200661 } else if (debug_irq) {
662 print_irq_status(irqstatus);
663 }
664
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200665 for (i = 0; i < 4; ++i) {
666 if (vcstatus[i] & DSI_VC_IRQ_ERROR_MASK) {
667 DSSERR("DSI VC(%d) error, vc irqstatus %x\n",
668 i, vcstatus[i]);
669 print_irq_status_vc(i, vcstatus[i]);
670 } else if (debug_irq) {
671 print_irq_status_vc(i, vcstatus[i]);
672 }
673 }
674
675 if (ciostatus & DSI_CIO_IRQ_ERROR_MASK) {
676 DSSERR("DSI CIO error, cio irqstatus %x\n", ciostatus);
677 print_irq_status_cio(ciostatus);
678 } else if (debug_irq) {
679 print_irq_status_cio(ciostatus);
680 }
681}
682
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200683static void dsi_call_isrs(struct dsi_isr_data *isr_array,
684 unsigned isr_array_size, u32 irqstatus)
685{
686 struct dsi_isr_data *isr_data;
687 int i;
688
689 for (i = 0; i < isr_array_size; i++) {
690 isr_data = &isr_array[i];
691 if (isr_data->isr && isr_data->mask & irqstatus)
692 isr_data->isr(isr_data->arg, irqstatus);
693 }
694}
695
696static void dsi_handle_isrs(struct dsi_isr_tables *isr_tables,
697 u32 irqstatus, u32 *vcstatus, u32 ciostatus)
698{
699 int i;
700
701 dsi_call_isrs(isr_tables->isr_table,
702 ARRAY_SIZE(isr_tables->isr_table),
703 irqstatus);
704
705 for (i = 0; i < 4; ++i) {
706 if (vcstatus[i] == 0)
707 continue;
708 dsi_call_isrs(isr_tables->isr_table_vc[i],
709 ARRAY_SIZE(isr_tables->isr_table_vc[i]),
710 vcstatus[i]);
711 }
712
713 if (ciostatus != 0)
714 dsi_call_isrs(isr_tables->isr_table_cio,
715 ARRAY_SIZE(isr_tables->isr_table_cio),
716 ciostatus);
717}
718
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200719static irqreturn_t omap_dsi_irq_handler(int irq, void *arg)
720{
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530721 struct platform_device *dsidev;
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530722 struct dsi_data *dsi;
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200723 u32 irqstatus, vcstatus[4], ciostatus;
724 int i;
725
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530726 dsidev = (struct platform_device *) arg;
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530727 dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530728
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530729 spin_lock(&dsi->irq_lock);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200730
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530731 irqstatus = dsi_read_reg(dsidev, DSI_IRQSTATUS);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200732
733 /* IRQ is not for us */
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200734 if (!irqstatus) {
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530735 spin_unlock(&dsi->irq_lock);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200736 return IRQ_NONE;
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200737 }
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200738
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530739 dsi_write_reg(dsidev, DSI_IRQSTATUS, irqstatus & ~DSI_IRQ_CHANNEL_MASK);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200740 /* flush posted write */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530741 dsi_read_reg(dsidev, DSI_IRQSTATUS);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200742
743 for (i = 0; i < 4; ++i) {
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200744 if ((irqstatus & (1 << i)) == 0) {
745 vcstatus[i] = 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200746 continue;
Tomi Valkeinenab83b142010-06-09 15:31:01 +0300747 }
748
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530749 vcstatus[i] = dsi_read_reg(dsidev, DSI_VC_IRQSTATUS(i));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200750
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530751 dsi_write_reg(dsidev, DSI_VC_IRQSTATUS(i), vcstatus[i]);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200752 /* flush posted write */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530753 dsi_read_reg(dsidev, DSI_VC_IRQSTATUS(i));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200754 }
755
756 if (irqstatus & DSI_IRQ_COMPLEXIO_ERR) {
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530757 ciostatus = dsi_read_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200758
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530759 dsi_write_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS, ciostatus);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200760 /* flush posted write */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530761 dsi_read_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200762 } else {
763 ciostatus = 0;
764 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200765
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200766#ifdef DSI_CATCH_MISSING_TE
767 if (irqstatus & DSI_IRQ_TE_TRIGGER)
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530768 del_timer(&dsi->te_timer);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200769#endif
770
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200771 /* make a copy and unlock, so that isrs can unregister
772 * themselves */
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530773 memcpy(&dsi->isr_tables_copy, &dsi->isr_tables,
774 sizeof(dsi->isr_tables));
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200775
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530776 spin_unlock(&dsi->irq_lock);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200777
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530778 dsi_handle_isrs(&dsi->isr_tables_copy, irqstatus, vcstatus, ciostatus);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200779
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530780 dsi_handle_irq_errors(dsidev, irqstatus, vcstatus, ciostatus);
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200781
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530782 dsi_collect_irq_stats(dsidev, irqstatus, vcstatus, ciostatus);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200783
archit tanejaaffe3602011-02-23 08:41:03 +0000784 return IRQ_HANDLED;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200785}
786
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530787/* dsi->irq_lock has to be locked by the caller */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530788static void _omap_dsi_configure_irqs(struct platform_device *dsidev,
789 struct dsi_isr_data *isr_array,
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200790 unsigned isr_array_size, u32 default_mask,
791 const struct dsi_reg enable_reg,
792 const struct dsi_reg status_reg)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200793{
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200794 struct dsi_isr_data *isr_data;
795 u32 mask;
796 u32 old_mask;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200797 int i;
798
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200799 mask = default_mask;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200800
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200801 for (i = 0; i < isr_array_size; i++) {
802 isr_data = &isr_array[i];
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200803
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200804 if (isr_data->isr == NULL)
805 continue;
806
807 mask |= isr_data->mask;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200808 }
809
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530810 old_mask = dsi_read_reg(dsidev, enable_reg);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200811 /* clear the irqstatus for newly enabled irqs */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530812 dsi_write_reg(dsidev, status_reg, (mask ^ old_mask) & mask);
813 dsi_write_reg(dsidev, enable_reg, mask);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200814
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200815 /* flush posted writes */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530816 dsi_read_reg(dsidev, enable_reg);
817 dsi_read_reg(dsidev, status_reg);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200818}
819
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530820/* dsi->irq_lock has to be locked by the caller */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530821static void _omap_dsi_set_irqs(struct platform_device *dsidev)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200822{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530823 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200824 u32 mask = DSI_IRQ_ERROR_MASK;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200825#ifdef DSI_CATCH_MISSING_TE
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200826 mask |= DSI_IRQ_TE_TRIGGER;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200827#endif
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530828 _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table,
829 ARRAY_SIZE(dsi->isr_tables.isr_table), mask,
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200830 DSI_IRQENABLE, DSI_IRQSTATUS);
831}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200832
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530833/* dsi->irq_lock has to be locked by the caller */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530834static void _omap_dsi_set_irqs_vc(struct platform_device *dsidev, int vc)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200835{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530836 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
837
838 _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table_vc[vc],
839 ARRAY_SIZE(dsi->isr_tables.isr_table_vc[vc]),
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200840 DSI_VC_IRQ_ERROR_MASK,
841 DSI_VC_IRQENABLE(vc), DSI_VC_IRQSTATUS(vc));
842}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200843
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530844/* dsi->irq_lock has to be locked by the caller */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530845static void _omap_dsi_set_irqs_cio(struct platform_device *dsidev)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200846{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530847 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
848
849 _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table_cio,
850 ARRAY_SIZE(dsi->isr_tables.isr_table_cio),
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200851 DSI_CIO_IRQ_ERROR_MASK,
852 DSI_COMPLEXIO_IRQ_ENABLE, DSI_COMPLEXIO_IRQ_STATUS);
853}
854
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530855static void _dsi_initialize_irq(struct platform_device *dsidev)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200856{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530857 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200858 unsigned long flags;
859 int vc;
860
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530861 spin_lock_irqsave(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200862
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530863 memset(&dsi->isr_tables, 0, sizeof(dsi->isr_tables));
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200864
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530865 _omap_dsi_set_irqs(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200866 for (vc = 0; vc < 4; ++vc)
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530867 _omap_dsi_set_irqs_vc(dsidev, vc);
868 _omap_dsi_set_irqs_cio(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200869
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530870 spin_unlock_irqrestore(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200871}
872
873static int _dsi_register_isr(omap_dsi_isr_t isr, void *arg, u32 mask,
874 struct dsi_isr_data *isr_array, unsigned isr_array_size)
875{
876 struct dsi_isr_data *isr_data;
877 int free_idx;
878 int i;
879
880 BUG_ON(isr == NULL);
881
882 /* check for duplicate entry and find a free slot */
883 free_idx = -1;
884 for (i = 0; i < isr_array_size; i++) {
885 isr_data = &isr_array[i];
886
887 if (isr_data->isr == isr && isr_data->arg == arg &&
888 isr_data->mask == mask) {
889 return -EINVAL;
890 }
891
892 if (isr_data->isr == NULL && free_idx == -1)
893 free_idx = i;
894 }
895
896 if (free_idx == -1)
897 return -EBUSY;
898
899 isr_data = &isr_array[free_idx];
900 isr_data->isr = isr;
901 isr_data->arg = arg;
902 isr_data->mask = mask;
903
904 return 0;
905}
906
907static int _dsi_unregister_isr(omap_dsi_isr_t isr, void *arg, u32 mask,
908 struct dsi_isr_data *isr_array, unsigned isr_array_size)
909{
910 struct dsi_isr_data *isr_data;
911 int i;
912
913 for (i = 0; i < isr_array_size; i++) {
914 isr_data = &isr_array[i];
915 if (isr_data->isr != isr || isr_data->arg != arg ||
916 isr_data->mask != mask)
917 continue;
918
919 isr_data->isr = NULL;
920 isr_data->arg = NULL;
921 isr_data->mask = 0;
922
923 return 0;
924 }
925
926 return -EINVAL;
927}
928
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530929static int dsi_register_isr(struct platform_device *dsidev, omap_dsi_isr_t isr,
930 void *arg, u32 mask)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200931{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530932 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200933 unsigned long flags;
934 int r;
935
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530936 spin_lock_irqsave(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200937
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530938 r = _dsi_register_isr(isr, arg, mask, dsi->isr_tables.isr_table,
939 ARRAY_SIZE(dsi->isr_tables.isr_table));
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200940
941 if (r == 0)
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530942 _omap_dsi_set_irqs(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200943
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530944 spin_unlock_irqrestore(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200945
946 return r;
947}
948
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530949static int dsi_unregister_isr(struct platform_device *dsidev,
950 omap_dsi_isr_t isr, void *arg, u32 mask)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200951{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530952 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200953 unsigned long flags;
954 int r;
955
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530956 spin_lock_irqsave(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200957
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530958 r = _dsi_unregister_isr(isr, arg, mask, dsi->isr_tables.isr_table,
959 ARRAY_SIZE(dsi->isr_tables.isr_table));
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200960
961 if (r == 0)
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530962 _omap_dsi_set_irqs(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200963
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530964 spin_unlock_irqrestore(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200965
966 return r;
967}
968
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530969static int dsi_register_isr_vc(struct platform_device *dsidev, int channel,
970 omap_dsi_isr_t isr, void *arg, u32 mask)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200971{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530972 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200973 unsigned long flags;
974 int r;
975
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530976 spin_lock_irqsave(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200977
978 r = _dsi_register_isr(isr, arg, mask,
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530979 dsi->isr_tables.isr_table_vc[channel],
980 ARRAY_SIZE(dsi->isr_tables.isr_table_vc[channel]));
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200981
982 if (r == 0)
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530983 _omap_dsi_set_irqs_vc(dsidev, channel);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200984
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530985 spin_unlock_irqrestore(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200986
987 return r;
988}
989
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530990static int dsi_unregister_isr_vc(struct platform_device *dsidev, int channel,
991 omap_dsi_isr_t isr, void *arg, u32 mask)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200992{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530993 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200994 unsigned long flags;
995 int r;
996
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530997 spin_lock_irqsave(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200998
999 r = _dsi_unregister_isr(isr, arg, mask,
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301000 dsi->isr_tables.isr_table_vc[channel],
1001 ARRAY_SIZE(dsi->isr_tables.isr_table_vc[channel]));
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001002
1003 if (r == 0)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301004 _omap_dsi_set_irqs_vc(dsidev, channel);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001005
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301006 spin_unlock_irqrestore(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001007
1008 return r;
1009}
1010
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301011static int dsi_register_isr_cio(struct platform_device *dsidev,
1012 omap_dsi_isr_t isr, void *arg, u32 mask)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001013{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301014 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001015 unsigned long flags;
1016 int r;
1017
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301018 spin_lock_irqsave(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001019
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301020 r = _dsi_register_isr(isr, arg, mask, dsi->isr_tables.isr_table_cio,
1021 ARRAY_SIZE(dsi->isr_tables.isr_table_cio));
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001022
1023 if (r == 0)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301024 _omap_dsi_set_irqs_cio(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001025
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301026 spin_unlock_irqrestore(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001027
1028 return r;
1029}
1030
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301031static int dsi_unregister_isr_cio(struct platform_device *dsidev,
1032 omap_dsi_isr_t isr, void *arg, u32 mask)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001033{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301034 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001035 unsigned long flags;
1036 int r;
1037
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301038 spin_lock_irqsave(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001039
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301040 r = _dsi_unregister_isr(isr, arg, mask, dsi->isr_tables.isr_table_cio,
1041 ARRAY_SIZE(dsi->isr_tables.isr_table_cio));
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001042
1043 if (r == 0)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301044 _omap_dsi_set_irqs_cio(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001045
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301046 spin_unlock_irqrestore(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001047
1048 return r;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001049}
1050
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301051static u32 dsi_get_errors(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001052{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301053 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001054 unsigned long flags;
1055 u32 e;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301056 spin_lock_irqsave(&dsi->errors_lock, flags);
1057 e = dsi->errors;
1058 dsi->errors = 0;
1059 spin_unlock_irqrestore(&dsi->errors_lock, flags);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001060 return e;
1061}
1062
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001063int dsi_runtime_get(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001064{
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001065 int r;
1066 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1067
1068 DSSDBG("dsi_runtime_get\n");
1069
1070 r = pm_runtime_get_sync(&dsi->pdev->dev);
1071 WARN_ON(r < 0);
1072 return r < 0 ? r : 0;
1073}
1074
1075void dsi_runtime_put(struct platform_device *dsidev)
1076{
1077 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1078 int r;
1079
1080 DSSDBG("dsi_runtime_put\n");
1081
Tomi Valkeinen0eaf9f52012-01-23 13:23:08 +02001082 r = pm_runtime_put_sync(&dsi->pdev->dev);
Tomi Valkeinen5be3aeb2012-06-27 16:37:18 +03001083 WARN_ON(r < 0 && r != -ENOSYS);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001084}
1085
1086/* source clock for DSI PLL. this could also be PCLKFREE */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301087static inline void dsi_enable_pll_clock(struct platform_device *dsidev,
1088 bool enable)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001089{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301090 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1091
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001092 if (enable)
Rajendra Nayakf11766d2012-06-27 14:21:26 +05301093 clk_prepare_enable(dsi->sys_clk);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001094 else
Rajendra Nayakf11766d2012-06-27 14:21:26 +05301095 clk_disable_unprepare(dsi->sys_clk);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001096
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301097 if (enable && dsi->pll_locked) {
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301098 if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 1, 1) != 1)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001099 DSSERR("cannot lock PLL when enabling clocks\n");
1100 }
1101}
1102
1103#ifdef DEBUG
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301104static void _dsi_print_reset_status(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001105{
1106 u32 l;
Tomi Valkeinenc335cbf2010-10-07 13:27:42 +03001107 int b0, b1, b2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001108
1109 if (!dss_debug)
1110 return;
1111
1112 /* A dummy read using the SCP interface to any DSIPHY register is
1113 * required after DSIPHY reset to complete the reset of the DSI complex
1114 * I/O. */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301115 l = dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001116
1117 printk(KERN_DEBUG "DSI resets: ");
1118
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301119 l = dsi_read_reg(dsidev, DSI_PLL_STATUS);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001120 printk("PLL (%d) ", FLD_GET(l, 0, 0));
1121
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301122 l = dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001123 printk("CIO (%d) ", FLD_GET(l, 29, 29));
1124
Tomi Valkeinenc335cbf2010-10-07 13:27:42 +03001125 if (dss_has_feature(FEAT_DSI_REVERSE_TXCLKESC)) {
1126 b0 = 28;
1127 b1 = 27;
1128 b2 = 26;
1129 } else {
1130 b0 = 24;
1131 b1 = 25;
1132 b2 = 26;
1133 }
1134
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301135 l = dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
Tomi Valkeinenc335cbf2010-10-07 13:27:42 +03001136 printk("PHY (%x%x%x, %d, %d, %d)\n",
1137 FLD_GET(l, b0, b0),
1138 FLD_GET(l, b1, b1),
1139 FLD_GET(l, b2, b2),
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001140 FLD_GET(l, 29, 29),
1141 FLD_GET(l, 30, 30),
1142 FLD_GET(l, 31, 31));
1143}
1144#else
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301145#define _dsi_print_reset_status(x)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001146#endif
1147
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301148static inline int dsi_if_enable(struct platform_device *dsidev, bool enable)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001149{
1150 DSSDBG("dsi_if_enable(%d)\n", enable);
1151
1152 enable = enable ? 1 : 0;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301153 REG_FLD_MOD(dsidev, DSI_CTRL, enable, 0, 0); /* IF_EN */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001154
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301155 if (wait_for_bit_change(dsidev, DSI_CTRL, 0, enable) != enable) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001156 DSSERR("Failed to set dsi_if_enable to %d\n", enable);
1157 return -EIO;
1158 }
1159
1160 return 0;
1161}
1162
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301163unsigned long dsi_get_pll_hsdiv_dispc_rate(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001164{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301165 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1166
1167 return dsi->current_cinfo.dsi_pll_hsdiv_dispc_clk;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001168}
1169
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301170static unsigned long dsi_get_pll_hsdiv_dsi_rate(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001171{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301172 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1173
1174 return dsi->current_cinfo.dsi_pll_hsdiv_dsi_clk;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001175}
1176
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301177static unsigned long dsi_get_txbyteclkhs(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001178{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301179 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1180
1181 return dsi->current_cinfo.clkin4ddr / 16;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001182}
1183
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301184static unsigned long dsi_fclk_rate(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001185{
1186 unsigned long r;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001187 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001188
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02001189 if (dss_get_dsi_clk_source(dsi->module_id) == OMAP_DSS_CLK_SRC_FCK) {
Archit Taneja1bb47832011-02-24 14:17:30 +05301190 /* DSI FCLK source is DSS_CLK_FCK */
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001191 r = clk_get_rate(dsi->dss_clk);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001192 } else {
Archit Taneja1bb47832011-02-24 14:17:30 +05301193 /* DSI FCLK source is dsi_pll_hsdiv_dsi_clk */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301194 r = dsi_get_pll_hsdiv_dsi_rate(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001195 }
1196
1197 return r;
1198}
1199
1200static int dsi_set_lp_clk_divisor(struct omap_dss_device *dssdev)
1201{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301202 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301203 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001204 unsigned long dsi_fclk;
1205 unsigned lp_clk_div;
1206 unsigned long lp_clk;
1207
Tomi Valkeinenc6940a32011-02-22 13:36:10 +02001208 lp_clk_div = dssdev->clocks.dsi.lp_clk_div;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001209
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301210 if (lp_clk_div == 0 || lp_clk_div > dsi->lpdiv_max)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001211 return -EINVAL;
1212
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301213 dsi_fclk = dsi_fclk_rate(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001214
1215 lp_clk = dsi_fclk / 2 / lp_clk_div;
1216
1217 DSSDBG("LP_CLK_DIV %u, LP_CLK %lu\n", lp_clk_div, lp_clk);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301218 dsi->current_cinfo.lp_clk = lp_clk;
1219 dsi->current_cinfo.lp_clk_div = lp_clk_div;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001220
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301221 /* LP_CLK_DIVISOR */
1222 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, lp_clk_div, 12, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001223
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301224 /* LP_RX_SYNCHRO_ENABLE */
1225 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, dsi_fclk > 30000000 ? 1 : 0, 21, 21);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001226
1227 return 0;
1228}
1229
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301230static void dsi_enable_scp_clk(struct platform_device *dsidev)
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +03001231{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301232 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1233
1234 if (dsi->scp_clk_refcount++ == 0)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301235 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 1, 14, 14); /* CIO_CLK_ICG */
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +03001236}
1237
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301238static void dsi_disable_scp_clk(struct platform_device *dsidev)
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +03001239{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301240 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1241
1242 WARN_ON(dsi->scp_clk_refcount == 0);
1243 if (--dsi->scp_clk_refcount == 0)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301244 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 14, 14); /* CIO_CLK_ICG */
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +03001245}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001246
1247enum dsi_pll_power_state {
1248 DSI_PLL_POWER_OFF = 0x0,
1249 DSI_PLL_POWER_ON_HSCLK = 0x1,
1250 DSI_PLL_POWER_ON_ALL = 0x2,
1251 DSI_PLL_POWER_ON_DIV = 0x3,
1252};
1253
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301254static int dsi_pll_power(struct platform_device *dsidev,
1255 enum dsi_pll_power_state state)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001256{
1257 int t = 0;
1258
Tomi Valkeinenc94dfe02011-04-15 10:42:59 +03001259 /* DSI-PLL power command 0x3 is not working */
1260 if (dss_has_feature(FEAT_DSI_PLL_PWR_BUG) &&
1261 state == DSI_PLL_POWER_ON_DIV)
1262 state = DSI_PLL_POWER_ON_ALL;
1263
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301264 /* PLL_PWR_CMD */
1265 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, state, 31, 30);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001266
1267 /* PLL_PWR_STATUS */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301268 while (FLD_GET(dsi_read_reg(dsidev, DSI_CLK_CTRL), 29, 28) != state) {
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02001269 if (++t > 1000) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001270 DSSERR("Failed to set DSI PLL power mode to %d\n",
1271 state);
1272 return -ENODEV;
1273 }
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02001274 udelay(1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001275 }
1276
1277 return 0;
1278}
1279
1280/* calculate clock rates using dividers in cinfo */
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02001281static int dsi_calc_clock_rates(struct platform_device *dsidev,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00001282 struct dsi_clock_info *cinfo)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001283{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301284 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1285
1286 if (cinfo->regn == 0 || cinfo->regn > dsi->regn_max)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001287 return -EINVAL;
1288
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301289 if (cinfo->regm == 0 || cinfo->regm > dsi->regm_max)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001290 return -EINVAL;
1291
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301292 if (cinfo->regm_dispc > dsi->regm_dispc_max)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001293 return -EINVAL;
1294
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301295 if (cinfo->regm_dsi > dsi->regm_dsi_max)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001296 return -EINVAL;
1297
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02001298 cinfo->clkin = clk_get_rate(dsi->sys_clk);
1299 cinfo->fint = cinfo->clkin / cinfo->regn;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001300
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301301 if (cinfo->fint > dsi->fint_max || cinfo->fint < dsi->fint_min)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001302 return -EINVAL;
1303
1304 cinfo->clkin4ddr = 2 * cinfo->regm * cinfo->fint;
1305
1306 if (cinfo->clkin4ddr > 1800 * 1000 * 1000)
1307 return -EINVAL;
1308
Archit Taneja1bb47832011-02-24 14:17:30 +05301309 if (cinfo->regm_dispc > 0)
1310 cinfo->dsi_pll_hsdiv_dispc_clk =
1311 cinfo->clkin4ddr / cinfo->regm_dispc;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001312 else
Archit Taneja1bb47832011-02-24 14:17:30 +05301313 cinfo->dsi_pll_hsdiv_dispc_clk = 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001314
Archit Taneja1bb47832011-02-24 14:17:30 +05301315 if (cinfo->regm_dsi > 0)
1316 cinfo->dsi_pll_hsdiv_dsi_clk =
1317 cinfo->clkin4ddr / cinfo->regm_dsi;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001318 else
Archit Taneja1bb47832011-02-24 14:17:30 +05301319 cinfo->dsi_pll_hsdiv_dsi_clk = 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001320
1321 return 0;
1322}
1323
Archit Taneja6d523e72012-06-21 09:33:55 +05301324int dsi_pll_calc_clock_div_pck(struct platform_device *dsidev,
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301325 unsigned long req_pck, struct dsi_clock_info *dsi_cinfo,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001326 struct dispc_clock_info *dispc_cinfo)
1327{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301328 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001329 struct dsi_clock_info cur, best;
1330 struct dispc_clock_info best_dispc;
1331 int min_fck_per_pck;
1332 int match = 0;
Archit Taneja1bb47832011-02-24 14:17:30 +05301333 unsigned long dss_sys_clk, max_dss_fck;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001334
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001335 dss_sys_clk = clk_get_rate(dsi->sys_clk);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001336
Taneja, Archit31ef8232011-03-14 23:28:22 -05001337 max_dss_fck = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK);
Archit Taneja819d8072011-03-01 11:54:00 +05301338
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301339 if (req_pck == dsi->cache_req_pck &&
1340 dsi->cache_cinfo.clkin == dss_sys_clk) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001341 DSSDBG("DSI clock info found from cache\n");
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301342 *dsi_cinfo = dsi->cache_cinfo;
Archit Taneja6d523e72012-06-21 09:33:55 +05301343 dispc_find_clk_divs(req_pck, dsi_cinfo->dsi_pll_hsdiv_dispc_clk,
1344 dispc_cinfo);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001345 return 0;
1346 }
1347
1348 min_fck_per_pck = CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK;
1349
1350 if (min_fck_per_pck &&
Archit Taneja819d8072011-03-01 11:54:00 +05301351 req_pck * min_fck_per_pck > max_dss_fck) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001352 DSSERR("Requested pixel clock not possible with the current "
1353 "OMAP2_DSS_MIN_FCK_PER_PCK setting. Turning "
1354 "the constraint off.\n");
1355 min_fck_per_pck = 0;
1356 }
1357
1358 DSSDBG("dsi_pll_calc\n");
1359
1360retry:
1361 memset(&best, 0, sizeof(best));
1362 memset(&best_dispc, 0, sizeof(best_dispc));
1363
1364 memset(&cur, 0, sizeof(cur));
Archit Taneja1bb47832011-02-24 14:17:30 +05301365 cur.clkin = dss_sys_clk;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001366
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02001367 /* 0.75MHz < Fint = clkin / regn < 2.1MHz */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001368 /* To reduce PLL lock time, keep Fint high (around 2 MHz) */
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301369 for (cur.regn = 1; cur.regn < dsi->regn_max; ++cur.regn) {
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02001370 cur.fint = cur.clkin / cur.regn;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001371
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301372 if (cur.fint > dsi->fint_max || cur.fint < dsi->fint_min)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001373 continue;
1374
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02001375 /* DSIPHY(MHz) = (2 * regm / regn) * clkin */
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301376 for (cur.regm = 1; cur.regm < dsi->regm_max; ++cur.regm) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001377 unsigned long a, b;
1378
1379 a = 2 * cur.regm * (cur.clkin/1000);
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02001380 b = cur.regn;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001381 cur.clkin4ddr = a / b * 1000;
1382
1383 if (cur.clkin4ddr > 1800 * 1000 * 1000)
1384 break;
1385
Archit Taneja1bb47832011-02-24 14:17:30 +05301386 /* dsi_pll_hsdiv_dispc_clk(MHz) =
1387 * DSIPHY(MHz) / regm_dispc < 173MHz/186Mhz */
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301388 for (cur.regm_dispc = 1; cur.regm_dispc <
1389 dsi->regm_dispc_max; ++cur.regm_dispc) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001390 struct dispc_clock_info cur_dispc;
Archit Taneja1bb47832011-02-24 14:17:30 +05301391 cur.dsi_pll_hsdiv_dispc_clk =
1392 cur.clkin4ddr / cur.regm_dispc;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001393
1394 /* this will narrow down the search a bit,
1395 * but still give pixclocks below what was
1396 * requested */
Archit Taneja1bb47832011-02-24 14:17:30 +05301397 if (cur.dsi_pll_hsdiv_dispc_clk < req_pck)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001398 break;
1399
Archit Taneja1bb47832011-02-24 14:17:30 +05301400 if (cur.dsi_pll_hsdiv_dispc_clk > max_dss_fck)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001401 continue;
1402
1403 if (min_fck_per_pck &&
Archit Taneja1bb47832011-02-24 14:17:30 +05301404 cur.dsi_pll_hsdiv_dispc_clk <
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001405 req_pck * min_fck_per_pck)
1406 continue;
1407
1408 match = 1;
1409
Archit Taneja6d523e72012-06-21 09:33:55 +05301410 dispc_find_clk_divs(req_pck,
Archit Taneja1bb47832011-02-24 14:17:30 +05301411 cur.dsi_pll_hsdiv_dispc_clk,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001412 &cur_dispc);
1413
1414 if (abs(cur_dispc.pck - req_pck) <
1415 abs(best_dispc.pck - req_pck)) {
1416 best = cur;
1417 best_dispc = cur_dispc;
1418
1419 if (cur_dispc.pck == req_pck)
1420 goto found;
1421 }
1422 }
1423 }
1424 }
1425found:
1426 if (!match) {
1427 if (min_fck_per_pck) {
1428 DSSERR("Could not find suitable clock settings.\n"
1429 "Turning FCK/PCK constraint off and"
1430 "trying again.\n");
1431 min_fck_per_pck = 0;
1432 goto retry;
1433 }
1434
1435 DSSERR("Could not find suitable clock settings.\n");
1436
1437 return -EINVAL;
1438 }
1439
Archit Taneja1bb47832011-02-24 14:17:30 +05301440 /* dsi_pll_hsdiv_dsi_clk (regm_dsi) is not used */
1441 best.regm_dsi = 0;
1442 best.dsi_pll_hsdiv_dsi_clk = 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001443
1444 if (dsi_cinfo)
1445 *dsi_cinfo = best;
1446 if (dispc_cinfo)
1447 *dispc_cinfo = best_dispc;
1448
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301449 dsi->cache_req_pck = req_pck;
1450 dsi->cache_clk_freq = 0;
1451 dsi->cache_cinfo = best;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001452
1453 return 0;
1454}
1455
Tomi Valkeinenee144e62012-08-10 16:50:51 +03001456static int dsi_pll_calc_ddrfreq(struct platform_device *dsidev,
Tomi Valkeinend66b1582012-09-24 15:15:06 +03001457 unsigned long req_clkin4ddr, struct dsi_clock_info *cinfo)
Tomi Valkeinenee144e62012-08-10 16:50:51 +03001458{
1459 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1460 struct dsi_clock_info cur, best;
Tomi Valkeinenee144e62012-08-10 16:50:51 +03001461
1462 DSSDBG("dsi_pll_calc_ddrfreq\n");
1463
Tomi Valkeinenee144e62012-08-10 16:50:51 +03001464 memset(&best, 0, sizeof(best));
1465 memset(&cur, 0, sizeof(cur));
1466
Tomi Valkeinend66b1582012-09-24 15:15:06 +03001467 cur.clkin = clk_get_rate(dsi->sys_clk);
Tomi Valkeinenee144e62012-08-10 16:50:51 +03001468
1469 for (cur.regn = 1; cur.regn < dsi->regn_max; ++cur.regn) {
1470 cur.fint = cur.clkin / cur.regn;
1471
1472 if (cur.fint > dsi->fint_max || cur.fint < dsi->fint_min)
1473 continue;
1474
1475 /* DSIPHY(MHz) = (2 * regm / regn) * clkin */
1476 for (cur.regm = 1; cur.regm < dsi->regm_max; ++cur.regm) {
1477 unsigned long a, b;
1478
1479 a = 2 * cur.regm * (cur.clkin/1000);
1480 b = cur.regn;
1481 cur.clkin4ddr = a / b * 1000;
1482
1483 if (cur.clkin4ddr > 1800 * 1000 * 1000)
1484 break;
1485
1486 if (abs(cur.clkin4ddr - req_clkin4ddr) <
1487 abs(best.clkin4ddr - req_clkin4ddr)) {
1488 best = cur;
1489 DSSDBG("best %ld\n", best.clkin4ddr);
1490 }
1491
1492 if (cur.clkin4ddr == req_clkin4ddr)
1493 goto found;
1494 }
1495 }
1496found:
Tomi Valkeinenee144e62012-08-10 16:50:51 +03001497 if (cinfo)
1498 *cinfo = best;
1499
1500 return 0;
1501}
1502
Tomi Valkeinend66b1582012-09-24 15:15:06 +03001503static void dsi_pll_calc_dsi_fck(struct platform_device *dsidev,
1504 struct dsi_clock_info *cinfo)
1505{
1506 unsigned long max_dsi_fck;
1507
1508 max_dsi_fck = dss_feat_get_param_max(FEAT_PARAM_DSI_FCK);
1509
1510 cinfo->regm_dsi = DIV_ROUND_UP(cinfo->clkin4ddr, max_dsi_fck);
1511 cinfo->dsi_pll_hsdiv_dsi_clk = cinfo->clkin4ddr / cinfo->regm_dsi;
1512}
1513
1514static int dsi_pll_calc_dispc_fck(struct platform_device *dsidev,
1515 unsigned long req_pck, struct dsi_clock_info *cinfo,
1516 struct dispc_clock_info *dispc_cinfo)
1517{
1518 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1519 unsigned regm_dispc, best_regm_dispc;
1520 unsigned long dispc_clk, best_dispc_clk;
1521 int min_fck_per_pck;
1522 unsigned long max_dss_fck;
1523 struct dispc_clock_info best_dispc;
1524 bool match;
1525
1526 max_dss_fck = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK);
1527
1528 min_fck_per_pck = CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK;
1529
1530 if (min_fck_per_pck &&
1531 req_pck * min_fck_per_pck > max_dss_fck) {
1532 DSSERR("Requested pixel clock not possible with the current "
1533 "OMAP2_DSS_MIN_FCK_PER_PCK setting. Turning "
1534 "the constraint off.\n");
1535 min_fck_per_pck = 0;
1536 }
1537
1538retry:
1539 best_regm_dispc = 0;
1540 best_dispc_clk = 0;
1541 memset(&best_dispc, 0, sizeof(best_dispc));
1542 match = false;
1543
1544 for (regm_dispc = 1; regm_dispc < dsi->regm_dispc_max; ++regm_dispc) {
1545 struct dispc_clock_info cur_dispc;
1546
1547 dispc_clk = cinfo->clkin4ddr / regm_dispc;
1548
1549 /* this will narrow down the search a bit,
1550 * but still give pixclocks below what was
1551 * requested */
1552 if (dispc_clk < req_pck)
1553 break;
1554
1555 if (dispc_clk > max_dss_fck)
1556 continue;
1557
1558 if (min_fck_per_pck && dispc_clk < req_pck * min_fck_per_pck)
1559 continue;
1560
1561 match = true;
1562
1563 dispc_find_clk_divs(req_pck, dispc_clk, &cur_dispc);
1564
1565 if (abs(cur_dispc.pck - req_pck) <
1566 abs(best_dispc.pck - req_pck)) {
1567 best_regm_dispc = regm_dispc;
1568 best_dispc_clk = dispc_clk;
1569 best_dispc = cur_dispc;
1570
1571 if (cur_dispc.pck == req_pck)
1572 goto found;
1573 }
1574 }
1575
1576 if (!match) {
1577 if (min_fck_per_pck) {
1578 DSSERR("Could not find suitable clock settings.\n"
1579 "Turning FCK/PCK constraint off and"
1580 "trying again.\n");
1581 min_fck_per_pck = 0;
1582 goto retry;
1583 }
1584
1585 DSSERR("Could not find suitable clock settings.\n");
1586
1587 return -EINVAL;
1588 }
1589found:
1590 cinfo->regm_dispc = best_regm_dispc;
1591 cinfo->dsi_pll_hsdiv_dispc_clk = best_dispc_clk;
1592
1593 *dispc_cinfo = best_dispc;
1594
1595 return 0;
1596}
1597
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301598int dsi_pll_set_clock_div(struct platform_device *dsidev,
1599 struct dsi_clock_info *cinfo)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001600{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301601 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001602 int r = 0;
1603 u32 l;
Archit Taneja9613c022011-03-22 06:33:36 -05001604 int f = 0;
Taneja, Archit49641112011-03-14 23:28:23 -05001605 u8 regn_start, regn_end, regm_start, regm_end;
1606 u8 regm_dispc_start, regm_dispc_end, regm_dsi_start, regm_dsi_end;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001607
1608 DSSDBGF();
1609
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02001610 dsi->current_cinfo.clkin = cinfo->clkin;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301611 dsi->current_cinfo.fint = cinfo->fint;
1612 dsi->current_cinfo.clkin4ddr = cinfo->clkin4ddr;
1613 dsi->current_cinfo.dsi_pll_hsdiv_dispc_clk =
Archit Taneja1bb47832011-02-24 14:17:30 +05301614 cinfo->dsi_pll_hsdiv_dispc_clk;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301615 dsi->current_cinfo.dsi_pll_hsdiv_dsi_clk =
Archit Taneja1bb47832011-02-24 14:17:30 +05301616 cinfo->dsi_pll_hsdiv_dsi_clk;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001617
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301618 dsi->current_cinfo.regn = cinfo->regn;
1619 dsi->current_cinfo.regm = cinfo->regm;
1620 dsi->current_cinfo.regm_dispc = cinfo->regm_dispc;
1621 dsi->current_cinfo.regm_dsi = cinfo->regm_dsi;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001622
1623 DSSDBG("DSI Fint %ld\n", cinfo->fint);
1624
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02001625 DSSDBG("clkin rate %ld\n", cinfo->clkin);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001626
1627 /* DSIPHY == CLKIN4DDR */
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02001628 DSSDBG("CLKIN4DDR = 2 * %d / %d * %lu = %lu\n",
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001629 cinfo->regm,
1630 cinfo->regn,
1631 cinfo->clkin,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001632 cinfo->clkin4ddr);
1633
1634 DSSDBG("Data rate on 1 DSI lane %ld Mbps\n",
1635 cinfo->clkin4ddr / 1000 / 1000 / 2);
1636
1637 DSSDBG("Clock lane freq %ld Hz\n", cinfo->clkin4ddr / 4);
1638
Archit Taneja1bb47832011-02-24 14:17:30 +05301639 DSSDBG("regm_dispc = %d, %s (%s) = %lu\n", cinfo->regm_dispc,
Archit Taneja89a35e52011-04-12 13:52:23 +05301640 dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
1641 dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
Archit Taneja1bb47832011-02-24 14:17:30 +05301642 cinfo->dsi_pll_hsdiv_dispc_clk);
1643 DSSDBG("regm_dsi = %d, %s (%s) = %lu\n", cinfo->regm_dsi,
Archit Taneja89a35e52011-04-12 13:52:23 +05301644 dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
1645 dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
Archit Taneja1bb47832011-02-24 14:17:30 +05301646 cinfo->dsi_pll_hsdiv_dsi_clk);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001647
Taneja, Archit49641112011-03-14 23:28:23 -05001648 dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGN, &regn_start, &regn_end);
1649 dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM, &regm_start, &regm_end);
1650 dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM_DISPC, &regm_dispc_start,
1651 &regm_dispc_end);
1652 dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM_DSI, &regm_dsi_start,
1653 &regm_dsi_end);
1654
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301655 /* DSI_PLL_AUTOMODE = manual */
1656 REG_FLD_MOD(dsidev, DSI_PLL_CONTROL, 0, 0, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001657
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301658 l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001659 l = FLD_MOD(l, 1, 0, 0); /* DSI_PLL_STOPMODE */
Taneja, Archit49641112011-03-14 23:28:23 -05001660 /* DSI_PLL_REGN */
1661 l = FLD_MOD(l, cinfo->regn - 1, regn_start, regn_end);
1662 /* DSI_PLL_REGM */
1663 l = FLD_MOD(l, cinfo->regm, regm_start, regm_end);
1664 /* DSI_CLOCK_DIV */
Archit Taneja1bb47832011-02-24 14:17:30 +05301665 l = FLD_MOD(l, cinfo->regm_dispc > 0 ? cinfo->regm_dispc - 1 : 0,
Taneja, Archit49641112011-03-14 23:28:23 -05001666 regm_dispc_start, regm_dispc_end);
1667 /* DSIPROTO_CLOCK_DIV */
Archit Taneja1bb47832011-02-24 14:17:30 +05301668 l = FLD_MOD(l, cinfo->regm_dsi > 0 ? cinfo->regm_dsi - 1 : 0,
Taneja, Archit49641112011-03-14 23:28:23 -05001669 regm_dsi_start, regm_dsi_end);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301670 dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION1, l);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001671
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301672 BUG_ON(cinfo->fint < dsi->fint_min || cinfo->fint > dsi->fint_max);
Archit Taneja9613c022011-03-22 06:33:36 -05001673
Tomi Valkeinenf8ef3d62012-08-22 16:00:31 +03001674 l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION2);
1675
Archit Taneja9613c022011-03-22 06:33:36 -05001676 if (dss_has_feature(FEAT_DSI_PLL_FREQSEL)) {
1677 f = cinfo->fint < 1000000 ? 0x3 :
1678 cinfo->fint < 1250000 ? 0x4 :
1679 cinfo->fint < 1500000 ? 0x5 :
1680 cinfo->fint < 1750000 ? 0x6 :
1681 0x7;
Tomi Valkeinenf8ef3d62012-08-22 16:00:31 +03001682
1683 l = FLD_MOD(l, f, 4, 1); /* DSI_PLL_FREQSEL */
1684 } else if (dss_has_feature(FEAT_DSI_PLL_SELFREQDCO)) {
1685 f = cinfo->clkin4ddr < 1000000000 ? 0x2 : 0x4;
1686
1687 l = FLD_MOD(l, f, 4, 1); /* PLL_SELFREQDCO */
Archit Taneja9613c022011-03-22 06:33:36 -05001688 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001689
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001690 l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */
1691 l = FLD_MOD(l, 0, 14, 14); /* DSIPHY_CLKINEN */
1692 l = FLD_MOD(l, 1, 20, 20); /* DSI_HSDIVBYPASS */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301693 dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION2, l);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001694
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301695 REG_FLD_MOD(dsidev, DSI_PLL_GO, 1, 0, 0); /* DSI_PLL_GO */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001696
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301697 if (wait_for_bit_change(dsidev, DSI_PLL_GO, 0, 0) != 0) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001698 DSSERR("dsi pll go bit not going down.\n");
1699 r = -EIO;
1700 goto err;
1701 }
1702
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301703 if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 1, 1) != 1) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001704 DSSERR("cannot lock PLL\n");
1705 r = -EIO;
1706 goto err;
1707 }
1708
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301709 dsi->pll_locked = 1;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001710
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301711 l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION2);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001712 l = FLD_MOD(l, 0, 0, 0); /* DSI_PLL_IDLE */
1713 l = FLD_MOD(l, 0, 5, 5); /* DSI_PLL_PLLLPMODE */
1714 l = FLD_MOD(l, 0, 6, 6); /* DSI_PLL_LOWCURRSTBY */
1715 l = FLD_MOD(l, 0, 7, 7); /* DSI_PLL_TIGHTPHASELOCK */
1716 l = FLD_MOD(l, 0, 8, 8); /* DSI_PLL_DRIFTGUARDEN */
1717 l = FLD_MOD(l, 0, 10, 9); /* DSI_PLL_LOCKSEL */
1718 l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */
1719 l = FLD_MOD(l, 1, 14, 14); /* DSIPHY_CLKINEN */
1720 l = FLD_MOD(l, 0, 15, 15); /* DSI_BYPASSEN */
1721 l = FLD_MOD(l, 1, 16, 16); /* DSS_CLOCK_EN */
1722 l = FLD_MOD(l, 0, 17, 17); /* DSS_CLOCK_PWDN */
1723 l = FLD_MOD(l, 1, 18, 18); /* DSI_PROTO_CLOCK_EN */
1724 l = FLD_MOD(l, 0, 19, 19); /* DSI_PROTO_CLOCK_PWDN */
1725 l = FLD_MOD(l, 0, 20, 20); /* DSI_HSDIVBYPASS */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301726 dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION2, l);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001727
1728 DSSDBG("PLL config done\n");
1729err:
1730 return r;
1731}
1732
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301733int dsi_pll_init(struct platform_device *dsidev, bool enable_hsclk,
1734 bool enable_hsdiv)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001735{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301736 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001737 int r = 0;
1738 enum dsi_pll_power_state pwstate;
1739
1740 DSSDBG("PLL init\n");
1741
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301742 if (dsi->vdds_dsi_reg == NULL) {
Tomi Valkeinenf2988ab2011-03-02 10:06:48 +02001743 struct regulator *vdds_dsi;
1744
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301745 vdds_dsi = regulator_get(&dsi->pdev->dev, "vdds_dsi");
Tomi Valkeinenf2988ab2011-03-02 10:06:48 +02001746
1747 if (IS_ERR(vdds_dsi)) {
1748 DSSERR("can't get VDDS_DSI regulator\n");
1749 return PTR_ERR(vdds_dsi);
1750 }
1751
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301752 dsi->vdds_dsi_reg = vdds_dsi;
Tomi Valkeinenf2988ab2011-03-02 10:06:48 +02001753 }
Tomi Valkeinenf2988ab2011-03-02 10:06:48 +02001754
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301755 dsi_enable_pll_clock(dsidev, 1);
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +03001756 /*
1757 * Note: SCP CLK is not required on OMAP3, but it is required on OMAP4.
1758 */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301759 dsi_enable_scp_clk(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001760
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301761 if (!dsi->vdds_dsi_enabled) {
1762 r = regulator_enable(dsi->vdds_dsi_reg);
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +03001763 if (r)
1764 goto err0;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301765 dsi->vdds_dsi_enabled = true;
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +03001766 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001767
1768 /* XXX PLL does not come out of reset without this... */
1769 dispc_pck_free_enable(1);
1770
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301771 if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 0, 1) != 1) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001772 DSSERR("PLL not coming out of reset.\n");
1773 r = -ENODEV;
Ville Syrjälä481dfa02010-04-22 22:50:04 +02001774 dispc_pck_free_enable(0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001775 goto err1;
1776 }
1777
1778 /* XXX ... but if left on, we get problems when planes do not
1779 * fill the whole display. No idea about this */
1780 dispc_pck_free_enable(0);
1781
1782 if (enable_hsclk && enable_hsdiv)
1783 pwstate = DSI_PLL_POWER_ON_ALL;
1784 else if (enable_hsclk)
1785 pwstate = DSI_PLL_POWER_ON_HSCLK;
1786 else if (enable_hsdiv)
1787 pwstate = DSI_PLL_POWER_ON_DIV;
1788 else
1789 pwstate = DSI_PLL_POWER_OFF;
1790
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301791 r = dsi_pll_power(dsidev, pwstate);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001792
1793 if (r)
1794 goto err1;
1795
1796 DSSDBG("PLL init done\n");
1797
1798 return 0;
1799err1:
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301800 if (dsi->vdds_dsi_enabled) {
1801 regulator_disable(dsi->vdds_dsi_reg);
1802 dsi->vdds_dsi_enabled = false;
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +03001803 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001804err0:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301805 dsi_disable_scp_clk(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301806 dsi_enable_pll_clock(dsidev, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001807 return r;
1808}
1809
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301810void dsi_pll_uninit(struct platform_device *dsidev, bool disconnect_lanes)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001811{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301812 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1813
1814 dsi->pll_locked = 0;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301815 dsi_pll_power(dsidev, DSI_PLL_POWER_OFF);
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +03001816 if (disconnect_lanes) {
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301817 WARN_ON(!dsi->vdds_dsi_enabled);
1818 regulator_disable(dsi->vdds_dsi_reg);
1819 dsi->vdds_dsi_enabled = false;
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +03001820 }
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +03001821
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301822 dsi_disable_scp_clk(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301823 dsi_enable_pll_clock(dsidev, 0);
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +03001824
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001825 DSSDBG("PLL uninit done\n");
1826}
1827
Archit Taneja5a8b5722011-05-12 17:26:29 +05301828static void dsi_dump_dsidev_clocks(struct platform_device *dsidev,
1829 struct seq_file *s)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001830{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301831 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1832 struct dsi_clock_info *cinfo = &dsi->current_cinfo;
Archit Taneja89a35e52011-04-12 13:52:23 +05301833 enum omap_dss_clk_source dispc_clk_src, dsi_clk_src;
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02001834 int dsi_module = dsi->module_id;
Archit Taneja067a57e2011-03-02 11:57:25 +05301835
1836 dispc_clk_src = dss_get_dispc_clk_source();
Archit Taneja5a8b5722011-05-12 17:26:29 +05301837 dsi_clk_src = dss_get_dsi_clk_source(dsi_module);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001838
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001839 if (dsi_runtime_get(dsidev))
1840 return;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001841
Archit Taneja5a8b5722011-05-12 17:26:29 +05301842 seq_printf(s, "- DSI%d PLL -\n", dsi_module + 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001843
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02001844 seq_printf(s, "dsi pll clkin\t%lu\n", cinfo->clkin);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001845
1846 seq_printf(s, "Fint\t\t%-16luregn %u\n", cinfo->fint, cinfo->regn);
1847
1848 seq_printf(s, "CLKIN4DDR\t%-16luregm %u\n",
1849 cinfo->clkin4ddr, cinfo->regm);
1850
Archit Taneja84309f12011-12-12 11:47:41 +05301851 seq_printf(s, "DSI_PLL_HSDIV_DISPC (%s)\t%-16luregm_dispc %u\t(%s)\n",
1852 dss_feat_get_clk_source_name(dsi_module == 0 ?
1853 OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC :
1854 OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC),
Archit Taneja1bb47832011-02-24 14:17:30 +05301855 cinfo->dsi_pll_hsdiv_dispc_clk,
1856 cinfo->regm_dispc,
Archit Taneja89a35e52011-04-12 13:52:23 +05301857 dispc_clk_src == OMAP_DSS_CLK_SRC_FCK ?
Tomi Valkeinen63cf28a2010-02-23 17:40:00 +02001858 "off" : "on");
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001859
Archit Taneja84309f12011-12-12 11:47:41 +05301860 seq_printf(s, "DSI_PLL_HSDIV_DSI (%s)\t%-16luregm_dsi %u\t(%s)\n",
1861 dss_feat_get_clk_source_name(dsi_module == 0 ?
1862 OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI :
1863 OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DSI),
Archit Taneja1bb47832011-02-24 14:17:30 +05301864 cinfo->dsi_pll_hsdiv_dsi_clk,
1865 cinfo->regm_dsi,
Archit Taneja89a35e52011-04-12 13:52:23 +05301866 dsi_clk_src == OMAP_DSS_CLK_SRC_FCK ?
Tomi Valkeinen63cf28a2010-02-23 17:40:00 +02001867 "off" : "on");
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001868
Archit Taneja5a8b5722011-05-12 17:26:29 +05301869 seq_printf(s, "- DSI%d -\n", dsi_module + 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001870
Archit Taneja067a57e2011-03-02 11:57:25 +05301871 seq_printf(s, "dsi fclk source = %s (%s)\n",
1872 dss_get_generic_clk_source_name(dsi_clk_src),
1873 dss_feat_get_clk_source_name(dsi_clk_src));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001874
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301875 seq_printf(s, "DSI_FCLK\t%lu\n", dsi_fclk_rate(dsidev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001876
1877 seq_printf(s, "DDR_CLK\t\t%lu\n",
1878 cinfo->clkin4ddr / 4);
1879
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301880 seq_printf(s, "TxByteClkHS\t%lu\n", dsi_get_txbyteclkhs(dsidev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001881
1882 seq_printf(s, "LP_CLK\t\t%lu\n", cinfo->lp_clk);
1883
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001884 dsi_runtime_put(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001885}
1886
Archit Taneja5a8b5722011-05-12 17:26:29 +05301887void dsi_dump_clocks(struct seq_file *s)
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001888{
Archit Taneja5a8b5722011-05-12 17:26:29 +05301889 struct platform_device *dsidev;
1890 int i;
1891
1892 for (i = 0; i < MAX_NUM_DSI; i++) {
1893 dsidev = dsi_get_dsidev_from_id(i);
1894 if (dsidev)
1895 dsi_dump_dsidev_clocks(dsidev, s);
1896 }
1897}
1898
1899#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
1900static void dsi_dump_dsidev_irqs(struct platform_device *dsidev,
1901 struct seq_file *s)
1902{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301903 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001904 unsigned long flags;
1905 struct dsi_irq_stats stats;
1906
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301907 spin_lock_irqsave(&dsi->irq_stats_lock, flags);
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001908
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301909 stats = dsi->irq_stats;
1910 memset(&dsi->irq_stats, 0, sizeof(dsi->irq_stats));
1911 dsi->irq_stats.last_reset = jiffies;
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001912
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301913 spin_unlock_irqrestore(&dsi->irq_stats_lock, flags);
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001914
1915 seq_printf(s, "period %u ms\n",
1916 jiffies_to_msecs(jiffies - stats.last_reset));
1917
1918 seq_printf(s, "irqs %d\n", stats.irq_count);
1919#define PIS(x) \
1920 seq_printf(s, "%-20s %10d\n", #x, stats.dsi_irqs[ffs(DSI_IRQ_##x)-1]);
1921
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02001922 seq_printf(s, "-- DSI%d interrupts --\n", dsi->module_id + 1);
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001923 PIS(VC0);
1924 PIS(VC1);
1925 PIS(VC2);
1926 PIS(VC3);
1927 PIS(WAKEUP);
1928 PIS(RESYNC);
1929 PIS(PLL_LOCK);
1930 PIS(PLL_UNLOCK);
1931 PIS(PLL_RECALL);
1932 PIS(COMPLEXIO_ERR);
1933 PIS(HS_TX_TIMEOUT);
1934 PIS(LP_RX_TIMEOUT);
1935 PIS(TE_TRIGGER);
1936 PIS(ACK_TRIGGER);
1937 PIS(SYNC_LOST);
1938 PIS(LDO_POWER_GOOD);
1939 PIS(TA_TIMEOUT);
1940#undef PIS
1941
1942#define PIS(x) \
1943 seq_printf(s, "%-20s %10d %10d %10d %10d\n", #x, \
1944 stats.vc_irqs[0][ffs(DSI_VC_IRQ_##x)-1], \
1945 stats.vc_irqs[1][ffs(DSI_VC_IRQ_##x)-1], \
1946 stats.vc_irqs[2][ffs(DSI_VC_IRQ_##x)-1], \
1947 stats.vc_irqs[3][ffs(DSI_VC_IRQ_##x)-1]);
1948
1949 seq_printf(s, "-- VC interrupts --\n");
1950 PIS(CS);
1951 PIS(ECC_CORR);
1952 PIS(PACKET_SENT);
1953 PIS(FIFO_TX_OVF);
1954 PIS(FIFO_RX_OVF);
1955 PIS(BTA);
1956 PIS(ECC_NO_CORR);
1957 PIS(FIFO_TX_UDF);
1958 PIS(PP_BUSY_CHANGE);
1959#undef PIS
1960
1961#define PIS(x) \
1962 seq_printf(s, "%-20s %10d\n", #x, \
1963 stats.cio_irqs[ffs(DSI_CIO_IRQ_##x)-1]);
1964
1965 seq_printf(s, "-- CIO interrupts --\n");
1966 PIS(ERRSYNCESC1);
1967 PIS(ERRSYNCESC2);
1968 PIS(ERRSYNCESC3);
1969 PIS(ERRESC1);
1970 PIS(ERRESC2);
1971 PIS(ERRESC3);
1972 PIS(ERRCONTROL1);
1973 PIS(ERRCONTROL2);
1974 PIS(ERRCONTROL3);
1975 PIS(STATEULPS1);
1976 PIS(STATEULPS2);
1977 PIS(STATEULPS3);
1978 PIS(ERRCONTENTIONLP0_1);
1979 PIS(ERRCONTENTIONLP1_1);
1980 PIS(ERRCONTENTIONLP0_2);
1981 PIS(ERRCONTENTIONLP1_2);
1982 PIS(ERRCONTENTIONLP0_3);
1983 PIS(ERRCONTENTIONLP1_3);
1984 PIS(ULPSACTIVENOT_ALL0);
1985 PIS(ULPSACTIVENOT_ALL1);
1986#undef PIS
1987}
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001988
Archit Taneja5a8b5722011-05-12 17:26:29 +05301989static void dsi1_dump_irqs(struct seq_file *s)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001990{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301991 struct platform_device *dsidev = dsi_get_dsidev_from_id(0);
1992
Archit Taneja5a8b5722011-05-12 17:26:29 +05301993 dsi_dump_dsidev_irqs(dsidev, s);
1994}
1995
1996static void dsi2_dump_irqs(struct seq_file *s)
1997{
1998 struct platform_device *dsidev = dsi_get_dsidev_from_id(1);
1999
2000 dsi_dump_dsidev_irqs(dsidev, s);
2001}
Archit Taneja5a8b5722011-05-12 17:26:29 +05302002#endif
2003
2004static void dsi_dump_dsidev_regs(struct platform_device *dsidev,
2005 struct seq_file *s)
2006{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302007#define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dsi_read_reg(dsidev, r))
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002008
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03002009 if (dsi_runtime_get(dsidev))
2010 return;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302011 dsi_enable_scp_clk(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002012
2013 DUMPREG(DSI_REVISION);
2014 DUMPREG(DSI_SYSCONFIG);
2015 DUMPREG(DSI_SYSSTATUS);
2016 DUMPREG(DSI_IRQSTATUS);
2017 DUMPREG(DSI_IRQENABLE);
2018 DUMPREG(DSI_CTRL);
2019 DUMPREG(DSI_COMPLEXIO_CFG1);
2020 DUMPREG(DSI_COMPLEXIO_IRQ_STATUS);
2021 DUMPREG(DSI_COMPLEXIO_IRQ_ENABLE);
2022 DUMPREG(DSI_CLK_CTRL);
2023 DUMPREG(DSI_TIMING1);
2024 DUMPREG(DSI_TIMING2);
2025 DUMPREG(DSI_VM_TIMING1);
2026 DUMPREG(DSI_VM_TIMING2);
2027 DUMPREG(DSI_VM_TIMING3);
2028 DUMPREG(DSI_CLK_TIMING);
2029 DUMPREG(DSI_TX_FIFO_VC_SIZE);
2030 DUMPREG(DSI_RX_FIFO_VC_SIZE);
2031 DUMPREG(DSI_COMPLEXIO_CFG2);
2032 DUMPREG(DSI_RX_FIFO_VC_FULLNESS);
2033 DUMPREG(DSI_VM_TIMING4);
2034 DUMPREG(DSI_TX_FIFO_VC_EMPTINESS);
2035 DUMPREG(DSI_VM_TIMING5);
2036 DUMPREG(DSI_VM_TIMING6);
2037 DUMPREG(DSI_VM_TIMING7);
2038 DUMPREG(DSI_STOPCLK_TIMING);
2039
2040 DUMPREG(DSI_VC_CTRL(0));
2041 DUMPREG(DSI_VC_TE(0));
2042 DUMPREG(DSI_VC_LONG_PACKET_HEADER(0));
2043 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(0));
2044 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(0));
2045 DUMPREG(DSI_VC_IRQSTATUS(0));
2046 DUMPREG(DSI_VC_IRQENABLE(0));
2047
2048 DUMPREG(DSI_VC_CTRL(1));
2049 DUMPREG(DSI_VC_TE(1));
2050 DUMPREG(DSI_VC_LONG_PACKET_HEADER(1));
2051 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(1));
2052 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(1));
2053 DUMPREG(DSI_VC_IRQSTATUS(1));
2054 DUMPREG(DSI_VC_IRQENABLE(1));
2055
2056 DUMPREG(DSI_VC_CTRL(2));
2057 DUMPREG(DSI_VC_TE(2));
2058 DUMPREG(DSI_VC_LONG_PACKET_HEADER(2));
2059 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(2));
2060 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(2));
2061 DUMPREG(DSI_VC_IRQSTATUS(2));
2062 DUMPREG(DSI_VC_IRQENABLE(2));
2063
2064 DUMPREG(DSI_VC_CTRL(3));
2065 DUMPREG(DSI_VC_TE(3));
2066 DUMPREG(DSI_VC_LONG_PACKET_HEADER(3));
2067 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(3));
2068 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(3));
2069 DUMPREG(DSI_VC_IRQSTATUS(3));
2070 DUMPREG(DSI_VC_IRQENABLE(3));
2071
2072 DUMPREG(DSI_DSIPHY_CFG0);
2073 DUMPREG(DSI_DSIPHY_CFG1);
2074 DUMPREG(DSI_DSIPHY_CFG2);
2075 DUMPREG(DSI_DSIPHY_CFG5);
2076
2077 DUMPREG(DSI_PLL_CONTROL);
2078 DUMPREG(DSI_PLL_STATUS);
2079 DUMPREG(DSI_PLL_GO);
2080 DUMPREG(DSI_PLL_CONFIGURATION1);
2081 DUMPREG(DSI_PLL_CONFIGURATION2);
2082
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302083 dsi_disable_scp_clk(dsidev);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03002084 dsi_runtime_put(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002085#undef DUMPREG
2086}
2087
Archit Taneja5a8b5722011-05-12 17:26:29 +05302088static void dsi1_dump_regs(struct seq_file *s)
2089{
2090 struct platform_device *dsidev = dsi_get_dsidev_from_id(0);
2091
2092 dsi_dump_dsidev_regs(dsidev, s);
2093}
2094
2095static void dsi2_dump_regs(struct seq_file *s)
2096{
2097 struct platform_device *dsidev = dsi_get_dsidev_from_id(1);
2098
2099 dsi_dump_dsidev_regs(dsidev, s);
2100}
2101
Tomi Valkeinencc5c1852010-10-06 15:18:13 +03002102enum dsi_cio_power_state {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002103 DSI_COMPLEXIO_POWER_OFF = 0x0,
2104 DSI_COMPLEXIO_POWER_ON = 0x1,
2105 DSI_COMPLEXIO_POWER_ULPS = 0x2,
2106};
2107
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302108static int dsi_cio_power(struct platform_device *dsidev,
2109 enum dsi_cio_power_state state)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002110{
2111 int t = 0;
2112
2113 /* PWR_CMD */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302114 REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG1, state, 28, 27);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002115
2116 /* PWR_STATUS */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302117 while (FLD_GET(dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1),
2118 26, 25) != state) {
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02002119 if (++t > 1000) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002120 DSSERR("failed to set complexio power state to "
2121 "%d\n", state);
2122 return -ENODEV;
2123 }
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02002124 udelay(1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002125 }
2126
2127 return 0;
2128}
2129
Archit Taneja0c656222011-05-16 15:17:09 +05302130static unsigned dsi_get_line_buf_size(struct platform_device *dsidev)
2131{
2132 int val;
2133
2134 /* line buffer on OMAP3 is 1024 x 24bits */
2135 /* XXX: for some reason using full buffer size causes
2136 * considerable TX slowdown with update sizes that fill the
2137 * whole buffer */
2138 if (!dss_has_feature(FEAT_DSI_GNQ))
2139 return 1023 * 3;
2140
2141 val = REG_GET(dsidev, DSI_GNQ, 14, 12); /* VP1_LINE_BUFFER_SIZE */
2142
2143 switch (val) {
2144 case 1:
2145 return 512 * 3; /* 512x24 bits */
2146 case 2:
2147 return 682 * 3; /* 682x24 bits */
2148 case 3:
2149 return 853 * 3; /* 853x24 bits */
2150 case 4:
2151 return 1024 * 3; /* 1024x24 bits */
2152 case 5:
2153 return 1194 * 3; /* 1194x24 bits */
2154 case 6:
2155 return 1365 * 3; /* 1365x24 bits */
2156 default:
2157 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002158 return 0;
Archit Taneja0c656222011-05-16 15:17:09 +05302159 }
2160}
2161
Tomi Valkeinen48368392011-10-13 11:22:39 +03002162static int dsi_set_lane_config(struct omap_dss_device *dssdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002163{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302164 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Tomi Valkeinen48368392011-10-13 11:22:39 +03002165 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2166 static const u8 offsets[] = { 0, 4, 8, 12, 16 };
2167 static const enum dsi_lane_function functions[] = {
2168 DSI_LANE_CLK,
2169 DSI_LANE_DATA1,
2170 DSI_LANE_DATA2,
2171 DSI_LANE_DATA3,
2172 DSI_LANE_DATA4,
2173 };
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002174 u32 r;
Tomi Valkeinen48368392011-10-13 11:22:39 +03002175 int i;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002176
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302177 r = dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1);
Archit Taneja75d72472011-05-16 15:17:08 +05302178
Tomi Valkeinen48368392011-10-13 11:22:39 +03002179 for (i = 0; i < dsi->num_lanes_used; ++i) {
2180 unsigned offset = offsets[i];
2181 unsigned polarity, lane_number;
2182 unsigned t;
Archit Taneja75d72472011-05-16 15:17:08 +05302183
Tomi Valkeinen48368392011-10-13 11:22:39 +03002184 for (t = 0; t < dsi->num_lanes_supported; ++t)
2185 if (dsi->lanes[t].function == functions[i])
2186 break;
2187
2188 if (t == dsi->num_lanes_supported)
2189 return -EINVAL;
2190
2191 lane_number = t;
2192 polarity = dsi->lanes[t].polarity;
2193
2194 r = FLD_MOD(r, lane_number + 1, offset + 2, offset);
2195 r = FLD_MOD(r, polarity, offset + 3, offset + 3);
Archit Taneja75d72472011-05-16 15:17:08 +05302196 }
Tomi Valkeinen48368392011-10-13 11:22:39 +03002197
2198 /* clear the unused lanes */
2199 for (; i < dsi->num_lanes_supported; ++i) {
2200 unsigned offset = offsets[i];
2201
2202 r = FLD_MOD(r, 0, offset + 2, offset);
2203 r = FLD_MOD(r, 0, offset + 3, offset + 3);
2204 }
2205
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302206 dsi_write_reg(dsidev, DSI_COMPLEXIO_CFG1, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002207
Tomi Valkeinen48368392011-10-13 11:22:39 +03002208 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002209}
2210
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302211static inline unsigned ns2ddr(struct platform_device *dsidev, unsigned ns)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002212{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302213 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2214
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002215 /* convert time in ns to ddr ticks, rounding up */
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302216 unsigned long ddr_clk = dsi->current_cinfo.clkin4ddr / 4;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002217 return (ns * (ddr_clk / 1000 / 1000) + 999) / 1000;
2218}
2219
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302220static inline unsigned ddr2ns(struct platform_device *dsidev, unsigned ddr)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002221{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302222 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2223
2224 unsigned long ddr_clk = dsi->current_cinfo.clkin4ddr / 4;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002225 return ddr * 1000 * 1000 / (ddr_clk / 1000);
2226}
2227
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302228static void dsi_cio_timings(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002229{
2230 u32 r;
2231 u32 ths_prepare, ths_prepare_ths_zero, ths_trail, ths_exit;
2232 u32 tlpx_half, tclk_trail, tclk_zero;
2233 u32 tclk_prepare;
2234
2235 /* calculate timings */
2236
2237 /* 1 * DDR_CLK = 2 * UI */
2238
2239 /* min 40ns + 4*UI max 85ns + 6*UI */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302240 ths_prepare = ns2ddr(dsidev, 70) + 2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002241
2242 /* min 145ns + 10*UI */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302243 ths_prepare_ths_zero = ns2ddr(dsidev, 175) + 2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002244
2245 /* min max(8*UI, 60ns+4*UI) */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302246 ths_trail = ns2ddr(dsidev, 60) + 5;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002247
2248 /* min 100ns */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302249 ths_exit = ns2ddr(dsidev, 145);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002250
2251 /* tlpx min 50n */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302252 tlpx_half = ns2ddr(dsidev, 25);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002253
2254 /* min 60ns */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302255 tclk_trail = ns2ddr(dsidev, 60) + 2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002256
2257 /* min 38ns, max 95ns */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302258 tclk_prepare = ns2ddr(dsidev, 65);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002259
2260 /* min tclk-prepare + tclk-zero = 300ns */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302261 tclk_zero = ns2ddr(dsidev, 260);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002262
2263 DSSDBG("ths_prepare %u (%uns), ths_prepare_ths_zero %u (%uns)\n",
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302264 ths_prepare, ddr2ns(dsidev, ths_prepare),
2265 ths_prepare_ths_zero, ddr2ns(dsidev, ths_prepare_ths_zero));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002266 DSSDBG("ths_trail %u (%uns), ths_exit %u (%uns)\n",
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302267 ths_trail, ddr2ns(dsidev, ths_trail),
2268 ths_exit, ddr2ns(dsidev, ths_exit));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002269
2270 DSSDBG("tlpx_half %u (%uns), tclk_trail %u (%uns), "
2271 "tclk_zero %u (%uns)\n",
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302272 tlpx_half, ddr2ns(dsidev, tlpx_half),
2273 tclk_trail, ddr2ns(dsidev, tclk_trail),
2274 tclk_zero, ddr2ns(dsidev, tclk_zero));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002275 DSSDBG("tclk_prepare %u (%uns)\n",
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302276 tclk_prepare, ddr2ns(dsidev, tclk_prepare));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002277
2278 /* program timings */
2279
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302280 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002281 r = FLD_MOD(r, ths_prepare, 31, 24);
2282 r = FLD_MOD(r, ths_prepare_ths_zero, 23, 16);
2283 r = FLD_MOD(r, ths_trail, 15, 8);
2284 r = FLD_MOD(r, ths_exit, 7, 0);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302285 dsi_write_reg(dsidev, DSI_DSIPHY_CFG0, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002286
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302287 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002288 r = FLD_MOD(r, tlpx_half, 22, 16);
2289 r = FLD_MOD(r, tclk_trail, 15, 8);
2290 r = FLD_MOD(r, tclk_zero, 7, 0);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302291 dsi_write_reg(dsidev, DSI_DSIPHY_CFG1, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002292
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302293 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG2);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002294 r = FLD_MOD(r, tclk_prepare, 7, 0);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302295 dsi_write_reg(dsidev, DSI_DSIPHY_CFG2, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002296}
2297
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002298/* lane masks have lane 0 at lsb. mask_p for positive lines, n for negative */
Tomi Valkeinencc5c1852010-10-06 15:18:13 +03002299static void dsi_cio_enable_lane_override(struct omap_dss_device *dssdev,
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002300 unsigned mask_p, unsigned mask_n)
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002301{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302302 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Taneja75d72472011-05-16 15:17:08 +05302303 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002304 int i;
2305 u32 l;
Tomi Valkeinend9820852011-10-12 15:05:59 +03002306 u8 lptxscp_start = dsi->num_lanes_supported == 3 ? 22 : 26;
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002307
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002308 l = 0;
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002309
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002310 for (i = 0; i < dsi->num_lanes_supported; ++i) {
2311 unsigned p = dsi->lanes[i].polarity;
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002312
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002313 if (mask_p & (1 << i))
2314 l |= 1 << (i * 2 + (p ? 0 : 1));
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002315
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002316 if (mask_n & (1 << i))
2317 l |= 1 << (i * 2 + (p ? 1 : 0));
2318 }
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002319
2320 /*
2321 * Bits in REGLPTXSCPDAT4TO0DXDY:
2322 * 17: DY0 18: DX0
2323 * 19: DY1 20: DX1
2324 * 21: DY2 22: DX2
Archit Taneja75d72472011-05-16 15:17:08 +05302325 * 23: DY3 24: DX3
2326 * 25: DY4 26: DX4
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002327 */
2328
2329 /* Set the lane override configuration */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302330
2331 /* REGLPTXSCPDAT4TO0DXDY */
Archit Taneja75d72472011-05-16 15:17:08 +05302332 REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, l, lptxscp_start, 17);
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002333
2334 /* Enable lane override */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302335
2336 /* ENLPTXSCPDAT */
2337 REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 1, 27, 27);
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002338}
2339
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302340static void dsi_cio_disable_lane_override(struct platform_device *dsidev)
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002341{
2342 /* Disable lane override */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302343 REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 0, 27, 27); /* ENLPTXSCPDAT */
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002344 /* Reset the lane override configuration */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302345 /* REGLPTXSCPDAT4TO0DXDY */
2346 REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 0, 22, 17);
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002347}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002348
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002349static int dsi_cio_wait_tx_clk_esc_reset(struct omap_dss_device *dssdev)
2350{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302351 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Tomi Valkeinen8dc07662011-10-13 15:26:50 +03002352 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2353 int t, i;
2354 bool in_use[DSI_MAX_NR_LANES];
2355 static const u8 offsets_old[] = { 28, 27, 26 };
2356 static const u8 offsets_new[] = { 24, 25, 26, 27, 28 };
2357 const u8 *offsets;
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002358
Tomi Valkeinen8dc07662011-10-13 15:26:50 +03002359 if (dss_has_feature(FEAT_DSI_REVERSE_TXCLKESC))
2360 offsets = offsets_old;
2361 else
2362 offsets = offsets_new;
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002363
Tomi Valkeinen8dc07662011-10-13 15:26:50 +03002364 for (i = 0; i < dsi->num_lanes_supported; ++i)
2365 in_use[i] = dsi->lanes[i].function != DSI_LANE_UNUSED;
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002366
2367 t = 100000;
2368 while (true) {
2369 u32 l;
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002370 int ok;
2371
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302372 l = dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002373
2374 ok = 0;
Tomi Valkeinen8dc07662011-10-13 15:26:50 +03002375 for (i = 0; i < dsi->num_lanes_supported; ++i) {
2376 if (!in_use[i] || (l & (1 << offsets[i])))
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002377 ok++;
2378 }
2379
Tomi Valkeinen8dc07662011-10-13 15:26:50 +03002380 if (ok == dsi->num_lanes_supported)
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002381 break;
2382
2383 if (--t == 0) {
Tomi Valkeinen8dc07662011-10-13 15:26:50 +03002384 for (i = 0; i < dsi->num_lanes_supported; ++i) {
2385 if (!in_use[i] || (l & (1 << offsets[i])))
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002386 continue;
2387
2388 DSSERR("CIO TXCLKESC%d domain not coming " \
2389 "out of reset\n", i);
2390 }
2391 return -EIO;
2392 }
2393 }
2394
2395 return 0;
2396}
2397
Tomi Valkeinen85f17e82011-10-13 15:12:23 +03002398/* return bitmask of enabled lanes, lane0 being the lsb */
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03002399static unsigned dsi_get_lane_mask(struct omap_dss_device *dssdev)
2400{
Tomi Valkeinen85f17e82011-10-13 15:12:23 +03002401 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
2402 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2403 unsigned mask = 0;
2404 int i;
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03002405
Tomi Valkeinen85f17e82011-10-13 15:12:23 +03002406 for (i = 0; i < dsi->num_lanes_supported; ++i) {
2407 if (dsi->lanes[i].function != DSI_LANE_UNUSED)
2408 mask |= 1 << i;
2409 }
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03002410
Tomi Valkeinen85f17e82011-10-13 15:12:23 +03002411 return mask;
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03002412}
2413
Tomi Valkeinencc5c1852010-10-06 15:18:13 +03002414static int dsi_cio_init(struct omap_dss_device *dssdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002415{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302416 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302417 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002418 int r;
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002419 u32 l;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002420
Tomi Valkeinencc5c1852010-10-06 15:18:13 +03002421 DSSDBGF();
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002422
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02002423 r = dss_dsi_enable_pads(dsi->module_id, dsi_get_lane_mask(dssdev));
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03002424 if (r)
2425 return r;
Tomi Valkeinend1f58572010-07-30 11:57:57 +03002426
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302427 dsi_enable_scp_clk(dsidev);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002428
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002429 /* A dummy read using the SCP interface to any DSIPHY register is
2430 * required after DSIPHY reset to complete the reset of the DSI complex
2431 * I/O. */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302432 dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002433
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302434 if (wait_for_bit_change(dsidev, DSI_DSIPHY_CFG5, 30, 1) != 1) {
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002435 DSSERR("CIO SCP Clock domain not coming out of reset.\n");
2436 r = -EIO;
2437 goto err_scp_clk_dom;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002438 }
2439
Tomi Valkeinen48368392011-10-13 11:22:39 +03002440 r = dsi_set_lane_config(dssdev);
2441 if (r)
2442 goto err_scp_clk_dom;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002443
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002444 /* set TX STOP MODE timer to maximum for this operation */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302445 l = dsi_read_reg(dsidev, DSI_TIMING1);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002446 l = FLD_MOD(l, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
2447 l = FLD_MOD(l, 1, 14, 14); /* STOP_STATE_X16_IO */
2448 l = FLD_MOD(l, 1, 13, 13); /* STOP_STATE_X4_IO */
2449 l = FLD_MOD(l, 0x1fff, 12, 0); /* STOP_STATE_COUNTER_IO */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302450 dsi_write_reg(dsidev, DSI_TIMING1, l);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002451
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302452 if (dsi->ulps_enabled) {
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002453 unsigned mask_p;
2454 int i;
Archit Taneja75d72472011-05-16 15:17:08 +05302455
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002456 DSSDBG("manual ulps exit\n");
2457
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002458 /* ULPS is exited by Mark-1 state for 1ms, followed by
2459 * stop state. DSS HW cannot do this via the normal
2460 * ULPS exit sequence, as after reset the DSS HW thinks
2461 * that we are not in ULPS mode, and refuses to send the
2462 * sequence. So we need to send the ULPS exit sequence
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002463 * manually by setting positive lines high and negative lines
2464 * low for 1ms.
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002465 */
2466
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002467 mask_p = 0;
Archit Taneja75d72472011-05-16 15:17:08 +05302468
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002469 for (i = 0; i < dsi->num_lanes_supported; ++i) {
2470 if (dsi->lanes[i].function == DSI_LANE_UNUSED)
2471 continue;
2472 mask_p |= 1 << i;
2473 }
Archit Taneja75d72472011-05-16 15:17:08 +05302474
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002475 dsi_cio_enable_lane_override(dssdev, mask_p, 0);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002476 }
2477
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302478 r = dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_ON);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002479 if (r)
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002480 goto err_cio_pwr;
2481
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302482 if (wait_for_bit_change(dsidev, DSI_COMPLEXIO_CFG1, 29, 1) != 1) {
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002483 DSSERR("CIO PWR clock domain not coming out of reset.\n");
2484 r = -ENODEV;
2485 goto err_cio_pwr_dom;
2486 }
2487
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302488 dsi_if_enable(dsidev, true);
2489 dsi_if_enable(dsidev, false);
2490 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 1, 20, 20); /* LP_CLK_ENABLE */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002491
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002492 r = dsi_cio_wait_tx_clk_esc_reset(dssdev);
2493 if (r)
2494 goto err_tx_clk_esc_rst;
2495
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302496 if (dsi->ulps_enabled) {
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002497 /* Keep Mark-1 state for 1ms (as per DSI spec) */
2498 ktime_t wait = ns_to_ktime(1000 * 1000);
2499 set_current_state(TASK_UNINTERRUPTIBLE);
2500 schedule_hrtimeout(&wait, HRTIMER_MODE_REL);
2501
2502 /* Disable the override. The lanes should be set to Mark-11
2503 * state by the HW */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302504 dsi_cio_disable_lane_override(dsidev);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002505 }
2506
2507 /* FORCE_TX_STOP_MODE_IO */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302508 REG_FLD_MOD(dsidev, DSI_TIMING1, 0, 15, 15);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002509
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302510 dsi_cio_timings(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002511
Archit Tanejadca2b152012-08-16 18:02:00 +05302512 if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
Archit Taneja8af6ff02011-09-05 16:48:27 +05302513 /* DDR_CLK_ALWAYS_ON */
2514 REG_FLD_MOD(dsidev, DSI_CLK_CTRL,
Archit Taneja0b3ffe32012-08-13 22:13:39 +05302515 dsi->vm_timings.ddr_clk_always_on, 13, 13);
Archit Taneja8af6ff02011-09-05 16:48:27 +05302516 }
2517
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302518 dsi->ulps_enabled = false;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002519
2520 DSSDBG("CIO init done\n");
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002521
2522 return 0;
2523
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002524err_tx_clk_esc_rst:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302525 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 20, 20); /* LP_CLK_ENABLE */
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002526err_cio_pwr_dom:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302527 dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_OFF);
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002528err_cio_pwr:
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302529 if (dsi->ulps_enabled)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302530 dsi_cio_disable_lane_override(dsidev);
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002531err_scp_clk_dom:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302532 dsi_disable_scp_clk(dsidev);
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02002533 dss_dsi_disable_pads(dsi->module_id, dsi_get_lane_mask(dssdev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002534 return r;
2535}
2536
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03002537static void dsi_cio_uninit(struct omap_dss_device *dssdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002538{
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03002539 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02002540 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302541
Archit Taneja8af6ff02011-09-05 16:48:27 +05302542 /* DDR_CLK_ALWAYS_ON */
2543 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 13, 13);
2544
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302545 dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_OFF);
2546 dsi_disable_scp_clk(dsidev);
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02002547 dss_dsi_disable_pads(dsi->module_id, dsi_get_lane_mask(dssdev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002548}
2549
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302550static void dsi_config_tx_fifo(struct platform_device *dsidev,
2551 enum fifo_size size1, enum fifo_size size2,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002552 enum fifo_size size3, enum fifo_size size4)
2553{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302554 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002555 u32 r = 0;
2556 int add = 0;
2557 int i;
2558
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302559 dsi->vc[0].fifo_size = size1;
2560 dsi->vc[1].fifo_size = size2;
2561 dsi->vc[2].fifo_size = size3;
2562 dsi->vc[3].fifo_size = size4;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002563
2564 for (i = 0; i < 4; i++) {
2565 u8 v;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302566 int size = dsi->vc[i].fifo_size;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002567
2568 if (add + size > 4) {
2569 DSSERR("Illegal FIFO configuration\n");
2570 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002571 return;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002572 }
2573
2574 v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
2575 r |= v << (8 * i);
2576 /*DSSDBG("TX FIFO vc %d: size %d, add %d\n", i, size, add); */
2577 add += size;
2578 }
2579
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302580 dsi_write_reg(dsidev, DSI_TX_FIFO_VC_SIZE, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002581}
2582
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302583static void dsi_config_rx_fifo(struct platform_device *dsidev,
2584 enum fifo_size size1, enum fifo_size size2,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002585 enum fifo_size size3, enum fifo_size size4)
2586{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302587 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002588 u32 r = 0;
2589 int add = 0;
2590 int i;
2591
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302592 dsi->vc[0].fifo_size = size1;
2593 dsi->vc[1].fifo_size = size2;
2594 dsi->vc[2].fifo_size = size3;
2595 dsi->vc[3].fifo_size = size4;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002596
2597 for (i = 0; i < 4; i++) {
2598 u8 v;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302599 int size = dsi->vc[i].fifo_size;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002600
2601 if (add + size > 4) {
2602 DSSERR("Illegal FIFO configuration\n");
2603 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002604 return;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002605 }
2606
2607 v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
2608 r |= v << (8 * i);
2609 /*DSSDBG("RX FIFO vc %d: size %d, add %d\n", i, size, add); */
2610 add += size;
2611 }
2612
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302613 dsi_write_reg(dsidev, DSI_RX_FIFO_VC_SIZE, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002614}
2615
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302616static int dsi_force_tx_stop_mode_io(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002617{
2618 u32 r;
2619
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302620 r = dsi_read_reg(dsidev, DSI_TIMING1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002621 r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302622 dsi_write_reg(dsidev, DSI_TIMING1, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002623
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302624 if (wait_for_bit_change(dsidev, DSI_TIMING1, 15, 0) != 0) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002625 DSSERR("TX_STOP bit not going down\n");
2626 return -EIO;
2627 }
2628
2629 return 0;
2630}
2631
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302632static bool dsi_vc_is_enabled(struct platform_device *dsidev, int channel)
Archit Tanejacf398fb2011-03-23 09:59:34 +00002633{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302634 return REG_GET(dsidev, DSI_VC_CTRL(channel), 0, 0);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002635}
2636
2637static void dsi_packet_sent_handler_vp(void *data, u32 mask)
2638{
Archit Taneja2e868db2011-05-12 17:26:28 +05302639 struct dsi_packet_sent_handler_data *vp_data =
2640 (struct dsi_packet_sent_handler_data *) data;
2641 struct dsi_data *dsi = dsi_get_dsidrv_data(vp_data->dsidev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302642 const int channel = dsi->update_channel;
2643 u8 bit = dsi->te_enabled ? 30 : 31;
Archit Tanejacf398fb2011-03-23 09:59:34 +00002644
Archit Taneja2e868db2011-05-12 17:26:28 +05302645 if (REG_GET(vp_data->dsidev, DSI_VC_TE(channel), bit, bit) == 0)
2646 complete(vp_data->completion);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002647}
2648
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302649static int dsi_sync_vc_vp(struct platform_device *dsidev, int channel)
Archit Tanejacf398fb2011-03-23 09:59:34 +00002650{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302651 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Taneja2e868db2011-05-12 17:26:28 +05302652 DECLARE_COMPLETION_ONSTACK(completion);
2653 struct dsi_packet_sent_handler_data vp_data = { dsidev, &completion };
Archit Tanejacf398fb2011-03-23 09:59:34 +00002654 int r = 0;
2655 u8 bit;
2656
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302657 bit = dsi->te_enabled ? 30 : 31;
Archit Tanejacf398fb2011-03-23 09:59:34 +00002658
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302659 r = dsi_register_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp,
Archit Taneja2e868db2011-05-12 17:26:28 +05302660 &vp_data, DSI_VC_IRQ_PACKET_SENT);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002661 if (r)
2662 goto err0;
2663
2664 /* Wait for completion only if TE_EN/TE_START is still set */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302665 if (REG_GET(dsidev, DSI_VC_TE(channel), bit, bit)) {
Archit Tanejacf398fb2011-03-23 09:59:34 +00002666 if (wait_for_completion_timeout(&completion,
2667 msecs_to_jiffies(10)) == 0) {
2668 DSSERR("Failed to complete previous frame transfer\n");
2669 r = -EIO;
2670 goto err1;
2671 }
2672 }
2673
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302674 dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp,
Archit Taneja2e868db2011-05-12 17:26:28 +05302675 &vp_data, DSI_VC_IRQ_PACKET_SENT);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002676
2677 return 0;
2678err1:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302679 dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp,
Archit Taneja2e868db2011-05-12 17:26:28 +05302680 &vp_data, DSI_VC_IRQ_PACKET_SENT);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002681err0:
2682 return r;
2683}
2684
2685static void dsi_packet_sent_handler_l4(void *data, u32 mask)
2686{
Archit Taneja2e868db2011-05-12 17:26:28 +05302687 struct dsi_packet_sent_handler_data *l4_data =
2688 (struct dsi_packet_sent_handler_data *) data;
2689 struct dsi_data *dsi = dsi_get_dsidrv_data(l4_data->dsidev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302690 const int channel = dsi->update_channel;
Archit Tanejacf398fb2011-03-23 09:59:34 +00002691
Archit Taneja2e868db2011-05-12 17:26:28 +05302692 if (REG_GET(l4_data->dsidev, DSI_VC_CTRL(channel), 5, 5) == 0)
2693 complete(l4_data->completion);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002694}
2695
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302696static int dsi_sync_vc_l4(struct platform_device *dsidev, int channel)
Archit Tanejacf398fb2011-03-23 09:59:34 +00002697{
Archit Taneja2e868db2011-05-12 17:26:28 +05302698 DECLARE_COMPLETION_ONSTACK(completion);
2699 struct dsi_packet_sent_handler_data l4_data = { dsidev, &completion };
Archit Tanejacf398fb2011-03-23 09:59:34 +00002700 int r = 0;
2701
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302702 r = dsi_register_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4,
Archit Taneja2e868db2011-05-12 17:26:28 +05302703 &l4_data, DSI_VC_IRQ_PACKET_SENT);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002704 if (r)
2705 goto err0;
2706
2707 /* Wait for completion only if TX_FIFO_NOT_EMPTY is still set */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302708 if (REG_GET(dsidev, DSI_VC_CTRL(channel), 5, 5)) {
Archit Tanejacf398fb2011-03-23 09:59:34 +00002709 if (wait_for_completion_timeout(&completion,
2710 msecs_to_jiffies(10)) == 0) {
2711 DSSERR("Failed to complete previous l4 transfer\n");
2712 r = -EIO;
2713 goto err1;
2714 }
2715 }
2716
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302717 dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4,
Archit Taneja2e868db2011-05-12 17:26:28 +05302718 &l4_data, DSI_VC_IRQ_PACKET_SENT);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002719
2720 return 0;
2721err1:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302722 dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4,
Archit Taneja2e868db2011-05-12 17:26:28 +05302723 &l4_data, DSI_VC_IRQ_PACKET_SENT);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002724err0:
2725 return r;
2726}
2727
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302728static int dsi_sync_vc(struct platform_device *dsidev, int channel)
Archit Tanejacf398fb2011-03-23 09:59:34 +00002729{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302730 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2731
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302732 WARN_ON(!dsi_bus_is_locked(dsidev));
Archit Tanejacf398fb2011-03-23 09:59:34 +00002733
2734 WARN_ON(in_interrupt());
2735
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302736 if (!dsi_vc_is_enabled(dsidev, channel))
Archit Tanejacf398fb2011-03-23 09:59:34 +00002737 return 0;
2738
Archit Tanejad6049142011-08-22 11:58:08 +05302739 switch (dsi->vc[channel].source) {
2740 case DSI_VC_SOURCE_VP:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302741 return dsi_sync_vc_vp(dsidev, channel);
Archit Tanejad6049142011-08-22 11:58:08 +05302742 case DSI_VC_SOURCE_L4:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302743 return dsi_sync_vc_l4(dsidev, channel);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002744 default:
2745 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002746 return -EINVAL;
Archit Tanejacf398fb2011-03-23 09:59:34 +00002747 }
2748}
2749
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302750static int dsi_vc_enable(struct platform_device *dsidev, int channel,
2751 bool enable)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002752{
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +02002753 DSSDBG("dsi_vc_enable channel %d, enable %d\n",
2754 channel, enable);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002755
2756 enable = enable ? 1 : 0;
2757
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302758 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 0, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002759
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302760 if (wait_for_bit_change(dsidev, DSI_VC_CTRL(channel),
2761 0, enable) != enable) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002762 DSSERR("Failed to set dsi_vc_enable to %d\n", enable);
2763 return -EIO;
2764 }
2765
2766 return 0;
2767}
2768
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302769static void dsi_vc_initial_config(struct platform_device *dsidev, int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002770{
2771 u32 r;
2772
2773 DSSDBGF("%d", channel);
2774
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302775 r = dsi_read_reg(dsidev, DSI_VC_CTRL(channel));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002776
2777 if (FLD_GET(r, 15, 15)) /* VC_BUSY */
2778 DSSERR("VC(%d) busy when trying to configure it!\n",
2779 channel);
2780
2781 r = FLD_MOD(r, 0, 1, 1); /* SOURCE, 0 = L4 */
2782 r = FLD_MOD(r, 0, 2, 2); /* BTA_SHORT_EN */
2783 r = FLD_MOD(r, 0, 3, 3); /* BTA_LONG_EN */
2784 r = FLD_MOD(r, 0, 4, 4); /* MODE, 0 = command */
2785 r = FLD_MOD(r, 1, 7, 7); /* CS_TX_EN */
2786 r = FLD_MOD(r, 1, 8, 8); /* ECC_TX_EN */
2787 r = FLD_MOD(r, 0, 9, 9); /* MODE_SPEED, high speed on/off */
Archit Taneja9613c022011-03-22 06:33:36 -05002788 if (dss_has_feature(FEAT_DSI_VC_OCP_WIDTH))
2789 r = FLD_MOD(r, 3, 11, 10); /* OCP_WIDTH = 32 bit */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002790
2791 r = FLD_MOD(r, 4, 29, 27); /* DMA_RX_REQ_NB = no dma */
2792 r = FLD_MOD(r, 4, 23, 21); /* DMA_TX_REQ_NB = no dma */
2793
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302794 dsi_write_reg(dsidev, DSI_VC_CTRL(channel), r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002795}
2796
Archit Tanejad6049142011-08-22 11:58:08 +05302797static int dsi_vc_config_source(struct platform_device *dsidev, int channel,
2798 enum dsi_vc_source source)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002799{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302800 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2801
Archit Tanejad6049142011-08-22 11:58:08 +05302802 if (dsi->vc[channel].source == source)
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03002803 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002804
2805 DSSDBGF("%d", channel);
2806
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302807 dsi_sync_vc(dsidev, channel);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002808
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302809 dsi_vc_enable(dsidev, channel, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002810
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03002811 /* VC_BUSY */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302812 if (wait_for_bit_change(dsidev, DSI_VC_CTRL(channel), 15, 0) != 0) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002813 DSSERR("vc(%d) busy when trying to config for VP\n", channel);
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03002814 return -EIO;
2815 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002816
Archit Tanejad6049142011-08-22 11:58:08 +05302817 /* SOURCE, 0 = L4, 1 = video port */
2818 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), source, 1, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002819
Archit Taneja9613c022011-03-22 06:33:36 -05002820 /* DCS_CMD_ENABLE */
Archit Tanejad6049142011-08-22 11:58:08 +05302821 if (dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC)) {
2822 bool enable = source == DSI_VC_SOURCE_VP;
2823 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 30, 30);
2824 }
Archit Taneja9613c022011-03-22 06:33:36 -05002825
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302826 dsi_vc_enable(dsidev, channel, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002827
Archit Tanejad6049142011-08-22 11:58:08 +05302828 dsi->vc[channel].source = source;
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03002829
2830 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002831}
2832
Archit Taneja1ffefe72011-05-12 17:26:24 +05302833void omapdss_dsi_vc_enable_hs(struct omap_dss_device *dssdev, int channel,
2834 bool enable)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002835{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302836 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Taneja0b3ffe32012-08-13 22:13:39 +05302837 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302838
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002839 DSSDBG("dsi_vc_enable_hs(%d, %d)\n", channel, enable);
2840
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302841 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen61140c92010-01-12 16:00:30 +02002842
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302843 dsi_vc_enable(dsidev, channel, 0);
2844 dsi_if_enable(dsidev, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002845
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302846 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 9, 9);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002847
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302848 dsi_vc_enable(dsidev, channel, 1);
2849 dsi_if_enable(dsidev, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002850
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302851 dsi_force_tx_stop_mode_io(dsidev);
Archit Taneja8af6ff02011-09-05 16:48:27 +05302852
2853 /* start the DDR clock by sending a NULL packet */
Archit Taneja0b3ffe32012-08-13 22:13:39 +05302854 if (dsi->vm_timings.ddr_clk_always_on && enable)
Archit Taneja8af6ff02011-09-05 16:48:27 +05302855 dsi_vc_send_null(dssdev, channel);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002856}
Tomi Valkeinen61140c92010-01-12 16:00:30 +02002857EXPORT_SYMBOL(omapdss_dsi_vc_enable_hs);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002858
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302859static void dsi_vc_flush_long_data(struct platform_device *dsidev, int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002860{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302861 while (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002862 u32 val;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302863 val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002864 DSSDBG("\t\tb1 %#02x b2 %#02x b3 %#02x b4 %#02x\n",
2865 (val >> 0) & 0xff,
2866 (val >> 8) & 0xff,
2867 (val >> 16) & 0xff,
2868 (val >> 24) & 0xff);
2869 }
2870}
2871
2872static void dsi_show_rx_ack_with_err(u16 err)
2873{
2874 DSSERR("\tACK with ERROR (%#x):\n", err);
2875 if (err & (1 << 0))
2876 DSSERR("\t\tSoT Error\n");
2877 if (err & (1 << 1))
2878 DSSERR("\t\tSoT Sync Error\n");
2879 if (err & (1 << 2))
2880 DSSERR("\t\tEoT Sync Error\n");
2881 if (err & (1 << 3))
2882 DSSERR("\t\tEscape Mode Entry Command Error\n");
2883 if (err & (1 << 4))
2884 DSSERR("\t\tLP Transmit Sync Error\n");
2885 if (err & (1 << 5))
2886 DSSERR("\t\tHS Receive Timeout Error\n");
2887 if (err & (1 << 6))
2888 DSSERR("\t\tFalse Control Error\n");
2889 if (err & (1 << 7))
2890 DSSERR("\t\t(reserved7)\n");
2891 if (err & (1 << 8))
2892 DSSERR("\t\tECC Error, single-bit (corrected)\n");
2893 if (err & (1 << 9))
2894 DSSERR("\t\tECC Error, multi-bit (not corrected)\n");
2895 if (err & (1 << 10))
2896 DSSERR("\t\tChecksum Error\n");
2897 if (err & (1 << 11))
2898 DSSERR("\t\tData type not recognized\n");
2899 if (err & (1 << 12))
2900 DSSERR("\t\tInvalid VC ID\n");
2901 if (err & (1 << 13))
2902 DSSERR("\t\tInvalid Transmission Length\n");
2903 if (err & (1 << 14))
2904 DSSERR("\t\t(reserved14)\n");
2905 if (err & (1 << 15))
2906 DSSERR("\t\tDSI Protocol Violation\n");
2907}
2908
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302909static u16 dsi_vc_flush_receive_data(struct platform_device *dsidev,
2910 int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002911{
2912 /* RX_FIFO_NOT_EMPTY */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302913 while (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002914 u32 val;
2915 u8 dt;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302916 val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel));
Tomi Valkeinen86a78672010-03-16 16:19:06 +02002917 DSSERR("\trawval %#08x\n", val);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002918 dt = FLD_GET(val, 5, 0);
Archit Taneja7a7c48f2011-08-25 18:25:03 +05302919 if (dt == MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002920 u16 err = FLD_GET(val, 23, 8);
2921 dsi_show_rx_ack_with_err(err);
Archit Taneja7a7c48f2011-08-25 18:25:03 +05302922 } else if (dt == MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE) {
Tomi Valkeinen86a78672010-03-16 16:19:06 +02002923 DSSERR("\tDCS short response, 1 byte: %#x\n",
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002924 FLD_GET(val, 23, 8));
Archit Taneja7a7c48f2011-08-25 18:25:03 +05302925 } else if (dt == MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE) {
Tomi Valkeinen86a78672010-03-16 16:19:06 +02002926 DSSERR("\tDCS short response, 2 byte: %#x\n",
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002927 FLD_GET(val, 23, 8));
Archit Taneja7a7c48f2011-08-25 18:25:03 +05302928 } else if (dt == MIPI_DSI_RX_DCS_LONG_READ_RESPONSE) {
Tomi Valkeinen86a78672010-03-16 16:19:06 +02002929 DSSERR("\tDCS long response, len %d\n",
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002930 FLD_GET(val, 23, 8));
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302931 dsi_vc_flush_long_data(dsidev, channel);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002932 } else {
2933 DSSERR("\tunknown datatype 0x%02x\n", dt);
2934 }
2935 }
2936 return 0;
2937}
2938
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302939static int dsi_vc_send_bta(struct platform_device *dsidev, int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002940{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302941 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2942
2943 if (dsi->debug_write || dsi->debug_read)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002944 DSSDBG("dsi_vc_send_bta %d\n", channel);
2945
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302946 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002947
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302948 /* RX_FIFO_NOT_EMPTY */
2949 if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002950 DSSERR("rx fifo not empty when sending BTA, dumping data:\n");
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302951 dsi_vc_flush_receive_data(dsidev, channel);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002952 }
2953
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302954 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 1, 6, 6); /* BTA_EN */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002955
Tomi Valkeinen968f8e92011-10-12 10:13:14 +03002956 /* flush posted write */
2957 dsi_read_reg(dsidev, DSI_VC_CTRL(channel));
2958
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002959 return 0;
2960}
2961
Archit Taneja1ffefe72011-05-12 17:26:24 +05302962int dsi_vc_send_bta_sync(struct omap_dss_device *dssdev, int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002963{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302964 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Tomi Valkeinenf36a06e2011-03-02 14:48:41 +02002965 DECLARE_COMPLETION_ONSTACK(completion);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002966 int r = 0;
2967 u32 err;
2968
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302969 r = dsi_register_isr_vc(dsidev, channel, dsi_completion_handler,
Tomi Valkeinenf36a06e2011-03-02 14:48:41 +02002970 &completion, DSI_VC_IRQ_BTA);
2971 if (r)
2972 goto err0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002973
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302974 r = dsi_register_isr(dsidev, dsi_completion_handler, &completion,
Tomi Valkeinen773b30b2010-10-08 16:15:25 +03002975 DSI_IRQ_ERROR_MASK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002976 if (r)
Tomi Valkeinenf36a06e2011-03-02 14:48:41 +02002977 goto err1;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002978
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302979 r = dsi_vc_send_bta(dsidev, channel);
Tomi Valkeinen773b30b2010-10-08 16:15:25 +03002980 if (r)
2981 goto err2;
2982
Tomi Valkeinenf36a06e2011-03-02 14:48:41 +02002983 if (wait_for_completion_timeout(&completion,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002984 msecs_to_jiffies(500)) == 0) {
2985 DSSERR("Failed to receive BTA\n");
2986 r = -EIO;
Tomi Valkeinen773b30b2010-10-08 16:15:25 +03002987 goto err2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002988 }
2989
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302990 err = dsi_get_errors(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002991 if (err) {
2992 DSSERR("Error while sending BTA: %x\n", err);
2993 r = -EIO;
Tomi Valkeinen773b30b2010-10-08 16:15:25 +03002994 goto err2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002995 }
Tomi Valkeinen773b30b2010-10-08 16:15:25 +03002996err2:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302997 dsi_unregister_isr(dsidev, dsi_completion_handler, &completion,
Tomi Valkeinen773b30b2010-10-08 16:15:25 +03002998 DSI_IRQ_ERROR_MASK);
Tomi Valkeinenf36a06e2011-03-02 14:48:41 +02002999err1:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303000 dsi_unregister_isr_vc(dsidev, channel, dsi_completion_handler,
Tomi Valkeinenf36a06e2011-03-02 14:48:41 +02003001 &completion, DSI_VC_IRQ_BTA);
3002err0:
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003003 return r;
3004}
3005EXPORT_SYMBOL(dsi_vc_send_bta_sync);
3006
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303007static inline void dsi_vc_write_long_header(struct platform_device *dsidev,
3008 int channel, u8 data_type, u16 len, u8 ecc)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003009{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303010 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003011 u32 val;
3012 u8 data_id;
3013
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303014 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003015
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303016 data_id = data_type | dsi->vc[channel].vc_id << 6;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003017
3018 val = FLD_VAL(data_id, 7, 0) | FLD_VAL(len, 23, 8) |
3019 FLD_VAL(ecc, 31, 24);
3020
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303021 dsi_write_reg(dsidev, DSI_VC_LONG_PACKET_HEADER(channel), val);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003022}
3023
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303024static inline void dsi_vc_write_long_payload(struct platform_device *dsidev,
3025 int channel, u8 b1, u8 b2, u8 b3, u8 b4)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003026{
3027 u32 val;
3028
3029 val = b4 << 24 | b3 << 16 | b2 << 8 | b1 << 0;
3030
3031/* DSSDBG("\twriting %02x, %02x, %02x, %02x (%#010x)\n",
3032 b1, b2, b3, b4, val); */
3033
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303034 dsi_write_reg(dsidev, DSI_VC_LONG_PACKET_PAYLOAD(channel), val);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003035}
3036
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303037static int dsi_vc_send_long(struct platform_device *dsidev, int channel,
3038 u8 data_type, u8 *data, u16 len, u8 ecc)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003039{
3040 /*u32 val; */
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303041 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003042 int i;
3043 u8 *p;
3044 int r = 0;
3045 u8 b1, b2, b3, b4;
3046
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303047 if (dsi->debug_write)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003048 DSSDBG("dsi_vc_send_long, %d bytes\n", len);
3049
3050 /* len + header */
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303051 if (dsi->vc[channel].fifo_size * 32 * 4 < len + 4) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003052 DSSERR("unable to send long packet: packet too long.\n");
3053 return -EINVAL;
3054 }
3055
Archit Tanejad6049142011-08-22 11:58:08 +05303056 dsi_vc_config_source(dsidev, channel, DSI_VC_SOURCE_L4);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003057
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303058 dsi_vc_write_long_header(dsidev, channel, data_type, len, ecc);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003059
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003060 p = data;
3061 for (i = 0; i < len >> 2; i++) {
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303062 if (dsi->debug_write)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003063 DSSDBG("\tsending full packet %d\n", i);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003064
3065 b1 = *p++;
3066 b2 = *p++;
3067 b3 = *p++;
3068 b4 = *p++;
3069
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303070 dsi_vc_write_long_payload(dsidev, channel, b1, b2, b3, b4);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003071 }
3072
3073 i = len % 4;
3074 if (i) {
3075 b1 = 0; b2 = 0; b3 = 0;
3076
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303077 if (dsi->debug_write)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003078 DSSDBG("\tsending remainder bytes %d\n", i);
3079
3080 switch (i) {
3081 case 3:
3082 b1 = *p++;
3083 b2 = *p++;
3084 b3 = *p++;
3085 break;
3086 case 2:
3087 b1 = *p++;
3088 b2 = *p++;
3089 break;
3090 case 1:
3091 b1 = *p++;
3092 break;
3093 }
3094
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303095 dsi_vc_write_long_payload(dsidev, channel, b1, b2, b3, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003096 }
3097
3098 return r;
3099}
3100
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303101static int dsi_vc_send_short(struct platform_device *dsidev, int channel,
3102 u8 data_type, u16 data, u8 ecc)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003103{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303104 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003105 u32 r;
3106 u8 data_id;
3107
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303108 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003109
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303110 if (dsi->debug_write)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003111 DSSDBG("dsi_vc_send_short(ch%d, dt %#x, b1 %#x, b2 %#x)\n",
3112 channel,
3113 data_type, data & 0xff, (data >> 8) & 0xff);
3114
Archit Tanejad6049142011-08-22 11:58:08 +05303115 dsi_vc_config_source(dsidev, channel, DSI_VC_SOURCE_L4);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003116
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303117 if (FLD_GET(dsi_read_reg(dsidev, DSI_VC_CTRL(channel)), 16, 16)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003118 DSSERR("ERROR FIFO FULL, aborting transfer\n");
3119 return -EINVAL;
3120 }
3121
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303122 data_id = data_type | dsi->vc[channel].vc_id << 6;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003123
3124 r = (data_id << 0) | (data << 8) | (ecc << 24);
3125
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303126 dsi_write_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel), r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003127
3128 return 0;
3129}
3130
Archit Taneja1ffefe72011-05-12 17:26:24 +05303131int dsi_vc_send_null(struct omap_dss_device *dssdev, int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003132{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303133 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303134
Archit Taneja18b7d092011-09-05 17:01:08 +05303135 return dsi_vc_send_long(dsidev, channel, MIPI_DSI_NULL_PACKET, NULL,
3136 0, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003137}
3138EXPORT_SYMBOL(dsi_vc_send_null);
3139
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303140static int dsi_vc_write_nosync_common(struct omap_dss_device *dssdev,
3141 int channel, u8 *data, int len, enum dss_dsi_content_type type)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003142{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303143 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003144 int r;
3145
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303146 if (len == 0) {
3147 BUG_ON(type == DSS_DSI_CONTENT_DCS);
Archit Taneja7a7c48f2011-08-25 18:25:03 +05303148 r = dsi_vc_send_short(dsidev, channel,
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303149 MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM, 0, 0);
3150 } else if (len == 1) {
3151 r = dsi_vc_send_short(dsidev, channel,
3152 type == DSS_DSI_CONTENT_GENERIC ?
3153 MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM :
Archit Taneja7a7c48f2011-08-25 18:25:03 +05303154 MIPI_DSI_DCS_SHORT_WRITE, data[0], 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003155 } else if (len == 2) {
Archit Taneja7a7c48f2011-08-25 18:25:03 +05303156 r = dsi_vc_send_short(dsidev, channel,
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303157 type == DSS_DSI_CONTENT_GENERIC ?
3158 MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM :
Archit Taneja7a7c48f2011-08-25 18:25:03 +05303159 MIPI_DSI_DCS_SHORT_WRITE_PARAM,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003160 data[0] | (data[1] << 8), 0);
3161 } else {
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303162 r = dsi_vc_send_long(dsidev, channel,
3163 type == DSS_DSI_CONTENT_GENERIC ?
3164 MIPI_DSI_GENERIC_LONG_WRITE :
3165 MIPI_DSI_DCS_LONG_WRITE, data, len, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003166 }
3167
3168 return r;
3169}
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303170
3171int dsi_vc_dcs_write_nosync(struct omap_dss_device *dssdev, int channel,
3172 u8 *data, int len)
3173{
3174 return dsi_vc_write_nosync_common(dssdev, channel, data, len,
3175 DSS_DSI_CONTENT_DCS);
3176}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003177EXPORT_SYMBOL(dsi_vc_dcs_write_nosync);
3178
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303179int dsi_vc_generic_write_nosync(struct omap_dss_device *dssdev, int channel,
3180 u8 *data, int len)
3181{
3182 return dsi_vc_write_nosync_common(dssdev, channel, data, len,
3183 DSS_DSI_CONTENT_GENERIC);
3184}
3185EXPORT_SYMBOL(dsi_vc_generic_write_nosync);
3186
3187static int dsi_vc_write_common(struct omap_dss_device *dssdev, int channel,
3188 u8 *data, int len, enum dss_dsi_content_type type)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003189{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303190 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003191 int r;
3192
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303193 r = dsi_vc_write_nosync_common(dssdev, channel, data, len, type);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003194 if (r)
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003195 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003196
Archit Taneja1ffefe72011-05-12 17:26:24 +05303197 r = dsi_vc_send_bta_sync(dssdev, channel);
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003198 if (r)
3199 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003200
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303201 /* RX_FIFO_NOT_EMPTY */
3202 if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
Tomi Valkeinenb63ac1e2010-04-09 13:20:57 +03003203 DSSERR("rx fifo not empty after write, dumping data:\n");
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303204 dsi_vc_flush_receive_data(dsidev, channel);
Tomi Valkeinenb63ac1e2010-04-09 13:20:57 +03003205 r = -EIO;
3206 goto err;
3207 }
3208
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003209 return 0;
3210err:
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303211 DSSERR("dsi_vc_write_common(ch %d, cmd 0x%02x, len %d) failed\n",
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003212 channel, data[0], len);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003213 return r;
3214}
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303215
3216int dsi_vc_dcs_write(struct omap_dss_device *dssdev, int channel, u8 *data,
3217 int len)
3218{
3219 return dsi_vc_write_common(dssdev, channel, data, len,
3220 DSS_DSI_CONTENT_DCS);
3221}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003222EXPORT_SYMBOL(dsi_vc_dcs_write);
3223
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303224int dsi_vc_generic_write(struct omap_dss_device *dssdev, int channel, u8 *data,
3225 int len)
3226{
3227 return dsi_vc_write_common(dssdev, channel, data, len,
3228 DSS_DSI_CONTENT_GENERIC);
3229}
3230EXPORT_SYMBOL(dsi_vc_generic_write);
3231
Archit Taneja1ffefe72011-05-12 17:26:24 +05303232int dsi_vc_dcs_write_0(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd)
Tomi Valkeinen828c48f2009-12-16 14:53:15 +02003233{
Archit Taneja1ffefe72011-05-12 17:26:24 +05303234 return dsi_vc_dcs_write(dssdev, channel, &dcs_cmd, 1);
Tomi Valkeinen828c48f2009-12-16 14:53:15 +02003235}
3236EXPORT_SYMBOL(dsi_vc_dcs_write_0);
3237
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303238int dsi_vc_generic_write_0(struct omap_dss_device *dssdev, int channel)
3239{
3240 return dsi_vc_generic_write(dssdev, channel, NULL, 0);
3241}
3242EXPORT_SYMBOL(dsi_vc_generic_write_0);
3243
Archit Taneja1ffefe72011-05-12 17:26:24 +05303244int dsi_vc_dcs_write_1(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
3245 u8 param)
Tomi Valkeinen828c48f2009-12-16 14:53:15 +02003246{
3247 u8 buf[2];
3248 buf[0] = dcs_cmd;
3249 buf[1] = param;
Archit Taneja1ffefe72011-05-12 17:26:24 +05303250 return dsi_vc_dcs_write(dssdev, channel, buf, 2);
Tomi Valkeinen828c48f2009-12-16 14:53:15 +02003251}
3252EXPORT_SYMBOL(dsi_vc_dcs_write_1);
3253
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303254int dsi_vc_generic_write_1(struct omap_dss_device *dssdev, int channel,
3255 u8 param)
3256{
3257 return dsi_vc_generic_write(dssdev, channel, &param, 1);
3258}
3259EXPORT_SYMBOL(dsi_vc_generic_write_1);
3260
3261int dsi_vc_generic_write_2(struct omap_dss_device *dssdev, int channel,
3262 u8 param1, u8 param2)
3263{
3264 u8 buf[2];
3265 buf[0] = param1;
3266 buf[1] = param2;
3267 return dsi_vc_generic_write(dssdev, channel, buf, 2);
3268}
3269EXPORT_SYMBOL(dsi_vc_generic_write_2);
3270
Archit Tanejab8509752011-08-30 15:48:23 +05303271static int dsi_vc_dcs_send_read_request(struct omap_dss_device *dssdev,
3272 int channel, u8 dcs_cmd)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003273{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303274 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303275 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejab8509752011-08-30 15:48:23 +05303276 int r;
3277
3278 if (dsi->debug_read)
3279 DSSDBG("dsi_vc_dcs_send_read_request(ch%d, dcs_cmd %x)\n",
3280 channel, dcs_cmd);
3281
3282 r = dsi_vc_send_short(dsidev, channel, MIPI_DSI_DCS_READ, dcs_cmd, 0);
3283 if (r) {
3284 DSSERR("dsi_vc_dcs_send_read_request(ch %d, cmd 0x%02x)"
3285 " failed\n", channel, dcs_cmd);
3286 return r;
3287 }
3288
3289 return 0;
3290}
3291
Archit Tanejab3b89c02011-08-30 16:07:39 +05303292static int dsi_vc_generic_send_read_request(struct omap_dss_device *dssdev,
3293 int channel, u8 *reqdata, int reqlen)
3294{
3295 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
3296 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
3297 u16 data;
3298 u8 data_type;
3299 int r;
3300
3301 if (dsi->debug_read)
3302 DSSDBG("dsi_vc_generic_send_read_request(ch %d, reqlen %d)\n",
3303 channel, reqlen);
3304
3305 if (reqlen == 0) {
3306 data_type = MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM;
3307 data = 0;
3308 } else if (reqlen == 1) {
3309 data_type = MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM;
3310 data = reqdata[0];
3311 } else if (reqlen == 2) {
3312 data_type = MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM;
3313 data = reqdata[0] | (reqdata[1] << 8);
3314 } else {
3315 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03003316 return -EINVAL;
Archit Tanejab3b89c02011-08-30 16:07:39 +05303317 }
3318
3319 r = dsi_vc_send_short(dsidev, channel, data_type, data, 0);
3320 if (r) {
3321 DSSERR("dsi_vc_generic_send_read_request(ch %d, reqlen %d)"
3322 " failed\n", channel, reqlen);
3323 return r;
3324 }
3325
3326 return 0;
3327}
3328
3329static int dsi_vc_read_rx_fifo(struct platform_device *dsidev, int channel,
3330 u8 *buf, int buflen, enum dss_dsi_content_type type)
Archit Tanejab8509752011-08-30 15:48:23 +05303331{
3332 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003333 u32 val;
3334 u8 dt;
3335 int r;
3336
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003337 /* RX_FIFO_NOT_EMPTY */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303338 if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20) == 0) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003339 DSSERR("RX fifo empty when trying to read.\n");
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003340 r = -EIO;
3341 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003342 }
3343
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303344 val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel));
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303345 if (dsi->debug_read)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003346 DSSDBG("\theader: %08x\n", val);
3347 dt = FLD_GET(val, 5, 0);
Archit Taneja7a7c48f2011-08-25 18:25:03 +05303348 if (dt == MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003349 u16 err = FLD_GET(val, 23, 8);
3350 dsi_show_rx_ack_with_err(err);
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003351 r = -EIO;
3352 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003353
Archit Tanejab3b89c02011-08-30 16:07:39 +05303354 } else if (dt == (type == DSS_DSI_CONTENT_GENERIC ?
3355 MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_1BYTE :
3356 MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003357 u8 data = FLD_GET(val, 15, 8);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303358 if (dsi->debug_read)
Archit Tanejab3b89c02011-08-30 16:07:39 +05303359 DSSDBG("\t%s short response, 1 byte: %02x\n",
3360 type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" :
3361 "DCS", data);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003362
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003363 if (buflen < 1) {
3364 r = -EIO;
3365 goto err;
3366 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003367
3368 buf[0] = data;
3369
3370 return 1;
Archit Tanejab3b89c02011-08-30 16:07:39 +05303371 } else if (dt == (type == DSS_DSI_CONTENT_GENERIC ?
3372 MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_2BYTE :
3373 MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003374 u16 data = FLD_GET(val, 23, 8);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303375 if (dsi->debug_read)
Archit Tanejab3b89c02011-08-30 16:07:39 +05303376 DSSDBG("\t%s short response, 2 byte: %04x\n",
3377 type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" :
3378 "DCS", data);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003379
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003380 if (buflen < 2) {
3381 r = -EIO;
3382 goto err;
3383 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003384
3385 buf[0] = data & 0xff;
3386 buf[1] = (data >> 8) & 0xff;
3387
3388 return 2;
Archit Tanejab3b89c02011-08-30 16:07:39 +05303389 } else if (dt == (type == DSS_DSI_CONTENT_GENERIC ?
3390 MIPI_DSI_RX_GENERIC_LONG_READ_RESPONSE :
3391 MIPI_DSI_RX_DCS_LONG_READ_RESPONSE)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003392 int w;
3393 int len = FLD_GET(val, 23, 8);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303394 if (dsi->debug_read)
Archit Tanejab3b89c02011-08-30 16:07:39 +05303395 DSSDBG("\t%s long response, len %d\n",
3396 type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" :
3397 "DCS", len);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003398
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003399 if (len > buflen) {
3400 r = -EIO;
3401 goto err;
3402 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003403
3404 /* two byte checksum ends the packet, not included in len */
3405 for (w = 0; w < len + 2;) {
3406 int b;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303407 val = dsi_read_reg(dsidev,
3408 DSI_VC_SHORT_PACKET_HEADER(channel));
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303409 if (dsi->debug_read)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003410 DSSDBG("\t\t%02x %02x %02x %02x\n",
3411 (val >> 0) & 0xff,
3412 (val >> 8) & 0xff,
3413 (val >> 16) & 0xff,
3414 (val >> 24) & 0xff);
3415
3416 for (b = 0; b < 4; ++b) {
3417 if (w < len)
3418 buf[w] = (val >> (b * 8)) & 0xff;
3419 /* we discard the 2 byte checksum */
3420 ++w;
3421 }
3422 }
3423
3424 return len;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003425 } else {
3426 DSSERR("\tunknown datatype 0x%02x\n", dt);
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003427 r = -EIO;
3428 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003429 }
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003430
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003431err:
Archit Tanejab3b89c02011-08-30 16:07:39 +05303432 DSSERR("dsi_vc_read_rx_fifo(ch %d type %s) failed\n", channel,
3433 type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" : "DCS");
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003434
Archit Tanejab8509752011-08-30 15:48:23 +05303435 return r;
3436}
3437
3438int dsi_vc_dcs_read(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
3439 u8 *buf, int buflen)
3440{
3441 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
3442 int r;
3443
3444 r = dsi_vc_dcs_send_read_request(dssdev, channel, dcs_cmd);
3445 if (r)
3446 goto err;
3447
3448 r = dsi_vc_send_bta_sync(dssdev, channel);
3449 if (r)
3450 goto err;
3451
Archit Tanejab3b89c02011-08-30 16:07:39 +05303452 r = dsi_vc_read_rx_fifo(dsidev, channel, buf, buflen,
3453 DSS_DSI_CONTENT_DCS);
Archit Tanejab8509752011-08-30 15:48:23 +05303454 if (r < 0)
3455 goto err;
3456
3457 if (r != buflen) {
3458 r = -EIO;
3459 goto err;
3460 }
3461
3462 return 0;
3463err:
3464 DSSERR("dsi_vc_dcs_read(ch %d, cmd 0x%02x) failed\n", channel, dcs_cmd);
3465 return r;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003466}
3467EXPORT_SYMBOL(dsi_vc_dcs_read);
3468
Archit Tanejab3b89c02011-08-30 16:07:39 +05303469static int dsi_vc_generic_read(struct omap_dss_device *dssdev, int channel,
3470 u8 *reqdata, int reqlen, u8 *buf, int buflen)
3471{
3472 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
3473 int r;
3474
3475 r = dsi_vc_generic_send_read_request(dssdev, channel, reqdata, reqlen);
3476 if (r)
3477 return r;
3478
3479 r = dsi_vc_send_bta_sync(dssdev, channel);
3480 if (r)
3481 return r;
3482
3483 r = dsi_vc_read_rx_fifo(dsidev, channel, buf, buflen,
3484 DSS_DSI_CONTENT_GENERIC);
3485 if (r < 0)
3486 return r;
3487
3488 if (r != buflen) {
3489 r = -EIO;
3490 return r;
3491 }
3492
3493 return 0;
3494}
3495
3496int dsi_vc_generic_read_0(struct omap_dss_device *dssdev, int channel, u8 *buf,
3497 int buflen)
3498{
3499 int r;
3500
3501 r = dsi_vc_generic_read(dssdev, channel, NULL, 0, buf, buflen);
3502 if (r) {
3503 DSSERR("dsi_vc_generic_read_0(ch %d) failed\n", channel);
3504 return r;
3505 }
3506
3507 return 0;
3508}
3509EXPORT_SYMBOL(dsi_vc_generic_read_0);
3510
3511int dsi_vc_generic_read_1(struct omap_dss_device *dssdev, int channel, u8 param,
3512 u8 *buf, int buflen)
3513{
3514 int r;
3515
3516 r = dsi_vc_generic_read(dssdev, channel, &param, 1, buf, buflen);
3517 if (r) {
3518 DSSERR("dsi_vc_generic_read_1(ch %d) failed\n", channel);
3519 return r;
3520 }
3521
3522 return 0;
3523}
3524EXPORT_SYMBOL(dsi_vc_generic_read_1);
3525
3526int dsi_vc_generic_read_2(struct omap_dss_device *dssdev, int channel,
3527 u8 param1, u8 param2, u8 *buf, int buflen)
3528{
3529 int r;
3530 u8 reqdata[2];
3531
3532 reqdata[0] = param1;
3533 reqdata[1] = param2;
3534
3535 r = dsi_vc_generic_read(dssdev, channel, reqdata, 2, buf, buflen);
3536 if (r) {
3537 DSSERR("dsi_vc_generic_read_2(ch %d) failed\n", channel);
3538 return r;
3539 }
3540
3541 return 0;
3542}
3543EXPORT_SYMBOL(dsi_vc_generic_read_2);
3544
Archit Taneja1ffefe72011-05-12 17:26:24 +05303545int dsi_vc_set_max_rx_packet_size(struct omap_dss_device *dssdev, int channel,
3546 u16 len)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003547{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303548 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
3549
Archit Taneja7a7c48f2011-08-25 18:25:03 +05303550 return dsi_vc_send_short(dsidev, channel,
3551 MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE, len, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003552}
3553EXPORT_SYMBOL(dsi_vc_set_max_rx_packet_size);
3554
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303555static int dsi_enter_ulps(struct platform_device *dsidev)
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003556{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303557 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003558 DECLARE_COMPLETION_ONSTACK(completion);
Tomi Valkeinen522a0c22011-10-13 16:18:52 +03003559 int r, i;
3560 unsigned mask;
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003561
3562 DSSDBGF();
3563
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303564 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003565
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303566 WARN_ON(dsi->ulps_enabled);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003567
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303568 if (dsi->ulps_enabled)
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003569 return 0;
3570
Tomi Valkeinen6cc78aa2011-10-13 19:22:43 +03003571 /* DDR_CLK_ALWAYS_ON */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303572 if (REG_GET(dsidev, DSI_CLK_CTRL, 13, 13)) {
Tomi Valkeinen6cc78aa2011-10-13 19:22:43 +03003573 dsi_if_enable(dsidev, 0);
3574 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 13, 13);
3575 dsi_if_enable(dsidev, 1);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003576 }
3577
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303578 dsi_sync_vc(dsidev, 0);
3579 dsi_sync_vc(dsidev, 1);
3580 dsi_sync_vc(dsidev, 2);
3581 dsi_sync_vc(dsidev, 3);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003582
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303583 dsi_force_tx_stop_mode_io(dsidev);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003584
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303585 dsi_vc_enable(dsidev, 0, false);
3586 dsi_vc_enable(dsidev, 1, false);
3587 dsi_vc_enable(dsidev, 2, false);
3588 dsi_vc_enable(dsidev, 3, false);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003589
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303590 if (REG_GET(dsidev, DSI_COMPLEXIO_CFG2, 16, 16)) { /* HS_BUSY */
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003591 DSSERR("HS busy when enabling ULPS\n");
3592 return -EIO;
3593 }
3594
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303595 if (REG_GET(dsidev, DSI_COMPLEXIO_CFG2, 17, 17)) { /* LP_BUSY */
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003596 DSSERR("LP busy when enabling ULPS\n");
3597 return -EIO;
3598 }
3599
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303600 r = dsi_register_isr_cio(dsidev, dsi_completion_handler, &completion,
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003601 DSI_CIO_IRQ_ULPSACTIVENOT_ALL0);
3602 if (r)
3603 return r;
3604
Tomi Valkeinen522a0c22011-10-13 16:18:52 +03003605 mask = 0;
3606
3607 for (i = 0; i < dsi->num_lanes_supported; ++i) {
3608 if (dsi->lanes[i].function == DSI_LANE_UNUSED)
3609 continue;
3610 mask |= 1 << i;
3611 }
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003612 /* Assert TxRequestEsc for data lanes and TxUlpsClk for clk lane */
3613 /* LANEx_ULPS_SIG2 */
Tomi Valkeinen522a0c22011-10-13 16:18:52 +03003614 REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG2, mask, 9, 5);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003615
Tomi Valkeinena702c852011-10-12 10:10:21 +03003616 /* flush posted write and wait for SCP interface to finish the write */
3617 dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG2);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003618
3619 if (wait_for_completion_timeout(&completion,
3620 msecs_to_jiffies(1000)) == 0) {
3621 DSSERR("ULPS enable timeout\n");
3622 r = -EIO;
3623 goto err;
3624 }
3625
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303626 dsi_unregister_isr_cio(dsidev, dsi_completion_handler, &completion,
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003627 DSI_CIO_IRQ_ULPSACTIVENOT_ALL0);
3628
Tomi Valkeinen8ef0e612011-05-31 16:55:47 +03003629 /* Reset LANEx_ULPS_SIG2 */
Tomi Valkeinen522a0c22011-10-13 16:18:52 +03003630 REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG2, 0, 9, 5);
Tomi Valkeinen8ef0e612011-05-31 16:55:47 +03003631
Tomi Valkeinena702c852011-10-12 10:10:21 +03003632 /* flush posted write and wait for SCP interface to finish the write */
3633 dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG2);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003634
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303635 dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_ULPS);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003636
3637 dsi_if_enable(dsidev, false);
3638
3639 dsi->ulps_enabled = true;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303640
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003641 return 0;
3642
3643err:
3644 dsi_unregister_isr_cio(dsidev, dsi_completion_handler, &completion,
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303645 DSI_CIO_IRQ_ULPSACTIVENOT_ALL0);
3646 return r;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003647}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003648
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003649static void dsi_set_lp_rx_timeout(struct platform_device *dsidev,
3650 unsigned ticks, bool x4, bool x16)
3651{
3652 unsigned long fck;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003653 unsigned long total_ticks;
3654 u32 r;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303655
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003656 BUG_ON(ticks > 0x1fff);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303657
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003658 /* ticks in DSI_FCK */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003659 fck = dsi_fclk_rate(dsidev);
3660
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003661 r = dsi_read_reg(dsidev, DSI_TIMING2);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303662 r = FLD_MOD(r, 1, 15, 15); /* LP_RX_TO */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003663 r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* LP_RX_TO_X16 */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003664 r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* LP_RX_TO_X4 */
3665 r = FLD_MOD(r, ticks, 12, 0); /* LP_RX_COUNTER */
3666 dsi_write_reg(dsidev, DSI_TIMING2, r);
3667
3668 total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
3669
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003670 DSSDBG("LP_RX_TO %lu ticks (%#x%s%s) = %lu ns\n",
3671 total_ticks,
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303672 ticks, x4 ? " x4" : "", x16 ? " x16" : "",
3673 (total_ticks * 1000) / (fck / 1000 / 1000));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003674}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003675
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003676static void dsi_set_ta_timeout(struct platform_device *dsidev, unsigned ticks,
3677 bool x8, bool x16)
3678{
3679 unsigned long fck;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003680 unsigned long total_ticks;
3681 u32 r;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303682
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003683 BUG_ON(ticks > 0x1fff);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303684
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003685 /* ticks in DSI_FCK */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003686 fck = dsi_fclk_rate(dsidev);
3687
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003688 r = dsi_read_reg(dsidev, DSI_TIMING1);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303689 r = FLD_MOD(r, 1, 31, 31); /* TA_TO */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003690 r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* TA_TO_X16 */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003691 r = FLD_MOD(r, x8 ? 1 : 0, 29, 29); /* TA_TO_X8 */
3692 r = FLD_MOD(r, ticks, 28, 16); /* TA_TO_COUNTER */
3693 dsi_write_reg(dsidev, DSI_TIMING1, r);
3694
3695 total_ticks = ticks * (x16 ? 16 : 1) * (x8 ? 8 : 1);
3696
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003697 DSSDBG("TA_TO %lu ticks (%#x%s%s) = %lu ns\n",
3698 total_ticks,
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303699 ticks, x8 ? " x8" : "", x16 ? " x16" : "",
3700 (total_ticks * 1000) / (fck / 1000 / 1000));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003701}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003702
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003703static void dsi_set_stop_state_counter(struct platform_device *dsidev,
3704 unsigned ticks, bool x4, bool x16)
3705{
3706 unsigned long fck;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003707 unsigned long total_ticks;
3708 u32 r;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303709
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003710 BUG_ON(ticks > 0x1fff);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303711
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003712 /* ticks in DSI_FCK */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003713 fck = dsi_fclk_rate(dsidev);
3714
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003715 r = dsi_read_reg(dsidev, DSI_TIMING1);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303716 r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003717 r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* STOP_STATE_X16_IO */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003718 r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* STOP_STATE_X4_IO */
3719 r = FLD_MOD(r, ticks, 12, 0); /* STOP_STATE_COUNTER_IO */
3720 dsi_write_reg(dsidev, DSI_TIMING1, r);
3721
3722 total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
3723
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003724 DSSDBG("STOP_STATE_COUNTER %lu ticks (%#x%s%s) = %lu ns\n",
3725 total_ticks,
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303726 ticks, x4 ? " x4" : "", x16 ? " x16" : "",
3727 (total_ticks * 1000) / (fck / 1000 / 1000));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003728}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003729
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003730static void dsi_set_hs_tx_timeout(struct platform_device *dsidev,
3731 unsigned ticks, bool x4, bool x16)
3732{
3733 unsigned long fck;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003734 unsigned long total_ticks;
3735 u32 r;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303736
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003737 BUG_ON(ticks > 0x1fff);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303738
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003739 /* ticks in TxByteClkHS */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003740 fck = dsi_get_txbyteclkhs(dsidev);
3741
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003742 r = dsi_read_reg(dsidev, DSI_TIMING2);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303743 r = FLD_MOD(r, 1, 31, 31); /* HS_TX_TO */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003744 r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* HS_TX_TO_X16 */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003745 r = FLD_MOD(r, x4 ? 1 : 0, 29, 29); /* HS_TX_TO_X8 (4 really) */
3746 r = FLD_MOD(r, ticks, 28, 16); /* HS_TX_TO_COUNTER */
3747 dsi_write_reg(dsidev, DSI_TIMING2, r);
3748
3749 total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
3750
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003751 DSSDBG("HS_TX_TO %lu ticks (%#x%s%s) = %lu ns\n",
3752 total_ticks,
3753 ticks, x4 ? " x4" : "", x16 ? " x16" : "",
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303754 (total_ticks * 1000) / (fck / 1000 / 1000));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003755}
Archit Taneja8af6ff02011-09-05 16:48:27 +05303756
3757static void dsi_config_vp_num_line_buffers(struct omap_dss_device *dssdev)
3758{
3759 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejadca2b152012-08-16 18:02:00 +05303760 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Taneja8af6ff02011-09-05 16:48:27 +05303761 int num_line_buffers;
3762
Archit Tanejadca2b152012-08-16 18:02:00 +05303763 if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
Archit Tanejae67458a2012-08-13 14:17:30 +05303764 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Taneja02c39602012-08-10 15:01:33 +05303765 int bpp = dsi_get_pixel_size(dsi->pix_fmt);
Archit Taneja8af6ff02011-09-05 16:48:27 +05303766 unsigned line_buf_size = dsi_get_line_buf_size(dsidev);
Archit Tanejae67458a2012-08-13 14:17:30 +05303767 struct omap_video_timings *timings = &dsi->timings;
Archit Taneja8af6ff02011-09-05 16:48:27 +05303768 /*
3769 * Don't use line buffers if width is greater than the video
3770 * port's line buffer size
3771 */
3772 if (line_buf_size <= timings->x_res * bpp / 8)
3773 num_line_buffers = 0;
3774 else
3775 num_line_buffers = 2;
3776 } else {
3777 /* Use maximum number of line buffers in command mode */
3778 num_line_buffers = 2;
3779 }
3780
3781 /* LINE_BUFFER */
3782 REG_FLD_MOD(dsidev, DSI_CTRL, num_line_buffers, 13, 12);
3783}
3784
3785static void dsi_config_vp_sync_events(struct omap_dss_device *dssdev)
3786{
3787 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Taneja0b3ffe32012-08-13 22:13:39 +05303788 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
3789 bool vsync_end = dsi->vm_timings.vp_vsync_end;
3790 bool hsync_end = dsi->vm_timings.vp_hsync_end;
Archit Taneja8af6ff02011-09-05 16:48:27 +05303791 u32 r;
3792
3793 r = dsi_read_reg(dsidev, DSI_CTRL);
Archit Tanejabd5a7b12012-06-26 12:38:31 +05303794 r = FLD_MOD(r, 1, 9, 9); /* VP_DE_POL */
3795 r = FLD_MOD(r, 1, 10, 10); /* VP_HSYNC_POL */
3796 r = FLD_MOD(r, 1, 11, 11); /* VP_VSYNC_POL */
Archit Taneja8af6ff02011-09-05 16:48:27 +05303797 r = FLD_MOD(r, 1, 15, 15); /* VP_VSYNC_START */
3798 r = FLD_MOD(r, vsync_end, 16, 16); /* VP_VSYNC_END */
3799 r = FLD_MOD(r, 1, 17, 17); /* VP_HSYNC_START */
3800 r = FLD_MOD(r, hsync_end, 18, 18); /* VP_HSYNC_END */
3801 dsi_write_reg(dsidev, DSI_CTRL, r);
3802}
3803
3804static void dsi_config_blanking_modes(struct omap_dss_device *dssdev)
3805{
3806 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Taneja0b3ffe32012-08-13 22:13:39 +05303807 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
3808 int blanking_mode = dsi->vm_timings.blanking_mode;
3809 int hfp_blanking_mode = dsi->vm_timings.hfp_blanking_mode;
3810 int hbp_blanking_mode = dsi->vm_timings.hbp_blanking_mode;
3811 int hsa_blanking_mode = dsi->vm_timings.hsa_blanking_mode;
Archit Taneja8af6ff02011-09-05 16:48:27 +05303812 u32 r;
3813
3814 /*
3815 * 0 = TX FIFO packets sent or LPS in corresponding blanking periods
3816 * 1 = Long blanking packets are sent in corresponding blanking periods
3817 */
3818 r = dsi_read_reg(dsidev, DSI_CTRL);
3819 r = FLD_MOD(r, blanking_mode, 20, 20); /* BLANKING_MODE */
3820 r = FLD_MOD(r, hfp_blanking_mode, 21, 21); /* HFP_BLANKING */
3821 r = FLD_MOD(r, hbp_blanking_mode, 22, 22); /* HBP_BLANKING */
3822 r = FLD_MOD(r, hsa_blanking_mode, 23, 23); /* HSA_BLANKING */
3823 dsi_write_reg(dsidev, DSI_CTRL, r);
3824}
3825
Archit Taneja6f28c292012-05-15 11:32:18 +05303826/*
3827 * According to section 'HS Command Mode Interleaving' in OMAP TRM, Scenario 3
3828 * results in maximum transition time for data and clock lanes to enter and
3829 * exit HS mode. Hence, this is the scenario where the least amount of command
3830 * mode data can be interleaved. We program the minimum amount of TXBYTECLKHS
3831 * clock cycles that can be used to interleave command mode data in HS so that
3832 * all scenarios are satisfied.
3833 */
3834static int dsi_compute_interleave_hs(int blank, bool ddr_alwon, int enter_hs,
3835 int exit_hs, int exiths_clk, int ddr_pre, int ddr_post)
3836{
3837 int transition;
3838
3839 /*
3840 * If DDR_CLK_ALWAYS_ON is set, we need to consider HS mode transition
3841 * time of data lanes only, if it isn't set, we need to consider HS
3842 * transition time of both data and clock lanes. HS transition time
3843 * of Scenario 3 is considered.
3844 */
3845 if (ddr_alwon) {
3846 transition = enter_hs + exit_hs + max(enter_hs, 2) + 1;
3847 } else {
3848 int trans1, trans2;
3849 trans1 = ddr_pre + enter_hs + exit_hs + max(enter_hs, 2) + 1;
3850 trans2 = ddr_pre + enter_hs + exiths_clk + ddr_post + ddr_pre +
3851 enter_hs + 1;
3852 transition = max(trans1, trans2);
3853 }
3854
3855 return blank > transition ? blank - transition : 0;
3856}
3857
3858/*
3859 * According to section 'LP Command Mode Interleaving' in OMAP TRM, Scenario 1
3860 * results in maximum transition time for data lanes to enter and exit LP mode.
3861 * Hence, this is the scenario where the least amount of command mode data can
3862 * be interleaved. We program the minimum amount of bytes that can be
3863 * interleaved in LP so that all scenarios are satisfied.
3864 */
3865static int dsi_compute_interleave_lp(int blank, int enter_hs, int exit_hs,
3866 int lp_clk_div, int tdsi_fclk)
3867{
3868 int trans_lp; /* time required for a LP transition, in TXBYTECLKHS */
3869 int tlp_avail; /* time left for interleaving commands, in CLKIN4DDR */
3870 int ttxclkesc; /* period of LP transmit escape clock, in CLKIN4DDR */
3871 int thsbyte_clk = 16; /* Period of TXBYTECLKHS clock, in CLKIN4DDR */
3872 int lp_inter; /* cmd mode data that can be interleaved, in bytes */
3873
3874 /* maximum LP transition time according to Scenario 1 */
3875 trans_lp = exit_hs + max(enter_hs, 2) + 1;
3876
3877 /* CLKIN4DDR = 16 * TXBYTECLKHS */
3878 tlp_avail = thsbyte_clk * (blank - trans_lp);
3879
Archit Taneja2e063c32012-06-04 13:36:34 +05303880 ttxclkesc = tdsi_fclk * lp_clk_div;
Archit Taneja6f28c292012-05-15 11:32:18 +05303881
3882 lp_inter = ((tlp_avail - 8 * thsbyte_clk - 5 * tdsi_fclk) / ttxclkesc -
3883 26) / 16;
3884
3885 return max(lp_inter, 0);
3886}
3887
3888static void dsi_config_cmd_mode_interleaving(struct omap_dss_device *dssdev)
3889{
3890 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
3891 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
3892 int blanking_mode;
3893 int hfp_blanking_mode, hbp_blanking_mode, hsa_blanking_mode;
3894 int hsa, hfp, hbp, width_bytes, bllp, lp_clk_div;
3895 int ddr_clk_pre, ddr_clk_post, enter_hs_mode_lat, exit_hs_mode_lat;
3896 int tclk_trail, ths_exit, exiths_clk;
3897 bool ddr_alwon;
Archit Tanejae67458a2012-08-13 14:17:30 +05303898 struct omap_video_timings *timings = &dsi->timings;
Archit Taneja02c39602012-08-10 15:01:33 +05303899 int bpp = dsi_get_pixel_size(dsi->pix_fmt);
Archit Taneja6f28c292012-05-15 11:32:18 +05303900 int ndl = dsi->num_lanes_used - 1;
3901 int dsi_fclk_hsdiv = dssdev->clocks.dsi.regm_dsi + 1;
3902 int hsa_interleave_hs = 0, hsa_interleave_lp = 0;
3903 int hfp_interleave_hs = 0, hfp_interleave_lp = 0;
3904 int hbp_interleave_hs = 0, hbp_interleave_lp = 0;
3905 int bl_interleave_hs = 0, bl_interleave_lp = 0;
3906 u32 r;
3907
3908 r = dsi_read_reg(dsidev, DSI_CTRL);
3909 blanking_mode = FLD_GET(r, 20, 20);
3910 hfp_blanking_mode = FLD_GET(r, 21, 21);
3911 hbp_blanking_mode = FLD_GET(r, 22, 22);
3912 hsa_blanking_mode = FLD_GET(r, 23, 23);
3913
3914 r = dsi_read_reg(dsidev, DSI_VM_TIMING1);
3915 hbp = FLD_GET(r, 11, 0);
3916 hfp = FLD_GET(r, 23, 12);
3917 hsa = FLD_GET(r, 31, 24);
3918
3919 r = dsi_read_reg(dsidev, DSI_CLK_TIMING);
3920 ddr_clk_post = FLD_GET(r, 7, 0);
3921 ddr_clk_pre = FLD_GET(r, 15, 8);
3922
3923 r = dsi_read_reg(dsidev, DSI_VM_TIMING7);
3924 exit_hs_mode_lat = FLD_GET(r, 15, 0);
3925 enter_hs_mode_lat = FLD_GET(r, 31, 16);
3926
3927 r = dsi_read_reg(dsidev, DSI_CLK_CTRL);
3928 lp_clk_div = FLD_GET(r, 12, 0);
3929 ddr_alwon = FLD_GET(r, 13, 13);
3930
3931 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0);
3932 ths_exit = FLD_GET(r, 7, 0);
3933
3934 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1);
3935 tclk_trail = FLD_GET(r, 15, 8);
3936
3937 exiths_clk = ths_exit + tclk_trail;
3938
3939 width_bytes = DIV_ROUND_UP(timings->x_res * bpp, 8);
3940 bllp = hbp + hfp + hsa + DIV_ROUND_UP(width_bytes + 6, ndl);
3941
3942 if (!hsa_blanking_mode) {
3943 hsa_interleave_hs = dsi_compute_interleave_hs(hsa, ddr_alwon,
3944 enter_hs_mode_lat, exit_hs_mode_lat,
3945 exiths_clk, ddr_clk_pre, ddr_clk_post);
3946 hsa_interleave_lp = dsi_compute_interleave_lp(hsa,
3947 enter_hs_mode_lat, exit_hs_mode_lat,
3948 lp_clk_div, dsi_fclk_hsdiv);
3949 }
3950
3951 if (!hfp_blanking_mode) {
3952 hfp_interleave_hs = dsi_compute_interleave_hs(hfp, ddr_alwon,
3953 enter_hs_mode_lat, exit_hs_mode_lat,
3954 exiths_clk, ddr_clk_pre, ddr_clk_post);
3955 hfp_interleave_lp = dsi_compute_interleave_lp(hfp,
3956 enter_hs_mode_lat, exit_hs_mode_lat,
3957 lp_clk_div, dsi_fclk_hsdiv);
3958 }
3959
3960 if (!hbp_blanking_mode) {
3961 hbp_interleave_hs = dsi_compute_interleave_hs(hbp, ddr_alwon,
3962 enter_hs_mode_lat, exit_hs_mode_lat,
3963 exiths_clk, ddr_clk_pre, ddr_clk_post);
3964
3965 hbp_interleave_lp = dsi_compute_interleave_lp(hbp,
3966 enter_hs_mode_lat, exit_hs_mode_lat,
3967 lp_clk_div, dsi_fclk_hsdiv);
3968 }
3969
3970 if (!blanking_mode) {
3971 bl_interleave_hs = dsi_compute_interleave_hs(bllp, ddr_alwon,
3972 enter_hs_mode_lat, exit_hs_mode_lat,
3973 exiths_clk, ddr_clk_pre, ddr_clk_post);
3974
3975 bl_interleave_lp = dsi_compute_interleave_lp(bllp,
3976 enter_hs_mode_lat, exit_hs_mode_lat,
3977 lp_clk_div, dsi_fclk_hsdiv);
3978 }
3979
3980 DSSDBG("DSI HS interleaving(TXBYTECLKHS) HSA %d, HFP %d, HBP %d, BLLP %d\n",
3981 hsa_interleave_hs, hfp_interleave_hs, hbp_interleave_hs,
3982 bl_interleave_hs);
3983
3984 DSSDBG("DSI LP interleaving(bytes) HSA %d, HFP %d, HBP %d, BLLP %d\n",
3985 hsa_interleave_lp, hfp_interleave_lp, hbp_interleave_lp,
3986 bl_interleave_lp);
3987
3988 r = dsi_read_reg(dsidev, DSI_VM_TIMING4);
3989 r = FLD_MOD(r, hsa_interleave_hs, 23, 16);
3990 r = FLD_MOD(r, hfp_interleave_hs, 15, 8);
3991 r = FLD_MOD(r, hbp_interleave_hs, 7, 0);
3992 dsi_write_reg(dsidev, DSI_VM_TIMING4, r);
3993
3994 r = dsi_read_reg(dsidev, DSI_VM_TIMING5);
3995 r = FLD_MOD(r, hsa_interleave_lp, 23, 16);
3996 r = FLD_MOD(r, hfp_interleave_lp, 15, 8);
3997 r = FLD_MOD(r, hbp_interleave_lp, 7, 0);
3998 dsi_write_reg(dsidev, DSI_VM_TIMING5, r);
3999
4000 r = dsi_read_reg(dsidev, DSI_VM_TIMING6);
4001 r = FLD_MOD(r, bl_interleave_hs, 31, 15);
4002 r = FLD_MOD(r, bl_interleave_lp, 16, 0);
4003 dsi_write_reg(dsidev, DSI_VM_TIMING6, r);
4004}
4005
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004006static int dsi_proto_config(struct omap_dss_device *dssdev)
4007{
4008 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Taneja02c39602012-08-10 15:01:33 +05304009 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004010 u32 r;
4011 int buswidth = 0;
4012
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304013 dsi_config_tx_fifo(dsidev, DSI_FIFO_SIZE_32,
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02004014 DSI_FIFO_SIZE_32,
4015 DSI_FIFO_SIZE_32,
4016 DSI_FIFO_SIZE_32);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004017
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304018 dsi_config_rx_fifo(dsidev, DSI_FIFO_SIZE_32,
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02004019 DSI_FIFO_SIZE_32,
4020 DSI_FIFO_SIZE_32,
4021 DSI_FIFO_SIZE_32);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004022
4023 /* XXX what values for the timeouts? */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304024 dsi_set_stop_state_counter(dsidev, 0x1000, false, false);
4025 dsi_set_ta_timeout(dsidev, 0x1fff, true, true);
4026 dsi_set_lp_rx_timeout(dsidev, 0x1fff, true, true);
4027 dsi_set_hs_tx_timeout(dsidev, 0x1fff, true, true);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004028
Archit Taneja02c39602012-08-10 15:01:33 +05304029 switch (dsi_get_pixel_size(dsi->pix_fmt)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004030 case 16:
4031 buswidth = 0;
4032 break;
4033 case 18:
4034 buswidth = 1;
4035 break;
4036 case 24:
4037 buswidth = 2;
4038 break;
4039 default:
4040 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03004041 return -EINVAL;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004042 }
4043
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304044 r = dsi_read_reg(dsidev, DSI_CTRL);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004045 r = FLD_MOD(r, 1, 1, 1); /* CS_RX_EN */
4046 r = FLD_MOD(r, 1, 2, 2); /* ECC_RX_EN */
4047 r = FLD_MOD(r, 1, 3, 3); /* TX_FIFO_ARBITRATION */
4048 r = FLD_MOD(r, 1, 4, 4); /* VP_CLK_RATIO, always 1, see errata*/
4049 r = FLD_MOD(r, buswidth, 7, 6); /* VP_DATA_BUS_WIDTH */
4050 r = FLD_MOD(r, 0, 8, 8); /* VP_CLK_POL */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004051 r = FLD_MOD(r, 1, 14, 14); /* TRIGGER_RESET_MODE */
4052 r = FLD_MOD(r, 1, 19, 19); /* EOT_ENABLE */
Archit Taneja9613c022011-03-22 06:33:36 -05004053 if (!dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC)) {
4054 r = FLD_MOD(r, 1, 24, 24); /* DCS_CMD_ENABLE */
4055 /* DCS_CMD_CODE, 1=start, 0=continue */
4056 r = FLD_MOD(r, 0, 25, 25);
4057 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004058
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304059 dsi_write_reg(dsidev, DSI_CTRL, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004060
Archit Taneja8af6ff02011-09-05 16:48:27 +05304061 dsi_config_vp_num_line_buffers(dssdev);
4062
Archit Tanejadca2b152012-08-16 18:02:00 +05304063 if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
Archit Taneja8af6ff02011-09-05 16:48:27 +05304064 dsi_config_vp_sync_events(dssdev);
4065 dsi_config_blanking_modes(dssdev);
Archit Taneja6f28c292012-05-15 11:32:18 +05304066 dsi_config_cmd_mode_interleaving(dssdev);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304067 }
4068
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304069 dsi_vc_initial_config(dsidev, 0);
4070 dsi_vc_initial_config(dsidev, 1);
4071 dsi_vc_initial_config(dsidev, 2);
4072 dsi_vc_initial_config(dsidev, 3);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004073
4074 return 0;
4075}
4076
4077static void dsi_proto_timings(struct omap_dss_device *dssdev)
4078{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304079 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Tomi Valkeinendb186442011-10-13 16:12:29 +03004080 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004081 unsigned tlpx, tclk_zero, tclk_prepare, tclk_trail;
4082 unsigned tclk_pre, tclk_post;
4083 unsigned ths_prepare, ths_prepare_ths_zero, ths_zero;
4084 unsigned ths_trail, ths_exit;
4085 unsigned ddr_clk_pre, ddr_clk_post;
4086 unsigned enter_hs_mode_lat, exit_hs_mode_lat;
4087 unsigned ths_eot;
Tomi Valkeinendb186442011-10-13 16:12:29 +03004088 int ndl = dsi->num_lanes_used - 1;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004089 u32 r;
4090
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304091 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004092 ths_prepare = FLD_GET(r, 31, 24);
4093 ths_prepare_ths_zero = FLD_GET(r, 23, 16);
4094 ths_zero = ths_prepare_ths_zero - ths_prepare;
4095 ths_trail = FLD_GET(r, 15, 8);
4096 ths_exit = FLD_GET(r, 7, 0);
4097
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304098 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004099 tlpx = FLD_GET(r, 22, 16) * 2;
4100 tclk_trail = FLD_GET(r, 15, 8);
4101 tclk_zero = FLD_GET(r, 7, 0);
4102
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304103 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG2);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004104 tclk_prepare = FLD_GET(r, 7, 0);
4105
4106 /* min 8*UI */
4107 tclk_pre = 20;
4108 /* min 60ns + 52*UI */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304109 tclk_post = ns2ddr(dsidev, 60) + 26;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004110
Archit Taneja8af6ff02011-09-05 16:48:27 +05304111 ths_eot = DIV_ROUND_UP(4, ndl);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004112
4113 ddr_clk_pre = DIV_ROUND_UP(tclk_pre + tlpx + tclk_zero + tclk_prepare,
4114 4);
4115 ddr_clk_post = DIV_ROUND_UP(tclk_post + ths_trail, 4) + ths_eot;
4116
4117 BUG_ON(ddr_clk_pre == 0 || ddr_clk_pre > 255);
4118 BUG_ON(ddr_clk_post == 0 || ddr_clk_post > 255);
4119
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304120 r = dsi_read_reg(dsidev, DSI_CLK_TIMING);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004121 r = FLD_MOD(r, ddr_clk_pre, 15, 8);
4122 r = FLD_MOD(r, ddr_clk_post, 7, 0);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304123 dsi_write_reg(dsidev, DSI_CLK_TIMING, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004124
4125 DSSDBG("ddr_clk_pre %u, ddr_clk_post %u\n",
4126 ddr_clk_pre,
4127 ddr_clk_post);
4128
4129 enter_hs_mode_lat = 1 + DIV_ROUND_UP(tlpx, 4) +
4130 DIV_ROUND_UP(ths_prepare, 4) +
4131 DIV_ROUND_UP(ths_zero + 3, 4);
4132
4133 exit_hs_mode_lat = DIV_ROUND_UP(ths_trail + ths_exit, 4) + 1 + ths_eot;
4134
4135 r = FLD_VAL(enter_hs_mode_lat, 31, 16) |
4136 FLD_VAL(exit_hs_mode_lat, 15, 0);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304137 dsi_write_reg(dsidev, DSI_VM_TIMING7, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004138
4139 DSSDBG("enter_hs_mode_lat %u, exit_hs_mode_lat %u\n",
4140 enter_hs_mode_lat, exit_hs_mode_lat);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304141
Archit Tanejadca2b152012-08-16 18:02:00 +05304142 if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
Archit Taneja8af6ff02011-09-05 16:48:27 +05304143 /* TODO: Implement a video mode check_timings function */
Archit Taneja0b3ffe32012-08-13 22:13:39 +05304144 int hsa = dsi->vm_timings.hsa;
4145 int hfp = dsi->vm_timings.hfp;
4146 int hbp = dsi->vm_timings.hbp;
4147 int vsa = dsi->vm_timings.vsa;
4148 int vfp = dsi->vm_timings.vfp;
4149 int vbp = dsi->vm_timings.vbp;
4150 int window_sync = dsi->vm_timings.window_sync;
4151 bool hsync_end = dsi->vm_timings.vp_hsync_end;
Archit Tanejae67458a2012-08-13 14:17:30 +05304152 struct omap_video_timings *timings = &dsi->timings;
Archit Taneja02c39602012-08-10 15:01:33 +05304153 int bpp = dsi_get_pixel_size(dsi->pix_fmt);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304154 int tl, t_he, width_bytes;
4155
4156 t_he = hsync_end ?
4157 ((hsa == 0 && ndl == 3) ? 1 : DIV_ROUND_UP(4, ndl)) : 0;
4158
4159 width_bytes = DIV_ROUND_UP(timings->x_res * bpp, 8);
4160
4161 /* TL = t_HS + HSA + t_HE + HFP + ceil((WC + 6) / NDL) + HBP */
4162 tl = DIV_ROUND_UP(4, ndl) + (hsync_end ? hsa : 0) + t_he + hfp +
4163 DIV_ROUND_UP(width_bytes + 6, ndl) + hbp;
4164
4165 DSSDBG("HBP: %d, HFP: %d, HSA: %d, TL: %d TXBYTECLKHS\n", hbp,
4166 hfp, hsync_end ? hsa : 0, tl);
4167 DSSDBG("VBP: %d, VFP: %d, VSA: %d, VACT: %d lines\n", vbp, vfp,
4168 vsa, timings->y_res);
4169
4170 r = dsi_read_reg(dsidev, DSI_VM_TIMING1);
4171 r = FLD_MOD(r, hbp, 11, 0); /* HBP */
4172 r = FLD_MOD(r, hfp, 23, 12); /* HFP */
4173 r = FLD_MOD(r, hsync_end ? hsa : 0, 31, 24); /* HSA */
4174 dsi_write_reg(dsidev, DSI_VM_TIMING1, r);
4175
4176 r = dsi_read_reg(dsidev, DSI_VM_TIMING2);
4177 r = FLD_MOD(r, vbp, 7, 0); /* VBP */
4178 r = FLD_MOD(r, vfp, 15, 8); /* VFP */
4179 r = FLD_MOD(r, vsa, 23, 16); /* VSA */
4180 r = FLD_MOD(r, window_sync, 27, 24); /* WINDOW_SYNC */
4181 dsi_write_reg(dsidev, DSI_VM_TIMING2, r);
4182
4183 r = dsi_read_reg(dsidev, DSI_VM_TIMING3);
4184 r = FLD_MOD(r, timings->y_res, 14, 0); /* VACT */
4185 r = FLD_MOD(r, tl, 31, 16); /* TL */
4186 dsi_write_reg(dsidev, DSI_VM_TIMING3, r);
4187 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004188}
4189
Tomi Valkeinene4a9e942012-03-28 15:58:56 +03004190int omapdss_dsi_configure_pins(struct omap_dss_device *dssdev,
4191 const struct omap_dsi_pin_config *pin_cfg)
4192{
4193 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4194 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4195 int num_pins;
4196 const int *pins;
4197 struct dsi_lane_config lanes[DSI_MAX_NR_LANES];
4198 int num_lanes;
4199 int i;
4200
4201 static const enum dsi_lane_function functions[] = {
4202 DSI_LANE_CLK,
4203 DSI_LANE_DATA1,
4204 DSI_LANE_DATA2,
4205 DSI_LANE_DATA3,
4206 DSI_LANE_DATA4,
4207 };
4208
4209 num_pins = pin_cfg->num_pins;
4210 pins = pin_cfg->pins;
4211
4212 if (num_pins < 4 || num_pins > dsi->num_lanes_supported * 2
4213 || num_pins % 2 != 0)
4214 return -EINVAL;
4215
4216 for (i = 0; i < DSI_MAX_NR_LANES; ++i)
4217 lanes[i].function = DSI_LANE_UNUSED;
4218
4219 num_lanes = 0;
4220
4221 for (i = 0; i < num_pins; i += 2) {
4222 u8 lane, pol;
4223 int dx, dy;
4224
4225 dx = pins[i];
4226 dy = pins[i + 1];
4227
4228 if (dx < 0 || dx >= dsi->num_lanes_supported * 2)
4229 return -EINVAL;
4230
4231 if (dy < 0 || dy >= dsi->num_lanes_supported * 2)
4232 return -EINVAL;
4233
4234 if (dx & 1) {
4235 if (dy != dx - 1)
4236 return -EINVAL;
4237 pol = 1;
4238 } else {
4239 if (dy != dx + 1)
4240 return -EINVAL;
4241 pol = 0;
4242 }
4243
4244 lane = dx / 2;
4245
4246 lanes[lane].function = functions[i / 2];
4247 lanes[lane].polarity = pol;
4248 num_lanes++;
4249 }
4250
4251 memcpy(dsi->lanes, lanes, sizeof(dsi->lanes));
4252 dsi->num_lanes_used = num_lanes;
4253
4254 return 0;
4255}
4256EXPORT_SYMBOL(omapdss_dsi_configure_pins);
4257
Tomi Valkeinenee144e62012-08-10 16:50:51 +03004258int omapdss_dsi_set_clocks(struct omap_dss_device *dssdev,
4259 unsigned long ddr_clk, unsigned long lp_clk)
4260{
4261 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4262 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4263 struct dsi_clock_info cinfo;
4264 struct dispc_clock_info dispc_cinfo;
4265 unsigned lp_clk_div;
4266 unsigned long dsi_fclk;
4267 int bpp = dsi_get_pixel_size(dssdev->panel.dsi_pix_fmt);
4268 unsigned long pck;
4269 int r;
4270
4271 DSSDBGF("ddr_clk %lu, lp_clk %lu", ddr_clk, lp_clk);
4272
4273 mutex_lock(&dsi->lock);
4274
Tomi Valkeinend66b1582012-09-24 15:15:06 +03004275 /* Calculate PLL output clock */
4276 r = dsi_pll_calc_ddrfreq(dsidev, ddr_clk * 4, &cinfo);
Tomi Valkeinenee144e62012-08-10 16:50:51 +03004277 if (r)
4278 goto err;
4279
Tomi Valkeinend66b1582012-09-24 15:15:06 +03004280 /* Calculate PLL's DSI clock */
4281 dsi_pll_calc_dsi_fck(dsidev, &cinfo);
4282
4283 /* Calculate PLL's DISPC clock and pck & lck divs */
4284 pck = cinfo.clkin4ddr / 16 * (dsi->num_lanes_used - 1) * 8 / bpp;
4285 DSSDBG("finding dispc dividers for pck %lu\n", pck);
4286 r = dsi_pll_calc_dispc_fck(dsidev, pck, &cinfo, &dispc_cinfo);
4287 if (r)
4288 goto err;
4289
4290 /* Calculate LP clock */
4291 dsi_fclk = cinfo.dsi_pll_hsdiv_dsi_clk;
4292 lp_clk_div = DIV_ROUND_UP(dsi_fclk, lp_clk * 2);
4293
Tomi Valkeinenee144e62012-08-10 16:50:51 +03004294 dssdev->clocks.dsi.regn = cinfo.regn;
4295 dssdev->clocks.dsi.regm = cinfo.regm;
4296 dssdev->clocks.dsi.regm_dispc = cinfo.regm_dispc;
4297 dssdev->clocks.dsi.regm_dsi = cinfo.regm_dsi;
4298
Tomi Valkeinenee144e62012-08-10 16:50:51 +03004299 dssdev->clocks.dsi.lp_clk_div = lp_clk_div;
4300
Tomi Valkeinenee144e62012-08-10 16:50:51 +03004301 dssdev->clocks.dispc.channel.lck_div = dispc_cinfo.lck_div;
4302 dssdev->clocks.dispc.channel.pck_div = dispc_cinfo.pck_div;
4303
Tomi Valkeinenee144e62012-08-10 16:50:51 +03004304 dssdev->clocks.dispc.dispc_fclk_src = OMAP_DSS_CLK_SRC_FCK;
4305
4306 dssdev->clocks.dispc.channel.lcd_clk_src =
4307 dsi->module_id == 0 ?
4308 OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC :
4309 OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC;
4310
4311 dssdev->clocks.dsi.dsi_fclk_src =
4312 dsi->module_id == 0 ?
4313 OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI :
4314 OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DSI;
4315
4316 mutex_unlock(&dsi->lock);
4317 return 0;
4318err:
4319 mutex_unlock(&dsi->lock);
4320 return r;
4321}
4322EXPORT_SYMBOL(omapdss_dsi_set_clocks);
4323
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004324int dsi_enable_video_output(struct omap_dss_device *dssdev, int channel)
Archit Taneja8af6ff02011-09-05 16:48:27 +05304325{
4326 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejae67458a2012-08-13 14:17:30 +05304327 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Taneja02c39602012-08-10 15:01:33 +05304328 int bpp = dsi_get_pixel_size(dsi->pix_fmt);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304329 u8 data_type;
4330 u16 word_count;
Tomi Valkeinen33ca2372011-11-21 13:42:58 +02004331 int r;
Archit Taneja8af6ff02011-09-05 16:48:27 +05304332
Archit Tanejadca2b152012-08-16 18:02:00 +05304333 if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
Archit Taneja02c39602012-08-10 15:01:33 +05304334 switch (dsi->pix_fmt) {
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004335 case OMAP_DSS_DSI_FMT_RGB888:
4336 data_type = MIPI_DSI_PACKED_PIXEL_STREAM_24;
4337 break;
4338 case OMAP_DSS_DSI_FMT_RGB666:
4339 data_type = MIPI_DSI_PIXEL_STREAM_3BYTE_18;
4340 break;
4341 case OMAP_DSS_DSI_FMT_RGB666_PACKED:
4342 data_type = MIPI_DSI_PACKED_PIXEL_STREAM_18;
4343 break;
4344 case OMAP_DSS_DSI_FMT_RGB565:
4345 data_type = MIPI_DSI_PACKED_PIXEL_STREAM_16;
4346 break;
4347 default:
4348 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03004349 return -EINVAL;
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004350 };
Archit Taneja8af6ff02011-09-05 16:48:27 +05304351
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004352 dsi_if_enable(dsidev, false);
4353 dsi_vc_enable(dsidev, channel, false);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304354
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004355 /* MODE, 1 = video mode */
4356 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 1, 4, 4);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304357
Archit Tanejae67458a2012-08-13 14:17:30 +05304358 word_count = DIV_ROUND_UP(dsi->timings.x_res * bpp, 8);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304359
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004360 dsi_vc_write_long_header(dsidev, channel, data_type,
4361 word_count, 0);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304362
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004363 dsi_vc_enable(dsidev, channel, true);
4364 dsi_if_enable(dsidev, true);
4365 }
Archit Taneja8af6ff02011-09-05 16:48:27 +05304366
Tomi Valkeinen33ca2372011-11-21 13:42:58 +02004367 r = dss_mgr_enable(dssdev->manager);
4368 if (r) {
Archit Tanejadca2b152012-08-16 18:02:00 +05304369 if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
Tomi Valkeinen33ca2372011-11-21 13:42:58 +02004370 dsi_if_enable(dsidev, false);
4371 dsi_vc_enable(dsidev, channel, false);
4372 }
4373
4374 return r;
4375 }
Archit Taneja8af6ff02011-09-05 16:48:27 +05304376
4377 return 0;
4378}
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004379EXPORT_SYMBOL(dsi_enable_video_output);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304380
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004381void dsi_disable_video_output(struct omap_dss_device *dssdev, int channel)
Archit Taneja8af6ff02011-09-05 16:48:27 +05304382{
4383 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejadca2b152012-08-16 18:02:00 +05304384 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304385
Archit Tanejadca2b152012-08-16 18:02:00 +05304386 if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004387 dsi_if_enable(dsidev, false);
4388 dsi_vc_enable(dsidev, channel, false);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304389
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004390 /* MODE, 0 = command mode */
4391 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 0, 4, 4);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304392
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004393 dsi_vc_enable(dsidev, channel, true);
4394 dsi_if_enable(dsidev, true);
4395 }
Archit Taneja8af6ff02011-09-05 16:48:27 +05304396
Tomi Valkeinen7797c6d2011-11-04 10:22:46 +02004397 dss_mgr_disable(dssdev->manager);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304398}
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004399EXPORT_SYMBOL(dsi_disable_video_output);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304400
Archit Taneja55cd63a2012-08-09 15:41:13 +05304401static void dsi_update_screen_dispc(struct omap_dss_device *dssdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004402{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304403 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304404 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004405 unsigned bytespp;
4406 unsigned bytespl;
4407 unsigned bytespf;
4408 unsigned total_len;
4409 unsigned packet_payload;
4410 unsigned packet_len;
4411 u32 l;
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03004412 int r;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304413 const unsigned channel = dsi->update_channel;
Archit Taneja0c656222011-05-16 15:17:09 +05304414 const unsigned line_buf_size = dsi_get_line_buf_size(dsidev);
Archit Taneja55cd63a2012-08-09 15:41:13 +05304415 u16 w = dsi->timings.x_res;
4416 u16 h = dsi->timings.y_res;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004417
Tomi Valkeinen5476e742011-11-03 16:34:20 +02004418 DSSDBG("dsi_update_screen_dispc(%dx%d)\n", w, h);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004419
Archit Tanejad6049142011-08-22 11:58:08 +05304420 dsi_vc_config_source(dsidev, channel, DSI_VC_SOURCE_VP);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004421
Archit Taneja02c39602012-08-10 15:01:33 +05304422 bytespp = dsi_get_pixel_size(dsi->pix_fmt) / 8;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004423 bytespl = w * bytespp;
4424 bytespf = bytespl * h;
4425
4426 /* NOTE: packet_payload has to be equal to N * bytespl, where N is
4427 * number of lines in a packet. See errata about VP_CLK_RATIO */
4428
4429 if (bytespf < line_buf_size)
4430 packet_payload = bytespf;
4431 else
4432 packet_payload = (line_buf_size) / bytespl * bytespl;
4433
4434 packet_len = packet_payload + 1; /* 1 byte for DCS cmd */
4435 total_len = (bytespf / packet_payload) * packet_len;
4436
4437 if (bytespf % packet_payload)
4438 total_len += (bytespf % packet_payload) + 1;
4439
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004440 l = FLD_VAL(total_len, 23, 0); /* TE_SIZE */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304441 dsi_write_reg(dsidev, DSI_VC_TE(channel), l);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004442
Archit Taneja7a7c48f2011-08-25 18:25:03 +05304443 dsi_vc_write_long_header(dsidev, channel, MIPI_DSI_DCS_LONG_WRITE,
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304444 packet_len, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004445
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304446 if (dsi->te_enabled)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004447 l = FLD_MOD(l, 1, 30, 30); /* TE_EN */
4448 else
4449 l = FLD_MOD(l, 1, 31, 31); /* TE_START */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304450 dsi_write_reg(dsidev, DSI_VC_TE(channel), l);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004451
4452 /* We put SIDLEMODE to no-idle for the duration of the transfer,
4453 * because DSS interrupts are not capable of waking up the CPU and the
4454 * framedone interrupt could be delayed for quite a long time. I think
4455 * the same goes for any DSS interrupts, but for some reason I have not
4456 * seen the problem anywhere else than here.
4457 */
4458 dispc_disable_sidle();
4459
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304460 dsi_perf_mark_start(dsidev);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004461
Archit Taneja49dbf582011-05-16 15:17:07 +05304462 r = schedule_delayed_work(&dsi->framedone_timeout_work,
4463 msecs_to_jiffies(250));
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03004464 BUG_ON(r == 0);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004465
Archit Taneja55cd63a2012-08-09 15:41:13 +05304466 dss_mgr_set_timings(dssdev->manager, &dsi->timings);
4467
Tomi Valkeinen1cb00172011-11-18 11:14:01 +02004468 dss_mgr_start_update(dssdev->manager);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004469
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304470 if (dsi->te_enabled) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004471 /* disable LP_RX_TO, so that we can receive TE. Time to wait
4472 * for TE is longer than the timer allows */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304473 REG_FLD_MOD(dsidev, DSI_TIMING2, 0, 15, 15); /* LP_RX_TO */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004474
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304475 dsi_vc_send_bta(dsidev, channel);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004476
4477#ifdef DSI_CATCH_MISSING_TE
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304478 mod_timer(&dsi->te_timer, jiffies + msecs_to_jiffies(250));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004479#endif
4480 }
4481}
4482
4483#ifdef DSI_CATCH_MISSING_TE
4484static void dsi_te_timeout(unsigned long arg)
4485{
4486 DSSERR("TE not received for 250ms!\n");
4487}
4488#endif
4489
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304490static void dsi_handle_framedone(struct platform_device *dsidev, int error)
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004491{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304492 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4493
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004494 /* SIDLEMODE back to smart-idle */
4495 dispc_enable_sidle();
4496
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304497 if (dsi->te_enabled) {
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004498 /* enable LP_RX_TO again after the TE */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304499 REG_FLD_MOD(dsidev, DSI_TIMING2, 1, 15, 15); /* LP_RX_TO */
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004500 }
4501
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304502 dsi->framedone_callback(error, dsi->framedone_data);
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004503
4504 if (!error)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304505 dsi_perf_show(dsidev, "DISPC");
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004506}
4507
4508static void dsi_framedone_timeout_work_callback(struct work_struct *work)
4509{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304510 struct dsi_data *dsi = container_of(work, struct dsi_data,
4511 framedone_timeout_work.work);
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03004512 /* XXX While extremely unlikely, we could get FRAMEDONE interrupt after
4513 * 250ms which would conflict with this timeout work. What should be
4514 * done is first cancel the transfer on the HW, and then cancel the
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004515 * possibly scheduled framedone work. However, cancelling the transfer
4516 * on the HW is buggy, and would probably require resetting the whole
4517 * DSI */
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03004518
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004519 DSSERR("Framedone not received for 250ms!\n");
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004520
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304521 dsi_handle_framedone(dsi->pdev, -ETIMEDOUT);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004522}
4523
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004524static void dsi_framedone_irq_callback(void *data, u32 mask)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004525{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304526 struct omap_dss_device *dssdev = (struct omap_dss_device *) data;
4527 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304528 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4529
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004530 /* Note: We get FRAMEDONE when DISPC has finished sending pixels and
4531 * turns itself off. However, DSI still has the pixels in its buffers,
4532 * and is sending the data.
4533 */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004534
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304535 __cancel_delayed_work(&dsi->framedone_timeout_work);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004536
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304537 dsi_handle_framedone(dsidev, 0);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004538}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004539
Tomi Valkeinen5476e742011-11-03 16:34:20 +02004540int omap_dsi_update(struct omap_dss_device *dssdev, int channel,
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004541 void (*callback)(int, void *), void *data)
4542{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304543 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304544 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen5476e742011-11-03 16:34:20 +02004545 u16 dw, dh;
4546
4547 dsi_perf_mark_setup(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304548
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304549 dsi->update_channel = channel;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004550
Tomi Valkeinen4a9e78a2011-08-15 11:22:21 +03004551 dsi->framedone_callback = callback;
4552 dsi->framedone_data = data;
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004553
Archit Tanejae3525742012-08-09 15:23:43 +05304554 dw = dsi->timings.x_res;
4555 dh = dsi->timings.y_res;
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004556
Tomi Valkeinen5476e742011-11-03 16:34:20 +02004557#ifdef DEBUG
4558 dsi->update_bytes = dw * dh *
Archit Taneja02c39602012-08-10 15:01:33 +05304559 dsi_get_pixel_size(dsi->pix_fmt) / 8;
Tomi Valkeinen5476e742011-11-03 16:34:20 +02004560#endif
Archit Taneja55cd63a2012-08-09 15:41:13 +05304561 dsi_update_screen_dispc(dssdev);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004562
4563 return 0;
4564}
4565EXPORT_SYMBOL(omap_dsi_update);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004566
4567/* Display funcs */
4568
Archit Taneja7d2572f2012-06-29 14:31:07 +05304569static int dsi_configure_dispc_clocks(struct omap_dss_device *dssdev)
4570{
4571 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4572 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4573 struct dispc_clock_info dispc_cinfo;
4574 int r;
4575 unsigned long long fck;
4576
4577 fck = dsi_get_pll_hsdiv_dispc_rate(dsidev);
4578
4579 dispc_cinfo.lck_div = dssdev->clocks.dispc.channel.lck_div;
4580 dispc_cinfo.pck_div = dssdev->clocks.dispc.channel.pck_div;
4581
4582 r = dispc_calc_clock_rates(fck, &dispc_cinfo);
4583 if (r) {
4584 DSSERR("Failed to calc dispc clocks\n");
4585 return r;
4586 }
4587
4588 dsi->mgr_config.clock_info = dispc_cinfo;
4589
4590 return 0;
4591}
4592
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004593static int dsi_display_init_dispc(struct omap_dss_device *dssdev)
4594{
Archit Taneja7d2572f2012-06-29 14:31:07 +05304595 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4596 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Taneja7d2572f2012-06-29 14:31:07 +05304597 int r;
4598 u32 irq = 0;
Archit Taneja5a8b5722011-05-12 17:26:29 +05304599
Archit Tanejadca2b152012-08-16 18:02:00 +05304600 if (dsi->mode == OMAP_DSS_DSI_CMD_MODE) {
Archit Tanejae67458a2012-08-13 14:17:30 +05304601 dsi->timings.hsw = 1;
4602 dsi->timings.hfp = 1;
4603 dsi->timings.hbp = 1;
4604 dsi->timings.vsw = 1;
4605 dsi->timings.vfp = 0;
4606 dsi->timings.vbp = 0;
Tomi Valkeinen5476e742011-11-03 16:34:20 +02004607
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05304608 irq = dispc_mgr_get_framedone_irq(dssdev->manager->id);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304609
4610 r = omap_dispc_register_isr(dsi_framedone_irq_callback,
4611 (void *) dssdev, irq);
4612 if (r) {
4613 DSSERR("can't get FRAMEDONE irq\n");
Archit Taneja7d2572f2012-06-29 14:31:07 +05304614 goto err;
Archit Taneja8af6ff02011-09-05 16:48:27 +05304615 }
4616
Archit Taneja7d2572f2012-06-29 14:31:07 +05304617 dsi->mgr_config.stallmode = true;
4618 dsi->mgr_config.fifohandcheck = true;
Archit Taneja8af6ff02011-09-05 16:48:27 +05304619 } else {
Archit Taneja7d2572f2012-06-29 14:31:07 +05304620 dsi->mgr_config.stallmode = false;
4621 dsi->mgr_config.fifohandcheck = false;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004622 }
4623
Archit Tanejabd5a7b12012-06-26 12:38:31 +05304624 /*
4625 * override interlace, logic level and edge related parameters in
4626 * omap_video_timings with default values
4627 */
Archit Tanejae67458a2012-08-13 14:17:30 +05304628 dsi->timings.interlace = false;
4629 dsi->timings.hsync_level = OMAPDSS_SIG_ACTIVE_HIGH;
4630 dsi->timings.vsync_level = OMAPDSS_SIG_ACTIVE_HIGH;
4631 dsi->timings.data_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE;
4632 dsi->timings.de_level = OMAPDSS_SIG_ACTIVE_HIGH;
4633 dsi->timings.sync_pclk_edge = OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES;
Archit Tanejabd5a7b12012-06-26 12:38:31 +05304634
Archit Tanejae67458a2012-08-13 14:17:30 +05304635 dss_mgr_set_timings(dssdev->manager, &dsi->timings);
Archit Tanejabd5a7b12012-06-26 12:38:31 +05304636
Archit Taneja7d2572f2012-06-29 14:31:07 +05304637 r = dsi_configure_dispc_clocks(dssdev);
4638 if (r)
4639 goto err1;
4640
4641 dsi->mgr_config.io_pad_mode = DSS_IO_PAD_MODE_BYPASS;
4642 dsi->mgr_config.video_port_width =
Archit Taneja02c39602012-08-10 15:01:33 +05304643 dsi_get_pixel_size(dsi->pix_fmt);
Archit Taneja7d2572f2012-06-29 14:31:07 +05304644 dsi->mgr_config.lcden_sig_polarity = 0;
4645
Archit Tanejaf476ae92012-06-29 14:37:03 +05304646 dss_mgr_set_lcd_config(dssdev->manager, &dsi->mgr_config);
Archit Tanejad21f43b2012-06-21 09:45:11 +05304647
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004648 return 0;
Archit Taneja7d2572f2012-06-29 14:31:07 +05304649err1:
Archit Tanejadca2b152012-08-16 18:02:00 +05304650 if (dsi->mode == OMAP_DSS_DSI_CMD_MODE)
Archit Taneja7d2572f2012-06-29 14:31:07 +05304651 omap_dispc_unregister_isr(dsi_framedone_irq_callback,
4652 (void *) dssdev, irq);
4653err:
4654 return r;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004655}
4656
4657static void dsi_display_uninit_dispc(struct omap_dss_device *dssdev)
4658{
Archit Tanejadca2b152012-08-16 18:02:00 +05304659 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4660 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4661
4662 if (dsi->mode == OMAP_DSS_DSI_CMD_MODE) {
Archit Taneja8af6ff02011-09-05 16:48:27 +05304663 u32 irq;
Archit Taneja5a8b5722011-05-12 17:26:29 +05304664
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05304665 irq = dispc_mgr_get_framedone_irq(dssdev->manager->id);
Archit Taneja5a8b5722011-05-12 17:26:29 +05304666
Archit Taneja8af6ff02011-09-05 16:48:27 +05304667 omap_dispc_unregister_isr(dsi_framedone_irq_callback,
4668 (void *) dssdev, irq);
4669 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004670}
4671
4672static int dsi_configure_dsi_clocks(struct omap_dss_device *dssdev)
4673{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304674 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004675 struct dsi_clock_info cinfo;
4676 int r;
4677
Tomi Valkeinenc6940a32011-02-22 13:36:10 +02004678 cinfo.regn = dssdev->clocks.dsi.regn;
4679 cinfo.regm = dssdev->clocks.dsi.regm;
4680 cinfo.regm_dispc = dssdev->clocks.dsi.regm_dispc;
4681 cinfo.regm_dsi = dssdev->clocks.dsi.regm_dsi;
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02004682 r = dsi_calc_clock_rates(dsidev, &cinfo);
Ville Syrjäläebf0a3f2010-04-22 22:50:05 +02004683 if (r) {
4684 DSSERR("Failed to calc dsi clocks\n");
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004685 return r;
Ville Syrjäläebf0a3f2010-04-22 22:50:05 +02004686 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004687
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304688 r = dsi_pll_set_clock_div(dsidev, &cinfo);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004689 if (r) {
4690 DSSERR("Failed to set dsi clocks\n");
4691 return r;
4692 }
4693
4694 return 0;
4695}
4696
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004697static int dsi_display_init_dsi(struct omap_dss_device *dssdev)
4698{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304699 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02004700 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004701 int r;
4702
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304703 r = dsi_pll_init(dsidev, true, true);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004704 if (r)
4705 goto err0;
4706
4707 r = dsi_configure_dsi_clocks(dssdev);
4708 if (r)
4709 goto err1;
4710
Archit Tanejae8881662011-04-12 13:52:24 +05304711 dss_select_dispc_clk_source(dssdev->clocks.dispc.dispc_fclk_src);
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02004712 dss_select_dsi_clk_source(dsi->module_id, dssdev->clocks.dsi.dsi_fclk_src);
Archit Taneja9613c022011-03-22 06:33:36 -05004713 dss_select_lcd_clk_source(dssdev->manager->id,
Archit Tanejae8881662011-04-12 13:52:24 +05304714 dssdev->clocks.dispc.channel.lcd_clk_src);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004715
4716 DSSDBG("PLL OK\n");
4717
Tomi Valkeinencc5c1852010-10-06 15:18:13 +03004718 r = dsi_cio_init(dssdev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004719 if (r)
4720 goto err2;
4721
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304722 _dsi_print_reset_status(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004723
4724 dsi_proto_timings(dssdev);
4725 dsi_set_lp_clk_divisor(dssdev);
4726
4727 if (1)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304728 _dsi_print_reset_status(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004729
4730 r = dsi_proto_config(dssdev);
4731 if (r)
4732 goto err3;
4733
4734 /* enable interface */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304735 dsi_vc_enable(dsidev, 0, 1);
4736 dsi_vc_enable(dsidev, 1, 1);
4737 dsi_vc_enable(dsidev, 2, 1);
4738 dsi_vc_enable(dsidev, 3, 1);
4739 dsi_if_enable(dsidev, 1);
4740 dsi_force_tx_stop_mode_io(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004741
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004742 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004743err3:
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03004744 dsi_cio_uninit(dssdev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004745err2:
Archit Taneja89a35e52011-04-12 13:52:23 +05304746 dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK);
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02004747 dss_select_dsi_clk_source(dsi->module_id, OMAP_DSS_CLK_SRC_FCK);
Tomi Valkeinen5e785092011-08-10 11:25:36 +03004748 dss_select_lcd_clk_source(dssdev->manager->id, OMAP_DSS_CLK_SRC_FCK);
4749
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004750err1:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304751 dsi_pll_uninit(dsidev, true);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004752err0:
4753 return r;
4754}
4755
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +03004756static void dsi_display_uninit_dsi(struct omap_dss_device *dssdev,
Tomi Valkeinen22d6d672010-10-11 11:33:30 +03004757 bool disconnect_lanes, bool enter_ulps)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004758{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304759 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304760 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304761
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304762 if (enter_ulps && !dsi->ulps_enabled)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304763 dsi_enter_ulps(dsidev);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03004764
Ville Syrjäläd7370102010-04-22 22:50:09 +02004765 /* disable interface */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304766 dsi_if_enable(dsidev, 0);
4767 dsi_vc_enable(dsidev, 0, 0);
4768 dsi_vc_enable(dsidev, 1, 0);
4769 dsi_vc_enable(dsidev, 2, 0);
4770 dsi_vc_enable(dsidev, 3, 0);
Ville Syrjäläd7370102010-04-22 22:50:09 +02004771
Archit Taneja89a35e52011-04-12 13:52:23 +05304772 dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK);
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02004773 dss_select_dsi_clk_source(dsi->module_id, OMAP_DSS_CLK_SRC_FCK);
Tomi Valkeinen5e785092011-08-10 11:25:36 +03004774 dss_select_lcd_clk_source(dssdev->manager->id, OMAP_DSS_CLK_SRC_FCK);
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03004775 dsi_cio_uninit(dssdev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304776 dsi_pll_uninit(dsidev, disconnect_lanes);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004777}
4778
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02004779int omapdss_dsi_display_enable(struct omap_dss_device *dssdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004780{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304781 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304782 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004783 int r = 0;
4784
4785 DSSDBG("dsi_display_enable\n");
4786
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304787 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02004788
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304789 mutex_lock(&dsi->lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004790
Tomi Valkeinen05e1d602011-06-23 16:38:21 +03004791 if (dssdev->manager == NULL) {
4792 DSSERR("failed to enable display: no manager\n");
4793 r = -ENODEV;
4794 goto err_start_dev;
4795 }
4796
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004797 r = omap_dss_start_device(dssdev);
4798 if (r) {
4799 DSSERR("failed to start device\n");
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004800 goto err_start_dev;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004801 }
4802
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004803 r = dsi_runtime_get(dsidev);
4804 if (r)
4805 goto err_get_dsi;
4806
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304807 dsi_enable_pll_clock(dsidev, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004808
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004809 _dsi_initialize_irq(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004810
4811 r = dsi_display_init_dispc(dssdev);
4812 if (r)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004813 goto err_init_dispc;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004814
4815 r = dsi_display_init_dsi(dssdev);
4816 if (r)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004817 goto err_init_dsi;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004818
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304819 mutex_unlock(&dsi->lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004820
4821 return 0;
4822
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004823err_init_dsi:
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02004824 dsi_display_uninit_dispc(dssdev);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004825err_init_dispc:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304826 dsi_enable_pll_clock(dsidev, 0);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004827 dsi_runtime_put(dsidev);
4828err_get_dsi:
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004829 omap_dss_stop_device(dssdev);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004830err_start_dev:
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304831 mutex_unlock(&dsi->lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004832 DSSDBG("dsi_display_enable FAILED\n");
4833 return r;
4834}
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02004835EXPORT_SYMBOL(omapdss_dsi_display_enable);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004836
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +03004837void omapdss_dsi_display_disable(struct omap_dss_device *dssdev,
Tomi Valkeinen22d6d672010-10-11 11:33:30 +03004838 bool disconnect_lanes, bool enter_ulps)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004839{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304840 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304841 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304842
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004843 DSSDBG("dsi_display_disable\n");
4844
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304845 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02004846
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304847 mutex_lock(&dsi->lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004848
Tomi Valkeinen15ffa1d2011-06-16 14:34:06 +03004849 dsi_sync_vc(dsidev, 0);
4850 dsi_sync_vc(dsidev, 1);
4851 dsi_sync_vc(dsidev, 2);
4852 dsi_sync_vc(dsidev, 3);
4853
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004854 dsi_display_uninit_dispc(dssdev);
4855
Tomi Valkeinen22d6d672010-10-11 11:33:30 +03004856 dsi_display_uninit_dsi(dssdev, disconnect_lanes, enter_ulps);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004857
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004858 dsi_runtime_put(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304859 dsi_enable_pll_clock(dsidev, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004860
4861 omap_dss_stop_device(dssdev);
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02004862
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304863 mutex_unlock(&dsi->lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004864}
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02004865EXPORT_SYMBOL(omapdss_dsi_display_disable);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004866
Tomi Valkeinen225b6502010-01-11 15:11:01 +02004867int omapdss_dsi_enable_te(struct omap_dss_device *dssdev, bool enable)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004868{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304869 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4870 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4871
4872 dsi->te_enabled = enable;
Tomi Valkeinen225b6502010-01-11 15:11:01 +02004873 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004874}
Tomi Valkeinen225b6502010-01-11 15:11:01 +02004875EXPORT_SYMBOL(omapdss_dsi_enable_te);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004876
Archit Tanejae67458a2012-08-13 14:17:30 +05304877void omapdss_dsi_set_timings(struct omap_dss_device *dssdev,
4878 struct omap_video_timings *timings)
4879{
4880 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4881 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4882
4883 mutex_lock(&dsi->lock);
4884
4885 dsi->timings = *timings;
4886
4887 mutex_unlock(&dsi->lock);
4888}
4889EXPORT_SYMBOL(omapdss_dsi_set_timings);
4890
Archit Tanejae3525742012-08-09 15:23:43 +05304891void omapdss_dsi_set_size(struct omap_dss_device *dssdev, u16 w, u16 h)
4892{
4893 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4894 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4895
4896 mutex_lock(&dsi->lock);
4897
4898 dsi->timings.x_res = w;
4899 dsi->timings.y_res = h;
4900
4901 mutex_unlock(&dsi->lock);
4902}
4903EXPORT_SYMBOL(omapdss_dsi_set_size);
4904
Archit Taneja02c39602012-08-10 15:01:33 +05304905void omapdss_dsi_set_pixel_format(struct omap_dss_device *dssdev,
4906 enum omap_dss_dsi_pixel_format fmt)
4907{
4908 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4909 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4910
4911 mutex_lock(&dsi->lock);
4912
4913 dsi->pix_fmt = fmt;
4914
4915 mutex_unlock(&dsi->lock);
4916}
4917EXPORT_SYMBOL(omapdss_dsi_set_pixel_format);
4918
Archit Tanejadca2b152012-08-16 18:02:00 +05304919void omapdss_dsi_set_operation_mode(struct omap_dss_device *dssdev,
4920 enum omap_dss_dsi_mode mode)
4921{
4922 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4923 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4924
4925 mutex_lock(&dsi->lock);
4926
4927 dsi->mode = mode;
4928
4929 mutex_unlock(&dsi->lock);
4930}
4931EXPORT_SYMBOL(omapdss_dsi_set_operation_mode);
4932
Archit Taneja0b3ffe32012-08-13 22:13:39 +05304933void omapdss_dsi_set_videomode_timings(struct omap_dss_device *dssdev,
4934 struct omap_dss_dsi_videomode_timings *timings)
4935{
4936 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4937 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4938
4939 mutex_lock(&dsi->lock);
4940
4941 dsi->vm_timings = *timings;
4942
4943 mutex_unlock(&dsi->lock);
4944}
4945EXPORT_SYMBOL(omapdss_dsi_set_videomode_timings);
4946
Tomi Valkeinen9d8232a2012-03-01 16:58:39 +02004947static int __init dsi_init_display(struct omap_dss_device *dssdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004948{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304949 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4950 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4951
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004952 DSSDBG("DSI init\n");
4953
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304954 if (dsi->vdds_dsi_reg == NULL) {
Tomi Valkeinen5f42f2c2011-02-22 15:53:46 +02004955 struct regulator *vdds_dsi;
4956
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304957 vdds_dsi = regulator_get(&dsi->pdev->dev, "vdds_dsi");
Tomi Valkeinen5f42f2c2011-02-22 15:53:46 +02004958
4959 if (IS_ERR(vdds_dsi)) {
4960 DSSERR("can't get VDDS_DSI regulator\n");
4961 return PTR_ERR(vdds_dsi);
4962 }
4963
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304964 dsi->vdds_dsi_reg = vdds_dsi;
Tomi Valkeinen5f42f2c2011-02-22 15:53:46 +02004965 }
4966
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004967 return 0;
4968}
4969
Archit Taneja5ee3c142011-03-02 12:35:53 +05304970int omap_dsi_request_vc(struct omap_dss_device *dssdev, int *channel)
4971{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304972 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4973 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Taneja5ee3c142011-03-02 12:35:53 +05304974 int i;
4975
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304976 for (i = 0; i < ARRAY_SIZE(dsi->vc); i++) {
4977 if (!dsi->vc[i].dssdev) {
4978 dsi->vc[i].dssdev = dssdev;
Archit Taneja5ee3c142011-03-02 12:35:53 +05304979 *channel = i;
4980 return 0;
4981 }
4982 }
4983
4984 DSSERR("cannot get VC for display %s", dssdev->name);
4985 return -ENOSPC;
4986}
4987EXPORT_SYMBOL(omap_dsi_request_vc);
4988
4989int omap_dsi_set_vc_id(struct omap_dss_device *dssdev, int channel, int vc_id)
4990{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304991 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4992 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4993
Archit Taneja5ee3c142011-03-02 12:35:53 +05304994 if (vc_id < 0 || vc_id > 3) {
4995 DSSERR("VC ID out of range\n");
4996 return -EINVAL;
4997 }
4998
4999 if (channel < 0 || channel > 3) {
5000 DSSERR("Virtual Channel out of range\n");
5001 return -EINVAL;
5002 }
5003
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305004 if (dsi->vc[channel].dssdev != dssdev) {
Archit Taneja5ee3c142011-03-02 12:35:53 +05305005 DSSERR("Virtual Channel not allocated to display %s\n",
5006 dssdev->name);
5007 return -EINVAL;
5008 }
5009
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305010 dsi->vc[channel].vc_id = vc_id;
Archit Taneja5ee3c142011-03-02 12:35:53 +05305011
5012 return 0;
5013}
5014EXPORT_SYMBOL(omap_dsi_set_vc_id);
5015
5016void omap_dsi_release_vc(struct omap_dss_device *dssdev, int channel)
5017{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305018 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
5019 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
5020
Archit Taneja5ee3c142011-03-02 12:35:53 +05305021 if ((channel >= 0 && channel <= 3) &&
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305022 dsi->vc[channel].dssdev == dssdev) {
5023 dsi->vc[channel].dssdev = NULL;
5024 dsi->vc[channel].vc_id = 0;
Archit Taneja5ee3c142011-03-02 12:35:53 +05305025 }
5026}
5027EXPORT_SYMBOL(omap_dsi_release_vc);
5028
Archit Tanejaa72b64b2011-05-12 17:26:26 +05305029void dsi_wait_pll_hsdiv_dispc_active(struct platform_device *dsidev)
Tomi Valkeinene406f902010-06-09 15:28:12 +03005030{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05305031 if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 7, 1) != 1)
Archit Taneja067a57e2011-03-02 11:57:25 +05305032 DSSERR("%s (%s) not active\n",
Archit Taneja89a35e52011-04-12 13:52:23 +05305033 dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
5034 dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC));
Tomi Valkeinene406f902010-06-09 15:28:12 +03005035}
5036
Archit Tanejaa72b64b2011-05-12 17:26:26 +05305037void dsi_wait_pll_hsdiv_dsi_active(struct platform_device *dsidev)
Tomi Valkeinene406f902010-06-09 15:28:12 +03005038{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05305039 if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 8, 1) != 1)
Archit Taneja067a57e2011-03-02 11:57:25 +05305040 DSSERR("%s (%s) not active\n",
Archit Taneja89a35e52011-04-12 13:52:23 +05305041 dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
5042 dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI));
Tomi Valkeinene406f902010-06-09 15:28:12 +03005043}
5044
Archit Tanejaa72b64b2011-05-12 17:26:26 +05305045static void dsi_calc_clock_param_ranges(struct platform_device *dsidev)
Taneja, Archit49641112011-03-14 23:28:23 -05005046{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305047 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
5048
5049 dsi->regn_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGN);
5050 dsi->regm_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM);
5051 dsi->regm_dispc_max =
5052 dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DISPC);
5053 dsi->regm_dsi_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DSI);
5054 dsi->fint_min = dss_feat_get_param_min(FEAT_PARAM_DSIPLL_FINT);
5055 dsi->fint_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_FINT);
5056 dsi->lpdiv_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_LPDIV);
Taneja, Archit49641112011-03-14 23:28:23 -05005057}
5058
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005059static int dsi_get_clocks(struct platform_device *dsidev)
5060{
5061 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
5062 struct clk *clk;
5063
5064 clk = clk_get(&dsidev->dev, "fck");
5065 if (IS_ERR(clk)) {
5066 DSSERR("can't get fck\n");
5067 return PTR_ERR(clk);
5068 }
5069
5070 dsi->dss_clk = clk;
5071
Tomi Valkeinenbfe4f8d2011-08-04 11:22:54 +03005072 clk = clk_get(&dsidev->dev, "sys_clk");
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005073 if (IS_ERR(clk)) {
5074 DSSERR("can't get sys_clk\n");
5075 clk_put(dsi->dss_clk);
5076 dsi->dss_clk = NULL;
5077 return PTR_ERR(clk);
5078 }
5079
5080 dsi->sys_clk = clk;
5081
5082 return 0;
5083}
5084
5085static void dsi_put_clocks(struct platform_device *dsidev)
5086{
5087 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
5088
5089 if (dsi->dss_clk)
5090 clk_put(dsi->dss_clk);
5091 if (dsi->sys_clk)
5092 clk_put(dsi->sys_clk);
5093}
5094
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +03005095static void __init dsi_probe_pdata(struct platform_device *dsidev)
5096{
5097 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
5098 struct omap_dss_board_info *pdata = dsidev->dev.platform_data;
5099 int i, r;
5100
5101 for (i = 0; i < pdata->num_devices; ++i) {
5102 struct omap_dss_device *dssdev = pdata->devices[i];
5103
5104 if (dssdev->type != OMAP_DISPLAY_TYPE_DSI)
5105 continue;
5106
5107 if (dssdev->phy.dsi.module != dsi->module_id)
5108 continue;
5109
5110 r = dsi_init_display(dssdev);
5111 if (r) {
5112 DSSERR("device %s init failed: %d\n", dssdev->name, r);
5113 continue;
5114 }
5115
5116 r = omap_dss_register_device(dssdev, &dsidev->dev, i);
5117 if (r)
5118 DSSERR("device %s register failed: %d\n",
5119 dssdev->name, r);
5120 }
5121}
5122
Tomi Valkeinenb98482e2011-05-16 13:52:51 +03005123/* DSI1 HW IP initialisation */
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02005124static int __init omap_dsihw_probe(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005125{
5126 u32 rev;
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02005127 int r, i;
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00005128 struct resource *dsi_mem;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305129 struct dsi_data *dsi;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005130
Julia Lawall6e2a14d2012-01-24 14:00:45 +01005131 dsi = devm_kzalloc(&dsidev->dev, sizeof(*dsi), GFP_KERNEL);
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005132 if (!dsi)
5133 return -ENOMEM;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305134
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02005135 dsi->module_id = dsidev->id;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305136 dsi->pdev = dsidev;
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02005137 dsi_pdev_map[dsi->module_id] = dsidev;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305138 dev_set_drvdata(&dsidev->dev, dsi);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05305139
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305140 spin_lock_init(&dsi->irq_lock);
5141 spin_lock_init(&dsi->errors_lock);
5142 dsi->errors = 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005143
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02005144#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305145 spin_lock_init(&dsi->irq_stats_lock);
5146 dsi->irq_stats.last_reset = jiffies;
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02005147#endif
5148
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305149 mutex_init(&dsi->lock);
5150 sema_init(&dsi->bus_lock, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005151
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305152 INIT_DELAYED_WORK_DEFERRABLE(&dsi->framedone_timeout_work,
5153 dsi_framedone_timeout_work_callback);
5154
5155#ifdef DSI_CATCH_MISSING_TE
5156 init_timer(&dsi->te_timer);
5157 dsi->te_timer.function = dsi_te_timeout;
5158 dsi->te_timer.data = 0;
5159#endif
5160 dsi_mem = platform_get_resource(dsi->pdev, IORESOURCE_MEM, 0);
5161 if (!dsi_mem) {
5162 DSSERR("can't get IORESOURCE_MEM DSI\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005163 return -EINVAL;
archit tanejaaffe3602011-02-23 08:41:03 +00005164 }
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005165
Julia Lawall6e2a14d2012-01-24 14:00:45 +01005166 dsi->base = devm_ioremap(&dsidev->dev, dsi_mem->start,
5167 resource_size(dsi_mem));
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305168 if (!dsi->base) {
5169 DSSERR("can't ioremap DSI\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005170 return -ENOMEM;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305171 }
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005172
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305173 dsi->irq = platform_get_irq(dsi->pdev, 0);
5174 if (dsi->irq < 0) {
5175 DSSERR("platform_get_irq failed\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005176 return -ENODEV;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305177 }
archit tanejaaffe3602011-02-23 08:41:03 +00005178
Julia Lawall6e2a14d2012-01-24 14:00:45 +01005179 r = devm_request_irq(&dsidev->dev, dsi->irq, omap_dsi_irq_handler,
5180 IRQF_SHARED, dev_name(&dsidev->dev), dsi->pdev);
archit tanejaaffe3602011-02-23 08:41:03 +00005181 if (r < 0) {
5182 DSSERR("request_irq failed\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005183 return r;
archit tanejaaffe3602011-02-23 08:41:03 +00005184 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005185
Archit Taneja5ee3c142011-03-02 12:35:53 +05305186 /* DSI VCs initialization */
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305187 for (i = 0; i < ARRAY_SIZE(dsi->vc); i++) {
Archit Tanejad6049142011-08-22 11:58:08 +05305188 dsi->vc[i].source = DSI_VC_SOURCE_L4;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305189 dsi->vc[i].dssdev = NULL;
5190 dsi->vc[i].vc_id = 0;
Archit Taneja5ee3c142011-03-02 12:35:53 +05305191 }
5192
Archit Tanejaa72b64b2011-05-12 17:26:26 +05305193 dsi_calc_clock_param_ranges(dsidev);
Taneja, Archit49641112011-03-14 23:28:23 -05005194
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005195 r = dsi_get_clocks(dsidev);
5196 if (r)
5197 return r;
5198
5199 pm_runtime_enable(&dsidev->dev);
5200
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005201 r = dsi_runtime_get(dsidev);
5202 if (r)
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005203 goto err_runtime_get;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005204
Archit Tanejaa72b64b2011-05-12 17:26:26 +05305205 rev = dsi_read_reg(dsidev, DSI_REVISION);
5206 dev_dbg(&dsidev->dev, "OMAP DSI rev %d.%d\n",
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005207 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
5208
Tomi Valkeinend9820852011-10-12 15:05:59 +03005209 /* DSI on OMAP3 doesn't have register DSI_GNQ, set number
5210 * of data to 3 by default */
5211 if (dss_has_feature(FEAT_DSI_GNQ))
5212 /* NB_DATA_LANES */
5213 dsi->num_lanes_supported = 1 + REG_GET(dsidev, DSI_GNQ, 11, 9);
5214 else
5215 dsi->num_lanes_supported = 3;
Archit Taneja75d72472011-05-16 15:17:08 +05305216
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +03005217 dsi_probe_pdata(dsidev);
Tomi Valkeinen35deca32012-03-01 15:45:53 +02005218
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005219 dsi_runtime_put(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005220
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02005221 if (dsi->module_id == 0)
Tomi Valkeinene40402c2012-03-02 18:01:07 +02005222 dss_debugfs_create_file("dsi1_regs", dsi1_dump_regs);
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02005223 else if (dsi->module_id == 1)
Tomi Valkeinene40402c2012-03-02 18:01:07 +02005224 dss_debugfs_create_file("dsi2_regs", dsi2_dump_regs);
5225
5226#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02005227 if (dsi->module_id == 0)
Tomi Valkeinene40402c2012-03-02 18:01:07 +02005228 dss_debugfs_create_file("dsi1_irqs", dsi1_dump_irqs);
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02005229 else if (dsi->module_id == 1)
Tomi Valkeinene40402c2012-03-02 18:01:07 +02005230 dss_debugfs_create_file("dsi2_irqs", dsi2_dump_irqs);
5231#endif
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005232 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005233
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005234err_runtime_get:
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005235 pm_runtime_disable(&dsidev->dev);
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005236 dsi_put_clocks(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005237 return r;
5238}
5239
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02005240static int __exit omap_dsihw_remove(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005241{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305242 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
5243
Tomi Valkeinenb98482e2011-05-16 13:52:51 +03005244 WARN_ON(dsi->scp_clk_refcount > 0);
5245
Tomi Valkeinen35deca32012-03-01 15:45:53 +02005246 omap_dss_unregister_child_devices(&dsidev->dev);
5247
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005248 pm_runtime_disable(&dsidev->dev);
5249
5250 dsi_put_clocks(dsidev);
5251
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305252 if (dsi->vdds_dsi_reg != NULL) {
5253 if (dsi->vdds_dsi_enabled) {
5254 regulator_disable(dsi->vdds_dsi_reg);
5255 dsi->vdds_dsi_enabled = false;
Tomi Valkeinen88257b22010-12-20 16:26:22 +02005256 }
5257
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305258 regulator_put(dsi->vdds_dsi_reg);
5259 dsi->vdds_dsi_reg = NULL;
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005260 }
5261
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005262 return 0;
5263}
5264
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005265static int dsi_runtime_suspend(struct device *dev)
5266{
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005267 dispc_runtime_put();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005268
5269 return 0;
5270}
5271
5272static int dsi_runtime_resume(struct device *dev)
5273{
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005274 int r;
5275
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005276 r = dispc_runtime_get();
5277 if (r)
Tomi Valkeinen852f0832012-02-17 17:58:04 +02005278 return r;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005279
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005280 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005281}
5282
5283static const struct dev_pm_ops dsi_pm_ops = {
5284 .runtime_suspend = dsi_runtime_suspend,
5285 .runtime_resume = dsi_runtime_resume,
5286};
5287
Tomi Valkeinen7c68dd92011-08-03 14:00:57 +03005288static struct platform_driver omap_dsihw_driver = {
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02005289 .remove = __exit_p(omap_dsihw_remove),
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005290 .driver = {
Tomi Valkeinen7c68dd92011-08-03 14:00:57 +03005291 .name = "omapdss_dsi",
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005292 .owner = THIS_MODULE,
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005293 .pm = &dsi_pm_ops,
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005294 },
5295};
5296
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02005297int __init dsi_init_platform_driver(void)
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005298{
Tomi Valkeinen61055d42012-03-07 12:53:38 +02005299 return platform_driver_probe(&omap_dsihw_driver, omap_dsihw_probe);
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005300}
5301
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02005302void __exit dsi_uninit_platform_driver(void)
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005303{
Tomi Valkeinen04c742c2012-02-23 15:32:37 +02005304 platform_driver_unregister(&omap_dsihw_driver);
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005305}