blob: af07ec6a83bd29387e9cf64fb83395e6dfe9f0f0 [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
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +020048#define DSI_CATCH_MISSING_TE
49
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +020050struct dsi_reg { u16 idx; };
51
52#define DSI_REG(idx) ((const struct dsi_reg) { idx })
53
54#define DSI_SZ_REGS SZ_1K
55/* DSI Protocol Engine */
56
57#define DSI_REVISION DSI_REG(0x0000)
58#define DSI_SYSCONFIG DSI_REG(0x0010)
59#define DSI_SYSSTATUS DSI_REG(0x0014)
60#define DSI_IRQSTATUS DSI_REG(0x0018)
61#define DSI_IRQENABLE DSI_REG(0x001C)
62#define DSI_CTRL DSI_REG(0x0040)
Archit Taneja75d72472011-05-16 15:17:08 +053063#define DSI_GNQ DSI_REG(0x0044)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +020064#define DSI_COMPLEXIO_CFG1 DSI_REG(0x0048)
65#define DSI_COMPLEXIO_IRQ_STATUS DSI_REG(0x004C)
66#define DSI_COMPLEXIO_IRQ_ENABLE DSI_REG(0x0050)
67#define DSI_CLK_CTRL DSI_REG(0x0054)
68#define DSI_TIMING1 DSI_REG(0x0058)
69#define DSI_TIMING2 DSI_REG(0x005C)
70#define DSI_VM_TIMING1 DSI_REG(0x0060)
71#define DSI_VM_TIMING2 DSI_REG(0x0064)
72#define DSI_VM_TIMING3 DSI_REG(0x0068)
73#define DSI_CLK_TIMING DSI_REG(0x006C)
74#define DSI_TX_FIFO_VC_SIZE DSI_REG(0x0070)
75#define DSI_RX_FIFO_VC_SIZE DSI_REG(0x0074)
76#define DSI_COMPLEXIO_CFG2 DSI_REG(0x0078)
77#define DSI_RX_FIFO_VC_FULLNESS DSI_REG(0x007C)
78#define DSI_VM_TIMING4 DSI_REG(0x0080)
79#define DSI_TX_FIFO_VC_EMPTINESS DSI_REG(0x0084)
80#define DSI_VM_TIMING5 DSI_REG(0x0088)
81#define DSI_VM_TIMING6 DSI_REG(0x008C)
82#define DSI_VM_TIMING7 DSI_REG(0x0090)
83#define DSI_STOPCLK_TIMING DSI_REG(0x0094)
84#define DSI_VC_CTRL(n) DSI_REG(0x0100 + (n * 0x20))
85#define DSI_VC_TE(n) DSI_REG(0x0104 + (n * 0x20))
86#define DSI_VC_LONG_PACKET_HEADER(n) DSI_REG(0x0108 + (n * 0x20))
87#define DSI_VC_LONG_PACKET_PAYLOAD(n) DSI_REG(0x010C + (n * 0x20))
88#define DSI_VC_SHORT_PACKET_HEADER(n) DSI_REG(0x0110 + (n * 0x20))
89#define DSI_VC_IRQSTATUS(n) DSI_REG(0x0118 + (n * 0x20))
90#define DSI_VC_IRQENABLE(n) DSI_REG(0x011C + (n * 0x20))
91
92/* DSIPHY_SCP */
93
94#define DSI_DSIPHY_CFG0 DSI_REG(0x200 + 0x0000)
95#define DSI_DSIPHY_CFG1 DSI_REG(0x200 + 0x0004)
96#define DSI_DSIPHY_CFG2 DSI_REG(0x200 + 0x0008)
97#define DSI_DSIPHY_CFG5 DSI_REG(0x200 + 0x0014)
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +030098#define DSI_DSIPHY_CFG10 DSI_REG(0x200 + 0x0028)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +020099
100/* DSI_PLL_CTRL_SCP */
101
102#define DSI_PLL_CONTROL DSI_REG(0x300 + 0x0000)
103#define DSI_PLL_STATUS DSI_REG(0x300 + 0x0004)
104#define DSI_PLL_GO DSI_REG(0x300 + 0x0008)
105#define DSI_PLL_CONFIGURATION1 DSI_REG(0x300 + 0x000C)
106#define DSI_PLL_CONFIGURATION2 DSI_REG(0x300 + 0x0010)
107
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530108#define REG_GET(dsidev, idx, start, end) \
109 FLD_GET(dsi_read_reg(dsidev, idx), start, end)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200110
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530111#define REG_FLD_MOD(dsidev, idx, val, start, end) \
112 dsi_write_reg(dsidev, idx, FLD_MOD(dsi_read_reg(dsidev, idx), val, start, end))
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200113
114/* Global interrupts */
115#define DSI_IRQ_VC0 (1 << 0)
116#define DSI_IRQ_VC1 (1 << 1)
117#define DSI_IRQ_VC2 (1 << 2)
118#define DSI_IRQ_VC3 (1 << 3)
119#define DSI_IRQ_WAKEUP (1 << 4)
120#define DSI_IRQ_RESYNC (1 << 5)
121#define DSI_IRQ_PLL_LOCK (1 << 7)
122#define DSI_IRQ_PLL_UNLOCK (1 << 8)
123#define DSI_IRQ_PLL_RECALL (1 << 9)
124#define DSI_IRQ_COMPLEXIO_ERR (1 << 10)
125#define DSI_IRQ_HS_TX_TIMEOUT (1 << 14)
126#define DSI_IRQ_LP_RX_TIMEOUT (1 << 15)
127#define DSI_IRQ_TE_TRIGGER (1 << 16)
128#define DSI_IRQ_ACK_TRIGGER (1 << 17)
129#define DSI_IRQ_SYNC_LOST (1 << 18)
130#define DSI_IRQ_LDO_POWER_GOOD (1 << 19)
131#define DSI_IRQ_TA_TIMEOUT (1 << 20)
132#define DSI_IRQ_ERROR_MASK \
133 (DSI_IRQ_HS_TX_TIMEOUT | DSI_IRQ_LP_RX_TIMEOUT | DSI_IRQ_SYNC_LOST | \
Archit Taneja8af6ff02011-09-05 16:48:27 +0530134 DSI_IRQ_TA_TIMEOUT | DSI_IRQ_SYNC_LOST)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200135#define DSI_IRQ_CHANNEL_MASK 0xf
136
137/* Virtual channel interrupts */
138#define DSI_VC_IRQ_CS (1 << 0)
139#define DSI_VC_IRQ_ECC_CORR (1 << 1)
140#define DSI_VC_IRQ_PACKET_SENT (1 << 2)
141#define DSI_VC_IRQ_FIFO_TX_OVF (1 << 3)
142#define DSI_VC_IRQ_FIFO_RX_OVF (1 << 4)
143#define DSI_VC_IRQ_BTA (1 << 5)
144#define DSI_VC_IRQ_ECC_NO_CORR (1 << 6)
145#define DSI_VC_IRQ_FIFO_TX_UDF (1 << 7)
146#define DSI_VC_IRQ_PP_BUSY_CHANGE (1 << 8)
147#define DSI_VC_IRQ_ERROR_MASK \
148 (DSI_VC_IRQ_CS | DSI_VC_IRQ_ECC_CORR | DSI_VC_IRQ_FIFO_TX_OVF | \
149 DSI_VC_IRQ_FIFO_RX_OVF | DSI_VC_IRQ_ECC_NO_CORR | \
150 DSI_VC_IRQ_FIFO_TX_UDF)
151
152/* ComplexIO interrupts */
153#define DSI_CIO_IRQ_ERRSYNCESC1 (1 << 0)
154#define DSI_CIO_IRQ_ERRSYNCESC2 (1 << 1)
155#define DSI_CIO_IRQ_ERRSYNCESC3 (1 << 2)
Tomi Valkeinen67056152011-03-24 16:30:17 +0200156#define DSI_CIO_IRQ_ERRSYNCESC4 (1 << 3)
157#define DSI_CIO_IRQ_ERRSYNCESC5 (1 << 4)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200158#define DSI_CIO_IRQ_ERRESC1 (1 << 5)
159#define DSI_CIO_IRQ_ERRESC2 (1 << 6)
160#define DSI_CIO_IRQ_ERRESC3 (1 << 7)
Tomi Valkeinen67056152011-03-24 16:30:17 +0200161#define DSI_CIO_IRQ_ERRESC4 (1 << 8)
162#define DSI_CIO_IRQ_ERRESC5 (1 << 9)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200163#define DSI_CIO_IRQ_ERRCONTROL1 (1 << 10)
164#define DSI_CIO_IRQ_ERRCONTROL2 (1 << 11)
165#define DSI_CIO_IRQ_ERRCONTROL3 (1 << 12)
Tomi Valkeinen67056152011-03-24 16:30:17 +0200166#define DSI_CIO_IRQ_ERRCONTROL4 (1 << 13)
167#define DSI_CIO_IRQ_ERRCONTROL5 (1 << 14)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200168#define DSI_CIO_IRQ_STATEULPS1 (1 << 15)
169#define DSI_CIO_IRQ_STATEULPS2 (1 << 16)
170#define DSI_CIO_IRQ_STATEULPS3 (1 << 17)
Tomi Valkeinen67056152011-03-24 16:30:17 +0200171#define DSI_CIO_IRQ_STATEULPS4 (1 << 18)
172#define DSI_CIO_IRQ_STATEULPS5 (1 << 19)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200173#define DSI_CIO_IRQ_ERRCONTENTIONLP0_1 (1 << 20)
174#define DSI_CIO_IRQ_ERRCONTENTIONLP1_1 (1 << 21)
175#define DSI_CIO_IRQ_ERRCONTENTIONLP0_2 (1 << 22)
176#define DSI_CIO_IRQ_ERRCONTENTIONLP1_2 (1 << 23)
177#define DSI_CIO_IRQ_ERRCONTENTIONLP0_3 (1 << 24)
178#define DSI_CIO_IRQ_ERRCONTENTIONLP1_3 (1 << 25)
Tomi Valkeinen67056152011-03-24 16:30:17 +0200179#define DSI_CIO_IRQ_ERRCONTENTIONLP0_4 (1 << 26)
180#define DSI_CIO_IRQ_ERRCONTENTIONLP1_4 (1 << 27)
181#define DSI_CIO_IRQ_ERRCONTENTIONLP0_5 (1 << 28)
182#define DSI_CIO_IRQ_ERRCONTENTIONLP1_5 (1 << 29)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200183#define DSI_CIO_IRQ_ULPSACTIVENOT_ALL0 (1 << 30)
184#define DSI_CIO_IRQ_ULPSACTIVENOT_ALL1 (1 << 31)
Tomi Valkeinenbbecb502010-05-10 14:35:33 +0300185#define DSI_CIO_IRQ_ERROR_MASK \
186 (DSI_CIO_IRQ_ERRSYNCESC1 | DSI_CIO_IRQ_ERRSYNCESC2 | \
Tomi Valkeinen67056152011-03-24 16:30:17 +0200187 DSI_CIO_IRQ_ERRSYNCESC3 | DSI_CIO_IRQ_ERRSYNCESC4 | \
188 DSI_CIO_IRQ_ERRSYNCESC5 | \
189 DSI_CIO_IRQ_ERRESC1 | DSI_CIO_IRQ_ERRESC2 | \
190 DSI_CIO_IRQ_ERRESC3 | DSI_CIO_IRQ_ERRESC4 | \
191 DSI_CIO_IRQ_ERRESC5 | \
192 DSI_CIO_IRQ_ERRCONTROL1 | DSI_CIO_IRQ_ERRCONTROL2 | \
193 DSI_CIO_IRQ_ERRCONTROL3 | DSI_CIO_IRQ_ERRCONTROL4 | \
194 DSI_CIO_IRQ_ERRCONTROL5 | \
Tomi Valkeinenbbecb502010-05-10 14:35:33 +0300195 DSI_CIO_IRQ_ERRCONTENTIONLP0_1 | DSI_CIO_IRQ_ERRCONTENTIONLP1_1 | \
196 DSI_CIO_IRQ_ERRCONTENTIONLP0_2 | DSI_CIO_IRQ_ERRCONTENTIONLP1_2 | \
Tomi Valkeinen67056152011-03-24 16:30:17 +0200197 DSI_CIO_IRQ_ERRCONTENTIONLP0_3 | DSI_CIO_IRQ_ERRCONTENTIONLP1_3 | \
198 DSI_CIO_IRQ_ERRCONTENTIONLP0_4 | DSI_CIO_IRQ_ERRCONTENTIONLP1_4 | \
199 DSI_CIO_IRQ_ERRCONTENTIONLP0_5 | DSI_CIO_IRQ_ERRCONTENTIONLP1_5)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200200
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200201typedef void (*omap_dsi_isr_t) (void *arg, u32 mask);
202
203#define DSI_MAX_NR_ISRS 2
Tomi Valkeinen739a7f42011-10-13 11:22:06 +0300204#define DSI_MAX_NR_LANES 5
205
206enum dsi_lane_function {
207 DSI_LANE_UNUSED = 0,
208 DSI_LANE_CLK,
209 DSI_LANE_DATA1,
210 DSI_LANE_DATA2,
211 DSI_LANE_DATA3,
212 DSI_LANE_DATA4,
213};
214
215struct dsi_lane_config {
216 enum dsi_lane_function function;
217 u8 polarity;
218};
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200219
220struct dsi_isr_data {
221 omap_dsi_isr_t isr;
222 void *arg;
223 u32 mask;
224};
225
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200226enum fifo_size {
227 DSI_FIFO_SIZE_0 = 0,
228 DSI_FIFO_SIZE_32 = 1,
229 DSI_FIFO_SIZE_64 = 2,
230 DSI_FIFO_SIZE_96 = 3,
231 DSI_FIFO_SIZE_128 = 4,
232};
233
Archit Tanejad6049142011-08-22 11:58:08 +0530234enum dsi_vc_source {
235 DSI_VC_SOURCE_L4 = 0,
236 DSI_VC_SOURCE_VP,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200237};
238
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200239struct dsi_irq_stats {
240 unsigned long last_reset;
241 unsigned irq_count;
242 unsigned dsi_irqs[32];
243 unsigned vc_irqs[4][32];
244 unsigned cio_irqs[32];
245};
246
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200247struct dsi_isr_tables {
248 struct dsi_isr_data isr_table[DSI_MAX_NR_ISRS];
249 struct dsi_isr_data isr_table_vc[4][DSI_MAX_NR_ISRS];
250 struct dsi_isr_data isr_table_cio[DSI_MAX_NR_ISRS];
251};
252
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530253struct dsi_data {
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +0000254 struct platform_device *pdev;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200255 void __iomem *base;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300256
Tomi Valkeinen11ee9602012-03-09 16:07:39 +0200257 int module_id;
258
archit tanejaaffe3602011-02-23 08:41:03 +0000259 int irq;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200260
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300261 struct clk *dss_clk;
262 struct clk *sys_clk;
263
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200264 struct dsi_clock_info current_cinfo;
265
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +0300266 bool vdds_dsi_enabled;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200267 struct regulator *vdds_dsi_reg;
268
269 struct {
Archit Tanejad6049142011-08-22 11:58:08 +0530270 enum dsi_vc_source source;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200271 struct omap_dss_device *dssdev;
272 enum fifo_size fifo_size;
Archit Taneja5ee3c142011-03-02 12:35:53 +0530273 int vc_id;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200274 } vc[4];
275
276 struct mutex lock;
Tomi Valkeinenb9eb5d72010-01-11 16:33:56 +0200277 struct semaphore bus_lock;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200278
279 unsigned pll_locked;
280
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200281 spinlock_t irq_lock;
282 struct dsi_isr_tables isr_tables;
283 /* space for a copy used by the interrupt handler */
284 struct dsi_isr_tables isr_tables_copy;
285
Tomi Valkeinen18946f62010-01-12 14:16:41 +0200286 int update_channel;
Tomi Valkeinen5476e742011-11-03 16:34:20 +0200287#ifdef DEBUG
288 unsigned update_bytes;
289#endif
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200290
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200291 bool te_enabled;
Tomi Valkeinen40885ab2010-07-28 15:53:38 +0300292 bool ulps_enabled;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200293
Tomi Valkeinen18946f62010-01-12 14:16:41 +0200294 void (*framedone_callback)(int, void *);
295 void *framedone_data;
296
297 struct delayed_work framedone_timeout_work;
298
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200299#ifdef DSI_CATCH_MISSING_TE
300 struct timer_list te_timer;
301#endif
302
303 unsigned long cache_req_pck;
304 unsigned long cache_clk_freq;
305 struct dsi_clock_info cache_cinfo;
306
307 u32 errors;
308 spinlock_t errors_lock;
309#ifdef DEBUG
310 ktime_t perf_setup_time;
311 ktime_t perf_start_time;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200312#endif
313 int debug_read;
314 int debug_write;
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200315
316#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
317 spinlock_t irq_stats_lock;
318 struct dsi_irq_stats irq_stats;
319#endif
Taneja, Archit49641112011-03-14 23:28:23 -0500320 /* DSI PLL Parameter Ranges */
321 unsigned long regm_max, regn_max;
322 unsigned long regm_dispc_max, regm_dsi_max;
323 unsigned long fint_min, fint_max;
324 unsigned long lpdiv_max;
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +0300325
Tomi Valkeinend9820852011-10-12 15:05:59 +0300326 unsigned num_lanes_supported;
Archit Taneja75d72472011-05-16 15:17:08 +0530327
Tomi Valkeinen739a7f42011-10-13 11:22:06 +0300328 struct dsi_lane_config lanes[DSI_MAX_NR_LANES];
329 unsigned num_lanes_used;
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +0300330
331 unsigned scp_clk_refcount;
Archit Taneja7d2572f2012-06-29 14:31:07 +0530332
333 struct dss_lcd_mgr_config mgr_config;
Archit Tanejae67458a2012-08-13 14:17:30 +0530334 struct omap_video_timings timings;
Archit Taneja02c39602012-08-10 15:01:33 +0530335 enum omap_dss_dsi_pixel_format pix_fmt;
Archit Tanejadca2b152012-08-16 18:02:00 +0530336 enum omap_dss_dsi_mode mode;
Archit Taneja0b3ffe32012-08-13 22:13:39 +0530337 struct omap_dss_dsi_videomode_timings vm_timings;
Archit Taneja81b87f52012-09-26 16:30:49 +0530338
339 struct omap_dss_output output;
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530340};
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200341
Archit Taneja2e868db2011-05-12 17:26:28 +0530342struct dsi_packet_sent_handler_data {
343 struct platform_device *dsidev;
344 struct completion *completion;
345};
346
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200347#ifdef DEBUG
Rusty Russell90ab5ee2012-01-13 09:32:20 +1030348static bool dsi_perf;
349module_param(dsi_perf, bool, 0644);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200350#endif
351
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530352static inline struct dsi_data *dsi_get_dsidrv_data(struct platform_device *dsidev)
353{
354 return dev_get_drvdata(&dsidev->dev);
355}
356
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530357static inline struct platform_device *dsi_get_dsidev_from_dssdev(struct omap_dss_device *dssdev)
358{
Archit Taneja400e65d2012-07-04 13:48:34 +0530359 return dssdev->output->pdev;
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530360}
361
362struct platform_device *dsi_get_dsidev_from_id(int module)
363{
Archit Taneja400e65d2012-07-04 13:48:34 +0530364 struct omap_dss_output *out;
365 enum omap_dss_output_id id;
366
367 id = module == 0 ? OMAP_DSS_OUTPUT_DSI1 : OMAP_DSS_OUTPUT_DSI2;
368
369 out = omap_dss_get_output(id);
370
371 return out->pdev;
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530372}
373
374static inline void dsi_write_reg(struct platform_device *dsidev,
375 const struct dsi_reg idx, u32 val)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200376{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530377 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
378
379 __raw_writel(val, dsi->base + idx.idx);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200380}
381
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530382static inline u32 dsi_read_reg(struct platform_device *dsidev,
383 const struct dsi_reg idx)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200384{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530385 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
386
387 return __raw_readl(dsi->base + idx.idx);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200388}
389
Archit Taneja1ffefe72011-05-12 17:26:24 +0530390void dsi_bus_lock(struct omap_dss_device *dssdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200391{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530392 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
393 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
394
395 down(&dsi->bus_lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200396}
397EXPORT_SYMBOL(dsi_bus_lock);
398
Archit Taneja1ffefe72011-05-12 17:26:24 +0530399void dsi_bus_unlock(struct omap_dss_device *dssdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200400{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530401 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
402 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
403
404 up(&dsi->bus_lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200405}
406EXPORT_SYMBOL(dsi_bus_unlock);
407
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530408static bool dsi_bus_is_locked(struct platform_device *dsidev)
Tomi Valkeinen4f765022010-01-18 16:27:52 +0200409{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530410 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
411
412 return dsi->bus_lock.count == 0;
Tomi Valkeinen4f765022010-01-18 16:27:52 +0200413}
414
Tomi Valkeinenf36a06e2011-03-02 14:48:41 +0200415static void dsi_completion_handler(void *data, u32 mask)
416{
417 complete((struct completion *)data);
418}
419
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530420static inline int wait_for_bit_change(struct platform_device *dsidev,
421 const struct dsi_reg idx, int bitnum, int value)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200422{
Tomi Valkeinen3b984092011-10-13 19:06:49 +0300423 unsigned long timeout;
424 ktime_t wait;
425 int t;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200426
Tomi Valkeinen3b984092011-10-13 19:06:49 +0300427 /* first busyloop to see if the bit changes right away */
428 t = 100;
429 while (t-- > 0) {
430 if (REG_GET(dsidev, idx, bitnum, bitnum) == value)
431 return value;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200432 }
433
Tomi Valkeinen3b984092011-10-13 19:06:49 +0300434 /* then loop for 500ms, sleeping for 1ms in between */
435 timeout = jiffies + msecs_to_jiffies(500);
436 while (time_before(jiffies, timeout)) {
437 if (REG_GET(dsidev, idx, bitnum, bitnum) == value)
438 return value;
439
440 wait = ns_to_ktime(1000 * 1000);
441 set_current_state(TASK_UNINTERRUPTIBLE);
442 schedule_hrtimeout(&wait, HRTIMER_MODE_REL);
443 }
444
445 return !value;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200446}
447
Archit Tanejaa3b3cc22011-09-08 18:42:16 +0530448u8 dsi_get_pixel_size(enum omap_dss_dsi_pixel_format fmt)
449{
450 switch (fmt) {
451 case OMAP_DSS_DSI_FMT_RGB888:
452 case OMAP_DSS_DSI_FMT_RGB666:
453 return 24;
454 case OMAP_DSS_DSI_FMT_RGB666_PACKED:
455 return 18;
456 case OMAP_DSS_DSI_FMT_RGB565:
457 return 16;
458 default:
459 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300460 return 0;
Archit Tanejaa3b3cc22011-09-08 18:42:16 +0530461 }
462}
463
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200464#ifdef DEBUG
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530465static void dsi_perf_mark_setup(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_setup_time = ktime_get();
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200469}
470
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530471static void dsi_perf_mark_start(struct platform_device *dsidev)
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);
474 dsi->perf_start_time = ktime_get();
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200475}
476
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530477static void dsi_perf_show(struct platform_device *dsidev, const char *name)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200478{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530479 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200480 ktime_t t, setup_time, trans_time;
481 u32 total_bytes;
482 u32 setup_us, trans_us, total_us;
483
484 if (!dsi_perf)
485 return;
486
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200487 t = ktime_get();
488
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530489 setup_time = ktime_sub(dsi->perf_start_time, dsi->perf_setup_time);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200490 setup_us = (u32)ktime_to_us(setup_time);
491 if (setup_us == 0)
492 setup_us = 1;
493
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530494 trans_time = ktime_sub(t, dsi->perf_start_time);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200495 trans_us = (u32)ktime_to_us(trans_time);
496 if (trans_us == 0)
497 trans_us = 1;
498
499 total_us = setup_us + trans_us;
500
Tomi Valkeinen5476e742011-11-03 16:34:20 +0200501 total_bytes = dsi->update_bytes;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200502
Tomi Valkeinen1bbb2752010-01-11 16:41:10 +0200503 printk(KERN_INFO "DSI(%s): %u us + %u us = %u us (%uHz), "
504 "%u bytes, %u kbytes/sec\n",
505 name,
506 setup_us,
507 trans_us,
508 total_us,
509 1000*1000 / total_us,
510 total_bytes,
511 total_bytes * 1000 / total_us);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200512}
513#else
Tomi Valkeinen4a9a5e32011-05-23 16:36:09 +0300514static inline void dsi_perf_mark_setup(struct platform_device *dsidev)
515{
516}
517
518static inline void dsi_perf_mark_start(struct platform_device *dsidev)
519{
520}
521
522static inline void dsi_perf_show(struct platform_device *dsidev,
523 const char *name)
524{
525}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200526#endif
527
Chandrabhanu Mahapatraf30be7d2012-09-29 12:33:05 +0530528static int verbose_irq;
529
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200530static void print_irq_status(u32 status)
531{
Tomi Valkeinend80d4992011-03-02 15:53:07 +0200532 if (status == 0)
533 return;
534
Chandrabhanu Mahapatraf30be7d2012-09-29 12:33:05 +0530535 if (!verbose_irq && (status & ~DSI_IRQ_CHANNEL_MASK) == 0)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200536 return;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200537
Chandrabhanu Mahapatraf30be7d2012-09-29 12:33:05 +0530538#define PIS(x) (status & DSI_IRQ_##x) ? (#x " ") : ""
539
540 pr_debug("DSI IRQ: 0x%x: %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
541 status,
542 verbose_irq ? PIS(VC0) : "",
543 verbose_irq ? PIS(VC1) : "",
544 verbose_irq ? PIS(VC2) : "",
545 verbose_irq ? PIS(VC3) : "",
546 PIS(WAKEUP),
547 PIS(RESYNC),
548 PIS(PLL_LOCK),
549 PIS(PLL_UNLOCK),
550 PIS(PLL_RECALL),
551 PIS(COMPLEXIO_ERR),
552 PIS(HS_TX_TIMEOUT),
553 PIS(LP_RX_TIMEOUT),
554 PIS(TE_TRIGGER),
555 PIS(ACK_TRIGGER),
556 PIS(SYNC_LOST),
557 PIS(LDO_POWER_GOOD),
558 PIS(TA_TIMEOUT));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200559#undef PIS
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200560}
561
562static void print_irq_status_vc(int channel, u32 status)
563{
Tomi Valkeinend80d4992011-03-02 15:53:07 +0200564 if (status == 0)
565 return;
566
Chandrabhanu Mahapatraf30be7d2012-09-29 12:33:05 +0530567 if (!verbose_irq && (status & ~DSI_VC_IRQ_PACKET_SENT) == 0)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200568 return;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200569
Chandrabhanu Mahapatraf30be7d2012-09-29 12:33:05 +0530570#define PIS(x) (status & DSI_VC_IRQ_##x) ? (#x " ") : ""
571
572 pr_debug("DSI VC(%d) IRQ 0x%x: %s%s%s%s%s%s%s%s%s\n",
573 channel,
574 status,
575 PIS(CS),
576 PIS(ECC_CORR),
577 PIS(ECC_NO_CORR),
578 verbose_irq ? PIS(PACKET_SENT) : "",
579 PIS(BTA),
580 PIS(FIFO_TX_OVF),
581 PIS(FIFO_RX_OVF),
582 PIS(FIFO_TX_UDF),
583 PIS(PP_BUSY_CHANGE));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200584#undef PIS
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200585}
586
587static void print_irq_status_cio(u32 status)
588{
Tomi Valkeinend80d4992011-03-02 15:53:07 +0200589 if (status == 0)
590 return;
591
Chandrabhanu Mahapatraf30be7d2012-09-29 12:33:05 +0530592#define PIS(x) (status & DSI_CIO_IRQ_##x) ? (#x " ") : ""
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200593
Chandrabhanu Mahapatraf30be7d2012-09-29 12:33:05 +0530594 pr_debug("DSI CIO IRQ 0x%x: %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
595 status,
596 PIS(ERRSYNCESC1),
597 PIS(ERRSYNCESC2),
598 PIS(ERRSYNCESC3),
599 PIS(ERRESC1),
600 PIS(ERRESC2),
601 PIS(ERRESC3),
602 PIS(ERRCONTROL1),
603 PIS(ERRCONTROL2),
604 PIS(ERRCONTROL3),
605 PIS(STATEULPS1),
606 PIS(STATEULPS2),
607 PIS(STATEULPS3),
608 PIS(ERRCONTENTIONLP0_1),
609 PIS(ERRCONTENTIONLP1_1),
610 PIS(ERRCONTENTIONLP0_2),
611 PIS(ERRCONTENTIONLP1_2),
612 PIS(ERRCONTENTIONLP0_3),
613 PIS(ERRCONTENTIONLP1_3),
614 PIS(ULPSACTIVENOT_ALL0),
615 PIS(ULPSACTIVENOT_ALL1));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200616#undef PIS
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200617}
618
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200619#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530620static void dsi_collect_irq_stats(struct platform_device *dsidev, u32 irqstatus,
621 u32 *vcstatus, u32 ciostatus)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200622{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530623 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200624 int i;
625
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530626 spin_lock(&dsi->irq_stats_lock);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200627
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530628 dsi->irq_stats.irq_count++;
629 dss_collect_irq_stats(irqstatus, dsi->irq_stats.dsi_irqs);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200630
631 for (i = 0; i < 4; ++i)
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530632 dss_collect_irq_stats(vcstatus[i], dsi->irq_stats.vc_irqs[i]);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200633
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530634 dss_collect_irq_stats(ciostatus, dsi->irq_stats.cio_irqs);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200635
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530636 spin_unlock(&dsi->irq_stats_lock);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200637}
638#else
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530639#define dsi_collect_irq_stats(dsidev, irqstatus, vcstatus, ciostatus)
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200640#endif
641
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200642static int debug_irq;
643
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530644static void dsi_handle_irq_errors(struct platform_device *dsidev, u32 irqstatus,
645 u32 *vcstatus, u32 ciostatus)
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200646{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530647 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200648 int i;
649
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200650 if (irqstatus & DSI_IRQ_ERROR_MASK) {
651 DSSERR("DSI error, irqstatus %x\n", irqstatus);
652 print_irq_status(irqstatus);
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530653 spin_lock(&dsi->errors_lock);
654 dsi->errors |= irqstatus & DSI_IRQ_ERROR_MASK;
655 spin_unlock(&dsi->errors_lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200656 } else if (debug_irq) {
657 print_irq_status(irqstatus);
658 }
659
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200660 for (i = 0; i < 4; ++i) {
661 if (vcstatus[i] & DSI_VC_IRQ_ERROR_MASK) {
662 DSSERR("DSI VC(%d) error, vc irqstatus %x\n",
663 i, vcstatus[i]);
664 print_irq_status_vc(i, vcstatus[i]);
665 } else if (debug_irq) {
666 print_irq_status_vc(i, vcstatus[i]);
667 }
668 }
669
670 if (ciostatus & DSI_CIO_IRQ_ERROR_MASK) {
671 DSSERR("DSI CIO error, cio irqstatus %x\n", ciostatus);
672 print_irq_status_cio(ciostatus);
673 } else if (debug_irq) {
674 print_irq_status_cio(ciostatus);
675 }
676}
677
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200678static void dsi_call_isrs(struct dsi_isr_data *isr_array,
679 unsigned isr_array_size, u32 irqstatus)
680{
681 struct dsi_isr_data *isr_data;
682 int i;
683
684 for (i = 0; i < isr_array_size; i++) {
685 isr_data = &isr_array[i];
686 if (isr_data->isr && isr_data->mask & irqstatus)
687 isr_data->isr(isr_data->arg, irqstatus);
688 }
689}
690
691static void dsi_handle_isrs(struct dsi_isr_tables *isr_tables,
692 u32 irqstatus, u32 *vcstatus, u32 ciostatus)
693{
694 int i;
695
696 dsi_call_isrs(isr_tables->isr_table,
697 ARRAY_SIZE(isr_tables->isr_table),
698 irqstatus);
699
700 for (i = 0; i < 4; ++i) {
701 if (vcstatus[i] == 0)
702 continue;
703 dsi_call_isrs(isr_tables->isr_table_vc[i],
704 ARRAY_SIZE(isr_tables->isr_table_vc[i]),
705 vcstatus[i]);
706 }
707
708 if (ciostatus != 0)
709 dsi_call_isrs(isr_tables->isr_table_cio,
710 ARRAY_SIZE(isr_tables->isr_table_cio),
711 ciostatus);
712}
713
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200714static irqreturn_t omap_dsi_irq_handler(int irq, void *arg)
715{
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530716 struct platform_device *dsidev;
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530717 struct dsi_data *dsi;
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200718 u32 irqstatus, vcstatus[4], ciostatus;
719 int i;
720
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530721 dsidev = (struct platform_device *) arg;
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530722 dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530723
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530724 spin_lock(&dsi->irq_lock);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200725
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530726 irqstatus = dsi_read_reg(dsidev, DSI_IRQSTATUS);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200727
728 /* IRQ is not for us */
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200729 if (!irqstatus) {
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530730 spin_unlock(&dsi->irq_lock);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200731 return IRQ_NONE;
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200732 }
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200733
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530734 dsi_write_reg(dsidev, DSI_IRQSTATUS, irqstatus & ~DSI_IRQ_CHANNEL_MASK);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200735 /* flush posted write */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530736 dsi_read_reg(dsidev, DSI_IRQSTATUS);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200737
738 for (i = 0; i < 4; ++i) {
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200739 if ((irqstatus & (1 << i)) == 0) {
740 vcstatus[i] = 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200741 continue;
Tomi Valkeinenab83b142010-06-09 15:31:01 +0300742 }
743
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530744 vcstatus[i] = dsi_read_reg(dsidev, DSI_VC_IRQSTATUS(i));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200745
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530746 dsi_write_reg(dsidev, DSI_VC_IRQSTATUS(i), vcstatus[i]);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200747 /* flush posted write */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530748 dsi_read_reg(dsidev, DSI_VC_IRQSTATUS(i));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200749 }
750
751 if (irqstatus & DSI_IRQ_COMPLEXIO_ERR) {
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530752 ciostatus = dsi_read_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200753
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530754 dsi_write_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS, ciostatus);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200755 /* flush posted write */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530756 dsi_read_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200757 } else {
758 ciostatus = 0;
759 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200760
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200761#ifdef DSI_CATCH_MISSING_TE
762 if (irqstatus & DSI_IRQ_TE_TRIGGER)
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530763 del_timer(&dsi->te_timer);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200764#endif
765
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200766 /* make a copy and unlock, so that isrs can unregister
767 * themselves */
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530768 memcpy(&dsi->isr_tables_copy, &dsi->isr_tables,
769 sizeof(dsi->isr_tables));
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200770
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530771 spin_unlock(&dsi->irq_lock);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200772
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530773 dsi_handle_isrs(&dsi->isr_tables_copy, irqstatus, vcstatus, ciostatus);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200774
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530775 dsi_handle_irq_errors(dsidev, irqstatus, vcstatus, ciostatus);
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200776
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530777 dsi_collect_irq_stats(dsidev, irqstatus, vcstatus, ciostatus);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200778
archit tanejaaffe3602011-02-23 08:41:03 +0000779 return IRQ_HANDLED;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200780}
781
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530782/* dsi->irq_lock has to be locked by the caller */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530783static void _omap_dsi_configure_irqs(struct platform_device *dsidev,
784 struct dsi_isr_data *isr_array,
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200785 unsigned isr_array_size, u32 default_mask,
786 const struct dsi_reg enable_reg,
787 const struct dsi_reg status_reg)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200788{
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200789 struct dsi_isr_data *isr_data;
790 u32 mask;
791 u32 old_mask;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200792 int i;
793
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200794 mask = default_mask;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200795
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200796 for (i = 0; i < isr_array_size; i++) {
797 isr_data = &isr_array[i];
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200798
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200799 if (isr_data->isr == NULL)
800 continue;
801
802 mask |= isr_data->mask;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200803 }
804
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530805 old_mask = dsi_read_reg(dsidev, enable_reg);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200806 /* clear the irqstatus for newly enabled irqs */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530807 dsi_write_reg(dsidev, status_reg, (mask ^ old_mask) & mask);
808 dsi_write_reg(dsidev, enable_reg, mask);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200809
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200810 /* flush posted writes */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530811 dsi_read_reg(dsidev, enable_reg);
812 dsi_read_reg(dsidev, status_reg);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200813}
814
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530815/* dsi->irq_lock has to be locked by the caller */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530816static void _omap_dsi_set_irqs(struct platform_device *dsidev)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200817{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530818 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200819 u32 mask = DSI_IRQ_ERROR_MASK;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200820#ifdef DSI_CATCH_MISSING_TE
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200821 mask |= DSI_IRQ_TE_TRIGGER;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200822#endif
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530823 _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table,
824 ARRAY_SIZE(dsi->isr_tables.isr_table), mask,
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200825 DSI_IRQENABLE, DSI_IRQSTATUS);
826}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200827
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530828/* dsi->irq_lock has to be locked by the caller */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530829static void _omap_dsi_set_irqs_vc(struct platform_device *dsidev, int vc)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200830{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530831 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
832
833 _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table_vc[vc],
834 ARRAY_SIZE(dsi->isr_tables.isr_table_vc[vc]),
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200835 DSI_VC_IRQ_ERROR_MASK,
836 DSI_VC_IRQENABLE(vc), DSI_VC_IRQSTATUS(vc));
837}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200838
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530839/* dsi->irq_lock has to be locked by the caller */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530840static void _omap_dsi_set_irqs_cio(struct platform_device *dsidev)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200841{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530842 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
843
844 _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table_cio,
845 ARRAY_SIZE(dsi->isr_tables.isr_table_cio),
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200846 DSI_CIO_IRQ_ERROR_MASK,
847 DSI_COMPLEXIO_IRQ_ENABLE, DSI_COMPLEXIO_IRQ_STATUS);
848}
849
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530850static void _dsi_initialize_irq(struct platform_device *dsidev)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200851{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530852 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200853 unsigned long flags;
854 int vc;
855
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530856 spin_lock_irqsave(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200857
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530858 memset(&dsi->isr_tables, 0, sizeof(dsi->isr_tables));
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200859
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530860 _omap_dsi_set_irqs(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200861 for (vc = 0; vc < 4; ++vc)
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530862 _omap_dsi_set_irqs_vc(dsidev, vc);
863 _omap_dsi_set_irqs_cio(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200864
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530865 spin_unlock_irqrestore(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200866}
867
868static int _dsi_register_isr(omap_dsi_isr_t isr, void *arg, u32 mask,
869 struct dsi_isr_data *isr_array, unsigned isr_array_size)
870{
871 struct dsi_isr_data *isr_data;
872 int free_idx;
873 int i;
874
875 BUG_ON(isr == NULL);
876
877 /* check for duplicate entry and find a free slot */
878 free_idx = -1;
879 for (i = 0; i < isr_array_size; i++) {
880 isr_data = &isr_array[i];
881
882 if (isr_data->isr == isr && isr_data->arg == arg &&
883 isr_data->mask == mask) {
884 return -EINVAL;
885 }
886
887 if (isr_data->isr == NULL && free_idx == -1)
888 free_idx = i;
889 }
890
891 if (free_idx == -1)
892 return -EBUSY;
893
894 isr_data = &isr_array[free_idx];
895 isr_data->isr = isr;
896 isr_data->arg = arg;
897 isr_data->mask = mask;
898
899 return 0;
900}
901
902static int _dsi_unregister_isr(omap_dsi_isr_t isr, void *arg, u32 mask,
903 struct dsi_isr_data *isr_array, unsigned isr_array_size)
904{
905 struct dsi_isr_data *isr_data;
906 int i;
907
908 for (i = 0; i < isr_array_size; i++) {
909 isr_data = &isr_array[i];
910 if (isr_data->isr != isr || isr_data->arg != arg ||
911 isr_data->mask != mask)
912 continue;
913
914 isr_data->isr = NULL;
915 isr_data->arg = NULL;
916 isr_data->mask = 0;
917
918 return 0;
919 }
920
921 return -EINVAL;
922}
923
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530924static int dsi_register_isr(struct platform_device *dsidev, omap_dsi_isr_t isr,
925 void *arg, u32 mask)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200926{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530927 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200928 unsigned long flags;
929 int r;
930
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530931 spin_lock_irqsave(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200932
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530933 r = _dsi_register_isr(isr, arg, mask, dsi->isr_tables.isr_table,
934 ARRAY_SIZE(dsi->isr_tables.isr_table));
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200935
936 if (r == 0)
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530937 _omap_dsi_set_irqs(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200938
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530939 spin_unlock_irqrestore(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200940
941 return r;
942}
943
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530944static int dsi_unregister_isr(struct platform_device *dsidev,
945 omap_dsi_isr_t isr, void *arg, u32 mask)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200946{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530947 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200948 unsigned long flags;
949 int r;
950
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530951 spin_lock_irqsave(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200952
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530953 r = _dsi_unregister_isr(isr, arg, mask, dsi->isr_tables.isr_table,
954 ARRAY_SIZE(dsi->isr_tables.isr_table));
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200955
956 if (r == 0)
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530957 _omap_dsi_set_irqs(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200958
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530959 spin_unlock_irqrestore(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200960
961 return r;
962}
963
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530964static int dsi_register_isr_vc(struct platform_device *dsidev, int channel,
965 omap_dsi_isr_t isr, void *arg, u32 mask)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200966{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530967 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200968 unsigned long flags;
969 int r;
970
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530971 spin_lock_irqsave(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200972
973 r = _dsi_register_isr(isr, arg, mask,
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530974 dsi->isr_tables.isr_table_vc[channel],
975 ARRAY_SIZE(dsi->isr_tables.isr_table_vc[channel]));
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200976
977 if (r == 0)
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530978 _omap_dsi_set_irqs_vc(dsidev, channel);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200979
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530980 spin_unlock_irqrestore(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200981
982 return r;
983}
984
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530985static int dsi_unregister_isr_vc(struct platform_device *dsidev, int channel,
986 omap_dsi_isr_t isr, void *arg, u32 mask)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200987{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530988 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200989 unsigned long flags;
990 int r;
991
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530992 spin_lock_irqsave(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200993
994 r = _dsi_unregister_isr(isr, arg, mask,
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530995 dsi->isr_tables.isr_table_vc[channel],
996 ARRAY_SIZE(dsi->isr_tables.isr_table_vc[channel]));
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200997
998 if (r == 0)
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530999 _omap_dsi_set_irqs_vc(dsidev, channel);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001000
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301001 spin_unlock_irqrestore(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001002
1003 return r;
1004}
1005
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301006static int dsi_register_isr_cio(struct platform_device *dsidev,
1007 omap_dsi_isr_t isr, void *arg, u32 mask)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001008{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301009 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001010 unsigned long flags;
1011 int r;
1012
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301013 spin_lock_irqsave(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001014
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301015 r = _dsi_register_isr(isr, arg, mask, dsi->isr_tables.isr_table_cio,
1016 ARRAY_SIZE(dsi->isr_tables.isr_table_cio));
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001017
1018 if (r == 0)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301019 _omap_dsi_set_irqs_cio(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001020
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301021 spin_unlock_irqrestore(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001022
1023 return r;
1024}
1025
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301026static int dsi_unregister_isr_cio(struct platform_device *dsidev,
1027 omap_dsi_isr_t isr, void *arg, u32 mask)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001028{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301029 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001030 unsigned long flags;
1031 int r;
1032
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301033 spin_lock_irqsave(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001034
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301035 r = _dsi_unregister_isr(isr, arg, mask, dsi->isr_tables.isr_table_cio,
1036 ARRAY_SIZE(dsi->isr_tables.isr_table_cio));
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001037
1038 if (r == 0)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301039 _omap_dsi_set_irqs_cio(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001040
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301041 spin_unlock_irqrestore(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001042
1043 return r;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001044}
1045
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301046static u32 dsi_get_errors(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001047{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301048 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001049 unsigned long flags;
1050 u32 e;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301051 spin_lock_irqsave(&dsi->errors_lock, flags);
1052 e = dsi->errors;
1053 dsi->errors = 0;
1054 spin_unlock_irqrestore(&dsi->errors_lock, flags);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001055 return e;
1056}
1057
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001058int dsi_runtime_get(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001059{
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001060 int r;
1061 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1062
1063 DSSDBG("dsi_runtime_get\n");
1064
1065 r = pm_runtime_get_sync(&dsi->pdev->dev);
1066 WARN_ON(r < 0);
1067 return r < 0 ? r : 0;
1068}
1069
1070void dsi_runtime_put(struct platform_device *dsidev)
1071{
1072 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1073 int r;
1074
1075 DSSDBG("dsi_runtime_put\n");
1076
Tomi Valkeinen0eaf9f52012-01-23 13:23:08 +02001077 r = pm_runtime_put_sync(&dsi->pdev->dev);
Tomi Valkeinen5be3aeb2012-06-27 16:37:18 +03001078 WARN_ON(r < 0 && r != -ENOSYS);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001079}
1080
1081/* source clock for DSI PLL. this could also be PCLKFREE */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301082static inline void dsi_enable_pll_clock(struct platform_device *dsidev,
1083 bool enable)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001084{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301085 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1086
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001087 if (enable)
Rajendra Nayakf11766d2012-06-27 14:21:26 +05301088 clk_prepare_enable(dsi->sys_clk);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001089 else
Rajendra Nayakf11766d2012-06-27 14:21:26 +05301090 clk_disable_unprepare(dsi->sys_clk);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001091
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301092 if (enable && dsi->pll_locked) {
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301093 if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 1, 1) != 1)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001094 DSSERR("cannot lock PLL when enabling clocks\n");
1095 }
1096}
1097
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301098static void _dsi_print_reset_status(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001099{
1100 u32 l;
Tomi Valkeinenc335cbf2010-10-07 13:27:42 +03001101 int b0, b1, b2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001102
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001103 /* A dummy read using the SCP interface to any DSIPHY register is
1104 * required after DSIPHY reset to complete the reset of the DSI complex
1105 * I/O. */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301106 l = dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001107
Tomi Valkeinenc335cbf2010-10-07 13:27:42 +03001108 if (dss_has_feature(FEAT_DSI_REVERSE_TXCLKESC)) {
1109 b0 = 28;
1110 b1 = 27;
1111 b2 = 26;
1112 } else {
1113 b0 = 24;
1114 b1 = 25;
1115 b2 = 26;
1116 }
1117
Chandrabhanu Mahapatraf30be7d2012-09-29 12:33:05 +05301118#define DSI_FLD_GET(fld, start, end)\
1119 FLD_GET(dsi_read_reg(dsidev, DSI_##fld), start, end)
1120
1121 pr_debug("DSI resets: PLL (%d) CIO (%d) PHY (%x%x%x, %d, %d, %d)\n",
1122 DSI_FLD_GET(PLL_STATUS, 0, 0),
1123 DSI_FLD_GET(COMPLEXIO_CFG1, 29, 29),
1124 DSI_FLD_GET(DSIPHY_CFG5, b0, b0),
1125 DSI_FLD_GET(DSIPHY_CFG5, b1, b1),
1126 DSI_FLD_GET(DSIPHY_CFG5, b2, b2),
1127 DSI_FLD_GET(DSIPHY_CFG5, 29, 29),
1128 DSI_FLD_GET(DSIPHY_CFG5, 30, 30),
1129 DSI_FLD_GET(DSIPHY_CFG5, 31, 31));
1130
1131#undef DSI_FLD_GET
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001132}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001133
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301134static inline int dsi_if_enable(struct platform_device *dsidev, bool enable)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001135{
1136 DSSDBG("dsi_if_enable(%d)\n", enable);
1137
1138 enable = enable ? 1 : 0;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301139 REG_FLD_MOD(dsidev, DSI_CTRL, enable, 0, 0); /* IF_EN */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001140
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301141 if (wait_for_bit_change(dsidev, DSI_CTRL, 0, enable) != enable) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001142 DSSERR("Failed to set dsi_if_enable to %d\n", enable);
1143 return -EIO;
1144 }
1145
1146 return 0;
1147}
1148
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301149unsigned long dsi_get_pll_hsdiv_dispc_rate(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001150{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301151 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1152
1153 return dsi->current_cinfo.dsi_pll_hsdiv_dispc_clk;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001154}
1155
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301156static unsigned long dsi_get_pll_hsdiv_dsi_rate(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001157{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301158 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1159
1160 return dsi->current_cinfo.dsi_pll_hsdiv_dsi_clk;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001161}
1162
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301163static unsigned long dsi_get_txbyteclkhs(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.clkin4ddr / 16;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001168}
1169
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301170static unsigned long dsi_fclk_rate(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001171{
1172 unsigned long r;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001173 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001174
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02001175 if (dss_get_dsi_clk_source(dsi->module_id) == OMAP_DSS_CLK_SRC_FCK) {
Archit Taneja1bb47832011-02-24 14:17:30 +05301176 /* DSI FCLK source is DSS_CLK_FCK */
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001177 r = clk_get_rate(dsi->dss_clk);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001178 } else {
Archit Taneja1bb47832011-02-24 14:17:30 +05301179 /* DSI FCLK source is dsi_pll_hsdiv_dsi_clk */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301180 r = dsi_get_pll_hsdiv_dsi_rate(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001181 }
1182
1183 return r;
1184}
1185
1186static int dsi_set_lp_clk_divisor(struct omap_dss_device *dssdev)
1187{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301188 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301189 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001190 unsigned long dsi_fclk;
1191 unsigned lp_clk_div;
1192 unsigned long lp_clk;
1193
Tomi Valkeinenc6940a32011-02-22 13:36:10 +02001194 lp_clk_div = dssdev->clocks.dsi.lp_clk_div;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001195
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301196 if (lp_clk_div == 0 || lp_clk_div > dsi->lpdiv_max)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001197 return -EINVAL;
1198
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301199 dsi_fclk = dsi_fclk_rate(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001200
1201 lp_clk = dsi_fclk / 2 / lp_clk_div;
1202
1203 DSSDBG("LP_CLK_DIV %u, LP_CLK %lu\n", lp_clk_div, lp_clk);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301204 dsi->current_cinfo.lp_clk = lp_clk;
1205 dsi->current_cinfo.lp_clk_div = lp_clk_div;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001206
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301207 /* LP_CLK_DIVISOR */
1208 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, lp_clk_div, 12, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001209
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301210 /* LP_RX_SYNCHRO_ENABLE */
1211 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, dsi_fclk > 30000000 ? 1 : 0, 21, 21);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001212
1213 return 0;
1214}
1215
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301216static void dsi_enable_scp_clk(struct platform_device *dsidev)
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +03001217{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301218 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1219
1220 if (dsi->scp_clk_refcount++ == 0)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301221 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 1, 14, 14); /* CIO_CLK_ICG */
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +03001222}
1223
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301224static void dsi_disable_scp_clk(struct platform_device *dsidev)
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +03001225{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301226 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1227
1228 WARN_ON(dsi->scp_clk_refcount == 0);
1229 if (--dsi->scp_clk_refcount == 0)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301230 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 14, 14); /* CIO_CLK_ICG */
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +03001231}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001232
1233enum dsi_pll_power_state {
1234 DSI_PLL_POWER_OFF = 0x0,
1235 DSI_PLL_POWER_ON_HSCLK = 0x1,
1236 DSI_PLL_POWER_ON_ALL = 0x2,
1237 DSI_PLL_POWER_ON_DIV = 0x3,
1238};
1239
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301240static int dsi_pll_power(struct platform_device *dsidev,
1241 enum dsi_pll_power_state state)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001242{
1243 int t = 0;
1244
Tomi Valkeinenc94dfe052011-04-15 10:42:59 +03001245 /* DSI-PLL power command 0x3 is not working */
1246 if (dss_has_feature(FEAT_DSI_PLL_PWR_BUG) &&
1247 state == DSI_PLL_POWER_ON_DIV)
1248 state = DSI_PLL_POWER_ON_ALL;
1249
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301250 /* PLL_PWR_CMD */
1251 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, state, 31, 30);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001252
1253 /* PLL_PWR_STATUS */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301254 while (FLD_GET(dsi_read_reg(dsidev, DSI_CLK_CTRL), 29, 28) != state) {
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02001255 if (++t > 1000) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001256 DSSERR("Failed to set DSI PLL power mode to %d\n",
1257 state);
1258 return -ENODEV;
1259 }
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02001260 udelay(1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001261 }
1262
1263 return 0;
1264}
1265
1266/* calculate clock rates using dividers in cinfo */
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02001267static int dsi_calc_clock_rates(struct platform_device *dsidev,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00001268 struct dsi_clock_info *cinfo)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001269{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301270 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1271
1272 if (cinfo->regn == 0 || cinfo->regn > dsi->regn_max)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001273 return -EINVAL;
1274
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301275 if (cinfo->regm == 0 || cinfo->regm > dsi->regm_max)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001276 return -EINVAL;
1277
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301278 if (cinfo->regm_dispc > dsi->regm_dispc_max)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001279 return -EINVAL;
1280
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301281 if (cinfo->regm_dsi > dsi->regm_dsi_max)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001282 return -EINVAL;
1283
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02001284 cinfo->clkin = clk_get_rate(dsi->sys_clk);
1285 cinfo->fint = cinfo->clkin / cinfo->regn;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001286
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301287 if (cinfo->fint > dsi->fint_max || cinfo->fint < dsi->fint_min)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001288 return -EINVAL;
1289
1290 cinfo->clkin4ddr = 2 * cinfo->regm * cinfo->fint;
1291
1292 if (cinfo->clkin4ddr > 1800 * 1000 * 1000)
1293 return -EINVAL;
1294
Archit Taneja1bb47832011-02-24 14:17:30 +05301295 if (cinfo->regm_dispc > 0)
1296 cinfo->dsi_pll_hsdiv_dispc_clk =
1297 cinfo->clkin4ddr / cinfo->regm_dispc;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001298 else
Archit Taneja1bb47832011-02-24 14:17:30 +05301299 cinfo->dsi_pll_hsdiv_dispc_clk = 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001300
Archit Taneja1bb47832011-02-24 14:17:30 +05301301 if (cinfo->regm_dsi > 0)
1302 cinfo->dsi_pll_hsdiv_dsi_clk =
1303 cinfo->clkin4ddr / cinfo->regm_dsi;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001304 else
Archit Taneja1bb47832011-02-24 14:17:30 +05301305 cinfo->dsi_pll_hsdiv_dsi_clk = 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001306
1307 return 0;
1308}
1309
Archit Taneja6d523e72012-06-21 09:33:55 +05301310int dsi_pll_calc_clock_div_pck(struct platform_device *dsidev,
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301311 unsigned long req_pck, struct dsi_clock_info *dsi_cinfo,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001312 struct dispc_clock_info *dispc_cinfo)
1313{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301314 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001315 struct dsi_clock_info cur, best;
1316 struct dispc_clock_info best_dispc;
1317 int min_fck_per_pck;
1318 int match = 0;
Archit Taneja1bb47832011-02-24 14:17:30 +05301319 unsigned long dss_sys_clk, max_dss_fck;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001320
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001321 dss_sys_clk = clk_get_rate(dsi->sys_clk);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001322
Taneja, Archit31ef8232011-03-14 23:28:22 -05001323 max_dss_fck = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK);
Archit Taneja819d8072011-03-01 11:54:00 +05301324
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301325 if (req_pck == dsi->cache_req_pck &&
1326 dsi->cache_cinfo.clkin == dss_sys_clk) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001327 DSSDBG("DSI clock info found from cache\n");
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301328 *dsi_cinfo = dsi->cache_cinfo;
Archit Taneja6d523e72012-06-21 09:33:55 +05301329 dispc_find_clk_divs(req_pck, dsi_cinfo->dsi_pll_hsdiv_dispc_clk,
1330 dispc_cinfo);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001331 return 0;
1332 }
1333
1334 min_fck_per_pck = CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK;
1335
1336 if (min_fck_per_pck &&
Archit Taneja819d8072011-03-01 11:54:00 +05301337 req_pck * min_fck_per_pck > max_dss_fck) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001338 DSSERR("Requested pixel clock not possible with the current "
1339 "OMAP2_DSS_MIN_FCK_PER_PCK setting. Turning "
1340 "the constraint off.\n");
1341 min_fck_per_pck = 0;
1342 }
1343
1344 DSSDBG("dsi_pll_calc\n");
1345
1346retry:
1347 memset(&best, 0, sizeof(best));
1348 memset(&best_dispc, 0, sizeof(best_dispc));
1349
1350 memset(&cur, 0, sizeof(cur));
Archit Taneja1bb47832011-02-24 14:17:30 +05301351 cur.clkin = dss_sys_clk;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001352
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02001353 /* 0.75MHz < Fint = clkin / regn < 2.1MHz */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001354 /* To reduce PLL lock time, keep Fint high (around 2 MHz) */
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301355 for (cur.regn = 1; cur.regn < dsi->regn_max; ++cur.regn) {
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02001356 cur.fint = cur.clkin / cur.regn;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001357
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301358 if (cur.fint > dsi->fint_max || cur.fint < dsi->fint_min)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001359 continue;
1360
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02001361 /* DSIPHY(MHz) = (2 * regm / regn) * clkin */
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301362 for (cur.regm = 1; cur.regm < dsi->regm_max; ++cur.regm) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001363 unsigned long a, b;
1364
1365 a = 2 * cur.regm * (cur.clkin/1000);
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02001366 b = cur.regn;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001367 cur.clkin4ddr = a / b * 1000;
1368
1369 if (cur.clkin4ddr > 1800 * 1000 * 1000)
1370 break;
1371
Archit Taneja1bb47832011-02-24 14:17:30 +05301372 /* dsi_pll_hsdiv_dispc_clk(MHz) =
1373 * DSIPHY(MHz) / regm_dispc < 173MHz/186Mhz */
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301374 for (cur.regm_dispc = 1; cur.regm_dispc <
1375 dsi->regm_dispc_max; ++cur.regm_dispc) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001376 struct dispc_clock_info cur_dispc;
Archit Taneja1bb47832011-02-24 14:17:30 +05301377 cur.dsi_pll_hsdiv_dispc_clk =
1378 cur.clkin4ddr / cur.regm_dispc;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001379
1380 /* this will narrow down the search a bit,
1381 * but still give pixclocks below what was
1382 * requested */
Archit Taneja1bb47832011-02-24 14:17:30 +05301383 if (cur.dsi_pll_hsdiv_dispc_clk < req_pck)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001384 break;
1385
Archit Taneja1bb47832011-02-24 14:17:30 +05301386 if (cur.dsi_pll_hsdiv_dispc_clk > max_dss_fck)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001387 continue;
1388
1389 if (min_fck_per_pck &&
Archit Taneja1bb47832011-02-24 14:17:30 +05301390 cur.dsi_pll_hsdiv_dispc_clk <
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001391 req_pck * min_fck_per_pck)
1392 continue;
1393
1394 match = 1;
1395
Archit Taneja6d523e72012-06-21 09:33:55 +05301396 dispc_find_clk_divs(req_pck,
Archit Taneja1bb47832011-02-24 14:17:30 +05301397 cur.dsi_pll_hsdiv_dispc_clk,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001398 &cur_dispc);
1399
1400 if (abs(cur_dispc.pck - req_pck) <
1401 abs(best_dispc.pck - req_pck)) {
1402 best = cur;
1403 best_dispc = cur_dispc;
1404
1405 if (cur_dispc.pck == req_pck)
1406 goto found;
1407 }
1408 }
1409 }
1410 }
1411found:
1412 if (!match) {
1413 if (min_fck_per_pck) {
1414 DSSERR("Could not find suitable clock settings.\n"
1415 "Turning FCK/PCK constraint off and"
1416 "trying again.\n");
1417 min_fck_per_pck = 0;
1418 goto retry;
1419 }
1420
1421 DSSERR("Could not find suitable clock settings.\n");
1422
1423 return -EINVAL;
1424 }
1425
Archit Taneja1bb47832011-02-24 14:17:30 +05301426 /* dsi_pll_hsdiv_dsi_clk (regm_dsi) is not used */
1427 best.regm_dsi = 0;
1428 best.dsi_pll_hsdiv_dsi_clk = 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001429
1430 if (dsi_cinfo)
1431 *dsi_cinfo = best;
1432 if (dispc_cinfo)
1433 *dispc_cinfo = best_dispc;
1434
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301435 dsi->cache_req_pck = req_pck;
1436 dsi->cache_clk_freq = 0;
1437 dsi->cache_cinfo = best;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001438
1439 return 0;
1440}
1441
Tomi Valkeinenee144e62012-08-10 16:50:51 +03001442static int dsi_pll_calc_ddrfreq(struct platform_device *dsidev,
Tomi Valkeinend66b1582012-09-24 15:15:06 +03001443 unsigned long req_clkin4ddr, struct dsi_clock_info *cinfo)
Tomi Valkeinenee144e62012-08-10 16:50:51 +03001444{
1445 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1446 struct dsi_clock_info cur, best;
Tomi Valkeinenee144e62012-08-10 16:50:51 +03001447
1448 DSSDBG("dsi_pll_calc_ddrfreq\n");
1449
Tomi Valkeinenee144e62012-08-10 16:50:51 +03001450 memset(&best, 0, sizeof(best));
1451 memset(&cur, 0, sizeof(cur));
1452
Tomi Valkeinend66b1582012-09-24 15:15:06 +03001453 cur.clkin = clk_get_rate(dsi->sys_clk);
Tomi Valkeinenee144e62012-08-10 16:50:51 +03001454
1455 for (cur.regn = 1; cur.regn < dsi->regn_max; ++cur.regn) {
1456 cur.fint = cur.clkin / cur.regn;
1457
1458 if (cur.fint > dsi->fint_max || cur.fint < dsi->fint_min)
1459 continue;
1460
1461 /* DSIPHY(MHz) = (2 * regm / regn) * clkin */
1462 for (cur.regm = 1; cur.regm < dsi->regm_max; ++cur.regm) {
1463 unsigned long a, b;
1464
1465 a = 2 * cur.regm * (cur.clkin/1000);
1466 b = cur.regn;
1467 cur.clkin4ddr = a / b * 1000;
1468
1469 if (cur.clkin4ddr > 1800 * 1000 * 1000)
1470 break;
1471
1472 if (abs(cur.clkin4ddr - req_clkin4ddr) <
1473 abs(best.clkin4ddr - req_clkin4ddr)) {
1474 best = cur;
1475 DSSDBG("best %ld\n", best.clkin4ddr);
1476 }
1477
1478 if (cur.clkin4ddr == req_clkin4ddr)
1479 goto found;
1480 }
1481 }
1482found:
Tomi Valkeinenee144e62012-08-10 16:50:51 +03001483 if (cinfo)
1484 *cinfo = best;
1485
1486 return 0;
1487}
1488
Tomi Valkeinend66b1582012-09-24 15:15:06 +03001489static void dsi_pll_calc_dsi_fck(struct platform_device *dsidev,
1490 struct dsi_clock_info *cinfo)
1491{
1492 unsigned long max_dsi_fck;
1493
1494 max_dsi_fck = dss_feat_get_param_max(FEAT_PARAM_DSI_FCK);
1495
1496 cinfo->regm_dsi = DIV_ROUND_UP(cinfo->clkin4ddr, max_dsi_fck);
1497 cinfo->dsi_pll_hsdiv_dsi_clk = cinfo->clkin4ddr / cinfo->regm_dsi;
1498}
1499
1500static int dsi_pll_calc_dispc_fck(struct platform_device *dsidev,
1501 unsigned long req_pck, struct dsi_clock_info *cinfo,
1502 struct dispc_clock_info *dispc_cinfo)
1503{
1504 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1505 unsigned regm_dispc, best_regm_dispc;
1506 unsigned long dispc_clk, best_dispc_clk;
1507 int min_fck_per_pck;
1508 unsigned long max_dss_fck;
1509 struct dispc_clock_info best_dispc;
1510 bool match;
1511
1512 max_dss_fck = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK);
1513
1514 min_fck_per_pck = CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK;
1515
1516 if (min_fck_per_pck &&
1517 req_pck * min_fck_per_pck > max_dss_fck) {
1518 DSSERR("Requested pixel clock not possible with the current "
1519 "OMAP2_DSS_MIN_FCK_PER_PCK setting. Turning "
1520 "the constraint off.\n");
1521 min_fck_per_pck = 0;
1522 }
1523
1524retry:
1525 best_regm_dispc = 0;
1526 best_dispc_clk = 0;
1527 memset(&best_dispc, 0, sizeof(best_dispc));
1528 match = false;
1529
1530 for (regm_dispc = 1; regm_dispc < dsi->regm_dispc_max; ++regm_dispc) {
1531 struct dispc_clock_info cur_dispc;
1532
1533 dispc_clk = cinfo->clkin4ddr / regm_dispc;
1534
1535 /* this will narrow down the search a bit,
1536 * but still give pixclocks below what was
1537 * requested */
1538 if (dispc_clk < req_pck)
1539 break;
1540
1541 if (dispc_clk > max_dss_fck)
1542 continue;
1543
1544 if (min_fck_per_pck && dispc_clk < req_pck * min_fck_per_pck)
1545 continue;
1546
1547 match = true;
1548
1549 dispc_find_clk_divs(req_pck, dispc_clk, &cur_dispc);
1550
1551 if (abs(cur_dispc.pck - req_pck) <
1552 abs(best_dispc.pck - req_pck)) {
1553 best_regm_dispc = regm_dispc;
1554 best_dispc_clk = dispc_clk;
1555 best_dispc = cur_dispc;
1556
1557 if (cur_dispc.pck == req_pck)
1558 goto found;
1559 }
1560 }
1561
1562 if (!match) {
1563 if (min_fck_per_pck) {
1564 DSSERR("Could not find suitable clock settings.\n"
1565 "Turning FCK/PCK constraint off and"
1566 "trying again.\n");
1567 min_fck_per_pck = 0;
1568 goto retry;
1569 }
1570
1571 DSSERR("Could not find suitable clock settings.\n");
1572
1573 return -EINVAL;
1574 }
1575found:
1576 cinfo->regm_dispc = best_regm_dispc;
1577 cinfo->dsi_pll_hsdiv_dispc_clk = best_dispc_clk;
1578
1579 *dispc_cinfo = best_dispc;
1580
1581 return 0;
1582}
1583
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301584int dsi_pll_set_clock_div(struct platform_device *dsidev,
1585 struct dsi_clock_info *cinfo)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001586{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301587 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001588 int r = 0;
1589 u32 l;
Archit Taneja9613c022011-03-22 06:33:36 -05001590 int f = 0;
Taneja, Archit49641112011-03-14 23:28:23 -05001591 u8 regn_start, regn_end, regm_start, regm_end;
1592 u8 regm_dispc_start, regm_dispc_end, regm_dsi_start, regm_dsi_end;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001593
Chandrabhanu Mahapatra702d2672012-09-24 17:12:58 +05301594 DSSDBG("DSI PLL clock config starts");
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001595
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02001596 dsi->current_cinfo.clkin = cinfo->clkin;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301597 dsi->current_cinfo.fint = cinfo->fint;
1598 dsi->current_cinfo.clkin4ddr = cinfo->clkin4ddr;
1599 dsi->current_cinfo.dsi_pll_hsdiv_dispc_clk =
Archit Taneja1bb47832011-02-24 14:17:30 +05301600 cinfo->dsi_pll_hsdiv_dispc_clk;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301601 dsi->current_cinfo.dsi_pll_hsdiv_dsi_clk =
Archit Taneja1bb47832011-02-24 14:17:30 +05301602 cinfo->dsi_pll_hsdiv_dsi_clk;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001603
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301604 dsi->current_cinfo.regn = cinfo->regn;
1605 dsi->current_cinfo.regm = cinfo->regm;
1606 dsi->current_cinfo.regm_dispc = cinfo->regm_dispc;
1607 dsi->current_cinfo.regm_dsi = cinfo->regm_dsi;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001608
1609 DSSDBG("DSI Fint %ld\n", cinfo->fint);
1610
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02001611 DSSDBG("clkin rate %ld\n", cinfo->clkin);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001612
1613 /* DSIPHY == CLKIN4DDR */
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02001614 DSSDBG("CLKIN4DDR = 2 * %d / %d * %lu = %lu\n",
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001615 cinfo->regm,
1616 cinfo->regn,
1617 cinfo->clkin,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001618 cinfo->clkin4ddr);
1619
1620 DSSDBG("Data rate on 1 DSI lane %ld Mbps\n",
1621 cinfo->clkin4ddr / 1000 / 1000 / 2);
1622
1623 DSSDBG("Clock lane freq %ld Hz\n", cinfo->clkin4ddr / 4);
1624
Archit Taneja1bb47832011-02-24 14:17:30 +05301625 DSSDBG("regm_dispc = %d, %s (%s) = %lu\n", cinfo->regm_dispc,
Archit Taneja89a35e52011-04-12 13:52:23 +05301626 dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
1627 dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
Archit Taneja1bb47832011-02-24 14:17:30 +05301628 cinfo->dsi_pll_hsdiv_dispc_clk);
1629 DSSDBG("regm_dsi = %d, %s (%s) = %lu\n", cinfo->regm_dsi,
Archit Taneja89a35e52011-04-12 13:52:23 +05301630 dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
1631 dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
Archit Taneja1bb47832011-02-24 14:17:30 +05301632 cinfo->dsi_pll_hsdiv_dsi_clk);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001633
Taneja, Archit49641112011-03-14 23:28:23 -05001634 dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGN, &regn_start, &regn_end);
1635 dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM, &regm_start, &regm_end);
1636 dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM_DISPC, &regm_dispc_start,
1637 &regm_dispc_end);
1638 dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM_DSI, &regm_dsi_start,
1639 &regm_dsi_end);
1640
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301641 /* DSI_PLL_AUTOMODE = manual */
1642 REG_FLD_MOD(dsidev, DSI_PLL_CONTROL, 0, 0, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001643
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301644 l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001645 l = FLD_MOD(l, 1, 0, 0); /* DSI_PLL_STOPMODE */
Taneja, Archit49641112011-03-14 23:28:23 -05001646 /* DSI_PLL_REGN */
1647 l = FLD_MOD(l, cinfo->regn - 1, regn_start, regn_end);
1648 /* DSI_PLL_REGM */
1649 l = FLD_MOD(l, cinfo->regm, regm_start, regm_end);
1650 /* DSI_CLOCK_DIV */
Archit Taneja1bb47832011-02-24 14:17:30 +05301651 l = FLD_MOD(l, cinfo->regm_dispc > 0 ? cinfo->regm_dispc - 1 : 0,
Taneja, Archit49641112011-03-14 23:28:23 -05001652 regm_dispc_start, regm_dispc_end);
1653 /* DSIPROTO_CLOCK_DIV */
Archit Taneja1bb47832011-02-24 14:17:30 +05301654 l = FLD_MOD(l, cinfo->regm_dsi > 0 ? cinfo->regm_dsi - 1 : 0,
Taneja, Archit49641112011-03-14 23:28:23 -05001655 regm_dsi_start, regm_dsi_end);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301656 dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION1, l);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001657
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301658 BUG_ON(cinfo->fint < dsi->fint_min || cinfo->fint > dsi->fint_max);
Archit Taneja9613c022011-03-22 06:33:36 -05001659
Tomi Valkeinenf8ef3d62012-08-22 16:00:31 +03001660 l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION2);
1661
Archit Taneja9613c022011-03-22 06:33:36 -05001662 if (dss_has_feature(FEAT_DSI_PLL_FREQSEL)) {
1663 f = cinfo->fint < 1000000 ? 0x3 :
1664 cinfo->fint < 1250000 ? 0x4 :
1665 cinfo->fint < 1500000 ? 0x5 :
1666 cinfo->fint < 1750000 ? 0x6 :
1667 0x7;
Tomi Valkeinenf8ef3d62012-08-22 16:00:31 +03001668
1669 l = FLD_MOD(l, f, 4, 1); /* DSI_PLL_FREQSEL */
1670 } else if (dss_has_feature(FEAT_DSI_PLL_SELFREQDCO)) {
1671 f = cinfo->clkin4ddr < 1000000000 ? 0x2 : 0x4;
1672
1673 l = FLD_MOD(l, f, 4, 1); /* PLL_SELFREQDCO */
Archit Taneja9613c022011-03-22 06:33:36 -05001674 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001675
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001676 l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */
1677 l = FLD_MOD(l, 0, 14, 14); /* DSIPHY_CLKINEN */
1678 l = FLD_MOD(l, 1, 20, 20); /* DSI_HSDIVBYPASS */
Tomi Valkeinen6d446102012-08-22 16:00:40 +03001679 if (dss_has_feature(FEAT_DSI_PLL_REFSEL))
1680 l = FLD_MOD(l, 3, 22, 21); /* REF_SYSCLK = sysclk */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301681 dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION2, l);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001682
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301683 REG_FLD_MOD(dsidev, DSI_PLL_GO, 1, 0, 0); /* DSI_PLL_GO */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001684
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301685 if (wait_for_bit_change(dsidev, DSI_PLL_GO, 0, 0) != 0) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001686 DSSERR("dsi pll go bit not going down.\n");
1687 r = -EIO;
1688 goto err;
1689 }
1690
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301691 if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 1, 1) != 1) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001692 DSSERR("cannot lock PLL\n");
1693 r = -EIO;
1694 goto err;
1695 }
1696
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301697 dsi->pll_locked = 1;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001698
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301699 l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION2);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001700 l = FLD_MOD(l, 0, 0, 0); /* DSI_PLL_IDLE */
1701 l = FLD_MOD(l, 0, 5, 5); /* DSI_PLL_PLLLPMODE */
1702 l = FLD_MOD(l, 0, 6, 6); /* DSI_PLL_LOWCURRSTBY */
1703 l = FLD_MOD(l, 0, 7, 7); /* DSI_PLL_TIGHTPHASELOCK */
1704 l = FLD_MOD(l, 0, 8, 8); /* DSI_PLL_DRIFTGUARDEN */
1705 l = FLD_MOD(l, 0, 10, 9); /* DSI_PLL_LOCKSEL */
1706 l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */
1707 l = FLD_MOD(l, 1, 14, 14); /* DSIPHY_CLKINEN */
1708 l = FLD_MOD(l, 0, 15, 15); /* DSI_BYPASSEN */
1709 l = FLD_MOD(l, 1, 16, 16); /* DSS_CLOCK_EN */
1710 l = FLD_MOD(l, 0, 17, 17); /* DSS_CLOCK_PWDN */
1711 l = FLD_MOD(l, 1, 18, 18); /* DSI_PROTO_CLOCK_EN */
1712 l = FLD_MOD(l, 0, 19, 19); /* DSI_PROTO_CLOCK_PWDN */
1713 l = FLD_MOD(l, 0, 20, 20); /* DSI_HSDIVBYPASS */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301714 dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION2, l);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001715
1716 DSSDBG("PLL config done\n");
1717err:
1718 return r;
1719}
1720
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301721int dsi_pll_init(struct platform_device *dsidev, bool enable_hsclk,
1722 bool enable_hsdiv)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001723{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301724 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001725 int r = 0;
1726 enum dsi_pll_power_state pwstate;
1727
1728 DSSDBG("PLL init\n");
1729
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301730 if (dsi->vdds_dsi_reg == NULL) {
Tomi Valkeinenf2988ab2011-03-02 10:06:48 +02001731 struct regulator *vdds_dsi;
1732
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301733 vdds_dsi = regulator_get(&dsi->pdev->dev, "vdds_dsi");
Tomi Valkeinenf2988ab2011-03-02 10:06:48 +02001734
1735 if (IS_ERR(vdds_dsi)) {
1736 DSSERR("can't get VDDS_DSI regulator\n");
1737 return PTR_ERR(vdds_dsi);
1738 }
1739
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301740 dsi->vdds_dsi_reg = vdds_dsi;
Tomi Valkeinenf2988ab2011-03-02 10:06:48 +02001741 }
Tomi Valkeinenf2988ab2011-03-02 10:06:48 +02001742
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301743 dsi_enable_pll_clock(dsidev, 1);
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +03001744 /*
1745 * Note: SCP CLK is not required on OMAP3, but it is required on OMAP4.
1746 */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301747 dsi_enable_scp_clk(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001748
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301749 if (!dsi->vdds_dsi_enabled) {
1750 r = regulator_enable(dsi->vdds_dsi_reg);
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +03001751 if (r)
1752 goto err0;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301753 dsi->vdds_dsi_enabled = true;
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +03001754 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001755
1756 /* XXX PLL does not come out of reset without this... */
1757 dispc_pck_free_enable(1);
1758
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301759 if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 0, 1) != 1) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001760 DSSERR("PLL not coming out of reset.\n");
1761 r = -ENODEV;
Ville Syrjälä481dfa02010-04-22 22:50:04 +02001762 dispc_pck_free_enable(0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001763 goto err1;
1764 }
1765
1766 /* XXX ... but if left on, we get problems when planes do not
1767 * fill the whole display. No idea about this */
1768 dispc_pck_free_enable(0);
1769
1770 if (enable_hsclk && enable_hsdiv)
1771 pwstate = DSI_PLL_POWER_ON_ALL;
1772 else if (enable_hsclk)
1773 pwstate = DSI_PLL_POWER_ON_HSCLK;
1774 else if (enable_hsdiv)
1775 pwstate = DSI_PLL_POWER_ON_DIV;
1776 else
1777 pwstate = DSI_PLL_POWER_OFF;
1778
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301779 r = dsi_pll_power(dsidev, pwstate);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001780
1781 if (r)
1782 goto err1;
1783
1784 DSSDBG("PLL init done\n");
1785
1786 return 0;
1787err1:
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301788 if (dsi->vdds_dsi_enabled) {
1789 regulator_disable(dsi->vdds_dsi_reg);
1790 dsi->vdds_dsi_enabled = false;
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +03001791 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001792err0:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301793 dsi_disable_scp_clk(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301794 dsi_enable_pll_clock(dsidev, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001795 return r;
1796}
1797
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301798void dsi_pll_uninit(struct platform_device *dsidev, bool disconnect_lanes)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001799{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301800 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1801
1802 dsi->pll_locked = 0;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301803 dsi_pll_power(dsidev, DSI_PLL_POWER_OFF);
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +03001804 if (disconnect_lanes) {
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301805 WARN_ON(!dsi->vdds_dsi_enabled);
1806 regulator_disable(dsi->vdds_dsi_reg);
1807 dsi->vdds_dsi_enabled = false;
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +03001808 }
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +03001809
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301810 dsi_disable_scp_clk(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301811 dsi_enable_pll_clock(dsidev, 0);
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +03001812
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001813 DSSDBG("PLL uninit done\n");
1814}
1815
Archit Taneja5a8b5722011-05-12 17:26:29 +05301816static void dsi_dump_dsidev_clocks(struct platform_device *dsidev,
1817 struct seq_file *s)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001818{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301819 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1820 struct dsi_clock_info *cinfo = &dsi->current_cinfo;
Archit Taneja89a35e52011-04-12 13:52:23 +05301821 enum omap_dss_clk_source dispc_clk_src, dsi_clk_src;
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02001822 int dsi_module = dsi->module_id;
Archit Taneja067a57e2011-03-02 11:57:25 +05301823
1824 dispc_clk_src = dss_get_dispc_clk_source();
Archit Taneja5a8b5722011-05-12 17:26:29 +05301825 dsi_clk_src = dss_get_dsi_clk_source(dsi_module);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001826
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001827 if (dsi_runtime_get(dsidev))
1828 return;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001829
Archit Taneja5a8b5722011-05-12 17:26:29 +05301830 seq_printf(s, "- DSI%d PLL -\n", dsi_module + 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001831
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02001832 seq_printf(s, "dsi pll clkin\t%lu\n", cinfo->clkin);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001833
1834 seq_printf(s, "Fint\t\t%-16luregn %u\n", cinfo->fint, cinfo->regn);
1835
1836 seq_printf(s, "CLKIN4DDR\t%-16luregm %u\n",
1837 cinfo->clkin4ddr, cinfo->regm);
1838
Archit Taneja84309f12011-12-12 11:47:41 +05301839 seq_printf(s, "DSI_PLL_HSDIV_DISPC (%s)\t%-16luregm_dispc %u\t(%s)\n",
1840 dss_feat_get_clk_source_name(dsi_module == 0 ?
1841 OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC :
1842 OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC),
Archit Taneja1bb47832011-02-24 14:17:30 +05301843 cinfo->dsi_pll_hsdiv_dispc_clk,
1844 cinfo->regm_dispc,
Archit Taneja89a35e52011-04-12 13:52:23 +05301845 dispc_clk_src == OMAP_DSS_CLK_SRC_FCK ?
Tomi Valkeinen63cf28a2010-02-23 17:40:00 +02001846 "off" : "on");
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001847
Archit Taneja84309f12011-12-12 11:47:41 +05301848 seq_printf(s, "DSI_PLL_HSDIV_DSI (%s)\t%-16luregm_dsi %u\t(%s)\n",
1849 dss_feat_get_clk_source_name(dsi_module == 0 ?
1850 OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI :
1851 OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DSI),
Archit Taneja1bb47832011-02-24 14:17:30 +05301852 cinfo->dsi_pll_hsdiv_dsi_clk,
1853 cinfo->regm_dsi,
Archit Taneja89a35e52011-04-12 13:52:23 +05301854 dsi_clk_src == OMAP_DSS_CLK_SRC_FCK ?
Tomi Valkeinen63cf28a2010-02-23 17:40:00 +02001855 "off" : "on");
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001856
Archit Taneja5a8b5722011-05-12 17:26:29 +05301857 seq_printf(s, "- DSI%d -\n", dsi_module + 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001858
Archit Taneja067a57e2011-03-02 11:57:25 +05301859 seq_printf(s, "dsi fclk source = %s (%s)\n",
1860 dss_get_generic_clk_source_name(dsi_clk_src),
1861 dss_feat_get_clk_source_name(dsi_clk_src));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001862
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301863 seq_printf(s, "DSI_FCLK\t%lu\n", dsi_fclk_rate(dsidev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001864
1865 seq_printf(s, "DDR_CLK\t\t%lu\n",
1866 cinfo->clkin4ddr / 4);
1867
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301868 seq_printf(s, "TxByteClkHS\t%lu\n", dsi_get_txbyteclkhs(dsidev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001869
1870 seq_printf(s, "LP_CLK\t\t%lu\n", cinfo->lp_clk);
1871
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001872 dsi_runtime_put(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001873}
1874
Archit Taneja5a8b5722011-05-12 17:26:29 +05301875void dsi_dump_clocks(struct seq_file *s)
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001876{
Archit Taneja5a8b5722011-05-12 17:26:29 +05301877 struct platform_device *dsidev;
1878 int i;
1879
1880 for (i = 0; i < MAX_NUM_DSI; i++) {
1881 dsidev = dsi_get_dsidev_from_id(i);
1882 if (dsidev)
1883 dsi_dump_dsidev_clocks(dsidev, s);
1884 }
1885}
1886
1887#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
1888static void dsi_dump_dsidev_irqs(struct platform_device *dsidev,
1889 struct seq_file *s)
1890{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301891 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001892 unsigned long flags;
1893 struct dsi_irq_stats stats;
1894
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301895 spin_lock_irqsave(&dsi->irq_stats_lock, flags);
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001896
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301897 stats = dsi->irq_stats;
1898 memset(&dsi->irq_stats, 0, sizeof(dsi->irq_stats));
1899 dsi->irq_stats.last_reset = jiffies;
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001900
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301901 spin_unlock_irqrestore(&dsi->irq_stats_lock, flags);
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001902
1903 seq_printf(s, "period %u ms\n",
1904 jiffies_to_msecs(jiffies - stats.last_reset));
1905
1906 seq_printf(s, "irqs %d\n", stats.irq_count);
1907#define PIS(x) \
1908 seq_printf(s, "%-20s %10d\n", #x, stats.dsi_irqs[ffs(DSI_IRQ_##x)-1]);
1909
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02001910 seq_printf(s, "-- DSI%d interrupts --\n", dsi->module_id + 1);
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001911 PIS(VC0);
1912 PIS(VC1);
1913 PIS(VC2);
1914 PIS(VC3);
1915 PIS(WAKEUP);
1916 PIS(RESYNC);
1917 PIS(PLL_LOCK);
1918 PIS(PLL_UNLOCK);
1919 PIS(PLL_RECALL);
1920 PIS(COMPLEXIO_ERR);
1921 PIS(HS_TX_TIMEOUT);
1922 PIS(LP_RX_TIMEOUT);
1923 PIS(TE_TRIGGER);
1924 PIS(ACK_TRIGGER);
1925 PIS(SYNC_LOST);
1926 PIS(LDO_POWER_GOOD);
1927 PIS(TA_TIMEOUT);
1928#undef PIS
1929
1930#define PIS(x) \
1931 seq_printf(s, "%-20s %10d %10d %10d %10d\n", #x, \
1932 stats.vc_irqs[0][ffs(DSI_VC_IRQ_##x)-1], \
1933 stats.vc_irqs[1][ffs(DSI_VC_IRQ_##x)-1], \
1934 stats.vc_irqs[2][ffs(DSI_VC_IRQ_##x)-1], \
1935 stats.vc_irqs[3][ffs(DSI_VC_IRQ_##x)-1]);
1936
1937 seq_printf(s, "-- VC interrupts --\n");
1938 PIS(CS);
1939 PIS(ECC_CORR);
1940 PIS(PACKET_SENT);
1941 PIS(FIFO_TX_OVF);
1942 PIS(FIFO_RX_OVF);
1943 PIS(BTA);
1944 PIS(ECC_NO_CORR);
1945 PIS(FIFO_TX_UDF);
1946 PIS(PP_BUSY_CHANGE);
1947#undef PIS
1948
1949#define PIS(x) \
1950 seq_printf(s, "%-20s %10d\n", #x, \
1951 stats.cio_irqs[ffs(DSI_CIO_IRQ_##x)-1]);
1952
1953 seq_printf(s, "-- CIO interrupts --\n");
1954 PIS(ERRSYNCESC1);
1955 PIS(ERRSYNCESC2);
1956 PIS(ERRSYNCESC3);
1957 PIS(ERRESC1);
1958 PIS(ERRESC2);
1959 PIS(ERRESC3);
1960 PIS(ERRCONTROL1);
1961 PIS(ERRCONTROL2);
1962 PIS(ERRCONTROL3);
1963 PIS(STATEULPS1);
1964 PIS(STATEULPS2);
1965 PIS(STATEULPS3);
1966 PIS(ERRCONTENTIONLP0_1);
1967 PIS(ERRCONTENTIONLP1_1);
1968 PIS(ERRCONTENTIONLP0_2);
1969 PIS(ERRCONTENTIONLP1_2);
1970 PIS(ERRCONTENTIONLP0_3);
1971 PIS(ERRCONTENTIONLP1_3);
1972 PIS(ULPSACTIVENOT_ALL0);
1973 PIS(ULPSACTIVENOT_ALL1);
1974#undef PIS
1975}
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001976
Archit Taneja5a8b5722011-05-12 17:26:29 +05301977static void dsi1_dump_irqs(struct seq_file *s)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001978{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301979 struct platform_device *dsidev = dsi_get_dsidev_from_id(0);
1980
Archit Taneja5a8b5722011-05-12 17:26:29 +05301981 dsi_dump_dsidev_irqs(dsidev, s);
1982}
1983
1984static void dsi2_dump_irqs(struct seq_file *s)
1985{
1986 struct platform_device *dsidev = dsi_get_dsidev_from_id(1);
1987
1988 dsi_dump_dsidev_irqs(dsidev, s);
1989}
Archit Taneja5a8b5722011-05-12 17:26:29 +05301990#endif
1991
1992static void dsi_dump_dsidev_regs(struct platform_device *dsidev,
1993 struct seq_file *s)
1994{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301995#define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dsi_read_reg(dsidev, r))
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001996
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001997 if (dsi_runtime_get(dsidev))
1998 return;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301999 dsi_enable_scp_clk(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002000
2001 DUMPREG(DSI_REVISION);
2002 DUMPREG(DSI_SYSCONFIG);
2003 DUMPREG(DSI_SYSSTATUS);
2004 DUMPREG(DSI_IRQSTATUS);
2005 DUMPREG(DSI_IRQENABLE);
2006 DUMPREG(DSI_CTRL);
2007 DUMPREG(DSI_COMPLEXIO_CFG1);
2008 DUMPREG(DSI_COMPLEXIO_IRQ_STATUS);
2009 DUMPREG(DSI_COMPLEXIO_IRQ_ENABLE);
2010 DUMPREG(DSI_CLK_CTRL);
2011 DUMPREG(DSI_TIMING1);
2012 DUMPREG(DSI_TIMING2);
2013 DUMPREG(DSI_VM_TIMING1);
2014 DUMPREG(DSI_VM_TIMING2);
2015 DUMPREG(DSI_VM_TIMING3);
2016 DUMPREG(DSI_CLK_TIMING);
2017 DUMPREG(DSI_TX_FIFO_VC_SIZE);
2018 DUMPREG(DSI_RX_FIFO_VC_SIZE);
2019 DUMPREG(DSI_COMPLEXIO_CFG2);
2020 DUMPREG(DSI_RX_FIFO_VC_FULLNESS);
2021 DUMPREG(DSI_VM_TIMING4);
2022 DUMPREG(DSI_TX_FIFO_VC_EMPTINESS);
2023 DUMPREG(DSI_VM_TIMING5);
2024 DUMPREG(DSI_VM_TIMING6);
2025 DUMPREG(DSI_VM_TIMING7);
2026 DUMPREG(DSI_STOPCLK_TIMING);
2027
2028 DUMPREG(DSI_VC_CTRL(0));
2029 DUMPREG(DSI_VC_TE(0));
2030 DUMPREG(DSI_VC_LONG_PACKET_HEADER(0));
2031 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(0));
2032 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(0));
2033 DUMPREG(DSI_VC_IRQSTATUS(0));
2034 DUMPREG(DSI_VC_IRQENABLE(0));
2035
2036 DUMPREG(DSI_VC_CTRL(1));
2037 DUMPREG(DSI_VC_TE(1));
2038 DUMPREG(DSI_VC_LONG_PACKET_HEADER(1));
2039 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(1));
2040 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(1));
2041 DUMPREG(DSI_VC_IRQSTATUS(1));
2042 DUMPREG(DSI_VC_IRQENABLE(1));
2043
2044 DUMPREG(DSI_VC_CTRL(2));
2045 DUMPREG(DSI_VC_TE(2));
2046 DUMPREG(DSI_VC_LONG_PACKET_HEADER(2));
2047 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(2));
2048 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(2));
2049 DUMPREG(DSI_VC_IRQSTATUS(2));
2050 DUMPREG(DSI_VC_IRQENABLE(2));
2051
2052 DUMPREG(DSI_VC_CTRL(3));
2053 DUMPREG(DSI_VC_TE(3));
2054 DUMPREG(DSI_VC_LONG_PACKET_HEADER(3));
2055 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(3));
2056 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(3));
2057 DUMPREG(DSI_VC_IRQSTATUS(3));
2058 DUMPREG(DSI_VC_IRQENABLE(3));
2059
2060 DUMPREG(DSI_DSIPHY_CFG0);
2061 DUMPREG(DSI_DSIPHY_CFG1);
2062 DUMPREG(DSI_DSIPHY_CFG2);
2063 DUMPREG(DSI_DSIPHY_CFG5);
2064
2065 DUMPREG(DSI_PLL_CONTROL);
2066 DUMPREG(DSI_PLL_STATUS);
2067 DUMPREG(DSI_PLL_GO);
2068 DUMPREG(DSI_PLL_CONFIGURATION1);
2069 DUMPREG(DSI_PLL_CONFIGURATION2);
2070
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302071 dsi_disable_scp_clk(dsidev);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03002072 dsi_runtime_put(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002073#undef DUMPREG
2074}
2075
Archit Taneja5a8b5722011-05-12 17:26:29 +05302076static void dsi1_dump_regs(struct seq_file *s)
2077{
2078 struct platform_device *dsidev = dsi_get_dsidev_from_id(0);
2079
2080 dsi_dump_dsidev_regs(dsidev, s);
2081}
2082
2083static void dsi2_dump_regs(struct seq_file *s)
2084{
2085 struct platform_device *dsidev = dsi_get_dsidev_from_id(1);
2086
2087 dsi_dump_dsidev_regs(dsidev, s);
2088}
2089
Tomi Valkeinencc5c1852010-10-06 15:18:13 +03002090enum dsi_cio_power_state {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002091 DSI_COMPLEXIO_POWER_OFF = 0x0,
2092 DSI_COMPLEXIO_POWER_ON = 0x1,
2093 DSI_COMPLEXIO_POWER_ULPS = 0x2,
2094};
2095
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302096static int dsi_cio_power(struct platform_device *dsidev,
2097 enum dsi_cio_power_state state)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002098{
2099 int t = 0;
2100
2101 /* PWR_CMD */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302102 REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG1, state, 28, 27);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002103
2104 /* PWR_STATUS */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302105 while (FLD_GET(dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1),
2106 26, 25) != state) {
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02002107 if (++t > 1000) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002108 DSSERR("failed to set complexio power state to "
2109 "%d\n", state);
2110 return -ENODEV;
2111 }
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02002112 udelay(1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002113 }
2114
2115 return 0;
2116}
2117
Archit Taneja0c656222011-05-16 15:17:09 +05302118static unsigned dsi_get_line_buf_size(struct platform_device *dsidev)
2119{
2120 int val;
2121
2122 /* line buffer on OMAP3 is 1024 x 24bits */
2123 /* XXX: for some reason using full buffer size causes
2124 * considerable TX slowdown with update sizes that fill the
2125 * whole buffer */
2126 if (!dss_has_feature(FEAT_DSI_GNQ))
2127 return 1023 * 3;
2128
2129 val = REG_GET(dsidev, DSI_GNQ, 14, 12); /* VP1_LINE_BUFFER_SIZE */
2130
2131 switch (val) {
2132 case 1:
2133 return 512 * 3; /* 512x24 bits */
2134 case 2:
2135 return 682 * 3; /* 682x24 bits */
2136 case 3:
2137 return 853 * 3; /* 853x24 bits */
2138 case 4:
2139 return 1024 * 3; /* 1024x24 bits */
2140 case 5:
2141 return 1194 * 3; /* 1194x24 bits */
2142 case 6:
2143 return 1365 * 3; /* 1365x24 bits */
Tomi Valkeinen2ac80fb2012-08-22 16:00:47 +03002144 case 7:
2145 return 1920 * 3; /* 1920x24 bits */
Archit Taneja0c656222011-05-16 15:17:09 +05302146 default:
2147 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002148 return 0;
Archit Taneja0c656222011-05-16 15:17:09 +05302149 }
2150}
2151
Archit Taneja9e7e9372012-08-14 12:29:22 +05302152static int dsi_set_lane_config(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002153{
Tomi Valkeinen48368392011-10-13 11:22:39 +03002154 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2155 static const u8 offsets[] = { 0, 4, 8, 12, 16 };
2156 static const enum dsi_lane_function functions[] = {
2157 DSI_LANE_CLK,
2158 DSI_LANE_DATA1,
2159 DSI_LANE_DATA2,
2160 DSI_LANE_DATA3,
2161 DSI_LANE_DATA4,
2162 };
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002163 u32 r;
Tomi Valkeinen48368392011-10-13 11:22:39 +03002164 int i;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002165
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302166 r = dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1);
Archit Taneja75d72472011-05-16 15:17:08 +05302167
Tomi Valkeinen48368392011-10-13 11:22:39 +03002168 for (i = 0; i < dsi->num_lanes_used; ++i) {
2169 unsigned offset = offsets[i];
2170 unsigned polarity, lane_number;
2171 unsigned t;
Archit Taneja75d72472011-05-16 15:17:08 +05302172
Tomi Valkeinen48368392011-10-13 11:22:39 +03002173 for (t = 0; t < dsi->num_lanes_supported; ++t)
2174 if (dsi->lanes[t].function == functions[i])
2175 break;
2176
2177 if (t == dsi->num_lanes_supported)
2178 return -EINVAL;
2179
2180 lane_number = t;
2181 polarity = dsi->lanes[t].polarity;
2182
2183 r = FLD_MOD(r, lane_number + 1, offset + 2, offset);
2184 r = FLD_MOD(r, polarity, offset + 3, offset + 3);
Archit Taneja75d72472011-05-16 15:17:08 +05302185 }
Tomi Valkeinen48368392011-10-13 11:22:39 +03002186
2187 /* clear the unused lanes */
2188 for (; i < dsi->num_lanes_supported; ++i) {
2189 unsigned offset = offsets[i];
2190
2191 r = FLD_MOD(r, 0, offset + 2, offset);
2192 r = FLD_MOD(r, 0, offset + 3, offset + 3);
2193 }
2194
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302195 dsi_write_reg(dsidev, DSI_COMPLEXIO_CFG1, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002196
Tomi Valkeinen48368392011-10-13 11:22:39 +03002197 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002198}
2199
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302200static inline unsigned ns2ddr(struct platform_device *dsidev, unsigned ns)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002201{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302202 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2203
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002204 /* convert time in ns to ddr ticks, rounding up */
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302205 unsigned long ddr_clk = dsi->current_cinfo.clkin4ddr / 4;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002206 return (ns * (ddr_clk / 1000 / 1000) + 999) / 1000;
2207}
2208
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302209static inline unsigned ddr2ns(struct platform_device *dsidev, unsigned ddr)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002210{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302211 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2212
2213 unsigned long ddr_clk = dsi->current_cinfo.clkin4ddr / 4;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002214 return ddr * 1000 * 1000 / (ddr_clk / 1000);
2215}
2216
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302217static void dsi_cio_timings(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002218{
2219 u32 r;
2220 u32 ths_prepare, ths_prepare_ths_zero, ths_trail, ths_exit;
2221 u32 tlpx_half, tclk_trail, tclk_zero;
2222 u32 tclk_prepare;
2223
2224 /* calculate timings */
2225
2226 /* 1 * DDR_CLK = 2 * UI */
2227
2228 /* min 40ns + 4*UI max 85ns + 6*UI */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302229 ths_prepare = ns2ddr(dsidev, 70) + 2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002230
2231 /* min 145ns + 10*UI */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302232 ths_prepare_ths_zero = ns2ddr(dsidev, 175) + 2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002233
2234 /* min max(8*UI, 60ns+4*UI) */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302235 ths_trail = ns2ddr(dsidev, 60) + 5;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002236
2237 /* min 100ns */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302238 ths_exit = ns2ddr(dsidev, 145);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002239
2240 /* tlpx min 50n */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302241 tlpx_half = ns2ddr(dsidev, 25);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002242
2243 /* min 60ns */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302244 tclk_trail = ns2ddr(dsidev, 60) + 2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002245
2246 /* min 38ns, max 95ns */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302247 tclk_prepare = ns2ddr(dsidev, 65);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002248
2249 /* min tclk-prepare + tclk-zero = 300ns */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302250 tclk_zero = ns2ddr(dsidev, 260);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002251
2252 DSSDBG("ths_prepare %u (%uns), ths_prepare_ths_zero %u (%uns)\n",
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302253 ths_prepare, ddr2ns(dsidev, ths_prepare),
2254 ths_prepare_ths_zero, ddr2ns(dsidev, ths_prepare_ths_zero));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002255 DSSDBG("ths_trail %u (%uns), ths_exit %u (%uns)\n",
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302256 ths_trail, ddr2ns(dsidev, ths_trail),
2257 ths_exit, ddr2ns(dsidev, ths_exit));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002258
2259 DSSDBG("tlpx_half %u (%uns), tclk_trail %u (%uns), "
2260 "tclk_zero %u (%uns)\n",
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302261 tlpx_half, ddr2ns(dsidev, tlpx_half),
2262 tclk_trail, ddr2ns(dsidev, tclk_trail),
2263 tclk_zero, ddr2ns(dsidev, tclk_zero));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002264 DSSDBG("tclk_prepare %u (%uns)\n",
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302265 tclk_prepare, ddr2ns(dsidev, tclk_prepare));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002266
2267 /* program timings */
2268
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302269 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002270 r = FLD_MOD(r, ths_prepare, 31, 24);
2271 r = FLD_MOD(r, ths_prepare_ths_zero, 23, 16);
2272 r = FLD_MOD(r, ths_trail, 15, 8);
2273 r = FLD_MOD(r, ths_exit, 7, 0);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302274 dsi_write_reg(dsidev, DSI_DSIPHY_CFG0, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002275
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302276 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1);
Tomi Valkeinene84dc1c2012-09-24 09:34:52 +03002277 r = FLD_MOD(r, tlpx_half, 20, 16);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002278 r = FLD_MOD(r, tclk_trail, 15, 8);
2279 r = FLD_MOD(r, tclk_zero, 7, 0);
Tomi Valkeinen77ccbfb2012-09-24 15:15:57 +03002280
2281 if (dss_has_feature(FEAT_DSI_PHY_DCC)) {
2282 r = FLD_MOD(r, 0, 21, 21); /* DCCEN = disable */
2283 r = FLD_MOD(r, 1, 22, 22); /* CLKINP_DIVBY2EN = enable */
2284 r = FLD_MOD(r, 1, 23, 23); /* CLKINP_SEL = enable */
2285 }
2286
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302287 dsi_write_reg(dsidev, DSI_DSIPHY_CFG1, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002288
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302289 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG2);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002290 r = FLD_MOD(r, tclk_prepare, 7, 0);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302291 dsi_write_reg(dsidev, DSI_DSIPHY_CFG2, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002292}
2293
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002294/* lane masks have lane 0 at lsb. mask_p for positive lines, n for negative */
Archit Taneja9e7e9372012-08-14 12:29:22 +05302295static void dsi_cio_enable_lane_override(struct platform_device *dsidev,
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002296 unsigned mask_p, unsigned mask_n)
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002297{
Archit Taneja75d72472011-05-16 15:17:08 +05302298 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002299 int i;
2300 u32 l;
Tomi Valkeinend9820852011-10-12 15:05:59 +03002301 u8 lptxscp_start = dsi->num_lanes_supported == 3 ? 22 : 26;
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002302
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002303 l = 0;
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002304
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002305 for (i = 0; i < dsi->num_lanes_supported; ++i) {
2306 unsigned p = dsi->lanes[i].polarity;
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002307
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002308 if (mask_p & (1 << i))
2309 l |= 1 << (i * 2 + (p ? 0 : 1));
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002310
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002311 if (mask_n & (1 << i))
2312 l |= 1 << (i * 2 + (p ? 1 : 0));
2313 }
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002314
2315 /*
2316 * Bits in REGLPTXSCPDAT4TO0DXDY:
2317 * 17: DY0 18: DX0
2318 * 19: DY1 20: DX1
2319 * 21: DY2 22: DX2
Archit Taneja75d72472011-05-16 15:17:08 +05302320 * 23: DY3 24: DX3
2321 * 25: DY4 26: DX4
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002322 */
2323
2324 /* Set the lane override configuration */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302325
2326 /* REGLPTXSCPDAT4TO0DXDY */
Archit Taneja75d72472011-05-16 15:17:08 +05302327 REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, l, lptxscp_start, 17);
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002328
2329 /* Enable lane override */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302330
2331 /* ENLPTXSCPDAT */
2332 REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 1, 27, 27);
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002333}
2334
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302335static void dsi_cio_disable_lane_override(struct platform_device *dsidev)
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002336{
2337 /* Disable lane override */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302338 REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 0, 27, 27); /* ENLPTXSCPDAT */
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002339 /* Reset the lane override configuration */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302340 /* REGLPTXSCPDAT4TO0DXDY */
2341 REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 0, 22, 17);
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002342}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002343
Archit Taneja9e7e9372012-08-14 12:29:22 +05302344static int dsi_cio_wait_tx_clk_esc_reset(struct platform_device *dsidev)
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002345{
Tomi Valkeinen8dc07662011-10-13 15:26:50 +03002346 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2347 int t, i;
2348 bool in_use[DSI_MAX_NR_LANES];
2349 static const u8 offsets_old[] = { 28, 27, 26 };
2350 static const u8 offsets_new[] = { 24, 25, 26, 27, 28 };
2351 const u8 *offsets;
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002352
Tomi Valkeinen8dc07662011-10-13 15:26:50 +03002353 if (dss_has_feature(FEAT_DSI_REVERSE_TXCLKESC))
2354 offsets = offsets_old;
2355 else
2356 offsets = offsets_new;
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002357
Tomi Valkeinen8dc07662011-10-13 15:26:50 +03002358 for (i = 0; i < dsi->num_lanes_supported; ++i)
2359 in_use[i] = dsi->lanes[i].function != DSI_LANE_UNUSED;
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002360
2361 t = 100000;
2362 while (true) {
2363 u32 l;
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002364 int ok;
2365
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302366 l = dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002367
2368 ok = 0;
Tomi Valkeinen8dc07662011-10-13 15:26:50 +03002369 for (i = 0; i < dsi->num_lanes_supported; ++i) {
2370 if (!in_use[i] || (l & (1 << offsets[i])))
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002371 ok++;
2372 }
2373
Tomi Valkeinen8dc07662011-10-13 15:26:50 +03002374 if (ok == dsi->num_lanes_supported)
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002375 break;
2376
2377 if (--t == 0) {
Tomi Valkeinen8dc07662011-10-13 15:26:50 +03002378 for (i = 0; i < dsi->num_lanes_supported; ++i) {
2379 if (!in_use[i] || (l & (1 << offsets[i])))
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002380 continue;
2381
2382 DSSERR("CIO TXCLKESC%d domain not coming " \
2383 "out of reset\n", i);
2384 }
2385 return -EIO;
2386 }
2387 }
2388
2389 return 0;
2390}
2391
Tomi Valkeinen85f17e82011-10-13 15:12:23 +03002392/* return bitmask of enabled lanes, lane0 being the lsb */
Archit Taneja9e7e9372012-08-14 12:29:22 +05302393static unsigned dsi_get_lane_mask(struct platform_device *dsidev)
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03002394{
Tomi Valkeinen85f17e82011-10-13 15:12:23 +03002395 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2396 unsigned mask = 0;
2397 int i;
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03002398
Tomi Valkeinen85f17e82011-10-13 15:12:23 +03002399 for (i = 0; i < dsi->num_lanes_supported; ++i) {
2400 if (dsi->lanes[i].function != DSI_LANE_UNUSED)
2401 mask |= 1 << i;
2402 }
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03002403
Tomi Valkeinen85f17e82011-10-13 15:12:23 +03002404 return mask;
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03002405}
2406
Archit Taneja9e7e9372012-08-14 12:29:22 +05302407static int dsi_cio_init(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002408{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302409 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002410 int r;
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002411 u32 l;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002412
Chandrabhanu Mahapatra702d2672012-09-24 17:12:58 +05302413 DSSDBG("DSI CIO init starts");
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002414
Archit Taneja9e7e9372012-08-14 12:29:22 +05302415 r = dss_dsi_enable_pads(dsi->module_id, dsi_get_lane_mask(dsidev));
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03002416 if (r)
2417 return r;
Tomi Valkeinend1f5857e2010-07-30 11:57:57 +03002418
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302419 dsi_enable_scp_clk(dsidev);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002420
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002421 /* A dummy read using the SCP interface to any DSIPHY register is
2422 * required after DSIPHY reset to complete the reset of the DSI complex
2423 * I/O. */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302424 dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002425
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302426 if (wait_for_bit_change(dsidev, DSI_DSIPHY_CFG5, 30, 1) != 1) {
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002427 DSSERR("CIO SCP Clock domain not coming out of reset.\n");
2428 r = -EIO;
2429 goto err_scp_clk_dom;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002430 }
2431
Archit Taneja9e7e9372012-08-14 12:29:22 +05302432 r = dsi_set_lane_config(dsidev);
Tomi Valkeinen48368392011-10-13 11:22:39 +03002433 if (r)
2434 goto err_scp_clk_dom;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002435
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002436 /* set TX STOP MODE timer to maximum for this operation */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302437 l = dsi_read_reg(dsidev, DSI_TIMING1);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002438 l = FLD_MOD(l, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
2439 l = FLD_MOD(l, 1, 14, 14); /* STOP_STATE_X16_IO */
2440 l = FLD_MOD(l, 1, 13, 13); /* STOP_STATE_X4_IO */
2441 l = FLD_MOD(l, 0x1fff, 12, 0); /* STOP_STATE_COUNTER_IO */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302442 dsi_write_reg(dsidev, DSI_TIMING1, l);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002443
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302444 if (dsi->ulps_enabled) {
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002445 unsigned mask_p;
2446 int i;
Archit Taneja75d72472011-05-16 15:17:08 +05302447
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002448 DSSDBG("manual ulps exit\n");
2449
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002450 /* ULPS is exited by Mark-1 state for 1ms, followed by
2451 * stop state. DSS HW cannot do this via the normal
2452 * ULPS exit sequence, as after reset the DSS HW thinks
2453 * that we are not in ULPS mode, and refuses to send the
2454 * sequence. So we need to send the ULPS exit sequence
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002455 * manually by setting positive lines high and negative lines
2456 * low for 1ms.
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002457 */
2458
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002459 mask_p = 0;
Archit Taneja75d72472011-05-16 15:17:08 +05302460
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002461 for (i = 0; i < dsi->num_lanes_supported; ++i) {
2462 if (dsi->lanes[i].function == DSI_LANE_UNUSED)
2463 continue;
2464 mask_p |= 1 << i;
2465 }
Archit Taneja75d72472011-05-16 15:17:08 +05302466
Archit Taneja9e7e9372012-08-14 12:29:22 +05302467 dsi_cio_enable_lane_override(dsidev, mask_p, 0);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002468 }
2469
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302470 r = dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_ON);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002471 if (r)
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002472 goto err_cio_pwr;
2473
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302474 if (wait_for_bit_change(dsidev, DSI_COMPLEXIO_CFG1, 29, 1) != 1) {
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002475 DSSERR("CIO PWR clock domain not coming out of reset.\n");
2476 r = -ENODEV;
2477 goto err_cio_pwr_dom;
2478 }
2479
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302480 dsi_if_enable(dsidev, true);
2481 dsi_if_enable(dsidev, false);
2482 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 1, 20, 20); /* LP_CLK_ENABLE */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002483
Archit Taneja9e7e9372012-08-14 12:29:22 +05302484 r = dsi_cio_wait_tx_clk_esc_reset(dsidev);
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002485 if (r)
2486 goto err_tx_clk_esc_rst;
2487
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302488 if (dsi->ulps_enabled) {
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002489 /* Keep Mark-1 state for 1ms (as per DSI spec) */
2490 ktime_t wait = ns_to_ktime(1000 * 1000);
2491 set_current_state(TASK_UNINTERRUPTIBLE);
2492 schedule_hrtimeout(&wait, HRTIMER_MODE_REL);
2493
2494 /* Disable the override. The lanes should be set to Mark-11
2495 * state by the HW */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302496 dsi_cio_disable_lane_override(dsidev);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002497 }
2498
2499 /* FORCE_TX_STOP_MODE_IO */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302500 REG_FLD_MOD(dsidev, DSI_TIMING1, 0, 15, 15);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002501
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302502 dsi_cio_timings(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002503
Archit Tanejadca2b152012-08-16 18:02:00 +05302504 if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
Archit Taneja8af6ff02011-09-05 16:48:27 +05302505 /* DDR_CLK_ALWAYS_ON */
2506 REG_FLD_MOD(dsidev, DSI_CLK_CTRL,
Archit Taneja0b3ffe32012-08-13 22:13:39 +05302507 dsi->vm_timings.ddr_clk_always_on, 13, 13);
Archit Taneja8af6ff02011-09-05 16:48:27 +05302508 }
2509
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302510 dsi->ulps_enabled = false;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002511
2512 DSSDBG("CIO init done\n");
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002513
2514 return 0;
2515
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002516err_tx_clk_esc_rst:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302517 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 20, 20); /* LP_CLK_ENABLE */
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002518err_cio_pwr_dom:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302519 dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_OFF);
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002520err_cio_pwr:
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302521 if (dsi->ulps_enabled)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302522 dsi_cio_disable_lane_override(dsidev);
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002523err_scp_clk_dom:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302524 dsi_disable_scp_clk(dsidev);
Archit Taneja9e7e9372012-08-14 12:29:22 +05302525 dss_dsi_disable_pads(dsi->module_id, dsi_get_lane_mask(dsidev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002526 return r;
2527}
2528
Archit Taneja9e7e9372012-08-14 12:29:22 +05302529static void dsi_cio_uninit(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002530{
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02002531 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302532
Archit Taneja8af6ff02011-09-05 16:48:27 +05302533 /* DDR_CLK_ALWAYS_ON */
2534 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 13, 13);
2535
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302536 dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_OFF);
2537 dsi_disable_scp_clk(dsidev);
Archit Taneja9e7e9372012-08-14 12:29:22 +05302538 dss_dsi_disable_pads(dsi->module_id, dsi_get_lane_mask(dsidev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002539}
2540
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302541static void dsi_config_tx_fifo(struct platform_device *dsidev,
2542 enum fifo_size size1, enum fifo_size size2,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002543 enum fifo_size size3, enum fifo_size size4)
2544{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302545 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002546 u32 r = 0;
2547 int add = 0;
2548 int i;
2549
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302550 dsi->vc[0].fifo_size = size1;
2551 dsi->vc[1].fifo_size = size2;
2552 dsi->vc[2].fifo_size = size3;
2553 dsi->vc[3].fifo_size = size4;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002554
2555 for (i = 0; i < 4; i++) {
2556 u8 v;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302557 int size = dsi->vc[i].fifo_size;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002558
2559 if (add + size > 4) {
2560 DSSERR("Illegal FIFO configuration\n");
2561 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002562 return;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002563 }
2564
2565 v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
2566 r |= v << (8 * i);
2567 /*DSSDBG("TX FIFO vc %d: size %d, add %d\n", i, size, add); */
2568 add += size;
2569 }
2570
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302571 dsi_write_reg(dsidev, DSI_TX_FIFO_VC_SIZE, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002572}
2573
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302574static void dsi_config_rx_fifo(struct platform_device *dsidev,
2575 enum fifo_size size1, enum fifo_size size2,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002576 enum fifo_size size3, enum fifo_size size4)
2577{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302578 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002579 u32 r = 0;
2580 int add = 0;
2581 int i;
2582
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302583 dsi->vc[0].fifo_size = size1;
2584 dsi->vc[1].fifo_size = size2;
2585 dsi->vc[2].fifo_size = size3;
2586 dsi->vc[3].fifo_size = size4;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002587
2588 for (i = 0; i < 4; i++) {
2589 u8 v;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302590 int size = dsi->vc[i].fifo_size;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002591
2592 if (add + size > 4) {
2593 DSSERR("Illegal FIFO configuration\n");
2594 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002595 return;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002596 }
2597
2598 v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
2599 r |= v << (8 * i);
2600 /*DSSDBG("RX FIFO vc %d: size %d, add %d\n", i, size, add); */
2601 add += size;
2602 }
2603
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302604 dsi_write_reg(dsidev, DSI_RX_FIFO_VC_SIZE, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002605}
2606
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302607static int dsi_force_tx_stop_mode_io(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002608{
2609 u32 r;
2610
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302611 r = dsi_read_reg(dsidev, DSI_TIMING1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002612 r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302613 dsi_write_reg(dsidev, DSI_TIMING1, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002614
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302615 if (wait_for_bit_change(dsidev, DSI_TIMING1, 15, 0) != 0) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002616 DSSERR("TX_STOP bit not going down\n");
2617 return -EIO;
2618 }
2619
2620 return 0;
2621}
2622
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302623static bool dsi_vc_is_enabled(struct platform_device *dsidev, int channel)
Archit Tanejacf398fb2011-03-23 09:59:34 +00002624{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302625 return REG_GET(dsidev, DSI_VC_CTRL(channel), 0, 0);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002626}
2627
2628static void dsi_packet_sent_handler_vp(void *data, u32 mask)
2629{
Archit Taneja2e868db2011-05-12 17:26:28 +05302630 struct dsi_packet_sent_handler_data *vp_data =
2631 (struct dsi_packet_sent_handler_data *) data;
2632 struct dsi_data *dsi = dsi_get_dsidrv_data(vp_data->dsidev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302633 const int channel = dsi->update_channel;
2634 u8 bit = dsi->te_enabled ? 30 : 31;
Archit Tanejacf398fb2011-03-23 09:59:34 +00002635
Archit Taneja2e868db2011-05-12 17:26:28 +05302636 if (REG_GET(vp_data->dsidev, DSI_VC_TE(channel), bit, bit) == 0)
2637 complete(vp_data->completion);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002638}
2639
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302640static int dsi_sync_vc_vp(struct platform_device *dsidev, int channel)
Archit Tanejacf398fb2011-03-23 09:59:34 +00002641{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302642 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Taneja2e868db2011-05-12 17:26:28 +05302643 DECLARE_COMPLETION_ONSTACK(completion);
2644 struct dsi_packet_sent_handler_data vp_data = { dsidev, &completion };
Archit Tanejacf398fb2011-03-23 09:59:34 +00002645 int r = 0;
2646 u8 bit;
2647
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302648 bit = dsi->te_enabled ? 30 : 31;
Archit Tanejacf398fb2011-03-23 09:59:34 +00002649
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302650 r = dsi_register_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp,
Archit Taneja2e868db2011-05-12 17:26:28 +05302651 &vp_data, DSI_VC_IRQ_PACKET_SENT);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002652 if (r)
2653 goto err0;
2654
2655 /* Wait for completion only if TE_EN/TE_START is still set */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302656 if (REG_GET(dsidev, DSI_VC_TE(channel), bit, bit)) {
Archit Tanejacf398fb2011-03-23 09:59:34 +00002657 if (wait_for_completion_timeout(&completion,
2658 msecs_to_jiffies(10)) == 0) {
2659 DSSERR("Failed to complete previous frame transfer\n");
2660 r = -EIO;
2661 goto err1;
2662 }
2663 }
2664
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302665 dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp,
Archit Taneja2e868db2011-05-12 17:26:28 +05302666 &vp_data, DSI_VC_IRQ_PACKET_SENT);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002667
2668 return 0;
2669err1:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302670 dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp,
Archit Taneja2e868db2011-05-12 17:26:28 +05302671 &vp_data, DSI_VC_IRQ_PACKET_SENT);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002672err0:
2673 return r;
2674}
2675
2676static void dsi_packet_sent_handler_l4(void *data, u32 mask)
2677{
Archit Taneja2e868db2011-05-12 17:26:28 +05302678 struct dsi_packet_sent_handler_data *l4_data =
2679 (struct dsi_packet_sent_handler_data *) data;
2680 struct dsi_data *dsi = dsi_get_dsidrv_data(l4_data->dsidev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302681 const int channel = dsi->update_channel;
Archit Tanejacf398fb2011-03-23 09:59:34 +00002682
Archit Taneja2e868db2011-05-12 17:26:28 +05302683 if (REG_GET(l4_data->dsidev, DSI_VC_CTRL(channel), 5, 5) == 0)
2684 complete(l4_data->completion);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002685}
2686
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302687static int dsi_sync_vc_l4(struct platform_device *dsidev, int channel)
Archit Tanejacf398fb2011-03-23 09:59:34 +00002688{
Archit Taneja2e868db2011-05-12 17:26:28 +05302689 DECLARE_COMPLETION_ONSTACK(completion);
2690 struct dsi_packet_sent_handler_data l4_data = { dsidev, &completion };
Archit Tanejacf398fb2011-03-23 09:59:34 +00002691 int r = 0;
2692
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302693 r = dsi_register_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4,
Archit Taneja2e868db2011-05-12 17:26:28 +05302694 &l4_data, DSI_VC_IRQ_PACKET_SENT);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002695 if (r)
2696 goto err0;
2697
2698 /* Wait for completion only if TX_FIFO_NOT_EMPTY is still set */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302699 if (REG_GET(dsidev, DSI_VC_CTRL(channel), 5, 5)) {
Archit Tanejacf398fb2011-03-23 09:59:34 +00002700 if (wait_for_completion_timeout(&completion,
2701 msecs_to_jiffies(10)) == 0) {
2702 DSSERR("Failed to complete previous l4 transfer\n");
2703 r = -EIO;
2704 goto err1;
2705 }
2706 }
2707
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302708 dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4,
Archit Taneja2e868db2011-05-12 17:26:28 +05302709 &l4_data, DSI_VC_IRQ_PACKET_SENT);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002710
2711 return 0;
2712err1:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302713 dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4,
Archit Taneja2e868db2011-05-12 17:26:28 +05302714 &l4_data, DSI_VC_IRQ_PACKET_SENT);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002715err0:
2716 return r;
2717}
2718
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302719static int dsi_sync_vc(struct platform_device *dsidev, int channel)
Archit Tanejacf398fb2011-03-23 09:59:34 +00002720{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302721 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2722
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302723 WARN_ON(!dsi_bus_is_locked(dsidev));
Archit Tanejacf398fb2011-03-23 09:59:34 +00002724
2725 WARN_ON(in_interrupt());
2726
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302727 if (!dsi_vc_is_enabled(dsidev, channel))
Archit Tanejacf398fb2011-03-23 09:59:34 +00002728 return 0;
2729
Archit Tanejad6049142011-08-22 11:58:08 +05302730 switch (dsi->vc[channel].source) {
2731 case DSI_VC_SOURCE_VP:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302732 return dsi_sync_vc_vp(dsidev, channel);
Archit Tanejad6049142011-08-22 11:58:08 +05302733 case DSI_VC_SOURCE_L4:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302734 return dsi_sync_vc_l4(dsidev, channel);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002735 default:
2736 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002737 return -EINVAL;
Archit Tanejacf398fb2011-03-23 09:59:34 +00002738 }
2739}
2740
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302741static int dsi_vc_enable(struct platform_device *dsidev, int channel,
2742 bool enable)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002743{
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +02002744 DSSDBG("dsi_vc_enable channel %d, enable %d\n",
2745 channel, enable);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002746
2747 enable = enable ? 1 : 0;
2748
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302749 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 0, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002750
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302751 if (wait_for_bit_change(dsidev, DSI_VC_CTRL(channel),
2752 0, enable) != enable) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002753 DSSERR("Failed to set dsi_vc_enable to %d\n", enable);
2754 return -EIO;
2755 }
2756
2757 return 0;
2758}
2759
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302760static void dsi_vc_initial_config(struct platform_device *dsidev, int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002761{
2762 u32 r;
2763
Chandrabhanu Mahapatra702d2672012-09-24 17:12:58 +05302764 DSSDBG("Initial config of virtual channel %d", channel);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002765
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302766 r = dsi_read_reg(dsidev, DSI_VC_CTRL(channel));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002767
2768 if (FLD_GET(r, 15, 15)) /* VC_BUSY */
2769 DSSERR("VC(%d) busy when trying to configure it!\n",
2770 channel);
2771
2772 r = FLD_MOD(r, 0, 1, 1); /* SOURCE, 0 = L4 */
2773 r = FLD_MOD(r, 0, 2, 2); /* BTA_SHORT_EN */
2774 r = FLD_MOD(r, 0, 3, 3); /* BTA_LONG_EN */
2775 r = FLD_MOD(r, 0, 4, 4); /* MODE, 0 = command */
2776 r = FLD_MOD(r, 1, 7, 7); /* CS_TX_EN */
2777 r = FLD_MOD(r, 1, 8, 8); /* ECC_TX_EN */
2778 r = FLD_MOD(r, 0, 9, 9); /* MODE_SPEED, high speed on/off */
Archit Taneja9613c022011-03-22 06:33:36 -05002779 if (dss_has_feature(FEAT_DSI_VC_OCP_WIDTH))
2780 r = FLD_MOD(r, 3, 11, 10); /* OCP_WIDTH = 32 bit */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002781
2782 r = FLD_MOD(r, 4, 29, 27); /* DMA_RX_REQ_NB = no dma */
2783 r = FLD_MOD(r, 4, 23, 21); /* DMA_TX_REQ_NB = no dma */
2784
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302785 dsi_write_reg(dsidev, DSI_VC_CTRL(channel), r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002786}
2787
Archit Tanejad6049142011-08-22 11:58:08 +05302788static int dsi_vc_config_source(struct platform_device *dsidev, int channel,
2789 enum dsi_vc_source source)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002790{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302791 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2792
Archit Tanejad6049142011-08-22 11:58:08 +05302793 if (dsi->vc[channel].source == source)
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03002794 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002795
Chandrabhanu Mahapatra702d2672012-09-24 17:12:58 +05302796 DSSDBG("Source config of virtual channel %d", channel);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002797
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302798 dsi_sync_vc(dsidev, channel);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002799
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302800 dsi_vc_enable(dsidev, channel, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002801
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03002802 /* VC_BUSY */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302803 if (wait_for_bit_change(dsidev, DSI_VC_CTRL(channel), 15, 0) != 0) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002804 DSSERR("vc(%d) busy when trying to config for VP\n", channel);
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03002805 return -EIO;
2806 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002807
Archit Tanejad6049142011-08-22 11:58:08 +05302808 /* SOURCE, 0 = L4, 1 = video port */
2809 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), source, 1, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002810
Archit Taneja9613c022011-03-22 06:33:36 -05002811 /* DCS_CMD_ENABLE */
Archit Tanejad6049142011-08-22 11:58:08 +05302812 if (dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC)) {
2813 bool enable = source == DSI_VC_SOURCE_VP;
2814 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 30, 30);
2815 }
Archit Taneja9613c022011-03-22 06:33:36 -05002816
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302817 dsi_vc_enable(dsidev, channel, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002818
Archit Tanejad6049142011-08-22 11:58:08 +05302819 dsi->vc[channel].source = source;
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03002820
2821 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002822}
2823
Archit Taneja1ffefe72011-05-12 17:26:24 +05302824void omapdss_dsi_vc_enable_hs(struct omap_dss_device *dssdev, int channel,
2825 bool enable)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002826{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302827 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Taneja0b3ffe32012-08-13 22:13:39 +05302828 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302829
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002830 DSSDBG("dsi_vc_enable_hs(%d, %d)\n", channel, enable);
2831
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302832 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen61140c92010-01-12 16:00:30 +02002833
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302834 dsi_vc_enable(dsidev, channel, 0);
2835 dsi_if_enable(dsidev, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002836
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302837 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 9, 9);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002838
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302839 dsi_vc_enable(dsidev, channel, 1);
2840 dsi_if_enable(dsidev, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002841
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302842 dsi_force_tx_stop_mode_io(dsidev);
Archit Taneja8af6ff02011-09-05 16:48:27 +05302843
2844 /* start the DDR clock by sending a NULL packet */
Archit Taneja0b3ffe32012-08-13 22:13:39 +05302845 if (dsi->vm_timings.ddr_clk_always_on && enable)
Archit Taneja8af6ff02011-09-05 16:48:27 +05302846 dsi_vc_send_null(dssdev, channel);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002847}
Tomi Valkeinen61140c92010-01-12 16:00:30 +02002848EXPORT_SYMBOL(omapdss_dsi_vc_enable_hs);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002849
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302850static void dsi_vc_flush_long_data(struct platform_device *dsidev, int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002851{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302852 while (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002853 u32 val;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302854 val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002855 DSSDBG("\t\tb1 %#02x b2 %#02x b3 %#02x b4 %#02x\n",
2856 (val >> 0) & 0xff,
2857 (val >> 8) & 0xff,
2858 (val >> 16) & 0xff,
2859 (val >> 24) & 0xff);
2860 }
2861}
2862
2863static void dsi_show_rx_ack_with_err(u16 err)
2864{
2865 DSSERR("\tACK with ERROR (%#x):\n", err);
2866 if (err & (1 << 0))
2867 DSSERR("\t\tSoT Error\n");
2868 if (err & (1 << 1))
2869 DSSERR("\t\tSoT Sync Error\n");
2870 if (err & (1 << 2))
2871 DSSERR("\t\tEoT Sync Error\n");
2872 if (err & (1 << 3))
2873 DSSERR("\t\tEscape Mode Entry Command Error\n");
2874 if (err & (1 << 4))
2875 DSSERR("\t\tLP Transmit Sync Error\n");
2876 if (err & (1 << 5))
2877 DSSERR("\t\tHS Receive Timeout Error\n");
2878 if (err & (1 << 6))
2879 DSSERR("\t\tFalse Control Error\n");
2880 if (err & (1 << 7))
2881 DSSERR("\t\t(reserved7)\n");
2882 if (err & (1 << 8))
2883 DSSERR("\t\tECC Error, single-bit (corrected)\n");
2884 if (err & (1 << 9))
2885 DSSERR("\t\tECC Error, multi-bit (not corrected)\n");
2886 if (err & (1 << 10))
2887 DSSERR("\t\tChecksum Error\n");
2888 if (err & (1 << 11))
2889 DSSERR("\t\tData type not recognized\n");
2890 if (err & (1 << 12))
2891 DSSERR("\t\tInvalid VC ID\n");
2892 if (err & (1 << 13))
2893 DSSERR("\t\tInvalid Transmission Length\n");
2894 if (err & (1 << 14))
2895 DSSERR("\t\t(reserved14)\n");
2896 if (err & (1 << 15))
2897 DSSERR("\t\tDSI Protocol Violation\n");
2898}
2899
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302900static u16 dsi_vc_flush_receive_data(struct platform_device *dsidev,
2901 int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002902{
2903 /* RX_FIFO_NOT_EMPTY */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302904 while (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002905 u32 val;
2906 u8 dt;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302907 val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel));
Tomi Valkeinen86a78672010-03-16 16:19:06 +02002908 DSSERR("\trawval %#08x\n", val);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002909 dt = FLD_GET(val, 5, 0);
Archit Taneja7a7c48f2011-08-25 18:25:03 +05302910 if (dt == MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002911 u16 err = FLD_GET(val, 23, 8);
2912 dsi_show_rx_ack_with_err(err);
Archit Taneja7a7c48f2011-08-25 18:25:03 +05302913 } else if (dt == MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE) {
Tomi Valkeinen86a78672010-03-16 16:19:06 +02002914 DSSERR("\tDCS short response, 1 byte: %#x\n",
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002915 FLD_GET(val, 23, 8));
Archit Taneja7a7c48f2011-08-25 18:25:03 +05302916 } else if (dt == MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE) {
Tomi Valkeinen86a78672010-03-16 16:19:06 +02002917 DSSERR("\tDCS short response, 2 byte: %#x\n",
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002918 FLD_GET(val, 23, 8));
Archit Taneja7a7c48f2011-08-25 18:25:03 +05302919 } else if (dt == MIPI_DSI_RX_DCS_LONG_READ_RESPONSE) {
Tomi Valkeinen86a78672010-03-16 16:19:06 +02002920 DSSERR("\tDCS long response, len %d\n",
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002921 FLD_GET(val, 23, 8));
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302922 dsi_vc_flush_long_data(dsidev, channel);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002923 } else {
2924 DSSERR("\tunknown datatype 0x%02x\n", dt);
2925 }
2926 }
2927 return 0;
2928}
2929
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302930static int dsi_vc_send_bta(struct platform_device *dsidev, int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002931{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302932 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2933
2934 if (dsi->debug_write || dsi->debug_read)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002935 DSSDBG("dsi_vc_send_bta %d\n", channel);
2936
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302937 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002938
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302939 /* RX_FIFO_NOT_EMPTY */
2940 if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002941 DSSERR("rx fifo not empty when sending BTA, dumping data:\n");
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302942 dsi_vc_flush_receive_data(dsidev, channel);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002943 }
2944
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302945 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 1, 6, 6); /* BTA_EN */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002946
Tomi Valkeinen968f8e92011-10-12 10:13:14 +03002947 /* flush posted write */
2948 dsi_read_reg(dsidev, DSI_VC_CTRL(channel));
2949
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002950 return 0;
2951}
2952
Archit Taneja1ffefe72011-05-12 17:26:24 +05302953int dsi_vc_send_bta_sync(struct omap_dss_device *dssdev, int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002954{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302955 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Tomi Valkeinenf36a06e2011-03-02 14:48:41 +02002956 DECLARE_COMPLETION_ONSTACK(completion);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002957 int r = 0;
2958 u32 err;
2959
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302960 r = dsi_register_isr_vc(dsidev, channel, dsi_completion_handler,
Tomi Valkeinenf36a06e2011-03-02 14:48:41 +02002961 &completion, DSI_VC_IRQ_BTA);
2962 if (r)
2963 goto err0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002964
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302965 r = dsi_register_isr(dsidev, dsi_completion_handler, &completion,
Tomi Valkeinen773b30b2010-10-08 16:15:25 +03002966 DSI_IRQ_ERROR_MASK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002967 if (r)
Tomi Valkeinenf36a06e2011-03-02 14:48:41 +02002968 goto err1;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002969
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302970 r = dsi_vc_send_bta(dsidev, channel);
Tomi Valkeinen773b30b2010-10-08 16:15:25 +03002971 if (r)
2972 goto err2;
2973
Tomi Valkeinenf36a06e2011-03-02 14:48:41 +02002974 if (wait_for_completion_timeout(&completion,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002975 msecs_to_jiffies(500)) == 0) {
2976 DSSERR("Failed to receive BTA\n");
2977 r = -EIO;
Tomi Valkeinen773b30b2010-10-08 16:15:25 +03002978 goto err2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002979 }
2980
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302981 err = dsi_get_errors(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002982 if (err) {
2983 DSSERR("Error while sending BTA: %x\n", err);
2984 r = -EIO;
Tomi Valkeinen773b30b2010-10-08 16:15:25 +03002985 goto err2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002986 }
Tomi Valkeinen773b30b2010-10-08 16:15:25 +03002987err2:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302988 dsi_unregister_isr(dsidev, dsi_completion_handler, &completion,
Tomi Valkeinen773b30b2010-10-08 16:15:25 +03002989 DSI_IRQ_ERROR_MASK);
Tomi Valkeinenf36a06e2011-03-02 14:48:41 +02002990err1:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302991 dsi_unregister_isr_vc(dsidev, channel, dsi_completion_handler,
Tomi Valkeinenf36a06e2011-03-02 14:48:41 +02002992 &completion, DSI_VC_IRQ_BTA);
2993err0:
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002994 return r;
2995}
2996EXPORT_SYMBOL(dsi_vc_send_bta_sync);
2997
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302998static inline void dsi_vc_write_long_header(struct platform_device *dsidev,
2999 int channel, u8 data_type, u16 len, u8 ecc)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003000{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303001 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003002 u32 val;
3003 u8 data_id;
3004
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303005 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003006
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303007 data_id = data_type | dsi->vc[channel].vc_id << 6;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003008
3009 val = FLD_VAL(data_id, 7, 0) | FLD_VAL(len, 23, 8) |
3010 FLD_VAL(ecc, 31, 24);
3011
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303012 dsi_write_reg(dsidev, DSI_VC_LONG_PACKET_HEADER(channel), val);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003013}
3014
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303015static inline void dsi_vc_write_long_payload(struct platform_device *dsidev,
3016 int channel, u8 b1, u8 b2, u8 b3, u8 b4)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003017{
3018 u32 val;
3019
3020 val = b4 << 24 | b3 << 16 | b2 << 8 | b1 << 0;
3021
3022/* DSSDBG("\twriting %02x, %02x, %02x, %02x (%#010x)\n",
3023 b1, b2, b3, b4, val); */
3024
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303025 dsi_write_reg(dsidev, DSI_VC_LONG_PACKET_PAYLOAD(channel), val);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003026}
3027
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303028static int dsi_vc_send_long(struct platform_device *dsidev, int channel,
3029 u8 data_type, u8 *data, u16 len, u8 ecc)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003030{
3031 /*u32 val; */
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303032 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003033 int i;
3034 u8 *p;
3035 int r = 0;
3036 u8 b1, b2, b3, b4;
3037
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303038 if (dsi->debug_write)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003039 DSSDBG("dsi_vc_send_long, %d bytes\n", len);
3040
3041 /* len + header */
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303042 if (dsi->vc[channel].fifo_size * 32 * 4 < len + 4) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003043 DSSERR("unable to send long packet: packet too long.\n");
3044 return -EINVAL;
3045 }
3046
Archit Tanejad6049142011-08-22 11:58:08 +05303047 dsi_vc_config_source(dsidev, channel, DSI_VC_SOURCE_L4);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003048
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303049 dsi_vc_write_long_header(dsidev, channel, data_type, len, ecc);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003050
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003051 p = data;
3052 for (i = 0; i < len >> 2; i++) {
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303053 if (dsi->debug_write)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003054 DSSDBG("\tsending full packet %d\n", i);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003055
3056 b1 = *p++;
3057 b2 = *p++;
3058 b3 = *p++;
3059 b4 = *p++;
3060
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303061 dsi_vc_write_long_payload(dsidev, channel, b1, b2, b3, b4);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003062 }
3063
3064 i = len % 4;
3065 if (i) {
3066 b1 = 0; b2 = 0; b3 = 0;
3067
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303068 if (dsi->debug_write)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003069 DSSDBG("\tsending remainder bytes %d\n", i);
3070
3071 switch (i) {
3072 case 3:
3073 b1 = *p++;
3074 b2 = *p++;
3075 b3 = *p++;
3076 break;
3077 case 2:
3078 b1 = *p++;
3079 b2 = *p++;
3080 break;
3081 case 1:
3082 b1 = *p++;
3083 break;
3084 }
3085
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303086 dsi_vc_write_long_payload(dsidev, channel, b1, b2, b3, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003087 }
3088
3089 return r;
3090}
3091
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303092static int dsi_vc_send_short(struct platform_device *dsidev, int channel,
3093 u8 data_type, u16 data, u8 ecc)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003094{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303095 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003096 u32 r;
3097 u8 data_id;
3098
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303099 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003100
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303101 if (dsi->debug_write)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003102 DSSDBG("dsi_vc_send_short(ch%d, dt %#x, b1 %#x, b2 %#x)\n",
3103 channel,
3104 data_type, data & 0xff, (data >> 8) & 0xff);
3105
Archit Tanejad6049142011-08-22 11:58:08 +05303106 dsi_vc_config_source(dsidev, channel, DSI_VC_SOURCE_L4);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003107
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303108 if (FLD_GET(dsi_read_reg(dsidev, DSI_VC_CTRL(channel)), 16, 16)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003109 DSSERR("ERROR FIFO FULL, aborting transfer\n");
3110 return -EINVAL;
3111 }
3112
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303113 data_id = data_type | dsi->vc[channel].vc_id << 6;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003114
3115 r = (data_id << 0) | (data << 8) | (ecc << 24);
3116
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303117 dsi_write_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel), r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003118
3119 return 0;
3120}
3121
Archit Taneja1ffefe72011-05-12 17:26:24 +05303122int dsi_vc_send_null(struct omap_dss_device *dssdev, int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003123{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303124 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303125
Archit Taneja18b7d092011-09-05 17:01:08 +05303126 return dsi_vc_send_long(dsidev, channel, MIPI_DSI_NULL_PACKET, NULL,
3127 0, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003128}
3129EXPORT_SYMBOL(dsi_vc_send_null);
3130
Archit Taneja9e7e9372012-08-14 12:29:22 +05303131static int dsi_vc_write_nosync_common(struct platform_device *dsidev,
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303132 int channel, u8 *data, int len, enum dss_dsi_content_type type)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003133{
3134 int r;
3135
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303136 if (len == 0) {
3137 BUG_ON(type == DSS_DSI_CONTENT_DCS);
Archit Taneja7a7c48f2011-08-25 18:25:03 +05303138 r = dsi_vc_send_short(dsidev, channel,
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303139 MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM, 0, 0);
3140 } else if (len == 1) {
3141 r = dsi_vc_send_short(dsidev, channel,
3142 type == DSS_DSI_CONTENT_GENERIC ?
3143 MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM :
Archit Taneja7a7c48f2011-08-25 18:25:03 +05303144 MIPI_DSI_DCS_SHORT_WRITE, data[0], 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003145 } else if (len == 2) {
Archit Taneja7a7c48f2011-08-25 18:25:03 +05303146 r = dsi_vc_send_short(dsidev, channel,
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303147 type == DSS_DSI_CONTENT_GENERIC ?
3148 MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM :
Archit Taneja7a7c48f2011-08-25 18:25:03 +05303149 MIPI_DSI_DCS_SHORT_WRITE_PARAM,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003150 data[0] | (data[1] << 8), 0);
3151 } else {
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303152 r = dsi_vc_send_long(dsidev, channel,
3153 type == DSS_DSI_CONTENT_GENERIC ?
3154 MIPI_DSI_GENERIC_LONG_WRITE :
3155 MIPI_DSI_DCS_LONG_WRITE, data, len, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003156 }
3157
3158 return r;
3159}
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303160
3161int dsi_vc_dcs_write_nosync(struct omap_dss_device *dssdev, int channel,
3162 u8 *data, int len)
3163{
Archit Taneja9e7e9372012-08-14 12:29:22 +05303164 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
3165
3166 return dsi_vc_write_nosync_common(dsidev, channel, data, len,
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303167 DSS_DSI_CONTENT_DCS);
3168}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003169EXPORT_SYMBOL(dsi_vc_dcs_write_nosync);
3170
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303171int dsi_vc_generic_write_nosync(struct omap_dss_device *dssdev, int channel,
3172 u8 *data, int len)
3173{
Archit Taneja9e7e9372012-08-14 12:29:22 +05303174 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
3175
3176 return dsi_vc_write_nosync_common(dsidev, channel, data, len,
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303177 DSS_DSI_CONTENT_GENERIC);
3178}
3179EXPORT_SYMBOL(dsi_vc_generic_write_nosync);
3180
3181static int dsi_vc_write_common(struct omap_dss_device *dssdev, int channel,
3182 u8 *data, int len, enum dss_dsi_content_type type)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003183{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303184 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003185 int r;
3186
Archit Taneja9e7e9372012-08-14 12:29:22 +05303187 r = dsi_vc_write_nosync_common(dsidev, channel, data, len, type);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003188 if (r)
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003189 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003190
Archit Taneja1ffefe72011-05-12 17:26:24 +05303191 r = dsi_vc_send_bta_sync(dssdev, channel);
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003192 if (r)
3193 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003194
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303195 /* RX_FIFO_NOT_EMPTY */
3196 if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
Tomi Valkeinenb63ac1e2010-04-09 13:20:57 +03003197 DSSERR("rx fifo not empty after write, dumping data:\n");
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303198 dsi_vc_flush_receive_data(dsidev, channel);
Tomi Valkeinenb63ac1e2010-04-09 13:20:57 +03003199 r = -EIO;
3200 goto err;
3201 }
3202
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003203 return 0;
3204err:
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303205 DSSERR("dsi_vc_write_common(ch %d, cmd 0x%02x, len %d) failed\n",
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003206 channel, data[0], len);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003207 return r;
3208}
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303209
3210int dsi_vc_dcs_write(struct omap_dss_device *dssdev, int channel, u8 *data,
3211 int len)
3212{
3213 return dsi_vc_write_common(dssdev, channel, data, len,
3214 DSS_DSI_CONTENT_DCS);
3215}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003216EXPORT_SYMBOL(dsi_vc_dcs_write);
3217
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303218int dsi_vc_generic_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_GENERIC);
3223}
3224EXPORT_SYMBOL(dsi_vc_generic_write);
3225
Archit Taneja1ffefe72011-05-12 17:26:24 +05303226int dsi_vc_dcs_write_0(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd)
Tomi Valkeinen828c48f2009-12-16 14:53:15 +02003227{
Archit Taneja1ffefe72011-05-12 17:26:24 +05303228 return dsi_vc_dcs_write(dssdev, channel, &dcs_cmd, 1);
Tomi Valkeinen828c48f2009-12-16 14:53:15 +02003229}
3230EXPORT_SYMBOL(dsi_vc_dcs_write_0);
3231
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303232int dsi_vc_generic_write_0(struct omap_dss_device *dssdev, int channel)
3233{
3234 return dsi_vc_generic_write(dssdev, channel, NULL, 0);
3235}
3236EXPORT_SYMBOL(dsi_vc_generic_write_0);
3237
Archit Taneja1ffefe72011-05-12 17:26:24 +05303238int dsi_vc_dcs_write_1(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
3239 u8 param)
Tomi Valkeinen828c48f2009-12-16 14:53:15 +02003240{
3241 u8 buf[2];
3242 buf[0] = dcs_cmd;
3243 buf[1] = param;
Archit Taneja1ffefe72011-05-12 17:26:24 +05303244 return dsi_vc_dcs_write(dssdev, channel, buf, 2);
Tomi Valkeinen828c48f2009-12-16 14:53:15 +02003245}
3246EXPORT_SYMBOL(dsi_vc_dcs_write_1);
3247
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303248int dsi_vc_generic_write_1(struct omap_dss_device *dssdev, int channel,
3249 u8 param)
3250{
3251 return dsi_vc_generic_write(dssdev, channel, &param, 1);
3252}
3253EXPORT_SYMBOL(dsi_vc_generic_write_1);
3254
3255int dsi_vc_generic_write_2(struct omap_dss_device *dssdev, int channel,
3256 u8 param1, u8 param2)
3257{
3258 u8 buf[2];
3259 buf[0] = param1;
3260 buf[1] = param2;
3261 return dsi_vc_generic_write(dssdev, channel, buf, 2);
3262}
3263EXPORT_SYMBOL(dsi_vc_generic_write_2);
3264
Archit Taneja9e7e9372012-08-14 12:29:22 +05303265static int dsi_vc_dcs_send_read_request(struct platform_device *dsidev,
Archit Tanejab8509752011-08-30 15:48:23 +05303266 int channel, u8 dcs_cmd)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003267{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303268 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejab8509752011-08-30 15:48:23 +05303269 int r;
3270
3271 if (dsi->debug_read)
3272 DSSDBG("dsi_vc_dcs_send_read_request(ch%d, dcs_cmd %x)\n",
3273 channel, dcs_cmd);
3274
3275 r = dsi_vc_send_short(dsidev, channel, MIPI_DSI_DCS_READ, dcs_cmd, 0);
3276 if (r) {
3277 DSSERR("dsi_vc_dcs_send_read_request(ch %d, cmd 0x%02x)"
3278 " failed\n", channel, dcs_cmd);
3279 return r;
3280 }
3281
3282 return 0;
3283}
3284
Archit Taneja9e7e9372012-08-14 12:29:22 +05303285static int dsi_vc_generic_send_read_request(struct platform_device *dsidev,
Archit Tanejab3b89c02011-08-30 16:07:39 +05303286 int channel, u8 *reqdata, int reqlen)
3287{
Archit Tanejab3b89c02011-08-30 16:07:39 +05303288 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
3289 u16 data;
3290 u8 data_type;
3291 int r;
3292
3293 if (dsi->debug_read)
3294 DSSDBG("dsi_vc_generic_send_read_request(ch %d, reqlen %d)\n",
3295 channel, reqlen);
3296
3297 if (reqlen == 0) {
3298 data_type = MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM;
3299 data = 0;
3300 } else if (reqlen == 1) {
3301 data_type = MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM;
3302 data = reqdata[0];
3303 } else if (reqlen == 2) {
3304 data_type = MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM;
3305 data = reqdata[0] | (reqdata[1] << 8);
3306 } else {
3307 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03003308 return -EINVAL;
Archit Tanejab3b89c02011-08-30 16:07:39 +05303309 }
3310
3311 r = dsi_vc_send_short(dsidev, channel, data_type, data, 0);
3312 if (r) {
3313 DSSERR("dsi_vc_generic_send_read_request(ch %d, reqlen %d)"
3314 " failed\n", channel, reqlen);
3315 return r;
3316 }
3317
3318 return 0;
3319}
3320
3321static int dsi_vc_read_rx_fifo(struct platform_device *dsidev, int channel,
3322 u8 *buf, int buflen, enum dss_dsi_content_type type)
Archit Tanejab8509752011-08-30 15:48:23 +05303323{
3324 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003325 u32 val;
3326 u8 dt;
3327 int r;
3328
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003329 /* RX_FIFO_NOT_EMPTY */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303330 if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20) == 0) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003331 DSSERR("RX fifo empty when trying to read.\n");
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003332 r = -EIO;
3333 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003334 }
3335
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303336 val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel));
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303337 if (dsi->debug_read)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003338 DSSDBG("\theader: %08x\n", val);
3339 dt = FLD_GET(val, 5, 0);
Archit Taneja7a7c48f2011-08-25 18:25:03 +05303340 if (dt == MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003341 u16 err = FLD_GET(val, 23, 8);
3342 dsi_show_rx_ack_with_err(err);
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003343 r = -EIO;
3344 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003345
Archit Tanejab3b89c02011-08-30 16:07:39 +05303346 } else if (dt == (type == DSS_DSI_CONTENT_GENERIC ?
3347 MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_1BYTE :
3348 MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003349 u8 data = FLD_GET(val, 15, 8);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303350 if (dsi->debug_read)
Archit Tanejab3b89c02011-08-30 16:07:39 +05303351 DSSDBG("\t%s short response, 1 byte: %02x\n",
3352 type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" :
3353 "DCS", data);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003354
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003355 if (buflen < 1) {
3356 r = -EIO;
3357 goto err;
3358 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003359
3360 buf[0] = data;
3361
3362 return 1;
Archit Tanejab3b89c02011-08-30 16:07:39 +05303363 } else if (dt == (type == DSS_DSI_CONTENT_GENERIC ?
3364 MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_2BYTE :
3365 MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003366 u16 data = FLD_GET(val, 23, 8);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303367 if (dsi->debug_read)
Archit Tanejab3b89c02011-08-30 16:07:39 +05303368 DSSDBG("\t%s short response, 2 byte: %04x\n",
3369 type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" :
3370 "DCS", data);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003371
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003372 if (buflen < 2) {
3373 r = -EIO;
3374 goto err;
3375 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003376
3377 buf[0] = data & 0xff;
3378 buf[1] = (data >> 8) & 0xff;
3379
3380 return 2;
Archit Tanejab3b89c02011-08-30 16:07:39 +05303381 } else if (dt == (type == DSS_DSI_CONTENT_GENERIC ?
3382 MIPI_DSI_RX_GENERIC_LONG_READ_RESPONSE :
3383 MIPI_DSI_RX_DCS_LONG_READ_RESPONSE)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003384 int w;
3385 int len = FLD_GET(val, 23, 8);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303386 if (dsi->debug_read)
Archit Tanejab3b89c02011-08-30 16:07:39 +05303387 DSSDBG("\t%s long response, len %d\n",
3388 type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" :
3389 "DCS", len);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003390
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003391 if (len > buflen) {
3392 r = -EIO;
3393 goto err;
3394 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003395
3396 /* two byte checksum ends the packet, not included in len */
3397 for (w = 0; w < len + 2;) {
3398 int b;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303399 val = dsi_read_reg(dsidev,
3400 DSI_VC_SHORT_PACKET_HEADER(channel));
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303401 if (dsi->debug_read)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003402 DSSDBG("\t\t%02x %02x %02x %02x\n",
3403 (val >> 0) & 0xff,
3404 (val >> 8) & 0xff,
3405 (val >> 16) & 0xff,
3406 (val >> 24) & 0xff);
3407
3408 for (b = 0; b < 4; ++b) {
3409 if (w < len)
3410 buf[w] = (val >> (b * 8)) & 0xff;
3411 /* we discard the 2 byte checksum */
3412 ++w;
3413 }
3414 }
3415
3416 return len;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003417 } else {
3418 DSSERR("\tunknown datatype 0x%02x\n", dt);
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003419 r = -EIO;
3420 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003421 }
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003422
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003423err:
Archit Tanejab3b89c02011-08-30 16:07:39 +05303424 DSSERR("dsi_vc_read_rx_fifo(ch %d type %s) failed\n", channel,
3425 type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" : "DCS");
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003426
Archit Tanejab8509752011-08-30 15:48:23 +05303427 return r;
3428}
3429
3430int dsi_vc_dcs_read(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
3431 u8 *buf, int buflen)
3432{
3433 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
3434 int r;
3435
Archit Taneja9e7e9372012-08-14 12:29:22 +05303436 r = dsi_vc_dcs_send_read_request(dsidev, channel, dcs_cmd);
Archit Tanejab8509752011-08-30 15:48:23 +05303437 if (r)
3438 goto err;
3439
3440 r = dsi_vc_send_bta_sync(dssdev, channel);
3441 if (r)
3442 goto err;
3443
Archit Tanejab3b89c02011-08-30 16:07:39 +05303444 r = dsi_vc_read_rx_fifo(dsidev, channel, buf, buflen,
3445 DSS_DSI_CONTENT_DCS);
Archit Tanejab8509752011-08-30 15:48:23 +05303446 if (r < 0)
3447 goto err;
3448
3449 if (r != buflen) {
3450 r = -EIO;
3451 goto err;
3452 }
3453
3454 return 0;
3455err:
3456 DSSERR("dsi_vc_dcs_read(ch %d, cmd 0x%02x) failed\n", channel, dcs_cmd);
3457 return r;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003458}
3459EXPORT_SYMBOL(dsi_vc_dcs_read);
3460
Archit Tanejab3b89c02011-08-30 16:07:39 +05303461static int dsi_vc_generic_read(struct omap_dss_device *dssdev, int channel,
3462 u8 *reqdata, int reqlen, u8 *buf, int buflen)
3463{
3464 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
3465 int r;
3466
Archit Taneja9e7e9372012-08-14 12:29:22 +05303467 r = dsi_vc_generic_send_read_request(dsidev, channel, reqdata, reqlen);
Archit Tanejab3b89c02011-08-30 16:07:39 +05303468 if (r)
3469 return r;
3470
3471 r = dsi_vc_send_bta_sync(dssdev, channel);
3472 if (r)
3473 return r;
3474
3475 r = dsi_vc_read_rx_fifo(dsidev, channel, buf, buflen,
3476 DSS_DSI_CONTENT_GENERIC);
3477 if (r < 0)
3478 return r;
3479
3480 if (r != buflen) {
3481 r = -EIO;
3482 return r;
3483 }
3484
3485 return 0;
3486}
3487
3488int dsi_vc_generic_read_0(struct omap_dss_device *dssdev, int channel, u8 *buf,
3489 int buflen)
3490{
3491 int r;
3492
3493 r = dsi_vc_generic_read(dssdev, channel, NULL, 0, buf, buflen);
3494 if (r) {
3495 DSSERR("dsi_vc_generic_read_0(ch %d) failed\n", channel);
3496 return r;
3497 }
3498
3499 return 0;
3500}
3501EXPORT_SYMBOL(dsi_vc_generic_read_0);
3502
3503int dsi_vc_generic_read_1(struct omap_dss_device *dssdev, int channel, u8 param,
3504 u8 *buf, int buflen)
3505{
3506 int r;
3507
3508 r = dsi_vc_generic_read(dssdev, channel, &param, 1, buf, buflen);
3509 if (r) {
3510 DSSERR("dsi_vc_generic_read_1(ch %d) failed\n", channel);
3511 return r;
3512 }
3513
3514 return 0;
3515}
3516EXPORT_SYMBOL(dsi_vc_generic_read_1);
3517
3518int dsi_vc_generic_read_2(struct omap_dss_device *dssdev, int channel,
3519 u8 param1, u8 param2, u8 *buf, int buflen)
3520{
3521 int r;
3522 u8 reqdata[2];
3523
3524 reqdata[0] = param1;
3525 reqdata[1] = param2;
3526
3527 r = dsi_vc_generic_read(dssdev, channel, reqdata, 2, buf, buflen);
3528 if (r) {
3529 DSSERR("dsi_vc_generic_read_2(ch %d) failed\n", channel);
3530 return r;
3531 }
3532
3533 return 0;
3534}
3535EXPORT_SYMBOL(dsi_vc_generic_read_2);
3536
Archit Taneja1ffefe72011-05-12 17:26:24 +05303537int dsi_vc_set_max_rx_packet_size(struct omap_dss_device *dssdev, int channel,
3538 u16 len)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003539{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303540 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
3541
Archit Taneja7a7c48f2011-08-25 18:25:03 +05303542 return dsi_vc_send_short(dsidev, channel,
3543 MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE, len, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003544}
3545EXPORT_SYMBOL(dsi_vc_set_max_rx_packet_size);
3546
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303547static int dsi_enter_ulps(struct platform_device *dsidev)
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003548{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303549 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003550 DECLARE_COMPLETION_ONSTACK(completion);
Tomi Valkeinen522a0c22011-10-13 16:18:52 +03003551 int r, i;
3552 unsigned mask;
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003553
Chandrabhanu Mahapatra702d2672012-09-24 17:12:58 +05303554 DSSDBG("Entering ULPS");
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003555
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303556 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003557
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303558 WARN_ON(dsi->ulps_enabled);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003559
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303560 if (dsi->ulps_enabled)
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003561 return 0;
3562
Tomi Valkeinen6cc78aa2011-10-13 19:22:43 +03003563 /* DDR_CLK_ALWAYS_ON */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303564 if (REG_GET(dsidev, DSI_CLK_CTRL, 13, 13)) {
Tomi Valkeinen6cc78aa2011-10-13 19:22:43 +03003565 dsi_if_enable(dsidev, 0);
3566 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 13, 13);
3567 dsi_if_enable(dsidev, 1);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003568 }
3569
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303570 dsi_sync_vc(dsidev, 0);
3571 dsi_sync_vc(dsidev, 1);
3572 dsi_sync_vc(dsidev, 2);
3573 dsi_sync_vc(dsidev, 3);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003574
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303575 dsi_force_tx_stop_mode_io(dsidev);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003576
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303577 dsi_vc_enable(dsidev, 0, false);
3578 dsi_vc_enable(dsidev, 1, false);
3579 dsi_vc_enable(dsidev, 2, false);
3580 dsi_vc_enable(dsidev, 3, false);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003581
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303582 if (REG_GET(dsidev, DSI_COMPLEXIO_CFG2, 16, 16)) { /* HS_BUSY */
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003583 DSSERR("HS busy when enabling ULPS\n");
3584 return -EIO;
3585 }
3586
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303587 if (REG_GET(dsidev, DSI_COMPLEXIO_CFG2, 17, 17)) { /* LP_BUSY */
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003588 DSSERR("LP busy when enabling ULPS\n");
3589 return -EIO;
3590 }
3591
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303592 r = dsi_register_isr_cio(dsidev, dsi_completion_handler, &completion,
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003593 DSI_CIO_IRQ_ULPSACTIVENOT_ALL0);
3594 if (r)
3595 return r;
3596
Tomi Valkeinen522a0c22011-10-13 16:18:52 +03003597 mask = 0;
3598
3599 for (i = 0; i < dsi->num_lanes_supported; ++i) {
3600 if (dsi->lanes[i].function == DSI_LANE_UNUSED)
3601 continue;
3602 mask |= 1 << i;
3603 }
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003604 /* Assert TxRequestEsc for data lanes and TxUlpsClk for clk lane */
3605 /* LANEx_ULPS_SIG2 */
Tomi Valkeinen522a0c22011-10-13 16:18:52 +03003606 REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG2, mask, 9, 5);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003607
Tomi Valkeinena702c852011-10-12 10:10:21 +03003608 /* flush posted write and wait for SCP interface to finish the write */
3609 dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG2);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003610
3611 if (wait_for_completion_timeout(&completion,
3612 msecs_to_jiffies(1000)) == 0) {
3613 DSSERR("ULPS enable timeout\n");
3614 r = -EIO;
3615 goto err;
3616 }
3617
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303618 dsi_unregister_isr_cio(dsidev, dsi_completion_handler, &completion,
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003619 DSI_CIO_IRQ_ULPSACTIVENOT_ALL0);
3620
Tomi Valkeinen8ef0e612011-05-31 16:55:47 +03003621 /* Reset LANEx_ULPS_SIG2 */
Tomi Valkeinen522a0c22011-10-13 16:18:52 +03003622 REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG2, 0, 9, 5);
Tomi Valkeinen8ef0e612011-05-31 16:55:47 +03003623
Tomi Valkeinena702c852011-10-12 10:10:21 +03003624 /* flush posted write and wait for SCP interface to finish the write */
3625 dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG2);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003626
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303627 dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_ULPS);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003628
3629 dsi_if_enable(dsidev, false);
3630
3631 dsi->ulps_enabled = true;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303632
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003633 return 0;
3634
3635err:
3636 dsi_unregister_isr_cio(dsidev, dsi_completion_handler, &completion,
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303637 DSI_CIO_IRQ_ULPSACTIVENOT_ALL0);
3638 return r;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003639}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003640
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003641static void dsi_set_lp_rx_timeout(struct platform_device *dsidev,
3642 unsigned ticks, bool x4, bool x16)
3643{
3644 unsigned long fck;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003645 unsigned long total_ticks;
3646 u32 r;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303647
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003648 BUG_ON(ticks > 0x1fff);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303649
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003650 /* ticks in DSI_FCK */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003651 fck = dsi_fclk_rate(dsidev);
3652
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003653 r = dsi_read_reg(dsidev, DSI_TIMING2);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303654 r = FLD_MOD(r, 1, 15, 15); /* LP_RX_TO */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003655 r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* LP_RX_TO_X16 */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003656 r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* LP_RX_TO_X4 */
3657 r = FLD_MOD(r, ticks, 12, 0); /* LP_RX_COUNTER */
3658 dsi_write_reg(dsidev, DSI_TIMING2, r);
3659
3660 total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
3661
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003662 DSSDBG("LP_RX_TO %lu ticks (%#x%s%s) = %lu ns\n",
3663 total_ticks,
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303664 ticks, x4 ? " x4" : "", x16 ? " x16" : "",
3665 (total_ticks * 1000) / (fck / 1000 / 1000));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003666}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003667
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003668static void dsi_set_ta_timeout(struct platform_device *dsidev, unsigned ticks,
3669 bool x8, bool x16)
3670{
3671 unsigned long fck;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003672 unsigned long total_ticks;
3673 u32 r;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303674
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003675 BUG_ON(ticks > 0x1fff);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303676
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003677 /* ticks in DSI_FCK */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003678 fck = dsi_fclk_rate(dsidev);
3679
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003680 r = dsi_read_reg(dsidev, DSI_TIMING1);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303681 r = FLD_MOD(r, 1, 31, 31); /* TA_TO */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003682 r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* TA_TO_X16 */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003683 r = FLD_MOD(r, x8 ? 1 : 0, 29, 29); /* TA_TO_X8 */
3684 r = FLD_MOD(r, ticks, 28, 16); /* TA_TO_COUNTER */
3685 dsi_write_reg(dsidev, DSI_TIMING1, r);
3686
3687 total_ticks = ticks * (x16 ? 16 : 1) * (x8 ? 8 : 1);
3688
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003689 DSSDBG("TA_TO %lu ticks (%#x%s%s) = %lu ns\n",
3690 total_ticks,
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303691 ticks, x8 ? " x8" : "", x16 ? " x16" : "",
3692 (total_ticks * 1000) / (fck / 1000 / 1000));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003693}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003694
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003695static void dsi_set_stop_state_counter(struct platform_device *dsidev,
3696 unsigned ticks, bool x4, bool x16)
3697{
3698 unsigned long fck;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003699 unsigned long total_ticks;
3700 u32 r;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303701
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003702 BUG_ON(ticks > 0x1fff);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303703
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003704 /* ticks in DSI_FCK */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003705 fck = dsi_fclk_rate(dsidev);
3706
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003707 r = dsi_read_reg(dsidev, DSI_TIMING1);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303708 r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003709 r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* STOP_STATE_X16_IO */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003710 r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* STOP_STATE_X4_IO */
3711 r = FLD_MOD(r, ticks, 12, 0); /* STOP_STATE_COUNTER_IO */
3712 dsi_write_reg(dsidev, DSI_TIMING1, r);
3713
3714 total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
3715
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003716 DSSDBG("STOP_STATE_COUNTER %lu ticks (%#x%s%s) = %lu ns\n",
3717 total_ticks,
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303718 ticks, x4 ? " x4" : "", x16 ? " x16" : "",
3719 (total_ticks * 1000) / (fck / 1000 / 1000));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003720}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003721
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003722static void dsi_set_hs_tx_timeout(struct platform_device *dsidev,
3723 unsigned ticks, bool x4, bool x16)
3724{
3725 unsigned long fck;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003726 unsigned long total_ticks;
3727 u32 r;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303728
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003729 BUG_ON(ticks > 0x1fff);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303730
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003731 /* ticks in TxByteClkHS */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003732 fck = dsi_get_txbyteclkhs(dsidev);
3733
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003734 r = dsi_read_reg(dsidev, DSI_TIMING2);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303735 r = FLD_MOD(r, 1, 31, 31); /* HS_TX_TO */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003736 r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* HS_TX_TO_X16 */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003737 r = FLD_MOD(r, x4 ? 1 : 0, 29, 29); /* HS_TX_TO_X8 (4 really) */
3738 r = FLD_MOD(r, ticks, 28, 16); /* HS_TX_TO_COUNTER */
3739 dsi_write_reg(dsidev, DSI_TIMING2, r);
3740
3741 total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
3742
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003743 DSSDBG("HS_TX_TO %lu ticks (%#x%s%s) = %lu ns\n",
3744 total_ticks,
3745 ticks, x4 ? " x4" : "", x16 ? " x16" : "",
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303746 (total_ticks * 1000) / (fck / 1000 / 1000));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003747}
Archit Taneja8af6ff02011-09-05 16:48:27 +05303748
Archit Taneja9e7e9372012-08-14 12:29:22 +05303749static void dsi_config_vp_num_line_buffers(struct platform_device *dsidev)
Archit Taneja8af6ff02011-09-05 16:48:27 +05303750{
Archit Tanejadca2b152012-08-16 18:02:00 +05303751 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Taneja8af6ff02011-09-05 16:48:27 +05303752 int num_line_buffers;
3753
Archit Tanejadca2b152012-08-16 18:02:00 +05303754 if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
Archit Taneja02c39602012-08-10 15:01:33 +05303755 int bpp = dsi_get_pixel_size(dsi->pix_fmt);
Archit Taneja8af6ff02011-09-05 16:48:27 +05303756 unsigned line_buf_size = dsi_get_line_buf_size(dsidev);
Archit Tanejae67458a2012-08-13 14:17:30 +05303757 struct omap_video_timings *timings = &dsi->timings;
Archit Taneja8af6ff02011-09-05 16:48:27 +05303758 /*
3759 * Don't use line buffers if width is greater than the video
3760 * port's line buffer size
3761 */
3762 if (line_buf_size <= timings->x_res * bpp / 8)
3763 num_line_buffers = 0;
3764 else
3765 num_line_buffers = 2;
3766 } else {
3767 /* Use maximum number of line buffers in command mode */
3768 num_line_buffers = 2;
3769 }
3770
3771 /* LINE_BUFFER */
3772 REG_FLD_MOD(dsidev, DSI_CTRL, num_line_buffers, 13, 12);
3773}
3774
Archit Taneja9e7e9372012-08-14 12:29:22 +05303775static void dsi_config_vp_sync_events(struct platform_device *dsidev)
Archit Taneja8af6ff02011-09-05 16:48:27 +05303776{
Archit Taneja0b3ffe32012-08-13 22:13:39 +05303777 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
3778 bool vsync_end = dsi->vm_timings.vp_vsync_end;
3779 bool hsync_end = dsi->vm_timings.vp_hsync_end;
Archit Taneja8af6ff02011-09-05 16:48:27 +05303780 u32 r;
3781
3782 r = dsi_read_reg(dsidev, DSI_CTRL);
Archit Tanejabd5a7b12012-06-26 12:38:31 +05303783 r = FLD_MOD(r, 1, 9, 9); /* VP_DE_POL */
3784 r = FLD_MOD(r, 1, 10, 10); /* VP_HSYNC_POL */
3785 r = FLD_MOD(r, 1, 11, 11); /* VP_VSYNC_POL */
Archit Taneja8af6ff02011-09-05 16:48:27 +05303786 r = FLD_MOD(r, 1, 15, 15); /* VP_VSYNC_START */
3787 r = FLD_MOD(r, vsync_end, 16, 16); /* VP_VSYNC_END */
3788 r = FLD_MOD(r, 1, 17, 17); /* VP_HSYNC_START */
3789 r = FLD_MOD(r, hsync_end, 18, 18); /* VP_HSYNC_END */
3790 dsi_write_reg(dsidev, DSI_CTRL, r);
3791}
3792
Archit Taneja9e7e9372012-08-14 12:29:22 +05303793static void dsi_config_blanking_modes(struct platform_device *dsidev)
Archit Taneja8af6ff02011-09-05 16:48:27 +05303794{
Archit Taneja0b3ffe32012-08-13 22:13:39 +05303795 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
3796 int blanking_mode = dsi->vm_timings.blanking_mode;
3797 int hfp_blanking_mode = dsi->vm_timings.hfp_blanking_mode;
3798 int hbp_blanking_mode = dsi->vm_timings.hbp_blanking_mode;
3799 int hsa_blanking_mode = dsi->vm_timings.hsa_blanking_mode;
Archit Taneja8af6ff02011-09-05 16:48:27 +05303800 u32 r;
3801
3802 /*
3803 * 0 = TX FIFO packets sent or LPS in corresponding blanking periods
3804 * 1 = Long blanking packets are sent in corresponding blanking periods
3805 */
3806 r = dsi_read_reg(dsidev, DSI_CTRL);
3807 r = FLD_MOD(r, blanking_mode, 20, 20); /* BLANKING_MODE */
3808 r = FLD_MOD(r, hfp_blanking_mode, 21, 21); /* HFP_BLANKING */
3809 r = FLD_MOD(r, hbp_blanking_mode, 22, 22); /* HBP_BLANKING */
3810 r = FLD_MOD(r, hsa_blanking_mode, 23, 23); /* HSA_BLANKING */
3811 dsi_write_reg(dsidev, DSI_CTRL, r);
3812}
3813
Archit Taneja6f28c292012-05-15 11:32:18 +05303814/*
3815 * According to section 'HS Command Mode Interleaving' in OMAP TRM, Scenario 3
3816 * results in maximum transition time for data and clock lanes to enter and
3817 * exit HS mode. Hence, this is the scenario where the least amount of command
3818 * mode data can be interleaved. We program the minimum amount of TXBYTECLKHS
3819 * clock cycles that can be used to interleave command mode data in HS so that
3820 * all scenarios are satisfied.
3821 */
3822static int dsi_compute_interleave_hs(int blank, bool ddr_alwon, int enter_hs,
3823 int exit_hs, int exiths_clk, int ddr_pre, int ddr_post)
3824{
3825 int transition;
3826
3827 /*
3828 * If DDR_CLK_ALWAYS_ON is set, we need to consider HS mode transition
3829 * time of data lanes only, if it isn't set, we need to consider HS
3830 * transition time of both data and clock lanes. HS transition time
3831 * of Scenario 3 is considered.
3832 */
3833 if (ddr_alwon) {
3834 transition = enter_hs + exit_hs + max(enter_hs, 2) + 1;
3835 } else {
3836 int trans1, trans2;
3837 trans1 = ddr_pre + enter_hs + exit_hs + max(enter_hs, 2) + 1;
3838 trans2 = ddr_pre + enter_hs + exiths_clk + ddr_post + ddr_pre +
3839 enter_hs + 1;
3840 transition = max(trans1, trans2);
3841 }
3842
3843 return blank > transition ? blank - transition : 0;
3844}
3845
3846/*
3847 * According to section 'LP Command Mode Interleaving' in OMAP TRM, Scenario 1
3848 * results in maximum transition time for data lanes to enter and exit LP mode.
3849 * Hence, this is the scenario where the least amount of command mode data can
3850 * be interleaved. We program the minimum amount of bytes that can be
3851 * interleaved in LP so that all scenarios are satisfied.
3852 */
3853static int dsi_compute_interleave_lp(int blank, int enter_hs, int exit_hs,
3854 int lp_clk_div, int tdsi_fclk)
3855{
3856 int trans_lp; /* time required for a LP transition, in TXBYTECLKHS */
3857 int tlp_avail; /* time left for interleaving commands, in CLKIN4DDR */
3858 int ttxclkesc; /* period of LP transmit escape clock, in CLKIN4DDR */
3859 int thsbyte_clk = 16; /* Period of TXBYTECLKHS clock, in CLKIN4DDR */
3860 int lp_inter; /* cmd mode data that can be interleaved, in bytes */
3861
3862 /* maximum LP transition time according to Scenario 1 */
3863 trans_lp = exit_hs + max(enter_hs, 2) + 1;
3864
3865 /* CLKIN4DDR = 16 * TXBYTECLKHS */
3866 tlp_avail = thsbyte_clk * (blank - trans_lp);
3867
Archit Taneja2e063c32012-06-04 13:36:34 +05303868 ttxclkesc = tdsi_fclk * lp_clk_div;
Archit Taneja6f28c292012-05-15 11:32:18 +05303869
3870 lp_inter = ((tlp_avail - 8 * thsbyte_clk - 5 * tdsi_fclk) / ttxclkesc -
3871 26) / 16;
3872
3873 return max(lp_inter, 0);
3874}
3875
3876static void dsi_config_cmd_mode_interleaving(struct omap_dss_device *dssdev)
3877{
3878 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
3879 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
3880 int blanking_mode;
3881 int hfp_blanking_mode, hbp_blanking_mode, hsa_blanking_mode;
3882 int hsa, hfp, hbp, width_bytes, bllp, lp_clk_div;
3883 int ddr_clk_pre, ddr_clk_post, enter_hs_mode_lat, exit_hs_mode_lat;
3884 int tclk_trail, ths_exit, exiths_clk;
3885 bool ddr_alwon;
Archit Tanejae67458a2012-08-13 14:17:30 +05303886 struct omap_video_timings *timings = &dsi->timings;
Archit Taneja02c39602012-08-10 15:01:33 +05303887 int bpp = dsi_get_pixel_size(dsi->pix_fmt);
Archit Taneja6f28c292012-05-15 11:32:18 +05303888 int ndl = dsi->num_lanes_used - 1;
3889 int dsi_fclk_hsdiv = dssdev->clocks.dsi.regm_dsi + 1;
3890 int hsa_interleave_hs = 0, hsa_interleave_lp = 0;
3891 int hfp_interleave_hs = 0, hfp_interleave_lp = 0;
3892 int hbp_interleave_hs = 0, hbp_interleave_lp = 0;
3893 int bl_interleave_hs = 0, bl_interleave_lp = 0;
3894 u32 r;
3895
3896 r = dsi_read_reg(dsidev, DSI_CTRL);
3897 blanking_mode = FLD_GET(r, 20, 20);
3898 hfp_blanking_mode = FLD_GET(r, 21, 21);
3899 hbp_blanking_mode = FLD_GET(r, 22, 22);
3900 hsa_blanking_mode = FLD_GET(r, 23, 23);
3901
3902 r = dsi_read_reg(dsidev, DSI_VM_TIMING1);
3903 hbp = FLD_GET(r, 11, 0);
3904 hfp = FLD_GET(r, 23, 12);
3905 hsa = FLD_GET(r, 31, 24);
3906
3907 r = dsi_read_reg(dsidev, DSI_CLK_TIMING);
3908 ddr_clk_post = FLD_GET(r, 7, 0);
3909 ddr_clk_pre = FLD_GET(r, 15, 8);
3910
3911 r = dsi_read_reg(dsidev, DSI_VM_TIMING7);
3912 exit_hs_mode_lat = FLD_GET(r, 15, 0);
3913 enter_hs_mode_lat = FLD_GET(r, 31, 16);
3914
3915 r = dsi_read_reg(dsidev, DSI_CLK_CTRL);
3916 lp_clk_div = FLD_GET(r, 12, 0);
3917 ddr_alwon = FLD_GET(r, 13, 13);
3918
3919 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0);
3920 ths_exit = FLD_GET(r, 7, 0);
3921
3922 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1);
3923 tclk_trail = FLD_GET(r, 15, 8);
3924
3925 exiths_clk = ths_exit + tclk_trail;
3926
3927 width_bytes = DIV_ROUND_UP(timings->x_res * bpp, 8);
3928 bllp = hbp + hfp + hsa + DIV_ROUND_UP(width_bytes + 6, ndl);
3929
3930 if (!hsa_blanking_mode) {
3931 hsa_interleave_hs = dsi_compute_interleave_hs(hsa, ddr_alwon,
3932 enter_hs_mode_lat, exit_hs_mode_lat,
3933 exiths_clk, ddr_clk_pre, ddr_clk_post);
3934 hsa_interleave_lp = dsi_compute_interleave_lp(hsa,
3935 enter_hs_mode_lat, exit_hs_mode_lat,
3936 lp_clk_div, dsi_fclk_hsdiv);
3937 }
3938
3939 if (!hfp_blanking_mode) {
3940 hfp_interleave_hs = dsi_compute_interleave_hs(hfp, ddr_alwon,
3941 enter_hs_mode_lat, exit_hs_mode_lat,
3942 exiths_clk, ddr_clk_pre, ddr_clk_post);
3943 hfp_interleave_lp = dsi_compute_interleave_lp(hfp,
3944 enter_hs_mode_lat, exit_hs_mode_lat,
3945 lp_clk_div, dsi_fclk_hsdiv);
3946 }
3947
3948 if (!hbp_blanking_mode) {
3949 hbp_interleave_hs = dsi_compute_interleave_hs(hbp, ddr_alwon,
3950 enter_hs_mode_lat, exit_hs_mode_lat,
3951 exiths_clk, ddr_clk_pre, ddr_clk_post);
3952
3953 hbp_interleave_lp = dsi_compute_interleave_lp(hbp,
3954 enter_hs_mode_lat, exit_hs_mode_lat,
3955 lp_clk_div, dsi_fclk_hsdiv);
3956 }
3957
3958 if (!blanking_mode) {
3959 bl_interleave_hs = dsi_compute_interleave_hs(bllp, ddr_alwon,
3960 enter_hs_mode_lat, exit_hs_mode_lat,
3961 exiths_clk, ddr_clk_pre, ddr_clk_post);
3962
3963 bl_interleave_lp = dsi_compute_interleave_lp(bllp,
3964 enter_hs_mode_lat, exit_hs_mode_lat,
3965 lp_clk_div, dsi_fclk_hsdiv);
3966 }
3967
3968 DSSDBG("DSI HS interleaving(TXBYTECLKHS) HSA %d, HFP %d, HBP %d, BLLP %d\n",
3969 hsa_interleave_hs, hfp_interleave_hs, hbp_interleave_hs,
3970 bl_interleave_hs);
3971
3972 DSSDBG("DSI LP interleaving(bytes) HSA %d, HFP %d, HBP %d, BLLP %d\n",
3973 hsa_interleave_lp, hfp_interleave_lp, hbp_interleave_lp,
3974 bl_interleave_lp);
3975
3976 r = dsi_read_reg(dsidev, DSI_VM_TIMING4);
3977 r = FLD_MOD(r, hsa_interleave_hs, 23, 16);
3978 r = FLD_MOD(r, hfp_interleave_hs, 15, 8);
3979 r = FLD_MOD(r, hbp_interleave_hs, 7, 0);
3980 dsi_write_reg(dsidev, DSI_VM_TIMING4, r);
3981
3982 r = dsi_read_reg(dsidev, DSI_VM_TIMING5);
3983 r = FLD_MOD(r, hsa_interleave_lp, 23, 16);
3984 r = FLD_MOD(r, hfp_interleave_lp, 15, 8);
3985 r = FLD_MOD(r, hbp_interleave_lp, 7, 0);
3986 dsi_write_reg(dsidev, DSI_VM_TIMING5, r);
3987
3988 r = dsi_read_reg(dsidev, DSI_VM_TIMING6);
3989 r = FLD_MOD(r, bl_interleave_hs, 31, 15);
3990 r = FLD_MOD(r, bl_interleave_lp, 16, 0);
3991 dsi_write_reg(dsidev, DSI_VM_TIMING6, r);
3992}
3993
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003994static int dsi_proto_config(struct omap_dss_device *dssdev)
3995{
3996 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Taneja02c39602012-08-10 15:01:33 +05303997 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003998 u32 r;
3999 int buswidth = 0;
4000
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304001 dsi_config_tx_fifo(dsidev, DSI_FIFO_SIZE_32,
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02004002 DSI_FIFO_SIZE_32,
4003 DSI_FIFO_SIZE_32,
4004 DSI_FIFO_SIZE_32);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004005
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304006 dsi_config_rx_fifo(dsidev, DSI_FIFO_SIZE_32,
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02004007 DSI_FIFO_SIZE_32,
4008 DSI_FIFO_SIZE_32,
4009 DSI_FIFO_SIZE_32);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004010
4011 /* XXX what values for the timeouts? */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304012 dsi_set_stop_state_counter(dsidev, 0x1000, false, false);
4013 dsi_set_ta_timeout(dsidev, 0x1fff, true, true);
4014 dsi_set_lp_rx_timeout(dsidev, 0x1fff, true, true);
4015 dsi_set_hs_tx_timeout(dsidev, 0x1fff, true, true);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004016
Archit Taneja02c39602012-08-10 15:01:33 +05304017 switch (dsi_get_pixel_size(dsi->pix_fmt)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004018 case 16:
4019 buswidth = 0;
4020 break;
4021 case 18:
4022 buswidth = 1;
4023 break;
4024 case 24:
4025 buswidth = 2;
4026 break;
4027 default:
4028 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03004029 return -EINVAL;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004030 }
4031
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304032 r = dsi_read_reg(dsidev, DSI_CTRL);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004033 r = FLD_MOD(r, 1, 1, 1); /* CS_RX_EN */
4034 r = FLD_MOD(r, 1, 2, 2); /* ECC_RX_EN */
4035 r = FLD_MOD(r, 1, 3, 3); /* TX_FIFO_ARBITRATION */
4036 r = FLD_MOD(r, 1, 4, 4); /* VP_CLK_RATIO, always 1, see errata*/
4037 r = FLD_MOD(r, buswidth, 7, 6); /* VP_DATA_BUS_WIDTH */
4038 r = FLD_MOD(r, 0, 8, 8); /* VP_CLK_POL */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004039 r = FLD_MOD(r, 1, 14, 14); /* TRIGGER_RESET_MODE */
4040 r = FLD_MOD(r, 1, 19, 19); /* EOT_ENABLE */
Archit Taneja9613c022011-03-22 06:33:36 -05004041 if (!dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC)) {
4042 r = FLD_MOD(r, 1, 24, 24); /* DCS_CMD_ENABLE */
4043 /* DCS_CMD_CODE, 1=start, 0=continue */
4044 r = FLD_MOD(r, 0, 25, 25);
4045 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004046
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304047 dsi_write_reg(dsidev, DSI_CTRL, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004048
Archit Taneja9e7e9372012-08-14 12:29:22 +05304049 dsi_config_vp_num_line_buffers(dsidev);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304050
Archit Tanejadca2b152012-08-16 18:02:00 +05304051 if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
Archit Taneja9e7e9372012-08-14 12:29:22 +05304052 dsi_config_vp_sync_events(dsidev);
4053 dsi_config_blanking_modes(dsidev);
Archit Taneja6f28c292012-05-15 11:32:18 +05304054 dsi_config_cmd_mode_interleaving(dssdev);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304055 }
4056
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304057 dsi_vc_initial_config(dsidev, 0);
4058 dsi_vc_initial_config(dsidev, 1);
4059 dsi_vc_initial_config(dsidev, 2);
4060 dsi_vc_initial_config(dsidev, 3);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004061
4062 return 0;
4063}
4064
Archit Taneja9e7e9372012-08-14 12:29:22 +05304065static void dsi_proto_timings(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004066{
Tomi Valkeinendb186442011-10-13 16:12:29 +03004067 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004068 unsigned tlpx, tclk_zero, tclk_prepare, tclk_trail;
4069 unsigned tclk_pre, tclk_post;
4070 unsigned ths_prepare, ths_prepare_ths_zero, ths_zero;
4071 unsigned ths_trail, ths_exit;
4072 unsigned ddr_clk_pre, ddr_clk_post;
4073 unsigned enter_hs_mode_lat, exit_hs_mode_lat;
4074 unsigned ths_eot;
Tomi Valkeinendb186442011-10-13 16:12:29 +03004075 int ndl = dsi->num_lanes_used - 1;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004076 u32 r;
4077
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304078 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004079 ths_prepare = FLD_GET(r, 31, 24);
4080 ths_prepare_ths_zero = FLD_GET(r, 23, 16);
4081 ths_zero = ths_prepare_ths_zero - ths_prepare;
4082 ths_trail = FLD_GET(r, 15, 8);
4083 ths_exit = FLD_GET(r, 7, 0);
4084
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304085 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1);
Tomi Valkeinene84dc1c2012-09-24 09:34:52 +03004086 tlpx = FLD_GET(r, 20, 16) * 2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004087 tclk_trail = FLD_GET(r, 15, 8);
4088 tclk_zero = FLD_GET(r, 7, 0);
4089
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304090 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG2);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004091 tclk_prepare = FLD_GET(r, 7, 0);
4092
4093 /* min 8*UI */
4094 tclk_pre = 20;
4095 /* min 60ns + 52*UI */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304096 tclk_post = ns2ddr(dsidev, 60) + 26;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004097
Archit Taneja8af6ff02011-09-05 16:48:27 +05304098 ths_eot = DIV_ROUND_UP(4, ndl);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004099
4100 ddr_clk_pre = DIV_ROUND_UP(tclk_pre + tlpx + tclk_zero + tclk_prepare,
4101 4);
4102 ddr_clk_post = DIV_ROUND_UP(tclk_post + ths_trail, 4) + ths_eot;
4103
4104 BUG_ON(ddr_clk_pre == 0 || ddr_clk_pre > 255);
4105 BUG_ON(ddr_clk_post == 0 || ddr_clk_post > 255);
4106
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304107 r = dsi_read_reg(dsidev, DSI_CLK_TIMING);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004108 r = FLD_MOD(r, ddr_clk_pre, 15, 8);
4109 r = FLD_MOD(r, ddr_clk_post, 7, 0);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304110 dsi_write_reg(dsidev, DSI_CLK_TIMING, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004111
4112 DSSDBG("ddr_clk_pre %u, ddr_clk_post %u\n",
4113 ddr_clk_pre,
4114 ddr_clk_post);
4115
4116 enter_hs_mode_lat = 1 + DIV_ROUND_UP(tlpx, 4) +
4117 DIV_ROUND_UP(ths_prepare, 4) +
4118 DIV_ROUND_UP(ths_zero + 3, 4);
4119
4120 exit_hs_mode_lat = DIV_ROUND_UP(ths_trail + ths_exit, 4) + 1 + ths_eot;
4121
4122 r = FLD_VAL(enter_hs_mode_lat, 31, 16) |
4123 FLD_VAL(exit_hs_mode_lat, 15, 0);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304124 dsi_write_reg(dsidev, DSI_VM_TIMING7, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004125
4126 DSSDBG("enter_hs_mode_lat %u, exit_hs_mode_lat %u\n",
4127 enter_hs_mode_lat, exit_hs_mode_lat);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304128
Archit Tanejadca2b152012-08-16 18:02:00 +05304129 if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
Archit Taneja8af6ff02011-09-05 16:48:27 +05304130 /* TODO: Implement a video mode check_timings function */
Archit Taneja0b3ffe32012-08-13 22:13:39 +05304131 int hsa = dsi->vm_timings.hsa;
4132 int hfp = dsi->vm_timings.hfp;
4133 int hbp = dsi->vm_timings.hbp;
4134 int vsa = dsi->vm_timings.vsa;
4135 int vfp = dsi->vm_timings.vfp;
4136 int vbp = dsi->vm_timings.vbp;
4137 int window_sync = dsi->vm_timings.window_sync;
4138 bool hsync_end = dsi->vm_timings.vp_hsync_end;
Archit Tanejae67458a2012-08-13 14:17:30 +05304139 struct omap_video_timings *timings = &dsi->timings;
Archit Taneja02c39602012-08-10 15:01:33 +05304140 int bpp = dsi_get_pixel_size(dsi->pix_fmt);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304141 int tl, t_he, width_bytes;
4142
4143 t_he = hsync_end ?
4144 ((hsa == 0 && ndl == 3) ? 1 : DIV_ROUND_UP(4, ndl)) : 0;
4145
4146 width_bytes = DIV_ROUND_UP(timings->x_res * bpp, 8);
4147
4148 /* TL = t_HS + HSA + t_HE + HFP + ceil((WC + 6) / NDL) + HBP */
4149 tl = DIV_ROUND_UP(4, ndl) + (hsync_end ? hsa : 0) + t_he + hfp +
4150 DIV_ROUND_UP(width_bytes + 6, ndl) + hbp;
4151
4152 DSSDBG("HBP: %d, HFP: %d, HSA: %d, TL: %d TXBYTECLKHS\n", hbp,
4153 hfp, hsync_end ? hsa : 0, tl);
4154 DSSDBG("VBP: %d, VFP: %d, VSA: %d, VACT: %d lines\n", vbp, vfp,
4155 vsa, timings->y_res);
4156
4157 r = dsi_read_reg(dsidev, DSI_VM_TIMING1);
4158 r = FLD_MOD(r, hbp, 11, 0); /* HBP */
4159 r = FLD_MOD(r, hfp, 23, 12); /* HFP */
4160 r = FLD_MOD(r, hsync_end ? hsa : 0, 31, 24); /* HSA */
4161 dsi_write_reg(dsidev, DSI_VM_TIMING1, r);
4162
4163 r = dsi_read_reg(dsidev, DSI_VM_TIMING2);
4164 r = FLD_MOD(r, vbp, 7, 0); /* VBP */
4165 r = FLD_MOD(r, vfp, 15, 8); /* VFP */
4166 r = FLD_MOD(r, vsa, 23, 16); /* VSA */
4167 r = FLD_MOD(r, window_sync, 27, 24); /* WINDOW_SYNC */
4168 dsi_write_reg(dsidev, DSI_VM_TIMING2, r);
4169
4170 r = dsi_read_reg(dsidev, DSI_VM_TIMING3);
4171 r = FLD_MOD(r, timings->y_res, 14, 0); /* VACT */
4172 r = FLD_MOD(r, tl, 31, 16); /* TL */
4173 dsi_write_reg(dsidev, DSI_VM_TIMING3, r);
4174 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004175}
4176
Tomi Valkeinene4a9e942012-03-28 15:58:56 +03004177int omapdss_dsi_configure_pins(struct omap_dss_device *dssdev,
4178 const struct omap_dsi_pin_config *pin_cfg)
4179{
4180 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4181 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4182 int num_pins;
4183 const int *pins;
4184 struct dsi_lane_config lanes[DSI_MAX_NR_LANES];
4185 int num_lanes;
4186 int i;
4187
4188 static const enum dsi_lane_function functions[] = {
4189 DSI_LANE_CLK,
4190 DSI_LANE_DATA1,
4191 DSI_LANE_DATA2,
4192 DSI_LANE_DATA3,
4193 DSI_LANE_DATA4,
4194 };
4195
4196 num_pins = pin_cfg->num_pins;
4197 pins = pin_cfg->pins;
4198
4199 if (num_pins < 4 || num_pins > dsi->num_lanes_supported * 2
4200 || num_pins % 2 != 0)
4201 return -EINVAL;
4202
4203 for (i = 0; i < DSI_MAX_NR_LANES; ++i)
4204 lanes[i].function = DSI_LANE_UNUSED;
4205
4206 num_lanes = 0;
4207
4208 for (i = 0; i < num_pins; i += 2) {
4209 u8 lane, pol;
4210 int dx, dy;
4211
4212 dx = pins[i];
4213 dy = pins[i + 1];
4214
4215 if (dx < 0 || dx >= dsi->num_lanes_supported * 2)
4216 return -EINVAL;
4217
4218 if (dy < 0 || dy >= dsi->num_lanes_supported * 2)
4219 return -EINVAL;
4220
4221 if (dx & 1) {
4222 if (dy != dx - 1)
4223 return -EINVAL;
4224 pol = 1;
4225 } else {
4226 if (dy != dx + 1)
4227 return -EINVAL;
4228 pol = 0;
4229 }
4230
4231 lane = dx / 2;
4232
4233 lanes[lane].function = functions[i / 2];
4234 lanes[lane].polarity = pol;
4235 num_lanes++;
4236 }
4237
4238 memcpy(dsi->lanes, lanes, sizeof(dsi->lanes));
4239 dsi->num_lanes_used = num_lanes;
4240
4241 return 0;
4242}
4243EXPORT_SYMBOL(omapdss_dsi_configure_pins);
4244
Tomi Valkeinenee144e62012-08-10 16:50:51 +03004245int omapdss_dsi_set_clocks(struct omap_dss_device *dssdev,
4246 unsigned long ddr_clk, unsigned long lp_clk)
4247{
4248 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4249 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4250 struct dsi_clock_info cinfo;
4251 struct dispc_clock_info dispc_cinfo;
4252 unsigned lp_clk_div;
4253 unsigned long dsi_fclk;
4254 int bpp = dsi_get_pixel_size(dssdev->panel.dsi_pix_fmt);
4255 unsigned long pck;
4256 int r;
4257
Chandrabhanu Mahapatra702d2672012-09-24 17:12:58 +05304258 DSSDBG("Setting DSI clocks: ddr_clk %lu, lp_clk %lu", ddr_clk, lp_clk);
Tomi Valkeinenee144e62012-08-10 16:50:51 +03004259
4260 mutex_lock(&dsi->lock);
4261
Tomi Valkeinend66b1582012-09-24 15:15:06 +03004262 /* Calculate PLL output clock */
4263 r = dsi_pll_calc_ddrfreq(dsidev, ddr_clk * 4, &cinfo);
Tomi Valkeinenee144e62012-08-10 16:50:51 +03004264 if (r)
4265 goto err;
4266
Tomi Valkeinend66b1582012-09-24 15:15:06 +03004267 /* Calculate PLL's DSI clock */
4268 dsi_pll_calc_dsi_fck(dsidev, &cinfo);
4269
4270 /* Calculate PLL's DISPC clock and pck & lck divs */
4271 pck = cinfo.clkin4ddr / 16 * (dsi->num_lanes_used - 1) * 8 / bpp;
4272 DSSDBG("finding dispc dividers for pck %lu\n", pck);
4273 r = dsi_pll_calc_dispc_fck(dsidev, pck, &cinfo, &dispc_cinfo);
4274 if (r)
4275 goto err;
4276
4277 /* Calculate LP clock */
4278 dsi_fclk = cinfo.dsi_pll_hsdiv_dsi_clk;
4279 lp_clk_div = DIV_ROUND_UP(dsi_fclk, lp_clk * 2);
4280
Tomi Valkeinenee144e62012-08-10 16:50:51 +03004281 dssdev->clocks.dsi.regn = cinfo.regn;
4282 dssdev->clocks.dsi.regm = cinfo.regm;
4283 dssdev->clocks.dsi.regm_dispc = cinfo.regm_dispc;
4284 dssdev->clocks.dsi.regm_dsi = cinfo.regm_dsi;
4285
Tomi Valkeinenee144e62012-08-10 16:50:51 +03004286 dssdev->clocks.dsi.lp_clk_div = lp_clk_div;
4287
Tomi Valkeinenee144e62012-08-10 16:50:51 +03004288 dssdev->clocks.dispc.channel.lck_div = dispc_cinfo.lck_div;
4289 dssdev->clocks.dispc.channel.pck_div = dispc_cinfo.pck_div;
4290
Tomi Valkeinenee144e62012-08-10 16:50:51 +03004291 dssdev->clocks.dispc.dispc_fclk_src = OMAP_DSS_CLK_SRC_FCK;
4292
4293 dssdev->clocks.dispc.channel.lcd_clk_src =
4294 dsi->module_id == 0 ?
4295 OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC :
4296 OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC;
4297
4298 dssdev->clocks.dsi.dsi_fclk_src =
4299 dsi->module_id == 0 ?
4300 OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI :
4301 OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DSI;
4302
4303 mutex_unlock(&dsi->lock);
4304 return 0;
4305err:
4306 mutex_unlock(&dsi->lock);
4307 return r;
4308}
4309EXPORT_SYMBOL(omapdss_dsi_set_clocks);
4310
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004311int dsi_enable_video_output(struct omap_dss_device *dssdev, int channel)
Archit Taneja8af6ff02011-09-05 16:48:27 +05304312{
4313 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejae67458a2012-08-13 14:17:30 +05304314 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejaeea83402012-09-04 11:42:36 +05304315 struct omap_overlay_manager *mgr = dssdev->output->manager;
Archit Taneja02c39602012-08-10 15:01:33 +05304316 int bpp = dsi_get_pixel_size(dsi->pix_fmt);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304317 u8 data_type;
4318 u16 word_count;
Tomi Valkeinen33ca2372011-11-21 13:42:58 +02004319 int r;
Archit Taneja8af6ff02011-09-05 16:48:27 +05304320
Archit Tanejadca2b152012-08-16 18:02:00 +05304321 if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
Archit Taneja02c39602012-08-10 15:01:33 +05304322 switch (dsi->pix_fmt) {
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004323 case OMAP_DSS_DSI_FMT_RGB888:
4324 data_type = MIPI_DSI_PACKED_PIXEL_STREAM_24;
4325 break;
4326 case OMAP_DSS_DSI_FMT_RGB666:
4327 data_type = MIPI_DSI_PIXEL_STREAM_3BYTE_18;
4328 break;
4329 case OMAP_DSS_DSI_FMT_RGB666_PACKED:
4330 data_type = MIPI_DSI_PACKED_PIXEL_STREAM_18;
4331 break;
4332 case OMAP_DSS_DSI_FMT_RGB565:
4333 data_type = MIPI_DSI_PACKED_PIXEL_STREAM_16;
4334 break;
4335 default:
4336 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03004337 return -EINVAL;
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004338 };
Archit Taneja8af6ff02011-09-05 16:48:27 +05304339
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004340 dsi_if_enable(dsidev, false);
4341 dsi_vc_enable(dsidev, channel, false);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304342
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004343 /* MODE, 1 = video mode */
4344 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 1, 4, 4);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304345
Archit Tanejae67458a2012-08-13 14:17:30 +05304346 word_count = DIV_ROUND_UP(dsi->timings.x_res * bpp, 8);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304347
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004348 dsi_vc_write_long_header(dsidev, channel, data_type,
4349 word_count, 0);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304350
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004351 dsi_vc_enable(dsidev, channel, true);
4352 dsi_if_enable(dsidev, true);
4353 }
Archit Taneja8af6ff02011-09-05 16:48:27 +05304354
Archit Tanejaeea83402012-09-04 11:42:36 +05304355 r = dss_mgr_enable(mgr);
Tomi Valkeinen33ca2372011-11-21 13:42:58 +02004356 if (r) {
Archit Tanejadca2b152012-08-16 18:02:00 +05304357 if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
Tomi Valkeinen33ca2372011-11-21 13:42:58 +02004358 dsi_if_enable(dsidev, false);
4359 dsi_vc_enable(dsidev, channel, false);
4360 }
4361
4362 return r;
4363 }
Archit Taneja8af6ff02011-09-05 16:48:27 +05304364
4365 return 0;
4366}
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004367EXPORT_SYMBOL(dsi_enable_video_output);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304368
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004369void dsi_disable_video_output(struct omap_dss_device *dssdev, int channel)
Archit Taneja8af6ff02011-09-05 16:48:27 +05304370{
4371 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejadca2b152012-08-16 18:02:00 +05304372 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejaeea83402012-09-04 11:42:36 +05304373 struct omap_overlay_manager *mgr = dssdev->output->manager;
Archit Taneja8af6ff02011-09-05 16:48:27 +05304374
Archit Tanejadca2b152012-08-16 18:02:00 +05304375 if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004376 dsi_if_enable(dsidev, false);
4377 dsi_vc_enable(dsidev, channel, false);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304378
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004379 /* MODE, 0 = command mode */
4380 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 0, 4, 4);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304381
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004382 dsi_vc_enable(dsidev, channel, true);
4383 dsi_if_enable(dsidev, true);
4384 }
Archit Taneja8af6ff02011-09-05 16:48:27 +05304385
Archit Tanejaeea83402012-09-04 11:42:36 +05304386 dss_mgr_disable(mgr);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304387}
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004388EXPORT_SYMBOL(dsi_disable_video_output);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304389
Archit Taneja55cd63a2012-08-09 15:41:13 +05304390static void dsi_update_screen_dispc(struct omap_dss_device *dssdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004391{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304392 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304393 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejaeea83402012-09-04 11:42:36 +05304394 struct omap_overlay_manager *mgr = dssdev->output->manager;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004395 unsigned bytespp;
4396 unsigned bytespl;
4397 unsigned bytespf;
4398 unsigned total_len;
4399 unsigned packet_payload;
4400 unsigned packet_len;
4401 u32 l;
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03004402 int r;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304403 const unsigned channel = dsi->update_channel;
Archit Taneja0c656222011-05-16 15:17:09 +05304404 const unsigned line_buf_size = dsi_get_line_buf_size(dsidev);
Archit Taneja55cd63a2012-08-09 15:41:13 +05304405 u16 w = dsi->timings.x_res;
4406 u16 h = dsi->timings.y_res;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004407
Tomi Valkeinen5476e742011-11-03 16:34:20 +02004408 DSSDBG("dsi_update_screen_dispc(%dx%d)\n", w, h);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004409
Archit Tanejad6049142011-08-22 11:58:08 +05304410 dsi_vc_config_source(dsidev, channel, DSI_VC_SOURCE_VP);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004411
Archit Taneja02c39602012-08-10 15:01:33 +05304412 bytespp = dsi_get_pixel_size(dsi->pix_fmt) / 8;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004413 bytespl = w * bytespp;
4414 bytespf = bytespl * h;
4415
4416 /* NOTE: packet_payload has to be equal to N * bytespl, where N is
4417 * number of lines in a packet. See errata about VP_CLK_RATIO */
4418
4419 if (bytespf < line_buf_size)
4420 packet_payload = bytespf;
4421 else
4422 packet_payload = (line_buf_size) / bytespl * bytespl;
4423
4424 packet_len = packet_payload + 1; /* 1 byte for DCS cmd */
4425 total_len = (bytespf / packet_payload) * packet_len;
4426
4427 if (bytespf % packet_payload)
4428 total_len += (bytespf % packet_payload) + 1;
4429
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004430 l = FLD_VAL(total_len, 23, 0); /* TE_SIZE */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304431 dsi_write_reg(dsidev, DSI_VC_TE(channel), l);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004432
Archit Taneja7a7c48f2011-08-25 18:25:03 +05304433 dsi_vc_write_long_header(dsidev, channel, MIPI_DSI_DCS_LONG_WRITE,
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304434 packet_len, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004435
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304436 if (dsi->te_enabled)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004437 l = FLD_MOD(l, 1, 30, 30); /* TE_EN */
4438 else
4439 l = FLD_MOD(l, 1, 31, 31); /* TE_START */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304440 dsi_write_reg(dsidev, DSI_VC_TE(channel), l);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004441
4442 /* We put SIDLEMODE to no-idle for the duration of the transfer,
4443 * because DSS interrupts are not capable of waking up the CPU and the
4444 * framedone interrupt could be delayed for quite a long time. I think
4445 * the same goes for any DSS interrupts, but for some reason I have not
4446 * seen the problem anywhere else than here.
4447 */
4448 dispc_disable_sidle();
4449
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304450 dsi_perf_mark_start(dsidev);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004451
Archit Taneja49dbf582011-05-16 15:17:07 +05304452 r = schedule_delayed_work(&dsi->framedone_timeout_work,
4453 msecs_to_jiffies(250));
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03004454 BUG_ON(r == 0);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004455
Archit Tanejaeea83402012-09-04 11:42:36 +05304456 dss_mgr_set_timings(mgr, &dsi->timings);
Archit Taneja55cd63a2012-08-09 15:41:13 +05304457
Archit Tanejaeea83402012-09-04 11:42:36 +05304458 dss_mgr_start_update(mgr);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004459
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304460 if (dsi->te_enabled) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004461 /* disable LP_RX_TO, so that we can receive TE. Time to wait
4462 * for TE is longer than the timer allows */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304463 REG_FLD_MOD(dsidev, DSI_TIMING2, 0, 15, 15); /* LP_RX_TO */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004464
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304465 dsi_vc_send_bta(dsidev, channel);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004466
4467#ifdef DSI_CATCH_MISSING_TE
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304468 mod_timer(&dsi->te_timer, jiffies + msecs_to_jiffies(250));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004469#endif
4470 }
4471}
4472
4473#ifdef DSI_CATCH_MISSING_TE
4474static void dsi_te_timeout(unsigned long arg)
4475{
4476 DSSERR("TE not received for 250ms!\n");
4477}
4478#endif
4479
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304480static void dsi_handle_framedone(struct platform_device *dsidev, int error)
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004481{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304482 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4483
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004484 /* SIDLEMODE back to smart-idle */
4485 dispc_enable_sidle();
4486
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304487 if (dsi->te_enabled) {
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004488 /* enable LP_RX_TO again after the TE */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304489 REG_FLD_MOD(dsidev, DSI_TIMING2, 1, 15, 15); /* LP_RX_TO */
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004490 }
4491
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304492 dsi->framedone_callback(error, dsi->framedone_data);
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004493
4494 if (!error)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304495 dsi_perf_show(dsidev, "DISPC");
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004496}
4497
4498static void dsi_framedone_timeout_work_callback(struct work_struct *work)
4499{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304500 struct dsi_data *dsi = container_of(work, struct dsi_data,
4501 framedone_timeout_work.work);
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03004502 /* XXX While extremely unlikely, we could get FRAMEDONE interrupt after
4503 * 250ms which would conflict with this timeout work. What should be
4504 * done is first cancel the transfer on the HW, and then cancel the
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004505 * possibly scheduled framedone work. However, cancelling the transfer
4506 * on the HW is buggy, and would probably require resetting the whole
4507 * DSI */
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03004508
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004509 DSSERR("Framedone not received for 250ms!\n");
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004510
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304511 dsi_handle_framedone(dsi->pdev, -ETIMEDOUT);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004512}
4513
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004514static void dsi_framedone_irq_callback(void *data, u32 mask)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004515{
Archit Taneja9e7e9372012-08-14 12:29:22 +05304516 struct platform_device *dsidev = (struct platform_device *) data;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304517 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4518
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004519 /* Note: We get FRAMEDONE when DISPC has finished sending pixels and
4520 * turns itself off. However, DSI still has the pixels in its buffers,
4521 * and is sending the data.
4522 */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004523
Tejun Heo136b5722012-08-21 13:18:24 -07004524 cancel_delayed_work(&dsi->framedone_timeout_work);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004525
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304526 dsi_handle_framedone(dsidev, 0);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004527}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004528
Tomi Valkeinen5476e742011-11-03 16:34:20 +02004529int omap_dsi_update(struct omap_dss_device *dssdev, int channel,
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004530 void (*callback)(int, void *), void *data)
4531{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304532 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304533 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen5476e742011-11-03 16:34:20 +02004534 u16 dw, dh;
4535
4536 dsi_perf_mark_setup(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304537
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304538 dsi->update_channel = channel;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004539
Tomi Valkeinen4a9e78a2011-08-15 11:22:21 +03004540 dsi->framedone_callback = callback;
4541 dsi->framedone_data = data;
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004542
Archit Tanejae3525742012-08-09 15:23:43 +05304543 dw = dsi->timings.x_res;
4544 dh = dsi->timings.y_res;
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004545
Tomi Valkeinen5476e742011-11-03 16:34:20 +02004546#ifdef DEBUG
4547 dsi->update_bytes = dw * dh *
Archit Taneja02c39602012-08-10 15:01:33 +05304548 dsi_get_pixel_size(dsi->pix_fmt) / 8;
Tomi Valkeinen5476e742011-11-03 16:34:20 +02004549#endif
Archit Taneja55cd63a2012-08-09 15:41:13 +05304550 dsi_update_screen_dispc(dssdev);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004551
4552 return 0;
4553}
4554EXPORT_SYMBOL(omap_dsi_update);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004555
4556/* Display funcs */
4557
Archit Taneja7d2572f2012-06-29 14:31:07 +05304558static int dsi_configure_dispc_clocks(struct omap_dss_device *dssdev)
4559{
4560 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4561 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4562 struct dispc_clock_info dispc_cinfo;
4563 int r;
4564 unsigned long long fck;
4565
4566 fck = dsi_get_pll_hsdiv_dispc_rate(dsidev);
4567
4568 dispc_cinfo.lck_div = dssdev->clocks.dispc.channel.lck_div;
4569 dispc_cinfo.pck_div = dssdev->clocks.dispc.channel.pck_div;
4570
4571 r = dispc_calc_clock_rates(fck, &dispc_cinfo);
4572 if (r) {
4573 DSSERR("Failed to calc dispc clocks\n");
4574 return r;
4575 }
4576
4577 dsi->mgr_config.clock_info = dispc_cinfo;
4578
4579 return 0;
4580}
4581
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004582static int dsi_display_init_dispc(struct omap_dss_device *dssdev)
4583{
Archit Taneja7d2572f2012-06-29 14:31:07 +05304584 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4585 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejaeea83402012-09-04 11:42:36 +05304586 struct omap_overlay_manager *mgr = dssdev->output->manager;
Archit Taneja7d2572f2012-06-29 14:31:07 +05304587 int r;
4588 u32 irq = 0;
Archit Taneja5a8b5722011-05-12 17:26:29 +05304589
Archit Tanejadca2b152012-08-16 18:02:00 +05304590 if (dsi->mode == OMAP_DSS_DSI_CMD_MODE) {
Archit Tanejae67458a2012-08-13 14:17:30 +05304591 dsi->timings.hsw = 1;
4592 dsi->timings.hfp = 1;
4593 dsi->timings.hbp = 1;
4594 dsi->timings.vsw = 1;
4595 dsi->timings.vfp = 0;
4596 dsi->timings.vbp = 0;
Tomi Valkeinen5476e742011-11-03 16:34:20 +02004597
Archit Tanejaeea83402012-09-04 11:42:36 +05304598 irq = dispc_mgr_get_framedone_irq(mgr->id);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304599
4600 r = omap_dispc_register_isr(dsi_framedone_irq_callback,
Archit Taneja9e7e9372012-08-14 12:29:22 +05304601 (void *) dsidev, irq);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304602 if (r) {
4603 DSSERR("can't get FRAMEDONE irq\n");
Archit Taneja7d2572f2012-06-29 14:31:07 +05304604 goto err;
Archit Taneja8af6ff02011-09-05 16:48:27 +05304605 }
4606
Archit Taneja7d2572f2012-06-29 14:31:07 +05304607 dsi->mgr_config.stallmode = true;
4608 dsi->mgr_config.fifohandcheck = true;
Archit Taneja8af6ff02011-09-05 16:48:27 +05304609 } else {
Archit Taneja7d2572f2012-06-29 14:31:07 +05304610 dsi->mgr_config.stallmode = false;
4611 dsi->mgr_config.fifohandcheck = false;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004612 }
4613
Archit Tanejabd5a7b12012-06-26 12:38:31 +05304614 /*
4615 * override interlace, logic level and edge related parameters in
4616 * omap_video_timings with default values
4617 */
Archit Tanejae67458a2012-08-13 14:17:30 +05304618 dsi->timings.interlace = false;
4619 dsi->timings.hsync_level = OMAPDSS_SIG_ACTIVE_HIGH;
4620 dsi->timings.vsync_level = OMAPDSS_SIG_ACTIVE_HIGH;
4621 dsi->timings.data_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE;
4622 dsi->timings.de_level = OMAPDSS_SIG_ACTIVE_HIGH;
4623 dsi->timings.sync_pclk_edge = OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES;
Archit Tanejabd5a7b12012-06-26 12:38:31 +05304624
Archit Tanejaeea83402012-09-04 11:42:36 +05304625 dss_mgr_set_timings(mgr, &dsi->timings);
Archit Tanejabd5a7b12012-06-26 12:38:31 +05304626
Archit Taneja7d2572f2012-06-29 14:31:07 +05304627 r = dsi_configure_dispc_clocks(dssdev);
4628 if (r)
4629 goto err1;
4630
4631 dsi->mgr_config.io_pad_mode = DSS_IO_PAD_MODE_BYPASS;
4632 dsi->mgr_config.video_port_width =
Archit Taneja02c39602012-08-10 15:01:33 +05304633 dsi_get_pixel_size(dsi->pix_fmt);
Archit Taneja7d2572f2012-06-29 14:31:07 +05304634 dsi->mgr_config.lcden_sig_polarity = 0;
4635
Archit Tanejaeea83402012-09-04 11:42:36 +05304636 dss_mgr_set_lcd_config(mgr, &dsi->mgr_config);
Archit Tanejad21f43b2012-06-21 09:45:11 +05304637
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004638 return 0;
Archit Taneja7d2572f2012-06-29 14:31:07 +05304639err1:
Archit Tanejadca2b152012-08-16 18:02:00 +05304640 if (dsi->mode == OMAP_DSS_DSI_CMD_MODE)
Archit Taneja7d2572f2012-06-29 14:31:07 +05304641 omap_dispc_unregister_isr(dsi_framedone_irq_callback,
Archit Taneja9e7e9372012-08-14 12:29:22 +05304642 (void *) dsidev, irq);
Archit Taneja7d2572f2012-06-29 14:31:07 +05304643err:
4644 return r;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004645}
4646
4647static void dsi_display_uninit_dispc(struct omap_dss_device *dssdev)
4648{
Archit Tanejadca2b152012-08-16 18:02:00 +05304649 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4650 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejaeea83402012-09-04 11:42:36 +05304651 struct omap_overlay_manager *mgr = dssdev->output->manager;
Archit Tanejadca2b152012-08-16 18:02:00 +05304652
4653 if (dsi->mode == OMAP_DSS_DSI_CMD_MODE) {
Archit Taneja8af6ff02011-09-05 16:48:27 +05304654 u32 irq;
Archit Taneja5a8b5722011-05-12 17:26:29 +05304655
Archit Tanejaeea83402012-09-04 11:42:36 +05304656 irq = dispc_mgr_get_framedone_irq(mgr->id);
Archit Taneja5a8b5722011-05-12 17:26:29 +05304657
Archit Taneja8af6ff02011-09-05 16:48:27 +05304658 omap_dispc_unregister_isr(dsi_framedone_irq_callback,
Archit Taneja9e7e9372012-08-14 12:29:22 +05304659 (void *) dsidev, irq);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304660 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004661}
4662
4663static int dsi_configure_dsi_clocks(struct omap_dss_device *dssdev)
4664{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304665 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004666 struct dsi_clock_info cinfo;
4667 int r;
4668
Tomi Valkeinenc6940a32011-02-22 13:36:10 +02004669 cinfo.regn = dssdev->clocks.dsi.regn;
4670 cinfo.regm = dssdev->clocks.dsi.regm;
4671 cinfo.regm_dispc = dssdev->clocks.dsi.regm_dispc;
4672 cinfo.regm_dsi = dssdev->clocks.dsi.regm_dsi;
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02004673 r = dsi_calc_clock_rates(dsidev, &cinfo);
Ville Syrjäläebf0a3f2010-04-22 22:50:05 +02004674 if (r) {
4675 DSSERR("Failed to calc dsi clocks\n");
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004676 return r;
Ville Syrjäläebf0a3f2010-04-22 22:50:05 +02004677 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004678
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304679 r = dsi_pll_set_clock_div(dsidev, &cinfo);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004680 if (r) {
4681 DSSERR("Failed to set dsi clocks\n");
4682 return r;
4683 }
4684
4685 return 0;
4686}
4687
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004688static int dsi_display_init_dsi(struct omap_dss_device *dssdev)
4689{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304690 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02004691 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejaeea83402012-09-04 11:42:36 +05304692 struct omap_overlay_manager *mgr = dssdev->output->manager;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004693 int r;
4694
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304695 r = dsi_pll_init(dsidev, true, true);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004696 if (r)
4697 goto err0;
4698
4699 r = dsi_configure_dsi_clocks(dssdev);
4700 if (r)
4701 goto err1;
4702
Archit Tanejae8881662011-04-12 13:52:24 +05304703 dss_select_dispc_clk_source(dssdev->clocks.dispc.dispc_fclk_src);
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02004704 dss_select_dsi_clk_source(dsi->module_id, dssdev->clocks.dsi.dsi_fclk_src);
Archit Tanejaeea83402012-09-04 11:42:36 +05304705 dss_select_lcd_clk_source(mgr->id,
Archit Tanejae8881662011-04-12 13:52:24 +05304706 dssdev->clocks.dispc.channel.lcd_clk_src);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004707
4708 DSSDBG("PLL OK\n");
4709
Archit Taneja9e7e9372012-08-14 12:29:22 +05304710 r = dsi_cio_init(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004711 if (r)
4712 goto err2;
4713
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304714 _dsi_print_reset_status(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004715
Archit Taneja9e7e9372012-08-14 12:29:22 +05304716 dsi_proto_timings(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004717 dsi_set_lp_clk_divisor(dssdev);
4718
4719 if (1)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304720 _dsi_print_reset_status(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004721
4722 r = dsi_proto_config(dssdev);
4723 if (r)
4724 goto err3;
4725
4726 /* enable interface */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304727 dsi_vc_enable(dsidev, 0, 1);
4728 dsi_vc_enable(dsidev, 1, 1);
4729 dsi_vc_enable(dsidev, 2, 1);
4730 dsi_vc_enable(dsidev, 3, 1);
4731 dsi_if_enable(dsidev, 1);
4732 dsi_force_tx_stop_mode_io(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004733
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004734 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004735err3:
Archit Taneja9e7e9372012-08-14 12:29:22 +05304736 dsi_cio_uninit(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004737err2:
Archit Taneja89a35e52011-04-12 13:52:23 +05304738 dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK);
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02004739 dss_select_dsi_clk_source(dsi->module_id, OMAP_DSS_CLK_SRC_FCK);
Archit Tanejaeea83402012-09-04 11:42:36 +05304740 dss_select_lcd_clk_source(mgr->id, OMAP_DSS_CLK_SRC_FCK);
Tomi Valkeinen5e785092011-08-10 11:25:36 +03004741
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004742err1:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304743 dsi_pll_uninit(dsidev, true);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004744err0:
4745 return r;
4746}
4747
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +03004748static void dsi_display_uninit_dsi(struct omap_dss_device *dssdev,
Tomi Valkeinen22d6d672010-10-11 11:33:30 +03004749 bool disconnect_lanes, bool enter_ulps)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004750{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304751 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304752 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejaeea83402012-09-04 11:42:36 +05304753 struct omap_overlay_manager *mgr = dssdev->output->manager;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304754
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304755 if (enter_ulps && !dsi->ulps_enabled)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304756 dsi_enter_ulps(dsidev);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03004757
Ville Syrjäläd7370102010-04-22 22:50:09 +02004758 /* disable interface */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304759 dsi_if_enable(dsidev, 0);
4760 dsi_vc_enable(dsidev, 0, 0);
4761 dsi_vc_enable(dsidev, 1, 0);
4762 dsi_vc_enable(dsidev, 2, 0);
4763 dsi_vc_enable(dsidev, 3, 0);
Ville Syrjäläd7370102010-04-22 22:50:09 +02004764
Archit Taneja89a35e52011-04-12 13:52:23 +05304765 dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK);
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02004766 dss_select_dsi_clk_source(dsi->module_id, OMAP_DSS_CLK_SRC_FCK);
Archit Tanejaeea83402012-09-04 11:42:36 +05304767 dss_select_lcd_clk_source(mgr->id, OMAP_DSS_CLK_SRC_FCK);
Archit Taneja9e7e9372012-08-14 12:29:22 +05304768 dsi_cio_uninit(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304769 dsi_pll_uninit(dsidev, disconnect_lanes);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004770}
4771
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02004772int omapdss_dsi_display_enable(struct omap_dss_device *dssdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004773{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304774 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304775 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejaeea83402012-09-04 11:42:36 +05304776 struct omap_dss_output *out = dssdev->output;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004777 int r = 0;
4778
4779 DSSDBG("dsi_display_enable\n");
4780
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304781 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02004782
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304783 mutex_lock(&dsi->lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004784
Archit Tanejaeea83402012-09-04 11:42:36 +05304785 if (out == NULL || out->manager == NULL) {
4786 DSSERR("failed to enable display: no output/manager\n");
Tomi Valkeinen05e1d602011-06-23 16:38:21 +03004787 r = -ENODEV;
4788 goto err_start_dev;
4789 }
4790
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004791 r = omap_dss_start_device(dssdev);
4792 if (r) {
4793 DSSERR("failed to start device\n");
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004794 goto err_start_dev;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004795 }
4796
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004797 r = dsi_runtime_get(dsidev);
4798 if (r)
4799 goto err_get_dsi;
4800
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304801 dsi_enable_pll_clock(dsidev, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004802
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004803 _dsi_initialize_irq(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004804
4805 r = dsi_display_init_dispc(dssdev);
4806 if (r)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004807 goto err_init_dispc;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004808
4809 r = dsi_display_init_dsi(dssdev);
4810 if (r)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004811 goto err_init_dsi;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004812
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304813 mutex_unlock(&dsi->lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004814
4815 return 0;
4816
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004817err_init_dsi:
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02004818 dsi_display_uninit_dispc(dssdev);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004819err_init_dispc:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304820 dsi_enable_pll_clock(dsidev, 0);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004821 dsi_runtime_put(dsidev);
4822err_get_dsi:
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004823 omap_dss_stop_device(dssdev);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004824err_start_dev:
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304825 mutex_unlock(&dsi->lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004826 DSSDBG("dsi_display_enable FAILED\n");
4827 return r;
4828}
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02004829EXPORT_SYMBOL(omapdss_dsi_display_enable);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004830
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +03004831void omapdss_dsi_display_disable(struct omap_dss_device *dssdev,
Tomi Valkeinen22d6d672010-10-11 11:33:30 +03004832 bool disconnect_lanes, bool enter_ulps)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004833{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304834 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304835 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304836
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004837 DSSDBG("dsi_display_disable\n");
4838
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304839 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02004840
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304841 mutex_lock(&dsi->lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004842
Tomi Valkeinen15ffa1d2011-06-16 14:34:06 +03004843 dsi_sync_vc(dsidev, 0);
4844 dsi_sync_vc(dsidev, 1);
4845 dsi_sync_vc(dsidev, 2);
4846 dsi_sync_vc(dsidev, 3);
4847
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004848 dsi_display_uninit_dispc(dssdev);
4849
Tomi Valkeinen22d6d672010-10-11 11:33:30 +03004850 dsi_display_uninit_dsi(dssdev, disconnect_lanes, enter_ulps);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004851
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004852 dsi_runtime_put(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304853 dsi_enable_pll_clock(dsidev, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004854
4855 omap_dss_stop_device(dssdev);
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02004856
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304857 mutex_unlock(&dsi->lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004858}
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02004859EXPORT_SYMBOL(omapdss_dsi_display_disable);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004860
Tomi Valkeinen225b6502010-01-11 15:11:01 +02004861int omapdss_dsi_enable_te(struct omap_dss_device *dssdev, bool enable)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004862{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304863 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4864 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4865
4866 dsi->te_enabled = enable;
Tomi Valkeinen225b6502010-01-11 15:11:01 +02004867 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004868}
Tomi Valkeinen225b6502010-01-11 15:11:01 +02004869EXPORT_SYMBOL(omapdss_dsi_enable_te);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004870
Archit Tanejae67458a2012-08-13 14:17:30 +05304871void omapdss_dsi_set_timings(struct omap_dss_device *dssdev,
4872 struct omap_video_timings *timings)
4873{
4874 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4875 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4876
4877 mutex_lock(&dsi->lock);
4878
4879 dsi->timings = *timings;
4880
4881 mutex_unlock(&dsi->lock);
4882}
4883EXPORT_SYMBOL(omapdss_dsi_set_timings);
4884
Archit Tanejae3525742012-08-09 15:23:43 +05304885void omapdss_dsi_set_size(struct omap_dss_device *dssdev, u16 w, u16 h)
4886{
4887 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4888 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4889
4890 mutex_lock(&dsi->lock);
4891
4892 dsi->timings.x_res = w;
4893 dsi->timings.y_res = h;
4894
4895 mutex_unlock(&dsi->lock);
4896}
4897EXPORT_SYMBOL(omapdss_dsi_set_size);
4898
Archit Taneja02c39602012-08-10 15:01:33 +05304899void omapdss_dsi_set_pixel_format(struct omap_dss_device *dssdev,
4900 enum omap_dss_dsi_pixel_format fmt)
4901{
4902 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4903 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4904
4905 mutex_lock(&dsi->lock);
4906
4907 dsi->pix_fmt = fmt;
4908
4909 mutex_unlock(&dsi->lock);
4910}
4911EXPORT_SYMBOL(omapdss_dsi_set_pixel_format);
4912
Archit Tanejadca2b152012-08-16 18:02:00 +05304913void omapdss_dsi_set_operation_mode(struct omap_dss_device *dssdev,
4914 enum omap_dss_dsi_mode mode)
4915{
4916 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4917 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4918
4919 mutex_lock(&dsi->lock);
4920
4921 dsi->mode = mode;
4922
4923 mutex_unlock(&dsi->lock);
4924}
4925EXPORT_SYMBOL(omapdss_dsi_set_operation_mode);
4926
Archit Taneja0b3ffe32012-08-13 22:13:39 +05304927void omapdss_dsi_set_videomode_timings(struct omap_dss_device *dssdev,
4928 struct omap_dss_dsi_videomode_timings *timings)
4929{
4930 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4931 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4932
4933 mutex_lock(&dsi->lock);
4934
4935 dsi->vm_timings = *timings;
4936
4937 mutex_unlock(&dsi->lock);
4938}
4939EXPORT_SYMBOL(omapdss_dsi_set_videomode_timings);
4940
Tomi Valkeinen9d8232a2012-03-01 16:58:39 +02004941static int __init dsi_init_display(struct omap_dss_device *dssdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004942{
Archit Tanejaeea83402012-09-04 11:42:36 +05304943 struct platform_device *dsidev =
4944 dsi_get_dsidev_from_id(dssdev->phy.dsi.module);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304945 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4946
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004947 DSSDBG("DSI init\n");
4948
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304949 if (dsi->vdds_dsi_reg == NULL) {
Tomi Valkeinen5f42f2c2011-02-22 15:53:46 +02004950 struct regulator *vdds_dsi;
4951
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304952 vdds_dsi = regulator_get(&dsi->pdev->dev, "vdds_dsi");
Tomi Valkeinen5f42f2c2011-02-22 15:53:46 +02004953
4954 if (IS_ERR(vdds_dsi)) {
4955 DSSERR("can't get VDDS_DSI regulator\n");
4956 return PTR_ERR(vdds_dsi);
4957 }
4958
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304959 dsi->vdds_dsi_reg = vdds_dsi;
Tomi Valkeinen5f42f2c2011-02-22 15:53:46 +02004960 }
4961
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004962 return 0;
4963}
4964
Archit Taneja5ee3c142011-03-02 12:35:53 +05304965int omap_dsi_request_vc(struct omap_dss_device *dssdev, int *channel)
4966{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304967 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4968 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Taneja5ee3c142011-03-02 12:35:53 +05304969 int i;
4970
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304971 for (i = 0; i < ARRAY_SIZE(dsi->vc); i++) {
4972 if (!dsi->vc[i].dssdev) {
4973 dsi->vc[i].dssdev = dssdev;
Archit Taneja5ee3c142011-03-02 12:35:53 +05304974 *channel = i;
4975 return 0;
4976 }
4977 }
4978
4979 DSSERR("cannot get VC for display %s", dssdev->name);
4980 return -ENOSPC;
4981}
4982EXPORT_SYMBOL(omap_dsi_request_vc);
4983
4984int omap_dsi_set_vc_id(struct omap_dss_device *dssdev, int channel, int vc_id)
4985{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304986 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4987 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4988
Archit Taneja5ee3c142011-03-02 12:35:53 +05304989 if (vc_id < 0 || vc_id > 3) {
4990 DSSERR("VC ID out of range\n");
4991 return -EINVAL;
4992 }
4993
4994 if (channel < 0 || channel > 3) {
4995 DSSERR("Virtual Channel out of range\n");
4996 return -EINVAL;
4997 }
4998
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304999 if (dsi->vc[channel].dssdev != dssdev) {
Archit Taneja5ee3c142011-03-02 12:35:53 +05305000 DSSERR("Virtual Channel not allocated to display %s\n",
5001 dssdev->name);
5002 return -EINVAL;
5003 }
5004
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305005 dsi->vc[channel].vc_id = vc_id;
Archit Taneja5ee3c142011-03-02 12:35:53 +05305006
5007 return 0;
5008}
5009EXPORT_SYMBOL(omap_dsi_set_vc_id);
5010
5011void omap_dsi_release_vc(struct omap_dss_device *dssdev, int channel)
5012{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305013 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
5014 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
5015
Archit Taneja5ee3c142011-03-02 12:35:53 +05305016 if ((channel >= 0 && channel <= 3) &&
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305017 dsi->vc[channel].dssdev == dssdev) {
5018 dsi->vc[channel].dssdev = NULL;
5019 dsi->vc[channel].vc_id = 0;
Archit Taneja5ee3c142011-03-02 12:35:53 +05305020 }
5021}
5022EXPORT_SYMBOL(omap_dsi_release_vc);
5023
Archit Tanejaa72b64b2011-05-12 17:26:26 +05305024void dsi_wait_pll_hsdiv_dispc_active(struct platform_device *dsidev)
Tomi Valkeinene406f902010-06-09 15:28:12 +03005025{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05305026 if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 7, 1) != 1)
Archit Taneja067a57e2011-03-02 11:57:25 +05305027 DSSERR("%s (%s) not active\n",
Archit Taneja89a35e52011-04-12 13:52:23 +05305028 dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
5029 dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC));
Tomi Valkeinene406f902010-06-09 15:28:12 +03005030}
5031
Archit Tanejaa72b64b2011-05-12 17:26:26 +05305032void dsi_wait_pll_hsdiv_dsi_active(struct platform_device *dsidev)
Tomi Valkeinene406f902010-06-09 15:28:12 +03005033{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05305034 if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 8, 1) != 1)
Archit Taneja067a57e2011-03-02 11:57:25 +05305035 DSSERR("%s (%s) not active\n",
Archit Taneja89a35e52011-04-12 13:52:23 +05305036 dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
5037 dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI));
Tomi Valkeinene406f902010-06-09 15:28:12 +03005038}
5039
Archit Tanejaa72b64b2011-05-12 17:26:26 +05305040static void dsi_calc_clock_param_ranges(struct platform_device *dsidev)
Taneja, Archit49641112011-03-14 23:28:23 -05005041{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305042 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
5043
5044 dsi->regn_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGN);
5045 dsi->regm_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM);
5046 dsi->regm_dispc_max =
5047 dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DISPC);
5048 dsi->regm_dsi_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DSI);
5049 dsi->fint_min = dss_feat_get_param_min(FEAT_PARAM_DSIPLL_FINT);
5050 dsi->fint_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_FINT);
5051 dsi->lpdiv_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_LPDIV);
Taneja, Archit49641112011-03-14 23:28:23 -05005052}
5053
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005054static int dsi_get_clocks(struct platform_device *dsidev)
5055{
5056 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
5057 struct clk *clk;
5058
5059 clk = clk_get(&dsidev->dev, "fck");
5060 if (IS_ERR(clk)) {
5061 DSSERR("can't get fck\n");
5062 return PTR_ERR(clk);
5063 }
5064
5065 dsi->dss_clk = clk;
5066
Tomi Valkeinenbfe4f8d2011-08-04 11:22:54 +03005067 clk = clk_get(&dsidev->dev, "sys_clk");
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005068 if (IS_ERR(clk)) {
5069 DSSERR("can't get sys_clk\n");
5070 clk_put(dsi->dss_clk);
5071 dsi->dss_clk = NULL;
5072 return PTR_ERR(clk);
5073 }
5074
5075 dsi->sys_clk = clk;
5076
5077 return 0;
5078}
5079
5080static void dsi_put_clocks(struct platform_device *dsidev)
5081{
5082 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
5083
5084 if (dsi->dss_clk)
5085 clk_put(dsi->dss_clk);
5086 if (dsi->sys_clk)
5087 clk_put(dsi->sys_clk);
5088}
5089
Tomi Valkeinen15216532012-09-06 14:29:31 +03005090static struct omap_dss_device * __init dsi_find_dssdev(struct platform_device *pdev)
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +03005091{
Tomi Valkeinen15216532012-09-06 14:29:31 +03005092 struct omap_dss_board_info *pdata = pdev->dev.platform_data;
5093 struct dsi_data *dsi = dsi_get_dsidrv_data(pdev);
5094 const char *def_disp_name = dss_get_default_display_name();
5095 struct omap_dss_device *def_dssdev;
5096 int i;
5097
5098 def_dssdev = NULL;
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +03005099
5100 for (i = 0; i < pdata->num_devices; ++i) {
5101 struct omap_dss_device *dssdev = pdata->devices[i];
5102
5103 if (dssdev->type != OMAP_DISPLAY_TYPE_DSI)
5104 continue;
5105
5106 if (dssdev->phy.dsi.module != dsi->module_id)
5107 continue;
5108
Tomi Valkeinen15216532012-09-06 14:29:31 +03005109 if (def_dssdev == NULL)
5110 def_dssdev = dssdev;
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +03005111
Tomi Valkeinen15216532012-09-06 14:29:31 +03005112 if (def_disp_name != NULL &&
5113 strcmp(dssdev->name, def_disp_name) == 0) {
5114 def_dssdev = dssdev;
5115 break;
5116 }
5117 }
5118
5119 return def_dssdev;
5120}
5121
5122static void __init dsi_probe_pdata(struct platform_device *dsidev)
5123{
Tomi Valkeinen52744842012-09-10 13:58:29 +03005124 struct omap_dss_device *plat_dssdev;
Tomi Valkeinen15216532012-09-06 14:29:31 +03005125 struct omap_dss_device *dssdev;
5126 int r;
5127
Tomi Valkeinen52744842012-09-10 13:58:29 +03005128 plat_dssdev = dsi_find_dssdev(dsidev);
Tomi Valkeinen15216532012-09-06 14:29:31 +03005129
Tomi Valkeinen52744842012-09-10 13:58:29 +03005130 if (!plat_dssdev)
5131 return;
5132
5133 dssdev = dss_alloc_and_init_device(&dsidev->dev);
Tomi Valkeinen15216532012-09-06 14:29:31 +03005134 if (!dssdev)
5135 return;
5136
Tomi Valkeinen52744842012-09-10 13:58:29 +03005137 dss_copy_device_pdata(dssdev, plat_dssdev);
5138
Tomi Valkeinen15216532012-09-06 14:29:31 +03005139 r = dsi_init_display(dssdev);
5140 if (r) {
5141 DSSERR("device %s init failed: %d\n", dssdev->name, r);
Tomi Valkeinen52744842012-09-10 13:58:29 +03005142 dss_put_device(dssdev);
Tomi Valkeinen15216532012-09-06 14:29:31 +03005143 return;
5144 }
5145
Tomi Valkeinen52744842012-09-10 13:58:29 +03005146 r = dss_add_device(dssdev);
Tomi Valkeinen15216532012-09-06 14:29:31 +03005147 if (r) {
5148 DSSERR("device %s register failed: %d\n", dssdev->name, r);
Tomi Valkeinen52744842012-09-10 13:58:29 +03005149 dss_put_device(dssdev);
Tomi Valkeinen15216532012-09-06 14:29:31 +03005150 return;
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +03005151 }
5152}
5153
Archit Taneja81b87f52012-09-26 16:30:49 +05305154static void __init dsi_init_output(struct platform_device *dsidev)
5155{
5156 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
5157 struct omap_dss_output *out = &dsi->output;
5158
5159 out->pdev = dsidev;
5160 out->id = dsi->module_id == 0 ?
5161 OMAP_DSS_OUTPUT_DSI1 : OMAP_DSS_OUTPUT_DSI2;
5162
5163 out->type = OMAP_DISPLAY_TYPE_DSI;
5164
5165 dss_register_output(out);
5166}
5167
5168static void __exit dsi_uninit_output(struct platform_device *dsidev)
5169{
5170 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
5171 struct omap_dss_output *out = &dsi->output;
5172
5173 dss_unregister_output(out);
5174}
5175
Tomi Valkeinenb98482e2011-05-16 13:52:51 +03005176/* DSI1 HW IP initialisation */
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02005177static int __init omap_dsihw_probe(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005178{
5179 u32 rev;
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02005180 int r, i;
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00005181 struct resource *dsi_mem;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305182 struct dsi_data *dsi;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005183
Julia Lawall6e2a14d2012-01-24 14:00:45 +01005184 dsi = devm_kzalloc(&dsidev->dev, sizeof(*dsi), GFP_KERNEL);
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005185 if (!dsi)
5186 return -ENOMEM;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305187
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02005188 dsi->module_id = dsidev->id;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305189 dsi->pdev = dsidev;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305190 dev_set_drvdata(&dsidev->dev, dsi);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05305191
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305192 spin_lock_init(&dsi->irq_lock);
5193 spin_lock_init(&dsi->errors_lock);
5194 dsi->errors = 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005195
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02005196#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305197 spin_lock_init(&dsi->irq_stats_lock);
5198 dsi->irq_stats.last_reset = jiffies;
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02005199#endif
5200
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305201 mutex_init(&dsi->lock);
5202 sema_init(&dsi->bus_lock, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005203
Tejun Heo203b42f2012-08-21 13:18:23 -07005204 INIT_DEFERRABLE_WORK(&dsi->framedone_timeout_work,
5205 dsi_framedone_timeout_work_callback);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305206
5207#ifdef DSI_CATCH_MISSING_TE
5208 init_timer(&dsi->te_timer);
5209 dsi->te_timer.function = dsi_te_timeout;
5210 dsi->te_timer.data = 0;
5211#endif
5212 dsi_mem = platform_get_resource(dsi->pdev, IORESOURCE_MEM, 0);
5213 if (!dsi_mem) {
5214 DSSERR("can't get IORESOURCE_MEM DSI\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005215 return -EINVAL;
archit tanejaaffe3602011-02-23 08:41:03 +00005216 }
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005217
Julia Lawall6e2a14d2012-01-24 14:00:45 +01005218 dsi->base = devm_ioremap(&dsidev->dev, dsi_mem->start,
5219 resource_size(dsi_mem));
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305220 if (!dsi->base) {
5221 DSSERR("can't ioremap DSI\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005222 return -ENOMEM;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305223 }
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005224
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305225 dsi->irq = platform_get_irq(dsi->pdev, 0);
5226 if (dsi->irq < 0) {
5227 DSSERR("platform_get_irq failed\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005228 return -ENODEV;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305229 }
archit tanejaaffe3602011-02-23 08:41:03 +00005230
Julia Lawall6e2a14d2012-01-24 14:00:45 +01005231 r = devm_request_irq(&dsidev->dev, dsi->irq, omap_dsi_irq_handler,
5232 IRQF_SHARED, dev_name(&dsidev->dev), dsi->pdev);
archit tanejaaffe3602011-02-23 08:41:03 +00005233 if (r < 0) {
5234 DSSERR("request_irq failed\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005235 return r;
archit tanejaaffe3602011-02-23 08:41:03 +00005236 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005237
Archit Taneja5ee3c142011-03-02 12:35:53 +05305238 /* DSI VCs initialization */
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305239 for (i = 0; i < ARRAY_SIZE(dsi->vc); i++) {
Archit Tanejad6049142011-08-22 11:58:08 +05305240 dsi->vc[i].source = DSI_VC_SOURCE_L4;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305241 dsi->vc[i].dssdev = NULL;
5242 dsi->vc[i].vc_id = 0;
Archit Taneja5ee3c142011-03-02 12:35:53 +05305243 }
5244
Archit Tanejaa72b64b2011-05-12 17:26:26 +05305245 dsi_calc_clock_param_ranges(dsidev);
Taneja, Archit49641112011-03-14 23:28:23 -05005246
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005247 r = dsi_get_clocks(dsidev);
5248 if (r)
5249 return r;
5250
5251 pm_runtime_enable(&dsidev->dev);
5252
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005253 r = dsi_runtime_get(dsidev);
5254 if (r)
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005255 goto err_runtime_get;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005256
Archit Tanejaa72b64b2011-05-12 17:26:26 +05305257 rev = dsi_read_reg(dsidev, DSI_REVISION);
5258 dev_dbg(&dsidev->dev, "OMAP DSI rev %d.%d\n",
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005259 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
5260
Tomi Valkeinend9820852011-10-12 15:05:59 +03005261 /* DSI on OMAP3 doesn't have register DSI_GNQ, set number
5262 * of data to 3 by default */
5263 if (dss_has_feature(FEAT_DSI_GNQ))
5264 /* NB_DATA_LANES */
5265 dsi->num_lanes_supported = 1 + REG_GET(dsidev, DSI_GNQ, 11, 9);
5266 else
5267 dsi->num_lanes_supported = 3;
Archit Taneja75d72472011-05-16 15:17:08 +05305268
Archit Taneja81b87f52012-09-26 16:30:49 +05305269 dsi_init_output(dsidev);
5270
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +03005271 dsi_probe_pdata(dsidev);
Tomi Valkeinen35deca32012-03-01 15:45:53 +02005272
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005273 dsi_runtime_put(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005274
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02005275 if (dsi->module_id == 0)
Tomi Valkeinene40402c2012-03-02 18:01:07 +02005276 dss_debugfs_create_file("dsi1_regs", dsi1_dump_regs);
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02005277 else if (dsi->module_id == 1)
Tomi Valkeinene40402c2012-03-02 18:01:07 +02005278 dss_debugfs_create_file("dsi2_regs", dsi2_dump_regs);
5279
5280#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02005281 if (dsi->module_id == 0)
Tomi Valkeinene40402c2012-03-02 18:01:07 +02005282 dss_debugfs_create_file("dsi1_irqs", dsi1_dump_irqs);
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02005283 else if (dsi->module_id == 1)
Tomi Valkeinene40402c2012-03-02 18:01:07 +02005284 dss_debugfs_create_file("dsi2_irqs", dsi2_dump_irqs);
5285#endif
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005286 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005287
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005288err_runtime_get:
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005289 pm_runtime_disable(&dsidev->dev);
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005290 dsi_put_clocks(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005291 return r;
5292}
5293
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02005294static int __exit omap_dsihw_remove(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005295{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305296 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
5297
Tomi Valkeinenb98482e2011-05-16 13:52:51 +03005298 WARN_ON(dsi->scp_clk_refcount > 0);
5299
Tomi Valkeinen52744842012-09-10 13:58:29 +03005300 dss_unregister_child_devices(&dsidev->dev);
Tomi Valkeinen35deca32012-03-01 15:45:53 +02005301
Archit Taneja81b87f52012-09-26 16:30:49 +05305302 dsi_uninit_output(dsidev);
5303
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005304 pm_runtime_disable(&dsidev->dev);
5305
5306 dsi_put_clocks(dsidev);
5307
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305308 if (dsi->vdds_dsi_reg != NULL) {
5309 if (dsi->vdds_dsi_enabled) {
5310 regulator_disable(dsi->vdds_dsi_reg);
5311 dsi->vdds_dsi_enabled = false;
Tomi Valkeinen88257b22010-12-20 16:26:22 +02005312 }
5313
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305314 regulator_put(dsi->vdds_dsi_reg);
5315 dsi->vdds_dsi_reg = NULL;
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005316 }
5317
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005318 return 0;
5319}
5320
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005321static int dsi_runtime_suspend(struct device *dev)
5322{
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005323 dispc_runtime_put();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005324
5325 return 0;
5326}
5327
5328static int dsi_runtime_resume(struct device *dev)
5329{
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005330 int r;
5331
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005332 r = dispc_runtime_get();
5333 if (r)
Tomi Valkeinen852f0832012-02-17 17:58:04 +02005334 return r;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005335
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005336 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005337}
5338
5339static const struct dev_pm_ops dsi_pm_ops = {
5340 .runtime_suspend = dsi_runtime_suspend,
5341 .runtime_resume = dsi_runtime_resume,
5342};
5343
Tomi Valkeinen7c68dd92011-08-03 14:00:57 +03005344static struct platform_driver omap_dsihw_driver = {
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02005345 .remove = __exit_p(omap_dsihw_remove),
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005346 .driver = {
Tomi Valkeinen7c68dd92011-08-03 14:00:57 +03005347 .name = "omapdss_dsi",
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005348 .owner = THIS_MODULE,
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005349 .pm = &dsi_pm_ops,
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005350 },
5351};
5352
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02005353int __init dsi_init_platform_driver(void)
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005354{
Tomi Valkeinen61055d42012-03-07 12:53:38 +02005355 return platform_driver_probe(&omap_dsihw_driver, omap_dsihw_probe);
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005356}
5357
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02005358void __exit dsi_uninit_platform_driver(void)
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005359{
Tomi Valkeinen04c742c2012-02-23 15:32:37 +02005360 platform_driver_unregister(&omap_dsihw_driver);
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005361}