blob: efb24b377d04a1d212e364381e9d8fc9e7b3cfaf [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 Valkeinen6274a612012-08-21 15:35:42 +030041#include <linux/of.h>
42#include <linux/of_platform.h>
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +020043
Tomi Valkeinena0b38cc2011-05-11 14:05:07 +030044#include <video/omapdss.h>
Archit Taneja7a7c48f2011-08-25 18:25:03 +053045#include <video/mipi_display.h>
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +020046
47#include "dss.h"
Archit Taneja819d8072011-03-01 11:54:00 +053048#include "dss_features.h"
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +020049
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +020050#define DSI_CATCH_MISSING_TE
51
Tomi Valkeinen68104462013-12-17 13:53:28 +020052struct dsi_reg { u16 module; u16 idx; };
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +020053
Tomi Valkeinen68104462013-12-17 13:53:28 +020054#define DSI_REG(mod, idx) ((const struct dsi_reg) { mod, idx })
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +020055
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +020056/* DSI Protocol Engine */
57
Tomi Valkeinen68104462013-12-17 13:53:28 +020058#define DSI_PROTO 0
59#define DSI_PROTO_SZ 0x200
60
61#define DSI_REVISION DSI_REG(DSI_PROTO, 0x0000)
62#define DSI_SYSCONFIG DSI_REG(DSI_PROTO, 0x0010)
63#define DSI_SYSSTATUS DSI_REG(DSI_PROTO, 0x0014)
64#define DSI_IRQSTATUS DSI_REG(DSI_PROTO, 0x0018)
65#define DSI_IRQENABLE DSI_REG(DSI_PROTO, 0x001C)
66#define DSI_CTRL DSI_REG(DSI_PROTO, 0x0040)
67#define DSI_GNQ DSI_REG(DSI_PROTO, 0x0044)
68#define DSI_COMPLEXIO_CFG1 DSI_REG(DSI_PROTO, 0x0048)
69#define DSI_COMPLEXIO_IRQ_STATUS DSI_REG(DSI_PROTO, 0x004C)
70#define DSI_COMPLEXIO_IRQ_ENABLE DSI_REG(DSI_PROTO, 0x0050)
71#define DSI_CLK_CTRL DSI_REG(DSI_PROTO, 0x0054)
72#define DSI_TIMING1 DSI_REG(DSI_PROTO, 0x0058)
73#define DSI_TIMING2 DSI_REG(DSI_PROTO, 0x005C)
74#define DSI_VM_TIMING1 DSI_REG(DSI_PROTO, 0x0060)
75#define DSI_VM_TIMING2 DSI_REG(DSI_PROTO, 0x0064)
76#define DSI_VM_TIMING3 DSI_REG(DSI_PROTO, 0x0068)
77#define DSI_CLK_TIMING DSI_REG(DSI_PROTO, 0x006C)
78#define DSI_TX_FIFO_VC_SIZE DSI_REG(DSI_PROTO, 0x0070)
79#define DSI_RX_FIFO_VC_SIZE DSI_REG(DSI_PROTO, 0x0074)
80#define DSI_COMPLEXIO_CFG2 DSI_REG(DSI_PROTO, 0x0078)
81#define DSI_RX_FIFO_VC_FULLNESS DSI_REG(DSI_PROTO, 0x007C)
82#define DSI_VM_TIMING4 DSI_REG(DSI_PROTO, 0x0080)
83#define DSI_TX_FIFO_VC_EMPTINESS DSI_REG(DSI_PROTO, 0x0084)
84#define DSI_VM_TIMING5 DSI_REG(DSI_PROTO, 0x0088)
85#define DSI_VM_TIMING6 DSI_REG(DSI_PROTO, 0x008C)
86#define DSI_VM_TIMING7 DSI_REG(DSI_PROTO, 0x0090)
87#define DSI_STOPCLK_TIMING DSI_REG(DSI_PROTO, 0x0094)
88#define DSI_VC_CTRL(n) DSI_REG(DSI_PROTO, 0x0100 + (n * 0x20))
89#define DSI_VC_TE(n) DSI_REG(DSI_PROTO, 0x0104 + (n * 0x20))
90#define DSI_VC_LONG_PACKET_HEADER(n) DSI_REG(DSI_PROTO, 0x0108 + (n * 0x20))
91#define DSI_VC_LONG_PACKET_PAYLOAD(n) DSI_REG(DSI_PROTO, 0x010C + (n * 0x20))
92#define DSI_VC_SHORT_PACKET_HEADER(n) DSI_REG(DSI_PROTO, 0x0110 + (n * 0x20))
93#define DSI_VC_IRQSTATUS(n) DSI_REG(DSI_PROTO, 0x0118 + (n * 0x20))
94#define DSI_VC_IRQENABLE(n) DSI_REG(DSI_PROTO, 0x011C + (n * 0x20))
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +020095
96/* DSIPHY_SCP */
97
Tomi Valkeinen68104462013-12-17 13:53:28 +020098#define DSI_PHY 1
99#define DSI_PHY_OFFSET 0x200
100#define DSI_PHY_SZ 0x40
101
102#define DSI_DSIPHY_CFG0 DSI_REG(DSI_PHY, 0x0000)
103#define DSI_DSIPHY_CFG1 DSI_REG(DSI_PHY, 0x0004)
104#define DSI_DSIPHY_CFG2 DSI_REG(DSI_PHY, 0x0008)
105#define DSI_DSIPHY_CFG5 DSI_REG(DSI_PHY, 0x0014)
106#define DSI_DSIPHY_CFG10 DSI_REG(DSI_PHY, 0x0028)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200107
108/* DSI_PLL_CTRL_SCP */
109
Tomi Valkeinen68104462013-12-17 13:53:28 +0200110#define DSI_PLL 2
111#define DSI_PLL_OFFSET 0x300
112#define DSI_PLL_SZ 0x20
113
114#define DSI_PLL_CONTROL DSI_REG(DSI_PLL, 0x0000)
115#define DSI_PLL_STATUS DSI_REG(DSI_PLL, 0x0004)
116#define DSI_PLL_GO DSI_REG(DSI_PLL, 0x0008)
117#define DSI_PLL_CONFIGURATION1 DSI_REG(DSI_PLL, 0x000C)
118#define DSI_PLL_CONFIGURATION2 DSI_REG(DSI_PLL, 0x0010)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200119
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530120#define REG_GET(dsidev, idx, start, end) \
121 FLD_GET(dsi_read_reg(dsidev, idx), start, end)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200122
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530123#define REG_FLD_MOD(dsidev, idx, val, start, end) \
124 dsi_write_reg(dsidev, idx, FLD_MOD(dsi_read_reg(dsidev, idx), val, start, end))
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200125
126/* Global interrupts */
127#define DSI_IRQ_VC0 (1 << 0)
128#define DSI_IRQ_VC1 (1 << 1)
129#define DSI_IRQ_VC2 (1 << 2)
130#define DSI_IRQ_VC3 (1 << 3)
131#define DSI_IRQ_WAKEUP (1 << 4)
132#define DSI_IRQ_RESYNC (1 << 5)
133#define DSI_IRQ_PLL_LOCK (1 << 7)
134#define DSI_IRQ_PLL_UNLOCK (1 << 8)
135#define DSI_IRQ_PLL_RECALL (1 << 9)
136#define DSI_IRQ_COMPLEXIO_ERR (1 << 10)
137#define DSI_IRQ_HS_TX_TIMEOUT (1 << 14)
138#define DSI_IRQ_LP_RX_TIMEOUT (1 << 15)
139#define DSI_IRQ_TE_TRIGGER (1 << 16)
140#define DSI_IRQ_ACK_TRIGGER (1 << 17)
141#define DSI_IRQ_SYNC_LOST (1 << 18)
142#define DSI_IRQ_LDO_POWER_GOOD (1 << 19)
143#define DSI_IRQ_TA_TIMEOUT (1 << 20)
144#define DSI_IRQ_ERROR_MASK \
145 (DSI_IRQ_HS_TX_TIMEOUT | DSI_IRQ_LP_RX_TIMEOUT | DSI_IRQ_SYNC_LOST | \
Archit Taneja8af6ff02011-09-05 16:48:27 +0530146 DSI_IRQ_TA_TIMEOUT | DSI_IRQ_SYNC_LOST)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200147#define DSI_IRQ_CHANNEL_MASK 0xf
148
149/* Virtual channel interrupts */
150#define DSI_VC_IRQ_CS (1 << 0)
151#define DSI_VC_IRQ_ECC_CORR (1 << 1)
152#define DSI_VC_IRQ_PACKET_SENT (1 << 2)
153#define DSI_VC_IRQ_FIFO_TX_OVF (1 << 3)
154#define DSI_VC_IRQ_FIFO_RX_OVF (1 << 4)
155#define DSI_VC_IRQ_BTA (1 << 5)
156#define DSI_VC_IRQ_ECC_NO_CORR (1 << 6)
157#define DSI_VC_IRQ_FIFO_TX_UDF (1 << 7)
158#define DSI_VC_IRQ_PP_BUSY_CHANGE (1 << 8)
159#define DSI_VC_IRQ_ERROR_MASK \
160 (DSI_VC_IRQ_CS | DSI_VC_IRQ_ECC_CORR | DSI_VC_IRQ_FIFO_TX_OVF | \
161 DSI_VC_IRQ_FIFO_RX_OVF | DSI_VC_IRQ_ECC_NO_CORR | \
162 DSI_VC_IRQ_FIFO_TX_UDF)
163
164/* ComplexIO interrupts */
165#define DSI_CIO_IRQ_ERRSYNCESC1 (1 << 0)
166#define DSI_CIO_IRQ_ERRSYNCESC2 (1 << 1)
167#define DSI_CIO_IRQ_ERRSYNCESC3 (1 << 2)
Tomi Valkeinen67056152011-03-24 16:30:17 +0200168#define DSI_CIO_IRQ_ERRSYNCESC4 (1 << 3)
169#define DSI_CIO_IRQ_ERRSYNCESC5 (1 << 4)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200170#define DSI_CIO_IRQ_ERRESC1 (1 << 5)
171#define DSI_CIO_IRQ_ERRESC2 (1 << 6)
172#define DSI_CIO_IRQ_ERRESC3 (1 << 7)
Tomi Valkeinen67056152011-03-24 16:30:17 +0200173#define DSI_CIO_IRQ_ERRESC4 (1 << 8)
174#define DSI_CIO_IRQ_ERRESC5 (1 << 9)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200175#define DSI_CIO_IRQ_ERRCONTROL1 (1 << 10)
176#define DSI_CIO_IRQ_ERRCONTROL2 (1 << 11)
177#define DSI_CIO_IRQ_ERRCONTROL3 (1 << 12)
Tomi Valkeinen67056152011-03-24 16:30:17 +0200178#define DSI_CIO_IRQ_ERRCONTROL4 (1 << 13)
179#define DSI_CIO_IRQ_ERRCONTROL5 (1 << 14)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200180#define DSI_CIO_IRQ_STATEULPS1 (1 << 15)
181#define DSI_CIO_IRQ_STATEULPS2 (1 << 16)
182#define DSI_CIO_IRQ_STATEULPS3 (1 << 17)
Tomi Valkeinen67056152011-03-24 16:30:17 +0200183#define DSI_CIO_IRQ_STATEULPS4 (1 << 18)
184#define DSI_CIO_IRQ_STATEULPS5 (1 << 19)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200185#define DSI_CIO_IRQ_ERRCONTENTIONLP0_1 (1 << 20)
186#define DSI_CIO_IRQ_ERRCONTENTIONLP1_1 (1 << 21)
187#define DSI_CIO_IRQ_ERRCONTENTIONLP0_2 (1 << 22)
188#define DSI_CIO_IRQ_ERRCONTENTIONLP1_2 (1 << 23)
189#define DSI_CIO_IRQ_ERRCONTENTIONLP0_3 (1 << 24)
190#define DSI_CIO_IRQ_ERRCONTENTIONLP1_3 (1 << 25)
Tomi Valkeinen67056152011-03-24 16:30:17 +0200191#define DSI_CIO_IRQ_ERRCONTENTIONLP0_4 (1 << 26)
192#define DSI_CIO_IRQ_ERRCONTENTIONLP1_4 (1 << 27)
193#define DSI_CIO_IRQ_ERRCONTENTIONLP0_5 (1 << 28)
194#define DSI_CIO_IRQ_ERRCONTENTIONLP1_5 (1 << 29)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200195#define DSI_CIO_IRQ_ULPSACTIVENOT_ALL0 (1 << 30)
196#define DSI_CIO_IRQ_ULPSACTIVENOT_ALL1 (1 << 31)
Tomi Valkeinenbbecb502010-05-10 14:35:33 +0300197#define DSI_CIO_IRQ_ERROR_MASK \
198 (DSI_CIO_IRQ_ERRSYNCESC1 | DSI_CIO_IRQ_ERRSYNCESC2 | \
Tomi Valkeinen67056152011-03-24 16:30:17 +0200199 DSI_CIO_IRQ_ERRSYNCESC3 | DSI_CIO_IRQ_ERRSYNCESC4 | \
200 DSI_CIO_IRQ_ERRSYNCESC5 | \
201 DSI_CIO_IRQ_ERRESC1 | DSI_CIO_IRQ_ERRESC2 | \
202 DSI_CIO_IRQ_ERRESC3 | DSI_CIO_IRQ_ERRESC4 | \
203 DSI_CIO_IRQ_ERRESC5 | \
204 DSI_CIO_IRQ_ERRCONTROL1 | DSI_CIO_IRQ_ERRCONTROL2 | \
205 DSI_CIO_IRQ_ERRCONTROL3 | DSI_CIO_IRQ_ERRCONTROL4 | \
206 DSI_CIO_IRQ_ERRCONTROL5 | \
Tomi Valkeinenbbecb502010-05-10 14:35:33 +0300207 DSI_CIO_IRQ_ERRCONTENTIONLP0_1 | DSI_CIO_IRQ_ERRCONTENTIONLP1_1 | \
208 DSI_CIO_IRQ_ERRCONTENTIONLP0_2 | DSI_CIO_IRQ_ERRCONTENTIONLP1_2 | \
Tomi Valkeinen67056152011-03-24 16:30:17 +0200209 DSI_CIO_IRQ_ERRCONTENTIONLP0_3 | DSI_CIO_IRQ_ERRCONTENTIONLP1_3 | \
210 DSI_CIO_IRQ_ERRCONTENTIONLP0_4 | DSI_CIO_IRQ_ERRCONTENTIONLP1_4 | \
211 DSI_CIO_IRQ_ERRCONTENTIONLP0_5 | DSI_CIO_IRQ_ERRCONTENTIONLP1_5)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200212
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200213typedef void (*omap_dsi_isr_t) (void *arg, u32 mask);
214
Tomi Valkeinenb7dec9b2013-02-22 12:58:35 +0200215static int dsi_display_init_dispc(struct platform_device *dsidev,
216 struct omap_overlay_manager *mgr);
217static void dsi_display_uninit_dispc(struct platform_device *dsidev,
218 struct omap_overlay_manager *mgr);
219
Tomi Valkeinen5cfc1c32013-05-15 11:24:30 +0300220static int dsi_vc_send_null(struct omap_dss_device *dssdev, int channel);
221
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200222#define DSI_MAX_NR_ISRS 2
Tomi Valkeinen739a7f42011-10-13 11:22:06 +0300223#define DSI_MAX_NR_LANES 5
224
225enum dsi_lane_function {
226 DSI_LANE_UNUSED = 0,
227 DSI_LANE_CLK,
228 DSI_LANE_DATA1,
229 DSI_LANE_DATA2,
230 DSI_LANE_DATA3,
231 DSI_LANE_DATA4,
232};
233
234struct dsi_lane_config {
235 enum dsi_lane_function function;
236 u8 polarity;
237};
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200238
239struct dsi_isr_data {
240 omap_dsi_isr_t isr;
241 void *arg;
242 u32 mask;
243};
244
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200245enum fifo_size {
246 DSI_FIFO_SIZE_0 = 0,
247 DSI_FIFO_SIZE_32 = 1,
248 DSI_FIFO_SIZE_64 = 2,
249 DSI_FIFO_SIZE_96 = 3,
250 DSI_FIFO_SIZE_128 = 4,
251};
252
Archit Tanejad6049142011-08-22 11:58:08 +0530253enum dsi_vc_source {
254 DSI_VC_SOURCE_L4 = 0,
255 DSI_VC_SOURCE_VP,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200256};
257
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200258struct dsi_irq_stats {
259 unsigned long last_reset;
260 unsigned irq_count;
261 unsigned dsi_irqs[32];
262 unsigned vc_irqs[4][32];
263 unsigned cio_irqs[32];
264};
265
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200266struct dsi_isr_tables {
267 struct dsi_isr_data isr_table[DSI_MAX_NR_ISRS];
268 struct dsi_isr_data isr_table_vc[4][DSI_MAX_NR_ISRS];
269 struct dsi_isr_data isr_table_cio[DSI_MAX_NR_ISRS];
270};
271
Tomi Valkeinenf1e00012013-03-05 17:21:35 +0200272struct dsi_clk_calc_ctx {
273 struct platform_device *dsidev;
274
275 /* inputs */
276
277 const struct omap_dss_dsi_config *config;
278
279 unsigned long req_pck_min, req_pck_nom, req_pck_max;
280
281 /* outputs */
282
283 struct dsi_clock_info dsi_cinfo;
284 struct dispc_clock_info dispc_cinfo;
285
286 struct omap_video_timings dispc_vm;
287 struct omap_dss_dsi_videomode_timings dsi_vm;
288};
289
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530290struct dsi_data {
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +0000291 struct platform_device *pdev;
Tomi Valkeinen68104462013-12-17 13:53:28 +0200292 void __iomem *proto_base;
293 void __iomem *phy_base;
294 void __iomem *pll_base;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300295
Tomi Valkeinen11ee9602012-03-09 16:07:39 +0200296 int module_id;
297
archit tanejaaffe3602011-02-23 08:41:03 +0000298 int irq;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200299
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300300 struct clk *dss_clk;
301 struct clk *sys_clk;
302
Tomi Valkeinena0d269e2012-11-27 17:05:54 +0200303 struct dispc_clock_info user_dispc_cinfo;
304 struct dsi_clock_info user_dsi_cinfo;
305
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200306 struct dsi_clock_info current_cinfo;
307
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +0300308 bool vdds_dsi_enabled;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200309 struct regulator *vdds_dsi_reg;
310
311 struct {
Archit Tanejad6049142011-08-22 11:58:08 +0530312 enum dsi_vc_source source;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200313 struct omap_dss_device *dssdev;
Tomi Valkeinen558c73e2013-09-25 14:40:06 +0300314 enum fifo_size tx_fifo_size;
315 enum fifo_size rx_fifo_size;
Archit Taneja5ee3c142011-03-02 12:35:53 +0530316 int vc_id;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200317 } vc[4];
318
319 struct mutex lock;
Tomi Valkeinenb9eb5d72010-01-11 16:33:56 +0200320 struct semaphore bus_lock;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200321
322 unsigned pll_locked;
323
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200324 spinlock_t irq_lock;
325 struct dsi_isr_tables isr_tables;
326 /* space for a copy used by the interrupt handler */
327 struct dsi_isr_tables isr_tables_copy;
328
Tomi Valkeinen18946f62010-01-12 14:16:41 +0200329 int update_channel;
Tomi Valkeinen477fed72013-10-02 14:41:24 +0300330#ifdef DSI_PERF_MEASURE
Tomi Valkeinen5476e742011-11-03 16:34:20 +0200331 unsigned update_bytes;
332#endif
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200333
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200334 bool te_enabled;
Tomi Valkeinen40885ab2010-07-28 15:53:38 +0300335 bool ulps_enabled;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200336
Tomi Valkeinen18946f62010-01-12 14:16:41 +0200337 void (*framedone_callback)(int, void *);
338 void *framedone_data;
339
340 struct delayed_work framedone_timeout_work;
341
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200342#ifdef DSI_CATCH_MISSING_TE
343 struct timer_list te_timer;
344#endif
345
346 unsigned long cache_req_pck;
347 unsigned long cache_clk_freq;
348 struct dsi_clock_info cache_cinfo;
349
350 u32 errors;
351 spinlock_t errors_lock;
Tomi Valkeinen477fed72013-10-02 14:41:24 +0300352#ifdef DSI_PERF_MEASURE
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200353 ktime_t perf_setup_time;
354 ktime_t perf_start_time;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200355#endif
356 int debug_read;
357 int debug_write;
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200358
359#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
360 spinlock_t irq_stats_lock;
361 struct dsi_irq_stats irq_stats;
362#endif
Taneja, Archit49641112011-03-14 23:28:23 -0500363 /* DSI PLL Parameter Ranges */
364 unsigned long regm_max, regn_max;
365 unsigned long regm_dispc_max, regm_dsi_max;
366 unsigned long fint_min, fint_max;
367 unsigned long lpdiv_max;
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +0300368
Tomi Valkeinend9820852011-10-12 15:05:59 +0300369 unsigned num_lanes_supported;
Tomi Valkeinen99322572013-03-05 10:37:02 +0200370 unsigned line_buffer_size;
Archit Taneja75d72472011-05-16 15:17:08 +0530371
Tomi Valkeinen739a7f42011-10-13 11:22:06 +0300372 struct dsi_lane_config lanes[DSI_MAX_NR_LANES];
373 unsigned num_lanes_used;
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +0300374
375 unsigned scp_clk_refcount;
Archit Taneja7d2572f2012-06-29 14:31:07 +0530376
377 struct dss_lcd_mgr_config mgr_config;
Archit Tanejae67458a2012-08-13 14:17:30 +0530378 struct omap_video_timings timings;
Archit Taneja02c39602012-08-10 15:01:33 +0530379 enum omap_dss_dsi_pixel_format pix_fmt;
Archit Tanejadca2b152012-08-16 18:02:00 +0530380 enum omap_dss_dsi_mode mode;
Archit Taneja0b3ffe32012-08-13 22:13:39 +0530381 struct omap_dss_dsi_videomode_timings vm_timings;
Archit Taneja81b87f52012-09-26 16:30:49 +0530382
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +0300383 struct omap_dss_device output;
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530384};
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200385
Archit Taneja2e868db2011-05-12 17:26:28 +0530386struct dsi_packet_sent_handler_data {
387 struct platform_device *dsidev;
388 struct completion *completion;
389};
390
Tomi Valkeinen6274a612012-08-21 15:35:42 +0300391struct dsi_module_id_data {
392 u32 address;
393 int id;
394};
395
396static const struct of_device_id dsi_of_match[];
397
Tomi Valkeinen477fed72013-10-02 14:41:24 +0300398#ifdef DSI_PERF_MEASURE
Rusty Russell90ab5ee2012-01-13 09:32:20 +1030399static bool dsi_perf;
400module_param(dsi_perf, bool, 0644);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200401#endif
402
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530403static inline struct dsi_data *dsi_get_dsidrv_data(struct platform_device *dsidev)
404{
405 return dev_get_drvdata(&dsidev->dev);
406}
407
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530408static inline struct platform_device *dsi_get_dsidev_from_dssdev(struct omap_dss_device *dssdev)
409{
Tomi Valkeinen5cfc1c32013-05-15 11:24:30 +0300410 return to_platform_device(dssdev->dev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530411}
412
413struct platform_device *dsi_get_dsidev_from_id(int module)
414{
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +0300415 struct omap_dss_device *out;
Archit Taneja400e65d2012-07-04 13:48:34 +0530416 enum omap_dss_output_id id;
417
Tomi Valkeinen78e7f252012-10-15 12:48:11 +0300418 switch (module) {
419 case 0:
420 id = OMAP_DSS_OUTPUT_DSI1;
421 break;
422 case 1:
423 id = OMAP_DSS_OUTPUT_DSI2;
424 break;
425 default:
426 return NULL;
427 }
Archit Taneja400e65d2012-07-04 13:48:34 +0530428
429 out = omap_dss_get_output(id);
430
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +0300431 return out ? to_platform_device(out->dev) : NULL;
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530432}
433
434static inline void dsi_write_reg(struct platform_device *dsidev,
435 const struct dsi_reg idx, u32 val)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200436{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530437 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen68104462013-12-17 13:53:28 +0200438 void __iomem *base;
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530439
Tomi Valkeinen68104462013-12-17 13:53:28 +0200440 switch(idx.module) {
441 case DSI_PROTO: base = dsi->proto_base; break;
442 case DSI_PHY: base = dsi->phy_base; break;
443 case DSI_PLL: base = dsi->pll_base; break;
444 default: return;
445 }
446
447 __raw_writel(val, base + idx.idx);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200448}
449
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530450static inline u32 dsi_read_reg(struct platform_device *dsidev,
451 const struct dsi_reg idx)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200452{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530453 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen68104462013-12-17 13:53:28 +0200454 void __iomem *base;
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530455
Tomi Valkeinen68104462013-12-17 13:53:28 +0200456 switch(idx.module) {
457 case DSI_PROTO: base = dsi->proto_base; break;
458 case DSI_PHY: base = dsi->phy_base; break;
459 case DSI_PLL: base = dsi->pll_base; break;
460 default: return 0;
461 }
462
463 return __raw_readl(base + idx.idx);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200464}
465
Tomi Valkeinen5cfc1c32013-05-15 11:24:30 +0300466static void dsi_bus_lock(struct omap_dss_device *dssdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200467{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530468 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
469 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
470
471 down(&dsi->bus_lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200472}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200473
Tomi Valkeinen5cfc1c32013-05-15 11:24:30 +0300474static void dsi_bus_unlock(struct omap_dss_device *dssdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200475{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530476 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
477 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
478
479 up(&dsi->bus_lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200480}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200481
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530482static bool dsi_bus_is_locked(struct platform_device *dsidev)
Tomi Valkeinen4f765022010-01-18 16:27:52 +0200483{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530484 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
485
486 return dsi->bus_lock.count == 0;
Tomi Valkeinen4f765022010-01-18 16:27:52 +0200487}
488
Tomi Valkeinenf36a06e2011-03-02 14:48:41 +0200489static void dsi_completion_handler(void *data, u32 mask)
490{
491 complete((struct completion *)data);
492}
493
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530494static inline int wait_for_bit_change(struct platform_device *dsidev,
495 const struct dsi_reg idx, int bitnum, int value)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200496{
Tomi Valkeinen3b984092011-10-13 19:06:49 +0300497 unsigned long timeout;
498 ktime_t wait;
499 int t;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200500
Tomi Valkeinen3b984092011-10-13 19:06:49 +0300501 /* first busyloop to see if the bit changes right away */
502 t = 100;
503 while (t-- > 0) {
504 if (REG_GET(dsidev, idx, bitnum, bitnum) == value)
505 return value;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200506 }
507
Tomi Valkeinen3b984092011-10-13 19:06:49 +0300508 /* then loop for 500ms, sleeping for 1ms in between */
509 timeout = jiffies + msecs_to_jiffies(500);
510 while (time_before(jiffies, timeout)) {
511 if (REG_GET(dsidev, idx, bitnum, bitnum) == value)
512 return value;
513
514 wait = ns_to_ktime(1000 * 1000);
515 set_current_state(TASK_UNINTERRUPTIBLE);
516 schedule_hrtimeout(&wait, HRTIMER_MODE_REL);
517 }
518
519 return !value;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200520}
521
Archit Tanejaa3b3cc22011-09-08 18:42:16 +0530522u8 dsi_get_pixel_size(enum omap_dss_dsi_pixel_format fmt)
523{
524 switch (fmt) {
525 case OMAP_DSS_DSI_FMT_RGB888:
526 case OMAP_DSS_DSI_FMT_RGB666:
527 return 24;
528 case OMAP_DSS_DSI_FMT_RGB666_PACKED:
529 return 18;
530 case OMAP_DSS_DSI_FMT_RGB565:
531 return 16;
532 default:
533 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +0300534 return 0;
Archit Tanejaa3b3cc22011-09-08 18:42:16 +0530535 }
536}
537
Tomi Valkeinen477fed72013-10-02 14:41:24 +0300538#ifdef DSI_PERF_MEASURE
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530539static void dsi_perf_mark_setup(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200540{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530541 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
542 dsi->perf_setup_time = ktime_get();
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200543}
544
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530545static void dsi_perf_mark_start(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200546{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530547 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
548 dsi->perf_start_time = ktime_get();
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200549}
550
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530551static void dsi_perf_show(struct platform_device *dsidev, const char *name)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200552{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530553 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200554 ktime_t t, setup_time, trans_time;
555 u32 total_bytes;
556 u32 setup_us, trans_us, total_us;
557
558 if (!dsi_perf)
559 return;
560
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200561 t = ktime_get();
562
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530563 setup_time = ktime_sub(dsi->perf_start_time, dsi->perf_setup_time);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200564 setup_us = (u32)ktime_to_us(setup_time);
565 if (setup_us == 0)
566 setup_us = 1;
567
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530568 trans_time = ktime_sub(t, dsi->perf_start_time);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200569 trans_us = (u32)ktime_to_us(trans_time);
570 if (trans_us == 0)
571 trans_us = 1;
572
573 total_us = setup_us + trans_us;
574
Tomi Valkeinen5476e742011-11-03 16:34:20 +0200575 total_bytes = dsi->update_bytes;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200576
Tomi Valkeinen1bbb2752010-01-11 16:41:10 +0200577 printk(KERN_INFO "DSI(%s): %u us + %u us = %u us (%uHz), "
578 "%u bytes, %u kbytes/sec\n",
579 name,
580 setup_us,
581 trans_us,
582 total_us,
583 1000*1000 / total_us,
584 total_bytes,
585 total_bytes * 1000 / total_us);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200586}
587#else
Tomi Valkeinen4a9a5e32011-05-23 16:36:09 +0300588static inline void dsi_perf_mark_setup(struct platform_device *dsidev)
589{
590}
591
592static inline void dsi_perf_mark_start(struct platform_device *dsidev)
593{
594}
595
596static inline void dsi_perf_show(struct platform_device *dsidev,
597 const char *name)
598{
599}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200600#endif
601
Chandrabhanu Mahapatraf30be7d2012-09-29 12:33:05 +0530602static int verbose_irq;
603
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200604static void print_irq_status(u32 status)
605{
Tomi Valkeinend80d4992011-03-02 15:53:07 +0200606 if (status == 0)
607 return;
608
Chandrabhanu Mahapatraf30be7d2012-09-29 12:33:05 +0530609 if (!verbose_irq && (status & ~DSI_IRQ_CHANNEL_MASK) == 0)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200610 return;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200611
Chandrabhanu Mahapatraf30be7d2012-09-29 12:33:05 +0530612#define PIS(x) (status & DSI_IRQ_##x) ? (#x " ") : ""
613
614 pr_debug("DSI IRQ: 0x%x: %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
615 status,
616 verbose_irq ? PIS(VC0) : "",
617 verbose_irq ? PIS(VC1) : "",
618 verbose_irq ? PIS(VC2) : "",
619 verbose_irq ? PIS(VC3) : "",
620 PIS(WAKEUP),
621 PIS(RESYNC),
622 PIS(PLL_LOCK),
623 PIS(PLL_UNLOCK),
624 PIS(PLL_RECALL),
625 PIS(COMPLEXIO_ERR),
626 PIS(HS_TX_TIMEOUT),
627 PIS(LP_RX_TIMEOUT),
628 PIS(TE_TRIGGER),
629 PIS(ACK_TRIGGER),
630 PIS(SYNC_LOST),
631 PIS(LDO_POWER_GOOD),
632 PIS(TA_TIMEOUT));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200633#undef PIS
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200634}
635
636static void print_irq_status_vc(int channel, u32 status)
637{
Tomi Valkeinend80d4992011-03-02 15:53:07 +0200638 if (status == 0)
639 return;
640
Chandrabhanu Mahapatraf30be7d2012-09-29 12:33:05 +0530641 if (!verbose_irq && (status & ~DSI_VC_IRQ_PACKET_SENT) == 0)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200642 return;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200643
Chandrabhanu Mahapatraf30be7d2012-09-29 12:33:05 +0530644#define PIS(x) (status & DSI_VC_IRQ_##x) ? (#x " ") : ""
645
646 pr_debug("DSI VC(%d) IRQ 0x%x: %s%s%s%s%s%s%s%s%s\n",
647 channel,
648 status,
649 PIS(CS),
650 PIS(ECC_CORR),
651 PIS(ECC_NO_CORR),
652 verbose_irq ? PIS(PACKET_SENT) : "",
653 PIS(BTA),
654 PIS(FIFO_TX_OVF),
655 PIS(FIFO_RX_OVF),
656 PIS(FIFO_TX_UDF),
657 PIS(PP_BUSY_CHANGE));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200658#undef PIS
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200659}
660
661static void print_irq_status_cio(u32 status)
662{
Tomi Valkeinend80d4992011-03-02 15:53:07 +0200663 if (status == 0)
664 return;
665
Chandrabhanu Mahapatraf30be7d2012-09-29 12:33:05 +0530666#define PIS(x) (status & DSI_CIO_IRQ_##x) ? (#x " ") : ""
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200667
Chandrabhanu Mahapatraf30be7d2012-09-29 12:33:05 +0530668 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",
669 status,
670 PIS(ERRSYNCESC1),
671 PIS(ERRSYNCESC2),
672 PIS(ERRSYNCESC3),
673 PIS(ERRESC1),
674 PIS(ERRESC2),
675 PIS(ERRESC3),
676 PIS(ERRCONTROL1),
677 PIS(ERRCONTROL2),
678 PIS(ERRCONTROL3),
679 PIS(STATEULPS1),
680 PIS(STATEULPS2),
681 PIS(STATEULPS3),
682 PIS(ERRCONTENTIONLP0_1),
683 PIS(ERRCONTENTIONLP1_1),
684 PIS(ERRCONTENTIONLP0_2),
685 PIS(ERRCONTENTIONLP1_2),
686 PIS(ERRCONTENTIONLP0_3),
687 PIS(ERRCONTENTIONLP1_3),
688 PIS(ULPSACTIVENOT_ALL0),
689 PIS(ULPSACTIVENOT_ALL1));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200690#undef PIS
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200691}
692
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200693#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530694static void dsi_collect_irq_stats(struct platform_device *dsidev, u32 irqstatus,
695 u32 *vcstatus, u32 ciostatus)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200696{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530697 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200698 int i;
699
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530700 spin_lock(&dsi->irq_stats_lock);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200701
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530702 dsi->irq_stats.irq_count++;
703 dss_collect_irq_stats(irqstatus, dsi->irq_stats.dsi_irqs);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200704
705 for (i = 0; i < 4; ++i)
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530706 dss_collect_irq_stats(vcstatus[i], dsi->irq_stats.vc_irqs[i]);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200707
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530708 dss_collect_irq_stats(ciostatus, dsi->irq_stats.cio_irqs);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200709
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530710 spin_unlock(&dsi->irq_stats_lock);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200711}
712#else
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530713#define dsi_collect_irq_stats(dsidev, irqstatus, vcstatus, ciostatus)
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200714#endif
715
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200716static int debug_irq;
717
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530718static void dsi_handle_irq_errors(struct platform_device *dsidev, u32 irqstatus,
719 u32 *vcstatus, u32 ciostatus)
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200720{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530721 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200722 int i;
723
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200724 if (irqstatus & DSI_IRQ_ERROR_MASK) {
725 DSSERR("DSI error, irqstatus %x\n", irqstatus);
726 print_irq_status(irqstatus);
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530727 spin_lock(&dsi->errors_lock);
728 dsi->errors |= irqstatus & DSI_IRQ_ERROR_MASK;
729 spin_unlock(&dsi->errors_lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200730 } else if (debug_irq) {
731 print_irq_status(irqstatus);
732 }
733
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200734 for (i = 0; i < 4; ++i) {
735 if (vcstatus[i] & DSI_VC_IRQ_ERROR_MASK) {
736 DSSERR("DSI VC(%d) error, vc irqstatus %x\n",
737 i, vcstatus[i]);
738 print_irq_status_vc(i, vcstatus[i]);
739 } else if (debug_irq) {
740 print_irq_status_vc(i, vcstatus[i]);
741 }
742 }
743
744 if (ciostatus & DSI_CIO_IRQ_ERROR_MASK) {
745 DSSERR("DSI CIO error, cio irqstatus %x\n", ciostatus);
746 print_irq_status_cio(ciostatus);
747 } else if (debug_irq) {
748 print_irq_status_cio(ciostatus);
749 }
750}
751
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200752static void dsi_call_isrs(struct dsi_isr_data *isr_array,
753 unsigned isr_array_size, u32 irqstatus)
754{
755 struct dsi_isr_data *isr_data;
756 int i;
757
758 for (i = 0; i < isr_array_size; i++) {
759 isr_data = &isr_array[i];
760 if (isr_data->isr && isr_data->mask & irqstatus)
761 isr_data->isr(isr_data->arg, irqstatus);
762 }
763}
764
765static void dsi_handle_isrs(struct dsi_isr_tables *isr_tables,
766 u32 irqstatus, u32 *vcstatus, u32 ciostatus)
767{
768 int i;
769
770 dsi_call_isrs(isr_tables->isr_table,
771 ARRAY_SIZE(isr_tables->isr_table),
772 irqstatus);
773
774 for (i = 0; i < 4; ++i) {
775 if (vcstatus[i] == 0)
776 continue;
777 dsi_call_isrs(isr_tables->isr_table_vc[i],
778 ARRAY_SIZE(isr_tables->isr_table_vc[i]),
779 vcstatus[i]);
780 }
781
782 if (ciostatus != 0)
783 dsi_call_isrs(isr_tables->isr_table_cio,
784 ARRAY_SIZE(isr_tables->isr_table_cio),
785 ciostatus);
786}
787
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200788static irqreturn_t omap_dsi_irq_handler(int irq, void *arg)
789{
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530790 struct platform_device *dsidev;
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530791 struct dsi_data *dsi;
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200792 u32 irqstatus, vcstatus[4], ciostatus;
793 int i;
794
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530795 dsidev = (struct platform_device *) arg;
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530796 dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530797
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530798 spin_lock(&dsi->irq_lock);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200799
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530800 irqstatus = dsi_read_reg(dsidev, DSI_IRQSTATUS);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200801
802 /* IRQ is not for us */
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200803 if (!irqstatus) {
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530804 spin_unlock(&dsi->irq_lock);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200805 return IRQ_NONE;
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200806 }
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200807
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530808 dsi_write_reg(dsidev, DSI_IRQSTATUS, irqstatus & ~DSI_IRQ_CHANNEL_MASK);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200809 /* flush posted write */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530810 dsi_read_reg(dsidev, DSI_IRQSTATUS);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200811
812 for (i = 0; i < 4; ++i) {
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200813 if ((irqstatus & (1 << i)) == 0) {
814 vcstatus[i] = 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200815 continue;
Tomi Valkeinenab83b142010-06-09 15:31:01 +0300816 }
817
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530818 vcstatus[i] = dsi_read_reg(dsidev, DSI_VC_IRQSTATUS(i));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200819
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530820 dsi_write_reg(dsidev, DSI_VC_IRQSTATUS(i), vcstatus[i]);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200821 /* flush posted write */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530822 dsi_read_reg(dsidev, DSI_VC_IRQSTATUS(i));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200823 }
824
825 if (irqstatus & DSI_IRQ_COMPLEXIO_ERR) {
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530826 ciostatus = dsi_read_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200827
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530828 dsi_write_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS, ciostatus);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200829 /* flush posted write */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530830 dsi_read_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200831 } else {
832 ciostatus = 0;
833 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200834
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200835#ifdef DSI_CATCH_MISSING_TE
836 if (irqstatus & DSI_IRQ_TE_TRIGGER)
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530837 del_timer(&dsi->te_timer);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200838#endif
839
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200840 /* make a copy and unlock, so that isrs can unregister
841 * themselves */
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530842 memcpy(&dsi->isr_tables_copy, &dsi->isr_tables,
843 sizeof(dsi->isr_tables));
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200844
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530845 spin_unlock(&dsi->irq_lock);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200846
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530847 dsi_handle_isrs(&dsi->isr_tables_copy, irqstatus, vcstatus, ciostatus);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200848
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530849 dsi_handle_irq_errors(dsidev, irqstatus, vcstatus, ciostatus);
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +0200850
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530851 dsi_collect_irq_stats(dsidev, irqstatus, vcstatus, ciostatus);
Tomi Valkeinen69b281a2011-03-02 14:44:27 +0200852
archit tanejaaffe3602011-02-23 08:41:03 +0000853 return IRQ_HANDLED;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200854}
855
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530856/* dsi->irq_lock has to be locked by the caller */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530857static void _omap_dsi_configure_irqs(struct platform_device *dsidev,
858 struct dsi_isr_data *isr_array,
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200859 unsigned isr_array_size, u32 default_mask,
860 const struct dsi_reg enable_reg,
861 const struct dsi_reg status_reg)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200862{
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200863 struct dsi_isr_data *isr_data;
864 u32 mask;
865 u32 old_mask;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200866 int i;
867
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200868 mask = default_mask;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200869
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200870 for (i = 0; i < isr_array_size; i++) {
871 isr_data = &isr_array[i];
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200872
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200873 if (isr_data->isr == NULL)
874 continue;
875
876 mask |= isr_data->mask;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200877 }
878
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530879 old_mask = dsi_read_reg(dsidev, enable_reg);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200880 /* clear the irqstatus for newly enabled irqs */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530881 dsi_write_reg(dsidev, status_reg, (mask ^ old_mask) & mask);
882 dsi_write_reg(dsidev, enable_reg, mask);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200883
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200884 /* flush posted writes */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530885 dsi_read_reg(dsidev, enable_reg);
886 dsi_read_reg(dsidev, status_reg);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200887}
888
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530889/* dsi->irq_lock has to be locked by the caller */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530890static void _omap_dsi_set_irqs(struct platform_device *dsidev)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200891{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530892 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200893 u32 mask = DSI_IRQ_ERROR_MASK;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200894#ifdef DSI_CATCH_MISSING_TE
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200895 mask |= DSI_IRQ_TE_TRIGGER;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200896#endif
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530897 _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table,
898 ARRAY_SIZE(dsi->isr_tables.isr_table), mask,
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200899 DSI_IRQENABLE, DSI_IRQSTATUS);
900}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200901
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530902/* dsi->irq_lock has to be locked by the caller */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530903static void _omap_dsi_set_irqs_vc(struct platform_device *dsidev, int vc)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200904{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530905 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
906
907 _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table_vc[vc],
908 ARRAY_SIZE(dsi->isr_tables.isr_table_vc[vc]),
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200909 DSI_VC_IRQ_ERROR_MASK,
910 DSI_VC_IRQENABLE(vc), DSI_VC_IRQSTATUS(vc));
911}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +0200912
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530913/* dsi->irq_lock has to be locked by the caller */
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530914static void _omap_dsi_set_irqs_cio(struct platform_device *dsidev)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200915{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530916 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
917
918 _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table_cio,
919 ARRAY_SIZE(dsi->isr_tables.isr_table_cio),
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200920 DSI_CIO_IRQ_ERROR_MASK,
921 DSI_COMPLEXIO_IRQ_ENABLE, DSI_COMPLEXIO_IRQ_STATUS);
922}
923
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530924static void _dsi_initialize_irq(struct platform_device *dsidev)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200925{
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530926 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200927 unsigned long flags;
928 int vc;
929
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530930 spin_lock_irqsave(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200931
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530932 memset(&dsi->isr_tables, 0, sizeof(dsi->isr_tables));
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200933
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530934 _omap_dsi_set_irqs(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200935 for (vc = 0; vc < 4; ++vc)
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530936 _omap_dsi_set_irqs_vc(dsidev, vc);
937 _omap_dsi_set_irqs_cio(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200938
Archit Tanejaf1da39d2011-05-12 17:26:27 +0530939 spin_unlock_irqrestore(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +0200940}
941
942static int _dsi_register_isr(omap_dsi_isr_t isr, void *arg, u32 mask,
943 struct dsi_isr_data *isr_array, unsigned isr_array_size)
944{
945 struct dsi_isr_data *isr_data;
946 int free_idx;
947 int i;
948
949 BUG_ON(isr == NULL);
950
951 /* check for duplicate entry and find a free slot */
952 free_idx = -1;
953 for (i = 0; i < isr_array_size; i++) {
954 isr_data = &isr_array[i];
955
956 if (isr_data->isr == isr && isr_data->arg == arg &&
957 isr_data->mask == mask) {
958 return -EINVAL;
959 }
960
961 if (isr_data->isr == NULL && free_idx == -1)
962 free_idx = i;
963 }
964
965 if (free_idx == -1)
966 return -EBUSY;
967
968 isr_data = &isr_array[free_idx];
969 isr_data->isr = isr;
970 isr_data->arg = arg;
971 isr_data->mask = mask;
972
973 return 0;
974}
975
976static int _dsi_unregister_isr(omap_dsi_isr_t isr, void *arg, u32 mask,
977 struct dsi_isr_data *isr_array, unsigned isr_array_size)
978{
979 struct dsi_isr_data *isr_data;
980 int i;
981
982 for (i = 0; i < isr_array_size; i++) {
983 isr_data = &isr_array[i];
984 if (isr_data->isr != isr || isr_data->arg != arg ||
985 isr_data->mask != mask)
986 continue;
987
988 isr_data->isr = NULL;
989 isr_data->arg = NULL;
990 isr_data->mask = 0;
991
992 return 0;
993 }
994
995 return -EINVAL;
996}
997
Archit Tanejaa72b64b2011-05-12 17:26:26 +0530998static int dsi_register_isr(struct platform_device *dsidev, omap_dsi_isr_t isr,
999 void *arg, u32 mask)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001000{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301001 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001002 unsigned long flags;
1003 int r;
1004
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301005 spin_lock_irqsave(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001006
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301007 r = _dsi_register_isr(isr, arg, mask, dsi->isr_tables.isr_table,
1008 ARRAY_SIZE(dsi->isr_tables.isr_table));
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001009
1010 if (r == 0)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301011 _omap_dsi_set_irqs(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001012
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301013 spin_unlock_irqrestore(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001014
1015 return r;
1016}
1017
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301018static int dsi_unregister_isr(struct platform_device *dsidev,
1019 omap_dsi_isr_t isr, void *arg, u32 mask)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001020{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301021 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001022 unsigned long flags;
1023 int r;
1024
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301025 spin_lock_irqsave(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001026
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301027 r = _dsi_unregister_isr(isr, arg, mask, dsi->isr_tables.isr_table,
1028 ARRAY_SIZE(dsi->isr_tables.isr_table));
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001029
1030 if (r == 0)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301031 _omap_dsi_set_irqs(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001032
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301033 spin_unlock_irqrestore(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001034
1035 return r;
1036}
1037
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301038static int dsi_register_isr_vc(struct platform_device *dsidev, int channel,
1039 omap_dsi_isr_t isr, void *arg, u32 mask)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001040{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301041 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001042 unsigned long flags;
1043 int r;
1044
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301045 spin_lock_irqsave(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001046
1047 r = _dsi_register_isr(isr, arg, mask,
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301048 dsi->isr_tables.isr_table_vc[channel],
1049 ARRAY_SIZE(dsi->isr_tables.isr_table_vc[channel]));
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001050
1051 if (r == 0)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301052 _omap_dsi_set_irqs_vc(dsidev, channel);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001053
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301054 spin_unlock_irqrestore(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001055
1056 return r;
1057}
1058
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301059static int dsi_unregister_isr_vc(struct platform_device *dsidev, int channel,
1060 omap_dsi_isr_t isr, void *arg, u32 mask)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001061{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301062 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001063 unsigned long flags;
1064 int r;
1065
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301066 spin_lock_irqsave(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001067
1068 r = _dsi_unregister_isr(isr, arg, mask,
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301069 dsi->isr_tables.isr_table_vc[channel],
1070 ARRAY_SIZE(dsi->isr_tables.isr_table_vc[channel]));
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001071
1072 if (r == 0)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301073 _omap_dsi_set_irqs_vc(dsidev, channel);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001074
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301075 spin_unlock_irqrestore(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001076
1077 return r;
1078}
1079
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301080static int dsi_register_isr_cio(struct platform_device *dsidev,
1081 omap_dsi_isr_t isr, void *arg, u32 mask)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001082{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301083 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001084 unsigned long flags;
1085 int r;
1086
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301087 spin_lock_irqsave(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001088
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301089 r = _dsi_register_isr(isr, arg, mask, dsi->isr_tables.isr_table_cio,
1090 ARRAY_SIZE(dsi->isr_tables.isr_table_cio));
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001091
1092 if (r == 0)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301093 _omap_dsi_set_irqs_cio(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001094
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301095 spin_unlock_irqrestore(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001096
1097 return r;
1098}
1099
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301100static int dsi_unregister_isr_cio(struct platform_device *dsidev,
1101 omap_dsi_isr_t isr, void *arg, u32 mask)
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001102{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301103 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001104 unsigned long flags;
1105 int r;
1106
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301107 spin_lock_irqsave(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001108
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301109 r = _dsi_unregister_isr(isr, arg, mask, dsi->isr_tables.isr_table_cio,
1110 ARRAY_SIZE(dsi->isr_tables.isr_table_cio));
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001111
1112 if (r == 0)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301113 _omap_dsi_set_irqs_cio(dsidev);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001114
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301115 spin_unlock_irqrestore(&dsi->irq_lock, flags);
Tomi Valkeinen4ae2ddd2011-03-02 14:47:04 +02001116
1117 return r;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001118}
1119
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301120static u32 dsi_get_errors(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001121{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301122 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001123 unsigned long flags;
1124 u32 e;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301125 spin_lock_irqsave(&dsi->errors_lock, flags);
1126 e = dsi->errors;
1127 dsi->errors = 0;
1128 spin_unlock_irqrestore(&dsi->errors_lock, flags);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001129 return e;
1130}
1131
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001132int dsi_runtime_get(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001133{
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001134 int r;
1135 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1136
1137 DSSDBG("dsi_runtime_get\n");
1138
1139 r = pm_runtime_get_sync(&dsi->pdev->dev);
1140 WARN_ON(r < 0);
1141 return r < 0 ? r : 0;
1142}
1143
1144void dsi_runtime_put(struct platform_device *dsidev)
1145{
1146 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1147 int r;
1148
1149 DSSDBG("dsi_runtime_put\n");
1150
Tomi Valkeinen0eaf9f52012-01-23 13:23:08 +02001151 r = pm_runtime_put_sync(&dsi->pdev->dev);
Tomi Valkeinen5be3aeb2012-06-27 16:37:18 +03001152 WARN_ON(r < 0 && r != -ENOSYS);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001153}
1154
Tomi Valkeinenb2541c42013-05-03 13:42:24 +03001155static int dsi_regulator_init(struct platform_device *dsidev)
1156{
1157 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1158 struct regulator *vdds_dsi;
1159
1160 if (dsi->vdds_dsi_reg != NULL)
1161 return 0;
1162
Tomi Valkeinene6fa68b2014-01-02 12:54:31 +02001163 if (dsi->pdev->dev.of_node)
1164 vdds_dsi = devm_regulator_get(&dsi->pdev->dev, "vdd");
1165 else
1166 vdds_dsi = devm_regulator_get(&dsi->pdev->dev, "vdds_dsi");
Tomi Valkeinenb2541c42013-05-03 13:42:24 +03001167
1168 /* DT HACK: try VCXIO to make omapdss work for o4 sdp/panda */
1169 if (IS_ERR(vdds_dsi))
1170 vdds_dsi = devm_regulator_get(&dsi->pdev->dev, "VCXIO");
1171
1172 if (IS_ERR(vdds_dsi)) {
Tomi Valkeinen40359a92013-12-19 16:15:34 +02001173 if (PTR_ERR(vdds_dsi) != -EPROBE_DEFER)
1174 DSSERR("can't get VDDS_DSI regulator\n");
Tomi Valkeinenb2541c42013-05-03 13:42:24 +03001175 return PTR_ERR(vdds_dsi);
1176 }
1177
1178 dsi->vdds_dsi_reg = vdds_dsi;
1179
1180 return 0;
1181}
1182
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001183/* source clock for DSI PLL. this could also be PCLKFREE */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301184static inline void dsi_enable_pll_clock(struct platform_device *dsidev,
1185 bool enable)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001186{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301187 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1188
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001189 if (enable)
Rajendra Nayakf11766d2012-06-27 14:21:26 +05301190 clk_prepare_enable(dsi->sys_clk);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001191 else
Rajendra Nayakf11766d2012-06-27 14:21:26 +05301192 clk_disable_unprepare(dsi->sys_clk);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001193
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301194 if (enable && dsi->pll_locked) {
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301195 if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 1, 1) != 1)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001196 DSSERR("cannot lock PLL when enabling clocks\n");
1197 }
1198}
1199
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301200static void _dsi_print_reset_status(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001201{
1202 u32 l;
Tomi Valkeinenc335cbf2010-10-07 13:27:42 +03001203 int b0, b1, b2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001204
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001205 /* A dummy read using the SCP interface to any DSIPHY register is
1206 * required after DSIPHY reset to complete the reset of the DSI complex
1207 * I/O. */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301208 l = dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001209
Tomi Valkeinenc335cbf2010-10-07 13:27:42 +03001210 if (dss_has_feature(FEAT_DSI_REVERSE_TXCLKESC)) {
1211 b0 = 28;
1212 b1 = 27;
1213 b2 = 26;
1214 } else {
1215 b0 = 24;
1216 b1 = 25;
1217 b2 = 26;
1218 }
1219
Chandrabhanu Mahapatraf30be7d2012-09-29 12:33:05 +05301220#define DSI_FLD_GET(fld, start, end)\
1221 FLD_GET(dsi_read_reg(dsidev, DSI_##fld), start, end)
1222
1223 pr_debug("DSI resets: PLL (%d) CIO (%d) PHY (%x%x%x, %d, %d, %d)\n",
1224 DSI_FLD_GET(PLL_STATUS, 0, 0),
1225 DSI_FLD_GET(COMPLEXIO_CFG1, 29, 29),
1226 DSI_FLD_GET(DSIPHY_CFG5, b0, b0),
1227 DSI_FLD_GET(DSIPHY_CFG5, b1, b1),
1228 DSI_FLD_GET(DSIPHY_CFG5, b2, b2),
1229 DSI_FLD_GET(DSIPHY_CFG5, 29, 29),
1230 DSI_FLD_GET(DSIPHY_CFG5, 30, 30),
1231 DSI_FLD_GET(DSIPHY_CFG5, 31, 31));
1232
1233#undef DSI_FLD_GET
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001234}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001235
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301236static inline int dsi_if_enable(struct platform_device *dsidev, bool enable)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001237{
1238 DSSDBG("dsi_if_enable(%d)\n", enable);
1239
1240 enable = enable ? 1 : 0;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301241 REG_FLD_MOD(dsidev, DSI_CTRL, enable, 0, 0); /* IF_EN */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001242
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301243 if (wait_for_bit_change(dsidev, DSI_CTRL, 0, enable) != enable) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001244 DSSERR("Failed to set dsi_if_enable to %d\n", enable);
1245 return -EIO;
1246 }
1247
1248 return 0;
1249}
1250
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301251unsigned long dsi_get_pll_hsdiv_dispc_rate(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001252{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301253 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1254
1255 return dsi->current_cinfo.dsi_pll_hsdiv_dispc_clk;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001256}
1257
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301258static unsigned long dsi_get_pll_hsdiv_dsi_rate(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001259{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301260 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1261
1262 return dsi->current_cinfo.dsi_pll_hsdiv_dsi_clk;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001263}
1264
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301265static unsigned long dsi_get_txbyteclkhs(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001266{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301267 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1268
1269 return dsi->current_cinfo.clkin4ddr / 16;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001270}
1271
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301272static unsigned long dsi_fclk_rate(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001273{
1274 unsigned long r;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001275 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001276
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02001277 if (dss_get_dsi_clk_source(dsi->module_id) == OMAP_DSS_CLK_SRC_FCK) {
Archit Taneja1bb47832011-02-24 14:17:30 +05301278 /* DSI FCLK source is DSS_CLK_FCK */
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001279 r = clk_get_rate(dsi->dss_clk);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001280 } else {
Archit Taneja1bb47832011-02-24 14:17:30 +05301281 /* DSI FCLK source is dsi_pll_hsdiv_dsi_clk */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301282 r = dsi_get_pll_hsdiv_dsi_rate(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001283 }
1284
1285 return r;
1286}
1287
Tomi Valkeinenf1e00012013-03-05 17:21:35 +02001288static int dsi_lp_clock_calc(struct dsi_clock_info *cinfo,
1289 unsigned long lp_clk_min, unsigned long lp_clk_max)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001290{
Tomi Valkeinenf1e00012013-03-05 17:21:35 +02001291 unsigned long dsi_fclk = cinfo->dsi_pll_hsdiv_dsi_clk;
1292 unsigned lp_clk_div;
1293 unsigned long lp_clk;
1294
1295 lp_clk_div = DIV_ROUND_UP(dsi_fclk, lp_clk_max * 2);
1296 lp_clk = dsi_fclk / 2 / lp_clk_div;
1297
1298 if (lp_clk < lp_clk_min || lp_clk > lp_clk_max)
1299 return -EINVAL;
1300
1301 cinfo->lp_clk_div = lp_clk_div;
1302 cinfo->lp_clk = lp_clk;
1303
1304 return 0;
1305}
1306
Tomi Valkeinen57612172012-11-27 17:32:36 +02001307static int dsi_set_lp_clk_divisor(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001308{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301309 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001310 unsigned long dsi_fclk;
1311 unsigned lp_clk_div;
1312 unsigned long lp_clk;
1313
Tomi Valkeinena0d269e2012-11-27 17:05:54 +02001314 lp_clk_div = dsi->user_dsi_cinfo.lp_clk_div;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001315
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301316 if (lp_clk_div == 0 || lp_clk_div > dsi->lpdiv_max)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001317 return -EINVAL;
1318
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301319 dsi_fclk = dsi_fclk_rate(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001320
1321 lp_clk = dsi_fclk / 2 / lp_clk_div;
1322
1323 DSSDBG("LP_CLK_DIV %u, LP_CLK %lu\n", lp_clk_div, lp_clk);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301324 dsi->current_cinfo.lp_clk = lp_clk;
1325 dsi->current_cinfo.lp_clk_div = lp_clk_div;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001326
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301327 /* LP_CLK_DIVISOR */
1328 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, lp_clk_div, 12, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001329
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301330 /* LP_RX_SYNCHRO_ENABLE */
1331 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, dsi_fclk > 30000000 ? 1 : 0, 21, 21);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001332
1333 return 0;
1334}
1335
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301336static void dsi_enable_scp_clk(struct platform_device *dsidev)
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +03001337{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301338 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1339
1340 if (dsi->scp_clk_refcount++ == 0)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301341 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 1, 14, 14); /* CIO_CLK_ICG */
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +03001342}
1343
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301344static void dsi_disable_scp_clk(struct platform_device *dsidev)
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +03001345{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301346 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1347
1348 WARN_ON(dsi->scp_clk_refcount == 0);
1349 if (--dsi->scp_clk_refcount == 0)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301350 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 14, 14); /* CIO_CLK_ICG */
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +03001351}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001352
1353enum dsi_pll_power_state {
1354 DSI_PLL_POWER_OFF = 0x0,
1355 DSI_PLL_POWER_ON_HSCLK = 0x1,
1356 DSI_PLL_POWER_ON_ALL = 0x2,
1357 DSI_PLL_POWER_ON_DIV = 0x3,
1358};
1359
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301360static int dsi_pll_power(struct platform_device *dsidev,
1361 enum dsi_pll_power_state state)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001362{
1363 int t = 0;
1364
Tomi Valkeinenc94dfe052011-04-15 10:42:59 +03001365 /* DSI-PLL power command 0x3 is not working */
1366 if (dss_has_feature(FEAT_DSI_PLL_PWR_BUG) &&
1367 state == DSI_PLL_POWER_ON_DIV)
1368 state = DSI_PLL_POWER_ON_ALL;
1369
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301370 /* PLL_PWR_CMD */
1371 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, state, 31, 30);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001372
1373 /* PLL_PWR_STATUS */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301374 while (FLD_GET(dsi_read_reg(dsidev, DSI_CLK_CTRL), 29, 28) != state) {
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02001375 if (++t > 1000) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001376 DSSERR("Failed to set DSI PLL power mode to %d\n",
1377 state);
1378 return -ENODEV;
1379 }
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02001380 udelay(1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001381 }
1382
1383 return 0;
1384}
1385
Tomi Valkeinen72658f02013-03-05 16:39:00 +02001386unsigned long dsi_get_pll_clkin(struct platform_device *dsidev)
1387{
1388 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1389 return clk_get_rate(dsi->sys_clk);
1390}
1391
1392bool dsi_hsdiv_calc(struct platform_device *dsidev, unsigned long pll,
1393 unsigned long out_min, dsi_hsdiv_calc_func func, void *data)
1394{
1395 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1396 int regm, regm_start, regm_stop;
1397 unsigned long out_max;
1398 unsigned long out;
1399
1400 out_min = out_min ? out_min : 1;
1401 out_max = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK);
1402
1403 regm_start = max(DIV_ROUND_UP(pll, out_max), 1ul);
1404 regm_stop = min(pll / out_min, dsi->regm_dispc_max);
1405
1406 for (regm = regm_start; regm <= regm_stop; ++regm) {
1407 out = pll / regm;
1408
1409 if (func(regm, out, data))
1410 return true;
1411 }
1412
1413 return false;
1414}
1415
1416bool dsi_pll_calc(struct platform_device *dsidev, unsigned long clkin,
1417 unsigned long pll_min, unsigned long pll_max,
1418 dsi_pll_calc_func func, void *data)
1419{
1420 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1421 int regn, regn_start, regn_stop;
1422 int regm, regm_start, regm_stop;
1423 unsigned long fint, pll;
1424 const unsigned long pll_hw_max = 1800000000;
1425 unsigned long fint_hw_min, fint_hw_max;
1426
1427 fint_hw_min = dsi->fint_min;
1428 fint_hw_max = dsi->fint_max;
1429
1430 regn_start = max(DIV_ROUND_UP(clkin, fint_hw_max), 1ul);
1431 regn_stop = min(clkin / fint_hw_min, dsi->regn_max);
1432
1433 pll_max = pll_max ? pll_max : ULONG_MAX;
1434
1435 for (regn = regn_start; regn <= regn_stop; ++regn) {
1436 fint = clkin / regn;
1437
1438 regm_start = max(DIV_ROUND_UP(DIV_ROUND_UP(pll_min, fint), 2),
1439 1ul);
1440 regm_stop = min3(pll_max / fint / 2,
1441 pll_hw_max / fint / 2,
1442 dsi->regm_max);
1443
1444 for (regm = regm_start; regm <= regm_stop; ++regm) {
1445 pll = 2 * regm * fint;
1446
1447 if (func(regn, regm, fint, pll, data))
1448 return true;
1449 }
1450 }
1451
1452 return false;
1453}
1454
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001455/* calculate clock rates using dividers in cinfo */
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02001456static int dsi_calc_clock_rates(struct platform_device *dsidev,
Sumit Semwalff1b2cd2010-12-02 11:27:11 +00001457 struct dsi_clock_info *cinfo)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001458{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301459 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1460
1461 if (cinfo->regn == 0 || cinfo->regn > dsi->regn_max)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001462 return -EINVAL;
1463
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301464 if (cinfo->regm == 0 || cinfo->regm > dsi->regm_max)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001465 return -EINVAL;
1466
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301467 if (cinfo->regm_dispc > dsi->regm_dispc_max)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001468 return -EINVAL;
1469
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301470 if (cinfo->regm_dsi > dsi->regm_dsi_max)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001471 return -EINVAL;
1472
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02001473 cinfo->clkin = clk_get_rate(dsi->sys_clk);
1474 cinfo->fint = cinfo->clkin / cinfo->regn;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001475
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301476 if (cinfo->fint > dsi->fint_max || cinfo->fint < dsi->fint_min)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001477 return -EINVAL;
1478
1479 cinfo->clkin4ddr = 2 * cinfo->regm * cinfo->fint;
1480
1481 if (cinfo->clkin4ddr > 1800 * 1000 * 1000)
1482 return -EINVAL;
1483
Archit Taneja1bb47832011-02-24 14:17:30 +05301484 if (cinfo->regm_dispc > 0)
1485 cinfo->dsi_pll_hsdiv_dispc_clk =
1486 cinfo->clkin4ddr / cinfo->regm_dispc;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001487 else
Archit Taneja1bb47832011-02-24 14:17:30 +05301488 cinfo->dsi_pll_hsdiv_dispc_clk = 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001489
Archit Taneja1bb47832011-02-24 14:17:30 +05301490 if (cinfo->regm_dsi > 0)
1491 cinfo->dsi_pll_hsdiv_dsi_clk =
1492 cinfo->clkin4ddr / cinfo->regm_dsi;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001493 else
Archit Taneja1bb47832011-02-24 14:17:30 +05301494 cinfo->dsi_pll_hsdiv_dsi_clk = 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001495
1496 return 0;
1497}
1498
Tomi Valkeinenf1e00012013-03-05 17:21:35 +02001499static void dsi_pll_calc_dsi_fck(struct dsi_clock_info *cinfo)
Tomi Valkeinend66b1582012-09-24 15:15:06 +03001500{
1501 unsigned long max_dsi_fck;
1502
1503 max_dsi_fck = dss_feat_get_param_max(FEAT_PARAM_DSI_FCK);
1504
1505 cinfo->regm_dsi = DIV_ROUND_UP(cinfo->clkin4ddr, max_dsi_fck);
1506 cinfo->dsi_pll_hsdiv_dsi_clk = cinfo->clkin4ddr / cinfo->regm_dsi;
1507}
1508
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301509int dsi_pll_set_clock_div(struct platform_device *dsidev,
1510 struct dsi_clock_info *cinfo)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001511{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301512 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001513 int r = 0;
1514 u32 l;
Archit Taneja9613c022011-03-22 06:33:36 -05001515 int f = 0;
Taneja, Archit49641112011-03-14 23:28:23 -05001516 u8 regn_start, regn_end, regm_start, regm_end;
1517 u8 regm_dispc_start, regm_dispc_end, regm_dsi_start, regm_dsi_end;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001518
Chandrabhanu Mahapatra702d2672012-09-24 17:12:58 +05301519 DSSDBG("DSI PLL clock config starts");
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001520
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02001521 dsi->current_cinfo.clkin = cinfo->clkin;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301522 dsi->current_cinfo.fint = cinfo->fint;
1523 dsi->current_cinfo.clkin4ddr = cinfo->clkin4ddr;
1524 dsi->current_cinfo.dsi_pll_hsdiv_dispc_clk =
Archit Taneja1bb47832011-02-24 14:17:30 +05301525 cinfo->dsi_pll_hsdiv_dispc_clk;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301526 dsi->current_cinfo.dsi_pll_hsdiv_dsi_clk =
Archit Taneja1bb47832011-02-24 14:17:30 +05301527 cinfo->dsi_pll_hsdiv_dsi_clk;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001528
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301529 dsi->current_cinfo.regn = cinfo->regn;
1530 dsi->current_cinfo.regm = cinfo->regm;
1531 dsi->current_cinfo.regm_dispc = cinfo->regm_dispc;
1532 dsi->current_cinfo.regm_dsi = cinfo->regm_dsi;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001533
1534 DSSDBG("DSI Fint %ld\n", cinfo->fint);
1535
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02001536 DSSDBG("clkin rate %ld\n", cinfo->clkin);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001537
1538 /* DSIPHY == CLKIN4DDR */
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02001539 DSSDBG("CLKIN4DDR = 2 * %d / %d * %lu = %lu\n",
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001540 cinfo->regm,
1541 cinfo->regn,
1542 cinfo->clkin,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001543 cinfo->clkin4ddr);
1544
1545 DSSDBG("Data rate on 1 DSI lane %ld Mbps\n",
1546 cinfo->clkin4ddr / 1000 / 1000 / 2);
1547
1548 DSSDBG("Clock lane freq %ld Hz\n", cinfo->clkin4ddr / 4);
1549
Archit Taneja1bb47832011-02-24 14:17:30 +05301550 DSSDBG("regm_dispc = %d, %s (%s) = %lu\n", cinfo->regm_dispc,
Archit Taneja89a35e52011-04-12 13:52:23 +05301551 dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
1552 dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
Archit Taneja1bb47832011-02-24 14:17:30 +05301553 cinfo->dsi_pll_hsdiv_dispc_clk);
1554 DSSDBG("regm_dsi = %d, %s (%s) = %lu\n", cinfo->regm_dsi,
Archit Taneja89a35e52011-04-12 13:52:23 +05301555 dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
1556 dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
Archit Taneja1bb47832011-02-24 14:17:30 +05301557 cinfo->dsi_pll_hsdiv_dsi_clk);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001558
Taneja, Archit49641112011-03-14 23:28:23 -05001559 dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGN, &regn_start, &regn_end);
1560 dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM, &regm_start, &regm_end);
1561 dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM_DISPC, &regm_dispc_start,
1562 &regm_dispc_end);
1563 dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM_DSI, &regm_dsi_start,
1564 &regm_dsi_end);
1565
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301566 /* DSI_PLL_AUTOMODE = manual */
1567 REG_FLD_MOD(dsidev, DSI_PLL_CONTROL, 0, 0, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001568
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301569 l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001570 l = FLD_MOD(l, 1, 0, 0); /* DSI_PLL_STOPMODE */
Taneja, Archit49641112011-03-14 23:28:23 -05001571 /* DSI_PLL_REGN */
1572 l = FLD_MOD(l, cinfo->regn - 1, regn_start, regn_end);
1573 /* DSI_PLL_REGM */
1574 l = FLD_MOD(l, cinfo->regm, regm_start, regm_end);
1575 /* DSI_CLOCK_DIV */
Archit Taneja1bb47832011-02-24 14:17:30 +05301576 l = FLD_MOD(l, cinfo->regm_dispc > 0 ? cinfo->regm_dispc - 1 : 0,
Taneja, Archit49641112011-03-14 23:28:23 -05001577 regm_dispc_start, regm_dispc_end);
1578 /* DSIPROTO_CLOCK_DIV */
Archit Taneja1bb47832011-02-24 14:17:30 +05301579 l = FLD_MOD(l, cinfo->regm_dsi > 0 ? cinfo->regm_dsi - 1 : 0,
Taneja, Archit49641112011-03-14 23:28:23 -05001580 regm_dsi_start, regm_dsi_end);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301581 dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION1, l);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001582
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301583 BUG_ON(cinfo->fint < dsi->fint_min || cinfo->fint > dsi->fint_max);
Archit Taneja9613c022011-03-22 06:33:36 -05001584
Tomi Valkeinenf8ef3d62012-08-22 16:00:31 +03001585 l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION2);
1586
Archit Taneja9613c022011-03-22 06:33:36 -05001587 if (dss_has_feature(FEAT_DSI_PLL_FREQSEL)) {
1588 f = cinfo->fint < 1000000 ? 0x3 :
1589 cinfo->fint < 1250000 ? 0x4 :
1590 cinfo->fint < 1500000 ? 0x5 :
1591 cinfo->fint < 1750000 ? 0x6 :
1592 0x7;
Tomi Valkeinenf8ef3d62012-08-22 16:00:31 +03001593
1594 l = FLD_MOD(l, f, 4, 1); /* DSI_PLL_FREQSEL */
1595 } else if (dss_has_feature(FEAT_DSI_PLL_SELFREQDCO)) {
1596 f = cinfo->clkin4ddr < 1000000000 ? 0x2 : 0x4;
1597
1598 l = FLD_MOD(l, f, 4, 1); /* PLL_SELFREQDCO */
Archit Taneja9613c022011-03-22 06:33:36 -05001599 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001600
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001601 l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */
1602 l = FLD_MOD(l, 0, 14, 14); /* DSIPHY_CLKINEN */
1603 l = FLD_MOD(l, 1, 20, 20); /* DSI_HSDIVBYPASS */
Tomi Valkeinen6d446102012-08-22 16:00:40 +03001604 if (dss_has_feature(FEAT_DSI_PLL_REFSEL))
1605 l = FLD_MOD(l, 3, 22, 21); /* REF_SYSCLK = sysclk */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301606 dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION2, l);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001607
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301608 REG_FLD_MOD(dsidev, DSI_PLL_GO, 1, 0, 0); /* DSI_PLL_GO */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001609
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301610 if (wait_for_bit_change(dsidev, DSI_PLL_GO, 0, 0) != 0) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001611 DSSERR("dsi pll go bit not going down.\n");
1612 r = -EIO;
1613 goto err;
1614 }
1615
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301616 if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 1, 1) != 1) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001617 DSSERR("cannot lock PLL\n");
1618 r = -EIO;
1619 goto err;
1620 }
1621
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301622 dsi->pll_locked = 1;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001623
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301624 l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION2);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001625 l = FLD_MOD(l, 0, 0, 0); /* DSI_PLL_IDLE */
1626 l = FLD_MOD(l, 0, 5, 5); /* DSI_PLL_PLLLPMODE */
1627 l = FLD_MOD(l, 0, 6, 6); /* DSI_PLL_LOWCURRSTBY */
1628 l = FLD_MOD(l, 0, 7, 7); /* DSI_PLL_TIGHTPHASELOCK */
1629 l = FLD_MOD(l, 0, 8, 8); /* DSI_PLL_DRIFTGUARDEN */
1630 l = FLD_MOD(l, 0, 10, 9); /* DSI_PLL_LOCKSEL */
1631 l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */
1632 l = FLD_MOD(l, 1, 14, 14); /* DSIPHY_CLKINEN */
1633 l = FLD_MOD(l, 0, 15, 15); /* DSI_BYPASSEN */
1634 l = FLD_MOD(l, 1, 16, 16); /* DSS_CLOCK_EN */
1635 l = FLD_MOD(l, 0, 17, 17); /* DSS_CLOCK_PWDN */
1636 l = FLD_MOD(l, 1, 18, 18); /* DSI_PROTO_CLOCK_EN */
1637 l = FLD_MOD(l, 0, 19, 19); /* DSI_PROTO_CLOCK_PWDN */
1638 l = FLD_MOD(l, 0, 20, 20); /* DSI_HSDIVBYPASS */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301639 dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION2, l);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001640
1641 DSSDBG("PLL config done\n");
1642err:
1643 return r;
1644}
1645
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301646int dsi_pll_init(struct platform_device *dsidev, bool enable_hsclk,
1647 bool enable_hsdiv)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001648{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301649 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001650 int r = 0;
1651 enum dsi_pll_power_state pwstate;
1652
1653 DSSDBG("PLL init\n");
1654
Tomi Valkeinen7a987862012-10-12 16:27:28 +03001655 /*
1656 * It seems that on many OMAPs we need to enable both to have a
1657 * functional HSDivider.
1658 */
1659 enable_hsclk = enable_hsdiv = true;
1660
Tomi Valkeinenb2541c42013-05-03 13:42:24 +03001661 r = dsi_regulator_init(dsidev);
1662 if (r)
1663 return r;
Tomi Valkeinenf2988ab2011-03-02 10:06:48 +02001664
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301665 dsi_enable_pll_clock(dsidev, 1);
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +03001666 /*
1667 * Note: SCP CLK is not required on OMAP3, but it is required on OMAP4.
1668 */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301669 dsi_enable_scp_clk(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001670
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301671 if (!dsi->vdds_dsi_enabled) {
1672 r = regulator_enable(dsi->vdds_dsi_reg);
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +03001673 if (r)
1674 goto err0;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301675 dsi->vdds_dsi_enabled = true;
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +03001676 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001677
1678 /* XXX PLL does not come out of reset without this... */
1679 dispc_pck_free_enable(1);
1680
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301681 if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 0, 1) != 1) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001682 DSSERR("PLL not coming out of reset.\n");
1683 r = -ENODEV;
Ville Syrjälä481dfa02010-04-22 22:50:04 +02001684 dispc_pck_free_enable(0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001685 goto err1;
1686 }
1687
1688 /* XXX ... but if left on, we get problems when planes do not
1689 * fill the whole display. No idea about this */
1690 dispc_pck_free_enable(0);
1691
1692 if (enable_hsclk && enable_hsdiv)
1693 pwstate = DSI_PLL_POWER_ON_ALL;
1694 else if (enable_hsclk)
1695 pwstate = DSI_PLL_POWER_ON_HSCLK;
1696 else if (enable_hsdiv)
1697 pwstate = DSI_PLL_POWER_ON_DIV;
1698 else
1699 pwstate = DSI_PLL_POWER_OFF;
1700
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301701 r = dsi_pll_power(dsidev, pwstate);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001702
1703 if (r)
1704 goto err1;
1705
1706 DSSDBG("PLL init done\n");
1707
1708 return 0;
1709err1:
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301710 if (dsi->vdds_dsi_enabled) {
1711 regulator_disable(dsi->vdds_dsi_reg);
1712 dsi->vdds_dsi_enabled = false;
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +03001713 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001714err0:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301715 dsi_disable_scp_clk(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301716 dsi_enable_pll_clock(dsidev, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001717 return r;
1718}
1719
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301720void dsi_pll_uninit(struct platform_device *dsidev, bool disconnect_lanes)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001721{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301722 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1723
1724 dsi->pll_locked = 0;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301725 dsi_pll_power(dsidev, DSI_PLL_POWER_OFF);
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +03001726 if (disconnect_lanes) {
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301727 WARN_ON(!dsi->vdds_dsi_enabled);
1728 regulator_disable(dsi->vdds_dsi_reg);
1729 dsi->vdds_dsi_enabled = false;
Tomi Valkeinen2a89dc12010-07-30 12:39:34 +03001730 }
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +03001731
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301732 dsi_disable_scp_clk(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301733 dsi_enable_pll_clock(dsidev, 0);
Tomi Valkeinen24c1ae42011-04-13 17:12:52 +03001734
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001735 DSSDBG("PLL uninit done\n");
1736}
1737
Archit Taneja5a8b5722011-05-12 17:26:29 +05301738static void dsi_dump_dsidev_clocks(struct platform_device *dsidev,
1739 struct seq_file *s)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001740{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301741 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1742 struct dsi_clock_info *cinfo = &dsi->current_cinfo;
Archit Taneja89a35e52011-04-12 13:52:23 +05301743 enum omap_dss_clk_source dispc_clk_src, dsi_clk_src;
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02001744 int dsi_module = dsi->module_id;
Archit Taneja067a57e2011-03-02 11:57:25 +05301745
1746 dispc_clk_src = dss_get_dispc_clk_source();
Archit Taneja5a8b5722011-05-12 17:26:29 +05301747 dsi_clk_src = dss_get_dsi_clk_source(dsi_module);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001748
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001749 if (dsi_runtime_get(dsidev))
1750 return;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001751
Archit Taneja5a8b5722011-05-12 17:26:29 +05301752 seq_printf(s, "- DSI%d PLL -\n", dsi_module + 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001753
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02001754 seq_printf(s, "dsi pll clkin\t%lu\n", cinfo->clkin);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001755
1756 seq_printf(s, "Fint\t\t%-16luregn %u\n", cinfo->fint, cinfo->regn);
1757
1758 seq_printf(s, "CLKIN4DDR\t%-16luregm %u\n",
1759 cinfo->clkin4ddr, cinfo->regm);
1760
Archit Taneja84309f12011-12-12 11:47:41 +05301761 seq_printf(s, "DSI_PLL_HSDIV_DISPC (%s)\t%-16luregm_dispc %u\t(%s)\n",
1762 dss_feat_get_clk_source_name(dsi_module == 0 ?
1763 OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC :
1764 OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC),
Archit Taneja1bb47832011-02-24 14:17:30 +05301765 cinfo->dsi_pll_hsdiv_dispc_clk,
1766 cinfo->regm_dispc,
Archit Taneja89a35e52011-04-12 13:52:23 +05301767 dispc_clk_src == OMAP_DSS_CLK_SRC_FCK ?
Tomi Valkeinen63cf28a2010-02-23 17:40:00 +02001768 "off" : "on");
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001769
Archit Taneja84309f12011-12-12 11:47:41 +05301770 seq_printf(s, "DSI_PLL_HSDIV_DSI (%s)\t%-16luregm_dsi %u\t(%s)\n",
1771 dss_feat_get_clk_source_name(dsi_module == 0 ?
1772 OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI :
1773 OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DSI),
Archit Taneja1bb47832011-02-24 14:17:30 +05301774 cinfo->dsi_pll_hsdiv_dsi_clk,
1775 cinfo->regm_dsi,
Archit Taneja89a35e52011-04-12 13:52:23 +05301776 dsi_clk_src == OMAP_DSS_CLK_SRC_FCK ?
Tomi Valkeinen63cf28a2010-02-23 17:40:00 +02001777 "off" : "on");
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001778
Archit Taneja5a8b5722011-05-12 17:26:29 +05301779 seq_printf(s, "- DSI%d -\n", dsi_module + 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001780
Archit Taneja067a57e2011-03-02 11:57:25 +05301781 seq_printf(s, "dsi fclk source = %s (%s)\n",
1782 dss_get_generic_clk_source_name(dsi_clk_src),
1783 dss_feat_get_clk_source_name(dsi_clk_src));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001784
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301785 seq_printf(s, "DSI_FCLK\t%lu\n", dsi_fclk_rate(dsidev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001786
1787 seq_printf(s, "DDR_CLK\t\t%lu\n",
1788 cinfo->clkin4ddr / 4);
1789
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301790 seq_printf(s, "TxByteClkHS\t%lu\n", dsi_get_txbyteclkhs(dsidev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001791
1792 seq_printf(s, "LP_CLK\t\t%lu\n", cinfo->lp_clk);
1793
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001794 dsi_runtime_put(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001795}
1796
Archit Taneja5a8b5722011-05-12 17:26:29 +05301797void dsi_dump_clocks(struct seq_file *s)
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001798{
Archit Taneja5a8b5722011-05-12 17:26:29 +05301799 struct platform_device *dsidev;
1800 int i;
1801
1802 for (i = 0; i < MAX_NUM_DSI; i++) {
1803 dsidev = dsi_get_dsidev_from_id(i);
1804 if (dsidev)
1805 dsi_dump_dsidev_clocks(dsidev, s);
1806 }
1807}
1808
1809#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
1810static void dsi_dump_dsidev_irqs(struct platform_device *dsidev,
1811 struct seq_file *s)
1812{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301813 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001814 unsigned long flags;
1815 struct dsi_irq_stats stats;
1816
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301817 spin_lock_irqsave(&dsi->irq_stats_lock, flags);
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001818
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301819 stats = dsi->irq_stats;
1820 memset(&dsi->irq_stats, 0, sizeof(dsi->irq_stats));
1821 dsi->irq_stats.last_reset = jiffies;
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001822
Archit Tanejaf1da39d2011-05-12 17:26:27 +05301823 spin_unlock_irqrestore(&dsi->irq_stats_lock, flags);
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001824
1825 seq_printf(s, "period %u ms\n",
1826 jiffies_to_msecs(jiffies - stats.last_reset));
1827
1828 seq_printf(s, "irqs %d\n", stats.irq_count);
1829#define PIS(x) \
1830 seq_printf(s, "%-20s %10d\n", #x, stats.dsi_irqs[ffs(DSI_IRQ_##x)-1]);
1831
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02001832 seq_printf(s, "-- DSI%d interrupts --\n", dsi->module_id + 1);
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001833 PIS(VC0);
1834 PIS(VC1);
1835 PIS(VC2);
1836 PIS(VC3);
1837 PIS(WAKEUP);
1838 PIS(RESYNC);
1839 PIS(PLL_LOCK);
1840 PIS(PLL_UNLOCK);
1841 PIS(PLL_RECALL);
1842 PIS(COMPLEXIO_ERR);
1843 PIS(HS_TX_TIMEOUT);
1844 PIS(LP_RX_TIMEOUT);
1845 PIS(TE_TRIGGER);
1846 PIS(ACK_TRIGGER);
1847 PIS(SYNC_LOST);
1848 PIS(LDO_POWER_GOOD);
1849 PIS(TA_TIMEOUT);
1850#undef PIS
1851
1852#define PIS(x) \
1853 seq_printf(s, "%-20s %10d %10d %10d %10d\n", #x, \
1854 stats.vc_irqs[0][ffs(DSI_VC_IRQ_##x)-1], \
1855 stats.vc_irqs[1][ffs(DSI_VC_IRQ_##x)-1], \
1856 stats.vc_irqs[2][ffs(DSI_VC_IRQ_##x)-1], \
1857 stats.vc_irqs[3][ffs(DSI_VC_IRQ_##x)-1]);
1858
1859 seq_printf(s, "-- VC interrupts --\n");
1860 PIS(CS);
1861 PIS(ECC_CORR);
1862 PIS(PACKET_SENT);
1863 PIS(FIFO_TX_OVF);
1864 PIS(FIFO_RX_OVF);
1865 PIS(BTA);
1866 PIS(ECC_NO_CORR);
1867 PIS(FIFO_TX_UDF);
1868 PIS(PP_BUSY_CHANGE);
1869#undef PIS
1870
1871#define PIS(x) \
1872 seq_printf(s, "%-20s %10d\n", #x, \
1873 stats.cio_irqs[ffs(DSI_CIO_IRQ_##x)-1]);
1874
1875 seq_printf(s, "-- CIO interrupts --\n");
1876 PIS(ERRSYNCESC1);
1877 PIS(ERRSYNCESC2);
1878 PIS(ERRSYNCESC3);
1879 PIS(ERRESC1);
1880 PIS(ERRESC2);
1881 PIS(ERRESC3);
1882 PIS(ERRCONTROL1);
1883 PIS(ERRCONTROL2);
1884 PIS(ERRCONTROL3);
1885 PIS(STATEULPS1);
1886 PIS(STATEULPS2);
1887 PIS(STATEULPS3);
1888 PIS(ERRCONTENTIONLP0_1);
1889 PIS(ERRCONTENTIONLP1_1);
1890 PIS(ERRCONTENTIONLP0_2);
1891 PIS(ERRCONTENTIONLP1_2);
1892 PIS(ERRCONTENTIONLP0_3);
1893 PIS(ERRCONTENTIONLP1_3);
1894 PIS(ULPSACTIVENOT_ALL0);
1895 PIS(ULPSACTIVENOT_ALL1);
1896#undef PIS
1897}
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02001898
Archit Taneja5a8b5722011-05-12 17:26:29 +05301899static void dsi1_dump_irqs(struct seq_file *s)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001900{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301901 struct platform_device *dsidev = dsi_get_dsidev_from_id(0);
1902
Archit Taneja5a8b5722011-05-12 17:26:29 +05301903 dsi_dump_dsidev_irqs(dsidev, s);
1904}
1905
1906static void dsi2_dump_irqs(struct seq_file *s)
1907{
1908 struct platform_device *dsidev = dsi_get_dsidev_from_id(1);
1909
1910 dsi_dump_dsidev_irqs(dsidev, s);
1911}
Archit Taneja5a8b5722011-05-12 17:26:29 +05301912#endif
1913
1914static void dsi_dump_dsidev_regs(struct platform_device *dsidev,
1915 struct seq_file *s)
1916{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301917#define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dsi_read_reg(dsidev, r))
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001918
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001919 if (dsi_runtime_get(dsidev))
1920 return;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301921 dsi_enable_scp_clk(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001922
1923 DUMPREG(DSI_REVISION);
1924 DUMPREG(DSI_SYSCONFIG);
1925 DUMPREG(DSI_SYSSTATUS);
1926 DUMPREG(DSI_IRQSTATUS);
1927 DUMPREG(DSI_IRQENABLE);
1928 DUMPREG(DSI_CTRL);
1929 DUMPREG(DSI_COMPLEXIO_CFG1);
1930 DUMPREG(DSI_COMPLEXIO_IRQ_STATUS);
1931 DUMPREG(DSI_COMPLEXIO_IRQ_ENABLE);
1932 DUMPREG(DSI_CLK_CTRL);
1933 DUMPREG(DSI_TIMING1);
1934 DUMPREG(DSI_TIMING2);
1935 DUMPREG(DSI_VM_TIMING1);
1936 DUMPREG(DSI_VM_TIMING2);
1937 DUMPREG(DSI_VM_TIMING3);
1938 DUMPREG(DSI_CLK_TIMING);
1939 DUMPREG(DSI_TX_FIFO_VC_SIZE);
1940 DUMPREG(DSI_RX_FIFO_VC_SIZE);
1941 DUMPREG(DSI_COMPLEXIO_CFG2);
1942 DUMPREG(DSI_RX_FIFO_VC_FULLNESS);
1943 DUMPREG(DSI_VM_TIMING4);
1944 DUMPREG(DSI_TX_FIFO_VC_EMPTINESS);
1945 DUMPREG(DSI_VM_TIMING5);
1946 DUMPREG(DSI_VM_TIMING6);
1947 DUMPREG(DSI_VM_TIMING7);
1948 DUMPREG(DSI_STOPCLK_TIMING);
1949
1950 DUMPREG(DSI_VC_CTRL(0));
1951 DUMPREG(DSI_VC_TE(0));
1952 DUMPREG(DSI_VC_LONG_PACKET_HEADER(0));
1953 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(0));
1954 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(0));
1955 DUMPREG(DSI_VC_IRQSTATUS(0));
1956 DUMPREG(DSI_VC_IRQENABLE(0));
1957
1958 DUMPREG(DSI_VC_CTRL(1));
1959 DUMPREG(DSI_VC_TE(1));
1960 DUMPREG(DSI_VC_LONG_PACKET_HEADER(1));
1961 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(1));
1962 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(1));
1963 DUMPREG(DSI_VC_IRQSTATUS(1));
1964 DUMPREG(DSI_VC_IRQENABLE(1));
1965
1966 DUMPREG(DSI_VC_CTRL(2));
1967 DUMPREG(DSI_VC_TE(2));
1968 DUMPREG(DSI_VC_LONG_PACKET_HEADER(2));
1969 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(2));
1970 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(2));
1971 DUMPREG(DSI_VC_IRQSTATUS(2));
1972 DUMPREG(DSI_VC_IRQENABLE(2));
1973
1974 DUMPREG(DSI_VC_CTRL(3));
1975 DUMPREG(DSI_VC_TE(3));
1976 DUMPREG(DSI_VC_LONG_PACKET_HEADER(3));
1977 DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(3));
1978 DUMPREG(DSI_VC_SHORT_PACKET_HEADER(3));
1979 DUMPREG(DSI_VC_IRQSTATUS(3));
1980 DUMPREG(DSI_VC_IRQENABLE(3));
1981
1982 DUMPREG(DSI_DSIPHY_CFG0);
1983 DUMPREG(DSI_DSIPHY_CFG1);
1984 DUMPREG(DSI_DSIPHY_CFG2);
1985 DUMPREG(DSI_DSIPHY_CFG5);
1986
1987 DUMPREG(DSI_PLL_CONTROL);
1988 DUMPREG(DSI_PLL_STATUS);
1989 DUMPREG(DSI_PLL_GO);
1990 DUMPREG(DSI_PLL_CONFIGURATION1);
1991 DUMPREG(DSI_PLL_CONFIGURATION2);
1992
Archit Tanejaa72b64b2011-05-12 17:26:26 +05301993 dsi_disable_scp_clk(dsidev);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03001994 dsi_runtime_put(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02001995#undef DUMPREG
1996}
1997
Archit Taneja5a8b5722011-05-12 17:26:29 +05301998static void dsi1_dump_regs(struct seq_file *s)
1999{
2000 struct platform_device *dsidev = dsi_get_dsidev_from_id(0);
2001
2002 dsi_dump_dsidev_regs(dsidev, s);
2003}
2004
2005static void dsi2_dump_regs(struct seq_file *s)
2006{
2007 struct platform_device *dsidev = dsi_get_dsidev_from_id(1);
2008
2009 dsi_dump_dsidev_regs(dsidev, s);
2010}
2011
Tomi Valkeinencc5c1852010-10-06 15:18:13 +03002012enum dsi_cio_power_state {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002013 DSI_COMPLEXIO_POWER_OFF = 0x0,
2014 DSI_COMPLEXIO_POWER_ON = 0x1,
2015 DSI_COMPLEXIO_POWER_ULPS = 0x2,
2016};
2017
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302018static int dsi_cio_power(struct platform_device *dsidev,
2019 enum dsi_cio_power_state state)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002020{
2021 int t = 0;
2022
2023 /* PWR_CMD */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302024 REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG1, state, 28, 27);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002025
2026 /* PWR_STATUS */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302027 while (FLD_GET(dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1),
2028 26, 25) != state) {
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02002029 if (++t > 1000) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002030 DSSERR("failed to set complexio power state to "
2031 "%d\n", state);
2032 return -ENODEV;
2033 }
Tomi Valkeinen24be78b2010-01-07 14:19:48 +02002034 udelay(1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002035 }
2036
2037 return 0;
2038}
2039
Archit Taneja0c656222011-05-16 15:17:09 +05302040static unsigned dsi_get_line_buf_size(struct platform_device *dsidev)
2041{
2042 int val;
2043
2044 /* line buffer on OMAP3 is 1024 x 24bits */
2045 /* XXX: for some reason using full buffer size causes
2046 * considerable TX slowdown with update sizes that fill the
2047 * whole buffer */
2048 if (!dss_has_feature(FEAT_DSI_GNQ))
2049 return 1023 * 3;
2050
2051 val = REG_GET(dsidev, DSI_GNQ, 14, 12); /* VP1_LINE_BUFFER_SIZE */
2052
2053 switch (val) {
2054 case 1:
2055 return 512 * 3; /* 512x24 bits */
2056 case 2:
2057 return 682 * 3; /* 682x24 bits */
2058 case 3:
2059 return 853 * 3; /* 853x24 bits */
2060 case 4:
2061 return 1024 * 3; /* 1024x24 bits */
2062 case 5:
2063 return 1194 * 3; /* 1194x24 bits */
2064 case 6:
2065 return 1365 * 3; /* 1365x24 bits */
Tomi Valkeinen2ac80fb2012-08-22 16:00:47 +03002066 case 7:
2067 return 1920 * 3; /* 1920x24 bits */
Archit Taneja0c656222011-05-16 15:17:09 +05302068 default:
2069 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002070 return 0;
Archit Taneja0c656222011-05-16 15:17:09 +05302071 }
2072}
2073
Archit Taneja9e7e9372012-08-14 12:29:22 +05302074static int dsi_set_lane_config(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002075{
Tomi Valkeinen48368392011-10-13 11:22:39 +03002076 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2077 static const u8 offsets[] = { 0, 4, 8, 12, 16 };
2078 static const enum dsi_lane_function functions[] = {
2079 DSI_LANE_CLK,
2080 DSI_LANE_DATA1,
2081 DSI_LANE_DATA2,
2082 DSI_LANE_DATA3,
2083 DSI_LANE_DATA4,
2084 };
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002085 u32 r;
Tomi Valkeinen48368392011-10-13 11:22:39 +03002086 int i;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002087
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302088 r = dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1);
Archit Taneja75d72472011-05-16 15:17:08 +05302089
Tomi Valkeinen48368392011-10-13 11:22:39 +03002090 for (i = 0; i < dsi->num_lanes_used; ++i) {
2091 unsigned offset = offsets[i];
2092 unsigned polarity, lane_number;
2093 unsigned t;
Archit Taneja75d72472011-05-16 15:17:08 +05302094
Tomi Valkeinen48368392011-10-13 11:22:39 +03002095 for (t = 0; t < dsi->num_lanes_supported; ++t)
2096 if (dsi->lanes[t].function == functions[i])
2097 break;
2098
2099 if (t == dsi->num_lanes_supported)
2100 return -EINVAL;
2101
2102 lane_number = t;
2103 polarity = dsi->lanes[t].polarity;
2104
2105 r = FLD_MOD(r, lane_number + 1, offset + 2, offset);
2106 r = FLD_MOD(r, polarity, offset + 3, offset + 3);
Archit Taneja75d72472011-05-16 15:17:08 +05302107 }
Tomi Valkeinen48368392011-10-13 11:22:39 +03002108
2109 /* clear the unused lanes */
2110 for (; i < dsi->num_lanes_supported; ++i) {
2111 unsigned offset = offsets[i];
2112
2113 r = FLD_MOD(r, 0, offset + 2, offset);
2114 r = FLD_MOD(r, 0, offset + 3, offset + 3);
2115 }
2116
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302117 dsi_write_reg(dsidev, DSI_COMPLEXIO_CFG1, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002118
Tomi Valkeinen48368392011-10-13 11:22:39 +03002119 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002120}
2121
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302122static inline unsigned ns2ddr(struct platform_device *dsidev, unsigned ns)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002123{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302124 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2125
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002126 /* convert time in ns to ddr ticks, rounding up */
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302127 unsigned long ddr_clk = dsi->current_cinfo.clkin4ddr / 4;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002128 return (ns * (ddr_clk / 1000 / 1000) + 999) / 1000;
2129}
2130
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302131static inline unsigned ddr2ns(struct platform_device *dsidev, unsigned ddr)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002132{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302133 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2134
2135 unsigned long ddr_clk = dsi->current_cinfo.clkin4ddr / 4;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002136 return ddr * 1000 * 1000 / (ddr_clk / 1000);
2137}
2138
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302139static void dsi_cio_timings(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002140{
2141 u32 r;
2142 u32 ths_prepare, ths_prepare_ths_zero, ths_trail, ths_exit;
2143 u32 tlpx_half, tclk_trail, tclk_zero;
2144 u32 tclk_prepare;
2145
2146 /* calculate timings */
2147
2148 /* 1 * DDR_CLK = 2 * UI */
2149
2150 /* min 40ns + 4*UI max 85ns + 6*UI */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302151 ths_prepare = ns2ddr(dsidev, 70) + 2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002152
2153 /* min 145ns + 10*UI */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302154 ths_prepare_ths_zero = ns2ddr(dsidev, 175) + 2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002155
2156 /* min max(8*UI, 60ns+4*UI) */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302157 ths_trail = ns2ddr(dsidev, 60) + 5;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002158
2159 /* min 100ns */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302160 ths_exit = ns2ddr(dsidev, 145);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002161
2162 /* tlpx min 50n */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302163 tlpx_half = ns2ddr(dsidev, 25);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002164
2165 /* min 60ns */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302166 tclk_trail = ns2ddr(dsidev, 60) + 2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002167
2168 /* min 38ns, max 95ns */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302169 tclk_prepare = ns2ddr(dsidev, 65);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002170
2171 /* min tclk-prepare + tclk-zero = 300ns */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302172 tclk_zero = ns2ddr(dsidev, 260);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002173
2174 DSSDBG("ths_prepare %u (%uns), ths_prepare_ths_zero %u (%uns)\n",
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302175 ths_prepare, ddr2ns(dsidev, ths_prepare),
2176 ths_prepare_ths_zero, ddr2ns(dsidev, ths_prepare_ths_zero));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002177 DSSDBG("ths_trail %u (%uns), ths_exit %u (%uns)\n",
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302178 ths_trail, ddr2ns(dsidev, ths_trail),
2179 ths_exit, ddr2ns(dsidev, ths_exit));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002180
2181 DSSDBG("tlpx_half %u (%uns), tclk_trail %u (%uns), "
2182 "tclk_zero %u (%uns)\n",
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302183 tlpx_half, ddr2ns(dsidev, tlpx_half),
2184 tclk_trail, ddr2ns(dsidev, tclk_trail),
2185 tclk_zero, ddr2ns(dsidev, tclk_zero));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002186 DSSDBG("tclk_prepare %u (%uns)\n",
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302187 tclk_prepare, ddr2ns(dsidev, tclk_prepare));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002188
2189 /* program timings */
2190
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302191 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002192 r = FLD_MOD(r, ths_prepare, 31, 24);
2193 r = FLD_MOD(r, ths_prepare_ths_zero, 23, 16);
2194 r = FLD_MOD(r, ths_trail, 15, 8);
2195 r = FLD_MOD(r, ths_exit, 7, 0);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302196 dsi_write_reg(dsidev, DSI_DSIPHY_CFG0, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002197
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302198 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1);
Tomi Valkeinene84dc1c2012-09-24 09:34:52 +03002199 r = FLD_MOD(r, tlpx_half, 20, 16);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002200 r = FLD_MOD(r, tclk_trail, 15, 8);
2201 r = FLD_MOD(r, tclk_zero, 7, 0);
Tomi Valkeinen77ccbfb2012-09-24 15:15:57 +03002202
2203 if (dss_has_feature(FEAT_DSI_PHY_DCC)) {
2204 r = FLD_MOD(r, 0, 21, 21); /* DCCEN = disable */
2205 r = FLD_MOD(r, 1, 22, 22); /* CLKINP_DIVBY2EN = enable */
2206 r = FLD_MOD(r, 1, 23, 23); /* CLKINP_SEL = enable */
2207 }
2208
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302209 dsi_write_reg(dsidev, DSI_DSIPHY_CFG1, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002210
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302211 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG2);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002212 r = FLD_MOD(r, tclk_prepare, 7, 0);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302213 dsi_write_reg(dsidev, DSI_DSIPHY_CFG2, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002214}
2215
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002216/* lane masks have lane 0 at lsb. mask_p for positive lines, n for negative */
Archit Taneja9e7e9372012-08-14 12:29:22 +05302217static void dsi_cio_enable_lane_override(struct platform_device *dsidev,
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002218 unsigned mask_p, unsigned mask_n)
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002219{
Archit Taneja75d72472011-05-16 15:17:08 +05302220 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002221 int i;
2222 u32 l;
Tomi Valkeinend9820852011-10-12 15:05:59 +03002223 u8 lptxscp_start = dsi->num_lanes_supported == 3 ? 22 : 26;
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002224
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002225 l = 0;
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002226
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002227 for (i = 0; i < dsi->num_lanes_supported; ++i) {
2228 unsigned p = dsi->lanes[i].polarity;
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002229
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002230 if (mask_p & (1 << i))
2231 l |= 1 << (i * 2 + (p ? 0 : 1));
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002232
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002233 if (mask_n & (1 << i))
2234 l |= 1 << (i * 2 + (p ? 1 : 0));
2235 }
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002236
2237 /*
2238 * Bits in REGLPTXSCPDAT4TO0DXDY:
2239 * 17: DY0 18: DX0
2240 * 19: DY1 20: DX1
2241 * 21: DY2 22: DX2
Archit Taneja75d72472011-05-16 15:17:08 +05302242 * 23: DY3 24: DX3
2243 * 25: DY4 26: DX4
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002244 */
2245
2246 /* Set the lane override configuration */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302247
2248 /* REGLPTXSCPDAT4TO0DXDY */
Archit Taneja75d72472011-05-16 15:17:08 +05302249 REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, l, lptxscp_start, 17);
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002250
2251 /* Enable lane override */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302252
2253 /* ENLPTXSCPDAT */
2254 REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 1, 27, 27);
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002255}
2256
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302257static void dsi_cio_disable_lane_override(struct platform_device *dsidev)
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002258{
2259 /* Disable lane override */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302260 REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 0, 27, 27); /* ENLPTXSCPDAT */
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002261 /* Reset the lane override configuration */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302262 /* REGLPTXSCPDAT4TO0DXDY */
2263 REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 0, 22, 17);
Tomi Valkeinen0a0ee462010-07-27 11:11:48 +03002264}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002265
Archit Taneja9e7e9372012-08-14 12:29:22 +05302266static int dsi_cio_wait_tx_clk_esc_reset(struct platform_device *dsidev)
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002267{
Tomi Valkeinen8dc07662011-10-13 15:26:50 +03002268 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2269 int t, i;
2270 bool in_use[DSI_MAX_NR_LANES];
2271 static const u8 offsets_old[] = { 28, 27, 26 };
2272 static const u8 offsets_new[] = { 24, 25, 26, 27, 28 };
2273 const u8 *offsets;
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002274
Tomi Valkeinen8dc07662011-10-13 15:26:50 +03002275 if (dss_has_feature(FEAT_DSI_REVERSE_TXCLKESC))
2276 offsets = offsets_old;
2277 else
2278 offsets = offsets_new;
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002279
Tomi Valkeinen8dc07662011-10-13 15:26:50 +03002280 for (i = 0; i < dsi->num_lanes_supported; ++i)
2281 in_use[i] = dsi->lanes[i].function != DSI_LANE_UNUSED;
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002282
2283 t = 100000;
2284 while (true) {
2285 u32 l;
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002286 int ok;
2287
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302288 l = dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002289
2290 ok = 0;
Tomi Valkeinen8dc07662011-10-13 15:26:50 +03002291 for (i = 0; i < dsi->num_lanes_supported; ++i) {
2292 if (!in_use[i] || (l & (1 << offsets[i])))
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002293 ok++;
2294 }
2295
Tomi Valkeinen8dc07662011-10-13 15:26:50 +03002296 if (ok == dsi->num_lanes_supported)
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002297 break;
2298
2299 if (--t == 0) {
Tomi Valkeinen8dc07662011-10-13 15:26:50 +03002300 for (i = 0; i < dsi->num_lanes_supported; ++i) {
2301 if (!in_use[i] || (l & (1 << offsets[i])))
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002302 continue;
2303
2304 DSSERR("CIO TXCLKESC%d domain not coming " \
2305 "out of reset\n", i);
2306 }
2307 return -EIO;
2308 }
2309 }
2310
2311 return 0;
2312}
2313
Tomi Valkeinen85f17e82011-10-13 15:12:23 +03002314/* return bitmask of enabled lanes, lane0 being the lsb */
Archit Taneja9e7e9372012-08-14 12:29:22 +05302315static unsigned dsi_get_lane_mask(struct platform_device *dsidev)
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03002316{
Tomi Valkeinen85f17e82011-10-13 15:12:23 +03002317 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2318 unsigned mask = 0;
2319 int i;
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03002320
Tomi Valkeinen85f17e82011-10-13 15:12:23 +03002321 for (i = 0; i < dsi->num_lanes_supported; ++i) {
2322 if (dsi->lanes[i].function != DSI_LANE_UNUSED)
2323 mask |= 1 << i;
2324 }
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03002325
Tomi Valkeinen85f17e82011-10-13 15:12:23 +03002326 return mask;
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03002327}
2328
Archit Taneja9e7e9372012-08-14 12:29:22 +05302329static int dsi_cio_init(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002330{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302331 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002332 int r;
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002333 u32 l;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002334
Chandrabhanu Mahapatra702d2672012-09-24 17:12:58 +05302335 DSSDBG("DSI CIO init starts");
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002336
Archit Taneja9e7e9372012-08-14 12:29:22 +05302337 r = dss_dsi_enable_pads(dsi->module_id, dsi_get_lane_mask(dsidev));
Tomi Valkeinen5bc416c2011-06-15 15:21:12 +03002338 if (r)
2339 return r;
Tomi Valkeinend1f5857e2010-07-30 11:57:57 +03002340
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302341 dsi_enable_scp_clk(dsidev);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002342
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002343 /* A dummy read using the SCP interface to any DSIPHY register is
2344 * required after DSIPHY reset to complete the reset of the DSI complex
2345 * I/O. */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302346 dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002347
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302348 if (wait_for_bit_change(dsidev, DSI_DSIPHY_CFG5, 30, 1) != 1) {
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002349 DSSERR("CIO SCP Clock domain not coming out of reset.\n");
2350 r = -EIO;
2351 goto err_scp_clk_dom;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002352 }
2353
Archit Taneja9e7e9372012-08-14 12:29:22 +05302354 r = dsi_set_lane_config(dsidev);
Tomi Valkeinen48368392011-10-13 11:22:39 +03002355 if (r)
2356 goto err_scp_clk_dom;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002357
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002358 /* set TX STOP MODE timer to maximum for this operation */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302359 l = dsi_read_reg(dsidev, DSI_TIMING1);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002360 l = FLD_MOD(l, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
2361 l = FLD_MOD(l, 1, 14, 14); /* STOP_STATE_X16_IO */
2362 l = FLD_MOD(l, 1, 13, 13); /* STOP_STATE_X4_IO */
2363 l = FLD_MOD(l, 0x1fff, 12, 0); /* STOP_STATE_COUNTER_IO */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302364 dsi_write_reg(dsidev, DSI_TIMING1, l);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002365
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302366 if (dsi->ulps_enabled) {
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002367 unsigned mask_p;
2368 int i;
Archit Taneja75d72472011-05-16 15:17:08 +05302369
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002370 DSSDBG("manual ulps exit\n");
2371
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002372 /* ULPS is exited by Mark-1 state for 1ms, followed by
2373 * stop state. DSS HW cannot do this via the normal
2374 * ULPS exit sequence, as after reset the DSS HW thinks
2375 * that we are not in ULPS mode, and refuses to send the
2376 * sequence. So we need to send the ULPS exit sequence
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002377 * manually by setting positive lines high and negative lines
2378 * low for 1ms.
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002379 */
2380
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002381 mask_p = 0;
Archit Taneja75d72472011-05-16 15:17:08 +05302382
Tomi Valkeinen9b4362f2011-10-13 16:06:43 +03002383 for (i = 0; i < dsi->num_lanes_supported; ++i) {
2384 if (dsi->lanes[i].function == DSI_LANE_UNUSED)
2385 continue;
2386 mask_p |= 1 << i;
2387 }
Archit Taneja75d72472011-05-16 15:17:08 +05302388
Archit Taneja9e7e9372012-08-14 12:29:22 +05302389 dsi_cio_enable_lane_override(dsidev, mask_p, 0);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002390 }
2391
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302392 r = dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_ON);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002393 if (r)
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002394 goto err_cio_pwr;
2395
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302396 if (wait_for_bit_change(dsidev, DSI_COMPLEXIO_CFG1, 29, 1) != 1) {
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002397 DSSERR("CIO PWR clock domain not coming out of reset.\n");
2398 r = -ENODEV;
2399 goto err_cio_pwr_dom;
2400 }
2401
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302402 dsi_if_enable(dsidev, true);
2403 dsi_if_enable(dsidev, false);
2404 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 1, 20, 20); /* LP_CLK_ENABLE */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002405
Archit Taneja9e7e9372012-08-14 12:29:22 +05302406 r = dsi_cio_wait_tx_clk_esc_reset(dsidev);
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002407 if (r)
2408 goto err_tx_clk_esc_rst;
2409
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302410 if (dsi->ulps_enabled) {
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002411 /* Keep Mark-1 state for 1ms (as per DSI spec) */
2412 ktime_t wait = ns_to_ktime(1000 * 1000);
2413 set_current_state(TASK_UNINTERRUPTIBLE);
2414 schedule_hrtimeout(&wait, HRTIMER_MODE_REL);
2415
2416 /* Disable the override. The lanes should be set to Mark-11
2417 * state by the HW */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302418 dsi_cio_disable_lane_override(dsidev);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002419 }
2420
2421 /* FORCE_TX_STOP_MODE_IO */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302422 REG_FLD_MOD(dsidev, DSI_TIMING1, 0, 15, 15);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03002423
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302424 dsi_cio_timings(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002425
Archit Tanejadca2b152012-08-16 18:02:00 +05302426 if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
Archit Taneja8af6ff02011-09-05 16:48:27 +05302427 /* DDR_CLK_ALWAYS_ON */
2428 REG_FLD_MOD(dsidev, DSI_CLK_CTRL,
Archit Taneja0b3ffe32012-08-13 22:13:39 +05302429 dsi->vm_timings.ddr_clk_always_on, 13, 13);
Archit Taneja8af6ff02011-09-05 16:48:27 +05302430 }
2431
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302432 dsi->ulps_enabled = false;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002433
2434 DSSDBG("CIO init done\n");
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002435
2436 return 0;
2437
Tomi Valkeinen03329ac2010-10-07 13:59:22 +03002438err_tx_clk_esc_rst:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302439 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 20, 20); /* LP_CLK_ENABLE */
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002440err_cio_pwr_dom:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302441 dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_OFF);
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002442err_cio_pwr:
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302443 if (dsi->ulps_enabled)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302444 dsi_cio_disable_lane_override(dsidev);
Tomi Valkeinen65c62bb2011-04-15 11:58:41 +03002445err_scp_clk_dom:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302446 dsi_disable_scp_clk(dsidev);
Archit Taneja9e7e9372012-08-14 12:29:22 +05302447 dss_dsi_disable_pads(dsi->module_id, dsi_get_lane_mask(dsidev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002448 return r;
2449}
2450
Archit Taneja9e7e9372012-08-14 12:29:22 +05302451static void dsi_cio_uninit(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002452{
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02002453 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302454
Archit Taneja8af6ff02011-09-05 16:48:27 +05302455 /* DDR_CLK_ALWAYS_ON */
2456 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 13, 13);
2457
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302458 dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_OFF);
2459 dsi_disable_scp_clk(dsidev);
Archit Taneja9e7e9372012-08-14 12:29:22 +05302460 dss_dsi_disable_pads(dsi->module_id, dsi_get_lane_mask(dsidev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002461}
2462
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302463static void dsi_config_tx_fifo(struct platform_device *dsidev,
2464 enum fifo_size size1, enum fifo_size size2,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002465 enum fifo_size size3, enum fifo_size size4)
2466{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302467 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002468 u32 r = 0;
2469 int add = 0;
2470 int i;
2471
Tomi Valkeinen558c73e2013-09-25 14:40:06 +03002472 dsi->vc[0].tx_fifo_size = size1;
2473 dsi->vc[1].tx_fifo_size = size2;
2474 dsi->vc[2].tx_fifo_size = size3;
2475 dsi->vc[3].tx_fifo_size = size4;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002476
2477 for (i = 0; i < 4; i++) {
2478 u8 v;
Tomi Valkeinen558c73e2013-09-25 14:40:06 +03002479 int size = dsi->vc[i].tx_fifo_size;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002480
2481 if (add + size > 4) {
2482 DSSERR("Illegal FIFO configuration\n");
2483 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002484 return;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002485 }
2486
2487 v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
2488 r |= v << (8 * i);
2489 /*DSSDBG("TX FIFO vc %d: size %d, add %d\n", i, size, add); */
2490 add += size;
2491 }
2492
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302493 dsi_write_reg(dsidev, DSI_TX_FIFO_VC_SIZE, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002494}
2495
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302496static void dsi_config_rx_fifo(struct platform_device *dsidev,
2497 enum fifo_size size1, enum fifo_size size2,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002498 enum fifo_size size3, enum fifo_size size4)
2499{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302500 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002501 u32 r = 0;
2502 int add = 0;
2503 int i;
2504
Tomi Valkeinen558c73e2013-09-25 14:40:06 +03002505 dsi->vc[0].rx_fifo_size = size1;
2506 dsi->vc[1].rx_fifo_size = size2;
2507 dsi->vc[2].rx_fifo_size = size3;
2508 dsi->vc[3].rx_fifo_size = size4;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002509
2510 for (i = 0; i < 4; i++) {
2511 u8 v;
Tomi Valkeinen558c73e2013-09-25 14:40:06 +03002512 int size = dsi->vc[i].rx_fifo_size;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002513
2514 if (add + size > 4) {
2515 DSSERR("Illegal FIFO configuration\n");
2516 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002517 return;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002518 }
2519
2520 v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
2521 r |= v << (8 * i);
2522 /*DSSDBG("RX FIFO vc %d: size %d, add %d\n", i, size, add); */
2523 add += size;
2524 }
2525
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302526 dsi_write_reg(dsidev, DSI_RX_FIFO_VC_SIZE, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002527}
2528
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302529static int dsi_force_tx_stop_mode_io(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002530{
2531 u32 r;
2532
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302533 r = dsi_read_reg(dsidev, DSI_TIMING1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002534 r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302535 dsi_write_reg(dsidev, DSI_TIMING1, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002536
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302537 if (wait_for_bit_change(dsidev, DSI_TIMING1, 15, 0) != 0) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002538 DSSERR("TX_STOP bit not going down\n");
2539 return -EIO;
2540 }
2541
2542 return 0;
2543}
2544
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302545static bool dsi_vc_is_enabled(struct platform_device *dsidev, int channel)
Archit Tanejacf398fb2011-03-23 09:59:34 +00002546{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302547 return REG_GET(dsidev, DSI_VC_CTRL(channel), 0, 0);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002548}
2549
2550static void dsi_packet_sent_handler_vp(void *data, u32 mask)
2551{
Archit Taneja2e868db2011-05-12 17:26:28 +05302552 struct dsi_packet_sent_handler_data *vp_data =
2553 (struct dsi_packet_sent_handler_data *) data;
2554 struct dsi_data *dsi = dsi_get_dsidrv_data(vp_data->dsidev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302555 const int channel = dsi->update_channel;
2556 u8 bit = dsi->te_enabled ? 30 : 31;
Archit Tanejacf398fb2011-03-23 09:59:34 +00002557
Archit Taneja2e868db2011-05-12 17:26:28 +05302558 if (REG_GET(vp_data->dsidev, DSI_VC_TE(channel), bit, bit) == 0)
2559 complete(vp_data->completion);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002560}
2561
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302562static int dsi_sync_vc_vp(struct platform_device *dsidev, int channel)
Archit Tanejacf398fb2011-03-23 09:59:34 +00002563{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302564 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Taneja2e868db2011-05-12 17:26:28 +05302565 DECLARE_COMPLETION_ONSTACK(completion);
2566 struct dsi_packet_sent_handler_data vp_data = { dsidev, &completion };
Archit Tanejacf398fb2011-03-23 09:59:34 +00002567 int r = 0;
2568 u8 bit;
2569
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302570 bit = dsi->te_enabled ? 30 : 31;
Archit Tanejacf398fb2011-03-23 09:59:34 +00002571
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302572 r = dsi_register_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp,
Archit Taneja2e868db2011-05-12 17:26:28 +05302573 &vp_data, DSI_VC_IRQ_PACKET_SENT);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002574 if (r)
2575 goto err0;
2576
2577 /* Wait for completion only if TE_EN/TE_START is still set */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302578 if (REG_GET(dsidev, DSI_VC_TE(channel), bit, bit)) {
Archit Tanejacf398fb2011-03-23 09:59:34 +00002579 if (wait_for_completion_timeout(&completion,
2580 msecs_to_jiffies(10)) == 0) {
2581 DSSERR("Failed to complete previous frame transfer\n");
2582 r = -EIO;
2583 goto err1;
2584 }
2585 }
2586
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302587 dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp,
Archit Taneja2e868db2011-05-12 17:26:28 +05302588 &vp_data, DSI_VC_IRQ_PACKET_SENT);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002589
2590 return 0;
2591err1:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302592 dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp,
Archit Taneja2e868db2011-05-12 17:26:28 +05302593 &vp_data, DSI_VC_IRQ_PACKET_SENT);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002594err0:
2595 return r;
2596}
2597
2598static void dsi_packet_sent_handler_l4(void *data, u32 mask)
2599{
Archit Taneja2e868db2011-05-12 17:26:28 +05302600 struct dsi_packet_sent_handler_data *l4_data =
2601 (struct dsi_packet_sent_handler_data *) data;
2602 struct dsi_data *dsi = dsi_get_dsidrv_data(l4_data->dsidev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302603 const int channel = dsi->update_channel;
Archit Tanejacf398fb2011-03-23 09:59:34 +00002604
Archit Taneja2e868db2011-05-12 17:26:28 +05302605 if (REG_GET(l4_data->dsidev, DSI_VC_CTRL(channel), 5, 5) == 0)
2606 complete(l4_data->completion);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002607}
2608
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302609static int dsi_sync_vc_l4(struct platform_device *dsidev, int channel)
Archit Tanejacf398fb2011-03-23 09:59:34 +00002610{
Archit Taneja2e868db2011-05-12 17:26:28 +05302611 DECLARE_COMPLETION_ONSTACK(completion);
2612 struct dsi_packet_sent_handler_data l4_data = { dsidev, &completion };
Archit Tanejacf398fb2011-03-23 09:59:34 +00002613 int r = 0;
2614
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302615 r = dsi_register_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4,
Archit Taneja2e868db2011-05-12 17:26:28 +05302616 &l4_data, DSI_VC_IRQ_PACKET_SENT);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002617 if (r)
2618 goto err0;
2619
2620 /* Wait for completion only if TX_FIFO_NOT_EMPTY is still set */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302621 if (REG_GET(dsidev, DSI_VC_CTRL(channel), 5, 5)) {
Archit Tanejacf398fb2011-03-23 09:59:34 +00002622 if (wait_for_completion_timeout(&completion,
2623 msecs_to_jiffies(10)) == 0) {
2624 DSSERR("Failed to complete previous l4 transfer\n");
2625 r = -EIO;
2626 goto err1;
2627 }
2628 }
2629
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302630 dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4,
Archit Taneja2e868db2011-05-12 17:26:28 +05302631 &l4_data, DSI_VC_IRQ_PACKET_SENT);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002632
2633 return 0;
2634err1:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302635 dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4,
Archit Taneja2e868db2011-05-12 17:26:28 +05302636 &l4_data, DSI_VC_IRQ_PACKET_SENT);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002637err0:
2638 return r;
2639}
2640
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302641static int dsi_sync_vc(struct platform_device *dsidev, int channel)
Archit Tanejacf398fb2011-03-23 09:59:34 +00002642{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302643 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2644
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302645 WARN_ON(!dsi_bus_is_locked(dsidev));
Archit Tanejacf398fb2011-03-23 09:59:34 +00002646
2647 WARN_ON(in_interrupt());
2648
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302649 if (!dsi_vc_is_enabled(dsidev, channel))
Archit Tanejacf398fb2011-03-23 09:59:34 +00002650 return 0;
2651
Archit Tanejad6049142011-08-22 11:58:08 +05302652 switch (dsi->vc[channel].source) {
2653 case DSI_VC_SOURCE_VP:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302654 return dsi_sync_vc_vp(dsidev, channel);
Archit Tanejad6049142011-08-22 11:58:08 +05302655 case DSI_VC_SOURCE_L4:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302656 return dsi_sync_vc_l4(dsidev, channel);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002657 default:
2658 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03002659 return -EINVAL;
Archit Tanejacf398fb2011-03-23 09:59:34 +00002660 }
2661}
2662
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302663static int dsi_vc_enable(struct platform_device *dsidev, int channel,
2664 bool enable)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002665{
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +02002666 DSSDBG("dsi_vc_enable channel %d, enable %d\n",
2667 channel, enable);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002668
2669 enable = enable ? 1 : 0;
2670
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302671 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 0, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002672
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302673 if (wait_for_bit_change(dsidev, DSI_VC_CTRL(channel),
2674 0, enable) != enable) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002675 DSSERR("Failed to set dsi_vc_enable to %d\n", enable);
2676 return -EIO;
2677 }
2678
2679 return 0;
2680}
2681
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302682static void dsi_vc_initial_config(struct platform_device *dsidev, int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002683{
Tomi Valkeinen2c1a3ea2013-02-22 13:42:59 +02002684 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002685 u32 r;
2686
Chandrabhanu Mahapatra702d2672012-09-24 17:12:58 +05302687 DSSDBG("Initial config of virtual channel %d", channel);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002688
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302689 r = dsi_read_reg(dsidev, DSI_VC_CTRL(channel));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002690
2691 if (FLD_GET(r, 15, 15)) /* VC_BUSY */
2692 DSSERR("VC(%d) busy when trying to configure it!\n",
2693 channel);
2694
2695 r = FLD_MOD(r, 0, 1, 1); /* SOURCE, 0 = L4 */
2696 r = FLD_MOD(r, 0, 2, 2); /* BTA_SHORT_EN */
2697 r = FLD_MOD(r, 0, 3, 3); /* BTA_LONG_EN */
2698 r = FLD_MOD(r, 0, 4, 4); /* MODE, 0 = command */
2699 r = FLD_MOD(r, 1, 7, 7); /* CS_TX_EN */
2700 r = FLD_MOD(r, 1, 8, 8); /* ECC_TX_EN */
2701 r = FLD_MOD(r, 0, 9, 9); /* MODE_SPEED, high speed on/off */
Archit Taneja9613c022011-03-22 06:33:36 -05002702 if (dss_has_feature(FEAT_DSI_VC_OCP_WIDTH))
2703 r = FLD_MOD(r, 3, 11, 10); /* OCP_WIDTH = 32 bit */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002704
2705 r = FLD_MOD(r, 4, 29, 27); /* DMA_RX_REQ_NB = no dma */
2706 r = FLD_MOD(r, 4, 23, 21); /* DMA_TX_REQ_NB = no dma */
2707
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302708 dsi_write_reg(dsidev, DSI_VC_CTRL(channel), r);
Tomi Valkeinen2c1a3ea2013-02-22 13:42:59 +02002709
2710 dsi->vc[channel].source = DSI_VC_SOURCE_L4;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002711}
2712
Archit Tanejad6049142011-08-22 11:58:08 +05302713static int dsi_vc_config_source(struct platform_device *dsidev, int channel,
2714 enum dsi_vc_source source)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002715{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302716 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2717
Archit Tanejad6049142011-08-22 11:58:08 +05302718 if (dsi->vc[channel].source == source)
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03002719 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002720
Chandrabhanu Mahapatra702d2672012-09-24 17:12:58 +05302721 DSSDBG("Source config of virtual channel %d", channel);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002722
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302723 dsi_sync_vc(dsidev, channel);
Archit Tanejacf398fb2011-03-23 09:59:34 +00002724
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302725 dsi_vc_enable(dsidev, channel, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002726
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03002727 /* VC_BUSY */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302728 if (wait_for_bit_change(dsidev, DSI_VC_CTRL(channel), 15, 0) != 0) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002729 DSSERR("vc(%d) busy when trying to config for VP\n", channel);
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03002730 return -EIO;
2731 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002732
Archit Tanejad6049142011-08-22 11:58:08 +05302733 /* SOURCE, 0 = L4, 1 = video port */
2734 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), source, 1, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002735
Archit Taneja9613c022011-03-22 06:33:36 -05002736 /* DCS_CMD_ENABLE */
Archit Tanejad6049142011-08-22 11:58:08 +05302737 if (dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC)) {
2738 bool enable = source == DSI_VC_SOURCE_VP;
2739 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 30, 30);
2740 }
Archit Taneja9613c022011-03-22 06:33:36 -05002741
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302742 dsi_vc_enable(dsidev, channel, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002743
Archit Tanejad6049142011-08-22 11:58:08 +05302744 dsi->vc[channel].source = source;
Tomi Valkeinen9ecd9682010-04-30 11:24:33 +03002745
2746 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002747}
2748
Tomi Valkeinen5cfc1c32013-05-15 11:24:30 +03002749static void dsi_vc_enable_hs(struct omap_dss_device *dssdev, int channel,
Archit Taneja1ffefe72011-05-12 17:26:24 +05302750 bool enable)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002751{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302752 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Taneja0b3ffe32012-08-13 22:13:39 +05302753 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302754
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002755 DSSDBG("dsi_vc_enable_hs(%d, %d)\n", channel, enable);
2756
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302757 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen61140c92010-01-12 16:00:30 +02002758
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302759 dsi_vc_enable(dsidev, channel, 0);
2760 dsi_if_enable(dsidev, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002761
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302762 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 9, 9);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002763
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302764 dsi_vc_enable(dsidev, channel, 1);
2765 dsi_if_enable(dsidev, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002766
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302767 dsi_force_tx_stop_mode_io(dsidev);
Archit Taneja8af6ff02011-09-05 16:48:27 +05302768
2769 /* start the DDR clock by sending a NULL packet */
Archit Taneja0b3ffe32012-08-13 22:13:39 +05302770 if (dsi->vm_timings.ddr_clk_always_on && enable)
Archit Taneja8af6ff02011-09-05 16:48:27 +05302771 dsi_vc_send_null(dssdev, channel);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002772}
2773
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302774static void dsi_vc_flush_long_data(struct platform_device *dsidev, int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002775{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302776 while (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002777 u32 val;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302778 val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002779 DSSDBG("\t\tb1 %#02x b2 %#02x b3 %#02x b4 %#02x\n",
2780 (val >> 0) & 0xff,
2781 (val >> 8) & 0xff,
2782 (val >> 16) & 0xff,
2783 (val >> 24) & 0xff);
2784 }
2785}
2786
2787static void dsi_show_rx_ack_with_err(u16 err)
2788{
2789 DSSERR("\tACK with ERROR (%#x):\n", err);
2790 if (err & (1 << 0))
2791 DSSERR("\t\tSoT Error\n");
2792 if (err & (1 << 1))
2793 DSSERR("\t\tSoT Sync Error\n");
2794 if (err & (1 << 2))
2795 DSSERR("\t\tEoT Sync Error\n");
2796 if (err & (1 << 3))
2797 DSSERR("\t\tEscape Mode Entry Command Error\n");
2798 if (err & (1 << 4))
2799 DSSERR("\t\tLP Transmit Sync Error\n");
2800 if (err & (1 << 5))
2801 DSSERR("\t\tHS Receive Timeout Error\n");
2802 if (err & (1 << 6))
2803 DSSERR("\t\tFalse Control Error\n");
2804 if (err & (1 << 7))
2805 DSSERR("\t\t(reserved7)\n");
2806 if (err & (1 << 8))
2807 DSSERR("\t\tECC Error, single-bit (corrected)\n");
2808 if (err & (1 << 9))
2809 DSSERR("\t\tECC Error, multi-bit (not corrected)\n");
2810 if (err & (1 << 10))
2811 DSSERR("\t\tChecksum Error\n");
2812 if (err & (1 << 11))
2813 DSSERR("\t\tData type not recognized\n");
2814 if (err & (1 << 12))
2815 DSSERR("\t\tInvalid VC ID\n");
2816 if (err & (1 << 13))
2817 DSSERR("\t\tInvalid Transmission Length\n");
2818 if (err & (1 << 14))
2819 DSSERR("\t\t(reserved14)\n");
2820 if (err & (1 << 15))
2821 DSSERR("\t\tDSI Protocol Violation\n");
2822}
2823
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302824static u16 dsi_vc_flush_receive_data(struct platform_device *dsidev,
2825 int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002826{
2827 /* RX_FIFO_NOT_EMPTY */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302828 while (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002829 u32 val;
2830 u8 dt;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302831 val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel));
Tomi Valkeinen86a78672010-03-16 16:19:06 +02002832 DSSERR("\trawval %#08x\n", val);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002833 dt = FLD_GET(val, 5, 0);
Archit Taneja7a7c48f2011-08-25 18:25:03 +05302834 if (dt == MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002835 u16 err = FLD_GET(val, 23, 8);
2836 dsi_show_rx_ack_with_err(err);
Archit Taneja7a7c48f2011-08-25 18:25:03 +05302837 } else if (dt == MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE) {
Tomi Valkeinen86a78672010-03-16 16:19:06 +02002838 DSSERR("\tDCS short response, 1 byte: %#x\n",
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002839 FLD_GET(val, 23, 8));
Archit Taneja7a7c48f2011-08-25 18:25:03 +05302840 } else if (dt == MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE) {
Tomi Valkeinen86a78672010-03-16 16:19:06 +02002841 DSSERR("\tDCS short response, 2 byte: %#x\n",
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002842 FLD_GET(val, 23, 8));
Archit Taneja7a7c48f2011-08-25 18:25:03 +05302843 } else if (dt == MIPI_DSI_RX_DCS_LONG_READ_RESPONSE) {
Tomi Valkeinen86a78672010-03-16 16:19:06 +02002844 DSSERR("\tDCS long response, len %d\n",
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002845 FLD_GET(val, 23, 8));
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302846 dsi_vc_flush_long_data(dsidev, channel);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002847 } else {
2848 DSSERR("\tunknown datatype 0x%02x\n", dt);
2849 }
2850 }
2851 return 0;
2852}
2853
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302854static int dsi_vc_send_bta(struct platform_device *dsidev, int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002855{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302856 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
2857
2858 if (dsi->debug_write || dsi->debug_read)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002859 DSSDBG("dsi_vc_send_bta %d\n", channel);
2860
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302861 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002862
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302863 /* RX_FIFO_NOT_EMPTY */
2864 if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002865 DSSERR("rx fifo not empty when sending BTA, dumping data:\n");
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302866 dsi_vc_flush_receive_data(dsidev, channel);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002867 }
2868
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302869 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 1, 6, 6); /* BTA_EN */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002870
Tomi Valkeinen968f8e92011-10-12 10:13:14 +03002871 /* flush posted write */
2872 dsi_read_reg(dsidev, DSI_VC_CTRL(channel));
2873
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002874 return 0;
2875}
2876
Tomi Valkeinen5cfc1c32013-05-15 11:24:30 +03002877static int dsi_vc_send_bta_sync(struct omap_dss_device *dssdev, int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002878{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302879 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Tomi Valkeinenf36a06e2011-03-02 14:48:41 +02002880 DECLARE_COMPLETION_ONSTACK(completion);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002881 int r = 0;
2882 u32 err;
2883
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302884 r = dsi_register_isr_vc(dsidev, channel, dsi_completion_handler,
Tomi Valkeinenf36a06e2011-03-02 14:48:41 +02002885 &completion, DSI_VC_IRQ_BTA);
2886 if (r)
2887 goto err0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002888
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302889 r = dsi_register_isr(dsidev, dsi_completion_handler, &completion,
Tomi Valkeinen773b30b2010-10-08 16:15:25 +03002890 DSI_IRQ_ERROR_MASK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002891 if (r)
Tomi Valkeinenf36a06e2011-03-02 14:48:41 +02002892 goto err1;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002893
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302894 r = dsi_vc_send_bta(dsidev, channel);
Tomi Valkeinen773b30b2010-10-08 16:15:25 +03002895 if (r)
2896 goto err2;
2897
Tomi Valkeinenf36a06e2011-03-02 14:48:41 +02002898 if (wait_for_completion_timeout(&completion,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002899 msecs_to_jiffies(500)) == 0) {
2900 DSSERR("Failed to receive BTA\n");
2901 r = -EIO;
Tomi Valkeinen773b30b2010-10-08 16:15:25 +03002902 goto err2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002903 }
2904
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302905 err = dsi_get_errors(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002906 if (err) {
2907 DSSERR("Error while sending BTA: %x\n", err);
2908 r = -EIO;
Tomi Valkeinen773b30b2010-10-08 16:15:25 +03002909 goto err2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002910 }
Tomi Valkeinen773b30b2010-10-08 16:15:25 +03002911err2:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302912 dsi_unregister_isr(dsidev, dsi_completion_handler, &completion,
Tomi Valkeinen773b30b2010-10-08 16:15:25 +03002913 DSI_IRQ_ERROR_MASK);
Tomi Valkeinenf36a06e2011-03-02 14:48:41 +02002914err1:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302915 dsi_unregister_isr_vc(dsidev, channel, dsi_completion_handler,
Tomi Valkeinenf36a06e2011-03-02 14:48:41 +02002916 &completion, DSI_VC_IRQ_BTA);
2917err0:
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002918 return r;
2919}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002920
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302921static inline void dsi_vc_write_long_header(struct platform_device *dsidev,
2922 int channel, u8 data_type, u16 len, u8 ecc)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002923{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302924 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002925 u32 val;
2926 u8 data_id;
2927
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302928 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002929
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302930 data_id = data_type | dsi->vc[channel].vc_id << 6;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002931
2932 val = FLD_VAL(data_id, 7, 0) | FLD_VAL(len, 23, 8) |
2933 FLD_VAL(ecc, 31, 24);
2934
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302935 dsi_write_reg(dsidev, DSI_VC_LONG_PACKET_HEADER(channel), val);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002936}
2937
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302938static inline void dsi_vc_write_long_payload(struct platform_device *dsidev,
2939 int channel, u8 b1, u8 b2, u8 b3, u8 b4)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002940{
2941 u32 val;
2942
2943 val = b4 << 24 | b3 << 16 | b2 << 8 | b1 << 0;
2944
2945/* DSSDBG("\twriting %02x, %02x, %02x, %02x (%#010x)\n",
2946 b1, b2, b3, b4, val); */
2947
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302948 dsi_write_reg(dsidev, DSI_VC_LONG_PACKET_PAYLOAD(channel), val);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002949}
2950
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302951static int dsi_vc_send_long(struct platform_device *dsidev, int channel,
2952 u8 data_type, u8 *data, u16 len, u8 ecc)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002953{
2954 /*u32 val; */
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302955 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002956 int i;
2957 u8 *p;
2958 int r = 0;
2959 u8 b1, b2, b3, b4;
2960
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302961 if (dsi->debug_write)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002962 DSSDBG("dsi_vc_send_long, %d bytes\n", len);
2963
2964 /* len + header */
Tomi Valkeinen558c73e2013-09-25 14:40:06 +03002965 if (dsi->vc[channel].tx_fifo_size * 32 * 4 < len + 4) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002966 DSSERR("unable to send long packet: packet too long.\n");
2967 return -EINVAL;
2968 }
2969
Archit Tanejad6049142011-08-22 11:58:08 +05302970 dsi_vc_config_source(dsidev, channel, DSI_VC_SOURCE_L4);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002971
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302972 dsi_vc_write_long_header(dsidev, channel, data_type, len, ecc);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002973
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002974 p = data;
2975 for (i = 0; i < len >> 2; i++) {
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302976 if (dsi->debug_write)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002977 DSSDBG("\tsending full packet %d\n", i);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002978
2979 b1 = *p++;
2980 b2 = *p++;
2981 b3 = *p++;
2982 b4 = *p++;
2983
Archit Tanejaa72b64b2011-05-12 17:26:26 +05302984 dsi_vc_write_long_payload(dsidev, channel, b1, b2, b3, b4);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002985 }
2986
2987 i = len % 4;
2988 if (i) {
2989 b1 = 0; b2 = 0; b3 = 0;
2990
Archit Tanejaf1da39d2011-05-12 17:26:27 +05302991 if (dsi->debug_write)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02002992 DSSDBG("\tsending remainder bytes %d\n", i);
2993
2994 switch (i) {
2995 case 3:
2996 b1 = *p++;
2997 b2 = *p++;
2998 b3 = *p++;
2999 break;
3000 case 2:
3001 b1 = *p++;
3002 b2 = *p++;
3003 break;
3004 case 1:
3005 b1 = *p++;
3006 break;
3007 }
3008
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303009 dsi_vc_write_long_payload(dsidev, channel, b1, b2, b3, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003010 }
3011
3012 return r;
3013}
3014
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303015static int dsi_vc_send_short(struct platform_device *dsidev, int channel,
3016 u8 data_type, u16 data, u8 ecc)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003017{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303018 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003019 u32 r;
3020 u8 data_id;
3021
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303022 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003023
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303024 if (dsi->debug_write)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003025 DSSDBG("dsi_vc_send_short(ch%d, dt %#x, b1 %#x, b2 %#x)\n",
3026 channel,
3027 data_type, data & 0xff, (data >> 8) & 0xff);
3028
Archit Tanejad6049142011-08-22 11:58:08 +05303029 dsi_vc_config_source(dsidev, channel, DSI_VC_SOURCE_L4);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003030
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303031 if (FLD_GET(dsi_read_reg(dsidev, DSI_VC_CTRL(channel)), 16, 16)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003032 DSSERR("ERROR FIFO FULL, aborting transfer\n");
3033 return -EINVAL;
3034 }
3035
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303036 data_id = data_type | dsi->vc[channel].vc_id << 6;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003037
3038 r = (data_id << 0) | (data << 8) | (ecc << 24);
3039
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303040 dsi_write_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel), r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003041
3042 return 0;
3043}
3044
Tomi Valkeinen5cfc1c32013-05-15 11:24:30 +03003045static int dsi_vc_send_null(struct omap_dss_device *dssdev, int channel)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003046{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303047 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303048
Archit Taneja18b7d092011-09-05 17:01:08 +05303049 return dsi_vc_send_long(dsidev, channel, MIPI_DSI_NULL_PACKET, NULL,
3050 0, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003051}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003052
Archit Taneja9e7e9372012-08-14 12:29:22 +05303053static int dsi_vc_write_nosync_common(struct platform_device *dsidev,
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303054 int channel, u8 *data, int len, enum dss_dsi_content_type type)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003055{
3056 int r;
3057
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303058 if (len == 0) {
3059 BUG_ON(type == DSS_DSI_CONTENT_DCS);
Archit Taneja7a7c48f2011-08-25 18:25:03 +05303060 r = dsi_vc_send_short(dsidev, channel,
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303061 MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM, 0, 0);
3062 } else if (len == 1) {
3063 r = dsi_vc_send_short(dsidev, channel,
3064 type == DSS_DSI_CONTENT_GENERIC ?
3065 MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM :
Archit Taneja7a7c48f2011-08-25 18:25:03 +05303066 MIPI_DSI_DCS_SHORT_WRITE, data[0], 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003067 } else if (len == 2) {
Archit Taneja7a7c48f2011-08-25 18:25:03 +05303068 r = dsi_vc_send_short(dsidev, channel,
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303069 type == DSS_DSI_CONTENT_GENERIC ?
3070 MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM :
Archit Taneja7a7c48f2011-08-25 18:25:03 +05303071 MIPI_DSI_DCS_SHORT_WRITE_PARAM,
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003072 data[0] | (data[1] << 8), 0);
3073 } else {
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303074 r = dsi_vc_send_long(dsidev, channel,
3075 type == DSS_DSI_CONTENT_GENERIC ?
3076 MIPI_DSI_GENERIC_LONG_WRITE :
3077 MIPI_DSI_DCS_LONG_WRITE, data, len, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003078 }
3079
3080 return r;
3081}
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303082
Tomi Valkeinen5cfc1c32013-05-15 11:24:30 +03003083static int dsi_vc_dcs_write_nosync(struct omap_dss_device *dssdev, int channel,
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303084 u8 *data, int len)
3085{
Archit Taneja9e7e9372012-08-14 12:29:22 +05303086 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
3087
3088 return dsi_vc_write_nosync_common(dsidev, channel, data, len,
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303089 DSS_DSI_CONTENT_DCS);
3090}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003091
Tomi Valkeinen5cfc1c32013-05-15 11:24:30 +03003092static int dsi_vc_generic_write_nosync(struct omap_dss_device *dssdev, int channel,
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303093 u8 *data, int len)
3094{
Archit Taneja9e7e9372012-08-14 12:29:22 +05303095 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
3096
3097 return dsi_vc_write_nosync_common(dsidev, channel, data, len,
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303098 DSS_DSI_CONTENT_GENERIC);
3099}
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303100
3101static int dsi_vc_write_common(struct omap_dss_device *dssdev, int channel,
3102 u8 *data, int len, enum dss_dsi_content_type type)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003103{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303104 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003105 int r;
3106
Archit Taneja9e7e9372012-08-14 12:29:22 +05303107 r = dsi_vc_write_nosync_common(dsidev, channel, data, len, type);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003108 if (r)
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003109 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003110
Archit Taneja1ffefe72011-05-12 17:26:24 +05303111 r = dsi_vc_send_bta_sync(dssdev, channel);
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003112 if (r)
3113 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003114
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303115 /* RX_FIFO_NOT_EMPTY */
3116 if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
Tomi Valkeinenb63ac1e2010-04-09 13:20:57 +03003117 DSSERR("rx fifo not empty after write, dumping data:\n");
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303118 dsi_vc_flush_receive_data(dsidev, channel);
Tomi Valkeinenb63ac1e2010-04-09 13:20:57 +03003119 r = -EIO;
3120 goto err;
3121 }
3122
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003123 return 0;
3124err:
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303125 DSSERR("dsi_vc_write_common(ch %d, cmd 0x%02x, len %d) failed\n",
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003126 channel, data[0], len);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003127 return r;
3128}
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303129
Tomi Valkeinen5cfc1c32013-05-15 11:24:30 +03003130static int dsi_vc_dcs_write(struct omap_dss_device *dssdev, int channel, u8 *data,
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303131 int len)
3132{
3133 return dsi_vc_write_common(dssdev, channel, data, len,
3134 DSS_DSI_CONTENT_DCS);
3135}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003136
Tomi Valkeinen5cfc1c32013-05-15 11:24:30 +03003137static int dsi_vc_generic_write(struct omap_dss_device *dssdev, int channel, u8 *data,
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303138 int len)
3139{
3140 return dsi_vc_write_common(dssdev, channel, data, len,
3141 DSS_DSI_CONTENT_GENERIC);
3142}
Archit Taneja6ff8aa32011-08-25 18:35:58 +05303143
Archit Taneja9e7e9372012-08-14 12:29:22 +05303144static int dsi_vc_dcs_send_read_request(struct platform_device *dsidev,
Archit Tanejab8509752011-08-30 15:48:23 +05303145 int channel, u8 dcs_cmd)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003146{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303147 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejab8509752011-08-30 15:48:23 +05303148 int r;
3149
3150 if (dsi->debug_read)
3151 DSSDBG("dsi_vc_dcs_send_read_request(ch%d, dcs_cmd %x)\n",
3152 channel, dcs_cmd);
3153
3154 r = dsi_vc_send_short(dsidev, channel, MIPI_DSI_DCS_READ, dcs_cmd, 0);
3155 if (r) {
3156 DSSERR("dsi_vc_dcs_send_read_request(ch %d, cmd 0x%02x)"
3157 " failed\n", channel, dcs_cmd);
3158 return r;
3159 }
3160
3161 return 0;
3162}
3163
Archit Taneja9e7e9372012-08-14 12:29:22 +05303164static int dsi_vc_generic_send_read_request(struct platform_device *dsidev,
Archit Tanejab3b89c02011-08-30 16:07:39 +05303165 int channel, u8 *reqdata, int reqlen)
3166{
Archit Tanejab3b89c02011-08-30 16:07:39 +05303167 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
3168 u16 data;
3169 u8 data_type;
3170 int r;
3171
3172 if (dsi->debug_read)
3173 DSSDBG("dsi_vc_generic_send_read_request(ch %d, reqlen %d)\n",
3174 channel, reqlen);
3175
3176 if (reqlen == 0) {
3177 data_type = MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM;
3178 data = 0;
3179 } else if (reqlen == 1) {
3180 data_type = MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM;
3181 data = reqdata[0];
3182 } else if (reqlen == 2) {
3183 data_type = MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM;
3184 data = reqdata[0] | (reqdata[1] << 8);
3185 } else {
3186 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03003187 return -EINVAL;
Archit Tanejab3b89c02011-08-30 16:07:39 +05303188 }
3189
3190 r = dsi_vc_send_short(dsidev, channel, data_type, data, 0);
3191 if (r) {
3192 DSSERR("dsi_vc_generic_send_read_request(ch %d, reqlen %d)"
3193 " failed\n", channel, reqlen);
3194 return r;
3195 }
3196
3197 return 0;
3198}
3199
3200static int dsi_vc_read_rx_fifo(struct platform_device *dsidev, int channel,
3201 u8 *buf, int buflen, enum dss_dsi_content_type type)
Archit Tanejab8509752011-08-30 15:48:23 +05303202{
3203 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003204 u32 val;
3205 u8 dt;
3206 int r;
3207
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003208 /* RX_FIFO_NOT_EMPTY */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303209 if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20) == 0) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003210 DSSERR("RX fifo empty when trying to read.\n");
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003211 r = -EIO;
3212 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003213 }
3214
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303215 val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel));
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303216 if (dsi->debug_read)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003217 DSSDBG("\theader: %08x\n", val);
3218 dt = FLD_GET(val, 5, 0);
Archit Taneja7a7c48f2011-08-25 18:25:03 +05303219 if (dt == MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003220 u16 err = FLD_GET(val, 23, 8);
3221 dsi_show_rx_ack_with_err(err);
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003222 r = -EIO;
3223 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003224
Archit Tanejab3b89c02011-08-30 16:07:39 +05303225 } else if (dt == (type == DSS_DSI_CONTENT_GENERIC ?
3226 MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_1BYTE :
3227 MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003228 u8 data = FLD_GET(val, 15, 8);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303229 if (dsi->debug_read)
Archit Tanejab3b89c02011-08-30 16:07:39 +05303230 DSSDBG("\t%s short response, 1 byte: %02x\n",
3231 type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" :
3232 "DCS", data);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003233
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003234 if (buflen < 1) {
3235 r = -EIO;
3236 goto err;
3237 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003238
3239 buf[0] = data;
3240
3241 return 1;
Archit Tanejab3b89c02011-08-30 16:07:39 +05303242 } else if (dt == (type == DSS_DSI_CONTENT_GENERIC ?
3243 MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_2BYTE :
3244 MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003245 u16 data = FLD_GET(val, 23, 8);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303246 if (dsi->debug_read)
Archit Tanejab3b89c02011-08-30 16:07:39 +05303247 DSSDBG("\t%s short response, 2 byte: %04x\n",
3248 type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" :
3249 "DCS", data);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003250
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003251 if (buflen < 2) {
3252 r = -EIO;
3253 goto err;
3254 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003255
3256 buf[0] = data & 0xff;
3257 buf[1] = (data >> 8) & 0xff;
3258
3259 return 2;
Archit Tanejab3b89c02011-08-30 16:07:39 +05303260 } else if (dt == (type == DSS_DSI_CONTENT_GENERIC ?
3261 MIPI_DSI_RX_GENERIC_LONG_READ_RESPONSE :
3262 MIPI_DSI_RX_DCS_LONG_READ_RESPONSE)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003263 int w;
3264 int len = FLD_GET(val, 23, 8);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303265 if (dsi->debug_read)
Archit Tanejab3b89c02011-08-30 16:07:39 +05303266 DSSDBG("\t%s long response, len %d\n",
3267 type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" :
3268 "DCS", len);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003269
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003270 if (len > buflen) {
3271 r = -EIO;
3272 goto err;
3273 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003274
3275 /* two byte checksum ends the packet, not included in len */
3276 for (w = 0; w < len + 2;) {
3277 int b;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303278 val = dsi_read_reg(dsidev,
3279 DSI_VC_SHORT_PACKET_HEADER(channel));
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303280 if (dsi->debug_read)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003281 DSSDBG("\t\t%02x %02x %02x %02x\n",
3282 (val >> 0) & 0xff,
3283 (val >> 8) & 0xff,
3284 (val >> 16) & 0xff,
3285 (val >> 24) & 0xff);
3286
3287 for (b = 0; b < 4; ++b) {
3288 if (w < len)
3289 buf[w] = (val >> (b * 8)) & 0xff;
3290 /* we discard the 2 byte checksum */
3291 ++w;
3292 }
3293 }
3294
3295 return len;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003296 } else {
3297 DSSERR("\tunknown datatype 0x%02x\n", dt);
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003298 r = -EIO;
3299 goto err;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003300 }
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003301
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003302err:
Archit Tanejab3b89c02011-08-30 16:07:39 +05303303 DSSERR("dsi_vc_read_rx_fifo(ch %d type %s) failed\n", channel,
3304 type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" : "DCS");
Tomi Valkeinen5d68e032010-02-26 11:32:56 +02003305
Archit Tanejab8509752011-08-30 15:48:23 +05303306 return r;
3307}
3308
Tomi Valkeinen5cfc1c32013-05-15 11:24:30 +03003309static int dsi_vc_dcs_read(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
Archit Tanejab8509752011-08-30 15:48:23 +05303310 u8 *buf, int buflen)
3311{
3312 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
3313 int r;
3314
Archit Taneja9e7e9372012-08-14 12:29:22 +05303315 r = dsi_vc_dcs_send_read_request(dsidev, channel, dcs_cmd);
Archit Tanejab8509752011-08-30 15:48:23 +05303316 if (r)
3317 goto err;
3318
3319 r = dsi_vc_send_bta_sync(dssdev, channel);
3320 if (r)
3321 goto err;
3322
Archit Tanejab3b89c02011-08-30 16:07:39 +05303323 r = dsi_vc_read_rx_fifo(dsidev, channel, buf, buflen,
3324 DSS_DSI_CONTENT_DCS);
Archit Tanejab8509752011-08-30 15:48:23 +05303325 if (r < 0)
3326 goto err;
3327
3328 if (r != buflen) {
3329 r = -EIO;
3330 goto err;
3331 }
3332
3333 return 0;
3334err:
3335 DSSERR("dsi_vc_dcs_read(ch %d, cmd 0x%02x) failed\n", channel, dcs_cmd);
3336 return r;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003337}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003338
Archit Tanejab3b89c02011-08-30 16:07:39 +05303339static int dsi_vc_generic_read(struct omap_dss_device *dssdev, int channel,
3340 u8 *reqdata, int reqlen, u8 *buf, int buflen)
3341{
3342 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
3343 int r;
3344
Archit Taneja9e7e9372012-08-14 12:29:22 +05303345 r = dsi_vc_generic_send_read_request(dsidev, channel, reqdata, reqlen);
Archit Tanejab3b89c02011-08-30 16:07:39 +05303346 if (r)
3347 return r;
3348
3349 r = dsi_vc_send_bta_sync(dssdev, channel);
3350 if (r)
3351 return r;
3352
3353 r = dsi_vc_read_rx_fifo(dsidev, channel, buf, buflen,
3354 DSS_DSI_CONTENT_GENERIC);
3355 if (r < 0)
3356 return r;
3357
3358 if (r != buflen) {
3359 r = -EIO;
3360 return r;
3361 }
3362
3363 return 0;
3364}
3365
Tomi Valkeinen5cfc1c32013-05-15 11:24:30 +03003366static int dsi_vc_set_max_rx_packet_size(struct omap_dss_device *dssdev, int channel,
Archit Taneja1ffefe72011-05-12 17:26:24 +05303367 u16 len)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003368{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303369 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
3370
Archit Taneja7a7c48f2011-08-25 18:25:03 +05303371 return dsi_vc_send_short(dsidev, channel,
3372 MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE, len, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003373}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003374
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303375static int dsi_enter_ulps(struct platform_device *dsidev)
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003376{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303377 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003378 DECLARE_COMPLETION_ONSTACK(completion);
Tomi Valkeinen522a0c22011-10-13 16:18:52 +03003379 int r, i;
3380 unsigned mask;
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003381
Chandrabhanu Mahapatra702d2672012-09-24 17:12:58 +05303382 DSSDBG("Entering ULPS");
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003383
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303384 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003385
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303386 WARN_ON(dsi->ulps_enabled);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003387
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303388 if (dsi->ulps_enabled)
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003389 return 0;
3390
Tomi Valkeinen6cc78aa2011-10-13 19:22:43 +03003391 /* DDR_CLK_ALWAYS_ON */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303392 if (REG_GET(dsidev, DSI_CLK_CTRL, 13, 13)) {
Tomi Valkeinen6cc78aa2011-10-13 19:22:43 +03003393 dsi_if_enable(dsidev, 0);
3394 REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 13, 13);
3395 dsi_if_enable(dsidev, 1);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003396 }
3397
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303398 dsi_sync_vc(dsidev, 0);
3399 dsi_sync_vc(dsidev, 1);
3400 dsi_sync_vc(dsidev, 2);
3401 dsi_sync_vc(dsidev, 3);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003402
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303403 dsi_force_tx_stop_mode_io(dsidev);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003404
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303405 dsi_vc_enable(dsidev, 0, false);
3406 dsi_vc_enable(dsidev, 1, false);
3407 dsi_vc_enable(dsidev, 2, false);
3408 dsi_vc_enable(dsidev, 3, false);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003409
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303410 if (REG_GET(dsidev, DSI_COMPLEXIO_CFG2, 16, 16)) { /* HS_BUSY */
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003411 DSSERR("HS busy when enabling ULPS\n");
3412 return -EIO;
3413 }
3414
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303415 if (REG_GET(dsidev, DSI_COMPLEXIO_CFG2, 17, 17)) { /* LP_BUSY */
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003416 DSSERR("LP busy when enabling ULPS\n");
3417 return -EIO;
3418 }
3419
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303420 r = dsi_register_isr_cio(dsidev, dsi_completion_handler, &completion,
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003421 DSI_CIO_IRQ_ULPSACTIVENOT_ALL0);
3422 if (r)
3423 return r;
3424
Tomi Valkeinen522a0c22011-10-13 16:18:52 +03003425 mask = 0;
3426
3427 for (i = 0; i < dsi->num_lanes_supported; ++i) {
3428 if (dsi->lanes[i].function == DSI_LANE_UNUSED)
3429 continue;
3430 mask |= 1 << i;
3431 }
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003432 /* Assert TxRequestEsc for data lanes and TxUlpsClk for clk lane */
3433 /* LANEx_ULPS_SIG2 */
Tomi Valkeinen522a0c22011-10-13 16:18:52 +03003434 REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG2, mask, 9, 5);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003435
Tomi Valkeinena702c852011-10-12 10:10:21 +03003436 /* flush posted write and wait for SCP interface to finish the write */
3437 dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG2);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003438
3439 if (wait_for_completion_timeout(&completion,
3440 msecs_to_jiffies(1000)) == 0) {
3441 DSSERR("ULPS enable timeout\n");
3442 r = -EIO;
3443 goto err;
3444 }
3445
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303446 dsi_unregister_isr_cio(dsidev, dsi_completion_handler, &completion,
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003447 DSI_CIO_IRQ_ULPSACTIVENOT_ALL0);
3448
Tomi Valkeinen8ef0e612011-05-31 16:55:47 +03003449 /* Reset LANEx_ULPS_SIG2 */
Tomi Valkeinen522a0c22011-10-13 16:18:52 +03003450 REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG2, 0, 9, 5);
Tomi Valkeinen8ef0e612011-05-31 16:55:47 +03003451
Tomi Valkeinena702c852011-10-12 10:10:21 +03003452 /* flush posted write and wait for SCP interface to finish the write */
3453 dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG2);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003454
Archit Tanejaf1da39d2011-05-12 17:26:27 +05303455 dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_ULPS);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003456
3457 dsi_if_enable(dsidev, false);
3458
3459 dsi->ulps_enabled = true;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303460
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03003461 return 0;
3462
3463err:
3464 dsi_unregister_isr_cio(dsidev, dsi_completion_handler, &completion,
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303465 DSI_CIO_IRQ_ULPSACTIVENOT_ALL0);
3466 return r;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003467}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003468
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003469static void dsi_set_lp_rx_timeout(struct platform_device *dsidev,
3470 unsigned ticks, bool x4, bool x16)
3471{
3472 unsigned long fck;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003473 unsigned long total_ticks;
3474 u32 r;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303475
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003476 BUG_ON(ticks > 0x1fff);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303477
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003478 /* ticks in DSI_FCK */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003479 fck = dsi_fclk_rate(dsidev);
3480
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003481 r = dsi_read_reg(dsidev, DSI_TIMING2);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303482 r = FLD_MOD(r, 1, 15, 15); /* LP_RX_TO */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003483 r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* LP_RX_TO_X16 */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003484 r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* LP_RX_TO_X4 */
3485 r = FLD_MOD(r, ticks, 12, 0); /* LP_RX_COUNTER */
3486 dsi_write_reg(dsidev, DSI_TIMING2, r);
3487
3488 total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
3489
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003490 DSSDBG("LP_RX_TO %lu ticks (%#x%s%s) = %lu ns\n",
3491 total_ticks,
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303492 ticks, x4 ? " x4" : "", x16 ? " x16" : "",
3493 (total_ticks * 1000) / (fck / 1000 / 1000));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003494}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003495
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003496static void dsi_set_ta_timeout(struct platform_device *dsidev, unsigned ticks,
3497 bool x8, bool x16)
3498{
3499 unsigned long fck;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003500 unsigned long total_ticks;
3501 u32 r;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303502
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003503 BUG_ON(ticks > 0x1fff);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303504
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003505 /* ticks in DSI_FCK */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003506 fck = dsi_fclk_rate(dsidev);
3507
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003508 r = dsi_read_reg(dsidev, DSI_TIMING1);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303509 r = FLD_MOD(r, 1, 31, 31); /* TA_TO */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003510 r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* TA_TO_X16 */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003511 r = FLD_MOD(r, x8 ? 1 : 0, 29, 29); /* TA_TO_X8 */
3512 r = FLD_MOD(r, ticks, 28, 16); /* TA_TO_COUNTER */
3513 dsi_write_reg(dsidev, DSI_TIMING1, r);
3514
3515 total_ticks = ticks * (x16 ? 16 : 1) * (x8 ? 8 : 1);
3516
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003517 DSSDBG("TA_TO %lu ticks (%#x%s%s) = %lu ns\n",
3518 total_ticks,
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303519 ticks, x8 ? " x8" : "", x16 ? " x16" : "",
3520 (total_ticks * 1000) / (fck / 1000 / 1000));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003521}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003522
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003523static void dsi_set_stop_state_counter(struct platform_device *dsidev,
3524 unsigned ticks, bool x4, bool x16)
3525{
3526 unsigned long fck;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003527 unsigned long total_ticks;
3528 u32 r;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303529
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003530 BUG_ON(ticks > 0x1fff);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303531
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003532 /* ticks in DSI_FCK */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003533 fck = dsi_fclk_rate(dsidev);
3534
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003535 r = dsi_read_reg(dsidev, DSI_TIMING1);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303536 r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003537 r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* STOP_STATE_X16_IO */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003538 r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* STOP_STATE_X4_IO */
3539 r = FLD_MOD(r, ticks, 12, 0); /* STOP_STATE_COUNTER_IO */
3540 dsi_write_reg(dsidev, DSI_TIMING1, r);
3541
3542 total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
3543
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003544 DSSDBG("STOP_STATE_COUNTER %lu ticks (%#x%s%s) = %lu ns\n",
3545 total_ticks,
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303546 ticks, x4 ? " x4" : "", x16 ? " x16" : "",
3547 (total_ticks * 1000) / (fck / 1000 / 1000));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003548}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003549
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003550static void dsi_set_hs_tx_timeout(struct platform_device *dsidev,
3551 unsigned ticks, bool x4, bool x16)
3552{
3553 unsigned long fck;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003554 unsigned long total_ticks;
3555 u32 r;
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303556
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003557 BUG_ON(ticks > 0x1fff);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303558
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003559 /* ticks in TxByteClkHS */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003560 fck = dsi_get_txbyteclkhs(dsidev);
3561
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003562 r = dsi_read_reg(dsidev, DSI_TIMING2);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303563 r = FLD_MOD(r, 1, 31, 31); /* HS_TX_TO */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003564 r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* HS_TX_TO_X16 */
Tomi Valkeinen4ffa3572010-04-12 10:40:12 +03003565 r = FLD_MOD(r, x4 ? 1 : 0, 29, 29); /* HS_TX_TO_X8 (4 really) */
3566 r = FLD_MOD(r, ticks, 28, 16); /* HS_TX_TO_COUNTER */
3567 dsi_write_reg(dsidev, DSI_TIMING2, r);
3568
3569 total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
3570
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003571 DSSDBG("HS_TX_TO %lu ticks (%#x%s%s) = %lu ns\n",
3572 total_ticks,
3573 ticks, x4 ? " x4" : "", x16 ? " x16" : "",
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303574 (total_ticks * 1000) / (fck / 1000 / 1000));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003575}
Archit Taneja8af6ff02011-09-05 16:48:27 +05303576
Archit Taneja9e7e9372012-08-14 12:29:22 +05303577static void dsi_config_vp_num_line_buffers(struct platform_device *dsidev)
Archit Taneja8af6ff02011-09-05 16:48:27 +05303578{
Archit Tanejadca2b152012-08-16 18:02:00 +05303579 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Taneja8af6ff02011-09-05 16:48:27 +05303580 int num_line_buffers;
3581
Archit Tanejadca2b152012-08-16 18:02:00 +05303582 if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
Archit Taneja02c39602012-08-10 15:01:33 +05303583 int bpp = dsi_get_pixel_size(dsi->pix_fmt);
Archit Tanejae67458a2012-08-13 14:17:30 +05303584 struct omap_video_timings *timings = &dsi->timings;
Archit Taneja8af6ff02011-09-05 16:48:27 +05303585 /*
3586 * Don't use line buffers if width is greater than the video
3587 * port's line buffer size
3588 */
Tomi Valkeinen99322572013-03-05 10:37:02 +02003589 if (dsi->line_buffer_size <= timings->x_res * bpp / 8)
Archit Taneja8af6ff02011-09-05 16:48:27 +05303590 num_line_buffers = 0;
3591 else
3592 num_line_buffers = 2;
3593 } else {
3594 /* Use maximum number of line buffers in command mode */
3595 num_line_buffers = 2;
3596 }
3597
3598 /* LINE_BUFFER */
3599 REG_FLD_MOD(dsidev, DSI_CTRL, num_line_buffers, 13, 12);
3600}
3601
Archit Taneja9e7e9372012-08-14 12:29:22 +05303602static void dsi_config_vp_sync_events(struct platform_device *dsidev)
Archit Taneja8af6ff02011-09-05 16:48:27 +05303603{
Archit Taneja0b3ffe32012-08-13 22:13:39 +05303604 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen478d7df2013-03-05 16:29:36 +02003605 bool sync_end;
Archit Taneja8af6ff02011-09-05 16:48:27 +05303606 u32 r;
3607
Tomi Valkeinen478d7df2013-03-05 16:29:36 +02003608 if (dsi->vm_timings.trans_mode == OMAP_DSS_DSI_PULSE_MODE)
3609 sync_end = true;
3610 else
3611 sync_end = false;
3612
Archit Taneja8af6ff02011-09-05 16:48:27 +05303613 r = dsi_read_reg(dsidev, DSI_CTRL);
Archit Tanejabd5a7b12012-06-26 12:38:31 +05303614 r = FLD_MOD(r, 1, 9, 9); /* VP_DE_POL */
3615 r = FLD_MOD(r, 1, 10, 10); /* VP_HSYNC_POL */
3616 r = FLD_MOD(r, 1, 11, 11); /* VP_VSYNC_POL */
Archit Taneja8af6ff02011-09-05 16:48:27 +05303617 r = FLD_MOD(r, 1, 15, 15); /* VP_VSYNC_START */
Tomi Valkeinen478d7df2013-03-05 16:29:36 +02003618 r = FLD_MOD(r, sync_end, 16, 16); /* VP_VSYNC_END */
Archit Taneja8af6ff02011-09-05 16:48:27 +05303619 r = FLD_MOD(r, 1, 17, 17); /* VP_HSYNC_START */
Tomi Valkeinen478d7df2013-03-05 16:29:36 +02003620 r = FLD_MOD(r, sync_end, 18, 18); /* VP_HSYNC_END */
Archit Taneja8af6ff02011-09-05 16:48:27 +05303621 dsi_write_reg(dsidev, DSI_CTRL, r);
3622}
3623
Archit Taneja9e7e9372012-08-14 12:29:22 +05303624static void dsi_config_blanking_modes(struct platform_device *dsidev)
Archit Taneja8af6ff02011-09-05 16:48:27 +05303625{
Archit Taneja0b3ffe32012-08-13 22:13:39 +05303626 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
3627 int blanking_mode = dsi->vm_timings.blanking_mode;
3628 int hfp_blanking_mode = dsi->vm_timings.hfp_blanking_mode;
3629 int hbp_blanking_mode = dsi->vm_timings.hbp_blanking_mode;
3630 int hsa_blanking_mode = dsi->vm_timings.hsa_blanking_mode;
Archit Taneja8af6ff02011-09-05 16:48:27 +05303631 u32 r;
3632
3633 /*
3634 * 0 = TX FIFO packets sent or LPS in corresponding blanking periods
3635 * 1 = Long blanking packets are sent in corresponding blanking periods
3636 */
3637 r = dsi_read_reg(dsidev, DSI_CTRL);
3638 r = FLD_MOD(r, blanking_mode, 20, 20); /* BLANKING_MODE */
3639 r = FLD_MOD(r, hfp_blanking_mode, 21, 21); /* HFP_BLANKING */
3640 r = FLD_MOD(r, hbp_blanking_mode, 22, 22); /* HBP_BLANKING */
3641 r = FLD_MOD(r, hsa_blanking_mode, 23, 23); /* HSA_BLANKING */
3642 dsi_write_reg(dsidev, DSI_CTRL, r);
3643}
3644
Archit Taneja6f28c292012-05-15 11:32:18 +05303645/*
3646 * According to section 'HS Command Mode Interleaving' in OMAP TRM, Scenario 3
3647 * results in maximum transition time for data and clock lanes to enter and
3648 * exit HS mode. Hence, this is the scenario where the least amount of command
3649 * mode data can be interleaved. We program the minimum amount of TXBYTECLKHS
3650 * clock cycles that can be used to interleave command mode data in HS so that
3651 * all scenarios are satisfied.
3652 */
3653static int dsi_compute_interleave_hs(int blank, bool ddr_alwon, int enter_hs,
3654 int exit_hs, int exiths_clk, int ddr_pre, int ddr_post)
3655{
3656 int transition;
3657
3658 /*
3659 * If DDR_CLK_ALWAYS_ON is set, we need to consider HS mode transition
3660 * time of data lanes only, if it isn't set, we need to consider HS
3661 * transition time of both data and clock lanes. HS transition time
3662 * of Scenario 3 is considered.
3663 */
3664 if (ddr_alwon) {
3665 transition = enter_hs + exit_hs + max(enter_hs, 2) + 1;
3666 } else {
3667 int trans1, trans2;
3668 trans1 = ddr_pre + enter_hs + exit_hs + max(enter_hs, 2) + 1;
3669 trans2 = ddr_pre + enter_hs + exiths_clk + ddr_post + ddr_pre +
3670 enter_hs + 1;
3671 transition = max(trans1, trans2);
3672 }
3673
3674 return blank > transition ? blank - transition : 0;
3675}
3676
3677/*
3678 * According to section 'LP Command Mode Interleaving' in OMAP TRM, Scenario 1
3679 * results in maximum transition time for data lanes to enter and exit LP mode.
3680 * Hence, this is the scenario where the least amount of command mode data can
3681 * be interleaved. We program the minimum amount of bytes that can be
3682 * interleaved in LP so that all scenarios are satisfied.
3683 */
3684static int dsi_compute_interleave_lp(int blank, int enter_hs, int exit_hs,
3685 int lp_clk_div, int tdsi_fclk)
3686{
3687 int trans_lp; /* time required for a LP transition, in TXBYTECLKHS */
3688 int tlp_avail; /* time left for interleaving commands, in CLKIN4DDR */
3689 int ttxclkesc; /* period of LP transmit escape clock, in CLKIN4DDR */
3690 int thsbyte_clk = 16; /* Period of TXBYTECLKHS clock, in CLKIN4DDR */
3691 int lp_inter; /* cmd mode data that can be interleaved, in bytes */
3692
3693 /* maximum LP transition time according to Scenario 1 */
3694 trans_lp = exit_hs + max(enter_hs, 2) + 1;
3695
3696 /* CLKIN4DDR = 16 * TXBYTECLKHS */
3697 tlp_avail = thsbyte_clk * (blank - trans_lp);
3698
Archit Taneja2e063c32012-06-04 13:36:34 +05303699 ttxclkesc = tdsi_fclk * lp_clk_div;
Archit Taneja6f28c292012-05-15 11:32:18 +05303700
3701 lp_inter = ((tlp_avail - 8 * thsbyte_clk - 5 * tdsi_fclk) / ttxclkesc -
3702 26) / 16;
3703
3704 return max(lp_inter, 0);
3705}
3706
Tomi Valkeinen57612172012-11-27 17:32:36 +02003707static void dsi_config_cmd_mode_interleaving(struct platform_device *dsidev)
Archit Taneja6f28c292012-05-15 11:32:18 +05303708{
Archit Taneja6f28c292012-05-15 11:32:18 +05303709 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
3710 int blanking_mode;
3711 int hfp_blanking_mode, hbp_blanking_mode, hsa_blanking_mode;
3712 int hsa, hfp, hbp, width_bytes, bllp, lp_clk_div;
3713 int ddr_clk_pre, ddr_clk_post, enter_hs_mode_lat, exit_hs_mode_lat;
3714 int tclk_trail, ths_exit, exiths_clk;
3715 bool ddr_alwon;
Archit Tanejae67458a2012-08-13 14:17:30 +05303716 struct omap_video_timings *timings = &dsi->timings;
Archit Taneja02c39602012-08-10 15:01:33 +05303717 int bpp = dsi_get_pixel_size(dsi->pix_fmt);
Archit Taneja6f28c292012-05-15 11:32:18 +05303718 int ndl = dsi->num_lanes_used - 1;
Tomi Valkeinena0d269e2012-11-27 17:05:54 +02003719 int dsi_fclk_hsdiv = dsi->user_dsi_cinfo.regm_dsi + 1;
Archit Taneja6f28c292012-05-15 11:32:18 +05303720 int hsa_interleave_hs = 0, hsa_interleave_lp = 0;
3721 int hfp_interleave_hs = 0, hfp_interleave_lp = 0;
3722 int hbp_interleave_hs = 0, hbp_interleave_lp = 0;
3723 int bl_interleave_hs = 0, bl_interleave_lp = 0;
3724 u32 r;
3725
3726 r = dsi_read_reg(dsidev, DSI_CTRL);
3727 blanking_mode = FLD_GET(r, 20, 20);
3728 hfp_blanking_mode = FLD_GET(r, 21, 21);
3729 hbp_blanking_mode = FLD_GET(r, 22, 22);
3730 hsa_blanking_mode = FLD_GET(r, 23, 23);
3731
3732 r = dsi_read_reg(dsidev, DSI_VM_TIMING1);
3733 hbp = FLD_GET(r, 11, 0);
3734 hfp = FLD_GET(r, 23, 12);
3735 hsa = FLD_GET(r, 31, 24);
3736
3737 r = dsi_read_reg(dsidev, DSI_CLK_TIMING);
3738 ddr_clk_post = FLD_GET(r, 7, 0);
3739 ddr_clk_pre = FLD_GET(r, 15, 8);
3740
3741 r = dsi_read_reg(dsidev, DSI_VM_TIMING7);
3742 exit_hs_mode_lat = FLD_GET(r, 15, 0);
3743 enter_hs_mode_lat = FLD_GET(r, 31, 16);
3744
3745 r = dsi_read_reg(dsidev, DSI_CLK_CTRL);
3746 lp_clk_div = FLD_GET(r, 12, 0);
3747 ddr_alwon = FLD_GET(r, 13, 13);
3748
3749 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0);
3750 ths_exit = FLD_GET(r, 7, 0);
3751
3752 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1);
3753 tclk_trail = FLD_GET(r, 15, 8);
3754
3755 exiths_clk = ths_exit + tclk_trail;
3756
3757 width_bytes = DIV_ROUND_UP(timings->x_res * bpp, 8);
3758 bllp = hbp + hfp + hsa + DIV_ROUND_UP(width_bytes + 6, ndl);
3759
3760 if (!hsa_blanking_mode) {
3761 hsa_interleave_hs = dsi_compute_interleave_hs(hsa, ddr_alwon,
3762 enter_hs_mode_lat, exit_hs_mode_lat,
3763 exiths_clk, ddr_clk_pre, ddr_clk_post);
3764 hsa_interleave_lp = dsi_compute_interleave_lp(hsa,
3765 enter_hs_mode_lat, exit_hs_mode_lat,
3766 lp_clk_div, dsi_fclk_hsdiv);
3767 }
3768
3769 if (!hfp_blanking_mode) {
3770 hfp_interleave_hs = dsi_compute_interleave_hs(hfp, ddr_alwon,
3771 enter_hs_mode_lat, exit_hs_mode_lat,
3772 exiths_clk, ddr_clk_pre, ddr_clk_post);
3773 hfp_interleave_lp = dsi_compute_interleave_lp(hfp,
3774 enter_hs_mode_lat, exit_hs_mode_lat,
3775 lp_clk_div, dsi_fclk_hsdiv);
3776 }
3777
3778 if (!hbp_blanking_mode) {
3779 hbp_interleave_hs = dsi_compute_interleave_hs(hbp, ddr_alwon,
3780 enter_hs_mode_lat, exit_hs_mode_lat,
3781 exiths_clk, ddr_clk_pre, ddr_clk_post);
3782
3783 hbp_interleave_lp = dsi_compute_interleave_lp(hbp,
3784 enter_hs_mode_lat, exit_hs_mode_lat,
3785 lp_clk_div, dsi_fclk_hsdiv);
3786 }
3787
3788 if (!blanking_mode) {
3789 bl_interleave_hs = dsi_compute_interleave_hs(bllp, ddr_alwon,
3790 enter_hs_mode_lat, exit_hs_mode_lat,
3791 exiths_clk, ddr_clk_pre, ddr_clk_post);
3792
3793 bl_interleave_lp = dsi_compute_interleave_lp(bllp,
3794 enter_hs_mode_lat, exit_hs_mode_lat,
3795 lp_clk_div, dsi_fclk_hsdiv);
3796 }
3797
3798 DSSDBG("DSI HS interleaving(TXBYTECLKHS) HSA %d, HFP %d, HBP %d, BLLP %d\n",
3799 hsa_interleave_hs, hfp_interleave_hs, hbp_interleave_hs,
3800 bl_interleave_hs);
3801
3802 DSSDBG("DSI LP interleaving(bytes) HSA %d, HFP %d, HBP %d, BLLP %d\n",
3803 hsa_interleave_lp, hfp_interleave_lp, hbp_interleave_lp,
3804 bl_interleave_lp);
3805
3806 r = dsi_read_reg(dsidev, DSI_VM_TIMING4);
3807 r = FLD_MOD(r, hsa_interleave_hs, 23, 16);
3808 r = FLD_MOD(r, hfp_interleave_hs, 15, 8);
3809 r = FLD_MOD(r, hbp_interleave_hs, 7, 0);
3810 dsi_write_reg(dsidev, DSI_VM_TIMING4, r);
3811
3812 r = dsi_read_reg(dsidev, DSI_VM_TIMING5);
3813 r = FLD_MOD(r, hsa_interleave_lp, 23, 16);
3814 r = FLD_MOD(r, hfp_interleave_lp, 15, 8);
3815 r = FLD_MOD(r, hbp_interleave_lp, 7, 0);
3816 dsi_write_reg(dsidev, DSI_VM_TIMING5, r);
3817
3818 r = dsi_read_reg(dsidev, DSI_VM_TIMING6);
3819 r = FLD_MOD(r, bl_interleave_hs, 31, 15);
3820 r = FLD_MOD(r, bl_interleave_lp, 16, 0);
3821 dsi_write_reg(dsidev, DSI_VM_TIMING6, r);
3822}
3823
Tomi Valkeinen57612172012-11-27 17:32:36 +02003824static int dsi_proto_config(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003825{
Archit Taneja02c39602012-08-10 15:01:33 +05303826 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003827 u32 r;
3828 int buswidth = 0;
3829
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303830 dsi_config_tx_fifo(dsidev, DSI_FIFO_SIZE_32,
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02003831 DSI_FIFO_SIZE_32,
3832 DSI_FIFO_SIZE_32,
3833 DSI_FIFO_SIZE_32);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003834
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303835 dsi_config_rx_fifo(dsidev, DSI_FIFO_SIZE_32,
Tomi Valkeinendd8079d2009-12-16 16:49:03 +02003836 DSI_FIFO_SIZE_32,
3837 DSI_FIFO_SIZE_32,
3838 DSI_FIFO_SIZE_32);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003839
3840 /* XXX what values for the timeouts? */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303841 dsi_set_stop_state_counter(dsidev, 0x1000, false, false);
3842 dsi_set_ta_timeout(dsidev, 0x1fff, true, true);
3843 dsi_set_lp_rx_timeout(dsidev, 0x1fff, true, true);
3844 dsi_set_hs_tx_timeout(dsidev, 0x1fff, true, true);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003845
Archit Taneja02c39602012-08-10 15:01:33 +05303846 switch (dsi_get_pixel_size(dsi->pix_fmt)) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003847 case 16:
3848 buswidth = 0;
3849 break;
3850 case 18:
3851 buswidth = 1;
3852 break;
3853 case 24:
3854 buswidth = 2;
3855 break;
3856 default:
3857 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +03003858 return -EINVAL;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003859 }
3860
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303861 r = dsi_read_reg(dsidev, DSI_CTRL);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003862 r = FLD_MOD(r, 1, 1, 1); /* CS_RX_EN */
3863 r = FLD_MOD(r, 1, 2, 2); /* ECC_RX_EN */
3864 r = FLD_MOD(r, 1, 3, 3); /* TX_FIFO_ARBITRATION */
3865 r = FLD_MOD(r, 1, 4, 4); /* VP_CLK_RATIO, always 1, see errata*/
3866 r = FLD_MOD(r, buswidth, 7, 6); /* VP_DATA_BUS_WIDTH */
3867 r = FLD_MOD(r, 0, 8, 8); /* VP_CLK_POL */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003868 r = FLD_MOD(r, 1, 14, 14); /* TRIGGER_RESET_MODE */
3869 r = FLD_MOD(r, 1, 19, 19); /* EOT_ENABLE */
Archit Taneja9613c022011-03-22 06:33:36 -05003870 if (!dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC)) {
3871 r = FLD_MOD(r, 1, 24, 24); /* DCS_CMD_ENABLE */
3872 /* DCS_CMD_CODE, 1=start, 0=continue */
3873 r = FLD_MOD(r, 0, 25, 25);
3874 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003875
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303876 dsi_write_reg(dsidev, DSI_CTRL, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003877
Archit Taneja9e7e9372012-08-14 12:29:22 +05303878 dsi_config_vp_num_line_buffers(dsidev);
Archit Taneja8af6ff02011-09-05 16:48:27 +05303879
Archit Tanejadca2b152012-08-16 18:02:00 +05303880 if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
Archit Taneja9e7e9372012-08-14 12:29:22 +05303881 dsi_config_vp_sync_events(dsidev);
3882 dsi_config_blanking_modes(dsidev);
Tomi Valkeinen57612172012-11-27 17:32:36 +02003883 dsi_config_cmd_mode_interleaving(dsidev);
Archit Taneja8af6ff02011-09-05 16:48:27 +05303884 }
3885
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303886 dsi_vc_initial_config(dsidev, 0);
3887 dsi_vc_initial_config(dsidev, 1);
3888 dsi_vc_initial_config(dsidev, 2);
3889 dsi_vc_initial_config(dsidev, 3);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003890
3891 return 0;
3892}
3893
Archit Taneja9e7e9372012-08-14 12:29:22 +05303894static void dsi_proto_timings(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003895{
Tomi Valkeinendb186442011-10-13 16:12:29 +03003896 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003897 unsigned tlpx, tclk_zero, tclk_prepare, tclk_trail;
3898 unsigned tclk_pre, tclk_post;
3899 unsigned ths_prepare, ths_prepare_ths_zero, ths_zero;
3900 unsigned ths_trail, ths_exit;
3901 unsigned ddr_clk_pre, ddr_clk_post;
3902 unsigned enter_hs_mode_lat, exit_hs_mode_lat;
3903 unsigned ths_eot;
Tomi Valkeinendb186442011-10-13 16:12:29 +03003904 int ndl = dsi->num_lanes_used - 1;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003905 u32 r;
3906
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303907 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003908 ths_prepare = FLD_GET(r, 31, 24);
3909 ths_prepare_ths_zero = FLD_GET(r, 23, 16);
3910 ths_zero = ths_prepare_ths_zero - ths_prepare;
3911 ths_trail = FLD_GET(r, 15, 8);
3912 ths_exit = FLD_GET(r, 7, 0);
3913
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303914 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1);
Tomi Valkeinene84dc1c2012-09-24 09:34:52 +03003915 tlpx = FLD_GET(r, 20, 16) * 2;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003916 tclk_trail = FLD_GET(r, 15, 8);
3917 tclk_zero = FLD_GET(r, 7, 0);
3918
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303919 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG2);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003920 tclk_prepare = FLD_GET(r, 7, 0);
3921
3922 /* min 8*UI */
3923 tclk_pre = 20;
3924 /* min 60ns + 52*UI */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303925 tclk_post = ns2ddr(dsidev, 60) + 26;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003926
Archit Taneja8af6ff02011-09-05 16:48:27 +05303927 ths_eot = DIV_ROUND_UP(4, ndl);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003928
3929 ddr_clk_pre = DIV_ROUND_UP(tclk_pre + tlpx + tclk_zero + tclk_prepare,
3930 4);
3931 ddr_clk_post = DIV_ROUND_UP(tclk_post + ths_trail, 4) + ths_eot;
3932
3933 BUG_ON(ddr_clk_pre == 0 || ddr_clk_pre > 255);
3934 BUG_ON(ddr_clk_post == 0 || ddr_clk_post > 255);
3935
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303936 r = dsi_read_reg(dsidev, DSI_CLK_TIMING);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003937 r = FLD_MOD(r, ddr_clk_pre, 15, 8);
3938 r = FLD_MOD(r, ddr_clk_post, 7, 0);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303939 dsi_write_reg(dsidev, DSI_CLK_TIMING, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003940
3941 DSSDBG("ddr_clk_pre %u, ddr_clk_post %u\n",
3942 ddr_clk_pre,
3943 ddr_clk_post);
3944
3945 enter_hs_mode_lat = 1 + DIV_ROUND_UP(tlpx, 4) +
3946 DIV_ROUND_UP(ths_prepare, 4) +
3947 DIV_ROUND_UP(ths_zero + 3, 4);
3948
3949 exit_hs_mode_lat = DIV_ROUND_UP(ths_trail + ths_exit, 4) + 1 + ths_eot;
3950
3951 r = FLD_VAL(enter_hs_mode_lat, 31, 16) |
3952 FLD_VAL(exit_hs_mode_lat, 15, 0);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05303953 dsi_write_reg(dsidev, DSI_VM_TIMING7, r);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02003954
3955 DSSDBG("enter_hs_mode_lat %u, exit_hs_mode_lat %u\n",
3956 enter_hs_mode_lat, exit_hs_mode_lat);
Archit Taneja8af6ff02011-09-05 16:48:27 +05303957
Archit Tanejadca2b152012-08-16 18:02:00 +05303958 if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
Archit Taneja8af6ff02011-09-05 16:48:27 +05303959 /* TODO: Implement a video mode check_timings function */
Archit Taneja0b3ffe32012-08-13 22:13:39 +05303960 int hsa = dsi->vm_timings.hsa;
3961 int hfp = dsi->vm_timings.hfp;
3962 int hbp = dsi->vm_timings.hbp;
3963 int vsa = dsi->vm_timings.vsa;
3964 int vfp = dsi->vm_timings.vfp;
3965 int vbp = dsi->vm_timings.vbp;
3966 int window_sync = dsi->vm_timings.window_sync;
Tomi Valkeinen478d7df2013-03-05 16:29:36 +02003967 bool hsync_end;
Archit Tanejae67458a2012-08-13 14:17:30 +05303968 struct omap_video_timings *timings = &dsi->timings;
Archit Taneja02c39602012-08-10 15:01:33 +05303969 int bpp = dsi_get_pixel_size(dsi->pix_fmt);
Archit Taneja8af6ff02011-09-05 16:48:27 +05303970 int tl, t_he, width_bytes;
3971
Tomi Valkeinen478d7df2013-03-05 16:29:36 +02003972 hsync_end = dsi->vm_timings.trans_mode == OMAP_DSS_DSI_PULSE_MODE;
Archit Taneja8af6ff02011-09-05 16:48:27 +05303973 t_he = hsync_end ?
3974 ((hsa == 0 && ndl == 3) ? 1 : DIV_ROUND_UP(4, ndl)) : 0;
3975
3976 width_bytes = DIV_ROUND_UP(timings->x_res * bpp, 8);
3977
3978 /* TL = t_HS + HSA + t_HE + HFP + ceil((WC + 6) / NDL) + HBP */
3979 tl = DIV_ROUND_UP(4, ndl) + (hsync_end ? hsa : 0) + t_he + hfp +
3980 DIV_ROUND_UP(width_bytes + 6, ndl) + hbp;
3981
3982 DSSDBG("HBP: %d, HFP: %d, HSA: %d, TL: %d TXBYTECLKHS\n", hbp,
3983 hfp, hsync_end ? hsa : 0, tl);
3984 DSSDBG("VBP: %d, VFP: %d, VSA: %d, VACT: %d lines\n", vbp, vfp,
3985 vsa, timings->y_res);
3986
3987 r = dsi_read_reg(dsidev, DSI_VM_TIMING1);
3988 r = FLD_MOD(r, hbp, 11, 0); /* HBP */
3989 r = FLD_MOD(r, hfp, 23, 12); /* HFP */
3990 r = FLD_MOD(r, hsync_end ? hsa : 0, 31, 24); /* HSA */
3991 dsi_write_reg(dsidev, DSI_VM_TIMING1, r);
3992
3993 r = dsi_read_reg(dsidev, DSI_VM_TIMING2);
3994 r = FLD_MOD(r, vbp, 7, 0); /* VBP */
3995 r = FLD_MOD(r, vfp, 15, 8); /* VFP */
3996 r = FLD_MOD(r, vsa, 23, 16); /* VSA */
3997 r = FLD_MOD(r, window_sync, 27, 24); /* WINDOW_SYNC */
3998 dsi_write_reg(dsidev, DSI_VM_TIMING2, r);
3999
4000 r = dsi_read_reg(dsidev, DSI_VM_TIMING3);
4001 r = FLD_MOD(r, timings->y_res, 14, 0); /* VACT */
4002 r = FLD_MOD(r, tl, 31, 16); /* TL */
4003 dsi_write_reg(dsidev, DSI_VM_TIMING3, r);
4004 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004005}
4006
Tomi Valkeinen5cfc1c32013-05-15 11:24:30 +03004007static int dsi_configure_pins(struct omap_dss_device *dssdev,
Tomi Valkeinene4a9e942012-03-28 15:58:56 +03004008 const struct omap_dsi_pin_config *pin_cfg)
4009{
4010 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4011 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4012 int num_pins;
4013 const int *pins;
4014 struct dsi_lane_config lanes[DSI_MAX_NR_LANES];
4015 int num_lanes;
4016 int i;
4017
4018 static const enum dsi_lane_function functions[] = {
4019 DSI_LANE_CLK,
4020 DSI_LANE_DATA1,
4021 DSI_LANE_DATA2,
4022 DSI_LANE_DATA3,
4023 DSI_LANE_DATA4,
4024 };
4025
4026 num_pins = pin_cfg->num_pins;
4027 pins = pin_cfg->pins;
4028
4029 if (num_pins < 4 || num_pins > dsi->num_lanes_supported * 2
4030 || num_pins % 2 != 0)
4031 return -EINVAL;
4032
4033 for (i = 0; i < DSI_MAX_NR_LANES; ++i)
4034 lanes[i].function = DSI_LANE_UNUSED;
4035
4036 num_lanes = 0;
4037
4038 for (i = 0; i < num_pins; i += 2) {
4039 u8 lane, pol;
4040 int dx, dy;
4041
4042 dx = pins[i];
4043 dy = pins[i + 1];
4044
4045 if (dx < 0 || dx >= dsi->num_lanes_supported * 2)
4046 return -EINVAL;
4047
4048 if (dy < 0 || dy >= dsi->num_lanes_supported * 2)
4049 return -EINVAL;
4050
4051 if (dx & 1) {
4052 if (dy != dx - 1)
4053 return -EINVAL;
4054 pol = 1;
4055 } else {
4056 if (dy != dx + 1)
4057 return -EINVAL;
4058 pol = 0;
4059 }
4060
4061 lane = dx / 2;
4062
4063 lanes[lane].function = functions[i / 2];
4064 lanes[lane].polarity = pol;
4065 num_lanes++;
4066 }
4067
4068 memcpy(dsi->lanes, lanes, sizeof(dsi->lanes));
4069 dsi->num_lanes_used = num_lanes;
4070
4071 return 0;
4072}
Tomi Valkeinene4a9e942012-03-28 15:58:56 +03004073
Tomi Valkeinen5cfc1c32013-05-15 11:24:30 +03004074static int dsi_enable_video_output(struct omap_dss_device *dssdev, int channel)
Archit Taneja8af6ff02011-09-05 16:48:27 +05304075{
4076 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejae67458a2012-08-13 14:17:30 +05304077 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen57612172012-11-27 17:32:36 +02004078 struct omap_overlay_manager *mgr = dsi->output.manager;
Archit Taneja02c39602012-08-10 15:01:33 +05304079 int bpp = dsi_get_pixel_size(dsi->pix_fmt);
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +03004080 struct omap_dss_device *out = &dsi->output;
Archit Taneja8af6ff02011-09-05 16:48:27 +05304081 u8 data_type;
4082 u16 word_count;
Tomi Valkeinen33ca2372011-11-21 13:42:58 +02004083 int r;
Archit Taneja8af6ff02011-09-05 16:48:27 +05304084
Tomi Valkeinenb7dec9b2013-02-22 12:58:35 +02004085 if (out == NULL || out->manager == NULL) {
4086 DSSERR("failed to enable display: no output/manager\n");
4087 return -ENODEV;
4088 }
4089
4090 r = dsi_display_init_dispc(dsidev, mgr);
4091 if (r)
4092 goto err_init_dispc;
4093
Archit Tanejadca2b152012-08-16 18:02:00 +05304094 if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
Archit Taneja02c39602012-08-10 15:01:33 +05304095 switch (dsi->pix_fmt) {
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004096 case OMAP_DSS_DSI_FMT_RGB888:
4097 data_type = MIPI_DSI_PACKED_PIXEL_STREAM_24;
4098 break;
4099 case OMAP_DSS_DSI_FMT_RGB666:
4100 data_type = MIPI_DSI_PIXEL_STREAM_3BYTE_18;
4101 break;
4102 case OMAP_DSS_DSI_FMT_RGB666_PACKED:
4103 data_type = MIPI_DSI_PACKED_PIXEL_STREAM_18;
4104 break;
4105 case OMAP_DSS_DSI_FMT_RGB565:
4106 data_type = MIPI_DSI_PACKED_PIXEL_STREAM_16;
4107 break;
4108 default:
Tomi Valkeinenb7dec9b2013-02-22 12:58:35 +02004109 r = -EINVAL;
4110 goto err_pix_fmt;
Joe Perchescf6ac4ce2013-10-08 16:23:24 -07004111 }
Archit Taneja8af6ff02011-09-05 16:48:27 +05304112
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004113 dsi_if_enable(dsidev, false);
4114 dsi_vc_enable(dsidev, channel, false);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304115
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004116 /* MODE, 1 = video mode */
4117 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 1, 4, 4);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304118
Archit Tanejae67458a2012-08-13 14:17:30 +05304119 word_count = DIV_ROUND_UP(dsi->timings.x_res * bpp, 8);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304120
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004121 dsi_vc_write_long_header(dsidev, channel, data_type,
4122 word_count, 0);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304123
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004124 dsi_vc_enable(dsidev, channel, true);
4125 dsi_if_enable(dsidev, true);
4126 }
Archit Taneja8af6ff02011-09-05 16:48:27 +05304127
Archit Tanejaeea83402012-09-04 11:42:36 +05304128 r = dss_mgr_enable(mgr);
Tomi Valkeinenb7dec9b2013-02-22 12:58:35 +02004129 if (r)
4130 goto err_mgr_enable;
Archit Taneja8af6ff02011-09-05 16:48:27 +05304131
4132 return 0;
Tomi Valkeinenb7dec9b2013-02-22 12:58:35 +02004133
4134err_mgr_enable:
4135 if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
4136 dsi_if_enable(dsidev, false);
4137 dsi_vc_enable(dsidev, channel, false);
4138 }
4139err_pix_fmt:
4140 dsi_display_uninit_dispc(dsidev, mgr);
4141err_init_dispc:
4142 return r;
Archit Taneja8af6ff02011-09-05 16:48:27 +05304143}
Archit Taneja8af6ff02011-09-05 16:48:27 +05304144
Tomi Valkeinen5cfc1c32013-05-15 11:24:30 +03004145static void dsi_disable_video_output(struct omap_dss_device *dssdev, int channel)
Archit Taneja8af6ff02011-09-05 16:48:27 +05304146{
4147 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejadca2b152012-08-16 18:02:00 +05304148 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen57612172012-11-27 17:32:36 +02004149 struct omap_overlay_manager *mgr = dsi->output.manager;
Archit Taneja8af6ff02011-09-05 16:48:27 +05304150
Archit Tanejadca2b152012-08-16 18:02:00 +05304151 if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004152 dsi_if_enable(dsidev, false);
4153 dsi_vc_enable(dsidev, channel, false);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304154
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004155 /* MODE, 0 = command mode */
4156 REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 0, 4, 4);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304157
Tomi Valkeinen9a147a62011-11-09 15:30:11 +02004158 dsi_vc_enable(dsidev, channel, true);
4159 dsi_if_enable(dsidev, true);
4160 }
Archit Taneja8af6ff02011-09-05 16:48:27 +05304161
Archit Tanejaeea83402012-09-04 11:42:36 +05304162 dss_mgr_disable(mgr);
Tomi Valkeinenb7dec9b2013-02-22 12:58:35 +02004163
4164 dsi_display_uninit_dispc(dsidev, mgr);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304165}
Archit Taneja8af6ff02011-09-05 16:48:27 +05304166
Tomi Valkeinen57612172012-11-27 17:32:36 +02004167static void dsi_update_screen_dispc(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004168{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304169 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen57612172012-11-27 17:32:36 +02004170 struct omap_overlay_manager *mgr = dsi->output.manager;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004171 unsigned bytespp;
4172 unsigned bytespl;
4173 unsigned bytespf;
4174 unsigned total_len;
4175 unsigned packet_payload;
4176 unsigned packet_len;
4177 u32 l;
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03004178 int r;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304179 const unsigned channel = dsi->update_channel;
Tomi Valkeinen99322572013-03-05 10:37:02 +02004180 const unsigned line_buf_size = dsi->line_buffer_size;
Archit Taneja55cd63a2012-08-09 15:41:13 +05304181 u16 w = dsi->timings.x_res;
4182 u16 h = dsi->timings.y_res;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004183
Tomi Valkeinen5476e742011-11-03 16:34:20 +02004184 DSSDBG("dsi_update_screen_dispc(%dx%d)\n", w, h);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004185
Archit Tanejad6049142011-08-22 11:58:08 +05304186 dsi_vc_config_source(dsidev, channel, DSI_VC_SOURCE_VP);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004187
Archit Taneja02c39602012-08-10 15:01:33 +05304188 bytespp = dsi_get_pixel_size(dsi->pix_fmt) / 8;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004189 bytespl = w * bytespp;
4190 bytespf = bytespl * h;
4191
4192 /* NOTE: packet_payload has to be equal to N * bytespl, where N is
4193 * number of lines in a packet. See errata about VP_CLK_RATIO */
4194
4195 if (bytespf < line_buf_size)
4196 packet_payload = bytespf;
4197 else
4198 packet_payload = (line_buf_size) / bytespl * bytespl;
4199
4200 packet_len = packet_payload + 1; /* 1 byte for DCS cmd */
4201 total_len = (bytespf / packet_payload) * packet_len;
4202
4203 if (bytespf % packet_payload)
4204 total_len += (bytespf % packet_payload) + 1;
4205
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004206 l = FLD_VAL(total_len, 23, 0); /* TE_SIZE */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304207 dsi_write_reg(dsidev, DSI_VC_TE(channel), l);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004208
Archit Taneja7a7c48f2011-08-25 18:25:03 +05304209 dsi_vc_write_long_header(dsidev, channel, MIPI_DSI_DCS_LONG_WRITE,
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304210 packet_len, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004211
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304212 if (dsi->te_enabled)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004213 l = FLD_MOD(l, 1, 30, 30); /* TE_EN */
4214 else
4215 l = FLD_MOD(l, 1, 31, 31); /* TE_START */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304216 dsi_write_reg(dsidev, DSI_VC_TE(channel), l);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004217
4218 /* We put SIDLEMODE to no-idle for the duration of the transfer,
4219 * because DSS interrupts are not capable of waking up the CPU and the
4220 * framedone interrupt could be delayed for quite a long time. I think
4221 * the same goes for any DSS interrupts, but for some reason I have not
4222 * seen the problem anywhere else than here.
4223 */
4224 dispc_disable_sidle();
4225
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304226 dsi_perf_mark_start(dsidev);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004227
Archit Taneja49dbf582011-05-16 15:17:07 +05304228 r = schedule_delayed_work(&dsi->framedone_timeout_work,
4229 msecs_to_jiffies(250));
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03004230 BUG_ON(r == 0);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004231
Archit Tanejaeea83402012-09-04 11:42:36 +05304232 dss_mgr_set_timings(mgr, &dsi->timings);
Archit Taneja55cd63a2012-08-09 15:41:13 +05304233
Archit Tanejaeea83402012-09-04 11:42:36 +05304234 dss_mgr_start_update(mgr);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004235
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304236 if (dsi->te_enabled) {
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004237 /* disable LP_RX_TO, so that we can receive TE. Time to wait
4238 * for TE is longer than the timer allows */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304239 REG_FLD_MOD(dsidev, DSI_TIMING2, 0, 15, 15); /* LP_RX_TO */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004240
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304241 dsi_vc_send_bta(dsidev, channel);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004242
4243#ifdef DSI_CATCH_MISSING_TE
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304244 mod_timer(&dsi->te_timer, jiffies + msecs_to_jiffies(250));
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004245#endif
4246 }
4247}
4248
4249#ifdef DSI_CATCH_MISSING_TE
4250static void dsi_te_timeout(unsigned long arg)
4251{
4252 DSSERR("TE not received for 250ms!\n");
4253}
4254#endif
4255
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304256static void dsi_handle_framedone(struct platform_device *dsidev, int error)
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004257{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304258 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4259
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004260 /* SIDLEMODE back to smart-idle */
4261 dispc_enable_sidle();
4262
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304263 if (dsi->te_enabled) {
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004264 /* enable LP_RX_TO again after the TE */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304265 REG_FLD_MOD(dsidev, DSI_TIMING2, 1, 15, 15); /* LP_RX_TO */
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004266 }
4267
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304268 dsi->framedone_callback(error, dsi->framedone_data);
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004269
4270 if (!error)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304271 dsi_perf_show(dsidev, "DISPC");
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004272}
4273
4274static void dsi_framedone_timeout_work_callback(struct work_struct *work)
4275{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304276 struct dsi_data *dsi = container_of(work, struct dsi_data,
4277 framedone_timeout_work.work);
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03004278 /* XXX While extremely unlikely, we could get FRAMEDONE interrupt after
4279 * 250ms which would conflict with this timeout work. What should be
4280 * done is first cancel the transfer on the HW, and then cancel the
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004281 * possibly scheduled framedone work. However, cancelling the transfer
4282 * on the HW is buggy, and would probably require resetting the whole
4283 * DSI */
Tomi Valkeinen0f16aa02010-04-12 09:57:19 +03004284
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004285 DSSERR("Framedone not received for 250ms!\n");
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004286
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304287 dsi_handle_framedone(dsi->pdev, -ETIMEDOUT);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004288}
4289
Tomi Valkeinen15502022012-10-10 13:59:07 +03004290static void dsi_framedone_irq_callback(void *data)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004291{
Archit Taneja9e7e9372012-08-14 12:29:22 +05304292 struct platform_device *dsidev = (struct platform_device *) data;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304293 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4294
Tomi Valkeinenab83b142010-06-09 15:31:01 +03004295 /* Note: We get FRAMEDONE when DISPC has finished sending pixels and
4296 * turns itself off. However, DSI still has the pixels in its buffers,
4297 * and is sending the data.
4298 */
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004299
Tejun Heo136b5722012-08-21 13:18:24 -07004300 cancel_delayed_work(&dsi->framedone_timeout_work);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004301
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304302 dsi_handle_framedone(dsidev, 0);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004303}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004304
Tomi Valkeinen5cfc1c32013-05-15 11:24:30 +03004305static int dsi_update(struct omap_dss_device *dssdev, int channel,
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004306 void (*callback)(int, void *), void *data)
4307{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304308 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304309 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen5476e742011-11-03 16:34:20 +02004310 u16 dw, dh;
4311
4312 dsi_perf_mark_setup(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304313
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304314 dsi->update_channel = channel;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004315
Tomi Valkeinen4a9e78a2011-08-15 11:22:21 +03004316 dsi->framedone_callback = callback;
4317 dsi->framedone_data = data;
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004318
Archit Tanejae3525742012-08-09 15:23:43 +05304319 dw = dsi->timings.x_res;
4320 dh = dsi->timings.y_res;
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004321
Tomi Valkeinen477fed72013-10-02 14:41:24 +03004322#ifdef DSI_PERF_MEASURE
Tomi Valkeinen5476e742011-11-03 16:34:20 +02004323 dsi->update_bytes = dw * dh *
Archit Taneja02c39602012-08-10 15:01:33 +05304324 dsi_get_pixel_size(dsi->pix_fmt) / 8;
Tomi Valkeinen5476e742011-11-03 16:34:20 +02004325#endif
Tomi Valkeinen57612172012-11-27 17:32:36 +02004326 dsi_update_screen_dispc(dsidev);
Tomi Valkeinen18946f62010-01-12 14:16:41 +02004327
4328 return 0;
4329}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004330
4331/* Display funcs */
4332
Tomi Valkeinen57612172012-11-27 17:32:36 +02004333static int dsi_configure_dispc_clocks(struct platform_device *dsidev)
Archit Taneja7d2572f2012-06-29 14:31:07 +05304334{
Archit Taneja7d2572f2012-06-29 14:31:07 +05304335 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4336 struct dispc_clock_info dispc_cinfo;
4337 int r;
Tomi Valkeinen17518182013-03-07 11:21:45 +02004338 unsigned long fck;
Archit Taneja7d2572f2012-06-29 14:31:07 +05304339
4340 fck = dsi_get_pll_hsdiv_dispc_rate(dsidev);
4341
Tomi Valkeinena0d269e2012-11-27 17:05:54 +02004342 dispc_cinfo.lck_div = dsi->user_dispc_cinfo.lck_div;
4343 dispc_cinfo.pck_div = dsi->user_dispc_cinfo.pck_div;
Archit Taneja7d2572f2012-06-29 14:31:07 +05304344
4345 r = dispc_calc_clock_rates(fck, &dispc_cinfo);
4346 if (r) {
4347 DSSERR("Failed to calc dispc clocks\n");
4348 return r;
4349 }
4350
4351 dsi->mgr_config.clock_info = dispc_cinfo;
4352
4353 return 0;
4354}
4355
Tomi Valkeinenb7dec9b2013-02-22 12:58:35 +02004356static int dsi_display_init_dispc(struct platform_device *dsidev,
4357 struct omap_overlay_manager *mgr)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004358{
Archit Taneja7d2572f2012-06-29 14:31:07 +05304359 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Taneja7d2572f2012-06-29 14:31:07 +05304360 int r;
Archit Taneja5a8b5722011-05-12 17:26:29 +05304361
Tomi Valkeinen4ce9e332013-03-05 17:11:16 +02004362 dss_select_lcd_clk_source(mgr->id, dsi->module_id == 0 ?
4363 OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC :
4364 OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC);
Tomi Valkeinen5476e742011-11-03 16:34:20 +02004365
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004366 if (dsi->mode == OMAP_DSS_DSI_CMD_MODE) {
Tomi Valkeinen15502022012-10-10 13:59:07 +03004367 r = dss_mgr_register_framedone_handler(mgr,
4368 dsi_framedone_irq_callback, dsidev);
Archit Taneja8af6ff02011-09-05 16:48:27 +05304369 if (r) {
Tomi Valkeinen15502022012-10-10 13:59:07 +03004370 DSSERR("can't register FRAMEDONE handler\n");
Archit Taneja7d2572f2012-06-29 14:31:07 +05304371 goto err;
Archit Taneja8af6ff02011-09-05 16:48:27 +05304372 }
4373
Archit Taneja7d2572f2012-06-29 14:31:07 +05304374 dsi->mgr_config.stallmode = true;
4375 dsi->mgr_config.fifohandcheck = true;
Archit Taneja8af6ff02011-09-05 16:48:27 +05304376 } else {
Archit Taneja7d2572f2012-06-29 14:31:07 +05304377 dsi->mgr_config.stallmode = false;
4378 dsi->mgr_config.fifohandcheck = false;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004379 }
4380
Archit Tanejabd5a7b12012-06-26 12:38:31 +05304381 /*
4382 * override interlace, logic level and edge related parameters in
4383 * omap_video_timings with default values
4384 */
Archit Tanejae67458a2012-08-13 14:17:30 +05304385 dsi->timings.interlace = false;
4386 dsi->timings.hsync_level = OMAPDSS_SIG_ACTIVE_HIGH;
4387 dsi->timings.vsync_level = OMAPDSS_SIG_ACTIVE_HIGH;
4388 dsi->timings.data_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE;
4389 dsi->timings.de_level = OMAPDSS_SIG_ACTIVE_HIGH;
4390 dsi->timings.sync_pclk_edge = OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES;
Archit Tanejabd5a7b12012-06-26 12:38:31 +05304391
Archit Tanejaeea83402012-09-04 11:42:36 +05304392 dss_mgr_set_timings(mgr, &dsi->timings);
Archit Tanejabd5a7b12012-06-26 12:38:31 +05304393
Tomi Valkeinen57612172012-11-27 17:32:36 +02004394 r = dsi_configure_dispc_clocks(dsidev);
Archit Taneja7d2572f2012-06-29 14:31:07 +05304395 if (r)
4396 goto err1;
4397
4398 dsi->mgr_config.io_pad_mode = DSS_IO_PAD_MODE_BYPASS;
4399 dsi->mgr_config.video_port_width =
Archit Taneja02c39602012-08-10 15:01:33 +05304400 dsi_get_pixel_size(dsi->pix_fmt);
Archit Taneja7d2572f2012-06-29 14:31:07 +05304401 dsi->mgr_config.lcden_sig_polarity = 0;
4402
Archit Tanejaeea83402012-09-04 11:42:36 +05304403 dss_mgr_set_lcd_config(mgr, &dsi->mgr_config);
Archit Tanejad21f43b2012-06-21 09:45:11 +05304404
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004405 return 0;
Archit Taneja7d2572f2012-06-29 14:31:07 +05304406err1:
Archit Tanejadca2b152012-08-16 18:02:00 +05304407 if (dsi->mode == OMAP_DSS_DSI_CMD_MODE)
Tomi Valkeinen15502022012-10-10 13:59:07 +03004408 dss_mgr_unregister_framedone_handler(mgr,
4409 dsi_framedone_irq_callback, dsidev);
Archit Taneja7d2572f2012-06-29 14:31:07 +05304410err:
Tomi Valkeinenb7dec9b2013-02-22 12:58:35 +02004411 dss_select_lcd_clk_source(mgr->id, OMAP_DSS_CLK_SRC_FCK);
Archit Taneja7d2572f2012-06-29 14:31:07 +05304412 return r;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004413}
4414
Tomi Valkeinenb7dec9b2013-02-22 12:58:35 +02004415static void dsi_display_uninit_dispc(struct platform_device *dsidev,
4416 struct omap_overlay_manager *mgr)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004417{
Archit Tanejadca2b152012-08-16 18:02:00 +05304418 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4419
Tomi Valkeinen15502022012-10-10 13:59:07 +03004420 if (dsi->mode == OMAP_DSS_DSI_CMD_MODE)
4421 dss_mgr_unregister_framedone_handler(mgr,
4422 dsi_framedone_irq_callback, dsidev);
Tomi Valkeinenb7dec9b2013-02-22 12:58:35 +02004423
4424 dss_select_lcd_clk_source(mgr->id, OMAP_DSS_CLK_SRC_FCK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004425}
4426
Tomi Valkeinen57612172012-11-27 17:32:36 +02004427static int dsi_configure_dsi_clocks(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004428{
Tomi Valkeinena0d269e2012-11-27 17:05:54 +02004429 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004430 struct dsi_clock_info cinfo;
4431 int r;
4432
Tomi Valkeinena0d269e2012-11-27 17:05:54 +02004433 cinfo = dsi->user_dsi_cinfo;
4434
Tomi Valkeinenb6e695a2012-03-15 15:22:58 +02004435 r = dsi_calc_clock_rates(dsidev, &cinfo);
Ville Syrjäläebf0a3f2010-04-22 22:50:05 +02004436 if (r) {
4437 DSSERR("Failed to calc dsi clocks\n");
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004438 return r;
Ville Syrjäläebf0a3f2010-04-22 22:50:05 +02004439 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004440
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304441 r = dsi_pll_set_clock_div(dsidev, &cinfo);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004442 if (r) {
4443 DSSERR("Failed to set dsi clocks\n");
4444 return r;
4445 }
4446
4447 return 0;
4448}
4449
Tomi Valkeinen57612172012-11-27 17:32:36 +02004450static int dsi_display_init_dsi(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004451{
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02004452 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004453 int r;
4454
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304455 r = dsi_pll_init(dsidev, true, true);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004456 if (r)
4457 goto err0;
4458
Tomi Valkeinen57612172012-11-27 17:32:36 +02004459 r = dsi_configure_dsi_clocks(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004460 if (r)
4461 goto err1;
4462
Tomi Valkeinen4ce9e332013-03-05 17:11:16 +02004463 dss_select_dsi_clk_source(dsi->module_id, dsi->module_id == 0 ?
4464 OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI :
4465 OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DSI);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004466
4467 DSSDBG("PLL OK\n");
4468
Archit Taneja9e7e9372012-08-14 12:29:22 +05304469 r = dsi_cio_init(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004470 if (r)
4471 goto err2;
4472
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304473 _dsi_print_reset_status(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004474
Archit Taneja9e7e9372012-08-14 12:29:22 +05304475 dsi_proto_timings(dsidev);
Tomi Valkeinen57612172012-11-27 17:32:36 +02004476 dsi_set_lp_clk_divisor(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004477
4478 if (1)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304479 _dsi_print_reset_status(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004480
Tomi Valkeinen57612172012-11-27 17:32:36 +02004481 r = dsi_proto_config(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004482 if (r)
4483 goto err3;
4484
4485 /* enable interface */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304486 dsi_vc_enable(dsidev, 0, 1);
4487 dsi_vc_enable(dsidev, 1, 1);
4488 dsi_vc_enable(dsidev, 2, 1);
4489 dsi_vc_enable(dsidev, 3, 1);
4490 dsi_if_enable(dsidev, 1);
4491 dsi_force_tx_stop_mode_io(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004492
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004493 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004494err3:
Archit Taneja9e7e9372012-08-14 12:29:22 +05304495 dsi_cio_uninit(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004496err2:
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02004497 dss_select_dsi_clk_source(dsi->module_id, OMAP_DSS_CLK_SRC_FCK);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004498err1:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304499 dsi_pll_uninit(dsidev, true);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004500err0:
4501 return r;
4502}
4503
Tomi Valkeinen57612172012-11-27 17:32:36 +02004504static void dsi_display_uninit_dsi(struct platform_device *dsidev,
Tomi Valkeinen22d6d672010-10-11 11:33:30 +03004505 bool disconnect_lanes, bool enter_ulps)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004506{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304507 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304508
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304509 if (enter_ulps && !dsi->ulps_enabled)
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304510 dsi_enter_ulps(dsidev);
Tomi Valkeinen40885ab2010-07-28 15:53:38 +03004511
Ville Syrjäläd7370102010-04-22 22:50:09 +02004512 /* disable interface */
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304513 dsi_if_enable(dsidev, 0);
4514 dsi_vc_enable(dsidev, 0, 0);
4515 dsi_vc_enable(dsidev, 1, 0);
4516 dsi_vc_enable(dsidev, 2, 0);
4517 dsi_vc_enable(dsidev, 3, 0);
Ville Syrjäläd7370102010-04-22 22:50:09 +02004518
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02004519 dss_select_dsi_clk_source(dsi->module_id, OMAP_DSS_CLK_SRC_FCK);
Archit Taneja9e7e9372012-08-14 12:29:22 +05304520 dsi_cio_uninit(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304521 dsi_pll_uninit(dsidev, disconnect_lanes);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004522}
4523
Tomi Valkeinen5cfc1c32013-05-15 11:24:30 +03004524static int dsi_display_enable(struct omap_dss_device *dssdev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004525{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304526 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304527 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004528 int r = 0;
4529
4530 DSSDBG("dsi_display_enable\n");
4531
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304532 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02004533
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304534 mutex_lock(&dsi->lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004535
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004536 r = dsi_runtime_get(dsidev);
4537 if (r)
4538 goto err_get_dsi;
4539
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304540 dsi_enable_pll_clock(dsidev, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004541
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004542 _dsi_initialize_irq(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004543
Tomi Valkeinen57612172012-11-27 17:32:36 +02004544 r = dsi_display_init_dsi(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004545 if (r)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004546 goto err_init_dsi;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004547
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304548 mutex_unlock(&dsi->lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004549
4550 return 0;
4551
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004552err_init_dsi:
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304553 dsi_enable_pll_clock(dsidev, 0);
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004554 dsi_runtime_put(dsidev);
4555err_get_dsi:
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304556 mutex_unlock(&dsi->lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004557 DSSDBG("dsi_display_enable FAILED\n");
4558 return r;
4559}
4560
Tomi Valkeinen5cfc1c32013-05-15 11:24:30 +03004561static void dsi_display_disable(struct omap_dss_device *dssdev,
Tomi Valkeinen22d6d672010-10-11 11:33:30 +03004562 bool disconnect_lanes, bool enter_ulps)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004563{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304564 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304565 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304566
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004567 DSSDBG("dsi_display_disable\n");
4568
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304569 WARN_ON(!dsi_bus_is_locked(dsidev));
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +02004570
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304571 mutex_lock(&dsi->lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004572
Tomi Valkeinen15ffa1d2011-06-16 14:34:06 +03004573 dsi_sync_vc(dsidev, 0);
4574 dsi_sync_vc(dsidev, 1);
4575 dsi_sync_vc(dsidev, 2);
4576 dsi_sync_vc(dsidev, 3);
4577
Tomi Valkeinen57612172012-11-27 17:32:36 +02004578 dsi_display_uninit_dsi(dsidev, disconnect_lanes, enter_ulps);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004579
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03004580 dsi_runtime_put(dsidev);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05304581 dsi_enable_pll_clock(dsidev, 0);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004582
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304583 mutex_unlock(&dsi->lock);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004584}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004585
Tomi Valkeinen5cfc1c32013-05-15 11:24:30 +03004586static int dsi_enable_te(struct omap_dss_device *dssdev, bool enable)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004587{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05304588 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4589 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4590
4591 dsi->te_enabled = enable;
Tomi Valkeinen225b6502010-01-11 15:11:01 +02004592 return 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004593}
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02004594
Tomi Valkeinenf1e00012013-03-05 17:21:35 +02004595#ifdef PRINT_VERBOSE_VM_TIMINGS
4596static void print_dsi_vm(const char *str,
4597 const struct omap_dss_dsi_videomode_timings *t)
4598{
4599 unsigned long byteclk = t->hsclk / 4;
4600 int bl, wc, pps, tot;
4601
4602 wc = DIV_ROUND_UP(t->hact * t->bitspp, 8);
4603 pps = DIV_ROUND_UP(wc + 6, t->ndl); /* pixel packet size */
4604 bl = t->hss + t->hsa + t->hse + t->hbp + t->hfp;
4605 tot = bl + pps;
4606
4607#define TO_DSI_T(x) ((u32)div64_u64((u64)x * 1000000000llu, byteclk))
4608
4609 pr_debug("%s bck %lu, %u/%u/%u/%u/%u/%u = %u+%u = %u, "
4610 "%u/%u/%u/%u/%u/%u = %u + %u = %u\n",
4611 str,
4612 byteclk,
4613 t->hss, t->hsa, t->hse, t->hbp, pps, t->hfp,
4614 bl, pps, tot,
4615 TO_DSI_T(t->hss),
4616 TO_DSI_T(t->hsa),
4617 TO_DSI_T(t->hse),
4618 TO_DSI_T(t->hbp),
4619 TO_DSI_T(pps),
4620 TO_DSI_T(t->hfp),
4621
4622 TO_DSI_T(bl),
4623 TO_DSI_T(pps),
4624
4625 TO_DSI_T(tot));
4626#undef TO_DSI_T
4627}
4628
4629static void print_dispc_vm(const char *str, const struct omap_video_timings *t)
4630{
4631 unsigned long pck = t->pixel_clock * 1000;
4632 int hact, bl, tot;
4633
4634 hact = t->x_res;
4635 bl = t->hsw + t->hbp + t->hfp;
4636 tot = hact + bl;
4637
4638#define TO_DISPC_T(x) ((u32)div64_u64((u64)x * 1000000000llu, pck))
4639
4640 pr_debug("%s pck %lu, %u/%u/%u/%u = %u+%u = %u, "
4641 "%u/%u/%u/%u = %u + %u = %u\n",
4642 str,
4643 pck,
4644 t->hsw, t->hbp, hact, t->hfp,
4645 bl, hact, tot,
4646 TO_DISPC_T(t->hsw),
4647 TO_DISPC_T(t->hbp),
4648 TO_DISPC_T(hact),
4649 TO_DISPC_T(t->hfp),
4650 TO_DISPC_T(bl),
4651 TO_DISPC_T(hact),
4652 TO_DISPC_T(tot));
4653#undef TO_DISPC_T
4654}
4655
4656/* note: this is not quite accurate */
4657static void print_dsi_dispc_vm(const char *str,
4658 const struct omap_dss_dsi_videomode_timings *t)
4659{
4660 struct omap_video_timings vm = { 0 };
4661 unsigned long byteclk = t->hsclk / 4;
4662 unsigned long pck;
4663 u64 dsi_tput;
4664 int dsi_hact, dsi_htot;
4665
4666 dsi_tput = (u64)byteclk * t->ndl * 8;
4667 pck = (u32)div64_u64(dsi_tput, t->bitspp);
4668 dsi_hact = DIV_ROUND_UP(DIV_ROUND_UP(t->hact * t->bitspp, 8) + 6, t->ndl);
4669 dsi_htot = t->hss + t->hsa + t->hse + t->hbp + dsi_hact + t->hfp;
4670
4671 vm.pixel_clock = pck / 1000;
4672 vm.hsw = div64_u64((u64)(t->hsa + t->hse) * pck, byteclk);
4673 vm.hbp = div64_u64((u64)t->hbp * pck, byteclk);
4674 vm.hfp = div64_u64((u64)t->hfp * pck, byteclk);
4675 vm.x_res = t->hact;
4676
4677 print_dispc_vm(str, &vm);
4678}
4679#endif /* PRINT_VERBOSE_VM_TIMINGS */
4680
4681static bool dsi_cm_calc_dispc_cb(int lckd, int pckd, unsigned long lck,
4682 unsigned long pck, void *data)
4683{
4684 struct dsi_clk_calc_ctx *ctx = data;
4685 struct omap_video_timings *t = &ctx->dispc_vm;
4686
4687 ctx->dispc_cinfo.lck_div = lckd;
4688 ctx->dispc_cinfo.pck_div = pckd;
4689 ctx->dispc_cinfo.lck = lck;
4690 ctx->dispc_cinfo.pck = pck;
4691
4692 *t = *ctx->config->timings;
4693 t->pixel_clock = pck / 1000;
4694 t->x_res = ctx->config->timings->x_res;
4695 t->y_res = ctx->config->timings->y_res;
4696 t->hsw = t->hfp = t->hbp = t->vsw = 1;
4697 t->vfp = t->vbp = 0;
4698
4699 return true;
4700}
4701
4702static bool dsi_cm_calc_hsdiv_cb(int regm_dispc, unsigned long dispc,
4703 void *data)
4704{
4705 struct dsi_clk_calc_ctx *ctx = data;
4706
4707 ctx->dsi_cinfo.regm_dispc = regm_dispc;
4708 ctx->dsi_cinfo.dsi_pll_hsdiv_dispc_clk = dispc;
4709
4710 return dispc_div_calc(dispc, ctx->req_pck_min, ctx->req_pck_max,
4711 dsi_cm_calc_dispc_cb, ctx);
4712}
4713
4714static bool dsi_cm_calc_pll_cb(int regn, int regm, unsigned long fint,
4715 unsigned long pll, void *data)
4716{
4717 struct dsi_clk_calc_ctx *ctx = data;
4718
4719 ctx->dsi_cinfo.regn = regn;
4720 ctx->dsi_cinfo.regm = regm;
4721 ctx->dsi_cinfo.fint = fint;
4722 ctx->dsi_cinfo.clkin4ddr = pll;
4723
4724 return dsi_hsdiv_calc(ctx->dsidev, pll, ctx->req_pck_min,
4725 dsi_cm_calc_hsdiv_cb, ctx);
4726}
4727
4728static bool dsi_cm_calc(struct dsi_data *dsi,
4729 const struct omap_dss_dsi_config *cfg,
4730 struct dsi_clk_calc_ctx *ctx)
4731{
4732 unsigned long clkin;
4733 int bitspp, ndl;
4734 unsigned long pll_min, pll_max;
4735 unsigned long pck, txbyteclk;
4736
4737 clkin = clk_get_rate(dsi->sys_clk);
4738 bitspp = dsi_get_pixel_size(cfg->pixel_format);
4739 ndl = dsi->num_lanes_used - 1;
4740
4741 /*
4742 * Here we should calculate minimum txbyteclk to be able to send the
4743 * frame in time, and also to handle TE. That's not very simple, though,
4744 * especially as we go to LP between each pixel packet due to HW
4745 * "feature". So let's just estimate very roughly and multiply by 1.5.
4746 */
4747 pck = cfg->timings->pixel_clock * 1000;
4748 pck = pck * 3 / 2;
4749 txbyteclk = pck * bitspp / 8 / ndl;
4750
4751 memset(ctx, 0, sizeof(*ctx));
4752 ctx->dsidev = dsi->pdev;
4753 ctx->config = cfg;
4754 ctx->req_pck_min = pck;
4755 ctx->req_pck_nom = pck;
4756 ctx->req_pck_max = pck * 3 / 2;
4757 ctx->dsi_cinfo.clkin = clkin;
4758
4759 pll_min = max(cfg->hs_clk_min * 4, txbyteclk * 4 * 4);
4760 pll_max = cfg->hs_clk_max * 4;
4761
4762 return dsi_pll_calc(dsi->pdev, clkin,
4763 pll_min, pll_max,
4764 dsi_cm_calc_pll_cb, ctx);
4765}
4766
4767static bool dsi_vm_calc_blanking(struct dsi_clk_calc_ctx *ctx)
4768{
4769 struct dsi_data *dsi = dsi_get_dsidrv_data(ctx->dsidev);
4770 const struct omap_dss_dsi_config *cfg = ctx->config;
4771 int bitspp = dsi_get_pixel_size(cfg->pixel_format);
4772 int ndl = dsi->num_lanes_used - 1;
4773 unsigned long hsclk = ctx->dsi_cinfo.clkin4ddr / 4;
4774 unsigned long byteclk = hsclk / 4;
4775
4776 unsigned long dispc_pck, req_pck_min, req_pck_nom, req_pck_max;
4777 int xres;
4778 int panel_htot, panel_hbl; /* pixels */
4779 int dispc_htot, dispc_hbl; /* pixels */
4780 int dsi_htot, dsi_hact, dsi_hbl, hss, hse; /* byteclks */
4781 int hfp, hsa, hbp;
4782 const struct omap_video_timings *req_vm;
4783 struct omap_video_timings *dispc_vm;
4784 struct omap_dss_dsi_videomode_timings *dsi_vm;
4785 u64 dsi_tput, dispc_tput;
4786
4787 dsi_tput = (u64)byteclk * ndl * 8;
4788
4789 req_vm = cfg->timings;
4790 req_pck_min = ctx->req_pck_min;
4791 req_pck_max = ctx->req_pck_max;
4792 req_pck_nom = ctx->req_pck_nom;
4793
4794 dispc_pck = ctx->dispc_cinfo.pck;
4795 dispc_tput = (u64)dispc_pck * bitspp;
4796
4797 xres = req_vm->x_res;
4798
4799 panel_hbl = req_vm->hfp + req_vm->hbp + req_vm->hsw;
4800 panel_htot = xres + panel_hbl;
4801
4802 dsi_hact = DIV_ROUND_UP(DIV_ROUND_UP(xres * bitspp, 8) + 6, ndl);
4803
4804 /*
4805 * When there are no line buffers, DISPC and DSI must have the
4806 * same tput. Otherwise DISPC tput needs to be higher than DSI's.
4807 */
4808 if (dsi->line_buffer_size < xres * bitspp / 8) {
4809 if (dispc_tput != dsi_tput)
4810 return false;
4811 } else {
4812 if (dispc_tput < dsi_tput)
4813 return false;
4814 }
4815
4816 /* DSI tput must be over the min requirement */
4817 if (dsi_tput < (u64)bitspp * req_pck_min)
4818 return false;
4819
4820 /* When non-burst mode, DSI tput must be below max requirement. */
4821 if (cfg->trans_mode != OMAP_DSS_DSI_BURST_MODE) {
4822 if (dsi_tput > (u64)bitspp * req_pck_max)
4823 return false;
4824 }
4825
4826 hss = DIV_ROUND_UP(4, ndl);
4827
4828 if (cfg->trans_mode == OMAP_DSS_DSI_PULSE_MODE) {
4829 if (ndl == 3 && req_vm->hsw == 0)
4830 hse = 1;
4831 else
4832 hse = DIV_ROUND_UP(4, ndl);
4833 } else {
4834 hse = 0;
4835 }
4836
4837 /* DSI htot to match the panel's nominal pck */
4838 dsi_htot = div64_u64((u64)panel_htot * byteclk, req_pck_nom);
4839
4840 /* fail if there would be no time for blanking */
4841 if (dsi_htot < hss + hse + dsi_hact)
4842 return false;
4843
4844 /* total DSI blanking needed to achieve panel's TL */
4845 dsi_hbl = dsi_htot - dsi_hact;
4846
4847 /* DISPC htot to match the DSI TL */
4848 dispc_htot = div64_u64((u64)dsi_htot * dispc_pck, byteclk);
4849
4850 /* verify that the DSI and DISPC TLs are the same */
4851 if ((u64)dsi_htot * dispc_pck != (u64)dispc_htot * byteclk)
4852 return false;
4853
4854 dispc_hbl = dispc_htot - xres;
4855
4856 /* setup DSI videomode */
4857
4858 dsi_vm = &ctx->dsi_vm;
4859 memset(dsi_vm, 0, sizeof(*dsi_vm));
4860
4861 dsi_vm->hsclk = hsclk;
4862
4863 dsi_vm->ndl = ndl;
4864 dsi_vm->bitspp = bitspp;
4865
4866 if (cfg->trans_mode != OMAP_DSS_DSI_PULSE_MODE) {
4867 hsa = 0;
4868 } else if (ndl == 3 && req_vm->hsw == 0) {
4869 hsa = 0;
4870 } else {
4871 hsa = div64_u64((u64)req_vm->hsw * byteclk, req_pck_nom);
4872 hsa = max(hsa - hse, 1);
4873 }
4874
4875 hbp = div64_u64((u64)req_vm->hbp * byteclk, req_pck_nom);
4876 hbp = max(hbp, 1);
4877
4878 hfp = dsi_hbl - (hss + hsa + hse + hbp);
4879 if (hfp < 1) {
4880 int t;
4881 /* we need to take cycles from hbp */
4882
4883 t = 1 - hfp;
4884 hbp = max(hbp - t, 1);
4885 hfp = dsi_hbl - (hss + hsa + hse + hbp);
4886
4887 if (hfp < 1 && hsa > 0) {
4888 /* we need to take cycles from hsa */
4889 t = 1 - hfp;
4890 hsa = max(hsa - t, 1);
4891 hfp = dsi_hbl - (hss + hsa + hse + hbp);
4892 }
4893 }
4894
4895 if (hfp < 1)
4896 return false;
4897
4898 dsi_vm->hss = hss;
4899 dsi_vm->hsa = hsa;
4900 dsi_vm->hse = hse;
4901 dsi_vm->hbp = hbp;
4902 dsi_vm->hact = xres;
4903 dsi_vm->hfp = hfp;
4904
4905 dsi_vm->vsa = req_vm->vsw;
4906 dsi_vm->vbp = req_vm->vbp;
4907 dsi_vm->vact = req_vm->y_res;
4908 dsi_vm->vfp = req_vm->vfp;
4909
4910 dsi_vm->trans_mode = cfg->trans_mode;
4911
4912 dsi_vm->blanking_mode = 0;
4913 dsi_vm->hsa_blanking_mode = 1;
4914 dsi_vm->hfp_blanking_mode = 1;
4915 dsi_vm->hbp_blanking_mode = 1;
4916
4917 dsi_vm->ddr_clk_always_on = cfg->ddr_clk_always_on;
4918 dsi_vm->window_sync = 4;
4919
4920 /* setup DISPC videomode */
4921
4922 dispc_vm = &ctx->dispc_vm;
4923 *dispc_vm = *req_vm;
4924 dispc_vm->pixel_clock = dispc_pck / 1000;
4925
4926 if (cfg->trans_mode == OMAP_DSS_DSI_PULSE_MODE) {
4927 hsa = div64_u64((u64)req_vm->hsw * dispc_pck,
4928 req_pck_nom);
4929 hsa = max(hsa, 1);
4930 } else {
4931 hsa = 1;
4932 }
4933
4934 hbp = div64_u64((u64)req_vm->hbp * dispc_pck, req_pck_nom);
4935 hbp = max(hbp, 1);
4936
4937 hfp = dispc_hbl - hsa - hbp;
4938 if (hfp < 1) {
4939 int t;
4940 /* we need to take cycles from hbp */
4941
4942 t = 1 - hfp;
4943 hbp = max(hbp - t, 1);
4944 hfp = dispc_hbl - hsa - hbp;
4945
4946 if (hfp < 1) {
4947 /* we need to take cycles from hsa */
4948 t = 1 - hfp;
4949 hsa = max(hsa - t, 1);
4950 hfp = dispc_hbl - hsa - hbp;
4951 }
4952 }
4953
4954 if (hfp < 1)
4955 return false;
4956
4957 dispc_vm->hfp = hfp;
4958 dispc_vm->hsw = hsa;
4959 dispc_vm->hbp = hbp;
4960
4961 return true;
4962}
4963
4964
4965static bool dsi_vm_calc_dispc_cb(int lckd, int pckd, unsigned long lck,
4966 unsigned long pck, void *data)
4967{
4968 struct dsi_clk_calc_ctx *ctx = data;
4969
4970 ctx->dispc_cinfo.lck_div = lckd;
4971 ctx->dispc_cinfo.pck_div = pckd;
4972 ctx->dispc_cinfo.lck = lck;
4973 ctx->dispc_cinfo.pck = pck;
4974
4975 if (dsi_vm_calc_blanking(ctx) == false)
4976 return false;
4977
4978#ifdef PRINT_VERBOSE_VM_TIMINGS
4979 print_dispc_vm("dispc", &ctx->dispc_vm);
4980 print_dsi_vm("dsi ", &ctx->dsi_vm);
4981 print_dispc_vm("req ", ctx->config->timings);
4982 print_dsi_dispc_vm("act ", &ctx->dsi_vm);
4983#endif
4984
4985 return true;
4986}
4987
4988static bool dsi_vm_calc_hsdiv_cb(int regm_dispc, unsigned long dispc,
4989 void *data)
4990{
4991 struct dsi_clk_calc_ctx *ctx = data;
4992 unsigned long pck_max;
4993
4994 ctx->dsi_cinfo.regm_dispc = regm_dispc;
4995 ctx->dsi_cinfo.dsi_pll_hsdiv_dispc_clk = dispc;
4996
4997 /*
4998 * In burst mode we can let the dispc pck be arbitrarily high, but it
4999 * limits our scaling abilities. So for now, don't aim too high.
5000 */
5001
5002 if (ctx->config->trans_mode == OMAP_DSS_DSI_BURST_MODE)
5003 pck_max = ctx->req_pck_max + 10000000;
5004 else
5005 pck_max = ctx->req_pck_max;
5006
5007 return dispc_div_calc(dispc, ctx->req_pck_min, pck_max,
5008 dsi_vm_calc_dispc_cb, ctx);
5009}
5010
5011static bool dsi_vm_calc_pll_cb(int regn, int regm, unsigned long fint,
5012 unsigned long pll, void *data)
5013{
5014 struct dsi_clk_calc_ctx *ctx = data;
5015
5016 ctx->dsi_cinfo.regn = regn;
5017 ctx->dsi_cinfo.regm = regm;
5018 ctx->dsi_cinfo.fint = fint;
5019 ctx->dsi_cinfo.clkin4ddr = pll;
5020
5021 return dsi_hsdiv_calc(ctx->dsidev, pll, ctx->req_pck_min,
5022 dsi_vm_calc_hsdiv_cb, ctx);
5023}
5024
5025static bool dsi_vm_calc(struct dsi_data *dsi,
5026 const struct omap_dss_dsi_config *cfg,
5027 struct dsi_clk_calc_ctx *ctx)
5028{
5029 const struct omap_video_timings *t = cfg->timings;
5030 unsigned long clkin;
5031 unsigned long pll_min;
5032 unsigned long pll_max;
5033 int ndl = dsi->num_lanes_used - 1;
5034 int bitspp = dsi_get_pixel_size(cfg->pixel_format);
5035 unsigned long byteclk_min;
5036
5037 clkin = clk_get_rate(dsi->sys_clk);
5038
5039 memset(ctx, 0, sizeof(*ctx));
5040 ctx->dsidev = dsi->pdev;
5041 ctx->config = cfg;
5042
5043 ctx->dsi_cinfo.clkin = clkin;
5044
5045 /* these limits should come from the panel driver */
5046 ctx->req_pck_min = t->pixel_clock * 1000 - 1000;
5047 ctx->req_pck_nom = t->pixel_clock * 1000;
5048 ctx->req_pck_max = t->pixel_clock * 1000 + 1000;
5049
5050 byteclk_min = div64_u64((u64)ctx->req_pck_min * bitspp, ndl * 8);
5051 pll_min = max(cfg->hs_clk_min * 4, byteclk_min * 4 * 4);
5052
5053 if (cfg->trans_mode == OMAP_DSS_DSI_BURST_MODE) {
5054 pll_max = cfg->hs_clk_max * 4;
5055 } else {
5056 unsigned long byteclk_max;
5057 byteclk_max = div64_u64((u64)ctx->req_pck_max * bitspp,
5058 ndl * 8);
5059
5060 pll_max = byteclk_max * 4 * 4;
5061 }
5062
5063 return dsi_pll_calc(dsi->pdev, clkin,
5064 pll_min, pll_max,
5065 dsi_vm_calc_pll_cb, ctx);
5066}
5067
Tomi Valkeinen5cfc1c32013-05-15 11:24:30 +03005068static int dsi_set_config(struct omap_dss_device *dssdev,
Tomi Valkeinen777f05c2013-03-06 11:10:29 +02005069 const struct omap_dss_dsi_config *config)
Archit Tanejae67458a2012-08-13 14:17:30 +05305070{
5071 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
5072 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinenf1e00012013-03-05 17:21:35 +02005073 struct dsi_clk_calc_ctx ctx;
5074 bool ok;
5075 int r;
Archit Tanejae67458a2012-08-13 14:17:30 +05305076
5077 mutex_lock(&dsi->lock);
5078
Tomi Valkeinen777f05c2013-03-06 11:10:29 +02005079 dsi->pix_fmt = config->pixel_format;
5080 dsi->mode = config->mode;
5081
Tomi Valkeinenf1e00012013-03-05 17:21:35 +02005082 if (config->mode == OMAP_DSS_DSI_VIDEO_MODE)
5083 ok = dsi_vm_calc(dsi, config, &ctx);
5084 else
5085 ok = dsi_cm_calc(dsi, config, &ctx);
5086
5087 if (!ok) {
5088 DSSERR("failed to find suitable DSI clock settings\n");
5089 r = -EINVAL;
5090 goto err;
5091 }
5092
5093 dsi_pll_calc_dsi_fck(&ctx.dsi_cinfo);
5094
5095 r = dsi_lp_clock_calc(&ctx.dsi_cinfo, config->lp_clk_min,
5096 config->lp_clk_max);
5097 if (r) {
5098 DSSERR("failed to find suitable DSI LP clock settings\n");
5099 goto err;
5100 }
5101
5102 dsi->user_dsi_cinfo = ctx.dsi_cinfo;
5103 dsi->user_dispc_cinfo = ctx.dispc_cinfo;
5104
5105 dsi->timings = ctx.dispc_vm;
5106 dsi->vm_timings = ctx.dsi_vm;
Archit Tanejae67458a2012-08-13 14:17:30 +05305107
5108 mutex_unlock(&dsi->lock);
Archit Tanejae67458a2012-08-13 14:17:30 +05305109
Tomi Valkeinen777f05c2013-03-06 11:10:29 +02005110 return 0;
Tomi Valkeinenf1e00012013-03-05 17:21:35 +02005111err:
5112 mutex_unlock(&dsi->lock);
5113
5114 return r;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005115}
Archit Taneja0b3ffe32012-08-13 22:13:39 +05305116
Tomi Valkeinen2eea5ae2013-02-13 11:23:54 +02005117/*
5118 * Return a hardcoded channel for the DSI output. This should work for
5119 * current use cases, but this can be later expanded to either resolve
5120 * the channel in some more dynamic manner, or get the channel as a user
5121 * parameter.
5122 */
5123static enum omap_channel dsi_get_channel(int module_id)
Archit Tanejae3525742012-08-09 15:23:43 +05305124{
Tomi Valkeinen2eea5ae2013-02-13 11:23:54 +02005125 switch (omapdss_get_version()) {
5126 case OMAPDSS_VER_OMAP24xx:
5127 DSSWARN("DSI not supported\n");
5128 return OMAP_DSS_CHANNEL_LCD;
Archit Tanejae3525742012-08-09 15:23:43 +05305129
Tomi Valkeinen2eea5ae2013-02-13 11:23:54 +02005130 case OMAPDSS_VER_OMAP34xx_ES1:
5131 case OMAPDSS_VER_OMAP34xx_ES3:
5132 case OMAPDSS_VER_OMAP3630:
5133 case OMAPDSS_VER_AM35xx:
5134 return OMAP_DSS_CHANNEL_LCD;
Archit Tanejae3525742012-08-09 15:23:43 +05305135
Tomi Valkeinen2eea5ae2013-02-13 11:23:54 +02005136 case OMAPDSS_VER_OMAP4430_ES1:
5137 case OMAPDSS_VER_OMAP4430_ES2:
5138 case OMAPDSS_VER_OMAP4:
5139 switch (module_id) {
5140 case 0:
5141 return OMAP_DSS_CHANNEL_LCD;
5142 case 1:
5143 return OMAP_DSS_CHANNEL_LCD2;
5144 default:
5145 DSSWARN("unsupported module id\n");
5146 return OMAP_DSS_CHANNEL_LCD;
5147 }
Archit Tanejae3525742012-08-09 15:23:43 +05305148
Tomi Valkeinen2eea5ae2013-02-13 11:23:54 +02005149 case OMAPDSS_VER_OMAP5:
5150 switch (module_id) {
5151 case 0:
5152 return OMAP_DSS_CHANNEL_LCD;
5153 case 1:
5154 return OMAP_DSS_CHANNEL_LCD3;
5155 default:
5156 DSSWARN("unsupported module id\n");
5157 return OMAP_DSS_CHANNEL_LCD;
5158 }
5159
5160 default:
5161 DSSWARN("unsupported DSS version\n");
5162 return OMAP_DSS_CHANNEL_LCD;
5163 }
Archit Taneja02c39602012-08-10 15:01:33 +05305164}
Tomi Valkeinen5f42f2c2011-02-22 15:53:46 +02005165
Tomi Valkeinen5cfc1c32013-05-15 11:24:30 +03005166static int dsi_request_vc(struct omap_dss_device *dssdev, int *channel)
Archit Taneja5ee3c142011-03-02 12:35:53 +05305167{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305168 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
5169 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Archit Taneja5ee3c142011-03-02 12:35:53 +05305170 int i;
5171
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305172 for (i = 0; i < ARRAY_SIZE(dsi->vc); i++) {
5173 if (!dsi->vc[i].dssdev) {
5174 dsi->vc[i].dssdev = dssdev;
Archit Taneja5ee3c142011-03-02 12:35:53 +05305175 *channel = i;
5176 return 0;
5177 }
5178 }
5179
5180 DSSERR("cannot get VC for display %s", dssdev->name);
5181 return -ENOSPC;
5182}
Archit Taneja5ee3c142011-03-02 12:35:53 +05305183
Tomi Valkeinen5cfc1c32013-05-15 11:24:30 +03005184static int dsi_set_vc_id(struct omap_dss_device *dssdev, int channel, int vc_id)
Archit Taneja5ee3c142011-03-02 12:35:53 +05305185{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305186 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
5187 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
5188
Archit Taneja5ee3c142011-03-02 12:35:53 +05305189 if (vc_id < 0 || vc_id > 3) {
5190 DSSERR("VC ID out of range\n");
5191 return -EINVAL;
5192 }
5193
5194 if (channel < 0 || channel > 3) {
5195 DSSERR("Virtual Channel out of range\n");
5196 return -EINVAL;
5197 }
5198
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305199 if (dsi->vc[channel].dssdev != dssdev) {
Archit Taneja5ee3c142011-03-02 12:35:53 +05305200 DSSERR("Virtual Channel not allocated to display %s\n",
5201 dssdev->name);
5202 return -EINVAL;
5203 }
5204
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305205 dsi->vc[channel].vc_id = vc_id;
Archit Taneja5ee3c142011-03-02 12:35:53 +05305206
5207 return 0;
5208}
Archit Taneja5ee3c142011-03-02 12:35:53 +05305209
Tomi Valkeinen5cfc1c32013-05-15 11:24:30 +03005210static void dsi_release_vc(struct omap_dss_device *dssdev, int channel)
Archit Taneja5ee3c142011-03-02 12:35:53 +05305211{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305212 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
5213 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
5214
Archit Taneja5ee3c142011-03-02 12:35:53 +05305215 if ((channel >= 0 && channel <= 3) &&
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305216 dsi->vc[channel].dssdev == dssdev) {
5217 dsi->vc[channel].dssdev = NULL;
5218 dsi->vc[channel].vc_id = 0;
Archit Taneja5ee3c142011-03-02 12:35:53 +05305219 }
5220}
Archit Taneja5ee3c142011-03-02 12:35:53 +05305221
Archit Tanejaa72b64b2011-05-12 17:26:26 +05305222void dsi_wait_pll_hsdiv_dispc_active(struct platform_device *dsidev)
Tomi Valkeinene406f902010-06-09 15:28:12 +03005223{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05305224 if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 7, 1) != 1)
Archit Taneja067a57e2011-03-02 11:57:25 +05305225 DSSERR("%s (%s) not active\n",
Archit Taneja89a35e52011-04-12 13:52:23 +05305226 dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
5227 dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC));
Tomi Valkeinene406f902010-06-09 15:28:12 +03005228}
5229
Archit Tanejaa72b64b2011-05-12 17:26:26 +05305230void dsi_wait_pll_hsdiv_dsi_active(struct platform_device *dsidev)
Tomi Valkeinene406f902010-06-09 15:28:12 +03005231{
Archit Tanejaa72b64b2011-05-12 17:26:26 +05305232 if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 8, 1) != 1)
Archit Taneja067a57e2011-03-02 11:57:25 +05305233 DSSERR("%s (%s) not active\n",
Archit Taneja89a35e52011-04-12 13:52:23 +05305234 dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
5235 dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI));
Tomi Valkeinene406f902010-06-09 15:28:12 +03005236}
5237
Archit Tanejaa72b64b2011-05-12 17:26:26 +05305238static void dsi_calc_clock_param_ranges(struct platform_device *dsidev)
Taneja, Archit49641112011-03-14 23:28:23 -05005239{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305240 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
5241
5242 dsi->regn_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGN);
5243 dsi->regm_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM);
5244 dsi->regm_dispc_max =
5245 dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DISPC);
5246 dsi->regm_dsi_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DSI);
5247 dsi->fint_min = dss_feat_get_param_min(FEAT_PARAM_DSIPLL_FINT);
5248 dsi->fint_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_FINT);
5249 dsi->lpdiv_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_LPDIV);
Taneja, Archit49641112011-03-14 23:28:23 -05005250}
5251
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005252static int dsi_get_clocks(struct platform_device *dsidev)
5253{
5254 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
5255 struct clk *clk;
5256
Sachin Kamat5303b3a2013-04-02 14:33:00 +03005257 clk = devm_clk_get(&dsidev->dev, "fck");
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005258 if (IS_ERR(clk)) {
5259 DSSERR("can't get fck\n");
5260 return PTR_ERR(clk);
5261 }
5262
5263 dsi->dss_clk = clk;
5264
Sachin Kamat5303b3a2013-04-02 14:33:00 +03005265 clk = devm_clk_get(&dsidev->dev, "sys_clk");
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005266 if (IS_ERR(clk)) {
5267 DSSERR("can't get sys_clk\n");
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005268 return PTR_ERR(clk);
5269 }
5270
5271 dsi->sys_clk = clk;
5272
5273 return 0;
5274}
5275
Tomi Valkeinendeb16df2013-05-24 13:20:27 +03005276static int dsi_connect(struct omap_dss_device *dssdev,
5277 struct omap_dss_device *dst)
5278{
5279 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
5280 struct omap_overlay_manager *mgr;
5281 int r;
5282
5283 r = dsi_regulator_init(dsidev);
5284 if (r)
5285 return r;
5286
5287 mgr = omap_dss_get_overlay_manager(dssdev->dispc_channel);
5288 if (!mgr)
5289 return -ENODEV;
5290
5291 r = dss_mgr_connect(mgr, dssdev);
5292 if (r)
5293 return r;
5294
5295 r = omapdss_output_set_device(dssdev, dst);
5296 if (r) {
5297 DSSERR("failed to connect output to new device: %s\n",
5298 dssdev->name);
5299 dss_mgr_disconnect(mgr, dssdev);
5300 return r;
5301 }
5302
5303 return 0;
5304}
5305
5306static void dsi_disconnect(struct omap_dss_device *dssdev,
5307 struct omap_dss_device *dst)
5308{
Tomi Valkeinen9560dc102013-07-24 13:06:54 +03005309 WARN_ON(dst != dssdev->dst);
Tomi Valkeinendeb16df2013-05-24 13:20:27 +03005310
Tomi Valkeinen9560dc102013-07-24 13:06:54 +03005311 if (dst != dssdev->dst)
Tomi Valkeinendeb16df2013-05-24 13:20:27 +03005312 return;
5313
5314 omapdss_output_unset_device(dssdev);
5315
5316 if (dssdev->manager)
5317 dss_mgr_disconnect(dssdev->manager, dssdev);
5318}
5319
5320static const struct omapdss_dsi_ops dsi_ops = {
5321 .connect = dsi_connect,
5322 .disconnect = dsi_disconnect,
5323
5324 .bus_lock = dsi_bus_lock,
5325 .bus_unlock = dsi_bus_unlock,
5326
Tomi Valkeinen5cfc1c32013-05-15 11:24:30 +03005327 .enable = dsi_display_enable,
5328 .disable = dsi_display_disable,
Tomi Valkeinendeb16df2013-05-24 13:20:27 +03005329
Tomi Valkeinen5cfc1c32013-05-15 11:24:30 +03005330 .enable_hs = dsi_vc_enable_hs,
Tomi Valkeinendeb16df2013-05-24 13:20:27 +03005331
Tomi Valkeinen5cfc1c32013-05-15 11:24:30 +03005332 .configure_pins = dsi_configure_pins,
5333 .set_config = dsi_set_config,
Tomi Valkeinendeb16df2013-05-24 13:20:27 +03005334
5335 .enable_video_output = dsi_enable_video_output,
5336 .disable_video_output = dsi_disable_video_output,
5337
Tomi Valkeinen5cfc1c32013-05-15 11:24:30 +03005338 .update = dsi_update,
Tomi Valkeinendeb16df2013-05-24 13:20:27 +03005339
Tomi Valkeinen5cfc1c32013-05-15 11:24:30 +03005340 .enable_te = dsi_enable_te,
Tomi Valkeinendeb16df2013-05-24 13:20:27 +03005341
Tomi Valkeinen5cfc1c32013-05-15 11:24:30 +03005342 .request_vc = dsi_request_vc,
5343 .set_vc_id = dsi_set_vc_id,
5344 .release_vc = dsi_release_vc,
Tomi Valkeinendeb16df2013-05-24 13:20:27 +03005345
5346 .dcs_write = dsi_vc_dcs_write,
5347 .dcs_write_nosync = dsi_vc_dcs_write_nosync,
5348 .dcs_read = dsi_vc_dcs_read,
5349
5350 .gen_write = dsi_vc_generic_write,
5351 .gen_write_nosync = dsi_vc_generic_write_nosync,
5352 .gen_read = dsi_vc_generic_read,
5353
5354 .bta_sync = dsi_vc_send_bta_sync,
5355
5356 .set_max_rx_packet_size = dsi_vc_set_max_rx_packet_size,
5357};
5358
Tomi Valkeinenee4a24e2013-04-26 13:47:06 +03005359static void dsi_init_output(struct platform_device *dsidev)
Archit Taneja81b87f52012-09-26 16:30:49 +05305360{
5361 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +03005362 struct omap_dss_device *out = &dsi->output;
Archit Taneja81b87f52012-09-26 16:30:49 +05305363
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +03005364 out->dev = &dsidev->dev;
Archit Taneja81b87f52012-09-26 16:30:49 +05305365 out->id = dsi->module_id == 0 ?
5366 OMAP_DSS_OUTPUT_DSI1 : OMAP_DSS_OUTPUT_DSI2;
5367
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +03005368 out->output_type = OMAP_DISPLAY_TYPE_DSI;
Tomi Valkeinen7286a082013-02-18 13:06:01 +02005369 out->name = dsi->module_id == 0 ? "dsi.0" : "dsi.1";
Tomi Valkeinen2eea5ae2013-02-13 11:23:54 +02005370 out->dispc_channel = dsi_get_channel(dsi->module_id);
Tomi Valkeinendeb16df2013-05-24 13:20:27 +03005371 out->ops.dsi = &dsi_ops;
Tomi Valkeinenb7328e12013-05-03 11:42:18 +03005372 out->owner = THIS_MODULE;
Archit Taneja81b87f52012-09-26 16:30:49 +05305373
Tomi Valkeinen5d47dbc2013-04-24 13:32:51 +03005374 omapdss_register_output(out);
Archit Taneja81b87f52012-09-26 16:30:49 +05305375}
5376
Tomi Valkeinend1890a682013-04-26 13:47:41 +03005377static void dsi_uninit_output(struct platform_device *dsidev)
Archit Taneja81b87f52012-09-26 16:30:49 +05305378{
5379 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
Tomi Valkeinen1f68d9c2013-04-19 15:09:34 +03005380 struct omap_dss_device *out = &dsi->output;
Archit Taneja81b87f52012-09-26 16:30:49 +05305381
Tomi Valkeinen5d47dbc2013-04-24 13:32:51 +03005382 omapdss_unregister_output(out);
Archit Taneja81b87f52012-09-26 16:30:49 +05305383}
5384
Tomi Valkeinen6274a612012-08-21 15:35:42 +03005385static int dsi_probe_of(struct platform_device *pdev)
5386{
5387 struct device_node *node = pdev->dev.of_node;
5388 struct dsi_data *dsi = dsi_get_dsidrv_data(pdev);
5389 struct property *prop;
5390 u32 lane_arr[10];
5391 int len, num_pins;
5392 int r, i;
5393 struct device_node *ep;
5394 struct omap_dsi_pin_config pin_cfg;
5395
5396 ep = omapdss_of_get_first_endpoint(node);
5397 if (!ep)
5398 return 0;
5399
5400 prop = of_find_property(ep, "lanes", &len);
5401 if (prop == NULL) {
5402 dev_err(&pdev->dev, "failed to find lane data\n");
5403 r = -EINVAL;
5404 goto err;
5405 }
5406
5407 num_pins = len / sizeof(u32);
5408
5409 if (num_pins < 4 || num_pins % 2 != 0 ||
5410 num_pins > dsi->num_lanes_supported * 2) {
5411 dev_err(&pdev->dev, "bad number of lanes\n");
5412 r = -EINVAL;
5413 goto err;
5414 }
5415
5416 r = of_property_read_u32_array(ep, "lanes", lane_arr, num_pins);
5417 if (r) {
5418 dev_err(&pdev->dev, "failed to read lane data\n");
5419 goto err;
5420 }
5421
5422 pin_cfg.num_pins = num_pins;
5423 for (i = 0; i < num_pins; ++i)
5424 pin_cfg.pins[i] = (int)lane_arr[i];
5425
5426 r = dsi_configure_pins(&dsi->output, &pin_cfg);
5427 if (r) {
5428 dev_err(&pdev->dev, "failed to configure pins");
5429 goto err;
5430 }
5431
5432 of_node_put(ep);
5433
5434 return 0;
5435
5436err:
5437 of_node_put(ep);
5438 return r;
5439}
5440
Tomi Valkeinenb98482e2011-05-16 13:52:51 +03005441/* DSI1 HW IP initialisation */
Tomi Valkeinenee4a24e2013-04-26 13:47:06 +03005442static int omap_dsihw_probe(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005443{
5444 u32 rev;
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02005445 int r, i;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305446 struct dsi_data *dsi;
Tomi Valkeinen6274a612012-08-21 15:35:42 +03005447 struct resource *dsi_mem;
Tomi Valkeinen68104462013-12-17 13:53:28 +02005448 struct resource *res;
5449 struct resource temp_res;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005450
Julia Lawall6e2a14d2012-01-24 14:00:45 +01005451 dsi = devm_kzalloc(&dsidev->dev, sizeof(*dsi), GFP_KERNEL);
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005452 if (!dsi)
5453 return -ENOMEM;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305454
5455 dsi->pdev = dsidev;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305456 dev_set_drvdata(&dsidev->dev, dsi);
Archit Tanejaa72b64b2011-05-12 17:26:26 +05305457
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305458 spin_lock_init(&dsi->irq_lock);
5459 spin_lock_init(&dsi->errors_lock);
5460 dsi->errors = 0;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005461
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02005462#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305463 spin_lock_init(&dsi->irq_stats_lock);
5464 dsi->irq_stats.last_reset = jiffies;
Tomi Valkeinendfc0fd82009-12-17 14:35:21 +02005465#endif
5466
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305467 mutex_init(&dsi->lock);
5468 sema_init(&dsi->bus_lock, 1);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005469
Tejun Heo203b42f2012-08-21 13:18:23 -07005470 INIT_DEFERRABLE_WORK(&dsi->framedone_timeout_work,
5471 dsi_framedone_timeout_work_callback);
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305472
5473#ifdef DSI_CATCH_MISSING_TE
5474 init_timer(&dsi->te_timer);
5475 dsi->te_timer.function = dsi_te_timeout;
5476 dsi->te_timer.data = 0;
5477#endif
Tomi Valkeinen68104462013-12-17 13:53:28 +02005478
5479 res = platform_get_resource_byname(dsidev, IORESOURCE_MEM, "proto");
5480 if (!res) {
5481 res = platform_get_resource(dsidev, IORESOURCE_MEM, 0);
5482 if (!res) {
5483 DSSERR("can't get IORESOURCE_MEM DSI\n");
5484 return -EINVAL;
5485 }
5486
5487 temp_res.start = res->start;
5488 temp_res.end = temp_res.start + DSI_PROTO_SZ - 1;
5489 res = &temp_res;
archit tanejaaffe3602011-02-23 08:41:03 +00005490 }
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005491
Tomi Valkeinen6274a612012-08-21 15:35:42 +03005492 dsi_mem = res;
5493
Tomi Valkeinen68104462013-12-17 13:53:28 +02005494 dsi->proto_base = devm_ioremap(&dsidev->dev, res->start,
5495 resource_size(res));
5496 if (!dsi->proto_base) {
5497 DSSERR("can't ioremap DSI protocol engine\n");
5498 return -ENOMEM;
5499 }
5500
5501 res = platform_get_resource_byname(dsidev, IORESOURCE_MEM, "phy");
5502 if (!res) {
5503 res = platform_get_resource(dsidev, IORESOURCE_MEM, 0);
5504 if (!res) {
5505 DSSERR("can't get IORESOURCE_MEM DSI\n");
5506 return -EINVAL;
5507 }
5508
5509 temp_res.start = res->start + DSI_PHY_OFFSET;
5510 temp_res.end = temp_res.start + DSI_PHY_SZ - 1;
5511 res = &temp_res;
5512 }
5513
5514 dsi->phy_base = devm_ioremap(&dsidev->dev, res->start,
5515 resource_size(res));
5516 if (!dsi->proto_base) {
5517 DSSERR("can't ioremap DSI PHY\n");
5518 return -ENOMEM;
5519 }
5520
5521 res = platform_get_resource_byname(dsidev, IORESOURCE_MEM, "pll");
5522 if (!res) {
5523 res = platform_get_resource(dsidev, IORESOURCE_MEM, 0);
5524 if (!res) {
5525 DSSERR("can't get IORESOURCE_MEM DSI\n");
5526 return -EINVAL;
5527 }
5528
5529 temp_res.start = res->start + DSI_PLL_OFFSET;
5530 temp_res.end = temp_res.start + DSI_PLL_SZ - 1;
5531 res = &temp_res;
5532 }
5533
5534 dsi->pll_base = devm_ioremap(&dsidev->dev, res->start,
5535 resource_size(res));
5536 if (!dsi->proto_base) {
5537 DSSERR("can't ioremap DSI PLL\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005538 return -ENOMEM;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305539 }
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005540
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305541 dsi->irq = platform_get_irq(dsi->pdev, 0);
5542 if (dsi->irq < 0) {
5543 DSSERR("platform_get_irq failed\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005544 return -ENODEV;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305545 }
archit tanejaaffe3602011-02-23 08:41:03 +00005546
Julia Lawall6e2a14d2012-01-24 14:00:45 +01005547 r = devm_request_irq(&dsidev->dev, dsi->irq, omap_dsi_irq_handler,
5548 IRQF_SHARED, dev_name(&dsidev->dev), dsi->pdev);
archit tanejaaffe3602011-02-23 08:41:03 +00005549 if (r < 0) {
5550 DSSERR("request_irq failed\n");
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005551 return r;
archit tanejaaffe3602011-02-23 08:41:03 +00005552 }
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005553
Tomi Valkeinen6274a612012-08-21 15:35:42 +03005554 if (dsidev->dev.of_node) {
5555 const struct of_device_id *match;
5556 const struct dsi_module_id_data *d;
5557
5558 match = of_match_node(dsi_of_match, dsidev->dev.of_node);
5559 if (!match) {
5560 DSSERR("unsupported DSI module\n");
5561 return -ENODEV;
5562 }
5563
5564 d = match->data;
5565
5566 while (d->address != 0 && d->address != dsi_mem->start)
5567 d++;
5568
5569 if (d->address == 0) {
5570 DSSERR("unsupported DSI module\n");
5571 return -ENODEV;
5572 }
5573
5574 dsi->module_id = d->id;
5575 } else {
5576 dsi->module_id = dsidev->id;
5577 }
5578
Archit Taneja5ee3c142011-03-02 12:35:53 +05305579 /* DSI VCs initialization */
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305580 for (i = 0; i < ARRAY_SIZE(dsi->vc); i++) {
Archit Tanejad6049142011-08-22 11:58:08 +05305581 dsi->vc[i].source = DSI_VC_SOURCE_L4;
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305582 dsi->vc[i].dssdev = NULL;
5583 dsi->vc[i].vc_id = 0;
Archit Taneja5ee3c142011-03-02 12:35:53 +05305584 }
5585
Archit Tanejaa72b64b2011-05-12 17:26:26 +05305586 dsi_calc_clock_param_ranges(dsidev);
Taneja, Archit49641112011-03-14 23:28:23 -05005587
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005588 r = dsi_get_clocks(dsidev);
5589 if (r)
5590 return r;
5591
5592 pm_runtime_enable(&dsidev->dev);
5593
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005594 r = dsi_runtime_get(dsidev);
5595 if (r)
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005596 goto err_runtime_get;
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005597
Archit Tanejaa72b64b2011-05-12 17:26:26 +05305598 rev = dsi_read_reg(dsidev, DSI_REVISION);
5599 dev_dbg(&dsidev->dev, "OMAP DSI rev %d.%d\n",
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005600 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
5601
Tomi Valkeinend9820852011-10-12 15:05:59 +03005602 /* DSI on OMAP3 doesn't have register DSI_GNQ, set number
5603 * of data to 3 by default */
5604 if (dss_has_feature(FEAT_DSI_GNQ))
5605 /* NB_DATA_LANES */
5606 dsi->num_lanes_supported = 1 + REG_GET(dsidev, DSI_GNQ, 11, 9);
5607 else
5608 dsi->num_lanes_supported = 3;
Archit Taneja75d72472011-05-16 15:17:08 +05305609
Tomi Valkeinen99322572013-03-05 10:37:02 +02005610 dsi->line_buffer_size = dsi_get_line_buf_size(dsidev);
5611
Archit Taneja81b87f52012-09-26 16:30:49 +05305612 dsi_init_output(dsidev);
5613
Tomi Valkeinen6274a612012-08-21 15:35:42 +03005614 if (dsidev->dev.of_node) {
5615 r = dsi_probe_of(dsidev);
5616 if (r) {
5617 DSSERR("Invalid DSI DT data\n");
5618 goto err_probe_of;
5619 }
5620
5621 r = of_platform_populate(dsidev->dev.of_node, NULL, NULL,
5622 &dsidev->dev);
5623 if (r)
5624 DSSERR("Failed to populate DSI child devices: %d\n", r);
5625 }
5626
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005627 dsi_runtime_put(dsidev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005628
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02005629 if (dsi->module_id == 0)
Tomi Valkeinene40402c2012-03-02 18:01:07 +02005630 dss_debugfs_create_file("dsi1_regs", dsi1_dump_regs);
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02005631 else if (dsi->module_id == 1)
Tomi Valkeinene40402c2012-03-02 18:01:07 +02005632 dss_debugfs_create_file("dsi2_regs", dsi2_dump_regs);
5633
5634#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02005635 if (dsi->module_id == 0)
Tomi Valkeinene40402c2012-03-02 18:01:07 +02005636 dss_debugfs_create_file("dsi1_irqs", dsi1_dump_irqs);
Tomi Valkeinen11ee9602012-03-09 16:07:39 +02005637 else if (dsi->module_id == 1)
Tomi Valkeinene40402c2012-03-02 18:01:07 +02005638 dss_debugfs_create_file("dsi2_irqs", dsi2_dump_irqs);
5639#endif
Tomi Valkeinen6274a612012-08-21 15:35:42 +03005640
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005641 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005642
Tomi Valkeinen6274a612012-08-21 15:35:42 +03005643err_probe_of:
5644 dsi_uninit_output(dsidev);
5645 dsi_runtime_put(dsidev);
5646
Tomi Valkeinencd3b3442012-01-25 13:31:04 +02005647err_runtime_get:
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005648 pm_runtime_disable(&dsidev->dev);
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005649 return r;
5650}
5651
Tomi Valkeinen6274a612012-08-21 15:35:42 +03005652static int dsi_unregister_child(struct device *dev, void *data)
5653{
5654 struct platform_device *pdev = to_platform_device(dev);
5655 platform_device_unregister(pdev);
5656 return 0;
5657}
5658
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02005659static int __exit omap_dsihw_remove(struct platform_device *dsidev)
Tomi Valkeinen3de7a1d2009-10-28 11:59:56 +02005660{
Archit Tanejaf1da39d2011-05-12 17:26:27 +05305661 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
5662
Tomi Valkeinen6274a612012-08-21 15:35:42 +03005663 device_for_each_child(&dsidev->dev, NULL, dsi_unregister_child);
5664
Tomi Valkeinenb98482e2011-05-16 13:52:51 +03005665 WARN_ON(dsi->scp_clk_refcount > 0);
5666
Archit Taneja81b87f52012-09-26 16:30:49 +05305667 dsi_uninit_output(dsidev);
5668
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005669 pm_runtime_disable(&dsidev->dev);
5670
Tomi Valkeinenb2541c42013-05-03 13:42:24 +03005671 if (dsi->vdds_dsi_reg != NULL && dsi->vdds_dsi_enabled) {
5672 regulator_disable(dsi->vdds_dsi_reg);
5673 dsi->vdds_dsi_enabled = false;
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005674 }
5675
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005676 return 0;
5677}
5678
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005679static int dsi_runtime_suspend(struct device *dev)
5680{
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005681 dispc_runtime_put();
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005682
5683 return 0;
5684}
5685
5686static int dsi_runtime_resume(struct device *dev)
5687{
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005688 int r;
5689
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005690 r = dispc_runtime_get();
5691 if (r)
Tomi Valkeinen852f0832012-02-17 17:58:04 +02005692 return r;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005693
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005694 return 0;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005695}
5696
5697static const struct dev_pm_ops dsi_pm_ops = {
5698 .runtime_suspend = dsi_runtime_suspend,
5699 .runtime_resume = dsi_runtime_resume,
5700};
5701
Tomi Valkeinen6274a612012-08-21 15:35:42 +03005702static const struct dsi_module_id_data dsi_of_data_omap3[] = {
5703 { .address = 0x4804fc00, .id = 0, },
5704 { },
5705};
5706
5707static const struct dsi_module_id_data dsi_of_data_omap4[] = {
5708 { .address = 0x58004000, .id = 0, },
5709 { .address = 0x58005000, .id = 1, },
5710 { },
5711};
5712
5713static const struct of_device_id dsi_of_match[] = {
5714 { .compatible = "ti,omap3-dsi", .data = dsi_of_data_omap3, },
5715 { .compatible = "ti,omap4-dsi", .data = dsi_of_data_omap4, },
5716 {},
5717};
5718
Tomi Valkeinen7c68dd92011-08-03 14:00:57 +03005719static struct platform_driver omap_dsihw_driver = {
Tomi Valkeinenee4a24e2013-04-26 13:47:06 +03005720 .probe = omap_dsihw_probe,
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02005721 .remove = __exit_p(omap_dsihw_remove),
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005722 .driver = {
Tomi Valkeinen7c68dd92011-08-03 14:00:57 +03005723 .name = "omapdss_dsi",
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005724 .owner = THIS_MODULE,
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +03005725 .pm = &dsi_pm_ops,
Tomi Valkeinen6274a612012-08-21 15:35:42 +03005726 .of_match_table = dsi_of_match,
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005727 },
5728};
5729
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02005730int __init dsi_init_platform_driver(void)
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005731{
Tomi Valkeinenee4a24e2013-04-26 13:47:06 +03005732 return platform_driver_register(&omap_dsihw_driver);
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005733}
5734
Tomi Valkeinen6e7e8f02012-02-17 17:41:13 +02005735void __exit dsi_uninit_platform_driver(void)
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005736{
Tomi Valkeinen04c742c2012-02-23 15:32:37 +02005737 platform_driver_unregister(&omap_dsihw_driver);
Senthilvadivu Guruswamyc8aac012011-01-24 06:22:02 +00005738}