blob: 28d41d16b7be45aa10d646ba8983cd57e418e363 [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
Tomi Valkeinen78e7f252012-10-15 12:48:11 +0300367 switch (module) {
368 case 0:
369 id = OMAP_DSS_OUTPUT_DSI1;
370 break;
371 case 1:
372 id = OMAP_DSS_OUTPUT_DSI2;
373 break;
374 default:
375 return NULL;
376 }
Archit Taneja400e65d2012-07-04 13:48:34 +0530377
378 out = omap_dss_get_output(id);
379
Tomi Valkeinen78e7f252012-10-15 12:48:11 +0300380 return out ? out->pdev : NULL;
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530381}
382
383static inline void dsi_write_reg(struct platform_device *dsidev,
384 const struct dsi_reg idx, u32 val)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200385{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530386 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
387
388 __raw_writel(val, dsi->base + idx.idx);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200389}
390
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530391static inline u32 dsi_read_reg(struct platform_device *dsidev,
392 const struct dsi_reg idx)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200393{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530394 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
395
396 return __raw_readl(dsi->base + idx.idx);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200397}
398
Archit Taneja1ffefe72011-05-12 17:26:24 +0530399void dsi_bus_lock(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 down(&dsi->bus_lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200405}
406EXPORT_SYMBOL(dsi_bus_lock);
407
Archit Taneja1ffefe72011-05-12 17:26:24 +0530408void dsi_bus_unlock(struct omap_dss_device *dssdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200409{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530410 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
411 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
412
413 up(&dsi->bus_lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200414}
415EXPORT_SYMBOL(dsi_bus_unlock);
416
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530417static bool dsi_bus_is_locked(struct platform_device *dsidev)
Tomi Valkeinen4f765022010-01-18 16:27:52 +0200418{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530419 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
420
421 return dsi->bus_lock.count == 0;
Tomi Valkeinen4f765022010-01-18 16:27:52 +0200422}
423
Tomi Valkeinenf36a06e2011-03-02 14:48:41 +0200424static void dsi_completion_handler(void *data, u32 mask)
425{
426 complete((struct completion *)data);
427}
428
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530429static inline int wait_for_bit_change(struct platform_device *dsidev,
430 const struct dsi_reg idx, int bitnum, int value)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200431{
Tomi Valkeinen3b984092011-10-13 19:06:49 +0300432 unsigned long timeout;
433 ktime_t wait;
434 int t;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200435
Tomi Valkeinen3b984092011-10-13 19:06:49 +0300436 /* first busyloop to see if the bit changes right away */
437 t = 100;
438 while (t-- > 0) {
439 if (REG_GET(dsidev, idx, bitnum, bitnum) == value)
440 return value;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200441 }
442
Tomi Valkeinen3b984092011-10-13 19:06:49 +0300443 /* then loop for 500ms, sleeping for 1ms in between */
444 timeout = jiffies + msecs_to_jiffies(500);
445 while (time_before(jiffies, timeout)) {
446 if (REG_GET(dsidev, idx, bitnum, bitnum) == value)
447 return value;
448
449 wait = ns_to_ktime(1000 * 1000);
450 set_current_state(TASK_UNINTERRUPTIBLE);
451 schedule_hrtimeout(&wait, HRTIMER_MODE_REL);
452 }
453
454 return !value;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200455}
456
Archit Tanejaa3b3cc22011-09-08 18:42:16 +0530457u8 dsi_get_pixel_size(enum omap_dss_dsi_pixel_format fmt)
458{
459 switch (fmt) {
460 case OMAP_DSS_DSI_FMT_RGB888:
461 case OMAP_DSS_DSI_FMT_RGB666:
462 return 24;
463 case OMAP_DSS_DSI_FMT_RGB666_PACKED:
464 return 18;
465 case OMAP_DSS_DSI_FMT_RGB565:
466 return 16;
467 default:
468 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300469 return 0;
Archit Tanejaa3b3cc22011-09-08 18:42:16 +0530470 }
471}
472
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200473#ifdef DEBUG
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530474static void dsi_perf_mark_setup(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200475{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530476 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
477 dsi->perf_setup_time = ktime_get();
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200478}
479
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530480static void dsi_perf_mark_start(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200481{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530482 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
483 dsi->perf_start_time = ktime_get();
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200484}
485
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530486static void dsi_perf_show(struct platform_device *dsidev, const char *name)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200487{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530488 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200489 ktime_t t, setup_time, trans_time;
490 u32 total_bytes;
491 u32 setup_us, trans_us, total_us;
492
493 if (!dsi_perf)
494 return;
495
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200496 t = ktime_get();
497
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530498 setup_time = ktime_sub(dsi->perf_start_time, dsi->perf_setup_time);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200499 setup_us = (u32)ktime_to_us(setup_time);
500 if (setup_us == 0)
501 setup_us = 1;
502
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530503 trans_time = ktime_sub(t, dsi->perf_start_time);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200504 trans_us = (u32)ktime_to_us(trans_time);
505 if (trans_us == 0)
506 trans_us = 1;
507
508 total_us = setup_us + trans_us;
509
Tomi Valkeinen5476e742011-11-03 16:34:20 +0200510 total_bytes = dsi->update_bytes;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200511
Tomi Valkeinen1bbb2752010-01-11 16:41:10 +0200512 printk(KERN_INFO "DSI(%s): %u us + %u us = %u us (%uHz), "
513 "%u bytes, %u kbytes/sec\n",
514 name,
515 setup_us,
516 trans_us,
517 total_us,
518 1000*1000 / total_us,
519 total_bytes,
520 total_bytes * 1000 / total_us);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200521}
522#else
Tomi Valkeinen4a9a5e32011-05-23 16:36:09 +0300523static inline void dsi_perf_mark_setup(struct platform_device *dsidev)
524{
525}
526
527static inline void dsi_perf_mark_start(struct platform_device *dsidev)
528{
529}
530
531static inline void dsi_perf_show(struct platform_device *dsidev,
532 const char *name)
533{
534}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200535#endif
536
Chandrabhanu Mahapatraf30be7d2012-09-29 12:33:05 +0530537static int verbose_irq;
538
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200539static void print_irq_status(u32 status)
540{
Tomi Valkeinend80d4992011-03-02 15:53:07 +0200541 if (status == 0)
542 return;
543
Chandrabhanu Mahapatraf30be7d2012-09-29 12:33:05 +0530544 if (!verbose_irq && (status & ~DSI_IRQ_CHANNEL_MASK) == 0)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200545 return;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200546
Chandrabhanu Mahapatraf30be7d2012-09-29 12:33:05 +0530547#define PIS(x) (status & DSI_IRQ_##x) ? (#x " ") : ""
548
549 pr_debug("DSI IRQ: 0x%x: %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
550 status,
551 verbose_irq ? PIS(VC0) : "",
552 verbose_irq ? PIS(VC1) : "",
553 verbose_irq ? PIS(VC2) : "",
554 verbose_irq ? PIS(VC3) : "",
555 PIS(WAKEUP),
556 PIS(RESYNC),
557 PIS(PLL_LOCK),
558 PIS(PLL_UNLOCK),
559 PIS(PLL_RECALL),
560 PIS(COMPLEXIO_ERR),
561 PIS(HS_TX_TIMEOUT),
562 PIS(LP_RX_TIMEOUT),
563 PIS(TE_TRIGGER),
564 PIS(ACK_TRIGGER),
565 PIS(SYNC_LOST),
566 PIS(LDO_POWER_GOOD),
567 PIS(TA_TIMEOUT));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200568#undef PIS
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200569}
570
571static void print_irq_status_vc(int channel, u32 status)
572{
Tomi Valkeinend80d4992011-03-02 15:53:07 +0200573 if (status == 0)
574 return;
575
Chandrabhanu Mahapatraf30be7d2012-09-29 12:33:05 +0530576 if (!verbose_irq && (status & ~DSI_VC_IRQ_PACKET_SENT) == 0)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200577 return;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200578
Chandrabhanu Mahapatraf30be7d2012-09-29 12:33:05 +0530579#define PIS(x) (status & DSI_VC_IRQ_##x) ? (#x " ") : ""
580
581 pr_debug("DSI VC(%d) IRQ 0x%x: %s%s%s%s%s%s%s%s%s\n",
582 channel,
583 status,
584 PIS(CS),
585 PIS(ECC_CORR),
586 PIS(ECC_NO_CORR),
587 verbose_irq ? PIS(PACKET_SENT) : "",
588 PIS(BTA),
589 PIS(FIFO_TX_OVF),
590 PIS(FIFO_RX_OVF),
591 PIS(FIFO_TX_UDF),
592 PIS(PP_BUSY_CHANGE));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200593#undef PIS
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200594}
595
596static void print_irq_status_cio(u32 status)
597{
Tomi Valkeinend80d4992011-03-02 15:53:07 +0200598 if (status == 0)
599 return;
600
Chandrabhanu Mahapatraf30be7d2012-09-29 12:33:05 +0530601#define PIS(x) (status & DSI_CIO_IRQ_##x) ? (#x " ") : ""
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200602
Chandrabhanu Mahapatraf30be7d2012-09-29 12:33:05 +0530603 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",
604 status,
605 PIS(ERRSYNCESC1),
606 PIS(ERRSYNCESC2),
607 PIS(ERRSYNCESC3),
608 PIS(ERRESC1),
609 PIS(ERRESC2),
610 PIS(ERRESC3),
611 PIS(ERRCONTROL1),
612 PIS(ERRCONTROL2),
613 PIS(ERRCONTROL3),
614 PIS(STATEULPS1),
615 PIS(STATEULPS2),
616 PIS(STATEULPS3),
617 PIS(ERRCONTENTIONLP0_1),
618 PIS(ERRCONTENTIONLP1_1),
619 PIS(ERRCONTENTIONLP0_2),
620 PIS(ERRCONTENTIONLP1_2),
621 PIS(ERRCONTENTIONLP0_3),
622 PIS(ERRCONTENTIONLP1_3),
623 PIS(ULPSACTIVENOT_ALL0),
624 PIS(ULPSACTIVENOT_ALL1));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200625#undef PIS
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200626}
627
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200628#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530629static void dsi_collect_irq_stats(struct platform_device *dsidev, u32 irqstatus,
630 u32 *vcstatus, u32 ciostatus)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200631{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530632 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200633 int i;
634
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530635 spin_lock(&dsi->irq_stats_lock);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200636
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530637 dsi->irq_stats.irq_count++;
638 dss_collect_irq_stats(irqstatus, dsi->irq_stats.dsi_irqs);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200639
640 for (i = 0; i < 4; ++i)
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530641 dss_collect_irq_stats(vcstatus[i], dsi->irq_stats.vc_irqs[i]);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200642
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530643 dss_collect_irq_stats(ciostatus, dsi->irq_stats.cio_irqs);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200644
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530645 spin_unlock(&dsi->irq_stats_lock);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200646}
647#else
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530648#define dsi_collect_irq_stats(dsidev, irqstatus, vcstatus, ciostatus)
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200649#endif
650
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200651static int debug_irq;
652
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530653static void dsi_handle_irq_errors(struct platform_device *dsidev, u32 irqstatus,
654 u32 *vcstatus, u32 ciostatus)
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200655{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530656 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200657 int i;
658
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200659 if (irqstatus & DSI_IRQ_ERROR_MASK) {
660 DSSERR("DSI error, irqstatus %x\n", irqstatus);
661 print_irq_status(irqstatus);
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530662 spin_lock(&dsi->errors_lock);
663 dsi->errors |= irqstatus & DSI_IRQ_ERROR_MASK;
664 spin_unlock(&dsi->errors_lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200665 } else if (debug_irq) {
666 print_irq_status(irqstatus);
667 }
668
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200669 for (i = 0; i < 4; ++i) {
670 if (vcstatus[i] & DSI_VC_IRQ_ERROR_MASK) {
671 DSSERR("DSI VC(%d) error, vc irqstatus %x\n",
672 i, vcstatus[i]);
673 print_irq_status_vc(i, vcstatus[i]);
674 } else if (debug_irq) {
675 print_irq_status_vc(i, vcstatus[i]);
676 }
677 }
678
679 if (ciostatus & DSI_CIO_IRQ_ERROR_MASK) {
680 DSSERR("DSI CIO error, cio irqstatus %x\n", ciostatus);
681 print_irq_status_cio(ciostatus);
682 } else if (debug_irq) {
683 print_irq_status_cio(ciostatus);
684 }
685}
686
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200687static void dsi_call_isrs(struct dsi_isr_data *isr_array,
688 unsigned isr_array_size, u32 irqstatus)
689{
690 struct dsi_isr_data *isr_data;
691 int i;
692
693 for (i = 0; i < isr_array_size; i++) {
694 isr_data = &isr_array[i];
695 if (isr_data->isr && isr_data->mask & irqstatus)
696 isr_data->isr(isr_data->arg, irqstatus);
697 }
698}
699
700static void dsi_handle_isrs(struct dsi_isr_tables *isr_tables,
701 u32 irqstatus, u32 *vcstatus, u32 ciostatus)
702{
703 int i;
704
705 dsi_call_isrs(isr_tables->isr_table,
706 ARRAY_SIZE(isr_tables->isr_table),
707 irqstatus);
708
709 for (i = 0; i < 4; ++i) {
710 if (vcstatus[i] == 0)
711 continue;
712 dsi_call_isrs(isr_tables->isr_table_vc[i],
713 ARRAY_SIZE(isr_tables->isr_table_vc[i]),
714 vcstatus[i]);
715 }
716
717 if (ciostatus != 0)
718 dsi_call_isrs(isr_tables->isr_table_cio,
719 ARRAY_SIZE(isr_tables->isr_table_cio),
720 ciostatus);
721}
722
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200723static irqreturn_t omap_dsi_irq_handler(int irq, void *arg)
724{
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530725 struct platform_device *dsidev;
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530726 struct dsi_data *dsi;
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200727 u32 irqstatus, vcstatus[4], ciostatus;
728 int i;
729
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530730 dsidev = (struct platform_device *) arg;
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530731 dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530732
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530733 spin_lock(&dsi->irq_lock);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200734
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530735 irqstatus = dsi_read_reg(dsidev, DSI_IRQSTATUS);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200736
737 /* IRQ is not for us */
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200738 if (!irqstatus) {
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530739 spin_unlock(&dsi->irq_lock);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200740 return IRQ_NONE;
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200741 }
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200742
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530743 dsi_write_reg(dsidev, DSI_IRQSTATUS, irqstatus & ~DSI_IRQ_CHANNEL_MASK);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200744 /* flush posted write */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530745 dsi_read_reg(dsidev, DSI_IRQSTATUS);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200746
747 for (i = 0; i < 4; ++i) {
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200748 if ((irqstatus & (1 << i)) == 0) {
749 vcstatus[i] = 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200750 continue;
Tomi Valkeinenab83b142010-06-09 15:31:01 +0300751 }
752
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530753 vcstatus[i] = dsi_read_reg(dsidev, DSI_VC_IRQSTATUS(i));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200754
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530755 dsi_write_reg(dsidev, DSI_VC_IRQSTATUS(i), vcstatus[i]);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200756 /* flush posted write */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530757 dsi_read_reg(dsidev, DSI_VC_IRQSTATUS(i));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200758 }
759
760 if (irqstatus & DSI_IRQ_COMPLEXIO_ERR) {
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530761 ciostatus = dsi_read_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200762
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530763 dsi_write_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS, ciostatus);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200764 /* flush posted write */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530765 dsi_read_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200766 } else {
767 ciostatus = 0;
768 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200769
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200770#ifdef DSI_CATCH_MISSING_TE
771 if (irqstatus & DSI_IRQ_TE_TRIGGER)
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530772 del_timer(&dsi->te_timer);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200773#endif
774
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200775 /* make a copy and unlock, so that isrs can unregister
776 * themselves */
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530777 memcpy(&dsi->isr_tables_copy, &dsi->isr_tables,
778 sizeof(dsi->isr_tables));
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200779
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530780 spin_unlock(&dsi->irq_lock);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200781
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530782 dsi_handle_isrs(&dsi->isr_tables_copy, irqstatus, vcstatus, ciostatus);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200783
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530784 dsi_handle_irq_errors(dsidev, irqstatus, vcstatus, ciostatus);
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200785
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530786 dsi_collect_irq_stats(dsidev, irqstatus, vcstatus, ciostatus);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200787
archit tanejaaffe3602011-02-23 08:41:03 +0000788 return IRQ_HANDLED;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200789}
790
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530791/* dsi->irq_lock has to be locked by the caller */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530792static void _omap_dsi_configure_irqs(struct platform_device *dsidev,
793 struct dsi_isr_data *isr_array,
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200794 unsigned isr_array_size, u32 default_mask,
795 const struct dsi_reg enable_reg,
796 const struct dsi_reg status_reg)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200797{
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200798 struct dsi_isr_data *isr_data;
799 u32 mask;
800 u32 old_mask;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200801 int i;
802
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200803 mask = default_mask;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200804
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200805 for (i = 0; i < isr_array_size; i++) {
806 isr_data = &isr_array[i];
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200807
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200808 if (isr_data->isr == NULL)
809 continue;
810
811 mask |= isr_data->mask;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200812 }
813
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530814 old_mask = dsi_read_reg(dsidev, enable_reg);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200815 /* clear the irqstatus for newly enabled irqs */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530816 dsi_write_reg(dsidev, status_reg, (mask ^ old_mask) & mask);
817 dsi_write_reg(dsidev, enable_reg, mask);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200818
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200819 /* flush posted writes */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530820 dsi_read_reg(dsidev, enable_reg);
821 dsi_read_reg(dsidev, status_reg);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200822}
823
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530824/* dsi->irq_lock has to be locked by the caller */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530825static void _omap_dsi_set_irqs(struct platform_device *dsidev)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200826{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530827 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200828 u32 mask = DSI_IRQ_ERROR_MASK;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200829#ifdef DSI_CATCH_MISSING_TE
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200830 mask |= DSI_IRQ_TE_TRIGGER;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200831#endif
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530832 _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table,
833 ARRAY_SIZE(dsi->isr_tables.isr_table), mask,
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200834 DSI_IRQENABLE, DSI_IRQSTATUS);
835}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200836
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530837/* dsi->irq_lock has to be locked by the caller */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530838static void _omap_dsi_set_irqs_vc(struct platform_device *dsidev, int vc)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200839{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530840 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
841
842 _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table_vc[vc],
843 ARRAY_SIZE(dsi->isr_tables.isr_table_vc[vc]),
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200844 DSI_VC_IRQ_ERROR_MASK,
845 DSI_VC_IRQENABLE(vc), DSI_VC_IRQSTATUS(vc));
846}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200847
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530848/* dsi->irq_lock has to be locked by the caller */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530849static void _omap_dsi_set_irqs_cio(struct platform_device *dsidev)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200850{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530851 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
852
853 _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table_cio,
854 ARRAY_SIZE(dsi->isr_tables.isr_table_cio),
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200855 DSI_CIO_IRQ_ERROR_MASK,
856 DSI_COMPLEXIO_IRQ_ENABLE, DSI_COMPLEXIO_IRQ_STATUS);
857}
858
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530859static void _dsi_initialize_irq(struct platform_device *dsidev)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200860{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530861 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200862 unsigned long flags;
863 int vc;
864
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530865 spin_lock_irqsave(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200866
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530867 memset(&dsi->isr_tables, 0, sizeof(dsi->isr_tables));
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200868
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530869 _omap_dsi_set_irqs(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200870 for (vc = 0; vc < 4; ++vc)
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530871 _omap_dsi_set_irqs_vc(dsidev, vc);
872 _omap_dsi_set_irqs_cio(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200873
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530874 spin_unlock_irqrestore(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200875}
876
877static int _dsi_register_isr(omap_dsi_isr_t isr, void *arg, u32 mask,
878 struct dsi_isr_data *isr_array, unsigned isr_array_size)
879{
880 struct dsi_isr_data *isr_data;
881 int free_idx;
882 int i;
883
884 BUG_ON(isr == NULL);
885
886 /* check for duplicate entry and find a free slot */
887 free_idx = -1;
888 for (i = 0; i < isr_array_size; i++) {
889 isr_data = &isr_array[i];
890
891 if (isr_data->isr == isr && isr_data->arg == arg &&
892 isr_data->mask == mask) {
893 return -EINVAL;
894 }
895
896 if (isr_data->isr == NULL && free_idx == -1)
897 free_idx = i;
898 }
899
900 if (free_idx == -1)
901 return -EBUSY;
902
903 isr_data = &isr_array[free_idx];
904 isr_data->isr = isr;
905 isr_data->arg = arg;
906 isr_data->mask = mask;
907
908 return 0;
909}
910
911static int _dsi_unregister_isr(omap_dsi_isr_t isr, void *arg, u32 mask,
912 struct dsi_isr_data *isr_array, unsigned isr_array_size)
913{
914 struct dsi_isr_data *isr_data;
915 int i;
916
917 for (i = 0; i < isr_array_size; i++) {
918 isr_data = &isr_array[i];
919 if (isr_data->isr != isr || isr_data->arg != arg ||
920 isr_data->mask != mask)
921 continue;
922
923 isr_data->isr = NULL;
924 isr_data->arg = NULL;
925 isr_data->mask = 0;
926
927 return 0;
928 }
929
930 return -EINVAL;
931}
932
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530933static int dsi_register_isr(struct platform_device *dsidev, omap_dsi_isr_t isr,
934 void *arg, u32 mask)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200935{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530936 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200937 unsigned long flags;
938 int r;
939
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530940 spin_lock_irqsave(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200941
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530942 r = _dsi_register_isr(isr, arg, mask, dsi->isr_tables.isr_table,
943 ARRAY_SIZE(dsi->isr_tables.isr_table));
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200944
945 if (r == 0)
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530946 _omap_dsi_set_irqs(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200947
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530948 spin_unlock_irqrestore(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200949
950 return r;
951}
952
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530953static int dsi_unregister_isr(struct platform_device *dsidev,
954 omap_dsi_isr_t isr, void *arg, u32 mask)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200955{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530956 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200957 unsigned long flags;
958 int r;
959
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530960 spin_lock_irqsave(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200961
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530962 r = _dsi_unregister_isr(isr, arg, mask, dsi->isr_tables.isr_table,
963 ARRAY_SIZE(dsi->isr_tables.isr_table));
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200964
965 if (r == 0)
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530966 _omap_dsi_set_irqs(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200967
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530968 spin_unlock_irqrestore(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200969
970 return r;
971}
972
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530973static int dsi_register_isr_vc(struct platform_device *dsidev, int channel,
974 omap_dsi_isr_t isr, void *arg, u32 mask)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200975{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530976 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200977 unsigned long flags;
978 int r;
979
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530980 spin_lock_irqsave(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200981
982 r = _dsi_register_isr(isr, arg, mask,
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530983 dsi->isr_tables.isr_table_vc[channel],
984 ARRAY_SIZE(dsi->isr_tables.isr_table_vc[channel]));
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200985
986 if (r == 0)
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530987 _omap_dsi_set_irqs_vc(dsidev, channel);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200988
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530989 spin_unlock_irqrestore(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200990
991 return r;
992}
993
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530994static int dsi_unregister_isr_vc(struct platform_device *dsidev, int channel,
995 omap_dsi_isr_t isr, void *arg, u32 mask)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200996{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530997 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200998 unsigned long flags;
999 int r;
1000
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301001 spin_lock_irqsave(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001002
1003 r = _dsi_unregister_isr(isr, arg, mask,
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301004 dsi->isr_tables.isr_table_vc[channel],
1005 ARRAY_SIZE(dsi->isr_tables.isr_table_vc[channel]));
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001006
1007 if (r == 0)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301008 _omap_dsi_set_irqs_vc(dsidev, channel);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001009
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301010 spin_unlock_irqrestore(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001011
1012 return r;
1013}
1014
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301015static int dsi_register_isr_cio(struct platform_device *dsidev,
1016 omap_dsi_isr_t isr, void *arg, u32 mask)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001017{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301018 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001019 unsigned long flags;
1020 int r;
1021
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301022 spin_lock_irqsave(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001023
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301024 r = _dsi_register_isr(isr, arg, mask, dsi->isr_tables.isr_table_cio,
1025 ARRAY_SIZE(dsi->isr_tables.isr_table_cio));
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001026
1027 if (r == 0)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301028 _omap_dsi_set_irqs_cio(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001029
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301030 spin_unlock_irqrestore(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001031
1032 return r;
1033}
1034
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301035static int dsi_unregister_isr_cio(struct platform_device *dsidev,
1036 omap_dsi_isr_t isr, void *arg, u32 mask)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001037{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301038 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001039 unsigned long flags;
1040 int r;
1041
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301042 spin_lock_irqsave(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001043
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301044 r = _dsi_unregister_isr(isr, arg, mask, dsi->isr_tables.isr_table_cio,
1045 ARRAY_SIZE(dsi->isr_tables.isr_table_cio));
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001046
1047 if (r == 0)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301048 _omap_dsi_set_irqs_cio(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001049
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301050 spin_unlock_irqrestore(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001051
1052 return r;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001053}
1054
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301055static u32 dsi_get_errors(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001056{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301057 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001058 unsigned long flags;
1059 u32 e;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301060 spin_lock_irqsave(&dsi->errors_lock, flags);
1061 e = dsi->errors;
1062 dsi->errors = 0;
1063 spin_unlock_irqrestore(&dsi->errors_lock, flags);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001064 return e;
1065}
1066
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001067int dsi_runtime_get(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001068{
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001069 int r;
1070 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1071
1072 DSSDBG("dsi_runtime_get\n");
1073
1074 r = pm_runtime_get_sync(&dsi->pdev->dev);
1075 WARN_ON(r < 0);
1076 return r < 0 ? r : 0;
1077}
1078
1079void dsi_runtime_put(struct platform_device *dsidev)
1080{
1081 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1082 int r;
1083
1084 DSSDBG("dsi_runtime_put\n");
1085
Tomi Valkeinen0eaf9f52012-01-23 13:23:08 +02001086 r = pm_runtime_put_sync(&dsi->pdev->dev);
Tomi Valkeinen5be3aeb2012-06-27 16:37:18 +03001087 WARN_ON(r < 0 && r != -ENOSYS);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001088}
1089
1090/* source clock for DSI PLL. this could also be PCLKFREE */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301091static inline void dsi_enable_pll_clock(struct platform_device *dsidev,
1092 bool enable)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001093{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301094 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1095
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001096 if (enable)
Rajendra Nayakf11766d2012-06-27 14:21:26 +05301097 clk_prepare_enable(dsi->sys_clk);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001098 else
Rajendra Nayakf11766d2012-06-27 14:21:26 +05301099 clk_disable_unprepare(dsi->sys_clk);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001100
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301101 if (enable && dsi->pll_locked) {
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301102 if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 1, 1) != 1)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001103 DSSERR("cannot lock PLL when enabling clocks\n");
1104 }
1105}
1106
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301107static void _dsi_print_reset_status(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001108{
1109 u32 l;
Tomi Valkeinenc335cbf2010-10-07 13:27:42 +03001110 int b0, b1, b2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001111
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001112 /* A dummy read using the SCP interface to any DSIPHY register is
1113 * required after DSIPHY reset to complete the reset of the DSI complex
1114 * I/O. */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301115 l = dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001116
Tomi Valkeinenc335cbf2010-10-07 13:27:42 +03001117 if (dss_has_feature(FEAT_DSI_REVERSE_TXCLKESC)) {
1118 b0 = 28;
1119 b1 = 27;
1120 b2 = 26;
1121 } else {
1122 b0 = 24;
1123 b1 = 25;
1124 b2 = 26;
1125 }
1126
Chandrabhanu Mahapatraf30be7d2012-09-29 12:33:05 +05301127#define DSI_FLD_GET(fld, start, end)\
1128 FLD_GET(dsi_read_reg(dsidev, DSI_##fld), start, end)
1129
1130 pr_debug("DSI resets: PLL (%d) CIO (%d) PHY (%x%x%x, %d, %d, %d)\n",
1131 DSI_FLD_GET(PLL_STATUS, 0, 0),
1132 DSI_FLD_GET(COMPLEXIO_CFG1, 29, 29),
1133 DSI_FLD_GET(DSIPHY_CFG5, b0, b0),
1134 DSI_FLD_GET(DSIPHY_CFG5, b1, b1),
1135 DSI_FLD_GET(DSIPHY_CFG5, b2, b2),
1136 DSI_FLD_GET(DSIPHY_CFG5, 29, 29),
1137 DSI_FLD_GET(DSIPHY_CFG5, 30, 30),
1138 DSI_FLD_GET(DSIPHY_CFG5, 31, 31));
1139
1140#undef DSI_FLD_GET
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001141}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001142
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301143static inline int dsi_if_enable(struct platform_device *dsidev, bool enable)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001144{
1145 DSSDBG("dsi_if_enable(%d)\n", enable);
1146
1147 enable = enable ? 1 : 0;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301148 REG_FLD_MOD(dsidev, DSI_CTRL, enable, 0, 0); /* IF_EN */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001149
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301150 if (wait_for_bit_change(dsidev, DSI_CTRL, 0, enable) != enable) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001151 DSSERR("Failed to set dsi_if_enable to %d\n", enable);
1152 return -EIO;
1153 }
1154
1155 return 0;
1156}
1157
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301158unsigned long dsi_get_pll_hsdiv_dispc_rate(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001159{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301160 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1161
1162 return dsi->current_cinfo.dsi_pll_hsdiv_dispc_clk;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001163}
1164
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301165static unsigned long dsi_get_pll_hsdiv_dsi_rate(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001166{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301167 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1168
1169 return dsi->current_cinfo.dsi_pll_hsdiv_dsi_clk;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001170}
1171
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301172static unsigned long dsi_get_txbyteclkhs(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001173{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301174 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1175
1176 return dsi->current_cinfo.clkin4ddr / 16;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001177}
1178
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301179static unsigned long dsi_fclk_rate(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001180{
1181 unsigned long r;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001182 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001183
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02001184 if (dss_get_dsi_clk_source(dsi->module_id) == OMAP_DSS_CLK_SRC_FCK) {
Archit Taneja1bb47832011-02-24 14:17:30 +05301185 /* DSI FCLK source is DSS_CLK_FCK */
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001186 r = clk_get_rate(dsi->dss_clk);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001187 } else {
Archit Taneja1bb47832011-02-24 14:17:30 +05301188 /* DSI FCLK source is dsi_pll_hsdiv_dsi_clk */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301189 r = dsi_get_pll_hsdiv_dsi_rate(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001190 }
1191
1192 return r;
1193}
1194
1195static int dsi_set_lp_clk_divisor(struct omap_dss_device *dssdev)
1196{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301197 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301198 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001199 unsigned long dsi_fclk;
1200 unsigned lp_clk_div;
1201 unsigned long lp_clk;
1202
Tomi Valkeinenc6940a32011-02-22 13:36:10 +02001203 lp_clk_div = dssdev->clocks.dsi.lp_clk_div;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001204
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301205 if (lp_clk_div == 0 || lp_clk_div > dsi->lpdiv_max)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001206 return -EINVAL;
1207
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301208 dsi_fclk = dsi_fclk_rate(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001209
1210 lp_clk = dsi_fclk / 2 / lp_clk_div;
1211
1212 DSSDBG("LP_CLK_DIV %u, LP_CLK %lu\n", lp_clk_div, lp_clk);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301213 dsi->current_cinfo.lp_clk = lp_clk;
1214 dsi->current_cinfo.lp_clk_div = lp_clk_div;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001215
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301216 /* LP_CLK_DIVISOR */
1217 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, lp_clk_div, 12, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001218
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301219 /* LP_RX_SYNCHRO_ENABLE */
1220 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, dsi_fclk > 30000000 ? 1 : 0, 21, 21);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001221
1222 return 0;
1223}
1224
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301225static void dsi_enable_scp_clk(struct platform_device *dsidev)
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +03001226{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301227 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1228
1229 if (dsi->scp_clk_refcount++ == 0)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301230 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 1, 14, 14); /* CIO_CLK_ICG */
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +03001231}
1232
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301233static void dsi_disable_scp_clk(struct platform_device *dsidev)
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +03001234{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301235 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1236
1237 WARN_ON(dsi->scp_clk_refcount == 0);
1238 if (--dsi->scp_clk_refcount == 0)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301239 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 14, 14); /* CIO_CLK_ICG */
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +03001240}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001241
1242enum dsi_pll_power_state {
1243 DSI_PLL_POWER_OFF = 0x0,
1244 DSI_PLL_POWER_ON_HSCLK = 0x1,
1245 DSI_PLL_POWER_ON_ALL = 0x2,
1246 DSI_PLL_POWER_ON_DIV = 0x3,
1247};
1248
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301249static int dsi_pll_power(struct platform_device *dsidev,
1250 enum dsi_pll_power_state state)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001251{
1252 int t = 0;
1253
Tomi Valkeinenc94dfe052011-04-15 10:42:59 +03001254 /* DSI-PLL power command 0x3 is not working */
1255 if (dss_has_feature(FEAT_DSI_PLL_PWR_BUG) &&
1256 state == DSI_PLL_POWER_ON_DIV)
1257 state = DSI_PLL_POWER_ON_ALL;
1258
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301259 /* PLL_PWR_CMD */
1260 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, state, 31, 30);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001261
1262 /* PLL_PWR_STATUS */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301263 while (FLD_GET(dsi_read_reg(dsidev, DSI_CLK_CTRL), 29, 28) != state) {
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02001264 if (++t > 1000) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001265 DSSERR("Failed to set DSI PLL power mode to %d\n",
1266 state);
1267 return -ENODEV;
1268 }
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02001269 udelay(1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001270 }
1271
1272 return 0;
1273}
1274
1275/* calculate clock rates using dividers in cinfo */
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02001276static int dsi_calc_clock_rates(struct platform_device *dsidev,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00001277 struct dsi_clock_info *cinfo)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001278{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301279 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1280
1281 if (cinfo->regn == 0 || cinfo->regn > dsi->regn_max)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001282 return -EINVAL;
1283
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301284 if (cinfo->regm == 0 || cinfo->regm > dsi->regm_max)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001285 return -EINVAL;
1286
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301287 if (cinfo->regm_dispc > dsi->regm_dispc_max)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001288 return -EINVAL;
1289
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301290 if (cinfo->regm_dsi > dsi->regm_dsi_max)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001291 return -EINVAL;
1292
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02001293 cinfo->clkin = clk_get_rate(dsi->sys_clk);
1294 cinfo->fint = cinfo->clkin / cinfo->regn;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001295
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301296 if (cinfo->fint > dsi->fint_max || cinfo->fint < dsi->fint_min)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001297 return -EINVAL;
1298
1299 cinfo->clkin4ddr = 2 * cinfo->regm * cinfo->fint;
1300
1301 if (cinfo->clkin4ddr > 1800 * 1000 * 1000)
1302 return -EINVAL;
1303
Archit Taneja1bb47832011-02-24 14:17:30 +05301304 if (cinfo->regm_dispc > 0)
1305 cinfo->dsi_pll_hsdiv_dispc_clk =
1306 cinfo->clkin4ddr / cinfo->regm_dispc;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001307 else
Archit Taneja1bb47832011-02-24 14:17:30 +05301308 cinfo->dsi_pll_hsdiv_dispc_clk = 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001309
Archit Taneja1bb47832011-02-24 14:17:30 +05301310 if (cinfo->regm_dsi > 0)
1311 cinfo->dsi_pll_hsdiv_dsi_clk =
1312 cinfo->clkin4ddr / cinfo->regm_dsi;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001313 else
Archit Taneja1bb47832011-02-24 14:17:30 +05301314 cinfo->dsi_pll_hsdiv_dsi_clk = 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001315
1316 return 0;
1317}
1318
Archit Taneja6d523e72012-06-21 09:33:55 +05301319int dsi_pll_calc_clock_div_pck(struct platform_device *dsidev,
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301320 unsigned long req_pck, struct dsi_clock_info *dsi_cinfo,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001321 struct dispc_clock_info *dispc_cinfo)
1322{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301323 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001324 struct dsi_clock_info cur, best;
1325 struct dispc_clock_info best_dispc;
1326 int min_fck_per_pck;
1327 int match = 0;
Archit Taneja1bb47832011-02-24 14:17:30 +05301328 unsigned long dss_sys_clk, max_dss_fck;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001329
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001330 dss_sys_clk = clk_get_rate(dsi->sys_clk);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001331
Taneja, Archit31ef8232011-03-14 23:28:22 -05001332 max_dss_fck = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK);
Archit Taneja819d8072011-03-01 11:54:00 +05301333
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301334 if (req_pck == dsi->cache_req_pck &&
1335 dsi->cache_cinfo.clkin == dss_sys_clk) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001336 DSSDBG("DSI clock info found from cache\n");
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301337 *dsi_cinfo = dsi->cache_cinfo;
Archit Taneja6d523e72012-06-21 09:33:55 +05301338 dispc_find_clk_divs(req_pck, dsi_cinfo->dsi_pll_hsdiv_dispc_clk,
1339 dispc_cinfo);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001340 return 0;
1341 }
1342
1343 min_fck_per_pck = CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK;
1344
1345 if (min_fck_per_pck &&
Archit Taneja819d8072011-03-01 11:54:00 +05301346 req_pck * min_fck_per_pck > max_dss_fck) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001347 DSSERR("Requested pixel clock not possible with the current "
1348 "OMAP2_DSS_MIN_FCK_PER_PCK setting. Turning "
1349 "the constraint off.\n");
1350 min_fck_per_pck = 0;
1351 }
1352
1353 DSSDBG("dsi_pll_calc\n");
1354
1355retry:
1356 memset(&best, 0, sizeof(best));
1357 memset(&best_dispc, 0, sizeof(best_dispc));
1358
1359 memset(&cur, 0, sizeof(cur));
Archit Taneja1bb47832011-02-24 14:17:30 +05301360 cur.clkin = dss_sys_clk;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001361
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02001362 /* 0.75MHz < Fint = clkin / regn < 2.1MHz */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001363 /* To reduce PLL lock time, keep Fint high (around 2 MHz) */
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301364 for (cur.regn = 1; cur.regn < dsi->regn_max; ++cur.regn) {
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02001365 cur.fint = cur.clkin / cur.regn;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001366
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301367 if (cur.fint > dsi->fint_max || cur.fint < dsi->fint_min)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001368 continue;
1369
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02001370 /* DSIPHY(MHz) = (2 * regm / regn) * clkin */
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301371 for (cur.regm = 1; cur.regm < dsi->regm_max; ++cur.regm) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001372 unsigned long a, b;
1373
1374 a = 2 * cur.regm * (cur.clkin/1000);
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02001375 b = cur.regn;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001376 cur.clkin4ddr = a / b * 1000;
1377
1378 if (cur.clkin4ddr > 1800 * 1000 * 1000)
1379 break;
1380
Archit Taneja1bb47832011-02-24 14:17:30 +05301381 /* dsi_pll_hsdiv_dispc_clk(MHz) =
1382 * DSIPHY(MHz) / regm_dispc < 173MHz/186Mhz */
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301383 for (cur.regm_dispc = 1; cur.regm_dispc <
1384 dsi->regm_dispc_max; ++cur.regm_dispc) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001385 struct dispc_clock_info cur_dispc;
Archit Taneja1bb47832011-02-24 14:17:30 +05301386 cur.dsi_pll_hsdiv_dispc_clk =
1387 cur.clkin4ddr / cur.regm_dispc;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001388
Tomi Valkeinenb7f1fe52012-10-12 15:21:44 +03001389 if (cur.regm_dispc > 1 &&
1390 cur.regm_dispc % 2 != 0 &&
1391 req_pck >= 1000000)
1392 continue;
1393
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001394 /* this will narrow down the search a bit,
1395 * but still give pixclocks below what was
1396 * requested */
Archit Taneja1bb47832011-02-24 14:17:30 +05301397 if (cur.dsi_pll_hsdiv_dispc_clk < req_pck)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001398 break;
1399
Archit Taneja1bb47832011-02-24 14:17:30 +05301400 if (cur.dsi_pll_hsdiv_dispc_clk > max_dss_fck)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001401 continue;
1402
1403 if (min_fck_per_pck &&
Archit Taneja1bb47832011-02-24 14:17:30 +05301404 cur.dsi_pll_hsdiv_dispc_clk <
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001405 req_pck * min_fck_per_pck)
1406 continue;
1407
1408 match = 1;
1409
Archit Taneja6d523e72012-06-21 09:33:55 +05301410 dispc_find_clk_divs(req_pck,
Archit Taneja1bb47832011-02-24 14:17:30 +05301411 cur.dsi_pll_hsdiv_dispc_clk,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001412 &cur_dispc);
1413
1414 if (abs(cur_dispc.pck - req_pck) <
1415 abs(best_dispc.pck - req_pck)) {
1416 best = cur;
1417 best_dispc = cur_dispc;
1418
1419 if (cur_dispc.pck == req_pck)
1420 goto found;
1421 }
1422 }
1423 }
1424 }
1425found:
1426 if (!match) {
1427 if (min_fck_per_pck) {
1428 DSSERR("Could not find suitable clock settings.\n"
1429 "Turning FCK/PCK constraint off and"
1430 "trying again.\n");
1431 min_fck_per_pck = 0;
1432 goto retry;
1433 }
1434
1435 DSSERR("Could not find suitable clock settings.\n");
1436
1437 return -EINVAL;
1438 }
1439
Archit Taneja1bb47832011-02-24 14:17:30 +05301440 /* dsi_pll_hsdiv_dsi_clk (regm_dsi) is not used */
1441 best.regm_dsi = 0;
1442 best.dsi_pll_hsdiv_dsi_clk = 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001443
1444 if (dsi_cinfo)
1445 *dsi_cinfo = best;
1446 if (dispc_cinfo)
1447 *dispc_cinfo = best_dispc;
1448
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301449 dsi->cache_req_pck = req_pck;
1450 dsi->cache_clk_freq = 0;
1451 dsi->cache_cinfo = best;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001452
1453 return 0;
1454}
1455
Tomi Valkeinenee144e62012-08-10 16:50:51 +03001456static int dsi_pll_calc_ddrfreq(struct platform_device *dsidev,
Tomi Valkeinend66b1582012-09-24 15:15:06 +03001457 unsigned long req_clkin4ddr, struct dsi_clock_info *cinfo)
Tomi Valkeinenee144e62012-08-10 16:50:51 +03001458{
1459 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1460 struct dsi_clock_info cur, best;
Tomi Valkeinenee144e62012-08-10 16:50:51 +03001461
1462 DSSDBG("dsi_pll_calc_ddrfreq\n");
1463
Tomi Valkeinenee144e62012-08-10 16:50:51 +03001464 memset(&best, 0, sizeof(best));
1465 memset(&cur, 0, sizeof(cur));
1466
Tomi Valkeinend66b1582012-09-24 15:15:06 +03001467 cur.clkin = clk_get_rate(dsi->sys_clk);
Tomi Valkeinenee144e62012-08-10 16:50:51 +03001468
1469 for (cur.regn = 1; cur.regn < dsi->regn_max; ++cur.regn) {
1470 cur.fint = cur.clkin / cur.regn;
1471
1472 if (cur.fint > dsi->fint_max || cur.fint < dsi->fint_min)
1473 continue;
1474
1475 /* DSIPHY(MHz) = (2 * regm / regn) * clkin */
1476 for (cur.regm = 1; cur.regm < dsi->regm_max; ++cur.regm) {
1477 unsigned long a, b;
1478
1479 a = 2 * cur.regm * (cur.clkin/1000);
1480 b = cur.regn;
1481 cur.clkin4ddr = a / b * 1000;
1482
1483 if (cur.clkin4ddr > 1800 * 1000 * 1000)
1484 break;
1485
1486 if (abs(cur.clkin4ddr - req_clkin4ddr) <
1487 abs(best.clkin4ddr - req_clkin4ddr)) {
1488 best = cur;
1489 DSSDBG("best %ld\n", best.clkin4ddr);
1490 }
1491
1492 if (cur.clkin4ddr == req_clkin4ddr)
1493 goto found;
1494 }
1495 }
1496found:
Tomi Valkeinenee144e62012-08-10 16:50:51 +03001497 if (cinfo)
1498 *cinfo = best;
1499
1500 return 0;
1501}
1502
Tomi Valkeinend66b1582012-09-24 15:15:06 +03001503static void dsi_pll_calc_dsi_fck(struct platform_device *dsidev,
1504 struct dsi_clock_info *cinfo)
1505{
1506 unsigned long max_dsi_fck;
1507
1508 max_dsi_fck = dss_feat_get_param_max(FEAT_PARAM_DSI_FCK);
1509
1510 cinfo->regm_dsi = DIV_ROUND_UP(cinfo->clkin4ddr, max_dsi_fck);
1511 cinfo->dsi_pll_hsdiv_dsi_clk = cinfo->clkin4ddr / cinfo->regm_dsi;
1512}
1513
1514static int dsi_pll_calc_dispc_fck(struct platform_device *dsidev,
1515 unsigned long req_pck, struct dsi_clock_info *cinfo,
1516 struct dispc_clock_info *dispc_cinfo)
1517{
1518 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1519 unsigned regm_dispc, best_regm_dispc;
1520 unsigned long dispc_clk, best_dispc_clk;
1521 int min_fck_per_pck;
1522 unsigned long max_dss_fck;
1523 struct dispc_clock_info best_dispc;
1524 bool match;
1525
1526 max_dss_fck = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK);
1527
1528 min_fck_per_pck = CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK;
1529
1530 if (min_fck_per_pck &&
1531 req_pck * min_fck_per_pck > max_dss_fck) {
1532 DSSERR("Requested pixel clock not possible with the current "
1533 "OMAP2_DSS_MIN_FCK_PER_PCK setting. Turning "
1534 "the constraint off.\n");
1535 min_fck_per_pck = 0;
1536 }
1537
1538retry:
1539 best_regm_dispc = 0;
1540 best_dispc_clk = 0;
1541 memset(&best_dispc, 0, sizeof(best_dispc));
1542 match = false;
1543
1544 for (regm_dispc = 1; regm_dispc < dsi->regm_dispc_max; ++regm_dispc) {
1545 struct dispc_clock_info cur_dispc;
1546
1547 dispc_clk = cinfo->clkin4ddr / regm_dispc;
1548
1549 /* this will narrow down the search a bit,
1550 * but still give pixclocks below what was
1551 * requested */
1552 if (dispc_clk < req_pck)
1553 break;
1554
1555 if (dispc_clk > max_dss_fck)
1556 continue;
1557
1558 if (min_fck_per_pck && dispc_clk < req_pck * min_fck_per_pck)
1559 continue;
1560
1561 match = true;
1562
1563 dispc_find_clk_divs(req_pck, dispc_clk, &cur_dispc);
1564
1565 if (abs(cur_dispc.pck - req_pck) <
1566 abs(best_dispc.pck - req_pck)) {
1567 best_regm_dispc = regm_dispc;
1568 best_dispc_clk = dispc_clk;
1569 best_dispc = cur_dispc;
1570
1571 if (cur_dispc.pck == req_pck)
1572 goto found;
1573 }
1574 }
1575
1576 if (!match) {
1577 if (min_fck_per_pck) {
1578 DSSERR("Could not find suitable clock settings.\n"
1579 "Turning FCK/PCK constraint off and"
1580 "trying again.\n");
1581 min_fck_per_pck = 0;
1582 goto retry;
1583 }
1584
1585 DSSERR("Could not find suitable clock settings.\n");
1586
1587 return -EINVAL;
1588 }
1589found:
1590 cinfo->regm_dispc = best_regm_dispc;
1591 cinfo->dsi_pll_hsdiv_dispc_clk = best_dispc_clk;
1592
1593 *dispc_cinfo = best_dispc;
1594
1595 return 0;
1596}
1597
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301598int dsi_pll_set_clock_div(struct platform_device *dsidev,
1599 struct dsi_clock_info *cinfo)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001600{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301601 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001602 int r = 0;
1603 u32 l;
Archit Taneja9613c022011-03-22 06:33:36 -05001604 int f = 0;
Taneja, Archit49641112011-03-14 23:28:23 -05001605 u8 regn_start, regn_end, regm_start, regm_end;
1606 u8 regm_dispc_start, regm_dispc_end, regm_dsi_start, regm_dsi_end;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001607
Chandrabhanu Mahapatra702d2672012-09-24 17:12:58 +05301608 DSSDBG("DSI PLL clock config starts");
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001609
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02001610 dsi->current_cinfo.clkin = cinfo->clkin;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301611 dsi->current_cinfo.fint = cinfo->fint;
1612 dsi->current_cinfo.clkin4ddr = cinfo->clkin4ddr;
1613 dsi->current_cinfo.dsi_pll_hsdiv_dispc_clk =
Archit Taneja1bb47832011-02-24 14:17:30 +05301614 cinfo->dsi_pll_hsdiv_dispc_clk;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301615 dsi->current_cinfo.dsi_pll_hsdiv_dsi_clk =
Archit Taneja1bb47832011-02-24 14:17:30 +05301616 cinfo->dsi_pll_hsdiv_dsi_clk;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001617
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301618 dsi->current_cinfo.regn = cinfo->regn;
1619 dsi->current_cinfo.regm = cinfo->regm;
1620 dsi->current_cinfo.regm_dispc = cinfo->regm_dispc;
1621 dsi->current_cinfo.regm_dsi = cinfo->regm_dsi;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001622
1623 DSSDBG("DSI Fint %ld\n", cinfo->fint);
1624
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02001625 DSSDBG("clkin rate %ld\n", cinfo->clkin);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001626
1627 /* DSIPHY == CLKIN4DDR */
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02001628 DSSDBG("CLKIN4DDR = 2 * %d / %d * %lu = %lu\n",
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001629 cinfo->regm,
1630 cinfo->regn,
1631 cinfo->clkin,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001632 cinfo->clkin4ddr);
1633
1634 DSSDBG("Data rate on 1 DSI lane %ld Mbps\n",
1635 cinfo->clkin4ddr / 1000 / 1000 / 2);
1636
1637 DSSDBG("Clock lane freq %ld Hz\n", cinfo->clkin4ddr / 4);
1638
Archit Taneja1bb47832011-02-24 14:17:30 +05301639 DSSDBG("regm_dispc = %d, %s (%s) = %lu\n", cinfo->regm_dispc,
Archit Taneja89a35e52011-04-12 13:52:23 +05301640 dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
1641 dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
Archit Taneja1bb47832011-02-24 14:17:30 +05301642 cinfo->dsi_pll_hsdiv_dispc_clk);
1643 DSSDBG("regm_dsi = %d, %s (%s) = %lu\n", cinfo->regm_dsi,
Archit Taneja89a35e52011-04-12 13:52:23 +05301644 dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
1645 dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
Archit Taneja1bb47832011-02-24 14:17:30 +05301646 cinfo->dsi_pll_hsdiv_dsi_clk);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001647
Taneja, Archit49641112011-03-14 23:28:23 -05001648 dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGN, &regn_start, &regn_end);
1649 dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM, &regm_start, &regm_end);
1650 dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM_DISPC, &regm_dispc_start,
1651 &regm_dispc_end);
1652 dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM_DSI, &regm_dsi_start,
1653 &regm_dsi_end);
1654
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301655 /* DSI_PLL_AUTOMODE = manual */
1656 REG_FLD_MOD(dsidev, DSI_PLL_CONTROL, 0, 0, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001657
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301658 l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001659 l = FLD_MOD(l, 1, 0, 0); /* DSI_PLL_STOPMODE */
Taneja, Archit49641112011-03-14 23:28:23 -05001660 /* DSI_PLL_REGN */
1661 l = FLD_MOD(l, cinfo->regn - 1, regn_start, regn_end);
1662 /* DSI_PLL_REGM */
1663 l = FLD_MOD(l, cinfo->regm, regm_start, regm_end);
1664 /* DSI_CLOCK_DIV */
Archit Taneja1bb47832011-02-24 14:17:30 +05301665 l = FLD_MOD(l, cinfo->regm_dispc > 0 ? cinfo->regm_dispc - 1 : 0,
Taneja, Archit49641112011-03-14 23:28:23 -05001666 regm_dispc_start, regm_dispc_end);
1667 /* DSIPROTO_CLOCK_DIV */
Archit Taneja1bb47832011-02-24 14:17:30 +05301668 l = FLD_MOD(l, cinfo->regm_dsi > 0 ? cinfo->regm_dsi - 1 : 0,
Taneja, Archit49641112011-03-14 23:28:23 -05001669 regm_dsi_start, regm_dsi_end);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301670 dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION1, l);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001671
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301672 BUG_ON(cinfo->fint < dsi->fint_min || cinfo->fint > dsi->fint_max);
Archit Taneja9613c022011-03-22 06:33:36 -05001673
Tomi Valkeinenf8ef3d62012-08-22 16:00:31 +03001674 l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION2);
1675
Archit Taneja9613c022011-03-22 06:33:36 -05001676 if (dss_has_feature(FEAT_DSI_PLL_FREQSEL)) {
1677 f = cinfo->fint < 1000000 ? 0x3 :
1678 cinfo->fint < 1250000 ? 0x4 :
1679 cinfo->fint < 1500000 ? 0x5 :
1680 cinfo->fint < 1750000 ? 0x6 :
1681 0x7;
Tomi Valkeinenf8ef3d62012-08-22 16:00:31 +03001682
1683 l = FLD_MOD(l, f, 4, 1); /* DSI_PLL_FREQSEL */
1684 } else if (dss_has_feature(FEAT_DSI_PLL_SELFREQDCO)) {
1685 f = cinfo->clkin4ddr < 1000000000 ? 0x2 : 0x4;
1686
1687 l = FLD_MOD(l, f, 4, 1); /* PLL_SELFREQDCO */
Archit Taneja9613c022011-03-22 06:33:36 -05001688 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001689
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001690 l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */
1691 l = FLD_MOD(l, 0, 14, 14); /* DSIPHY_CLKINEN */
1692 l = FLD_MOD(l, 1, 20, 20); /* DSI_HSDIVBYPASS */
Tomi Valkeinen6d446102012-08-22 16:00:40 +03001693 if (dss_has_feature(FEAT_DSI_PLL_REFSEL))
1694 l = FLD_MOD(l, 3, 22, 21); /* REF_SYSCLK = sysclk */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301695 dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION2, l);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001696
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301697 REG_FLD_MOD(dsidev, DSI_PLL_GO, 1, 0, 0); /* DSI_PLL_GO */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001698
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301699 if (wait_for_bit_change(dsidev, DSI_PLL_GO, 0, 0) != 0) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001700 DSSERR("dsi pll go bit not going down.\n");
1701 r = -EIO;
1702 goto err;
1703 }
1704
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301705 if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 1, 1) != 1) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001706 DSSERR("cannot lock PLL\n");
1707 r = -EIO;
1708 goto err;
1709 }
1710
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301711 dsi->pll_locked = 1;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001712
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301713 l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION2);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001714 l = FLD_MOD(l, 0, 0, 0); /* DSI_PLL_IDLE */
1715 l = FLD_MOD(l, 0, 5, 5); /* DSI_PLL_PLLLPMODE */
1716 l = FLD_MOD(l, 0, 6, 6); /* DSI_PLL_LOWCURRSTBY */
1717 l = FLD_MOD(l, 0, 7, 7); /* DSI_PLL_TIGHTPHASELOCK */
1718 l = FLD_MOD(l, 0, 8, 8); /* DSI_PLL_DRIFTGUARDEN */
1719 l = FLD_MOD(l, 0, 10, 9); /* DSI_PLL_LOCKSEL */
1720 l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */
1721 l = FLD_MOD(l, 1, 14, 14); /* DSIPHY_CLKINEN */
1722 l = FLD_MOD(l, 0, 15, 15); /* DSI_BYPASSEN */
1723 l = FLD_MOD(l, 1, 16, 16); /* DSS_CLOCK_EN */
1724 l = FLD_MOD(l, 0, 17, 17); /* DSS_CLOCK_PWDN */
1725 l = FLD_MOD(l, 1, 18, 18); /* DSI_PROTO_CLOCK_EN */
1726 l = FLD_MOD(l, 0, 19, 19); /* DSI_PROTO_CLOCK_PWDN */
1727 l = FLD_MOD(l, 0, 20, 20); /* DSI_HSDIVBYPASS */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301728 dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION2, l);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001729
1730 DSSDBG("PLL config done\n");
1731err:
1732 return r;
1733}
1734
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301735int dsi_pll_init(struct platform_device *dsidev, bool enable_hsclk,
1736 bool enable_hsdiv)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001737{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301738 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001739 int r = 0;
1740 enum dsi_pll_power_state pwstate;
1741
1742 DSSDBG("PLL init\n");
1743
Tomi Valkeinen7a987862012-10-12 16:27:28 +03001744 /*
1745 * It seems that on many OMAPs we need to enable both to have a
1746 * functional HSDivider.
1747 */
1748 enable_hsclk = enable_hsdiv = true;
1749
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301750 if (dsi->vdds_dsi_reg == NULL) {
Tomi Valkeinenf2988ab2011-03-02 10:06:48 +02001751 struct regulator *vdds_dsi;
1752
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301753 vdds_dsi = regulator_get(&dsi->pdev->dev, "vdds_dsi");
Tomi Valkeinenf2988ab2011-03-02 10:06:48 +02001754
Tomi Valkeinen76eed4b2012-11-05 13:41:25 +02001755 /* DT HACK: try VCXIO to make omapdss work for o4 sdp/panda */
1756 if (IS_ERR(vdds_dsi))
1757 vdds_dsi = regulator_get(&dsi->pdev->dev, "VCXIO");
1758
Tomi Valkeinenf2988ab2011-03-02 10:06:48 +02001759 if (IS_ERR(vdds_dsi)) {
1760 DSSERR("can't get VDDS_DSI regulator\n");
1761 return PTR_ERR(vdds_dsi);
1762 }
1763
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301764 dsi->vdds_dsi_reg = vdds_dsi;
Tomi Valkeinenf2988ab2011-03-02 10:06:48 +02001765 }
Tomi Valkeinenf2988ab2011-03-02 10:06:48 +02001766
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301767 dsi_enable_pll_clock(dsidev, 1);
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +03001768 /*
1769 * Note: SCP CLK is not required on OMAP3, but it is required on OMAP4.
1770 */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301771 dsi_enable_scp_clk(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001772
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301773 if (!dsi->vdds_dsi_enabled) {
1774 r = regulator_enable(dsi->vdds_dsi_reg);
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +03001775 if (r)
1776 goto err0;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301777 dsi->vdds_dsi_enabled = true;
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +03001778 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001779
1780 /* XXX PLL does not come out of reset without this... */
1781 dispc_pck_free_enable(1);
1782
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301783 if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 0, 1) != 1) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001784 DSSERR("PLL not coming out of reset.\n");
1785 r = -ENODEV;
Ville Syrjälä481dfa02010-04-22 22:50:04 +02001786 dispc_pck_free_enable(0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001787 goto err1;
1788 }
1789
1790 /* XXX ... but if left on, we get problems when planes do not
1791 * fill the whole display. No idea about this */
1792 dispc_pck_free_enable(0);
1793
1794 if (enable_hsclk && enable_hsdiv)
1795 pwstate = DSI_PLL_POWER_ON_ALL;
1796 else if (enable_hsclk)
1797 pwstate = DSI_PLL_POWER_ON_HSCLK;
1798 else if (enable_hsdiv)
1799 pwstate = DSI_PLL_POWER_ON_DIV;
1800 else
1801 pwstate = DSI_PLL_POWER_OFF;
1802
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301803 r = dsi_pll_power(dsidev, pwstate);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001804
1805 if (r)
1806 goto err1;
1807
1808 DSSDBG("PLL init done\n");
1809
1810 return 0;
1811err1:
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301812 if (dsi->vdds_dsi_enabled) {
1813 regulator_disable(dsi->vdds_dsi_reg);
1814 dsi->vdds_dsi_enabled = false;
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +03001815 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001816err0:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301817 dsi_disable_scp_clk(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301818 dsi_enable_pll_clock(dsidev, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001819 return r;
1820}
1821
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301822void dsi_pll_uninit(struct platform_device *dsidev, bool disconnect_lanes)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001823{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301824 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1825
1826 dsi->pll_locked = 0;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301827 dsi_pll_power(dsidev, DSI_PLL_POWER_OFF);
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +03001828 if (disconnect_lanes) {
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301829 WARN_ON(!dsi->vdds_dsi_enabled);
1830 regulator_disable(dsi->vdds_dsi_reg);
1831 dsi->vdds_dsi_enabled = false;
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +03001832 }
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +03001833
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301834 dsi_disable_scp_clk(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301835 dsi_enable_pll_clock(dsidev, 0);
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +03001836
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001837 DSSDBG("PLL uninit done\n");
1838}
1839
Archit Taneja5a8b5722011-05-12 17:26:29 +05301840static void dsi_dump_dsidev_clocks(struct platform_device *dsidev,
1841 struct seq_file *s)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001842{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301843 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1844 struct dsi_clock_info *cinfo = &dsi->current_cinfo;
Archit Taneja89a35e52011-04-12 13:52:23 +05301845 enum omap_dss_clk_source dispc_clk_src, dsi_clk_src;
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02001846 int dsi_module = dsi->module_id;
Archit Taneja067a57e2011-03-02 11:57:25 +05301847
1848 dispc_clk_src = dss_get_dispc_clk_source();
Archit Taneja5a8b5722011-05-12 17:26:29 +05301849 dsi_clk_src = dss_get_dsi_clk_source(dsi_module);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001850
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001851 if (dsi_runtime_get(dsidev))
1852 return;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001853
Archit Taneja5a8b5722011-05-12 17:26:29 +05301854 seq_printf(s, "- DSI%d PLL -\n", dsi_module + 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001855
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02001856 seq_printf(s, "dsi pll clkin\t%lu\n", cinfo->clkin);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001857
1858 seq_printf(s, "Fint\t\t%-16luregn %u\n", cinfo->fint, cinfo->regn);
1859
1860 seq_printf(s, "CLKIN4DDR\t%-16luregm %u\n",
1861 cinfo->clkin4ddr, cinfo->regm);
1862
Archit Taneja84309f12011-12-12 11:47:41 +05301863 seq_printf(s, "DSI_PLL_HSDIV_DISPC (%s)\t%-16luregm_dispc %u\t(%s)\n",
1864 dss_feat_get_clk_source_name(dsi_module == 0 ?
1865 OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC :
1866 OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC),
Archit Taneja1bb47832011-02-24 14:17:30 +05301867 cinfo->dsi_pll_hsdiv_dispc_clk,
1868 cinfo->regm_dispc,
Archit Taneja89a35e52011-04-12 13:52:23 +05301869 dispc_clk_src == OMAP_DSS_CLK_SRC_FCK ?
Tomi Valkeinen63cf28a2010-02-23 17:40:00 +02001870 "off" : "on");
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001871
Archit Taneja84309f12011-12-12 11:47:41 +05301872 seq_printf(s, "DSI_PLL_HSDIV_DSI (%s)\t%-16luregm_dsi %u\t(%s)\n",
1873 dss_feat_get_clk_source_name(dsi_module == 0 ?
1874 OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI :
1875 OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DSI),
Archit Taneja1bb47832011-02-24 14:17:30 +05301876 cinfo->dsi_pll_hsdiv_dsi_clk,
1877 cinfo->regm_dsi,
Archit Taneja89a35e52011-04-12 13:52:23 +05301878 dsi_clk_src == OMAP_DSS_CLK_SRC_FCK ?
Tomi Valkeinen63cf28a2010-02-23 17:40:00 +02001879 "off" : "on");
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001880
Archit Taneja5a8b5722011-05-12 17:26:29 +05301881 seq_printf(s, "- DSI%d -\n", dsi_module + 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001882
Archit Taneja067a57e2011-03-02 11:57:25 +05301883 seq_printf(s, "dsi fclk source = %s (%s)\n",
1884 dss_get_generic_clk_source_name(dsi_clk_src),
1885 dss_feat_get_clk_source_name(dsi_clk_src));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001886
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301887 seq_printf(s, "DSI_FCLK\t%lu\n", dsi_fclk_rate(dsidev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001888
1889 seq_printf(s, "DDR_CLK\t\t%lu\n",
1890 cinfo->clkin4ddr / 4);
1891
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301892 seq_printf(s, "TxByteClkHS\t%lu\n", dsi_get_txbyteclkhs(dsidev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001893
1894 seq_printf(s, "LP_CLK\t\t%lu\n", cinfo->lp_clk);
1895
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001896 dsi_runtime_put(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001897}
1898
Archit Taneja5a8b5722011-05-12 17:26:29 +05301899void dsi_dump_clocks(struct seq_file *s)
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001900{
Archit Taneja5a8b5722011-05-12 17:26:29 +05301901 struct platform_device *dsidev;
1902 int i;
1903
1904 for (i = 0; i < MAX_NUM_DSI; i++) {
1905 dsidev = dsi_get_dsidev_from_id(i);
1906 if (dsidev)
1907 dsi_dump_dsidev_clocks(dsidev, s);
1908 }
1909}
1910
1911#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
1912static void dsi_dump_dsidev_irqs(struct platform_device *dsidev,
1913 struct seq_file *s)
1914{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301915 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001916 unsigned long flags;
1917 struct dsi_irq_stats stats;
1918
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301919 spin_lock_irqsave(&dsi->irq_stats_lock, flags);
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001920
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301921 stats = dsi->irq_stats;
1922 memset(&dsi->irq_stats, 0, sizeof(dsi->irq_stats));
1923 dsi->irq_stats.last_reset = jiffies;
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001924
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301925 spin_unlock_irqrestore(&dsi->irq_stats_lock, flags);
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001926
1927 seq_printf(s, "period %u ms\n",
1928 jiffies_to_msecs(jiffies - stats.last_reset));
1929
1930 seq_printf(s, "irqs %d\n", stats.irq_count);
1931#define PIS(x) \
1932 seq_printf(s, "%-20s %10d\n", #x, stats.dsi_irqs[ffs(DSI_IRQ_##x)-1]);
1933
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02001934 seq_printf(s, "-- DSI%d interrupts --\n", dsi->module_id + 1);
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001935 PIS(VC0);
1936 PIS(VC1);
1937 PIS(VC2);
1938 PIS(VC3);
1939 PIS(WAKEUP);
1940 PIS(RESYNC);
1941 PIS(PLL_LOCK);
1942 PIS(PLL_UNLOCK);
1943 PIS(PLL_RECALL);
1944 PIS(COMPLEXIO_ERR);
1945 PIS(HS_TX_TIMEOUT);
1946 PIS(LP_RX_TIMEOUT);
1947 PIS(TE_TRIGGER);
1948 PIS(ACK_TRIGGER);
1949 PIS(SYNC_LOST);
1950 PIS(LDO_POWER_GOOD);
1951 PIS(TA_TIMEOUT);
1952#undef PIS
1953
1954#define PIS(x) \
1955 seq_printf(s, "%-20s %10d %10d %10d %10d\n", #x, \
1956 stats.vc_irqs[0][ffs(DSI_VC_IRQ_##x)-1], \
1957 stats.vc_irqs[1][ffs(DSI_VC_IRQ_##x)-1], \
1958 stats.vc_irqs[2][ffs(DSI_VC_IRQ_##x)-1], \
1959 stats.vc_irqs[3][ffs(DSI_VC_IRQ_##x)-1]);
1960
1961 seq_printf(s, "-- VC interrupts --\n");
1962 PIS(CS);
1963 PIS(ECC_CORR);
1964 PIS(PACKET_SENT);
1965 PIS(FIFO_TX_OVF);
1966 PIS(FIFO_RX_OVF);
1967 PIS(BTA);
1968 PIS(ECC_NO_CORR);
1969 PIS(FIFO_TX_UDF);
1970 PIS(PP_BUSY_CHANGE);
1971#undef PIS
1972
1973#define PIS(x) \
1974 seq_printf(s, "%-20s %10d\n", #x, \
1975 stats.cio_irqs[ffs(DSI_CIO_IRQ_##x)-1]);
1976
1977 seq_printf(s, "-- CIO interrupts --\n");
1978 PIS(ERRSYNCESC1);
1979 PIS(ERRSYNCESC2);
1980 PIS(ERRSYNCESC3);
1981 PIS(ERRESC1);
1982 PIS(ERRESC2);
1983 PIS(ERRESC3);
1984 PIS(ERRCONTROL1);
1985 PIS(ERRCONTROL2);
1986 PIS(ERRCONTROL3);
1987 PIS(STATEULPS1);
1988 PIS(STATEULPS2);
1989 PIS(STATEULPS3);
1990 PIS(ERRCONTENTIONLP0_1);
1991 PIS(ERRCONTENTIONLP1_1);
1992 PIS(ERRCONTENTIONLP0_2);
1993 PIS(ERRCONTENTIONLP1_2);
1994 PIS(ERRCONTENTIONLP0_3);
1995 PIS(ERRCONTENTIONLP1_3);
1996 PIS(ULPSACTIVENOT_ALL0);
1997 PIS(ULPSACTIVENOT_ALL1);
1998#undef PIS
1999}
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02002000
Archit Taneja5a8b5722011-05-12 17:26:29 +05302001static void dsi1_dump_irqs(struct seq_file *s)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002002{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302003 struct platform_device *dsidev = dsi_get_dsidev_from_id(0);
2004
Archit Taneja5a8b5722011-05-12 17:26:29 +05302005 dsi_dump_dsidev_irqs(dsidev, s);
2006}
2007
2008static void dsi2_dump_irqs(struct seq_file *s)
2009{
2010 struct platform_device *dsidev = dsi_get_dsidev_from_id(1);
2011
2012 dsi_dump_dsidev_irqs(dsidev, s);
2013}
Archit Taneja5a8b5722011-05-12 17:26:29 +05302014#endif
2015
2016static void dsi_dump_dsidev_regs(struct platform_device *dsidev,
2017 struct seq_file *s)
2018{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302019#define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dsi_read_reg(dsidev, r))
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002020
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03002021 if (dsi_runtime_get(dsidev))
2022 return;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302023 dsi_enable_scp_clk(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002024
2025 DUMPREG(DSI_REVISION);
2026 DUMPREG(DSI_SYSCONFIG);
2027 DUMPREG(DSI_SYSSTATUS);
2028 DUMPREG(DSI_IRQSTATUS);
2029 DUMPREG(DSI_IRQENABLE);
2030 DUMPREG(DSI_CTRL);
2031 DUMPREG(DSI_COMPLEXIO_CFG1);
2032 DUMPREG(DSI_COMPLEXIO_IRQ_STATUS);
2033 DUMPREG(DSI_COMPLEXIO_IRQ_ENABLE);
2034 DUMPREG(DSI_CLK_CTRL);
2035 DUMPREG(DSI_TIMING1);
2036 DUMPREG(DSI_TIMING2);
2037 DUMPREG(DSI_VM_TIMING1);
2038 DUMPREG(DSI_VM_TIMING2);
2039 DUMPREG(DSI_VM_TIMING3);
2040 DUMPREG(DSI_CLK_TIMING);
2041 DUMPREG(DSI_TX_FIFO_VC_SIZE);
2042 DUMPREG(DSI_RX_FIFO_VC_SIZE);
2043 DUMPREG(DSI_COMPLEXIO_CFG2);
2044 DUMPREG(DSI_RX_FIFO_VC_FULLNESS);
2045 DUMPREG(DSI_VM_TIMING4);
2046 DUMPREG(DSI_TX_FIFO_VC_EMPTINESS);
2047 DUMPREG(DSI_VM_TIMING5);
2048 DUMPREG(DSI_VM_TIMING6);
2049 DUMPREG(DSI_VM_TIMING7);
2050 DUMPREG(DSI_STOPCLK_TIMING);
2051
2052 DUMPREG(DSI_VC_CTRL(0));
2053 DUMPREG(DSI_VC_TE(0));
2054 DUMPREG(DSI_VC_LONG_PACKET_HEADER(0));
2055 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(0));
2056 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(0));
2057 DUMPREG(DSI_VC_IRQSTATUS(0));
2058 DUMPREG(DSI_VC_IRQENABLE(0));
2059
2060 DUMPREG(DSI_VC_CTRL(1));
2061 DUMPREG(DSI_VC_TE(1));
2062 DUMPREG(DSI_VC_LONG_PACKET_HEADER(1));
2063 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(1));
2064 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(1));
2065 DUMPREG(DSI_VC_IRQSTATUS(1));
2066 DUMPREG(DSI_VC_IRQENABLE(1));
2067
2068 DUMPREG(DSI_VC_CTRL(2));
2069 DUMPREG(DSI_VC_TE(2));
2070 DUMPREG(DSI_VC_LONG_PACKET_HEADER(2));
2071 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(2));
2072 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(2));
2073 DUMPREG(DSI_VC_IRQSTATUS(2));
2074 DUMPREG(DSI_VC_IRQENABLE(2));
2075
2076 DUMPREG(DSI_VC_CTRL(3));
2077 DUMPREG(DSI_VC_TE(3));
2078 DUMPREG(DSI_VC_LONG_PACKET_HEADER(3));
2079 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(3));
2080 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(3));
2081 DUMPREG(DSI_VC_IRQSTATUS(3));
2082 DUMPREG(DSI_VC_IRQENABLE(3));
2083
2084 DUMPREG(DSI_DSIPHY_CFG0);
2085 DUMPREG(DSI_DSIPHY_CFG1);
2086 DUMPREG(DSI_DSIPHY_CFG2);
2087 DUMPREG(DSI_DSIPHY_CFG5);
2088
2089 DUMPREG(DSI_PLL_CONTROL);
2090 DUMPREG(DSI_PLL_STATUS);
2091 DUMPREG(DSI_PLL_GO);
2092 DUMPREG(DSI_PLL_CONFIGURATION1);
2093 DUMPREG(DSI_PLL_CONFIGURATION2);
2094
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302095 dsi_disable_scp_clk(dsidev);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03002096 dsi_runtime_put(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002097#undef DUMPREG
2098}
2099
Archit Taneja5a8b5722011-05-12 17:26:29 +05302100static void dsi1_dump_regs(struct seq_file *s)
2101{
2102 struct platform_device *dsidev = dsi_get_dsidev_from_id(0);
2103
2104 dsi_dump_dsidev_regs(dsidev, s);
2105}
2106
2107static void dsi2_dump_regs(struct seq_file *s)
2108{
2109 struct platform_device *dsidev = dsi_get_dsidev_from_id(1);
2110
2111 dsi_dump_dsidev_regs(dsidev, s);
2112}
2113
Tomi Valkeinencc5c1852010-10-06 15:18:13 +03002114enum dsi_cio_power_state {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002115 DSI_COMPLEXIO_POWER_OFF = 0x0,
2116 DSI_COMPLEXIO_POWER_ON = 0x1,
2117 DSI_COMPLEXIO_POWER_ULPS = 0x2,
2118};
2119
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302120static int dsi_cio_power(struct platform_device *dsidev,
2121 enum dsi_cio_power_state state)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002122{
2123 int t = 0;
2124
2125 /* PWR_CMD */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302126 REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG1, state, 28, 27);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002127
2128 /* PWR_STATUS */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302129 while (FLD_GET(dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1),
2130 26, 25) != state) {
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02002131 if (++t > 1000) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002132 DSSERR("failed to set complexio power state to "
2133 "%d\n", state);
2134 return -ENODEV;
2135 }
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02002136 udelay(1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002137 }
2138
2139 return 0;
2140}
2141
Archit Taneja0c65622b2011-05-16 15:17:09 +05302142static unsigned dsi_get_line_buf_size(struct platform_device *dsidev)
2143{
2144 int val;
2145
2146 /* line buffer on OMAP3 is 1024 x 24bits */
2147 /* XXX: for some reason using full buffer size causes
2148 * considerable TX slowdown with update sizes that fill the
2149 * whole buffer */
2150 if (!dss_has_feature(FEAT_DSI_GNQ))
2151 return 1023 * 3;
2152
2153 val = REG_GET(dsidev, DSI_GNQ, 14, 12); /* VP1_LINE_BUFFER_SIZE */
2154
2155 switch (val) {
2156 case 1:
2157 return 512 * 3; /* 512x24 bits */
2158 case 2:
2159 return 682 * 3; /* 682x24 bits */
2160 case 3:
2161 return 853 * 3; /* 853x24 bits */
2162 case 4:
2163 return 1024 * 3; /* 1024x24 bits */
2164 case 5:
2165 return 1194 * 3; /* 1194x24 bits */
2166 case 6:
2167 return 1365 * 3; /* 1365x24 bits */
Tomi Valkeinen2ac80fb2012-08-22 16:00:47 +03002168 case 7:
2169 return 1920 * 3; /* 1920x24 bits */
Archit Taneja0c65622b2011-05-16 15:17:09 +05302170 default:
2171 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002172 return 0;
Archit Taneja0c65622b2011-05-16 15:17:09 +05302173 }
2174}
2175
Archit Taneja9e7e9372012-08-14 12:29:22 +05302176static int dsi_set_lane_config(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002177{
Tomi Valkeinen48368392011-10-13 11:22:39 +03002178 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2179 static const u8 offsets[] = { 0, 4, 8, 12, 16 };
2180 static const enum dsi_lane_function functions[] = {
2181 DSI_LANE_CLK,
2182 DSI_LANE_DATA1,
2183 DSI_LANE_DATA2,
2184 DSI_LANE_DATA3,
2185 DSI_LANE_DATA4,
2186 };
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002187 u32 r;
Tomi Valkeinen48368392011-10-13 11:22:39 +03002188 int i;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002189
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302190 r = dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1);
Archit Taneja75d72472011-05-16 15:17:08 +05302191
Tomi Valkeinen48368392011-10-13 11:22:39 +03002192 for (i = 0; i < dsi->num_lanes_used; ++i) {
2193 unsigned offset = offsets[i];
2194 unsigned polarity, lane_number;
2195 unsigned t;
Archit Taneja75d72472011-05-16 15:17:08 +05302196
Tomi Valkeinen48368392011-10-13 11:22:39 +03002197 for (t = 0; t < dsi->num_lanes_supported; ++t)
2198 if (dsi->lanes[t].function == functions[i])
2199 break;
2200
2201 if (t == dsi->num_lanes_supported)
2202 return -EINVAL;
2203
2204 lane_number = t;
2205 polarity = dsi->lanes[t].polarity;
2206
2207 r = FLD_MOD(r, lane_number + 1, offset + 2, offset);
2208 r = FLD_MOD(r, polarity, offset + 3, offset + 3);
Archit Taneja75d72472011-05-16 15:17:08 +05302209 }
Tomi Valkeinen48368392011-10-13 11:22:39 +03002210
2211 /* clear the unused lanes */
2212 for (; i < dsi->num_lanes_supported; ++i) {
2213 unsigned offset = offsets[i];
2214
2215 r = FLD_MOD(r, 0, offset + 2, offset);
2216 r = FLD_MOD(r, 0, offset + 3, offset + 3);
2217 }
2218
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302219 dsi_write_reg(dsidev, DSI_COMPLEXIO_CFG1, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002220
Tomi Valkeinen48368392011-10-13 11:22:39 +03002221 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002222}
2223
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302224static inline unsigned ns2ddr(struct platform_device *dsidev, unsigned ns)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002225{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302226 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2227
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002228 /* convert time in ns to ddr ticks, rounding up */
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302229 unsigned long ddr_clk = dsi->current_cinfo.clkin4ddr / 4;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002230 return (ns * (ddr_clk / 1000 / 1000) + 999) / 1000;
2231}
2232
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302233static inline unsigned ddr2ns(struct platform_device *dsidev, unsigned ddr)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002234{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302235 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2236
2237 unsigned long ddr_clk = dsi->current_cinfo.clkin4ddr / 4;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002238 return ddr * 1000 * 1000 / (ddr_clk / 1000);
2239}
2240
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302241static void dsi_cio_timings(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002242{
2243 u32 r;
2244 u32 ths_prepare, ths_prepare_ths_zero, ths_trail, ths_exit;
2245 u32 tlpx_half, tclk_trail, tclk_zero;
2246 u32 tclk_prepare;
2247
2248 /* calculate timings */
2249
2250 /* 1 * DDR_CLK = 2 * UI */
2251
2252 /* min 40ns + 4*UI max 85ns + 6*UI */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302253 ths_prepare = ns2ddr(dsidev, 70) + 2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002254
2255 /* min 145ns + 10*UI */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302256 ths_prepare_ths_zero = ns2ddr(dsidev, 175) + 2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002257
2258 /* min max(8*UI, 60ns+4*UI) */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302259 ths_trail = ns2ddr(dsidev, 60) + 5;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002260
2261 /* min 100ns */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302262 ths_exit = ns2ddr(dsidev, 145);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002263
2264 /* tlpx min 50n */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302265 tlpx_half = ns2ddr(dsidev, 25);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002266
2267 /* min 60ns */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302268 tclk_trail = ns2ddr(dsidev, 60) + 2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002269
2270 /* min 38ns, max 95ns */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302271 tclk_prepare = ns2ddr(dsidev, 65);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002272
2273 /* min tclk-prepare + tclk-zero = 300ns */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302274 tclk_zero = ns2ddr(dsidev, 260);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002275
2276 DSSDBG("ths_prepare %u (%uns), ths_prepare_ths_zero %u (%uns)\n",
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302277 ths_prepare, ddr2ns(dsidev, ths_prepare),
2278 ths_prepare_ths_zero, ddr2ns(dsidev, ths_prepare_ths_zero));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002279 DSSDBG("ths_trail %u (%uns), ths_exit %u (%uns)\n",
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302280 ths_trail, ddr2ns(dsidev, ths_trail),
2281 ths_exit, ddr2ns(dsidev, ths_exit));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002282
2283 DSSDBG("tlpx_half %u (%uns), tclk_trail %u (%uns), "
2284 "tclk_zero %u (%uns)\n",
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302285 tlpx_half, ddr2ns(dsidev, tlpx_half),
2286 tclk_trail, ddr2ns(dsidev, tclk_trail),
2287 tclk_zero, ddr2ns(dsidev, tclk_zero));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002288 DSSDBG("tclk_prepare %u (%uns)\n",
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302289 tclk_prepare, ddr2ns(dsidev, tclk_prepare));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002290
2291 /* program timings */
2292
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302293 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002294 r = FLD_MOD(r, ths_prepare, 31, 24);
2295 r = FLD_MOD(r, ths_prepare_ths_zero, 23, 16);
2296 r = FLD_MOD(r, ths_trail, 15, 8);
2297 r = FLD_MOD(r, ths_exit, 7, 0);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302298 dsi_write_reg(dsidev, DSI_DSIPHY_CFG0, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002299
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302300 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1);
Tomi Valkeinene84dc1c2012-09-24 09:34:52 +03002301 r = FLD_MOD(r, tlpx_half, 20, 16);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002302 r = FLD_MOD(r, tclk_trail, 15, 8);
2303 r = FLD_MOD(r, tclk_zero, 7, 0);
Tomi Valkeinen77ccbfb2012-09-24 15:15:57 +03002304
2305 if (dss_has_feature(FEAT_DSI_PHY_DCC)) {
2306 r = FLD_MOD(r, 0, 21, 21); /* DCCEN = disable */
2307 r = FLD_MOD(r, 1, 22, 22); /* CLKINP_DIVBY2EN = enable */
2308 r = FLD_MOD(r, 1, 23, 23); /* CLKINP_SEL = enable */
2309 }
2310
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302311 dsi_write_reg(dsidev, DSI_DSIPHY_CFG1, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002312
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302313 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG2);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002314 r = FLD_MOD(r, tclk_prepare, 7, 0);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302315 dsi_write_reg(dsidev, DSI_DSIPHY_CFG2, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002316}
2317
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002318/* lane masks have lane 0 at lsb. mask_p for positive lines, n for negative */
Archit Taneja9e7e9372012-08-14 12:29:22 +05302319static void dsi_cio_enable_lane_override(struct platform_device *dsidev,
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002320 unsigned mask_p, unsigned mask_n)
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002321{
Archit Taneja75d72472011-05-16 15:17:08 +05302322 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002323 int i;
2324 u32 l;
Tomi Valkeinend9820852011-10-12 15:05:59 +03002325 u8 lptxscp_start = dsi->num_lanes_supported == 3 ? 22 : 26;
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002326
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002327 l = 0;
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002328
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002329 for (i = 0; i < dsi->num_lanes_supported; ++i) {
2330 unsigned p = dsi->lanes[i].polarity;
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002331
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002332 if (mask_p & (1 << i))
2333 l |= 1 << (i * 2 + (p ? 0 : 1));
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002334
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002335 if (mask_n & (1 << i))
2336 l |= 1 << (i * 2 + (p ? 1 : 0));
2337 }
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002338
2339 /*
2340 * Bits in REGLPTXSCPDAT4TO0DXDY:
2341 * 17: DY0 18: DX0
2342 * 19: DY1 20: DX1
2343 * 21: DY2 22: DX2
Archit Taneja75d72472011-05-16 15:17:08 +05302344 * 23: DY3 24: DX3
2345 * 25: DY4 26: DX4
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002346 */
2347
2348 /* Set the lane override configuration */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302349
2350 /* REGLPTXSCPDAT4TO0DXDY */
Archit Taneja75d72472011-05-16 15:17:08 +05302351 REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, l, lptxscp_start, 17);
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002352
2353 /* Enable lane override */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302354
2355 /* ENLPTXSCPDAT */
2356 REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 1, 27, 27);
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002357}
2358
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302359static void dsi_cio_disable_lane_override(struct platform_device *dsidev)
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002360{
2361 /* Disable lane override */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302362 REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 0, 27, 27); /* ENLPTXSCPDAT */
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002363 /* Reset the lane override configuration */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302364 /* REGLPTXSCPDAT4TO0DXDY */
2365 REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 0, 22, 17);
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002366}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002367
Archit Taneja9e7e9372012-08-14 12:29:22 +05302368static int dsi_cio_wait_tx_clk_esc_reset(struct platform_device *dsidev)
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002369{
Tomi Valkeinen8dc07662011-10-13 15:26:50 +03002370 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2371 int t, i;
2372 bool in_use[DSI_MAX_NR_LANES];
2373 static const u8 offsets_old[] = { 28, 27, 26 };
2374 static const u8 offsets_new[] = { 24, 25, 26, 27, 28 };
2375 const u8 *offsets;
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002376
Tomi Valkeinen8dc07662011-10-13 15:26:50 +03002377 if (dss_has_feature(FEAT_DSI_REVERSE_TXCLKESC))
2378 offsets = offsets_old;
2379 else
2380 offsets = offsets_new;
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002381
Tomi Valkeinen8dc07662011-10-13 15:26:50 +03002382 for (i = 0; i < dsi->num_lanes_supported; ++i)
2383 in_use[i] = dsi->lanes[i].function != DSI_LANE_UNUSED;
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002384
2385 t = 100000;
2386 while (true) {
2387 u32 l;
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002388 int ok;
2389
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302390 l = dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002391
2392 ok = 0;
Tomi Valkeinen8dc07662011-10-13 15:26:50 +03002393 for (i = 0; i < dsi->num_lanes_supported; ++i) {
2394 if (!in_use[i] || (l & (1 << offsets[i])))
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002395 ok++;
2396 }
2397
Tomi Valkeinen8dc07662011-10-13 15:26:50 +03002398 if (ok == dsi->num_lanes_supported)
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002399 break;
2400
2401 if (--t == 0) {
Tomi Valkeinen8dc07662011-10-13 15:26:50 +03002402 for (i = 0; i < dsi->num_lanes_supported; ++i) {
2403 if (!in_use[i] || (l & (1 << offsets[i])))
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002404 continue;
2405
2406 DSSERR("CIO TXCLKESC%d domain not coming " \
2407 "out of reset\n", i);
2408 }
2409 return -EIO;
2410 }
2411 }
2412
2413 return 0;
2414}
2415
Tomi Valkeinen85f17e82011-10-13 15:12:23 +03002416/* return bitmask of enabled lanes, lane0 being the lsb */
Archit Taneja9e7e9372012-08-14 12:29:22 +05302417static unsigned dsi_get_lane_mask(struct platform_device *dsidev)
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03002418{
Tomi Valkeinen85f17e82011-10-13 15:12:23 +03002419 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2420 unsigned mask = 0;
2421 int i;
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03002422
Tomi Valkeinen85f17e82011-10-13 15:12:23 +03002423 for (i = 0; i < dsi->num_lanes_supported; ++i) {
2424 if (dsi->lanes[i].function != DSI_LANE_UNUSED)
2425 mask |= 1 << i;
2426 }
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03002427
Tomi Valkeinen85f17e82011-10-13 15:12:23 +03002428 return mask;
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03002429}
2430
Archit Taneja9e7e9372012-08-14 12:29:22 +05302431static int dsi_cio_init(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002432{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302433 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002434 int r;
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002435 u32 l;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002436
Chandrabhanu Mahapatra702d2672012-09-24 17:12:58 +05302437 DSSDBG("DSI CIO init starts");
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002438
Archit Taneja9e7e9372012-08-14 12:29:22 +05302439 r = dss_dsi_enable_pads(dsi->module_id, dsi_get_lane_mask(dsidev));
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03002440 if (r)
2441 return r;
Tomi Valkeinend1f58572010-07-30 11:57:57 +03002442
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302443 dsi_enable_scp_clk(dsidev);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002444
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002445 /* A dummy read using the SCP interface to any DSIPHY register is
2446 * required after DSIPHY reset to complete the reset of the DSI complex
2447 * I/O. */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302448 dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002449
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302450 if (wait_for_bit_change(dsidev, DSI_DSIPHY_CFG5, 30, 1) != 1) {
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002451 DSSERR("CIO SCP Clock domain not coming out of reset.\n");
2452 r = -EIO;
2453 goto err_scp_clk_dom;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002454 }
2455
Archit Taneja9e7e9372012-08-14 12:29:22 +05302456 r = dsi_set_lane_config(dsidev);
Tomi Valkeinen48368392011-10-13 11:22:39 +03002457 if (r)
2458 goto err_scp_clk_dom;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002459
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002460 /* set TX STOP MODE timer to maximum for this operation */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302461 l = dsi_read_reg(dsidev, DSI_TIMING1);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002462 l = FLD_MOD(l, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
2463 l = FLD_MOD(l, 1, 14, 14); /* STOP_STATE_X16_IO */
2464 l = FLD_MOD(l, 1, 13, 13); /* STOP_STATE_X4_IO */
2465 l = FLD_MOD(l, 0x1fff, 12, 0); /* STOP_STATE_COUNTER_IO */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302466 dsi_write_reg(dsidev, DSI_TIMING1, l);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002467
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302468 if (dsi->ulps_enabled) {
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002469 unsigned mask_p;
2470 int i;
Archit Taneja75d72472011-05-16 15:17:08 +05302471
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002472 DSSDBG("manual ulps exit\n");
2473
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002474 /* ULPS is exited by Mark-1 state for 1ms, followed by
2475 * stop state. DSS HW cannot do this via the normal
2476 * ULPS exit sequence, as after reset the DSS HW thinks
2477 * that we are not in ULPS mode, and refuses to send the
2478 * sequence. So we need to send the ULPS exit sequence
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002479 * manually by setting positive lines high and negative lines
2480 * low for 1ms.
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002481 */
2482
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002483 mask_p = 0;
Archit Taneja75d72472011-05-16 15:17:08 +05302484
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002485 for (i = 0; i < dsi->num_lanes_supported; ++i) {
2486 if (dsi->lanes[i].function == DSI_LANE_UNUSED)
2487 continue;
2488 mask_p |= 1 << i;
2489 }
Archit Taneja75d72472011-05-16 15:17:08 +05302490
Archit Taneja9e7e9372012-08-14 12:29:22 +05302491 dsi_cio_enable_lane_override(dsidev, mask_p, 0);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002492 }
2493
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302494 r = dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_ON);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002495 if (r)
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002496 goto err_cio_pwr;
2497
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302498 if (wait_for_bit_change(dsidev, DSI_COMPLEXIO_CFG1, 29, 1) != 1) {
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002499 DSSERR("CIO PWR clock domain not coming out of reset.\n");
2500 r = -ENODEV;
2501 goto err_cio_pwr_dom;
2502 }
2503
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302504 dsi_if_enable(dsidev, true);
2505 dsi_if_enable(dsidev, false);
2506 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 1, 20, 20); /* LP_CLK_ENABLE */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002507
Archit Taneja9e7e9372012-08-14 12:29:22 +05302508 r = dsi_cio_wait_tx_clk_esc_reset(dsidev);
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002509 if (r)
2510 goto err_tx_clk_esc_rst;
2511
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302512 if (dsi->ulps_enabled) {
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002513 /* Keep Mark-1 state for 1ms (as per DSI spec) */
2514 ktime_t wait = ns_to_ktime(1000 * 1000);
2515 set_current_state(TASK_UNINTERRUPTIBLE);
2516 schedule_hrtimeout(&wait, HRTIMER_MODE_REL);
2517
2518 /* Disable the override. The lanes should be set to Mark-11
2519 * state by the HW */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302520 dsi_cio_disable_lane_override(dsidev);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002521 }
2522
2523 /* FORCE_TX_STOP_MODE_IO */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302524 REG_FLD_MOD(dsidev, DSI_TIMING1, 0, 15, 15);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002525
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302526 dsi_cio_timings(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002527
Archit Tanejadca2b152012-08-16 18:02:00 +05302528 if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
Archit Taneja8af6ff02011-09-05 16:48:27 +05302529 /* DDR_CLK_ALWAYS_ON */
2530 REG_FLD_MOD(dsidev, DSI_CLK_CTRL,
Archit Taneja0b3ffe32012-08-13 22:13:39 +05302531 dsi->vm_timings.ddr_clk_always_on, 13, 13);
Archit Taneja8af6ff02011-09-05 16:48:27 +05302532 }
2533
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302534 dsi->ulps_enabled = false;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002535
2536 DSSDBG("CIO init done\n");
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002537
2538 return 0;
2539
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002540err_tx_clk_esc_rst:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302541 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 20, 20); /* LP_CLK_ENABLE */
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002542err_cio_pwr_dom:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302543 dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_OFF);
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002544err_cio_pwr:
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302545 if (dsi->ulps_enabled)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302546 dsi_cio_disable_lane_override(dsidev);
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002547err_scp_clk_dom:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302548 dsi_disable_scp_clk(dsidev);
Archit Taneja9e7e9372012-08-14 12:29:22 +05302549 dss_dsi_disable_pads(dsi->module_id, dsi_get_lane_mask(dsidev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002550 return r;
2551}
2552
Archit Taneja9e7e9372012-08-14 12:29:22 +05302553static void dsi_cio_uninit(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002554{
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02002555 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302556
Archit Taneja8af6ff02011-09-05 16:48:27 +05302557 /* DDR_CLK_ALWAYS_ON */
2558 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 13, 13);
2559
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302560 dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_OFF);
2561 dsi_disable_scp_clk(dsidev);
Archit Taneja9e7e9372012-08-14 12:29:22 +05302562 dss_dsi_disable_pads(dsi->module_id, dsi_get_lane_mask(dsidev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002563}
2564
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302565static void dsi_config_tx_fifo(struct platform_device *dsidev,
2566 enum fifo_size size1, enum fifo_size size2,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002567 enum fifo_size size3, enum fifo_size size4)
2568{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302569 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002570 u32 r = 0;
2571 int add = 0;
2572 int i;
2573
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302574 dsi->vc[0].fifo_size = size1;
2575 dsi->vc[1].fifo_size = size2;
2576 dsi->vc[2].fifo_size = size3;
2577 dsi->vc[3].fifo_size = size4;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002578
2579 for (i = 0; i < 4; i++) {
2580 u8 v;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302581 int size = dsi->vc[i].fifo_size;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002582
2583 if (add + size > 4) {
2584 DSSERR("Illegal FIFO configuration\n");
2585 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002586 return;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002587 }
2588
2589 v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
2590 r |= v << (8 * i);
2591 /*DSSDBG("TX FIFO vc %d: size %d, add %d\n", i, size, add); */
2592 add += size;
2593 }
2594
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302595 dsi_write_reg(dsidev, DSI_TX_FIFO_VC_SIZE, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002596}
2597
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302598static void dsi_config_rx_fifo(struct platform_device *dsidev,
2599 enum fifo_size size1, enum fifo_size size2,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002600 enum fifo_size size3, enum fifo_size size4)
2601{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302602 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002603 u32 r = 0;
2604 int add = 0;
2605 int i;
2606
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302607 dsi->vc[0].fifo_size = size1;
2608 dsi->vc[1].fifo_size = size2;
2609 dsi->vc[2].fifo_size = size3;
2610 dsi->vc[3].fifo_size = size4;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002611
2612 for (i = 0; i < 4; i++) {
2613 u8 v;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302614 int size = dsi->vc[i].fifo_size;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002615
2616 if (add + size > 4) {
2617 DSSERR("Illegal FIFO configuration\n");
2618 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002619 return;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002620 }
2621
2622 v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
2623 r |= v << (8 * i);
2624 /*DSSDBG("RX FIFO vc %d: size %d, add %d\n", i, size, add); */
2625 add += size;
2626 }
2627
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302628 dsi_write_reg(dsidev, DSI_RX_FIFO_VC_SIZE, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002629}
2630
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302631static int dsi_force_tx_stop_mode_io(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002632{
2633 u32 r;
2634
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302635 r = dsi_read_reg(dsidev, DSI_TIMING1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002636 r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302637 dsi_write_reg(dsidev, DSI_TIMING1, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002638
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302639 if (wait_for_bit_change(dsidev, DSI_TIMING1, 15, 0) != 0) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002640 DSSERR("TX_STOP bit not going down\n");
2641 return -EIO;
2642 }
2643
2644 return 0;
2645}
2646
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302647static bool dsi_vc_is_enabled(struct platform_device *dsidev, int channel)
Archit Tanejacf398fb2011-03-23 09:59:34 +00002648{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302649 return REG_GET(dsidev, DSI_VC_CTRL(channel), 0, 0);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002650}
2651
2652static void dsi_packet_sent_handler_vp(void *data, u32 mask)
2653{
Archit Taneja2e868db2011-05-12 17:26:28 +05302654 struct dsi_packet_sent_handler_data *vp_data =
2655 (struct dsi_packet_sent_handler_data *) data;
2656 struct dsi_data *dsi = dsi_get_dsidrv_data(vp_data->dsidev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302657 const int channel = dsi->update_channel;
2658 u8 bit = dsi->te_enabled ? 30 : 31;
Archit Tanejacf398fb2011-03-23 09:59:34 +00002659
Archit Taneja2e868db2011-05-12 17:26:28 +05302660 if (REG_GET(vp_data->dsidev, DSI_VC_TE(channel), bit, bit) == 0)
2661 complete(vp_data->completion);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002662}
2663
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302664static int dsi_sync_vc_vp(struct platform_device *dsidev, int channel)
Archit Tanejacf398fb2011-03-23 09:59:34 +00002665{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302666 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Taneja2e868db2011-05-12 17:26:28 +05302667 DECLARE_COMPLETION_ONSTACK(completion);
2668 struct dsi_packet_sent_handler_data vp_data = { dsidev, &completion };
Archit Tanejacf398fb2011-03-23 09:59:34 +00002669 int r = 0;
2670 u8 bit;
2671
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302672 bit = dsi->te_enabled ? 30 : 31;
Archit Tanejacf398fb2011-03-23 09:59:34 +00002673
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302674 r = dsi_register_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp,
Archit Taneja2e868db2011-05-12 17:26:28 +05302675 &vp_data, DSI_VC_IRQ_PACKET_SENT);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002676 if (r)
2677 goto err0;
2678
2679 /* Wait for completion only if TE_EN/TE_START is still set */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302680 if (REG_GET(dsidev, DSI_VC_TE(channel), bit, bit)) {
Archit Tanejacf398fb2011-03-23 09:59:34 +00002681 if (wait_for_completion_timeout(&completion,
2682 msecs_to_jiffies(10)) == 0) {
2683 DSSERR("Failed to complete previous frame transfer\n");
2684 r = -EIO;
2685 goto err1;
2686 }
2687 }
2688
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302689 dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp,
Archit Taneja2e868db2011-05-12 17:26:28 +05302690 &vp_data, DSI_VC_IRQ_PACKET_SENT);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002691
2692 return 0;
2693err1:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302694 dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp,
Archit Taneja2e868db2011-05-12 17:26:28 +05302695 &vp_data, DSI_VC_IRQ_PACKET_SENT);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002696err0:
2697 return r;
2698}
2699
2700static void dsi_packet_sent_handler_l4(void *data, u32 mask)
2701{
Archit Taneja2e868db2011-05-12 17:26:28 +05302702 struct dsi_packet_sent_handler_data *l4_data =
2703 (struct dsi_packet_sent_handler_data *) data;
2704 struct dsi_data *dsi = dsi_get_dsidrv_data(l4_data->dsidev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302705 const int channel = dsi->update_channel;
Archit Tanejacf398fb2011-03-23 09:59:34 +00002706
Archit Taneja2e868db2011-05-12 17:26:28 +05302707 if (REG_GET(l4_data->dsidev, DSI_VC_CTRL(channel), 5, 5) == 0)
2708 complete(l4_data->completion);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002709}
2710
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302711static int dsi_sync_vc_l4(struct platform_device *dsidev, int channel)
Archit Tanejacf398fb2011-03-23 09:59:34 +00002712{
Archit Taneja2e868db2011-05-12 17:26:28 +05302713 DECLARE_COMPLETION_ONSTACK(completion);
2714 struct dsi_packet_sent_handler_data l4_data = { dsidev, &completion };
Archit Tanejacf398fb2011-03-23 09:59:34 +00002715 int r = 0;
2716
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302717 r = dsi_register_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4,
Archit Taneja2e868db2011-05-12 17:26:28 +05302718 &l4_data, DSI_VC_IRQ_PACKET_SENT);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002719 if (r)
2720 goto err0;
2721
2722 /* Wait for completion only if TX_FIFO_NOT_EMPTY is still set */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302723 if (REG_GET(dsidev, DSI_VC_CTRL(channel), 5, 5)) {
Archit Tanejacf398fb2011-03-23 09:59:34 +00002724 if (wait_for_completion_timeout(&completion,
2725 msecs_to_jiffies(10)) == 0) {
2726 DSSERR("Failed to complete previous l4 transfer\n");
2727 r = -EIO;
2728 goto err1;
2729 }
2730 }
2731
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302732 dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4,
Archit Taneja2e868db2011-05-12 17:26:28 +05302733 &l4_data, DSI_VC_IRQ_PACKET_SENT);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002734
2735 return 0;
2736err1:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302737 dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4,
Archit Taneja2e868db2011-05-12 17:26:28 +05302738 &l4_data, DSI_VC_IRQ_PACKET_SENT);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002739err0:
2740 return r;
2741}
2742
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302743static int dsi_sync_vc(struct platform_device *dsidev, int channel)
Archit Tanejacf398fb2011-03-23 09:59:34 +00002744{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302745 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2746
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302747 WARN_ON(!dsi_bus_is_locked(dsidev));
Archit Tanejacf398fb2011-03-23 09:59:34 +00002748
2749 WARN_ON(in_interrupt());
2750
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302751 if (!dsi_vc_is_enabled(dsidev, channel))
Archit Tanejacf398fb2011-03-23 09:59:34 +00002752 return 0;
2753
Archit Tanejad6049142011-08-22 11:58:08 +05302754 switch (dsi->vc[channel].source) {
2755 case DSI_VC_SOURCE_VP:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302756 return dsi_sync_vc_vp(dsidev, channel);
Archit Tanejad6049142011-08-22 11:58:08 +05302757 case DSI_VC_SOURCE_L4:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302758 return dsi_sync_vc_l4(dsidev, channel);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002759 default:
2760 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002761 return -EINVAL;
Archit Tanejacf398fb2011-03-23 09:59:34 +00002762 }
2763}
2764
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302765static int dsi_vc_enable(struct platform_device *dsidev, int channel,
2766 bool enable)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002767{
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +02002768 DSSDBG("dsi_vc_enable channel %d, enable %d\n",
2769 channel, enable);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002770
2771 enable = enable ? 1 : 0;
2772
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302773 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 0, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002774
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302775 if (wait_for_bit_change(dsidev, DSI_VC_CTRL(channel),
2776 0, enable) != enable) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002777 DSSERR("Failed to set dsi_vc_enable to %d\n", enable);
2778 return -EIO;
2779 }
2780
2781 return 0;
2782}
2783
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302784static void dsi_vc_initial_config(struct platform_device *dsidev, int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002785{
2786 u32 r;
2787
Chandrabhanu Mahapatra702d2672012-09-24 17:12:58 +05302788 DSSDBG("Initial config of virtual channel %d", channel);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002789
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302790 r = dsi_read_reg(dsidev, DSI_VC_CTRL(channel));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002791
2792 if (FLD_GET(r, 15, 15)) /* VC_BUSY */
2793 DSSERR("VC(%d) busy when trying to configure it!\n",
2794 channel);
2795
2796 r = FLD_MOD(r, 0, 1, 1); /* SOURCE, 0 = L4 */
2797 r = FLD_MOD(r, 0, 2, 2); /* BTA_SHORT_EN */
2798 r = FLD_MOD(r, 0, 3, 3); /* BTA_LONG_EN */
2799 r = FLD_MOD(r, 0, 4, 4); /* MODE, 0 = command */
2800 r = FLD_MOD(r, 1, 7, 7); /* CS_TX_EN */
2801 r = FLD_MOD(r, 1, 8, 8); /* ECC_TX_EN */
2802 r = FLD_MOD(r, 0, 9, 9); /* MODE_SPEED, high speed on/off */
Archit Taneja9613c022011-03-22 06:33:36 -05002803 if (dss_has_feature(FEAT_DSI_VC_OCP_WIDTH))
2804 r = FLD_MOD(r, 3, 11, 10); /* OCP_WIDTH = 32 bit */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002805
2806 r = FLD_MOD(r, 4, 29, 27); /* DMA_RX_REQ_NB = no dma */
2807 r = FLD_MOD(r, 4, 23, 21); /* DMA_TX_REQ_NB = no dma */
2808
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302809 dsi_write_reg(dsidev, DSI_VC_CTRL(channel), r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002810}
2811
Archit Tanejad6049142011-08-22 11:58:08 +05302812static int dsi_vc_config_source(struct platform_device *dsidev, int channel,
2813 enum dsi_vc_source source)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002814{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302815 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2816
Archit Tanejad6049142011-08-22 11:58:08 +05302817 if (dsi->vc[channel].source == source)
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03002818 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002819
Chandrabhanu Mahapatra702d2672012-09-24 17:12:58 +05302820 DSSDBG("Source config of virtual channel %d", channel);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002821
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302822 dsi_sync_vc(dsidev, channel);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002823
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302824 dsi_vc_enable(dsidev, channel, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002825
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03002826 /* VC_BUSY */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302827 if (wait_for_bit_change(dsidev, DSI_VC_CTRL(channel), 15, 0) != 0) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002828 DSSERR("vc(%d) busy when trying to config for VP\n", channel);
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03002829 return -EIO;
2830 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002831
Archit Tanejad6049142011-08-22 11:58:08 +05302832 /* SOURCE, 0 = L4, 1 = video port */
2833 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), source, 1, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002834
Archit Taneja9613c022011-03-22 06:33:36 -05002835 /* DCS_CMD_ENABLE */
Archit Tanejad6049142011-08-22 11:58:08 +05302836 if (dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC)) {
2837 bool enable = source == DSI_VC_SOURCE_VP;
2838 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 30, 30);
2839 }
Archit Taneja9613c022011-03-22 06:33:36 -05002840
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302841 dsi_vc_enable(dsidev, channel, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002842
Archit Tanejad6049142011-08-22 11:58:08 +05302843 dsi->vc[channel].source = source;
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03002844
2845 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002846}
2847
Archit Taneja1ffefe72011-05-12 17:26:24 +05302848void omapdss_dsi_vc_enable_hs(struct omap_dss_device *dssdev, int channel,
2849 bool enable)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002850{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302851 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Taneja0b3ffe32012-08-13 22:13:39 +05302852 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302853
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002854 DSSDBG("dsi_vc_enable_hs(%d, %d)\n", channel, enable);
2855
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302856 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen61140c92010-01-12 16:00:30 +02002857
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302858 dsi_vc_enable(dsidev, channel, 0);
2859 dsi_if_enable(dsidev, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002860
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302861 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 9, 9);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002862
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302863 dsi_vc_enable(dsidev, channel, 1);
2864 dsi_if_enable(dsidev, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002865
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302866 dsi_force_tx_stop_mode_io(dsidev);
Archit Taneja8af6ff02011-09-05 16:48:27 +05302867
2868 /* start the DDR clock by sending a NULL packet */
Archit Taneja0b3ffe32012-08-13 22:13:39 +05302869 if (dsi->vm_timings.ddr_clk_always_on && enable)
Archit Taneja8af6ff02011-09-05 16:48:27 +05302870 dsi_vc_send_null(dssdev, channel);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002871}
Tomi Valkeinen61140c92010-01-12 16:00:30 +02002872EXPORT_SYMBOL(omapdss_dsi_vc_enable_hs);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002873
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302874static void dsi_vc_flush_long_data(struct platform_device *dsidev, int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002875{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302876 while (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002877 u32 val;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302878 val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002879 DSSDBG("\t\tb1 %#02x b2 %#02x b3 %#02x b4 %#02x\n",
2880 (val >> 0) & 0xff,
2881 (val >> 8) & 0xff,
2882 (val >> 16) & 0xff,
2883 (val >> 24) & 0xff);
2884 }
2885}
2886
2887static void dsi_show_rx_ack_with_err(u16 err)
2888{
2889 DSSERR("\tACK with ERROR (%#x):\n", err);
2890 if (err & (1 << 0))
2891 DSSERR("\t\tSoT Error\n");
2892 if (err & (1 << 1))
2893 DSSERR("\t\tSoT Sync Error\n");
2894 if (err & (1 << 2))
2895 DSSERR("\t\tEoT Sync Error\n");
2896 if (err & (1 << 3))
2897 DSSERR("\t\tEscape Mode Entry Command Error\n");
2898 if (err & (1 << 4))
2899 DSSERR("\t\tLP Transmit Sync Error\n");
2900 if (err & (1 << 5))
2901 DSSERR("\t\tHS Receive Timeout Error\n");
2902 if (err & (1 << 6))
2903 DSSERR("\t\tFalse Control Error\n");
2904 if (err & (1 << 7))
2905 DSSERR("\t\t(reserved7)\n");
2906 if (err & (1 << 8))
2907 DSSERR("\t\tECC Error, single-bit (corrected)\n");
2908 if (err & (1 << 9))
2909 DSSERR("\t\tECC Error, multi-bit (not corrected)\n");
2910 if (err & (1 << 10))
2911 DSSERR("\t\tChecksum Error\n");
2912 if (err & (1 << 11))
2913 DSSERR("\t\tData type not recognized\n");
2914 if (err & (1 << 12))
2915 DSSERR("\t\tInvalid VC ID\n");
2916 if (err & (1 << 13))
2917 DSSERR("\t\tInvalid Transmission Length\n");
2918 if (err & (1 << 14))
2919 DSSERR("\t\t(reserved14)\n");
2920 if (err & (1 << 15))
2921 DSSERR("\t\tDSI Protocol Violation\n");
2922}
2923
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302924static u16 dsi_vc_flush_receive_data(struct platform_device *dsidev,
2925 int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002926{
2927 /* RX_FIFO_NOT_EMPTY */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302928 while (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002929 u32 val;
2930 u8 dt;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302931 val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel));
Tomi Valkeinen86a78672010-03-16 16:19:06 +02002932 DSSERR("\trawval %#08x\n", val);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002933 dt = FLD_GET(val, 5, 0);
Archit Taneja7a7c48f2011-08-25 18:25:03 +05302934 if (dt == MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002935 u16 err = FLD_GET(val, 23, 8);
2936 dsi_show_rx_ack_with_err(err);
Archit Taneja7a7c48f2011-08-25 18:25:03 +05302937 } else if (dt == MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE) {
Tomi Valkeinen86a78672010-03-16 16:19:06 +02002938 DSSERR("\tDCS short response, 1 byte: %#x\n",
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002939 FLD_GET(val, 23, 8));
Archit Taneja7a7c48f2011-08-25 18:25:03 +05302940 } else if (dt == MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE) {
Tomi Valkeinen86a78672010-03-16 16:19:06 +02002941 DSSERR("\tDCS short response, 2 byte: %#x\n",
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002942 FLD_GET(val, 23, 8));
Archit Taneja7a7c48f2011-08-25 18:25:03 +05302943 } else if (dt == MIPI_DSI_RX_DCS_LONG_READ_RESPONSE) {
Tomi Valkeinen86a78672010-03-16 16:19:06 +02002944 DSSERR("\tDCS long response, len %d\n",
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002945 FLD_GET(val, 23, 8));
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302946 dsi_vc_flush_long_data(dsidev, channel);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002947 } else {
2948 DSSERR("\tunknown datatype 0x%02x\n", dt);
2949 }
2950 }
2951 return 0;
2952}
2953
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302954static int dsi_vc_send_bta(struct platform_device *dsidev, int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002955{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302956 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2957
2958 if (dsi->debug_write || dsi->debug_read)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002959 DSSDBG("dsi_vc_send_bta %d\n", channel);
2960
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302961 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002962
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302963 /* RX_FIFO_NOT_EMPTY */
2964 if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002965 DSSERR("rx fifo not empty when sending BTA, dumping data:\n");
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302966 dsi_vc_flush_receive_data(dsidev, channel);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002967 }
2968
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302969 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 1, 6, 6); /* BTA_EN */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002970
Tomi Valkeinen968f8e92011-10-12 10:13:14 +03002971 /* flush posted write */
2972 dsi_read_reg(dsidev, DSI_VC_CTRL(channel));
2973
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002974 return 0;
2975}
2976
Archit Taneja1ffefe72011-05-12 17:26:24 +05302977int dsi_vc_send_bta_sync(struct omap_dss_device *dssdev, int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002978{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302979 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Tomi Valkeinenf36a06e2011-03-02 14:48:41 +02002980 DECLARE_COMPLETION_ONSTACK(completion);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002981 int r = 0;
2982 u32 err;
2983
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302984 r = dsi_register_isr_vc(dsidev, channel, dsi_completion_handler,
Tomi Valkeinenf36a06e2011-03-02 14:48:41 +02002985 &completion, DSI_VC_IRQ_BTA);
2986 if (r)
2987 goto err0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002988
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302989 r = dsi_register_isr(dsidev, dsi_completion_handler, &completion,
Tomi Valkeinen773b30b2010-10-08 16:15:25 +03002990 DSI_IRQ_ERROR_MASK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002991 if (r)
Tomi Valkeinenf36a06e2011-03-02 14:48:41 +02002992 goto err1;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002993
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302994 r = dsi_vc_send_bta(dsidev, channel);
Tomi Valkeinen773b30b2010-10-08 16:15:25 +03002995 if (r)
2996 goto err2;
2997
Tomi Valkeinenf36a06e2011-03-02 14:48:41 +02002998 if (wait_for_completion_timeout(&completion,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002999 msecs_to_jiffies(500)) == 0) {
3000 DSSERR("Failed to receive BTA\n");
3001 r = -EIO;
Tomi Valkeinen773b30b2010-10-08 16:15:25 +03003002 goto err2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003003 }
3004
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303005 err = dsi_get_errors(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003006 if (err) {
3007 DSSERR("Error while sending BTA: %x\n", err);
3008 r = -EIO;
Tomi Valkeinen773b30b2010-10-08 16:15:25 +03003009 goto err2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003010 }
Tomi Valkeinen773b30b2010-10-08 16:15:25 +03003011err2:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303012 dsi_unregister_isr(dsidev, dsi_completion_handler, &completion,
Tomi Valkeinen773b30b2010-10-08 16:15:25 +03003013 DSI_IRQ_ERROR_MASK);
Tomi Valkeinenf36a06e2011-03-02 14:48:41 +02003014err1:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303015 dsi_unregister_isr_vc(dsidev, channel, dsi_completion_handler,
Tomi Valkeinenf36a06e2011-03-02 14:48:41 +02003016 &completion, DSI_VC_IRQ_BTA);
3017err0:
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003018 return r;
3019}
3020EXPORT_SYMBOL(dsi_vc_send_bta_sync);
3021
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303022static inline void dsi_vc_write_long_header(struct platform_device *dsidev,
3023 int channel, u8 data_type, u16 len, u8 ecc)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003024{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303025 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003026 u32 val;
3027 u8 data_id;
3028
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303029 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003030
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303031 data_id = data_type | dsi->vc[channel].vc_id << 6;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003032
3033 val = FLD_VAL(data_id, 7, 0) | FLD_VAL(len, 23, 8) |
3034 FLD_VAL(ecc, 31, 24);
3035
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303036 dsi_write_reg(dsidev, DSI_VC_LONG_PACKET_HEADER(channel), val);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003037}
3038
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303039static inline void dsi_vc_write_long_payload(struct platform_device *dsidev,
3040 int channel, u8 b1, u8 b2, u8 b3, u8 b4)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003041{
3042 u32 val;
3043
3044 val = b4 << 24 | b3 << 16 | b2 << 8 | b1 << 0;
3045
3046/* DSSDBG("\twriting %02x, %02x, %02x, %02x (%#010x)\n",
3047 b1, b2, b3, b4, val); */
3048
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303049 dsi_write_reg(dsidev, DSI_VC_LONG_PACKET_PAYLOAD(channel), val);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003050}
3051
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303052static int dsi_vc_send_long(struct platform_device *dsidev, int channel,
3053 u8 data_type, u8 *data, u16 len, u8 ecc)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003054{
3055 /*u32 val; */
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303056 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003057 int i;
3058 u8 *p;
3059 int r = 0;
3060 u8 b1, b2, b3, b4;
3061
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303062 if (dsi->debug_write)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003063 DSSDBG("dsi_vc_send_long, %d bytes\n", len);
3064
3065 /* len + header */
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303066 if (dsi->vc[channel].fifo_size * 32 * 4 < len + 4) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003067 DSSERR("unable to send long packet: packet too long.\n");
3068 return -EINVAL;
3069 }
3070
Archit Tanejad6049142011-08-22 11:58:08 +05303071 dsi_vc_config_source(dsidev, channel, DSI_VC_SOURCE_L4);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003072
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303073 dsi_vc_write_long_header(dsidev, channel, data_type, len, ecc);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003074
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003075 p = data;
3076 for (i = 0; i < len >> 2; i++) {
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303077 if (dsi->debug_write)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003078 DSSDBG("\tsending full packet %d\n", i);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003079
3080 b1 = *p++;
3081 b2 = *p++;
3082 b3 = *p++;
3083 b4 = *p++;
3084
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303085 dsi_vc_write_long_payload(dsidev, channel, b1, b2, b3, b4);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003086 }
3087
3088 i = len % 4;
3089 if (i) {
3090 b1 = 0; b2 = 0; b3 = 0;
3091
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303092 if (dsi->debug_write)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003093 DSSDBG("\tsending remainder bytes %d\n", i);
3094
3095 switch (i) {
3096 case 3:
3097 b1 = *p++;
3098 b2 = *p++;
3099 b3 = *p++;
3100 break;
3101 case 2:
3102 b1 = *p++;
3103 b2 = *p++;
3104 break;
3105 case 1:
3106 b1 = *p++;
3107 break;
3108 }
3109
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303110 dsi_vc_write_long_payload(dsidev, channel, b1, b2, b3, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003111 }
3112
3113 return r;
3114}
3115
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303116static int dsi_vc_send_short(struct platform_device *dsidev, int channel,
3117 u8 data_type, u16 data, u8 ecc)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003118{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303119 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003120 u32 r;
3121 u8 data_id;
3122
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303123 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003124
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303125 if (dsi->debug_write)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003126 DSSDBG("dsi_vc_send_short(ch%d, dt %#x, b1 %#x, b2 %#x)\n",
3127 channel,
3128 data_type, data & 0xff, (data >> 8) & 0xff);
3129
Archit Tanejad6049142011-08-22 11:58:08 +05303130 dsi_vc_config_source(dsidev, channel, DSI_VC_SOURCE_L4);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003131
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303132 if (FLD_GET(dsi_read_reg(dsidev, DSI_VC_CTRL(channel)), 16, 16)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003133 DSSERR("ERROR FIFO FULL, aborting transfer\n");
3134 return -EINVAL;
3135 }
3136
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303137 data_id = data_type | dsi->vc[channel].vc_id << 6;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003138
3139 r = (data_id << 0) | (data << 8) | (ecc << 24);
3140
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303141 dsi_write_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel), r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003142
3143 return 0;
3144}
3145
Archit Taneja1ffefe72011-05-12 17:26:24 +05303146int dsi_vc_send_null(struct omap_dss_device *dssdev, int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003147{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303148 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303149
Archit Taneja18b7d092011-09-05 17:01:08 +05303150 return dsi_vc_send_long(dsidev, channel, MIPI_DSI_NULL_PACKET, NULL,
3151 0, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003152}
3153EXPORT_SYMBOL(dsi_vc_send_null);
3154
Archit Taneja9e7e9372012-08-14 12:29:22 +05303155static int dsi_vc_write_nosync_common(struct platform_device *dsidev,
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303156 int channel, u8 *data, int len, enum dss_dsi_content_type type)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003157{
3158 int r;
3159
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303160 if (len == 0) {
3161 BUG_ON(type == DSS_DSI_CONTENT_DCS);
Archit Taneja7a7c48f2011-08-25 18:25:03 +05303162 r = dsi_vc_send_short(dsidev, channel,
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303163 MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM, 0, 0);
3164 } else if (len == 1) {
3165 r = dsi_vc_send_short(dsidev, channel,
3166 type == DSS_DSI_CONTENT_GENERIC ?
3167 MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM :
Archit Taneja7a7c48f2011-08-25 18:25:03 +05303168 MIPI_DSI_DCS_SHORT_WRITE, data[0], 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003169 } else if (len == 2) {
Archit Taneja7a7c48f2011-08-25 18:25:03 +05303170 r = dsi_vc_send_short(dsidev, channel,
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303171 type == DSS_DSI_CONTENT_GENERIC ?
3172 MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM :
Archit Taneja7a7c48f2011-08-25 18:25:03 +05303173 MIPI_DSI_DCS_SHORT_WRITE_PARAM,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003174 data[0] | (data[1] << 8), 0);
3175 } else {
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303176 r = dsi_vc_send_long(dsidev, channel,
3177 type == DSS_DSI_CONTENT_GENERIC ?
3178 MIPI_DSI_GENERIC_LONG_WRITE :
3179 MIPI_DSI_DCS_LONG_WRITE, data, len, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003180 }
3181
3182 return r;
3183}
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303184
3185int dsi_vc_dcs_write_nosync(struct omap_dss_device *dssdev, int channel,
3186 u8 *data, int len)
3187{
Archit Taneja9e7e9372012-08-14 12:29:22 +05303188 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
3189
3190 return dsi_vc_write_nosync_common(dsidev, channel, data, len,
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303191 DSS_DSI_CONTENT_DCS);
3192}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003193EXPORT_SYMBOL(dsi_vc_dcs_write_nosync);
3194
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303195int dsi_vc_generic_write_nosync(struct omap_dss_device *dssdev, int channel,
3196 u8 *data, int len)
3197{
Archit Taneja9e7e9372012-08-14 12:29:22 +05303198 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
3199
3200 return dsi_vc_write_nosync_common(dsidev, channel, data, len,
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303201 DSS_DSI_CONTENT_GENERIC);
3202}
3203EXPORT_SYMBOL(dsi_vc_generic_write_nosync);
3204
3205static int dsi_vc_write_common(struct omap_dss_device *dssdev, int channel,
3206 u8 *data, int len, enum dss_dsi_content_type type)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003207{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303208 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003209 int r;
3210
Archit Taneja9e7e9372012-08-14 12:29:22 +05303211 r = dsi_vc_write_nosync_common(dsidev, channel, data, len, type);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003212 if (r)
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003213 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003214
Archit Taneja1ffefe72011-05-12 17:26:24 +05303215 r = dsi_vc_send_bta_sync(dssdev, channel);
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003216 if (r)
3217 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003218
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303219 /* RX_FIFO_NOT_EMPTY */
3220 if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
Tomi Valkeinenb63ac1e2010-04-09 13:20:57 +03003221 DSSERR("rx fifo not empty after write, dumping data:\n");
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303222 dsi_vc_flush_receive_data(dsidev, channel);
Tomi Valkeinenb63ac1e2010-04-09 13:20:57 +03003223 r = -EIO;
3224 goto err;
3225 }
3226
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003227 return 0;
3228err:
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303229 DSSERR("dsi_vc_write_common(ch %d, cmd 0x%02x, len %d) failed\n",
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003230 channel, data[0], len);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003231 return r;
3232}
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303233
3234int dsi_vc_dcs_write(struct omap_dss_device *dssdev, int channel, u8 *data,
3235 int len)
3236{
3237 return dsi_vc_write_common(dssdev, channel, data, len,
3238 DSS_DSI_CONTENT_DCS);
3239}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003240EXPORT_SYMBOL(dsi_vc_dcs_write);
3241
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303242int dsi_vc_generic_write(struct omap_dss_device *dssdev, int channel, u8 *data,
3243 int len)
3244{
3245 return dsi_vc_write_common(dssdev, channel, data, len,
3246 DSS_DSI_CONTENT_GENERIC);
3247}
3248EXPORT_SYMBOL(dsi_vc_generic_write);
3249
Archit Taneja1ffefe72011-05-12 17:26:24 +05303250int dsi_vc_dcs_write_0(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd)
Tomi Valkeinen828c48f2009-12-16 14:53:15 +02003251{
Archit Taneja1ffefe72011-05-12 17:26:24 +05303252 return dsi_vc_dcs_write(dssdev, channel, &dcs_cmd, 1);
Tomi Valkeinen828c48f2009-12-16 14:53:15 +02003253}
3254EXPORT_SYMBOL(dsi_vc_dcs_write_0);
3255
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303256int dsi_vc_generic_write_0(struct omap_dss_device *dssdev, int channel)
3257{
3258 return dsi_vc_generic_write(dssdev, channel, NULL, 0);
3259}
3260EXPORT_SYMBOL(dsi_vc_generic_write_0);
3261
Archit Taneja1ffefe72011-05-12 17:26:24 +05303262int dsi_vc_dcs_write_1(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
3263 u8 param)
Tomi Valkeinen828c48f2009-12-16 14:53:15 +02003264{
3265 u8 buf[2];
3266 buf[0] = dcs_cmd;
3267 buf[1] = param;
Archit Taneja1ffefe72011-05-12 17:26:24 +05303268 return dsi_vc_dcs_write(dssdev, channel, buf, 2);
Tomi Valkeinen828c48f2009-12-16 14:53:15 +02003269}
3270EXPORT_SYMBOL(dsi_vc_dcs_write_1);
3271
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303272int dsi_vc_generic_write_1(struct omap_dss_device *dssdev, int channel,
3273 u8 param)
3274{
3275 return dsi_vc_generic_write(dssdev, channel, &param, 1);
3276}
3277EXPORT_SYMBOL(dsi_vc_generic_write_1);
3278
3279int dsi_vc_generic_write_2(struct omap_dss_device *dssdev, int channel,
3280 u8 param1, u8 param2)
3281{
3282 u8 buf[2];
3283 buf[0] = param1;
3284 buf[1] = param2;
3285 return dsi_vc_generic_write(dssdev, channel, buf, 2);
3286}
3287EXPORT_SYMBOL(dsi_vc_generic_write_2);
3288
Archit Taneja9e7e9372012-08-14 12:29:22 +05303289static int dsi_vc_dcs_send_read_request(struct platform_device *dsidev,
Archit Tanejab8509752011-08-30 15:48:23 +05303290 int channel, u8 dcs_cmd)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003291{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303292 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejab8509752011-08-30 15:48:23 +05303293 int r;
3294
3295 if (dsi->debug_read)
3296 DSSDBG("dsi_vc_dcs_send_read_request(ch%d, dcs_cmd %x)\n",
3297 channel, dcs_cmd);
3298
3299 r = dsi_vc_send_short(dsidev, channel, MIPI_DSI_DCS_READ, dcs_cmd, 0);
3300 if (r) {
3301 DSSERR("dsi_vc_dcs_send_read_request(ch %d, cmd 0x%02x)"
3302 " failed\n", channel, dcs_cmd);
3303 return r;
3304 }
3305
3306 return 0;
3307}
3308
Archit Taneja9e7e9372012-08-14 12:29:22 +05303309static int dsi_vc_generic_send_read_request(struct platform_device *dsidev,
Archit Tanejab3b89c02011-08-30 16:07:39 +05303310 int channel, u8 *reqdata, int reqlen)
3311{
Archit Tanejab3b89c02011-08-30 16:07:39 +05303312 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
3313 u16 data;
3314 u8 data_type;
3315 int r;
3316
3317 if (dsi->debug_read)
3318 DSSDBG("dsi_vc_generic_send_read_request(ch %d, reqlen %d)\n",
3319 channel, reqlen);
3320
3321 if (reqlen == 0) {
3322 data_type = MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM;
3323 data = 0;
3324 } else if (reqlen == 1) {
3325 data_type = MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM;
3326 data = reqdata[0];
3327 } else if (reqlen == 2) {
3328 data_type = MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM;
3329 data = reqdata[0] | (reqdata[1] << 8);
3330 } else {
3331 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03003332 return -EINVAL;
Archit Tanejab3b89c02011-08-30 16:07:39 +05303333 }
3334
3335 r = dsi_vc_send_short(dsidev, channel, data_type, data, 0);
3336 if (r) {
3337 DSSERR("dsi_vc_generic_send_read_request(ch %d, reqlen %d)"
3338 " failed\n", channel, reqlen);
3339 return r;
3340 }
3341
3342 return 0;
3343}
3344
3345static int dsi_vc_read_rx_fifo(struct platform_device *dsidev, int channel,
3346 u8 *buf, int buflen, enum dss_dsi_content_type type)
Archit Tanejab8509752011-08-30 15:48:23 +05303347{
3348 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003349 u32 val;
3350 u8 dt;
3351 int r;
3352
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003353 /* RX_FIFO_NOT_EMPTY */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303354 if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20) == 0) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003355 DSSERR("RX fifo empty when trying to read.\n");
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003356 r = -EIO;
3357 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003358 }
3359
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303360 val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel));
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303361 if (dsi->debug_read)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003362 DSSDBG("\theader: %08x\n", val);
3363 dt = FLD_GET(val, 5, 0);
Archit Taneja7a7c48f2011-08-25 18:25:03 +05303364 if (dt == MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003365 u16 err = FLD_GET(val, 23, 8);
3366 dsi_show_rx_ack_with_err(err);
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003367 r = -EIO;
3368 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003369
Archit Tanejab3b89c02011-08-30 16:07:39 +05303370 } else if (dt == (type == DSS_DSI_CONTENT_GENERIC ?
3371 MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_1BYTE :
3372 MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003373 u8 data = FLD_GET(val, 15, 8);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303374 if (dsi->debug_read)
Archit Tanejab3b89c02011-08-30 16:07:39 +05303375 DSSDBG("\t%s short response, 1 byte: %02x\n",
3376 type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" :
3377 "DCS", data);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003378
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003379 if (buflen < 1) {
3380 r = -EIO;
3381 goto err;
3382 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003383
3384 buf[0] = data;
3385
3386 return 1;
Archit Tanejab3b89c02011-08-30 16:07:39 +05303387 } else if (dt == (type == DSS_DSI_CONTENT_GENERIC ?
3388 MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_2BYTE :
3389 MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003390 u16 data = FLD_GET(val, 23, 8);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303391 if (dsi->debug_read)
Archit Tanejab3b89c02011-08-30 16:07:39 +05303392 DSSDBG("\t%s short response, 2 byte: %04x\n",
3393 type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" :
3394 "DCS", data);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003395
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003396 if (buflen < 2) {
3397 r = -EIO;
3398 goto err;
3399 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003400
3401 buf[0] = data & 0xff;
3402 buf[1] = (data >> 8) & 0xff;
3403
3404 return 2;
Archit Tanejab3b89c02011-08-30 16:07:39 +05303405 } else if (dt == (type == DSS_DSI_CONTENT_GENERIC ?
3406 MIPI_DSI_RX_GENERIC_LONG_READ_RESPONSE :
3407 MIPI_DSI_RX_DCS_LONG_READ_RESPONSE)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003408 int w;
3409 int len = FLD_GET(val, 23, 8);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303410 if (dsi->debug_read)
Archit Tanejab3b89c02011-08-30 16:07:39 +05303411 DSSDBG("\t%s long response, len %d\n",
3412 type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" :
3413 "DCS", len);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003414
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003415 if (len > buflen) {
3416 r = -EIO;
3417 goto err;
3418 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003419
3420 /* two byte checksum ends the packet, not included in len */
3421 for (w = 0; w < len + 2;) {
3422 int b;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303423 val = dsi_read_reg(dsidev,
3424 DSI_VC_SHORT_PACKET_HEADER(channel));
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303425 if (dsi->debug_read)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003426 DSSDBG("\t\t%02x %02x %02x %02x\n",
3427 (val >> 0) & 0xff,
3428 (val >> 8) & 0xff,
3429 (val >> 16) & 0xff,
3430 (val >> 24) & 0xff);
3431
3432 for (b = 0; b < 4; ++b) {
3433 if (w < len)
3434 buf[w] = (val >> (b * 8)) & 0xff;
3435 /* we discard the 2 byte checksum */
3436 ++w;
3437 }
3438 }
3439
3440 return len;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003441 } else {
3442 DSSERR("\tunknown datatype 0x%02x\n", dt);
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003443 r = -EIO;
3444 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003445 }
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003446
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003447err:
Archit Tanejab3b89c02011-08-30 16:07:39 +05303448 DSSERR("dsi_vc_read_rx_fifo(ch %d type %s) failed\n", channel,
3449 type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" : "DCS");
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003450
Archit Tanejab8509752011-08-30 15:48:23 +05303451 return r;
3452}
3453
3454int dsi_vc_dcs_read(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
3455 u8 *buf, int buflen)
3456{
3457 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
3458 int r;
3459
Archit Taneja9e7e9372012-08-14 12:29:22 +05303460 r = dsi_vc_dcs_send_read_request(dsidev, channel, dcs_cmd);
Archit Tanejab8509752011-08-30 15:48:23 +05303461 if (r)
3462 goto err;
3463
3464 r = dsi_vc_send_bta_sync(dssdev, channel);
3465 if (r)
3466 goto err;
3467
Archit Tanejab3b89c02011-08-30 16:07:39 +05303468 r = dsi_vc_read_rx_fifo(dsidev, channel, buf, buflen,
3469 DSS_DSI_CONTENT_DCS);
Archit Tanejab8509752011-08-30 15:48:23 +05303470 if (r < 0)
3471 goto err;
3472
3473 if (r != buflen) {
3474 r = -EIO;
3475 goto err;
3476 }
3477
3478 return 0;
3479err:
3480 DSSERR("dsi_vc_dcs_read(ch %d, cmd 0x%02x) failed\n", channel, dcs_cmd);
3481 return r;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003482}
3483EXPORT_SYMBOL(dsi_vc_dcs_read);
3484
Archit Tanejab3b89c02011-08-30 16:07:39 +05303485static int dsi_vc_generic_read(struct omap_dss_device *dssdev, int channel,
3486 u8 *reqdata, int reqlen, u8 *buf, int buflen)
3487{
3488 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
3489 int r;
3490
Archit Taneja9e7e9372012-08-14 12:29:22 +05303491 r = dsi_vc_generic_send_read_request(dsidev, channel, reqdata, reqlen);
Archit Tanejab3b89c02011-08-30 16:07:39 +05303492 if (r)
3493 return r;
3494
3495 r = dsi_vc_send_bta_sync(dssdev, channel);
3496 if (r)
3497 return r;
3498
3499 r = dsi_vc_read_rx_fifo(dsidev, channel, buf, buflen,
3500 DSS_DSI_CONTENT_GENERIC);
3501 if (r < 0)
3502 return r;
3503
3504 if (r != buflen) {
3505 r = -EIO;
3506 return r;
3507 }
3508
3509 return 0;
3510}
3511
3512int dsi_vc_generic_read_0(struct omap_dss_device *dssdev, int channel, u8 *buf,
3513 int buflen)
3514{
3515 int r;
3516
3517 r = dsi_vc_generic_read(dssdev, channel, NULL, 0, buf, buflen);
3518 if (r) {
3519 DSSERR("dsi_vc_generic_read_0(ch %d) failed\n", channel);
3520 return r;
3521 }
3522
3523 return 0;
3524}
3525EXPORT_SYMBOL(dsi_vc_generic_read_0);
3526
3527int dsi_vc_generic_read_1(struct omap_dss_device *dssdev, int channel, u8 param,
3528 u8 *buf, int buflen)
3529{
3530 int r;
3531
3532 r = dsi_vc_generic_read(dssdev, channel, &param, 1, buf, buflen);
3533 if (r) {
3534 DSSERR("dsi_vc_generic_read_1(ch %d) failed\n", channel);
3535 return r;
3536 }
3537
3538 return 0;
3539}
3540EXPORT_SYMBOL(dsi_vc_generic_read_1);
3541
3542int dsi_vc_generic_read_2(struct omap_dss_device *dssdev, int channel,
3543 u8 param1, u8 param2, u8 *buf, int buflen)
3544{
3545 int r;
3546 u8 reqdata[2];
3547
3548 reqdata[0] = param1;
3549 reqdata[1] = param2;
3550
3551 r = dsi_vc_generic_read(dssdev, channel, reqdata, 2, buf, buflen);
3552 if (r) {
3553 DSSERR("dsi_vc_generic_read_2(ch %d) failed\n", channel);
3554 return r;
3555 }
3556
3557 return 0;
3558}
3559EXPORT_SYMBOL(dsi_vc_generic_read_2);
3560
Archit Taneja1ffefe72011-05-12 17:26:24 +05303561int dsi_vc_set_max_rx_packet_size(struct omap_dss_device *dssdev, int channel,
3562 u16 len)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003563{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303564 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
3565
Archit Taneja7a7c48f2011-08-25 18:25:03 +05303566 return dsi_vc_send_short(dsidev, channel,
3567 MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE, len, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003568}
3569EXPORT_SYMBOL(dsi_vc_set_max_rx_packet_size);
3570
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303571static int dsi_enter_ulps(struct platform_device *dsidev)
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003572{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303573 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003574 DECLARE_COMPLETION_ONSTACK(completion);
Tomi Valkeinen522a0c22011-10-13 16:18:52 +03003575 int r, i;
3576 unsigned mask;
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003577
Chandrabhanu Mahapatra702d2672012-09-24 17:12:58 +05303578 DSSDBG("Entering ULPS");
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003579
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303580 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003581
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303582 WARN_ON(dsi->ulps_enabled);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003583
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303584 if (dsi->ulps_enabled)
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003585 return 0;
3586
Tomi Valkeinen6cc78aa2011-10-13 19:22:43 +03003587 /* DDR_CLK_ALWAYS_ON */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303588 if (REG_GET(dsidev, DSI_CLK_CTRL, 13, 13)) {
Tomi Valkeinen6cc78aa2011-10-13 19:22:43 +03003589 dsi_if_enable(dsidev, 0);
3590 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 13, 13);
3591 dsi_if_enable(dsidev, 1);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003592 }
3593
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303594 dsi_sync_vc(dsidev, 0);
3595 dsi_sync_vc(dsidev, 1);
3596 dsi_sync_vc(dsidev, 2);
3597 dsi_sync_vc(dsidev, 3);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003598
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303599 dsi_force_tx_stop_mode_io(dsidev);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003600
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303601 dsi_vc_enable(dsidev, 0, false);
3602 dsi_vc_enable(dsidev, 1, false);
3603 dsi_vc_enable(dsidev, 2, false);
3604 dsi_vc_enable(dsidev, 3, false);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003605
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303606 if (REG_GET(dsidev, DSI_COMPLEXIO_CFG2, 16, 16)) { /* HS_BUSY */
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003607 DSSERR("HS busy when enabling ULPS\n");
3608 return -EIO;
3609 }
3610
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303611 if (REG_GET(dsidev, DSI_COMPLEXIO_CFG2, 17, 17)) { /* LP_BUSY */
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003612 DSSERR("LP busy when enabling ULPS\n");
3613 return -EIO;
3614 }
3615
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303616 r = dsi_register_isr_cio(dsidev, dsi_completion_handler, &completion,
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003617 DSI_CIO_IRQ_ULPSACTIVENOT_ALL0);
3618 if (r)
3619 return r;
3620
Tomi Valkeinen522a0c22011-10-13 16:18:52 +03003621 mask = 0;
3622
3623 for (i = 0; i < dsi->num_lanes_supported; ++i) {
3624 if (dsi->lanes[i].function == DSI_LANE_UNUSED)
3625 continue;
3626 mask |= 1 << i;
3627 }
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003628 /* Assert TxRequestEsc for data lanes and TxUlpsClk for clk lane */
3629 /* LANEx_ULPS_SIG2 */
Tomi Valkeinen522a0c22011-10-13 16:18:52 +03003630 REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG2, mask, 9, 5);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003631
Tomi Valkeinena702c852011-10-12 10:10:21 +03003632 /* flush posted write and wait for SCP interface to finish the write */
3633 dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG2);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003634
3635 if (wait_for_completion_timeout(&completion,
3636 msecs_to_jiffies(1000)) == 0) {
3637 DSSERR("ULPS enable timeout\n");
3638 r = -EIO;
3639 goto err;
3640 }
3641
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303642 dsi_unregister_isr_cio(dsidev, dsi_completion_handler, &completion,
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003643 DSI_CIO_IRQ_ULPSACTIVENOT_ALL0);
3644
Tomi Valkeinen8ef0e612011-05-31 16:55:47 +03003645 /* Reset LANEx_ULPS_SIG2 */
Tomi Valkeinen522a0c22011-10-13 16:18:52 +03003646 REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG2, 0, 9, 5);
Tomi Valkeinen8ef0e612011-05-31 16:55:47 +03003647
Tomi Valkeinena702c852011-10-12 10:10:21 +03003648 /* flush posted write and wait for SCP interface to finish the write */
3649 dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG2);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003650
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303651 dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_ULPS);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003652
3653 dsi_if_enable(dsidev, false);
3654
3655 dsi->ulps_enabled = true;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303656
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003657 return 0;
3658
3659err:
3660 dsi_unregister_isr_cio(dsidev, dsi_completion_handler, &completion,
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303661 DSI_CIO_IRQ_ULPSACTIVENOT_ALL0);
3662 return r;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003663}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003664
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003665static void dsi_set_lp_rx_timeout(struct platform_device *dsidev,
3666 unsigned ticks, bool x4, bool x16)
3667{
3668 unsigned long fck;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003669 unsigned long total_ticks;
3670 u32 r;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303671
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003672 BUG_ON(ticks > 0x1fff);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303673
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003674 /* ticks in DSI_FCK */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003675 fck = dsi_fclk_rate(dsidev);
3676
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003677 r = dsi_read_reg(dsidev, DSI_TIMING2);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303678 r = FLD_MOD(r, 1, 15, 15); /* LP_RX_TO */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003679 r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* LP_RX_TO_X16 */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003680 r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* LP_RX_TO_X4 */
3681 r = FLD_MOD(r, ticks, 12, 0); /* LP_RX_COUNTER */
3682 dsi_write_reg(dsidev, DSI_TIMING2, r);
3683
3684 total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
3685
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003686 DSSDBG("LP_RX_TO %lu ticks (%#x%s%s) = %lu ns\n",
3687 total_ticks,
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303688 ticks, x4 ? " x4" : "", x16 ? " x16" : "",
3689 (total_ticks * 1000) / (fck / 1000 / 1000));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003690}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003691
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003692static void dsi_set_ta_timeout(struct platform_device *dsidev, unsigned ticks,
3693 bool x8, bool x16)
3694{
3695 unsigned long fck;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003696 unsigned long total_ticks;
3697 u32 r;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303698
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003699 BUG_ON(ticks > 0x1fff);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303700
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003701 /* ticks in DSI_FCK */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003702 fck = dsi_fclk_rate(dsidev);
3703
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003704 r = dsi_read_reg(dsidev, DSI_TIMING1);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303705 r = FLD_MOD(r, 1, 31, 31); /* TA_TO */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003706 r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* TA_TO_X16 */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003707 r = FLD_MOD(r, x8 ? 1 : 0, 29, 29); /* TA_TO_X8 */
3708 r = FLD_MOD(r, ticks, 28, 16); /* TA_TO_COUNTER */
3709 dsi_write_reg(dsidev, DSI_TIMING1, r);
3710
3711 total_ticks = ticks * (x16 ? 16 : 1) * (x8 ? 8 : 1);
3712
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003713 DSSDBG("TA_TO %lu ticks (%#x%s%s) = %lu ns\n",
3714 total_ticks,
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303715 ticks, x8 ? " x8" : "", x16 ? " x16" : "",
3716 (total_ticks * 1000) / (fck / 1000 / 1000));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003717}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003718
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003719static void dsi_set_stop_state_counter(struct platform_device *dsidev,
3720 unsigned ticks, bool x4, bool x16)
3721{
3722 unsigned long fck;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003723 unsigned long total_ticks;
3724 u32 r;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303725
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003726 BUG_ON(ticks > 0x1fff);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303727
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003728 /* ticks in DSI_FCK */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003729 fck = dsi_fclk_rate(dsidev);
3730
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003731 r = dsi_read_reg(dsidev, DSI_TIMING1);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303732 r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003733 r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* STOP_STATE_X16_IO */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003734 r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* STOP_STATE_X4_IO */
3735 r = FLD_MOD(r, ticks, 12, 0); /* STOP_STATE_COUNTER_IO */
3736 dsi_write_reg(dsidev, DSI_TIMING1, r);
3737
3738 total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
3739
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003740 DSSDBG("STOP_STATE_COUNTER %lu ticks (%#x%s%s) = %lu ns\n",
3741 total_ticks,
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303742 ticks, x4 ? " x4" : "", x16 ? " x16" : "",
3743 (total_ticks * 1000) / (fck / 1000 / 1000));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003744}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003745
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003746static void dsi_set_hs_tx_timeout(struct platform_device *dsidev,
3747 unsigned ticks, bool x4, bool x16)
3748{
3749 unsigned long fck;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003750 unsigned long total_ticks;
3751 u32 r;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303752
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003753 BUG_ON(ticks > 0x1fff);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303754
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003755 /* ticks in TxByteClkHS */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003756 fck = dsi_get_txbyteclkhs(dsidev);
3757
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003758 r = dsi_read_reg(dsidev, DSI_TIMING2);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303759 r = FLD_MOD(r, 1, 31, 31); /* HS_TX_TO */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003760 r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* HS_TX_TO_X16 */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003761 r = FLD_MOD(r, x4 ? 1 : 0, 29, 29); /* HS_TX_TO_X8 (4 really) */
3762 r = FLD_MOD(r, ticks, 28, 16); /* HS_TX_TO_COUNTER */
3763 dsi_write_reg(dsidev, DSI_TIMING2, r);
3764
3765 total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
3766
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003767 DSSDBG("HS_TX_TO %lu ticks (%#x%s%s) = %lu ns\n",
3768 total_ticks,
3769 ticks, x4 ? " x4" : "", x16 ? " x16" : "",
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303770 (total_ticks * 1000) / (fck / 1000 / 1000));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003771}
Archit Taneja8af6ff02011-09-05 16:48:27 +05303772
Archit Taneja9e7e9372012-08-14 12:29:22 +05303773static void dsi_config_vp_num_line_buffers(struct platform_device *dsidev)
Archit Taneja8af6ff02011-09-05 16:48:27 +05303774{
Archit Tanejadca2b152012-08-16 18:02:00 +05303775 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Taneja8af6ff02011-09-05 16:48:27 +05303776 int num_line_buffers;
3777
Archit Tanejadca2b152012-08-16 18:02:00 +05303778 if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
Archit Taneja02c39602012-08-10 15:01:33 +05303779 int bpp = dsi_get_pixel_size(dsi->pix_fmt);
Archit Taneja8af6ff02011-09-05 16:48:27 +05303780 unsigned line_buf_size = dsi_get_line_buf_size(dsidev);
Archit Tanejae67458a2012-08-13 14:17:30 +05303781 struct omap_video_timings *timings = &dsi->timings;
Archit Taneja8af6ff02011-09-05 16:48:27 +05303782 /*
3783 * Don't use line buffers if width is greater than the video
3784 * port's line buffer size
3785 */
3786 if (line_buf_size <= timings->x_res * bpp / 8)
3787 num_line_buffers = 0;
3788 else
3789 num_line_buffers = 2;
3790 } else {
3791 /* Use maximum number of line buffers in command mode */
3792 num_line_buffers = 2;
3793 }
3794
3795 /* LINE_BUFFER */
3796 REG_FLD_MOD(dsidev, DSI_CTRL, num_line_buffers, 13, 12);
3797}
3798
Archit Taneja9e7e9372012-08-14 12:29:22 +05303799static void dsi_config_vp_sync_events(struct platform_device *dsidev)
Archit Taneja8af6ff02011-09-05 16:48:27 +05303800{
Archit Taneja0b3ffe32012-08-13 22:13:39 +05303801 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
3802 bool vsync_end = dsi->vm_timings.vp_vsync_end;
3803 bool hsync_end = dsi->vm_timings.vp_hsync_end;
Archit Taneja8af6ff02011-09-05 16:48:27 +05303804 u32 r;
3805
3806 r = dsi_read_reg(dsidev, DSI_CTRL);
Archit Tanejabd5a7b12012-06-26 12:38:31 +05303807 r = FLD_MOD(r, 1, 9, 9); /* VP_DE_POL */
3808 r = FLD_MOD(r, 1, 10, 10); /* VP_HSYNC_POL */
3809 r = FLD_MOD(r, 1, 11, 11); /* VP_VSYNC_POL */
Archit Taneja8af6ff02011-09-05 16:48:27 +05303810 r = FLD_MOD(r, 1, 15, 15); /* VP_VSYNC_START */
3811 r = FLD_MOD(r, vsync_end, 16, 16); /* VP_VSYNC_END */
3812 r = FLD_MOD(r, 1, 17, 17); /* VP_HSYNC_START */
3813 r = FLD_MOD(r, hsync_end, 18, 18); /* VP_HSYNC_END */
3814 dsi_write_reg(dsidev, DSI_CTRL, r);
3815}
3816
Archit Taneja9e7e9372012-08-14 12:29:22 +05303817static void dsi_config_blanking_modes(struct platform_device *dsidev)
Archit Taneja8af6ff02011-09-05 16:48:27 +05303818{
Archit Taneja0b3ffe32012-08-13 22:13:39 +05303819 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
3820 int blanking_mode = dsi->vm_timings.blanking_mode;
3821 int hfp_blanking_mode = dsi->vm_timings.hfp_blanking_mode;
3822 int hbp_blanking_mode = dsi->vm_timings.hbp_blanking_mode;
3823 int hsa_blanking_mode = dsi->vm_timings.hsa_blanking_mode;
Archit Taneja8af6ff02011-09-05 16:48:27 +05303824 u32 r;
3825
3826 /*
3827 * 0 = TX FIFO packets sent or LPS in corresponding blanking periods
3828 * 1 = Long blanking packets are sent in corresponding blanking periods
3829 */
3830 r = dsi_read_reg(dsidev, DSI_CTRL);
3831 r = FLD_MOD(r, blanking_mode, 20, 20); /* BLANKING_MODE */
3832 r = FLD_MOD(r, hfp_blanking_mode, 21, 21); /* HFP_BLANKING */
3833 r = FLD_MOD(r, hbp_blanking_mode, 22, 22); /* HBP_BLANKING */
3834 r = FLD_MOD(r, hsa_blanking_mode, 23, 23); /* HSA_BLANKING */
3835 dsi_write_reg(dsidev, DSI_CTRL, r);
3836}
3837
Archit Taneja6f28c292012-05-15 11:32:18 +05303838/*
3839 * According to section 'HS Command Mode Interleaving' in OMAP TRM, Scenario 3
3840 * results in maximum transition time for data and clock lanes to enter and
3841 * exit HS mode. Hence, this is the scenario where the least amount of command
3842 * mode data can be interleaved. We program the minimum amount of TXBYTECLKHS
3843 * clock cycles that can be used to interleave command mode data in HS so that
3844 * all scenarios are satisfied.
3845 */
3846static int dsi_compute_interleave_hs(int blank, bool ddr_alwon, int enter_hs,
3847 int exit_hs, int exiths_clk, int ddr_pre, int ddr_post)
3848{
3849 int transition;
3850
3851 /*
3852 * If DDR_CLK_ALWAYS_ON is set, we need to consider HS mode transition
3853 * time of data lanes only, if it isn't set, we need to consider HS
3854 * transition time of both data and clock lanes. HS transition time
3855 * of Scenario 3 is considered.
3856 */
3857 if (ddr_alwon) {
3858 transition = enter_hs + exit_hs + max(enter_hs, 2) + 1;
3859 } else {
3860 int trans1, trans2;
3861 trans1 = ddr_pre + enter_hs + exit_hs + max(enter_hs, 2) + 1;
3862 trans2 = ddr_pre + enter_hs + exiths_clk + ddr_post + ddr_pre +
3863 enter_hs + 1;
3864 transition = max(trans1, trans2);
3865 }
3866
3867 return blank > transition ? blank - transition : 0;
3868}
3869
3870/*
3871 * According to section 'LP Command Mode Interleaving' in OMAP TRM, Scenario 1
3872 * results in maximum transition time for data lanes to enter and exit LP mode.
3873 * Hence, this is the scenario where the least amount of command mode data can
3874 * be interleaved. We program the minimum amount of bytes that can be
3875 * interleaved in LP so that all scenarios are satisfied.
3876 */
3877static int dsi_compute_interleave_lp(int blank, int enter_hs, int exit_hs,
3878 int lp_clk_div, int tdsi_fclk)
3879{
3880 int trans_lp; /* time required for a LP transition, in TXBYTECLKHS */
3881 int tlp_avail; /* time left for interleaving commands, in CLKIN4DDR */
3882 int ttxclkesc; /* period of LP transmit escape clock, in CLKIN4DDR */
3883 int thsbyte_clk = 16; /* Period of TXBYTECLKHS clock, in CLKIN4DDR */
3884 int lp_inter; /* cmd mode data that can be interleaved, in bytes */
3885
3886 /* maximum LP transition time according to Scenario 1 */
3887 trans_lp = exit_hs + max(enter_hs, 2) + 1;
3888
3889 /* CLKIN4DDR = 16 * TXBYTECLKHS */
3890 tlp_avail = thsbyte_clk * (blank - trans_lp);
3891
Archit Taneja2e063c32012-06-04 13:36:34 +05303892 ttxclkesc = tdsi_fclk * lp_clk_div;
Archit Taneja6f28c292012-05-15 11:32:18 +05303893
3894 lp_inter = ((tlp_avail - 8 * thsbyte_clk - 5 * tdsi_fclk) / ttxclkesc -
3895 26) / 16;
3896
3897 return max(lp_inter, 0);
3898}
3899
3900static void dsi_config_cmd_mode_interleaving(struct omap_dss_device *dssdev)
3901{
3902 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
3903 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
3904 int blanking_mode;
3905 int hfp_blanking_mode, hbp_blanking_mode, hsa_blanking_mode;
3906 int hsa, hfp, hbp, width_bytes, bllp, lp_clk_div;
3907 int ddr_clk_pre, ddr_clk_post, enter_hs_mode_lat, exit_hs_mode_lat;
3908 int tclk_trail, ths_exit, exiths_clk;
3909 bool ddr_alwon;
Archit Tanejae67458a2012-08-13 14:17:30 +05303910 struct omap_video_timings *timings = &dsi->timings;
Archit Taneja02c39602012-08-10 15:01:33 +05303911 int bpp = dsi_get_pixel_size(dsi->pix_fmt);
Archit Taneja6f28c292012-05-15 11:32:18 +05303912 int ndl = dsi->num_lanes_used - 1;
3913 int dsi_fclk_hsdiv = dssdev->clocks.dsi.regm_dsi + 1;
3914 int hsa_interleave_hs = 0, hsa_interleave_lp = 0;
3915 int hfp_interleave_hs = 0, hfp_interleave_lp = 0;
3916 int hbp_interleave_hs = 0, hbp_interleave_lp = 0;
3917 int bl_interleave_hs = 0, bl_interleave_lp = 0;
3918 u32 r;
3919
3920 r = dsi_read_reg(dsidev, DSI_CTRL);
3921 blanking_mode = FLD_GET(r, 20, 20);
3922 hfp_blanking_mode = FLD_GET(r, 21, 21);
3923 hbp_blanking_mode = FLD_GET(r, 22, 22);
3924 hsa_blanking_mode = FLD_GET(r, 23, 23);
3925
3926 r = dsi_read_reg(dsidev, DSI_VM_TIMING1);
3927 hbp = FLD_GET(r, 11, 0);
3928 hfp = FLD_GET(r, 23, 12);
3929 hsa = FLD_GET(r, 31, 24);
3930
3931 r = dsi_read_reg(dsidev, DSI_CLK_TIMING);
3932 ddr_clk_post = FLD_GET(r, 7, 0);
3933 ddr_clk_pre = FLD_GET(r, 15, 8);
3934
3935 r = dsi_read_reg(dsidev, DSI_VM_TIMING7);
3936 exit_hs_mode_lat = FLD_GET(r, 15, 0);
3937 enter_hs_mode_lat = FLD_GET(r, 31, 16);
3938
3939 r = dsi_read_reg(dsidev, DSI_CLK_CTRL);
3940 lp_clk_div = FLD_GET(r, 12, 0);
3941 ddr_alwon = FLD_GET(r, 13, 13);
3942
3943 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0);
3944 ths_exit = FLD_GET(r, 7, 0);
3945
3946 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1);
3947 tclk_trail = FLD_GET(r, 15, 8);
3948
3949 exiths_clk = ths_exit + tclk_trail;
3950
3951 width_bytes = DIV_ROUND_UP(timings->x_res * bpp, 8);
3952 bllp = hbp + hfp + hsa + DIV_ROUND_UP(width_bytes + 6, ndl);
3953
3954 if (!hsa_blanking_mode) {
3955 hsa_interleave_hs = dsi_compute_interleave_hs(hsa, ddr_alwon,
3956 enter_hs_mode_lat, exit_hs_mode_lat,
3957 exiths_clk, ddr_clk_pre, ddr_clk_post);
3958 hsa_interleave_lp = dsi_compute_interleave_lp(hsa,
3959 enter_hs_mode_lat, exit_hs_mode_lat,
3960 lp_clk_div, dsi_fclk_hsdiv);
3961 }
3962
3963 if (!hfp_blanking_mode) {
3964 hfp_interleave_hs = dsi_compute_interleave_hs(hfp, ddr_alwon,
3965 enter_hs_mode_lat, exit_hs_mode_lat,
3966 exiths_clk, ddr_clk_pre, ddr_clk_post);
3967 hfp_interleave_lp = dsi_compute_interleave_lp(hfp,
3968 enter_hs_mode_lat, exit_hs_mode_lat,
3969 lp_clk_div, dsi_fclk_hsdiv);
3970 }
3971
3972 if (!hbp_blanking_mode) {
3973 hbp_interleave_hs = dsi_compute_interleave_hs(hbp, ddr_alwon,
3974 enter_hs_mode_lat, exit_hs_mode_lat,
3975 exiths_clk, ddr_clk_pre, ddr_clk_post);
3976
3977 hbp_interleave_lp = dsi_compute_interleave_lp(hbp,
3978 enter_hs_mode_lat, exit_hs_mode_lat,
3979 lp_clk_div, dsi_fclk_hsdiv);
3980 }
3981
3982 if (!blanking_mode) {
3983 bl_interleave_hs = dsi_compute_interleave_hs(bllp, ddr_alwon,
3984 enter_hs_mode_lat, exit_hs_mode_lat,
3985 exiths_clk, ddr_clk_pre, ddr_clk_post);
3986
3987 bl_interleave_lp = dsi_compute_interleave_lp(bllp,
3988 enter_hs_mode_lat, exit_hs_mode_lat,
3989 lp_clk_div, dsi_fclk_hsdiv);
3990 }
3991
3992 DSSDBG("DSI HS interleaving(TXBYTECLKHS) HSA %d, HFP %d, HBP %d, BLLP %d\n",
3993 hsa_interleave_hs, hfp_interleave_hs, hbp_interleave_hs,
3994 bl_interleave_hs);
3995
3996 DSSDBG("DSI LP interleaving(bytes) HSA %d, HFP %d, HBP %d, BLLP %d\n",
3997 hsa_interleave_lp, hfp_interleave_lp, hbp_interleave_lp,
3998 bl_interleave_lp);
3999
4000 r = dsi_read_reg(dsidev, DSI_VM_TIMING4);
4001 r = FLD_MOD(r, hsa_interleave_hs, 23, 16);
4002 r = FLD_MOD(r, hfp_interleave_hs, 15, 8);
4003 r = FLD_MOD(r, hbp_interleave_hs, 7, 0);
4004 dsi_write_reg(dsidev, DSI_VM_TIMING4, r);
4005
4006 r = dsi_read_reg(dsidev, DSI_VM_TIMING5);
4007 r = FLD_MOD(r, hsa_interleave_lp, 23, 16);
4008 r = FLD_MOD(r, hfp_interleave_lp, 15, 8);
4009 r = FLD_MOD(r, hbp_interleave_lp, 7, 0);
4010 dsi_write_reg(dsidev, DSI_VM_TIMING5, r);
4011
4012 r = dsi_read_reg(dsidev, DSI_VM_TIMING6);
4013 r = FLD_MOD(r, bl_interleave_hs, 31, 15);
4014 r = FLD_MOD(r, bl_interleave_lp, 16, 0);
4015 dsi_write_reg(dsidev, DSI_VM_TIMING6, r);
4016}
4017
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004018static int dsi_proto_config(struct omap_dss_device *dssdev)
4019{
4020 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Taneja02c39602012-08-10 15:01:33 +05304021 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004022 u32 r;
4023 int buswidth = 0;
4024
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304025 dsi_config_tx_fifo(dsidev, DSI_FIFO_SIZE_32,
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02004026 DSI_FIFO_SIZE_32,
4027 DSI_FIFO_SIZE_32,
4028 DSI_FIFO_SIZE_32);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004029
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304030 dsi_config_rx_fifo(dsidev, DSI_FIFO_SIZE_32,
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02004031 DSI_FIFO_SIZE_32,
4032 DSI_FIFO_SIZE_32,
4033 DSI_FIFO_SIZE_32);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004034
4035 /* XXX what values for the timeouts? */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304036 dsi_set_stop_state_counter(dsidev, 0x1000, false, false);
4037 dsi_set_ta_timeout(dsidev, 0x1fff, true, true);
4038 dsi_set_lp_rx_timeout(dsidev, 0x1fff, true, true);
4039 dsi_set_hs_tx_timeout(dsidev, 0x1fff, true, true);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004040
Archit Taneja02c39602012-08-10 15:01:33 +05304041 switch (dsi_get_pixel_size(dsi->pix_fmt)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004042 case 16:
4043 buswidth = 0;
4044 break;
4045 case 18:
4046 buswidth = 1;
4047 break;
4048 case 24:
4049 buswidth = 2;
4050 break;
4051 default:
4052 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03004053 return -EINVAL;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004054 }
4055
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304056 r = dsi_read_reg(dsidev, DSI_CTRL);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004057 r = FLD_MOD(r, 1, 1, 1); /* CS_RX_EN */
4058 r = FLD_MOD(r, 1, 2, 2); /* ECC_RX_EN */
4059 r = FLD_MOD(r, 1, 3, 3); /* TX_FIFO_ARBITRATION */
4060 r = FLD_MOD(r, 1, 4, 4); /* VP_CLK_RATIO, always 1, see errata*/
4061 r = FLD_MOD(r, buswidth, 7, 6); /* VP_DATA_BUS_WIDTH */
4062 r = FLD_MOD(r, 0, 8, 8); /* VP_CLK_POL */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004063 r = FLD_MOD(r, 1, 14, 14); /* TRIGGER_RESET_MODE */
4064 r = FLD_MOD(r, 1, 19, 19); /* EOT_ENABLE */
Archit Taneja9613c022011-03-22 06:33:36 -05004065 if (!dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC)) {
4066 r = FLD_MOD(r, 1, 24, 24); /* DCS_CMD_ENABLE */
4067 /* DCS_CMD_CODE, 1=start, 0=continue */
4068 r = FLD_MOD(r, 0, 25, 25);
4069 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004070
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304071 dsi_write_reg(dsidev, DSI_CTRL, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004072
Archit Taneja9e7e9372012-08-14 12:29:22 +05304073 dsi_config_vp_num_line_buffers(dsidev);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304074
Archit Tanejadca2b152012-08-16 18:02:00 +05304075 if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
Archit Taneja9e7e9372012-08-14 12:29:22 +05304076 dsi_config_vp_sync_events(dsidev);
4077 dsi_config_blanking_modes(dsidev);
Archit Taneja6f28c292012-05-15 11:32:18 +05304078 dsi_config_cmd_mode_interleaving(dssdev);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304079 }
4080
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304081 dsi_vc_initial_config(dsidev, 0);
4082 dsi_vc_initial_config(dsidev, 1);
4083 dsi_vc_initial_config(dsidev, 2);
4084 dsi_vc_initial_config(dsidev, 3);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004085
4086 return 0;
4087}
4088
Archit Taneja9e7e9372012-08-14 12:29:22 +05304089static void dsi_proto_timings(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004090{
Tomi Valkeinendb186442011-10-13 16:12:29 +03004091 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004092 unsigned tlpx, tclk_zero, tclk_prepare, tclk_trail;
4093 unsigned tclk_pre, tclk_post;
4094 unsigned ths_prepare, ths_prepare_ths_zero, ths_zero;
4095 unsigned ths_trail, ths_exit;
4096 unsigned ddr_clk_pre, ddr_clk_post;
4097 unsigned enter_hs_mode_lat, exit_hs_mode_lat;
4098 unsigned ths_eot;
Tomi Valkeinendb186442011-10-13 16:12:29 +03004099 int ndl = dsi->num_lanes_used - 1;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004100 u32 r;
4101
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304102 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004103 ths_prepare = FLD_GET(r, 31, 24);
4104 ths_prepare_ths_zero = FLD_GET(r, 23, 16);
4105 ths_zero = ths_prepare_ths_zero - ths_prepare;
4106 ths_trail = FLD_GET(r, 15, 8);
4107 ths_exit = FLD_GET(r, 7, 0);
4108
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304109 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1);
Tomi Valkeinene84dc1c2012-09-24 09:34:52 +03004110 tlpx = FLD_GET(r, 20, 16) * 2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004111 tclk_trail = FLD_GET(r, 15, 8);
4112 tclk_zero = FLD_GET(r, 7, 0);
4113
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304114 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG2);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004115 tclk_prepare = FLD_GET(r, 7, 0);
4116
4117 /* min 8*UI */
4118 tclk_pre = 20;
4119 /* min 60ns + 52*UI */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304120 tclk_post = ns2ddr(dsidev, 60) + 26;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004121
Archit Taneja8af6ff02011-09-05 16:48:27 +05304122 ths_eot = DIV_ROUND_UP(4, ndl);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004123
4124 ddr_clk_pre = DIV_ROUND_UP(tclk_pre + tlpx + tclk_zero + tclk_prepare,
4125 4);
4126 ddr_clk_post = DIV_ROUND_UP(tclk_post + ths_trail, 4) + ths_eot;
4127
4128 BUG_ON(ddr_clk_pre == 0 || ddr_clk_pre > 255);
4129 BUG_ON(ddr_clk_post == 0 || ddr_clk_post > 255);
4130
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304131 r = dsi_read_reg(dsidev, DSI_CLK_TIMING);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004132 r = FLD_MOD(r, ddr_clk_pre, 15, 8);
4133 r = FLD_MOD(r, ddr_clk_post, 7, 0);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304134 dsi_write_reg(dsidev, DSI_CLK_TIMING, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004135
4136 DSSDBG("ddr_clk_pre %u, ddr_clk_post %u\n",
4137 ddr_clk_pre,
4138 ddr_clk_post);
4139
4140 enter_hs_mode_lat = 1 + DIV_ROUND_UP(tlpx, 4) +
4141 DIV_ROUND_UP(ths_prepare, 4) +
4142 DIV_ROUND_UP(ths_zero + 3, 4);
4143
4144 exit_hs_mode_lat = DIV_ROUND_UP(ths_trail + ths_exit, 4) + 1 + ths_eot;
4145
4146 r = FLD_VAL(enter_hs_mode_lat, 31, 16) |
4147 FLD_VAL(exit_hs_mode_lat, 15, 0);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304148 dsi_write_reg(dsidev, DSI_VM_TIMING7, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004149
4150 DSSDBG("enter_hs_mode_lat %u, exit_hs_mode_lat %u\n",
4151 enter_hs_mode_lat, exit_hs_mode_lat);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304152
Archit Tanejadca2b152012-08-16 18:02:00 +05304153 if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
Archit Taneja8af6ff02011-09-05 16:48:27 +05304154 /* TODO: Implement a video mode check_timings function */
Archit Taneja0b3ffe32012-08-13 22:13:39 +05304155 int hsa = dsi->vm_timings.hsa;
4156 int hfp = dsi->vm_timings.hfp;
4157 int hbp = dsi->vm_timings.hbp;
4158 int vsa = dsi->vm_timings.vsa;
4159 int vfp = dsi->vm_timings.vfp;
4160 int vbp = dsi->vm_timings.vbp;
4161 int window_sync = dsi->vm_timings.window_sync;
4162 bool hsync_end = dsi->vm_timings.vp_hsync_end;
Archit Tanejae67458a2012-08-13 14:17:30 +05304163 struct omap_video_timings *timings = &dsi->timings;
Archit Taneja02c39602012-08-10 15:01:33 +05304164 int bpp = dsi_get_pixel_size(dsi->pix_fmt);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304165 int tl, t_he, width_bytes;
4166
4167 t_he = hsync_end ?
4168 ((hsa == 0 && ndl == 3) ? 1 : DIV_ROUND_UP(4, ndl)) : 0;
4169
4170 width_bytes = DIV_ROUND_UP(timings->x_res * bpp, 8);
4171
4172 /* TL = t_HS + HSA + t_HE + HFP + ceil((WC + 6) / NDL) + HBP */
4173 tl = DIV_ROUND_UP(4, ndl) + (hsync_end ? hsa : 0) + t_he + hfp +
4174 DIV_ROUND_UP(width_bytes + 6, ndl) + hbp;
4175
4176 DSSDBG("HBP: %d, HFP: %d, HSA: %d, TL: %d TXBYTECLKHS\n", hbp,
4177 hfp, hsync_end ? hsa : 0, tl);
4178 DSSDBG("VBP: %d, VFP: %d, VSA: %d, VACT: %d lines\n", vbp, vfp,
4179 vsa, timings->y_res);
4180
4181 r = dsi_read_reg(dsidev, DSI_VM_TIMING1);
4182 r = FLD_MOD(r, hbp, 11, 0); /* HBP */
4183 r = FLD_MOD(r, hfp, 23, 12); /* HFP */
4184 r = FLD_MOD(r, hsync_end ? hsa : 0, 31, 24); /* HSA */
4185 dsi_write_reg(dsidev, DSI_VM_TIMING1, r);
4186
4187 r = dsi_read_reg(dsidev, DSI_VM_TIMING2);
4188 r = FLD_MOD(r, vbp, 7, 0); /* VBP */
4189 r = FLD_MOD(r, vfp, 15, 8); /* VFP */
4190 r = FLD_MOD(r, vsa, 23, 16); /* VSA */
4191 r = FLD_MOD(r, window_sync, 27, 24); /* WINDOW_SYNC */
4192 dsi_write_reg(dsidev, DSI_VM_TIMING2, r);
4193
4194 r = dsi_read_reg(dsidev, DSI_VM_TIMING3);
4195 r = FLD_MOD(r, timings->y_res, 14, 0); /* VACT */
4196 r = FLD_MOD(r, tl, 31, 16); /* TL */
4197 dsi_write_reg(dsidev, DSI_VM_TIMING3, r);
4198 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004199}
4200
Tomi Valkeinene4a9e942012-03-28 15:58:56 +03004201int omapdss_dsi_configure_pins(struct omap_dss_device *dssdev,
4202 const struct omap_dsi_pin_config *pin_cfg)
4203{
4204 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4205 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4206 int num_pins;
4207 const int *pins;
4208 struct dsi_lane_config lanes[DSI_MAX_NR_LANES];
4209 int num_lanes;
4210 int i;
4211
4212 static const enum dsi_lane_function functions[] = {
4213 DSI_LANE_CLK,
4214 DSI_LANE_DATA1,
4215 DSI_LANE_DATA2,
4216 DSI_LANE_DATA3,
4217 DSI_LANE_DATA4,
4218 };
4219
4220 num_pins = pin_cfg->num_pins;
4221 pins = pin_cfg->pins;
4222
4223 if (num_pins < 4 || num_pins > dsi->num_lanes_supported * 2
4224 || num_pins % 2 != 0)
4225 return -EINVAL;
4226
4227 for (i = 0; i < DSI_MAX_NR_LANES; ++i)
4228 lanes[i].function = DSI_LANE_UNUSED;
4229
4230 num_lanes = 0;
4231
4232 for (i = 0; i < num_pins; i += 2) {
4233 u8 lane, pol;
4234 int dx, dy;
4235
4236 dx = pins[i];
4237 dy = pins[i + 1];
4238
4239 if (dx < 0 || dx >= dsi->num_lanes_supported * 2)
4240 return -EINVAL;
4241
4242 if (dy < 0 || dy >= dsi->num_lanes_supported * 2)
4243 return -EINVAL;
4244
4245 if (dx & 1) {
4246 if (dy != dx - 1)
4247 return -EINVAL;
4248 pol = 1;
4249 } else {
4250 if (dy != dx + 1)
4251 return -EINVAL;
4252 pol = 0;
4253 }
4254
4255 lane = dx / 2;
4256
4257 lanes[lane].function = functions[i / 2];
4258 lanes[lane].polarity = pol;
4259 num_lanes++;
4260 }
4261
4262 memcpy(dsi->lanes, lanes, sizeof(dsi->lanes));
4263 dsi->num_lanes_used = num_lanes;
4264
4265 return 0;
4266}
4267EXPORT_SYMBOL(omapdss_dsi_configure_pins);
4268
Tomi Valkeinenee144e62012-08-10 16:50:51 +03004269int omapdss_dsi_set_clocks(struct omap_dss_device *dssdev,
4270 unsigned long ddr_clk, unsigned long lp_clk)
4271{
4272 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4273 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4274 struct dsi_clock_info cinfo;
4275 struct dispc_clock_info dispc_cinfo;
4276 unsigned lp_clk_div;
4277 unsigned long dsi_fclk;
4278 int bpp = dsi_get_pixel_size(dssdev->panel.dsi_pix_fmt);
4279 unsigned long pck;
4280 int r;
4281
Chandrabhanu Mahapatra702d2672012-09-24 17:12:58 +05304282 DSSDBG("Setting DSI clocks: ddr_clk %lu, lp_clk %lu", ddr_clk, lp_clk);
Tomi Valkeinenee144e62012-08-10 16:50:51 +03004283
4284 mutex_lock(&dsi->lock);
4285
Tomi Valkeinend66b1582012-09-24 15:15:06 +03004286 /* Calculate PLL output clock */
4287 r = dsi_pll_calc_ddrfreq(dsidev, ddr_clk * 4, &cinfo);
Tomi Valkeinenee144e62012-08-10 16:50:51 +03004288 if (r)
4289 goto err;
4290
Tomi Valkeinend66b1582012-09-24 15:15:06 +03004291 /* Calculate PLL's DSI clock */
4292 dsi_pll_calc_dsi_fck(dsidev, &cinfo);
4293
4294 /* Calculate PLL's DISPC clock and pck & lck divs */
4295 pck = cinfo.clkin4ddr / 16 * (dsi->num_lanes_used - 1) * 8 / bpp;
4296 DSSDBG("finding dispc dividers for pck %lu\n", pck);
4297 r = dsi_pll_calc_dispc_fck(dsidev, pck, &cinfo, &dispc_cinfo);
4298 if (r)
4299 goto err;
4300
4301 /* Calculate LP clock */
4302 dsi_fclk = cinfo.dsi_pll_hsdiv_dsi_clk;
4303 lp_clk_div = DIV_ROUND_UP(dsi_fclk, lp_clk * 2);
4304
Tomi Valkeinenee144e62012-08-10 16:50:51 +03004305 dssdev->clocks.dsi.regn = cinfo.regn;
4306 dssdev->clocks.dsi.regm = cinfo.regm;
4307 dssdev->clocks.dsi.regm_dispc = cinfo.regm_dispc;
4308 dssdev->clocks.dsi.regm_dsi = cinfo.regm_dsi;
4309
Tomi Valkeinenee144e62012-08-10 16:50:51 +03004310 dssdev->clocks.dsi.lp_clk_div = lp_clk_div;
4311
Tomi Valkeinenee144e62012-08-10 16:50:51 +03004312 dssdev->clocks.dispc.channel.lck_div = dispc_cinfo.lck_div;
4313 dssdev->clocks.dispc.channel.pck_div = dispc_cinfo.pck_div;
4314
Tomi Valkeinenee144e62012-08-10 16:50:51 +03004315 dssdev->clocks.dispc.dispc_fclk_src = OMAP_DSS_CLK_SRC_FCK;
4316
4317 dssdev->clocks.dispc.channel.lcd_clk_src =
4318 dsi->module_id == 0 ?
4319 OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC :
4320 OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC;
4321
4322 dssdev->clocks.dsi.dsi_fclk_src =
4323 dsi->module_id == 0 ?
4324 OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI :
4325 OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DSI;
4326
4327 mutex_unlock(&dsi->lock);
4328 return 0;
4329err:
4330 mutex_unlock(&dsi->lock);
4331 return r;
4332}
4333EXPORT_SYMBOL(omapdss_dsi_set_clocks);
4334
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004335int dsi_enable_video_output(struct omap_dss_device *dssdev, int channel)
Archit Taneja8af6ff02011-09-05 16:48:27 +05304336{
4337 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejae67458a2012-08-13 14:17:30 +05304338 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejaeea83402012-09-04 11:42:36 +05304339 struct omap_overlay_manager *mgr = dssdev->output->manager;
Archit Taneja02c39602012-08-10 15:01:33 +05304340 int bpp = dsi_get_pixel_size(dsi->pix_fmt);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304341 u8 data_type;
4342 u16 word_count;
Tomi Valkeinen33ca2372011-11-21 13:42:58 +02004343 int r;
Archit Taneja8af6ff02011-09-05 16:48:27 +05304344
Archit Tanejadca2b152012-08-16 18:02:00 +05304345 if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
Archit Taneja02c39602012-08-10 15:01:33 +05304346 switch (dsi->pix_fmt) {
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004347 case OMAP_DSS_DSI_FMT_RGB888:
4348 data_type = MIPI_DSI_PACKED_PIXEL_STREAM_24;
4349 break;
4350 case OMAP_DSS_DSI_FMT_RGB666:
4351 data_type = MIPI_DSI_PIXEL_STREAM_3BYTE_18;
4352 break;
4353 case OMAP_DSS_DSI_FMT_RGB666_PACKED:
4354 data_type = MIPI_DSI_PACKED_PIXEL_STREAM_18;
4355 break;
4356 case OMAP_DSS_DSI_FMT_RGB565:
4357 data_type = MIPI_DSI_PACKED_PIXEL_STREAM_16;
4358 break;
4359 default:
4360 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03004361 return -EINVAL;
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004362 };
Archit Taneja8af6ff02011-09-05 16:48:27 +05304363
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004364 dsi_if_enable(dsidev, false);
4365 dsi_vc_enable(dsidev, channel, false);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304366
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004367 /* MODE, 1 = video mode */
4368 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 1, 4, 4);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304369
Archit Tanejae67458a2012-08-13 14:17:30 +05304370 word_count = DIV_ROUND_UP(dsi->timings.x_res * bpp, 8);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304371
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004372 dsi_vc_write_long_header(dsidev, channel, data_type,
4373 word_count, 0);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304374
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004375 dsi_vc_enable(dsidev, channel, true);
4376 dsi_if_enable(dsidev, true);
4377 }
Archit Taneja8af6ff02011-09-05 16:48:27 +05304378
Archit Tanejaeea83402012-09-04 11:42:36 +05304379 r = dss_mgr_enable(mgr);
Tomi Valkeinen33ca2372011-11-21 13:42:58 +02004380 if (r) {
Archit Tanejadca2b152012-08-16 18:02:00 +05304381 if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
Tomi Valkeinen33ca2372011-11-21 13:42:58 +02004382 dsi_if_enable(dsidev, false);
4383 dsi_vc_enable(dsidev, channel, false);
4384 }
4385
4386 return r;
4387 }
Archit Taneja8af6ff02011-09-05 16:48:27 +05304388
4389 return 0;
4390}
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004391EXPORT_SYMBOL(dsi_enable_video_output);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304392
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004393void dsi_disable_video_output(struct omap_dss_device *dssdev, int channel)
Archit Taneja8af6ff02011-09-05 16:48:27 +05304394{
4395 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejadca2b152012-08-16 18:02:00 +05304396 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejaeea83402012-09-04 11:42:36 +05304397 struct omap_overlay_manager *mgr = dssdev->output->manager;
Archit Taneja8af6ff02011-09-05 16:48:27 +05304398
Archit Tanejadca2b152012-08-16 18:02:00 +05304399 if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004400 dsi_if_enable(dsidev, false);
4401 dsi_vc_enable(dsidev, channel, false);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304402
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004403 /* MODE, 0 = command mode */
4404 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 0, 4, 4);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304405
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004406 dsi_vc_enable(dsidev, channel, true);
4407 dsi_if_enable(dsidev, true);
4408 }
Archit Taneja8af6ff02011-09-05 16:48:27 +05304409
Archit Tanejaeea83402012-09-04 11:42:36 +05304410 dss_mgr_disable(mgr);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304411}
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004412EXPORT_SYMBOL(dsi_disable_video_output);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304413
Archit Taneja55cd63a2012-08-09 15:41:13 +05304414static void dsi_update_screen_dispc(struct omap_dss_device *dssdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004415{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304416 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304417 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejaeea83402012-09-04 11:42:36 +05304418 struct omap_overlay_manager *mgr = dssdev->output->manager;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004419 unsigned bytespp;
4420 unsigned bytespl;
4421 unsigned bytespf;
4422 unsigned total_len;
4423 unsigned packet_payload;
4424 unsigned packet_len;
4425 u32 l;
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03004426 int r;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304427 const unsigned channel = dsi->update_channel;
Archit Taneja0c65622b2011-05-16 15:17:09 +05304428 const unsigned line_buf_size = dsi_get_line_buf_size(dsidev);
Archit Taneja55cd63a2012-08-09 15:41:13 +05304429 u16 w = dsi->timings.x_res;
4430 u16 h = dsi->timings.y_res;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004431
Tomi Valkeinen5476e742011-11-03 16:34:20 +02004432 DSSDBG("dsi_update_screen_dispc(%dx%d)\n", w, h);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004433
Archit Tanejad6049142011-08-22 11:58:08 +05304434 dsi_vc_config_source(dsidev, channel, DSI_VC_SOURCE_VP);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004435
Archit Taneja02c39602012-08-10 15:01:33 +05304436 bytespp = dsi_get_pixel_size(dsi->pix_fmt) / 8;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004437 bytespl = w * bytespp;
4438 bytespf = bytespl * h;
4439
4440 /* NOTE: packet_payload has to be equal to N * bytespl, where N is
4441 * number of lines in a packet. See errata about VP_CLK_RATIO */
4442
4443 if (bytespf < line_buf_size)
4444 packet_payload = bytespf;
4445 else
4446 packet_payload = (line_buf_size) / bytespl * bytespl;
4447
4448 packet_len = packet_payload + 1; /* 1 byte for DCS cmd */
4449 total_len = (bytespf / packet_payload) * packet_len;
4450
4451 if (bytespf % packet_payload)
4452 total_len += (bytespf % packet_payload) + 1;
4453
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004454 l = FLD_VAL(total_len, 23, 0); /* TE_SIZE */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304455 dsi_write_reg(dsidev, DSI_VC_TE(channel), l);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004456
Archit Taneja7a7c48f2011-08-25 18:25:03 +05304457 dsi_vc_write_long_header(dsidev, channel, MIPI_DSI_DCS_LONG_WRITE,
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304458 packet_len, 0);
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 l = FLD_MOD(l, 1, 30, 30); /* TE_EN */
4462 else
4463 l = FLD_MOD(l, 1, 31, 31); /* TE_START */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304464 dsi_write_reg(dsidev, DSI_VC_TE(channel), l);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004465
4466 /* We put SIDLEMODE to no-idle for the duration of the transfer,
4467 * because DSS interrupts are not capable of waking up the CPU and the
4468 * framedone interrupt could be delayed for quite a long time. I think
4469 * the same goes for any DSS interrupts, but for some reason I have not
4470 * seen the problem anywhere else than here.
4471 */
4472 dispc_disable_sidle();
4473
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304474 dsi_perf_mark_start(dsidev);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004475
Archit Taneja49dbf582011-05-16 15:17:07 +05304476 r = schedule_delayed_work(&dsi->framedone_timeout_work,
4477 msecs_to_jiffies(250));
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03004478 BUG_ON(r == 0);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004479
Archit Tanejaeea83402012-09-04 11:42:36 +05304480 dss_mgr_set_timings(mgr, &dsi->timings);
Archit Taneja55cd63a2012-08-09 15:41:13 +05304481
Archit Tanejaeea83402012-09-04 11:42:36 +05304482 dss_mgr_start_update(mgr);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004483
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304484 if (dsi->te_enabled) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004485 /* disable LP_RX_TO, so that we can receive TE. Time to wait
4486 * for TE is longer than the timer allows */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304487 REG_FLD_MOD(dsidev, DSI_TIMING2, 0, 15, 15); /* LP_RX_TO */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004488
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304489 dsi_vc_send_bta(dsidev, channel);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004490
4491#ifdef DSI_CATCH_MISSING_TE
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304492 mod_timer(&dsi->te_timer, jiffies + msecs_to_jiffies(250));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004493#endif
4494 }
4495}
4496
4497#ifdef DSI_CATCH_MISSING_TE
4498static void dsi_te_timeout(unsigned long arg)
4499{
4500 DSSERR("TE not received for 250ms!\n");
4501}
4502#endif
4503
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304504static void dsi_handle_framedone(struct platform_device *dsidev, int error)
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004505{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304506 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4507
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004508 /* SIDLEMODE back to smart-idle */
4509 dispc_enable_sidle();
4510
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304511 if (dsi->te_enabled) {
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004512 /* enable LP_RX_TO again after the TE */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304513 REG_FLD_MOD(dsidev, DSI_TIMING2, 1, 15, 15); /* LP_RX_TO */
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004514 }
4515
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304516 dsi->framedone_callback(error, dsi->framedone_data);
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004517
4518 if (!error)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304519 dsi_perf_show(dsidev, "DISPC");
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004520}
4521
4522static void dsi_framedone_timeout_work_callback(struct work_struct *work)
4523{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304524 struct dsi_data *dsi = container_of(work, struct dsi_data,
4525 framedone_timeout_work.work);
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03004526 /* XXX While extremely unlikely, we could get FRAMEDONE interrupt after
4527 * 250ms which would conflict with this timeout work. What should be
4528 * done is first cancel the transfer on the HW, and then cancel the
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004529 * possibly scheduled framedone work. However, cancelling the transfer
4530 * on the HW is buggy, and would probably require resetting the whole
4531 * DSI */
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03004532
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004533 DSSERR("Framedone not received for 250ms!\n");
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004534
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304535 dsi_handle_framedone(dsi->pdev, -ETIMEDOUT);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004536}
4537
Tomi Valkeinen15502022012-10-10 13:59:07 +03004538static void dsi_framedone_irq_callback(void *data)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004539{
Archit Taneja9e7e9372012-08-14 12:29:22 +05304540 struct platform_device *dsidev = (struct platform_device *) data;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304541 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4542
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004543 /* Note: We get FRAMEDONE when DISPC has finished sending pixels and
4544 * turns itself off. However, DSI still has the pixels in its buffers,
4545 * and is sending the data.
4546 */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004547
Tejun Heo136b5722012-08-21 13:18:24 -07004548 cancel_delayed_work(&dsi->framedone_timeout_work);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004549
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304550 dsi_handle_framedone(dsidev, 0);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004551}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004552
Tomi Valkeinen5476e742011-11-03 16:34:20 +02004553int omap_dsi_update(struct omap_dss_device *dssdev, int channel,
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004554 void (*callback)(int, void *), void *data)
4555{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304556 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304557 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen5476e742011-11-03 16:34:20 +02004558 u16 dw, dh;
4559
4560 dsi_perf_mark_setup(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304561
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304562 dsi->update_channel = channel;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004563
Tomi Valkeinen4a9e78a2011-08-15 11:22:21 +03004564 dsi->framedone_callback = callback;
4565 dsi->framedone_data = data;
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004566
Archit Tanejae3525742012-08-09 15:23:43 +05304567 dw = dsi->timings.x_res;
4568 dh = dsi->timings.y_res;
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004569
Tomi Valkeinen5476e742011-11-03 16:34:20 +02004570#ifdef DEBUG
4571 dsi->update_bytes = dw * dh *
Archit Taneja02c39602012-08-10 15:01:33 +05304572 dsi_get_pixel_size(dsi->pix_fmt) / 8;
Tomi Valkeinen5476e742011-11-03 16:34:20 +02004573#endif
Archit Taneja55cd63a2012-08-09 15:41:13 +05304574 dsi_update_screen_dispc(dssdev);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004575
4576 return 0;
4577}
4578EXPORT_SYMBOL(omap_dsi_update);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004579
4580/* Display funcs */
4581
Archit Taneja7d2572f2012-06-29 14:31:07 +05304582static int dsi_configure_dispc_clocks(struct omap_dss_device *dssdev)
4583{
4584 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4585 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4586 struct dispc_clock_info dispc_cinfo;
4587 int r;
4588 unsigned long long fck;
4589
4590 fck = dsi_get_pll_hsdiv_dispc_rate(dsidev);
4591
4592 dispc_cinfo.lck_div = dssdev->clocks.dispc.channel.lck_div;
4593 dispc_cinfo.pck_div = dssdev->clocks.dispc.channel.pck_div;
4594
4595 r = dispc_calc_clock_rates(fck, &dispc_cinfo);
4596 if (r) {
4597 DSSERR("Failed to calc dispc clocks\n");
4598 return r;
4599 }
4600
4601 dsi->mgr_config.clock_info = dispc_cinfo;
4602
4603 return 0;
4604}
4605
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004606static int dsi_display_init_dispc(struct omap_dss_device *dssdev)
4607{
Archit Taneja7d2572f2012-06-29 14:31:07 +05304608 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4609 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejaeea83402012-09-04 11:42:36 +05304610 struct omap_overlay_manager *mgr = dssdev->output->manager;
Archit Taneja7d2572f2012-06-29 14:31:07 +05304611 int r;
Archit Taneja5a8b5722011-05-12 17:26:29 +05304612
Archit Tanejadca2b152012-08-16 18:02:00 +05304613 if (dsi->mode == OMAP_DSS_DSI_CMD_MODE) {
Archit Tanejae67458a2012-08-13 14:17:30 +05304614 dsi->timings.hsw = 1;
4615 dsi->timings.hfp = 1;
4616 dsi->timings.hbp = 1;
4617 dsi->timings.vsw = 1;
4618 dsi->timings.vfp = 0;
4619 dsi->timings.vbp = 0;
Tomi Valkeinen5476e742011-11-03 16:34:20 +02004620
Tomi Valkeinen15502022012-10-10 13:59:07 +03004621 r = dss_mgr_register_framedone_handler(mgr,
4622 dsi_framedone_irq_callback, dsidev);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304623 if (r) {
Tomi Valkeinen15502022012-10-10 13:59:07 +03004624 DSSERR("can't register FRAMEDONE handler\n");
Archit Taneja7d2572f2012-06-29 14:31:07 +05304625 goto err;
Archit Taneja8af6ff02011-09-05 16:48:27 +05304626 }
4627
Archit Taneja7d2572f2012-06-29 14:31:07 +05304628 dsi->mgr_config.stallmode = true;
4629 dsi->mgr_config.fifohandcheck = true;
Archit Taneja8af6ff02011-09-05 16:48:27 +05304630 } else {
Archit Taneja7d2572f2012-06-29 14:31:07 +05304631 dsi->mgr_config.stallmode = false;
4632 dsi->mgr_config.fifohandcheck = false;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004633 }
4634
Archit Tanejabd5a7b12012-06-26 12:38:31 +05304635 /*
4636 * override interlace, logic level and edge related parameters in
4637 * omap_video_timings with default values
4638 */
Archit Tanejae67458a2012-08-13 14:17:30 +05304639 dsi->timings.interlace = false;
4640 dsi->timings.hsync_level = OMAPDSS_SIG_ACTIVE_HIGH;
4641 dsi->timings.vsync_level = OMAPDSS_SIG_ACTIVE_HIGH;
4642 dsi->timings.data_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE;
4643 dsi->timings.de_level = OMAPDSS_SIG_ACTIVE_HIGH;
4644 dsi->timings.sync_pclk_edge = OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES;
Archit Tanejabd5a7b12012-06-26 12:38:31 +05304645
Archit Tanejaeea83402012-09-04 11:42:36 +05304646 dss_mgr_set_timings(mgr, &dsi->timings);
Archit Tanejabd5a7b12012-06-26 12:38:31 +05304647
Archit Taneja7d2572f2012-06-29 14:31:07 +05304648 r = dsi_configure_dispc_clocks(dssdev);
4649 if (r)
4650 goto err1;
4651
4652 dsi->mgr_config.io_pad_mode = DSS_IO_PAD_MODE_BYPASS;
4653 dsi->mgr_config.video_port_width =
Archit Taneja02c39602012-08-10 15:01:33 +05304654 dsi_get_pixel_size(dsi->pix_fmt);
Archit Taneja7d2572f2012-06-29 14:31:07 +05304655 dsi->mgr_config.lcden_sig_polarity = 0;
4656
Archit Tanejaeea83402012-09-04 11:42:36 +05304657 dss_mgr_set_lcd_config(mgr, &dsi->mgr_config);
Archit Tanejad21f43b2012-06-21 09:45:11 +05304658
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004659 return 0;
Archit Taneja7d2572f2012-06-29 14:31:07 +05304660err1:
Archit Tanejadca2b152012-08-16 18:02:00 +05304661 if (dsi->mode == OMAP_DSS_DSI_CMD_MODE)
Tomi Valkeinen15502022012-10-10 13:59:07 +03004662 dss_mgr_unregister_framedone_handler(mgr,
4663 dsi_framedone_irq_callback, dsidev);
Archit Taneja7d2572f2012-06-29 14:31:07 +05304664err:
4665 return r;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004666}
4667
4668static void dsi_display_uninit_dispc(struct omap_dss_device *dssdev)
4669{
Archit Tanejadca2b152012-08-16 18:02:00 +05304670 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4671 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejaeea83402012-09-04 11:42:36 +05304672 struct omap_overlay_manager *mgr = dssdev->output->manager;
Archit Tanejadca2b152012-08-16 18:02:00 +05304673
Tomi Valkeinen15502022012-10-10 13:59:07 +03004674 if (dsi->mode == OMAP_DSS_DSI_CMD_MODE)
4675 dss_mgr_unregister_framedone_handler(mgr,
4676 dsi_framedone_irq_callback, dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004677}
4678
4679static int dsi_configure_dsi_clocks(struct omap_dss_device *dssdev)
4680{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304681 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004682 struct dsi_clock_info cinfo;
4683 int r;
4684
Tomi Valkeinenc6940a32011-02-22 13:36:10 +02004685 cinfo.regn = dssdev->clocks.dsi.regn;
4686 cinfo.regm = dssdev->clocks.dsi.regm;
4687 cinfo.regm_dispc = dssdev->clocks.dsi.regm_dispc;
4688 cinfo.regm_dsi = dssdev->clocks.dsi.regm_dsi;
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02004689 r = dsi_calc_clock_rates(dsidev, &cinfo);
Ville Syrjäläebf0a3f2010-04-22 22:50:05 +02004690 if (r) {
4691 DSSERR("Failed to calc dsi clocks\n");
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004692 return r;
Ville Syrjäläebf0a3f2010-04-22 22:50:05 +02004693 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004694
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304695 r = dsi_pll_set_clock_div(dsidev, &cinfo);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004696 if (r) {
4697 DSSERR("Failed to set dsi clocks\n");
4698 return r;
4699 }
4700
4701 return 0;
4702}
4703
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004704static int dsi_display_init_dsi(struct omap_dss_device *dssdev)
4705{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304706 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02004707 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejaeea83402012-09-04 11:42:36 +05304708 struct omap_overlay_manager *mgr = dssdev->output->manager;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004709 int r;
4710
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304711 r = dsi_pll_init(dsidev, true, true);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004712 if (r)
4713 goto err0;
4714
4715 r = dsi_configure_dsi_clocks(dssdev);
4716 if (r)
4717 goto err1;
4718
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02004719 dss_select_dsi_clk_source(dsi->module_id, dssdev->clocks.dsi.dsi_fclk_src);
Archit Tanejaeea83402012-09-04 11:42:36 +05304720 dss_select_lcd_clk_source(mgr->id,
Archit Tanejae8881662011-04-12 13:52:24 +05304721 dssdev->clocks.dispc.channel.lcd_clk_src);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004722
4723 DSSDBG("PLL OK\n");
4724
Archit Taneja9e7e9372012-08-14 12:29:22 +05304725 r = dsi_cio_init(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004726 if (r)
4727 goto err2;
4728
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304729 _dsi_print_reset_status(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004730
Archit Taneja9e7e9372012-08-14 12:29:22 +05304731 dsi_proto_timings(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004732 dsi_set_lp_clk_divisor(dssdev);
4733
4734 if (1)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304735 _dsi_print_reset_status(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004736
4737 r = dsi_proto_config(dssdev);
4738 if (r)
4739 goto err3;
4740
4741 /* enable interface */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304742 dsi_vc_enable(dsidev, 0, 1);
4743 dsi_vc_enable(dsidev, 1, 1);
4744 dsi_vc_enable(dsidev, 2, 1);
4745 dsi_vc_enable(dsidev, 3, 1);
4746 dsi_if_enable(dsidev, 1);
4747 dsi_force_tx_stop_mode_io(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004748
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004749 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004750err3:
Archit Taneja9e7e9372012-08-14 12:29:22 +05304751 dsi_cio_uninit(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004752err2:
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02004753 dss_select_dsi_clk_source(dsi->module_id, OMAP_DSS_CLK_SRC_FCK);
Archit Tanejaeea83402012-09-04 11:42:36 +05304754 dss_select_lcd_clk_source(mgr->id, OMAP_DSS_CLK_SRC_FCK);
Tomi Valkeinen5e785092011-08-10 11:25:36 +03004755
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004756err1:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304757 dsi_pll_uninit(dsidev, true);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004758err0:
4759 return r;
4760}
4761
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +03004762static void dsi_display_uninit_dsi(struct omap_dss_device *dssdev,
Tomi Valkeinen22d6d672010-10-11 11:33:30 +03004763 bool disconnect_lanes, bool enter_ulps)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004764{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304765 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304766 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejaeea83402012-09-04 11:42:36 +05304767 struct omap_overlay_manager *mgr = dssdev->output->manager;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304768
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304769 if (enter_ulps && !dsi->ulps_enabled)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304770 dsi_enter_ulps(dsidev);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03004771
Ville Syrjäläd7370102010-04-22 22:50:09 +02004772 /* disable interface */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304773 dsi_if_enable(dsidev, 0);
4774 dsi_vc_enable(dsidev, 0, 0);
4775 dsi_vc_enable(dsidev, 1, 0);
4776 dsi_vc_enable(dsidev, 2, 0);
4777 dsi_vc_enable(dsidev, 3, 0);
Ville Syrjäläd7370102010-04-22 22:50:09 +02004778
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02004779 dss_select_dsi_clk_source(dsi->module_id, OMAP_DSS_CLK_SRC_FCK);
Archit Tanejaeea83402012-09-04 11:42:36 +05304780 dss_select_lcd_clk_source(mgr->id, OMAP_DSS_CLK_SRC_FCK);
Archit Taneja9e7e9372012-08-14 12:29:22 +05304781 dsi_cio_uninit(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304782 dsi_pll_uninit(dsidev, disconnect_lanes);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004783}
4784
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02004785int omapdss_dsi_display_enable(struct omap_dss_device *dssdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004786{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304787 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304788 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejaeea83402012-09-04 11:42:36 +05304789 struct omap_dss_output *out = dssdev->output;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004790 int r = 0;
4791
4792 DSSDBG("dsi_display_enable\n");
4793
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304794 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02004795
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304796 mutex_lock(&dsi->lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004797
Archit Tanejaeea83402012-09-04 11:42:36 +05304798 if (out == NULL || out->manager == NULL) {
4799 DSSERR("failed to enable display: no output/manager\n");
Tomi Valkeinen05e1d602011-06-23 16:38:21 +03004800 r = -ENODEV;
4801 goto err_start_dev;
4802 }
4803
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004804 r = omap_dss_start_device(dssdev);
4805 if (r) {
4806 DSSERR("failed to start device\n");
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004807 goto err_start_dev;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004808 }
4809
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004810 r = dsi_runtime_get(dsidev);
4811 if (r)
4812 goto err_get_dsi;
4813
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304814 dsi_enable_pll_clock(dsidev, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004815
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004816 _dsi_initialize_irq(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004817
4818 r = dsi_display_init_dispc(dssdev);
4819 if (r)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004820 goto err_init_dispc;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004821
4822 r = dsi_display_init_dsi(dssdev);
4823 if (r)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004824 goto err_init_dsi;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004825
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304826 mutex_unlock(&dsi->lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004827
4828 return 0;
4829
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004830err_init_dsi:
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02004831 dsi_display_uninit_dispc(dssdev);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004832err_init_dispc:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304833 dsi_enable_pll_clock(dsidev, 0);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004834 dsi_runtime_put(dsidev);
4835err_get_dsi:
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004836 omap_dss_stop_device(dssdev);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004837err_start_dev:
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304838 mutex_unlock(&dsi->lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004839 DSSDBG("dsi_display_enable FAILED\n");
4840 return r;
4841}
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02004842EXPORT_SYMBOL(omapdss_dsi_display_enable);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004843
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +03004844void omapdss_dsi_display_disable(struct omap_dss_device *dssdev,
Tomi Valkeinen22d6d672010-10-11 11:33:30 +03004845 bool disconnect_lanes, bool enter_ulps)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004846{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304847 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304848 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304849
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004850 DSSDBG("dsi_display_disable\n");
4851
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304852 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02004853
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304854 mutex_lock(&dsi->lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004855
Tomi Valkeinen15ffa1d2011-06-16 14:34:06 +03004856 dsi_sync_vc(dsidev, 0);
4857 dsi_sync_vc(dsidev, 1);
4858 dsi_sync_vc(dsidev, 2);
4859 dsi_sync_vc(dsidev, 3);
4860
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004861 dsi_display_uninit_dispc(dssdev);
4862
Tomi Valkeinen22d6d672010-10-11 11:33:30 +03004863 dsi_display_uninit_dsi(dssdev, disconnect_lanes, enter_ulps);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004864
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004865 dsi_runtime_put(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304866 dsi_enable_pll_clock(dsidev, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004867
4868 omap_dss_stop_device(dssdev);
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02004869
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304870 mutex_unlock(&dsi->lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004871}
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02004872EXPORT_SYMBOL(omapdss_dsi_display_disable);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004873
Tomi Valkeinen225b6502010-01-11 15:11:01 +02004874int omapdss_dsi_enable_te(struct omap_dss_device *dssdev, bool enable)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004875{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304876 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4877 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4878
4879 dsi->te_enabled = enable;
Tomi Valkeinen225b6502010-01-11 15:11:01 +02004880 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004881}
Tomi Valkeinen225b6502010-01-11 15:11:01 +02004882EXPORT_SYMBOL(omapdss_dsi_enable_te);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004883
Archit Tanejae67458a2012-08-13 14:17:30 +05304884void omapdss_dsi_set_timings(struct omap_dss_device *dssdev,
4885 struct omap_video_timings *timings)
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 = *timings;
4893
4894 mutex_unlock(&dsi->lock);
4895}
4896EXPORT_SYMBOL(omapdss_dsi_set_timings);
4897
Archit Tanejae3525742012-08-09 15:23:43 +05304898void omapdss_dsi_set_size(struct omap_dss_device *dssdev, u16 w, u16 h)
4899{
4900 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4901 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4902
4903 mutex_lock(&dsi->lock);
4904
4905 dsi->timings.x_res = w;
4906 dsi->timings.y_res = h;
4907
4908 mutex_unlock(&dsi->lock);
4909}
4910EXPORT_SYMBOL(omapdss_dsi_set_size);
4911
Archit Taneja02c39602012-08-10 15:01:33 +05304912void omapdss_dsi_set_pixel_format(struct omap_dss_device *dssdev,
4913 enum omap_dss_dsi_pixel_format fmt)
4914{
4915 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4916 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4917
4918 mutex_lock(&dsi->lock);
4919
4920 dsi->pix_fmt = fmt;
4921
4922 mutex_unlock(&dsi->lock);
4923}
4924EXPORT_SYMBOL(omapdss_dsi_set_pixel_format);
4925
Archit Tanejadca2b152012-08-16 18:02:00 +05304926void omapdss_dsi_set_operation_mode(struct omap_dss_device *dssdev,
4927 enum omap_dss_dsi_mode mode)
4928{
4929 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4930 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4931
4932 mutex_lock(&dsi->lock);
4933
4934 dsi->mode = mode;
4935
4936 mutex_unlock(&dsi->lock);
4937}
4938EXPORT_SYMBOL(omapdss_dsi_set_operation_mode);
4939
Archit Taneja0b3ffe32012-08-13 22:13:39 +05304940void omapdss_dsi_set_videomode_timings(struct omap_dss_device *dssdev,
4941 struct omap_dss_dsi_videomode_timings *timings)
4942{
4943 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4944 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4945
4946 mutex_lock(&dsi->lock);
4947
4948 dsi->vm_timings = *timings;
4949
4950 mutex_unlock(&dsi->lock);
4951}
4952EXPORT_SYMBOL(omapdss_dsi_set_videomode_timings);
4953
Tomi Valkeinen9d8232a2012-03-01 16:58:39 +02004954static int __init dsi_init_display(struct omap_dss_device *dssdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004955{
Archit Tanejaeea83402012-09-04 11:42:36 +05304956 struct platform_device *dsidev =
4957 dsi_get_dsidev_from_id(dssdev->phy.dsi.module);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304958 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4959
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004960 DSSDBG("DSI init\n");
4961
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304962 if (dsi->vdds_dsi_reg == NULL) {
Tomi Valkeinen5f42f2ce2011-02-22 15:53:46 +02004963 struct regulator *vdds_dsi;
4964
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304965 vdds_dsi = regulator_get(&dsi->pdev->dev, "vdds_dsi");
Tomi Valkeinen5f42f2ce2011-02-22 15:53:46 +02004966
Tomi Valkeinen76eed4b2012-11-05 13:41:25 +02004967 /* DT HACK: try VCXIO to make omapdss work for o4 sdp/panda */
4968 if (IS_ERR(vdds_dsi))
4969 vdds_dsi = regulator_get(&dsi->pdev->dev, "VCXIO");
4970
Tomi Valkeinen5f42f2ce2011-02-22 15:53:46 +02004971 if (IS_ERR(vdds_dsi)) {
4972 DSSERR("can't get VDDS_DSI regulator\n");
4973 return PTR_ERR(vdds_dsi);
4974 }
4975
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304976 dsi->vdds_dsi_reg = vdds_dsi;
Tomi Valkeinen5f42f2ce2011-02-22 15:53:46 +02004977 }
4978
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004979 return 0;
4980}
4981
Archit Taneja5ee3c142011-03-02 12:35:53 +05304982int omap_dsi_request_vc(struct omap_dss_device *dssdev, int *channel)
4983{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304984 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4985 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Taneja5ee3c142011-03-02 12:35:53 +05304986 int i;
4987
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304988 for (i = 0; i < ARRAY_SIZE(dsi->vc); i++) {
4989 if (!dsi->vc[i].dssdev) {
4990 dsi->vc[i].dssdev = dssdev;
Archit Taneja5ee3c142011-03-02 12:35:53 +05304991 *channel = i;
4992 return 0;
4993 }
4994 }
4995
4996 DSSERR("cannot get VC for display %s", dssdev->name);
4997 return -ENOSPC;
4998}
4999EXPORT_SYMBOL(omap_dsi_request_vc);
5000
5001int omap_dsi_set_vc_id(struct omap_dss_device *dssdev, int channel, int vc_id)
5002{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305003 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
5004 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
5005
Archit Taneja5ee3c142011-03-02 12:35:53 +05305006 if (vc_id < 0 || vc_id > 3) {
5007 DSSERR("VC ID out of range\n");
5008 return -EINVAL;
5009 }
5010
5011 if (channel < 0 || channel > 3) {
5012 DSSERR("Virtual Channel out of range\n");
5013 return -EINVAL;
5014 }
5015
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305016 if (dsi->vc[channel].dssdev != dssdev) {
Archit Taneja5ee3c142011-03-02 12:35:53 +05305017 DSSERR("Virtual Channel not allocated to display %s\n",
5018 dssdev->name);
5019 return -EINVAL;
5020 }
5021
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305022 dsi->vc[channel].vc_id = vc_id;
Archit Taneja5ee3c142011-03-02 12:35:53 +05305023
5024 return 0;
5025}
5026EXPORT_SYMBOL(omap_dsi_set_vc_id);
5027
5028void omap_dsi_release_vc(struct omap_dss_device *dssdev, int channel)
5029{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305030 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
5031 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
5032
Archit Taneja5ee3c142011-03-02 12:35:53 +05305033 if ((channel >= 0 && channel <= 3) &&
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305034 dsi->vc[channel].dssdev == dssdev) {
5035 dsi->vc[channel].dssdev = NULL;
5036 dsi->vc[channel].vc_id = 0;
Archit Taneja5ee3c142011-03-02 12:35:53 +05305037 }
5038}
5039EXPORT_SYMBOL(omap_dsi_release_vc);
5040
Archit Tanejaa72b64b2011-05-12 17:26:26 +05305041void dsi_wait_pll_hsdiv_dispc_active(struct platform_device *dsidev)
Tomi Valkeinene406f902010-06-09 15:28:12 +03005042{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05305043 if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 7, 1) != 1)
Archit Taneja067a57e2011-03-02 11:57:25 +05305044 DSSERR("%s (%s) not active\n",
Archit Taneja89a35e52011-04-12 13:52:23 +05305045 dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
5046 dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC));
Tomi Valkeinene406f902010-06-09 15:28:12 +03005047}
5048
Archit Tanejaa72b64b2011-05-12 17:26:26 +05305049void dsi_wait_pll_hsdiv_dsi_active(struct platform_device *dsidev)
Tomi Valkeinene406f902010-06-09 15:28:12 +03005050{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05305051 if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 8, 1) != 1)
Archit Taneja067a57e2011-03-02 11:57:25 +05305052 DSSERR("%s (%s) not active\n",
Archit Taneja89a35e52011-04-12 13:52:23 +05305053 dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
5054 dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI));
Tomi Valkeinene406f902010-06-09 15:28:12 +03005055}
5056
Archit Tanejaa72b64b2011-05-12 17:26:26 +05305057static void dsi_calc_clock_param_ranges(struct platform_device *dsidev)
Taneja, Archit49641112011-03-14 23:28:23 -05005058{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305059 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
5060
5061 dsi->regn_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGN);
5062 dsi->regm_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM);
5063 dsi->regm_dispc_max =
5064 dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DISPC);
5065 dsi->regm_dsi_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DSI);
5066 dsi->fint_min = dss_feat_get_param_min(FEAT_PARAM_DSIPLL_FINT);
5067 dsi->fint_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_FINT);
5068 dsi->lpdiv_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_LPDIV);
Taneja, Archit49641112011-03-14 23:28:23 -05005069}
5070
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005071static int dsi_get_clocks(struct platform_device *dsidev)
5072{
5073 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
5074 struct clk *clk;
5075
5076 clk = clk_get(&dsidev->dev, "fck");
5077 if (IS_ERR(clk)) {
5078 DSSERR("can't get fck\n");
5079 return PTR_ERR(clk);
5080 }
5081
5082 dsi->dss_clk = clk;
5083
Tomi Valkeinenbfe4f8d2011-08-04 11:22:54 +03005084 clk = clk_get(&dsidev->dev, "sys_clk");
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005085 if (IS_ERR(clk)) {
5086 DSSERR("can't get sys_clk\n");
5087 clk_put(dsi->dss_clk);
5088 dsi->dss_clk = NULL;
5089 return PTR_ERR(clk);
5090 }
5091
5092 dsi->sys_clk = clk;
5093
5094 return 0;
5095}
5096
5097static void dsi_put_clocks(struct platform_device *dsidev)
5098{
5099 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
5100
5101 if (dsi->dss_clk)
5102 clk_put(dsi->dss_clk);
5103 if (dsi->sys_clk)
5104 clk_put(dsi->sys_clk);
5105}
5106
Tomi Valkeinen15216532012-09-06 14:29:31 +03005107static struct omap_dss_device * __init dsi_find_dssdev(struct platform_device *pdev)
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +03005108{
Tomi Valkeinen15216532012-09-06 14:29:31 +03005109 struct omap_dss_board_info *pdata = pdev->dev.platform_data;
5110 struct dsi_data *dsi = dsi_get_dsidrv_data(pdev);
Tomi Valkeinen2bbcce52012-10-29 12:40:46 +02005111 const char *def_disp_name = omapdss_get_default_display_name();
Tomi Valkeinen15216532012-09-06 14:29:31 +03005112 struct omap_dss_device *def_dssdev;
5113 int i;
5114
5115 def_dssdev = NULL;
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +03005116
5117 for (i = 0; i < pdata->num_devices; ++i) {
5118 struct omap_dss_device *dssdev = pdata->devices[i];
5119
5120 if (dssdev->type != OMAP_DISPLAY_TYPE_DSI)
5121 continue;
5122
5123 if (dssdev->phy.dsi.module != dsi->module_id)
5124 continue;
5125
Tomi Valkeinen15216532012-09-06 14:29:31 +03005126 if (def_dssdev == NULL)
5127 def_dssdev = dssdev;
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +03005128
Tomi Valkeinen15216532012-09-06 14:29:31 +03005129 if (def_disp_name != NULL &&
5130 strcmp(dssdev->name, def_disp_name) == 0) {
5131 def_dssdev = dssdev;
5132 break;
5133 }
5134 }
5135
5136 return def_dssdev;
5137}
5138
5139static void __init dsi_probe_pdata(struct platform_device *dsidev)
5140{
Tomi Valkeinen486c0e12012-12-07 12:50:08 +02005141 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen52744842012-09-10 13:58:29 +03005142 struct omap_dss_device *plat_dssdev;
Tomi Valkeinen15216532012-09-06 14:29:31 +03005143 struct omap_dss_device *dssdev;
5144 int r;
5145
Tomi Valkeinen52744842012-09-10 13:58:29 +03005146 plat_dssdev = dsi_find_dssdev(dsidev);
Tomi Valkeinen15216532012-09-06 14:29:31 +03005147
Tomi Valkeinen52744842012-09-10 13:58:29 +03005148 if (!plat_dssdev)
5149 return;
5150
5151 dssdev = dss_alloc_and_init_device(&dsidev->dev);
Tomi Valkeinen15216532012-09-06 14:29:31 +03005152 if (!dssdev)
5153 return;
5154
Tomi Valkeinen52744842012-09-10 13:58:29 +03005155 dss_copy_device_pdata(dssdev, plat_dssdev);
5156
Tomi Valkeinen15216532012-09-06 14:29:31 +03005157 r = dsi_init_display(dssdev);
5158 if (r) {
5159 DSSERR("device %s init failed: %d\n", dssdev->name, r);
Tomi Valkeinen52744842012-09-10 13:58:29 +03005160 dss_put_device(dssdev);
Tomi Valkeinen15216532012-09-06 14:29:31 +03005161 return;
5162 }
5163
Tomi Valkeinen486c0e12012-12-07 12:50:08 +02005164 r = omapdss_output_set_device(&dsi->output, dssdev);
5165 if (r) {
5166 DSSERR("failed to connect output to new device: %s\n",
5167 dssdev->name);
5168 dss_put_device(dssdev);
5169 return;
5170 }
5171
Tomi Valkeinen52744842012-09-10 13:58:29 +03005172 r = dss_add_device(dssdev);
Tomi Valkeinen15216532012-09-06 14:29:31 +03005173 if (r) {
5174 DSSERR("device %s register failed: %d\n", dssdev->name, r);
Tomi Valkeinen486c0e12012-12-07 12:50:08 +02005175 omapdss_output_unset_device(&dsi->output);
Tomi Valkeinen52744842012-09-10 13:58:29 +03005176 dss_put_device(dssdev);
Tomi Valkeinen15216532012-09-06 14:29:31 +03005177 return;
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +03005178 }
5179}
5180
Archit Taneja81b87f52012-09-26 16:30:49 +05305181static void __init dsi_init_output(struct platform_device *dsidev)
5182{
5183 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
5184 struct omap_dss_output *out = &dsi->output;
5185
5186 out->pdev = dsidev;
5187 out->id = dsi->module_id == 0 ?
5188 OMAP_DSS_OUTPUT_DSI1 : OMAP_DSS_OUTPUT_DSI2;
5189
5190 out->type = OMAP_DISPLAY_TYPE_DSI;
5191
5192 dss_register_output(out);
5193}
5194
5195static void __exit dsi_uninit_output(struct platform_device *dsidev)
5196{
5197 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
5198 struct omap_dss_output *out = &dsi->output;
5199
5200 dss_unregister_output(out);
5201}
5202
Tomi Valkeinenb98482e2011-05-16 13:52:51 +03005203/* DSI1 HW IP initialisation */
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02005204static int __init omap_dsihw_probe(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005205{
5206 u32 rev;
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02005207 int r, i;
Senthilvadivu Guruswamyea9da362011-01-24 06:22:04 +00005208 struct resource *dsi_mem;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305209 struct dsi_data *dsi;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005210
Julia Lawall6e2a14d2012-01-24 14:00:45 +01005211 dsi = devm_kzalloc(&dsidev->dev, sizeof(*dsi), GFP_KERNEL);
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005212 if (!dsi)
5213 return -ENOMEM;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305214
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02005215 dsi->module_id = dsidev->id;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305216 dsi->pdev = dsidev;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305217 dev_set_drvdata(&dsidev->dev, dsi);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05305218
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305219 spin_lock_init(&dsi->irq_lock);
5220 spin_lock_init(&dsi->errors_lock);
5221 dsi->errors = 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005222
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02005223#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305224 spin_lock_init(&dsi->irq_stats_lock);
5225 dsi->irq_stats.last_reset = jiffies;
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02005226#endif
5227
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305228 mutex_init(&dsi->lock);
5229 sema_init(&dsi->bus_lock, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005230
Tejun Heo203b42f2012-08-21 13:18:23 -07005231 INIT_DEFERRABLE_WORK(&dsi->framedone_timeout_work,
5232 dsi_framedone_timeout_work_callback);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305233
5234#ifdef DSI_CATCH_MISSING_TE
5235 init_timer(&dsi->te_timer);
5236 dsi->te_timer.function = dsi_te_timeout;
5237 dsi->te_timer.data = 0;
5238#endif
5239 dsi_mem = platform_get_resource(dsi->pdev, IORESOURCE_MEM, 0);
5240 if (!dsi_mem) {
5241 DSSERR("can't get IORESOURCE_MEM DSI\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005242 return -EINVAL;
archit tanejaaffe3602011-02-23 08:41:03 +00005243 }
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005244
Julia Lawall6e2a14d2012-01-24 14:00:45 +01005245 dsi->base = devm_ioremap(&dsidev->dev, dsi_mem->start,
5246 resource_size(dsi_mem));
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305247 if (!dsi->base) {
5248 DSSERR("can't ioremap DSI\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005249 return -ENOMEM;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305250 }
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005251
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305252 dsi->irq = platform_get_irq(dsi->pdev, 0);
5253 if (dsi->irq < 0) {
5254 DSSERR("platform_get_irq failed\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005255 return -ENODEV;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305256 }
archit tanejaaffe3602011-02-23 08:41:03 +00005257
Julia Lawall6e2a14d2012-01-24 14:00:45 +01005258 r = devm_request_irq(&dsidev->dev, dsi->irq, omap_dsi_irq_handler,
5259 IRQF_SHARED, dev_name(&dsidev->dev), dsi->pdev);
archit tanejaaffe3602011-02-23 08:41:03 +00005260 if (r < 0) {
5261 DSSERR("request_irq failed\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005262 return r;
archit tanejaaffe3602011-02-23 08:41:03 +00005263 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005264
Archit Taneja5ee3c142011-03-02 12:35:53 +05305265 /* DSI VCs initialization */
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305266 for (i = 0; i < ARRAY_SIZE(dsi->vc); i++) {
Archit Tanejad6049142011-08-22 11:58:08 +05305267 dsi->vc[i].source = DSI_VC_SOURCE_L4;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305268 dsi->vc[i].dssdev = NULL;
5269 dsi->vc[i].vc_id = 0;
Archit Taneja5ee3c142011-03-02 12:35:53 +05305270 }
5271
Archit Tanejaa72b64b2011-05-12 17:26:26 +05305272 dsi_calc_clock_param_ranges(dsidev);
Taneja, Archit49641112011-03-14 23:28:23 -05005273
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005274 r = dsi_get_clocks(dsidev);
5275 if (r)
5276 return r;
5277
5278 pm_runtime_enable(&dsidev->dev);
5279
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005280 r = dsi_runtime_get(dsidev);
5281 if (r)
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005282 goto err_runtime_get;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005283
Archit Tanejaa72b64b2011-05-12 17:26:26 +05305284 rev = dsi_read_reg(dsidev, DSI_REVISION);
5285 dev_dbg(&dsidev->dev, "OMAP DSI rev %d.%d\n",
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005286 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
5287
Tomi Valkeinend9820852011-10-12 15:05:59 +03005288 /* DSI on OMAP3 doesn't have register DSI_GNQ, set number
5289 * of data to 3 by default */
5290 if (dss_has_feature(FEAT_DSI_GNQ))
5291 /* NB_DATA_LANES */
5292 dsi->num_lanes_supported = 1 + REG_GET(dsidev, DSI_GNQ, 11, 9);
5293 else
5294 dsi->num_lanes_supported = 3;
Archit Taneja75d72472011-05-16 15:17:08 +05305295
Archit Taneja81b87f52012-09-26 16:30:49 +05305296 dsi_init_output(dsidev);
5297
Tomi Valkeinen38f3daf2012-05-02 14:55:12 +03005298 dsi_probe_pdata(dsidev);
Tomi Valkeinen35deca32012-03-01 15:45:53 +02005299
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005300 dsi_runtime_put(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005301
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02005302 if (dsi->module_id == 0)
Tomi Valkeinene40402c2012-03-02 18:01:07 +02005303 dss_debugfs_create_file("dsi1_regs", dsi1_dump_regs);
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02005304 else if (dsi->module_id == 1)
Tomi Valkeinene40402c2012-03-02 18:01:07 +02005305 dss_debugfs_create_file("dsi2_regs", dsi2_dump_regs);
5306
5307#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02005308 if (dsi->module_id == 0)
Tomi Valkeinene40402c2012-03-02 18:01:07 +02005309 dss_debugfs_create_file("dsi1_irqs", dsi1_dump_irqs);
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02005310 else if (dsi->module_id == 1)
Tomi Valkeinene40402c2012-03-02 18:01:07 +02005311 dss_debugfs_create_file("dsi2_irqs", dsi2_dump_irqs);
5312#endif
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005313 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005314
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005315err_runtime_get:
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005316 pm_runtime_disable(&dsidev->dev);
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005317 dsi_put_clocks(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005318 return r;
5319}
5320
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02005321static int __exit omap_dsihw_remove(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005322{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305323 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
5324
Tomi Valkeinenb98482e2011-05-16 13:52:51 +03005325 WARN_ON(dsi->scp_clk_refcount > 0);
5326
Tomi Valkeinen52744842012-09-10 13:58:29 +03005327 dss_unregister_child_devices(&dsidev->dev);
Tomi Valkeinen35deca32012-03-01 15:45:53 +02005328
Archit Taneja81b87f52012-09-26 16:30:49 +05305329 dsi_uninit_output(dsidev);
5330
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005331 pm_runtime_disable(&dsidev->dev);
5332
5333 dsi_put_clocks(dsidev);
5334
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305335 if (dsi->vdds_dsi_reg != NULL) {
5336 if (dsi->vdds_dsi_enabled) {
5337 regulator_disable(dsi->vdds_dsi_reg);
5338 dsi->vdds_dsi_enabled = false;
Tomi Valkeinen88257b22010-12-20 16:26:22 +02005339 }
5340
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305341 regulator_put(dsi->vdds_dsi_reg);
5342 dsi->vdds_dsi_reg = NULL;
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005343 }
5344
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005345 return 0;
5346}
5347
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005348static int dsi_runtime_suspend(struct device *dev)
5349{
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005350 dispc_runtime_put();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005351
5352 return 0;
5353}
5354
5355static int dsi_runtime_resume(struct device *dev)
5356{
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005357 int r;
5358
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005359 r = dispc_runtime_get();
5360 if (r)
Tomi Valkeinen852f0832012-02-17 17:58:04 +02005361 return r;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005362
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005363 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005364}
5365
5366static const struct dev_pm_ops dsi_pm_ops = {
5367 .runtime_suspend = dsi_runtime_suspend,
5368 .runtime_resume = dsi_runtime_resume,
5369};
5370
Tomi Valkeinen7c68dd92011-08-03 14:00:57 +03005371static struct platform_driver omap_dsihw_driver = {
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02005372 .remove = __exit_p(omap_dsihw_remove),
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005373 .driver = {
Tomi Valkeinen7c68dd92011-08-03 14:00:57 +03005374 .name = "omapdss_dsi",
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005375 .owner = THIS_MODULE,
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005376 .pm = &dsi_pm_ops,
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005377 },
5378};
5379
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02005380int __init dsi_init_platform_driver(void)
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005381{
Tomi Valkeinen61055d42012-03-07 12:53:38 +02005382 return platform_driver_probe(&omap_dsihw_driver, omap_dsihw_probe);
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005383}
5384
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02005385void __exit dsi_uninit_platform_driver(void)
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005386{
Tomi Valkeinen04c742c2012-02-23 15:32:37 +02005387 platform_driver_unregister(&omap_dsihw_driver);
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005388}