blob: a16c8b229ea717544d3057a8c21cef8f5f877f1c [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 Valkeinenc94dfe052011-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 */
Tomi Valkeinen6d446102012-08-22 16:00:40 +03001693 if (dss_has_feature(FEAT_DSI_PLL_REFSEL))
1694 l = FLD_MOD(l, 3, 22, 21); /* REF_SYSCLK = sysclk */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301695 dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION2, l);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001696
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301697 REG_FLD_MOD(dsidev, DSI_PLL_GO, 1, 0, 0); /* DSI_PLL_GO */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001698
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301699 if (wait_for_bit_change(dsidev, DSI_PLL_GO, 0, 0) != 0) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001700 DSSERR("dsi pll go bit not going down.\n");
1701 r = -EIO;
1702 goto err;
1703 }
1704
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301705 if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 1, 1) != 1) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001706 DSSERR("cannot lock PLL\n");
1707 r = -EIO;
1708 goto err;
1709 }
1710
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301711 dsi->pll_locked = 1;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001712
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301713 l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION2);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001714 l = FLD_MOD(l, 0, 0, 0); /* DSI_PLL_IDLE */
1715 l = FLD_MOD(l, 0, 5, 5); /* DSI_PLL_PLLLPMODE */
1716 l = FLD_MOD(l, 0, 6, 6); /* DSI_PLL_LOWCURRSTBY */
1717 l = FLD_MOD(l, 0, 7, 7); /* DSI_PLL_TIGHTPHASELOCK */
1718 l = FLD_MOD(l, 0, 8, 8); /* DSI_PLL_DRIFTGUARDEN */
1719 l = FLD_MOD(l, 0, 10, 9); /* DSI_PLL_LOCKSEL */
1720 l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */
1721 l = FLD_MOD(l, 1, 14, 14); /* DSIPHY_CLKINEN */
1722 l = FLD_MOD(l, 0, 15, 15); /* DSI_BYPASSEN */
1723 l = FLD_MOD(l, 1, 16, 16); /* DSS_CLOCK_EN */
1724 l = FLD_MOD(l, 0, 17, 17); /* DSS_CLOCK_PWDN */
1725 l = FLD_MOD(l, 1, 18, 18); /* DSI_PROTO_CLOCK_EN */
1726 l = FLD_MOD(l, 0, 19, 19); /* DSI_PROTO_CLOCK_PWDN */
1727 l = FLD_MOD(l, 0, 20, 20); /* DSI_HSDIVBYPASS */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301728 dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION2, l);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001729
1730 DSSDBG("PLL config done\n");
1731err:
1732 return r;
1733}
1734
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301735int dsi_pll_init(struct platform_device *dsidev, bool enable_hsclk,
1736 bool enable_hsdiv)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001737{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301738 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001739 int r = 0;
1740 enum dsi_pll_power_state pwstate;
1741
1742 DSSDBG("PLL init\n");
1743
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301744 if (dsi->vdds_dsi_reg == NULL) {
Tomi Valkeinenf2988ab2011-03-02 10:06:48 +02001745 struct regulator *vdds_dsi;
1746
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301747 vdds_dsi = regulator_get(&dsi->pdev->dev, "vdds_dsi");
Tomi Valkeinenf2988ab2011-03-02 10:06:48 +02001748
1749 if (IS_ERR(vdds_dsi)) {
1750 DSSERR("can't get VDDS_DSI regulator\n");
1751 return PTR_ERR(vdds_dsi);
1752 }
1753
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301754 dsi->vdds_dsi_reg = vdds_dsi;
Tomi Valkeinenf2988ab2011-03-02 10:06:48 +02001755 }
Tomi Valkeinenf2988ab2011-03-02 10:06:48 +02001756
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301757 dsi_enable_pll_clock(dsidev, 1);
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +03001758 /*
1759 * Note: SCP CLK is not required on OMAP3, but it is required on OMAP4.
1760 */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301761 dsi_enable_scp_clk(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001762
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301763 if (!dsi->vdds_dsi_enabled) {
1764 r = regulator_enable(dsi->vdds_dsi_reg);
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +03001765 if (r)
1766 goto err0;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301767 dsi->vdds_dsi_enabled = true;
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +03001768 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001769
1770 /* XXX PLL does not come out of reset without this... */
1771 dispc_pck_free_enable(1);
1772
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301773 if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 0, 1) != 1) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001774 DSSERR("PLL not coming out of reset.\n");
1775 r = -ENODEV;
Ville Syrjälä481dfa02010-04-22 22:50:04 +02001776 dispc_pck_free_enable(0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001777 goto err1;
1778 }
1779
1780 /* XXX ... but if left on, we get problems when planes do not
1781 * fill the whole display. No idea about this */
1782 dispc_pck_free_enable(0);
1783
1784 if (enable_hsclk && enable_hsdiv)
1785 pwstate = DSI_PLL_POWER_ON_ALL;
1786 else if (enable_hsclk)
1787 pwstate = DSI_PLL_POWER_ON_HSCLK;
1788 else if (enable_hsdiv)
1789 pwstate = DSI_PLL_POWER_ON_DIV;
1790 else
1791 pwstate = DSI_PLL_POWER_OFF;
1792
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301793 r = dsi_pll_power(dsidev, pwstate);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001794
1795 if (r)
1796 goto err1;
1797
1798 DSSDBG("PLL init done\n");
1799
1800 return 0;
1801err1:
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301802 if (dsi->vdds_dsi_enabled) {
1803 regulator_disable(dsi->vdds_dsi_reg);
1804 dsi->vdds_dsi_enabled = false;
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +03001805 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001806err0:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301807 dsi_disable_scp_clk(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301808 dsi_enable_pll_clock(dsidev, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001809 return r;
1810}
1811
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301812void dsi_pll_uninit(struct platform_device *dsidev, bool disconnect_lanes)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001813{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301814 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1815
1816 dsi->pll_locked = 0;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301817 dsi_pll_power(dsidev, DSI_PLL_POWER_OFF);
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +03001818 if (disconnect_lanes) {
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301819 WARN_ON(!dsi->vdds_dsi_enabled);
1820 regulator_disable(dsi->vdds_dsi_reg);
1821 dsi->vdds_dsi_enabled = false;
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +03001822 }
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +03001823
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301824 dsi_disable_scp_clk(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301825 dsi_enable_pll_clock(dsidev, 0);
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +03001826
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001827 DSSDBG("PLL uninit done\n");
1828}
1829
Archit Taneja5a8b5722011-05-12 17:26:29 +05301830static void dsi_dump_dsidev_clocks(struct platform_device *dsidev,
1831 struct seq_file *s)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001832{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301833 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1834 struct dsi_clock_info *cinfo = &dsi->current_cinfo;
Archit Taneja89a35e52011-04-12 13:52:23 +05301835 enum omap_dss_clk_source dispc_clk_src, dsi_clk_src;
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02001836 int dsi_module = dsi->module_id;
Archit Taneja067a57e2011-03-02 11:57:25 +05301837
1838 dispc_clk_src = dss_get_dispc_clk_source();
Archit Taneja5a8b5722011-05-12 17:26:29 +05301839 dsi_clk_src = dss_get_dsi_clk_source(dsi_module);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001840
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001841 if (dsi_runtime_get(dsidev))
1842 return;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001843
Archit Taneja5a8b5722011-05-12 17:26:29 +05301844 seq_printf(s, "- DSI%d PLL -\n", dsi_module + 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001845
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02001846 seq_printf(s, "dsi pll clkin\t%lu\n", cinfo->clkin);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001847
1848 seq_printf(s, "Fint\t\t%-16luregn %u\n", cinfo->fint, cinfo->regn);
1849
1850 seq_printf(s, "CLKIN4DDR\t%-16luregm %u\n",
1851 cinfo->clkin4ddr, cinfo->regm);
1852
Archit Taneja84309f12011-12-12 11:47:41 +05301853 seq_printf(s, "DSI_PLL_HSDIV_DISPC (%s)\t%-16luregm_dispc %u\t(%s)\n",
1854 dss_feat_get_clk_source_name(dsi_module == 0 ?
1855 OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC :
1856 OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC),
Archit Taneja1bb47832011-02-24 14:17:30 +05301857 cinfo->dsi_pll_hsdiv_dispc_clk,
1858 cinfo->regm_dispc,
Archit Taneja89a35e52011-04-12 13:52:23 +05301859 dispc_clk_src == OMAP_DSS_CLK_SRC_FCK ?
Tomi Valkeinen63cf28a2010-02-23 17:40:00 +02001860 "off" : "on");
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001861
Archit Taneja84309f12011-12-12 11:47:41 +05301862 seq_printf(s, "DSI_PLL_HSDIV_DSI (%s)\t%-16luregm_dsi %u\t(%s)\n",
1863 dss_feat_get_clk_source_name(dsi_module == 0 ?
1864 OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI :
1865 OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DSI),
Archit Taneja1bb47832011-02-24 14:17:30 +05301866 cinfo->dsi_pll_hsdiv_dsi_clk,
1867 cinfo->regm_dsi,
Archit Taneja89a35e52011-04-12 13:52:23 +05301868 dsi_clk_src == OMAP_DSS_CLK_SRC_FCK ?
Tomi Valkeinen63cf28a2010-02-23 17:40:00 +02001869 "off" : "on");
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001870
Archit Taneja5a8b5722011-05-12 17:26:29 +05301871 seq_printf(s, "- DSI%d -\n", dsi_module + 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001872
Archit Taneja067a57e2011-03-02 11:57:25 +05301873 seq_printf(s, "dsi fclk source = %s (%s)\n",
1874 dss_get_generic_clk_source_name(dsi_clk_src),
1875 dss_feat_get_clk_source_name(dsi_clk_src));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001876
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301877 seq_printf(s, "DSI_FCLK\t%lu\n", dsi_fclk_rate(dsidev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001878
1879 seq_printf(s, "DDR_CLK\t\t%lu\n",
1880 cinfo->clkin4ddr / 4);
1881
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301882 seq_printf(s, "TxByteClkHS\t%lu\n", dsi_get_txbyteclkhs(dsidev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001883
1884 seq_printf(s, "LP_CLK\t\t%lu\n", cinfo->lp_clk);
1885
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001886 dsi_runtime_put(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001887}
1888
Archit Taneja5a8b5722011-05-12 17:26:29 +05301889void dsi_dump_clocks(struct seq_file *s)
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001890{
Archit Taneja5a8b5722011-05-12 17:26:29 +05301891 struct platform_device *dsidev;
1892 int i;
1893
1894 for (i = 0; i < MAX_NUM_DSI; i++) {
1895 dsidev = dsi_get_dsidev_from_id(i);
1896 if (dsidev)
1897 dsi_dump_dsidev_clocks(dsidev, s);
1898 }
1899}
1900
1901#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
1902static void dsi_dump_dsidev_irqs(struct platform_device *dsidev,
1903 struct seq_file *s)
1904{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301905 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001906 unsigned long flags;
1907 struct dsi_irq_stats stats;
1908
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301909 spin_lock_irqsave(&dsi->irq_stats_lock, flags);
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001910
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301911 stats = dsi->irq_stats;
1912 memset(&dsi->irq_stats, 0, sizeof(dsi->irq_stats));
1913 dsi->irq_stats.last_reset = jiffies;
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001914
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301915 spin_unlock_irqrestore(&dsi->irq_stats_lock, flags);
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001916
1917 seq_printf(s, "period %u ms\n",
1918 jiffies_to_msecs(jiffies - stats.last_reset));
1919
1920 seq_printf(s, "irqs %d\n", stats.irq_count);
1921#define PIS(x) \
1922 seq_printf(s, "%-20s %10d\n", #x, stats.dsi_irqs[ffs(DSI_IRQ_##x)-1]);
1923
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02001924 seq_printf(s, "-- DSI%d interrupts --\n", dsi->module_id + 1);
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001925 PIS(VC0);
1926 PIS(VC1);
1927 PIS(VC2);
1928 PIS(VC3);
1929 PIS(WAKEUP);
1930 PIS(RESYNC);
1931 PIS(PLL_LOCK);
1932 PIS(PLL_UNLOCK);
1933 PIS(PLL_RECALL);
1934 PIS(COMPLEXIO_ERR);
1935 PIS(HS_TX_TIMEOUT);
1936 PIS(LP_RX_TIMEOUT);
1937 PIS(TE_TRIGGER);
1938 PIS(ACK_TRIGGER);
1939 PIS(SYNC_LOST);
1940 PIS(LDO_POWER_GOOD);
1941 PIS(TA_TIMEOUT);
1942#undef PIS
1943
1944#define PIS(x) \
1945 seq_printf(s, "%-20s %10d %10d %10d %10d\n", #x, \
1946 stats.vc_irqs[0][ffs(DSI_VC_IRQ_##x)-1], \
1947 stats.vc_irqs[1][ffs(DSI_VC_IRQ_##x)-1], \
1948 stats.vc_irqs[2][ffs(DSI_VC_IRQ_##x)-1], \
1949 stats.vc_irqs[3][ffs(DSI_VC_IRQ_##x)-1]);
1950
1951 seq_printf(s, "-- VC interrupts --\n");
1952 PIS(CS);
1953 PIS(ECC_CORR);
1954 PIS(PACKET_SENT);
1955 PIS(FIFO_TX_OVF);
1956 PIS(FIFO_RX_OVF);
1957 PIS(BTA);
1958 PIS(ECC_NO_CORR);
1959 PIS(FIFO_TX_UDF);
1960 PIS(PP_BUSY_CHANGE);
1961#undef PIS
1962
1963#define PIS(x) \
1964 seq_printf(s, "%-20s %10d\n", #x, \
1965 stats.cio_irqs[ffs(DSI_CIO_IRQ_##x)-1]);
1966
1967 seq_printf(s, "-- CIO interrupts --\n");
1968 PIS(ERRSYNCESC1);
1969 PIS(ERRSYNCESC2);
1970 PIS(ERRSYNCESC3);
1971 PIS(ERRESC1);
1972 PIS(ERRESC2);
1973 PIS(ERRESC3);
1974 PIS(ERRCONTROL1);
1975 PIS(ERRCONTROL2);
1976 PIS(ERRCONTROL3);
1977 PIS(STATEULPS1);
1978 PIS(STATEULPS2);
1979 PIS(STATEULPS3);
1980 PIS(ERRCONTENTIONLP0_1);
1981 PIS(ERRCONTENTIONLP1_1);
1982 PIS(ERRCONTENTIONLP0_2);
1983 PIS(ERRCONTENTIONLP1_2);
1984 PIS(ERRCONTENTIONLP0_3);
1985 PIS(ERRCONTENTIONLP1_3);
1986 PIS(ULPSACTIVENOT_ALL0);
1987 PIS(ULPSACTIVENOT_ALL1);
1988#undef PIS
1989}
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001990
Archit Taneja5a8b5722011-05-12 17:26:29 +05301991static void dsi1_dump_irqs(struct seq_file *s)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001992{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301993 struct platform_device *dsidev = dsi_get_dsidev_from_id(0);
1994
Archit Taneja5a8b5722011-05-12 17:26:29 +05301995 dsi_dump_dsidev_irqs(dsidev, s);
1996}
1997
1998static void dsi2_dump_irqs(struct seq_file *s)
1999{
2000 struct platform_device *dsidev = dsi_get_dsidev_from_id(1);
2001
2002 dsi_dump_dsidev_irqs(dsidev, s);
2003}
Archit Taneja5a8b5722011-05-12 17:26:29 +05302004#endif
2005
2006static void dsi_dump_dsidev_regs(struct platform_device *dsidev,
2007 struct seq_file *s)
2008{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302009#define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dsi_read_reg(dsidev, r))
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002010
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03002011 if (dsi_runtime_get(dsidev))
2012 return;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302013 dsi_enable_scp_clk(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002014
2015 DUMPREG(DSI_REVISION);
2016 DUMPREG(DSI_SYSCONFIG);
2017 DUMPREG(DSI_SYSSTATUS);
2018 DUMPREG(DSI_IRQSTATUS);
2019 DUMPREG(DSI_IRQENABLE);
2020 DUMPREG(DSI_CTRL);
2021 DUMPREG(DSI_COMPLEXIO_CFG1);
2022 DUMPREG(DSI_COMPLEXIO_IRQ_STATUS);
2023 DUMPREG(DSI_COMPLEXIO_IRQ_ENABLE);
2024 DUMPREG(DSI_CLK_CTRL);
2025 DUMPREG(DSI_TIMING1);
2026 DUMPREG(DSI_TIMING2);
2027 DUMPREG(DSI_VM_TIMING1);
2028 DUMPREG(DSI_VM_TIMING2);
2029 DUMPREG(DSI_VM_TIMING3);
2030 DUMPREG(DSI_CLK_TIMING);
2031 DUMPREG(DSI_TX_FIFO_VC_SIZE);
2032 DUMPREG(DSI_RX_FIFO_VC_SIZE);
2033 DUMPREG(DSI_COMPLEXIO_CFG2);
2034 DUMPREG(DSI_RX_FIFO_VC_FULLNESS);
2035 DUMPREG(DSI_VM_TIMING4);
2036 DUMPREG(DSI_TX_FIFO_VC_EMPTINESS);
2037 DUMPREG(DSI_VM_TIMING5);
2038 DUMPREG(DSI_VM_TIMING6);
2039 DUMPREG(DSI_VM_TIMING7);
2040 DUMPREG(DSI_STOPCLK_TIMING);
2041
2042 DUMPREG(DSI_VC_CTRL(0));
2043 DUMPREG(DSI_VC_TE(0));
2044 DUMPREG(DSI_VC_LONG_PACKET_HEADER(0));
2045 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(0));
2046 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(0));
2047 DUMPREG(DSI_VC_IRQSTATUS(0));
2048 DUMPREG(DSI_VC_IRQENABLE(0));
2049
2050 DUMPREG(DSI_VC_CTRL(1));
2051 DUMPREG(DSI_VC_TE(1));
2052 DUMPREG(DSI_VC_LONG_PACKET_HEADER(1));
2053 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(1));
2054 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(1));
2055 DUMPREG(DSI_VC_IRQSTATUS(1));
2056 DUMPREG(DSI_VC_IRQENABLE(1));
2057
2058 DUMPREG(DSI_VC_CTRL(2));
2059 DUMPREG(DSI_VC_TE(2));
2060 DUMPREG(DSI_VC_LONG_PACKET_HEADER(2));
2061 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(2));
2062 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(2));
2063 DUMPREG(DSI_VC_IRQSTATUS(2));
2064 DUMPREG(DSI_VC_IRQENABLE(2));
2065
2066 DUMPREG(DSI_VC_CTRL(3));
2067 DUMPREG(DSI_VC_TE(3));
2068 DUMPREG(DSI_VC_LONG_PACKET_HEADER(3));
2069 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(3));
2070 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(3));
2071 DUMPREG(DSI_VC_IRQSTATUS(3));
2072 DUMPREG(DSI_VC_IRQENABLE(3));
2073
2074 DUMPREG(DSI_DSIPHY_CFG0);
2075 DUMPREG(DSI_DSIPHY_CFG1);
2076 DUMPREG(DSI_DSIPHY_CFG2);
2077 DUMPREG(DSI_DSIPHY_CFG5);
2078
2079 DUMPREG(DSI_PLL_CONTROL);
2080 DUMPREG(DSI_PLL_STATUS);
2081 DUMPREG(DSI_PLL_GO);
2082 DUMPREG(DSI_PLL_CONFIGURATION1);
2083 DUMPREG(DSI_PLL_CONFIGURATION2);
2084
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302085 dsi_disable_scp_clk(dsidev);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03002086 dsi_runtime_put(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002087#undef DUMPREG
2088}
2089
Archit Taneja5a8b5722011-05-12 17:26:29 +05302090static void dsi1_dump_regs(struct seq_file *s)
2091{
2092 struct platform_device *dsidev = dsi_get_dsidev_from_id(0);
2093
2094 dsi_dump_dsidev_regs(dsidev, s);
2095}
2096
2097static void dsi2_dump_regs(struct seq_file *s)
2098{
2099 struct platform_device *dsidev = dsi_get_dsidev_from_id(1);
2100
2101 dsi_dump_dsidev_regs(dsidev, s);
2102}
2103
Tomi Valkeinencc5c1852010-10-06 15:18:13 +03002104enum dsi_cio_power_state {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002105 DSI_COMPLEXIO_POWER_OFF = 0x0,
2106 DSI_COMPLEXIO_POWER_ON = 0x1,
2107 DSI_COMPLEXIO_POWER_ULPS = 0x2,
2108};
2109
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302110static int dsi_cio_power(struct platform_device *dsidev,
2111 enum dsi_cio_power_state state)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002112{
2113 int t = 0;
2114
2115 /* PWR_CMD */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302116 REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG1, state, 28, 27);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002117
2118 /* PWR_STATUS */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302119 while (FLD_GET(dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1),
2120 26, 25) != state) {
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02002121 if (++t > 1000) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002122 DSSERR("failed to set complexio power state to "
2123 "%d\n", state);
2124 return -ENODEV;
2125 }
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02002126 udelay(1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002127 }
2128
2129 return 0;
2130}
2131
Archit Taneja0c656222011-05-16 15:17:09 +05302132static unsigned dsi_get_line_buf_size(struct platform_device *dsidev)
2133{
2134 int val;
2135
2136 /* line buffer on OMAP3 is 1024 x 24bits */
2137 /* XXX: for some reason using full buffer size causes
2138 * considerable TX slowdown with update sizes that fill the
2139 * whole buffer */
2140 if (!dss_has_feature(FEAT_DSI_GNQ))
2141 return 1023 * 3;
2142
2143 val = REG_GET(dsidev, DSI_GNQ, 14, 12); /* VP1_LINE_BUFFER_SIZE */
2144
2145 switch (val) {
2146 case 1:
2147 return 512 * 3; /* 512x24 bits */
2148 case 2:
2149 return 682 * 3; /* 682x24 bits */
2150 case 3:
2151 return 853 * 3; /* 853x24 bits */
2152 case 4:
2153 return 1024 * 3; /* 1024x24 bits */
2154 case 5:
2155 return 1194 * 3; /* 1194x24 bits */
2156 case 6:
2157 return 1365 * 3; /* 1365x24 bits */
2158 default:
2159 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002160 return 0;
Archit Taneja0c656222011-05-16 15:17:09 +05302161 }
2162}
2163
Tomi Valkeinen48368392011-10-13 11:22:39 +03002164static int dsi_set_lane_config(struct omap_dss_device *dssdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002165{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302166 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Tomi Valkeinen48368392011-10-13 11:22:39 +03002167 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2168 static const u8 offsets[] = { 0, 4, 8, 12, 16 };
2169 static const enum dsi_lane_function functions[] = {
2170 DSI_LANE_CLK,
2171 DSI_LANE_DATA1,
2172 DSI_LANE_DATA2,
2173 DSI_LANE_DATA3,
2174 DSI_LANE_DATA4,
2175 };
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002176 u32 r;
Tomi Valkeinen48368392011-10-13 11:22:39 +03002177 int i;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002178
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302179 r = dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1);
Archit Taneja75d72472011-05-16 15:17:08 +05302180
Tomi Valkeinen48368392011-10-13 11:22:39 +03002181 for (i = 0; i < dsi->num_lanes_used; ++i) {
2182 unsigned offset = offsets[i];
2183 unsigned polarity, lane_number;
2184 unsigned t;
Archit Taneja75d72472011-05-16 15:17:08 +05302185
Tomi Valkeinen48368392011-10-13 11:22:39 +03002186 for (t = 0; t < dsi->num_lanes_supported; ++t)
2187 if (dsi->lanes[t].function == functions[i])
2188 break;
2189
2190 if (t == dsi->num_lanes_supported)
2191 return -EINVAL;
2192
2193 lane_number = t;
2194 polarity = dsi->lanes[t].polarity;
2195
2196 r = FLD_MOD(r, lane_number + 1, offset + 2, offset);
2197 r = FLD_MOD(r, polarity, offset + 3, offset + 3);
Archit Taneja75d72472011-05-16 15:17:08 +05302198 }
Tomi Valkeinen48368392011-10-13 11:22:39 +03002199
2200 /* clear the unused lanes */
2201 for (; i < dsi->num_lanes_supported; ++i) {
2202 unsigned offset = offsets[i];
2203
2204 r = FLD_MOD(r, 0, offset + 2, offset);
2205 r = FLD_MOD(r, 0, offset + 3, offset + 3);
2206 }
2207
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302208 dsi_write_reg(dsidev, DSI_COMPLEXIO_CFG1, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002209
Tomi Valkeinen48368392011-10-13 11:22:39 +03002210 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002211}
2212
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302213static inline unsigned ns2ddr(struct platform_device *dsidev, unsigned ns)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002214{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302215 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2216
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002217 /* convert time in ns to ddr ticks, rounding up */
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302218 unsigned long ddr_clk = dsi->current_cinfo.clkin4ddr / 4;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002219 return (ns * (ddr_clk / 1000 / 1000) + 999) / 1000;
2220}
2221
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302222static inline unsigned ddr2ns(struct platform_device *dsidev, unsigned ddr)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002223{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302224 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2225
2226 unsigned long ddr_clk = dsi->current_cinfo.clkin4ddr / 4;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002227 return ddr * 1000 * 1000 / (ddr_clk / 1000);
2228}
2229
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302230static void dsi_cio_timings(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002231{
2232 u32 r;
2233 u32 ths_prepare, ths_prepare_ths_zero, ths_trail, ths_exit;
2234 u32 tlpx_half, tclk_trail, tclk_zero;
2235 u32 tclk_prepare;
2236
2237 /* calculate timings */
2238
2239 /* 1 * DDR_CLK = 2 * UI */
2240
2241 /* min 40ns + 4*UI max 85ns + 6*UI */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302242 ths_prepare = ns2ddr(dsidev, 70) + 2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002243
2244 /* min 145ns + 10*UI */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302245 ths_prepare_ths_zero = ns2ddr(dsidev, 175) + 2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002246
2247 /* min max(8*UI, 60ns+4*UI) */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302248 ths_trail = ns2ddr(dsidev, 60) + 5;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002249
2250 /* min 100ns */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302251 ths_exit = ns2ddr(dsidev, 145);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002252
2253 /* tlpx min 50n */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302254 tlpx_half = ns2ddr(dsidev, 25);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002255
2256 /* min 60ns */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302257 tclk_trail = ns2ddr(dsidev, 60) + 2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002258
2259 /* min 38ns, max 95ns */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302260 tclk_prepare = ns2ddr(dsidev, 65);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002261
2262 /* min tclk-prepare + tclk-zero = 300ns */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302263 tclk_zero = ns2ddr(dsidev, 260);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002264
2265 DSSDBG("ths_prepare %u (%uns), ths_prepare_ths_zero %u (%uns)\n",
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302266 ths_prepare, ddr2ns(dsidev, ths_prepare),
2267 ths_prepare_ths_zero, ddr2ns(dsidev, ths_prepare_ths_zero));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002268 DSSDBG("ths_trail %u (%uns), ths_exit %u (%uns)\n",
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302269 ths_trail, ddr2ns(dsidev, ths_trail),
2270 ths_exit, ddr2ns(dsidev, ths_exit));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002271
2272 DSSDBG("tlpx_half %u (%uns), tclk_trail %u (%uns), "
2273 "tclk_zero %u (%uns)\n",
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302274 tlpx_half, ddr2ns(dsidev, tlpx_half),
2275 tclk_trail, ddr2ns(dsidev, tclk_trail),
2276 tclk_zero, ddr2ns(dsidev, tclk_zero));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002277 DSSDBG("tclk_prepare %u (%uns)\n",
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302278 tclk_prepare, ddr2ns(dsidev, tclk_prepare));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002279
2280 /* program timings */
2281
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302282 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002283 r = FLD_MOD(r, ths_prepare, 31, 24);
2284 r = FLD_MOD(r, ths_prepare_ths_zero, 23, 16);
2285 r = FLD_MOD(r, ths_trail, 15, 8);
2286 r = FLD_MOD(r, ths_exit, 7, 0);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302287 dsi_write_reg(dsidev, DSI_DSIPHY_CFG0, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002288
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302289 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002290 r = FLD_MOD(r, tlpx_half, 22, 16);
2291 r = FLD_MOD(r, tclk_trail, 15, 8);
2292 r = FLD_MOD(r, tclk_zero, 7, 0);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302293 dsi_write_reg(dsidev, DSI_DSIPHY_CFG1, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002294
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302295 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG2);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002296 r = FLD_MOD(r, tclk_prepare, 7, 0);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302297 dsi_write_reg(dsidev, DSI_DSIPHY_CFG2, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002298}
2299
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002300/* lane masks have lane 0 at lsb. mask_p for positive lines, n for negative */
Tomi Valkeinencc5c1852010-10-06 15:18:13 +03002301static void dsi_cio_enable_lane_override(struct omap_dss_device *dssdev,
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002302 unsigned mask_p, unsigned mask_n)
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002303{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302304 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Taneja75d72472011-05-16 15:17:08 +05302305 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002306 int i;
2307 u32 l;
Tomi Valkeinend9820852011-10-12 15:05:59 +03002308 u8 lptxscp_start = dsi->num_lanes_supported == 3 ? 22 : 26;
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002309
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002310 l = 0;
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002311
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002312 for (i = 0; i < dsi->num_lanes_supported; ++i) {
2313 unsigned p = dsi->lanes[i].polarity;
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002314
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002315 if (mask_p & (1 << i))
2316 l |= 1 << (i * 2 + (p ? 0 : 1));
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002317
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002318 if (mask_n & (1 << i))
2319 l |= 1 << (i * 2 + (p ? 1 : 0));
2320 }
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002321
2322 /*
2323 * Bits in REGLPTXSCPDAT4TO0DXDY:
2324 * 17: DY0 18: DX0
2325 * 19: DY1 20: DX1
2326 * 21: DY2 22: DX2
Archit Taneja75d72472011-05-16 15:17:08 +05302327 * 23: DY3 24: DX3
2328 * 25: DY4 26: DX4
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002329 */
2330
2331 /* Set the lane override configuration */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302332
2333 /* REGLPTXSCPDAT4TO0DXDY */
Archit Taneja75d72472011-05-16 15:17:08 +05302334 REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, l, lptxscp_start, 17);
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002335
2336 /* Enable lane override */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302337
2338 /* ENLPTXSCPDAT */
2339 REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 1, 27, 27);
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002340}
2341
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302342static void dsi_cio_disable_lane_override(struct platform_device *dsidev)
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002343{
2344 /* Disable lane override */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302345 REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 0, 27, 27); /* ENLPTXSCPDAT */
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002346 /* Reset the lane override configuration */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302347 /* REGLPTXSCPDAT4TO0DXDY */
2348 REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 0, 22, 17);
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002349}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002350
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002351static int dsi_cio_wait_tx_clk_esc_reset(struct omap_dss_device *dssdev)
2352{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302353 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Tomi Valkeinen8dc07662011-10-13 15:26:50 +03002354 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2355 int t, i;
2356 bool in_use[DSI_MAX_NR_LANES];
2357 static const u8 offsets_old[] = { 28, 27, 26 };
2358 static const u8 offsets_new[] = { 24, 25, 26, 27, 28 };
2359 const u8 *offsets;
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002360
Tomi Valkeinen8dc07662011-10-13 15:26:50 +03002361 if (dss_has_feature(FEAT_DSI_REVERSE_TXCLKESC))
2362 offsets = offsets_old;
2363 else
2364 offsets = offsets_new;
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002365
Tomi Valkeinen8dc07662011-10-13 15:26:50 +03002366 for (i = 0; i < dsi->num_lanes_supported; ++i)
2367 in_use[i] = dsi->lanes[i].function != DSI_LANE_UNUSED;
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002368
2369 t = 100000;
2370 while (true) {
2371 u32 l;
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002372 int ok;
2373
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302374 l = dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002375
2376 ok = 0;
Tomi Valkeinen8dc07662011-10-13 15:26:50 +03002377 for (i = 0; i < dsi->num_lanes_supported; ++i) {
2378 if (!in_use[i] || (l & (1 << offsets[i])))
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002379 ok++;
2380 }
2381
Tomi Valkeinen8dc07662011-10-13 15:26:50 +03002382 if (ok == dsi->num_lanes_supported)
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002383 break;
2384
2385 if (--t == 0) {
Tomi Valkeinen8dc07662011-10-13 15:26:50 +03002386 for (i = 0; i < dsi->num_lanes_supported; ++i) {
2387 if (!in_use[i] || (l & (1 << offsets[i])))
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002388 continue;
2389
2390 DSSERR("CIO TXCLKESC%d domain not coming " \
2391 "out of reset\n", i);
2392 }
2393 return -EIO;
2394 }
2395 }
2396
2397 return 0;
2398}
2399
Tomi Valkeinen85f17e82011-10-13 15:12:23 +03002400/* return bitmask of enabled lanes, lane0 being the lsb */
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03002401static unsigned dsi_get_lane_mask(struct omap_dss_device *dssdev)
2402{
Tomi Valkeinen85f17e82011-10-13 15:12:23 +03002403 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
2404 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2405 unsigned mask = 0;
2406 int i;
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03002407
Tomi Valkeinen85f17e82011-10-13 15:12:23 +03002408 for (i = 0; i < dsi->num_lanes_supported; ++i) {
2409 if (dsi->lanes[i].function != DSI_LANE_UNUSED)
2410 mask |= 1 << i;
2411 }
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03002412
Tomi Valkeinen85f17e82011-10-13 15:12:23 +03002413 return mask;
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03002414}
2415
Tomi Valkeinencc5c1852010-10-06 15:18:13 +03002416static int dsi_cio_init(struct omap_dss_device *dssdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002417{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302418 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302419 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002420 int r;
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002421 u32 l;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002422
Tomi Valkeinencc5c1852010-10-06 15:18:13 +03002423 DSSDBGF();
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002424
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02002425 r = dss_dsi_enable_pads(dsi->module_id, dsi_get_lane_mask(dssdev));
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03002426 if (r)
2427 return r;
Tomi Valkeinend1f5857e2010-07-30 11:57:57 +03002428
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302429 dsi_enable_scp_clk(dsidev);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002430
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002431 /* A dummy read using the SCP interface to any DSIPHY register is
2432 * required after DSIPHY reset to complete the reset of the DSI complex
2433 * I/O. */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302434 dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002435
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302436 if (wait_for_bit_change(dsidev, DSI_DSIPHY_CFG5, 30, 1) != 1) {
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002437 DSSERR("CIO SCP Clock domain not coming out of reset.\n");
2438 r = -EIO;
2439 goto err_scp_clk_dom;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002440 }
2441
Tomi Valkeinen48368392011-10-13 11:22:39 +03002442 r = dsi_set_lane_config(dssdev);
2443 if (r)
2444 goto err_scp_clk_dom;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002445
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002446 /* set TX STOP MODE timer to maximum for this operation */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302447 l = dsi_read_reg(dsidev, DSI_TIMING1);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002448 l = FLD_MOD(l, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
2449 l = FLD_MOD(l, 1, 14, 14); /* STOP_STATE_X16_IO */
2450 l = FLD_MOD(l, 1, 13, 13); /* STOP_STATE_X4_IO */
2451 l = FLD_MOD(l, 0x1fff, 12, 0); /* STOP_STATE_COUNTER_IO */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302452 dsi_write_reg(dsidev, DSI_TIMING1, l);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002453
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302454 if (dsi->ulps_enabled) {
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002455 unsigned mask_p;
2456 int i;
Archit Taneja75d72472011-05-16 15:17:08 +05302457
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002458 DSSDBG("manual ulps exit\n");
2459
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002460 /* ULPS is exited by Mark-1 state for 1ms, followed by
2461 * stop state. DSS HW cannot do this via the normal
2462 * ULPS exit sequence, as after reset the DSS HW thinks
2463 * that we are not in ULPS mode, and refuses to send the
2464 * sequence. So we need to send the ULPS exit sequence
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002465 * manually by setting positive lines high and negative lines
2466 * low for 1ms.
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002467 */
2468
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002469 mask_p = 0;
Archit Taneja75d72472011-05-16 15:17:08 +05302470
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002471 for (i = 0; i < dsi->num_lanes_supported; ++i) {
2472 if (dsi->lanes[i].function == DSI_LANE_UNUSED)
2473 continue;
2474 mask_p |= 1 << i;
2475 }
Archit Taneja75d72472011-05-16 15:17:08 +05302476
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002477 dsi_cio_enable_lane_override(dssdev, mask_p, 0);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002478 }
2479
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302480 r = dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_ON);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002481 if (r)
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002482 goto err_cio_pwr;
2483
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302484 if (wait_for_bit_change(dsidev, DSI_COMPLEXIO_CFG1, 29, 1) != 1) {
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002485 DSSERR("CIO PWR clock domain not coming out of reset.\n");
2486 r = -ENODEV;
2487 goto err_cio_pwr_dom;
2488 }
2489
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302490 dsi_if_enable(dsidev, true);
2491 dsi_if_enable(dsidev, false);
2492 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 1, 20, 20); /* LP_CLK_ENABLE */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002493
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002494 r = dsi_cio_wait_tx_clk_esc_reset(dssdev);
2495 if (r)
2496 goto err_tx_clk_esc_rst;
2497
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302498 if (dsi->ulps_enabled) {
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002499 /* Keep Mark-1 state for 1ms (as per DSI spec) */
2500 ktime_t wait = ns_to_ktime(1000 * 1000);
2501 set_current_state(TASK_UNINTERRUPTIBLE);
2502 schedule_hrtimeout(&wait, HRTIMER_MODE_REL);
2503
2504 /* Disable the override. The lanes should be set to Mark-11
2505 * state by the HW */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302506 dsi_cio_disable_lane_override(dsidev);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002507 }
2508
2509 /* FORCE_TX_STOP_MODE_IO */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302510 REG_FLD_MOD(dsidev, DSI_TIMING1, 0, 15, 15);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002511
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302512 dsi_cio_timings(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002513
Archit Tanejadca2b152012-08-16 18:02:00 +05302514 if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
Archit Taneja8af6ff02011-09-05 16:48:27 +05302515 /* DDR_CLK_ALWAYS_ON */
2516 REG_FLD_MOD(dsidev, DSI_CLK_CTRL,
Archit Taneja0b3ffe32012-08-13 22:13:39 +05302517 dsi->vm_timings.ddr_clk_always_on, 13, 13);
Archit Taneja8af6ff02011-09-05 16:48:27 +05302518 }
2519
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302520 dsi->ulps_enabled = false;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002521
2522 DSSDBG("CIO init done\n");
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002523
2524 return 0;
2525
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002526err_tx_clk_esc_rst:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302527 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 20, 20); /* LP_CLK_ENABLE */
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002528err_cio_pwr_dom:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302529 dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_OFF);
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002530err_cio_pwr:
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302531 if (dsi->ulps_enabled)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302532 dsi_cio_disable_lane_override(dsidev);
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002533err_scp_clk_dom:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302534 dsi_disable_scp_clk(dsidev);
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02002535 dss_dsi_disable_pads(dsi->module_id, dsi_get_lane_mask(dssdev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002536 return r;
2537}
2538
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03002539static void dsi_cio_uninit(struct omap_dss_device *dssdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002540{
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03002541 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02002542 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302543
Archit Taneja8af6ff02011-09-05 16:48:27 +05302544 /* DDR_CLK_ALWAYS_ON */
2545 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 13, 13);
2546
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302547 dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_OFF);
2548 dsi_disable_scp_clk(dsidev);
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02002549 dss_dsi_disable_pads(dsi->module_id, dsi_get_lane_mask(dssdev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002550}
2551
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302552static void dsi_config_tx_fifo(struct platform_device *dsidev,
2553 enum fifo_size size1, enum fifo_size size2,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002554 enum fifo_size size3, enum fifo_size size4)
2555{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302556 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002557 u32 r = 0;
2558 int add = 0;
2559 int i;
2560
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302561 dsi->vc[0].fifo_size = size1;
2562 dsi->vc[1].fifo_size = size2;
2563 dsi->vc[2].fifo_size = size3;
2564 dsi->vc[3].fifo_size = size4;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002565
2566 for (i = 0; i < 4; i++) {
2567 u8 v;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302568 int size = dsi->vc[i].fifo_size;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002569
2570 if (add + size > 4) {
2571 DSSERR("Illegal FIFO configuration\n");
2572 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002573 return;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002574 }
2575
2576 v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
2577 r |= v << (8 * i);
2578 /*DSSDBG("TX FIFO vc %d: size %d, add %d\n", i, size, add); */
2579 add += size;
2580 }
2581
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302582 dsi_write_reg(dsidev, DSI_TX_FIFO_VC_SIZE, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002583}
2584
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302585static void dsi_config_rx_fifo(struct platform_device *dsidev,
2586 enum fifo_size size1, enum fifo_size size2,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002587 enum fifo_size size3, enum fifo_size size4)
2588{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302589 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002590 u32 r = 0;
2591 int add = 0;
2592 int i;
2593
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302594 dsi->vc[0].fifo_size = size1;
2595 dsi->vc[1].fifo_size = size2;
2596 dsi->vc[2].fifo_size = size3;
2597 dsi->vc[3].fifo_size = size4;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002598
2599 for (i = 0; i < 4; i++) {
2600 u8 v;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302601 int size = dsi->vc[i].fifo_size;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002602
2603 if (add + size > 4) {
2604 DSSERR("Illegal FIFO configuration\n");
2605 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002606 return;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002607 }
2608
2609 v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
2610 r |= v << (8 * i);
2611 /*DSSDBG("RX FIFO vc %d: size %d, add %d\n", i, size, add); */
2612 add += size;
2613 }
2614
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302615 dsi_write_reg(dsidev, DSI_RX_FIFO_VC_SIZE, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002616}
2617
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302618static int dsi_force_tx_stop_mode_io(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002619{
2620 u32 r;
2621
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302622 r = dsi_read_reg(dsidev, DSI_TIMING1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002623 r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302624 dsi_write_reg(dsidev, DSI_TIMING1, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002625
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302626 if (wait_for_bit_change(dsidev, DSI_TIMING1, 15, 0) != 0) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002627 DSSERR("TX_STOP bit not going down\n");
2628 return -EIO;
2629 }
2630
2631 return 0;
2632}
2633
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302634static bool dsi_vc_is_enabled(struct platform_device *dsidev, int channel)
Archit Tanejacf398fb2011-03-23 09:59:34 +00002635{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302636 return REG_GET(dsidev, DSI_VC_CTRL(channel), 0, 0);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002637}
2638
2639static void dsi_packet_sent_handler_vp(void *data, u32 mask)
2640{
Archit Taneja2e868db2011-05-12 17:26:28 +05302641 struct dsi_packet_sent_handler_data *vp_data =
2642 (struct dsi_packet_sent_handler_data *) data;
2643 struct dsi_data *dsi = dsi_get_dsidrv_data(vp_data->dsidev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302644 const int channel = dsi->update_channel;
2645 u8 bit = dsi->te_enabled ? 30 : 31;
Archit Tanejacf398fb2011-03-23 09:59:34 +00002646
Archit Taneja2e868db2011-05-12 17:26:28 +05302647 if (REG_GET(vp_data->dsidev, DSI_VC_TE(channel), bit, bit) == 0)
2648 complete(vp_data->completion);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002649}
2650
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302651static int dsi_sync_vc_vp(struct platform_device *dsidev, int channel)
Archit Tanejacf398fb2011-03-23 09:59:34 +00002652{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302653 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Taneja2e868db2011-05-12 17:26:28 +05302654 DECLARE_COMPLETION_ONSTACK(completion);
2655 struct dsi_packet_sent_handler_data vp_data = { dsidev, &completion };
Archit Tanejacf398fb2011-03-23 09:59:34 +00002656 int r = 0;
2657 u8 bit;
2658
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302659 bit = dsi->te_enabled ? 30 : 31;
Archit Tanejacf398fb2011-03-23 09:59:34 +00002660
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302661 r = dsi_register_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp,
Archit Taneja2e868db2011-05-12 17:26:28 +05302662 &vp_data, DSI_VC_IRQ_PACKET_SENT);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002663 if (r)
2664 goto err0;
2665
2666 /* Wait for completion only if TE_EN/TE_START is still set */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302667 if (REG_GET(dsidev, DSI_VC_TE(channel), bit, bit)) {
Archit Tanejacf398fb2011-03-23 09:59:34 +00002668 if (wait_for_completion_timeout(&completion,
2669 msecs_to_jiffies(10)) == 0) {
2670 DSSERR("Failed to complete previous frame transfer\n");
2671 r = -EIO;
2672 goto err1;
2673 }
2674 }
2675
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302676 dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp,
Archit Taneja2e868db2011-05-12 17:26:28 +05302677 &vp_data, DSI_VC_IRQ_PACKET_SENT);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002678
2679 return 0;
2680err1:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302681 dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp,
Archit Taneja2e868db2011-05-12 17:26:28 +05302682 &vp_data, DSI_VC_IRQ_PACKET_SENT);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002683err0:
2684 return r;
2685}
2686
2687static void dsi_packet_sent_handler_l4(void *data, u32 mask)
2688{
Archit Taneja2e868db2011-05-12 17:26:28 +05302689 struct dsi_packet_sent_handler_data *l4_data =
2690 (struct dsi_packet_sent_handler_data *) data;
2691 struct dsi_data *dsi = dsi_get_dsidrv_data(l4_data->dsidev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302692 const int channel = dsi->update_channel;
Archit Tanejacf398fb2011-03-23 09:59:34 +00002693
Archit Taneja2e868db2011-05-12 17:26:28 +05302694 if (REG_GET(l4_data->dsidev, DSI_VC_CTRL(channel), 5, 5) == 0)
2695 complete(l4_data->completion);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002696}
2697
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302698static int dsi_sync_vc_l4(struct platform_device *dsidev, int channel)
Archit Tanejacf398fb2011-03-23 09:59:34 +00002699{
Archit Taneja2e868db2011-05-12 17:26:28 +05302700 DECLARE_COMPLETION_ONSTACK(completion);
2701 struct dsi_packet_sent_handler_data l4_data = { dsidev, &completion };
Archit Tanejacf398fb2011-03-23 09:59:34 +00002702 int r = 0;
2703
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302704 r = dsi_register_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4,
Archit Taneja2e868db2011-05-12 17:26:28 +05302705 &l4_data, DSI_VC_IRQ_PACKET_SENT);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002706 if (r)
2707 goto err0;
2708
2709 /* Wait for completion only if TX_FIFO_NOT_EMPTY is still set */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302710 if (REG_GET(dsidev, DSI_VC_CTRL(channel), 5, 5)) {
Archit Tanejacf398fb2011-03-23 09:59:34 +00002711 if (wait_for_completion_timeout(&completion,
2712 msecs_to_jiffies(10)) == 0) {
2713 DSSERR("Failed to complete previous l4 transfer\n");
2714 r = -EIO;
2715 goto err1;
2716 }
2717 }
2718
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302719 dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4,
Archit Taneja2e868db2011-05-12 17:26:28 +05302720 &l4_data, DSI_VC_IRQ_PACKET_SENT);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002721
2722 return 0;
2723err1:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302724 dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4,
Archit Taneja2e868db2011-05-12 17:26:28 +05302725 &l4_data, DSI_VC_IRQ_PACKET_SENT);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002726err0:
2727 return r;
2728}
2729
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302730static int dsi_sync_vc(struct platform_device *dsidev, int channel)
Archit Tanejacf398fb2011-03-23 09:59:34 +00002731{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302732 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2733
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302734 WARN_ON(!dsi_bus_is_locked(dsidev));
Archit Tanejacf398fb2011-03-23 09:59:34 +00002735
2736 WARN_ON(in_interrupt());
2737
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302738 if (!dsi_vc_is_enabled(dsidev, channel))
Archit Tanejacf398fb2011-03-23 09:59:34 +00002739 return 0;
2740
Archit Tanejad6049142011-08-22 11:58:08 +05302741 switch (dsi->vc[channel].source) {
2742 case DSI_VC_SOURCE_VP:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302743 return dsi_sync_vc_vp(dsidev, channel);
Archit Tanejad6049142011-08-22 11:58:08 +05302744 case DSI_VC_SOURCE_L4:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302745 return dsi_sync_vc_l4(dsidev, channel);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002746 default:
2747 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002748 return -EINVAL;
Archit Tanejacf398fb2011-03-23 09:59:34 +00002749 }
2750}
2751
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302752static int dsi_vc_enable(struct platform_device *dsidev, int channel,
2753 bool enable)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002754{
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +02002755 DSSDBG("dsi_vc_enable channel %d, enable %d\n",
2756 channel, enable);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002757
2758 enable = enable ? 1 : 0;
2759
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302760 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 0, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002761
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302762 if (wait_for_bit_change(dsidev, DSI_VC_CTRL(channel),
2763 0, enable) != enable) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002764 DSSERR("Failed to set dsi_vc_enable to %d\n", enable);
2765 return -EIO;
2766 }
2767
2768 return 0;
2769}
2770
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302771static void dsi_vc_initial_config(struct platform_device *dsidev, int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002772{
2773 u32 r;
2774
2775 DSSDBGF("%d", channel);
2776
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302777 r = dsi_read_reg(dsidev, DSI_VC_CTRL(channel));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002778
2779 if (FLD_GET(r, 15, 15)) /* VC_BUSY */
2780 DSSERR("VC(%d) busy when trying to configure it!\n",
2781 channel);
2782
2783 r = FLD_MOD(r, 0, 1, 1); /* SOURCE, 0 = L4 */
2784 r = FLD_MOD(r, 0, 2, 2); /* BTA_SHORT_EN */
2785 r = FLD_MOD(r, 0, 3, 3); /* BTA_LONG_EN */
2786 r = FLD_MOD(r, 0, 4, 4); /* MODE, 0 = command */
2787 r = FLD_MOD(r, 1, 7, 7); /* CS_TX_EN */
2788 r = FLD_MOD(r, 1, 8, 8); /* ECC_TX_EN */
2789 r = FLD_MOD(r, 0, 9, 9); /* MODE_SPEED, high speed on/off */
Archit Taneja9613c022011-03-22 06:33:36 -05002790 if (dss_has_feature(FEAT_DSI_VC_OCP_WIDTH))
2791 r = FLD_MOD(r, 3, 11, 10); /* OCP_WIDTH = 32 bit */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002792
2793 r = FLD_MOD(r, 4, 29, 27); /* DMA_RX_REQ_NB = no dma */
2794 r = FLD_MOD(r, 4, 23, 21); /* DMA_TX_REQ_NB = no dma */
2795
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302796 dsi_write_reg(dsidev, DSI_VC_CTRL(channel), r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002797}
2798
Archit Tanejad6049142011-08-22 11:58:08 +05302799static int dsi_vc_config_source(struct platform_device *dsidev, int channel,
2800 enum dsi_vc_source source)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002801{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302802 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2803
Archit Tanejad6049142011-08-22 11:58:08 +05302804 if (dsi->vc[channel].source == source)
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03002805 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002806
2807 DSSDBGF("%d", channel);
2808
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302809 dsi_sync_vc(dsidev, channel);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002810
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302811 dsi_vc_enable(dsidev, channel, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002812
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03002813 /* VC_BUSY */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302814 if (wait_for_bit_change(dsidev, DSI_VC_CTRL(channel), 15, 0) != 0) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002815 DSSERR("vc(%d) busy when trying to config for VP\n", channel);
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03002816 return -EIO;
2817 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002818
Archit Tanejad6049142011-08-22 11:58:08 +05302819 /* SOURCE, 0 = L4, 1 = video port */
2820 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), source, 1, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002821
Archit Taneja9613c022011-03-22 06:33:36 -05002822 /* DCS_CMD_ENABLE */
Archit Tanejad6049142011-08-22 11:58:08 +05302823 if (dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC)) {
2824 bool enable = source == DSI_VC_SOURCE_VP;
2825 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 30, 30);
2826 }
Archit Taneja9613c022011-03-22 06:33:36 -05002827
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302828 dsi_vc_enable(dsidev, channel, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002829
Archit Tanejad6049142011-08-22 11:58:08 +05302830 dsi->vc[channel].source = source;
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03002831
2832 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002833}
2834
Archit Taneja1ffefe72011-05-12 17:26:24 +05302835void omapdss_dsi_vc_enable_hs(struct omap_dss_device *dssdev, int channel,
2836 bool enable)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002837{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302838 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Taneja0b3ffe32012-08-13 22:13:39 +05302839 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302840
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002841 DSSDBG("dsi_vc_enable_hs(%d, %d)\n", channel, enable);
2842
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302843 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen61140c92010-01-12 16:00:30 +02002844
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302845 dsi_vc_enable(dsidev, channel, 0);
2846 dsi_if_enable(dsidev, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002847
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302848 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 9, 9);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002849
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302850 dsi_vc_enable(dsidev, channel, 1);
2851 dsi_if_enable(dsidev, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002852
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302853 dsi_force_tx_stop_mode_io(dsidev);
Archit Taneja8af6ff02011-09-05 16:48:27 +05302854
2855 /* start the DDR clock by sending a NULL packet */
Archit Taneja0b3ffe32012-08-13 22:13:39 +05302856 if (dsi->vm_timings.ddr_clk_always_on && enable)
Archit Taneja8af6ff02011-09-05 16:48:27 +05302857 dsi_vc_send_null(dssdev, channel);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002858}
Tomi Valkeinen61140c92010-01-12 16:00:30 +02002859EXPORT_SYMBOL(omapdss_dsi_vc_enable_hs);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002860
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302861static void dsi_vc_flush_long_data(struct platform_device *dsidev, int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002862{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302863 while (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002864 u32 val;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302865 val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002866 DSSDBG("\t\tb1 %#02x b2 %#02x b3 %#02x b4 %#02x\n",
2867 (val >> 0) & 0xff,
2868 (val >> 8) & 0xff,
2869 (val >> 16) & 0xff,
2870 (val >> 24) & 0xff);
2871 }
2872}
2873
2874static void dsi_show_rx_ack_with_err(u16 err)
2875{
2876 DSSERR("\tACK with ERROR (%#x):\n", err);
2877 if (err & (1 << 0))
2878 DSSERR("\t\tSoT Error\n");
2879 if (err & (1 << 1))
2880 DSSERR("\t\tSoT Sync Error\n");
2881 if (err & (1 << 2))
2882 DSSERR("\t\tEoT Sync Error\n");
2883 if (err & (1 << 3))
2884 DSSERR("\t\tEscape Mode Entry Command Error\n");
2885 if (err & (1 << 4))
2886 DSSERR("\t\tLP Transmit Sync Error\n");
2887 if (err & (1 << 5))
2888 DSSERR("\t\tHS Receive Timeout Error\n");
2889 if (err & (1 << 6))
2890 DSSERR("\t\tFalse Control Error\n");
2891 if (err & (1 << 7))
2892 DSSERR("\t\t(reserved7)\n");
2893 if (err & (1 << 8))
2894 DSSERR("\t\tECC Error, single-bit (corrected)\n");
2895 if (err & (1 << 9))
2896 DSSERR("\t\tECC Error, multi-bit (not corrected)\n");
2897 if (err & (1 << 10))
2898 DSSERR("\t\tChecksum Error\n");
2899 if (err & (1 << 11))
2900 DSSERR("\t\tData type not recognized\n");
2901 if (err & (1 << 12))
2902 DSSERR("\t\tInvalid VC ID\n");
2903 if (err & (1 << 13))
2904 DSSERR("\t\tInvalid Transmission Length\n");
2905 if (err & (1 << 14))
2906 DSSERR("\t\t(reserved14)\n");
2907 if (err & (1 << 15))
2908 DSSERR("\t\tDSI Protocol Violation\n");
2909}
2910
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302911static u16 dsi_vc_flush_receive_data(struct platform_device *dsidev,
2912 int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002913{
2914 /* RX_FIFO_NOT_EMPTY */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302915 while (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002916 u32 val;
2917 u8 dt;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302918 val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel));
Tomi Valkeinen86a78672010-03-16 16:19:06 +02002919 DSSERR("\trawval %#08x\n", val);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002920 dt = FLD_GET(val, 5, 0);
Archit Taneja7a7c48f2011-08-25 18:25:03 +05302921 if (dt == MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002922 u16 err = FLD_GET(val, 23, 8);
2923 dsi_show_rx_ack_with_err(err);
Archit Taneja7a7c48f2011-08-25 18:25:03 +05302924 } else if (dt == MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE) {
Tomi Valkeinen86a78672010-03-16 16:19:06 +02002925 DSSERR("\tDCS short response, 1 byte: %#x\n",
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002926 FLD_GET(val, 23, 8));
Archit Taneja7a7c48f2011-08-25 18:25:03 +05302927 } else if (dt == MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE) {
Tomi Valkeinen86a78672010-03-16 16:19:06 +02002928 DSSERR("\tDCS short response, 2 byte: %#x\n",
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002929 FLD_GET(val, 23, 8));
Archit Taneja7a7c48f2011-08-25 18:25:03 +05302930 } else if (dt == MIPI_DSI_RX_DCS_LONG_READ_RESPONSE) {
Tomi Valkeinen86a78672010-03-16 16:19:06 +02002931 DSSERR("\tDCS long response, len %d\n",
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002932 FLD_GET(val, 23, 8));
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302933 dsi_vc_flush_long_data(dsidev, channel);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002934 } else {
2935 DSSERR("\tunknown datatype 0x%02x\n", dt);
2936 }
2937 }
2938 return 0;
2939}
2940
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302941static int dsi_vc_send_bta(struct platform_device *dsidev, int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002942{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302943 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2944
2945 if (dsi->debug_write || dsi->debug_read)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002946 DSSDBG("dsi_vc_send_bta %d\n", channel);
2947
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302948 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002949
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302950 /* RX_FIFO_NOT_EMPTY */
2951 if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002952 DSSERR("rx fifo not empty when sending BTA, dumping data:\n");
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302953 dsi_vc_flush_receive_data(dsidev, channel);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002954 }
2955
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302956 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 1, 6, 6); /* BTA_EN */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002957
Tomi Valkeinen968f8e92011-10-12 10:13:14 +03002958 /* flush posted write */
2959 dsi_read_reg(dsidev, DSI_VC_CTRL(channel));
2960
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002961 return 0;
2962}
2963
Archit Taneja1ffefe72011-05-12 17:26:24 +05302964int dsi_vc_send_bta_sync(struct omap_dss_device *dssdev, int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002965{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302966 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Tomi Valkeinenf36a06e2011-03-02 14:48:41 +02002967 DECLARE_COMPLETION_ONSTACK(completion);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002968 int r = 0;
2969 u32 err;
2970
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302971 r = dsi_register_isr_vc(dsidev, channel, dsi_completion_handler,
Tomi Valkeinenf36a06e2011-03-02 14:48:41 +02002972 &completion, DSI_VC_IRQ_BTA);
2973 if (r)
2974 goto err0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002975
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302976 r = dsi_register_isr(dsidev, dsi_completion_handler, &completion,
Tomi Valkeinen773b30b2010-10-08 16:15:25 +03002977 DSI_IRQ_ERROR_MASK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002978 if (r)
Tomi Valkeinenf36a06e2011-03-02 14:48:41 +02002979 goto err1;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002980
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302981 r = dsi_vc_send_bta(dsidev, channel);
Tomi Valkeinen773b30b2010-10-08 16:15:25 +03002982 if (r)
2983 goto err2;
2984
Tomi Valkeinenf36a06e2011-03-02 14:48:41 +02002985 if (wait_for_completion_timeout(&completion,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002986 msecs_to_jiffies(500)) == 0) {
2987 DSSERR("Failed to receive BTA\n");
2988 r = -EIO;
Tomi Valkeinen773b30b2010-10-08 16:15:25 +03002989 goto err2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002990 }
2991
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302992 err = dsi_get_errors(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002993 if (err) {
2994 DSSERR("Error while sending BTA: %x\n", err);
2995 r = -EIO;
Tomi Valkeinen773b30b2010-10-08 16:15:25 +03002996 goto err2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002997 }
Tomi Valkeinen773b30b2010-10-08 16:15:25 +03002998err2:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302999 dsi_unregister_isr(dsidev, dsi_completion_handler, &completion,
Tomi Valkeinen773b30b2010-10-08 16:15:25 +03003000 DSI_IRQ_ERROR_MASK);
Tomi Valkeinenf36a06e2011-03-02 14:48:41 +02003001err1:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303002 dsi_unregister_isr_vc(dsidev, channel, dsi_completion_handler,
Tomi Valkeinenf36a06e2011-03-02 14:48:41 +02003003 &completion, DSI_VC_IRQ_BTA);
3004err0:
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003005 return r;
3006}
3007EXPORT_SYMBOL(dsi_vc_send_bta_sync);
3008
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303009static inline void dsi_vc_write_long_header(struct platform_device *dsidev,
3010 int channel, u8 data_type, u16 len, u8 ecc)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003011{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303012 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003013 u32 val;
3014 u8 data_id;
3015
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303016 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003017
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303018 data_id = data_type | dsi->vc[channel].vc_id << 6;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003019
3020 val = FLD_VAL(data_id, 7, 0) | FLD_VAL(len, 23, 8) |
3021 FLD_VAL(ecc, 31, 24);
3022
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303023 dsi_write_reg(dsidev, DSI_VC_LONG_PACKET_HEADER(channel), val);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003024}
3025
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303026static inline void dsi_vc_write_long_payload(struct platform_device *dsidev,
3027 int channel, u8 b1, u8 b2, u8 b3, u8 b4)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003028{
3029 u32 val;
3030
3031 val = b4 << 24 | b3 << 16 | b2 << 8 | b1 << 0;
3032
3033/* DSSDBG("\twriting %02x, %02x, %02x, %02x (%#010x)\n",
3034 b1, b2, b3, b4, val); */
3035
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303036 dsi_write_reg(dsidev, DSI_VC_LONG_PACKET_PAYLOAD(channel), val);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003037}
3038
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303039static int dsi_vc_send_long(struct platform_device *dsidev, int channel,
3040 u8 data_type, u8 *data, u16 len, u8 ecc)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003041{
3042 /*u32 val; */
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303043 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003044 int i;
3045 u8 *p;
3046 int r = 0;
3047 u8 b1, b2, b3, b4;
3048
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303049 if (dsi->debug_write)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003050 DSSDBG("dsi_vc_send_long, %d bytes\n", len);
3051
3052 /* len + header */
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303053 if (dsi->vc[channel].fifo_size * 32 * 4 < len + 4) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003054 DSSERR("unable to send long packet: packet too long.\n");
3055 return -EINVAL;
3056 }
3057
Archit Tanejad6049142011-08-22 11:58:08 +05303058 dsi_vc_config_source(dsidev, channel, DSI_VC_SOURCE_L4);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003059
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303060 dsi_vc_write_long_header(dsidev, channel, data_type, len, ecc);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003061
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003062 p = data;
3063 for (i = 0; i < len >> 2; i++) {
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303064 if (dsi->debug_write)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003065 DSSDBG("\tsending full packet %d\n", i);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003066
3067 b1 = *p++;
3068 b2 = *p++;
3069 b3 = *p++;
3070 b4 = *p++;
3071
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303072 dsi_vc_write_long_payload(dsidev, channel, b1, b2, b3, b4);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003073 }
3074
3075 i = len % 4;
3076 if (i) {
3077 b1 = 0; b2 = 0; b3 = 0;
3078
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303079 if (dsi->debug_write)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003080 DSSDBG("\tsending remainder bytes %d\n", i);
3081
3082 switch (i) {
3083 case 3:
3084 b1 = *p++;
3085 b2 = *p++;
3086 b3 = *p++;
3087 break;
3088 case 2:
3089 b1 = *p++;
3090 b2 = *p++;
3091 break;
3092 case 1:
3093 b1 = *p++;
3094 break;
3095 }
3096
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303097 dsi_vc_write_long_payload(dsidev, channel, b1, b2, b3, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003098 }
3099
3100 return r;
3101}
3102
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303103static int dsi_vc_send_short(struct platform_device *dsidev, int channel,
3104 u8 data_type, u16 data, u8 ecc)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003105{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303106 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003107 u32 r;
3108 u8 data_id;
3109
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303110 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003111
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303112 if (dsi->debug_write)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003113 DSSDBG("dsi_vc_send_short(ch%d, dt %#x, b1 %#x, b2 %#x)\n",
3114 channel,
3115 data_type, data & 0xff, (data >> 8) & 0xff);
3116
Archit Tanejad6049142011-08-22 11:58:08 +05303117 dsi_vc_config_source(dsidev, channel, DSI_VC_SOURCE_L4);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003118
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303119 if (FLD_GET(dsi_read_reg(dsidev, DSI_VC_CTRL(channel)), 16, 16)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003120 DSSERR("ERROR FIFO FULL, aborting transfer\n");
3121 return -EINVAL;
3122 }
3123
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303124 data_id = data_type | dsi->vc[channel].vc_id << 6;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003125
3126 r = (data_id << 0) | (data << 8) | (ecc << 24);
3127
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303128 dsi_write_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel), r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003129
3130 return 0;
3131}
3132
Archit Taneja1ffefe72011-05-12 17:26:24 +05303133int dsi_vc_send_null(struct omap_dss_device *dssdev, int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003134{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303135 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303136
Archit Taneja18b7d092011-09-05 17:01:08 +05303137 return dsi_vc_send_long(dsidev, channel, MIPI_DSI_NULL_PACKET, NULL,
3138 0, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003139}
3140EXPORT_SYMBOL(dsi_vc_send_null);
3141
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303142static int dsi_vc_write_nosync_common(struct omap_dss_device *dssdev,
3143 int channel, u8 *data, int len, enum dss_dsi_content_type type)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003144{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303145 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003146 int r;
3147
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303148 if (len == 0) {
3149 BUG_ON(type == DSS_DSI_CONTENT_DCS);
Archit Taneja7a7c48f2011-08-25 18:25:03 +05303150 r = dsi_vc_send_short(dsidev, channel,
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303151 MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM, 0, 0);
3152 } else if (len == 1) {
3153 r = dsi_vc_send_short(dsidev, channel,
3154 type == DSS_DSI_CONTENT_GENERIC ?
3155 MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM :
Archit Taneja7a7c48f2011-08-25 18:25:03 +05303156 MIPI_DSI_DCS_SHORT_WRITE, data[0], 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003157 } else if (len == 2) {
Archit Taneja7a7c48f2011-08-25 18:25:03 +05303158 r = dsi_vc_send_short(dsidev, channel,
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303159 type == DSS_DSI_CONTENT_GENERIC ?
3160 MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM :
Archit Taneja7a7c48f2011-08-25 18:25:03 +05303161 MIPI_DSI_DCS_SHORT_WRITE_PARAM,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003162 data[0] | (data[1] << 8), 0);
3163 } else {
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303164 r = dsi_vc_send_long(dsidev, channel,
3165 type == DSS_DSI_CONTENT_GENERIC ?
3166 MIPI_DSI_GENERIC_LONG_WRITE :
3167 MIPI_DSI_DCS_LONG_WRITE, data, len, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003168 }
3169
3170 return r;
3171}
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303172
3173int dsi_vc_dcs_write_nosync(struct omap_dss_device *dssdev, int channel,
3174 u8 *data, int len)
3175{
3176 return dsi_vc_write_nosync_common(dssdev, channel, data, len,
3177 DSS_DSI_CONTENT_DCS);
3178}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003179EXPORT_SYMBOL(dsi_vc_dcs_write_nosync);
3180
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303181int dsi_vc_generic_write_nosync(struct omap_dss_device *dssdev, int channel,
3182 u8 *data, int len)
3183{
3184 return dsi_vc_write_nosync_common(dssdev, channel, data, len,
3185 DSS_DSI_CONTENT_GENERIC);
3186}
3187EXPORT_SYMBOL(dsi_vc_generic_write_nosync);
3188
3189static int dsi_vc_write_common(struct omap_dss_device *dssdev, int channel,
3190 u8 *data, int len, enum dss_dsi_content_type type)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003191{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303192 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003193 int r;
3194
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303195 r = dsi_vc_write_nosync_common(dssdev, channel, data, len, type);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003196 if (r)
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003197 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003198
Archit Taneja1ffefe72011-05-12 17:26:24 +05303199 r = dsi_vc_send_bta_sync(dssdev, channel);
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003200 if (r)
3201 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003202
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303203 /* RX_FIFO_NOT_EMPTY */
3204 if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
Tomi Valkeinenb63ac1e2010-04-09 13:20:57 +03003205 DSSERR("rx fifo not empty after write, dumping data:\n");
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303206 dsi_vc_flush_receive_data(dsidev, channel);
Tomi Valkeinenb63ac1e2010-04-09 13:20:57 +03003207 r = -EIO;
3208 goto err;
3209 }
3210
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003211 return 0;
3212err:
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303213 DSSERR("dsi_vc_write_common(ch %d, cmd 0x%02x, len %d) failed\n",
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003214 channel, data[0], len);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003215 return r;
3216}
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303217
3218int dsi_vc_dcs_write(struct omap_dss_device *dssdev, int channel, u8 *data,
3219 int len)
3220{
3221 return dsi_vc_write_common(dssdev, channel, data, len,
3222 DSS_DSI_CONTENT_DCS);
3223}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003224EXPORT_SYMBOL(dsi_vc_dcs_write);
3225
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303226int dsi_vc_generic_write(struct omap_dss_device *dssdev, int channel, u8 *data,
3227 int len)
3228{
3229 return dsi_vc_write_common(dssdev, channel, data, len,
3230 DSS_DSI_CONTENT_GENERIC);
3231}
3232EXPORT_SYMBOL(dsi_vc_generic_write);
3233
Archit Taneja1ffefe72011-05-12 17:26:24 +05303234int dsi_vc_dcs_write_0(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd)
Tomi Valkeinen828c48f2009-12-16 14:53:15 +02003235{
Archit Taneja1ffefe72011-05-12 17:26:24 +05303236 return dsi_vc_dcs_write(dssdev, channel, &dcs_cmd, 1);
Tomi Valkeinen828c48f2009-12-16 14:53:15 +02003237}
3238EXPORT_SYMBOL(dsi_vc_dcs_write_0);
3239
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303240int dsi_vc_generic_write_0(struct omap_dss_device *dssdev, int channel)
3241{
3242 return dsi_vc_generic_write(dssdev, channel, NULL, 0);
3243}
3244EXPORT_SYMBOL(dsi_vc_generic_write_0);
3245
Archit Taneja1ffefe72011-05-12 17:26:24 +05303246int dsi_vc_dcs_write_1(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
3247 u8 param)
Tomi Valkeinen828c48f2009-12-16 14:53:15 +02003248{
3249 u8 buf[2];
3250 buf[0] = dcs_cmd;
3251 buf[1] = param;
Archit Taneja1ffefe72011-05-12 17:26:24 +05303252 return dsi_vc_dcs_write(dssdev, channel, buf, 2);
Tomi Valkeinen828c48f2009-12-16 14:53:15 +02003253}
3254EXPORT_SYMBOL(dsi_vc_dcs_write_1);
3255
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303256int dsi_vc_generic_write_1(struct omap_dss_device *dssdev, int channel,
3257 u8 param)
3258{
3259 return dsi_vc_generic_write(dssdev, channel, &param, 1);
3260}
3261EXPORT_SYMBOL(dsi_vc_generic_write_1);
3262
3263int dsi_vc_generic_write_2(struct omap_dss_device *dssdev, int channel,
3264 u8 param1, u8 param2)
3265{
3266 u8 buf[2];
3267 buf[0] = param1;
3268 buf[1] = param2;
3269 return dsi_vc_generic_write(dssdev, channel, buf, 2);
3270}
3271EXPORT_SYMBOL(dsi_vc_generic_write_2);
3272
Archit Tanejab8509752011-08-30 15:48:23 +05303273static int dsi_vc_dcs_send_read_request(struct omap_dss_device *dssdev,
3274 int channel, u8 dcs_cmd)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003275{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303276 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303277 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejab8509752011-08-30 15:48:23 +05303278 int r;
3279
3280 if (dsi->debug_read)
3281 DSSDBG("dsi_vc_dcs_send_read_request(ch%d, dcs_cmd %x)\n",
3282 channel, dcs_cmd);
3283
3284 r = dsi_vc_send_short(dsidev, channel, MIPI_DSI_DCS_READ, dcs_cmd, 0);
3285 if (r) {
3286 DSSERR("dsi_vc_dcs_send_read_request(ch %d, cmd 0x%02x)"
3287 " failed\n", channel, dcs_cmd);
3288 return r;
3289 }
3290
3291 return 0;
3292}
3293
Archit Tanejab3b89c02011-08-30 16:07:39 +05303294static int dsi_vc_generic_send_read_request(struct omap_dss_device *dssdev,
3295 int channel, u8 *reqdata, int reqlen)
3296{
3297 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
3298 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
3299 u16 data;
3300 u8 data_type;
3301 int r;
3302
3303 if (dsi->debug_read)
3304 DSSDBG("dsi_vc_generic_send_read_request(ch %d, reqlen %d)\n",
3305 channel, reqlen);
3306
3307 if (reqlen == 0) {
3308 data_type = MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM;
3309 data = 0;
3310 } else if (reqlen == 1) {
3311 data_type = MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM;
3312 data = reqdata[0];
3313 } else if (reqlen == 2) {
3314 data_type = MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM;
3315 data = reqdata[0] | (reqdata[1] << 8);
3316 } else {
3317 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03003318 return -EINVAL;
Archit Tanejab3b89c02011-08-30 16:07:39 +05303319 }
3320
3321 r = dsi_vc_send_short(dsidev, channel, data_type, data, 0);
3322 if (r) {
3323 DSSERR("dsi_vc_generic_send_read_request(ch %d, reqlen %d)"
3324 " failed\n", channel, reqlen);
3325 return r;
3326 }
3327
3328 return 0;
3329}
3330
3331static int dsi_vc_read_rx_fifo(struct platform_device *dsidev, int channel,
3332 u8 *buf, int buflen, enum dss_dsi_content_type type)
Archit Tanejab8509752011-08-30 15:48:23 +05303333{
3334 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003335 u32 val;
3336 u8 dt;
3337 int r;
3338
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003339 /* RX_FIFO_NOT_EMPTY */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303340 if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20) == 0) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003341 DSSERR("RX fifo empty when trying to read.\n");
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003342 r = -EIO;
3343 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003344 }
3345
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303346 val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel));
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303347 if (dsi->debug_read)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003348 DSSDBG("\theader: %08x\n", val);
3349 dt = FLD_GET(val, 5, 0);
Archit Taneja7a7c48f2011-08-25 18:25:03 +05303350 if (dt == MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003351 u16 err = FLD_GET(val, 23, 8);
3352 dsi_show_rx_ack_with_err(err);
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003353 r = -EIO;
3354 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003355
Archit Tanejab3b89c02011-08-30 16:07:39 +05303356 } else if (dt == (type == DSS_DSI_CONTENT_GENERIC ?
3357 MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_1BYTE :
3358 MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003359 u8 data = FLD_GET(val, 15, 8);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303360 if (dsi->debug_read)
Archit Tanejab3b89c02011-08-30 16:07:39 +05303361 DSSDBG("\t%s short response, 1 byte: %02x\n",
3362 type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" :
3363 "DCS", data);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003364
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003365 if (buflen < 1) {
3366 r = -EIO;
3367 goto err;
3368 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003369
3370 buf[0] = data;
3371
3372 return 1;
Archit Tanejab3b89c02011-08-30 16:07:39 +05303373 } else if (dt == (type == DSS_DSI_CONTENT_GENERIC ?
3374 MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_2BYTE :
3375 MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003376 u16 data = FLD_GET(val, 23, 8);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303377 if (dsi->debug_read)
Archit Tanejab3b89c02011-08-30 16:07:39 +05303378 DSSDBG("\t%s short response, 2 byte: %04x\n",
3379 type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" :
3380 "DCS", data);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003381
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003382 if (buflen < 2) {
3383 r = -EIO;
3384 goto err;
3385 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003386
3387 buf[0] = data & 0xff;
3388 buf[1] = (data >> 8) & 0xff;
3389
3390 return 2;
Archit Tanejab3b89c02011-08-30 16:07:39 +05303391 } else if (dt == (type == DSS_DSI_CONTENT_GENERIC ?
3392 MIPI_DSI_RX_GENERIC_LONG_READ_RESPONSE :
3393 MIPI_DSI_RX_DCS_LONG_READ_RESPONSE)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003394 int w;
3395 int len = FLD_GET(val, 23, 8);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303396 if (dsi->debug_read)
Archit Tanejab3b89c02011-08-30 16:07:39 +05303397 DSSDBG("\t%s long response, len %d\n",
3398 type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" :
3399 "DCS", len);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003400
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003401 if (len > buflen) {
3402 r = -EIO;
3403 goto err;
3404 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003405
3406 /* two byte checksum ends the packet, not included in len */
3407 for (w = 0; w < len + 2;) {
3408 int b;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303409 val = dsi_read_reg(dsidev,
3410 DSI_VC_SHORT_PACKET_HEADER(channel));
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303411 if (dsi->debug_read)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003412 DSSDBG("\t\t%02x %02x %02x %02x\n",
3413 (val >> 0) & 0xff,
3414 (val >> 8) & 0xff,
3415 (val >> 16) & 0xff,
3416 (val >> 24) & 0xff);
3417
3418 for (b = 0; b < 4; ++b) {
3419 if (w < len)
3420 buf[w] = (val >> (b * 8)) & 0xff;
3421 /* we discard the 2 byte checksum */
3422 ++w;
3423 }
3424 }
3425
3426 return len;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003427 } else {
3428 DSSERR("\tunknown datatype 0x%02x\n", dt);
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003429 r = -EIO;
3430 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003431 }
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003432
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003433err:
Archit Tanejab3b89c02011-08-30 16:07:39 +05303434 DSSERR("dsi_vc_read_rx_fifo(ch %d type %s) failed\n", channel,
3435 type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" : "DCS");
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003436
Archit Tanejab8509752011-08-30 15:48:23 +05303437 return r;
3438}
3439
3440int dsi_vc_dcs_read(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
3441 u8 *buf, int buflen)
3442{
3443 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
3444 int r;
3445
3446 r = dsi_vc_dcs_send_read_request(dssdev, channel, dcs_cmd);
3447 if (r)
3448 goto err;
3449
3450 r = dsi_vc_send_bta_sync(dssdev, channel);
3451 if (r)
3452 goto err;
3453
Archit Tanejab3b89c02011-08-30 16:07:39 +05303454 r = dsi_vc_read_rx_fifo(dsidev, channel, buf, buflen,
3455 DSS_DSI_CONTENT_DCS);
Archit Tanejab8509752011-08-30 15:48:23 +05303456 if (r < 0)
3457 goto err;
3458
3459 if (r != buflen) {
3460 r = -EIO;
3461 goto err;
3462 }
3463
3464 return 0;
3465err:
3466 DSSERR("dsi_vc_dcs_read(ch %d, cmd 0x%02x) failed\n", channel, dcs_cmd);
3467 return r;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003468}
3469EXPORT_SYMBOL(dsi_vc_dcs_read);
3470
Archit Tanejab3b89c02011-08-30 16:07:39 +05303471static int dsi_vc_generic_read(struct omap_dss_device *dssdev, int channel,
3472 u8 *reqdata, int reqlen, u8 *buf, int buflen)
3473{
3474 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
3475 int r;
3476
3477 r = dsi_vc_generic_send_read_request(dssdev, channel, reqdata, reqlen);
3478 if (r)
3479 return r;
3480
3481 r = dsi_vc_send_bta_sync(dssdev, channel);
3482 if (r)
3483 return r;
3484
3485 r = dsi_vc_read_rx_fifo(dsidev, channel, buf, buflen,
3486 DSS_DSI_CONTENT_GENERIC);
3487 if (r < 0)
3488 return r;
3489
3490 if (r != buflen) {
3491 r = -EIO;
3492 return r;
3493 }
3494
3495 return 0;
3496}
3497
3498int dsi_vc_generic_read_0(struct omap_dss_device *dssdev, int channel, u8 *buf,
3499 int buflen)
3500{
3501 int r;
3502
3503 r = dsi_vc_generic_read(dssdev, channel, NULL, 0, buf, buflen);
3504 if (r) {
3505 DSSERR("dsi_vc_generic_read_0(ch %d) failed\n", channel);
3506 return r;
3507 }
3508
3509 return 0;
3510}
3511EXPORT_SYMBOL(dsi_vc_generic_read_0);
3512
3513int dsi_vc_generic_read_1(struct omap_dss_device *dssdev, int channel, u8 param,
3514 u8 *buf, int buflen)
3515{
3516 int r;
3517
3518 r = dsi_vc_generic_read(dssdev, channel, &param, 1, buf, buflen);
3519 if (r) {
3520 DSSERR("dsi_vc_generic_read_1(ch %d) failed\n", channel);
3521 return r;
3522 }
3523
3524 return 0;
3525}
3526EXPORT_SYMBOL(dsi_vc_generic_read_1);
3527
3528int dsi_vc_generic_read_2(struct omap_dss_device *dssdev, int channel,
3529 u8 param1, u8 param2, u8 *buf, int buflen)
3530{
3531 int r;
3532 u8 reqdata[2];
3533
3534 reqdata[0] = param1;
3535 reqdata[1] = param2;
3536
3537 r = dsi_vc_generic_read(dssdev, channel, reqdata, 2, buf, buflen);
3538 if (r) {
3539 DSSERR("dsi_vc_generic_read_2(ch %d) failed\n", channel);
3540 return r;
3541 }
3542
3543 return 0;
3544}
3545EXPORT_SYMBOL(dsi_vc_generic_read_2);
3546
Archit Taneja1ffefe72011-05-12 17:26:24 +05303547int dsi_vc_set_max_rx_packet_size(struct omap_dss_device *dssdev, int channel,
3548 u16 len)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003549{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303550 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
3551
Archit Taneja7a7c48f2011-08-25 18:25:03 +05303552 return dsi_vc_send_short(dsidev, channel,
3553 MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE, len, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003554}
3555EXPORT_SYMBOL(dsi_vc_set_max_rx_packet_size);
3556
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303557static int dsi_enter_ulps(struct platform_device *dsidev)
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003558{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303559 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003560 DECLARE_COMPLETION_ONSTACK(completion);
Tomi Valkeinen522a0c22011-10-13 16:18:52 +03003561 int r, i;
3562 unsigned mask;
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003563
3564 DSSDBGF();
3565
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303566 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003567
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303568 WARN_ON(dsi->ulps_enabled);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003569
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303570 if (dsi->ulps_enabled)
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003571 return 0;
3572
Tomi Valkeinen6cc78aa2011-10-13 19:22:43 +03003573 /* DDR_CLK_ALWAYS_ON */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303574 if (REG_GET(dsidev, DSI_CLK_CTRL, 13, 13)) {
Tomi Valkeinen6cc78aa2011-10-13 19:22:43 +03003575 dsi_if_enable(dsidev, 0);
3576 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 13, 13);
3577 dsi_if_enable(dsidev, 1);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003578 }
3579
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303580 dsi_sync_vc(dsidev, 0);
3581 dsi_sync_vc(dsidev, 1);
3582 dsi_sync_vc(dsidev, 2);
3583 dsi_sync_vc(dsidev, 3);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003584
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303585 dsi_force_tx_stop_mode_io(dsidev);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003586
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303587 dsi_vc_enable(dsidev, 0, false);
3588 dsi_vc_enable(dsidev, 1, false);
3589 dsi_vc_enable(dsidev, 2, false);
3590 dsi_vc_enable(dsidev, 3, false);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003591
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303592 if (REG_GET(dsidev, DSI_COMPLEXIO_CFG2, 16, 16)) { /* HS_BUSY */
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003593 DSSERR("HS busy when enabling ULPS\n");
3594 return -EIO;
3595 }
3596
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303597 if (REG_GET(dsidev, DSI_COMPLEXIO_CFG2, 17, 17)) { /* LP_BUSY */
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003598 DSSERR("LP busy when enabling ULPS\n");
3599 return -EIO;
3600 }
3601
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303602 r = dsi_register_isr_cio(dsidev, dsi_completion_handler, &completion,
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003603 DSI_CIO_IRQ_ULPSACTIVENOT_ALL0);
3604 if (r)
3605 return r;
3606
Tomi Valkeinen522a0c22011-10-13 16:18:52 +03003607 mask = 0;
3608
3609 for (i = 0; i < dsi->num_lanes_supported; ++i) {
3610 if (dsi->lanes[i].function == DSI_LANE_UNUSED)
3611 continue;
3612 mask |= 1 << i;
3613 }
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003614 /* Assert TxRequestEsc for data lanes and TxUlpsClk for clk lane */
3615 /* LANEx_ULPS_SIG2 */
Tomi Valkeinen522a0c22011-10-13 16:18:52 +03003616 REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG2, mask, 9, 5);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003617
Tomi Valkeinena702c852011-10-12 10:10:21 +03003618 /* flush posted write and wait for SCP interface to finish the write */
3619 dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG2);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003620
3621 if (wait_for_completion_timeout(&completion,
3622 msecs_to_jiffies(1000)) == 0) {
3623 DSSERR("ULPS enable timeout\n");
3624 r = -EIO;
3625 goto err;
3626 }
3627
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303628 dsi_unregister_isr_cio(dsidev, dsi_completion_handler, &completion,
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003629 DSI_CIO_IRQ_ULPSACTIVENOT_ALL0);
3630
Tomi Valkeinen8ef0e612011-05-31 16:55:47 +03003631 /* Reset LANEx_ULPS_SIG2 */
Tomi Valkeinen522a0c22011-10-13 16:18:52 +03003632 REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG2, 0, 9, 5);
Tomi Valkeinen8ef0e612011-05-31 16:55:47 +03003633
Tomi Valkeinena702c852011-10-12 10:10:21 +03003634 /* flush posted write and wait for SCP interface to finish the write */
3635 dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG2);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003636
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303637 dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_ULPS);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003638
3639 dsi_if_enable(dsidev, false);
3640
3641 dsi->ulps_enabled = true;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303642
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003643 return 0;
3644
3645err:
3646 dsi_unregister_isr_cio(dsidev, dsi_completion_handler, &completion,
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303647 DSI_CIO_IRQ_ULPSACTIVENOT_ALL0);
3648 return r;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003649}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003650
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003651static void dsi_set_lp_rx_timeout(struct platform_device *dsidev,
3652 unsigned ticks, bool x4, bool x16)
3653{
3654 unsigned long fck;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003655 unsigned long total_ticks;
3656 u32 r;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303657
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003658 BUG_ON(ticks > 0x1fff);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303659
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003660 /* ticks in DSI_FCK */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003661 fck = dsi_fclk_rate(dsidev);
3662
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003663 r = dsi_read_reg(dsidev, DSI_TIMING2);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303664 r = FLD_MOD(r, 1, 15, 15); /* LP_RX_TO */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003665 r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* LP_RX_TO_X16 */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003666 r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* LP_RX_TO_X4 */
3667 r = FLD_MOD(r, ticks, 12, 0); /* LP_RX_COUNTER */
3668 dsi_write_reg(dsidev, DSI_TIMING2, r);
3669
3670 total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
3671
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003672 DSSDBG("LP_RX_TO %lu ticks (%#x%s%s) = %lu ns\n",
3673 total_ticks,
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303674 ticks, x4 ? " x4" : "", x16 ? " x16" : "",
3675 (total_ticks * 1000) / (fck / 1000 / 1000));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003676}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003677
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003678static void dsi_set_ta_timeout(struct platform_device *dsidev, unsigned ticks,
3679 bool x8, bool x16)
3680{
3681 unsigned long fck;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003682 unsigned long total_ticks;
3683 u32 r;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303684
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003685 BUG_ON(ticks > 0x1fff);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303686
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003687 /* ticks in DSI_FCK */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003688 fck = dsi_fclk_rate(dsidev);
3689
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003690 r = dsi_read_reg(dsidev, DSI_TIMING1);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303691 r = FLD_MOD(r, 1, 31, 31); /* TA_TO */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003692 r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* TA_TO_X16 */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003693 r = FLD_MOD(r, x8 ? 1 : 0, 29, 29); /* TA_TO_X8 */
3694 r = FLD_MOD(r, ticks, 28, 16); /* TA_TO_COUNTER */
3695 dsi_write_reg(dsidev, DSI_TIMING1, r);
3696
3697 total_ticks = ticks * (x16 ? 16 : 1) * (x8 ? 8 : 1);
3698
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003699 DSSDBG("TA_TO %lu ticks (%#x%s%s) = %lu ns\n",
3700 total_ticks,
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303701 ticks, x8 ? " x8" : "", x16 ? " x16" : "",
3702 (total_ticks * 1000) / (fck / 1000 / 1000));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003703}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003704
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003705static void dsi_set_stop_state_counter(struct platform_device *dsidev,
3706 unsigned ticks, bool x4, bool x16)
3707{
3708 unsigned long fck;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003709 unsigned long total_ticks;
3710 u32 r;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303711
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003712 BUG_ON(ticks > 0x1fff);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303713
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003714 /* ticks in DSI_FCK */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003715 fck = dsi_fclk_rate(dsidev);
3716
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003717 r = dsi_read_reg(dsidev, DSI_TIMING1);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303718 r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003719 r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* STOP_STATE_X16_IO */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003720 r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* STOP_STATE_X4_IO */
3721 r = FLD_MOD(r, ticks, 12, 0); /* STOP_STATE_COUNTER_IO */
3722 dsi_write_reg(dsidev, DSI_TIMING1, r);
3723
3724 total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
3725
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003726 DSSDBG("STOP_STATE_COUNTER %lu ticks (%#x%s%s) = %lu ns\n",
3727 total_ticks,
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303728 ticks, x4 ? " x4" : "", x16 ? " x16" : "",
3729 (total_ticks * 1000) / (fck / 1000 / 1000));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003730}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003731
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003732static void dsi_set_hs_tx_timeout(struct platform_device *dsidev,
3733 unsigned ticks, bool x4, bool x16)
3734{
3735 unsigned long fck;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003736 unsigned long total_ticks;
3737 u32 r;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303738
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003739 BUG_ON(ticks > 0x1fff);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303740
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003741 /* ticks in TxByteClkHS */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003742 fck = dsi_get_txbyteclkhs(dsidev);
3743
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003744 r = dsi_read_reg(dsidev, DSI_TIMING2);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303745 r = FLD_MOD(r, 1, 31, 31); /* HS_TX_TO */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003746 r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* HS_TX_TO_X16 */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003747 r = FLD_MOD(r, x4 ? 1 : 0, 29, 29); /* HS_TX_TO_X8 (4 really) */
3748 r = FLD_MOD(r, ticks, 28, 16); /* HS_TX_TO_COUNTER */
3749 dsi_write_reg(dsidev, DSI_TIMING2, r);
3750
3751 total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
3752
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003753 DSSDBG("HS_TX_TO %lu ticks (%#x%s%s) = %lu ns\n",
3754 total_ticks,
3755 ticks, x4 ? " x4" : "", x16 ? " x16" : "",
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303756 (total_ticks * 1000) / (fck / 1000 / 1000));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003757}
Archit Taneja8af6ff02011-09-05 16:48:27 +05303758
3759static void dsi_config_vp_num_line_buffers(struct omap_dss_device *dssdev)
3760{
3761 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejadca2b152012-08-16 18:02:00 +05303762 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Taneja8af6ff02011-09-05 16:48:27 +05303763 int num_line_buffers;
3764
Archit Tanejadca2b152012-08-16 18:02:00 +05303765 if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
Archit Tanejae67458a2012-08-13 14:17:30 +05303766 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Taneja02c39602012-08-10 15:01:33 +05303767 int bpp = dsi_get_pixel_size(dsi->pix_fmt);
Archit Taneja8af6ff02011-09-05 16:48:27 +05303768 unsigned line_buf_size = dsi_get_line_buf_size(dsidev);
Archit Tanejae67458a2012-08-13 14:17:30 +05303769 struct omap_video_timings *timings = &dsi->timings;
Archit Taneja8af6ff02011-09-05 16:48:27 +05303770 /*
3771 * Don't use line buffers if width is greater than the video
3772 * port's line buffer size
3773 */
3774 if (line_buf_size <= timings->x_res * bpp / 8)
3775 num_line_buffers = 0;
3776 else
3777 num_line_buffers = 2;
3778 } else {
3779 /* Use maximum number of line buffers in command mode */
3780 num_line_buffers = 2;
3781 }
3782
3783 /* LINE_BUFFER */
3784 REG_FLD_MOD(dsidev, DSI_CTRL, num_line_buffers, 13, 12);
3785}
3786
3787static void dsi_config_vp_sync_events(struct omap_dss_device *dssdev)
3788{
3789 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Taneja0b3ffe32012-08-13 22:13:39 +05303790 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
3791 bool vsync_end = dsi->vm_timings.vp_vsync_end;
3792 bool hsync_end = dsi->vm_timings.vp_hsync_end;
Archit Taneja8af6ff02011-09-05 16:48:27 +05303793 u32 r;
3794
3795 r = dsi_read_reg(dsidev, DSI_CTRL);
Archit Tanejabd5a7b12012-06-26 12:38:31 +05303796 r = FLD_MOD(r, 1, 9, 9); /* VP_DE_POL */
3797 r = FLD_MOD(r, 1, 10, 10); /* VP_HSYNC_POL */
3798 r = FLD_MOD(r, 1, 11, 11); /* VP_VSYNC_POL */
Archit Taneja8af6ff02011-09-05 16:48:27 +05303799 r = FLD_MOD(r, 1, 15, 15); /* VP_VSYNC_START */
3800 r = FLD_MOD(r, vsync_end, 16, 16); /* VP_VSYNC_END */
3801 r = FLD_MOD(r, 1, 17, 17); /* VP_HSYNC_START */
3802 r = FLD_MOD(r, hsync_end, 18, 18); /* VP_HSYNC_END */
3803 dsi_write_reg(dsidev, DSI_CTRL, r);
3804}
3805
3806static void dsi_config_blanking_modes(struct omap_dss_device *dssdev)
3807{
3808 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Taneja0b3ffe32012-08-13 22:13:39 +05303809 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
3810 int blanking_mode = dsi->vm_timings.blanking_mode;
3811 int hfp_blanking_mode = dsi->vm_timings.hfp_blanking_mode;
3812 int hbp_blanking_mode = dsi->vm_timings.hbp_blanking_mode;
3813 int hsa_blanking_mode = dsi->vm_timings.hsa_blanking_mode;
Archit Taneja8af6ff02011-09-05 16:48:27 +05303814 u32 r;
3815
3816 /*
3817 * 0 = TX FIFO packets sent or LPS in corresponding blanking periods
3818 * 1 = Long blanking packets are sent in corresponding blanking periods
3819 */
3820 r = dsi_read_reg(dsidev, DSI_CTRL);
3821 r = FLD_MOD(r, blanking_mode, 20, 20); /* BLANKING_MODE */
3822 r = FLD_MOD(r, hfp_blanking_mode, 21, 21); /* HFP_BLANKING */
3823 r = FLD_MOD(r, hbp_blanking_mode, 22, 22); /* HBP_BLANKING */
3824 r = FLD_MOD(r, hsa_blanking_mode, 23, 23); /* HSA_BLANKING */
3825 dsi_write_reg(dsidev, DSI_CTRL, r);
3826}
3827
Archit Taneja6f28c292012-05-15 11:32:18 +05303828/*
3829 * According to section 'HS Command Mode Interleaving' in OMAP TRM, Scenario 3
3830 * results in maximum transition time for data and clock lanes to enter and
3831 * exit HS mode. Hence, this is the scenario where the least amount of command
3832 * mode data can be interleaved. We program the minimum amount of TXBYTECLKHS
3833 * clock cycles that can be used to interleave command mode data in HS so that
3834 * all scenarios are satisfied.
3835 */
3836static int dsi_compute_interleave_hs(int blank, bool ddr_alwon, int enter_hs,
3837 int exit_hs, int exiths_clk, int ddr_pre, int ddr_post)
3838{
3839 int transition;
3840
3841 /*
3842 * If DDR_CLK_ALWAYS_ON is set, we need to consider HS mode transition
3843 * time of data lanes only, if it isn't set, we need to consider HS
3844 * transition time of both data and clock lanes. HS transition time
3845 * of Scenario 3 is considered.
3846 */
3847 if (ddr_alwon) {
3848 transition = enter_hs + exit_hs + max(enter_hs, 2) + 1;
3849 } else {
3850 int trans1, trans2;
3851 trans1 = ddr_pre + enter_hs + exit_hs + max(enter_hs, 2) + 1;
3852 trans2 = ddr_pre + enter_hs + exiths_clk + ddr_post + ddr_pre +
3853 enter_hs + 1;
3854 transition = max(trans1, trans2);
3855 }
3856
3857 return blank > transition ? blank - transition : 0;
3858}
3859
3860/*
3861 * According to section 'LP Command Mode Interleaving' in OMAP TRM, Scenario 1
3862 * results in maximum transition time for data lanes to enter and exit LP mode.
3863 * Hence, this is the scenario where the least amount of command mode data can
3864 * be interleaved. We program the minimum amount of bytes that can be
3865 * interleaved in LP so that all scenarios are satisfied.
3866 */
3867static int dsi_compute_interleave_lp(int blank, int enter_hs, int exit_hs,
3868 int lp_clk_div, int tdsi_fclk)
3869{
3870 int trans_lp; /* time required for a LP transition, in TXBYTECLKHS */
3871 int tlp_avail; /* time left for interleaving commands, in CLKIN4DDR */
3872 int ttxclkesc; /* period of LP transmit escape clock, in CLKIN4DDR */
3873 int thsbyte_clk = 16; /* Period of TXBYTECLKHS clock, in CLKIN4DDR */
3874 int lp_inter; /* cmd mode data that can be interleaved, in bytes */
3875
3876 /* maximum LP transition time according to Scenario 1 */
3877 trans_lp = exit_hs + max(enter_hs, 2) + 1;
3878
3879 /* CLKIN4DDR = 16 * TXBYTECLKHS */
3880 tlp_avail = thsbyte_clk * (blank - trans_lp);
3881
Archit Taneja2e063c32012-06-04 13:36:34 +05303882 ttxclkesc = tdsi_fclk * lp_clk_div;
Archit Taneja6f28c292012-05-15 11:32:18 +05303883
3884 lp_inter = ((tlp_avail - 8 * thsbyte_clk - 5 * tdsi_fclk) / ttxclkesc -
3885 26) / 16;
3886
3887 return max(lp_inter, 0);
3888}
3889
3890static void dsi_config_cmd_mode_interleaving(struct omap_dss_device *dssdev)
3891{
3892 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
3893 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
3894 int blanking_mode;
3895 int hfp_blanking_mode, hbp_blanking_mode, hsa_blanking_mode;
3896 int hsa, hfp, hbp, width_bytes, bllp, lp_clk_div;
3897 int ddr_clk_pre, ddr_clk_post, enter_hs_mode_lat, exit_hs_mode_lat;
3898 int tclk_trail, ths_exit, exiths_clk;
3899 bool ddr_alwon;
Archit Tanejae67458a2012-08-13 14:17:30 +05303900 struct omap_video_timings *timings = &dsi->timings;
Archit Taneja02c39602012-08-10 15:01:33 +05303901 int bpp = dsi_get_pixel_size(dsi->pix_fmt);
Archit Taneja6f28c292012-05-15 11:32:18 +05303902 int ndl = dsi->num_lanes_used - 1;
3903 int dsi_fclk_hsdiv = dssdev->clocks.dsi.regm_dsi + 1;
3904 int hsa_interleave_hs = 0, hsa_interleave_lp = 0;
3905 int hfp_interleave_hs = 0, hfp_interleave_lp = 0;
3906 int hbp_interleave_hs = 0, hbp_interleave_lp = 0;
3907 int bl_interleave_hs = 0, bl_interleave_lp = 0;
3908 u32 r;
3909
3910 r = dsi_read_reg(dsidev, DSI_CTRL);
3911 blanking_mode = FLD_GET(r, 20, 20);
3912 hfp_blanking_mode = FLD_GET(r, 21, 21);
3913 hbp_blanking_mode = FLD_GET(r, 22, 22);
3914 hsa_blanking_mode = FLD_GET(r, 23, 23);
3915
3916 r = dsi_read_reg(dsidev, DSI_VM_TIMING1);
3917 hbp = FLD_GET(r, 11, 0);
3918 hfp = FLD_GET(r, 23, 12);
3919 hsa = FLD_GET(r, 31, 24);
3920
3921 r = dsi_read_reg(dsidev, DSI_CLK_TIMING);
3922 ddr_clk_post = FLD_GET(r, 7, 0);
3923 ddr_clk_pre = FLD_GET(r, 15, 8);
3924
3925 r = dsi_read_reg(dsidev, DSI_VM_TIMING7);
3926 exit_hs_mode_lat = FLD_GET(r, 15, 0);
3927 enter_hs_mode_lat = FLD_GET(r, 31, 16);
3928
3929 r = dsi_read_reg(dsidev, DSI_CLK_CTRL);
3930 lp_clk_div = FLD_GET(r, 12, 0);
3931 ddr_alwon = FLD_GET(r, 13, 13);
3932
3933 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0);
3934 ths_exit = FLD_GET(r, 7, 0);
3935
3936 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1);
3937 tclk_trail = FLD_GET(r, 15, 8);
3938
3939 exiths_clk = ths_exit + tclk_trail;
3940
3941 width_bytes = DIV_ROUND_UP(timings->x_res * bpp, 8);
3942 bllp = hbp + hfp + hsa + DIV_ROUND_UP(width_bytes + 6, ndl);
3943
3944 if (!hsa_blanking_mode) {
3945 hsa_interleave_hs = dsi_compute_interleave_hs(hsa, ddr_alwon,
3946 enter_hs_mode_lat, exit_hs_mode_lat,
3947 exiths_clk, ddr_clk_pre, ddr_clk_post);
3948 hsa_interleave_lp = dsi_compute_interleave_lp(hsa,
3949 enter_hs_mode_lat, exit_hs_mode_lat,
3950 lp_clk_div, dsi_fclk_hsdiv);
3951 }
3952
3953 if (!hfp_blanking_mode) {
3954 hfp_interleave_hs = dsi_compute_interleave_hs(hfp, ddr_alwon,
3955 enter_hs_mode_lat, exit_hs_mode_lat,
3956 exiths_clk, ddr_clk_pre, ddr_clk_post);
3957 hfp_interleave_lp = dsi_compute_interleave_lp(hfp,
3958 enter_hs_mode_lat, exit_hs_mode_lat,
3959 lp_clk_div, dsi_fclk_hsdiv);
3960 }
3961
3962 if (!hbp_blanking_mode) {
3963 hbp_interleave_hs = dsi_compute_interleave_hs(hbp, ddr_alwon,
3964 enter_hs_mode_lat, exit_hs_mode_lat,
3965 exiths_clk, ddr_clk_pre, ddr_clk_post);
3966
3967 hbp_interleave_lp = dsi_compute_interleave_lp(hbp,
3968 enter_hs_mode_lat, exit_hs_mode_lat,
3969 lp_clk_div, dsi_fclk_hsdiv);
3970 }
3971
3972 if (!blanking_mode) {
3973 bl_interleave_hs = dsi_compute_interleave_hs(bllp, ddr_alwon,
3974 enter_hs_mode_lat, exit_hs_mode_lat,
3975 exiths_clk, ddr_clk_pre, ddr_clk_post);
3976
3977 bl_interleave_lp = dsi_compute_interleave_lp(bllp,
3978 enter_hs_mode_lat, exit_hs_mode_lat,
3979 lp_clk_div, dsi_fclk_hsdiv);
3980 }
3981
3982 DSSDBG("DSI HS interleaving(TXBYTECLKHS) HSA %d, HFP %d, HBP %d, BLLP %d\n",
3983 hsa_interleave_hs, hfp_interleave_hs, hbp_interleave_hs,
3984 bl_interleave_hs);
3985
3986 DSSDBG("DSI LP interleaving(bytes) HSA %d, HFP %d, HBP %d, BLLP %d\n",
3987 hsa_interleave_lp, hfp_interleave_lp, hbp_interleave_lp,
3988 bl_interleave_lp);
3989
3990 r = dsi_read_reg(dsidev, DSI_VM_TIMING4);
3991 r = FLD_MOD(r, hsa_interleave_hs, 23, 16);
3992 r = FLD_MOD(r, hfp_interleave_hs, 15, 8);
3993 r = FLD_MOD(r, hbp_interleave_hs, 7, 0);
3994 dsi_write_reg(dsidev, DSI_VM_TIMING4, r);
3995
3996 r = dsi_read_reg(dsidev, DSI_VM_TIMING5);
3997 r = FLD_MOD(r, hsa_interleave_lp, 23, 16);
3998 r = FLD_MOD(r, hfp_interleave_lp, 15, 8);
3999 r = FLD_MOD(r, hbp_interleave_lp, 7, 0);
4000 dsi_write_reg(dsidev, DSI_VM_TIMING5, r);
4001
4002 r = dsi_read_reg(dsidev, DSI_VM_TIMING6);
4003 r = FLD_MOD(r, bl_interleave_hs, 31, 15);
4004 r = FLD_MOD(r, bl_interleave_lp, 16, 0);
4005 dsi_write_reg(dsidev, DSI_VM_TIMING6, r);
4006}
4007
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004008static int dsi_proto_config(struct omap_dss_device *dssdev)
4009{
4010 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Taneja02c39602012-08-10 15:01:33 +05304011 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004012 u32 r;
4013 int buswidth = 0;
4014
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304015 dsi_config_tx_fifo(dsidev, DSI_FIFO_SIZE_32,
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02004016 DSI_FIFO_SIZE_32,
4017 DSI_FIFO_SIZE_32,
4018 DSI_FIFO_SIZE_32);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004019
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304020 dsi_config_rx_fifo(dsidev, DSI_FIFO_SIZE_32,
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02004021 DSI_FIFO_SIZE_32,
4022 DSI_FIFO_SIZE_32,
4023 DSI_FIFO_SIZE_32);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004024
4025 /* XXX what values for the timeouts? */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304026 dsi_set_stop_state_counter(dsidev, 0x1000, false, false);
4027 dsi_set_ta_timeout(dsidev, 0x1fff, true, true);
4028 dsi_set_lp_rx_timeout(dsidev, 0x1fff, true, true);
4029 dsi_set_hs_tx_timeout(dsidev, 0x1fff, true, true);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004030
Archit Taneja02c39602012-08-10 15:01:33 +05304031 switch (dsi_get_pixel_size(dsi->pix_fmt)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004032 case 16:
4033 buswidth = 0;
4034 break;
4035 case 18:
4036 buswidth = 1;
4037 break;
4038 case 24:
4039 buswidth = 2;
4040 break;
4041 default:
4042 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03004043 return -EINVAL;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004044 }
4045
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304046 r = dsi_read_reg(dsidev, DSI_CTRL);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004047 r = FLD_MOD(r, 1, 1, 1); /* CS_RX_EN */
4048 r = FLD_MOD(r, 1, 2, 2); /* ECC_RX_EN */
4049 r = FLD_MOD(r, 1, 3, 3); /* TX_FIFO_ARBITRATION */
4050 r = FLD_MOD(r, 1, 4, 4); /* VP_CLK_RATIO, always 1, see errata*/
4051 r = FLD_MOD(r, buswidth, 7, 6); /* VP_DATA_BUS_WIDTH */
4052 r = FLD_MOD(r, 0, 8, 8); /* VP_CLK_POL */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004053 r = FLD_MOD(r, 1, 14, 14); /* TRIGGER_RESET_MODE */
4054 r = FLD_MOD(r, 1, 19, 19); /* EOT_ENABLE */
Archit Taneja9613c022011-03-22 06:33:36 -05004055 if (!dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC)) {
4056 r = FLD_MOD(r, 1, 24, 24); /* DCS_CMD_ENABLE */
4057 /* DCS_CMD_CODE, 1=start, 0=continue */
4058 r = FLD_MOD(r, 0, 25, 25);
4059 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004060
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304061 dsi_write_reg(dsidev, DSI_CTRL, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004062
Archit Taneja8af6ff02011-09-05 16:48:27 +05304063 dsi_config_vp_num_line_buffers(dssdev);
4064
Archit Tanejadca2b152012-08-16 18:02:00 +05304065 if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
Archit Taneja8af6ff02011-09-05 16:48:27 +05304066 dsi_config_vp_sync_events(dssdev);
4067 dsi_config_blanking_modes(dssdev);
Archit Taneja6f28c292012-05-15 11:32:18 +05304068 dsi_config_cmd_mode_interleaving(dssdev);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304069 }
4070
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304071 dsi_vc_initial_config(dsidev, 0);
4072 dsi_vc_initial_config(dsidev, 1);
4073 dsi_vc_initial_config(dsidev, 2);
4074 dsi_vc_initial_config(dsidev, 3);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004075
4076 return 0;
4077}
4078
4079static void dsi_proto_timings(struct omap_dss_device *dssdev)
4080{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304081 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Tomi Valkeinendb186442011-10-13 16:12:29 +03004082 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004083 unsigned tlpx, tclk_zero, tclk_prepare, tclk_trail;
4084 unsigned tclk_pre, tclk_post;
4085 unsigned ths_prepare, ths_prepare_ths_zero, ths_zero;
4086 unsigned ths_trail, ths_exit;
4087 unsigned ddr_clk_pre, ddr_clk_post;
4088 unsigned enter_hs_mode_lat, exit_hs_mode_lat;
4089 unsigned ths_eot;
Tomi Valkeinendb186442011-10-13 16:12:29 +03004090 int ndl = dsi->num_lanes_used - 1;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004091 u32 r;
4092
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304093 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004094 ths_prepare = FLD_GET(r, 31, 24);
4095 ths_prepare_ths_zero = FLD_GET(r, 23, 16);
4096 ths_zero = ths_prepare_ths_zero - ths_prepare;
4097 ths_trail = FLD_GET(r, 15, 8);
4098 ths_exit = FLD_GET(r, 7, 0);
4099
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304100 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004101 tlpx = FLD_GET(r, 22, 16) * 2;
4102 tclk_trail = FLD_GET(r, 15, 8);
4103 tclk_zero = FLD_GET(r, 7, 0);
4104
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304105 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG2);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004106 tclk_prepare = FLD_GET(r, 7, 0);
4107
4108 /* min 8*UI */
4109 tclk_pre = 20;
4110 /* min 60ns + 52*UI */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304111 tclk_post = ns2ddr(dsidev, 60) + 26;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004112
Archit Taneja8af6ff02011-09-05 16:48:27 +05304113 ths_eot = DIV_ROUND_UP(4, ndl);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004114
4115 ddr_clk_pre = DIV_ROUND_UP(tclk_pre + tlpx + tclk_zero + tclk_prepare,
4116 4);
4117 ddr_clk_post = DIV_ROUND_UP(tclk_post + ths_trail, 4) + ths_eot;
4118
4119 BUG_ON(ddr_clk_pre == 0 || ddr_clk_pre > 255);
4120 BUG_ON(ddr_clk_post == 0 || ddr_clk_post > 255);
4121
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304122 r = dsi_read_reg(dsidev, DSI_CLK_TIMING);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004123 r = FLD_MOD(r, ddr_clk_pre, 15, 8);
4124 r = FLD_MOD(r, ddr_clk_post, 7, 0);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304125 dsi_write_reg(dsidev, DSI_CLK_TIMING, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004126
4127 DSSDBG("ddr_clk_pre %u, ddr_clk_post %u\n",
4128 ddr_clk_pre,
4129 ddr_clk_post);
4130
4131 enter_hs_mode_lat = 1 + DIV_ROUND_UP(tlpx, 4) +
4132 DIV_ROUND_UP(ths_prepare, 4) +
4133 DIV_ROUND_UP(ths_zero + 3, 4);
4134
4135 exit_hs_mode_lat = DIV_ROUND_UP(ths_trail + ths_exit, 4) + 1 + ths_eot;
4136
4137 r = FLD_VAL(enter_hs_mode_lat, 31, 16) |
4138 FLD_VAL(exit_hs_mode_lat, 15, 0);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304139 dsi_write_reg(dsidev, DSI_VM_TIMING7, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004140
4141 DSSDBG("enter_hs_mode_lat %u, exit_hs_mode_lat %u\n",
4142 enter_hs_mode_lat, exit_hs_mode_lat);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304143
Archit Tanejadca2b152012-08-16 18:02:00 +05304144 if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
Archit Taneja8af6ff02011-09-05 16:48:27 +05304145 /* TODO: Implement a video mode check_timings function */
Archit Taneja0b3ffe32012-08-13 22:13:39 +05304146 int hsa = dsi->vm_timings.hsa;
4147 int hfp = dsi->vm_timings.hfp;
4148 int hbp = dsi->vm_timings.hbp;
4149 int vsa = dsi->vm_timings.vsa;
4150 int vfp = dsi->vm_timings.vfp;
4151 int vbp = dsi->vm_timings.vbp;
4152 int window_sync = dsi->vm_timings.window_sync;
4153 bool hsync_end = dsi->vm_timings.vp_hsync_end;
Archit Tanejae67458a2012-08-13 14:17:30 +05304154 struct omap_video_timings *timings = &dsi->timings;
Archit Taneja02c39602012-08-10 15:01:33 +05304155 int bpp = dsi_get_pixel_size(dsi->pix_fmt);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304156 int tl, t_he, width_bytes;
4157
4158 t_he = hsync_end ?
4159 ((hsa == 0 && ndl == 3) ? 1 : DIV_ROUND_UP(4, ndl)) : 0;
4160
4161 width_bytes = DIV_ROUND_UP(timings->x_res * bpp, 8);
4162
4163 /* TL = t_HS + HSA + t_HE + HFP + ceil((WC + 6) / NDL) + HBP */
4164 tl = DIV_ROUND_UP(4, ndl) + (hsync_end ? hsa : 0) + t_he + hfp +
4165 DIV_ROUND_UP(width_bytes + 6, ndl) + hbp;
4166
4167 DSSDBG("HBP: %d, HFP: %d, HSA: %d, TL: %d TXBYTECLKHS\n", hbp,
4168 hfp, hsync_end ? hsa : 0, tl);
4169 DSSDBG("VBP: %d, VFP: %d, VSA: %d, VACT: %d lines\n", vbp, vfp,
4170 vsa, timings->y_res);
4171
4172 r = dsi_read_reg(dsidev, DSI_VM_TIMING1);
4173 r = FLD_MOD(r, hbp, 11, 0); /* HBP */
4174 r = FLD_MOD(r, hfp, 23, 12); /* HFP */
4175 r = FLD_MOD(r, hsync_end ? hsa : 0, 31, 24); /* HSA */
4176 dsi_write_reg(dsidev, DSI_VM_TIMING1, r);
4177
4178 r = dsi_read_reg(dsidev, DSI_VM_TIMING2);
4179 r = FLD_MOD(r, vbp, 7, 0); /* VBP */
4180 r = FLD_MOD(r, vfp, 15, 8); /* VFP */
4181 r = FLD_MOD(r, vsa, 23, 16); /* VSA */
4182 r = FLD_MOD(r, window_sync, 27, 24); /* WINDOW_SYNC */
4183 dsi_write_reg(dsidev, DSI_VM_TIMING2, r);
4184
4185 r = dsi_read_reg(dsidev, DSI_VM_TIMING3);
4186 r = FLD_MOD(r, timings->y_res, 14, 0); /* VACT */
4187 r = FLD_MOD(r, tl, 31, 16); /* TL */
4188 dsi_write_reg(dsidev, DSI_VM_TIMING3, r);
4189 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004190}
4191
Tomi Valkeinene4a9e942012-03-28 15:58:56 +03004192int omapdss_dsi_configure_pins(struct omap_dss_device *dssdev,
4193 const struct omap_dsi_pin_config *pin_cfg)
4194{
4195 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4196 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4197 int num_pins;
4198 const int *pins;
4199 struct dsi_lane_config lanes[DSI_MAX_NR_LANES];
4200 int num_lanes;
4201 int i;
4202
4203 static const enum dsi_lane_function functions[] = {
4204 DSI_LANE_CLK,
4205 DSI_LANE_DATA1,
4206 DSI_LANE_DATA2,
4207 DSI_LANE_DATA3,
4208 DSI_LANE_DATA4,
4209 };
4210
4211 num_pins = pin_cfg->num_pins;
4212 pins = pin_cfg->pins;
4213
4214 if (num_pins < 4 || num_pins > dsi->num_lanes_supported * 2
4215 || num_pins % 2 != 0)
4216 return -EINVAL;
4217
4218 for (i = 0; i < DSI_MAX_NR_LANES; ++i)
4219 lanes[i].function = DSI_LANE_UNUSED;
4220
4221 num_lanes = 0;
4222
4223 for (i = 0; i < num_pins; i += 2) {
4224 u8 lane, pol;
4225 int dx, dy;
4226
4227 dx = pins[i];
4228 dy = pins[i + 1];
4229
4230 if (dx < 0 || dx >= dsi->num_lanes_supported * 2)
4231 return -EINVAL;
4232
4233 if (dy < 0 || dy >= dsi->num_lanes_supported * 2)
4234 return -EINVAL;
4235
4236 if (dx & 1) {
4237 if (dy != dx - 1)
4238 return -EINVAL;
4239 pol = 1;
4240 } else {
4241 if (dy != dx + 1)
4242 return -EINVAL;
4243 pol = 0;
4244 }
4245
4246 lane = dx / 2;
4247
4248 lanes[lane].function = functions[i / 2];
4249 lanes[lane].polarity = pol;
4250 num_lanes++;
4251 }
4252
4253 memcpy(dsi->lanes, lanes, sizeof(dsi->lanes));
4254 dsi->num_lanes_used = num_lanes;
4255
4256 return 0;
4257}
4258EXPORT_SYMBOL(omapdss_dsi_configure_pins);
4259
Tomi Valkeinenee144e62012-08-10 16:50:51 +03004260int omapdss_dsi_set_clocks(struct omap_dss_device *dssdev,
4261 unsigned long ddr_clk, unsigned long lp_clk)
4262{
4263 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4264 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4265 struct dsi_clock_info cinfo;
4266 struct dispc_clock_info dispc_cinfo;
4267 unsigned lp_clk_div;
4268 unsigned long dsi_fclk;
4269 int bpp = dsi_get_pixel_size(dssdev->panel.dsi_pix_fmt);
4270 unsigned long pck;
4271 int r;
4272
4273 DSSDBGF("ddr_clk %lu, lp_clk %lu", ddr_clk, lp_clk);
4274
4275 mutex_lock(&dsi->lock);
4276
Tomi Valkeinend66b1582012-09-24 15:15:06 +03004277 /* Calculate PLL output clock */
4278 r = dsi_pll_calc_ddrfreq(dsidev, ddr_clk * 4, &cinfo);
Tomi Valkeinenee144e62012-08-10 16:50:51 +03004279 if (r)
4280 goto err;
4281
Tomi Valkeinend66b1582012-09-24 15:15:06 +03004282 /* Calculate PLL's DSI clock */
4283 dsi_pll_calc_dsi_fck(dsidev, &cinfo);
4284
4285 /* Calculate PLL's DISPC clock and pck & lck divs */
4286 pck = cinfo.clkin4ddr / 16 * (dsi->num_lanes_used - 1) * 8 / bpp;
4287 DSSDBG("finding dispc dividers for pck %lu\n", pck);
4288 r = dsi_pll_calc_dispc_fck(dsidev, pck, &cinfo, &dispc_cinfo);
4289 if (r)
4290 goto err;
4291
4292 /* Calculate LP clock */
4293 dsi_fclk = cinfo.dsi_pll_hsdiv_dsi_clk;
4294 lp_clk_div = DIV_ROUND_UP(dsi_fclk, lp_clk * 2);
4295
Tomi Valkeinenee144e62012-08-10 16:50:51 +03004296 dssdev->clocks.dsi.regn = cinfo.regn;
4297 dssdev->clocks.dsi.regm = cinfo.regm;
4298 dssdev->clocks.dsi.regm_dispc = cinfo.regm_dispc;
4299 dssdev->clocks.dsi.regm_dsi = cinfo.regm_dsi;
4300
Tomi Valkeinenee144e62012-08-10 16:50:51 +03004301 dssdev->clocks.dsi.lp_clk_div = lp_clk_div;
4302
Tomi Valkeinenee144e62012-08-10 16:50:51 +03004303 dssdev->clocks.dispc.channel.lck_div = dispc_cinfo.lck_div;
4304 dssdev->clocks.dispc.channel.pck_div = dispc_cinfo.pck_div;
4305
Tomi Valkeinenee144e62012-08-10 16:50:51 +03004306 dssdev->clocks.dispc.dispc_fclk_src = OMAP_DSS_CLK_SRC_FCK;
4307
4308 dssdev->clocks.dispc.channel.lcd_clk_src =
4309 dsi->module_id == 0 ?
4310 OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC :
4311 OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC;
4312
4313 dssdev->clocks.dsi.dsi_fclk_src =
4314 dsi->module_id == 0 ?
4315 OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI :
4316 OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DSI;
4317
4318 mutex_unlock(&dsi->lock);
4319 return 0;
4320err:
4321 mutex_unlock(&dsi->lock);
4322 return r;
4323}
4324EXPORT_SYMBOL(omapdss_dsi_set_clocks);
4325
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004326int dsi_enable_video_output(struct omap_dss_device *dssdev, int channel)
Archit Taneja8af6ff02011-09-05 16:48:27 +05304327{
4328 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejae67458a2012-08-13 14:17:30 +05304329 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Taneja02c39602012-08-10 15:01:33 +05304330 int bpp = dsi_get_pixel_size(dsi->pix_fmt);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304331 u8 data_type;
4332 u16 word_count;
Tomi Valkeinen33ca2372011-11-21 13:42:58 +02004333 int r;
Archit Taneja8af6ff02011-09-05 16:48:27 +05304334
Archit Tanejadca2b152012-08-16 18:02:00 +05304335 if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
Archit Taneja02c39602012-08-10 15:01:33 +05304336 switch (dsi->pix_fmt) {
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004337 case OMAP_DSS_DSI_FMT_RGB888:
4338 data_type = MIPI_DSI_PACKED_PIXEL_STREAM_24;
4339 break;
4340 case OMAP_DSS_DSI_FMT_RGB666:
4341 data_type = MIPI_DSI_PIXEL_STREAM_3BYTE_18;
4342 break;
4343 case OMAP_DSS_DSI_FMT_RGB666_PACKED:
4344 data_type = MIPI_DSI_PACKED_PIXEL_STREAM_18;
4345 break;
4346 case OMAP_DSS_DSI_FMT_RGB565:
4347 data_type = MIPI_DSI_PACKED_PIXEL_STREAM_16;
4348 break;
4349 default:
4350 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03004351 return -EINVAL;
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004352 };
Archit Taneja8af6ff02011-09-05 16:48:27 +05304353
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004354 dsi_if_enable(dsidev, false);
4355 dsi_vc_enable(dsidev, channel, false);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304356
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004357 /* MODE, 1 = video mode */
4358 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 1, 4, 4);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304359
Archit Tanejae67458a2012-08-13 14:17:30 +05304360 word_count = DIV_ROUND_UP(dsi->timings.x_res * bpp, 8);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304361
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004362 dsi_vc_write_long_header(dsidev, channel, data_type,
4363 word_count, 0);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304364
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004365 dsi_vc_enable(dsidev, channel, true);
4366 dsi_if_enable(dsidev, true);
4367 }
Archit Taneja8af6ff02011-09-05 16:48:27 +05304368
Tomi Valkeinen33ca2372011-11-21 13:42:58 +02004369 r = dss_mgr_enable(dssdev->manager);
4370 if (r) {
Archit Tanejadca2b152012-08-16 18:02:00 +05304371 if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
Tomi Valkeinen33ca2372011-11-21 13:42:58 +02004372 dsi_if_enable(dsidev, false);
4373 dsi_vc_enable(dsidev, channel, false);
4374 }
4375
4376 return r;
4377 }
Archit Taneja8af6ff02011-09-05 16:48:27 +05304378
4379 return 0;
4380}
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004381EXPORT_SYMBOL(dsi_enable_video_output);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304382
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004383void dsi_disable_video_output(struct omap_dss_device *dssdev, int channel)
Archit Taneja8af6ff02011-09-05 16:48:27 +05304384{
4385 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejadca2b152012-08-16 18:02:00 +05304386 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304387
Archit Tanejadca2b152012-08-16 18:02:00 +05304388 if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004389 dsi_if_enable(dsidev, false);
4390 dsi_vc_enable(dsidev, channel, false);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304391
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004392 /* MODE, 0 = command mode */
4393 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 0, 4, 4);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304394
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004395 dsi_vc_enable(dsidev, channel, true);
4396 dsi_if_enable(dsidev, true);
4397 }
Archit Taneja8af6ff02011-09-05 16:48:27 +05304398
Tomi Valkeinen7797c6d2011-11-04 10:22:46 +02004399 dss_mgr_disable(dssdev->manager);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304400}
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004401EXPORT_SYMBOL(dsi_disable_video_output);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304402
Archit Taneja55cd63a2012-08-09 15:41:13 +05304403static void dsi_update_screen_dispc(struct omap_dss_device *dssdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004404{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304405 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304406 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004407 unsigned bytespp;
4408 unsigned bytespl;
4409 unsigned bytespf;
4410 unsigned total_len;
4411 unsigned packet_payload;
4412 unsigned packet_len;
4413 u32 l;
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03004414 int r;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304415 const unsigned channel = dsi->update_channel;
Archit Taneja0c656222011-05-16 15:17:09 +05304416 const unsigned line_buf_size = dsi_get_line_buf_size(dsidev);
Archit Taneja55cd63a2012-08-09 15:41:13 +05304417 u16 w = dsi->timings.x_res;
4418 u16 h = dsi->timings.y_res;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004419
Tomi Valkeinen5476e742011-11-03 16:34:20 +02004420 DSSDBG("dsi_update_screen_dispc(%dx%d)\n", w, h);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004421
Archit Tanejad6049142011-08-22 11:58:08 +05304422 dsi_vc_config_source(dsidev, channel, DSI_VC_SOURCE_VP);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004423
Archit Taneja02c39602012-08-10 15:01:33 +05304424 bytespp = dsi_get_pixel_size(dsi->pix_fmt) / 8;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004425 bytespl = w * bytespp;
4426 bytespf = bytespl * h;
4427
4428 /* NOTE: packet_payload has to be equal to N * bytespl, where N is
4429 * number of lines in a packet. See errata about VP_CLK_RATIO */
4430
4431 if (bytespf < line_buf_size)
4432 packet_payload = bytespf;
4433 else
4434 packet_payload = (line_buf_size) / bytespl * bytespl;
4435
4436 packet_len = packet_payload + 1; /* 1 byte for DCS cmd */
4437 total_len = (bytespf / packet_payload) * packet_len;
4438
4439 if (bytespf % packet_payload)
4440 total_len += (bytespf % packet_payload) + 1;
4441
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004442 l = FLD_VAL(total_len, 23, 0); /* TE_SIZE */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304443 dsi_write_reg(dsidev, DSI_VC_TE(channel), l);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004444
Archit Taneja7a7c48f2011-08-25 18:25:03 +05304445 dsi_vc_write_long_header(dsidev, channel, MIPI_DSI_DCS_LONG_WRITE,
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304446 packet_len, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004447
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304448 if (dsi->te_enabled)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004449 l = FLD_MOD(l, 1, 30, 30); /* TE_EN */
4450 else
4451 l = FLD_MOD(l, 1, 31, 31); /* TE_START */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304452 dsi_write_reg(dsidev, DSI_VC_TE(channel), l);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004453
4454 /* We put SIDLEMODE to no-idle for the duration of the transfer,
4455 * because DSS interrupts are not capable of waking up the CPU and the
4456 * framedone interrupt could be delayed for quite a long time. I think
4457 * the same goes for any DSS interrupts, but for some reason I have not
4458 * seen the problem anywhere else than here.
4459 */
4460 dispc_disable_sidle();
4461
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304462 dsi_perf_mark_start(dsidev);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004463
Archit Taneja49dbf582011-05-16 15:17:07 +05304464 r = schedule_delayed_work(&dsi->framedone_timeout_work,
4465 msecs_to_jiffies(250));
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03004466 BUG_ON(r == 0);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004467
Archit Taneja55cd63a2012-08-09 15:41:13 +05304468 dss_mgr_set_timings(dssdev->manager, &dsi->timings);
4469
Tomi Valkeinen1cb00172011-11-18 11:14:01 +02004470 dss_mgr_start_update(dssdev->manager);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004471
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304472 if (dsi->te_enabled) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004473 /* disable LP_RX_TO, so that we can receive TE. Time to wait
4474 * for TE is longer than the timer allows */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304475 REG_FLD_MOD(dsidev, DSI_TIMING2, 0, 15, 15); /* LP_RX_TO */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004476
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304477 dsi_vc_send_bta(dsidev, channel);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004478
4479#ifdef DSI_CATCH_MISSING_TE
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304480 mod_timer(&dsi->te_timer, jiffies + msecs_to_jiffies(250));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004481#endif
4482 }
4483}
4484
4485#ifdef DSI_CATCH_MISSING_TE
4486static void dsi_te_timeout(unsigned long arg)
4487{
4488 DSSERR("TE not received for 250ms!\n");
4489}
4490#endif
4491
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304492static void dsi_handle_framedone(struct platform_device *dsidev, int error)
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004493{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304494 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4495
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004496 /* SIDLEMODE back to smart-idle */
4497 dispc_enable_sidle();
4498
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304499 if (dsi->te_enabled) {
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004500 /* enable LP_RX_TO again after the TE */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304501 REG_FLD_MOD(dsidev, DSI_TIMING2, 1, 15, 15); /* LP_RX_TO */
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004502 }
4503
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304504 dsi->framedone_callback(error, dsi->framedone_data);
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004505
4506 if (!error)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304507 dsi_perf_show(dsidev, "DISPC");
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004508}
4509
4510static void dsi_framedone_timeout_work_callback(struct work_struct *work)
4511{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304512 struct dsi_data *dsi = container_of(work, struct dsi_data,
4513 framedone_timeout_work.work);
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03004514 /* XXX While extremely unlikely, we could get FRAMEDONE interrupt after
4515 * 250ms which would conflict with this timeout work. What should be
4516 * done is first cancel the transfer on the HW, and then cancel the
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004517 * possibly scheduled framedone work. However, cancelling the transfer
4518 * on the HW is buggy, and would probably require resetting the whole
4519 * DSI */
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03004520
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004521 DSSERR("Framedone not received for 250ms!\n");
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004522
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304523 dsi_handle_framedone(dsi->pdev, -ETIMEDOUT);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004524}
4525
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004526static void dsi_framedone_irq_callback(void *data, u32 mask)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004527{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304528 struct omap_dss_device *dssdev = (struct omap_dss_device *) data;
4529 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304530 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4531
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004532 /* Note: We get FRAMEDONE when DISPC has finished sending pixels and
4533 * turns itself off. However, DSI still has the pixels in its buffers,
4534 * and is sending the data.
4535 */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004536
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304537 __cancel_delayed_work(&dsi->framedone_timeout_work);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004538
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304539 dsi_handle_framedone(dsidev, 0);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004540}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004541
Tomi Valkeinen5476e742011-11-03 16:34:20 +02004542int omap_dsi_update(struct omap_dss_device *dssdev, int channel,
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004543 void (*callback)(int, void *), void *data)
4544{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304545 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304546 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen5476e742011-11-03 16:34:20 +02004547 u16 dw, dh;
4548
4549 dsi_perf_mark_setup(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304550
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304551 dsi->update_channel = channel;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004552
Tomi Valkeinen4a9e78a2011-08-15 11:22:21 +03004553 dsi->framedone_callback = callback;
4554 dsi->framedone_data = data;
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004555
Archit Tanejae3525742012-08-09 15:23:43 +05304556 dw = dsi->timings.x_res;
4557 dh = dsi->timings.y_res;
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004558
Tomi Valkeinen5476e742011-11-03 16:34:20 +02004559#ifdef DEBUG
4560 dsi->update_bytes = dw * dh *
Archit Taneja02c39602012-08-10 15:01:33 +05304561 dsi_get_pixel_size(dsi->pix_fmt) / 8;
Tomi Valkeinen5476e742011-11-03 16:34:20 +02004562#endif
Archit Taneja55cd63a2012-08-09 15:41:13 +05304563 dsi_update_screen_dispc(dssdev);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004564
4565 return 0;
4566}
4567EXPORT_SYMBOL(omap_dsi_update);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004568
4569/* Display funcs */
4570
Archit Taneja7d2572f2012-06-29 14:31:07 +05304571static int dsi_configure_dispc_clocks(struct omap_dss_device *dssdev)
4572{
4573 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4574 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4575 struct dispc_clock_info dispc_cinfo;
4576 int r;
4577 unsigned long long fck;
4578
4579 fck = dsi_get_pll_hsdiv_dispc_rate(dsidev);
4580
4581 dispc_cinfo.lck_div = dssdev->clocks.dispc.channel.lck_div;
4582 dispc_cinfo.pck_div = dssdev->clocks.dispc.channel.pck_div;
4583
4584 r = dispc_calc_clock_rates(fck, &dispc_cinfo);
4585 if (r) {
4586 DSSERR("Failed to calc dispc clocks\n");
4587 return r;
4588 }
4589
4590 dsi->mgr_config.clock_info = dispc_cinfo;
4591
4592 return 0;
4593}
4594
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004595static int dsi_display_init_dispc(struct omap_dss_device *dssdev)
4596{
Archit Taneja7d2572f2012-06-29 14:31:07 +05304597 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4598 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Taneja7d2572f2012-06-29 14:31:07 +05304599 int r;
4600 u32 irq = 0;
Archit Taneja5a8b5722011-05-12 17:26:29 +05304601
Archit Tanejadca2b152012-08-16 18:02:00 +05304602 if (dsi->mode == OMAP_DSS_DSI_CMD_MODE) {
Archit Tanejae67458a2012-08-13 14:17:30 +05304603 dsi->timings.hsw = 1;
4604 dsi->timings.hfp = 1;
4605 dsi->timings.hbp = 1;
4606 dsi->timings.vsw = 1;
4607 dsi->timings.vfp = 0;
4608 dsi->timings.vbp = 0;
Tomi Valkeinen5476e742011-11-03 16:34:20 +02004609
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05304610 irq = dispc_mgr_get_framedone_irq(dssdev->manager->id);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304611
4612 r = omap_dispc_register_isr(dsi_framedone_irq_callback,
4613 (void *) dssdev, irq);
4614 if (r) {
4615 DSSERR("can't get FRAMEDONE irq\n");
Archit Taneja7d2572f2012-06-29 14:31:07 +05304616 goto err;
Archit Taneja8af6ff02011-09-05 16:48:27 +05304617 }
4618
Archit Taneja7d2572f2012-06-29 14:31:07 +05304619 dsi->mgr_config.stallmode = true;
4620 dsi->mgr_config.fifohandcheck = true;
Archit Taneja8af6ff02011-09-05 16:48:27 +05304621 } else {
Archit Taneja7d2572f2012-06-29 14:31:07 +05304622 dsi->mgr_config.stallmode = false;
4623 dsi->mgr_config.fifohandcheck = false;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004624 }
4625
Archit Tanejabd5a7b12012-06-26 12:38:31 +05304626 /*
4627 * override interlace, logic level and edge related parameters in
4628 * omap_video_timings with default values
4629 */
Archit Tanejae67458a2012-08-13 14:17:30 +05304630 dsi->timings.interlace = false;
4631 dsi->timings.hsync_level = OMAPDSS_SIG_ACTIVE_HIGH;
4632 dsi->timings.vsync_level = OMAPDSS_SIG_ACTIVE_HIGH;
4633 dsi->timings.data_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE;
4634 dsi->timings.de_level = OMAPDSS_SIG_ACTIVE_HIGH;
4635 dsi->timings.sync_pclk_edge = OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES;
Archit Tanejabd5a7b12012-06-26 12:38:31 +05304636
Archit Tanejae67458a2012-08-13 14:17:30 +05304637 dss_mgr_set_timings(dssdev->manager, &dsi->timings);
Archit Tanejabd5a7b12012-06-26 12:38:31 +05304638
Archit Taneja7d2572f2012-06-29 14:31:07 +05304639 r = dsi_configure_dispc_clocks(dssdev);
4640 if (r)
4641 goto err1;
4642
4643 dsi->mgr_config.io_pad_mode = DSS_IO_PAD_MODE_BYPASS;
4644 dsi->mgr_config.video_port_width =
Archit Taneja02c39602012-08-10 15:01:33 +05304645 dsi_get_pixel_size(dsi->pix_fmt);
Archit Taneja7d2572f2012-06-29 14:31:07 +05304646 dsi->mgr_config.lcden_sig_polarity = 0;
4647
Archit Tanejaf476ae92012-06-29 14:37:03 +05304648 dss_mgr_set_lcd_config(dssdev->manager, &dsi->mgr_config);
Archit Tanejad21f43b2012-06-21 09:45:11 +05304649
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004650 return 0;
Archit Taneja7d2572f2012-06-29 14:31:07 +05304651err1:
Archit Tanejadca2b152012-08-16 18:02:00 +05304652 if (dsi->mode == OMAP_DSS_DSI_CMD_MODE)
Archit Taneja7d2572f2012-06-29 14:31:07 +05304653 omap_dispc_unregister_isr(dsi_framedone_irq_callback,
4654 (void *) dssdev, irq);
4655err:
4656 return r;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004657}
4658
4659static void dsi_display_uninit_dispc(struct omap_dss_device *dssdev)
4660{
Archit Tanejadca2b152012-08-16 18:02:00 +05304661 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4662 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4663
4664 if (dsi->mode == OMAP_DSS_DSI_CMD_MODE) {
Archit Taneja8af6ff02011-09-05 16:48:27 +05304665 u32 irq;
Archit Taneja5a8b5722011-05-12 17:26:29 +05304666
Chandrabhanu Mahapatraefa70b32012-06-21 11:07:44 +05304667 irq = dispc_mgr_get_framedone_irq(dssdev->manager->id);
Archit Taneja5a8b5722011-05-12 17:26:29 +05304668
Archit Taneja8af6ff02011-09-05 16:48:27 +05304669 omap_dispc_unregister_isr(dsi_framedone_irq_callback,
4670 (void *) dssdev, irq);
4671 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004672}
4673
4674static int dsi_configure_dsi_clocks(struct omap_dss_device *dssdev)
4675{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304676 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004677 struct dsi_clock_info cinfo;
4678 int r;
4679
Tomi Valkeinenc6940a32011-02-22 13:36:10 +02004680 cinfo.regn = dssdev->clocks.dsi.regn;
4681 cinfo.regm = dssdev->clocks.dsi.regm;
4682 cinfo.regm_dispc = dssdev->clocks.dsi.regm_dispc;
4683 cinfo.regm_dsi = dssdev->clocks.dsi.regm_dsi;
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02004684 r = dsi_calc_clock_rates(dsidev, &cinfo);
Ville Syrjäläebf0a3f2010-04-22 22:50:05 +02004685 if (r) {
4686 DSSERR("Failed to calc dsi clocks\n");
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004687 return r;
Ville Syrjäläebf0a3f2010-04-22 22:50:05 +02004688 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004689
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304690 r = dsi_pll_set_clock_div(dsidev, &cinfo);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004691 if (r) {
4692 DSSERR("Failed to set dsi clocks\n");
4693 return r;
4694 }
4695
4696 return 0;
4697}
4698
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004699static int dsi_display_init_dsi(struct omap_dss_device *dssdev)
4700{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304701 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02004702 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004703 int r;
4704
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304705 r = dsi_pll_init(dsidev, true, true);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004706 if (r)
4707 goto err0;
4708
4709 r = dsi_configure_dsi_clocks(dssdev);
4710 if (r)
4711 goto err1;
4712
Archit Tanejae8881662011-04-12 13:52:24 +05304713 dss_select_dispc_clk_source(dssdev->clocks.dispc.dispc_fclk_src);
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02004714 dss_select_dsi_clk_source(dsi->module_id, dssdev->clocks.dsi.dsi_fclk_src);
Archit Taneja9613c022011-03-22 06:33:36 -05004715 dss_select_lcd_clk_source(dssdev->manager->id,
Archit Tanejae8881662011-04-12 13:52:24 +05304716 dssdev->clocks.dispc.channel.lcd_clk_src);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004717
4718 DSSDBG("PLL OK\n");
4719
Tomi Valkeinencc5c1852010-10-06 15:18:13 +03004720 r = dsi_cio_init(dssdev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004721 if (r)
4722 goto err2;
4723
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304724 _dsi_print_reset_status(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004725
4726 dsi_proto_timings(dssdev);
4727 dsi_set_lp_clk_divisor(dssdev);
4728
4729 if (1)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304730 _dsi_print_reset_status(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004731
4732 r = dsi_proto_config(dssdev);
4733 if (r)
4734 goto err3;
4735
4736 /* enable interface */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304737 dsi_vc_enable(dsidev, 0, 1);
4738 dsi_vc_enable(dsidev, 1, 1);
4739 dsi_vc_enable(dsidev, 2, 1);
4740 dsi_vc_enable(dsidev, 3, 1);
4741 dsi_if_enable(dsidev, 1);
4742 dsi_force_tx_stop_mode_io(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004743
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004744 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004745err3:
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03004746 dsi_cio_uninit(dssdev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004747err2:
Archit Taneja89a35e52011-04-12 13:52:23 +05304748 dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK);
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02004749 dss_select_dsi_clk_source(dsi->module_id, OMAP_DSS_CLK_SRC_FCK);
Tomi Valkeinen5e785092011-08-10 11:25:36 +03004750 dss_select_lcd_clk_source(dssdev->manager->id, OMAP_DSS_CLK_SRC_FCK);
4751
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004752err1:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304753 dsi_pll_uninit(dsidev, true);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004754err0:
4755 return r;
4756}
4757
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +03004758static void dsi_display_uninit_dsi(struct omap_dss_device *dssdev,
Tomi Valkeinen22d6d672010-10-11 11:33:30 +03004759 bool disconnect_lanes, bool enter_ulps)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004760{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304761 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304762 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304763
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304764 if (enter_ulps && !dsi->ulps_enabled)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304765 dsi_enter_ulps(dsidev);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03004766
Ville Syrjäläd7370102010-04-22 22:50:09 +02004767 /* disable interface */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304768 dsi_if_enable(dsidev, 0);
4769 dsi_vc_enable(dsidev, 0, 0);
4770 dsi_vc_enable(dsidev, 1, 0);
4771 dsi_vc_enable(dsidev, 2, 0);
4772 dsi_vc_enable(dsidev, 3, 0);
Ville Syrjäläd7370102010-04-22 22:50:09 +02004773
Archit Taneja89a35e52011-04-12 13:52:23 +05304774 dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK);
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02004775 dss_select_dsi_clk_source(dsi->module_id, OMAP_DSS_CLK_SRC_FCK);
Tomi Valkeinen5e785092011-08-10 11:25:36 +03004776 dss_select_lcd_clk_source(dssdev->manager->id, OMAP_DSS_CLK_SRC_FCK);
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03004777 dsi_cio_uninit(dssdev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304778 dsi_pll_uninit(dsidev, disconnect_lanes);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004779}
4780
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02004781int omapdss_dsi_display_enable(struct omap_dss_device *dssdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004782{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304783 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304784 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004785 int r = 0;
4786
4787 DSSDBG("dsi_display_enable\n");
4788
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304789 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02004790
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304791 mutex_lock(&dsi->lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004792
Tomi Valkeinen05e1d602011-06-23 16:38:21 +03004793 if (dssdev->manager == NULL) {
4794 DSSERR("failed to enable display: no manager\n");
4795 r = -ENODEV;
4796 goto err_start_dev;
4797 }
4798
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004799 r = omap_dss_start_device(dssdev);
4800 if (r) {
4801 DSSERR("failed to start device\n");
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004802 goto err_start_dev;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004803 }
4804
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004805 r = dsi_runtime_get(dsidev);
4806 if (r)
4807 goto err_get_dsi;
4808
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304809 dsi_enable_pll_clock(dsidev, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004810
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004811 _dsi_initialize_irq(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004812
4813 r = dsi_display_init_dispc(dssdev);
4814 if (r)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004815 goto err_init_dispc;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004816
4817 r = dsi_display_init_dsi(dssdev);
4818 if (r)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004819 goto err_init_dsi;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004820
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304821 mutex_unlock(&dsi->lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004822
4823 return 0;
4824
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004825err_init_dsi:
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02004826 dsi_display_uninit_dispc(dssdev);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004827err_init_dispc:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304828 dsi_enable_pll_clock(dsidev, 0);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004829 dsi_runtime_put(dsidev);
4830err_get_dsi:
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004831 omap_dss_stop_device(dssdev);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004832err_start_dev:
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304833 mutex_unlock(&dsi->lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004834 DSSDBG("dsi_display_enable FAILED\n");
4835 return r;
4836}
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02004837EXPORT_SYMBOL(omapdss_dsi_display_enable);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004838
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +03004839void omapdss_dsi_display_disable(struct omap_dss_device *dssdev,
Tomi Valkeinen22d6d672010-10-11 11:33:30 +03004840 bool disconnect_lanes, bool enter_ulps)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004841{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304842 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304843 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304844
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004845 DSSDBG("dsi_display_disable\n");
4846
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304847 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02004848
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304849 mutex_lock(&dsi->lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004850
Tomi Valkeinen15ffa1d2011-06-16 14:34:06 +03004851 dsi_sync_vc(dsidev, 0);
4852 dsi_sync_vc(dsidev, 1);
4853 dsi_sync_vc(dsidev, 2);
4854 dsi_sync_vc(dsidev, 3);
4855
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004856 dsi_display_uninit_dispc(dssdev);
4857
Tomi Valkeinen22d6d672010-10-11 11:33:30 +03004858 dsi_display_uninit_dsi(dssdev, disconnect_lanes, enter_ulps);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004859
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004860 dsi_runtime_put(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304861 dsi_enable_pll_clock(dsidev, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004862
4863 omap_dss_stop_device(dssdev);
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02004864
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304865 mutex_unlock(&dsi->lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004866}
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02004867EXPORT_SYMBOL(omapdss_dsi_display_disable);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004868
Tomi Valkeinen225b6502010-01-11 15:11:01 +02004869int omapdss_dsi_enable_te(struct omap_dss_device *dssdev, bool enable)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004870{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304871 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4872 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4873
4874 dsi->te_enabled = enable;
Tomi Valkeinen225b6502010-01-11 15:11:01 +02004875 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004876}
Tomi Valkeinen225b6502010-01-11 15:11:01 +02004877EXPORT_SYMBOL(omapdss_dsi_enable_te);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004878
Archit Tanejae67458a2012-08-13 14:17:30 +05304879void omapdss_dsi_set_timings(struct omap_dss_device *dssdev,
4880 struct omap_video_timings *timings)
4881{
4882 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4883 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4884
4885 mutex_lock(&dsi->lock);
4886
4887 dsi->timings = *timings;
4888
4889 mutex_unlock(&dsi->lock);
4890}
4891EXPORT_SYMBOL(omapdss_dsi_set_timings);
4892
Archit Tanejae3525742012-08-09 15:23:43 +05304893void omapdss_dsi_set_size(struct omap_dss_device *dssdev, u16 w, u16 h)
4894{
4895 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4896 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4897
4898 mutex_lock(&dsi->lock);
4899
4900 dsi->timings.x_res = w;
4901 dsi->timings.y_res = h;
4902
4903 mutex_unlock(&dsi->lock);
4904}
4905EXPORT_SYMBOL(omapdss_dsi_set_size);
4906
Archit Taneja02c39602012-08-10 15:01:33 +05304907void omapdss_dsi_set_pixel_format(struct omap_dss_device *dssdev,
4908 enum omap_dss_dsi_pixel_format fmt)
4909{
4910 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4911 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4912
4913 mutex_lock(&dsi->lock);
4914
4915 dsi->pix_fmt = fmt;
4916
4917 mutex_unlock(&dsi->lock);
4918}
4919EXPORT_SYMBOL(omapdss_dsi_set_pixel_format);
4920
Archit Tanejadca2b152012-08-16 18:02:00 +05304921void omapdss_dsi_set_operation_mode(struct omap_dss_device *dssdev,
4922 enum omap_dss_dsi_mode mode)
4923{
4924 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4925 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4926
4927 mutex_lock(&dsi->lock);
4928
4929 dsi->mode = mode;
4930
4931 mutex_unlock(&dsi->lock);
4932}
4933EXPORT_SYMBOL(omapdss_dsi_set_operation_mode);
4934
Archit Taneja0b3ffe32012-08-13 22:13:39 +05304935void omapdss_dsi_set_videomode_timings(struct omap_dss_device *dssdev,
4936 struct omap_dss_dsi_videomode_timings *timings)
4937{
4938 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4939 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4940
4941 mutex_lock(&dsi->lock);
4942
4943 dsi->vm_timings = *timings;
4944
4945 mutex_unlock(&dsi->lock);
4946}
4947EXPORT_SYMBOL(omapdss_dsi_set_videomode_timings);
4948
Tomi Valkeinen9d8232a2012-03-01 16:58:39 +02004949static int __init dsi_init_display(struct omap_dss_device *dssdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004950{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304951 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4952 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4953
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004954 DSSDBG("DSI init\n");
4955
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304956 if (dsi->vdds_dsi_reg == NULL) {
Tomi Valkeinen5f42f2c2011-02-22 15:53:46 +02004957 struct regulator *vdds_dsi;
4958
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304959 vdds_dsi = regulator_get(&dsi->pdev->dev, "vdds_dsi");
Tomi Valkeinen5f42f2c2011-02-22 15:53:46 +02004960
4961 if (IS_ERR(vdds_dsi)) {
4962 DSSERR("can't get VDDS_DSI regulator\n");
4963 return PTR_ERR(vdds_dsi);
4964 }
4965
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304966 dsi->vdds_dsi_reg = vdds_dsi;
Tomi Valkeinen5f42f2c2011-02-22 15:53:46 +02004967 }
4968
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004969 return 0;
4970}
4971
Archit Taneja5ee3c142011-03-02 12:35:53 +05304972int omap_dsi_request_vc(struct omap_dss_device *dssdev, int *channel)
4973{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304974 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4975 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Taneja5ee3c142011-03-02 12:35:53 +05304976 int i;
4977
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304978 for (i = 0; i < ARRAY_SIZE(dsi->vc); i++) {
4979 if (!dsi->vc[i].dssdev) {
4980 dsi->vc[i].dssdev = dssdev;
Archit Taneja5ee3c142011-03-02 12:35:53 +05304981 *channel = i;
4982 return 0;
4983 }
4984 }
4985
4986 DSSERR("cannot get VC for display %s", dssdev->name);
4987 return -ENOSPC;
4988}
4989EXPORT_SYMBOL(omap_dsi_request_vc);
4990
4991int omap_dsi_set_vc_id(struct omap_dss_device *dssdev, int channel, int vc_id)
4992{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304993 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4994 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4995
Archit Taneja5ee3c142011-03-02 12:35:53 +05304996 if (vc_id < 0 || vc_id > 3) {
4997 DSSERR("VC ID out of range\n");
4998 return -EINVAL;
4999 }
5000
5001 if (channel < 0 || channel > 3) {
5002 DSSERR("Virtual Channel out of range\n");
5003 return -EINVAL;
5004 }
5005
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305006 if (dsi->vc[channel].dssdev != dssdev) {
Archit Taneja5ee3c142011-03-02 12:35:53 +05305007 DSSERR("Virtual Channel not allocated to display %s\n",
5008 dssdev->name);
5009 return -EINVAL;
5010 }
5011
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305012 dsi->vc[channel].vc_id = vc_id;
Archit Taneja5ee3c142011-03-02 12:35:53 +05305013
5014 return 0;
5015}
5016EXPORT_SYMBOL(omap_dsi_set_vc_id);
5017
5018void omap_dsi_release_vc(struct omap_dss_device *dssdev, int channel)
5019{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305020 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
5021 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
5022
Archit Taneja5ee3c142011-03-02 12:35:53 +05305023 if ((channel >= 0 && channel <= 3) &&
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305024 dsi->vc[channel].dssdev == dssdev) {
5025 dsi->vc[channel].dssdev = NULL;
5026 dsi->vc[channel].vc_id = 0;
Archit Taneja5ee3c142011-03-02 12:35:53 +05305027 }
5028}
5029EXPORT_SYMBOL(omap_dsi_release_vc);
5030
Archit Tanejaa72b64b2011-05-12 17:26:26 +05305031void dsi_wait_pll_hsdiv_dispc_active(struct platform_device *dsidev)
Tomi Valkeinene406f902010-06-09 15:28:12 +03005032{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05305033 if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 7, 1) != 1)
Archit Taneja067a57e2011-03-02 11:57:25 +05305034 DSSERR("%s (%s) not active\n",
Archit Taneja89a35e52011-04-12 13:52:23 +05305035 dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
5036 dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC));
Tomi Valkeinene406f902010-06-09 15:28:12 +03005037}
5038
Archit Tanejaa72b64b2011-05-12 17:26:26 +05305039void dsi_wait_pll_hsdiv_dsi_active(struct platform_device *dsidev)
Tomi Valkeinene406f902010-06-09 15:28:12 +03005040{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05305041 if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 8, 1) != 1)
Archit Taneja067a57e2011-03-02 11:57:25 +05305042 DSSERR("%s (%s) not active\n",
Archit Taneja89a35e52011-04-12 13:52:23 +05305043 dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
5044 dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI));
Tomi Valkeinene406f902010-06-09 15:28:12 +03005045}
5046
Archit Tanejaa72b64b2011-05-12 17:26:26 +05305047static void dsi_calc_clock_param_ranges(struct platform_device *dsidev)
Taneja, Archit49641112011-03-14 23:28:23 -05005048{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305049 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
5050
5051 dsi->regn_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGN);
5052 dsi->regm_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM);
5053 dsi->regm_dispc_max =
5054 dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DISPC);
5055 dsi->regm_dsi_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DSI);
5056 dsi->fint_min = dss_feat_get_param_min(FEAT_PARAM_DSIPLL_FINT);
5057 dsi->fint_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_FINT);
5058 dsi->lpdiv_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_LPDIV);
Taneja, Archit49641112011-03-14 23:28:23 -05005059}
5060
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005061static int dsi_get_clocks(struct platform_device *dsidev)
5062{
5063 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
5064 struct clk *clk;
5065
5066 clk = clk_get(&dsidev->dev, "fck");
5067 if (IS_ERR(clk)) {
5068 DSSERR("can't get fck\n");
5069 return PTR_ERR(clk);
5070 }
5071
5072 dsi->dss_clk = clk;
5073
Tomi Valkeinenbfe4f8d2011-08-04 11:22:54 +03005074 clk = clk_get(&dsidev->dev, "sys_clk");
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005075 if (IS_ERR(clk)) {
5076 DSSERR("can't get sys_clk\n");
5077 clk_put(dsi->dss_clk);
5078 dsi->dss_clk = NULL;
5079 return PTR_ERR(clk);
5080 }
5081
5082 dsi->sys_clk = clk;
5083
5084 return 0;
5085}
5086
5087static void dsi_put_clocks(struct platform_device *dsidev)
5088{
5089 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
5090
5091 if (dsi->dss_clk)
5092 clk_put(dsi->dss_clk);
5093 if (dsi->sys_clk)
5094 clk_put(dsi->sys_clk);
5095}
5096
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +03005097static void __init dsi_probe_pdata(struct platform_device *dsidev)
5098{
5099 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
5100 struct omap_dss_board_info *pdata = dsidev->dev.platform_data;
5101 int i, r;
5102
5103 for (i = 0; i < pdata->num_devices; ++i) {
5104 struct omap_dss_device *dssdev = pdata->devices[i];
5105
5106 if (dssdev->type != OMAP_DISPLAY_TYPE_DSI)
5107 continue;
5108
5109 if (dssdev->phy.dsi.module != dsi->module_id)
5110 continue;
5111
5112 r = dsi_init_display(dssdev);
5113 if (r) {
5114 DSSERR("device %s init failed: %d\n", dssdev->name, r);
5115 continue;
5116 }
5117
5118 r = omap_dss_register_device(dssdev, &dsidev->dev, i);
5119 if (r)
5120 DSSERR("device %s register failed: %d\n",
5121 dssdev->name, r);
5122 }
5123}
5124
Tomi Valkeinenb98482e2011-05-16 13:52:51 +03005125/* DSI1 HW IP initialisation */
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02005126static int __init omap_dsihw_probe(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005127{
5128 u32 rev;
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02005129 int r, i;
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00005130 struct resource *dsi_mem;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305131 struct dsi_data *dsi;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005132
Julia Lawall6e2a14d2012-01-24 14:00:45 +01005133 dsi = devm_kzalloc(&dsidev->dev, sizeof(*dsi), GFP_KERNEL);
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005134 if (!dsi)
5135 return -ENOMEM;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305136
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02005137 dsi->module_id = dsidev->id;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305138 dsi->pdev = dsidev;
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02005139 dsi_pdev_map[dsi->module_id] = dsidev;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305140 dev_set_drvdata(&dsidev->dev, dsi);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05305141
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305142 spin_lock_init(&dsi->irq_lock);
5143 spin_lock_init(&dsi->errors_lock);
5144 dsi->errors = 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005145
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02005146#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305147 spin_lock_init(&dsi->irq_stats_lock);
5148 dsi->irq_stats.last_reset = jiffies;
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02005149#endif
5150
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305151 mutex_init(&dsi->lock);
5152 sema_init(&dsi->bus_lock, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005153
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305154 INIT_DELAYED_WORK_DEFERRABLE(&dsi->framedone_timeout_work,
5155 dsi_framedone_timeout_work_callback);
5156
5157#ifdef DSI_CATCH_MISSING_TE
5158 init_timer(&dsi->te_timer);
5159 dsi->te_timer.function = dsi_te_timeout;
5160 dsi->te_timer.data = 0;
5161#endif
5162 dsi_mem = platform_get_resource(dsi->pdev, IORESOURCE_MEM, 0);
5163 if (!dsi_mem) {
5164 DSSERR("can't get IORESOURCE_MEM DSI\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005165 return -EINVAL;
archit tanejaaffe3602011-02-23 08:41:03 +00005166 }
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005167
Julia Lawall6e2a14d2012-01-24 14:00:45 +01005168 dsi->base = devm_ioremap(&dsidev->dev, dsi_mem->start,
5169 resource_size(dsi_mem));
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305170 if (!dsi->base) {
5171 DSSERR("can't ioremap DSI\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005172 return -ENOMEM;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305173 }
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005174
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305175 dsi->irq = platform_get_irq(dsi->pdev, 0);
5176 if (dsi->irq < 0) {
5177 DSSERR("platform_get_irq failed\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005178 return -ENODEV;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305179 }
archit tanejaaffe3602011-02-23 08:41:03 +00005180
Julia Lawall6e2a14d2012-01-24 14:00:45 +01005181 r = devm_request_irq(&dsidev->dev, dsi->irq, omap_dsi_irq_handler,
5182 IRQF_SHARED, dev_name(&dsidev->dev), dsi->pdev);
archit tanejaaffe3602011-02-23 08:41:03 +00005183 if (r < 0) {
5184 DSSERR("request_irq failed\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005185 return r;
archit tanejaaffe3602011-02-23 08:41:03 +00005186 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005187
Archit Taneja5ee3c142011-03-02 12:35:53 +05305188 /* DSI VCs initialization */
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305189 for (i = 0; i < ARRAY_SIZE(dsi->vc); i++) {
Archit Tanejad6049142011-08-22 11:58:08 +05305190 dsi->vc[i].source = DSI_VC_SOURCE_L4;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305191 dsi->vc[i].dssdev = NULL;
5192 dsi->vc[i].vc_id = 0;
Archit Taneja5ee3c142011-03-02 12:35:53 +05305193 }
5194
Archit Tanejaa72b64b2011-05-12 17:26:26 +05305195 dsi_calc_clock_param_ranges(dsidev);
Taneja, Archit49641112011-03-14 23:28:23 -05005196
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005197 r = dsi_get_clocks(dsidev);
5198 if (r)
5199 return r;
5200
5201 pm_runtime_enable(&dsidev->dev);
5202
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005203 r = dsi_runtime_get(dsidev);
5204 if (r)
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005205 goto err_runtime_get;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005206
Archit Tanejaa72b64b2011-05-12 17:26:26 +05305207 rev = dsi_read_reg(dsidev, DSI_REVISION);
5208 dev_dbg(&dsidev->dev, "OMAP DSI rev %d.%d\n",
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005209 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
5210
Tomi Valkeinend9820852011-10-12 15:05:59 +03005211 /* DSI on OMAP3 doesn't have register DSI_GNQ, set number
5212 * of data to 3 by default */
5213 if (dss_has_feature(FEAT_DSI_GNQ))
5214 /* NB_DATA_LANES */
5215 dsi->num_lanes_supported = 1 + REG_GET(dsidev, DSI_GNQ, 11, 9);
5216 else
5217 dsi->num_lanes_supported = 3;
Archit Taneja75d72472011-05-16 15:17:08 +05305218
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +03005219 dsi_probe_pdata(dsidev);
Tomi Valkeinen35deca32012-03-01 15:45:53 +02005220
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005221 dsi_runtime_put(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005222
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02005223 if (dsi->module_id == 0)
Tomi Valkeinene40402c2012-03-02 18:01:07 +02005224 dss_debugfs_create_file("dsi1_regs", dsi1_dump_regs);
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02005225 else if (dsi->module_id == 1)
Tomi Valkeinene40402c2012-03-02 18:01:07 +02005226 dss_debugfs_create_file("dsi2_regs", dsi2_dump_regs);
5227
5228#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02005229 if (dsi->module_id == 0)
Tomi Valkeinene40402c2012-03-02 18:01:07 +02005230 dss_debugfs_create_file("dsi1_irqs", dsi1_dump_irqs);
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02005231 else if (dsi->module_id == 1)
Tomi Valkeinene40402c2012-03-02 18:01:07 +02005232 dss_debugfs_create_file("dsi2_irqs", dsi2_dump_irqs);
5233#endif
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005234 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005235
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005236err_runtime_get:
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005237 pm_runtime_disable(&dsidev->dev);
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005238 dsi_put_clocks(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005239 return r;
5240}
5241
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02005242static int __exit omap_dsihw_remove(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005243{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305244 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
5245
Tomi Valkeinenb98482e2011-05-16 13:52:51 +03005246 WARN_ON(dsi->scp_clk_refcount > 0);
5247
Tomi Valkeinen35deca32012-03-01 15:45:53 +02005248 omap_dss_unregister_child_devices(&dsidev->dev);
5249
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005250 pm_runtime_disable(&dsidev->dev);
5251
5252 dsi_put_clocks(dsidev);
5253
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305254 if (dsi->vdds_dsi_reg != NULL) {
5255 if (dsi->vdds_dsi_enabled) {
5256 regulator_disable(dsi->vdds_dsi_reg);
5257 dsi->vdds_dsi_enabled = false;
Tomi Valkeinen88257b22010-12-20 16:26:22 +02005258 }
5259
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305260 regulator_put(dsi->vdds_dsi_reg);
5261 dsi->vdds_dsi_reg = NULL;
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005262 }
5263
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005264 return 0;
5265}
5266
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005267static int dsi_runtime_suspend(struct device *dev)
5268{
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005269 dispc_runtime_put();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005270
5271 return 0;
5272}
5273
5274static int dsi_runtime_resume(struct device *dev)
5275{
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005276 int r;
5277
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005278 r = dispc_runtime_get();
5279 if (r)
Tomi Valkeinen852f0832012-02-17 17:58:04 +02005280 return r;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005281
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005282 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005283}
5284
5285static const struct dev_pm_ops dsi_pm_ops = {
5286 .runtime_suspend = dsi_runtime_suspend,
5287 .runtime_resume = dsi_runtime_resume,
5288};
5289
Tomi Valkeinen7c68dd92011-08-03 14:00:57 +03005290static struct platform_driver omap_dsihw_driver = {
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02005291 .remove = __exit_p(omap_dsihw_remove),
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005292 .driver = {
Tomi Valkeinen7c68dd92011-08-03 14:00:57 +03005293 .name = "omapdss_dsi",
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005294 .owner = THIS_MODULE,
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005295 .pm = &dsi_pm_ops,
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005296 },
5297};
5298
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02005299int __init dsi_init_platform_driver(void)
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005300{
Tomi Valkeinen61055d42012-03-07 12:53:38 +02005301 return platform_driver_probe(&omap_dsihw_driver, omap_dsihw_probe);
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005302}
5303
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02005304void __exit dsi_uninit_platform_driver(void)
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005305{
Tomi Valkeinen04c742c2012-02-23 15:32:37 +02005306 platform_driver_unregister(&omap_dsihw_driver);
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005307}